linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64
PATCH 1/1 linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64
From 4601a624f40b2c89e7df2dec1adffb4f4308ba2d Mon Sep 17 00:00:00 2001
From: fanwenjie <[email protected]>
Date: Sun, 1 Jan 2023 23:13:34 +0800
Subject: [PATCH] linux-user: fix bug about incorrect base addresss of idt and
gdt on i386 and x86_64
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405
--- linux-user/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
linux-user/main.c +13 -0
@@ -171,6 +171,12 @@ void fork_end(int child) __threadCPUState *thread_cpu; +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) +#include <stdalign.h> +__thread alignas(TARGET_PAGE_SIZE )static uint64_t gdt_base[TARGET_GDT_ENTRIES ]; +__thread alignas(TARGET_PAGE_SIZE )static uint64_t idt_base[TARGET_PAGE_SIZE /sizeof (uint64_t )]; +#endif +bool qemu_cpu_is_self (CPUState *cpu) {return thread_cpu == cpu;
@@ -235,6 +241,13 @@ CPUArchState *cpu_copy(CPUArchState *env) new_cpu->tcg_cflags = cpu->tcg_cflags;memcpy (new_env, env,sizeof (CPUArchState)); +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) +memcpy (idt_base, (void *)new_env->idt.base,sizeof (uint64_t ) * (new_env->idt.limit +1 )); +memcpy (gdt_base, (void *)new_env->gdt.base,sizeof (uint64_t ) *TARGET_GDT_ENTRIES ); + new_env->idt.base = (target_ulong )idt_base; + new_env->gdt.base = (target_ulong )gdt_base; +#endif +/* Clone all break/watchpoints. Note: Once we support ptrace with hw-debug register access, make sure BP_CPU break/watchpoints are handled correctly on clone. */
Signature · 1 line
2.34.1
Recall: [PATCH] linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64
The Patch has some problem, Please RECALL it!
-----原始邮件-----
发件人:[email protected]
发送时间:2023-01-01 23:57:06 (星期日)
收件人: [email protected]
抄送: [email protected]
主题: [PATCH] linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64
From 4601a624f40b2c89e7df2dec1adffb4f4308ba2d Mon Sep 17 00:00:00 2001
From: fanwenjie <[email protected]>
Date: Sun, 1 Jan 2023 23:13:34 +0800
Subject: [PATCH] linux-user: fix bug about incorrect base addresss of idt and
gdt on i386 and x86_64
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405
--- linux-user/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
linux-user/main.c +13 -0
@@ -171,6 +171,12 @@ void fork_end(int child) __threadCPUState *thread_cpu; +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) +#include <stdalign.h> +__thread alignas(TARGET_PAGE_SIZE )static uint64_t gdt_base[TARGET_GDT_ENTRIES ]; +__thread alignas(TARGET_PAGE_SIZE )static uint64_t idt_base[TARGET_PAGE_SIZE /sizeof (uint64_t )]; +#endif +bool qemu_cpu_is_self (CPUState *cpu) {return thread_cpu == cpu;
@@ -235,6 +241,13 @@ CPUArchState *cpu_copy(CPUArchState *env) new_cpu->tcg_cflags = cpu->tcg_cflags;memcpy (new_env, env,sizeof (CPUArchState)); +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) +memcpy (idt_base, (void *)new_env->idt.base,sizeof (uint64_t ) * (new_env->idt.limit +1 )); +memcpy (gdt_base, (void *)new_env->gdt.base,sizeof (uint64_t ) *TARGET_GDT_ENTRIES ); + new_env->idt.base = (target_ulong )idt_base; + new_env->gdt.base = (target_ulong )gdt_base; +#endif +/* Clone all break/watchpoints. Note: Once we support ptrace with hw-debug register access, make sure BP_CPU break/watchpoints are handled correctly on clone. */
Signature · 1 line
2.34.1
Quoted 30 lines · [email protected] writes:
From
4601a624f40b2c89e7df2dec1adffb4f4308ba2dMon Sep 17 00:00:00 2001
From: fanwenjie <[email protected]>
Date: Sun, 1 Jan 2023 23:13:34 +0800
Subject: [PATCH] linux-user: fix bug about incorrect base addresss of idt and
gdt on i386 andx86_64Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405
Signed-off-by fanwenjie <[email protected]>--- linux-user/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)linux-user/main.c +6
-0@@ -171,6 +171,12 @@ void fork_end(int child) __threadCPUState *thread_cpu; +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) +#include <stdalign.h> +__thread alignas(TARGET_PAGE_SIZE )static uint64_t gdt_base[TARGET_GDT_ENTRIES ]; +__thread alignas(TARGET_PAGE_SIZE )static uint64_t idt_base[TARGET_PAGE_SIZE /sizeof (uint64_t )]; +#endif +bool qemu_cpu_is_self (CPUState *cpu) {return thread_cpu == cpu;
linux-user/main.c CPUArchState *cpu_copy(CPUArchState *env) · line 250
Quoted 10 lines
linux-user/main.c +7
-0@@ -235,6 +241,13 @@ CPUArchState *cpu_copy(CPUArchState *env) new_cpu->tcg_cflags = cpu->tcg_cflags;memcpy (new_env, env,sizeof (CPUArchState)); +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) +memcpy (idt_base, (void *)new_env->idt.base,sizeof (uint64_t ) * (new_env->idt.limit +1 )); +memcpy (gdt_base, (void *)new_env->gdt.base,sizeof (uint64_t ) *TARGET_GDT_ENTRIES ); + new_env->idt.base = (target_ulong )idt_base; + new_env->gdt.base = (target_ulong )gdt_base; +#endif +
This is the wrong place to copy target specific bits of code. I think this belongs with cpu_clone_regs_child and the gdt/idt structures in linux-user/i386/cpu_loop.c I think.
Quoted 3 lines
linux-user/main.c +0
-0/* Clone all break/watchpoints. Note: Once we support ptrace with hw-debug register access, make sure BP_CPU break/watchpoints are handled correctly on clone. */
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro