Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3323552rwo; Fri, 4 Aug 2023 03:08:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEzgqr8Xb3rSrXq9WApGiO+ewdCrSGh2TmALOnljGHdnLCzwKDtJ1vd6Pn7tt8isogg+Cw X-Received: by 2002:aca:1007:0:b0:3a7:372f:c1b1 with SMTP id 7-20020aca1007000000b003a7372fc1b1mr1584841oiq.48.1691143682226; Fri, 04 Aug 2023 03:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691143682; cv=none; d=google.com; s=arc-20160816; b=N5ONxIlQCAYv6vrIMU7B7RWTS0BBmgbr9Sx85UWPfB8Swts0vF4S/+LkPyH8fim9hY U0VS/2r8+YbHI4tvEBfTxf6JYS0SRF2Qg85qktPzfZ5OJwlEUfRPAE0aHLK+9gDIE+56 RpInyJxBtBrOGcfX9CIJuZztEn3wtLaMcpPIknfsFGk1GB0nc4HkdKqgUpCf+opT3LBd zcDfxuYhd1725fw+Zdc7lm3Zkf0Ad0QtGy8I6MPJnQ7C5R09CxBA1v9MkPCogDFHsE25 Sj15/Hw4kX9yiN1RzcohUmMHj2SbzCoa8/pWYs6hRmk5VCOTfRnkJClWjy8mgPDCkaRZ xCKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZfqEgyUyGWV+uCR/G+Jp30EpbAjcXJAFKXc4wfVRnvc=; fh=X/fq8tNCKhSaB1G+q/7SmIDUwlCVXWOor03xNgKoEvQ=; b=yqVGhHJp/rbm+2ptGtp8YRUc/dKPb+ltmRQ9bbz7gsofZmM3X9c0SA5SQ6NtA0T4DM D9vtuMvUU4hVcNjh/ZZk0p1lgRNZl0FcQgR+MAe2erOlLSpwDdUda4fwKyXh6PFzZ1uI IgF2Nlr8ONvZbQTbbE8tn1NpwPmKM47nidg5TF49AG42QqU5nnd2ukz2zsrQEbvXc1Fm 5HCJwENaOCEzoeoKdkmLfdCDLX2i2/l+iXarM3gBBrRqZ39WVPf8m+jmyO34D0sqDuOH wn/KOVLl60GFPJWFJ2Q6iWPXzyoLEmiEt54V4o0+w8TOjV0WJ8FTuiKXkAwhhaHBVoQi xygw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=E5XARrnW; 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 d20-20020a17090ab31400b00262ca5c4c12si1541832pjr.178.2023.08.04.03.07.50; Fri, 04 Aug 2023 03:08: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=@ventanamicro.com header.s=google header.b=E5XARrnW; 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 S230105AbjHDJ2h (ORCPT + 99 others); Fri, 4 Aug 2023 05:28:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjHDJ2e (ORCPT ); Fri, 4 Aug 2023 05:28:34 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D98730EB for ; Fri, 4 Aug 2023 02:28:32 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-99bed101b70so256632266b.3 for ; Fri, 04 Aug 2023 02:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691141310; x=1691746110; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZfqEgyUyGWV+uCR/G+Jp30EpbAjcXJAFKXc4wfVRnvc=; b=E5XARrnWgyw7Cl6ZED5yZTcAjZ31Ocmt/9ACuiwG3t25Jv8VSFbwPR0xS8/w6YDBWS jFraad9vh58ejKHgML+JfZPZLP6hZx6immp48/Ns5zgR1eVbrtVmIxwjpDjurBTZQLkZ 0la33KkRHDu0Sny+rPQjycd9YlzI3KNeLSdwoRjSh2x7GSGeRvrN+8/jv+SxRdnX4Mf2 5wLmtp9/XsJpk/EWdDbpwoNxWZsvCmxe0FRPzCVH7oKMxWd9yyKlyhyTQ6KTnoB2fiEt 192MzRXO2VNkgNOtCPU4sZx8wov6wXGgBZfbXDKB++JuQrVnIiKO3CXnkPFx07E5vDhY NsZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691141310; x=1691746110; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZfqEgyUyGWV+uCR/G+Jp30EpbAjcXJAFKXc4wfVRnvc=; b=Z7/KXgCnGMVGob5+MR4iVCRGJjNG4hRAJlTW7eSuBCP2/qNDMQPeOUiTSe84TC+wIx 95v+8l5W1zcOqsPnfJPKILrHunb4sKJHvCKDEy95PM1doTfnp+a+YnfHFQD+gZwQJIgc 8ypIeozYqZzrGZrpgQAuNCqCqvrKB4ieHkxi4WEfqym2cIto8jEluBYfPJvdx9DN5wqW hlV4k5NrdbewG7SCa20b+TQAhSFH874YitWEtJkQ4vx+9w02BgQHYQGDVsFwC5aAiC1P x9Q/f4AsWl5dgGH03xpvXrOKvdv4Pl2WbMX4n2dTOepDPqwX7QBfuTCmhFmEQ89MaiyN IKgg== X-Gm-Message-State: AOJu0YwSu/lcXT23s5lCr3r8khWyyRPSnQTwvxL0gOcmSeRmHHOF97eY u87D5JslpVV47NOeEVECj7Y65g== X-Received: by 2002:a17:906:2012:b0:99b:f53c:3648 with SMTP id 18-20020a170906201200b0099bf53c3648mr991573ejo.72.1691141310471; Fri, 04 Aug 2023 02:28:30 -0700 (PDT) Received: from localhost (212-5-140-29.ip.btc-net.bg. [212.5.140.29]) by smtp.gmail.com with ESMTPSA id p7-20020a1709066a8700b009930042510csm1024394ejr.222.2023.08.04.02.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 02:28:30 -0700 (PDT) Date: Fri, 4 Aug 2023 12:28:28 +0300 From: Andrew Jones To: Charlie Jenkins Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, bpf@vger.kernel.org, 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?QmrDtnJuIFTDtnBlbA==?= , Luke Nelson , Xi Wang , Nam Cao Subject: Re: [PATCH 00/10] RISC-V: Refactor instructions Message-ID: <20230804-2c57bddd6e87fdebc20ff9d5@orel> References: <20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Thu, Aug 03, 2023 at 07:10:25PM -0700, Charlie Jenkins wrote: > 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 How about we create macros which generate each of the functions an instruction needs, e.g. riscv_insn_is_*(), etc. based on the output of [1]. I know basically nothing about that project, but it looks like it creates most the defines this series is creating from what we [hope] to be an authoritative source. I also assume that if we don't like the current output format, then we could probably post patches to the project to get the format we want. For example, we could maybe propose an "lc" format for "Linux C". I'd also recommend only importing the generated defines and generating the functions that will actually have immediate consumers or are part of a set of defines that have immediate consumers. Each consumer of new instructions will be responsible for generating and importing the defines and adding the respective macro invocations to generate the functions. This series can also take that approach, i.e. convert one set of instructions at a time, each in a separate patch. [1] https://github.com/riscv/riscv-opcodes Thanks, drew > , 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 > > > -- > kvm-riscv mailing list > kvm-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kvm-riscv