From: "Jan Beulich" Subject: Re: [BUGFIX][PATCH 3/4] hvm_save_one: return correct data. Date: Fri, 13 Dec 2013 14:20:20 +0000 Message-ID: <52AB25B4020000780010D0B0@nat28.tlf.novell.com> References: <1386809777-12898-1-git-send-email-dslutz@terremark.com> <1386809777-12898-4-git-send-email-dslutz@terremark.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VrTbL-0005H7-IS for xen-devel@lists.xenproject.org; Fri, 13 Dec 2013 14:20:23 +0000 In-Reply-To: <1386809777-12898-4-git-send-email-dslutz@terremark.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Don Slutz Cc: xen-devel , Keir Fraser , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org >>> On 12.12.13 at 01:56, Don Slutz wrote: > From: Don Slutz > > It is possible that hvm_sr_handlers[typecode].save does not use all > the provided room. In that case, using: > > instance * hvm_sr_handlers[typecode].size > > does not select the correct instance. Add code to search for the > correct instance. > > Signed-off-by: Don Slutz Reviewed-by: Jan Beulich But this needs to be cleaned up coding style wise and ... > --- a/xen/common/hvm/save.c > +++ b/xen/common/hvm/save.c > @@ -112,13 +112,27 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, > d->domain_id, typecode); > rv = -EFAULT; > } > - else if ( copy_to_guest(handle, > - ctxt.data > - + (instance * hvm_sr_handlers[typecode].size) > - + sizeof (struct hvm_save_descriptor), > - hvm_sr_handlers[typecode].size > - - sizeof (struct hvm_save_descriptor)) ) > - rv = -EFAULT; > + else > + { > + uint32_t off; > + > + rv = -EBADSLT; > + for (off = 0; off < ctxt.cur; off += hvm_sr_handlers[typecode].size) { > + struct hvm_save_descriptor *desc > + = (struct hvm_save_descriptor *)&ctxt.data[off]; .. this could be const, and the cast could simply be (void *), ... > + if (instance == desc->instance) { > + rv = 0; > + if ( copy_to_guest(handle, > + ctxt.data > + + off ... this doesn't need to be on a separate line, and ... > + + sizeof (struct hvm_save_descriptor), > + hvm_sr_handlers[typecode].size > + - sizeof (struct hvm_save_descriptor)) ) ... both these sizeof()s would now better be sizeof(*desc). Jan