From nobody Sun May 5 17:45:28 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=1570821580; cv=none; d=zoho.com; s=zohoarc; b=bhx/KAx4KlQ5rFpsF+Eqpp7uATkx9eRt86q9fJ8vh/QvqEudnTMpFI9Y+kpFlHIcilc1VmFsqdxLymzmHp3pKA1qvbc7qffJksupP1zFDBZTkZOD+mBR09qEP5QuJ0cbor6oyAn67ZRlxfwYnaWCvJy6p7DG9U4eivux3VN8n8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821580; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rlPnZgM3nV29wJ1YO+u6xXIiM2E6iEuFa7II6BHxseA=; b=dHkbdbguvYozaxiagwpNAL4NCnFGVjdWAtgA8bCWP8IylMml0A0CV0/WoD59cFzQhf0SUu4cUUet/xsj/Di4NJ6kcuwZMIMaKvHdOIKINyZ7BQTpA2l6pHzYZfj45dqVN7zpN1GXxaUYIaLBPf9vhW1ilsqcV4WaIO9PlUOpR3k= 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 157082158006893.96847521602535; Fri, 11 Oct 2019 12:19:40 -0700 (PDT) Received: from localhost ([::1]:56154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Ru-0002Ki-FQ for importer@patchew.org; Fri, 11 Oct 2019 15:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37393) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PL-00006p-13 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PJ-0003hK-Up for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:16:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PJ-0003gm-Or for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:16:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03E2D309843A; Fri, 11 Oct 2019 19:16:57 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE5F75D6C8; Fri, 11 Oct 2019 19:16:55 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 01/21] migration: use migration_is_active to represent active state Date: Fri, 11 Oct 2019 20:16:26 +0100 Message-Id: <20191011191646.226814-2-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 11 Oct 2019 19:16:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang Wrap the check into a function to make it easy to read. Signed-off-by: Wei Yang Message-Id: <20190717005341.14140-1-richardw.yang@linux.intel.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- include/migration/misc.h | 1 + migration/migration.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index b9d8e787af..d2762257aa 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -60,6 +60,7 @@ void migration_object_init(void); void migration_shutdown(void); void qemu_start_incoming_migration(const char *uri, Error **errp); bool migration_is_idle(void); +bool migration_is_active(MigrationState *); void add_migration_state_change_notifier(Notifier *notify); void remove_migration_state_change_notifier(Notifier *notify); bool migration_in_setup(MigrationState *); diff --git a/migration/migration.c b/migration/migration.c index 5f7e4d15e9..0c51aa6ac7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1533,8 +1533,7 @@ static void migrate_fd_cleanup(MigrationState *s) qemu_fclose(tmp); } =20 - assert((s->state !=3D MIGRATION_STATUS_ACTIVE) && - (s->state !=3D MIGRATION_STATUS_POSTCOPY_ACTIVE)); + assert(!migration_is_active(s)); =20 if (s->state =3D=3D MIGRATION_STATUS_CANCELLING) { migrate_set_state(&s->state, MIGRATION_STATUS_CANCELLING, @@ -1703,6 +1702,12 @@ bool migration_is_idle(void) return false; } =20 +bool migration_is_active(MigrationState *s) +{ + return (s->state =3D=3D MIGRATION_STATUS_ACTIVE || + s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE); +} + void migrate_init(MigrationState *s) { /* @@ -3266,8 +3271,7 @@ static void *migration_thread(void *opaque) =20 trace_migration_thread_setup_complete(); =20 - while (s->state =3D=3D MIGRATION_STATUS_ACTIVE || - s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE) { + while (migration_is_active(s)) { int64_t current_time; =20 if (urgent || !qemu_file_rate_limit(s->to_dst_file)) { --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821706; cv=none; d=zoho.com; s=zohoarc; b=HAyN2ayM0+Kvi5to2mLg7UOkTFJMy9QQPPswN7M6qscLuY8EnlOFx6kbMDZpLlEeT0v1iV7iR0oMgXjmBxhhzHCaYpkttixo8WjOqo3b5Fab68YGEfB9edphi3zd7HnkAq+MrBmxnDGbBZCxvaBHKM44rvMMeS6dKhHc8JuvEJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821706; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aRGFtAU4ivjJg8nzXUiGjPJmdgPabr/GZxOYBxl2nzo=; b=WUxkYmHhlPkTKHN4v5E033s5Siy30onLlfG0hhYSkBZ6sNLwe3AWS7ST/3RVMRZq7YV9Yoeuzky8hJBcEJMLKa8SvituoO2Vkmh6PRCL+nr+398cjEEs1TUkIKAwznydIqqi0t1xPF7U3GMjvUyAUjwkpZc4Tn4TNuObytR90Z8= 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 1570821706275200.17248137254649; Fri, 11 Oct 2019 12:21:46 -0700 (PDT) Received: from localhost ([::1]:56180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Tw-0005ZH-OU for importer@patchew.org; Fri, 11 Oct 2019 15:21:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37416) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PP-0000Aw-5o for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PL-0003ij-IM for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57948) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PL-0003iA-AK for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:16:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C5D110CC205; Fri, 11 Oct 2019 19:16:58 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D6D85D6C8; Fri, 11 Oct 2019 19:16:57 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 02/21] rcu: Add automatically released rcu_read_lock variants Date: Fri, 11 Oct 2019 20:16:27 +0100 Message-Id: <20191011191646.226814-3-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Fri, 11 Oct 2019 19:16:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" RCU_READ_LOCK_GUARD() takes the rcu_read_lock and then uses glib's g_auto infrastructure (and thus whatever the compiler's hooks are) to release it on all exits of the block. WITH_RCU_READ_LOCK_GUARD() is similar but is used as a wrapper for the lock, i.e.: WITH_RCU_READ_LOCK_GUARD() { stuff under lock } Note the 'unused' attribute is needed to work around clang bug: https://bugs.llvm.org/show_bug.cgi?id=3D43482 Signed-off-by: Dr. David Alan Gilbert Acked-by: Paolo Bonzini Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20191007143642.301445-2-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- docs/devel/rcu.txt | 16 ++++++++++++++++ include/qemu/rcu.h | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/docs/devel/rcu.txt b/docs/devel/rcu.txt index c84e7f42b2..d83fed2f79 100644 --- a/docs/devel/rcu.txt +++ b/docs/devel/rcu.txt @@ -187,6 +187,22 @@ The following APIs must be used before RCU is used in = a thread: Note that these APIs are relatively heavyweight, and should _not_ be nested. =20 +Convenience macros +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Two macros are provided that automatically release the read lock at the +end of the scope. + + RCU_READ_LOCK_GUARD() + + Takes the lock and will release it at the end of the block it's + used in. + + WITH_RCU_READ_LOCK_GUARD() { code } + + Is used at the head of a block to protect the code within the blo= ck. + +Note that 'goto'ing out of the guarded block will also drop the lock. =20 DIFFERENCES WITH LINUX =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 22876d1428..9c82683e37 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -154,6 +154,31 @@ extern void call_rcu1(struct rcu_head *head, RCUCBFunc= *func); }), \ (RCUCBFunc *)g_free); =20 +typedef void RCUReadAuto; +static inline RCUReadAuto *rcu_read_auto_lock(void) +{ + rcu_read_lock(); + /* Anything non-NULL causes the cleanup function to be called */ + return (void *)(uintptr_t)0x1; +} + +static inline void rcu_read_auto_unlock(RCUReadAuto *r) +{ + rcu_read_unlock(); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(RCUReadAuto, rcu_read_auto_unlock) + +#define WITH_RCU_READ_LOCK_GUARD() \ + WITH_RCU_READ_LOCK_GUARD_(_rcu_read_auto##__COUNTER__) + +#define WITH_RCU_READ_LOCK_GUARD_(var) \ + for (g_autoptr(RCUReadAuto) var =3D rcu_read_auto_lock(); \ + (var); rcu_read_auto_unlock(var), (var) =3D NULL) + +#define RCU_READ_LOCK_GUARD() \ + g_autoptr(RCUReadAuto) _rcu_read_auto __attribute__((unused)) =3D rcu_= read_auto_lock() + #ifdef __cplusplus } #endif --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821846; cv=none; d=zoho.com; s=zohoarc; b=SN/qwzYjNMKN3xqiVds6pdwY42CyQwel3wVdntk010x0LuL6GPW3/p39K0rdmbHk7iU0P0hV1Spbe092uWXe/bzxYb2mGsypx1zHvd7p1Om+odO9MicaEEyQypQW7tc3lcENvj/FER6dxCeixrRKYndTGeDcSUsJHfzVnSv112o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821846; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aFN2JlQWiUOum+SLL2YrwORl/TeZAANvZ0/R8acTN+o=; b=W9H2j4soVTVKNpoSgVDq9miuiwlhR2hEkFSxxQRxDWbiTSgO6sT790MBDbfatyYtDg89r7ORRu0KXBp0fbdA29A1agJ892uzOjfo35csA0/kGQ1cYADZmpz1Rmx1by/yy0WEeMOv/5bkK3Rh25ytDS1n07e2XuJ98K4RL5/pX7s= 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 1570821846728377.5703057493869; Fri, 11 Oct 2019 12:24:06 -0700 (PDT) Received: from localhost ([::1]:56210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0WC-0000hP-Sb for importer@patchew.org; Fri, 11 Oct 2019 15:24:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37446) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PS-0000Ca-3d for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PQ-0003kb-W0 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PO-0003jC-Ux for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AED981DF7; Fri, 11 Oct 2019 19:17:00 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id C21AE5D6C8; Fri, 11 Oct 2019 19:16:58 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 03/21] migration: Fix missing rcu_read_unlock Date: Fri, 11 Oct 2019 20:16:28 +0100 Message-Id: <20191011191646.226814-4-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 11 Oct 2019 19:17:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Use the automatic rcu_read unlocker to fix a missing unlock. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20191007143642.301445-3-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 22423f08cd..484d66379a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3373,24 +3373,23 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } (*rsp)->f =3D f; =20 - rcu_read_lock(); - - qemu_put_be64(f, ram_bytes_total_common(true) | RAM_SAVE_FLAG_MEM_SIZE= ); + WITH_RCU_READ_LOCK_GUARD() { + qemu_put_be64(f, ram_bytes_total_common(true) | RAM_SAVE_FLAG_MEM_= SIZE); =20 - RAMBLOCK_FOREACH_MIGRATABLE(block) { - qemu_put_byte(f, strlen(block->idstr)); - qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); - qemu_put_be64(f, block->used_length); - if (migrate_postcopy_ram() && block->page_size !=3D qemu_host_page= _size) { - qemu_put_be64(f, block->page_size); - } - if (migrate_ignore_shared()) { - qemu_put_be64(f, block->mr->addr); + RAMBLOCK_FOREACH_MIGRATABLE(block) { + qemu_put_byte(f, strlen(block->idstr)); + qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idst= r)); + qemu_put_be64(f, block->used_length); + if (migrate_postcopy_ram() && block->page_size !=3D + qemu_host_page_size) { + qemu_put_be64(f, block->page_size); + } + if (migrate_ignore_shared()) { + qemu_put_be64(f, block->mr->addr); + } } } =20 - rcu_read_unlock(); - ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822051; cv=none; d=zoho.com; s=zohoarc; b=olHYrmecGwTLywyfTXl+uQbp6JRsYrgT7Ldg//UCPfdT+9nbkSlAh5ABTRh57GDjC/dSG8zyLcQZrUArgcm63Nby7e4FBV5QWUE454S4C78OLD58McPaj9DHNLbm/qUEDRkt87xXeO53e9MU0E+V1Tb8MOsfqHS/Z8O9FLlYM6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822051; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JGLxfxrQ0yKbC6OMgA+hNjUHCkuuTfR0yFUB0TP2mv8=; b=BUM2+HSXEQeuX3wMesQs9+r7KIkBhf2kncY5psDs8WzTeZFm9me8shM4zsL5OlLdce4labRkqfX3fVniwgxDxBvTKVR2MpsYlupNQd/D7ZLeJWG11AC5RDQA+bzDxf2me67ZfYVamEYT8FmaFjhW+urBWg9WemLe6L+ocgM9zWA= 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 1570822051889296.1837917445969; Fri, 11 Oct 2019 12:27:31 -0700 (PDT) Received: from localhost ([::1]:56240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0ZW-0004Yp-6l for importer@patchew.org; Fri, 11 Oct 2019 15:27:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37482) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PU-0000E2-19 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PR-0003kp-1o for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PP-0003jf-0v for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70ACA10CC205; Fri, 11 Oct 2019 19:17:01 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 437615D71C; Fri, 11 Oct 2019 19:17:00 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 04/21] migration: Use automatic rcu_read unlock in ram.c Date: Fri, 11 Oct 2019 20:16:29 +0100 Message-Id: <20191011191646.226814-5-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Fri, 11 Oct 2019 19:17:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Use the automatic read unlocker in migration/ram.c Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20191007143642.301445-4-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 259 ++++++++++++++++++++++-------------------------- 1 file changed, 121 insertions(+), 138 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 484d66379a..e29c8b3408 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -181,14 +181,14 @@ int foreach_not_ignored_block(RAMBlockIterFunc func, = void *opaque) RAMBlock *block; int ret =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); + RAMBLOCK_FOREACH_NOT_IGNORED(block) { ret =3D func(block, opaque); if (ret) { break; } } - rcu_read_unlock(); return ret; } =20 @@ -1848,12 +1848,12 @@ static void migration_bitmap_sync(RAMState *rs) memory_global_dirty_log_sync(); =20 qemu_mutex_lock(&rs->bitmap_mutex); - rcu_read_lock(); - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - ramblock_sync_dirty_bitmap(rs, block); + WITH_RCU_READ_LOCK_GUARD() { + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + ramblock_sync_dirty_bitmap(rs, block); + } + ram_counters.remaining =3D ram_bytes_remaining(); } - ram_counters.remaining =3D ram_bytes_remaining(); - rcu_read_unlock(); qemu_mutex_unlock(&rs->bitmap_mutex); =20 memory_global_after_dirty_log_sync(); @@ -2397,13 +2397,12 @@ static void migration_page_queue_free(RAMState *rs) /* This queue generally should be empty - but in the case of a failed * migration might have some droppings in. */ - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); QSIMPLEQ_FOREACH_SAFE(mspr, &rs->src_page_requests, next_req, next_msp= r) { memory_region_unref(mspr->rb->mr); QSIMPLEQ_REMOVE_HEAD(&rs->src_page_requests, next_req); g_free(mspr); } - rcu_read_unlock(); } =20 /** @@ -2424,7 +2423,8 @@ int ram_save_queue_pages(const char *rbname, ram_addr= _t start, ram_addr_t len) RAMState *rs =3D ram_state; =20 ram_counters.postcopy_requests++; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); + if (!rbname) { /* Reuse last RAMBlock */ ramblock =3D rs->last_req_rb; @@ -2466,12 +2466,10 @@ int ram_save_queue_pages(const char *rbname, ram_ad= dr_t start, ram_addr_t len) QSIMPLEQ_INSERT_TAIL(&rs->src_page_requests, new_entry, next_req); migration_make_urgent_request(); qemu_mutex_unlock(&rs->src_page_req_mutex); - rcu_read_unlock(); =20 return 0; =20 err: - rcu_read_unlock(); return -1; } =20 @@ -2700,7 +2698,8 @@ static uint64_t ram_bytes_total_common(bool count_ign= ored) RAMBlock *block; uint64_t total =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); + if (count_ignored) { RAMBLOCK_FOREACH_MIGRATABLE(block) { total +=3D block->used_length; @@ -2710,7 +2709,6 @@ static uint64_t ram_bytes_total_common(bool count_ign= ored) total +=3D block->used_length; } } - rcu_read_unlock(); return total; } =20 @@ -3034,7 +3032,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *= ms) RAMBlock *block; int ret; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); =20 /* This should be our last sync, the src is now paused */ migration_bitmap_sync(rs); @@ -3048,7 +3046,6 @@ int ram_postcopy_send_discard_bitmap(MigrationState *= ms) /* Deal with TPS !=3D HPS and huge pages */ ret =3D postcopy_chunk_hostpages(ms, block); if (ret) { - rcu_read_unlock(); return ret; } =20 @@ -3060,7 +3057,6 @@ int ram_postcopy_send_discard_bitmap(MigrationState *= ms) trace_ram_postcopy_send_discard_bitmap(); =20 ret =3D postcopy_each_ram_send_discard(ms); - rcu_read_unlock(); =20 return ret; } @@ -3081,7 +3077,7 @@ int ram_discard_range(const char *rbname, uint64_t st= art, size_t length) =20 trace_ram_discard_range(rbname, start, length); =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); RAMBlock *rb =3D qemu_ram_block_by_name(rbname); =20 if (!rb) { @@ -3101,8 +3097,6 @@ int ram_discard_range(const char *rbname, uint64_t st= art, size_t length) ret =3D ram_block_discard_range(rb, start, length); =20 err: - rcu_read_unlock(); - return ret; } =20 @@ -3231,13 +3225,12 @@ static void ram_init_bitmaps(RAMState *rs) /* For memory_global_dirty_log_start below. */ qemu_mutex_lock_iothread(); qemu_mutex_lock_ramlist(); - rcu_read_lock(); =20 - ram_list_init_bitmaps(); - memory_global_dirty_log_start(); - migration_bitmap_sync_precopy(rs); - - rcu_read_unlock(); + WITH_RCU_READ_LOCK_GUARD() { + ram_list_init_bitmaps(); + memory_global_dirty_log_start(); + migration_bitmap_sync_precopy(rs); + } qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_iothread(); } @@ -3424,55 +3417,57 @@ static int ram_save_iterate(QEMUFile *f, void *opaq= ue) goto out; } =20 - rcu_read_lock(); - if (ram_list.version !=3D rs->last_version) { - ram_state_reset(rs); - } - - /* Read version before ram_list.blocks */ - smp_rmb(); + WITH_RCU_READ_LOCK_GUARD() { + if (ram_list.version !=3D rs->last_version) { + ram_state_reset(rs); + } =20 - ram_control_before_iterate(f, RAM_CONTROL_ROUND); + /* Read version before ram_list.blocks */ + smp_rmb(); =20 - t0 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - i =3D 0; - while ((ret =3D qemu_file_rate_limit(f)) =3D=3D 0 || - !QSIMPLEQ_EMPTY(&rs->src_page_requests)) { - int pages; + ram_control_before_iterate(f, RAM_CONTROL_ROUND); =20 - if (qemu_file_get_error(f)) { - break; - } + t0 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + i =3D 0; + while ((ret =3D qemu_file_rate_limit(f)) =3D=3D 0 || + !QSIMPLEQ_EMPTY(&rs->src_page_requests)) { + int pages; =20 - pages =3D ram_find_and_save_block(rs, false); - /* no more pages to sent */ - if (pages =3D=3D 0) { - done =3D 1; - break; - } + if (qemu_file_get_error(f)) { + break; + } =20 - if (pages < 0) { - qemu_file_set_error(f, pages); - break; - } + pages =3D ram_find_and_save_block(rs, false); + /* no more pages to sent */ + if (pages =3D=3D 0) { + done =3D 1; + break; + } =20 - rs->target_page_count +=3D pages; - - /* we want to check in the 1st loop, just in case it was the 1st t= ime - and we had to sync the dirty bitmap. - qemu_clock_get_ns() is a bit expensive, so we only check each s= ome - iterations - */ - if ((i & 63) =3D=3D 0) { - uint64_t t1 =3D (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - t0) = / 1000000; - if (t1 > MAX_WAIT) { - trace_ram_save_iterate_big_wait(t1, i); + if (pages < 0) { + qemu_file_set_error(f, pages); break; } + + rs->target_page_count +=3D pages; + + /* + * we want to check in the 1st loop, just in case it was the 1= st + * time and we had to sync the dirty bitmap. + * qemu_clock_get_ns() is a bit expensive, so we only check ea= ch + * some iterations + */ + if ((i & 63) =3D=3D 0) { + uint64_t t1 =3D (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - = t0) / + 1000000; + if (t1 > MAX_WAIT) { + trace_ram_save_iterate_big_wait(t1, i); + break; + } + } + i++; } - i++; } - rcu_read_unlock(); =20 /* * Must occur before EOS (or any QEMUFile operation) @@ -3510,35 +3505,33 @@ static int ram_save_complete(QEMUFile *f, void *opa= que) RAMState *rs =3D *temp; int ret =3D 0; =20 - rcu_read_lock(); - - if (!migration_in_postcopy()) { - migration_bitmap_sync_precopy(rs); - } + WITH_RCU_READ_LOCK_GUARD() { + if (!migration_in_postcopy()) { + migration_bitmap_sync_precopy(rs); + } =20 - ram_control_before_iterate(f, RAM_CONTROL_FINISH); + ram_control_before_iterate(f, RAM_CONTROL_FINISH); =20 - /* try transferring iterative blocks of memory */ + /* try transferring iterative blocks of memory */ =20 - /* flush all remaining blocks regardless of rate limiting */ - while (true) { - int pages; + /* flush all remaining blocks regardless of rate limiting */ + while (true) { + int pages; =20 - pages =3D ram_find_and_save_block(rs, !migration_in_colo_state()); - /* no more blocks to sent */ - if (pages =3D=3D 0) { - break; - } - if (pages < 0) { - ret =3D pages; - break; + pages =3D ram_find_and_save_block(rs, !migration_in_colo_state= ()); + /* no more blocks to sent */ + if (pages =3D=3D 0) { + break; + } + if (pages < 0) { + ret =3D pages; + break; + } } - } - - flush_compressed_data(rs); - ram_control_after_iterate(f, RAM_CONTROL_FINISH); =20 - rcu_read_unlock(); + flush_compressed_data(rs); + ram_control_after_iterate(f, RAM_CONTROL_FINISH); + } =20 multifd_send_sync_main(rs); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); @@ -3561,9 +3554,9 @@ static void ram_save_pending(QEMUFile *f, void *opaqu= e, uint64_t max_size, if (!migration_in_postcopy() && remaining_size < max_size) { qemu_mutex_lock_iothread(); - rcu_read_lock(); - migration_bitmap_sync_precopy(rs); - rcu_read_unlock(); + WITH_RCU_READ_LOCK_GUARD() { + migration_bitmap_sync_precopy(rs); + } qemu_mutex_unlock_iothread(); remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SIZE; } @@ -3907,7 +3900,13 @@ int colo_init_ram_cache(void) error_report("%s: Can't alloc memory for COLO cache of block %= s," "size 0x" RAM_ADDR_FMT, __func__, block->idstr, block->used_length); - goto out_locked; + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + if (block->colo_cache) { + qemu_anon_ram_free(block->colo_cache, block->used_leng= th); + block->colo_cache =3D NULL; + } + } + return -errno; } memcpy(block->colo_cache, block->host, block->used_length); } @@ -3933,18 +3932,6 @@ int colo_init_ram_cache(void) memory_global_dirty_log_start(); =20 return 0; - -out_locked: - - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - if (block->colo_cache) { - qemu_anon_ram_free(block->colo_cache, block->used_length); - block->colo_cache =3D NULL; - } - } - - rcu_read_unlock(); - return -errno; } =20 /* It is need to hold the global lock to call this helper */ @@ -3958,16 +3945,14 @@ void colo_release_ram_cache(void) block->bmap =3D NULL; } =20 - rcu_read_lock(); - - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - if (block->colo_cache) { - qemu_anon_ram_free(block->colo_cache, block->used_length); - block->colo_cache =3D NULL; + WITH_RCU_READ_LOCK_GUARD() { + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + if (block->colo_cache) { + qemu_anon_ram_free(block->colo_cache, block->used_length); + block->colo_cache =3D NULL; + } } } - - rcu_read_unlock(); qemu_mutex_destroy(&ram_state->bitmap_mutex); g_free(ram_state); ram_state =3D NULL; @@ -4205,31 +4190,30 @@ static void colo_flush_ram_cache(void) unsigned long offset =3D 0; =20 memory_global_dirty_log_sync(); - rcu_read_lock(); - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - ramblock_sync_dirty_bitmap(ram_state, block); + WITH_RCU_READ_LOCK_GUARD() { + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + ramblock_sync_dirty_bitmap(ram_state, block); + } } - rcu_read_unlock(); =20 trace_colo_flush_ram_cache_begin(ram_state->migration_dirty_pages); - rcu_read_lock(); - block =3D QLIST_FIRST_RCU(&ram_list.blocks); + WITH_RCU_READ_LOCK_GUARD() { + block =3D QLIST_FIRST_RCU(&ram_list.blocks); =20 - while (block) { - offset =3D migration_bitmap_find_dirty(ram_state, block, offset); + while (block) { + offset =3D migration_bitmap_find_dirty(ram_state, block, offse= t); =20 - if (offset << TARGET_PAGE_BITS >=3D block->used_length) { - offset =3D 0; - block =3D QLIST_NEXT_RCU(block, next); - } else { - migration_bitmap_clear_dirty(ram_state, block, offset); - dst_host =3D block->host + (offset << TARGET_PAGE_BITS); - src_host =3D block->colo_cache + (offset << TARGET_PAGE_BITS); - memcpy(dst_host, src_host, TARGET_PAGE_SIZE); + if (offset << TARGET_PAGE_BITS >=3D block->used_length) { + offset =3D 0; + block =3D QLIST_NEXT_RCU(block, next); + } else { + migration_bitmap_clear_dirty(ram_state, block, offset); + dst_host =3D block->host + (offset << TARGET_PAGE_BITS); + src_host =3D block->colo_cache + (offset << TARGET_PAGE_BI= TS); + memcpy(dst_host, src_host, TARGET_PAGE_SIZE); + } } } - - rcu_read_unlock(); trace_colo_flush_ram_cache_end(); } =20 @@ -4428,16 +4412,15 @@ static int ram_load(QEMUFile *f, void *opaque, int = version_id) * it will be necessary to reduce the granularity of this * critical section. */ - rcu_read_lock(); + WITH_RCU_READ_LOCK_GUARD() { + if (postcopy_running) { + ret =3D ram_load_postcopy(f); + } else { + ret =3D ram_load_precopy(f); + } =20 - if (postcopy_running) { - ret =3D ram_load_postcopy(f); - } else { - ret =3D ram_load_precopy(f); + ret |=3D wait_for_decompress_done(); } - - ret |=3D wait_for_decompress_done(); - rcu_read_unlock(); trace_ram_load_complete(ret, seq_iter); =20 if (!ret && migration_incoming_in_colo_state()) { --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821722; cv=none; d=zoho.com; s=zohoarc; b=YAcgMFcfJ6rxVXQO1mvDXr1L6MNry3T9soeDvIE5LUeaWEe0m2CNZb5DpcowUSnofBeepiqsua7RF1qKUrAFJ1I3H5N5vghrDJ16j3NU5N8RqruidGc4YExhU7ZtI8qjdpuG6nhjVYXcnvRz9F5Z/MXTBl7bibXlnZOcMPiJorw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821722; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7lfkcNyJlgc3UkwR7SVVsxDPvk80g5Pa4uFrThBA+RU=; b=b18Q91Tuclnc3tqa+X8ywy+9fWrRjMMDN48KdUDqAxZjTByArL0AQD5UhoG3uF6cO1vO1MO4rnSNuWEPehXaKLTWlXq7dyNPMo33Ku7UUwplezirZ9zTKGA/PAnyjehMPstwEjTc65L+KtjVatRFw0iILYGd12fFpZN6LJaOjrM= 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 1570821722732404.7561986977263; Fri, 11 Oct 2019 12:22:02 -0700 (PDT) Received: from localhost ([::1]:56184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0UD-00060i-1c for importer@patchew.org; Fri, 11 Oct 2019 15:22:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37468) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PT-0000Di-4T for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PR-0003lC-A5 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4628) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PQ-0003k1-Vi for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5FCBC057EC0; Fri, 11 Oct 2019 19:17:02 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA02C5D6C8; Fri, 11 Oct 2019 19:17:01 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 05/21] migration: Use automatic rcu_read unlock in rdma.c Date: Fri, 11 Oct 2019 20:16:30 +0100 Message-Id: <20191011191646.226814-6-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 11 Oct 2019 19:17:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Use the automatic read unlocker in migration/rdma.c. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20191007143642.301445-5-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/rdma.c | 57 ++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 4c74e88a37..e241dcb992 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -88,7 +88,6 @@ static uint32_t known_capabilities =3D RDMA_CAPABILITY_PI= N_ALL; " to abort!"); \ rdma->error_reported =3D 1; \ } \ - rcu_read_unlock(); \ return rdma->error_state; \ } \ } while (0) @@ -2678,11 +2677,10 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *= ioc, size_t i; size_t len =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmaout); =20 if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 @@ -2695,7 +2693,6 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, ret =3D qemu_rdma_write_flush(f, rdma); if (ret < 0) { rdma->error_state =3D ret; - rcu_read_unlock(); return ret; } =20 @@ -2715,7 +2712,6 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, =20 if (ret < 0) { rdma->error_state =3D ret; - rcu_read_unlock(); return ret; } =20 @@ -2724,7 +2720,6 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, } } =20 - rcu_read_unlock(); return done; } =20 @@ -2764,11 +2759,10 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *i= oc, ssize_t i; size_t done =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmain); =20 if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 @@ -2805,7 +2799,6 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, =20 if (ret < 0) { rdma->error_state =3D ret; - rcu_read_unlock(); return ret; } =20 @@ -2819,14 +2812,12 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *i= oc, /* Still didn't get enough, so lets just return */ if (want) { if (done =3D=3D 0) { - rcu_read_unlock(); return QIO_CHANNEL_ERR_BLOCK; } else { break; } } } - rcu_read_unlock(); return done; } =20 @@ -2882,7 +2873,7 @@ qio_channel_rdma_source_prepare(GSource *source, GIOCondition cond =3D 0; *timeout =3D -1; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); if (rsource->condition =3D=3D G_IO_IN) { rdma =3D atomic_rcu_read(&rsource->rioc->rdmain); } else { @@ -2891,7 +2882,6 @@ qio_channel_rdma_source_prepare(GSource *source, =20 if (!rdma) { error_report("RDMAContext is NULL when prepare Gsource"); - rcu_read_unlock(); return FALSE; } =20 @@ -2900,7 +2890,6 @@ qio_channel_rdma_source_prepare(GSource *source, } cond |=3D G_IO_OUT; =20 - rcu_read_unlock(); return cond & rsource->condition; } =20 @@ -2911,7 +2900,7 @@ qio_channel_rdma_source_check(GSource *source) RDMAContext *rdma; GIOCondition cond =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); if (rsource->condition =3D=3D G_IO_IN) { rdma =3D atomic_rcu_read(&rsource->rioc->rdmain); } else { @@ -2920,7 +2909,6 @@ qio_channel_rdma_source_check(GSource *source) =20 if (!rdma) { error_report("RDMAContext is NULL when check Gsource"); - rcu_read_unlock(); return FALSE; } =20 @@ -2929,7 +2917,6 @@ qio_channel_rdma_source_check(GSource *source) } cond |=3D G_IO_OUT; =20 - rcu_read_unlock(); return cond & rsource->condition; } =20 @@ -2943,7 +2930,7 @@ qio_channel_rdma_source_dispatch(GSource *source, RDMAContext *rdma; GIOCondition cond =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); if (rsource->condition =3D=3D G_IO_IN) { rdma =3D atomic_rcu_read(&rsource->rioc->rdmain); } else { @@ -2952,7 +2939,6 @@ qio_channel_rdma_source_dispatch(GSource *source, =20 if (!rdma) { error_report("RDMAContext is NULL when dispatch Gsource"); - rcu_read_unlock(); return FALSE; } =20 @@ -2961,7 +2947,6 @@ qio_channel_rdma_source_dispatch(GSource *source, } cond |=3D G_IO_OUT; =20 - rcu_read_unlock(); return (*func)(QIO_CHANNEL(rsource->rioc), (cond & rsource->condition), user_data); @@ -3073,7 +3058,7 @@ qio_channel_rdma_shutdown(QIOChannel *ioc, QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); RDMAContext *rdmain, *rdmaout; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); =20 rdmain =3D atomic_rcu_read(&rioc->rdmain); rdmaout =3D atomic_rcu_read(&rioc->rdmain); @@ -3100,7 +3085,6 @@ qio_channel_rdma_shutdown(QIOChannel *ioc, break; } =20 - rcu_read_unlock(); return 0; } =20 @@ -3146,18 +3130,16 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void= *opaque, RDMAContext *rdma; int ret; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmaout); =20 if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 CHECK_ERROR_STATE(); =20 if (migration_in_postcopy()) { - rcu_read_unlock(); return RAM_SAVE_CONTROL_NOT_SUPP; } =20 @@ -3242,11 +3224,9 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void = *opaque, } } =20 - rcu_read_unlock(); return RAM_SAVE_CONTROL_DELAYED; err: rdma->error_state =3D ret; - rcu_read_unlock(); return ret; } =20 @@ -3470,11 +3450,10 @@ static int qemu_rdma_registration_handle(QEMUFile *= f, void *opaque) int count =3D 0; int i =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmain); =20 if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 @@ -3717,7 +3696,6 @@ out: if (ret < 0) { rdma->error_state =3D ret; } - rcu_read_unlock(); return ret; } =20 @@ -3735,11 +3713,10 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc= , const char *name) int curr; int found =3D -1; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmain); =20 if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 @@ -3753,7 +3730,6 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc, = const char *name) =20 if (found =3D=3D -1) { error_report("RAMBlock '%s' not found on destination", name); - rcu_read_unlock(); return -ENOENT; } =20 @@ -3761,7 +3737,6 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc, = const char *name) trace_rdma_block_notification_handle(name, rdma->next_src_index); rdma->next_src_index++; =20 - rcu_read_unlock(); return 0; } =20 @@ -3786,17 +3761,15 @@ static int qemu_rdma_registration_start(QEMUFile *f= , void *opaque, QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(opaque); RDMAContext *rdma; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmaout); if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 CHECK_ERROR_STATE(); =20 if (migration_in_postcopy()) { - rcu_read_unlock(); return 0; } =20 @@ -3804,7 +3777,6 @@ static int qemu_rdma_registration_start(QEMUFile *f, = void *opaque, qemu_put_be64(f, RAM_SAVE_FLAG_HOOK); qemu_fflush(f); =20 - rcu_read_unlock(); return 0; } =20 @@ -3821,17 +3793,15 @@ static int qemu_rdma_registration_stop(QEMUFile *f,= void *opaque, RDMAControlHeader head =3D { .len =3D 0, .repeat =3D 1 }; int ret =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); rdma =3D atomic_rcu_read(&rioc->rdmaout); if (!rdma) { - rcu_read_unlock(); return -EIO; } =20 CHECK_ERROR_STATE(); =20 if (migration_in_postcopy()) { - rcu_read_unlock(); return 0; } =20 @@ -3863,7 +3833,6 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, qemu_rdma_reg_whole_ram_blocks : NULL); if (ret < 0) { ERROR(errp, "receiving remote info!"); - rcu_read_unlock(); return ret; } =20 @@ -3887,7 +3856,6 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, "not identical on both the source and destination.= ", local->nb_blocks, nb_dest_blocks); rdma->error_state =3D -EINVAL; - rcu_read_unlock(); return -EINVAL; } =20 @@ -3904,7 +3872,6 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, local->block[i].length, rdma->dest_blocks[i].length); rdma->error_state =3D -EINVAL; - rcu_read_unlock(); return -EINVAL; } local->block[i].remote_host_addr =3D @@ -3922,11 +3889,9 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, goto err; } =20 - rcu_read_unlock(); return 0; err: rdma->error_state =3D ret; - rcu_read_unlock(); return ret; } =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822180; cv=none; d=zoho.com; s=zohoarc; b=Xh2gU4U8jf4FrrEP0M4GepA+851SnJ+362RU5Du3AxUuuQR5D/q7k2WkNeAhMMpJdK/QdfqniuyOyds1Y4MYx6PnORI+0PsVraxt5zCJ//GooAm0kUESZ4dUkqlW1FU/rNG6tDHcYmS9FNVbaTxuFTQfaozGbMyXUTdSLdlPopc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822180; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d4hTURUHiv+0MnEcYC1jTpZVqzcoXNXhNLSRIiM8j/w=; b=LusF+uBxsSGjhLij9s97/uhm7sKZfms7y/2nj//JEd48Ot8mo+Tmqykb6KSnTk3jsySWeSNb9FZ8dyJqmsA2OojMdFsIhbUHmE2mVcV7aFCta7Xxhw4gYRxHhOZiqdXIw7NJbD3LdZWZBER/2gt5nYhqLj0PwG5yKROOKBKrFJY= 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 1570822180743919.4780639261807; Fri, 11 Oct 2019 12:29:40 -0700 (PDT) Received: from localhost ([::1]:56266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0ba-0007cF-3Z for importer@patchew.org; Fri, 11 Oct 2019 15:29:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37487) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PU-0000E4-2J for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PR-0003lU-KX for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43482) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PR-0003kQ-BQ for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F546745A1; Fri, 11 Oct 2019 19:17:04 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CF555D6C8; Fri, 11 Oct 2019 19:17:03 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 06/21] rcu: Use automatic rc_read unlock in core memory/exec code Date: Fri, 11 Oct 2019 20:16:31 +0100 Message-Id: <20191011191646.226814-7-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 11 Oct 2019 19:17:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20191007143642.301445-6-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- exec.c | 116 ++++++++++++++------------------- include/exec/ram_addr.h | 138 +++++++++++++++++++--------------------- memory.c | 15 ++--- 3 files changed, 118 insertions(+), 151 deletions(-) diff --git a/exec.c b/exec.c index bdcfcdff3f..fb0943cfed 100644 --- a/exec.c +++ b/exec.c @@ -1037,16 +1037,14 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwad= dr addr, MemTxAttrs attrs) return; } =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); mr =3D address_space_translate(as, addr, &addr, &l, false, attrs); if (!(memory_region_is_ram(mr) || memory_region_is_romd(mr))) { - rcu_read_unlock(); return; } ram_addr =3D memory_region_get_ram_addr(mr) + addr; tb_invalidate_phys_page_range(ram_addr, ram_addr + 1); - rcu_read_unlock(); } =20 static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) @@ -1332,14 +1330,13 @@ static void tlb_reset_dirty_range_all(ram_addr_t st= art, ram_addr_t length) end =3D TARGET_PAGE_ALIGN(start + length); start &=3D TARGET_PAGE_MASK; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); block =3D qemu_get_ram_block(start); assert(block =3D=3D qemu_get_ram_block(end - 1)); start1 =3D (uintptr_t)ramblock_ptr(block, start - block->offset); CPU_FOREACH(cpu) { tlb_reset_dirty(cpu, start1, length); } - rcu_read_unlock(); } =20 /* Note: start and end must be within the same ram block. */ @@ -1360,30 +1357,29 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_a= ddr_t start, end =3D TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; page =3D start >> TARGET_PAGE_BITS; =20 - rcu_read_lock(); + WITH_RCU_READ_LOCK_GUARD() { + 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_lengt= h); =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); + while (page < end) { + unsigned long idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; + unsigned long offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; + unsigned long num =3D MIN(end - page, + DIRTY_MEMORY_BLOCK_SIZE - offset); =20 - while (page < end) { - unsigned long idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; - unsigned long offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; - unsigned long num =3D MIN(end - page, DIRTY_MEMORY_BLOCK_SIZE - of= fset); + dirty |=3D bitmap_test_and_clear_atomic(blocks->blocks[idx], + offset, num); + page +=3D num; + } =20 - dirty |=3D bitmap_test_and_clear_atomic(blocks->blocks[idx], - offset, num); - page +=3D num; + mr_offset =3D (ram_addr_t)(page << TARGET_PAGE_BITS) - ramblock->o= ffset; + mr_size =3D (end - page) << TARGET_PAGE_BITS; + memory_region_clear_dirty_bitmap(ramblock->mr, mr_offset, mr_size); } =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(); - if (dirty && tcg_enabled()) { tlb_reset_dirty_range_all(start, length); } @@ -1411,28 +1407,27 @@ DirtyBitmapSnapshot *cpu_physical_memory_snapshot_a= nd_clear_dirty end =3D last >> TARGET_PAGE_BITS; dest =3D 0; =20 - rcu_read_lock(); + WITH_RCU_READ_LOCK_GUARD() { + blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); =20 - blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); + while (page < end) { + unsigned long idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; + unsigned long offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; + unsigned long num =3D MIN(end - page, + DIRTY_MEMORY_BLOCK_SIZE - offset); =20 - while (page < end) { - unsigned long idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; - unsigned long offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; - unsigned long num =3D MIN(end - page, DIRTY_MEMORY_BLOCK_SIZE - of= fset); - - assert(QEMU_IS_ALIGNED(offset, (1 << BITS_PER_LEVEL))); - assert(QEMU_IS_ALIGNED(num, (1 << BITS_PER_LEVEL))); - offset >>=3D BITS_PER_LEVEL; + assert(QEMU_IS_ALIGNED(offset, (1 << BITS_PER_LEVEL))); + assert(QEMU_IS_ALIGNED(num, (1 << BITS_PER_LEVEL))); + offset >>=3D BITS_PER_LEVEL; =20 - bitmap_copy_and_clear_atomic(snap->dirty + dest, - blocks->blocks[idx] + offset, - num); - page +=3D num; - dest +=3D num >> BITS_PER_LEVEL; + bitmap_copy_and_clear_atomic(snap->dirty + dest, + blocks->blocks[idx] + offset, + num); + page +=3D num; + dest +=3D num >> BITS_PER_LEVEL; + } } =20 - rcu_read_unlock(); - if (tcg_enabled()) { tlb_reset_dirty_range_all(start, length); } @@ -1643,7 +1638,7 @@ void ram_block_dump(Monitor *mon) RAMBlock *block; char *psize; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); monitor_printf(mon, "%24s %8s %18s %18s %18s\n", "Block Name", "PSize", "Offset", "Used", "Total"); RAMBLOCK_FOREACH(block) { @@ -1655,7 +1650,6 @@ void ram_block_dump(Monitor *mon) (uint64_t)block->max_length); g_free(psize); } - rcu_read_unlock(); } =20 #ifdef __linux__ @@ -2009,11 +2003,10 @@ static unsigned long last_ram_page(void) RAMBlock *block; ram_addr_t last =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); RAMBLOCK_FOREACH(block) { last =3D MAX(last, block->offset + block->max_length); } - rcu_read_unlock(); return last >> TARGET_PAGE_BITS; } =20 @@ -2100,7 +2093,7 @@ void qemu_ram_set_idstr(RAMBlock *new_block, const ch= ar *name, DeviceState *dev) } pstrcat(new_block->idstr, sizeof(new_block->idstr), name); =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); RAMBLOCK_FOREACH(block) { if (block !=3D new_block && !strcmp(block->idstr, new_block->idstr)) { @@ -2109,7 +2102,6 @@ void qemu_ram_set_idstr(RAMBlock *new_block, const ch= ar *name, DeviceState *dev) abort(); } } - rcu_read_unlock(); } =20 /* Called with iothread lock held. */ @@ -2651,17 +2643,16 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool = round_offset, =20 if (xen_enabled()) { ram_addr_t ram_addr; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); ram_addr =3D xen_ram_addr_from_mapcache(ptr); block =3D qemu_get_ram_block(ram_addr); if (block) { *offset =3D ram_addr - block->offset; } - rcu_read_unlock(); return block; } =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); block =3D atomic_rcu_read(&ram_list.mru_block); if (block && block->host && host - block->host < block->max_length) { goto found; @@ -2677,7 +2668,6 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool ro= und_offset, } } =20 - rcu_read_unlock(); return NULL; =20 found: @@ -2685,7 +2675,6 @@ found: if (round_offset) { *offset &=3D TARGET_PAGE_MASK; } - rcu_read_unlock(); return block; } =20 @@ -3281,10 +3270,9 @@ MemTxResult address_space_read_full(AddressSpace *as= , hwaddr addr, FlatView *fv; =20 if (len > 0) { - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); fv =3D address_space_to_flatview(as); result =3D flatview_read(fv, addr, attrs, buf, len); - rcu_read_unlock(); } =20 return result; @@ -3298,10 +3286,9 @@ MemTxResult address_space_write(AddressSpace *as, hw= addr addr, FlatView *fv; =20 if (len > 0) { - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); fv =3D address_space_to_flatview(as); result =3D flatview_write(fv, addr, attrs, buf, len); - rcu_read_unlock(); } =20 return result; @@ -3341,7 +3328,7 @@ static inline MemTxResult address_space_write_rom_int= ernal(AddressSpace *as, hwaddr addr1; MemoryRegion *mr; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); while (len > 0) { l =3D len; mr =3D address_space_translate(as, addr, &addr1, &l, true, attrs); @@ -3366,7 +3353,6 @@ static inline MemTxResult address_space_write_rom_int= ernal(AddressSpace *as, buf +=3D l; addr +=3D l; } - rcu_read_unlock(); return MEMTX_OK; } =20 @@ -3511,10 +3497,9 @@ bool address_space_access_valid(AddressSpace *as, hw= addr addr, FlatView *fv; bool result; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); fv =3D address_space_to_flatview(as); result =3D flatview_access_valid(fv, addr, len, is_write, attrs); - rcu_read_unlock(); return result; } =20 @@ -3569,13 +3554,12 @@ void *address_space_map(AddressSpace *as, } =20 l =3D len; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); fv =3D address_space_to_flatview(as); mr =3D flatview_translate(fv, addr, &xlat, &l, is_write, attrs); =20 if (!memory_access_is_direct(mr, is_write)) { if (atomic_xchg(&bounce.in_use, true)) { - rcu_read_unlock(); return NULL; } /* Avoid unbounded allocations */ @@ -3591,7 +3575,6 @@ void *address_space_map(AddressSpace *as, bounce.buffer, l); } =20 - rcu_read_unlock(); *plen =3D l; return bounce.buffer; } @@ -3601,7 +3584,6 @@ void *address_space_map(AddressSpace *as, *plen =3D flatview_extend_translation(fv, addr, len, mr, xlat, l, is_write, attrs); ptr =3D qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); - rcu_read_unlock(); =20 return ptr; } @@ -3869,13 +3851,12 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr) hwaddr l =3D 1; bool res; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); mr =3D address_space_translate(&address_space_memory, phys_addr, &phys_addr, &l, false, MEMTXATTRS_UNSPECIFIED); =20 res =3D !(memory_region_is_ram(mr) || memory_region_is_romd(mr)); - rcu_read_unlock(); return res; } =20 @@ -3884,14 +3865,13 @@ int qemu_ram_foreach_block(RAMBlockIterFunc func, v= oid *opaque) RAMBlock *block; int ret =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); RAMBLOCK_FOREACH(block) { ret =3D func(block, opaque); if (ret) { break; } } - rcu_read_unlock(); return ret; } =20 diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index e96e621de5..ad158bb247 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -193,30 +193,29 @@ static inline bool cpu_physical_memory_get_dirty(ram_= addr_t start, end =3D TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; page =3D start >> TARGET_PAGE_BITS; =20 - rcu_read_lock(); - - blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); + WITH_RCU_READ_LOCK_GUARD() { + blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); + + idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; + offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; + base =3D page - offset; + while (page < end) { + unsigned long next =3D MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE= ); + unsigned long num =3D next - base; + unsigned long found =3D find_next_bit(blocks->blocks[idx], + num, offset); + if (found < num) { + dirty =3D true; + break; + } =20 - idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; - offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; - base =3D page - offset; - while (page < end) { - unsigned long next =3D MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE); - unsigned long num =3D next - base; - unsigned long found =3D find_next_bit(blocks->blocks[idx], num, of= fset); - if (found < num) { - dirty =3D true; - break; + page =3D next; + idx++; + offset =3D 0; + base +=3D DIRTY_MEMORY_BLOCK_SIZE; } - - page =3D next; - idx++; - offset =3D 0; - base +=3D DIRTY_MEMORY_BLOCK_SIZE; } =20 - rcu_read_unlock(); - return dirty; } =20 @@ -234,7 +233,7 @@ static inline bool cpu_physical_memory_all_dirty(ram_ad= dr_t start, end =3D TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; page =3D start >> TARGET_PAGE_BITS; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); =20 blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); =20 @@ -256,8 +255,6 @@ static inline bool cpu_physical_memory_all_dirty(ram_ad= dr_t start, base +=3D DIRTY_MEMORY_BLOCK_SIZE; } =20 - rcu_read_unlock(); - return dirty; } =20 @@ -309,13 +306,11 @@ static inline void cpu_physical_memory_set_dirty_flag= (ram_addr_t addr, idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); =20 blocks =3D atomic_rcu_read(&ram_list.dirty_memory[client]); =20 set_bit_atomic(offset, blocks->blocks[idx]); - - rcu_read_unlock(); } =20 static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, @@ -334,39 +329,37 @@ static inline void cpu_physical_memory_set_dirty_rang= e(ram_addr_t start, end =3D TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; page =3D start >> TARGET_PAGE_BITS; =20 - rcu_read_lock(); + WITH_RCU_READ_LOCK_GUARD() { + for (i =3D 0; i < DIRTY_MEMORY_NUM; i++) { + blocks[i] =3D atomic_rcu_read(&ram_list.dirty_memory[i]); + } =20 - for (i =3D 0; i < DIRTY_MEMORY_NUM; i++) { - blocks[i] =3D atomic_rcu_read(&ram_list.dirty_memory[i]); - } + idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; + offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; + base =3D page - offset; + while (page < end) { + unsigned long next =3D MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE= ); =20 - idx =3D page / DIRTY_MEMORY_BLOCK_SIZE; - offset =3D page % DIRTY_MEMORY_BLOCK_SIZE; - base =3D page - offset; - while (page < end) { - unsigned long next =3D MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE); + if (likely(mask & (1 << DIRTY_MEMORY_MIGRATION))) { + bitmap_set_atomic(blocks[DIRTY_MEMORY_MIGRATION]->blocks[i= dx], + offset, next - page); + } + if (unlikely(mask & (1 << DIRTY_MEMORY_VGA))) { + bitmap_set_atomic(blocks[DIRTY_MEMORY_VGA]->blocks[idx], + offset, next - page); + } + if (unlikely(mask & (1 << DIRTY_MEMORY_CODE))) { + bitmap_set_atomic(blocks[DIRTY_MEMORY_CODE]->blocks[idx], + offset, next - page); + } =20 - if (likely(mask & (1 << DIRTY_MEMORY_MIGRATION))) { - bitmap_set_atomic(blocks[DIRTY_MEMORY_MIGRATION]->blocks[idx], - offset, next - page); + page =3D next; + idx++; + offset =3D 0; + base +=3D DIRTY_MEMORY_BLOCK_SIZE; } - if (unlikely(mask & (1 << DIRTY_MEMORY_VGA))) { - bitmap_set_atomic(blocks[DIRTY_MEMORY_VGA]->blocks[idx], - offset, next - page); - } - if (unlikely(mask & (1 << DIRTY_MEMORY_CODE))) { - bitmap_set_atomic(blocks[DIRTY_MEMORY_CODE]->blocks[idx], - offset, next - page); - } - - page =3D next; - idx++; - offset =3D 0; - base +=3D DIRTY_MEMORY_BLOCK_SIZE; } =20 - rcu_read_unlock(); - xen_hvm_modified_memory(start, length); } =20 @@ -396,36 +389,35 @@ static inline void cpu_physical_memory_set_dirty_lebi= tmap(unsigned long *bitmap, offset =3D BIT_WORD((start >> TARGET_PAGE_BITS) % DIRTY_MEMORY_BLOCK_SIZE); =20 - rcu_read_lock(); + WITH_RCU_READ_LOCK_GUARD() { + for (i =3D 0; i < DIRTY_MEMORY_NUM; i++) { + blocks[i] =3D atomic_rcu_read(&ram_list.dirty_memory[i])->= blocks; + } =20 - for (i =3D 0; i < DIRTY_MEMORY_NUM; i++) { - blocks[i] =3D atomic_rcu_read(&ram_list.dirty_memory[i])->bloc= ks; - } + for (k =3D 0; k < nr; k++) { + if (bitmap[k]) { + unsigned long temp =3D leul_to_cpu(bitmap[k]); =20 - for (k =3D 0; k < nr; k++) { - if (bitmap[k]) { - unsigned long temp =3D leul_to_cpu(bitmap[k]); + atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp= ); =20 - atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp); + if (global_dirty_log) { + atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][off= set], + temp); + } =20 - if (global_dirty_log) { - atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset], - temp); + if (tcg_enabled()) { + atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset], + temp); + } } =20 - if (tcg_enabled()) { - atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset], tem= p); + if (++offset >=3D BITS_TO_LONGS(DIRTY_MEMORY_BLOCK_SIZE)) { + offset =3D 0; + idx++; } } - - if (++offset >=3D BITS_TO_LONGS(DIRTY_MEMORY_BLOCK_SIZE)) { - offset =3D 0; - idx++; - } } =20 - rcu_read_unlock(); - xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS); } else { uint8_t clients =3D tcg_enabled() ? DIRTY_CLIENTS_ALL : DIRTY_CLIE= NTS_NOCODE; diff --git a/memory.c b/memory.c index 978da3d3df..c952eabb5d 100644 --- a/memory.c +++ b/memory.c @@ -779,14 +779,13 @@ FlatView *address_space_get_flatview(AddressSpace *as) { FlatView *view; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); do { view =3D address_space_to_flatview(as); /* If somebody has replaced as->current_map concurrently, * flatview_ref returns false. */ } while (!flatview_ref(view)); - rcu_read_unlock(); return view; } =20 @@ -2166,12 +2165,11 @@ int memory_region_get_fd(MemoryRegion *mr) { int fd; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); while (mr->alias) { mr =3D mr->alias; } fd =3D mr->ram_block->fd; - rcu_read_unlock(); =20 return fd; } @@ -2181,14 +2179,13 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr) void *ptr; uint64_t offset =3D 0; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); while (mr->alias) { offset +=3D mr->alias_offset; mr =3D mr->alias; } assert(mr->ram_block); ptr =3D qemu_map_ram_ptr(mr->ram_block, offset); - rcu_read_unlock(); =20 return ptr; } @@ -2578,12 +2575,11 @@ MemoryRegionSection memory_region_find(MemoryRegion= *mr, hwaddr addr, uint64_t size) { MemoryRegionSection ret; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); ret =3D memory_region_find_rcu(mr, addr, size); if (ret.mr) { memory_region_ref(ret.mr); } - rcu_read_unlock(); return ret; } =20 @@ -2591,9 +2587,8 @@ bool memory_region_present(MemoryRegion *container, h= waddr addr) { MemoryRegion *mr; =20 - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); mr =3D memory_region_find_rcu(container, addr, 1).mr; - rcu_read_unlock(); return mr && mr !=3D container; } =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821577; cv=none; d=zoho.com; s=zohoarc; b=hQ28Ks8SwWYphpkTRLsZp+juG9wiLmowqBHVIGcFUlXmuCWDJcPdJ+E+IU0KUrTCWOL9BIMuIODHCUv7Clx2IvnlqsEvXPyMPF/bA9Btmy+Jp0zlTAaoihcT9sXpVsIY5yp/sP24HAuQQvRQ680Vjd/5YajCql7TWpdV4VgaYjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821577; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aBAhpBkJxL5TqECc3axrI6xeqcumrDNsVTm0WuYpvZ8=; b=FHJEKHFj0qgxHhUTYIl2QI2aDzafxGMqa070Nm7b99yozUKgU2vhZ+NWXtQwFiyYGU6ZX2kptZuLkjG15JcHKU5pvWo1p9TDdgP7YNuNfE5Rx3EVOQKVc+LqVNoShArjPqnApaOEto+F08Itab/gYnPV1w2JjF21OTv0VClW7lw= 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 1570821577181964.042562681895; Fri, 11 Oct 2019 12:19:37 -0700 (PDT) Received: from localhost ([::1]:56152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Rp-0002DO-6L for importer@patchew.org; Fri, 11 Oct 2019 15:19:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37496) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PU-0000ER-Ou for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PT-0003nQ-KF for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29015) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PS-0003m3-Pj for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E7CF883850; Fri, 11 Oct 2019 19:17:06 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7D1B5D6C8; Fri, 11 Oct 2019 19:17:04 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 07/21] migration: Don't try and recover return path in non-postcopy Date: Fri, 11 Oct 2019 20:16:32 +0100 Message-Id: <20191011191646.226814-8-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 11 Oct 2019 19:17:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" In normal precopy we can't do reconnection recovery - but we also don't need to, since you can just rerun migration. At the moment if the 'return-path' capability is on, we use the return path in precopy to give a positive 'OK' to the end of migration; however if migration fails then we fall into the postcopy recovery path and hang. This fixes it by only running the return path in the postcopy case. Reported-by: Greg Kurz Tested-by: Greg Kurz Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 0c51aa6ac7..d7f8b428e0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2486,7 +2486,7 @@ retry: out: res =3D qemu_file_get_error(rp); if (res) { - if (res =3D=3D -EIO) { + if (res =3D=3D -EIO && migration_in_postcopy()) { /* * Maybe there is something we can do: it looks like a * network down issue, and we pause for a recovery. --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821654; cv=none; d=zoho.com; s=zohoarc; b=STHMwuJ8Jla5orXppmRWnAsuhlEhzJ7enP4ifLuC7/MmRWsDDe41xHUaho4vdu7axA/fRkbOimkwA5n+S4zTiBNQTh2KLEA7ie7hTdb28RZSSPQWCqx35MVSf58JH4ZnXaVExYFr9F4JsrjDS66FYg11ryohoz98M7gvkEJENP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821654; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1FyTkDt4osKVRJXprKwvkpm7ycf39a7KPp5Eq9W6Jos=; b=efqGpy0SMgpGka+HVcmfdncSFK6OVJV+58LEgX/MSxKdle1gKK5KmFwO1FB+lJFouTVhNr59CSaGi3CgV9KqwLQWV206jmlEfYuZdc/FWVyoC8OD9XIZsaqhQBdavDUN9YFWU3m0eFnaV6jcBHfQfYCaMV621YawzKcOYVmJqIw= 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 1570821654789231.2865667604375; Fri, 11 Oct 2019 12:20:54 -0700 (PDT) Received: from localhost ([::1]:56172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0T5-00048b-48 for importer@patchew.org; Fri, 11 Oct 2019 15:20:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37520) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PW-0000GR-4b for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PU-0003oR-Ur for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PU-0003nW-LF for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 829CE18CB8F0; Fri, 11 Oct 2019 19:17:07 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58E7C5D784; Fri, 11 Oct 2019 19:17:06 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 08/21] migration/postcopy: allocate tmp_page in setup stage Date: Fri, 11 Oct 2019 20:16:33 +0100 Message-Id: <20191011191646.226814-9-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Fri, 11 Oct 2019 19:17:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang During migration, a tmp page is allocated so that we could place a whole host page during postcopy. Currently the page is allocated during load stage, this is a little bit late. And more important, if we failed to allocate it, the error is not checked properly. Even it is NULL, we would still use it. This patch moves the allocation to setup stage and if failed error message would be printed and caller would notice it. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 40 ++++++++++------------------------------ migration/postcopy-ram.h | 7 ------- migration/ram.c | 2 +- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 1f63e65ed7..9a16f52a79 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1134,6 +1134,16 @@ int postcopy_ram_enable_notify(MigrationIncomingStat= e *mis) return -1; } =20 + mis->postcopy_tmp_page =3D mmap(NULL, mis->largest_page_size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | + MAP_ANONYMOUS, -1, 0); + if (mis->postcopy_tmp_page =3D=3D MAP_FAILED) { + mis->postcopy_tmp_page =3D NULL; + error_report("%s: Failed to map postcopy_tmp_page %s", + __func__, strerror(errno)); + return -1; + } + /* * Ballooning can mark pages as absent while we're postcopying * that would cause false userfaults. @@ -1260,30 +1270,6 @@ int postcopy_place_page_zero(MigrationIncomingState = *mis, void *host, } } =20 -/* - * Returns a target page of memory that can be mapped at a later point in = time - * using postcopy_place_page - * The same address is used repeatedly, postcopy_place_page just takes the - * backing page away. - * Returns: Pointer to allocated page - * - */ -void *postcopy_get_tmp_page(MigrationIncomingState *mis) -{ - if (!mis->postcopy_tmp_page) { - mis->postcopy_tmp_page =3D mmap(NULL, mis->largest_page_size, - PROT_READ | PROT_WRITE, MAP_PRIVATE | - MAP_ANONYMOUS, -1, 0); - if (mis->postcopy_tmp_page =3D=3D MAP_FAILED) { - mis->postcopy_tmp_page =3D NULL; - error_report("%s: %s", __func__, strerror(errno)); - return NULL; - } - } - - return mis->postcopy_tmp_page; -} - #else /* No target OS support, stubs just fail */ void fill_destination_postcopy_migration_info(MigrationInfo *info) @@ -1341,12 +1327,6 @@ int postcopy_place_page_zero(MigrationIncomingState = *mis, void *host, return -1; } =20 -void *postcopy_get_tmp_page(MigrationIncomingState *mis) -{ - assert(0); - return NULL; -} - int postcopy_wake_shared(struct PostCopyFD *pcfd, uint64_t client_addr, RAMBlock *rb) diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 9c8bd2bae0..fb4cd11d28 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -100,13 +100,6 @@ typedef enum { POSTCOPY_INCOMING_END } PostcopyState; =20 -/* - * Allocate a page of memory that can be mapped at a later point in time - * using postcopy_place_page - * Returns: Pointer to allocated page - */ -void *postcopy_get_tmp_page(MigrationIncomingState *mis); - PostcopyState postcopy_state_get(void); /* Set the state and return the old state */ PostcopyState postcopy_state_set(PostcopyState new_state); diff --git a/migration/ram.c b/migration/ram.c index e29c8b3408..071687ef37 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4032,7 +4032,7 @@ static int ram_load_postcopy(QEMUFile *f) bool matches_target_page_size =3D false; MigrationIncomingState *mis =3D migration_incoming_get_current(); /* Temporary page that is later 'placed' */ - void *postcopy_host_page =3D postcopy_get_tmp_page(mis); + void *postcopy_host_page =3D mis->postcopy_tmp_page; void *last_host =3D NULL; bool all_zero =3D false; =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821769; cv=none; d=zoho.com; s=zohoarc; b=UAdTHs5oeIOgSewxTIAwiAKZEW280+FkE+t4T8Q00pMdUaKBJBnJZr7VznGxGVzaYKDCHzgkklqoLAdzuR6cb6iIMoQMUkVp6YiWiwOTtPdJxoME6+m+f80MMINEUq+wFhgFmK3SEvNb5sGq4nb+yfqgYJAz0BSQBDbf6l8JXcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821769; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tY5o5sBfLafR51Q1YVY76/hcnfLvuaVggmgGddTJ8Mg=; b=lAXMfxk55WmBokho5/7SlUJJvFeLH6Msilv7xQGMDHQaykk2OspQysSuDRI2TEXC98AtXiHCU2PpHuUG8B3bId/BghJ60W55+oG6w6PRaENr84ieWvPs0HUOs7x4vOm5fsRGzgamVs2AXmX0MsSkFffTt4lPoEC92/FsZ3osrPw= 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 1570821769823104.21363063755405; Fri, 11 Oct 2019 12:22:49 -0700 (PDT) Received: from localhost ([::1]:56188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Uy-0007Fx-9M for importer@patchew.org; Fri, 11 Oct 2019 15:22:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37542) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0PZ-0000I1-Jq for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0PY-0003qO-FN for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0PY-0003pu-7G for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 794E1C05AA63; Fri, 11 Oct 2019 19:17:11 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAC3A5D6C8; Fri, 11 Oct 2019 19:17:07 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 09/21] migration/postcopy: map large zero page in postcopy_ram_incoming_setup() Date: Fri, 11 Oct 2019 20:16:34 +0100 Message-Id: <20191011191646.226814-10-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 11 Oct 2019 19:17:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang postcopy_ram_incoming_setup() and postcopy_ram_incoming_cleanup() are counterpart. It is reasonable to map/unmap large zero page in these two functions respectively. Signed-off-by: Wei Yang Message-Id: <20191005135021.21721-3-richardw.yang@linux.intel.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 9a16f52a79..08a3ed516e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1144,6 +1144,22 @@ int postcopy_ram_enable_notify(MigrationIncomingStat= e *mis) return -1; } =20 + /* + * Map large zero page when kernel can't use UFFDIO_ZEROPAGE for hugep= ages + */ + mis->postcopy_tmp_zero_page =3D mmap(NULL, mis->largest_page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (mis->postcopy_tmp_zero_page =3D=3D MAP_FAILED) { + int e =3D errno; + mis->postcopy_tmp_zero_page =3D NULL; + error_report("%s: Failed to map large zero page %s", + __func__, strerror(e)); + return -e; + } + memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size); + /* * Ballooning can mark pages as absent while we're postcopying * that would cause false userfaults. @@ -1250,23 +1266,7 @@ int postcopy_place_page_zero(MigrationIncomingState = *mis, void *host, qemu_ram_block_host_offset(rb, host= )); } else { - /* The kernel can't use UFFDIO_ZEROPAGE for hugepages */ - if (!mis->postcopy_tmp_zero_page) { - mis->postcopy_tmp_zero_page =3D mmap(NULL, mis->largest_page_s= ize, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, 0); - if (mis->postcopy_tmp_zero_page =3D=3D MAP_FAILED) { - int e =3D errno; - mis->postcopy_tmp_zero_page =3D NULL; - error_report("%s: %s mapping large zero page", - __func__, strerror(e)); - return -e; - } - memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_si= ze); - } - return postcopy_place_page(mis, host, mis->postcopy_tmp_zero_page, - rb); + return postcopy_place_page(mis, host, mis->postcopy_tmp_zero_page,= rb); } } =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822387; cv=none; d=zoho.com; s=zohoarc; b=SHnlAiWpYT4TS/Dsd/1/4eFQ+CFC+KCihRNRqIhKEBbvAkxADbbndN1zLWrbKA3R20NujIR0kLIV6E8gvEgmXJfIQsj9tncCC9FrNk4WgMhyoKPmVMiKZXbDmYMR9MGBeQXkxIFP5DSO4f/b/Is+4DhJUbuW/98jOEBWxWwyDI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822387; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ins+vq1fdP2NCT3NCXwZ98oItZsPlC2UylSmefRbEQE=; b=SOmww/Vw1l+CvPaamQt5GmA5X/IqLdmk6oMskVVF21D38uPF3qxoknQj+3VEdZXWlb0Rh7L5tyTCebmc/cwSEM2cN+lGPDWEv5OqNBKEV8BxxRzdTahF/TEXxN6UD5Wg3hvbj0VRGcovCVTj2SlBsfaySW4cwJoWi/MTojxQuFA= 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 1570822387947156.32790094582867; Fri, 11 Oct 2019 12:33:07 -0700 (PDT) Received: from localhost ([::1]:56314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0eu-0002Gd-JT for importer@patchew.org; Fri, 11 Oct 2019 15:33:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37563) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pe-0000Oq-Ad for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pd-0003sn-7T for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50684) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pd-0003s5-26 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92F94306729E; Fri, 11 Oct 2019 19:17:15 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id C23695D6C8; Fri, 11 Oct 2019 19:17:11 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 10/21] migration/postcopy: fix typo in mark_postcopy_blocktime_begin's comment Date: Fri, 11 Oct 2019 20:16:35 +0100 Message-Id: <20191011191646.226814-11-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 11 Oct 2019 19:17:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang Signed-off-by: Wei Yang Message-Id: <20191005220517.24029-3-richardw.yang@linux.intel.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 08a3ed516e..3a72f7b4fe 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -768,9 +768,11 @@ static void mark_postcopy_blocktime_begin(uintptr_t ad= dr, uint32_t ptid, atomic_xchg(&dc->page_fault_vcpu_time[cpu], low_time_offset); atomic_xchg(&dc->vcpu_addr[cpu], addr); =20 - /* check it here, not at the begining of the function, - * due to, check could accur early than bitmap_set in - * qemu_ufd_copy_ioctl */ + /* + * check it here, not at the beginning of the function, + * due to, check could occur early than bitmap_set in + * qemu_ufd_copy_ioctl + */ already_received =3D ramblock_recv_bitmap_test(rb, (void *)addr); if (already_received) { atomic_xchg(&dc->vcpu_addr[cpu], 0); --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821793; cv=none; d=zoho.com; s=zohoarc; b=JJLzh10/ccAh16BVDTlD8XcssYkNalsjQCWyQqXh3L0Sgl3jK5PzNK2lVYpju31TkveHuaqGbZHDDe3Hi1XxDUi1+B8cddhBWP3N3yr6Jwi/TrvY6kaldbWEd+7+CZkjwe64ao8ElAYbfAmY3aIPkyXm6GYzp7cylCAhwu604NM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821793; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+cjH1EbCyyuhzWoZOccAswZXGlPVn0FMsdZun4NTI20=; b=ErIRcmkgWf9F97aTnIJssKhNeux0KiFFfyaija8QHTuSRM3uKVd+SrmOMKPL+W1cGtiyUYzqXvSs7ZgmDvj8VjYD6kKSw3VI7Lwv9my/TxgjOjd51+YKNHpu/SSwlTQ05bFne/dcZbyaepdgBYvvETFoXAIuKsykynY6XuFzjio= 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 1570821793592268.8498601202731; Fri, 11 Oct 2019 12:23:13 -0700 (PDT) Received: from localhost ([::1]:56198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0VM-0007tf-7Q for importer@patchew.org; Fri, 11 Oct 2019 15:23:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37578) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pf-0000QR-8H for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pe-0003tZ-7X for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42948) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pe-0003t0-1N for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 169F810DCCA6; Fri, 11 Oct 2019 19:17:17 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCD845D6C8; Fri, 11 Oct 2019 19:17:15 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 11/21] migration: pass in_postcopy instead of check state again Date: Fri, 11 Oct 2019 20:16:36 +0100 Message-Id: <20191011191646.226814-12-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Fri, 11 Oct 2019 19:17:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang Not necessary to do the check again. Signed-off-by: Wei Yang Message-Id: <20191005220517.24029-4-richardw.yang@linux.intel.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index d7f8b428e0..3febd0f8f3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3149,8 +3149,7 @@ static MigIterateState migration_iteration_run(Migrat= ionState *s) return MIG_ITERATE_SKIP; } /* Just another iteration step */ - qemu_savevm_state_iterate(s->to_dst_file, - s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE); + qemu_savevm_state_iterate(s->to_dst_file, in_postcopy); } else { trace_migration_thread_low_pending(pending_size); migration_completion(s); --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821880; cv=none; d=zoho.com; s=zohoarc; b=VbAsnwEtjzzrMx2iD8L99RXdMLVcEbQFuYD2GvVm0zuN/sN/6diru9N6xzClkXPns6kNSHkMWFGjvav5O83Q7zHuG13xqmhMJAEFW4ZP4qziQqzzM/tKvd1pUccq8XRo1mlcVdGu4Ck+5WB4U9DeXIcTRyUQR8IloB7pnMa/OgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821880; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XTPWcKVSTkDEdaLIlDGlSxqtJ9iY6yRw0H6LtDmbzg0=; b=hR/GKuTJHsw7XmAuktwKUPPDwk80GZi8pNT7foJeJJpXu+met9HHk/z/lBzvSaf0HlCXntSIRAXQhuDvtWsTnYk4EdRl1cab9qtWoGMZYg08L7kFQoSOpItq5Am+lCa2UVclsE/7GZYnJ7UciehNRg+4pr0NKvMG0uHETsz4tnA= 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 1570821880636571.8011507998788; Fri, 11 Oct 2019 12:24:40 -0700 (PDT) Received: from localhost ([::1]:56214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Wf-0001C7-MF for importer@patchew.org; Fri, 11 Oct 2019 15:24:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37592) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pg-0000Sp-Ji for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pf-0003ur-G2 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pf-0003u3-AW for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CAEE83F3D; Fri, 11 Oct 2019 19:17:18 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E6DA5D6C8; Fri, 11 Oct 2019 19:17:17 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 12/21] migration: report SaveStateEntry id and name on failure Date: Fri, 11 Oct 2019 20:16:37 +0100 Message-Id: <20191011191646.226814-13-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 11 Oct 2019 19:17:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang This provides helpful information on which entry failed. Signed-off-by: Wei Yang Message-Id: <20191005220517.24029-5-richardw.yang@linux.intel.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Dr. David Alan Gilbert --- migration/savevm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index bb9462a54d..241c5dd097 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1215,6 +1215,8 @@ int qemu_savevm_state_iterate(QEMUFile *f, bool postc= opy) save_section_footer(f, se); =20 if (ret < 0) { + error_report("failed to save SaveStateEntry with id(name): %d(= %s)", + se->section_id, se->idstr); qemu_file_set_error(f, ret); } if (ret <=3D 0) { --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822570; cv=none; d=zoho.com; s=zohoarc; b=Tr1lIcV92zUs2OsnPLUB9RdpUg/xklej409W03jychm/BUSOxaeoWnfojJBDG9h46hTddR3HWlUAQLL0eVzE+XI1XQmG0XT4yZIlq8tSgK7vfmaWt2gzDnNMQ9wUE/vhiCLgw4Gkg6LntFC+Mlu7guKfXnz2y2JnN+hvxiAALmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822570; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=74JnMIP+LyHPupX5F7nLgqToRRe8Wzcoqkm9jEJjN2Y=; b=N/L6I82KclOoPPyGA1YaqKmP82v0amxMFBs/T2xP8CMOtSQa81b3dAzNbMw8JRxZcT4usZ/Mj5KJIIG59RYm1AI5+8nRhIKI30Q6G2y47BXlSzl3hvBiInTssDNm1rjmrCzpEkj/GPEZmGhpIFqTKK6u15q5UAHse+miy8vkPjA= 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 1570822570553566.817683941795; Fri, 11 Oct 2019 12:36:10 -0700 (PDT) Received: from localhost ([::1]:56338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0ht-0005uk-42 for importer@patchew.org; Fri, 11 Oct 2019 15:36:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37607) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pi-0000Vb-5i for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pg-0003vl-VJ for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pg-0003vD-Ps for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 098A210C0930; Fri, 11 Oct 2019 19:17:20 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4BE55D6C8; Fri, 11 Oct 2019 19:17:18 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 13/21] migration/postcopy: mis->have_listen_thread check will never be touched Date: Fri, 11 Oct 2019 20:16:38 +0100 Message-Id: <20191011191646.226814-14-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Fri, 11 Oct 2019 19:17:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang If mis->have_listen_thread is true, this means current PostcopyState must be LISTENING or RUNNING. While the check at the beginning of the function makes sure the state transaction happens when its previous PostcopyState is ADVISE or DISCARD. This means we would never touch this check. Signed-off-by: Wei Yang Message-Id: <20191006000249.29926-2-richardw.yang@linux.intel.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/savevm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 241c5dd097..c62687afef 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1878,11 +1878,6 @@ static int loadvm_postcopy_handle_listen(MigrationIn= comingState *mis) return -1; } =20 - if (mis->have_listen_thread) { - error_report("CMD_POSTCOPY_RAM_LISTEN already has a listen thread"= ); - return -1; - } - mis->have_listen_thread =3D true; /* Start up the listening thread and wait for it to signal ready */ qemu_sem_init(&mis->listen_thread_sem, 0); --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822687; cv=none; d=zoho.com; s=zohoarc; b=AgfPll8vj/2YNgUanL1P+mnj1eSDUOQPbm+/C4RtY2IMMlpj9ptB015k0r1WDEwSX6PSYlBAyJwbYY4xZMH8mw3NVyq7DnU1JOm9/Jp/MHU4mbau2r4rrIiWhkM7irXNNvwao8T3gMRWYf4W4CNz/wOdWaKl2HtKsHYNGX22bVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822687; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hf8OVUpLicMoUD11LNtXuPDfLeFGTiswKZS4x1KzFfM=; b=TbKJ8TYnp2bVk3qkBJmO8MYL1Jex9Foj06xaId/6tOISnP7jDZXu0wyfSnSSnocTaELc7zWkJ2OBVIrtgIzahBXmsmeLUXHUjzgG1e9H1XUCL2ZQhLDxkk8jGuHQvB53NnRZXRG12KFM8nwOQnxfo3lVOnP7Y0b53FuCD6+EuXc= 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 1570822687403758.3356664484362; Fri, 11 Oct 2019 12:38:07 -0700 (PDT) Received: from localhost ([::1]:56370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0jm-0008EQ-AY for importer@patchew.org; Fri, 11 Oct 2019 15:38:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37632) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pm-0000cQ-2P for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pk-0003xk-Rv for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48863) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pk-0003xK-ML for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8AC78AC6FD; Fri, 11 Oct 2019 19:17:23 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5463E5D713; Fri, 11 Oct 2019 19:17:20 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 14/21] migration/postcopy: postpone setting PostcopyState to END Date: Fri, 11 Oct 2019 20:16:39 +0100 Message-Id: <20191011191646.226814-15-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 11 Oct 2019 19:17:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang There are two places to call function postcopy_ram_incoming_cleanup() postcopy_ram_listen_thread on migration success loadvm_postcopy_handle_listen one setup failure On success, the vm will never accept another migration. On failure, PostcopyState is transited from LISTENING to END and would be checked in qemu_loadvm_state_main(). If PostcopyState is RUNNING, migration would be paused and retried. Currently PostcopyState is set to END in function postcopy_ram_incoming_cleanup(). With above analysis, we can take this step out and postpone this till the end of listen thread to indicate the listen thread is done. This is a preparation patch for later cleanup. Signed-off-by: Wei Yang Message-Id: <20191006000249.29926-3-richardw.yang@linux.intel.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert Fixed up in merge to the 1 parameter postcopy_state_set --- migration/postcopy-ram.c | 2 -- migration/savevm.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 3a72f7b4fe..a793bad477 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -577,8 +577,6 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingStat= e *mis) } } =20 - postcopy_state_set(POSTCOPY_INCOMING_END); - if (mis->postcopy_tmp_page) { munmap(mis->postcopy_tmp_page, mis->largest_page_size); mis->postcopy_tmp_page =3D NULL; diff --git a/migration/savevm.c b/migration/savevm.c index c62687afef..bf3da58ecc 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1837,6 +1837,8 @@ static void *postcopy_ram_listen_thread(void *opaque) =20 rcu_unregister_thread(); mis->have_listen_thread =3D false; + postcopy_state_set(POSTCOPY_INCOMING_END); + return NULL; } =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822070; cv=none; d=zoho.com; s=zohoarc; b=nqZ+g6SqqjWqdzmN/SYNXmAaVlCNsXFk4FDWPcqftWmk4PMgBghTMm39JZY+mItn/BqYsCNsztW+SsPtkiraS6gFK1jaYHIlhna4Pe2Gn6xatEXYLss5R+V+uIxemK6SwLoO7AQVvKGBefWwB+bQ5zkETaUeF/D4j1HIf15hR7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822070; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=byR/mqcCw0Q9+Sy9CYKK0RS8gswi3oWXnmm+KGt1QBI=; b=DKTDL+GZDdMVsU6aLg3giOEd8BPfOGNKsoJFhbPuHxT93L58DZWA/xsaACnRxFrNnq9jwi5B+6wzcjX39NExAv23VwL1DQLgnaW2+mmN0qtwrkG6xS7O5DiWHqiL61ZUv7x5qflYLNPwcjT9e8TW7YMNcoFBw3lMRMURHTGR8Wo= 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 1570822070606603.8627030548594; Fri, 11 Oct 2019 12:27:50 -0700 (PDT) Received: from localhost ([::1]:56244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Zp-00057x-9I for importer@patchew.org; Fri, 11 Oct 2019 15:27:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37643) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pn-0000er-F0 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pm-0003yM-8e for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pm-0003y6-33 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A248300BEAB; Fri, 11 Oct 2019 19:17:25 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E0A15D6C8; Fri, 11 Oct 2019 19:17:24 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 15/21] migration/postcopy: rename postcopy_ram_enable_notify to postcopy_ram_incoming_setup Date: Fri, 11 Oct 2019 20:16:40 +0100 Message-Id: <20191011191646.226814-16-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 11 Oct 2019 19:17:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang Function postcopy_ram_incoming_setup and postcopy_ram_incoming_cleanup is a pair. Rename to make it clear for audience. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert Message-Id: <20191010011316.31363-2-richardw.yang@linux.intel.com> Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 4 ++-- migration/postcopy-ram.h | 2 +- migration/savevm.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a793bad477..abccafc8c8 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1094,7 +1094,7 @@ retry: return NULL; } =20 -int postcopy_ram_enable_notify(MigrationIncomingState *mis) +int postcopy_ram_incoming_setup(MigrationIncomingState *mis) { /* Open the fd for the kernel to give us userfaults */ mis->userfault_fd =3D syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK= ); @@ -1307,7 +1307,7 @@ int postcopy_request_shared_page(struct PostCopyFD *p= cfd, RAMBlock *rb, return -1; } =20 -int postcopy_ram_enable_notify(MigrationIncomingState *mis) +int postcopy_ram_incoming_setup(MigrationIncomingState *mis) { assert(0); return -1; diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index fb4cd11d28..9941feb63a 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -20,7 +20,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingStat= e *mis); * Make all of RAM sensitive to accesses to areas that haven't yet been wr= itten * and wire up anything necessary to deal with it. */ -int postcopy_ram_enable_notify(MigrationIncomingState *mis); +int postcopy_ram_incoming_setup(MigrationIncomingState *mis); =20 /* * Initialise postcopy-ram, setting the RAM to a state where we can go into diff --git a/migration/savevm.c b/migration/savevm.c index bf3da58ecc..95574c4e9d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1869,7 +1869,7 @@ static int loadvm_postcopy_handle_listen(MigrationInc= omingState *mis) * shouldn't be doing anything yet so don't actually expect requests */ if (migrate_postcopy_ram()) { - if (postcopy_ram_enable_notify(mis)) { + if (postcopy_ram_incoming_setup(mis)) { postcopy_ram_incoming_cleanup(mis); return -1; } --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822745; cv=none; d=zoho.com; s=zohoarc; b=ZQcK1kMZYiW+cK50SZ5vs3q/BaC0p8Q9nc6l6ygBOljl3huSuMVsQZ+W0u9CDDroBBNjKbxdv4WgB5RUtDQRD5IjoHZpm2LgjtEg4Q4qmnJrhXjEtMkTacW+XWO8+eD3so0TKzXn6T/Wx46TKIEq8LefpPZRfgmolt5Xo9qplOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822745; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1GJBLNlPjqY0bIDEXDu+affZrfgf9ea2lCeh4NhDUO4=; b=FCs3jVKpl5Sf52TFamYydIHrvdeKhI7CPUF1eomGg7+7HP/ZXSD2Md8x59DJDoKo/fm/WLv+8Z1Czu5iP9NsNemozrCaIm5l/J+lAJVHlKw4yTbBu7Lhs/8+UJVzt3sDjEqyZy/mZtY69vQiqPnZTQeyE6hh05LQ63AqmOl/deo= 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 1570822745906780.1171818433277; Fri, 11 Oct 2019 12:39:05 -0700 (PDT) Received: from localhost ([::1]:56378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0ki-0000mF-Qj for importer@patchew.org; Fri, 11 Oct 2019 15:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37657) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Po-0000hU-T7 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pn-0003zD-OL for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pn-0003yi-In for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF0CFC053B32; Fri, 11 Oct 2019 19:17:26 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3DAB5D6C8; Fri, 11 Oct 2019 19:17:25 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 16/21] migration/postcopy: check PostcopyState before setting to POSTCOPY_INCOMING_RUNNING Date: Fri, 11 Oct 2019 20:16:41 +0100 Message-Id: <20191011191646.226814-17-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 11 Oct 2019 19:17:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang Currently, we set PostcopyState blindly to RUNNING, even we found the previous state is not LISTENING. This will lead to a corner case. First let's look at the code flow: qemu_loadvm_state_main() ret =3D loadvm_process_command() loadvm_postcopy_handle_run() return -1; if (ret < 0) { if (postcopy_state_get() =3D=3D POSTCOPY_INCOMING_RUNNING) ... } >From above snippet, the corner case is loadvm_postcopy_handle_run() always sets state to RUNNING. And then it checks the previous state. If the previous state is not LISTENING, it will return -1. But at this moment, PostcopyState is already been set to RUNNING. Then ret is checked in qemu_loadvm_state_main(), when it is -1 PostcopyState is checked. Current logic would pause postcopy and retry if PostcopyState is RUNNING. This is not what we expect, because postcopy is not active yet. This patch makes sure state is set to RUNNING only previous state is LISTENING by checking the state first. Signed-off-by: Wei Yang Suggested by: Peter Xu Message-Id: <20191010011316.31363-3-richardw.yang@linux.intel.com> Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- migration/savevm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/savevm.c b/migration/savevm.c index 95574c4e9d..8d95e261f6 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1933,7 +1933,7 @@ static void loadvm_postcopy_handle_run_bh(void *opaqu= e) /* After all discards we can start running and asking for pages */ static int loadvm_postcopy_handle_run(MigrationIncomingState *mis) { - PostcopyState ps =3D postcopy_state_set(POSTCOPY_INCOMING_RUNNING); + PostcopyState ps =3D postcopy_state_get(); =20 trace_loadvm_postcopy_handle_run(); if (ps !=3D POSTCOPY_INCOMING_LISTENING) { @@ -1941,6 +1941,7 @@ static int loadvm_postcopy_handle_run(MigrationIncomi= ngState *mis) return -1; } =20 + postcopy_state_set(POSTCOPY_INCOMING_RUNNING); mis->bh =3D qemu_bh_new(loadvm_postcopy_handle_run_bh, mis); qemu_bh_schedule(mis->bh); =20 --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821941; cv=none; d=zoho.com; s=zohoarc; b=F228x6TH7UktJX1EIoL/bQ0KyTdm22+T70U8FATTUedmUZtVg8pc04tXf7Vt5IlNSVAxWqA+veoqU6eqxhYnUovA14R4sVXdNERNUKQHZak6UZHesMmu7hoPJXLc/Z/CDsQBA4WnfmqNal05ju4yqnsP3vxuQXV3E70mOGoMDXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821941; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pp/Zc2vKY4YQLUfC74K5OYI90MAngebRsznBQ7iLlvA=; b=NlsNHkzMH2oqra+WS/2sXrD75tZeNGj3brEKFXy9yS+udNeZlaGcMWDLqLEzC34WaE2DNhdPD4RqIwv5FA/pUZBAl8hS4IfQU8rMzLJl4JBNFq3n3RVbAIBeecoICmDL/XBdb+FNnRCwu2DSuRgf0M/rxFEpTzL1wjL3F/mHEZA= 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 1570821941345381.15837719578144; Fri, 11 Oct 2019 12:25:41 -0700 (PDT) Received: from localhost ([::1]:56220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Xh-0002IH-EM for importer@patchew.org; Fri, 11 Oct 2019 15:25:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37674) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pt-0000na-2I for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pr-00040l-Tz for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pr-00040J-OA for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00DE310CC1ED; Fri, 11 Oct 2019 19:17:31 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24AEA5D6C8; Fri, 11 Oct 2019 19:17:26 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 17/21] migration/multifd: fix a typo in comment of multifd_recv_unfill_packet() Date: Fri, 11 Oct 2019 20:16:42 +0100 Message-Id: <20191011191646.226814-18-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Fri, 11 Oct 2019 19:17:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang Signed-off-by: Wei Yang Message-Id: <20191011085050.17622-2-richardw.yang@linux.intel.com> Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 071687ef37..698ba4d669 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -838,7 +838,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) =20 packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); /* - * If we recevied a packet that is 100 times bigger than expected + * If we received a packet that is 100 times bigger than expected * just stop migration. It is a magic number. */ if (packet->pages_alloc > pages_max * 100) { --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822114; cv=none; d=zoho.com; s=zohoarc; b=e6lBKcMkw6ut7k3NgV0jnRBYrHZwnfST6ahbt3IJ+5yBplgBtYZOdJSkbkXEBs2mXNOAHUJXuidSEsSbSMn+JPztS06vHg+I0GRD8tAXkuucOtF3415rNlEi7QaNj+xNgKdpj2w9Ery+vdDp2TNGHFyM331AYljZvp9x2jCk2Ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822114; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nTNIleUuyfPr/z/rII8eeSu6wjXokmTrA+2TAhgNLr4=; b=JBXN6bcffIYxmsRdv74uEUBCBJBmxIPfcvosN6xk6HLVL25TnXduE/t/SUlBDWc24+WQN3ee2E6DYmfJQGq0I/75hEpf8jwjqIaUt7kh5F47iRwW1uzxXb8vfHCsJCBrBZ7FYvdeVIdTVpV3sQ5WIa7oCku/sjPpoKB7Tx+kmow= 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 1570822114841920.4637557080047; Fri, 11 Oct 2019 12:28:34 -0700 (PDT) Received: from localhost ([::1]:56248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0aX-0005wo-I3 for importer@patchew.org; Fri, 11 Oct 2019 15:28:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37703) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pw-0000ty-UX for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pv-000443-Um for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Pv-00043n-Oz for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BA1630655F9; Fri, 11 Oct 2019 19:17:35 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A2465D6C8; Fri, 11 Oct 2019 19:17:31 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 18/21] migration/multifd: use pages->allocated instead of the static max Date: Fri, 11 Oct 2019 20:16:43 +0100 Message-Id: <20191011191646.226814-19-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 11 Oct 2019 19:17:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang multifd_send_fill_packet() prepares meta data for following pages to transfer. It would be more proper to fill pages->allocated instead of static max value, especially we want to support flexible packet size. Signed-off-by: Wei Yang Message-Id: <20191011085050.17622-3-richardw.yang@linux.intel.com> Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 698ba4d669..84c5953a84 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -791,13 +791,12 @@ static void multifd_pages_clear(MultiFDPages_t *pages) static void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; - uint32_t page_max =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); int i; =20 packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); packet->version =3D cpu_to_be32(MULTIFD_VERSION); packet->flags =3D cpu_to_be32(p->flags); - packet->pages_alloc =3D cpu_to_be32(page_max); + packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); packet->pages_used =3D cpu_to_be32(p->pages->used); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); packet->packet_num =3D cpu_to_be64(p->packet_num); --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822849; cv=none; d=zoho.com; s=zohoarc; b=Ll3LfuSbpdNKhh5kjjYDSPxJyU26e5NH1fm+OwPFdL0SAYDmlI0xz/fc5NrQudcthwSNXsk0PepQmT9mOirXqv/BOmjIN33HoyKMOOvQKsbGGGN0F4I4o2CWKJd+FcdP8ZB9o7KnbJ5QvOOoMObyaGr6sJQv8NHWrC0RWxFF2JU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822849; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=j1W0/2fLwCNUlIg9y33okc7lYWb2YcJ58L3l3ge/2DA=; b=fPDHNryukso2LbOxSz2g1i3inoGcofQer7n1LkN7nqFNByyC4Q/ZtzkmDyZD5pIZeAVfvvdDYdSKG0gc8IuDpX77nU/qh2as9xkiDL0uQvxhSmOKuaXJ0h3UdVjb551/NNHmPcjYRta+X4Kn5yM1RwjLXFK9hNcKY/oSzS10kjo= 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 1570822849667255.83497194311144; Fri, 11 Oct 2019 12:40:49 -0700 (PDT) Received: from localhost ([::1]:56396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0mO-0002Hy-F4 for importer@patchew.org; Fri, 11 Oct 2019 15:40:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37727) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Py-0000wc-Q2 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Px-00045D-Jn for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Px-00044Z-9J for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C5B9309BDA3; Fri, 11 Oct 2019 19:17:36 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54A8066A01; Fri, 11 Oct 2019 19:17:35 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 19/21] migration/multifd: initialize packet->magic/version once at setup stage Date: Fri, 11 Oct 2019 20:16:44 +0100 Message-Id: <20191011191646.226814-20-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 11 Oct 2019 19:17:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang MultiFDPacket_t's magic and version field never changes during migration, so move these two fields in setup stage. Signed-off-by: Wei Yang Message-Id: <20191011085050.17622-4-richardw.yang@linux.intel.com> Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 84c5953a84..963e795ed0 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -793,8 +793,6 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) MultiFDPacket_t *packet =3D p->packet; int i; =20 - packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - packet->version =3D cpu_to_be32(MULTIFD_VERSION); packet->flags =3D cpu_to_be32(p->flags); packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); packet->pages_used =3D cpu_to_be32(p->pages->used); @@ -1240,6 +1238,8 @@ int multifd_save_setup(void) p->packet_len =3D sizeof(MultiFDPacket_t) + sizeof(ram_addr_t) * page_count; p->packet =3D g_malloc0(p->packet_len); + p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); + p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); p->name =3D g_strdup_printf("multifdsend_%d", i); socket_send_channel_create(multifd_new_send_channel_async, p); } --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570821983; cv=none; d=zoho.com; s=zohoarc; b=lug/l/CX/veKBu4zjDI4xyLYEpzocVtWqI33IA1FRjbei11kXHvhfQOjjy8okOP688nhzGetaXjaRDQ/IjYC2B82dc2Pq/DnkkdelrjpCuA5JGLt/cdintnBVqqmv4nTR3m9X3pwlaZN9aX+M31KfwLyHsmlYaG0Qbtj+kCEPLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570821983; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6ACcpV2KiCXCpVaKkCNSijHfplkr8XqJUcKyq6gx4Oo=; b=mNQNMdLcRnOnLtTRR8S1QFBWenhjWVGmtEBl+kJRCnKNRyNmX/ZLauXZiZTZMNXKmLyd2t3M1fC3pWqOkB+NPWFAcPzsof+sBtONEOKmkRDH6ZI0kbF42TH+hwGG3pgyPn2BX+q2zyDL3UwLxzBy/zu7swgWuXUu14Y/VWE6+A0= 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 1570821983765325.1272903715993; Fri, 11 Oct 2019 12:26:23 -0700 (PDT) Received: from localhost ([::1]:56230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0YQ-0003Le-38 for importer@patchew.org; Fri, 11 Oct 2019 15:26:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37739) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Pz-0000y6-Tt for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Pz-00046r-0U for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Py-00045Y-OL for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F19D9801661; Fri, 11 Oct 2019 19:17:37 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7B685D6C8; Fri, 11 Oct 2019 19:17:36 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 20/21] migration/multifd: pages->used would be cleared when attach to multifd_send_state Date: Fri, 11 Oct 2019 20:16:45 +0100 Message-Id: <20191011191646.226814-21-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Fri, 11 Oct 2019 19:17:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Wei Yang When we found an available channel in multifd_send_pages(), its pages->used is cleared and then attached to multifd_send_state. It is not necessary to do this twice. Signed-off-by: Wei Yang Message-Id: <20191011085050.17622-5-richardw.yang@linux.intel.com> Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 1 - 1 file changed, 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 963e795ed0..5078f94490 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1129,7 +1129,6 @@ static void *multifd_send_thread(void *opaque) p->flags =3D 0; p->num_packets++; p->num_pages +=3D used; - p->pages->used =3D 0; qemu_mutex_unlock(&p->mutex); =20 trace_multifd_send(p->id, packet_num, used, flags, --=20 2.23.0 From nobody Sun May 5 17:45:28 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=1570822270; cv=none; d=zoho.com; s=zohoarc; b=UVwnxu9kpzO4TE7sWxzk1hBqK2tkT4mnA9DznJ4MD82ikODj/RD+uTOKtsxSZ3o2UqhT/Dq4rVnBSoq3Tj5XwL3bmesVlWskADcl81zdw0bAQ8pHReV3/5ysb0ESJi+nUtae8t0OtmuWh0DYCz+OscXW/oK+I5cPhRQ4b5SssZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570822270; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SFBHcP1bCx5lIcJApgq/avOX2JzESJ3GLNkXn1eDyQs=; b=hyMzAYsxIIKaIvlWzoFHKgLgYmv7OtC2QmJTp0/cFngrfD4pyh0x803ZIrTMfP4AaJfdkocm7c/ix1QP7feHhXC8RF316WQ8055vgMNfDqWX5kVNeU+Ebc1WfMgtHP24avEKH/mCKpI/hnkRjZp0+/No92cQgClGkcwcg10+yHo= 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 1570822270851685.9119320741937; Fri, 11 Oct 2019 12:31:10 -0700 (PDT) Received: from localhost ([::1]:56290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0d2-0000Nl-Qw for importer@patchew.org; Fri, 11 Oct 2019 15:31:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37754) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ0Q5-0000zB-KQ for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ0Q1-000493-Pf for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43942) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ0Q1-00047R-0F for qemu-devel@nongnu.org; Fri, 11 Oct 2019 15:17:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76BB883F3D; Fri, 11 Oct 2019 19:17:39 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-117-210.ams2.redhat.com [10.36.117.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4807B5D6C8; Fri, 11 Oct 2019 19:17:38 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, eric.auger@redhat.com, richardw.yang@linux.intel.com Subject: [PULL 21/21] migration: Support gtree migration Date: Fri, 11 Oct 2019 20:16:46 +0100 Message-Id: <20191011191646.226814-22-dgilbert@redhat.com> In-Reply-To: <20191011191646.226814-1-dgilbert@redhat.com> References: <20191011191646.226814-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 11 Oct 2019 19:17:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Eric Auger Introduce support for GTree migration. A custom save/restore is implemented. Each item is made of a key and a data. If the key is a pointer to an object, 2 VMSDs are passed into the GTree VMStateField. When putting the items, the tree is traversed in sorted order by g_tree_foreach. On the get() path, gtrees must be allocated using the proper key compare, key destroy and value destroy. This must be handled beforehand, for example in a pre_load method. Tests are added to test save/dump of structs containing gtrees including the virtio-iommu domain/mappings scenario. Signed-off-by: Eric Auger Message-Id: <20191011121724.433-1-eric.auger@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert uintptr_t fixup for test on 32bit --- include/migration/vmstate.h | 40 ++++ migration/trace-events | 5 + migration/vmstate-types.c | 152 +++++++++++++ tests/test-vmstate.c | 421 ++++++++++++++++++++++++++++++++++++ 4 files changed, 618 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1fbfd099dd..b9ee563aa4 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -224,6 +224,7 @@ extern const VMStateInfo vmstate_info_unused_buffer; extern const VMStateInfo vmstate_info_tmp; extern const VMStateInfo vmstate_info_bitmap; extern const VMStateInfo vmstate_info_qtailq; +extern const VMStateInfo vmstate_info_gtree; =20 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) /* @@ -754,6 +755,45 @@ extern const VMStateInfo vmstate_info_qtailq; .start =3D offsetof(_type, _next), = \ } =20 +/* + * For migrating a GTree whose key is a pointer to _key_type and the + * value, a pointer to _val_type + * The target tree must have been properly initialized + * _vmsd: Start address of the 2 element array containing the data vmsd + * and the key vmsd, in that order + * _key_type: type of the key + * _val_type: type of the value + */ +#define VMSTATE_GTREE_V(_field, _state, _version, _vmsd, = \ + _key_type, _val_type) = \ +{ = \ + .name =3D (stringify(_field)), = \ + .version_id =3D (_version), = \ + .vmsd =3D (_vmsd), = \ + .info =3D &vmstate_info_gtree, = \ + .start =3D sizeof(_key_type), = \ + .size =3D sizeof(_val_type), = \ + .offset =3D offsetof(_state, _field), = \ +} + +/* + * For migrating a GTree with direct key and the value a pointer + * to _val_type + * The target tree must have been properly initialized + * _vmsd: data vmsd + * _val_type: type of the value + */ +#define VMSTATE_GTREE_DIRECT_KEY_V(_field, _state, _version, _vmsd, _val_t= ype) \ +{ = \ + .name =3D (stringify(_field)), = \ + .version_id =3D (_version), = \ + .vmsd =3D (_vmsd), = \ + .info =3D &vmstate_info_gtree, = \ + .start =3D 0, = \ + .size =3D sizeof(_val_type), = \ + .offset =3D offsetof(_state, _field), = \ +} + /* _f : field name _f_n : num of elements field_name _n : num of elements diff --git a/migration/trace-events b/migration/trace-events index 858d415d56..6dee7b5389 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -71,6 +71,11 @@ get_qtailq_end(const char *name, const char *reason, int= val) "%s %s/%d" put_qtailq(const char *name, int version_id) "%s v%d" put_qtailq_end(const char *name, const char *reason) "%s %s" =20 +get_gtree(const char *field_name, const char *key_vmsd_name, const char *v= al_vmsd_name, uint32_t nnodes) "%s(%s/%s) nnodes=3D%d" +get_gtree_end(const char *field_name, const char *key_vmsd_name, const cha= r *val_vmsd_name, int ret) "%s(%s/%s) %d" +put_gtree(const char *field_name, const char *key_vmsd_name, const char *v= al_vmsd_name, uint32_t nnodes) "%s(%s/%s) nnodes=3D%d" +put_gtree_end(const char *field_name, const char *key_vmsd_name, const cha= r *val_vmsd_name, int ret) "%s(%s/%s) %d" + # qemu-file.c qemu_file_fclose(void) "" =20 diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index bee658a1b2..7236cf92bc 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -691,3 +691,155 @@ const VMStateInfo vmstate_info_qtailq =3D { .get =3D get_qtailq, .put =3D put_qtailq, }; + +struct put_gtree_data { + QEMUFile *f; + const VMStateDescription *key_vmsd; + const VMStateDescription *val_vmsd; + QJSON *vmdesc; + int ret; +}; + +static gboolean put_gtree_elem(gpointer key, gpointer value, gpointer data) +{ + struct put_gtree_data *capsule =3D (struct put_gtree_data *)data; + QEMUFile *f =3D capsule->f; + int ret; + + qemu_put_byte(f, true); + + /* put the key */ + if (!capsule->key_vmsd) { + qemu_put_be64(f, (uint64_t)(uintptr_t)(key)); /* direct key */ + } else { + ret =3D vmstate_save_state(f, capsule->key_vmsd, key, capsule->vmd= esc); + if (ret) { + capsule->ret =3D ret; + return true; + } + } + + /* put the data */ + ret =3D vmstate_save_state(f, capsule->val_vmsd, value, capsule->vmdes= c); + if (ret) { + capsule->ret =3D ret; + return true; + } + return false; +} + +static int put_gtree(QEMUFile *f, void *pv, size_t unused_size, + const VMStateField *field, QJSON *vmdesc) +{ + bool direct_key =3D (!field->start); + const VMStateDescription *key_vmsd =3D direct_key ? NULL : &field->vms= d[1]; + const VMStateDescription *val_vmsd =3D &field->vmsd[0]; + const char *key_vmsd_name =3D direct_key ? "direct" : key_vmsd->name; + struct put_gtree_data capsule =3D { + .f =3D f, + .key_vmsd =3D key_vmsd, + .val_vmsd =3D val_vmsd, + .vmdesc =3D vmdesc, + .ret =3D 0}; + GTree **pval =3D pv; + GTree *tree =3D *pval; + uint32_t nnodes =3D g_tree_nnodes(tree); + int ret; + + trace_put_gtree(field->name, key_vmsd_name, val_vmsd->name, nnodes); + qemu_put_be32(f, nnodes); + g_tree_foreach(tree, put_gtree_elem, (gpointer)&capsule); + qemu_put_byte(f, false); + ret =3D capsule.ret; + if (ret) { + error_report("%s : failed to save gtree (%d)", field->name, ret); + } + trace_put_gtree_end(field->name, key_vmsd_name, val_vmsd->name, ret); + return ret; +} + +static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, + const VMStateField *field) +{ + bool direct_key =3D (!field->start); + const VMStateDescription *key_vmsd =3D direct_key ? NULL : &field->vms= d[1]; + const VMStateDescription *val_vmsd =3D &field->vmsd[0]; + const char *key_vmsd_name =3D direct_key ? "direct" : key_vmsd->name; + int version_id =3D field->version_id; + size_t key_size =3D field->start; + size_t val_size =3D field->size; + int nnodes, count =3D 0; + GTree **pval =3D pv; + GTree *tree =3D *pval; + void *key, *val; + int ret =3D 0; + + /* in case of direct key, the key vmsd can be {}, ie. check fields */ + if (!direct_key && version_id > key_vmsd->version_id) { + error_report("%s %s", key_vmsd->name, "too new"); + return -EINVAL; + } + if (!direct_key && version_id < key_vmsd->minimum_version_id) { + error_report("%s %s", key_vmsd->name, "too old"); + return -EINVAL; + } + if (version_id > val_vmsd->version_id) { + error_report("%s %s", val_vmsd->name, "too new"); + return -EINVAL; + } + if (version_id < val_vmsd->minimum_version_id) { + error_report("%s %s", val_vmsd->name, "too old"); + return -EINVAL; + } + + nnodes =3D qemu_get_be32(f); + trace_get_gtree(field->name, key_vmsd_name, val_vmsd->name, nnodes); + + while (qemu_get_byte(f)) { + if ((++count) > nnodes) { + ret =3D -EINVAL; + break; + } + if (direct_key) { + key =3D (void *)(uintptr_t)qemu_get_be64(f); + } else { + key =3D g_malloc0(key_size); + ret =3D vmstate_load_state(f, key_vmsd, key, version_id); + if (ret) { + error_report("%s : failed to load %s (%d)", + field->name, key_vmsd->name, ret); + goto key_error; + } + } + val =3D g_malloc0(val_size); + ret =3D vmstate_load_state(f, val_vmsd, val, version_id); + if (ret) { + error_report("%s : failed to load %s (%d)", + field->name, val_vmsd->name, ret); + goto val_error; + } + g_tree_insert(tree, key, val); + } + if (count !=3D nnodes) { + error_report("%s inconsistent stream when loading the gtree", + field->name); + return -EINVAL; + } + trace_get_gtree_end(field->name, key_vmsd_name, val_vmsd->name, ret); + return ret; +val_error: + g_free(val); +key_error: + if (!direct_key) { + g_free(key); + } + trace_get_gtree_end(field->name, key_vmsd_name, val_vmsd->name, ret); + return ret; +} + + +const VMStateInfo vmstate_info_gtree =3D { + .name =3D "gtree", + .get =3D get_gtree, + .put =3D put_gtree, +}; diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index e80c4c6143..1e5be1d4ff 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -812,6 +812,423 @@ static void test_load_q(void) qemu_fclose(fload); } =20 +/* interval (key) */ +typedef struct TestGTreeInterval { + uint64_t low; + uint64_t high; +} TestGTreeInterval; + +#define VMSTATE_INTERVAL \ +{ \ + .name =3D "interval", \ + .version_id =3D 1, \ + .minimum_version_id =3D 1, \ + .fields =3D (VMStateField[]) { \ + VMSTATE_UINT64(low, TestGTreeInterval), \ + VMSTATE_UINT64(high, TestGTreeInterval), \ + VMSTATE_END_OF_LIST() \ + } \ +} + +/* mapping (value) */ +typedef struct TestGTreeMapping { + uint64_t phys_addr; + uint32_t flags; +} TestGTreeMapping; + +#define VMSTATE_MAPPING \ +{ \ + .name =3D "mapping", \ + .version_id =3D 1, \ + .minimum_version_id =3D 1, \ + .fields =3D (VMStateField[]) { \ + VMSTATE_UINT64(phys_addr, TestGTreeMapping), \ + VMSTATE_UINT32(flags, TestGTreeMapping), \ + VMSTATE_END_OF_LIST() \ + }, \ +} + +static const VMStateDescription vmstate_interval_mapping[2] =3D { + VMSTATE_MAPPING, /* value */ + VMSTATE_INTERVAL /* key */ +}; + +typedef struct TestGTreeDomain { + int32_t id; + GTree *mappings; +} TestGTreeDomain; + +typedef struct TestGTreeIOMMU { + int32_t id; + GTree *domains; +} TestGTreeIOMMU; + +/* Interval comparison function */ +static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_d= ata) +{ + TestGTreeInterval *inta =3D (TestGTreeInterval *)a; + TestGTreeInterval *intb =3D (TestGTreeInterval *)b; + + if (inta->high < intb->low) { + return -1; + } else if (intb->high < inta->low) { + return 1; + } else { + return 0; + } +} + +/* ID comparison function */ +static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data) +{ + uint ua =3D GPOINTER_TO_UINT(a); + uint ub =3D GPOINTER_TO_UINT(b); + return (ua > ub) - (ua < ub); +} + +static void destroy_domain(gpointer data) +{ + TestGTreeDomain *domain =3D (TestGTreeDomain *)data; + + g_tree_destroy(domain->mappings); + g_free(domain); +} + +static int domain_preload(void *opaque) +{ + TestGTreeDomain *domain =3D opaque; + + domain->mappings =3D g_tree_new_full((GCompareDataFunc)interval_cmp, + NULL, g_free, g_free); + return 0; +} + +static int iommu_preload(void *opaque) +{ + TestGTreeIOMMU *iommu =3D opaque; + + iommu->domains =3D g_tree_new_full((GCompareDataFunc)int_cmp, + NULL, NULL, destroy_domain); + return 0; +} + +static const VMStateDescription vmstate_domain =3D { + .name =3D "domain", + .version_id =3D 1, + .minimum_version_id =3D 1, + .pre_load =3D domain_preload, + .fields =3D (VMStateField[]) { + VMSTATE_INT32(id, TestGTreeDomain), + VMSTATE_GTREE_V(mappings, TestGTreeDomain, 1, + vmstate_interval_mapping, + TestGTreeInterval, TestGTreeMapping), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_iommu =3D { + .name =3D "iommu", + .version_id =3D 1, + .minimum_version_id =3D 1, + .pre_load =3D iommu_preload, + .fields =3D (VMStateField[]) { + VMSTATE_INT32(id, TestGTreeIOMMU), + VMSTATE_GTREE_DIRECT_KEY_V(domains, TestGTreeIOMMU, 1, + &vmstate_domain, TestGTreeDomain), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t first_domain_dump[] =3D { + /* id */ + 0x00, 0x0, 0x0, 0x6, + 0x00, 0x0, 0x0, 0x2, /* 2 mappings */ + 0x1, /* start of a */ + /* a */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, + /* map_a */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x1, /* start of b */ + /* b */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0xFF, + /* map_b */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, + 0x0, /* end of gtree */ + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static TestGTreeDomain *create_first_domain(void) +{ + TestGTreeDomain *domain; + TestGTreeMapping *map_a, *map_b; + TestGTreeInterval *a, *b; + + domain =3D g_malloc0(sizeof(TestGTreeDomain)); + domain->id =3D 6; + + a =3D g_malloc0(sizeof(TestGTreeInterval)); + a->low =3D 0x1000; + a->high =3D 0x1FFF; + + b =3D g_malloc0(sizeof(TestGTreeInterval)); + b->low =3D 0x4000; + b->high =3D 0x4FFF; + + map_a =3D g_malloc0(sizeof(TestGTreeMapping)); + map_a->phys_addr =3D 0xa000; + map_a->flags =3D 1; + + map_b =3D g_malloc0(sizeof(TestGTreeMapping)); + map_b->phys_addr =3D 0xe0000; + map_b->flags =3D 2; + + domain->mappings =3D g_tree_new_full((GCompareDataFunc)interval_cmp, N= ULL, + (GDestroyNotify)g_free, + (GDestroyNotify)g_free); + g_tree_insert(domain->mappings, a, map_a); + g_tree_insert(domain->mappings, b, map_b); + return domain; +} + +static void test_gtree_save_domain(void) +{ + TestGTreeDomain *first_domain =3D create_first_domain(); + + save_vmstate(&vmstate_domain, first_domain); + compare_vmstate(first_domain_dump, sizeof(first_domain_dump)); + destroy_domain(first_domain); +} + +struct match_node_data { + GTree *tree; + gpointer key; + gpointer value; +}; + +struct tree_cmp_data { + GTree *tree1; + GTree *tree2; + GTraverseFunc match_node; +}; + +static gboolean match_interval_mapping_node(gpointer key, + gpointer value, gpointer data) +{ + TestGTreeMapping *map_a, *map_b; + TestGTreeInterval *a, *b; + struct match_node_data *d =3D (struct match_node_data *)data; + char *str =3D g_strdup_printf("dest"); + + g_free(str); + a =3D (TestGTreeInterval *)key; + b =3D (TestGTreeInterval *)d->key; + + map_a =3D (TestGTreeMapping *)value; + map_b =3D (TestGTreeMapping *)d->value; + + assert(a->low =3D=3D b->low); + assert(a->high =3D=3D b->high); + assert(map_a->phys_addr =3D=3D map_b->phys_addr); + assert(map_a->flags =3D=3D map_b->flags); + g_tree_remove(d->tree, key); + return true; +} + +static gboolean diff_tree(gpointer key, gpointer value, gpointer data) +{ + struct tree_cmp_data *tp =3D (struct tree_cmp_data *)data; + struct match_node_data d =3D {tp->tree2, key, value}; + + g_tree_foreach(tp->tree2, tp->match_node, &d); + g_tree_remove(tp->tree1, key); + return false; +} + +static void compare_trees(GTree *tree1, GTree *tree2, + GTraverseFunc function) +{ + struct tree_cmp_data tp =3D {tree1, tree2, function}; + + g_tree_foreach(tree1, diff_tree, &tp); + assert(g_tree_nnodes(tree1) =3D=3D 0); + assert(g_tree_nnodes(tree2) =3D=3D 0); +} + +static void diff_domain(TestGTreeDomain *d1, TestGTreeDomain *d2) +{ + assert(d1->id =3D=3D d2->id); + compare_trees(d1->mappings, d2->mappings, match_interval_mapping_node); +} + +static gboolean match_domain_node(gpointer key, gpointer value, gpointer d= ata) +{ + uint64_t id1, id2; + TestGTreeDomain *d1, *d2; + struct match_node_data *d =3D (struct match_node_data *)data; + + id1 =3D (uint64_t)(uintptr_t)key; + id2 =3D (uint64_t)(uintptr_t)d->key; + d1 =3D (TestGTreeDomain *)value; + d2 =3D (TestGTreeDomain *)d->value; + assert(id1 =3D=3D id2); + diff_domain(d1, d2); + g_tree_remove(d->tree, key); + return true; +} + +static void diff_iommu(TestGTreeIOMMU *iommu1, TestGTreeIOMMU *iommu2) +{ + assert(iommu1->id =3D=3D iommu2->id); + compare_trees(iommu1->domains, iommu2->domains, match_domain_node); +} + +static void test_gtree_load_domain(void) +{ + TestGTreeDomain *dest_domain =3D g_malloc0(sizeof(TestGTreeDomain)); + TestGTreeDomain *orig_domain =3D create_first_domain(); + QEMUFile *fload, *fsave; + char eof; + + fsave =3D open_test_file(true); + qemu_put_buffer(fsave, first_domain_dump, sizeof(first_domain_dump)); + g_assert(!qemu_file_get_error(fsave)); + qemu_fclose(fsave); + + fload =3D open_test_file(false); + + vmstate_load_state(fload, &vmstate_domain, dest_domain, 1); + eof =3D qemu_get_byte(fload); + g_assert(!qemu_file_get_error(fload)); + g_assert_cmpint(orig_domain->id, =3D=3D, dest_domain->id); + g_assert_cmpint(eof, =3D=3D, QEMU_VM_EOF); + + diff_domain(orig_domain, dest_domain); + destroy_domain(orig_domain); + destroy_domain(dest_domain); + qemu_fclose(fload); +} + +uint8_t iommu_dump[] =3D { + /* iommu id */ + 0x00, 0x0, 0x0, 0x7, + 0x00, 0x0, 0x0, 0x2, /* 2 domains */ + 0x1,/* start of domain 5 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x0, 0x5, /* key =3D 5 */ + 0x00, 0x0, 0x0, 0x5, /* domain1 id */ + 0x00, 0x0, 0x0, 0x1, /* 1 mapping */ + 0x1, /* start of mappings */ + /* c */ + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, + /* map_c */ + 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, + 0x00, 0x0, 0x0, 0x3, + 0x0, /* end of domain1 mappings*/ + 0x1,/* start of domain 6 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x0, 0x6, /* key =3D 6 */ + 0x00, 0x0, 0x0, 0x6, /* domain6 id */ + 0x00, 0x0, 0x0, 0x2, /* 2 mappings */ + 0x1, /* start of a */ + /* a */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, + /* map_a */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x1, /* start of b */ + /* b */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0xFF, + /* map_b */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, + 0x0, /* end of domain6 mappings*/ + 0x0, /* end of domains */ + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static TestGTreeIOMMU *create_iommu(void) +{ + TestGTreeIOMMU *iommu =3D g_malloc0(sizeof(TestGTreeIOMMU)); + TestGTreeDomain *first_domain =3D create_first_domain(); + TestGTreeDomain *second_domain; + TestGTreeMapping *map_c; + TestGTreeInterval *c; + + iommu->id =3D 7; + iommu->domains =3D g_tree_new_full((GCompareDataFunc)int_cmp, NULL, + NULL, + destroy_domain); + + second_domain =3D g_malloc0(sizeof(TestGTreeDomain)); + second_domain->id =3D 5; + second_domain->mappings =3D g_tree_new_full((GCompareDataFunc)interval= _cmp, + NULL, + (GDestroyNotify)g_free, + (GDestroyNotify)g_free); + + g_tree_insert(iommu->domains, GUINT_TO_POINTER(6), first_domain); + g_tree_insert(iommu->domains, (gpointer)0x0000000000000005, second_dom= ain); + + c =3D g_malloc0(sizeof(TestGTreeInterval)); + c->low =3D 0x1000000; + c->high =3D 0x1FFFFFF; + + map_c =3D g_malloc0(sizeof(TestGTreeMapping)); + map_c->phys_addr =3D 0xF000000; + map_c->flags =3D 0x3; + + g_tree_insert(second_domain->mappings, c, map_c); + return iommu; +} + +static void destroy_iommu(TestGTreeIOMMU *iommu) +{ + g_tree_destroy(iommu->domains); + g_free(iommu); +} + +static void test_gtree_save_iommu(void) +{ + TestGTreeIOMMU *iommu =3D create_iommu(); + + save_vmstate(&vmstate_iommu, iommu); + compare_vmstate(iommu_dump, sizeof(iommu_dump)); + destroy_iommu(iommu); +} + +static void test_gtree_load_iommu(void) +{ + TestGTreeIOMMU *dest_iommu =3D g_malloc0(sizeof(TestGTreeIOMMU)); + TestGTreeIOMMU *orig_iommu =3D create_iommu(); + QEMUFile *fsave, *fload; + char eof; + int ret; + + fsave =3D open_test_file(true); + qemu_put_buffer(fsave, iommu_dump, sizeof(iommu_dump)); + g_assert(!qemu_file_get_error(fsave)); + qemu_fclose(fsave); + + fload =3D open_test_file(false); + vmstate_load_state(fload, &vmstate_iommu, dest_iommu, 1); + ret =3D qemu_file_get_error(fload); + eof =3D qemu_get_byte(fload); + ret =3D qemu_file_get_error(fload); + g_assert(!ret); + g_assert_cmpint(orig_iommu->id, =3D=3D, dest_iommu->id); + g_assert_cmpint(eof, =3D=3D, QEMU_VM_EOF); + + diff_iommu(orig_iommu, dest_iommu); + destroy_iommu(orig_iommu); + destroy_iommu(dest_iommu); + qemu_fclose(fload); +} + typedef struct TmpTestStruct { TestStruct *parent; int64_t diff; @@ -932,6 +1349,10 @@ int main(int argc, char **argv) test_arr_ptr_prim_0_load); g_test_add_func("/vmstate/qtailq/save/saveq", test_save_q); g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q); + g_test_add_func("/vmstate/gtree/save/savedomain", test_gtree_save_doma= in); + g_test_add_func("/vmstate/gtree/load/loaddomain", test_gtree_load_doma= in); + g_test_add_func("/vmstate/gtree/save/saveiommu", test_gtree_save_iommu= ); + g_test_add_func("/vmstate/gtree/load/loadiommu", test_gtree_load_iommu= ); g_test_add_func("/vmstate/tmp_struct", test_tmp_struct); g_test_run(); =20 --=20 2.23.0