From nobody Thu Nov 6 01:34:32 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 Reviewed-by: Maxime Coquelin --- 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 From nobody Thu Nov 6 01:34:32 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 1539014802942142.8203629352506; Mon, 8 Oct 2018 09:06:42 -0700 (PDT) Received: from localhost ([::1]:47171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9Y3N-00027N-EO for importer@patchew.org; Mon, 08 Oct 2018 12:06:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9Y0L-0000FV-4g for qemu-devel@nongnu.org; Mon, 08 Oct 2018 12:03:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9Y0J-0007so-Oh for qemu-devel@nongnu.org; Mon, 08 Oct 2018 12:03:33 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:59180) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9Y0J-0007sW-D8; Mon, 08 Oct 2018 12:03:31 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181008160329euoutp01cf8e01c21359e8cd26017ac080902dc6~braI2XByy2487724877euoutp016; Mon, 8 Oct 2018 16:03:29 +0000 (GMT) Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181008160329eucas1p275af7249d7d35abfc606f436745dfc34~braIP1yfS2993629936eucas1p2x; Mon, 8 Oct 2018 16:03:29 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 8B.F7.04294.0DF7BBB5; Mon, 8 Oct 2018 17:03:28 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181008160328eucas1p14fff8e1e5e5f065019353fb86b845340~braHZRVol3093330933eucas1p1r; Mon, 8 Oct 2018 16:03:28 +0000 (GMT) Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EB.94.04128.0DF7BBB5; Mon, 8 Oct 2018 17:03:28 +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:28 +0100 (BST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181008160329euoutp01cf8e01c21359e8cd26017ac080902dc6~braI2XByy2487724877euoutp016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539014609; bh=/SKj2YJ1whwnuOtAX/4Bxh5jE/Vkaown0P7KgBLyTXc=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=MBOPHFKAoawpSzR5MeGNJXEdO1gGqdpmJPmyd74BoVzn7/NI/vLeegFcZ7tO8c2jQ S7+vRc2Ux8DFraeTnqJO/QtrqOgWs3Rgv1H1yuXhhCQv0AuVrRhW6n4KiEegPZGjly +A5RwQY2XKmJkEJZAp7bc8iZb1OHQ0Pn+uaNnZSw= X-AuditID: cbfec7f4-835ff700000010c6-51-5bbb7fd075e2 From: Ilya Maximets To: "Michael S. Tsirkin" Date: Mon, 08 Oct 2018 19:05:36 +0300 Message-id: <20181008160536.6332-3-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+NgFjrPIsWRmVeSWpSXmKPExsWy7djP87oX6ndHG3zrMLHo3XaP3eJK+092 iwVt7awWxzr3sFj8//WK1eJ47w4Wi/lLd7I4sHs8ubaZyeP9vqtsHn1bVjEGMEdx2aSk5mSW pRbp2yVwZTRP+cdYsIG74sXkZrYGximcXYwcHBICJhIvFst1MXJxCAmsYJT4dv8UK4TzmVHi 9vWNzF2MnGBFmy/MZ4FILGOUePHvOVRVM5PEgS0rwarYBHQkTq0+wghiiwhoSjy99ZoJpIhZ oJFJYu3K+ywgCWEBY4kZVy6zgtgsAqoSVw4dBWvmFbCS2H/pGhvEOnmJ1RsOgMU5Bawl+lpO sULUCEr8mHwPbA4zUM3BK8/BTpIQmMEmMXMGyFCQh1wkXjSrQMwRlnh1fAs7hC0jcXlyNwuE XS9xv+UlI0RvB6PE9EP/mCAS9hJbXp9jh1jAJzFp23RmiJm8Eh1tQhCmh8TyqdYQz/cxSqzY u4B5AqP0LCTnzUJy3gJGplWM4qmlxbnpqcVGeanlesWJucWleel6yfm5mxiB0Xz63/EvOxh3 /Uk6xCjAwajEwzsjb3e0EGtiWXFl7iFGCQ5mJRFe0e27ooV4UxIrq1KL8uOLSnNSiw8xSnOw KInzLpu3MVpIID2xJDU7NbUgtQgmy8TBKdXA2CPie3yyzwx98W0lzIHZKpNOHr3MuluMR6I6 XDck4oKfcOZ2x0Qxk8CNl39VHrstIR0cuOaYQ8C7Nx2NGgd/+B/bEXt8xrGd9cKV9galguZf XQ1DOnu6ZpZtrjwur1rTpamr8Ig33J7Vj+2ybrr92najpQJH7K4wTX3l7XfPS/KdlMe55VJK LMUZiYZazEXFiQAFp5Vs4gIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPLMWRmVeSWpSXmKPExsVy+t/xa7oX6ndHG0z9J2jRu+0eu8WV9p/s Fgva2lktjnXuYbH4/+sVq8Xx3h0sFvOX7mRxYPd4cm0zk8f7fVfZPPq2rGIMYI7isklJzcks Sy3St0vgymie8o+xYAN3xYvJzWwNjFM4uxg5OSQETCQ2X5jP0sXIxSEksIRRYlH7R0YIp5VJ Ysv5mcwgVWwCOhKnVh9hBLFFBDQlnt56zQRSxCzQyCSxfNp3sISwgLHEjCuXWUFsFgFViSuH joI18wpYSey/dI0NYp28xOoNB8DinALWEn0tp8DqhYBqFh9YzQJRLyjxY/I9MJsZqP7glecs Exj5ZiFJzUKSWsDItIpRJLW0ODc9t9hIrzgxt7g0L10vOT93EyMwGLcd+7llB2PXu+BDjAIc jEo8vDPydkcLsSaWFVfmHmKU4GBWEuEV3b4rWog3JbGyKrUoP76oNCe1+BCjNAeLkjjveYPK KCGB9MSS1OzU1ILUIpgsEwenVAOjt23Ut/l3Sl6Ef7r1ajfrkqq7f0yna52cuazivmzA66yr QZyqi2aK2zAYpLdzlk86Yeejxi/5nsX7LpPfftmO2rrn9Wyf5vLdXObw+D7/8llSe/bEJX/m cF3I1uVQK/a2+e1PjZ79UnOCxV3+VwpoqUVcs5pirO4hd1/6kOveqe4NCeweB1KVWIozEg21 mIuKEwESXlHgQgIAAA== X-CMS-MailID: 20181008160328eucas1p14fff8e1e5e5f065019353fb86b845340 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181008160328eucas1p14fff8e1e5e5f065019353fb86b845340 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 2/2] vhost-user: Fix userfaultfd leak 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" 'fd' received from the vhost side is never freed. Also, everything (including 'postcopy_listen' state) should be cleaned up on vhost cleanup. Fixes: 46343570c06e ("vhost+postcopy: Wire up POSTCOPY_END notify") Fixes: f82c11165ffa ("vhost+postcopy: Register shared ufd with postcopy") Cc: qemu-stable@nongnu.org Signed-off-by: Ilya Maximets Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Maxime Coquelin --- hw/virtio/vhost-user.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index c442daa562..e09bed0e4a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1280,6 +1280,7 @@ static int vhost_user_postcopy_end(struct vhost_dev *= dev, Error **errp) return ret; } postcopy_unregister_shared_ufd(&u->postcopy_fd); + close(u->postcopy_fd.fd); u->postcopy_fd.handler =3D NULL; =20 trace_vhost_user_postcopy_end_exit(); @@ -1419,6 +1420,12 @@ static int vhost_user_backend_cleanup(struct vhost_d= ev *dev) postcopy_remove_notifier(&u->postcopy_notifier); u->postcopy_notifier.notify =3D NULL; } + u->postcopy_listen =3D false; + if (u->postcopy_fd.handler) { + postcopy_unregister_shared_ufd(&u->postcopy_fd); + close(u->postcopy_fd.fd); + u->postcopy_fd.handler =3D NULL; + } if (u->slave_fd >=3D 0) { qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); close(u->slave_fd); --=20 2.17.1