Linux CXL
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Mike Rapoport <rppt@kernel.org>,
	x86@kernel.org, linux-cxl@vger.kernel.org
Subject: Re: [PATCH 2/2] x86/numa: Fix the sort compare func used in numa_fill_memblks()
Date: Fri, 12 Jan 2024 16:35:02 -0800	[thread overview]
Message-ID: <ZaHatrJJc8MqtBHP@aschofie-mobl2> (raw)
In-Reply-To: <65a1bb13f0262_3b8e29483@dwillia2-xfh.jf.intel.com.notmuch>

On Fri, Jan 12, 2024 at 02:20:04PM -0800, Dan Williams wrote:
> alison.schofield@ wrote:
> > From: Alison Schofield <alison.schofield@intel.com>
> > 
> > The compare function used to sort memblks into starting address
> > order fails when the result of its u64 address subtraction gets
> > truncated to an int upon return.
> > 
> > The impact of the bad sort is that memblks will be filled out
> > incorrectly. Depending on the set of memblks, a user may see no
> > errors at all but still have a bad fill, or see messages reporting
> > a node overlap that leads to numa init failure:
> > 
> > [] node 0 [mem: ] overlaps with node 1 [mem: ]
> > [] No NUMA configuration found
> > 
> > Replace with a comparison that can only result in: 1, 0, -1.
> 
> Good eye!
> 
> > Fixes: 8f012db27c95 ("x86/numa: Introduce numa_fill_memblks()")
> > Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> > ---
> >  arch/x86/mm/numa.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
> > index 8ada9bbfad58..65e9a6e391c0 100644
> > --- a/arch/x86/mm/numa.c
> > +++ b/arch/x86/mm/numa.c
> > @@ -934,7 +934,7 @@ static int __init cmp_memblk(const void *a, const void *b)
> >  	const struct numa_memblk *ma = *(const struct numa_memblk **)a;
> >  	const struct numa_memblk *mb = *(const struct numa_memblk **)b;
> >  
> > -	return ma->start - mb->start;
> > +	return (ma->start > mb->start) - (ma->start < mb->start);
> 
> Maybe just do the less clever but obviously correct thing like 
> other unsigned compares like ktime_compare():
> 
>     if (ma->start > mb->start)
>         return 1;
>     if (ma->start < mb->start)
>         return -1;
>     return 0;
> 
> ...but otherwise this looks good to me.

During the upstream march of the original set, I oversimplified and
broke. For this fix, I surveyed the sort compare funcs and lifted this
simple method from commit: 4ac19ead0dfb ("kvm: x86/pmu: Fix the compare
function used by the pmu event filter"). 

Let me see what else I get to trigger a v2.

Thanks for the review!


  reply	other threads:[~2024-01-13  0:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12 20:09 [PATCH 0/2] x86/numa: Fix NUMA node overlap & init failure alison.schofield
2024-01-12 20:09 ` [PATCH 1/2] x86/numa: Fix the address overlap check in numa_fill_memblks() alison.schofield
2024-01-23  8:13   ` Mike Rapoport
2024-01-12 20:09 ` [PATCH 2/2] x86/numa: Fix the sort compare func used " alison.schofield
2024-01-12 22:20   ` Dan Williams
2024-01-13  0:35     ` Alison Schofield [this message]
2024-01-13  1:54       ` Dan Williams
2024-01-12 22:27 ` [PATCH 0/2] x86/numa: Fix NUMA node overlap & init failure Dan Williams
2024-01-25 21:49   ` Dan Williams
2024-01-29 23:00     ` Dave Hansen

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=ZaHatrJJc8MqtBHP@aschofie-mobl2 \
    --to=alison.schofield@intel.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rppt@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox