Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp284403lqj; Sat, 1 Jun 2024 20:37:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV+SYNkQAK9HQzLWC+ME2joa68kPDJqCIvsv7VLFiQH4ZIX3ShGmjoDrBFPLP97wkAcBtBNYqhceWdeQ+XI7DqfVkn0QBVMryOkzjEa2A== X-Google-Smtp-Source: AGHT+IFVsqXokdRVloj4t6ws765WfAHYjwP1rPNZdbHHfanM3s89MtmhQXLagFRpPb+Qd/PWl6eK X-Received: by 2002:a05:622a:13d0:b0:43e:9eb:d714 with SMTP id d75a77b69052e-43ff54ff7f0mr61863071cf.54.1717299472511; Sat, 01 Jun 2024 20:37:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717299472; cv=pass; d=google.com; s=arc-20160816; b=s3vpVc4YMtG/YmuRdBodjXcXiJ6ZVCd0MUHFXB7CEcgGut/Ai18CouyqpRU4z95yzC odiuqIu5vvlAGbQXF8RqhRXi9xgwSCQg9LVJUIA4UZrGDKvP/Rb/aS7Qtc0dLz5iKALr CHoi1vnaD7I1gkhyDHqi+D5X7sPJZjkQ+FUGTON0GUATckP6ltRq+lHRK/CwWXPF4pN2 9gJ12MlWwKbAPLaxN1bJKhxG0F9D/21rRUw1ysXgaO51cEWbmoUyrpYkYxl4PBscWZ3j mfDQYg/Na59wdF4yMkvPUc5m1k21UyvweuhUyLpEjueoaZhMzcmtsz3/69gQ2zBPHGZ0 sXWQ== 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=b7Vb5bnCSiCTSnP2oAOQU4qRLbir4aGzHXlkWMUXk3Y=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=z1oSkf9GRCs53x7H0i+T6Efsxjy5/LWu9TwHrkFWYvHMG6vbESMWkpITg+QC9teEf+ +0Y3nlG/q1VjOKyyQF12Vf5aykbkHY9ZaSGDuIc2MGVYjCQn3qai0JJCZyENQAFtKRA/ q3AzmIydAhLTwF7ASU1ivBm52NpmZ56fcE4uyUCxTnIQ/lOpaeA2aV5SgAnjptVAjz3x nFDz1HEovSsAWINnYEzgtA8Nq2zn6U3bDXMsQdKLIW6VCjrOEY59OFBlnT1NLZGb81d9 4FvDXwI61ElM3fcXim03li73ZFnUQSrwtwrb5reyEHlAZfLKmEDUvWi2+r+BeECEFD55 2aYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-198084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198084-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43ff24681b4si57899401cf.358.2024.06.01.20.37.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 20:37:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198084-linux.lists.archive=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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-198084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198084-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1528C1C20CC3 for ; Sun, 2 Jun 2024 03:37:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C5CA18E1E; Sun, 2 Jun 2024 03:37:25 +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 AEE421173F; Sun, 2 Jun 2024 03:37:24 +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=1717299444; cv=none; b=U2CssKSem4O4+B9+Ny0Wf0bS0FIc+vxe4ZW24Ba6NAPJpPIRqzG/RuEkDRrZQagyepp6+2ffDN1LVkerfwXNNVCaqaOH8jmVeMExYNW3Hui+uOuL3VKvhfqJp/5MtwMZC28HWCkrbkmvb8WYQz+ofPjnhIcN5w6TY8r0VxDM47A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717299444; c=relaxed/simple; bh=9lgCYOF+tkC1R4x/Mh3CLz0Erih4ZZSea1s6G/+5Llo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cpuEfqD4giBrVUVcVN5OtxO0t++wbo234K0B/ItZw3tlPa2ATJklDf4vn5qwjQI/PemH6/rlaf4i/GE/Y9c+77l0MuXnzYkyeycuMQJuqPDaQaDiA7opQCEQygjKgdjbkajrUr+6qItVJxZVdca5jFZfjE7HJw5w0zrcaYBgovY= 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 54C0FC4AF0D; Sun, 2 Jun 2024 03:37:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sDc3D-000000094K0-2Ieq; Sat, 01 Jun 2024 23:38:31 -0400 Message-ID: <20240602033831.407508591@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 01 Jun 2024 23:37:46 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-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 , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [PATCH v2 02/27] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long References: <20240602033744.563858532@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 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