Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1005470rwb; Fri, 28 Jul 2023 03:21:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlFttsLrl6hq8N5sxhFQPti/4/Vk1c60HbskGm/1ibqc5jvNjSwy/Jqxh2q3wo0uQj/sSxIP X-Received: by 2002:a17:906:310d:b0:99b:e243:9ecc with SMTP id 13-20020a170906310d00b0099be2439eccmr1764864ejx.36.1690539679318; Fri, 28 Jul 2023 03:21:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690539679; cv=none; d=google.com; s=arc-20160816; b=U0mxPVhwpfZTO18xyTevjfU6ILicuG/QAH2GBwsBaIJmigIHaad70HZrKIvu+cRa5l dqcRwuHWBKXb5h2E9bpPBGkhBh7eEBFdqO3Md2QmQNqtfLNZ9w3ZUuUBZgRyECJjLTKz JFTWTJoQ0ui3QFboy7j5zV60GXJrSoD9f3oHs00dQUxLPjQPIPFaorSUw466gjs05eAW 2Lu0EvHq+H3q4DnK6j7OhGe+KCGQJb71ZrR5vCqef07VrLxnvnD1065Hy5hQXF72nmSO Uc6oC/FEYL0G6mgwGBjRC+vZc/FWa1CNiMak61CyuCe0R9SVDRFMU+h/syjZ8t3ZKyBa MLxA== 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=q5nn0TL8ozMkfbttvB6kE7ZxMnlIo+EeJgK/9n8Mj1I=; fh=LRBbFSk9XFWdfLfAufsVfTmfF9fy9Kurp7tSqc34It4=; b=N5S/zOO8o0OLr/50sy545eOP4UTL2a6NSUHrpAZIBOigSb0kHk72p8QH/becPmB9Lv OgyE+gTECcxhmp8WnMPbhFfNgx4L6c0fALOFlqA4hUQ5w5Y9HVEA0LjTdJwiIVQvP85K qXjs+U/HC6o5xrYHGvQYc3wN27VVg7XB1DNBfHEdRqdvsUmbro+ru5HWRPqgDWe/Zs7+ k5it+RB/pXWlKtwoKCVuCn3Yr3By0rEQs00VIG4iDcJutcO1tKbd43yk1bJMu5ocx1hw zYXPLfFD4tY0hoX9rx0Brvsf1r0t6iWjWun25I+8StlAvoGRRSTgLR29OQQcnw1fdqCJ C/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=gACLxCuQ; 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 u23-20020a1709064ad700b0098821ac27b7si468055ejt.39.2023.07.28.03.20.55; Fri, 28 Jul 2023 03:21:19 -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=gACLxCuQ; 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 S235057AbjG1Jt3 (ORCPT + 99 others); Fri, 28 Jul 2023 05:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234121AbjG1JtZ (ORCPT ); Fri, 28 Jul 2023 05:49:25 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8305735A3 for ; Fri, 28 Jul 2023 02:49:14 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-52222562f1eso2553586a12.3 for ; Fri, 28 Jul 2023 02:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690537753; x=1691142553; 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=q5nn0TL8ozMkfbttvB6kE7ZxMnlIo+EeJgK/9n8Mj1I=; b=gACLxCuQCEdu51w5VdhqNvVqjzISdVkvlBLeYLgdbaG++mxGSCdtdqms/zahddtjDi j0swRIun2wRShaOvnaf+KJtHxVBLMBAy+i/Ge80sFlOEt9wsFA63xc/mDWcyGjpq2JUI qbn10cgJWzEGQaljXx/EQImIsEBlXmq32QKDgrx368aaSED44YsEtr2B0tLz9452dkzM XFEefqxSqwwuL8g7g/r3nirycyUq5MNoherWPm4I+L1JFLxm6DQYSgpkG9Wz4t4Kf3p4 KSVA0GDbMRnCMeiOnPKc6zLCdQmICLmt+RWoDujl1leVv/QmLV+UMJPjwH1PxcTJoIzG Rgqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690537753; x=1691142553; 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=q5nn0TL8ozMkfbttvB6kE7ZxMnlIo+EeJgK/9n8Mj1I=; b=j5oro9/VUrf2PYu19PCj9Oqj6/AhBgbgm10L7oltJn3ShkHF7eK3Cymo1ZTrO4T2wx WpSbqsO24sgWN+4v5aUkBsu8zmAkw2zE0Xc73J8vjkyqFGMmt2pZSnZIKRili0kkTgoE A66VpRqb1h/3Rd6MDtQN0a6OD3w8giglSaNz51FQj9kLIYHz0QZ1fhpQn56CUlV6g2Xt yc6rbkHrr9fAq2gthOZPE4RLx8I0V0EXkpT3OXcutvwpjf4Pc1z+I+1yY7QaQ46qKIGy MwWXJMjtVwXA64sMuRwL/qhxAfI9kgzV/G6jG4N8y/j7wX8wO+xHukm9891u0kGzNSq1 wZ4Q== X-Gm-Message-State: ABy/qLa2Q7OY7MPpLCiN9DVCYmrnyFhxRX/ngfOW/7RIC02E09x9C6Iy s9Sm4+vfruzxzs8dFpbbfdofjg== X-Received: by 2002:aa7:c0d4:0:b0:522:303c:2f8c with SMTP id j20-20020aa7c0d4000000b00522303c2f8cmr1136476edp.6.1690537752939; Fri, 28 Jul 2023 02:49:12 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id b26-20020aa7d49a000000b0051dfa2e30b2sm1604860edr.9.2023.07.28.02.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 02:49:12 -0700 (PDT) Date: Fri, 28 Jul 2023 11:49:11 +0200 From: Andrew Jones To: Haibo Xu Cc: xiaobo55x@gmail.com, 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 Subject: Re: [PATCH 3/4] KVM: riscv: selftests: Add guest helper to get vcpu id Message-ID: <20230728-42019a78766a59dc5abdd412@orel> References: <36b5837e9e94465dd2b7d7a17bb84dea082f2ffa.1690364259.git.haibo1.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <36b5837e9e94465dd2b7d7a17bb84dea082f2ffa.1690364259.git.haibo1.xu@intel.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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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/tools/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_size); > 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_unexp_trap); > > @@ -424,3 +427,8 @@ void vm_install_interrupt_handler(struct kvm_vm *vm, void (*handler)(struct ex_r > > handlers->exception_handlers[1][0] = handler; > } > + > +uint32_t guest_get_vcpuid(void) > +{ > + return csr_read(CSR_SSCRATCH); > +} > -- > 2.34.1 > Thanks, drew