From nobody Mon Feb 9 19:07:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1652326104; cv=none; d=zohomail.com; s=zohoarc; b=ggv2guatIJWVoCWY1PcA8oxdF4tD902U8Y0iNS0UP4N5NCv5IRmiHD/22tdBTsBWAYfFZTPHvHOGN+2iwvO7Qdh1LB/l/DG10plc13/sPoXJ1zvzdwP9k5DX5RAmPiUy5QzF/L2QqSX808km4YZ2q7shrx+K6Ywv8jhJBC83qLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652326104; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=i2F012/fgxPgIdP9gUPQ1R06+W11AeenCGCrX2YP7Tg=; b=Uq7HQ/UNkDYNJ1ThVkXbnBIBtgZoIRJ6U/Ufz2bhBfV42J/qAWC0w1thg/wbcTviAIZIlDq7Hzwtdz3ybWCS7Z80IxEbEeZ6iZHZbISd8SYD2HQ7Oxz4k+M+gZqq09cRBNAoHZBK7qYw0SXeHhPR3UdPay3k54mYIH8v99GieFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652326104866989.0987968645381; Wed, 11 May 2022 20:28:24 -0700 (PDT) Received: from localhost ([::1]:39098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nozV1-0000gs-Qx for importer@patchew.org; Wed, 11 May 2022 23:28:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nozLX-0001jN-Jc for qemu-devel@nongnu.org; Wed, 11 May 2022 23:18:35 -0400 Received: from mga18.intel.com ([134.134.136.126]:33504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nozLV-0002mx-FB for qemu-devel@nongnu.org; Wed, 11 May 2022 23:18:35 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2022 20:18:32 -0700 Received: from lxy-dell.sh.intel.com ([10.239.159.55]) by orsmga008.jf.intel.com with ESMTP; 11 May 2022 20:18:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652325513; x=1683861513; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=13oKdudyn3OtFlvHP52LX9jc6TvQaEwqOOc3JtOS3+Y=; b=BAtSEhRwTeOMBwcVsPZkng8vEt0zXzLnnytrZbJdZctiEJhcqfRPxyYZ gR9HnFDWe73ezny1mD+9QKlTi4GuxvYWN2TBQz/A9Hva/s3AGFjhi7OTc /2tDPnT5rzxRqyENrQK4eHAWiJuLLBEJh4u24dZ/iPqo6ZbKzGcsL6HtT Gb4D0HehcSdL90mRrRZH6xsIJvT0yvUdXDkhV8TQQUbgKUiz3qmXHk1Q0 bUEF8f7HG7MhG2WqHXX+qtpFQLiSpEPPGf0Dn3JpRXtkISCEG6Ly+UYtE 2FKIvDUja9+8crWdkQM49Y5k+cn+0NS/yi3Mx5/c2p8t1CBFS9n+DmNEs A==; X-IronPort-AV: E=McAfee;i="6400,9594,10344"; a="251928204" X-IronPort-AV: E=Sophos;i="5.91,218,1647327600"; d="scan'208";a="251928204" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,218,1647327600"; d="scan'208";a="594455481" From: Xiaoyao Li To: Paolo Bonzini , Isaku Yamahata , isaku.yamahata@intel.com, Gerd Hoffmann , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , "Michael S . Tsirkin" , Marcel Apfelbaum , Cornelia Huck , Marcelo Tosatti , Laszlo Ersek , Eric Blake Cc: Connor Kuehl , erdemaktas@google.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, seanjc@google.com, xiaoyao.li@intel.com Subject: [RFC PATCH v4 05/36] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context Date: Thu, 12 May 2022 11:17:32 +0800 Message-Id: <20220512031803.3315890-6-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220512031803.3315890-1-xiaoyao.li@intel.com> References: <20220512031803.3315890-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.126; envelope-from=xiaoyao.li@intel.com; helo=mga18.intel.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.998, HK_RANDOM_FROM=0.998, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1652326105811100001 Content-Type: text/plain; charset="utf-8" Introduce tdx_kvm_init() and invoke it in kvm_confidential_guest_init() if it's a TDX VM. More initialization will be added later. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/kvm.c | 15 ++++++--------- target/i386/kvm/meson.build | 2 +- target/i386/kvm/tdx-stub.c | 9 +++++++++ target/i386/kvm/tdx.c | 7 +++++++ target/i386/kvm/tdx.h | 2 ++ 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 target/i386/kvm/tdx-stub.c diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index f657518616f1..f257ffda259d 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -54,6 +54,7 @@ #include "migration/blocker.h" #include "exec/memattrs.h" #include "trace.h" +#include "tdx.h" =20 #include CONFIG_DEVICES =20 @@ -2430,6 +2431,8 @@ static int kvm_confidential_guest_init(MachineState *= ms, Error **errp) { if (object_dynamic_cast(OBJECT(ms->cgs), TYPE_SEV_GUEST)) { return sev_kvm_init(ms->cgs, errp); + } else if (object_dynamic_cast(OBJECT(ms->cgs), TYPE_TDX_GUEST)) { + return tdx_kvm_init(ms, errp); } =20 return 0; @@ -2444,16 +2447,10 @@ int kvm_arch_init(MachineState *ms, KVMState *s) Error *local_err =3D NULL; =20 /* - * Initialize SEV context, if required + * Initialize confidential guest (SEV/TDX) context, if required * - * If no memory encryption is requested (ms->cgs =3D=3D 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. + * It's a no-op if a non-SEV/non-tdx confidential guest support + * mechanism is selected, i.e., ms->cgs =3D=3D NULL */ ret =3D kvm_confidential_guest_init(ms, &local_err); if (ret < 0) { diff --git a/target/i386/kvm/meson.build b/target/i386/kvm/meson.build index b2d7d41acde2..fd30b93ecec9 100644 --- a/target/i386/kvm/meson.build +++ b/target/i386/kvm/meson.build @@ -9,7 +9,7 @@ i386_softmmu_kvm_ss.add(files( =20 i386_softmmu_kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c')) =20 -i386_softmmu_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c')) +i386_softmmu_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c'), if_fa= lse: files('tdx-stub.c')) =20 i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_= false: files('hyperv-stub.c')) =20 diff --git a/target/i386/kvm/tdx-stub.c b/target/i386/kvm/tdx-stub.c new file mode 100644 index 000000000000..1df24735201e --- /dev/null +++ b/target/i386/kvm/tdx-stub.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "tdx.h" + +int tdx_kvm_init(MachineState *ms, Error **errp) +{ + return -EINVAL; +} diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index d3792d4a3d56..77e33ae01147 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -12,10 +12,17 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "qom/object_interfaces.h" =20 +#include "hw/i386/x86.h" #include "tdx.h" =20 +int tdx_kvm_init(MachineState *ms, Error **errp) +{ + return 0; +} + /* tdx guest */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, tdx_guest, diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index 415aeb5af746..c8a23d95258d 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -16,4 +16,6 @@ typedef struct TdxGuest { uint64_t attributes; /* TD attributes */ } TdxGuest; =20 +int tdx_kvm_init(MachineState *ms, Error **errp); + #endif /* QEMU_I386_TDX_H */ --=20 2.27.0