From patchwork Tue Nov 5 06:24:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13862462 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 AA32719047D for ; Tue, 5 Nov 2024 06:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730788815; cv=none; b=YjKKQoDiR0Du1XUG884BtcJcMhca5HJtuCxR4QqGEOYXBLMXuZpsfh+yRRpOzA78S5zgCxKbzCmYDtW47KJrHd7mv683krrOFXGKYeNfjFlJZFTt9juHLYxuTPtJKBtttJzDhB2/CFSL+n0puvYMcteYqo2slZg9xFHnUcueCp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730788815; c=relaxed/simple; bh=xs0CRmXKoLP85ntSNgfzBFyenj5am27Jk7rZikXTb+4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q5H20Gj/6y/JGpkeAyRPoi4Jvu1zMHFYx+5n1QwvKQfWBXaQ2t5F8le9GOkHbQSJ4bQBUd1BzWaLeUNhztGKUGCu8RMqDVCax7bwdFvvnx5kwTc2SrYUnYBgRCd7k6nagzIKyPkRFvOiw2S1geCGL22LDW17qUszqO7scjSkc9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DwUKqCtK; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DwUKqCtK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788814; x=1762324814; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xs0CRmXKoLP85ntSNgfzBFyenj5am27Jk7rZikXTb+4=; b=DwUKqCtKrdkFqYT6hbYBcAxn9yAdzG5ivZ+IWH5syJgzHUNcCwbqNzzh YvI+MGxtWdmyxhxWZPJuSfGeZ3+3sj15e/v6vFuOoh3SUJSdqOw0s1JbZ EvvzgjqeR0MZg5KUf7zmlpsMYVjbsXe3Fm2XE5b9HyfzvAFB+qxHeV33t R1Xin665fzvYaRGoelmKmvSgd3AzynqF9cgN19Eu8OLHjaq/KqxhENRfx FDQRBNdLoL45mSDrR09H/dY1N2aRIxcgErtl+fX8ToxgE2+2aFp5aF/Rm WDZIKlgOiKUX3iWl32zpURuHG281MDCj/qT6C3xWSNNVh4ite7GjHl9GU g==; X-CSE-ConnectionGUID: wCiV7yJEQV2OJcKNHAcuhA== X-CSE-MsgGUID: DtOL7uDmRCafbJHfPY0yBQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689909" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689909" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:14 -0800 X-CSE-ConnectionGUID: +AXT2kK8SDWa5RYfBzoJxw== X-CSE-MsgGUID: xLmUcX+pSb2KsI+RjIq5Og== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989984" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:09 -0800 From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 54/60] i386/cgs: Introduce x86_confidential_guest_check_features() Date: Tue, 5 Nov 2024 01:24:02 -0500 Message-Id: <20241105062408.3533704-55-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To do cgs specific feature checking. Note the feature checking in x86_cpu_filter_features() is valid for non-cgs VMs. For cgs VMs like TDX, what features can be supported has more restrictions. Signed-off-by: Xiaoyao Li --- target/i386/confidential-guest.h | 13 +++++++++++++ target/i386/kvm/kvm.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-guest.h index 2dde29889c23..3018f38e18bf 100644 --- a/target/i386/confidential-guest.h +++ b/target/i386/confidential-guest.h @@ -43,6 +43,7 @@ struct X86ConfidentialGuestClass { void (*cpu_realizefn)(X86ConfidentialGuest *cg, CPUState *cpu, Error **errp); uint32_t (*adjust_cpuid_features)(X86ConfidentialGuest *cg, uint32_t feature, uint32_t index, int reg, uint32_t value); + int (*check_features)(X86ConfidentialGuest *cg, CPUState *cs); }; /** @@ -103,4 +104,16 @@ static inline int x86_confidential_guest_adjust_cpuid_features(X86ConfidentialGu } } +static inline int x86_confidential_guest_check_features(X86ConfidentialGuest *cg, + CPUState *cs) +{ + X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg); + + if (klass->check_features) { + return klass->check_features(cg, cs); + } + + return 0; +} + #endif diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index f067961fba43..42dc5b78faf0 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2086,6 +2086,14 @@ int kvm_arch_init_vcpu(CPUState *cs) int r; Error *local_err = NULL; + if (current_machine->cgs) { + r = x86_confidential_guest_check_features( + X86_CONFIDENTIAL_GUEST(current_machine->cgs), cs); + if (r < 0) { + return r; + } + } + memset(&cpuid_data, 0, sizeof(cpuid_data)); cpuid_i = 0;