x86, vdso: Error out if the vdso contains external references
Subsystems (2)
Commit-ID: 05d0b0889ca9d033a960542af7f8a13b3ad4f630 Gitweb: http://git.kernel.org/tip/05d0b0889ca9d033a960542af7f8a13b3ad4f630 Author: H. Peter Anvin <[email protected]> AuthorDate: Fri, 18 Jun 2010 14:36:26 -0700 Committer: H. Peter Anvin <[email protected]> CommitDate: Fri, 18 Jun 2010 14:46:21 -0700
x86, vdso: Error out if the vdso contains external references
The vdso is a piece of userspace code which is supposed to be fully self-contained. Any external (undefined) reference is an error, and should be caught at compile time. This was giving us trouble when compiling with -Os on gcc 4.5.0, for example (failed inline).
The need to do a buildtime check was pointed out by Andi Kleen.
LKML-Reference: <tip-*@vger.kernel.org>
--- arch/x86/vdso/Makefile | 3 ++- arch/x86/vdso/checkundef.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletions(-)
arch/x86/vdso/Makefile +2 -1
@@ -120,7 +120,8 @@ $(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE quiet_cmd_vdso = VDSO $@ cmd_vdso = $(CC) -nostdlib -o $@ \ $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ - -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) + -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ + sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) GCOV_PROFILE := n
arch/x86/vdso/checkundef.sh new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/sh +nm="$1" +file="$2" +"$nm" "$file" | grep '^ *U' > /dev/null 2>&1 +if [ $? -eq 1 ]; then + exit 0 +else + echo "$file: undefined symbols found" >&2 + exit 1 +fi
arch/x86/vdso/checkundef.sh line 4
Quoted 10 lines
arch/x86/vdso/checkundef.sh new file +4
-0@@ -0,0 +1,10 @@ +#!/bin/sh +nm="$1" +file="$2" +"$nm" "$file" | grep '^ *U' > /dev/null 2>&1
Does that really handle the failed inline, static function case?
In this case you get a function which is not 'U', but it's just in the wrong section. I think that would need to be checked too.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
H. Peter Anvin
reviewerQuoted 13 lines · Andi Kleen
arch/x86/vdso/checkundef.sh line 4
Quoted 10 lines
arch/x86/vdso/checkundef.sh new file +4
-0@@ -0,0 +1,10 @@ +#!/bin/sh +nm="$1" +file="$2" +"$nm" "$file" | grep '^ *U' > /dev/null 2>&1Does that really handle the failed inline, static function case?
Quoted 3 lines
In this case you get a function which is not 'U', but it's just in the wrong section. I think that would need to be checked too.
Makes sense.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
tip-bot for H. Peter Anvin
reviewer[tip:x86/cpu] x86, cpu: Support the features flags in new CPUID leaf 7
In reply to a message not in the archiveCommit-ID: bdc802dcca1709b01988d57e91f9f35ce1609fcc Gitweb: http://git.kernel.org/tip/bdc802dcca1709b01988d57e91f9f35ce1609fcc Author: H. Peter Anvin <[email protected]> AuthorDate: Wed, 7 Jul 2010 17:29:18 -0700 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 7 Jul 2010 17:29:18 -0700
x86, cpu: Support the features flags in new CPUID leaf 7
Intel has defined CPUID leaf 7 as the next set of feature flags (see the AVX specification, version 007). Add support for this new feature flags word.
LKML-Reference: <tip-*@vger.kernel.org>
--- arch/x86/include/asm/cpufeature.h | 13 +++++++++---- arch/x86/include/asm/required-features.h | 2 ++ arch/x86/kernel/cpu/common.c | 10 ++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-)
arch/x86/include/asm/cpufeature.h +9 -4
@@ -6,7 +6,7 @@#include <asm/required-features.h> -#define NCAPINTS 9/* N 32-bit words worth of info */ +#define NCAPINTS 10/* N 32-bit words worth of info */ /* * Note: If the comment begins with a quoted string, that string is used
@@ -159,14 +159,14 @@/* * Auxiliary flags: Linux defined - For features scattered in various -* CPUID levels like 0x6, 0xA etc +* CPUID levels like 0x6, 0xA etc, word 7 */ #define X86_FEATURE_IDA (7*32+ 0)/* Intel Dynamic Acceleration */ #define X86_FEATURE_ARAT (7*32+ 1)/* Always Running APIC Timer */ #define X86_FEATURE_CPB (7*32+ 2)/* AMD Core Performance Boost */ #define X86_FEATURE_EPB (7*32+ 3)/* IA32_ENERGY_PERF_BIAS support */ -/* Virtualization flags: Linux defined */ +/* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW (8*32+ 0)/* Intel TPR Shadow */ #define X86_FEATURE_VNMI (8*32+ 1)/* Intel Virtual NMI */ #define X86_FEATURE_FLEXPRIORITY (8*32+ 2)/* Intel FlexPriority */
@@ -177,6 +177,9 @@#define X86_FEATURE_SVML (8*32+7)/* "svm_lock" AMD SVM locking MSR */ #define X86_FEATURE_NRIPS (8*32+8)/* "nrip_save" AMD SVM next_rip save */ +/* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */ +#define X86_FEATURE_FSGSBASE (9*32+0)/* {RD/WR}{FS/GS}BASE instructions*/ +#if defined(__KERNEL__) && !defined(__ASSEMBLY__)#include <asm/asm.h>
@@ -197,7 +200,9 @@ extern const char * const x86_power_flags[32]; (((bit)>>5 )==4 && (1UL <<((bit)&31 ) &REQUIRED_MASK4 )) || \ (((bit)>>5 )==5 && (1UL <<((bit)&31 ) &REQUIRED_MASK5 )) || \ (((bit)>>5 )==6 && (1UL <<((bit)&31 ) &REQUIRED_MASK6 )) || \ - (((bit)>>5)==7 && (1UL<<((bit)&31) & REQUIRED_MASK7)) ) \ + (((bit)>>5 )==7 && (1UL <<((bit)&31 ) &REQUIRED_MASK7 )) || \ + (((bit)>>5 )==8 && (1UL <<((bit)&31 ) &REQUIRED_MASK8 )) || \ + (((bit)>>5)==9 && (1UL<<((bit)&31) & REQUIRED_MASK9)) ) \ ?1 : \ test_cpu_cap(c, bit))
arch/x86/include/asm/required-features.h +2 -0
@@ -84,5 +84,7 @@#define REQUIRED_MASK5 0#define REQUIRED_MASK6 0#define REQUIRED_MASK7 0 +#define REQUIRED_MASK8 0 +#define REQUIRED_MASK9 0#endif /* _ASM_X86_REQUIRED_FEATURES_H */
arch/x86/kernel/cpu/common.c +10 -0
@@ -551,6 +551,16 @@ static void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c) c->x86_capability[4 ] = excap; } +/* Additional Intel-defined flags: level 0x00000007 */ +if (c->cpuid_level >=0x00000007 ) { +u32 eax, ebx, ecx, edx; + +cpuid_count (0x00000007 ,0 , &eax, &ebx, &ecx, &edx); + +if (eax >0 ) + c->x86_capability[9 ] = ebx; + } +/* AMD-defined flags: level 0x80000001 */ xlvl =cpuid_eax (0x80000000 ); c->extended_cpuid_level = xlvl;
Hi,
arch/x86/vdso/checkundef.sh line 4
Quoted 11 lines · On Fri, 18 Jun 2010 22:16:05 GMT "tip-bot for H. Peter Anvin"…
arch/x86/vdso/checkundef.sh new file +4
-0@@ -0,0 +1,10 @@ +#!/bin/sh +nm="$1" +file="$2" +"$nm" "$file" | grep '^ *U' > /dev/null 2>&1
Quoting $nm here doesn't work if you are building with ccache like this:
make CROSS_COMPILE="ccache ...."
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 16 lines · Stephen Rothwell
Hi,
arch/x86/vdso/checkundef.sh line 4
Quoted 10 lines · On Fri, 18 Jun 2010 22:16:05 GMT "tip-bot for H. Peter Anvin"…
arch/x86/vdso/checkundef.sh new file +4
-0@@ -0,0 +1,10 @@ +#!/bin/sh +nm="$1" +file="$2" +"$nm" "$file" | grep '^ *U' > /dev/null 2>&1Quoting $nm here doesn't work if you are building with ccache like this:
Quoted 1 line
make CROSS_COMPILE="ccache ...."
Hmmm... in some ways I'm not sure if that's a feature or a bug, but I guess it's the only way currently provided. Sigh.
-hpa
tip-bot for H. Peter Anvin
reviewer[tip:x86/asm] x86, asm: Clean up and simplify set_64bit()
In reply to a message not in the archiveCommit-ID: 69309a05907546fb686b251d4ab041c26afe1e1d Gitweb: http://git.kernel.org/tip/69309a05907546fb686b251d4ab041c26afe1e1d Author: H. Peter Anvin <[email protected]> AuthorDate: Tue, 27 Jul 2010 23:29:52 -0700 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 27 Jul 2010 23:29:52 -0700
x86, asm: Clean up and simplify set_64bit()
Clean up and simplify set_64bit(). This code is quite old (1.3.11) and contains a fair bit of auxilliary machinery that current versions of gcc handle just fine automatically. Worse, the auxilliary machinery can actually cause an unnecessary spill to memory.
Furthermore, the loading of the old value inside the loop in the 32-bit case is unnecessary: if the value doesn't match, the CMPXCHG8B instruction will already have loaded the "new previous" value for us.
Clean up the comment, too, and remove page references to obsolete versions of the Intel SDM.
LKML-Reference: <tip-*@vger.kernel.org>
--- arch/x86/include/asm/cmpxchg_32.h | 67 +++++++++++-------------------------- arch/x86/include/asm/cmpxchg_64.h | 4 +-- 2 files changed, 21 insertions(+), 50 deletions(-)
arch/x86/include/asm/cmpxchg_32.h +20 -47
@@ -53,60 +53,33 @@ struct __xchg_dummy {__xchg ((v), (ptr),sizeof (*ptr))/* -* The semantics of XCHGCMP8B are a bit strange, this is why -* there is a loop and the loading of %%eax and %%edx has to -* be inside. This inlines well in most cases, the cached -* cost is around ~38 cycles. (in the future we might want -* to do an SIMD/3DNOW!/MMX/FPU 64-bit store here, but that -* might have an implicit FPU-save as a cost, so it's not -* clear which path to go.) +* CMPXCHG8B only writes to the target if we had the previous +* value in registers, otherwise it acts as a read and gives us the +* "new previous" value. That is why there is a loop. Preloading +* EDX:EAX is a performance optimization: in the common case it means +* we need only one locked operation. * -* cmpxchg8b must be used with the lock prefix here to allow -* the instruction to be executed atomically, see page 3-102 -* of the instruction set reference 24319102.pdf. We need -* the reader side to see the coherent 64bit value. +* A SIMD/3DNOW!/MMX/FPU 64-bit store here would require at the very +* least an FPU save and/or %cr0.ts manipulation. +* +* cmpxchg8b must be used with the lock prefix here to allow the +* instruction to be executed atomically. We need to have the reader +* side to see the coherent 64bit value. */ -static inline void __set_64bit (unsigned long long *ptr, -unsigned int low,unsigned int high) +static inline void set_64bit (volatile u64 *ptr,u64 value) { +u32 low = value; +u32 high = value >>32 ; +u64 prev = *ptr; + asmvolatile ("\n1:\t" -"movl (%1), %%eax\n\t" -"movl 4(%1), %%edx\n\t" -LOCK_PREFIX "cmpxchg8b (%1)\n\t" +LOCK_PREFIX "cmpxchg8b %0\n\t" "jnz 1b" - :"=m" (*ptr) - :"D" (ptr), -"b" (low), -"c" (high) - :"ax" ,"dx" ,"memory" ); -} - -static inline void __set_64bit_constant (unsigned long long *ptr, -unsigned long long value) -{ -__set_64bit (ptr, (unsigned int )value, (unsigned int )(value >>32 )); -} - -#define ll_low (x) *(((unsigned int *)&(x)) + 0) -#define ll_high (x) *(((unsigned int *)&(x)) + 1) - -static inline void __set_64bit_var (unsigned long long *ptr, -unsigned long long value) -{ -__set_64bit (ptr,ll_low (value),ll_high (value)); + :"=m" (*ptr),"+A" (prev) + :"b" (low),"c" (high) + :"memory" ); } -#define set_64bit (ptr, value) \ - (__builtin_constant_p((value)) \ - ? __set_64bit_constant((ptr), (value)) \ - : __set_64bit_var((ptr), (value))) - -#define _set_64bit (ptr, value) \ - (__builtin_constant_p(value) \ - ? __set_64bit(ptr, (unsigned int)(value), \ - (unsigned int)((value) >> 32)) \ - : __set_64bit(ptr, ll_low((value)), ll_high((value)))) -extern void __cmpxchg_wrong_size (void );/*
arch/x86/include/asm/cmpxchg_64.h +1 -3
@@ -5,13 +5,11 @@#define __xg (x) ((volatile long *)(x)) -static inline void set_64bit (volatile unsigned long *ptr,unsigned long val) +static inline void set_64bit (volatile u64 *ptr,u64 val) { *ptr = val; } -#define _set_64bit set_64bit -extern void __xchg_wrong_size (void );extern void __cmpxchg_wrong_size (void );
tip-bot for H. Peter Anvin
reviewer[tip:x86/build] x86, vdso: Don't quote $nm in the script for checking vdso references
In reply to Stephen RothwellCommit-ID: 18642a57df02a044b91219d3176128996ddc81a5 Gitweb: http://git.kernel.org/tip/18642a57df02a044b91219d3176128996ddc81a5 Author: H. Peter Anvin <[email protected]> AuthorDate: Tue, 27 Jul 2010 23:52:29 -0700 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 27 Jul 2010 23:52:29 -0700
x86, vdso: Don't quote $nm in the script for checking vdso references
Don't quote $nm in the script for checking the vdso for external references. Doing so breaks multiword constructs, like using CROSS_COMPILE='ccache '.
LKML-Reference: <[email protected]>
--- arch/x86/vdso/checkundef.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/vdso/checkundef.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/sh nm="$1" file="$2" -"$nm" "$file" | grep '^ *U' > /dev/null 2>&1 +$nm "$file" | grep '^ *U' > /dev/null 2>&1 if [ $? -eq 1 ]; then exit 0 else
tip-bot for H. Peter Anvin
reviewer[tip:x86/asm] um, x86: Cast to (u64 *) inside set_64bit()
In reply to tip-bot for H. Peter AnvinCommit-ID: bf676945cb5bfe455321f57968967c18976f4995 Gitweb: http://git.kernel.org/tip/bf676945cb5bfe455321f57968967c18976f4995 Author: H. Peter Anvin <[email protected]> AuthorDate: Tue, 3 Aug 2010 07:00:16 -0700 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 3 Aug 2010 07:00:16 -0700
um, x86: Cast to (u64 *) inside set_64bit()
After tightening up the types passed to set_64bit(), the cast to (phys_t *) triggers a warning apparently because phys_t is defined as "unsigned long" when building on 64 bits; however, u64 is defined as "unsigned long long". This is, however, a explicit cast inside a size-specific call, so just make the cast explicitly (u64 *).
LKML-Reference: <[email protected]>
--- arch/um/include/asm/pgtable-3level.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/um/include/asm/pgtable-3level.h +2 -2
@@ -60,7 +60,7 @@ set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))#ifdef CONFIG_64BIT -#define set_pud (pudptr, pudval) set_64bit((phys_t *) (pudptr), pud_val(pudval)) +#define set_pud (pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))#else #define set_pud (pudptr, pudval) (*(pudptr) = (pudval))#endif
@@ -73,7 +73,7 @@ static inline int pgd_newpage(pgd_t pgd)static inline void pgd_mkuptodate (pgd_t pgd) {pgd_val (pgd) &= ~_PAGE_NEWPAGE; }#ifdef CONFIG_64BIT -#define set_pmd (pmdptr, pmdval) set_64bit((phys_t *) (pmdptr), pmd_val(pmdval)) +#define set_pmd (pmdptr, pmdval) set_64bit((u64 *) (pmdptr), pmd_val(pmdval))#else #define set_pmd (pmdptr, pmdval) (*(pmdptr) = (pmdval))#endif