Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp1043437lqs; Wed, 6 Mar 2024 04:57:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWtC98VIEaFTDx/a/8cwjX/v2k+UBysH+u1ba7D5QwEvUJf6MKJC1oKt7KZDQ2MwL7oi4KgAGU84H231hRVOIs7ljDuld1nP48CjsVXvg== X-Google-Smtp-Source: AGHT+IGX6VumPEXMQnofeQ4vB78UgpUvA7S230LbC31nU68tHr0TuZWB20SZURkG790I9Vrcjh0o X-Received: by 2002:a05:6a20:4299:b0:1a1:67b8:2a18 with SMTP id o25-20020a056a20429900b001a167b82a18mr1341208pzj.28.1709729870050; Wed, 06 Mar 2024 04:57:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709729870; cv=pass; d=google.com; s=arc-20160816; b=rFZ1QD0YKMW/zkFCoWBsiys5gvJ7iTpAZQoAtuJOjrBRaUj2X93CCF6jwVNtvpMV8G kKxop9GBwUDTyhgBB01OiMIAhxkkGJenePH9XNQ04MNyA2U0oZslINsNfk6as48s/cZ4 hqlqyyvg4V7cIzUe5tMeNoeHidr6mPgnF8r2mRGqj316MV5GIkvwe/ium6o1axpXOrAh wWHGxwa/Qul2d0JMFPeB6EbFUxVpc1LrWZaah8tnPqQkFXkiePQXZpHCadC6DuDYEu7h 9FYLjddFMa1GuHX18UsWlwG5SMJn40ZX6+4h0pidp9weYBvkUz0uoug8RDUjXmacMHBT UJUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=7qMkj855gnIh1UQkcFt0aaaoTWPFayqXkWGgolRjo9E=; fh=+CCST2uuQw0OpcnFOMpEjA5d2TGrixbNrbqUrDf02XM=; b=uQKRkRgJJyHiN5B+QD/nnurP0wWwgU/efXDm/+oIaZDcSVcOXauXzwd1zaRoqNLXQQ gqZhrmXqwbmOxr/Wq/hta4ulBJdMQLU6jW/9WkRuaWwSkv4zQEazM6ld6Yqe+XRi8WZf syTNs6o16HjiPEks3dWxHfbf1LjvmmAZFK66D61om4tAh6IACeKbkSwDrn/wO4F/eMRV k2LqpznF7uMnmnq3JcnTaS4H/ZjUqLPbkdgwNU4Baha+jlU0ylA0HdhNLnrAW3lLHgBZ X174vJNM+G8ATxPX4xLeUKtwBaCAnIRX0OS/5JomOLGC7bzvpFWYq2Z/+9X5kFke6Dfg rSbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=UfEtVolq; arc=pass (i=1 spf=pass spfdomain=ellerman.id.au dkim=pass dkdomain=ellerman.id.au); spf=pass (google.com: domain of linux-kernel+bounces-93933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93933-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l15-20020a056a00140f00b006e5787d1b4csi11978338pfu.128.2024.03.06.04.57.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 04:57:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=UfEtVolq; arc=pass (i=1 spf=pass spfdomain=ellerman.id.au dkim=pass dkdomain=ellerman.id.au); spf=pass (google.com: domain of linux-kernel+bounces-93933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93933-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 33BDD281F62 for ; Wed, 6 Mar 2024 12:57:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37FF012F5B8; Wed, 6 Mar 2024 12:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="UfEtVolq" Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 921DB12D767; Wed, 6 Mar 2024 12:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=150.107.74.76 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729825; cv=none; b=MWKbXzQKr0ZG8CX5wwvm2fBX1wRegu6pwzSQ/Dld07P/C4SbQ0E0ab0Mchmhpwrd718RPdxOMylCfO/HYjI8yFUiKuQ//pHaf6ZgiL3KttmHSMva8C3UrAiu8djkVFSCWWJM6kWAhKVC18779fdyQ/yWBPSCTudh00t9Jpif9V8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729825; c=relaxed/simple; bh=33SuGDVKhyAmIEY/wnNy0LGNUvfWeALTFWmEh2mPwPA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=JoTvS75aw5Z+85b0WqdtgjEHGNwhtcs3jdmGjHsYmRVyVMjWpUHs/NR4RXPY+NcNPzhreluNQm0mt4zUHsjTUlr0tgJuqgqLSMAYJmq/ZvHDooQ+R/AtkL4M2ohH/r9HdFJItABXiltSVo5Q9H7jqSvfHtkNoT9ZHAsGVevfAHs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au; spf=pass smtp.mailfrom=ellerman.id.au; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b=UfEtVolq; arc=none smtp.client-ip=150.107.74.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ellerman.id.au DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1709729819; bh=7qMkj855gnIh1UQkcFt0aaaoTWPFayqXkWGgolRjo9E=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=UfEtVolq5MqXw9jCn/GeBb+IBQz1dQvJaH/0rnEilELcXz+ev5Hbtp9B7h7mEpBX6 Qz3f0JVrd097eeURWnaXC2C/GW5fBXQWNrwBK0QxwWX1YaRiQ6aIQQ0XFTkV+WzC5v GXYLf6FZmSDmamdgEA80gV9hcMOlFslVWN4X9wP38RFheO1qGLQawaGr7s8/LUFbMT gHkmLZS2HLXRCVJcdsFeWrt3RUA35VQsD9LPG6nt3TSnIA5kK6I5fFJLsrkNZ/vfmm hPS72F4Sajlz8pB2B5k39v9Xa14Hc85llYzAKp2qodd6KdX7Cyd3f5C9srqntJv+gy 0gOjJMv33jZmA== Received: from authenticated.ozlabs.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 mail.ozlabs.org (Postfix) with ESMTPSA id 4TqXWY0xZyz4wc8; Wed, 6 Mar 2024 23:56:56 +1100 (AEDT) From: Michael Ellerman To: peterx@redhat.com, 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, Nicholas Piggin , "Aneesh Kumar K.V" , "Naveen N. Rao" Subject: Re: [PATCH RFC 09/13] mm/powerpc: Redefine pXd_huge() with pXd_leaf() In-Reply-To: <20240306104147.193052-10-peterx@redhat.com> References: <20240306104147.193052-1-peterx@redhat.com> <20240306104147.193052-10-peterx@redhat.com> Date: Wed, 06 Mar 2024 23:56:56 +1100 Message-ID: <87v85zo6w7.fsf@mail.lhotse> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable peterx@redhat.com writes: > From: Peter Xu > > PowerPC book3s 4K mostly has the same definition on both, except pXd_huge= () > constantly returns 0 for hash MMUs. AFAICT that is fine to be removed, > because pXd_huge() reflects a hugetlb entry, while it's own hugetlb pgtab= le > lookup function (__find_linux_pte() shared by all powerpc code) already u= se > pXd_leaf() irrelevant of the MMU type. It means pXd_leaf() should work a= ll > fine with hash MMU pgtables or something could already went wrong. Yes I think that's correct. 4K Hash MMU doesn't support any hugepage size at PMD or PUD level (the geometry is wrong), so pmd/pud_huge() were written with that in mind, ie. they are hard coded to return false. But it should be OK to use pmd/pud_leaf(), they will actually look for _PAGE_PTE, but it should never be set for 4K Hash. See eg. arch/powerpc/include/asm/book3s/64/hash-4k.h: static inline pmd_t hash__pmd_mkhuge(pmd_t pmd) { BUG(); return pmd; } > The goal should be that we will have one API pXd_leaf() to detect all kin= ds > of huge mappings. AFAICT we need to use the pXd_leaf() impl (rather than > pXd_huge() ones) 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. > > 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 > --- > arch/powerpc/include/asm/book3s/64/pgtable-4k.h | 14 ++------------ > 1 file changed, 2 insertions(+), 12 deletions(-) > > diff --git a/arch/powerpc/include/asm/book3s/64/pgtable-4k.h b/arch/power= pc/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); > } >=20=20 > 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); > } This doesn't actually compile though. arch/powerpc/include/asm/book3s/64/pgtable-4k.h:11:16: error: implicit de= claration of function =E2=80=98pmd_leaf=E2=80=99; did you mean =E2=80=98pgd= _clear=E2=80=99? [-Werror=3Dimplicit-function-declaration] etc. To make it compile we'd need to relocate the pmd/pud_leaf() definitions: diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/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 o= ld_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_ */ cheers