mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 06:02:05 +00:00
KVM Xen change for 6.8:
To workaround Xen guests that don't expect Xen PV clocks to be marked as being based on a stable TSC, add a Xen config knob to allow userspace to opt out of KVM setting the "TSC stable" bit in Xen PV clocks. Note, the "TSC stable" bit was added to the PVCLOCK ABI by KVM without an ack from Xen, i.e. KVM isn't entirely blameless for the buggy guest behavior. -----BEGIN PGP SIGNATURE----- iQJGBAABCgAwFiEEMHr+pfEFOIzK+KY1YJEiAU0MEvkFAmWXASsSHHNlYW5qY0Bn b29nbGUuY29tAAoJEGCRIgFNDBL5R54P/iQPQBs4dJmNkPiA6uSq1O5/8hN4P59z aapJNgDiny/D9/zPbOxGWR31W7lvCgiES/lp3KcHZmwbeAwJpdT6a0cJWGRlGuov gccK8AoYcnwSU98sPisnFv7dJ66ogJfXVkPKKaWo+zVW53XUq2XpIie4eWaOweBt QsXpTGYpGajv1Bf/MgRtNtlkVAo1w8XL1L0NWRugzCk2CAYezz8IT1874GNZoJbd GJfVP+76FdNw+4/CxiaBwxP0gHfBIiAsJzGqbmMPhGG2xJn+KGs5FTEf37Pta8cl aMHAq6/JAoabJfP39MexVkopMaFlPbDwIWfkLWf6wSP86KHei+t9kLC0E4/R2NJ+ GKlrBB6Gj+gzFR4fZ75hIwS/4REMt6zVCbS7uSRrCduqrlEFcY5ED2NesoL9wZrB WMDIxIGIVDdRxc9WLypKmBj7KTgL0qXBxnsAcPiDRf1sk6SGajkesWxA1C1Nzo/H yNfqq0gjdPZVB2RIGN6DpWQFu3d+ZQnG2ToKIBW7OkvJ5USYiDSo4VozhESgYHRZ UJDhJ73QYESynClP6ST+9cxNof3FXCEPDeKr5NcmjVZxlJcdeUDNRqv0LUxQ56BI FvHMHtSs4WLYHZZVzsdh+Yhnc9rEGfoL0NwDPBCcOXjuNMvNQmuzSldc/VDGm/qt sCtxYMms5n7u =3v8F -----END PGP SIGNATURE----- Merge tag 'kvm-x86-xen-6.8' of https://github.com/kvm-x86/linux into HEAD KVM Xen change for 6.8: To workaround Xen guests that don't expect Xen PV clocks to be marked as being based on a stable TSC, add a Xen config knob to allow userspace to opt out of KVM setting the "TSC stable" bit in Xen PV clocks. Note, the "TSC stable" bit was added to the PVCLOCK ABI by KVM without an ack from Xen, i.e. KVM isn't entirely blameless for the buggy guest behavior.
This commit is contained in:
commit
3115d2de39
@ -8550,6 +8550,7 @@ PVHVM guests. Valid flags are::
|
||||
#define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)
|
||||
#define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5)
|
||||
#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)
|
||||
#define KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE (1 << 7)
|
||||
|
||||
The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
|
||||
ioctl is available, for the guest to set its hypercall page.
|
||||
@ -8593,6 +8594,11 @@ behave more correctly, not using the XEN_RUNSTATE_UPDATE flag until/unless
|
||||
specifically enabled (by the guest making the hypercall, causing the VMM
|
||||
to enable the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute).
|
||||
|
||||
The KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE flag indicates that KVM supports
|
||||
clearing the PVCLOCK_TSC_STABLE_BIT flag in Xen pvclock sources. This will be
|
||||
done when the KVM_CAP_XEN_HVM ioctl sets the
|
||||
KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE flag.
|
||||
|
||||
8.31 KVM_CAP_PPC_MULTITCE
|
||||
-------------------------
|
||||
|
||||
|
@ -3110,7 +3110,8 @@ u64 get_kvmclock_ns(struct kvm *kvm)
|
||||
|
||||
static void kvm_setup_guest_pvclock(struct kvm_vcpu *v,
|
||||
struct gfn_to_pfn_cache *gpc,
|
||||
unsigned int offset)
|
||||
unsigned int offset,
|
||||
bool force_tsc_unstable)
|
||||
{
|
||||
struct kvm_vcpu_arch *vcpu = &v->arch;
|
||||
struct pvclock_vcpu_time_info *guest_hv_clock;
|
||||
@ -3147,6 +3148,10 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v,
|
||||
}
|
||||
|
||||
memcpy(guest_hv_clock, &vcpu->hv_clock, sizeof(*guest_hv_clock));
|
||||
|
||||
if (force_tsc_unstable)
|
||||
guest_hv_clock->flags &= ~PVCLOCK_TSC_STABLE_BIT;
|
||||
|
||||
smp_wmb();
|
||||
|
||||
guest_hv_clock->version = ++vcpu->hv_clock.version;
|
||||
@ -3167,6 +3172,16 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
|
||||
u64 tsc_timestamp, host_tsc;
|
||||
u8 pvclock_flags;
|
||||
bool use_master_clock;
|
||||
#ifdef CONFIG_KVM_XEN
|
||||
/*
|
||||
* For Xen guests we may need to override PVCLOCK_TSC_STABLE_BIT as unless
|
||||
* explicitly told to use TSC as its clocksource Xen will not set this bit.
|
||||
* This default behaviour led to bugs in some guest kernels which cause
|
||||
* problems if they observe PVCLOCK_TSC_STABLE_BIT in the pvclock flags.
|
||||
*/
|
||||
bool xen_pvclock_tsc_unstable =
|
||||
ka->xen_hvm_config.flags & KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE;
|
||||
#endif
|
||||
|
||||
kernel_ns = 0;
|
||||
host_tsc = 0;
|
||||
@ -3245,13 +3260,15 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
|
||||
vcpu->hv_clock.flags = pvclock_flags;
|
||||
|
||||
if (vcpu->pv_time.active)
|
||||
kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0);
|
||||
kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0, false);
|
||||
#ifdef CONFIG_KVM_XEN
|
||||
if (vcpu->xen.vcpu_info_cache.active)
|
||||
kvm_setup_guest_pvclock(v, &vcpu->xen.vcpu_info_cache,
|
||||
offsetof(struct compat_vcpu_info, time));
|
||||
offsetof(struct compat_vcpu_info, time),
|
||||
xen_pvclock_tsc_unstable);
|
||||
if (vcpu->xen.vcpu_time_info_cache.active)
|
||||
kvm_setup_guest_pvclock(v, &vcpu->xen.vcpu_time_info_cache, 0);
|
||||
kvm_setup_guest_pvclock(v, &vcpu->xen.vcpu_time_info_cache, 0,
|
||||
xen_pvclock_tsc_unstable);
|
||||
#endif
|
||||
kvm_hv_setup_tsc_page(v->kvm, &vcpu->hv_clock);
|
||||
return 0;
|
||||
@ -4660,7 +4677,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
|
||||
KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL |
|
||||
KVM_XEN_HVM_CONFIG_SHARED_INFO |
|
||||
KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL |
|
||||
KVM_XEN_HVM_CONFIG_EVTCHN_SEND;
|
||||
KVM_XEN_HVM_CONFIG_EVTCHN_SEND |
|
||||
KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE;
|
||||
if (sched_info_on())
|
||||
r |= KVM_XEN_HVM_CONFIG_RUNSTATE |
|
||||
KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG;
|
||||
|
@ -1162,7 +1162,9 @@ int kvm_xen_hvm_config(struct kvm *kvm, struct kvm_xen_hvm_config *xhc)
|
||||
{
|
||||
/* Only some feature flags need to be *enabled* by userspace */
|
||||
u32 permitted_flags = KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL |
|
||||
KVM_XEN_HVM_CONFIG_EVTCHN_SEND;
|
||||
KVM_XEN_HVM_CONFIG_EVTCHN_SEND |
|
||||
KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE;
|
||||
u32 old_flags;
|
||||
|
||||
if (xhc->flags & ~permitted_flags)
|
||||
return -EINVAL;
|
||||
@ -1183,9 +1185,14 @@ int kvm_xen_hvm_config(struct kvm *kvm, struct kvm_xen_hvm_config *xhc)
|
||||
else if (!xhc->msr && kvm->arch.xen_hvm_config.msr)
|
||||
static_branch_slow_dec_deferred(&kvm_xen_enabled);
|
||||
|
||||
old_flags = kvm->arch.xen_hvm_config.flags;
|
||||
memcpy(&kvm->arch.xen_hvm_config, xhc, sizeof(*xhc));
|
||||
|
||||
mutex_unlock(&kvm->arch.xen.xen_lock);
|
||||
|
||||
if ((old_flags ^ xhc->flags) & KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE)
|
||||
kvm_make_all_cpus_request(kvm, KVM_REQ_CLOCK_UPDATE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1245,6 +1245,7 @@ struct kvm_x86_mce {
|
||||
#define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)
|
||||
#define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5)
|
||||
#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)
|
||||
#define KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE (1 << 7)
|
||||
|
||||
struct kvm_xen_hvm_config {
|
||||
__u32 flags;
|
||||
|
Loading…
Reference in New Issue
Block a user