From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 976401E1041 for ; Tue, 7 Jan 2025 09:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736242902; cv=none; b=QirrRBPYMknrGOQbRaZKdvbsROJ4jKC/nCjepv8HfyDtVWSOamIj2pqoatt+Af8h5PhoVkwSdhGl2/RDCraY4m0hf0Wmjvn1pjYtVl6MxrkClyq7xzOIw5+QqkHC8+yOzLR8Yu/319R0gkn/mW4Lo0kOnw+HY4B+EbqMCTKbVKE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736242902; c=relaxed/simple; bh=g0rO5RXNZxmhVGJa0ZyJM7gnaZgsHeeEX3l02Id9wO4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q4m4twiHgJJbOK01RcYjv9ubrmQmX+x20gL8TGfbb0dUKEiBqGlZ/0CT8c+74UdhMUJP9+URtefXTCUwMz4SmnVr2AMN0sDg/78o/6ZSu6W7DQ6BaAPtl1C9rOms3iduC9KcxvxC6qpCNi/cAT0P1dnqOHf6JS4y/Q3l3rHxfig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=h5i/ofR0; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="h5i/ofR0" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d90a5581fcso8327944a12.1 for ; Tue, 07 Jan 2025 01:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736242898; x=1736847698; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sQAp8VACnKHObFrcN6BKQWBu0lC+h+9xnjqKvK7FcXs=; b=h5i/ofR0CpF5/jC1aK4yX94CT30FJ3yo49I9ZClTrWb3waUWYEBH7ZZWlzoAhs95HU ApZl+SwET+j3jGrYCiMA0KG7vzsfdIlqwyMw/C0sHmvWSUlYKjk+rx8+onN9q5OxFwsv Cp4QVHn40VFEVlMzy73+pykzi6QjSJ4yhIdA0Rr9TbBQ5bQs7s5JpFPY2M6gDWDaN9e0 MRIKuvy8QU9n5HA/577PO77lmd5xY0nGkOrIGY52g5DG8IPY4OtPaJ5syUKDUKq57AK6 RlD3QfeC3M5WKk7bLZOuufOBvxL7no2i8NVwGkK5gZZjZu1hIY7Bk6u+2jQEsZ3OKk58 7WkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736242898; x=1736847698; 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=sQAp8VACnKHObFrcN6BKQWBu0lC+h+9xnjqKvK7FcXs=; b=CtkUgDXtl4GPaDt/BGDz0kVGP3m8XLXZHNVedfoArWBFLSlcTEGLKkCpVYmvsvsyJ7 6riXGNBaTip09YeSBx/Zr7Pq1InI2FTnm5NYRn3lbh69/+KWpfyGVW1Jy03IIy4wdyvO yZesXeTdcmZcWyo/xrVGt2zwFg2KucPaO9eKs+eBSunbWT2J3BkzAjTPR4vbcjp7tXAb ewZR38uitr+khLq/2/DKtX1bqGy10/RhTjK97By1ph2CROJZr85B4NOXZB0o2BKWapfn 7Xdcy9I1HrG32aesNM8B53oCZyKCj45khfkNsknaiZw+KUVWe32JHnivi/maPuuL1tlw NnHw== X-Forwarded-Encrypted: i=1; AJvYcCV4/GKFV1WOKBZ3Zyd02WDA/uXNEofKU7xZ9KBNgYWs1S5yMltpmkejil9JyPASWBNUG3j1nQt6l4GLIUA=@vger.kernel.org X-Gm-Message-State: AOJu0YyMTDyctQ4vIexEWFgX1kk6QIlGSacP/PcyF6O8DSTThHV6d97d 0Mjp0d8sKc9KFtRg8NUxA3lDszyaGahrkCWrT7mbKHis03tnpOwgbPG2hcCqKSg= X-Gm-Gg: ASbGncvdeo4mYsVcGjNqP0leLh/gUV9OElLTYuTI4qdtdHv62GpGPOzwDUi29Tc9Oh0 ot3eMoh6iPpsS9EwyVd89YFnVoWmFLJh10XrUsbrPhrFiLFoO0baI6I7IXQioO4VXf5YDAy/cSu PNrFHIoe1VYVU81rqOdv0rYX87i4mNBZTpoY0GWwDsm9+aotOZFCd9WHIGfgSxZEzSmDaWl+HeG dbH6TgJyk6s0eRhGxuwU4QrkrvW+Br5B8owR30b/kw7Tr0BOnH6uyRKti3nAAoOL0U= X-Google-Smtp-Source: AGHT+IFbK5JNMY/DlBPttO03FrsecsUcG94kP+7J7Uhk6bjBGJqZw7Ul1vEZtVACwonxWgRUxG1J2Q== X-Received: by 2002:a17:906:6a27:b0:aa6:9fad:3c1d with SMTP id a640c23a62f3a-aac3464881amr4406657766b.39.1736242897835; Tue, 07 Jan 2025 01:41:37 -0800 (PST) Received: from [192.168.1.140] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f012229sm2356901166b.133.2025.01.07.01.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 01:41:37 -0800 (PST) From: Linus Walleij Date: Tue, 07 Jan 2025 10:41:25 +0100 Subject: [PATCH RFC v3 09/30] ARM: entry: save the syscall sp in thread_info Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250107-arm-generic-entry-v3-9-4e5f3c15db2d@linaro.org> References: <20250107-arm-generic-entry-v3-0-4e5f3c15db2d@linaro.org> In-Reply-To: <20250107-arm-generic-entry-v3-0-4e5f3c15db2d@linaro.org> To: Dmitry Vyukov , 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.2 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 943ffcf069d29cf4a035964d20d56f7ebdd6d602..d8a45c5a10496aaf806bfeaa0353d5e8985bd6f5 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 4853875740d0fe61c6bbc32ddd9a16fa8d1fb530..c9525cbb26b73827821aa746030e56b037f49556 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 3cfc6d952ff99be9c4c1be4481ac3039260e3e57..8baab7f97f59c434396f30b08ddd3029c5f9c0e5 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) -- 2.47.1