Re: [PATCH] xen/p2m: fix extra memory regions accounting

From: Juergen Gross
Date: Thu Sep 03 2015 - 10:51:02 EST

On 09/03/2015 04:38 PM, Roger Pau Monnà wrote:
El 03/09/15 a les 14.25, Juergen Gross ha escrit:
On 09/03/2015 02:05 PM, Roger Pau Monne wrote:
On systems with memory maps with ranges that don't end at page

(XEN) 0000000000100000 - 00000000dfdf9c00 (usable)
(XEN) 00000000dfdf9c00 - 00000000dfe4bc00 (ACPI NVS)

xen_add_extra_mem will create a protected range that ends up at
but the function used to check if a memory address is inside of a
range works with pfns, which means that an attempt to map 0xdfdf9c00
will be
refused because the check is performed against 0xdfdf9000 instead of

In order to fix this, make sure that the ranges that are added to the
xen_extra_mem array are aligned to page boundaries.

Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
Cc: David Vrabel <david.vrabel@xxxxxxxxxx>
Cc: Juergen Gross <jgross@xxxxxxxx>
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
AFAICT this patch needs to be backported to 3.19, 4.0, 4.1 and 4.2.
arch/x86/xen/setup.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 55f388e..dcf5865 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -68,6 +68,9 @@ static void __init xen_add_extra_mem(phys_addr_t
start, phys_addr_t size)
int i;

+ start = PAGE_ALIGN(start);
+ size &= PAGE_MASK;

This is not correct. If start wasn't page aligned and size was, you'll
add one additional page to xen_extra_mem.

I'm not understanding this, let's put an example:

start = 0x8c00
size = 0x1000

After the fixup added above this would become:

start = 0x9000
size = 0x1000

So if anything, I'm adding one page less (because 0x8000 was partly
added, and with the fixup it is not added).

You'd add 9c00-9cff which shouldn't be added (in this example you
shouldn't add anything as no complete page is covered by the range).

You need something like:

end = (start + size) & PAGE_MASK;
start = PAGE_ALIGN(start);
size = end - start;
if (!size)


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at