From patchwork Fri Feb 23 10:40:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 205298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp500304dyb; Fri, 23 Feb 2024 02:43:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWAwvpCGvdZuwuAPd/JTuskV7+uFxWJfQkjVUu63q6+yfbLt3RrS6NcVkuIygSuLb1mJljyg5y+F9ICbpRSlI2PgBkxeg== X-Google-Smtp-Source: AGHT+IHZDxgZ6+fkY4EAtTUd4npRWnkMxbVJsFi0XQEGmSxnMKUkzkaibuzDIO4A8WmOp3wFN1S9 X-Received: by 2002:aa7:d44c:0:b0:564:ae07:e539 with SMTP id q12-20020aa7d44c000000b00564ae07e539mr909087edr.25.1708685039753; Fri, 23 Feb 2024 02:43:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708685039; cv=pass; d=google.com; s=arc-20160816; b=WnBI8SGs5eObocsT2ZwhyZ303Own0BAXMaYefpt5QLhp4Cp6YZ3YRT2bllyQejtHMS 5pMP2mOOkDDNjSxnziwz+UsXGfipS7egRjvscmhxiB8K+S3yLS5Z4ywmrEpWDxSdqSKj h80ysH5bh5XdXEpzFAfnWLjMHu6A/vsAcGuO8eKxXwnqY4G8u2GqltQYK57ygg97r3MG V6snQjNCiWQe5RFSZbbVtgOjhO7bwoYpDVkteWzxmzmki6skn7E8Mf3FH0DOr3wzDTCf 9ZJ3ScerwTXzD8EWOC9v4bvpV2kQSCqHU3oOQGVJxhQYwLPJqvEBZrt3nSS19G9l+dr4 /QPA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78162-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x19-20020a05640226d300b0056447ebd7afsi5390149edd.1.2024.02.23.02.43.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:43:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78162-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78162-ouuuleilei=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 5FEE81F218F3 for ; Fri, 23 Feb 2024 10:43:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C28BA6312D; Fri, 23 Feb 2024 10:40:24 +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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791686124431602649 X-GMAIL-MSGID: 1791686124431602649 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;