Skip to contentSkip to conversation

hvm_save_one: return correct data.

PATCH In review Don Slutz 7 participants 34 messages Dec 12, 2013 – Jan 7, 2014

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

cover hvm_save_one: return correct data.

From: Don Slutz <[email protected]>

Without this xenctx can return incorrect register values. Also xc_translate_foreign_address might do the wrong thing.

Patch #1 is unit test code.
Patch #2 is quick and dirty linux kernel module to offline some cpus Patch #3 fixes the offline VCPU handling.
Patch #4 fixes hvm_save_one to be able to return PIC instance 1.

State:

# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  2048     8     r-----      58.0
P-8-0                                        1  3080     8     r-----      27.1
# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  2048     8     r-----      66.8
P-8-0                                        1  3080     1     ------      45.0

Before:

# ./check-hvmctx 1
Check HVM save record vs partial for domain 1
Error: entry 1: type 2 instance 2, length 1024 mismatch!
    CPU:    rax 0x0000000000000000     rbx 0xffffffff8006b287

(And PIC issue:)

# ./check-hvmctx 1
Check HVM save record vs partial for domain 1
Error: entry 1: type 2 instance 2, length 1024 mismatch!
    CPU:    rax 0x0000000000000000     rbx 0xffffffff8006b287
Error: xc_domain_hvm_getcontext_partial: entry 3: type 3 instance 1, length 8: Invalid argument
Error: entry 3: type 3 instance 1, length 8 mismatch!
    PIC: IRQ base 0x28, irr 0x11, imr 0xff, isr 0

After:

# ./check-hvmctx 1
Check HVM save record vs partial for domain 1

Don Slutz (4):
tools/test: Add check-hvmctx
Add tools/tests/offline_module
hvm_save_one: return correct data.
hvm_save_one: allow the 2nd instance to be fetched for PIC.

 tools/tests/check-hvmctx/.gitignore     |   1 +
 tools/tests/check-hvmctx/Makefile       |  34 ++
 tools/tests/check-hvmctx/README         |  21 +
 tools/tests/check-hvmctx/check-hvmctx.c | 661 ++++++++++++++++++++++++++++++++
 tools/tests/offline_module/.gitignore   |   8 +
 tools/tests/offline_module/Makefile     |  10 +
 tools/tests/offline_module/README       |  37 ++
 tools/tests/offline_module/offline.c    |  89 +++++
 xen/common/hvm/save.c                   |  31 +-
 9 files changed, 882 insertions(+), 10 deletions(-)
 create mode 100644 tools/tests/check-hvmctx/.gitignore
 create mode 100644 tools/tests/check-hvmctx/Makefile
 create mode 100644 tools/tests/check-hvmctx/README
 create mode 100644 tools/tests/check-hvmctx/check-hvmctx.c
 create mode 100644 tools/tests/offline_module/.gitignore
 create mode 100644 tools/tests/offline_module/Makefile
 create mode 100644 tools/tests/offline_module/README
 create mode 100644 tools/tests/offline_module/offline.c
Signature · 1 line
1.8.4
author
#1 lore raw

PATCH 1/4 tools/test: Add check-hvmctx

From: Don Slutz <[email protected]>

This is a unit test for xc_domain_hvm_getcontext_partial vs xc_domain_hvm_getcontext.

---
 tools/tests/check-hvmctx/.gitignore     |   1 +
 tools/tests/check-hvmctx/Makefile       |  34 ++
 tools/tests/check-hvmctx/README         |  21 +
 tools/tests/check-hvmctx/check-hvmctx.c | 661 ++++++++++++++++++++++++++++++++
 4 files changed, 717 insertions(+)
 create mode 100644 tools/tests/check-hvmctx/.gitignore
 create mode 100644 tools/tests/check-hvmctx/Makefile
 create mode 100644 tools/tests/check-hvmctx/README
 create mode 100644 tools/tests/check-hvmctx/check-hvmctx.c
tools/tests/check-hvmctx/.gitignore new file +1 -0
new file mode 100644
index 0000000..e2dabd8
@@ -0,0 +1 @@
+check-hvmctx
tools/tests/check-hvmctx/Makefile new file +34 -0
new file mode 100644
index 0000000..dce7508
@@ -0,0 +1,34 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+CFLAGS += -Werror
+
+CFLAGS += $(CFLAGS_libxenctrl)
+CFLAGS += $(CFLAGS_xeninclude)
+CFLAGS += $(CFLAGS_libxenstore)
+
+HDRS     = $(wildcard *.h)
+
+TARGETS-$(CONFIG_X86) += check-hvmctx
+TARGETS := $(TARGETS-y)
+
+# Include configure output (config.h) to headers search path
+CFLAGS += -I$(XEN_ROOT)/tools
+
+# Allow special builds
+CFLAGS += $(CHECK_HVMCTX)
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build: $(TARGETS) Makefile
+
+.PHONY: clean
+clean:
+	$(RM) *.o $(TARGETS) *~ $(DEPS)
+
+check-hvmctx: check-hvmctx.o Makefile
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+
+-include $(DEPS)
tools/tests/check-hvmctx/README new file +21 -0
new file mode 100644
index 0000000..0d70df4
@@ -0,0 +1,21 @@
+Check that xc_domain_hvm_getcontext_partial gets the same data as
+xc_domain_hvm_getcontext.
+
+To see the bug about offline VCPU(s) you can use the offline_module
+(offline.ko) in a domU.
+
+To see the bug about PIC:
+
+make clean;make CHECK_HVMCTX="-DDOPIC"
+
+To never report a time based issue (I see it about 1 out of 50):
+
+make clean;make CHECK_HVMCTX="-DFULLCLEAN"
+
+To see time based issues:
+
+make clean;make CHECK_HVMCTX="-DNOTCLEAN"
+
+Normal:
+
+make clean;make
tools/tests/check-hvmctx/check-hvmctx.c new file +661 -0

661 lines not on this page · raw message

Signature · 1 line
1.8.4
author
#2 lore raw

PATCH 2/4 Add tools/tests/offline_module

In reply to Don Slutz

From: Don Slutz <[email protected]>

This is a quick and dirty linux kernel module to offline some cpus as far as Xen knows.

This can be used to re-create the bug in hvm_save_one about returning the wrong data.

---
 tools/tests/offline_module/.gitignore |  8 ++++
 tools/tests/offline_module/Makefile   | 10 ++++
 tools/tests/offline_module/README     | 37 +++++++++++++++
 tools/tests/offline_module/offline.c  | 89 +++++++++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+)
 create mode 100644 tools/tests/offline_module/.gitignore
 create mode 100644 tools/tests/offline_module/Makefile
 create mode 100644 tools/tests/offline_module/README
 create mode 100644 tools/tests/offline_module/offline.c
