From: "H. Peter Anvin" <hpa@zytor.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH] x86/ioperm: Use atomic64_inc_return() in ksys_ioperm()
Date: Sat, 26 Oct 2024 16:28:04 -0700 [thread overview]
Message-ID: <77294ea6-480b-456e-8102-6c36ed4b7b96@zytor.com> (raw)
In-Reply-To: <CAFULd4a5+er=7xk+oXOtOsJVUqg86ZWxxvX7jdtOEBcMX60fKg@mail.gmail.com>
On 10/25/24 14:01, Uros Bizjak wrote:
>>
>> What does ASM_CALL_CONSTRAINT actually do *in the kernel*, *for x86*? There isn't a redzone in the kernel, and there *can't* be, because asynchronous events can clobber data below the stack pointer at any time.
>
> The reason for ASM_CALL_CONSTRAINT is explained in arch/x86/include/asm/asm.h:
>
> --q--
> /*
> * This output constraint should be used for any inline asm which has a "call"
> * instruction. Otherwise the asm may be inserted before the frame pointer
> * gets set up by the containing function. If you forget to do this, objtool
> * may print a "call without frame pointer save/setup" warning.
> */
> register unsigned long current_stack_pointer asm(_ASM_SP);
> #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
> --/q--
>
> __alternative_atomic64() macro always uses CALL instruction and one of
> alternatives in __arch_{,try_}cmpxchg64_emu() uses CALL as well, so
> according to the above comment, they all qualify for
> ASM_CALL_CONSTRAINT. This constraint is added to the mentioned macros
> in the proposed series [1].
>
> [1] https://lore.kernel.org/lkml/20241024180612.162045-1-ubizjak@gmail.com/
>
Ugh. I am not criticizing the usage here, but the construct is
bleacherous, because it converts what is properly an input constraint
into an inout constraint, which wouldn't be a big deal except for the
slight fact that older compilers don't allow asm goto to have output
constraints.
By any sane definition, the constraint should actually be an input
constraint on the frame pointer itself; something like:
#define ASM_CALL_CONSTRAINT "r" (__builtin_frame_address(0))
... except that "r" really should be a %rbp constraint, but %rbp doesn't
seem to have a constraint letter. At least gcc 14.2 seems to do the
right thing anyway, though: __builtin_frame_address(0) seems to force a
frame pointer to have been created (even with -fomit-frame-pointer
specified, and in a leaf function), and the value is always passed in
%rbp (because why on Earth would it do it differently, when it is
sitting right there?)
-hpa
next prev parent reply other threads:[~2024-10-26 23:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 8:33 Uros Bizjak
2024-10-24 15:20 ` Dave Hansen
2024-10-24 16:20 ` Uros Bizjak
2024-10-25 17:12 ` H. Peter Anvin
2024-10-25 21:01 ` Uros Bizjak
2024-10-26 23:28 ` H. Peter Anvin [this message]
2024-10-26 23:38 ` H. Peter Anvin
2024-10-27 1:23 ` H. Peter Anvin
2024-10-24 18:27 Uros Bizjak
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=77294ea6-480b-456e-8102-6c36ed4b7b96@zytor.com \
--to=hpa@zytor.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=ubizjak@gmail.com \
--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
all inboxes | Powered by JetHome®