qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Yang Zhong <yang.zhong@intel.com>
Cc: pbonzini@redhat.com, philmd@redhat.com, qemu-devel@nongnu.org,
	eblake@redhat.com, seanjc@google.com
Subject: Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces
Date: Fri, 10 Sep 2021 14:46:00 +0100	[thread overview]
Message-ID: <YTthmPn2KGcfNX21@redhat.com> (raw)
In-Reply-To: <20210910102258.46648-2-yang.zhong@intel.com>

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 :|



  parent reply	other threads:[~2021-09-10 13:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 10:22 [PATCH v2 0/3] The HMP/QMP interfaces in Qemu SGX Yang Zhong
2021-09-10 10:22 ` [PATCH v2 1/3] monitor: Add HMP and QMP interfaces Yang Zhong
2021-09-10 12:39   ` Philippe Mathieu-Daudé
2021-09-13 10:37     ` Yang Zhong
2021-09-13 12:42       ` Paolo Bonzini
2021-09-10 13:46   ` Daniel P. Berrangé [this message]
2021-09-13  9:35     ` Daniel P. Berrangé
2021-09-13 10:46       ` Yang Zhong
2021-09-13 12:48       ` Paolo Bonzini
2021-09-13 12:56         ` Daniel P. Berrangé
2021-09-13 12:52           ` Yang Zhong
2021-09-13 13:24             ` Daniel P. Berrangé
2021-09-16  6:14               ` Yang Zhong
2021-09-10 10:22 ` [PATCH v2 2/3] qmp: Add the qmp_query_sgx_capabilities() Yang Zhong
2021-09-10 12:41   ` Philippe Mathieu-Daudé
2021-09-13 10:34     ` Yang Zhong
2021-09-10 10:22 ` [PATCH v2 3/3] pc: Cleanup the SGX definitions Yang Zhong
2021-09-10 14:15 ` [PATCH v2 0/3] The HMP/QMP interfaces in Qemu SGX Paolo Bonzini
2021-09-10 14:21   ` Daniel P. Berrangé
2021-09-10 19:10     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YTthmPn2KGcfNX21@redhat.com \
    --to=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seanjc@google.com \
    --cc=yang.zhong@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).