xen/p2m: Check __brk_limit before allocating.
The P2M code is smart enough to return false (which means that it
cannot allocate anymore) and the error can perculate up the calling
stack without trouble - with the error logic doing the proper thing.
So check the __brk_limit values before allocating from extend_brk.
This allows us to boot on machines where we do not have enough
__brk space, and we would get this:
(XEN) domain_crash_sync called from entry.S
(XEN) CPU: 0
(XEN) RIP: e033:[<
ffffffff818aad3b>]
(XEN) RFLAGS:
0000000000000206 EM: 1 CONTEXT: pv guest
(XEN) rax:
ffffffff81a7c000 rbx:
000000000000003d rcx:
0000000000001000
(XEN) rdx:
ffffffff81a7b000 rsi:
0000000000001000 rdi:
0000000000001000
(XEN) rbp:
ffffffff81801cd8 rsp:
ffffffff81801c98 r8:
0000000000100000
(XEN) r9:
ffffffff81a7a000 r10:
0000000000000001 r11:
0000000000000003
(XEN) r12:
0000000000000004 r13:
0000000000000004 r14:
000000000000003d
(XEN) r15:
00000000000001e8 cr0:
000000008005003b cr4:
00000000000006f0
(XEN) cr3:
0000000125803000 cr2:
0000000000000000
(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e02b cs: e033
(XEN) Guest stack trace from rsp=
ffffffff81801c98:
.. which is extend_brk hitting a BUG_ON.
Note that git commit
c3d93f880197953f86ab90d9da4744e926b38e33
(xen: populate correct number of pages when across mem boundary (v2))
exposed this bug).
Interestingly enough, most of the time we are not going to hit this
b/c the _brk space is quite large (v3.5):
ffffffff81a25000 B __brk_base
ffffffff81e43000 B __brk_limit
= ~4MB.
vs earlier kernels (with this back-ported), the space is smaller:
ffffffff81a25000 B __brk_base
ffffffff81a7b000 B __brk_limit
= 344 kBytes.
With this patch, we would get now a limited amount of pages populated back:
Freeing 9f-100 pfn range: 97 pages freed
Freeing b7ee0-ecd9b pfn range: 216763 pages freed
Released 216860 pages of unused memory
Set 295297 page(s) to 1-1 mapping
Populating 100000-134f1c pfn range: 30720 pages added
[while it was instructed to populate 216860 pages back
on this particular machine]
[upstream git commit
6fc0f0142ecf25e3a7e1db52033586107f829af0]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>