Re: [PATCH v12 06/24] KVM: x86: Introduce KVM_{G,S}ET_ONE_REG uAPIs support

From: Chao Gao
Date: Thu Aug 21 2025 - 09:24:45 EST


On Wed, Aug 20, 2025 at 04:29:04PM +0800, Chao Gao wrote:
>>> +#define KVM_X86_REG_MSR (1 << 2)
>>> +#define KVM_X86_REG_SYNTHETIC (1 << 3)
>>> +
>>> +struct kvm_x86_reg_id {
>>> + __u32 index;
>>> + __u8 type;
>>> + __u8 rsvd;
>>> + __u16 rsvd16;
>>> +};
>>
>>Some feedback from a while back never got addressed[*]. That feedback still
>>looks sane/good, so this for the uAPI:
>
>I missed that comment. Below is the diff I end up with. I moved struct
>kvm_x86_reg_id to x86.c and added checks for ARCH (i.e., x86) and size.
>
>diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
>index e72d9e6c1739..bb17b7a85159 100644
>--- a/arch/x86/include/uapi/asm/kvm.h
>+++ b/arch/x86/include/uapi/asm/kvm.h
>@@ -411,15 +411,23 @@ struct kvm_xcrs {
> __u64 padding[16];
> };
>
>-#define KVM_X86_REG_MSR (1 << 2)
>-#define KVM_X86_REG_SYNTHETIC (1 << 3)
>-
>-struct kvm_x86_reg_id {
>- __u32 index;
>- __u8 type;
>- __u8 rsvd;
>- __u16 rsvd16;
>-};
>+#define KVM_X86_REG_TYPE_MSR 2
>+#define KVM_X86_REG_TYPE_SYNTHETIC_MSR 3
>+
>+#define KVM_x86_REG_TYPE_SIZE(type) \
>+{( \

There are two typos here. s/x86/X86 and s/{(/({

>+ __u64 type_size = type; \

and this should be __u64 type_size = (__u64)type << 32;

When I tried to add a kselftest for the new ioctls, I found this patch didn't
advertise KVM_CAP_ONE_REG support for x86.