All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Prarit Bhargava <prarit@redhat.com>
Cc: linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH] x86, bitops, variable_test_bit should return 1 not -1 on a match
Date: Fri, 21 Aug 2015 08:51:03 +0200	[thread overview]
Message-ID: <20150821065103.GA4541@gmail.com> (raw)
In-Reply-To: <1440004734-24290-1-git-send-email-prarit@redhat.com>


* Prarit Bhargava <prarit@redhat.com> wrote:

> This issue was noticed while debugging a CPU hotplug issue.  On x86
> with (NR_CPUS > 1) the cpu_online() define is cpumask_test_cpu().
> cpumask_test_cpu() should return 1 if the cpu is set in cpumask and
> 0 otherwise.
> 
> However, cpumask_test_cpu() returns -1 if the cpu in the cpumask is
> set and 0 otherwise.  This happens because cpumask_test_cpu() calls
> test_bit() which is a define that will call variable_test_bit().
> 
> variable_test_bit() calls the assembler instruction sbb (Subtract
> with Borrow, " Subtracts the source from the destination, and subtracts 1
> extra if the Carry Flag is set. Results are returned in "dest".)
> 
> A bit match results in -1 being returned from variable_test_bit() if a
> match occurs, not 1 as the function is supposed to.  This can be easily
> resolved by adding a "!!" to force 0 or 1 as a return.
> 
> It looks like the code never does, for example, (test_bit() == 1) so this
> change should not have any impact.
> 
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> ---
>  arch/x86/include/asm/bitops.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
> index cfe3b95..a87a5fb 100644
> --- a/arch/x86/include/asm/bitops.h
> +++ b/arch/x86/include/asm/bitops.h
> @@ -320,7 +320,7 @@ static inline int variable_test_bit(long nr, volatile const unsigned long *addr)
>  		     : "=r" (oldbit)
>  		     : "m" (*(unsigned long *)addr), "Ir" (nr));
>  
> -	return oldbit;
> +	return !!oldbit;
>  }
>  
>  #if 0 /* Fool kernel-doc since it doesn't do macros yet */

Ok, I think this is a good fix to improve the robustness of this primitive, unless 
someone objects.

I tried to find the CPU hotplug code that broke with cpu_online() returning -1 but 
failed - all current mainline usage sites seem to be testing for nonzero in one 
way or another. Could you please point it out?

Thanks,

	Ingo

  reply	other threads:[~2015-08-21  6:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-19 17:18 [PATCH] x86, bitops, variable_test_bit should return 1 not -1 on a match Prarit Bhargava
2015-08-21  6:51 ` Ingo Molnar [this message]
2015-08-21  8:08   ` H. Peter Anvin
2015-08-21 11:53     ` Prarit Bhargava
2015-08-24 18:22     ` [PATCH v2] " Prarit Bhargava
2015-10-07 23:27       ` Prarit Bhargava
2015-10-08  8:51         ` Ingo Molnar
2015-10-08 11:48     ` [PATCH] " Prarit Bhargava
2015-08-21 11:50   ` Prarit Bhargava
2015-08-22  9:14     ` Ingo Molnar

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=20150821065103.GA4541@gmail.com \
    --to=mingo@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=prarit@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --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 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.