Skip to contentSkip to conversation

Crash on boot with 2.6.37-rc8-git3

DISCUSSION M A Young 6 participants 25 messages Jan 7, 2011 – Jan 25, 2011

Subsystems (3)
lore
Share & tools
lore

M A Young

author
#0 lore raw
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 2 lines

BUG unable to handle kernel NULL pointer dereference at
IP: [<ffffffff81b69b92>] setup_node_bootmem+0x16b/0x199

Hmmm, I did see something similar to this in 2.6.37-rc1, but we fixed that quickly. It was triggered by having 4GB of memory or so and the work-around was to use dom0_mem=max:2GB.

Can you send the photo? Maybe the calleer stack will shed some light.

Here are two photos of the output at different times. The context is

0xffffffff81b69b6d <setup_node_bootmem+326>:

    callq  0xffffffff81475ec9 <printk>
   0xffffffff81b69b72 <setup_node_bootmem+331>:	movslq %ebx,%rdx
   0xffffffff81b69b75 <setup_node_bootmem+334>:	xor    %eax,%eax
   0xffffffff81b69b77 <setup_node_bootmem+336>:	mov    $0x4fc0,%ecx
   0xffffffff81b69b7c <setup_node_bootmem+341>:
    mov    -0x7e4cb750(,%rdx,8),%rsi
   0xffffffff81b69b84 <setup_node_bootmem+349>:	shr    $0xc,%r13
   0xffffffff81b69b88 <setup_node_bootmem+353>:	shr    $0xc,%r12
   0xffffffff81b69b8c <setup_node_bootmem+357>:	sub    %r13,%r12
   0xffffffff81b69b8f <setup_node_bootmem+360>:	mov    %rsi,%rdi
   0xffffffff81b69b92 <setup_node_bootmem+363>:	rep stos %eax,%es:(%rdi)
   0xffffffff81b69b94 <setup_node_bootmem+365>:	mov    %ebx,%edi
   0xffffffff81b69b96 <setup_node_bootmem+367>:
    mov    -0x7e4cb750(,%rdx,8),%rax

which is somewhere around line 224 in arch/x86/mm/numa_64.c

if (nid != nodeid)
printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid,
nid);

        memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
        NODE_DATA(nodeid)->node_id = nodeid;
        NODE_DATA(nodeid)->node_start_pfn = start_pfn;
        NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;

        node_set_online(nodeid);

I do have 4GB of memory and the system does boot if I add dom0_mem=max:2GB to the xen boot line.

Michael Young

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 12 lines · M A Young
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 2 lines

BUG unable to handle kernel NULL pointer dereference at
IP: [<ffffffff81b69b92>] setup_node_bootmem+0x16b/0x199

Hmmm, I did see something similar to this in 2.6.37-rc1, but we fixed that quickly. It was triggered by having 4GB of memory or so and the work-around was to use dom0_mem=max:2GB.

Can you send the photo? Maybe the calleer stack will shed some light.

Here are two photos of the output at different times. The context is

Quoted 12 lines
   0xffffffff81b69b6d <setup_node_bootmem+326>:
    callq  0xffffffff81475ec9 <printk>
   0xffffffff81b69b72 <setup_node_bootmem+331>:	movslq %ebx,%rdx
   0xffffffff81b69b75 <setup_node_bootmem+334>:	xor    %eax,%eax
   0xffffffff81b69b77 <setup_node_bootmem+336>:	mov    $0x4fc0,%ecx
   0xffffffff81b69b7c <setup_node_bootmem+341>:
    mov    -0x7e4cb750(,%rdx,8),%rsi
   0xffffffff81b69b84 <setup_node_bootmem+349>:	shr    $0xc,%r13
   0xffffffff81b69b88 <setup_node_bootmem+353>:	shr    $0xc,%r12
   0xffffffff81b69b8c <setup_node_bootmem+357>:	sub    %r13,%r12
   0xffffffff81b69b8f <setup_node_bootmem+360>:	mov    %rsi,%rdi
   0xffffffff81b69b92 <setup_node_bootmem+363>:	rep stos %eax,%es:(%rdi)

That looks like:

	memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
Quoted 7 lines

From the photo, %eax is zero, and this is perfect code for copying values in.

   0xffffffff81b69b94 <setup_node_bootmem+365>:	mov    %ebx,%edi
   0xffffffff81b69b96 <setup_node_bootmem+367>:
    mov    -0x7e4cb750(,%rdx,8),%rax
