linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"Xin Li" <xin@zytor.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Borislav Petkov" <bp@alien8.de>,
	"Brian Gerst" <brgerst@gmail.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"James Morse" <james.morse@arm.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Kees Cook" <kees@kernel.org>, "Nam Cao" <namcao@linutronix.de>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Perry Yuan" <perry.yuan@amd.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Thomas Huth" <thuth@redhat.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-sgx@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH v2 7/9] x86/vdso: abstract out vdso system call internals
Date: Wed, 12 Nov 2025 11:31:05 +0100	[thread overview]
Message-ID: <CAFULd4aMOueG5y3K7F57ryLtt-JUhE-yfsDODC=5+bgjF_gtSw@mail.gmail.com> (raw)
In-Reply-To: <20251112043730.992152-8-hpa@zytor.com>

On Wed, Nov 12, 2025 at 5:38 AM H. Peter Anvin <hpa@zytor.com> wrote:
>
> Abstract out the calling of true system calls from the vdso into
> macros.
>
> It has been a very long time since gcc did not allow %ebx or %ebp in
> inline asm in 32-bit PIC mode; remove the corresponding hacks.
>
> Remove the use of memory output constraints in gettimeofday.h in favor
> of "memory" clobbers. The resulting code is identical for the current
> use cases, as the system call is usually a terminal fallback anyway,
> and it merely complicates the macroization.
>
> This patch adds only a handful of more lines of code than it removes,
> and in fact could be made substantially smaller by removing the macros
> for the argument counts that aren't currently used, however, it seems
> better to be general from the start.
>
> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>

[...]

> diff --git a/arch/x86/include/asm/vdso/sys_call.h b/arch/x86/include/asm/vdso/sys_call.h
> new file mode 100644
> index 000000000000..6b1fbcdcbd5c
> --- /dev/null
> +++ b/arch/x86/include/asm/vdso/sys_call.h
> @@ -0,0 +1,119 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Macros for issuing an inline system call from the vDSO.
> + */
> +
> +#ifndef X86_ASM_VDSO_SYS_CALL_H
> +#define X86_ASM_VDSO_SYS_CALL_H
> +
> +#include <linux/compiler.h>
> +#include <asm/cpufeatures.h>
> +#include <asm/alternative.h>
> +
> +/*
> + * Note: only three arguments are currently supported,
> + * because there are no constraint letters for r10, r8, r9.

The above comment does not apply when using local variables associated
with a register.

> + */
> +#ifdef CONFIG_X86_64
> +/* Using dummy output registers instead of clobbers avoids messing up
> +   user-specified clobbers. */
> +#define __sys_instr    "syscall"
> +#define __sys_clobber  "rcx", "r11", "memory"
> +#define __sys_nr(x,y)  __NR_ ## x
> +#define __sys_reg1     "rdi"
> +#define __sys_reg2     "rsi"
> +#define __sys_reg3     "rdx"
> +#define __sys_reg4     "r10"
> +#define __sys_reg5     "r8"
> +#define __sys_reg6     "r9"
> +#else
> +#define __sys_instr    "call __kernel_vsyscall"
> +#define __sys_clobber  "memory"
> +#define __sys_nr(x,y)  __NR_ ## x ## y
> +#define __sys_reg1     "ebx"
> +#define __sys_reg2     "ecx"
> +#define __sys_reg3     "edx"
> +#define __sys_reg4     "esi"
> +#define __sys_reg5     "edi"
> +#define __sys_reg6     "ebp"
> +#endif

[...]

> +#define VDSO_SYSCALL6(name,suf32,a1,a2,a3,a4,a5,a6)                    \
> +       ({                                                              \
> +               register long _sys_arg1 asm(__sys_reg1) = (long)(a1);   \
> +               register long _sys_arg2 asm(__sys_reg2) = (long)(a2);   \
> +               register long _sys_arg3 asm(__sys_reg3) = (long)(a3);   \
> +               register long _sys_arg4 asm(__sys_reg4) = (long)(a4);   \
> +               register long _sys_arg5 asm(__sys_reg5) = (long)(a5);   \
> +               register long _sys_arg6 asm(__sys_reg6) = (long)(a6);   \
> +               _VDSO_SYSCALL(name,suf32,                               \
> +                             "r" (_sys_arg1), "r" (_sys_arg2),         \
> +                             "r" (_sys_arg3), "r" (_sys_arg4),         \
> +                             "r" (_sys_arg5), "r" (_sys_arg6));        \
> +       })

Unfortunately, %ebp is still special with -fno-omit-frame-pointer, so
using "ebp" as _sys_arg6 on 32-bit targets will result in:

error: bp cannot be used in ‘asm’ here

Please see how %ebp register is handled in
arch/x86/include/asm/vmware.h, vmware_hypercall_hb_out() and
vmware_hypercall_hb_in().

Uros.


  reply	other threads:[~2025-11-12 10:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12  4:37 [PATCH v2 0/9] x86/entry/vdso: clean up the vdso build, vdso updates H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 1/9] x86/entry/vdso: rename vdso_image_* to vdso*_image H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 2/9] x86/entry/vdso: refactor the vdso build H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 3/9] x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 4/9] x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 5/9] x86/entry/vdso32: remove open-coded DWARF " H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 6/9] x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 7/9] x86/vdso: abstract out vdso system call internals H. Peter Anvin
2025-11-12 10:31   ` Uros Bizjak [this message]
2025-11-12 21:25     ` H. Peter Anvin
2025-11-13  7:15       ` Uros Bizjak
2025-11-14  4:40         ` H. Peter Anvin
2025-11-14 21:08           ` H. Peter Anvin
2025-11-14  4:48         ` H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 8/9] x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 H. Peter Anvin
2025-11-12  4:37 ` [PATCH v2 9/9] x86/entry/vdso32: when using int $0x80, use it directly H. Peter Anvin

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='CAFULd4aMOueG5y3K7F57ryLtt-JUhE-yfsDODC=5+bgjF_gtSw@mail.gmail.com' \
    --to=ubizjak@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=jarkko@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namcao@linutronix.de \
    --cc=oleg@redhat.com \
    --cc=perry.yuan@amd.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=thuth@redhat.com \
    --cc=tytso@mit.edu \
    --cc=x86@kernel.org \
    --cc=xin@zytor.com \
    /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