xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Don Slutz <dslutz@verizon.com>
To: Jan Beulich <JBeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Don Slutz <dslutz@verizon.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>,
	Keir Fraser <keir@xen.org>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: Re: [BUGFIX][PATCH 3/4] hvm_save_one: return correct data.
Date: Mon, 16 Dec 2013 12:51:13 -0500	[thread overview]
Message-ID: <52AF3D91.6000809@terremark.com> (raw)
In-Reply-To: <52AEC522020000780010D7BE@nat28.tlf.novell.com>


[-- Attachment #1.1: Type: text/plain, Size: 2608 bytes --]

On 12/16/13 03:17, Jan Beulich wrote:
>>>> On 15.12.13 at 17:51, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>> On 15/12/2013 00:29, Don Slutz wrote:
>>> I think I have corrected all coding errors (please check again). And
>>> done all requested changes.  I did add the reviewed by (not sure if I
>>> should since this changes a large part of the patch, but they are all
>>> what Jan said).
>>>
>>> I have unit tested it and it appears to work the same as the previous
>>> version (as expected).
>>>
>>> Here is the new version, also attached.
>>>
>>>  From e0e8f5246ba492b153884cea93bfe753f1b0782e Mon Sep 17 00:00:00 2001
>>> From: Don Slutz <dslutz@verizon.com>
>>> Date: Tue, 12 Nov 2013 08:22:53 -0500
>>> Subject: [PATCH v2 3/4] hvm_save_one: return correct data.
>>>
>>> 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 <dslutz@verizon.com>
>>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>> but this fairs no better at selecting the correct subset in the case
>> that less data than hvm_sr_handlers[typecode].size is written by
>> hvm_sr_handlers[typecode].save.
> Oh, yes, indeed.
>
>> It always increments by 'size' bytes, and will only copy the data back
>> if the bytes under desc->instance happen to match the instance we are
>> looking for.
>>
>> The only solution I can see is that for the per-vcpu records, the save
>> functions get refactored to take an instance ID, and only save their
>> specific instance.
> I don't see why you shouldn't be able to look at the descriptor
> instead - that one does have the correct size, doesn't it?
>
> Jan
>
Attached is v3 of this.  It is basically a merge of patch #3 and patch #4 with cleanups.

This is what I said in:

http://lists.xen.org/archives/html/xen-devel/2013-12/msg02216.html

and Andrew replied in:

http://lists.xen.org/archives/html/xen-devel/2013-12/msg02217.html

and the RFC is:

http://lists.xen.org/archives/html/xen-devel/2013-12/msg02223.html

to which:

http://lists.xen.org/archives/html/xen-devel/2013-12/msg02270.html

(from this):

        IMHO this is obviously not 4.4 material at this stage. Apart from
        anything else we've been managing to release with these short comings
        for many years.

    Indeed. -George

I feel that the attached bugfix patch is simple enough to make it into 4.4 and also be back ported to stable branches.

    -Don Slutz







[-- Attachment #1.2: Type: text/html, Size: 4354 bytes --]

[-- Attachment #2: 0001-hvm_save_one-return-correct-data.patch --]
[-- Type: text/x-patch, Size: 2370 bytes --]

>From 07897bd0d4a680df03421c0eab96cfa41de2d9f6 Mon Sep 17 00:00:00 2001
From: Don Slutz <dslutz@verizon.com>
Date: Tue, 12 Nov 2013 08:22:53 -0500
Subject: [BUGFIX][PATCH v3 1/1] hvm_save_one: return correct data.

It is possible that hvm_sr_handlers[typecode].save does not use all
the provided room.  Also it can use variable sized records.  In both
cases, 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 <dslutz@verizon.com>
---
changes v2 to v3: merge in patch #4.
changes v1 to v2: fix coding style and coding issues.

 xen/common/hvm/save.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/xen/common/hvm/save.c b/xen/common/hvm/save.c
index de76ada..a7e0edc 100644
--- a/xen/common/hvm/save.c
+++ b/xen/common/hvm/save.c
@@ -98,9 +98,6 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance,
     else 
         sz = hvm_sr_handlers[typecode].size;
     
-    if ( (instance + 1) * hvm_sr_handlers[typecode].size > sz )
-        return -EINVAL;
-
     ctxt.size = sz;
     ctxt.data = xmalloc_bytes(sz);
     if ( !ctxt.data )
@@ -112,13 +109,26 @@ 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;
+        struct hvm_save_descriptor *desc;
+
+        rv = -EBADSLT;
+        for ( off = 0; off < ctxt.cur; off += desc->length )
+        {
+            desc = (void *)ctxt.data + off;
+            /* Move past header */
+            off +=  sizeof(*desc);
+            if ( instance == desc->instance )
+            {
+                rv = 0;
+                if ( copy_to_guest(handle, ctxt.data + off, desc->length) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
 
     xfree(ctxt.data);
     return rv;
-- 
1.8.4


[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

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

  reply	other threads:[~2013-12-16 17:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-12  0:56 [BUGFIX][PATCH 0/4] hvm_save_one: return correct data Don Slutz
2013-12-12  0:56 ` [PATCH 1/4] tools/test: Add check-hvmctx Don Slutz
2013-12-12  0:56 ` [PATCH 2/4] Add tools/tests/offline_module Don Slutz
2013-12-12 10:01   ` Ian Campbell
2013-12-12 11:09     ` David Vrabel
2013-12-12 14:24       ` Don Slutz
2013-12-12 14:32         ` Don Slutz
2013-12-12  0:56 ` [BUGFIX][PATCH 3/4] hvm_save_one: return correct data Don Slutz
2013-12-13 14:20   ` Jan Beulich
2013-12-15  0:29     ` Don Slutz
2013-12-15 16:51       ` Andrew Cooper
2013-12-15 17:19         ` Don Slutz
2013-12-15 17:22           ` Andrew Cooper
2013-12-15 17:42             ` Don Slutz
2013-12-15 18:11               ` Andrew Cooper
2013-12-15 18:41                 ` Don Slutz
2013-12-15 19:06                   ` Andrew Cooper
2013-12-15 19:23                     ` Don Slutz
2013-12-16  8:17         ` Jan Beulich
2013-12-16 17:51           ` Don Slutz [this message]
2013-12-16 18:33             ` Andrew Cooper
2013-12-22 19:40               ` Don Slutz
2013-12-22 21:13                 ` Andrew Cooper
2014-01-07 15:55                 ` Keir Fraser
2013-12-17  8:20             ` Jan Beulich
2013-12-17 10:40               ` Andrew Cooper
2013-12-20  0:32                 ` Don Slutz
2013-12-20 13:31                   ` George Dunlap
2013-12-22 19:44                     ` Don Slutz
2013-12-17 15:58               ` Don Slutz
2013-12-12  0:56 ` [BUGFIX][PATCH 4/4] hvm_save_one: allow the 2nd instance to be fetched for PIC Don Slutz
2013-12-13 14:38   ` Jan Beulich
2013-12-15  1:38     ` Don Slutz
2013-12-16  8:22       ` 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=52AF3D91.6000809@terremark.com \
    --to=dslutz@verizon.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --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).