From patchwork Thu Jul 4 04:30:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723188 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 D5EF4C30653 for ; Thu, 4 Jul 2024 04:32:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1087B6B009D; Thu, 4 Jul 2024 00:32:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEA0B6B009E; Thu, 4 Jul 2024 00:32:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D10C96B009F; Thu, 4 Jul 2024 00:32:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A03766B009D for ; Thu, 4 Jul 2024 00:32:05 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6DEBF1C264C for ; Thu, 4 Jul 2024 04:32:05 +0000 (UTC) X-FDA: 82300797810.25.6FF070F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf19.hostedemail.com (Postfix) with ESMTP id 611CA1A0003 for ; Thu, 4 Jul 2024 04:32:03 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.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=1720067511; 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=uuCDOs4UnzbN/DaULDdat4m597hHyp5dumV+Rvovzyo=; b=JZuh1Dn5tJ4tsC015XS24cfSdNh1ahFd4wkdZYd2gx9HU0jzr/kwwWtg9Qa1tK64mVJZ1K 7XxATyClSW93UdA16E9kK1nOKkY4+3Cy+gIpkaR2FQJo46RLCbopd1fX07298owTyGO+/t Ow0fCF4zNsUEpETA9cPPi3zFbm75BNs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.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=1720067511; a=rsa-sha256; cv=none; b=o+cm//Z0jg4TsSMXDWKp0a8btclsyay82ghNs2P78aWVStJFHT6k3WSpc1hKBiSBsHyoRc rR1TEpt+tSs1fMuKqebyCE2JaTKLh5HEi2UuEeth/xpJc0Zmh+gJDCKCstgoROrhFzlsW+ 9zPmyjvYAQyfiEc3k0lqGhjeVVS5vCw= 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-out1.suse.de (Postfix) with ESMTPS id 26D7421C0D; Thu, 4 Jul 2024 04:32:02 +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 01D7013889; Thu, 4 Jul 2024 04:32:00 +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 MCZPN8AlhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:00 +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 10/45] fs/proc: Create smaps_pud_range to handle PUD-mapped hugetlb vmas Date: Thu, 4 Jul 2024 06:30:57 +0200 Message-ID: <20240704043132.28501-11-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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 611CA1A0003 X-Stat-Signature: pnupb695p6sm56opxk1u8dhdtm3ctfsx X-HE-Tag: 1720067523-249987 X-HE-Meta: U2FsdGVkX1+qp3yJWdWJiAmSutwzS/N2X5jNSAe+UZZx9BAYqShBXH4BETVx+KVKResbQ2kYI/sX30LBNfV7XG3plZV+mumK5SmbuhnSl4pYpv94xDvMbEm0YEm6KfHTA+OpIUSo7VR3J60Za8YFkH0vdvpgEQLNvU1OyIwYrfw8lXv1kRzwxB/6VCg0mbLktO/e+M5YVPkSvMfzLLi/aIb2ipcAxyfRiriQrnFJdjFskAqpr1MCsQpK+v/CrnPbgyiylfG7z1Ch/7I5a/l9WJCjedXbC9enoBfvxsHo6nEIHVINLENpL187jxiy10HaPG/c580VsGKneBMlcnvWCn7tNNQHsRtMAynxtCoap3u57aXlBmP+wRxX4gV+crKnJzy+RRDTQS3vyZAjTTHypMaXAAbywUCTXK8bPrCSMR3nfd0zNGM7Hz6aRmmAdMJcl8qF/x6/Bjzd5DhKy9wP8pwOkaydJsLxfIYJmmOUpu7VViHqnOOlge/1v/lO8pMkKbU1hOzu3vbdPqzpTNiWHdXUQ0dPH/2wJu670ktnyiZ6aFaxsKd41HRBju3hdllYs1HV1W/Uc3sq9DHWhUOdjQTrgSontrgUAAAzvzEYjQ4uENIoj9+AQxCGE5G+oLewIlN4Ix3vW3KqhNDJRyO9FneEhQbUcMzYNDTesT7YZRtE9ToKgz7+8rK6QtctCXm8f+j4zvwpJm/P9ZVWrE1y/HzYILVnhE1/1UnVMGnHWPMHR64Tcff+PkhvolmCitReFBrDZPvZHyHoPVUhk5s7khgU2xsOjgEQL7ekgnkGakfiWXG5xD+mCUVgzIP+ZnPRj+cYqII+9uwRN+FESGgVHFLA16mGUfq3v1bho9cYZOh+paeXitlmuOCPhshVBc56ci25yWHNGveQTCuT0eYFaIbhdOOcIJAnZeLArTIQ3F17T3+6xGM9LmbTipnnIlgoeTDuDcFUzugKiMjTka9 KHyLYMU5 96fLBTUXruv/650R27oVmwzmy9w7iChEPtOI49M08IHzf716YTnqPhaIDoHR+YfzTVns789x4/5LbvqfqjsmuOzGnqzXx4CtXzIHLR6cJ4pj80daA1ryF6oGYvrd7q0B4twPTljoWgRh6ff2YFid0rYYpFTjy8V9W/oqgHEXf/zxwOyc= 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 smaps_pud_range in order to handle PUD-mapped hugetlb vmas. Signed-off-by: Oscar Salvador --- fs/proc/task_mmu.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 78d84d7e2353..3f3460ff03b0 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -912,6 +912,40 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, } #endif +#ifdef CONFIG_HUGETLB_PAGE +static int smaps_pud_range(pud_t *pudp, unsigned long addr, unsigned long end, + struct mm_walk *walk) +{ + spinlock_t *ptl; + struct folio *folio; + struct vm_area_struct *vma = walk->vma; + struct mem_size_stats *mss = walk->private; + + ptl = pud_huge_lock(pudp, vma); + if (!ptl) + return 0; + + if (pud_present(*pudp)) { + folio = vm_normal_folio_pud(vma, addr, *pudp); + } else if (is_swap_pud(*pudp)) { + /* PUD-hugetlbs can have swap entries */ + swp_entry_t swpent = pud_to_swp_entry(*pudp); + + if (is_pfn_swap_entry(swpent)) + folio = pfn_swap_entry_folio(swpent); + } + + if (folio) + /* Only for now hugetlb pages can end up here */ + mss_hugetlb_update(mss, folio, vma, (pte_t *)pudp); + + spin_unlock(ptl); + return 0; +} +#else +#define smaps_pud_range NULL +#endif + static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, struct mm_walk *walk) { @@ -1061,12 +1095,14 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, #endif /* HUGETLB_PAGE */ static const struct mm_walk_ops smaps_walk_ops = { + .pud_entry = smaps_pud_range, .pmd_entry = smaps_pte_range, .hugetlb_entry = smaps_hugetlb_range, .walk_lock = PGWALK_RDLOCK, }; static const struct mm_walk_ops smaps_shmem_walk_ops = { + .pud_entry = smaps_pud_range, .pmd_entry = smaps_pte_range, .hugetlb_entry = smaps_hugetlb_range, .pte_hole = smaps_pte_hole,