Quoted 5 lines

which is somewhere around line 224 in arch/x86/mm/numa_64.c

if (nid != nodeid)
printk(KERN_INFO " NODE_DATA(%d) on node %d\n",
nodeid, nid);

Can you make sure that 419db274bed4269f475a8e78cbe9c917192cfe8b is in? That is the patch that fixed this issue last time.

However .. the more I look at the code the less it seems to be that and that is the last fix in that file.

Do you see any messages about 'Cannot find 20 bytes in node X' (where X I think is 0)?

author
#2 lore raw
Quoted 2 lines · Konrad Rzeszutek Wilk

Can you make sure that 419db274bed4269f475a8e78cbe9c917192cfe8b is in? That is the patch that fixed this issue last time.

Yes it is.

Quoted 2 lines

Do you see any messages about 'Cannot find 20 bytes in node X' (where X I think is 0)?

I haven't spotted any such message.

Michael Young

#3 lore raw
Quoted 4 lines
Quoted 2 lines

Do you see any messages about 'Cannot find 20 bytes in node X' (where X I think is 0)?

I haven't spotted any such message.

Try fiddling with the dom0_mem.. to see at what point it starts failing. Is this happening only on this machine or do you see it on other boxes too?

Your E820 looks as so:
BIOS-e820: 0000000000000000 - 000000000009f000 (usable)
BIOS-e820: 000000000009f000 - 00000000000a0000 (reserved)
BIOS-e820: 0000000000100000 - 00000000df66d800 (usable)
BIOS-e820: 00000000df66d800 - 00000000e0000000 (reserved)
BIOS-e820: 00000000f8000000 - 00000000fc000000 (reserved)
BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
BIOS-e820: 00000000fed18000 - 00000000fed1c000 (reserved)
BIOS-e820: 00000000fed20000 - 00000000fed90000 (reserved)
BIOS-e820: 00000000feda0000 - 00000000feda6000 (reserved)
BIOS-e820: 00000000fee00000 - 00000000fee10000 (reserved)
BIOS-e820: 00000000ffe00000 - 0000000100000000 (reserved)
BIOS-e820: 0000000100000000 - 0000000120000000 (usable)

Which looks completly normal.. I am really at loss here. You could also sprinkle printk's around that code (or xen_raw_printk and inhibit the Linux kernel console output - that way you would only see the Xen and output from xen_raw_printk).

Let me bootup 2.6.37 on a 4GB machine just to see if I am seeing this.

author
#4 lore raw
Quoted 2 lines · Konrad Rzeszutek Wilk

Try fiddling with the dom0_mem.. to see at what point it starts failing. Is this happening only on this machine or do you see it on other boxes too?

dom0_mem=max:3574MB boots, dom0_mem=max:3575MB doesn't. I haven't tried it on other boxes yet.

Quoted 4 lines

Which looks completly normal.. I am really at loss here. You could also sprinkle printk's around that code (or xen_raw_printk and inhibit the Linux kernel console output - that way you would only see the Xen and output from xen_raw_printk).

I will think about where the printk's should go, but probably not tonight.

Michael Young

author
#5 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 14 lines · Konrad Rzeszutek Wilk

Your E820 looks as so:
BIOS-e820: 0000000000000000 - 000000000009f000 (usable)
BIOS-e820: 000000000009f000 - 00000000000a0000 (reserved)
BIOS-e820: 0000000000100000 - 00000000df66d800 (usable)
BIOS-e820: 00000000df66d800 - 00000000e0000000 (reserved)
BIOS-e820: 00000000f8000000 - 00000000fc000000 (reserved)
BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
BIOS-e820: 00000000fed18000 - 00000000fed1c000 (reserved)
BIOS-e820: 00000000fed20000 - 00000000fed90000 (reserved)
BIOS-e820: 00000000feda0000 - 00000000feda6000 (reserved)
BIOS-e820: 00000000fee00000 - 00000000fee10000 (reserved)
BIOS-e820: 00000000ffe00000 - 0000000100000000 (reserved)
BIOS-e820: 0000000100000000 - 0000000120000000 (usable)

Quoted 1 line

Which looks completly normal.. I am really at loss here.

