]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
KVM: xen: (re-)initialize shared_info if guest (32/64-bit) mode is set shared-info10
authorPaul Durrant <pdurrant@amazon.com>
Wed, 8 Nov 2023 10:06:33 +0000 (10:06 +0000)
committerPaul Durrant <pdurrant@amazon.com>
Fri, 1 Dec 2023 09:03:36 +0000 (09:03 +0000)
If the shared_info PFN cache has already been initialized then the content
of the shared_info page needs to be (re-)initialized if the guest mode is
set. It is no lnger done when the PFN cache is activated.
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>
arch/x86/kvm/xen.c

index 7bead3f65e55db8a11f13632f1b6c346ad5673f2..bfc8f6698cbc0d3215bb40408a4af8931217b916 100644 (file)
@@ -624,8 +624,15 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
                } else {
                        mutex_lock(&kvm->arch.xen.xen_lock);
                        kvm->arch.xen.long_mode = !!data->u.long_mode;
+
+                       /*
+                        * If shared_info has already been initialized
+                        * then re-initialize it with the new width.
+                        */
+                       r = kvm->arch.xen.shinfo_cache.active ?
+                               kvm_xen_shared_info_init(kvm) : 0;
+
                        mutex_unlock(&kvm->arch.xen.xen_lock);
-                       r = 0;
                }
                break;
 
@@ -657,9 +664,6 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
                }
                srcu_read_unlock(&kvm->srcu, idx);
 
-               if (!r && kvm->arch.xen.shinfo_cache.active)
-                       r = kvm_xen_shared_info_init(kvm);
-
                mutex_unlock(&kvm->arch.xen.xen_lock);
                break;
        }
@@ -1144,7 +1148,13 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
        bool lm = is_long_mode(vcpu);
 
        /* Latch long_mode for shared_info pages etc. */
-       vcpu->kvm->arch.xen.long_mode = lm;
+       kvm->arch.xen.long_mode = lm;
+
+       if (kvm->arch.xen.shinfo_cache.active &&
+           kvm_xen_shared_info_init(kvm)) {
+               mutex_unlock(&kvm->arch.xen.xen_lock);
+               return 1;
+       }
 
        /*
         * If Xen hypercall intercept is enabled, fill the hypercall