From: Johannes Berg <johannes.b...@intel.com>

There's really not much value in having this as a
separate lock, and having it makes it harder to
clean up the init_new_context() semantics to not
rely on 'current', even if dup_mm() is really only
called with 'current->mm' as the source today.

Replace the locking accordingly with mmap read and
write lock, and remove it from init_new_ldt()
entirely since it already holds the source lock.

Signed-off-by: Johannes Berg <johannes.b...@intel.com>
---
 arch/x86/um/asm/mm_context.h |  1 -
 arch/x86/um/ldt.c            | 14 ++++----------
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/arch/x86/um/asm/mm_context.h b/arch/x86/um/asm/mm_context.h
index dc32dc023c2f..2b1a76a87e14 100644
--- a/arch/x86/um/asm/mm_context.h
+++ b/arch/x86/um/asm/mm_context.h
@@ -25,7 +25,6 @@ struct ldt_entry {
 
 typedef struct uml_ldt {
        int entry_count;
-       struct mutex lock;
        union {
                struct ldt_entry * pages[LDT_PAGES_MAX];
                struct ldt_entry entries[LDT_DIRECT_ENTRIES];
diff --git a/arch/x86/um/ldt.c b/arch/x86/um/ldt.c
index 255a44dd415a..6b8e368f779c 100644
--- a/arch/x86/um/ldt.c
+++ b/arch/x86/um/ldt.c
@@ -65,7 +65,7 @@ static int read_ldt(void __user * ptr, unsigned long 
bytecount)
                bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
        err = bytecount;
 
-       mutex_lock(&ldt->lock);
+       mmap_read_lock(current->mm);
        if (ldt->entry_count <= LDT_DIRECT_ENTRIES) {
                size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES;
                if (size > bytecount)
@@ -89,7 +89,7 @@ static int read_ldt(void __user * ptr, unsigned long 
bytecount)
                        ptr += size;
                }
        }
-       mutex_unlock(&ldt->lock);
+       mmap_read_unlock(current->mm);
 
        if (bytecount == 0 || err == -EFAULT)
                goto out;
@@ -146,7 +146,7 @@ static int write_ldt(void __user * ptr, unsigned long 
bytecount, int func)
                        goto out;
        }
 
-       mutex_lock(&ldt->lock);
+       mmap_write_lock(current->mm);
 
        err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1);
        if (err)
@@ -201,7 +201,7 @@ static int write_ldt(void __user * ptr, unsigned long 
bytecount, int func)
        err = 0;
 
 out_unlock:
-       mutex_unlock(&ldt->lock);
+       mmap_write_unlock(current->mm);
 out:
        return err;
 }
@@ -305,9 +305,6 @@ long init_new_ldt(struct mm_context *new_mm, struct 
mm_context *from_mm)
        long page, err=0;
        void *addr = NULL;
 
-
-       mutex_init(&new_mm->arch.ldt.lock);
-
        if (!from_mm) {
                memset(&desc, 0, sizeof(desc));
                /*
@@ -334,7 +331,6 @@ long init_new_ldt(struct mm_context *new_mm, struct 
mm_context *from_mm)
         * i.e., we have to use the stub for modify_ldt, which
         * can't handle the big read buffer of up to 64kB.
         */
-       mutex_lock(&from_mm->arch.ldt.lock);
        if (from_mm->arch.ldt.entry_count <= LDT_DIRECT_ENTRIES)
                memcpy(new_mm->arch.ldt.u.entries, from_mm->arch.ldt.u.entries,
                       sizeof(new_mm->arch.ldt.u.entries));
@@ -353,8 +349,6 @@ long init_new_ldt(struct mm_context *new_mm, struct 
mm_context *from_mm)
                }
        }
        new_mm->arch.ldt.entry_count = from_mm->arch.ldt.entry_count;
-       mutex_unlock(&from_mm->arch.ldt.lock);
-
     out:
        return err;
 }
-- 
2.41.0


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

Reply via email to