Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp540440lql; Mon, 11 Mar 2024 09:49:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUzFdCsb2xndAcCOpq7/wBWRulyMM13wZNULJfizC1iB8AU7DYxOgiBiWVtgbJ0P/k0g5xjcpTINhq6MPuF1X6zFD0rCX0VZvKIXpjGfg== X-Google-Smtp-Source: AGHT+IFi5MqVEiJpP8Z02Vy/yl5HcbSwLFFljOAH1qTDYZm8NfubpASfpglJLoKAUY4iDAqq5/wp X-Received: by 2002:a05:6a00:3cc9:b0:6e6:3d15:418e with SMTP id ln9-20020a056a003cc900b006e63d15418emr8021053pfb.1.1710175757557; Mon, 11 Mar 2024 09:49:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710175757; cv=pass; d=google.com; s=arc-20160816; b=OOfL1WpxjTvhgJSQCiUY8LdBX7MecZBK7ZQ46AB7pX7ZVMW/C1O7ja+NX7Lvix9clb /JJOmV7xAaAjuuLVrB1eUaVQyLesFrQAcQOwYQ5AJhb6yeGrejdH7aaNtLTCG5/umIpf VQPsV12tBMLZhfZvawa7zIiFZ+CAH4xz4F02gIpX6tzx+wpSKv2FnH3l3F6ogzHAGLHp hz8VsXi/QtPx3KT6o9BZQU1JRalH2be8Dqf+D54tFISBgkgf7c5VN+bWv9c4Z+eF1hY7 Ai1eheLsXf37L9AiJSvrjg+i0x4bdjB851Z9OsDCsWR2NbNnLuGDDjQSwpuk2HOfpIk+ UH2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=w3lfkbgOqarNxaTYrCv0KyWjfiF6t60qYNqci1EaSrU=; fh=kQiLOTmmTYT/RnYbETsrCCUkzAGxYfMbAVQHF5Hzuqo=; b=B3HEomsBJUzY9l1rWCZWtShGvtofkrypOUR5Tj3yaD5ATvIpjV8fNBiwmANU/RfKWA tLDwbCbokWHoMZ1/5Kg1bfCvIVwdZJtXCccTx14WsgrfrJiNsTc1zGD+PAHnUvo5wl+i 1uk/XMKWojPKcGNX9vQjEs3XHCwpiawrNHiinMywSFXJsr78vTgTDLzSi+OYCYcJRHIg 4RR+ZdkfZDbUXXHWSwK6i5CsYs08z28Fp7+eb0PaG0Uru+DgDAyNTZGQ5s15Q9HuZxC3 SytBd8D7ZrCX/zAXuj7KdEip7gEowCRCtrw/mglFs8ZOmFqUQjHE8SkwXCFlf8AmjLio uWAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="KvYA/g7n"; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-99269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l185-20020a6391c2000000b005dc7fe1218dsi5071673pge.284.2024.03.11.09.49.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:49:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="KvYA/g7n"; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-99269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3A1322814AC for ; Mon, 11 Mar 2024 16:49:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FED457322; Mon, 11 Mar 2024 16:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="KvYA/g7n" Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 A04FB56B72 for ; Mon, 11 Mar 2024 16:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710175618; cv=none; b=HWLd15y2qE3f7IQzxUhsYXR+k5FMTDQaDWCws6mWxZJtitIlUpKBp8ZGjRY+DL80IQtgE11cz6HfdjANjdkWtL0RBcv1YfhDPwg9kwF17yAo/B+nn4hUXPh1MEjMIa25V+RwlNsFRC9+FfaQZjSKeUSjKNBwQNj1NhfFZY4tXg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710175618; c=relaxed/simple; bh=yMyYef3NZl4G4p32yVMbEyHz15V0r/n9UEHNsI8V/OU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTU6rzXEBgQ9NX4SL5bUTBq55J3F9zH2vJN7KexCYJQLGiUwY8I9hTfOJWMuGG19mPYTXzc5gfpGTXSxI59uG88LT4lXpQLK367DWeA0eOXkmhpgn0KXTyl7p9++9rFtb0ueQN5tGjcJHyjpqLVYZ3oz68O6mz+bRuRxD/Qeotc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=KvYA/g7n; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-783045e88a6so277632585a.0 for ; Mon, 11 Mar 2024 09:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1710175615; x=1710780415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=w3lfkbgOqarNxaTYrCv0KyWjfiF6t60qYNqci1EaSrU=; b=KvYA/g7nW8657mqsa3INNq4bY3H2wyoRVWYt64PLx8aNNc1UOdVPJncyG4qm3EG7T4 kxmmtALcXLvEbGobR6d5CDb6mfMSBIVUPVfMhZm8Rm8T3MnDmKOnXvfTE5krvypWnYn9 9gWfoFmwRlJ6cCn4ZP7CBm4CS7uj5Ni2Uu1kxz1yUR+cUP3y0YfVpuV2RF8rtrLy7+7L tprYNFeJCUwBCJcYRpOahsv8WF+By1fHIzrGQ3FPkme8EIe8NTYlOqNifFhwieS3fQAJ HEYORzRRjXTfMmjbfBXN0DMZ9FR7Ai/oCIOIPzlShzmZ0F4aRiUrFVRIioH5n/dgSpVf RuQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710175615; x=1710780415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w3lfkbgOqarNxaTYrCv0KyWjfiF6t60qYNqci1EaSrU=; b=vj8jsMSdix0sgocRk2cgx+F/immNRyXgHip8rFzDizjKsDk/nWhNyBmtcqWGKPRvjS i9zrQeMGHBpSNjui8noIJdIJXY9dTZqGM6aN7b54Zeec5PzMZB0vhHN5jbSoAbqY2hSR NwDbquxne3o9A/iWZJkNg2rqgOjCyYrV3xoJ2jzLLyfMcBe6Wf7iSPGQEH6R6HTFZlD+ e4VB50IbyNWLGOwDF782rdh6PgLWt08HuHVk8ks5Pk4S1BaAwruMeiTaAhWiWO7oyjld E7hMMd2DGnLjduNm1CJU6Dme8lXpAoixyG0/Tio36FlLbZD2rQ+3qOIBo5gB7h7MdvkB 6W6g== X-Gm-Message-State: AOJu0YwPhowmijEBNMNmGFIuGMiauSyuD0kEFeVOgQIYAHqdm9Ro4PWl RvW1P2UTsHFJJ4Bpuqlb+tGpBsSMgP1cglP6OVXUqv7tVDws/2GC4nbgUYxypUN9t36HZSGePqO PPgc= X-Received: by 2002:a05:620a:4609:b0:788:2740:550a with SMTP id br9-20020a05620a460900b007882740550amr9951495qkb.44.1710175615373; Mon, 11 Mar 2024 09:46:55 -0700 (PDT) Received: from soleen.c.googlers.com.com (150.254.86.34.bc.googleusercontent.com. [34.86.254.150]) by smtp.gmail.com with ESMTPSA id d27-20020a05620a137b00b00788228fbe05sm2851589qkl.17.2024.03.11.09.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:46:54 -0700 (PDT) From: Pasha Tatashin To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, x86@kernel.org, bp@alien8.de, brauner@kernel.org, bristot@redhat.com, bsegall@google.com, dave.hansen@linux.intel.com, dianders@chromium.org, dietmar.eggemann@arm.com, eric.devolder@oracle.com, hca@linux.ibm.com, hch@infradead.org, hpa@zytor.com, jacob.jun.pan@linux.intel.com, jgg@ziepe.ca, jpoimboe@kernel.org, jroedel@suse.de, juri.lelli@redhat.com, kent.overstreet@linux.dev, kinseyho@google.com, kirill.shutemov@linux.intel.com, lstoakes@gmail.com, luto@kernel.org, mgorman@suse.de, mic@digikod.net, michael.christie@oracle.com, mingo@redhat.com, mjguzik@gmail.com, mst@redhat.com, npiggin@gmail.com, peterz@infradead.org, pmladek@suse.com, rick.p.edgecombe@intel.com, rostedt@goodmis.org, surenb@google.com, tglx@linutronix.de, urezki@gmail.com, vincent.guittot@linaro.org, vschneid@redhat.com, pasha.tatashin@soleen.com Subject: [RFC 12/14] task_stack.h: Clean-up stack_not_used() implementation Date: Mon, 11 Mar 2024 16:46:36 +0000 Message-ID: <20240311164638.2015063-13-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog In-Reply-To: <20240311164638.2015063-1-pasha.tatashin@soleen.com> References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Inside small stack_not_used() function there are several ifdefs for stack growing-up vs. regular versions. Instead just implement this function two times, one for growing-up and another regular. This is needed, because there will be a third implementation of this function for dynamic stacks. Signed-off-by: Pasha Tatashin --- include/linux/sched/task_stack.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h index 4934bfd65ad1..396d5418ae32 100644 --- a/include/linux/sched/task_stack.h +++ b/include/linux/sched/task_stack.h @@ -135,25 +135,30 @@ static inline int object_is_on_stack(const void *obj) extern void thread_stack_cache_init(void); #ifdef CONFIG_DEBUG_STACK_USAGE +#ifdef CONFIG_STACK_GROWSUP static inline unsigned long stack_not_used(struct task_struct *p) { unsigned long *n = end_of_stack(p); - do { /* Skip over canary */ -# ifdef CONFIG_STACK_GROWSUP + do { /* Skip over canary */ n--; -# else - n++; -# endif } while (!*n); -# ifdef CONFIG_STACK_GROWSUP return (unsigned long)end_of_stack(p) - (unsigned long)n; -# else +} +#else /* !CONFIG_STACK_GROWSUP */ +static inline unsigned long stack_not_used(struct task_struct *p) +{ + unsigned long *n = end_of_stack(p); + + do { /* Skip over canary */ + n++; + } while (!*n); + return (unsigned long)n - (unsigned long)end_of_stack(p); -# endif } -#endif +#endif /* CONFIG_STACK_GROWSUP */ +#endif /* CONFIG_DEBUG_STACK_USAGE */ static inline int kstack_end(void *addr) { -- 2.44.0.278.ge034bb2e1d-goog