linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: move bad zone checking before getting it
@ 2024-09-05  9:52 Wang Yibo
  2024-09-05 10:22 ` David Hildenbrand
  0 siblings, 1 reply; 6+ messages in thread
From: Wang Yibo @ 2024-09-05  9:52 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, trivial, Wang Yibo

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

Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
---
 include/linux/gfp.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index f53f76e0b17e..ca61b2440ab3 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -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;
 }
 
-- 
2.20.1



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

* Re: [PATCH] mm: move bad zone checking before getting it
  2024-09-05  9:52 [PATCH] mm: move bad zone checking before getting it Wang Yibo
@ 2024-09-05 10:22 ` David Hildenbrand
  2024-09-05 10:48   ` [PATCH v2 1/1] mm: move bad zone checking in gfp_zone() Wang Yibo
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: David Hildenbrand @ 2024-09-05 10:22 UTC (permalink / raw)
  To: Wang Yibo, akpm; +Cc: linux-mm, linux-kernel, trivial, Wang Yibo

On 05.09.24 11:52, Wang Yibo wrote:
> 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)

> 
> Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
> ---
>   include/linux/gfp.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> index f53f76e0b17e..ca61b2440ab3 100644
> --- a/include/linux/gfp.h
> +++ b/include/linux/gfp.h
> @@ -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.

>   
>   	z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
>   					 ((1 << GFP_ZONES_SHIFT) - 1);
> -	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
> +

Unrelated whitespace change.

>   	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?

-- 
Cheers,

David / dhildenb



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

* [PATCH v2 1/1] mm: move bad zone checking in gfp_zone()
  2024-09-05 10:22 ` David Hildenbrand
@ 2024-09-05 10:48   ` Wang Yibo
  2024-09-05 13:13     ` David Hildenbrand
  2024-09-06  3:35   ` [PATCH] mm: move bad zone checking before getting it Lucien Wang
  2024-09-06  3:50   ` Lucien Wang
  2 siblings, 1 reply; 6+ messages in thread
From: Wang Yibo @ 2024-09-05 10:48 UTC (permalink / raw)
  To: david; +Cc: akpm, lcnwed, linux-kernel, linux-mm, trivial, wangyibo

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

Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
---
 include/linux/gfp.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index f53f76e0b17e..ca61b2440ab3 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -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;
 }
 
-- 
2.20.1



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

* Re: [PATCH v2 1/1] mm: move bad zone checking in gfp_zone()
  2024-09-05 10:48   ` [PATCH v2 1/1] mm: move bad zone checking in gfp_zone() Wang Yibo
@ 2024-09-05 13:13     ` David Hildenbrand
  0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2024-09-05 13:13 UTC (permalink / raw)
  To: Wang Yibo; +Cc: akpm, linux-kernel, linux-mm, trivial, wangyibo

On 05.09.24 12:48, Wang Yibo wrote:
> When flags in gfp_zone() has an error combination,
> VM_BUG_ON() should first know it before use it.
> 
> Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
> ---
>   include/linux/gfp.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> index f53f76e0b17e..ca61b2440ab3 100644
> --- a/include/linux/gfp.h
> +++ b/include/linux/gfp.h
> @@ -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.

-- 
Cheers,

David / dhildenb



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

* Re: [PATCH] mm: move bad zone checking before getting it
  2024-09-05 10:22 ` David Hildenbrand
  2024-09-05 10:48   ` [PATCH v2 1/1] mm: move bad zone checking in gfp_zone() Wang Yibo
@ 2024-09-06  3:35   ` Lucien Wang
  2024-09-06  3:50   ` Lucien Wang
  2 siblings, 0 replies; 6+ messages in thread
From: Lucien Wang @ 2024-09-06  3:35 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: akpm, linux-mm, linux-kernel, trivial, Wang Yibo

On Thu, Sep 5, 2024 at 6:22 PM David Hildenbrand <david@redhat.com> wrote:
>
> On 05.09.24 11:52, Wang Yibo wrote:
> > 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)
>
> >
> > Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
> > ---
> >   include/linux/gfp.h | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> > index f53f76e0b17e..ca61b2440ab3 100644
> > --- a/include/linux/gfp.h
> > +++ b/include/linux/gfp.h
> > @@ -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.
>
> >
> >       z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
> >                                        ((1 << GFP_ZONES_SHIFT) - 1);
> > -     VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
> > +
>
> Unrelated whitespace change.
>
> >       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?

On Thu, Sep 5, 2024 at 9:13 PM David Hildenbrand <david@redhat.com> wrote:
>
> On 05.09.24 12:48, Wang Yibo wrote:
> > When flags in gfp_zone() has an error combination,
> > VM_BUG_ON() should first know it before use it.
> >
> > Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
> > ---
> >   include/linux/gfp.h | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> > index f53f76e0b17e..ca61b2440ab3 100644
> > --- a/include/linux/gfp.h
> > +++ b/include/linux/gfp.h
> > @@ -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.

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

>
> --
> Cheers,
>
> David / dhildenb
>

>
> --
> Cheers,
>
> David / dhildenb
>


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

* Re: [PATCH] mm: move bad zone checking before getting it
  2024-09-05 10:22 ` David Hildenbrand
  2024-09-05 10:48   ` [PATCH v2 1/1] mm: move bad zone checking in gfp_zone() Wang Yibo
  2024-09-06  3:35   ` [PATCH] mm: move bad zone checking before getting it Lucien Wang
@ 2024-09-06  3:50   ` Lucien Wang
  2 siblings, 0 replies; 6+ messages in thread
From: Lucien Wang @ 2024-09-06  3:50 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: akpm, linux-mm, linux-kernel, trivial, Wang Yibo

On Thu, Sep 5, 2024 at 6:22 PM David Hildenbrand <david@redhat.com> wrote:
>
> On 05.09.24 11:52, Wang Yibo wrote:
> > 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.

>
> >
> > Signed-off-by: Wang Yibo <wangyibo@uniontech.com>
> > ---
> >   include/linux/gfp.h | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> > index f53f76e0b17e..ca61b2440ab3 100644
> > --- a/include/linux/gfp.h
> > +++ b/include/linux/gfp.h
> > @@ -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 ?

>
> >
> >       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.

>
> >       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.

>
> --
> Cheers,
>
> David / dhildenb
>


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

end of thread, other threads:[~2024-09-06  3:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-05  9:52 [PATCH] mm: move bad zone checking before getting it Wang Yibo
2024-09-05 10:22 ` David Hildenbrand
2024-09-05 10:48   ` [PATCH v2 1/1] mm: move bad zone checking in gfp_zone() Wang Yibo
2024-09-05 13:13     ` David Hildenbrand
2024-09-06  3:35   ` [PATCH] mm: move bad zone checking before getting it Lucien Wang
2024-09-06  3:50   ` Lucien Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox