Skip to contentSkip to conversation

x86/rwsem changes for v2.6.34

GIT PULL Ingo Molnar 1 participant 1 message Feb 27, 2010

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest x86-rwsem-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git x86-rwsem-for-linus

out-of-topic modifications in x86-rwsem-for-linus:
--------------------------------------------------
arch/um/sys-x86_64/Makefile # 4126faf: x86: Fix breakage of UML from the
lib/hweight.c # 39d997b: x86, core: Optimize hweight32()

Thanks,

Ingo

------------------>
Akinobu Mita (1):

      x86, core: Optimize hweight32()

Avi Kivity (1):
x86-64, rwsem: Avoid store forwarding hazard in __downgrade_write

Brian Gerst (4):

      x86: Split atomic64_t functions into seperate headers
      x86: Sync asm/atomic_32.h and asm/atomic_64.h
      x86: Merge asm/atomic_{32,64}.h
      x86: Merge show_regs()

Dave Jones (1):
x86: Macroise x86 cache descriptors

H. Peter Anvin (1):
x86-64, rwsem: 64-bit xadd rwsem implementation

Jan Beulich (3):
x86: Lift restriction on the location of FIX_BTMAP_*
x86-64: Modify copy_user_generic() alternatives mechanism
x86-64: Modify memcpy()/memset() alternatives mechanism

Linus Torvalds (4):
x86-32: clean up rwsem inline asm statements
x86: clean up rwsem type system
x86-64: support native xadd rwsem implementation
x86: Fix breakage of UML from the changes in the rwsem system

 arch/um/sys-x86_64/Makefile           |    3 +-
 arch/x86/Kconfig.cpu                  |    2 +-
 arch/x86/include/asm/alternative.h    |    7 +-
 arch/x86/include/asm/atomic.h         |  299 ++++++++++++++++++++-
 arch/x86/include/asm/atomic64_32.h    |  160 +++++++++++
 arch/x86/include/asm/atomic64_64.h    |  224 +++++++++++++++
 arch/x86/include/asm/atomic_32.h      |  415 ----------------------------
 arch/x86/include/asm/atomic_64.h      |  485 ---------------------------------
 arch/x86/include/asm/fixmap.h         |   16 +-
 arch/x86/include/asm/rwsem.h          |   81 ++++---
 arch/x86/include/asm/uaccess_64.h     |   21 ++-
 arch/x86/kernel/alternative.c         |    4 +-
 arch/x86/kernel/cpu/intel_cacheinfo.c |   84 +++---
 arch/x86/kernel/process.c             |    7 +
 arch/x86/kernel/process_32.c          |    6 -
 arch/x86/kernel/process_64.c          |    6 -
 arch/x86/kernel/x8664_ksyms_64.c      |    3 +-
 arch/x86/lib/Makefile                 |    1 +
 arch/x86/lib/copy_user_64.S           |    6 -
 arch/x86/lib/memcpy_64.S              |   23 +-
 arch/x86/lib/memset_64.S              |   18 +-
 arch/x86/lib/rwsem_64.S               |   81 ++++++
 arch/x86/mm/ioremap.c                 |    4 +
 lib/hweight.c                         |    7 +
 24 files changed, 932 insertions(+), 1031 deletions(-)
 create mode 100644 arch/x86/include/asm/atomic64_32.h
 create mode 100644 arch/x86/include/asm/atomic64_64.h
 delete mode 100644 arch/x86/include/asm/atomic_32.h
 delete mode 100644 arch/x86/include/asm/atomic_64.h
 create mode 100644 arch/x86/lib/rwsem_64.S
arch/um/sys-x86_64/Makefile +2 -1
index 2201e9c..c1ea9eb 100644
@@ -8,7 +8,8 @@ obj-y = bug.o bugs.o delay.o fault.o ldt.o mem.o ptrace.o ptrace_user.o \
 	setjmp.o signal.o stub.o stub_segv.o syscalls.o syscall_table.o \
 	sysrq.o ksyms.o tls.o
 
-subarch-obj-y = lib/csum-partial_64.o lib/memcpy_64.o lib/thunk_64.o
+subarch-obj-y = lib/csum-partial_64.o lib/memcpy_64.o lib/thunk_64.o \
+		lib/rwsem_64.o
 subarch-obj-$(CONFIG_MODULES) += kernel/module.o
 
 ldt-y = ../sys-i386/ldt.o
