From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KIWGn-0006Lm-5H for qemu-devel@nongnu.org; Mon, 14 Jul 2008 18:11:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KIWGl-0006Jn-NG for qemu-devel@nongnu.org; Mon, 14 Jul 2008 18:11:44 -0400 Received: from [199.232.76.173] (port=45303 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIWGl-0006Ja-7r for qemu-devel@nongnu.org; Mon, 14 Jul 2008 18:11:43 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:33518) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KIWGk-0001Gz-IZ for qemu-devel@nongnu.org; Mon, 14 Jul 2008 18:11:43 -0400 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate03.web.de (Postfix) with ESMTP id C34F7E3C337F for ; Tue, 15 Jul 2008 00:11:41 +0200 (CEST) Received: from [88.64.11.250] (helo=[192.168.1.198]) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1KIWGj-0001v7-00 for qemu-devel@nongnu.org; Tue, 15 Jul 2008 00:11:41 +0200 Resent-To: qemu-devel@nongnu.org Resent-Message-Id: <487BCF1D.9080700@web.de> Message-ID: <487BCEA6.3030209@web.de> Date: Tue, 15 Jul 2008 00:09:42 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <487BCA03.9060001@web.de> In-Reply-To: <487BCA03.9060001@web.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH 3/4] linux-user: Allocate guest-reachable descriptor tables Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org IDT, GDT and LDTs have to allocated from memory regions also reachable by the guests. Obtain them via the new qemu_vmalloc_guest_safe service. Signed-off-by: Jan Kiszka --- linux-user/i386/syscall.h | 2 ++ linux-user/main.c | 13 +++++++------ linux-user/syscall.c | 3 ++- linux-user/x86_64/syscall.h | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) Index: b/linux-user/main.c =================================================================== --- a/linux-user/main.c +++ b/linux-user/main.c @@ -280,9 +280,9 @@ static void write_dt(void *ptr, unsigned p[1] = tswapl(e2); } -#if TARGET_X86_64 -uint64_t idt_table[512]; +uint64_t *idt_table; +#if TARGET_X86_64 static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, uint64_t addr, unsigned int sel) { @@ -301,8 +301,6 @@ static void set_idt(int n, unsigned int set_gate64(idt_table + n * 2, 0, dpl, 0, 0); } #else -uint64_t idt_table[256]; - static void set_gate(void *ptr, unsigned int type, unsigned int dpl, uint32_t addr, unsigned int sel) { @@ -2444,8 +2442,10 @@ int main(int argc, char **argv) #endif /* linux interrupt setup */ + idt_table = qemu_vmalloc_guest_safe(sizeof(uint64_t) * TARGET_IDT_ENTRIES); + memset(idt_table, 0, sizeof(uint64_t) * TARGET_IDT_ENTRIES); env->idt.base = h2g(idt_table); - env->idt.limit = sizeof(idt_table) - 1; + env->idt.limit = sizeof(uint64_t) * TARGET_IDT_ENTRIES - 1; set_idt(0, 0); set_idt(1, 0); set_idt(2, 0); @@ -2471,7 +2471,8 @@ int main(int argc, char **argv) /* linux segment setup */ { uint64_t *gdt_table; - gdt_table = qemu_mallocz(sizeof(uint64_t) * TARGET_GDT_ENTRIES); + gdt_table = qemu_vmalloc_guest_safe(sizeof(uint64_t) * TARGET_GDT_ENTRIES); + memset(gdt_table, 0, sizeof(uint64_t) * TARGET_GDT_ENTRIES); env->gdt.base = h2g((unsigned long)gdt_table); env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; #ifdef TARGET_ABI32 Index: b/linux-user/i386/syscall.h =================================================================== --- a/linux-user/i386/syscall.h +++ b/linux-user/i386/syscall.h @@ -22,6 +22,8 @@ struct target_pt_regs { /* ioctls */ +#define TARGET_IDT_ENTRIES 256 + #define TARGET_LDT_ENTRIES 8192 #define TARGET_LDT_ENTRY_SIZE 8 Index: b/linux-user/x86_64/syscall.h =================================================================== --- a/linux-user/x86_64/syscall.h +++ b/linux-user/x86_64/syscall.h @@ -29,6 +29,8 @@ struct target_pt_regs { /* top of stack page */ }; +#define TARGET_IDT_ENTRIES 512 + /* Maximum number of LDT entries supported. */ #define TARGET_LDT_ENTRIES 8192 /* The size of each LDT entry. */ Index: b/linux-user/syscall.c =================================================================== --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2473,7 +2473,8 @@ static abi_long write_ldt(CPUX86State *e } /* allocate the LDT */ if (!ldt_table) { - ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); + ldt_table = qemu_vmalloc_guest_safe(TARGET_LDT_ENTRIES + * TARGET_LDT_ENTRY_SIZE); if (!ldt_table) return -TARGET_ENOMEM; memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);