diff mbox series

[v2,4/7] mm,memory_hotplug: Enforce struct page size to be multiple of PMD

Message ID 20210209133854.17399-5-osalvador@suse.de (mailing list archive)
State New, archived
Headers show
Series Allocate memmap from hotadded memory (per device) | expand

Commit Message

Oscar Salvador Feb. 9, 2021, 1:38 p.m. UTC
When struct page's size is not multiple of PMD, these do not get
fully populated when adding sections, hence two sections will
intersect the same the PMD. This goes against the vmemmap-per-device
premise, so reject it if that is the case.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
 mm/memory_hotplug.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

David Hildenbrand Feb. 25, 2021, 6:26 p.m. UTC | #1
On 09.02.21 14:38, Oscar Salvador wrote:
> When struct page's size is not multiple of PMD, these do not get
> fully populated when adding sections, hence two sections will
> intersect the same the PMD. This goes against the vmemmap-per-device
> premise, so reject it if that is the case.
> 
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> ---
>   mm/memory_hotplug.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 95695483a622..d3fb036d33fd 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -57,10 +57,11 @@ static __meminit int memmap_on_memory_store(const char *val,
>   					    const struct kernel_param *kp)
>   {
>   	/*
> -	 * Fail silently in case we cannot enable it due to platform constraints.
> +	 * Fail silently in case we cannot enable it due to system constraints.
>   	 * User can always check whether it is enabled or not via /sys/module.
>   	 */
> -	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE))
> +	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE) ||
> +	    (PMD_SIZE % sizeof(struct page)))
>   		return 0;
>   
>   	return param_set_bool(val, kp);
> 

Squash that into #1 - it's part of basic operation.
Oscar Salvador Feb. 26, 2021, 12:06 p.m. UTC | #2
On Thu, Feb 25, 2021 at 07:26:50PM +0100, David Hildenbrand wrote:
> Squash that into #1 - it's part of basic operation.

Ok, will do.
Oscar Salvador March 1, 2021, 10:06 a.m. UTC | #3
On Thu, Feb 25, 2021 at 07:26:50PM +0100, David Hildenbrand wrote:
> On 09.02.21 14:38, Oscar Salvador wrote:
> > When struct page's size is not multiple of PMD, these do not get
> > fully populated when adding sections, hence two sections will
> > intersect the same the PMD. This goes against the vmemmap-per-device
> > premise, so reject it if that is the case.
> > 
> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
> > ---
> >   mm/memory_hotplug.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> > index 95695483a622..d3fb036d33fd 100644
> > --- a/mm/memory_hotplug.c
> > +++ b/mm/memory_hotplug.c
> > @@ -57,10 +57,11 @@ static __meminit int memmap_on_memory_store(const char *val,
> >   					    const struct kernel_param *kp)
> >   {
> >   	/*
> > -	 * Fail silently in case we cannot enable it due to platform constraints.
> > +	 * Fail silently in case we cannot enable it due to system constraints.
> >   	 * User can always check whether it is enabled or not via /sys/module.
> >   	 */
> > -	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE))
> > +	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE) ||
> > +	    (PMD_SIZE % sizeof(struct page)))
> >   		return 0;
> >   	return param_set_bool(val, kp);
> > 
> 
> Squash that into #1 - it's part of basic operation.

Just to be sure we are on the same page.
You mean to move this patch and patch#5 into the runtime check in
mhp_supports_memmap_on_memory(), right?
David Hildenbrand March 1, 2021, 10:24 a.m. UTC | #4
On 01.03.21 11:06, Oscar Salvador wrote:
> On Thu, Feb 25, 2021 at 07:26:50PM +0100, David Hildenbrand wrote:
>> On 09.02.21 14:38, Oscar Salvador wrote:
>>> When struct page's size is not multiple of PMD, these do not get
>>> fully populated when adding sections, hence two sections will
>>> intersect the same the PMD. This goes against the vmemmap-per-device
>>> premise, so reject it if that is the case.
>>>
>>> Signed-off-by: Oscar Salvador <osalvador@suse.de>
>>> ---
>>>    mm/memory_hotplug.c | 5 +++--
>>>    1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
>>> index 95695483a622..d3fb036d33fd 100644
>>> --- a/mm/memory_hotplug.c
>>> +++ b/mm/memory_hotplug.c
>>> @@ -57,10 +57,11 @@ static __meminit int memmap_on_memory_store(const char *val,
>>>    					    const struct kernel_param *kp)
>>>    {
>>>    	/*
>>> -	 * Fail silently in case we cannot enable it due to platform constraints.
>>> +	 * Fail silently in case we cannot enable it due to system constraints.
>>>    	 * User can always check whether it is enabled or not via /sys/module.
>>>    	 */
>>> -	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE))
>>> +	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE) ||
>>> +	    (PMD_SIZE % sizeof(struct page)))
>>>    		return 0;
>>>    	return param_set_bool(val, kp);
>>>
>>
>> Squash that into #1 - it's part of basic operation.
> 
> Just to be sure we are on the same page.
> You mean to move this patch and patch#5 into the runtime check in
> mhp_supports_memmap_on_memory(), right?

Yes, then the compiler might even be able to figure out that what 
follows the check is dead code.
diff mbox series

Patch

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 95695483a622..d3fb036d33fd 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -57,10 +57,11 @@  static __meminit int memmap_on_memory_store(const char *val,
 					    const struct kernel_param *kp)
 {
 	/*
-	 * Fail silently in case we cannot enable it due to platform constraints.
+	 * Fail silently in case we cannot enable it due to system constraints.
 	 * User can always check whether it is enabled or not via /sys/module.
 	 */
-	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE))
+	if (!IS_ENABLED(CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE) ||
+	    (PMD_SIZE % sizeof(struct page)))
 		return 0;
 
 	return param_set_bool(val, kp);