Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8130507rwr; Wed, 10 May 2023 18:49:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IGJ5fgKt0yr2xlcld/WOJVdkYWJT3RVavx7xuEwHeQIaJTB6m2a5GIaUZIQig57GB8eSY X-Received: by 2002:a05:6a21:9981:b0:103:f088:105e with SMTP id ve1-20020a056a21998100b00103f088105emr16913pzb.16.1683769744495; Wed, 10 May 2023 18:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683769744; cv=none; d=google.com; s=arc-20160816; b=JUzcMBRxIHyLlK8qtsh9JX1E5nJ2Qem2xLRNv9V9xpjoJWLLHGDoqk4TdmPQeAGqer tcgvFcmw3pppa4ptcdQmH6HNMyhIGkjN2c896WTzB/Qc+c37IRR4bQMAK5JvmvrUQeZT FswhclojoFkNHXXVXL+rtpbjosEON3VP72f+HwNlLC7zDfPyx3zDKgdLsvjkSQuXllCz 2t8olDfZchseWDKevXouFSUWumJB3VOlo1JR4AuRRVcu6TG2hNpTucYWlAK89uwVDY+S xPF2iyhTiP+aICjCB9PqwGRJAPLZKDY/+fF7Su2PfzNvcEuV4Z6x6U7btxFL0wY4NK/m zRYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=7h13HjBygL+i0g+CVUEKrOh562lF//tt37Tefs860n0=; b=Qa/3IFHd/2t3YBUwO+aJEJvPaUguoVKUqyT39WTTSKStQukN+wooPZGR5pbxhtb3sa VVaNsI4s5hs2P+UxEpc7nxbWEMTBMS3/VTWXXxE0HxglyYWSwf79s4zjkt7WQ1fw4Cqf 8BMrQ4oPpE1unW0lhihbVIvn/MYcNNLpKeNp9I2VgBKI442mh/VtyABG2QmlaPN6EPdh klTY27MVVxAkPaPqkSxT7opr817+wBEUgyhIYH6dnEE0/pzuOr1QOQlpID38lcMx1DBt lYwgK8n6uEDFeNkm5nUi1xGYzE20gbEEuCoMkVDpd5HwgeYI5p0i5gvvdOUKYeEcJTLp ekcA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a637a01000000b00517f0c53072si5775017pgc.170.2023.05.10.18.48.50; Wed, 10 May 2023 18:49:04 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236661AbjEKBdu (ORCPT + 99 others); Wed, 10 May 2023 21:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjEKBds (ORCPT ); Wed, 10 May 2023 21:33:48 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9BE7C65A8; Wed, 10 May 2023 18:33:42 -0700 (PDT) Received: from loongson.cn (unknown [192.168.100.1]) by gateway (Coremail) with SMTP id _____8BxrOr1RVxkTZgHAA--.13034S3; Thu, 11 May 2023 09:33:41 +0800 (CST) Received: from [0.0.0.0] (unknown [192.168.100.1]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxBMXxRVxk8AxVAA--.21003S3; Thu, 11 May 2023 09:33:38 +0800 (CST) Subject: Re: [PATCH v2] LoongArch: Add jump-label implementation To: WANG Xuerui References: <1683710206-23905-1-git-send-email-tangyouling@loongson.cn> <3b360532-6ad5-b22c-b02a-103be491be4c@xen0n.name> Cc: Huacai Chen , Jonathan Corbet , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Zhangjin Wu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev From: Youling Tang Message-ID: <72b6c81a-d4ee-575a-ff48-6be7e034ac96@loongson.cn> Date: Thu, 11 May 2023 09:33:37 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <3b360532-6ad5-b22c-b02a-103be491be4c@xen0n.name> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf8BxBMXxRVxk8AxVAA--.21003S3 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Wr13uryfZF4DAr4UZr1rCrg_yoWxGr4fpF 1UCan5GF4kGF1fJrZ0qw1Dur1Yq393Gr12gF13tFy8AFnFvry8Arnakryq9F1ktaykWrWI vF1ruFsIva1UJa7anT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bq8YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2kK e7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI 0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280 aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2 xFo4CEbIxvr21lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC 6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jw0_GFylx2IqxVAqx4xG67AKxVWUJVWUGwC20s 026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF 0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0x vE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv 6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4Xo7DUUUU X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi, Xuerui On 05/10/2023 05:28 PM, WANG Xuerui wrote: > Hi Youling, > > On 2023/5/10 17:16, Youling Tang wrote: >> Add jump-label implementation based on the ARM64 version. > > "Add support for jump labels based on ..." sounds better IMO. OK. > >> >> Signed-off-by: Youling Tang >> --- >> Changes in v2: >> - Fix build errors. >> - fix comment. >> >> .../core/jump-labels/arch-support.txt | 2 +- >> arch/loongarch/Kconfig | 2 + >> arch/loongarch/configs/loongson3_defconfig | 1 + >> arch/loongarch/include/asm/jump_label.h | 51 +++++++++++++++++++ >> arch/loongarch/kernel/Makefile | 2 + >> arch/loongarch/kernel/jump_label.c | 23 +++++++++ >> 6 files changed, 80 insertions(+), 1 deletion(-) >> create mode 100644 arch/loongarch/include/asm/jump_label.h >> create mode 100644 arch/loongarch/kernel/jump_label.c >> >> diff --git a/Documentation/features/core/jump-labels/arch-support.txt >> b/Documentation/features/core/jump-labels/arch-support.txt >> index 2328eada3a49..94d9dece580f 100644 >> --- a/Documentation/features/core/jump-labels/arch-support.txt >> +++ b/Documentation/features/core/jump-labels/arch-support.txt >> @@ -13,7 +13,7 @@ >> | csky: | ok | >> | hexagon: | TODO | >> | ia64: | TODO | >> - | loongarch: | TODO | >> + | loongarch: | ok | > > +1 for updating the docs along with the implementation! > >> | m68k: | TODO | >> | microblaze: | TODO | >> | mips: | ok | >> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig >> index d38b066fc931..193a959a5611 100644 >> --- a/arch/loongarch/Kconfig >> +++ b/arch/loongarch/Kconfig >> @@ -83,6 +83,8 @@ config LOONGARCH >> select GPIOLIB >> select HAS_IOPORT >> select HAVE_ARCH_AUDITSYSCALL >> + select HAVE_ARCH_JUMP_LABEL >> + select HAVE_ARCH_JUMP_LABEL_RELATIVE >> select HAVE_ARCH_MMAP_RND_BITS if MMU >> select HAVE_ARCH_SECCOMP_FILTER >> select HAVE_ARCH_TRACEHOOK >> diff --git a/arch/loongarch/configs/loongson3_defconfig >> b/arch/loongarch/configs/loongson3_defconfig >> index 6cd26dd3c134..33a0f5f742f6 100644 >> --- a/arch/loongarch/configs/loongson3_defconfig >> +++ b/arch/loongarch/configs/loongson3_defconfig >> @@ -63,6 +63,7 @@ CONFIG_EFI_ZBOOT=y >> CONFIG_EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER=y >> CONFIG_EFI_CAPSULE_LOADER=m >> CONFIG_EFI_TEST=m >> +CONFIG_JUMP_LABEL=y >> CONFIG_MODULES=y >> CONFIG_MODULE_FORCE_LOAD=y >> CONFIG_MODULE_UNLOAD=y >> diff --git a/arch/loongarch/include/asm/jump_label.h >> b/arch/loongarch/include/asm/jump_label.h >> new file mode 100644 >> index 000000000000..2f9fdec256c5 >> --- /dev/null >> +++ b/arch/loongarch/include/asm/jump_label.h >> @@ -0,0 +1,51 @@ >> +/* SPDX-License-Identifier: GPL-2.0-only */ >> +/* >> + * Copyright (C) 2023 Loongson Technology Corporation Limited >> + * >> + * Based on arch/arm64/include/asm/jump_label.h >> + */ >> +#ifndef __ASM_JUMP_LABEL_H >> +#define __ASM_JUMP_LABEL_H >> + >> +#ifndef __ASSEMBLY__ >> + >> +#include >> + >> +#define JUMP_LABEL_NOP_SIZE 4 > > Saying LOONGARCH_INSN_SIZE here might be better for reducing redundancy, > although that'll necessitate an extra include of . Leaving > the 4 alone won't cause much harm so I'm fine with either. Using LOONGARCH_INSN_SIZE in v1, but causing build errors due to inclusion of [1]. So I removed the include and used hardcoded 4. [1]: https://lore.kernel.org/loongarch/202305100412.gazWW71q-lkp@intel.com/T/#m0d8393aaf529aea0a4dcc5985469e698d63d66b3 > >> + >> +static __always_inline bool arch_static_branch(struct static_key * >> const key, >> + const bool branch) >> +{ >> + asm_volatile_goto( >> + "1: nop \n\t" >> + " .pushsection __jump_table, \"aw\" \n\t" >> + " .align 3 \n\t" >> + " .long 1b - ., %l[l_yes] - . \n\t" >> + " .quad %0 - . \n\t" >> + " .popsection \n\t" >> + : : "i"(&((char *)key)[branch]) : : l_yes); >> + >> + return false; >> +l_yes: >> + return true; >> +} >> + >> +static __always_inline bool arch_static_branch_jump(struct static_key >> * const key, >> + const bool branch) >> +{ >> + asm_volatile_goto( >> + "1: b %l[l_yes] \n\t" >> + " .pushsection __jump_table, \"aw\" \n\t" >> + " .align 3 \n\t" >> + " .long 1b - ., %l[l_yes] - . \n\t" >> + " .quad %0 - . \n\t" >> + " .popsection \n\t" >> + : : "i"(&((char *)key)[branch]) : : l_yes); >> + >> + return false; >> +l_yes: >> + return true; >> +} >> + >> +#endif /* __ASSEMBLY__ */ >> +#endif /* __ASM_JUMP_LABEL_H */ >> diff --git a/arch/loongarch/kernel/Makefile >> b/arch/loongarch/kernel/Makefile >> index 9a72d91cd104..64ea76f60e2c 100644 >> --- a/arch/loongarch/kernel/Makefile >> +++ b/arch/loongarch/kernel/Makefile >> @@ -54,4 +54,6 @@ obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o >> obj-$(CONFIG_KPROBES) += kprobes.o kprobes_trampoline.o >> +obj-$(CONFIG_JUMP_LABEL) += jump_label.o >> + >> CPPFLAGS_vmlinux.lds := $(KBUILD_CFLAGS) >> diff --git a/arch/loongarch/kernel/jump_label.c >> b/arch/loongarch/kernel/jump_label.c >> new file mode 100644 >> index 000000000000..b06245955f7a >> --- /dev/null >> +++ b/arch/loongarch/kernel/jump_label.c >> @@ -0,0 +1,23 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* >> + * Copyright (C) 2023 Loongson Technology Corporation Limited >> + * >> + * Based on arch/arm64/kernel/jump_label.c >> + */ >> +#include >> +#include >> +#include >> + >> +void arch_jump_label_transform(struct jump_entry *entry, >> + enum jump_label_type type) >> +{ >> + void *addr = (void *)jump_entry_code(entry); >> + u32 insn; >> + >> + if (type == JUMP_LABEL_JMP) > > Please use a switch for dealing with enum-typed values. Because the current type only has JUMP_LABEL_NOP and JUMP_LABEL_JMP, using if may be simpler than switch. Thanks, Youling. > >> + insn = larch_insn_gen_b(jump_entry_code(entry), >> jump_entry_target(entry)); >> + else >> + insn = larch_insn_gen_nop(); >> + >> + larch_insn_patch_text(addr, insn); >> +} >