Skip to contentSkip to conversation

mm: small cleanups for io-mapping, debug_page_alloc and numa

PATCH Applied Ye Liu 4 participants 13 messages Apr 27, 2025 – Apr 29, 2025

Subsystems (3)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

cover mm: small cleanups for io-mapping, debug_page_alloc and numa

From: Ye Liu <[email protected]>

This series includes three small cleanups to mm/:

- io-mapping: simplify remap protection flag calculation
- debug_page_alloc: improve error message by printing invalid input
- numa: remove unnecessary variable for clarity

No functional changes.

Ye Liu (3):
mm/io-mapping: precompute remap protection flags for clarity mm/debug_page_alloc: improve error message for invalid guardpage
minorder
mm/numa: remove unnecessary local variable in alloc_node_data()

 mm/debug_page_alloc.c | 2 +-
 mm/io-mapping.c       | 7 ++++---
 mm/numa.c             | 4 +---
 3 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/3 mm/io-mapping: precompute remap protection flags for clarity

From: Ye Liu <[email protected]>

In io_mapping_map_user(), precompute the page protection flags in a local variable before calling remap_pfn_range_notrack().

No functional change.

---
 mm/io-mapping.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/io-mapping.c +4 -3
index 01b362799930..f44a6a134712 100644
@@ -21,9 +21,10 @@ int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,
 	if (WARN_ON_ONCE((vma->vm_flags & expected_flags) != expected_flags))
 		return -EINVAL;
 
+	pgprot_t remap_prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
+				       (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK));
+
 	/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
-	return remap_pfn_range_notrack(vma, addr, pfn, size,
-		__pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
-			 (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK)));
+	return remap_pfn_range_notrack(vma, addr, pfn, size, remap_prot);
 }
 EXPORT_SYMBOL_GPL(io_mapping_map_user);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] mm/io-mapping: precompute remap protection flags for clarity

Quoted 20 lines · Ye Liu

From: Ye Liu <[email protected]>

In io_mapping_map_user(), precompute the page protection flags in a local variable before calling remap_pfn_range_notrack().

No functional change.

---
  mm/io-mapping.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
mm/io-mapping.c +0 -0
index 01b362799930..f44a6a134712 100644
@@ -21,9 +21,10 @@ int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,
  	if (WARN_ON_ONCE((vma->vm_flags & expected_flags) != expected_flags))
  		return -EINVAL;
 

mm/io-mapping.c int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma, · line 30

Quoted 10 lines
mm/io-mapping.c +4 -3
+	pgprot_t remap_prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
+				       (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK));
+
  	/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
-	return remap_pfn_range_notrack(vma, addr, pfn, size,
-		__pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
-			 (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK)));
+	return remap_pfn_range_notrack(vma, addr, pfn, size, remap_prot);
  }
  EXPORT_SYMBOL_GPL(io_mapping_map_user);
Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] mm/io-mapping: precompute remap protection flags for clarity

In reply to Ye Liu
Quoted 20 lines · Ye Liu

From: Ye Liu <[email protected]>

In io_mapping_map_user(), precompute the page protection flags in a local variable before calling remap_pfn_range_notrack().

No functional change.

---
 mm/io-mapping.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/io-mapping.c +0 -0
index 01b362799930..f44a6a134712 100644
@@ -21,9 +21,10 @@ int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,
 	if (WARN_ON_ONCE((vma->vm_flags & expected_flags) != expected_flags))
 		return -EINVAL;
 

mm/io-mapping.c int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma, · line 30

Quoted 10 lines
mm/io-mapping.c +4 -3
+	pgprot_t remap_prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
+				       (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK));
+
 	/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
-	return remap_pfn_range_notrack(vma, addr, pfn, size,
-		__pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
-			 (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK)));
+	return remap_pfn_range_notrack(vma, addr, pfn, size, remap_prot);
 }
 EXPORT_SYMBOL_GPL(io_mapping_map_user);
maintainer Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] mm/io-mapping: precompute remap protection flags for clarity

In reply to Ye Liu
Quoted 8 lines · Ye Liu

From: Ye Liu <[email protected]>

In io_mapping_map_user(), precompute the page protection flags in a local variable before calling remap_pfn_range_notrack().

No functional change.

Quoted 25 lines
---
 mm/io-mapping.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/io-mapping.c +4 -3