I have looked at this again and I am worried by the last section, which is a chunk from 4GB to 4.5GB. The problem is that I only have 4GB. My tests show that dom0_mem=max:3574MB boots, dom0_mem=max:3575MB doesn't. The first two "usable" chunks add up to a few KB over 3574MB so the problems come when it tries to use the final "usable" chunk which I interpret as being beyond the memory I have.

3574MB is a bit less than 3.5GB so I would guess that the final chunk is trying to make up the memory to 4GB. There are also gaps in these memory pieces which add up to about 445MB. Hence I think there are some issues with the memory allocation mechanism.

Michael Young

#6 lore raw
Quoted 22 lines · M A Young
Quoted 13 lines

BIOS-e820: 0000000000000000 - 000000000009f000 (usable)
BIOS-e820: 000000000009f000 - 00000000000a0000 (reserved)
BIOS-e820: 0000000000100000 - 00000000df66d800 (usable)
BIOS-e820: 00000000df66d800 - 00000000e0000000 (reserved)
BIOS-e820: 00000000f8000000 - 00000000fc000000 (reserved)
BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
BIOS-e820: 00000000fed18000 - 00000000fed1c000 (reserved)
BIOS-e820: 00000000fed20000 - 00000000fed90000 (reserved)
BIOS-e820: 00000000feda0000 - 00000000feda6000 (reserved)
BIOS-e820: 00000000fee00000 - 00000000fee10000 (reserved)
BIOS-e820: 00000000ffe00000 - 0000000100000000 (reserved)
BIOS-e820: 0000000100000000 - 0000000120000000 (usable)

Quoted 1 line

Which looks completly normal.. I am really at loss here.

I have looked at this again and I am worried by the last section, which is a chunk from 4GB to 4.5GB. The problem is that I only have 4GB. My tests show that dom0_mem=max:3574MB boots, dom0_mem=max:3575MB doesn't. The first two "usable" chunks add up to a few KB over 3574MB so the problems come when it tries to use the final "usable" chunk which I interpret as being beyond the memory I have.

Quoted 4 lines

3574MB is a bit less than 3.5GB so I would guess that the final chunk is trying to make up the memory to 4GB. There are also gaps in these memory pieces which add up to about 445MB. Hence I think there are some issues with the memory allocation mechanism.

Device memory gets mapped just below 4GB, so the last piece of your RAM gets re-mapped above 4GB by your BIOS, so that it can still be accessed. If you add up the size of all the usable regions in the list above, it will sum to a bit less than 4GB.

The bug will be something in the kernel code that can't handle physical addresses wider than 32 bits (i.e., physical addresses 4GB and above).

-- Keir

author
#7 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 22 lines · Konrad Rzeszutek Wilk
Quoted 4 lines
Quoted 2 lines

Do you see any messages about 'Cannot find 20 bytes in node X' (where X I think is 0)?

I haven't spotted any such message.

Try fiddling with the dom0_mem.. to see at what point it starts failing. Is this happening only on this machine or do you see it on other boxes too?

Your E820 looks as so:
BIOS-e820: 0000000000000000 - 000000000009f000 (usable)
BIOS-e820: 000000000009f000 - 00000000000a0000 (reserved)
BIOS-e820: 0000000000100000 - 00000000df66d800 (usable)
BIOS-e820: 00000000df66d800 - 00000000e0000000 (reserved)
BIOS-e820: 00000000f8000000 - 00000000fc000000 (reserved)
BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
BIOS-e820: 00000000fed18000 - 00000000fed1c000 (reserved)
BIOS-e820: 00000000fed20000 - 00000000fed90000 (reserved)
BIOS-e820: 00000000feda0000 - 00000000feda6000 (reserved)
BIOS-e820: 00000000fee00000 - 00000000fee10000 (reserved)
BIOS-e820: 00000000ffe00000 - 0000000100000000 (reserved)
BIOS-e820: 0000000100000000 - 0000000120000000 (usable)

Quoted 6 lines

Which looks completly normal.. I am really at loss here. You could also sprinkle printk's around that code (or xen_raw_printk and inhibit the Linux kernel console output - that way you would only see the Xen and output from xen_raw_printk).

Let me bootup 2.6.37 on a 4GB machine just to see if I am seeing this.

My next theory is that the issue is that the system is an alignment issue. The NODE DATA is put in the range 00000000df659800 to 00000000df66d7ff (the top end of the second "usable" chunk) and the problem come when it tries to write to the final 2K piece (00000000df66d000 to 00000000df66d800 - 00000000df66d000 occurs on the stack) which hasn't been initialized properly because it isn't a 4K piece. Does this sound plausible?

