From nobody Thu Feb 22 10:31:19 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TgTvX2Chrz5CMB2; Thu, 22 Feb 2024 10:31:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TgTvX0Y0Zz4kcw; Thu, 22 Feb 2024 10:31:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708597880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1op4LSRuMN5oboEiAxzC01fvvJaFwyxFIwfce+VSkuM=; b=sqHqhSCagEeJbHI2ROU2GY02GbHgE5FymH6s6pZYSZFOVclUqgXX7HMkYxFb5Ttdf08lFb rYtcIBpq81m8vtxpxSJnLT+5LrZEbbWbvoe1l0Dzepzjv1sS22NIbRSfzsGG0QM1MBF5ZR yzNOzC6CzlaWAqhjW0dWfFCaX5shRynKu4C0kPltvtAT5rekj8N3oEC6oH+ptfhCA0e//7 YPSdI3C6yYNd+ROtLkdMwKrzSaKDISLTAck3q8/sY0oMMKzVgBa5uiapBmideKn6Xaksq3 71EPcV8XZ62aMijfwdX1PYby+ScabdamtrWVl79HUnwiMjM6SU1o/gKglD525Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708597880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1op4LSRuMN5oboEiAxzC01fvvJaFwyxFIwfce+VSkuM=; b=U9AG6Ti+PAAyT7mEspR2gNPHG7FAl2CG0mxcnOB/7t/H23bQ33CeuAAxEINkZB1eb7VbPf 0kORVOCoVcpKouLw+auoweto7d3/kS6xPZvzvVRdsZrhYJcBh1lT/xxx/WF0afGt4VYojy lYqwIyZG96enrwdbOJJ+fqnmsVWDUZQKSGwjmkwGPzvVBBINJKokzxeIAorsveb11z3Tes ZI0xsA+A3HitcRpB5To9+a1VACoUjtN9FYHNUbEWf8jWVOt8R0fMNm6BtveALUM3CZkx6D MpN/G1VzvQoiAE8rvERFf3fhSzdtV40MXo+uM6x5MfG0Nt3SOFuOutHt/BzF4w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708597880; a=rsa-sha256; cv=none; b=xJmSI70Tq0fDf7EemlWUB5ReSC58v/IBjAA7QqXrTqxPYcAW6qU3bRBhlPSSZRTRaSxjrZ NlWEatDv7JAVmEPus67YaRp98ZbJdAzQhJG3RIB2nZA/RJy2zBiJmxaEZLVbepj5orNXh0 hYDCacB1XbJoDIpPynBfYByLtr1aAMl1BbMT1IAW3UZJ1XLSB1WfvdLdwc4SbFkBK5qy/k fySqY0+0nArMTcO/95gJQfN0VpoO6MDYa4iM3VxxwjNpFo5mRY+KvUmtul6lr4XFprk3Qw RQbBnU9Nyf2jezKeqXKPPNyugKM+lgd57gWCCeKWWOFpl18T8elxprjuNMw3Hw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TgTvW56P1zSb6; Thu, 22 Feb 2024 10:31:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41MAVJeR016634; Thu, 22 Feb 2024 10:31:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41MAVJuL016631; Thu, 22 Feb 2024 10:31:19 GMT (envelope-from git) Date: Thu, 22 Feb 2024 10:31:19 GMT Message-Id: <202402221031.41MAVJuL016631@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: 6744fd8e7503 - main - x86/cpu: improve hypervisor detection List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6744fd8e75032c893e6a80bced8be3a991fa2901 Auto-Submitted: auto-generated The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=6744fd8e75032c893e6a80bced8be3a991fa2901 commit 6744fd8e75032c893e6a80bced8be3a991fa2901 Author: Roger Pau MonnĂ© AuthorDate: 2024-01-19 09:15:17 +0000 Commit: Roger Pau MonnĂ© CommitDate: 2024-02-22 10:08:04 +0000 x86/cpu: improve hypervisor detection Some hypervisors can expose multiple signatures, for example Xen will expose both the Xen and the HyperV signatures if Viridian extensions are enabled for the guest. Presence of multiple signatures is currently not handled by FreeBSD, that will exit once a known signature is found in cpuid output. Exposing the HyperV signature on hypervisors different than HyperV is not uncommon, this is done so that such hypervisor can expose a (subset) of the Viridian extensions to Windows guests for performance reasons. Likely for compatibility purposes the HyperV signature is always exposed on the first leaf, and the Xen signature is exposed in the secondary leaf. Fix the specific case of HyperV by not exiting from the scan if the HyperV signature is found, and prefer a second signature if one is found. Note that long term we might wish to convert vm_guest into a bitmap, so that it can signal detection of multiple hypervisor interfaces. Fixes: b0165dc4539f ('x86/xen: fix HVM guest hypercall page setup') PR: 276421 Sponsored by: Cloud Software Group Reviewed by: markj kib Differential revision: https://reviews.freebsd.org/D43508 --- sys/x86/x86/identcpu.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c index 9c82f9f8a882..df24c5bddffd 100644 --- a/sys/x86/x86/identcpu.c +++ b/sys/x86/x86/identcpu.c @@ -1385,6 +1385,8 @@ identify_hypervisor_cpuid_base(void) regs[0] = leaf + 1; if (regs[0] >= leaf) { + enum VM_GUEST prev_vm_guest = vm_guest; + for (i = 0; i < nitems(vm_cpuids); i++) if (strncmp((const char *)®s[1], vm_cpuids[i].vm_cpuid, 12) == 0) { @@ -1397,7 +1399,7 @@ identify_hypervisor_cpuid_base(void) * specific hypervisor, record the base, high value, * and vendor identifier. */ - if (vm_guest != VM_GUEST_VM || leaf == 0x40000000) { + if (vm_guest != prev_vm_guest || leaf == 0x40000000) { hv_base = leaf; hv_high = regs[0]; ((u_int *)&hv_vendor)[0] = regs[1]; @@ -1409,7 +1411,18 @@ identify_hypervisor_cpuid_base(void) * If we found a specific hypervisor, then * we are finished. */ - if (vm_guest != VM_GUEST_VM) + if (vm_guest != VM_GUEST_VM && + /* + * Xen and other hypervisors can expose the + * HyperV signature in addition to the + * native one in order to support Viridian + * extensions for Windows guests. + * + * Do the full cpuid scan if HyperV is + * detected, as the native hypervisor is + * preferred. + */ + vm_guest != VM_GUEST_HV) return; } }