tools/tests/offline_module/.gitignore new file +8 -0
new file mode 100644
index 0000000..0a0b67b
@@ -0,0 +1,8 @@
+.offline.ko.cmd
+.offline.mod.o.cmd
+.offline.o.cmd
+.tmp_versions
+Module.symvers
+modules.order
+offline.ko
+offline.mod.c
tools/tests/offline_module/Makefile new file +10 -0
new file mode 100644
index 0000000..8fd246f
@@ -0,0 +1,10 @@
+obj-m	:= offline.o
+
+KDIR	:= /lib/modules/$(shell uname -r)/build
+PWD	:= $(shell pwd)
+
+all:
+	make -C $(KDIR) SUBDIRS=$(PWD) modules
+
+clean:
+	make -C $(KDIR) SUBDIRS=$(PWD) clean
tools/tests/offline_module/README new file +37 -0
new file mode 100644
index 0000000..9bc0e01
@@ -0,0 +1,37 @@
+This is a quick and dirty linux kernel module to offline some cpus
+as far as Xen knows.
+
+This can be used to re-create the bug in hvm_save_one about
+returning the wrong data.
+
+You only need the 2 files: Makefile and offline.c alone in some
+directory on DomU.  "make" should build the kernel module.
+
+to leave just cpu 3 (id #2) of 8 (id #0-#7) running:
+
+taskset 0x4 insmod offline.ko who=0xff
+
+
+Note: Not sure when, but older kernels (2.6.18 for example) have:
+
+/*
+ * smp_call_function - run a function on all other CPUs.
+ * @func: The function to run. This must be fast and non-blocking.
+ * @info: An arbitrary pointer to pass to the function.
+ * @nonatomic: currently unused.
+ * @wait: If true, wait (atomically) until function has completed on other
+ *        CPUs.
+ * Returns 0 on success, else a negative status code. Does not return until
+ * remote CPUs are nearly ready to execute func or are or have executed.
+
+
+Instead of:
+
+/**                                                                             
+ * smp_call_function(): Run a function on all other CPUs.                       
+ * @func: The function to run. This must be fast and non-blocking.              
+ * @info: An arbitrary pointer to pass to the function.                         
+ * @wait: If true, wait (atomically) until function has completed               
+ *        on other CPUs.                                                        
+ *                                                                              
+ * Returns 0.                                                                   
tools/tests/offline_module/offline.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
1.8.4
#3 lore raw

Re: [PATCH 2/4] Add tools/tests/offline_module

Quoted 7 lines · Don Slutz

From: Don Slutz <[email protected]>

This is a quick and dirty linux kernel module to offline some cpus as far as Xen knows.

This can be used to re-create the bug in hvm_save_one about returning the wrong data.

Can this not be done via /sys/devices/system/cpu/cpu1/online etc? Documentation/cpu-hotplug.txt seems to suggest it can.

Ian.

#4 lore raw

Re: [PATCH 2/4] Add tools/tests/offline_module

Quoted 11 lines · Ian Campbell
Quoted 7 lines · Don Slutz

From: Don Slutz <[email protected]>

This is a quick and dirty linux kernel module to offline some cpus as far as Xen knows.

This can be used to re-create the bug in hvm_save_one about returning the wrong data.

Can this not be done via /sys/devices/system/cpu/cpu1/online etc? Documentation/cpu-hotplug.txt seems to suggest it can.

Yes it can.

echo 0 > /sys/devices/system/cpu/cpuN/online

And onlined again with 1.

David

author
#5 lore raw

Re: [PATCH 2/4] Add tools/tests/offline_module

Quoted 12 lines · David Vrabel
Quoted 11 lines · Ian Campbell
Quoted 11 lines · Don Slutz
Quoted 7 lines
Quoted 7 lines

From: Don Slutz<[email protected]>

This is a quick and dirty linux kernel module to offline some cpus as far as Xen knows.

This can be used to re-create the bug in hvm_save_one about returning the wrong data.

Can this not be done via /sys/devices/system/cpu/cpu1/online etc? Documentation/cpu-hotplug.txt seems to suggest it can.

Quoted 7 lines

Yes it can.

echo 0 > /sys/devices/system/cpu/cpuN/online

And onlined again with 1.

David

I had forgotten about that when I was testing. At least on 2.6.18-128.el5, cpu 0 does not work:

[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu0/online
-bash: /sys/devices/system/cpu/cpu0/online: Permission denied
[root@P-8-0 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=root:system_r:unconfined_t:SystemLow-SystemHigh [root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu1/online
[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu3/online
[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu5/online
[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu7/online

And making cpu 0 offline was something I wanted to test.
-Don Slutz

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#6 lore raw

Re: [PATCH 2/4] Add tools/tests/offline_module

Quoted 10 lines · Don Slutz
Quoted 9 lines · David Vrabel
Quoted 8 lines · Ian Campbell
Quoted 8 lines · Don Slutz
Quoted 7 lines
Quoted 7 lines

From: Don Slutz<[email protected]>

This is a quick and dirty linux kernel module to offline some cpus as far as Xen knows.

This can be used to re-create the bug in hvm_save_one about returning the wrong data.

Opps, I should have added "No need to accept or apply this patch." here and in the cover letter.
-Don Slutz

Quoted 21 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

Can this not be done via /sys/devices/system/cpu/cpu1/online etc? Documentation/cpu-hotplug.txt seems to suggest it can.

Yes it can.

echo 0 > /sys/devices/system/cpu/cpuN/online

And onlined again with 1.

David

I had forgotten about that when I was testing. At least on 2.6.18-128.el5, cpu 0 does not work:

[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu0/online
-bash: /sys/devices/system/cpu/cpu0/online: Permission denied
[root@P-8-0 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=root:system_r:unconfined_t:SystemLow-SystemHigh [root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu1/online
[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu3/online
[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu5/online
[root@P-8-0 ~]# echo 0 > /sys/devices/system/cpu/cpu7/online

Quoted 2 lines

And making cpu 0 offline was something I wanted to test.
-Don Slutz

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#7 lore raw

PATCH 3/4 hvm_save_one: return correct data.

In reply to Don Slutz

From: Don Slutz <[email protected]>

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.

---
 xen/common/hvm/save.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
xen/common/hvm/save.c +21 -7
index de76ada..ff6e910 100644
@@ -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];
+            if (instance == desc->instance) {
+                rv = 0;
+                if ( copy_to_guest(handle,
+                                   ctxt.data
+                                   + off
+                                   + sizeof (struct hvm_save_descriptor),
+                                   hvm_sr_handlers[typecode].size
+                                   - sizeof (struct hvm_save_descriptor)) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
 
     xfree(ctxt.data);
     return rv;
Signature · 1 line
1.8.4
Reviewed-by on v1 3/4
#8 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Don Slutz

From: Don Slutz <[email protected]>

It is possible that hvm_sr_handlers[typecode].save does not use all the provided room. In that case, using:

Quoted 6 lines

instance * hvm_sr_handlers[typecode].size

does not select the correct instance. Add code to search for the correct instance.

But this needs to be cleaned up coding style wise and ...

Quoted 11 lines
xen/common/hvm/save.c +0 -5
@@ -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

xen/common/hvm/save.c int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 122

Quoted 10 lines
xen/common/hvm/save.c +8 -2
-                            - 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 *), ...

xen/common/hvm/save.c int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 127

Quoted 5 lines
xen/common/hvm/save.c +5 -0
+            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 ...

xen/common/hvm/save.c int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 130

Quoted 3 lines
xen/common/hvm/save.c +3 -0
+                                   + 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

author Reviewed-by Jan Beulich Reviewed-by Jan Beulich
#9 lore raw
Quoted 40 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Don Slutz

From: Don Slutz <[email protected]>

It is possible that hvm_sr_handlers[typecode].save does not use all the provided room. In that case, using:

Quoted 6 lines

instance * hvm_sr_handlers[typecode].size

does not select the correct instance. Add code to search for the correct instance.

But this needs to be cleaned up coding style wise and ...

Quoted 6 lines

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

Quoted 8 lines

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 *), ...

Quoted 3 lines

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

Quoted 9 lines
Quoted 4 lines

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

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 <[email protected]>
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.

---
 xen/common/hvm/save.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
xen/common/hvm/save.c +21 -7
index de76ada..6aaea6f 100644
@@ -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 )
+        {
+            const struct hvm_save_descriptor *desc = (void *)&ctxt.data[off];
+
+            if ( instance == desc->instance )
+            {
+                rv = 0;
+                if ( copy_to_guest(handle,
+                                   ctxt.data + off + sizeof(*desc),
+                                   hvm_sr_handlers[typecode].size
+                                   - sizeof(*desc)) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
 
     xfree(ctxt.data);
     return rv;
Signature · 3 lines
1.7.11.7

   -Don Slutz
Quoted 1 line

From e0e8f5246ba492b153884cea93bfe753f1b0782e Mon Sep 17 00:00:00 2001

From: Don Slutz <[email protected]>
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.

---
 xen/common/hvm/save.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
xen/common/hvm/save.c +21 -7
index de76ada..6aaea6f 100644
@@ -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 )
+        {
+            const struct hvm_save_descriptor *desc = (void *)&ctxt.data[off];
+
+            if ( instance == desc->instance )
+            {
+                rv = 0;
+                if ( copy_to_guest(handle,
+                                   ctxt.data + off + sizeof(*desc),
+                                   hvm_sr_handlers[typecode].size
+                                   - sizeof(*desc)) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
 
     xfree(ctxt.data);
     return rv;
Signature · 1 line
1.7.11.7

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw
Quoted 19 lines · Don Slutz

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 <[email protected]>
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:

Quoted 7 lines

instance * hvm_sr_handlers[typecode].size

does not select the correct instance. Add code to search for the correct instance.

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.

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 shall have a go at this and see how invasive it is.

~Andrew

Quoted 49 lines
---
 xen/common/hvm/save.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
xen/common/hvm/save.c +8 -7
index de76ada..6aaea6f 100644
@@ -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 )
+        {
+            const struct hvm_save_descriptor *desc = (void

*)&ctxt.data[off];

xen/common/hvm/save.c +13 -0
+
+            if ( instance == desc->instance )
+            {
+                rv = 0;
+                if ( copy_to_guest(handle,
+                                   ctxt.data + off + sizeof(*desc),
+                                   hvm_sr_handlers[typecode].size
+                                   - sizeof(*desc)) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
 
     xfree(ctxt.data);
     return rv;
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#11 lore raw
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Don Slutz

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 <[email protected]>
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

Quoted 8 lines
Quoted 5 lines

does not select the correct instance. Add code to search for the correct instance.

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.

True, but the inverse is the case here; .save writes 'n' 'size' blocks. Form the loop above:

    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;

so sz is in multiples of 'size'. Normally sz == ctxt.cur. With some offline vcpus it write fewer 'size' blocks.

Quoted 2 lines

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 time it does not find one is for an offline vcpu. Try out the unit test code in patch #1 on an unchanged xen. It should not display anything. Then offline a cpu in a domU (echo 0 > /sys/devices/system/cpu/cpu1/online). And with 3 vcpus, it will report an error.

-Don Slutz

Quoted 51 lines

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 shall have a go at this and see how invasive it is.

~Andrew

Quoted 45 lines
---
 xen/common/hvm/save.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
xen/common/hvm/save.c +8 -7
index de76ada..6aaea6f 100644
@@ -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 )
+        {
+            const struct hvm_save_descriptor *desc = (void 

*)&ctxt.data[off];

xen/common/hvm/save.c +13 -0
+
+            if ( instance == desc->instance )
+            {
+                rv = 0;
+                if ( copy_to_guest(handle,
+                                   ctxt.data + off + sizeof(*desc),
+ hvm_sr_handlers[typecode].size
+                                   - sizeof(*desc)) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
Quoted 9 lines
Quoted 8 lines
     xfree(ctxt.data);
     return rv;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw
Quoted 48 lines · Don Slutz
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Don Slutz

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 <[email protected]>
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.

Quoted 7 lines
Quoted 2 lines

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.

True, but the inverse is the case here; .save writes 'n' 'size' blocks. Form the loop above:

    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;

so sz is in multiples of 'size'. Normally sz == ctxt.cur. With some offline vcpus it write fewer 'size' blocks.

Quoted 4 lines

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.

Quoted 7 lines

The only time it does not find one is for an offline vcpu. Try out the unit test code in patch #1 on an unchanged xen. It should not display anything. Then offline a cpu in a domU (echo 0 > /sys/devices/system/cpu/cpu1/online). And with 3 vcpus, it will report an error.

-Don Slutz

Ah - so there are actually two problems. I see now the one you are trying to solve, and would agree that your code does solve it.

However, some of the save handlers are themselves variable length, and will write records shorter than hvm_sr_handlers[typecode].size if they can get away with doing so. In this case, the new logic still wont get the correct instance.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#13 lore raw
Quoted 39 lines · Andrew Cooper
Quoted 38 lines · Don Slutz
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Don Slutz

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 <[email protected]>
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

Quoted 8 lines
Quoted 5 lines

does not select the correct instance. Add code to search for the correct instance.

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.

True, but the inverse is the case here; .save writes 'n' 'size' blocks. Form the loop above:

    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;

so sz is in multiples of 'size'. Normally sz == ctxt.cur. With some offline vcpus it write fewer 'size' blocks.

Quoted 2 lines

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.

Quoted 8 lines
Quoted 3 lines

The only time it does not find one is for an offline vcpu. Try out the unit test code in patch #1 on an unchanged xen. It should not display anything. Then offline a cpu in a domU (echo 0 > /sys/devices/system/cpu/cpu1/online). And with 3 vcpus, it will report an error.

-Don Slutz

Ah - so there are actually two problems. I see now the one you are trying to solve, and would agree that your code does solve it.

However, some of the save handlers are themselves variable length, and will write records shorter than hvm_sr_handlers[typecode].size if they can get away with doing so. In this case, the new logic still wont get the correct instance.

Not sure which one(s) you are referring to.

From the full dump:

xen-hvmctx 1| grep -i entry
Entry 0: type 1 instance 0, length 24 Entry 1: type 2 instance 0, length 1024 Entry 2: type 2 instance 2, length 1024 Entry 3: type 2 instance 3, length 1024 Entry 4: type 2 instance 4, length 1024 Entry 5: type 2 instance 5, length 1024 Entry 6: type 2 instance 6, length 1024 Entry 7: type 2 instance 7, length 1024 Entry 8: type 3 instance 0, length 8 Entry 9: type 3 instance 1, length 8 Entry 10: type 4 instance 0, length 400 Entry 11: type 5 instance 0, length 24 Entry 12: type 5 instance 1, length 24 Entry 13: type 5 instance 2, length 24 Entry 14: type 5 instance 3, length 24 Entry 15: type 5 instance 4, length 24 Entry 16: type 5 instance 5, length 24 Entry 17: type 5 instance 6, length 24 Entry 18: type 5 instance 7, length 24 Entry 19: type 6 instance 0, length 1024 Entry 20: type 6 instance 1, length 1024 Entry 21: type 6 instance 2, length 1024 Entry 22: type 6 instance 3, length 1024 Entry 23: type 6 instance 4, length 1024 Entry 24: type 6 instance 5, length 1024 Entry 25: type 6 instance 6, length 1024 Entry 26: type 6 instance 7, length 1024 Entry 27: type 7 instance 0, length 16 Entry 28: type 8 instance 0, length 8 Entry 29: type 9 instance 0, length 8 Entry 30: type 10 instance 0, length 56 Entry 31: type 11 instance 0, length 16 Entry 32: type 12 instance 0, length 1048 Entry 33: type 13 instance 0, length 8 Entry 34: type 14 instance 0, length 240 Entry 35: type 14 instance 1, length 240 Entry 36: type 14 instance 2, length 240 Entry 37: type 14 instance 3, length 240 Entry 38: type 14 instance 4, length 240 Entry 39: type 14 instance 5, length 240 Entry 40: type 14 instance 6, length 240 Entry 41: type 14 instance 7, length 240 Entry 42: type 16 instance 0, length 856 Entry 43: type 16 instance 1, length 856 Entry 44: type 16 instance 2, length 856 Entry 45: type 16 instance 3, length 856 Entry 46: type 16 instance 4, length 856 Entry 47: type 16 instance 5, length 856 Entry 48: type 16 instance 6, length 856 Entry 49: type 16 instance 7, length 856 Entry 50: type 18 instance 0, length 24 Entry 51: type 18 instance 1, length 24 Entry 52: type 18 instance 2, length 24 Entry 53: type 18 instance 3, length 24 Entry 54: type 18 instance 4, length 24 Entry 55: type 18 instance 5, length 24 Entry 56: type 18 instance 6, length 24 Entry 57: type 18 instance 7, length 24 Entry 58: type 19 instance 0, length 8 Entry 59: type 19 instance 1, length 8 Entry 60: type 19 instance 2, length 8 Entry 61: type 19 instance 3, length 8 Entry 62: type 19 instance 4, length 8 Entry 63: type 19 instance 5, length 8 Entry 64: type 19 instance 6, length 8 Entry 65: type 19 instance 7, length 8 Entry 66: type 0 instance 0, length 0

All typecode's appear to save the same amount per instance.

Most use hvm_save_entry:

...

        _hvm_write_entry((_h), (_src), HVM_SAVE_LENGTH(_x));    \

and

/* Syntactic sugar around that function: specify the max number of
* saves, and this calculates the size of buffer needed */
#define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num, _k) \
static int __init __hvm_register_##_x##_save_and_restore(void) \
{ \
hvm_register_savevm(HVM_SAVE_CODE(_x), \

#_x,                                              \
&_save,                                           \
&_load,                                           \
                        (_num) * (HVM_SAVE_LENGTH(_x)                     \
                                  + sizeof (struct hvm_save_descriptor)), \
_k);                                              \
    return 0;                                                             \
} \

I do not find any that call on _hvm_write_entry directly.

The only special one I found: CPU_XSAVE_CODE

Still "writes" a full sized entry:

        if ( _hvm_init_entry(h, CPU_XSAVE_CODE, v->vcpu_id, 
HVM_CPU_XSAVE_SIZE) )
            return 1;
        ctxt = (struct hvm_hw_cpu_xsave *)&h->data[h->cur];
        h->cur += HVM_CPU_XSAVE_SIZE;
        memset(ctxt, 0, HVM_CPU_XSAVE_SIZE);

It then modifies the zeros conditionaly.

        if ( v->fpu_initialised )
            memcpy(&ctxt->save_area,
                v->arch.xsave_area, xsave_cntxt_size);

#define HVM_CPU_XSAVE_SIZE (3 * sizeof(uint64_t) + xsave_cntxt_size)

is part of this.

/* We need variable length data chunk for xsave area, hence customized
* declaration other than HVM_REGISTER_SAVE_RESTORE.
*/
static int __init __hvm_register_CPU_XSAVE_save_and_restore(void) {
hvm_register_savevm(CPU_XSAVE_CODE,
"CPU_XSAVE", hvm_save_cpu_xsave_states, hvm_load_cpu_xsave_states, HVM_CPU_XSAVE_SIZE + sizeof (struct
hvm_save_descriptor),

                        HVMSR_PER_VCPU);
    return 0;
}

__initcall(__hvm_register_CPU_XSAVE_save_and_restore);

is the final part of this one. So I do not find any code that does what you are wondering about.

-Don

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw
Quoted 217 lines · Don Slutz
Quoted 58 lines · Andrew Cooper
Quoted 49 lines · Don Slutz
Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Don Slutz

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 <[email protected]>
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.

Quoted 7 lines
Quoted 2 lines

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.

True, but the inverse is the case here; .save writes 'n' 'size' blocks. Form the loop above:

    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;

so sz is in multiples of 'size'. Normally sz == ctxt.cur. With some offline vcpus it write fewer 'size' blocks.

Quoted 4 lines

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.

Quoted 7 lines

The only time it does not find one is for an offline vcpu. Try out the unit test code in patch #1 on an unchanged xen. It should not display anything. Then offline a cpu in a domU (echo 0 > /sys/devices/system/cpu/cpu1/online). And with 3 vcpus, it will report an error.

-Don Slutz

Quoted 8 lines

Ah - so there are actually two problems. I see now the one you are trying to solve, and would agree that your code does solve it.

However, some of the save handlers are themselves variable length, and will write records shorter than hvm_sr_handlers[typecode].size if they can get away with doing so. In this case, the new logic still wont get the correct instance.

Not sure which one(s) you are referring to.

From the full dump:

xen-hvmctx 1| grep -i entry
Entry 0: type 1 instance 0, length 24 Entry 1: type 2 instance 0, length 1024 Entry 2: type 2 instance 2, length 1024 Entry 3: type 2 instance 3, length 1024 Entry 4: type 2 instance 4, length 1024 Entry 5: type 2 instance 5, length 1024 Entry 6: type 2 instance 6, length 1024 Entry 7: type 2 instance 7, length 1024 Entry 8: type 3 instance 0, length 8 Entry 9: type 3 instance 1, length 8 Entry 10: type 4 instance 0, length 400 Entry 11: type 5 instance 0, length 24 Entry 12: type 5 instance 1, length 24 Entry 13: type 5 instance 2, length 24 Entry 14: type 5 instance 3, length 24 Entry 15: type 5 instance 4, length 24 Entry 16: type 5 instance 5, length 24 Entry 17: type 5 instance 6, length 24 Entry 18: type 5 instance 7, length 24 Entry 19: type 6 instance 0, length 1024 Entry 20: type 6 instance 1, length 1024 Entry 21: type 6 instance 2, length 1024 Entry 22: type 6 instance 3, length 1024 Entry 23: type 6 instance 4, length 1024 Entry 24: type 6 instance 5, length 1024 Entry 25: type 6 instance 6, length 1024 Entry 26: type 6 instance 7, length 1024 Entry 27: type 7 instance 0, length 16 Entry 28: type 8 instance 0, length 8 Entry 29: type 9 instance 0, length 8 Entry 30: type 10 instance 0, length 56 Entry 31: type 11 instance 0, length 16 Entry 32: type 12 instance 0, length 1048 Entry 33: type 13 instance 0, length 8 Entry 34: type 14 instance 0, length 240 Entry 35: type 14 instance 1, length 240 Entry 36: type 14 instance 2, length 240 Entry 37: type 14 instance 3, length 240 Entry 38: type 14 instance 4, length 240 Entry 39: type 14 instance 5, length 240 Entry 40: type 14 instance 6, length 240 Entry 41: type 14 instance 7, length 240 Entry 42: type 16 instance 0, length 856 Entry 43: type 16 instance 1, length 856 Entry 44: type 16 instance 2, length 856 Entry 45: type 16 instance 3, length 856 Entry 46: type 16 instance 4, length 856 Entry 47: type 16 instance 5, length 856 Entry 48: type 16 instance 6, length 856 Entry 49: type 16 instance 7, length 856 Entry 50: type 18 instance 0, length 24 Entry 51: type 18 instance 1, length 24 Entry 52: type 18 instance 2, length 24 Entry 53: type 18 instance 3, length 24 Entry 54: type 18 instance 4, length 24 Entry 55: type 18 instance 5, length 24 Entry 56: type 18 instance 6, length 24 Entry 57: type 18 instance 7, length 24 Entry 58: type 19 instance 0, length 8 Entry 59: type 19 instance 1, length 8 Entry 60: type 19 instance 2, length 8 Entry 61: type 19 instance 3, length 8 Entry 62: type 19 instance 4, length 8 Entry 63: type 19 instance 5, length 8 Entry 64: type 19 instance 6, length 8 Entry 65: type 19 instance 7, length 8 Entry 66: type 0 instance 0, length 0

All typecode's appear to save the same amount per instance.

Most use hvm_save_entry:

...

        _hvm_write_entry((_h), (_src), HVM_SAVE_LENGTH(_x));    \

and

/* Syntactic sugar around that function: specify the max number of
* saves, and this calculates the size of buffer needed */
#define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num,
_k) \
static int __init
__hvm_register_##_x##_save_and_restore(void) \
{
\

hvm_register_savevm(HVM_SAVE_CODE(_x), \

#_x, \

&_save, \

&_load,                                           \
                        (_num) *

(HVM_SAVE_LENGTH(_x) \
+ sizeof (struct
hvm_save_descriptor)), \

_k); \
return
0; \
}
\

