LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 3/3] powerpc: Check only single values are passed to CPU/MMU feature checks
Date: Fri, 10 May 2024 16:45:37 +1000	[thread overview]
Message-ID: <87ikzmmage.fsf@mail.lhotse> (raw)
In-Reply-To: <20240509163456.GX19790@gate.crashing.org>

Segher Boessenkool <segher@kernel.crashing.org> writes:
> On Thu, May 09, 2024 at 10:12:48PM +1000, Michael Ellerman wrote:
>> cpu_has_feature()/mmu_has_feature() are only able to check a single
>> feature at a time, but there is no enforcement of that.
>> 
>> In fact, as fixed in the previous commit, there was code that was
>> passing multiple values to cpu_has_feature().
>> 
>> So add a check that only a single feature is passed using popcount.
>> 
>> Note that the test allows 0 or 1 bits to be set, because some code
>> relies on cpu_has_feature(0) being false, the check with
>> CPU_FTRS_POSSIBLE ensures that. See for example CPU_FTR_PPC_LE.
>
> This btw is exactly
>
> 	BUILD_BUG_ON(feature & (feature - 1));
>
> but the popcount is more readable :-)

Yeah for those of us who don't see bits cascading in our sleep I think
the popcount is easier to understand ;)

cheers

  reply	other threads:[~2024-05-10  6:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 12:12 [PATCH 1/3] powerpc: Drop clang workaround for builtin constant checks Michael Ellerman
2024-05-09 12:12 ` [PATCH 2/3] powerpc/xmon: Fix disassembly CPU feature checks Michael Ellerman
2024-05-09 12:12 ` [PATCH 3/3] powerpc: Check only single values are passed to CPU/MMU " Michael Ellerman
2024-05-09 16:34   ` Segher Boessenkool
2024-05-10  6:45     ` Michael Ellerman [this message]
2024-05-10  8:07       ` Segher Boessenkool
2024-07-12 12:53 ` [PATCH 1/3] powerpc: Drop clang workaround for builtin constant checks Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ikzmmage.fsf@mail.lhotse \
    --to=mpe@ellerman.id.au \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox