From nobody Mon Feb 9 06:26:49 2026 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