Skip to contentSkip to conversation

s390/z14: extended TOD-clock support

PATCH Superseded Christian Borntraeger 4 participants 6 messages Sep 25, 2017 – Sep 26, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover s390/z14: extended TOD-clock support

I still have this patch on my queue as the last remaining z14 item. Since I have already rebase it several time, its time for some additional review.

Collin L. Walling (2):
linux-headers: Update linux headers for extended TOD-Clock s390/kvm: Support for get/set of extended TOD-Clock for guest

 hw/s390x/s390-virtio-ccw.c   |  8 +++-----
 linux-headers/asm-s390/kvm.h |  6 ++++++
 target/s390x/cpu.c           | 26 +++++++++++++++++++-------
 target/s390x/kvm-stub.c      | 10 ++++++++++
 target/s390x/kvm.c           | 35 +++++++++++++++++++++++++++++++++++
 target/s390x/kvm_s390x.h     |  2 ++
 6 files changed, 75 insertions(+), 12 deletions(-)
Signature · 1 line
2.9.4
#1 lore raw

PATCH 1/2 linux-headers: Update linux headers for extended TOD-Clock

From: "Collin L. Walling" <[email protected]>

Conny: to be replaced with 4.14-rc*.

Adds KVM_S390_VM_TOD_EXT attribute for the extended TOD-Clock attribute and kvm_s390_vm_tod_clock struct for TOD-Clock data.

---
 linux-headers/asm-s390/kvm.h | 6 ++++++
 1 file changed, 6 insertions(+)
linux-headers/asm-s390/kvm.h +6 -0
index 8387d71..7b750ef 100644
@@ -88,6 +88,12 @@ struct kvm_s390_io_adapter_req {
 /* kvm attributes for KVM_S390_VM_TOD */
 #define KVM_S390_VM_TOD_LOW		0
 #define KVM_S390_VM_TOD_HIGH		1
+#define KVM_S390_VM_TOD_EXT		2
+
+struct kvm_s390_vm_tod_clock {
+	__u8  epoch_idx;
+	__u64 tod;
+};
 
 /* kvm attributes for KVM_S390_VM_CPU_MODEL */
 /* processor related attributes are r/w */
Signature · 1 line
2.9.4
#2 lore raw

PATCH 2/2 s390/kvm: Support for get/set of extended TOD-Clock for guest

In reply to Christian Borntraeger

From: "Collin L. Walling" <[email protected]>

Provides an interface for getting and setting the guest's extended TOD-Clock via a single ioctl to kvm. If the ioctl fails because it is not support by kvm, then we fall back to the old style of retrieving the clock via two ioctls.

If kvm fails to set a nonzero epoch index, then we ultimately fail the migration altogether and the guest will resume normally on the original host machine.

---
 hw/s390x/s390-virtio-ccw.c |  8 +++-----
 target/s390x/cpu.c         | 26 +++++++++++++++++++-------
 target/s390x/kvm-stub.c    | 10 ++++++++++
 target/s390x/kvm.c         | 35 +++++++++++++++++++++++++++++++++++
 target/s390x/kvm_s390x.h   |  2 ++
 5 files changed, 69 insertions(+), 12 deletions(-)
hw/s390x/s390-virtio-ccw.c +3 -5
index fafbc6d..bad09f5 100644
@@ -213,13 +213,11 @@ static int gtod_load(QEMUFile *f, void *opaque, int version_id)
 
     r = s390_set_clock(&tod_high, &tod_low);
     if (r) {
-        warn_report("Unable to set guest clock for migration: %s",
-                    strerror(-r));
-        error_printf("Guest clock will not be restored "
-                     "which could cause the guest to hang.");
+        error_report("Unable to set guest clock value. "
+                     "s390_get_clock returned error %d.\n", r);
     }
 
-    return 0;
+    return r;
 }
 
 static SaveVMHandlers savevm_gtod = {
target/s390x/cpu.c +19 -7
index 34538c3..c8f1219 100644
@@ -357,22 +357,34 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
 
 int s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
 {
+    int r = 0;
+
     if (kvm_enabled()) {
-        return kvm_s390_get_clock(tod_high, tod_low);
+        r = kvm_s390_get_clock_ext(tod_high, tod_low);
+        if (r == -ENXIO) {
+            return kvm_s390_get_clock(tod_high, tod_low);
+        }
+    } else {
+        /* Fixme TCG */
+        *tod_high = 0;
+        *tod_low = 0;
     }
-    /* Fixme TCG */
-    *tod_high = 0;
-    *tod_low = 0;
-    return 0;
+
+    return r;
 }
 
 int s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
 {
+    int r = 0;
+
     if (kvm_enabled()) {
-        return kvm_s390_set_clock(tod_high, tod_low);
+        r = kvm_s390_set_clock_ext(tod_high, tod_low);
+        if (r == -ENXIO) {
+            return kvm_s390_set_clock(tod_high, tod_low);
+        }
     }
     /* Fixme TCG */
-    return 0;
+    return r;
 }
 
 int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)
