From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408725; cv=none; d=zohomail.com; s=zohoarc; b=i6TUirUO9Ttlc+94iyD+nHjsZSUQDtntJJuaLQ51qitlVZDpJ+c1N8B5tpAv6Wt/Aw/K/xterRAtknfIRceEWZXbkh93LBny4ZZ49tUuwyaWz85N9pesnqsuu/yaqycuCTnCIBm5N8NOiO2ZN4pgAvjFDRAkQ+VvGkWGb4HLCIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408725; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GGv4LvH3bqWlkXxLlo/pkxjQ8HX4BfZUoTqpMbfXXe8=; b=U1g8uvsclm23OR2L48UhgNfACuZ3lD56tKA9rpsXXS573t6OxMqfZED0Ls6+9xe1kGm+V+MXlxFMIj3ew4egVBM6UYsGGKHohuUujwUQY1cN3atX8QGk0mKtBlx1JKQzNj0rCphg4Wu0F6P+WetBMgObyUdZfDYUt1n8fztFHY0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615408725587697.8212118570683; Wed, 10 Mar 2021 12:38:45 -0800 (PST) Received: from localhost ([::1]:46560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5bQ-00022i-2U for importer@patchew.org; Wed, 10 Mar 2021 15:38:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5W6-0005tR-6Y for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W1-0000bS-Hc for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:13 -0500 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-qgr7BfIrN3qA4jg_b6zaYQ-1; Wed, 10 Mar 2021 15:33:05 -0500 Received: by mail-qv1-f71.google.com with SMTP id j3so13624894qvo.1 for ; Wed, 10 Mar 2021 12:33:05 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:03 -0800 (PST) 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=GGv4LvH3bqWlkXxLlo/pkxjQ8HX4BfZUoTqpMbfXXe8=; b=RPBFuRzqgZhqcxL8fu5Z7pIctDVkwAhTOIfu2a/Hx2fKRlJaSL78utSS+e7kS2/ZUmoCIX oup6/7KypVSim+S2Q6pTiVz8oc5GhND9GGHV2VPFhfe5UvYPlzVANpoZUJ8WTjpBlYh1cO zJ0VcuFRDUcqIxQ43HCpgN05PLfkQWg= X-MC-Unique: qgr7BfIrN3qA4jg_b6zaYQ-1 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=GGv4LvH3bqWlkXxLlo/pkxjQ8HX4BfZUoTqpMbfXXe8=; b=BTDbcpiONEvtwPoN1+WGkMctaSYM3t6/MFLYJ/zmmFQ3ILlCV/66XHfJfaYJqDH78P mjgnRj30npYk4clnlOGwPCyePuL4LAAwUeDcCsl4WBKZmvQ5F9m/b7Ju7gVym1Dr00kR YNzJg1IZFJ7L2wBMMnjSU9LXZbxEj3Hf88IrTIB0IzoDDk9iFaIZzJr5MqlHBXj7s5cd UjkDgGV9//CMk2mSryfhG0l9zXrg7+p1GUzNfS8ZoNj+fhcwePLM64hWUqIJSD/KcNFD v2FP/MoPKOoJqcjBXBI/kFnYT4HMYLzUYDywtWigOuMI7JKmESFHFI9JXudoPNHjz07l zcZQ== X-Gm-Message-State: AOAM5320j+62UHyel3qqgcBHCJno94llGmuxxtr0Ery/L9gwvZjzYvcJ girAhK3xG1rFmrdtfzH993g9FO7DxCmnmY9PYOOCAJU/+VWElqtuDgbS8TE/9VnfmFdA/tK/81z 2fwd6RsFnBz22IbNhsOh0ph0ebJvpKCx4zmGlwwBzTT5QqPKxqy+6S14icD5Na3SQ X-Received: by 2002:a37:5943:: with SMTP id n64mr4601296qkb.127.1615408384280; Wed, 10 Mar 2021 12:33:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxftJ4BJjRVAMTt0aH9Ud6oR8MEB0C8ngQvOhXi82o9OFmkftQNzhVhFxTy3h2e7QC0xoTmRw== X-Received: by 2002:a37:5943:: with SMTP id n64mr4601260qkb.127.1615408383951; Wed, 10 Mar 2021 12:33:03 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 01/10] memory: Introduce log_sync_global() to memory listener Date: Wed, 10 Mar 2021 15:32:52 -0500 Message-Id: <20210310203301.194842-2-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.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_H4=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Some of the memory listener may want to do log synchronization without being able to specify a range of memory to sync but always globally. Such a memory listener should provide this new method instead of the log_sync() method. Obviously we can also achieve similar thing when we put the global sync logic into a log_sync() handler. However that's not efficient enough because otherwise memory_global_dirty_log_sync() may do the global sync N times, where N is the number of flat ranges in the address space. Make this new method be exclusive to log_sync(). Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- include/exec/memory.h | 12 ++++++++++++ softmmu/memory.c | 33 +++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index c6fb714e499..e52e2c31eb7 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -616,6 +616,18 @@ struct MemoryListener { */ void (*log_sync)(MemoryListener *listener, MemoryRegionSection *sectio= n); =20 + /** + * @log_sync_global: + * + * This is the global version of @log_sync when the listener does + * not have a way to synchronize the log with finer granularity. + * When the listener registers with @log_sync_global defined, then + * its @log_sync must be NULL. Vice versa. + * + * @listener: The #MemoryListener. + */ + void (*log_sync_global)(MemoryListener *listener); + /** * @log_clear: * diff --git a/softmmu/memory.c b/softmmu/memory.c index 874a8fccdee..f655ed83129 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2056,6 +2056,10 @@ void memory_region_set_dirty(MemoryRegion *mr, hwadd= r addr, memory_region_get_dirty_log_mask(m= r)); } =20 +/* + * If memory region `mr' is NULL, do global sync. Otherwise, sync + * dirty bitmap for the specified memory region. + */ static void memory_region_sync_dirty_bitmap(MemoryRegion *mr) { MemoryListener *listener; @@ -2069,18 +2073,24 @@ static void memory_region_sync_dirty_bitmap(MemoryR= egion *mr) * address space once. */ QTAILQ_FOREACH(listener, &memory_listeners, link) { - if (!listener->log_sync) { - continue; - } - as =3D listener->address_space; - view =3D address_space_get_flatview(as); - FOR_EACH_FLAT_RANGE(fr, view) { - if (fr->dirty_log_mask && (!mr || fr->mr =3D=3D mr)) { - MemoryRegionSection mrs =3D section_from_flat_range(fr, vi= ew); - listener->log_sync(listener, &mrs); + if (listener->log_sync) { + as =3D listener->address_space; + view =3D address_space_get_flatview(as); + FOR_EACH_FLAT_RANGE(fr, view) { + if (fr->dirty_log_mask && (!mr || fr->mr =3D=3D mr)) { + MemoryRegionSection mrs =3D section_from_flat_range(fr= , view); + listener->log_sync(listener, &mrs); + } } + flatview_unref(view); + } else if (listener->log_sync_global) { + /* + * No matter whether MR is specified, what we can do here + * is to do a global sync, because we are not capable to + * sync in a finer granularity. + */ + listener->log_sync_global(listener); } - flatview_unref(view); } } =20 @@ -2768,6 +2778,9 @@ void memory_listener_register(MemoryListener *listene= r, AddressSpace *as) { MemoryListener *other =3D NULL; =20 + /* Only one of them can be defined for a listener */ + assert(!(listener->log_sync && listener->log_sync_global)); + listener->address_space =3D as; if (QTAILQ_EMPTY(&memory_listeners) || listener->priority >=3D QTAILQ_LAST(&memory_listeners)->priorit= y) { --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408652; cv=none; d=zohomail.com; s=zohoarc; b=TI36sWGL2bGYWyO53aznHmlSecl9OKHTLNVfWGVxDYY3xDPoil5znOob5nOkN7d9GXvazvHoN0q0DgBgoT97g2+E/Kz2ZdwBIjegV6gJYV8lhUbyv1UyY3zOJVmnYzpLXBSY+2wOM2XeevrRL02Wn39rifmolIh9o0KOl5kp0LY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408652; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=W45wrGyush/oGSqrXaYtg/y5rrnMn7xxwc1GgVTmze0=; b=NHvnpsZT5p2vMmBB1JSYTedzL41lv5e/RKRZUVjQbm2SB9VEvnNMxDuix8oRuIJdwZZ6yFofgoobBvj5S6am2UHWYo/NL2W6Nf4GIcOz9/D2lWd8O7K5meailtDTc06us/Brgio1NF4kXJFJAOJaxlEjptsqxFQHzAPyWX5uvcY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615408652265795.6445305074318; Wed, 10 Mar 2021 12:37:32 -0800 (PST) Received: from localhost ([::1]:45006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5aE-0001J3-SA for importer@patchew.org; Wed, 10 Mar 2021 15:37:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5W4-0005rI-TL for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W1-0000aT-6H for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:12 -0500 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-2-GrXgl3OXCSDCeXH0ieFg-1; Wed, 10 Mar 2021 15:33:06 -0500 Received: by mail-qk1-f198.google.com with SMTP id i188so13712771qkd.7 for ; 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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408387; 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=W45wrGyush/oGSqrXaYtg/y5rrnMn7xxwc1GgVTmze0=; b=DASuEIjKOYB1nzS/A1AXSrv9zfIgncsIzPSdVBU7lpArWFxfSJSOg5drENU6K3VIe2XMOF yTqJAA4nQn/DVKaFxE4lHmowpHUXflB/4P0BQtkuGZdhfxdm1ulbKnJiyBmec3ebGIYUKs 62/qFzN1fIdC7QnL9y68WE8NQVaU0DQ= X-MC-Unique: 2-GrXgl3OXCSDCeXH0ieFg-1 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=W45wrGyush/oGSqrXaYtg/y5rrnMn7xxwc1GgVTmze0=; b=etpuPMuQGdG47rc/nI9axLL+hQs+rViRzvl0mIAnCc6HIZc19Ug9ubW8ob7hyNB4Mb b3Mt3cGbOa1P8TG81thifzmf5rXr1LU4hw/b3plTlWuw6nqzhL6ySjMaT5ZxAJc5xl4q Aa6fp0NSXPoy7r4prvy1geHzyfs3VgmvzxWFncm0PGDwP46G3ug/k5rr4+LrO0TtRmT7 b1B/pdrTTlKFvrhqN97BYMgyfX3VXIlv9vhg3xT94/y9+5KlFMCevQTjYJ4BJxLvapny k9+4lImh2qq1Yu3J8kM4LE5wvI98ZRwZ/Kt3AIIDx8sevaMMpckUguG7Xma7vaI8/Pca xb2g== X-Gm-Message-State: AOAM5316/EqP+7pX9kgKI54XZhTV+2pzUmRTIhOGWujBUGvou37EtklX sroUVskHaCb7/hFb+RL1wdqIPud0hzpeLwfJZa6eLq6Pdf/1t/e5Bz+mkO4TBakv46P+IK1/+n6 ZRzH0A46nX4Y50ZJ+XTex/HuSNYMwU/PoxHVQm0pr0m0qpLIyMW9wtjpAsdP0WFzc X-Received: by 2002:a37:8b44:: with SMTP id n65mr4323346qkd.235.1615408385469; Wed, 10 Mar 2021 12:33:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBVqrwR5oHqRsKNh/jZ0aqwqXq22sWwqifzbwAKqigbCaMJ8Zv7qpTmxs6fcC5fEQMN3PE+A== X-Received: by 2002:a37:8b44:: with SMTP id n65mr4323318qkd.235.1615408385131; Wed, 10 Mar 2021 12:33:05 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 02/10] KVM: Use a big lock to replace per-kml slots_lock Date: Wed, 10 Mar 2021 15:32:53 -0500 Message-Id: <20210310203301.194842-3-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.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_H4=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Per-kml slots_lock will bring some trouble if we want to take all slots_loc= k of all the KMLs, especially when we're in a context that we could have taken s= ome of the KML slots_lock, then we even need to figure out what we've taken and what we need to take. Make this simple by merging all KML slots_lock into a single slots lock. Per-kml slots_lock isn't anything that helpful anyway - so far only x86 has= two address spaces (so, two slots_locks). All the rest archs will be having one address space always, which means there's actually one slots_lock so it wil= l be the same as before. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 32 +++++++++++++++++--------------- include/sysemu/kvm_int.h | 2 -- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index f88a52393fe..94e881f123b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -174,8 +174,10 @@ typedef struct KVMResampleFd KVMResampleFd; static QLIST_HEAD(, KVMResampleFd) kvm_resample_fd_list =3D QLIST_HEAD_INITIALIZER(kvm_resample_fd_list); =20 -#define kvm_slots_lock(kml) qemu_mutex_lock(&(kml)->slots_lock) -#define kvm_slots_unlock(kml) qemu_mutex_unlock(&(kml)->slots_lock) +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) =20 static inline void kvm_resample_fd_remove(int gsi) { @@ -241,9 +243,9 @@ bool kvm_has_free_slot(MachineState *ms) bool result; KVMMemoryListener *kml =3D &s->memory_listener; =20 - kvm_slots_lock(kml); + kvm_slots_lock(); result =3D !!kvm_get_free_slot(kml); - kvm_slots_unlock(kml); + kvm_slots_unlock(); =20 return result; } @@ -309,7 +311,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, voi= d *ram, KVMMemoryListener *kml =3D &s->memory_listener; int i, ret =3D 0; =20 - kvm_slots_lock(kml); + kvm_slots_lock(); for (i =3D 0; i < s->nr_slots; i++) { KVMSlot *mem =3D &kml->slots[i]; =20 @@ -319,7 +321,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, voi= d *ram, break; } } - kvm_slots_unlock(kml); + kvm_slots_unlock(); =20 return ret; } @@ -515,7 +517,7 @@ static int kvm_section_update_flags(KVMMemoryListener *= kml, return 0; } =20 - kvm_slots_lock(kml); + kvm_slots_lock(); =20 while (size && !ret) { slot_size =3D MIN(kvm_max_slot_size, size); @@ -531,7 +533,7 @@ static int kvm_section_update_flags(KVMMemoryListener *= kml, } =20 out: - kvm_slots_unlock(kml); + kvm_slots_unlock(); return ret; } =20 @@ -819,7 +821,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *km= l, return ret; } =20 - kvm_slots_lock(kml); + kvm_slots_lock(); =20 for (i =3D 0; i < s->nr_slots; i++) { mem =3D &kml->slots[i]; @@ -845,7 +847,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *km= l, } } =20 - kvm_slots_unlock(kml); + kvm_slots_unlock(); =20 return ret; } @@ -1150,7 +1152,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram =3D memory_region_get_ram_ptr(mr) + section->offset_within_region + (start_addr - section->offset_within_address_space); =20 - kvm_slots_lock(kml); + kvm_slots_lock(); =20 if (!add) { do { @@ -1208,7 +1210,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, } while (size); =20 out: - kvm_slots_unlock(kml); + kvm_slots_unlock(); } =20 static void kvm_region_add(MemoryListener *listener, @@ -1235,9 +1237,9 @@ static void kvm_log_sync(MemoryListener *listener, KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); int r; =20 - kvm_slots_lock(kml); + kvm_slots_lock(); r =3D kvm_physical_sync_dirty_bitmap(kml, section); - kvm_slots_unlock(kml); + kvm_slots_unlock(); if (r < 0) { abort(); } @@ -1337,7 +1339,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMem= oryListener *kml, { int i; =20 - qemu_mutex_init(&kml->slots_lock); + qemu_mutex_init(&kml_slots_lock); kml->slots =3D g_malloc0(s->nr_slots * sizeof(KVMSlot)); kml->as_id =3D as_id; =20 diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index ccb8869f01b..1da30e18841 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -27,8 +27,6 @@ typedef struct KVMSlot =20 typedef struct KVMMemoryListener { MemoryListener listener; - /* Protects the slots and all inside them */ - QemuMutex slots_lock; KVMSlot *slots; int as_id; } KVMMemoryListener; --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408538; cv=none; d=zohomail.com; s=zohoarc; b=D9isUl6NAWFIi5dG9N/hMrVar28UeD+YJ99WYYmLhiS8niYRu3W+xNeow2119A1hYNEp/SSE297a5Yt70Xfk7G0+GKuv/m34xcGAwRMyp0Khtb3f6+EKS9WaeYtZK7bDvXCL0Inm0OBX9y5u8651aVT1gjyC2okpPnuw64vEkAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408538; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nYyDNXI+29l7QpN/hyZzbO6CzINI95wpx6Vs4UISad8=; b=U/7VknkEyDJoCLlhVbsemBzBuTYoxkb1IWhI3Qvl6riZmgFVCTZK7uOGLw5u7/wCbmggHv4mak0IGb9XsksByg6rSfNd6hT8Yz6vPNGexpzx2J3R2Q8lsHE15KeIbUMU29X68yba8eKl31zmkE0HFxCBli2fSpnnoHI4lSuJiyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615408538722459.38564572247833; Wed, 10 Mar 2021 12:35:38 -0800 (PST) Received: from localhost ([::1]:40660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5YP-0007W0-Jj for importer@patchew.org; Wed, 10 Mar 2021 15:35:37 -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 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 Received: by mail-qt1-f197.google.com with SMTP id d11so13879052qth.3 for ; Wed, 10 Mar 2021 12:33:07 -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) 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= X-MC-Unique: uSOHk71wMNyg4l7Dv6sGig-1 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) 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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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) =20 +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; } =20 + kvm_slot_init_dirty_bitmap(mem); return kvm_set_user_memory_region(kml, mem, false); } =20 @@ -586,8 +589,12 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionS= ection *section, #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) =20 /* 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(KVMMemoryLis= tener *kml, goto out; } =20 - if (!mem->dirty_bmap) { - /* Allocate on the first log_sync, once and for all */ - kvm_memslot_init_dirty_bitmap(mem); - } - d.dirty_bitmap =3D mem->dirty_bmap; d.slot =3D mem->slot | (kml->as_id << 16); ret =3D kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d); @@ -1190,14 +1192,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->start_addr =3D start_addr; mem->ram =3D ram; mem->flags =3D 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 =3D kvm_set_user_memory_region(kml, mem, true); if (err) { fprintf(stderr, "%s: error registering slot: %s\n", __func__, --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408761; cv=none; d=zohomail.com; s=zohoarc; b=nDShwUlOSm0VdOiqqtYQV7h9XqT3THMLYv060gtWEuscSPgGk8gaMkGNQ8IM/zuUw6MA4HBdBhnfa5oPdA/2oLVImS2Dh9u3C5QvmzR1tQ1Q5kSMpyI9/h9fHgmsr79Cjrp6g5d87naPzNZvg+YfYgwZkF6EqOip//srGzNj7/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408761; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FYTm0Ygz3+9TFDUpsIdZ9xetLL5/rO9MVJVwiaBlDfA=; b=A1JFiBN5I3b/URNVWtQOQIGTXQqgd2A/ts4grekThbYtJXL+9lnuConuydnth7PZSL4x1piFnNVjOLaUP/sb/OOZaky30jDk/PI9nGZ/jzj8MA+dCSe7aR77ilyhmVeq+vYCtwMl/i7konBywmhxqiXorFM1X5XzJxvwU/2C/2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16154087614841017.1653137926455; Wed, 10 Mar 2021 12:39:21 -0800 (PST) Received: from localhost ([::1]:47676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5c0-0002e9-Dj for importer@patchew.org; Wed, 10 Mar 2021 15:39:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5W7-0005vi-FV for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W2-0000d2-F8 for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:15 -0500 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-D-NIIMWhNt-gNh5vB3y7mw-1; Wed, 10 Mar 2021 15:33:08 -0500 Received: by mail-qk1-f197.google.com with SMTP id k185so13700960qkb.17 for ; Wed, 10 Mar 2021 12:33:08 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408389; 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=FYTm0Ygz3+9TFDUpsIdZ9xetLL5/rO9MVJVwiaBlDfA=; b=NBrKPqjJgbC+/HUo0hfiV7oVUWFnO4poQYu8sfSL9+kvY6WJs562BBd+1VxK8GB90fKi71 GLU7n7sJn0CRDbyrNcYH5v5xoJ2utT0hOuzBGBYFEoOcJlv8NR5PGigkkEKEpLwGAamf3J MjQhkYpJ0bX/VJR4J0lSG1Yz1S1DX4Y= X-MC-Unique: D-NIIMWhNt-gNh5vB3y7mw-1 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=FYTm0Ygz3+9TFDUpsIdZ9xetLL5/rO9MVJVwiaBlDfA=; b=li3crto/0D7Y1UFTOfqQkbrycNR9jLXwXq1xmn/lEF8zpCufhHKxhzOO8ypg25a4TC QiRCWrypnW3/uS2h9mJ6894H8pBnkrfDYVc3kH7hOJ60Vjjxw6BuhfkBgHjWcQ9GddpX on2luSgYX8q8YyF8mhgSOlhTMwfcKYTdL8nUWh3dmP3AQH9aRgWCI5dbi/C6l773X3jp SGJkWcZ1D9jZ5aPoo4HDj6UXKiLLkO6iuBjS9HoPxUsWiBSMvcZqfBix3jSJL958C647 +Haj3sTSp4/VD1EKImR42DuMlemFqPcCtLJLPow15HUXjdm57XlULJ/xRAJKoy8XWwoQ 0gNA== X-Gm-Message-State: AOAM530o3GI+xHJVRl77BNeo1d8gt0cBGSrTo0R44lfBEgieXj7c/4jg jrltKgkKtAAAf/Yf4i8/7JQ7Fqg7pzLfrwUandzvIfDI7RRWlw82K/s0+wqQtqVLyJflMNCBMTZ EKoDc4p8c+IO90BHJv/0+x+MVg70oUyO/Ui5MZVCENqdN0ZOVuP1o+vLeXlZmQ/0T X-Received: by 2002:ac8:cc5:: with SMTP id o5mr4609603qti.0.1615408387764; Wed, 10 Mar 2021 12:33:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZsKyFq64L2fGAfQP0hq3M08rN5MaSCE18JJ89rNQMd3wvrLBASjrUodU48X1fWFyj4drs4A== X-Received: by 2002:ac8:cc5:: with SMTP id o5mr4609585qti.0.1615408387448; Wed, 10 Mar 2021 12:33:07 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 04/10] KVM: Provide helper to get kvm dirty log Date: Wed, 10 Mar 2021 15:32:55 -0500 Message-Id: <20210310203301.194842-5-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.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_H4=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Provide a helper kvm_slot_get_dirty_log() to make the function kvm_physical_sync_dirty_bitmap() clearer. We can even cache the as_id into KVMSlot when it is created, so that we don't even need to pass it down every time. Since at it, remove return value of kvm_physical_sync_dirty_bitmap() because it should never fail. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 52 +++++++++++++++++++++++----------------- include/sysemu/kvm_int.h | 2 ++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index fa337418636..853dfb076bd 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -617,6 +617,30 @@ static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) mem->dirty_bmap =3D g_malloc0(bitmap_size); } =20 +/* + * Sync dirty bitmap from kernel to KVMSlot.dirty_bmap, return true if + * succeeded, false otherwise + */ +static bool kvm_slot_get_dirty_log(KVMState *s, KVMSlot *slot) +{ + struct kvm_dirty_log d =3D {}; + int ret; + + d.dirty_bitmap =3D slot->dirty_bmap; + d.slot =3D slot->slot | (slot->as_id << 16); + ret =3D kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d); + + if (ret =3D=3D -ENOENT) { + /* kernel does not have dirty bitmap in this slot */ + ret =3D 0; + } + if (ret) { + error_report_once("%s: KVM_GET_DIRTY_LOG failed with %d", + __func__, ret); + } + return ret =3D=3D 0; +} + /** * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * @@ -628,15 +652,13 @@ static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) * @kml: the KVM memory listener object * @section: the memory section to sync the dirty bitmap with */ -static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, - MemoryRegionSection *section) +static void kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, + MemoryRegionSection *section) { KVMState *s =3D kvm_state; - struct kvm_dirty_log d =3D {}; KVMSlot *mem; hwaddr start_addr, size; hwaddr slot_size, slot_offset =3D 0; - int ret =3D 0; =20 size =3D kvm_align_section(section, &start_addr); while (size) { @@ -646,19 +668,10 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryLi= stener *kml, mem =3D kvm_lookup_matching_slot(kml, start_addr, slot_size); if (!mem) { /* We don't have a slot if we want to trap every access. */ - goto out; + return; } =20 - d.dirty_bitmap =3D mem->dirty_bmap; - d.slot =3D mem->slot | (kml->as_id << 16); - ret =3D kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d); - if (ret =3D=3D -ENOENT) { - /* kernel does not have dirty bitmap in this slot */ - ret =3D 0; - } else if (ret < 0) { - error_report("ioctl KVM_GET_DIRTY_LOG failed: %d", errno); - goto out; - } else { + if (kvm_slot_get_dirty_log(s, mem)) { subsection.offset_within_region +=3D slot_offset; subsection.size =3D int128_make64(slot_size); kvm_get_dirty_pages_log_range(&subsection, d.dirty_bitmap); @@ -668,8 +681,6 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryList= ener *kml, start_addr +=3D slot_size; size -=3D slot_size; } -out: - return ret; } =20 /* Alignment requirement for KVM_CLEAR_DIRTY_LOG - 64 pages */ @@ -1188,6 +1199,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, do { slot_size =3D MIN(kvm_max_slot_size, size); mem =3D kvm_alloc_slot(kml); + mem->as_id =3D kml->as_id; mem->memory_size =3D slot_size; mem->start_addr =3D start_addr; mem->ram =3D ram; @@ -1230,14 +1242,10 @@ static void kvm_log_sync(MemoryListener *listener, MemoryRegionSection *section) { KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); - int r; =20 kvm_slots_lock(); - r =3D kvm_physical_sync_dirty_bitmap(kml, section); + kvm_physical_sync_dirty_bitmap(kml, section); kvm_slots_unlock(); - if (r < 0) { - abort(); - } } =20 static void kvm_log_clear(MemoryListener *listener, diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 1da30e18841..e13075f738a 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -23,6 +23,8 @@ typedef struct KVMSlot int old_flags; /* Dirty bitmap cache for the slot */ unsigned long *dirty_bmap; + /* Cache of the address space ID */ + int as_id; } KVMSlot; =20 typedef struct KVMMemoryListener { --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408919; cv=none; d=zohomail.com; s=zohoarc; b=Mp163Pw0Lv04hdIkDXnGoDieZLk241dSru8hB/QYbB+JKBHcbilvDUHIeELSRLlgcUCpawNBs0oDyFEW75LoSQnBozVHwhRp/MYAjixgi6I9qfABxRQnNf3+76mh624v+ZsCQLIvmT/cWMG6g+lMxgv8u68t8WkEn69UHV1Ct38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408919; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WqvzdIPMNuAzIXhcxKTb8y+ZMqe5riHFG+8d1gboz4c=; b=n8bI3F0xVOeug9MkbF3fVaKrDsQrfHRC9XGDdvY/UsqlkHc7n6gP3JNIKJn7opwusL+MgYfBnyAcRcVNNXx9vKYRkQ7sPz3V2k0qKlipsrZnHX+P13T+6P4LAbA5E+UKK+EsVgmv5m5a7VNMUiha9e0yDKRL4xwN1k47TGraWhQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615408919199574.8655185817438; Wed, 10 Mar 2021 12:41:59 -0800 (PST) Received: from localhost ([::1]:54626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5eY-000638-5w for importer@patchew.org; Wed, 10 Mar 2021 15:41:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5W9-0005wp-M8 for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W4-0000dC-Jj for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:17 -0500 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-5wnWInEgMeSsPLi2-EDpmg-1; Wed, 10 Mar 2021 15:33:09 -0500 Received: by mail-qk1-f198.google.com with SMTP id h20so13760007qkj.18 for ; Wed, 10 Mar 2021 12:33:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408391; 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=WqvzdIPMNuAzIXhcxKTb8y+ZMqe5riHFG+8d1gboz4c=; b=JZQa3D3fML0bcOrxZtJCrn/MlFlgp8gzAWe/w5Dc1Wob7uDaI4jff6MepY3im2g2CVGy6W N0+f5esArgFzKEy3utk/dsKpn1HcvY3ggt3aa9cY1Xl+1bqOEFXamFTZpE5f6wE6qHNWQy Pzmb9tG4SVZ/6wYrs4PxFOOwkJcejoY= X-MC-Unique: 5wnWInEgMeSsPLi2-EDpmg-1 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=WqvzdIPMNuAzIXhcxKTb8y+ZMqe5riHFG+8d1gboz4c=; b=nIgJV5b002GH3uNLXpB4ubr2sABbnvjUkR//p838+COob15XYcYtW8YsRM5UuvdOgw r+O48g2cmTje6Y9mYx2xbG+Cgez5BbVlKGwENbBqszuhDO+9gyRoUKMwSxW/jDn1VRA4 JBActJ3LWhN9SFPCwGbXmUF44u5nYz8V/OkqmGEz/KpT6ID/+moGX4leFZ0bI6Tc9wn4 QH0jfOFETo/4mm4exmfUgAvIld301L4NMjHW282nt5all/aO6eXbp0cPxGs7apBIUa6i XrLW/dEtUtuAWeL9v3O6XbPp/M+HpsvV6RolI2Jp82zf/rFGDGBmP9muuJ6vqpkOax0w dqRw== X-Gm-Message-State: AOAM5334dt80ihd2w9uNh8ZpQLCC1FFvGuSLrjnftvhnZuq96qfqnydU 2axluVUITbQzSQa/tSMJvJtf7fb5rEQZPXH7gD/TdG1DjEgB2zFDYQG1rXrAAi+ltYLGm5h/rpR vDvd6+08kjKOZgoPiWu/VwGN5MO4esvOzI7T0Opuwjl7uSLPWLPO65cMnrIsAiMoZ X-Received: by 2002:ac8:588a:: with SMTP id t10mr4512413qta.32.1615408388928; Wed, 10 Mar 2021 12:33:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOF91aI42unVNVxQFa4GYHgom7mfYC/e6Ml92nFAX3JhCveze7/ij9cH0pJAp/18pc2rEgFw== X-Received: by 2002:ac8:588a:: with SMTP id t10mr4512383qta.32.1615408388608; Wed, 10 Mar 2021 12:33:08 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 05/10] KVM: Provide helper to sync dirty bitmap from slot to ramblock Date: Wed, 10 Mar 2021 15:32:56 -0500 Message-Id: <20210310203301.194842-6-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.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_H4=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" kvm_physical_sync_dirty_bitmap() calculates the ramblock offset in an awkward way from the MemoryRegionSection that passed in from the caller. The truth is for each KVMSlot the ramblock offset never change for the lifecycle. Cache the ramblock offset for each KVMSlot into the structure when the KVMSlot is created. With that, we can further simplify kvm_physical_sync_dirty_bitmap() with a helper to sync KVMSlot dirty bitmap to the ramblock dirty bitmap of a specific KVMSlot. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 37 +++++++++++++++++-------------------- include/sysemu/kvm_int.h | 2 ++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 853dfb076bd..65dc00b0a61 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -575,15 +575,12 @@ static void kvm_log_stop(MemoryListener *listener, } =20 /* get kvm's dirty pages bitmap and update qemu's */ -static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, - unsigned long *bitmap) +static void kvm_slot_sync_dirty_pages(KVMSlot *slot) { - ram_addr_t start =3D section->offset_within_region + - memory_region_get_ram_addr(section->mr); - ram_addr_t pages =3D int128_get64(section->size) / qemu_real_host_page= _size; + ram_addr_t start =3D slot->ram_start_offset; + ram_addr_t pages =3D slot->memory_size / qemu_real_host_page_size; =20 - cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages); - return 0; + cpu_physical_memory_set_dirty_lebitmap(slot->dirty_bmap, start, pages); } =20 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) @@ -658,26 +655,19 @@ static void kvm_physical_sync_dirty_bitmap(KVMMemoryL= istener *kml, KVMState *s =3D kvm_state; KVMSlot *mem; hwaddr start_addr, size; - hwaddr slot_size, slot_offset =3D 0; + hwaddr slot_size; =20 size =3D kvm_align_section(section, &start_addr); while (size) { - MemoryRegionSection subsection =3D *section; - slot_size =3D MIN(kvm_max_slot_size, size); mem =3D kvm_lookup_matching_slot(kml, start_addr, slot_size); if (!mem) { /* We don't have a slot if we want to trap every access. */ return; } - if (kvm_slot_get_dirty_log(s, mem)) { - subsection.offset_within_region +=3D slot_offset; - subsection.size =3D int128_make64(slot_size); - kvm_get_dirty_pages_log_range(&subsection, d.dirty_bitmap); + kvm_slot_sync_dirty_pages(mem); } - - slot_offset +=3D slot_size; start_addr +=3D slot_size; size -=3D slot_size; } @@ -1143,7 +1133,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, int err; MemoryRegion *mr =3D section->mr; bool writeable =3D !mr->readonly && !mr->rom_device; - hwaddr start_addr, size, slot_size; + hwaddr start_addr, size, slot_size, mr_offset; + ram_addr_t ram_start_offset; void *ram; =20 if (!memory_region_is_ram(mr)) { @@ -1161,9 +1152,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, return; } =20 - /* use aligned delta to align the ram address */ - ram =3D memory_region_get_ram_ptr(mr) + section->offset_within_region + - (start_addr - section->offset_within_address_space); + /* The offset of the kvmslot within the memory region */ + mr_offset =3D section->offset_within_region + start_addr - + section->offset_within_address_space; + + /* use aligned delta to align the ram address and offset */ + ram =3D memory_region_get_ram_ptr(mr) + mr_offset; + ram_start_offset =3D memory_region_get_ram_addr(mr) + mr_offset; =20 kvm_slots_lock(); =20 @@ -1202,6 +1197,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->as_id =3D kml->as_id; mem->memory_size =3D slot_size; mem->start_addr =3D start_addr; + mem->ram_start_offset =3D ram_start_offset; mem->ram =3D ram; mem->flags =3D kvm_mem_flags(mr); kvm_slot_init_dirty_bitmap(mem); @@ -1212,6 +1208,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, abort(); } start_addr +=3D slot_size; + ram_start_offset +=3D slot_size; ram +=3D slot_size; size -=3D slot_size; } while (size); diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index e13075f738a..ab09a150e19 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -25,6 +25,8 @@ typedef struct KVMSlot unsigned long *dirty_bmap; /* Cache of the address space ID */ int as_id; + /* Cache of the offset in ram address space */ + ram_addr_t ram_start_offset; } KVMSlot; =20 typedef struct KVMMemoryListener { --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408883; cv=none; d=zohomail.com; s=zohoarc; b=l3aPXB2DX1aFNjdWmlMnt5pNdjpw0crVI4bNvPsz/huwynXYoQRDFlU/Owrc6Efk0z3CSUBzNRB+9Yn8e5WL1a95P/n1HvO0M8oZyHAQ2EGPzTyGIDTSD9X0yod8km/N1ZMjolKrXDH7QYu6KDefjQdYrZ4sukV97FPR7q+6+kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408883; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rc8/S0CxImyM7JcvYL6r6zrwC2hxrA9qeeZBCUuAeK0=; b=MEfztQj4RkR4hyeKYyLaV4eLDWsOZ6e3aLqfa0owqApGeyUdDyE75K/1HiTN5+JzXsEG0e693sFaebQVLKrT1LP4nBGNPTcppv4kjcgEcMNQLKRTLo5f7b2CaFwy38BY1d+iIrz/bTEiIlE1eYF0RHeEFXJSH0NnFfKCiwswY4s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161540888355957.82678971498899; Wed, 10 Mar 2021 12:41:23 -0800 (PST) Received: from localhost ([::1]:53678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5dy-0005cR-Am for importer@patchew.org; Wed, 10 Mar 2021 15:41:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5WD-00060g-Dn for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49138) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W6-0000eI-9J for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:21 -0500 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-250-Tk0WQsF2OeyBc0haIW7OeA-1; Wed, 10 Mar 2021 15:33:11 -0500 Received: by mail-qv1-f71.google.com with SMTP id j3so13625069qvo.1 for ; Wed, 10 Mar 2021 12:33:11 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408393; 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=rc8/S0CxImyM7JcvYL6r6zrwC2hxrA9qeeZBCUuAeK0=; b=Zx+jALfn/YL0Qa0pZbd/qFg0cF5WHLeFKBOXTOPQoBpqrmecV/CVKhTIZqMrJw9TrPQF7t M85w9+WUWdY0/4PYWqtJObB5byA00UY7fEmYAP+da8tsohIXOMISNesU49uaaMcI8MBB2V ucHP/SXAcnDU7Ejyam5qWTDDPNixwV8= X-MC-Unique: Tk0WQsF2OeyBc0haIW7OeA-1 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=rc8/S0CxImyM7JcvYL6r6zrwC2hxrA9qeeZBCUuAeK0=; b=DyXR57PUmM5QvpVbpT8ZQOUH8YyZP7S3rOtiCc7PtGgwShdeouVhi2l3kCeBQPzbrB 6frK1APxpyMRqz/QqbWwO6HqavAbjQ3eEbAUtm00WilaFxcB9227QJuSp6JlVuQNiviE kk2wLla46nq2zQlAiTYIkjX6NOM55HzFm5nkY+QTaUQxBwVWjCVk8ADSgl1Y5hCcs2wB pqqyszExY57hK3KZUEOG9NvkMPCNVrzMhrV+annHrsUbKpCbmIb6TLEmHVcE0Y+5cAvh Xb8kN9ZBDzF1/I5meevhm2FEI5V6rHV0DDvPMktQrU53Z07eC8f3OdlBOM3Kf0qlQMJ8 zuHA== X-Gm-Message-State: AOAM531PhqoHmH4UDMpHpyAyNhLO6AzlLLzEOhxhjUzf30wCUABkVTJi x/0zAsyaJsjYzuSYXXJ3PNK4Zn4ICkQ6VyfXTpBzwwbrs1x/wt39yOVpfg0haw/7dOQWF69juHi ntAJh6Tz11Xpcpr2/R9ueIj5JPKQ/23l47tIl0gLkCfqRUe2kzpOun1qELgDVv8NU X-Received: by 2002:ac8:4783:: with SMTP id k3mr4531830qtq.231.1615408390378; Wed, 10 Mar 2021 12:33:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzr/jt3kfH0jZgvaUpSMwGBYeTAg+qb+Rgwme0L2RMp5KkPViMfDBu8b571u34SvFsUiC/sUA== X-Received: by 2002:ac8:4783:: with SMTP id k3mr4531802qtq.231.1615408390050; Wed, 10 Mar 2021 12:33:10 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 06/10] KVM: Simplify dirty log sync in kvm_set_phys_mem Date: Wed, 10 Mar 2021 15:32:57 -0500 Message-Id: <20210310203301.194842-7-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.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_H4=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" kvm_physical_sync_dirty_bitmap() on the whole section is inaccurate, because the section can be a superset of the memslot that we're working on. The re= sult is that if the section covers multiple kvm memslots, we could be doing the synchronization for multiple times for each kvmslot in the section. With the two helpers that we just introduced, it's very easy to do it right= now by calling the helpers. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 65dc00b0a61..20f852a990b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1170,7 +1170,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, goto out; } if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { - kvm_physical_sync_dirty_bitmap(kml, section); + kvm_slot_get_dirty_log(kvm_state, mem); + kvm_slot_sync_dirty_pages(mem); } =20 /* unregister the slot */ --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615409258; cv=none; d=zohomail.com; s=zohoarc; b=Su5Y7bxOUOWkNBIhstleTmHBc6AgZlh1uAKS8EDgEDSXqRXMkNbegqPuBrP/1GVrfr9btYc9ua8GOrzhATNiy/xOosJ3iUMQIKEJkLgVeFohhfiSYT7DbeaDJ1Fq5IcU1WFH7fBZXqh4F+tJPQnwxpLB/RHCQp6jMuJwoA2NpOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615409258; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FoLec6+xKQz6+kZzNSNrg7nWUFgwlkYHzUSpPyi8uF8=; b=Jz+BEYNkCVxraY+JhldNtJAOq1q41+nhB5EsjpHu2vxh18qblj5zNzufi5Rmheie9xW7xe9eq7AvWXj4Njhslev/3jEn4DRsBVmFKUkh6jsPUOORKHIjoWG4TXjBsV8ut7xFssg7mMvRAMZft0pYeUqEOxhTDd/lgZ+/arpTJOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615409258128998.174821308989; Wed, 10 Mar 2021 12:47:38 -0800 (PST) Received: from localhost ([::1]:38672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5k1-0005IO-55 for importer@patchew.org; Wed, 10 Mar 2021 15:47:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5WH-00068m-2d for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5WF-0000jd-EX for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:24 -0500 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-PDDei4lgNzSGk1j_9DTomg-1; Wed, 10 Mar 2021 15:33:12 -0500 Received: by mail-qk1-f199.google.com with SMTP id h134so13789991qke.1 for ; Wed, 10 Mar 2021 12:33:12 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408402; 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=FoLec6+xKQz6+kZzNSNrg7nWUFgwlkYHzUSpPyi8uF8=; b=VMA1aDCxmFoXI7fM51STwB1weQd5/Z8PGR3uBLvJf064yKK5fIj7vVj1zLwZ+QZ1KsLH2p uvW1XGNTPZvoYPARY3GqUauEqDX36m94llQbz9jH608tru6PV/dsea+LBWYCIHo+5zyfWg 5Err5traocbgRBaFVp92CKHYzcghx70= X-MC-Unique: PDDei4lgNzSGk1j_9DTomg-1 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=FoLec6+xKQz6+kZzNSNrg7nWUFgwlkYHzUSpPyi8uF8=; b=K+5HMzQxgBhuwk4HTuSEzPwmIx0Toz/StDEV9WiYU0Wgh1YELfYjDuCdVVpePpMMAJ QoXgysmYl4DocS7gQTgrKzZmbi106Y0182PV0cp+w59oCn0eBGT+Tghb/GQl/bqdEWZz wTIMVgAAeFwWQKXSEB+PMCgXqv7QVaTPxN2wehQs4lMQfpZQxAa8HJlAUUlNpUMtcvSm Dz5Jxy2TruWhSw8azF1/BHTxFf6guXtdaXf6UPDvGY+mO+Cb8PDuJV95/ofQRblviPib M1A8JYlwrs38B8/oA8lRvnamY+z35sGVIhRJEexfAQgxu+HxdHkL9dBxCtbNuCtT2eYb WzYQ== X-Gm-Message-State: AOAM532sTrZTzKsK5D8p9X+AjOUx5BzZTNDLa7w8Y+SJv3AQp4a48pPE cUTRMCTCLuwotYNWXxnw5qQk+fV6ie55zivpCJZaby4Y1KhSABPbc1a/P3GO5kXdOi44HDNbXbt 84ZAYUP5DB0M3BJbtWnvrKvaHzNKkMKFxjjZ1wX+zw9vXNwY8Ge5vaaHWBIbfLN0n X-Received: by 2002:a05:620a:914:: with SMTP id v20mr4629036qkv.140.1615408391365; Wed, 10 Mar 2021 12:33:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgAqrOgEZzkj6ZjV9TWgdWMbvdSqrR0M3RECr1xOJVFWMXsoUYdS4SII97+3q/Cee9L955Eg== X-Received: by 2002:a05:620a:914:: with SMTP id v20mr4629007qkv.140.1615408391070; Wed, 10 Mar 2021 12:33:11 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 07/10] KVM: Cache kvm slot dirty bitmap size Date: Wed, 10 Mar 2021 15:32:58 -0500 Message-Id: <20210310203301.194842-8-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Cache it too because we'll reference it more frequently in the future. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 1 + include/sysemu/kvm_int.h | 1 + 2 files changed, 2 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 20f852a990b..a1e7b1332a1 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -612,6 +612,7 @@ static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) hwaddr bitmap_size =3D ALIGN(mem->memory_size / qemu_real_host_page_si= ze, /*HOST_LONG_BITS*/ 64) / 8; mem->dirty_bmap =3D g_malloc0(bitmap_size); + mem->dirty_bmap_size =3D bitmap_size; } =20 /* diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index ab09a150e19..c788452cd96 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -23,6 +23,7 @@ typedef struct KVMSlot int old_flags; /* Dirty bitmap cache for the slot */ unsigned long *dirty_bmap; + unsigned long dirty_bmap_size; /* Cache of the address space ID */ int as_id; /* Cache of the offset in ram address space */ --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615408846; cv=none; d=zohomail.com; s=zohoarc; b=YdAZ/YlKTo9GmE3a5KE+N8gL2RmiQokIPphzkp7c7sYCwxRvTpSjUJXEC87EIMd/OflakSdHiP+PhshekGsJAaSAo2Qwo0xlS4unJ0QX/XZqGESk2W7h2GdEVIyGCvbLBCTKmdxraqieNYvMW1mnq76zQboVRvXu+5CZMYH1lLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615408846; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KIrk7YST/OerGKiVr8D/f35rg2J/3wCy+F9CoZg4Yx0=; b=ZActathhbP9OoInCnayoFW3SCGsiprEB4FQhjMACgy80E1MB60G712vH91ro3H56lpGhNQqhy1D5Q03bSoXI0jR6z8cVF5GPcPzx4iDYOlVgaATrj/yEus+2fxNwO933BgGv4mAHzaNcUAKePmNifFPvbDtJKdcNy11JL9CUDmc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16154088462111016.4237903145107; Wed, 10 Mar 2021 12:40:46 -0800 (PST) Received: from localhost ([::1]:52194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5dM-0004kD-O6 for importer@patchew.org; Wed, 10 Mar 2021 15:40:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5WA-0005yZ-SN for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W8-0000fn-6b for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:18 -0500 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-zM-cWhMSNZOHt6Vb_WYftA-1; Wed, 10 Mar 2021 15:33:14 -0500 Received: by mail-qv1-f71.google.com with SMTP id bt20so4685327qvb.0 for ; Wed, 10 Mar 2021 12:33:14 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408395; 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=KIrk7YST/OerGKiVr8D/f35rg2J/3wCy+F9CoZg4Yx0=; b=VP0hy5bOfhkITmecyN8aEVB7qNxp/0tVBT43dHddciZXm3V4b5y7FoWN/yp/2UxFqZwGKE Hf9+G5T1pWmJpnvL0aToCrBw2okR1u47TmtVomW0xTP8Op6Chb1imV0mPo53ARbvJdjIlT p9PJWI9EXbva3C1nXIzDzN8hiGeio+k= X-MC-Unique: zM-cWhMSNZOHt6Vb_WYftA-1 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=KIrk7YST/OerGKiVr8D/f35rg2J/3wCy+F9CoZg4Yx0=; b=gYqwYT4m2ivdREG0PWM0k+FazJbJXDPaHNMK+FX3+Sqogo7ehFl7KNl0HyeEs0JkLO 3sluQ/IUix0aBabuIE22303tHLSSHG7IfjbcdhEccNY1MFQCSi9j5CCOzaD/6xfTYPun Lt4qvVjRtr0+PWSxrnneB62v5XLNk4rjDfLJYT78JeGF2lS4U7o7LYACmWzriHoZwPcp 6iSVcDXv1R2UaD9/RaAXVSl8NqjSgTaRY0li6mloYYj7gBmcdsCzvvbBcdB7sh146S48 1llqUPjeiEJg2cCyFDA3mV4z31N90ygVJMFHijFYJ6OD7oawMJxXRqZzapMQ44rImp/x ntAg== X-Gm-Message-State: AOAM532hh1Dmu/blggRySryEK3tnwjtTrH9ZFOVa+/uhGQOWM+hc6NNv CRdHCcWxytDhVYLKSy+EtU6Qld2LpwTN2aOZzIcVB69cvY3htMuU69Sndp5CBo6IgAm4b1+eFbV b5fpCMYkPkIP1/1/YOlNiCI081CYKBGq3frki1VSV8XBO8bVTE2cS0Smdyj/wFh1z X-Received: by 2002:a37:a9cf:: with SMTP id s198mr4337643qke.143.1615408392899; Wed, 10 Mar 2021 12:33:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUax1DDG5wtxEpWhatITs/OD8Dt8NoXwrS/r2/G8q0EtTqVhftK+swU8cYRic+31w/GBz/KA== X-Received: by 2002:a37:a9cf:: with SMTP id s198mr4337606qke.143.1615408392501; Wed, 10 Mar 2021 12:33:12 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 08/10] KVM: Add dirty-gfn-count property Date: Wed, 10 Mar 2021 15:32:59 -0500 Message-Id: <20210310203301.194842-9-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a parameter for dirty gfn count for dirty rings. If zero, dirty ring is disabled. Otherwise dirty ring will be enabled with the per-vcpu gfn count= as specified. If dirty ring cannot be enabled due to unsupported kernel or illegal parameter, it'll fallback to dirty logging. By default, dirty ring is not enabled (dirty-gfn-count default to 0). Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 12 ++++++++ 2 files changed, 84 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index a1e7b1332a1..10137b6af11 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -128,6 +128,9 @@ struct KVMState KVMMemoryListener *ml; AddressSpace *as; } *as; + bool kvm_dirty_ring_enabled; /* Whether KVM dirty ring is enabled */ + uint64_t kvm_dirty_ring_size; /* Size of the per-vcpu dirty ring */ + uint32_t kvm_dirty_gfn_count; /* Number of dirty GFNs per ring */ }; =20 KVMState *kvm_state; @@ -2136,6 +2139,40 @@ static int kvm_init(MachineState *ms) s->coalesced_pio =3D s->coalesced_mmio && kvm_check_extension(s, KVM_CAP_COALESCED_PIO); =20 + /* + * Enable KVM dirty ring if supported, otherwise fall back to + * dirty logging mode + */ + if (s->kvm_dirty_gfn_count > 0) { + uint64_t ring_size; + + ring_size =3D s->kvm_dirty_gfn_count * sizeof(struct kvm_dirty_gfn= ); + + /* Read the max supported pages */ + ret =3D kvm_vm_check_extension(s, KVM_CAP_DIRTY_LOG_RING); + if (ret > 0) { + if (ring_size > ret) { + error_report("KVM dirty GFN count %" PRIu32 " too big " + "(maximum is %ld). Please use a smaller valu= e.", + s->kvm_dirty_gfn_count, + ret / sizeof(struct kvm_dirty_gfn)); + ret =3D -EINVAL; + goto err; + } + + ret =3D kvm_vm_enable_cap(s, KVM_CAP_DIRTY_LOG_RING, 0, ring_s= ize); + if (ret) { + error_report("Enabling of KVM dirty ring failed: %d. " + "Suggested mininum value is 1024. " + "Please also make sure it's a power of two.",= ret); + goto err; + } + + s->kvm_dirty_ring_size =3D ring_size; + s->kvm_dirty_ring_enabled =3D true; + } + } + dirty_log_manual_caps =3D kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); dirty_log_manual_caps &=3D (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | @@ -3179,6 +3216,33 @@ bool kvm_kernel_irqchip_split(void) return kvm_state->kernel_irqchip_split =3D=3D ON_OFF_AUTO_ON; } =20 +static void kvm_get_dirty_gfn_count(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s =3D KVM_STATE(obj); + uint32_t value =3D s->kvm_dirty_gfn_count; + + visit_type_uint32(v, name, &value, errp); +} + +static void kvm_set_dirty_gfn_count(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s =3D KVM_STATE(obj); + Error *error =3D NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->kvm_dirty_gfn_count =3D value; +} + static void kvm_accel_instance_init(Object *obj) { KVMState *s =3D KVM_STATE(obj); @@ -3186,6 +3250,8 @@ static void kvm_accel_instance_init(Object *obj) s->kvm_shadow_mem =3D -1; s->kernel_irqchip_allowed =3D true; s->kernel_irqchip_split =3D ON_OFF_AUTO_AUTO; + /* KVM dirty ring is by default off */ + s->kvm_dirty_gfn_count =3D 0; } =20 static void kvm_accel_class_init(ObjectClass *oc, void *data) @@ -3207,6 +3273,12 @@ static void kvm_accel_class_init(ObjectClass *oc, vo= id *data) NULL, NULL); object_class_property_set_description(oc, "kvm-shadow-mem", "KVM shadow MMU size"); + + object_class_property_add(oc, "dirty-gfn-count", "uint32", + kvm_get_dirty_gfn_count, kvm_set_dirty_gfn_count, + NULL, NULL); + object_class_property_set_description(oc, "dirty-gfn-count", + "KVM dirty GFN count (=3D0 to disable dirty ring)"); } =20 static const TypeInfo kvm_accel_type =3D { diff --git a/qemu-options.hx b/qemu-options.hx index 90801286c6e..08becce4ad0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -141,6 +141,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, " kvm-shadow-mem=3Dsize of KVM shadow MMU in bytes\n" " split-wx=3Don|off (enable TCG split w^x mapping)\n" " tb-size=3Dn (TCG translation block cache size)\n" + " dirty-gfn-count=3Dn (KVM dirty ring GFN count, defaul= t 0)\n" " thread=3Dsingle|multi (enable multi-threaded TCG)\n",= QEMU_ARCH_ALL) SRST ``-accel name[,prop=3Dvalue[,...]]`` @@ -181,6 +182,17 @@ SRST where both the back-end and front-ends support it and no incompatible TCG features have been enabled (e.g. icount/replay). + + ``dirty-gfn-count=3Dn`` + When KVM accelerator is used, it controls the per-vcpu KVM dirty r= ing + size (number of entries one dirty ring contains, per-vcpu). It sho= uld + be a value that is power of two, and it should be 1024 or bigger (= but + still less than the maximum value that the kernel supports). 4096 + could be a good initial value if you have no idea which is the bes= t. + Set this value to 0 to disable the feature. By default, this feat= ure + is disabled (dirty-gfn-count=3D0). When enabled, it'll automatica= lly + replace the kvm get dirty log feature. + ERST =20 DEF("smp", HAS_ARG, QEMU_OPTION_smp, --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615409257; cv=none; d=zohomail.com; s=zohoarc; b=kMxI8QoVwIvxNCy6jV+mw8H0vV5J7TS6Ynjdfr6kscRfjWPd0ONpepLZ+qkx5bnkHvEYD0N/2G6N/cF14MdRxuZJVi5Vithn4avLqvKypySprVFtyjMbpUS7ftXVYYmtOORjF9ItNyyPLZjAD+RSnjM7WTFvp14fGF7Fca8pN1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615409257; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O+AomLI9wrG5xhM1xQmZ+/NRUp82zimm1r3k6Rcg5v0=; b=Km6e6yx+lqTkDSzS7NnISuLjM4DIvYwzzWBBkI27AkZGDxPoMBkO+oB64IFPjDs4GpxAN9C4bY4nIM7VdvO2rjZ255cGfnRbA35Lpm3F5JGhC6Me+IAbGGa4JkGEl3hqihqNI4KO8BBoDuAi14YMyofHotATdMTDMsJ9QbKGv1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615409257002273.3325366932095; Wed, 10 Mar 2021 12:47:37 -0800 (PST) Received: from localhost ([::1]:38530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5jz-0005EE-Rs for importer@patchew.org; Wed, 10 Mar 2021 15:47:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5WC-000604-JJ for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5W9-0000ga-Cb for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:20 -0500 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-4mMdSS7LOxaVQtMAmeG-ug-1; Wed, 10 Mar 2021 15:33:15 -0500 Received: by mail-qv1-f69.google.com with SMTP id da16so13597839qvb.2 for ; Wed, 10 Mar 2021 12:33:15 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408396; 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=O+AomLI9wrG5xhM1xQmZ+/NRUp82zimm1r3k6Rcg5v0=; b=KGXA5xaRxYYXIUP4z4xYmexGZVBb8dbOmBc3tTMmnbxGILs1wih8fk53T0DZwx8zQSLeqW Gmr5G3T6e2FuG4mWf/iQz0h5O6H5EGZXyj8Uk0/AuG9ZnHa3WTO1kqRNWnjDSaHfs2P267 207Q+VojcqlDqik0T/B1h2GkqpIoduo= X-MC-Unique: 4mMdSS7LOxaVQtMAmeG-ug-1 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=O+AomLI9wrG5xhM1xQmZ+/NRUp82zimm1r3k6Rcg5v0=; b=MkK23KRBR/SIVtX3bdYNxQRYXqxmjI/FPaE2fQfPAWgEZL7Oeobjb6SWlwaWh7GcFb 0MiPDvQAsGRBRnkZIO/xyMp8cjO4Z9PtgE1Xwu1YdLwCiAOdoLMAZwQYpt8wjR6wvvIf Y1vzvjGZPzuk8popQWFPHbHRBtlouHfJwi5Sd9fKxPKzsagHYQqiyp8uGtR6HD6OwmIO AzsCJX4AdlSO947Jbdw7+VCRbN+A5eSD7NvxoV/oNUUsCGGxiJboh5BPHxEO6xxIzQyF 2hEmZCaYESXIsL529eTNhDteb1cb7J0n3n4tKiMGG2hcZLosSCHl93Hk9MlPnV18CP4l nPPA== X-Gm-Message-State: AOAM532AxvUWeDrn9Y4dn9qDi4DpzYdqnvmY+r+vIPc9i196LW7Vtb9i T6xM/O547CoH2i9bEuaJKIMLDJlk6+c73bKepqYhSqBE75s9jxbS9CXgc1lNOSYWxQ2h0bs1hpz sEOvonoRRh9+KpFspZhs2yhyZYatZDTQB69qFhrlo6n/vH6P4M5sYe1UXWsCkY/Eu X-Received: by 2002:a05:620a:16b9:: with SMTP id s25mr4390205qkj.500.1615408394445; Wed, 10 Mar 2021 12:33:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJz87UpWZXa71qQfE6+9PWke738LMs2yURI+AFAFujWokvcUMdkiNvzsLvHb060UoSBlFkSunA== X-Received: by 2002:a05:620a:16b9:: with SMTP id s25mr4390183qkj.500.1615408394132; Wed, 10 Mar 2021 12:33:14 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 09/10] KVM: Disable manual dirty log when dirty ring enabled Date: Wed, 10 Mar 2021 15:33:00 -0500 Message-Id: <20210310203301.194842-10-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is for KVM_CLEAR_DIRTY_LOG, which is only useful for KVM_GET_DIRTY_LOG. Skip enabling it for kvm dirty ring. More importantly, KVM_DIRTY_LOG_INITIALLY_SET will not wr-protect all the p= ages initially, which is against how kvm dirty ring is used - there's no way for= kvm dirty ring to re-protect a page before it's notified as being written first with a GFN entry in the ring! So when KVM_DIRTY_LOG_INITIALLY_SET is enabl= ed with dirty ring, we'll see silent data loss after migration. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 10137b6af11..ae9393266b2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2173,20 +2173,29 @@ static int kvm_init(MachineState *ms) } } =20 - dirty_log_manual_caps =3D - kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); - dirty_log_manual_caps &=3D (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | - KVM_DIRTY_LOG_INITIALLY_SET); - s->manual_dirty_log_protect =3D dirty_log_manual_caps; - if (dirty_log_manual_caps) { - ret =3D kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2, 0, - dirty_log_manual_caps); - if (ret) { - warn_report("Trying to enable capability %"PRIu64" of " - "KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 but failed. " - "Falling back to the legacy mode. ", - dirty_log_manual_caps); - s->manual_dirty_log_protect =3D 0; + /* + * KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is not needed when dirty ring is + * enabled. More importantly, KVM_DIRTY_LOG_INITIALLY_SET will assume= no + * page is wr-protected initially, which is against how kvm dirty ring= is + * usage - kvm dirty ring requires all pages are wr-protected at the v= ery + * beginning. Enabling this feature for dirty ring causes data corrup= tion. + */ + if (!s->kvm_dirty_ring_enabled) { + dirty_log_manual_caps =3D + kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); + dirty_log_manual_caps &=3D (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | + KVM_DIRTY_LOG_INITIALLY_SET); + s->manual_dirty_log_protect =3D dirty_log_manual_caps; + if (dirty_log_manual_caps) { + ret =3D kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2= , 0, + dirty_log_manual_caps); + if (ret) { + warn_report("Trying to enable capability %"PRIu64" of " + "KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 but failed.= " + "Falling back to the legacy mode. ", + dirty_log_manual_caps); + s->manual_dirty_log_protect =3D 0; + } } } =20 --=20 2.26.2 From nobody Mon Dec 15 01:32:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615409090; cv=none; d=zohomail.com; s=zohoarc; b=aWydjBwlbPFSVn5PslfZsoKoO3JdyLbKzHWhNVT9Xv2KGoZeaQaRP8oYUBlh65t6P9clO0gS+bwYxMSX4Y3Cq3ENvpkL8F2CFkdRQ8BW91/gYeLc/sjUrQI6FKJrSTQae3AVqdN/VpwlsHlWVLqmy4Qr24VgZ5nEeIYYXz7yYiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615409090; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tE+fyefSQ550ysljZxzV8SnfGDmPMbztraA9hFPB8Ck=; b=nvdm6gmr4vdUacOoGGtfFbt2MiU/qqMpcfFQiutal+tcIpyoPm28S65S+T2V6NM91DfaYeHyn8234mjE+w2OjxSeA8KNIRUgzuu4EVBJ6spY5KqMfATKB+0QqYboGtE7XADGLilXnLnafba6M+3xHSS3EEZiYe5XmZe3F8ixZKA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615409090557564.8067610699793; Wed, 10 Mar 2021 12:44:50 -0800 (PST) Received: from localhost ([::1]:33886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK5hJ-0002IN-51 for importer@patchew.org; Wed, 10 Mar 2021 15:44:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK5WD-00061X-Ui for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54211) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lK5WB-0000hG-8D for qemu-devel@nongnu.org; Wed, 10 Mar 2021 15:33:21 -0500 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-LwJ0A3fcOiCNwXtUw7XVfQ-1; Wed, 10 Mar 2021 15:33:17 -0500 Received: by mail-qk1-f200.google.com with SMTP id e17so1838064qkg.3 for ; Wed, 10 Mar 2021 12:33:17 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 12:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615408398; 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=tE+fyefSQ550ysljZxzV8SnfGDmPMbztraA9hFPB8Ck=; b=astmP1u9HU+FyihhZn9L23tBHGTU2DNuEFrc1KlJLYquADLswI3bwqQjXXMN0TQlnvj+yF m74PnfDcDifitJUoIqJfdA23nIDrrDF6BrcLJrgKusY8dn87R+O0Pa7jeIU4Vr+qT6FhwX dsRVXbPx9miQ+7b6d4mkXRBFkcAVoLI= X-MC-Unique: LwJ0A3fcOiCNwXtUw7XVfQ-1 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=tE+fyefSQ550ysljZxzV8SnfGDmPMbztraA9hFPB8Ck=; b=nF/w2Xgsj7rZ3ZCQoH/Z3397rs3u1FIUpRmOWGmehZTK0L3Txcb5xKVlD3TBHQ9RxN 3Ze/ePgn6iu+mWFin8kk+NoXQYn393BwX04v5aRb07VXLO71E24uEpq3ubYOzRIFfpfd WFyZmhZQwnExQxPAU3xfYX4fJ64TWbKDHLPQ3xKwbufS3FblgXXSaqJq6bnnkvbTJ36Z rIcA4pdhG796fn16mfixmNEhYbnT7JW2xj8jSHjX/CAoLliI0NPpkfs0X0cNuOdAE+sR fDnsQA4PTo0Fup3nIwyPVWb+DglvP4iY9pDDzjQ0wACXCoObcfXOC6Ta2HKzQY9/kxGf EmwQ== X-Gm-Message-State: AOAM5308OljzPv9It05ppFCBOVm6Gi3MPa2VjYGcIvO0EMFinUSqdDoG ey4Gz0xruOBz7rpFxUT9ia9Rx2RAZzWid9GO5bNqR6orbFcZp/q1lme1tmNyE21wZ2ZsSwym9lB u3gpk1543VgpbOI7oe20nRr0BeskUHaUTwolz3rqom6YdkRvd/FwYCvCOGLR7R8xB X-Received: by 2002:a37:3c8:: with SMTP id 191mr4459143qkd.90.1615408395842; Wed, 10 Mar 2021 12:33:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFyyEaFruEUcBMPg+eXADLYjCaWV5SGN6cNgslg/jGG3lUJAjokMurMOgkOAz7pKhp2h2rXA== X-Received: by 2002:a37:3c8:: with SMTP id 191mr4459094qkd.90.1615408395255; Wed, 10 Mar 2021 12:33:15 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 10/10] KVM: Dirty ring support Date: Wed, 10 Mar 2021 15:33:01 -0500 Message-Id: <20210310203301.194842-11-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: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.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_H4=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" KVM dirty ring is a new interface to pass over dirty bits from kernel to the userspace. Instead of using a bitmap for each memory region, the dirty ring contains an array of dirtied GPAs to fetch (in the form of offset in slots). For each vcpu there will be one dirty ring that binds to it. kvm_dirty_ring_reap() is the major function to collect dirty rings. It can= be called either by a standalone reaper thread that runs in the background, collecting dirty pages for the whole VM. It can also be called directly by= any thread that has BQL taken. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 332 ++++++++++++++++++++++++++++++++++++++++- accel/kvm/trace-events | 7 + include/hw/core/cpu.h | 8 + 3 files changed, 344 insertions(+), 3 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index ae9393266b2..bf2b21f038b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -15,6 +15,7 @@ =20 #include "qemu/osdep.h" #include +#include =20 #include =20 @@ -80,6 +81,25 @@ struct KVMParkedVcpu { QLIST_ENTRY(KVMParkedVcpu) node; }; =20 +enum KVMDirtyRingReaperState { + KVM_DIRTY_RING_REAPER_NONE =3D 0, + /* The reaper is sleeping */ + KVM_DIRTY_RING_REAPER_WAIT, + /* The reaper is reaping for dirty pages */ + KVM_DIRTY_RING_REAPER_REAPING, +}; + +/* + * KVM reaper instance, responsible for collecting the KVM dirty bits + * via the dirty ring. + */ +struct KVMDirtyRingReaper { + /* The reaper thread */ + QemuThread reaper_thr; + volatile uint64_t reaper_iteration; /* iteration number of reaper thr = */ + volatile enum KVMDirtyRingReaperState reaper_state; /* reap thr state = */ +}; + struct KVMState { AccelState parent_obj; @@ -131,6 +151,7 @@ struct KVMState bool kvm_dirty_ring_enabled; /* Whether KVM dirty ring is enabled */ uint64_t kvm_dirty_ring_size; /* Size of the per-vcpu dirty ring */ uint32_t kvm_dirty_gfn_count; /* Number of dirty GFNs per ring */ + struct KVMDirtyRingReaper reaper; }; =20 KVMState *kvm_state; @@ -392,6 +413,13 @@ static int do_kvm_destroy_vcpu(CPUState *cpu) goto err; } =20 + if (cpu->kvm_dirty_gfns) { + ret =3D munmap(cpu->kvm_dirty_gfns, s->kvm_dirty_ring_size); + if (ret < 0) { + goto err; + } + } + vcpu =3D g_malloc0(sizeof(*vcpu)); vcpu->vcpu_id =3D kvm_arch_vcpu_id(cpu); vcpu->kvm_fd =3D cpu->kvm_fd; @@ -468,6 +496,19 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) (void *)cpu->kvm_run + s->coalesced_mmio * PAGE_SIZE; } =20 + if (s->kvm_dirty_ring_enabled) { + /* Use MAP_SHARED to share pages with the kernel */ + cpu->kvm_dirty_gfns =3D mmap(NULL, s->kvm_dirty_ring_size, + PROT_READ | PROT_WRITE, MAP_SHARED, + cpu->kvm_fd, + PAGE_SIZE * KVM_DIRTY_LOG_PAGE_OFFSET); + if (cpu->kvm_dirty_gfns =3D=3D MAP_FAILED) { + ret =3D -errno; + DPRINTF("mmap'ing vcpu dirty gfns failed: %d\n", ret); + goto err; + } + } + ret =3D kvm_arch_init_vcpu(cpu); if (ret < 0) { error_setg_errno(errp, -ret, @@ -586,6 +627,11 @@ static void kvm_slot_sync_dirty_pages(KVMSlot *slot) cpu_physical_memory_set_dirty_lebitmap(slot->dirty_bmap, start, pages); } =20 +static void kvm_slot_reset_dirty_pages(KVMSlot *slot) +{ + memset(slot->dirty_bmap, 0, slot->dirty_bmap_size); +} + #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) =20 /* Allocate the dirty bitmap for a slot */ @@ -642,6 +688,170 @@ static bool kvm_slot_get_dirty_log(KVMState *s, KVMSl= ot *slot) return ret =3D=3D 0; } =20 +/* Should be with all slots_lock held for the address spaces. */ +static void kvm_dirty_ring_mark_page(KVMState *s, uint32_t as_id, + uint32_t slot_id, uint64_t offset) +{ + KVMMemoryListener *kml; + KVMSlot *mem; + + if (as_id >=3D s->nr_as) { + return; + } + + kml =3D s->as[as_id].ml; + mem =3D &kml->slots[slot_id]; + + if (!mem->memory_size || offset >=3D (mem->memory_size / TARGET_PAGE_S= IZE)) { + return; + } + + set_bit(offset, mem->dirty_bmap); +} + +static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn) +{ + return gfn->flags =3D=3D KVM_DIRTY_GFN_F_DIRTY; +} + +static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn) +{ + gfn->flags =3D KVM_DIRTY_GFN_F_RESET; +} + +/* + * Should be with all slots_lock held for the address spaces. It returns = the + * dirty page we've collected on this dirty ring. + */ +static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CPUState *cpu) +{ + struct kvm_dirty_gfn *dirty_gfns =3D cpu->kvm_dirty_gfns, *cur; + uint32_t gfn_count =3D s->kvm_dirty_gfn_count; + uint32_t count =3D 0, fetch =3D cpu->kvm_fetch_index; + + assert(dirty_gfns && gfn_count); + trace_kvm_dirty_ring_reap_vcpu(cpu->cpu_index); + + while (true) { + cur =3D &dirty_gfns[fetch % gfn_count]; + if (!dirty_gfn_is_dirtied(cur)) { + break; + } + kvm_dirty_ring_mark_page(s, cur->slot >> 16, cur->slot & 0xffff, + cur->offset); + dirty_gfn_set_collected(cur); + trace_kvm_dirty_ring_page(cpu->cpu_index, fetch, cur->offset); + fetch++; + count++; + } + cpu->kvm_fetch_index =3D fetch; + + return count; +} + +/* Must be with slots_lock held */ +static uint64_t kvm_dirty_ring_reap_locked(KVMState *s) +{ + int ret; + CPUState *cpu; + uint64_t total =3D 0; + int64_t stamp; + + stamp =3D get_clock(); + + CPU_FOREACH(cpu) { + total +=3D kvm_dirty_ring_reap_one(s, cpu); + } + + if (total) { + ret =3D kvm_vm_ioctl(s, KVM_RESET_DIRTY_RINGS); + assert(ret =3D=3D total); + } + + stamp =3D get_clock() - stamp; + + if (total) { + trace_kvm_dirty_ring_reap(total, stamp / 1000); + } + + return total; +} + +/* + * Currently for simplicity, we must hold BQL before calling this. We can + * consider to drop the BQL if we're clear with all the race conditions. + */ +static uint64_t kvm_dirty_ring_reap(KVMState *s) +{ + uint64_t total; + + /* + * We need to lock all kvm slots for all address spaces here, + * because: + * + * (1) We need to mark dirty for dirty bitmaps in multiple slots + * and for tons of pages, so it's better to take the lock here + * once rather than once per page. And more importantly, + * + * (2) We must _NOT_ publish dirty bits to the other threads + * (e.g., the migration thread) via the kvm memory slot dirty + * bitmaps before correctly re-protect those dirtied pages. + * Otherwise we can have potential risk of data corruption if + * the page data is read in the other thread before we do + * reset below. + */ + kvm_slots_lock(); + total =3D kvm_dirty_ring_reap_locked(s); + kvm_slots_unlock(); + + return total; +} + +static void do_kvm_cpu_synchronize_kick(CPUState *cpu, run_on_cpu_data arg) +{ + /* No need to do anything */ +} + +/* + * Kick all vcpus out in a synchronized way. When returned, we + * guarantee that every vcpu has been kicked and at least returned to + * userspace once. + */ +static void kvm_cpu_synchronize_kick_all(void) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + run_on_cpu(cpu, do_kvm_cpu_synchronize_kick, RUN_ON_CPU_NULL); + } +} + +/* + * Flush all the existing dirty pages to the KVM slot buffers. When + * this call returns, we guarantee that all the touched dirty pages + * before calling this function have been put into the per-kvmslot + * dirty bitmap. + * + * This function must be called with BQL held. + */ +static void kvm_dirty_ring_flush(struct KVMDirtyRingReaper *r) +{ + trace_kvm_dirty_ring_flush(0); + /* + * The function needs to be serialized. Since this function + * should always be with BQL held, serialization is guaranteed. + * However, let's be sure of it. + */ + assert(qemu_mutex_iothread_locked()); + /* + * First make sure to flush the hardware buffers by kicking all + * vcpus out in a synchronous way. + */ + kvm_cpu_synchronize_kick_all(); + kvm_dirty_ring_reap(kvm_state); + trace_kvm_dirty_ring_flush(1); +} + /** * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * @@ -1174,7 +1384,24 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, goto out; } if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { - kvm_slot_get_dirty_log(kvm_state, mem); + /* + * NOTE: We should be aware of the fact that here we're on= ly + * doing a best effort to sync dirty bits. No matter whet= her + * we're using dirty log or dirty ring, we ignored two fac= ts: + * + * (1) dirty bits can reside in hardware buffers (PML) + * + * (2) after we collected dirty bits here, pages can be di= rtied + * again before we do the final KVM_SET_USER_MEMORY_REGION= to + * remove the slot. + * + * Not easy. Let's cross the fingers until it's fixed. + */ + if (kvm_state->kvm_dirty_ring_enabled) { + kvm_dirty_ring_reap_locked(kvm_state); + } else { + kvm_slot_get_dirty_log(kvm_state, mem); + } kvm_slot_sync_dirty_pages(mem); } =20 @@ -1222,6 +1449,51 @@ out: kvm_slots_unlock(); } =20 +static void *kvm_dirty_ring_reaper_thread(void *data) +{ + KVMState *s =3D data; + struct KVMDirtyRingReaper *r =3D &s->reaper; + + rcu_register_thread(); + + trace_kvm_dirty_ring_reaper("init"); + + while (true) { + r->reaper_state =3D KVM_DIRTY_RING_REAPER_WAIT; + trace_kvm_dirty_ring_reaper("wait"); + /* + * TODO: provide a smarter timeout rather than a constant? + */ + sleep(1); + + trace_kvm_dirty_ring_reaper("wakeup"); + r->reaper_state =3D KVM_DIRTY_RING_REAPER_REAPING; + + qemu_mutex_lock_iothread(); + kvm_dirty_ring_reap(s); + qemu_mutex_unlock_iothread(); + + r->reaper_iteration++; + } + + trace_kvm_dirty_ring_reaper("exit"); + + rcu_unregister_thread(); + + return NULL; +} + +static int kvm_dirty_ring_reaper_init(KVMState *s) +{ + struct KVMDirtyRingReaper *r =3D &s->reaper; + + qemu_thread_create(&r->reaper_thr, "kvm-reaper", + kvm_dirty_ring_reaper_thread, + s, QEMU_THREAD_JOINABLE); + + return 0; +} + static void kvm_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -1250,6 +1522,36 @@ static void kvm_log_sync(MemoryListener *listener, kvm_slots_unlock(); } =20 +static void kvm_log_sync_global(MemoryListener *l) +{ + KVMMemoryListener *kml =3D container_of(l, KVMMemoryListener, listener= ); + KVMState *s =3D kvm_state; + KVMSlot *mem; + int i; + + /* Flush all kernel dirty addresses into KVMSlot dirty bitmap */ + kvm_dirty_ring_flush(&s->reaper); + + /* + * TODO: make this faster when nr_slots is big while there are + * only a few used slots (small VMs). + */ + kvm_slots_lock(); + for (i =3D 0; i < s->nr_slots; i++) { + mem =3D &kml->slots[i]; + if (mem->memory_size && mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { + kvm_slot_sync_dirty_pages(mem); + /* + * This is not needed by KVM_GET_DIRTY_LOG because the + * ioctl will unconditionally overwrite the whole region. + * However kvm dirty ring has no such side effect. + */ + kvm_slot_reset_dirty_pages(mem); + } + } + kvm_slots_unlock(); +} + static void kvm_log_clear(MemoryListener *listener, MemoryRegionSection *section) { @@ -1356,10 +1658,15 @@ void kvm_memory_listener_register(KVMState *s, KVMM= emoryListener *kml, kml->listener.region_del =3D kvm_region_del; kml->listener.log_start =3D kvm_log_start; kml->listener.log_stop =3D kvm_log_stop; - kml->listener.log_sync =3D kvm_log_sync; - kml->listener.log_clear =3D kvm_log_clear; kml->listener.priority =3D 10; =20 + if (s->kvm_dirty_ring_enabled) { + kml->listener.log_sync_global =3D kvm_log_sync_global; + } else { + kml->listener.log_sync =3D kvm_log_sync; + kml->listener.log_clear =3D kvm_log_clear; + } + memory_listener_register(&kml->listener, as); =20 for (i =3D 0; i < s->nr_as; ++i) { @@ -2281,6 +2588,14 @@ static int kvm_init(MachineState *ms) ret =3D ram_block_discard_disable(true); assert(!ret); } + + if (s->kvm_dirty_ring_enabled) { + ret =3D kvm_dirty_ring_reaper_init(s); + if (ret) { + goto err; + } + } + return 0; =20 err: @@ -2593,6 +2908,17 @@ int kvm_cpu_exec(CPUState *cpu) case KVM_EXIT_INTERNAL_ERROR: ret =3D kvm_handle_internal_error(cpu, run); break; + case KVM_EXIT_DIRTY_RING_FULL: + /* + * We shouldn't continue if the dirty ring of this vcpu is + * still full. Got kicked by KVM_RESET_DIRTY_RINGS. + */ + trace_kvm_dirty_ring_full(cpu->cpu_index); + qemu_mutex_lock_iothread(); + kvm_dirty_ring_reap(kvm_state); + qemu_mutex_unlock_iothread(); + ret =3D 0; + break; case KVM_EXIT_SYSTEM_EVENT: switch (run->system_event.type) { case KVM_SYSTEM_EVENT_SHUTDOWN: diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index e15ae8980d3..72a01320a1a 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -18,4 +18,11 @@ kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint32_t va= l, bool assign, uint32_t kvm_set_user_memory(uint32_t slot, uint32_t flags, uint64_t guest_phys_add= r, uint64_t memory_size, uint64_t userspace_addr, int ret) "Slot#%d flags= =3D0x%x gpa=3D0x%"PRIx64 " size=3D0x%"PRIx64 " ua=3D0x%"PRIx64 " ret=3D%d" kvm_clear_dirty_log(uint32_t slot, uint64_t start, uint32_t size) "slot#%"= PRId32" start 0x%"PRIx64" size 0x%"PRIx32 kvm_resample_fd_notify(int gsi) "gsi %d" +kvm_dirty_ring_full(int id) "vcpu %d" +kvm_dirty_ring_reap_vcpu(int id) "vcpu %d" +kvm_dirty_ring_page(int vcpu, uint32_t slot, uint64_t offset) "vcpu %d fet= ch %"PRIu32" offset 0x%"PRIx64 +kvm_dirty_ring_reaper(const char *s) "%s" +kvm_dirty_ring_reap(uint64_t count, int64_t t) "reaped %"PRIu64" pages (to= ok %"PRIi64" us)" +kvm_dirty_ring_reaper_kick(const char *reason) "%s" +kvm_dirty_ring_flush(int finished) "%d" =20 diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index c68bc3ba8af..2f0991d93f7 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -323,6 +323,11 @@ struct qemu_work_item; * @ignore_memory_transaction_failures: Cached copy of the MachineState * flag of the same name: allows the board to suppress calling of the * CPU do_transaction_failed hook function. + * @kvm_dirty_ring_full: + * Whether the kvm dirty ring of this vcpu is soft-full. + * @kvm_dirty_ring_avail: + * Semaphore to be posted when the kvm dirty ring of the vcpu is + * available again. * * State of one CPU core or thread. */ @@ -394,9 +399,12 @@ struct CPUState { */ uintptr_t mem_io_pc; =20 + /* Only used in KVM */ int kvm_fd; struct KVMState *kvm_state; struct kvm_run *kvm_run; + struct kvm_dirty_gfn *kvm_dirty_gfns; + uint32_t kvm_fetch_index; =20 /* Used for events with 'vcpu' and *without* the 'disabled' properties= */ DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS); --=20 2.26.2