Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3610074rdb; Wed, 13 Sep 2023 18:29:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFz4VfrQEOHXo3KTWQjef4M98aUlSu9qgTFJKQPOsIeLZ6BMqx78uiZLn4y59hqHUEFlKZ2 X-Received: by 2002:a05:6a00:2289:b0:68a:3c7a:129e with SMTP id f9-20020a056a00228900b0068a3c7a129emr4896683pfe.27.1694654991383; Wed, 13 Sep 2023 18:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694654991; cv=none; d=google.com; s=arc-20160816; b=DKjG3OHKo5+UsgVWIe6eupfdHCLJIKaerHlDJvszyt9ZbjUCVQcNgVvPYLnCEIvzx8 dt1KkwVZqiuki+IPxBBXPjCOE4+ADBirk60m62xYPrCRSOuDYk8rW8UlK1URlQWBT7fY hXcgMa1LYjmN1euo3cXkQ6oZl1pI7rnkFJmeih3eVCXASVwdvVg17Di5NVterdPO3zz6 Vt2j3EOYlypY2oofQtt55KguX3xRy/m9lMvxD/wqxENHCMVU0h9IGcyd3kmEtRiGJ9u9 8z4Zmi+XTJiNPcihJzuA4FtWVcRZ+SDBLqYCDgiG/hvKEyX0NKXek4AZxJin9uK4gdnS isrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=kxbFH5mzBT1nh4oDE9NVdu0yUurjsYdbt4+XSrJSqTI=; fh=8XGyA0DqQ6UhzgGLnaGA2HqDpCCyF4PTg8uAiNuoBIg=; b=s/BPM5zlPfk/PALx8gP0CVXllAOl5eSmOY1bSDfxrF1uTXb1z62mxu2VdUQbcI7BOb H0WVzBTAVBKomACrY01HLLsRmtFLRf1hJE1TvEq9gYIhpri3ahBENsK0rxS1fwNBQ5S9 ZyfJe8TzBKkopc0GPB7AeXjG8gbJZ9a1GgH2ZuVgGxxPpbsIxGMuFqlOESZ/olX9vFEQ VEKyMO1W/+gKt+fZRyiq1c21AOCxzl9rZCEaJ6NScO73i+Wf9aX5QgJ/Otwd1EmvNlSg r/pXgCMWstdOIgPuM6tXgj7nlrTE3n/Z8qco6XQ9ucB09/rJ2MWMt0Q5EEyQrKkoShYN oOJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@intel.com header.s=Intel header.b=WaX8l2PV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id o184-20020a62cdc1000000b0068e45c6ca3fsi451306pfg.93.2023.09.13.18.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 18:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=fail header.i=@intel.com header.s=Intel header.b=WaX8l2PV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CFA9A826E5AC; Wed, 13 Sep 2023 18:29:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233867AbjINB3r (ORCPT + 99 others); Wed, 13 Sep 2023 21:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233828AbjINB3o (ORCPT ); Wed, 13 Sep 2023 21:29:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 802F81BD7; Wed, 13 Sep 2023 18:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694654980; x=1726190980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b/0N3bmHKPwLoIm1d3ucuRyECJSoSIj1ZqZKhOBkTUo=; b=WaX8l2PVp/PejBtCiBLjbUvG9hkW4AAz/DwTq5gzzX3Wo5CPxfNC5/9S FOsUn7FwH1F3JFQxTjsnDrqOMrsRfKYljIN459m3oZ+Y+vJO04Mzj3j1Q PsI2PGtdpskDHiz78/AuWRmQW227AK7/TAp2NRhwrX9dnctvCStBHLyw1 oI8FTmFCASiWLZRCqT7aHyzkxUOJmbvhdqqNLA8tdBM8T3JGHmXanhvA+ ATAtYJ9AlvSx1VlBYcWFGkHU2X114Afka1eonQosn7V3VRXCcNgk2BjSy N8GpJsbgDERdEF7F40cq0ADTiCwVcR5jhS0MEBNwGxECTtTSyHdwYFAr8 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="377734242" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="377734242" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 18:29:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="694049515" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="694049515" Received: from haibo-optiplex-7090.sh.intel.com ([10.239.159.132]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 18:29:33 -0700 From: Haibo Xu Cc: xiaobo55x@gmail.com, haibo1.xu@intel.com, ajones@ventanamicro.com, Paul Walmsley , Palmer Dabbelt , Albert Ou , Paolo Bonzini , Shuah Khan , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Anup Patel , Atish Patra , Sean Christopherson , Ricardo Koller , Vishal Annapurve , Vitaly Kuznetsov , Vipin Sharma , David Matlack , Colton Lewis , Aaron Lewis , Thomas Huth , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [PATCH v3 7/9] KVM: riscv: selftests: Add guest helper to get vcpu id Date: Thu, 14 Sep 2023 09:37:01 +0800 Message-Id: <17c19d6ec28bcde8f3a2d169501a700635c0c332.1694421911.git.haibo1.xu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 18:29:49 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 morse.vger.email 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 Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/include/aarch64/processor.h | 4 ---- tools/testing/selftests/kvm/include/kvm_util_base.h | 2 ++ tools/testing/selftests/kvm/lib/riscv/processor.c | 8 ++++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index 69e7b08d3f99..f41fcd63624f 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -219,8 +219,4 @@ void smccc_smc(uint32_t function_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, struct arm_smccc_res *res); - - -uint32_t guest_get_vcpuid(void); - #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 135ae2eb5249..666438113d22 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -939,4 +939,6 @@ struct ex_regs; typedef void(*exception_handler_fn)(struct ex_regs *); void vm_install_exception_handler(struct kvm_vm *vm, int vector, exception_handler_fn handler); +uint32_t guest_get_vcpuid(void); + #endif /* SELFTEST_KVM_UTIL_BASE_H */ diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c index efd9ac4b0198..39a1e9902dec 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 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); @@ -436,3 +439,8 @@ void vm_install_interrupt_handler(struct kvm_vm *vm, exception_handler_fn handle handlers->exception_handlers[1][0] = handler; } + +uint32_t guest_get_vcpuid(void) +{ + return csr_read(CSR_SSCRATCH); +} -- 2.34.1