From patchwork Mon Dec 18 13:12:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 180385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1231102dyi; Mon, 18 Dec 2023 05:16:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqk6P/HIbeS1ACHp1gpi4+KTPsjhRjhu8kSLOFTo66+R+Hz/zBDpb1hw5TyHRPo57Tm7ad X-Received: by 2002:ad4:5685:0:b0:67a:a721:7209 with SMTP id bd5-20020ad45685000000b0067aa7217209mr20068526qvb.38.1702905388591; Mon, 18 Dec 2023 05:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702905388; cv=none; d=google.com; s=arc-20160816; b=if36hYc4a8fxoPj5KMedWA5Ue1Uk7eL7bfuUYucPSPVnsiiRiZ+MIPcQSstHokfF5q KKE02dXBiO0eVETIWylNdE7KfGInppuhVkEEWO3MFvcp+jl8PzrD/xWsco7IvYD1g7bs sJBoB5hjm3dfxWyarm/fnZIexDwoj9GFyuilAryjFNF3MQbEjNOcYPgUkPH1Jzg4GUpP /n6PkSA77kpVdC8z6cp/tRDYsoP8/D04gzIeNKEFUdqjHS3mVa9Z0HhmupihV46dX+ru Luqc8s+LsHGvLW0bjW/+QNSQQWNhLmtFlQzkqVA/ljnOUmW4Q5z6cZSfezvSwXb5B+zq M6hA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3707-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c10-20020a0ce14a000000b0067f2be94c35si4755075qvl.613.2023.12.18.05.16.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:16:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3707-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3707-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 40F681C2435E for ; Mon, 18 Dec 2023 13:16:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B60A498A6; Mon, 18 Dec 2023 13:12:30 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785625721068139532 X-GMAIL-MSGID: 1785625721068139532 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;