Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp870317rdb; Fri, 23 Feb 2024 02:42:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWs1YYJWTyeAUm82Kw7MgV3faJfKspnQAGtFWf016BqcCd8WbJKLZLiqCf0tLnzqhLauvhsTWyWveiV/vP4lzwrXcRLB1e2wYXDyTKNjQ== X-Google-Smtp-Source: AGHT+IEr4T1aemDE28V0rsGKCC13TKDSNIdKk1FXn4K7z9IZjWwBT7weBYOEKnimk2byVRrSUOaW X-Received: by 2002:a17:902:9a08:b0:1d9:b8cf:779 with SMTP id v8-20020a1709029a0800b001d9b8cf0779mr1339351plp.33.1708684955950; Fri, 23 Feb 2024 02:42:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708684955; cv=pass; d=google.com; s=arc-20160816; b=O9vkQaBo5rzXQO/Kt1X/0VSThdA26ArDa1AUknJeykM4jts1+FAxU1QFUEtvv0eEsr C9gk89ZNNDFXIhWsQAZf6ag1xP1nXqRMlPfdF+3VcFw0k7KgYywYoHrPy3+m30ZbEibm FD8je9pt/Tf1+9KiumtKqaTPeqESAzumzWZ1zS4jZg4sO6msizw/gmVxTJF9v+0cKe7L D/TzxNhM+yE0ZWzx66IYy5Wq8M3746znRJNq+Y8nCw7Cx78Cfl1WMjf3sWRWDy0xDvFR fihwuW6eE20cBDm/RgYdV712VeK4cmNJCzQlKNYiiMIv48JzwFkUFzrVJJK5KazFrPyq 0kkg== 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=P+nR0TAnkSpDrfkTZplFwZ3L3OjoWb5NbbRwlVY9jbI=; fh=TLdZJsFzSA0fpm6Q4iUv+uB0sG0oU+h3Bp6HiSGyZm8=; b=UsF9MVu+dmx2WNKjnyZYq7rQBeD1JZ3XWR4guV3DHp8VOqUU43AfEcftUggyxrSzFh rU+KL1OtQDt95HhA1GmnsGvM9PVDElkdCY6IO9z/cIh6DG4ckZZdukz+AxIhkKHvzbL8 HXX0m3fdOIsC28G/5nqiTHmIE4qkhwegIbZY+xCCPx9BIYoyQcaFkEXOozjY/AnLgNdP PCN53hqDAl/dXlBCPqUzR9VJsO0ewzW6VQ/vxgVnFQnU1v97RpTgxjhqrNXHBE4baHy0 4isyBVGx3tr27qx72HdKUlHmCPQV6T1SZxXBpuOn6VSGAk56JVVf6hKgtw0mjAMHtump sXrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VKWapa0I; 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-78162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78162-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 m17-20020a170902f65100b001dc5ae92980si2244888plg.107.2024.02.23.02.42.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:42:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78162-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=VKWapa0I; 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-78162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78162-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 7F4082876B4 for ; Fri, 23 Feb 2024 10:42:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13FEC7E105; Fri, 23 Feb 2024 10:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VKWapa0I" 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 787486280B for ; Fri, 23 Feb 2024 10:40:18 +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=1708684820; cv=none; b=CXJXIGwJtGi7BEIBJMH75hdAjziD5F0wxfKuFB5w6zrlglk0G6jBul+AUlV4i0WLWpMibc7rV9SIuIUPp3nEdEQI/QQu7BJqOvME+zZe5DqrT4PprXm9Z6xqfKG600X+Eqag4JTwO68B7OMD0bZZDp8SwwJFz61IHOUPaLyCZ9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708684820; c=relaxed/simple; bh=yJOTF4Fo3Zuv/OxFDFVsXOE/9tKTgWyjyBG3UlU2g6g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=jjIsWJF4iJ34n2z0xPrYeEu30YRwoIc1wCfa2zZo1xxdhpZ0CmjxTjqg50gLsCRw+/ZxGkH7GqsxiOTzaAcPto7nSTDpHoqTgagZ+fOYGk5aX68Tmz4BBZMdTTbZb0ycSlYmRRe799CN0EWbdcGi3zyVDmpYYYJlwYxE3IklC5Y= 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=VKWapa0I; 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=1708684816; 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=P+nR0TAnkSpDrfkTZplFwZ3L3OjoWb5NbbRwlVY9jbI=; b=VKWapa0I6y/e767b6CDMA97799tUOi7Gr0b22TLI6UoG9PrtPmvfxysKjEDITEqhKqiTcl FMpqfH9aEWTXUK1s0jp768IIEhCG9MAFBNLO0YBNdFvnouFDXUloOC/g8cqy7q3Y4sLeRA 1SCmav9pzlk+to1H2Gvt/cNIApolytc= 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-56-C_SQYLXlNTCSs8ELV03X0g-1; Fri, 23 Feb 2024 05:40:12 -0500 X-MC-Unique: C_SQYLXlNTCSs8ELV03X0g-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 F3539185A781; Fri, 23 Feb 2024 10:40:11 +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 CC3C3112132A; Fri, 23 Feb 2024 10:40:11 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, michael.roth@amd.com, aik@amd.com Subject: [PATCH v2 08/11] KVM: x86: Add is_vm_type_supported callback Date: Fri, 23 Feb 2024 05:40:06 -0500 Message-Id: <20240223104009.632194-9-pbonzini@redhat.com> In-Reply-To: <20240223104009.632194-1-pbonzini@redhat.com> References: <20240223104009.632194-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 Allow the backend to specify which VM types are supported. Based on a patch by Isaku Yamahata . Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index ac8b7614e79d..8694a6e3d012 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -20,6 +20,7 @@ KVM_X86_OP(hardware_disable) KVM_X86_OP(hardware_unsetup) KVM_X86_OP(has_emulated_msr) KVM_X86_OP(vcpu_after_set_cpuid) +KVM_X86_OP_OPTIONAL_RET0(is_vm_type_supported) KVM_X86_OP(vm_init) KVM_X86_OP_OPTIONAL(vm_destroy) KVM_X86_OP_OPTIONAL_RET0(vcpu_precreate) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 15db2697863c..9cf588db55e9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1601,6 +1601,7 @@ struct kvm_x86_ops { bool (*has_emulated_msr)(struct kvm *kvm, u32 index); void (*vcpu_after_set_cpuid)(struct kvm_vcpu *vcpu); + bool (*is_vm_type_supported)(unsigned long vm_type); unsigned int vm_size; int (*vm_init)(struct kvm *kvm); void (*vm_destroy)(struct kvm *kvm); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e634e5b67516..d4029053b6d8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4581,13 +4581,19 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu, } #endif -static bool kvm_is_vm_type_supported(unsigned long type) +static inline 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_enabled); } +static bool kvm_is_vm_type_supported(unsigned long type) +{ + return __kvm_is_vm_type_supported(type) || + static_call(kvm_x86_is_vm_type_supported)(type); +} + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) { int r = 0; -- 2.39.1