From patchwork Fri Aug 9 19:15:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 13759169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5DF0C3DA4A for ; Fri, 9 Aug 2024 19:18:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=00CQDJv56R56E0v7S3AM5QNWk5MpGT79Ov7YjoX0w98=; b=EG05d5DVTmOE5UunzTg/3Oq1ta laJREjgCsFC6dOndfsAE62CcQMkEWdy2hoar/qMUFep/1oYGgxsLDLaJ3wcIgciPAuul2PvS4PjjX WGGRSaOS4wdejoRqKrRtR48a3Vaq79kDxC64jULeC3gefC4XszexoDib8LvVr3ZWGlcC/JHiSL00R NAAvPISiaaYXVrkGDqW6+vHHSXgvKHZWCGh/rDvMq69GW7G64YLZjVAV+jE7Ef12DS9maFPCGgeYJ OtjRUAl6+YbKtgr1IEx+haHOxY54nSG3vfY48w/6agODgPWnQGGrQrivhfPp/S6nldVwDp2eSnR9Z xz//uLeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1scV7t-0000000CKoe-0XcV; Fri, 09 Aug 2024 19:18:13 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1scV5h-0000000CKBE-44fE for linux-arm-kernel@lists.infradead.org; Fri, 09 Aug 2024 19:15:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 307A313D5; Fri, 9 Aug 2024 12:16:23 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 952C13F71E; Fri, 9 Aug 2024 12:15:56 -0700 (PDT) From: Robin Murphy To: will@kernel.org Cc: mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ilkka@os.amperecomputing.com Subject: [PATCH 4/8] perf/arm-cmn: Improve build-time assertions Date: Fri, 9 Aug 2024 20:15:43 +0100 Message-Id: <2aabebd619b65416a6cd2ca7058ca85fa3656958.1723229941.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240809_121558_079193_8068119F X-CRM114-Status: GOOD ( 11.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org These days we can use static_assert() in the logical place rather than jamming a BUILD_BUG_ON() into the nearest function scope. And since it is now so convenient to do so, let's add an extra one to reinforce the dtm_idx bitmap as well. Signed-off-by: Robin Murphy --- drivers/perf/arm-cmn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index c9a2b21a7aec..8f7a1a6f8ab7 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -577,6 +577,9 @@ struct arm_cmn_hw_event { bool wide_sel; enum cmn_filter_select filter_sel; }; +static_assert(sizeof(struct arm_cmn_hw_event) <= offsetof(struct hw_perf_event, target)); +/* Currently XPs are the node type we can have most of; others top out at 128 */ +static_assert(sizeof_field(struct arm_cmn_hw_event, dtm_idx) >= CMN_MAX_XPS / 4); #define for_each_hw_dn(hw, dn, i) \ for (i = 0, dn = hw->dn; i < hw->num_dns; i++, dn++) @@ -587,7 +590,6 @@ struct arm_cmn_hw_event { static struct arm_cmn_hw_event *to_cmn_hw(struct perf_event *event) { - BUILD_BUG_ON(sizeof(struct arm_cmn_hw_event) > offsetof(struct hw_perf_event, target)); return (struct arm_cmn_hw_event *)&event->hw; }