From nobody Tue Feb 10 02:55:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1618829014; cv=none; d=zohomail.com; s=zohoarc; b=SOzW4jIJXmg175Vq7wRuNSHC02Cpf4t8fkBZQrzwygraqV4ViqtMAoZ1ubElRI8mSZyjBdV9txUDQEnEpnNlf7VCJ1JrhpoAEU8kZZE7a9J26mA8sFxCMTIFZiIqO7XYDkEkTDdJWhVmFdk2gLWXICPhZmBXqQFqzBXIu9niqXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618829014; 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=oGyIrejkmftw7WIMo45kyRORLiycRfqxfkh6R+zBnmc=; b=mXBDJ1IjPBEFYFKxQ/+ohIYUEm2EmXyZG5eHRMAVFS6RUs6fOcBmNUuSceROvIBVjww1KT2yNRqqB89RQoA/0UurP80xV7PVSmUoqU8KjndmWi/6dHroZk/fd178Kx8HN735kWdGiovU5Dtg5RA+vdeGghUjVVIUgA42vW874Qk= ARC-Authentication-Results: i=1; mx.zohomail.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618829014457232.59164398657288; Mon, 19 Apr 2021 03:43:34 -0700 (PDT) Received: from localhost ([::1]:45930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYRNN-0002Ur-DG for importer@patchew.org; Mon, 19 Apr 2021 06:43:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYR4e-0006LV-V4 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 06:24:12 -0400 Received: from mga17.intel.com ([192.55.52.151]:24099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYR4b-00025K-D9 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 06:24:12 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2021 03:23:15 -0700 Received: from icx-2s.bj.intel.com ([10.240.192.119]) by fmsmga008.fm.intel.com with ESMTP; 19 Apr 2021 03:23:13 -0700 IronPort-SDR: fSBGjmR4udaWdEoEQcjY6g7fimwgZGqX2VRqFFfSoUPJ9fpK8nAGjU3FF6wgvq0E0RyMfB8w/9 ecVQtHN9g4ug== X-IronPort-AV: E=McAfee;i="6200,9189,9958"; a="175409334" X-IronPort-AV: E=Sophos;i="5.82,233,1613462400"; d="scan'208";a="175409334" IronPort-SDR: rydEPnfwRqqXOicDZUG094dQibpn63qhfg9a8ogy1al+u2pwDuia8s3sEydPJD9acCtS7viQxF RPQ9l2NHpgqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,233,1613462400"; d="scan'208";a="419947517" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 27/32] i386: Add sgx_get_info() interface Date: Mon, 19 Apr 2021 18:01:51 +0800 Message-Id: <20210419100156.53504-28-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20210419100156.53504-1-yang.zhong@intel.com> References: <20210419100156.53504-1-yang.zhong@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=192.55.52.151; envelope-from=yang.zhong@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, kai.huang@intel.com, seanjc@google.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add the sgx_get_info() interface for hmp and QMP usage, which will get the SGX info from this API. Signed-off-by: Yang Zhong --- hw/i386/sgx-epc.c | 22 ++++++++++++++++++++++ include/hw/i386/pc.h | 1 + include/hw/i386/sgx-epc.h | 1 + monitor/hmp-cmds.c | 20 ++++++++++++++++++-- monitor/qmp-cmds.c | 12 ++++++++++-- stubs/meson.build | 1 + stubs/sgx-stub.c | 7 +++++++ 7 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 stubs/sgx-stub.c diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c index fbacec6e00..7daea0613b 100644 --- a/hw/i386/sgx-epc.c +++ b/hw/i386/sgx-epc.c @@ -322,6 +322,28 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms) memory_region_set_size(&sgx_epc->mr, sgx_epc->size); } =20 +SGXInfo *sgx_get_info(void) +{ + SGXInfo *info; + + info =3D g_new0(SGXInfo, 1); + if (sgx_epc_enabled) { + PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); + SGXEPCState *sgx_epc =3D pcms->sgx_epc; + + info->sgx =3D true; + info->sgx1 =3D true; + info->sgx2 =3D true; + info->flc =3D true; + + if (sgx_epc) { + info->section_size =3D sgx_epc->size; + } + } + + return info; +} + static QemuOptsList sgx_epc_opts =3D { .name =3D "sgx-epc", .implied_opt_name =3D "id", diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 44b8c5d271..cb74298117 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -204,6 +204,7 @@ void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, void pc_machine_init_sgx_epc(PCMachineState *pcms); void sgx_memory_backend_reset(HostMemoryBackend *backend, int fd, Error **errp); +SGXInfo *sgx_get_info(void); =20 extern GlobalProperty pc_compat_5_2[]; extern const size_t pc_compat_5_2_len; diff --git a/include/hw/i386/sgx-epc.h b/include/hw/i386/sgx-epc.h index 3d3eab5074..bd006bd7a0 100644 --- a/include/hw/i386/sgx-epc.h +++ b/include/hw/i386/sgx-epc.h @@ -13,6 +13,7 @@ #define QEMU_SGX_EPC_H =20 #include "sysemu/hostmem.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_SGX_EPC "sgx-epc" #define SGX_EPC(obj) \ diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 1d1efca713..bd539e0c1e 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2229,6 +2229,22 @@ void hmp_info_memory_size_summary(Monitor *mon, cons= t QDict *qdict) =20 void hmp_info_sgx(Monitor *mon, const QDict *qdict) { - error_setg(errp, QERR_FEATURE_DISABLED, "query-sgx"); - return NULL; + SGXInfo *info =3D qmp_query_sgx(NULL); + + if (info && info->sgx) { + monitor_printf(mon, "SGX support: %s\n", + info->sgx ? "enabled" : "disabled"); + monitor_printf(mon, "SGX1 support: %s\n", + info->sgx1 ? "enabled" : "disabled"); + monitor_printf(mon, "SGX2 support: %s\n", + info->sgx2 ? "enabled" : "disabled"); + monitor_printf(mon, "FLC support: %s\n", + info->flc ? "enabled" : "disabled"); + monitor_printf(mon, "size: %" PRIu64 "\n", + info->section_size); + } else { + monitor_printf(mon, "SGX is not enabled\n"); + } + + qapi_free_SGXInfo(info); } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index d63d59149f..48f7708ffe 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -40,6 +40,7 @@ #include "qapi/qmp/qerror.h" #include "hw/mem/memory-device.h" #include "hw/acpi/acpi_dev_interface.h" +#include "hw/i386/pc.h" =20 NameInfo *qmp_query_name(Error **errp) { @@ -354,6 +355,13 @@ void qmp_display_reload(DisplayReloadOptions *arg, Err= or **errp) =20 SGXInfo *qmp_query_sgx(Error **errp) { - error_setg(errp, QERR_FEATURE_DISABLED, "query-sgx"); - return NULL; + SGXInfo *info; + + info =3D sgx_get_info(); + if (!info) { + error_setg(errp, "SGX features are not available"); + return NULL; + } + + return info; } diff --git a/stubs/meson.build b/stubs/meson.build index be6f6d609e..1cba20a9a8 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -54,3 +54,4 @@ if have_system else stub_ss.add(files('qdev.c')) endif +stub_ss.add(files('sgx-stub.c')) diff --git a/stubs/sgx-stub.c b/stubs/sgx-stub.c new file mode 100644 index 0000000000..c2b59a88fd --- /dev/null +++ b/stubs/sgx-stub.c @@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" + +SGXInfo *sgx_get_info(void) +{ + return NULL; +} --=20 2.29.2.334.gfaefdd61ec