From nobody Mon Jun 22 14:23:30 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1BA1C6FA83 for ; Tue, 27 Sep 2022 14:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233026AbiI0Ogc (ORCPT ); Tue, 27 Sep 2022 10:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233135AbiI0Oe4 (ORCPT ); Tue, 27 Sep 2022 10:34:56 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43C1B52FD8 for ; Tue, 27 Sep 2022 07:33:47 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4McMYk0fN4z9snl; Tue, 27 Sep 2022 16:33:30 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id biIyK2QFn12v; Tue, 27 Sep 2022 16:33:30 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4McMYh2f3Bz9sp2; Tue, 27 Sep 2022 16:33:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 497AF8B77A; Tue, 27 Sep 2022 16:33:28 +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 L6VIRAJnhDY4; Tue, 27 Sep 2022 16:33:28 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.35]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D0DF08B763; Tue, 27 Sep 2022 16:33:27 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 28REXGNI351152 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 27 Sep 2022 16:33:16 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 28REXG2x351151; Tue, 27 Sep 2022 16:33:16 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Gray , Michael Ellerman , Nicholas Piggin Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 1/6] powerpc/code-patching: Use pte_offset_kernel() instead of virt_to_kpte() Date: Tue, 27 Sep 2022 16:33:03 +0200 Message-Id: X-Mailer: git-send-email 2.37.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1664289185; l=1173; s=20211009; h=from:subject:message-id; bh=TJVSTY+u+eC9uArZy9PxzVn61RI81XijmNXf2efdcos=; b=08CC8l68eApcHJPLy8Uoi3pBgKeJMQt7S/0XYtHT5hyjeQHdPw5dydIjDArIGHqKtojqoVA+Xgzg oUVdU+sJDHtK33eq+EIDnzFKzOt0PawN6ufwTE4NyUYdA/GP3QKt X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" virt_to_kpte() checks pmd_none() and returns NULL in that case. __do_patch_instruction() doesn't expect the pmd to be none and doesn't handle the case anyway. So avoid the pmd_none() check by using pte_offset_kernel() directly. It improves ftrace activation by approx 1% on an 8xx. Signed-off-by: Christophe Leroy --- arch/powerpc/lib/code-patching.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index ad0cf3108dd0..0f3acb0534b6 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -158,7 +158,7 @@ static int __do_patch_instruction(u32 *addr, ppc_inst_t= instr) text_poke_addr =3D (unsigned long)__this_cpu_read(text_poke_area)->addr &= PAGE_MASK; patch_addr =3D (u32 *)(text_poke_addr + offset_in_page(addr)); =20 - pte =3D virt_to_kpte(text_poke_addr); + pte =3D pte_offset_kernel(pmd_off_k(text_poke_addr), text_poke_addr); __set_pte_at(&init_mm, text_poke_addr, pte, pfn_pte(pfn, PAGE_KERNEL), 0); /* See ptesync comment in radix__set_pte_at() */ if (radix_enabled()) --=20 2.37.1 From nobody Mon Jun 22 14:23:30 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39224C433EF for ; Tue, 22 Mar 2022 15:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238671AbiCVPmP (ORCPT ); Tue, 22 Mar 2022 11:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238647AbiCVPmM (ORCPT ); Tue, 22 Mar 2022 11:42:12 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A388890B7 for ; Tue, 22 Mar 2022 08:40:45 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KNG0Q0lwkz9sTb; Tue, 22 Mar 2022 16:40:38 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4PM4Gat-FIaZ; Tue, 22 Mar 2022 16:40:38 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4KNG0N0HP6z9sTQ; Tue, 22 Mar 2022 16:40:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EB5B88B773; Tue, 22 Mar 2022 16:40:35 +0100 (CET) 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 JCefATiHZUjg; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.14]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A0C928B775; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22MFeTP91513366 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Mar 2022 16:40:29 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22MFeTkt1513365; Tue, 22 Mar 2022 16:40:29 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 1/4] powerpc/code-patching: Don't call is_vmalloc_or_module_addr() without CONFIG_MODULES Date: Tue, 22 Mar 2022 16:40:18 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1647963619; l=872; s=20211009; h=from:subject:message-id; bh=ZfTeZCNos+9TM+ODeoKZHrQvpqXI+wYtliNjGS/FiJM=; b=y5DV3Rx5CzGcO3XwPAk0teKABXW5GFOefONOVHZn1mu1Pcs+/6DNAonka28vtA9euT6tXjo2tHYi xGKNxqKCBjfjNLBhVPeY7F9lk/9sVA5bihINd7OBH8ps1PPwrk33 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If CONFIG_MODULES is not set, there is no point in checking whether text is in module area. This reduced the time needed to activate/deactivate ftrace by more than 10% on an 8xx. Signed-off-by: Christophe Leroy --- arch/powerpc/lib/code-patching.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index 00c68e7fb11e..f970f189875b 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -97,7 +97,7 @@ static int map_patch_area(void *addr, unsigned long text_= poke_addr) { unsigned long pfn; =20 - if (is_vmalloc_or_module_addr(addr)) + if (IS_ENABLED(CONFIG_MODULES) && is_vmalloc_or_module_addr(addr)) pfn =3D vmalloc_to_pfn(addr); else pfn =3D __pa_symbol(addr) >> PAGE_SHIFT; --=20 2.35.1 From nobody Mon Jun 22 14:23:30 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 316B0C433EF for ; Tue, 22 Mar 2022 15:41:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238706AbiCVPm3 (ORCPT ); Tue, 22 Mar 2022 11:42:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238684AbiCVPm0 (ORCPT ); Tue, 22 Mar 2022 11:42:26 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B4A48BF23 for ; Tue, 22 Mar 2022 08:40:51 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KNG0S6KMDz9sTf; Tue, 22 Mar 2022 16:40:40 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IdS7A4p8cTJ3; Tue, 22 Mar 2022 16:40:40 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4KNG0N0gHPz9sTX; Tue, 22 Mar 2022 16:40:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0522E8B763; Tue, 22 Mar 2022 16:40:36 +0100 (CET) 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 GtRwm26YODKb; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.14]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A2F258B776; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22MFeT9R1513370 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Mar 2022 16:40:29 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22MFeT5D1513369; Tue, 22 Mar 2022 16:40:29 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 2/4] powerpc/code-patching: Speed up page mapping/unmapping Date: Tue, 22 Mar 2022 16:40:19 +0100 Message-Id: <3a1e34312b5c169cde846174c275241db85f7406.1647962456.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1647963619; l=2635; s=20211009; h=from:subject:message-id; bh=35yiHUmQqTxn+N9RYcp08cbKx03tJYDkvUBA219cU6Q=; b=C1icnQR+MZ6ADKWVnpRpqlb+vWViOhf0mEe0MchKsPUtNDbD69fdcgFkM7Crvql273l7ISOsCS4r vocZXidRCkWjGuy8MaUzY/j17WJUfzCAxHHqn5HSwDR8dbaeozAW X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 591b4b268435 ("powerpc/code-patching: Pre-map patch area") the patch area is premapped so intermediate page tables are already allocated. Use __set_pte_at() directly instead of the heavy map_kernel_page(), at for unmapping just do a pte_clear() followed by a flush. __set_pte_at() can be used directly without the filters in set_pte_at() because we are mapping a normal page non executable. Make sure gcc knows text_poke_area is page aligned in order to optimise the flush. This change reduces by 66% the time needed to activate ftrace on an 8xx (588000 tb ticks instead of 1744000). Signed-off-by: Christophe Leroy --- arch/powerpc/lib/code-patching.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index f970f189875b..62692c6031bc 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -90,17 +90,20 @@ void __init poking_init(void) text_area_cpu_down)); } =20 +static unsigned long get_patch_pfn(void *addr) +{ + if (IS_ENABLED(CONFIG_MODULES) && is_vmalloc_or_module_addr(addr)) + return vmalloc_to_pfn(addr); + else + return __pa_symbol(addr) >> PAGE_SHIFT; +} + /* * This can be called for kernel text or a module. */ static int map_patch_area(void *addr, unsigned long text_poke_addr) { - unsigned long pfn; - - if (IS_ENABLED(CONFIG_MODULES) && is_vmalloc_or_module_addr(addr)) - pfn =3D vmalloc_to_pfn(addr); - else - pfn =3D __pa_symbol(addr) >> PAGE_SHIFT; + unsigned long pfn =3D get_patch_pfn(addr); =20 return map_kernel_page(text_poke_addr, (pfn << PAGE_SHIFT), PAGE_KERNEL); } @@ -145,17 +148,19 @@ static int __do_patch_instruction(u32 *addr, ppc_inst= _t instr) int err; u32 *patch_addr; unsigned long text_poke_addr; + pte_t *pte; + unsigned long pfn =3D get_patch_pfn(addr); =20 - text_poke_addr =3D (unsigned long)__this_cpu_read(text_poke_area)->addr; + text_poke_addr =3D (unsigned long)__this_cpu_read(text_poke_area)->addr &= PAGE_MASK; patch_addr =3D (u32 *)(text_poke_addr + offset_in_page(addr)); =20 - err =3D map_patch_area(addr, text_poke_addr); - if (err) - return err; + pte =3D virt_to_kpte(text_poke_addr); + __set_pte_at(&init_mm, text_poke_addr, pte, pfn_pte(pfn, PAGE_KERNEL), 0); =20 err =3D __patch_instruction(addr, instr, patch_addr); =20 - unmap_patch_area(text_poke_addr); + pte_clear(&init_mm, text_poke_addr, pte); + flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE); =20 return err; } --=20 2.35.1 From nobody Mon Jun 22 14:23:30 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D6BDC433F5 for ; Tue, 22 Mar 2022 15:40:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238677AbiCVPmT (ORCPT ); Tue, 22 Mar 2022 11:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238674AbiCVPmP (ORCPT ); Tue, 22 Mar 2022 11:42:15 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773CD8BE1A for ; Tue, 22 Mar 2022 08:40:48 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KNG0R0yW5z9sTQ; Tue, 22 Mar 2022 16:40:39 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uFfBl0zt-ofa; Tue, 22 Mar 2022 16:40:39 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4KNG0N0NGJz9sTT; Tue, 22 Mar 2022 16:40:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F03E78B774; Tue, 22 Mar 2022 16:40:35 +0100 (CET) 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 TIeO7rkuVip6; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.14]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 97A248B763; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22MFeUux1513374 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Mar 2022 16:40:30 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22MFeUtJ1513373; Tue, 22 Mar 2022 16:40:30 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 3/4] powerpc/code-patching: Use jump_label for testing freed initmem Date: Tue, 22 Mar 2022 16:40:20 +0100 Message-Id: <0aee964721cab7316cffde21a2ca223cee14d373.1647962456.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1647963619; l=2469; s=20211009; h=from:subject:message-id; bh=lospu3LTx6JL+bF7CXBGRzqT/qZ+/MCraSgpnZzmhtw=; b=g9l17FQMJr6yrEZPgNG+4p15OSDMMEY5JeDtpnZVp+/OOFsFar8jgaLPRnJ4XeKEfoavmTx0EaH2 U05xBb8qBX4s+DRAV+Fcy92l52v4AyJN2roz1MqnvUdtQQWOszJA X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Once init is done, initmem is freed forever so no need to test system_state at every call to patch_instruction(). Use jump_label. This reduces by 2% the time needed to activate ftrace on an 8xx. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/code-patching.h | 2 ++ arch/powerpc/lib/code-patching.c | 5 ++++- arch/powerpc/mm/mem.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/includ= e/asm/code-patching.h index 409483b2d0ce..bccc3a538b9f 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -22,6 +22,8 @@ #define BRANCH_SET_LINK 0x1 #define BRANCH_ABSOLUTE 0x2 =20 +DECLARE_STATIC_KEY_FALSE(init_mem_is_free); + bool is_offset_in_branch_range(long offset); bool is_offset_in_cond_branch_range(long offset); int create_branch(ppc_inst_t *instr, const u32 *addr, diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index 62692c6031bc..ab434c3853c9 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 #include #include @@ -193,10 +194,12 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t= instr) =20 #endif /* CONFIG_STRICT_KERNEL_RWX */ =20 +__ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free); + int patch_instruction(u32 *addr, ppc_inst_t instr) { /* Make sure we aren't patching a freed init section */ - if (system_state >=3D SYSTEM_FREEING_INITMEM && init_section_contains(add= r, 4)) + if (static_branch_likely(&init_mem_is_free) && init_section_contains(addr= , 4)) return 0; =20 return do_patch_instruction(addr, instr); diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 8e301cd8925b..9710d4e0bf08 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 #include =20 @@ -311,6 +312,7 @@ void free_initmem(void) { ppc_md.progress =3D ppc_printk_progress; mark_initmem_nx(); + static_branch_enable(&init_mem_is_free); free_initmem_default(POISON_FREE_INITMEM); } =20 --=20 2.35.1 From nobody Mon Jun 22 14:23:31 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF939C433F5 for ; Tue, 22 Mar 2022 15:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238641AbiCVPmN (ORCPT ); Tue, 22 Mar 2022 11:42:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238499AbiCVPmJ (ORCPT ); Tue, 22 Mar 2022 11:42:09 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2906E89307 for ; Tue, 22 Mar 2022 08:40:42 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KNG0P1xBBz9sTJ; Tue, 22 Mar 2022 16:40:37 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fyuRthqRyGhe; Tue, 22 Mar 2022 16:40:37 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4KNG0N09Bfz9sTN; Tue, 22 Mar 2022 16:40:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E6A2B8B778; Tue, 22 Mar 2022 16:40:35 +0100 (CET) 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 DASnUpcyQiCP; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.14]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9AFE58B774; Tue, 22 Mar 2022 16:40:35 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22MFeU4I1513378 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Mar 2022 16:40:30 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22MFeUuq1513377; Tue, 22 Mar 2022 16:40:30 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 4/4] powerpc/code-patching: Use jump_label to check if poking_init() is done Date: Tue, 22 Mar 2022 16:40:21 +0100 Message-Id: <8d6088aca7b63247377b6d9e4897d08d935fbe93.1647962456.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1647963619; l=1657; s=20211009; h=from:subject:message-id; bh=VpCvKObwtwt586zecmpLYRX0hNgaFguYgIynvmw/m08=; b=6g96jp94nOECf9453iw6yW4xXNCjIbsZcPV9VpQOZT5CHAxxbybhTCDWxioVRHhOYBl7Q7CXK5xL 9Io9NWy6DhdpnjrZtNfLAVvAqesW4m13bQIuubUf5UGoGjPsamUM X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's only during early startup that poking_init() is not done yet, for instance when calling ftrace_init(). Once poking_init() has been called there must be a poking area, no need to check it everytime patch_instruction() is called. ftrace activation time is reduced by 7% with the change on an 8xx. Signed-off-by: Christophe Leroy --- arch/powerpc/lib/code-patching.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index ab434c3853c9..8bd74bbe8b8d 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -79,6 +79,8 @@ static int text_area_cpu_down(unsigned int cpu) return 0; } =20 +static __ro_after_init DEFINE_STATIC_KEY_FALSE(poking_init_done); + /* * Although BUG_ON() is rude, in this case it should only happen if ENOMEM= , and * we judge it as being preferable to a kernel that will crash later when @@ -89,6 +91,7 @@ void __init poking_init(void) BUG_ON(!cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powerpc/text_poke:online", text_area_cpu_up, text_area_cpu_down)); + static_branch_enable(&poking_init_done); } =20 static unsigned long get_patch_pfn(void *addr) @@ -176,7 +179,7 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t i= nstr) * when text_poke_area is not ready, but we still need * to allow patching. We just do the plain old patching */ - if (!this_cpu_read(text_poke_area)) + if (!static_branch_likely(&poking_init_done)) return raw_patch_instruction(addr, instr); =20 local_irq_save(flags); --=20 2.35.1