From mboxrd@z Thu Jan 1 00:00:00 1970 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 A2EEFC3DA6E for ; Mon, 8 Jan 2024 17:46:50 +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:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6/Opgw2cJJaOsQK6LaF5CkXrXZF8Hu2VVye3pWZQZtE=; b=ktRPNOLafS+Tmh xCjJAJkqIHxTlBu9gYHasCq8NS+rvA9c2JNFI1tbcNKXe40z8N1j8A4XqBU9ScEqcUfoEvhexzKcU wUddqAn8SkxzgLwW3xvW6cASr8XEVQdNIT6lCOi8zUu8Mq1twTzgt3HpaUrVHMhLXa4DkYDcLAU2f y5FqZ5HOw8YTPc9ETUQWpXuvEt7LivyBgDnDs70MGl4yibr/HiCouUvyvVp+2KGyYrnBnZID4UltB G85qwxn8idTDllHg/+OAUii4daK2ObWx4WBVUAxG579pgbsHTUWuERVi+oXPCDB1Xr55OIW4C30Am NtAz4e54qmkiKk8SCbdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rMtha-005n6J-2m; Mon, 08 Jan 2024 17:46:18 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rMthY-005n5v-1t for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2024 17:46:18 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E5A346117E; Mon, 8 Jan 2024 17:46:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87A58C433C8; Mon, 8 Jan 2024 17:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704735975; bh=sggkAbQsD67a6iRYIRHWcupeo05mEp2wThMNl7TOb2k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=D8yiJHlOhBfH8LbxCpQyPb1M/rNyK+MuADzSmu036kjg5983WRKV09qPuqqI4/qQr 8hlhGpBtSdFAZYzqA9qgUQ8IAvz9f2Bb9y+1T9LV+iWBsIwWiJx0sliQFdhYUQ8fYr GwxtjCDdRqBlzRZekONfuGcLF0GnZNakcbmTezI+gHW41CR2J5OAr+lZRrDOTKr7++ mQ68Z1Td1pitJfjr40Ilfy/rt4kkpMuTIvH3jTA7UebhfnksmdvWCEQJ8U+XWzJQOA OR5iTRn1bW3KOp79bgSqAxEm5VIlLgLVxyRZZWyMR+l3FUcs5kc7/5r26phRkLgMf6 DBOZvZyvJFYDA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rMthV-009the-1M; Mon, 08 Jan 2024 17:46:13 +0000 Date: Mon, 08 Jan 2024 17:46:12 +0000 Message-ID: <86a5pfafbv.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Catalin Marinas , Mark Rutland , Ard Biesheuvel , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: Re: [PATCH v3 02/13] arm64: cpufeatures: Correctly handle signed values In-Reply-To: <20231211122416.GA25277@willie-the-truck> References: <20231127114559.990314-1-maz@kernel.org> <20231127114559.990314-3-maz@kernel.org> <20231211122416.GA25277@willie-the-truck> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, catalin.marinas@arm.com, mark.rutland@arm.com, ardb@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240108_094616_705391_96A3DB8C X-CRM114-Status: GOOD ( 30.40 ) 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 On Mon, 11 Dec 2023 12:24:16 +0000, Will Deacon wrote: > > On Mon, Nov 27, 2023 at 11:45:48AM +0000, Marc Zyngier wrote: > > Although we've had signed values for some features such as PMUv3 > > and FP, the code that handles the comparaison with some limit > > has a couple of annoying issues: > > > > - the min_field_value is always unsigned, meaning that we cannot > > easily compare it with a negative value > > > > - it is not possible to have a range of values, let alone a range > > of negative values > > > > Fix this by: > > > > - adding an upper limit to the comparison, defaulting to all bits > > being set to the maximum positive value > > > > - ensuring that the signess of the min and max values are taken into > > account > > > > A ARM64_CPUID_FIELDS_NEG() macro is provided for signed features, but > > nothing is using it yet. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/cpufeature.h | 1 + > > arch/arm64/kernel/cpufeature.c | 65 +++++++++++++++++++++++++---- > > 2 files changed, 57 insertions(+), 9 deletions(-) > > > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > > index f6d416fe49b0..5f3f62efebd5 100644 > > --- a/arch/arm64/include/asm/cpufeature.h > > +++ b/arch/arm64/include/asm/cpufeature.h > > @@ -363,6 +363,7 @@ struct arm64_cpu_capabilities { > > u8 field_pos; > > u8 field_width; > > u8 min_field_value; > > + u8 max_field_value; > > u8 hwcap_type; > > bool sign; > > unsigned long hwcap; > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > index 646591c67e7a..bc8787f28ffd 100644 > > --- a/arch/arm64/kernel/cpufeature.c > > +++ b/arch/arm64/kernel/cpufeature.c > > @@ -140,12 +140,42 @@ void dump_cpu_features(void) > > pr_emerg("0x%*pb\n", ARM64_NCAPS, &system_cpucaps); > > } > > > > +#define __ARM64_MAX_POSITIVE(reg, field) \ > > + ((reg##_##field##_SIGNED ? \ > > + BIT(reg##_##field##_WIDTH - 1) : \ > > + BIT(reg##_##field##_WIDTH)) - 1) > > + > > +#define __ARM64_MIN_NEGATIVE(reg, field) BIT(reg##_##field##_WIDTH - 1) > > I'm struggling to grok these two macros. For example, let's say I have a > 4-bit signed field. In that case, the maximum positive value is 7 (0b0111) > and the minimum negative value is -8 (0b1000), but the macros above appear > to give 0b1000 for both. Crap. Well spotted. The signed maximum needs to be further adjusted like this: #define __ARM64_MAX_POSITIVE(reg, field) \ ((reg##_##field##_SIGNED ? \ BIT(reg##_##field##_WIDTH - 1) - 1: \ BIT(reg##_##field##_WIDTH)) - 1) Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel