Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14725868rwd; Sun, 25 Jun 2023 03:18:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5iGvgsg7bdsoeyMLENqLVZO8CIkyX/WhH6CG4BvRfEwyw/NpppWSf87Tl09ARMf4ZRKQDc X-Received: by 2002:a17:902:da8c:b0:1af:981b:eeff with SMTP id j12-20020a170902da8c00b001af981beeffmr4769167plx.64.1687688315036; Sun, 25 Jun 2023 03:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687688315; cv=none; d=google.com; s=arc-20160816; b=F8NdVjeA5gBvHkgQk1LQagwLfCXTrJyvFyzCJylIMd9lEp/ZOLkKNlFQedYTUo7OUV vhnE6Zq4tO0uq0ymDtE37ll1WwkqSSMicuVpAHGmKmEdiKC3okddCVJ886HHYKybKMXx kRSTBazV9VdGAwmnff+yjpfWNdq7dCPUYf1UW+umd7cIbX0Dzl6hnY0lWays8KHmlK/T abRtUaz0Y5rPxxImojctoV/aNeFYCg6r+dsKlW/uTMFOqRvEEWZ/uTo671jQ+7oKqddY puN1wLe7lCiEsov1YsfvhPnjIjNbIwLTv/cLUXeF6+k2OV3CJg7EvY0L36FYZ/xrIGWK lypQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QlQ2XxHYZgYLcRQn1HlvWKV8O5QrfRUfnkgd/PHciw8=; fh=dOptu1ihZdKkZ8ajFex7p+VOwkwvZgrA6cQy2X6s+EM=; b=nyxIbdeEf+pFBXDi85Z6KpARCPy8PcBq62C4YQm720T2ihdVQcRkchijgJFt4CU+oo sNXRUtUcl+ioDQipSrKKjMRCX9zXcEP9Ty9bnE9fXnA6sUCcTjXWuf4jFtjDMyXaHeW6 f14u1G4fa2K6AHgd6zkstz4TDiHNXCBCm9A+aXTH945+zTvybtP0KKQ4OhQboNcpfx4N CZfJ+lloDC5TdPypD0i5lvlW9nKnyndTLrXtaG74jn71q6S/LRAGrun72EjyEQlRQ/li C4EO2lgoOK9yIcoJZAYubQNqPCXm6DVh6x7ucpWDsJlMulHOylE7L7qbZJtKyl6Fqc6O HJXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=mAbA173V; 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 p1-20020a170902bd0100b001b3d5f01c28si2777238pls.252.2023.06.25.03.18.04; Sun, 25 Jun 2023 03:18:34 -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=@xen0n.name header.s=mail header.b=mAbA173V; 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 S232026AbjFYJ6M (ORCPT + 99 others); Sun, 25 Jun 2023 05:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbjFYJ6H (ORCPT ); Sun, 25 Jun 2023 05:58:07 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A0210F2; Sun, 25 Jun 2023 02:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1687687057; bh=Wpug7va/Sehn1qLVf771ez1BHcOrsgYtBJSQBEXO3Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mAbA173VM6FsH8b5N0w1Op2tmRffDFtS5hCc0prq+aUfP9SDHAHE1jrBpI2Qn1mBA Gt5ktfjdYkmAj64mk9W1lTcFZz0win/LyFVNfwrXeh/KtVu1EuzPmK+UTwNX3CUg8/ 2zVhSw+hfBAaMaCSf2v0FV0LD4VlNm1CL0PzXywg= Received: from ld50.lan (unknown [101.88.25.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 533B06015B; Sun, 25 Jun 2023 17:57:37 +0800 (CST) From: WANG Xuerui To: Huacai Chen 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 Subject: [PATCH v3 5/8] LoongArch: Simplify the invtlb wrappers Date: Sun, 25 Jun 2023 17:56:41 +0800 Message-Id: <20230625095644.3156349-6-kernel@xen0n.name> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230625095644.3156349-1-kernel@xen0n.name> References: <20230625095644.3156349-1-kernel@xen0n.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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 functions are also marked as __always_inline instead of just "inline", because they cannot work at all if not inlined: the op argument will not be compile-time const in that case, thus failing to satisfy the "i" constraint. 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 | 43 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/arch/loongarch/include/asm/tlb.h b/arch/loongarch/include/asm/tlb.h index 0dc9ee2b05d2..da7a3b5b9374 100644 --- a/arch/loongarch/include/asm/tlb.h +++ b/arch/loongarch/include/asm/tlb.h @@ -88,52 +88,47 @@ 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) +static __always_inline void invtlb(u32 op, u32 info, u64 addr) { __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) +static __always_inline void invtlb_addr(u32 op, u32 info, u64 addr) { + 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) +static __always_inline void invtlb_info(u32 op, u32 info, u64 addr) { + 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) +static __always_inline void invtlb_all(u32 op, u32 info, u64 addr) { + 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" ); } -- 2.40.0