From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>,
Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] x86/bitops: Account for POPCNT errata on earlier Intel CPUs
Date: Wed, 26 Mar 2025 09:34:45 +0000 [thread overview]
Message-ID: <a57c2ae0-2c9f-4fac-9ebb-a570f0f2cabc@citrix.com> (raw)
In-Reply-To: <56fbd614-2b46-4cc2-88f3-e244aedd5479@suse.com>
On 26/03/2025 9:20 am, Jan Beulich wrote:
> On 25.03.2025 19:52, Andrew Cooper wrote:
>> It turns out that LZCNT/TZCNT have the same input dependent bug, prior to
>> Skylake.
> These two do, but BSF/BSR don't? Pretty odd.
BSF/BSR have true input dependencies. They both have cases where the
destination register is left unmodified.
>
>> --- a/xen/arch/x86/include/asm/bitops.h
>> +++ b/xen/arch/x86/include/asm/bitops.h
>> @@ -488,10 +488,16 @@ static always_inline unsigned int arch_hweightl(unsigned long x)
>> *
>> * This limits the POPCNT instruction to using the same ABI as a function
>> * call (input in %rdi, output in %eax) but that's fine.
>> + *
>> + * On Intel CPUs prior to Cannon Lake, the POPCNT instruction has a false
>> + * input dependency on it's destination register (errata HSD146, SKL029
>> + * amongst others), impacting loops such as bitmap_weight(). Insert an
>> + * XOR to manually break the dependency.
>> */
> With this being an Intel-only issue, wouldn't we better ...
>
>> alternative_io("call arch_generic_hweightl",
>> + "xor %k[res], %k[res]\n\t"
> ... put this line in #ifdef CONFIG_INTEL then? The extra overhead is small, but
> I see no reason not to avoid it if we can. (I realize that's not quite as
> straightforward as it reads, for alternative_io() being a macro.)
For an XOR, no; not worth the complexity.
Besides, this gets used a whole 5 locations in the hypervisor, after I
cleaned up the paths which shouldn't have been using hweight() in the
first place.
~Andrew
next prev parent reply other threads:[~2025-03-26 9:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 18:52 [PATCH] x86/bitops: Account for POPCNT errata on earlier Intel CPUs Andrew Cooper
2025-03-26 9:20 ` Jan Beulich
2025-03-26 9:34 ` Andrew Cooper [this message]
2025-03-26 9:47 ` Jan Beulich
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=a57c2ae0-2c9f-4fac-9ebb-a570f0f2cabc@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.