index 01b362799930..f44a6a134712 100644
@@ -21,9 +21,10 @@ int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,
 	if (WARN_ON_ONCE((vma->vm_flags & expected_flags) != expected_flags))
 		return -EINVAL;
 
+	pgprot_t remap_prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
+				       (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK));
+
 	/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
-	return remap_pfn_range_notrack(vma, addr, pfn, size,
-		__pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
-			 (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK)));
+	return remap_pfn_range_notrack(vma, addr, pfn, size, remap_prot);
 }
 EXPORT_SYMBOL_GPL(io_mapping_map_user);
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#5 lore raw

PATCH 2/3 mm/debug_page_alloc: improve error message for invalid guardpage minorder

In reply to Ye Liu

From: Ye Liu <[email protected]>

When an invalid debug_guardpage_minorder value is provided, include the user input in the error message. This helps users and developers diagnose configuration issues more easily.

No functional change.

---
 mm/debug_page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/debug_page_alloc.c +1 -1
index d46acf989dde..6a26eca546c3 100644
@@ -23,7 +23,7 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 	unsigned long res;
 
 	if (kstrtoul(buf, 10, &res) < 0 ||  res > MAX_PAGE_ORDER / 2) {
-		pr_err("Bad debug_guardpage_minorder value\n");
+		pr_err("Bad debug_guardpage_minorder value: %s\n", buf);
 		return 0;
 	}
 	_debug_guardpage_minorder = res;
Signature · 1 line
2.25.1
Acked-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] mm/debug_page_alloc: improve error message for invalid guardpage minorder

Quoted 18 lines · Ye Liu

From: Ye Liu <[email protected]>

When an invalid debug_guardpage_minorder value is provided, include the user input in the error message. This helps users and developers diagnose configuration issues more easily.

No functional change.

---
  mm/debug_page_alloc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/debug_page_alloc.c +0 -0
index d46acf989dde..6a26eca546c3 100644

mm/debug_page_alloc.c static int __init debug_guardpage_minorder_setup(char *buf) · line 26

Quoted 5 lines
mm/debug_page_alloc.c +1 -1
@@ -23,7 +23,7 @@ static int __init debug_guardpage_minorder_setup(char *buf)
  	unsigned long res;
 
  	if (kstrtoul(buf, 10, &res) < 0 ||  res > MAX_PAGE_ORDER / 2) {
-		pr_err("Bad debug_guardpage_minorder value\n");
+		pr_err("Bad debug_guardpage_minorder value: %s\n", buf);

I would guess everybody setting that should know how to find easily out what they tried to set, but in any case

Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] mm/debug_page_alloc: improve error message for invalid guardpage minorder

In reply to Ye Liu
Quoted 18 lines · Ye Liu

From: Ye Liu <[email protected]>

When an invalid debug_guardpage_minorder value is provided, include the user input in the error message. This helps users and developers diagnose configuration issues more easily.

No functional change.

---
 mm/debug_page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/debug_page_alloc.c +0 -0
index d46acf989dde..6a26eca546c3 100644

mm/debug_page_alloc.c static int __init debug_guardpage_minorder_setup(char *buf) · line 29

Quoted 8 lines
mm/debug_page_alloc.c +1 -1
@@ -23,7 +23,7 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 	unsigned long res;
 
 	if (kstrtoul(buf, 10, &res) < 0 ||  res > MAX_PAGE_ORDER / 2) {
-		pr_err("Bad debug_guardpage_minorder value\n");
+		pr_err("Bad debug_guardpage_minorder value: %s\n", buf);
 		return 0;
 	}
 	_debug_guardpage_minorder = res;
maintainer Acked-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] mm/debug_page_alloc: improve error message for invalid guardpage minorder

In reply to Ye Liu
Quoted 9 lines · Ye Liu

From: Ye Liu <[email protected]>

When an invalid debug_guardpage_minorder value is provided, include the user input in the error message. This helps users and developers diagnose configuration issues more easily.

No functional change.

Quoted 20 lines
---
 mm/debug_page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/debug_page_alloc.c +1 -1
index d46acf989dde..6a26eca546c3 100644
@@ -23,7 +23,7 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 	unsigned long res;
 
 	if (kstrtoul(buf, 10, &res) < 0 ||  res > MAX_PAGE_ORDER / 2) {
-		pr_err("Bad debug_guardpage_minorder value\n");
+		pr_err("Bad debug_guardpage_minorder value: %s\n", buf);
 		return 0;
 	}
 	_debug_guardpage_minorder = res;
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#9 lore raw

