diff mbox series

mm: move bad zone checking before getting it

Message ID 20240905095216.7888-1-wangyibo@uniontech.com (mailing list archive)
State New
Headers show
Series mm: move bad zone checking before getting it | expand

Commit Message

Lucien Wang Sept. 5, 2024, 9:52 a.m. UTC
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(-)

Comments

David Hildenbrand Sept. 5, 2024, 10:22 a.m. UTC | #1
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?
Lucien Wang Sept. 6, 2024, 3:35 a.m. UTC | #2
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
>
Lucien Wang Sept. 6, 2024, 3:50 a.m. UTC | #3
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
>
diff mbox series

Patch

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;
 }