Michael Ellerman wrote: > I can't believe I'm the first person to see this, so I imagine I'm missing > something. Perhaps it's only an issue on powerpc? > > I have a machine with some memory at 0, then a hole, and then some more memory > which doesn't start on a section boundary. This is causing the following > crash: > > add_region nid 1 start_pfn 0x77c0 pages 0x840 > add_region nid 1 start_pfn 0x0 pages 0x6000 > > ... > > Unable to handle kernel paging request for data at address 0x00002430 > Faulting instruction address: 0xc0000000004f2940 > cpu 0x4: Vector: 300 (Data Access) at [c000000000737aa0] > pc: c0000000004f2940: .__alloc_bootmem_node+0x28/0x7c > lr: c0000000000a47a0: .sparse_init+0xa8/0x138 > sp: c000000000737d20 > msr: 8000000000001032 > dar: 2430 > dsisr: 40000000 > current = 0xc000000000538410 > paca = 0xc000000000539780 > pid = 0, comm = swapper > enter ? for help > 4:mon> r > R00 = c0000000000a47a0 R16 = 0000000005ff5000 > R01 = c000000000737d20 R17 = 0000000000000004 > R02 = c0000000007331e0 R18 = 00000000100d0000 > R03 = 0000000000000000 R19 = 00000000100b0000 > R04 = 0000000000038000 R20 = 00000000100d0000 > R05 = 0000000000000080 R21 = 0000000010070000 > > The root cause is that we have no memory at pfn 7000 and so early_pfn_to_nid() > is giving us back -1 in sparse_early_mem_map_alloc(). We then pass -1 to > NODE_DATA() which gets us NULL, and hence __alloc_bootmem_node() explodes. > > AFAICT there's no logic to prevent us creating sections with no zeroth page, > and in fact my box is doing it. Therefore it's not valid to assume we can > get the nid from the zeroth page in a section. All we know is that there's > one or more pages in that section for which early_pfn_to_nid() will work. > > So I came up with this hack. Loop through all pages in the section until > we get a valid nid, this should always work. > > We also call early_pfn_to_nid() in node_memmap_size_bytes(), but I didn't > touch that because it's not used on powerpc so I can't test it. > > With this patch my machine boots and seems to be happy. We see to have a few options: 1) default the nid to something -- right now most of the non powerpc architectures return 0 when the nid cannot be found thus avoiding this panic. 2) nid search -- we can do pretty much what is in this patch probabally with some optimisations like trying the first and last pfn in the section first. 3) record the nid -- when we record the memory present in the system we are passed the nid. Somehow the last of these seems the most logical given we have the correct information at the time we record that we need to instantiate the section. So I had a quick go at something which seems to have come out pretty clean. Attached is a completly untested patch to show what I am proposing. -apw