All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm: export __vmalloc_node_range and use it
@ 2021-06-08 18:06 Claudio Imbrenda
  2021-06-08 18:06 ` [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range Claudio Imbrenda
  2021-06-08 18:06 ` [PATCH v2 2/2] KVM: s390: fix for hugepage vmalloc Claudio Imbrenda
  0 siblings, 2 replies; 10+ messages in thread
From: Claudio Imbrenda @ 2021-06-08 18:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: kvm, linux-s390, frankja, borntraeger, cohuck, david, linux-mm

Export __vmalloc_node_range so it can be used in modules.

Use the newly exported __vmalloc_node_range in KVM on s390 to overcome
a hardware limitation.

Claudio Imbrenda (2):
  mm/vmalloc: export __vmalloc_node_range
  KVM: s390: fix for hugepage vmalloc

 arch/s390/kvm/pv.c | 5 ++++-
 mm/vmalloc.c       | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

-- 
2.31.1


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

* [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-08 18:06 [PATCH v2 0/2] mm: export __vmalloc_node_range and use it Claudio Imbrenda
@ 2021-06-08 18:06 ` Claudio Imbrenda
  2021-06-09 15:59   ` Christoph Hellwig
  2021-06-08 18:06 ` [PATCH v2 2/2] KVM: s390: fix for hugepage vmalloc Claudio Imbrenda
  1 sibling, 1 reply; 10+ messages in thread
From: Claudio Imbrenda @ 2021-06-08 18:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: kvm, linux-s390, frankja, borntraeger, cohuck, david, linux-mm,
	Andrew Morton, Nicholas Piggin, Uladzislau Rezki,
	Catalin Marinas, Thomas Gleixner, Ingo Molnar, David Rientjes

The recent patches to add support for hugepage vmalloc mappings added a
flag for __vmalloc_node_range to allow to request small pages.
This flag is not accessible when calling vmalloc, the only option is to
call directly __vmalloc_node_range, which is not exported.

This means that a module can't vmalloc memory with small pages.

Case in point: KVM on s390x needs to vmalloc a large area, and it needs
to be mapped with small pages, because of a hardware limitation.

This patch exports __vmalloc_node_range so it can be used in modules
too.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: David Rientjes <rientjes@google.com>
---
 mm/vmalloc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index a13ac524f6ff..bd6fa160b31b 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2937,6 +2937,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(__vmalloc_node_range);
 
 /**
  * __vmalloc_node - allocate virtually contiguous memory
-- 
2.31.1


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

* [PATCH v2 2/2] KVM: s390: fix for hugepage vmalloc
  2021-06-08 18:06 [PATCH v2 0/2] mm: export __vmalloc_node_range and use it Claudio Imbrenda
  2021-06-08 18:06 ` [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range Claudio Imbrenda
@ 2021-06-08 18:06 ` Claudio Imbrenda
  2021-06-08 18:52   ` Christian Borntraeger
  1 sibling, 1 reply; 10+ messages in thread
From: Claudio Imbrenda @ 2021-06-08 18:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: kvm, linux-s390, frankja, borntraeger, cohuck, david, linux-mm,
	Andrew Morton, Nicholas Piggin, Uladzislau Rezki,
	Catalin Marinas, Thomas Gleixner, Ingo Molnar, David Rientjes

The Create Secure Configuration Ultravisor Call does not support using
large pages for the virtual memory area. This is a hardware limitation.

This patch replaces the vzalloc call with a longer but equivalent
__vmalloc_node_range call, also setting the VM_NO_HUGE_VMAP flag, to
guarantee that this allocation will not be performed with large pages.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Fixes: 121e6f3258fe393e22c3 ("mm/vmalloc: hugepage vmalloc mappings")
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: David Rientjes <rientjes@google.com>
---
 arch/s390/kvm/pv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
index 813b6e93dc83..6087fe7ae77c 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -140,7 +140,10 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)
 	/* Allocate variable storage */
 	vlen = ALIGN(virt * ((npages * PAGE_SIZE) / HPAGE_SIZE), PAGE_SIZE);
 	vlen += uv_info.guest_virt_base_stor_len;
-	kvm->arch.pv.stor_var = vzalloc(vlen);
+	kvm->arch.pv.stor_var = __vmalloc_node_range(vlen, PAGE_SIZE, VMALLOC_START, VMALLOC_END,
+						     GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL,
+						     VM_NO_HUGE_VMAP, NUMA_NO_NODE,
+						     __builtin_return_address(0));
 	if (!kvm->arch.pv.stor_var)
 		goto out_err;
 	return 0;
-- 
2.31.1


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

* Re: [PATCH v2 2/2] KVM: s390: fix for hugepage vmalloc
  2021-06-08 18:06 ` [PATCH v2 2/2] KVM: s390: fix for hugepage vmalloc Claudio Imbrenda
@ 2021-06-08 18:52   ` Christian Borntraeger
  0 siblings, 0 replies; 10+ messages in thread
From: Christian Borntraeger @ 2021-06-08 18:52 UTC (permalink / raw)
  To: Claudio Imbrenda, linux-kernel
  Cc: kvm, linux-s390, frankja, cohuck, david, linux-mm, Andrew Morton,
	Nicholas Piggin, Uladzislau Rezki, Catalin Marinas,
	Thomas Gleixner, Ingo Molnar, David Rientjes


On 08.06.21 20:06, Claudio Imbrenda wrote:
> The Create Secure Configuration Ultravisor Call does not support using
> large pages for the virtual memory area. This is a hardware limitation.
> 
> This patch replaces the vzalloc call with a longer but equivalent
> __vmalloc_node_range call, also setting the VM_NO_HUGE_VMAP flag, to
> guarantee that this allocation will not be performed with large pages.
> 
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
> Fixes: 121e6f3258fe393e22c3 ("mm/vmalloc: hugepage vmalloc mappings")
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: David Rientjes <rientjes@google.com>

Would be good to have this in 5.13, as for everything else we want to have
hugepages in vmalloc space on s390.

In case Andrew picks this up
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
for the KVM/390 part.

> ---
>   arch/s390/kvm/pv.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
> index 813b6e93dc83..6087fe7ae77c 100644
> --- a/arch/s390/kvm/pv.c
> +++ b/arch/s390/kvm/pv.c
> @@ -140,7 +140,10 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)
>   	/* Allocate variable storage */
>   	vlen = ALIGN(virt * ((npages * PAGE_SIZE) / HPAGE_SIZE), PAGE_SIZE);
>   	vlen += uv_info.guest_virt_base_stor_len;
> -	kvm->arch.pv.stor_var = vzalloc(vlen);
> +	kvm->arch.pv.stor_var = __vmalloc_node_range(vlen, PAGE_SIZE, VMALLOC_START, VMALLOC_END,
> +						     GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL,
> +						     VM_NO_HUGE_VMAP, NUMA_NO_NODE,
> +						     __builtin_return_address(0));
>   	if (!kvm->arch.pv.stor_var)
>   		goto out_err;
>   	return 0;
> 

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

