[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces |
Date: |
Fri, 10 Sep 2021 14:46:00 +0100 |
User-agent: |
Mutt/2.0.7 (2021-05-04) |
On Fri, Sep 10, 2021 at 06:22:56PM +0800, Yang Zhong wrote:
> The QMP and HMP interfaces can be used by monitor or QMP tools to retrieve
> the SGX information from VM side when SGX is enabled on Intel platform.
>
> Signed-off-by: Yang Zhong <yang.zhong@intel.com>
> ---
> hmp-commands-info.hx | 15 +++++++++++++
> hw/i386/sgx.c | 29 ++++++++++++++++++++++++
> include/hw/i386/sgx.h | 11 +++++++++
> include/monitor/hmp-target.h | 1 +
> qapi/misc-target.json | 43 ++++++++++++++++++++++++++++++++++++
> target/i386/monitor.c | 36 ++++++++++++++++++++++++++++++
> tests/qtest/qmp-cmd-test.c | 1 +
> 7 files changed, 136 insertions(+)
> create mode 100644 include/hw/i386/sgx.h
> diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
> index 02fa6487c3..8a32d62d7e 100644
> --- a/hw/i386/sgx.c
> +++ b/hw/i386/sgx.c
> @@ -17,6 +17,35 @@
> #include "monitor/qdev.h"
> #include "qapi/error.h"
> #include "exec/address-spaces.h"
> +#include "hw/i386/sgx.h"
> +
> +SGXInfo *sgx_get_info(void)
I'd suggest this should have an 'Error **errp'
> +{
> + SGXInfo *info = NULL;
> + X86MachineState *x86ms;
> + PCMachineState *pcms =
> + (PCMachineState *)object_dynamic_cast(qdev_get_machine(),
> + TYPE_PC_MACHINE);
> + if (!pcms) {
error_setg(errp, "SGX is only available for x86 PC machines");
> + return NULL;
> + }
> +
> + x86ms = X86_MACHINE(pcms);
> + if (!x86ms->sgx_epc_list) {
error_setg(errp "SGX is not enabled on this machine");
> + return NULL;
> + }
> +
> + SGXEPCState *sgx_epc = &pcms->sgx_epc;
> + info = g_new0(SGXInfo, 1);
> +
> + info->sgx = true;
> + info->sgx1 = true;
> + info->sgx2 = true;
> + info->flc = true;
> + info->section_size = sgx_epc->size;
> +
> + return info;
> +}
> diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> index 119211f0b0..0f1b48b4f8 100644
> --- a/target/i386/monitor.c
> +++ b/target/i386/monitor.c
> @@ -35,6 +35,7 @@
> #include "qapi/qapi-commands-misc-target.h"
> #include "qapi/qapi-commands-misc.h"
> #include "hw/i386/pc.h"
> +#include "hw/i386/sgx.h"
>
> /* Perform linear address sign extension */
> static hwaddr addr_canonical(CPUArchState *env, hwaddr addr)
> @@ -763,3 +764,38 @@ qmp_query_sev_attestation_report(const char *mnonce,
> Error **errp)
> {
> return sev_get_attestation_report(mnonce, errp);
> }
> +
> +SGXInfo *qmp_query_sgx(Error **errp)
> +{
> + SGXInfo *info;
> +
> + info = sgx_get_info();
Pass errp into this
> + if (!info) {
> + error_setg(errp, "SGX features are not available");
And get rid of this.
> + return NULL;
> + }
> +
> + return info;
> +}
> +
> +void hmp_info_sgx(Monitor *mon, const QDict *qdict)
> +{
g_autoptr(Error) err = NULL
> + SGXInfo *info = qmp_query_sgx(NULL);
Pass in &err not NULL;
Also declare it with 'g_autoptr(SGXInfo) info = ...'
And then
if (err) {
monitor_printf(mon, "%s\n", error_get_pretty(err);
return;
}
> +
> + 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");
> + }
Now you can remove the if/else and just print the result
> +
> + qapi_free_SGXInfo(info);
This can be dropped with the g_autoptr usage
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [PATCH v2 0/3] The HMP/QMP interfaces in Qemu SGX, Yang Zhong, 2021/09/10
- [PATCH v2 3/3] pc: Cleanup the SGX definitions, Yang Zhong, 2021/09/10
- [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Yang Zhong, 2021/09/10
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces,
Daniel P . Berrangé <=
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Daniel P . Berrangé, 2021/09/13
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Yang Zhong, 2021/09/13
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Paolo Bonzini, 2021/09/13
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Daniel P . Berrangé, 2021/09/13
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Yang Zhong, 2021/09/13
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Daniel P . Berrangé, 2021/09/13
- Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces, Yang Zhong, 2021/09/16
[PATCH v2 2/3] qmp: Add the qmp_query_sgx_capabilities(), Yang Zhong, 2021/09/10