From patchwork Tue Oct 16 12:12:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10643481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C634B112B for ; Tue, 16 Oct 2018 12:13:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71E2289E1 for ; Tue, 16 Oct 2018 12:13:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABB2B28F96; Tue, 16 Oct 2018 12:13:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 509EA289E1 for ; Tue, 16 Oct 2018 12:13:32 +0000 (UTC) Received: from localhost ([::1]:57698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCOE7-0003CH-KO for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Oct 2018 08:13:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCOD6-0002Kc-G3 for qemu-devel@nongnu.org; Tue, 16 Oct 2018 08:12:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCOCy-0005Yp-RV for qemu-devel@nongnu.org; Tue, 16 Oct 2018 08:12:26 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:33969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCOCy-0005XD-9l for qemu-devel@nongnu.org; Tue, 16 Oct 2018 08:12:20 -0400 Received: by mail-pl1-x644.google.com with SMTP id f18-v6so10942261plr.1 for ; Tue, 16 Oct 2018 05:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=EDAUSM4aXsNXXJnhmXoaLuTAYn25ZN1PaiAD/QTFPM8=; b=TLnLX3jZNo/Cw+GTWHwABTVY2Gia278TPc49AEmpxnfAOEhtV+AgmH8vLgqrPaqOXU 5OZH1NZ6L8SNEPLuu253jn//X/wKa8d72gR2fWHtVcVO7SU9otVXO4ONCUSY+lUHG/7Z nVszt1p2VDkO/tQ16o/Ee6WZ+kTBCFedml4r4VFTZsTA3FuMOaxM+AGyMCCRZ52eZtiy +EZL0yxbvw3qdYEndWRsbcE1b9McAZiJDqw0NZtnAUWV0XEMVqx+TwigfmXJfmImerms 9xYq8HGVOv55mxVtLdsLWrpro/zLs0Ur+pxVNJW3eEYigum7h3TV1D42Zzajd6S8jFLf whyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EDAUSM4aXsNXXJnhmXoaLuTAYn25ZN1PaiAD/QTFPM8=; b=pw5LzWJQ/pmK9cJacFk2YQu3p94/NV2cy6/GKAnNqzVSD5dIdrbLWSmTUohYEABCCt ZBGMr0HYhD9TTdWV67pE7li7usEw2L8LFsixW8bIAbuJGfIMA7sh/X4FrcAumVkA3iOm 3GoXd7xg8m/2tr734E98P/S6YKmcsik1j0hjGwguIj9k0FGmm647viZJ4T5AljF2jC/X ZKIsRpFtVqUrfUOHGWBRmEyGCpSEAX0eN4usIESMmofn5I57iGR0IMbhEcFJLgUS1CNW I59oghuB0FfzlZ4GRpFOmKS0zUwNP5+f4B2HdbB4OMBhEP/HYFVHxnU2r/xlruPIfw9P 8dgA== X-Gm-Message-State: ABuFfoiT1y4B9ms9iZkzRJQeg1gVISqUg1g+10OkPq6EEPN04/MIqJpG gN8GjXPpG2kxFrzkn5DII98= X-Google-Smtp-Source: ACcGV60YYqZLesss1mDg4NTns8WDohbEy2ftk1heTJ3hOONpEHRVnI5MyFK3hN+iXUylwJldHxLYBw== X-Received: by 2002:a17:902:15a8:: with SMTP id m37-v6mr21188781pla.132.1539691938528; Tue, 16 Oct 2018 05:12:18 -0700 (PDT) Received: from localhost.localdomain.localdomain ([103.65.40.65]) by smtp.gmail.com with ESMTPSA id u77-v6sm24209706pfj.40.2018.10.16.05.12.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Oct 2018 05:12:18 -0700 (PDT) From: Li Qiang To: pbonzini@redhat.com Date: Tue, 16 Oct 2018 05:12:13 -0700 Message-Id: <1539691933-4211-1-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH] kvm: move vcpu mmap size to KVMState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@163.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);