linux-um archives
 help / color / mirror / Atom feed
From: Nadav Amit <nadav.amit@gmail.com>
To: Anton Ivanov <anton.ivanov@kot-begemot.co.uk>
Cc: Richard Weinberger <richard@nod.at>,
	linux-um@lists.infradead.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: Missing clobber on alternative use on Linux UM 32-bit
Date: Sat, 4 Nov 2023 11:40:48 +0200	[thread overview]
Message-ID: <1616BF59-5C18-46C7-86AB-92604B683652@gmail.com> (raw)
In-Reply-To: <a55f6941-ddf6-2355-271d-5ed0db5a2a62@kot-begemot.co.uk>



> On Nov 4, 2023, at 11:34 AM, Anton Ivanov <anton.ivanov@kot-begemot.co.uk> wrote:
> 
> On 04/11/2023 09:25, Nadav Amit wrote:
>> 
>> I was reading (again) the x86 C macro of “alternative()” and I was a bit
>> surprised it does clobber the flags (“cc”) as a precaution.
>> 
>>  #define alternative(oldinstr, newinstr, ft_flags) \
>> 	asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "memory")
>> 
>> Actually there seems to be only one instance of problematic cases - in um/32-bit:
>> 
>>  #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
>>  #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
>>  #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
>> 
>> Presumably, if XMM or XMM2 are not supported, there would be instances where addl
>> would be able to change eflags arithmetic flags without the compiler being aware
>> of it.
>> 
>> As it only affects 32-bit Linux UM - I don’t easily have an environment to test
>> the fix. An alternative (word-pun unintended) is to add “cc” as a precaution
>> to the alternative macro.
>> 
> Application alternatives in um is presently a NOP. It always uses the "blunt and heavy instrument" - the most conservative option.
> 
> It is on the TODO list.

Thanks for the quick response. But I don’t see how it prevents the problem
(it actually makes it worse - affecting XMM/XMM2 CPUs as well) since you
keep the “lock; addl $0,0(%%esp)” in the running code, affecting eflags
without telling the compiler that you do so through a “cc” clobber.


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

  reply	other threads:[~2023-11-04  9:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04  9:25 Missing clobber on alternative use on Linux UM 32-bit Nadav Amit
2023-11-04  9:34 ` Anton Ivanov
2023-11-04  9:40   ` Nadav Amit [this message]
2023-11-05 15:47     ` David Laight
2023-11-06 11:33       ` Nadav Amit

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=1616BF59-5C18-46C7-86AB-92604B683652@gmail.com \
    --to=nadav.amit@gmail.com \
    --cc=anton.ivanov@kot-begemot.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=peterz@infradead.org \
    --cc=richard@nod.at \
    --cc=tglx@linutronix.de \
    /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