Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
Hi Pavel, sorry for the late reply On 6/30/2018 1:07 AM, Pavel Tatashin Wrote: > On Thu, Jun 28, 2018 at 10:30 PM Jia He wrote: >> >> Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns >> where possible") optimized the loop in memmap_init_zone(). But it causes >> possible panic bug. So Daniel Vacek reverted it later. >> >> But as suggested by Daniel Vacek, it is fine to using memblock to skip >> gaps and finding next valid frame with CONFIG_HAVE_ARCH_PFN_VALID. >> >> On arm and arm64, memblock is used by default. But generic version of >> pfn_valid() is based on mem sections and memblock_next_valid_pfn() does >> not always return the next valid one but skips more resulting in some >> valid frames to be skipped (as if they were invalid). And that's why >> kernel was eventually crashing on some !arm machines. > > Hi Jia, > > Is this a bug? Should we make other arches that support memblock to > use memblock_is_map_memory() ? it is more expensive, but if the > default is broken, maybe it makes sense to change? > IIUC, the bug is in memblock_next_valid_pfn instead of pfn_valid. memblock_next_valid_pfn will return the incorrect next valid pfn on !arm arches (e.g. X86). Please refer to b92df1de5. Currently only arm/arm64 use MEMBLOCK_NOMAP, it is really beyond my power to implement it on all other arches ;-) -- Cheers, Jia
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
Hi Pavel, sorry for the late reply On 6/30/2018 1:07 AM, Pavel Tatashin Wrote: > On Thu, Jun 28, 2018 at 10:30 PM Jia He wrote: >> >> Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns >> where possible") optimized the loop in memmap_init_zone(). But it causes >> possible panic bug. So Daniel Vacek reverted it later. >> >> But as suggested by Daniel Vacek, it is fine to using memblock to skip >> gaps and finding next valid frame with CONFIG_HAVE_ARCH_PFN_VALID. >> >> On arm and arm64, memblock is used by default. But generic version of >> pfn_valid() is based on mem sections and memblock_next_valid_pfn() does >> not always return the next valid one but skips more resulting in some >> valid frames to be skipped (as if they were invalid). And that's why >> kernel was eventually crashing on some !arm machines. > > Hi Jia, > > Is this a bug? Should we make other arches that support memblock to > use memblock_is_map_memory() ? it is more expensive, but if the > default is broken, maybe it makes sense to change? > IIUC, the bug is in memblock_next_valid_pfn instead of pfn_valid. memblock_next_valid_pfn will return the incorrect next valid pfn on !arm arches (e.g. X86). Please refer to b92df1de5. Currently only arm/arm64 use MEMBLOCK_NOMAP, it is really beyond my power to implement it on all other arches ;-) -- Cheers, Jia
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
Can you put it into memblock.c > Do you think it looks ok if I add the inline prefix? I would say no, this function is a too complex, and is not in some critical path to be always inlined. I would put it into memblock.c, and have #ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID around it. Thank you, Pavel
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
Can you put it into memblock.c > Do you think it looks ok if I add the inline prefix? I would say no, this function is a too complex, and is not in some critical path to be always inlined. I would put it into memblock.c, and have #ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID around it. Thank you, Pavel
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
Hi, Pavel Thanks for the comments. On 6/30/2018 2:13 AM, Pavel Tatashin Wrote: >> +++ b/include/linux/early_pfn.h >> @@ -0,0 +1,34 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +/* Copyright (C) 2018 HXT-semitech Corp. */ >> +#ifndef __EARLY_PFN_H >> +#define __EARLY_PFN_H >> +#ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID >> +ulong __init_memblock memblock_next_valid_pfn(ulong pfn) >> +{ >> + struct memblock_type *type = > > Why put it in a header file and not in some C file? In my opinion it > is confusing to have non-line functions in header files. Basically, > you can include this header file in exactly one C file without > breaking compilation. > My original intent is to make this helper memblock_next_valid_pfn a common api between arm64 and arm arches since both arches will use enable CONFIG_HAVE_MEMBLOCK_PFN_VALID by default. Do you think it looks ok if I add the inline prefix? -- Cheers, Jia
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
Hi, Pavel Thanks for the comments. On 6/30/2018 2:13 AM, Pavel Tatashin Wrote: >> +++ b/include/linux/early_pfn.h >> @@ -0,0 +1,34 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +/* Copyright (C) 2018 HXT-semitech Corp. */ >> +#ifndef __EARLY_PFN_H >> +#define __EARLY_PFN_H >> +#ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID >> +ulong __init_memblock memblock_next_valid_pfn(ulong pfn) >> +{ >> + struct memblock_type *type = > > Why put it in a header file and not in some C file? In my opinion it > is confusing to have non-line functions in header files. Basically, > you can include this header file in exactly one C file without > breaking compilation. > My original intent is to make this helper memblock_next_valid_pfn a common api between arm64 and arm arches since both arches will use enable CONFIG_HAVE_MEMBLOCK_PFN_VALID by default. Do you think it looks ok if I add the inline prefix? -- Cheers, Jia
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
On Fri 29-06-18 14:13:08, Pavel Tatashin wrote: > > +++ b/include/linux/early_pfn.h > > @@ -0,0 +1,34 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 HXT-semitech Corp. */ > > +#ifndef __EARLY_PFN_H > > +#define __EARLY_PFN_H > > +#ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID > > +ulong __init_memblock memblock_next_valid_pfn(ulong pfn) > > +{ > > + struct memblock_type *type = > > Why put it in a header file and not in some C file? In my opinion it > is confusing to have non-line functions in header files. Basically, > you can include this header file in exactly one C file without > breaking compilation. It is not confusing. It is outright broken. -- Michal Hocko SUSE Labs
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
On Fri 29-06-18 14:13:08, Pavel Tatashin wrote: > > +++ b/include/linux/early_pfn.h > > @@ -0,0 +1,34 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 HXT-semitech Corp. */ > > +#ifndef __EARLY_PFN_H > > +#define __EARLY_PFN_H > > +#ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID > > +ulong __init_memblock memblock_next_valid_pfn(ulong pfn) > > +{ > > + struct memblock_type *type = > > Why put it in a header file and not in some C file? In my opinion it > is confusing to have non-line functions in header files. Basically, > you can include this header file in exactly one C file without > breaking compilation. It is not confusing. It is outright broken. -- Michal Hocko SUSE Labs
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
> +++ b/include/linux/early_pfn.h > @@ -0,0 +1,34 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright (C) 2018 HXT-semitech Corp. */ > +#ifndef __EARLY_PFN_H > +#define __EARLY_PFN_H > +#ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID > +ulong __init_memblock memblock_next_valid_pfn(ulong pfn) > +{ > + struct memblock_type *type = Why put it in a header file and not in some C file? In my opinion it is confusing to have non-line functions in header files. Basically, you can include this header file in exactly one C file without breaking compilation.
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
> +++ b/include/linux/early_pfn.h > @@ -0,0 +1,34 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright (C) 2018 HXT-semitech Corp. */ > +#ifndef __EARLY_PFN_H > +#define __EARLY_PFN_H > +#ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID > +ulong __init_memblock memblock_next_valid_pfn(ulong pfn) > +{ > + struct memblock_type *type = Why put it in a header file and not in some C file? In my opinion it is confusing to have non-line functions in header files. Basically, you can include this header file in exactly one C file without breaking compilation.
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
On Thu, Jun 28, 2018 at 10:30 PM Jia He wrote: > > Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns > where possible") optimized the loop in memmap_init_zone(). But it causes > possible panic bug. So Daniel Vacek reverted it later. > > But as suggested by Daniel Vacek, it is fine to using memblock to skip > gaps and finding next valid frame with CONFIG_HAVE_ARCH_PFN_VALID. > > On arm and arm64, memblock is used by default. But generic version of > pfn_valid() is based on mem sections and memblock_next_valid_pfn() does > not always return the next valid one but skips more resulting in some > valid frames to be skipped (as if they were invalid). And that's why > kernel was eventually crashing on some !arm machines. Hi Jia, Is this a bug? Should we make other arches that support memblock to use memblock_is_map_memory() ? it is more expensive, but if the default is broken, maybe it makes sense to change? Thank you, Pavel
Re: [PATCH v9 2/6] mm: page_alloc: remain memblock_next_valid_pfn() on arm/arm64
On Thu, Jun 28, 2018 at 10:30 PM Jia He wrote: > > Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns > where possible") optimized the loop in memmap_init_zone(). But it causes > possible panic bug. So Daniel Vacek reverted it later. > > But as suggested by Daniel Vacek, it is fine to using memblock to skip > gaps and finding next valid frame with CONFIG_HAVE_ARCH_PFN_VALID. > > On arm and arm64, memblock is used by default. But generic version of > pfn_valid() is based on mem sections and memblock_next_valid_pfn() does > not always return the next valid one but skips more resulting in some > valid frames to be skipped (as if they were invalid). And that's why > kernel was eventually crashing on some !arm machines. Hi Jia, Is this a bug? Should we make other arches that support memblock to use memblock_is_map_memory() ? it is more expensive, but if the default is broken, maybe it makes sense to change? Thank you, Pavel