All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Juergen Gross <jgross@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 1/3] x86/mm: fix #GP(0) in switch_cr3_cr4()
Date: Tue, 05 Mar 2019 06:25:04 -0700	[thread overview]
Message-ID: <5C7E78B0020000780021BB1E@prv1-mh.provo.novell.com> (raw)
In-Reply-To: <5C7E77D1020000780021BB0B@prv1-mh.provo.novell.com>

With "pcid=no-xpti" and opposite XPTI settings in two 64-bit PV domains
(achievable with one of "xpti=no-dom0" or "xpti=no-domu"), switching
from a PCID-disabled to a PCID-enabled 64-bit PV domain fails to set
CR4.PCIDE in time, as CR4.PGE would not be set in either (see
pv_guest_cr4_to_real_cr4(), in particular as used by write_ptbase()),
and hence the early CR4 write would be skipped.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/flushtlb.c
+++ b/xen/arch/x86/flushtlb.c
@@ -122,6 +122,7 @@ void switch_cr3_cr4(unsigned long cr3, u
         write_cr4(old_cr4);
     }
     else if ( use_invpcid )
+    {
         /*
          * Flushing the TLB via INVPCID is necessary only in case PCIDs are
          * in use, which is true only with INVPCID being available.
@@ -132,6 +133,19 @@ void switch_cr3_cr4(unsigned long cr3, u
          */
         invpcid_flush_all_nonglobals();
 
+        /*
+         * CR4.PCIDE needs to be set before the CR3 write below. Otherwise
+         * - the CR3 write will fault when CR3.NOFLUSH is set (which is the
+         *   case normally),
+         * - the subsequent CR4 write will fault if CR3.PCID != 0.
+         */
+        if ( (old_cr4 & X86_CR4_PCIDE) < (cr4 & X86_CR4_PCIDE) )
+        {
+            write_cr4(cr4);
+            old_cr4 = cr4;
+        }
+    }
+
     /*
      * If we don't change PCIDs, the CR3 write below needs to flush this very
      * PCID, even when a full flush was performed above, as we are currently





_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-03-05 13:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05 13:21 [PATCH 0/3] today's XSAs assorted 4.12 candidate follow-up Jan Beulich
2019-03-05 13:25 ` Jan Beulich [this message]
2019-03-05 13:58   ` [PATCH 1/3] x86/mm: fix #GP(0) in switch_cr3_cr4() Andrew Cooper
2019-03-05 13:26 ` [PATCH 2/3] IOMMU/x86: make page type checks consistent when mapping pages Jan Beulich
2019-05-13 13:44   ` George Dunlap
2019-05-13 13:44     ` [Xen-devel] " George Dunlap
2019-05-13 13:59     ` Jan Beulich
2019-05-13 13:59       ` [Xen-devel] " Jan Beulich
2019-05-14 11:17     ` Jan Beulich
2019-05-14 11:17       ` [Xen-devel] " Jan Beulich
     [not found] ` <5C7E78B0020000780021BB1E@suse.com>
2019-03-05 13:28   ` [PATCH 1/3] x86/mm: fix #GP(0) in switch_cr3_cr4() Juergen Gross
2019-03-05 13:28 ` [PATCH 3/3] memory: restrict XENMEM_remove_from_physmap to translated guests Jan Beulich
2019-04-02 10:26   ` Julien Grall
2019-04-02 16:10     ` Jan Beulich
2019-04-08 11:47       ` Julien Grall
2019-04-08 11:47         ` [Xen-devel] " Julien Grall
2019-04-08 14:29         ` Jan Beulich
2019-04-08 14:29           ` [Xen-devel] " Jan Beulich
2019-04-09  9:50           ` Julien Grall
2019-04-09  9:50             ` [Xen-devel] " Julien Grall
2019-04-09 12:21             ` Jan Beulich
2019-04-09 12:21               ` [Xen-devel] " Jan Beulich
2019-04-14 16:33               ` Julien Grall
2019-04-14 16:33                 ` [Xen-devel] " Julien Grall
2019-04-25 10:36                 ` Jan Beulich
2019-04-25 10:36                   ` [Xen-devel] " Jan Beulich
2019-04-08 11:58   ` Julien Grall
2019-04-08 11:58     ` [Xen-devel] " Julien Grall
2019-04-08 14:02     ` Jan Beulich
2019-04-08 14:02       ` [Xen-devel] " Jan Beulich
2019-04-08 16:10       ` Julien Grall
2019-04-08 16:10         ` [Xen-devel] " Julien Grall
2019-05-13  8:06   ` Ping: " Jan Beulich
2019-05-13  8:06     ` [Xen-devel] " Jan Beulich
2019-05-13 14:35   ` George Dunlap
2019-05-13 14:35     ` [Xen-devel] " George Dunlap
2019-05-13 15:13     ` Jan Beulich
2019-05-13 15:13       ` [Xen-devel] " Jan Beulich
     [not found] ` <5C7E78F6020000780021BB21@suse.com>
2019-03-05 13:50   ` [PATCH 2/3] IOMMU/x86: make page type checks consistent when mapping pages Juergen Gross
2019-03-05 15:21     ` Jan Beulich
     [not found] ` <5C7E798E020000780021BB43@suse.com>
2019-03-05 13:53   ` [PATCH 3/3] memory: restrict XENMEM_remove_from_physmap to translated guests Juergen Gross
2019-03-05 15:22     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5C7E78B0020000780021BB1E@prv1-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jgross@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.