All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
@ 2020-02-06 12:53 Wei Yang
  2020-02-06 13:28 ` David Hildenbrand
  2020-02-09 10:36 ` Baoquan He
  0 siblings, 2 replies; 13+ messages in thread
From: Wei Yang @ 2020-02-06 12:53 UTC (permalink / raw)
  To: akpm, osalvador, dan.j.williams
  Cc: linux-mm, linux-kernel, david, bhe, Wei Yang

When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
doesn't work before sparse_init_one_section() is called. This leads to a
crash when hotplug memory.

We should use memmap as it did.

Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
CC: Dan Williams <dan.j.williams@intel.com>
---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index 5a8599041a2a..2efb24ff8f96 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
 	 * Poison uninitialized struct pages in order to catch invalid flags
 	 * combinations.
 	 */
-	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
+	page_init_poison(memmap, sizeof(struct page) * nr_pages);
 
 	ms = __nr_to_section(section_nr);
 	set_section_nid(section_nr, nid);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 12:53 [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM Wei Yang
@ 2020-02-06 13:28 ` David Hildenbrand
  2020-02-06 13:50   ` Baoquan He
  2020-02-06 13:57   ` Wei Yang
  2020-02-09 10:36 ` Baoquan He
  1 sibling, 2 replies; 13+ messages in thread
From: David Hildenbrand @ 2020-02-06 13:28 UTC (permalink / raw)
  To: Wei Yang, akpm, osalvador, dan.j.williams; +Cc: linux-mm, linux-kernel, bhe

On 06.02.20 13:53, Wei Yang wrote:
> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
> doesn't work before sparse_init_one_section() is called. This leads to a
> crash when hotplug memory.
> 
> We should use memmap as it did.
> 
> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> CC: Dan Williams <dan.j.williams@intel.com>
> ---
>  mm/sparse.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 5a8599041a2a..2efb24ff8f96 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>  	 * Poison uninitialized struct pages in order to catch invalid flags
>  	 * combinations.
>  	 */
> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);

If you add sub-sections that don't fall onto the start of the section,

pfn_to_page(start_pfn) != memmap

and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.

Instead of memmap, there would have to be something like

memmap + (start_pfn - SECTION_ALIGN_DOWN(start_pfn))

