2020-12-08 04:23:18

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

This overrides arch_get_mappabble_range() on s390 platform which will be
used with recently added generic framework. It drops a redundant similar
check in vmem_add_mapping() while compensating __segment_load() with a new
address range check to preserve the existing functionality. It also adds a
VM_BUG_ON() check that would ensure that memhp_range_allowed() has already
been called on the hotplug path.

Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
---
arch/s390/mm/extmem.c | 5 +++++
arch/s390/mm/init.c | 10 ++++++++++
arch/s390/mm/vmem.c | 4 ----
3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
index 5060956b8e7d..cc055a78f7b6 100644
--- a/arch/s390/mm/extmem.c
+++ b/arch/s390/mm/extmem.c
@@ -337,6 +337,11 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
goto out_free_resource;
}

+ if (seg->end + 1 > VMEM_MAX_PHYS || seg->end + 1 < seg->start_addr) {
+ rc = -ERANGE;
+ goto out_resource;
+ }
+
rc = vmem_add_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
if (rc)
goto out_resource;
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 77767850d0d0..64937baabf93 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -278,6 +278,15 @@ device_initcall(s390_cma_mem_init);

#endif /* CONFIG_CMA */

+struct range arch_get_mappable_range(void)
+{
+ struct range memhp_range;
+
+ memhp_range.start = 0;
+ memhp_range.end = VMEM_MAX_PHYS;
+ return memhp_range;
+}
+
int arch_add_memory(int nid, u64 start, u64 size,
struct mhp_params *params)
{
@@ -291,6 +300,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
return -EINVAL;

+ VM_BUG_ON(!memhp_range_allowed(start, size, 1));
rc = vmem_add_mapping(start, size);
if (rc)
return rc;
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index b239f2ba93b0..749eab43aa93 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -536,10 +536,6 @@ int vmem_add_mapping(unsigned long start, unsigned long size)
{
int ret;

- if (start + size > VMEM_MAX_PHYS ||
- start + size < start)
- return -ERANGE;
-
mutex_lock(&vmem_mutex);
ret = vmem_add_range(start, size);
if (ret)
--
2.20.1


2020-12-08 15:31:01

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

On Tue, Dec 08, 2020 at 09:46:18AM +0530, Anshuman Khandual wrote:
> This overrides arch_get_mappabble_range() on s390 platform which will be
> used with recently added generic framework. It drops a redundant similar
> check in vmem_add_mapping() while compensating __segment_load() with a new
> address range check to preserve the existing functionality. It also adds a
> VM_BUG_ON() check that would ensure that memhp_range_allowed() has already
> been called on the hotplug path.
>
> Cc: Heiko Carstens <[email protected]>
> Cc: Vasily Gorbik <[email protected]>
> Cc: David Hildenbrand <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Anshuman Khandual <[email protected]>
> ---
> arch/s390/mm/extmem.c | 5 +++++
> arch/s390/mm/init.c | 10 ++++++++++
> arch/s390/mm/vmem.c | 4 ----
> 3 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
> index 5060956b8e7d..cc055a78f7b6 100644
> --- a/arch/s390/mm/extmem.c
> +++ b/arch/s390/mm/extmem.c
> @@ -337,6 +337,11 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
> goto out_free_resource;
> }
>
> + if (seg->end + 1 > VMEM_MAX_PHYS || seg->end + 1 < seg->start_addr) {
> + rc = -ERANGE;
> + goto out_resource;
> + }
> +
> rc = vmem_add_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
> if (rc)
> goto out_resource;
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 77767850d0d0..64937baabf93 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -278,6 +278,15 @@ device_initcall(s390_cma_mem_init);
>
> #endif /* CONFIG_CMA */
>
> +struct range arch_get_mappable_range(void)
> +{
> + struct range memhp_range;
> +
> + memhp_range.start = 0;
> + memhp_range.end = VMEM_MAX_PHYS;
> + return memhp_range;
> +}
> +
> int arch_add_memory(int nid, u64 start, u64 size,
> struct mhp_params *params)
> {
> @@ -291,6 +300,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
> return -EINVAL;
>
> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
> rc = vmem_add_mapping(start, size);
> if (rc)
> return rc;
> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
> index b239f2ba93b0..749eab43aa93 100644
> --- a/arch/s390/mm/vmem.c
> +++ b/arch/s390/mm/vmem.c
> @@ -536,10 +536,6 @@ int vmem_add_mapping(unsigned long start, unsigned long size)
> {
> int ret;
>
> - if (start + size > VMEM_MAX_PHYS ||
> - start + size < start)
> - return -ERANGE;
> -

Is there a reason why you added the memhp_range_allowed() check call
to arch_add_memory() instead of vmem_add_mapping()? If you would do
that, then the extra code in __segment_load() wouldn't be
required.
Even though the error message from memhp_range_allowed() might be
highly confusing.

2020-12-09 03:37:09

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()



On 12/8/20 8:57 PM, Heiko Carstens wrote:
> On Tue, Dec 08, 2020 at 09:46:18AM +0530, Anshuman Khandual wrote:
>> This overrides arch_get_mappabble_range() on s390 platform which will be
>> used with recently added generic framework. It drops a redundant similar
>> check in vmem_add_mapping() while compensating __segment_load() with a new
>> address range check to preserve the existing functionality. It also adds a
>> VM_BUG_ON() check that would ensure that memhp_range_allowed() has already
>> been called on the hotplug path.
>>
>> Cc: Heiko Carstens <[email protected]>
>> Cc: Vasily Gorbik <[email protected]>
>> Cc: David Hildenbrand <[email protected]>
>> Cc: [email protected]
>> Cc: [email protected]
>> Signed-off-by: Anshuman Khandual <[email protected]>
>> ---
>> arch/s390/mm/extmem.c | 5 +++++
>> arch/s390/mm/init.c | 10 ++++++++++
>> arch/s390/mm/vmem.c | 4 ----
>> 3 files changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
>> index 5060956b8e7d..cc055a78f7b6 100644
>> --- a/arch/s390/mm/extmem.c
>> +++ b/arch/s390/mm/extmem.c
>> @@ -337,6 +337,11 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
>> goto out_free_resource;
>> }
>>
>> + if (seg->end + 1 > VMEM_MAX_PHYS || seg->end + 1 < seg->start_addr) {
>> + rc = -ERANGE;
>> + goto out_resource;
>> + }
>> +
>> rc = vmem_add_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
>> if (rc)
>> goto out_resource;
>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>> index 77767850d0d0..64937baabf93 100644
>> --- a/arch/s390/mm/init.c
>> +++ b/arch/s390/mm/init.c
>> @@ -278,6 +278,15 @@ device_initcall(s390_cma_mem_init);
>>
>> #endif /* CONFIG_CMA */
>>
>> +struct range arch_get_mappable_range(void)
>> +{
>> + struct range memhp_range;
>> +
>> + memhp_range.start = 0;
>> + memhp_range.end = VMEM_MAX_PHYS;
>> + return memhp_range;
>> +}
>> +
>> int arch_add_memory(int nid, u64 start, u64 size,
>> struct mhp_params *params)
>> {
>> @@ -291,6 +300,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>> return -EINVAL;
>>
>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>> rc = vmem_add_mapping(start, size);
>> if (rc)
>> return rc;
>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>> index b239f2ba93b0..749eab43aa93 100644
>> --- a/arch/s390/mm/vmem.c
>> +++ b/arch/s390/mm/vmem.c
>> @@ -536,10 +536,6 @@ int vmem_add_mapping(unsigned long start, unsigned long size)
>> {
>> int ret;
>>
>> - if (start + size > VMEM_MAX_PHYS ||
>> - start + size < start)
>> - return -ERANGE;
>> -
>
> Is there a reason why you added the memhp_range_allowed() check call
> to arch_add_memory() instead of vmem_add_mapping()? If you would do

As I had mentioned previously, memhp_range_allowed() is available with
CONFIG_MEMORY_HOTPLUG but vmem_add_mapping() is always available. Hence
there will be a build failure in vmem_add_mapping() for the range check
memhp_range_allowed() without memory hotplug enabled.

> that, then the extra code in __segment_load() wouldn't be
> required.
> Even though the error message from memhp_range_allowed() might be
> highly confusing.
Alternatively leaving __segment_load() and vmem_add_memory() unchanged
will create three range checks i.e two memhp_range_allowed() and the
existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
paths, which is not optimal.

2020-12-10 01:43:45

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

On Wed, Dec 09, 2020 at 08:07:04AM +0530, Anshuman Khandual wrote:
> >> + if (seg->end + 1 > VMEM_MAX_PHYS || seg->end + 1 < seg->start_addr) {
> >> + rc = -ERANGE;
> >> + goto out_resource;
> >> + }
> >> +
...
> >> +struct range arch_get_mappable_range(void)
> >> +{
> >> + struct range memhp_range;
> >> +
> >> + memhp_range.start = 0;
> >> + memhp_range.end = VMEM_MAX_PHYS;
> >> + return memhp_range;
> >> +}
> >> +
> >> int arch_add_memory(int nid, u64 start, u64 size,
> >> struct mhp_params *params)
> >> {
> >> @@ -291,6 +300,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
> >> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
> >> return -EINVAL;
> >>
> >> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
> >> rc = vmem_add_mapping(start, size);
> >> if (rc)
> > Is there a reason why you added the memhp_range_allowed() check call
> > to arch_add_memory() instead of vmem_add_mapping()? If you would do
>
> As I had mentioned previously, memhp_range_allowed() is available with
> CONFIG_MEMORY_HOTPLUG but vmem_add_mapping() is always available. Hence
> there will be a build failure in vmem_add_mapping() for the range check
> memhp_range_allowed() without memory hotplug enabled.
>
> > that, then the extra code in __segment_load() wouldn't be
> > required.
> > Even though the error message from memhp_range_allowed() might be
> > highly confusing.
>
> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
> will create three range checks i.e two memhp_range_allowed() and the
> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
> paths, which is not optimal.

Ah, sorry. I didn't follow this discussion too closely. I just thought
my point of view would be clear: let's not have two different ways to
check for the same thing which must be kept in sync.
Therefore I was wondering why this next version is still doing
that. Please find a way to solve this.

2020-12-10 07:41:01

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()


> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>
> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>> paths, which is not optimal.
>>>
>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>> my point of view would be clear: let's not have two different ways to
>>> check for the same thing which must be kept in sync.
>>> Therefore I was wondering why this next version is still doing
>>> that. Please find a way to solve this.
>>
>> The following change is after the current series and should work with
>> and without memory hotplug enabled. There will be just a single place
>> i.e vmem_get_max_addr() to update in case the maximum address changes
>> from VMEM_MAX_PHYS to something else later.
>
> Still not. That's way too much code churn for what you want to achieve.
> If the s390 specific patch would look like below you can add
>
> Acked-by: Heiko Carstens <[email protected]>
>
> But please make sure that the arch_get_mappable_range() prototype in
> linux/memory_hotplug.h is always visible and does not depend on
> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
> because of this.
>
> Thanks.
>
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 77767850d0d0..e0e78234ae57 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
> return -EINVAL;
>
> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
> rc = vmem_add_mapping(start, size);
> if (rc)
> return rc;
> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
> index b239f2ba93b0..ccd55e2f97f9 100644
> --- a/arch/s390/mm/vmem.c
> +++ b/arch/s390/mm/vmem.c
> @@ -4,6 +4,7 @@
> * Author(s): Heiko Carstens <[email protected]>
> */
>
> +#include <linux/memory_hotplug.h>
> #include <linux/memblock.h>
> #include <linux/pfn.h>
> #include <linux/mm.h>
> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
> mutex_unlock(&vmem_mutex);
> }
>
> +struct range arch_get_mappable_range(void)
> +{
> + struct range range;
> +
> + range.start = 0;
> + range.end = VMEM_MAX_PHYS;
> + return range;
> +}
> +
> int vmem_add_mapping(unsigned long start, unsigned long size)
> {
> + struct range range;
> int ret;
>
> - if (start + size > VMEM_MAX_PHYS ||
> + range = arch_get_mappable_range();
> + if (start < range.start ||
> + start + size > range.end ||
> start + size < start)
> return -ERANGE;
>
>

Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).

2020-12-10 07:48:33

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()



On 12/10/20 12:34 PM, David Hildenbrand wrote:
>
>> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>>
>> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>>> paths, which is not optimal.
>>>>
>>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>>> my point of view would be clear: let's not have two different ways to
>>>> check for the same thing which must be kept in sync.
>>>> Therefore I was wondering why this next version is still doing
>>>> that. Please find a way to solve this.
>>>
>>> The following change is after the current series and should work with
>>> and without memory hotplug enabled. There will be just a single place
>>> i.e vmem_get_max_addr() to update in case the maximum address changes
>>> from VMEM_MAX_PHYS to something else later.
>>
>> Still not. That's way too much code churn for what you want to achieve.
>> If the s390 specific patch would look like below you can add
>>
>> Acked-by: Heiko Carstens <[email protected]>
>>
>> But please make sure that the arch_get_mappable_range() prototype in
>> linux/memory_hotplug.h is always visible and does not depend on
>> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
>> because of this.
>>
>> Thanks.
>>
>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>> index 77767850d0d0..e0e78234ae57 100644
>> --- a/arch/s390/mm/init.c
>> +++ b/arch/s390/mm/init.c
>> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>> return -EINVAL;
>>
>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>> rc = vmem_add_mapping(start, size);
>> if (rc)
>> return rc;
>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>> index b239f2ba93b0..ccd55e2f97f9 100644
>> --- a/arch/s390/mm/vmem.c
>> +++ b/arch/s390/mm/vmem.c
>> @@ -4,6 +4,7 @@
>> * Author(s): Heiko Carstens <[email protected]>
>> */
>>
>> +#include <linux/memory_hotplug.h>
>> #include <linux/memblock.h>
>> #include <linux/pfn.h>
>> #include <linux/mm.h>
>> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
>> mutex_unlock(&vmem_mutex);
>> }
>>
>> +struct range arch_get_mappable_range(void)
>> +{
>> + struct range range;
>> +
>> + range.start = 0;
>> + range.end = VMEM_MAX_PHYS;
>> + return range;
>> +}
>> +
>> int vmem_add_mapping(unsigned long start, unsigned long size)
>> {
>> + struct range range;
>> int ret;
>>
>> - if (start + size > VMEM_MAX_PHYS ||
>> + range = arch_get_mappable_range();
>> + if (start < range.start ||
>> + start + size > range.end ||
>> start + size < start)
>> return -ERANGE;
>>
>>
>
> Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).
Didn't quite understand "Not sure if we really need new checks in common code".
Could you please be more specific. New checks as in pagemap_range() ? Because
other places it is either replacing erstwhile check_hotplug_memory_addressable()
or just moving existing checks from platform arch_add_memory() to the beginning
of various hotplug paths.

2020-12-10 08:09:41

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

On 10.12.20 08:40, Anshuman Khandual wrote:
>
>
> On 12/10/20 12:34 PM, David Hildenbrand wrote:
>>
>>> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>>>
>>> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>>>> paths, which is not optimal.
>>>>>
>>>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>>>> my point of view would be clear: let's not have two different ways to
>>>>> check for the same thing which must be kept in sync.
>>>>> Therefore I was wondering why this next version is still doing
>>>>> that. Please find a way to solve this.
>>>>
>>>> The following change is after the current series and should work with
>>>> and without memory hotplug enabled. There will be just a single place
>>>> i.e vmem_get_max_addr() to update in case the maximum address changes
>>>> from VMEM_MAX_PHYS to something else later.
>>>
>>> Still not. That's way too much code churn for what you want to achieve.
>>> If the s390 specific patch would look like below you can add
>>>
>>> Acked-by: Heiko Carstens <[email protected]>
>>>
>>> But please make sure that the arch_get_mappable_range() prototype in
>>> linux/memory_hotplug.h is always visible and does not depend on
>>> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
>>> because of this.
>>>
>>> Thanks.
>>>
>>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>>> index 77767850d0d0..e0e78234ae57 100644
>>> --- a/arch/s390/mm/init.c
>>> +++ b/arch/s390/mm/init.c
>>> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>>> return -EINVAL;
>>>
>>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>>> rc = vmem_add_mapping(start, size);
>>> if (rc)
>>> return rc;
>>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>>> index b239f2ba93b0..ccd55e2f97f9 100644
>>> --- a/arch/s390/mm/vmem.c
>>> +++ b/arch/s390/mm/vmem.c
>>> @@ -4,6 +4,7 @@
>>> * Author(s): Heiko Carstens <[email protected]>
>>> */
>>>
>>> +#include <linux/memory_hotplug.h>
>>> #include <linux/memblock.h>
>>> #include <linux/pfn.h>
>>> #include <linux/mm.h>
>>> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
>>> mutex_unlock(&vmem_mutex);
>>> }
>>>
>>> +struct range arch_get_mappable_range(void)
>>> +{
>>> + struct range range;
>>> +
>>> + range.start = 0;
>>> + range.end = VMEM_MAX_PHYS;
>>> + return range;
>>> +}
>>> +
>>> int vmem_add_mapping(unsigned long start, unsigned long size)
>>> {
>>> + struct range range;
>>> int ret;
>>>
>>> - if (start + size > VMEM_MAX_PHYS ||
>>> + range = arch_get_mappable_range();
>>> + if (start < range.start ||
>>> + start + size > range.end ||
>>> start + size < start)
>>> return -ERANGE;
>>>
>>>
>>
>> Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).
> Didn't quite understand "Not sure if we really need new checks in common code".
> Could you please be more specific. New checks as in pagemap_range() ? Because
> other places it is either replacing erstwhile check_hotplug_memory_addressable()
> or just moving existing checks from platform arch_add_memory() to the beginning
> of various hotplug paths.

The main concern I have with current code is that it makes it impossible
for some driver to detect which ranges it could actually later hotplug.
You cannot warn about a strange setup before you actually run into the
issues while trying to add memory. Like returning "-EINVAL" from a
function but not exposing which values are actually valid.

If we have memhp_get_pluggable_range(), we have such a mechanism and

1. Trying to add out-of-range memory will fail (although deep down in
arch code, but at least it fails).

2. There is a way for drivers to find out which values are actually
valid before triggering 1.

For my use case that's good enough. Do you have others in mind that
require new checks in common code (meaning inside add_memory() and friends)?

--
Thanks,

David / dhildenb

2020-12-10 09:03:59

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()



On 12/10/20 1:32 PM, David Hildenbrand wrote:
> On 10.12.20 08:40, Anshuman Khandual wrote:
>>
>>
>> On 12/10/20 12:34 PM, David Hildenbrand wrote:
>>>
>>>> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>>>>
>>>> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>>>>> paths, which is not optimal.
>>>>>>
>>>>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>>>>> my point of view would be clear: let's not have two different ways to
>>>>>> check for the same thing which must be kept in sync.
>>>>>> Therefore I was wondering why this next version is still doing
>>>>>> that. Please find a way to solve this.
>>>>>
>>>>> The following change is after the current series and should work with
>>>>> and without memory hotplug enabled. There will be just a single place
>>>>> i.e vmem_get_max_addr() to update in case the maximum address changes
>>>>> from VMEM_MAX_PHYS to something else later.
>>>>
>>>> Still not. That's way too much code churn for what you want to achieve.
>>>> If the s390 specific patch would look like below you can add
>>>>
>>>> Acked-by: Heiko Carstens <[email protected]>
>>>>
>>>> But please make sure that the arch_get_mappable_range() prototype in
>>>> linux/memory_hotplug.h is always visible and does not depend on
>>>> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
>>>> because of this.
>>>>
>>>> Thanks.
>>>>
>>>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>>>> index 77767850d0d0..e0e78234ae57 100644
>>>> --- a/arch/s390/mm/init.c
>>>> +++ b/arch/s390/mm/init.c
>>>> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>>>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>>>> return -EINVAL;
>>>>
>>>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>>>> rc = vmem_add_mapping(start, size);
>>>> if (rc)
>>>> return rc;
>>>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>>>> index b239f2ba93b0..ccd55e2f97f9 100644
>>>> --- a/arch/s390/mm/vmem.c
>>>> +++ b/arch/s390/mm/vmem.c
>>>> @@ -4,6 +4,7 @@
>>>> * Author(s): Heiko Carstens <[email protected]>
>>>> */
>>>>
>>>> +#include <linux/memory_hotplug.h>
>>>> #include <linux/memblock.h>
>>>> #include <linux/pfn.h>
>>>> #include <linux/mm.h>
>>>> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
>>>> mutex_unlock(&vmem_mutex);
>>>> }
>>>>
>>>> +struct range arch_get_mappable_range(void)
>>>> +{
>>>> + struct range range;
>>>> +
>>>> + range.start = 0;
>>>> + range.end = VMEM_MAX_PHYS;
>>>> + return range;
>>>> +}
>>>> +
>>>> int vmem_add_mapping(unsigned long start, unsigned long size)
>>>> {
>>>> + struct range range;
>>>> int ret;
>>>>
>>>> - if (start + size > VMEM_MAX_PHYS ||
>>>> + range = arch_get_mappable_range();
>>>> + if (start < range.start ||
>>>> + start + size > range.end ||
>>>> start + size < start)
>>>> return -ERANGE;
>>>>
>>>>
>>>
>>> Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).
>> Didn't quite understand "Not sure if we really need new checks in common code".
>> Could you please be more specific. New checks as in pagemap_range() ? Because
>> other places it is either replacing erstwhile check_hotplug_memory_addressable()
>> or just moving existing checks from platform arch_add_memory() to the beginning
>> of various hotplug paths.
>
> The main concern I have with current code is that it makes it impossible
> for some driver to detect which ranges it could actually later hotplug.
> You cannot warn about a strange setup before you actually run into the
> issues while trying to add memory. Like returning "-EINVAL" from a
> function but not exposing which values are actually valid.
>
> If we have memhp_get_pluggable_range(), we have such a mechanism and
>
> 1. Trying to add out-of-range memory will fail (although deep down in
> arch code, but at least it fails).
>
> 2. There is a way for drivers to find out which values are actually
> valid before triggering 1.

Right, that is an important use case from a driver perspective as it
helps validate the range being attempted for hotplug, before failing.
But then memhp_range_allowed() also uses the same mechanism i.e
memhp_get_pluggable_range() to unify

1. Generic check_hotplug_memory_addressable()
2. Platform checks in arch_add_memory()

This unified function can be called just at the beginning of memory
hotplug so that both (1) and (2) can be dropped all together. This
is just a logical extension which does improve the memory hotplug
implementation (in itself) by failing earlier and while at it, also
unifying generic and platform specific range constraints. Both the
use cases are orthogonal IMHO.

>
> For my use case that's good enough. Do you have others in mind that
> require new checks in common code (meaning inside add_memory() and friends)?

2020-12-10 09:46:17

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

On 10.12.20 09:58, Anshuman Khandual wrote:
>
>
> On 12/10/20 1:32 PM, David Hildenbrand wrote:
>> On 10.12.20 08:40, Anshuman Khandual wrote:
>>>
>>>
>>> On 12/10/20 12:34 PM, David Hildenbrand wrote:
>>>>
>>>>> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>>>>>
>>>>> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>>>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>>>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>>>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>>>>>> paths, which is not optimal.
>>>>>>>
>>>>>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>>>>>> my point of view would be clear: let's not have two different ways to
>>>>>>> check for the same thing which must be kept in sync.
>>>>>>> Therefore I was wondering why this next version is still doing
>>>>>>> that. Please find a way to solve this.
>>>>>>
>>>>>> The following change is after the current series and should work with
>>>>>> and without memory hotplug enabled. There will be just a single place
>>>>>> i.e vmem_get_max_addr() to update in case the maximum address changes
>>>>>> from VMEM_MAX_PHYS to something else later.
>>>>>
>>>>> Still not. That's way too much code churn for what you want to achieve.
>>>>> If the s390 specific patch would look like below you can add
>>>>>
>>>>> Acked-by: Heiko Carstens <[email protected]>
>>>>>
>>>>> But please make sure that the arch_get_mappable_range() prototype in
>>>>> linux/memory_hotplug.h is always visible and does not depend on
>>>>> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
>>>>> because of this.
>>>>>
>>>>> Thanks.
>>>>>
>>>>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>>>>> index 77767850d0d0..e0e78234ae57 100644
>>>>> --- a/arch/s390/mm/init.c
>>>>> +++ b/arch/s390/mm/init.c
>>>>> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>>>>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>>>>> return -EINVAL;
>>>>>
>>>>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>>>>> rc = vmem_add_mapping(start, size);
>>>>> if (rc)
>>>>> return rc;
>>>>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>>>>> index b239f2ba93b0..ccd55e2f97f9 100644
>>>>> --- a/arch/s390/mm/vmem.c
>>>>> +++ b/arch/s390/mm/vmem.c
>>>>> @@ -4,6 +4,7 @@
>>>>> * Author(s): Heiko Carstens <[email protected]>
>>>>> */
>>>>>
>>>>> +#include <linux/memory_hotplug.h>
>>>>> #include <linux/memblock.h>
>>>>> #include <linux/pfn.h>
>>>>> #include <linux/mm.h>
>>>>> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
>>>>> mutex_unlock(&vmem_mutex);
>>>>> }
>>>>>
>>>>> +struct range arch_get_mappable_range(void)
>>>>> +{
>>>>> + struct range range;
>>>>> +
>>>>> + range.start = 0;
>>>>> + range.end = VMEM_MAX_PHYS;
>>>>> + return range;
>>>>> +}
>>>>> +
>>>>> int vmem_add_mapping(unsigned long start, unsigned long size)
>>>>> {
>>>>> + struct range range;
>>>>> int ret;
>>>>>
>>>>> - if (start + size > VMEM_MAX_PHYS ||
>>>>> + range = arch_get_mappable_range();
>>>>> + if (start < range.start ||
>>>>> + start + size > range.end ||
>>>>> start + size < start)
>>>>> return -ERANGE;
>>>>>
>>>>>
>>>>
>>>> Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).
>>> Didn't quite understand "Not sure if we really need new checks in common code".
>>> Could you please be more specific. New checks as in pagemap_range() ? Because
>>> other places it is either replacing erstwhile check_hotplug_memory_addressable()
>>> or just moving existing checks from platform arch_add_memory() to the beginning
>>> of various hotplug paths.
>>
>> The main concern I have with current code is that it makes it impossible
>> for some driver to detect which ranges it could actually later hotplug.
>> You cannot warn about a strange setup before you actually run into the
>> issues while trying to add memory. Like returning "-EINVAL" from a
>> function but not exposing which values are actually valid.
>>
>> If we have memhp_get_pluggable_range(), we have such a mechanism and
>>
>> 1. Trying to add out-of-range memory will fail (although deep down in
>> arch code, but at least it fails).
>>
>> 2. There is a way for drivers to find out which values are actually
>> valid before triggering 1.
>
> Right, that is an important use case from a driver perspective as it
> helps validate the range being attempted for hotplug, before failing.
> But then memhp_range_allowed() also uses the same mechanism i.e
> memhp_get_pluggable_range() to unify
>
> 1. Generic check_hotplug_memory_addressable()
> 2. Platform checks in arch_add_memory()
>
> This unified function can be called just at the beginning of memory
> hotplug so that both (1) and (2) can be dropped all together. This
> is just a logical extension which does improve the memory hotplug
> implementation (in itself) by failing earlier and while at it, also
> unifying generic and platform specific range constraints. Both the
> use cases are orthogonal IMHO.

As longs as it simplifies the code sure. But at least in the s390x case,
we cannot get rid of the internal checks.

--
Thanks,

David / dhildenb

2020-12-10 23:00:43

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()



On 12/9/20 8:27 PM, Heiko Carstens wrote:
> On Wed, Dec 09, 2020 at 08:07:04AM +0530, Anshuman Khandual wrote:
>>>> + if (seg->end + 1 > VMEM_MAX_PHYS || seg->end + 1 < seg->start_addr) {
>>>> + rc = -ERANGE;
>>>> + goto out_resource;
>>>> + }
>>>> +
> ...
>>>> +struct range arch_get_mappable_range(void)
>>>> +{
>>>> + struct range memhp_range;
>>>> +
>>>> + memhp_range.start = 0;
>>>> + memhp_range.end = VMEM_MAX_PHYS;
>>>> + return memhp_range;
>>>> +}
>>>> +
>>>> int arch_add_memory(int nid, u64 start, u64 size,
>>>> struct mhp_params *params)
>>>> {
>>>> @@ -291,6 +300,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>>>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>>>> return -EINVAL;
>>>>
>>>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>>>> rc = vmem_add_mapping(start, size);
>>>> if (rc)
>>> Is there a reason why you added the memhp_range_allowed() check call
>>> to arch_add_memory() instead of vmem_add_mapping()? If you would do
>>
>> As I had mentioned previously, memhp_range_allowed() is available with
>> CONFIG_MEMORY_HOTPLUG but vmem_add_mapping() is always available. Hence
>> there will be a build failure in vmem_add_mapping() for the range check
>> memhp_range_allowed() without memory hotplug enabled.
>>
>>> that, then the extra code in __segment_load() wouldn't be
>>> required.
>>> Even though the error message from memhp_range_allowed() might be
>>> highly confusing.
>>
>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>> will create three range checks i.e two memhp_range_allowed() and the
>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>> paths, which is not optimal.
>
> Ah, sorry. I didn't follow this discussion too closely. I just thought
> my point of view would be clear: let's not have two different ways to
> check for the same thing which must be kept in sync.
> Therefore I was wondering why this next version is still doing
> that. Please find a way to solve this.

The following change is after the current series and should work with
and without memory hotplug enabled. There will be just a single place
i.e vmem_get_max_addr() to update in case the maximum address changes
from VMEM_MAX_PHYS to something else later.

diff --git a/arch/s390/include/asm/sections.h b/arch/s390/include/asm/sections.h
index 0c21514..2da496f 100644
--- a/arch/s390/include/asm/sections.h
+++ b/arch/s390/include/asm/sections.h
@@ -16,6 +16,7 @@ static inline int arch_is_kernel_initmem_freed(unsigned long addr)
addr < (unsigned long)__init_end;
}

+unsigned long vmem_get_max_addr(void);
/*
* .boot.data section contains variables "shared" between the decompressor and
* the decompressed kernel. The decompressor will store values in them, and
diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
index cc055a7..1bddd6f 100644
--- a/arch/s390/mm/extmem.c
+++ b/arch/s390/mm/extmem.c
@@ -28,6 +28,7 @@
#include <asm/extmem.h>
#include <asm/cpcmd.h>
#include <asm/setup.h>
+#include <asm/sections.h>

#define DCSS_PURGESEG 0x08
#define DCSS_LOADSHRX 0x20
@@ -287,6 +288,13 @@ segment_overlaps_others (struct dcss_segment *seg)
return 0;
}

+static bool segment_outside_range(struct dcss_segment *seg)
+{
+ unsigned long max_addr = vmem_get_max_addr();
+
+ return (seg->end + 1 > max_addr || seg->end + 1 < seg->start_addr);
+}
+
/*
* real segment loading function, called from segment_load
*/
@@ -337,7 +345,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
goto out_free_resource;
}

- if (seg->end + 1 > VMEM_MAX_PHYS || seg->end + 1 < seg->start_addr) {
+ if (segment_outside_range(seg)) {
rc = -ERANGE;
goto out_resource;
}
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 64937ba..5c6ee9f 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -283,7 +283,7 @@ struct range arch_get_mappable_range(void)
struct range memhp_range;

memhp_range.start = 0;
- memhp_range.end = VMEM_MAX_PHYS;
+ memhp_range.end = vmem_get_max_addr();
return memhp_range;
}

diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index 749eab4..6044e85 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -532,6 +532,11 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
mutex_unlock(&vmem_mutex);
}

+unsigned long vmem_get_max_addr(void)
+{
+ return VMEM_MAX_PHYS;
+}
+
int vmem_add_mapping(unsigned long start, unsigned long size)
{
int ret;
--
2.7.4

2020-12-10 23:03:08

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
> >> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
> >> will create three range checks i.e two memhp_range_allowed() and the
> >> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
> >> paths, which is not optimal.
> >
> > Ah, sorry. I didn't follow this discussion too closely. I just thought
> > my point of view would be clear: let's not have two different ways to
> > check for the same thing which must be kept in sync.
> > Therefore I was wondering why this next version is still doing
> > that. Please find a way to solve this.
>
> The following change is after the current series and should work with
> and without memory hotplug enabled. There will be just a single place
> i.e vmem_get_max_addr() to update in case the maximum address changes
> from VMEM_MAX_PHYS to something else later.

Still not. That's way too much code churn for what you want to achieve.
If the s390 specific patch would look like below you can add

Acked-by: Heiko Carstens <[email protected]>

But please make sure that the arch_get_mappable_range() prototype in
linux/memory_hotplug.h is always visible and does not depend on
CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
because of this.

Thanks.

diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 77767850d0d0..e0e78234ae57 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
return -EINVAL;

+ VM_BUG_ON(!memhp_range_allowed(start, size, 1));
rc = vmem_add_mapping(start, size);
if (rc)
return rc;
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index b239f2ba93b0..ccd55e2f97f9 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -4,6 +4,7 @@
* Author(s): Heiko Carstens <[email protected]>
*/

+#include <linux/memory_hotplug.h>
#include <linux/memblock.h>
#include <linux/pfn.h>
#include <linux/mm.h>
@@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
mutex_unlock(&vmem_mutex);
}

+struct range arch_get_mappable_range(void)
+{
+ struct range range;
+
+ range.start = 0;
+ range.end = VMEM_MAX_PHYS;
+ return range;
+}
+
int vmem_add_mapping(unsigned long start, unsigned long size)
{
+ struct range range;
int ret;

- if (start + size > VMEM_MAX_PHYS ||
+ range = arch_get_mappable_range();
+ if (start < range.start ||
+ start + size > range.end ||
start + size < start)
return -ERANGE;

2020-12-17 11:47:22

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()



On 12/10/20 12:34 PM, David Hildenbrand wrote:
>
>> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>>
>> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>>> paths, which is not optimal.
>>>>
>>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>>> my point of view would be clear: let's not have two different ways to
>>>> check for the same thing which must be kept in sync.
>>>> Therefore I was wondering why this next version is still doing
>>>> that. Please find a way to solve this.
>>>
>>> The following change is after the current series and should work with
>>> and without memory hotplug enabled. There will be just a single place
>>> i.e vmem_get_max_addr() to update in case the maximum address changes
>>> from VMEM_MAX_PHYS to something else later.
>>
>> Still not. That's way too much code churn for what you want to achieve.
>> If the s390 specific patch would look like below you can add
>>
>> Acked-by: Heiko Carstens <[email protected]>
>>
>> But please make sure that the arch_get_mappable_range() prototype in
>> linux/memory_hotplug.h is always visible and does not depend on
>> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
>> because of this.
>>
>> Thanks.
>>
>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>> index 77767850d0d0..e0e78234ae57 100644
>> --- a/arch/s390/mm/init.c
>> +++ b/arch/s390/mm/init.c
>> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>> return -EINVAL;
>>
>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>> rc = vmem_add_mapping(start, size);
>> if (rc)
>> return rc;
>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>> index b239f2ba93b0..ccd55e2f97f9 100644
>> --- a/arch/s390/mm/vmem.c
>> +++ b/arch/s390/mm/vmem.c
>> @@ -4,6 +4,7 @@
>> * Author(s): Heiko Carstens <[email protected]>
>> */
>>
>> +#include <linux/memory_hotplug.h>
>> #include <linux/memblock.h>
>> #include <linux/pfn.h>
>> #include <linux/mm.h>
>> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
>> mutex_unlock(&vmem_mutex);
>> }
>>
>> +struct range arch_get_mappable_range(void)
>> +{
>> + struct range range;
>> +
>> + range.start = 0;
>> + range.end = VMEM_MAX_PHYS;
>> + return range;
>> +}
>> +
>> int vmem_add_mapping(unsigned long start, unsigned long size)
>> {
>> + struct range range;
>> int ret;
>>
>> - if (start + size > VMEM_MAX_PHYS ||
>> + range = arch_get_mappable_range();
>> + if (start < range.start ||
>> + start + size > range.end ||
>> start + size < start)
>> return -ERANGE;
>>
>>
>
> Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).

Hello David,

Quick question. Currently memhp_get_pluggable_range() is a mm/memory_hotplug.c
internal static inline function. Only memhp_range_allowed() is available via
the header include/linux/memory_hotplug.h But For memhp_get_pluggable_range()
to be visible to the drivers, it needs to get included in the header and also
be exported via EXPORT_SYMBOL_GPL() in mm/memory_hotplug.c OR just move the
entire definition as static inline into the header itself. Wondering which way
would be better ?

- Anshuman

2020-12-17 12:21:38

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 3/3] s390/mm: Define arch_get_mappable_range()

On 17.12.20 12:45, Anshuman Khandual wrote:
>
>
> On 12/10/20 12:34 PM, David Hildenbrand wrote:
>>
>>> Am 10.12.2020 um 07:58 schrieb Heiko Carstens <[email protected]>:
>>>
>>> On Thu, Dec 10, 2020 at 09:48:11AM +0530, Anshuman Khandual wrote:
>>>>>> Alternatively leaving __segment_load() and vmem_add_memory() unchanged
>>>>>> will create three range checks i.e two memhp_range_allowed() and the
>>>>>> existing VMEM_MAX_PHYS check in vmem_add_mapping() on all the hotplug
>>>>>> paths, which is not optimal.
>>>>>
>>>>> Ah, sorry. I didn't follow this discussion too closely. I just thought
>>>>> my point of view would be clear: let's not have two different ways to
>>>>> check for the same thing which must be kept in sync.
>>>>> Therefore I was wondering why this next version is still doing
>>>>> that. Please find a way to solve this.
>>>>
>>>> The following change is after the current series and should work with
>>>> and without memory hotplug enabled. There will be just a single place
>>>> i.e vmem_get_max_addr() to update in case the maximum address changes
>>>> from VMEM_MAX_PHYS to something else later.
>>>
>>> Still not. That's way too much code churn for what you want to achieve.
>>> If the s390 specific patch would look like below you can add
>>>
>>> Acked-by: Heiko Carstens <[email protected]>
>>>
>>> But please make sure that the arch_get_mappable_range() prototype in
>>> linux/memory_hotplug.h is always visible and does not depend on
>>> CONFIG_MEMORY_HOTPLUG. I'd like to avoid seeing sparse warnings
>>> because of this.
>>>
>>> Thanks.
>>>
>>> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
>>> index 77767850d0d0..e0e78234ae57 100644
>>> --- a/arch/s390/mm/init.c
>>> +++ b/arch/s390/mm/init.c
>>> @@ -291,6 +291,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
>>> if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
>>> return -EINVAL;
>>>
>>> + VM_BUG_ON(!memhp_range_allowed(start, size, 1));
>>> rc = vmem_add_mapping(start, size);
>>> if (rc)
>>> return rc;
>>> diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
>>> index b239f2ba93b0..ccd55e2f97f9 100644
>>> --- a/arch/s390/mm/vmem.c
>>> +++ b/arch/s390/mm/vmem.c
>>> @@ -4,6 +4,7 @@
>>> * Author(s): Heiko Carstens <[email protected]>
>>> */
>>>
>>> +#include <linux/memory_hotplug.h>
>>> #include <linux/memblock.h>
>>> #include <linux/pfn.h>
>>> #include <linux/mm.h>
>>> @@ -532,11 +533,23 @@ void vmem_remove_mapping(unsigned long start, unsigned long size)
>>> mutex_unlock(&vmem_mutex);
>>> }
>>>
>>> +struct range arch_get_mappable_range(void)
>>> +{
>>> + struct range range;
>>> +
>>> + range.start = 0;
>>> + range.end = VMEM_MAX_PHYS;
>>> + return range;
>>> +}
>>> +
>>> int vmem_add_mapping(unsigned long start, unsigned long size)
>>> {
>>> + struct range range;
>>> int ret;
>>>
>>> - if (start + size > VMEM_MAX_PHYS ||
>>> + range = arch_get_mappable_range();
>>> + if (start < range.start ||
>>> + start + size > range.end ||
>>> start + size < start)
>>> return -ERANGE;
>>>
>>>
>>
>> Right, what I had in mind as reply to v1. Not sure if we really need new checks in common code. Having a new memhp_get_pluggable_range() would be sufficient for my use case (virtio-mem).
>
> Hello David,
>
> Quick question. Currently memhp_get_pluggable_range() is a mm/memory_hotplug.c
> internal static inline function. Only memhp_range_allowed() is available via
> the header include/linux/memory_hotplug.h But For memhp_get_pluggable_range()
> to be visible to the drivers, it needs to get included in the header and also
> be exported via EXPORT_SYMBOL_GPL() in mm/memory_hotplug.c OR just move the
> entire definition as static inline into the header itself. Wondering which way
> would be better ?

As it's most likely not on any hot path, exporting the symbol might be
the cleanest approach.

>
> - Anshuman
>


--
Thanks,

David / dhildenb