From patchwork Tue Oct 29 10:52:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45BD6D2AB20 for ; Tue, 29 Oct 2024 11:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2ECqHBAN3rDV9yo1zqeLO+ji9lVIoh6IkMKI7b6YgP4=; b=l5wRA8faf4QX3vL7qOiDtI9X0l gxvvldn00fFanqTbBwkPPprC1shE3UMWYgTIQN0ANlLyiEo6zHcbN32Mks7JspjSkhh36xO24n9xZ ELwVYyZAGHCeNEgxiwSecKzp+11nu6nbVBkXA2XEdGLYRRVKRg2MEBoXw1S5y6ADkuhzzp6wLuuW3 zhswGeMd9BmMOrF0eZE0rBTcCioSOzLxeWWkRLmVEAmaAOHOsfhwtQnmLGnJ6aFFSUSQ/uz0yivXV fhPPIJrQ0FsxUsTKPgAMhvNqBJHYg7DYlIi0GHVeO82bQllo4ThorPlghJP5Uin3mbEAXT/7e6ND9 5pqRSSgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5k8s-0000000ECPC-05mk; Tue, 29 Oct 2024 11:12:06 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqC-0000000E7CL-4Bae for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:52:50 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-539fb49c64aso8787724e87.0 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=lists.infradead.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=wdpZ/a5/uj46bApvahjqVx6S2CHPRzkV6bbWLHQDadKVOJZSR2MXR3tfVLOVHsmM0O Am4e0eXFL+0nhVMzJzFOAywJ0xc7p0q10qASkaYa2eOhl5Z2PcEyH6eVPdW1tp7KProE 51dA/nNrZTzn1BRnDMUaJBRofPAofQZ5LjX7OAf2BwpdIFVULz2dBL4g1QxtJfHTXUU/ 6txcAzz09BwZOzvBBrRlCyqJ40PC7+tQYgOAbTf9sj7/AgkO8oljGUFPuo911ezi6d3O 8N315OXqyuAxCd8RLkNpZrl4EsGBSr4lFpPw76Kz7J4hiRzvqP5u9S54hQWFkaTWouax DqIw== 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=mlkudchoc0MkGoxlJOW+ZU86Kl7UiJE2VfaZAQ2c0v6gXNBSRatexMYMK5C+nxF5hH iG56gldWxzbzevqdATVHQ9Si2d70+SiICWJehqdK3lfFHyIAXbU6lmtS+oXYCzptNPbd onsoMervwGQz6Jq3sNcRkNKAsAphJjQdCeHHq+Qh4DlNyzhhee+YlLXKLveczRCgtd8y o4VmjVdHQG8cV5Pz6ve7lvbShdtW0a3+09A3JAgU+hidTQb5NL3Z7Sj2wglQFp1NfJGb G1aUde3lTrYUeYLIbcIXfqk+xgEyE5Zhve9A5S5sKdpjeP/htNVk3T9edFR+hQQrI93d 7K6g== X-Gm-Message-State: AOJu0Yyinx6/SchekF+qcZoIb0VqDGXiVNyzLmFMoluGkBQHA0Woon+J qK/0bYhkOEL7nD+izH6ZCkMY/UNm5tHw7tF8U0MQVBLX3C9/wBSuFC/7TWj7yKE= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035249_085590_1FFFAF38 X-CRM114-Status: GOOD ( 13.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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)) +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/stacktrace.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 }; -static inline bool on_thread_stack(void) +static __always_inline bool on_thread_stack(void) { unsigned long delta = current_stack_pointer ^ (unsigned long)current->stack; From patchwork Tue Oct 29 10:52:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26DEED2AB20 for ; Tue, 29 Oct 2024 11:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=R4LTFu04v+ewJrCMf1qStO/yKKemj/dlkSOHqQ2h8u0=; b=QLoKd9l3N9iEldnfE5jc3EbIYf jgxHxomQk8SEdY1oV7WWLao6LAqyktIBAwk0FntHCLaGRqn9zVSQzDp2QeS3yuZnCM80HutPE1BCY GYzdSV7a1xlXh6DMjvfngZBJ3oG8E0XAeyUWOPBCH+4SLOC4gLIc0PV73HBKPd1S1VjwPxLJR8RE0 ENGJPaUCb/Hx/NNLREPC8OwyF51XWgZpDLSOGfO2t80m1qZTzDL2z9UOr44ekoeyzakjPEDgwcGgg HrCYryHX0TnX3QFcOiNb24/d8ct8orbqIfRKXLzCdltrzfFiYyirT3q8PqA/whp2DKMmD/EoJszK0 RLF1s8eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kAU-0000000ECnU-3JfO; Tue, 29 Oct 2024 11:13:46 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqE-0000000E7DM-3DcE for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:52:51 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-539f1292a9bso6177866e87.2 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=lists.infradead.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=qPlP35wx81RVgKN5Sz9ibIEeAJDn1dC9DZc98YtPLfwNUEVSIKl6BTjzGMudxFtFT2 OrTa0O/qvZZ8I5nXzqWaC4/qIgH0Wr5IdqZVuQRs4UeGMkVkc5rKThZ2aoP77dyvdXyt mCWWea0pUs/4EwhQjP4iJj8BS3hxDSwS7rbcAXX8Xh+PhEorYhVhyaX5kxXhlF0Ci2D5 h70o4jly/WMwIlI1NAHThNDgqsb3riV+4gaPEyQyfu29+01exsHYzlJtg9C/ThsRK5Ai sLrvmLi/qwg4cy3SPuhymM+ySHsYF1/rfRZSavYGrJDMT7sWq1vNMtqgiEJVd1u5iRP4 J5OQ== 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=uFR3U2BjTaF8NjD7Ra+3LHjPpISyo4Rx0SGKm7tbiijHpd2tSCXVp4HpHmKDL9s+LP 15pIW+pheskhuPdAy3wyhcjYAx0Pyy+uAXH1dMmeayBkzL4tJQ7EwAglcz4zRg5Ns6ky h8A65QOrOVi5cWJ5UJtwwj614vbN7sey6ARjv5t2/Rz85XYwSjEOl+OXLGNCQceb8Xg/ Pmef2LOQqSj4jOHSy6K1/6vWi40qszxDE4nYpvvoWAMFeeOw37Fo6VwXs4pt9oZ2BNMA pItUD9uCOgGsSMKH2DpIQnWRPg6Y1pvuTuVantpbrHe16vlGFP0nVNIvhXjS06GLskqM VpDQ== X-Gm-Message-State: AOJu0Yw1qq4CyGs/+v/g8GIjPGmi4tClWxKyDsIJtYKlWgPVpkoJKC8l 9MAQigxyyVNpfrZKuZtI4/SA6rzgpxAARpch9IjOFtHlQ7lev94llTMADuHDxUM= 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() MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035250_845185_A09BE5B2 X-CRM114-Status: GOOD ( 14.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, }; -static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir) +static void report_syscall_enter(struct pt_regs *regs) { unsigned long ip; /* * IP is used to denote syscall entry/exit: - * IP = 0 -> entry, =1 -> exit + * IP = 0 -> entry */ ip = regs->ARM_ip; - regs->ARM_ip = dir; + regs->ARM_ip = PTRACE_SYSCALL_ENTER; - if (dir == 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 = -1; regs->ARM_ip = ip; } +static void report_syscall_exit(struct pt_regs *regs) +{ + unsigned long ip; + + /* + * IP is used to denote syscall entry/exit: + * IP = 1 -> exit + */ + ip = regs->ARM_ip; + regs->ARM_ip = PTRACE_SYSCALL_EXIT; + + ptrace_report_syscall_exit(regs, 0); + + regs->ARM_ip = ip; +} + asmlinkage int syscall_trace_enter(struct pt_regs *regs) { int scno; if (test_thread_flag(TIF_SYSCALL_TRACE)) - report_syscall(regs, PTRACE_SYSCALL_ENTER); + report_syscall_enter(regs); /* 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)); if (test_thread_flag(TIF_SYSCALL_TRACE)) - report_syscall(regs, PTRACE_SYSCALL_EXIT); + report_syscall_exit(regs); } From patchwork Tue Oct 29 10:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93F53D2AB1F for ; Tue, 29 Oct 2024 11:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OxEtYMLSB1QX4C5qcE83rstSx0FEcAVbxyG1Gu9/c1s=; b=0yVRBbDwf5kTtohftF1ywB3b/Z WMAj1tlKjgH6OVyZokbaJ8fVkZ+y+m0YGmWWUQWipaZ6nZv/9B9cgm/poMF4hDhokN468NMpZoqtF ljrGoniUEkYGY3+ryTbUFnFEFDewOf9W9gYqyaYhiSEo4Z+PxkxbAXH2vtiUz45tnrRZuVgdQp/bN 7lmmibxUtXvTJ2Z44koREAfioANrCCrT9ysSO/f9leGjVFc9571k7BnCT62izrOzATUXkfZU4SR0S xF0UQeBhjScNhLAhmbmWtb/DRqCqNVtp3ZkJZggzVZmbWMBvfu2ErrybhRsiRINJaR+HawOlzZDO4 5afW3uJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kC5-0000000ED3O-1LL5; Tue, 29 Oct 2024 11:15:25 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqH-0000000E7E7-0NFK for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:52:54 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-53b13ea6b78so8220551e87.2 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=lists.infradead.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=R5Q/a1iEaLPxgsVKbnWU5WgMws3vd6CRff5aZ57MItHo2Nl3pL77raH/jZeGEF1ROV RGGThB8DrnQSdzQhz3iXzpkrMm75AawUDfCvR/CDY5wi5Ax4VUGcZ19ru3IsytsB/C1W 0X9OK66tdj8Y+/HEeUImsR0ef96UYWbPNbvH316HpQL10qtHHFv6m23nd36s82ta4Co5 K8AguwiAS2V8SNN7EOcUIitASNwYVenJ11FPQxlqJIXiD7S+5lB42U4XCBr547AoEupW 5RsXjHcH9Y06xVj5grFDC8x8H0vTC1gzIJttBzGCmzKlRViw4ImFAv2N89lIp5FIgwos S3tA== 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=Fm/GgebD6zQFJsJ2KC2FHs96aBlsagaLo1oluqOGJVIR8T1sr2Zw8PAKcPsheciknI oYkQ7aXfMAZhH3l0RXGs6BlK6/g3Lfu2Mcit9lUsOVcbJC49lXANeqbhUzaV45Qt86nq K8qQY0LXPIFch45SDPkmP/DTp3I/N9ZMfy603Y+40xDRyZHI1VdNWCPF+VD7ZGolaciD VTKgLZT6vOrE1izR3edoSlNXSKbFjQqh3BkqDvF2uMYk7hFpPMmL/LSb7XB4wmlWBWhm 1jJ9+j2fb8AhJ644Q47JbjD3RLKfGbfXqLhi33LIRlQl9Al+YR9X7ZMuuC1SRlIZB93r bIgw== X-Gm-Message-State: AOJu0YyTLG7rwUxwO/u+yZiLYGSID8f4A1FgDflkBQy67PDfJ83pia5I zXNlRnsLN6yFZ0qwcesDbrGFbjSieoNT1eDm2ri4N6NmktLh2UOOK23hGlSNUyQ= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035253_218678_FD8547F1 X-CRM114-Status: GOOD ( 11.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) /*============================================================================= @@ -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 __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 .macro syscall_table_start, sym .equ __sys_nr, 0 From patchwork Tue Oct 29 10:52:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64A0BD2AB1F for ; Tue, 29 Oct 2024 11:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=; b=sQLxQujrjpCPbjy++0VymxTlKU mXNJipT9s66vl2lJ8Z+3uN6nLbCYkLaW4dCO8sizQZHH0mB4z8LbAjutnh+0wAmzuthTP8b5Wbuxt lbnVRN4pg+ToXRjsdv7j77rd+7br5b4M4giFBG3ODaaN6/1C7ULwDMZB2uRLOn1ikwVcpPLdeplMF jEjEzj+sMiohkOsECltvhHwEN+dADcJ5d+51ZmRFlHaemFqanGj+Ia8cwmumUlvuz878RddXy2AsX 4xbf+oXTQN9gplQFMv6JFlxn6WyxDnu5UnxDRksZY8aImnjUBBCFVL3AiKzSTtoeWfIKTBydkIGND enWUiPfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kIP-0000000EDo4-3874; Tue, 29 Oct 2024 11:21:57 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqT-0000000E7JB-166N for linux-arm-kernel@bombadil.infradead.org; Tue, 29 Oct 2024 10:53:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=; b=TcImbAd94WcaFyjyZoS8uXHqSE sbtjcmx5IMJ44OvKbjU2oUdt39iwGtUTSy7UzA6JMSELY3XBfGLDfWrOeC+QLXbAdLBq69wbgiR0P 1Ry8fF1S1XpwW8gEsAeh1H5dMxQk7QzHXlY19dG3N/OI+WJb/RbmWo+w6EY6qjEzqaU3F5ObaLwEe F7O1sGxE4HBDgJZBO6z/j4VJhYr6+RBv/IfrrJZQeu8FQ9DGGOtvGi/TCB2rpku332PByeLwNzlOr asLwu2GS70Bq1kNl44Keh3kQj1eIIU+kvoEM0AoqzruCUL8cj7cZyd0+IjaUOvwLliF7t+dLuRN4J o9ssxDaw==; Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqP-00000009sXY-2FEQ for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:03 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-539fe02c386so5766361e87.0 for ; Tue, 29 Oct 2024 03:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199174; x=1730803974; darn=lists.infradead.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=HS81v0x3E04bR41TYaIjqtYuPmX6ucDAYoDWUwWJu/2lBmn8/ZLJCF7HL7e8h1mjp+ 3T/57nNnuTZ+M/s5NmKbKWiojupxuWPwJFrRFoAv6EcOqSt27Sw9Rf2h0NzFCzMYb70d RdvVKApmhx4JzSIqGHV3p3Xu1r52WFkrO7WsENSJR8PegcY2lhX0D23UKtlfOs8Ylj90 SynHFkue9HqnWyBHvwJDlMDe1U7+pJae/jbqoOMFTIp4VOgAtLaHV8VbHE3FZigdXhGo anC95HjoZT8WYhl9nX10eQ4ec0bqG1f9uH4e8zu/9K3ARUUY0ECbb02+fMXSz7DbqIYe SULg== 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=Kcd5Etw4ugzvqzhKxbinKSAwOj1yj2FsWTgziaG+CrPjeBho5wQfTA3xYvsNXY88qN XqlJPNx4l2hgJs1FikEEO5Q+MujUGxFG+L1JIo1ObiqvgoSfPtUU/UA7gdbJ4h6ZkA9T nBTwnEEJv0yYqlnPQQ7Y7pgo7l5Z9NfKgU35Tp2Xwtjx3Il/tRN91md6w0aQRzpFdvcR hU+wnesMeKTUx2lkxpuULYo1vgUfZ/Qa0/OgzsZAP/5AZy1JZIoTSrsk8OHhsyZeU9xS arcTj3OP27US9MX/poecyYmi7+TGZEzRM+HhI5nYzIw3tIomwoa6cyClftH9Hi4YTXlK 2MFA== X-Gm-Message-State: AOJu0Yw+DXjqEbrQlvBAIC8ihpDWGTw+85qST/TIvmvaY6cY0m5m0IFi 4vrJT8zSq8MKEbaY5BytZn12IO+p74rHRB4jy665uIs2K2KUeE/O87WcUqUalKc= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_105302_095538_F154EB53 X-CRM114-Status: GOOD ( 19.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 +asmlinkage void ret_from_fork_asm(void); +__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs, + 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 */ +#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) /*============================================================================= * 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); } -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 *regs, + 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 */ +} int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) { @@ -263,7 +283,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) thread->cpu_context.r5 = (unsigned long)args->fn; childregs->ARM_cpsr = SVC_MODE; } - thread->cpu_context.pc = (unsigned long)ret_from_fork; + thread->cpu_context.pc = (unsigned long)ret_from_fork_asm; thread->cpu_context.sp = (unsigned long)childregs; clear_ptrace_hw_breakpoint(p); From patchwork Tue Oct 29 10:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FC78D2AB20 for ; Tue, 29 Oct 2024 11:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=hBq7ng2ALEITTpHUSzldPQmOXE W1oOXrzs0g0XMdoc3hoqVqoKXHVtpVdHGjwfhk6KEtejRcjfTnbFyoTXJVYb5jhVhowDsY5GOZ2Ei FbTVKiAcLcO9a1jn3W7+L4BM8zA5S/brbrD7+SvWCJrxLy/S5dCJzeD91xpyhlfxpzmnM8S+V52KZ IGUpFJ3hzZZQERnC+jLbdJrmFHSBmuVizzRtbxnBgWRUdV6bMi76Fdzi/+vaUj2lkKgsxaGbiZnG0 qVnENTT560YD9RpVwybFi6B4JUlqPf96j2WIQ4TFyQTBSLttl742IezLfSq/fTHZdO81DeEekT1PH n1hDma6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kLb-0000000EEKh-3jOO; Tue, 29 Oct 2024 11:25:15 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqU-0000000E7JZ-11p6 for linux-arm-kernel@bombadil.infradead.org; Tue, 29 Oct 2024 10:53:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=nBIpKJdwp/gAe7GrGuPyEbykeN L1dGjS/gL0nfI9ARO+pXy4UyKG7APVNAXekmgvD+eukNhSYRf6Xi1a3RUgulDi1BcoXGjSI/+JsoH N66BYyf1A01jX1ZEmo9P8Rkz3FP6txT3xycnotwHczOL7Qrg3fgv823TpCOghrSjNPnIaWY260T1T bN/DegM1lo2+4wkTRsfniVVF6TImfHBsp9nyXePVsl+ltcJiXT5zAUtoVgW3Y5dzWTj4yI6ooT2E/ rk1Xm45M+GcFyug8/cT+zJbmrdEz7MoQrQV+KKzIzFKY3q6PrKS27h8DN8cWh1Nui8xdd5v5oROQz zjJ9p5ZA==; Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqP-00000009sXZ-3L0G for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:05 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-539f7606199so5690399e87.0 for ; Tue, 29 Oct 2024 03:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199175; x=1730803975; darn=lists.infradead.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=EdbC9vlAMk7qssyMhmnciTBXWZ9dsnrK9tCsg9DsNvprg10f3MnokN2NGvAUSDx6vw 8DvtRwuDQ/5XmpSSszMXT2HsKhKcZlrG+NbqyjjMqoh3UN7LNnVlML3VVSR1GYjF98UH nhjxTDoAEU6ATPiPS182zVxNdlsJlTpGDcnUf4rHjBvdfY5jMSTvHSN1bxPzSuek9T2g vzUUJWa+ryhQ/wAq8iuR1rI55faM+aan/uqBtqYS/1F6GmII+qcmraan2LWNQG2/E2vG RDT1OSJ3NQbKwnxHy6GbXoSeBv0u6k7o9IpMPd6pJFzUZ527O8OvwPSaPtQGgjiooVL7 wKhA== 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=C+GsCouuHyO+PmKTeeUyO00JNQQJyiPdLwICX/4Uk/M3Q6ZXAcC30Lc6AM/pz0C7yk XKsC+h3XIS0CX5LBGkjE+yO3r3+Eb3gNr8Tqua3N/Egr6O9vCMj/L23PmqNMCR0UXPhE uaSt+EnJRZ+mRNkbqY3AoGTnGgySzphR6KfxJFeMrOEHb1hYK77NmuSljXo2zCJo0rFL 1frM1GWuQoXAQEvYjjaqckdbKkjdw1R5GCGaOlGnTKlyyk/KWT+PbHzzsj9Nh6xDJu+h tFIYjxnhn0t7YTaOwWLBago2cho2/k0L13wdH70KJTDqq45uX92TqIHgWdpyqqw+aVom lBEg== X-Gm-Message-State: AOJu0YwNL1X5TtdPJ2En0CfxpWlEPRtT48tk9Nu+mixt2nACe0XG/JBE HEW2ABrfZwlcH8eIMp9QhKDjnoweEYDGdzL3K5jyeYxLWzRBk+fBEk5/Xw7On2I= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_105302_130343_9D7F0250 X-CRM114-Status: GOOD ( 22.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 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); #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) /* @@ -266,7 +260,6 @@ ENTRY(vector_swi) */ TRACE( ldmia sp, {r0 - r3} ) -local_restart: ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args 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 #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 handling * 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 = 0, continue_addr = 0, restart_addr = 0; + bool syscall = (syscall_get_nr(current, regs) != -1); struct ksignal ksig; int restart = 0; @@ -590,16 +592,14 @@ static int do_signal(struct pt_regs *regs, int syscall) } else { /* no handler */ restore_saved_sigmask(); - if (unlikely(restart) && regs->ARM_pc == restart_addr) { + if (unlikely(restart) && regs->ARM_pc == restart_addr) regs->ARM_pc = continue_addr; - return restart; - } } - return 0; + return; } -asmlinkage int -do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) +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 thread_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 = do_signal(regs, syscall); - if (unlikely(restart)) { - /* - * Restart without handlers. - * Deal with it without leaving - * the kernel space. - */ - return restart; - } - syscall = 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 thread_flags, int syscall) local_irq_disable(); thread_flags = read_thread_flags(); } while (thread_flags & _TIF_WORK_MASK); - return 0; } struct page *get_signal_page(void) From patchwork Tue Oct 29 10:52:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C043BD2AB20 for ; Tue, 29 Oct 2024 11:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MQAt5SKeBz56FAHiHxrYIQX+VEnQ+LorFKx32LG+SI8=; b=VFaBhdHxq9hMQRfJyrV+GTVI6e 0zSSTJj+8ug7CJ8aodNwOM8KLXwPWFwxjOR0Y95OkfLviUpCBywB74p4rhETc3G4gTLCiE9R7ZJFM s0XJ8AR21h6HEllUr/Si7+x85xSoJVb+ZMHPYhzysQZYeFUVaLsLSpzIRb0dpSWkvcGX7Evr3fHTw BXzqi5J9fhSHYpb6dotZxFVVwa8Ct5nOA0UBff5ako5xChno8TPajVs7BLgnO93CiE5UMwnNRePXU T4U7RFxn4PaBT8MuChJUxuaHeGEjDijCHgIQSUXx+qWkXCOgEsckJclmbUn6V00IKEsxc9KuOg9jU 4UjvnwQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kDf-0000000EDFb-19oI; Tue, 29 Oct 2024 11:17:03 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqM-0000000E7Gn-2Vux for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:00 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-539e3f35268so6247323e87.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=lists.infradead.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=xSxR0u58HrhDxveV6NMFskmkKlg41xOCNo0/HOkqC0qxSOpfjoAWOc+L9+0ZdzAiEr BipkofRc72y2aaRFzXfSIpos3kNkq6r0HrQ69poawwG+ZKiRZ5mObPS83+nNc7PeCJM/ 0JFZSIXwtxIQW0+l8Z0Z0gj6PBX+TDZLPQf+K3Mw8rfzHlxVFK9uyYe16APViImAbJrv voXOr8skuBHV1PonEhCYbID31ejDuGg+ocrPmpm6i7Vl4W1hO90jY+bLvuaKLoxRtGQA UCCXIo6V1K3kGbulW/NSkAEKV2qANXOSDcBBwQMrm8csWlL8cc0pgWj/eXGl7ZO7pOI5 Ywhg== 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=kX0KcknFo+ncvTMjXbmh55E5/oygTmIMV6kHFkQ7vDZh1ul8/FFPGKMCmfVeOgsAJe QUwj/S70dSZy+IsJqHUbJfcvbaZHOUqTqVcmhZatQgQg3n7MjaHGVqmecTPZqR0GRhUR 1XKVmskznDVvke0HgbrH0wttT1UnGgNXRzChlNHtERrS2eiHxt5g8Hm+JRPz2sLeNS1q DRur6yOFxeKDsdl+Vs0I4u32h4cw8qEM/6ffD/IEGfVJt/FZOoj9KrneZVV4+rwNDgXf AyqGUTwZA85bDvroAAeCSVIIH45gfI20ipyuC0X3gfkATWEyVg4IKUaGUv4EM5y3Drum I9Xw== X-Gm-Message-State: AOJu0Yx64IDnth5GcOoKGArm7gxfY+bGmbLY4B2WBzPcdfzLqHVBcQUJ OT1E8dQKS0RAMagKKOo/uU78nVSu+ar/dC9D5zWJ9HAOPipcfae5iJISPl97IQQ= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035258_716711_328A3F07 X-CRM114-Status: GOOD ( 27.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 @@ extern const unsigned long sys_call_table[]; +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 = -pg obj-y := 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 KASAN_SANITIZE_stacktrace.o := n KASAN_SANITIZE_traps.o := 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 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? bne __sys_trace - 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 + /* 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=1 + 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) +/* + * 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 /* 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 - .macro invoke_syscall, table, nr, tmp, ret, reload=0 -#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; +} From patchwork Tue Oct 29 10:52:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE0D1D2AB1F for ; Tue, 29 Oct 2024 11:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=; b=xNDl/9EOq7MYsFCYA/6eL/69C2 8r53zHKXsCvZfNlTiuDvWyHpem7jh4KT3lazhI7ZqNsbXK0QnndRzt9a2fig/VLbmi0iWxIQId9K+ 4Dm4nMI41WZKDRNuGG0IGmKjFcY7XLlahVTuf+0VT/sK14VuaUh6teTDmnBhU6CvUwsdS0ac6/RJK yMvqg1lhqgfUkIOrDws6ozVUetM/Es7JDOwPXArOpYNi2LXfd+5Lz5jbjlwM2hGp4Vmu5ioQz8MDw DuXqni9wrvi8B527hsBNUxxRUZRZuGs0lQDOQV4GRLUSd/4LjDDlaOo9ZEmnFTuErWq/v2W+WHPw8 1KdGkwbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kFH-0000000EDPV-08xq; Tue, 29 Oct 2024 11:18:43 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqO-0000000E7HP-3tCy for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:03 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2fabb837ddbso79073291fa.1 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=lists.infradead.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=JQCklD+UUr0TcxgtjAtB5fLeIx5YRcFgI3UlLX2xtTCChlu4+KmDrnu9ILxny4L8a/ PZyBMrZrawOijtWzP01vUTTFTnm9dd6cEaGE9GeyMHXDnlO1Ljzh0a/cZkc5v2aoatJV XIlk47Msd+l0tJuYKSPTSBnXy1FCs9iZsGMDoje88G0bGKsKeJFsdjfyni66LMcF5qtu Pc4gW4/qzNxwgyz+nxx7w0VQ/z5xkoYfLegDK0wftUveOrZt3kt6zjbxZJahlctO1OCd vU0As8bhZ6mO2gcX+nfpaQ+ewhazGIQ8HdTFB3Hd2tJ/S1v7sz/tIct1/EaZsa6lMgPT hivw== 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=I+Wsd0BZPzmKTzip70ucXJpE4oBPOYJAGZYg9kJH+uHu9afo0qoF+YYHq0gD99IwmS /4fsa5kazumj3rEhycJa+Y0LazYstxQOhgFM6ZvuioQfsnFbWt0337IOVLw3ofS9cTyt 4ouyQlU2TK2nlKBjDkKXUMMRhMAq3ty0foeZpSyRWJiExrhtP5MKTgYbKwXJQlBPZJWt KmoapflzZwM6fCfaI7Dmtes3RFW6JpGMmLZrxaBjmOZDbfXfWiKDPBLFwYYBtTi+SsMR fjCEAhFlz4rZlttcJW/nuF5BiiclizFG09t0ooNv+KSzf0R14OLHfFXIDN+2ztCXn70G KI/g== X-Gm-Message-State: AOJu0YxUcnEzTkSanG8r7whop53IpTQGaLs7qIUxw+n4bgVhiVpvJOmz CgfKeseZjowQ/xqxtes4MK2YHifdroUWRexNDc7op0YTOfD7U2Asc9lK6i8jDz0= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035301_018562_7CD2BDE8 X-CRM114-Status: GOOD ( 17.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 instruction, 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 #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 __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_regs *regs, int scno, void * /* Doing this with return makes sure the stack gets pop:ed */ return invoke_syscall_asm(table, regs, scno, retp); - return 0; + if (scno >= __ARM_NR_BASE) + return arm_syscall(scno, regs); + + return sys_ni_syscall(); } 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 == -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); - return 0; + if (scno >= __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) != (__ARM_NR_BASE>> 16)) return bad_syscall(no, regs); From patchwork Tue Oct 29 10:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26B6AD2AB20 for ; Tue, 29 Oct 2024 11:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8kAN7grhcUpbCDFoKucfYZVBg7IClr2vppXay/MPoLQ=; b=hYuw2HeAAQXRYLKMU+qu/0B12f 3MDQ/Ew1Im6cDI1J8bTeTOy3r8FkFsVafoKybNOF34VEQPM+93SOqsfsVVMqqHO3C4LVJfrpPv30Q NHyEPNIN5iAaCXv5yVMlUpGPfM+f5SZYpJ7mAGdx6nU9w11VM4SRDNaoG7fG35TNb6u/+Nd/AfyF5 L9n5bQT9iyU0ElkrQ/pAi0+6Ss/vhLHJ3DfoJjGXW1fIDuXCuw5w+n5wdta/cEoAQkWrJpKUYl3tl NeCujAnCLebRDrWRBjoiuu90JreTmfR/ce4zlSRUqt4Yvhbgs2zjwM/iIjzPe89UCtWZ0OaUrkIgo ShPKvEJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kGq-0000000EDcg-1y3Q; Tue, 29 Oct 2024 11:20:20 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqP-0000000E7Hp-3Zzh for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:03 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2fb470a8b27so56722481fa.1 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=lists.infradead.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=zEPZpwrAoEIdW7rjRu57gRW1GFTO56dsWoVWIwlhQgUySkM20SffmIH8r0HdM/umbw hNAKs6RZz+pnhc+Su4t/MnZCKIhgcosKNonOD0oEmqVdGg5I60AikaGl0TeYs0Rjra2z ISSpqRcFbMl6B4jy+dA3015jWdY0wOmxiPlwMv/JQN90N/Pq9yVDmcAL8C/xIqDOK6jO B/xl5UCAJti7Z0rFvT6h1J1MXFXAoDfWryK9nTbV7gDpJnxw+7ZCO393FTb6YyFrS2pS hTw29JZUBzKoEpLPLl+80rgIlUsQndNrm9kNEPYBgCrDW0WRXQeBtl4RjZQ4mXGnHjBF ogjg== 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=I3Xsn1DbXrliSuCVRoqQq8OS9JtdwLX7XH0IGo0f67rWWffMUnwajccry8i95kkKpT cvCTs+bR15wUy1daSdh1hoDxHT6MXmLZNXXvUt2byGF7bSUwQibv2b4BgeIjfBqaMcF6 c7hC3OxthChjxYTLtdGjnu5c2KykNsPpLxje8iZctyP/Zq4DcctqyTH4sVDkqHbEEnpi j1KgFmecxrHuVC/VZkuPfTOXS4xA8Q5nRWzdhRauQsc9lps+6zo8EG30EQsa91wKbork zZk+7ZD4w+aEe1A/QErCe/FY9In0CLXNgjj7jSOI85o3LogxYAl37x4+dZ6+X8SInIFl Yf7Q== X-Gm-Message-State: AOJu0Yw/phFX2A+ODozVkGT6tvyRLNq1qLj7WIaSL7I34Df+XSmAl6Bx DdA0g1TlQRS0Cr8rRPmGAGQkZ0KAKHaFD0QM7imwm8mhnZCoBw7MYPlTiCUtS74= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035302_041455_AE97FF78 X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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[]; 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); 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 * 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) +__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp) { + int scno; + + scno = syscall_trace_enter(regs); if (scno == -1) return -1; From patchwork Tue Oct 29 10:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0F38D2AB1F for ; Tue, 29 Oct 2024 11:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wP1nC9llP2df/xsfs1zPIJ3oMrkiGOdpltxFcj+OFqQ=; b=a8Qxyo9k9WVUmE79+qgivI9QVe T4IXxWCI1WqBMe2xtqoK6Egf3pR0odnoVj1lWkXTHy4CXWf1MDVOhTHyamEnvhef/2WBdZRGUWSOx WTFC7z4+LHVQ/wW8+NoQHl9tEZ8c4pDkajaaPsCdqL9SGKDlhoXvZMtpaDeqC7spRdYMKlXG83CvA Artuv7/b1zVK6r9C4qLOXqQSqljobTJloWj29QaZGk8p5XirHymQi7WQkJmlC1nJgwtjpCxHs0inR t0143AmXyRGBX2OIwK/Ha+w4y2KghKl9xNXyx/HK+ES7amGqwGSaVfFIt5yfXH3qrNrnCUQB+Q3Ra clh+laIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kK1-0000000EE1P-1hBt; Tue, 29 Oct 2024 11:23:37 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqS-0000000E7Iw-1sv1 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:05 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-539e63c8678so5347726e87.0 for ; Tue, 29 Oct 2024 03:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199182; x=1730803982; darn=lists.infradead.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=EJX49Ninl9sMpGdBKfdx/NpOaZisMWj5J/1oSw4RoavjSnN2GXjo6BWO4GZQwIimDV gIl6mguk/U3PuOFrT0ftp36DlpXTRlO/wXBs6JRkUDPMrJCwMdpcQhHh29KboOPikBBa myoZbwqUk4SKiH9xcCWNRT9RbC4KRRSW6v5nBwujuKxpzqqjGj4lvuW0GMb9X3/wZMDU NrmmxHeFXpPfK56/t22jpALmTRXm8uM6dXnIPPKKVEA61UKD9sUbzheuI35C7kyyKCyr L1CI8TuLzHJ4gSfKKmGt6PnjfyCZ+IC1AN+Mnlwh1nNS5p8TI3CqB4d5mxiwOhRn2Tt4 lVpQ== 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=fveUXi0HCcVW3hXwm9ajvFeDhxVmzYvtCI6SxNqodblI1dQAtAOz/1yGTza291oZV9 Aym+scrJsB7lUCZv0HNbDrzPINfXxgbUbBnBAPj222D1P2fChMxjFPA6sN9P5yEXsCMQ tvIg4iKFf8U4S5cc8F60Y1LGln29yrDUnKH0stzmMP+ihFM8N9mc75P84pH6nblwL4AC t0YFkNqoUER/7FRRf8t//lyDwlLpoMINUqr7nJTB6vknVoJkWXTipFxX6VciT5+OgA8b M6fQNM7tFiCxS1pDbuMOGokVrUQP1nHKC5ayvgqLLaFoXKVgnUGWv0WEb94mjiee3/TB A42w== X-Gm-Message-State: AOJu0Yz/TYuuuiJHNNY3kaElRa0bR4Xo/Pxsx1PL32h07iB8utCZ4gc3 DdF+BgaxKG4nvpjCMD1Nlc6V8ipkRJHKVM4y/cMbdljRkilThAvAHdbW5J3LHdM= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035304_525027_F0C7767E X-CRM114-Status: GOOD ( 18.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/thread_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) uaccess_disable tbl get_thread_info tsk + /* Save a per-task copy of SP for sigreturn */ + str sp, [tsk, #TI_SP_SYSCALL] adr tbl, sys_call_table @ load syscall table pointer @@ -377,13 +379,15 @@ sys_syscall: ENDPROC(sys_syscall) 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) 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) From patchwork Tue Oct 29 10:52:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 202EDD2AB25 for ; Tue, 29 Oct 2024 11:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HAeVmp86zd6G4zC8AXuoLcHe5Kdpm6JlP18N2B6Kh/4=; b=kssxCOXKNZFYb79VBditm8Jzro zYwV2OlXToiCL8xHT50Izp3GUGDfRJO0EMEnh58YLrbdghzxTeZD93z6DZ1tdPNbGuUeswclNxaHD XkgTNCnDzYrnTCmQL0JUrdIBeuvUBYbTdYol+sdWtPtPJJwpurPDu53Hi+x1sSVQyUNA7Q9+O0g8n HjrgrR8rzYgR96mOs9iee12DZCUPHdnl+LrknWcsGHBoG0V+LWPI+EtR8VYMX1QAFJkpDs9zPsqZ0 OlPD0FyC0c4QF/5yt2adNTUd4XSjeYbvyMaP68tHUMFP03d63xt0MkTILIzIXniESdCPIXZu1HNfc 1rYk4YVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kn3-0000000EIkA-3Ugp; Tue, 29 Oct 2024 11:53:37 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqT-0000000E7JS-2WjP for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:07 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-539e4b7409fso5072543e87.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=lists.infradead.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=lI81DDmZzMmcWHpbeO2QCCiNUrY3pRPAw0yJexotC3hD2QDkMFoMs18lWP4IQkOn0B ZNUuIxu7kh76ssGoMWZhLquMtnprgCTTz3MJBOI3eyBvnGMIqbuw/++WurNaVtvwVGbq wkFSrfBdpeLggSMdBb3M9iH6jnzoL+ayIwgOOx8Z8McOyaJs2iiinRjpwY+SBI6kEFus nWilEoK0rZNzK19Ojq0ZAnjqnoSkhhZ+t9+DH7Ok+K6YxKdyKAogNl7IX3mZrBz/bCEL FNNapnbOw4j5GRQd25eVXkoIOs7nistjvq8Ed9Z6Y3kARTf4mr1q/QrWDkwui/QLckG/ gKJg== 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=Xn5aeBS0yaE5XgUBIQGw0VBk1Ax0m5lkmF9vdpxL4UytQo8qGQ90Hk30VKUVtG9pPM 9pGQmQXf8v+I2/Fd2wsigvQkwwkKzLvo4bJaDeMCRBRAgav7soy7mHVOEpfEHJ51gpDy JGHjCWE3ZYqqshlFcV2qb7tZKJXN8F2520zo8xew0v6lWeQqInFL29+7v7nwRRQZw9S2 nRO4ad5WQZX8KwXeQE/bVIyXkkRDCAFg++lYds6vb4Jxu33J2Rsvnjiq/JPn4oqMWQw+ OJ2OUg3rvfTBon/J/X808IU5pisg1y2Tek5u4jGcz686kot1QeTjyuAw6di9Vfjj2qZg oR0w== X-Gm-Message-State: AOJu0Yzj3MBbyfxoHK++Yy03miJeXw2r9zVtsYNRJlY2ZLeq6rKC1m+a r7jDtdT99cTz+kSmPxISFe677szTbRxGrg+TyWOiJKSwsvvJ32Wddl49nAJ4TGY= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035305_684689_27B22823 X-CRM114-Status: GOOD ( 21.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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[]; 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); 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 -__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 .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) #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; } -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_regs *regs, int scno, void * return sys_ni_syscall(); } -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); -__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; scno = syscall_trace_enter(regs); if (scno == -1) - return -1; + goto trace_exit_nosave; - 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 = invoke_syscall_trace_asm(table, regs, scno); + goto trace_exit_save; + } - if (scno >= __ARM_NR_BASE) - return arm_syscall(scno, regs); + if (scno >= __ARM_NR_BASE) { + ret = arm_syscall(scno, regs); + goto trace_exit_save; + } - return sys_ni_syscall(); + ret = sys_ni_syscall(); + +trace_exit_save: + /* Save return value from syscall */ + regs->ARM_r0 = ret; + +trace_exit_nosave: + local_irq_enable(); + syscall_trace_exit(regs); } From patchwork Tue Oct 29 10:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4593FD2AB26 for ; Tue, 29 Oct 2024 11:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+Ojsf1FDD3J/q7BWA6tzk7mG2LcyH7oHP8nC2ES9d2U=; b=DgTeUKorgJAPfpHSR83g5ne4qN VGJKSsymiqGcBYd2QyfsJZKP8yW93Zlou05rgXZMibRfqYAeH0g8dfxZClL2vUslg2DvYQHDg+40z AxsgD+bYFJDyTJvyofIN6hvHmSFvEPHVx6ZV12yVzw70AZrMoQerkjYCZzupCcMzSxiBLNeX3EN7/ d0eexbaVTk0/ISlOS9YgzixZLoU4qJK/bnG3mgOdsB/GA3nmV4sITLMSKS2FeZX8gWFpNeDmw4vEy 2azQGkiRFHI4xSQ4ribRQvediJIUYTgE3pDHYMEbob0K6d4fI3ofTlXGomUVdtG1FUZqZAUv/97yN rn8/rF2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5koe-0000000EJ2n-3euV; Tue, 29 Oct 2024 11:55:16 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqW-0000000E7KB-1doP for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:09 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2fb599aac99so48690071fa.1 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=lists.infradead.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=wR2l9TpzURDMXhp9oC1YfmpPbGHteKJlCsYcZ2cY/KARqUzNUi7FrNp5yc6ybNvkaT 7R5TgrFHCUGMQVW9lkSiY+YVf1Ymh2bNMUoSZYwdY1043tyzUOnyk5YIpfQGr56PMzZ7 L10A5iPzOWsfBPIkaNQggbd4UmsH0zcLlvIxJBS1QLci9RK/NA/KEuaKg9bChtmJDahF GYx/MfRkhFFpXr3AnG5MwDObR1i3fajv4ES5wbnDYGzLTYY1+f6sC7woJiStZjseJwsX kpeKTWu+IqRONtIn3a7hbz3Of/t5IyE3Odo6hXYvCjPguWb/vHMXtXvTcaNTtIIl+7qO j7Jg== 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=BelHtTPlAMeitT8rH6YI2xBS8mFBTb65eTNgqxna35vMFb+mo3OZq+fmyFx3dNvMOo bg1sGPfqQoF3p6UsKnskZQfeQMNe/5B3Hn6UEr3v7+Bf/5c/FQopPF6RdpuzpW6O8hDI 1vn6szjr43JRa12DuZmNiqjWojFEN+cN+j4IESXrO2e8TVCZnT6Z4B2ycszsPfF6kF3w HnF4bSDeV/XQL2dcpHWPkDStuK/3i1jekUFpi/7EqHz26A4AzhwAK6sFOJet9eofljQZ 2f0PxLBqmmrnmyn+jh3NyYuxLEMF3f/uaXncpGJsEMWfrArr4HUSDrl3msSLyOUnOS1f TMTQ== X-Gm-Message-State: AOJu0Yx8Yp3nGrLngW3Q+vG0MhzUBdNvaMiSDEDlYbfDT8/AVPiy0WV7 fJIbnn7kAL9fmykCGrOub4bU80wctBOnhVRwhFWzla9oPuEH1URIwQ3nIHcW8Lk= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035308_478531_CD8D9D1D X-CRM114-Status: GOOD ( 24.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 @@ extern const unsigned long sys_call_table[]; -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); 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 - restore_user_regs fast = 1, offset = S_OFF + restore_user_regs fast = 0, offset = S_OFF UNWIND(.fnend ) ENDPROC(ret_fast_syscall) /* 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 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 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) /* @@ -289,20 +285,6 @@ ENTRY(vector_swi) ENDPROC(vector_swi) .ltorg - /* - * 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) -/* - * 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 -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 >= __ARM_NR_BASE) - return arm_syscall(scno, regs); - - return sys_ni_syscall(); + return unlikely(flags & _TIF_SYSCALL_WORK); } int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno); -__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 = read_thread_flags(); int ret; - scno = syscall_trace_enter(regs); - if (scno == -1) - goto trace_exit_nosave; + if (has_syscall_work(flags)) { + scno = syscall_trace_enter(regs); + if (scno == -1) + goto trace_exit_nosave; + } if (scno < NR_syscalls) { ret = invoke_syscall_trace_asm(table, regs, scno); - goto trace_exit_save; + goto exit_save; } if (scno >= __ARM_NR_BASE) { ret = arm_syscall(scno, regs); - goto trace_exit_save; + goto exit_save; } ret = sys_ni_syscall(); -trace_exit_save: +exit_save: /* Save return value from syscall */ regs->ARM_r0 = ret; + if (!has_syscall_work(flags)) + return 0; trace_exit_nosave: local_irq_enable(); syscall_trace_exit(regs); + return 1; } From patchwork Tue Oct 29 10:52:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C38F5D2AB26 for ; Tue, 29 Oct 2024 11:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VzzrIJOoccLZThZLp3kOXktHyMNXE6/2voWdPpMOjWQ=; b=hvjBVTlXUX5qrW5dqUcHY69Veh sAxM2Re2DlNAVHiNxzsD5tHxy5qpvLUVrTu7czN+Bd+k/IKiX2g6l4gJ9dVndtjcdHhWZAXN85qvg gED/2X+Lfnxt+x9p0XmNmrskFbUPurjs9Wx4VpZiGWVp/emjWWdWQu5MwNfDfKdvKtmSAz+s48Fge W2f8MkmE19KHJ5vJp4Gmw4/e48qmOJVSp4GEdodSLYYTl+n90bRKIh4yWKp1VkmLKuv2V51mwmVHd upHAvr0KBPXuWzqSS56IEFMTVd2o/t0x91Bmz7aQ3skEIKYQdTK02J5oSO1j801DpbqPj+Ke8z5/j xwQZ8JZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kqG-0000000EJS4-3Por; Tue, 29 Oct 2024 11:56:56 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqY-0000000E7L5-0D9G for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:11 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2fb51e00c05so77807011fa.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=lists.infradead.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=MCm5Sv//OqtvW4XR1aJfHpEvS98UPhDWUWsu795Ll4u9jg+DaCFSeNBKa+QmSaxhGJ A32wTLMO5VQ9Id0l2UhDdqEX3jBIq9NeXKt439hRHArv3qjYrF7Al14XPALfnMqJkKb2 3qYe0SlCGGAKNbAzPg/QNvCCbmE7RAWwgmH3WWaH5EOKxedA4sv2aOsKxv8lUCfAEjpN Y4+tr7zoyfNMIYK5QiaHe49atUtCRNkE8lcVlvp6Cium4PNJlZfZywwGNz5DdOgfalsi gsX4mhCBFGKPcaSG2IXUxnK9sozYZFzmkJMnGWsXl6hvbiAvOGn0+9O6WxnMfboejxMn 92/w== 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=kLj6Go4um4RmRx3xPS73FTXYpPb+ThAB83SYSJ9t4+Gwnj3Q6AomfaNC+Omchs9v1n Ix8Z/win62eSy4gLH7TKfeU5+0RJYBUPduNo6Qk5hvifrvLWJceZAMJG4lYC0uZs97Bc TtnOxeRBtOghia4HirM0KBJa4BwvD811hOh1s7FbjdjwDbbGW9n4ubzj/CSGXGSesrXy dXBoXwg59uk5gsncXAAUPEAYD2et8ceWt8hGumzrl2ly079hQCvCAKfFx/78ou5bhdKR LbyV/wGSRavoJXnJFfEPfitqX1qUySrLrqOqaSs6kwV6/CChb5mfgBUkcKVp2YG3WUer bCGQ== X-Gm-Message-State: AOJu0YzgQ+qbVjqkGcT6OHLi810AWbdH6rGx1HDZzfHQpRnovRe+OKxP zcnHrHl7VayMS2dNt6sgWo518AF4dZw0Ykzybdcaz75cs9NfMp2iZ0Tv1ghei5Y= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035310_252053_5AC00FE1 X-CRM114-Status: GOOD ( 15.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 @@ extern const unsigned long sys_call_table[]; -int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno); +int invoke_syscall(void *table, struct pt_regs *regs, int scno); 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) #ifdef CONFIG_OABI_COMPAT 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); } -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); -__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 = read_thread_flags(); int ret; @@ -22,7 +22,7 @@ __visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno) } if (scno < NR_syscalls) { - ret = invoke_syscall_trace_asm(table, regs, scno); + ret = invoke_syscall_asm(table, regs, scno); goto exit_save; } From patchwork Tue Oct 29 10:52:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854800 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31B8DD2AB29 for ; Tue, 29 Oct 2024 11:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=; b=F9PnA/Ipx8KpPhyFKDvnrwBWCj Vj1V0RO6u8d7ad4ZV3xq7qRkNu/qz6qpLM6BIvQV1uonkadvPju+QXdFx97UMMnst5KFYBpptFXfM F2vv8VnvWMJ6JxB6zauE6BidI+ODAnMY7O0ymlrfYl1PPsfXcUoUUAJfms6qnurpseYn4rdcjD4Ak g2/PQ9oxmdQatQ0UjRkwrhTZyn0LeBlb6YApjU4U34dJTJoF78aVqszcaTpbmviU98TcIkCCEMXQY CIAYVK0WsNrXzCq+K2mbbxsyarNXnC4syJe+1mWupv1sGMuzAVpLLrOYURPV8Cn3+ZgLN+hbsXAZQ V9VJJezw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5krr-0000000EJhb-0nb3; Tue, 29 Oct 2024 11:58:35 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqa-0000000E7M4-06gu for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:13 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-53a007743e7so6043972e87.1 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=lists.infradead.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=AaxaRzYNY6EWvZ73zYDt7Jg0afxLBDq78MWo7WZ/ia8epGjcxpHkl0SVaGsQO6vw1z QRdR03l+3Kv8YNdJIziCaS6yJFe4DlgPZJxCeofF+8p8X/EQsNFVN9o7MiNuktZQ4kn0 pgS9gmu9nGhkmpMHqAzmx08qkkTfquqUt96/0hssmyDGI7OXzWDbBShd6ztPAG0lGOH1 tlpWojtyREhdExeuy9yG99t+bIl8bxH2AHb9WFKJNjRTP3PljHa+BY5bH806LJ+5z18k OSK6kWBJklePIfBVpe+MSWHRQsxFLTHiQC2P7jL2qBiclLB4zdq1XplPulc3YAEPAHad d6Bg== 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=PBpA3YOQYSx0lFjGdGFP5om4y6WXR8eWOsErKMYz01KOrZhMZOYJpjehFGsSpRamSx 4Q2YxriXEj936huUgfICwtpwg+UpCPqdrWWqOPe5L0+IsyQS/FwiRmh8ecFeOLPfhr5o Se/CQmKiEYzpcMad8b1KRjzwxHu0+jnQeFrXNwbt3vpqEz7nmvLIoa1xQEkC1kXEFqk8 ENPxHIyrdAYvWZIsW6pJKyo/Ovcy92A/1GpMHB063wP5Faxs5uqshm8FwM9AvYOwV8+1 qZeHjyDE84PP1srQ35CrYph2V0HrqOJGx/L1tK1EdknmZxwqqkgENPaJHdRqU8tJcU7m M3Ow== X-Gm-Message-State: AOJu0YzpFgK70OzKzz1jHkA9z+TerL65PFLQS1zKzpqBeMIrPGvOED1u H40LCYTMJTqiiPGMfDVd9iXykmXFDj4jabOxRKay4dJdx6c3k3ag51rNU11wtAo= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035312_217754_227140E0 X-CRM114-Status: GOOD ( 19.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = -pg # Object file lists. -obj-y := elf.o entry-common.o irq.o opcodes.o \ +obj-y := 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 = 0 + asm_irqentry_enter_from_user_mode save = 0 .endif .endm 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 = 0 - ct_user_enter save = 0 + asm_irqentry_exit_to_user_mode save = 0 #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=0 enable_irq_notrace - ct_user_exit save=0 + asm_irqentry_enter_from_user_mode save = 0 /* * 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 /* - * Context tracking subsystem. Used to instrument transitions + * Context tracking and other mode transitions. Used to instrument transitions * between user and kernel mode. - */ - .macro ct_user_exit, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING_USER +*/ + .macro asm_irqentry_enter_from_user_mode, save = 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 - .macro ct_user_enter, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING_USER + .macro asm_irqentry_exit_to_user_mode, save = 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 /* 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(); +} From patchwork Tue Oct 29 10:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1677D2AB24 for ; Tue, 29 Oct 2024 12:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DsQ2/1OD1833y3AwH5IJOrZR5jmPSoKtfSG79U8bJN4=; b=aRRr5VMOzCAeMnQw+Okj9G0rhh dus1V/+QU8wYU09WhfnlLAd02GLECEkFCanMrAVYDKy5yjuHFQB2QmI4SOlo+/lfRiEGan13KILbV A1AR6+xl1e4wbtUOb5WaMZFdld/8S+lkHqrdMZffHNSH0tugoV4kLp57f8jj2HRE+wGAy+UvY60XN cjg1KIcqlg7nanFh0gARoLvvrxjuVvm2hEMiZcyRVRufRUXdotAcMZttQTbQ0GSAkMvs8mz9BVHku H3yNjI6F29lOswws9qwUwUL9RlqdfwUwoXDtokIhKx7e9FpU18Expq/m24oSh4K4Lss7mGYGJSuJA Ce7saSmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5ktR-0000000EJx5-2y8x; Tue, 29 Oct 2024 12:00:13 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqb-0000000E7Mz-3KfE for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:15 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-539e8607c2aso5399186e87.3 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=lists.infradead.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=zjyZB+zh2w4x6OXhVjIO3GM6emdE9OfL6PKDQlgdB2JmHJzbLWcL34bpwPTraHcj3T tyXyO8fTIbYKCL73tuDXbM6GGon3PKfX2l70qev1WLBc53b0aK/zeKxHkmYG7dDHq6X9 rp9cjLB/dQUq9nzxLYyTDEe8klmpgZCtlq8HRhLTCzbmxnBumGf20cgl4dMqlZnqR0F7 9MYXoNImObtI7cxls90uxkA2fKvj0kh3z2jpvPG+nY2r12MCj8PCNtjsHw3IpUlD32qk ortMQNefBdHt7NWN1P3mfdEkzyLoiRiGZ6PBtQLjy/vJ+KUcwzqVejtaPpeNDtjfsN0X cnGA== 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=WeYFGBOsQD5RWL6ICoyxUziCOE/eQtKr4g8mNiPtUd7tgDt5F+pSi4xxDZgwx9GV0T 0ktuAAK2xtGjIkd2UO18ntt4bRGjkwwkiIJsobhy3X/OIbRxNrCqUy1bhQp1L92mtNdp tsaqIIJwW1tCzn6J4/9+jgO2Du69FNBP9PjoSVxNfS/V8gFn9YRzuuUWbARHYGcr/nth MnAcNjvnzB7iGfcpftrEsYS+3uAP9QA0dOdG2vqdfvQoMxb3kWhqtmmsJCLLZEZ7Lpse KOEnMniBrXfj5SvbHL7gTOF9Zd69FjhwCTXE9q7s5NswIT9jb6HG1KEdH4zwP/uWC2bw eKPw== X-Gm-Message-State: AOJu0YzOiP3qqWLvx3nNN64JsKdctXa8RvW+yF+g4d9K9Hn3yMAZrOY9 XK4rvfQ8UVn5eumlgVuozxQMV+3Q2lB+WKCzoqeKkKH9hnmpCkdNvI4gd5TXPoc= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035313_923684_2F8C3978 X-CRM114-Status: GOOD ( 12.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 - .macro usr_entry, trace=1, uaccess=1 + .macro usr_entry, uaccess=1 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 - .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 = 0 - .endif .endm .macro kuser_cmpxchg_check @@ -428,6 +429,7 @@ ENDPROC(__fiq_abt) .align 5 __dabt_usr: usr_entry uaccess=0 + 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=1 get_thread_info tsk @@ -451,6 +454,7 @@ ENDPROC(__irq_usr) .align 5 __und_usr: usr_entry uaccess=0 + usr_entry_enter @ 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) .align 5 __fiq_usr: - usr_entry trace=0 + usr_entry kuser_cmpxchg_check mov r0, sp @ struct pt_regs *regs bl handle_fiq_as_nmi From patchwork Tue Oct 29 10:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854756 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F305D2AB1F for ; Tue, 29 Oct 2024 11:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qPx4kMCDrheeY8xWYJ0qE47ahtpfJ0dLdCDyA5qyaAo=; b=y/3PGdCg76wGdmuD3N7zkHHhXR i2QqZaxvndgMRPcLFX+276ZN90YJY7wRABTQDHGpIceD/22s/eGrNsDHhOsRFDIArJNKkMxDhCt0n ou0VeZVqP9N8l0iUuRWleaPEmF8lHiX8rc6QXv7GQ1qvEp0pUPP/yjORe138vnj4EiVN6mRyk74+S l7EnHJhJ5FQr9XdG/zcG0buZXkk8RMGrCNhyybwN8YNkJsgvLpZjQrwVGaqIP/oCwhU0f+EAeD3Vz m7ih8IINMF8/pici7hsffWH8k3UGKVbecCW0m7xR6regTrUw9GFLg9uw+LAm5Lbi2j5ek+w8OfNuu c+AU/O/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kSE-0000000EF9i-3XHR; Tue, 29 Oct 2024 11:32:07 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqd-0000000E7NK-16bH for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:17 +0000 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2fb4af0b6beso80044691fa.3 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=lists.infradead.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=HyPJumtxfxrAEnXUNvwegHoeH44nAc7EMwwDPveBMJ7bvIhKWQZPZw/aGKQf7yZXxG oj2NThVNX51wEA4RrWYnTgzhda0IJ6CKi2qISfx2+3vNUgTjtFKVVnWdknue72EtG1Uv 1HedpX9HRq0ZCPa28IbktyGoN6XfSXygfPFhlzGdmJ06h9xNeguG+2+zI63OUb5mwDQq yn+do2iC9LpeYrhaP9vGDR0rRJ7bRviAZHCPKZqqsSu/xxUiYiZDQq0rNq4y+lgMIpV2 CAYI9GpYpoyI6Y1/myQ6ZKMBWZrTCewiB7EItyvypA4kMAh7Q2K26LaFgLzmuvZI5Qbn unrg== 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=USQVQs5fDFSiqaKIU8eW7G2Oc3XFuTKYLGWz4H/hUFAlISZihTsqJYzAGZIO5HO6c+ AE3fkZX+BTWxPcqdhEG01635aOSQx8Nvy91HS2lR8oJBoTbmip1H7o2RJeSLvEXbvuSW xEXWLi+DywhymV6TepOQzx+0Kd5EgDGPAyBLP606HFKjrVx+xOmnCRVA6plUAY0EzBzw Pi1srQj6gpu2KqKr1Rb1Wkn/70oXpFHftw9qlbNdO4HItaPGsyriwEI8EeWVe5j/xzud zPB1L1/z2CkPN9ZkZU2c46SGKbTmPiZVLwubeeXAnppsAMApH1z3Wk0f6d4l4/IcjAL7 MAZw== X-Gm-Message-State: AOJu0Yzy3SU6tR9245/J7JU8FmEMul9HgyZFfl23JtQioy0DwRLyPnxG 6geqAXo2IpF/iSzDPIh7YP/0SYoCHSa/LpvcKqz1JAaX+qZW4prPIhqj2ccBTog= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035315_444943_81DFEE2C X-CRM114-Status: GOOD ( 18.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); 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 - /* 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 = 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=0 - usr_entry_enter + asm_irqentry_enter_from_user_mode save = 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 = 0 kuser_cmpxchg_check irq_handler from_user=1 get_thread_info tsk @@ -454,7 +446,7 @@ ENDPROC(__irq_usr) .align 5 __und_usr: usr_entry uaccess=0 - usr_entry_enter + asm_irqentry_enter_from_user_mode save = 0 @ 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 = 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 = 0 - asm_irqentry_exit_to_user_mode save = 0 #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=0 - enable_irq_notrace - asm_irqentry_enter_from_user_mode save = 0 /* * 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; +} noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) { + trace_hardirqs_off(); /* This context tracking call has inverse naming */ user_exit_callable(); } noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) { + trace_hardirqs_on(); /* This context tracking call has inverse naming */ user_enter_callable(); } From patchwork Tue Oct 29 10:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7480CD2AB20 for ; Tue, 29 Oct 2024 11:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JNSBA39L+uD3IEP0aKHjk6mvKlXPMhygyF+Shfug/O4=; b=bLpH9pr79CJV+nRW1r3C5wNYEk ulQZ89htmB0oP5vfDo/hguT16K1Gq/kszwwWULAHYuj2L0My7nY0T0GH8iWVGuARHievPs808LVkX tcl0wP9MZsXnxnlv/XsP/dMDt9reDjKGQrSKq5aa/V/b5qvd/JraKZrs5hTz+xEpBdOlR7CdLuhVc oW8JKvk9Vx1Ad0cFNtgnAfZQugG91zYr35CoaoAgoxfu+8ULUQkIB28XaroehpByVwGQlnK/et0dW SLMM1K7udTG7X1dna2rVChO21FkVR4VInZqIMfDIj9DzA0443SOKOt1aXz8VGj8+E6qI5kqDtGMMK ZVb4rdiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kTs-0000000EFPg-10e3; Tue, 29 Oct 2024 11:33:48 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqf-0000000E7OY-0mx9 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:18 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-539f58c68c5so8765134e87.3 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=lists.infradead.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=gjnaDZPTlh2tCWwHiOUaphyDTbERFYhOAc9cGbdOX5Fvw0cQMoo3DcilTgtwgv5x1m pomRuk+soVt5qQbBApNxoNBfujh+g9pzTKvV4lOcEHCwNEwkRvYXt53upMOdgoFzdjS8 wXF0N3BMZTqYiTOHcIBZfqej4naiaGj/jIwXKia02Ed2rkFN6fM3ps4zgXfbmfJ5o3WX h0CdtVHEck2aQEdoH9/K2y2QDdasyFCnwz1Sj68iDzGGVUG5AzrUF3a+GLCaVWstE/G4 aHhY4i6hz4qDffpqNmwuMrJMkpfyst7m9s81UvWTfOf632mDC4XDlag8s8MblE4hJ6VJ NXJg== 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=m1bW8rM7ooJdkHaeO+1J14/xtUmVcBOcLFfYYTjCInrAZDkZVcoIs82VTJQ9VKpnRU dHqgT3zLvgH26QPSHIzbsH2gMWBqc+pBS5jPED7bD5LLmRrP2/6ibMaNxUbs9UAynhpE SzU11nKk19f/zU3OvLzsfODTWeLSXU1ip3BgaVb6HfPdaHT5Va9hD7eTckpVnCjJDAW/ xDfgWrxid45KzvHV4BjHdZ9kjOUmdUTre4nfeAdEjvH1T/HzDhTJy+ZGR52tStPF6MRY iAcvGljUOWJvAsWXMmUVWwax6arH143pXU7uMtYybixbvx0P/c7Yen3ETdmm8s5/Sn7e Ur3w== X-Gm-Message-State: AOJu0Yw7mqlkqmigF4rzGFrgtBLLzGsY0Li9mZVkaroL9p8EZuWn//Ip ajCdzq7siJOVn+10i3tZ/+z8tsJ0tlG0pAXFntBFXhyCJ+TP0cHRwe89piS0Mqo= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035317_383322_7A067127 X-CRM114-Status: GOOD ( 13.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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=0 - asm_irqentry_enter_from_user_mode save = 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 = 0 + asm_irqentry_enter_from_user_mode kuser_cmpxchg_check irq_handler from_user=1 get_thread_info tsk @@ -446,7 +446,7 @@ ENDPROC(__irq_usr) .align 5 __und_usr: usr_entry uaccess=0 - asm_irqentry_enter_from_user_mode save = 0 + asm_irqentry_enter_from_user_mode @ 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 = 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 = 0 + asm_irqentry_exit_to_user_mode #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 transitions * between user and kernel mode. */ - .macro asm_irqentry_enter_from_user_mode, save = 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 - .macro asm_irqentry_exit_to_user_mode, save = 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 /* From patchwork Tue Oct 29 10:52:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45E35D2AB20 for ; Tue, 29 Oct 2024 11:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=; b=ZSZ37sP6H2rRe3NWdoKY6ML3pk JhxPLPb+5i6a6mp5wcou7jPaYpcLnaRkDel7vwnHjUL451drKKM+xhnSzeDsdisEQiMw0iQBTob2D 99+9djNnd/U+On5SNUeo7oO1vLxIPeLTvawdU42zLHq6CDZy3YPlturHgNuI5DzmmMtjXhrsBChMo j2fl8XXQmUMD1O0UaO94Tw5/S+iXBro1xqgASUfbVUSYSHhB/+KYLO1N6hEzsNqLdBOmKGvjVCxh0 J305Q3RVr2f7LI8LwcY5OK5SICta+8FiMzr8k6/rxvsVVRpNbr6qwRnXK7EtzKX3X4+qFWLYzeRCY GP2IZ1OQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kVS-0000000EFa7-1aBW; Tue, 29 Oct 2024 11:35:26 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqh-0000000E7Po-1tEJ for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:20 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-539e8607c2aso5399285e87.3 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=lists.infradead.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=hyMvskPRXdde2mT1EEkHo2GGhrEMo5RpjccmdIBgE9galS+PaAXA0clW4Uwm0xTkjv XrD8EtsJlksrJ7PPeY0j6Etc4PPxOcnYHrfZZh51qQndFR4jLemwLHve6BjDN0CTz6oZ ibDOLWu6G7ObDatqcsJqibseVkgTcdr+saDFEec4JBx/s8lfjLIymjNJikTBhTl4fnsl 2KqExqO8g2lG5EV072CmKZta2SRSBLfu4D0865bS538mkzntN8BgwVdxLCBHs28A20ze KPNUe6+ugKgBk60CnKZ+0V5GJTe+LAFLrN1qq+kR56lZOJV5kJmAWjGpzWcQpeizcCv/ pDkA== 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=i45GTJ4SFq0IzjNvA7M6tdzTB449M3o/iuq7mo6ikGrfoYfSYwsaY2yWqeLU+3OJUB 8JqF6R3HQQg0XP8uxZ9eahWwI+BTSRssiRZniyrIGqeRmrnwRkuI2wCsxf6qAJtwCh1R GKXvk12xEdiQ5K1OoSzfQwGgEjWzw9g+0ERJSwkyOR/1MchlLoBYqXTn2pcDSlYd3rSW Lo0gtZ/Tvbw+nASU8SBHWRrW+/Bgc2HdvfVy5Ar4D9MXsMswOqm3rALKZCzR+aDU6Etf 29PO8BjCeEfT2wuTwf09F59kYcu772DCylB5Wj4HM9xrn0T8vQAMMpA1w6+JI8DESUBt jbSQ== X-Gm-Message-State: AOJu0Ywb2FeEe5gGEO19/g/sdZm+uhm7ZZr8UPGerUWLR7JZk3QU4cfJ iYI2Sl7ys3OXnN+KMCWWsvnnRAny5ACk6BD6ww6bMC6w1K2l97azFN82YHwDcSc= 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() MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035319_536496_4CAC8EFC X-CRM114-Status: GOOD ( 15.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); 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 { #include -void do_rseq_syscall(struct pt_regs *regs); void do_work_pending(struct pt_regs *regs, unsigned int thread_flags); #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 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; } +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; } -#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. From patchwork Tue Oct 29 10:52:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C378D2AB1F for ; Tue, 29 Oct 2024 11:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KWToKPY4NC+RvNbtP48N7l0nt4O+1hLmMWZz8WN9xgg=; b=PIE/IzmmizZgLK8gUhcdDZT/2M ScZ60hLI3fIkXvehinXrK2M1gNZ5IOKUrLZpEC+37MJ5RBeHWlhB6LbkOK1dQJ8EuxfrrBJuonLmh IsMIfZMs2726sDfGMUjr+s+tusaYgTahsSBD382VXmdlH5slOZ0E39ScG44zsEqNQirnluqYPdbV9 W7KE10uxMeMKqkgrjkhaTv9Hw2/M3EaG4aS6XmoC9TUOO3OBDwabTwpii4JV8hlTIXhl9E7sTm7Cz PB57CtoEJiEl6UPkB8S3d4GWYtAdvhUEAyd++S+yUjhP2iWBq/maG51kq1mlOtRKBcHySICJPtsQb 6WAlYuKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kX3-0000000EFmd-2f89; Tue, 29 Oct 2024 11:37:05 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqj-0000000E7QW-1YF3 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:22 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2fb3ce15172so55565081fa.0 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=lists.infradead.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=xIP+V1WCUpO1GF6uLnA7eY7jzjOEKvkcAOMYwDnYlp8ELo5Lnre7jmjF/EG5B0qZi5 lzTI38+00WANV4/jqZJZXHs6viFghsZ8oZHGEkvzZ9PJo7KGXtNQYTYb+mQizEHIpT4q 6+g7dbgTYUsWlGLzlREeSOxCk063of9rrOPOZ/fQEvcAU+mldmRx4R9Afsj/FjjpM8m+ uUf9yVp58pjydt6h5Ws8n4miPhmo4QhhaaVvC+qTmKbGu+rLiwimnrlFxTki4/io8MFg 7s48vMGyW8XL52Cp6zPLsNupR+2YrTEml36K9Ffg5067tAWOwCoL7NTowZAXZEH/DD6u x+PQ== 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=l6woQ1ipdBxOz0j4APQmhbzopCQ31tcU+iVIopPEfbAF+W0sFPzzT+9EgFZGvNgI3A 1LoJzLkCKYP2BdkmMiqE42U6+MId43DxjQlWzsPvbiKeM2cwx4Dny+hWFJDgzWsjd6aa /Wk+HPDSx/p5DNiVrYRAIFLs7XBFTWMFRg/iNPds7b0BoYFKR6viPcA6OVr7sDCwKr6C 5RyhwENFNjGTzYmRYdeAP56QVorA8kpxX4WpBK3blYv43aLf+v/+zYL7W7rBiJi+wUck iWCher2qp+beDJFTNBfXIFMW4ufP9vXvkLLQsu4UQkRou8Ixfl+0L4f+UpoXhFEsdoy9 CKdA== X-Gm-Message-State: AOJu0YxThYhaj81KzpbAmyCz+GUYJkdjFB71mbu08N8WQD17I1BSkDpg Lmiaf462RUaJMJsfsMzIKhmFB7jxyM4cXnoPds9pe7ccW4sHW16S/mxFbj+hNHw= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035321_447268_FF7D492B X-CRM114-Status: GOOD ( 14.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 .section .entry.text,"ax",%progbits .align 5 -#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING_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 = 0, offset = 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 functions, + * As we will need to call out to some C functions, * we save r0 first to avoid needing to save registers around each C function * call. */ @@ -75,7 +49,6 @@ ret_fast_syscall: ENDPROC(ret_fast_syscall) /* Slower path - fall through to work_pending */ -#endif tst r1, #_TIF_SYSCALL_WORK beq slow_work_pending From patchwork Tue Oct 29 10:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16B66D2AB20 for ; Tue, 29 Oct 2024 11:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4s7yTStZNPQghs61B8MN+wTLfopUv2dudvbP9oK+hzk=; b=tLG0af4RqYbk3HcOFNVKqdS3/g IZJH04Bou5NdVjjKEPm2BzNGyeQZHN+bN5PwOZ82tz5ts0AiH7w59veRXZtBhwX50wbF/5StIOZlm UHXXoxIqphAOXJgEb22rPZNP6twoJ/WVNgs/dZDnAixRyiNJjPT7bUhh6t3ogzBl/Cxu4mHYstow+ N4iuSPfvLvetDtEWXIAmwx/6C3aFmRXKM88IyAYqbvaOGTjyj2Kxxw/a50HK2eQj9U1gBpqeVAtoR zrYDx2cz8ibp9EhSLC4iGGYadKRHI0lrxZBQ1IrnY8bhieaag1BcTmgCtj2gy04yjgvGuNmWuV4Ge pOdhPOHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kYe-0000000EG5d-0idP; Tue, 29 Oct 2024 11:38:44 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jql-0000000E7RF-2hwk for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:24 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-539e6c754bdso4744389e87.2 for ; Tue, 29 Oct 2024 03:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199201; x=1730804001; darn=lists.infradead.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=A1gBg48LuUDDQ4HBNaABQFOpgITE0tv56VDbSB4WXWpSy2JzCbByfPneWY+eR3cqAr 3EDS8bj86b2640hYDD/ehCRFWKtMHLyBKWlVcN0n5/SSJ7UOJWGlm8heJjXbNwGqzAhh r6oDYeuT2mGb3ljIVZhEGsQ7tds1UI2lQw+jOpjgI4ozZXqn+UJGiPjVs5vZ2Pw9d/vd 5iwXH5Y/DGcHJnazJzAcQDexKOfDwXKteS7oDpsViUx+kPJyVDocRwbLGMAsO2TXNzeJ 7sQ8JixOpTrUmuDRVQPWsoXdplu0Qk8LxgeWWfspTlQwwEmIwp7Nx3Trj1o/lSVA7lU1 rwgA== 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=Hcz35vwnlYNZz4PPY3oK6a9vMaQUTi1g/NZGIhFTlgEnK6i+OFN5iZvRGL2FsLngNg hwl1huzgDVD3VKYKYI85F8c7jmgSMtvYJ3Zci6J2PmFaVToQtmjaath4oYSezNzYvPpc L0ATpaESAMb9MWY5YYzNcfAGLyoKmS3s2urUbTUC4Y3qsp0o9xKMkP23x+To7HqlLGPn Xi/NKrE8TKCiftRSXb7OR2H/1juAaJk7na06idm0edcisFTzWwEZutVZKbWYiOJFVSHr qPfJVt/aRNlwobbT1yDioi0fLl2Dv/cRuFEt1CmcDiDIh1n/1nBZPt6f1YEp3z+gMDSI uJCg== X-Gm-Message-State: AOJu0YxBMlioaBX/JtQ/K542EVo4ShC4NESznj8DXQ2A+VDuJ6u6Cs5H jcPt2STj+y6e8Sf4s7ipm+rft1a+3X0owwVGYsu1JpKhPM6YZPB6io/MpFKH9cw= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035323_734990_DD27B1DE X-CRM114-Status: GOOD ( 13.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now all remaining invocations of restore_user_regs has fast = 0 and offset = 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 = 0, offset = 0 + restore_user_regs UNWIND(.fnend ) ENDPROC(__fiq_usr) 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 = 0, offset = 0 + restore_user_regs ENDPROC(ret_to_user_from_irq) ENDPROC(ret_to_user) 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 - .macro restore_user_regs, fast = 0, offset = 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 = \fast + v7m_exception_slow_exit ret_r0 = 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 - .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?", \@ From patchwork Tue Oct 29 10:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 349AED2AB20 for ; Tue, 29 Oct 2024 11:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hWWOf9VRKfs2/tqyRJcdO75r8/gLb8BcoV6DE9Ay3YY=; b=tpfivcgXsLcapw3qvKnadQyHYN OVLsp6EWUMCqRyn+bVThmkIkmcI/cltu5GaH3SgZcsddKI8NkEPLPWMC7pHQZI/U8WKQJkXMsmFVf vDSsTfDTD5K98ofDn7zMpsK5BBwJX1X0phhg/q22s0z2nLPUh7U/tiHZFgjrVHDZfltzB9bkw/+3j ILNa5lez8F5wb1vDgaROHqiVnSHrVEaS70f+73XUvslUyGPjJMyXKuDXYbkic1EgB0kpRtzeer4pR PeX3r4o5OowTqMHKKKrEyxxs9cL3gzWDXQLi9BahvZtgN8q/Tkgt4n+0DeMOsk/o1AI8HIxpyBBE6 7M73e9SA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kaE-0000000EGHY-0gYY; Tue, 29 Oct 2024 11:40:22 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqm-0000000E7Rp-2kV6 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:26 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-539e8607c2aso5399361e87.3 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=lists.infradead.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=AyUt0bUl0tOeac6A+WieszW/53hVgo3TbBxOzSkhE5C/fmMYYFk/BsQdf+ic4iIqUm RVRhofKK8ahtwjLysPF1bnWt7OYTRzyDzMfGkrFAgsVFykVJ3XpnAm62+2b4q+E4lF/a /9SQfd+YXSmrusnor7quuMWBS+R36yi8lqyTsstFcq/Dar2kghypHejVLDjlD5ii7hMf +AlL81vEk366ZZDN1DYFI6B66ziBcXqHMRR9aZmB62ugTKFnKagacozELvfohKEiB9KE lOgUWNQ7sBCKgyslrISlxUYNnmnMviWLtEQ6kgE2wXmpBy+JaAf2moq/oigzL3LBr1aZ scSQ== 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=wmgdsALTxO+8g5uIqGliT59GC/WlytBKGumUAdw0Thm0fLKlSKVGTO1wW3S003v2hW CbarBp57KQArG4+sP1Zg3ma4x81M4f3QF4xa2w62W0tABRRRfTzGgQhq+p5iF6f+gpI5 9d/yrK/pBQ9UYbR3X0O8RfllNlO7spnNJiuxrM+1sAdu/zaL+QeBLNF1oEoh+lvTkwpl H6EwDw56eJU5t+azs90cjJJW2FsCw9S8sFrzMobPxyjsq7jH/NQkjG9Nw+8uCWgIgY7O wWFXPAr5F00njOVaCmgSSwD08hWHx4xw9RzDX3MPT8/uU1E2fdrzOMTjSfR6WHt0M1eu QSkA== X-Gm-Message-State: AOJu0Yz5qgXbIGBpeRt+9a34RZNpKUytLPw3Zn4z3xR25qrHc4dZUTC6 xhL8J8JugMaLAnJy6qV77fQkU6pmuIoGCfdNrYLgaiLgXHDwMwYV/l7NOkOgN8E= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035324_736506_320D282E X-CRM114-Status: GOOD ( 12.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 tst r1, #_TIF_SYSCALL_WORK - beq slow_work_pending + beq 1f + b ret_to_user -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) /* @@ -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 From patchwork Tue Oct 29 10:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED9FAD2AB20 for ; Tue, 29 Oct 2024 11:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=P2OP9NgXP8OYjhdkePmH5sP15xkO/BVCD1VA0/cLgTg=; b=vzt0Jmctn+9o87mMJSR7yeQHeh Mmfjs3U4Y8c0pSTV8Ht4+eNJ+bnJRDvHNkjM3gvo3CPKkCGCJ/bFdOOkIdaLK7jNe6uA8MAkn7sgi raVCmhWlvBuKDcwdnsqTpKV8uZjS2m+NfDZIA6bpfc0rhlSHhaZ9ol3sMyi32QosZZSuOYQZ/09ra o4/TpKZy+igw9iHWlcLr8AswHBxN5WHF31gzreywot15OuQqNIbxEi7Bsn1DHk2lPF1kk1BepSVOi KD3IUPNyJ5PJ6RhOO02CSWgGEq7B2qYF3yB2io3uXwzSwdBOL27Y7KUJTreiYR2Xw/s10ak4wyMOC Iw0hawnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kbo-0000000EGQi-2SLm; Tue, 29 Oct 2024 11:42:00 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqo-0000000E7ST-0USk for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:27 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-539f72c8fc1so6476625e87.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=lists.infradead.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=P/LqQ+HCejdyGCc4GFCd4AQHRNECb5e1drua/aC1fGD4GvDOjT85FkJsieaE35PoIF R6fnr6ItNRP+7UXX7Co1JPb+Et9K0fNg6NSQh3IRtbW/Ok30cnaoenT15Al5bt4rgolA sPeJLNpGaKh0wXKMYtoFaW2f4z8kQ0b94VOg5a6xf4SEzatSrXJR4IZsUVJzwfpNayjG Ny+r+/KbrdFlGjFdIfmpybCSrPuWmjkC/ttD1eeV02psuNGBvWaF6YTnRcf2ix82A9kE VBF9uOxUyQIchtHVf3gvVnBA0Ldb8V3bglTWrtutNh0LPXGmvkYPcpE3ugdRBzCbiyPm YEwA== 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=ZIOsY9wbBbB6EAr4gEu5kWmoL7eWdeHnSEXcK6et26pFTSPanVfh+RWmmhwJAZPC2T 0I1dBKbJSmapslFebqCcZUyhZPVbUesq+2V3DsAnCZ4d/JzcTWj1IjHZn2wbVKDUKEUs +s55BFw/9G4SgaWfA3ip0/tM/MgdBEDM/H0GMufggIszokcBGoxF40ojaiqe47Pfp5i6 WvTI87nxO8fR3aggczEAJcfWPTvdQPHDO5md8skU7SYfFwUiA0sxNld8VrHWguUvEziQ nAsxJNpa+H3LHKdgTdPfwTbiB8l+1ZUf/6YDHwo6PikXyTdX2+M464/xVgbXZH3WD97y ABNA== X-Gm-Message-State: AOJu0YxpELe2Qb8IEPjdIADCx16Whn+vJYIvwQMlaLCCSMg4oLehOH0Y Qf0leAlk5Q6BVdoADNY+dtDZxoDPZcwum17x209s1AciV8IJPlgNo/X3niJvdJ9igI+pcI8CarE N 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035326_248571_4EB14396 X-CRM114-Status: GOOD ( 17.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 - b ret_to_user + b 2f 1: mov r0, sp @ 'regs' bl do_work_pending From patchwork Tue Oct 29 10:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854780 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67043D2AB20 for ; Tue, 29 Oct 2024 11:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Gi2KcUYCbZkPlsUdwrNEo9QLrpmnXM+YJIWNYO7+o8Y=; b=GtRj121mkR1izir1CqaFlRdpZp eGMYSDdx0BYwWi1EHa3P4LDGdVtgMMFMhaReyKeFRU71sYN/WRfsvmRt8A2dt+5Rp4NK1LiJj5aIG ATETMaJ7l6xIai2TVDQugINGsMNKNDsnuCeW5q37A4/l7LECZR+Q5p+FpJvfSkhFJLJK2QK8XnAnt pQ3JnshkX1C76p0Edhdh3i4lzso0WcWB6LAtnqXemwql12TvnUi4PWsrU2SE3by5IQQj9u6OeZGbY s/2AFMGOdq5AZRO6HTew3U3aGRjAx6BPkmY39pQ2R7qsS65eGXdwQCL8oqJ51LRWSC7S6lcbdfRZK wEQObjsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kdN-0000000EGiD-3SF8; Tue, 29 Oct 2024 11:43:37 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqq-0000000E7TK-1alD for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:30 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-53b13ea6b78so8221376e87.2 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=lists.infradead.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=SbVNe9/wyoTceVhs3mMo1XKpR43ucrZIWDKpyAeYrhvJixfa3Qw4pIa1QLEg/gOJFF X+YFJp2nD0hDwhoKr8mWP64ynriOEWwB63yKtuF2lExEUxJCvZ+iWC7HCrQQns012PgO k9nM17ZQQnvCrwPn3cZOS0bqcNVq6otZHIo5+0DrV0zYMpvAnhBIVHmWymX2e0oqVotg WpP16eUS6aNX0TyQGd1coaLz3fcBwl6cikf8VqKuHMFDPo7XBGQFQnI6HvN1EUD7jlbk tckuYbd7BOvAWXHlrlifGmjo5yi1kCYeArdRtW2H4Tlk4V9doexjqyzJxS4EGAxOg2dY JjTQ== 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=WE2qmmx925ptCUsKthMsrbjbTSZSWRJf06pSyeivQR3WMx2ziZmiczHc+GfEz8SDyK ZjpS1SkmGkgd0V6XoqHMExUI6fiEUlAUGUNweiCYbZeTTjY2lm+YGwI7Yg0IhrzvxKyb zqS/FGMwP8ouE3Tm6gccp/POLBVBSxPKjIGrmjwvqlmcXI90oQ3FK0XY1jNTpgxVyp2W h7b9t0Z59Lca5lDxsqIIT48pKsnUJEInMNeVqCSMLskYrOIRhVbc3DG/b/c9pp/xif71 uV5gdggxqaK3RgCrDawYrw1PeHwsAjaFDx/2UXMtl6DNB52/71DAV5Za+o6g5nJO9mnn RFUg== X-Gm-Message-State: AOJu0YxcOPpa2EWRcCGvKHMx1YNQO3pn3O8A3686sMXeva8mon2REA6z gYgwS8lRQu2sAncqjjrc+UkwV7tGn/UFXJ9V9Tlz3lesvWkxf3khOihH3MnQ9sM= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035328_458413_DF91E0AD X-CRM114-Status: GOOD ( 14.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 #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 +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) void syscall_exit_to_user_mode(struct pt_regs *regs) { + unsigned long flags = read_thread_flags(); + rseq_syscall(regs); local_irq_disable(); + if (has_syscall_work(flags)) + do_work_pending(regs, flags); } noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) From patchwork Tue Oct 29 10:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C7AFD2AB23 for ; Tue, 29 Oct 2024 11:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bckn3YFGIgJxyi6JuzR+D6XCfS8U3/QVQiTYkjNWbHI=; b=fQwZOSU4exf8SFvcyeNAX/7+s9 C9+eO8p3+PZwUhBBhUjrA6a9ghqX7gWyVyqu98kAhh2KLToe2peVyPJMYVvGyt/SOdyyCIp9+OjOr A2+NJVfC7f8Ty0913XC2ostRRP3SAnoPXgELM8NVSERYWBvrMHq6zS8ZwoHSX2jAbAg6qkrd59qXR W1xIxo74ItBPCT2GjHMAm4JoKDcYn1L+niWmk+tI0SIa8MQUKoBJqoOiHuTVjsh3rXv6PYTEpe/gd vLOqNoulqZKrAKGmFpSVPoeYUSVfQa3VF4PcLGg9ElCPmPFfq8N0zGgXTfD/ddZkSKWee3P/H3Q/k cTnGuO8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kez-0000000EHAc-0aP9; Tue, 29 Oct 2024 11:45:17 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqr-0000000E7Tz-2gAW for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:30 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-539e59dadebso6203365e87.0 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=lists.infradead.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=PW82LS8bSHt5eNwN72M2LgiNv2tdHowr4sWpKxcNJZEcIgZcv3EyTM+z2uPvtPIXx0 6AbooLMm1BuQ8DziG4VIJc+iSbXjdJm/VaKmtv5UC/YCr1+QEJdhs7Nkp9l5k7W8WLLo s4qH2zPbVaxLEMarpBaSbGzD9gf8A2uEp0oKISgVvs/sXwVyMNW50BG9WP7JKJQlXu1G TIB2iarfs1qAiT0bkWaD9KIAya2XjLyaCuf6dDDllh+KXIPDJLHwktElfrIDfGnZrSEK 2xZFB7lfOReGVO38POtn+bvqX530PphmQLjqDM+vUnhlSmeLJ+2+snBReVgowiOZSOvh 6LYQ== 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=cjDIC5PilyRid7E7p7z4rjSaTD7t2tfO/WDMntZZr6CeP6WEy01u08LmBx3wPvdlKi B2xljo2H+oAD4YWe9RTR0S/8abTobA+zVNb+JzmuuMpBGIs5EfFkdT8Hjh86W2GZUXBP beKj6L6qfiKwuRcESF78sZapu50lPzoRCbJCs9vn+GWgOSUy36bujq4v0vfbeKuyoLYQ WsTZPvxVlphd+OwrSmW10dtiw6iNXlSSxHX81+bpZnV6AMdvsn3P2sG69LWqVJFMG0Cw T/lbHxusnOhaRZNf2qsK++S3WgSFdZPwThuq+C8T9TzJ2AQcJGOgrro2vAwSM8WYPVQm U2PA== X-Gm-Message-State: AOJu0Yxymyc4fix9Zg7VvpIEqlslFkwTg5gx7CNYW0PHfBx5WYRMCmFL OowXFvXmVmkhXrYDS3wPVrgRi3TRyl5LYqIpL05Rba6b5svk6Itb1n9kd+R22ww= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035329_738585_ABF5BBB1 X-CRM114-Status: GOOD ( 14.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 #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) /* * 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(); } noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) From patchwork Tue Oct 29 10:53:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82999D2AB23 for ; Tue, 29 Oct 2024 11:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=; b=VgGatiZ3o13IdndNFcfjxCCbOs fYiGHdpljgskRYLesSdhGPApcm20ioUQuznsGpP8Y9bWMtMn4sMS9eQ/koOBWgfpK/zjD+8VW/Yj9 1cgX2ihJzfC5p4Qe17muVlDksD9OBLhw4XGjr/Gsky/3hGtvYjivOqGSRX7K12of03Pe9zXTJgu6I +FQusA85ta/MjTt8HFQF3IxiCaJ80RtYMQhcLRqlvero3oE1Azt9EjMVpSP1rpVaYiwXoIxiUzfBL 7wbvfYcnpX55TrcSteHAvZgVqlJ1WHDP/3VA08FJl6KYKznJone2m9NJP5jnFbMiupKC87l7lhMdU lisi1H5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kgZ-0000000EHPU-2HjY; Tue, 29 Oct 2024 11:46:55 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqt-0000000E7UX-0fi7 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:32 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-53a0c160b94so5892774e87.2 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=lists.infradead.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=IyJD3HwpWEsKix0YsRaIg60s4wq+tXxL0t8WdWHZSRiW5lA2635E2Qfojha0VRXOKO QDDx+31xHtcHCa5izpOgTQuZr+c6MSenf8OHof1gJwch7tODE7wMgBeyH8yiehFYrhrJ gYMEHHmnNnSoOt/g9od5l1gmdPhoRBgo3tTNerPcBz1raTin/97SiKH2I+n5WrLmYWNL lkmNKcIeqbBJDKSQ0qTjxgtuuTnkzZ7l1fSE+6XCA4LYtg48q7dPSffXhV1Pqf8yRgi6 +F/mEZchG2jdsRlSOO+t+6qOMhCopP+cOLc1TXPbeXo016zdibjjlQmqN50UDfEAin0z OqsQ== 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=B0FwjM4PYbWnOJsD1HJ7kaDtepaKrjKRoqrMC63nUjqGqOv4+GPqyTNSHsHkkdQx3q kvHOksDmFjvZ6dIEtL/AfZqAW01IeqarOgeHNA+N6w79W4km0bpnM2gyNIj8xVha3egb ANjURGvG0eTRpw6Ws12qaUC7Elc9rb5DHcT/Cmmpj5//m+roM9/K5hGm5tW4JUXpgnww AF5I9tuFIjbUVWI7/iHvqnb45jfVnBbVErGWPdFH4uqXYO9KMNXDY/dV651sMWtSPP1G SPzzuPXqDZMO2NXDJuAqh/8K4P4LnpbJy1iWIRkjGItt1nrHj09dIHmwp0VLQLvTmPOa V/Ww== X-Gm-Message-State: AOJu0YxnlQWkHLDqqhAC/03ZrTgowk2F+ONQ08nuZdczhTcITAMcj9us K+J1lID86d1zlS3J5WfTWzdgfTRMk54YLxcT3vaIP3YvHn/s6L9uZjlIXkFkQU8= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035331_237553_D2FCB617 X-CRM114-Status: GOOD ( 17.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 != 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) 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 #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 -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) rseq_syscall(regs); local_irq_disable(); - if (has_syscall_work(flags)) + /* + * It really matters that we check for flags != 0 and not + * just for pending work here! + */ + if (flags) do_work_pending(regs, flags); trace_hardirqs_on(); @@ -45,6 +44,14 @@ noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) { + unsigned long flags = read_thread_flags(); + + /* + * It really matters that we check for flags != 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 *regs) return; } -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 From patchwork Tue Oct 29 10:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 123F7D2AB29 for ; Tue, 29 Oct 2024 12:02:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=e/3IXPLtEzkdPxakYsKtSl6x7P98QonT1kDDJ6tUink=; b=HhU0JzyTQZc2NyMaOqGL5KjpsZ E1MrkFryR1BgkZ7bY3TER/RBcvMM9hrHqR3aZl2OHZR+HddTt5QtzEDF7oT5IJeoUNtqd9sHep675 ZqagFWt8aHC9+xJ4+N45Ryfj00PMfNT/D3bWZX5c/sx4vyoesUDEzv7agl5sIH8CgqGUUt3AFFb4g FUHXncWCiZNMaTrWGp092AIynodjS3L+Qvqf92YegmP2wJX3lUUpE4WbAWoUbswZ9LUCUy7P3UiH3 f3rR9cm323smrzDbH8vaGt1Fn2cY1E0jXYoD2AYmD5vBYKpyagYH7eSnX1ApcdNYiTVLeREwToXre UJixNwrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kv1-0000000EKC3-2IIl; Tue, 29 Oct 2024 12:01:51 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqx-0000000E7Wu-0qct for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:36 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-53b34ed38easo2587824e87.0 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=lists.infradead.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=rV6VXuOTZ5nUJtQwimH9+DfTUkLG8xq9XX2NYlk0y8NDWqNPvixGAzDE46XPGaCF4t 2/JWkgpS4Wl1QK+HkETnxoWGRRo38PnycWB3g4s40VXlK3p7M82fmuPVbiFoUMKvxS24 YWYvBV8PAPXN/p8pM4X/8p5KJV41zPp9q7Yp3eR+RVB3vmZ6AQ40s6RCaJcmrWkj7RUY z+HgF5NBJNW10NBjO97QCF9BrfSAS2+/d7epIMmac4aujhGOA7WYHEKsc5qnmlOtkKIr zKxKLiUdzhO66Xl5zBknr8MbGl4wB7dPz5ntdO9vu20Zq7aOHrHRLDgPEL0+71W35eaa 1K4w== 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=bKzA1rfQQOciobGVu1ljZXASh24C6aIZGfEz+cVhaKUNppUWi68DU3zMLNgBA3bNlF wy0Q1ILF9RU6FOfRu218yNNBUmhO6m9nKMVluflTicN5G6hJQPLPWRoOoNwAFURm97Zi o4aN6MKpBMQVvneZQIKQhck/ARBw1m2QpSbfslRryCn1E2jFcg1JX6gSWFFDG4RvsRQa NjDRWTKLKE2Fgt9OOKWVV7V8UF08jIc1MctrMbjbgkR85eEnuwFa7YhkpGF6Esgoqy4I ZjGv6BI/fWzRx/wkze2YWmvnViIqW5ssbCaUKbvIC9Mzkv6xiCiCbK8Z22FRioxfKXzB adXA== X-Gm-Message-State: AOJu0YyGBOJn8T+NZxh88cR9IDiiM6woSyJcyIXxQMSrzcrGaWWaFfjk dZH3g74NGclrNfkBbNYdAigfN3c1M3ui+VNojXIy3NW+T0ar25N69EtB7SU9QVk= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035335_281795_C414C4BE X-CRM114-Status: GOOD ( 14.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, 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); #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 + 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 #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) +{ +} From patchwork Tue Oct 29 10:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC793D2AB29 for ; Tue, 29 Oct 2024 12:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZScZ0+O1z+KD5ly1wGwp6XJNh1QIX+DiUm/Qzjn1DDQ=; b=aghFBhwda4E4F1Y4kxhcp4i4Bt 5GVmdFI+FwLBBGRTcgSAFQyKLDLFKnFeZvOVrPsBQx3r0LT/OW+SVEES4A0+uRaTGvrglmU1AbT7g 9oQOQ2BBgqCF5BYjeNUxYfoUanr9YNxXPCyIuApS96BDBnzJAwTwUAi1ZUQs5JpPly4tEaY2j+EZB AUxuL6uVnzNVWRKRB8B3uQCOQJJWDBqbyiIhjUFFeorO4aaN2D/xxYq/59q8VPTIkz4/7Asf0vY3h +pOOd5dR2ESC2r1z7DWsKdMPQk5MdQC7OXK3bbJhg28LVDv+FReXTuLhbiUQnC7yhpFliE9LMQOsV 8kpHza/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kwe-0000000EKWr-0d3I; Tue, 29 Oct 2024 12:03:32 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqy-0000000E7XJ-3ARD for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:38 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-539f72c913aso6808096e87.1 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=lists.infradead.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=H4Amsxa054rWEs19mf/EyC+1bVRRBOxwhHOpRYMchL1WNnPQcOLmHCzHmQUchrlhMG RWN95Y5NvTVJBUshyfN6vZnos/07mtqFbOaHE3JELKj68j7B/tkzJMjvXSGIm9p7kncC DWJ/1yrMBOfvgKdBGfHW8JHvsh2MuVEHEITza3sS8uOgD7rhL6Gj6LN8BhJ94s2K0CVB O0mb2QSuUrwzel/Sotj3C9wwIVf3QEdL7qJbJazxHxaZBYCGL78kKiWIlRmt3RLQsLom jncbj0G0rXPho0cTAqTPlRmN/zgKYclVXpEiXtt3Wny5LJwRkgD0xJxR1V0Os4w4jNzS 7Pbw== 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=SupHQtKGpBoVUeBtRPtyQIYkOpg550E8bg2ydAj6LZ4B/C6SBCu/hisrArga1b2UWe pY8TDC6jVwU/uuCUFpPygUbAIo6Qf1gUT1BbXn6j6MtcUHCoPZ1zb6N+Py7GXkWb94jx EkEJf32nx+ZE3kOHHcJBv4AnMg7RFfz80s6XD6Hk0w4CM4q8HUeUGNMbPBZFiaYRb7Hn 153wcP3/55OBWRHifYHQvF99TdoMF2mNCta30Ohhknqdh3NgL4sPSiUT6s2vFjVRJ1XH F/TRBU0T6+m2re+aB059grHHNYD1uCtDiU1R9zw0R/2nYwBeN1Rd8UjB9P/IaMFdQ4sM yeMA== X-Gm-Message-State: AOJu0YxaFxoGgIMPp3/BpJ2CVaACutEvN0OXkUKj/Gsrf2PBpOit/aeZ /eGDD6Limn3L4VG+t1KYHmkckr+NuQL8+yFWY2hzyg3N562tFz/c6ryJcIvxayk= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035336_840424_DC9DE154 X-CRM114-Status: GOOD ( 14.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 - .macro svc_entry, stack_hole=0, trace=1, uaccess=1, overflow_check=1 + .macro svc_entry, stack_hole=0 uaccess=1, overflow_check=1 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 - .if \trace -#ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_off -#endif - .endif .endm .align 5 @@ -238,7 +233,7 @@ __irq_svc: blne svc_preempt #endif - svc_exit r5, irq = 1 @ return from exception + svc_exit r5 @ return from exception UNWIND(.fnend ) ENDPROC(__irq_svc) @@ -302,7 +297,7 @@ ENDPROC(__pabt_svc) .align 5 __fiq_svc: - svc_entry trace=0 + 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=0 + svc_entry 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 - .macro svc_exit, rpsr, irq = 0 - .if \irq != 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 -#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 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) noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs) { + trace_hardirqs_off(); } noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs) { + if (interrupts_enabled(regs)) + trace_hardirqs_on(); + else + trace_hardirqs_off(); } From patchwork Tue Oct 29 10:53:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F277DD2AB29 for ; Tue, 29 Oct 2024 12:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/aytaH1oLbxE7oXL5Lh1BICkPib3Ft7vQWy4tTKokWI=; b=oUagOdCkWu4eziRmJDSLh8gx2Y KTZGZvKxU++fdP+z+CcZmr8HcvQ1431jA+5eCkp9F8fgX3pFXgkMpOmAEK7adCtnA2KxDNgN0E7su 80EeCGdLKwWJGV85LH42lbIevYHWcwCfKwu500n5r4Ht0GNo03dN/OHL17WPgTvm24ygXhCtWpq/L YEkdO/Z8iU7gqppU0w8+bPOOTShGeRkLWJUp6QRkHxnTMT3bpvqI60K7hmq/PsLRbehar8dKInKj1 tCJlrMTnF19peGEKQmpDY/odOMkNI3bFqG3HvSZan2Uv1rgnPIISXdbfFG3M58aBNj9WK7yUZZfR0 QG7Z2vGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kyF-0000000EKwO-1kPT; Tue, 29 Oct 2024 12:05:11 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jr0-0000000E7Xo-0voh for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:39 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-539f72c8fc1so6476856e87.1 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=lists.infradead.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=WHHg6DHzbAjRHBRKKONy7gPdWxbar0Yao58TVM22uQm2YongJ60V/ddZpgYA1/aDkR 9ullBO3Qy0Uo3dhBdVG+7osyaObwgAuT6MBdP5dkiYJITN5+SzADEu9ocv4j3EgUDX+S aObf2uVgTSqTJRfjpTMUSNn3EXE3OFt7TyWlVX6VljEBJr9E1uKfe9276yAWBuy67xbK JilqdHnzwj93UVQCfEj7nt7QGvz+F61yp9jd/HRHBT7wFEuGWIpZKNgakTaeUTiLYzqj KJG4vuRzJe0l2TeNgYN733fqaH36YUmxtBVBCXz/K9Ulmcu0UGv6LZere5hmf0RxM+ln Mxcg== 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=t00rXVU8FAdjLpkFUaDH9F7j05JFU3Re4IHMy6M/6tKWnGcYsHwaE5lGFIGexGCghD sfCT22lDKyfj/L8VgtanUONFhmzZna4g8hIqiHv+z+jfD+0fYxUiIJ3a3NMA8QMd9QYP c1Xs1aK7sGl54uTfMgLgwJFSAbvkhZ4hyE2EQyu77XDCjRPhi9M1lzSaHADewr8J3PeJ P9/izrXJHJAmWxNM/W6v3nO2XY5CZxMern+tLcmt77D/D6EMLCJBFMpW7Gl1FtIKZrSE e2FXarsHdCmrKbPRNTFzgod9+phy3hzVeAC8LKrvRUGgapqIv0ubYiBssUvZrKdDmbVl YfuA== X-Gm-Message-State: AOJu0YyhJNQ0K98ihT3qxe+lSHwUKpbGEuwskzMRPQHmG48moV3grAUO DeHkJuY5oxuV/yX5gLu2ZXb7NHK8XXg6azk2CPk1RUWf9NAWEMb+cXBEWG4aaFM= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035338_302018_35A1A3AE X-CRM114-Status: GOOD ( 13.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); #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 - .macro svc_entry, stack_hole=0 uaccess=1, overflow_check=1 + .macro svc_entry, stack_hole=0 uaccess=1, overflow_check=1, nmi=0 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 mov r0, sp @ 'regs' + .if \nmi + bl irqentry_nmi_enter_from_kernel_mode + .else bl irqentry_enter_from_kernel_mode + .endif .endm @@ -297,7 +301,7 @@ ENDPROC(__pabt_svc) .align 5 __fiq_svc: - svc_entry + svc_entry nmi=1 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=1 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) +{ +} From patchwork Tue Oct 29 10:53:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37AEBD2AB2B for ; Tue, 29 Oct 2024 12:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=n0vhef1d/tO4V+dCGdQHkCwxrnfd2znP3qGknf9D7ME=; b=z4cewYnTVBLBwam6gUO10m4iKt uqYuyzx53QVQ5fT0qCL1u+82bfy/WPPf+k9tm5dXklG7xSWClUxVMQtQH3GMMZ167FMgrw/ufQex3 jF+Yz40k8IGIqU9VMAG+nk0unwoNZhGc3CIbDPII7qAm2hIZ3JHc/Gv//x9stnFsuFjncwXJrFrX1 6sd0t5k+a7k+av3oMZq4M4WC4ZBEJ0VxY2NrPHzljHJrD5aAWZtbPtog/DEPWROFomfp3kdQGtITw oXwJc81iZCWw7FeEXsObZ/I0tY8p/bO87TX2Xv82KSoTUUqIIt/e0NTOcUi2Qb125T+NS1bAMcQqW FBobz9zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5kzr-0000000ELJO-0SzU; Tue, 29 Oct 2024 12:06:51 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jr2-0000000E7YV-0kot for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:42 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-539ee1acb86so5298993e87.0 for ; Tue, 29 Oct 2024 03:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199218; x=1730804018; darn=lists.infradead.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=aN6z/tKOXJi+Uc1Viz4vGHPvMm9ggtuH7Phl9f4ussyPBblOOCUbDqNBigJrOdXAay 8VBuG9plkpOcLWhBgmKI7ecbd3BvAaEhWxtsHWcbqBTnpmG23c+Gm/etnJGHx6TY6n9a cW+gz5n6hZ7iJsgtzSktJGvGqmmXwhZ3Y2Ltmzq5YYN/so6on+9ego2ObUQZTAv0dfPS uu/ELQWmpl9SiG/pVZpaCXLl3ABhg21bhX062yxNXgTt4fm7lKkjDjb3ELL73JnvNQLg ddfrypnwlyDmwbgYTYxpBkyRM8HdqFfl4jpFirHpMOIHyDa09LVEXH0q8TmMs5FwKUIM cUQQ== 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=mFIkWLSpnO1TAbFfiIYElsV6XhiNeWWWGHIcLMhP8LsZMYZEg3eMOj8CI9IIHG7rB9 NzADnL5Ey6TROqIJ+ROdc7thfV0Nmi2n4zFfdUSwdFii0m8n/kXfnYBx+gYGPShCHKvV VRx00adzR7SmfntYZZDoUskTHXcp5s1z6OdSDLTtQqzLrc+jYytxjTWpdBiHIG2e/LLB sSK0WkzcCeiu7pr+fryKeswWgAg5s+jUnfnU0UOT3KXAsGAT2za1Nv9xAT0KT01K4qAe zKc390oRyp6H1stDrrjHbrJBeM0Vvc/HWRgDocM9afm4oPZqvRSBjXFbUWhn2CmMxKeS bang== X-Gm-Message-State: AOJu0YxCMUUIgzSA7VaSfN4jS8Tk8GodT9Gd60pqNOGPS7VOJLDsFsX9 7LZH3MAXrt194Fb95ds0pWsPaTTQjzt7c9BtDaNyNa+n67rYoWO0ndViEU3+nV8= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035340_379104_4FB93308 X-CRM114-Status: GOOD ( 28.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/entry-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 = 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 = 0 -> entry + */ + ip = regs->ARM_ip; + regs->ARM_ip = 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 = 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 = 1 -> exit + */ + ip = regs->ARM_ip; + regs->ARM_ip = 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 = 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 @@ 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 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); #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 cpsr) return cpsr; } -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 { #include -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 @@ extern const unsigned long sys_call_table[]; -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; +} 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/thread_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 */ }; #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 */ - #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) -/* 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 #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) 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 .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 #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) /*============================================================================= @@ -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 #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 mov r0, sp @ 'regs' - bl irqentry_exit_to_kernel_mode + bl arm_irqentry_exit_to_kernel_mode uaccess_exit tsk, r0, r1 @@ -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 .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 /* 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 -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; -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 = read_thread_flags(); - - rseq_syscall(regs); - local_irq_disable(); - /* - * It really matters that we check for flags != 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 = irqentry_enter(regs); } -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); } -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 = read_thread_flags(); - - /* - * It really matters that we check for flags != 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 = irqentry_enter(regs); } -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); } -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 = irqentry_nmi_enter(regs); } -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); } -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 = irqentry_nmi_enter(regs); } -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); } -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 */ } int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) 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 -#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 request, return ret; } - -enum ptrace_syscall_dir { - PTRACE_SYSCALL_ENTER = 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 = 0 -> entry - */ - ip = regs->ARM_ip; - regs->ARM_ip = PTRACE_SYSCALL_ENTER; - - if (ptrace_report_syscall_entry(regs)) - current_thread_info()->abi_syscall = -1; - - regs->ARM_ip = ip; -} - -static void report_syscall_exit(struct pt_regs *regs) -{ - unsigned long ip; - - /* - * IP is used to denote syscall entry/exit: - * IP = 1 -> exit - */ - ip = regs->ARM_ip; - regs->ARM_ip = PTRACE_SYSCALL_EXIT; - - ptrace_report_syscall_exit(regs, 0); - - regs->ARM_ip = 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() == -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 = 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 handling * 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 = 0, continue_addr = 0, restart_addr = 0; bool syscall = (syscall_get_nr(current, regs) != -1); @@ -598,34 +599,6 @@ static void arch_do_signal_or_restart(struct pt_regs *regs) return; } -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 = 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 +#include #include #include -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); -__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 = read_thread_flags(); int ret; - if (has_syscall_work(flags)) { - scno = syscall_trace_enter(regs); - if (scno == -1) - goto trace_exit_nosave; - } + scno = syscall_enter_from_user_mode(regs, scno); if (scno < NR_syscalls) { ret = invoke_syscall_asm(table, regs, scno); @@ -34,13 +25,7 @@ __visible int invoke_syscall(void *table, struct pt_regs *regs, int scno) ret = sys_ni_syscall(); exit_save: - /* Save return value from syscall */ - regs->ARM_r0 = 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); }