Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3042427rwo; Thu, 3 Aug 2023 20:59:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoLavI9IN4t9ZiX3LOk0MO5KWq0hNYllMxZqSxrIU68VfaQo8Y3avU2f7+f1v9vWmQPPTC X-Received: by 2002:ac8:5b06:0:b0:403:eb3c:1fed with SMTP id m6-20020ac85b06000000b00403eb3c1fedmr753484qtw.35.1691121542738; Thu, 03 Aug 2023 20:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691121542; cv=none; d=google.com; s=arc-20160816; b=PuPSB9e6es98uQAgOurIfp2oU2mBIaIrgRxw4fdxFcxpjp6PCULMmZWrhNuQ5Zcnlj JpmH4BmlfOdE2JHkVJ8Oiy02zoQgf4Crq2rmCL02Is5Sb5KOiZOK5HjXAfmXgqPH+7Op FsEOW7q7U4uvoEr7GEjzAU56vOOxAjVuifHZPwSs4tkSVuh29qSXP2ytg+LWKuEsccwv +YR1Befv2tWgL9HcPRuNm8HGcuNHb7g81tYgXpBHZDHHlnRVnkR2BJvPM1LCqfyjrZnu KORLiwObCKV/F0Pun80VKt+T3ZU4PVHVDPdnOY1Px6TAoLpfd4c/10RmfU/DPtUKb6rs MmjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=+3U++cEq45L7iITV+zLwLaldo0Na07T+o+hHDfRRKC4=; fh=C/sT03bfou/Jz5QuFE/+sRxLlugyhMwMBpibogIGu0w=; b=BbyRzv79CO/XN0BZ73wg/esXGwgMgMblRbITFWDFP1u1o4RttHLR81UzsL55lfZcPN +gdyJdxjhyu9qWJeh+kg1T6ZVI1UVftPxKtBRVDAXGLd/6xr3aqWK3+OoMPlHVIzD8t/ BQK+4dymqg7QB2FU3HZ3Dfi6+jAMl2WTOJZXIdW6E+Q2xDDyVI/k1yPuYe95IutfLtrx ElFHLLfuwNEbgej0xoQP27ewHHYd0AuhSe/UPEQzM81pHJq5DBjS43PutCAP8KV0BEZ0 WF922tBgi57wqxIFIpDo41n7PMmaWbm1dv0Q4COMF8U1zuUvUeKUYNfbUZmg6u+2vunV +k3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ayC0Day7; 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 y23-20020a17090a105700b00267f3363479si1124210pjd.57.2023.08.03.20.58.50; Thu, 03 Aug 2023 20:59:02 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ayC0Day7; 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 S233613AbjHDCMA (ORCPT + 99 others); Thu, 3 Aug 2023 22:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233312AbjHDCLc (ORCPT ); Thu, 3 Aug 2023 22:11:32 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73153468C for ; Thu, 3 Aug 2023 19:11:04 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-765a7768f1dso133499885a.0 for ; Thu, 03 Aug 2023 19:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691115056; x=1691719856; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+3U++cEq45L7iITV+zLwLaldo0Na07T+o+hHDfRRKC4=; b=ayC0Day7CXdP53wwIDs0tv4bKX6RYBEbt+WDQyLb8tpMqzB8hUHeS+pZ/fmXrx4qpA 3JkEy7VvFQFPwmFiZrOcgMEo3fzpW+ldBC+JO6eugwsbDr7vJSjP1/35CxXsN0MB0Irt mkx9hB89+CUahHSi5pi8nO9KgVUWFgp8tr4jlCEdJmhvewPu4OWQqZ3baJYZwvTPdBfy +HdxqmvQtuuS7UKmZq8wZJhY55hKFLVGi3/KRn4eaZy7GtYIOEbVuJ5qIJOIr+oSnw4f I7cK7giGeGjDDUCgXif5SspsldvYp/giTIrzSG6SdHe7tpD9OaruV+cA9piG0QSIk91/ G56g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691115056; x=1691719856; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+3U++cEq45L7iITV+zLwLaldo0Na07T+o+hHDfRRKC4=; b=HGbY/A+ZZ30Wyo2wyeSgra+++tpDgMwzUcehh1m+bKDoU1gknndsShK9iRgFMicST3 EZej5gvbtrhCFuMC45/O9UTGmFZw4MSulq89bSf0LIRj4LCB6kM4tK4jiy/+VCPRKa+7 x0l9mCUOgrzQmZPuPG4gpXXT9D+b+tY8pyg5Jry3tOY328JE9N+aPV9cRm25WbVWfcSg W7ugTjesJ607+mKIlF851WIod9qlR5q8p+CO94vML1xd7638VPbsxSiw+uYiv+vPGqkh RD8plmx+PK/hSt5Z8uTiafHZHFSK+qQlBrxKOoX5R3NeUfbBxAmpxkywBZfd4RBzUMbP wxBA== X-Gm-Message-State: AOJu0Ywjmh+u24fLBj5KKu8ExWbII5ew1G0nBdT0j84ZxNWNgERDB+0f G/X7biapXZe5ruhkMPd7wUGMKQ== X-Received: by 2002:a05:620a:1918:b0:76c:a187:13be with SMTP id bj24-20020a05620a191800b0076ca18713bemr687807qkb.33.1691115056542; Thu, 03 Aug 2023 19:10:56 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id g6-20020a655806000000b0055c558ac4edsm369499pgr.46.2023.08.03.19.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 19:10:56 -0700 (PDT) From: Charlie Jenkins Date: Thu, 03 Aug 2023 19:10:28 -0700 Subject: [PATCH 03/10] RISC-V: Refactor jump label instructions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230803-master-refactor-instructions-v4-v1-3-2128e61fa4ff@rivosinc.com> References: <20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com> In-Reply-To: <20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com> To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, bpf@vger.kernel.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel , Anup Patel , Atish Patra , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , Luke Nelson , Xi Wang , Nam Cao , Charlie Jenkins X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 Use shared instruction definitions in insn.h instead of manually constructing them. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/insn.h | 2 +- arch/riscv/kernel/jump_label.c | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h index 04f7649e1add..124ab02973a7 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -1984,7 +1984,7 @@ static __always_inline bool riscv_insn_is_branch(u32 code) << RVC_J_IMM_10_OFF) | \ (RVC_IMM_SIGN(x_) << RVC_J_IMM_SIGN_OFF); }) -#define RVC_EXTRACT_BTYPE_IMM(x) \ +#define RVC_EXTRACT_BZ_IMM(x) \ ({typeof(x) x_ = (x); \ (RVC_X(x_, RVC_BZ_IMM_2_1_OPOFF, RVC_BZ_IMM_2_1_MASK) \ << RVC_BZ_IMM_2_1_OFF) | \ diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c index e6694759dbd0..fdaac2a13eac 100644 --- a/arch/riscv/kernel/jump_label.c +++ b/arch/riscv/kernel/jump_label.c @@ -9,11 +9,9 @@ #include #include #include +#include #include -#define RISCV_INSN_NOP 0x00000013U -#define RISCV_INSN_JAL 0x0000006fU - void arch_jump_label_transform(struct jump_entry *entry, enum jump_label_type type) { @@ -26,13 +24,10 @@ void arch_jump_label_transform(struct jump_entry *entry, if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288)) return; - insn = RISCV_INSN_JAL | - (((u32)offset & GENMASK(19, 12)) << (12 - 12)) | - (((u32)offset & GENMASK(11, 11)) << (20 - 11)) | - (((u32)offset & GENMASK(10, 1)) << (21 - 1)) | - (((u32)offset & GENMASK(20, 20)) << (31 - 20)); + insn = RVG_OPCODE_JAL; + riscv_insn_insert_jtype_imm(&insn, (s32)offset); } else { - insn = RISCV_INSN_NOP; + insn = RVG_OPCODE_NOP; } mutex_lock(&text_mutex); -- 2.34.1