On 8/4/23 21:56, Yifei Ma wrote:
The doc says "Read the KVM_VCPU_TSC_OFFSET attribute for*every vCPU* to record the guest TSC offset”. However, the KVM API for getting/setting the offset is not through vCPU’s fd, it is through KVM device's fd, E.g., when I refer to the KVM selftest code, I found accessing TSC_OFFSET is through the “KVM_SET_DEVICE_ATTR” cmd, with args “KVM_VCPU_TSC_CTRL” & “KVM_VCPU_TSC_OFFSET”. It looks like the API sets the TSC offset on all vCPUs, instead of a single vCPU.
KVM_SET_DEVICE_ATTR is accessible through the vCPU fd as well. In particular, the group=KVM_VCPU_TSC_CTRL attr=KVM_VCPU_TSC_OFFSET is available through the vCPU fd.
On x86, the device fd instead supports group=0 attr=KVM_X86_XCOMP_GUEST_SUPP.
Paolo