From patchwork Thu Sep 14 01:37:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 139220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp47337vqi; Wed, 13 Sep 2023 18:36:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhfBnEaWyQefOqOiX/0ynedvhp3A6GuA5XU2VqoDQLvuUtHcSE71hlOBCxroNQmGQhRFet X-Received: by 2002:a05:6358:f089:b0:142:d3dc:d3f3 with SMTP id ig9-20020a056358f08900b00142d3dcd3f3mr5027826rwb.0.1694655390481; Wed, 13 Sep 2023 18:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694655390; cv=none; d=google.com; s=arc-20160816; b=mEyy33PcrCnKjcAspdt+YdPZRKzK8jf5p6FVmD0t3m3ZdnuqLN+MK0zGZa4CcXuJYR FqbZ0Prt8a0k65cMDnp/zjPFel8taROiQKuwPdIEj0esP/ZlSZ+oLRUP/x8q5C7vMUg/ OeG24K1L8N1V56AAG8INSXwYOOvhKbklZxRZILfiWwTXQFb46CgZ651jR4Wx/RceumIL TZokXjk/o+nBMw273yrIlAdt8iTY+2tjYVN2pQvT/DhvViZ/pml1H3FVGWMBCUh5/zpS 9Y8Yx8316E3vBKMAJioJ02tRssaZQZJv6FWadoJ8rhK6qltZlWtBjjsSrYJbMfVFcfcp Ikgw== 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.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g5-20020a636b05000000b0057760853711si371507pgc.273.2023.09.13.18.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 18:36:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; 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.37 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 snail.vger.email (Postfix) with ESMTP id 1AFDF81CE10E; Wed, 13 Sep 2023 18:29:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233878AbjINB3s (ORCPT + 35 others); Wed, 13 Sep 2023 21:29:48 -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 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 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 18:29:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776974970604873856 X-GMAIL-MSGID: 1776974970604873856 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); +}