From nobody Sat Apr 27 00:41:16 2024 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=1575331456; cv=none; d=zohomail.com; s=zohoarc; b=Y8XTCgMziV9wpc/s2YCNXJ4m/v+81p9Qz7D5rUPli3xFKhbuknpWh7BJj+0eaMeZFqROv7z+Qp1GiFp4J7qaPiOsmOLwHY3tx26cHgbtomzgG+5VDAzK0s/KTEyK5o9DCMLyI02fw+HXZyNDpB+VDplqRY59CNh5lGgY8UAeNbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575331456; 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=wRHRznstE4ygu+dw0oZlTjgC4qDfVbGvHZR4xPqtjbk=; b=Nm6aq3y7/J9ZVivwsBU34M6s7KZ3A/xdEBcnbw3CgOXcC3LsPqkK/7CsC0iKsCsGDwDeIDsilXf75L+Vsjhf4YuDjRozAxxZnErC4AqdUsBrpKtKpE4BoSFvPg6imDDjfUYy9E2nq3w1s6kfRJYyPMHpDZbTev/OKIlviiWaQ00= 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 1575331456104666.9914310747508; Mon, 2 Dec 2019 16:04:16 -0800 (PST) Received: from localhost ([::1]:45944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvfq-0005AB-Ft for importer@patchew.org; Mon, 02 Dec 2019 19:04:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46398) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvXf-0006fg-Av for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibvXc-0008RI-Tp for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:47 -0500 Received: from nwk-aaemail-lapp01.apple.com ([17.151.62.66]:37060) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibvXc-0008NS-J3 for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:44 -0500 Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id xB2Nq6Lt044435; Mon, 2 Dec 2019 15:55:43 -0800 Received: from ma1-mtap-s03.corp.apple.com (ma1-mtap-s03.corp.apple.com [17.40.76.7]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2wkr83ys1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 02 Dec 2019 15:55:43 -0800 Received: from nwk-mmpp-sz12.apple.com (nwk-mmpp-sz12.apple.com [17.128.115.204]) by ma1-mtap-s03.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q1W00D69T4U1O50@ma1-mtap-s03.corp.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from process_milters-daemon.nwk-mmpp-sz12.apple.com by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q1W00A00SGIRL00@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from pontoon.com (unknown [17.193.42.217]) by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q1W00JNAT4TQI20@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -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=wRHRznstE4ygu+dw0oZlTjgC4qDfVbGvHZR4xPqtjbk=; b=p8FokfvnUovlofAEK7/6CGp8JpoY8enOaMoxdpGsEGi+VWDbbbtTt/NsQH7lc+I4Sz+6 GWkDLQMWaT+90E6wWoVaYvhbB1ih89XHZaJzZrUwkMzloxJbkhK2yvM3wqVuXuEuAyCv V0vdoV7Q5htH+sAiGB8kRZ2SUZzrm/D+RGEV0t7+4u7N13v/zSkiTLaw/DowF+NqynTl 93pC2TrdDn1WPo5w9M5mEdsXLMKY7HCaBC0DPY3eKipq706LWyqv5XaxgRbD2t3wvGIJ 3WMZkIjvcqhMINjIBxa7VNh7iz8VZUY/RZI53BnkbRWGmc9MA5s2voU3apRqvi/BSRhx dQ== X-Va-A: X-Va-T-CD: c56cc4374afe9162bf6a337f3d661529 X-Va-E-CD: 15deaa169f2b4447ffc7b83b019c30c6 X-Va-R-CD: 78d6d63b5531fbab8eb6146b51df527c X-Va-CD: 0 X-Va-ID: b53dabe8-dd64-404f-a4c5-158f110531ff X-V-A: X-V-T-CD: c56cc4374afe9162bf6a337f3d661529 X-V-E-CD: 15deaa169f2b4447ffc7b83b019c30c6 X-V-R-CD: 78d6d63b5531fbab8eb6146b51df527c X-V-CD: 0 X-V-ID: af441b0f-30ac-468e-9048-7f5023588c78 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-12-02_06:,, signatures=0 To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v3 1/5] hvf: non-RAM, non-ROMD memory ranges are now correctly mapped in Date: Mon, 02 Dec 2019 15:55:37 -0800 Message-id: <148d7842c00839ebc55d9391de83d86cf83b5fa8.1575330463.git.dirty@apple.com> 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-12-02_06:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 17.151.62.66 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" If an area is non-RAM and non-ROMD, then remove mappings so accesses will trap and can be emulated. Change hvf_find_overlap_slot() to take a size instead of an end address: it wouldn't return a slot because callers would pass the same address for start and end. Don't always map area as read/write/execute, respect area flags. Signed-off-by: Cameron Esfahani Signed-off-by: Paolo Bonzini --- target/i386/hvf/hvf.c | 50 ++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 231732aaf7..0b50cfcbc6 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -107,14 +107,14 @@ static void assert_hvf_ok(hv_return_t ret) } =20 /* Memory slots */ -hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t end) +hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size) { hvf_slot *slot; int x; for (x =3D 0; x < hvf_state->num_slots; ++x) { slot =3D &hvf_state->slots[x]; if (slot->size && start < (slot->start + slot->size) && - end > slot->start) { + (start + size) > slot->start) { return slot; } } @@ -129,12 +129,10 @@ struct mac_slot { }; =20 struct mac_slot mac_slots[32]; -#define ALIGN(x, y) (((x) + (y) - 1) & ~((y) - 1)) =20 -static int do_hvf_set_memory(hvf_slot *slot) +static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags) { struct mac_slot *macslot; - hv_memory_flags_t flags; hv_return_t ret; =20 macslot =3D &mac_slots[slot->slot_id]; @@ -151,8 +149,6 @@ static int do_hvf_set_memory(hvf_slot *slot) return 0; } =20 - flags =3D HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC; - macslot->present =3D 1; macslot->gpa_start =3D slot->start; macslot->size =3D slot->size; @@ -165,14 +161,24 @@ void hvf_set_phys_mem(MemoryRegionSection *section, b= ool add) { hvf_slot *mem; MemoryRegion *area =3D section->mr; + bool writeable =3D !area->readonly && !area->rom_device; + hv_memory_flags_t flags; =20 if (!memory_region_is_ram(area)) { - return; + if (writeable) { + return; + } else if (!memory_region_is_romd(area)) { + /* + * If the memory device is not in romd_mode, then we actually = want + * to remove the hvf memory slot so all accesses will trap. + */ + add =3D false; + } } =20 mem =3D hvf_find_overlap_slot( section->offset_within_address_space, - section->offset_within_address_space + int128_get64(section->s= ize)); + int128_get64(section->size)); =20 if (mem && add) { if (mem->size =3D=3D int128_get64(section->size) && @@ -186,7 +192,7 @@ void hvf_set_phys_mem(MemoryRegionSection *section, boo= l add) /* Region needs to be reset. set the size to 0 and remap it. */ if (mem) { mem->size =3D 0; - if (do_hvf_set_memory(mem)) { + if (do_hvf_set_memory(mem, 0)) { error_report("Failed to reset overlapping slot"); abort(); } @@ -196,6 +202,13 @@ void hvf_set_phys_mem(MemoryRegionSection *section, bo= ol add) return; } =20 + if (area->readonly || + (!memory_region_is_ram(area) && memory_region_is_romd(area))) { + flags =3D HV_MEMORY_READ | HV_MEMORY_EXEC; + } else { + flags =3D HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC; + } + /* Now make a new slot. */ int x; =20 @@ -216,7 +229,7 @@ void hvf_set_phys_mem(MemoryRegionSection *section, boo= l add) mem->start =3D section->offset_within_address_space; mem->region =3D area; =20 - if (do_hvf_set_memory(mem)) { + if (do_hvf_set_memory(mem, flags)) { error_report("Error registering new memory slot"); abort(); } @@ -345,7 +358,14 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64= _t gpa, uint64_t ept_qual) return false; } =20 - return !slot; + if (!slot) { + return true; + } + if (!memory_region_is_ram(slot->region) && + !(read && memory_region_is_romd(slot->region))) { + return true; + } + return false; } =20 static void hvf_set_dirty_tracking(MemoryRegionSection *section, bool on) @@ -354,7 +374,7 @@ static void hvf_set_dirty_tracking(MemoryRegionSection = *section, bool on) =20 slot =3D hvf_find_overlap_slot( section->offset_within_address_space, - section->offset_within_address_space + int128_get64(section->s= ize)); + int128_get64(section->size)); =20 /* protect region against writes; begin tracking it */ if (on) { @@ -720,7 +740,7 @@ int hvf_vcpu_exec(CPUState *cpu) ret =3D EXCP_INTERRUPT; break; } - /* Need to check if MMIO or unmmaped fault */ + /* Need to check if MMIO or unmapped fault */ case EXIT_REASON_EPT_FAULT: { hvf_slot *slot; @@ -731,7 +751,7 @@ int hvf_vcpu_exec(CPUState *cpu) vmx_set_nmi_blocking(cpu); } =20 - slot =3D hvf_find_overlap_slot(gpa, gpa); + slot =3D hvf_find_overlap_slot(gpa, 1); /* mmio */ if (ept_emulation_fault(slot, gpa, exit_qual)) { struct x86_decode decode; --=20 2.24.0 From nobody Sat Apr 27 00:41:16 2024 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=1575331361; cv=none; d=zohomail.com; s=zohoarc; b=TzKGT2pum7lkulxoAmSr3Nzl+oGB51OvAkUhK2UfFxljv27FhCsTB4RmGA8R8KMDiJuWL94DhYMYGdq4I26tHbT5ndhxR5M1NilpVcuEe8D7dve7trMDfQRtDA9RbeO1gKjN8jFBJ/hH/0lxYJbFBsiVUJ7Awlf6YTP85vqtWUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575331361; 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=FG09fH2kz8jEX/xXK1yo35vtn8o4/Q0MVF2XlhtILaU=; b=bzRWWDA/zrgUazqt5HV5Q5UWwg0CLvORgxMsvTXrkVHzGkzKTJK6cwwRkaIsPszGvzA9/OjQIR5QdPfDsDndGXhoMpZgP2PD4RrNuYqtodpdOL/kne31NfA5CZArviMOYINJQTLpgG47d183r8hBGFWBWFrkn49q7xmcar2wRlI= 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 1575331361808987.4831710327966; Mon, 2 Dec 2019 16:02:41 -0800 (PST) Received: from localhost ([::1]:45928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibveJ-0003gO-Vs for importer@patchew.org; Mon, 02 Dec 2019 19:02:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46275) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvXf-0006fY-2V for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibvXc-0008QY-N0 for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:45 -0500 Received: from nwk-aaemail-lapp01.apple.com ([17.151.62.66]:37072) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibvXc-0008Nz-CL for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:44 -0500 Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id xB2Nq6Lu044435; Mon, 2 Dec 2019 15:55:43 -0800 Received: from ma1-mtap-s03.corp.apple.com (ma1-mtap-s03.corp.apple.com [17.40.76.7]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2wkr83ys1h-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 02 Dec 2019 15:55:43 -0800 Received: from nwk-mmpp-sz12.apple.com (nwk-mmpp-sz12.apple.com [17.128.115.204]) by ma1-mtap-s03.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q1W00D69T4U1O50@ma1-mtap-s03.corp.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from process_milters-daemon.nwk-mmpp-sz12.apple.com by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q1W00A00SGIRL00@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from pontoon.com (unknown [17.193.42.217]) by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q1W00JNAT4TQI20@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -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=FG09fH2kz8jEX/xXK1yo35vtn8o4/Q0MVF2XlhtILaU=; b=vmpSSLiLVJG5BbyiSs8CDSBR1EoHzMXPS/UrGZlDLDVApuzxh3ZSg3XJ9mpP7NfkBxd+ 6sk0ErlEQeKO0rFL5FJGf27aqwp6isq7SQUswIhsUzTYAuq3SiDxFZY1xB96aRdpoXuM j9P2N8tQ6V7LUSQHLzEIAraGRPXk13qo+csNBF/IsGtGUE4TwxraE5IgbWspOtCcZK+v DGgO28fkvZGUPs22O+drDXgibtlXf8wlADxyHXRSzoykALYnf1NCpQsLffeB5AM+3rH9 5paK/iOqY3alRG1mNwsPLxH7Bs2zmvd73ZLIjM0HND8QqmQWi4M7ZGNzHLg4Mzg3YpkN UQ== X-Va-A: X-Va-T-CD: c56cc4374afe9162bf6a337f3d661529 X-Va-E-CD: 3a0700f7bd232aa2e14bd4948494cd90 X-Va-R-CD: 8d09ec05a2462c69b598a16229b39d18 X-Va-CD: 0 X-Va-ID: d8a8f06a-7dec-469b-ba33-1a74b6198b12 X-V-A: X-V-T-CD: c56cc4374afe9162bf6a337f3d661529 X-V-E-CD: 3a0700f7bd232aa2e14bd4948494cd90 X-V-R-CD: 8d09ec05a2462c69b598a16229b39d18 X-V-CD: 0 X-V-ID: ed368b89-e80d-429d-b32c-9cc63f798036 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-12-02_06:,, signatures=0 To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v3 2/5] hvf: remove TSC synchronization code because it isn't fully complete Date: Mon, 02 Dec 2019 15:55:38 -0800 Message-id: <211818e56f8f4900800274e769470e46987e337c.1575330463.git.dirty@apple.com> 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-12-02_06:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 17.151.62.66 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" The existing code in QEMU's HVF support to attempt to synchronize TSC across multiple cores is not sufficient. TSC value on other cores can go backwards. Until implementation is fixed, remove calls to hv_vm_sync_tsc(). Pass through TSC to guest OS. Signed-off-by: Cameron Esfahani Signed-off-by: Paolo Bonzini --- target/i386/hvf/hvf.c | 3 +-- target/i386/hvf/x86_emu.c | 3 --- target/i386/hvf/x86hvf.c | 4 ---- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 0b50cfcbc6..90fd50acfc 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -518,7 +518,6 @@ void hvf_reset_vcpu(CPUState *cpu) { wreg(cpu->hvf_fd, HV_X86_R8 + i, 0x0); } =20 - hv_vm_sync_tsc(0); hv_vcpu_invalidate_tlb(cpu->hvf_fd); hv_vcpu_flush(cpu->hvf_fd); } @@ -612,7 +611,7 @@ int hvf_init_vcpu(CPUState *cpu) hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_GSBASE, 1); hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_KERNELGSBASE, 1); hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_TSC_AUX, 1); - /*hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_TSC, 1);*/ + hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_TSC, 1); hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_SYSENTER_CS, 1); hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_SYSENTER_EIP, 1); hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_SYSENTER_ESP, 1); diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index 1b04bd7e94..3df767209d 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -772,9 +772,6 @@ void simulate_wrmsr(struct CPUState *cpu) =20 switch (msr) { case MSR_IA32_TSC: - /* if (!osx_is_sierra()) - wvmcs(cpu->hvf_fd, VMCS_TSC_OFFSET, data - rdtscp()); - hv_vm_sync_tsc(data);*/ break; case MSR_IA32_APICBASE: cpu_set_apic_base(X86_CPU(cpu)->apic_state, data); diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c index e0ea02d631..1485b95776 100644 --- a/target/i386/hvf/x86hvf.c +++ b/target/i386/hvf/x86hvf.c @@ -152,10 +152,6 @@ void hvf_put_msrs(CPUState *cpu_state) =20 hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_GSBASE, env->segs[R_GS].base); hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_FSBASE, env->segs[R_FS].base); - - /* if (!osx_is_sierra()) - wvmcs(cpu_state->hvf_fd, VMCS_TSC_OFFSET, env->tsc - rdtscp());*/ - hv_vm_sync_tsc(env->tsc); } =20 =20 --=20 2.24.0 From nobody Sat Apr 27 00:41:16 2024 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=1575331111; cv=none; d=zohomail.com; s=zohoarc; b=ROA9xvQE2RXDWlMgY0gmtCsOTG3yt3OSH2YeG0tIkH8NxL5zQNs39EKPnwfvq7xvtls9KL4d8AhEXkZvT9l+lW3g6TFg98bSR6DJLs2wR6RNE8BnZQ6Kdswvmp4Inq+bLFqhhTw5jEMdhCuEz6NzSKCAkpoA0Hp8DuawQcrK3pg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575331111; 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=GZJYJxYnNhFTqV98YR/cXz/sbGl3k1AK5iVBynTVHQ4=; b=O3z4TmVhKZj8QAr0H97dYBbHMHXO1s22WyTj8V/Bb3rb4XOPMaqzfIta/A5bJyvz7HF3h84TsKR1AbQpM+CP6Ke+/NYV7l4ttDXNkldCTJ7+tjPZqjTT6XqCpuIO65pSqxZj/Izd75MyrPsOf7nPnHv7nAblLRBv9bx9waQFdQ0= 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 1575331111244672.1334748072813; Mon, 2 Dec 2019 15:58:31 -0800 (PST) Received: from localhost ([::1]:45868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvaG-0008QN-42 for importer@patchew.org; Mon, 02 Dec 2019 18:58:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46432) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvXf-0006fi-Ih for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibvXd-0008Ru-2E for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:47 -0500 Received: from nwk-aaemail-lapp01.apple.com ([17.151.62.66]:37096) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibvXc-0008Ol-Ma for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:44 -0500 Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id xB2Nq6Lv044435; Mon, 2 Dec 2019 15:55:43 -0800 Received: from ma1-mtap-s03.corp.apple.com (ma1-mtap-s03.corp.apple.com [17.40.76.7]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2wkr83ys1h-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 02 Dec 2019 15:55:43 -0800 Received: from nwk-mmpp-sz12.apple.com (nwk-mmpp-sz12.apple.com [17.128.115.204]) by ma1-mtap-s03.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q1W00D69T4U1O50@ma1-mtap-s03.corp.apple.com>; Mon, 02 Dec 2019 15:55:43 -0800 (PST) Received: from process_milters-daemon.nwk-mmpp-sz12.apple.com by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q1W00A00SGIRL00@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from pontoon.com (unknown [17.193.42.217]) by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q1W00JNAT4TQI20@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -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=GZJYJxYnNhFTqV98YR/cXz/sbGl3k1AK5iVBynTVHQ4=; b=jbD92zb6YEBp7xrAE1VxW4vXd77zVR2scynlQ4HUgQP0yGrJlZ4O1VyLJxn/KELVwHg1 L7Ir0lLyzD3pqShIx7EW666t708tjP5alR1vuC6cKqSyLXQFzJfXehi7dxgLYJM5sMI/ +oPwiB4oepE3l6x++OgfISX+l19f+kizvoD1f7B70LBQNdYJQeV0c9VUEUlDJdLRa5cr oXxW9A9zgIha94yPpjHywiICaT1g9IDAo1z+tsYK2YnhE7viciRTBfabSxeRh5pdRmgj h6m4+U8dRB/2C246y77LSPiKkCFYv4B22Wbksv4jGh/E/F0AgLyB1Eoh25ZpVByrp0FN bw== X-Va-A: X-Va-T-CD: X-Va-E-CD: X-Va-R-CD: X-Va-CD: 0 X-Va-ID: d34965fb-21a0-4138-bcec-ea52802ecacf X-V-A: X-V-T-CD: c56cc4374afe9162bf6a337f3d661529 X-V-E-CD: 291ed8d7b9e4fc5ea2a5c06f0fe12f87 X-V-R-CD: ffbcac2a58459699290d8448c41fbad7 X-V-CD: 0 X-V-ID: 8d8955b4-48ef-4c58-b6d7-8c637f27f5e7 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-12-02_06:,, signatures=0 To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v3 3/5] hvf: correctly handle REX prefix in relation to legacy prefixes Date: Mon, 02 Dec 2019 15:55:39 -0800 Message-id: <0d6b7acd75fb20b2686affb8992eccada91bfc7f.1575330463.git.dirty@apple.com> 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-12-02_06:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 17.151.62.66 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" In real x86 processors, the REX prefix must come after legacy prefixes. REX before legacy is ignored. Update the HVF emulation code to properly handle this. Fix some spelling errors in constants. Fix some decoder table initialization issues found by Coverity. Signed-off-by: Cameron Esfahani Signed-off-by: Paolo Bonzini --- target/i386/hvf/x86_decode.c | 64 ++++++++++++++++++++---------------- target/i386/hvf/x86_decode.h | 20 +++++------ 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c index 822fa1866e..77c346605f 100644 --- a/target/i386/hvf/x86_decode.c +++ b/target/i386/hvf/x86_decode.c @@ -122,7 +122,8 @@ static void decode_rax(CPUX86State *env, struct x86_dec= ode *decode, { op->type =3D X86_VAR_REG; op->reg =3D R_EAX; - op->ptr =3D get_reg_ref(env, op->reg, decode->rex.rex, 0, + /* Since reg is always AX, REX prefix has no impact. */ + op->ptr =3D get_reg_ref(env, op->reg, false, 0, decode->operand_size); } =20 @@ -1687,40 +1688,37 @@ calc_addr: } } =20 -target_ulong get_reg_ref(CPUX86State *env, int reg, int rex, int is_extend= ed, - int size) +target_ulong get_reg_ref(CPUX86State *env, int reg, int rex_present, + int is_extended, int size) { target_ulong ptr =3D 0; - int which =3D 0; =20 if (is_extended) { reg |=3D R_R8; } =20 - switch (size) { case 1: - if (is_extended || reg < 4 || rex) { - which =3D 1; + if (is_extended || reg < 4 || rex_present) { ptr =3D (target_ulong)&RL(env, reg); } else { - which =3D 2; ptr =3D (target_ulong)&RH(env, reg - 4); } break; default: - which =3D 3; ptr =3D (target_ulong)&RRX(env, reg); break; } return ptr; } =20 -target_ulong get_reg_val(CPUX86State *env, int reg, int rex, int is_extend= ed, - int size) +target_ulong get_reg_val(CPUX86State *env, int reg, int rex_present, + int is_extended, int size) { target_ulong val =3D 0; - memcpy(&val, (void *)get_reg_ref(env, reg, rex, is_extended, size), si= ze); + memcpy(&val, + (void *)get_reg_ref(env, reg, rex_present, is_extended, size), + size); return val; } =20 @@ -1853,28 +1851,38 @@ void calc_modrm_operand(CPUX86State *env, struct x8= 6_decode *decode, static void decode_prefix(CPUX86State *env, struct x86_decode *decode) { while (1) { + /* + * REX prefix must come after legacy prefixes. + * REX before legacy is ignored. + * Clear rex to simulate this. + */ uint8_t byte =3D decode_byte(env, decode); switch (byte) { case PREFIX_LOCK: decode->lock =3D byte; + decode->rex.rex =3D 0; break; case PREFIX_REPN: case PREFIX_REP: decode->rep =3D byte; + decode->rex.rex =3D 0; break; - case PREFIX_CS_SEG_OVEERIDE: - case PREFIX_SS_SEG_OVEERIDE: - case PREFIX_DS_SEG_OVEERIDE: - case PREFIX_ES_SEG_OVEERIDE: - case PREFIX_FS_SEG_OVEERIDE: - case PREFIX_GS_SEG_OVEERIDE: + case PREFIX_CS_SEG_OVERRIDE: + case PREFIX_SS_SEG_OVERRIDE: + case PREFIX_DS_SEG_OVERRIDE: + case PREFIX_ES_SEG_OVERRIDE: + case PREFIX_FS_SEG_OVERRIDE: + case PREFIX_GS_SEG_OVERRIDE: decode->segment_override =3D byte; + decode->rex.rex =3D 0; break; case PREFIX_OP_SIZE_OVERRIDE: decode->op_size_override =3D byte; + decode->rex.rex =3D 0; break; case PREFIX_ADDR_SIZE_OVERRIDE: decode->addr_size_override =3D byte; + decode->rex.rex =3D 0; break; case PREFIX_REX ... (PREFIX_REX + 0xf): if (x86_is_long_mode(env_cpu(env))) { @@ -2111,14 +2119,14 @@ void init_decoder() { int i; =20 - for (i =3D 0; i < ARRAY_SIZE(_decode_tbl2); i++) { - memcpy(_decode_tbl1, &invl_inst, sizeof(invl_inst)); + for (i =3D 0; i < ARRAY_SIZE(_decode_tbl1); i++) { + memcpy(&_decode_tbl1[i], &invl_inst, sizeof(invl_inst)); } for (i =3D 0; i < ARRAY_SIZE(_decode_tbl2); i++) { - memcpy(_decode_tbl2, &invl_inst, sizeof(invl_inst)); + memcpy(&_decode_tbl2[i], &invl_inst, sizeof(invl_inst)); } for (i =3D 0; i < ARRAY_SIZE(_decode_tbl3); i++) { - memcpy(_decode_tbl3, &invl_inst, sizeof(invl_inst_x87)); + memcpy(&_decode_tbl3[i], &invl_inst_x87, sizeof(invl_inst_x87)); =20 } for (i =3D 0; i < ARRAY_SIZE(_1op_inst); i++) { @@ -2167,22 +2175,22 @@ target_ulong decode_linear_addr(CPUX86State *env, s= truct x86_decode *decode, target_ulong addr, X86Seg seg) { switch (decode->segment_override) { - case PREFIX_CS_SEG_OVEERIDE: + case PREFIX_CS_SEG_OVERRIDE: seg =3D R_CS; break; - case PREFIX_SS_SEG_OVEERIDE: + case PREFIX_SS_SEG_OVERRIDE: seg =3D R_SS; break; - case PREFIX_DS_SEG_OVEERIDE: + case PREFIX_DS_SEG_OVERRIDE: seg =3D R_DS; break; - case PREFIX_ES_SEG_OVEERIDE: + case PREFIX_ES_SEG_OVERRIDE: seg =3D R_ES; break; - case PREFIX_FS_SEG_OVEERIDE: + case PREFIX_FS_SEG_OVERRIDE: seg =3D R_FS; break; - case PREFIX_GS_SEG_OVEERIDE: + case PREFIX_GS_SEG_OVERRIDE: seg =3D R_GS; break; default: diff --git a/target/i386/hvf/x86_decode.h b/target/i386/hvf/x86_decode.h index bc574a7a44..ef7960113f 100644 --- a/target/i386/hvf/x86_decode.h +++ b/target/i386/hvf/x86_decode.h @@ -27,12 +27,12 @@ typedef enum x86_prefix { PREFIX_REPN =3D 0xf2, PREFIX_REP =3D 0xf3, /* group 2 */ - PREFIX_CS_SEG_OVEERIDE =3D 0x2e, - PREFIX_SS_SEG_OVEERIDE =3D 0x36, - PREFIX_DS_SEG_OVEERIDE =3D 0x3e, - PREFIX_ES_SEG_OVEERIDE =3D 0x26, - PREFIX_FS_SEG_OVEERIDE =3D 0x64, - PREFIX_GS_SEG_OVEERIDE =3D 0x65, + PREFIX_CS_SEG_OVERRIDE =3D 0x2e, + PREFIX_SS_SEG_OVERRIDE =3D 0x36, + PREFIX_DS_SEG_OVERRIDE =3D 0x3e, + PREFIX_ES_SEG_OVERRIDE =3D 0x26, + PREFIX_FS_SEG_OVERRIDE =3D 0x64, + PREFIX_GS_SEG_OVERRIDE =3D 0x65, /* group 3 */ PREFIX_OP_SIZE_OVERRIDE =3D 0x66, /* group 4 */ @@ -303,10 +303,10 @@ uint64_t sign(uint64_t val, int size); =20 uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode); =20 -target_ulong get_reg_ref(CPUX86State *env, int reg, int rex, int is_extend= ed, - int size); -target_ulong get_reg_val(CPUX86State *env, int reg, int rex, int is_extend= ed, - int size); +target_ulong get_reg_ref(CPUX86State *env, int reg, int rex_present, + int is_extended, int size); +target_ulong get_reg_val(CPUX86State *env, int reg, int rex_present, + int is_extended, int size); void calc_modrm_operand(CPUX86State *env, struct x86_decode *decode, struct x86_decode_op *op); target_ulong decode_linear_addr(CPUX86State *env, struct x86_decode *decod= e, --=20 2.24.0 From nobody Sat Apr 27 00:41:16 2024 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=1575331111; cv=none; d=zohomail.com; s=zohoarc; b=ENWsHAYolt0JO/Ic9V1CnQnySiT7ACHoR7pP7+pb/m5B5W/JGrYTShRc2Eiet33/ieX+4uqbm8TLuHbmWiwePgi5NcB4utqQjcjaWrCMEYYoE+y39L8qbu2ERm4T1jEbSBEBy79N1F3SfMgejNlg9CcSXtxpOm/HZ8IiKLdHGiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575331111; 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=ee7/7Ngklg3ShuDiqM1OyHxaWCHXtBSBarKuirDBevs=; b=jgMFV+yEIHJEUzrPXVvCMNwzNPWtvxSD5w72SCxxd0a7wfKyvGXKya7TV1Ob1bd9ijWTnYMcmzsuDvPwYhsn7DKtlnsidw6XU6YXVVS9TNirqlayZ4KCxzlC7+Hq/2CUvg3UOQbiWhl6KGyp0VpxTauaDCUuxtIBH0d5F59qS8E= 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 1575331111292915.4616247966759; Mon, 2 Dec 2019 15:58:31 -0800 (PST) Received: from localhost ([::1]:45872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvaH-0008U6-Qv for importer@patchew.org; Mon, 02 Dec 2019 18:58:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46419) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvXf-0006fh-GS for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibvXd-0008SP-7A for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:47 -0500 Received: from nwk-aaemail-lapp01.apple.com ([17.151.62.66]:37118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibvXc-0008PS-U4 for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:45 -0500 Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id xB2Nq6Lw044435; Mon, 2 Dec 2019 15:55:44 -0800 Received: from ma1-mtap-s03.corp.apple.com (ma1-mtap-s03.corp.apple.com [17.40.76.7]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2wkr83ys1h-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 02 Dec 2019 15:55:44 -0800 Received: from nwk-mmpp-sz12.apple.com (nwk-mmpp-sz12.apple.com [17.128.115.204]) by ma1-mtap-s03.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q1W00D69T4U1O50@ma1-mtap-s03.corp.apple.com>; Mon, 02 Dec 2019 15:55:43 -0800 (PST) Received: from process_milters-daemon.nwk-mmpp-sz12.apple.com by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q1W00A00SGIRL00@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from pontoon.com (unknown [17.193.42.217]) by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q1W00JNAT4TQI20@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -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=ee7/7Ngklg3ShuDiqM1OyHxaWCHXtBSBarKuirDBevs=; b=JsN1yuR8DbdR6AAAktaUpvXZ3NyP771eqL0MniXpwFuXFodp+WfUjvSAJOXOkjqxHFJT Pr+SXCAdR1aEnEfYAK++qMlcoZHDZ30VpFFfL1a2GreZbXFAFMhdmbAwo7TvWLCC6qaD ltak1ho2qvSRJBqAY7DzPQJjRM7ISRGrA/Vwia3CoV4CFjxSDhx46nAP2lz4MsALUYg1 /b2HES+fxKfr89gIa9MAf+IRymI22oaZ6RKFwH/I3sJBbZvT4ghU3Va0nnmf72OO6FHe lBfqHYbyNZ5DIEW7SNbOU8NxWObHbK9yJpS3EsEzNtsB+4ZbRhcEPq1PGlJgdnHmMnJ5 GA== X-Va-A: X-Va-T-CD: c56cc4374afe9162bf6a337f3d661529 X-Va-E-CD: 263ce0a3bfc93a533d48b3d0f711ae8c X-Va-R-CD: 4f855c1c806c43b90c8de5dcdc6f0780 X-Va-CD: 0 X-Va-ID: 9b16ca19-295a-4906-9e71-268c6a03dab1 X-V-A: X-V-T-CD: c56cc4374afe9162bf6a337f3d661529 X-V-E-CD: 263ce0a3bfc93a533d48b3d0f711ae8c X-V-R-CD: 4f855c1c806c43b90c8de5dcdc6f0780 X-V-CD: 0 X-V-ID: ad9ef32c-9d87-4ef6-9c48-586f54af0cd5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-12-02_06:,, signatures=0 To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v3 4/5] hvf: more accurately match SDM when setting CR0 and PDPTE registers Date: Mon, 02 Dec 2019 15:55:40 -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-12-02_06:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 17.151.62.66 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" More accurately match SDM when setting CR0 and PDPTE registers. Clear PDPTE registers when resetting vcpus. Signed-off-by: Cameron Esfahani Signed-off-by: Paolo Bonzini --- target/i386/hvf/hvf.c | 8 ++++++++ target/i386/hvf/vmx.h | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 90fd50acfc..784e67d77e 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -441,12 +441,20 @@ static MemoryListener hvf_memory_listener =3D { }; =20 void hvf_reset_vcpu(CPUState *cpu) { + uint64_t pdpte[4] =3D {0, 0, 0, 0}; + int i; =20 /* TODO: this shouldn't be needed; there is already a call to * cpu_synchronize_all_post_reset in vl.c */ wvmcs(cpu->hvf_fd, VMCS_ENTRY_CTLS, 0); wvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER, 0); + + /* Initialize PDPTE */ + for (i =3D 0; i < 4; i++) { + wvmcs(cpu->hvf_fd, VMCS_GUEST_PDPTE0 + i * 2, pdpte[i]); + } + macvm_set_cr0(cpu->hvf_fd, 0x60000010); =20 wvmcs(cpu->hvf_fd, VMCS_CR4_MASK, CR4_VMXE_MASK); diff --git a/target/i386/hvf/vmx.h b/target/i386/hvf/vmx.h index 5dc52ecad6..eb8894cd58 100644 --- a/target/i386/hvf/vmx.h +++ b/target/i386/hvf/vmx.h @@ -121,6 +121,7 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint= 64_t cr0) uint64_t pdpte[4] =3D {0, 0, 0, 0}; uint64_t efer =3D rvmcs(vcpu, VMCS_GUEST_IA32_EFER); uint64_t old_cr0 =3D rvmcs(vcpu, VMCS_GUEST_CR0); + uint64_t mask =3D CR0_PG | CR0_CD | CR0_NW | CR0_NE | CR0_ET; =20 if ((cr0 & CR0_PG) && (rvmcs(vcpu, VMCS_GUEST_CR4) & CR4_PAE) && !(efer & MSR_EFER_LME)) { @@ -128,18 +129,15 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, ui= nt64_t cr0) rvmcs(vcpu, VMCS_GUEST_CR3) & ~0x1f, MEMTXATTRS_UNSPECIFIED, (uint8_t *)pdpte, 32, 0); + /* Only set PDPTE when appropriate. */ + for (i =3D 0; i < 4; i++) { + wvmcs(vcpu, VMCS_GUEST_PDPTE0 + i * 2, pdpte[i]); + } } =20 - for (i =3D 0; i < 4; i++) { - wvmcs(vcpu, VMCS_GUEST_PDPTE0 + i * 2, pdpte[i]); - } - - wvmcs(vcpu, VMCS_CR0_MASK, CR0_CD | CR0_NE | CR0_PG); + wvmcs(vcpu, VMCS_CR0_MASK, mask); wvmcs(vcpu, VMCS_CR0_SHADOW, cr0); =20 - cr0 &=3D ~CR0_CD; - wvmcs(vcpu, VMCS_GUEST_CR0, cr0 | CR0_NE | CR0_ET); - if (efer & MSR_EFER_LME) { if (!(old_cr0 & CR0_PG) && (cr0 & CR0_PG)) { enter_long_mode(vcpu, cr0, efer); @@ -149,6 +147,10 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uin= t64_t cr0) } } =20 + /* Filter new CR0 after we are finished examining it above. */ + cr0 =3D (cr0 & ~(mask & ~CR0_PG)); + wvmcs(vcpu, VMCS_GUEST_CR0, cr0 | CR0_NE | CR0_ET); + hv_vcpu_invalidate_tlb(vcpu); hv_vcpu_flush(vcpu); } --=20 2.24.0 From nobody Sat Apr 27 00:41:16 2024 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=1575331116; cv=none; d=zohomail.com; s=zohoarc; b=ZDx9XMjf9hz1dGRvYn+3PLVhlj8axjMz4nOZqgAGNbp2+yH+1T4dCkDTdj4acg7Nx0+Upq3SmOD0lyC/vdThTAPkvOEhO8VoUjU0yMTYGsu9ZjYUdHr7wVPfRrif9f0tnpi9gY9gS/ClURdoUElX6GnxcluFRtPfkwBXR1PQdlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575331116; 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=M6Amdn5tTnG0+MiIbSoHQ+Q5fB9Zaizyl4VxdLmO/kM=; b=i0rc+tE3QFaq7M9G/wtBNBdeAtXLfOKP5ctnKW5wYm5GZOsHXy8vzysRHvWEJYw6PuOmlf2A8Qdkem9BGO34z7NMmGn/waUOuQnNg+lwDPLg7kBMUrZCpE+tp4LF+5Rev8DbemBauCv7HKmjQKek5GmfN+AdS72xjH29/oKCdds= 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 1575331116028400.982633067494; Mon, 2 Dec 2019 15:58:36 -0800 (PST) Received: from localhost ([::1]:45876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvaM-0000A7-Fl for importer@patchew.org; Mon, 02 Dec 2019 18:58:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46472) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibvXf-0006fl-VA for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibvXd-0008TF-H3 for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:47 -0500 Received: from nwk-aaemail-lapp01.apple.com ([17.151.62.66]:37134) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibvXd-0008QE-6i for qemu-devel@nongnu.org; Mon, 02 Dec 2019 18:55:45 -0500 Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id xB2Nq6Lx044435; Mon, 2 Dec 2019 15:55:44 -0800 Received: from ma1-mtap-s03.corp.apple.com (ma1-mtap-s03.corp.apple.com [17.40.76.7]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2wkr83ys1h-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 02 Dec 2019 15:55:44 -0800 Received: from nwk-mmpp-sz12.apple.com (nwk-mmpp-sz12.apple.com [17.128.115.204]) by ma1-mtap-s03.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q1W00D69T4U1O50@ma1-mtap-s03.corp.apple.com>; Mon, 02 Dec 2019 15:55:43 -0800 (PST) Received: from process_milters-daemon.nwk-mmpp-sz12.apple.com by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q1W00A00SGIRL00@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -0800 (PST) Received: from pontoon.com (unknown [17.193.42.217]) by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q1W00JNAT4TQI20@nwk-mmpp-sz12.apple.com>; Mon, 02 Dec 2019 15:55:42 -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=M6Amdn5tTnG0+MiIbSoHQ+Q5fB9Zaizyl4VxdLmO/kM=; b=WSsFoc2QN+FRvFnnaFf9wNSRpt83JFp5LRorxfI690Lrr2oorXypbCMG0XER0J0enOhp T6oFK04qrqzQ63FT1fe0SP86bugzhBEJXqRpnIrF44uN7foQ9Mb2Gab10yU28e37KwOy YjRaetdmKd4MWL3YHL5+LPtWJNNJ9xqVuB9tC22Ne5WZ/tvvQPj9VMJ3fbVpMT37Z3nP HAAeLi3lZykTtgwGdsmlR+k1eBYEW5xui1RAZ25xsbh5AOBMH5GsupQbqkWhhqCaN8MF u4n10T5SbmQPP6GqfsRrVZ6bi7pl4CzQ4gjn0aYiB6Iv6lF2Lf8c860CNpQXT6OrHjVT FQ== X-Va-A: X-Va-T-CD: c56cc4374afe9162bf6a337f3d661529 X-Va-E-CD: e901bae79aabc4d8f90935e818db0bf1 X-Va-R-CD: 717efc5767b68d0267f4c572528f496b X-Va-CD: 0 X-Va-ID: 5dcc9b38-72a6-4400-9259-6c6f6ae2f8c4 X-V-A: X-V-T-CD: c56cc4374afe9162bf6a337f3d661529 X-V-E-CD: e901bae79aabc4d8f90935e818db0bf1 X-V-R-CD: 717efc5767b68d0267f4c572528f496b X-V-CD: 0 X-V-ID: d94293ff-4d4d-4fb9-b533-5ed91a6a0d7a X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-12-02_06:,, signatures=0 To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v3 5/5] hvf: correctly inject VMCS_INTR_T_HWINTR versus VMCS_INTR_T_SWINTR. Date: Mon, 02 Dec 2019 15:55:41 -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-12-02_06:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 17.151.62.66 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" Previous implementation in hvf_inject_interrupts() would always inject VMCS_INTR_T_SWINTR even when VMCS_INTR_T_HWINTR was required. Now correctly determine when VMCS_INTR_T_HWINTR is appropriate versus VMCS_INTR_T_SWINTR. 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 | 4 +++- target/i386/hvf/x86hvf.c | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 784e67d77e..d72543dc31 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -637,6 +637,8 @@ static void hvf_store_events(CPUState *cpu, uint32_t in= s_len, uint64_t idtvec_in env->exception_injected =3D 0; env->interrupt_injected =3D -1; env->nmi_injected =3D false; + env->ins_len =3D 0; + env->has_error_code =3D false; if (idtvec_info & VMCS_IDT_VEC_VALID) { switch (idtvec_info & VMCS_IDT_VEC_TYPE) { case VMCS_IDT_VEC_HWINTR: @@ -659,7 +661,7 @@ static void hvf_store_events(CPUState *cpu, uint32_t in= s_len, uint64_t idtvec_in (idtvec_info & VMCS_IDT_VEC_TYPE) =3D=3D VMCS_IDT_VEC_SWINTR) { env->ins_len =3D ins_len; } - 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); } diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c index 1485b95776..edefe5319a 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); @@ -357,7 +355,11 @@ bool hvf_inject_interrupts(CPUState *cpu_state) bool have_event =3D true; if (env->interrupt_injected !=3D -1) { vector =3D env->interrupt_injected; - intr_type =3D VMCS_INTR_T_SWINTR; + if (env->ins_len) { + intr_type =3D VMCS_INTR_T_SWINTR; + } else { + intr_type =3D VMCS_INTR_T_HWINTR; + } } else if (env->exception_nr !=3D -1) { vector =3D env->exception_nr; if (vector =3D=3D EXCP03_INT3 || vector =3D=3D EXCP04_INTO) { @@ -366,7 +368,7 @@ bool hvf_inject_interrupts(CPUState *cpu_state) intr_type =3D VMCS_INTR_T_HWEXCEPTION; } } 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 +392,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 +403,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