From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEEC3C433DB for ; Wed, 10 Mar 2021 20:35:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F5B264F58 for ; Wed, 10 Mar 2021 20:35:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F5B264F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5YK-0007W0-TA for qemu-devel@archiver.kernel.org; Wed, 10 Mar 2021 15:35:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5W6-0005uW-RE for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W1-0000c9-GI for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nYyDNXI+29l7QpN/hyZzbO6CzINI95wpx6Vs4UISad8=; b=X+oHy2o3GgfgsinBlnFVjTXkugvRWrrWm3L6dSCkTFKJrJiI3/1hnl8KOQJ1BXw6kUV/W2 yG5/mX0xRldknRCaBB7LWUODGk9JHK5+bC9a66SB89j12BSWYnglzE4JhZWA6ImRnE/M9a B6NjW3A2QM2wpLC13uN4YxBzqerrGNc= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-uSOHk71wMNyg4l7Dv6sGig-1; Wed, 10 Mar 2021 15:33:07 -0500 X-MC-Unique: uSOHk71wMNyg4l7Dv6sGig-1 Received: by mail-qt1-f197.google.com with SMTP id d11so13879052qth.3 for ; Wed, 10 Mar 2021 12:33:07 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=nYyDNXI+29l7QpN/hyZzbO6CzINI95wpx6Vs4UISad8=; b=mmFis1h7nnWpbvDxuYgg9sbkaDQVpT6+QDLS8i0w+LX5WWS/nMQl9e0ruHmxIwJx/u 4IP7lnGMzankVzXwt1wV+Yx0grh7PCdYaFjBUtE3omeZUlUh53mnlFXU4gy3JhwXKB07 ePMvDgIPoiPpLUOGXSIuMdsAfwVrjmaq/oIFzwTdbSJIgdE2ZFpktw0UVH1KBK0U7Db1 JcieQJ/FQfgFYd8j0OsI1ElgFJXPHKF1Ws8/2umr1MNZyQZUkbXOscIdqBMyhgHLCgqL 9I1bWZ93YTmwKGBNxZISYIJo+MLPXdEtZu38aGloyoBYurNVMF6S3MLxYwC2sxoMjbbJ d3NA== X-Gm-Message-State: AOAM533oO0HCzIFmaAXduTEpDT4Ag0y70/RDGCynxibDFItOsXpkrk4o HHcjSdaNkV52rudIDXsem4yH44kG2XKVAqxIqi0hnBI49zq0vXmrM576YeU5FyfSFRBjwc6zN/1 629GeQd9bbRBKIRlII19BFXVo0wxMH4QmH/eaNdXs/ar2wbX7JqM1M/eVpTFR0mkI X-Received: by 2002:ac8:7384:: with SMTP id t4mr4343323qtp.364.1615408386609; Wed, 10 Mar 2021 12:33:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4xEwELKHIqrHYvrru4mtQq6HdFI6MPpeZvgbp+5rPwfupmKiq0HTIYsCRsCTP0KYW0svu7w== X-Received: by 2002:ac8:7384:: with SMTP id t4mr4343301qtp.364.1615408386304; Wed, 10 Mar 2021 12:33:06 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.89.138]) by smtp.gmail.com with ESMTPSA id z89sm306746qtd.5.2021.03.10.12.33.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:05 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 03/10] KVM: Create the KVMSlot dirty bitmap on flag changes Date: Wed, 10 Mar 2021 15:32:54 -0500 Message-Id: <20210310203301.194842-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310203301.194842-1-peterx@redhat.com> References: <20210310203301.194842-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.243, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Previously we have two places that will create the per KVMSlot dirty bitmap: 1. When a newly created KVMSlot has dirty logging enabled, 2. When the first log_sync() happens for a memory slot. The 2nd case is lazy-init, while the 1st case is not (which is a fix of what the 2nd case missed). To do explicit initialization of dirty bitmaps, what we're missing is to create the dirty bitmap when the slot changed from not-dirty-track to dirty-track. Do that in kvm_slot_update_flags(). With that, we can safely remove the 2nd lazy-init. This change will be needed for kvm dirty ring because kvm dirty ring does not use the log_sync() interface at all. Also move all the pre-checks into kvm_slot_init_dirty_bitmap(). Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 94e881f123b..fa337418636 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -179,6 +179,8 @@ static QemuMutex kml_slots_lock; #define kvm_slots_lock() qemu_mutex_lock(&kml_slots_lock) #define kvm_slots_unlock() qemu_mutex_unlock(&kml_slots_lock) +static void kvm_slot_init_dirty_bitmap(KVMSlot *mem); + static inline void kvm_resample_fd_remove(int gsi) { KVMResampleFd *rfd; @@ -502,6 +504,7 @@ static int kvm_slot_update_flags(KVMMemoryListener *kml, KVMSlot *mem, return 0; } + kvm_slot_init_dirty_bitmap(mem); return kvm_set_user_memory_region(kml, mem, false); } @@ -586,8 +589,12 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) /* Allocate the dirty bitmap for a slot */ -static void kvm_memslot_init_dirty_bitmap(KVMSlot *mem) +static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) { + if (!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) || mem->dirty_bmap) { + return; + } + /* * XXX bad kernel interface alert * For dirty bitmap, kernel allocates array of size aligned to @@ -642,11 +649,6 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, goto out; } - if (!mem->dirty_bmap) { - /* Allocate on the first log_sync, once and for all */ - kvm_memslot_init_dirty_bitmap(mem); - } - d.dirty_bitmap = mem->dirty_bmap; d.slot = mem->slot | (kml->as_id << 16); ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d); @@ -1190,14 +1192,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->start_addr = start_addr; mem->ram = ram; mem->flags = kvm_mem_flags(mr); - - if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { - /* - * Reallocate the bmap; it means it doesn't disappear in - * middle of a migrate. - */ - kvm_memslot_init_dirty_bitmap(mem); - } + kvm_slot_init_dirty_bitmap(mem); err = kvm_set_user_memory_region(kml, mem, true); if (err) { fprintf(stderr, "%s: error registering slot: %s\n", __func__, -- 2.26.2