Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp546603lqh; Tue, 7 May 2024 07:09:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnY8ewJWsmOi5TQ4WlNHsD8qYlHn3OXQewLbo0qZCaml8HOzUfJFD/jQoJzUlOjRptBY7RI2hh1sdmyXmUmKaHPtBxs/6LlaiRwV95aQ== X-Google-Smtp-Source: AGHT+IEmIcKv9wTz7Imd39QUoBt4y86MG2Wv8z0SDC06j2dsshfmGJQwZ4H8ncOpUB9ewJDxDxAj X-Received: by 2002:a17:907:3d88:b0:a59:c577:c5c8 with SMTP id he8-20020a1709073d8800b00a59c577c5c8mr4935178ejc.17.1715090985115; Tue, 07 May 2024 07:09:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715090985; cv=pass; d=google.com; s=arc-20160816; b=e2f5Z0ih0DbeQ8/xWIcbNyCSPUuVYF3M8tcRVv8Zxg/GtErSWtFpGW3UeF+homQElr m8/z2mWye+NWDNiiOMWSP3GWmnn7aw4Zht7EJQEiKeSoJ1u4+vOImLIlfyOkc8WNPIUH QWB7NTvUxYMI+RBMo4Sp0jrTdiVzoRDGGxEKZok260jSstlByyx76JlXK+K2ujiSvwLo d+H1UNxFl+FKSn71j4d7blrWxXUX7TAYvV7g+Fb10rMIQQWcAO14RxV6HWuZ1DR0m5HN BhBWkmBoLFBL0tcrIpnNuP3Ug10tIsyY+6EuOfTOdD67lD+7LoCZymBQ5332CyjZajZz Bxdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=eVgZgoy+UGwGEm8Va6QmNfArgtjudfTwfrDl+ut0Pgc=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=ln/p6LOdiTPxVShEM1k4/n+Mijffm1dwcAWnQFWZj8VYtblqjMeDYj0WqrnotcbMkH xg4crCs5zcMnOlmOzLWbE7sZWI1CEwzHxJK7HZeFdUeljPa/bCUNhxxu8oNUfeOCQCbQ XeebLkMCytCL+kub2CB2RwpH+VvS0jZHbYDy77/E+hjtygXaM7ZnMDEWdh0ryf31WTo4 Dz8C2E4gwIk8P4mENiVjojFeqj+jUxFvP46s2LF70EraIlIV3MQ81n9fZCKYBVtUpiSK apvTNm90/GWRBOGXF2k0IQ71qCGdtuOCuzS6wDy1WgZftLJU0yJ216OQ16zTuHsZ7p4+ V1xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u8IfJJl6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dn17-20020a17090794d100b00a59cc76e103si2424558ejc.521.2024.05.07.07.09.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:09:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u8IfJJl6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 D57251F2244D for ; Tue, 7 May 2024 14:09:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B676B15FA97; Tue, 7 May 2024 14:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u8IfJJl6" 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 D9DE915ECD8; Tue, 7 May 2024 14:09:05 +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=1715090945; cv=none; b=I8yetT5ACAmpfuDDsHPCZ+NEZbZXjf3kUR9g/cvoX/LF7lbr8y1v9vSKOJdV5G02PM3ZO9iv6z4hoCnG85ZzvnBAuav6pMdypPs+f3tSoc9HIbH7I8h4KZ+DA+Ml7mZ1pSlzMMi+0xEwPBs472kN6IKrluNC1itrVNc8fzCJ8X0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715090945; c=relaxed/simple; bh=v6a8A4n/NQNVvl6IUBlyb4ncY6wKsPnocwxI4QmL7G4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=g65+gw4EBILZtR/QG8YErEaAQUQxZjiSg01xivGSGrGrqzxI5vqFRfu7OOmpQma1WzUbtaSQahEyJbDTa1YoP37EnkYoXK0dzZP9UeOu/rFhJ0SEm4/O34/7gdjTVlDRJqAw36DUt96KCUSwfcuWGS0h5veSGsqioREgJ3cnTeU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u8IfJJl6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A20DEC2BBFC; Tue, 7 May 2024 14:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715090945; bh=v6a8A4n/NQNVvl6IUBlyb4ncY6wKsPnocwxI4QmL7G4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8IfJJl6+0sZvwL5knwXSlWFzYCOSnHneGE5W1pj4dQX4v86eIjwQjm22o3HdPoeE U1ayi8zgncgcyOmxZOunDL+Uyx6LQ9RHkG2GiM9bfhxfT5qjjWIZphgk1HcODObQfp UarLHDFTviiCashKBTsN+nJx0f+fuq5G736g/Wyim1Et0dCS697/wj7tLa8xLF0VEB jnInb8KOgmtbYMbq6blCk9wVjx4ugF00wPgiQGDQWLCdOZGPcsphikVPWp8eCATibU XN1rx5Yw0PA9xTjcELdoovCXpWGSYBVrNMFt921CuJf+wThe8YUpKIhIsby3lyZUpB hFMsCGfrQl6XQ== 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 v10 05/36] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long Date: Tue, 7 May 2024 23:08:59 +0900 Message-Id: <171509093949.162236.14518699447151894536.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171509088006.162236.7227326999861366050.stgit@devnote2> References: <171509088006.162236.7227326999861366050.stgit@devnote2> User-Agent: StGit/0.19 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" Content-Transfer-Encoding: 8bit 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) --- Changes in v7: - Use DIV_ROUND_UP() to calculate FGRAPH_RET_INDEX --- 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..6f8d36370994 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 DIV_ROUND_UP(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;