Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8129881rwr; Wed, 10 May 2023 18:48:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/njwZnOB2bojw21JbdgkoFksKdMlXNjYkIV7t2+9A66ukwNFgw8Xb92bblHTJh5NFJmlB X-Received: by 2002:a17:902:b707:b0:1ac:aaf6:ee3a with SMTP id d7-20020a170902b70700b001acaaf6ee3amr6032223pls.32.1683769696881; Wed, 10 May 2023 18:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683769696; cv=none; d=google.com; s=arc-20160816; b=reawstAHrYE77wCedkc2NCzlUrq7K4U3lmVGCSBoL+sOGzDvEaytMhsEleqvrZ3NsT EV3aIOvyk0cK6WJmshHrmZ/FRxRgy0tTZ3aIaZ+mDgGp3QTkXxO+zuCl2MwxFF/zoz6R UnHbZeCJ7UFdPymvrm88AX+ULsStV1x35ctdh1DicK+5tY3pNCpWmTC6iX4pSWxGSdi2 F8dzBMxZLxEp+npJUNaSPvT8hWEH35oXG15LfOLj5YiGTAHlLTBtHzzdSkszcwHATSQt zE6PN9GoACZW8ZKaKOpfGFKFQvK1/HjT5T+zkqrJe6sYJ4e0SsE73fKgsvn+b+Pb0Lov udJQ== 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=lG8bfiJPNdgeD3pGdiwg8x2HbVw72NgghlRwoTuOVDw=; b=yfSVoRg7ouKvJR5s5untL98aLNOiQX1mXaT4zeRRbTHVv3mVNxsVKfVEchruiissG7 EtTTdAihOhkdd58HdgfpoW9SHxvy6b/Mkx2RMjbsWoBCMb6t0OWOiqvgrwYPBtnI3II4 9YXojNGKbFZTSByHHjqzzD1jBcIy4zckCAzU7lI/im/2IZC5ZM81JlRR4K0x/HfjJlfV Md74ocCZudfdR3JQaSIu5Jbv0ktUBJrmL2z2tjXX17BjVgh3sbPLvbc4k6vQ1rMAWDuN +qgndhN4tOSFjggQ+euIUwvATBIJ4ibkSunvSsWU1wjcEoMFvkifA3g5pWLyQTmCQn8F ZFZA== 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 v9-20020a17090a778900b002470264eb50si29567908pjk.169.2023.05.10.18.48.02; Wed, 10 May 2023 18:48:16 -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 S230514AbjEKBcp (ORCPT + 99 others); Wed, 10 May 2023 21:32:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjEKBcp (ORCPT ); Wed, 10 May 2023 21:32:45 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4BCD3A96; Wed, 10 May 2023 18:32:42 -0700 (PDT) Received: from loongson.cn (unknown [192.168.100.1]) by gateway (Coremail) with SMTP id _____8BxZ+m5RVxkK5gHAA--.12680S3; Thu, 11 May 2023 09:32:41 +0800 (CST) Received: from [0.0.0.0] (unknown [192.168.100.1]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD7+2RVxkuQxVAA--.20458S3; Thu, 11 May 2023 09:32:38 +0800 (CST) Subject: Re: [PATCH v2] LoongArch: Add jump-label implementation To: Peter Zijlstra References: <1683710206-23905-1-git-send-email-tangyouling@loongson.cn> <20230510092723.GK4253@hirez.programming.kicks-ass.net> Cc: Huacai Chen , Jonathan Corbet , Josh Poimboeuf , Jason Baron , WANG Xuerui , Zhangjin Wu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev From: Youling Tang Message-ID: Date: Thu, 11 May 2023 09:32:38 +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: <20230510092723.GK4253@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf8DxD7+2RVxkuQxVAA--.20458S3 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw4DtF4UJF1ruF43ur1xXwb_yoW5KF1xpF yUCa9YkF4kt3WfJr98XrnxZF1Yvws5KF9FqFZ0g34xAFnFv340kF1IkrZ09as2yaykGr42 v3WYvFZIv3W5taDanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bDAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2kK e7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI 0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280 aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2 xFo4CEbIxvr21lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC 6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s 026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF 0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0x vE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jz5lbUUUUU= 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, Peter On 05/10/2023 05:27 PM, Peter Zijlstra wrote: > On Wed, May 10, 2023 at 05:16:46PM +0800, Youling Tang wrote: >> Add jump-label implementation based on the ARM64 version. >> >> Signed-off-by: Youling Tang > >> 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 >> + >> +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; >> +} > > Seems simple enough; one change I did a while ago for the x86 version is > to put the __jump_table entry generation in a macro so it could be > shared between the (3 for x86) variants. Looks better, I will define JUMP_TABLE_ENTRY macro so that arch_static_branch and arch_static_branch_jump can share. Thanks, Youling. > > Not saying you have to do that, just saying it's an option. > >> +#endif /* __ASSEMBLY__ */ >> +#endif /* __ASM_JUMP_LABEL_H */ > >> 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) >> + 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); >> +} > > This all implies Loongarch is fine with the nop<->b transition (much > like arm64 is), but I found no actual mention of what transitions are > valid for the architecture in your inst.c file -- perhaps you could put > a small comment there to elucidate the occasional reader that doesn't > have your arch manual memorized? > > > Anyway, as with most RISC implementations it's short and sweet. > > Acked-by: Peter Zijlstra (Intel) >