Re: [PATCH v16 49/51] KVM: selftests: Add coverate for KVM-defined registers in MSRs test

Chao Gao
2025-09-23T06:32:10Z

On Fri, Sep 19, 2025 at 03:32:56PM -0700, Sean Christopherson wrote:
>Add test coverage for the KVM-defined GUEST_SSP "register" in the MSRs
>test. While _KVM's_ goal is to not tie the uAPI of KVM-defined registers
>to any particular internal implementation, i.e. to not commit in uAPI to
>handling GUEST_SSP as an MSR, treating GUEST_SSP as an MSR for testing
>purposes is a-ok and is a naturally fit given the semantics of SSP.
>
>Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Chao Gao <chao.gao@intel.com>

<snip>

>+static bool vcpu_has_reg(struct kvm_vcpu *vcpu, u64 reg)
>+{
>+ struct {
>+ struct kvm_reg_list list;
>+ u64 regs[KVM_X86_MAX_NR_REGS];
>+ } regs = {};
>+ int r, i;
>+
>+ /*
>+ * If KVM_GET_REG_LIST succeeds with n=0, i.e. there are no supported
>+ * regs, then the vCPU obviously doesn't support the reg.
>+ */
>+ r = __vcpu_ioctl(vcpu, KVM_GET_REG_LIST, &regs.list.n);
^^^^^^^^^^^^
it would be more clear to use &reg.list here.

>+ if (!r)
>+ return false;
>+
>+ TEST_ASSERT_EQ(errno, E2BIG);
>+
>+ /*
>+ * KVM x86 is expected to support enumerating a relative small number
>+ * of regs. The majority of registers supported by KVM_{G,S}ET_ONE_REG
>+ * are enumerated via other ioctls, e.g. KVM_GET_MSR_INDEX_LIST. For
>+ * simplicity, hardcode the maximum number of regs and manually update
>+ * the test as necessary.
>+ */
>+ TEST_ASSERT(regs.list.n <= KVM_X86_MAX_NR_REGS,
>+ "KVM reports %llu regs, test expects at most %u regs, stale test?",
>+ regs.list.n, KVM_X86_MAX_NR_REGS);
>+
>+ vcpu_ioctl(vcpu, KVM_GET_REG_LIST, &regs.list.n);

Ditto.