From patchwork Tue Nov 5 06:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13862393 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 BACCF1F16B for ; Tue, 5 Nov 2024 06:36:38 +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=1730788600; cv=none; b=qyYXKlJiTrTmEq4wgRRn3Ts4SQeIZNzYfQWYpI+1Ibp6rjfQ/C5paqmm7TNf8CnhP2BYqQWYIJeoo3TgvSdZE46V3uUhM63mgJQmJ2fOTpZD+sJv1+VobamtOiIwGBoLNf1awWQJPwQHXPxdicHc7epaNkUiPYXwAbOoWgKuZGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730788600; c=relaxed/simple; bh=ou+Mdobmm1tQq2ArTm7wdCK4exn2TLAYJgjckbytn0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hmi4RcnnztUTNAFiGj1bep+uvKvsRKCmFPdJRCoGYUobilS18KK1JcPYRV6QDEKqwPLBoaoC5lbXI4D6d0/ErBU5VgZuwQ9D1PvqteUd5Szl0xb60/XCFJucOm1XRGSB9bWDsNFlSSojBesgPA366EkmRY88pLRf4ztfWGTmiuw= 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=A+LvCwdU; 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="A+LvCwdU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788599; x=1762324599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ou+Mdobmm1tQq2ArTm7wdCK4exn2TLAYJgjckbytn0A=; b=A+LvCwdUJl5Wt4Xq02ub6C8tEdUDfCBVG7eW6sp0H0emya/Vl85l7fRr DwQVpvih/VqEg9tOlsq3EUZewuE2K47XRzn4ri0UeqyY98OJRqi5MFQCt opQmZI0FqR5agWMXiYrDDsgUscv94CVYTt089SSAj77ab8xuuXVdlairj Z9YtgDC1PWtx6zRqEfdq/bYQ2Qq3Z2FOfATjqBMGOMpF6Y7Bn/C325Dg2 lISfNAQ6Bj5wF5uiLFa81faUy8OccApheM1Ma73NArIwNFTMzf0ttJ4wB jyDi14zhzvHTcqe4laKhzjBW96xd8g7FfBuLKJkGRvsFfJettH08jJ3Fq w==; X-CSE-ConnectionGUID: YoxPk2X7TV+isH0qGGWGtg== X-CSE-MsgGUID: 6zX7bMqERa6AmP0cEqxY3A== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689256" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689256" 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:36:39 -0800 X-CSE-ConnectionGUID: r1o3UWJtR+OrzWAUBbZ4Gw== X-CSE-MsgGUID: /2AI0GzRRKefGwjrd6onTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988607" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:34 -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 04/60] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context Date: Tue, 5 Nov 2024 01:23:12 -0500 Message-Id: <20241105062408.3533704-5-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 Implement TDX specific ConfidentialGuestSupportClass::kvm_init() callback, tdx_kvm_init(). Mark guest state is proctected for TDX VM. More TDX specific initialization will be added later. Signed-off-by: Xiaoyao Li --- Changes in v6: - remove Acked-by from Gerd since the patch changed due to use ConfidentialGuestSupportClass::kvm_init(); --- target/i386/kvm/kvm.c | 11 +---------- target/i386/kvm/tdx.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index ed2e89946c44..2bbac603da70 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3204,16 +3204,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) Error *local_err = NULL; /* - * Initialize SEV context, if required - * - * If no memory encryption is requested (ms->cgs == NULL) this is - * a no-op. - * - * It's also a no-op if a non-SEV confidential guest support - * mechanism is selected. SEV is the only mechanism available to - * select on x86 at present, so this doesn't arise, but if new - * mechanisms are supported in future (e.g. TDX), they'll need - * their own initialization either here or elsewhere. + * Initialize confidential guest (SEV/TDX) context, if required */ if (ms->cgs) { ret = confidential_guest_kvm_init(ms->cgs, &local_err); diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index bf8947549a96..85f006c1d6b4 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -14,9 +14,17 @@ #include "qemu/osdep.h" #include "qom/object_interfaces.h" +#include "hw/i386/x86.h" #include "kvm_i386.h" #include "tdx.h" +static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) +{ + kvm_mark_guest_state_protected(); + + return 0; +} + static int tdx_kvm_type(X86ConfidentialGuest *cg) { /* Do the object check */ @@ -51,7 +59,9 @@ static void tdx_guest_finalize(Object *obj) static void tdx_guest_class_init(ObjectClass *oc, void *data) { + ConfidentialGuestSupportClass *klass = CONFIDENTIAL_GUEST_SUPPORT_CLASS(oc); X86ConfidentialGuestClass *x86_klass = X86_CONFIDENTIAL_GUEST_CLASS(oc); + klass->kvm_init = tdx_kvm_init; x86_klass->kvm_type = tdx_kvm_type; }