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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20151118182304.GG4138@pd.tnic>
Date:	Wed, 18 Nov 2015 19:23:04 +0100
From:	Borislav Petkov <bp@...en8.de>
To:	Ingo Molnar <mingo@...nel.org>
Cc:	X86 ML <x86@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Andy Lutomirski <luto@...capital.net>,
	Herbert Xu <herbert@...dor.apana.org.au>,
	Matt Mackall <mpm@...enic.com>, Chris Mason <clm@...com>,
	Josef Bacik <jbacik@...com>, David Sterba <dsterba@...e.com>
Subject: Re: [RFC PATCH 3/3] x86/cpufeature: Remove unused and seldomly used
 cpu_has_xx macros

On Tue, Nov 10, 2015 at 01:30:00PM +0100, Ingo Molnar wrote:
> 
> * Borislav Petkov <bp@...en8.de> wrote:
> 
> > From: Borislav Petkov <bp@...e.de>
> > 
> > Those are stupid and code should use static_cpu_has_safe() anyway. Kill
> > the least used and unused ones.
> 
> So cpufeature.h doesn't really do a good job of explaining what the difference is 
> between all these variants:

How's that for starters?

---
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 27ab2e7d14c4..a9a8313e278e 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -351,6 +351,10 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
 	   (((bit)>>5)==8 && (1UL<<((bit)&31) & DISABLED_MASK8)) ||	\
 	   (((bit)>>5)==9 && (1UL<<((bit)&31) & DISABLED_MASK9)) )
 
+/*
+ * Test whether the CPU represented by descriptor @c has the feature bit @bit
+ * set.
+ */
 #define cpu_has(c, bit)							\
 	(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 :	\
 	 test_cpu_cap(c, bit))
@@ -416,11 +420,6 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
 extern void warn_pre_alternatives(void);
 extern bool __static_cpu_has_safe(u16 bit);
 
-/*
- * Static testing of CPU features.  Used the same as boot_cpu_has().
- * These are only valid after alternatives have run, but will statically
- * patch the target code for additional performance.
- */
 static __always_inline __pure bool __static_cpu_has(u16 bit)
 {
 #ifdef CC_HAVE_ASM_GOTO
@@ -495,6 +494,18 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
 #endif /* CC_HAVE_ASM_GOTO */
 }
 
+/*
+ * Test whether the boot CPU has feature bit @bit enabled.
+ *
+ * This is static testing of CPU features. It is used in the same manner as
+ * boot_cpu_has(). It is differs from the previous one in that the alternatives
+ * infrastructure will statically patch the code where the test is performed for
+ * additional performance.
+ *
+ * However, results from that macro are only valid after the alternatives have
+ * run and not before that. IOW, you want static_cpu_has_safe() instead, see
+ * below.
+ */
 #define static_cpu_has(bit)					\
 (								\
 	__builtin_constant_p(boot_cpu_has(bit)) ?		\
@@ -580,6 +591,11 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
 #endif /* CC_HAVE_ASM_GOTO */
 }
 
+/*
+ * Like static_cpu_has() above but it works even before the alternatives have
+ * run by falling back to boot_cpu_has(). You should use that macro for all your
+ * CPU feature bit testing needs.
+ */
 #define static_cpu_has_safe(bit)				\
 (								\
 	__builtin_constant_p(boot_cpu_has(bit)) ?		\

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