If I am not wrong :)

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:28 ` David Hildenbrand
@ 2020-02-06 13:50   ` Baoquan He
  2020-02-06 13:55     ` David Hildenbrand
  2020-02-06 14:15     ` Wei Yang
  2020-02-06 13:57   ` Wei Yang
  1 sibling, 2 replies; 13+ messages in thread
From: Baoquan He @ 2020-02-06 13:50 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel

On 02/06/20 at 02:28pm, David Hildenbrand wrote:
> On 06.02.20 13:53, Wei Yang wrote:
> > When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
> > doesn't work before sparse_init_one_section() is called. This leads to a
> > crash when hotplug memory.
> > 
> > We should use memmap as it did.
> > 
> > Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
> > Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> > CC: Dan Williams <dan.j.williams@intel.com>
> > ---
> >  mm/sparse.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/mm/sparse.c b/mm/sparse.c
> > index 5a8599041a2a..2efb24ff8f96 100644
> > --- a/mm/sparse.c
> > +++ b/mm/sparse.c
> > @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
> >  	 * Poison uninitialized struct pages in order to catch invalid flags
> >  	 * combinations.
> >  	 */
> > -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
> > +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
> 
> If you add sub-sections that don't fall onto the start of the section,
> 
> pfn_to_page(start_pfn) != memmap
> 
> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.

It returns the pfn_to_page(pfn) from __populate_section_memmap() and
assign to memmap in vmemmap case, how come it breaks anything. Correct
me if I was wrong.

> 
> Instead of memmap, there would have to be something like
> 
> memmap + (start_pfn - SECTION_ALIGN_DOWN(start_pfn))
> 
> If I am not wrong :)
> 
> -- 
> Thanks,
> 
> David / dhildenb


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:50   ` Baoquan He
@ 2020-02-06 13:55     ` David Hildenbrand
  2020-02-06 14:07       ` Baoquan He
  2020-02-06 14:15     ` Wei Yang
  1 sibling, 1 reply; 13+ messages in thread
From: David Hildenbrand @ 2020-02-06 13:55 UTC (permalink / raw)
  To: Baoquan He
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel

On 06.02.20 14:50, Baoquan He wrote:
> On 02/06/20 at 02:28pm, David Hildenbrand wrote:
>> On 06.02.20 13:53, Wei Yang wrote:
>>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>>> doesn't work before sparse_init_one_section() is called. This leads to a
>>> crash when hotplug memory.
>>>
>>> We should use memmap as it did.
>>>
>>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>>> CC: Dan Williams <dan.j.williams@intel.com>
>>> ---
>>>  mm/sparse.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/mm/sparse.c b/mm/sparse.c
>>> index 5a8599041a2a..2efb24ff8f96 100644
>>> --- a/mm/sparse.c
>>> +++ b/mm/sparse.c
>>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>>>  	 * Poison uninitialized struct pages in order to catch invalid flags
>>>  	 * combinations.
>>>  	 */
>>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>>
>> If you add sub-sections that don't fall onto the start of the section,
>>
>> pfn_to_page(start_pfn) != memmap
>>
>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
> 
> It returns the pfn_to_page(pfn) from __populate_section_memmap() and
> assign to memmap in vmemmap case, how come it breaks anything. Correct
> me if I was wrong.

I'm sorry, I can't follow :) Can you elaborate?

Was your comment targeted at why the old code cannot be broken or why
this patch cannot be broken?


-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:28 ` David Hildenbrand
  2020-02-06 13:50   ` Baoquan He
@ 2020-02-06 13:57   ` Wei Yang
  2020-02-06 13:59     ` David Hildenbrand
  1 sibling, 1 reply; 13+ messages in thread
From: Wei Yang @ 2020-02-06 13:57 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel, bhe

On Thu, Feb 06, 2020 at 02:28:53PM +0100, David Hildenbrand wrote:
>On 06.02.20 13:53, Wei Yang wrote:
>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>> doesn't work before sparse_init_one_section() is called. This leads to a
>> crash when hotplug memory.
>> 
>> We should use memmap as it did.
>> 
>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> CC: Dan Williams <dan.j.williams@intel.com>
>> ---
>>  mm/sparse.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/mm/sparse.c b/mm/sparse.c
>> index 5a8599041a2a..2efb24ff8f96 100644
>> --- a/mm/sparse.c
>> +++ b/mm/sparse.c
>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>>  	 * Poison uninitialized struct pages in order to catch invalid flags
>>  	 * combinations.
>>  	 */
>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>
>If you add sub-sections that don't fall onto the start of the section,
>
>pfn_to_page(start_pfn) != memmap
>
>and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
>
>Instead of memmap, there would have to be something like
>
>memmap + (start_pfn - SECTION_ALIGN_DOWN(start_pfn))
>
>If I am not wrong :)

Hi, David, Thanks for your comment.

To be hones, I am not familiar with SPARSEMEM_VMEMMAP. Here is my
understanding about section_activate() when SPARSEMEM_VMEMMAP is set.

  section_activate(nid, start_pfn, nr_pages, altmap)
    populate_section_mmemap(start_pfn, nr_pages, nid, altmap)
      __populate_section_mmemap(start_pfn, nr_pages, nid, altmap)
        return pfn_to_page(start_pfn)

So the memmap is the page struct for start_pfn when SPARSEMEM_VMEMMAP is set.

Maybe I missed some critical part?

>
>-- 
>Thanks,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:57   ` Wei Yang
@ 2020-02-06 13:59     ` David Hildenbrand
  2020-02-06 14:14       ` Wei Yang
  0 siblings, 1 reply; 13+ messages in thread
From: David Hildenbrand @ 2020-02-06 13:59 UTC (permalink / raw)
  To: Wei Yang
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel, bhe