Michael Young

author
#8 lore raw
Quoted 2 lines · M A Young

My next theory is that the issue is that the system is an alignment issue. The NODE DATA is put in the range 00000000df659800 to 00000000df66d7ff (the top end of the second "usable" chunk) and the problem come when it tries to write to the final 2K piece (00000000df66d000 to 00000000df66d800 - 00000000df66d000 occurs on the stack) which hasn't been initialized properly because it isn't a 4K piece. Does this sound plausible?

Further experiments confirm that it is this 2K piece causing the problem - if I reserve the 2K chunk in the same was that NODE DATA is reserved (though without zeroing it) the system boots, if I reduce this to reserving only 1K then it doesn't.

Michael Young

#9 lore raw
Quoted 11 lines · M A Young
Quoted 8 lines · M A Young

My next theory is that the issue is that the system is an alignment issue. The NODE DATA is put in the range 00000000df659800 to 00000000df66d7ff (the top end of the second "usable" chunk) and the problem come when it tries to write to the final 2K piece (00000000df66d000 to 00000000df66d800 - 00000000df66d000 occurs on the stack) which hasn't been initialized properly because it isn't a 4K piece.
Does this sound plausible?

Quoted 4 lines

Further experiments confirm that it is this 2K piece causing the problem - if I reserve the 2K chunk in the same was that NODE DATA is reserved (though without zeroing it) the system boots, if I reduce this to reserving only 1K then it doesn't.

I think my math is off here. The reserve call is made on the df659800 -> df66d7ff, that would be 20 pages of data. The last PFN df66d is where it dies b/c there is no PTE entry set for it?

What happens if you fudge the code so it allocates those pages to be page aligned. So df65a000->df66e000 ? We skip this way the region df659800->df659fff and start on a new PFN (and pte).

author
#10 lore raw
Quoted 7 lines · Konrad Rzeszutek Wilk

I think my math is off here. The reserve call is made on the df659800 -> df66d7ff, that would be 20 pages of data. The last PFN df66d is where it dies b/c there is no PTE entry set for it?

What happens if you fudge the code so it allocates those pages to be page aligned. So df65a000->df66e000 ? We skip this way the region df659800->df659fff and start on a new PFN (and pte).

