From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB9F754763; Thu, 9 Jul 2026 02:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783565109; cv=none; b=WVa96foT+gpLie8AWNQK2/d4pLK519EGb59hlhYciH0ziFfXHQJG5YfCTXWH82rFy4naGslpKByjsK10xM6RpCSUF5QSg2jaNXVfd0aECH61dKAVIfQ1iZHfgKxiPD3FeqrkannH5Lr+RQWX1q+TxME1qKhhnO6mNBuuU/aKgeU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783565109; c=relaxed/simple; bh=d2f4/3m9Um6Nf7CnB7yBIDQ8aYxSXgAKWGUPpBNAoFI=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=f4iztnsGkBwaESJjl/fy48ugE1E47OL4XQ4buODabzAQKUV300ifrL3H/jpIdZgmUWh8eMHFP+Z3TNpGhQj7mHE6Onogw0R3FuZ8HXdj30tItqnE1OK16nCSb3PRR1eQqYrKE+YFGKU7J5nTZrPz/EWfB4IEY2obKGQQmTNAwvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=vWAJv97f; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="vWAJv97f" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=dcBLjAZIuOcKQn3MTY+bY4X711wnRwuwnS+wCIvAotY=; b=vWAJv97fd4j7v7LNzsA1jn7LpDaj1qwxvv/Lzs0LqF+U5jdju4uyIQO/9pQ/LJxYukNVEgr9E NQoEi0lQj6z3nWKyFlljAYQcLzbsWESODoQ516BnoreEQp50kC1pN6GxxIn6she9WscRAAZsS6n UHY+SgzEAjANoQ5JULImdXU= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4gwfG3311mzmVZr; Thu, 9 Jul 2026 10:35:39 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 14A5440563; Thu, 9 Jul 2026 10:44:54 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 9 Jul 2026 10:44:50 +0800 Message-ID: Date: Thu, 9 Jul 2026 10:44:48 +0800 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [patch 08/18] x86/syscall: Use [syscall_]enter_from_user_mode_randomize_stack() To: Thomas Gleixner , LKML CC: Peter Zijlstra , , Michael Ellerman , Shrikanth Hegde , , Kees Cook , Huacai Chen , , Paul Walmsley , Palmer Dabbelt , , Sven Schnelle , , Mark Rutland , Andy Lutomirski , Oleg Nesterov , Richard Henderson , Russell King , Catalin Marinas , Guo Ren , Geert Uytterhoeven , Thomas Bogendoerfer , Helge Deller , Yoshinori Sato , Richard Weinberger , Chris Zankel , , , , , , , , , Arnd Bergmann , Vineet Gupta , Will Deacon , Brian Cain , Michal Simek , Dinh Nguyen , "David S. Miller" , Andreas Larsson , , , , , , =?UTF-8?Q?Michal_Such=C3=A1nek?= , Jonathan Corbet , References: <20260707181957.433213175@kernel.org> <20260707190254.079478122@kernel.org> From: Jinjie Ruan In-Reply-To: <20260707190254.079478122@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf500011.china.huawei.com (7.185.36.131) On 7/8/2026 3:06 AM, Thomas Gleixner wrote: > These functions integrate the stack randomization. > > syscall_enter_from_user_mode_randomize_stack() has the advantage that the > randomization happens early right after enter_from_user_mode(). > > In both cases also the overhead of get/put_cpu_var() in > add_random_kstack_offset() is avoided. > > No functional change. > > Signed-off-by: Thomas Gleixner > Cc: x86@kernel.org > --- > arch/x86/entry/syscall_32.c | 19 +++++-------------- > arch/x86/entry/syscall_64.c | 3 +-- > arch/x86/include/asm/entry-common.h | 1 - > 3 files changed, 6 insertions(+), 17 deletions(-) Reviewed-by: Jinjie Ruan > > --- a/arch/x86/entry/syscall_32.c > +++ b/arch/x86/entry/syscall_32.c > @@ -142,10 +142,9 @@ static __always_inline bool int80_is_ext > * int80_is_external() below which calls into the APIC driver. > * Identical for soft and external interrupts. > */ > - enter_from_user_mode(regs); > + enter_from_user_mode_randomize_stack(regs); > > instrumentation_begin(); > - add_random_kstack_offset(); > > /* Validate that this is a soft interrupt to the extent possible */ > if (unlikely(int80_is_external())) > @@ -210,11 +209,9 @@ DEFINE_FREDENTRY_RAW(int80_emulation) > { > int nr; > > - enter_from_user_mode(regs); > + enter_from_user_mode_randomize_stack(regs); > > instrumentation_begin(); > - add_random_kstack_offset(); > - > /* > * FRED pushed 0 into regs::orig_ax and regs::ax contains the > * syscall number. > @@ -252,10 +249,10 @@ DEFINE_FREDENTRY_RAW(int80_emulation) > * orig_ax, the int return value truncates it. This matches > * the semantics of syscall_get_nr(). > */ > - nr = syscall_enter_from_user_mode(regs, nr); > + nr = syscall_enter_from_user_mode_randomize_stack(regs, nr); > + > instrumentation_begin(); > > - add_random_kstack_offset(); > do_syscall_32_irqs_on(regs, nr); > > instrumentation_end(); > @@ -268,15 +265,9 @@ static noinstr bool __do_fast_syscall_32 > int nr = syscall_32_enter(regs); > int res; > > - /* > - * This cannot use syscall_enter_from_user_mode() as it has to > - * fetch EBP before invoking any of the syscall entry work > - * functions. > - */ > - enter_from_user_mode(regs); > + enter_from_user_mode_randomize_stack(regs); > > instrumentation_begin(); > - add_random_kstack_offset(); > local_irq_enable(); > /* Fetch EBP from where the vDSO stashed it. */ > if (IS_ENABLED(CONFIG_X86_64)) { > --- a/arch/x86/entry/syscall_64.c > +++ b/arch/x86/entry/syscall_64.c > @@ -86,10 +86,9 @@ static __always_inline bool do_syscall_x > /* Returns true to return using SYSRET, or false to use IRET */ > __visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) > { > - nr = syscall_enter_from_user_mode(regs, nr); > + nr = syscall_enter_from_user_mode_randomize_stack(regs, nr); > > instrumentation_begin(); > - add_random_kstack_offset(); > > if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr != -1) { > /* Invalid system call, but still a system call. */ > --- a/arch/x86/include/asm/entry-common.h > +++ b/arch/x86/include/asm/entry-common.h > @@ -2,7 +2,6 @@ > #ifndef _ASM_X86_ENTRY_COMMON_H > #define _ASM_X86_ENTRY_COMMON_H > > -#include > #include > > #include >