On 06.02.20 14:57, Wei Yang wrote:
> On Thu, Feb 06, 2020 at 02:28:53PM +0100, David Hildenbrand wrote:
>> On 06.02.20 13:53, Wei Yang wrote:
>>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>>> doesn't work before sparse_init_one_section() is called. This leads to a
>>> crash when hotplug memory.
>>>
>>> We should use memmap as it did.
>>>
>>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>>> CC: Dan Williams <dan.j.williams@intel.com>
>>> ---
>>>  mm/sparse.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/mm/sparse.c b/mm/sparse.c
>>> index 5a8599041a2a..2efb24ff8f96 100644
>>> --- a/mm/sparse.c
>>> +++ b/mm/sparse.c
>>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>>>  	 * Poison uninitialized struct pages in order to catch invalid flags
>>>  	 * combinations.
>>>  	 */
>>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>>
>> If you add sub-sections that don't fall onto the start of the section,
>>
>> pfn_to_page(start_pfn) != memmap
>>
>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
>>
>> Instead of memmap, there would have to be something like
>>
>> memmap + (start_pfn - SECTION_ALIGN_DOWN(start_pfn))
>>
>> If I am not wrong :)
> 
> Hi, David, Thanks for your comment.
> 
> To be hones, I am not familiar with SPARSEMEM_VMEMMAP. Here is my
> understanding about section_activate() when SPARSEMEM_VMEMMAP is set.
> 
>   section_activate(nid, start_pfn, nr_pages, altmap)
>     populate_section_mmemap(start_pfn, nr_pages, nid, altmap)
>       __populate_section_mmemap(start_pfn, nr_pages, nid, altmap)
>         return pfn_to_page(start_pfn)
> 
> So the memmap is the page struct for start_pfn when SPARSEMEM_VMEMMAP is set.
> 
> Maybe I missed some critical part?

I was assuming that memmap is the memmap of the section, not of the
sub-section. (judging from the change in the original patch)

