qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Li Qiang <liq3ea@gmail.com>
To: pbonzini@redhat.com
Cc: qemu-devel@nongnu.org, liq3ea@163.com, Li Qiang <liq3ea@gmail.com>
Subject: [Qemu-devel] [PATCH] kvm: move vcpu mmap size to KVMState
Date: Tue, 16 Oct 2018 05:12:13 -0700	[thread overview]
Message-ID: <1539691933-4211-1-git-send-email-liq3ea@gmail.com> (raw)

First the mmap size is a kvm ioctl, so it can go kvm initialization.
Second this can avoid triggering KVM_GET_VCPU_MMAP_SIZE while
initializing and destroying every VCPU.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 accel/kvm/kvm-all.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index de12f78eb8..f5cc47ec9f 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -101,6 +101,7 @@ struct KVMState
     int nr_allocated_irq_routes;
     unsigned long *used_gsi_bitmap;
     unsigned int gsi_count;
+    long mmap_size;
     QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
 #endif
     KVMMemoryListener memory_listener;
@@ -285,20 +286,12 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, boo
 int kvm_destroy_vcpu(CPUState *cpu)
 {
     KVMState *s = kvm_state;
-    long mmap_size;
     struct KVMParkedVcpu *vcpu = NULL;
     int ret = 0;
 
     DPRINTF("kvm_destroy_vcpu\n");
 
-    mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
-    if (mmap_size < 0) {
-        ret = mmap_size;
-        DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
-        goto err;
-    }
-
-    ret = munmap(cpu->kvm_run, mmap_size);
+    ret = munmap(cpu->kvm_run, s->mmap_size);
     if (ret < 0) {
         goto err;
     }
@@ -332,7 +325,6 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
 int kvm_init_vcpu(CPUState *cpu)
 {
     KVMState *s = kvm_state;
-    long mmap_size;
     int ret;
 
     DPRINTF("kvm_init_vcpu\n");
@@ -347,14 +339,7 @@ int kvm_init_vcpu(CPUState *cpu)
     cpu->kvm_state = s;
     cpu->vcpu_dirty = true;
 
-    mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
-    if (mmap_size < 0) {
-        ret = mmap_size;
-        DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
-        goto err;
-    }
-
-    cpu->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
+    cpu->kvm_run = mmap(NULL, s->mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
                         cpu->kvm_fd, 0);
     if (cpu->kvm_run == MAP_FAILED) {
         ret = -errno;
@@ -1583,6 +1568,13 @@ static int kvm_init(MachineState *ms)
 
     s->vmfd = ret;
 
+    s->mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
+    if (s->mmap_size < 0) {
+        ret = s->mmap_size;
+        fprintf(stderr, "KVM_GET_VCPU_MMAP_SIZE failed\n");
+        goto err;
+    }
+
     /* check the vcpu limits */
     soft_vcpus_limit = kvm_recommended_vcpus(s);
     hard_vcpus_limit = kvm_max_vcpus(s);
-- 
2.11.0

                 reply	other threads:[~2018-10-16 12:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1539691933-4211-1-git-send-email-liq3ea@gmail.com \
    --to=liq3ea@gmail.com \
    --cc=liq3ea@163.com \
    --cc=pbonzini@redhat.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).