Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14444720rwd; Sat, 24 Jun 2023 20:29:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6t2Uk3CpQwvEsx4XDsuNMjPnac99hsAwyXzSOLeQk/UAG9nra8eWTkUHk2RZAV/XBKlpks X-Received: by 2002:a05:6808:1288:b0:3a0:492b:f07b with SMTP id a8-20020a056808128800b003a0492bf07bmr17378247oiw.26.1687663773685; Sat, 24 Jun 2023 20:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687663773; cv=none; d=google.com; s=arc-20160816; b=hASa1wxXJB9FXdlDq4JiOtCZjrB9GSd68fO0fv40KsYBsctyaybQWMbwaB0HKf9myW A5ysuxa0kC7dkHErNlJxKydk8438c3bLb1eDXXOSyVwqInS1aSeWn9C/g/1AwJvyjGtD OvmukhKmj8HjlJvJ5lxtBcaSQ7h04Hab3h6O7vCMntgjVs9v70pWvhtH4Dv5NUDSXwxy jfAakNBQqADvST4Maw+PJR4P+WkzUYrXi9M6tSb4AZJKPSQQ1kjSe4Cr9tm4UzFJ2z86 DtPcS2GfYQFx7IoeVaTbxryrNqGSlzxllx8h7Yy0TRrL/QjWoVtehKjY7LQL6nsGTu1z /3lw== 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:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=52rzfZgSYKm96nWtNVtgbrtEt6E6FjSJQqCuA4JS//A=; fh=MObjwz3PcWoSmj9Y2bb+Yw1IxAOIA5sKcJleL/Fs1aA=; b=PppYzZLSZX0xAMvqblq1LIIj323sewF2bNO40+Hy+fbtdG/a++2nwLhEzJQIU+PAHM GCk8xZ5nlWjAE//8DU3NOOu2gcVNnTQq4437HO+zbU6iW3JLOMcTc9ox9qhGtfeN53fY rHuEJ2G/4HxIGMdDxHuH9KHPThWyjF/cRQqdwhy8IeqaCuBeguSihLJ9wWnxrUlYQhoE hmZmosA6af/GgxuOaqnTbpWi5yk2xtviixoc0tYO6x9OGe+04/1b45kMW+bqFGm9WTsi 5ttycDwzmVq9ub8t7+ogzoE/zzWBWBJJM9Mee7402FaveEwaL7giPUS6XwbZVrwURpsl +o1Q== 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 b6-20020a170903228600b001b3bda067dasi1571834plh.493.2023.06.24.20.29.21; Sat, 24 Jun 2023 20:29:33 -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 S231356AbjFYDRs (ORCPT + 99 others); Sat, 24 Jun 2023 23:17:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230459AbjFYDRR (ORCPT ); Sat, 24 Jun 2023 23:17:17 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0F0DDE77; Sat, 24 Jun 2023 20:17:14 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.170]) by gateway (Coremail) with SMTP id _____8BxHMe2sZdkb2gBAA--.2135S3; Sun, 25 Jun 2023 11:17:10 +0800 (CST) Received: from [10.20.42.170] (unknown [10.20.42.170]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxWM22sZdknSQGAA--.30049S3; Sun, 25 Jun 2023 11:17:10 +0800 (CST) Message-ID: <70dfa38f-7bb7-6d67-1a27-9e5eb30945b6@loongson.cn> Date: Sun, 25 Jun 2023 11:17:10 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v2 5/9] LoongArch: Simplify the invtlb wrappers To: WANG Xuerui Cc: WANG Rui , Xi Ruoyao , loongarch@lists.linux.dev, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui , Huacai Chen References: <20230624184055.3000636-1-kernel@xen0n.name> <20230624184055.3000636-6-kernel@xen0n.name> Content-Language: en-US From: bibo mao In-Reply-To: <20230624184055.3000636-6-kernel@xen0n.name> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxWM22sZdknSQGAA--.30049S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZF13AF1kKFy3JF18GF1xWFX_yoW5Zw15pF 9xCF4akF4ktF1fuF97Jr1vvr4ayr15Kw4SvF93KF9ayFnrXw1Iqrs8AF4qyry5JayrArW7 XF4Yv3W5uFsYvwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAF wI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4 CEbIxvr21l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j0FALU UUUU= X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,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 在 2023/6/25 02:40, WANG Xuerui 写道: > From: WANG Xuerui > > The invtlb instruction has been supported by upstream LoongArch > toolchains from day one, so ditch the raw opcode trickery and just use > plain inline asm for it. > > While at it, also make the invtlb asm statements barriers, for proper > modeling of the side effects. > > The signature of the other more specific invtlb wrappers contain unused > arguments right now, but these are not removed right away in order for > the patch to be focused. In the meantime, assertions are added to ensure > no accidental misuse happens before the refactor. (The more specific > wrappers cannot re-use the generic invtlb wrapper, because the ISA > manual says $zero shall be used in case a particular op does not take > the respective argument: re-using the generic wrapper would mean losing > control over the register usage.) > > Signed-off-by: WANG Xuerui > --- > arch/loongarch/include/asm/tlb.h | 39 ++++++++++++++++---------------- > 1 file changed, 19 insertions(+), 20 deletions(-) > > diff --git a/arch/loongarch/include/asm/tlb.h b/arch/loongarch/include/asm/tlb.h > index 0dc9ee2b05d2..15750900540c 100644 > --- a/arch/loongarch/include/asm/tlb.h > +++ b/arch/loongarch/include/asm/tlb.h > @@ -88,52 +88,51 @@ enum invtlb_ops { > INVTLB_GID_ADDR = 0x16, > }; > > -/* > - * invtlb op info addr > - * (0x1 << 26) | (0x24 << 20) | (0x13 << 15) | > - * (addr << 10) | (info << 5) | op > - */ > static inline void invtlb(u32 op, u32 info, u64 addr) > { inline function is not assured, it may be general function so op is not constant in this situation. Had better define it as macro or change inline as __always_inline. Regards Bibo Mao > + BUILD_BUG_ON(!__builtin_constant_p(op)); > __asm__ __volatile__( > - "parse_r addr,%0\n\t" > - "parse_r info,%1\n\t" > - ".word ((0x6498000) | (addr << 10) | (info << 5) | %2)\n\t" > - : > - : "r"(addr), "r"(info), "i"(op) > + "invtlb %0, %1, %2\n\t" > : > + : "i"(op), "r"(info), "r"(addr) > + : "memory" > ); > } > > static inline void invtlb_addr(u32 op, u32 info, u64 addr) > { > + BUILD_BUG_ON(!__builtin_constant_p(op)); > + BUILD_BUG_ON(!__builtin_constant_p(info) || info != 0); > __asm__ __volatile__( > - "parse_r addr,%0\n\t" > - ".word ((0x6498000) | (addr << 10) | (0 << 5) | %1)\n\t" > - : > - : "r"(addr), "i"(op) > + "invtlb %0, $zero, %1\n\t" > : > + : "i"(op), "r"(addr) > + : "memory" > ); > } > > static inline void invtlb_info(u32 op, u32 info, u64 addr) > { > + BUILD_BUG_ON(!__builtin_constant_p(op)); > + BUILD_BUG_ON(!__builtin_constant_p(addr) || addr != 0); > __asm__ __volatile__( > - "parse_r info,%0\n\t" > - ".word ((0x6498000) | (0 << 10) | (info << 5) | %1)\n\t" > - : > - : "r"(info), "i"(op) > + "invtlb %0, %1, $zero\n\t" > : > + : "i"(op), "r"(info) > + : "memory" > ); > } > > static inline void invtlb_all(u32 op, u32 info, u64 addr) > { > + BUILD_BUG_ON(!__builtin_constant_p(op)); > + BUILD_BUG_ON(!__builtin_constant_p(info) || info != 0); > + BUILD_BUG_ON(!__builtin_constant_p(addr) || addr != 0); > __asm__ __volatile__( > - ".word ((0x6498000) | (0 << 10) | (0 << 5) | %0)\n\t" > + "invtlb %0, $zero, $zero\n\t" > : > : "i"(op) > - : > + : "memory" > ); > } >