All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Guenter Roeck <linux@roeck-us.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm-treewide-redefine-max_order-sanely-fix.txt
Date: Fri, 7 Apr 2023 00:14:31 +0300	[thread overview]
Message-ID: <ZC82N4sP5xE63kl4@kernel.org> (raw)
In-Reply-To: <20230406151015.yndcm24fyxitvqyc@box.shutemov.name>

On Thu, Apr 06, 2023 at 06:10:15PM +0300, Kirill A. Shutemov wrote:
> On Thu, Apr 06, 2023 at 06:57:41AM -0700, Guenter Roeck wrote:
> > On 4/6/23 00:25, Kirill A. Shutemov wrote:
> > > On Wed, Apr 05, 2023 at 10:20:26PM -0700, Guenter Roeck wrote:
> > > > Hi,
> > > > 
> > > > On Wed, Mar 15, 2023 at 06:38:00PM +0300, Kirill A. Shutemov wrote:
> > > > > fix min() warning
> > > > > 
> > > > > Link: https://lkml.kernel.org/r/20230315153800.32wib3n5rickolvh@box
> > > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > >    Link: https://lore.kernel.org/oe-kbuild-all/202303152343.D93IbJmn-lkp@intel.com/
> > > > > Signed-off-by: "Kirill A. Shutemov" <kirill@shutemov.name>
> > > > > Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> > > > > Cc: Zi Yan <ziy@nvidia.com>
> > > > > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> > > > 
> > > > This patch results in various boot failures (hang) on arm targets
> > > > in linux-next. Debug messages reveal the reason.
> > > > 
> > > > ########### MAX_ORDER=10 start=0 __ffs(start)=-1 min()=10 min_t=-1
> > > >                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > > 
> > > > If start==0, __ffs(start) returns 0xfffffff or (as int) -1, which min_t()
> > > > interprets as such, while min() apparently uses the returned unsigned long
> > > > value. Obviously a negative order isn't received well by the rest of the
> > > > code.
> > > 
> > > Actually, __ffs() is not defined for 0.
> > > 
> > > Maybe something like this?
> > > 
> > > diff --git a/mm/memblock.c b/mm/memblock.c
> > > index 7911224b1ed3..63603b943bd0 100644
> > > --- a/mm/memblock.c
> > > +++ b/mm/memblock.c
> > > @@ -2043,7 +2043,11 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
> > >   	int order;
> > >   	while (start < end) {
> > > -		order = min_t(int, MAX_ORDER, __ffs(start));
> > > +		/* __ffs() behaviour is undefined for 0 */
> > > +		if (start)
> > > +			order = min_t(int, MAX_ORDER, __ffs(start));
> > > +		else
> > > +			order = MAX_ORDER;
> > 
> > Shouldn't that be
> > 		else
> > 			order = 0;
> > ?
> 
> +Mike.
> 
> No. start == 0 is MAX_ORDER-aligned. We want to free the pages in the
> largest chunks alignment allows.

Right. Before the changes to MAX_ORDER it was

		order = min(MAX_ORDER - 1UL, __ffs(start));

which would evaluate to 10.

I'd just prefer the comment to include the explanation about why we choose
MAX_ORDER for start == 0. Say

	/*
	 * __ffs() behaviour is undefined for 0 and we want to free the
	 * pages in the largest chunks alignment allows, so set order to
	 * MAX_ORDER when start == 0
	 */

> -- 
>   Kiryl Shutsemau / Kirill A. Shutemov

-- 
Sincerely yours,
Mike.


  parent reply	other threads:[~2023-04-06 21:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06  5:20 [PATCH] mm-treewide-redefine-max_order-sanely-fix.txt Guenter Roeck
2023-04-06  7:25 ` Kirill A. Shutemov
2023-04-06 13:57   ` Guenter Roeck
2023-04-06 15:10     ` Kirill A. Shutemov
2023-04-06 18:23       ` Guenter Roeck
2023-04-06 21:14       ` Mike Rapoport [this message]
2023-04-06 22:44         ` Andrew Morton
2023-04-07 12:40           ` Kirill A. Shutemov
2023-04-07 18:03             ` Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZC82N4sP5xE63kl4@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.