From nobody Sat Feb 7 22:21:03 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89A594879E for ; Wed, 28 Feb 2024 10:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709115527; cv=none; b=JwehL1CYvOKLXQI+x0U1FeZmhPlnqqqOZHGYNeatU6j/M7nKzlcBUp4GkUtF4EmD2dtRi2+LIbHMgqqXvaeeo+kpJl2Fr5YuoeiNiTDFx3OjZJ4y2opNBujznnHKOHz4iTFK1bM31aPXusLy2G7ic6wFOu+0/DIhVAjz88RDq4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709115527; c=relaxed/simple; bh=9GX/XMY+qWHH5f0/ts7l5PYv9fa6tTvpHvjq3I6ksOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Xkca4uKfs6cRskPgj3innd+HkDLidZMSQ5tQSK48W2P8eG+vAsZtX45y+To8pKvKt5J0viQJUdJBo+5K41mkewRHADq4WUxnA8h+/iahNeyLXZvF1SG8ym9dxToQ5JdUt1xLPoN/+3ZrbZYv8bYokfxGxNOZrGu+mlGWxNhUTJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BwyB4Wvd; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BwyB4Wvd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709115524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tru+vVOx4RxykInR0Cy5aul0KMpFDZJO5JqglFuDZAM=; b=BwyB4WvdtdzfJ3fgcbGkhXeyaSMs2evtNnkaQSnqPhGdge2VYkbTH6fIx5oU/juyByT+HU OYPjpjt0lCt+2/V6hi5uR4XYMqa5ZnmjsP4aHUpAzptdpM9LzGawKu9YZfEUMrFgKnOvz1 fg+1cdFqgi3mv46kl2nSOJ+4rwBAxX0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-0bEoAZwaNEu0p7SajveeqA-1; Wed, 28 Feb 2024 05:18:40 -0500 X-MC-Unique: 0bEoAZwaNEu0p7SajveeqA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A77F28AC1D3; Wed, 28 Feb 2024 10:18:40 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 999AD8177; Wed, 28 Feb 2024 10:18:39 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Li RongQing , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] KVM: x86: Introduce __kvm_get_hypervisor_cpuid() helper Date: Wed, 28 Feb 2024 11:18:35 +0100 Message-ID: <20240228101837.93642-2-vkuznets@redhat.com> In-Reply-To: <20240228101837.93642-1-vkuznets@redhat.com> References: <20240228101837.93642-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" Similar to kvm_find_kvm_cpuid_features()/__kvm_find_kvm_cpuid_features(), introduce a helper to search for the specific hypervisor signature in any struct kvm_cpuid_entry2 array, not only in vcpu->arch.cpuid_entries. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/cpuid.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index adba49afb5fe..0e1e3e5df6dd 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -189,15 +189,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcp= u, struct kvm_cpuid_entry2 return 0; } =20 -static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcp= u *vcpu, - const char *sig) +static struct kvm_hypervisor_cpuid __kvm_get_hypervisor_cpuid(struct kvm_c= puid_entry2 *entries, + int nent, const char *sig) { struct kvm_hypervisor_cpuid cpuid =3D {}; struct kvm_cpuid_entry2 *entry; u32 base; =20 for_each_possible_hypervisor_cpuid_base(base) { - entry =3D kvm_find_cpuid_entry(vcpu, base); + entry =3D cpuid_entry2_find(entries, nent, base, KVM_CPUID_INDEX_NOT_SIG= NIFICANT); =20 if (entry) { u32 signature[3]; @@ -217,6 +217,13 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_= cpuid(struct kvm_vcpu *vcp return cpuid; } =20 +static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcp= u *vcpu, + const char *sig) +{ + return __kvm_get_hypervisor_cpuid(vcpu->arch.cpuid_entries, + vcpu->arch.cpuid_nent, sig); +} + static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_v= cpu *vcpu, struct kvm_cpuid_entry2 *entries, int nent) { --=20 2.43.0 From nobody Sat Feb 7 22:21:03 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 711324F1F5 for ; Wed, 28 Feb 2024 10:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709115529; cv=none; b=F2XlvcE0s8L528/q/1AgoCd26uxv49gg3ZmNsY9DJ45iHL7yXZzWR9StAez2KnVMi24yMD/au+oC4afC43kwqwmfMrTnrzWstFQwQV7CzNXIqtl0rqUfScTBObk6xUkBFjttYVIcKE004LTCfXAbx5KHKkwiRUwQzO0gfUmu5jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709115529; c=relaxed/simple; bh=AFrt1azRX6F6xoU8LmSGEkM6KPcieGDLWHZpLZFggGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T0/PZjWmmcjhhNjqNVsMyEIjzXdvA5l4qtAoclcoKj3s9hhuYNXKDIGBnVCSdYYpsFri0kuXBLRLmOGCMVPtOefQ7tMtWq4iwcazFQGx8Ic9cuCDvbE4nHCrkIUOlyjq5a1Ch4+WSkPWpzfgPAZJWr6cSMf896C0XBqfOwsYWcg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ObDuppDF; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ObDuppDF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709115526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t/5jpa1XgBVWLxk01sM9mNbfC1AL5hF7JpXXB/j4JUM=; b=ObDuppDFJnNffluS8ysPt/7xJe020OVhvQ166TLdXnkSgmDNMJImkSqnCbrqeJh9xlFX+1 6e5Zt6WUzBzSvk4WUR4fx90siGWK5U+fJmHjLaDWQSVK9Rmm23pjggMF08vxvaLONpxF+b h8wK1VvNjCePp6vZKl+OanEjyfBT8TM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-W1AfAvOYOdWms_GIF-BClA-1; Wed, 28 Feb 2024 05:18:42 -0500 X-MC-Unique: W1AfAvOYOdWms_GIF-BClA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF6BA185A785; Wed, 28 Feb 2024 10:18:41 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id C75E58177; Wed, 28 Feb 2024 10:18:40 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Li RongQing , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] KVM: x86: Use actual kvm_cpuid.base for clearing KVM_FEATURE_PV_UNHALT Date: Wed, 28 Feb 2024 11:18:36 +0100 Message-ID: <20240228101837.93642-3-vkuznets@redhat.com> In-Reply-To: <20240228101837.93642-1-vkuznets@redhat.com> References: <20240228101837.93642-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" Commit ee3a5f9e3d9b ("KVM: x86: Do runtime CPUID update before updating vcpu->arch.cpuid_entries") moved tweaking of the supplied CPUID data earlier in kvm_set_cpuid() but __kvm_update_cpuid_runtime() actually uses 'vcpu->arch.kvm_cpuid' (though __kvm_find_kvm_cpuid_features()) which gets set later in kvm_set_cpuid(). In some cases, e.g. when kvm_set_cpuid() is called for the first time and 'vcpu->arch.kvm_cpuid' is clear, __kvm_find_kvm_cpuid_features() fails to find KVM PV feature entry and the logic which clears KVM_FEATURE_PV_UNHALT after enabling KVM_X86_DISABLE_EXITS_HLT does not work. The logic, introduced by the commit ee3a5f9e3d9b ("KVM: x86: Do runtime CPUID update before updating vcpu->arch.cpuid_entries") must stay: the supplied CPUID data is tweaked by KVM first (__kvm_update_cpuid_runtime()) and checked later (kvm_check_cpuid()) and the actual data (vcpu->arch.cpuid_*, vcpu->arch.kvm_cpuid, vcpu->arch.xen.cpuid,..) is only updated on success. Switch to searching for KVM_SIGNATURE in the supplied CPUID data to discover KVM PV feature entry instead of using stale 'vcpu->arch.kvm_cpuid'. While on it, drop pointless "&& (best->eax & (1 << KVM_FEATURE_PV_UNHALT)" check when clearing KVM_FEATURE_PV_UNHALT bit. Fixes: ee3a5f9e3d9b ("KVM: x86: Do runtime CPUID update before updating vcp= u->arch.cpuid_entries") Reported-and-tested-by: Li RongQing Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/cpuid.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 0e1e3e5df6dd..bfc0bfcb2bc6 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -224,22 +224,22 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor= _cpuid(struct kvm_vcpu *vcp vcpu->arch.cpuid_nent, sig); } =20 -static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_v= cpu *vcpu, - struct kvm_cpuid_entry2 *entries, int nent) +static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_c= puid_entry2 *entries, + int nent, u32 kvm_cpuid_base) { - u32 base =3D vcpu->arch.kvm_cpuid.base; - - if (!base) - return NULL; - - return cpuid_entry2_find(entries, nent, base | KVM_CPUID_FEATURES, + return cpuid_entry2_find(entries, nent, kvm_cpuid_base | KVM_CPUID_FEATUR= ES, KVM_CPUID_INDEX_NOT_SIGNIFICANT); } =20 static struct kvm_cpuid_entry2 *kvm_find_kvm_cpuid_features(struct kvm_vcp= u *vcpu) { - return __kvm_find_kvm_cpuid_features(vcpu, vcpu->arch.cpuid_entries, - vcpu->arch.cpuid_nent); + u32 base =3D vcpu->arch.kvm_cpuid.base; + + if (!base) + return NULL; + + return __kvm_find_kvm_cpuid_features(vcpu->arch.cpuid_entries, + vcpu->arch.cpuid_nent, base); } =20 void kvm_update_pv_runtime(struct kvm_vcpu *vcpu) @@ -273,6 +273,7 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcpu = *vcpu, struct kvm_cpuid_e int nent) { struct kvm_cpuid_entry2 *best; + struct kvm_hypervisor_cpuid kvm_cpuid; =20 best =3D cpuid_entry2_find(entries, nent, 1, KVM_CPUID_INDEX_NOT_SIGNIFIC= ANT); if (best) { @@ -299,10 +300,12 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcp= u *vcpu, struct kvm_cpuid_e cpuid_entry_has(best, X86_FEATURE_XSAVEC))) best->ebx =3D xstate_required_size(vcpu->arch.xcr0, true); =20 - best =3D __kvm_find_kvm_cpuid_features(vcpu, entries, nent); - if (kvm_hlt_in_guest(vcpu->kvm) && best && - (best->eax & (1 << KVM_FEATURE_PV_UNHALT))) - best->eax &=3D ~(1 << KVM_FEATURE_PV_UNHALT); + kvm_cpuid =3D __kvm_get_hypervisor_cpuid(entries, nent, KVM_SIGNATURE); + if (kvm_cpuid.base) { + best =3D __kvm_find_kvm_cpuid_features(entries, nent, kvm_cpuid.base); + if (kvm_hlt_in_guest(vcpu->kvm) && best) + best->eax &=3D ~(1 << KVM_FEATURE_PV_UNHALT); + } =20 if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) { best =3D cpuid_entry2_find(entries, nent, 0x1, KVM_CPUID_INDEX_NOT_SIGNI= FICANT); --=20 2.43.0 From nobody Sat Feb 7 22:21:03 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04E0B4C619 for ; Wed, 28 Feb 2024 10:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709115527; cv=none; b=MN544N4bqdvo71RIK7pUGdwCQKdyXH9agTVD5ssN1qeQdGIHdnUbDCCXwpRQBb5yTlZnbbMumMH6PFKmuvGrIcgJON/fly5+lp9OTZN3bXfYWJ8Vx2VdllqAG7M4BEUcpvGsosiju2vetWBtIIdqiq7sdkG7gKIRMt9klI6pKAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709115527; c=relaxed/simple; bh=MmAxZeXm6ySHX8QqZPQEg5xdtw2UlmdNm+MH9FdZFl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k2r9Qewge0bksyo16cU4XZxBs5Rip7HXVxuW5e5EnKdPMgBjX18W0fTdhUJuZmPaG9fSbQme+yt4f8Adb8HCzZ7K0sWY7yKKudGZuD+mmKEc4IaQKO7yWvzsSQTR2xbKjrlncC602xQSXUr41TavMyWSlCDPxIet2KJsX1cdleY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KY+YIkIj; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KY+YIkIj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709115524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=15m+OfdU4bOi0nHIjrNzMXNbHQ8G8Ha+jOqgfdqoMVA=; b=KY+YIkIjAMCCPva+rA/M7996UcrnvMPutW5pif2jYirw8k34VSwytLJGQsKi1RFlEejcUD qJ1FoiWrXZKJn/DdD4gZSYbYQQos5clEMFRiIY7rQhWfUHSvb8MDfZHAPvtG+TAfrHt6yt b04XEQy2+zG90puBa+oFyd0wTqV/X5c= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-UaQ4UnogOLe-SZLVay7y2w-1; Wed, 28 Feb 2024 05:18:43 -0500 X-MC-Unique: UaQ4UnogOLe-SZLVay7y2w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6B6F3C11A14; Wed, 28 Feb 2024 10:18:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 015D98177; Wed, 28 Feb 2024 10:18:41 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Li RongQing , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] KVM: selftests: Check that KVM_FEATURE_PV_UNHALT is cleared with KVM_X86_DISABLE_EXITS_HLT Date: Wed, 28 Feb 2024 11:18:37 +0100 Message-ID: <20240228101837.93642-4-vkuznets@redhat.com> In-Reply-To: <20240228101837.93642-1-vkuznets@redhat.com> References: <20240228101837.93642-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" KVM_FEATURE_PV_UNHALT is expected to get cleared from KVM PV feature CPUID data when KVM_X86_DISABLE_EXITS_HLT is enabled. Add the corresponding test to kvm_pv_test. Note, the newly added code doesn't actually test KVM_FEATURE_PV_UNHALT and KVM_X86_DISABLE_EXITS_HLT features. Signed-off-by: Vitaly Kuznetsov --- .../selftests/kvm/x86_64/kvm_pv_test.c | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c b/tools/testi= ng/selftests/kvm/x86_64/kvm_pv_test.c index 9e2879af7c20..60399454b45e 100644 --- a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c +++ b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c @@ -133,6 +133,46 @@ static void enter_guest(struct kvm_vcpu *vcpu) } } =20 +static void test_pv_unhalt(void) +{ + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + struct kvm_cpuid_entry2 *ent; + u32 kvm_sig_old; + + pr_info("testing KVM_FEATURE_PV_UNHALT\n"); + + TEST_REQUIRE(KVM_CAP_X86_DISABLE_EXITS); + + /* KVM_PV_UNHALT test */ + vm =3D vm_create_with_one_vcpu(&vcpu, guest_main); + vcpu_set_cpuid_feature(vcpu, X86_FEATURE_KVM_PV_UNHALT); + + ent =3D vcpu_get_cpuid_entry(vcpu, KVM_CPUID_FEATURES); + + TEST_ASSERT(ent->eax & (1 << KVM_FEATURE_PV_UNHALT), + "Enabling X86_FEATURE_KVM_PV_UNHALT had no effect"); + + /* Make sure KVM clears vcpu->arch.kvm_cpuid */ + ent =3D vcpu_get_cpuid_entry(vcpu, KVM_CPUID_SIGNATURE); + kvm_sig_old =3D ent->ebx; + ent->ebx =3D 0xdeadbeef; + vcpu_set_cpuid(vcpu); + + vm_enable_cap(vm, KVM_CAP_X86_DISABLE_EXITS, KVM_X86_DISABLE_EXITS_HLT); + ent =3D vcpu_get_cpuid_entry(vcpu, KVM_CPUID_SIGNATURE); + ent->ebx =3D kvm_sig_old; + vcpu_set_cpuid(vcpu); + ent =3D vcpu_get_cpuid_entry(vcpu, KVM_CPUID_FEATURES); + + TEST_ASSERT(!(ent->eax & (1 << KVM_FEATURE_PV_UNHALT)), + "KVM_FEATURE_PV_UNHALT is set with KVM_CAP_X86_DISABLE_EXITS"); + + /* FIXME: actually test KVM_FEATURE_PV_UNHALT feature */ + + kvm_vm_free(vm); +} + int main(void) { struct kvm_vcpu *vcpu; @@ -151,4 +191,6 @@ int main(void) =20 enter_guest(vcpu); kvm_vm_free(vm); + + test_pv_unhalt(); } --=20 2.43.0