Re: [PATCH v2 1/2] lib/crypto: x86/sha1: PHE Extensions optimized SHA1 transform function
From: AlanSong-oc
Date: Thu Jan 15 2026 - 02:48:54 EST
On 1/13/2026 3:34 AM, Eric Biggers wrote:
>
> On Mon, Jan 12, 2026 at 05:12:01PM +0800, AlanSong-oc wrote:
>>> Is it supported in both 32-bit and 64-bit modes? Your patch doesn't
>>> check for CONFIG_64BIT. Should it? New optimized assembly code
>>> generally should be 64-bit only.
>>
>> The XSHA1 and XSHA256 are supported in both 32-bit and 64-bit modes.
>> Since newly optimized assembly code is typically 64-bit only, and XSHA1
>> and XSHA256 fully support 64-bit mode, an explicit CONFIG_64BIT check
>> should not required.
>
> Right, all the x86-optimized SHA-1 and SHA-256 code is already 64-bit
> specific, due to CONFIG_CRYPTO_LIB_SHA1_ARCH and
> CONFIG_CRYPTO_LIB_SHA256_ARCH being enabled only when CONFIG_x86_64=y.
> So there's no need to check for 64-bit again.
>
>>> What is the difference between X86_FEATURE_PHE and X86_FEATURE_PHE_EN,
>>> and why are both needed?
>>
>> The X86_FEATURE_PHE indicates the presence of the XSHA1 and XSHA256
>> instructions, whereas the X86_FEATURE_PHE_EN indicates that these
>> instructions are enabled for normal use.
>
> I still don't understand the difference.
>
> If you look at the other CPU feature flags, like X86_FEATURE_SHA_NI for
> example, there's just a single flag for the feature. We don't have
> X86_FEATURE_SHA_NI and X86_FEATURE_SHA_NI_EN. If the CPU supports the
> feature but the kernel decides it can't or shouldn't be used for
> whatever reason, the kernel just doesn't set the flag. There's no
> separate flag that tracks the CPU support independently.
>
> Why can't the PHE flag work the same way?
Unlike most x86 CPU features, the PHE extension uses two bits to
describe a single feature: a present bit and an enable bit. On Zhaoxin
processors, these two bits are always identical. Therefore, in the next
revision of this patch, I will only check X86_FEATURE_PHE_EN, as with
other CPU support checks. Thanks for the suggestion.
Best Regards
AlanSong-oc