Xen bugfixes
Subsystems (4)
Hi,
Here's 3 patches which fix two Xen PV spinlock bugs, and makes CONFIG_CC_STACKPROTECTOR work on both 32- and 64-bit.
The spinlock bugs are both rare races:
- lock can briefly hold the lock while interrupts are enabled, allowing an ISR to deadlock
- unlock doesn't enforce CPU memory ordering between the actual unlock write and the check to see if there are any pending waiters, so it can end up deciding there's nobody to kick on unlock, leaving another CPU hanging. It needs a full mb() to guarantee the correct ordering.
The stack-protector fix bites the bullet and does a full GDT setup early so that we can load %gs for the stack-protector canary segment on i386. This also removes the assumption that the initial percpu %fs segment has a zero base.
x86-64 still just needs the GS_BASE MSR written, but that now happens using the same code as i386 rather than being special cased.
Thanks,
J
The following changes since commit e07cccf4046978df10f2e13fe2b99b2f9b3a65db:
Linus Torvalds (1):
Linux 2.6.31-rc9
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git bugfix
Jeremy Fitzhardinge (2):
xen: make -fstack-protector work under Xen
xen: only enable interrupts while actually blocking for spinlock
Yang Xiaowei (1):
xen: use stronger barrier after unlocking lock
arch/x86/mm/Makefile | 4 ++ arch/x86/xen/Makefile | 2 + arch/x86/xen/enlighten.c | 131 +++++++++++++++++++++++++++++++++++++++------- arch/x86/xen/smp.c | 1 + arch/x86/xen/spinlock.c | 28 ++++++---- drivers/xen/Makefile | 3 + 6 files changed, 140 insertions(+), 29 deletions(-)
arch/x86/mm/Makefile +4 -0
@@ -1,6 +1,10 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ pat.o pgtable.o gup.o +# Make sure __phys_addr has no stackprotector +nostackp := $(call cc-option, -fno-stack-protector) +CFLAGS_ioremap.o := $(nostackp) + obj-$(CONFIG_SMP) += tlb.o obj-$(CONFIG_X86_32) += pgtable_32.o iomap_32.o
arch/x86/xen/Makefile +2 -0
@@ -8,6 +8,7 @@ endif # Make sure early boot has no stackprotector nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_enlighten.o := $(nostackp) +CFLAGS_mmu.o := $(nostackp) obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ time.o xen-asm.o xen-asm_$(BITS).o \
@@ -16,3 +17,4 @@ obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o +
arch/x86/xen/enlighten.c +112 -19
192 lines not on this page · raw message
arch/x86/xen/smp.c +1 -0
@@ -236,6 +236,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle) ctxt->user_regs.ss = __KERNEL_DS;#ifdef CONFIG_X86_32 ctxt->user_regs.fs = __KERNEL_PERCPU; + ctxt->user_regs.gs = __KERNEL_STACK_CANARY;#else ctxt->gs_base_kernel =per_cpu_offset (cpu);#endif
arch/x86/xen/spinlock.c +18 -10
@@ -187,7 +187,6 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enablstruct xen_spinlock *prev;int irq =__get_cpu_var (lock_kicker_irq);int ret; -unsigned long flags;u64 start;/* If kicker interrupts not initialized yet, just spin */
@@ -199,16 +198,12 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl/* announce we're spinning */ prev =spinning_lock (xl); - flags =__raw_local_save_flags (); -if (irq_enable) { -ADD_STATS (taken_slow_irqenable,1 ); -raw_local_irq_enable (); - } -ADD_STATS (taken_slow,1 );ADD_STATS (taken_slow_nested, prev !=NULL ); do { + unsigned long flags; + /* clear pending */ xen_clear_irq_pending(irq);
@@ -228,6 +223,12 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl goto out; } + flags =__raw_local_save_flags (); +if (irq_enable) { +ADD_STATS (taken_slow_irqenable,1 ); +raw_local_irq_enable (); + } +/* * Block until irq becomes pending. If we're * interrupted at this point (after the trylock but
@@ -238,13 +239,15 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl* pending. */ xen_poll_irq (irq); + +raw_local_irq_restore (flags); +ADD_STATS (taken_slow_spurious, !xen_test_irq_pending (irq)); }while (!xen_test_irq_pending (irq));/* check for spurious wakeups */ kstat_incr_irqs_this_cpu (irq,irq_to_desc (irq)); out: -raw_local_irq_restore (flags);unspinning_lock (xl, prev);spin_time_accum_blocked (start);
@@ -323,8 +326,13 @@ static void xen_spin_unlock(struct raw_spinlock *lock)smp_wmb ();/* make sure no writes get moved after unlock */ xl->lock =0 ;/* release lock */ -/* make sure unlock happens before kick */ -barrier (); +/* +* Make sure unlock happens before checking for waiting +* spinners. We need a strong barrier to enforce the +* write-read ordering to different memory locations, as the +* CPU makes no implied guarantees about their ordering. +*/ +mb ();if (unlikely (xl->spinners))xen_spin_unlock_slow (xl);
drivers/xen/Makefile +3 -0
@@ -1,6 +1,9 @@ obj-y += grant-table.o features.o events.o manage.o obj-y += xenbus/ +nostackp := $(call cc-option, -fno-stack-protector) +CFLAGS_features.o := $(nostackp) + obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o obj-$(CONFIG_XEN_XENCOMM) += xencomm.o obj-$(CONFIG_XEN_BALLOON) += balloon.o
Quoted 39 lines · Jeremy Fitzhardinge
Hi,
Here's 3 patches which fix two Xen PV spinlock bugs, and makes
CONFIG_CC_STACKPROTECTORwork on both 32- and 64-bit.The spinlock bugs are both rare races:
- lock can briefly hold the lock while interrupts are enabled, allowing an ISR to deadlock
- unlock doesn't enforce CPU memory ordering between the actual unlock write and the check to see if there are any pending waiters, so it can end up deciding there's nobody to kick on unlock, leaving another CPU hanging. It needs a fullmb()to guarantee the correct ordering.The stack-protector fix bites the bullet and does a full GDT setup early so that we can load %gs for the stack-protector canary segment on i386. This also removes the assumption that the initial percpu %fs segment has a zero base.
x86-64 still just needs the
GS_BASEMSR written, but that now happens using the same code as i386 rather than being special cased.Thanks,
JThe following changes since commit
e07cccf4046978df10f2e13fe2b99b2f9b3a65db:
Linus Torvalds (1):Linux 2.6.31-rc9are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.gitbugfixJeremy Fitzhardinge (2):
xen: make -fstack-protector work under Xen
xen: only enable interrupts while actually blocking for spinlockYang Xiaowei (1):
xen: use stronger barrier after unlocking lock
Quoted 7 lines
arch/x86/mm/Makefile | 4 ++ arch/x86/xen/Makefile | 2 + arch/x86/xen/enlighten.c | 131 +++++++++++++++++++++++++++++++++++++++------- arch/x86/xen/smp.c | 1 + arch/x86/xen/spinlock.c | 28 ++++++---- drivers/xen/Makefile | 3 + 6 files changed, 140 insertions(+), 29 deletions(-)
Pulled, thanks a lot Jeremy!
A few comments:
arch/x86/mm/Makefile line 7
Quoted 4 lines
arch/x86/mm/Makefile +4
-0+# Make sure __phys_addr has no stackprotector +nostackp := $(call cc-option, -fno-stack-protector) +CFLAGS_ioremap.o := $(nostackp) +
Sure we could move __phys_addr into its own file and thus avoid turning off stackprotector for the rest of ioremap.c?
arch/x86/xen/Makefile endif · line 11
Quoted 7 lines
arch/x86/xen/Makefile +1
-0@@ -8,6 +8,7 @@ endif # Make sure early boot has no stackprotector nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_enlighten.o := $(nostackp) +CFLAGS_mmu.o := $(nostackp)
A similar argument could be made here - what proportion of mmu.c is affected?
Also, once the commits have hit upstream feel free bounce them to [email protected] - they dont have Cc: <[email protected]> tags for automatic back-merging requests. The fixes narrowly missed v2.6.31.
Ingo
Quoted 8 lines · Ingo Molnar
Review
Quoted 5 lines
(quoted diff) +4
-0+# Make sure __phys_addr has no stackprotector +nostackp := $(call cc-option, -fno-stack-protector) +CFLAGS_ioremap.o := $(nostackp) +Sure we could move
__phys_addrinto its own file and thus avoid turning off stackprotector for the rest ofioremap.c?
I'm not very keen on having zillions of tiny files just to cope with the lack of per-function stackprotector disable. I don't see any code in ioremap.c that would really benefit from stack-protector anyway; there are no local arrays.
At least __phys_addr and friends aren't terribly closely related to ioremap so it would at least make some sense. Patch below.
Quoted 11 lines
arch/x86/xen/Makefile endif · line 12
Quoted 8 lines
arch/x86/xen/Makefile +1
-0@@ -8,6 +8,7 @@ endif # Make sure early boot has no stackprotector nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_enlighten.o := $(nostackp) +CFLAGS_mmu.o := $(nostackp)A similar argument could be made here - what proportion of
mmu.cis affected?
More. It would be a fairly arbitrary chunk of code to split out into a separate file.
Quoted 4 lines
Also, once the commits have hit upstream feel free bounce them to [email protected] - they dont have Cc: <[email protected]> tags for automatic back-merging requests. The fixes narrowly missed v2.6.31.
Will do.
Thanks,
J
From: Jeremy Fitzhardinge <[email protected]>
Subject: [PATCH] x86: split __phys_addr out into separate file
Split __phys_addr out into its own file so we can disable -fstack-protector in a fine-grained fashion. Also it doesn't have terribly much to do with the rest of ioremap.c.
arch/x86/mm/Makefile +2 -2
@@ -1,9 +1,9 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ - pat.o pgtable.o gup.o + pat.o pgtable.o physaddr.o gup.o # Make sure __phys_addr has no stackprotector nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_ioremap.o := $(nostackp) +CFLAGS_physaddr.o := $(nostackp) obj-$(CONFIG_SMP) += tlb.o
arch/x86/mm/ioremap.c +1 -71
78 lines not on this page · raw message
arch/x86/mm/physaddr.c new file +70 -0
70 lines not on this page · raw message
arch/x86/mm/physaddr.h new file +10 -0
@@ -0,0 +1,10 @@ +#include <asm/processor.h> + +static inline int phys_addr_valid (resource_size_t addr) +{ +#ifdef CONFIG_PHYS_ADDR_T_64BIT +return !(addr >> boot_cpu_data.x86_phys_bits); +#else +return 1 ; +#endif +}
Quoted 10 lines · Jeremy Fitzhardinge
Quoted 8 lines · Ingo Molnar
Review
Quoted 5 lines
(quoted diff) +4
-0+# Make sure __phys_addr has no stackprotector +nostackp := $(call cc-option, -fno-stack-protector) +CFLAGS_ioremap.o := $(nostackp) +Sure we could move
__phys_addrinto its own file and thus avoid turning off stackprotector for the rest ofioremap.c?
Quoted 7 lines
I'm not very keen on having zillions of tiny files just to cope with the lack of per-function stackprotector disable. I don't see any code in
ioremap.cthat would really benefit from stack-protector anyway; there are no local arrays.At least
__phys_addrand friends aren't terribly closely related to ioremap so it would at least make some sense.
Agreed, i wouldnt do it just for the stackprotector benefit (it's really stupid that GCC does not allow per function exceptions) - but here __phys_addr() looked out of place a bit.
Quoted 1 line
[...] Patch below.
Looks like a nice cleanup. Mind sticking it into your next pull request?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
+CFLAGS_mmu.o := $(nostackp)
A similar argument could be made here - what proportion of
mmu.cis affected?More. It would be a fairly arbitrary chunk of code to split out into a separate file.
Ok - i'd not do it then.
Quoted 7 lines
Quoted 5 lines
Also, once the commits have hit upstream feel free bounce them to [email protected] - they dont have Cc: <[email protected]> tags for automatic back-merging requests. The fixes narrowly missed v2.6.31.
Will do.
Thanks,
Ingo
Quoted 3 lines · Ingo Molnar
Looks like a nice cleanup. Mind sticking it into your next pull request?
The following changes since commit 2496afbf1e50c70f80992656bcb730c8583ddac3:
Yang Xiaowei (1):
xen: use stronger barrier after unlocking lock
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git bugfix
Jeremy Fitzhardinge (1):
x86: split __phys_addr out into separate file
arch/x86/mm/Makefile | 4 +- arch/x86/mm/ioremap.c | 72 +----------------------------------------------- arch/x86/mm/physaddr.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/mm/physaddr.h | 10 ++++++ 4 files changed, 83 insertions(+), 73 deletions(-) create mode 100644 arch/x86/mm/physaddr.c create mode 100644 arch/x86/mm/physaddr.h
J