public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Raghavendra Rao Ananta <rananta@google.com>
To: Marc Zyngier <maz@kernel.org>, Andrew Jones <drjones@redhat.com>,
	James Morse <james.morse@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Peter Shier <pshier@google.com>,
	Ricardo Koller <ricarkol@google.com>,
	Oliver Upton <oupton@google.com>,
	Reiji Watanabe <reijiw@google.com>,
	Jing Zhang <jingzhangos@google.com>,
	Raghavendra Rao Anata <rananta@google.com>,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Subject: [PATCH v4 12/13] selftests: KVM: aarch64: hypercalls: Test with KVM_CAP_ARM_REG_SCOPE
Date: Thu, 24 Feb 2022 17:25:58 +0000	[thread overview]
Message-ID: <20220224172559.4170192-13-rananta@google.com> (raw)
In-Reply-To: <20220224172559.4170192-1-rananta@google.com>

Upgrade the aarch64/hypercalls test to also consider the
firmware register's scope information. Thus, run the test
with the capability KVM_CAP_ARM_REG_SCOPE disabled and enabled.

Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 .../selftests/kvm/aarch64/hypercalls.c        | 83 +++++++++++++++++--
 1 file changed, 75 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/kvm/aarch64/hypercalls.c b/tools/testing/selftests/kvm/aarch64/hypercalls.c
index e4e3a286ff3e..85818b91b4fb 100644
--- a/tools/testing/selftests/kvm/aarch64/hypercalls.c
+++ b/tools/testing/selftests/kvm/aarch64/hypercalls.c
@@ -29,7 +29,7 @@ struct kvm_fw_reg_info {
 		.max_feat_bit = bit_max,	\
 	}
 
-static const struct kvm_fw_reg_info fw_reg_info[] = {
+static struct kvm_fw_reg_info fw_reg_info[] = {
 	FW_REG_INFO(KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_BMAP_BIT_MAX),
 	FW_REG_INFO(KVM_REG_ARM_STD_HYP_BMAP, KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX),
 	FW_REG_INFO(KVM_REG_ARM_VENDOR_HYP_BMAP, KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX),
@@ -294,19 +294,78 @@ static void test_fw_regs_after_vm_start(struct kvm_vm *vm)
 	}
 }
 