If the right memmap pointer to the sub-section is returned, then we are
fine. Will double check :)

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:55     ` David Hildenbrand
@ 2020-02-06 14:07       ` Baoquan He
  2020-02-06 14:37         ` David Hildenbrand
  0 siblings, 1 reply; 13+ messages in thread
From: Baoquan He @ 2020-02-06 14:07 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel

On 02/06/20 at 02:55pm, David Hildenbrand wrote:
> On 06.02.20 14:50, Baoquan He wrote:
> > On 02/06/20 at 02:28pm, David Hildenbrand wrote:
> >> On 06.02.20 13:53, Wei Yang wrote:
> >>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
> >>> doesn't work before sparse_init_one_section() is called. This leads to a
> >>> crash when hotplug memory.
> >>>
> >>> We should use memmap as it did.
> >>>
> >>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
> >>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> >>> CC: Dan Williams <dan.j.williams@intel.com>
> >>> ---
> >>>  mm/sparse.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/mm/sparse.c b/mm/sparse.c
> >>> index 5a8599041a2a..2efb24ff8f96 100644
> >>> --- a/mm/sparse.c
> >>> +++ b/mm/sparse.c
> >>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
> >>>  	 * Poison uninitialized struct pages in order to catch invalid flags
> >>>  	 * combinations.
> >>>  	 */
> >>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
> >>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
> >>
> >> If you add sub-sections that don't fall onto the start of the section,
> >>
> >> pfn_to_page(start_pfn) != memmap
> >>
> >> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
> > 
> > It returns the pfn_to_page(pfn) from __populate_section_memmap() and
> > assign to memmap in vmemmap case, how come it breaks anything. Correct
> > me if I was wrong.
> 
> I'm sorry, I can't follow :) Can you elaborate?
> 
> Was your comment targeted at why the old code cannot be broken or why
> this patch cannot be broken?

Sorry for the confusion :-) the latter. I mean the returned memmap has been
at the pfn_to_page(start_pfn) in SPARSEMEM_VMEMMAP case.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:59     ` David Hildenbrand
@ 2020-02-06 14:14       ` Wei Yang
  0 siblings, 0 replies; 13+ messages in thread
From: Wei Yang @ 2020-02-06 14:14 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Wei Yang, Wei Yang, akpm, osalvador, dan.j.williams, linux-mm,
	linux-kernel, bhe

On Thu, Feb 06, 2020 at 02:59:50PM +0100, David Hildenbrand wrote:
>On 06.02.20 14:57, Wei Yang wrote:
>> On Thu, Feb 06, 2020 at 02:28:53PM +0100, David Hildenbrand wrote:
>>> On 06.02.20 13:53, Wei Yang wrote:
>>>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>>>> doesn't work before sparse_init_one_section() is called. This leads to a
>>>> crash when hotplug memory.
>>>>
>>>> We should use memmap as it did.
>>>>
>>>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>>>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>>>> CC: Dan Williams <dan.j.williams@intel.com>
>>>> ---
>>>>  mm/sparse.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/mm/sparse.c b/mm/sparse.c
>>>> index 5a8599041a2a..2efb24ff8f96 100644
>>>> --- a/mm/sparse.c
>>>> +++ b/mm/sparse.c
>>>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>>>>  	 * Poison uninitialized struct pages in order to catch invalid flags
>>>>  	 * combinations.
>>>>  	 */
>>>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>>>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>>>
>>> If you add sub-sections that don't fall onto the start of the section,
>>>
>>> pfn_to_page(start_pfn) != memmap
>>>
>>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
>>>
>>> Instead of memmap, there would have to be something like
>>>
>>> memmap + (start_pfn - SECTION_ALIGN_DOWN(start_pfn))
>>>
>>> If I am not wrong :)
>> 
>> Hi, David, Thanks for your comment.
>> 
>> To be hones, I am not familiar with SPARSEMEM_VMEMMAP. Here is my
>> understanding about section_activate() when SPARSEMEM_VMEMMAP is set.
>> 
>>   section_activate(nid, start_pfn, nr_pages, altmap)
>>     populate_section_mmemap(start_pfn, nr_pages, nid, altmap)
>>       __populate_section_mmemap(start_pfn, nr_pages, nid, altmap)
>>         return pfn_to_page(start_pfn)
>> 
>> So the memmap is the page struct for start_pfn when SPARSEMEM_VMEMMAP is set.
>> 
>> Maybe I missed some critical part?
>
>I was assuming that memmap is the memmap of the section, not of the
>sub-section. (judging from the change in the original patch)
>
>If the right memmap pointer to the sub-section is returned, then we are
>fine. Will double check :)
>

Thanks, your comments are valuable :-)

>-- 
>Thanks,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 13:50   ` Baoquan He
  2020-02-06 13:55     ` David Hildenbrand
@ 2020-02-06 14:15     ` Wei Yang
  1 sibling, 0 replies; 13+ messages in thread
From: Wei Yang @ 2020-02-06 14:15 UTC (permalink / raw)
  To: Baoquan He
  Cc: David Hildenbrand, Wei Yang, akpm, osalvador, dan.j.williams,
	linux-mm, linux-kernel

On Thu, Feb 06, 2020 at 09:50:16PM +0800, Baoquan He wrote:
>On 02/06/20 at 02:28pm, David Hildenbrand wrote:
>> On 06.02.20 13:53, Wei Yang wrote:
>> > When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>> > doesn't work before sparse_init_one_section() is called. This leads to a
>> > crash when hotplug memory.
>> > 
>> > We should use memmap as it did.
>> > 
>> > Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>> > Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> > CC: Dan Williams <dan.j.williams@intel.com>
>> > ---
>> >  mm/sparse.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> > 
>> > diff --git a/mm/sparse.c b/mm/sparse.c
>> > index 5a8599041a2a..2efb24ff8f96 100644
>> > --- a/mm/sparse.c
>> > +++ b/mm/sparse.c
>> > @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>> >  	 * Poison uninitialized struct pages in order to catch invalid flags
>> >  	 * combinations.
>> >  	 */
>> > -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>> > +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>> 
>> If you add sub-sections that don't fall onto the start of the section,
>> 
>> pfn_to_page(start_pfn) != memmap
>> 
>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
>
>It returns the pfn_to_page(pfn) from __populate_section_memmap() and
>assign to memmap in vmemmap case, how come it breaks anything. Correct
>me if I was wrong.
>

