From nobody Wed Nov 12 23:20:51 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1574626093; cv=none; d=zohomail.com; s=zohoarc; b=L9S4FcciZkq8woiVpswsEqLO+6Eq3GIUi1I3A06dfsv+x30H+x46S5AKrbsPvQKHPemspZXmFY+D08IdGwuTVpdjyh02oo9H6HU2zhZPQR3/KzUB3LKbw3tVqrL/e893AgqzWrZ1zSdCZcyvXqZZh3ySKrkQ/p6cvd7JdIjZ8yk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574626093; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ED8kSIZUYTrDZMsmkkGXVJ7ZZBX4G9LJm1K81o1D27A=; b=fRX4LZIbF+bHw6PWc6Z7nQMZKJvbL85cOMmadJVZ81FRoI+KyVRPM9Aali/iyJqxYxnq8tdzlycxED+klSREmHUxVhK4ehry/V6EAto++gYEaEQtghuDncpySYvrpWO8LY1XpRhv7dVSMOKEEWp7TgQOw0ulia8TVTDWh402azs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574626093235434.3694977795675; Sun, 24 Nov 2019 12:08:13 -0800 (PST) Received: from localhost ([::1]:38506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iYyB1-0000J4-IJ for importer@patchew.org; Sun, 24 Nov 2019 15:08:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44094) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iYy8U-0006uU-JK for qemu-devel@nongnu.org; Sun, 24 Nov 2019 15:05:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iYy8S-0007x0-Uf for qemu-devel@nongnu.org; Sun, 24 Nov 2019 15:05:34 -0500 Received: from nwk-aaemail-lapp02.apple.com ([17.151.62.67]:34630) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iYy8S-0007vj-LH for qemu-devel@nongnu.org; Sun, 24 Nov 2019 15:05:32 -0500 Received: from pps.filterd (nwk-aaemail-lapp02.apple.com [127.0.0.1]) by nwk-aaemail-lapp02.apple.com (8.16.0.27/8.16.0.27) with SMTP id xAOK2Gce023790; Sun, 24 Nov 2019 12:05:31 -0800 Received: from ma1-mtap-s03.corp.apple.com (ma1-mtap-s03.corp.apple.com [17.40.76.7]) by nwk-aaemail-lapp02.apple.com with ESMTP id 2wf27mnhc9-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 24 Nov 2019 12:05:31 -0800 Received: from nwk-mmpp-sz10.apple.com (nwk-mmpp-sz10.apple.com [17.128.115.122]) by ma1-mtap-s03.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q1H003BCP56HM10@ma1-mtap-s03.corp.apple.com>; Sun, 24 Nov 2019 12:05:31 -0800 (PST) Received: from process_milters-daemon.nwk-mmpp-sz10.apple.com by nwk-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q1H00F00P3BWT00@nwk-mmpp-sz10.apple.com>; Sun, 24 Nov 2019 12:05:30 -0800 (PST) Received: from pontoon.com (unknown [17.234.36.164]) by nwk-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q1H000C0P54NN30@nwk-mmpp-sz10.apple.com>; Sun, 24 Nov 2019 12:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=sender : from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=20180706; bh=ED8kSIZUYTrDZMsmkkGXVJ7ZZBX4G9LJm1K81o1D27A=; b=jd/oPeLFwmvgaOGUKY4e4MQd5TUEN2iZuYbDQlmLjNj6J/NVmwCPW1vxhJRHic2VDzp6 Vc7eYaBPLM6XCGyEQXZjlthJD4rTqw2FcBZCj7iPJLGEFnK+Zga0o/kp92Q3S7DjShPs if0Os4pmvV6ZUjfbmKI2shiP3QHR5KWQRL2Z1DZvDc5luembOQkICqNrS6e8FHqd9ts/ CVDX4NdZQylgh9aeRc+g3ACZ4WK3yEv/3Pe1LZT6/WPD+DnWt2X/Dr9XcR8odVfnL9Z3 nvJ0evMFAm5WLksmviD6d/tl2O8ZrJmpL8TjMoO8lt4FToJ+sDB9cAi2IyKUsY7qwYGs Ow== X-Va-A: X-Va-T-CD: X-Va-E-CD: X-Va-R-CD: X-Va-CD: 0 X-Va-ID: db7eba79-676b-49c4-bd3a-724b4a196e83 X-V-A: X-V-T-CD: c56cc4374afe9162bf6a337f3d661529 X-V-E-CD: 755bae5e0993979b31cced1bacd1a159 X-V-R-CD: 0283d5b3f8dcb9bdbbcfd61ba47c139b X-V-CD: 0 X-V-ID: 0cb25030-75f2-445a-98b7-ef600e2c1160 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-24_02:,, signatures=0 To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them Date: Sun, 24 Nov 2019 12:05:27 -0800 Message-id: X-Mailer: git-send-email 2.24.0 In-reply-to: References: MIME-version: 1.0 Content-transfer-encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-11-24_02:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 17.151.62.67 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Cameron Esfahani From: Cameron Esfahani via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Save away type as well as vector in hvf_store_events() so we can correctly reinject both in hvf_inject_interrupts(). Make sure to clear ins_len and has_error_code when ins_len isn't valid and error_code isn't set. Signed-off-by: Cameron Esfahani --- target/i386/hvf/hvf.c | 18 ++++++++++++++---- target/i386/hvf/x86hvf.c | 22 ++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 784e67d77e..8a8aee4495 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -641,14 +641,18 @@ static void hvf_store_events(CPUState *cpu, uint32_t = ins_len, uint64_t idtvec_in switch (idtvec_info & VMCS_IDT_VEC_TYPE) { case VMCS_IDT_VEC_HWINTR: case VMCS_IDT_VEC_SWINTR: - env->interrupt_injected =3D idtvec_info & VMCS_IDT_VEC_VECNUM; + /* Save event type as well so we can inject the correct type. = */ + env->interrupt_injected =3D + idtvec_info & (VMCS_IDT_VEC_TYPE | VMCS_IDT_VEC_VECNUM); break; case VMCS_IDT_VEC_NMI: env->nmi_injected =3D true; break; case VMCS_IDT_VEC_HWEXCEPTION: case VMCS_IDT_VEC_SWEXCEPTION: - env->exception_nr =3D idtvec_info & VMCS_IDT_VEC_VECNUM; + /* Save event type as well so we can inject the correct type. = */ + env->exception_nr =3D + idtvec_info & (VMCS_IDT_VEC_TYPE | VMCS_IDT_VEC_VECNUM); env->exception_injected =3D 1; break; case VMCS_IDT_VEC_PRIV_SWEXCEPTION: @@ -658,10 +662,16 @@ static void hvf_store_events(CPUState *cpu, uint32_t = ins_len, uint64_t idtvec_in if ((idtvec_info & VMCS_IDT_VEC_TYPE) =3D=3D VMCS_IDT_VEC_SWEXCEPT= ION || (idtvec_info & VMCS_IDT_VEC_TYPE) =3D=3D VMCS_IDT_VEC_SWINTR) { env->ins_len =3D ins_len; + } else { + /* Clear ins_len when it isn't valid. */ + env->ins_len =3D 0; } - if (idtvec_info & VMCS_INTR_DEL_ERRCODE) { + if (idtvec_info & VMCS_IDT_VEC_ERRCODE_VALID) { env->has_error_code =3D true; env->error_code =3D rvmcs(cpu->hvf_fd, VMCS_IDT_VECTORING_ERRO= R); + } else { + /* Clear has_error_code when error_code isn't valid. */ + env->has_error_code =3D false; } } if ((rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY) & @@ -942,7 +952,7 @@ int hvf_vcpu_exec(CPUState *cpu) macvm_set_rip(cpu, rip + ins_len); break; case VMX_REASON_VMCALL: - env->exception_nr =3D EXCP0D_GPF; + env->exception_nr =3D VMCS_INTR_T_HWEXCEPTION | EXCP0D_GPF; env->exception_injected =3D 1; env->has_error_code =3D true; env->error_code =3D 0; diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c index 1485b95776..d25ae4585b 100644 --- a/target/i386/hvf/x86hvf.c +++ b/target/i386/hvf/x86hvf.c @@ -345,8 +345,6 @@ void vmx_clear_int_window_exiting(CPUState *cpu) ~VMCS_PRI_PROC_BASED_CTLS_INT_WINDOW_EXITING); } =20 -#define NMI_VEC 2 - bool hvf_inject_interrupts(CPUState *cpu_state) { X86CPU *x86cpu =3D X86_CPU(cpu_state); @@ -356,17 +354,15 @@ bool hvf_inject_interrupts(CPUState *cpu_state) uint64_t intr_type; bool have_event =3D true; if (env->interrupt_injected !=3D -1) { - vector =3D env->interrupt_injected; - intr_type =3D VMCS_INTR_T_SWINTR; + /* Type and vector are both saved in interrupt_injected. */ + vector =3D env->interrupt_injected & VMCS_IDT_VEC_VECNUM; + intr_type =3D env->interrupt_injected & VMCS_IDT_VEC_TYPE; } else if (env->exception_nr !=3D -1) { - vector =3D env->exception_nr; - if (vector =3D=3D EXCP03_INT3 || vector =3D=3D EXCP04_INTO) { - intr_type =3D VMCS_INTR_T_SWEXCEPTION; - } else { - intr_type =3D VMCS_INTR_T_HWEXCEPTION; - } + /* Type and vector are both saved in exception_nr. */ + vector =3D env->exception_nr & VMCS_IDT_VEC_VECNUM; + intr_type =3D env->exception_nr & VMCS_IDT_VEC_TYPE; } else if (env->nmi_injected) { - vector =3D NMI_VEC; + vector =3D EXCP02_NMI; intr_type =3D VMCS_INTR_T_NMI; } else { have_event =3D false; @@ -390,6 +386,8 @@ bool hvf_inject_interrupts(CPUState *cpu_state) if (env->has_error_code) { wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_EXCEPTION_ERROR, env->error_code); + /* Indicate that VMCS_ENTRY_EXCEPTION_ERROR is valid */ + info |=3D VMCS_INTR_DEL_ERRCODE; } /*printf("reinject %lx err %d\n", info, err);*/ wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info); @@ -399,7 +397,7 @@ bool hvf_inject_interrupts(CPUState *cpu_state) if (cpu_state->interrupt_request & CPU_INTERRUPT_NMI) { if (!(env->hflags2 & HF2_NMI_MASK) && !(info & VMCS_INTR_VALID)) { cpu_state->interrupt_request &=3D ~CPU_INTERRUPT_NMI; - info =3D VMCS_INTR_VALID | VMCS_INTR_T_NMI | NMI_VEC; + info =3D VMCS_INTR_VALID | VMCS_INTR_T_NMI | EXCP02_NMI; wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info); } else { vmx_set_nmi_window_exiting(cpu_state); --=20 2.24.0