Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp90154rdh; Mon, 18 Dec 2023 05:21:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IENgar4/P/Sr4OuALJVKkiSSNU7wZkK8zeL6tcBrHcK6wHEJjlD/OK8G0nUAbh2uIm+8shr X-Received: by 2002:a17:902:ce90:b0:1d3:b85c:53c6 with SMTP id f16-20020a170902ce9000b001d3b85c53c6mr1895368plg.57.1702905695612; Mon, 18 Dec 2023 05:21:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702905695; cv=none; d=google.com; s=arc-20160816; b=YJFDj7GfdGbm+Wz/oZwxom3OC0JClgxt/qviWccdreXFytpBhl4t4b41C4lAxlRuzr 9QnOkcN/6k+minxH3Gm+vnRHBb1EEZKgnf1VXXlFpp3X9MyRTPT2dQ5Auj2UFl0tiD6a A3beSScz2Km7Gh+dWJZKgrobJ602LIAJHbNLvW+axrK6KvxNpsFzbttc5vlvoDDSUzRp MRi13WamFx1rBz5VpAVLH/1lNwrDXTBIyeKCY0ZQHNslHCw204LWtYNTq/BY8SMZV21v PVPSBaKYeEy3j7VHj66HTGI+USI6ec2+yW7R8/zpJWO5IYAN9IzuM0Cjq9/kLH3aT2eC mKLw== ARC-Message-Signature: i=1; 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=OESyYZVxbmArs5V4zMGrIL0/uPgjACK9BAVI1aKMbU0=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=clbBSpAY+iSxV56gSfJrunySWD89ex/AeRTpT1Xd5D/OPVqC9NTI1Hz3Q9nCsurbb4 tcgxVutRT1oARxAxgjYL0NQQ4sKhLr4jZVQNpIZfPi4akX+qPuF9PoueaLtajHHygNGK lsqIoiIqBzDGBBueoJZNojD3FXRe62J19xs5cfcvEwguTERzA1hP9J5LziM3zyCl2lJi klVLtZi0Tf+kEOCo9XdmHGCeoPDHsOXJVlwusUAGpVs8h1G4ZzYqqP4puxc80Fg3XALN 7rTTtL6C4Cc77z0KAwICQ0ByfYtDyWBBwHKMqqz66A/QVT5r3bRaH/hL2eSygDP0ecfl YY4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=shtAi0c4; spf=pass (google.com: domain of linux-kernel+bounces-3707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f1-20020a17090274c100b001d056d38cf4si6912213plt.625.2023.12.18.05.21.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:21:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=shtAi0c4; spf=pass (google.com: domain of linux-kernel+bounces-3707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 57D26285307 for ; Mon, 18 Dec 2023 13:16:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C29E498BA; Mon, 18 Dec 2023 13:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="shtAi0c4" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6B384239D; Mon, 18 Dec 2023 13:12:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 705A8C433C7; Mon, 18 Dec 2023 13:12:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702905147; bh=BJTb9S/48BMXgKg9JdebJFjIf4uCQaHDkO4DGbu+/d0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=shtAi0c4o9YjvzP6qszxNlE8DqQrpawwXJg1907k+JgmVOfDelbzXRpeMa1hlwmlG LhaiH4254qBTsmFOcV7gru3CE9hwNFcM0E9IB0Z9IAiE63DP0jghZT7TioMajiz/V+ 0YYdJ1hj3+Viup+FAnM4cUNPFWpmHF83zDLbwsLTnN6QT4vwZzJkKqjmQ2KxrJRbkI Hz+bAnzcUytjtnHMMHAS5BmZuPpl7mdpoLNaMtw7alZCldBZ9cesLU3Xo6Z9K3VYLU 0j/nlfauGMDi2lCU/FVPLvfvarcAKFSAeSRth7Bw3UX0nNV10FPbd/k8KpglhfammB wQ0j4JOuxW3Fw== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [PATCH v5 04/34] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long Date: Mon, 18 Dec 2023 22:12:20 +0900 Message-Id: <170290514029.220107.775585007438096339.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170290509018.220107.1347127510564358608.stgit@devnote2> References: <170290509018.220107.1347127510564358608.stgit@devnote2> User-Agent: StGit/0.19 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: 8bit From: Steven Rostedt (VMware) Instead of using "ALIGN()", use BUILD_BUG_ON() as the structures should always be divisible by sizeof(long). Link: http://lkml.kernel.org/r/20190524111144.GI2589@hirez.programming.kicks-ass.net Suggested-by: Peter Zijlstra Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/fgraph.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 30edeb6d4aa9..837daf929d2a 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -26,10 +26,9 @@ #endif #define FGRAPH_RET_SIZE sizeof(struct ftrace_ret_stack) -#define FGRAPH_RET_INDEX (ALIGN(FGRAPH_RET_SIZE, sizeof(long)) / sizeof(long)) +#define FGRAPH_RET_INDEX (FGRAPH_RET_SIZE / sizeof(long)) #define SHADOW_STACK_SIZE (PAGE_SIZE) -#define SHADOW_STACK_INDEX \ - (ALIGN(SHADOW_STACK_SIZE, sizeof(long)) / sizeof(long)) +#define SHADOW_STACK_INDEX (SHADOW_STACK_SIZE / sizeof(long)) /* Leave on a buffer at the end */ #define SHADOW_STACK_MAX_INDEX (SHADOW_STACK_INDEX - FGRAPH_RET_INDEX) @@ -91,6 +90,8 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, if (!current->ret_stack) return -EBUSY; + BUILD_BUG_ON(SHADOW_STACK_SIZE % sizeof(long)); + /* * We must make sure the ret_stack is tested before we read * anything else. @@ -325,6 +326,8 @@ ftrace_graph_get_ret_stack(struct task_struct *task, int idx) { int index = task->curr_ret_stack; + BUILD_BUG_ON(FGRAPH_RET_SIZE % sizeof(long)); + index -= FGRAPH_RET_INDEX * (idx + 1); if (index < 0) return NULL;