From nobody Fri Nov 7 13:02:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=samsung.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539014833233618.8952564388817; Mon, 8 Oct 2018 09:07:13 -0700 (PDT) Received: from localhost ([::1]:47178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9Y3s-0002R4-3s for importer@patchew.org; Mon, 08 Oct 2018 12:07:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9Y0L-0000FS-4E for qemu-devel@nongnu.org; Mon, 08 Oct 2018 12:03:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9Y0H-0007sQ-UF for qemu-devel@nongnu.org; Mon, 08 Oct 2018 12:03:33 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:59168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9Y0H-0007qE-Mr; Mon, 08 Oct 2018 12:03:29 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181008160326euoutp015f14302b6f399087fbbe6c3610d29453~braF7OKiU2487724877euoutp015; Mon, 8 Oct 2018 16:03:26 +0000 (GMT) Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181008160326eucas1p2364bac8750af81cc98fbcc86ca277ee1~braFebbcu2832128321eucas1p2j; Mon, 8 Oct 2018 16:03:26 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 9A.F7.04294.DCF7BBB5; Mon, 8 Oct 2018 17:03:25 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181008160325eucas1p23bd6b6ce112175d274db884fb2a83f54~braEu5EY42894328943eucas1p2w; Mon, 8 Oct 2018 16:03:25 +0000 (GMT) Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id BC.35.04284.DCF7BBB5; Mon, 8 Oct 2018 17:03:25 +0100 (BST) Received: from imaximets.rnd.samsung.ru ([106.109.129.180]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PGA00GFSF9BGY30@eusync4.samsung.com>; Mon, 08 Oct 2018 17:03:25 +0100 (BST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181008160326euoutp015f14302b6f399087fbbe6c3610d29453~braF7OKiU2487724877euoutp015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539014606; bh=GPL7o+F+066DBaIL4w6UFXSPVsU0XhcscD6AtSYAD14=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=cpMF1Cyz6hpmkc501MFOgdpVWDhk8u1yToVJcLTfM2MuCCfTQ0raj3JgXjDX3/jtW TM7DQh97tHmwAMfl/WYpeUHZilOm7gjsi3RdUGqxKMBpjmXaqbwRgRc9U1zdHFB/nK g19m1vvbsM9Iy0Akk/ZOP1pLxHAC7jqbXc+/zqlg= X-AuditID: cbfec7f4-84fff700000010c6-4a-5bbb7fcde3aa From: Ilya Maximets To: "Michael S. Tsirkin" Date: Mon, 08 Oct 2018 19:05:35 +0300 Message-id: <20181008160536.6332-2-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 In-reply-to: <20181008160536.6332-1-i.maximets@samsung.com> MIME-version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRmVeSWpSXmKPExsWy7djP87pn63dHGzT3mlr0brvHbnGl/Se7 xYK2dlaLY517WCz+/3rFanG8dweLxfylO1kc2D2eXNvM5PF+31U2j74tqxgDmKO4bFJSczLL Uov07RK4MtpePmctOM9b8bBvOXsD42OuLkZODgkBE4mm62uZuxi5OIQEVjBKzF3WB+V8ZpRo ntzMDFPVdeQiG0RiGaPEpXmPWSGcZiaJk3t/soJUsQnoSJxafYQRxBYR0JR4eus1E0gRs0Aj k8TalfdZQBLCAp4SfxeCdHNwsAioSnTPVAcxeQWsJN6+tYdYJi+xesMBsMWcAtYSfS2nwMbz CghK/Jh8D2wKM1DNwSvPWUDGSwjMYZPYceAYI0Szi8SNGx+YIGxhiVfHt7BD2DISnR0HoeL1 EvdbXjJCNHcwSkw/9A8qYS+x5fU5dogNfBKTtk1nBjlOQoBXoqNNCKLEQ+L0la/QkOhjlJi2 7z7LBEbpWUgOnIXkwAWMTKsYxVNLi3PTU4uN8lLL9YoTc4tL89L1kvNzNzEC4/n0v+NfdjDu +pN0iFGAg1GJh3dG3u5oIdbEsuLK3EOMEhzMSiK8ott3RQvxpiRWVqUW5ccXleakFh9ilOZg URLnXTZvY7SQQHpiSWp2ampBahFMlomDU6qB0ZRhxsKlXkvnOC5rePzHQcjtmv45M47vEh7H +S7+bLWMnZb3ban++n1q+Ubs63QD6zJ3H9QwS95d3ly7Qe9WpOyN0+3XS3wuRUv5cFyw6Ux3 iwzwLHcsLS1a/+vsr3XqPtrb951g9ax6v4BbOKMqWWXfhcO9H78c3f6VlUf+yn12xUOFc5l3 KLEUZyQaajEXFScCAPwPYVTjAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDLMWRmVeSWpSXmKPExsVy+t/xa7pn63dHG1w4xW7Ru+0eu8WV9p/s Fgva2lktjnXuYbH4/+sVq8Xx3h0sFvOX7mRxYPd4cm0zk8f7fVfZPPq2rGIMYI7isklJzcks Sy3St0vgymh7+Zy14DxvxcO+5ewNjI+5uhg5OSQETCS6jlxk62Lk4hASWMIosbb9IgtIQkig lUlif58eiM0moCNxavURRhBbREBT4umt10wgDcwCjUwSy6d9B0sIC3hK/F34mLWLkYODRUBV onumOojJK2Al8fatPcQueYnVGw4wg9icAtYSfS2nWCFWWUksPrAabC2vgKDEj8n3wGxmoPqD V56zTGDkm4UkNQtJagEj0ypGkdTS4tz03GJDveLE3OLSvHS95PzcTYzAMNx27OfmHYyXNgYf YhTgYFTi4Z2RtztaiDWxrLgy9xCjBAezkgiv6PZd0UK8KYmVValF+fFFpTmpxYcYpTlYlMR5 zxtURgkJpCeWpGanphakFsFkmTg4pRoYS5UC3okq/VZYdmXfi6BF5VpuEnWdxQs1gu5GhE6u mfrn3EHtrlRvpQKWW/qc8dJzFpukf50/6XZUmUhGzZeMd6ESTxn+qZstPC9QefH3JjWpQtN0 zQkHvVIZrfvC5O/t3+3z5MPrUz+2sq2ef99Xr0Lf7dYz1QxFudK/oveP6rbttdSY9GCDEktx RqKhFnNRcSIAY7v4yD8CAAA= X-CMS-MailID: 20181008160325eucas1p23bd6b6ce112175d274db884fb2a83f54 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181008160325eucas1p23bd6b6ce112175d274db884fb2a83f54 References: <20181008160536.6332-1-i.maximets@samsung.com> Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 210.118.77.11 Subject: [Qemu-devel] [RFC 1/2] migration: Stop postcopy fault thread before notifying X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org, qemu-devel@nongnu.org, Maxime Coquelin , Ilya Maximets , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" POSTCOPY_NOTIFY_INBOUND_END handlers will remove userfault fds from the postcopy_remote_fds array which could be still in use by the fault thread. Let's stop the thread before notification to avoid possible accessing wrong memory. Fixes: 46343570c06e ("vhost+postcopy: Wire up POSTCOPY_END notify") Cc: qemu-stable@nongnu.org Signed-off-by: Ilya Maximets Reviewed-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 853d8b32ca..e5c02a32c5 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -533,6 +533,12 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingSta= te *mis) if (mis->have_fault_thread) { Error *local_err =3D NULL; =20 + /* Let the fault thread quit */ + atomic_set(&mis->fault_thread_quit, 1); + postcopy_fault_thread_notify(mis); + trace_postcopy_ram_incoming_cleanup_join(); + qemu_thread_join(&mis->fault_thread); + if (postcopy_notify(POSTCOPY_NOTIFY_INBOUND_END, &local_err)) { error_report_err(local_err); return -1; @@ -541,11 +547,6 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingSta= te *mis) if (qemu_ram_foreach_migratable_block(cleanup_range, mis)) { return -1; } - /* Let the fault thread quit */ - atomic_set(&mis->fault_thread_quit, 1); - postcopy_fault_thread_notify(mis); - trace_postcopy_ram_incoming_cleanup_join(); - qemu_thread_join(&mis->fault_thread); =20 trace_postcopy_ram_incoming_cleanup_closeuf(); close(mis->userfault_fd); --=20 2.17.1