xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Paul Durrant <Paul.Durrant@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Andrew Cooper <Andrew.Cooper3@citrix.com>,
	"Keir (Xen.org)" <keir@xen.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] x86/hvm/viridian: zero and check vcpu context __pad field
Date: Wed, 30 Mar 2016 11:26:55 +0000	[thread overview]
Message-ID: <29b8c208e4c6404e81dff86bb5751255@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <56FBD31C02000078000E13FB@prv-mh.provo.novell.com>

> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 30 March 2016 12:23
> To: Paul Durrant
> Cc: Andrew Cooper; xen-devel@lists.xenproject.org; Keir (Xen.org)
> Subject: Re: [PATCH] x86/hvm/viridian: zero and check vcpu context __pad
> field
> 
> >>> On 30.03.16 at 12:32, <paul.durrant@citrix.com> wrote:
> > --- a/xen/arch/x86/hvm/viridian.c
> > +++ b/xen/arch/x86/hvm/viridian.c
> > @@ -824,6 +824,8 @@ static int viridian_save_vcpu_ctxt(struct domain *d,
> hvm_domain_context_t *h)
> >      for_each_vcpu( d, v ) {
> >          struct hvm_viridian_vcpu_context ctxt;
> >
> > +        memset(&ctxt, 0, sizeof(ctxt));
> 
> How about just adding an empty initializer to the declaration?
> 

I think having a 'zero the entire struct' call at the start is better as it will cover any additions made to the struct in future. It's what I had mistakenly assumed was already there. In fact I think adding a similar call into the domain context save function would probably be worthwhile.

> > @@ -834,6 +836,15 @@ static int viridian_save_vcpu_ctxt(struct domain
> *d, hvm_domain_context_t *h)
> >      return 0;
> >  }
> >
> > +static bool_t is_zero(void *p, size_t size)
> 
> At the very least this wants to be a pointer to const.
> 
> > +{
> > +    while ( size-- )
> > +        if ( *(uint8_t *)p++ != 0 )
> > +            return 0;
> > +
> > +    return 1;
> > +}
> > +
> >  static int viridian_load_vcpu_ctxt(struct domain *d,
> hvm_domain_context_t *h)
> >  {
> >      int vcpuid;
> > @@ -851,6 +862,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d,
> hvm_domain_context_t *h)
> >      if ( hvm_load_entry_zeroextend(VIRIDIAN_VCPU, h, &ctxt) != 0 )
> >          return -EINVAL;
> >
> > +    if ( !is_zero(&ctxt._pad, sizeof(ctxt._pad)) )
> > +        return -EINVAL;
> 
> "memcmp(&ctx._pad, zero_page, sizeof(ctxt._pad))" would be an
> alternative not requiring any new helper function.
> 

Ah, I didn't know about the zero_page definition. I'll use that and drop the helper.

  Paul

> Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-03-30 11:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 10:32 [PATCH] x86/hvm/viridian: zero and check vcpu context __pad field Paul Durrant
2016-03-30 11:22 ` Jan Beulich
2016-03-30 11:26   ` Paul Durrant [this message]
2016-03-30 13:16     ` Jan Beulich
2016-03-30 13:19       ` Paul Durrant
2016-03-30 14:22         ` Jan Beulich
2016-03-30 15:16           ` Paul Durrant
2016-03-30 15:24             ` Jan Beulich

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=29b8c208e4c6404e81dff86bb5751255@AMSPEX02CL03.citrite.net \
    --to=paul.durrant@citrix.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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).