From patchwork Thu Oct 10 11:33:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13829987 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 A0BF3CF11D0 for ; Thu, 10 Oct 2024 11:36: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=2ECqHBAN3rDV9yo1zqeLO+ji9lVIoh6IkMKI7b6YgP4=; b=oS80ddL9JKrLI832FyF/YZ0Tle XhNW7VnERD2mlgwqW31I2kpusnMd0R24cQb1KsRQTVm9sCszNaPKvgShHK3TMtu+RT8+KGxoWZ1Ur 3u/mz4kV02u+23kJgMau/bmF7/LGlEDiXfKZZKlAhCnnFDGnchxodbO4QWCtW9DlPg1hiWkZyDKjH hKJTQ5P9LkG6j6U/gvlK+h3HUuLnFfCJ4SdDOMEtQoOJD+CzW32KqgPdczHjXSFSHJpPgiX+BEZl4 pNzNk/Yiz1JZvfw9Z3Fno2RXcf3kmwB9lEDFEtEnExW5QOI4WIrdE6ATiqVHxeWgkDo2kzMGr3cgQ AN7FD0/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrSR-0000000CYq7-0VmT; Thu, 10 Oct 2024 11:35:51 +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 1syrQP-0000000CY9O-2zTh for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:33:49 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5398b589032so1347474e87.1 for ; Thu, 10 Oct 2024 04:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560024; x=1729164824; 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=v1UBSJoCf1Z5ktoUl0v0M3ed/okZW3qEn6a0MNSS1TXEPXYBar21kmXPyYLsbU6jJj ev+Qy677pFMoDNNEJMqFNkdDfhp29saHxln0C7Pk8A0MFwFzVCDuDCQOhd3APah8kL9d kbCNWnJlgcsJymXIGy1vE3GMuuhRM17VJ2OwoZbvp5MWdSK6kvRAVDPwTzQFyGPQ4SAM exWwMi5SYQaPFx0N3bopt/iD1eOMuaNtnOQBddjX67yBDy7nDFJVyAuRx0Vox7lkP7q+ 0mDb1ACScLRE96sb1j3YR8cZVTxlXCLwxJH2j0gLnkDijYopDjJu831er7ItHA/XRrLS SwDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560024; x=1729164824; 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=g3P9jOn7H+Pgu6AbMKIV5LMPOaVCHDsD3n+2mjTG/SuvctNoaKfR7gY+ll6fIVXZFT Be+54DcWeeGSr0+b4kgsJ6RH9X+C3bOlD4a4hch9G70zoDImyhsNj0RtsaZDbvSUhAdD MXjGu04n/8Q7y4x4SFjC0eb+QPNK+gpXTN4FJfDaQ09F9mZmsD1edwezyygvgmM1O4YE a5I/EIyPmnDYP3DvQ/OGAh3pPPzcAQZY3yjvblW5HkSrI7s6mi2m93w1N3ePgwDZYLez QOl/Gn32GVj4dOaIsjZ4yNEnvCsIRD1gV3ypwcXxuYFdqeBYOLinqdbEeNX6uELNohqd oYCw== X-Gm-Message-State: AOJu0YxtMKhiRsXJfLG1vZQrOYWdUbiQdPdpd8ir2uZezFm+vA1vow7N BKGXwA2NeDbSfvpKvOo/s/LDhP/DWRXRD4m4WBZZyiIFRH0wwDFyDDMgUVM/cEw= X-Google-Smtp-Source: AGHT+IEzOwjSeRaNRAgIP2djHbcgDjxIdas3zeUxGw2eRXDLl+1CJu9P76G7kqLMU7BvW+xxCPu7BQ== X-Received: by 2002:a05:6512:31ca:b0:52c:e17c:cd7b with SMTP id 2adb3069b0e04-539c489fecdmr5606542e87.22.1728560023941; Thu, 10 Oct 2024 04:33:43 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:42 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:39 +0200 Subject: [PATCH RFC 01/28] ARM: Prepare includes for generic entry MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-1-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043345_790796_E465FB40 X-CRM114-Status: GOOD ( 14.04 ) 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 Thu Oct 10 11:33:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13829989 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 57DC3CF11D0 for ; Thu, 10 Oct 2024 11:38: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=R4LTFu04v+ewJrCMf1qStO/yKKemj/dlkSOHqQ2h8u0=; b=bNpigo2A2PJPAbumph2KQ1E7Q+ rB3qAglz8m6ccp9h1T3XjrmqnNsZ9a/rIr4gAkcI5TYl4jzTRyjaiQdwQxQEKIrNgibs1cUxp4ou8 JPEW574EGoO7hVJhj84l3MzERND88/vaXpe+B/FwUnC70sP7AGyyjFHbbmM4NJyS15SR8RsiZMlrq 45qCGhX5X9l7YwVS7IorCQFFFqh83MN1MKH8j/i0xyQS5TS2vKV+Uh1si1LA0XSybmipHyrwwBPsg nPV4Ze6LCgaz4aw6OeEFn4i8vMNkct8UtQI5szX30rsRdI51TXYoVyt4IvK7iyYeXAPwUd8SAFuFt ql2yNo+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrVA-0000000CZaK-20n1; Thu, 10 Oct 2024 11:38:40 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQR-0000000CY9e-3J26 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:33:51 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a994ecf79e7so133828166b.0 for ; Thu, 10 Oct 2024 04:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560026; x=1729164826; 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=xI+boc9EMzHnIBxaHgisioCvUTZcyKlgAsrSigIWi0VMcAbnmTrH3nK6GtLeqOUt1v IWTgKQNbDDv7TAz8VqxWDSIbGroif4R3jNjKeX9UpaNh7n5SL7vOXCL+ywOLGLEHbefq LrtyiLElVR7O6MZZBBGltyvEgF/60WLCDiRR6cvNZDRxkR/mU+GHEQE0E4Qv7ZFGjiRd maUH6sF0E/CQZK+HpgEWsWCTsf2j6Jzk1p2P8VGuUIkx/gQn+pIitC4N88MS8cIUKjE2 HkuQydcX/nS6+h/A/XInlc3jFgOWks4AoUAlGLdVMLtqLNxup00JbVZHBLqSnwzU9rcn DxIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560026; x=1729164826; 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=qqv9fTiDwurRug8l03Ys61YJabp6RfXvs+m8zuhcjzi+ztIBajETAcljDg4RKfeont q0Ir/kkIxluqc0/qFysqoeMHUfmh1TWS9gk9SErQ0B/6fke7BrkutlXn7hRBdwA+XJdQ gqwVUzw6UduswpGRztkXH/7S6mu1JnGkThl9jU0KMI8vu5DJEjrYwg68C9spUQnWw0t6 9okExad19gNLS8CzCfOf6eq1INS1GdLEEykq1csfO+OCJixd3Yi2XDjqyv72k8FOmlCn 8kkv5NSSzcJfpejvd7+gtJBQ4IAXeoJvf+AJxAJhUpOKvrQD6tPrhKFZREL/Q9rSt2YS rKJg== X-Gm-Message-State: AOJu0YxBbIXpVkMxsios2rEsLkYiXaQxdtJ6psqWySF2Q85eLqAUT4qJ X1LKGIYS6NCVYM4xYhR8yN2emqODbsXhvDDlRxVWT0h6LQBIibGhxQnK8cIhZnI= X-Google-Smtp-Source: AGHT+IF/7BdKriGHfpakAch78gEDyPg7g4F5Squ3DH3oytxrvyGsFjm+zrnSb3mJBDsLPEmr+DbRWQ== X-Received: by 2002:a17:907:7e84:b0:a99:62a4:3fc1 with SMTP id a640c23a62f3a-a998d315001mr502326466b.49.1728560026025; Thu, 10 Oct 2024 04:33:46 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:44 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:40 +0200 Subject: [PATCH RFC 02/28] ARM: ptrace: Split report_syscall() MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-2-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043347_861481_B6A8684A X-CRM114-Status: GOOD ( 14.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 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 Thu Oct 10 11:33: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: 13829991 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 54649CF11D2 for ; Thu, 10 Oct 2024 11:40:18 +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=P8ALwNhKvz3ae9K751Zi6dTsn1 ufWwFdD3OhHUrdB0lE9WiSPq8/Gec1CuloKVrLYFnFOMI/sEg8+Y22ubUqzQ1fTlw+HAxdltL+GAj J/cVl5Sq/L/0qlyMG7f3e2edpjUu0EwbAMjeNIlxsf+GBFsoW6MOyqxp1dRPoLAeM+3YkwjDi8EDE cqYpvf9BOi9mLTELh/VMb3cm1nyC7zv8fqqXn64w6S5gyHYadDTfiX6ixbVteR3jM6TLj13WRkKDl A4D+u6+rPmqjAtBeu+iwe81TagD+Ig3+FiMBwrVWz+5+7E75FGxyCpAhaOAiM0zsah0KzyPMKXdBW sGUrHhWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrWX-0000000CZzL-2meW; Thu, 10 Oct 2024 11:40:05 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQT-0000000CYA5-3YVF for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:33:53 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso1046350a12.3 for ; Thu, 10 Oct 2024 04:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560028; x=1729164828; 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=jLp82/UDEB/V6ZO/o+4KIxuTLIG+9/1OmytPp9OVKq3Bp6krIB8xMlB4EkwbVtnPuD goD6nx9NWPfHIoMGpkbk5SoRJmR0nH7sfJ1fTGWzI+qEkEkX5GB/J3MrJ5GFk5+xBMz3 3LleEip6aPKx9uRU09f/yZRmlpDru3t579F1NLXV9VvzIUZPGCAxV3R0Kn1RtmQ6bR8S lRLCAXxPlPTKEHDzEu+1goG0CyD4I5WubMvEqgQg5Rq1iaGkjTYE5b6NPetdPRoJFZ8+ hZMgL4l88iixq7+KBqm3scvqcdJyWCsGEFcH5Fh2IuZ1V/9oOADwOMvHvTuxeFq/Y6Bc RHQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560028; x=1729164828; 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=ddkiN/nrSdjxwLcr9ZuPVIURqUpzMzCLs65sgSJIZtPHgl50SMKxNXkl6kALQndg1j XbUj42l0D1/s7HmugIs5Dq+2tuhZ5zzMNnoaT1MJvEZNrRFc/XtJGWoCEQxgXVNq/eLp OusMemAgTvAiUWxlz3k/ZLyfWaKfx9Pm5U6eVULVOo6HURM3EqykUlETUBuH1xL8yHmn NY5Pj+XgfsT0uQogZOWusoJwaJv4z7MC1WPn6WT97pGIadft/AIgoLzdWNlkZxVetsea PQSnd8wmtHNG6pmJaAQwb/NVsPj9WuY5+btLzOLVZndLbPDoCN5+R1UXUoIuCPTfecu5 mcvQ== X-Gm-Message-State: AOJu0YwMTSJnsnhgSKY/xcHKyHBaHoMxo0EehaK6qmYC83h8NYZiFcbH 8qA9g5MbeBwfnn+mXnIhLZacDGjYaH6kFu4KNIpv0YqUZ7xlVGt6PgZ4EaQPbEk= X-Google-Smtp-Source: AGHT+IGmKNJPIbWGBVZJfO8+b8zw8XAoQP29rf5wbFh2YjSEj93didfv6G/hdQTs2PTJu3Y9jhUpkw== X-Received: by 2002:a17:907:360d:b0:a99:adc1:1432 with SMTP id a640c23a62f3a-a99adc11551mr84023666b.65.1728560028080; Thu, 10 Oct 2024 04:33:48 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:46 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:41 +0200 Subject: [PATCH RFC 03/28] ARM: entry: Skip ret_slow_syscall label MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-3-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043349_992294_CE1E49B5 X-CRM114-Status: GOOD ( 11.08 ) 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 Thu Oct 10 11:33: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: 13829992 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 1EAA1CF11D2 for ; Thu, 10 Oct 2024 11:41: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=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=; b=odaegtXsQMx4tfc7X4PGzpVzFT 1OL/ZB+mSvYAdVsNch2F6J3THcc5gmqJkF2kCzhwTl993pT7GIPz3Vv8L/c/3fQZKL7z2QU2TNSoz jmtMaWuIYQM72BtOoKNqw2RwP9rwRhCXk8jubSPCX12E86lf1O7oM8SO3+MGJpRjHwSUCJKiQbG8l JRFOmGoEtBZPUP1XJ2qTyWyHu0MEjOIXFEC2bwP5Qfz4lU4GR3JaAjbKtUmcsFn4BssTmbAOGd3nf feOhdTC6b+cukvuto3gI+lq/5oR+7lnyYQghV8Ep22sayI/y/vLPE7gRpeCWpK8ZYGcRWFJJIGa8F c5L2cJkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrXs-0000000CaDT-2S44; Thu, 10 Oct 2024 11:41:28 +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 1syrQW-0000000CYAb-17C9 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:33:56 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2fac6b3c220so12352021fa.2 for ; Thu, 10 Oct 2024 04:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560030; x=1729164830; 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=t31gOHv7FscNVsIsBzC7KYHWTJJwU7B3sxPafNjxUhBx+72Vs9lbCTLK1ug5WE4RL7 HSgov+hpQW+nV8ZRKExQrVjWPD7CsKie0KbBtt9IBP/VU5MU0zcGGXNJO3BxSqovCdJw 4o6JudFvH5WyJTw6ZKVoomutH2/eH76R96NY2i3vo1kmRlPgItz05xErlNbeYqEZmhFD U3kDJJeeH1P3awMDn1DfNAOMJX/dn0Po6625rM5BNze+clFkpdSFclY/UwxFI+J83afD 9RGFnmXo8vGJO+kOqWnUkuO+O1T7a82B+wNAxY4Y3Iy8obHHyZCVBg7nsTSfWuLKhfgU Dy/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560030; x=1729164830; 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=WW6n1IZnkNqrHAPb+BEQx2lWI9Fu61basNW8hPk8wyahRIGtYyh1Qts23IxSh+6UXA tl2RG29r/gvymXG7FXzv7QhUAU0tCcw50oCiVnHUZUAD7ZGwOrWBNGVPIFvXeR+qduXw E+17cOxZAfYuxXAVNbFf3cC3+n7r3wRKW22ZSQWURfYQNNQdxMm3eUuHubgecrVSW3P/ LS2C6UxK4A5g7K7xkKK+xYXJtit1EckEpBTVc9vaCoNlXXwM1CbqXxg30qXj7ybj3rT+ 4IgcIXtZn0KIrDbNrlC3Ed9VIaO6q6UbXaNSz7HhUpI7i6HNXRSpoNBnSmVPcoqd7PbZ eRRQ== X-Gm-Message-State: AOJu0Yzdz8y9O0fWEAGawEfdmK6EG1HYnm9svgau7ke3ReJ8PYmDtGo0 GzC6dKat6zvr+zY4GJxRpCo3N5yXA8MC3Qt769Gi7sxxIqpKmIJlGAgSkXjuWmU= X-Google-Smtp-Source: AGHT+IFYXNUhaWmpiLq2q8xgds0Kykd3WYlCfTU5AddMN69mncHRj5KixgWaFupTNP5HEIlSrViaww== X-Received: by 2002:a2e:b8cb:0:b0:2f3:f1ee:2256 with SMTP id 38308e7fff4ca-2fb18807a65mr56092621fa.44.1728560030103; Thu, 10 Oct 2024 04:33:50 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:48 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:42 +0200 Subject: [PATCH RFC 04/28] ARM: process: Rewrite ret_from_fork i C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-4-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043352_418396_09539486 X-CRM114-Status: GOOD ( 19.10 ) 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 Thu Oct 10 11:33: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: 13829993 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 E4856CF11D2 for ; Thu, 10 Oct 2024 11:43: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=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=2TzLo/LIXLNRtx+wnCFLQrngr4 2h49vp9c/lqgpzNGnidBFV3aZT4liqrELs4HAjBNq7afvkuvojtXZu8cpGXF8Kcgz7SxDUUvqtiVQ fF0P8DVLxDlpa5lGaFn8xD2nmlko7OLTB1pTSi6C67HTFtPBgFjI3O8aMJq6UBVR9FU+kEjCMAQ3+ dvottwTO7579lCiI60QfTQdAsAgVALvS9oS65785/x3EPXwz7gMN1irFusEFZjOjcjcXWmOPARTmZ aBIxPZpMuES6L6Q1lXxHcc7K+U2INThBZJG/LmlRQzUaII6/mKzbP5QLASceaRCGoV+SB8Bhjs/zv +gH/85Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrZC-0000000CaTB-27qw; Thu, 10 Oct 2024 11:42:50 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQY-0000000CYBF-0m1R for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:33:59 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a99415adecaso340232266b.0 for ; Thu, 10 Oct 2024 04:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560032; x=1729164832; 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=ipomTfq3QAuPECC8zB0yxzPijzl6L3G2hbVFlRrrxgJnihN0xDuCXmSXHuURmqXSsU vB1fh7c/9e5Mem7q81JgKGwi2KCTTMiACQWaFQzQRten2E08Ar6NO4gY7B+pDZG9YZ9Z 76lCI6gEP5CJkxbNxXecqluvpYQnaCR/wwYDegmCQeFJEQ8VV/Bu8C+SOw6XxdjCNRZ6 Fo9kzkwCIZOzzbfJkMlPyvOAPUTi8HdWcjvBUeSLIoZNqkfggIzwJfUUYCYSf67ZVl8t TPqtysNXrKutlKWk3UiRKdPooQBdKdYuGADDIfnfyn4VqNLMss9o1tOUZ+Y6yYyGpOiG 8ayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560032; x=1729164832; 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=JKGsrpWiBMEOiknUilGxcW/xOzF/jswO70OdXmpliY1mPfZZk4oB4VSFflgaqhP4+m GsP48CzQbh5VvjeRWHppTLHAb49LQlXfMR0+tKONUFqGMmaR4d0m7KzL/D9vrhxW9O9y YXFjg3RlSGxs6Rf//d6JIG9xl/J6Omz4tDHSDqQ/r0tZqzU3e0Uq4IorPo6w8LHxcYNg gn65DeuWRaAOvnxsqnMIWlogMhnwuIZc07LhQBfpW5O8xbJzlkMe/y1bho58K4+ka2/i zfdx1p38JlB9tKMaexxPDRVIa1j5An81hhvoTjqAN0id0iEJl7ERAuom4MLLhDKMuboZ YJmQ== X-Gm-Message-State: AOJu0YwhggdrwLq1MWOyegUvqQq70yB5wXXQnPbTVb/jBwP4N9jkFcWG YDPvPg/o9fVvIcZGAGe7ql6DtLu9CQDXKxbJxSQjbGkazGNqJ5hjFE6zO1sRTW4= X-Google-Smtp-Source: AGHT+IFaoE3sZWLkTplU7TDESmJsAO9u+n0GW9GsY4BElZ/Wg4eEpzfSZ1AqFssYL+f+8cp61QXAgw== X-Received: by 2002:a17:906:6a11:b0:a86:8f9b:ef6e with SMTP id a640c23a62f3a-a99a10f7328mr306580766b.13.1728560032206; Thu, 10 Oct 2024 04:33:52 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:50 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:43 +0200 Subject: [PATCH RFC 05/28] ARM: process: Remove local restart MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-5-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043354_264071_B7B48409 X-CRM114-Status: GOOD ( 22.67 ) 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 Thu Oct 10 11:33: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: 13829994 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 3B97ECF11D2 for ; Thu, 10 Oct 2024 11:44: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=MQAt5SKeBz56FAHiHxrYIQX+VEnQ+LorFKx32LG+SI8=; b=0/junopiBQBNj4FkFQ2cU/Sncu nE7qFPNifOwsKT3xmWF2vno3gw52a11AWEsGAZJd3l/0O6gx4exrhVBEMwjJ4XjoWIIwwqGJ8eatF i3PpaXXe5XUT88940XjU3iT6Qrle4U3JRV0HUFl80WXwGxpPjjbU4w/aukVd0iwWFG/kZCcwlW7og NrBypXr4+H6ix0A7c3ZZX8zenQu1XOL3S18ZrH2oT6gxUXcvwGYFPZe8Bk+GJ5N7I3WTDbFiQJxMh icUFICa9dzZPq1H/uwwY/gFyx+YdZiv8pwmQQj3xn24rT2yUGK5pcgM7QosfMzIETYCXp+zFd9IXW nc/yeoDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syraV-0000000Cahf-0sYo; Thu, 10 Oct 2024 11:44:11 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQY-0000000CYBp-3X6I for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:00 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a9982159d98so132436566b.1 for ; Thu, 10 Oct 2024 04:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560033; x=1729164833; 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=FDqOGqgDQJl5n88mpoc1tD+Tn6LNVr/aHAkWFbu4bqobTrgXq3PxoUHCADSPLJK5BT 3b5oFqA94zwIDHTSib8+6aCaG/NYObrSbER4N8Eay4CDRRaL9ndvddsnvnpzratZQlwJ /fANtG4Mp9YNfpJnfcCQOPPcLXXQ9lZ9mXzOvqadjM/ZZWqlnkf/+HZqTNdl+AphNJk1 pkYJWFdqMzd4dtAqsEiVEe0rEyt/OQj6Rbcm/yxfip03PTbfPVlGu5QHwVPs3AyvSeRw 0Y1ZozJIdr06XYHx7HkvROHzqSfRauJNepTdsNoOx2u0qIg4bWqD2Ffsse0GQSRN1cZV W1uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560033; x=1729164833; 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=jjdFv3X4voWntKBSwjen+uOc9cspCRW5jx3EQ353nBn43DTyGgaYeL38G1f9Sqb3Fq s/h95HPjtosrruE1YL2YysOTpDQbiU8E0/dR1Ewwjvne6P9IZVQaoaHjjMN7u8jP8ztk 8SvJpwykiLkkOo5saOOiEuqdNSdP+2r0JThdknKKIZpphK0NO2Ut85mE61DMV4xxutiw XhZZspNuaAc694R74G7u4ajOdgTh9l3pU3s1zGsNijAdAqy3+VKNTTRDrYm8pDpANnqU bn2W7tSVckimI+ili8xxhe02MOryBX4YBHnylEiZ4AsllyGNhY/wjEo/M2M0QP39YB8B xAoA== X-Gm-Message-State: AOJu0YxsvnRPEkKnCTs1FRbAv3QMQUbAxU/JwRebuWAFF+x2b7kIR3Xg yU2lBH79Xd/zBnA2uQG4hmKSUt0Bir0P6wUnah1VFg+GJIQ6ygMKlZhUhVqDc7s= X-Google-Smtp-Source: AGHT+IECf+nIoR64vGLK0N0tRyy3m6kGQh9nhQM+SGfR2yrRMxhPLMUSOA5Znclos1a6qtcyfJhm9w== X-Received: by 2002:a17:907:3e23:b0:a8a:78bb:1e2 with SMTP id a640c23a62f3a-a998d117c0bmr654465266b.6.1728560033384; Thu, 10 Oct 2024 04:33:53 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:52 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:44 +0200 Subject: [PATCH RFC 06/28] ARM: entry: Invoke syscalls using C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-6-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043354_948138_3942F28F X-CRM114-Status: GOOD ( 27.48 ) 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 Thu Oct 10 11:33: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: 13829995 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 909B7CF11D2 for ; Thu, 10 Oct 2024 11:45:43 +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=XFmj7kIFXkFzqTaCpgfCzY8Nvv xYdUyI19AI1BfRFBWZfri9JQv57OiKWLMoLSS7+0bKanPAo61DWlkrho/YXAezpvTvs++EVOAJ5WU yYc8SK0lPhvIYf55IEXZ0X5/jii0vX4yJJwwHdyMOR7NeUOZ9tM5hfxr5zN6vw8QfYM6qKfGs3sxe Aij11B8WXya+NUFYzDbbXXCKbygv6YXL549IhFkgYtppRlb8fAWFh6JhEDZXnuNnT3/SzmoTyqPrC JD1VTAcvhKm6yg0fhmA4g+eUrOPhPllw2Q+hg1+6hx0YNBkBRiQkohRzad2yEcE0mwJca1mkaY849 20awXQTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrbp-0000000Catj-3THs; Thu, 10 Oct 2024 11:45:33 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQb-0000000CYD0-0Zbo for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:01 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c87c7d6ad4so1031894a12.3 for ; Thu, 10 Oct 2024 04:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560035; x=1729164835; 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=QRNrKo6nkuZKbMzJ4QkUN6zNtfWlknULyhMuyuRhQwkG9VrBkYqawwwMOVcyL1/egC LNP+B4OGjRhKDWlbWNXba4lNiSFGe5Aa8hJT2XlqW6+xVJj8tvka5sEZDhJEJwvJRYt8 HFqlgDJLZJNbuOZDFKok7HbEVjrzm2rT5zIY1g0tdPAI4lZG8Y1IDyTl+K32VohXD05Z kVCJMs6yLbPtn5+Swgy6proubby/Dh5PvK1BAd6FlrEatoMpCFEcjNgd7wxYFHG+QPPW JzlBvRMSku6CWS8yXpaKE1YxOUeoG2gyUQDtfybfc2PzzWZuImlAEtYqF4Ktu0Y0A3bd DmcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560035; x=1729164835; 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=h57gTVLW3ue8qohvmwCwH40tsg+bNcsnVn6FWFWJtURUAgA5ududMXsJq9ydw9zNS7 vjLWPvEJ0X6D1H5z5TWMm3SVLzBbKXsrTKsv1ky495WN6rVLi8KLqy4m4ZCAjj7Jj6zV H5PrFGA+c/5mvpXrMfpJ2elD/Vc1HgwTjCoGmXUVVbn1JrBGVJ9HyO5i7xqEgvmPVlM6 SD9MGCheX/WKDX4CoO/WB650aofIBq57NCENrIA3iq1wu41d3WkdV5xVK4kYRXRvAbn2 MR8eKcSSqMybDaoKCiBb/d3H4F4lndQPXqMH8NguZQYBeWwwdR3EA3SOTkDULcEJ1zyQ 35Gg== X-Gm-Message-State: AOJu0Ywe/q+HHTpzcha3FwfF0NYIKXsZxeophn950g4TrZ/kwo7pI92y gwIkREo11677otC7G0mdquyNuHqEpiyHyuBY/ulebJaPNvxU2sTyPDFx0NGzBVk= X-Google-Smtp-Source: AGHT+IEIU5Pj5ZFEwE9UNRPJZ2YyGwVO4NXzcsvArZ+4K3EO08VhOOCr6/3XirfwIGeg5+bwIqCr5w== X-Received: by 2002:a17:907:5083:b0:a99:8edf:a367 with SMTP id a640c23a62f3a-a998edfa4cbmr371973966b.57.1728560035569; Thu, 10 Oct 2024 04:33:55 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:54 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:45 +0200 Subject: [PATCH RFC 07/28] ARM: entry: Rewrite two asm calls in C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-7-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043357_431879_3E6ED160 X-CRM114-Status: GOOD ( 17.45 ) 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 Thu Oct 10 11:33: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: 13829997 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 8D07FCF11D2 for ; Thu, 10 Oct 2024 11:47:08 +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=RMlrRCCIcZHX1sSauSUw2uswo4 u81wbuZJQh4YGL9tp2XCD2BshsbdiYttd5fWG7WMEDkivSUa2TLJpGVuHAKr3JbpumWWKPluPVw1c a0XLwfQ9URtA0SZSHH3NT5VTmQvgwYYJJ01EEA6d8jXW1NbGpaXFckTb3RgCv5jE0NFoR3llVhxdM 5kN3ROUwDVga+1q7J3F8enUYeYu6TyVZ3M5IBk7dWG6RyaWFAq7BuhoUKzBgGuUDwjqWUvQ8aP7VA KiO2UvuzKOAJtnyIdK3j3CNyhe6spmvKCmdCAQX2zFCf5YZbyHeAovsVXYIc7StqnBpJOQUkV/LKC gwIV1j6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrdD-0000000CbEE-2Ajz; Thu, 10 Oct 2024 11:46:59 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQd-0000000CYDZ-22Ty for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:02 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a9943897c07so114204266b.3 for ; Thu, 10 Oct 2024 04:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560037; x=1729164837; 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=PHVG2SbTJfEfadU0n8p/Fvmd0j5+HmR9Fi9A41NJP4Af/gTZuciZNtdb/ALPpo3ND/ 8feT5dqE+6N6Hr8jjrFHk7MFieqwd+Epg5C8Yy4C69sUZ90A+3SmPCuttmHSuDesigW2 iqTOBLCa5jyrESLsRocM1ZfZdIOdZlRTnW5Nd+R5+/wRYitArpKdXhsF2fFwvsEKkeCF s1Cdlynd7inssVXEymEIunLFd4JPEENYxNM3is3C0/LcKXkKFXSuu0W5DPcw4oepKkgx 8N3/fF6tX30QNiG1lVO5i8K+hzu2VDiQGONXY07kn9USDzppT/mZOkBQZg8VNDPEfG+a qMRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560037; x=1729164837; 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=cvcH4LMO+gww772xIK1001iDA5yVmfnnmtI8lp3fbhDo9y99RgU4bTzXU090HnYECt 6AcSfitY/1qeqTQ6o/cgJ4P/qgex4ivj9kbuRdubzdYQpp3ixmqFzOtIPIZnu4Oiba1i CwwGrL8cZT54xz2BjltSi8kcOxYXarI1/+gdYyijiJEWHvuQAGS0wDEYKA3YFoeW2IyP iimf50GONYwgeKFDPVaEoiIGu4o2y608frnmA6cpnw6jw+kREJ1mE7gG1ax2aD+60/QG cvr7HJY8ph2BvxoQz8tZzK9WtyjX6BfRlXYlseYoxCD5u2BoDN1/7qyunLwf7WPBmom8 jTFg== X-Gm-Message-State: AOJu0YzdA8VEAv/UQvNHAKN5jffMbUoN1zaiGF/ZLoydrT08JtNDZOIb cS6/oQkQzaiKGvxrTKLAWg6KDyGEVrs8vCWgvshBCemneMEpFm6/NTmmKVvMOjE= X-Google-Smtp-Source: AGHT+IFukWWZ+4l7WL4Af/FV3llg/yA4aFqolHoqsZkfDC6Tj/Nvfup8eye8T7q53dHtZfNUaRUeAQ== X-Received: by 2002:a17:907:e2c1:b0:a8d:3085:a7b1 with SMTP id a640c23a62f3a-a998d205f31mr531467266b.38.1728560037608; Thu, 10 Oct 2024 04:33:57 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:56 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:46 +0200 Subject: [PATCH RFC 08/28] ARM: entry: Move trace entry to C function MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-8-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043359_614757_6D448F35 X-CRM114-Status: GOOD ( 15.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 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 Thu Oct 10 11:33: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: 13830000 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 B7661CF11D0 for ; Thu, 10 Oct 2024 11:52: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=wP1nC9llP2df/xsfs1zPIJ3oMrkiGOdpltxFcj+OFqQ=; b=l//bqOiQJLU3spsvw4aJbro8mq hdeZnx08VJ5ZBsaZDtAtxDwTVL9mGRPgNEuCd1ijXTlSzBVs6xWzcK8MOO/7ePAyuTQWEu7PQLW48 65aQtWoPWV9VkqLrmBdEiRevsHJqn7c/dHODak3N6ms14rgzyOQSqZyvaA+fuKk0up8K3A7EkTtJD 6GXttaQchmvVT47pi6uIfw1eXQUZ2jiD2DEgpFKiQ11pMlBZI/M+3K4NNxKcv1Q1zGILDudpvB9OB KcFNpzj/gKpURJxNxxCAeSztj6TUb1IMP13p+GOjwC/BGuHgAzdnAdmyC5WlvsVRX9/igmsWXfHDy UbThzDww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrhx-0000000Cc52-0wsM; Thu, 10 Oct 2024 11:51:53 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQf-0000000CYEn-3KcF for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:08 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a995f56ea2dso132003866b.1 for ; Thu, 10 Oct 2024 04:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560040; x=1729164840; 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=lp4Ni1zMDLaiG5qqpk4l6FSB+iNUJRTr0mB1O4ZSh2kOL6LIrdO3fcdOFATRi4/mSR pYYEelNSsGpBJgc9UBcG6MgTU33yGzW5SANbXDu83vWVig1HVp5baAymsnPfpiamplO2 THwpeR0wYVrTwrlAAGMn31f3JocFIK7j5FqlgdaD3zGSd18UH3NDHSuwSWp7ss8B6ktr Pd8qwrlTiMBQ25UdnAGArEB4Y3xXd/26Wnvp0K5ALv0nbBi85cd7vVSSnTTrP9jBGFpt Gi0iux4DOKTKZbsMulnxtixrbKLxMTxCcXBlUsTOJ1hxnS2ehSC/Y6qbIUKz6Kj3EzI9 gU5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560040; x=1729164840; 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=qFGpRTYTlHePGN3dTMQ2z7pfr58U91h7F2e5woK9t50fYvm3mgDAAB5zZVHix4L/8A kHqEwse/k+6DgexKgK5/gHSNOe626UmjuUWlkTxSQP6E4gYX88/mXbx/2RHnzKpbAI2g rauDUJVoN7IfO5DmK+VbjBDFIDFQKcSFkG9LcFznV/PXi7wQ6Qwj3+GXyJvIT12O6DV7 i5IZr9CbUvjf2DYMpQRx05ksrfu/UtMkdtmxcF+ltp38k770uvm7GfD88vECgi+fpu1j Z9bynKmqhMbOhK9gUSFVX8dyESPEotmbVqjSbpVVgDUzrQ2kIp1qyS4+wtNVeaVu4Hxm 9x3g== X-Gm-Message-State: AOJu0Yy+gkSFgiKMc4EX0S8SUgTWHhbjAN/oMUSLSyL82TwJQKLnEGU2 JBkrPzQo2S7mjl6bLzkJSYhZVSaCB5lPuo8J6xk+kINj5EPDQ/ZXVO8ijZPEMuA= X-Google-Smtp-Source: AGHT+IFueHlgiHQRsmvP//M3I79F0TgX4HWc1hPrICoYFkYMHOkR70UMR7ValzDrWStV4N5tCJsulQ== X-Received: by 2002:a17:907:1c82:b0:a99:379b:6b2c with SMTP id a640c23a62f3a-a998d31be20mr575777066b.42.1728560039732; Thu, 10 Oct 2024 04:33:59 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:58 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:47 +0200 Subject: [PATCH RFC 09/28] ARM: entry: save the syscall sp in thread_info MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-9-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043401_966858_93AAEADE X-CRM114-Status: GOOD ( 18.90 ) 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 Thu Oct 10 11:33: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: 13829998 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 720B0CF11D2 for ; Thu, 10 Oct 2024 11:48: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=HAeVmp86zd6G4zC8AXuoLcHe5Kdpm6JlP18N2B6Kh/4=; b=mLXYBQpZLONm2YJX1pNKtSJ/PD nJJdCU0uVzDB0Fr5vqVcZvEAXLDluAPEZepPLtCDs3x8rXoSmW233TP8dQGvNMqTSNlGmRGKwSg0g q+4R4nrn36gdmK1L9GydOFKEghAZQjBAyaDS65d1PzYLdkGNScoSSv1VVXQJGeAoDu3mms1YqdigD M7QBgJhiIAShkIefgLPxfzhX5QYBeKbWlZ/1WfMWHBF6YZ/ut0LbI6/P4FOhW3e+mpFb1Q4SQuv88 sgT0u84PjwxShN+6VbNHC1ibtq3fwky+1vGcGN+LyHiVM6Md361ogBvi0WXO0lEUQqUu/eduCv3NP b0SaSnWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syreY-0000000Cbf8-1V4H; Thu, 10 Oct 2024 11:48:22 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQg-0000000CYFJ-3h1n for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:07 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c8967dd2c7so981847a12.1 for ; Thu, 10 Oct 2024 04:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560041; x=1729164841; 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=jxCVKcVd9wm63C4HZfDsKJJKjPMxiKgjJwGq4+HqIGrlm17iX+O5gZOPPXndwkVL5W J1ANLEAjyliNfjYeMXuMoJXnpfiYHDGGRgPZ+Mo3mvlIhc82Rq6fynG2hxgprREgQBsU jHBXAJKLxr/JdagPSzdp+UTEVvd2MKD/tNeZAAUe98rT85Tm7mVqBUwhr7532xI3clNb DMt2FV5A2Urhq3GaCp7Yfgicjqx4k5+vKjgdjxOHzJhDfTO4fxWCJX/Kw6gKKMz3ZxJ0 IcQK6y/284VQedkdiYJiceS9Y9VvcGIrazgo6Z+EmT7IOIvVL4ZK4RtDYcoMNE2Dm9+o ON3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560041; x=1729164841; 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=cfUQVW8OY0xBDY2HT5cJle3+UeCqhyF9KQHmc+P30H4I5gJBZISMcXlRk7TTqrBSGp 3eP6fT5vBMEYUDx+jddgemopemhZJnx/w0cyJpMg1PD8bY6D9MRIbDM52XjJfuecgij5 ffp5eCc42CmZsUmG1qv909vZqEBRPIHukZ37JVFqMzpjJYEsSHXeDWHRaffksOGlY4OF 7Vp4tVgoJA33rRYTpqEGgFoHQNsytYVMkmv6q25h8UmDYyV3m95sPp/TIPzGWiSxC4VD nJNjfIGCvqA2kyqtrWxFRCc32w/8Jr9iQWlvZ9E8lPEjbWdd9uhb8b/ZWddDZ/7TZdKb 7zeA== X-Gm-Message-State: AOJu0Yz/lDgK5sz46to2zErYKb+XVKYkIGydJbUujjfKTXmYT0icmtWY Sykus4obb1hdovFRqJ4Og/G0bqZl4QZ/Ir/DcLdWJFkD0kagUdfJ/5oyQI1PBes= X-Google-Smtp-Source: AGHT+IFrAl7fhKtOJ2kSM3VOQKvmdXs79itsAMaItGxniru0zsN4lIQu3jpddRsSAmCeamwhHFpCEQ== X-Received: by 2002:a17:907:940f:b0:a99:499f:4cb7 with SMTP id a640c23a62f3a-a998d1aad4fmr589155066b.23.1728560040814; Thu, 10 Oct 2024 04:34:00 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:00 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:48 +0200 Subject: [PATCH RFC 10/28] ARM: entry: move all tracing invocation to C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-10-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043402_972048_3CCCCA51 X-CRM114-Status: GOOD ( 21.19 ) 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 Thu Oct 10 11:33: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: 13829999 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 002A5CF11D0 for ; Thu, 10 Oct 2024 11:50: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=+Ojsf1FDD3J/q7BWA6tzk7mG2LcyH7oHP8nC2ES9d2U=; b=jlAHvl95PXWuALNcdc71/Z1yFD J0WTry93IRNt8Z8CDIQS4KoFHImUSaltdRx6KKp2536Ht+nFr/o8pkNhu3CBOmexZ36wJ2zDtALhn 1QzWk1TlMx+a2CddXJvoK/vW52QGskHaSo4nB2BF5X6srJztOCUdL7rwpe50WkKK74eKxhRnDBVp0 qj1IKZ9e7sxhsZWZYw2hOt+wyZseHRphPlsl5qPmD/HCa2IE9rrNw0gwAlzH89E9vfoDHh3PxDLCU HlIhaVCa9KPO7RQMhXGsBXEqMOf3vN9041h1WQLGdrojYOt9L6EInH5v/mGkzYKAiPhU8GnWAC2+Z Pi2KL9Nw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrg7-0000000Cbww-3Cvq; Thu, 10 Oct 2024 11:49:59 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQh-0000000CYGA-3xtP for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:07 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c924667851so948654a12.3 for ; Thu, 10 Oct 2024 04:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560042; x=1729164842; 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=yZuB5kGIE8vuGZz8X2nbvCt7D1pSlFUj99eQrji9vNnMJjZ4Xs6drtkzUDOnYjpvOp bY7hNwdYAzWvL6++Fp8mNsh5DydKIjp/QuW112mVU8u2zOq6mvGlDWW++IkqX/su83m0 JCiF/UeYQz3W49dNdQA8oKg6qBGK8iSqF3bOznVeQqJIYautCck4VynkXJZFVTID9VbC Gov6fehoqxS5vEXBKE0XnWtwBxdwlanlcweJUIOtzlEcbWTzNCOTRmcMUfkFEY3mQPnb Ga20v1lkLIzD4+ioUDlaTYy1UoY8hrcR6HNQoDC+ymUNmGk4mK1x6z2B9ucUi7LWo9ic wdyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560042; x=1729164842; 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=kRUT06Jc3/CqqkjCPhYuvEkX8464BoqevQjzC/194fLzxPF42IvNQZKuE8uBrpdosD nUB+orpaSO0qhdDUedQIxsk0CmuXdmLMU7LiVuitDWK1eo9J+oLbfk1k116PrTxzBgJ5 IEHArWKcgTrui3YWHaE83ktzgBRl6AzKvy3TXqPdLJlwb91uiiY6E+HZHSzwGYfIOKgo aD1Nx0E4btcs3Cot4IH5EoGzrHPzX2z3U4i3XOyeHRcPhZa+v2Vex+uUI1SkhZMlmZHs F2zcRcbSKYfBTcOKMlpr0Qx0SpXf9kpi7fOacu8WMAE1UA2qf2tHmYM/6+V5/b390xdT liiA== X-Gm-Message-State: AOJu0YxAEE3JAgTJANKMq8qk8Hftwv8zKQIEk9rA9vqKmLvhGJqsn9ug P2UHj9eItY1nkl6WrDTfuaFQXtR7P0GOfdPP9uS4ZhyB9XAYXNWTqinkfETasbI= X-Google-Smtp-Source: AGHT+IEnD0Vl7gplgYYFyXbkA3DuwA6nUrMhw3YhotT21n+Ce3lTwwfBSn8bVKNVmOPEtF7j8R0Y7g== X-Received: by 2002:a17:907:9705:b0:a99:4b58:c0b7 with SMTP id a640c23a62f3a-a999e8f41fbmr307100666b.57.1728560042464; Thu, 10 Oct 2024 04:34:02 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:01 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:49 +0200 Subject: [PATCH RFC 11/28] ARM: entry: Merge the common and trace entry code MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-11-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043404_026545_B03C33EE X-CRM114-Status: GOOD ( 24.50 ) 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 Thu Oct 10 11:33: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: 13830001 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 08253CF11D2 for ; Thu, 10 Oct 2024 11:53:24 +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=FNptCsszatlnP0FGIEin8aUjuh P8dOoiUrVgdcqCW5rui35sZhWv4QPfbOpTDtVeXTZ7iBqvFD9uArmdHZVkGZOMlpADd8c6hax4PVA tAV+j8C68ICND5lQ+ZCoH52paeRKqGxhQZ9d8zyQuUFXW6Znrx6ANNWukwGMdK2lHTz9F870AXYs7 HkNGKpI9nVJthlKNRnZbfNH7YqmpYKow/LxSEQIPEHggIlOUTiECau6Ff5P4hzTjpbylBxGogN9Rw QtEswkhzJf11z0X7Xzb+Af/5gtY/8OdWN2rHt4LVjmdLwZsutbcS+2HyoP1tU338WtApnrBJKtTKg lKQM6vPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrjG-0000000CcC4-41s1; Thu, 10 Oct 2024 11:53:15 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQj-0000000CYGa-0WSM for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:08 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a93c1cc74fdso139032966b.3 for ; Thu, 10 Oct 2024 04:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560043; x=1729164843; 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=Yi1aI23Fn3GZF04nJb0fHKuf2DqGghT9/JlnwdUQKVzu+7hExCSEv5dbdkx/yknM6h 89kt81JFaOB3LFG6qOElCWfsfKt25JNtq4L+LRAKoq5czwqIWWU2KDc5pBn8EnKO7fIh kPqr3FILAGWmZa6JmF2Ne3uZ61XJklVLRMsVrJV3QxbFVNPFdsslc92y9LIHvHcFedYl qyHNnyCIgLiNWZ6a28SrCbwoaiPENXW+Uo8Un1cNnQ85WC5R6O7BdgzsVkppKmq3r1Fp otv6R9VvP0y7+c0hCYBTA/uF/fFuthoV2lapWyIk+vsa8SLUHjfl83+ie8uv6DsQgqSK YMsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560043; x=1729164843; 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=v029YA7EXaXknwhi0laVwQems+6kwHSxoe8RzL3iat8Y8fZxRTJbCzSz8tH9r0Cl5N R1POXM5Y+EpmttP/RFBuLINpQPJoyUb3gHy/6JjuoiQZUs4BZpBieOdhKWppwcQIxmyh u97q+XRQSYWs/7zpm6D6gIoj2i/EW/scwWwx3qDmU1xmAWSAW0YNfOq9EdP6lqRIZxLD z7Af9GwK8ocaZnWFEni1ATWHNFMWU1N2DJhcEvjSM6NssKoTYeHVxBNqKR5xMhRKnk96 GmQcxDnFSzXlI9iPPMyuHRodCKhJzEbOJ1955K/SIFLmqTbfxhSxm3eJAG4puttOQ0sx NhQw== X-Gm-Message-State: AOJu0Yy587DZujcLw8jqrpNnNFvFWiFjPsPB7ZG3gdSoV9r8nNPsy20V eBcTiA7RMzO+by56mMLO4zUm6fxwncUPgnoagGbqzlRJvvvMp8tBOXJ4l/M7isM= X-Google-Smtp-Source: AGHT+IHADUgNkk0hVOK1JFXtca7534b5748m22i8omloPYXVG1QKj3GD3Xqq0GICp3+Pdqz4GrjLzQ== X-Received: by 2002:a17:906:730b:b0:a99:4a87:cc7c with SMTP id a640c23a62f3a-a998d34c373mr530776766b.58.1728560043498; Thu, 10 Oct 2024 04:34:03 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:03 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:50 +0200 Subject: [PATCH RFC 12/28] ARM: entry: Rename syscall invocation MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-12-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043405_216226_99E8B118 X-CRM114-Status: GOOD ( 15.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 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 Thu Oct 10 11:33: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: 13830002 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 E7FCECF11D0 for ; Thu, 10 Oct 2024 11:54:48 +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=AnuahYA4i0qeAFjFTJNcgGABSz 2uOLI+RvnmP7YjO1DJfS5HNenpUXr2FpaSW4KkWZMilnWP6nYddukSZEsOJK4yfjvSniOnBHHfass nqfdH4GuYx7tV0infu7VVVBaFG3tgOT4QLM3MvmLuNj0daafe/SvVCml9HMpAcK8joWfng8eAygf+ 1JN0KH2xySTDOJYnQoUbUxmisRQPn3Q9opnT2JSTUgJbY0Ab2dq0Lv6M7oKqG1XIHCltXmpdL7LvG ZHrzCuWhSRnXl5hBGTyU/i8R4StlRB5xiiQFpbwVrNaG3Yy6WbDXRhqMgce3Wspxpy/vu2zNhxDDv ly/oNA/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrkc-0000000CcRF-0v6N; Thu, 10 Oct 2024 11:54:38 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQl-0000000CYHa-3mmj for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:12 +0000 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5c8af23a4fcso989985a12.0 for ; Thu, 10 Oct 2024 04:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560046; x=1729164846; 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=gTl4dKLnzEyH30Oo+HHEW8vwEqi/RVfqO6/s1mGQNu2d1nvjUIbIvgdAPpI67t0Pq4 EfX0xLueOZJJxHL9UkCPbn2Bhv6wO32KHxt6DHU5pGTk4RNQlrPSnG32ctVxpyU5dyFh iyVAx2EBJfUST0syrM4cpHXCOaQGywwFa9u+js3t0V8ZlrpqxGAHxD01yDzLgyWDfX52 2IJySH1d1KX+DvJEOV6fygSeqEhgAtTWWAXfobRVvDzSNU6x1bUKifxdyuCK6f0psnZ/ WyotPR+/Z82RUxn1plxrYQgOz4nNUbXM36F8d/fM2kxAsh/HZFdBXcMDhkBNiDPGMO5B VJmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560046; x=1729164846; 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=vo5fuYx8K8Tk3LH3eBGQ3jjZXwq71ChUHDwQtmweGik8hwEuEQmG5VOtzmax3vGBM1 Vl99DquuhqQm6ctFhMrbA4nk1komh7MkcsPT+3sVuWMBjzurP6ayF59gNu58Ty/2hG2H oFIEoFe2UvCVVPnF6cNIZHKUs379MOneb/8irNrCdMf/vkGYGYAtkBwXOVtE4W8ZdPqu UpqepLSn612Nbr5RC7ZtAlCieAQgJ4L4FV2zlmvzkq/gDW27V9nFf82lPAgPUeCNCGe/ ftmE/ZPXwdK8k0Mgc7zj7fNATeHLoMyF7titd3vmDAK5xwT7S893qhpeiXCCJrCvXLxW 8tug== X-Gm-Message-State: AOJu0YxVEqroOYTiyDN9EqjElW0wwrNZHHmmZTAJzliLmos8ly8HvPGH IIKDyRH4vQXm5uhTDHJb1iHwP18R3UacZt+wkDhmSyeE85lbHidzfjIhg9OSjWU= X-Google-Smtp-Source: AGHT+IGmc9n6VQianQrFxqDVPOVQDV5YCcFVpaGOA7jxGuHzUJl/veHr7yvG1GzHaeWsSpHDbkqbxQ== X-Received: by 2002:a17:906:c151:b0:a8d:3338:a497 with SMTP id a640c23a62f3a-a999e628c38mr322887866b.4.1728560045769; Thu, 10 Oct 2024 04:34:05 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:04 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:51 +0200 Subject: [PATCH RFC 13/28] ARM: entry: Create user_mode_enter/exit MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-13-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043408_092991_774DAFDA X-CRM114-Status: GOOD ( 19.19 ) 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 Thu Oct 10 11:33: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: 13830006 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 3E8A0CF11D0 for ; Thu, 10 Oct 2024 11:57:32 +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=3UseuiXAyxhmWoy95LB4R6hJae e7Lj9EG7RHXw5FChbm74ksUrs/dgQITi4/cdbRV6f3sgIdMXASZjveZeYnKqtGosNmzSODdZVWZwl idya3ToM+h0RdT3R5UBD2GO6IPlIZJ08LpXaOmMPPmy8t4H79x2MIvwbaznGVACGSyCCULa21QalJ xocZ7mFUA5ygXkgTkSe00OcoBso8iiggzwT1uT/rzvnKRSwsCEgBJ3Y/5Nihh0zcp2rMWpLDMO5Vi Uk+5M1x6/12SR4BM24+CwjT9AceRRP70Mw6o/Zg3zU08+Ppb8NyES+W+7ayZoIU3Z7nrhMcihANY1 +glon8dw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrnF-0000000Ccl5-1FV8; Thu, 10 Oct 2024 11:57:21 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQm-0000000CYIB-3hr4 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:14 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c896b9b3e1so1039541a12.2 for ; Thu, 10 Oct 2024 04:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560047; x=1729164847; 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=ul8hR04WbnDssMDoYr5TCeXosM1xDT63JLka0bTEzmPAMkDMPXWuiuZJSbU8jN2gLg 8nMAhLc0yj8DoVSR12CuvuOCbB4bjzuwXHeMz1npvymoBCS7FXa80LKxF3Xd9R4zj3sG EEq5KZ24kn/ewKgv7nSHBThCojgX68dnOxiF/D26yp6bxMLq/Ee275EFcZ2L+VAF1cAz Bpz7xhZYHc5mLp2N0PvnjDx/XT0qq7r3kwYeC/bNgDPIwhoEBA+LF0+CTM3bx3zkSpCy SQgCe9536dfMBQhxa3GRetXvjmAFXyrymiVQurVtCEJFGRsx1k9t3wwD5qKw1sh3pHej DMKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560047; x=1729164847; 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=oFlGJUL44Vw7n3s5p9VL6TXANmwIC8yLTDeZBO6yS4rnJUfLv+7JjJYOwNsakvtV9l DH5P6Zb4KMPpQO5SVR0UUUvkGJJtqvX8obTvOLBVlBlpXYlnas4szJ/vXa25nxNBo9zE b8GW2PJBSWXc/4NE5WnHu/+e0JC84s1xohcFZqp+HDPlmdmj1nqHlewXTguECoQRUOcq dKeiK6yaJfsKwOZE07kW/v7EUuGAYxjDdHtxes9c6QQ0pdhhqFGJDkqMDASJ81mCwRBv 5Vt5fVKcR4nKYhv4UjAd6/hAul2qVi4kWNDw88dHE+PnADc3sACcQKYkVrqJEcV/PZ03 sZOA== X-Gm-Message-State: AOJu0YwdtwhFsZZuXoO0FLyi/ESIWrCRgKMg60RciHTJSWR9QAhzmNNG FqutuhTNce3TgUpIo+cVbkT0xx4kVC5NAXrTnKAWlbZeTYLz7fKlMgwvDhHJRSA= X-Google-Smtp-Source: AGHT+IFtzNsWgaNiVVEj8OP/CCcRSjW/L9HZNJ/xW1811pDAMg/fQ7GHSKZ1D1WYhG9TkEqfw7s76w== X-Received: by 2002:a17:907:e2d3:b0:a99:52aa:cae9 with SMTP id a640c23a62f3a-a998d1a256bmr530617366b.24.1728560046838; Thu, 10 Oct 2024 04:34:06 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:06 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:52 +0200 Subject: [PATCH RFC 14/28] ARM: entry: Drop trace argument from usr_entry macro MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-14-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043408_962305_272F76BD X-CRM114-Status: GOOD ( 12.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 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 Thu Oct 10 11:33: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: 13830005 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 B8407CF11D2 for ; Thu, 10 Oct 2024 11:56: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=qPx4kMCDrheeY8xWYJ0qE47ahtpfJ0dLdCDyA5qyaAo=; b=B8uaerNcN1R8TQM8gUfFN6JhIk a/c6wT3nAmLq5r9IIhFF7XcwasDhaMMFC3numLgSIn9rX1rMNcTEJPtFpLH+pe+5ewdR2nNOAF7ar tufLxI/6SXfFQRAnbGD5lZEsZ3DtfE0EF5MIxB+MAesa4wYBOoKon1ZsVGCDxLoFWFUQgHOS+Bo95 cbAkMio/wYp5Tcm6MglawBmFfFptRc7vK3mTlvn/KDJe9Ib8vtMxgmnjjr6xgSPcxsuWoVGHZkMF1 NwwuNELsFhK1kyCTNX5cQzJFe/hnwhfGFJkhbILCkVq7I6xFB9Qb01BqT4QArbomM5RM9Oa+SyhpF UyapwVnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrlw-0000000CcbV-0r5e; Thu, 10 Oct 2024 11:56:00 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQo-0000000CYJ0-00Ff for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:14 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a9957588566so98680366b.3 for ; Thu, 10 Oct 2024 04:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560048; x=1729164848; 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=W2RX+0iuE+nPBho7uXYrVqI0/k36gBWOJeLQIN5lLii2eK9m0FMhx1zKdXLshZXRQQ CCpNTegBMCSJMgz/IYbsOZ80k4GITPu+Rze4YtHmK0nifCdFbPAHvlFP21MeNhvTQPpG rdXsoioMowyAeDzHLrTXufmALU9r/q99HRhlUCYMXOqm0iDtGaiHj4xb+oEKjzth8LZ3 OTOdWJdfnSz1g+/gGNALs+0i4r2DP+ssB3wSnFm4AL1hJDwftkOeOxizEw2om3iP884h RimX4LKMkotb4IvRjX6Dd+TIAgxFnNYfRTgzr/EeFEOViOJn97ajlWvJRt7Lb0PC2bBk KfQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560048; x=1729164848; 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=ofior+/FW97OHbnTYy9akFefLLVTsm3Bh3EekfBjmJ+FYVT1hr9yao4ZhqU+9DUnk0 90z1xZfprte+ZeJcVYkDeihQxGocEFbym+F4/xJAbHvqPctECdarilJU349dgRKVum3u G7lZkWejN+ARayk9e35rMGEdHwfinNB9Nod96/ZNM8i0h89vJDGD/DbM84I+5wpKr9gN G0sLKEX0+J/qGqitW2jukDhJGVWFrkpHdsRp4pxNkvXkL/yMJsdgYbm/hf/sES43Ukh6 YHklIcPdSLMUDhYmhZTeWe/44OakLIN8+9uSwGWDVxCQuWEbjPSFG0O5pPc/2JuESBuw R9YQ== X-Gm-Message-State: AOJu0YzK9Ve+FxGa/b7tukz9wUKSy8Vdw/GVW9aoMh4nastGRGv4xUGm 3TaxQUkdFGsgBy4I5mwd4Ybwv5ci2s9ieImDHQ4mvIHzPF2wdk7jWeNlzq6Jb3U= X-Google-Smtp-Source: AGHT+IEPVi1mk+/SGvuJTkVQs54hGFUGD5KsWVr2ppK+fAaiWlRn48WKs9o66a2GQRtPuO9/UgXQ1w== X-Received: by 2002:a17:907:7da0:b0:a99:4e17:cdf2 with SMTP id a640c23a62f3a-a998d329a02mr518892266b.46.1728560047912; Thu, 10 Oct 2024 04:34:07 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:07 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:53 +0200 Subject: [PATCH RFC 15/28] ARM: entry: Separate call path for syscall SWI entry MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-15-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043410_151424_4841507C X-CRM114-Status: GOOD ( 18.67 ) 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 Thu Oct 10 11:33: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: 13830007 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 0AE4FCF11D3 for ; Thu, 10 Oct 2024 11:58:54 +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=QiCmSIGHUZECgnJQfgeIr1Zf7B vAbWgrd21irHMJz/m6pU9E3WaDdL0MGUHHPSTSgdH+W6p6XcoNPNWznbJggoXjuOqwK9ZutsKbtO6 Gw00MlgaYsU639yakVPKfZ3MEerhasSPG6ixV4HUWK94pBGnWqk+Rurpv2nLLAvhkadAOdtVYMvaG u3EtDt9t0pLeRuRiT1iotrePNNvVAjxwhaHVTi0vI9GXeTY1yV28kBloozev8WnMCgw/hxsjvB/zB PHI4Qnh0ditEL0TOgwqve68YYoEq/ZFafEjgnLhiqK0UjCDANd/ykZ9wwQ5egYkWizfjHZ/zxtEgw cCBADTXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syroX-0000000Ccui-02rP; Thu, 10 Oct 2024 11:58:41 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQr-0000000CYKM-2o0X for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:18 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a995f56ea2dso132029366b.1 for ; Thu, 10 Oct 2024 04:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560051; x=1729164851; 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=NAZy9cUj92LcGIGngqzv7De26JmfnYm7m5DNmyKhSzxNO2AvBKkhoyCMbMvwqd2Ak3 heRwapvHcWOmAMSlCVAvAW+W2/9O4c9zH/u9fL6ELBBdqsp3H0obs/r3Sg4HALQa6SI+ nR9S7dO+tZf3OhFhYFbMUv9jQTkJbdZzChDr5rS4z1UuQImfUwki4B2qAeKY2OeNpjS2 S0XuM1QxRFDwboG8hdtE9KMkCtUrn4PfNh3ZfVkfoDZ29n0ig8ffA/7gwkomVseiYEE9 tQxxouhWQBFj0X3HYDULWgxbRkqtHyKxDfAuOis8WrOaQ59Do9H/9J8jbO06O6UuKwNS Q0fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560051; x=1729164851; 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=Kgz6u2aAxHQdIchlLGkBqCUivTTuZsQElzdsQISm47B+hXow62SSkG2PLtU3LjNO6l LRw+UOhvcOkjhLCchS/MpKF1UQeY9kD4stwtOns1frAX81xFoEtf1CbhqILAxvTVHVXF acZtjdSdrULJMSfM+GEOcfj0R+DTsquucXnHyytZF8Jde/jQTaMD36C9KVlhQoQcSI9J 976leHHSS0upr1Ob91g739i7lIfzSei6vfkdHa0BQvFFWYzWgyHHYoEF4/NB+PzJuSCx o8KzoDWUogLdgJ7L4rhnVF5sWuFTz+rC/F0tymNGlX8/nYVEOFNXzcycpL49Wp0yDhtl pu5A== X-Gm-Message-State: AOJu0YwvY1rpDcuCOLDwjiL4QeygsI01A6Ipozxm+xEM5AI25QT8l3Yb m4vJa10OOxZeQytUS2CNWJxcXCT+HU/IeEN/mwTAQSS4mX93yXIMEFCL9fSDHms= X-Google-Smtp-Source: AGHT+IE5VMKxvHaqB8TM4UQMzMj1+qpZY8SgS8d9OXFElPL9iiC2IKmw/Xc8WMoNH9f/aynvyMEWdg== X-Received: by 2002:a17:907:e65c:b0:a99:5773:3612 with SMTP id a640c23a62f3a-a998d202140mr531002866b.36.1728560049978; Thu, 10 Oct 2024 04:34:09 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:08 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:54 +0200 Subject: [PATCH RFC 16/28] ARM: entry: Drop argument to asm_irqentry macros MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-16-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043413_763909_9FDFA8ED X-CRM114-Status: GOOD ( 13.38 ) 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 Thu Oct 10 11:33: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: 13830011 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 4651ECF11D0 for ; Thu, 10 Oct 2024 12:01:45 +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=jAJSRwFCT1TnzTwXmPKPnKmKj+ DkjQnfqPH24puVyY6oRHDsfDlPijKNe0w4f2BQtT1mQvWpMfS5IFGKSvmkYR6RoZ4lPeFYSKkjCdN YeiVjH/vUdfXG0a1/6EtWkmOf179jlFikbOzuiZJhKV/Gcp+uFm0i8Q1Us0Ix69QoRX57qIZryw/v RuicSfFfwozSOttRSIiEs3paFfAA82xhnYWnxuD2bc0dG1BSgBDSwKlK/XFrNzkCtbJO2XLijFoQf KDOZtSe8cs89So42rTVng9KhyhqREpu5bw8FKVukBP2wxzX6Cww+xusu24jgpIx0k/lhJS3XedRSJ UF+31Obg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrrJ-0000000CdY1-3Tcf; Thu, 10 Oct 2024 12:01:33 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQs-0000000CYKl-0aHV for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:19 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a9953bdc341so19032266b.2 for ; Thu, 10 Oct 2024 04:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560053; x=1729164853; 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=h9t5lPok6XSzJtiKtvC1kP5M2Iug4yqsNj0BwyV9R6aAzqPykp5P4nwNrJ9ocl439w zI1miKwB86SNixAj49GarceyoSfpFfy2OX4JvbgFTK6OH6qP5YS95En2/+py6NOoyXur xxhpfowy+0fRI76voPV1itCDponWGRyVj0zbugjGRpg/wRg6gG2CIFn1P7LR5f5SNRms 5MU44GIyZd0gNV6TM7DpT9kUoLtHXB4yX6NSVfg5iG1LiOXoAKGXzUKM2NXeC3LyKoYz AZ4ekyPWo20ynsSKE+Sa2kvzMuc1FTyI9Efcc46p08nlW1ASUbHqYWHlxtITLVUyFsrh NLNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560053; x=1729164853; 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=dl41tv7pGC6CRZ9k9IfBceGD7znRangB8W4gbWh0PRvjeCXY/q1AHXoCbtnRDAsD38 +Qz519+Zp1w7HQ8ChXYIbeaorzPuCPCdyNsIGh28ln8sRd7OR2PnVPV6HyFlV3QX7lPA /8XEdxk5XEaSKGZWZoor/y/hk4nPc9c8omeqY5FBmhawgZ/CCtHr3v/AeK44wma8wsks 3bVWUPaVDnsgSAuNXe0D5E23TECGc9hR4Df9Jesoul+LpZljJu1OAv7mpRHtZIUaJmBp I8c7O5lNzQDLt5gyIF3/fRu2zwD65E/oJqjlXwS/vE8Y9LQln0dsEY54NLgtbYVIzubd RVjw== X-Gm-Message-State: AOJu0YzV835Q69CnU18876OSKLtZ1vrLP9iZBO93FbYTKIf12q71yXv1 p33Kv20u9rjsG43QUBrMR1cZ1erlwaLIORpUVdosbQu0OCXolgEoz2zGz5EU4Fg= X-Google-Smtp-Source: AGHT+IHL5fhjnV7jrHCiVi1KTSPjzJB1MdYFxv8NsvHT8D9zQW+FbMo3EZMj/2II5YwtAlSsYXswMA== X-Received: by 2002:a17:906:d259:b0:a99:42e7:21f with SMTP id a640c23a62f3a-a998d224f32mr538373366b.37.1728560052587; Thu, 10 Oct 2024 04:34:12 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:12 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:55 +0200 Subject: [PATCH RFC 17/28] ARM: entry: Implement syscall_exit_to_user_mode() MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-17-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043414_225191_25DDE356 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 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 Thu Oct 10 11:33: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: 13830010 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 097CDCF11D5 for ; Thu, 10 Oct 2024 12:00:17 +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=427QfwqDt6N9qVCGZnTLyoEGum 7jZSGPyYfqG9iDtexsNP54DO5SP5olJcqZs2wodkRTRksPTu1AfXHMDe7vh4kWVA1Cixq3FUHfhNs 33CfgZde8zLnSTyBcRQ5M+itUcSXoe9xptwCmA2W13ZbHyk06vFrIXd9+ul6Sm73bUOxNWNraAX2l KtikC+rTe9+pOSiTj1p/cbSzJ5shIqLKMPGkBvgIJaKp5nS0OyGzUT6g2UFgEz2ybcs2MZh3qzEyd F5scFO2bqI5soy/I4aDDCsvJbVc/XgFWbouWfSxDHfVsCK6troGvdiqIQEqR1gtqP5+Cl6tJ3BLnV LNJljjjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrpq-0000000Cd3d-2QnZ; Thu, 10 Oct 2024 12:00:02 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQt-0000000CYLF-2p92 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:19 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a99650da839so133344666b.2 for ; Thu, 10 Oct 2024 04:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560054; x=1729164854; 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=nagsQ+K22T/a5F5DByPl51Dqh7HxftF5p7xvxTEIiKTvDOytCcolT7FLArcnDJ6obi 0IOGygai+wUFrTL9xtZYxGrExz5oIWRKV51Fskn3g2UB3UHPSLOshZhYii8Z7sOKtQZb CpCK4SFcIU7SQuetJdxXGYMxAeXCYlG0BeFaGzpTXdRx0+OGsUuJYksDWGhXuilQU25Y +ukSl1ww8Ve7sl/YWe7nOkS0In+8rTqxU+cOuWoDP0+piEw348X1ocrJ2G3WQ541IhNZ VNc2exeePsLPbJZufAORgUptZJT8T1Cl+sYQHnUXyEKD7FYaqrd+DwHiahVLokZef3qe B2Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560054; x=1729164854; 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=VWaHWDPBiI4UD9NySDB85UxCMFU8Fj9K5sPnGI+XO0VfOfPB0Y3sFFoPpjg7eCDid0 oeYth7GOR/6HhBesDtQzxcfMmwv5jutYyMVt72AgkuRmqllNQHsUKd+TbLCdHepcHVRX zgEsv2KHCwilVXa/qsO0H8oCglUQUKNOWmFL//Ya6wxNDsbmKt8JmXEBgPQrQJ46g+UM cqQR5qycBImlIiDn6wSahYZX8yJWne1r4Jp9TSzN3gfdTYWdUSbUZDtPnGhGJPZ5lwPt AexvyTon5mVlJ4omDyolD2VA9htby7lUxaUfD4qZQ7I/sOAxdZMnKKSrBZTHZ9Ou6yy1 uFTg== X-Gm-Message-State: AOJu0Yy4MzB6TX7j52FgsTyIQ6iNLP5dSo7GhuQGNaXWeIlbZGUf2vyR uGdhDmp0Ws8K5XrejUK+UYoOyBNhG1/258so+vIv82aD+oExmftlSOciC/uuS2g= X-Google-Smtp-Source: AGHT+IFDPzLaonbakRRWJT+0QxQclhlzU2yW7uKOVcDb6pVGDrHLXlnDxsO6QIKMg9pncKslUeaLQA== X-Received: by 2002:a17:907:3fa5:b0:a99:75ba:baa8 with SMTP id a640c23a62f3a-a998d1fa613mr557910666b.31.1728560053677; Thu, 10 Oct 2024 04:34:13 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:13 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:56 +0200 Subject: [PATCH RFC 18/28] ARM: entry: Drop the superfast ret_fast_syscall MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-18-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043415_749753_F48014FC X-CRM114-Status: GOOD ( 14.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 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 Thu Oct 10 11:33: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: 13830012 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 B364DCF11D0 for ; Thu, 10 Oct 2024 12:03:14 +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=RgPvhY3/dIDplTeFkyfexvkvdB X44zUI3A48fry4BAQbtzGI85dfJe1yNzMgIb+NjtRxUBZE/qofLqgZlMFPrVDFuVo2B0pBEdrOM6e SzM84Ru/UtE/rl1ItvHGG9Mh2Oxa8bcHd1ryRbNHJAK48v5b+DW9gcoYD5+Vr4Cj+uEhvnG0OzdHY awfUWQWUZCKD+eVJjdcVj/YSMGFT8gIkJvPqSewVjl676BudchqJiAFRuq7Bky07hWtiU6b9GhJtk CkAU1FlVAwbjQSZU1SyeT2JGRBAM2nPCgfyiYVi157P5toNQx0m5OAbMuG7MTVui7FGqlOTTYQ9lQ vlKTV++A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrsk-0000000Cdyf-3Bpv; Thu, 10 Oct 2024 12:03:02 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQu-0000000CYLb-3TGT for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:20 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a83562f9be9so100287666b.0 for ; Thu, 10 Oct 2024 04:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560055; x=1729164855; 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=M/c1mrbDVqXVJjIn40osX2mifl8JwKIqdxGa9L0IswbPSkjzC2IKYDhX4Iqw7yU01V uYD7mL5PPTFwYBT43V3ZrW1oxGS/2LK0Pc6eKyAAWPW0fgRYTGu86yKciUyB95++93Cz KoM+lJnGDUTq+N5zM+8MTQMEJzoIKA6w5nQsWN9MJPHphRE40DX++UpvcQ8/iXUuUz89 +XvLOte2pFR7Il7dpQPAn1TNH52sZBbEawUBBZZMn+B24dIhn+qBP0dVGT2UdiWksUPz RcIyFzSHjQhffX00kUwUkzzlR3M8OxZFV7h4T2hnM4I8yU9vSTfYmuuGmJshiZRdncRM VdaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560055; x=1729164855; 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=eYxILOuAJdH5Q2hKB0RMhBFzx2LHC5E1LvRf1VP6aQdubOj5Dn1v0onoITqSWFSH+w I9snqBarCiu4vCjCKR56QzfbFvsTX7GgXyjKuPe4ddHaduHNXoMBYDPJSEjJZXIwm+F/ NK/2y8RAIzvbrQOqwThT4pUyenYm93WQEL2/wO1nTdeYk+Atlqaf1nsWSe52UGyTyF1p Wz2VecKIfj2TKpkDgDpwmNQGjRubwpzkP04kRl7FPtvX0d5gG9BWXM51bYf+d9Ks/Gns uE+up1ny9vL2a3GgzA0gUhG0fCV6N9x6bHfz4UHoVkenhe7ggA3qbUFfrwhHg2SQrm5f AFdQ== X-Gm-Message-State: AOJu0YzTJLiHuVLXhabD8KF2ndVNeP7qeLvY5cTrhcpQIuRt+lHZTWUS KPQQf0GjigEP62uhwqB/RRWrzUoTbCE5wx/WWP2vQJMdA1j6yG/Z1QFUizzHA7k= X-Google-Smtp-Source: AGHT+IG4ChkXSJOOJVtKgVJOl19DQS8X/tzmbK2e58/g2XwPHPYY2o/CB6c01S2WX4Js3ghS2dg9FA== X-Received: by 2002:a17:907:8688:b0:a99:76a4:7052 with SMTP id a640c23a62f3a-a998d34db43mr548587466b.65.1728560054756; Thu, 10 Oct 2024 04:34:14 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:14 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:57 +0200 Subject: [PATCH RFC 19/28] ARM: entry: Remove fast and offset register restore MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-19-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043416_904569_47F05865 X-CRM114-Status: GOOD ( 13.88 ) 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 Thu Oct 10 11:33: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: 13830013 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 B67A9CF11D0 for ; Thu, 10 Oct 2024 12:04:35 +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=BQG/JLUZVeJ3k8//8AcTDdS8WN dadNPkuac70G/4XzEqxK0MyrN8xRNnBIYv6dvNZgT/PsubsnR8N6mWkW74DEtKe8DVBYM9bBsB9D0 UP+Smlyew9Vqq7m16QhX7G8AYeWq/gyLNp3BHpaAeQxVc2dgU9kpYGHsY821MYtQfI7H5ZzU7A7O6 txyBHVOVDYWTJ5BBevbrxx4lty9z3Zen4TqvPtJoYQmmnd+633efmDcgRbRB7Q9FFi8xYrvtvG9py ZEZiqL2exPeNTrDRczR6t8I0uaihOdhiGBGtgrELGXCN0ZaarjIl2qNDlSu3ft9KyBIiEV79GvBe1 PtIJIM2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syru3-0000000Ce7y-1kl5; Thu, 10 Oct 2024 12:04:23 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQv-0000000CYLy-2AFN for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:21 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a994c322aefso354142866b.1 for ; Thu, 10 Oct 2024 04:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560056; x=1729164856; 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=qQsZA1GyKnA8N2dhMSzCgGAZWfS999We8sHtljyW8YQsTl64afAof5KfbaXl8/zesv jv0YZ0ZuTQ8oPcKb6cO2qK9WWN2AhWYAC/7q6DCZw2t6VIwadS92xtKWfJS49IAxfu4K 5YJBFs7BROHXQNrl02EDaGyi+XH2htlXuAy3cPlaXpGimtCHQ6yh7Vtol/qasKr6nSFs 6s/gKWXESRkFQDlSHuBZGQn7+hcmUOHqAjmBo5IYR7LSwl722tS4zYePwh3MRw4JqSBX Ww3YC8Cu90rhfuSIcI2vjOzuVUxwRPgYuRwrAy/xdRkUj549qivotokbd2/ko8iIg1bc vLkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560056; x=1729164856; 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=YkhuUkAHoRvYyX5XuCXO//6D6XguApyxBUOcfkQzmZYzYp6WqfuAedLQbjvBhtVDnY U1GxiPsh4qhRP9rSgUiBv2ofCsCik0Ttu6LhbsMbhMEal7trFJVsdgEZipkj6c0BmlqI ExXqk/K3Qe/yx0QlkTgqEq6MRxXH3cu+F9N0dUwiuKZMWl8oo5OeHP6uib4xHmlPKMBe E/sdDWi/N6Xkdxl4vPAsxFyxRi+maaTFKDdfvhSpMv9bwaMh7DUixJkJeJm+6ramlsxc 6HXZqHvOl9KOcx4Q6uvzd6xV6qsU8YW6QK5RdEfX7TOKrO2Ay8Y5zVBJAtci1rtW7Q9R cKsg== X-Gm-Message-State: AOJu0YyVYAG3j1rtEqBPMFolsIXCLCtFQBaTPN83ibYYNBXh5Q9hSBYa ianbwtLr8c+GC5PHpJ1d3D7TO7fysPyQwL/YH2NnWKZCA0RUcAfUub3p9oMgBxs= X-Google-Smtp-Source: AGHT+IEHCTRRp7fVGYbHaZJRdCWztPF5Cmz1ArhsR37YdkkUHo8yQ2UvzGBEaqZF9J54+PdeX3iD/A== X-Received: by 2002:a17:906:eec7:b0:a77:ab9e:9202 with SMTP id a640c23a62f3a-a99a0eb9349mr287624366b.4.1728560056112; Thu, 10 Oct 2024 04:34:16 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:15 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:58 +0200 Subject: [PATCH RFC 20/28] ARM: entry: Untangle ret_fast_syscall/to_user MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-20-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043417_628698_04AAE082 X-CRM114-Status: GOOD ( 12.26 ) 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 Thu Oct 10 11:33: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: 13830109 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 700DDCF11E9 for ; Thu, 10 Oct 2024 13:16:18 +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=lxHUmBCRIpgvWscSDTLGxNANtL bDdecOHgdbq/9/afoe/4qIxw0ncHEGFNhf+KuiqMYM8erCd/npupxdljOTKvbvAsRipC3NWfNJKuZ 5UMScf83HV1r4kZ4gePPSvCQLlqSKIA30aYD+lG+MeMuQcNReSdgL47wTe8dmkEB557uFLwNRAJyz NfnW3aAb2yO+7wSouGh7BxpT6FtjKkhZPFXGvm7L3hf7g1lZ5WQ27ECTqhDRPQqQGL7+Wn78mfS7i RyDvZ7Yu9xRIQUdmeUBpGy+PwjRzpgDx0IY1WrR/aE2GIGZmn0g3oCGO2lrZf6oXkL+b1JSzeGjsP YhDEfyEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syt1X-0000000Csj1-0ds7; Thu, 10 Oct 2024 13:16:11 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQy-0000000CYNG-15Jt for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:23 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a9968114422so118918266b.2 for ; Thu, 10 Oct 2024 04:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560058; x=1729164858; 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=WuG4+7kwrrhdSKXUlhSyKUXJxAi/hDxt6efwYOZpTfompvxtyBLvfDdfQxfjXFT/8h 8uMrdEEzYmAjQKWMeB5dYfxvYqrQmv6iBf4aVNurdHN7xlyjhOPyFgEnojNiF3WP0Z0k guqDlQ10x9wrqfUf7UwrI+I5ZVV9ApKrEPGM6u4ayQVE0ar+gISUftJqBFHzIgOecZXl +D5Fgt5mUyPhg2VusWpRnpsnz/XA/a8OuT9Df0Z8CqerxSlQx5crz2EP4+lBpdOAHwQB J4HcnpMRDwKLP/rTpHZypljjoPp22zsi2nKg1m/goO+Rm6Xpm0k66hfNeVzr/wbttLjU Lghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560058; x=1729164858; 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=Apto7/8SrHBzJCUn56akDbcTvWOX3qkwzjstMWbUq1dFU4o+zRC3+Y3zpsW1C+a75S MkJIa4hWALGaTS/F/v+dFpXL7Emdn6TzFKwOeRnUIEkrBWlX2en+eWQ9e86KD4K6T94d Q66ebVZxlgvs0jJ6IrAvh3ohyGX9RHAYpGjvf7MaXl0f2W0M2gkeehsuP5r3tbFAE9TI mXyFHHOTRWqQdL9afo24LDmLvPKjs8SA7IV5jy9Pp5hzfJdDEf1jz4xxKvlcQosVnP/V JNqJ+dwlS/jNaEHy4OuPWQs22E7mgzWHnOyyi/zC4Rnec1gPbyb9n29rqqusBS7UwAnB IDzA== X-Gm-Message-State: AOJu0YyOHb62CG2oOWQ6HRzN1GR6AZohEsC9Uxq6Dq38W6WrhPGDn/YG T66/9Y+6/oInM6Z0rzPydIhX4ZlaNjCtVRKZ0N/gPWcWJqKrEpwqsrVN/4FgoPM= X-Google-Smtp-Source: AGHT+IHjkGGKiDc97wWL2KlgD9Onfb1ojmEjNcRbkL8DUMdOhIwDFVL57b9sjrWd7TF2zYrCFdqZEA== X-Received: by 2002:a17:907:7ba9:b0:a99:442e:34ac with SMTP id a640c23a62f3a-a999e8c9f03mr327117266b.40.1728560058140; Thu, 10 Oct 2024 04:34:18 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:16 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:59 +0200 Subject: [PATCH RFC 21/28] ARM: entry: Do not double-call exit functions MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-21-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043420_340494_6B4C7659 X-CRM114-Status: GOOD ( 17.57 ) 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 Thu Oct 10 11:34: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: 13830019 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 51F16CF11D0 for ; Thu, 10 Oct 2024 12:07:17 +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=vOLRv7uH5+QrpdYTL00Z8agWUj 3Wr8Spzmz+hdsYuYesCuj53r/y8sJqeAIT8isFwbzYIQYyTQU/N8Gk0DfXN8PnmXHgJBIxXDkXdqj wuwDEhRMS46tS5oRY0ZIKhP4Vm5BSLa9/4gx3P3nYBSEq7eE9e5uQlHxvFLswSwgFYXO9sSSJbuXX 8pwdFhGWXfeLKmQN8We3WtaUypv7vVB94Iyhl+dI70IV5Ao85SXr9a7gAIM5tWTLRHM0nSOdU1RU2 5PxmjQowUMwX3Q2aTfSbaNbxS4mXmywhr11/Bk/eciaeC7Cb76Miaj1joufDt1/JjRfZaUBAyYGd6 uPUeintA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrwh-0000000Cehj-3W7L; Thu, 10 Oct 2024 12:07:07 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQz-0000000CYOg-21WO for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:25 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a995ec65c35so137451866b.1 for ; Thu, 10 Oct 2024 04:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560060; x=1729164860; 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=Cl4AQ5W3CEI30Xf/9u0Blu4ZEYReGpBAhkLrN8g4SduZyUzB2CdzN50tKgeTiEZhxL 8yRG7ZT63it9uSPHTsvGVcprTo2IHZhuFoK8Av5N4vi0tcYrQXu3mfESJrXVelKJUJWX jRFIBR+R681TJgd4W9/HCLo07GcNdUECneFNGutNf5CB66OE9Z6Fa2tBVnDL9iaoeNDB qfEC6BJLCvnecvtCt3YsmG+xr56v8mmZlWIMx4ki6Lq0yFiAMM4/Pc6kA2LT57bOg1C0 rXrMWNdN19C68DizmDxXZ0QMRKZUBi82NXc1hviKcbx7gb6LbAdAiAImE9XeBtXvMb/7 j+dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560060; x=1729164860; 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=q/LpXL714TNanl2beTwo2H1RQim1V+eF7aQ7Pewtk00mA9PrNyV4Pz1tZym3AsHN9K Od3lxw4tUFMdDY+1WXx7TvLZ7N0nXITrLzpkjw5MqME4qcQjtNw51pOsJVMs+jj2zIy7 /ALumqfJrwtPYqFm1P/ELTaX3djmWK3Ha8ttMxLm3+OIkHojlSO3ZYeL0GBsfOXBaDBD aIxWdU8yfIE518X7ikGGQ8bIdUzeOiCIry2OsMwSaWahfTSy/FVcpo/xMnSA+vgJ7feZ XxJdKJvTWdEzp8slbQ06M48R+QBvYPAi9eeUUud9WQGZrF9WAJY0UAmqxyDZbuwOBZMg QaSg== X-Gm-Message-State: AOJu0YxEP1TGGm3R2/d3WNrzzzjWvLN/a6U4MxHF3B6oNsu6Ae648Oj8 /gmMOewmiwqz1gR1l1IM+KPPN+PPmoln3WaTdysYhqvdwcuJCi/p50t4CCWr2AM= X-Google-Smtp-Source: AGHT+IG0T9Kw9rtdvh8MtWNWqvxS8ro6kLfwIAoOvd9amat2XPjlnHbF8UXzNiDyhtYS8hL41xf2rA== X-Received: by 2002:a17:907:7f8e:b0:a8d:4954:c209 with SMTP id a640c23a62f3a-a99a13ae710mr266075066b.22.1728560060101; Thu, 10 Oct 2024 04:34:20 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:18 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:00 +0200 Subject: [PATCH RFC 22/28] ARM: entry: Move work processing to C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-22-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043421_559125_F9A4E0FE 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 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 Thu Oct 10 11:34: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: 13830020 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 56066CF11D0 for ; Thu, 10 Oct 2024 12:08:42 +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=QOzIFshtabAAuftkY/Tg4lWW5M viSm/fsnPSRoKwV/PrkdjIUz+nuTs7Fqa5GA7qUlxLTwb/+lsiuG+1ADVRMwOjzQblV6wr3ATHVpr kOuPuCKx2wCSDUXCB9qlcYZKFOUEjoUdenkGAnd0heganAwn/76DaIDoMdRWFlgRW9yZi6FrpbyZ2 YmvGcllIdprVrjx77ggTpZqdthqc9SITbseyY+fLtPs2bN1fYat8T/PtbnUNO0Q0MVNz0BGa+LLDM KoiC6cn6TMOl/Op9UERgAKSGcf2fkVGO9NTUi9Lcv/BW0FkcC00Ehb9VB+D8tqcZsGt2aaZk6h2RI IBli0SQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syry3-0000000CesP-03FI; Thu, 10 Oct 2024 12:08:31 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR2-0000000CYPK-0UwU for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:30 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a7aa086b077so115805766b.0 for ; Thu, 10 Oct 2024 04:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560062; x=1729164862; 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=mgCTZ/44EutcGKcUII1en5JHBXRPfjEPmkG0jKD1jJxbDrhF+iTKNHqa74aHd3YnEK j21QZwdBKZgyRMgg52Q/RPj8BFTR05hH9aSTlHPHGP28crNp/DoaQh2/1Fef0e3Q21e0 mI1b7CO0HZKYRmrH9wtzW8k4oEczq4hf+VEIG4Yfuxm6dOmbU/pTWb18FGw3Ef1q5sb1 jTS9Jeo6/xP222+DTy49QghJPAQTXmO+xplvsJ7IKkwTRv9NLpYf02NH13cEzlF+RSMW umKMszUJ8AoR70wCS7svhXRPcYGdr8rDIYW6+xxDKZxDz8HYmWfTIVQpHuEY/YckJx6w RdKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560062; x=1729164862; 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=iByZFmegQwZvrMuuqUMyicV+iDrMLIFOeFS2WGlUpCs19CnFw/pOFrnCvx3/uI5LZR 2lSwzWkaCGkfNq63jnWnlsu/OErrVWXZYwN28VcEjE8SWujSdvb8vbASNWpanXbw6y0T pXOgPys4M/3Lw4G3VqqWTq7s+KieDSTUooisrbAGs6Cg3kFJRbymc6XS1L2L3pUA+04r YyOD5ZZDD9FTQKH3wNAG4J1tNvNbgDLtoUFHFJco6omTmQUrS93zXzK26r9/h5cYpium GSsSNVjC6mo2RrFd+ZcSzfyfeoYZnhSTOWU2Lpmx0y3ggsjp3aLKR+HUEq9+2fdVfvVJ R/Mw== X-Gm-Message-State: AOJu0YyR8HKGdlCU9UsFgMY02gwWGrqiwmW9zFnpdqtC5Hus2b3JjOc5 k0U1TojA1F/Ci5WsozwQD/bMTNf4/MaJZJgMxAnYPVr/Ymy99htcR3hVIyn23IU= X-Google-Smtp-Source: AGHT+IFigyJ/4+OGI1gC8uCP0lgfYv0O7YK2EBVE6+TDguBMfdVneKhgbLHN8YNte2qxqNUZjO00NA== X-Received: by 2002:a17:907:944d:b0:a99:5baf:12a4 with SMTP id a640c23a62f3a-a999e695b35mr298335366b.17.1728560062133; Thu, 10 Oct 2024 04:34:22 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:20 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:01 +0200 Subject: [PATCH RFC 23/28] ARM: entry: Stop exiting syscalls like IRQs MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-23-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043424_227961_07F80777 X-CRM114-Status: GOOD ( 14.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 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 Thu Oct 10 11:34: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: 13830023 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 A29CECF11D0 for ; Thu, 10 Oct 2024 12:10:00 +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=hvAGTzXIz2zKPf76okyEENbQ3o GUU+XEo/8TzAvymysU8ajftPYTfSFRCzweM5j0wY+06s1sbsMmKaVT2RpL9SXU21VmM0KHOFm5zQZ UpZ6X9HLu4KUqDzZuG/Ty0EWluWvuVJ9yVxUc/6FZH72k4VzH/n4LZzsHvAwjZtyhWTOLrv4AAJIN aOs+k+MVcYX76Eya6uHmqeF0PDnvUKVulNZhfZxYLwzJ3Y3HKRu4pMUt1UJnfN/3kgT3qkNOwV/Jn iL8lmPLhWcx5dPHSayNHFmSPnZR8XhI8m9nZzol9tpAQUCLILNX3/AO8WPSq1BchWEKFo/7b9j/2u yo1DBZMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrzL-0000000Cf0D-3SbC; Thu, 10 Oct 2024 12:09:51 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR2-0000000CYPX-3onn for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:31 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a994ecf79e7so133918066b.0 for ; Thu, 10 Oct 2024 04:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560063; x=1729164863; 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=iMCIPuSMYYIuq7pMO852Dq4+L4D8k0BSvsE9dJ1jcEStXCZ7K31/loE9w9BeAq5/Qq c77lvw47iqCBxem+aNDs+lyVbcSn216k8eLbIqqF68HBqTGRDfClJhkhIkE9fPVZFNlX dy2tZmhNAnZYIahAhFyiJNY2vOlVpsMZnrqSNlqB8PCIaYJ7Vxj33Eqa+136SpexBVYt bdRRNJoluAr/lwT4QrTLWa4y1tmZzBVO+6v2Qd6I6dt4Ru22B4ewndyB+bgeY94uchtS hLqXOj7gz2KM3+2kZV7RrSI2PMgzBlW9hgTRjLleUdhm+gHKecu6W+D5Jw0C7DZeYlWT 0tEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560063; x=1729164863; 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=sJF+SwkhBPjsU6iwUAKAw90ZRUhSokT9N94iRVjrLpNHcUKzZNtOpLMfmvHs0BoNIi KzjU7N6zjP4dpYo/BkfvNgZ33+Zemr6rNttb5YEja8dIlqGlaByd1Tnq/Di0htX5eW6s OeXgBc05m8uGoKkh1WY6R7fGpeLW+XYnViWZE/K14MfZcGdajmlCFuEpqG/EQgAfmF8u qPcOkvGrgM2Ga/wyaOHeYSOFPEGo4oI5V2Og997RJcMHWzBon1ojEdQPxh1DoSO4O/+E OGNgv3OlP3Qwd96eL79VR8YcGhRv7nIoI9nRK792f/HKGAObmFDnZyaLmxOspyDAt7mx 1GRA== X-Gm-Message-State: AOJu0Yz/zYLW6poL53xig1XLF/JpAWCX3x65MAQH83/kqSwLoSxzrNlZ loy7uqREUaYLR6nmwimkWoOVVjmw8RkAc+RJgWw4BpP41RI7VXY1UutxA7ueXOo= X-Google-Smtp-Source: AGHT+IHJRHiR4KzKVHqPedhfFs92LdPjHSU6zPVuDKN5K3YQhsffs0YsSzQJndzJhUDXQSRYclCqMA== X-Received: by 2002:a17:907:e648:b0:a99:5985:bf39 with SMTP id a640c23a62f3a-a998d117e0amr515807466b.13.1728560063234; Thu, 10 Oct 2024 04:34:23 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:22 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:02 +0200 Subject: [PATCH RFC 24/28] ARM: entry: Complete syscall and IRQ transition to C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-24-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043425_048980_EB7C3E8D X-CRM114-Status: GOOD ( 17.25 ) 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 Thu Oct 10 11:34: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: 13830024 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 BEAEDCF11DA for ; Thu, 10 Oct 2024 12:11:27 +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=C0YBxYAEPsMvUo+G0C3Utctlsb V8f9MYVy3dxgqi7+PcDCnCyN96omXyXmFxlosN764niD41yu2zHt9CHjlA6LR0brUNvvTcFd3J+dN DccejgkOqRd4G5OUUTMoXeoYCnRiSXMkopJA+ZgKJQBxSTSxGCnNDUAMMh1cJ0ZVOLbt9frKZwyPQ RLWjpkR9JfHjhsM9n7fDu07bQLF4vfMaHkMvGewowe6zHDVGn4M5iYNPfxQPQnsYQoZQnngVuukfc rO8OKF3g8Ib0MclD0oht/6jTcDTbUZIwbwrnzxUSLML1isGUJfGVmKGoDw0LOGE5qOR6TnmjtQjYD fY3RDfAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sys0f-0000000Cf8h-1aBs; Thu, 10 Oct 2024 12:11:13 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR4-0000000CYQO-0Rsz for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:31 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a7aa086b077so115808866b.0 for ; Thu, 10 Oct 2024 04:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560064; x=1729164864; 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=pTTfvs4S8e+Dc/QUGZ9vy9ljNLHUt+snkKtHeA+R6iibA6eLs+3th67DOA+UdxF4HU UNxSzBHWW4cHP9QJcJVJcfdYKn3PaMmSYAJgYfzEPKJsL9n80khDsuaAE5ejbFegWfoW ykhWdo+4xXKDnmiadlAx9GKKRa/xuG9rwcEaEIvqt8KbXwMKhtBv1Rh42B/spnN7IKUl +MMU4ivymv0SprYkp15I7HF0gAxRtF0EmbVTYA9C+oziddl+ks6lUBAu3cHq82xPRX5W jHNb7JjRHITdaWJcvUo0qAEyfWYxqAKMVernfe46xwUBpj0tS4dnNfCKJFmF9VDQS7Hc E29A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560064; x=1729164864; 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=rbR7+DFvb+eYm9RqP8jSivVhspBWVyULgs39mocSI/mRHf9d4dmGVn4zg15CrC3P8g YZXrI54ZUgzu+91sRVv2eazcXTDSBhnjIohUFXNXmof4bbNjzrAEmBkRuSnsUZ6KhYaQ 6fXH91+mLGa8hZINs02u5ekrhgYhF7RaU5MRutzCOgYXevbfLVEnAEcFQTz7pZBLm67q xlcKBp0rKf1wWoRntNG8s9Tzm1HlNczKxuGSUY0EXvdrQKkMltAqtDMs68LmUHCcX2Ln mckIP7sm6AeSA0iCnh8Mm5Uz2551ZPZ45b0QfUHg80Pvz19fdk3YfPnf5cmsCXzM3aQH TKlw== X-Gm-Message-State: AOJu0YxMoNL59rc0vRkHz79x9HpRlzzmtvg1aJefbC3StuYXScbnd+fC Ymy1AnFs75VZn3wtJnbfRN8eM1h5vRZXX3vNqDYakGQwDbREySby/WkLTFEfP1w= X-Google-Smtp-Source: AGHT+IGSkGuyhdw8AmjZaYSG3AbwkYxBJPVivMy155PvJBG22/KVJmiGE/T4Z0mI0+yJzLqzOiUsfg== X-Received: by 2002:a17:906:c109:b0:a99:403e:2578 with SMTP id a640c23a62f3a-a999e628eb0mr313283366b.5.1728560064365; Thu, 10 Oct 2024 04:34:24 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:23 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:03 +0200 Subject: [PATCH RFC 25/28] ARM: entry: Create irqentry calls from kernel mode MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-25-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043426_186599_B502646F X-CRM114-Status: GOOD ( 14.21 ) 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 Thu Oct 10 11:34: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: 13830025 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 27B1DCF11DF for ; Thu, 10 Oct 2024 12:12:45 +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=c+EV8+Nqe/MAAQrZGKvXOgWwQz aqygQhgrvlZ83CnyVyGB1yqNpER083K6rnxyFpd/f/5rBfC1GqMvkT2jgdVWEhEpkkcGQCaqCKlp4 oUqyRnDOV808I+DWn0/Xtf21vg3zyFa89bHKox53PmkNFeqd2w/3THaKx+xBL97t5yLvJEYHUIV5c wLhH39GZc94wdhQgrPkzGEE+HbFpox8lqAuWZ17Rk2EWsbqjXU5RFNNwzIeFQj5Xv1ytCBbLtMebQ nk1Wk9OuEPO12iSoXGgeVmHP4Sa9twcC1b2tiTdnvr52wKh3ZXXjCTBq6iTn5WiOMrFklRIfMKIm8 2RA934Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sys1y-0000000CfHc-0ycg; Thu, 10 Oct 2024 12:12:34 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR5-0000000CYRV-1KEA for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:32 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a7a843bef98so106161266b.2 for ; Thu, 10 Oct 2024 04:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560065; x=1729164865; 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=cjtnkrlmfgXnSxkPsQsBa1F9no6N9WedPxuBPMvLkkjfYxEOjBGyS1VnIP3pkS2gYl LzFZ1H2x1NOZBI3A6VJOsNKZi2oKYbA/3U1mzqp/XXq6tYo1iuSIiUe2Vabw34T+ig7i wY8OuSFYk+LcKOtKdt4ssNhvsg8BOpcwY3mfvrTSRuta36FghLS5WTa/lXSob2Jz9VCj NEYJJsj+PYl9XmTjGETVhOUfTtc+1pNCGWNvk9dVwlg6iJI97Gb3CqcafYiyP14ZEvSR C6NowBbR9qrZPIc+UynfEzT5zCrAaVvNLtjPxViFcm6/740R0WiRblqBM0mItI7Of4KP tsEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560065; x=1729164865; 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=Pp0Ip4IgiUpikDRVam2yMUtjb0seNHCtiEo5Z5EGtxTxwJMIg2K28tXPJwBP73P/IA 7JfRjKnIx3JKkHCVyRZgEgbangzdfUKsgvIDc46FN33t0E6raaVt9oLdjGGuWPunReXm X7oZWvdsvoNOjYEVSJT4G+ptNdKYqIgAwDqKc+J+eNpRXumIG/aeFSsdpLCbHaZMxvPa FZ7Zey3iU7zrUyRToZGcm3FcOFIfh/ZINyPw2Zrr+Jor2QdC46u8fh2Yk3fZoHAPdzTS 5125eUPRhnOl+nM+WOdGZZDhxKdIa9cXd47hcH7CA9CkaQha2Dj1+nPpAoq6+tqSAC2Q x/1Q== X-Gm-Message-State: AOJu0YyqDFbi4lcLB+X45RVQ6r9IGJahthDlHH/OVeGDyN0OSYdOO4u8 s2m1rg2RhNfjzfjszepiE0xN4CRVB+a3mrBhNH3NjbkHtxNLIFCVH2LMdVux5kw= X-Google-Smtp-Source: AGHT+IGPbjmbOuudiYSl7s9WBi8ngVmIAJNEhV6kvE7fpNTobtjhLab6+DrMs8j68CZRmdtyA7IjSw== X-Received: by 2002:a17:907:9810:b0:a99:4fce:c343 with SMTP id a640c23a62f3a-a998d1cb499mr538738466b.26.1728560065458; Thu, 10 Oct 2024 04:34:25 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:25 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:04 +0200 Subject: [PATCH RFC 26/28] ARM: entry: Move in-kernel hardirq tracing to C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-26-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043427_390559_21003D08 X-CRM114-Status: GOOD ( 14.82 ) 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 Thu Oct 10 11:34: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: 13830026 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 5B19CCF11DA for ; Thu, 10 Oct 2024 12:14: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=/aytaH1oLbxE7oXL5Lh1BICkPib3Ft7vQWy4tTKokWI=; b=gZBJiQJTW6N5tPui4hJz9bGs7N 2EPhZ/mkg0zxjQca9LS8/ZI82pcQztUrLFi0YwkYAbtEFpS0ywv37vHqZkKduGhsEXs//SHGXLDHw mEU1Ed3x3seI7rwtiSuS1zdVRHcdzo10dJvgRIPR+jLnLpdtQ7hkBKXDEa1814mLMnPrwp5VqyPXk 5vnr5gSI2TS2tQbtnkJillfgiQ7+GkwxCwsJncIBKA8nv7yCM1E+gMFm+YAGeG1pbBeWZkcUgtCa2 DOjT8ajiK1SFYpAEFutucYRADvlFU+EnHCy6ZQyc28iTiX63ADq25RYKSeJmAE1p9+iXxYM9MMypa zs02VkaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sys3I-0000000CfTX-43Nv; Thu, 10 Oct 2024 12:13:57 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR7-0000000CYSC-0Esd for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:35 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a995ec65c35so137467566b.1 for ; Thu, 10 Oct 2024 04:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560067; x=1729164867; 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=GIbTy5ikZq3Ka4m710Sm5ZoNEN2gAxM5rzWVMM5SCVDEK0lugxSCsklJHkL9yxpjr0 EoUHcfi4SWZI3sdZRqf9A5V42NoNhLAP+/KuFTVnfgUXfskpIZWMtcb3fppn/L/rIGnX cOwaU0UuKZREt1xW02za7ZzeLDZ+aCg64XaJe/2N6UZMNJcee4kfxO1bxP9/28JP80IY UdtWkoyoDWOwZptho01vYD2eRr0f8aKkpaknOwxR+BCYCOPE260YAzawMgDGLAL82NKh WU589acssaYlWFX1eMdseqlcSZ8ss1P742yEaBNnRDqc2yDBGhBOoaCGQX4ACBVY7WPd NcXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560067; x=1729164867; 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=FUPyfmhA1e5Y4LVMe4YSGigviGXrg1yExmwIAJsB5hFxKmwJx3hCYLwNO4QSvcgJje 28IHNqN8pbOWkWDonF7Dhr1Pdy9k1x6TzVkMfkLaeZl+se6muoLVpLM9kvRP+qpKtPAh yfBcBo050juvPj0Q/R1+lWe7c0Tdj38Qhc/Nxc28c0xMOBYLSLli8A93l3vjXk1VGkJl VFMTQ9tZFX8U5LV+6w8pzpsyI2iPgte9X8gxltbqLBN3G8ACkPMd+PaXv6JtK2jCRzkJ 09n6aVFylL3rf3CPFIzTu35QIwj0DOm5oREBoLaJ86ZW8JPEK0xDYi7h6M0bY+Sh6VR7 BS2A== X-Gm-Message-State: AOJu0Yy/eYNax8zbpkcIjcjDPfLBaEZpL6vXDcohf+EcvfGSHrE7T2k+ xy+RODiF9HeRSMdMMOx9iYtiWxZTT/r+ycqLYWFRqtvogg//YjI5OPA3HYBi8y8= X-Google-Smtp-Source: AGHT+IHJCZC9ttmjEV4fugv9O8uxWYQ1Bo3ztMHrIb7V/zI60wobNn2BdMO/fiOPIzAK9oQNZ6UZoA== X-Received: by 2002:a17:907:940a:b0:a99:55ca:3758 with SMTP id a640c23a62f3a-a99a10e840emr242802266b.8.1728560067473; Thu, 10 Oct 2024 04:34:27 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:26 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:05 +0200 Subject: [PATCH RFC 27/28] ARM: entry: Add FIQ/NMI C callbacks MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-27-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043429_227714_C25C7A24 X-CRM114-Status: GOOD ( 13.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 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 Thu Oct 10 11:34: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: 13830029 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 D9AAECF11DA for ; Thu, 10 Oct 2024 12:15: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=n0vhef1d/tO4V+dCGdQHkCwxrnfd2znP3qGknf9D7ME=; b=2YSjJo3zqWgPRmAqf47t6CsmGd fZ+gkUDY08ONB7FkxoQ/ESkHztGJ2/edyLuhNuWZcGM/Z8DDayT2IYQOHOfYiDQMi6wu4L4dmII/O eE5CBETxOLXiQoVa0g/XvL3P9NVlXZszgJJaVt4iqmevIL7UO3U1jryh3sDdgTXhzWgyzJl/S8SFD mDHRfiVtN3WqSiR86vmB/EwQyLSbeGS/8L6GEixwc7tmIgr0a8/4Q3JFW8tK2Wli7C7M+cyTD++jq Xc+UpotWgC4YZ2Eo14wHfWimZPRN3TcwVoVRp9u0YDiH/SMMk8sm55KmxPmPSRXj4zX7gdUx7eZQc g25qq6Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sys4e-0000000Cffv-07wh; Thu, 10 Oct 2024 12:15:20 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR8-0000000CYT2-2KSv for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:36 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a99650da839so133381766b.2 for ; Thu, 10 Oct 2024 04:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560069; x=1729164869; 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=NeG1k4dnTrGlzP47af5VUURo54sULbXR7bcKngEJk2ezcSlGS4x2N3kMrSGPLA2h0Z vc6/pyP4F4zkfzlKRPSnL6eCGJ4jKXIPVJM9fBp8o2AQnOrMOwMuuxqZnud9NNSkGthj jU6B41xLBkGXNSsamhUlh+x2rlN6IBo2xS6QQqEirsnWjHt3PiNeTBJrZkYM2OH1lHMu dlQ7X53WUhK4wKdcwixFG54LpxY3ljozQFmmFnY7WDBFAz+D1f5SKbHzBsJostORbw4p nIu/hWI+7IPxr8NaYso/7+41F9p8Baqsd5a3Ajdy0bvDLnqMmdWkjR/c4T33Psapfi7L h1ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560069; x=1729164869; 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=RhbCO79MEaD0HIBv0ZW+EVOcjcmZDQ9/pTZ2orkUSiMwqaAsN5zjHXNhqQnMzY4uYu GgKBFG9GgjpxaN0yhyly3jnf7wS72HATMyxi48virK52uvJ3H36Ok0XnpWJ2LCwh1UkI JAMaycMCddD4A1+4KR6DZBrZlMC14c/nw53CnIB8OSaaW4IgqzxE1Wf672jyJM6tsBU0 eNIZkgJ6pxCOrpdJcECOZRVnHd1A55y6Cnmup6U3ZJsmeIQ9KLt34nKH1ajXmAghuR1z Mq4VUjRZy9LcoEHIZkFRP5feaoi0PCRwuZOzvqlC+rCKdA07V9pkslZxw+yS6BqrS25a EyuA== X-Gm-Message-State: AOJu0YzF53JMGmTNCUtN82wG5I1W40h0BdQqPeNJu3Cgm0G00IGXSEV7 pN+1Po7PdzEtTnqv44esEnvVzDhiexqRFBE+S5CmYAK6ObEKbt3MScsKhpsqmCc= X-Google-Smtp-Source: AGHT+IFKm2rdDuCf/QsWQ4NxI2MXBXXxaL2dIFKygtqouLDYiJ7ZzQmqCTl6FWi1bJEBc6ec7JRyjg== X-Received: by 2002:a17:906:794b:b0:a99:35eb:1301 with SMTP id a640c23a62f3a-a998d19971cmr549151466b.18.1728560068636; Thu, 10 Oct 2024 04:34:28 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:28 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:06 +0200 Subject: [PATCH RFC 28/28] ARM: entry: Convert to generic entry MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-28-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@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-20241010_043431_019226_4E9A422E X-CRM114-Status: GOOD ( 28.04 ) 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); }