Just see your reply.

Thanks for your explanation. :-)

>> David / dhildenb

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 14:07       ` Baoquan He
@ 2020-02-06 14:37         ` David Hildenbrand
  2020-02-06 22:15           ` Wei Yang
  2020-02-07  7:23           ` Baoquan He
  0 siblings, 2 replies; 13+ messages in thread
From: David Hildenbrand @ 2020-02-06 14:37 UTC (permalink / raw)
  To: Baoquan He
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel

On 06.02.20 15:07, Baoquan He wrote:
> On 02/06/20 at 02:55pm, David Hildenbrand wrote:
>> On 06.02.20 14:50, Baoquan He wrote:
>>> On 02/06/20 at 02:28pm, David Hildenbrand wrote:
>>>> On 06.02.20 13:53, Wei Yang wrote:
>>>>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>>>>> doesn't work before sparse_init_one_section() is called. This leads to a
>>>>> crash when hotplug memory.
>>>>>
>>>>> We should use memmap as it did.
>>>>>
>>>>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>>>>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>>>>> CC: Dan Williams <dan.j.williams@intel.com>
>>>>> ---
>>>>>  mm/sparse.c | 2 +-
>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/mm/sparse.c b/mm/sparse.c
>>>>> index 5a8599041a2a..2efb24ff8f96 100644
>>>>> --- a/mm/sparse.c
>>>>> +++ b/mm/sparse.c
>>>>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>>>>>  	 * Poison uninitialized struct pages in order to catch invalid flags
>>>>>  	 * combinations.
>>>>>  	 */
>>>>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>>>>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>>>>
>>>> If you add sub-sections that don't fall onto the start of the section,
>>>>
>>>> pfn_to_page(start_pfn) != memmap
>>>>
>>>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
>>>
>>> It returns the pfn_to_page(pfn) from __populate_section_memmap() and
>>> assign to memmap in vmemmap case, how come it breaks anything. Correct
>>> me if I was wrong.
>>
>> I'm sorry, I can't follow :) Can you elaborate?
>>
>> Was your comment targeted at why the old code cannot be broken or why
>> this patch cannot be broken?
> 
> Sorry for the confusion :-) the latter. I mean the returned memmap has been
> at the pfn_to_page(start_pfn) in SPARSEMEM_VMEMMAP case.

Yeah, at least for SPARSEMEM_VMEMMAP it is indeed right. Thanks :)


Now, about SPARSEMEM:

populate_section_memmap() does not care about nr_pages and will allocate
a memmap for the whole section. So, whenever we add sub-sections to a
section, we allocate a new memmap for the whole section. And we do
overwrite the memmap pointer in our section. ( sparse_add_section() )

That makes me assume that sub-section hot-add under SPARSEMEM is either

a) never enabled and only works with SPARSEMEM_VMEMMAP
b) horribly broken

