From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208714; cv=none; d=zoho.com; s=zohoarc; b=H3n/6VTSe+iUhmPgzuMbyf1eXn6vIH6LMT2V7HbZfWQ3ZXLgiNnIpVTPOjCWvff+2C7/q0kXQ9ih73r9WgDs0SVtZGIaQH5FxOverl4zPO1T63zwQRz6PhFy1OhYUwezWKZIJTTp0adUhbu1QBsJyAin8nzAcd1hXeruQLwvA78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208714; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=g+CW9SSI/U56JDm/lu3SPsjykjFUHqRfdkCeB063/qI=; b=J6mv6pSlFc5UX249IH/B33uogkps6mpTR5KYDcexGFlpPB/F+x6Kn69ucX7DwnxWRaavh/IKGPVv+jOYhv7WByi2YYv3XqXBaoYxk23RAmCDcBS5WzUV8Nbz+9CF/Kil+mgDvue3ljxgFLP+LIMnWSIGbYssfR7L3zfKN0BL/WM= 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 1559208714101768.2613452647935; Thu, 30 May 2019 02:31:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:49947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHPY-0001zu-31 for importer@patchew.org; Thu, 30 May 2019 05:31:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNN-0000fZ-5g for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNM-0001Bu-6G for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNM-0001BR-1E for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 553E390C87 for ; Thu, 30 May 2019 09:29:31 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBFED1001E86; Thu, 30 May 2019 09:29:28 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:08 +0800 Message-Id: <20190530092919.26059-2-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 30 May 2019 09:29:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 01/12] checkpatch: Allow SPDX-License-Identifier X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" According to: https://spdx.org/ids-how, let's still allow QEMU to use the SPDX license identifier: // SPDX-License-Identifier: *** Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 88682cb0a9..c2aaf421da 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1949,7 +1949,8 @@ sub process { } =20 # no C99 // comments - if ($line =3D~ m{//}) { + if ($line =3D~ m{//} && + $rawline !~ m{// SPDX-License-Identifier: }) { ERROR("do not use C99 // comments\n" . $herecurr); } # Remove C99 comments. --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208730; cv=none; d=zoho.com; s=zohoarc; b=RyIRAz1FSBMO+TUVCSCL1h//rwvhUmv1Hxf33Yr6KTpuI7LHVhUDRmWrZ/vPOtjF0JfRCFG/hl5lpPZYQi6JaxPUJ0FaOZsxOwtq6F4Ko5XrACvisttHIqsSXrmhoIYOyV39ukae2WdCkmaN2xNKbwm+86gWIRUA3U1y0G4Wbhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208730; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7bxrWLeFA1lWKfnbLl/yKDokNfljww5F7KLePrkBu38=; b=QBIsHWOs7TvHzrMnTKrqAA8tX1th3Fs7kKNO2LcBNzIA7KdDo+gulRRaTxqpQoumJ1RH+o+gmH5F26X9LXh6sHLQUnsR6v2JghyVcM0pt5SFifFzfIP+lL0ZKZEFEs8eObV6TTV6KzSnuR9iNXPlvSRFR/LMGuHM18d80CMHRGI= 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 15592087300741005.8171904127286; Thu, 30 May 2019 02:32:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:49949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHPk-00029p-40 for importer@patchew.org; Thu, 30 May 2019 05:32:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNR-0000i3-20 for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNQ-0001Kd-5m for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNQ-0001Jh-0E for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EFA7C13070F for ; Thu, 30 May 2019 09:29:35 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4EC51001DF6; Thu, 30 May 2019 09:29:31 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:09 +0800 Message-Id: <20190530092919.26059-3-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 30 May 2019 09:29:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 02/12] migration: No need to take rcu during sync_dirty_bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" cpu_physical_memory_sync_dirty_bitmap() has one RAMBlock* as parameter, which means that it must be with RCU read lock held already. Taking it again inside seems redundant. Removing it. Instead comment on the functions about the RCU read lock. Reviewed-by: Paolo Bonzini Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- include/exec/ram_addr.h | 5 +---- migration/ram.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 139ad79390..6fc49e5db5 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -408,6 +408,7 @@ static inline void cpu_physical_memory_clear_dirty_rang= e(ram_addr_t start, } =20 =20 +/* Called with RCU critical section */ static inline uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, ram_addr_t start, @@ -431,8 +432,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock= *rb, DIRTY_MEMORY_BLOCK_SIZE); unsigned long page =3D BIT_WORD(start >> TARGET_PAGE_BITS); =20 - rcu_read_lock(); - src =3D atomic_rcu_read( &ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION])->blocks; =20 @@ -452,8 +451,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock= *rb, idx++; } } - - rcu_read_unlock(); } else { ram_addr_t offset =3D rb->offset; =20 diff --git a/migration/ram.c b/migration/ram.c index 4c60869226..dc916042fb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1678,6 +1678,7 @@ static inline bool migration_bitmap_clear_dirty(RAMSt= ate *rs, return ret; } =20 +/* Called with RCU critical section */ static void migration_bitmap_sync_range(RAMState *rs, RAMBlock *rb, ram_addr_t length) { --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208919; cv=none; d=zoho.com; s=zohoarc; b=UrvShAUSBO74TQDVe2tfMnL4DAZGRy/QkmvgGEK1hIuoMcshE53Kl37ZFnTqL4qzTCnx+RK5g5vzoi/yruQCtdHc4gOSV5YkQIsQEU5Tf5vgG51xRJnsVDPUNBKGTSpRpyyLMLkc8ishhlEirEPuTEyxhAi5VEoXuM10KQlC2jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208919; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=taZceGC3TYt+Aso6L4Go2RcSzDujet294Qp8gSDNqGY=; b=R/4goI+BN4xzqHBtCgMtHR8MoY2e+EghuxqpKZQBeTsT5Sy2xAum4szZKda9xpnbiTwk4bAURFGwF+6pa/AicIPbDI0OEZoe0Qohyo2eiPw67qYooSDWpBm2sMTKV7AhQBzW0cKZstSrRct1O/zUGUgq38gaQNihmF45yXEC7oU= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559208919178779.5363099289839; Thu, 30 May 2019 02:35:19 -0700 (PDT) Received: from localhost ([127.0.0.1]:49971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHSo-0004Lz-75 for importer@patchew.org; Thu, 30 May 2019 05:35:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNV-0000lS-7d for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNU-0001P8-8K for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNU-0001OQ-2z for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BB735AFD9 for ; Thu, 30 May 2019 09:29:39 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26DD510027C7; Thu, 30 May 2019 09:29:35 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:10 +0800 Message-Id: <20190530092919.26059-4-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 30 May 2019 09:29:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 03/12] memory: Remove memory_region_get_dirty() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's never used anywhere. Reviewed-by: Paolo Bonzini Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- include/exec/memory.h | 17 ----------------- memory.c | 8 -------- 2 files changed, 25 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9144a47f57..e6140e8a04 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1254,23 +1254,6 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_= addr_t newsize, */ void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client); =20 -/** - * memory_region_get_dirty: Check whether a range of bytes is dirty - * for a specified client. - * - * Checks whether a range of bytes has been written to since the last - * call to memory_region_reset_dirty() with the same @client. Dirty loggi= ng - * must be enabled. - * - * @mr: the memory region being queried. - * @addr: the address (relative to the start of the region) being queried. - * @size: the size of the range being queried. - * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or - * %DIRTY_MEMORY_VGA. - */ -bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr, - hwaddr size, unsigned client); - /** * memory_region_set_dirty: Mark a range of bytes as dirty in a memory reg= ion. * diff --git a/memory.c b/memory.c index 3071c4bdad..0920c105aa 100644 --- a/memory.c +++ b/memory.c @@ -2027,14 +2027,6 @@ void memory_region_set_log(MemoryRegion *mr, bool lo= g, unsigned client) memory_region_transaction_commit(); } =20 -bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr, - hwaddr size, unsigned client) -{ - assert(mr->ram_block); - return cpu_physical_memory_get_dirty(memory_region_get_ram_addr(mr) + = addr, - size, client); -} - void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size) { --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208735; cv=none; d=zoho.com; s=zohoarc; b=SBZrfSQILPVorPz3fI76gNzhyLiBGlRle3YqS5KN0TDVBHFOX/fLwGpRaiEZakKPW0KK6pUh6yVJeq1Jx/whD0jWq+PB6wkd7BhCVZfTe6M3KQ721q7bgoU19j1zcZQo18VIEIEdZZH0YDgLzxn45zT4TK1T/B7pfuQZZN9AHxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208735; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PAJqat5mkhBuHsMbD7j6frONU0oT3sZ551ajugQFpDk=; b=eOOJ6yfxc4DadZX+PPMIp5HSNKdFxgxYLCpDu8Ln3oSRFS+hLuuwTZNhYqIBx8W0gPbzSlrcR3ugTBvbCz7wfPuCxOFFHW0phZypPTKk2FKcBwDyCpHJ8Qf8Re9qQ3lbxWRw8lv12axNmJQf1MC4Uyuo0g/W0n4T/xLe2SAhiCM= 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 1559208735198585.252639119867; Thu, 30 May 2019 02:32:15 -0700 (PDT) Received: from localhost ([127.0.0.1]:49951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHPv-0002HF-5N for importer@patchew.org; Thu, 30 May 2019 05:32:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNb-0000o7-7b for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNa-0001Y7-6A for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNa-0001WL-1A for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 657183680B for ; Thu, 30 May 2019 09:29:45 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EDBB1001DF6; Thu, 30 May 2019 09:29:39 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:11 +0800 Message-Id: <20190530092919.26059-5-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 30 May 2019 09:29:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 04/12] memory: Don't set migration bitmap when without migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Similar to 9460dee4b2 ("memory: do not touch code dirty bitmap unless TCG is enabled", 2015-06-05) but for the migration bitmap - we can skip the MIGRATION bitmap update if migration not enabled. Reviewed-by: Paolo Bonzini Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 12 +++++++++++- memory.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index e6140e8a04..f29300c54d 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -46,6 +46,8 @@ OBJECT_GET_CLASS(IOMMUMemoryRegionClass, (obj), \ TYPE_IOMMU_MEMORY_REGION) =20 +extern bool global_dirty_log; + typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegionMmio MemoryRegionMmio; =20 diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 6fc49e5db5..79e70a96ee 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -348,8 +348,13 @@ static inline void cpu_physical_memory_set_dirty_lebit= map(unsigned long *bitmap, if (bitmap[k]) { unsigned long temp =3D leul_to_cpu(bitmap[k]); =20 - atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset], te= mp); atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp); + + if (global_dirty_log) { + atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset], + temp); + } + if (tcg_enabled()) { atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset], tem= p); } @@ -366,6 +371,11 @@ static inline void cpu_physical_memory_set_dirty_lebit= map(unsigned long *bitmap, xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS); } else { uint8_t clients =3D tcg_enabled() ? DIRTY_CLIENTS_ALL : DIRTY_CLIE= NTS_NOCODE; + + if (!global_dirty_log) { + clients &=3D ~(1 << DIRTY_MEMORY_MIGRATION); + } + /* * bitmap-traveling is faster than memory-traveling (for addr...) * especially when most of the memory is not dirty. diff --git a/memory.c b/memory.c index 0920c105aa..cff0ea8f40 100644 --- a/memory.c +++ b/memory.c @@ -38,7 +38,7 @@ static unsigned memory_region_transaction_depth; static bool memory_region_update_pending; static bool ioeventfd_update_pending; -static bool global_dirty_log =3D false; +bool global_dirty_log; =20 static QTAILQ_HEAD(, MemoryListener) memory_listeners =3D QTAILQ_HEAD_INITIALIZER(memory_listeners); --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208916; cv=none; d=zoho.com; s=zohoarc; b=Aac4kfcZ3E3UBGtkB1V6yVP1y2rXkDlXkVXufAdS2Y6BYVxVL+wFOb1lor6AdoFFDQm0tYLbEZY0xFpxf0bVtnjowiZOJQI8nxbwSwxSvwu2m1qCQLcXOsYEkOszBulnBprxkD+pEol0hxQAxMgT2qsPNr7FewtrLTB2qPrrWbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208916; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JhQJbhv9TdL+o+O604lrNO2QE+nG5BlWIcq8+gaT2tA=; b=lAT0pRPgYYGesKZK0sUksM7G8N9oKF1byDaDZ8ECR0/mSW/fVDCP5VmtJmScq8xwe/W+fkDzNuZr9pphsZYdGnx9kMlMRoFMiYY2B+le8OI4kasPLFgGxOhHjSk2tO+OkDUYUwK8HUESlumMvDssfFgylOqnX5HJk7Orw3hNR48= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 155920891605561.7976738931244; Thu, 30 May 2019 02:35:16 -0700 (PDT) Received: from localhost ([127.0.0.1]:49969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHSk-0004HZ-DG for importer@patchew.org; Thu, 30 May 2019 05:35:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNg-0000sl-9s for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNe-0001eO-Qc for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38048) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNe-0001du-J5 for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:50 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E09CE30001DD for ; Thu, 30 May 2019 09:29:49 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DA2110027C7; Thu, 30 May 2019 09:29:45 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:12 +0800 Message-Id: <20190530092919.26059-6-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 30 May 2019 09:29:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 05/12] bitmap: Add bitmap_copy_with_{src|dst}_offset() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" These helpers copy the source bitmap to destination bitmap with a shift either on the src or dst bitmap. Meanwhile, we never have bitmap tests but we should. This patch also introduces the initial test cases for utils/bitmap.c but it only tests the newly introduced functions. Signed-off-by: Peter Xu --- include/qemu/bitmap.h | 9 +++++ tests/Makefile.include | 2 ++ tests/test-bitmap.c | 81 ++++++++++++++++++++++++++++++++++++++++++ util/bitmap.c | 73 +++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 tests/test-bitmap.c diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 5c313346b9..cdaa953371 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -41,6 +41,10 @@ * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area * bitmap_to_le(dst, src, nbits) Convert bitmap to little endian * bitmap_from_le(dst, src, nbits) Convert bitmap from little endian + * bitmap_copy_with_src_offset(dst, src, offset, nbits) + * *dst =3D *src (with an offset upon s= rc) + * bitmap_copy_with_dst_offset(dst, src, offset, nbits) + * *dst =3D *src (with an offset upon d= st) */ =20 /* @@ -271,4 +275,9 @@ void bitmap_to_le(unsigned long *dst, const unsigned lo= ng *src, void bitmap_from_le(unsigned long *dst, const unsigned long *src, long nbits); =20 +void bitmap_copy_with_src_offset(unsigned long *dst, const unsigned long *= src, + long offset, long nbits); +void bitmap_copy_with_dst_offset(unsigned long *dst, const unsigned long *= src, + long shift, long nbits); + #endif /* BITMAP_H */ diff --git a/tests/Makefile.include b/tests/Makefile.include index 1865f6b322..5e2d7dddff 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -64,6 +64,7 @@ check-unit-y +=3D tests/test-opts-visitor$(EXESUF) check-unit-$(CONFIG_BLOCK) +=3D tests/test-coroutine$(EXESUF) check-unit-y +=3D tests/test-visitor-serialization$(EXESUF) check-unit-y +=3D tests/test-iov$(EXESUF) +check-unit-y +=3D tests/test-bitmap$(EXESUF) check-unit-$(CONFIG_BLOCK) +=3D tests/test-aio$(EXESUF) check-unit-$(CONFIG_BLOCK) +=3D tests/test-aio-multithread$(EXESUF) check-unit-$(CONFIG_BLOCK) +=3D tests/test-throttle$(EXESUF) @@ -529,6 +530,7 @@ tests/test-image-locking$(EXESUF): tests/test-image-loc= king.o $(test-block-obj-y tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj= -y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(tes= t-crypto-obj-y) +tests/test-bitmap$(EXESUF): tests/test-bitmap.o $(test-util-obj-y) tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o migrati= on/page_cache.o $(test-util-obj-y) tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o $(test-util-= obj-y) diff --git a/tests/test-bitmap.c b/tests/test-bitmap.c new file mode 100644 index 0000000000..36b4c07bf2 --- /dev/null +++ b/tests/test-bitmap.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Bitmap.c unit-tests. + * + * Copyright (C) 2019, Red Hat, Inc. + * + * Author: Peter Xu + */ + +#include +#include "qemu/osdep.h" +#include "qemu/bitmap.h" + +#define BMAP_SIZE 1024 + +static void check_bitmap_copy_with_offset(void) +{ + int i; + unsigned long *bmap1, *bmap2, *bmap3, total; + + bmap1 =3D bitmap_new(BMAP_SIZE); + bmap2 =3D bitmap_new(BMAP_SIZE); + bmap3 =3D bitmap_new(BMAP_SIZE); + + *bmap1 =3D random(); + *(bmap1 + 1) =3D random(); + *(bmap1 + 2) =3D random(); + *(bmap1 + 3) =3D random(); + total =3D BITS_PER_LONG * 4; + + /* Shift 115 bits into bmap2 */ + bitmap_copy_with_dst_offset(bmap2, bmap1, 115, total); + /* Shift another 85 bits into bmap3 */ + bitmap_copy_with_dst_offset(bmap3, bmap2, 85, total + 115); + /* Shift back 200 bits back */ + bitmap_copy_with_src_offset(bmap2, bmap3, 200, total); + + for (i =3D 0; i < 3; i++) { + g_assert(*(bmap1 + i) =3D=3D *(bmap2 + i)); + } + + bitmap_clear(bmap1, 0, BMAP_SIZE); + /* Set bits in bmap1 are 100-245 */ + bitmap_set(bmap1, 100, 145); + + /* Set bits in bmap2 are 60-205 */ + bitmap_copy_with_src_offset(bmap2, bmap1, 40, 250); + for (i =3D 0; i < 60; i++) { + g_assert(test_bit(i, bmap2) =3D=3D 0); + } + for (i =3D 60; i < 205; i++) { + g_assert(test_bit(i, bmap2)); + } + g_assert(test_bit(205, bmap2) =3D=3D 0); + + /* Set bits in bmap3 are 135-280 */ + bitmap_copy_with_dst_offset(bmap3, bmap1, 35, 250); + for (i =3D 0; i < 135; i++) { + g_assert(test_bit(i, bmap3) =3D=3D 0); + } + for (i =3D 135; i < 280; i++) { + g_assert(test_bit(i, bmap3)); + } + g_assert(test_bit(280, bmap3) =3D=3D 0); + + g_free(bmap1); + g_free(bmap2); + g_free(bmap3); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/bitmap/bitmap_copy_with_offset", + check_bitmap_copy_with_offset); + + g_test_run(); + + return 0; +} diff --git a/util/bitmap.c b/util/bitmap.c index cb618c65a5..391a7bb744 100644 --- a/util/bitmap.c +++ b/util/bitmap.c @@ -402,3 +402,76 @@ void bitmap_to_le(unsigned long *dst, const unsigned l= ong *src, { bitmap_to_from_le(dst, src, nbits); } + +/* + * Copy "src" bitmap with a positive offset and put it into the "dst" + * bitmap. The caller needs to make sure the bitmap size of "src" + * is bigger than (shift + nbits). + */ +void bitmap_copy_with_src_offset(unsigned long *dst, const unsigned long *= src, + long shift, long nbits) +{ + unsigned long left_mask, right_mask, last_mask; + + assert(shift >=3D 0); + /* Proper shift src pointer to the first word to copy from */ + src +=3D BIT_WORD(shift); + shift %=3D BITS_PER_LONG; + right_mask =3D (1ul << shift) - 1; + left_mask =3D ~right_mask; + + while (nbits >=3D BITS_PER_LONG) { + *dst =3D (*src & left_mask) >> shift; + *dst |=3D (*(src + 1) & right_mask) << (BITS_PER_LONG - shift); + dst++; + src++; + nbits -=3D BITS_PER_LONG; + } + + if (nbits > BITS_PER_LONG - shift) { + *dst =3D (*src & left_mask) >> shift; + nbits -=3D BITS_PER_LONG - shift; + last_mask =3D (1 << nbits) - 1; + *dst |=3D (*(src + 1) & last_mask) << (BITS_PER_LONG - shift); + } else if (nbits) { + last_mask =3D (1 << nbits) - 1; + *dst =3D (*src >> shift) & last_mask; + } +} + +/* + * Copy "src" bitmap into the "dst" bitmap with an offset in the + * "dst". The caller needs to make sure the bitmap size of "dst" is + * bigger than (shift + nbits). + */ +void bitmap_copy_with_dst_offset(unsigned long *dst, const unsigned long *= src, + long shift, long nbits) +{ + unsigned long left_mask, right_mask, last_mask; + + assert(shift >=3D 0); + /* Proper shift src pointer to the first word to copy from */ + dst +=3D BIT_WORD(shift); + shift %=3D BITS_PER_LONG; + right_mask =3D (1ul << (BITS_PER_LONG - shift)) - 1; + left_mask =3D ~right_mask; + + *dst &=3D (1ul << shift) - 1; + while (nbits >=3D BITS_PER_LONG) { + *dst |=3D (*src & right_mask) << shift; + *(dst + 1) =3D (*src & left_mask) >> (BITS_PER_LONG - shift); + dst++; + src++; + nbits -=3D BITS_PER_LONG; + } + + if (nbits > BITS_PER_LONG - shift) { + *dst |=3D (*src & right_mask) << shift; + nbits -=3D BITS_PER_LONG - shift; + last_mask =3D ((1 << nbits) - 1) << (BITS_PER_LONG - shift); + *(dst + 1) =3D (*src & last_mask) >> (BITS_PER_LONG - shift); + } else if (nbits) { + last_mask =3D (1 << nbits) - 1; + *dst |=3D (*src & last_mask) << shift; + } +} --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208923; cv=none; d=zoho.com; s=zohoarc; b=DsvrDqCVZsO+yGR3Ecx19xkmIsHa4Y6uY8ZsYFI4ALSd0tal+JxCONjQ4iA7zDKfI7+xc46TX4ewCg1HU6kUCY7F/JIrI7D6A/r1ywfMV59yq4PjWsy1XZxo/hVylQwciFpcSERh1pHuIiuQY4MPo+jqBHhkrtcwbb+dsLb9Tyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208923; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6Pev+xMvgjfNh+a0KCoEA9qijHqP+jISozuWiG0aIjw=; b=V3X2+RDYUUx0kedTvtxdGVvLclFW2uK3GdxiA10g5GTDA6N+yqtMxjCA7bHjx4McX99VlyRcoPz7JfJO/fWQeGREJEgLBDjBwdr5T6+ldf7XZO1NwL0L/917mTkuJMZF9RBefrcVld3Shkq9HxB1c1ToKhr2Ogg9qMrpSbw+9+c= 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 1559208923838976.5903371177986; Thu, 30 May 2019 02:35:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:49973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHSx-0004V7-PV for importer@patchew.org; Thu, 30 May 2019 05:35:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNj-0000vo-DW for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNi-0001lL-D4 for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNi-0001iq-7z for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:54 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92B853082B64 for ; Thu, 30 May 2019 09:29:53 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7E331018A0D; Thu, 30 May 2019 09:29:50 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:13 +0800 Message-Id: <20190530092919.26059-7-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 30 May 2019 09:29:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 06/12] memory: Pass mr into snapshot_and_clear_dirty X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Also we change the 2nd parameter of it to be the relative offset within the memory region. This is to be used in follow up patches. Signed-off-by: Peter Xu --- exec.c | 3 ++- include/exec/ram_addr.h | 2 +- memory.c | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index 4e734770c2..2615b4cfed 100644 --- a/exec.c +++ b/exec.c @@ -1387,9 +1387,10 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_ad= dr_t start, } =20 DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty - (ram_addr_t start, ram_addr_t length, unsigned client) +(MemoryRegion *mr, hwaddr addr, hwaddr length, unsigned client) { DirtyMemoryBlocks *blocks; + ram_addr_t start =3D memory_region_get_ram_addr(mr) + addr; unsigned long align =3D 1UL << (TARGET_PAGE_BITS + BITS_PER_LEVEL); ram_addr_t first =3D QEMU_ALIGN_DOWN(start, align); ram_addr_t last =3D QEMU_ALIGN_UP(start + length, align); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 79e70a96ee..f8ee011d3c 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -403,7 +403,7 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_= t start, unsigned client); =20 DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty - (ram_addr_t start, ram_addr_t length, unsigned client); +(MemoryRegion *mr, ram_addr_t start, hwaddr length, unsigned client); =20 bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap, ram_addr_t start, diff --git a/memory.c b/memory.c index cff0ea8f40..84bba7b65c 100644 --- a/memory.c +++ b/memory.c @@ -2071,8 +2071,7 @@ DirtyBitmapSnapshot *memory_region_snapshot_and_clear= _dirty(MemoryRegion *mr, { assert(mr->ram_block); memory_region_sync_dirty_bitmap(mr); - return cpu_physical_memory_snapshot_and_clear_dirty( - memory_region_get_ram_addr(mr) + addr, size, client); + return cpu_physical_memory_snapshot_and_clear_dirty(mr, addr, size, cl= ient); } =20 bool memory_region_snapshot_get_dirty(MemoryRegion *mr, DirtyBitmapSnapsho= t *snap, --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559209110; cv=none; d=zoho.com; s=zohoarc; b=jGO20oygEcPUq3mt53YuB9wkS4ANDUeGLzpNOL83A0xY9FJCHrJKtGEtQl60n/QNKNSzZB+knXTFE/H/GRqJtIFMlPShGykmz8wJ8friMqRpPGSuVdsTmpDgCAajZ9OOgoa1WNz0M24J/VhRc0yzE8l2FeNU0/XZBlgfe0kJnbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559209110; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lHKGC+De3cUnyK0ZNNCwMG870aTiz8DeWsD77+1P1OQ=; b=aadm1tWrlJPi/rAM7JoBItSuKvqb3BG45CbxU3ET1mJlqEFt+H6TjyK7gKs9uXrO3FDkySbEnIrYLDA5eE0+i4PAfnopXd++IqpFIwe3qdf21eLzBVZOzUjauent4z1inzZDgwJJ/CNa58GqbLAGKjMJpXzLEKYKGlHLaom6euI= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559209110448968.2612625492238; Thu, 30 May 2019 02:38:30 -0700 (PDT) Received: from localhost ([127.0.0.1]:50026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHVZ-0006rL-Vi for importer@patchew.org; Thu, 30 May 2019 05:38:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNn-0000zn-Gg for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNl-0001qX-VR for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60720) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNl-0001pN-Np for qemu-devel@nongnu.org; Thu, 30 May 2019 05:29:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18DD43001757 for ; Thu, 30 May 2019 09:29:57 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57C3A1001E86; Thu, 30 May 2019 09:29:53 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:14 +0800 Message-Id: <20190530092919.26059-8-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 30 May 2019 09:29:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 07/12] memory: Introduce memory listener hook log_clear() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce a new memory region listener hook log_clear() to allow the listeners to hook onto the points where the dirty bitmap is cleared by the bitmap users. Previously log_sync() contains two operations: - dirty bitmap collection, and, - dirty bitmap clear on remote site. Let's take KVM as example - log_sync() for KVM will first copy the kernel dirty bitmap to userspace, and at the same time we'll clear the dirty bitmap there along with re-protecting all the guest pages again. We add this new log_clear() interface only to split the old log_sync() into two separated procedures: - use log_sync() to collect the collection only, and, - use log_clear() to clear the remote dirty bitmap. With the new interface, the memory listener users will still be able to decide how to implement the log synchronization procedure, e.g., they can still only provide log_sync() method only and put all the two procedures within log_sync() (that's how the old KVM works before KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is introduced). However with this new interface the memory listener users will start to have a chance to postpone the log clear operation explicitly if the module supports. That can really benefit users like KVM at least for host kernels that support KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2. There are three places that can clear dirty bits in any one of the dirty bitmap in the ram_list.dirty_memory[3] array: cpu_physical_memory_snapshot_and_clear_dirty cpu_physical_memory_test_and_clear_dirty cpu_physical_memory_sync_dirty_bitmap Currently we hook directly into each of the functions to notify about the log_clear(). Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- exec.c | 12 ++++++++++ include/exec/memory.h | 17 ++++++++++++++ include/exec/ram_addr.h | 3 +++ memory.c | 51 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) diff --git a/exec.c b/exec.c index 2615b4cfed..ab595e1e4b 100644 --- a/exec.c +++ b/exec.c @@ -1355,6 +1355,8 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_add= r_t start, DirtyMemoryBlocks *blocks; unsigned long end, page; bool dirty =3D false; + RAMBlock *ramblock; + uint64_t mr_offset, mr_size; =20 if (length =3D=3D 0) { return false; @@ -1366,6 +1368,10 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_ad= dr_t start, rcu_read_lock(); =20 blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); + ramblock =3D qemu_get_ram_block(start); + /* Range sanity check on the ramblock */ + assert(start >=3D ramblock->offset && + start + length <=3D ramblock->offset + ramblock->used_length); =20 while (page < end) { unsigned long idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; @@ -1377,6 +1383,10 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_ad= dr_t start, page +=3D num; } =20 + mr_offset =3D (ram_addr_t)(page << TARGET_PAGE_BITS) - ramblock->offse= t; + mr_size =3D (end - page) << TARGET_PAGE_BITS; + memory_region_clear_dirty_bitmap(ramblock->mr, mr_offset, mr_size); + rcu_read_unlock(); =20 if (dirty && tcg_enabled()) { @@ -1432,6 +1442,8 @@ DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and= _clear_dirty tlb_reset_dirty_range_all(start, length); } =20 + memory_region_clear_dirty_bitmap(mr, addr, length); + return snap; } =20 diff --git a/include/exec/memory.h b/include/exec/memory.h index f29300c54d..d752b2a758 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -416,6 +416,7 @@ struct MemoryListener { void (*log_stop)(MemoryListener *listener, MemoryRegionSection *sectio= n, int old, int new); void (*log_sync)(MemoryListener *listener, MemoryRegionSection *sectio= n); + void (*log_clear)(MemoryListener *listener, MemoryRegionSection *secti= on); void (*log_global_start)(MemoryListener *listener); void (*log_global_stop)(MemoryListener *listener); void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *sec= tion, @@ -1269,6 +1270,22 @@ void memory_region_set_log(MemoryRegion *mr, bool lo= g, unsigned client); void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size); =20 +/** + * memory_region_clear_dirty_bitmap - clear dirty bitmap for memory range + * + * This function is called when the caller wants to clear the remote + * dirty bitmap of a memory range within the memory region. This can + * be used by e.g. KVM to manually clear dirty log when + * KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is declared support by the host + * kernel. + * + * @mr: the memory region to clear the dirty log upon + * @start: start address offset within the memory region + * @len: length of the memory region to clear dirty bitmap + */ +void memory_region_clear_dirty_bitmap(MemoryRegion *mr, hwaddr start, + hwaddr len); + /** * memory_region_snapshot_and_clear_dirty: Get a snapshot of the dirty * bitmap and clear it. diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index f8ee011d3c..f8930914cd 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -461,6 +461,9 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock= *rb, idx++; } } + + /* TODO: split the huge bitmap into smaller chunks */ + memory_region_clear_dirty_bitmap(rb->mr, start, length); } else { ram_addr_t offset =3D rb->offset; =20 diff --git a/memory.c b/memory.c index 84bba7b65c..a051025dd1 100644 --- a/memory.c +++ b/memory.c @@ -2064,6 +2064,57 @@ static void memory_region_sync_dirty_bitmap(MemoryRe= gion *mr) } } =20 +void memory_region_clear_dirty_bitmap(MemoryRegion *mr, hwaddr start, + hwaddr len) +{ + MemoryRegionSection mrs; + MemoryListener *listener; + AddressSpace *as; + FlatView *view; + FlatRange *fr; + hwaddr sec_start, sec_end, sec_size; + + QTAILQ_FOREACH(listener, &memory_listeners, link) { + if (!listener->log_clear) { + continue; + } + as =3D listener->address_space; + view =3D address_space_get_flatview(as); + FOR_EACH_FLAT_RANGE(fr, view) { + if (!fr->dirty_log_mask || fr->mr !=3D mr) { + /* + * Clear dirty bitmap operation only applies to those + * regions whose dirty logging is at least enabled + */ + continue; + } + + mrs =3D section_from_flat_range(fr, view); + + sec_start =3D MAX(mrs.offset_within_region, start); + sec_end =3D mrs.offset_within_region + int128_get64(mrs.size); + sec_end =3D MIN(sec_end, start + len); + + if (sec_start >=3D sec_end) { + /* + * If this memory region section has no intersection + * with the requested range, skip. + */ + continue; + } + + /* Valid case; shrink the section if needed */ + mrs.offset_within_address_space +=3D + sec_start - mrs.offset_within_region; + mrs.offset_within_region =3D sec_start; + sec_size =3D sec_end - sec_start; + mrs.size =3D int128_make64(sec_size); + listener->log_clear(listener, &mrs); + } + flatview_unref(view); + } +} + DirtyBitmapSnapshot *memory_region_snapshot_and_clear_dirty(MemoryRegion *= mr, hwaddr addr, hwaddr size, --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559209112; cv=none; d=zoho.com; s=zohoarc; b=C7aSapRFDAre7u2wbxhXKt1uXtmaBe9zb0QQtgTxr2h4O8jzB6Fh/jJOUXDRdBmdst/pfphn7aiToXlaIYkFK9bHvDlFwAKxNR25H0snTkpNgcilEA2/6b0aC6P8BoUfMqa+X3FRZg5NqZmGomHIf/8qZZ5NyMIj3RtfK4mFKgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559209112; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=og20E3wdbANUmZCjUQ92SPPWgafJrnViwGppUA3nhJU=; b=VWfudEsL+MxTEmTs78vImkprySujdmLaAs7Qy907XHmKO/mTiJjSTOt+Fl5RJHUlP2I0dPwFFFHHnZpkDtM/6BRTa/t040Rdj029x/HD6Cux40XqE/8Z3qhoVIcuDOpXKwmrwHIOggKXx4Ie6MdPaH1kGCyYPm+zXa4D5ajOI2s= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559209112209663.0806574092768; Thu, 30 May 2019 02:38:32 -0700 (PDT) Received: from localhost ([127.0.0.1]:50028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHVc-0006tx-3h for importer@patchew.org; Thu, 30 May 2019 05:38:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNp-00011h-Mq for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNo-0001uy-Qp for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNo-0001uS-Li for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 099F83005159 for ; Thu, 30 May 2019 09:30:00 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D1CB10027C7; Thu, 30 May 2019 09:29:57 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:15 +0800 Message-Id: <20190530092919.26059-9-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 30 May 2019 09:30:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 08/12] kvm: Update comments for sync_dirty_bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's obviously obsolete. Do some update. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 524c4ddfbd..b686531586 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -473,13 +473,13 @@ static int kvm_get_dirty_pages_log_range(MemoryRegion= Section *section, #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) =20 /** - * kvm_physical_sync_dirty_bitmap - Grab dirty bitmap from kernel space - * This function updates qemu's dirty bitmap using - * memory_region_set_dirty(). This means all bits are set - * to dirty. + * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * - * @start_add: start of logged region. - * @end_addr: end of logged region. + * This function will first try to fetch dirty bitmap from the kernel, + * and then updates qemu's dirty bitmap. + * + * @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) --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559208940; cv=none; d=zoho.com; s=zohoarc; b=oFYOBykFum6GE+BwX7/hYgQghYNRfgoY+t/0tJCzd5dJwdCQvTvPH2xGaQa0d36q+FSmMl6EvrhFz/ZPrfOPblYr4G81zCqkJzsSidAoecmD3TfVBpn8kPWLHVRcF5ier0CApOJ5ypKuxEtuqDFJFikSDC4RBlCv1ukHNfKzCNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559208940; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=l9tf+YRhl35k00uIIVx57FIDKmshjf7+kNkoVpLLqsw=; b=b1TZXom/87+7+/TofGy9trhNAPLTa0SqEHtXYsehjfPvHrxgq4Cyarq+5OGwSFdtp/TaqDPWDrIj+fW0GGJvMzOcG2k73SWBa+1EbeKUguL7tmyMJU2QKG0oEFfEZqeS4fZcrLO6HOcBAkoPdQo1JrqZVPjxOyC1cJbwqxZaoXg= 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 1559208940321753.0822894187336; Thu, 30 May 2019 02:35:40 -0700 (PDT) Received: from localhost ([127.0.0.1]:49975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHT8-0004dU-77 for importer@patchew.org; Thu, 30 May 2019 05:35:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHNx-000178-9f for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNw-00021c-2w for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49250) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNv-00020l-RC for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31596307D848 for ; Thu, 30 May 2019 09:30:07 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AC931001E77; Thu, 30 May 2019 09:30:00 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:16 +0800 Message-Id: <20190530092919.26059-10-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 30 May 2019 09:30:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/12] kvm: Persistent per kvmslot dirty bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When synchronizing dirty bitmap from kernel KVM we do it in a per-kvmslot fashion and we allocate the userspace bitmap for each of the ioctl. This patch instead make the bitmap cache be persistent then we don't need to g_malloc0() every time. More importantly, the cached per-kvmslot dirty bitmap will be further used when we want to add support for the KVM_CLEAR_DIRTY_LOG and this cached bitmap will be used to guarantee we won't clear any unknown dirty bits otherwise that can be a severe data loss issue for migration code. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 39 +++++++++++++++++++++------------------ include/sysemu/kvm_int.h | 2 ++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b686531586..334c610918 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -497,31 +497,14 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryLi= stener *kml, return 0; } =20 - /* XXX bad kernel interface alert - * For dirty bitmap, kernel allocates array of size aligned to - * bits-per-long. But for case when the kernel is 64bits and - * the userspace is 32bits, userspace can't align to the same - * bits-per-long, since sizeof(long) is different between kernel - * and user space. This way, userspace will provide buffer which - * may be 4 bytes less than the kernel will use, resulting in - * userspace memory corruption (which is not detectable by valgrind - * too, in most cases). - * So for now, let's align to 64 instead of HOST_LONG_BITS here, in - * a hope that sizeof(long) won't become >8 any time soon. - */ - size =3D ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), - /*HOST_LONG_BITS*/ 64) / 8; - d.dirty_bitmap =3D g_malloc0(size); - + d.dirty_bitmap =3D mem->dirty_bmap; d.slot =3D mem->slot | (kml->as_id << 16); if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) =3D=3D -1) { DPRINTF("ioctl failed %d\n", errno); - g_free(d.dirty_bitmap); return -1; } =20 kvm_get_dirty_pages_log_range(section, d.dirty_bitmap); - g_free(d.dirty_bitmap); } =20 return 0; @@ -765,6 +748,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, MemoryRegion *mr =3D section->mr; bool writeable =3D !mr->readonly && !mr->rom_device; hwaddr start_addr, size; + unsigned long bmap_size; void *ram; =20 if (!memory_region_is_ram(mr)) { @@ -796,6 +780,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, } =20 /* unregister the slot */ + g_free(mem->dirty_bmap); + mem->dirty_bmap =3D NULL; mem->memory_size =3D 0; mem->flags =3D 0; err =3D kvm_set_user_memory_region(kml, mem, false); @@ -807,12 +793,29 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, return; } =20 + /* + * XXX bad kernel interface alert For dirty bitmap, kernel + * allocates array of size aligned to bits-per-long. But for case + * when the kernel is 64bits and the userspace is 32bits, + * userspace can't align to the same bits-per-long, since + * sizeof(long) is different between kernel and user space. This + * way, userspace will provide buffer which may be 4 bytes less + * than the kernel will use, resulting in userspace memory + * corruption (which is not detectable by valgrind too, in most + * cases). So for now, let's align to 64 instead of + * HOST_LONG_BITS here, in a hope that sizeof(long) won't become + * >8 any time soon. + */ + bmap_size =3D ALIGN((size >> TARGET_PAGE_BITS), + /*HOST_LONG_BITS*/ 64) / 8; + /* register the new slot */ mem =3D kvm_alloc_slot(kml); mem->memory_size =3D size; mem->start_addr =3D start_addr; mem->ram =3D ram; mem->flags =3D kvm_mem_flags(mr); + mem->dirty_bmap =3D g_malloc0(bmap_size); =20 err =3D kvm_set_user_memory_region(kml, mem, true); if (err) { diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index f838412491..687a2ee423 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -21,6 +21,8 @@ typedef struct KVMSlot int slot; int flags; int old_flags; + /* Dirty bitmap cache for the slot */ + unsigned long *dirty_bmap; } KVMSlot; =20 typedef struct KVMMemoryListener { --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559209235; cv=none; d=zoho.com; s=zohoarc; b=V2EYn0JQVbec37NrHNTcFEkO4GSdDiqNQ5GyCMoOWBAHNJFtDJy5cd9tCL4D8B+VytrgmUmetXWMVJfgGW3lC6m8JSoCZpKxvHQFYabFktk3pXvPz/ErmNguJ42//PrKB3JALca8yohQxxS0W1Vz6WO9tdMtDgzzkuIrWESRo3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559209235; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VXUjqKl8wilJwCuZZOCyQb5NiMiFtt9uLh9KlTXgCy0=; b=V/JTvLLjuxA4JJB58enfvNppVCWymQmHRAw6howWdFdOIKclzUHu84xq2W+sRlU9Rc6OdpnKVd9dw4KmDcxnuAujamNnYcRp+FSyhU04ro+FlESu20xNFYye213drOkaB3Rsn507JL2LU/hZPpaCgJiFJTzulbcyuunsd1PVsvQ= 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 1559209235940174.76911685425227; Thu, 30 May 2019 02:40:35 -0700 (PDT) Received: from localhost ([127.0.0.1]:50050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHXt-0000EA-O8 for importer@patchew.org; Thu, 30 May 2019 05:40:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHO0-0001CD-Sx for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHNz-0002AQ-Ie for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHNy-000271-NL for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:11 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16CD53092673 for ; Thu, 30 May 2019 09:30:10 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1C321001DF6; Thu, 30 May 2019 09:30:07 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:17 +0800 Message-Id: <20190530092919.26059-11-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 30 May 2019 09:30:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 10/12] kvm: Introduce slots lock for memory listener X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce KVMMemoryListener.slots_lock to protect the slots inside the kvm memory listener. Currently it is close to useless because all the KVM code path now is always protected by the BQL. But it'll start to make sense in follow up patches where we might do remote dirty bitmap clear and also we'll update the per-slot cached dirty bitmap even without the BQL. So let's prepare for it. We can also use per-slot lock for above reason but it seems to be an overkill. Let's just use this bigger one (which covers all the slots of a single address space) but anyway this lock is still much smaller than the BQL. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- accel/kvm/kvm-all.c | 58 +++++++++++++++++++++++++++++++--------- include/sysemu/kvm_int.h | 2 ++ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 334c610918..e687060296 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -138,6 +138,9 @@ static const KVMCapabilityInfo kvm_required_capabilites= [] =3D { KVM_CAP_LAST_INFO }; =20 +#define kvm_slots_lock(kml) qemu_mutex_lock(&(kml)->slots_lock) +#define kvm_slots_unlock(kml) qemu_mutex_unlock(&(kml)->slots_lock) + int kvm_get_max_memslots(void) { KVMState *s =3D KVM_STATE(current_machine->accelerator); @@ -165,6 +168,7 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t le= n) return 1; } =20 +/* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { KVMState *s =3D kvm_state; @@ -182,10 +186,17 @@ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *= kml) bool kvm_has_free_slot(MachineState *ms) { KVMState *s =3D KVM_STATE(ms->accelerator); + bool result; + KVMMemoryListener *kml =3D &s->memory_listener; + + kvm_slots_lock(kml); + result =3D !!kvm_get_free_slot(kml); + kvm_slots_unlock(kml); =20 - return kvm_get_free_slot(&s->memory_listener); + return result; } =20 +/* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_alloc_slot(KVMMemoryListener *kml) { KVMSlot *slot =3D kvm_get_free_slot(kml); @@ -244,18 +255,21 @@ int kvm_physical_memory_addr_from_host(KVMState *s, v= oid *ram, hwaddr *phys_addr) { KVMMemoryListener *kml =3D &s->memory_listener; - int i; + int i, ret =3D 0; =20 + kvm_slots_lock(kml); for (i =3D 0; i < s->nr_slots; i++) { KVMSlot *mem =3D &kml->slots[i]; =20 if (ram >=3D mem->ram && ram < mem->ram + mem->memory_size) { *phys_addr =3D mem->start_addr + (ram - mem->ram); - return 1; + ret =3D 1; + break; } } + kvm_slots_unlock(kml); =20 - return 0; + return ret; } =20 static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slo= t, bool new) @@ -391,6 +405,7 @@ static int kvm_mem_flags(MemoryRegion *mr) return flags; } =20 +/* Called with KVMMemoryListener.slots_lock held */ static int kvm_slot_update_flags(KVMMemoryListener *kml, KVMSlot *mem, MemoryRegion *mr) { @@ -409,19 +424,26 @@ static int kvm_section_update_flags(KVMMemoryListener= *kml, { hwaddr start_addr, size; KVMSlot *mem; + int ret =3D 0; =20 size =3D kvm_align_section(section, &start_addr); if (!size) { return 0; } =20 + kvm_slots_lock(kml); + mem =3D kvm_lookup_matching_slot(kml, start_addr, size); if (!mem) { /* We don't have a slot if we want to trap every access. */ - return 0; + goto out; } =20 - return kvm_slot_update_flags(kml, mem, section->mr); + ret =3D kvm_slot_update_flags(kml, mem, section->mr); + +out: + kvm_slots_unlock(kml); + return ret; } =20 static void kvm_log_start(MemoryListener *listener, @@ -478,6 +500,8 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSe= ction *section, * This function will first try to fetch dirty bitmap from the kernel, * and then updates qemu's dirty bitmap. * + * NOTE: caller must be with kml->slots_lock held. + * * @kml: the KVM memory listener object * @section: the memory section to sync the dirty bitmap with */ @@ -488,26 +512,28 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryLi= stener *kml, struct kvm_dirty_log d =3D {}; KVMSlot *mem; hwaddr start_addr, size; + int ret =3D 0; =20 size =3D kvm_align_section(section, &start_addr); if (size) { mem =3D kvm_lookup_matching_slot(kml, start_addr, size); if (!mem) { /* We don't have a slot if we want to trap every access. */ - return 0; + goto out; } =20 d.dirty_bitmap =3D mem->dirty_bmap; d.slot =3D mem->slot | (kml->as_id << 16); if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) =3D=3D -1) { DPRINTF("ioctl failed %d\n", errno); - return -1; + ret =3D -1; + goto out; } =20 kvm_get_dirty_pages_log_range(section, d.dirty_bitmap); } - - return 0; +out: + return ret; } =20 static void kvm_coalesce_mmio_region(MemoryListener *listener, @@ -770,10 +796,12 @@ 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); + if (!add) { mem =3D kvm_lookup_matching_slot(kml, start_addr, size); if (!mem) { - return; + goto out; } if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { kvm_physical_sync_dirty_bitmap(kml, section); @@ -790,7 +818,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, __func__, strerror(-err)); abort(); } - return; + goto out; } =20 /* @@ -823,6 +851,9 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, strerror(-err)); abort(); } + +out: + kvm_slots_unlock(kml); } =20 static void kvm_region_add(MemoryListener *listener, @@ -849,7 +880,9 @@ static void kvm_log_sync(MemoryListener *listener, KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); int r; =20 + kvm_slots_lock(kml); r =3D kvm_physical_sync_dirty_bitmap(kml, section); + kvm_slots_unlock(kml); if (r < 0) { abort(); } @@ -929,6 +962,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemor= yListener *kml, { int i; =20 + 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 687a2ee423..31df465fdc 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -27,6 +27,8 @@ 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.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559209267; cv=none; d=zoho.com; s=zohoarc; b=A3FWpEgDmnsazcIDu/2dcKHdm5Um7NDUjXwaRKqcrUqb0Zi+8HbX+ZtkMi0TcRVsY6BBsNUXzyAixsm3LxqnhhozB8HUkLDlwN2KEBJpTRQXbkUgLo1mC7UygPfWxZSwgzxhIWGW28Px3/YQBnBJP6HzbGgKQtvX3xDkxQDoS78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559209267; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vkcj9Ytl3Af8GEfcvi9hUAFOqM9kB9NikAq5alt7Ctg=; b=b6cUM9xWM6f0WqvTvZrZh/Ol4nWAqG9KhouXkSeuBl0IwbSJbQq+BPHaES0OWBjWz6A6NBrU22sCYZoLHNuB5369Fuw2gvXTLdivFvTko49kZhxQcIpeV4uvhUmRV5R4FqrD27GwSq7EfIhrcl2oeGaw2w+Z7xh8JcQ7UzHb/iI= 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 1559209267100791.8417958530591; Thu, 30 May 2019 02:41:07 -0700 (PDT) Received: from localhost ([127.0.0.1]:50084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHYL-0000bA-Qo for importer@patchew.org; Thu, 30 May 2019 05:40:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHO5-0001HO-Vz for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHO4-0002FJ-0G for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53430) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHO2-0002Du-Lw for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:15 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D89503001822 for ; Thu, 30 May 2019 09:30:13 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id EED3C1001E77; Thu, 30 May 2019 09:30:10 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:18 +0800 Message-Id: <20190530092919.26059-12-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 30 May 2019 09:30:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 11/12] kvm: Support KVM_CLEAR_DIRTY_LOG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Firstly detect the interface using KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 and mark it. When failed to enable the new feature we'll fall back to the old sync. Provide the log_clear() hook for the memory listeners for both address spaces of KVM (normal system memory, and SMM) and deliever the clear message to kernel. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- accel/kvm/kvm-all.c | 180 +++++++++++++++++++++++++++++++++++++++++ accel/kvm/trace-events | 1 + 2 files changed, 181 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index e687060296..23895a95a2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -91,6 +91,7 @@ struct KVMState int many_ioeventfds; int intx_set_mask; bool sync_mmu; + bool 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 */ @@ -536,6 +537,157 @@ out: return ret; } =20 +/* Alignment requirement for KVM_CLEAR_DIRTY_LOG - 64 pages */ +#define KVM_CLEAR_LOG_SHIFT 6 +#define KVM_CLEAR_LOG_ALIGN (qemu_real_host_page_size << KVM_CLEAR_LOG_SH= IFT) +#define KVM_CLEAR_LOG_MASK (-KVM_CLEAR_LOG_ALIGN) + +/** + * kvm_physical_log_clear - Clear the kernel's dirty bitmap for range + * + * NOTE: this will be a no-op if we haven't enabled manual dirty log + * protection in the host kernel because in that case this operation + * will be done within log_sync(). + * + * @kml: the kvm memory listener + * @section: the memory range to clear dirty bitmap + */ +static int kvm_physical_log_clear(KVMMemoryListener *kml, + MemoryRegionSection *section) +{ + KVMState *s =3D kvm_state; + struct kvm_clear_dirty_log d; + uint64_t start, end, bmap_start, start_delta, bmap_npages, size; + unsigned long *bmap_clear =3D NULL, psize =3D qemu_real_host_page_size; + KVMSlot *mem =3D NULL; + int ret, i; + + if (!s->manual_dirty_log_protect) { + /* No need to do explicit clear */ + return 0; + } + + start =3D section->offset_within_address_space; + size =3D int128_get64(section->size); + + if (!size) { + /* Nothing more we can do... */ + return 0; + } + + kvm_slots_lock(kml); + + /* 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) { + break; + } + } + + /* + * 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); + + /* + * We need to extend either the start or the size or both to + * 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 psize; + + /* + * The kernel interface has restriction on the size too, that either: + * + * (1) the size is 64 host pages aligned (just like the start), or + * (2) the size fills up until the end of the KVM memslot. + */ + bmap_npages =3D DIV_ROUND_UP(size + start_delta, KVM_CLEAR_LOG_ALIGN) + << KVM_CLEAR_LOG_SHIFT; + end =3D mem->memory_size / psize; + if (bmap_npages > end - bmap_start) { + bmap_npages =3D end - bmap_start; + } + start_delta /=3D psize; + + /* + * Prepare the bitmap to clear dirty bits. Here we must guarantee + * that we won't clear any unknown dirty bits otherwise we might + * accidentally clear some set bits which are not yet synced from + * the kernel into QEMU's bitmap, then we'll lose track of the + * guest modifications upon those pages (which can directly lead + * to guest data loss or panic after migration). + * + * Layout of the KVMSlot.dirty_bmap: + * + * |<-------- bmap_npages -----------..>| + * [1] + * start_delta size + * |----------------|-------------|------------------|------------| + * ^ ^ ^ ^ + * | | | | + * start bmap_start (start) end + * of memslot of memslot + * + * [1] bmap_npages can be aligned to either 64 pages or the end of slot + */ + + assert(bmap_start % BITS_PER_LONG =3D=3D 0); + if (start_delta) { + /* Slow path - we need to manipulate a temp bitmap */ + bmap_clear =3D bitmap_new(bmap_npages); + bitmap_copy_with_src_offset(bmap_clear, mem->dirty_bmap, + bmap_start, start_delta + size / psize= ); + /* + * We need to fill the holes at start because that was not + * specified by the caller and we extended the bitmap only for + * 64 pages alignment + */ + bitmap_clear(bmap_clear, 0, start_delta); + d.dirty_bitmap =3D bmap_clear; + } else { + /* Fast path - start address aligns well with BITS_PER_LONG */ + d.dirty_bitmap =3D mem->dirty_bmap + BIT_WORD(bmap_start); + } + + d.first_page =3D bmap_start; + /* It should never overflow. If it happens, say something */ + assert(bmap_npages <=3D UINT32_MAX); + d.num_pages =3D bmap_npages; + d.slot =3D mem->slot | (kml->as_id << 16); + + if (kvm_vm_ioctl(s, KVM_CLEAR_DIRTY_LOG, &d) =3D=3D -1) { + ret =3D -errno; + error_report("%s: KVM_CLEAR_DIRTY_LOG failed, slot=3D%d, " + "start=3D0x%"PRIx64", size=3D0x%"PRIx32", errno=3D%d", + __func__, d.slot, (uint64_t)d.first_page, + (uint32_t)d.num_pages, ret); + } else { + ret =3D 0; + trace_kvm_clear_dirty_log(d.slot, d.first_page, d.num_pages); + } + + /* + * After we have updated the remote dirty bitmap, we update the + * cached bitmap as well for the memslot, then if another user + * clears the same region we know we shouldn't clear it again on + * the remote otherwise it's data loss as well. + */ + bitmap_clear(mem->dirty_bmap, bmap_start + start_delta, + size / psize); + /* This handles the NULL case well */ + g_free(bmap_clear); + + kvm_slots_unlock(kml); + + return ret; +} + static void kvm_coalesce_mmio_region(MemoryListener *listener, MemoryRegionSection *secion, hwaddr start, hwaddr size) @@ -888,6 +1040,22 @@ static void kvm_log_sync(MemoryListener *listener, } } =20 +static void kvm_log_clear(MemoryListener *listener, + MemoryRegionSection *section) +{ + KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); + int r; + + r =3D kvm_physical_log_clear(kml, section); + if (r < 0) { + error_report_once("%s: kvm log clear failed: mr=3D%s " + "offset=3D%"HWADDR_PRIx" size=3D%"PRIx64, __func= __, + section->mr->name, section->offset_within_region, + int128_get64(section->size)); + abort(); + } +} + static void kvm_mem_ioeventfd_add(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data, @@ -975,6 +1143,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemo= ryListener *kml, 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 memory_listener_register(&kml->listener, as); @@ -1699,6 +1868,17 @@ 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 + 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); + 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; + } + } + #ifdef KVM_CAP_VCPU_EVENTS s->vcpu_events =3D kvm_check_extension(s, KVM_CAP_VCPU_EVENTS); #endif diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index 33c5b1b3af..4fb6e59d19 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -15,4 +15,5 @@ kvm_irqchip_release_virq(int virq) "virq %d" kvm_set_ioeventfd_mmio(int fd, uint64_t addr, uint32_t val, bool assign, u= int32_t size, bool datamatch) "fd: %d @0x%" PRIx64 " val=3D0x%x assign: %d = size: %d match: %d" kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint32_t val, bool assign, ui= nt32_t size, bool datamatch) "fd: %d @0x%x val=3D0x%x assign: %d size: %d m= atch: %d" 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 =20 --=20 2.17.1 From nobody Sun May 19 00:17:10 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559209388; cv=none; d=zoho.com; s=zohoarc; b=PIwfBLQkzluS72GOLFc54ELJAee0Di8gJkrMmY4ML1pcCCa1dTu3LQqdiKZsn8qszcQ71MRibJkZ+G22QRabUs8zRuK8juP4a0Fl20VqFXHR8c5te30ur0qwylZ55FABrhvZ780zMDHeAzVv2GNjJ+E4ojPXWyFcRhPHMqvazm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559209388; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=yy0xo53I3/mjqk0S0lZv2X28sAr924uK5d2dxJdd6n0=; b=IKgDfWMW3JBJPK73UEeZ9MtcBYm7KuTyqpu27VigBnOrKIRhA2YlrhWwt71IY5o353sBbV4NX1uMQ+8fkowRqlhGwhkb8Q1gglGLFrjrdbIsL0/0Oe8SL/hZbyiOykJPKnPMgSCMKIl8VacFclODTO+xkW7NRP44DboFwZ6DvrM= 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 1559209388362468.1950864990888; Thu, 30 May 2019 02:43:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:50111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHaP-0002dp-AC for importer@patchew.org; Thu, 30 May 2019 05:43:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHOA-0001Lj-5O for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHO6-0002IR-SK for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHO6-0002HH-KX for qemu-devel@nongnu.org; Thu, 30 May 2019 05:30:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F015130821AE for ; Thu, 30 May 2019 09:30:17 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-221.pek2.redhat.com [10.72.12.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id A16591001E77; Thu, 30 May 2019 09:30:14 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 17:29:19 +0800 Message-Id: <20190530092919.26059-13-peterx@redhat.com> In-Reply-To: <20190530092919.26059-1-peterx@redhat.com> References: <20190530092919.26059-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 30 May 2019 09:30:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 12/12] migration: Split log_clear() into smaller chunks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently we are doing log_clear() right after log_sync() which mostly keeps the old behavior when log_clear() was still part of log_sync(). This patch tries to further optimize the migration log_clear() code path to split huge log_clear()s into smaller chunks. We do this by spliting the whole guest memory region into memory chunks, whose size is decided by MigrationState.clear_bitmap_shift (an example will be given below). With that, we don't do the dirty bitmap clear operation on the remote node (e.g., KVM) when we fetch the dirty bitmap, instead we explicitly clear the dirty bitmap for the memory chunk for each of the first time we send a page in that chunk. Here comes an example. Assuming the guest has 64G memory, then before this patch the KVM ioctl KVM_CLEAR_DIRTY_LOG will be a single one covering 64G memory. If after the patch, let's assume when the clear bitmap shift is 18, then the memory chunk size on x86_64 will be 1UL<<18 * 4K =3D 1GB. Then instead of sending a big 64G ioctl, we'll send 64 small ioctls, each of the ioctl will cover 1G of the guest memory. For each of the 64 small ioctls, we'll only send if any of the page in that small chunk was going to be sent right away. Signed-off-by: Peter Xu --- include/exec/ram_addr.h | 75 +++++++++++++++++++++++++++++++++++++++-- migration/migration.c | 4 +++ migration/migration.h | 27 +++++++++++++++ migration/ram.c | 44 ++++++++++++++++++++++++ migration/trace-events | 1 + 5 files changed, 149 insertions(+), 2 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index f8930914cd..c85896f4d5 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -50,8 +50,69 @@ struct RAMBlock { unsigned long *unsentmap; /* bitmap of already received pages in postcopy */ unsigned long *receivedmap; + + /* + * bitmap of already cleared dirty bitmap. Set this up to + * non-NULL to enable the capability to postpone and split + * clearing of dirty bitmap on the remote node (e.g., KVM). The + * bitmap will be set only when doing global sync. + * + * NOTE: this bitmap is different comparing to the other bitmaps + * in that one bit can represent multiple guest pages (which is + * decided by the `clear_bmap_shift' variable below). On + * destination side, this should always be NULL, and the variable + * `clear_bmap_shift' is meaningless. + */ + unsigned long *clear_bmap; + uint8_t clear_bmap_shift; }; =20 +/** + * clear_bmap_size: calculate clear bitmap size + * + * @pages: number of guest pages + * @shift: guest page number shift + * + * Returns: number of bits for the clear bitmap + */ +static inline long clear_bmap_size(uint64_t pages, uint8_t shift) +{ + return DIV_ROUND_UP(pages, 1UL << shift); +} + +/** + * clear_bmap_set: set clear bitmap for the page range + * + * @rb: the ramblock to operate on + * @start: the start page number + * @size: number of pages to set in the bitmap + * + * Returns: None + */ +static inline void clear_bmap_set(RAMBlock *rb, uint64_t start, + uint64_t npages) +{ + uint8_t shift =3D rb->clear_bmap_shift; + + bitmap_set_atomic(rb->clear_bmap, start >> shift, + clear_bmap_size(npages, shift)); +} + +/** + * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set + * + * @rb: the ramblock to operate on + * @page: the page number to check + * + * Returns: true if the bit was set, false otherwise + */ +static inline bool clear_bmap_test_and_clear(RAMBlock *rb, uint64_t page) +{ + uint8_t shift =3D rb->clear_bmap_shift; + + return bitmap_test_and_clear_atomic(rb->clear_bmap, page >> shift, 1); +} + static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset) { return (b && b->host && offset < b->used_length) ? true : false; @@ -462,8 +523,18 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBloc= k *rb, } } =20 - /* TODO: split the huge bitmap into smaller chunks */ - memory_region_clear_dirty_bitmap(rb->mr, start, length); + if (rb->clear_bmap) { + /* + * Postpone the dirty bitmap clear to the point before we + * really send the pages, also we will split the clear + * dirty procedure into smaller chunks. + */ + clear_bmap_set(rb, start >> TARGET_PAGE_BITS, + length >> TARGET_PAGE_BITS); + } else { + /* Slow path - still do that in a huge chunk */ + memory_region_clear_dirty_bitmap(rb->mr, start, length); + } } else { ram_addr_t offset =3D rb->offset; =20 diff --git a/migration/migration.c b/migration/migration.c index 2865ae3fa9..8a607fe1e2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3362,6 +3362,8 @@ void migration_global_dump(Monitor *mon) ms->send_section_footer ? "on" : "off"); monitor_printf(mon, "decompress-error-check: %s\n", ms->decompress_error_check ? "on" : "off"); + monitor_printf(mon, "clear-bitmap-shift: %u\n", + ms->clear_bitmap_shift); } =20 #define DEFINE_PROP_MIG_CAP(name, x) \ @@ -3376,6 +3378,8 @@ static Property migration_properties[] =3D { send_section_footer, true), DEFINE_PROP_BOOL("decompress-error-check", MigrationState, decompress_error_check, true), + DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState, + clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT), =20 /* Migration parameters */ DEFINE_PROP_UINT8("x-compress-level", MigrationState, diff --git a/migration/migration.h b/migration/migration.h index 780a096857..6e3178d8b2 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -27,6 +27,23 @@ struct PostcopyBlocktimeContext; =20 #define MIGRATION_RESUME_ACK_VALUE (1) =20 +/* + * 1<<6=3D64 pages -> 256K chunk when page size is 4K. This gives us + * the benefit that all the chunks are 64 pages aligned then the + * bitmaps are always aligned to LONG. + */ +#define CLEAR_BITMAP_SHIFT_MIN 6 +/* + * 1<<18=3D256K pages -> 1G chunk when page size is 4K. This is the + * default value to use if no one specified. + */ +#define CLEAR_BITMAP_SHIFT_DEFAULT 18 +/* + * 1<<31=3D2G pages -> 8T chunk when page size is 4K. This should be + * big enough and make sure we won't overflow easily. + */ +#define CLEAR_BITMAP_SHIFT_MAX 31 + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -233,6 +250,16 @@ struct MigrationState * do not trigger spurious decompression errors. */ bool decompress_error_check; + + /* + * This decides the size of guest memory chunk that will be used + * to track dirty bitmap clearing. The size of memory chunk will + * be GUEST_PAGE_SIZE << N. Say, N=3D0 means we will clear dirty + * bitmap for each page to send (1<<0=3D1); N=3D10 means we will clear + * dirty bitmap only once for 1<<10=3D1K continuous guest pages + * (which is in 4M chunk). + */ + uint8_t clear_bitmap_shift; }; =20 void migrate_set_state(int *state, int old_state, int new_state); diff --git a/migration/ram.c b/migration/ram.c index dc916042fb..632bf02575 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1668,6 +1668,33 @@ static inline bool migration_bitmap_clear_dirty(RAMS= tate *rs, bool ret; =20 qemu_mutex_lock(&rs->bitmap_mutex); + + /* + * Clear dirty bitmap if needed. This _must_ be called before we + * send any of the page in the chunk because we need to make sure + * we can capture further page content changes when we sync dirty + * log the next time. So as long as we are going to send any of + * the page in the chunk we clear the remote dirty bitmap for all. + * Clearing it earlier won't be a problem, but too late will. + */ + if (rb->clear_bmap && clear_bmap_test_and_clear(rb, page)) { + uint8_t shift =3D rb->clear_bmap_shift; + hwaddr size =3D 1ULL << (TARGET_PAGE_BITS + shift); + hwaddr start =3D (page << TARGET_PAGE_BITS) & (-size); + + /* + * CLEAR_BITMAP_SHIFT_MIN should always guarantee this... this + * can make things easier sometimes since then start address + * of the small chunk will always be 64 pages aligned so the + * bitmap will always be aligned to unsigned long. We should + * even be able to remove this restriction but I'm simply + * keeping it. + */ + assert(shift >=3D 6); + trace_migration_bitmap_clear_dirty(rb->idstr, start, size, page); + memory_region_clear_dirty_bitmap(rb->mr, start, size); + } + ret =3D test_and_clear_bit(page, rb->bmap); =20 if (ret) { @@ -2685,6 +2712,8 @@ static void ram_save_cleanup(void *opaque) memory_global_dirty_log_stop(); =20 RAMBLOCK_FOREACH_NOT_IGNORED(block) { + g_free(block->clear_bmap); + block->clear_bmap =3D NULL; g_free(block->bmap); block->bmap =3D NULL; g_free(block->unsentmap); @@ -3195,15 +3224,30 @@ static int ram_state_init(RAMState **rsp) =20 static void ram_list_init_bitmaps(void) { + MigrationState *ms =3D migrate_get_current(); RAMBlock *block; unsigned long pages; + uint8_t shift; =20 /* Skip setting bitmap if there is no RAM */ if (ram_bytes_total()) { + shift =3D ms->clear_bitmap_shift; + if (shift > CLEAR_BITMAP_SHIFT_MAX) { + error_report("clear_bitmap_shift (%u) too big, using " + "max value (%u)", shift, CLEAR_BITMAP_SHIFT_MAX); + shift =3D CLEAR_BITMAP_SHIFT_MAX; + } else if (shift < CLEAR_BITMAP_SHIFT_MIN) { + error_report("clear_bitmap_shift (%u) too small, using " + "min value (%u)", shift, CLEAR_BITMAP_SHIFT_MIN); + shift =3D CLEAR_BITMAP_SHIFT_MIN; + } + RAMBLOCK_FOREACH_NOT_IGNORED(block) { pages =3D block->max_length >> TARGET_PAGE_BITS; block->bmap =3D bitmap_new(pages); bitmap_set(block->bmap, 0, pages); + block->clear_bmap_shift =3D shift; + block->clear_bmap =3D bitmap_new(clear_bmap_size(pages, shift)= ); if (migrate_postcopy_ram()) { block->unsentmap =3D bitmap_new(pages); bitmap_set(block->unsentmap, 0, pages); diff --git a/migration/trace-events b/migration/trace-events index de2e136e57..2c45974330 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -79,6 +79,7 @@ get_queued_page(const char *block_name, uint64_t tmp_offs= et, unsigned long page_ get_queued_page_not_dirty(const char *block_name, uint64_t tmp_offset, uns= igned long page_abs, int sent) "%s/0x%" PRIx64 " page_abs=3D0x%lx (sent=3D%= d)" migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64 +migration_bitmap_clear_dirty(char *str, uint64_t start, uint64_t size, uns= igned long page) "rb %s start 0x%"PRIx64" size 0x%"PRIx64" page 0x%lx" migration_throttle(void) "" multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flag= s, uint32_t next_packet_size) "channel %d packet number %" PRIu64 " pages %= d flags 0x%x next packet size %d" multifd_recv_sync_main(long packet_num) "packet num %ld" --=20 2.17.1