I do not find any that call on _hvm_write_entry directly.

The only special one I found: CPU_XSAVE_CODE

Still "writes" a full sized entry:

        if ( _hvm_init_entry(h, CPU_XSAVE_CODE, v->vcpu_id,
HVM_CPU_XSAVE_SIZE) )
            return 1;
        ctxt = (struct hvm_hw_cpu_xsave *)&h->data[h->cur];
        h->cur += HVM_CPU_XSAVE_SIZE;
        memset(ctxt, 0, HVM_CPU_XSAVE_SIZE);

It then modifies the zeros conditionaly.

        if ( v->fpu_initialised )
            memcpy(&ctxt->save_area,
                v->arch.xsave_area, xsave_cntxt_size);

#define HVM_CPU_XSAVE_SIZE (3 * sizeof(uint64_t) + xsave_cntxt_size)

is part of this.

/* We need variable length data chunk for xsave area, hence customized
* declaration other than
HVM_REGISTER_SAVE_RESTORE.

*/
static int __init __hvm_register_CPU_XSAVE_save_and_restore(void) {
hvm_register_savevm(CPU_XSAVE_CODE,
"CPU_XSAVE", hvm_save_cpu_xsave_states, hvm_load_cpu_xsave_states, HVM_CPU_XSAVE_SIZE + sizeof (struct
hvm_save_descriptor),

                        HVMSR_PER_VCPU);
    return 0;
}
Quoted 7 lines

