From patchwork Wed Mar 6 10:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13583876 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 6461EC54E41 for ; Wed, 6 Mar 2024 10:42:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA3B96B00A0; Wed, 6 Mar 2024 05:42:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E537D6B00A1; Wed, 6 Mar 2024 05:42:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCED76B00A2; Wed, 6 Mar 2024 05:42:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B39546B00A0 for ; Wed, 6 Mar 2024 05:42:32 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7C941140C4F for ; Wed, 6 Mar 2024 10:42:32 +0000 (UTC) X-FDA: 81866275344.06.682BDDE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id DC155C001A for ; Wed, 6 Mar 2024 10:42:30 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VRjm1fdi; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709721750; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vtZJyICZEGrBJHpYWSu5beimQ7UmPGzVa4S5UCB/Dcs=; b=xAUkvCXEq7Rg0pMtXxePJBdbB3xQB4SFjWYb5ptk+P1RoJ0CX/0J9Cc8jGVRJm5snaV681 lxhsV/TM4uQs9MlZZ41QbbDw6lAqFZBf9IdrnzSvaDXer1uO+/LOjKfAQnP31WsnzanRK+ EQmb8q59x1SZvMJZZE2HBoolItt9gt8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709721750; a=rsa-sha256; cv=none; b=qcnmU+rNF0dvJilOjblvPjvAMOEPAak7z1FiQx9J0//7LGk3X8aIsD++uEgdJuRPpC2AwF t3OPx3ciFszpI3/INInUfcjs2KHOfEsSB8ANrEuXuOnc6AO6AXC4PZcf7d+sVa3nUeIGeH Xq5A8kefA4RdGJmX/VPb7QK3Zwh9V9M= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VRjm1fdi; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709721750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vtZJyICZEGrBJHpYWSu5beimQ7UmPGzVa4S5UCB/Dcs=; b=VRjm1fdi9IkjkEYwRTvp3lQqzyJKLYUGUs7D0K5tF8+0MQOJ8Blf4Uq/jnwHJSv8lBach3 Fm6jcvee1YDSWtw+GWZ+F7DwpVfOz5VLXBIkWMGyvLegp9sQ7Q9kSZJxmhOXQ1mAGj25gH 7jyWP0ekFp+V5COySdFO+W3snmuhmIY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-pSuV4CgQPZqjr3JAlJcBuA-1; Wed, 06 Mar 2024 05:42:27 -0500 X-MC-Unique: pSuV4CgQPZqjr3JAlJcBuA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 22C123C0DF60; Wed, 6 Mar 2024 10:42:26 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 252A3112131D; Wed, 6 Mar 2024 10:42:17 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Andrew Morton , Muchun Song , Jason Gunthorpe , peterx@redhat.com, Matthew Wilcox , Mike Rapoport , Christophe Leroy , x86@kernel.org, sparclinux@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Naoya Horiguchi , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Subject: [PATCH RFC 04/13] mm/x86: Change pXd_huge() behavior to exclude swap entries Date: Wed, 6 Mar 2024 18:41:38 +0800 Message-ID: <20240306104147.193052-5-peterx@redhat.com> In-Reply-To: <20240306104147.193052-1-peterx@redhat.com> References: <20240306104147.193052-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: DC155C001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: mo4wpqej4toqqq8uzcdfxkekwuindhh5 X-HE-Tag: 1709721750-724240 X-HE-Meta: U2FsdGVkX19zNzl32lD5E0/KwUi5EMQ73LxCDrMSuZwZ+gZqH0GoFzdWEFX8k13my2qTZU0/Ur3SZRFN/xgmOrFMWmpOXBb9UpMJZPnBmrsNKosXyO8xBmLjGwtrLZ6FEwRQbSDTfijs5xNKsWGImXhPYpJH5HyGxr6k4fm2D7CSO79zQvynwwXwv2qHlClhXxEDm3EsJMBZdHDlUNc15rVYIId1O6yqkMfe5gLurfV0kaUrbjBclSsgJOrnMj+rIhyxVySIsmvJkAeIALGcNmb1LsdJts8oovfBZaaS3RLNWHc0p6PRC/+NadrzTImTxM0w5qf8BGZsubmDZBLlNOI/fg1bnL95871IQPIsld76fTtP0bSHpwe0+zz47lQRQfWycwACzjVmE+ihNh1DwhXZalKFH+28070YjektATRzmpU8h4p/GCg7IhZEAOhnP7zLg/znkcJF6Tr5ZWVeI+bfjcxHNvZl4ndIEvIWAzAJ/ktLuPXRKrZJvkX1JpiYhv60XMCAMQSmElANCTFQ0RniWonzZ5SUQy30W4oL3HR4S4zPRsH5LzmzOVXEceD9r/gxnD8Gp+/uaCrb8kcfYr8SkY5ao2wgrx+k6YwvYpjEH+a8RA7eADIaZljBmRN8y8xoP8YO0BQA4SyHUQGio3bBcpY6QM1H15oT8spAij7gCM+RV9fhLGTeO88XPY0yYcRHjPL2fLKDSsg/H6fHGBE4MLeOs9VJgpSCFD9hUb+COzPSPR5ftTg7iSDwMhnCe8XwbG2dgDIuWCdFT2RqTKqABjZIOmqof4R2uxvDZLxJNuYWzB78jldNhawN4B4Wou0TEjdHy1sBez4Tg/VMX5S1rj56VQNyrHkgGfD8YpUi0k9kNG2JJPf2fl+UAcAZprih/StuJ4H3oSTpi5T538s/ITII+E24 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: From: Peter Xu This patch partly reverts below commits: 3a194f3f8ad0 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry") cbef8478bee5 ("mm/hugetlb: pmd_huge() returns true for non-present hugepage") Right now, pXd_huge() definition across kernel is unclear. We have two groups that think differently on swap entries: - x86/sparc: Allow pXd_huge() to accept swap entries - all the rest: Doesn't allow pXd_huge() to accept swap entries This is so confusing. Since the sparc helpers seem to be added in 2016, which is after x86's (2015), so sparc could have followed a trend. x86 proposed such swap handling in 2015 to resolve hugetlb swap entries hit in GUP, but now GUP guards swap entries with !pXd_present() in all layers so we should be safe. We should define this API properly, one way or another, rather than keep them defined differently across archs. Gut feeling tells me that pXd_huge() shouldn't include swap entries, and it turns out that I am not the only one thinking so, the question was raised when the current pmd_huge() for x86 was proposed by Ville Syrjälä: https://lore.kernel.org/all/Y2WQ7I4LXh8iUIRd@intel.com/ I might also be missing something obvious, but why is it even necessary to treat PRESENT==0+PSE==0 as a huge entry? It is also questioned when Jason Gunthorpe reviewed the other patchset on swap entry handlings: https://lore.kernel.org/all/20240221125753.GQ13330@nvidia.com/ Revert its meaning back to original. It shouldn't have any functional change as we should be ready with guards on !pXd_present() explicitly everywhere. Note that I also dropped the "#if CONFIG_PGTABLE_LEVELS > 2", it was there probably because it was breaking things when 3a194f3f8ad0 was proposed, according to the report here: https://lore.kernel.org/all/Y2LYXItKQyaJTv8j@intel.com/ Now we shouldn't need that. Instead of reverting to _PAGE_PSE raw check, leverage pXd_leaf(). Cc: Naoya Horiguchi Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Signed-off-by: Peter Xu --- arch/x86/mm/hugetlbpage.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index 5804bbae4f01..8362953a24ce 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -20,29 +20,19 @@ #include /* - * pmd_huge() returns 1 if @pmd is hugetlb related entry, that is normal - * hugetlb entry or non-present (migration or hwpoisoned) hugetlb entry. - * Otherwise, returns 0. + * pmd_huge() returns 1 if @pmd is hugetlb related entry. */ int pmd_huge(pmd_t pmd) { - return !pmd_none(pmd) && - (pmd_val(pmd) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; + return pmd_leaf(pmd); } /* - * pud_huge() returns 1 if @pud is hugetlb related entry, that is normal - * hugetlb entry or non-present (migration or hwpoisoned) hugetlb entry. - * Otherwise, returns 0. + * pud_huge() returns 1 if @pud is hugetlb related entry. */ int pud_huge(pud_t pud) { -#if CONFIG_PGTABLE_LEVELS > 2 - return !pud_none(pud) && - (pud_val(pud) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; -#else - return 0; -#endif + return pud_leaf(pud); } #ifdef CONFIG_HUGETLB_PAGE