From nobody Mon Feb 9 11:06:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1692867501018765.4357389844727; Thu, 24 Aug 2023 01:58:21 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id B2FAD21447; Thu, 24 Aug 2023 08:58:16 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 15C3C208B9 for ; Thu, 24 Aug 2023 08:58:02 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517--UABpUiMPomgKqhkaaAKLg-1; Thu, 24 Aug 2023 04:57:58 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4523A2808B2F; Thu, 24 Aug 2023 08:57:58 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEE80140E91D; Thu, 24 Aug 2023 08:57:57 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id B1BEE1800627; Thu, 24 Aug 2023 10:57:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692867481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FejcfvmcyBS10KS1IwKQD1UjRIW+u81CbUOC29wnz6Q=; b=Qnv+dBxaXGl8U8DFOAkojdO5XIeeogXWexbH3b56AzEMn8Fd3Yk/kvD5ivHhDwIm6liDsy NffwfIsLxby4/34oExV1Qjlwir7u3Kz2FTspXvJ3dhOk7Vfiw3kM5XtEkAHDFZNTTpm5/j 6shstDakg4CXJlJOWRTs73hjYdGvifU= X-MC-Unique: -UABpUiMPomgKqhkaaAKLg-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 24 Aug 2023 10:57:51 +0200 Message-ID: <20230824085756.66732-2-kraxel@redhat.com> In-Reply-To: <20230824085756.66732-1-kraxel@redhat.com> References: <20230824085756.66732-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Level: ** Message-ID-Hash: HALHZLG3WVF73AQG4UITTCJONZDHDOMQ X-Message-ID-Hash: HALHZLG3WVF73AQG4UITTCJONZDHDOMQ X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: qemu-devel@nongnu.org, Gerd Hoffmann X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] [PATCH v4 1/6] better kvm detection List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: / X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1692867501564100001 Content-Type: text/plain; charset="utf-8" In case kvm emulates features of another hypervisor (for example hyperv) two VMM CPUID blocks will be present, one for the emulated hypervisor and one for kvm itself. This patch makes seabios loop over the VMM CPUID blocks to make sure it will properly detect kvm when multiple blocks are present. Signed-off-by: Gerd Hoffmann --- src/fw/paravirt.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index fba4e52db684..42abac8460c5 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -53,23 +53,35 @@ inline int qemu_cfg_dma_enabled(void) * should be used to determine that a VM is running under KVM. */ #define KVM_CPUID_SIGNATURE 0x40000000 +static unsigned int kvm_cpuid_base =3D 0; =20 static void kvm_detect(void) { + unsigned int i, max =3D 0; unsigned int eax, ebx, ecx, edx; char signature[13]; =20 - cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx); - memcpy(signature + 0, &ebx, 4); - memcpy(signature + 4, &ecx, 4); - memcpy(signature + 8, &edx, 4); - signature[12] =3D 0; + for (i =3D KVM_CPUID_SIGNATURE;; i +=3D 0x100) { + eax =3D 0; + cpuid(i, &eax, &ebx, &ecx, &edx); + if (eax < i) + break; + memcpy(signature + 0, &ebx, 4); + memcpy(signature + 4, &ecx, 4); + memcpy(signature + 8, &edx, 4); + signature[12] =3D 0; + dprintf(1, "cpuid 0x%x: eax %x, signature '%s'\n", i, eax, signatu= re); + if (strcmp(signature, "KVMKVMKVM") =3D=3D 0) { + kvm_cpuid_base =3D i; + max =3D eax; + } + } =20 - if (strcmp(signature, "KVMKVMKVM") =3D=3D 0) { + if (kvm_cpuid_base) { dprintf(1, "Running on KVM\n"); PlatformRunningOn |=3D PF_KVM; - if (eax >=3D KVM_CPUID_SIGNATURE + 0x10) { - cpuid(KVM_CPUID_SIGNATURE + 0x10, &eax, &ebx, &ecx, &edx); + if (max >=3D kvm_cpuid_base + 0x10) { + cpuid(kvm_cpuid_base + 0x10, &eax, &ebx, &ecx, &edx); dprintf(1, "kvm: have invtsc, freq %u kHz\n", eax); tsctimer_setfreq(eax, "invtsc"); } @@ -93,7 +105,7 @@ static void kvmclock_init(void) if (!runningOnKVM()) return; =20 - cpuid(KVM_CPUID_SIGNATURE + 0x01, &eax, &ebx, &ecx, &edx); + cpuid(kvm_cpuid_base + 0x01, &eax, &ebx, &ecx, &edx); if (eax & (1 << KVM_FEATURE_CLOCKSOURCE2)) msr =3D MSR_KVM_SYSTEM_TIME_NEW; else if (eax & (1 << KVM_FEATURE_CLOCKSOURCE)) --=20 2.41.0 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org