From nobody Thu Nov 13 21:55:27 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1583290655; cv=none; d=zohomail.com; s=zohoarc; b=U6TOK77pgbhx3qe61i6lYWiyqqYZAOQYX8LpkVQDDjaOzJ77NsrX14kEwjfBY8NUev7BBXBnPwQKPVfKtO1pwvGdwoAloItE1g87ePSKvKoEnVqr73+TXJpCXzmfiEIJzwvAtRll4pPdqk+01EsJ1d6QbELSlJ88cUqTxfwbONk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583290655; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=KVuy7EP0T30DXVT//EqtQIHztsi4Nne4pYOZ66BCD0I=; b=RaKE2L1NlYJ3dGa36xBnaBIaXdClPLV5mfApC9iB07znd5Ge3XCTmyL9/Dm7eOse6Zdt5hKEpru9cRcE3pqf87mtcFc2HAVuP98WjeHtHkXL1P9U3LHP+t3/WB06dPwBA1mB66W8SZS+eNspVSloGMJg2tfybb3FPfMicVRk0oc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583290655391254.5394296941016; Tue, 3 Mar 2020 18:57:35 -0800 (PST) Received: from localhost ([::1]:56594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9KE2-0007zo-5c for importer@patchew.org; Tue, 03 Mar 2020 21:57:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43296) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9KCr-0006v5-Vo for qemu-devel@nongnu.org; Tue, 03 Mar 2020 21:56:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9KCp-00019Z-OM for qemu-devel@nongnu.org; Tue, 03 Mar 2020 21:56:21 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3258 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j9KCp-0000zp-Cs for qemu-devel@nongnu.org; Tue, 03 Mar 2020 21:56:19 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B3FB6199FD87F02F1DFD; Wed, 4 Mar 2020 10:56:07 +0800 (CST) Received: from localhost (10.173.228.206) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Wed, 4 Mar 2020 10:55:57 +0800 From: Jay Zhou To: , Subject: [PATCH] kvm: support to get/set dirty log initial-all-set capability Date: Wed, 4 Mar 2020 10:55:54 +0800 Message-ID: <20200304025554.2159-1-jianjay.zhou@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.173.228.206] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 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: liu.jinsong@huawei.com, weidong.huang@huawei.com, mst@redhat.com, wangxinxin.wang@huawei.com, cohuck@redhat.com, peterx@redhat.com, jianjay.zhou@huawei.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since the new capability KVM_DIRTY_LOG_INITIALLY_SET of KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 has been introduced in the kernel, tweak the userspace side to detect and enable this capability. Signed-off-by: Jay Zhou Reviewed-by: Peter Xu --- accel/kvm/kvm-all.c | 21 ++++++++++++++------- linux-headers/linux/kvm.h | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 439a4efe52..45ab25be63 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -100,7 +100,7 @@ struct KVMState bool kernel_irqchip_required; OnOffAuto kernel_irqchip_split; bool sync_mmu; - bool manual_dirty_log_protect; + uint64_t manual_dirty_log_protect; /* The man page (and posix) say ioctl numbers are signed int, but * they're not. Linux, glibc and *BSD all treat ioctl numbers as * unsigned, and treating them as signed here can break things */ @@ -1882,6 +1882,7 @@ static int kvm_init(MachineState *ms) int ret; int type =3D 0; const char *kvm_type; + uint64_t dirty_log_manual_caps; =20 s =3D KVM_STATE(ms->accelerator); =20 @@ -2007,14 +2008,20 @@ static int kvm_init(MachineState *ms) s->coalesced_pio =3D s->coalesced_mmio && kvm_check_extension(s, KVM_CAP_COALESCED_PIO); =20 - s->manual_dirty_log_protect =3D + dirty_log_manual_caps =3D kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); - if (s->manual_dirty_log_protect) { - ret =3D kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2, 0,= 1); + 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 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT= 2 " - "but failed. Falling back to the legacy mode. "); - s->manual_dirty_log_protect =3D false; + 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 diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 265099100e..3cb71c2b19 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1628,4 +1628,7 @@ struct kvm_hyperv_eventfd { #define KVM_HYPERV_CONN_ID_MASK 0x00ffffff #define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0) =20 +#define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0) +#define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1) + #endif /* __LINUX_KVM_H */ --=20 2.14.1.windows.1