From: Christian Borntraeger <borntraeger@de.ibm.com>
To: Alexander Graf <agraf@suse.de>
Cc: Heinz Graalfs <graalfs@linux.vnet.ibm.com>,
qemu-devel <qemu-devel@nongnu.org>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Jens Freimann <jfrei@linux.vnet.ibm.com>,
Avi Kivity <avi@redhat.com>,
Cornelia Huck <cornelia.huck@de.ibm.com>
Subject: [Qemu-devel] [PATCH 1/1] s390: autodetect map private
Date: Tue, 15 May 2012 14:49:44 +0200 [thread overview]
Message-ID: <1337086184-1535-2-git-send-email-borntraeger@de.ibm.com> (raw)
In-Reply-To: <1337086184-1535-1-git-send-email-borntraeger@de.ibm.com>
From: Christian Borntraeger <borntraeger@de.ibm.com>
kvm on specific s390 systems must not use MAP_PRIVATE since
host read-only page faults are delivered to the guest. Newer
systems allow the distinction via KVM_CAP_S390_COW
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
CC: Avi Kivity <avi@redhat.com>
---
exec.c | 54 ++++++++++++++++++++++++++++++++-------------
kvm-all.c | 6 +++++
kvm.h | 1 +
| 1 +
oslib-posix.c | 3 +++
5 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/exec.c b/exec.c
index 0607c9b..68c2940 100644
--- a/exec.c
+++ b/exec.c
@@ -2601,6 +2601,43 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
}
}
+/*
+ * lets make sure that we dont have the old s390x limitations regarding
+ * guest mappings
+ */
+static int legacy_s390x_mem_layout(void)
+{
+#if defined(TARGET_S390X) && defined(CONFIG_KVM)
+ return kvm_has_legacy_s390x_memlayout();
+#else
+ return 0;
+#endif
+}
+
+/*
+ * Legacy layout for s390:
+ * Older S390 KVM requires the topmost vma of the RAM to be
+ * smaller than an system defined value, which is at least 256GB.
+ * Larger systems have larger values. We put the guest between
+ * the end of data segment (system break) and this value. We
+ * use 32GB as a base to have enough room for the system break
+ * to grow. We also have to use MAP parameters that avoid
+ * read-only mapping of guest pages.
+ */
+static void *legacy_s390_alloc(ram_addr_t size)
+{
+ void *mem;
+
+ mem = mmap((void *) 0x800000000ULL, size,
+ PROT_EXEC|PROT_READ|PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+ if (mem == MAP_FAILED) {
+ fprintf(stderr, "Allocating RAM failed\n");
+ abort();
+ }
+ return mem;
+}
+
ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
MemoryRegion *mr)
{
@@ -2627,26 +2664,13 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
exit(1);
#endif
} else {
-#if defined(TARGET_S390X) && defined(CONFIG_KVM)
- /* S390 KVM requires the topmost vma of the RAM to be smaller than
- an system defined value, which is at least 256GB. Larger systems
- have larger values. We put the guest between the end of data
- segment (system break) and this value. We use 32GB as a base to
- have enough room for the system break to grow. */
- new_block->host = mmap((void*)0x800000000, size,
- PROT_EXEC|PROT_READ|PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
- if (new_block->host == MAP_FAILED) {
- fprintf(stderr, "Allocating RAM failed\n");
- abort();
- }
-#else
if (xen_enabled()) {
xen_ram_alloc(new_block->offset, size, mr);
+ } else if (legacy_s390x_mem_layout()) {
+ new_block->host = legacy_s390_alloc(size);
} else {
new_block->host = qemu_vmalloc(size);
}
-#endif
qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
}
}
diff --git a/kvm-all.c b/kvm-all.c
index 9b73ccf..f794546 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1417,6 +1417,12 @@ int kvm_has_many_ioeventfds(void)
return kvm_state->many_ioeventfds;
}
+int kvm_has_legacy_s390x_memlayout(void)
+{
+ return !kvm_check_extension(kvm_state, KVM_CAP_S390_GMAP) ||
+ !kvm_check_extension(kvm_state, KVM_CAP_S390_COW);
+}
+
int kvm_has_gsi_routing(void)
{
#ifdef KVM_CAP_IRQ_ROUTING
diff --git a/kvm.h b/kvm.h
index 4ccae8c..37f40ee 100644
--- a/kvm.h
+++ b/kvm.h
@@ -56,6 +56,7 @@ int kvm_has_xsave(void);
int kvm_has_xcrs(void);
int kvm_has_pit_state2(void);
int kvm_has_many_ioeventfds(void);
+int kvm_has_legacy_s390x_memlayout(void);
int kvm_has_gsi_routing(void);
int kvm_allows_irq0_override(void);
--git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index ee7bd9c..a7a2d6f 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -590,6 +590,7 @@ struct kvm_ppc_pvinfo {
#define KVM_CAP_SYNC_REGS 74
#define KVM_CAP_PCI_2_3 75
#define KVM_CAP_KVMCLOCK_CTRL 76
+#define KVM_CAP_S390_COW 79
#ifdef KVM_CAP_IRQ_ROUTING
diff --git a/oslib-posix.c b/oslib-posix.c
index b6a3c7f..93902ac 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -41,6 +41,9 @@ extern int daemon(int, int);
therefore we need special code which handles running on Valgrind. */
# define QEMU_VMALLOC_ALIGN (512 * 4096)
# define CONFIG_VALGRIND
+#elif defined(__linux__) && defined(__s390x__)
+ /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */
+# define QEMU_VMALLOC_ALIGN (256 * 4096)
#else
# define QEMU_VMALLOC_ALIGN getpagesize()
#endif
--
1.7.10.2
next prev parent reply other threads:[~2012-05-15 12:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1337084128-38219-2-git-send-email-borntraeger@de.ibm.com>
2012-05-15 12:49 ` [Qemu-devel] [PATCH 0/1] memory detection hack for s390 Christian Borntraeger
2012-05-15 12:49 ` Christian Borntraeger [this message]
2012-06-05 12:50 ` [Qemu-devel] [PATCH 1/1] s390: autodetect map private Alexander Graf
2012-06-05 12:44 ` [Qemu-devel] [PATCH 0/1] memory detection hack for s390 Alexander Graf
2012-07-10 16:23 [Qemu-devel] [PULL 0/1] s390 patch queue 2012-07-10 Alexander Graf
2012-07-10 16:24 ` [Qemu-devel] [PATCH 1/1] s390: autodetect map private Alexander Graf
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=1337086184-1535-2-git-send-email-borntraeger@de.ibm.com \
--to=borntraeger@de.ibm.com \
--cc=agraf@suse.de \
--cc=avi@redhat.com \
--cc=cornelia.huck@de.ibm.com \
--cc=graalfs@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).