From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 DB3D1205121 for ; Tue, 29 Oct 2024 10:52:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199170; cv=none; b=PCQBFNmUK8xZejFI5PRIRMuyOWn+R4RmIenNWYb8r3FYE+HvRefoNs4lpZZrEA5s3jdlb3jn0hK0ScFcHuYpd0xOhvnWk3eoft2cRTEaccXjRngD03Yio16Qrr5gI02JT5cNc+9F5TGMvNqcd4SsEuvmJeXWYa4nPHsF1BgZhj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199170; c=relaxed/simple; bh=EKV+QYYhMEK5XzmL1kz1mpSXJHzUUDAUOm6h5P/l9LI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CUmUVpVpboA0+ZpODp6saaHCzSARoXTeOU4SA8dVgu8OKO6bCTRJRsgcYj2Kn5pb1OLthtjXJ5oUNq1z9K1MYC6mm7FFrJ5WKGC/Fz3Iku6xgzbtXoipidYpZNdiEjiiCgTCWNgoxnUFNUE5QtU/gnaPKcpHuYbi+WtvRKqryE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=eddxTsiU; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eddxTsiU" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-539f58c68c5so8764404e87.3 for ; Tue, 29 Oct 2024 03:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199167; x=1730803967; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2ECqHBAN3rDV9yo1zqeLO+ji9lVIoh6IkMKI7b6YgP4=; b=eddxTsiUOj4eH+LO3P/SR1pOl7USzeXKIldvJ034SfQLizEtooagKNZMSRRHAwSsLp 4z21RNUJ+DxzNwciC7+cL3FgMNTu2dXqgXDBRd8mop+P4c0ahOFHO33wUZoTC8FiH1x4 eeUJ4Ta6mpT0jTS9LihGcKXfzEPFtEM4V1DFmLiDYdAEvywdkKV8ItQvQ7TqoGOpmXqg 6pP3TRQxXsA34uRKrk1/fbKgODzdhz3uucMMpG1Q4G2RV2I3T0bDI7aRvIFVOrssdAjb bWPicRGxCecEweQpgBkClui+3sFQJlFMCb7uW4HoyBvFQzKalIO1p+z8Udwt+0DO73yD ee3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199167; x=1730803967; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ECqHBAN3rDV9yo1zqeLO+ji9lVIoh6IkMKI7b6YgP4=; b=KUOr1isg7FKrjtEENrax1WFN8nVRPRQTdE/YQm4maZ9cniC2EXzx8yuS6MeBVUaMAj FWV3kHSvmQ6Jn3NigNJUR9OOOOOpI1FWbmTT3moxv1qQ+fKrqyU+OLwCLe0Nen5pFnG4 r8jynmBK3FBFT1cnVGjICr4+SVf4E/qldx1WAqwuvQP7+IKaO/TgVn3rw5d5Mlp7KdyE pKhcLvocOqYHep/lTP2pFIdHgZ3JU7t3wi/PDb0sRURXsaTbJpgCe/jx3NhtBES989Jw 0YJKEEY+fLSxlqD/GNzre25qFG3oeZprMJZ4Gzu+KHcAKDACGb++4DEuVoJ176dG6uP0 rfBA== X-Forwarded-Encrypted: i=1; AJvYcCXCXOEIXzXRfIYXrSXWmdf4/Wg3djiRf4FntqkpNvr4b6j38pdG9whVoja1+FfVD2lGrSbdp55+p4ZR3Ls=@vger.kernel.org X-Gm-Message-State: AOJu0YzY7sa7tS2fQUgCCbv3yEWdc9DfZqI8PACP1S/7PR6uPyXZlsPl BRhjVj7H3vPad2Cvf+Ftz+b2Nc5U8WP7BR8WmE0q6xUb602oamhrDZStiZMwN0A= X-Google-Smtp-Source: AGHT+IFxU85skQ0lHgZfBxehiTWY20leong2ojbAy2znYbSLCYYbTDr3GHQiZv+4b0NSU1Ui/HoHTQ== X-Received: by 2002:a05:6512:3d8d:b0:536:54ff:51c8 with SMTP id 2adb3069b0e04-53b348cc6e0mr8922755e87.17.1730199167001; Tue, 29 Oct 2024 03:52:47 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:46 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:41 +0100 Subject: [PATCH RFC v2 01/28] ARM: Prepare includes for generic entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-1-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The generic entry code needs a static inline function for regs_irq_disabled() so add this, in further requires the signature of on_thread_stack() to be __always_inline so add this as well. Signed-off-by: Linus Walleij --- arch/arm/include/asm/ptrace.h | 5 +++++ arch/arm/include/asm/stacktrace.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index 6eb311fb2da0..a01c66f0ad90 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -52,6 +52,11 @@ struct svc_pt_regs { #define fast_interrupts_enabled(regs) \ (!((regs)->ARM_cpsr & PSR_F_BIT)) =20 +static inline int regs_irqs_disabled(struct pt_regs *regs) +{ + return !interrupts_enabled(regs); +} + /* Are the current registers suitable for user mode? * (used to maintain security in signal handlers) */ diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stack= trace.h index f80a85b091d6..815b5f256af1 100644 --- a/arch/arm/include/asm/stacktrace.h +++ b/arch/arm/include/asm/stacktrace.h @@ -26,7 +26,7 @@ struct stackframe { #endif }; =20 -static inline bool on_thread_stack(void) +static __always_inline bool on_thread_stack(void) { unsigned long delta =3D current_stack_pointer ^ (unsigned long)current->s= tack; =20 --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 2282C205143 for ; Tue, 29 Oct 2024 10:52:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199173; cv=none; b=DoHWbX/rnqRiYYCOjy/R66bnY1Iz1qlcn9coplURn/WqsFwE03RnTPApWxyaCfshW7w/PYTbPAUjtEL/Dbje7aUz20ofRizPE7tkU6LktjG0qrZnPYBPJpzAsuT7jd61jRyRyBZdzgTjZLjWoiXVU43CaEz/QG/0eJiqifBxotE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199173; c=relaxed/simple; bh=0u2mldWq4lrnYPUiJZwplGdYFoRn/IGd4Af409B6kLE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eXV0TK7/5lmwARy0TtzZU3cNE8+MjqRWKon5btEfbNmVzo0/pfjdXtdZgO1z2SsiHRrem6xTdL76BuuqU9PfZFrLFMw+WjbpRVSWsPp7eIK8YMtQefkPNHyeYS2Bz2L4/MxN3xogciVGjQH0siTz3uhwYDTLxP+4ObS90fMcqyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=LvLuHkxq; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LvLuHkxq" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-539f0f9ee49so5632645e87.1 for ; Tue, 29 Oct 2024 03:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199169; x=1730803969; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=R4LTFu04v+ewJrCMf1qStO/yKKemj/dlkSOHqQ2h8u0=; b=LvLuHkxq/NGHQEupM6XJyVw41x5XJ+rR5TEvhV/guyI04Hu146R1ob7SFawYep2SKs NOnLSyzDV3KbLYZgxllFjne4E3ooGUPTbq9wZ6wyLwLnzRmUEWZ1RNU8gby2RVxk/5PJ VBOH3hx9rraMHeTB/EIiOhj/gQxf7TQtU5XkyhB8GeCYjKLD+aZFY21ItlljBQVSz0MA DRNXFdeaBWQKhAuQRrMhqB05RgTI/Iq/MJM5/fuzid2cs61JZiScf/lTLsQucubSYnAm ond/r8TmFTtvqyxz48wq24cufzCSXCleOhxc9gnZb1lhZDI05ZYONsKF1T5QaKDaY4eA 6f4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199169; x=1730803969; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R4LTFu04v+ewJrCMf1qStO/yKKemj/dlkSOHqQ2h8u0=; b=BhpLVeA6S/I0Qg0KbxI87kU86vEmlg+oNc8/ntPjg4B8A284VndEZahZOaXHLGdiTw WIyGKlWapnA8BXKwPk8KBOzH+CnBM9G9wYcpJXINYMD8WBiaEZsGRGEoLoUhZZSwoWd1 My30ggWEmTgz3/nQlKMdSnbMg1qBVnnTZ21MwS5GT/tfzy3jLJSSkkaejWsXUsmNqk1n C5tGTN+Fn/+Ka0iT8yKP8l4NvNfUdzImzlvZ0EKwijBJ9CBFwg+daxjZMCA/4H3LD6ut uY//QoVG0yJmPfS5iC5nWZVczaylYOLFytJVzheE0Nre78pNLuaMa+C0mEyJlTYyl2M3 rpYw== X-Forwarded-Encrypted: i=1; AJvYcCVZd5NxvfR1BztqDkpqf4278LY+dLMZ/cQu6T3nvIN76f2BG6Jn4OiY8HqiVQf2X9QT/7Q4FcSrNGGwM64=@vger.kernel.org X-Gm-Message-State: AOJu0YwWg9brni5PnbTdbiv5kEluBH0mT4tPMeGM0XzwlwxmBai1L4XI qRbeCDfpnkDn5Xk0HVRoGYZHpX5/R7MaA1yIJ55LmB4FGBH+LuCCdG7/n9UgNUY= X-Google-Smtp-Source: AGHT+IHzdoIpnm1raIIfmAFKx69MVi8OCs2VC2TJN21ljNCIN9pZ7ToE5AMSUbLLmWlJJIXJdiGYpg== X-Received: by 2002:ac2:4e06:0:b0:52c:fd46:bf07 with SMTP id 2adb3069b0e04-53b34a2e4d0mr4368775e87.49.1730199169220; Tue, 29 Oct 2024 03:52:49 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:47 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:42 +0100 Subject: [PATCH RFC v2 02/28] ARM: ptrace: Split report_syscall() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-2-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The generic entry code requires that report_syscall() be provided in two parts: report_syscall_enter() and report_syscall_exit() so split the combined function in two. Signed-off-by: Linus Walleij --- arch/arm/kernel/ptrace.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index c421a899fc84..07b0daf47441 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -827,31 +827,45 @@ enum ptrace_syscall_dir { PTRACE_SYSCALL_EXIT, }; =20 -static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir d= ir) +static void report_syscall_enter(struct pt_regs *regs) { unsigned long ip; =20 /* * IP is used to denote syscall entry/exit: - * IP =3D 0 -> entry, =3D1 -> exit + * IP =3D 0 -> entry */ ip =3D regs->ARM_ip; - regs->ARM_ip =3D dir; + regs->ARM_ip =3D PTRACE_SYSCALL_ENTER; =20 - if (dir =3D=3D PTRACE_SYSCALL_EXIT) - ptrace_report_syscall_exit(regs, 0); - else if (ptrace_report_syscall_entry(regs)) + if (ptrace_report_syscall_entry(regs)) current_thread_info()->abi_syscall =3D -1; =20 regs->ARM_ip =3D ip; } =20 +static void report_syscall_exit(struct pt_regs *regs) +{ + unsigned long ip; + + /* + * IP is used to denote syscall entry/exit: + * IP =3D 1 -> exit + */ + ip =3D regs->ARM_ip; + regs->ARM_ip =3D PTRACE_SYSCALL_EXIT; + + ptrace_report_syscall_exit(regs, 0); + + regs->ARM_ip =3D ip; +} + asmlinkage int syscall_trace_enter(struct pt_regs *regs) { int scno; =20 if (test_thread_flag(TIF_SYSCALL_TRACE)) - report_syscall(regs, PTRACE_SYSCALL_ENTER); + report_syscall_enter(regs); =20 /* Do seccomp after ptrace; syscall may have changed. */ #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER @@ -892,5 +906,5 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs) trace_sys_exit(regs, regs_return_value(regs)); =20 if (test_thread_flag(TIF_SYSCALL_TRACE)) - report_syscall(regs, PTRACE_SYSCALL_EXIT); + report_syscall_exit(regs); } --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 1FB48206510 for ; Tue, 29 Oct 2024 10:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199175; cv=none; b=HsTsbY0zaanjRDwSxgPMPXE9tvbbo0tFXCi81HJACONesgCfGj94rt0B1vIk1BnI2IPId1qjv32hO4ilQ4wARiwzUjFGj45yKx6vlrRVphfXLlZoXc452MVapZuSpcEdo5ZzOWriYB1gVs3iXpIu++nPKSf1S6J51ZrLcAhoHRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199175; c=relaxed/simple; bh=F4l5jY4Wqe+bOqNg1KeOS2Pb/rQnbpWuqlfxyr64WII=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ArDQnzb8WJ7X0vrlGNQSUfvghf6cFCDrrijSkLPCE6wpf7bFZSMWcL8yUSH7FlvR1Pv4hXD5JXCmXvAwOb/6J8aGoy/az7xD97FTnKOlr46su0Tnl/4NpqgdhRDZJvOmmBXwj+B1Cavt/2EnI5EYxRjLMi5FBzpO4oNW47d/rno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=JQXCaBKa; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JQXCaBKa" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-539f2b95775so6131622e87.1 for ; Tue, 29 Oct 2024 03:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199171; x=1730803971; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OxEtYMLSB1QX4C5qcE83rstSx0FEcAVbxyG1Gu9/c1s=; b=JQXCaBKapyVwqlbD1L9JJfg+rmYE5mHX6oDnrRoET2Amnp+DDRQJoEKc+LQk69rE6Z U7+SRwybO0bn4q/i8f9ewHDCWKM8vdVnO5aqf3DgetvwIlPAYq7H+joL6dpBVCGKhQM1 hJz6XiBE7dS4/6iS7oyrFfSejXsDbjgk6ECeS1+/KCJeW8OlZyQL3GyXPNwu/gs5UgeP EXV0MYkWI5rSj8SdMquv6xF3iU1jEpgm7Ksh/SjjwY0n5tR+4I68ScNYRcG1SXStjibk 4ubeyEI3kXLIMH48PSR9kd931Voey0/uZcnPHdlBLrm55i/HThQjKCaBmiUFFINRDjbo nSZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199171; x=1730803971; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OxEtYMLSB1QX4C5qcE83rstSx0FEcAVbxyG1Gu9/c1s=; b=Qa5MLeSCVdlSyMesnw0+NpLxHyh10I+Lyz7iWevFVouLT96BfGolRAWXmvWUikvsCN m4ksjPaQQ/y89lEu+Y+8LTdW8fAWV+rUr9nYpEtFd+UtsqgOqk7vhy1M0pT7MUO2ymnY g8zsQUTMtypFjIXsUzMFL6gI01MV/zyv/wOxMtucfmea57EEiVgeNdQbfkmI3jwwRhry /dmHvXidtgoavUmhU7QTYaJ8ohPVsAyVlOdKxeaYxldO4vDJwANZpJOTSA6Y2kDtx0x6 9r3cRKh0d8Frr6LRZMB3D0jhxM1BNVr3kEz0bA3aJIT1aNjad877/T2BPSFD+iXPDXSJ tzbg== X-Forwarded-Encrypted: i=1; AJvYcCUtJBTyoTpOBpw6okphAkj9M5pPsW5f74pQGhyt/FPt94PjMt0+hZuYHQHO1ODmCcMtxXttveGRSlsZ3tY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3cYSH4e6Zql3EUh9tK217hJXjuMWl0X63KRbjH6yP4g+EAmcc tQCrZD5WXKB1dBCNOQ+PiFrs545dQ7CxCPOl4TE52MYdz4fyxki4wInETrHcTNo= X-Google-Smtp-Source: AGHT+IG8wqLvl/74zfQu1AsovVWvKhyDOxgS68ymugVtQXnP4D9gfxPQaaqzIINEiXO/D6a/IaB5TQ== X-Received: by 2002:a05:6512:31d3:b0:539:8fbd:5218 with SMTP id 2adb3069b0e04-53b34a3515fmr9748104e87.56.1730199171163; Tue, 29 Oct 2024 03:52:51 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:49 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:43 +0100 Subject: [PATCH RFC v2 03/28] ARM: entry: Skip ret_slow_syscall label Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-3-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 Don't introduce this extra label anymore now that we have a clearly defined entry point for ret_to_user. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index f379c852dcb7..2f93c2f6d5b8 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -102,7 +102,6 @@ ENDPROC(ret_fast_syscall) * do_work_pending() will update this state if necessary. */ ENTRY(ret_to_user) -ret_slow_syscall: #if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ enable_irq_notrace @ enable interrupts @@ -136,7 +135,7 @@ ENTRY(ret_from_fork) badrne lr, 1f retne r5 1: get_thread_info tsk - b ret_slow_syscall + b ret_to_user ENDPROC(ret_from_fork) =20 /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D @@ -310,13 +309,13 @@ __sys_trace_return_nosave: enable_irq_notrace mov r0, sp bl syscall_trace_exit - b ret_slow_syscall + b ret_to_user =20 __sys_trace_return: str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 mov r0, sp bl syscall_trace_exit - b ret_slow_syscall + b ret_to_user =20 .macro syscall_table_start, sym .equ __sys_nr, 0 --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 CB512206E66 for ; Tue, 29 Oct 2024 10:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199178; cv=none; b=Ttlznk+W9DZ0dZdzvApb5lOoqUjKgEpiBkbRgeVLM+cK6gXbybr0gScH3wxOAMwZ8c/FCwXmWXzmeB3/7a2Jz7qKJFhiAmvAa6ZmFsE089GmcJRnJIg5M6PNnnGbi8cfN1vezXlEQL1ErXkTi2jwkztMthy6R6TdIhCH1yS8hOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199178; c=relaxed/simple; bh=HgpuQCGct+VCXYretZz57uSNbkNJ0GIymihuDxTTfNw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LMM1mfmBSaFdq7Bigq09XpyHyT4WH3pXkY8mdaDk1oJXWmRD4tP6+/DkP5PLIHt81JQULZAPGyhshtnJmxjxP83dc3EsRzIFDfnxrViDBOKO+pBqiRPLpwRx2jVv7ZANHsCkPtZ3RMcfg5KpaE55mIwHK8KYcKMsyRx1HwPzcJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=l0lR3nh1; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="l0lR3nh1" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-539f53973fdso4452379e87.1 for ; Tue, 29 Oct 2024 03:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199174; x=1730803974; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=; b=l0lR3nh1gOYUzbe1vvR/i2BQJJaeJ9cffTrDrhsidHPPXGBdZJ9mKZJjEiD7jccmwC +l2QkriNAJssbSqpJtG7jCeeaH8qfTGZg4EK2mvrYYZJAswBxCJzHg3HfTNkulhVWMk2 GqtvoOCZq5u7z9/p9i4Ho1jFBlLbhMzTqkvjKlCDj5Z2tnvCPvk3A5y7jVMXeJhodaxf MKb0qw+mW+ukor4re8cKSiCUtb/EEi9aSK7ccl1Oz/aYj2aAMnuSrvJWjEEheB3D1EvD StjfQpwfgLS+NIMp/xZhoyKc9kFFa55ORmz0yOXz00KNwP9aaTig3TDgGjQzd5vYtdnm em2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199174; x=1730803974; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=; b=gl1/i6hFG0pkhzAxC8lAm10P24LT3UH51Ms+CwiTIgQ65fNFq2FegxO+9VgwyIeJV3 8IE5qEx7l+KOl+ag4o1z6ZvqFuyzbKOZZUq6rDFtZj6amGPXAWGNtTC4fg4FIwLoMBzU 8l+gWhXyQi6VFuKGadhN2i1QdyYLAwvSyB2TtBqrsylxnvEktxcC2gfQ8y/PZQtJGAEx dHnAsUQJltEqabKnnniTEAc1y+m2wmQ7Q8uqVKjUmq9VWfkQgyZoWXNQ37B0SSabO/3q fs9Yi/B3yu0UCBbBBSo8ANLQHOIEyRRFCbZAYqdkuw/rg8BCPH8quhNaKPeIWogeXGF2 ombw== X-Forwarded-Encrypted: i=1; AJvYcCVy1ZXyAk02+jkvT+srfzomJqCqeBmJ5GhZ53PdBRMIrycDL+mPqrA7GbnQ+Rni3qnuJM3507lXupGaHhE=@vger.kernel.org X-Gm-Message-State: AOJu0YzL3Fq79cLzKDwXh5vtbV6Xt4BXGhvKjd5ccD8y+mlLYUqj4Cxz 0bhihq+CymGH9x3Psqk1SN2QAAn+T7q80vGnlgdjEtvNB+ZpRkT6YlFiMyJXI10= X-Google-Smtp-Source: AGHT+IGfHm6faFqK8jdHk5n5plXPyzGC/TcHbEJEFWbtB3+ViWXDca9EpWy+Qw2QzBfYVVQTkU/ogQ== X-Received: by 2002:a05:6512:2346:b0:539:e873:6d4 with SMTP id 2adb3069b0e04-53b4947e476mr663973e87.22.1730199173807; Tue, 29 Oct 2024 03:52:53 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:51 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:44 +0100 Subject: [PATCH RFC v2 04/28] ARM: process: Rewrite ret_from_fork i C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-4-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 Move the direct assembly call to schedule_tail() and the call starting a kernel thread into a C version of ret_from_fork() in process.c and rename the old ret_from_fork to ret_from_fork_asm following the pattern in x86. Leave a comment on what we will do when we get to switching to generic entry with this as a base. Signed-off-by: Linus Walleij --- arch/arm/include/asm/switch_to.h | 4 ++++ arch/arm/kernel/entry-common.S | 22 +++++++++++++++------- arch/arm/kernel/process.c | 24 ++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/switch_to.h b/arch/arm/include/asm/switch= _to.h index 9372348516ce..18d084aff5a4 100644 --- a/arch/arm/include/asm/switch_to.h +++ b/arch/arm/include/asm/switch_to.h @@ -17,6 +17,10 @@ #define __complete_pending_tlbi() #endif =20 +asmlinkage void ret_from_fork_asm(void); +__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *reg= s, + int (*fn)(void *), void *fn_arg); + /* * switch_to(prev, next) should switch from task `prev' to `next' * `prev' will never be the same as `next'. schedule() itself diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 2f93c2f6d5b8..df6961a1006b 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -5,6 +5,7 @@ * Copyright (C) 2000 Russell King */ =20 +#include #include #include #include @@ -128,15 +129,22 @@ ENDPROC(ret_to_user) /* * This is how we return from a fork. */ -ENTRY(ret_from_fork) - bl schedule_tail - cmp r5, #0 - movne r0, r4 - badrne lr, 1f - retne r5 +SYM_TYPED_FUNC_START(ret_from_fork_asm) + /* + * ret_from_fork() expects: + * r0: prev + * r1: regs + * r2: fn() for kernel process or NULL + * r3: fn_arg for kernel process or N/A + */ + mov r1, sp + mov r2, r5 + mov r3, r4 + bl ret_from_fork + mov r0, #0 1: get_thread_info tsk b ret_to_user -ENDPROC(ret_from_fork) +SYM_FUNC_END(ret_from_fork_asm) =20 /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D * SWI handler diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index e16ed102960c..81c1c3f98834 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -230,7 +231,26 @@ void flush_thread(void) thread_notify(THREAD_NOTIFY_FLUSH, thread); } =20 -asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); +/* The assembly stub sets up the parameters and calls ret_from_fork() */ +asmlinkage void ret_from_fork_asm(void) __asm__("ret_from_fork_asm"); + +__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *reg= s, + int (*fn)(void *), void *fn_arg) +{ + schedule_tail(prev); + + /* Is this a kernel thread? */ + if (unlikely(fn)) { + fn(fn_arg); + /* + * A kernel thread is allowed to return here after successfully + * calling kernel_execve(). Exit to userspace to complete the + * execve() syscall. + */ + } + + /* syscall_exit_to_user_mode(regs); here once we switch to generic entry = */ +} =20 int copy_thread(struct task_struct *p, const struct kernel_clone_args *arg= s) { @@ -263,7 +283,7 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) thread->cpu_context.r5 =3D (unsigned long)args->fn; childregs->ARM_cpsr =3D SVC_MODE; } - thread->cpu_context.pc =3D (unsigned long)ret_from_fork; + thread->cpu_context.pc =3D (unsigned long)ret_from_fork_asm; thread->cpu_context.sp =3D (unsigned long)childregs; =20 clear_ptrace_hw_breakpoint(p); --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 60A3D206E82 for ; Tue, 29 Oct 2024 10:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199179; cv=none; b=eKKH/N9w10Tc/0EMNBjTrrXoupwCTE6iHmCla0OsUFefFp9ljuicg8nGzo+ktcI55RJg8b90wiM0hHprfBYxsW6OFxYqOovR+Oi3hF76Xt1gaFWe7VJMyTEOwRsipdjIcd+fE+XrtFg0J80PPq0kHO5g44H+0jTWmmnX0c21ctg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199179; c=relaxed/simple; bh=TXjj9xFMQ8ObJncCvfOXEQyxyh4pdr8dOD7N4vVAW1Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XMOFadXQn6caGKAKf+Zi5ZU7cxGEGg6nnRa+1zETh0YFnINLoCwe1xGj0edBAPsVLFBM1AfnPR0OVN5xeM7dahoXp7CJ0lwrXIIE//SdLiX3Zhkbi9mTkxw9rt4LNlsr7FctOTk0zjfwXkYJKvUIVjtmwCQZY4VndJ3vHa5MZXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=O1/ihUO6; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="O1/ihUO6" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-539eb97f26aso5435641e87.2 for ; Tue, 29 Oct 2024 03:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199175; x=1730803975; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=O1/ihUO6X0FWsjLTrki5Kiv/jiGQdCAP7+sNVXn3o/AwONpV9JqIE1LRsqIIUfS0gB V4duyfBIwosraTXNEpByRia434Hez7wf60AnnI/hy1eNOlX2QVgcpXIhb6vfuCJkP7/W I17ZhBXp54Y/wbXzz8tqyZi2BRj+wn7LQ1MAb8/gojnvdZFRN0j37KLjmj9vKg6kvRHY /TEvVMorexZRiamtNfZQ+H6q8Di0/NSI4ygrJ4pieVFvbwEkPXp5kmGKFlwJ8zV/I6Ha Llz3F3xjiroRSpEfGn+ehS3Oyron1CqVpOR6lnjreAsfAIRMV8dUn3S9DyCTLtBXYDHa wlBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199175; x=1730803975; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=I3FPJCpH8XMuQ5cmWJNy0hHYQcEloZpHegBPgG7fmmhUz1yiyloseaoAbvg9alEZq7 JqTqF0lyI9L4iDk3dMP5zn7AGsg9/xN1j09lUdF3BS7Ek5xkVHHXhJlPVkuhhBemWmiv 0aiNLLd3l1fPjN2qMDqGn7VL1HhXz4TJKjyycV9p89Q2FnyzFlQ4v/GD367dzyDjOg6R UR4X1bb97GWgHj3Pyu7hAPbGVxkNE8Kx01vKtZv954HNy4V9tXZWehAZN6uixK/MpgRq mo6TBY7j2CUo4ExPqJTbqQn+7BkhKGz2MHwiumhlFk/9F9idvyo6DogfvtI39Tt8e5Ih nCJw== X-Forwarded-Encrypted: i=1; AJvYcCVkkdy1wp5Ex5MhiaLoeUlE95Cja5SII7ncxN6cgu6to8ObwKqX9ZZs8TL7ABO+6PNT6iamynoPx+sac+g=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2MbGPOUbwLFc2AkBY8YyvXooPmhcMN9MmONP7INUeAvY12ROj usOl1cJHaD/AkybDUCBE4/BBamI9yjldMvppv9VcVF6JmNWpgBrWCCfKVWQbDRo= X-Google-Smtp-Source: AGHT+IE7TBLGcMxKsC7a30pUEcJoXeIzSiYTepdqh334Y6u9VYfbvLHbrLSewuIIAuux0bNQMqTTNA== X-Received: by 2002:a05:6512:3b2b:b0:539:e1ea:c298 with SMTP id 2adb3069b0e04-53b348cbb37mr5497449e87.22.1730199175441; Tue, 29 Oct 2024 03:52:55 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:54 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:45 +0100 Subject: [PATCH RFC v2 05/28] ARM: process: Remove local restart Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-5-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The ARM kernel contains a quirk to handle syscall restarts inside the kernel without exiting to userspace. The generic entry cannot handle this. Rename do_signal() to arch_do_signal_or_restart() to fit with the upcoming generic entry conversion. This is essentially a revert of commit 81783786d5cf "ARM: 7473/1: deal with handlerless restarts without leaving the kernel" from 2012. Other solutions may be possible, such as checking the PC after do_work_pending and assume it is a local restart if that address is inside the kernel, or modifying the generic entry code to track local restarts like ARM does and pass that information back. Signed-off-by: Linus Walleij --- arch/arm/include/asm/signal.h | 3 +-- arch/arm/kernel/entry-common.S | 9 +-------- arch/arm/kernel/signal.c | 28 +++++++++------------------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h index 8b84092d1518..7acccc96840c 100644 --- a/arch/arm/include/asm/signal.h +++ b/arch/arm/include/asm/signal.h @@ -24,7 +24,6 @@ typedef struct { #include =20 void do_rseq_syscall(struct pt_regs *regs); -int do_work_pending(struct pt_regs *regs, unsigned int thread_flags, - int syscall); +void do_work_pending(struct pt_regs *regs, unsigned int thread_flags); =20 #endif diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index df6961a1006b..da5c2d4b62e5 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -86,14 +86,8 @@ ENDPROC(ret_fast_syscall) bne __sys_trace_return_nosave slow_work_pending: mov r0, sp @ 'regs' - mov r2, why @ 'syscall' bl do_work_pending - cmp r0, #0 - beq no_work_pending - movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE) - str scno, [tsk, #TI_ABI_SYSCALL] @ make sure tracers see update - ldmia sp, {r0 - r6} @ have to reload r0 - r6 - b local_restart @ ... and off we go + b no_work_pending ENDPROC(ret_fast_syscall) =20 /* @@ -266,7 +260,6 @@ ENTRY(vector_swi) */ TRACE( ldmia sp, {r0 - r3} ) =20 -local_restart: ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args =20 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 79a6730fa0eb..7b1a16e86b23 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -18,6 +18,7 @@ #include #include #include +#include #include =20 #include "signal.h" @@ -534,9 +535,10 @@ static void handle_signal(struct ksignal *ksig, struct= pt_regs *regs) * the kernel can handle, and then we build all the user-level signal hand= ling * stack-frames in one go after that. */ -static int do_signal(struct pt_regs *regs, int syscall) +static void arch_do_signal_or_restart(struct pt_regs *regs) { unsigned int retval =3D 0, continue_addr =3D 0, restart_addr =3D 0; + bool syscall =3D (syscall_get_nr(current, regs) !=3D -1); struct ksignal ksig; int restart =3D 0; =20 @@ -590,16 +592,14 @@ static int do_signal(struct pt_regs *regs, int syscal= l) } else { /* no handler */ restore_saved_sigmask(); - if (unlikely(restart) && regs->ARM_pc =3D=3D restart_addr) { + if (unlikely(restart) && regs->ARM_pc =3D=3D restart_addr) regs->ARM_pc =3D continue_addr; - return restart; - } } - return 0; + return; } =20 -asmlinkage int -do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int sysca= ll) +asmlinkage void +do_work_pending(struct pt_regs *regs, unsigned int thread_flags) { /* * The assembly code enters us with IRQs off, but it hasn't @@ -612,19 +612,10 @@ do_work_pending(struct pt_regs *regs, unsigned int th= read_flags, int syscall) schedule(); } else { if (unlikely(!user_mode(regs))) - return 0; + return; local_irq_enable(); if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - int restart =3D do_signal(regs, syscall); - if (unlikely(restart)) { - /* - * Restart without handlers. - * Deal with it without leaving - * the kernel space. - */ - return restart; - } - syscall =3D 0; + arch_do_signal_or_restart(regs); } else if (thread_flags & _TIF_UPROBE) { uprobe_notify_resume(regs); } else { @@ -634,7 +625,6 @@ do_work_pending(struct pt_regs *regs, unsigned int thre= ad_flags, int syscall) local_irq_disable(); thread_flags =3D read_thread_flags(); } while (thread_flags & _TIF_WORK_MASK); - return 0; } =20 struct page *get_signal_page(void) --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 18808206E99 for ; Tue, 29 Oct 2024 10:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199181; cv=none; b=ENcrXJy33JmenSH/q81EBSwJOJCK3ZSyuMJI/d8dNMveaIxjmS2QLRhM+eRLfnxReTCj/AIoPDKnrgqkJPS9HCbDE41XkcGU2uisEtBZGW0rParLj+ZQwf+FW3W1qNbIn14XYZrr9hGYrvu6JeA7r48rf88r8rfp7H2Q2oIGVM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199181; c=relaxed/simple; bh=tX5Wma4JHUbeyuYDZTw48n7VQjwfTQwWz6WO082EFwk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WR4ZO8T8I4qenm8+7TJIyDd1p2TShuBY0vxOwfH76Am8h7pAGE086F8GQVBM9uJC16oKO7jPRR0muSDX/yR6XYhD8zWCW4GSMMJmgF24HlJ7FhmvaU1Go0vQCdWIf1NY3f8RITa6wmO4Qf9E+x2VZxYieqYCsGXEUmUDkuB6tw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=i7b4OZ5d; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="i7b4OZ5d" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-539e3f35268so6247324e87.3 for ; Tue, 29 Oct 2024 03:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199177; x=1730803977; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MQAt5SKeBz56FAHiHxrYIQX+VEnQ+LorFKx32LG+SI8=; b=i7b4OZ5dWoQIvCmPhbyr4WQdyTT8ASREPk3bHU+1xndeKOtttGP3ho1JLhtZOWiUbf aFhPQYzX4S74M4q0vy+zfqhDIxdhlxW25ZRrSWOZYMridkYtzfqUL8LPeqMqq57B13z0 mBxeUif1ruIvq+fGg8KCP+7oJEwijQBcyXaPrTdU5rKFqVMvLCYC+SJRfadcuOCT7of1 TxrOJYP5JLOZS0G9ycpPnq0Sjr4DGpWHsZuVb+bTVumzKvzD5v0wr555SrDC1ahWjVS7 tV4tKk4XD3yzvwrIohvyYY0isnJVdueD9bqFsGCk5v+uC8oNPfCjNo/215m1IyfES/an XtLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199177; x=1730803977; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MQAt5SKeBz56FAHiHxrYIQX+VEnQ+LorFKx32LG+SI8=; b=I9uD2Q9sSsPQtESx8ntxPWWOZQ0XgQ0oiM2lrgOo2zMfjPv7FWEf4/s2v/9xW5sZlX 7mxnpooVz3AOc+vq4IQ8R3QYQcvnuZ4444KwrdEmHGGsTkTZBiPQYSLmV6FACtU2MNO2 Wkv0fSpwTnoznbYcv+ZtH4Fs51a6xkBHOwz6jf32LvqZ7m4U0EmaH9aZFV+m9+a/G+wy B/Y32BPcDRINL6bq2DZrWmpaaxQ2DNzpq5rah8TYgQ/OoJSwiSh8LSAGEFoVKiTtFaso b7tF8GnH14ypbgRKUEGpiNWmuz6HmnwBk7jSY2/9oDAftqvD55GCkn9YARO5VqYG3H/Q a8vg== X-Forwarded-Encrypted: i=1; AJvYcCUqxjZc21z3KAPyHFgsxQE/8B+ehzcuoJD9w9bvF/GxkHHA0AxorXEG+kB3BEHRrgkjwWo59qL6vYDpiCM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6DPUSzaxuZhOPR0n1GgYBmzUMD/6nyRkosemkbQl8HvErJs06 iecvU0xDVRnI7EBlk0h43PmfvROHbLhxb82cV4/zpoTF1D3XZAfGfMrg3IgMiuS/dUXoMfQrPpn 6 X-Google-Smtp-Source: AGHT+IH02DljC5OJLWSxuPwmNJgUqVDp/yV4HkIQznaaTz0rXBVRxssfaQFmZlb+HWxw2R8Zn8MI3Q== X-Received: by 2002:a05:6512:31c9:b0:539:e436:f1cc with SMTP id 2adb3069b0e04-53b34a33c57mr5584786e87.52.1730199177051; Tue, 29 Oct 2024 03:52:57 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:55 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:46 +0100 Subject: [PATCH RFC v2 06/28] ARM: entry: Invoke syscalls using C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-6-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 This makes the assembly invoking syscalls switch over to doing this from C with a small assembly stub to actually jump into the syscall. Split the syscall invocation into two paths: one for plain invocation and one for tracing (also known as "reload" as it was reloading the registers from regs). We rename this path with the infix "trace" as that code will be trace-specific as we move code over to C. Some registers such as r1 and lr get cobbled during the C calls and need to be restored when we return. Right now the part in C doesn't do much more than check the syscall number to be valid (a test previously done with a cmp r #NR_syscalls inside the invoke_syscall macro) but we will gradually factor over more assembly to C that can then be switched to the generic entry code so the exercise gets a point. Tested with a full system boot and by issuing some command line tools with strace to make sure the tracing path still works. Signed-off-by: Linus Walleij --- arch/arm/include/asm/syscall.h | 3 ++ arch/arm/kernel/Makefile | 3 +- arch/arm/kernel/entry-common.S | 65 ++++++++++++++++++++++++++++++++++++--= ---- arch/arm/kernel/entry-header.S | 25 ---------------- arch/arm/kernel/syscall.c | 26 +++++++++++++++++ 5 files changed, 88 insertions(+), 34 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..1d21f26ecf51 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -19,6 +19,9 @@ =20 extern const unsigned long sys_call_table[]; =20 +int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp= ); +int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void= *retp); + static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index aaae31b8c4a5..d5a128a4228d 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -20,7 +20,8 @@ CFLAGS_REMOVE_return_address.o =3D -pg obj-y :=3D elf.o entry-common.o irq.o opcodes.o \ process.o ptrace.o reboot.o io.o \ setup.o signal.o sigreturn_codes.o \ - stacktrace.o sys_arm.o time.o traps.o + stacktrace.o sys_arm.o time.o traps.o \ + syscall.o =20 KASAN_SANITIZE_stacktrace.o :=3D n KASAN_SANITIZE_traps.o :=3D n diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index da5c2d4b62e5..57aa1084a047 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -254,21 +254,23 @@ ENTRY(vector_swi) #else str scno, [tsk, #TI_ABI_SYSCALL] #endif - /* - * Reload the registers that may have been corrupted on entry to - * the syscall assembly (by tracing or context tracking.) - */ - TRACE( ldmia sp, {r0 - r3} ) - + mov r1, sp @ put regs into r1 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args =20 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? bne __sys_trace =20 - invoke_syscall tbl, scno, r10, __ret_fast_syscall + mov r0, tbl + /* r1 already contains regs */ + mov r2, scno @ syscall number from r7 + badr r3, __ret_fast_syscall + bl invoke_syscall =20 + /* Restore regs into r1 and lr after C call */ + badr lr, __ret_fast_syscall add r1, sp, #S_OFF + 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back bcs arm_syscall @@ -301,7 +303,16 @@ __sys_trace: add r0, sp, #S_OFF bl syscall_trace_enter mov scno, r0 - invoke_syscall tbl, scno, r10, __sys_trace_return, reload=3D1 + mov r2, r0 @ scno into r2 + add r1, sp, #S_R0 + S_OFF @ pointer to regs + mov r0, tbl + badr r3, __sys_trace_return + bl invoke_syscall_trace + + /* Restore regs into r1 and lr after C call */ + add r1, sp, #S_R0 + S_OFF @ pointer to regs + badr lr, __sys_trace_return + cmp scno, #-1 @ skip the syscall? bne 2b add sp, sp, #S_OFF @ restore stack @@ -415,6 +426,44 @@ sys_mmap2: b sys_mmap_pgoff ENDPROC(sys_mmap2) =20 +/* + * This call wants: + * r0: syscall table + * r1: regs + * r2: syscall number + * r3: pointer to return function + */ +SYM_TYPED_FUNC_START(invoke_syscall_asm) +#ifdef CONFIG_CPU_SPECTRE + csdb +#endif + mov tbl, r0 + mov scno, r2 + mov lr, r3 @ return address + ldmia r1, {r0 - r3} @ reload r0-r3 + /* Arguments 5 and 6 are (hopefully) on the stack */ + ldr pc, [tbl, scno, lsl #2] @ call sys_* routine +SYM_FUNC_END(invoke_syscall_asm) + +/* + * This call wants: + * r0: syscall table + * r1: regs + * r2: syscall number + * r3: pointer to return function + */ +SYM_TYPED_FUNC_START(invoke_syscall_trace_asm) +#ifdef CONFIG_CPU_SPECTRE + csdb +#endif + mov tbl, r0 + mov scno, r2 + mov lr, r3 @ return address + ldmia r1, {r0 - r6} @ reload r0-r6 + stmia sp, {r4, r5} @ update stack arguments + ldr pc, [tbl, scno, lsl #2] @ call sys_* routine +SYM_FUNC_END(invoke_syscall_trace_asm) + #ifdef CONFIG_OABI_COMPAT =20 /* diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 99411fa91350..52b4fa97226d 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -389,31 +389,6 @@ ALT_UP_B(.L1_\@) #endif .endm =20 - .macro invoke_syscall, table, nr, tmp, ret, reload=3D0 -#ifdef CONFIG_CPU_SPECTRE - mov \tmp, \nr - cmp \tmp, #NR_syscalls @ check upper syscall limit - movcs \tmp, #0 - csdb - badr lr, \ret @ return address - .if \reload - add r1, sp, #S_R0 + S_OFF @ pointer to regs - ldmiacc r1, {r0 - r6} @ reload r0-r6 - stmiacc sp, {r4, r5} @ update stack arguments - .endif - ldrcc pc, [\table, \tmp, lsl #2] @ call sys_* routine -#else - cmp \nr, #NR_syscalls @ check upper syscall limit - badr lr, \ret @ return address - .if \reload - add r1, sp, #S_R0 + S_OFF @ pointer to regs - ldmiacc r1, {r0 - r6} @ reload r0-r6 - stmiacc sp, {r4, r5} @ update stack arguments - .endif - ldrcc pc, [\table, \nr, lsl #2] @ call sys_* routine -#endif - .endm - /* * These are the registers used in the syscall handler, and allow us to * have in theory up to 7 arguments to a function - r0 to r6. diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c new file mode 100644 index 000000000000..be193266299f --- /dev/null +++ b/arch/arm/kernel/syscall.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno, void *= retp); + +__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, = void *retp) +{ + if (scno < NR_syscalls) + /* Doing this with return makes sure the stack gets pop:ed */ + return invoke_syscall_asm(table, regs, scno, retp); + + return 0; +} + +int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, = void *retp); + +__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int = scno, void *retp) +{ + if (scno < NR_syscalls) + /* Doing this with return makes sure the stack gets pop:ed */ + return invoke_syscall_trace_asm(table, regs, scno, retp); + + return 0; +} --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 939842071EB for ; Tue, 29 Oct 2024 10:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199183; cv=none; b=FORBWZdBlMvKgr+hlwvehPNdhIkJL7gMIasng4ghzmjJk8EvP0jv+bwuuaW+777LgRz/1esHfoOak4VEUbO3yoEi2pk0LuHYIPhU47TmMxI9leTfiIagKl1bKgQM+U3CgVDMY+7H75bC+HMSpmQv1Lpxi+phf7tFIdGpFaViWF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199183; c=relaxed/simple; bh=g9d64KHtUbVDBZrCbOcA7Q4EzM8BIaX3zFAaGvQCJXo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=omdnnZZxMNfCo6P9BGBFtLWz6Mm5QSLTpjWo0qDQnJn9q2or6C76KlvnnzgFOX8uGbO5/sgfcNHHmUWwt8fLiUUwwrdB8Mj6fiz9/pEu4anY9StiX2ldVpbPZKm5IyBtImU+7I6/w0tJg7LNSkLv4PtulErVvzoVzUxSXQOTudY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=OEImcMy7; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OEImcMy7" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2fb5fa911aaso71610661fa.2 for ; Tue, 29 Oct 2024 03:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199179; x=1730803979; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=; b=OEImcMy7UVw2IibYda8XCj3l45Em5rFyG8Vup9ZNgrqVMZhHA+YbwZ+f57RFN8Qa4o dfK1/of2S/JVpkBFvpjApt6y6vVWCJVHvR8t9Z8G8jrqu8CBrfB6/GD5oDoxEhJEypR0 xmwEJJnqCboCJVFv0H9MYdc9lea4zvdws6exkdKxQGdv3mg2YOcN8qhxnZKzsuA3dHKo 2wGMYSDWg/bKzcUKMrAjIKr5xEXZcI4Gc681f9MPM5IhARs+v/QxcKyvk3Jkr8Vws+C5 r8dhN+YqdoCdSFVhN2kxZFnX2zeyDgKOcfvxfPTqydmy2UGUntLGD1AYNfH/4LdM5fFw jF7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199179; x=1730803979; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=; b=UZPyK7E2Zu+Up9JEvSOasSh8zyL3vn+sR9SS/DfLy1X7mtJMKqVxkopQiVasSvH0hH rOH5cgtcFlLF+kXY0I5/3Jx7NRpOzIPuRqPIQEh1nHTLmSgwXiL8aDAnaccLuc6w5w95 MRo5O/yQXpKMCUiPYCQ4gtsVACHqSh1VRyiiznwngWcefOx0XC2x0YqszpunnHPHb3Kk C2mTcSMLiVeUe2qLTD2YX49mYcQay+Ykk+skD0pmbRE08gyi+1OR/RpszNqvOhjIcso3 6zBI62FBucSR+PL4e+ONL1hk6mHq06sly+9hrwGSQzNeSjA+ShXnYscExfIbBPRtt1Yr KyjA== X-Forwarded-Encrypted: i=1; AJvYcCXH5uFHzBdCMOdp4jP+E/dNbW5Bymmf01AjwOW4sbNlagX+ooEovbYKo7KPCFVEj+xmHbGx/+rlU48hIy0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8dYkVqb4v6Ul//MAXI3nYIETv1/Nbb7G4QIZmbzTANfYjTvSU BbwC3ypkRI7T2MCfC6r4Z4NpYIav6zkNUDmqjohQBSpy3lWPGfPTnZRhI3lQKuM= X-Google-Smtp-Source: AGHT+IE1Zk4oQJfcQ3ydT5j4hWbXtZadfIMGcMOO6V/a6kzdw22mTKnF7LA+e5CH2gcq4VfHFz9bfA== X-Received: by 2002:a05:6512:3ba3:b0:533:483f:9562 with SMTP id 2adb3069b0e04-53b3491e07amr8032028e87.42.1730199178733; Tue, 29 Oct 2024 03:52:58 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:57 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:47 +0100 Subject: [PATCH RFC v2 07/28] ARM: entry: Rewrite two asm calls in C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-7-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The normal and trace entry code calls out to arm_syscall() and sys_ni_syscall() from assembly, but these calls can be moved over to the new C implementation. Signed-off-by: Linus Walleij --- arch/arm/include/asm/traps.h | 2 +- arch/arm/kernel/entry-common.S | 23 +++++------------------ arch/arm/kernel/syscall.c | 13 +++++++++++-- arch/arm/kernel/traps.c | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/arch/arm/include/asm/traps.h b/arch/arm/include/asm/traps.h index 2621b9fb9b19..b888912c2450 100644 --- a/arch/arm/include/asm/traps.h +++ b/arch/arm/include/asm/traps.h @@ -40,7 +40,7 @@ asmlinkage void dump_backtrace_stm(u32 *stack, u32 instru= ction, const char *logl asmlinkage void do_undefinstr(struct pt_regs *regs); asmlinkage void handle_fiq_as_nmi(struct pt_regs *regs); asmlinkage void bad_mode(struct pt_regs *regs, int reason); -asmlinkage int arm_syscall(int no, struct pt_regs *regs); +int arm_syscall(int no, struct pt_regs *regs); asmlinkage void baddataabort(int code, unsigned long instr, struct pt_regs= *regs); asmlinkage void __div0(void); asmlinkage void handle_bad_stack(struct pt_regs *regs); diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 57aa1084a047..77801d039b5f 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -264,18 +264,10 @@ ENTRY(vector_swi) mov r0, tbl /* r1 already contains regs */ mov r2, scno @ syscall number from r7 - badr r3, __ret_fast_syscall - bl invoke_syscall - - /* Restore regs into r1 and lr after C call */ + /* We return here no matter what, also pass this as an argument */ badr lr, __ret_fast_syscall - add r1, sp, #S_OFF - -2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) - eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back - bcs arm_syscall - mov why, #0 @ no longer a real syscall - b sys_ni_syscall @ not private func + mov r3, lr + b invoke_syscall =20 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) /* @@ -308,13 +300,8 @@ __sys_trace: mov r0, tbl badr r3, __sys_trace_return bl invoke_syscall_trace - - /* Restore regs into r1 and lr after C call */ - add r1, sp, #S_R0 + S_OFF @ pointer to regs - badr lr, __sys_trace_return - - cmp scno, #-1 @ skip the syscall? - bne 2b + cmp r0, #-1 + bne __sys_trace_return add sp, sp, #S_OFF @ restore stack =20 __sys_trace_return_nosave: diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index be193266299f..d1259c6d2805 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -11,16 +11,25 @@ __visible int invoke_syscall(void *table, struct pt_reg= s *regs, int scno, void * /* Doing this with return makes sure the stack gets pop:ed */ return invoke_syscall_asm(table, regs, scno, retp); =20 - return 0; + if (scno >=3D __ARM_NR_BASE) + return arm_syscall(scno, regs); + + return sys_ni_syscall(); } =20 int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, = void *retp); =20 __visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int = scno, void *retp) { + if (scno =3D=3D -1) + return -1; + if (scno < NR_syscalls) /* Doing this with return makes sure the stack gets pop:ed */ return invoke_syscall_trace_asm(table, regs, scno, retp); =20 - return 0; + if (scno >=3D __ARM_NR_BASE) + return arm_syscall(scno, regs); + + return sys_ni_syscall(); } diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 480e307501bb..42f6bb593eb4 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -606,7 +606,7 @@ do_cache_op(unsigned long start, unsigned long end, int= flags) * 0x9f0000 - 0x9fffff are some more esoteric system calls */ #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE) -asmlinkage int arm_syscall(int no, struct pt_regs *regs) +int arm_syscall(int no, struct pt_regs *regs) { if ((no >> 16) !=3D (__ARM_NR_BASE>> 16)) return bad_syscall(no, regs); --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 3144F20720D for ; Tue, 29 Oct 2024 10:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199184; cv=none; b=BaybqyW3d/mnZ0YdtbHZunbN7cSmPdOl+sDFfgS4KP5/Wc8a/qyZznmSjp5fsskovirL+s3qY0Pa7iZsZZpOw44NtXG8ffmqKTeOeGHkmoRVcVBqqaVONGl73oBERa5wMzo/qY6Keo7YvYYVAiY5+bAEetZtwsqUOMMwE6TFwms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199184; c=relaxed/simple; bh=t98uwCV61GyOOlPQHbY+AntVKd7h/1gQX9jOuNSoZ9c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KYuoBWo6TBUwWqSfOSsOHMn+wXI19C4tr4V5yyJ6N779ZKM8GDaTZt8Wy5pC0ZOrsWb7xfbuBpGQvHqk+Usbd1Jlu2Xdx3+gWBRjOKYkTlRSFA8BnaSz8t0XQ/iHsdELD83fxCZtdKHTAx8lI1eEidoHhoa32c91LUpgVvltFIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=QKWyFmag; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QKWyFmag" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-539e4b7409fso5072504e87.0 for ; Tue, 29 Oct 2024 03:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199180; x=1730803980; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8kAN7grhcUpbCDFoKucfYZVBg7IClr2vppXay/MPoLQ=; b=QKWyFmagbzSc/ye+E3f3d9Xoix10Pyvq7vXQ4LXoJdsubjHKq+6W67TJkhxm5blIzS lCu9+uPRQ6ky8OnqlHIuS+nu2lAn0nEOEvFgfMYxeFA1p7bwKcnNnOmIHs/dAakEktoL Ab4IqAn1qwwTT7un5/BXhTs3D+M5FnpENkrOAmKNiZdk/muvltt4RikpKsIHfEearjK6 cVkXCGEe72scDLmJzze0ldcGyrjjw2hcYKUr7tGVlvxImZMrJhuwWLgpPUDXuc2yukNV EuB/eNvmR6SOijM+OGERGirbYiKGEnkzGK+xfiaf11DFY3iGUVGjSeeLA6H9LaC6KkUp pTaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199180; x=1730803980; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8kAN7grhcUpbCDFoKucfYZVBg7IClr2vppXay/MPoLQ=; b=fwDbfe7J/O4QbTGbG2BVc2opU8eW0LVHZZUkIVuhchaJe2rgJyCuzZ45XVRrfouTRf tRTsoP+ke7C+wjSjtsD8GTKyeDigaB2IIxUpw1Bykq5QKYvucsFm+SD7xevhO/HsywcG Cn/T4yyC6srNKk2JgJKlQIaglf9ZpX+KQ6LRLqtXxGpsotjx5WMVxt/YWI0iCydNyqdx 6+0bBliOhxMJIO8UQR/HuLC+wsqhQsERIg4gDz0C1iiGAO3tV55oLLc88ac+hVidYcSc oCT3WQImUe6BN4sPbEAw0qiDHlo2NSbTzEX2rBrxQJOufiAo/vSk59tv4cOlsLLhH0sS LbQQ== X-Forwarded-Encrypted: i=1; AJvYcCURt/mmKgrFgQ0H14YO/ks5MltJi8wLHUJR8MxW/+SfMgV1rSvAHr29dGe5GmTi/oui/lUqyW6HwcIRwto=@vger.kernel.org X-Gm-Message-State: AOJu0Yxf8QEG4E4W/yUUvcjpkoc5DX6XWZ9Pl9JJlZ0AqcPP0ucv0Zb6 pWRv25Z7rhVp/uzfKcvdBq6sRW+RwVufYTtkhGIuWkojvHOHNuOQ9DwhwyIMYsk= X-Google-Smtp-Source: AGHT+IE+BAtVqBrWdYhrt5vvhzxjJUA1tOK/oyMlifKXwIMsOAQXf/e2P1Qd8xMaKhzFGR4sJKMkaA== X-Received: by 2002:a05:6512:4012:b0:539:e263:331c with SMTP id 2adb3069b0e04-53b4944ffd6mr614860e87.17.1730199180265; Tue, 29 Oct 2024 03:53:00 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:52:59 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:48 +0100 Subject: [PATCH RFC v2 08/28] ARM: entry: Move trace entry to C function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-8-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 This moves over the code entering into tracing into the C syscall invocation code. As syscall_trace_enter() will provide the current syscall number from the regs we need not provide the syscall number to the invocation function any more. Signed-off-by: Linus Walleij --- arch/arm/include/asm/syscall.h | 2 +- arch/arm/kernel/entry-common.S | 6 +----- arch/arm/kernel/syscall.c | 5 ++++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 1d21f26ecf51..66067d165ba3 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -20,7 +20,7 @@ extern const unsigned long sys_call_table[]; =20 int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp= ); -int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void= *retp); +int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp); =20 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 77801d039b5f..3cfc6d952ff9 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -292,13 +292,9 @@ ENDPROC(vector_swi) * context switches, and waiting for our parent to respond. */ __sys_trace: - add r0, sp, #S_OFF - bl syscall_trace_enter - mov scno, r0 - mov r2, r0 @ scno into r2 add r1, sp, #S_R0 + S_OFF @ pointer to regs mov r0, tbl - badr r3, __sys_trace_return + badr r2, __sys_trace_return bl invoke_syscall_trace cmp r0, #-1 bne __sys_trace_return diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index d1259c6d2805..815312f7b254 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -19,8 +19,11 @@ __visible int invoke_syscall(void *table, struct pt_regs= *regs, int scno, void * =20 int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, = void *retp); =20 -__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int = scno, void *retp) +__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, void= *retp) { + int scno; + + scno =3D syscall_trace_enter(regs); if (scno =3D=3D -1) return -1; =20 --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 363DD2071FE for ; Tue, 29 Oct 2024 10:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199186; cv=none; b=RMDGl7GS8WA1CZmNC4n8+KeNaxuoUsywtmxVRgK8fTUI82TQNqLnoeqxPlx8PaTUJWqmCp/sgV48EBTi4hx9KJRqj1J5bsHSfmg73R0/+Wx0vpPoGSiB8fvoEaxdnEplzTX76X222xWtvPAipqCUic9VdDt5d0Z5FUzaWuQ9T48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199186; c=relaxed/simple; bh=TeWXUuVvYN/LOwsrfz7FuUVO8Dn9W3GDV6NRqA6SalU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=az3/pZl65BkbP0sFd0QAG2XC0ZMaOzuO+EXkfqYRnZeLT67FPSLflA4TfxRliHy0U/2deaarCdEnuaZFHoMvnHttInp32HNWMvjp5kuzw0jMA+rAFLm1o8e+zEJbbXdH9595vQ+Hz5DUDBewh13rO5ARojyuuBvFJsjnLynlpVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=K/DGrALV; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="K/DGrALV" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-539e63c8678so5347725e87.0 for ; Tue, 29 Oct 2024 03:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199182; x=1730803982; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wP1nC9llP2df/xsfs1zPIJ3oMrkiGOdpltxFcj+OFqQ=; b=K/DGrALVhGULPSU7M9E2Pj6YTXJtexwqx+iZVVVMreq8aml/Nz4KzapBTF9/YGWN1B X5bc//iFm+40Gq6Yh0bya+MqjigaW7yASTmj3HAHYlP4VFwe7glXTShvHkN9LvlPFTYa kCsFHBRff6HLBW0ddQYtgXf68UZIJB2KZ654lzY5vO7XYt5CB+f0PVOxUmVnqHfTLa6O aU9CNVzittcsiKEYf0X6nZ49iHmOWpebYb1fvQA5k2/HghBhJT17lBNZTK5+qLgb9tEX /ZdSgx6kiAHgthq+Ube9z6LY3L5LXBhF8Ss2S0q83hi31/fMNtcSFBOiUeu0AIMVZ7AY Kpzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199182; x=1730803982; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wP1nC9llP2df/xsfs1zPIJ3oMrkiGOdpltxFcj+OFqQ=; b=n4WT6HyO6Nbb++9gV3oSy5lt+opGJfH5SZ+80NsCIHGazl7Rgb1M7e/Ka0XABA5UDE lQLpMogvvghza42asAKow8pm/SJYrtOzGNVtke4CvOQDyYFTmgn5DTq8vRoswjYgsfKZ YqTzexJF53C5eZGPkC9DhX5oS7HaIQ2+eReu8EMg5ZKtAxAE07D21q6NcSfVlRg3Uhrh i+F5s+mmHEmahPxZEEkVApC8OED8xFpMTx1j4FyVP88/a+MMshNobsxJ5ryAhKNeLGxm 6fC1YBQsS26zC75AHYHJ/CXXvpVHdeJSPPAE11v8Io1Mdc5UUGTFa7H2ExQQ6miUbjTt Y7uw== X-Forwarded-Encrypted: i=1; AJvYcCVzELRAPfoNRA2CZV98pkp3/mFnMGlqJogewH9vl6syaoNljPi059wl6NE0EhQcBAz8tFW0mb3pNkUYSHM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5zpcP4Xdx8IUHDodbAzFXOXr5YM8xGXgs9Gg+pQPBW2ETypM4 R3FNi57FQqRWCBYnFHHmX4m/7tbUDhbdhtLqTSLi1kaLYXS8QLeCjGloiMU84HY= X-Google-Smtp-Source: AGHT+IE/w7kIOXo/Y3qsbp0tgFseC/dxf4IJVHvxSY84qtp5r2/GkVLWSkRL6dmR+BAQtvd2iOudFA== X-Received: by 2002:a05:6512:10d1:b0:53b:1f7a:9bfd with SMTP id 2adb3069b0e04-53b34a343d5mr5817803e87.52.1730199182371; Tue, 29 Oct 2024 03:53:02 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:00 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:49 +0100 Subject: [PATCH RFC v2 09/28] ARM: entry: save the syscall sp in thread_info Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-9-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 We are going to rewrite the syscall handling in C, which means that the stack used by the call code is no longer predicatably 8 bytes (for syscall arguments r4 and r5) but a varying number of bytes depending on how nested the C code is. However the current code is just assuming it can rewind the stack by adding 8 to sp if a syscall is interrupted by a sigreturn call. Solve this by storing the entry sp in the per-task struct thread_info and use that in the sigreturn wrapper instead. We already have the thread info available in the SWI entry and sigreturn is probably not so common that retrieveing a pointer to thread_info should affect anything very much. Storing this per-task in thread_info makes the solution SMP robust. Signed-off-by: Linus Walleij --- arch/arm/include/asm/thread_info.h | 1 + arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kernel/entry-common.S | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thre= ad_info.h index 943ffcf069d2..d8a45c5a1049 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -67,6 +67,7 @@ struct thread_info { __u32 cpu_domain; /* cpu domain */ struct cpu_context_save cpu_context; /* cpu context */ __u32 abi_syscall; /* ABI type and syscall nr */ + __u32 sp_syscall; /* SP when entering syscall */ unsigned long tp_value[2]; /* TLS registers */ union fp_state fpstate __attribute__((aligned(8))); union vfp_state vfpstate; diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index 4853875740d0..c9525cbb26b7 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -49,6 +49,7 @@ int main(void) DEFINE(TI_CPU_DOMAIN, offsetof(struct thread_info, cpu_domain)); DEFINE(TI_CPU_SAVE, offsetof(struct thread_info, cpu_context)); DEFINE(TI_ABI_SYSCALL, offsetof(struct thread_info, abi_syscall)); + DEFINE(TI_SP_SYSCALL, offsetof(struct thread_info, sp_syscall)); DEFINE(TI_TP_VALUE, offsetof(struct thread_info, tp_value)); DEFINE(TI_FPSTATE, offsetof(struct thread_info, fpstate)); #ifdef CONFIG_VFP diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 3cfc6d952ff9..8baab7f97f59 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -232,6 +232,8 @@ ENTRY(vector_swi) =20 uaccess_disable tbl get_thread_info tsk + /* Save a per-task copy of SP for sigreturn */ + str sp, [tsk, #TI_SP_SYSCALL] =20 adr tbl, sys_call_table @ load syscall table pointer =20 @@ -377,13 +379,15 @@ sys_syscall: ENDPROC(sys_syscall) =20 sys_sigreturn_wrapper: - add r0, sp, #S_OFF + get_thread_info tsk + ldr r0, [tsk, #TI_SP_SYSCALL] @ read back SP mov why, #0 @ prevent syscall restart handling b sys_sigreturn ENDPROC(sys_sigreturn_wrapper) =20 sys_rt_sigreturn_wrapper: - add r0, sp, #S_OFF + get_thread_info tsk + ldr r0, [tsk, #TI_SP_SYSCALL] @ read back SP mov why, #0 @ prevent syscall restart handling b sys_rt_sigreturn ENDPROC(sys_rt_sigreturn_wrapper) --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 D54762076C4 for ; Tue, 29 Oct 2024 10:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199188; cv=none; b=gRkv613yYGWTWjCkDHZRliwGsbX9zji4ytUbLteJr1fANRK91AdTvZRDlOVzGbi7maoGtge+jgcIqJC0D7sy10+Vatf/d4ciwKVZ9KTm2xnMSamO/zlvWRxBApey30EyA+JCT6ZkOyk5DICTzOZ+6rr4a5y3IQlkyhQCTeEU1w0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199188; c=relaxed/simple; bh=qkK3Y6eLdgBo76rzyOTfD4ef26pREyX7JWY2zTE4baU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u7kz2LN11L6/sYl3OIcHi+pC4PUdwEYB6utCOXxFMbo6+3UWdwgtl2S6Ql2lWEGd07X/kB1tkK6fA6Fs+Qd+qyDx+h3xksmkpTUU7kN+yX3hL/WmvoufUUbrwkBLUzO402ggFMT5Bi5jKrmmIv5YJnToheJRG/7Bid4GuExu1Ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dnRxapY/; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dnRxapY/" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-539e4b7409fso5072544e87.0 for ; Tue, 29 Oct 2024 03:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199184; x=1730803984; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HAeVmp86zd6G4zC8AXuoLcHe5Kdpm6JlP18N2B6Kh/4=; b=dnRxapY/qRiCD+KIt66YGtsGzBX7gjU2RydehDOfPJTllBOh5L76YiUyTRQqqMZ/03 9RAATHUEQXcldObGBCHQ/u2/0FBmjFcGO4alWjLrPymaAJu03R6oBfKS+qc03tWfwhau oHTffRUMdmIi+nSxeeJVvCJMYgrdNskJcrmsF15Iwop5aEPCKYHHAdkBfar0Lm2sn98p iPR3GCW2Wx4RtDpOGy/v1itQbRYPDlA8MBQ27M38co+oG3XvIHTN+hBLLSB0BuV8fn0W 7W9E5pF3XtXRxtFxsP6X7YPqL9BqBLMcVvmECuiA5itGmFm5huFM6v6UzRfAEE6ueUEO p/dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199184; x=1730803984; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HAeVmp86zd6G4zC8AXuoLcHe5Kdpm6JlP18N2B6Kh/4=; b=N8QQTgRqBzkMj06b+YaWhH2C49Z6aHciyrKYTnq/J8+mq9cZExWcpzfFIVAwjOQlEY ZIEMvl5xrUIOe1Uhu9ALNsvDqUa9Il+Ca8M79fpkE82BaN8nKFHAOIrnnXL2gKIZgT+R C216Tm+7smoTVWNAEgdLPjxBNEYaYBrfjwRskZmHBeI0KLExo1cuyJbvyv/jNmS483Wj h77OACosB6vd3DpNQoqWTMA+tZpIXu737QvRytJivPsETJ4G4VUBJub+aM6BCpm6Vnlf nwbkzqHm0Sde6Z/9KAbCQ13VeVf3TLsKHhLp5KT+u8LnMkw3VFUASDPbmHlsu++r9cVy k1WA== X-Forwarded-Encrypted: i=1; AJvYcCXJndVrmSdvQ91XGyOAruuOtq+qi2xLS7SQNwp0XQKBHvHgS4kWRZ20plsQb8sUIjh5x65ZhO4GSaLMtqQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxzxaeXfV2Vrmv/WiohUfaoa8WguEjPLs7gcWdJTgp87ObW9IJv xKjTp2RIWu+LYNhvizwYNJ/HY4nlz44s2sQ8xj00edPa37ocHDAReh7t6cipeoM= X-Google-Smtp-Source: AGHT+IFefyGlbbRKMfUFrz0xvxG/5dLGzWVofaMM/165xooZgf0Xpl0v+lfmrHJRxGbEyXi2pOzvbQ== X-Received: by 2002:a05:6512:696:b0:539:fcf0:268e with SMTP id 2adb3069b0e04-53b4922ad58mr608713e87.14.1730199183928; Tue, 29 Oct 2024 03:53:03 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:02 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:50 +0100 Subject: [PATCH RFC v2 10/28] ARM: entry: move all tracing invocation to C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-10-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The traced invocation of syscall is rewritten in C, moving over also the call to syscall_trace_exit() to C. To do this we cannot have invoke_syscall_trace_asm() be a leaf call, which is the mechanism we hithereto relied on to make sure the stack is pulled back to the state we were at before we called out to the code written in C. Push the registers potentially used by C on the stack, and make a copy of the two stack-pushed syscall arguments on the top of the stack before invoking the syscall and then drop these copied arguments and pop back the registers before returning from invoke_syscall_trace_asm(). As we are now calling from and returning to C, we no longer need to pass the regs pointer around so drop it. Signed-off-by: Linus Walleij --- arch/arm/include/asm/syscall.h | 2 +- arch/arm/kernel/entry-common.S | 32 +++++++++++++++----------------- arch/arm/kernel/ptrace.c | 2 +- arch/arm/kernel/syscall.c | 30 +++++++++++++++++++++--------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 66067d165ba3..cb0073c4151b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -20,7 +20,7 @@ extern const unsigned long sys_call_table[]; =20 int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp= ); -int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp); +void invoke_syscall_trace(void *table, struct pt_regs *regs); =20 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 8baab7f97f59..dbc947d301ec 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -296,22 +296,11 @@ ENDPROC(vector_swi) __sys_trace: add r1, sp, #S_R0 + S_OFF @ pointer to regs mov r0, tbl - badr r2, __sys_trace_return bl invoke_syscall_trace - cmp r0, #-1 - bne __sys_trace_return - add sp, sp, #S_OFF @ restore stack - -__sys_trace_return_nosave: - enable_irq_notrace - mov r0, sp - bl syscall_trace_exit + add sp, sp, #S_OFF @ restore stack pointer b ret_to_user =20 -__sys_trace_return: - str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 - mov r0, sp - bl syscall_trace_exit +__sys_trace_return_nosave: b ret_to_user =20 .macro syscall_table_start, sym @@ -437,18 +426,27 @@ SYM_FUNC_END(invoke_syscall_asm) * r0: syscall table * r1: regs * r2: syscall number - * r3: pointer to return function */ SYM_TYPED_FUNC_START(invoke_syscall_trace_asm) #ifdef CONFIG_CPU_SPECTRE csdb #endif + /* Save registers because we are being called from C */ + push {r4 - r10, lr} mov tbl, r0 + /* Make space to copy the two syscall stack arguments */ + sub sp, sp, #S_OFF mov scno, r2 - mov lr, r3 @ return address - ldmia r1, {r0 - r6} @ reload r0-r6 - stmia sp, {r4, r5} @ update stack arguments + badr lr, __invoke_syscall_trace_ret @ return right here + ldmia r1, {r0 - r6} @ reload r0-r6 from regs + stmia sp, {r4, r5} @ copy stack arguments ldr pc, [tbl, scno, lsl #2] @ call sys_* routine +__invoke_syscall_trace_ret: + /* Drop the copied stack arguments */ + add sp, sp, #S_OFF + pop {r4 - r10, lr} + ARM( mov pc, lr ) + THUMB( bx lr ) SYM_FUNC_END(invoke_syscall_trace_asm) =20 #ifdef CONFIG_OABI_COMPAT diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index 07b0daf47441..ac7b98ae4724 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -888,7 +888,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs) return scno; } =20 -asmlinkage void syscall_trace_exit(struct pt_regs *regs) +void syscall_trace_exit(struct pt_regs *regs) { /* * Audit the syscall before anything else, as a debugger may diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index 815312f7b254..3ee367958298 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -17,22 +17,34 @@ __visible int invoke_syscall(void *table, struct pt_reg= s *regs, int scno, void * return sys_ni_syscall(); } =20 -int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, = void *retp); +int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno); =20 -__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, void= *retp) +__visible void invoke_syscall_trace(void *table, struct pt_regs *regs) { int scno; + int ret; =20 scno =3D syscall_trace_enter(regs); if (scno =3D=3D -1) - return -1; + goto trace_exit_nosave; =20 - if (scno < NR_syscalls) - /* Doing this with return makes sure the stack gets pop:ed */ - return invoke_syscall_trace_asm(table, regs, scno, retp); + if (scno < NR_syscalls) { + ret =3D invoke_syscall_trace_asm(table, regs, scno); + goto trace_exit_save; + } =20 - if (scno >=3D __ARM_NR_BASE) - return arm_syscall(scno, regs); + if (scno >=3D __ARM_NR_BASE) { + ret =3D arm_syscall(scno, regs); + goto trace_exit_save; + } =20 - return sys_ni_syscall(); + ret =3D sys_ni_syscall(); + +trace_exit_save: + /* Save return value from syscall */ + regs->ARM_r0 =3D ret; + +trace_exit_nosave: + local_irq_enable(); + syscall_trace_exit(regs); } --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 3743F207A17 for ; Tue, 29 Oct 2024 10:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199190; cv=none; b=Ki2tW35FDc0OsPCeMwaB4yUNUfUrWRpsBQXvTua1/a5QDbImzahM8j2+1kvBFHmeAI1PZIHmHMVdJG8x4cFhquIoodAYPmiZ1qVikj7KSIsWGBjOI1JDRGXD6bhfG9oqiV8+qrd7wcjoaiCxPSbg9f65i8XKnDAf/i5Veu7mH7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199190; c=relaxed/simple; bh=Xo+V1CZRSvq8YRy8tU8+41AjinOUKFVT3YCYSnKFWvk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fkUkRY7k+pRs5BXV8CuByoEee30Zg1oW2AmZ8SOEMfoTlNZYBHmE8AZr0Y+raYip0XeKWIgrnxqatVI4KwgZVCpYff+lS/xeC5ULSGJ/FQkNGnc5/NiucTwqgbWk4yHyPPuxcSJgHxi7MFKHkK1ikQYqnF6ebZfL1EVdzxDA6Nc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=mCXQFpnw; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mCXQFpnw" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53a0c160b94so5892395e87.2 for ; Tue, 29 Oct 2024 03:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199186; x=1730803986; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+Ojsf1FDD3J/q7BWA6tzk7mG2LcyH7oHP8nC2ES9d2U=; b=mCXQFpnww5d0GTztfQ48K7FTPQEV4DAcHqDCNguo4J8ZLFTakNvWsMujP6mTMx1hq3 jo0X2W9gItdYYZzFdVX8mPcImjHTBCNre0k7wh2ylRIYvBrRzcbX+vGUY5qwSDzbgPq3 goYIr4iNbIBZFanWqpKKEfsPTfIlsE4TKoDzECT3ZBhAAnlieBygatZ+xiij8zfeBpKp M4xbCMk9zPf3i9xcqVJaV9+4VOalM7ryypsOOoUS/IkXcnqn3PLaK9zGLRu6VHBQgMgj ytTKuGCww9ijKC9sa8YS92thCsbfmXPez7z4p8ijRw05QqbkVKV/K9jfq2vn6mvRZkXp AxCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199186; x=1730803986; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Ojsf1FDD3J/q7BWA6tzk7mG2LcyH7oHP8nC2ES9d2U=; b=JYKkJxQVbTRzQf50OYXlqWRhwur+2PeXmCXXQGOShFMoJhIVwXMKxKqQk8JqXax73X NCmFyOWcZ2fhvp+CkppufmM/W6lRESJKXM4sk0COlDaFssHeSFl5t4RlFOGv//6nu0DM 4gsRxxMCyB0tY5vz93Y8163AZmMMmyrENAWja9olHkBRPoDiogvHIO+azS+ZE3+VgKtu wKoNiNI1K6HkwEYybHJYXP9G4Rs6N6WlOLjYDSmAvASoYZPCGFmUhlO56f0Rz8MHt9Gn KMBg8ZLBidMFZ2dVh4Uduin0/zho709iQrWD3FzqT1x/iSejOAWDRB9woiSh+81hh8um 3/kg== X-Forwarded-Encrypted: i=1; AJvYcCXQIXa0dF6QPqp6KuOawD7oO8M9Ap2GW7ioIWnCQPPVCuqbJuDGWQOfS+/N9ZCzXOiVchWDEl4Ebr9lXPw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4OEGHUC7204eHi/M26U5bnv88CZfCzR1g9zcUKGRxNfR6lcWb c6jTTiTBkGS5aMel5YYQyO2DdieGGZJftcOTY4CISIWEHbZblj9JL+Q2fVibz6Y= X-Google-Smtp-Source: AGHT+IFXG4+qFOLuZpZcmM1Lay+S0Jgq0PH3SGHMivCPOmdGtmS+4HV+qVrZtyBne6W8UBHPMqEfcA== X-Received: by 2002:ac2:4e0b:0:b0:536:741a:6bad with SMTP id 2adb3069b0e04-53b348c1086mr5244851e87.12.1730199186296; Tue, 29 Oct 2024 03:53:06 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:04 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:51 +0100 Subject: [PATCH RFC v2 11/28] ARM: entry: Merge the common and trace entry code Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-11-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The trace entry code now can handle recursive and complex calls in C using stack. Move the common code over to using that approach. We now use the ret_fast_syscall return path also when tracing, which appears to work just fine. Signed-off-by: Linus Walleij --- arch/arm/include/asm/syscall.h | 3 +-- arch/arm/kernel/entry-common.S | 61 +++++++++-----------------------------= ---- arch/arm/kernel/syscall.c | 34 +++++++++++------------ 3 files changed, 28 insertions(+), 70 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index cb0073c4151b..9c664d8c5718 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -19,8 +19,7 @@ =20 extern const unsigned long sys_call_table[]; =20 -int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp= ); -void invoke_syscall_trace(void *table, struct pt_regs *regs); +int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno); =20 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index dbc947d301ec..f0f1f8723965 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -39,7 +39,6 @@ saved_pc .req lr * from those features make this path too inefficient. */ ret_fast_syscall: -__ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) disable_irq_notrace @ disable interrupts @@ -47,13 +46,13 @@ __ret_fast_syscall: movs r1, r1, lsl #16 bne fast_work_pending =20 - restore_user_regs fast =3D 1, offset =3D S_OFF + restore_user_regs fast =3D 0, offset =3D S_OFF UNWIND(.fnend ) ENDPROC(ret_fast_syscall) =20 /* Ok, we need to do extra processing, enter the slow path. */ fast_work_pending: - str r0, [sp, #S_R0+S_OFF]! @ returned r0 + add sp, sp, #(S_R0 + S_OFF) /* fall through to work_pending */ #else /* @@ -63,10 +62,9 @@ fast_work_pending: * call. */ ret_fast_syscall: -__ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) - str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 + add sp, sp, #(S_R0 + S_OFF) #if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ mov r0, sp @ 'regs' @@ -83,7 +81,9 @@ ENDPROC(ret_fast_syscall) #endif =20 tst r1, #_TIF_SYSCALL_WORK - bne __sys_trace_return_nosave + beq slow_work_pending + b ret_to_user + slow_work_pending: mov r0, sp @ 'regs' bl do_work_pending @@ -257,19 +257,15 @@ ENTRY(vector_swi) str scno, [tsk, #TI_ABI_SYSCALL] #endif mov r1, sp @ put regs into r1 - ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args - - tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? - bne __sys_trace - mov r0, tbl - /* r1 already contains regs */ mov r2, scno @ syscall number from r7 - /* We return here no matter what, also pass this as an argument */ - badr lr, __ret_fast_syscall - mov r3, lr - b invoke_syscall + bl invoke_syscall_trace + cmp r0, #0 + beq ret_fast_syscall + /* This path taken when tracing */ + add sp, sp, #(S_R0 + S_OFF) + b ret_to_user =20 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) /* @@ -289,20 +285,6 @@ ENTRY(vector_swi) ENDPROC(vector_swi) .ltorg =20 - /* - * This is the really slow path. We're going to be doing - * context switches, and waiting for our parent to respond. - */ -__sys_trace: - add r1, sp, #S_R0 + S_OFF @ pointer to regs - mov r0, tbl - bl invoke_syscall_trace - add sp, sp, #S_OFF @ restore stack pointer - b ret_to_user - -__sys_trace_return_nosave: - b ret_to_user - .macro syscall_table_start, sym .equ __sys_nr, 0 .type \sym, #object @@ -402,25 +384,6 @@ sys_mmap2: b sys_mmap_pgoff ENDPROC(sys_mmap2) =20 -/* - * This call wants: - * r0: syscall table - * r1: regs - * r2: syscall number - * r3: pointer to return function - */ -SYM_TYPED_FUNC_START(invoke_syscall_asm) -#ifdef CONFIG_CPU_SPECTRE - csdb -#endif - mov tbl, r0 - mov scno, r2 - mov lr, r3 @ return address - ldmia r1, {r0 - r3} @ reload r0-r3 - /* Arguments 5 and 6 are (hopefully) on the stack */ - ldr pc, [tbl, scno, lsl #2] @ call sys_* routine -SYM_FUNC_END(invoke_syscall_asm) - /* * This call wants: * r0: syscall table diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index 3ee367958298..ab9e66da0a80 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -3,48 +3,44 @@ #include #include =20 -int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno, void *= retp); - -__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, = void *retp) +static inline bool has_syscall_work(unsigned long flags) { - if (scno < NR_syscalls) - /* Doing this with return makes sure the stack gets pop:ed */ - return invoke_syscall_asm(table, regs, scno, retp); - - if (scno >=3D __ARM_NR_BASE) - return arm_syscall(scno, regs); - - return sys_ni_syscall(); + return unlikely(flags & _TIF_SYSCALL_WORK); } =20 int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno); =20 -__visible void invoke_syscall_trace(void *table, struct pt_regs *regs) +__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int = scno) { - int scno; + unsigned long flags =3D read_thread_flags(); int ret; =20 - scno =3D syscall_trace_enter(regs); - if (scno =3D=3D -1) - goto trace_exit_nosave; + if (has_syscall_work(flags)) { + scno =3D syscall_trace_enter(regs); + if (scno =3D=3D -1) + goto trace_exit_nosave; + } =20 if (scno < NR_syscalls) { ret =3D invoke_syscall_trace_asm(table, regs, scno); - goto trace_exit_save; + goto exit_save; } =20 if (scno >=3D __ARM_NR_BASE) { ret =3D arm_syscall(scno, regs); - goto trace_exit_save; + goto exit_save; } =20 ret =3D sys_ni_syscall(); =20 -trace_exit_save: +exit_save: /* Save return value from syscall */ regs->ARM_r0 =3D ret; + if (!has_syscall_work(flags)) + return 0; =20 trace_exit_nosave: local_irq_enable(); syscall_trace_exit(regs); + return 1; } --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 CBE43207A31 for ; Tue, 29 Oct 2024 10:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199192; cv=none; b=KDqqsbgxoUjWeUNP4e4D5P7ThGnS/4xW5n+GR/0cf6m0USWJyJM+nPu12EC7BwbAagav6TpCEYXQ6QbM5W2j1Vve3bfiWu5CzZMgNu/kq5Ql2NngVejq7gSEdDP/NqqUBBIxiSn9WG+LduQffMHl0O87aZln7ha/r4jFIEQ3w3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199192; c=relaxed/simple; bh=GlhKGb3knP5MTTv+ON8XhDtdyIyG0oHge7Bj6y3E7+E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cNsWG6Wqwj73PD9dlZeDlshRqEDuc8GcwuFuAS4vP8SEr5pv3mX2UxJXXN224l3e+JwDHE3VLG/FpqP/cap7WH5HViczPiuvhXHnxofDj0D58IH634UFkIcX8le5IllqpbATfnPGT3FriT5T03vE/GzJLi9b99gLLCyrYv/TCCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=GB/Olxc4; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GB/Olxc4" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2fb51e00c05so77807021fa.0 for ; Tue, 29 Oct 2024 03:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199188; x=1730803988; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=VzzrIJOoccLZThZLp3kOXktHyMNXE6/2voWdPpMOjWQ=; b=GB/Olxc4blEpmLem/1YoVHxvlzdUTIb/6hFuocmi2tfU1xu5yzuxXxqO4NFmvILcZW 9ZDU8CwKT+z2wPgTX59eEF7Ue4J3MhfKC6Xs1Ajrxe+sPsb6o8AV9yKIXh2oNT5URMNT mNsD2xKJeEG2/Q+LsPHLT2WG2CO4+GwaoMzRoi0957X80d0dlfwZvUj3CFCe0d/7VdGD 282E7PGOqUVAQlnqgd+nv+tPw5LF2ftZclY2zjARJTBzXxELkxbeRiDsMA8FkbY4aq1F +w6LSRGFpgmw5rfOeXDw0n0CPtRrrdwqHBEM04d7Q+QD99IqlfUs6nK3x0+6ZJ60OMU5 IfYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199188; x=1730803988; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VzzrIJOoccLZThZLp3kOXktHyMNXE6/2voWdPpMOjWQ=; b=e9PLXVHU49dsr44V42bsmAjLLVCn1yBv5bXktt3wnPg5RvSBCjtDDDjsGg6ce3njJl qZiYgjJRtL5/GNDWKopwJA54/xpPEXViKnubEpP/P+Zx4Vy+AQG7gKZ3WfabWHIRa9nK pu2pWftFKZjIaN2WD5BCwUh6JbaArxm1Bun4gaXYraTIjb/xCVONR/WnP5CjJoe+QT+G S0IRt7d14jkxnoy6ZJNLP2NeFU5vXYtu+r6FqNngvv7ghKgi5qObPg9Mqjb8yrSHRJZr tgAJcGRK/x8sjo/4RlfgAHqMWzS8fK9ii4h5UzyuFoKb8B6QX1s+dMg05ztdjBeyVsRy WUUQ== X-Forwarded-Encrypted: i=1; AJvYcCVLK8C7EYFH5eaFN/Q6JvqIzz/ne7rm01ngPBaGT62Y9fZD9enDN41UUqz/Gcr80nZIIG9krZLoe8GG7uU=@vger.kernel.org X-Gm-Message-State: AOJu0YxEZqtVW2Knf42mhPHlaqztwPWTPy649TnE0Cif80iZwqjdE5Cu DBf04rCQ8W8lbBzoMORqwF7VtMA6MYCop18yvLHASMLPZOtbA5ONjprEFKQO608t60IwGLb9URL v X-Google-Smtp-Source: AGHT+IGRCP9njDT3bh0HLZQdKXOdaIKdzw+lCjY7s08cyEsqWgr6D/0u3fyrkqBD9EnSPMiRj86V7w== X-Received: by 2002:a05:6512:10c7:b0:52e:936e:a237 with SMTP id 2adb3069b0e04-53b348cc510mr9200713e87.16.1730199187934; Tue, 29 Oct 2024 03:53:07 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:06 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:52 +0100 Subject: [PATCH RFC v2 12/28] ARM: entry: Rename syscall invocation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-12-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 Now that we do not have a separate trace syscall invocation path, rename the invocation functions to be generic. This can be squashed into the previous patch, it is just done here for the previous patch to be easier to get a cleaner diff and be easier to read. Signed-off-by: Linus Walleij --- arch/arm/include/asm/syscall.h | 2 +- arch/arm/kernel/entry-common.S | 10 +++++----- arch/arm/kernel/syscall.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 9c664d8c5718..b94fd7ce17f8 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -19,7 +19,7 @@ =20 extern const unsigned long sys_call_table[]; =20 -int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno); +int invoke_syscall(void *table, struct pt_regs *regs, int scno); =20 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index f0f1f8723965..f1e48002bd30 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -260,7 +260,7 @@ ENTRY(vector_swi) stmdb sp!, {r4, r5} @ push fifth and sixth args mov r0, tbl mov r2, scno @ syscall number from r7 - bl invoke_syscall_trace + bl invoke_syscall cmp r0, #0 beq ret_fast_syscall /* This path taken when tracing */ @@ -390,7 +390,7 @@ ENDPROC(sys_mmap2) * r1: regs * r2: syscall number */ -SYM_TYPED_FUNC_START(invoke_syscall_trace_asm) +SYM_TYPED_FUNC_START(invoke_syscall_asm) #ifdef CONFIG_CPU_SPECTRE csdb #endif @@ -400,17 +400,17 @@ SYM_TYPED_FUNC_START(invoke_syscall_trace_asm) /* Make space to copy the two syscall stack arguments */ sub sp, sp, #S_OFF mov scno, r2 - badr lr, __invoke_syscall_trace_ret @ return right here + badr lr, __invoke_syscall_ret @ return right here ldmia r1, {r0 - r6} @ reload r0-r6 from regs stmia sp, {r4, r5} @ copy stack arguments ldr pc, [tbl, scno, lsl #2] @ call sys_* routine -__invoke_syscall_trace_ret: +__invoke_syscall_ret: /* Drop the copied stack arguments */ add sp, sp, #S_OFF pop {r4 - r10, lr} ARM( mov pc, lr ) THUMB( bx lr ) -SYM_FUNC_END(invoke_syscall_trace_asm) +SYM_FUNC_END(invoke_syscall_asm) =20 #ifdef CONFIG_OABI_COMPAT =20 diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index ab9e66da0a80..968cec945a7e 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -8,9 +8,9 @@ static inline bool has_syscall_work(unsigned long flags) return unlikely(flags & _TIF_SYSCALL_WORK); } =20 -int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno); +int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno); =20 -__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int = scno) +__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno) { unsigned long flags =3D read_thread_flags(); int ret; @@ -22,7 +22,7 @@ __visible int invoke_syscall_trace(void *table, struct pt= _regs *regs, int scno) } =20 if (scno < NR_syscalls) { - ret =3D invoke_syscall_trace_asm(table, regs, scno); + ret =3D invoke_syscall_asm(table, regs, scno); goto exit_save; } =20 --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 EF2C820820F for ; Tue, 29 Oct 2024 10:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199194; cv=none; b=Ggjsa1OAaV/hTkUitbhMY1plw00WU0Q6OVDwFj/rxdK+sfPvdE2iXhEHIZISidGoZ6mKGQ01/sVG4Ww5GzJpjh0bebO964BJ/a5MiWl64KyoIhg7tzeXXuM5hCr7CBCpAAqmOcJpFu7AQTKkAo0uoJTT25zbLb+xu9YIgVvd15M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199194; c=relaxed/simple; bh=F5bQDfkVsSRu/OqASLHtGTld91a3P5BAk4tZTozpgOA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jff3cu8kb8JZtWUaYwBTEE+ZMl9fAXE1TsQwICHO14yqKzCvDL2g0hvIq17fIkmL60MJiw2ffFQPUlRdEhvL7UcJcvVbmQ1YZrVJ0fmVYt5UDcCGoypz+OrPWaxIIolblN30VCJ9cg/dHoMrSkzm+zuM+IE9lg1NGG20CXwLcxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Ku6BZNp3; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ku6BZNp3" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-539e6c754bdso4744273e87.2 for ; Tue, 29 Oct 2024 03:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199190; x=1730803990; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=; b=Ku6BZNp3mjrolV5kaqL9LQIPwv4RkAkYlWrfUKz6q/Gi+njaoqorcCMa44oELCCALX 6qTGFIsgWQ8dwGsACqSfGPvluahILfD4KDbwYL5VmXM8b8hQUBiARqs4AMVMrRTpaLmj SOsWrc85NTkm2mIcqqvSpHZ9wqEurmSOi/vh3WENjoy1mMqaLCmvpR8kzwsO3PPQ7tjw hszScrqNRGzBl7ati1aJh58cOTrXWFyL8VYUGb5Cn/ZS6x+42Ad1xwHid9t6njub9mEl X3fmBMJEyn0i3wo0b+aYzHG9APfzPtc2w26PGG7N+6SWN8Bo/gxSf/Nt44K413zX0jEe kC/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199190; x=1730803990; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=; b=WwSwhtjGnoOEAvXBdabB4VPJvbVkxjHDUKPf1JTrrDet5C6PiihOKM4XqZIZ+US9uQ 3yjVqQqDVZXE2ULDpfjO8f2WnD9mAzTZntwkZdmp3fX2iKfQj/+JzKV/HkmE09eCKbDh CARKw4SysDXnhwNsUtGN8wGsDBhQT+aBuadz9mr3iaJfGpqpyD1pCdj7/D2bfke0z8VD i82iFiE3FpVq0Tichf1ba5270KDUwFnYARZWtDVI/cqvkkTb/dQA7RtU3CWZItfCFwzn lTRGxAWBwURarCvmYc7pCfIOAqk/cy1AbP1SdtKqhwi2SFyW+fP4vRmC0IVyxEvU5Lo/ SeSg== X-Forwarded-Encrypted: i=1; AJvYcCUXWN90rcO/15V0gkGfcaBOatGV5RNTzxs8MN4lKxSOusMMZK5IBT4c/pGWDjh/PNeS8JHBanOVAEV/eUU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4ONWjPJwkPvBFl664QJY729U6FlW3FlKzBDeVcDJ5gZh3/cyv SDgDeQRqFkvLtxPKKzaZU+fDmWEoo5Kjrg36MTjvEOTVHTht4ob7VJezYa6VJqk= X-Google-Smtp-Source: AGHT+IHnu3r1g0OwvCLOiPYGKbeTf+Hv9O68OAgzGiZtRX6hJe7xHb3GGSvsAVORAIl1GunSQigcZQ== X-Received: by 2002:a05:6512:33d5:b0:53a:3a:f4f4 with SMTP id 2adb3069b0e04-53b348e599cmr4735466e87.31.1730199190072; Tue, 29 Oct 2024 03:53:10 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:08 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:53 +0100 Subject: [PATCH RFC v2 13/28] ARM: entry: Create user_mode_enter/exit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-13-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The callbacks to the context tracking will be repurposed for several uses that are needed on the IRQ transition to/from userspace. Rename the macro, establish call sites in C calling into the context tracking following the corresponding generic entry function prototypes, despite the assembly macro names become a bit long this makes it clear to readers exactly what is going on and where this call will go. Drop the ifdefs pertaining to context tracking from the macro. The C calls we will use have stubs that will compile these out anyway. The inversion of the signature of the context tracking calls are especially confusing since the generic entry uses the reverse semantics: *enter from* user mode (to kernel mode) and *exit to* user mode (from kernel mode) instead of the other way around as the old context tracker code user_exit_callable() and user_enter_callable() which have inverted semantics. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 14 ++++++++++++++ arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/entry-armv.S | 2 +- arch/arm/kernel/entry-common.S | 4 ++-- arch/arm/kernel/entry-header.S | 24 ++++++++++++------------ arch/arm/kernel/entry.c | 15 +++++++++++++++ 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h new file mode 100644 index 000000000000..e26f369375ca --- /dev/null +++ b/arch/arm/include/asm/entry.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_ENTRY_H__ +#define __ASM_ENTRY_H__ + +struct pt_regs; + +/* + * These are copies of generic entry headers so we can transition + * to generic entry once they are semantically equivalent. + */ +void irqentry_enter_from_user_mode(struct pt_regs *regs); +void irqentry_exit_to_user_mode(struct pt_regs *regs); + +#endif /* __ASM_ENTRY_H__ */ diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index d5a128a4228d..9a6ac0974110 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -17,7 +17,7 @@ CFLAGS_REMOVE_return_address.o =3D -pg =20 # Object file lists. =20 -obj-y :=3D elf.o entry-common.o irq.o opcodes.o \ +obj-y :=3D elf.o entry.o entry-common.o irq.o opcodes.o \ process.o ptrace.o reboot.o io.o \ setup.o signal.o sigreturn_codes.o \ stacktrace.o sys_arm.o time.o traps.o \ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 1dfae1af8e31..d6e8b36c70f5 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -405,7 +405,7 @@ ENDPROC(__fiq_abt) #ifdef CONFIG_TRACE_IRQFLAGS bl trace_hardirqs_off #endif - ct_user_exit save =3D 0 + asm_irqentry_enter_from_user_mode save =3D 0 .endif .endm =20 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index f1e48002bd30..ff1dd3169346 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -111,7 +111,7 @@ ENTRY(ret_to_user_from_irq) no_work_pending: asm_trace_hardirqs_on save =3D 0 =20 - ct_user_enter save =3D 0 + asm_irqentry_exit_to_user_mode save =3D 0 =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack @@ -191,7 +191,7 @@ ENTRY(vector_swi) alignment_trap r10, ip, cr_alignment asm_trace_hardirqs_on save=3D0 enable_irq_notrace - ct_user_exit save=3D0 + asm_irqentry_enter_from_user_mode save =3D 0 =20 /* * Get the system call number. diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 52b4fa97226d..fb5bb019199b 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -362,31 +362,31 @@ ALT_UP_B(.L1_\@) .endm =20 /* - * Context tracking subsystem. Used to instrument transitions + * Context tracking and other mode transitions. Used to instrument transit= ions * between user and kernel mode. - */ - .macro ct_user_exit, save =3D 1 -#ifdef CONFIG_CONTEXT_TRACKING_USER +*/ + .macro asm_irqentry_enter_from_user_mode, save =3D 1 .if \save stmdb sp!, {r0-r3, ip, lr} - bl user_exit_callable + mov r0, sp @ regs + bl irqentry_enter_from_user_mode ldmia sp!, {r0-r3, ip, lr} .else - bl user_exit_callable + mov r0, sp @ regs + bl irqentry_enter_from_user_mode .endif -#endif .endm =20 - .macro ct_user_enter, save =3D 1 -#ifdef CONFIG_CONTEXT_TRACKING_USER + .macro asm_irqentry_exit_to_user_mode, save =3D 1 .if \save stmdb sp!, {r0-r3, ip, lr} - bl user_enter_callable + mov r0, sp @ regs + bl irqentry_exit_to_user_mode ldmia sp!, {r0-r3, ip, lr} .else - bl user_enter_callable + mov r0, sp @ regs + bl irqentry_exit_to_user_mode .endif -#endif .endm =20 /* diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c new file mode 100644 index 000000000000..8b2e8ea66c13 --- /dev/null +++ b/arch/arm/kernel/entry.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) +{ + /* This context tracking call has inverse naming */ + user_exit_callable(); +} + +noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) +{ + /* This context tracking call has inverse naming */ + user_enter_callable(); +} --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 89568208236 for ; Tue, 29 Oct 2024 10:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199195; cv=none; b=HXFwHIh7VlQwD4r3DDwq7ggnzn2VcNsuml0Sw575Nw1x/nxLhHXzMjS2OfAVAaRntBJ5i4f+J/1PQ1KU5tO3NxrLfqBgI8nwzBac1PfZ5drOerRTuMrA0bVWU0hJLVQidVQCyKGAXvg2W946LXfGdGKNwpmac0mU4opvF4xuX0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199195; c=relaxed/simple; bh=VwHPcRKEp6wrJTlkngBKpHSq3ywUIHnGGlB2f5ulxQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WjV7bkKl7y9EGqPBWaRpXJltlHTC7oVhzjGNYGIKNvcwyZgxb2DuIt5vVbd7u4MARenx4TEJOc3tP79HUCM91kCUxCauXyh1+RVSUVl2ppyWKFN61gUEthheXNdYQ1rA3OxWeaDD8IIY2Mk6OtXx7p9YbxkLevONFIUMHwLqUWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=e9zjvJr+; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="e9zjvJr+" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-53b34ed38easo2587477e87.0 for ; Tue, 29 Oct 2024 03:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199192; x=1730803992; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DsQ2/1OD1833y3AwH5IJOrZR5jmPSoKtfSG79U8bJN4=; b=e9zjvJr+74fmcGx/FffVtGb2MFi7vTcs4ri+L+99YSG6LNn1euR5ogTQZspg8w9+bE UogKOuMbyGSEN5Knu3xf8u9bmMpccpeXSNrAVLryPFwcU4xdlP+for11d5qxwrwYMlig fy5nn5IhVUndpJfGVoGe9p5DuiDrmpUsMHyn5odXRd7/XqNsO2Rp+enPOW/Ruu9CqzRW ah/S7iTC4Yd5eOly3jiBV+UxJriBVMuFZC4P00VVaTKuUlXFkfuOTLCZyFL0xoq+7AF0 TUciskfwjlNMg+YIOeF8/GFYM1MAwhx/u3Pn9yffoJVuDutgplB9pkCRgHiogTj025nA Snvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199192; x=1730803992; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DsQ2/1OD1833y3AwH5IJOrZR5jmPSoKtfSG79U8bJN4=; b=I4AthUVABmfkS9ziMCUNpBIVq+d+jRuGB6x8xObyqUUWWCL08rmNIWV7LT8/OMrlAc DBjyUaCsyQIlzt6hx+dF63IKnC8pxY+/uZ+kai2cnZxQmw99Rj4SPYSB9nBFz51XFRcB p7jnsceZlBTXkhPqPHKrt1KT0JCIHnyc1HJB8Su3MExH5BVtaD8EQgZ5A+sa/Yoz4cUD k7iSN9W8JiAgHMhEVyFDpKGvnpmeoIl6I6oFgxgX/iaKIzjPrXbpwbQ4+8X/9F7vdcTT K9d522+9dIUmu4b3IozV3hVyjAS3rzCYNskOzXr+XM3ZPajTzLw5vby6tzjUdsqIIEqY qlcw== X-Forwarded-Encrypted: i=1; AJvYcCVDoS4Up0LdGG/CsRewluzCxeImLfzqXtOP1L3idUh7+u1yxK59hFr/tNet7BA8uFwYDRyPivSweMixnoI=@vger.kernel.org X-Gm-Message-State: AOJu0YxSwyIh5MlC9M8dck4NMcopHLJA+c/9bSAGYGUoWBlnlrzvwilv 9KBdXKVMm3/rnTLvGHP78ysemJZ+5RGdsfqNDUJt0ECn+TBpB/uA6nKxsxTcyhX1Kta3+cUTV/N y X-Google-Smtp-Source: AGHT+IGOwfWqSbH0lylD+oRmBxNetXVYp5mK7klp6qC5Jtc7snUGEHRWcKY/n0b0UsFd0cmE4rybVA== X-Received: by 2002:a05:6512:2341:b0:536:554a:24c2 with SMTP id 2adb3069b0e04-53b348c8978mr5274118e87.13.1730199191697; Tue, 29 Oct 2024 03:53:11 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:10 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:54 +0100 Subject: [PATCH RFC v2 14/28] ARM: entry: Drop trace argument from usr_entry macro Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-14-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The trace argument select whether to look into tracing of the hardirqs for the exceptions from userspace, but also selects whether to call further down to establish context for RCU. Split off a second macro that is called on everything except the FIQ since this is the only outlier. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-armv.S | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index d6e8b36c70f5..be2df297ec0a 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -356,7 +356,7 @@ ENDPROC(__fiq_abt) #error "sizeof(struct pt_regs) must be a multiple of 8" #endif =20 - .macro usr_entry, trace=3D1, uaccess=3D1 + .macro usr_entry, uaccess=3D1 UNWIND(.fnstart ) UNWIND(.cantunwind ) @ don't unwind the user space sub sp, sp, #PT_REGS_SIZE @@ -400,13 +400,14 @@ ENDPROC(__fiq_abt) @ Clear FP to mark the first stack frame @ zero_fp + .endm =20 - .if \trace + /* Called after usr_entry for everything except FIQ */ + .macro usr_entry_enter #ifdef CONFIG_TRACE_IRQFLAGS bl trace_hardirqs_off #endif asm_irqentry_enter_from_user_mode save =3D 0 - .endif .endm =20 .macro kuser_cmpxchg_check @@ -428,6 +429,7 @@ ENDPROC(__fiq_abt) .align 5 __dabt_usr: usr_entry uaccess=3D0 + usr_entry_enter kuser_cmpxchg_check mov r2, sp dabt_helper @@ -438,6 +440,7 @@ ENDPROC(__dabt_usr) .align 5 __irq_usr: usr_entry + usr_entry_enter kuser_cmpxchg_check irq_handler from_user=3D1 get_thread_info tsk @@ -451,6 +454,7 @@ ENDPROC(__irq_usr) .align 5 __und_usr: usr_entry uaccess=3D0 + usr_entry_enter =20 @ IRQs must be enabled before attempting to read the instruction from @ user space since that could cause a page/translation fault if the @@ -475,6 +479,7 @@ ENDPROC(__und_usr) .align 5 __pabt_usr: usr_entry + usr_entry_enter mov r2, sp @ regs pabt_helper UNWIND(.fnend ) @@ -494,7 +499,7 @@ ENDPROC(ret_from_exception) =20 .align 5 __fiq_usr: - usr_entry trace=3D0 + usr_entry kuser_cmpxchg_check mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 20FC020C46B for ; Tue, 29 Oct 2024 10:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199198; cv=none; b=Spe0i1biodJ6xePbYFQE/MecKCgBRcWsRTcsg1BqOZ/1mmQnLOaCRiQ4t7ey3YuUdhBbZ8CFUnj4OSnBHfT7UPHRdlroc8keDdsJNG9/Z/BEfB/+CS3AqIZ3ZRi8Pz6ZA1H6Gob4pM5+JAyqceXqUQmJTF42FRwITDA/F05v0Yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199198; c=relaxed/simple; bh=GNeY2LQCUhc09WZjjbVfkXZmlZISRGueBzk8RTdV3Hg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B35G23/dGqVLQFFWI/4H3/dttsJ7YKU62k47ayt26crBhBNW2qXaXYcW3I0rAA3pVSYY36oYYwajtspJ7eED9JwFy1rnxdwNlFev6WyVnqGlm3URXeJQ75WTpOEk/zzTpn80knvjX8+oQGYguXQWqAxasuu6+Rj5kmV1DA520s0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=oOaNqpnj; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oOaNqpnj" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-53b13ea6b78so8220997e87.2 for ; Tue, 29 Oct 2024 03:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199193; x=1730803993; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qPx4kMCDrheeY8xWYJ0qE47ahtpfJ0dLdCDyA5qyaAo=; b=oOaNqpnj0lz/3hdWN79LNDKUJfps2FEMpQPvX4ERCgTSbgt8r59u2hoz7uVjG8TFDj yqeYDI5/l8H0l4xoj5h+OXHvpcbHqwK/btlZ/MMUBS+H1qmQCF1AvMKpmW60xe27m5GM i4DdrjxPpyOMGKVCtNW7hVwEJkVwh1lZx/KaGeKyx1Ao7JMBxI6sJ2oQ25coEP+96vxi /2Mlf/urX82v2uhqzTqZXffkYzJriFn/g7TBc5EZ9zMQTvItZ45pRLfgukomY52BAwaI Sjb4CtXYIjV9pLkRZqZl4y9rJGRhArvck/3uwuWX4tpWpzlktBUO2EpC5d5lxChwroHk Ur0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199193; x=1730803993; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qPx4kMCDrheeY8xWYJ0qE47ahtpfJ0dLdCDyA5qyaAo=; b=LBVlMj8nOc8HwgdIuyfSVxiugH+vTz9rOfG4JEWY2H+uexWkyMvpJWJEQZ09rFgk08 NCHor0YN13tuF+Fmpwrx1QnzwZxNdOwl2TCIvofKNp0AFb2MB1ZnRgiMHxgCzkmsIQ8q OhDFdLvAQYf8r9i8YcWIpB5aVDmMXHoIdC5txWGsEYA8ygiKqACMU9gNTaV1zOo1c28/ IYebGlrTo8oBRmy3tuAAWeDCZvktyszueBJAF5A48xgcm6dZGa5iHCUvwdz2DR/p/m87 NwUASTnVyIf47hHUl5CRMQCgSwyVp0iBeyCDhLVBUYBypXtr4AoyHlKbqPd9Ewwuz4ia la3Q== X-Forwarded-Encrypted: i=1; AJvYcCV1L34HFhpXnimdSvhaGlZ7O2MCi7q6v0YoIbhdIgL6qRVuU/GnkBSMWlC2Qw72+Bv1vkHX19DXg9M9Ozc=@vger.kernel.org X-Gm-Message-State: AOJu0YymxiKkRpZTwrFipusvLV+agiqfClarseGANUiET/CE+XN4xi68 7+zAj6s1CeexaGqs93x1SHFX/Gx1kXcmH5xsK8+Cy4r1ZU5h6rQE7BIoycJheTw= X-Google-Smtp-Source: AGHT+IHn5Jo6MxlNJU5iIOZUqab7EQOi+XN5sQRY1pjOsF1gVhbe2i3K7M96BCHGCpFL++J60EFYIg== X-Received: by 2002:a05:6512:a93:b0:535:6925:7a82 with SMTP id 2adb3069b0e04-53b3491e2c7mr8892647e87.41.1730199193203; Tue, 29 Oct 2024 03:53:13 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:12 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:55 +0100 Subject: [PATCH RFC v2 15/28] ARM: entry: Separate call path for syscall SWI entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-15-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The syscalls (SWIs, software interrupts) are deviating from how any other interrupts are handled as they enable the IRQs again while processing the syscall, while "hard" IRQs disable all interrupts until they are handled. Break out syscall_enter_from_user_mode() into its own function and call it instead of irqentry_enter_from_user_mode(). As we are moving toward generic entry, we use the signature from the generic function. As the generic function requires the syscall number to be determined, we move the call down below the code that figures out the syscall number, the only practical effect should be that interrupts are re-enabled a few instructions later. As we move the trace_hardirqs_on/off() calls into C, we can just get rid of the helper macro usr_entry_enter again and call asm_irqentry_enter_from_user_mode directly. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 1 + arch/arm/kernel/entry-armv.S | 16 ++++------------ arch/arm/kernel/entry-common.S | 18 +++++++++++++----- arch/arm/kernel/entry.c | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h index e26f369375ca..e259b074caef 100644 --- a/arch/arm/include/asm/entry.h +++ b/arch/arm/include/asm/entry.h @@ -8,6 +8,7 @@ struct pt_regs; * These are copies of generic entry headers so we can transition * to generic entry once they are semantically equivalent. */ +long syscall_enter_from_user_mode(struct pt_regs *regs, long); void irqentry_enter_from_user_mode(struct pt_regs *regs); void irqentry_exit_to_user_mode(struct pt_regs *regs); =20 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index be2df297ec0a..0328860475e1 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -402,14 +402,6 @@ ENDPROC(__fiq_abt) zero_fp .endm =20 - /* Called after usr_entry for everything except FIQ */ - .macro usr_entry_enter -#ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_off -#endif - asm_irqentry_enter_from_user_mode save =3D 0 - .endm - .macro kuser_cmpxchg_check #if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) #ifndef CONFIG_MMU @@ -429,7 +421,7 @@ ENDPROC(__fiq_abt) .align 5 __dabt_usr: usr_entry uaccess=3D0 - usr_entry_enter + asm_irqentry_enter_from_user_mode save =3D 0 kuser_cmpxchg_check mov r2, sp dabt_helper @@ -440,7 +432,7 @@ ENDPROC(__dabt_usr) .align 5 __irq_usr: usr_entry - usr_entry_enter + asm_irqentry_enter_from_user_mode save =3D 0 kuser_cmpxchg_check irq_handler from_user=3D1 get_thread_info tsk @@ -454,7 +446,7 @@ ENDPROC(__irq_usr) .align 5 __und_usr: usr_entry uaccess=3D0 - usr_entry_enter + asm_irqentry_enter_from_user_mode save =3D 0 =20 @ IRQs must be enabled before attempting to read the instruction from @ user space since that could cause a page/translation fault if the @@ -479,7 +471,7 @@ ENDPROC(__und_usr) .align 5 __pabt_usr: usr_entry - usr_entry_enter + asm_irqentry_enter_from_user_mode save =3D 0 mov r2, sp @ regs pabt_helper UNWIND(.fnend ) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index ff1dd3169346..14b2495cae3c 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -109,8 +109,6 @@ ENTRY(ret_to_user_from_irq) movs r1, r1, lsl #16 bne slow_work_pending no_work_pending: - asm_trace_hardirqs_on save =3D 0 - asm_irqentry_exit_to_user_mode save =3D 0 =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK @@ -189,9 +187,6 @@ ENTRY(vector_swi) reload_current r10, ip zero_fp alignment_trap r10, ip, cr_alignment - asm_trace_hardirqs_on save=3D0 - enable_irq_notrace - asm_irqentry_enter_from_user_mode save =3D 0 =20 /* * Get the system call number. @@ -256,6 +251,19 @@ ENTRY(vector_swi) #else str scno, [tsk, #TI_ABI_SYSCALL] #endif + + /* + * Calling out to C to be careful to save and restore registers. + * This call could modify the syscall number. scno is r7 so we + * do not save and restore r7. + */ + mov r0, sp @ regs + mov r1, scno + push {r4 - r6, r8 - r10, lr} + bl syscall_enter_from_user_mode + pop {r4 - r6, r8 - r10, lr} + mov scno, r0 + mov r1, sp @ put regs into r1 stmdb sp!, {r4, r5} @ push fifth and sixth args mov r0, tbl diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 8b2e8ea66c13..1973947c7ad7 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -1,15 +1,29 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include + +long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) +{ + trace_hardirqs_on(); + local_irq_enable(); + /* This context tracking call has inverse naming */ + user_exit_callable(); + + /* This will optionally be modified later */ + return syscall; +} =20 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) { + trace_hardirqs_off(); /* This context tracking call has inverse naming */ user_exit_callable(); } =20 noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) { + trace_hardirqs_on(); /* This context tracking call has inverse naming */ user_enter_callable(); } --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 9F49920C480 for ; Tue, 29 Oct 2024 10:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199200; cv=none; b=WHjkFSMpHWVXryMLQzOW5Pfo0jd2JNRiZ6aSxuV2IpSK0Xad/ruxJtcNU49nd7SU6j6x4y41f7cP5IkhU0OJxqsbntNFaH6gqNzeIz0pwJ576jhJtv/Ljj+ibLBjUXESpN2GeMOn1F5yZ3q9498UQnaqpMzfb833/N4x//Nykaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199200; c=relaxed/simple; bh=CpGlIrf5p+st0iXrAuSSydMx9vVrjXfwmalBa4qqxa4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s0zf5NRkYhWMcZ0cwue1O7oUjE02XVfTkHVn8hxnkt3hG0sppgVV51As3pw68ky2tMI/q3w0Mz+7s8zasikU/7GTIdtDdxsdkr8mdrpPT1EU12j7+OrlgILwjpSyJbA5O+kzGzhOQsUaKZbqSwPVwT8IkDIDIn3T0jAFmMzZ5Cs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tJh/T5fp; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tJh/T5fp" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-53b13ea6b78so8221054e87.2 for ; Tue, 29 Oct 2024 03:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199196; x=1730803996; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JNSBA39L+uD3IEP0aKHjk6mvKlXPMhygyF+Shfug/O4=; b=tJh/T5fptuE+SnLjw8VWhMeQhcaBUMmRsK/CATJuFduPuztA7KNSsdT5ihMK991bCk ZwolIVKk6cnLIvWssSYi0lzmCxjGR+ZLFdouxvX0fTAs1RymTd+RoCISul0uTWRuBcNk EbmH+di7x5biQkFDp6SXOAh0VJMowp5nFk98QFHGU/+mu9IMq7mzg0gBIvpXyCv5UwnK MhiFV+ABEsxGHGKMO/105TGXN5cSOCEFa2vNsxmIPf3YfRuEn5HZuM42LJ9RPxHe0Vyy TOBSMk0U1d9KWIIatUV0XgFmTxiJlHzo6+0oX5AlwBqLt/YLFkk4OKSvztFLmQu3msQN XVMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199196; x=1730803996; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JNSBA39L+uD3IEP0aKHjk6mvKlXPMhygyF+Shfug/O4=; b=fqV0OXPPRb7BS3RiHlWwHYJmeZQdi7DHkU57ZWKf8lhCygADH0mz9sbetUwz1g5z8n gDHxk+8+6MQHUHtyQqnPBXh0mGnZCuveJXvtYmashwmzqeF2d46UdjAjXe45QWkEFiKF htM4jJ7gjMa8PxDY+nAg9G8RQJA8nSFYGwQ/wzqHGj3I8ttn6tIxpFfD8xlgCjA1rj2k 4b/xLRj31guxUs/I7x0Xe78vL6ZefAlp494d53WuQtuAqk/tXkgFsz2EGXZi5K9ZIlWv Od8VWZwygk/a8NmzSe5DWv24TIhhvU8ipWQxiaDqemn4phj8TJVD9N7QpwzwoNxFRxtx F0uA== X-Forwarded-Encrypted: i=1; AJvYcCVO5/xH3lqRnyn7OCY+35r/iTeSNfIb62AUM/1+hDwRLPswy0FCFXqKvrNx5qMoy823lmr+htgyURYXHT8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxdv3sy8QjXwHQRnVQ5gcFbKBoUEv42HkQTEhZwpe+joZC4MTQN quHroNgnVFSvJ8KCh6ChHTexpREx2uhbAH5Z8n2hUKgbuBXrGk2cs7/5D0P3vTI= X-Google-Smtp-Source: AGHT+IHwhUbueHKfzusT1MGnoFMhY8X4pCN3hYae0P/kspX02WumWJCSxZicZBMwsoQhFKVcgb73SQ== X-Received: by 2002:a05:6512:3c9f:b0:539:93b2:1380 with SMTP id 2adb3069b0e04-53b34921b15mr9499847e87.48.1730199195613; Tue, 29 Oct 2024 03:53:15 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:13 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:56 +0100 Subject: [PATCH RFC v2 16/28] ARM: entry: Drop argument to asm_irqentry macros Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-16-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 asm_irqentry_enter_from_user_mode and asm_irqentry_exit_to_user_mode have a "save" argument that will save and restore registers before the call to the C function. Now all invocations set this argument to 0 so drop the surplus code. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-armv.S | 8 ++++---- arch/arm/kernel/entry-common.S | 2 +- arch/arm/kernel/entry-header.S | 18 ++---------------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 0328860475e1..09ce1be1f677 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -421,7 +421,7 @@ ENDPROC(__fiq_abt) .align 5 __dabt_usr: usr_entry uaccess=3D0 - asm_irqentry_enter_from_user_mode save =3D 0 + asm_irqentry_enter_from_user_mode kuser_cmpxchg_check mov r2, sp dabt_helper @@ -432,7 +432,7 @@ ENDPROC(__dabt_usr) .align 5 __irq_usr: usr_entry - asm_irqentry_enter_from_user_mode save =3D 0 + asm_irqentry_enter_from_user_mode kuser_cmpxchg_check irq_handler from_user=3D1 get_thread_info tsk @@ -446,7 +446,7 @@ ENDPROC(__irq_usr) .align 5 __und_usr: usr_entry uaccess=3D0 - asm_irqentry_enter_from_user_mode save =3D 0 + asm_irqentry_enter_from_user_mode =20 @ IRQs must be enabled before attempting to read the instruction from @ user space since that could cause a page/translation fault if the @@ -471,7 +471,7 @@ ENDPROC(__und_usr) .align 5 __pabt_usr: usr_entry - asm_irqentry_enter_from_user_mode save =3D 0 + asm_irqentry_enter_from_user_mode mov r2, sp @ regs pabt_helper UNWIND(.fnend ) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 14b2495cae3c..df564388905e 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -109,7 +109,7 @@ ENTRY(ret_to_user_from_irq) movs r1, r1, lsl #16 bne slow_work_pending no_work_pending: - asm_irqentry_exit_to_user_mode save =3D 0 + asm_irqentry_exit_to_user_mode =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index fb5bb019199b..50c0b55adc74 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -365,28 +365,14 @@ ALT_UP_B(.L1_\@) * Context tracking and other mode transitions. Used to instrument transit= ions * between user and kernel mode. */ - .macro asm_irqentry_enter_from_user_mode, save =3D 1 - .if \save - stmdb sp!, {r0-r3, ip, lr} + .macro asm_irqentry_enter_from_user_mode mov r0, sp @ regs bl irqentry_enter_from_user_mode - ldmia sp!, {r0-r3, ip, lr} - .else - mov r0, sp @ regs - bl irqentry_enter_from_user_mode - .endif .endm =20 - .macro asm_irqentry_exit_to_user_mode, save =3D 1 - .if \save - stmdb sp!, {r0-r3, ip, lr} + .macro asm_irqentry_exit_to_user_mode mov r0, sp @ regs bl irqentry_exit_to_user_mode - ldmia sp!, {r0-r3, ip, lr} - .else - mov r0, sp @ regs - bl irqentry_exit_to_user_mode - .endif .endm =20 /* --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 425DA20C494 for ; Tue, 29 Oct 2024 10:53:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199202; cv=none; b=Vxq1memV8q35uPz24++yqGklcu9VKmkYWyFe6n6dv0kNA9uAnEpahWIFX8zbFYrpMIEpNmRk9B8N0XD68hCLBz0Z3byUl4OoJ4pso6T/u4mSE2xHTuWTEXRULrGEUh82hfBDy12eNNimJOOtDYXWwep0Fz6DhKL7T4yZ5EOiKO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199202; c=relaxed/simple; bh=xji/pcLoEPAUztYWn3ikVISlaHvrDnwTx4BX+5Les5s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LwdiUmwc/wRe4o/pO1phJKw421JlXyczMuSXqHLDOGV+X1RQJAqF9BWeLpjPh1yBcIWC8T0DYt9SEh9yLwFVI+4J+EdtjnqYTxF3WMCeUa0kijMsyETnhFf8eTKaLUROrvxk/L28GjxYMd4BCKp8qEkxBGeyJvv0rF2tY3XxmaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=obEJfyzH; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="obEJfyzH" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-539f0f9ee49so5633150e87.1 for ; Tue, 29 Oct 2024 03:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199197; x=1730803997; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=; b=obEJfyzHD/xjJtjhV4KFQ0QlMRl2/OO48Qy2dYBJC6fOy4fhKRnjtPhwrpY9IilZ8U cFTrbYVWzb5U9C8EEjGY16dOLyNkh+NGNC73dEbb7lUTOVrz2Sgkai6UaZtY3MzRQVKP 9cX+vfmm9x3iNlpckWrV3l/2kJD/7fjFaPOHBhCeoURKihuF9h9KSBtDOejfaBdVdVcc rGyhvjY5u+LBth8abxt97tBskem/NFTDxAriWhjgKLs5pth7lAIPRhBfoKpGRBEqLP8V HoBgaGuFMu3R3hCXy69Xx4qNfqUqM6XwrRDjF+gzh1Q0EJOjPDKus49PZBtO0RnC9K+l 0cnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199197; x=1730803997; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=; b=gMO+cuyPkp2m2HiNSO+Gh3v84RLCc8FSsBhiNKQBt4ZciwmpkdeDrGJatD6qho8UFw HoZokkYP3Z+4NzwoRE5WHMx7WUOKWkuDHKq0CHQ9siA6kgeb7AERadFgfhstMlm8x5Cz tieBR5f6vVD0CgmHhRo35qNNkP0te1Xfe4iZ1ouwXmg5jUky9jqlUD4jdI9pkqeMMAFf bsi6Ma00W+1oxusibXX5VYrRcs9fpGU7dnVFd2Basz9xYw8jGtEZHjVosK1QZsjjbYbz MgNBtA+pswSNVKJPhsx6o78kOME/jKc2ik7dzD+cGa89ZiaM3vQwF3CiQz5LL+iPcOXr m56A== X-Forwarded-Encrypted: i=1; AJvYcCUFcUe0Zw8E9iWFdSIHj0i7uDES5ZFXzaiFZQ+/2pcIe3ae7muW3qNP1qiLtltKa8sGWkc92s1faCCpKRU=@vger.kernel.org X-Gm-Message-State: AOJu0YyeKt1a1lJY5K75I1sx26qu50oiR5wms9i6c+l/fpuccd3BxsGM tLrCHcMotsqdzq/PeBn8rncExvBiaZdwYGk1mOgygyKpDBDEyeEyREtwChBOvocDR8B5OZym66s B X-Google-Smtp-Source: AGHT+IHwQ1phmvi3b9piBcu57BfZXRkpJE1sq4dj92irBFwN0Et4RdmdKsOnmQgjI8ng74r87rZoaQ== X-Received: by 2002:a05:6512:3091:b0:539:ea7a:7688 with SMTP id 2adb3069b0e04-53b348b9130mr4630936e87.1.1730199197317; Tue, 29 Oct 2024 03:53:17 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:16 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:57 +0100 Subject: [PATCH RFC v2 17/28] ARM: entry: Implement syscall_exit_to_user_mode() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-17-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 Mirroring syscall_enter_from_user_mode() we create the sibling call syscall_exit_to_user_mode() and start to move some stuff over from assembly, first the rseq call and the interrupt disablement. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 1 + arch/arm/include/asm/signal.h | 1 - arch/arm/kernel/entry-common.S | 10 ++-------- arch/arm/kernel/entry.c | 8 ++++++++ arch/arm/kernel/signal.c | 7 ------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h index e259b074caef..8b8cc9a1eefb 100644 --- a/arch/arm/include/asm/entry.h +++ b/arch/arm/include/asm/entry.h @@ -9,6 +9,7 @@ struct pt_regs; * to generic entry once they are semantically equivalent. */ long syscall_enter_from_user_mode(struct pt_regs *regs, long); +void syscall_exit_to_user_mode(struct pt_regs *regs); void irqentry_enter_from_user_mode(struct pt_regs *regs); void irqentry_exit_to_user_mode(struct pt_regs *regs); =20 diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h index 7acccc96840c..bb753cd3e29f 100644 --- a/arch/arm/include/asm/signal.h +++ b/arch/arm/include/asm/signal.h @@ -23,7 +23,6 @@ typedef struct { =20 #include =20 -void do_rseq_syscall(struct pt_regs *regs); void do_work_pending(struct pt_regs *regs, unsigned int thread_flags); =20 #endif diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index df564388905e..3559e0a9f5e0 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -65,12 +65,9 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) add sp, sp, #(S_R0 + S_OFF) -#if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ mov r0, sp @ 'regs' - bl do_rseq_syscall -#endif - disable_irq_notrace @ disable interrupts + bl syscall_exit_to_user_mode ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing movs r1, r1, lsl #16 beq no_work_pending @@ -97,13 +94,10 @@ ENDPROC(ret_fast_syscall) * do_work_pending() will update this state if necessary. */ ENTRY(ret_to_user) -#if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ enable_irq_notrace @ enable interrupts mov r0, sp @ 'regs' - bl do_rseq_syscall -#endif - disable_irq_notrace @ disable interrupts + bl syscall_exit_to_user_mode ENTRY(ret_to_user_from_irq) ldr r1, [tsk, #TI_FLAGS] movs r1, r1, lsl #16 diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 1973947c7ad7..472338047337 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include +#include =20 long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) { @@ -14,6 +16,12 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, = long syscall) return syscall; } =20 +void syscall_exit_to_user_mode(struct pt_regs *regs) +{ + rseq_syscall(regs); + local_irq_disable(); +} + noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) { trace_hardirqs_off(); diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 7b1a16e86b23..03b20637a2e1 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -659,13 +659,6 @@ struct page *get_signal_page(void) return page; } =20 -#ifdef CONFIG_DEBUG_RSEQ -asmlinkage void do_rseq_syscall(struct pt_regs *regs) -{ - rseq_syscall(regs); -} -#endif - /* * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as * changes likely come with new fields that should be added below. --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 71D6A20CCC3 for ; Tue, 29 Oct 2024 10:53:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199203; cv=none; b=M7wQ13XiBWeVsaJ3gCaYrV724u2sdRqslK6A1W1Qve3ZZ6B74+PTvcnPfeR4T+W2bVG7+pFDe8XcVGR4XdT7h5LO+ib55My23Xm4LP4vhaKsGJdHCOsJJF1xLCQV6/zXrBmegCZ+66tuyscF36ndlqhOz0kVtfzae/y3VLSiQcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199203; c=relaxed/simple; bh=gNYk/dXXFiwzPEzltOa8cVyir3PP8qKub1uE6+vi5oc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oXkS3WAM/nOSgn/5zwwFZYpFUEPR3npUy2VxEHMf0calqeJaivuKGYmRcjvrKi9PrinH6iZecgtpgVzTnzaxx12VZoUoaZPdzXBu689uh3Q7+B6Ho8zyt0Zw9vamXPNhW/1FS4LIl+LcT+H9I+kVmaf0fLFhqbrtF1YJsOqtO+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=vlvyoGdT; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vlvyoGdT" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-53b1fbb8be5so5153948e87.1 for ; Tue, 29 Oct 2024 03:53:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199200; x=1730804000; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KWToKPY4NC+RvNbtP48N7l0nt4O+1hLmMWZz8WN9xgg=; b=vlvyoGdT/6inWjBvopQ40FtIfrioAMh2T0Cv3uxRratNMTaQMbQh4o1WOhKIHQk+6A beYVjOJVrDsedriQI1C8Xl+7SPlwVf0v0OZAKIcBTnAFjU7EXsDUhHJTUo8u5K02V5PL O+Kax4bPFmsE1g1OW1k89q6PHIaPZvsaWQDWRCU0OMBpH+3W0CE7PwOc1YVivVN5uzL6 5/56GJAsmuILLvfCYvfz9i3MQ+QFRVdz6CjfyXhTCDt3QCv4kUKIo/d2vwhf0JVMyGqP cxlkX5vTQvParV0j8J86QUPj4IlbF4JW3p+8cbf/z7W6m8CY4cBs122Xqq32TrMr3B1p uqvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199200; x=1730804000; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KWToKPY4NC+RvNbtP48N7l0nt4O+1hLmMWZz8WN9xgg=; b=QgNgRVX6pRR8Jpjt1wc0Zkg198Pe4r42eHbEj2TB5tL22MYvCUmf2t0uqQK5tEPikA lInC9xuJq0Zp++g31t6YyFvDtAA+RDTU2tx7vYgXVTapT+PuDP2Z6MCLys3gULylIWDR 7kEd0y7gFq5yYy/zPhXHx3rKzl0C3SubqZNPasBub+3ZtpES98pZplACbBBIq09+6BQh OeIR3yw/ijPZSAx4szp6WSXPPW7xHE12a5TFxQFGJce52GIn85xm853vgX++HePwjJO7 gx3LfHGb4GCJGmnIG6fesSHiYKgbbuRq/RaVXEZIbC4cqL3BTgddON+oQQlzkHyCAfT5 JQTQ== X-Forwarded-Encrypted: i=1; AJvYcCWKt5mozd8bL8hKNZDobHkT7GYdsVqmRbX5C4cVdayv/O84qwQxLvw2mjXnFk5hMWnxs5DmalLrz9msSo4=@vger.kernel.org X-Gm-Message-State: AOJu0YxISYzcS5+zpjBIc4yDC6NlxMmUV+W3K1Ami90hbJt/yGuofNAV +npb/0qNW31uNqYRfAEVLZBj+ZAPhKcG1Ix/Ylv7bJ5IEDKLkUHz/+9TqtJRcF0= X-Google-Smtp-Source: AGHT+IGGG5g/5+zGZjyROy/Yc3vo9dh2CvJXvwozTq1krbIQXNKWoJVtmLAen7EpI2bSFn7YNTEMaA== X-Received: by 2002:a05:6512:6ce:b0:539:8ee8:749e with SMTP id 2adb3069b0e04-53b491f773dmr589492e87.3.1730199199721; Tue, 29 Oct 2024 03:53:19 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:17 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:58 +0100 Subject: [PATCH RFC v2 18/28] ARM: entry: Drop the superfast ret_fast_syscall Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-18-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 When not using any irqflags tracing, context tracking or rseq debugging, the ARM kernel uses a "superfast" ret_fast_syscall with a very few assembly instructions. With generic entry, such local optimizations are not really possible, we need to call C unconditionally and take the (hopefully small) overhead. With generic entry in C, most of the tracing (etc) calls are replaced by stubs and optimized out by the compiler. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 3559e0a9f5e0..dddbd6ba1eb9 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -30,34 +30,8 @@ saved_pc .req lr =20 .section .entry.text,"ax",%progbits .align 5 -#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACK= ING_USER) || \ - IS_ENABLED(CONFIG_DEBUG_RSEQ)) /* - * This is the fast syscall return path. We do as little as possible here, - * such as avoiding writing r0 to the stack. We only use this path if we - * have tracing, context tracking and rseq debug disabled - the overheads - * from those features make this path too inefficient. - */ -ret_fast_syscall: - UNWIND(.fnstart ) - UNWIND(.cantunwind ) - disable_irq_notrace @ disable interrupts - ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing - movs r1, r1, lsl #16 - bne fast_work_pending - - restore_user_regs fast =3D 0, offset =3D S_OFF - UNWIND(.fnend ) -ENDPROC(ret_fast_syscall) - - /* Ok, we need to do extra processing, enter the slow path. */ -fast_work_pending: - add sp, sp, #(S_R0 + S_OFF) - /* fall through to work_pending */ -#else -/* - * The "replacement" ret_fast_syscall for when tracing, context tracking, - * or rseq debug is enabled. As we will need to call out to some C functi= ons, + * As we will need to call out to some C functions, * we save r0 first to avoid needing to save registers around each C funct= ion * call. */ @@ -75,7 +49,6 @@ ret_fast_syscall: ENDPROC(ret_fast_syscall) =20 /* Slower path - fall through to work_pending */ -#endif =20 tst r1, #_TIF_SYSCALL_WORK beq slow_work_pending --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 3BD6B20CCDA for ; Tue, 29 Oct 2024 10:53:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199205; cv=none; b=Ys1t7VQMTN2jQ+eKedbKp2ESnfda0ga8wFCP9NK2d4oFkVOybWYY/Vk2ypcq50uUn6kvjhD0XWfHsFNcQyXfpGSu2dMT1hf4p5J8/6JGqipDTiEXc0tjSxhaw1ujhF46gyiLG0LImvnAo5k0fPGu/4vwHQikb3akuJdv6Ii+Zes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199205; c=relaxed/simple; bh=Qsa08BehM4uts93sI8Y9iubQvhsHZG2Sg6J31UXi3tM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iuN8x5dQfbHdk0X5fKo/Zn1CMkfC9s2LRXNSFW2MFaNXfqm4jHHmn+EKychZXLsn5uaxgNpcovv65+YWaQxUIgFMvQut7t+DBM/OW/fLhVcgn+zPoK1Y16ORUm4UEZhhRy1A9Vdfe+/q0W4AKtF3sLQJUoEIv4po1fcGCNZX3Jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=LdAnZ/uR; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LdAnZ/uR" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53a007743e7so6044161e87.1 for ; Tue, 29 Oct 2024 03:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199201; x=1730804001; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4s7yTStZNPQghs61B8MN+wTLfopUv2dudvbP9oK+hzk=; b=LdAnZ/uRdG6AeFaYmfuh/wWVAnVWuypsHdezhqvMnoTyUtBHTvYrwPq7rH8liZARgF RisMpxmjJB/RFMz1LQ2ES/Wl8qgFvdvkEaZW6i3OHlEwBfj0b4k8idY9HoUukxeFul6L ENmFmo4WBtDAwr0XrIHs6Von1u68yt07Wt0H/FKNNfWxyGuJU2440MiTgCFckYTf3Zsx iF+1L8vC6vwDHholhmu2XuBf7zlTBYjHmqKpdx1rsOyasws5lRJPmANEa3Izy5ed4YVP f9Ktpkh+ItjSPmE20d0aXdfU4efc0fCaN0xnsnXgzAvZonesXswuwVo5VK4AhM3NY/Ti WFpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199201; x=1730804001; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4s7yTStZNPQghs61B8MN+wTLfopUv2dudvbP9oK+hzk=; b=pCztKOJqVEzPFLTgtDs5EudAVqOBOfQ9VDD17zTow2us8j/xjQ5luFpGT8jSxJGx2f eCJNqWqzamYxVHXq5xp5HLDONrON4vVFl5SOA5786RFxHZ+DsrJS9ngW1LdgWIuhNvXn lhBJztLpfjiMSfvQiDQ9NnivWQEcqE3GnbP3/Zv18wBrGNzmSOsuWkuc46KiCx4+7Jlb XYDvRIp+V/QhdA687FNsiUjEUVbpvQVIULrHU2ANhfuNrbe6yahrg8LMDJbzOuaVXN9J 3TmeVQipFDhEL7TahOC92OFEEFRLfby4+QmnW3MPeUx+kCPwZ/VTS7RQnFm5BlD/AaPh Jd+A== X-Forwarded-Encrypted: i=1; AJvYcCXVxgvqP2GZnZHEUipdpKfskMqKeAtco4J7TawzRy6VB1pIMHmgNaUv1nzkXPy6AP2f1qbLKL5CTga/yxU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8l+ejLD/hPfSPviaOOjDHMMUBiBM8z7kC1x+RUzlSirDg6FAG HTWA124+Xtq8epATrUWXDWDIXgOtKF6IHqiv2/w9l66CAgaQobkM0rAdbqXbtCo= X-Google-Smtp-Source: AGHT+IElXNTIUEjBzs2hSzfFmPti763QWvOuxnOHRmGwE5++Rd45XLgtaXunwBM8zueTxRgHduPWMA== X-Received: by 2002:a05:6512:104a:b0:539:f4ab:5638 with SMTP id 2adb3069b0e04-53b34c466d0mr4122591e87.60.1730199201347; Tue, 29 Oct 2024 03:53:21 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:20 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:59 +0100 Subject: [PATCH RFC v2 19/28] ARM: entry: Remove fast and offset register restore Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-19-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 Now all remaining invocations of restore_user_regs has fast =3D 0 and offset =3D 0 set, so drop these parameters to the macro. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-armv.S | 2 +- arch/arm/kernel/entry-common.S | 2 +- arch/arm/kernel/entry-header.S | 29 +++++++++-------------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 09ce1be1f677..bd468d58dc02 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -496,7 +496,7 @@ __fiq_usr: mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi get_thread_info tsk - restore_user_regs fast =3D 0, offset =3D 0 + restore_user_regs UNWIND(.fnend ) ENDPROC(__fiq_usr) =20 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index dddbd6ba1eb9..d27e34d7e97a 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -81,7 +81,7 @@ no_work_pending: #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack #endif - restore_user_regs fast =3D 0, offset =3D 0 + restore_user_regs ENDPROC(ret_to_user_from_irq) ENDPROC(ret_to_user) =20 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 50c0b55adc74..51c7f93c1ded 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -290,7 +290,7 @@ .endm =20 =20 - .macro restore_user_regs, fast =3D 0, offset =3D 0 + .macro restore_user_regs #if defined(CONFIG_CPU_32v6K) && \ (!defined(CONFIG_CPU_V6) || defined(CONFIG_SMP)) #ifdef CONFIG_CPU_V6 @@ -309,8 +309,8 @@ ALT_UP_B(.L1_\@) #ifndef CONFIG_THUMB2_KERNEL @ ARM mode restore mov r2, sp - ldr r1, [r2, #\offset + S_PSR] @ get calling cpsr - ldr lr, [r2, #\offset + S_PC]! @ get pc + ldr r1, [r2, S_PSR] @ get calling cpsr + ldr lr, [r2, S_PC]! @ get pc tst r1, #PSR_I_BIT | 0x0f bne 1f msr spsr_cxsf, r1 @ save in spsr_svc @@ -318,31 +318,24 @@ ALT_UP_B(.L1_\@) @ We must avoid clrex due to Cortex-A15 erratum #830321 strex r1, r2, [r2] @ clear the exclusive monitor #endif - .if \fast - ldmdb r2, {r1 - lr}^ @ get calling r1 - lr - .else ldmdb r2, {r0 - lr}^ @ get calling r0 - lr - .endif mov r0, r0 @ ARMv5T and earlier require a nop @ after ldm {}^ - add sp, sp, #\offset + PT_REGS_SIZE + add sp, sp, #PT_REGS_SIZE movs pc, lr @ return & move spsr_svc into cpsr 1: bug "Returning to usermode but unexpected PSR bits set?", \@ #elif defined(CONFIG_CPU_V7M) @ V7M restore. @ Note that we don't need to do clrex here as clearing the local @ monitor is part of the exception entry and exit sequence. - .if \offset - add sp, #\offset - .endif - v7m_exception_slow_exit ret_r0 =3D \fast + v7m_exception_slow_exit ret_r0 =3D 0 #else @ Thumb mode restore mov r2, sp - load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr - ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr - ldr lr, [sp, #\offset + S_PC] @ get pc - add sp, sp, #\offset + S_SP + load_user_sp_lr r2, r3, S_SP @ calling sp, lr + ldr r1, [sp, S_PSR] @ get calling cpsr + ldr lr, [sp, S_PC] @ get pc + add sp, sp, S_SP tst r1, #PSR_I_BIT | 0x0f bne 1f msr spsr_cxsf, r1 @ save in spsr_svc @@ -350,11 +343,7 @@ ALT_UP_B(.L1_\@) @ We must avoid clrex due to Cortex-A15 erratum #830321 strex r1, r2, [sp] @ clear the exclusive monitor =20 - .if \fast - ldmdb sp, {r1 - r12} @ get calling r1 - r12 - .else ldmdb sp, {r0 - r12} @ get calling r0 - r12 - .endif add sp, sp, #PT_REGS_SIZE - S_SP movs pc, lr @ return & move spsr_svc into cpsr 1: bug "Returning to usermode but unexpected PSR bits set?", \@ --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 D9E7F208990 for ; Tue, 29 Oct 2024 10:53:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199206; cv=none; b=BLHh2aI05Y6UH6sm99iqfUaNuit7ao6V92Tu9GN+n53PNu1xSFXmPHohXBBVwTRGnHJqp1fn+KUTnM8xlt/tI8oXMEGkz2fCyCHPSJWC1iseqwV4lLywoHxfAFPoSfWS2Hc0vl1Us7+1amUTBNr65ploPTOQnB/SJmiLnoiISoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199206; c=relaxed/simple; bh=U7+/gc2e2KuWRZx3ryccMQNU5ZCqQa+rXx8yeFy3Nh8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NjRCI0kWhaG3bHX3CS04ibwwv6NV6qznBHNUIg8QledDbEI7Dzr1HJrzG0e3Zu6Fw/jH/N4y4b9hNClQ4gT0ZAeXnq0NrGGCENX+uwesj0hqlgNU/1yL4DCPdicG44MFlgz9YorAEYvih5aC/lsZeE2kTtnsvJT0g0qrjxasLtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=wqeYGmZh; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wqeYGmZh" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-539f0f9ee49so5633242e87.1 for ; Tue, 29 Oct 2024 03:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199203; x=1730804003; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hWWOf9VRKfs2/tqyRJcdO75r8/gLb8BcoV6DE9Ay3YY=; b=wqeYGmZhkBmx+JKiBU/6fwO2+uOEUnY1Wglfg860BHfqB4FAB+FTdrvr7mVLdA9mFM kKQtTBF3kj35Sd31qLKKpfDGm2FRBTTdG0bAUvPLo9n3+3U6NnnS447NKOhAmuODb3qR xHNKd4WS1aicOLm16LEl4viXxHTddIgPGjsP9WphwHtHYKAizldAi8j9xRtxLkcD6OT9 oDFJpgpADLytklgN04/oRtwhSeGQHtPnKRkfnXzqtIXQPVWQlaf2fpdJ4uZmoR+ld/fE YGL+gLOsePMX2MKnEJ4klFVOmCg8QZzVNb2Gf6Cgv94yIVfjhXLsI0adaOW88tVCOUkl 0xog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199203; x=1730804003; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hWWOf9VRKfs2/tqyRJcdO75r8/gLb8BcoV6DE9Ay3YY=; b=kGZzKUFOlqto9hqwrxUeNdDnqLHrLVAv5yJaTzNm4w+Db8lNBfT97Ss7mKqW3bhSFG 8ebvr3EWW9kdAhF66sCCVezn4zz1v07+Gmf2xRoOWosOybFmzKxRB19wouUJNYQi+pzp VAdomGYqUWX8f4oHpNVchrSEX89ErMd3vwqD3o++j6HaAQQVJVP1fdQTCRnzMkoaMjso osvZFRr1HzJnse71e9uOz+K/d9nAru6uCYkzwc3rbzjNhj+6oQ1DfjucwwWfYUImUAIn mZCXdBwUm9ZQfEXf0oLXMA08e3BcwFqhKcxwQhfv4tKJWciiNSssdCFAFR4ZxgrRL/7e AsqQ== X-Forwarded-Encrypted: i=1; AJvYcCWq26kbOcC+IjkzdQSUPdFNd9o1YBzJHvwzxlgAorzk/YMQYnHlSlFqvw/qdB0bhH86YoTmNzLWpCoGDac=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7eeICny75YQj0YKAwRHESIcDVPjz/oZBn6ZDUpd6LMtgzglqb B6BZghJ5xY/Povu/qZ05lnZc1rNvoqnmntG7HXiK71LwDELuKbXOqJdj6E+5RPA= X-Google-Smtp-Source: AGHT+IGYokcfvTEQUjshtOgXGdmRS2U3eH+gIN/8bmikMfR0LXUeM0vzogR0GFUwOUcsWs1HgXxhYQ== X-Received: by 2002:a05:6512:3084:b0:539:fed8:321 with SMTP id 2adb3069b0e04-53b34a31cdbmr4939668e87.51.1730199202995; Tue, 29 Oct 2024 03:53:22 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:21 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:00 +0100 Subject: [PATCH RFC v2 20/28] ARM: entry: Untangle ret_fast_syscall/to_user Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-20-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The return to userspace is a bit hard to follow. To prepare the ground for further refactorings we rewrite the functions to ret_fast_syscall and ret_to_user are mostly stand-alone symbols. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index d27e34d7e97a..ece921571714 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -44,20 +44,23 @@ ret_fast_syscall: bl syscall_exit_to_user_mode ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing movs r1, r1, lsl #16 - beq no_work_pending - UNWIND(.fnend ) -ENDPROC(ret_fast_syscall) - - /* Slower path - fall through to work_pending */ + beq 2f =20 tst r1, #_TIF_SYSCALL_WORK - beq slow_work_pending + beq 1f + b ret_to_user =20 -slow_work_pending: - mov r0, sp @ 'regs' +1: mov r0, sp @ 'regs' bl do_work_pending - b no_work_pending + +2: asm_irqentry_exit_to_user_mode + +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK + bl stackleak_erase_on_task_stack +#endif + restore_user_regs + UNWIND(.fnend ) ENDPROC(ret_fast_syscall) =20 /* @@ -74,7 +77,9 @@ ENTRY(ret_to_user) ENTRY(ret_to_user_from_irq) ldr r1, [tsk, #TI_FLAGS] movs r1, r1, lsl #16 - bne slow_work_pending + beq no_work_pending + mov r0, sp @ 'regs' + bl do_work_pending no_work_pending: asm_irqentry_exit_to_user_mode =20 --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 77F7820D51C for ; Tue, 29 Oct 2024 10:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199208; cv=none; b=noW1eXVIGreO6ZFgwXBvpCvq4Fe6fMuBZukzBlq1+uG7FiDfmiKVntYaUTpOCqIl6Ngt8R6RXlBf0peXBDzPu3KgvWgW+KX29LwBl3NDZm9umEbCg15ZL8P9X1FfC7R/0Xv4bzIT26N9rUx+T6CGonGGlExRtCrnE/g2uT5hJY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199208; c=relaxed/simple; bh=6+lTQ2GqQK5nFNzuJ9HvRyHeFh0UjePZM0yliybbYSY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VKFXIGk1QqNWmdsSIcjNPmayQJbeoVvAc1Wns1SzJB+NoT3B0BxcxOwxGL7q+9tu60eSeBFGwkq+XzM0B20dohrCFpw9Cw+IuXJDDsVXzilogdgugltf7BKzkucL2bRBg0QQxdvR5fMbAwIkVq26ajL/mNevnuJOxeNBlN82BRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=uEr0Y7ZY; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uEr0Y7ZY" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-539f72c8fc1so6476624e87.1 for ; Tue, 29 Oct 2024 03:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199205; x=1730804005; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=P2OP9NgXP8OYjhdkePmH5sP15xkO/BVCD1VA0/cLgTg=; b=uEr0Y7ZYx++2nx7ghfIc5Jy34ioHDvN8MgutKVdej149ITq4+eA4jY/MQbJtxyufsm JniBR/FqAsOF1zrs3t7/tE3ztegMip37aa9i7PbKvBVxwTS26tD2a+UpytPyrolqWLTs zvPmkAOkE1UzTbWJOvKFdKGSVlVHmzBKnzw1v+rcmLmOmctkQNqmEojxfNmBZ3DFiUCt 2rgTPP9Fmkf0oTYtfPFjbDSr29bg7TSPpvUiJzkqmCJTys9p7kXj1Fsb0/EOGUch+dm+ oHa1FLSPVoq9u39jSAe90o+HZ6UjQ+fMpbspUPFhSLCygrTYLAzVo2IKwDK2EqKGfFnX 6edA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199205; x=1730804005; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P2OP9NgXP8OYjhdkePmH5sP15xkO/BVCD1VA0/cLgTg=; b=ZQlVwW+U6xPdRYGoKj+3EZfBByJGu4kU0/rS0zLwjSBecScPrxx+WtXBkL/p+yCobY 3yKdTqZpTbJKSTHjl0Z4Gwgqpverx0ImryM99rAegz3zyI/chujPudeKVw09HWO95pgq gV4RUOnDdWpDIiw6n4MvGULjwNMDU5nL2WIVE8TobTsz+CXStEHRFFRM0jnGbgjagVTp i37Ja0I3h7mFoOw9ees1LOzLH30WL6bug0M7m3cWVyV4+hBHc6vNoCkDI95vFZqKWk16 5bVjHWNTPoQ4fHY6NyrOvO0WzHlZWxLe/H9Y3oqevC6+yqSXjBZn203iBbfR3KlKXFi6 BMPA== X-Forwarded-Encrypted: i=1; AJvYcCXl2l15jLvpVjPOWiL8x18XRVygypbmAvs/96uGxQdM4nHcNP+iiwIEi3qOasp1f/NLUfM8z1x7Pqoc7SU=@vger.kernel.org X-Gm-Message-State: AOJu0YzZ+sXGd8IdS2hEir+PTDDPYoHKdq6B2V06e2XewliTCdW9rXk3 zg77A0MHNxSUZ6PZmqEGYh/k0k1WvP7lY4D8+K2IwDFn/mwexX5bOWIfhNTZIjg= X-Google-Smtp-Source: AGHT+IFllmxwh7EKDe/a3WvQfs+EHBA3khsZLhUnL3Z+I/JP6m6A/TkF2H92CKvNJpKEWjTk3WNgUA== X-Received: by 2002:a05:6512:4022:b0:539:fbfd:fc74 with SMTP id 2adb3069b0e04-53b3491cccdmr5480123e87.40.1730199204557; Tue, 29 Oct 2024 03:53:24 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:23 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:01 +0100 Subject: [PATCH RFC v2 21/28] ARM: entry: Do not double-call exit functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-21-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 This is a semantic change to ret_fast_syscall: if there is no work pending the function used to jump to ret_to_user, instead we proceed to return from the syscall. If we jump to ret_to_user, IRQs are enabled and we call syscall_exit_to_user_mode a second time; at this point a this just means a second call to rseq_syscall(), but it seems wrong and we want syscall_exit_to_user_mode to be called exactly once. Apparently the ARM kernel has under some circumstances called rseq_syscall() twice on the exit to userspace without side effects. ret_to_user also checks for pending work a second time under ret_to_user_from_irq, but this isn't even needed any more on the fast return path: this was needed because the syscall invocation enabled interrupts when doing syscall tracing, and all tracing invocation has been moved over to C in earlier patches. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index ece921571714..33bc9e7c5b32 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -49,7 +49,7 @@ ret_fast_syscall: tst r1, #_TIF_SYSCALL_WORK beq 1f =20 - b ret_to_user + b 2f =20 1: mov r0, sp @ 'regs' bl do_work_pending --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 2E61120E014 for ; Tue, 29 Oct 2024 10:53:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199210; cv=none; b=Yk9FYuK4TtgsQ55XW9e6XP6d5TgugOtYzbKkJFCNLMlJpF0z5Ni5GVNIIv1Lj6ikBNmMsxwAgkG6+6TOcqLMjD+7cWFu/q8LMFpfn0rlGiLo86DlDst39zs4/JLv8jm3+fKnuSSZ3wnTeQm3SSOAk2jbD8KKmw87UECKTGa6Rxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199210; c=relaxed/simple; bh=oB6HP3SopbCX1pJb2/iEaIAmUOMLymz+4GahfTzk35I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FRk9WqZW4kTG45/y+pmmKKus+RuElQKO7n3L94lfJH3XpJrDXyr20u6MkEnB8kLXvyiZ+3bakXgWMzbUla+WGFRK2mSb8rUXu8dVXS1KQ9u62GGSQng/h7q44jLCemLrDZahxnJDiOPqDg4Th3PiBzv7RNzR/Tm+0nhqv7/d9Po= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=FcAYGfJP; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FcAYGfJP" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-539fb49c64aso8788780e87.0 for ; Tue, 29 Oct 2024 03:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199206; x=1730804006; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Gi2KcUYCbZkPlsUdwrNEo9QLrpmnXM+YJIWNYO7+o8Y=; b=FcAYGfJPUM/gV2aR//C+h5LPdiRvm4sXYCKjpr3mn/EJ6n2jpeR/+07Ll7w49Gv41s QxuvySA05TTBKC0stEjm4BqLNFUgZGFW0Y0MwQjczAQOtrUQO/rta1iUKHeOgU5XG1uq XL7IQdriZc723SeltD8c39bTEcnyZUzDjAh6LsGWSvstw7R1RJAsXAkvZRPhAZ/xtAsc ILGXTByCCXzwtTlRXpny+jvwFtvOE4LYoVkSoZeo7sSTGBEJZpQAsjhmIVoKdm1wXECz gt0uecEQqMukMwqY7Twtz7I5SWvfVvBDIOkc1QeN684no3ahGqeqRPmPT9RWoKKmObrW cyzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199206; x=1730804006; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gi2KcUYCbZkPlsUdwrNEo9QLrpmnXM+YJIWNYO7+o8Y=; b=Ir2gN69gjKTdZh95dDTQ//IU9V5TiMwQpQMxVdcc9UDdXJI9Hk2/APF3MOdfiQKfEF QXkrFa3pxciest+h0zY1hNJ+XFDmxg/99mfkuWlW238Jy6PfeS6ASn2Kylqs2Rxnlgh5 Wayczyz8SYFmuQRGHLn9FOU6zpRGkGaYZacPYsLv+etcfgMO/5JEF2zOvmEMgAaKqtfY U81AjRGTifgjBxsr3NEvOkijNTky7kd8PQzR8GWdlfsiyRTvACU0gYFHn8w6aFRvbFsA VJNx9CXFqyO3zXH62WXAVnGHy8wgSe6H9l/qOf07flPgrEUWY7RPIx/Z1OXP60UpWBuW DIRQ== X-Forwarded-Encrypted: i=1; AJvYcCXalIPVQq5YMEWY1oftRy/eO7kX51aZRrxgKiji1CX1a+2jfoEUjJAscRz9MfkjV3EuUWjQHGC5+3ts8nQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxtSyS9Uu8GcNNX0IGYFz76KIbYVKYWCowrTIRTYn/LNgRWRwEu gq1nXID9k2w+AP3FpObs/5uJwmzwFver2XJBwOWXc/ID1cL0vn+hp0xsL2HTmOg= X-Google-Smtp-Source: AGHT+IFLoqBuIKnwUObAl1tJTS1Bn4dPHs461dC4/LHdcT9FwMkp5b3gbbvcN/LNXtk6xKOfbTGsmQ== X-Received: by 2002:a05:6512:3c9f:b0:539:93b2:1380 with SMTP id 2adb3069b0e04-53b34921b15mr9500411e87.48.1730199206270; Tue, 29 Oct 2024 03:53:26 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:25 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:02 +0100 Subject: [PATCH RFC v2 22/28] ARM: entry: Move work processing to C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-22-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 At the end of a syscall software interrupt and every time we exit an interrupt handler we check if there is work to do, i.e. if the current thread (userspace or kernel daemon) has set the _TIF_SYSCALL_WORK flag. Move this processing over to the C entry code. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 14 +------------- arch/arm/kernel/entry.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 33bc9e7c5b32..5385574c4339 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -42,19 +42,7 @@ ret_fast_syscall: /* do_rseq_syscall needs interrupts enabled. */ mov r0, sp @ 'regs' bl syscall_exit_to_user_mode - ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing - movs r1, r1, lsl #16 - beq 2f - - tst r1, #_TIF_SYSCALL_WORK - beq 1f - - b 2f - -1: mov r0, sp @ 'regs' - bl do_work_pending - -2: asm_irqentry_exit_to_user_mode + asm_irqentry_exit_to_user_mode =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 472338047337..0e3960844b94 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -1,10 +1,16 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include #include =20 +static inline bool has_syscall_work(unsigned long flags) +{ + return unlikely(flags & _TIF_SYSCALL_WORK); +} + long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) { trace_hardirqs_on(); @@ -18,8 +24,12 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, = long syscall) =20 void syscall_exit_to_user_mode(struct pt_regs *regs) { + unsigned long flags =3D read_thread_flags(); + rseq_syscall(regs); local_irq_disable(); + if (has_syscall_work(flags)) + do_work_pending(regs, flags); } =20 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.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 BEC4320E034 for ; Tue, 29 Oct 2024 10:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199211; cv=none; b=EWCU2weDenwWAlZHKyuUQA62CPTSxAS8m8r/+5srRYb4AQSOu91FpqqfDoaGlp743GH1ek89SAey+2dUQMOoONQvyXgy4xjAmmgA1R7vrmTL2elxPeg+rV8u9H4QpKa7cNIg43RxfhnHAjjE122OAs7wt9yZooKo3ovg+gEEAXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199211; c=relaxed/simple; bh=iM/dQm4bBW4OzU1EedLHO9rK90B09M3TWGeyZRpr9ek=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pun/Dkc++ICSh4MtYHPnv32zojkOqI6fxndotDwsXGwT9ytNmX4u2t0e/xBu98MSKYQTc/95bcJM1U5U9mAB5XZHkTUcB9+R/in5PfxvkPExoT05RdaIiXR5x88KVv3YXlay+mHTN0I4nM55x4p2SeFouu4zhzgMZL6yyw2R9ys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=JIUmOhCx; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JIUmOhCx" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2fb5be4381dso50274271fa.2 for ; Tue, 29 Oct 2024 03:53:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199208; x=1730804008; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bckn3YFGIgJxyi6JuzR+D6XCfS8U3/QVQiTYkjNWbHI=; b=JIUmOhCxMREd1l7USzFDF3OSwQcTCbdIZtbXyk2YrFzA/Sy4UetepD8hHQgZP5i+sd UjHn7G8GA+h5456t1l9H2Z95eYgytOTOjLnV6qfoIbDVHDBX2zIHVvO5uy3QK3jFubJG DjJ1EBolHoKYm+wgBjgvJOVs3WlIY8QYorX7Tx2LWClCXzJJYC0lntbzo44TlgNHZyJa I4MUEzxgYACgG9Yjx9fvMnQnCxh+hl67TEEWsjf4ld1CDvBgo5+UZuwfreFdwOBYWMbn KkbpDcm82v3HAQYsrMMAgf4hfFh/Wvo9EbIQ0b+duDnv8wjT0FSWKwgVSj7AwhgwwJfQ qs9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199208; x=1730804008; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bckn3YFGIgJxyi6JuzR+D6XCfS8U3/QVQiTYkjNWbHI=; b=mo//dJ6xj+JHlxvq5m3j0IdpCoYZDYMt4PDPv7AGHxMCZruF7lHNfDnneWnRyNj58O V+C9tP5qPGbwRi5Y3aY89fsrHLQI9suZyjGwbNIsPXI8pRLlrwSShcXq1VT6TOlRwIJz AHa8TGMvPyYWzaWU66Z26VSsENPuy7y13UKtKFtg3+2YfX1PqOrIY8TmRyf6biWOZmmR 9yCm5coAyAQEUHHvNFRNyZO7UjhMGG90FB2+ZtvJpsckHdRmBDnZScyEIhON4ZgumJIb mS1EMPr77W0GxcrsiCF3ykc0Zq5HmIHR7YUi0ZjshM/jZ0CF4xoZ9HPPuf4ybfTups64 ukLA== X-Forwarded-Encrypted: i=1; AJvYcCXtYsWRuwZj2Z5zmZY9IyvIHER9jNnNnUOoWenN+X7yZ28uqt2h2cnL50bxvHKkiBkwEzVNCtGXCVkdkOc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxn0q3GOsBui4FQ9xIeV7t8qz2uSAmOXpcCoa61kOGsyMRdz+eE +TzvQx6QDkvP1/Q6XpcTmcV812I5uQZAc428b9Ayx6m73QV4HoIf2iDl0P2U02g= X-Google-Smtp-Source: AGHT+IGgLkurQIqH+LeiVKuUnK882zQSAt0h3jg5bg57JzH8xBIm92K4anGF7sihxb5wM39FF6lmHQ== X-Received: by 2002:a05:6512:3da3:b0:52e:76d5:9504 with SMTP id 2adb3069b0e04-53b348ec0c6mr5342333e87.3.1730199207896; Tue, 29 Oct 2024 03:53:27 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:26 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:03 +0100 Subject: [PATCH RFC v2 23/28] ARM: entry: Stop exiting syscalls like IRQs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-23-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 The syscalls are issued as software interrupts, and to this point they were sharing code with the other exception handlers, but this does not work with generic entry. Make syscall_exit_to_user_mode do what irqentry_exit_to_user_mode does at it's tail, and drop the invocations of irqentry_exit_to_user_mode from the syscall path so that these are now exception-exclusive. Split ret_to_user and ret_to_user_from_irq into two distinct execution paths. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 14 ++++++++++++-- arch/arm/kernel/entry.c | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 5385574c4339..e2ac6d3216b6 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -42,7 +42,6 @@ ret_fast_syscall: /* do_rseq_syscall needs interrupts enabled. */ mov r0, sp @ 'regs' bl syscall_exit_to_user_mode - asm_irqentry_exit_to_user_mode =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack @@ -62,6 +61,18 @@ ENTRY(ret_to_user) enable_irq_notrace @ enable interrupts mov r0, sp @ 'regs' bl syscall_exit_to_user_mode + ldr r1, [tsk, #TI_FLAGS] + movs r1, r1, lsl #16 + beq 1f + mov r0, sp @ 'regs' + bl do_work_pending +1: +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK + bl stackleak_erase_on_task_stack +#endif + restore_user_regs +ENDPROC(ret_to_user) + ENTRY(ret_to_user_from_irq) ldr r1, [tsk, #TI_FLAGS] movs r1, r1, lsl #16 @@ -76,7 +87,6 @@ no_work_pending: #endif restore_user_regs ENDPROC(ret_to_user_from_irq) -ENDPROC(ret_to_user) =20 /* * This is how we return from a fork. diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 0e3960844b94..88a7a699306a 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -30,6 +30,10 @@ void syscall_exit_to_user_mode(struct pt_regs *regs) local_irq_disable(); if (has_syscall_work(flags)) do_work_pending(regs, flags); + + trace_hardirqs_on(); + /* This context tracking call has inverse naming */ + user_enter_callable(); } =20 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 9733420E30F for ; Tue, 29 Oct 2024 10:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199213; cv=none; b=ipN1eGIuFMAsen8Ap9yzuVCRDTFPMx121+xJR5d3Dnjj9OsVhLpD+J7/ZIZwDqQvxMaul3ynX5MYg5XW8RyymDfkIglimBXJP3LgXssZP1MC5NHWoXLUkTNKaZGZeDUHnG/Q0X4hjNkbR+stLW3b6xT2wXr/7Elusv01h0f1T2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199213; c=relaxed/simple; bh=pM9plyuaboA4oYUAVGKr/KBZR4661Ija+Nu2nTY/g5A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ms5f5TNNBG3eDdv/4hOWxXR1+GK0xA56TXFAAH/wAAA5j8IkRYfgulZ1VHq6a2x2JguYQxFteOhF3uxG2AxJFAuuHTBvTtwxwGmgU+7uvGoozY5z1TUQ0Y8mrD0j3DWHwuYiOTbIWW4SFNNPjmvRUyGRJMvJChV4sFR3mBovf2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nlf3+Klt; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nlf3+Klt" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-539e3f35268so6247856e87.3 for ; Tue, 29 Oct 2024 03:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199210; x=1730804010; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=; b=nlf3+KltBZBGbKJr8f80nly8GrmSdrEGnKa4+uMRFp4zU2F2A00zzBTbqCcsBjvTx3 lc0AKYSFQGE+fegefqpFkWR33zv3C53EdCxvwdmmeo9DsctZ6brIsWQtMX5W+VjT2opX L5I0v0cqGlPIQYFyaw0hYcwd25M9KGZCxezXvKBe9JNIxHZmofKcwjcFZ0r8w0PNVF7T 8ze/EUmiGxIak2FPlOEvm3RqoVqFVpCx2UVp4fjlGCu8d/GVXPAZm7FH+PVvdGqcQCw+ l8meUvZUEnGRVWGa+jQYPZnSw9roJPVgpubb4PY+P7lKiEcGT0yzSBOepYJELlaTCf2l KtPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199210; x=1730804010; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=; b=aUb66hU+b9lTDXjSdOWrzbyt8I0nRHMWUK71pfTuvaU9py1lXK9ktm5wh8PTPNSixs A3HPULq9LQPmmpWYdDuqw7EUpgzveUkG8PsgebkPs3+Zw5f7xVFS8NtjpqPw/UNksjwR E8XABIMXRCu/EEn4bFxYTaBqGNxWK9/GWG7mcs7Z/13JhGVwk/5v/ftu+3jWhaEd2thL Rcxpl99olk7er/GFTF4vFswhB7YDDErtJagwlCKqPnQdYa4ZGYDZPx8hLwpKH1Cs7iO7 PS8OdywRFAkkiZ6d9igkaHOFiLPNySYS0fD4JPQR/Jh53fB0MgTKRKu8jZuX8ev5YzS1 p/rg== X-Forwarded-Encrypted: i=1; AJvYcCXoGLQUPnC/BIaAudDqwKtYfr/SCixBip0PyAa/FlBHV8crDaF9+N5nAQKzJL3MXWhREsgwqmIcPkBZwdI=@vger.kernel.org X-Gm-Message-State: AOJu0YyWQslrgvG3Co9m0feFV/aSkiweqe3ATYTZ4Gyr8zISEUprd9kI aZOXWr4LM53xWmUeNNT+Gy1Bv5npUdU6LvK57euGxJfBwg4BctL+urvNuUhCbLA= X-Google-Smtp-Source: AGHT+IESV034VK8PKLncc0cgi0pz3sqYxwxxzlGeXGgL9emDXp4QopwrVEL+WsUUoIebBL3YXi7/Ow== X-Received: by 2002:a05:6512:1252:b0:53b:1fc6:3cef with SMTP id 2adb3069b0e04-53b3491ccfamr4773281e87.37.1730199209505; Tue, 29 Oct 2024 03:53:29 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:28 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:04 +0100 Subject: [PATCH RFC v2 24/28] ARM: entry: Complete syscall and IRQ transition to C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-24-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 This moves over the last few lines of assembly to C. The subtle change is that in return to userspace from syscall (SWI) or interrupt, we need to call do_work_pending() as soon as the thread flags are !=3D 0, just checking for work with _TIF_SYSCALL_WORK is not enough (the machine will freeze if we do that). This is because do_work_pending() does not just handle work: it handles _TIF_NEED_RESCHED, _TIF_SIGPENDING, _TIF_NOTIFY_SIGNAL and _TIF_UPROBE as well. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 13 +------------ arch/arm/kernel/entry.c | 19 +++++++++++++------ arch/arm/kernel/signal.c | 3 +-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e2ac6d3216b6..6b0f86786a7d 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -61,12 +61,7 @@ ENTRY(ret_to_user) enable_irq_notrace @ enable interrupts mov r0, sp @ 'regs' bl syscall_exit_to_user_mode - ldr r1, [tsk, #TI_FLAGS] - movs r1, r1, lsl #16 - beq 1f - mov r0, sp @ 'regs' - bl do_work_pending -1: + #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack #endif @@ -74,12 +69,6 @@ ENTRY(ret_to_user) ENDPROC(ret_to_user) =20 ENTRY(ret_to_user_from_irq) - ldr r1, [tsk, #TI_FLAGS] - movs r1, r1, lsl #16 - beq no_work_pending - mov r0, sp @ 'regs' - bl do_work_pending -no_work_pending: asm_irqentry_exit_to_user_mode =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 88a7a699306a..d7fdb9df3331 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -6,11 +6,6 @@ #include #include =20 -static inline bool has_syscall_work(unsigned long flags) -{ - return unlikely(flags & _TIF_SYSCALL_WORK); -} - long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) { trace_hardirqs_on(); @@ -28,7 +23,11 @@ void syscall_exit_to_user_mode(struct pt_regs *regs) =20 rseq_syscall(regs); local_irq_disable(); - if (has_syscall_work(flags)) + /* + * It really matters that we check for flags !=3D 0 and not + * just for pending work here! + */ + if (flags) do_work_pending(regs, flags); =20 trace_hardirqs_on(); @@ -45,6 +44,14 @@ noinstr void irqentry_enter_from_user_mode(struct pt_reg= s *regs) =20 noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) { + unsigned long flags =3D read_thread_flags(); + + /* + * It really matters that we check for flags !=3D 0 and not + * just for pending work here! + */ + if (flags) + do_work_pending(regs, flags); trace_hardirqs_on(); /* This context tracking call has inverse naming */ user_enter_callable(); diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 03b20637a2e1..a39ee14ec5b7 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -598,8 +598,7 @@ static void arch_do_signal_or_restart(struct pt_regs *r= egs) return; } =20 -asmlinkage void -do_work_pending(struct pt_regs *regs, unsigned int thread_flags) +void do_work_pending(struct pt_regs *regs, unsigned int thread_flags) { /* * The assembly code enters us with IRQs off, but it hasn't --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 7AD5A20E034 for ; Tue, 29 Oct 2024 10:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199217; cv=none; b=sa0vdOPd19Rh9/qi7g+odOOcMi8t1/d9a+Jmn5z8J0J1aU3UKHyxS7DGlCyVIRybAg3GbP7IpE2VYS9j81ZVQnzNpftI5X/kSojO7vEIO32yfa2z/ZASb4v6NrfI2MQAh0MOIm9VTN7fIXzZk5Wy7eIHcbn8ojm8BfOYWuU6pe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199217; c=relaxed/simple; bh=1+xGn+I5zGJWUmASKFRl6SMQB/wIv78GqsCAwMsFqAA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xh0zY+GoBlRTNu+I02qupVuFxZoX5igNqOl+e3uWY4b79hUDuNVI8b2N1PZ449wa89PLbtLfaFfEXgy20PIqByiSwKLpf+kwaIgarG3uHpMAZBoIYtlaDtthrstEpWUjDfpVE0ZjXQdZH9yJxp2Z6bqcQZj6AscOtxBlk1HTU5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rDzmJj8q; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rDzmJj8q" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-539f0f9ee49so5633413e87.1 for ; Tue, 29 Oct 2024 03:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199214; x=1730804014; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=e/3IXPLtEzkdPxakYsKtSl6x7P98QonT1kDDJ6tUink=; b=rDzmJj8qs6GBlIeQ4AEb/W5rR3G6Usf1zycSEqnNmDafPcXaPXtCrO9dI6OBzAnw9E kXdgQNuKwZxos+uA+qVG2uLfoKhZF19CUif/Uv5WshpSelS5bXnvg3yC3Cn43HXC0DSM gKWsivB2ggeGKhhvEBnOGCpuVaBFafT0eerAmjjr05PyxXBIOS1L1ntAdOK6UDpbRooX KDEFieZRWbU7SavjQkhaKA5BG1vfWwY2JJHMl3uV1mfBWM3MSlUK4jwMGr+c5UK5mRqI qT0T2X3xn6Gy9uCiQTTNRXY6UL1veVvw7ZAgm23j1vS05m+vlcHas3xwrLCOdAxJ/+4c G4gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199214; x=1730804014; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e/3IXPLtEzkdPxakYsKtSl6x7P98QonT1kDDJ6tUink=; b=sKXwQ0f+tq3vojb2hIZvuuPNI2XKjQJslyy4qd924/7XtlU66wfem5aweUDmtRp0dE nuQjn6oSM6kjrzRdfWUFN5nm+3P54/SbBbxiMfvHUWSb4mEgAFvX47KUvsC9eRKG/WRq hzG+5rT/RBDxWUdNToCC4bq1+NMwPhHULhcdyYKtgWlSNIVHKKj1gSaSb1OsDbMypvSz 1ilMT4Wjy29Z7bMDylfV+QkmP6PJRm4mkEn1sTloUgrsKTOQLON1osQp613X2g1zphaV sz5SZ4QYI39aKGzJLK6ArDTg+3ZzD7tdh50Akd5QybOt+20xxSmlr72plQ2i8u7jpLL1 OaOg== X-Forwarded-Encrypted: i=1; AJvYcCW/+CUS6qU5cWvre1/2KEc86wvaDn6250tHYIY2W8d3QQkHWrQq3hPKU5lDZ0M//AA9x3B6jrCiNrRN0Mk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9oB9fkERgfDlfAplajYMlKY+vmOdL1smpnqFdZS873oSL5eOx P9ypKH85Gvaf82/NSGJGd+8GcM6za3tlkgtdEtpz8w4v95vFNbfBNyE2HW0GxWkbw9AZZmZi+Y4 K X-Google-Smtp-Source: AGHT+IEv5OXz88Rah8wOjpkuPKbULq5MyD1fSlWtEkl9G05R3LmA9cdfp5t7ybciPjtapRrrDr8Jpw== X-Received: by 2002:a05:6512:3084:b0:539:fed8:321 with SMTP id 2adb3069b0e04-53b34a31cdbmr4939966e87.51.1730199213675; Tue, 29 Oct 2024 03:53:33 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:32 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:05 +0100 Subject: [PATCH RFC v2 25/28] ARM: entry: Create irqentry calls from kernel mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-25-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 This adds a few calls to C when exceptions enter/exit from the kernel itself, so these can be used for generic entry. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 2 ++ arch/arm/kernel/entry-armv.S | 3 +++ arch/arm/kernel/entry-header.S | 5 +++++ arch/arm/kernel/entry.c | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h index 8b8cc9a1eefb..a78bc5054b09 100644 --- a/arch/arm/include/asm/entry.h +++ b/arch/arm/include/asm/entry.h @@ -12,5 +12,7 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, l= ong); void syscall_exit_to_user_mode(struct pt_regs *regs); void irqentry_enter_from_user_mode(struct pt_regs *regs); void irqentry_exit_to_user_mode(struct pt_regs *regs); +void irqentry_enter_from_kernel_mode(struct pt_regs *regs); +void irqentry_exit_to_kernel_mode(struct pt_regs *regs); =20 #endif /* __ASM_ENTRY_H__ */ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index bd468d58dc02..21b11fe199cb 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -204,6 +204,9 @@ ENDPROC(__und_invalid) get_thread_info tsk uaccess_entry tsk, r0, r1, r2, \uaccess =20 + mov r0, sp @ 'regs' + bl irqentry_enter_from_kernel_mode + .if \trace #ifdef CONFIG_TRACE_IRQFLAGS bl trace_hardirqs_off diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 51c7f93c1ded..49a9c5cf6fd5 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -210,6 +210,7 @@ .else @ IRQs off again before pulling preserved data off the stack disable_irq_notrace + #ifdef CONFIG_TRACE_IRQFLAGS tst \rpsr, #PSR_I_BIT bleq trace_hardirqs_on @@ -217,6 +218,10 @@ blne trace_hardirqs_off #endif .endif + + mov r0, sp @ 'regs' + bl irqentry_exit_to_kernel_mode + uaccess_exit tsk, r0, r1 =20 #ifndef CONFIG_THUMB2_KERNEL diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index d7fdb9df3331..674b5adcec00 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -56,3 +56,11 @@ noinstr void irqentry_exit_to_user_mode(struct pt_regs *= regs) /* This context tracking call has inverse naming */ user_enter_callable(); } + +noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs) +{ +} + +noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs) +{ +} --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 096FB2076A8 for ; Tue, 29 Oct 2024 10:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199219; cv=none; b=UYupqJ9sjno87z3Aq0MPKnAJQ9LizmatmSefGR7abxNehJpNw3Hw5wFiRMiCpEvaBuAMDP8vkEvtl0RFjvdkOOfjyfA0bnej7P/By74670x6rOwpdYpQvSqLjYphW4JxLT0GnsQ8BdUhQbD1J+aulS1Y72twSb0bGiwlLvVQLb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199219; c=relaxed/simple; bh=p++J5jDdayY9hU28M7/pcg9MrpkZxPTcO20YZjwEn6Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qxolrndMhftUaTYUS5U52KSLSdONAcUA5lPiOp/DU8YFWQk08wo/MyFC1enZT7bKTorBSTgEVcm3/vQ2hxfB2B+GhSM7vFkqB4+A61sBR1jKzGGMouO3SPa3x9L4FSFvsqoE2/6+ejNeNHrE/qpqQgMsOYApXp53KJQ72Vrabg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WLNCzxAJ; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WLNCzxAJ" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-539f6e1f756so5518583e87.0 for ; Tue, 29 Oct 2024 03:53:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199215; x=1730804015; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZScZ0+O1z+KD5ly1wGwp6XJNh1QIX+DiUm/Qzjn1DDQ=; b=WLNCzxAJw381+jUh66ndCHEcVC+2L+JyxOYBd1ifdn3b8V9WjSsumG+dtmAfZ1iCml s+oKGTgqDOoGpzaZZAf17e2jEWJR8Brq7rhEzYFYMFac+TlcpiIfppXH6t5A/M4btlxy dYhZXWfOWzs8+o0oRCT9HTltjXlAWSpdeeqN/9i2dA/cOAKuJgA7RiSqb7IYuYJzlCT6 3oV/L1A4L4047Yximk28vBvEau2ewwSoT/itFhBPSR3Mf4Rb43gE9kTuiyE+7LG3FSai ViIf16kW0rcJ8VqmzWSsVPT211AWWrupdNgJmiQJSrOAxBLrMzBqcsVYk/8TVpvDVwTg qYEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199215; x=1730804015; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZScZ0+O1z+KD5ly1wGwp6XJNh1QIX+DiUm/Qzjn1DDQ=; b=XHy+2e/d/j54+V1cyleW9G+zY7o9Tv3Lxiwkr5Gw1BupsnY9bXMTEPaDNdjnqsXu1p NXEyu5KgkbRCSm5qREiyDeN44hptmZ7ekOvLdjLDBRKsGd1ye0nKKGJltv96zLCRRNIW f8jaFbdTdG2xwx3VX8qqkJKD3PtHZ1fVHAcfzBcoLGn/X+HKjgmW6Rszykib25A7lzzu a3llmuV5UE1jfT/g/N283LRrYJZaaqNZOQleu0w+LxN3BHwJS1gPRp9KuaPqTgQzzzao GOh4NufmkEoUubhdnIkHODxzcrgEK4RTJCBML5idUk+dL2Wd+a1Lu5QWK2zix9e++cy4 +kwg== X-Forwarded-Encrypted: i=1; AJvYcCWoNdb4ATO/yMcWUKtm8ndshLgIsMGPHmxklWSOphPJp3tmAL46cQDL2KxDIzjTFzKXMJrmhBnVb/mG8t0=@vger.kernel.org X-Gm-Message-State: AOJu0YyLcdmv0jkX+fKJbmWUvNADAHrI1vGcxPcVSiIP/s1BLVR5w+19 oExx++qSs7FmMMyEBQfAO+2V9msQpeLL15YxTOS/XrJpo3irCHlwaVdaB/+e/zA= X-Google-Smtp-Source: AGHT+IFuQtccSquVaHeIkt6pIsoMJv+xdK5WssF0bBYkK4KjihYMKnkM5Ythh/2t9kCbB2W6mYSllQ== X-Received: by 2002:a05:6512:a92:b0:539:fd10:f07b with SMTP id 2adb3069b0e04-53b34b39774mr5544494e87.55.1730199215170; Tue, 29 Oct 2024 03:53:35 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:34 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:06 +0100 Subject: [PATCH RFC v2 26/28] ARM: entry: Move in-kernel hardirq tracing to C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-26-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 Move the code tracing hardirqs on/off into the C callbacks for irqentry_enter_from_kernel_mode() and irqentry_exit_to_kernel_mode(). The semantic difference occurred is that we alsways check the PSR_I_BIT to determine if (hard) interrupts were enabled or not. The assembly has a tweak to avoid this if we are exiting an IRQ since it is obvious that IRQs must have been enabled to get there, but for simplicity we just check it for all exceptions. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-armv.S | 13 ++++--------- arch/arm/kernel/entry-header.S | 19 ++----------------- arch/arm/kernel/entry.c | 5 +++++ 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 21b11fe199cb..600375f6f5d8 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -157,7 +157,7 @@ ENDPROC(__und_invalid) #define SPFIX(code...) #endif =20 - .macro svc_entry, stack_hole=3D0, trace=3D1, uaccess=3D1, overflow_check= =3D1 + .macro svc_entry, stack_hole=3D0 uaccess=3D1, overflow_check=3D1 UNWIND(.fnstart ) sub sp, sp, #(SVC_REGS_SIZE + \stack_hole) THUMB( add sp, r1 ) @ get SP in a GPR without @@ -207,11 +207,6 @@ ENDPROC(__und_invalid) mov r0, sp @ 'regs' bl irqentry_enter_from_kernel_mode =20 - .if \trace -#ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_off -#endif - .endif .endm =20 .align 5 @@ -238,7 +233,7 @@ __irq_svc: blne svc_preempt #endif =20 - svc_exit r5, irq =3D 1 @ return from exception + svc_exit r5 @ return from exception UNWIND(.fnend ) ENDPROC(__irq_svc) =20 @@ -302,7 +297,7 @@ ENDPROC(__pabt_svc) =20 .align 5 __fiq_svc: - svc_entry trace=3D0 + svc_entry mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi svc_exit_via_fiq @@ -320,7 +315,7 @@ ENDPROC(__fiq_svc) @ .align 5 __fiq_abt: - svc_entry trace=3D0 + svc_entry =20 ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 49a9c5cf6fd5..cfaf14d71378 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -199,26 +199,11 @@ .endm =20 =20 - .macro svc_exit, rpsr, irq =3D 0 - .if \irq !=3D 0 - @ IRQs already off -#ifdef CONFIG_TRACE_IRQFLAGS - @ The parent context IRQs must have been enabled to get here in - @ the first place, so there's no point checking the PSR I bit. - bl trace_hardirqs_on -#endif - .else + .macro svc_exit, rpsr + @ IRQs off again before pulling preserved data off the stack disable_irq_notrace =20 -#ifdef CONFIG_TRACE_IRQFLAGS - tst \rpsr, #PSR_I_BIT - bleq trace_hardirqs_on - tst \rpsr, #PSR_I_BIT - blne trace_hardirqs_off -#endif - .endif - mov r0, sp @ 'regs' bl irqentry_exit_to_kernel_mode =20 diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 674b5adcec00..1e1284cc4cae 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -59,8 +59,13 @@ noinstr void irqentry_exit_to_user_mode(struct pt_regs *= regs) =20 noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs) { + trace_hardirqs_off(); } =20 noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs) { + if (interrupts_enabled(regs)) + trace_hardirqs_on(); + else + trace_hardirqs_off(); } --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 7BE4F20F3C9 for ; Tue, 29 Oct 2024 10:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199220; cv=none; b=slXd2h9voIKYUKZQQGa1y4DNuGCJR/AzU1JZtJxZgilcwXo1CzJFTkMthlNPeP3zNMdk7SVq4z7hDsiIYls6r8BSYgicbj7IvRHeOIVWsd2oa0oHRln6gSLshfEs09ky3pByuDQqivHNwUAvunUSUxRK/LTWGWvjReOziXH7rJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199220; c=relaxed/simple; bh=LswCk2i9g8K5KyBn9gI4xldOhoqS7tQiTwGUwHGEJZs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fIR/eKBaOiue5NRHCFeH5CapP+htxaj86A42b2Ck8obt1NBytcfyAa4kbHDBAczJZI+vgNrnh5nELg8hAhoTWxaNIpX0GA4Z5Fvk2ZTl4OeEVYXsHGT75mXMFSdMB9p+3gAgw2xCf+21reloJw2I2bP8uNbbeOub8P/GXEYXE20= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TrXbuvNB; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TrXbuvNB" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-539eb97f26aso5436376e87.2 for ; Tue, 29 Oct 2024 03:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199217; x=1730804017; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/aytaH1oLbxE7oXL5Lh1BICkPib3Ft7vQWy4tTKokWI=; b=TrXbuvNBxPwq33fZ17rEnplyUXjRDa4QzByPf3hx8zyafiFBdIbJLLJzXZKNqvjwiP yDvFehp8icK1CYzj+1/Dwszlfxi4gfsiClJKNuM/Chx0xB/L/1d/2hybg+07Nvyx6exw rslx2bDISrMAGsqcIrNJMnpziFrI4F4/ggvRZxGxoce71Nz+krdSweTbQloBpYmEECWb EwkiQX7YUMZISyFWYiSNoQyMOlkcLLUx7lpDJKdlAR36tTzfdUYg2j9UmJIMsXviG67T NsH/2lFRhysCGGUmsPaaUJN8n/mQFae9BUZ1FBRceveWtr/5HhtokdsYrAIWwqJ1Iui+ 9Sbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199217; x=1730804017; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/aytaH1oLbxE7oXL5Lh1BICkPib3Ft7vQWy4tTKokWI=; b=W5IYtdO2HjSGy2tQU8jgvTFHP8FzuIfi1X4XTySPlHyQ9NWM8A0mo+gYhxSBwLPM4c haRKPivXYhY1n1LWQK9Fiw6QQmm3rJiugZzBewQ5q0wAoyaud70Kv0Um97fkWwEXEk1/ BdfXaeFYjL28wYaDB61J3Vnw/ngB62SJg++Rlo5Niie768bgRSmewzEBgESOWGLo9pAJ gApIhS2PFBc2AKI+pINMAztwesZa/r/TdRa+CEX+oG6bx0y7SsU/H4LjN1ahSRVGRTUL u1+9nuVhd3p0KWQb5mBkMxRFJH9tgi+cdpFN59yXeqTWMjgN8CwPqHsUYqkWTPbo51wQ 31JQ== X-Forwarded-Encrypted: i=1; AJvYcCVMZr55kdDKS+Ai97Ijxai/fXu5XWZ2/m3GEAVlfjDvEtJyW1+Av75ngaX5HyEnxf6HdPfNYcGRKqGtZgs=@vger.kernel.org X-Gm-Message-State: AOJu0YwtEKX/Gie5/IDyF6dL++jXQvo1obK6GQA0tAyP4bh1n62tKagE eZX9P3RJNAVcNo2hldJmMYGYwGypPQwOJRdZrcCG1lL1xuy18HfKnjoMJ2ieox0= X-Google-Smtp-Source: AGHT+IGR4YQInxFI66N5j0WfMdCdeF355iwdhYBDKEXmAVJwY1SO6OvLh/7PzjphT8TgoLwPMIQX0Q== X-Received: by 2002:a05:6512:10d6:b0:539:f7de:df6a with SMTP id 2adb3069b0e04-53b34a3208dmr5334035e87.52.1730199216687; Tue, 29 Oct 2024 03:53:36 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:35 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:07 +0100 Subject: [PATCH RFC v2 27/28] ARM: entry: Add FIQ/NMI C callbacks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-27-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 These NMI (FIQ) callbacks are added to complete the calls expected by the generic entry. They are perfectly fine to add code to but are left empty for now. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 4 ++++ arch/arm/kernel/entry-armv.S | 14 +++++++++++--- arch/arm/kernel/entry-header.S | 2 ++ arch/arm/kernel/entry.c | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h index a78bc5054b09..2e7ccd87f0eb 100644 --- a/arch/arm/include/asm/entry.h +++ b/arch/arm/include/asm/entry.h @@ -14,5 +14,9 @@ void irqentry_enter_from_user_mode(struct pt_regs *regs); void irqentry_exit_to_user_mode(struct pt_regs *regs); void irqentry_enter_from_kernel_mode(struct pt_regs *regs); void irqentry_exit_to_kernel_mode(struct pt_regs *regs); +void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs); +void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs); +void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs); +void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs); =20 #endif /* __ASM_ENTRY_H__ */ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 600375f6f5d8..839f3ebe7228 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -157,7 +157,7 @@ ENDPROC(__und_invalid) #define SPFIX(code...) #endif =20 - .macro svc_entry, stack_hole=3D0 uaccess=3D1, overflow_check=3D1 + .macro svc_entry, stack_hole=3D0 uaccess=3D1, overflow_check=3D1, nmi=3D0 UNWIND(.fnstart ) sub sp, sp, #(SVC_REGS_SIZE + \stack_hole) THUMB( add sp, r1 ) @ get SP in a GPR without @@ -205,7 +205,11 @@ ENDPROC(__und_invalid) uaccess_entry tsk, r0, r1, r2, \uaccess =20 mov r0, sp @ 'regs' + .if \nmi + bl irqentry_nmi_enter_from_kernel_mode + .else bl irqentry_enter_from_kernel_mode + .endif =20 .endm =20 @@ -297,7 +301,7 @@ ENDPROC(__pabt_svc) =20 .align 5 __fiq_svc: - svc_entry + svc_entry nmi=3D1 mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi svc_exit_via_fiq @@ -315,7 +319,7 @@ ENDPROC(__fiq_svc) @ .align 5 __fiq_abt: - svc_entry + svc_entry nmi=3D1 =20 ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) @@ -490,9 +494,13 @@ ENDPROC(ret_from_exception) .align 5 __fiq_usr: usr_entry + mov r0, sp + bl irqentry_nmi_enter_from_user_mode kuser_cmpxchg_check mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi + mov r0, sp + bl irqentry_nmi_exit_to_user_mode get_thread_info tsk restore_user_regs UNWIND(.fnend ) diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index cfaf14d71378..ec8a6e193802 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -252,6 +252,8 @@ @ .macro svc_exit_via_fiq uaccess_exit tsk, r0, r1 + mov r0, sp + bl irqentry_nmi_exit_to_kernel_mode #ifndef CONFIG_THUMB2_KERNEL @ ARM mode restore mov r0, sp diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 1e1284cc4cae..09109215dfdf 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -69,3 +69,19 @@ noinstr void irqentry_exit_to_kernel_mode(struct pt_regs= *regs) else trace_hardirqs_off(); } + +noinstr void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs) +{ +} + +noinstr void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs) +{ +} + +noinstr void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs) +{ +} + +noinstr void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs) +{ +} --=20 2.46.2 From nobody Sat Feb 7 05:20:49 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 56CDF20F5A5 for ; Tue, 29 Oct 2024 10:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199224; cv=none; b=GwX0Pn38Wv/0Qe16b6LbfQb1B9L1RwdwF8VoWpoeyBrkbqtmgkjKsmYvyDwMEO1dwvMkQgxi7q82I8qT3HsnQgGG26AIqsIpiGCfP4amSM7EIFoB65D2+F9Egx3aFB3PJjyg2dWzYTef0UX9w5PzAJKY4Y0WzoFh69N7Rm48a8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730199224; c=relaxed/simple; bh=uPeneaNYhI5as6kmA2he0Saqo+6XyjuMdjrSQcWI3QE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s6sb5RUZnddU9ykV+J6XlG1S7gE1okm0JrWTfIi+ehOQIykc+t7HMpSly/JVzXjhzV5RkdqCE446DKSXYOQ8PTBO9cpAjzeaFZ4sO1JvJbAlEOPgY2c39GxE93C7bYJxyZGoiXLNzDZmmyeSKwawUujJr+zSQpB1IIL6YSJGbLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TTVEMFz3; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TTVEMFz3" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53a0c160b94so5892910e87.2 for ; Tue, 29 Oct 2024 03:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199218; x=1730804018; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=n0vhef1d/tO4V+dCGdQHkCwxrnfd2znP3qGknf9D7ME=; b=TTVEMFz3jk5Sjjm5WdvcKczzeVbQwNKLNKR549sC1+jZRuphnuK4eIKoZaeRjwT6aQ BXqcKTkKzTqTPyVv4FjvfkRR5tjQkWSKKV8yUWTrz0A5a3Ub3ApPXOU/JrJ44alMKXvh h+2HvlHbnfBZxPfaILbDxgAdAUTnJnhJOY6bozK7qBN+E3l50YjM4NFMxstJco1eAFfp iDLOhZ7TC+vd81CbCQOuIHsuVBFM1Nb+K/52KSPdbAEsdCdoGYG3UsQecSakLuQuG/To kIbpU8ywcZ22d38200R3wPOFk8Qpt126FIcJH7ZngMA1YjeQ/t1DffjJJLy59iwC0k51 Ax3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199218; x=1730804018; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n0vhef1d/tO4V+dCGdQHkCwxrnfd2znP3qGknf9D7ME=; b=PMbefGScXpAjvnvO1+JRBl+24TVPbXbmGvJ9t0y/Eni0RqhgKN4c/XhqAhDDmXNmGg G0OEUZyDkTpY+zpb+XYPkGmJ2/e/WmR0DGzwV4k3BLf/U2ahNF8ReKJ9PZOdfFiF/9d8 DfZXditqNNGu+jS/NgqnUQazuZ+WAaVy/+x4ughhww8A4zmfuj2u0IXFqcGBkOdHpNJ+ nxyLN1cRW+0dOC0FnAuKXfFluUNntw24L4LYjS+Kl2QGjIc/bb3+2Q7kBL5bcOshqVvq SWzwof8QO9Ott+ml+jv1jaUzd66QwlQVicx2/iYP+/tg0gJcZC11AJtajMWqVruhOc6Q shXw== X-Forwarded-Encrypted: i=1; AJvYcCUcue+eYtJhLnGbB8Uu9z7kFOwBOzNBc9RPrEuq/CMy05jGS5ARHOQF2Ef/+Wk1O7f/QR+ucfjiVftkS50=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7j3+x/95zn2KIgJJT861rw8ECiecxSqom8uXLGR80PhSapN9t +B1YGMoASzq33RX27WH2mYdTPlqs9FOTD/2W/jowGVJ6xfZTQ/4avGZsgbVUYGGZHuEY1vVHAu/ 2 X-Google-Smtp-Source: AGHT+IGwFjlzuzMZEo0N73/9K3H1Re0V56WIf94sbX16/ps67sdO8rsNPiu8KdHISykctGPyp0tuDg== X-Received: by 2002:a05:6512:4024:b0:539:8d9b:b624 with SMTP id 2adb3069b0e04-53b34a31f8fmr5316573e87.55.1730199218365; Tue, 29 Oct 2024 03:53:38 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:37 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:53:08 +0100 Subject: [PATCH RFC v2 28/28] ARM: entry: Convert to generic entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-arm-generic-entry-v2-28-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 This rewrites ARM to use the generic entry. All of the irqentry_* callbacks are renamed to arm_irqentry_* and made to call into the generic entry code. The state for IRQ and NMI for usermode and kernelmode is stored into a static local variable as interrupts are not reentrant. The syscall_enter_from_user_mode(), syscall_exit_to_user_mode(), do_work_pending() constructs are replaced with generic code. The syscall invocation now enables syscall tracing "work" using the generic callbacks and no extra actions are needed to enable/disable syscall tracing. The old context tracking with user_exit_callable() user_enter_callable() is no longer used. Only CSKY and Xtensa use this deprecated mechanism now. Like with the ARM64 proposed patch for generic entry, it is necessary to create a small call "arm_exit_to_user_mode()" that is used for things such as ret_from_fork, i.e. when we create a completely new execution context with a botched return from interrupt. Open questions: - I had to add defines for PTRACE_SYSEMU and PTRACE_SYSEMU_SINGLESTEP and I have no idea what those are or why they are required. Sorry for my ignorance, I need help to figure out how we deal with this. Signed-off-by: Linus Walleij --- arch/arm/Kconfig | 1 + arch/arm/include/asm/entry-common.h | 66 +++++++++++++++++++++++++++ arch/arm/include/asm/entry.h | 23 ++++------ arch/arm/include/asm/ptrace.h | 3 -- arch/arm/include/asm/signal.h | 2 - arch/arm/include/asm/syscall.h | 7 ++- arch/arm/include/asm/thread_info.h | 17 +------ arch/arm/include/uapi/asm/ptrace.h | 2 + arch/arm/kernel/entry-armv.S | 8 ++-- arch/arm/kernel/entry-common.S | 34 +++++--------- arch/arm/kernel/entry-header.S | 8 ++-- arch/arm/kernel/entry.c | 80 +++++++++++---------------------- arch/arm/kernel/process.c | 2 - arch/arm/kernel/ptrace.c | 90 ---------------------------------= ---- arch/arm/kernel/signal.c | 31 +------------ arch/arm/kernel/syscall.c | 27 +++-------- 16 files changed, 137 insertions(+), 264 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 749179a1d162..8155a4be7c9b 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -66,6 +66,7 @@ config ARM select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_DEVICES select GENERIC_EARLY_IOREMAP + select GENERIC_ENTRY select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_MULTI_HANDLER select GENERIC_IRQ_PROBE diff --git a/arch/arm/include/asm/entry-common.h b/arch/arm/include/asm/ent= ry-common.h new file mode 100644 index 000000000000..7b1f108512db --- /dev/null +++ b/arch/arm/include/asm/entry-common.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_ARM_ENTRY_COMMON_H +#define _ASM_ARM_ENTRY_COMMON_H + +#include + +#include + +enum ptrace_syscall_dir { + PTRACE_SYSCALL_ENTER =3D 0, + PTRACE_SYSCALL_EXIT, +}; + +static inline unsigned long +arch_prepare_report_syscall_entry(struct pt_regs *regs) +{ + unsigned long ip; + + /* + * IP is used to denote syscall entry/exit: + * IP =3D 0 -> entry + */ + ip =3D regs->ARM_ip; + regs->ARM_ip =3D PTRACE_SYSCALL_ENTER; + + return ip; +} +#define arch_prepare_report_syscall_entry arch_prepare_report_syscall_entry + +static inline void +arch_post_report_syscall_entry(struct pt_regs *regs, + unsigned long saved_reg, long ret) +{ + regs->ARM_ip =3D saved_reg; +} +#define arch_post_report_syscall_entry arch_post_report_syscall_entry + + +static inline unsigned long +arch_prepare_report_syscall_exit(struct pt_regs *regs, + unsigned long work) +{ + unsigned long ip; + + /* + * IP is used to denote syscall entry/exit: + * IP =3D 1 -> exit + */ + ip =3D regs->ARM_ip; + regs->ARM_ip =3D PTRACE_SYSCALL_EXIT; + + return ip; +} +#define arch_prepare_report_syscall_exit arch_prepare_report_syscall_exit + +static inline void +arch_post_report_syscall_exit(struct pt_regs *regs, + unsigned long saved_reg, + unsigned long work) +{ + regs->ARM_ip =3D saved_reg; +} +#define arch_post_report_syscall_exit arch_post_report_syscall_exit + +#endif /* _ASM_ARM_ENTRY_COMMON_H */ diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h index 2e7ccd87f0eb..dadf0064c65b 100644 --- a/arch/arm/include/asm/entry.h +++ b/arch/arm/include/asm/entry.h @@ -4,19 +4,14 @@ =20 struct pt_regs; =20 -/* - * These are copies of generic entry headers so we can transition - * to generic entry once they are semantically equivalent. - */ -long syscall_enter_from_user_mode(struct pt_regs *regs, long); -void syscall_exit_to_user_mode(struct pt_regs *regs); -void irqentry_enter_from_user_mode(struct pt_regs *regs); -void irqentry_exit_to_user_mode(struct pt_regs *regs); -void irqentry_enter_from_kernel_mode(struct pt_regs *regs); -void irqentry_exit_to_kernel_mode(struct pt_regs *regs); -void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs); -void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs); -void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs); -void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs); +void arm_irqentry_enter_from_user_mode(struct pt_regs *regs); +void arm_irqentry_exit_to_user_mode(struct pt_regs *regs); +void arm_irqentry_enter_from_kernel_mode(struct pt_regs *regs); +void arm_irqentry_exit_to_kernel_mode(struct pt_regs *regs); +void arm_irqentry_nmi_enter_from_user_mode(struct pt_regs *regs); +void arm_irqentry_nmi_exit_to_user_mode(struct pt_regs *regs); +void arm_irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs); +void arm_irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs); +void arm_exit_to_user_mode(struct pt_regs *regs); =20 #endif /* __ASM_ENTRY_H__ */ diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index a01c66f0ad90..8a7de4020cbc 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -200,8 +200,5 @@ static inline unsigned long it_advance(unsigned long cp= sr) return cpsr; } =20 -int syscall_trace_enter(struct pt_regs *regs); -void syscall_trace_exit(struct pt_regs *regs); - #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h index bb753cd3e29f..45885383646c 100644 --- a/arch/arm/include/asm/signal.h +++ b/arch/arm/include/asm/signal.h @@ -23,6 +23,4 @@ typedef struct { =20 #include =20 -void do_work_pending(struct pt_regs *regs, unsigned int thread_flags); - #endif diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index b94fd7ce17f8..a6c8f0e799bb 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -19,7 +19,12 @@ =20 extern const unsigned long sys_call_table[]; =20 -int invoke_syscall(void *table, struct pt_regs *regs, int scno); +void invoke_syscall(void *table, struct pt_regs *regs, int scno); + +static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) +{ + return false; +} =20 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thre= ad_info.h index d8a45c5a1049..84e58a9cdab6 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -74,6 +74,7 @@ struct thread_info { #ifdef CONFIG_ARM_THUMBEE unsigned long thumbee_state; /* ThumbEE Handler Base register */ #endif + unsigned long syscall_work; /* SYSCALL_WORK_ flags */ }; =20 #define INIT_THREAD_INFO(tsk) \ @@ -149,30 +150,14 @@ extern int vfp_restore_user_hwstate(struct user_vfp *, #define TIF_USING_IWMMXT 17 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 19 -#define TIF_SYSCALL_TRACE 20 /* syscall trace active */ -#define TIF_SYSCALL_AUDIT 21 /* syscall auditing active */ -#define TIF_SYSCALL_TRACEPOINT 22 /* syscall tracepoint instrumentation */ -#define TIF_SECCOMP 23 /* seccomp syscall filtering active */ - =20 #define _TIF_SIGPENDING (1 << TIF_SIGPENDING) #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) #define _TIF_UPROBE (1 << TIF_UPROBE) -#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) -#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) -#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) -#define _TIF_SECCOMP (1 << TIF_SECCOMP) #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL) #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT) =20 -/* Checks for any syscall work in entry-common.S */ -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP) - -/* - * Change these and you break ASM code in entry-common.S - */ #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ _TIF_NOTIFY_RESUME | _TIF_UPROBE | \ _TIF_NOTIFY_SIGNAL) diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm= /ptrace.h index 8896c23ccba7..336a5beb282f 100644 --- a/arch/arm/include/uapi/asm/ptrace.h +++ b/arch/arm/include/uapi/asm/ptrace.h @@ -33,6 +33,8 @@ #define PTRACE_GETHBPREGS 29 #define PTRACE_SETHBPREGS 30 #define PTRACE_GETFDPIC 31 +#define PTRACE_SYSEMU 32 +#define PTRACE_SYSEMU_SINGLESTEP 33 =20 #define PTRACE_GETFDPIC_EXEC 0 #define PTRACE_GETFDPIC_INTERP 1 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 839f3ebe7228..1bbadf13136e 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -206,9 +206,9 @@ ENDPROC(__und_invalid) =20 mov r0, sp @ 'regs' .if \nmi - bl irqentry_nmi_enter_from_kernel_mode + bl arm_irqentry_nmi_enter_from_kernel_mode .else - bl irqentry_enter_from_kernel_mode + bl arm_irqentry_enter_from_kernel_mode .endif =20 .endm @@ -495,12 +495,12 @@ ENDPROC(ret_from_exception) __fiq_usr: usr_entry mov r0, sp - bl irqentry_nmi_enter_from_user_mode + bl arm_irqentry_nmi_enter_from_user_mode kuser_cmpxchg_check mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi mov r0, sp - bl irqentry_nmi_exit_to_user_mode + bl arm_irqentry_nmi_exit_to_user_mode get_thread_info tsk restore_user_regs UNWIND(.fnend ) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 6b0f86786a7d..b3b2455ab0a1 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -39,10 +39,6 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) add sp, sp, #(S_R0 + S_OFF) - /* do_rseq_syscall needs interrupts enabled. */ - mov r0, sp @ 'regs' - bl syscall_exit_to_user_mode - #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack #endif @@ -60,7 +56,7 @@ ENTRY(ret_to_user) /* do_rseq_syscall needs interrupts enabled. */ enable_irq_notrace @ enable interrupts mov r0, sp @ 'regs' - bl syscall_exit_to_user_mode + bl arm_exit_to_user_mode =20 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack @@ -94,7 +90,14 @@ SYM_TYPED_FUNC_START(ret_from_fork_asm) bl ret_from_fork mov r0, #0 1: get_thread_info tsk - b ret_to_user + enable_irq_notrace @ enable interrupts + mov r0, sp @ 'regs' + bl syscall_exit_to_user_mode + +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK + bl stackleak_erase_on_task_stack +#endif + restore_user_regs SYM_FUNC_END(ret_from_fork_asm) =20 /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D @@ -210,29 +213,12 @@ ENTRY(vector_swi) #else str scno, [tsk, #TI_ABI_SYSCALL] #endif - - /* - * Calling out to C to be careful to save and restore registers. - * This call could modify the syscall number. scno is r7 so we - * do not save and restore r7. - */ - mov r0, sp @ regs - mov r1, scno - push {r4 - r6, r8 - r10, lr} - bl syscall_enter_from_user_mode - pop {r4 - r6, r8 - r10, lr} - mov scno, r0 - mov r1, sp @ put regs into r1 stmdb sp!, {r4, r5} @ push fifth and sixth args mov r0, tbl mov r2, scno @ syscall number from r7 bl invoke_syscall - cmp r0, #0 - beq ret_fast_syscall - /* This path taken when tracing */ - add sp, sp, #(S_R0 + S_OFF) - b ret_to_user + b ret_fast_syscall =20 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) /* diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index ec8a6e193802..b5d61b871dec 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -205,7 +205,7 @@ disable_irq_notrace =20 mov r0, sp @ 'regs' - bl irqentry_exit_to_kernel_mode + bl arm_irqentry_exit_to_kernel_mode =20 uaccess_exit tsk, r0, r1 =20 @@ -253,7 +253,7 @@ .macro svc_exit_via_fiq uaccess_exit tsk, r0, r1 mov r0, sp - bl irqentry_nmi_exit_to_kernel_mode + bl arm_irqentry_nmi_exit_to_kernel_mode #ifndef CONFIG_THUMB2_KERNEL @ ARM mode restore mov r0, sp @@ -348,12 +348,12 @@ ALT_UP_B(.L1_\@) */ .macro asm_irqentry_enter_from_user_mode mov r0, sp @ regs - bl irqentry_enter_from_user_mode + bl arm_irqentry_enter_from_user_mode .endm =20 .macro asm_irqentry_exit_to_user_mode mov r0, sp @ regs - bl irqentry_exit_to_user_mode + bl arm_irqentry_exit_to_user_mode .endm =20 /* diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 09109215dfdf..7302ed8025a9 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -1,87 +1,59 @@ // SPDX-License-Identifier: GPL-2.0 #include -#include -#include #include +#include #include #include =20 -long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) -{ - trace_hardirqs_on(); - local_irq_enable(); - /* This context tracking call has inverse naming */ - user_exit_callable(); - - /* This will optionally be modified later */ - return syscall; -} +static irqentry_state_t user_irq_state; +static irqentry_state_t kernel_irq_state; +static irqentry_state_t user_nmi_state; +static irqentry_state_t kernel_nmi_state; =20 -void syscall_exit_to_user_mode(struct pt_regs *regs) +noinstr void arm_irqentry_enter_from_user_mode(struct pt_regs *regs) { - unsigned long flags =3D read_thread_flags(); - - rseq_syscall(regs); - local_irq_disable(); - /* - * It really matters that we check for flags !=3D 0 and not - * just for pending work here! - */ - if (flags) - do_work_pending(regs, flags); - - trace_hardirqs_on(); - /* This context tracking call has inverse naming */ - user_enter_callable(); + user_irq_state =3D irqentry_enter(regs); } =20 -noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) +noinstr void arm_irqentry_exit_to_user_mode(struct pt_regs *regs) { - trace_hardirqs_off(); - /* This context tracking call has inverse naming */ - user_exit_callable(); + irqentry_exit(regs, user_irq_state); } =20 -noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) +noinstr void arm_irqentry_enter_from_kernel_mode(struct pt_regs *regs) { - unsigned long flags =3D read_thread_flags(); - - /* - * It really matters that we check for flags !=3D 0 and not - * just for pending work here! - */ - if (flags) - do_work_pending(regs, flags); - trace_hardirqs_on(); - /* This context tracking call has inverse naming */ - user_enter_callable(); + kernel_irq_state =3D irqentry_enter(regs); } =20 -noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs) +noinstr void arm_irqentry_exit_to_kernel_mode(struct pt_regs *regs) { - trace_hardirqs_off(); + irqentry_exit(regs, kernel_irq_state); } =20 -noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs) +noinstr void arm_irqentry_nmi_enter_from_user_mode(struct pt_regs *regs) { - if (interrupts_enabled(regs)) - trace_hardirqs_on(); - else - trace_hardirqs_off(); + irqentry_enter_from_user_mode(regs); + user_nmi_state =3D irqentry_nmi_enter(regs); } =20 -noinstr void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs) +noinstr void arm_irqentry_nmi_exit_to_user_mode(struct pt_regs *regs) { + irqentry_nmi_exit(regs, user_nmi_state); + irqentry_exit_to_user_mode(regs); } =20 -noinstr void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs) +noinstr void arm_irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs) { + kernel_nmi_state =3D irqentry_nmi_enter(regs); } =20 -noinstr void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs) +noinstr void arm_irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs) { + irqentry_nmi_exit(regs, kernel_nmi_state); } =20 -noinstr void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs) +asmlinkage void arm_exit_to_user_mode(struct pt_regs *regs) { + local_irq_disable(); + irqentry_exit_to_user_mode(regs); } diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index 81c1c3f98834..6c525a33fa6d 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -248,8 +248,6 @@ __visible void ret_from_fork(struct task_struct *prev, = struct pt_regs *regs, * execve() syscall. */ } - - /* syscall_exit_to_user_mode(regs); here once we switch to generic entry = */ } =20 int copy_thread(struct task_struct *p, const struct kernel_clone_args *arg= s) diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index ac7b98ae4724..89afe714cedc 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -27,9 +27,6 @@ #include #include =20 -#define CREATE_TRACE_POINTS -#include - #define REG_PC 15 #define REG_PSR 16 /* @@ -821,90 +818,3 @@ long arch_ptrace(struct task_struct *child, long reque= st, =20 return ret; } - -enum ptrace_syscall_dir { - PTRACE_SYSCALL_ENTER =3D 0, - PTRACE_SYSCALL_EXIT, -}; - -static void report_syscall_enter(struct pt_regs *regs) -{ - unsigned long ip; - - /* - * IP is used to denote syscall entry/exit: - * IP =3D 0 -> entry - */ - ip =3D regs->ARM_ip; - regs->ARM_ip =3D PTRACE_SYSCALL_ENTER; - - if (ptrace_report_syscall_entry(regs)) - current_thread_info()->abi_syscall =3D -1; - - regs->ARM_ip =3D ip; -} - -static void report_syscall_exit(struct pt_regs *regs) -{ - unsigned long ip; - - /* - * IP is used to denote syscall entry/exit: - * IP =3D 1 -> exit - */ - ip =3D regs->ARM_ip; - regs->ARM_ip =3D PTRACE_SYSCALL_EXIT; - - ptrace_report_syscall_exit(regs, 0); - - regs->ARM_ip =3D ip; -} - -asmlinkage int syscall_trace_enter(struct pt_regs *regs) -{ - int scno; - - if (test_thread_flag(TIF_SYSCALL_TRACE)) - report_syscall_enter(regs); - - /* Do seccomp after ptrace; syscall may have changed. */ -#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER - if (secure_computing() =3D=3D -1) - return -1; -#else - /* XXX: remove this once OABI gets fixed */ - secure_computing_strict(syscall_get_nr(current, regs)); -#endif - - /* Tracer or seccomp may have changed syscall. */ - scno =3D syscall_get_nr(current, regs); - - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) - trace_sys_enter(regs, scno); - - audit_syscall_entry(scno, regs->ARM_r0, regs->ARM_r1, regs->ARM_r2, - regs->ARM_r3); - - return scno; -} - -void syscall_trace_exit(struct pt_regs *regs) -{ - /* - * Audit the syscall before anything else, as a debugger may - * come in and change the current registers. - */ - audit_syscall_exit(regs); - - /* - * Note that we haven't updated the ->syscall field for the - * current thread. This isn't a problem because it will have - * been set on syscall entry and there hasn't been an opportunity - * for a PTRACE_SET_SYSCALL since then. - */ - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) - trace_sys_exit(regs, regs_return_value(regs)); - - if (test_thread_flag(TIF_SYSCALL_TRACE)) - report_syscall_exit(regs); -} diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index a39ee14ec5b7..35d2bb3cd2b4 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -4,6 +4,7 @@ * * Copyright (C) 1995-2009 Russell King */ +#include #include #include #include @@ -535,7 +536,7 @@ static void handle_signal(struct ksignal *ksig, struct = pt_regs *regs) * the kernel can handle, and then we build all the user-level signal hand= ling * stack-frames in one go after that. */ -static void arch_do_signal_or_restart(struct pt_regs *regs) +void arch_do_signal_or_restart(struct pt_regs *regs) { unsigned int retval =3D 0, continue_addr =3D 0, restart_addr =3D 0; bool syscall =3D (syscall_get_nr(current, regs) !=3D -1); @@ -598,34 +599,6 @@ static void arch_do_signal_or_restart(struct pt_regs *= regs) return; } =20 -void do_work_pending(struct pt_regs *regs, unsigned int thread_flags) -{ - /* - * The assembly code enters us with IRQs off, but it hasn't - * informed the tracing code of that for efficiency reasons. - * Update the trace code with the current status. - */ - trace_hardirqs_off(); - do { - if (likely(thread_flags & _TIF_NEED_RESCHED)) { - schedule(); - } else { - if (unlikely(!user_mode(regs))) - return; - local_irq_enable(); - if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - arch_do_signal_or_restart(regs); - } else if (thread_flags & _TIF_UPROBE) { - uprobe_notify_resume(regs); - } else { - resume_user_mode_work(regs); - } - } - local_irq_disable(); - thread_flags =3D read_thread_flags(); - } while (thread_flags & _TIF_WORK_MASK); -} - struct page *get_signal_page(void) { unsigned long ptr; diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index 968cec945a7e..26ec3a151652 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -1,25 +1,16 @@ // SPDX-License-Identifier: GPL-2.0 =20 +#include #include #include =20 -static inline bool has_syscall_work(unsigned long flags) -{ - return unlikely(flags & _TIF_SYSCALL_WORK); -} - int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno); =20 -__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno) +__visible void invoke_syscall(void *table, struct pt_regs *regs, int scno) { - unsigned long flags =3D read_thread_flags(); int ret; =20 - if (has_syscall_work(flags)) { - scno =3D syscall_trace_enter(regs); - if (scno =3D=3D -1) - goto trace_exit_nosave; - } + scno =3D syscall_enter_from_user_mode(regs, scno); =20 if (scno < NR_syscalls) { ret =3D invoke_syscall_asm(table, regs, scno); @@ -34,13 +25,7 @@ __visible int invoke_syscall(void *table, struct pt_regs= *regs, int scno) ret =3D sys_ni_syscall(); =20 exit_save: - /* Save return value from syscall */ - regs->ARM_r0 =3D ret; - if (!has_syscall_work(flags)) - return 0; - -trace_exit_nosave: - local_irq_enable(); - syscall_trace_exit(regs); - return 1; + syscall_set_return_value(current, regs, 0, ret); + + syscall_exit_to_user_mode(regs); } --=20 2.46.2