From: Konrad Rzeszutek Wilk <konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: Jan Beulich <JBeulich-IBi9RG/b67k@public.gmane.org>
Cc: Lukas Hejtmanek
<xhejtman-8qz54MUs51PtwjQa/ONI9g@public.gmane.org>,
roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
xen-devel-GuqFBffKawuEi8DpZVb4nw@public.gmane.org,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [Xen-devel] BUG: bad page map under Xen
Date: Wed, 23 Oct 2013 11:36:45 -0400 [thread overview]
Message-ID: <20131023153645.GA28011@phenom.dumpdata.com> (raw)
In-Reply-To: <5265609802000078000FC7B7-ce6RLXgGx+vWGUEhTRrCg1aTQe2KTcn/@public.gmane.org>
On Mon, Oct 21, 2013 at 04:12:56PM +0100, Jan Beulich wrote:
> >>> On 21.10.13 at 16:44, Konrad Rzeszutek Wilk <konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> wrote:
> > On Mon, Oct 21, 2013 at 03:27:50PM +0100, Jan Beulich wrote:
> >> >>> On 21.10.13 at 16:18, Konrad Rzeszutek Wilk <konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> wrote:
> >> > On Mon, Oct 21, 2013 at 04:06:07PM +0200, Lukas Hejtmanek wrote:
> >> >> Region 2: Memory at 380fff000000 (64-bit, prefetchable) [size=8M]
> >> >...
> >> > --- a/arch/x86/xen/setup.c
> >> > +++ b/arch/x86/xen/setup.c
> >> > @@ -92,6 +92,9 @@ static void __init xen_add_extra_mem(u64 start, u64 size)
> >> >
> >> > __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
> >> > }
> >> > + /* Anything past the balloon area is marked as identity. */
> >> > + for (pfn = xen_max_p2m_pfn; pfn < MAX_DOMAIN_PAGES; pfn++)
> >> > + __set_phys_to_machine(pfn, IDENTITY_FRAME(pfn));
> >>
> >> Hardly - MAX_DOMAIN_PAGES derives from
> >> CONFIG_XEN_MAX_DOMAIN_MEMORY, which in turn is unrelated
> >> to where MMIO might be. Should you perhaps simply start from
> >
> > Looks like your mailer ate some words.
>
> I don't think so - they're all there in the text you quoted.
>
> >> an all 1:1 mapping, inserting the RAM translations as you find
> >> them?
> >
> >
> > Yeah, as this code can be called for the regions under 4GB. Definitly
> > needs more analysis.
> >
> > Were you suggesting a lookup when we scan the PCI devices? (xen_add_device)?
>
> That was for PVH, and is obviously fragile, as there can be MMIO
> regions not matched by any PCI device's BAR. We could hope for
> all of them to be below 4Gb, but I think (based on logs I got to see
> recently from a certain vendor's upcoming systems) this isn't going
> to work out.
This is the patch I had in mind that I think will fix these issues. But
I would appreciate testing it and naturally send me the dmesg if possible.
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index b232908..258e3f9 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -133,6 +133,25 @@ static void balloon_append(struct page *page)
adjust_managed_page_count(page, -1);
}
+/*
+ * Check if any the balloon pages overlap with the supplied
+ * pfn and its range.
+ */
+bool balloon_pfn(unsigned long pfn, unsigned long nr)
+{
+ struct page *page;
+
+ if (list_empty(&ballooned_pages))
+ return false;
+
+ list_for_each_entry(page, &ballooned_pages, lru) {
+ unsigned long b_pfn = page_to_pfn(page);
+
+ if (b_pfn >= pfn && b_pfn < pfn + nr)
+ return true;
+ }
+ return false;
+}
/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
static struct page *balloon_retrieve(bool prefer_highmem)
{
diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c
index 18fff88..7e5ff49 100644
--- a/drivers/xen/pci.c
+++ b/drivers/xen/pci.c
@@ -17,11 +17,16 @@
* Author: Weidong Han <weidong.han-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
*/
+#define DEBUG 1
+
#include <linux/pci.h>
#include <linux/acpi.h>
#include <xen/xen.h>
#include <xen/interface/physdev.h>
#include <xen/interface/xen.h>
+#include <xen/interface/memory.h>
+#include <xen/page.h>
+#include <xen/balloon.h>
#include <asm/xen/hypervisor.h>
#include <asm/xen/hypercall.h>
@@ -123,10 +128,78 @@ static int xen_add_device(struct device *dev)
r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add,
&manage_pci);
}
-
return r;
}
+static void xen_p2m_add_device(struct device *dev)
+{
+ int i;
+ struct pci_dev *pci_dev = to_pci_dev(dev);
+
+ /* Verify whether the MMIO BARs are 1-1 in the P2M. */
+ for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+ unsigned long pfn, start, end, ok_pfns;
+ char bus_addr[64];
+ char *fmt;
+
+ if (!pci_resource_len(pci_dev, i))
+ continue;
+
+ if (pci_resource_flags(pci_dev, i) == IORESOURCE_IO)
+ fmt = " (bus address [%#06llx-%#06llx])";
+ else
+ fmt = " (bus address [%#010llx-%#010llx])";
+
+ snprintf(bus_addr, sizeof(bus_addr), fmt,
+ (unsigned long long) (pci_resource_start(pci_dev, i)),
+ (unsigned long long) (pci_resource_end(pci_dev, i)));
+
+ start = pci_resource_start(pci_dev, i) >> PAGE_SHIFT;
+ end = pci_resource_end(pci_dev, i) >> PAGE_SHIFT;
+
+ /*
+ * We don't worry about the balloon scratch page as it has a
+ * valid PFN - which means we will catch in the loop below.
+ */
+ if (balloon_pfn(start, end - start)) {
+ dev_warn(dev, "%s is within balloon pages!\n", bus_addr);
+ continue;
+ }
+
+ for (ok_pfns = 0, pfn = start; pfn < end; pfn ++) {
+ unsigned long mfn = pfn_to_mfn(pfn);
+
+ if (mfn == pfn) {
+ ok_pfns ++;
+ continue;
+ }
+ if (mfn != INVALID_P2M_ENTRY) { /* RAM */
+ dev_warn(dev, "%s is within RAM [%lx] region!\n", bus_addr, pfn);
+ break;
+ }
+ }
+ dev_dbg(dev, "%s pfn:%lx, s:%lx, e:%lx ok:%ld\n", bus_addr, pfn, start, end, ok_pfns);
+ if (pfn != end - 1) /* We broke out of the loop above. */
+ continue;
+
+ if (ok_pfns == end - start) /* All good. */
+ continue;
+
+ dev_dbg(dev, "%s [%lx->%lx]\n", bus_addr, start, end);
+
+ /* This BAR was not detected during E820 parsing. */
+ for (pfn = start; pfn < end; pfn ++) {
+ if (!set_phys_to_machine(pfn, pfn))
+ break;
+ }
+ WARN(pfn != end - 1, "Only set %ld instead of %ld PFNs!\n",
+ end - pfn, end - start);
+
+ dev_info(dev, "%s set %ld page(s) to 1-1 mapping.\n",
+ bus_addr, end - pfn);
+ }
+}
+
static int xen_remove_device(struct device *dev)
{
int r;
@@ -164,10 +237,14 @@ static int xen_pci_notifier(struct notifier_block *nb,
switch (action) {
case BUS_NOTIFY_ADD_DEVICE:
- r = xen_add_device(dev);
+ if (xen_initial_domain())
+ r = xen_add_device(dev);
+ if (r == 0)
+ xen_p2m_add_device(dev);
break;
case BUS_NOTIFY_DEL_DEVICE:
- r = xen_remove_device(dev);
+ if (xen_initial_domain())
+ r = xen_remove_device(dev);
break;
default:
return NOTIFY_DONE;
@@ -185,9 +262,8 @@ static struct notifier_block device_nb = {
static int __init register_xen_pci_notifier(void)
{
- if (!xen_initial_domain())
+ if (!xen_domain())
return 0;
-
return bus_register_notifier(&pci_bus_type, &device_nb);
}
diff --git a/include/xen/balloon.h b/include/xen/balloon.h
index a4c1c6a..60ecc50 100644
--- a/include/xen/balloon.h
+++ b/include/xen/balloon.h
@@ -41,3 +41,4 @@ static inline int register_xen_selfballooning(struct device *dev)
return -ENOSYS;
}
#endif
+bool balloon_pfn(unsigned long pfn, unsigned long nr);
>
> Jan
>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2013-10-23 15:36 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-21 11:57 BUG: bad page map under Xen Lukas Hejtmanek
2013-10-21 12:59 ` konrad wilk
[not found] ` <20131021115740.GN20913-8qz54MUs51PtwjQa/ONI9g@public.gmane.org>
2013-10-21 12:59 ` [Xen-devel] " konrad wilk
[not found] ` <52652534.2040303-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-10-21 13:18 ` Jan Beulich
[not found] ` <526545E002000078000FC5F1-ce6RLXgGx+vWGUEhTRrCg1aTQe2KTcn/@public.gmane.org>
2013-10-21 13:39 ` konrad wilk
2013-10-21 13:57 ` konrad wilk
[not found] ` <52652E95.3020305-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-10-21 13:57 ` [Xen-devel] " konrad wilk
2013-10-21 14:06 ` Lukas Hejtmanek
2013-10-21 14:18 ` Konrad Rzeszutek Wilk
2013-10-21 14:23 ` Lukas Hejtmanek
2013-10-21 14:27 ` Jan Beulich
[not found] ` <20131021141855.GA4211-6K5HmflnPlqSPmnEAIUT9EEOCMrvLtNR@public.gmane.org>
2013-10-21 14:23 ` [Xen-devel] " Lukas Hejtmanek
2013-10-21 14:27 ` Jan Beulich
[not found] ` <5265560602000078000FC73E-ce6RLXgGx+vWGUEhTRrCg1aTQe2KTcn/@public.gmane.org>
2013-10-21 14:44 ` Konrad Rzeszutek Wilk
[not found] ` <20131021144407.GC4560-6K5HmflnPlqSPmnEAIUT9EEOCMrvLtNR@public.gmane.org>
2013-10-21 15:12 ` Jan Beulich
2013-10-23 15:36 ` Konrad Rzeszutek Wilk
[not found] ` <5265609802000078000FC7B7-ce6RLXgGx+vWGUEhTRrCg1aTQe2KTcn/@public.gmane.org>
2013-10-23 15:36 ` Konrad Rzeszutek Wilk [this message]
[not found] ` <20131023153645.GA28011-6K5HmflnPlqSPmnEAIUT9EEOCMrvLtNR@public.gmane.org>
2013-10-23 15:45 ` [Xen-devel] " Jan Beulich
[not found] ` <5267FD3102000078000A56A1-ce6RLXgGx+vWGUEhTRrCg1aTQe2KTcn/@public.gmane.org>
2013-10-23 16:04 ` Konrad Rzeszutek Wilk
[not found] ` <20131023160433.GA28260-6K5HmflnPlqSPmnEAIUT9EEOCMrvLtNR@public.gmane.org>
2013-10-23 16:35 ` Jan Beulich
2013-10-23 16:35 ` Jan Beulich
2013-10-23 16:04 ` Konrad Rzeszutek Wilk
2013-10-24 23:08 ` [Xen-devel] " David Vrabel
[not found] ` <5269A865.2010100-5LkwijKnu/2sTnJN9+BGXg@public.gmane.org>
2013-10-25 14:21 ` Konrad Rzeszutek Wilk
2013-12-26 6:39 ` Zhang, Yang Z
[not found] ` <20131025142147.GB3742-6K5HmflnPlqSPmnEAIUT9EEOCMrvLtNR@public.gmane.org>
2013-12-26 6:39 ` [Xen-devel] " Zhang, Yang Z
[not found] ` <A9667DDFB95DB7438FA9D7D576C3D87E0A99CE00-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-01-02 14:18 ` David Vrabel
2014-01-02 14:18 ` David Vrabel
2013-10-25 14:21 ` Konrad Rzeszutek Wilk
2013-10-23 15:45 ` Jan Beulich
2013-10-24 23:08 ` David Vrabel
2013-10-21 15:12 ` Jan Beulich
2013-10-21 14:44 ` Konrad Rzeszutek Wilk
2013-10-21 14:20 ` Jan Beulich
[not found] ` <20131021140607.GQ20913-8qz54MUs51PtwjQa/ONI9g@public.gmane.org>
2013-10-21 14:20 ` [Xen-devel] " Jan Beulich
2013-10-21 14:06 ` Lukas Hejtmanek
2013-10-21 13:39 ` konrad wilk
2013-10-21 13:18 ` Jan Beulich
2013-10-21 13:14 ` [Xen-devel] " Jan Beulich
2013-10-21 13:14 ` 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=20131023153645.GA28011@phenom.dumpdata.com \
--to=konrad.wilk-qhclzuegtsvqt0dzr+alfa@public.gmane.org \
--cc=JBeulich-IBi9RG/b67k@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=xen-devel-GuqFBffKawuEi8DpZVb4nw@public.gmane.org \
--cc=xhejtman-8qz54MUs51PtwjQa/ONI9g@public.gmane.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.