From nobody Wed Nov 12 10:22:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=de.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1569849976; cv=none; d=zoho.com; s=zohoarc; b=fq1TrsjoTNoe9KLFEj4fT3JgV8yh53cd4PSJcfFdK7ZZ4r30zgJqASQRkB9nN5GtOOPAEI26YbQGtEzm6JEAMt49ifdwiRSZM7J35dQg0YNOTjk1LkuEjCkXebRJIaF2ehLIxPfW6wV08D5bujpP1vnZMwCDiUFZN7DM+OeAHFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569849976; 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:ARC-Authentication-Results; bh=6coH4ttRzQvB50gF3ZmTVhhoEF8gQoCQdOxti1cPSxU=; b=XtkT33Ec0l3+Cj9dVf2/3LwiqIl2GnaEG8HtUBsgvUIk0QxplInXBDMUOobp49qi5MRvd5FYfU6v6x1PrWtpDEeqkBc8aD8Cz9WnDO2sgKtYWViKhq1K1+ZGsdI3r0p/PA7Dvn+IVPU4Dv+0zEbiF6qTdO0wPrkkqWHbqL9G+tA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1569849976345464.64326552514535; Mon, 30 Sep 2019 06:26:16 -0700 (PDT) Received: from localhost ([::1]:52382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEvgs-0002eM-IF for importer@patchew.org; Mon, 30 Sep 2019 09:26:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42561) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEvbW-0004XN-Up for qemu-devel@nongnu.org; Mon, 30 Sep 2019 09:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iEvbV-0005Qz-BL for qemu-devel@nongnu.org; Mon, 30 Sep 2019 09:20:42 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53536) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iEvbT-000510-UC for qemu-devel@nongnu.org; Mon, 30 Sep 2019 09:20:41 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8UDI2fm128740 for ; Mon, 30 Sep 2019 09:20:07 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vbgqedutg-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 30 Sep 2019 09:20:07 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 30 Sep 2019 14:20:04 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 30 Sep 2019 14:20:00 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8UDJwtl52166690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Sep 2019 13:19:58 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A448A4C04E; Mon, 30 Sep 2019 13:19:58 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8638F4C044; Mon, 30 Sep 2019 13:19:58 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 30 Sep 2019 13:19:58 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id 3CAF7E020F; Mon, 30 Sep 2019 15:19:58 +0200 (CEST) From: Christian Borntraeger To: Peter Maydell Subject: [PULL 09/12] kvm: clear dirty bitmaps from all overlapping memslots Date: Mon, 30 Sep 2019 15:19:52 +0200 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190930131955.101131-1-borntraeger@de.ibm.com> References: <20190930131955.101131-1-borntraeger@de.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 x-cbid: 19093013-0020-0000-0000-000003730FBB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19093013-0021-0000-0000-000021C8EA27 Message-Id: <20190930131955.101131-10-borntraeger@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-09-30_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=992 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909300138 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 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: Thomas Huth , Janosch Frank , Matthew Rosato , David Hildenbrand , Cornelia Huck , qemu-devel , Peter Xu , Halil Pasic , Christian Borntraeger , qemu-s390x , kvm@vger.kernel.org, Igor Mammedov , Paolo Bonzini , Claudio Imbrenda , Collin Walling , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Currently MemoryRegionSection has 1:1 mapping to KVMSlot. However next patch will allow splitting MemoryRegionSection into several KVMSlot-s, make sure that kvm_physical_log_slot_clear() is able to handle such 1:N mapping. Signed-off-by: Paolo Bonzini Signed-off-by: Igor Mammedov Reviewed-by: Peter Xu Message-Id: <20190924144751.24149-3-imammedo@redhat.com> Acked-by: Paolo Bonzini Signed-off-by: Christian Borntraeger --- accel/kvm/kvm-all.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index a85ec09486dd..ff9b95c0d103 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -589,8 +589,8 @@ static int kvm_log_clear_one_slot(KVMSlot *mem, int as_= id, uint64_t start, * satisfy the KVM interface requirement. Firstly, do the start * page alignment on 64 host pages */ - bmap_start =3D (start - mem->start_addr) & KVM_CLEAR_LOG_MASK; - start_delta =3D start - mem->start_addr - bmap_start; + bmap_start =3D start & KVM_CLEAR_LOG_MASK; + start_delta =3D start - bmap_start; bmap_start /=3D psize; =20 /* @@ -694,8 +694,8 @@ static int kvm_physical_log_clear(KVMMemoryListener *km= l, MemoryRegionSection *section) { KVMState *s =3D kvm_state; - uint64_t start, size; - KVMSlot *mem =3D NULL; + uint64_t start, size, offset, count; + KVMSlot *mem; int ret, i; =20 if (!s->manual_dirty_log_protect) { @@ -713,22 +713,30 @@ static int kvm_physical_log_clear(KVMMemoryListener *= kml, =20 kvm_slots_lock(kml); =20 - /* Find any possible slot that covers the section */ for (i =3D 0; i < s->nr_slots; i++) { mem =3D &kml->slots[i]; - if (mem->start_addr <=3D start && - start + size <=3D mem->start_addr + mem->memory_size) { + /* Discard slots that are empty or do not overlap the section */ + if (!mem->memory_size || + mem->start_addr > start + size - 1 || + start > mem->start_addr + mem->memory_size - 1) { + continue; + } + + if (start >=3D mem->start_addr) { + /* The slot starts before section or is aligned to it. */ + offset =3D start - mem->start_addr; + count =3D MIN(mem->memory_size - offset, size); + } else { + /* The slot starts after section. */ + offset =3D 0; + count =3D MIN(mem->memory_size, size - (mem->start_addr - star= t)); + } + ret =3D kvm_log_clear_one_slot(mem, kml->as_id, offset, count); + if (ret < 0) { break; } } =20 - /* - * We should always find one memslot until this point, otherwise - * there could be something wrong from the upper layer - */ - assert(mem && i !=3D s->nr_slots); - ret =3D kvm_log_clear_one_slot(mem, kml->as_id, start, size); - kvm_slots_unlock(kml); =20 return ret; --=20 2.21.0