I get (though the photo isn't clear in places) df659000->df66cfff and it crashes at find_range_array+0x4d/0x56 which traces back to the call of memblock_find_dma_reserve from setup_arch in arch/x86/kernel/setup.c . So it still crashes, but at a slightly later stage.

Michael Young

#11 lore raw
Quoted 10 lines · M A Young
Quoted 7 lines · Konrad Rzeszutek Wilk

I think my math is off here. The reserve call is made on the df659800 -> df66d7ff, that would be 20 pages of data. The last PFN df66d is where it dies b/c there is no PTE entry set for it?

What happens if you fudge the code so it allocates those pages to be page aligned. So df65a000->df66e000 ? We skip this way the region df659800->df659fff and start on a new PFN (and pte).

Quoted 5 lines

I get (though the photo isn't clear in places) df659000->df66cfff and it crashes at find_range_array+0x4d/0x56 which traces back to the call of memblock_find_dma_reserve from setup_arch in arch/x86/kernel/setup.c . So it still crashes, but at a slightly later stage.

Ok, so we just pass the back so to say to the next user of that PFN.

We should find out why that PTE is not being setup.... And I think this might be a missing entry in the MFN (thanks to Stefan Bader finding a bug there). Looking at your E820:

[    0.000000]  Xen: 0000000000100000 - 000000003b0e2000 (usable)

Your memory ends a 3b0e, which is not on a nice page boundary. Can you try this patch (you will need to re-gigger as in 2.6.38-rc1 the p2m code moved out of xen/mmu.c to xen/p2m.c):

https://patchwork.kernel.org/patch/492011/

BTW, You are doing a great detective work here. Thanks for being willing to dig in this.

author
#12 lore raw
Quoted 5 lines · Konrad Rzeszutek Wilk

We should find out why that PTE is not being setup.... And I think this might be a missing entry in the MFN (thanks to Stefan Bader finding a bug there). Looking at your E820:

[    0.000000]  Xen: 0000000000100000 - 000000003b0e2000 (usable)

Mine is

[    0.000000]  Xen: 0000000000100000 - 00000000df66d800 (usable)
Quoted 1 line

Your memory ends a 3b0e, which is not on a nice page boundary.

Mine isn't on a page boundary at all!

Quoted 2 lines

Can you try this patch (you will need to re-gigger as in 2.6.38-rc1 the p2m code moved out of xen/mmu.c to xen/p2m.c):

It doesn't help, and crashes at the same place as the unaltered kernel. My problem may not be happening in the xen code at all. From the boot logs of one of my hack attempts that actually booted I have

[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  Xen: 0000000000000000 - 000000000009f000 (usable)
[    0.000000]  Xen: 000000000009f000 - 0000000000100000 (reserved)
[    0.000000]  Xen: 0000000000100000 - 00000000df66d800 (usable)
[    0.000000]  Xen: 00000000df66d800 - 00000000e0000000 (reserved)
[    0.000000]  Xen: 00000000f8000000 - 00000000fc000000 (reserved)
[    0.000000]  Xen: 00000000fec00000 - 00000000fec10000 (reserved)
[    0.000000]  Xen: 00000000fed18000 - 00000000fed1c000 (reserved)
[    0.000000]  Xen: 00000000fed20000 - 00000000fed90000 (reserved)
[    0.000000]  Xen: 00000000feda0000 - 00000000feda6000 (reserved)
[    0.000000]  Xen: 00000000fee00000 - 00000000fee10000 (reserved)
[    0.000000]  Xen: 00000000ffe00000 - 0000000100000000 (reserved)
[    0.000000]  Xen: 0000000100000000 - 00000001342cb000 (usable)
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI 2.4 present.
[    0.000000] No AGP bridge found
[    0.000000] last_pfn = 0x1342cb max_arch_pfn = 0x400000000
[    0.000000] last_pfn = 0xdf66d max_arch_pfn = 0x400000000
[    0.000000] init_memory_mapping: 0000000000000000-00000000df66d000
[    0.000000] init_memory_mapping: 0000000100000000-00000001342cb000

The last_pfn figure above is actually one more than the last pfn that is initialized and is obtained by right-shifting the start memory address plus the length of the memory piece. That is fine if the memory ends on a page boundary, but not if it doesn't because the partial page doesn't get a pfn. Thus it is available for early allocations such as the NODE DATA chunk. Xen goes for the memory chunk just below the 4GB mark and hits this region, bare metal (2.6.35) starts the NODE DATA at the 4GB mark and doesn't.

I am not sure if bare metal is clever enough not to try to use this partial page, or whether it could but misses it because of how it places the NODE_DATA (at the bottom end of a memory region rather than the top end).

Michael Young

#13 lore raw
Quoted 6 lines · M A Young
Quoted 4 lines · Konrad Rzeszutek Wilk

We should find out why that PTE is not being setup.... And I think this might be a missing entry in the MFN (thanks to Stefan Bader finding a bug there). Looking at your E820:

Quoted 8 lines
Quoted 1 line
[    0.000000]  Xen: 0000000000100000 - 000000003b0e2000 (usable)

Mine is

[    0.000000]  Xen: 0000000000100000 - 00000000df66d800 (usable)
Quoted 1 line

Your memory ends a 3b0e, which is not on a nice page boundary.

Mine isn't on a page boundary at all!

Whoa.

Quoted 29 lines
Quoted 3 lines

Can you try this patch (you will need to re-gigger as in 2.6.38-rc1 the p2m code moved out of xen/mmu.c to xen/p2m.c):

It doesn't help, and crashes at the same place as the unaltered kernel. My problem may not be happening in the xen code at all. From the boot logs of one of my hack attempts that actually booted I have

[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  Xen: 0000000000000000 - 000000000009f000 (usable)
[    0.000000]  Xen: 000000000009f000 - 0000000000100000 (reserved)
[    0.000000]  Xen: 0000000000100000 - 00000000df66d800 (usable)
[    0.000000]  Xen: 00000000df66d800 - 00000000e0000000 (reserved)
[    0.000000]  Xen: 00000000f8000000 - 00000000fc000000 (reserved)
[    0.000000]  Xen: 00000000fec00000 - 00000000fec10000 (reserved)
[    0.000000]  Xen: 00000000fed18000 - 00000000fed1c000 (reserved)
[    0.000000]  Xen: 00000000fed20000 - 00000000fed90000 (reserved)
[    0.000000]  Xen: 00000000feda0000 - 00000000feda6000 (reserved)
[    0.000000]  Xen: 00000000fee00000 - 00000000fee10000 (reserved)
[    0.000000]  Xen: 00000000ffe00000 - 0000000100000000 (reserved)
[    0.000000]  Xen: 0000000100000000 - 00000001342cb000 (usable)
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI 2.4 present.
[    0.000000] No AGP bridge found
[    0.000000] last_pfn = 0x1342cb max_arch_pfn = 0x400000000
[    0.000000] last_pfn = 0xdf66d max_arch_pfn = 0x400000000
[    0.000000] init_memory_mapping: 0000000000000000-00000000df66d000
[    0.000000] init_memory_mapping: 0000000100000000-00000001342cb000
Quoted 5 lines

The last_pfn figure above is actually one more than the last pfn that is initialized and is obtained by right-shifting the start memory address plus the length of the memory piece. That is fine if the memory ends on a page boundary, but not if it doesn't because the partial page doesn't get a pfn. Thus it is available for early

We can fix how the E820 is done.
Look in arch/x86/xen/setup.c for 'xen_memory_setup' function. Try to wrap make map[i].size be = map[i].szie & ~(PAGE_SIZE-1) that should trim off the last 2048 bytes.

Quoted 3 lines

allocations such as the NODE DATA chunk. Xen goes for the memory chunk just below the 4GB mark and hits this region, bare metal (2.6.35) starts the NODE DATA at the 4GB mark and doesn't.

That should be generic and hit both cases - but I think this got fixed in 2.6.36-ish were going for the region right underneath 4GB is not done (don't remember the details, sadly).

Quoted 5 lines

I am not sure if bare metal is clever enough not to try to use this partial page, or whether it could but misses it because of how it places the NODE_DATA (at the bottom end of a memory region rather than the top end).

If you leave the instrumentation you placed in and add 'memblock=debug' that should give you a good idea of how it does it?

Quoted 7 lines

Michael Young

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#14 lore raw
Quoted 4 lines · Konrad Rzeszutek Wilk

We can fix how the E820 is done.
Look in arch/x86/xen/setup.c for 'xen_memory_setup' function. Try to wrap make map[i].size be = map[i].szie & ~(PAGE_SIZE-1) that should trim off the last 2048 bytes.

The attached patch works for me, though it does assume the memory region starts on a page boundary.

Michael Young

arch/x86/xen/setup.c +4 -1
@@ -179,7 +179,10 @@
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size &= ~(PAGE_SIZE-1);
+		end = map[i].addr + map[i].size;
 
 		if (map[i].type == E820_RAM && end > mem_end) {
 			/* RAM off the end - may be partially included */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#15 lore raw
Quoted 9 lines · M A Young
Quoted 4 lines · Konrad Rzeszutek Wilk

We can fix how the E820 is done.
Look in arch/x86/xen/setup.c for 'xen_memory_setup' function. Try to wrap make map[i].size be = map[i].szie & ~(PAGE_SIZE-1) that should trim off the last 2048 bytes.

The attached patch works for me, though it does assume the memory region starts on a page boundary.

It turns out that it is me having the same issue you have and not the other way around :)

Your patch (in addition to my previous patch) makes my testbox boot, no matter what dom0_mem parameter I choose.

Appended is a version of the patch that doesn't assume that the memory region starts on a page boundary.

---

arch/x86/xen/setup.c +4 -1
index b5a7f92..a3d28a1 100644
@@ -179,7 +179,10 @@ char * __init xen_memory_setup(void)
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;
+		end = map[i].addr + map[i].size;
 
 		if (map[i].type == E820_RAM && end > mem_end) {
 			/* RAM off the end - may be partially included */
#16 lore raw
Quoted 27 lines · Stefano Stabellini
Quoted 9 lines · M A Young
Quoted 4 lines · Konrad Rzeszutek Wilk

We can fix how the E820 is done.
Look in arch/x86/xen/setup.c for 'xen_memory_setup' function. Try to wrap make map[i].size be = map[i].szie & ~(PAGE_SIZE-1) that should trim off the last 2048 bytes.

The attached patch works for me, though it does assume the memory region starts on a page boundary.

It turns out that it is me having the same issue you have and not the other way around :)

Your patch (in addition to my previous patch) makes my testbox boot, no matter what dom0_mem parameter I choose.

Appended is a version of the patch that doesn't assume that the memory region starts on a page boundary.

---

arch/x86/xen/setup.c +0 -0
index b5a7f92..a3d28a1 100644

arch/x86/xen/setup.c char * __init xen_memory_setup(void) · line 184

Quoted 7 lines
arch/x86/xen/setup.c +3 -1
@@ -179,7 +179,10 @@ char * __init xen_memory_setup(void)
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;

The more normal idiom to round down to a page boundary in the kernel is:

	map[i].size &= ~(PAGE_SIZE-1);

Do you also need to page align map[i].addr upwards for maximum safety?

Ian.

Quoted 10 lines
arch/x86/xen/setup.c +1 -0
+		end = map[i].addr + map[i].size;
 
 
 		if (map[i].type == E820_RAM && end > mem_end) {

/* RAM off the end - may be partially included */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#17 lore raw
Quoted 25 lines · Ian Campbell
Quoted 16 lines

It turns out that it is me having the same issue you have and not the other way around :)

Your patch (in addition to my previous patch) makes my testbox boot, no matter what dom0_mem parameter I choose.

Appended is a version of the patch that doesn't assume that the memory region starts on a page boundary.

---

arch/x86/xen/setup.c +0 -0
index b5a7f92..a3d28a1 100644

arch/x86/xen/setup.c char * __init xen_memory_setup(void) · line 184

Quoted 7 lines
arch/x86/xen/setup.c +3 -1
@@ -179,7 +179,10 @@ char * __init xen_memory_setup(void)
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;

The more normal idiom to round down to a page boundary in the kernel is:

Quoted 4 lines
	map[i].size &= ~(PAGE_SIZE-1);

Do you also need to page align map[i].addr upwards for maximum safety?

unless I am very confused

map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE

is not the same as:

as map[i].size &= ~(PAGE_SIZE-1):

because it also takes into account the possibility that map[i].addr is not page aligned. It doesn't move map[i].addr upward but still makes sure that the region ends at a page boundary anyway.

#18 lore raw
Quoted 33 lines · Stefano Stabellini
Quoted 25 lines · Ian Campbell
Quoted 16 lines

It turns out that it is me having the same issue you have and not the other way around :)

Your patch (in addition to my previous patch) makes my testbox boot, no matter what dom0_mem parameter I choose.

Appended is a version of the patch that doesn't assume that the memory region starts on a page boundary.

---

arch/x86/xen/setup.c +0 -0
index b5a7f92..a3d28a1 100644

arch/x86/xen/setup.c char * __init xen_memory_setup(void) · line 184

Quoted 7 lines
arch/x86/xen/setup.c +3 -1
@@ -179,7 +179,10 @@ char * __init xen_memory_setup(void)
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;

The more normal idiom to round down to a page boundary in the kernel is:

Quoted 4 lines
	map[i].size &= ~(PAGE_SIZE-1);

Do you also need to page align map[i].addr upwards for maximum safety?

unless I am very confused

Quoted 8 lines

map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE

is not the same as:

as map[i].size &= ~(PAGE_SIZE-1):

because it also takes into account the possibility that map[i].addr is not page aligned.

Oh yes, I didn't notice that aspect of it.

Quoted 2 lines

It doesn't move map[i].addr upward but still makes sure that
the region ends at a page boundary anyway.

Which returns to my second question ;-) Why do we not need to align addr too?

Ian.

#19 lore raw
Quoted 11 lines · Ian Campbell
Quoted 10 lines

unless I am very confused

map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE

is not the same as:

as map[i].size &= ~(PAGE_SIZE-1):

because it also takes into account the possibility that map[i].addr is not page aligned.

Quoted 7 lines

Oh yes, I didn't notice that aspect of it.

Quoted 2 lines

It doesn't move map[i].addr upward but still makes sure that
the region ends at a page boundary anyway.

Which returns to my second question ;-) Why do we not need to align addr too?

My machine can boot fine with a map[i].addr not page aligned.

#20 lore raw
Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Ian Campbell
Quoted 10 lines

unless I am very confused

map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE

is not the same as:

as map[i].size &= ~(PAGE_SIZE-1):

because it also takes into account the possibility that map[i].addr is not page aligned.

Oh yes, I didn't notice that aspect of it.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

It doesn't move map[i].addr upward but still makes sure that
the region ends at a page boundary anyway.

Which returns to my second question ;-) Why do we not need to align addr too?

My machine can boot fine with a map[i].addr not page aligned.

OK, so then the patch that M A Young came up with ought to do it?

#21 lore raw
Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Ian Campbell
Quoted 10 lines

unless I am very confused

map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE

is not the same as:

as map[i].size &= ~(PAGE_SIZE-1):

because it also takes into account the possibility that map[i].addr is not page aligned.

Oh yes, I didn't notice that aspect of it.

Quoted 2 lines

It doesn't move map[i].addr upward but still makes sure that
the region ends at a page boundary anyway.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Which returns to my second question ;-) Why do we not need to align addr too?

