From nobody Fri May 17 20:20:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1611362630; cv=none; d=zohomail.com; s=zohoarc; b=LZI9RolIG/KTGvSR3vIMsAdR+VF10ds3BTG3hDEw/NFSiXUyPeWYHkYUkHkxEAB6GUsLclL0zUeWKm2sV9eYnBkPzB6Kicy+FVytSxolO3ZoI/VTxy1VlPCEYDMT/u+PGV+h8Q+PYbzEBvdZAwV+Q4rm6CKNM4GUGeiK1MrEBxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611362630; 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=JulyeAId/pybi/mrpR6nNjXtH31H6gHviEvwI2sa+a0=; b=OdL2dUpBnlBF4M0JC/wzyoAlzzDaYwAOLii2ufo66dlvv84aspiQU5WoWLyJas218Q1+rNmrSI0boSB1/pJ28laYwkuipVelv0iatkHHgeCGylfDNQc7k5xjlZGKAEsvpAOSFZG0okgg27Qe8NdHXJP0amzB3jgKbsC5ozn+iBM= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1611362630238881.6416784349301; Fri, 22 Jan 2021 16:43:50 -0800 (PST) Received: from localhost ([::1]:56008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l371p-00024F-4h for importer@patchew.org; Fri, 22 Jan 2021 19:43:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l36zh-0001Bw-Cr for qemu-devel@nongnu.org; Fri, 22 Jan 2021 19:41:38 -0500 Received: from mail.csgraf.de ([188.138.100.120]:50170 helo=zulu616.server4you.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l36ze-0004oL-Oo for qemu-devel@nongnu.org; Fri, 22 Jan 2021 19:41:37 -0500 Received: from localhost.localdomain (dynamic-077-004-009-148.77.4.pool.telefonica.de [77.4.9.148]) by csgraf.de (Postfix) with ESMTPSA id 534D239002E0; Sat, 23 Jan 2021 01:41:30 +0100 (CET) From: Alexander Graf To: qemu-devel@nongnu.org Subject: [PATCH] hvf: Fetch cr4 before evaluating CPUID(1) Date: Sat, 23 Jan 2021 01:41:29 +0100 Message-Id: <20210123004129.6364-1-agraf@csgraf.de> X-Mailer: git-send-email 2.24.3 (Apple Git-128) 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=188.138.100.120; envelope-from=agraf@csgraf.de; helo=zulu616.server4you.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Asad Ali , Richard Henderson , Cameron Esfahani , Roman Bolshakov , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The CPUID function 1 has a bit called OSXSAVE which tells user space the status of the CR4.OSXSAVE bit. Our generic CPUID function injects that bit based on the status of CR4. With Hypervisor.framework, we do not synchronize full CPU state often enough for this function to see the CR4 update before guest user space asks for it. To be on the save side, let's just always synchronize it when we receive a CPUID(1) request. That way we can set the bit with real confidence. Reported-by: Asad Ali Signed-off-by: Alexander Graf --- target/i386/hvf/hvf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 08b4adecd9..f660b829ac 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -426,6 +426,10 @@ int hvf_vcpu_exec(CPUState *cpu) uint32_t rcx =3D (uint32_t)rreg(cpu->hvf->fd, HV_X86_RCX); uint32_t rdx =3D (uint32_t)rreg(cpu->hvf->fd, HV_X86_RDX); =20 + if (rax =3D=3D 1) { + /* CPUID1.ecx.OSXSAVE needs to know CR4 */ + env->cr[4] =3D rvmcs(cpu->hvf->fd, VMCS_GUEST_CR4); + } cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx); =20 wreg(cpu->hvf->fd, HV_X86_RAX, rax); --=20 2.24.3 (Apple Git-128)