Skip to contentSkip to conversation

mm: implement no-MMU variant of vmalloc_user_node_flags

PATCH Applied Andrii Nakryiko 5 participants 6 messages Nov 23, 2019 – Nov 25, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: implement no-MMU variant of vmalloc_user_node_flags

To fix build with !CONFIG_MMU, implement it for no-MMU configurations as well.

Cc Johannes Weiner <[email protected]>
Fixes fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
---
 mm/nommu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
mm/nommu.c +13 -2
index 99b7ec318824..7de592058ab4 100644
@@ -155,11 +155,11 @@ void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags)
 	return __vmalloc(size, flags, PAGE_KERNEL);
 }
 
-void *vmalloc_user(unsigned long size)
+static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
 {
 	void *ret;
 
-	ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+	ret = __vmalloc(size, flags, PAGE_KERNEL);
 	if (ret) {
 		struct vm_area_struct *vma;
 
@@ -172,8 +172,19 @@ void *vmalloc_user(unsigned long size)
 
 	return ret;
 }
+
+void *vmalloc_user(unsigned long size)
+{
+	return __vmalloc_user_flags(size, GFP_KERNEL | __GFP_ZERO);
+}
 EXPORT_SYMBOL(vmalloc_user);
 
+void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
+{
+	return __vmalloc_user_flags(size, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL(vmalloc_user_node_flags);
+
 struct page *vmalloc_to_page(const void *addr)
 {
 	return virt_to_page(addr);
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#2 lore raw
In reply to Andrii Nakryiko
Quoted 35 lines · Andrii Nakryiko

To fix build with !CONFIG_MMU, implement it for no-MMU configurations as well.

Cc Johannes Weiner <[email protected]>
Fixes fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
---
 mm/nommu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
mm/nommu.c +5 -2
index 99b7ec318824..7de592058ab4 100644
@@ -155,11 +155,11 @@ void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags)
 	return __vmalloc(size, flags, PAGE_KERNEL);
 }
 
-void *vmalloc_user(unsigned long size)
+static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
 {
 	void *ret;
 
-	ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+	ret = __vmalloc(size, flags, PAGE_KERNEL);
 	if (ret) {
 		struct vm_area_struct *vma;
 
@@ -172,8 +172,19 @@ void *vmalloc_user(unsigned long size)
 
 	return ret;
 }
+
+void *vmalloc_user(unsigned long size)
+{

mm/nommu.c void *vmalloc_user(unsigned long size) · line 187

Quoted 10 lines
mm/nommu.c +8 -0
+	return __vmalloc_user_flags(size, GFP_KERNEL | __GFP_ZERO);
+}
 EXPORT_SYMBOL(vmalloc_user);
 
+void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
+{
+	return __vmalloc_user_flags(size, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL(vmalloc_user_node_flags);
+

Hi Andrii, my first reaction was that it seemed not ideal to just ignore the node value like this but everything I came up with was uglier. I guess only user is BPF at the moment so it should be fine.

#3 lore raw
Quoted 41 lines · John Fastabend
Quoted 39 lines · Andrii Nakryiko

To fix build with !CONFIG_MMU, implement it for no-MMU configurations as well.

Cc Johannes Weiner <[email protected]>
Fixes fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
---
 mm/nommu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
mm/nommu.c +7 -2
index 99b7ec318824..7de592058ab4 100644
@@ -155,11 +155,11 @@ void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags)
      return __vmalloc(size, flags, PAGE_KERNEL);
 }
 
-void *vmalloc_user(unsigned long size)
+static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
 {
      void *ret;
 
-     ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+     ret = __vmalloc(size, flags, PAGE_KERNEL);
      if (ret) {
              struct vm_area_struct *vma;
 
@@ -172,8 +172,19 @@ void *vmalloc_user(unsigned long size)
 
      return ret;
 }
+
+void *vmalloc_user(unsigned long size)
+{
+     return __vmalloc_user_flags(size, GFP_KERNEL | __GFP_ZERO);
+}
 EXPORT_SYMBOL(vmalloc_user);
 
Quoted 10 lines

mm/nommu.c void *vmalloc_user(unsigned long size) · line 187

Quoted 6 lines
mm/nommu.c +6 -0
+void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
+{
+     return __vmalloc_user_flags(size, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL(vmalloc_user_node_flags);
+

Hi Andrii, my first reaction was that it seemed not ideal to just ignore the node value like this but everything I came up with was uglier. I guess only user is BPF at the moment so it should be fine.

Yeah, but that's what other node-aware vmalloc() variants do in nommu.c, so at least it's consistent with other cases. Thanks for review!

Quoted 2 lines
#4 lore raw
Quoted 14 lines · Andrii Nakryiko
Quoted 12 lines · John Fastabend
Quoted 10 lines · Andrii Nakryiko

To fix build with !CONFIG_MMU, implement it for no-MMU configurations as well.

Cc Johannes Weiner <[email protected]>
Fixes fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
---
 mm/nommu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

[...]

Quoted 7 lines
Quoted 3 lines

Hi Andrii, my first reaction was that it seemed not ideal to just ignore the node value like this but everything I came up with was uglier. I guess only user is BPF at the moment so it should be fine.

Yeah, but that's what other node-aware vmalloc() variants do in nommu.c, so at least it's consistent with other cases. Thanks for review!

Great, at least folks (not me) who are used to working with no-mmu APIs will expect this then.

Quoted 3 lines
Quoted 3 lines
#5 lore raw
Quoted 5 lines · John Fastabend
Quoted 3 lines · Andrii Nakryiko
Quoted 1 line · John Fastabend
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines · Andrii Nakryiko

To fix build with !CONFIG_MMU, implement it for no-MMU configurations as well.

Cc Johannes Weiner <[email protected]>
Fixes fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")

Applied. Thanks