Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1114704rdb; Fri, 9 Feb 2024 10:38:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVLBusevRmmoRN3VI6U9SQAdUO4GMi9p32852NCYDqnHARTuOHkIzkPkJ9lm9lmk6WaZruKvkt4SMOLgY0l7zugK+qBHzwecqRaLSbn/w== X-Google-Smtp-Source: AGHT+IGlJBioEy0JGuC51eYhrq//5cEeWsEOZ8pYJcBrhcFPv4l8qh+E/tbqC827nTLhVIURnxzF X-Received: by 2002:a05:6102:d86:b0:46d:6587:4bf0 with SMTP id d6-20020a0561020d8600b0046d65874bf0mr227308vst.20.1707503892505; Fri, 09 Feb 2024 10:38:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707503892; cv=pass; d=google.com; s=arc-20160816; b=xLDRNlobwE0NdQkR0ipPBKXbSZ7LFhRfA8KDm+3MAutZ0IifOe376gUaiy1gVAMtDm 1lMq2BGagAVNOVUKNkB2M3H9YYULFNhMf4twj2TgoH2phsz8Wek45aVy4eLROY8pXon/ 5HS9KtuIruWfb9eYnT/BpJJAi32TNq9iONvYs8PATWhdzqR1+2g5E9ahSomMX8gd0vFb Os97VW6l/Z51gBt8vOpiuATbE/gfoe2sBLzu7ooDfjY6W2zlViXSQXfOdUY6DHceOzV6 EQFzzXzOfIFp/GfQWbOLbKg5mxmeorhzYgTRqr7wFcXgvXF9fGKHASXQppt5fDctDIno geLQ== 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=2Yb42C16zvNs4Qe81/RZYCFLU8QdYJlCRgHBvvhE+xE=; fh=+bMF/mgQp0sjubTirkdoq8WPzL9WEa3aPH+TFwaH1dI=; b=Rs9i3FiK3NqDyj/vfau5WWnxu9NOueHjy68IIhr+bzZiQQUT3g0RERgBfgMBAGfU7+ fFFTdFcerHIogSihBdj+/sCXO72HFq1Hkynq6QBR468WCguJNURrSfYGvIVu/rgkM2cL Zs3iGHTjmrJRFhZibY6ARCZUhXasoKz7t09lfcUQf+4suyvnTxugw2m4eEtkoQ7btSCq FH0uHbmd0RQbRHey5zH9v44N0nxqg8HT2jp6BKwRcwCusaCGeW/DHf/ImbexqCXg4UAs YSxcZhYJdTVDefKsrsBSkW5sEMq0ru1P1WCoiy0FrjyeUyTPYzwdl7oC7sTVI+rKEdyK mNMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ANLFcA20; 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-59808-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59808-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCUxkLzd8/35XzflFjyPCiePp1DdAvedBmAXIKEKgyEH+mQvBwRFfLsIPZlPjfwDI2R4I7hSika4zRiS5QRjua2lMcT4ZKxKuVe/LaGpuw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id iw6-20020a0562140f2600b0068cdaa25d03si869791qvb.168.2024.02.09.10.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 10:38:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59808-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=ANLFcA20; 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-59808-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59808-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 43F9F1C23C0C for ; Fri, 9 Feb 2024 18:38:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88C1D8287B; Fri, 9 Feb 2024 18:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ANLFcA20" 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 55ADF54650 for ; Fri, 9 Feb 2024 18:37:48 +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=1707503870; cv=none; b=opK1a8BB8LfKSbq4QzCJOQLI7Ie1Ok4tiIS3SBIkLtKWkc1s3MIzzBtqYtP9lpp8E4Y7IDKUtxzCvHCHoIXhpQFCBPoYksuvUDWtx+QIEh39NCrHyA93q6CrY2mHeJgdVAxaMU+1VprfXwc4Zux10jQ09VvJcLPDmIE2biEbNJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707503870; c=relaxed/simple; bh=kvrgNkerakLij+Q7sGJMeCwb0heYoet1/gUQhvFFwXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=TyDnxDfMKg+IlfzoEDXii2kmhnx8JM0Pu3ZUqmj4QqCF9eqe4a8dY9scShTNUVzTedDM52/nQSQ31dO5qKkpmOQEesFOTQFtFh2Q3LIiRMT+5euQFFtfdlf/7p8vk7c26faCHIx7UKUF2Ha0jhKmu6bY17NU1nuaM84i3oaAjVY= 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=ANLFcA20; 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=1707503867; 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=2Yb42C16zvNs4Qe81/RZYCFLU8QdYJlCRgHBvvhE+xE=; b=ANLFcA20+i1HyDMFRew/A50RgLOkyeD8QOxY2IZ1gwzW+t7VP5yQZgCs0tsdCKEhHnVZ2o aW/OqqPMtZQf9T6wdhzukfWUKYD8LOlBN0xyGBo0oFGnwDsbzJ15Fl0B5CMR1EY98DZwyR jWi4ATlJrP9IPjmB86B3eO2fCLZsTVo= 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-556-Bp9guLUdMMq6yTAZrhDNKA-1; Fri, 09 Feb 2024 13:37:46 -0500 X-MC-Unique: Bp9guLUdMMq6yTAZrhDNKA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 7205B835381; Fri, 9 Feb 2024 18:37:45 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44DCD492BC6; Fri, 9 Feb 2024 18:37:45 +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, isaku.yamahata@intel.com Subject: [PATCH 07/10] KVM: x86: Add is_vm_type_supported callback Date: Fri, 9 Feb 2024 13:37:39 -0500 Message-Id: <20240209183743.22030-8-pbonzini@redhat.com> In-Reply-To: <20240209183743.22030-1-pbonzini@redhat.com> References: <20240209183743.22030-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.9 From: Isaku Yamahata 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 | 9 ++++++++- arch/x86/kvm/x86.h | 2 ++ 4 files changed, 12 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 b7d33205d49d..9636a43ccdc4 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..c89ddaa1e09f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4581,12 +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) +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); } +EXPORT_SYMBOL_GPL(__kvm_is_vm_type_supported); + +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) { diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 2f7e19166658..4e40c23d66ed 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -9,6 +9,8 @@ #include "kvm_cache_regs.h" #include "kvm_emulate.h" +bool __kvm_is_vm_type_supported(unsigned long type); + struct kvm_caps { /* control of guest tsc rate supported? */ bool has_tsc_control; -- 2.39.0