Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2984382rwo; Thu, 3 Aug 2023 19:34:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7K5RV2F0wNoM9pK6I468z7qsWUvUeL7PZT2+CxW862VzuOh3FD3b2z/2c+WizQW4kBfTd X-Received: by 2002:a17:902:e847:b0:1bb:ee1b:3cc8 with SMTP id t7-20020a170902e84700b001bbee1b3cc8mr455129plg.61.1691116469435; Thu, 03 Aug 2023 19:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691116469; cv=none; d=google.com; s=arc-20160816; b=tCOp1oIYh4cb3sG6u9V5m/p73YJN7fhkeDK0Dcs6VKjq6K3lsJXI+Q4vVws7e/W2P0 PG29m19LwyRrhY/SU3ZEpSc4Clq42xeFc9boUejl18lIquPKfQf16nvOglZCMpLXI1iQ roNUntS+orsXOD7/9SXRygPKCQtBpsuqkBV321wr3OqSyAb0lpvLIl5gZ2YGTPZj2frB 8Pff/OK/6Kf4smGIZU7EC4TZWJrHuglGqOadBe5As//ypYV8eRJdH1i/sK/zKzxwWFlF gQatvFHd/+vvoTchGBCx+somwuRG4p7ZlogiUMksZxwj5DUGOHOZLUYGQ8dSvcS3fhB7 BUTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:content-transfer-encoding:mime-version :message-id:date:subject:from:dkim-signature; bh=aKI9/8r29fiRcdK5stgXJjwhW7P4T9bJiQbL+zxyBRE=; fh=C/sT03bfou/Jz5QuFE/+sRxLlugyhMwMBpibogIGu0w=; b=aQCACkqxcatruei05jAH7+LRjsOGhNJpsPnta53pOiatW8qOBfM5+Y7EdR8VY+xFF5 PSgBib2kcyP2nMNzWqW9c3qJaZqGYDyKgjmTPnRX66gfitbeq9tJBXL93FDJeFDlo4Q7 HcqE+zmlj4ox6RSZ+yDTHyMZkYWsaeV0yOOV1Dg1vHCJDUQQzcScjf0cH5wn6onkgD5v 8UU4bUbXbHawvTT2GIjpFd1S/qIU9ye8mCns0o5ESi6DHdMGeLnZPvHVPL8IxwHCOfzB R7FGzfsJ5UoEZGJ9LcCCvNcO6DulAUVU87fy8sjFCHQba8QzBKcS4K4trmJTCG/I3l9j fJAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=AkhJfOQF; 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 z4-20020a170903018400b001b9c992945fsi1018286plg.555.2023.08.03.19.34.17; Thu, 03 Aug 2023 19:34:29 -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=AkhJfOQF; 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 S233291AbjHDCLm (ORCPT + 99 others); Thu, 3 Aug 2023 22:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbjHDCLW (ORCPT ); Thu, 3 Aug 2023 22:11:22 -0400 Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55E0B44B6 for ; Thu, 3 Aug 2023 19:10:52 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1bbaa549bcbso1180670fac.3 for ; Thu, 03 Aug 2023 19:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691115050; x=1691719850; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=aKI9/8r29fiRcdK5stgXJjwhW7P4T9bJiQbL+zxyBRE=; b=AkhJfOQFM1pGb6BlPUy06oljjiN78H7icu0FCH4lB+bXHw/LwEgE5WfUHUrhk68xKT VZ9dam0/U64TWA5t9TdKruXPJ3X0H+Sf0d6VfdGQUmlqqGKLC8z8Yvh7+P06WeYSaRF6 7tff9KQinoC1Hs5opB6YqN+4f3XkGXDoNcN0XTyYvtwmEI6i78JSWRjapxttsIFecIL3 TCvudV8tBM9EoNig/xmiY7igTYmcPHx0ukaFkc/TJlPFpGWB16NSmemF6Z9bDb7+PdFN fVb3cD33kRf2q8frdWvDdZU0s40iHWB50DKpovfgMWF8buP9mcXSJ1u8dbQjRbyQHCxf UWXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691115050; x=1691719850; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aKI9/8r29fiRcdK5stgXJjwhW7P4T9bJiQbL+zxyBRE=; b=jsjT746IFQYtPDNb2q58hVzWVr0WwAfzxb+hc9cMx0F1pHWSJQI2aPgLJTgwfK1hig t/A3cpFiLlsrQ5U9CxWelONz5ee46co3hmgZdpuOf5ISn26LKMOfJ7/PubLttAL4lFsD Gb5QD5kk20/vCY7gZgrp54h1ja/o4r3AUKdodmOveAZPAb7GQqb0F5WsEHfg556ykGJM 8qe9LBj025Y+SjeFOOpoQvcN+/ljMbpOEYSorVh37iDxgMDn3b4t0krnNOSBiyrp0nUU 8idpgXDtosLZKCIdy7hd2kck8/Uh4kXEXGHNKwhFfof/pV//FaWa2v/rVIjHgIbh3qWJ trlA== X-Gm-Message-State: AOJu0YzpBJzYmDFz4Zp9whMljh88i7rJQQeLZ24irdYTq6qLtAdNqcQj bOlQEjfFye3WIrjgf53J2T1bZw== X-Received: by 2002:a05:6871:707:b0:19f:aee0:e169 with SMTP id f7-20020a056871070700b0019faee0e169mr420658oap.30.1691115050056; Thu, 03 Aug 2023 19:10:50 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 19:10:49 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH 00/10] RISC-V: Refactor instructions Date: Thu, 03 Aug 2023 19:10:25 -0700 Message-Id: <20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIABJezGQC/x2NQQqDQAxFryJZG4jOLMSrlC7CmNYsHEsyFUG8e 0OXD/777wIXU3GYuwtMDnXda8DQd1BWrm9BXYJhpDHRRANu7E0MTV5c2m6o1Zt9SwvP8ciYU2K mTAtTgnj5xFLPf+HxvO8foTEC2nEAAAA= 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=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 There are numerous systems in the kernel that rely on directly modifying, creating, and reading instructions. Many of these systems have rewritten code to do this. This patch will delegate all instruction handling into insn.h and reg.h. All of the compressed instructions, RVI, Zicsr, M, A instructions are included, as well as a subset of the F,D,Q extensions. --- This is modifying code that https://lore.kernel.org/lkml/20230731183925.152145-1-namcaov@gmail.com/ is also touching. --- Testing: There are a lot of subsystems touched and I have not tested every individual instruction. I did a lot of copy-pasting from the RISC-V spec so opcodes and such should be correct, but the construction of every instruction is not fully tested. vector: Compiled and booted jump_label: Ensured static keys function as expected. kgdb: Attempted to run the provided tests but they failed even without my changes module: Loaded and unloaded modules patch.c: Ensured kernel booted kprobes: Used a kprobing module to probe jalr, auipc, and branch instructions nommu misaligned addresses: Kernel boots kvm: Ran KVM selftests bpf: Kernel boots. Most of the instructions are exclusively used by BPF but I am unsure of the best way of testing BPF. Signed-off-by: Charlie Jenkins --- Charlie Jenkins (10): RISC-V: Expand instruction definitions RISC-V: vector: Refactor instructions RISC-V: Refactor jump label instructions RISC-V: KGDB: Refactor instructions RISC-V: module: Refactor instructions RISC-V: Refactor patch instructions RISC-V: nommu: Refactor instructions RISC-V: kvm: Refactor instructions RISC-V: bpf: Refactor instructions RISC-V: Refactor bug and traps instructions arch/riscv/include/asm/bug.h | 18 +- arch/riscv/include/asm/insn.h | 2744 +++++++++++++++++++++++++++--- arch/riscv/include/asm/reg.h | 88 + arch/riscv/kernel/jump_label.c | 13 +- arch/riscv/kernel/kgdb.c | 13 +- arch/riscv/kernel/module.c | 80 +- arch/riscv/kernel/patch.c | 3 +- arch/riscv/kernel/probes/kprobes.c | 13 +- arch/riscv/kernel/probes/simulate-insn.c | 100 +- arch/riscv/kernel/probes/uprobes.c | 5 +- arch/riscv/kernel/traps.c | 9 +- arch/riscv/kernel/traps_misaligned.c | 218 +-- arch/riscv/kernel/vector.c | 5 +- arch/riscv/kvm/vcpu_insn.c | 281 +-- arch/riscv/net/bpf_jit.h | 707 +------- 15 files changed, 2825 insertions(+), 1472 deletions(-) --- base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4 change-id: 20230801-master-refactor-instructions-v4-433aa040da03 -- - Charlie