Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3005727rwo; Thu, 3 Aug 2023 20:05:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTb1ZlyasCg0Z4SC3yKvWyg+WsIjST8RuhcuEmWa3SxPHShZeGI1rDs4/pgWbbNSFQxkBO X-Received: by 2002:a05:6a00:14cc:b0:668:97bf:5ed7 with SMTP id w12-20020a056a0014cc00b0066897bf5ed7mr711194pfu.22.1691118323577; Thu, 03 Aug 2023 20:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691118323; cv=none; d=google.com; s=arc-20160816; b=eDYRyE1Kx+bJXJFwi9zLiArAYhsqs2npV3oLtQ/BXum//pF7BIOCLFhVc1cz1Aq+mE fyjs+VjYsES0iwv01VKItiRIC2H9RvUO3APpZjmuHEBSQv3M+44zz6+zgdoRgpLelrEA ahuLLpeysPgbiaCxaqM9C063hPVNRNLNlAwuv5w9bHnmhzmLDK/F69F7IR14+QEMF/q9 VCVpz1tD7JXyTO1y6UJ4innJ9Od/r7r8tDi2vdo73Hfj5Z5ysiDPROz59L5sAEihkKMS rBuvkMqMilnD8Z8L5YPls9SzQU93zm3ROtESIQ78oryw0ZovnOfTTlTtrWG9jmKDY1LF 2SjA== 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=ih06HArn9iAryRcOKi/nyaTeAf4B1pYQ5n3lzBGwExw=; fh=C/sT03bfou/Jz5QuFE/+sRxLlugyhMwMBpibogIGu0w=; b=GGKFmFOktvExO+qtkUIJJ2GlteLpnD44C43Ictob53GtBsh9BxgYZlThiRuOsd34Ix AUchU4NsqKi2NP/1/cw/kG1Zv7A0MEV9SHPQrOr8LVJeG/5m+2QQetrwxLaxM0D/fxeo SpIkKyvFz8kfHTSiSKBUzNSKALVAiUpXCxjQLL4YuYUVur9QbJXVfmdP8NMg+uz2Auy5 Av+0JRhxi4By821mKMJnTOgmQYpYHJQXBwzqTQjXX5gIp53iLpX/9a3HqEKPh9BEY+xn 4ROO9R11SJuBbkWwVUA4stUQaWdAzmQoZ4bvTFJP0WVtW7B82TwAXfnZJ+N/yTm6ZXa9 xUtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ew4rB+H6; 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 z16-20020aa78890000000b00687392ab4ffsi1004566pfe.17.2023.08.03.20.05.09; Thu, 03 Aug 2023 20:05:23 -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=ew4rB+H6; 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 S232591AbjHDCNK (ORCPT + 99 others); Thu, 3 Aug 2023 22:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233702AbjHDCMQ (ORCPT ); Thu, 3 Aug 2023 22:12:16 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079604EC4 for ; Thu, 3 Aug 2023 19:11:38 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686f38692b3so1487908b3a.2 for ; Thu, 03 Aug 2023 19:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691115071; x=1691719871; 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=ih06HArn9iAryRcOKi/nyaTeAf4B1pYQ5n3lzBGwExw=; b=ew4rB+H6wBVVmeh/ui4LIzo+yvnm98oRAW4V9bmZm0KpT/glMjqRgPghU5Pe7h4Esc ULiTigZbpum8dCcqLDUYCXDomBKmpj2JOHEklft07nNCBx1z82UYhCKCpuxj1PHAOzaE NMax1U3YW9v1aHa4//bwc1cTcDl4jdIR8DOmMX78OtylMdsneAv0M+DVuZ/oUvlzDjuy /Eo3HBz3BDHFXmGEXCMfBNAi9hv3UebxWREasDtlfQDxVygFxm5W9omrOT80TWEdv1+I 6Q3E3HhXfnIfxGtKYjYgSXjJeDKzMUjL0JxLCdBqUgV5jfcWHjIg0Oq1bhb98rkkscuS E9Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691115071; x=1691719871; 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=ih06HArn9iAryRcOKi/nyaTeAf4B1pYQ5n3lzBGwExw=; b=SMoJO3iKokbMmz3c8QME8kZjfaFC/lQkMv5hVpIOyMWr0lJUQ/wigOEAHt62W8eYEl BpHxY4L4BnEAk6xtI1aG3F2P/8Frrd7vOjQpVATP2nno1xPvGphCEzzYrt0VTiPjWQe6 c1Vvh8VBu3uT3Qwt2z7kXmye6/MV/ssohgE+fjzfuzAcI8OnqcrhOSJhz3jqzkp8khrx MKl3STELIOdCanjBeXjkE3ESPq+e6+CPCilwxLZgFz26VlcJxGc7GyXzNyEXwQSj4yVq kT+5vVgV81Xy0B3ro85F75p7a/MhaZoCtHPHJFrNSnQ9Q8RUkR4PyQRbZe569WQrB3HD Wk6g== X-Gm-Message-State: AOJu0YwC4vQxGWSmrpfqcXAJC6eEDXkL+xDZFVsz5MbkftvzXTp2CqK/ DdW9NIUHriQDM7k0AZd6k6fzTg== X-Received: by 2002:a05:6a00:189d:b0:687:2be1:e2f6 with SMTP id x29-20020a056a00189d00b006872be1e2f6mr555577pfh.16.1691115071421; Thu, 03 Aug 2023 19:11:11 -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.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 19:11:10 -0700 (PDT) From: Charlie Jenkins Date: Thu, 03 Aug 2023 19:10:35 -0700 Subject: [PATCH 10/10] RISC-V: Refactor bug and traps instructions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230803-master-refactor-instructions-v4-v1-10-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_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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/bug.h | 18 +++++------------- arch/riscv/kernel/traps.c | 9 +++++---- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h index 1aaea81fb141..6d9002d93f85 100644 --- a/arch/riscv/include/asm/bug.h +++ b/arch/riscv/include/asm/bug.h @@ -11,21 +11,13 @@ #include #include +#include -#define __INSN_LENGTH_MASK _UL(0x3) -#define __INSN_LENGTH_32 _UL(0x3) -#define __COMPRESSED_INSN_MASK _UL(0xffff) +#define __IS_BUG_INSN_32(insn) riscv_insn_is_c_ebreak(insn) +#define __IS_BUG_INSN_16(insn) riscv_insn_is_ebreak(insn) -#define __BUG_INSN_32 _UL(0x00100073) /* ebreak */ -#define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */ - -#define GET_INSN_LENGTH(insn) \ -({ \ - unsigned long __len; \ - __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \ - 4UL : 2UL; \ - __len; \ -}) +#define __BUG_INSN_32 RVG_MATCH_EBREAK +#define __BUG_INSN_16 RVC_MATCH_C_EBREAK typedef u32 bug_insn_t; diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index f910dfccbf5d..970b118d36b5 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -243,7 +244,7 @@ static inline unsigned long get_break_insn_length(unsigned long pc) if (get_kernel_nofault(insn, (bug_insn_t *)pc)) return 0; - return GET_INSN_LENGTH(insn); + return INSN_LEN(insn); } void handle_break(struct pt_regs *regs) @@ -389,10 +390,10 @@ int is_valid_bugaddr(unsigned long pc) return 0; if (get_kernel_nofault(insn, (bug_insn_t *)pc)) return 0; - if ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) - return (insn == __BUG_INSN_32); + if (INSN_IS_C(insn)) + return __IS_BUG_INSN_16(insn); else - return ((insn & __COMPRESSED_INSN_MASK) == __BUG_INSN_16); + return __IS_BUG_INSN_32(insn); } #endif /* CONFIG_GENERIC_BUG */ -- 2.34.1