From b3ee571e58120de30c3d15657022bf2c72477e02 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 18 Aug 2011 20:10:49 +0100 Subject: [PATCH] um: take ldt.h to arch/x86/um/asm/mm_context.h it's x86-only and we have no business playing with it in asm/mmu.h; make the latter have struct uml_arch_mm_context arch; instead of struct uml_ldt ldt; and let arch//um/asm/mm_context.h decide what'll be in there. While we are at it, kill host_ldt.h - it's not needed in part of places that include it (we want asm/ldt.h in those) and it can be trivially expanded into the single remaining one. Signed-off-by: Al Viro Signed-off-by: Richard Weinberger --- arch/um/include/asm/mmu.h | 4 +- arch/um/include/shared/ldt.h | 37 ------------------ .../sysdep/host_ldt.h => asm/mm_context.h} | 39 ++++++++++++++++++- arch/x86/um/asm/processor_32.h | 2 +- arch/x86/um/ldt.c | 36 ++++++++--------- arch/x86/um/shared/sysdep/tls.h | 1 - 6 files changed, 58 insertions(+), 61 deletions(-) delete mode 100644 arch/um/include/shared/ldt.h rename arch/x86/um/{shared/sysdep/host_ldt.h => asm/mm_context.h} (55%) diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index b1a7e47d1027..30509b9f37fd 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -7,11 +7,11 @@ #define __ARCH_UM_MMU_H #include "mm_id.h" -#include "ldt.h" +#include typedef struct mm_context { struct mm_id id; - struct uml_ldt ldt; + struct uml_arch_mm_context arch; struct page **stub_pages; } mm_context_t; diff --git a/arch/um/include/shared/ldt.h b/arch/um/include/shared/ldt.h deleted file mode 100644 index a7f999a58774..000000000000 --- a/arch/um/include/shared/ldt.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2004 Fujitsu Siemens Computers GmbH - * Licensed under the GPL - * - * Author: Bodo Stroesser - */ - -#ifndef __ASM_LDT_H -#define __ASM_LDT_H - -#include -#include - -extern void ldt_host_info(void); - -#define LDT_PAGES_MAX \ - ((LDT_ENTRIES * LDT_ENTRY_SIZE)/PAGE_SIZE) -#define LDT_ENTRIES_PER_PAGE \ - (PAGE_SIZE/LDT_ENTRY_SIZE) -#define LDT_DIRECT_ENTRIES \ - ((LDT_PAGES_MAX*sizeof(void *))/LDT_ENTRY_SIZE) - -struct ldt_entry { - __u32 a; - __u32 b; -}; - -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]; - } u; -} uml_ldt_t; - -#endif diff --git a/arch/x86/um/shared/sysdep/host_ldt.h b/arch/x86/um/asm/mm_context.h similarity index 55% rename from arch/x86/um/shared/sysdep/host_ldt.h rename to arch/x86/um/asm/mm_context.h index 246ff7ace5e5..4a73d63e4760 100644 --- a/arch/x86/um/shared/sysdep/host_ldt.h +++ b/arch/x86/um/asm/mm_context.h @@ -1,8 +1,39 @@ -#ifndef __ASM_HOST_LDT_H -#define __ASM_HOST_LDT_H +/* + * Copyright (C) 2004 Fujitsu Siemens Computers GmbH + * Licensed under the GPL + * + * Author: Bodo Stroesser + */ +#ifndef __ASM_LDT_H +#define __ASM_LDT_H + +#include #include +extern void ldt_host_info(void); + +#define LDT_PAGES_MAX \ + ((LDT_ENTRIES * LDT_ENTRY_SIZE)/PAGE_SIZE) +#define LDT_ENTRIES_PER_PAGE \ + (PAGE_SIZE/LDT_ENTRY_SIZE) +#define LDT_DIRECT_ENTRIES \ + ((LDT_PAGES_MAX*sizeof(void *))/LDT_ENTRY_SIZE) + +struct ldt_entry { + __u32 a; + __u32 b; +}; + +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]; + } u; +} uml_ldt_t; + #define LDT_entry_a(info) \ ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff)) @@ -34,4 +65,8 @@ #define LDT_empty(info) (_LDT_empty(info)) #endif +struct uml_arch_mm_context { + uml_ldt_t ldt; +}; + #endif diff --git a/arch/x86/um/asm/processor_32.h b/arch/x86/um/asm/processor_32.h index e5b72faea0f6..c4078b581df1 100644 --- a/arch/x86/um/asm/processor_32.h +++ b/arch/x86/um/asm/processor_32.h @@ -7,8 +7,8 @@ #define __UM_PROCESSOR_I386_H #include -#include #include +#include extern int host_has_cmov; diff --git a/arch/x86/um/ldt.c b/arch/x86/um/ldt.c index 3f2bf208d884..26b0e39d2ce9 100644 --- a/arch/x86/um/ldt.c +++ b/arch/x86/um/ldt.c @@ -137,7 +137,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount) { int i, err = 0; unsigned long size; - uml_ldt_t * ldt = ¤t->mm->context.ldt; + uml_ldt_t *ldt = ¤t->mm->context.arch.ldt; if (!ldt->entry_count) goto out; @@ -205,7 +205,7 @@ static int read_default_ldt(void __user * ptr, unsigned long bytecount) static int write_ldt(void __user * ptr, unsigned long bytecount, int func) { - uml_ldt_t * ldt = ¤t->mm->context.ldt; + uml_ldt_t *ldt = ¤t->mm->context.arch.ldt; struct mm_id * mm_idp = ¤t->mm->context.id; int i, err; struct user_desc ldt_info; @@ -397,7 +397,7 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm) if (!ptrace_ldt) - mutex_init(&new_mm->ldt.lock); + mutex_init(&new_mm->arch.ldt.lock); if (!from_mm) { memset(&desc, 0, sizeof(desc)); @@ -429,7 +429,7 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm) break; } } - new_mm->ldt.entry_count = 0; + new_mm->arch.ldt.entry_count = 0; goto out; } @@ -457,26 +457,26 @@ 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->ldt.lock); - if (from_mm->ldt.entry_count <= LDT_DIRECT_ENTRIES) - memcpy(new_mm->ldt.u.entries, from_mm->ldt.u.entries, - sizeof(new_mm->ldt.u.entries)); + 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)); else { - i = from_mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE; + i = from_mm->arch.ldt.entry_count / LDT_ENTRIES_PER_PAGE; while (i-->0) { page = __get_free_page(GFP_KERNEL|__GFP_ZERO); if (!page) { err = -ENOMEM; break; } - new_mm->ldt.u.pages[i] = + new_mm->arch.ldt.u.pages[i] = (struct ldt_entry *) page; - memcpy(new_mm->ldt.u.pages[i], - from_mm->ldt.u.pages[i], PAGE_SIZE); + memcpy(new_mm->arch.ldt.u.pages[i], + from_mm->arch.ldt.u.pages[i], PAGE_SIZE); } } - new_mm->ldt.entry_count = from_mm->ldt.entry_count; - mutex_unlock(&from_mm->ldt.lock); + new_mm->arch.ldt.entry_count = from_mm->arch.ldt.entry_count; + mutex_unlock(&from_mm->arch.ldt.lock); } out: @@ -488,12 +488,12 @@ void free_ldt(struct mm_context *mm) { int i; - if (!ptrace_ldt && mm->ldt.entry_count > LDT_DIRECT_ENTRIES) { - i = mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE; + if (!ptrace_ldt && mm->arch.ldt.entry_count > LDT_DIRECT_ENTRIES) { + i = mm->arch.ldt.entry_count / LDT_ENTRIES_PER_PAGE; while (i-- > 0) - free_page((long) mm->ldt.u.pages[i]); + free_page((long) mm->arch.ldt.u.pages[i]); } - mm->ldt.entry_count = 0; + mm->arch.ldt.entry_count = 0; } int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount) diff --git a/arch/x86/um/shared/sysdep/tls.h b/arch/x86/um/shared/sysdep/tls.h index f2f30bd67b9b..27cce00c6b30 100644 --- a/arch/x86/um/shared/sysdep/tls.h +++ b/arch/x86/um/shared/sysdep/tls.h @@ -24,7 +24,6 @@ typedef struct um_dup_user_desc { # else /* __KERNEL__ */ -# include typedef struct user_desc user_desc_t; # endif /* __KERNEL__ */ -- 2.20.1