Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2456394rbb; Wed, 28 Feb 2024 02:19:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUGac8fER5uMz48trfE8xyZoQZjlvuqBwKUY9huY802jYZ6Lj8hG5A2vC9Lt1Rxq+QpYELcc9smLZFtcsuFFyh1N99Kh3e0WK76ihBlaA== X-Google-Smtp-Source: AGHT+IE2poB3jbtI62cB+YCFvjrKd+uw0Sgcsr3naJwINNXldXeWAoEcZuCkXaa9b5IOvOCXW6SI X-Received: by 2002:a05:6402:2059:b0:565:5de9:719b with SMTP id bc25-20020a056402205900b005655de9719bmr9035718edb.25.1709115557774; Wed, 28 Feb 2024 02:19:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709115557; cv=pass; d=google.com; s=arc-20160816; b=UpkBJ8jDLWkNZWZBhtPqEOwAaW0nmCim392CfZuIJoSMXgmzn/ffDBnMm6sZ6QftyA v/PZx0x3BH8aXT9hG7NdFyu9oFXpbcEEAXf+3OrbFRARDWLqKxh8OIF8SxMmv9Is16OB dcKf0G8XukHkexATLgU29s07YXJEoL76aUC9tWAIlcJhyqAs2EizFXR88yVDaIcJll4O pcMHqoD1ts9tfjUfFijQwU7qn45OPpXAjr8gNGdzwQfr5daeiwH5l7wntnWWFC43R5ST mNwQY5Vo/k9IOJHrcbSv2J4LP/ey0+0vpyvmZIPbkheNoQYCibThAUkQSLd+UhpnVYHI knZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=15m+OfdU4bOi0nHIjrNzMXNbHQ8G8Ha+jOqgfdqoMVA=; fh=g5Cow6OuIakVpuXVBF5ZX8XYeT6H+v/9YFSb9jK60ps=; b=In7Y6hWAvY+nVH72oc68K4krOeqZ18NbSVkUmkJb24e2ug64JuaXXGLTmxcV2EtSXP B8h7T0xBjok2NYJ8+/mpp4JBM0jTEoMxa+DGK7ZBM1JjL/Vc5r+b6Yk1kn4aYHHXlAMa 47EZpg6zigO0zNDvFjkaD8VNflBavifO1UpmojT8PonYBlFZLf20ZSXGj0nokSYaFO2K /zu5z2wf466rP/nUSEeyAnPitB8jUunS/DIWT79pz4gvytBPOgx0n+H0whtU3nu5g2T+ TmGR8N6XdnVNHNM1AVlr0t7M6x6AxxR0BPTK/lWfYJdFUqh2Pms5uRx9Z8gZ3HlHTzJ1 wOyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KY+YIkIj; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-84824-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84824-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d21-20020a50f695000000b00565aefa1e0fsi1622245edn.515.2024.02.28.02.19.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 02:19:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84824-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KY+YIkIj; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-84824-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84824-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7FFE91F23A70 for ; Wed, 28 Feb 2024 10:19:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D46150A6C; Wed, 28 Feb 2024 10:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KY+YIkIj" 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 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-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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/testing/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) } } +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 = vm_create_with_one_vcpu(&vcpu, guest_main); + vcpu_set_cpuid_feature(vcpu, X86_FEATURE_KVM_PV_UNHALT); + + ent = 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 = vcpu_get_cpuid_entry(vcpu, KVM_CPUID_SIGNATURE); + kvm_sig_old = ent->ebx; + ent->ebx = 0xdeadbeef; + vcpu_set_cpuid(vcpu); + + vm_enable_cap(vm, KVM_CAP_X86_DISABLE_EXITS, KVM_X86_DISABLE_EXITS_HLT); + ent = vcpu_get_cpuid_entry(vcpu, KVM_CPUID_SIGNATURE); + ent->ebx = kvm_sig_old; + vcpu_set_cpuid(vcpu); + ent = 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) enter_guest(vcpu); kvm_vm_free(vm); + + test_pv_unhalt(); } -- 2.43.0