And I think a) applies (looking at pfn_section_valid()). Therefore, we
don't have to care about sub-section hot-add specifics (and I would be
broken already)

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 14:37         ` David Hildenbrand
@ 2020-02-06 22:15           ` Wei Yang
  2020-02-07  7:23           ` Baoquan He
  1 sibling, 0 replies; 13+ messages in thread
From: Wei Yang @ 2020-02-06 22:15 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Baoquan He, Wei Yang, akpm, osalvador, dan.j.williams, linux-mm,
	linux-kernel

On Thu, Feb 06, 2020 at 03:37:40PM +0100, David Hildenbrand wrote:
>On 06.02.20 15:07, Baoquan He wrote:
>> On 02/06/20 at 02:55pm, David Hildenbrand wrote:
>>> On 06.02.20 14:50, Baoquan He wrote:
>>>> On 02/06/20 at 02:28pm, David Hildenbrand wrote:
>>>>> On 06.02.20 13:53, Wei Yang wrote:
>>>>>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
>>>>>> doesn't work before sparse_init_one_section() is called. This leads to a
>>>>>> crash when hotplug memory.
>>>>>>
>>>>>> We should use memmap as it did.
>>>>>>
>>>>>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
>>>>>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>>>>>> CC: Dan Williams <dan.j.williams@intel.com>
>>>>>> ---
>>>>>>  mm/sparse.c | 2 +-
>>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/mm/sparse.c b/mm/sparse.c
>>>>>> index 5a8599041a2a..2efb24ff8f96 100644
>>>>>> --- a/mm/sparse.c
>>>>>> +++ b/mm/sparse.c
>>>>>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>>>>>>  	 * Poison uninitialized struct pages in order to catch invalid flags
>>>>>>  	 * combinations.
>>>>>>  	 */
>>>>>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
>>>>>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>>>>>
>>>>> If you add sub-sections that don't fall onto the start of the section,
>>>>>
>>>>> pfn_to_page(start_pfn) != memmap
>>>>>
>>>>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
>>>>
>>>> It returns the pfn_to_page(pfn) from __populate_section_memmap() and
>>>> assign to memmap in vmemmap case, how come it breaks anything. Correct
>>>> me if I was wrong.
>>>
>>> I'm sorry, I can't follow :) Can you elaborate?
>>>
>>> Was your comment targeted at why the old code cannot be broken or why
>>> this patch cannot be broken?
>> 
>> Sorry for the confusion :-) the latter. I mean the returned memmap has been
>> at the pfn_to_page(start_pfn) in SPARSEMEM_VMEMMAP case.
>
>Yeah, at least for SPARSEMEM_VMEMMAP it is indeed right. Thanks :)
>
>
>Now, about SPARSEMEM:
>
>populate_section_memmap() does not care about nr_pages and will allocate
>a memmap for the whole section. So, whenever we add sub-sections to a
>section, we allocate a new memmap for the whole section. And we do
>overwrite the memmap pointer in our section. ( sparse_add_section() )
>
>That makes me assume that sub-section hot-add under SPARSEMEM is either
>
>a) never enabled and only works with SPARSEMEM_VMEMMAP
>b) horribly broken
>
>And I think a) applies (looking at pfn_section_valid()). Therefore, we
>don't have to care about sub-section hot-add specifics (and I would be
>broken already)

Yes, I am looking into this problem. Actually, there maybe another problem.

Just get my brain refreshed, need some time to dig into.

>
>Acked-by: David Hildenbrand <david@redhat.com>
>
>-- 
>Thanks,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 14:37         ` David Hildenbrand
  2020-02-06 22:15           ` Wei Yang
@ 2020-02-07  7:23           ` Baoquan He
  1 sibling, 0 replies; 13+ messages in thread
From: Baoquan He @ 2020-02-07  7:23 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Wei Yang, akpm, osalvador, dan.j.williams, linux-mm, linux-kernel

