Skip to contentSkip to conversation

mm: move bad zone checking before getting it

PATCH In review Wang Yibo 2 participants 6 messages Sep 5, 2024 – Sep 6, 2024

Subsystems (3)
lore
Share & tools
lore

Wang Yibo

author
#0 lore raw

PATCH 1/1 mm: move bad zone checking before getting it

When flags from gfp_zone() has an error combination, VM_BUG_ON() should firt know it before use it.

---
 include/linux/gfp.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/gfp.h +2 -1
index f53f76e0b17e..ca61b2440ab3 100644
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
 {
 	enum zone_type z;
 	int bit = (__force int) (flags & GFP_ZONEMASK);
+	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
 
 	z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
 					 ((1 << GFP_ZONES_SHIFT) - 1);
-	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+
 	return z;
 }
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 1 line · Wang Yibo

When flags from gfp_zone() has an error combination, VM_BUG_ON() should firt know it before use it.

s/firt/first/

Please break long lines. (checkpatch.pl should have warned you)

Quoted 11 lines
---
  include/linux/gfp.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/gfp.h +0 -0
index f53f76e0b17e..ca61b2440ab3 100644

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 136

Quoted 4 lines
include/linux/gfp.h +1 -0
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
  {
  	enum zone_type z;
  	int bit = (__force int) (flags & GFP_ZONEMASK);
+	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);

Better use VM_WARN_ON_ONCE() instead while at it.

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 140

Quoted 5 lines
include/linux/gfp.h +1 -1
  	z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
  					 ((1 << GFP_ZONES_SHIFT) - 1);
-	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+

Unrelated whitespace change.

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 143

Quoted 3 lines
include/linux/gfp.h +0 -0
  	return z;
  }
 

But I don't see why we would want this change? It's not like the kernel would crash when calculating z.

Or is there some change in behavior I am missing?

Signature · 3 lines
Cheers,

David / dhildenb
author
#2 lore raw

PATCH v2 1/1 mm: move bad zone checking in gfp_zone()

When flags in gfp_zone() has an error combination, VM_BUG_ON() should first know it before use it.

---
 include/linux/gfp.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/gfp.h +2 -1
index f53f76e0b17e..ca61b2440ab3 100644
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
 {
 	enum zone_type z;
 	int bit = (__force int) (flags & GFP_ZONEMASK);
+	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
 
 	z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
 					 ((1 << GFP_ZONES_SHIFT) - 1);
-	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+
 	return z;
 }
 
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH v2 1/1] mm: move bad zone checking in gfp_zone()

Quoted 13 lines · Wang Yibo

When flags in gfp_zone() has an error combination, VM_BUG_ON() should first know it before use it.

---
  include/linux/gfp.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/gfp.h +0 -0
index f53f76e0b17e..ca61b2440ab3 100644

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 140

Quoted 9 lines
include/linux/gfp.h +2 -1
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
  {
  	enum zone_type z;
  	int bit = (__force int) (flags & GFP_ZONEMASK);
+	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
 
  	z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
  					 ((1 << GFP_ZONES_SHIFT) - 1);
-	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+

I'm afraid you either missed half my review comments or your answer to my mail did not make it to my inbox.

Signature · 3 lines
Cheers,

David / dhildenb
#4 lore raw
In reply to David Hildenbrand
Quoted 42 lines · David Hildenbrand
Quoted 1 line · Wang Yibo

When flags from gfp_zone() has an error combination, VM_BUG_ON() should firt know it before use it.

s/firt/first/

Please break long lines. (checkpatch.pl should have warned you)

Quoted 11 lines
---
  include/linux/gfp.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/gfp.h +0 -0
index f53f76e0b17e..ca61b2440ab3 100644

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 136

Quoted 4 lines
include/linux/gfp.h +1 -0
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
  {
      enum zone_type z;
      int bit = (__force int) (flags & GFP_ZONEMASK);
+     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);

Better use VM_WARN_ON_ONCE() instead while at it.

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 140

Quoted 5 lines
include/linux/gfp.h +1 -1
      z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
                                       ((1 << GFP_ZONES_SHIFT) - 1);
-     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+

Unrelated whitespace change.

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 143

Quoted 3 lines
include/linux/gfp.h +0 -0
      return z;
  }
 

But I don't see why we would want this change? It's not like the kernel would crash when calculating z.

Or is there some change in behavior I am missing?

Quoted 20 lines · David Hildenbrand
Quoted 18 lines · Wang Yibo
include/linux/gfp.h +0 -0
 When flags in gfp_zone() has an error combination,

VM_BUG_ON() should first know it before use it.

---
  include/linux/gfp.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/gfp.h +1 -0
index f53f76e0b17e..ca61b2440ab3 100644
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
  {
      enum zone_type z;
      int bit = (__force int) (flags & GFP_ZONEMASK);
+     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
 
Quoted 7 lines

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 140

Quoted 4 lines
include/linux/gfp.h +1 -1
      z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
                                       ((1 << GFP_ZONES_SHIFT) - 1);
-     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+

I'm afraid you either missed half my review comments or your answer to my mail did not make it to my inbox.

I did not read your first email carefully,Sorry for that. I will reply to your comments based on your last email.

Quoted 13 lines

--
Cheers,

David / dhildenb

--
Cheers,

David / dhildenb

#5 lore raw
In reply to David Hildenbrand
Quoted 7 lines · David Hildenbrand
Quoted 1 line · Wang Yibo

When flags from gfp_zone() has an error combination, VM_BUG_ON() should firt know it before use it.

s/firt/first/

Please break long lines. (checkpatch.pl should have warned you)

I will change it.

Quoted 7 lines
Quoted 7 lines
---
  include/linux/gfp.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 11 lines

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 136

Quoted 9 lines
include/linux/gfp.h +1 -0
index f53f76e0b17e..ca61b2440ab3 100644
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
  {
      enum zone_type z;
      int bit = (__force int) (flags & GFP_ZONEMASK);
+     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);

Better use VM_WARN_ON_ONCE() instead while at it.

Although I do not know what results BAD ZONE flags combinations will cause, I think maybe a BUG is necessary for security ?

Quoted 8 lines

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 140

Quoted 6 lines
include/linux/gfp.h +1 -1
      z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
                                       ((1 << GFP_ZONES_SHIFT) - 1);
-     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+

Unrelated whitespace change.

I will change it.

Quoted 9 lines

include/linux/gfp.h static inline enum zone_type gfp_zone(gfp_t flags) · line 143

Quoted 4 lines
include/linux/gfp.h +0 -0
      return z;
  }
 

But I don't see why we would want this change? It's not like the kernel would crash when calculating z.

Or is there some change in behavior I am missing?

I just think flags checking should precede using it logically, when I review these partial codes. So I submit this patch, there is no other reason.

Quoted 6 lines

--
Cheers,

David / dhildenb