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: Yang Zhong
Subject: Re: [PATCH v2 1/3] monitor: Add HMP and QMP interfaces
Date: Mon, 13 Sep 2021 18:46:19 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Sep 13, 2021 at 10:35:42AM +0100, Daniel P. Berrangé wrote:
> 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'

    Thanks, the new version will add this variable. thanks!


> > 
> > > +{
> > > +    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");
> > 

      Yes, i will add this, thanks!


> > > +        return NULL;
> > > +    }
> > > +
> > > +    x86ms = X86_MACHINE(pcms);
> > > +    if (!x86ms->sgx_epc_list) {
> > 
> >   error_setg(errp "SGX is not enabled on this machine");
> > 
 
      Ditto, thanks!


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

    Thanks, i will add this.


> > 
> > > +    if (!info) {
> > > +        error_setg(errp, "SGX features are not available");
> > 
> > And get rid of this.

    Yes, i will remove this, thanks!


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


    Yes, i will use this new defintion to handle it. thanks!


> 
> > 
> > > +    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'
> 

  Thanks, the new code like below:
  
  Error *err = NULL;

  SGXInfo *info = qmp_query_sgx(&err);
  if (err) {
      error_report_err(err);
      return;
  }

  ......

  I will send V3, please help review again, thanks!


  Yang



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