From patchwork Thu Jul 4 04:31:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB894C30653 for ; Thu, 4 Jul 2024 04:32:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7984A6B00A5; Thu, 4 Jul 2024 00:32:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7205B6B00A6; Thu, 4 Jul 2024 00:32:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54C736B00A7; Thu, 4 Jul 2024 00:32:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 330FC6B00A5 for ; Thu, 4 Jul 2024 00:32:14 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A9F3F140A71 for ; Thu, 4 Jul 2024 04:32:13 +0000 (UTC) X-FDA: 82300798146.15.6217C5B Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf21.hostedemail.com (Postfix) with ESMTP id 6D6221C000C for ; Thu, 4 Jul 2024 04:32:11 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GTzwuWvk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jvDVW3J6; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GTzwuWvk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jvDVW3J6; spf=pass (imf21.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720067519; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ywx5qYincblCns1hUo2a7V32kYl58scbVMBY9LF3T58=; b=Dg2oLOevl27hAR4ImsoQ/QPqlfjp1yhJ07wODJQn1viAYPxLIMJQt+ejg78npLxp3obmev Z4SBe+yWl0xtsZxSE6kWNNsADr0DMXHOPnH+6TgSWwi8MM+clTPt2Fdi8RwYSbdKjo2pxi OOqKlRZb0jn0kR0wfAGhMviEpCF1BEg= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GTzwuWvk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jvDVW3J6; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GTzwuWvk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jvDVW3J6; spf=pass (imf21.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720067519; a=rsa-sha256; cv=none; b=xBLi0uvZTjIIDryoBB1GGiEf2VzSttGk+OYodOlmFEWUNl1R+5t3RvKcAYyx3PLiUVTWvu YmK4hH9LC1HViwpibuu5jkYBCg8czr19ITOXsSGSTpSoI7Qn5Db02JQhlLzR8QG0Vb7VAm SRwpCS4sEj1oAb07bTTzDkQF5YGh1ns= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2A18B21180; Thu, 4 Jul 2024 04:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720067530; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ywx5qYincblCns1hUo2a7V32kYl58scbVMBY9LF3T58=; b=GTzwuWvkW4352FKSC60QDraIO7eJOmAixIJz5RFRrudJmWfKJkpiuKZHVlx8nO0wQbcFzt qLNYDqW+shNAbNnPmhFgaxr/xkRqxsQJ9oLNgCTLnZXKEUR5ZknhTrQbnFUU6RkjXXQiol jNr+qp+D+BH1yGYXIesILMJvxw273IE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720067530; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ywx5qYincblCns1hUo2a7V32kYl58scbVMBY9LF3T58=; b=jvDVW3J69xcP45jkzhmWbnnV1lDl4uY2pXNQ4DMnh1no9iNhknQuhbQaJO2boD0G3/hFKq b91zyh46S6CvurBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720067530; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ywx5qYincblCns1hUo2a7V32kYl58scbVMBY9LF3T58=; b=GTzwuWvkW4352FKSC60QDraIO7eJOmAixIJz5RFRrudJmWfKJkpiuKZHVlx8nO0wQbcFzt qLNYDqW+shNAbNnPmhFgaxr/xkRqxsQJ9oLNgCTLnZXKEUR5ZknhTrQbnFUU6RkjXXQiol jNr+qp+D+BH1yGYXIesILMJvxw273IE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720067530; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ywx5qYincblCns1hUo2a7V32kYl58scbVMBY9LF3T58=; b=jvDVW3J69xcP45jkzhmWbnnV1lDl4uY2pXNQ4DMnh1no9iNhknQuhbQaJO2boD0G3/hFKq b91zyh46S6CvurBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1083C13889; Thu, 4 Jul 2024 04:32:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QIUEO8glhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:08 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , SeongJae Park , Miaohe Lin , Michal Hocko , Matthew Wilcox , Christophe Leroy , Oscar Salvador Subject: [PATCH 16/45] fs/proc: Enable pagemap_scan_pmd_entry to handle hugetlb vmas Date: Thu, 4 Jul 2024 06:31:03 +0200 Message-ID: <20240704043132.28501-17-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240704043132.28501-1-osalvador@suse.de> References: <20240704043132.28501-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 6D6221C000C X-Stat-Signature: pztweqmgo1ej415e6fqnz1c6p5x7s58r X-HE-Tag: 1720067531-648812 X-HE-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OeOkKEjClLWkFYakvP1hWzwymMAgTa3aS4tgp42swoatxf4C1l6rB9SX0J+ogEW5khx45GADzNDSqnC4H/dT3OMYM2fACMjNY03gqxf9oLz1TeATVEbyycrjxBgosQ31fVx2cohSFvf+gFDclevnbvKKR385vrrjOoP1Kf/d4UwaDgu6mKntBMDxJTziZ1cdi55Amv8VihLUOulfvQo4gVP8fbQK5R0P+Io7rJjF2FhDpHreNpw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: PMD-mapped hugetlb vmas will also reach pagemap_scan_pmd_entry. Add the required code so it knows how to handle those there. Signed-off-by: Oscar Salvador --- fs/proc/task_mmu.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 22200018371d..df649f69ea2c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2263,8 +2263,8 @@ static void make_uffd_wp_pte(struct vm_area_struct *vma, } } -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, +#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES +static unsigned long pagemap_pmd_category(struct pagemap_scan_private *p, struct vm_area_struct *vma, unsigned long addr, pmd_t pmd) { @@ -2296,7 +2296,8 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, if (pmd_swp_soft_dirty(pmd)) categories |= PAGE_IS_SOFT_DIRTY; - if (p->masks_of_interest & PAGE_IS_FILE) { + if ((p->masks_of_interest & PAGE_IS_FILE) && + !is_vm_hugetlb_page(vma)) { swp = pmd_to_swp_entry(pmd); if (is_pfn_swap_entry(swp) && !folio_test_anon(pfn_swap_entry_folio(swp))) @@ -2321,7 +2322,7 @@ static void make_uffd_wp_pmd(struct vm_area_struct *vma, set_pmd_at(vma->vm_mm, addr, pmdp, pmd); } } -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +#endif /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */ #ifdef CONFIG_HUGETLB_PAGE static unsigned long pagemap_hugetlb_category(pte_t pte) @@ -2522,22 +2523,22 @@ static int pagemap_scan_output(unsigned long categories, return ret; } -static int pagemap_scan_thp_entry(pmd_t *pmd, unsigned long start, +static int pagemap_scan_huge_entry(pmd_t *pmd, unsigned long start, unsigned long end, struct mm_walk *walk) { -#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES struct pagemap_scan_private *p = walk->private; struct vm_area_struct *vma = walk->vma; unsigned long categories; spinlock_t *ptl; int ret = 0; - ptl = pmd_trans_huge_lock(pmd, vma); + ptl = pmd_huge_lock(pmd, vma); if (!ptl) return -ENOENT; categories = p->cur_vma_category | - pagemap_thp_category(p, vma, start, *pmd); + pagemap_pmd_category(p, vma, start, *pmd); if (!pagemap_scan_is_interesting_page(categories, p)) goto out_unlock; @@ -2556,19 +2557,29 @@ static int pagemap_scan_thp_entry(pmd_t *pmd, unsigned long start, * needs to be performed on a portion of the huge page. */ if (end != start + HPAGE_SIZE) { - spin_unlock(ptl); - split_huge_pmd(vma, pmd, start); pagemap_scan_backout_range(p, start, end); - /* Report as if there was no THP */ - return -ENOENT; + if (!is_vm_hugetlb_page(vma)) { + /* Report as if there was no THP */ + spin_unlock(ptl); + split_huge_pmd(vma, pmd, start); + ret = -ENOENT; + goto out; + } + ret = 0; + p->arg.walk_end = start; + goto out_unlock; } make_uffd_wp_pmd(vma, start, pmd); - flush_tlb_range(vma, start, end); + if (is_vm_hugetlb_page(vma)) + flush_hugetlb_tlb_range(vma, start, end); + else + flush_tlb_range(vma, start, end); out_unlock: spin_unlock(ptl); +out: return ret; -#else /* !CONFIG_TRANSPARENT_HUGEPAGE */ +#else /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */ return -ENOENT; #endif } @@ -2585,7 +2596,7 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start, arch_enter_lazy_mmu_mode(); - ret = pagemap_scan_thp_entry(pmd, start, end, walk); + ret = pagemap_scan_huge_entry(pmd, start, end, walk); if (ret != -ENOENT) { arch_leave_lazy_mmu_mode(); return ret;