__initcall(__hvm_register_CPU_XSAVE_save_and_restore);

is the final part of this one. So I do not find any code that does what you are wondering about.

-Don

HVM_CPU_XSAVE_SIZE() changes depending on which xsave features have ever been enabled by a vcpu (size is proportional to the contents of v->arch.xcr0_accum). It is not guaranteed to be the same for each vcpu in a domain, (although almost certainly will be the same for any recognisable OS)

Jan's new generic MSR save record will also write less than the maximum if it can.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#15 lore raw
Quoted 188 lines · Andrew Cooper
Quoted 187 lines · Don Slutz
Quoted 39 lines · Andrew Cooper
Quoted 38 lines · Don Slutz
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Don Slutz

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 <[email protected]>
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

Quoted 8 lines
Quoted 5 lines

does not select the correct instance. Add code to search for the correct instance.

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.

True, but the inverse is the case here; .save writes 'n' 'size' blocks. Form the loop above:

    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;

so sz is in multiples of 'size'. Normally sz == ctxt.cur. With some offline vcpus it write fewer 'size' blocks.

Quoted 2 lines

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.

Quoted 8 lines
Quoted 3 lines

The only time it does not find one is for an offline vcpu. Try out the unit test code in patch #1 on an unchanged xen. It should not display anything. Then offline a cpu in a domU (echo 0 > /sys/devices/system/cpu/cpu1/online). And with 3 vcpus, it will report an error.

-Don Slutz

Ah - so there are actually two problems. I see now the one you are trying to solve, and would agree that your code does solve it.

However, some of the save handlers are themselves variable length, and will write records shorter than hvm_sr_handlers[typecode].size if they can get away with doing so. In this case, the new logic still wont get the correct instance.

Not sure which one(s) you are referring to.

From the full dump:

