[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y89C+h4Fz4tvjbx5@biznet-home.integral.gnuweeb.org>
Date: Tue, 24 Jan 2023 09:31:22 +0700
From: Ammar Faizi <ammarfaizi2@...weeb.org>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: x86 Mailing List <x86@...nel.org>,
Dave Hansen <dave.hansen@...el.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Xin Li <xin3.li@...el.com>,
Thomas Gleixner <tglx@...utronix.de>,
Andrew Cooper <Andrew.Cooper3@...rix.com>,
Brian Gerst <brgerst@...il.com>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Peter Zijlstra <peterz@...radead.org>,
Shuah Khan <shuah@...nel.org>, Ingo Molnar <mingo@...nel.org>,
Andy Lutomirski <luto@...nel.org>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Linux Kselftest Mailing List
<linux-kselftest@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [RFC PATCH v1 1/2] selftests/x86: sysret_rip: Handle syscall in
a FRED system
On Mon, Jan 23, 2023 at 05:40:23PM -0800, H. Peter Anvin wrote:
> On 1/23/23 16:26, Ammar Faizi wrote:
> > +
> > +static long do_syscall(long nr_syscall, unsigned long arg1, unsigned long arg2,
> > + unsigned long arg3, unsigned long arg4,
> > + unsigned long arg5, unsigned long arg6)
> > +{
> > + register unsigned long r11 asm("%r11");
> > + register unsigned long r10 asm("%r10");
> > + register unsigned long r8 asm("%r8");
> > + register unsigned long r9 asm("%r9");
> > + unsigned long rcx, rbx;
> > +
> > + r11 = r11_sentinel;
> > + rcx = rcx_sentinel;
> > + r10 = arg4;
> > + r8 = arg5;
> > + r9 = arg6;
> > +
> > + asm volatile (
> > + "movq -8(%%rsp), %%r12\n\t" /* Don't clobber redzone. */
> > + "pushq %[rflags_sentinel]\n\t"
> > + "popf\n\t"
> > + "movq %%r12, -8(%%rsp)\n\t"
> > + "leaq 1f(%%rip), %[rbx]\n\t"
> > + "syscall\n"
> > + "1:"
> > +
> > + : "+a" (nr_syscall),
> > + "+r" (r11),
> > + "+c" (rcx),
> > + [rbx] "=b" (rbx)
> > +
> > + : [rflags_sentinel] "g" (rflags_sentinel),
> > + "D" (arg1), /* %rdi */
> > + "S" (arg2), /* %rsi */
> > + "d" (arg3), /* %rdx */
> > + "r" (r10),
> > + "r" (r8),
> > + "r" (r9)
> > +
> > + : "r12", "memory"
> > + );
> > +
> > + /*
> > + * Test that:
> > + *
> > + * - "syscall" in a FRED system doesn't clobber %rcx and %r11.
> > + * - "syscall" in a non-FRED system sets %rcx=%rip and %r11=%rflags.
> > + *
> > + */
> > + assert(check_regs_result(r11, rcx, rbx) != REGS_ERROR);
> > + return nr_syscall;
> > +}
> > +
>
> So as per Andrew's comment, add:
>
> register void * rsp asm("%rsp");
>
> ...
>
> "+r" (rsp) /* clobber the redzone */
>
> ... as the right way to avoid redzone problems.
Fixed in v2.
--
Ammar Faizi
Powered by blists - more mailing lists