PATCH 3/3 mm/numa: remove unnecessary local variable in alloc_node_data()

In reply to Ye Liu

From: Ye Liu <[email protected]>

The temporary local variable 'nd' is redundant. Directly assign the virtual address to node_data[nid] to simplify the code.

No functional change.

---
 mm/numa.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/numa.c +1 -3
index f1787d7713a6..7d5e06fe5bd4 100644
@@ -13,7 +13,6 @@ void __init alloc_node_data(int nid)
 {
 	const size_t nd_size = roundup(sizeof(pg_data_t), SMP_CACHE_BYTES);
 	u64 nd_pa;
-	void *nd;
 	int tnid;
 
 	/* Allocate node data.  Try node-local memory and then any node. */
@@ -21,7 +20,6 @@ void __init alloc_node_data(int nid)
 	if (!nd_pa)
 		panic("Cannot allocate %zu bytes for node %d data\n",
 		      nd_size, nid);
-	nd = __va(nd_pa);
 
 	/* report and initialize */
 	pr_info("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n", nid,
@@ -30,7 +28,7 @@ void __init alloc_node_data(int nid)
 	if (tnid != nid)
 		pr_info("    NODE_DATA(%d) on node %d\n", nid, tnid);
 
-	node_data[nid] = nd;
+	node_data[nid] = __va(nd_pa);
 	memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] mm/numa: remove unnecessary local variable in alloc_node_data()

In reply to Ye Liu
Quoted 33 lines · Ye Liu

From: Ye Liu <[email protected]>

The temporary local variable 'nd' is redundant. Directly assign the virtual address to node_data[nid] to simplify the code.

No functional change.

---
 mm/numa.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/numa.c +0 -2
index f1787d7713a6..7d5e06fe5bd4 100644
@@ -13,7 +13,6 @@ void __init alloc_node_data(int nid)
 {
 	const size_t nd_size = roundup(sizeof(pg_data_t), SMP_CACHE_BYTES);
 	u64 nd_pa;
-	void *nd;
 	int tnid;
 
 	/* Allocate node data.  Try node-local memory and then any node. */
@@ -21,7 +20,6 @@ void __init alloc_node_data(int nid)
 	if (!nd_pa)
 		panic("Cannot allocate %zu bytes for node %d data\n",
 		      nd_size, nid);
-	nd = __va(nd_pa);
 
 	/* report and initialize */
 	pr_info("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n", nid,

mm/numa.c void __init alloc_node_data(int nid) · line 34

Quoted 8 lines
mm/numa.c +1 -1
@@ -30,7 +28,7 @@ void __init alloc_node_data(int nid)
 	if (tnid != nid)
 		pr_info("    NODE_DATA(%d) on node %d\n", nid, tnid);
 
-	node_data[nid] = nd;
+	node_data[nid] = __va(nd_pa);
 	memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
 }
 
maintainer Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] mm/numa: remove unnecessary local variable in alloc_node_data()

In reply to Ye Liu
Quoted 8 lines · Ye Liu

From: Ye Liu <[email protected]>

The temporary local variable 'nd' is redundant. Directly assign the virtual address to node_data[nid] to simplify the code.

No functional change.

Quoted 36 lines
---
 mm/numa.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/numa.c +1 -3
index f1787d7713a6..7d5e06fe5bd4 100644
@@ -13,7 +13,6 @@ void __init alloc_node_data(int nid)
 {
 	const size_t nd_size = roundup(sizeof(pg_data_t), SMP_CACHE_BYTES);
 	u64 nd_pa;
-	void *nd;
 	int tnid;
 
 	/* Allocate node data.  Try node-local memory and then any node. */
@@ -21,7 +20,6 @@ void __init alloc_node_data(int nid)
 	if (!nd_pa)
 		panic("Cannot allocate %zu bytes for node %d data\n",
 		      nd_size, nid);
-	nd = __va(nd_pa);
 
 	/* report and initialize */
 	pr_info("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n", nid,
@@ -30,7 +28,7 @@ void __init alloc_node_data(int nid)
 	if (tnid != nid)
 		pr_info("    NODE_DATA(%d) on node %d\n", nid, tnid);
 
-	node_data[nid] = nd;
+	node_data[nid] = __va(nd_pa);
 	memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
 }
 
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.