From nobody Tue Sep 16 16:02:23 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=mail.ustc.edu.cn ARC-Seal: i=1; a=rsa-sha256; t=1672653898; cv=none; d=zohomail.com; s=zohoarc; b=g9PK6sJj/tG28aPCnehoE6Xb05To6TFWFzrBXAckXkAAOMjYsZNKQdL8aYjPHrOpVikyFFzyYbYjifxvFlrGKnHb0NMSVir18vGYN9LNISdCWebN+QsMh1Qf+XYr3h+MvuE7Z9seo1fQ9ecU/TJhQDcyMDgJoezAtvKTgafN/hE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672653898; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=1Wo3D7uYId+eiZoRwD7CVgMX+YG3n4wV0bOarfOvNI0=; b=dcTN0UTDnn+ueR/5dp3OAsSgzWCPKfaU8jSf1KvCFV6CWO2hB0X/iHovnTzDY7wSykqed4SNxeJeQFYjElTv10rB/OGn5SDrNaLJguGOi9Uxa13SkubSOQrH6QdbEnLkWyovfsa3EX49Bn6FZDO+xv38CMsxCZZDmc5CmqT79r8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16726538984291006.3017831629159; Mon, 2 Jan 2023 02:04:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pCHfn-0002P5-UH; Mon, 02 Jan 2023 05:04:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pCHfl-0002Oq-Dj for qemu-devel@nongnu.org; Mon, 02 Jan 2023 05:04:01 -0500 Received: from email6.ustc.edu.cn ([2001:da8:d800::8] helo=ustc.edu.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pCHfi-0003bB-L6 for qemu-devel@nongnu.org; Mon, 02 Jan 2023 05:04:00 -0500 Received: from localhost.localdomain (unknown [120.204.77.150]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygCXn4MHrLJj6AiMAA--.26676S2; Mon, 02 Jan 2023 18:03:55 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:MIME-Version:Content-Transfer-Encoding; bh=1Wo3D7uYId +eiZoRwD7CVgMX+YG3n4wV0bOarfOvNI0=; b=wT6S41UAymjWRKeKBqESE+EtGy bkabCKtaAwegaFki+LCc/ihWi4Zb+q8iTTw7nMX7GEy+aMtI3jl5H9RfGQmOBSzT U69cv9AdnFyV+OnL5pgcqoGAAumxAZR0SA4qc7DWozia+3lXmsM8/ouuRj1GBAqj hJdLZjafV5FCKBB0Q= From: fanwenjie To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, fanwenjie Subject: [PATCH] linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64 Date: Mon, 2 Jan 2023 18:03:46 +0800 Message-Id: <20230102100346.1706-1-fanwj@mail.ustc.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: LkAmygCXn4MHrLJj6AiMAA--.26676S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uw17Aw48XF15AF43WFyrCrg_yoW8Kw45pa sagF43tF17tFs8Janxtwn5ZFyUWF4kGrWUAw1fCanYya4kJry8ur1DCay7uw1DXw48ur4F yF98AFWDuayUX37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkC14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWUJwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUYwIDUU UUU X-CM-SenderInfo: pidq4yo6pdxzwoxv3uoohg3hdfq/1tbiAQwTEFQhoPOJ6QAUsc Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:da8:d800::8; envelope-from=fanwj@mail.ustc.edu.cn; helo=ustc.edu.cn X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @mail.ustc.edu.cn) X-ZM-MESSAGEID: 1672653899436100001 Content-Type: text/plain; charset="utf-8" On linux user mode, CPUX86State::idt::base and CPUX86State::gdt::base from = Different CPUX86State Objects have same value, It is incorrect! Every CPUX8= 6State::idt::base and Every CPUX86State::gdt::base Must points to independe= nt memory space.=20 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405 Signed-off-by: fanwenjie --- linux-user/i386/cpu_loop.c | 10 ++++++++++ linux-user/main.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 865413c08f..1f23bc5e3a 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -314,8 +314,18 @@ void cpu_loop(CPUX86State *env) } } =20 +static void target_cpu_free(void *obj) +{ + CPUArchState* env =3D ((CPUState*)obj)->env_ptr; + target_munmap(env->idt.base, sizeof(uint64_t) * (env->idt.limit + 1)); + 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 =3D env_cpu(env); + OBJECT(cpu)->free =3D target_cpu_free; env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; env->hflags |=3D 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 a17fed045b..2276040548 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -234,6 +234,17 @@ CPUArchState *cpu_copy(CPUArchState *env) =20 new_cpu->tcg_cflags =3D cpu->tcg_cflags; memcpy(new_env, env, sizeof(CPUArchState)); +#if defined(TARGET_I386) || defined(TARGET_X86_64) + new_env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENT= RIES, + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + new_env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limi= t + 1), + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + memcpy((void*)new_env->gdt.base, (void*)env->gdt.base, sizeof(uint64_t= ) * TARGET_GDT_ENTRIES); + memcpy((void*)new_env->idt.base, (void*)env->idt.base, sizeof(uint64_t= ) * (env->idt.limit + 1)); + OBJECT(new_cpu)->free =3D OBJECT(cpu)->free; +#endif =20 /* Clone all break/watchpoints. Note: Once we support ptrace with hw-debug register access, make su= re --=20 2.34.1