xen-hvmctx 1| grep -i entry
Entry 0: type 1 instance 0, length 24 Entry 1: type 2 instance 0, length 1024 Entry 2: type 2 instance 2, length 1024 Entry 3: type 2 instance 3, length 1024 Entry 4: type 2 instance 4, length 1024 Entry 5: type 2 instance 5, length 1024 Entry 6: type 2 instance 6, length 1024 Entry 7: type 2 instance 7, length 1024 Entry 8: type 3 instance 0, length 8 Entry 9: type 3 instance 1, length 8 Entry 10: type 4 instance 0, length 400 Entry 11: type 5 instance 0, length 24 Entry 12: type 5 instance 1, length 24 Entry 13: type 5 instance 2, length 24 Entry 14: type 5 instance 3, length 24 Entry 15: type 5 instance 4, length 24 Entry 16: type 5 instance 5, length 24 Entry 17: type 5 instance 6, length 24 Entry 18: type 5 instance 7, length 24 Entry 19: type 6 instance 0, length 1024 Entry 20: type 6 instance 1, length 1024 Entry 21: type 6 instance 2, length 1024 Entry 22: type 6 instance 3, length 1024 Entry 23: type 6 instance 4, length 1024 Entry 24: type 6 instance 5, length 1024 Entry 25: type 6 instance 6, length 1024 Entry 26: type 6 instance 7, length 1024 Entry 27: type 7 instance 0, length 16 Entry 28: type 8 instance 0, length 8 Entry 29: type 9 instance 0, length 8 Entry 30: type 10 instance 0, length 56 Entry 31: type 11 instance 0, length 16 Entry 32: type 12 instance 0, length 1048 Entry 33: type 13 instance 0, length 8 Entry 34: type 14 instance 0, length 240 Entry 35: type 14 instance 1, length 240 Entry 36: type 14 instance 2, length 240 Entry 37: type 14 instance 3, length 240 Entry 38: type 14 instance 4, length 240 Entry 39: type 14 instance 5, length 240 Entry 40: type 14 instance 6, length 240 Entry 41: type 14 instance 7, length 240 Entry 42: type 16 instance 0, length 856 Entry 43: type 16 instance 1, length 856 Entry 44: type 16 instance 2, length 856 Entry 45: type 16 instance 3, length 856 Entry 46: type 16 instance 4, length 856 Entry 47: type 16 instance 5, length 856 Entry 48: type 16 instance 6, length 856 Entry 49: type 16 instance 7, length 856 Entry 50: type 18 instance 0, length 24 Entry 51: type 18 instance 1, length 24 Entry 52: type 18 instance 2, length 24 Entry 53: type 18 instance 3, length 24 Entry 54: type 18 instance 4, length 24 Entry 55: type 18 instance 5, length 24 Entry 56: type 18 instance 6, length 24 Entry 57: type 18 instance 7, length 24 Entry 58: type 19 instance 0, length 8 Entry 59: type 19 instance 1, length 8 Entry 60: type 19 instance 2, length 8 Entry 61: type 19 instance 3, length 8 Entry 62: type 19 instance 4, length 8 Entry 63: type 19 instance 5, length 8 Entry 64: type 19 instance 6, length 8 Entry 65: type 19 instance 7, length 8 Entry 66: type 0 instance 0, length 0

All typecode's appear to save the same amount per instance.

Most use hvm_save_entry:

...

        _hvm_write_entry((_h), (_src), HVM_SAVE_LENGTH(_x)); \

and

/* Syntactic sugar around that function: specify the max number of
* saves, and this calculates the size of buffer needed */
#define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num, _k) \
static int __init __hvm_register_##_x##_save_and_restore(void) \
{ \
hvm_register_savevm(HVM_SAVE_CODE(_x), \

#_x,                                              \
&_save,                                           \
&_load,                                           \
                        (_num) * 

(HVM_SAVE_LENGTH(_x) \
+ sizeof (struct
hvm_save_descriptor)), \
_k); \
return
0; \
} \

I do not find any that call on _hvm_write_entry directly.

The only special one I found: CPU_XSAVE_CODE

Still "writes" a full sized entry:

        if ( _hvm_init_entry(h, CPU_XSAVE_CODE, v->vcpu_id, 
HVM_CPU_XSAVE_SIZE) )
            return 1;
        ctxt = (struct hvm_hw_cpu_xsave *)&h->data[h->cur];
        h->cur += HVM_CPU_XSAVE_SIZE;
        memset(ctxt, 0, HVM_CPU_XSAVE_SIZE);

It then modifies the zeros conditionaly.

        if ( v->fpu_initialised )
            memcpy(&ctxt->save_area,
                v->arch.xsave_area, xsave_cntxt_size);

#define HVM_CPU_XSAVE_SIZE (3 * sizeof(uint64_t) + xsave_cntxt_size)

is part of this.

/* We need variable length data chunk for xsave area, hence customized
* declaration other than HVM_REGISTER_SAVE_RESTORE.
*/
static int __init __hvm_register_CPU_XSAVE_save_and_restore(void) {
hvm_register_savevm(CPU_XSAVE_CODE,
"CPU_XSAVE", hvm_save_cpu_xsave_states, hvm_load_cpu_xsave_states, HVM_CPU_XSAVE_SIZE + sizeof (struct
hvm_save_descriptor),

                        HVMSR_PER_VCPU);
    return 0;
}

__initcall(__hvm_register_CPU_XSAVE_save_and_restore);

Quoted 7 lines
Quoted 4 lines

is the final part of this one. So I do not find any code that does what you are wondering about.

-Don

HVM_CPU_XSAVE_SIZE() changes depending on which xsave features have ever been enabled by a vcpu (size is proportional to the contents of v->arch.xcr0_accum). It is not guaranteed to be the same for each vcpu in a domain, (although almost certainly will be the same for any recognisable OS)

Ah, I see.

Well, hvm_save_one, hvm_save_size, and hvm_save all expect that hvm_sr_handlers[typecode].size has the max size. I do not see that being true for XSAVE.

Quoted 2 lines

Jan's new generic MSR save record will also write less than the maximum if it can.

This looks to be Jan's patch:

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

Does look to set hvm_sr_handlers[typecode].size to the max size.

And it looks like the code I did in patch #4 would actually fix this issue. Since it now uses the length stored in the save descriptor to find each instance.

Jan has some questions about patch #4; so what to do about it is still pending.

Clearly I can merge #3 and #4 into 1 patch.

-Don Slutz

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw
Quoted 16 lines · Don Slutz
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Don Slutz

is the final part of this one. So I do not find any code that does what you are wondering about.

Quoted 9 lines
Quoted 2 lines

-Don

HVM_CPU_XSAVE_SIZE() changes depending on which xsave features have ever been enabled by a vcpu (size is proportional to the contents of v->arch.xcr0_accum). It is not guaranteed to be the same for each vcpu in a domain, (although almost certainly will be the same for any recognisable OS)

Quoted 5 lines

Ah, I see.

Well, hvm_save_one, hvm_save_size, and hvm_save all expect that hvm_sr_handlers[typecode].size has the max size. I do not see that being true for XSAVE.

hvm_sr_handlers[typecode].size does need to be the maximum possible size. It does not mean that the maximum amount of data will be written.

So long as the load on the far side can read the somewhat-shorter-than-maximum save record, it doesn't matter (except hvm_save_one). hvm_save_size specifically need to return the maximum size possible, so the toolstack can allocate a big enough buffer. xc_domain_save() does correctly deal with Xen handing back less than the maximum when actually saving the domain.

Quoted 13 lines
Quoted 3 lines

Jan's new generic MSR save record will also write less than the maximum if it can.

This looks to be Jan's patch:

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

Does look to set hvm_sr_handlers[typecode].size to the max size.

And it looks like the code I did in patch #4 would actually fix this issue. Since it now uses the length stored in the save descriptor to find each instance.

Quoted 10 lines

Jan has some questions about patch #4; so what to do about it is still pending.

Clearly I can merge #3 and #4 into 1 patch.

-Don Slutz

Quoted 1 line

~Andrew

As I said, to fix this newest problem I am experimenting with splitting the per-dom and per-vcpu save handlers, and making good progress. It does mean that the fix for #3 would be much much more simple.

I shall send out a very RFC series as soon as I can

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#17 lore raw
Quoted 40 lines · Andrew Cooper
Quoted 6 lines · Don Slutz
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Don Slutz

is the final part of this one. So I do not find any code that does what you are wondering about.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

-Don

HVM_CPU_XSAVE_SIZE() changes depending on which xsave features have ever been enabled by a vcpu (size is proportional to the contents of v->arch.xcr0_accum). It is not guaranteed to be the same for each vcpu in a domain, (although almost certainly will be the same for any recognisable OS)

Ah, I see.

Well, hvm_save_one, hvm_save_size, and hvm_save all expect that hvm_sr_handlers[typecode].size has the max size. I do not see that being true for XSAVE.

hvm_sr_handlers[typecode].size does need to be the maximum possible size. It does not mean that the maximum amount of data will be written.

So long as the load on the far side can read the somewhat-shorter-than-maximum save record, it doesn't matter (except hvm_save_one). hvm_save_size specifically need to return the maximum size possible, so the toolstack can allocate a big enough buffer. xc_domain_save() does correctly deal with Xen handing back less than the maximum when actually saving the domain.

Quoted 8 lines
Quoted 2 lines

Jan's new generic MSR save record will also write less than the maximum if it can.

This looks to be Jan's patch:

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

Does look to set hvm_sr_handlers[typecode].size to the max size.

Quoted 11 lines

And it looks like the code I did in patch #4 would actually fix this issue. Since it now uses the length stored in the save descriptor to find each instance.

Jan has some questions about patch #4; so what to do about it is still pending.

Clearly I can merge #3 and #4 into 1 patch.

-Don Slutz

Quoted 1 line

~Andrew

