Skip to content

Commit f696566

Browse files
shamiali2008oupton
authored andcommitted
KVM: selftests: Add test for KVM_REG_ARM_VENDOR_HYP_BMAP_2
One difference here with other pseudo-firmware bitmap registers is that the default/reset value for the supported hypercall function-ids is 0 at present. Hence, modify the test accordingly. Reviewed-by: Sebastian Ott <sebott@redhat.com> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> Link: https://lore.kernel.org/r/20250221140229.12588-7-shameerali.kolothum.thodi@huawei.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 86edf6b commit f696566

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

tools/arch/arm64/include/uapi/asm/kvm.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ enum {
374374
#endif
375375
};
376376

377+
/* Vendor hyper call function numbers 0-63 */
377378
#define KVM_REG_ARM_VENDOR_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(2)
378379

379380
enum {
@@ -384,6 +385,17 @@ enum {
384385
#endif
385386
};
386387

388+
/* Vendor hyper call function numbers 64-127 */
389+
#define KVM_REG_ARM_VENDOR_HYP_BMAP_2 KVM_REG_ARM_FW_FEAT_BMAP_REG(3)
390+
391+
enum {
392+
KVM_REG_ARM_VENDOR_HYP_BIT_DISCOVER_IMPL_VER = 0,
393+
KVM_REG_ARM_VENDOR_HYP_BIT_DISCOVER_IMPL_CPUS = 1,
394+
#ifdef __KERNEL__
395+
KVM_REG_ARM_VENDOR_HYP_BMAP_2_BIT_COUNT,
396+
#endif
397+
};
398+
387399
/* Device Control API on vm fd */
388400
#define KVM_ARM_VM_SMCCC_CTRL 0
389401
#define KVM_ARM_VM_SMCCC_FILTER 0

tools/testing/selftests/kvm/arm64/get-reg-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ static __u64 base_regs[] = {
332332
KVM_REG_ARM_FW_FEAT_BMAP_REG(0), /* KVM_REG_ARM_STD_BMAP */
333333
KVM_REG_ARM_FW_FEAT_BMAP_REG(1), /* KVM_REG_ARM_STD_HYP_BMAP */
334334
KVM_REG_ARM_FW_FEAT_BMAP_REG(2), /* KVM_REG_ARM_VENDOR_HYP_BMAP */
335+
KVM_REG_ARM_FW_FEAT_BMAP_REG(3), /* KVM_REG_ARM_VENDOR_HYP_BMAP_2 */
335336
ARM64_SYS_REG(3, 3, 14, 3, 1), /* CNTV_CTL_EL0 */
336337
ARM64_SYS_REG(3, 3, 14, 3, 2), /* CNTV_CVAL_EL0 */
337338
ARM64_SYS_REG(3, 3, 14, 0, 2),

tools/testing/selftests/kvm/arm64/hypercalls.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,31 @@
2121
#define KVM_REG_ARM_STD_BMAP_BIT_MAX 0
2222
#define KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX 0
2323
#define KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX 1
24+
#define KVM_REG_ARM_VENDOR_HYP_BMAP_2_BIT_MAX 1
25+
26+
#define KVM_REG_ARM_STD_BMAP_RESET_VAL FW_REG_ULIMIT_VAL(KVM_REG_ARM_STD_BMAP_BIT_MAX)
27+
#define KVM_REG_ARM_STD_HYP_BMAP_RESET_VAL FW_REG_ULIMIT_VAL(KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX)
28+
#define KVM_REG_ARM_VENDOR_HYP_BMAP_RESET_VAL FW_REG_ULIMIT_VAL(KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX)
29+
#define KVM_REG_ARM_VENDOR_HYP_BMAP_2_RESET_VAL 0
2430

2531
struct kvm_fw_reg_info {
2632
uint64_t reg; /* Register definition */
2733
uint64_t max_feat_bit; /* Bit that represents the upper limit of the feature-map */
34+
uint64_t reset_val; /* Reset value for the register */
2835
};
2936

3037
#define FW_REG_INFO(r) \
3138
{ \
3239
.reg = r, \
3340
.max_feat_bit = r##_BIT_MAX, \
41+
.reset_val = r##_RESET_VAL \
3442
}
3543

3644
static const struct kvm_fw_reg_info fw_reg_info[] = {
3745
FW_REG_INFO(KVM_REG_ARM_STD_BMAP),
3846
FW_REG_INFO(KVM_REG_ARM_STD_HYP_BMAP),
3947
FW_REG_INFO(KVM_REG_ARM_VENDOR_HYP_BMAP),
48+
FW_REG_INFO(KVM_REG_ARM_VENDOR_HYP_BMAP_2),
4049
};
4150

4251
enum test_stage {
@@ -171,22 +180,39 @@ static void test_fw_regs_before_vm_start(struct kvm_vcpu *vcpu)
171180

172181
for (i = 0; i < ARRAY_SIZE(fw_reg_info); i++) {
173182
const struct kvm_fw_reg_info *reg_info = &fw_reg_info[i];
183+
uint64_t set_val;
174184

175-
/* First 'read' should be an upper limit of the features supported */
185+
/* First 'read' should be the reset value for the reg */
176186
val = vcpu_get_reg(vcpu, reg_info->reg);
177-
TEST_ASSERT(val == FW_REG_ULIMIT_VAL(reg_info->max_feat_bit),
178-
"Expected all the features to be set for reg: 0x%lx; expected: 0x%lx; read: 0x%lx",
179-
reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit), val);
187+
TEST_ASSERT(val == reg_info->reset_val,
188+
"Unexpected reset value for reg: 0x%lx; expected: 0x%lx; read: 0x%lx",
189+
reg_info->reg, reg_info->reset_val, val);
190+
191+
if (reg_info->reset_val)
192+
set_val = 0;
193+
else
194+
set_val = FW_REG_ULIMIT_VAL(reg_info->max_feat_bit);
180195

181-
/* Test a 'write' by disabling all the features of the register map */
182-
ret = __vcpu_set_reg(vcpu, reg_info->reg, 0);
196+
ret = __vcpu_set_reg(vcpu, reg_info->reg, set_val);
183197
TEST_ASSERT(ret == 0,
184-
"Failed to clear all the features of reg: 0x%lx; ret: %d",
185-
reg_info->reg, errno);
198+
"Failed to %s all the features of reg: 0x%lx; ret: %d",
199+
(set_val ? "set" : "clear"), reg_info->reg, errno);
186200

187201
val = vcpu_get_reg(vcpu, reg_info->reg);
188-
TEST_ASSERT(val == 0,
189-
"Expected all the features to be cleared for reg: 0x%lx", reg_info->reg);
202+
TEST_ASSERT(val == set_val,
203+
"Expected all the features to be %s for reg: 0x%lx",
204+
(set_val ? "set" : "cleared"), reg_info->reg);
205+
206+
/*
207+
* If the reg has been set, clear it as test_fw_regs_after_vm_start()
208+
* expects it to be cleared.
209+
*/
210+
if (set_val) {
211+
ret = __vcpu_set_reg(vcpu, reg_info->reg, 0);
212+
TEST_ASSERT(ret == 0,
213+
"Failed to clear all the features of reg: 0x%lx; ret: %d",
214+
reg_info->reg, errno);
215+
}
190216

191217
/*
192218
* Test enabling a feature that's not supported.

0 commit comments

Comments
 (0)