-static struct kvm_vm *test_vm_create(void)
+static bool test_reg_is_bmap_fw_reg(uint64_t reg)
+{
+	if ((reg & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW &&
+		(reg & 0xffff) >= 0xff00) /* Bitmap firmware register space */
+		return true;
+
+	return false;
+}
+
+static void test_fw_regs_encode_vm_scope(void)
+{
+	int i;
+
+	/*
+	 * Encode the scope as KVM_REG_ARM_SCOPE_VM for further use
+	 * in KVM_SET_ONE_REG and KVM_GET_ONE_REG operations.
+	 */
+	for (i = 0; i < ARRAY_SIZE(fw_reg_info); i++)
+		fw_reg_info[i].reg |= (KVM_REG_ARM_SCOPE_VM << KVM_REG_ARM_SCOPE_SHIFT);
+}
+
+static void test_validate_fw_regs(struct kvm_vm *vm, int scope)
+{
+	uint64_t i, reg;
+	int obtained_scope;
+	struct kvm_reg_list *reg_list;
+
+	reg_list = vcpu_get_reg_list(vm, 0);
+
+	for (i = 0; i < reg_list->n; i++) {
+		reg = reg_list->reg[i];
+		if (!test_reg_is_bmap_fw_reg(reg))
+			continue;
+
+		/*
+		 * Depending on KVM_CAP_ARM_REG_SCOPE, currently all the firmware
+		 * bitmap registers are either completely VM-scoped or vCPU scoped.
+		 */
+		obtained_scope = (reg & KVM_REG_ARM_SCOPE_MASK) >> KVM_REG_ARM_SCOPE_SHIFT;
+		TEST_ASSERT(obtained_scope == scope,
+				"Incorrect scope detected for reg: %lx. Expected: %d; Obtained: %d\n",
+				reg, scope, obtained_scope);
+	}
+}
+
+static struct kvm_vm *test_vm_create(int scope)
 {
 	struct kvm_vm *vm;
+	struct kvm_enable_cap reg_scope_cap = {
+		.cap = KVM_CAP_ARM_REG_SCOPE,
+	};
+
+	if (scope == KVM_REG_ARM_SCOPE_VM && !kvm_check_cap(KVM_CAP_ARM_REG_SCOPE)) {
+		print_skip("Capability KVM_CAP_ARM_REG_SCOPE unavailable\n");
+		return NULL;
+	}
 
 	vm = vm_create_default(0, 0, guest_code);
 
 	ucall_init(vm, NULL);
 	steal_time_init(vm);
 
+	if (scope == KVM_REG_ARM_SCOPE_VM) {
+		vm_enable_cap(vm, &reg_scope_cap);
+		test_fw_regs_encode_vm_scope();
+	}
+
 	return vm;
 }
 
-static struct kvm_vm *test_guest_stage(struct kvm_vm *vm)
+static struct kvm_vm *
+test_guest_stage(struct kvm_vm *vm, int scope)
 {
 	struct kvm_vm *ret_vm = vm;
 
@@ -319,7 +378,7 @@ static struct kvm_vm *test_guest_stage(struct kvm_vm *vm)
 	case TEST_STAGE_HVC_IFACE_FEAT_DISABLED:
 		/* Start a new VM so that all the features are now enabled by default */
 		kvm_vm_free(vm);
-		ret_vm = test_vm_create();
+		ret_vm = test_vm_create(scope);
 		break;
 	case TEST_STAGE_HVC_IFACE_FEAT_ENABLED:
 	case TEST_STAGE_HVC_IFACE_FALSE_INFO:
@@ -334,14 +393,20 @@ static struct kvm_vm *test_guest_stage(struct kvm_vm *vm)
 	return ret_vm;
 }
 
-static void test_run(void)
+static void test_run(int scope)
 {
 	struct kvm_vm *vm;
 	struct ucall uc;
 	bool guest_done = false;
 
-	vm = test_vm_create();
+	vm = test_vm_create(scope);
+	if (!vm)
+		return;
 
+	stage = TEST_STAGE_REG_IFACE;
+	sync_global_to_guest(vm, stage);
+
+	test_validate_fw_regs(vm, scope);
 	test_fw_regs_before_vm_start(vm);
 
 	while (!guest_done) {
@@ -349,7 +414,7 @@ static void test_run(void)
 
 		switch (get_ucall(vm, 0, &uc)) {
 		case UCALL_SYNC:
-			vm = test_guest_stage(vm);
+			vm = test_guest_stage(vm, scope);
 			break;
 		case UCALL_DONE:
 			guest_done = true;
@@ -371,6 +436,8 @@ int main(void)
 {
 	setbuf(stdout, NULL);
 
-	test_run();
+	test_run(KVM_REG_ARM_SCOPE_VCPU);
+	test_run(KVM_REG_ARM_SCOPE_VM);
+
 	return 0;
 }
-- 
2.35.1.473.g83b2b277ed-goog


  parent reply	other threads:[~2022-02-24 17:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 17:25 [PATCH v4 00/13] KVM: arm64: Add support for hypercall services selection Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 01/13] KVM: arm64: Factor out firmware register handling from psci.c Raghavendra Rao Ananta
2022-03-14 18:15   ` Oliver Upton
2022-03-14 23:15     ` Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 02/13] KVM: arm64: Introduce KVM_CAP_ARM_REG_SCOPE Raghavendra Rao Ananta
2022-02-25  6:42   ` Oliver Upton
2022-02-25 17:34     ` Raghavendra Rao Ananta
2022-02-25 18:26       ` Oliver Upton
2022-02-28 19:46         ` Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 03/13] KVM: arm64: Encode the scope for firmware registers Raghavendra Rao Ananta
2022-03-14 19:16   ` Oliver Upton
2022-02-24 17:25 ` [PATCH v4 04/13] KVM: arm64: Capture VM's first run Raghavendra Rao Ananta
2022-03-14 18:02   ` Oliver Upton
2022-03-14 23:12     ` Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 05/13] KVM: arm64: Setup a framework for hypercall bitmap firmware registers Raghavendra Rao Ananta
2022-03-14 19:41   ` Oliver Upton
2022-03-14 20:25     ` Oliver Upton
2022-03-15  0:22     ` Raghavendra Rao Ananta
2022-03-15  7:25       ` Oliver Upton
2022-03-15 16:59         ` Raghavendra Rao Ananta
2022-03-15 17:35           ` Oliver Upton
2022-02-24 17:25 ` [PATCH v4 06/13] KVM: arm64: Add standard hypervisor firmware register Raghavendra Rao Ananta
2022-03-14 19:45   ` Oliver Upton
2022-03-15  0:23     ` Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 07/13] KVM: arm64: Add vendor " Raghavendra Rao Ananta
2022-03-14 19:59   ` Oliver Upton
2022-03-15  0:30     ` Raghavendra Rao Ananta
2022-03-15  6:41       ` Oliver Upton
2022-03-15 17:53         ` Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 08/13] Docs: KVM: Add doc for the bitmap firmware registers Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 09/13] Docs: KVM: Rename psci.rst to hypercalls.rst Raghavendra Rao Ananta
2022-03-14 20:01   ` Oliver Upton
2022-03-15  0:31     ` Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 10/13] tools: Import ARM SMCCC definitions Raghavendra Rao Ananta
2022-02-24 17:25 ` [PATCH v4 11/13] selftests: KVM: aarch64: Introduce hypercall ABI test Raghavendra Rao Ananta
2022-02-24 17:25 ` Raghavendra Rao Ananta [this message]
2022-02-24 17:25 ` [PATCH v4 13/13] selftests: KVM: aarch64: Add the bitmap firmware registers to get-reg-list Raghavendra Rao Ananta
2022-03-14 20:02   ` Oliver Upton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220224172559.4170192-13-rananta@google.com \
    --to=rananta@google.com \
    --cc=alexandru.elisei@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=drjones@redhat.com \
    --cc=james.morse@arm.com \
    --cc=jingzhangos@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    --cc=pshier@google.com \
    --cc=reijiw@google.com \
    --cc=ricarkol@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox