From patchwork Mon Mar 18 20:03:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13595767 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 0C3C8C54E58 for ; Mon, 18 Mar 2024 20:04:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 293966B0096; Mon, 18 Mar 2024 16:04:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 242EE8D0002; Mon, 18 Mar 2024 16:04:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BC8D6B0099; Mon, 18 Mar 2024 16:04:26 -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 E4F656B0096 for ; Mon, 18 Mar 2024 16:04:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B613F1A0811 for ; Mon, 18 Mar 2024 20:04:25 +0000 (UTC) X-FDA: 81911236890.23.50AD79B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 8AFE8A002F for ; Mon, 18 Mar 2024 20:04:22 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hsHeQL8E; spf=pass (imf15.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=1710792262; 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=vy04FBLzPG5Zls0F5g74nprsAX71rsrg1jdch17dleE=; b=GlnIy1wSsROukMSksD0DECvWsg0oFtTcoi9bCM+0YG/dLKGSkkx/rmfEREFVUh+845FfZ7 OWMGy8pFGZvMihHeQXNl21pqQPA6Ch9Our8km0F/UnN6zCaJihwDhbuk99JyrW01QVwoTA TJvDyUh7YAkz8tfICUmiG1+eDdCX2Kk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hsHeQL8E; spf=pass (imf15.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710792262; a=rsa-sha256; cv=none; b=BVstcjRmfBIULELnOuQ0oYCimZlY0V/h9RI+vNboY/zZiQHQExOI/xO77TK3YbD+oKdDrW ung81Dd6rXb1ndYfYLEjrJLnSDxIoxOCVB+jrL7nVpwF3kWfMl5JOu0YpFPrlQVSI96BMl tidf8XuW+PafKb3csciygTVADMMVlXc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710792261; 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=vy04FBLzPG5Zls0F5g74nprsAX71rsrg1jdch17dleE=; b=hsHeQL8EiI13epBDM2TKEQdbEJoX1HHnwiP3kwKLfl5LMQKoNGrcREF6RUz1nM4bjURhw9 0Fwj2OTdaHRzyOb+LBn6QmE5HwUamMcOilt2H2ZC6+TKoIe+Ezfl3c8QgcAdCT5VMdCOnw uee5hvLwHmVYwoB0kJ+sPShfSCWcRJg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-AJl-T9yUP6q1E2U-ty6z5g-1; Mon, 18 Mar 2024 16:04:20 -0400 X-MC-Unique: AJl-T9yUP6q1E2U-ty6z5g-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-42f30752eb4so15656711cf.1 for ; Mon, 18 Mar 2024 13:04:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710792260; x=1711397060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vy04FBLzPG5Zls0F5g74nprsAX71rsrg1jdch17dleE=; b=AL90Un7pIavKxvdKeGaPKBWVDaLBKxUFTTE+VdHEeDmdzkaC8bqVjaWysjf0GMfrXw gMHWV4X0Qad1/5wzwOyGrzEGkyWxGoXUBx0vNbEDptOYjG7jBmeqPFmAFvU5nKPS3gY+ FKsMqv38Wk2r4gxd3jNsDXa529tgk0ZDC/2/buMz4f0otWRqvDGwGWt9Y+KhcLKvAjyh 0h4Upan3nBGeinNCF+uG/uIWtGyI7hJiM4p2oGGwjBzsMrAJtUpHpDOeFNxXVK3J4mQY EElNpfbWLNA++lWthhUNk/iUbqJa8OyBwDwHiOJnfS3003/pwUNCr7OJ6Pt1VLI+DCue NwTg== X-Forwarded-Encrypted: i=1; AJvYcCXCfGmLbEXGw1piHwhTVzqad1Zrzeu0qEQcCNq3m5E9tBOqTdsSai2VljoFV34c1t1Xp30Fy1dwTnJXibnBYW/2NUQ= X-Gm-Message-State: AOJu0Yyfgef0cD/Yp7l5M1bGBSe6nDksMSn7IJFHzvaKl2VuAogWH1aM ArayP8yoIJrHFUkBe2JRMxrLxAchV1HPu5fRpRR1xu+0MH9rwQto2LO6Fz9sYFYwSMZJya2F+QG QTzc2CaPw1AzhINgiEPvNAOuQYaDvoffGhm0IUoXH5+oHeJ1V X-Received: by 2002:ac8:4c86:0:b0:430:c314:d150 with SMTP id j6-20020ac84c86000000b00430c314d150mr275846qtv.6.1710792259908; Mon, 18 Mar 2024 13:04:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpXWUncergFjfMSFDTE8/2jUGQ81NOYysiHRDsucc9G0cV8OOvdubCssw9QQ67SSZupi5Ulw== X-Received: by 2002:ac8:4c86:0:b0:430:c314:d150 with SMTP id j6-20020ac84c86000000b00430c314d150mr275803qtv.6.1710792259416; Mon, 18 Mar 2024 13:04:19 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hj10-20020a05622a620a00b0042ebbc1196fsm3484491qtb.87.2024.03.18.13.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 13:04:19 -0700 (PDT) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , x86@kernel.org, Muchun Song , Mike Rapoport , Matthew Wilcox , sparclinux@vger.kernel.org, Jason Gunthorpe , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , linux-arm-kernel@lists.infradead.org, peterx@redhat.com, Michael Ellerman , Nicholas Piggin , "Aneesh Kumar K.V" , "Naveen N. Rao" Subject: [PATCH v2 09/14] mm/powerpc: Redefine pXd_huge() with pXd_leaf() Date: Mon, 18 Mar 2024 16:03:59 -0400 Message-ID: <20240318200404.448346-10-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318200404.448346-1-peterx@redhat.com> References: <20240318200404.448346-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 8AFE8A002F X-R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KCgR5vihmCKn469iG7vOdC2vIrvGqxhbWWenSqlKjbFbpWAe3CUqMTPoyGyrOvfmOGWcR24FLBtkfSQBPiEYYrt5Ap0YujAlQGBhT5wMfu92QAZAjih9w8pzghQMqCPGPhZ+HOuIfb4GXHEFJcN7kalFthKVlM7JtRuAt58gza1EoF5tS//OiW7hu7i8gfp5swcK/Fik7UuQaTrKDW/bh8XVj6JbtX/VXXfK3B9Eh+BbZj6QLamaiBUnkU+5fr76lLXDurRZ1UDvK41EUEFIRHMsX46JvHd+X5o4wAFnbGGSgzu0PRqfqoZByDjj0x2ZKT3doVvLE5O4xYY/HYx94mcjC7VWrPIRoUM//NVR6ILWQan7T8y+wxhrfDF7c++chmjSS3LiTV5J3EFUJVn5Al/XrGxHhkOmjPRcG9vonU9058ZEAwPl6n+9yJtMuUN4HlRvR2esjWTr03z0x3TK6c4YGW/5+rINXF9Hc5xxLwUaoYkf93GwjbhHt9A0G+90QCyUksOVKsOv/+ZGKdmF8/GCazTx4xyp1PBTrYuwPw3iBroTjxxeafZMjtg85afmorekzfmuuiasNuzmyz07cv19NcJtxVNtuJDXRo/QJJJxRtX9lp88Ps4hStSko3ulO5P5g/UdTTYYpE0C1UDb9Odwj6A== 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 PowerPC book3s 4K mostly has the same definition on both, except pXd_huge() constantly returns 0 for hash MMUs. As Michael Ellerman pointed out [1], it is safe to check _PAGE_PTE on hash MMUs, as the bit will never be set so it will keep returning false. As a reference, __p[mu]d_mkhuge() will trigger a BUG_ON trying to create such huge mappings for 4K hash MMUs. Meanwhile, the major powerpc hugetlb pgtable walker __find_linux_pte() already used pXd_leaf() to check leaf hugetlb mappings. The goal should be that we will have one API pXd_leaf() to detect all kinds of huge mappings (hugepd is still special in this case, though). AFAICT we need to use the pXd_leaf() impl (rather than pXd_huge()'s) to make sure ie. THPs on hash MMU will also return true. This helps to simplify a follow up patch to drop pXd_huge() treewide. NOTE: *_leaf() definition need to be moved before the inclusion of asm/book3s/64/pgtable-4k.h, which defines pXd_huge() with it. [1] https://lore.kernel.org/r/87v85zo6w7.fsf@mail.lhotse Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: "Aneesh Kumar K.V" Cc: "Naveen N. Rao" Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Peter Xu --- .../include/asm/book3s/64/pgtable-4k.h | 14 ++-------- arch/powerpc/include/asm/book3s/64/pgtable.h | 27 +++++++++---------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable-4k.h b/arch/powerpc/include/asm/book3s/64/pgtable-4k.h index 48f21820afe2..92545981bb49 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable-4k.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable-4k.h @@ -8,22 +8,12 @@ #ifdef CONFIG_HUGETLB_PAGE static inline int pmd_huge(pmd_t pmd) { - /* - * leaf pte for huge page - */ - if (radix_enabled()) - return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); - return 0; + return pmd_leaf(pmd); } static inline int pud_huge(pud_t pud) { - /* - * leaf pte for huge page - */ - if (radix_enabled()) - return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE)); - return 0; + return pud_leaf(pud); } /* diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index df66dce8306f..fd7180fded75 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -262,6 +262,18 @@ extern unsigned long __kernel_io_end; extern struct page *vmemmap; extern unsigned long pci_io_base; + +#define pmd_leaf pmd_leaf +static inline bool pmd_leaf(pmd_t pmd) +{ + return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); +} + +#define pud_leaf pud_leaf +static inline bool pud_leaf(pud_t pud) +{ + return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE)); +} #endif /* __ASSEMBLY__ */ #include @@ -1436,20 +1448,5 @@ static inline bool is_pte_rw_upgrade(unsigned long old_val, unsigned long new_va return false; } -/* - * Like pmd_huge(), but works regardless of config options - */ -#define pmd_leaf pmd_leaf -static inline bool pmd_leaf(pmd_t pmd) -{ - return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); -} - -#define pud_leaf pud_leaf -static inline bool pud_leaf(pud_t pud) -{ - return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE)); -} - #endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */