From owner-svn-src-all@freebsd.org Fri Mar 23 22:36:25 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A4644F5133A; Fri, 23 Mar 2018 22:36:25 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5A2A6685F3; Fri, 23 Mar 2018 22:36:25 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 50DEA260CC; Fri, 23 Mar 2018 22:36:25 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2NMaPuJ088066; Fri, 23 Mar 2018 22:36:25 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2NMaP8f088065; Fri, 23 Mar 2018 22:36:25 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201803232236.w2NMaP8f088065@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Fri, 23 Mar 2018 22:36:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331466 - head/sys/x86/x86 X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/sys/x86/x86 X-SVN-Commit-Revision: 331466 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Mar 2018 22:36:25 -0000 Author: jhb Date: Fri Mar 23 22:36:24 2018 New Revision: 331466 URL: https://svnweb.freebsd.org/changeset/base/331466 Log: Add a workaround to the hypervisor detection for older versions of KVM. Originally KVM set %eax to 0 in the cpuid leaf 0x4000000 rather than to the highest supported leaf in the hypervisor "branch". Detect this case and fixup the %eax value so that the hypervisor is still detected. Reported by: jpaetzel Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D14810 Modified: head/sys/x86/x86/identcpu.c Modified: head/sys/x86/x86/identcpu.c ============================================================================== --- head/sys/x86/x86/identcpu.c Fri Mar 23 21:06:06 2018 (r331465) +++ head/sys/x86/x86/identcpu.c Fri Mar 23 22:36:24 2018 (r331466) @@ -1304,6 +1304,18 @@ identify_hypervisor(void) if (cpu_feature2 & CPUID2_HV) { vm_guest = VM_GUEST_VM; do_cpuid(0x40000000, regs); + + /* + * KVM from Linux kernels prior to commit + * 57c22e5f35aa4b9b2fe11f73f3e62bbf9ef36190 set %eax + * to 0 rather than a valid hv_high value. Check for + * the KVM signature bytes and fixup %eax to the + * highest supported leaf in that case. + */ + if (regs[0] == 0 && regs[1] == 0x4b4d564b && + regs[2] == 0x564b4d56 && regs[3] == 0x0000004d) + regs[0] = 0x40000001; + if (regs[0] >= 0x40000000) { hv_high = regs[0]; ((u_int *)&hv_vendor)[0] = regs[1];