x86/ldt: Make modify_ldt synchronous
[pandora-kernel.git] / arch / x86 / kernel / cpu / perf_event.c
index 5801a14..9469dfa 100644 (file)
@@ -357,34 +357,24 @@ void x86_release_hardware(void)
  */
 int x86_add_exclusive(unsigned int what)
 {
-       int ret = -EBUSY, i;
-
-       if (atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what]))
-               return 0;
+       int i;
 
-       mutex_lock(&pmc_reserve_mutex);
-       for (i = 0; i < ARRAY_SIZE(x86_pmu.lbr_exclusive); i++) {
-               if (i != what && atomic_read(&x86_pmu.lbr_exclusive[i]))
-                       goto out;
+       if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) {
+               mutex_lock(&pmc_reserve_mutex);
+               for (i = 0; i < ARRAY_SIZE(x86_pmu.lbr_exclusive); i++) {
+                       if (i != what && atomic_read(&x86_pmu.lbr_exclusive[i]))
+                               goto fail_unlock;
+               }
+               atomic_inc(&x86_pmu.lbr_exclusive[what]);
+               mutex_unlock(&pmc_reserve_mutex);
        }
 
-       atomic_inc(&x86_pmu.lbr_exclusive[what]);
-       ret = 0;
+       atomic_inc(&active_events);
+       return 0;
 
-out:
+fail_unlock:
        mutex_unlock(&pmc_reserve_mutex);
-
-       /*
-        * Assuming that all exclusive events will share the PMI handler
-        * (which checks active_events for whether there is work to do),
-        * we can bump active_events counter right here, except for
-        * x86_lbr_exclusive_lbr events that go through x86_pmu_event_init()
-        * path, which already bumps active_events for them.
-        */
-       if (!ret && what != x86_lbr_exclusive_lbr)
-               atomic_inc(&active_events);
-
-       return ret;
+       return -EBUSY;
 }
 
 void x86_del_exclusive(unsigned int what)
@@ -2189,21 +2179,25 @@ static unsigned long get_segment_base(unsigned int segment)
        int idx = segment >> 3;
 
        if ((segment & SEGMENT_TI_MASK) == SEGMENT_LDT) {
+               struct ldt_struct *ldt;
+
                if (idx > LDT_ENTRIES)
                        return 0;
 
-               if (idx > current->active_mm->context.size)
+               /* IRQs are off, so this synchronizes with smp_store_release */
+               ldt = lockless_dereference(current->active_mm->context.ldt);
+               if (!ldt || idx > ldt->size)
                        return 0;
 
-               desc = current->active_mm->context.ldt;
+               desc = &ldt->entries[idx];
        } else {
                if (idx > GDT_ENTRIES)
                        return 0;
 
-               desc = raw_cpu_ptr(gdt_page.gdt);
+               desc = raw_cpu_ptr(gdt_page.gdt) + idx;
        }
 
-       return get_desc_base(desc + idx);
+       return get_desc_base(desc);
 }
 
 #ifdef CONFIG_COMPAT