Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp654455imw; Fri, 15 Jul 2022 10:17:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1soI1xOQJ6mOd976HBfEnouYdEhyc1oIVQF1WPBGL8ImZDyJLMG6ck710VibSAVE5cSAhfd X-Received: by 2002:a05:6870:9687:b0:10c:bee0:5365 with SMTP id o7-20020a056870968700b0010cbee05365mr10806524oaq.128.1657905423129; Fri, 15 Jul 2022 10:17:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657905423; cv=none; d=google.com; s=arc-20160816; b=xwxtceMd11bTcUZB3wy0JwfDb+/EfRXRwciT3gi9U481fOVvnt/mz5Renz6OFVJfU3 QcqdAsfCxnOhbx7WiIy73xAh5yAIF2oWq/8H3Y7an1ihg31yDLRGxQI+1xVKC/uCjTt8 6pRT6lg7jqNFYDXLpDxCwVx6hISjQwl7vXppD/rGOiNr4Pfmf00pM4O5kZs8W/ke0663 /E6MZQY98+so03GKETDzv8AXhwONYXjIscQg0BuSGIYs+wLjGNC2ckwNOm5nE0Wfd+Hr w2Le20OOPEt6W2t0+vSv9K0xSCIYv7r7nYFsNBOBsBQUcd/6hlGAhJdl/cJQLUfsoOlE AD/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Jm4WEsYFEXelt4jj7bpdr6k9qHo4LSaun0jfbuAJdkE=; b=bxgulgKe4faLDthkiK8jDSG+2tnPey4fNuONF7LadyIketM7Y2ru5IuUI/Jm4LoBGl GFPWAovPIxLs6Wx9DMgbCSVd7dOXW2v6Iebpb5vH4UasIFsbauadwEbiyJLiTNVOItgJ WP9L4muXq1bGQTgq7i1VbvoWMVxVX5k2PXaqk3Zw+NEXaWKxYMSE8Ytf3dAFMqXjpzIC 5qqUAPQa1bIANbIYxnLUJuzDXnj1yxrvpJmktVWqFvzXJQSWQ1/8NmCJA88GBgrRQqYU MBr9AlhiOtrYUruYQj0deZelagaJ22j8Df/0khUXWc0iVVUdTj3y1ckfmSQXUfxwdxf+ Rvbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ewKkhkla; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c14-20020a056808138e00b0033a35f3c9f1si4832233oiw.9.2022.07.15.10.16.50; Fri, 15 Jul 2022 10:17:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ewKkhkla; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235513AbiGORCT (ORCPT + 99 others); Fri, 15 Jul 2022 13:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235394AbiGORCS (ORCPT ); Fri, 15 Jul 2022 13:02:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160B282F86 for ; Fri, 15 Jul 2022 10:02:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A6E7662223 for ; Fri, 15 Jul 2022 17:02:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59449C34115; Fri, 15 Jul 2022 17:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657904536; bh=RneAB0zwL0Agua+ah8JJepJ4SyYzz9VQDMDzjZbNKm4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ewKkhklagPG8bQsRIeV3HeDAxKqJKsZpn4wuGiaNLGKmjYwWs6iDNwf6G+5acFVzZ nG9wSPVDoxMoluF8DqomLr8B8IUG3RQQ6Oz9hiWwB3BwknxTNP3fNRKp/nkC8800Ec JRL6S5V5HqPSR/bZCeSBObFRW5bTniT3msAfPWcsfSgYa7JuP9/SMvJ3y82TXydOEj oyUYKn7QMBvzwH730YcR2yCM1u2Ivh/yeLSWEsISJp3z4Xc5OfHU6xBxGndI/maZOp +a97+6bMd8Rypk9eK8NoDLIa+VD956MR8efgMH6NCPqf//Y+564ZNPQ6LG9vVfHLZ3 St0qO1l9uYHXA== Date: Sat, 16 Jul 2022 00:53:18 +0800 From: Jisheng Zhang To: Emil Renner Berthing Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Anup Patel Subject: Re: [PATCH v5 2/2] riscv: turn pgtable_l4|[l5]_enabled to static key for RV64 Message-ID: References: <20220715134847.2190-1-jszhang@kernel.org> <20220715134847.2190-3-jszhang@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 15, 2022 at 05:04:38PM +0200, Emil Renner Berthing wrote: > On Fri, 15 Jul 2022 at 15:59, Jisheng Zhang wrote: > > On a specific HW platform, pgtable_l4|[l5]_enabled won't change after > > boot, and the check sits at hot code path, this characteristic makes it > > suitable for optimization with static key. > > > > _pgtable_l4|[l5]_enabled is used very early during boot, even is used > > with MMU off, so the static key mechanism isn't ready. For this case, > > we use another static key _pgtable_lx_ready to indicate whether we > > have finalised pgtable_l4|[l5]_enabled or not, then fall back to > > _pgtable_l4|[l5]_enabled_early bool. > > > > Signed-off-by: Jisheng Zhang > > Reviewed-by: Anup Patel > > --- > > arch/riscv/include/asm/pgalloc.h | 16 ++++---- > > arch/riscv/include/asm/pgtable-32.h | 3 ++ > > arch/riscv/include/asm/pgtable-64.h | 60 ++++++++++++++++++--------- > > arch/riscv/include/asm/pgtable.h | 5 +-- > > arch/riscv/kernel/cpu.c | 4 +- > > arch/riscv/mm/init.c | 64 ++++++++++++++++++----------- > > arch/riscv/mm/kasan_init.c | 16 ++++---- > > 7 files changed, 103 insertions(+), 65 deletions(-) > > > > diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h > > index 947f23d7b6af..0280eeb4756f 100644 > > --- a/arch/riscv/include/asm/pgalloc.h > > +++ b/arch/riscv/include/asm/pgalloc.h > > @@ -41,7 +41,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) > > > > static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud) > > { > > - if (pgtable_l4_enabled) { > > + if (pgtable_l4_enabled()) { > > unsigned long pfn = virt_to_pfn(pud); > > > > set_p4d(p4d, __p4d((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE)); > > @@ -51,7 +51,7 @@ static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud) > > static inline void p4d_populate_safe(struct mm_struct *mm, p4d_t *p4d, > > pud_t *pud) > > { > > - if (pgtable_l4_enabled) { > > + if (pgtable_l4_enabled()) { > > unsigned long pfn = virt_to_pfn(pud); > > > > set_p4d_safe(p4d, > > @@ -61,7 +61,7 @@ static inline void p4d_populate_safe(struct mm_struct *mm, p4d_t *p4d, > > > > static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p4d) > > { > > - if (pgtable_l5_enabled) { > > + if (pgtable_l5_enabled()) { > > unsigned long pfn = virt_to_pfn(p4d); > > > > set_pgd(pgd, __pgd((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE)); > > @@ -71,7 +71,7 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p4d) > > static inline void pgd_populate_safe(struct mm_struct *mm, pgd_t *pgd, > > p4d_t *p4d) > > { > > - if (pgtable_l5_enabled) { > > + if (pgtable_l5_enabled()) { > > unsigned long pfn = virt_to_pfn(p4d); > > > > set_pgd_safe(pgd, > > @@ -82,7 +82,7 @@ static inline void pgd_populate_safe(struct mm_struct *mm, pgd_t *pgd, > > #define pud_alloc_one pud_alloc_one > > static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) > > { > > - if (pgtable_l4_enabled) > > + if (pgtable_l4_enabled()) > > return __pud_alloc_one(mm, addr); > > > > return NULL; > > @@ -91,7 +91,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) > > #define pud_free pud_free > > static inline void pud_free(struct mm_struct *mm, pud_t *pud) > > { > > - if (pgtable_l4_enabled) > > + if (pgtable_l4_enabled()) > > __pud_free(mm, pud); > > } > > > > @@ -100,7 +100,7 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud) > > #define p4d_alloc_one p4d_alloc_one > > static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) > > { > > - if (pgtable_l5_enabled) { > > + if (pgtable_l5_enabled()) { > > gfp_t gfp = GFP_PGTABLE_USER; > > > > if (mm == &init_mm) > > @@ -120,7 +120,7 @@ static inline void __p4d_free(struct mm_struct *mm, p4d_t *p4d) > > #define p4d_free p4d_free > > static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d) > > { > > - if (pgtable_l5_enabled) > > + if (pgtable_l5_enabled()) > > __p4d_free(mm, p4d); > > } > > > > diff --git a/arch/riscv/include/asm/pgtable-32.h b/arch/riscv/include/asm/pgtable-32.h > > index 59ba1fbaf784..1ef52079179a 100644 > > --- a/arch/riscv/include/asm/pgtable-32.h > > +++ b/arch/riscv/include/asm/pgtable-32.h > > @@ -17,6 +17,9 @@ > > > > #define MAX_POSSIBLE_PHYSMEM_BITS 34 > > > > +#define pgtable_l5_enabled() 0 > > +#define pgtable_l4_enabled() 0 > > + > > /* > > * rv32 PTE format: > > * | XLEN-1 10 | 9 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 > > diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h > > index 5c2aba5efbd0..edfff00d8ca3 100644 > > --- a/arch/riscv/include/asm/pgtable-64.h > > +++ b/arch/riscv/include/asm/pgtable-64.h > > @@ -8,18 +8,38 @@ > > > > #include > > #include > > +#include > > #include > > > > -extern bool pgtable_l4_enabled; > > -extern bool pgtable_l5_enabled; > > +extern bool _pgtable_l5_enabled_early; > > +extern bool _pgtable_l4_enabled_early; > > +extern struct static_key_false _pgtable_l5_enabled; > > +extern struct static_key_false _pgtable_l4_enabled; > > +extern struct static_key_false _pgtable_lx_ready; > > It amounts to the same, but I wonder if we ought to use the > DECLARE_STATIC_KEY_FALSE macro here. Thanks for the hint, will send out a newer version soon. Before that, I will wait a bit for other review feedbacks. Thanks