target/s390x/kvm-stub.c +10 -0
index 261e1cd..43f02c2 100644
@@ -68,11 +68,21 @@ int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
     return -ENOSYS;
 }
 
+int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_low)
+{
+    return -ENOSYS;
+}
+
 int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
 {
     return -ENOSYS;
 }
 
+int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_low)
+{
+    return -ENOSYS;
+}
+
 void kvm_s390_enable_css_support(S390CPU *cpu)
 {
 }
target/s390x/kvm.c +35 -0
index ebb75ca..ef7374c 100644
@@ -643,6 +643,25 @@ int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
     return kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
 }
 
+int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_low)
+{
+    int r;
+
+    struct kvm_s390_vm_tod_clock gtod;
+
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_TOD,
+        .attr = KVM_S390_VM_TOD_EXT,
+        .addr = (uint64_t)(&gtod),
+    };
+
+    r = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    *tod_high = gtod.epoch_idx;
+    *tod_low  = gtod.tod;
+
+    return r;
+}
+
 int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
 {
     int r;
@@ -663,6 +682,22 @@ int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
     return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
 }
 
+int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_low)
+{
+    struct kvm_s390_vm_tod_clock gtod = {
+        .epoch_idx = *tod_high,
+        .tod  = *tod_low,
+    };
+
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_TOD,
+        .attr = KVM_S390_VM_TOD_EXT,
+        .addr = (uint64_t)(&gtod),
+    };
+
+    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+}
+
 /**
  * kvm_s390_mem_op:
  * @addr:      the logical start address in guest memory
target/s390x/kvm_s390x.h +2 -0
index 2d594bd..501fc5a 100644
@@ -29,7 +29,9 @@ int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu);
 int kvm_s390_get_ri(void);
 int kvm_s390_get_gs(void);
 int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_clock);
+int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_clock);
 int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_clock);
+int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_clock);
 void kvm_s390_enable_css_support(S390CPU *cpu);
 int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
                                     int vq, bool assign);
Signature · 1 line
2.9.4
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] s390/kvm: Support for get/set of extended TOD-Clock for guest

Quoted 10 lines · On Mon, 25 Sep 2017 12:23:02 +0200 Christian Borntraeger…

From: "Collin L. Walling" <[email protected]>

Provides an interface for getting and setting the guest's extended TOD-Clock via a single ioctl to kvm. If the ioctl fails because it is not support by kvm, then we fall back to the old style of retrieving the clock via two ioctls.

If kvm fails to set a nonzero epoch index, then we ultimately fail the migration altogether and the guest will resume normally on the original host machine.

I'd prefer to have that part split off, as it is a change in behaviour and I don't think we should mix it with adding support for an improved interface.

Quoted 18 lines
---
 hw/s390x/s390-virtio-ccw.c |  8 +++-----
 target/s390x/cpu.c         | 26 +++++++++++++++++++-------
 target/s390x/kvm-stub.c    | 10 ++++++++++
 target/s390x/kvm.c         | 35 +++++++++++++++++++++++++++++++++++
 target/s390x/kvm_s390x.h   |  2 ++
 5 files changed, 69 insertions(+), 12 deletions(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index fafbc6d..bad09f5 100644

hw/s390x/s390-virtio-ccw.c static int gtod_load(QEMUFile *f, void *opaque, int version_id) · line 217

Quoted 9 lines
hw/s390x/s390-virtio-ccw.c +2 -4
@@ -213,13 +213,11 @@ static int gtod_load(QEMUFile *f, void *opaque, int version_id)
 
     r = s390_set_clock(&tod_high, &tod_low);
     if (r) {
-        warn_report("Unable to set guest clock for migration: %s",
-                    strerror(-r));
-        error_printf("Guest clock will not be restored "
-                     "which could cause the guest to hang.");
+        error_report("Unable to set guest clock value. "
+                     "s390_get_clock returned error %d.\n", r);

Please keep to a single phrase in error_report(). Also, I find strerror() often more useful.

hw/s390x/s390-virtio-ccw.c static int gtod_load(QEMUFile *f, void *opaque, int version_id) · line 223

Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +1 -1
     }
 
-    return 0;
+    return r;
 }
 
 static SaveVMHandlers savevm_gtod = {

Otherwise looks good.

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] s390/kvm: Support for get/set of extended TOD-Clock for guest

In reply to Christian Borntraeger
Quoted 28 lines · Christian Borntraeger

From: "Collin L. Walling" <[email protected]>

Provides an interface for getting and setting the guest's extended TOD-Clock via a single ioctl to kvm. If the ioctl fails because it is not support by kvm, then we fall back to the old style of retrieving the clock via two ioctls.

If kvm fails to set a nonzero epoch index, then we ultimately fail the migration altogether and the guest will resume normally on the original host machine.

---
 hw/s390x/s390-virtio-ccw.c |  8 +++-----
 target/s390x/cpu.c         | 26 +++++++++++++++++++-------
 target/s390x/kvm-stub.c    | 10 ++++++++++
 target/s390x/kvm.c         | 35 +++++++++++++++++++++++++++++++++++
 target/s390x/kvm_s390x.h   |  2 ++
 5 files changed, 69 insertions(+), 12 deletions(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index fafbc6d..bad09f5 100644

hw/s390x/s390-virtio-ccw.c static int gtod_load(QEMUFile *f, void *opaque, int version_id) · line 218

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +2 -4
@@ -213,13 +213,11 @@ static int gtod_load(QEMUFile *f, void *opaque, int version_id)
 
     r = s390_set_clock(&tod_high, &tod_low);
     if (r) {
-        warn_report("Unable to set guest clock for migration: %s",
-                    strerror(-r));
-        error_printf("Guest clock will not be restored "
-                     "which could cause the guest to hang.");
+        error_report("Unable to set guest clock value. "
+                     "s390_get_clock returned error %d.\n", r);
     }

This should go into a separate patch (I think also Conny referred to that in her comment).

hw/s390x/s390-virtio-ccw.c static int gtod_load(QEMUFile *f, void *opaque, int version_id) · line 222

Quoted 5 lines
hw/s390x/s390-virtio-ccw.c +1 -1
-    return 0;
+    return r;
 }
 

[..]
.c

target/s390x/kvm.c int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_low) · line 651

Quoted 13 lines

index ebb75ca..ef7374c 100644

target/s390x/kvm.c +6 -0
@@ -643,6 +643,25 @@ int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
     return kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
 }
 
+int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_low)
+{
+    int r;
+
+    struct kvm_s390_vm_tod_clock gtod;
+

Please drop spaces between initializers.

Quoted 17 lines
target/s390x/kvm.c +13 -0
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_TOD,
+        .attr = KVM_S390_VM_TOD_EXT,
+        .addr = (uint64_t)(&gtod),
+    };
+
+    r = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    *tod_high = gtod.epoch_idx;
+    *tod_low  = gtod.tod;
+
+    return r;
+}
+
 int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
 {
     int r;

target/s390x/kvm.c int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low) · line 691

Quoted 10 lines
target/s390x/kvm.c +7 -0
@@ -663,6 +682,22 @@ int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
     return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
 }
 
+int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_low)
+{
+    struct kvm_s390_vm_tod_clock gtod = {
+        .epoch_idx = *tod_high,
+        .tod  = *tod_low,
+    };
+

dito

Quoted 18 lines
target/s390x/kvm.c +9 -0
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_TOD,
+        .attr = KVM_S390_VM_TOD_EXT,
+        .addr = (uint64_t)(&gtod),
+    };
+
+    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+}
+
 /**
  * kvm_s390_mem_op:
  * @addr:      the logical start address in guest memory
target/s390x/kvm_s390x.h +0 -0
index 2d594bd..501fc5a 100644

target/s390x/kvm_s390x.h int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu); · line 37

Quoted 9 lines
target/s390x/kvm_s390x.h +2 -0
@@ -29,7 +29,9 @@ int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu);
 int kvm_s390_get_ri(void);
 int kvm_s390_get_gs(void);
 int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_clock);
+int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_clock);
 int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_clock);
+int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_clock);
 void kvm_s390_enable_css_support(S390CPU *cpu);
 int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
                                     int vq, bool assign);

Apart from that looks good to me (although I am still 99.9% sure that the kernel part is not fully correct, but have no time to look into it)

Signature · 3 lines
Thanks,

David
#5 lore raw
In reply to Christian Borntraeger
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 0/2] s390/z14: extended TOD-clock support

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
96c6906c93 s390/kvm: Support for get/set of extended TOD-Clock for guest f4ecf143f0 linux-headers: Update linux headers for extended TOD-Clock

=== OUTPUT BEGIN ===
Checking PATCH 1/2: linux-headers: Update linux headers for extended TOD-Clock... Checking PATCH 2/2: s390/kvm: Support for get/set of extended TOD-Clock for guest...
ERROR: Error messages should not contain newlines
#34: FILE: hw/s390x/s390-virtio-ccw.c:217:
+ "s390_get_clock returned error %d.\n", r);

total: 1 errors, 0 warnings, 134 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]