From: Laurent Vivier <laurent@vivier.eu>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: peter.maydell@linaro.org, fanwj@mail.ustc.edu.cn, qemu-devel@nongnu.org
Subject: Re: [PATCH] linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64
Date: Tue, 7 Mar 2023 15:30:57 +0100 [thread overview]
Message-ID: <86533769-fecb-974e-765e-c1210cb36d4f@vivier.eu> (raw)
In-Reply-To: <4172b90.58b08.18631b77860.Coremail.fanwj@mail.ustc.edu.cn>
Richard,
do you think it's correct?
Thanks,
Laurent
Le 08/02/2023 à 16:49, fanwj@mail.ustc.edu.cn a écrit :
> On linux user mode, CPUX86State::gdt::base from Different CPUX86State Objects have same value, It is incorrect! Every CPUX86State::gdt::base Must points to independent memory space.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405
> Signed-off-by: fanwenjie <fanwj@mail.ustc.edu.cn>
> ---
> linux-user/i386/cpu_loop.c | 9 +++++++++
> linux-user/main.c | 7 +++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
> index 865413c..48511cd 100644
> --- a/linux-user/i386/cpu_loop.c
> +++ b/linux-user/i386/cpu_loop.c
> @@ -314,8 +314,17 @@ void cpu_loop(CPUX86State *env)
> }
> }
>
> +static void target_cpu_free(void *obj)
> +{
> + CPUArchState* env = ((CPUState*)obj)->env_ptr;
> + target_munmap(env->gdt.base, sizeof(uint64_t) * TARGET_GDT_ENTRIES);
> + g_free(obj);
> +}
> +
> void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
> {
> + CPUState* cpu = env_cpu(env);
> + OBJECT(cpu)->free = target_cpu_free;
> env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
> env->hflags |= HF_PE_MASK | HF_CPL_MASK;
> if (env->features[FEAT_1_EDX] & CPUID_SSE) {
> diff --git a/linux-user/main.c b/linux-user/main.c
> index a17fed0..3acd9b4 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -234,6 +234,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)
> + new_env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES,
> + PROT_READ|PROT_WRITE,
> + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> + memcpy((void*)g2h_untagged(new_env->gdt.base), (void*)g2h_untagged(env->gdt.base), sizeof(uint64_t) * TARGET_GDT_ENTRIES);
> + OBJECT(new_cpu)->free = OBJECT(cpu)->free;
> +#endif
>
> /* Clone all break/watchpoints.
> Note: Once we support ptrace with hw-debug register access, make sure
next prev parent reply other threads:[~2023-03-07 14:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 15:49 [PATCH] linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64 fanwj
2023-03-07 14:30 ` Laurent Vivier [this message]
2023-03-07 18:20 ` Richard Henderson
2023-03-07 18:45 ` Laurent Vivier
-- strict thread matches above, loose matches on Subject: below --
2023-01-03 11:38 fanwenjie
2023-01-15 5:32 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86533769-fecb-974e-765e-c1210cb36d4f@vivier.eu \
--to=laurent@vivier.eu \
--cc=fanwj@mail.ustc.edu.cn \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).