Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4514452rdb; Tue, 12 Dec 2023 01:21:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvOcGlTYSn5ysd7KKyiCjFZIQKe/EcX+zDb/RaBFNYZDyh9RDf3mgy+yhj9yUuwXOhHd9g X-Received: by 2002:a17:90a:4884:b0:28a:b5ac:93db with SMTP id b4-20020a17090a488400b0028ab5ac93dbmr580708pjh.33.1702372912485; Tue, 12 Dec 2023 01:21:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702372912; cv=none; d=google.com; s=arc-20160816; b=leRiBj6KLC36HPcGdwyFq9gI/rHVuHZn8GNj5h+A5ynI554yKmqZv2+x3ckNM+aY1B iUifcLhCaqaSNQmDXIP3RyRTYNy/G0s9ZvRnSMYj1gjOcGuy2EWVkyeWmcwrsyLmmwYN RXTmjJ0yvu9fn4mfLv3uXOcHRSiJppTAEkiwYnRjwfZkVPDuy1H2fcLBoaRzyKe/IdRU umUiKGyVepIFPWWVYHt+n87HSTj7D88LoCO75oqAgQzHeRsqcRPx2KRteU//mQH7OjWj KMCVa+3Q+ks7Pe3X2J7dnnTMc/uFcLM7tjYHH2lr9nDbBUTA+hq41pgEqd+SJS/TVM+P boUg== 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=rHGIbuDRJFmGXEbnkjs6L01uuWoLNs89EzBH2buLpsA=; fh=R91aIMEQl1c3/SZMMU7MYOf6ewqA9kVk8Rb3yt+9yGw=; b=o5pA0klVoeR1U93bXLTR2gJJcq79qr3G7t7D0S/wc1JJFrpgbwRShpqzxbFWlxgsIK 9KicEAihZGDVxjBl/HWloPLOrZJVidHRzjxf0qRrU93HvUFU5a2/0C4qv5a8WZ4cK+3w ACbkRpZOXrfIv6s0JIZG92N8nAoHHRZY0mb1jXAyLrcZ78xWYDleFowCcT7kVWWIdc/L OTwIfWyScUdgSeEH3favjPPbAB4bPWZyvyYW3P1FUELvmsNrzbdEx1FAp3CBj0k6ln4B n1BGdtk6YuHhW6c90B2BbuwagHaI+HuyTl9DGx4NyiVEPBWNx+a/S6oPFjEwVZCjH5f3 mQyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@intel.com header.s=Intel header.b=Qz42eD5v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id d24-20020a17090ab31800b0028a9b910230si2636268pjr.116.2023.12.12.01.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 01:21:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=fail header.i=@intel.com header.s=Intel header.b=Qz42eD5v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id D281E80A443B; Tue, 12 Dec 2023 01:21:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346362AbjLLJVf (ORCPT + 99 others); Tue, 12 Dec 2023 04:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235329AbjLLJVM (ORCPT ); Tue, 12 Dec 2023 04:21:12 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DB03F7; Tue, 12 Dec 2023 01:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702372876; x=1733908876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tcwg5cDbVW/bdr5Y+a/ZcTpguYUa0xH/g6hVAHEIPkU=; b=Qz42eD5vf+0GzxbtRohjKpEwroLvja+B06m5KxKADIqJ8EpVn1dE9VRs 0jijGe/qMp002PfPNnwDHssGCq2ShheuKPcZ5XKMOoCqnlkF0M2lBaYhR Pr9l9n02SS2igeiWc3SSo8N51vKvEbTr9pSbQpqWz2Y4mxT53grCKOgV6 5gl0256tfeyJ7GkGmgq29YpgkIpaisRBldgXYISi07uxXTdGxI0/DR6o3 wx+QCT8Gz7KpnOdmufDzueCSd4EwZ5AjugvSjcFZFW6wyqBryoiinBXpM +iSRZIroEtcJHwBL0gbbUe7fZGYhWjObx6gZwdmHW+LCHXZLugYqcRSxo w==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="480974420" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="480974420" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 01:21:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="917213407" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="917213407" Received: from haibo-optiplex-7090.sh.intel.com ([10.239.159.132]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 01:21:07 -0800 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 , Guo Ren , Conor Dooley , Mayuresh Chitale , Greentime Hu , wchen , Jisheng Zhang , Minda Chen , Samuel Holland , Sean Christopherson , Like Xu , Peter Xu , Vipin Sharma , Aaron Lewis , Thomas Huth , Maciej Wieczor-Retman , 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 v4 08/11] KVM: riscv: selftests: Add guest helper to get vcpu id Date: Tue, 12 Dec 2023 17:31:17 +0800 Message-Id: <02f6c9ccaaeb4ceb67137863e0317f62cef62496.1702371136.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 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 12 Dec 2023 01:21:50 -0800 (PST) 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 | 9 +++++++++ tools/testing/selftests/kvm/lib/riscv/processor.c | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index c42d683102c7..16ae0ac01879 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -226,8 +226,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 a18db6a7b3cf..666438113d22 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -932,4 +932,13 @@ void kvm_selftest_arch_init(void); void kvm_arch_vm_post_create(struct kvm_vm *vm); +void vm_init_vector_tables(struct kvm_vm *vm); +void vcpu_init_vector_tables(struct kvm_vcpu *vcpu); + +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