Received: by 2002:ab2:2441:0:b0:1f3:1f8c:d0c6 with SMTP id k1csp236830lqe; Thu, 4 Apr 2024 05:29:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXH9+BupAZUXuk/2Sjp+41NNK8t5hjMPHf6yzvFDBurxxlT1Sq4OGOrE9L8HLAfBvhBnG/7v212oERdPH916VOpieY3Q4WY739S0lxq5A== X-Google-Smtp-Source: AGHT+IE14ks5yoGsEUdNATsJkXDKI1af9PU7Muz7vhY+HsEh8AqB83ugFb7AQPOfVrv67q1j4mQh X-Received: by 2002:a05:6870:c087:b0:220:8b8f:fc4d with SMTP id c7-20020a056870c08700b002208b8ffc4dmr2202967oad.39.1712233751213; Thu, 04 Apr 2024 05:29:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712233751; cv=pass; d=google.com; s=arc-20160816; b=mNPmyjiey9g+rzJIqJELv4nl63j9Od6w698A1H5lJ88IjsEVFdyWxj7rWwVK1dWw99 S5VQh+09HSMfc+0t66bgqJQ5iPwg/O8F7XSyK3wbVSi2+kV4xtqNyhbuT7qX8EBNUGwS qW/kZpjF3CpGgJdjp1APdD8b7UoHqsGPiGWlHSV69r1bztFI/GYk1dTDKYUyI4mz6WLk gkcFI56ObWGNiWEFkdzSFtCspHzKEt4KGBBC5GOFujmPLvTkuI1SNHO6PWyAJN6brbHX +26We8QevWfAje/dMlfOPMG+YMvLR+pIC1cU0ZbHtlo0LYHzsPmNOvJJI1LZj84mAqEF 50Wg== 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=G7WfOyCefJ4HRsnQAIdCxLgpQluq9aXquGfyKJWIFH0=; fh=4Mmgzbvh2cxmG/a9fVV/qttPj1jg++Mn8vNrcYlcRQg=; b=ycNTgjw6mxDVC2FMjJKPAth0KiusP+nur5IFFPo8RnGB/TJg1octzK1MFOBw7locUT z14+JeHRsC+91bPJupM5dFhVPM5nnHhaNN3H9q/bAQMVPxvV1vtB4mKSIAksAXe6fMOq x/K2ntwVWJ4xFNrBAEMC/VYoELEKt33HmuCSYyTV8lMb/scFYugp6IeQLo+XVJ3MALdR AOQ2iHQwjZOnkR4vgqBbW82G7Ak4ied67gRXlEtLX7ecYsNiDq1f1qlRiON5Xx/5ptX+ cgFbTqM0wmOZWLSjFRpWtOSkhOaeouNwogHTaBh2XMIV3hgsG0g8ZVq8xu3oYT1LWqXk odpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QcNVHtX+; 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-131386-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131386-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q24-20020a63d618000000b005f056691192si14949797pgg.528.2024.04.04.05.29.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 05:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131386-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QcNVHtX+; 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-131386-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131386-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 60CE9292FA2 for ; Thu, 4 Apr 2024 12:16:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3154D12D76E; Thu, 4 Apr 2024 12:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QcNVHtX+" 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 33120126F14 for ; Thu, 4 Apr 2024 12:13:34 +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=1712232819; cv=none; b=dxT+VFLRF2ELOa5pDtSS/RjG/rNRyLNreaMaOP9Qgk1x3JI6o59w1zNi1TJMsaw5pzblZ70pdEpxTBNmIi/6gypNgs9wfpiQw8MNMOlSUDyneAuxnACffaUbXs41NPk95jGTHDm9pZYniN+I01BL3HRGLF3rC8xXw6Jt3PUYtF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712232819; c=relaxed/simple; bh=fmUZOuLIrNu+zmJL+kpswOO2yDQ/2D3x/RlfcYh/Jbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s/4vuPZLI7bP2ESU4RqSaMbHEU2NTqScak5NhEMKBnAPSwJAm3u+lYwhJ7KTUYeJwqE6WYrsXi0al0+6UrR1uIa38MJxXmvo6p/MrBmNPzYrgMb/B5DL9BCK/BNmxv5y6GOEJPBw3KfBoCNoB3RoiDhmN5MgoyKH2znik4Jj79Q= 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=QcNVHtX+; 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=1712232814; 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=G7WfOyCefJ4HRsnQAIdCxLgpQluq9aXquGfyKJWIFH0=; b=QcNVHtX+dpCbQ5fVteZtBN50LYyF0S7CEjyBZikMt9uOGmyB6t8K16J8ruDz5LqH2k4UEB M6RnKwFotqCEmmp/rfLMW9roErpFMdV9V0EYSK1+CBfrJ9RPPNgJZVAfSoDVgrkKeqAf9m I4EvtWH1Ft3zki3fFoqWtYeC+TwqgkU= 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-624-xyzl1CA5NAGcIfKAiYFC1Q-1; Thu, 04 Apr 2024 08:13:30 -0400 X-MC-Unique: xyzl1CA5NAGcIfKAiYFC1Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 E253684FA95; Thu, 4 Apr 2024 12:13:29 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB99D2024517; Thu, 4 Apr 2024 12:13:29 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: michael.roth@amd.com, isaku.yamahata@intel.com, Sean Christopherson Subject: [PATCH v5 08/17] KVM: x86: Add supported_vm_types to kvm_caps Date: Thu, 4 Apr 2024 08:13:18 -0400 Message-ID: <20240404121327.3107131-9-pbonzini@redhat.com> In-Reply-To: <20240404121327.3107131-1-pbonzini@redhat.com> References: <20240404121327.3107131-1-pbonzini@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.4 This simplifies the implementation of KVM_CHECK_EXTENSION(KVM_CAP_VM_TYPES), and also allows the vendor module to specify which VM types are supported. Suggested-by: Sean Christopherson Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 12 ++++++------ arch/x86/kvm/x86.h | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d4a8d896798f..d584f5739402 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -94,6 +94,7 @@ struct kvm_caps kvm_caps __read_mostly = { .supported_mce_cap = MCG_CTL_P | MCG_SER_P, + .supported_vm_types = BIT(KVM_X86_DEFAULT_VM), }; EXPORT_SYMBOL_GPL(kvm_caps); @@ -4629,9 +4630,7 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu, static bool kvm_is_vm_type_supported(unsigned long type) { - return type == KVM_X86_DEFAULT_VM || - (type == KVM_X86_SW_PROTECTED_VM && - IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled); + return type < 32 && (kvm_caps.supported_vm_types & BIT(type)); } int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) @@ -4832,9 +4831,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r = kvm_caps.has_notify_vmexit; break; case KVM_CAP_VM_TYPES: - r = BIT(KVM_X86_DEFAULT_VM); - if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM)) - r |= BIT(KVM_X86_SW_PROTECTED_VM); + r = kvm_caps.supported_vm_types; break; default: break; @@ -9824,6 +9821,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) kvm_register_perf_callbacks(ops->handle_intel_pt_intr); + if (IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled) + kvm_caps.supported_vm_types |= BIT(KVM_X86_SW_PROTECTED_VM); + if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES)) kvm_caps.supported_xss = 0; diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index a8b71803777b..d80a4c6b5a38 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -24,6 +24,8 @@ struct kvm_caps { bool has_bus_lock_exit; /* notify VM exit supported? */ bool has_notify_vmexit; + /* bit mask of VM types */ + u32 supported_vm_types; u64 supported_mce_cap; u64 supported_xcr0; -- 2.43.0