Quoted 5 lines

As I said, to fix this newest problem I am experimenting with splitting the per-dom and per-vcpu save handlers, and making good progress. It does mean that the fix for #3 would be much much more simple.

I shall send out a very RFC series as soon as I can

~Andrew

Great, I look forward to seeing them.
-Don Slutz

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#18 lore raw
In reply to Andrew Cooper
Quoted 26 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 24 lines · Don Slutz

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 <[email protected]>
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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 7 lines

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

author
#19 lore raw
Quoted 36 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 20 lines · Don Slutz

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 <[email protected]>
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

Quoted 8 lines
Quoted 5 lines

does not select the correct instance. Add code to search for the correct instance.

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.

Quoted 4 lines

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.

Quoted 8 lines
Quoted 3 lines

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

Quoted 1 line

From 07897bd0d4a680df03421c0eab96cfa41de2d9f6 Mon Sep 17 00:00:00 2001

From: Don Slutz <[email protected]>
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.

---
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(-)
xen/common/hvm/save.c +20 -10
index de76ada..a7e0edc 100644
@@ -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;
Signature · 1 line
1.8.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#20 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Don Slutz

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

I would tend to agree on the 4.4 part of this, but afaict this is used for debugging purposes only, so I'm not so sure about backporting to stable branches. What is your rationale behind that request?

Andrew, short of taking your intrusive (and not yet agreed upon) rework - would you agree Don's change at least is a sufficient improvement to include it irrespective of any intentions you might have with this code?

Jan

#21 lore raw
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Don Slutz

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

I would tend to agree on the 4.4 part of this, but afaict this is used for debugging purposes only, so I'm not so sure about backporting to stable branches. What is your rationale behind that request?

Quoted 7 lines

Andrew, short of taking your intrusive (and not yet agreed upon) rework - would you agree Don's change at least is a sufficient improvement to include it irrespective of any intentions you might have with this code?

Jan

Yes - Dons' patch would appear to fix up all the corner-cases I am aware of in the hypercall.

~Andrew

author
#22 lore raw

Adding "George Dunlap" to list of people.

George,
I think this is a bug fix that can make it into 4.4. Some how I forgot to include you directly. Please let me know if pushing for this is wrong.

Bug fix is attached to:

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

Thanks,
-Don Slutz

Quoted 19 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Don Slutz

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

I would tend to agree on the 4.4 part of this, but afaict this is used for debugging purposes only, so I'm not so sure about backporting to stable branches. What is your rationale behind that request?

Quoted 7 lines

Andrew, short of taking your intrusive (and not yet agreed upon) rework - would you agree Don's change at least is a sufficient improvement to include it irrespective of any intentions you might have with this code?

Jan

Yes - Dons' patch would appear to fix up all the corner-cases I am aware of in the hypercall.

~Andrew

#23 lore raw
Quoted 6 lines · Don Slutz

Adding "George Dunlap" to list of people.

George,
I think this is a bug fix that can make it into 4.4. Some how I
forgot to include you directly. Please let me know if pushing for this is wrong.

Quoted 25 lines

Bug fix is attached to:

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

Thanks,
-Don Slutz

Quoted 17 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Don Slutz

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

I would tend to agree on the 4.4 part of this, but afaict this is used for debugging purposes only, so I'm not so sure about backporting to stable branches. What is your rationale behind that request?

Quoted 7 lines

Andrew, short of taking your intrusive (and not yet agreed upon) rework - would you agree Don's change at least is a sufficient improvement to include it irrespective of any intentions you might have with this code?

Jan

Yes - Dons' patch would appear to fix up all the corner-cases I am aware of in the hypercall.

It looks like this should only affect xenctx. It is a bug fix, and while not a critical one, nonetheless an important one. So I agree, it should be accepted.

author
#24 lore raw
Quoted 28 lines · George Dunlap
Quoted 27 lines · Don Slutz

Adding "George Dunlap" to list of people.

George,
I think this is a bug fix that can make it into 4.4. Some how I
forgot to include you directly. Please let me know if pushing for this is wrong.

Bug fix is attached to:

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

Thanks,
-Don Slutz

Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Don Slutz

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

I would tend to agree on the 4.4 part of this, but afaict this is used for debugging purposes only, so I'm not so sure about backporting to stable branches. What is your rationale behind that request?

Andrew, short of taking your intrusive (and not yet agreed upon) rework - would you agree Don's change at least is a sufficient improvement to include it irrespective of any intentions you might have with this code?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Jan

Yes - Dons' patch would appear to fix up all the corner-cases I am aware of in the hypercall.

It looks like this should only affect xenctx. It is a bug fix, and while not a critical one, nonetheless an important one. So I agree, it should be accepted.

I have posted a v4 attached to:

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

I saw Andrew's latest requests after I posted this.
-Don Slutz

author
#25 lore raw
In reply to Jan Beulich
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Don Slutz

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

I would tend to agree on the 4.4 part of this, but afaict this is used for debugging purposes only, so I'm not so sure about backporting to stable branches. What is your rationale behind that request?

I would think that getting bad info during debugging to be important. For example:

Before (i.e. correct data):

# xenctx 7 7
rip: ffffffff8006b2b0
flags: 00000246 i z p
rsp: ffff8100bfe6bef0
rax: 0000000000000000   rcx: 0000000000000000   rdx: 0000000000000000
rbx: ffffffff8006b287   rsi: 0000000000000001   rdi: ffffffff802f0658
rbp: 0000000000000007    r8: ffff8100bfe6a000    r9: 0000000000000039
r10: ffff8100b80a5b40   r11: ffff810037fe6100   r12: 00000000000000ff
r13: ffffffff803b4680   r14: 0000000000000700   r15: ffffffff803d6340
 cs: 0010        ss: 0018        ds: 0018        es: 0018
 fs: 0000 @ 0000000000000000
 gs: 0000 @ ffff8100bfe17340/0000000000000000
Code (instr addr ffffffff8006b2b0)
65 48 8b 04 25 10 00 00 00 8b 80 38 e0 ff ff a8 08 75 04 fb f4 <eb> 01 fb 65 48 8b 04 25 10 00 00
Stack:
 ffffffff80048d19 00000000000000e0 ffffffff80076be6 ffffffff803d4360
 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 0000000000000000 0000000000000000 0000000000000000 0000000000000000
 0000000000000000 0000000000000000 0000000000000000 0000000000000000

Call Trace:
  [<ffffffff8006b2b0>] <--
  [<ffffffff80048d19>]
  [<ffffffff80076be6>]
  [<ffffffff803d4360>]

After offline of vcpu 1:

# xenctx 7 7
cs:eip: 0010:8006b2b0
flags: 00000246 i z p
ss:esp: 0018:bfe6bef0
eax: 00000000   ebx: 8006b287   ecx: 00000000   edx: 00000000
esi: 00000001   edi: 802f0658   ebp: 00000007
 ds:     0018    es:     0018    fs:     0000    gs:     0000
Code (instr addr ffffffff8006b2b0)
f0 53 ff 00 f0 53 ff 00 f0 53 ff 00 f0 53 ff 00 f0 53 ff 00 f0 <53> ff 00 f0 53 ff 00 f0 53 ff 00
Stack:
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Call Trace:
  [<ffffffff8006b2b0>] <--

As you can see, it now looks like VCPU 7 is in 32 bit mode when it is not.

-Don Slutz

Quoted 7 lines

Andrew, short of taking your intrusive (and not yet agreed upon) rework - would you agree Don's change at least is a sufficient improvement to include it irrespective of any intentions you might have with this code?

Jan

#26 lore raw
In reply to Don Slutz
Quoted 70 lines · Don Slutz
Quoted 36 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 20 lines · Don Slutz

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 <[email protected]>
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

Quoted 8 lines
Quoted 5 lines

does not select the correct instance. Add code to search for the correct instance.

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.

Quoted 4 lines

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.

Quoted 8 lines
Quoted 3 lines

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.

Quoted 10 lines

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

Your loop condition needs to change be "off < (ctxt.cur - sizeof(*desc))" otherwise the "off += sizeof(*desc)" can wander beyond ctxt.cur in the loop body. You also need to verify that the copy_to_guest doesn't exceed ctxt.cur.

Stylistically, "desc = (void *)ctxt.data + off;" needs to be "desc = (void *)(ctxt.data + off);" as the latter is standards compliment C while the former is UB which GCC has an extension to deal with sensibly.

Also you have a double space before sizeof in "off += sizeof(*desc);"

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#27 lore raw

On 12/16/13 13:33, Andrew Cooper wrote:

Not sure why it took till late 12/21 for me to get this e-mail.

Quoted 4 lines · Don Slutz
Quoted 3 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

On 15/12/2013 00:29, Don Slutz wrote:

[snip]

Quoted 4 lines

Your loop condition needs to change be "off < (ctxt.cur - sizeof(*desc))" otherwise the "off += sizeof(*desc)" can wander beyond ctxt.cur in the loop body. You also need to verify that the copy_to_guest doesn't exceed ctxt.cur.