On 02/06/20 at 03:37pm, David Hildenbrand wrote:
> On 06.02.20 15:07, Baoquan He wrote:
> > On 02/06/20 at 02:55pm, David Hildenbrand wrote:
> >> On 06.02.20 14:50, Baoquan He wrote:
> >>> On 02/06/20 at 02:28pm, David Hildenbrand wrote:
> >>>> On 06.02.20 13:53, Wei Yang wrote:
> >>>>> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
> >>>>> doesn't work before sparse_init_one_section() is called. This leads to a
> >>>>> crash when hotplug memory.
> >>>>>
> >>>>> We should use memmap as it did.
> >>>>>
> >>>>> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
> >>>>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> >>>>> CC: Dan Williams <dan.j.williams@intel.com>
> >>>>> ---
> >>>>>  mm/sparse.c | 2 +-
> >>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>>>
> >>>>> diff --git a/mm/sparse.c b/mm/sparse.c
> >>>>> index 5a8599041a2a..2efb24ff8f96 100644
> >>>>> --- a/mm/sparse.c
> >>>>> +++ b/mm/sparse.c
> >>>>> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
> >>>>>  	 * Poison uninitialized struct pages in order to catch invalid flags
> >>>>>  	 * combinations.
> >>>>>  	 */
> >>>>> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
> >>>>> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
> >>>>
> >>>> If you add sub-sections that don't fall onto the start of the section,
> >>>>
> >>>> pfn_to_page(start_pfn) != memmap
> >>>>
> >>>> and your patch would break that under SPARSEMEM_VMEMMAP if I am not wrong.
> >>>
> >>> It returns the pfn_to_page(pfn) from __populate_section_memmap() and
> >>> assign to memmap in vmemmap case, how come it breaks anything. Correct
> >>> me if I was wrong.
> >>
> >> I'm sorry, I can't follow :) Can you elaborate?
> >>
> >> Was your comment targeted at why the old code cannot be broken or why
> >> this patch cannot be broken?
> > 
> > Sorry for the confusion :-) the latter. I mean the returned memmap has been
> > at the pfn_to_page(start_pfn) in SPARSEMEM_VMEMMAP case.
> 
> Yeah, at least for SPARSEMEM_VMEMMAP it is indeed right. Thanks :)
> 
> 
> Now, about SPARSEMEM:
> 
> populate_section_memmap() does not care about nr_pages and will allocate
> a memmap for the whole section. So, whenever we add sub-sections to a
> section, we allocate a new memmap for the whole section. And we do
> overwrite the memmap pointer in our section. ( sparse_add_section() )
> 
> That makes me assume that sub-section hot-add under SPARSEMEM is either
> 
> a) never enabled and only works with SPARSEMEM_VMEMMAP
> b) horribly broken
> 
> And I think a) applies (looking at pfn_section_valid()). Therefore, we
> don't have to care about sub-section hot-add specifics (and I would be
> broken already)

Yeah, I have the same thought as you. And later Dan's words confirms it
in another threaad.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM
  2020-02-06 12:53 [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM Wei Yang
  2020-02-06 13:28 ` David Hildenbrand
@ 2020-02-09 10:36 ` Baoquan He
  1 sibling, 0 replies; 13+ messages in thread
From: Baoquan He @ 2020-02-09 10:36 UTC (permalink / raw)
  To: Wei Yang; +Cc: akpm, osalvador, dan.j.williams, linux-mm, linux-kernel, david

On 02/06/20 at 08:53pm, Wei Yang wrote:
> When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page()
> doesn't work before sparse_init_one_section() is called. This leads to a
> crash when hotplug memory.
> 
> We should use memmap as it did.

A good fix, thanks.

Reviewed-by: Baoquan He <bhe@redhat.com>

By the way, the failure trace should be added to log so that people can
know better what happened. And this happened in hot adding side in
SPARSEMEM|!VMEMMAP case, the hot removing failed too in this case, I
will psot patch to fix it right away.

> 
> Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug")
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> CC: Dan Williams <dan.j.williams@intel.com>
> ---
>  mm/sparse.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 5a8599041a2a..2efb24ff8f96 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -882,7 +882,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
>  	 * Poison uninitialized struct pages in order to catch invalid flags
>  	 * combinations.
>  	 */
> -	page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
> +	page_init_poison(memmap, sizeof(struct page) * nr_pages);
>  
>  	ms = __nr_to_section(section_nr);
>  	set_section_nid(section_nr, nid);
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-02-09 10:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 12:53 [PATCH] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM Wei Yang
2020-02-06 13:28 ` David Hildenbrand
2020-02-06 13:50   ` Baoquan He
2020-02-06 13:55     ` David Hildenbrand
2020-02-06 14:07       ` Baoquan He
2020-02-06 14:37         ` David Hildenbrand
2020-02-06 22:15           ` Wei Yang
2020-02-07  7:23           ` Baoquan He
2020-02-06 14:15     ` Wei Yang
2020-02-06 13:57   ` Wei Yang
2020-02-06 13:59     ` David Hildenbrand
2020-02-06 14:14       ` Wei Yang
2020-02-09 10:36 ` Baoquan He

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.