* Re: [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-08 18:06 ` [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range Claudio Imbrenda
@ 2021-06-09 15:59   ` Christoph Hellwig
  2021-06-09 16:28     ` Claudio Imbrenda
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2021-06-09 15:59 UTC (permalink / raw)
  To: Claudio Imbrenda
  Cc: linux-kernel, kvm, linux-s390, frankja, borntraeger, cohuck,
	david, linux-mm, Andrew Morton, Nicholas Piggin,
	Uladzislau Rezki, Catalin Marinas, Thomas Gleixner, Ingo Molnar,
	David Rientjes

On Tue, Jun 08, 2021 at 08:06:17PM +0200, Claudio Imbrenda wrote:
> The recent patches to add support for hugepage vmalloc mappings added a
> flag for __vmalloc_node_range to allow to request small pages.
> This flag is not accessible when calling vmalloc, the only option is to
> call directly __vmalloc_node_range, which is not exported.
> 
> This means that a module can't vmalloc memory with small pages.
> 
> Case in point: KVM on s390x needs to vmalloc a large area, and it needs
> to be mapped with small pages, because of a hardware limitation.
> 
> This patch exports __vmalloc_node_range so it can be used in modules
> too.

No.  I spent a lot of effort to mak sure such a low-level API is
not exported.

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

* Re: [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-09 15:59   ` Christoph Hellwig
@ 2021-06-09 16:28     ` Claudio Imbrenda
  2021-06-09 16:49       ` Uladzislau Rezki
  2021-06-09 17:47       ` Christian Borntraeger
  0 siblings, 2 replies; 10+ messages in thread
From: Claudio Imbrenda @ 2021-06-09 16:28 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-kernel, kvm, linux-s390, frankja, borntraeger, cohuck,
	david, linux-mm, Andrew Morton, Nicholas Piggin,
	Uladzislau Rezki, Catalin Marinas, Thomas Gleixner, Ingo Molnar,
	David Rientjes

On Wed, 9 Jun 2021 16:59:17 +0100
Christoph Hellwig <hch@infradead.org> wrote:

> On Tue, Jun 08, 2021 at 08:06:17PM +0200, Claudio Imbrenda wrote:
> > The recent patches to add support for hugepage vmalloc mappings
> > added a flag for __vmalloc_node_range to allow to request small
> > pages. This flag is not accessible when calling vmalloc, the only
> > option is to call directly __vmalloc_node_range, which is not
> > exported.
> > 
> > This means that a module can't vmalloc memory with small pages.
> > 
> > Case in point: KVM on s390x needs to vmalloc a large area, and it
> > needs to be mapped with small pages, because of a hardware
> > limitation.
> > 
> > This patch exports __vmalloc_node_range so it can be used in modules
> > too.  
> 
> No.  I spent a lot of effort to mak sure such a low-level API is
> not exported.

ok, but then how can we vmalloc memory with small pages from KVM?

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

* Re: [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-09 16:28     ` Claudio Imbrenda
@ 2021-06-09 16:49       ` Uladzislau Rezki
  2021-06-09 17:50         ` Christian Borntraeger
  2021-06-09 17:47       ` Christian Borntraeger
  1 sibling, 1 reply; 10+ messages in thread
From: Uladzislau Rezki @ 2021-06-09 16:49 UTC (permalink / raw)
  To: Claudio Imbrenda
  Cc: Christoph Hellwig, linux-kernel, kvm, linux-s390, frankja,
	borntraeger, cohuck, david, linux-mm, Andrew Morton,
	Nicholas Piggin, Uladzislau Rezki, Catalin Marinas,
	Thomas Gleixner, Ingo Molnar, David Rientjes

On Wed, Jun 09, 2021 at 06:28:09PM +0200, Claudio Imbrenda wrote:
> On Wed, 9 Jun 2021 16:59:17 +0100
> Christoph Hellwig <hch@infradead.org> wrote:
> 
> > On Tue, Jun 08, 2021 at 08:06:17PM +0200, Claudio Imbrenda wrote:
> > > The recent patches to add support for hugepage vmalloc mappings
> > > added a flag for __vmalloc_node_range to allow to request small
> > > pages. This flag is not accessible when calling vmalloc, the only
> > > option is to call directly __vmalloc_node_range, which is not
> > > exported.
> > > 
> > > This means that a module can't vmalloc memory with small pages.
> > > 
> > > Case in point: KVM on s390x needs to vmalloc a large area, and it
> > > needs to be mapped with small pages, because of a hardware
> > > limitation.
> > > 
> > > This patch exports __vmalloc_node_range so it can be used in modules
> > > too.  
> > 
> > No.  I spent a lot of effort to mak sure such a low-level API is
> > not exported.
> 
> ok, but then how can we vmalloc memory with small pages from KVM?
Does the s390x support CONFIG_HAVE_ARCH_HUGE_VMALLOC what is arch
specific?

If not then small pages are used. Or am i missing something?

I agree with Christoph that exporting a low level internals
is not a good idea.

--
Vlad Rezki

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

* Re: [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-09 16:28     ` Claudio Imbrenda
  2021-06-09 16:49       ` Uladzislau Rezki
@ 2021-06-09 17:47       ` Christian Borntraeger
  2021-06-10  5:24         ` Christoph Hellwig
  1 sibling, 1 reply; 10+ messages in thread
From: Christian Borntraeger @ 2021-06-09 17:47 UTC (permalink / raw)
  To: Claudio Imbrenda, Christoph Hellwig
  Cc: linux-kernel, kvm, linux-s390, frankja, cohuck, david, linux-mm,
	Andrew Morton, Nicholas Piggin, Uladzislau Rezki,
	Catalin Marinas, Thomas Gleixner, Ingo Molnar, David Rientjes

On 09.06.21 18:28, Claudio Imbrenda wrote:
> On Wed, 9 Jun 2021 16:59:17 +0100
> Christoph Hellwig <hch@infradead.org> wrote:
> 
>> On Tue, Jun 08, 2021 at 08:06:17PM +0200, Claudio Imbrenda wrote:
>>> The recent patches to add support for hugepage vmalloc mappings
>>> added a flag for __vmalloc_node_range to allow to request small
>>> pages. This flag is not accessible when calling vmalloc, the only
>>> option is to call directly __vmalloc_node_range, which is not
>>> exported.
>>>
>>> This means that a module can't vmalloc memory with small pages.
>>>
>>> Case in point: KVM on s390x needs to vmalloc a large area, and it
>>> needs to be mapped with small pages, because of a hardware
>>> limitation.
>>>
>>> This patch exports __vmalloc_node_range so it can be used in modules
>>> too.
>>
>> No.  I spent a lot of effort to mak sure such a low-level API is
>> not exported.
> 
> ok, but then how can we vmalloc memory with small pages from KVM?

An alternative would be to provide a vmalloc_no_huge function in generic
code  (similar to  vmalloc_32) (or if preferred in s390 base architecture code)
Something like

void *vmalloc_no_huge(unsigned long size)
{
         return __vmalloc_node_flags(size, NUMA_NO_NODE,VM_NO_HUGE_VMAP |
                                 GFP_KERNEL | __GFP_ZERO);
}
EXPORT_SYMBOL(vmalloc_no_huge);

or a similar vzalloc variant.

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

* Re: [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-09 16:49       ` Uladzislau Rezki
@ 2021-06-09 17:50         ` Christian Borntraeger
  0 siblings, 0 replies; 10+ messages in thread
From: Christian Borntraeger @ 2021-06-09 17:50 UTC (permalink / raw)
  To: Uladzislau Rezki, Claudio Imbrenda
  Cc: Christoph Hellwig, linux-kernel, kvm, linux-s390, frankja,
	cohuck, david, linux-mm, Andrew Morton, Nicholas Piggin,
	Catalin Marinas, Thomas Gleixner, Ingo Molnar, David Rientjes



On 09.06.21 18:49, Uladzislau Rezki wrote:
> On Wed, Jun 09, 2021 at 06:28:09PM +0200, Claudio Imbrenda wrote:
>> On Wed, 9 Jun 2021 16:59:17 +0100
>> Christoph Hellwig <hch@infradead.org> wrote:
>>
>>> On Tue, Jun 08, 2021 at 08:06:17PM +0200, Claudio Imbrenda wrote:
>>>> The recent patches to add support for hugepage vmalloc mappings
>>>> added a flag for __vmalloc_node_range to allow to request small
>>>> pages. This flag is not accessible when calling vmalloc, the only
>>>> option is to call directly __vmalloc_node_range, which is not
>>>> exported.
>>>>
>>>> This means that a module can't vmalloc memory with small pages.
>>>>
>>>> Case in point: KVM on s390x needs to vmalloc a large area, and it
>>>> needs to be mapped with small pages, because of a hardware
>>>> limitation.
>>>>
>>>> This patch exports __vmalloc_node_range so it can be used in modules
>>>> too.
>>>
>>> No.  I spent a lot of effort to mak sure such a low-level API is
>>> not exported.
>>
>> ok, but then how can we vmalloc memory with small pages from KVM?
> Does the s390x support CONFIG_HAVE_ARCH_HUGE_VMALLOC what is arch
> specific?

Not yet, but we surely want that for almost everything on s390.
Only this particular firmware interface does not handle large pages
for donated memory.

> 
> If not then small pages are used. Or am i missing something?
> 
> I agree with Christoph that exporting a low level internals
> is not a good idea.

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

* Re: [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range
  2021-06-09 17:47       ` Christian Borntraeger
@ 2021-06-10  5:24         ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2021-06-10  5:24 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Claudio Imbrenda, Christoph Hellwig, linux-kernel, kvm,
	linux-s390, frankja, cohuck, david, linux-mm, Andrew Morton,
	Nicholas Piggin, Uladzislau Rezki, Catalin Marinas,
	Thomas Gleixner, Ingo Molnar, David Rientjes

On Wed, Jun 09, 2021 at 07:47:43PM +0200, Christian Borntraeger wrote:
> An alternative would be to provide a vmalloc_no_huge function in generic
> code  (similar to  vmalloc_32) (or if preferred in s390 base architecture code)
> Something like
> 
> void *vmalloc_no_huge(unsigned long size)
> {
>         return __vmalloc_node_flags(size, NUMA_NO_NODE,VM_NO_HUGE_VMAP |
>                                 GFP_KERNEL | __GFP_ZERO);
> }
> EXPORT_SYMBOL(vmalloc_no_huge);
> 
> or a similar vzalloc variant.

Exactly.  Given that this seems to be a weird pecularity of legacy s390
interfaces I'd only export it for 390 for now, although for
documentation purposes I'd probably still keep it in vmalloc.c.

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

end of thread, other threads:[~2021-06-10  5:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 18:06 [PATCH v2 0/2] mm: export __vmalloc_node_range and use it Claudio Imbrenda
2021-06-08 18:06 ` [PATCH v2 1/2] mm/vmalloc: export __vmalloc_node_range Claudio Imbrenda
2021-06-09 15:59   ` Christoph Hellwig
2021-06-09 16:28     ` Claudio Imbrenda
2021-06-09 16:49       ` Uladzislau Rezki
2021-06-09 17:50         ` Christian Borntraeger
2021-06-09 17:47       ` Christian Borntraeger
2021-06-10  5:24         ` Christoph Hellwig
2021-06-08 18:06 ` [PATCH v2 2/2] KVM: s390: fix for hugepage vmalloc Claudio Imbrenda
2021-06-08 18:52   ` Christian Borntraeger

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.