Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp394175rwo; Tue, 1 Aug 2023 19:46:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXa9BFV92RgpVLmK8jb+/uDYCWYRdRlleTeXvhicBrJSQEyV7V47vKewINE1zYtTaPY4P7 X-Received: by 2002:a17:902:da87:b0:1b8:6952:5381 with SMTP id j7-20020a170902da8700b001b869525381mr19116663plx.9.1690944392894; Tue, 01 Aug 2023 19:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690944392; cv=none; d=google.com; s=arc-20160816; b=S+3dDG7SVvxAEQmSI6O83HN9ux6xzHD+ae8dMI/VXDw4yBDTBbhPOO6r1/iyt1irtd oFJKhdNIoVG2562R2J81wCiO5vFfxAj86rfZNNhnzJ5yu5VCmrsew6smVLxBJ0VIb0lS 7CgzEbACykHev0FpTCvpOt6hDtmNAD+9LGxGvSSAdExFf73YRQjei7DYrNc7M/RNw8T6 cgGsnyNOX2N3R7bAuMie4oSRMx6fIaTqf88Qvw7QoFYVFr/DytrGoIr8m+u+l3xB0KiU ICZWn+H8SvyJ3qQJDxdLvtNnK6mFMfHpJx1Ue7+b9hnqlmqZ3uI7EPyYYRgLyW2redsa +jwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7BRNQZESjyk6IP99SQFSrutDbZmWlCuaWV8SfC7y5xc=; fh=yh80xiW7p4Avcmng92X6j/o2WupY0MhLlwOAQ6dOBH8=; b=HB6/TsJ+M+3b6Xvj+lWX99mxnOKqMGteLBJlwcoOTMzTD580mP0EKrLNizn5iFcJyE Mx81cqQRxMbtYqzKbir1WXXvIG9QB1zoTbBtXv54Qd7WrZ/yhOL8uWl+QHixRUKIUdI2 15Dzo8AhfAGevmWy3r1oRMPCb4FwN3L3RXYg0+I4qu6r/E+2p+3tChJ387s7u+z8g3fZ Hjc3GjIo6VgkmoYD+fzLgn+W8vE0TEc92io6x6466xuTZuEhzSpko2D5K+6F+2hJJ+Ia FkRVUcjOuHrApusT8dceJoi3fudn39VFSnMGSgk++RwtkKvJRFt2hy3ltxNvsB4SgC7T c6/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RescUJyA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a170902d4c500b001b3c7e6a8c0si5307802plg.531.2023.08.01.19.46.20; Tue, 01 Aug 2023 19:46:32 -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=@gmail.com header.s=20221208 header.b=RescUJyA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230471AbjHBCCZ (ORCPT + 99 others); Tue, 1 Aug 2023 22:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbjHBCCW (ORCPT ); Tue, 1 Aug 2023 22:02:22 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B201E67; Tue, 1 Aug 2023 19:02:21 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b9bd59d465so97404251fa.3; Tue, 01 Aug 2023 19:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690941739; x=1691546539; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7BRNQZESjyk6IP99SQFSrutDbZmWlCuaWV8SfC7y5xc=; b=RescUJyA4czz2u48U2yw6OwDEJhPPMZ5LPu/vHcqMP2ujZH2KrD93KlDeAzenoKEQV 2lTjLCYkYzvWRowhIE4IlB27gLUJ5UUVgAIvqpAHZd5ynlMs5CQQNG35qkhmHDebxT5P V8VUysW079YKkGkz9/ivxoDvOQ3i6EF+X85hYKxDmt+nd82A53KN/Zy0KRXZ6TbAzjLG d4q8oaVncLzZ2GGhw0fxstmxv0oLqDlSev+NubvETyLS5f1YFDLLwz2IlM+SxtqKxVJR 7Cit8m8XPAVblxn5NVRaai4sCh67qSxbEAb4KrlypAJRTqAK3uE5obDASpc8aalSo3+G AjeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690941739; x=1691546539; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7BRNQZESjyk6IP99SQFSrutDbZmWlCuaWV8SfC7y5xc=; b=DkO5SfgcRFSN2VqxeaMLJXfHKvp31mW314oRru5r14qaFCbdT2Ei/DEzC3CCk53ErJ AxACtLj2EXAJCs14cFtAqGnNlQ7XGhZbHXR9ea2DUkcwi6D8QNqPDzVgb0ud3Wr+qNEz eedlqRPETBl+pMOK3p+K6jhvrSm/RzzfboACJiY2Q6zyGqhlA4V4KbVBO/PSkycz+Jpc d89UvaZS58EkcI3q7abFXo9VnDe75v9fYQZpZf0WE1XR9CcjJObfdRjppj1Y/FYQw7bL XvRtkndxZur9tPr3lS/7Svib+yB+yP0Fu9yKufDqIe/RwctecRZTQVeLuCMAxQiTdmdk 0GYg== X-Gm-Message-State: ABy/qLbTA33O42rBjnP/9AEp/06hsAnu1PqvgIRQyC8XeQb2MsH5SphO MKgrTcT7yVwhlDssl5eFsc1Yl3HM9yRMpLDBolk= X-Received: by 2002:a2e:9942:0:b0:2b9:cb2a:11bf with SMTP id r2-20020a2e9942000000b002b9cb2a11bfmr3820055ljj.49.1690941739021; Tue, 01 Aug 2023 19:02:19 -0700 (PDT) MIME-Version: 1.0 References: <36b5837e9e94465dd2b7d7a17bb84dea082f2ffa.1690364259.git.haibo1.xu@intel.com> <20230728-42019a78766a59dc5abdd412@orel> In-Reply-To: <20230728-42019a78766a59dc5abdd412@orel> From: Haibo Xu Date: Wed, 2 Aug 2023 10:02:07 +0800 Message-ID: Subject: Re: [PATCH 3/4] KVM: riscv: selftests: Add guest helper to get vcpu id To: Andrew Jones Cc: Haibo Xu , Paul Walmsley , Palmer Dabbelt , Albert Ou , Paolo Bonzini , Shuah Khan , Anup Patel , Atish Patra , Sean Christopherson , Colton Lewis , Andrew Jones , Vipin Sharma , Marc Zyngier , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, kvm-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 On Fri, Jul 28, 2023 at 5:49=E2=80=AFPM Andrew Jones wrote: > > On Thu, Jul 27, 2023 at 03:20:07PM +0800, Haibo Xu wrote: > > Add guest_get_vcpuid() helper to simplify accessing to per-cpu > > private data. The sscratch CSR was used to store the vcpu id. > > > > Signed-off-by: Haibo Xu > > --- > > tools/testing/selftests/kvm/include/riscv/processor.h | 2 ++ > > tools/testing/selftests/kvm/lib/riscv/processor.c | 8 ++++++++ > > 2 files changed, 10 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/to= ols/testing/selftests/kvm/include/riscv/processor.h > > index 9ea6e7bedc61..ca53570ce6de 100644 > > --- a/tools/testing/selftests/kvm/include/riscv/processor.h > > +++ b/tools/testing/selftests/kvm/include/riscv/processor.h > > @@ -165,4 +165,6 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned = long arg0, > > unsigned long arg3, unsigned long arg4, > > unsigned long arg5); > > > > +uint32_t guest_get_vcpuid(void); > > I'd also put this prototype somewhere common. > > > + > > #endif /* SELFTEST_KVM_PROCESSOR_H */ > > diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/= testing/selftests/kvm/lib/riscv/processor.c > > index f1b0be58a5dc..b8ad3e69a697 100644 > > --- a/tools/testing/selftests/kvm/lib/riscv/processor.c > > +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c > > @@ -316,6 +316,9 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm= , uint32_t vcpu_id, > > vcpu_set_reg(vcpu, RISCV_CORE_REG(regs.sp), stack_vaddr + stack_s= ize); > > vcpu_set_reg(vcpu, RISCV_CORE_REG(regs.pc), (unsigned long)guest_= code); > > > > + /* Setup scratch regiter of guest */ > > typo: register > > The comment above is pretty useless since it just states what the code > states, but with even less information, since it doesn't state how the > sscratch register is getting set up. I'd either drop it or write it > as > > /* Setup sscratch for guest_get_vcpuid() */ > > > + vcpu_set_reg(vcpu, RISCV_CSR_REG(sscratch), vcpu_id); > > + > > /* Setup default exception vector of guest */ > > vcpu_set_reg(vcpu, RISCV_CSR_REG(stvec), (unsigned long)guest_une= xp_trap); > > > > @@ -424,3 +427,8 @@ void vm_install_interrupt_handler(struct kvm_vm *vm= , void (*handler)(struct ex_r > > > > handlers->exception_handlers[1][0] =3D handler; > > } > > + > > +uint32_t guest_get_vcpuid(void) > > +{ > > + return csr_read(CSR_SSCRATCH); > > +} > > -- > > 2.34.1 > > > Sure! will fix them in v2. Thanks, Haibo > Thanks, > drew