From patchwork Wed Nov 8 14:25:18 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: 163038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp948140vqo; Wed, 8 Nov 2023 06:25:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM+W9+QwcW5TOnYyBlo/ALcTqdUiGOu3Ll05aE9tdmkzQ4Mx5BGT4mkGvRd2Youura00G8 X-Received: by 2002:a05:6a20:4306:b0:13c:988c:e885 with SMTP id h6-20020a056a20430600b0013c988ce885mr2285334pzk.56.1699453533614; Wed, 08 Nov 2023 06:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699453533; cv=none; d=google.com; s=arc-20160816; b=ZkhN12oY0VkZByl4dj/ZxpAoLmpKAot/C6CMTbvVNPKGwu8aU+zywJNC1R1NPbqG0P fRUOeyM60M6TqrMmzSyyXzBeXzSwNgdWEN0iyBoUHGhvfr6YUVa6s+WN96kCnLQ2+8li 2CJCl2BEdPjYGoIgzsE161LCf9UFzpkjnggYXTSRLH4dK0+/J4qAwV94Mmd6mNo07F0M bhRjYGsSW9nIJeIGMk+DiLrbxId/Je/903xQorciqJ0/UJY6HYh+RMUnXFt5k6zzU1KH I7rq/u98OPQBJAOIB2KQq58aQYUeARWd85rwiJ+MlkOJbzo2Uy/mWpCV7rl1AWL2Ji3k eZAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OESyYZVxbmArs5V4zMGrIL0/uPgjACK9BAVI1aKMbU0=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=EQGoooGAFwdCLR+1fF4dJtcQJtENrC/8bwlUcH61xPW/JA4PBWVOtEYRmap+Oyz8dU j3zRpneSrm13RF8Lxk1gDorQJcYJBeplUtFtyrc6UbFHoUuGvk1PQ/ggd2d6/YcTt5d5 RhnLh/ZRkp/GjN9QnpRMI1SMDmwZK2JudITg/FVyTVX4e9LtS1mlSn55A8T/G0EFrGsU DICja97TrVbyRmAX3UYgI/gQE226FFBjuyFNWcVYxOqq9NS+6Iot5JZRJWmb56COtHOR ybMUBJyrb1j7M3JaV83tAi+lHu7UDqvTWDcyv0yazlD4K6bq7hylT6lV4KnyPYQlEsvi OSIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Acy4qeR6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l8-20020a170902f68800b001b8a67f1c10si2525039plg.468.2023.11.08.06.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 06:25:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Acy4qeR6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A73738331DE7; Wed, 8 Nov 2023 06:25:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232821AbjKHOZ3 (ORCPT + 32 others); Wed, 8 Nov 2023 09:25:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbjKHOZ0 (ORCPT ); Wed, 8 Nov 2023 09:25:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA7FD1FC2 for ; Wed, 8 Nov 2023 06:25:24 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C151CC433C7; Wed, 8 Nov 2023 14:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699453524; bh=BJTb9S/48BMXgKg9JdebJFjIf4uCQaHDkO4DGbu+/d0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Acy4qeR6BmcEQIGzPtHgOgB0gKQWzzYs3q3oYarlZc076haMeyyfEC9YzRmimIDDw yChtK1EyyMO6JJfs7T5C5Xd/g8i5c+LZbJ8fGQSEh2ueMA5xbuTdT+8Q1usaEPA30/ G7/8A+L1F+jJhYu00RzU545pcHZRXIyNPk5TXUYTlkHq1wIU+E1nBN1RcppKb+Xv2K DbVJnnTZSm+IYeZ9ma/6stb7jIlu0aPS6dBQnRRSkmDZ0z9PYwYumtdzCNQfJWNRCb KQvpIIGZqeK8rfyHkvBoYageUDVVhi9f0hf1CZYG6ZKZUza1IK1VJIc58YW20EqeRU 2NUTsAG4iorNQ== 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: [RFC PATCH v2 05/31] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long Date: Wed, 8 Nov 2023 23:25:18 +0900 Message-Id: <169945351784.55307.8993860437930966865.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169945345785.55307.5003201137843449313.stgit@devnote2> References: <169945345785.55307.5003201137843449313.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 08 Nov 2023 06:25:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782006188139705521 X-GMAIL-MSGID: 1782006188139705521 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;