[xen stable-4.9] x86/svm: Fix a livelock when trying to run shadowed unpaged guests

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen stable-4.9] x86/svm: Fix a livelock when trying to run shadowed unpaged guests

patchbot
commit 53d01aaa640822e9d8014f5c5151eb15812a9462
Author:     Andrew Cooper <[hidden email]>
AuthorDate: Tue Oct 24 16:09:11 2017 +0200
Commit:     Jan Beulich <[hidden email]>
CommitDate: Tue Oct 24 16:09:11 2017 +0200

    x86/svm: Fix a livelock when trying to run shadowed unpaged guests
   
    On AMD processors which support SMEP (Some Fam16h processors) and SMAP (Zen,
    Fam17h), a guest which is running with shadow paging and clears CR0.PG while
    keeping CR4.{SMEP,SMAP} set will livelock, as hardware raises #PF which the
    shadow pagetable concludes shouldn't happen.
   
    This occurs because hardware is running with host paging settings, which
    causes the guests choice of SMEP/SMAP to actually take effect, even though
    they shouldn't from the guests point of view.
   
    Signed-off-by: Andrew Cooper <[hidden email]>
    Reviewed-by: Boris Ostrovsky <[hidden email]>
    master commit: 3164f2f9db1e63ea64c3f9520d40cb09920d2b35
    master date: 2017-10-02 13:57:34 +0100
---
 xen/arch/x86/hvm/svm/svm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 178adc5..6d1e6bf 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -574,6 +574,24 @@ void svm_update_guest_cr(struct vcpu *v, unsigned int cr)
         if ( paging_mode_hap(v->domain) )
             value &= ~X86_CR4_PAE;
         value |= v->arch.hvm_vcpu.guest_cr[4];
+
+        if ( !hvm_paging_enabled(v) )
+        {
+            /*
+             * When the guest thinks paging is disabled, Xen may need to hide
+             * the effects of shadow paging, as hardware runs with the host
+             * paging settings, rather than the guests settings.
+             *
+             * Without CR0.PG, all memory accesses are user mode, so
+             * _PAGE_USER must be set in the shadow pagetables for guest
+             * userspace to function.  This in turn trips up guest supervisor
+             * mode if SMEP/SMAP are left active in context.  They wouldn't
+             * have any effect if paging was actually disabled, so hide them
+             * behind the back of the guest.
+             */
+            value &= ~(X86_CR4_SMEP | X86_CR4_SMAP);
+        }
+
         vmcb_set_cr4(vmcb, value);
         break;
     default:
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.9

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog