mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86, nospec: Fix uninitialized mask in array_index_mask_nospec()
@ 2018-02-14 20:50 Dan Williams
  2018-02-14 21:04 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2018-02-14 20:50 UTC (permalink / raw)
  To: mingo
  Cc: Andi Kleen, x86, linux-kernel, Ingo Molnar, H. Peter Anvin,
	Thomas Gleixner, Linus Torvalds

Break the false dependency on the uninitialized value of 'mask' in
array_index_mask_nospec(). This potentially allows the CPU to rename the
register, avoids reports from tools that can detect uninitialized inline
asm arguments, and makes it explicit that this sequence wants the result
of (0 - 0 - CARRY).

Reported-by: Andi Kleen <ak@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 arch/x86/include/asm/barrier.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
index e1259f043ae9..b572b6a77e12 100644
--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -36,10 +36,10 @@
 static inline unsigned long array_index_mask_nospec(unsigned long index,
 		unsigned long size)
 {
-	unsigned long mask;
+	unsigned long mask = 0;
 
-	asm ("cmp %1,%2; sbb %0,%0;"
-			:"=r" (mask)
+	asm ("cmp %1,%2; sbb $0,%0;"
+			:"+r" (mask)
 			:"g"(size),"r" (index)
 			:"cc");
 	return mask;

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

* Re: [PATCH] x86, nospec: Fix uninitialized mask in array_index_mask_nospec()
  2018-02-14 20:50 [PATCH] x86, nospec: Fix uninitialized mask in array_index_mask_nospec() Dan Williams
@ 2018-02-14 21:04 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2018-02-14 21:04 UTC (permalink / raw)
  To: Dan Williams
  Cc: Ingo Molnar, Andi Kleen, the arch/x86 maintainers,
	Linux Kernel Mailing List, Ingo Molnar, H. Peter Anvin,
	Thomas Gleixner

On Wed, Feb 14, 2018 at 12:50 PM, Dan Williams <dan.j.williams@intel.com> wrote:
> Break the false dependency on the uninitialized value of 'mask' in
> array_index_mask_nospec(). This potentially allows the CPU to rename the
> register, avoids reports from tools that can detect uninitialized inline
> asm arguments, and makes it explicit that this sequence wants the result
> of (0 - 0 - CARRY).

NAK.

This is stupid.

Any asm tools that think this is "uninitialized inline asm arguments"
are complete garbage. It's an output-only register. Fix the tool, or
ignore it as shit.

And that false dependency argument is pure garbage too. Making this an
input that has been initialized to zero doesn't just generate a
pointless zeroing operation, it also adds to register pressure.

So NAK NAK NAK. The arguments for this patch are pure and utter shite.

If somebody can actually show a performance reason (with NUMBERS!) for
it or some _real_ reason to do something this stupid, that's one
thing. But these arguments are just bad, and the patch is bad.

              Linus

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

end of thread, other threads:[~2018-02-14 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14 20:50 [PATCH] x86, nospec: Fix uninitialized mask in array_index_mask_nospec() Dan Williams
2018-02-14 21:04 ` Linus Torvalds

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

all inboxes | Powered by JetHome®