My machine can boot fine with a map[i].addr not page aligned.

OK, so then the patch that M A Young came up with ought to do it?

I think you need the slightly improved version I posted before that can handle map[i].addr not page aligned (I silently added a s-o-b Young, I hope he's OK with this).

---

commit b84683ad1e704c2a296d08ff0cbe29db936f94a7

Author: Stefano Stabellini <[email protected]>
Date:   Tue Jan 25 12:03:42 2011 +0000

xen: make sure the e820 memory regions end at page boundary

arch/x86/xen/setup.c +4 -1
index b5a7f92..a3d28a1 100644
@@ -179,7 +179,10 @@ char * __init xen_memory_setup(void)
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;
+		end = map[i].addr + map[i].size;
 
 		if (map[i].type == E820_RAM && end > mem_end) {
 			/* RAM off the end - may be partially included */
author
#22 lore raw
Quoted 3 lines · Stefano Stabellini

I think you need the slightly improved version I posted before that can handle map[i].addr not page aligned (I silently added a s-o-b Young, I hope he's OK with this).

Yes and yes. My version doesn't work if map[i].addr is not page aligned. The aim is to make sure the end address is page aligned, and avoid ending with a partial page which won't have a PFN and might also require different treatment if there is reserved content in the rest of the page (which is true in my case).

Michael Young

Quoted 26 lines

commit b84683ad1e704c2a296d08ff0cbe29db936f94a7

Author: Stefano Stabellini <[email protected]>
Date:   Tue Jan 25 12:03:42 2011 +0000

xen: make sure the e820 memory regions end at page boundary

arch/x86/xen/setup.c +4 -1
index b5a7f92..a3d28a1 100644
@@ -179,7 +179,10 @@ char * __init xen_memory_setup(void)
 	e820.nr_map = 0;
 	xen_extra_mem_start = mem_end;
 	for (i = 0; i < memmap.nr_entries; i++) {
-		unsigned long long end = map[i].addr + map[i].size;
+		unsigned long long end;
+		if (map[i].type == E820_RAM)
+			map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;
+		end = map[i].addr + map[i].size;
 
 		if (map[i].type == E820_RAM && end > mem_end) {
 			/* RAM off the end - may be partially included */
#23 lore raw
In reply to M A Young

I have a work-in-progress patch that fixes a booting issue on one of my testboxes. Could you please give it a try, passing dom0_mem=700M to the Xen command line?

arch/x86/mm/init.c +14 -1
index 947f42a..ebc0221 100644
@@ -291,10 +291,23 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 		 * located on different 2M pages. cleanup_highmap(), however,
 		 * can only consider _end when it runs, so destroy any
 		 * mappings beyond _brk_end here.
+		 * Be careful not to go over _end.
 		 */
 		pud = pud_offset(pgd_offset_k(_brk_end), _brk_end);
 		pmd = pmd_offset(pud, _brk_end - 1);
-		while (++pmd <= pmd_offset(pud, (unsigned long)_end - 1))
+		while (++pmd < pmd_offset(pud, (unsigned long)_end - 1))
+			pmd_clear(pmd);
+		if (((unsigned long)_end) & ~PMD_MASK) {
+			pte_t *pte;
+			unsigned long addr;
+			for (addr = ((unsigned long)_end) & PMD_MASK;
+					addr < ((unsigned long)_end);
+					addr += PAGE_SIZE) {
+				pte = pte_offset_map(pmd, addr);
+				pte_clear(&init_mm, addr, pte);
+				pte_unmap(pte);
+			}
+		} else
 			pmd_clear(pmd);
 	}
 #endif
author
#24 lore raw
Quoted 3 lines · Stefano Stabellini

I have a work-in-progress patch that fixes a booting issue on one of my testboxes. Could you please give it a try, passing dom0_mem=700M to the Xen command line?

It wouldn't prove anything in my case as booting with dom0_mem=700M works.

Michael Young