All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] 390x/kvm features
@ 2015-03-05 15:56 Jens Freimann
  2015-03-05 15:56 ` [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization Jens Freimann
  2015-03-05 15:56 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: passing max memory size to accelerator Jens Freimann
  0 siblings, 2 replies; 6+ messages in thread
From: Jens Freimann @ 2015-03-05 15:56 UTC (permalink / raw)
  To: Christian Borntraeger, Alexander Graf, Cornelia Huck
  Cc: Jens Freimann, qemu-devel

Conny, Alex, Christian,

Patch 1 enables Guest TOD migration
Patch 2 allows to limit the guest memory size 

Please note: This series needs a linux-headers sync with v4.0-rc2
to work and should be applied only after Michael Tsirkin's series
"virtio: pull headers from linux" was applied and a header sync
was done with the new scripts and header files.

Dominik Dingel (1):
  s390x/kvm: passing max memory size to accelerator

Jason J. Herne (1):
  s390x/kvm: Guest Migration TOD clock synchronization

 hw/s390x/s390-virtio-ccw.c | 14 ++++++++
 hw/s390x/s390-virtio.c     | 53 +++++++++++++++++++++++++++++
 linux-headers/linux/kvm.h  |  1 -
 target-s390x/cpu.h         | 48 ++++++++++++++++++++++++++
 target-s390x/kvm.c         | 84 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 199 insertions(+), 1 deletion(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization
  2015-03-05 15:56 [Qemu-devel] [PATCH 0/2] 390x/kvm features Jens Freimann
@ 2015-03-05 15:56 ` Jens Freimann
  2015-03-09  7:48   ` Christian Borntraeger
  2015-03-05 15:56 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: passing max memory size to accelerator Jens Freimann
  1 sibling, 1 reply; 6+ messages in thread
From: Jens Freimann @ 2015-03-05 15:56 UTC (permalink / raw)
  To: Christian Borntraeger, Alexander Graf, Cornelia Huck
  Cc: Jens Freimann, qemu-devel, Jason J. Herne, Jason J. Herne

From: "Jason J. Herne" <jjherne@us.ibm.com>

Synchronizes the guest TOD clock across a migration by sending the guest TOD
clock value to the destination system. If the guest TOD clock is not preserved
across a migration then the guest's view of time will snap backwards if the
destination host clock is behind the source host clock. This will cause the
guest to hang immediately upon resuming on the destination system.

Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>

---
 hw/s390x/s390-virtio-ccw.c |  4 ++++
 hw/s390x/s390-virtio.c     | 53 ++++++++++++++++++++++++++++++++++++++++++++++
 linux-headers/linux/kvm.h  |  1 -
 target-s390x/cpu.h         | 34 +++++++++++++++++++++++++++++
 target-s390x/kvm.c         | 39 ++++++++++++++++++++++++++++++++++
 5 files changed, 130 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 8f0ae59..078371a 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -171,6 +171,10 @@ static void ccw_init(MachineState *machine)
 
     /* Create VirtIO network adapters */
     s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
+
+    /* Register savevm handler for guest TOD clock */
+    register_savevm(NULL, "todclock", 0, 1,
+                    gtod_save, gtod_load, kvm_state);
 }
 
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index 412e49b..fb0ac64 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -39,6 +39,8 @@
 #include "hw/s390x/s390_flic.h"
 #include "hw/s390x/s390-virtio.h"
 
+#include "cpu.h"
+
 //#define DEBUG_S390
 
 #ifdef DEBUG_S390
@@ -53,6 +55,9 @@
 #define ZIPL_FILENAME                   "s390-zipl.rom"
 #define TYPE_S390_MACHINE               "s390-machine"
 
+#define S390_TOD_CLOCK_VALUE_MISSING    0x00
+#define S390_TOD_CLOCK_VALUE_PRESENT    0x01
+
 static VirtIOS390Bus *s390_bus;
 static S390CPU **ipi_states;
 
@@ -196,6 +201,51 @@ void s390_create_virtio_net(BusState *bus, const char *name)
     }
 }
 
+void gtod_save(QEMUFile *f, void *opaque)
+{
+    uint64_t tod_low;
+    uint8_t tod_high;
+    int r;
+
+    r = s390_get_clock(&tod_high, &tod_low);
+    if (r) {
+        fprintf(stderr, "WARNING: Unable to get guest clock for migration. "
+                        "Error code %d. Guest clock will not be migrated "
+                        "which could cause the guest to hang.\n", r);
+        qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
+        return;
+    }
+
+    qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
+    qemu_put_byte(f, tod_high);
+    qemu_put_be64(f, tod_low);
+}
+
+int gtod_load(QEMUFile *f, void *opaque, int version_id)
+{
+    uint64_t tod_low;
+    uint8_t tod_high;
+    int r;
+
+    if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
+        fprintf(stderr, "WARNING: Guest clock was not migrated. This could "
+                        "cause the guest to hang.\n");
+        return 0;
+    }
+
+    tod_high = qemu_get_byte(f);
+    tod_low = qemu_get_be64(f);
+
+    r = s390_set_clock(&tod_high, &tod_low);
+    if (r) {
+        fprintf(stderr, "WARNING: Unable to set guest clock value. "
+                        "s390_get_clock returned error %d. This could cause "
+                        "the guest to hang.\n", r);
+    }
+
+    return 0;
+}
+
 /* PC hardware initialisation */
 static void s390_init(MachineState *machine)
 {
@@ -253,6 +303,9 @@ static void s390_init(MachineState *machine)
 
     /* Create VirtIO network adapters */
     s390_create_virtio_net((BusState *)s390_bus, "virtio-net-s390");
+
+    /* Register savevm handler for guest TOD clock */
+    register_savevm(NULL, "todclock", 0, 1, gtod_save, gtod_load, NULL);
 }
 
 void s390_nmi(NMIState *n, int cpu_index, Error **errp)
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 84a4c10..ed80e49 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1094,7 +1094,6 @@ struct kvm_s390_ucas_mapping {
 #define KVM_SET_DEVICE_ATTR	  _IOW(KVMIO,  0xe1, struct kvm_device_attr)
 #define KVM_GET_DEVICE_ATTR	  _IOW(KVMIO,  0xe2, struct kvm_device_attr)
 #define KVM_HAS_DEVICE_ATTR	  _IOW(KVMIO,  0xe3, struct kvm_device_attr)
-
 /*
  * ioctls for vcpu fds
  */
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 60325b8..be53b5a 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -400,6 +400,8 @@ void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq);
 void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq);
 int kvm_s390_inject_flic(struct kvm_s390_irq *irq);
 void kvm_s390_access_exception(S390CPU *cpu, uint16_t code, uint64_t te_code);
+int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_clock);
+int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_clock);
 #else
 static inline void kvm_s390_virtio_irq(int config_change, uint64_t token)
 {
@@ -407,11 +409,40 @@ static inline void kvm_s390_virtio_irq(int config_change, uint64_t token)
 static inline void kvm_s390_service_interrupt(uint32_t parm)
 {
 }
+static inline int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
+{
+    return -ENOSYS;
+}
+static inline int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
+{
+    return -ENOSYS;
+}
 static inline void kvm_s390_access_exception(S390CPU *cpu, uint16_t code,
                                              uint64_t te_code)
 {
 }
 #endif
+
+static inline int s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
+{
+    if (kvm_enabled()) {
+        return kvm_s390_get_clock(tod_high, tod_low);
+    }
+    /* Fixme TCG */
+    *tod_high = 0;
+    *tod_low = 0;
+    return 0;
+}
+
+static inline int s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
+{
+    if (kvm_enabled()) {
+        return kvm_s390_set_clock(tod_high, tod_low);
+    }
+    /* Fixme TCG */
+    return 0;
+}
+
 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr);
 unsigned int s390_cpu_halt(S390CPU *cpu);
 void s390_cpu_unhalt(S390CPU *cpu);
@@ -421,6 +452,9 @@ static inline uint8_t s390_cpu_get_state(S390CPU *cpu)
     return cpu->env.cpu_state;
 }
 
+void gtod_save(QEMUFile *f, void *opaque);
+int gtod_load(QEMUFile *f, void *opaque, int version_id);
+
 /* service interrupts are floating therefore we must not pass an cpustate */
 void s390_sclp_extint(uint32_t parm);
 
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 6c4360b..6ef714c 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -441,6 +441,45 @@ int kvm_arch_get_registers(CPUState *cs)
     return 0;
 }
 
+int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
+{
+    int r;
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_TOD,
+        .attr = KVM_S390_VM_TOD_LOW,
+        .addr = (uint64_t)tod_low,
+    };
+
+    r = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (r) {
+        return r;
+    }
+
+    attr.attr = KVM_S390_VM_TOD_HIGH;
+    attr.addr = (uint64_t)tod_high;
+    return kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+}
+
+int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
+{
+    int r;
+
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_TOD,
+        .attr = KVM_S390_VM_TOD_LOW,
+        .addr = (uint64_t)tod_low,
+    };
+
+    r = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+    if (r) {
+        return r;
+    }
+
+    attr.attr = KVM_S390_VM_TOD_HIGH;
+    attr.addr = (uint64_t)tod_high;
+    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+}
+
 /*
  * Legacy layout for s390:
  * Older S390 KVM requires the topmost vma of the RAM to be
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/2] s390x/kvm: passing max memory size to accelerator
  2015-03-05 15:56 [Qemu-devel] [PATCH 0/2] 390x/kvm features Jens Freimann
  2015-03-05 15:56 ` [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization Jens Freimann
@ 2015-03-05 15:56 ` Jens Freimann
  2015-03-09  8:33   ` Christian Borntraeger
  1 sibling, 1 reply; 6+ messages in thread
From: Jens Freimann @ 2015-03-05 15:56 UTC (permalink / raw)
  To: Christian Borntraeger, Alexander Graf, Cornelia Huck
  Cc: Jens Freimann, qemu-devel, Dominik Dingel

From: Dominik Dingel <dingel@linux.vnet.ibm.com>

With "KVM: s390: Allow userspace to limit guest memory size" KVM is able to
do some optimizations based on the guest memory limit.

The guest memory limit is computed by the initial definition and with the notion of
hotplugged memory.

Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Reviewed-by: Guenther Hutzl <hutzl@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c | 10 ++++++++++
 target-s390x/cpu.h         | 14 ++++++++++++++
 target-s390x/kvm.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 078371a..eea0742 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -97,6 +97,7 @@ static void ccw_init(MachineState *machine)
     ram_addr_t pad_size = 0;
     ram_addr_t maxmem = qemu_opt_get_size(opts, "maxmem", my_ram_size);
     ram_addr_t standby_mem_size = maxmem - my_ram_size;
+    uint64_t kvm_limit;
 
     /* The storage increment size is a multiple of 1M and is a power of 2.
      * The number of storage increments must be MAX_STORAGE_INCREMENTS or fewer.
@@ -121,6 +122,15 @@ static void ccw_init(MachineState *machine)
 
     /* let's propagate the changed ram size into the global variable. */
     ram_size = my_ram_size;
+    machine->maxram_size = my_ram_size + standby_mem_size;
+
+    ret = s390_set_memory_limit(machine->maxram_size, &kvm_limit);
+    if (ret == -E2BIG) {
+        hw_error("qemu: host supports a maximum of %" PRIu64 " GB",
+                 kvm_limit >> 30);
+    } else if (ret) {
+        hw_error("qemu: setting the guest size failed");
+    }
 
     /* get a BUS */
     css_bus = virtual_css_bus_init();
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index be53b5a..f89e1e3 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -1062,6 +1062,7 @@ int kvm_s390_get_memslot_count(KVMState *s);
 void kvm_s390_clear_cmma_callback(void *opaque);
 int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
 void kvm_s390_reset_vcpu(S390CPU *cpu);
+int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit);
 #else
 static inline void kvm_s390_io_interrupt(uint16_t subchannel_id,
                                         uint16_t subchannel_nr,
@@ -1099,8 +1100,21 @@ static inline int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)
 static inline void kvm_s390_reset_vcpu(S390CPU *cpu)
 {
 }