arch/x86/Kconfig.cpu +1 -1
index 08e442b..9d38a13 100644
@@ -319,7 +319,7 @@ config X86_L1_CACHE_SHIFT
 
 config X86_XADD
 	def_bool y
-	depends on X86_32 && !M386
+	depends on X86_64 || !M386
 
 config X86_PPRO_FENCE
 	bool "PentiumPro memory ordering errata workaround"
arch/x86/include/asm/alternative.h +6 -1
index 69b74a7..3b5b828 100644
@@ -125,11 +125,16 @@ static inline void alternatives_smp_switch(int smp) {}
 	asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)		\
 		: output : "i" (0), ## input)
 
+/* Like alternative_io, but for replacing a direct call with another one. */
+#define alternative_call(oldfunc, newfunc, feature, output, input...)	\
+	asm volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
+		: output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
+
 /*
  * use this macro(s) if you need more than one output parameter
  * in alternative_io
  */
-#define ASM_OUTPUT2(a, b) a, b
+#define ASM_OUTPUT2(a...) a
 
 struct paravirt_patch_site;
 #ifdef CONFIG_PARAVIRT
arch/x86/include/asm/atomic.h +297 -2

302 lines not on this page · raw message

arch/x86/include/asm/atomic64_32.h new file +160 -0

160 lines not on this page · raw message

arch/x86/include/asm/atomic64_64.h new file +224 -0

224 lines not on this page · raw message

arch/x86/include/asm/atomic_32.h deleted +0 -415

415 lines not on this page · raw message

arch/x86/include/asm/atomic_64.h deleted +0 -485

485 lines not on this page · raw message

arch/x86/include/asm/fixmap.h +11 -5
index 14f9890..635f03b 100644
@@ -118,14 +118,20 @@ enum fixed_addresses {
 	 * 256 temporary boot-time mappings, used by early_ioremap(),
 	 * before ioremap() is functional.
 	 *
-	 * We round it up to the next 256 pages boundary so that we
-	 * can have a single pgd entry and a single pte table:
+	 * If necessary we round it up to the next 256 pages boundary so
+	 * that we can have a single pgd entry and a single pte table:
 	 */
 #define NR_FIX_BTMAPS		64
 #define FIX_BTMAPS_SLOTS	4
-	FIX_BTMAP_END = __end_of_permanent_fixed_addresses + 256 -
-			(__end_of_permanent_fixed_addresses & 255),
-	FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_SLOTS - 1,
+#define TOTAL_FIX_BTMAPS	(NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
+	FIX_BTMAP_END =
+	 (__end_of_permanent_fixed_addresses ^
+	  (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
+	 -PTRS_PER_PTE
+	 ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
+	   (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
+	 : __end_of_permanent_fixed_addresses,
+	FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
 	FIX_OHCI1394_BASE,
 #endif
arch/x86/include/asm/rwsem.h +49 -32

175 lines not on this page · raw message

arch/x86/include/asm/uaccess_64.h +20 -1
index 46324c6..a78c403 100644
@@ -8,6 +8,8 @@
 #include <linux/errno.h>
 #include <linux/prefetch.h>
 #include <linux/lockdep.h>
+#include <asm/alternative.h>
+#include <asm/cpufeature.h>
 #include <asm/page.h>
 
 /*
@@ -16,7 +18,24 @@
 
 /* Handles exceptions in both to and from, but doesn't do access_ok */
 __must_check unsigned long
-copy_user_generic(void *to, const void *from, unsigned len);
+copy_user_generic_string(void *to, const void *from, unsigned len);
+__must_check unsigned long
+copy_user_generic_unrolled(void *to, const void *from, unsigned len);
+
+static __always_inline __must_check unsigned long
+copy_user_generic(void *to, const void *from, unsigned len)
+{
+	unsigned ret;
+
+	alternative_call(copy_user_generic_unrolled,
+			 copy_user_generic_string,
+			 X86_FEATURE_REP_GOOD,
+			 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
+				     "=d" (len)),
+			 "1" (to), "2" (from), "3" (len)
+			 : "memory", "rcx", "r8", "r9", "r10", "r11");
+	return ret;
+}
 
 __must_check unsigned long
 _copy_to_user(void __user *to, const void *from, unsigned len);
arch/x86/kernel/alternative.c +3 -1
index de7353c..2589ea4 100644
@@ -205,7 +205,7 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
 					 struct alt_instr *end)
 {
 	struct alt_instr *a;
-	char insnbuf[MAX_PATCH_LEN];
+	u8 insnbuf[MAX_PATCH_LEN];
 
 	DPRINTK("%s: alt table %p -> %p\n", __func__, start, end);
 	for (a = start; a < end; a++) {
@@ -223,6 +223,8 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
 		}
 #endif
 		memcpy(insnbuf, a->replacement, a->replacementlen);
+		if (*insnbuf == 0xe8 && a->replacementlen == 5)
+		    *(s32 *)(insnbuf + 1) += a->replacement - a->instr;
 		add_nops(insnbuf + a->replacementlen,
 			 a->instrlen - a->replacementlen);
 		text_poke_early(instr, insnbuf, a->instrlen);
arch/x86/kernel/cpu/intel_cacheinfo.c +43 -41

108 lines not on this page · raw message

arch/x86/kernel/process.c +7 -0
index 98c2cde..cf1e04b 100644
@@ -92,6 +92,13 @@ void exit_thread(void)
 	}
 }
 
+void show_regs(struct pt_regs *regs)
+{
+	show_registers(regs);
+	show_trace(NULL, regs, (unsigned long *)kernel_stack_pointer(regs),
+		   regs->bp);
+}
+
 void show_regs_common(void)
 {
 	const char *board, *product;
arch/x86/kernel/process_32.c +0 -6
index 9c517b5..fe6a34e 100644
@@ -174,12 +174,6 @@ void __show_regs(struct pt_regs *regs, int all)
 			d6, d7);
 }
 
