From patchwork Thu Jul 4 04:31:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723192 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 9A206C30653 for ; Thu, 4 Jul 2024 04:32:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B6EA6B00A4; Thu, 4 Jul 2024 00:32:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6328E6B00A3; Thu, 4 Jul 2024 00:32:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AF5C6B00A4; Thu, 4 Jul 2024 00:32:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 234626B00A2 for ; Thu, 4 Jul 2024 00:32:11 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C6A31160AEF for ; Thu, 4 Jul 2024 04:32:10 +0000 (UTC) X-FDA: 82300798020.18.BF8822C Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf17.hostedemail.com (Postfix) with ESMTP id B532B40009 for ; Thu, 4 Jul 2024 04:32:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1720067516; a=rsa-sha256; cv=none; b=t7kPUBrDgHSc0NeSN42btMS38sEcfHIILjz5YHs0ak5GRQPcYz6biIAVMR/OHuRCzDeHL1 0/4+gZnppYf8cJBbm5x24WZNbA+LnlCDARWvLM0Xt/wXZ0C5YtUMM7+BoiYwM+vjx5Ulcr FvI5TKFv9SShMDPILpLKArMtb8wsUVo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1720067516; 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; bh=YM4pkR47P5mKiI327bLPmyVEZ8VoXoGDDAHCQmx/AdI=; b=TtE6A/pZXaKnxYuoGhaTt+saufwo+Ua7K/JYgTQSgCvsOv0JFyCAH0vWO5/wV+wofhHeXN 9TfyMX9khYUtFi36Vx9JKfbBDM1c4mtVE46l7yGRw0yNlDrdF+siKSOCV5hrsnhS+SlMji jUyzsplAqG0KW/7RItR2703YC9OpDtY= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id 820001FCF7; Thu, 4 Jul 2024 04:32:07 +0000 (UTC) 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 5043013889; Thu, 4 Jul 2024 04:32:06 +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 cPLADsYlhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:06 +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 14/45] fs/proc: Create pagemap_pud_range to handle PUD-mapped hugetlb vmas Date: Thu, 4 Jul 2024 06:31:01 +0200 Message-ID: <20240704043132.28501-15-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-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Stat-Signature: 47prs4dja1bjx8xou5976r6oftr7n8su X-Rspamd-Queue-Id: B532B40009 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720067528-21556 X-HE-Meta: U2FsdGVkX18QOIcoMAF6nEPZAHqdAYVhkkcl/DXDJ+9ngjQ/RP0naXjbl3NfHRiLe66mhCH92eNTMcNQLarN7kIsFIi/pbSEUKb00g/A0/VMEeqRaoxOdp5EaO9H8uE1XljajIuCvQuCBfMYAeI+uWrGOrUu81ewmcKlFHPeeGV7jnNu++tC8gRtigKsHM0Ci2R4Qsbo4+vacqHvk2mZG7ifu5/a9rscjXrXLghp1iP08wOqOTDJhNuTsynGAuwV9tI48aJfBVOTwCmZTBjb8+iH9nH71e+FpFeIiQHeVvi1qcyykp+pFDTE58HdMWwjdYarDyjL1z02dcn9KLU1wI5jtGbBW/Md8Pv3FDRilJfDGeRhq/O3k8m/Mttpc0/JAJ3vC5a5zhtE1ZW7lO5lToLG3pRtLx5JDKrWtpGPtuZLPCPIcS5JfYBDpYq+naFk/QqSEVRW9uFgGYfVpQZDXy6l0qf7VOsqoylvk1y8Oa4Zp6z5AJc//DjRUS+B1ZhNci58lxGFz6x4FPUw4QLBO1s73vV5XG9NDZpI/1yxqxlwnDSTkJFfiW6A4/XF5omYT7Oz2q3oEFa3MOUGWAHjL8BJnfRTPgmFSeNWb7JQOtUVoAVyQjNHYwx2J+9xor2ldK2uLELPYwNbdltG4AjNvX14DSL0ttzXSGiLZT6/Y4Coay0CPKTPiP98s8rVPFC0+2elXLxBgA1NUv5UG5Xb/6A2JPK4jRXBiYi0+CNdZ+52+wqRBLf0VmnSCLRrr+qTbq78aoSp3o6kwI+VVc7fMKpGnNMvD7NccWkPCdlBxEtxcSHh/z85POZIP5/vklcPvN3qCk840Sqshv1a/5a+GeI/ZdSbffIsSiytbPCdu24l6lUttS9yDmwhuK8mOr54HWaxRw+EtwOYlfF5ctWuLTs6zLXCU7AxXaL1ArJ4+84KVWJQfri8HscJt5Xa1WBkNFi0BVunvOfqhABv220 uCbQenDq A4WJnf9nEjvMjim4j7CmaQ9ri9sJzZZhy4EA97sWJPcdU8nniVma4Fff44Ft9BFOF5hBUOzArnzbmMKCrxvGXyj1MRzBpfe7UPHpytVEpXamDOf81LGhOibvMq9bWQaNNTQdalhHU/KJmIiwK6sswuP7q36lyyi9/1Jl+9t7arFgjARs= 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: Normal THP cannot be PUD-mapped (besides devmap) but hugetlb can, so create pagemap_pud_range in order to handle PUD-mapped hugetlb vmas Signed-off-by: Oscar Salvador --- fs/proc/task_mmu.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ec429d82b921..5965a074467e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1924,6 +1924,65 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, return err; } +#ifdef CONFIG_HUGETLB_PAGE +static int pagemap_pud_range(pud_t *pudp, unsigned long addr, unsigned long end, + struct mm_walk *walk) +{ + pud_t pud; + int err = 0; + spinlock_t *ptl; + u64 flags = 0, frame = 0; + struct pagemapread *pm = walk->private; + struct vm_area_struct *vma = walk->vma; + + ptl = pud_huge_lock(pudp, vma); + if (!ptl) + return err; + + pud = *pudp; + + if (vma->vm_flags & VM_SOFTDIRTY) + flags |= PM_SOFT_DIRTY; + if (pud_present(pud)) { + struct folio *folio = page_folio(pud_page(pud)); + + flags |= PM_PRESENT; + if (!folio_test_anon(folio)) + flags |= PM_FILE; + + if (!folio_likely_mapped_shared(folio)) + flags |= PM_MMAP_EXCLUSIVE; + + if (pud_soft_dirty(pud)) + flags |= PM_SOFT_DIRTY; + if (pud_uffd_wp(pud)) + flags |= PM_UFFD_WP; + if (pm->show_pfn) + frame = pud_pfn(pud) + + ((addr & ~PUD_MASK) >> PAGE_SHIFT); + } else if (pud_swp_uffd_wp(pud)) { + /* Only hugetlb can have swap entries at PUD level*/ + flags |= PM_UFFD_WP; + } + + for (; addr != end; addr += PAGE_SIZE) { + pagemap_entry_t pme = make_pme(frame, flags); + + err = add_to_pagemap(&pme, pm); + if (err) + return err; + if (pm->show_pfn && (flags & PM_PRESENT)) + frame++; + } + spin_unlock(ptl); + + cond_resched(); + return err; +} +#else +#define pagemap_pud_range NULL +#endif + #ifdef CONFIG_HUGETLB_PAGE /* This function walks within one hugetlb entry in the single call */ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask, @@ -1980,6 +2039,7 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask, #endif /* HUGETLB_PAGE */ static const struct mm_walk_ops pagemap_ops = { + .pud_entry = pagemap_pud_range, .pmd_entry = pagemap_pmd_range, .pte_hole = pagemap_pte_hole, .hugetlb_entry = pagemap_hugetlb_range,