Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 393B0C54E94 for ; Tue, 24 Jan 2023 02:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232195AbjAXCbj (ORCPT ); Mon, 23 Jan 2023 21:31:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbjAXCbh (ORCPT ); Mon, 23 Jan 2023 21:31:37 -0500 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7D59EF0; Mon, 23 Jan 2023 18:31:32 -0800 (PST) Received: from biznet-home.integral.gnuweeb.org (unknown [182.253.88.152]) by gnuweeb.org (Postfix) with ESMTPSA id 2FDF282EF0; Tue, 24 Jan 2023 02:31:25 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674527492; bh=IW8oyeE4wu7owMW/4DM/ie2HFK4Drs3s2h6ZsTjIYy0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AE1p2m2+ZBx54M+Ncmx4HVGgVeCo9bIR+b/BZXnehiQrGCthkOydJj2Ocu8KuZbGj ReXquTvKq5ECYdEGHqpyQM53W3kvSszOgdT7XGz5UDIKSKCjPlqNycXzMmQ4RpGiXp ab9/+neJJFX8dz9thbgW5EDgSKkfZHEMK3TDYdUFEu6qGw2WG+NQ5O62GuoqPriHVX ucWMlRpmqZA9x8kQUWKjsguEF4oZrpdMEltNBGW/7hCurZiky9M0fTxf4VpyCwKoK2 432ZOM/DjbQnIxVuuKbocvlw+6qTUqlD8A0cs028vx6DpR6O8omPTTB+/sUuz+qbL6 263dXJA7ZxU1Q== Date: Tue, 24 Jan 2023 09:31:22 +0700 From: Ammar Faizi To: "H. Peter Anvin" Cc: x86 Mailing List , Dave Hansen , Dave Hansen , Xin Li , Thomas Gleixner , Andrew Cooper , Brian Gerst , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Shuah Khan , Ingo Molnar , Andy Lutomirski , "Kirill A. Shutemov" , Linux Kselftest Mailing List , Linux Kernel Mailing List Subject: Re: [RFC PATCH v1 1/2] selftests/x86: sysret_rip: Handle syscall in a FRED system Message-ID: References: <25b96960-a07e-a952-5c23-786b55054126@zytor.com> <509443c8-e0fd-935f-63d8-7264f5dd3c05@zytor.com> <20230124002625.581323-1-ammarfaizi2@gnuweeb.org> <20230124002625.581323-2-ammarfaizi2@gnuweeb.org> <8f5c24df-514d-5d89-f58f-ec8c3eb1e049@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8f5c24df-514d-5d89-f58f-ec8c3eb1e049@zytor.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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