]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
KVM: xen: (re-)initialize shared_info if guest (32/64-bit) mode is set
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 18:30:46 +0000 (18:30 +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
(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>
---
Cc: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: x86@kernel.org
v10:
 - New in this version.

arch/x86/kvm/xen.c

index 9351b32cfcbaba338e438473916f217d86e125b2..6a56be78649ce1fe3bbe024fabf2b8a13ab8722c 100644 (file)
@@ -625,8 +625,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;
 
@@ -648,9 +655,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;
        }
@@ -1103,7 +1107,11 @@ 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))
+               return 1;
 
        /*
         * If Xen hypercall intercept is enabled, fill the hypercall