From patchwork Fri Aug 4 02:10:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 130964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp38659vqb; Thu, 3 Aug 2023 22:20:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlEV2da0to4J7B666pZOuhI6hELLtieapoi44NgTKWOdZZ/4zv51MBV3zHGkIQ89Gx47pVUz X-Received: by 2002:a17:902:ea0b:b0:1b8:95fc:cfe with SMTP id s11-20020a170902ea0b00b001b895fc0cfemr22901359plg.3.1691126458266; Thu, 03 Aug 2023 22:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691126458; cv=none; d=google.com; s=arc-20160816; b=JzQIvuzfrpPd9bk2L60HzjHiwQOhw/+R1+aJTdUDbs3pd77FwKXczPbv57tu99r9x5 Y010UKGKTFNswsDkwajLgK/kFwcArToTGRdnjPdYHE/tPPu0QTzlJaWykPKUvAPBUKrz VKn4cAZYP8Kv1+byF7X9ZQGuHOvCbuYp+rHCy4z1GI3nqmi+erwADu3ynap1Bc9+qlU+ apDJRbTaqpdoCDV9cf5r/SqSRz0qh2d0pN6GW4mh9z2JG46YqJWbcQP2b/bN0z5fK+6Z qUEqU2KlBPWbCNe1JkTf8jShIKhTlTDEyOScM2iDtQTGaWemCNRSIy7fgJdsDgcOj6Fq cdug== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a17090301c300b001b7f849cd12si1254203plh.81.2023.08.03.22.20.39; Thu, 03 Aug 2023 22:20:58 -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 S231397AbjHDCNK (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 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?b?Qmo=?= =?utf-8?b?w7ZybiBUw7ZwZWw=?= , 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773274616863077635 X-GMAIL-MSGID: 1773274616863077635 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 */