Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp552291lqt; Mon, 18 Mar 2024 16:36:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVH2Qzfr9Q5wunGPsSLVMSrK/R87gic1ahiVaHEIL5cdcJVaC00RbWB82fUwmOQ43DaG9bcCFy2YMiUAnq3y1lg7gl47AN3VreufRHkJQ== X-Google-Smtp-Source: AGHT+IGURNOy87UIVU6sfrgu3BI8ur4X1bjb9sYk4AUiSPwFGEadfrkiW4T4FmoDkD6bmwM4fPYG X-Received: by 2002:a05:620a:4d03:b0:789:ea5c:4dd6 with SMTP id wa3-20020a05620a4d0300b00789ea5c4dd6mr1228773qkn.6.1710805018643; Mon, 18 Mar 2024 16:36:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710805018; cv=pass; d=google.com; s=arc-20160816; b=wvi94heXPlsxZ97clTJmRBaU95vbRl7rPKlyfJPVGZeSqEwdSpJN+FaC0vAe0ebC3o 2u/IMovoASZXjx1TsTzXharXiWDY2bftmiqcYDUhZG9UH8vX+q646LNcK+uJ23j6dyhG xuOmjtVjBwJO30CuRndis0th+3SJZeq7CwaO0VuLoVPHdKDQy9VxloWI8VEsyQWxkFtK xix2f4WvzRC/aDBed0xpRn8C70wFnXskkUE8RH5FIQ0TXbzF6XG9KJLdLGokXoD+zu9/ 1AgkruU8INefbXLWwFPQZ3oSNkERJCMrNr3fO+1ICUSJjRrVmWdPDLsa1l7PM2Ptg70n njkg== 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=3akqZgNcQZFd1TqSeRZMm8OcjnakqT/fyGcLLrf83Kc=; fh=3hAI0TnvvweyuafrDQR9sJAViJ87fw+qG0excEgpXGk=; b=wFaccDAxv7E0+OSBc9fRVbjtY01ibgrprQp84JG7d7822RU/opRExDF6+DwzVluOyx VrW2CfEjIioWsjm8HhPxeVibegKWCasrx/uxIv0Ggi1z4IynvaBMV/ij/zJH5qdMFR8o x/D1Mk4JYOJaVWg+TpA3nVLMmwfqDpi4yZkBBTT4wI02M/G57Y7JexLvBqKMnGnuU5Oh 7v93/3g9W9AClkPTlIgkaxCu8iQ3BVwsh36zCZRReEz23GH6TI0LglEHqlGj5pVRsJn8 Rohy05x/bRCwJ5Vn3aArFOl1/7q6Yxu0znVL8EZjZIn2KnfoepA2ufRnG6Of7RpJpV9b RC8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZSwnzP6j; 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-106814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g20-20020a05620a40d400b00789e8f2219csi7744635qko.318.2024.03.18.16.36.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 16:36:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZSwnzP6j; 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-106814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106814-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 502851C213CB for ; Mon, 18 Mar 2024 23:36:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5217B60BB7; Mon, 18 Mar 2024 23:34:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZSwnzP6j" 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 DE8FC5FBA5 for ; Mon, 18 Mar 2024 23:34:01 +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=1710804844; cv=none; b=GV8fR78XjpT6zHtvYyvkPbE5LVoEU6xZB+OYlpu2frsPJhhSlxkT2JnFjahN5Lt1uHAbEDTxjL9bBsG/FEIKj8t6Y5ZsTSxqeWouRxn1U98wkL/cYvwLJPuaKEao9dDF8h50ETOdHwELK1kZR3a0/PV9pU1L26UyLQa9psjhytc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710804844; c=relaxed/simple; bh=/h8SqmURALLDyuGUX7H2nBueG9nOdv0SX3aEOGmrKSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZKMTRUzXDkFOYaIPaKPnvQpSbdvZyWhOQGhxqvt7kDzhlXaDeKInPFRG0gm1a2OqnIDQiJ/xPLsAQ8FwYJMlTQ730l2L4D20DgpPYCHMIQ2KeSmW1QBYqWpQE5u6dpmx8V9giFUPJRm+6cC7AxN/XRIAU8R/FVwv8lYjgIO8rAU= 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=ZSwnzP6j; 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=1710804840; 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=3akqZgNcQZFd1TqSeRZMm8OcjnakqT/fyGcLLrf83Kc=; b=ZSwnzP6jMADZP2dbyG10DTjKEPzBGvAZROEpTaIjzR1zJ0LLQ2AwOwVdmLUyNL+sUbcfKG 6z6vyvosG3DrxAerGG993zss49kBbT0CD1t8sUF/wDVNICDa66p4BIWHtGqVMpT8Uh4DQa Omo12IYFi1+hEVq+N0gdxhrYiGf3RMo= 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-12-7FSHSY0bP1OxNxIsfqICHA-1; Mon, 18 Mar 2024 19:33:55 -0400 X-MC-Unique: 7FSHSY0bP1OxNxIsfqICHA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 6B45885A58C; Mon, 18 Mar 2024 23:33:55 +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 44BF11121312; Mon, 18 Mar 2024 23:33:55 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: michael.roth@amd.com, isaku.yamahata@intel.com, seanjc@google.com Subject: [PATCH v4 08/15] KVM: x86: Add supported_vm_types to kvm_caps Date: Mon, 18 Mar 2024 19:33:45 -0400 Message-ID: <20240318233352.2728327-9-pbonzini@redhat.com> In-Reply-To: <20240318233352.2728327-1-pbonzini@redhat.com> References: <20240318233352.2728327-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.3 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 98b7979b4698..8c56bcf3feb7 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; @@ -9829,6 +9826,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