Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp153475lqb; Tue, 4 Jun 2024 07:43:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxyinxVOQyUHPtNarQt+lhQvm6vkRZenhzbGF4ovzi2GDr9OHeTfDBQBSDZNRI3+lajMlyNs9KQnuD15cSmjRhH6c+fyuc15Ih5xFOjw== X-Google-Smtp-Source: AGHT+IGsQkj5hnNrplIg1r+WPgtRJlSXDT7nc0Het70tsdiSYtqhWqp+aa0StAz18chgeLlnMqUS X-Received: by 2002:ac2:52a6:0:b0:52b:8255:71cf with SMTP id 2adb3069b0e04-52b896c7805mr8388846e87.47.1717512229121; Tue, 04 Jun 2024 07:43:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717512229; cv=pass; d=google.com; s=arc-20160816; b=RBwe/QXDoFkDhcRAZYBJgOrH3dOb7koC6XPAYAuFLh90lbEXCvC8IDv8Q4hogkVmlo gteD3YhlNGxbL2/fYhbbqcW9uMmuHpKF+Z0G5zlxbXiEospo+wHaxVZ+tmex/J/QLNz/ TicdfRfh9pL+8HlUz9onvulvSHbnAJQuiv7/2DOHImyaQJLnXO0DW5dFsnYc8EiSXyVl 8xk2mLHaD7U0ZBuXcomj4uhaQtbSuZpSMrvr75HlbI1EPY+Cs8Ccf3+nh3e/NbpMCP2Y 9U4g36UjDv7589+goLGvq301Mk79AbClLbQYXg8i7CakM/u6vPyb6nyZPP4Hyu+g70+4 jq6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=9nIi09a+jdH3EAIpQiS+zqSJsY2mZ1vHjgQQ3VUHg2g=; fh=HwmmpsnswhSdtXIJAPmQKgAimitzBfDFcXviuitYMp4=; b=Y5gRS+3o9rYiHCeh5Nz5z6diifMjIBV8cobWdRDkUxQ9LubH7Bp9s7iBddV2SE6PCu 6f5CtvULVqOpASBkiQ/jLnkPgCPypfr+8RJrGrBxGD7Vu0uvX2AGuxj4Lip88SmgOdFS wmmVgBG5LzhrEgnss8NLjh7ZaCdTGl6B+vnRdd7++kyJK4xM1Dt7T/J7IWar6jCze6RZ FaOKxwpmqMup2y5YGJEYGwfxrr8i6P4lzQWHcNtusWsXnum/7Z2gntplAdkIPglfDrQ2 245e9F8VWEFUBSTQRAe66nc97ogTRVpwrSlM0UjRcBDv9rPD2LscrrtHhTngS8dLbqUu A52w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200863-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200863-linux.lists.archive=gmail.com@vger.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 4fb4d7f45d1cf-57a31b816a4si5318428a12.74.2024.06.04.07.43.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 07:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200863-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200863-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200863-linux.lists.archive=gmail.com@vger.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 BBE271F21DE4 for ; Tue, 4 Jun 2024 14:43:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 674C2144D10; Tue, 4 Jun 2024 14:42:15 +0000 (UTC) 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 CCA80171BA; Tue, 4 Jun 2024 14:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717512134; cv=none; b=NJHB799f2yP/NIPKFVhsd+ZkfGxFF5gCWORm4rTJZssjJwkB3Z6ztk9Gk7B6kK0fcF/Dshw4mtDKakJyi7lj3LM9yB/MtZOCwAzRz3l/FRx8dOu6/lDISS8+SRwhDA7CRNXRZpXYKinKDm/L926UCjGhro+/Sw+vZRMN7I8Zd9w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717512134; c=relaxed/simple; bh=vYV83xCHqW60X90yf6GZR914c8efb/jm9Lzm+HGekqU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=i9KnTKdk6eGfiBWwTjDywHMWe6eyWPUymY+qPDZ3KGooxJoBoKajC4rQ2NPvyeTzCubgbiGi5hd8lLAoX4Vxx9xYr89TdaB+Z6gh5+d1XNlKlGXhao69Bm7EPU6woY1YAdg9K8BY93p8uNZyXjsSMNPTjVG4zv9/3U29L9s2Qq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88ABAC4AF07; Tue, 4 Jun 2024 14:42:14 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sEVMc-00000000Yu7-1oTd; Tue, 04 Jun 2024 10:42:14 -0400 Message-ID: <20240604144214.299594261@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Jun 2024 10:41:05 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Alexei Starovoitov , Florent Revest , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Thomas Gleixner , Guo Ren , Peter Zijlstra Subject: [for-next][PATCH 02/27] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long References: <20240604144103.293353991@goodmis.org> 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 From: "Steven Rostedt (VMware)" Instead of using "ALIGN()", use BUILD_BUG_ON() as the structures should always be divisible by sizeof(long). Co-developed with Masami Hiramatsu: Link: https://lore.kernel.org/linux-trace-kernel/171509093949.162236.14518699447151894536.stgit@devnote2 Link: http://lkml.kernel.org/r/20190524111144.GI2589@hirez.programming.kicks-ass.net Link: https://lore.kernel.org/linux-trace-kernel/20240603190821.232168933@goodmis.org Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Alexei Starovoitov Cc: Florent Revest Cc: Martin KaFai Lau Cc: bpf Cc: Sven Schnelle Cc: Alexei Starovoitov Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Daniel Borkmann Cc: Alan Maguire Cc: Thomas Gleixner Cc: Guo Ren Reviewed-by: Masami Hiramatsu (Google) Suggested-by: Peter Zijlstra Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index c62e6db718a0..fdb206aeffe3 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -33,7 +33,7 @@ * SHADOW_STACK_MAX_OFFSET: The max offset of the stack for a new frame to be added */ #define FGRAPH_FRAME_SIZE sizeof(struct ftrace_ret_stack) -#define FGRAPH_FRAME_OFFSET (ALIGN(FGRAPH_FRAME_SIZE, sizeof(long)) / sizeof(long)) +#define FGRAPH_FRAME_OFFSET DIV_ROUND_UP(FGRAPH_FRAME_SIZE, sizeof(long)) #define SHADOW_STACK_SIZE (PAGE_SIZE) #define SHADOW_STACK_OFFSET \ (ALIGN(SHADOW_STACK_SIZE, sizeof(long)) / sizeof(long)) @@ -103,6 +103,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. @@ -326,6 +328,8 @@ ftrace_graph_get_ret_stack(struct task_struct *task, int idx) { int index = task->curr_ret_stack; + BUILD_BUG_ON(FGRAPH_FRAME_SIZE % sizeof(long)); + index -= FGRAPH_FRAME_OFFSET * (idx + 1); if (index < 0) return NULL; -- 2.43.0