From nobody Wed Dec 17 23:25:09 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85F4917E8E2 for ; Thu, 13 Mar 2025 18:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890166; cv=none; b=oOIRu6PxhRikzsO6939KV45i12ob/9iB/OaO1wz3v9d7z8pBOMoqRGQqOEmripImymp1vWXFF+/5LYX+k5L17k0xU9WDIdNE6OB+Px1A2u3m7Igb+k8cMc+g2M4rdqxRiI5iRPWWM19PSNDt3t2kkLLp3cNr+UdLA5mSObJZY9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890166; c=relaxed/simple; bh=g4Kuo2CPanqbJ5fBryROh6KFUqZfMSobOEFj6Rycvvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uh2NdMNjgWm0Trg630G00pEBnodj8xVQBeoy8QflIZQZNSAPdwwcwniXTh7/d20zSws7pYXr84SML5GZRAZdfOOjLp/7LZpQDn6pNozevhjbRrLLd6/h5BlaQdCqjdhGeNtvNcUhOmQzm6Yi7o2XP4Ndw55yIIPb9rt0fHF5IWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b2AMyT+P; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b2AMyT+P" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e63c3a53a4cso1123841276.2 for ; Thu, 13 Mar 2025 11:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741890160; x=1742494960; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r249kTrGMfiJdyCvHIqY7lcf73sz6LjLxDDjAJXT47c=; b=b2AMyT+Pv0seaCWh19G3pRjWucd5RO329u+jA1QON9jpo85LY6GdKOgTA+kayu4zmT BfGIKoPq1iNkfyrR+UDi2YTxe1VB7QridXjsAg/GtaSwwJlj2lOo3CfnWYqfQ2lm6oZa UO0XBJcjJ+hxOSp6YVEK3fmbImcf5SKEN6912kGMPtGM3Qs8W20zalpTBvX7RIS2pIiX AcrYGUyqOrCy+jBhjXd3nRhOFtzOy1qZnbIGHuIuFph1W/mZfDsKLUyCvIiQ48P+SDrf hrV8lZQzmAB/7OFVN+05XCM9oUpAdJF5/3DpUqRHhsSHkrgZiuzePse0NRuLBY87158Z q8Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741890160; x=1742494960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r249kTrGMfiJdyCvHIqY7lcf73sz6LjLxDDjAJXT47c=; b=nOITefpwOkU9qoI8TA0i7SIsRg1AoORwQYrQUqPR6d/Rnj+g2ACXChUutkFEMs56jH +pZ6VzW3qLgTCNkyGQCsx57Q52jwFN47Q7qQoihGb4vSpo8wtCgxR8TBJvijha0kwhsT 4gnWrUJzxQNgfSUPwdf321FpkSYZUXawr4+kHHbAWUoBeHAibDzA21M9yzJRTH+hobFz 1OPBW64pNjNuBBgudJ9oKJQiNE7Dp1+mmngOQa/9B4Bx40Jkcoxf+b0FZGm+HcWxgR2Y V+rP8K1fJRZYKYJzsn5kbHnZT6nBUYG5XNo+z5KuKAoncsMiqOKmDM8SNrtaPaVEKd/D izow== X-Gm-Message-State: AOJu0YwXQQCI+HxKXTo1CdnJLDYEX3BMJNJLTAjFKCcSjmRuIjYxi+WT PwjqchmLdrXtliawKLu5GZdvM+WuTwGBKCkZDikDrZHON3oIXqzCh68E X-Gm-Gg: ASbGncsvdBxELTrQliTQoLRTXc/r+QRXlAIoocv95WpURzu78RMzhjtQ78JFEdSLP/f oexNE4jt6oTsS7Sr/1iCTHwaFWiKAb0oD82laVuHJUKhczOQmN1dJgVCbf1kax44YF5AaQF5EU9 4pw0apAUxue6psSnGM5BKj8w1FXftt86g0dI6pgbAegA3ZsdbxkMvE/duX6ibuXn6ExdptlmN4q 2LjilwY+bGIL5QtYtmbK/eH5qfbgsqi600RIbXQyFIz2O9YfqWP2nVSh5NjDyGiDh/VLfI3iB2y il0e1mxwYYVyjXAZVQkS5kqBLnH7pEYiOAd8 X-Google-Smtp-Source: AGHT+IEhb5zRpnSbW+CPM9ho/zNMlWHLm+SLOGqkvx+9244XZjARw7mgTV97uqXDMfpg6SlvLJqCEw== X-Received: by 2002:a05:690c:45c8:b0:6fb:4fee:6044 with SMTP id 00721157ae682-6ff43539961mr438647b3.15.1741890160624; Thu, 13 Mar 2025 11:22:40 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ff3288f0absm4910347b3.54.2025.03.13.11.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 11:22:40 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Juergen Gross , Boris Ostrovsky , Brian Gerst Subject: [PATCH 1/5] x86/xen: Move Xen upcall handler Date: Thu, 13 Mar 2025 14:22:32 -0400 Message-ID: <20250313182236.655724-2-brgerst@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313182236.655724-1-brgerst@gmail.com> References: <20250313182236.655724-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the upcall handler to Xen-specific files. No functional changes. Signed-off-by: Brian Gerst Cc: Juergen Gross Cc: Boris Ostrovsky --- arch/x86/entry/common.c | 72 ------------------------------------- arch/x86/xen/enlighten_pv.c | 46 ++++++++++++++++++++++++ include/xen/xen-ops.h | 19 ++++++++++ 3 files changed, 65 insertions(+), 72 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 3514bf2978ee..ce4d88eda693 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -21,11 +21,6 @@ #include #include =20 -#ifdef CONFIG_XEN_PV -#include -#include -#endif - #include #include #include @@ -455,70 +450,3 @@ SYSCALL_DEFINE0(ni_syscall) { return -ENOSYS; } - -#ifdef CONFIG_XEN_PV -#ifndef CONFIG_PREEMPTION -/* - * Some hypercalls issued by the toolstack can take many 10s of - * seconds. Allow tasks running hypercalls via the privcmd driver to - * be voluntarily preempted even if full kernel preemption is - * disabled. - * - * Such preemptible hypercalls are bracketed by - * xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() - * calls. - */ -DEFINE_PER_CPU(bool, xen_in_preemptible_hcall); -EXPORT_SYMBOL_GPL(xen_in_preemptible_hcall); - -/* - * In case of scheduling the flag must be cleared and restored after - * returning from schedule as the task might move to a different CPU. - */ -static __always_inline bool get_and_clear_inhcall(void) -{ - bool inhcall =3D __this_cpu_read(xen_in_preemptible_hcall); - - __this_cpu_write(xen_in_preemptible_hcall, false); - return inhcall; -} - -static __always_inline void restore_inhcall(bool inhcall) -{ - __this_cpu_write(xen_in_preemptible_hcall, inhcall); -} -#else -static __always_inline bool get_and_clear_inhcall(void) { return false; } -static __always_inline void restore_inhcall(bool inhcall) { } -#endif - -static void __xen_pv_evtchn_do_upcall(struct pt_regs *regs) -{ - struct pt_regs *old_regs =3D set_irq_regs(regs); - - inc_irq_stat(irq_hv_callback_count); - - xen_evtchn_do_upcall(); - - set_irq_regs(old_regs); -} - -__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) -{ - irqentry_state_t state =3D irqentry_enter(regs); - bool inhcall; - - instrumentation_begin(); - run_sysvec_on_irqstack_cond(__xen_pv_evtchn_do_upcall, regs); - - inhcall =3D get_and_clear_inhcall(); - if (inhcall && !WARN_ON_ONCE(state.exit_rcu)) { - irqentry_exit_cond_resched(); - instrumentation_end(); - restore_inhcall(inhcall); - } else { - instrumentation_end(); - irqentry_exit(regs, state); - } -} -#endif /* CONFIG_XEN_PV */ diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 5e57835e999d..af9e43c47b07 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -73,6 +73,7 @@ #include #include #include +#include #ifdef CONFIG_X86_IOPL_IOPERM #include #endif @@ -94,6 +95,21 @@ void *xen_initial_gdt; static int xen_cpu_up_prepare_pv(unsigned int cpu); static int xen_cpu_dead_pv(unsigned int cpu); =20 +#ifndef CONFIG_PREEMPTION +/* + * Some hypercalls issued by the toolstack can take many 10s of + * seconds. Allow tasks running hypercalls via the privcmd driver to + * be voluntarily preempted even if full kernel preemption is + * disabled. + * + * Such preemptible hypercalls are bracketed by + * xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() + * calls. + */ +DEFINE_PER_CPU(bool, xen_in_preemptible_hcall); +EXPORT_SYMBOL_GPL(xen_in_preemptible_hcall); +#endif + struct tls_descs { struct desc_struct desc[3]; }; @@ -687,6 +703,36 @@ DEFINE_IDTENTRY_RAW(xenpv_exc_machine_check) } #endif =20 +static void __xen_pv_evtchn_do_upcall(struct pt_regs *regs) +{ + struct pt_regs *old_regs =3D set_irq_regs(regs); + + inc_irq_stat(irq_hv_callback_count); + + xen_evtchn_do_upcall(); + + set_irq_regs(old_regs); +} + +__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) +{ + irqentry_state_t state =3D irqentry_enter(regs); + bool inhcall; + + instrumentation_begin(); + run_sysvec_on_irqstack_cond(__xen_pv_evtchn_do_upcall, regs); + + inhcall =3D get_and_clear_inhcall(); + if (inhcall && !WARN_ON_ONCE(state.exit_rcu)) { + irqentry_exit_cond_resched(); + instrumentation_end(); + restore_inhcall(inhcall); + } else { + instrumentation_end(); + irqentry_exit(regs, state); + } +} + struct trap_array_entry { void (*orig)(void); void (*xen)(void); diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 47f11bec5e90..174ef8e4600f 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -208,10 +208,29 @@ static inline void xen_preemptible_hcall_end(void) __this_cpu_write(xen_in_preemptible_hcall, false); } =20 +/* + * In case of scheduling the flag must be cleared and restored after + * returning from schedule as the task might move to a different CPU. + */ +static __always_inline bool get_and_clear_inhcall(void) +{ + bool inhcall =3D __this_cpu_read(xen_in_preemptible_hcall); + + __this_cpu_write(xen_in_preemptible_hcall, false); + return inhcall; +} + +static __always_inline void restore_inhcall(bool inhcall) +{ + __this_cpu_write(xen_in_preemptible_hcall, inhcall); +} + #else =20 static inline void xen_preemptible_hcall_begin(void) { } static inline void xen_preemptible_hcall_end(void) { } +static __always_inline bool get_and_clear_inhcall(void) { return false; } +static __always_inline void restore_inhcall(bool inhcall) { } =20 #endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */ =20 --=20 2.48.1 From nobody Wed Dec 17 23:25:09 2025 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 496851F0E27 for ; Thu, 13 Mar 2025 18:22:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890171; cv=none; b=FxudQTs41QqnUu5MDj/BBTg79Qyudt9L6aQOxla/4B+VashQfoiEn5mu72QkE4nkfVYNjTFq5eK1NOMMbCLIX9tSkAdeV9fwA9nEVbVoDO4ahMbeayGru5KgH63DDuWcLg/PhkdNb4r+nmJCQp09a57q6SS2Nmc3b+J5s4/15KQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890171; c=relaxed/simple; bh=Ih/15p3e+YusF5SBfkMrut+LZSUneG59jPziLo5dmRE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a3Se9KcsxRxYTMyZzehxwkLCn2Xd4a27Xe2fq/vJavlQnIZM/kuygmQEcfdpKzbCmncOiGZ+e6kMng9glb4yqS9z1wwvez14qHT8WFs4hm/tgylN12enRwcdl/K67FmaU7M+aOFHvJzbqNefaojRDjSNRznhZ8hOdDSqqG3NrF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=glhJFjHC; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="glhJFjHC" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-6ff0c9d1761so12180647b3.1 for ; Thu, 13 Mar 2025 11:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741890163; x=1742494963; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+A1kHXEAvFzpWlz21OYBee4KubY/kyVNoRGmvJidEss=; b=glhJFjHCuzAVzxT6M9PSVh/lxasWFbwnpKpXEd7Oa7/+iQ4s1/REdFhn45/YGWg113 D6WGS5M8ND6cYsxhwiFG8t6q98NwVUiLOmH+tJwng3825mM0Bd0QbHblX8t8zaNp2dse RhwyCj4HdlgB+rX2Sb2XyzkFsAUxyelTdyPuHN0JAjAk92NCozyxlSEq63xw4vr41UdI A48y7BtceUayP6T7M2QRoD6MKq5kiPE98Bb9+TaKJKEh3B6FQ0hTtffApL4cOfwfA8MO ziEvIPgKsaLz0C70Kos3taCh0hg0jzcfz/8+vo/h9XctOgUc14ks1PUkFXOZfZ9Y5KOg EmNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741890163; x=1742494963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+A1kHXEAvFzpWlz21OYBee4KubY/kyVNoRGmvJidEss=; b=GCMBhiPEaH0TrDEBEOTBYcaFMR7uBBVnODAmhslbu+a9w67ifw9SpQu59cGbl8BzT3 +8WKRqNa4x+AUQuvfYru3vPUkCUmLBXNh/8ZcLJOlVqv+i4Qm8ZiAmIGjyZ+xllVAesk 9LOP0EH38ee7QuWZLoATk4CcOc3l/7DDasIL7SziegHNFGj6l/HoXpnoRmnnnlbqKk5T HXswTOg3KCPvb0tW5nro5cDXwxnv5S+KrZRG3u4uv3wtB8XQpkla6es2Cb7xBYFmbHlT 3nJ72G1wKLUJMllNIJO0/HWGaX9EdLGd82y88qKp6bH/n2sQTkN31kS6dft38SsvUs6R 9CJw== X-Gm-Message-State: AOJu0Yzs4B89lECRj974H8kL4apwbfGoGcJpInspL5UT4JBBVPQm8BYE F+9X0wCA36vwYXz2KoEcWVsYjvnnnn0QoessjFoDLRfDTcSJ21G2inZS X-Gm-Gg: ASbGncv+EM5sM6jQI2IyntJCs04ns4BhzGkyi1HSrB9hl92VH+FKQbW+33MPxDiEdyf +yLtmHWFEW8g8kcH3zo3mkY1YnVhT/NhY0P7FnYjD+Ij7HP9+/NNY9qN4IkY48+jSz+WX+uW7RC x1N+vpnNco5X4Wpg9G06ucfj/PBJ2q2jnLN7stwdiYqtCus2bC5CwzVeq/7kKiE+F2xFUiELIre Gpso6+oAKU4Axp4ODvN6grqqZ003BKNBzV1qR98BM1lpcCmVwpTvPezPuqC0N0bJ0RfirbB1XV2 hn+qNy2D0XDQjaerjLIkECPK6A== X-Google-Smtp-Source: AGHT+IFRlyXzA7o0jrl0P5fDVCba5QQzgZPf1rtm6v9nS3SupVujqQHIg6rTkr8AlnUnb4BoXj3HHQ== X-Received: by 2002:a05:690c:25c3:b0:6f7:50b7:8fe0 with SMTP id 00721157ae682-6ff41f0c834mr8999407b3.1.1741890161864; Thu, 13 Mar 2025 11:22:41 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ff3288f0absm4910347b3.54.2025.03.13.11.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 11:22:41 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Juergen Gross , Boris Ostrovsky , Brian Gerst Subject: [PATCH 2/5] x86/syscall/32: Move 32-bit syscall dispatch code Date: Thu, 13 Mar 2025 14:22:33 -0400 Message-ID: <20250313182236.655724-3-brgerst@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313182236.655724-1-brgerst@gmail.com> References: <20250313182236.655724-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the 32-bit syscall dispatch code to syscall_32.c. No functional changes. Signed-off-by: Brian Gerst --- arch/x86/entry/Makefile | 2 + arch/x86/entry/common.c | 321 ---------------------------------- arch/x86/entry/syscall_32.c | 336 +++++++++++++++++++++++++++++++++++- 3 files changed, 336 insertions(+), 323 deletions(-) diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile index ce1cc1622385..96a6b86e0a8b 100644 --- a/arch/x86/entry/Makefile +++ b/arch/x86/entry/Makefile @@ -8,8 +8,10 @@ UBSAN_SANITIZE :=3D n KCOV_INSTRUMENT :=3D n =20 CFLAGS_REMOVE_common.o =3D $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_syscall_32.o =3D $(CC_FLAGS_FTRACE) =20 CFLAGS_common.o +=3D -fno-stack-protector +CFLAGS_syscall_32.o +=3D -fno-stack-protector =20 obj-y :=3D entry.o entry_$(BITS).o syscall_$(BITS).o obj-y +=3D common.o diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index ce4d88eda693..183efabefe57 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -125,327 +125,6 @@ __visible noinstr bool do_syscall_64(struct pt_regs *= regs, int nr) } #endif =20 -#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) -static __always_inline int syscall_32_enter(struct pt_regs *regs) -{ - if (IS_ENABLED(CONFIG_IA32_EMULATION)) - current_thread_info()->status |=3D TS_COMPAT; - - return (int)regs->orig_ax; -} - -#ifdef CONFIG_IA32_EMULATION -bool __ia32_enabled __ro_after_init =3D !IS_ENABLED(CONFIG_IA32_EMULATION_= DEFAULT_DISABLED); - -static int __init ia32_emulation_override_cmdline(char *arg) -{ - return kstrtobool(arg, &__ia32_enabled); -} -early_param("ia32_emulation", ia32_emulation_override_cmdline); -#endif - -/* - * Invoke a 32-bit syscall. Called with IRQs on in CT_STATE_KERNEL. - */ -static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, in= t nr) -{ - /* - * Convert negative numbers to very high and thus out of range - * numbers for comparisons. - */ - unsigned int unr =3D nr; - - if (likely(unr < IA32_NR_syscalls)) { - unr =3D array_index_nospec(unr, IA32_NR_syscalls); - regs->ax =3D ia32_sys_call(regs, unr); - } else if (nr !=3D -1) { - regs->ax =3D __ia32_sys_ni_syscall(regs); - } -} - -#ifdef CONFIG_IA32_EMULATION -static __always_inline bool int80_is_external(void) -{ - const unsigned int offs =3D (0x80 / 32) * 0x10; - const u32 bit =3D BIT(0x80 % 32); - - /* The local APIC on XENPV guests is fake */ - if (cpu_feature_enabled(X86_FEATURE_XENPV)) - return false; - - /* - * If vector 0x80 is set in the APIC ISR then this is an external - * interrupt. Either from broken hardware or injected by a VMM. - * - * Note: In guest mode this is only valid for secure guests where - * the secure module fully controls the vAPIC exposed to the guest. - */ - return apic_read(APIC_ISR + offs) & bit; -} - -/** - * do_int80_emulation - 32-bit legacy syscall C entry from asm - * @regs: syscall arguments in struct pt_args on the stack. - * - * This entry point can be used by 32-bit and 64-bit programs to perform - * 32-bit system calls. Instances of INT $0x80 can be found inline in - * various programs and libraries. It is also used by the vDSO's - * __kernel_vsyscall fallback for hardware that doesn't support a faster - * entry method. Restarted 32-bit system calls also fall back to INT - * $0x80 regardless of what instruction was originally used to do the - * system call. - * - * This is considered a slow path. It is not used by most libc - * implementations on modern hardware except during process startup. - * - * The arguments for the INT $0x80 based syscall are on stack in the - * pt_regs structure: - * eax: system call number - * ebx, ecx, edx, esi, edi, ebp: arg1 - arg 6 - */ -__visible noinstr void do_int80_emulation(struct pt_regs *regs) -{ - int nr; - - /* Kernel does not use INT $0x80! */ - if (unlikely(!user_mode(regs))) { - irqentry_enter(regs); - instrumentation_begin(); - panic("Unexpected external interrupt 0x80\n"); - } - - /* - * Establish kernel context for instrumentation, including for - * int80_is_external() below which calls into the APIC driver. - * Identical for soft and external interrupts. - */ - enter_from_user_mode(regs); - - instrumentation_begin(); - add_random_kstack_offset(); - - /* Validate that this is a soft interrupt to the extent possible */ - if (unlikely(int80_is_external())) - panic("Unexpected external interrupt 0x80\n"); - - /* - * The low level idtentry code pushed -1 into regs::orig_ax - * and regs::ax contains the syscall number. - * - * User tracing code (ptrace or signal handlers) might assume - * that the regs::orig_ax contains a 32-bit number on invoking - * a 32-bit syscall. - * - * Establish the syscall convention by saving the 32bit truncated - * syscall number in regs::orig_ax and by invalidating regs::ax. - */ - regs->orig_ax =3D regs->ax & GENMASK(31, 0); - regs->ax =3D -ENOSYS; - - nr =3D syscall_32_enter(regs); - - local_irq_enable(); - nr =3D syscall_enter_from_user_mode_work(regs, nr); - do_syscall_32_irqs_on(regs, nr); - - instrumentation_end(); - syscall_exit_to_user_mode(regs); -} - -#ifdef CONFIG_X86_FRED -/* - * A FRED-specific INT80 handler is warranted for the follwing reasons: - * - * 1) As INT instructions and hardware interrupts are separate event - * types, FRED does not preclude the use of vector 0x80 for external - * interrupts. As a result, the FRED setup code does not reserve - * vector 0x80 and calling int80_is_external() is not merely - * suboptimal but actively incorrect: it could cause a system call - * to be incorrectly ignored. - * - * 2) It is called only for handling vector 0x80 of event type - * EVENT_TYPE_SWINT and will never be called to handle any external - * interrupt (event type EVENT_TYPE_EXTINT). - * - * 3) FRED has separate entry flows depending on if the event came from - * user space or kernel space, and because the kernel does not use - * INT insns, the FRED kernel entry handler fred_entry_from_kernel() - * falls through to fred_bad_type() if the event type is - * EVENT_TYPE_SWINT, i.e., INT insns. So if the kernel is handling - * an INT insn, it can only be from a user level. - * - * 4) int80_emulation() does a CLEAR_BRANCH_HISTORY. While FRED will - * likely take a different approach if it is ever needed: it - * probably belongs in either fred_intx()/ fred_other() or - * asm_fred_entrypoint_user(), depending on if this ought to be done - * for all entries from userspace or only system - * calls. - * - * 5) INT $0x80 is the fast path for 32-bit system calls under FRED. - */ -DEFINE_FREDENTRY_RAW(int80_emulation) -{ - int nr; - - enter_from_user_mode(regs); - - instrumentation_begin(); - add_random_kstack_offset(); - - /* - * FRED pushed 0 into regs::orig_ax and regs::ax contains the - * syscall number. - * - * User tracing code (ptrace or signal handlers) might assume - * that the regs::orig_ax contains a 32-bit number on invoking - * a 32-bit syscall. - * - * Establish the syscall convention by saving the 32bit truncated - * syscall number in regs::orig_ax and by invalidating regs::ax. - */ - regs->orig_ax =3D regs->ax & GENMASK(31, 0); - regs->ax =3D -ENOSYS; - - nr =3D syscall_32_enter(regs); - - local_irq_enable(); - nr =3D syscall_enter_from_user_mode_work(regs, nr); - do_syscall_32_irqs_on(regs, nr); - - instrumentation_end(); - syscall_exit_to_user_mode(regs); -} -#endif -#else /* CONFIG_IA32_EMULATION */ - -/* Handles int $0x80 on a 32bit kernel */ -__visible noinstr void do_int80_syscall_32(struct pt_regs *regs) -{ - int nr =3D syscall_32_enter(regs); - - add_random_kstack_offset(); - /* - * Subtlety here: if ptrace pokes something larger than 2^31-1 into - * orig_ax, the int return value truncates it. This matches - * the semantics of syscall_get_nr(). - */ - nr =3D syscall_enter_from_user_mode(regs, nr); - instrumentation_begin(); - - do_syscall_32_irqs_on(regs, nr); - - instrumentation_end(); - syscall_exit_to_user_mode(regs); -} -#endif /* !CONFIG_IA32_EMULATION */ - -static noinstr bool __do_fast_syscall_32(struct pt_regs *regs) -{ - int nr =3D syscall_32_enter(regs); - int res; - - add_random_kstack_offset(); - /* - * This cannot use syscall_enter_from_user_mode() as it has to - * fetch EBP before invoking any of the syscall entry work - * functions. - */ - syscall_enter_from_user_mode_prepare(regs); - - instrumentation_begin(); - /* Fetch EBP from where the vDSO stashed it. */ - if (IS_ENABLED(CONFIG_X86_64)) { - /* - * Micro-optimization: the pointer we're following is - * explicitly 32 bits, so it can't be out of range. - */ - res =3D __get_user(*(u32 *)®s->bp, - (u32 __user __force *)(unsigned long)(u32)regs->sp); - } else { - res =3D get_user(*(u32 *)®s->bp, - (u32 __user __force *)(unsigned long)(u32)regs->sp); - } - - if (res) { - /* User code screwed up. */ - regs->ax =3D -EFAULT; - - local_irq_disable(); - instrumentation_end(); - irqentry_exit_to_user_mode(regs); - return false; - } - - nr =3D syscall_enter_from_user_mode_work(regs, nr); - - /* Now this is just like a normal syscall. */ - do_syscall_32_irqs_on(regs, nr); - - instrumentation_end(); - syscall_exit_to_user_mode(regs); - return true; -} - -/* Returns true to return using SYSEXIT/SYSRETL, or false to use IRET */ -__visible noinstr bool do_fast_syscall_32(struct pt_regs *regs) -{ - /* - * Called using the internal vDSO SYSENTER/SYSCALL32 calling - * convention. Adjust regs so it looks like we entered using int80. - */ - unsigned long landing_pad =3D (unsigned long)current->mm->context.vdso + - vdso_image_32.sym_int80_landing_pad; - - /* - * SYSENTER loses EIP, and even SYSCALL32 needs us to skip forward - * so that 'regs->ip -=3D 2' lands back on an int $0x80 instruction. - * Fix it up. - */ - regs->ip =3D landing_pad; - - /* Invoke the syscall. If it failed, keep it simple: use IRET. */ - if (!__do_fast_syscall_32(regs)) - return false; - - /* - * Check that the register state is valid for using SYSRETL/SYSEXIT - * to exit to userspace. Otherwise use the slower but fully capable - * IRET exit path. - */ - - /* XEN PV guests always use the IRET path */ - if (cpu_feature_enabled(X86_FEATURE_XENPV)) - return false; - - /* EIP must point to the VDSO landing pad */ - if (unlikely(regs->ip !=3D landing_pad)) - return false; - - /* CS and SS must match the values set in MSR_STAR */ - if (unlikely(regs->cs !=3D __USER32_CS || regs->ss !=3D __USER_DS)) - return false; - - /* If the TF, RF, or VM flags are set, use IRET */ - if (unlikely(regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF | X86_EFLAGS_VM= ))) - return false; - - /* Use SYSRETL/SYSEXIT to exit to userspace */ - return true; -} - -/* Returns true to return using SYSEXIT/SYSRETL, or false to use IRET */ -__visible noinstr bool do_SYSENTER_32(struct pt_regs *regs) -{ - /* SYSENTER loses RSP, but the vDSO saved it in RBP. */ - regs->sp =3D regs->bp; - - /* SYSENTER clobbers EFLAGS.IF. Assume it was set in usermode. */ - regs->flags |=3D X86_EFLAGS_IF; - - return do_fast_syscall_32(regs); -} -#endif - SYSCALL_DEFINE0(ni_syscall) { return -ENOSYS; diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index 8cc9950d7104..7c286e89fd04 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -1,10 +1,23 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for i386. */ +// SPDX-License-Identifier: GPL-2.0-only +/* + * 32-bit system call dispatch + * + * Copyright (c) 2015 Andrew Lutomirski + * + * Based on asm and ptrace code by many authors. The code here originated + * in ptrace.c and signal.c. + */ =20 #include #include #include #include +#include +#include +#include +#include +#include +#include #include =20 #ifdef CONFIG_IA32_EMULATION @@ -42,3 +55,322 @@ long ia32_sys_call(const struct pt_regs *regs, unsigned= int nr) default: return __ia32_sys_ni_syscall(regs); } }; + +static __always_inline int syscall_32_enter(struct pt_regs *regs) +{ + if (IS_ENABLED(CONFIG_IA32_EMULATION)) + current_thread_info()->status |=3D TS_COMPAT; + + return (int)regs->orig_ax; +} + +#ifdef CONFIG_IA32_EMULATION +bool __ia32_enabled __ro_after_init =3D !IS_ENABLED(CONFIG_IA32_EMULATION_= DEFAULT_DISABLED); + +static int __init ia32_emulation_override_cmdline(char *arg) +{ + return kstrtobool(arg, &__ia32_enabled); +} +early_param("ia32_emulation", ia32_emulation_override_cmdline); +#endif + +/* + * Invoke a 32-bit syscall. Called with IRQs on in CT_STATE_KERNEL. + */ +static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, in= t nr) +{ + /* + * Convert negative numbers to very high and thus out of range + * numbers for comparisons. + */ + unsigned int unr =3D nr; + + if (likely(unr < IA32_NR_syscalls)) { + unr =3D array_index_nospec(unr, IA32_NR_syscalls); + regs->ax =3D ia32_sys_call(regs, unr); + } else if (nr !=3D -1) { + regs->ax =3D __ia32_sys_ni_syscall(regs); + } +} + +#ifdef CONFIG_IA32_EMULATION +static __always_inline bool int80_is_external(void) +{ + const unsigned int offs =3D (0x80 / 32) * 0x10; + const u32 bit =3D BIT(0x80 % 32); + + /* The local APIC on XENPV guests is fake */ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return false; + + /* + * If vector 0x80 is set in the APIC ISR then this is an external + * interrupt. Either from broken hardware or injected by a VMM. + * + * Note: In guest mode this is only valid for secure guests where + * the secure module fully controls the vAPIC exposed to the guest. + */ + return apic_read(APIC_ISR + offs) & bit; +} + +/** + * do_int80_emulation - 32-bit legacy syscall C entry from asm + * @regs: syscall arguments in struct pt_args on the stack. + * + * This entry point can be used by 32-bit and 64-bit programs to perform + * 32-bit system calls. Instances of INT $0x80 can be found inline in + * various programs and libraries. It is also used by the vDSO's + * __kernel_vsyscall fallback for hardware that doesn't support a faster + * entry method. Restarted 32-bit system calls also fall back to INT + * $0x80 regardless of what instruction was originally used to do the + * system call. + * + * This is considered a slow path. It is not used by most libc + * implementations on modern hardware except during process startup. + * + * The arguments for the INT $0x80 based syscall are on stack in the + * pt_regs structure: + * eax: system call number + * ebx, ecx, edx, esi, edi, ebp: arg1 - arg 6 + */ +__visible noinstr void do_int80_emulation(struct pt_regs *regs) +{ + int nr; + + /* Kernel does not use INT $0x80! */ + if (unlikely(!user_mode(regs))) { + irqentry_enter(regs); + instrumentation_begin(); + panic("Unexpected external interrupt 0x80\n"); + } + + /* + * Establish kernel context for instrumentation, including for + * int80_is_external() below which calls into the APIC driver. + * Identical for soft and external interrupts. + */ + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* Validate that this is a soft interrupt to the extent possible */ + if (unlikely(int80_is_external())) + panic("Unexpected external interrupt 0x80\n"); + + /* + * The low level idtentry code pushed -1 into regs::orig_ax + * and regs::ax contains the syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax =3D regs->ax & GENMASK(31, 0); + regs->ax =3D -ENOSYS; + + nr =3D syscall_32_enter(regs); + + local_irq_enable(); + nr =3D syscall_enter_from_user_mode_work(regs, nr); + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); +} + +#ifdef CONFIG_X86_FRED +/* + * A FRED-specific INT80 handler is warranted for the follwing reasons: + * + * 1) As INT instructions and hardware interrupts are separate event + * types, FRED does not preclude the use of vector 0x80 for external + * interrupts. As a result, the FRED setup code does not reserve + * vector 0x80 and calling int80_is_external() is not merely + * suboptimal but actively incorrect: it could cause a system call + * to be incorrectly ignored. + * + * 2) It is called only for handling vector 0x80 of event type + * EVENT_TYPE_SWINT and will never be called to handle any external + * interrupt (event type EVENT_TYPE_EXTINT). + * + * 3) FRED has separate entry flows depending on if the event came from + * user space or kernel space, and because the kernel does not use + * INT insns, the FRED kernel entry handler fred_entry_from_kernel() + * falls through to fred_bad_type() if the event type is + * EVENT_TYPE_SWINT, i.e., INT insns. So if the kernel is handling + * an INT insn, it can only be from a user level. + * + * 4) int80_emulation() does a CLEAR_BRANCH_HISTORY. While FRED will + * likely take a different approach if it is ever needed: it + * probably belongs in either fred_intx()/ fred_other() or + * asm_fred_entrypoint_user(), depending on if this ought to be done + * for all entries from userspace or only system + * calls. + * + * 5) INT $0x80 is the fast path for 32-bit system calls under FRED. + */ +DEFINE_FREDENTRY_RAW(int80_emulation) +{ + int nr; + + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* + * FRED pushed 0 into regs::orig_ax and regs::ax contains the + * syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax =3D regs->ax & GENMASK(31, 0); + regs->ax =3D -ENOSYS; + + nr =3D syscall_32_enter(regs); + + local_irq_enable(); + nr =3D syscall_enter_from_user_mode_work(regs, nr); + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); +} +#endif +#else /* CONFIG_IA32_EMULATION */ + +/* Handles int $0x80 on a 32bit kernel */ +__visible noinstr void do_int80_syscall_32(struct pt_regs *regs) +{ + int nr =3D syscall_32_enter(regs); + + add_random_kstack_offset(); + /* + * Subtlety here: if ptrace pokes something larger than 2^31-1 into + * orig_ax, the int return value truncates it. This matches + * the semantics of syscall_get_nr(). + */ + nr =3D syscall_enter_from_user_mode(regs, nr); + instrumentation_begin(); + + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); +} +#endif /* !CONFIG_IA32_EMULATION */ + +static noinstr bool __do_fast_syscall_32(struct pt_regs *regs) +{ + int nr =3D syscall_32_enter(regs); + int res; + + add_random_kstack_offset(); + /* + * This cannot use syscall_enter_from_user_mode() as it has to + * fetch EBP before invoking any of the syscall entry work + * functions. + */ + syscall_enter_from_user_mode_prepare(regs); + + instrumentation_begin(); + /* Fetch EBP from where the vDSO stashed it. */ + if (IS_ENABLED(CONFIG_X86_64)) { + /* + * Micro-optimization: the pointer we're following is + * explicitly 32 bits, so it can't be out of range. + */ + res =3D __get_user(*(u32 *)®s->bp, + (u32 __user __force *)(unsigned long)(u32)regs->sp); + } else { + res =3D get_user(*(u32 *)®s->bp, + (u32 __user __force *)(unsigned long)(u32)regs->sp); + } + + if (res) { + /* User code screwed up. */ + regs->ax =3D -EFAULT; + + local_irq_disable(); + instrumentation_end(); + irqentry_exit_to_user_mode(regs); + return false; + } + + nr =3D syscall_enter_from_user_mode_work(regs, nr); + + /* Now this is just like a normal syscall. */ + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); + return true; +} + +/* Returns true to return using SYSEXIT/SYSRETL, or false to use IRET */ +__visible noinstr bool do_fast_syscall_32(struct pt_regs *regs) +{ + /* + * Called using the internal vDSO SYSENTER/SYSCALL32 calling + * convention. Adjust regs so it looks like we entered using int80. + */ + unsigned long landing_pad =3D (unsigned long)current->mm->context.vdso + + vdso_image_32.sym_int80_landing_pad; + + /* + * SYSENTER loses EIP, and even SYSCALL32 needs us to skip forward + * so that 'regs->ip -=3D 2' lands back on an int $0x80 instruction. + * Fix it up. + */ + regs->ip =3D landing_pad; + + /* Invoke the syscall. If it failed, keep it simple: use IRET. */ + if (!__do_fast_syscall_32(regs)) + return false; + + /* + * Check that the register state is valid for using SYSRETL/SYSEXIT + * to exit to userspace. Otherwise use the slower but fully capable + * IRET exit path. + */ + + /* XEN PV guests always use the IRET path */ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return false; + + /* EIP must point to the VDSO landing pad */ + if (unlikely(regs->ip !=3D landing_pad)) + return false; + + /* CS and SS must match the values set in MSR_STAR */ + if (unlikely(regs->cs !=3D __USER32_CS || regs->ss !=3D __USER_DS)) + return false; + + /* If the TF, RF, or VM flags are set, use IRET */ + if (unlikely(regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF | X86_EFLAGS_VM= ))) + return false; + + /* Use SYSRETL/SYSEXIT to exit to userspace */ + return true; +} + +/* Returns true to return using SYSEXIT/SYSRETL, or false to use IRET */ +__visible noinstr bool do_SYSENTER_32(struct pt_regs *regs) +{ + /* SYSENTER loses RSP, but the vDSO saved it in RBP. */ + regs->sp =3D regs->bp; + + /* SYSENTER clobbers EFLAGS.IF. Assume it was set in usermode. */ + regs->flags |=3D X86_EFLAGS_IF; + + return do_fast_syscall_32(regs); +} --=20 2.48.1 From nobody Wed Dec 17 23:25:09 2025 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6D8A1E8353 for ; Thu, 13 Mar 2025 18:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890167; cv=none; b=Fd6N/Y8SRiR3mQeL4R7IKtXoUV15gdGip9iVY4kTInFyZha+ybTcijdQhKC8yJ+KhXqUOqp9axhK5iQS4pCvHuChcyJNDIwuv6FMtu+h7vaMro4a2PKKrPCJUhrLmViowd/D4x/xZvDFJ18LxgJ9isu5gzIY3/iYS38JnBVjjyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890167; c=relaxed/simple; bh=moN+wU/LJ/MudLZn/5ShH666yGXIqDM/7zexntBbRnE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k7Z3cNK/wtMiz9IfODMZojxlunQLg9QuLh92gCmpk41raEGOJ//xZ5J0SBspbrU2pOh4ADO1sn2LcPR68EPQyo3n0Ik0Zj2pXcswPHjstziZPojBi104Vx+rP1DRgXvbhqEiArK4rrd8XMAk+mjYCBPgji/az4GPfUBT3SRTjOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CFAHh11u; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CFAHh11u" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6ef9b8b4f13so12985497b3.2 for ; Thu, 13 Mar 2025 11:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741890164; x=1742494964; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jHNDYN7puwtfPRioM9eDOR4JOExw68tKK5iB+G+beM4=; b=CFAHh11uwD4/9uBX/teXbLh4Ddi3BRSpgJvtWlGruELv2vkkJWjxr3k7e7yJEnPUad YgoPoWmeo+E8PFmXWLLOk+vPCqc0RxjztQgDoitaXV99jQjEMbcwgz5pBVhQl8aOH7T9 AbzJgvYTbk7TMzUjnWGk+46rDDm5SawZw30n+z7BnGMRThSQY+TtwXgUH3bvxYmTArJr WjsGYsTlWo2T8mso6hGmesmnTLCSeSd7/Qq+iofPZF4iv1Q80b8jOYW9qGXYMQGJytHh jH0dp1DM+FiAgtRxSH+YpLwnpqsIt9WRzf8LIsHWWQ5blbZP4BYj7ZNNHLxYRX9UQV+M +Aqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741890164; x=1742494964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jHNDYN7puwtfPRioM9eDOR4JOExw68tKK5iB+G+beM4=; b=UErrC9kADxRVT7qDFMUE4TUTLqswIaIR0+cZN5vD1tQRBI4i73EWXTPomFGneakR/3 IA+kGjcTkA/StmPsgmSYyLvVxGHtAh8Cro/ZcIIGIf513wVu+lPO3xhxiTgxZz0q4Bpv fWtYcZ35MSbujpm7jKkfBwuirKVv/8KZB7COQ68Dw/ja2mnLp24yazLWVEiJPhxl2bFg voLeq3DqemWgxE7NoV3gvUOFRvao9InKCBGpZdEtemEdCECUtGytReODS1phNv8NQVN6 WcId+PGTsmGKEXW7sxzbBANciaer8TQScwRKZ9m4FHqPjiRCpfNtaTl60rPnSVBXw/cs 3tzw== X-Gm-Message-State: AOJu0Yxnbd5qyPK/XGk6va2V5/MXc2miiYbrI4QC0jsGd/A+qh0QpHAq MQf2+z2CNSBn8iPNaYkTEFWtpYbWKKpE9rBcWQ9g5J5DBm6sMJxHQD6t X-Gm-Gg: ASbGnctnctadJ/ho2AGLLdQWSl4qKcmSYXPYMY1pAR/XHOwY73//+fLjaB8ZmaAboBJ dXuwgs7MwLSJ6hETM5sY3ka0aetK3bHRsX0bCTA+eZsbeGCwfKwgNu3aUUXbXVpRDq5qw3mZdgS VVobk+/LyZmLBNM1G8u8VVzQffr+XPIW/G4QxFmR5EtvVnv5wg0nZyFpgwZBg4piFxLBcIOM514 TdD29An6Z6O7NGMAhlD+M4zw71Kuv3yJ0MszwqAUUidsK+YeUElTjsHsxflVV4mDW1ewWssFNKY bcvls+/DYz+/PemGF2kj3lsnrA== X-Google-Smtp-Source: AGHT+IHDw3iC1bxlby/+x2sfiQCv10ZlXNkqQL3f+hzI0ft5LgVvyAc9xRcHhIdOwcfQVnZ+tcM/jg== X-Received: by 2002:a05:690c:700d:b0:6fe:c021:f745 with SMTP id 00721157ae682-6ff41f03320mr7698957b3.4.1741890164045; Thu, 13 Mar 2025 11:22:44 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ff3288f0absm4910347b3.54.2025.03.13.11.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 11:22:43 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Juergen Gross , Boris Ostrovsky , Brian Gerst Subject: [PATCH 3/5] x86/syscall/64: Move 64-bit syscall dispatch code Date: Thu, 13 Mar 2025 14:22:34 -0400 Message-ID: <20250313182236.655724-4-brgerst@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313182236.655724-1-brgerst@gmail.com> References: <20250313182236.655724-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the 64-bit syscall dispatch code to syscall_64.c. No functional changes. Signed-off-by: Brian Gerst --- arch/x86/entry/Makefile | 2 + arch/x86/entry/common.c | 93 -------------------------------- arch/x86/entry/syscall_64.c | 103 +++++++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 95 deletions(-) diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile index 96a6b86e0a8b..5fd28abfd5a0 100644 --- a/arch/x86/entry/Makefile +++ b/arch/x86/entry/Makefile @@ -9,9 +9,11 @@ KCOV_INSTRUMENT :=3D n =20 CFLAGS_REMOVE_common.o =3D $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_32.o =3D $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_syscall_64.o =3D $(CC_FLAGS_FTRACE) =20 CFLAGS_common.o +=3D -fno-stack-protector CFLAGS_syscall_32.o +=3D -fno-stack-protector +CFLAGS_syscall_64.o +=3D -fno-stack-protector =20 obj-y :=3D entry.o entry_$(BITS).o syscall_$(BITS).o obj-y +=3D common.o diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 183efabefe57..5bd448c0664f 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -32,99 +32,6 @@ #include #include =20 -#ifdef CONFIG_X86_64 - -static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) -{ - /* - * Convert negative numbers to very high and thus out of range - * numbers for comparisons. - */ - unsigned int unr =3D nr; - - if (likely(unr < NR_syscalls)) { - unr =3D array_index_nospec(unr, NR_syscalls); - regs->ax =3D x64_sys_call(regs, unr); - return true; - } - return false; -} - -static __always_inline bool do_syscall_x32(struct pt_regs *regs, int nr) -{ - /* - * Adjust the starting offset of the table, and convert numbers - * < __X32_SYSCALL_BIT to very high and thus out of range - * numbers for comparisons. - */ - unsigned int xnr =3D nr - __X32_SYSCALL_BIT; - - if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(xnr < X32_NR_syscalls)) { - xnr =3D array_index_nospec(xnr, X32_NR_syscalls); - regs->ax =3D x32_sys_call(regs, xnr); - return true; - } - return false; -} - -/* Returns true to return using SYSRET, or false to use IRET */ -__visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) -{ - add_random_kstack_offset(); - nr =3D syscall_enter_from_user_mode(regs, nr); - - instrumentation_begin(); - - if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr !=3D -1)= { - /* Invalid system call, but still a system call. */ - regs->ax =3D __x64_sys_ni_syscall(regs); - } - - instrumentation_end(); - syscall_exit_to_user_mode(regs); - - /* - * Check that the register state is valid for using SYSRET to exit - * to userspace. Otherwise use the slower but fully capable IRET - * exit path. - */ - - /* XEN PV guests always use the IRET path */ - if (cpu_feature_enabled(X86_FEATURE_XENPV)) - return false; - - /* SYSRET requires RCX =3D=3D RIP and R11 =3D=3D EFLAGS */ - if (unlikely(regs->cx !=3D regs->ip || regs->r11 !=3D regs->flags)) - return false; - - /* CS and SS must match the values set in MSR_STAR */ - if (unlikely(regs->cs !=3D __USER_CS || regs->ss !=3D __USER_DS)) - return false; - - /* - * On Intel CPUs, SYSRET with non-canonical RCX/RIP will #GP - * in kernel space. This essentially lets the user take over - * the kernel, since userspace controls RSP. - * - * TASK_SIZE_MAX covers all user-accessible addresses other than - * the deprecated vsyscall page. - */ - if (unlikely(regs->ip >=3D TASK_SIZE_MAX)) - return false; - - /* - * SYSRET cannot restore RF. It can restore TF, but unlike IRET, - * restoring TF results in a trap from userspace immediately after - * SYSRET. - */ - if (unlikely(regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF))) - return false; - - /* Use SYSRET to exit to userspace */ - return true; -} -#endif - SYSCALL_DEFINE0(ni_syscall) { return -ENOSYS; diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index ba8354424860..9e0ba339013c 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -1,10 +1,19 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for x86-64. */ +// SPDX-License-Identifier: GPL-2.0-only +/* + * 64-bit system call dispatch + * + * Copyright (c) 2015 Andrew Lutomirski + * + * Based on asm and ptrace code by many authors. The code here originated + * in ptrace.c and signal.c. + */ =20 #include #include #include #include +#include +#include #include =20 #define __SYSCALL(nr, sym) extern long __x64_##sym(const struct pt_regs *); @@ -34,3 +43,93 @@ long x64_sys_call(const struct pt_regs *regs, unsigned i= nt nr) default: return __x64_sys_ni_syscall(regs); } }; + +static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) +{ + /* + * Convert negative numbers to very high and thus out of range + * numbers for comparisons. + */ + unsigned int unr =3D nr; + + if (likely(unr < NR_syscalls)) { + unr =3D array_index_nospec(unr, NR_syscalls); + regs->ax =3D x64_sys_call(regs, unr); + return true; + } + return false; +} + +static __always_inline bool do_syscall_x32(struct pt_regs *regs, int nr) +{ + /* + * Adjust the starting offset of the table, and convert numbers + * < __X32_SYSCALL_BIT to very high and thus out of range + * numbers for comparisons. + */ + unsigned int xnr =3D nr - __X32_SYSCALL_BIT; + + if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(xnr < X32_NR_syscalls)) { + xnr =3D array_index_nospec(xnr, X32_NR_syscalls); + regs->ax =3D x32_sys_call(regs, xnr); + return true; + } + return false; +} + +/* Returns true to return using SYSRET, or false to use IRET */ +__visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) +{ + add_random_kstack_offset(); + nr =3D syscall_enter_from_user_mode(regs, nr); + + instrumentation_begin(); + + if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr !=3D -1)= { + /* Invalid system call, but still a system call. */ + regs->ax =3D __x64_sys_ni_syscall(regs); + } + + instrumentation_end(); + syscall_exit_to_user_mode(regs); + + /* + * Check that the register state is valid for using SYSRET to exit + * to userspace. Otherwise use the slower but fully capable IRET + * exit path. + */ + + /* XEN PV guests always use the IRET path */ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return false; + + /* SYSRET requires RCX =3D=3D RIP and R11 =3D=3D EFLAGS */ + if (unlikely(regs->cx !=3D regs->ip || regs->r11 !=3D regs->flags)) + return false; + + /* CS and SS must match the values set in MSR_STAR */ + if (unlikely(regs->cs !=3D __USER_CS || regs->ss !=3D __USER_DS)) + return false; + + /* + * On Intel CPUs, SYSRET with non-canonical RCX/RIP will #GP + * in kernel space. This essentially lets the user take over + * the kernel, since userspace controls RSP. + * + * TASK_SIZE_MAX covers all user-accessible addresses other than + * the deprecated vsyscall page. + */ + if (unlikely(regs->ip >=3D TASK_SIZE_MAX)) + return false; + + /* + * SYSRET cannot restore RF. It can restore TF, but unlike IRET, + * restoring TF results in a trap from userspace immediately after + * SYSRET. + */ + if (unlikely(regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF))) + return false; + + /* Use SYSRET to exit to userspace */ + return true; +} --=20 2.48.1 From nobody Wed Dec 17 23:25:09 2025 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 326CE1EE03C for ; Thu, 13 Mar 2025 18:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890168; cv=none; b=pROIxqI81VVSgJw8te5YMSNIoX1B4WUa3JEZLjif0PF/qQocoZ8xoTekdDaQe71rQ73C6Nd5lPbjrZXqhSw4cZFUsDKuM0tWnZ6vHsqdz0nbAmrYt3UMNODQUP0TXON/SB5HVyUSfTznYCNcVHZ2L+lFrjucTKgMuVxdyDNYFRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890168; c=relaxed/simple; bh=RlmYxCnBs/rCFIxe+5Q68BKDzVQHKXU407Jp3ZZc5q0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfDk9315FSIwv9R4NBv98pIUVEWwkEfp5kmPAw+buUVgtzgCvkTHnFLVtHDs0MTaUr6fDuCc9SzTIbCzbznaYCgC4UTYhZFoTyOOOUJqeF2BIyAiB8YfqBTJn+Cvt+ZujWTWC87ejUnMm71clzJ8paxYjRj3ie4FOnD39cnfQ0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fRy5k1v3; arc=none smtp.client-ip=209.85.128.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fRy5k1v3" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-6ff1e375a47so12418827b3.1 for ; Thu, 13 Mar 2025 11:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741890165; x=1742494965; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=12rQoY5a8UAWCWk8IrNehGNSyS9d3OIS0IF6FX04+lc=; b=fRy5k1v39MKo1UvKvWPgGeTKA8YDCvddE5kw7be4/Fhm1C8uRzV1f/UiTdQtGalEME khuXqmIyu+tYpM8f/W/KQ/m3RclJO2h1KLcbLyXS7P/8N84jAZZMKlWApx/FECLRpbMV MCclNXXWtwZjTFlxJxT8BxzWTkauNsYdy9MUnKXosVjiiVJYYxLi86GuMQdW8E8KAIwQ B9XT7fZPXwoGvDvCiMhjc2y9qcbW/v+tbWi7wIQStzt1AisXk23oxDr68DEviBqGSUAp u7omSOIK3AYUYaBgnH89OJZcQI9O1rxQllRZDB2NM9XP0ulejmPbapE+lY7MtHrcbbYh /5eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741890165; x=1742494965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=12rQoY5a8UAWCWk8IrNehGNSyS9d3OIS0IF6FX04+lc=; b=nnI06s6FGLKedggykgCkoClZ3tiz1zu0YQv0IiLB2Fxf6T4fgYB194RFCd0RfuKedW gx6WIf55yzYxJONbswDu5M8DlYvZh6gf3R8qbD22bM79Y7Z60aI1WF0XMzZp8I+uXFL7 Y4OTtpUcKG60Kg4tYVlYHqBJsys+jHuEUCccsGRFLddPsL4igpHNxMS8vm6oEy7qSFH4 ImTkQWhaOGT82dsx3SarQw0EMHw70Kn4w+Lb0eLbWFE2hQvRQvmw9MD5vkOI3IzBzXK1 9XQa/c3M6XFjAIt7HdTGXyEb8DpCI8iKGfXe83QQ+g4W+jcEHrVPm/X6C47dpxT5i0JG PJoQ== X-Gm-Message-State: AOJu0YydApKznB4+33RCHEmYJS6/6VXgQlT1KX1cjiTzXnF+yXg91Cid r8gfidQ34WnJ7Zn0xSQsiUHCsW2mAhH3n/t939htw6No2mvhzqroT8PU X-Gm-Gg: ASbGncve4TQqF1vE9tzhhuNwAfeV5VZGFz9UpgztTs957upHAaaV5Xekj5z2FfOnwd/ z670zB3Ok2OLSuc1Zthxs0ucjQur7UTsD3opNpCQex/MmrChfU/Q+bCOkcBlesIgxmywc4xPTHH HOHqkkN7k9/xoMHyoVmHqUgmEktcJaD2WCU+PwUxS7viB2zGCO7NN4Nqlpx44IFqFB6VEYXtLFI YYRT4NvEpnnWyOfhZCNF7Xsqur3GDoIs0MvivkBSjfOJJwRPbP5USW9kZqa+qAHE0mln5u9ZkNC XuU/9mPpdrZeJc2sRkZHXv103Q== X-Google-Smtp-Source: AGHT+IHDeEUgdIT4fwqMBles1//pJUHZV/RGbqVM3A8ak9OgOK7Jn2405LcuZBZYq6+FTBf0vueeGw== X-Received: by 2002:a05:690c:3612:b0:6f9:8910:38a3 with SMTP id 00721157ae682-6ff42157179mr6246967b3.37.1741890165238; Thu, 13 Mar 2025 11:22:45 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ff3288f0absm4910347b3.54.2025.03.13.11.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 11:22:44 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Juergen Gross , Boris Ostrovsky , Brian Gerst Subject: [PATCH 4/5] x86/syscall/x32: Move x32 syscall table Date: Thu, 13 Mar 2025 14:22:35 -0400 Message-ID: <20250313182236.655724-5-brgerst@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313182236.655724-1-brgerst@gmail.com> References: <20250313182236.655724-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since commit: 2e958a8a510d ("x86/entry/x32: Rename __x32_compat_sys_* to __x64_compat_sys_*"), the ABI prefix for x32 syscalls is the same as native 64-bit syscalls. Move the x32 syscall table to syscall_64.c No functional changes. Signed-off-by: Brian Gerst --- arch/x86/entry/Makefile | 1 - arch/x86/entry/syscall_64.c | 13 +++++++++++++ arch/x86/entry/syscall_x32.c | 25 ------------------------- 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 arch/x86/entry/syscall_x32.c diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile index 5fd28abfd5a0..e870f8aa936c 100644 --- a/arch/x86/entry/Makefile +++ b/arch/x86/entry/Makefile @@ -27,4 +27,3 @@ CFLAGS_REMOVE_entry_fred.o +=3D -pg $(CC_FLAGS_FTRACE) obj-$(CONFIG_X86_FRED) +=3D entry_64_fred.o entry_fred.o =20 obj-$(CONFIG_IA32_EMULATION) +=3D entry_64_compat.o syscall_32.o -obj-$(CONFIG_X86_X32_ABI) +=3D syscall_x32.o diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index 9e0ba339013c..b96f5621a2aa 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -19,6 +19,9 @@ #define __SYSCALL(nr, sym) extern long __x64_##sym(const struct pt_regs *); #define __SYSCALL_NORETURN(nr, sym) extern long __noreturn __x64_##sym(con= st struct pt_regs *); #include +#ifdef CONFIG_X86_X32_ABI +#include +#endif #undef __SYSCALL =20 #undef __SYSCALL_NORETURN @@ -44,6 +47,16 @@ long x64_sys_call(const struct pt_regs *regs, unsigned i= nt nr) } }; =20 +#ifdef CONFIG_X86_X32_ABI +long x32_sys_call(const struct pt_regs *regs, unsigned int nr) +{ + switch (nr) { + #include + default: return __x64_sys_ni_syscall(regs); + } +}; +#endif + static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) { /* diff --git a/arch/x86/entry/syscall_x32.c b/arch/x86/entry/syscall_x32.c deleted file mode 100644 index fb77908f44f3..000000000000 --- a/arch/x86/entry/syscall_x32.c +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for x32 ABI. */ - -#include -#include -#include -#include -#include - -#define __SYSCALL(nr, sym) extern long __x64_##sym(const struct pt_regs *); -#define __SYSCALL_NORETURN(nr, sym) extern long __noreturn __x64_##sym(con= st struct pt_regs *); -#include -#undef __SYSCALL - -#undef __SYSCALL_NORETURN -#define __SYSCALL_NORETURN __SYSCALL - -#define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs); -long x32_sys_call(const struct pt_regs *regs, unsigned int nr) -{ - switch (nr) { - #include - default: return __x64_sys_ni_syscall(regs); - } -}; --=20 2.48.1 From nobody Wed Dec 17 23:25:09 2025 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4810E1EF363 for ; Thu, 13 Mar 2025 18:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890169; cv=none; b=cAQh6xMUArjeB5SqBstIZNmCYT+9Vyl89kve/OWTWR6qvHEA9+ebADJqdjIwktMMS2sbOVnIySvUjr+/ZcPDqmgb+paylYQsT+PNrAaxHdzVRrZuaNysUaJx0AeZ0sIJKl3LsbhKlTxB4VYiKWEtqelkFgjQkXRSwmZncHF4UVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741890169; c=relaxed/simple; bh=KfIUC6vHrnWsZFhqX8PmZ3NcRke3NRhejMT28SIgMmo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aq0JDQMC85zexTHY/NHkJtxQ9bIPVZ7Zd5aV7xgDLq7uRdJvnUpWft3Dc3nRFq0vxGh9hUNi0RLO4BNe3nyoviZHn0G9vtyh7+mSPaK+acJEzxWJDqz3f3fwlgjtjbyruf8Z8+olHA/S/FZ/4Vqcm00djwM0gvH0WSdEFIeLbYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AKjOtqHG; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AKjOtqHG" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-6fee50bfea5so13023687b3.1 for ; Thu, 13 Mar 2025 11:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741890167; x=1742494967; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zhSNGE7xuts5hKV7orGt15bPAyx5e48naMNL2aOpQTE=; b=AKjOtqHGXqji1d0+zKw8h2oUsmsegQbsyOEEUMsUH0p6toTM33zyzwBNoX2eB7HMm7 OvZPZ8ggZvKYRi7wqAs/wIFp0jApwnjA0mZirmTvaRvtu0XehCTv5lSuB8KuSbm81mYt sQNjUZa8voqHRKYhtUmZL2azhkVHkAmnSWVI5/LWgmHk7TWq3pW6dGV2CicL3AnD2zTA LQikY5C4U9QJdgH63r6JcEeYfVHycGu6qnLrSb8kg0sm9RsxagYtNvWGUMDP5fp7rCfF z32ftQvb3GzRIhSrdGgCB71d8eEHclOdkFQY2tTZOe0+o/9fgmCTEVhFO6taSgevLdFu G5lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741890167; x=1742494967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zhSNGE7xuts5hKV7orGt15bPAyx5e48naMNL2aOpQTE=; b=SZHhcgpAF7ma3At62ZznRBbH9BcoMlkYlhOHLuTeF2DYuDjCxOETYpLqKXWgGoRv55 11hxpqsfNPC8vUg/Nq4GfMJSLWKmhDufkHn1rGu4jMuIL8OYEpnKMQp6WFnBRNaWQ3zk 2UCi2qndko3/kKgESUDh0SsHdlypIbs5HAxLCnYiz//ZZx/uDIKjNcerEuR61nLaJD9F uQfDi/zhcsrF7age7sFoAT1lwSQ9x+40m4A3Zvp2R3Z+ncBNjk2B8s0lFhsLYJMsVBHi a8j/5atVr/sqiExLi9fJCkyOaaeaOW0FlPa5cCxbXrPjCTZhzN54fuk86E/ylJrD+aqu RFFQ== X-Gm-Message-State: AOJu0YzCavT8Rdx3n5X7/wGoewm1dsnvsLVMkWzY9kg4krnSjX7QaaKI scjEZ0FwPr6Xk5h3s/LWJB+I6KIZm8FqkE2KHKDNsBfg3brrYqwEHCZM X-Gm-Gg: ASbGncv/cMmUxc1K5OdBSw2nhkGUaB9IhtofIR5njh+/igESiB0YtAhElGr4tOj6+Qv 6PTNvOCip+Ug3YI+Bm534xYkScbXOGdFJdoUA5r7XFvWhvy/AgCRV4AbUwFcDEtS0BoTYmV/9+D 1uE/YvyUYYgQZdC0PzxAgOeVqgoscu0dYHmow92oQzNGX2uWDSmOv7KrGbsYo+g/klAaY3nA2OA /2d72HGgaHBI4MW42uGjfzPoFCAtuYrWJ8yOC+ctJr4trXcD/dqsl8VNWoNhqljjPaASbQeS56r CIE/o6UIIROC3mF1iB5mOOLsAg== X-Google-Smtp-Source: AGHT+IH9E20QB2aVzr5D7lj1u2ad8uec6Gt0tQ0BuwaWlKmFEiW/LLc9k9ppyBrayEUzn3AHVM+neg== X-Received: by 2002:a05:690c:4807:b0:6fb:b2de:a2bd with SMTP id 00721157ae682-6ff42041178mr8430417b3.16.1741890166693; Thu, 13 Mar 2025 11:22:46 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ff3288f0absm4910347b3.54.2025.03.13.11.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 11:22:46 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Juergen Gross , Boris Ostrovsky , Brian Gerst Subject: [PATCH 5/5] x86/syscall: Move sys_ni_syscall() Date: Thu, 13 Mar 2025 14:22:36 -0400 Message-ID: <20250313182236.655724-6-brgerst@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313182236.655724-1-brgerst@gmail.com> References: <20250313182236.655724-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move sys_ni_syscall() to kernel/process.c, and remove the now empty entry/common.c No functional changes. Signed-off-by: Brian Gerst --- arch/x86/entry/Makefile | 3 --- arch/x86/entry/common.c | 38 -------------------------------------- arch/x86/kernel/process.c | 5 +++++ 3 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 arch/x86/entry/common.c diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile index e870f8aa936c..72cae8e0ce85 100644 --- a/arch/x86/entry/Makefile +++ b/arch/x86/entry/Makefile @@ -7,16 +7,13 @@ KASAN_SANITIZE :=3D n UBSAN_SANITIZE :=3D n KCOV_INSTRUMENT :=3D n =20 -CFLAGS_REMOVE_common.o =3D $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_32.o =3D $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_64.o =3D $(CC_FLAGS_FTRACE) =20 -CFLAGS_common.o +=3D -fno-stack-protector CFLAGS_syscall_32.o +=3D -fno-stack-protector CFLAGS_syscall_64.o +=3D -fno-stack-protector =20 obj-y :=3D entry.o entry_$(BITS).o syscall_$(BITS).o -obj-y +=3D common.o =20 obj-y +=3D vdso/ obj-y +=3D vsyscall/ diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c deleted file mode 100644 index 5bd448c0664f..000000000000 --- a/arch/x86/entry/common.c +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * common.c - C code for kernel entry and exit - * Copyright (c) 2015 Andrew Lutomirski - * - * Based on asm and ptrace code by many authors. The code here originated - * in ptrace.c and signal.c. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -SYSCALL_DEFINE0(ni_syscall) -{ - return -ENOSYS; -} diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 9c75d701011f..91f6ff618852 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -1068,3 +1068,8 @@ SYSCALL_DEFINE2(arch_prctl, int, option, unsigned lon= g, arg2) =20 return -EINVAL; } + +SYSCALL_DEFINE0(ni_syscall) +{ + return -ENOSYS; +} --=20 2.48.1