Skip to content

Commit 18b99e4

Browse files
Paul Durrantsean-jc
authored andcommitted
KVM: x86/xen: re-initialize shared_info if guest (32/64-bit) mode is set
If the shared_info PFN cache has already been initialized then the content of the shared_info page needs to be re-initialized whenever the guest mode is (re)set. Setting the guest mode is either done explicitly by the VMM via the KVM_XEN_ATTR_TYPE_LONG_MODE attribute, or implicitly when the guest writes the MSR to set up the hypercall page. Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://lore.kernel.org/r/20240215152916.1158-12-paul@xen.org Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c01c55a commit 18b99e4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

arch/x86/kvm/xen.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,16 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
625625
} else {
626626
mutex_lock(&kvm->arch.xen.xen_lock);
627627
kvm->arch.xen.long_mode = !!data->u.long_mode;
628+
629+
/*
630+
* Re-initialize shared_info to put the wallclock in the
631+
* correct place. Whilst it's not necessary to do this
632+
* unless the mode is actually changed, it does no harm
633+
* to make the call anyway.
634+
*/
635+
r = kvm->arch.xen.shinfo_cache.active ?
636+
kvm_xen_shared_info_init(kvm) : 0;
628637
mutex_unlock(&kvm->arch.xen.xen_lock);
629-
r = 0;
630638
}
631639
break;
632640

@@ -1101,9 +1109,24 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
11011109
u32 page_num = data & ~PAGE_MASK;
11021110
u64 page_addr = data & PAGE_MASK;
11031111
bool lm = is_long_mode(vcpu);
1112+
int r = 0;
1113+
1114+
mutex_lock(&kvm->arch.xen.xen_lock);
1115+
if (kvm->arch.xen.long_mode != lm) {
1116+
kvm->arch.xen.long_mode = lm;
1117+
1118+
/*
1119+
* Re-initialize shared_info to put the wallclock in the
1120+
* correct place.
1121+
*/
1122+
if (kvm->arch.xen.shinfo_cache.active &&
1123+
kvm_xen_shared_info_init(kvm))
1124+
r = 1;
1125+
}
1126+
mutex_unlock(&kvm->arch.xen.xen_lock);
11041127

1105-
/* Latch long_mode for shared_info pages etc. */
1106-
vcpu->kvm->arch.xen.long_mode = lm;
1128+
if (r)
1129+
return r;
11071130

11081131
/*
11091132
* If Xen hypercall intercept is enabled, fill the hypercall

0 commit comments

Comments
 (0)