lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMzpN2jCceqKTkSYTCK4q=_3s-QCZWk6AA6=QfawjhCd_6Pj_w@mail.gmail.com>
Date: Thu, 27 Jun 2024 14:39:32 -0400
From: Brian Gerst <brgerst@...il.com>
To: "Xin Li (Intel)" <xin@...or.com>
Cc: linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org, 
	tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, 
	dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com, will@...nel.org, 
	peterz@...radead.org, akpm@...ux-foundation.org, acme@...nel.org, 
	namhyung@...nel.org, andrew.cooper3@...rix.com
Subject: Re: [PATCH v3B 4/4] x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET

On Tue, Jun 25, 2024 at 1:23 AM Xin Li (Intel) <xin@...or.com> wrote:
>
> Generate macros {REQUIRED|DISABLED}_MASK_BIT_SET in the newly added AWK
> script that generates the required and disabled feature mask header.
>
> Suggested-by: Brian Gerst <brgerst@...il.com>
> Signed-off-by: Xin Li (Intel) <xin@...or.com>
> ---
>
> Change since v3A:
> * Use '1U' instead of '1' in feature mask shifting (Andrew Cooper).
>
> Change since v3:
> * Checking NCAPINTS isn't necessary anymore.  It was needed when these
>   macros had to be manually updated, but now if cpufeatures.h changes
>   this header will be regenerated (Brian Gerst).
> ---
>  arch/x86/include/asm/cpufeature.h | 69 -------------------------------
>  arch/x86/tools/featuremasks.awk   |  9 +++-
>  2 files changed, 8 insertions(+), 70 deletions(-)
>
> diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
> index 8332f596ba3c..8161dfb3255c 100644
> --- a/arch/x86/include/asm/cpufeature.h
> +++ b/arch/x86/include/asm/cpufeature.h
> @@ -55,75 +55,6 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
>  #define test_cpu_cap(c, bit)                                           \
>          arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
>
> -/*
> - * There are 32 bits/features in each mask word.  The high bits
> - * (selected with (bit>>5) give us the word number and the low 5
> - * bits give us the bit/feature number inside the word.
> - * (1UL<<((bit)&31) gives us a mask for the feature_bit so we can
> - * see if it is set in the mask word.
> - */
> -#define CHECK_BIT_IN_MASK_WORD(maskname, word, bit)    \
> -       (((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
> -
> -/*
> - * {REQUIRED,DISABLED}_MASK_CHECK below may seem duplicated with the
> - * following BUILD_BUG_ON_ZERO() check but when NCAPINTS gets changed, all
> - * header macros which use NCAPINTS need to be changed. The duplicated macro
> - * use causes the compiler to issue errors for all headers so that all usage
> - * sites can be corrected.
> - */
> -#define REQUIRED_MASK_BIT_SET(feature_bit)             \
> -        ( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  0, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  1, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  2, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  3, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  4, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  5, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  6, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  7, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  8, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK,  9, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 10, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 11, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 12, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 13, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 14, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 15, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 16, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 20, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 21, feature_bit) ||    \
> -          REQUIRED_MASK_CHECK                                    ||    \
> -          BUILD_BUG_ON_ZERO(NCAPINTS != 22))
> -
> -#define DISABLED_MASK_BIT_SET(feature_bit)                             \
> -        ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  0, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  1, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  2, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  3, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  4, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  5, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  6, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  7, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  8, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK,  9, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 10, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 11, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 12, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 13, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 14, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 15, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 16, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 20, feature_bit) ||    \
> -          CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 21, feature_bit) ||    \
> -          DISABLED_MASK_CHECK                                    ||    \
> -          BUILD_BUG_ON_ZERO(NCAPINTS != 22))
> -
>  #define cpu_has(c, bit)                                                        \
>         (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 :  \
>          test_cpu_cap(c, bit))
> diff --git a/arch/x86/tools/featuremasks.awk b/arch/x86/tools/featuremasks.awk
> index 989b021e73d3..e0383683e630 100755
> --- a/arch/x86/tools/featuremasks.awk
> +++ b/arch/x86/tools/featuremasks.awk
> @@ -77,7 +77,14 @@ END {
>                         printf "#define %s_MASK%d\t0x%08x\n", s, i, masks[i];
>                 }
>
> -               printf "#define %s_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != %d)\n\n", s, ncapints;
> +               printf "\n#define %s_MASK_BIT_SET(x)\t\t\t\\\n", s;
> +               printf "\t((\t\t\t\t\t";
> +               for (i = 0; i < ncapints; i++) {
> +                       if (masks[i])
> +                               printf "\t\\\n\t\t((x) >> 5) == %2d ? %s_MASK%d :", i, s, i;
> +               }
> +               printf " 0\t\\\n";
> +               printf "\t) & (1U << ((x) & 31)))\n";
>         }
>
>         printf "#endif /* _ASM_X86_FEATUREMASKS_H */\n";
> --
> 2.45.2
>

Reviewed-by: Brian Gerst <brgerst@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