From nobody Tue Sep 16 17:18:33 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717835754; cv=none; d=zohomail.com; s=zohoarc; b=ZZadm/zLKgnsg1NjbRy5CWWxf/UVDoysbysV52UOFEYGtBnSpThIMyro2n2XFdIyldl+dKoi0JK5mNXEKPT1VBvi7DuGh/XevcYcg7qNn+0n8/xS9QbwoT3ANwFYeJCjANRJ9yoQ0NfUWfHM8pO+xOp4O7tTKIE2gcKrZ2Q3Y4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717835754; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=JE1l3mnnViu2bSu14FqFVuNS+di8GAj9jPlWPGLObPQ=; b=eDProRmpn0Bo0aGbPPuUu5L0Ooo8S+EAQeYaZiMgpTqV5aHLBYGH2GChAdW7pZYxSOfnB49Jo4nG0CLiLbCva2b3Dq/K3epo4bz3v3xE452wlQM+TgrXrs2ZkyZ7Tc27rfQaR/lL1N0PhA5b5bHtlu3olv5ShY4X70zUeteISPQ= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717835754297562.4762171523518; Sat, 8 Jun 2024 01:35:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFrXK-0000Zu-UW; Sat, 08 Jun 2024 04:34:54 -0400 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 1sFrXG-0000Ya-CC for qemu-devel@nongnu.org; Sat, 08 Jun 2024 04:34:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFrXE-0008J6-Ap for qemu-devel@nongnu.org; Sat, 08 Jun 2024 04:34:50 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-7ePzo6xOPZGqGpS51nTd1A-1; Sat, 08 Jun 2024 04:34:45 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a6efac81377so29294966b.2 for ; Sat, 08 Jun 2024 01:34:45 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6ef64a75b7sm131819166b.191.2024.06.08.01.34.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 01:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717835687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JE1l3mnnViu2bSu14FqFVuNS+di8GAj9jPlWPGLObPQ=; b=i5Ah6Ailm2eFK3+7R4QXvNo9Om/xQwfQh4E4imHi3Gdjsy1b1TK6WlDK6O/Artdg619llT C2HaHU7sOZusvxmwx7VqKbQY/cp7IBqThfW/ZIoW5wwwqkDksSg6LuUfh10EciKjBQpDaQ My7ySWDRIuy2cIp3p46R/zBD9mhjckk= X-MC-Unique: 7ePzo6xOPZGqGpS51nTd1A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717835683; x=1718440483; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JE1l3mnnViu2bSu14FqFVuNS+di8GAj9jPlWPGLObPQ=; b=AlZLD/f5JyfKYDAMJghwKrJwNsAXhX67hd57+SlZjCS7RsyICjl7/1qpYKq8t/8nD4 JylKJhPnraqzrJOEJqsiJyHtUySOwJ8BfhNu4+x9SeV4LLSuD42qkWhSw8wb30ZVlHpu g9Rwdn3aVC7JOVs+NduMNmYxFF8DVCG7y1yryIW5GAucUPR4WHG900dkSAkMSwkOgpT0 j2GDOEl6VGRXK9SeujFNXywK74sypaC+BzHVMmY9RkMK18bvasDW0fP4NV3nYitn6Fro a9+aJ/ZP5ufkl0iV4uTlpgnSq4dhrrVHwvT5GmGTISI98DvXAbsoXEkHMFRdwijuH3I+ Fxsw== X-Gm-Message-State: AOJu0YwOqYMWsVtSxE6p+3eglE2Dv3qPXWb/l1g962ynsrgEGG+3/V/U iJelMgLZo99vnqXVNTU/j2DP6QQGQYunoEE4zCZOxbAq2oRQP2f2omdj6NcVcSNtYOr7zGPf5Jz wyiVK/jj6mvwjTjRWBcYKkLF/Cuybz4cPhNBMs/JBgFjUpDa/HIl0pwlxwyauJysaU/VrwdQQy1 zWivtEZz54vlajH/aH3LKE+uOcMjdBKgCLiAli X-Received: by 2002:a17:906:f5a9:b0:a6f:2c2:9e98 with SMTP id a640c23a62f3a-a6f02c2a0demr81619066b.12.1717835683496; Sat, 08 Jun 2024 01:34:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFx6qcKV/fspAlFFotHRSBQv3y5tyl/j9n9WpvReQoYBLRuxdozhPqC9x5OQDTR59AZsUrcFA== X-Received: by 2002:a17:906:f5a9:b0:a6f:2c2:9e98 with SMTP id a640c23a62f3a-a6f02c2a0demr81618166b.12.1717835683090; Sat, 08 Jun 2024 01:34:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 09/42] target/i386: fix TF/RF handling for HLT Date: Sat, 8 Jun 2024 10:33:42 +0200 Message-ID: <20240608083415.2769160-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240608083415.2769160-1-pbonzini@redhat.com> References: <20240608083415.2769160-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717835756177100003 Content-Type: text/plain; charset="utf-8" HLT uses DISAS_NORETURN because the corresponding helper calls cpu_loop_exit(). However, while gen_eob() clears HF_RF_MASK and synthesizes a #DB exception if single-step is active, none of this is done by HLT. Note that the single-step trap is generated after the halt is finished. Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/seg_helper.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/= misc_helper.c index 093cc2d0f90..7fa0c5a06de 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -520,7 +520,7 @@ G_NORETURN void helper_hlt(CPUX86State *env) { CPUState *cs =3D env_cpu(env); =20 - env->hflags &=3D ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before= */ + do_end_instruction(env); cs->halted =3D 1; cs->exception_index =3D EXCP_HLT; cpu_loop_exit(cs); diff --git a/target/i386/tcg/sysemu/seg_helper.c b/target/i386/tcg/sysemu/s= eg_helper.c index 9ba94deb3aa..05174a79e73 100644 --- a/target/i386/tcg/sysemu/seg_helper.c +++ b/target/i386/tcg/sysemu/seg_helper.c @@ -130,15 +130,26 @@ void x86_cpu_do_interrupt(CPUState *cs) =20 bool x86_cpu_exec_halt(CPUState *cpu) { - if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { - X86CPU *x86_cpu =3D X86_CPU(cpu); + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; =20 + if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { bql_lock(); apic_poll_irq(x86_cpu->apic_state); cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL); bql_unlock(); } - return cpu_has_work(cpu); + + if (!cpu_has_work(cpu)) { + return false; + } + + /* Complete HLT instruction. */ + if (env->eflags & TF_MASK) { + env->dr[6] |=3D DR6_BS; + do_interrupt_all(x86_cpu, EXCP01_DB, 0, 0, env->eip, 0); + } + return true; } =20 bool x86_need_replay_interrupt(int interrupt_request) --=20 2.45.1