+static inline int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit,
+                                         uint64_t *hw_limit)
+{
+    return 0;
+}
 #endif
 
+static inline int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)
+{
+    if (kvm_enabled()) {
+        return kvm_s390_set_mem_limit(kvm_state, new_limit, hw_limit);
+    }
+    return 0;
+}
+
 static inline void cmma_reset(S390CPU *cpu)
 {
     if (kvm_enabled()) {
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 6ef714c..f4bcca1 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -122,6 +122,51 @@ static int cap_async_pf;
 
 static void *legacy_s390_alloc(size_t size, uint64_t *align);
 
+static int kvm_s390_supports_mem_limit(KVMState *s)
+{
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_MEM_CTRL,
+        .attr = KVM_S390_VM_MEM_LIMIT_SIZE,
+    };
+
+    return (kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attr) == 0);
+}
+
+static int kvm_s390_query_mem_limit(KVMState *s, uint64_t *memory_limit)
+{
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_MEM_CTRL,
+        .attr = KVM_S390_VM_MEM_LIMIT_SIZE,
+        .addr = (uint64_t) memory_limit,
+    };
+
+    return kvm_vm_ioctl(s, KVM_GET_DEVICE_ATTR, &attr);
+}
+
+int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
+{
+    int rc;
+
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_MEM_CTRL,
+        .attr = KVM_S390_VM_MEM_LIMIT_SIZE,
+        .addr = (uint64_t) &new_limit,
+    };
+
+    if (!kvm_s390_supports_mem_limit(s)) {
+        return 0;
+    }
+
+    rc = kvm_s390_query_mem_limit(s, hw_limit);
+    if (rc) {
+        return rc;
+    } else if (*hw_limit < new_limit) {
+        return -E2BIG;
+    }
+
+    return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
+}
+
 static int kvm_s390_check_clear_cmma(KVMState *s)
 {
     struct kvm_device_attr attr = {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization
  2015-03-05 15:56 ` [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization Jens Freimann
@ 2015-03-09  7:48   ` Christian Borntraeger
  2015-03-09  8:41     ` Jens Freimann
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Borntraeger @ 2015-03-09  7:48 UTC (permalink / raw)
  To: Jens Freimann, Alexander Graf, Cornelia Huck
  Cc: qemu-devel, Jason J. Herne, Jason J. Herne

Am 05.03.2015 um 16:56 schrieb Jens Freimann:
[...]
> --- a/linux-headers/linux/kvm.h
> +++ b/linux-headers/linux/kvm.h
> @@ -1094,7 +1094,6 @@ struct kvm_s390_ucas_mapping {
>  #define KVM_SET_DEVICE_ATTR	  _IOW(KVMIO,  0xe1, struct kvm_device_attr)
>  #define KVM_GET_DEVICE_ATTR	  _IOW(KVMIO,  0xe2, struct kvm_device_attr)
>  #define KVM_HAS_DEVICE_ATTR	  _IOW(KVMIO,  0xe3, struct kvm_device_attr)
> -

Unrelated hunk. Can you fixup and resend?

[...]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] s390x/kvm: passing max memory size to accelerator
  2015-03-05 15:56 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: passing max memory size to accelerator Jens Freimann
@ 2015-03-09  8:33   ` Christian Borntraeger
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2015-03-09  8:33 UTC (permalink / raw)
  To: Jens Freimann, Alexander Graf, Cornelia Huck; +Cc: qemu-devel, Dominik Dingel

Am 05.03.2015 um 16:56 schrieb Jens Freimann:
> From: Dominik Dingel <dingel@linux.vnet.ibm.com>
> 
> With "KVM: s390: Allow userspace to limit guest memory size" KVM is able to
> do some optimizations based on the guest memory limit.
> 
> The guest memory limit is computed by the initial definition and with the notion of
> hotplugged memory.
> 
> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
> Reviewed-by: Guenther Hutzl <hutzl@linux.vnet.ibm.com>
> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> Signed-off-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
> Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>

Applied to s390-next. (Still waiting for Peter to pull the header update from
Michael)


> ---
>  hw/s390x/s390-virtio-ccw.c | 10 ++++++++++
>  target-s390x/cpu.h         | 14 ++++++++++++++
>  target-s390x/kvm.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 69 insertions(+)
> 
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index 078371a..eea0742 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -97,6 +97,7 @@ static void ccw_init(MachineState *machine)
>      ram_addr_t pad_size = 0;
>      ram_addr_t maxmem = qemu_opt_get_size(opts, "maxmem", my_ram_size);
>      ram_addr_t standby_mem_size = maxmem - my_ram_size;
> +    uint64_t kvm_limit;
> 
>      /* The storage increment size is a multiple of 1M and is a power of 2.
>       * The number of storage increments must be MAX_STORAGE_INCREMENTS or fewer.
> @@ -121,6 +122,15 @@ static void ccw_init(MachineState *machine)
> 
>      /* let's propagate the changed ram size into the global variable. */
>      ram_size = my_ram_size;
> +    machine->maxram_size = my_ram_size + standby_mem_size;
> +
> +    ret = s390_set_memory_limit(machine->maxram_size, &kvm_limit);
> +    if (ret == -E2BIG) {
> +        hw_error("qemu: host supports a maximum of %" PRIu64 " GB",
> +                 kvm_limit >> 30);
> +    } else if (ret) {
> +        hw_error("qemu: setting the guest size failed");
> +    }
> 
>      /* get a BUS */
>      css_bus = virtual_css_bus_init();
> diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
> index be53b5a..f89e1e3 100644
> --- a/target-s390x/cpu.h
> +++ b/target-s390x/cpu.h
> @@ -1062,6 +1062,7 @@ int kvm_s390_get_memslot_count(KVMState *s);
>  void kvm_s390_clear_cmma_callback(void *opaque);
>  int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
>  void kvm_s390_reset_vcpu(S390CPU *cpu);
> +int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit);
>  #else
>  static inline void kvm_s390_io_interrupt(uint16_t subchannel_id,
>                                          uint16_t subchannel_nr,
> @@ -1099,8 +1100,21 @@ static inline int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)
>  static inline void kvm_s390_reset_vcpu(S390CPU *cpu)
>  {
>  }
> +static inline int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit,
> +                                         uint64_t *hw_limit)
> +{
> +    return 0;
> +}
>  #endif
> 
> +static inline int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)
> +{
> +    if (kvm_enabled()) {
> +        return kvm_s390_set_mem_limit(kvm_state, new_limit, hw_limit);
> +    }
> +    return 0;
> +}
> +
>  static inline void cmma_reset(S390CPU *cpu)
>  {
>      if (kvm_enabled()) {
> diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
> index 6ef714c..f4bcca1 100644
> --- a/target-s390x/kvm.c
> +++ b/target-s390x/kvm.c
> @@ -122,6 +122,51 @@ static int cap_async_pf;
> 
>  static void *legacy_s390_alloc(size_t size, uint64_t *align);
> 
> +static int kvm_s390_supports_mem_limit(KVMState *s)
> +{
> +    struct kvm_device_attr attr = {
> +        .group = KVM_S390_VM_MEM_CTRL,
> +        .attr = KVM_S390_VM_MEM_LIMIT_SIZE,
> +    };
> +
> +    return (kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attr) == 0);
> +}
> +
> +static int kvm_s390_query_mem_limit(KVMState *s, uint64_t *memory_limit)
> +{
> +    struct kvm_device_attr attr = {
> +        .group = KVM_S390_VM_MEM_CTRL,
> +        .attr = KVM_S390_VM_MEM_LIMIT_SIZE,
> +        .addr = (uint64_t) memory_limit,
> +    };
> +
> +    return kvm_vm_ioctl(s, KVM_GET_DEVICE_ATTR, &attr);
> +}
> +
> +int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
> +{
> +    int rc;
> +
> +    struct kvm_device_attr attr = {
> +        .group = KVM_S390_VM_MEM_CTRL,
> +        .attr = KVM_S390_VM_MEM_LIMIT_SIZE,
> +        .addr = (uint64_t) &new_limit,
> +    };
> +
> +    if (!kvm_s390_supports_mem_limit(s)) {
> +        return 0;
> +    }
> +
> +    rc = kvm_s390_query_mem_limit(s, hw_limit);
> +    if (rc) {
> +        return rc;
> +    } else if (*hw_limit < new_limit) {
> +        return -E2BIG;
> +    }
> +
> +    return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
> +}
> +
>  static int kvm_s390_check_clear_cmma(KVMState *s)
>  {
>      struct kvm_device_attr attr = {
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization
  2015-03-09  7:48   ` Christian Borntraeger
@ 2015-03-09  8:41     ` Jens Freimann
  0 siblings, 0 replies; 6+ messages in thread
From: Jens Freimann @ 2015-03-09  8:41 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Cornelia Huck, Jason J. Herne, Alexander Graf, Jason J. Herne,
	qemu-devel

On Mon, Mar 09, 2015 at 08:48:57AM +0100, Christian Borntraeger wrote:
> Am 05.03.2015 um 16:56 schrieb Jens Freimann:
> [...]
> > --- a/linux-headers/linux/kvm.h
> > +++ b/linux-headers/linux/kvm.h
> > @@ -1094,7 +1094,6 @@ struct kvm_s390_ucas_mapping {
> >  #define KVM_SET_DEVICE_ATTR	  _IOW(KVMIO,  0xe1, struct kvm_device_attr)
> >  #define KVM_GET_DEVICE_ATTR	  _IOW(KVMIO,  0xe2, struct kvm_device_attr)
> >  #define KVM_HAS_DEVICE_ATTR	  _IOW(KVMIO,  0xe3, struct kvm_device_attr)
> > -
> 
> Unrelated hunk. Can you fixup and resend?
> 
> [...]

Yes, I'll fix it and resend.

Jens

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-09  8:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 15:56 [Qemu-devel] [PATCH 0/2] 390x/kvm features Jens Freimann
2015-03-05 15:56 ` [Qemu-devel] [PATCH 1/2] s390x/kvm: Guest Migration TOD clock synchronization Jens Freimann
2015-03-09  7:48   ` Christian Borntraeger
2015-03-09  8:41     ` Jens Freimann
2015-03-05 15:56 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: passing max memory size to accelerator Jens Freimann
2015-03-09  8:33   ` Christian Borntraeger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.