Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2195341rdd; Fri, 12 Jan 2024 02:13:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdn6Y1sjz9GocUgqxjIUBvUFmD0KutasRw06oSZ0jBh2V+YU08dGvUoe4uGBU28tE9Ogh0 X-Received: by 2002:aa7:d792:0:b0:558:c8d5:f1fa with SMTP id s18-20020aa7d792000000b00558c8d5f1famr211793edq.3.1705054412562; Fri, 12 Jan 2024 02:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705054412; cv=none; d=google.com; s=arc-20160816; b=Aynr+nOrgr6z+M8aPgTA9Ahr1KSNKpWehyWL7x1WqVqcbRHtVB5rZkKj8Ypz4UsutS JWL1lEAx8ktCX/73gWd9ihkm2jYlvrbgcjuiZh9F6kM37oI7qXV+6RM9Y5DXiVPTveYe yqu18nOfHaL8l8QgfomxA2AHttBSR1CGbEcq2+jWF0FRAISNBrzxF4xXLV26qD6mf/uS 0+4mO48yKp4ud7bsM2st+W0NyV5Z/ZPMlNMcAkyxOiRMcMTPX7y7VxGFlQZaD5W3qHQY MDzsAZs2cpEcVGuKIlYJNmT13TJkNp6TWfN129eUjeJFosmj5T2GS6YDXI4VwdfeYJeH c1YQ== 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=KqKaTMVZSdhvPPCpJKf4Uke4Yqsp3KVdeoVgdoQGvCS/YbtS4t47cGQR02oKficM2I V72XjXeCzBSesPFF+Z/6p68WRFzuLjYT9BeVUibR3lVfdCRQVKVN4smjOs8W4UcKrby4 RoWPlWtk7FaJoibca6MIhZVSWX9SAhfUYyHpiMOn9rJly9bwjCxPqdf0sk/1K1z6hdNQ iFFQt2waKT/MOiOXQfCAPaKRSNRyar3qp6EHM/LTkCahWoLJV8swxVH1pk2Y07XKXxQB c9v4Edz6Qo7WnL1CoJOThTq/UGPIEc3mgb6H+1keRW32KpldsTQXD3EgxobDmlS1xyQq Ru+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="FNHbNiB/"; spf=pass (google.com: domain of linux-kernel+bounces-24552-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24552-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c13-20020a50f60d000000b0055380682709si1284333edn.444.2024.01.12.02.13.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:13:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24552-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="FNHbNiB/"; spf=pass (google.com: domain of linux-kernel+bounces-24552-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24552-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 518CF1F235DF for ; Fri, 12 Jan 2024 10:13:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93D865DF3B; Fri, 12 Jan 2024 10:12:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FNHbNiB/" 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 C07B85FF0D; Fri, 12 Jan 2024 10:12:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C9E9C433C7; Fri, 12 Jan 2024 10:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705054327; bh=BJTb9S/48BMXgKg9JdebJFjIf4uCQaHDkO4DGbu+/d0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FNHbNiB/xSg/7ehU4MKZbWNtREQbJVpwYTkt3lrjrf9jZ/RGJgfpwJYwNNGQQz0tv OcBZQpGkcvYEDgRzYy7m/aYTaSC2aCJbQmy/Fu17w12A3t01/lcABpnPXCN8/u82Ld fK/gfmREyDHlo6WpgUbIRTTcFRZK39T4IQ6hI+Iw+2Lcc1oKpDOZR0Q6OMinpglSmA efv2X9NjXZ5HOUZZzrPrU1iiq2TXs7j+YGVydXLAKXnzP6bs40mAYqRa+e/pa2wTDG O+RftnN4z83jMnNxuw5cGMrZbcW3I/C1B44oMNOPLYRre/Z7cuNKOARteHrRm0wxSf csl00e7pnRNGA== 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 v6 06/36] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long Date: Fri, 12 Jan 2024 19:12:01 +0900 Message-Id: <170505432176.459169.10224406939710504027.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170505424954.459169.10630626365737237288.stgit@devnote2> References: <170505424954.459169.10630626365737237288.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;