From patchwork Thu Feb 29 06:36:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13576536 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 9C2014776A for ; Thu, 29 Feb 2024 06:39:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188748; cv=none; b=ljHi48/Ozx1STyeT88fAqFD6sd/UbPzAiv2T1biHb+V8cU9bWyrXD0DadtUtI78a426+RRziJ46xkGOJdwp2kgumK/RUeBMaqHeiCLS+mnF0gpN+avjyhIb6H6QBo8+hpm0b6PWlwGtGajymPPQFH13FADIn2pdzBb5GG4qeXzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188748; c=relaxed/simple; bh=mU0otVJn1bEwIQ9Zyr9mBs1D769YAuu9+hQHU1VV6MY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rwr+X9mgLCP7UfRsgGucTl71bKN6giDdkyQHq5uUlcB7Q+btmhtCOGl6HBSHMfdEjzCyRJtsYn0bSJBqLE81v2w+c+n33MWhDiLl5hFQTrERxYT7Fak1qd7U4zH75No2etsJRv05H/IxvJaKOMROOlKUwwufHiJynYre4YyLIX0= 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=n7/hMX/E; arc=none smtp.client-ip=192.198.163.15 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="n7/hMX/E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709188746; x=1740724746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mU0otVJn1bEwIQ9Zyr9mBs1D769YAuu9+hQHU1VV6MY=; b=n7/hMX/EnL/CpPXHoTEateD2te9U30tvZGJSAagZlmdGqlwgeYzmcqpy iWrx5Cq1qVKowr0d1KD1AnCcXKLnzQF8MlVFmvGBDMJuwXfeD53Jlgbsc U+kAcwv5m6sWE8UhSmOqTwFY1qd/HRfFBF65ihvAcR0VUFJ6WuKZabVDQ 3xtsv8e9e8yGDvGCJz4/AMp4xiXBiS4wPJ6d58HXtpT+spUGoZom2r+2O B2ObqGE0BNxGMctuZVL7W3+VHg3Xz9M/HmaiUBhwV1llcsBm8CE3BFhY5 pUeQgeik5B2FnIMFCE8xj85pj4c0uEJRVUD9x9V8GtXmnKts9yKpaKfQf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3802603" X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="3802603" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:39:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="8075059" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by orviesa007.jf.intel.com with ESMTP; 28 Feb 2024 22:39:00 -0800 From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , "Michael S. Tsirkin" , Richard Henderson , Ani Sinha , Peter Xu , Cornelia Huck , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, Michael Roth , Claudio Fontana , Gerd Hoffmann , Isaku Yamahata , Chenyi Qiang , xiaoyao.li@intel.com Subject: [PATCH v5 14/65] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context Date: Thu, 29 Feb 2024 01:36:35 -0500 Message-Id: <20240229063726.610065-15-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229063726.610065-1-xiaoyao.li@intel.com> References: <20240229063726.610065-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(). Set ms->require_guest_memfd to true to require private guest memfd allocation for any memory backend. More TDX specific initialization will be added later. Signed-off-by: Xiaoyao Li --- Changes in v5: - 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 | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 898f8fb30c61..52d99d30bdc8 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2550,16 +2550,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 d3792d4a3d56..d9a1dd46dc69 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -14,8 +14,18 @@ #include "qemu/osdep.h" #include "qom/object_interfaces.h" +#include "hw/i386/x86.h" #include "tdx.h" +static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + + ms->require_guest_memfd = true; + + return 0; +} + /* tdx guest */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, tdx_guest, @@ -37,4 +47,7 @@ static void tdx_guest_finalize(Object *obj) static void tdx_guest_class_init(ObjectClass *oc, void *data) { + ConfidentialGuestSupportClass *klass = CONFIDENTIAL_GUEST_SUPPORT_CLASS(oc); + + klass->kvm_init = tdx_kvm_init; }