From nobody Tue Feb 10 18:59:28 2026 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621500256; cv=none; d=zohomail.com; s=zohoarc; b=JdkM9lBMCXCfS0OnJlQY65921dGsieXsFcL9bxWk7US364yL+45+xvFLVZNoZ8ix/yD3wCiP3k37lcYBRE2DsgPz9cSXpi7iqYdRHGRBeKQRMe3L7I6mWRmIwMNVLgO4uMnoQKi5XcSQ2hqrB+wto/uIlNlb5lYkE7z6+Vv4MO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621500256; h=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=+6To3R747Gt8KrZIdybi9XgGpLzBn8XFWqjsTJBScXc=; b=cNhuVUdMvQ4u0dledHFBjsp93MMA4riRDWNBmc8OJfwR2wx0Q129BliwJWdxRUDGvI1XHLOna688+6AW129nqfahVqNpV7hBM/h1NWTsxzm6cOmubAKS7JgNl+2h6r5gRDIMDplvg8WWF0SwuRt/rqzPXfLmdlH9jIBG1IJWns8= 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+importer2=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 1621500256472131.7401139470246; Thu, 20 May 2021 01:44:16 -0700 (PDT) Received: from localhost ([::1]:34870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljeHv-0003wm-Ek for importer2@patchew.org; Thu, 20 May 2021 04:44:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljdxj-0005RK-8v for qemu-devel@nongnu.org; Thu, 20 May 2021 04:23:29 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:51061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljdxf-0001Y5-08 for qemu-devel@nongnu.org; Thu, 20 May 2021 04:23:22 -0400 Received: by mail-wm1-x332.google.com with SMTP id t206so8638725wmf.0 for ; Thu, 20 May 2021 01:23:10 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v10sm2603506wrq.0.2021.05.20.01.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 01:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+6To3R747Gt8KrZIdybi9XgGpLzBn8XFWqjsTJBScXc=; b=naWvRZUwVgLVlkiEDYK/2S4K54bNcNJ0G3DKgqUJpVP4fs7tdUvQQBBdtRzSCEe9HT iIs1Hmm9S2+m6E0TC+d9wpHVbw3jkNBqOwSaEIVxdqXwhnYYWQkFeU2MTlH35jy4VZCw D/mfqFNbLlqHQ7tPcotn/Byuh+RhYRSrfr2rCfMXIBFY1oXf9bf4VWkFb+NLYlsOTL5E bwHiiA8hDPOsoiMzUyHOgEwHcKXCUO3FzsedlR3BkdGieWzjpVl8Wu+iwLPHaK4ys/gx X3Q2JPLh1C27XxD1yBlcX2CeQNeuP0YlGzFhm0kuzjSmxLA4pOIoZ78JBbVmy6m8yk/x qUzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+6To3R747Gt8KrZIdybi9XgGpLzBn8XFWqjsTJBScXc=; b=HiUT3e/4wxzq4LadKcX41XLMb6+f1ai2JFozbE00/oSB8RINhmDAlBniGfIyZe/QO/ R7nDNHSr6vvTArktEMpmotJYYhcQKcCy1rTpqmIE0e1PMo4fuU6+s5wFqJqXBDDhogbc F8if2FmP7EcFxGnjg6X84QHrdiQR3PZvw2gMTRT6KyR5/TwAboGxPIn0BY+SE5T3XkVO gH79gGct97ZG+uR+LAXTv8BIvgTGx1vh2OZmcqVdDgNJs8i0t1Kx0gB7ewF+aOhZJkdd NPW1JhChYqbTb8wEtW4l3Qe3LcWzecPChKznoI1OFeKuuI7RMzUMFPH5Xy/COPPaCJzG hlnw== X-Gm-Message-State: AOAM531oHm+WNTLgjcIoIsxL+HX3vStcIL71/OaPd+OT7SLi5rxypbpZ SpPcw/bWeSN8Nyq7BvZGFtdun7ZY5V5FFg== X-Google-Smtp-Source: ABdhPJzSAenX3C9bCSoZbUP2MXyJQ69B+ZAZRXIjEZpUzG4pr4gNfGpjgF0fhpmh4HSY0SvJ72saTg== X-Received: by 2002:a1c:2507:: with SMTP id l7mr2399148wml.188.1621498989713; Thu, 20 May 2021 01:23:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 17/26] KVM: Add dirty-ring-size property Date: Thu, 20 May 2021 10:22:48 +0200 Message-Id: <20210520082257.187061-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520082257.187061-1-pbonzini@redhat.com> References: <20210520082257.187061-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Peter Xu Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Peter Xu 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 Message-Id: <20210506160549.130416-9-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 12 ++++++++++++ 2 files changed, 58 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index df9fbf59a6..5afe15ae66 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -126,6 +126,8 @@ struct KVMState KVMMemoryListener *ml; AddressSpace *as; } *as; + uint64_t kvm_dirty_ring_bytes; /* Size of the per-vcpu dirty ring */ + uint32_t kvm_dirty_ring_size; /* Number of dirty GFNs per ring */ }; =20 KVMState *kvm_state; @@ -3182,6 +3184,42 @@ bool kvm_kernel_irqchip_split(void) return kvm_state->kernel_irqchip_split =3D=3D ON_OFF_AUTO_ON; } =20 +static void kvm_get_dirty_ring_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s =3D KVM_STATE(obj); + uint32_t value =3D s->kvm_dirty_ring_size; + + visit_type_uint32(v, name, &value, errp); +} + +static void kvm_set_dirty_ring_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s =3D KVM_STATE(obj); + Error *error =3D NULL; + uint32_t value; + + if (s->fd !=3D -1) { + error_setg(errp, "Cannot set properties after the accelerator has = been initialized"); + return; + } + + visit_type_uint32(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + if (value & (value - 1)) { + error_setg(errp, "dirty-ring-size must be a power of two."); + return; + } + + s->kvm_dirty_ring_size =3D value; +} + static void kvm_accel_instance_init(Object *obj) { KVMState *s =3D KVM_STATE(obj); @@ -3191,6 +3229,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_ring_size =3D 0; } =20 static void kvm_accel_class_init(ObjectClass *oc, void *data) @@ -3212,6 +3252,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-ring-size", "uint32", + kvm_get_dirty_ring_size, kvm_set_dirty_ring_size, + NULL, NULL); + object_class_property_set_description(oc, "dirty-ring-size", + "Size of KVM dirty page ring buffer (default: 0, i.e. use bitmap)"= ); } =20 static const TypeInfo kvm_accel_type =3D { diff --git a/qemu-options.hx b/qemu-options.hx index e22fb94d99..ecdb064409 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-ring-size=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-ring-size=3Dn`` + When the KVM accelerator is used, it controls the size of the per-= vCPU + dirty page ring buffer (number of entries for each vCPU). It should + 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-ring-size=3D0). When enabled, KVM will instead + record dirty pages in a bitmap. + ERST =20 DEF("smp", HAS_ARG, QEMU_OPTION_smp, --=20 2.31.1