xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: xen-devel@lists.xensource.com,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH 1/2] xen/swiotlb: If iommu=soft was not passed in on > 4GB, don't turn it on.
Date: Thu, 26 Jul 2012 16:43:26 -0400	[thread overview]
Message-ID: <1343335407-5465-2-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1343335407-5465-1-git-send-email-konrad.wilk@oracle.com>

If we boot a 64-bit guest with more than 4GB memory, the SWIOTLB
gets turned on:
PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
software IO TLB [mem 0xfb43d000-0xff43cfff] (64MB) mapped at [ffff8800fb43d000-ffff8800ff43cfff]

which is OK if we had PCI devices, but not if we did not. In a PV
guest the SWIOTLB ends up asking the hypervisor for precious lowmem
memory - and 64MB of it per guest. On a 32GB machine, this limits the
amount of guests that are 4GB to start due to lowmem exhaustion.

What we do is detect whether the user supplied e820_hole=1
parameter, which is used to construct an E820 that is similar to
the machine  - so that the PCI regions do not overlap with RAM regions.
We check for that by looking at the E820 and seeing if it diverges
from the standard - and if so (and if iommu=soft was not turned on),
we disable the check pci_swiotlb_detect_4gb code.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 arch/x86/xen/pci-swiotlb-xen.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
index 967633a..56f373e 100644
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ b/arch/x86/xen/pci-swiotlb-xen.c
@@ -8,6 +8,10 @@
 #include <xen/xen.h>
 #include <asm/iommu_table.h>
 
+#include <asm/e820.h>
+#include <asm/dma.h>
+#include <asm/iommu.h>
+
 int xen_swiotlb __read_mostly;
 
 static struct dma_map_ops xen_swiotlb_dma_ops = {
@@ -24,7 +28,19 @@ static struct dma_map_ops xen_swiotlb_dma_ops = {
 	.unmap_page = xen_swiotlb_unmap_page,
 	.dma_supported = xen_swiotlb_dma_supported,
 };
+bool __init e820_has_acpi(void)
+{
+	int i;
 
+	/* Check if the user supplied the e820_hole parameter
+	 * which would create a machine looking E820 region. */
+	for (i = 0; i < e820.nr_map; i++) {
+		if ((e820.map[i].type == E820_ACPI) ||
+		    (e820.map[i].type == E820_NVS))
+			return true;
+	}
+	return false;
+}
 /*
  * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
  *
@@ -33,7 +49,17 @@ static struct dma_map_ops xen_swiotlb_dma_ops = {
  */
 int __init pci_xen_swiotlb_detect(void)
 {
+#ifdef CONFIG_X86_64
 
+	/* Having more than 4GB triggers the native SWIOTLB to activate.
+	 * The way to turn it off is to set no_iommu. */
+	printk(KERN_INFO "swiotlb: %d\n", swiotlb);
+	if (xen_pv_domain() && !swiotlb && max_pfn > MAX_DMA32_PFN) {
+		/* Normal PV guests only have E820_RSV and E820_RAM regions */
+		if (!e820_has_acpi())
+			no_iommu = 1;
+	}
+#endif
 	/* If running as PV guest, either iommu=soft, or swiotlb=force will
 	 * activate this IOMMU. If running as PV privileged, activate it
 	 * irregardless.
-- 
1.7.7.6

  reply	other threads:[~2012-07-26 20:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 20:43 [RFC PATCH] Xen-SWIOTLB fixes (v1) for 3.7 Konrad Rzeszutek Wilk
2012-07-26 20:43 ` Konrad Rzeszutek Wilk [this message]
2012-07-27  7:27   ` [PATCH 1/2] xen/swiotlb: If iommu=soft was not passed in on > 4GB, don't turn it on Jan Beulich
2012-07-27 11:06   ` Stefano Stabellini
2012-07-27 17:55     ` [Xen-devel] " Konrad Rzeszutek Wilk
2012-07-30 14:58       ` Stefano Stabellini
2012-07-30 15:10         ` Konrad Rzeszutek Wilk
     [not found]   ` <50125F0B0200007800090DFB@nat28.tlf.novell.com>
2012-07-27 17:54     ` Konrad Rzeszutek Wilk
     [not found]     ` <20120727175408.GG17427@andromeda.dapyr.net>
2012-07-30  7:06       ` Jan Beulich
2012-07-26 20:43 ` [PATCH 2/2] xen/swiotlb: If user supplied e820_hole=1 in the guest config, enable SWIOTLB Konrad Rzeszutek Wilk

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=1343335407-5465-2-git-send-email-konrad.wilk@oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xensource.com \
    /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).