mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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:38:24 -0700	[thread overview]
Message-ID: <3f0da3c0-22e8-4a19-9537-ac9c92b03174@zytor.com> (raw)
In-Reply-To: <77294ea6-480b-456e-8102-6c36ed4b7b96@zytor.com>

[-- Attachment #1: Type: text/plain, Size: 1188 bytes --]

On 10/26/24 16:28, H. Peter Anvin wrote:
> 
> 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?)
> 
cl
This also matches the "tell the compiler [and programmer] what we 
actually mean" issue that you have mentioned in other contexts.

Anyway, here is a simple test case that can be used to verify that this 
construct does indeed work; at least with gcc 14.2.1 and clang 18.1.8 
(the ones I ran a very quick test on).

It's simple enough that it is pretty straightforward to mess around with 
various modifications. So far I haven't been able to trip up the 
compilers this way.

	-hpa

[-- Attachment #2: fp.c --]
[-- Type: text/x-csrc, Size: 541 bytes --]

unsigned long testit_reg(unsigned long x, unsigned long y)
{
    unsigned long z = x + y;
    unsigned long v;

    asm("# Frame pointer in %[fp]\n\tmov %[in],%[out]"
	: [out] "=r" (v)
	: [in] "r" (z), [fp] "r" (__builtin_frame_address(0)));

    return v;
}

unsigned long testit_buf(unsigned long x, unsigned long y)
{
    unsigned long z = x + y;
    unsigned long buffer[64];

    asm("# Frame pointer in %[fp]\n\tmov %[in],%[out]"
	: [out] "=m" (buffer)
	: [in] "r" (z), [fp] "r" (__builtin_frame_address(0)));

    return buffer[0];
}

  reply	other threads:[~2024-10-26 23:38 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
2024-10-26 23:38           ` H. Peter Anvin [this message]
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=3f0da3c0-22e8-4a19-9537-ac9c92b03174@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®