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)