Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp519898rdb; Sat, 19 Aug 2023 11:04:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM7w67HtvMIvDRUZ+u4XoNH3vQlurCFpo+WTiGkHJb6afE6UBpwKkiJj4op0eUxqk+Of6z X-Received: by 2002:a05:6358:7e03:b0:135:89d6:22e9 with SMTP id o3-20020a0563587e0300b0013589d622e9mr2505870rwm.13.1692468249526; Sat, 19 Aug 2023 11:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692468249; cv=none; d=google.com; s=arc-20160816; b=oEE624YhSTaTt8B8+3IL/iiq2lNqrFhovue0nGa+RXHTWCN1kiGG6gals+SNp26sOh ICK7XzTW8kLpPLpirDjvT27BbTlJPSoSn1EVB14XgFRcVd5y9d9v0W7xho6sBkCysG1k JXp3am64qc6nHqWAeK7Los86AsRjM3/Tp223HwEbmippzIMvgwJK0Z8F8nZhcihOmXgg KmTMWcYFSWRdgOrbaJzV/F4DliYaxLBVuI5gwGPZ+zy6nMmjprl5ff69cbPKKGExsGRx Pc6jiva97N9IuXue3GXW9oMRu7iBDe+Hx9M9a/Ba1NYl7y8EcYSIHSOO8vdKpEWcaCT1 upiA== 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=bgC1JR3GltIDSf4x3tRknvWq/71clnqR/lvG3W7lMIY=; fh=FHMZ0XzOHHUkT1v8KC8lAXQ9JxW0r54Tn5r2OwxmoJU=; b=aOh0Vw0aa5J/6XbTtKqv71RLY2UGfdj/DGxGnu7Ra9PnvI+mTkR7SXCKza/sOxH1fL HaVjk1YQZIWlvJi5MO1QHCQFmzD6J5hljWQDGOl7yv351bit7THY77kB8+YDlBIRiOvn ZFxoxAMCEE1GgYWhxgBBGhRF87fpEMwMKD3QN+JoEg+0+GdAHos/d55INc4+FGnt4ldF JOEG62GRwHZFO/gVycDtKJShup7EFDbVpFquZI3hgmwKUlD3w+LzmSzRubLBRzGanckt I/Bb5zDdC9neUsBg5xgUihdKHHS2Lu51VpBocwsRaD89RBO9q36ttAErzu/aGDErrsSW SjPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Wk7ZcI2c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a62-20020a636641000000b00565bccfd025si3727318pgc.828.2023.08.19.11.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 11:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Wk7ZcI2c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 785E646712; Sat, 19 Aug 2023 01:30:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347457AbjHQAcB (ORCPT + 99 others); Wed, 16 Aug 2023 20:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347396AbjHQAbd (ORCPT ); Wed, 16 Aug 2023 20:31:33 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 280412D51 for ; Wed, 16 Aug 2023 17:31:31 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bdcb800594so29522425ad.1 for ; Wed, 16 Aug 2023 17:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1692232290; x=1692837090; 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=bgC1JR3GltIDSf4x3tRknvWq/71clnqR/lvG3W7lMIY=; b=Wk7ZcI2cSkKCmpwAOwQEWMxrL0tl/66pfHLM07y/kUfYtekvi/9AI3fVG2F8cet9z7 HaNmXcsLFe/opiDrpqTUwTwp2xAGG4VppLrGtJ817cSohKNEmlr38uTFl2Sz3N/BKGh8 URPT4Pgv2IShCvFGZg6os9YjX98OSOzdKTEzsWFGAay4H3HVGpaS/GVv2QchNq8KafvK IkyqfPF8xyh33b6/CuFgitvJDNid8GWpU+t4AG4nrLS2uSTJcWTF+Ba4KnzXdwinN19W fAdrVc/FNL6bAuRBVyr3h8XYuAfq3Ea1xvc1SKwFPIR4gZhmU+xURpjxgFC4H/ctLxds ZEyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692232290; x=1692837090; 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=bgC1JR3GltIDSf4x3tRknvWq/71clnqR/lvG3W7lMIY=; b=h1BPTTtssud2sSLMExxi0FCvsr/0+W2X2R8eIp5x3fOOgBVRHqtirDnVRCVS+GaJ64 q2HeHtT4Cw/G8i/sEJwuNRBktDyRdj944L0Cf1TY+0lOEpqKfzgqzeWgGjlCmEdEWT8i 2+GTGw+4rAZ1JWLgtEorkshzKKIbtBYkgJlpLvRA2NMVfyReuRAvV9DDQ0bf1+2iFz0E Y16yyk3Q3EJFdf5ycuN/V3YkJNdCW00R3saooUwRJDAu6DL7hgu/9jrUFujECOP5tmaP ph27BB7IEW+XZ2xnaJmMtTrOJI86G7nvdHxSpRnYxi2v/05XFXEII92W0OMF6QPmLrGd j/mA== X-Gm-Message-State: AOJu0YwrdgmN1DdnIIUT7PAjVlput3giPXlXbksX/9/rw/pV0BsXqHzS XLzEy2a6gzmFfCizd5XQZx4AOg== X-Received: by 2002:a17:902:e80d:b0:1bd:a0cd:1860 with SMTP id u13-20020a170902e80d00b001bda0cd1860mr4137638plg.64.1692232290547; Wed, 16 Aug 2023 17:31:30 -0700 (PDT) Received: from ghost ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id d12-20020a170902728c00b001ac5896e96esm13666450pll.207.2023.08.16.17.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 17:31:30 -0700 (PDT) Date: Wed, 16 Aug 2023 17:31:26 -0700 From: Charlie Jenkins To: Andrew Jones 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 , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Luke Nelson , Xi Wang , Nam Cao Subject: Re: [PATCH 00/10] RISC-V: Refactor instructions Message-ID: References: <20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com> <20230804-2c57bddd6e87fdebc20ff9d5@orel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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 Fri, Aug 04, 2023 at 10:24:33AM -0700, Charlie Jenkins wrote: > On Fri, Aug 04, 2023 at 12:28:28PM +0300, Andrew Jones wrote: > > 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". > That's a great idea, I didn't realize that existed! I have discovered that the riscv-opcodes repository is not in a state that makes it helpful. If it were workable, it would make it easy to include a "Linux C" format. I have had a pull request open on the repo for two weeks now and the person who maintains the repo has not interacted. At minimum, in order for it to be useful it would need an ability to describe the bit order of immediates in an instruction and include script arguments to select which instructions should be included. There is a "C" format, but it is actually just a Spike format. Nonetheless, it seems like it is prohibitive to use it. > > > > 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. > Since I was hand-writing everything and copying it wasn't too much > effort to just copy all of the instructions from a group. However, from > a testing standpoint it makes sense to exclude instructions not yet in > use. > > > > [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