qemu-devel
[Top][All Lists]
Advanced

[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: Mon, 13 Sep 2021 10:35:42 +0100
User-agent: Mutt/2.0.7 (2021-05-04)

On Fri, Sep 10, 2021 at 02:46:00PM +0100, Daniel P. Berrangé wrote:
> 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

I was mistaken here - Error shouldn't use g_autoptr, just

   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);

Then use the simpler:

    error_report_err(err);

which prints + frees 'err'

>       return;
>    }
> 

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]