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 781BFC433F5 for ; Mon, 7 Mar 2022 18:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Yt/+fYddhcT7+QsywT09uZG+v1lCk53p69SbcJ1NK2A=; b=N3KLiW8Z1J4Wsz i4waApc+ubsnjFj+TimvxEOLoCAT4F7GSfNDtzARO6wNkAaYMsj7an+p3B6FIkoT4IfMEn+M9m3wC n3ASCdLpUwOfeTdw82YJPeywZPe/xV0rE0365FqgoK7NLYHxmxTpvw/zCDQjb+kmChdC8nuMNIHlR 7X5uwnGynw+j973EHVgtEaja445wBjVdrIXrjf3AvrQWxJUMVus1SGD9XE6ljRs9AIpaHhIBztImP +Rp5GdyEHKT5XXdL2yrblCcDpgve9MjJUga6gF5yvZJSgb/5iEGXT5mk18Y+q8dqnir2SUHPcCljJ sVkSLwbLYvuTZFfA9tZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRHnJ-0015ts-S9; Mon, 07 Mar 2022 18:09:18 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRHnF-0015t4-VR for linux-arm-kernel@lists.infradead.org; Mon, 07 Mar 2022 18:09:15 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AD6DFB81646; Mon, 7 Mar 2022 18:09:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 801ADC340EB; Mon, 7 Mar 2022 18:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646676551; bh=5n3GMriRcFm3n2KBmnHdSynwPlB+MEQHQ30pZ1vlpTU=; h=From:To:Cc:Subject:Date:From; b=k8Rg+jESRtpyK1YcE3nJbqHcKxYbRbITpNrU5/UrIXxmNQt94PSFEiBeYfXagIx+l 9meSZveR5UmOR04GT0eHgMk/9ortmqKiBVZ91S5+pev26ukaxNY5M90k3iPgMvQ+kS C1hwoE+jbtrFLNnTflqjxWtB+1yqJ+zYIqGYi6hEqDSh7AZQ0iOHlcmrsKrCgP+Kij 8YXINin6jw9oEv7JeboQgN92XzRhEAHMjPg3W0ZfJYXVetSJPTopaatiFU+1AtreuN 5jSKfrITmEbkSv5udTfTeS85DoK1Q8dcgkssuIBwIKOGrPcK5xXb56z9VlcS4MA9Pg maJBFoFnvp43w== From: Mark Brown To: Will Deacon , Catalin Marinas Cc: Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Mark Brown , Marc Zyngier Subject: [PATCH v2] arm64: cpufeature: Warn if we attempt to read a zero width field Date: Mon, 7 Mar 2022 18:08:59 +0000 Message-Id: <20220307180900.3045812-1-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1211; h=from:subject; bh=5n3GMriRcFm3n2KBmnHdSynwPlB+MEQHQ30pZ1vlpTU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiJklfz+P/7WhboVsxKrkyMBkz+/R4i8p+z+BuqHeS JbOkM1OJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYiZJXwAKCRAk1otyXVSH0EOBB/ 9BFvx5NnzS61Vq2wXSMMUqwWk5FBP0VjBu/sRKwmR2xvUWxrT57xtgsCMasYnYcvQCxEb41rCSCgFb l6xm3rp/gZge520STVedgtXqlkbB2INoDAPLumcfsnFb93DGwtjgJs9u1M2T9E6ZAz/cfPXYOnK+kO 7DrERpUMCpGhFAc/lpp2AT+Za0poZjJLqSXeZUQm4V1hpE7smJ+pqop3ny9UDqLPix2jCzZeL+UShq sIo2sPcMHbogqc5LcMQJs1H6GEEH00IZQNfESxzrckeMdoMv1tE0eXS0zm9QWkEVylJrunwnxwnZ6p xkqfbHMA6eRiyW5hyh/MkIAjCfPB1U X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220307_100914_184916_130FC264 X-CRM114-Status: GOOD ( 12.66 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a WARN_ON_ONCE() when extracting a field if no width is specified. This should never happen outside of development since it will be triggered with or without the feature so long as the relevant ID register is present. If the warning triggers hope that the field was the standard 4 bits wide and soldier on. Suggested-by: Marc Zyngier Signed-off-by: Mark Brown --- v2: - Use a width of 4 if the warning triggers. arch/arm64/include/asm/cpufeature.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index e2be53f74cd7..380238ae3321 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -577,6 +577,8 @@ static inline u64 arm64_ftr_reg_user_value(const struct arm64_ftr_reg *reg) static inline int __attribute_const__ cpuid_feature_extract_field_width(u64 features, int field, int width, bool sign) { + if (WARN_ON_ONCE(!width)) + width = 4; return (sign) ? cpuid_feature_extract_signed_field_width(features, field, width) : cpuid_feature_extract_unsigned_field_width(features, field, width); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel