From: Paul Durrant Date: Wed, 8 Nov 2023 10:06:33 +0000 (+0000) Subject: KVM: xen: (re-)initialize shared_info if guest (32/64-bit) mode is set X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f1a72f58ae411709a32aa033ce1a3e4f9be7b91d;p=people%2Fpauldu%2Flinux.git KVM: 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 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 --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: David Woodhouse Cc: x86@kernel.org v10: - New in this version. --- diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 9351b32cfcba..6a56be78649c 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -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