From nobody Wed Dec 4 18:56:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@intel.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 171653233756680.66569732558014; Thu, 23 May 2024 23:32:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 74FDB196D; Fri, 24 May 2024 02:32:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 64F1D1C6B; Fri, 24 May 2024 02:26:37 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2D68A1B9C; Fri, 24 May 2024 02:26:24 -0400 (EDT) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9BCEF1B9C for ; Fri, 24 May 2024 02:25:44 -0400 (EDT) Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 23:24:43 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 23:24:41 -0700 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716531945; x=1748067945; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+llhBALzB/+mc85IynsvNsE2sa2Ub7o9kGMB6yq/Igc=; b=N3z5B8bdf7rvF8LgVfqrOTew6CP4YD7rWG8cr0GwOa1fZKr6Yu76NVPx vz5IAVjww11SvM8xkoWWqyEWGgy1oDdVWMPXHJ+HYcwNHIDh3h6LS2v3I Z+uJhJSvLiHYXb7nqiTEhXeJ+lc8pYo8YGdOBul7GvljkzqcEsL/cCc24 hLX48kb4PiiTl3ulctnqsBlpe3tp/S/qImj0CDjlcaG4PBlS/8zlL1lgA G76fA1r2pqWkBlsPQ52Wgx7on+VQz1D0edjceHr095B7wsc2SXv+xV80A yMH1CPruMGtg1vbqfF+eYa/EVet789omwxOSZA9OBp48y1R/HAYtG2J49 Q==; X-CSE-ConnectionGUID: 4mY1xB8iS6K+78ZIWbKR+w== X-CSE-MsgGUID: Vz5TssQVS52TTIpQBTAVeA== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="13081253" X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="13081253" X-CSE-ConnectionGUID: h9JhtA/NRYSQyhF0sTghcw== X-CSE-MsgGUID: +RU1AofNRsylxK7aq2sGtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="34033972" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH rfcv4 06/13] qemu: Add command line and validation for TDX type Date: Fri, 24 May 2024 14:21:21 +0800 Message-Id: <20240524062128.523820-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524062128.523820-1-zhenzhong.duan@intel.com> References: <20240524062128.523820-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6N7KP5F5Z44NI3R5U7STSPWUYXK6QYUO X-Message-ID-Hash: 6N7KP5F5Z44NI3R5U7STSPWUYXK6QYUO X-MailFrom: zhenzhong.duan@intel.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: phrdina@redhat.com, pkrempa@redhat.com, jjongsma@redhat.com, jsuchane@redhat.com, chenyi.qiang@intel.com, isaku.yamahata@intel.com, xiaoyao.li@intel.com, chao.p.peng@intel.com, Zhenzhong Duan X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716532338218100001 Content-Type: text/plain; charset="utf-8" QEMU will provides 'tdx-guest' object which is used to launch encrypted VMs on Intel platform using TDX feature. Command line looks like: $QEMU ... \ -object '{"qom-type":"tdx-guest","id":"lsec0","debug":true,"sept-ve-disab= le":false,"mrconfigid":"xxx","mrowner":"xxx","mrownerconfig":"xxx"}' \ -machine pc-q35-6.0,confidential-guest-support=3Dlsec0 Signed-off-by: Zhenzhong Duan --- src/conf/domain_conf.h | 5 +++++ src/qemu/qemu_command.c | 31 +++++++++++++++++++++++++++++++ src/qemu/qemu_validate.c | 11 +++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7882b7a75d..bb4973fce8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2880,6 +2880,11 @@ struct _virDomainTDXDef { char *mrownerconfig; }; =20 +#define VIR_DOMAIN_TDX_POLICY_DEBUG 0x1 +#define VIR_DOMAIN_TDX_POLICY_SEPT_VE_DISABLE 0x10000000 +#define VIR_DOMAIN_TDX_POLICY_ALLOWED_MASK (VIR_DOMAIN_TDX_POLICY_DE= BUG | \ + VIR_DOMAIN_TDX_POLICY_SE= PT_VE_DISABLE) + struct _virDomainSecDef { virDomainLaunchSecurity sectype; union { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index dde2d5fa01..d212d80038 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9745,6 +9745,36 @@ qemuBuildPVCommandLine(virDomainObj *vm, virCommand = *cmd) } =20 =20 +static int +qemuBuildTDXCommandLine(virDomainObj *vm, virCommand *cmd, + virDomainTDXDef *tdx) +{ + g_autoptr(virJSONValue) props =3D NULL; + qemuDomainObjPrivate *priv =3D vm->privateData; + bool sept_ve_disable =3D tdx->policy & VIR_DOMAIN_TDX_POLICY_SEPT_VE_D= ISABLE; + + VIR_DEBUG("policy=3D0x%llx", tdx->policy); + + if (qemuMonitorCreateObjectProps(&props, "tdx-guest", "lsec0", + "B:debug", !!(tdx->policy & VIR_DOMAI= N_TDX_POLICY_DEBUG), + "S:mrconfigid", tdx->mrconfigid, + "S:mrowner", tdx->mrowner, + "S:mrownerconfig", tdx->mrownerconfig, + NULL) < 0) + return -1; + + /* By default, QEMU set sept-ve-disable which is required by linux ker= nel */ + if (!sept_ve_disable && + virJSONValueObjectAdd(&props, "b:sept-ve-disable", false, NULL) < = 0) + return -1; + + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) + return -1; + + return 0; +} + + static int qemuBuildSecCommandLine(virDomainObj *vm, virCommand *cmd, virDomainSecDef *sec) @@ -9760,6 +9790,7 @@ qemuBuildSecCommandLine(virDomainObj *vm, virCommand = *cmd, return qemuBuildPVCommandLine(vm, cmd); break; case VIR_DOMAIN_LAUNCH_SECURITY_TDX: + return qemuBuildTDXCommandLine(vm, cmd, &sec->data.tdx); case VIR_DOMAIN_LAUNCH_SECURITY_NONE: case VIR_DOMAIN_LAUNCH_SECURITY_LAST: virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index ee25fd70d9..db8493be68 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1323,6 +1323,17 @@ qemuValidateDomainDef(const virDomainDef *def, } break; case VIR_DOMAIN_LAUNCH_SECURITY_TDX: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_TDX_GUEST)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Intel TDX launch security is not support= ed with this QEMU binary")); + return -1; + } + if (def->sec->data.tdx.policy & ~VIR_DOMAIN_TDX_POLICY_ALLOWED= _MASK) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only bit0(debug) and bit28(sept-ve-disab= le) are supported intel TDX launch security policy")); + return -1; + } + break; case VIR_DOMAIN_LAUNCH_SECURITY_NONE: case VIR_DOMAIN_LAUNCH_SECURITY_LAST: virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sec= type); --=20 2.34.1