Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1186626lqj; Mon, 3 Jun 2024 12:55:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXibBCQg28PUAZr2HxH+mA4gnt13cO+qtKyGE5FJRmN8Gwn4XTYgrhyEiGqmP7k1Frb2FO1r/UmQnts1lyffnRpbnbe0e/iUbDeK358xA== X-Google-Smtp-Source: AGHT+IGy4UJTNFW8oSzTq7sgvUPASBi4IE6igXEuo+yvDF9zNWGvMMPGh18f8S2s5DuywT9864kf X-Received: by 2002:a17:903:230f:b0:1f6:73a9:ec9a with SMTP id d9443c01a7336-1f673a9eff1mr50068815ad.12.1717444506251; Mon, 03 Jun 2024 12:55:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717444506; cv=pass; d=google.com; s=arc-20160816; b=qQe0U7kDs5xZMND2xZX/bFi2Zz0uubKvA3KZFFGckxZiYaS3CCnxnHC+WNro/1ouNs jveb9zCMT9Q88NBjn7HI2/hLpVcoGqPf/j+XliBpd193gtk1H+90WJUo1uKVQoYy+d9H nxyi4o+VeJMfogYHPyrVrR8Off9b3E+U144TQMz58wyFZV4IYGpGRdAeFjXIHRqbn/ur clYPXZ03d5GYS7Sf5kmWGQd19BVjnZyYTuB8P2opmYFCnCAKtUPkStW8HZIMlnjCfYmG G4T4dGMTBMwIdY1EfGPb1GecwagMDSWazDsq5kVenFoM2tZlHGXLpcDRUMGm8ZaS9FcP HDFg== 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=yF2oO/HHTJwbUPVqsPao2eXzuxbrtOQfHsyFpjgIEBgmbY6vK8GRkjoPkGvASzlBx4 1TfP2c4G/mD8W5R0APFtlUXCuIpZDPs8/VdYB8H+Zn3dlBv0Y0q02ygKvC36yFXUyVlu FcngWtfCSdlzKHapS5ztOM/pJtJ6xa1E4iaAUcqZP79R+DGsjBw/xmaogBGdAcv6uXjU zjANP34LnzZ9wSPzl0gOwnPQr6fsxgvM4J+RFiHoy9lqWqhTW5OHgEIo9ObEZ90yKzJY YNE/y2GaZhz7LuuaWJf973RlrfcTK1s2woJ4IEGDKafha0Mev/Q2lk776raoiSGIlWG1 6soA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199597-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f65fce8506si38363675ad.424.2024.06.03.12.55.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:55:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199597-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7C07CB21FD4 for ; Mon, 3 Jun 2024 19:07:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47C1613B596; Mon, 3 Jun 2024 19:07:11 +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 AFCE113A261; Mon, 3 Jun 2024 19:07:10 +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=1717441630; cv=none; b=Pu2LULdwzX8AeJA0zmL2GbKBvFC2gBiT3Q/j5wnL87utiWPRj1PkYN+b0xRRrmjegn9IRZ8g7OxjV2QtwWojaykcrTzMTMqD8M0aeCOQ7WnVIsraKjOYmOz/6j4MKBmNCop4HkASc6OBKJF13BbSAl4G8uGWzyZe234mfRxARWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717441630; c=relaxed/simple; bh=9lgCYOF+tkC1R4x/Mh3CLz0Erih4ZZSea1s6G/+5Llo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sop0rcxGoGl8ffeBs+cit1P75hGoOWN/okyiC+vHoM3HaAyIbQUmqC8n9VSsiK2HwWGdPii2Fdo4gPc9dWXnQVqhUl+eso/FblKbdLW8eDgeymaSbwJBPFzQhY9xrq4YioDTamiPu/9zmkPHSITfJlWW9on0VAIOE+mgktp79sk= 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 5BB58C4AF07; Mon, 3 Jun 2024 19:07:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sED2b-00000009Tn1-1YOC; Mon, 03 Jun 2024 15:08:21 -0400 Message-ID: <20240603190821.232168933@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 03 Jun 2024 15:07:06 -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 v3 02/27] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long References: <20240603190704.663840775@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