-void show_regs(struct pt_regs *regs)
-{
-	show_registers(regs);
-	show_trace(NULL, regs, &regs->sp, regs->bp);
-}
-
 void release_thread(struct task_struct *dead_task)
 {
 	BUG_ON(dead_task->mm);
arch/x86/kernel/process_64.c +0 -6
index 52fbd0c..418f860 100644
@@ -211,12 +211,6 @@ void __show_regs(struct pt_regs *regs, int all)
 	printk(KERN_INFO "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
 }
 
-void show_regs(struct pt_regs *regs)
-{
-	show_registers(regs);
-	show_trace(NULL, regs, (void *)(regs + 1), regs->bp);
-}
-
 void release_thread(struct task_struct *dead_task)
 {
 	if (dead_task->mm) {
arch/x86/kernel/x8664_ksyms_64.c +2 -1
index 619f7f8..693920b 100644
@@ -26,7 +26,8 @@ EXPORT_SYMBOL(__put_user_2);
 EXPORT_SYMBOL(__put_user_4);
 EXPORT_SYMBOL(__put_user_8);
 
-EXPORT_SYMBOL(copy_user_generic);
+EXPORT_SYMBOL(copy_user_generic_string);
+EXPORT_SYMBOL(copy_user_generic_unrolled);
 EXPORT_SYMBOL(__copy_user_nocache);
 EXPORT_SYMBOL(_copy_from_user);
 EXPORT_SYMBOL(_copy_to_user);
arch/x86/lib/Makefile +1 -0
index cffd754..c802451 100644
@@ -39,4 +39,5 @@ else
         lib-y += thunk_64.o clear_page_64.o copy_page_64.o
         lib-y += memmove_64.o memset_64.o
         lib-y += copy_user_64.o rwlock_64.o copy_user_nocache_64.o
+	lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem_64.o
 endif
arch/x86/lib/copy_user_64.S +0 -6
index cf889d4..71100c9 100644
@@ -90,12 +90,6 @@ ENTRY(_copy_from_user)
 	CFI_ENDPROC
 ENDPROC(_copy_from_user)
 
-ENTRY(copy_user_generic)
-	CFI_STARTPROC
-	ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
-	CFI_ENDPROC
-ENDPROC(copy_user_generic)
-
 	.section .fixup,"ax"
 	/* must zero dest */
 ENTRY(bad_from_user)
arch/x86/lib/memcpy_64.S +8 -15
index ad5441e..f82e884 100644
@@ -20,12 +20,11 @@
 /*
  * memcpy_c() - fast string ops (REP MOVSQ) based variant.
  *
- * Calls to this get patched into the kernel image via the
+ * This gets patched over the unrolled variant (below) via the
  * alternative instructions framework:
  */
-	ALIGN
-memcpy_c:
-	CFI_STARTPROC
+	.section .altinstr_replacement, "ax", @progbits
+.Lmemcpy_c:
 	movq %rdi, %rax
 
 	movl %edx, %ecx
@@ -35,8 +34,8 @@ memcpy_c:
 	movl %edx, %ecx
 	rep movsb
 	ret
-	CFI_ENDPROC
-ENDPROC(memcpy_c)
+.Lmemcpy_e:
+	.previous
 
 ENTRY(__memcpy)
 ENTRY(memcpy)
@@ -128,16 +127,10 @@ ENDPROC(__memcpy)
 	 * It is also a lot simpler. Use this when possible:
 	 */
 
-	.section .altinstr_replacement, "ax"
-1:	.byte 0xeb				/* jmp <disp8> */
-	.byte (memcpy_c - memcpy) - (2f - 1b)	/* offset */
-2:
-	.previous
-
 	.section .altinstructions, "a"
 	.align 8
 	.quad memcpy
-	.quad 1b
+	.quad .Lmemcpy_c
 	.byte X86_FEATURE_REP_GOOD
 
 	/*
@@ -145,6 +138,6 @@ ENDPROC(__memcpy)
 	 * so it is silly to overwrite itself with nops - reboot is the
 	 * only outcome...
 	 */
-	.byte 2b - 1b
-	.byte 2b - 1b
+	.byte .Lmemcpy_e - .Lmemcpy_c
+	.byte .Lmemcpy_e - .Lmemcpy_c
 	.previous
arch/x86/lib/memset_64.S +6 -12
index 2c59481..e88d3b8 100644
@@ -12,9 +12,8 @@
  * 
  * rax   original destination
  */	
-	ALIGN
-memset_c:
-	CFI_STARTPROC
+	.section .altinstr_replacement, "ax", @progbits
+.Lmemset_c:
 	movq %rdi,%r9
 	movl %edx,%r8d
 	andl $7,%r8d
@@ -29,8 +28,8 @@ memset_c:
 	rep stosb
 	movq %r9,%rax
 	ret
-	CFI_ENDPROC
-ENDPROC(memset_c)
+.Lmemset_e:
+	.previous
 
 ENTRY(memset)
 ENTRY(__memset)
@@ -118,16 +117,11 @@ ENDPROC(__memset)
 
 #include <asm/cpufeature.h>
 
-	.section .altinstr_replacement,"ax"
-1:	.byte 0xeb				/* jmp <disp8> */
-	.byte (memset_c - memset) - (2f - 1b)	/* offset */
-2:
-	.previous
 	.section .altinstructions,"a"
 	.align 8
 	.quad memset
-	.quad 1b
+	.quad .Lmemset_c
 	.byte X86_FEATURE_REP_GOOD
 	.byte .Lfinal - memset
-	.byte 2b - 1b
+	.byte .Lmemset_e - .Lmemset_c
 	.previous
arch/x86/lib/rwsem_64.S new file +81 -0

81 lines not on this page · raw message

arch/x86/mm/ioremap.c +4 -0
index c246d25..03c75ff 100644
@@ -422,6 +422,10 @@ void __init early_ioremap_init(void)
 	 * The boot-ioremap range spans multiple pmds, for which
 	 * we are not prepared:
 	 */
+#define __FIXADDR_TOP (-PAGE_SIZE)
+	BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
+		     != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
+#undef __FIXADDR_TOP
 	if (pmd != early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END))) {
 		WARN_ON(1);
 		printk(KERN_WARNING "pmd %p != %p\n",
lib/hweight.c +7 -0
index 389424e..63ee4eb 100644
@@ -11,11 +11,18 @@
 
 unsigned int hweight32(unsigned int w)
 {
+#ifdef ARCH_HAS_FAST_MULTIPLIER
+	w -= (w >> 1) & 0x55555555;
+	w =  (w & 0x33333333) + ((w >> 2) & 0x33333333);
+	w =  (w + (w >> 4)) & 0x0f0f0f0f;
+	return (w * 0x01010101) >> 24;
+#else
 	unsigned int res = w - ((w >> 1) & 0x55555555);
 	res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
 	res = (res + (res >> 4)) & 0x0F0F0F0F;
 	res = res + (res >> 8);
 	return (res + (res >> 16)) & 0x000000FF;
+#endif
 }
 EXPORT_SYMBOL(hweight32);