From patchwork Mon May 27 13:30:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13675245 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 56601C27C44 for ; Mon, 27 May 2024 13:30:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB3A96B00A8; Mon, 27 May 2024 09:30:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3A7F6B00A9; Mon, 27 May 2024 09:30:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B3626B00AA; Mon, 27 May 2024 09:30:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7CE8A6B00A8 for ; Mon, 27 May 2024 09:30:42 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 40E391A14A7 for ; Mon, 27 May 2024 13:30:42 +0000 (UTC) X-FDA: 82164260724.07.0F05A88 Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf04.hostedemail.com (Postfix) with ESMTP id 3961A40007 for ; Mon, 27 May 2024 13:30:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=csgroup.eu; spf=pass (imf04.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716816640; 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=4sNbTH/Pa1oE6FceQHZykBcEzOhcbZ+nV4MIdF+SwVA=; b=E9xrcsZyUYfyjeH65G6bvFFwT10IGCF7QQElY2nX8FrkXCaHs2d3TLSan3/tdbnB9y22pK H65fPUViUmQpN/qzRWEX0S922cVTSVAHPDqZD1aV4I5jYlh4yacGF5M1vFZfMYQm1Egvzf KvqflsqKFmWeRjoiEWuzCzYHnKMFD4o= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=csgroup.eu; spf=pass (imf04.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716816640; a=rsa-sha256; cv=none; b=1laGSpipBn9dZZMEdkxLZluwUrgjOhD7ZEiKm4WNq2NQxmZMWkW1CGedcR6d7hg3IpND3u 15uDL5FekKqW+1sCW2wbIlHdJ15UnpQSZ6Gho6nczVcGHN1cFUmcbnJA+E80CxkeWEaTqe FPf/vorlvKCn5fzRIUD7Jxh+mi5w/t0= Received: from localhost (mailhub3.si.c-s.fr [192.168.12.233]) by localhost (Postfix) with ESMTP id 4VnxNT6zt4z9tCl; Mon, 27 May 2024 15:30:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mnRJFRISjg-U; Mon, 27 May 2024 15:30:33 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4VnxNT69BJz9sqS; Mon, 27 May 2024 15:30:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CED8E8B773; Mon, 27 May 2024 15:30:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id nNWVwUBAoKxI; Mon, 27 May 2024 15:30:33 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.232.49]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4EAC88B764; Mon, 27 May 2024 15:30:32 +0200 (CEST) From: Christophe Leroy To: Andrew Morton , Jason Gunthorpe , Peter Xu , Oscar Salvador , Michael Ellerman , Nicholas Piggin Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org Subject: [RFC PATCH v4 05/16] powerpc/mm: Fix __find_linux_pte() on 32 bits with PMD leaf entries Date: Mon, 27 May 2024 15:30:03 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716816600; l=2268; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=CgsurgT/HBdZ/v9IT1Gnjjxrc//xCkwC6Uo2ZbsMc0U=; b=IfJ51RBuoaijjVJUpXSYAenvJ2xeDUJnOsadh4SsDBYVzR3VhIS7lTxdFZA6qrF8yyk96WhQi Uy+dEMH3SUzA4HGrpgq60Nk62vjH7QKtycWTD5UA/ytzt+kydidbAMU X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Rspamd-Queue-Id: 3961A40007 X-Stat-Signature: 1ym11de3qupheiggabn4d8gafynb4qak X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1716816639-90821 X-HE-Meta: U2FsdGVkX1/Qp1PgpPwAj82WH43b2RtbHt5qN8rZxkJQupt6ibhpF/DPC5FEs0/pg1kslK7ZD6Qy+oEnTOKHwVQtTqukMV1H4fh/pe+2xdStmIL9TbnxSe4I9z4U6Gd0syNe1qpuR+PTSEWHdgTdIRPoFuJHa7F25xgELxy5m4leAggP38n3nyzN6LGJtevL6hTBwK1bLp+QhqSmOcSixO40EAL99LqPneyfgBvO/qgOOranlKd+fCknlrWgT1sHKRAqNXTIICCU8Gk59IThjeT6XXrkCq3O1B11HYxsuyySQU7jho/hsjNDQsUhZ9fOijd00U0X+VerpuX4f4PYjym0cxXJzFdq+HY8I82h6loWkXMH5Y64kr4Ozbgi9VJlQet/Sjy2k5KcpsP9CVXz8LmDu7OGLHwZViqSy87p/5UuappuZZlXRKdIXzJCPp9r5+N9gVmaCaXq8H39yZH8/cWl+zWUkPPndk9bVsswxBynGuU4ENS0WPzGWGyzwd3s0XQmIiezkdWgo8gH/tjgnEvHNffb4CVqTDti/zzyPTHnQQSswEBmynWm14vghYH6s9ZTBf5ofBlxw7LWZqZ79bj3glfG4IsQhAkeJAYsOQlB+SPr1pHvYMj9WZlIBzAIUa1PylwaCBAui+M50ZoP0Si/LYOkx98FMc9an2PFVbXYGX8g1gVgskU1DmeiyrZBcWmcAcDEVSujhpzB2FSGs9Rpf7UmGviwQf+vuL0Ttf6oBBwxsv3bMHOkDFnLrtd3su5M32sGHA52ovlVjo8ysL/qowb2u0rwH+uWHaVy7qzjoBHccV4AKZtRmBYFnDvRzzp+i/E6t9gX/MxKV/fThFPFlxGFZwD2NukUTzTtPr0= 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: Building on 32 bits with pmd_leaf() not returning always false leads to the following error: CC arch/powerpc/mm/pgtable.o arch/powerpc/mm/pgtable.c: In function '__find_linux_pte': arch/powerpc/mm/pgtable.c:506:1: error: function may return address of local variable [-Werror=return-local-addr] 506 | } | ^ arch/powerpc/mm/pgtable.c:394:15: note: declared here 394 | pud_t pud, *pudp; | ^~~ arch/powerpc/mm/pgtable.c:394:15: note: declared here This is due to pmd_offset() being a no-op in that case. So rework it for powerpc/32 so that pXd_offset() are used on real pointers and not on on-stack copies. Signed-off-by: Christophe Leroy Reviewed-by: Oscar Salvador --- v3: Removed p4dp and pudp locals for PPC32 and add a comment. v4: Properly set pdshift on PPC32 case --- arch/powerpc/mm/pgtable.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 9e7ba9c3851f..bce8a8619589 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -382,8 +382,10 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, bool *is_thp, unsigned *hpage_shift) { pgd_t *pgdp; +#ifdef CONFIG_PPC64 p4d_t p4d, *p4dp; pud_t pud, *pudp; +#endif pmd_t pmd, *pmdp; pte_t *ret_pte; hugepd_t *hpdp = NULL; @@ -401,8 +403,12 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, * page fault or a page unmap. The return pte_t * is still not * stable. So should be checked there for above conditions. * Top level is an exception because it is folded into p4d. + * + * On PPC32, P4D/PUD/PMD are folded into PGD so go straight to + * PMD level. */ pgdp = pgdir + pgd_index(ea); +#ifdef CONFIG_PPC64 p4dp = p4d_offset(pgdp, ea); p4d = READ_ONCE(*p4dp); pdshift = P4D_SHIFT; @@ -442,8 +448,11 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, goto out_huge; } - pdshift = PMD_SHIFT; pmdp = pmd_offset(&pud, ea); +#else + pmdp = pmd_offset(pud_offset(p4d_offset(pgdp, ea), ea), ea); +#endif + pdshift = PMD_SHIFT; pmd = READ_ONCE(*pmdp); /*