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 0297436AEB for ; Tue, 9 Jan 2024 11:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ha680r0r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D11CC433F1; Tue, 9 Jan 2024 11:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704800428; bh=9v2sF+hZQgGLtSlalEb8xpEOtIYWC2+MtHxdv7xG+bU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ha680r0rM5BJ2jvajxvVgLRnPLH2VjdFQaKzk0el+sFtl/BYV0OKJff8NK5cAHp7j mjgrsZWltrB11RVmeMCcZw6Go34MVE/NJC3gd7l/MX/0oC1K1Oy44vepHgTHFWkYb/ S0rALmgs6QtiwbEFw9rVDCRW6pOtQKE9Q++ZqJQR5d/cmj2dkmtXbaiXn8tqTjOfVj HNh+/9laJU3brFmvHMYEIWOOr8FnUhOTfSmecoCFwQn/HEZPo3VhgrjIiQSNRl/Wdg rtYAxE5m4fLWbvEhn+WBpXX7Jnt3kuo4ApIQJKKqNntMH7ncifn+HsDk+p+0SO0Cxx bqMeYeHeX227w== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.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 1rNAT3-00AACE-IH; Tue, 09 Jan 2024 11:40:25 +0000 Date: Tue, 09 Jan 2024 11:40:19 +0000 Message-ID: <87plyau44c.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: <86a5pfafbv.wl-maz@kernel.org> References: <20231127114559.990314-1-maz@kernel.org> <20231127114559.990314-3-maz@kernel.org> <20231211122416.GA25277@willie-the-truck> <86a5pfafbv.wl-maz@kernel.org> 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/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII 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 On Mon, 08 Jan 2024 17:46:12 +0000, Marc Zyngier wrote: > > On Mon, 11 Dec 2023 12:24:16 +0000, > Will Deacon wrote: [...] > > > 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: Actually, scratch that. The original code is correct and does return 0b0111 for the max of a signed 4 bit value, and 0b1000 for the min. The clue is in the bracketing (the '- 1' is applied to the result of the conditional expression in the max case). M. -- Without deviation from the norm, progress is not possible.