From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 276F723D281 for ; Wed, 22 Apr 2026 14:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776869025; cv=none; b=VOfzD/AtQmlOBJNdcGg0jEMACH2bhl3SptA8deyWKkgeX2XCk5SrtP2IwnlVPbtjSrImTrUTVrdJ60NIBiivCgHhn9EzCvZTMipJQQ7SMOJZ9GrzCnRnShzkUldNc5F7gV5jYB6KhZIjhCiRWhXOIQgTc4RJE5JITVDwP3dbOLQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776869025; c=relaxed/simple; bh=1ea+KwZfdTYpB3s5PNSAn6QddPSqeVxzm3nlqZsqNFI=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=HFf9ZjcOWiilFVWxJZq4F7fX+DxDuYrP+aAm/1ln/fmS074YXBUv9qT6LVoJS2RBrPE+aBOX+UfPxaB+w9jyfBNKpI+osQNPZ7le1nH6f+1AZMQD+IddeSuW5ev35Es15zfcxZRZnEr2JSBHlOcPx7ByKWjr2CVdLu3K4osglV8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=paWZYiw2; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="paWZYiw2" 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 DEFB31E8D; Wed, 22 Apr 2026 07:43:37 -0700 (PDT) Received: from [10.1.34.169] (e121487-lin.cambridge.arm.com [10.1.34.169]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BB7593FBF8; Wed, 22 Apr 2026 07:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1776869023; bh=1ea+KwZfdTYpB3s5PNSAn6QddPSqeVxzm3nlqZsqNFI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=paWZYiw2PhHOSqkU0A/rB3nC5Dt+HYt9e+idu3uczE7pHOZ0RoFEnaE29XeSihj/V 83wVwnBqQ9XSPmQAqrokGBR6o5lqLOaBTXmw3Pn/ra3PqpvLUVoDkBR8LXJsWIrT+F PnR2v6TSMG5D2Pzh38B2IP38ilXwu48gPz30xg6Q= Message-ID: Date: Wed, 22 Apr 2026 15:43:39 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm64: traps: Add a macro to simplify the condition codes check To: Jinjie Ruan , catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, kees@kernel.org, maz@kernel.org, ada.coupriediaz@arm.com, smostafa@google.com, leitao@debian.org, mrigendra.chaubey@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20260320082846.1235016-1-ruanjinjie@huawei.com> Content-Language: en-GB From: Vladimir Murzin In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Jinjie, On 4/22/26 04:06, Jinjie Ruan wrote: > > On 3/20/2026 4:28 PM, Jinjie Ruan wrote: >> Add DEFINE_COND_CHECK macro to define the simple __check_* functions >> to simplify the condition codes check. >> >> No functional changes. > Gentle ping. > >> Signed-off-by: Jinjie Ruan >> --- >> arch/arm64/kernel/traps.c | 59 ++++++++++----------------------------- >> 1 file changed, 15 insertions(+), 44 deletions(-) >> >> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c >> index 914282016069..6216fe9e8e42 100644 >> --- a/arch/arm64/kernel/traps.c >> +++ b/arch/arm64/kernel/traps.c >> @@ -49,45 +49,21 @@ >> #include >> #include >> >> -static bool __kprobes __check_eq(unsigned long pstate) >> -{ >> - return (pstate & PSR_Z_BIT) != 0; >> -} >> - >> -static bool __kprobes __check_ne(unsigned long pstate) >> -{ >> - return (pstate & PSR_Z_BIT) == 0; >> -} >> - >> -static bool __kprobes __check_cs(unsigned long pstate) >> -{ >> - return (pstate & PSR_C_BIT) != 0; >> -} >> - >> -static bool __kprobes __check_cc(unsigned long pstate) >> -{ >> - return (pstate & PSR_C_BIT) == 0; >> -} >> - >> -static bool __kprobes __check_mi(unsigned long pstate) >> -{ >> - return (pstate & PSR_N_BIT) != 0; >> -} >> - >> -static bool __kprobes __check_pl(unsigned long pstate) >> -{ >> - return (pstate & PSR_N_BIT) == 0; >> -} >> - >> -static bool __kprobes __check_vs(unsigned long pstate) >> -{ >> - return (pstate & PSR_V_BIT) != 0; >> -} >> - >> -static bool __kprobes __check_vc(unsigned long pstate) >> -{ >> - return (pstate & PSR_V_BIT) == 0; >> -} >> +#define DEFINE_COND_CHECK(name, flag, expected) \ >> +static bool __kprobes __check_##name(unsigned long pstate) \ >> +{ \ >> + return ((pstate & (flag)) != 0) == (expected); \ >> +} >> + >> +DEFINE_COND_CHECK(eq, PSR_Z_BIT, true) >> +DEFINE_COND_CHECK(ne, PSR_Z_BIT, false) >> +DEFINE_COND_CHECK(cs, PSR_C_BIT, true) >> +DEFINE_COND_CHECK(cc, PSR_C_BIT, false) >> +DEFINE_COND_CHECK(mi, PSR_N_BIT, true) >> +DEFINE_COND_CHECK(pl, PSR_N_BIT, false) >> +DEFINE_COND_CHECK(vs, PSR_V_BIT, true) >> +DEFINE_COND_CHECK(vc, PSR_V_BIT, false) >> +DEFINE_COND_CHECK(al, 0, false) /* Always true */ >> >> static bool __kprobes __check_hi(unsigned long pstate) >> { >> @@ -131,11 +107,6 @@ static bool __kprobes __check_le(unsigned long pstate) >> return (temp & PSR_N_BIT) != 0; >> } >> >> -static bool __kprobes __check_al(unsigned long pstate) >> -{ >> - return true; >> -} >> - >> /* >> * Note that the ARMv8 ARM calls condition code 0b1111 "nv", but states that >> * it behaves identically to 0b1110 ("al"). > It looks like we now have a mix of checks implemented via macros and others written out explicitly. The existing approach has the advantage of being consistent and easy to follow, whereas introducing macros here, even if it reduces some duplication, adds a bit of cognitive overhead when reading the code. This may come down to preference, but I think sticking to a single, consistent style would make the code easier to scan and maintain. Just my 2p. Cheers Vladimir