All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>
Subject: [PATCH 2/2] HVM: clean up hvm_save_one()
Date: Wed, 31 May 2017 01:25:26 -0600	[thread overview]
Message-ID: <592E8C06020000780015DFD4@prv-mh.provo.novell.com> (raw)
In-Reply-To: <592E8AB8020000780015DFA8@prv-mh.provo.novell.com>

[-- Attachment #1: Type: text/plain, Size: 2100 bytes --]

Eliminate the for_each_vcpu() loop and the associated local variables,
don't override the save handler's return code, and correct formatting.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/hvm/save.c
+++ b/xen/common/hvm/save.c
@@ -79,36 +79,27 @@ size_t hvm_save_size(struct domain *d)
 int hvm_save_one(struct domain *d, unsigned int typecode, unsigned int instance,
                  XEN_GUEST_HANDLE_64(uint8) handle, uint64_t *bufsz)
 {
-    int rv = -ENOENT;
-    size_t sz = 0;
-    struct vcpu *v;
-    hvm_domain_context_t ctxt = { 0, };
+    int rv;
+    hvm_domain_context_t ctxt = { };
     const struct hvm_save_descriptor *desc;
 
-    if ( d->is_dying 
-         || typecode > HVM_SAVE_CODE_MAX 
-         || hvm_sr_handlers[typecode].size < sizeof(*desc)
-         || hvm_sr_handlers[typecode].save == NULL )
+    if ( d->is_dying ||
+         typecode > HVM_SAVE_CODE_MAX ||
+         hvm_sr_handlers[typecode].size < sizeof(*desc) ||
+         !hvm_sr_handlers[typecode].save )
         return -EINVAL;
 
+    ctxt.size = hvm_sr_handlers[typecode].size;
     if ( hvm_sr_handlers[typecode].kind == HVMSR_PER_VCPU )
-        for_each_vcpu(d, v)
-            sz += hvm_sr_handlers[typecode].size;
-    else 
-        sz = hvm_sr_handlers[typecode].size;
-    
-    ctxt.size = sz;
-    ctxt.data = xmalloc_bytes(sz);
+        hvm_sr_handlers[typecode].size *= d->max_vcpus;
+    ctxt.data = xmalloc_bytes(ctxt.size);
     if ( !ctxt.data )
         return -ENOMEM;
 
-    if ( hvm_sr_handlers[typecode].save(d, &ctxt) != 0 )
-    {
-        printk(XENLOG_G_ERR "HVM%d save: failed to save type %"PRIu16"\n",
-               d->domain_id, typecode);
-        rv = -EFAULT;
-    }
-    else if ( ctxt.cur >= sizeof(*desc) )
+    if ( (rv = hvm_sr_handlers[typecode].save(d, &ctxt)) != 0 )
+        printk(XENLOG_G_ERR "HVM%d save: failed to save type %"PRIu16" (%d)\n",
+               d->domain_id, typecode, rv);
+    else if ( rv = -ENOENT, ctxt.cur >= sizeof(*desc) )
     {
         uint32_t off;
 




[-- Attachment #2: HVM-save-one-cleanup.patch --]
[-- Type: text/plain, Size: 2126 bytes --]

HVM: clean up hvm_save_one()

Eliminate the for_each_vcpu() loop and the associated local variables,
don't override the save handler's return code, and correct formatting.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/hvm/save.c
+++ b/xen/common/hvm/save.c
@@ -79,36 +79,27 @@ size_t hvm_save_size(struct domain *d)
 int hvm_save_one(struct domain *d, unsigned int typecode, unsigned int instance,
                  XEN_GUEST_HANDLE_64(uint8) handle, uint64_t *bufsz)
 {
-    int rv = -ENOENT;
-    size_t sz = 0;
-    struct vcpu *v;
-    hvm_domain_context_t ctxt = { 0, };
+    int rv;
+    hvm_domain_context_t ctxt = { };
     const struct hvm_save_descriptor *desc;
 
-    if ( d->is_dying 
-         || typecode > HVM_SAVE_CODE_MAX 
-         || hvm_sr_handlers[typecode].size < sizeof(*desc)
-         || hvm_sr_handlers[typecode].save == NULL )
+    if ( d->is_dying ||
+         typecode > HVM_SAVE_CODE_MAX ||
+         hvm_sr_handlers[typecode].size < sizeof(*desc) ||
+         !hvm_sr_handlers[typecode].save )
         return -EINVAL;
 
+    ctxt.size = hvm_sr_handlers[typecode].size;
     if ( hvm_sr_handlers[typecode].kind == HVMSR_PER_VCPU )
-        for_each_vcpu(d, v)
-            sz += hvm_sr_handlers[typecode].size;
-    else 
-        sz = hvm_sr_handlers[typecode].size;
-    
-    ctxt.size = sz;
-    ctxt.data = xmalloc_bytes(sz);
+        hvm_sr_handlers[typecode].size *= d->max_vcpus;
+    ctxt.data = xmalloc_bytes(ctxt.size);
     if ( !ctxt.data )
         return -ENOMEM;
 
-    if ( hvm_sr_handlers[typecode].save(d, &ctxt) != 0 )
-    {
-        printk(XENLOG_G_ERR "HVM%d save: failed to save type %"PRIu16"\n",
-               d->domain_id, typecode);
-        rv = -EFAULT;
-    }
-    else if ( ctxt.cur >= sizeof(*desc) )
+    if ( (rv = hvm_sr_handlers[typecode].save(d, &ctxt)) != 0 )
+        printk(XENLOG_G_ERR "HVM%d save: failed to save type %"PRIu16" (%d)\n",
+               d->domain_id, typecode, rv);
+    else if ( rv = -ENOENT, ctxt.cur >= sizeof(*desc) )
     {
         uint32_t off;
 

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

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

  parent reply	other threads:[~2017-05-31  7:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31  7:19 [PATCH 0/2] hvm/save: cleanup Jan Beulich
2017-05-31  7:24 ` [PATCH 1/2] HVM: sanitize DOMCTL_gethvmcontext_partial handling Jan Beulich
2017-05-31 12:11   ` Wei Liu
2017-05-31  7:25 ` Jan Beulich [this message]
2017-06-06 17:52   ` [PATCH 2/2] HVM: clean up hvm_save_one() Wei Liu
2017-06-07 10:07     ` Jan Beulich
2017-06-07 10:29       ` Wei Liu
2017-06-07 10:39         ` Jan Beulich
2017-06-06 15:49 ` Ping: [PATCH 0/2] hvm/save: cleanup 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=592E8C06020000780015DFD4@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.