Received: from eggs.gnu.org ([2001:4830:134:3::10]:57517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrpO8-0001ls-Bt for qemu-devel@nongnu.org; Tue, 03 Jun 2014 10:08:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrpNy-0008Lg-RK for qemu-devel@nongnu.org; Tue, 03 Jun 2014 10:08:28 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:42762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrpNy-0008LN-9D for qemu-devel@nongnu.org; Tue, 03 Jun 2014 10:08:18 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 3 Jun 2014 15:08:17 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 599731B0805F for ; Tue, 3 Jun 2014 15:08:37 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s53E8EBI24379534 for ; Tue, 3 Jun 2014 14:08:14 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s53E8DFg022906 for ; Tue, 3 Jun 2014 08:08:14 -0600 From: Cornelia Huck Date: Tue, 3 Jun 2014 16:07:58 +0200 Message-Id: <1401804485-14801-4-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <1401804485-14801-1-git-send-email-cornelia.huck@de.ibm.com> References: <1401804485-14801-1-git-send-email-cornelia.huck@de.ibm.com> Subject: [Qemu-devel] [PATCH 03/10] s390x/kvm: enable/reset cmma via vm attributes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Cornelia Huck , borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, agraf@suse.de, Dominik Dingel From: Dominik Dingel Exploit the new api for userspace-controlled cmma. If supported, enable cmma during kvm initialization and register a reset handler for cmma, which is also called directly from the load IPL code. The reset functionality is needed to reset the cmma state of the guest pages, e.g. if a system reset is triggered via qemu monitor; otherwise this could result in data corruption. A guest triggered reboot may now lead to multiple cmma resets; this is OK, however, as this is slowpath anyway and the simplest way to achieve the intended effects. Signed-off-by: Dominik Dingel Acked-by: Christian Borntraeger Acked-by: Cornelia Huck Signed-off-by: Cornelia Huck --- target-s390x/cpu.h | 12 +++++++++ target-s390x/kvm.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ target-s390x/misc_helper.c | 2 ++ trace-events | 4 +++ 4 files changed, 76 insertions(+) diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 06454d6..808b906 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -1074,6 +1074,7 @@ void kvm_s390_enable_css_support(S390CPU *cpu); int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, int vq, bool assign); int kvm_s390_cpu_restart(S390CPU *cpu); +void kvm_s390_clear_cmma_callback(void *opaque); #else static inline void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, @@ -1098,8 +1099,19 @@ static inline int kvm_s390_cpu_restart(S390CPU *cpu) { return -ENOSYS; } +static inline void kvm_s390_clear_cmma_callback(void *opaque) +{ +} #endif +static inline void cmma_reset(S390CPU *cpu) +{ + if (kvm_enabled()) { + CPUState *cs = CPU(cpu); + kvm_s390_clear_cmma_callback(cs->kvm_state); + } +} + static inline int s390_cpu_restart(S390CPU *cpu) { if (kvm_enabled()) { diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 7a07f9d..0a2a205 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -32,6 +32,7 @@ #include "qemu/timer.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "hw/hw.h" #include "cpu.h" #include "sysemu/device_tree.h" #include "qapi/qmp/qjson.h" @@ -104,10 +105,67 @@ static int cap_async_pf; static void *legacy_s390_alloc(size_t size); +static int kvm_s390_check_clear_cmma(KVMState *s) +{ + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_CLR_CMMA, + }; + + return kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attr); +} + +static int kvm_s390_check_enable_cmma(KVMState *s) +{ + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_ENABLE_CMMA, + }; + + return kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attr); +} + +void kvm_s390_clear_cmma_callback(void *opaque) +{ + int rc; + KVMState *s = opaque; + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_CLR_CMMA, + }; + + rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr); + trace_kvm_clear_cmma(rc); +} + +static void kvm_s390_enable_cmma(KVMState *s) +{ + int rc; + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_ENABLE_CMMA, + }; + + if (kvm_s390_check_enable_cmma(s) || kvm_s390_check_clear_cmma(s)) { + return; + } + + rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr); + if (!rc) { + qemu_register_reset(kvm_s390_clear_cmma_callback, s); + } + trace_kvm_enable_cmma(rc); +} + int kvm_arch_init(KVMState *s) { cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS); cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF); + + if (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES)) { + kvm_s390_enable_cmma(s); + } + if (!kvm_check_extension(s, KVM_CAP_S390_GMAP) || !kvm_check_extension(s, KVM_CAP_S390_COW)) { phys_mem_set_alloc(legacy_s390_alloc); diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c index 44c08f3..fa2eeda 100644 --- a/target-s390x/misc_helper.c +++ b/target-s390x/misc_helper.c @@ -136,6 +136,7 @@ static int modified_clear_reset(S390CPU *cpu) pause_all_vcpus(); cpu_synchronize_all_states(); cpu_full_reset_all(); + cmma_reset(cpu); io_subsystem_reset(); scc->load_normal(CPU(cpu)); cpu_synchronize_all_post_reset(); @@ -150,6 +151,7 @@ static int load_normal_reset(S390CPU *cpu) pause_all_vcpus(); cpu_synchronize_all_states(); cpu_reset_all(); + cmma_reset(cpu); io_subsystem_reset(); scc->initial_cpu_reset(CPU(cpu)); scc->load_normal(CPU(cpu)); diff --git a/trace-events b/trace-events index ffe6e62..e984e76 100644 --- a/trace-events +++ b/trace-events @@ -1258,3 +1258,7 @@ xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO space (ad # hw/pci/pci_host.c pci_cfg_read(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x -> 0x%x" pci_cfg_write(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x <- 0x%x" + +# target-s390x/kvm.c +kvm_enable_cmma(int rc) "CMMA: enabling with result code %d" +kvm_clear_cmma(int rc) "CMMA: clearing with result code %d" -- 1.7.9.5