fixed.

Quoted 3 lines

Stylistically, "desc = (void *)ctxt.data + off;" needs to be "desc = (void *)(ctxt.data + off);" as the latter is standards compliment C while the former is UB which GCC has an extension to deal with sensibly.

fixed.

Quoted 1 line

Also you have a double space before sizeof in "off += sizeof(*desc);"

Fixed. Version 4 attached.

Quoted 2 lines

~Andrew

-Don Slutz

Quoted 1 line

From 975028470091a9517111a409501e477ea50e02a6 Mon Sep 17 00:00:00 2001

From: Don Slutz <[email protected]>
Date: Tue, 12 Nov 2013 08:22:53 -0500
Subject: [BUGFIX][PATCH v4 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.

---
changes v3 to v4: adjust loop limit and copy_length. changes v2 to v3: merge in patch #4.
changes v1 to v2: fix coding style and coding issues.

 xen/common/hvm/save.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
xen/common/hvm/save.c +24 -10
index de76ada..2f8b687 100644
@@ -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,30 @@ 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 - sizeof(*desc)); off += desc->length )
+        {
+            desc = (void *)(ctxt.data + off);
+            /* Move past header */
+            off += sizeof(*desc);
+            if ( instance == desc->instance )
+            {
+                uint32_t copy_length = desc->length;
+
+                if ( off + copy_length > ctxt.cur )
+                    copy_length = ctxt.cur - off;
+                rv = 0;
+                if ( copy_to_guest(handle, ctxt.data + off, copy_length) )
+                    rv = -EFAULT;
+                break;
+            }
+        }
+    }
 
     xfree(ctxt.data);
     return rv;
Signature · 1 line
1.8.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by
#28 lore raw
Quoted 18 lines · Don Slutz

On 12/16/13 13:33, Andrew Cooper wrote:

Not sure why it took till late 12/21 for me to get this e-mail.

Quoted 5 lines · Don Slutz
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

On 15.12.13 at 17:51, Andrew Cooper <[email protected]> wrote:

On 15/12/2013 00:29, Don Slutz wrote:

[snip]

Quoted 4 lines

Your loop condition needs to change be "off < (ctxt.cur - sizeof(*desc))" otherwise the "off += sizeof(*desc)" can wander beyond ctxt.cur in the loop body. You also need to verify that the copy_to_guest doesn't exceed ctxt.cur.

fixed.

Quoted 3 lines

Stylistically, "desc = (void *)ctxt.data + off;" needs to be "desc = (void *)(ctxt.data + off);" as the latter is standards compliment C while the former is UB which GCC has an extension to deal with sensibly.

Quoted 6 lines

fixed.

Quoted 1 line

Also you have a double space before sizeof in "off += sizeof(*desc);"

Fixed. Version 4 attached.

Quoted 2 lines

~Andrew

-Don Slutz

Acked-by
#29 lore raw
In reply to Don Slutz
Quoted 14 lines · Don Slutz

On 12/16/13 13:33, Andrew Cooper wrote:

Not sure why it took till late 12/21 for me to get this e-mail.

Quoted 4 lines · Don Slutz
Quoted 3 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

On 15/12/2013 00:29, Don Slutz wrote:

[snip]

Quoted 4 lines

Your loop condition needs to change be "off < (ctxt.cur - sizeof(*desc))" otherwise the "off += sizeof(*desc)" can wander beyond ctxt.cur in the loop body. You also need to verify that the copy_to_guest doesn't exceed ctxt.cur.

fixed.

Quoted 8 lines
Quoted 3 lines

Stylistically, "desc = (void *)ctxt.data + off;" needs to be "desc = (void *)(ctxt.data + off);" as the latter is standards compliment C while the former is UB which GCC has an extension to deal with sensibly.

fixed.

Quoted 1 line

Also you have a double space before sizeof in "off += sizeof(*desc);"

Fixed. Version 4 attached.

Quoted 3 lines
Quoted 2 lines

~Andrew

-Don Slutz

author
#30 lore raw

PATCH 4/4 hvm_save_one: allow the 2nd instance to be fetched for PIC.

In reply to Don Slutz

From: Don Slutz <[email protected]>

In this case hvm_sr_handlers[typecode].size is 2x the struct size. So use the saved size (length) to look at each possible instance.

---
 xen/common/hvm/save.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
