From mboxrd@z Thu Jan 1 00:00:00 1970 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 BDE68CA5FA2 for ; Mon, 28 Sep 2026 17:43:19 +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:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=b5BgLva5vXrAwBl9Y3v1BBOsVeywVgMCKKqE5NVyRxk=; b=GHnrokOxYfmt6ToaoMrHWS9JfS FR+tjqEUJiOr+bD+VV9aGCRo46t3HMSIBHpyhJWEBLLYmud1mEASs/CSOqyF30cWRgkfYyGHVLJJJ HsmVnHEhHbS0jo8b1mdKSwsL59dZCITR7TybobA4DUFnRqJK+E93RxT2X0WhSjrbpOcCzAznSjbti 0ps4mj5HmmEMSmRcRF0GzDhWDVLfzwwehS0ZxjJYicx2X9irDEwaYL16Roq2D47lzJyiu2DCU50qO SvcS7bvvHF4POR+29DX8lh0CmPi5JYpcXJAFDRg6skX0fmF1c3UmuTfnpHclbSpGhAPjpqNGiHBvb RPM+sZ7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xBFNh-00000001DOh-32pI; Mon, 28 Sep 2026 17:43:13 +0000 Received: from mail-wm1-x348.google.com ([2a00:1450:4864:20::348]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xBFMa-00000001CeV-4BZV for linux-arm-kernel@lists.infradead.org; Mon, 28 Sep 2026 17:42:06 +0000 Received: by mail-wm1-x348.google.com with SMTP id 5b1f17b1804b1-4994d67d0e3so24283955e9.2 for ; Mon, 28 Sep 2026 10:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790617323; x=1791222123; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=b5BgLva5vXrAwBl9Y3v1BBOsVeywVgMCKKqE5NVyRxk=; b=O0vwdnA8aghPb2IciHQKEsF46sZ92i0AFFxLQC4iRExwKFvyDoPTHFMDp8cjo3qcsE QhcDiJCXjHTV8JJ1ZJ1+1/ibRDG+IKYtaG55S0+mlJmtoQMOdrSi5f7XA6cgChtN0eYQ aexvzL+BF2XdTKyDmXFmcHqXKslcgXZWH5KKKTa17n14d5aDIfw7mlQgSrwCFl/KQJaP S/dub2TsIzSemRaZwqvPR3tTYbKW5S7TRuiEX780rBF2SiKEvmF9FW9SF5GAKnN2ewoh mEPDikzZWa6klSizuRHUa9sGAND7r6aXKbJEanTMSlNh+1cgSV74k2jjNDmVSV2sZ0O7 DQsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790617323; x=1791222123; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=b5BgLva5vXrAwBl9Y3v1BBOsVeywVgMCKKqE5NVyRxk=; b=z0VhMbMoBWFEDxwnbmbyH7JqgCvqjPL5LDk2qLZdCpCuzek8947Ygo5xiZFgGt8ckG DMnocsyJM/S/bq8/0DrmH9nkG+QIUfpEm/r4qbwm+3pRYfcyOWg1C2qq6Nwc1XWHF0yZ /DuwSYlzdtU5ZidJQJRuON5LfKyjghJoU5UX5IgmZHC24xYI0QYV/Cf+hYoeKdDyNjey bci8VHyzw9g7JyGRk2+VUFZXuYOOj82BMY9viG2DsAhcSQZHaGns4EjupDA5HEFH/ePZ ZLrMwXFeHp3Gv7T+Q97lkWTjL2HM3TKWkYtiego5aj0NuJYaZiEPnIVavE4rf5bAW06N Y+iA== X-Forwarded-Encrypted: i=1; AKwUvByFgNw5kPLsRH4ijMAFplOcGa8VMNxyPrcfnoZKSmfWTHu7t/+sSkAXL2OloU6dqcQvDG/rr9aB64oMFpkRTPCN@lists.infradead.org X-Gm-Message-State: AFuF++mxCdembhgT2c7wbdn8+3GMVaZenHpUAC6R05B1dZSj9TKanF53 yIE0ugBoMqNhLV5lSVP7IWoyk0r6DuFftNThTKM5AAJpqlzm3W1ikXZD7gwlVh0Waifa7aZ99Fn Q3ldkSNzY1VCCBw== X-Received: from wmhj21.prod.google.com ([2002:a05:600c:3015:b0:49e:8337:33d]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:83c4:b0:49f:c331:39e4 with SMTP id 5b1f17b1804b1-49fe66ca101mr236733115e9.7.1790617322864; Mon, 28 Sep 2026 10:42:02 -0700 (PDT) Date: Mon, 28 Sep 2026 17:41:19 +0000 In-Reply-To: <20260928174122.3380703-1-smostafa@google.com> Mime-Version: 1.0 References: <20260928174122.3380703-1-smostafa@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20260928174122.3380703-13-smostafa@google.com> Subject: [RFC PATCH 12/15] sched/task_stack: Introduce ARCH_HAS_VARIABLE_STACK_SIZE From: Mostafa Saleh To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, linux-rt-devel@lists.linux.dev Cc: corbet@lwn.net, skhan@linuxfoundation.org, rdunlap@infradead.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, akpm@linux-foundation.org, urezki@gmail.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, kees@kernel.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, gustavoars@kernel.org, bigeasy@linutronix.de, clrkwllms@kernel.org, Mostafa Saleh Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260928_104205_098953_66B6691B X-CRM114-Status: GOOD ( 15.06 ) 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 CONFIG_ARCH_HAS_VARIABLE_STACK_SIZE is enabled, the kernel stack may not be fully populated with the THREAD_SIZE virtual area. Teach task_stack_size() to return the size of the vm area and not a fixed size. This propagates to end_of_stack() which makes functions like stack_not_used() and set_task_stack_end_magic() to use the lowest valid stack address instead of THREAD_SIZE which would cause data aborts. Signed-off-by: Mostafa Saleh --- arch/Kconfig | 10 ++++++++++ include/linux/sched/task_stack.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 45c657772362..d6fa2ccb0599 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -431,6 +431,16 @@ config HAVE_ASM_MODVERSIONS to support the module versioning for symbols exported from assembly code. +config ARCH_HAS_VARIABLE_STACK_SIZE + bool + depends on VMAP_STACK + depends on !STACK_GROWSUP + depends on THREAD_INFO_IN_TASK + help + An arch should select this if it supports dynamically configuring the + kernel stack size. + For example the kernel stack size can be from the command line. + config HAVE_REGS_AND_STACK_ACCESS_API bool help diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h index 4a808f9c4631..07d73adaecd1 100644 --- a/include/linux/sched/task_stack.h +++ b/include/linux/sched/task_stack.h @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef CONFIG_THREAD_INFO_IN_TASK @@ -96,6 +97,10 @@ static inline unsigned long *end_of_stack(const struct task_struct *p) */ static __always_inline unsigned long task_stack_size(const struct task_struct *task) { +#ifdef CONFIG_ARCH_HAS_VARIABLE_STACK_SIZE + if (task->stack_vm_area) + return task->stack_vm_area->nr_pages * PAGE_SIZE; +#endif return THREAD_SIZE; } -- 2.56.0.rc1.315.gc6ed9934b7-goog