Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1730845 > unrolled thread
| Started by | Michal Hocko <mhocko@kernel.org> |
|---|---|
| First post | 2017-09-12 15:00 +0200 |
| Last post | 2017-09-15 11:40 +0200 |
| Articles | 5 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH] mm/memory_hotplug: fix wrong casting for __remove_section() Michal Hocko <mhocko@kernel.org> - 2017-09-12 15:00 +0200
Re: [PATCH] mm/memory_hotplug: fix wrong casting for __remove_section() YASUAKI ISHIMATSU <yasu.isimatu@gmail.com> - 2017-09-12 19:10 +0200
Re: [PATCH] mm/memory_hotplug: fix wrong casting for __remove_section() Michal Hocko <mhocko@kernel.org> - 2017-09-13 08:00 +0200
Re: [PATCH] mm/memory_hotplug: fix wrong casting for __remove_section() YASUAKI ISHIMATSU <yasu.isimatu@gmail.com> - 2017-09-14 17:50 +0200
Re: [PATCH] mm/memory_hotplug: fix wrong casting for __remove_section() Michal Hocko <mhocko@kernel.org> - 2017-09-15 11:40 +0200
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-09-12 15:00 +0200 |
| Subject | Re: [PATCH] mm/memory_hotplug: fix wrong casting for __remove_section() |
| Message-ID | <uoSXg-1pc-19@gated-at.bofh.it> |
On Fri 08-09-17 16:43:04, YASUAKI ISHIMATSU wrote:
> __remove_section() calls __remove_zone() to shrink zone and pgdat.
> But due to wrong castings, __remvoe_zone() cannot shrink zone
> and pgdat correctly if pfn is over 0xffffffff.
>
> So the patch fixes the following 3 wrong castings.
>
> 1. find_smallest_section_pfn() returns 0 or start_pfn which defined
> as unsigned long. But the function always returns 32bit value
> since the function is defined as int.
>
> 2. find_biggest_section_pfn() returns 0 or pfn which defined as
> unsigned long. the function always returns 32bit value
> since the function is defined as int.
this is indeed wrong. Pfns over would be really broken 15TB. Not that
unrealistic these days
>
> 3. __remove_section() calculates start_pfn using section_nr_to_pfn()
> and scn_nr. section_nr_to_pfn() just shifts scn_nr by
> PFN_SECTION_SHIFT bit. But since scn_nr is defined as int,
> section_nr_to_pfn() always return 32 bit value.
Dohh, those nasty macros. This is hidden quite well. It seems other
callers are using unsigned long properly. But I would rather make sure
we won't repeat that error again. Can we instead make section_nr_to_pfn
resp. pfn_to_section_nr static inline and enfore proper types?
I would also split this into two patches.
Thanks!
> The patch fixes the wrong castings.
>
> Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
> ---
> mm/memory_hotplug.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 73bf17d..3514ef2 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -331,7 +331,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,
>
> #ifdef CONFIG_MEMORY_HOTREMOVE
> /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
> -static int find_smallest_section_pfn(int nid, struct zone *zone,
> +static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
> unsigned long start_pfn,
> unsigned long end_pfn)
> {
> @@ -356,7 +356,7 @@ static int find_smallest_section_pfn(int nid, struct zone *zone,
> }
>
> /* find the biggest valid pfn in the range [start_pfn, end_pfn). */
> -static int find_biggest_section_pfn(int nid, struct zone *zone,
> +static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
> unsigned long start_pfn,
> unsigned long end_pfn)
> {
> @@ -544,7 +544,7 @@ static int __remove_section(struct zone *zone, struct mem_section *ms,
> return ret;
>
> scn_nr = __section_nr(ms);
> - start_pfn = section_nr_to_pfn(scn_nr);
> + start_pfn = section_nr_to_pfn((unsigned long)scn_nr);
> __remove_zone(zone, start_pfn);
>
> sparse_remove_one_section(zone, ms, map_offset);
> --
> 1.8.3.1
>
--
Michal Hocko
SUSE Labs
[toc] | [next] | [standalone]
| From | YASUAKI ISHIMATSU <yasu.isimatu@gmail.com> |
|---|---|
| Date | 2017-09-12 19:10 +0200 |
| Message-ID | <uoWRe-43L-41@gated-at.bofh.it> |
| In reply to | #1730845 |
Hi Michal,
Thanks you for reviewing my patch.
On 09/12/2017 08:49 AM, Michal Hocko wrote:
> On Fri 08-09-17 16:43:04, YASUAKI ISHIMATSU wrote:
>> __remove_section() calls __remove_zone() to shrink zone and pgdat.
>> But due to wrong castings, __remvoe_zone() cannot shrink zone
>> and pgdat correctly if pfn is over 0xffffffff.
>>
>> So the patch fixes the following 3 wrong castings.
>>
>> 1. find_smallest_section_pfn() returns 0 or start_pfn which defined
>> as unsigned long. But the function always returns 32bit value
>> since the function is defined as int.
>>
>> 2. find_biggest_section_pfn() returns 0 or pfn which defined as
>> unsigned long. the function always returns 32bit value
>> since the function is defined as int.
>
> this is indeed wrong. Pfns over would be really broken 15TB. Not that
> unrealistic these days
Why 15TB?
Actually, all callers use pfn which defined as unsigned long to receive
the return value of find_{smallest|biggest}_section_nr(). So it will break
over 16TB.
>
>>
>> 3. __remove_section() calculates start_pfn using section_nr_to_pfn()
>> and scn_nr. section_nr_to_pfn() just shifts scn_nr by
>> PFN_SECTION_SHIFT bit. But since scn_nr is defined as int,
>> section_nr_to_pfn() always return 32 bit value.
>
> Dohh, those nasty macros. This is hidden quite well. It seems other
> callers are using unsigned long properly. But I would rather make sure
> we won't repeat that error again. Can we instead make section_nr_to_pfn
> resp. pfn_to_section_nr static inline and enfore proper types?
I'll update it.
>
> I would also split this into two patches.
I'll update it.
Thanks,
Yasuaki Ishimatsu
>
> Thanks!
>
>> The patch fixes the wrong castings.
>>
>> Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
>> ---
>> mm/memory_hotplug.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
>> index 73bf17d..3514ef2 100644
>> --- a/mm/memory_hotplug.c
>> +++ b/mm/memory_hotplug.c
>> @@ -331,7 +331,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,
>>
>> #ifdef CONFIG_MEMORY_HOTREMOVE
>> /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
>> -static int find_smallest_section_pfn(int nid, struct zone *zone,
>> +static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
>> unsigned long start_pfn,
>> unsigned long end_pfn)
>> {
>> @@ -356,7 +356,7 @@ static int find_smallest_section_pfn(int nid, struct zone *zone,
>> }
>>
>> /* find the biggest valid pfn in the range [start_pfn, end_pfn). */
>> -static int find_biggest_section_pfn(int nid, struct zone *zone,
>> +static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
>> unsigned long start_pfn,
>> unsigned long end_pfn)
>> {
>> @@ -544,7 +544,7 @@ static int __remove_section(struct zone *zone, struct mem_section *ms,
>> return ret;
>>
>> scn_nr = __section_nr(ms);
>> - start_pfn = section_nr_to_pfn(scn_nr);
>> + start_pfn = section_nr_to_pfn((unsigned long)scn_nr);
>> __remove_zone(zone, start_pfn);
>>
>> sparse_remove_one_section(zone, ms, map_offset);
>> --
>> 1.8.3.1
>>
>
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-09-13 08:00 +0200 |
| Message-ID | <up8Sl-3ks-3@gated-at.bofh.it> |
| In reply to | #1731048 |
On Tue 12-09-17 13:05:39, YASUAKI ISHIMATSU wrote: > Hi Michal, > > Thanks you for reviewing my patch. > > On 09/12/2017 08:49 AM, Michal Hocko wrote: > > On Fri 08-09-17 16:43:04, YASUAKI ISHIMATSU wrote: > >> __remove_section() calls __remove_zone() to shrink zone and pgdat. > >> But due to wrong castings, __remvoe_zone() cannot shrink zone > >> and pgdat correctly if pfn is over 0xffffffff. > >> > >> So the patch fixes the following 3 wrong castings. > >> > >> 1. find_smallest_section_pfn() returns 0 or start_pfn which defined > >> as unsigned long. But the function always returns 32bit value > >> since the function is defined as int. > >> > >> 2. find_biggest_section_pfn() returns 0 or pfn which defined as > >> unsigned long. the function always returns 32bit value > >> since the function is defined as int. > > > > this is indeed wrong. Pfns over would be really broken 15TB. Not that > > unrealistic these days > > Why 15TB? 0xffffffff>>28 -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | YASUAKI ISHIMATSU <yasu.isimatu@gmail.com> |
|---|---|
| Date | 2017-09-14 17:50 +0200 |
| Message-ID | <upEyS-6RC-23@gated-at.bofh.it> |
| In reply to | #1731387 |
Hi Michal,
On 09/13/2017 01:59 AM, Michal Hocko wrote:
> On Tue 12-09-17 13:05:39, YASUAKI ISHIMATSU wrote:
>> Hi Michal,
>>
>> Thanks you for reviewing my patch.
>>
>> On 09/12/2017 08:49 AM, Michal Hocko wrote:
>>> On Fri 08-09-17 16:43:04, YASUAKI ISHIMATSU wrote:
>>>> __remove_section() calls __remove_zone() to shrink zone and pgdat.
>>>> But due to wrong castings, __remvoe_zone() cannot shrink zone
>>>> and pgdat correctly if pfn is over 0xffffffff.
>>>>
>>>> So the patch fixes the following 3 wrong castings.
>>>>
>>>> 1. find_smallest_section_pfn() returns 0 or start_pfn which defined
>>>> as unsigned long. But the function always returns 32bit value
>>>> since the function is defined as int.
>>>>
>>>> 2. find_biggest_section_pfn() returns 0 or pfn which defined as
>>>> unsigned long. the function always returns 32bit value
>>>> since the function is defined as int.
>>>
>>> this is indeed wrong. Pfns over would be really broken 15TB. Not that
>>> unrealistic these days
>>
>> Why 15TB?
>
> 0xffffffff>>28
>
Even thought I see your explanation, I cannot understand.
In my understanding, find_{smallest|biggest}_section_pfn() return integer.
So the functions always return 0x00000000 - 0xffffffff. Therefore if pfn is over
0xffffffff (under 16TB), then the function cannot work correctly.
What am I wrong?
Thanks,
Yasuaki Ishimatsu
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-09-15 11:40 +0200 |
| Message-ID | <upVgm-Wh-3@gated-at.bofh.it> |
| In reply to | #1732362 |
On Thu 14-09-17 11:43:10, YASUAKI ISHIMATSU wrote:
> Hi Michal,
>
> On 09/13/2017 01:59 AM, Michal Hocko wrote:
> > On Tue 12-09-17 13:05:39, YASUAKI ISHIMATSU wrote:
> >> Hi Michal,
> >>
> >> Thanks you for reviewing my patch.
> >>
> >> On 09/12/2017 08:49 AM, Michal Hocko wrote:
> >>> On Fri 08-09-17 16:43:04, YASUAKI ISHIMATSU wrote:
> >>>> __remove_section() calls __remove_zone() to shrink zone and pgdat.
> >>>> But due to wrong castings, __remvoe_zone() cannot shrink zone
> >>>> and pgdat correctly if pfn is over 0xffffffff.
> >>>>
> >>>> So the patch fixes the following 3 wrong castings.
> >>>>
> >>>> 1. find_smallest_section_pfn() returns 0 or start_pfn which defined
> >>>> as unsigned long. But the function always returns 32bit value
> >>>> since the function is defined as int.
> >>>>
> >>>> 2. find_biggest_section_pfn() returns 0 or pfn which defined as
> >>>> unsigned long. the function always returns 32bit value
> >>>> since the function is defined as int.
> >>>
> >>> this is indeed wrong. Pfns over would be really broken 15TB. Not that
> >>> unrealistic these days
> >>
> >> Why 15TB?
> >
> > 0xffffffff>>28
> >
>
> Even thought I see your explanation, I cannot understand.
>
> In my understanding, find_{smallest|biggest}_section_pfn() return integer.
> So the functions always return 0x00000000 - 0xffffffff. Therefore if pfn is over
> 0xffffffff (under 16TB), then the function cannot work correctly.
>
> What am I wrong?
You are not wrong. We are talking about the same thing AFAICS. I was
just less precise...
--
Michal Hocko
SUSE Labs
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web