{"id":807508,"url":"http://patchwork.ozlabs.org/api/1.0/patches/807508/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<1504081950-2528-7-git-send-email-peterx@redhat.com>","date":"2017-08-30T08:32:03","name":"[RFC,v2,06/33] migration: reuse mis->userfault_quit_fd","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"dd1f431a41952c1561fa0876bed6495c3d0633ed","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/1.0/people/67717/?format=json","name":"Peter Xu","email":"peterx@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1504081950-2528-7-git-send-email-peterx@redhat.com/mbox/","series":[{"id":552,"url":"http://patchwork.ozlabs.org/api/1.0/series/552/?format=json","date":"2017-08-30T08:31:59","name":"Migration: postcopy failure recovery","version":2,"mbox":"http://patchwork.ozlabs.org/series/552/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807508/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx04.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx04.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=peterx@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xhzhH28kTz9t2Q\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 30 Aug 2017 18:49:19 +1000 (AEST)","from localhost ([::1]:49083 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dmygX-0003rp-0c\n\tfor incoming@patchwork.ozlabs.org; Wed, 30 Aug 2017 04:49:17 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:34023)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <peterx@redhat.com>) id 1dmyQu-00070f-Ub\n\tfor qemu-devel@nongnu.org; Wed, 30 Aug 2017 04:33:10 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <peterx@redhat.com>) id 1dmyQr-0003EV-Ut\n\tfor qemu-devel@nongnu.org; Wed, 30 Aug 2017 04:33:08 -0400","from mx1.redhat.com ([209.132.183.28]:37504)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <peterx@redhat.com>) id 1dmyQr-0003E5-L8\n\tfor qemu-devel@nongnu.org; Wed, 30 Aug 2017 04:33:05 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id A17F58047F;\n\tWed, 30 Aug 2017 08:33:04 +0000 (UTC)","from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com\n\t[10.66.14.103])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id C717B871E6;\n\tWed, 30 Aug 2017 08:33:01 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com A17F58047F","From":"Peter Xu <peterx@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Wed, 30 Aug 2017 16:32:03 +0800","Message-Id":"<1504081950-2528-7-git-send-email-peterx@redhat.com>","In-Reply-To":"<1504081950-2528-1-git-send-email-peterx@redhat.com>","References":"<1504081950-2528-1-git-send-email-peterx@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.28]);\n\tWed, 30 Aug 2017 08:33:04 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [RFC v2 06/33] migration: reuse mis->userfault_quit_fd","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Laurent Vivier <lvivier@redhat.com>,\n\tAndrea Arcangeli <aarcange@redhat.com>, \n\tJuan Quintela <quintela@redhat.com>,\n\tAlexey Perevalov <a.perevalov@samsung.com>, peterx@redhat.com,\n\t\"Dr . David Alan Gilbert\" <dgilbert@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"It was only used for quitting the page fault thread before. Let it be\nsomething more useful - now we can use it to notify a \"wake\" for the\npage fault thread (for any reason), and it only means \"quit\" if the\nfault_thread_quit is set.\n\nSince we changed what it does, renaming it to userfault_event_fd.\n\nReviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>\nSigned-off-by: Peter Xu <peterx@redhat.com>\n---\n migration/migration.h    |  6 ++++--\n migration/postcopy-ram.c | 26 +++++++++++++++++---------\n 2 files changed, 21 insertions(+), 11 deletions(-)","diff":"diff --git a/migration/migration.h b/migration/migration.h\nindex 148c9fa..70e3094 100644\n--- a/migration/migration.h\n+++ b/migration/migration.h\n@@ -35,6 +35,8 @@ struct MigrationIncomingState {\n     bool           have_fault_thread;\n     QemuThread     fault_thread;\n     QemuSemaphore  fault_thread_sem;\n+    /* Set this when we want the fault thread to quit */\n+    bool           fault_thread_quit;\n \n     bool           have_listen_thread;\n     QemuThread     listen_thread;\n@@ -42,8 +44,8 @@ struct MigrationIncomingState {\n \n     /* For the kernel to send us notifications */\n     int       userfault_fd;\n-    /* To tell the fault_thread to quit */\n-    int       userfault_quit_fd;\n+    /* To notify the fault_thread to wake, e.g., when need to quit */\n+    int       userfault_event_fd;\n     QEMUFile *to_src_file;\n     QemuMutex rp_mutex;    /* We send replies from multiple threads */\n     void     *postcopy_tmp_page;\ndiff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c\nindex 7a414eb..0138a49 100644\n--- a/migration/postcopy-ram.c\n+++ b/migration/postcopy-ram.c\n@@ -305,17 +305,18 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis)\n          * currently be at 0, we're going to increment it to 1\n          */\n         tmp64 = 1;\n-        if (write(mis->userfault_quit_fd, &tmp64, 8) == 8) {\n+        atomic_set(&mis->fault_thread_quit, 1);\n+        if (write(mis->userfault_event_fd, &tmp64, 8) == 8) {\n             trace_postcopy_ram_incoming_cleanup_join();\n             qemu_thread_join(&mis->fault_thread);\n         } else {\n             /* Not much we can do here, but may as well report it */\n-            error_report(\"%s: incrementing userfault_quit_fd: %s\", __func__,\n+            error_report(\"%s: incrementing userfault_event_fd: %s\", __func__,\n                          strerror(errno));\n         }\n         trace_postcopy_ram_incoming_cleanup_closeuf();\n         close(mis->userfault_fd);\n-        close(mis->userfault_quit_fd);\n+        close(mis->userfault_event_fd);\n         mis->have_fault_thread = false;\n     }\n \n@@ -438,7 +439,7 @@ static void *postcopy_ram_fault_thread(void *opaque)\n         pfd[0].fd = mis->userfault_fd;\n         pfd[0].events = POLLIN;\n         pfd[0].revents = 0;\n-        pfd[1].fd = mis->userfault_quit_fd;\n+        pfd[1].fd = mis->userfault_event_fd;\n         pfd[1].events = POLLIN; /* Waiting for eventfd to go positive */\n         pfd[1].revents = 0;\n \n@@ -448,8 +449,15 @@ static void *postcopy_ram_fault_thread(void *opaque)\n         }\n \n         if (pfd[1].revents) {\n-            trace_postcopy_ram_fault_thread_quit();\n-            break;\n+            uint64_t tmp64 = 0;\n+\n+            /* Consume the signal */\n+            read(mis->userfault_event_fd, &tmp64, 8);\n+\n+            if (atomic_read(&mis->fault_thread_quit)) {\n+                trace_postcopy_ram_fault_thread_quit();\n+                break;\n+            }\n         }\n \n         ret = read(mis->userfault_fd, &msg, sizeof(msg));\n@@ -528,9 +536,9 @@ int postcopy_ram_enable_notify(MigrationIncomingState *mis)\n     }\n \n     /* Now an eventfd we use to tell the fault-thread to quit */\n-    mis->userfault_quit_fd = eventfd(0, EFD_CLOEXEC);\n-    if (mis->userfault_quit_fd == -1) {\n-        error_report(\"%s: Opening userfault_quit_fd: %s\", __func__,\n+    mis->userfault_event_fd = eventfd(0, EFD_CLOEXEC);\n+    if (mis->userfault_event_fd == -1) {\n+        error_report(\"%s: Opening userfault_event_fd: %s\", __func__,\n                      strerror(errno));\n         close(mis->userfault_fd);\n         return -1;\n","prefixes":["RFC","v2","06/33"]}