xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Paul Durrant <paul.durrant@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Paul Durrant <paul.durrant@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH 1/2] x86/mm/p2m: don't needlessly limit MMIO mapping order to 4k
Date: Mon, 29 Oct 2018 18:02:03 +0000	[thread overview]
Message-ID: <20181029180211.2155-3-paul.durrant@citrix.com> (raw)
In-Reply-To: <20181029180211.2155-1-paul.durrant@citrix.com>

The P2M common code currently restricts the MMIO mapping order of any
domain with IOMMU mappings, but that is not using shared tables, to 4k.
This has been shown to have a huge performance cost when passing through
a PCI device with a very large BAR (e.g. NVIDIA P40), increasing the guest
boot time from ~20s to several minutes when iommu=no-sharept is specified
on the Xen command line.

The limitation was added by commit c3c756bd "x86/p2m: use large pages
for MMIO mappings" however the underlying implementations of p2m->set_entry
for Intel and AMD are coded to cope with mapping orders higher than 4k,
even though the IOMMU mapping function is itself currently limited to 4k,
so there is no real need to limit the order passed into the method, other
than to avoid a potential DoS caused by a long running hypercall.

In practice, mmio_order() already strictly disallows 1G mappings since the
if clause in question starts with:

    if ( 0 /*
            * Don't use 1Gb pages, to limit the iteration count in
            * set_typed_p2m_entry() when it needs to zap M2P entries
            * for a RAM range.
            */ &&

With this patch applied (and hence 2M mappings in use) the VM boot time is
restored to something reasonable. Not as fast as without iommu=no-sharept,
but within a few seconds of it.

NOTE: This patch takes the opportunity to shorten a couple of > 80
      character lines in the code.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>

v2:
 - Add an extra to the if clause disallowing 1G mappings to make sure
   they are not used if need_iommu_pt_sync() is true, even though the
   check is currently moot (see main comment).
---
 xen/arch/x86/mm/p2m.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index a00a3c1bff..f972b4819d 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -2081,14 +2081,11 @@ static unsigned int mmio_order(const struct domain *d,
                                unsigned long start_fn, unsigned long nr)
 {
     /*
-     * Note that the !iommu_use_hap_pt() here has three effects:
-     * - cover iommu_{,un}map_page() not having an "order" input yet,
-     * - exclude shadow mode (which doesn't support large MMIO mappings),
-     * - exclude PV guests, should execution reach this code for such.
-     * So be careful when altering this.
+     * PV guests or shadow-mode HVM guests must be restricted to 4k
+     * mappings.
      */
-    if ( !iommu_use_hap_pt(d) ||
-         (start_fn & ((1UL << PAGE_ORDER_2M) - 1)) || !(nr >> PAGE_ORDER_2M) )
+    if ( !hap_enabled(d) || (start_fn & ((1UL << PAGE_ORDER_2M) - 1)) ||
+         !(nr >> PAGE_ORDER_2M) )
         return PAGE_ORDER_4K;
 
     if ( 0 /*
@@ -2096,8 +2093,12 @@ static unsigned int mmio_order(const struct domain *d,
             * set_typed_p2m_entry() when it needs to zap M2P entries
             * for a RAM range.
             */ &&
-         !(start_fn & ((1UL << PAGE_ORDER_1G) - 1)) && (nr >> PAGE_ORDER_1G) &&
-         hap_has_1gb )
+         !(start_fn & ((1UL << PAGE_ORDER_1G) - 1)) &&
+         (nr >> PAGE_ORDER_1G) &&
+         hap_has_1gb &&
+         /* disable 1G mappings if we need to keep the IOMMU in sync */
+         !need_iommu_pt_sync(d)
+        )
         return PAGE_ORDER_1G;
 
     if ( hap_has_2mb )
-- 
2.11.0


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

  parent reply	other threads:[~2018-10-29 18:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29 18:02 [PATCH 0/8] viridian cleanup Paul Durrant
2018-10-29 18:02 ` [PATCH 1/8] viridian: move the code into its own sub-directory Paul Durrant
2018-10-30  9:25   ` Jan Beulich
2018-10-31 10:17   ` Jan Beulich
2018-10-31 10:30     ` Paul Durrant
2018-10-29 18:02 ` Paul Durrant [this message]
2018-10-29 18:03   ` [PATCH 1/2] x86/mm/p2m: don't needlessly limit MMIO mapping order to 4k Paul Durrant
2018-10-29 18:02 ` [PATCH 2/2] iommu / p2m: add a page_order parameter to iommu_map/unmap_page() Paul Durrant
2018-10-29 18:03   ` Paul Durrant
2018-10-29 18:02 ` [PATCH 2/8] viridian: remove MSR perf counters Paul Durrant
2018-10-30 16:25   ` Roger Pau Monné
2018-10-29 18:02 ` [PATCH 3/8] viridian: remove comments referencing section number in the spec Paul Durrant
2018-10-30 16:34   ` Roger Pau Monné
2018-10-30 17:07     ` Paul Durrant
2018-10-29 18:02 ` [PATCH 4/8] viridian: remove duplicate union types Paul Durrant
2018-10-30 16:40   ` Roger Pau Monné
2018-10-30 17:03     ` Paul Durrant
2018-10-31  8:44       ` Roger Pau Monné
2018-10-29 18:02 ` [PATCH 5/8] viridian: separate interrupt related enlightenment implementations Paul Durrant
2018-10-30 16:52   ` Roger Pau Monné
2018-10-30 17:06     ` Paul Durrant
2018-10-29 18:02 ` [PATCH 6/8] viridian: separate time " Paul Durrant
2018-10-30 17:03   ` Roger Pau Monné
2018-10-30 17:08     ` Paul Durrant
2018-10-29 18:02 ` [PATCH 7/8] viridian: define type for the 'virtual VP assist page' Paul Durrant
2018-10-30 17:08   ` Roger Pau Monné
2018-10-30 17:11     ` Paul Durrant
2018-10-31  8:53       ` Roger Pau Monné
2018-10-31  9:27         ` Paul Durrant
2018-10-31  9:41           ` Jan Beulich
2018-10-31 10:01             ` Paul Durrant
2018-10-31 10:16               ` Jan Beulich
2018-10-29 18:02 ` [PATCH 8/8] viridian: introduce struct viridian_page Paul Durrant
2018-10-30 17:17   ` Roger Pau Monné
2018-10-30 17:25     ` Paul Durrant

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=20181029180211.2155-3-paul.durrant@citrix.com \
    --to=paul.durrant@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).