From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: qemu-devel@nongnu.org
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>,
borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, agraf@suse.de,
Dominik Dingel <dingel@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 03/10] s390x/kvm: enable/reset cmma via vm attributes
Date: Tue, 3 Jun 2014 16:07:58 +0200 [thread overview]
Message-ID: <1401804485-14801-4-git-send-email-cornelia.huck@de.ibm.com> (raw)
In-Reply-To: <1401804485-14801-1-git-send-email-cornelia.huck@de.ibm.com>
From: Dominik Dingel <dingel@linux.vnet.ibm.com>
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 <dingel@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
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
next prev parent reply other threads:[~2014-06-03 14:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-03 14:07 [Qemu-devel] [PATCH 00/10] pending s390 patches Cornelia Huck
2014-06-03 14:07 ` [Qemu-devel] [PATCH 01/10] s390x/css: handle emw correctly for tsch Cornelia Huck
2014-06-03 14:07 ` [Qemu-devel] [PATCH 02/10] s390x/kvm: make flic play well with old kernels Cornelia Huck
2014-06-03 14:07 ` Cornelia Huck [this message]
2014-06-03 14:07 ` [Qemu-devel] [PATCH 04/10] s390x/kvm: Log unmanageable external interruptions Cornelia Huck
2014-06-03 14:08 ` [Qemu-devel] [PATCH 05/10] s390x/kvm: Log unmanageable program interruptions Cornelia Huck
2014-06-03 14:08 ` [Qemu-devel] [PATCH 06/10] s390/virtio-ccw: migration support Cornelia Huck
2014-06-03 14:08 ` [Qemu-devel] [PATCH 07/10] s390x: consolidate floating interrupts Cornelia Huck
2014-06-03 14:08 ` [Qemu-devel] [PATCH 08/10] s390x/kvm: add alternative injection interface Cornelia Huck
2014-06-03 14:08 ` [Qemu-devel] [PATCH 09/10] s390x: cleanup interrupt injection Cornelia Huck
2014-06-03 14:08 ` [Qemu-devel] [PATCH 10/10] s390x/kvm: inject via flic Cornelia Huck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401804485-14801-4-git-send-email-cornelia.huck@de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--cc=agraf@suse.de \
--cc=borntraeger@de.ibm.com \
--cc=dingel@linux.vnet.ibm.com \
--cc=jfrei@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).