xen/common/hvm/save.c +4 -7
index ff6e910..f4138b4 100644
@@ -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 )
@@ -114,20 +111,20 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance,
     }
     else
     {
-        uint32_t off;
+        uint32_t off, add;
 
         rv = -EBADSLT;
-        for (off = 0; off < ctxt.cur; off += hvm_sr_handlers[typecode].size) {
+        for (off = 0; off < ctxt.cur; off += add + sizeof (struct hvm_save_descriptor)) {
             struct hvm_save_descriptor *desc
                    = (struct hvm_save_descriptor *)&ctxt.data[off];
+            add = desc->length;
             if (instance == desc->instance) {
                 rv = 0;
                 if ( copy_to_guest(handle,
                                    ctxt.data
                                    + off
                                    + sizeof (struct hvm_save_descriptor),
-                                   hvm_sr_handlers[typecode].size
-                                   - sizeof (struct hvm_save_descriptor)) )
+                                   add) )
                     rv = -EFAULT;
                 break;
             }
Signature · 1 line
1.8.4
#31 lore raw

Re: [BUGFIX][PATCH 4/4] hvm_save_one: allow the 2nd instance to be fetched for PIC.

xen/common/hvm/save.c int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 114

Quoted 7 lines
Quoted 1 line
Quoted 1 line · Don Slutz
xen/common/hvm/save.c +1 -1
@@ -114,20 +111,20 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance,
     }
     else
     {
-        uint32_t off;
+        uint32_t off, add;

"add" is a pretty odd name for what this is being used for. Why don't you use desc->length directly?

Quoted 6 lines
xen/common/hvm/save.c +1 -1
         rv = -EBADSLT;
-        for (off = 0; off < ctxt.cur; off += hvm_sr_handlers[typecode].size) {
+        for (off = 0; off < ctxt.cur; off += add + sizeof (struct hvm_save_descriptor)) {
             struct hvm_save_descriptor *desc
                    = (struct hvm_save_descriptor *)&ctxt.data[off];

xen/common/hvm/save.c int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 127

Quoted 10 lines
xen/common/hvm/save.c +2 -2
+            add = desc->length;
             if (instance == desc->instance) {
                 rv = 0;
                 if ( copy_to_guest(handle,
                                    ctxt.data
                                    + off
                                    + sizeof (struct hvm_save_descriptor),
-                                   hvm_sr_handlers[typecode].size
-                                   - sizeof (struct hvm_save_descriptor)) )
+                                   add) )

Further, the way this was done before means that for multi- instance records all records would get copied out, but the caller would have no way of knowing that (except by implying that behavior, e.g. "known to be the case for PIC").

Which shows another shortcoming of the interface: There's no buffer size being passed in from the caller, yet we have variable size records. Which means latent data corruption in the caller.

Hence I think rather than complicating the logic here, we should change the interface to pass a size in and back out, which will not only avoid corrupting memory, but also allow the guest to recognize multi-instance data being returned.

Jan

author
#32 lore raw

Re: [BUGFIX][PATCH 4/4] hvm_save_one: allow the 2nd instance to be fetched for PIC.

Quoted 9 lines · Jan Beulich

Review int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 114

Quoted 7 lines
Quoted 1 line
Quoted 1 line · Don Slutz
(quoted diff) +1 -1
@@ -114,20 +111,20 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance,
      }
      else
      {
-        uint32_t off;
+        uint32_t off, add;

"add" is a pretty odd name for what this is being used for. Why don't you use desc->length directly?

I picked the name when the 3rd part of the "for" was "off += add". During unit testing that did not work and so did not try and pick a new one. I could have added add2:

    const uint32_t add2 = sizeof (struct hvm_save_descriptor);

And then the last part of the for becomes "off += add + add2".

I can not use desc->length because:

save.c: In function 'hvm_save_one':
save.c:120:47: error: 'desc' undeclared (first use in this function)
save.c:120:47: note: each undeclared identifier is reported only once for each function it appears in

(It is only defined in the body of the for).

Quoted 16 lines
Quoted 6 lines
(quoted diff) +1 -1
          rv = -EBADSLT;
-        for (off = 0; off < ctxt.cur; off += hvm_sr_handlers[typecode].size) {
+        for (off = 0; off < ctxt.cur; off += add + sizeof (struct hvm_save_descriptor)) {
              struct hvm_save_descriptor *desc
                     = (struct hvm_save_descriptor *)&ctxt.data[off];

Review int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, · line 126

Quoted 10 lines
(quoted diff) +2 -2
+            add = desc->length;
              if (instance == desc->instance) {
                  rv = 0;
                  if ( copy_to_guest(handle,
                                     ctxt.data
                                     + off
                                     + sizeof (struct hvm_save_descriptor),
-                                   hvm_sr_handlers[typecode].size
-                                   - sizeof (struct hvm_save_descriptor)) )
+                                   add) )
Quoted 4 lines

Further, the way this was done before means that for multi- instance records all records would get copied out, but the caller would have no way of knowing that (except by implying that behavior, e.g. "known to be the case for PIC").

Not exactly. Using the following adjustment to check-hvmctx (patch #1):

cb4d0e75a497f169c8419b30c1954f92bb8e29a8 Mon Sep 17 00:00:00 2001
From: Don Slutz <[email protected]>
Date: Sat, 14 Dec 2013 19:31:16 -0500
Subject: [PATCH] check-hvmctx: add check for extra data under debug 8

---
 tools/tests/check-hvmctx/check-hvmctx.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
tools/tests/check-hvmctx/check-hvmctx.c +1 -1
index 9b5c3aa..668b77a 100644
@@ -574,7 +574,7 @@ int main(int argc, char **argv)
         default:
             if (xc_domain_hvm_getcontext_partial(
                     xch, domid, desc.typecode, desc.instance,
-                    tbuf, desc.length) != 0) {
+                    tbuf, len) != 0) {
                 fprintf(stderr, "Error: 

xc_domain_hvm_getcontext_partial: entry %i: type %u instance %u, length %u: ",
entry, (unsigned) desc.typecode, (unsigned) desc.instance, (unsigned) desc.length);
@@ -582,6 +582,23 @@ int main(int argc, char **argv)

                 retval = 42;
                 memset(tbuf, 0xee, desc.length);
             }

+ if (debug & 0x08) {
+ int i;
+ int header = 1;
+
+ for (i = desc.length; i < len; i++) {
+ if (tbuf[i]) {
+ if (header) {
+ header = 0;
+ printf("Error: entry %i: type %u instance %u, length %u extra data!\n",
+ entry, (unsigned) desc.typecode,
+ (unsigned) desc.instance, (unsigned) desc.length);
+ }
+ printf("[%03x] unexpected data=%02x\n",
+ i, tbuf[i]);
+ }
+ }
+ }

             ret = desc.length;
 #ifndef NOTCLEAN
             if (desc.typecode == HVM_SAVE_CODE(CPU))
Signature · 24 lines
1.7.11.7

and before this patch:

dcs-xen-51:~/xen/tools/tests/check-hvmctx>make clean;make CHECK_HVMCTX="-DDOPIC"
rm -f *.o check-hvmctx *~ .*.d
gcc  -O1 -fno-omit-frame-pointer -m64 -g -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -D__XEN_TOOLS__ -MMD -MF .check-hvmctx.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fno-optimize-sibling-calls  -Werror -I/home/don/xen/tools/tests/check-hvmctx/../../../tools/libxc -I/home/don/xen/tools/tests/check-hvmctx/../../../tools/include -I/home/don/xen/tools/tests/check-hvmctx/../../../tools/include -I/home/don/xen/tools/tests/check-hvmctx/../../../tools/xenstore -I/home/don/xen/tools/tests/check-hvmctx/../../../tools/include -I/home/don/xen/tools/tests/check-hvmctx/../../../tools -DDOPIC  -c -o check-hvmctx.o check-hvmctx.c
gcc    -o check-hvmctx check-hvmctx.o /home/don/xen/tools/tests/check-hvmctx/../../../tools/libxc/libxenctrl.so
dcs-xen-51:~/xen/tools/tests/check-hvmctx>sudo ./check-hvmctx 1 8
Check HVM save record vs partial for domain 1
Error: entry 8: type 3 instance 0, length 8 extra data!
[008] unexpected data=03
[00a] unexpected data=01
[00c] unexpected data=08
[010] unexpected data=01
[011] unexpected data=ff
[013] unexpected data=28
[016] unexpected data=0c
Error: xc_domain_hvm_getcontext_partial: entry 9: type 3 instance 1, length 8: Invalid argument
Error: entry 9: type 3 instance 1, length 8 mismatch!
    PIC: IRQ base 0x28, irr 0x1, imr 0xff, isr 0


I see that after the expected length (8), there is a struct hvm_save_descriptor (type 3 instance 1, length 8) followed by another HVM_SAVE_TYPE(PIC).
Quoted 3 lines

Which shows another shortcoming of the interface: There's no buffer size being passed in from the caller, yet we have variable size records. Which means latent data corruption in the caller.

This is not 100% correct. The libxl code for xc_domain_hvm_getcontext_partial does take a length:

/* Get just one element of the HVM guest context.
* size must be >= HVM_SAVE_LENGTH(type) */
int xc_domain_hvm_getcontext_partial(xc_interface *xch,

                                     uint32_t domid,
                                     uint16_t typecode,
                                     uint16_t instance,
                                     void *ctxt_buf,
                                     uint32_t size)

{

and it gets embeded in

DECLARE_HYPERCALL_BOUNCE(ctxt_buf, size,
XC_HYPERCALL_BUFFER_BOUNCE_OUT);

which is handle. I do not know that much about "XEN_GUEST_HANDLE_64(uint8) handle" and DECLARE_HYPERCALL_BOUNCE, but what my unit testing has shown me is that copy_to_guest(handle, <ptr>, <nr>) does only copy up to the size stored in handle. It looks to zero an unknown amount more (looks to be page sized). So there is more needed here.

Quoted 4 lines

Hence I think rather than complicating the logic here, we should change the interface to pass a size in and back out, which will not only avoid corrupting memory, but also allow the guest to recognize multi-instance data being returned.

The size is passed in, just not passed out. And the fact that the data is:

HVM_SAVE_TYPE(PIC)
struct hvm_save_descriptor
HVM_SAVE_TYPE(PIC)

Is strange to me. One descriptor for two entries. This was the primary reason I went the way I did. I am not saying that the interface should not change; I just do not see that as a bug fix type change.

-Don Slutz

Quoted 7 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#33 lore raw

Re: [BUGFIX][PATCH 4/4] hvm_save_one: allow the 2nd instance to be fetched for PIC.

Quoted 21 lines
Quoted 1 line
Quoted 1 line · Don Slutz
Quoted 2 lines · Jan Beulich

Review int hvm_save_one(struct domain *d, uint16_t typecode,

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Don Slutz
(quoted diff) +0 -0
@@ -114,20 +111,20 @@ int hvm_save_one(struct domain *d, uint16_t typecode, 

uint16_t instance,

Quoted 7 lines

Review int hvm_save_one(struct domain *d, uint16_t typecode, · line 114

Quoted 5 lines
(quoted diff) +1 -1
      }
      else
      {
-        uint32_t off;
+        uint32_t off, add;

"add" is a pretty odd name for what this is being used for. Why don't you use desc->length directly?

I picked the name when the 3rd part of the "for" was "off += add". During unit
testing that did not work and so did not try and pick a new one. I could have added add2:

     const uint32_t add2 = sizeof (struct hvm_save_descriptor);

And then the last part of the for becomes "off += add + add2".

Quoted 8 lines

I can not use desc->length because:

save.c: In function 'hvm_save_one':
save.c:120:47: error: 'desc' undeclared (first use in this function) save.c:120:47: note: each undeclared identifier is reported only once for each function it appears in

(It is only defined in the body of the for).

Right - so simply move it into the next surrounding scope.

Quoted 9 lines
Quoted 3 lines

Which shows another shortcoming of the interface: There's no buffer size being passed in from the caller, yet we have variable size records. Which means latent data corruption in the caller.

This is not 100% correct. The libxl code for xc_domain_hvm_getcontext_partial does take a length:

/* Get just one element of the HVM guest context.
* size must be >= HVM_SAVE_LENGTH(type) */
int xc_domain_hvm_getcontext_partial(xc_interface *xch,

Quoted 6 lines
                                      uint32_t domid,
                                      uint16_t typecode,
                                      uint16_t instance,
                                      void *ctxt_buf,
                                      uint32_t size)

{

Which doesn't mean anything for the hypervisor interface. Yet that's the one I said has the limitation.

Quoted 6 lines

and it gets embeded in

DECLARE_HYPERCALL_BOUNCE(ctxt_buf, size,
XC_HYPERCALL_BUFFER_BOUNCE_OUT);

Quoted 6 lines

which is handle. I do not know that much about "XEN_GUEST_HANDLE_64(uint8) handle" and DECLARE_HYPERCALL_BOUNCE, but what my unit testing has shown me is that copy_to_guest(handle, <ptr>, <nr>) does only copy up to the size stored in handle. It looks to zero an unknown amount more (looks to be page sized). So there is more needed here.

Again, you need to split the way libxc works from the actual
hypercall: A handle _never_ tells you to how many items it refers, there's always a second parameter required to pass the element count (unless known by other means).

Jan