Merge branch 'drm-patches' of master.kernel.org:/pub/scm/linux/kernel/git/airlied...
[linux-drm-fsl-dcu.git] / arch / um / sys-i386 / ldt.c
index 49057d8bc668b88a5ac4a45a3559171253abfaed..a939a7ef02274eff96f5e3ca46d3e14772b80975 100644 (file)
@@ -7,6 +7,7 @@
 #include "linux/slab.h"
 #include "linux/types.h"
 #include "linux/errno.h"
+#include "linux/spinlock.h"
 #include "asm/uaccess.h"
 #include "asm/smp.h"
 #include "asm/ldt.h"
@@ -166,7 +167,7 @@ static long read_ldt_from_host(void __user * ptr, unsigned long bytecount)
        struct ptrace_ldt ptrace_ldt = (struct ptrace_ldt) {
                        .func = 0,
                        .bytecount = bytecount,
-                       .ptr = (void *)kmalloc(bytecount, GFP_KERNEL)};
+                       .ptr = kmalloc(bytecount, GFP_KERNEL)};
        u32 cpu;
 
        if(ptrace_ldt.ptr == NULL)
@@ -386,23 +387,34 @@ static long do_modify_ldt_skas(int func, void __user *ptr,
        return ret;
 }
 
-short dummy_list[9] = {0, -1};
-short * host_ldt_entries = NULL;
+static DEFINE_SPINLOCK(host_ldt_lock);
+static short dummy_list[9] = {0, -1};
+static short * host_ldt_entries = NULL;
 
-void ldt_get_host_info(void)
+static void ldt_get_host_info(void)
 {
        long ret;
        struct ldt_entry * ldt;
+       short *tmp;
        int i, size, k, order;
 
+       spin_lock(&host_ldt_lock);
+
+       if(host_ldt_entries != NULL){
+               spin_unlock(&host_ldt_lock);
+               return;
+       }
        host_ldt_entries = dummy_list+1;
 
+       spin_unlock(&host_ldt_lock);
+
        for(i = LDT_PAGES_MAX-1, order=0; i; i>>=1, order++);
 
        ldt = (struct ldt_entry *)
              __get_free_pages(GFP_KERNEL|__GFP_ZERO, order);
        if(ldt == NULL) {
-               printk("ldt_get_host_info: couldn't allocate buffer for host ldt\n");
+               printk("ldt_get_host_info: couldn't allocate buffer for host "
+                      "ldt\n");
                return;
        }
 
@@ -426,11 +438,13 @@ void ldt_get_host_info(void)
                host_ldt_entries = dummy_list;
        else {
                size = (size + 1) * sizeof(dummy_list[0]);
-               host_ldt_entries = (short *)kmalloc(size, GFP_KERNEL);
-               if(host_ldt_entries == NULL) {
-                       printk("ldt_get_host_info: couldn't allocate host ldt list\n");
+               tmp = kmalloc(size, GFP_KERNEL);
+               if(tmp == NULL) {
+                       printk("ldt_get_host_info: couldn't allocate host ldt "
+                              "list\n");
                        goto out_free;
                }
+               host_ldt_entries = tmp;
        }
 
        for(i=0, k=0; i<ret/LDT_ENTRY_SIZE; i++){
@@ -480,8 +494,7 @@ long init_new_ldt(struct mmu_context_skas * new_mm,
                         * inherited from the host. All ldt-entries found
                         * will be reset in the following loop
                         */
-                       if(host_ldt_entries == NULL)
-                               ldt_get_host_info();
+                       ldt_get_host_info();
                        for(num_p=host_ldt_entries; *num_p != -1; num_p++){
                                desc.entry_number = *num_p;
                                err = write_ldt_entry(&new_mm->id, 1, &desc,
@@ -560,6 +573,6 @@ void free_ldt(struct mmu_context_skas * mm)
 
 int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
 {
-       return(CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
-                               ptr, bytecount));
+       return CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
+                               ptr, bytecount);
 }