From patchwork Fri Dec 8 10:25:04 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: 175733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5362237vqy; Fri, 8 Dec 2023 02:25:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMOao0dBoX+FHy6AXXSJ5XIKEnwVvxNDnJbrW6WnU7U2tUV6/wYzytsC6NAh/AqYk+IsU1 X-Received: by 2002:a17:90b:3912:b0:286:8672:5199 with SMTP id ob18-20020a17090b391200b0028686725199mr3146588pjb.35.1702031123646; Fri, 08 Dec 2023 02:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702031123; cv=none; d=google.com; s=arc-20160816; b=Upp3kPDdtadS9RF3G69gTQ5x8T0eX5/ZQzshejfiPkRvMpO5ItWuZcS86jydrRo+0J 9u75Bhg0RPtiJLt/gaotrfUWidTR27zazQ57F44c6RH+7EnuMaQjq9aI0C5Mngb4LRvB CwGAcDZI05wUdf8UywVsQ4eNf662WmuFvp+l4/qlG3Np+RrClwGAXvcZFVra9wgFhpU1 DAhUiQEL58/BrAP28eewW7CalXY7oqJOYYcXatsN1KrN6YDJ1iBgGnosaPhTc+pAyIk1 7PGNTmqbmjIf+91KKDcSh85xuQZp2pUCX+JDZ0SSP5sFv+DCH/48/rx3wiDlj/U3Nngg OXIQ== 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=rNVJPsaWm6yXwkthqGGBkZrqfIuEA1NJWWx31HnqkX1oy0xnarCBVz6zVwcwwMyoWs mDpH/QpbAjaTaz/LWIHVZUO8asOoE5duTp1oHYqhPN0gad9B2YHo8bE6LDR5VP0e5QuX toT37mGBe8up6axgf9sN/p/QL5P5YLWIccaEUFbQySVxaKt+Zlpqcw8ozymuVwihuaHD MPc9nzpm1sfVf9c2hJaR1utLs3eBiQeOgvRZdBAYoledyNFusNFI15Km4+Eb99kliQq+ cKb8bX65kV7908V38WnXGuMqM+DGPeP0nQ63H5itZq55NwNY/uVA2xwfjELqxi/NZgu1 LEvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rjbs+hxY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id x18-20020a17090aca1200b00285a62cc148si2726408pjt.134.2023.12.08.02.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 02:25:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rjbs+hxY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id C26C880F7E55; Fri, 8 Dec 2023 02:25:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573498AbjLHKZK (ORCPT + 99 others); Fri, 8 Dec 2023 05:25:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235889AbjLHKZF (ORCPT ); Fri, 8 Dec 2023 05:25:05 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFB001984 for ; Fri, 8 Dec 2023 02:25:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F007C433C8; Fri, 8 Dec 2023 10:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702031111; bh=BJTb9S/48BMXgKg9JdebJFjIf4uCQaHDkO4DGbu+/d0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rjbs+hxYEcpPGC8MLSK/pRCVRAlHDbE4xyI26zR8oOJ2neJs8NZElyzvWcuAglWyZ 6t7b6lQ+IBpA5CRFFwnlgLfpPBc87ApEPbidq42KRdPkgztPGUlHJeR8VcN/YjwEVm lh+tvQXFVncZc60f9RGHknM4JkopKP1bepIBXGJlr/hnzjytvBohTu+OjXV1AfuSMq KCqVjaiOmFqtAvkAvf+9Tf9odx/Njr1mOhSdQUlj8hok1i9Ud4RlwfHLlxL/nAaTAp i2C3LSiTdAPbqSgF05bRGR+HZIZ6XC1fjKavyeFRHbZB8850iHQ7d1RjfVCDV4zlJJ 51T6M60msuGJA== 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 v4 04/33] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long Date: Fri, 8 Dec 2023 19:25:04 +0900 Message-Id: <170203110417.579004.1203622490067947084.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170203105427.579004.8033550792660734570.stgit@devnote2> References: <170203105427.579004.8033550792660734570.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Fri, 08 Dec 2023 02:25:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784708987602219950 X-GMAIL-MSGID: 1784708987602219950 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;