From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644993163733922.8525819792959; Tue, 15 Feb 2022 22:32:43 -0800 (PST) Received: from localhost ([::1]:33132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKDrm-0006YB-Bn for importer@patchew.org; Wed, 16 Feb 2022 01:32:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDnt-0003ts-Cu for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:28:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38261) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDnp-0006Bs-UU for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:28:39 -0500 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-588-0TSpdulrP6KH_Kh5W2wYIQ-1; Wed, 16 Feb 2022 01:28:35 -0500 Received: by mail-pl1-f197.google.com with SMTP id y3-20020a1709029b8300b0014c8bcb70a1so695486plp.3 for ; Tue, 15 Feb 2022 22:28:35 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.28.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:28:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mnyPMZa4z+deUcT+LDnCHdFNt3ymR9XevyYLDisMNNM=; b=LZX6Ps0GvbZpGenoBsekhYd0Gwv94eOy773RkvDqbd5jp7TRpPv5sP+PsmrC+dORM+d1uL qN3nehFgidpH/s5Um2ecz1FJYrdsO8FriivRa7pub5yK9Oo/wufxY/6IZx3N52P/jWHP7c gu4iDq5zRfO7RIe9T4iqf7EDoFmSH5o= X-MC-Unique: 0TSpdulrP6KH_Kh5W2wYIQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mnyPMZa4z+deUcT+LDnCHdFNt3ymR9XevyYLDisMNNM=; b=7nSZptA3wQdoPz1ZCn8/7F8rXFKD5ALsEm/45PU+qXpAXWU7g2BEkEmMLa9iEq2uw6 Lm5Bue8ANfXanV4LxJPZooWCR3Y+6QewROp3AY2H83CiG4d3MQAyTDghr6r6wpqch4NP gUhzoN1snU4VEM17YweH4twSge/zZCJ2ELGnCZ4KlMnz3JtNS4Bh+gLxQTPibOBJcxKU EgbnaB38aUSsk4O8ZqXAUP26AWwtI+qWYdR/qGDf3vttmcOH4QPVQlDSFWOPhcdJKA5e CRS0AQj09gIAnl9vscAGhAeq2w19/0o8oAi2sE31uISJAxZJUbl37UaYVS+wIX5W2xsN 8ghA== X-Gm-Message-State: AOAM531A1kfOJIFHH+cZT1bKjrDw6NLgWl9wCLQAmKcTlHRHhTafL8+a RfwgRjB2GijcvGooKUFLWaYWmxnVPK5P8gPKIWcvfMRwB2BiHou/rlYEs1DVPgOFWd7KlVMgLfs cWdAN96wXWWqhLyA10Jk/0WDCh/zlmLr6UOI1A32qTg/ZVupO0H5b+NOAw3paNlaK X-Received: by 2002:a17:902:e88d:b0:14f:446b:264b with SMTP id w13-20020a170902e88d00b0014f446b264bmr1438675plg.166.1644992914665; Tue, 15 Feb 2022 22:28:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyB/ELyyp+00bUdVZaqbtySRmLkLL4bt5IyanNl+ZiOnG4/ezk/qVqCOaEAzJsOD/pvEBRw8A== X-Received: by 2002:a17:902:e88d:b0:14f:446b:264b with SMTP id w13-20020a170902e88d00b0014f446b264bmr1438653plg.166.1644992914301; Tue, 15 Feb 2022 22:28:34 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 01/20] migration: Dump sub-cmd name in loadvm_process_command tp Date: Wed, 16 Feb 2022 14:27:50 +0800 Message-Id: <20220216062809.57179-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644993165991100003 Content-Type: text/plain; charset="utf-8" It'll be easier to read the name rather than index of sub-cmd when debuggin= g. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/savevm.c | 3 ++- migration/trace-events | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 1599b02fbc..7bb65e1d61 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2273,12 +2273,13 @@ static int loadvm_process_command(QEMUFile *f) return qemu_file_get_error(f); } =20 - trace_loadvm_process_command(cmd, len); if (cmd >=3D MIG_CMD_MAX || cmd =3D=3D MIG_CMD_INVALID) { error_report("MIG_CMD 0x%x unknown (len 0x%x)", cmd, len); return -EINVAL; } =20 + trace_loadvm_process_command(mig_cmd_args[cmd].name, len); + if (mig_cmd_args[cmd].len !=3D -1 && mig_cmd_args[cmd].len !=3D len) { error_report("%s received with bad length - expecting %zu, got %d", mig_cmd_args[cmd].name, diff --git a/migration/trace-events b/migration/trace-events index 48aa7b10ee..123cfe79d7 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -22,7 +22,7 @@ loadvm_postcopy_handle_resume(void) "" loadvm_postcopy_ram_handle_discard(void) "" loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len)= "%s: %ud" -loadvm_process_command(uint16_t com, uint16_t len) "com=3D0x%x len=3D%d" +loadvm_process_command(const char *s, uint16_t len) "com=3D%s len=3D%d" loadvm_process_command_ping(uint32_t val) "0x%x" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644993169026822.5165274090753; Tue, 15 Feb 2022 22:32:49 -0800 (PST) Received: from localhost ([::1]:33468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKDrs-0006mV-13 for importer@patchew.org; Wed, 16 Feb 2022 01:32:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoN-00048n-73 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoE-0006Dr-NF for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:04 -0500 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-4QIT_ZS2NbyPvfLfn_5H4w-1; Wed, 16 Feb 2022 01:28:43 -0500 Received: by mail-pl1-f200.google.com with SMTP id e7-20020a170902ef4700b0014d2b420f1fso691586plx.17 for ; Tue, 15 Feb 2022 22:28:42 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.28.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EiC+MAxpNNYzgkQn7CDpdk/XLHjC0Acmh1wcwvYO5Gk=; b=a3zK8BqkoPaU2ofuvGhRmJU+dse0YBC4kNrNhK92ew7niWex68eez7SyTk+JQ9nGTUG1+U I41CHQNqAZzNEnTWKkdztE103V24AapsdcrXXM7IZdnmW4FeDwLIzlzdDcNRgtORig5gWK ibutEM/tcmgBzGgnKKLfDf3T6BFFMUs= X-MC-Unique: 4QIT_ZS2NbyPvfLfn_5H4w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EiC+MAxpNNYzgkQn7CDpdk/XLHjC0Acmh1wcwvYO5Gk=; b=XmlrXF3AMCSzgDhohc5BbFOwRU+uyGSvQpOF9/vZ22iFumiKjnWzlfctSaF/tjgfP6 khRrtF2ckmP2VlapJSIYn3dWaNT9L8lkBq21bvxkH7j1Si37oqaZt2lFexM3bKQm7ltS +ZjcMEiyBosOB+t83vzFmZ+XBUpwXO8Ts6VgrgeaDfXzubaSTTqLXK3Ng23vl9FsjPX5 9MwuQJP6Prnra5KsOPiJdoS5QtoqB5PBjFm6bzRnR1c57s5DqGuATOVuoYN9h/uy/sfV j1jlKTIAhkn+CwrHix0xN8lpQHS3G1UTDEr9qaqyk3jdikNnImbr+Fp2hDixHl7TMZdB Gy4A== X-Gm-Message-State: AOAM533QnUq00MbBa8c22pfh6NzdE+e69sFwjYxjsO2iC1JHiUT2NXDE eeRY1M6BcC3QJH0CIynGY+S6y9ES1JVUbJhMPhqQQqtd8cnMF59r5oQu2JcPbdxnc66hcu+uGi4 5Ux65LJvlxyildfJKcpPAueVru5dZKi6wC++F60PU3bOCPlDzDsOL+GXDhY/w+WZY X-Received: by 2002:a63:d158:0:b0:341:7eac:74d6 with SMTP id c24-20020a63d158000000b003417eac74d6mr1037856pgj.541.1644992921721; Tue, 15 Feb 2022 22:28:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9rlIUQzL6pf/+mw+If5d3wjKFbZ4Ptustfa1HliV2Tcms8sz9Qcxxo7irCedhrEEALFpRWA== X-Received: by 2002:a63:d158:0:b0:341:7eac:74d6 with SMTP id c24-20020a63d158000000b003417eac74d6mr1037832pgj.541.1644992921336; Tue, 15 Feb 2022 22:28:41 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 02/20] migration: Finer grained tracepoints for POSTCOPY_LISTEN Date: Wed, 16 Feb 2022 14:27:51 +0800 Message-Id: <20220216062809.57179-3-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644993170069100001 Content-Type: text/plain; charset="utf-8" The enablement of postcopy listening has a few steps, add a few tracepoints= to be there ready for some basic measurements for them. Signed-off-by: Peter Xu --- migration/savevm.c | 9 ++++++++- migration/trace-events | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 7bb65e1d61..190cc5fc42 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1948,9 +1948,10 @@ static void *postcopy_ram_listen_thread(void *opaque) static int loadvm_postcopy_handle_listen(MigrationIncomingState *mis) { PostcopyState ps =3D postcopy_state_set(POSTCOPY_INCOMING_LISTENING); - trace_loadvm_postcopy_handle_listen(); Error *local_err =3D NULL; =20 + trace_loadvm_postcopy_handle_listen("enter"); + if (ps !=3D POSTCOPY_INCOMING_ADVISE && ps !=3D POSTCOPY_INCOMING_DISC= ARD) { error_report("CMD_POSTCOPY_LISTEN in wrong postcopy state (%d)", p= s); return -1; @@ -1965,6 +1966,8 @@ static int loadvm_postcopy_handle_listen(MigrationInc= omingState *mis) } } =20 + trace_loadvm_postcopy_handle_listen("after discard"); + /* * Sensitise RAM - can now generate requests for blocks that don't exi= st * However, at this point the CPU shouldn't be running, and the IO @@ -1977,6 +1980,8 @@ static int loadvm_postcopy_handle_listen(MigrationInc= omingState *mis) } } =20 + trace_loadvm_postcopy_handle_listen("after uffd"); + if (postcopy_notify(POSTCOPY_NOTIFY_INBOUND_LISTEN, &local_err)) { error_report_err(local_err); return -1; @@ -1991,6 +1996,8 @@ static int loadvm_postcopy_handle_listen(MigrationInc= omingState *mis) qemu_sem_wait(&mis->listen_thread_sem); qemu_sem_destroy(&mis->listen_thread_sem); =20 + trace_loadvm_postcopy_handle_listen("return"); + return 0; } =20 diff --git a/migration/trace-events b/migration/trace-events index 123cfe79d7..92596c00d8 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -14,7 +14,7 @@ loadvm_handle_cmd_packaged_main(int ret) "%d" loadvm_handle_cmd_packaged_received(int ret) "%d" loadvm_handle_recv_bitmap(char *s) "%s" loadvm_postcopy_handle_advise(void) "" -loadvm_postcopy_handle_listen(void) "" +loadvm_postcopy_handle_listen(const char *str) "%s" loadvm_postcopy_handle_run(void) "" loadvm_postcopy_handle_run_cpu_sync(void) "" loadvm_postcopy_handle_run_vmstart(void) "" --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644993366709270.7309909639731; Tue, 15 Feb 2022 22:36:06 -0800 (PST) Received: from localhost ([::1]:41672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKDv4-00046b-MI for importer@patchew.org; Wed, 16 Feb 2022 01:36:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDo5-000414-La for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:28:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDo3-0006D1-VM for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:28:53 -0500 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-320-PyGS6uZlOGCLeIEcchPDJw-1; Wed, 16 Feb 2022 01:28:49 -0500 Received: by mail-pg1-f198.google.com with SMTP id r8-20020a638f48000000b0036c6a881088so734593pgn.2 for ; Tue, 15 Feb 2022 22:28:49 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.28.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:28:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fPP+80ZrJlA9hpl1s0Dn0wrbNF8DS14P9IUBr0cEZn8=; b=PNEgDCGfMZwmcJ6RCzoxdYbzBwmGod8TmG83kFHGQxJEI6ArKgFqf3er+rUoLB2d1hbkga jZFeudVss9P6MkQqFg2PEOLqipRBE1F1AZJlNnXFYOyAFFTY5XJTR43aLR9czcM36FbOcC uI/tpoBIx7B37MEgekQicdsEBiDJTlE= X-MC-Unique: PyGS6uZlOGCLeIEcchPDJw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fPP+80ZrJlA9hpl1s0Dn0wrbNF8DS14P9IUBr0cEZn8=; b=trvMfL2wqwS+93VNXlVX6ljQJb9BMSRgee8lIBnlFAi8rLH/aAk/2okscTFbKVw8DP 59tlcs3bh28WwSXqKXyL53G2XJ3Ht5RwxraAhVPUBNlFfiRyhsjfWTCIx9qfT0uly9er rEcNkDXh0Fzs4LV2SUCe8R1IL8DHPRF3KABsw5xxXOD4pMTxf9T3UZAtbGAqkk8DNJBt Mj/BwlKKDzfz1dUVe6mBu1wsZbwGWEagWS6I4KRPgm5T75UJ/IP6du9u/EuXcLinw/6l qRFPByhd8akVHH9o3L378jGm1AXu+nWRnIawNHo9t0TdOuNWmaQcZjYP2bdha0a9OONS LCLw== X-Gm-Message-State: AOAM533nhGSnt6QmS5cSWO6gRcWG4AgbAzTflIjC+jlIDPpy18xONRMa ezCIn61zPUs9hD5JPjsTsax5pBFYLRKSpzCxbqNh1DkUt1g3oMAhM0zWNSv9jYBTZ6/Lc7lT8jb JCkSHIyCPUhui2pEiyOAmZeiwUjYeHn3XPkk3yMwPsFZVkfISOfP0/mOmU2fjVH3G X-Received: by 2002:a17:90b:4a12:b0:1b8:d015:66db with SMTP id kk18-20020a17090b4a1200b001b8d01566dbmr117344pjb.66.1644992928533; Tue, 15 Feb 2022 22:28:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMGpOwRBoOwykO9z3xhLYmoSuKWxOn+rCzuQtqz3UF8u1vRrGkSKuPazDzndc2KTDTL2hv7w== X-Received: by 2002:a17:90b:4a12:b0:1b8:d015:66db with SMTP id kk18-20020a17090b4a1200b001b8d01566dbmr117320pjb.66.1644992928145; Tue, 15 Feb 2022 22:28:48 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 03/20] migration: Tracepoint change in postcopy-run bottom half Date: Wed, 16 Feb 2022 14:27:52 +0800 Message-Id: <20220216062809.57179-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644993378483100001 Content-Type: text/plain; charset="utf-8" Remove the old two tracepoints and they're even near each other: trace_loadvm_postcopy_handle_run_cpu_sync() trace_loadvm_postcopy_handle_run_vmstart() Add trace_loadvm_postcopy_handle_run_bh() with a finer granule trace. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/savevm.c | 12 +++++++++--- migration/trace-events | 3 +-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 190cc5fc42..41e3238798 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2006,13 +2006,19 @@ static void loadvm_postcopy_handle_run_bh(void *opa= que) Error *local_err =3D NULL; MigrationIncomingState *mis =3D opaque; =20 + trace_loadvm_postcopy_handle_run_bh("enter"); + /* TODO we should move all of this lot into postcopy_ram.c or a shared= code * in migration.c */ cpu_synchronize_all_post_init(); =20 + trace_loadvm_postcopy_handle_run_bh("after cpu sync"); + qemu_announce_self(&mis->announce_timer, migrate_announce_params()); =20 + trace_loadvm_postcopy_handle_run_bh("after announce"); + /* Make sure all file formats flush their mutable metadata. * If we get an error here, just don't restart the VM yet. */ bdrv_invalidate_cache_all(&local_err); @@ -2022,9 +2028,7 @@ static void loadvm_postcopy_handle_run_bh(void *opaqu= e) autostart =3D false; } =20 - trace_loadvm_postcopy_handle_run_cpu_sync(); - - trace_loadvm_postcopy_handle_run_vmstart(); + trace_loadvm_postcopy_handle_run_bh("after invalidate cache"); =20 dirty_bitmap_mig_before_vm_start(); =20 @@ -2037,6 +2041,8 @@ static void loadvm_postcopy_handle_run_bh(void *opaqu= e) } =20 qemu_bh_delete(mis->bh); + + trace_loadvm_postcopy_handle_run_bh("return"); } =20 /* After all discards we can start running and asking for pages */ diff --git a/migration/trace-events b/migration/trace-events index 92596c00d8..1aec580e92 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -16,8 +16,7 @@ loadvm_handle_recv_bitmap(char *s) "%s" loadvm_postcopy_handle_advise(void) "" loadvm_postcopy_handle_listen(const char *str) "%s" loadvm_postcopy_handle_run(void) "" -loadvm_postcopy_handle_run_cpu_sync(void) "" -loadvm_postcopy_handle_run_vmstart(void) "" +loadvm_postcopy_handle_run_bh(const char *str) "%s" loadvm_postcopy_handle_resume(void) "" loadvm_postcopy_ram_handle_discard(void) "" loadvm_postcopy_ram_handle_discard_end(void) "" --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644993364008797.2444193119633; Tue, 15 Feb 2022 22:36:04 -0800 (PST) Received: from localhost ([::1]:41464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKDv0-0003y2-QU for importer@patchew.org; Wed, 16 Feb 2022 01:36:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoC-00044U-Vs for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49946) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoA-0006DZ-GV for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:00 -0500 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-84RfrLFkNr-q2CP5BPP_GA-1; Wed, 16 Feb 2022 01:28:56 -0500 Received: by mail-pg1-f198.google.com with SMTP id t18-20020a63dd12000000b00342725203b5so728736pgg.16 for ; Tue, 15 Feb 2022 22:28:56 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.28.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1BnfTLYqettLbQaODOhQ1y2yM9f2SmYaiz0SiZ+kAfI=; b=KX63br9a8rF14uC45QB0H87jH3rGPf9RCZPHB/KO+3Bh0voB7qWVh+76Rk5i+zx8Cq8pBw Zp0Y6SHLGMuxZYmdDX5+Hi3VknzzR+tMqMDhlAZib6hq3azzuPUdnECrkzsWzQVkUxcYg8 DQbwXIu+0bJ6jTqWsLo1WUhAL10z0CM= X-MC-Unique: 84RfrLFkNr-q2CP5BPP_GA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1BnfTLYqettLbQaODOhQ1y2yM9f2SmYaiz0SiZ+kAfI=; b=c7rrnb2a4oq6FBj/BoEkCxXddphtczMSKHuTxVDo/8POJAYdVnZ9OWhM2RhoKVNrti wCriIu/3+pE/jhjcuTcA3FUAINJ9VQk3Ld9ZINhrz5XOTdz0sQDlyYRV33QoSGyhZO21 J6bc0ZrJBsVbLANHG1vQ5Z3vLqa20chi+cUYWFjYyRuaDXhXOUOlfrLx5fl95lQn9LLk 19VmJhWDbEygElUWKFOgVPk52MdUN9xzcK84Y40Wsv9uYOaBYBDz4w6+vpbrX6f6EZsH f19wIPlAHsgaPH3M5muBAkPNUQsNdjiVvXVqVzsXBPOdQblxTCIMgqCrEbai4uVKgrR8 gDaA== X-Gm-Message-State: AOAM530cmeJ8HhKvj8Hr6+JeEPiC1AysI7Mj79qapkLigDge2JrytVnD x8nnWSnJdMIELD57HDfdLqa63LfHdBFYOuVjEahNGMAolCCQBNtNkdvlA+DY73IVm79TZE3VVXb Fb+KeTfXaJlEJkvQSg0XKntrTKF7Puy/CxZM8O38dcna7xQ+g04jdERA9Y0kmv4gl X-Received: by 2002:a17:903:1210:b0:14e:e194:2f2c with SMTP id l16-20020a170903121000b0014ee1942f2cmr1135334plh.130.1644992935349; Tue, 15 Feb 2022 22:28:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9HrPjDhUesZEH+ATs0zbLy911bdBG/Coj9rI1oRRYmZkIPdr34PvsozikSzOF0wSj6kawFA== X-Received: by 2002:a17:903:1210:b0:14e:e194:2f2c with SMTP id l16-20020a170903121000b0014ee1942f2cmr1135296plh.130.1644992934741; Tue, 15 Feb 2022 22:28:54 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 04/20] migration: Introduce postcopy channels on dest node Date: Wed, 16 Feb 2022 14:27:53 +0800 Message-Id: <20220216062809.57179-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644993378508100003 Content-Type: text/plain; charset="utf-8" Postcopy handles huge pages in a special way that currently we can only have one "channel" to transfer the page. It's because when we install pages using UFFDIO_COPY, we need to have the w= hole huge page ready, it also means we need to have a temp huge page when trying= to receive the whole content of the page. Currently all maintainance around this tmp page is global: firstly we'll allocate a temp huge page, then we maintain its status mostly within ram_load_postcopy(). To enable multiple channels for postcopy, the first thing we need to do is = to prepare N temp huge pages as caching, one for each channel. Meanwhile we need to maintain the tmp huge page status per-channel too. To give some example, some local variables maintained in ram_load_postcopy() are listed; they are responsible for maintaining temp huge page status: - all_zero: this keeps whether this huge page contains all zeros - target_pages: this counts how many target pages have been copied - host_page: this keeps the host ptr for the page to install Move all these fields to be together with the temp huge pages to form a new structure called PostcopyTmpPage. Then for each (future) postcopy channel,= we need one structure to keep the state around. For vanilla postcopy, obviously there's only one channel. It contains both precopy and postcopy pages. This patch teaches the dest migration node to start realize the possible nu= mber of postcopy channels by introducing the "postcopy_channels" variable. Its value is calculated when setup postcopy on dest node (during POSTCOPY_LISTEN phase). Vanilla postcopy will have channels=3D1, but when postcopy-preempt capabili= ty is enabled (in the future), we will boost it to 2 because even during partial sending of a precopy huge page we still want to preempt it and start sending the postcopy requested page right away (so we start to keep two temp huge pages; more if we want to enable multifd). In this patch there's a TODO ma= rked for that; so far the channels is always set to 1. We need to send one "host huge page" on one channel only and we cannot split them, because otherwise the data upon the same huge page can locate on more than one channel so we need more complicated logic to manage. One temp host huge page for each channel will be enough for us for now. Postcopy will still always use the index=3D0 huge page even after this patc= h. However it prepares for the latter patches where it can start to use multip= le channels (which needs src intervention, because only src knows which channe= l we should use). Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.h | 36 +++++++++++++++++++++++- migration/postcopy-ram.c | 60 ++++++++++++++++++++++++++++++---------- migration/ram.c | 43 ++++++++++++++-------------- migration/savevm.c | 12 ++++++++ 4 files changed, 113 insertions(+), 38 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 8130b703eb..42c7395094 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -45,6 +45,24 @@ struct PostcopyBlocktimeContext; */ #define CLEAR_BITMAP_SHIFT_MAX 31 =20 +/* This is an abstraction of a "temp huge page" for postcopy's purpose */ +typedef struct { + /* + * This points to a temporary huge page as a buffer for UFFDIO_COPY. = It's + * mmap()ed and needs to be freed when cleanup. + */ + void *tmp_huge_page; + /* + * This points to the host page we're going to install for this temp p= age. + * It tells us after we've received the whole page, where we should pu= t it. + */ + void *host_addr; + /* Number of small pages copied (in size of TARGET_PAGE_SIZE) */ + unsigned int target_pages; + /* Whether this page contains all zeros */ + bool all_zero; +} PostcopyTmpPage; + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -81,7 +99,22 @@ struct MigrationIncomingState { QemuMutex rp_mutex; /* We send replies from multiple threads */ /* RAMBlock of last request sent to source */ RAMBlock *last_rb; - void *postcopy_tmp_page; + /* + * Number of postcopy channels including the default precopy channel, = so + * vanilla postcopy will only contain one channel which contain both + * precopy and postcopy streams. + * + * This is calculated when the src requests to enable postcopy but bef= ore + * it starts. Its value can depend on e.g. whether postcopy preemptio= n is + * enabled. + */ + unsigned int postcopy_channels; + /* + * An array of temp host huge pages to be used, one for each postcopy + * channel. + */ + PostcopyTmpPage *postcopy_tmp_pages; + /* This is shared for all postcopy channels */ void *postcopy_tmp_zero_page; /* PostCopyFD's for external userfaultfds & handlers of shared memory = */ GArray *postcopy_remote_fds; @@ -391,5 +424,6 @@ bool migration_rate_limit(void); void migration_cancel(const Error *error); =20 void populate_vfio_info(MigrationInfo *info); +void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page); =20 #endif diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index e662dd05cc..315f784965 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -525,9 +525,18 @@ int postcopy_ram_incoming_init(MigrationIncomingState = *mis) =20 static void postcopy_temp_pages_cleanup(MigrationIncomingState *mis) { - if (mis->postcopy_tmp_page) { - munmap(mis->postcopy_tmp_page, mis->largest_page_size); - mis->postcopy_tmp_page =3D NULL; + int i; + + if (mis->postcopy_tmp_pages) { + for (i =3D 0; i < mis->postcopy_channels; i++) { + if (mis->postcopy_tmp_pages[i].tmp_huge_page) { + munmap(mis->postcopy_tmp_pages[i].tmp_huge_page, + mis->largest_page_size); + mis->postcopy_tmp_pages[i].tmp_huge_page =3D NULL; + } + } + g_free(mis->postcopy_tmp_pages); + mis->postcopy_tmp_pages =3D NULL; } =20 if (mis->postcopy_tmp_zero_page) { @@ -1091,17 +1100,30 @@ retry: =20 static int postcopy_temp_pages_setup(MigrationIncomingState *mis) { - int err; - - 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) { - err =3D errno; - mis->postcopy_tmp_page =3D NULL; - error_report("%s: Failed to map postcopy_tmp_page %s", - __func__, strerror(err)); - return -err; + PostcopyTmpPage *tmp_page; + int err, i, channels; + void *temp_page; + + /* TODO: will be boosted when enable postcopy preemption */ + mis->postcopy_channels =3D 1; + + channels =3D mis->postcopy_channels; + mis->postcopy_tmp_pages =3D g_malloc0_n(sizeof(PostcopyTmpPage), chann= els); + + for (i =3D 0; i < channels; i++) { + tmp_page =3D &mis->postcopy_tmp_pages[i]; + temp_page =3D mmap(NULL, mis->largest_page_size, PROT_READ | PROT_= WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (temp_page =3D=3D MAP_FAILED) { + err =3D errno; + error_report("%s: Failed to map postcopy_tmp_pages[%d]: %s", + __func__, i, strerror(err)); + /* Clean up will be done later */ + return -err; + } + tmp_page->tmp_huge_page =3D temp_page; + /* Initialize default states for each tmp page */ + postcopy_temp_page_reset(tmp_page); } =20 /* @@ -1351,6 +1373,16 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, #endif =20 /* -----------------------------------------------------------------------= -- */ +void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page) +{ + tmp_page->target_pages =3D 0; + tmp_page->host_addr =3D NULL; + /* + * This is set to true when reset, and cleared as long as we received = any + * of the non-zero small page within this huge page. + */ + tmp_page->all_zero =3D true; +} =20 void postcopy_fault_thread_notify(MigrationIncomingState *mis) { diff --git a/migration/ram.c b/migration/ram.c index 91ca743ac8..36b0a53afe 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3640,11 +3640,8 @@ static int ram_load_postcopy(QEMUFile *f) bool place_needed =3D false; 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 mis->postcopy_tmp_page; - void *host_page =3D NULL; - bool all_zero =3D true; - int target_pages =3D 0; + /* Currently we only use channel 0. TODO: use all the channels */ + PostcopyTmpPage *tmp_page =3D &mis->postcopy_tmp_pages[0]; =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr; @@ -3688,7 +3685,7 @@ static int ram_load_postcopy(QEMUFile *f) ret =3D -EINVAL; break; } - target_pages++; + tmp_page->target_pages++; matches_target_page_size =3D block->page_size =3D=3D TARGET_PA= GE_SIZE; /* * Postcopy requires that we place whole host pages atomically; @@ -3700,15 +3697,16 @@ static int ram_load_postcopy(QEMUFile *f) * however the source ensures it always sends all the componen= ts * of a host page in one chunk. */ - page_buffer =3D postcopy_host_page + + page_buffer =3D tmp_page->tmp_huge_page + host_page_offset_from_ram_block_offset(block, ad= dr); /* If all TP are zero then we can optimise the place */ - if (target_pages =3D=3D 1) { - host_page =3D host_page_from_ram_block_offset(block, addr); - } else if (host_page !=3D host_page_from_ram_block_offset(bloc= k, - addr))= { + if (tmp_page->target_pages =3D=3D 1) { + tmp_page->host_addr =3D + host_page_from_ram_block_offset(block, addr); + } else if (tmp_page->host_addr !=3D + host_page_from_ram_block_offset(block, addr)) { /* not the 1st TP within the HP */ - error_report("Non-same host page %p/%p", host_page, + error_report("Non-same host page %p/%p", tmp_page->host_ad= dr, host_page_from_ram_block_offset(block, addr)); ret =3D -EINVAL; break; @@ -3718,10 +3716,11 @@ static int ram_load_postcopy(QEMUFile *f) * If it's the last part of a host page then we place the host * page */ - if (target_pages =3D=3D (block->page_size / TARGET_PAGE_SIZE))= { + if (tmp_page->target_pages =3D=3D + (block->page_size / TARGET_PAGE_SIZE)) { place_needed =3D true; } - place_source =3D postcopy_host_page; + place_source =3D tmp_page->tmp_huge_page; } =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { @@ -3735,12 +3734,12 @@ static int ram_load_postcopy(QEMUFile *f) memset(page_buffer, ch, TARGET_PAGE_SIZE); } if (ch) { - all_zero =3D false; + tmp_page->all_zero =3D false; } break; =20 case RAM_SAVE_FLAG_PAGE: - all_zero =3D false; + tmp_page->all_zero =3D false; if (!matches_target_page_size) { /* For huge pages, we always use temporary buffer */ qemu_get_buffer(f, page_buffer, TARGET_PAGE_SIZE); @@ -3758,7 +3757,7 @@ static int ram_load_postcopy(QEMUFile *f) } break; case RAM_SAVE_FLAG_COMPRESS_PAGE: - all_zero =3D false; + tmp_page->all_zero =3D false; len =3D qemu_get_be32(f); if (len < 0 || len > compressBound(TARGET_PAGE_SIZE)) { error_report("Invalid compressed data length: %d", len); @@ -3790,16 +3789,14 @@ static int ram_load_postcopy(QEMUFile *f) } =20 if (!ret && place_needed) { - if (all_zero) { - ret =3D postcopy_place_page_zero(mis, host_page, block); + if (tmp_page->all_zero) { + ret =3D postcopy_place_page_zero(mis, tmp_page->host_addr,= block); } else { - ret =3D postcopy_place_page(mis, host_page, place_source, + ret =3D postcopy_place_page(mis, tmp_page->host_addr, plac= e_source, block); } place_needed =3D false; - target_pages =3D 0; - /* Assume we have a zero page until we detect something differ= ent */ - all_zero =3D true; + postcopy_temp_page_reset(tmp_page); } } =20 diff --git a/migration/savevm.c b/migration/savevm.c index 41e3238798..0ccd7e5e3f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2579,6 +2579,18 @@ void qemu_loadvm_state_cleanup(void) /* Return true if we should continue the migration, or false. */ static bool postcopy_pause_incoming(MigrationIncomingState *mis) { + int i; + + /* + * If network is interrupted, any temp page we received will be useless + * because we didn't mark them as "received" in receivedmap. After a + * proper recovery later (which will sync src dirty bitmap with receiv= edmap + * on dest) these cached small pages will be resent again. + */ + for (i =3D 0; i < mis->postcopy_channels; i++) { + postcopy_temp_page_reset(&mis->postcopy_tmp_pages[i]); + } + trace_postcopy_pause_incoming(); =20 assert(migrate_postcopy_ram()); --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164499337961261.91028517973541; Tue, 15 Feb 2022 22:36:19 -0800 (PST) Received: from localhost ([::1]:42188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKDvH-0004T1-QW for importer@patchew.org; Wed, 16 Feb 2022 01:36:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoO-00049M-O9 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoL-0006F3-8Z for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:12 -0500 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-uQPKOwJNOae_kNsfEUP35A-1; Wed, 16 Feb 2022 01:29:03 -0500 Received: by mail-pf1-f198.google.com with SMTP id c192-20020a621cc9000000b004e0ff94313dso915197pfc.17 for ; Tue, 15 Feb 2022 22:29:02 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.28.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6zOELQqI2MPt8MdKn+c1VGRueIHRXa9jNGDaxs4L/0o=; b=JrlzQ0qra9qcTLtKozCuxnn5W4CRuI1PpYb2hGEz21YgNnUSpSQFpm4Vyval50yG375prl dJ6syXFLDXK2GpJZeLHw2L6Y3+CP5l4yWn/4wtbLIT5B/xvMdDoyasRmmtWB3ELviYSPYs 7PzUDBUXowJyXVQ06TzLQZ3nXkuioi8= X-MC-Unique: uQPKOwJNOae_kNsfEUP35A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6zOELQqI2MPt8MdKn+c1VGRueIHRXa9jNGDaxs4L/0o=; b=dP88xFJ0MhbBop9VeuVYvPqMQF1BltXjU7djcyAf12QU1n30rAzak034Ql6mxNMBSr TCGowHoAA7i6zlUuF1ThsAtScvjGvLX1MQAfD4iMbnROgp+EcJRNuGui5QY4nzkNBLgc HoCgXMWlpyUPg8+U+6rPa6F/Dsx22sjZeHkENWSpd7SWho5s2qfCFrvVUyfhLoPUSLnz 1LFmIdgOb68NpaUbkcpYSCqIg2pf42agT9+bTV8k3ivMkRiOMUcBWeaOlNySTnft3h0Y qJBK4CrQIe3oZQcTRr/x8bIlQi8fpLBy+Q/L/9FURgiJw6zNn0b3ztekwW037EZ11gVc TXkQ== X-Gm-Message-State: AOAM530Ss7sgZFALw7y8lvOQDZWsRZtjaYtT1PCWbPMynLMMuAWfhvjl 0laSI+zhMVL0NK79p/ggHiTwT8GT9mpVFEpQ9wZn/8z1p1W1PvIvXv2BiewvvYySPTFazjTD9Yb mXLRHq1y6wQxXmCm4BtD4+n3YobefQoqFdgBtoDdyKvG/yAb3k4fR1VQBTKrjAt52 X-Received: by 2002:a05:6a00:1301:b0:4e1:3dd:16d0 with SMTP id j1-20020a056a00130100b004e103dd16d0mr1230422pfu.21.1644992941870; Tue, 15 Feb 2022 22:29:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwHSeyIhDLvVIC6Uf3kzs6ZpqU16lbJEdUElGFBttLDS9DHhHWG81+G2TIwr1Y3iMz8/d8oA== X-Received: by 2002:a05:6a00:1301:b0:4e1:3dd:16d0 with SMTP id j1-20020a056a00130100b004e103dd16d0mr1230397pfu.21.1644992941492; Tue, 15 Feb 2022 22:29:01 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 05/20] migration: Dump ramblock and offset too when non-same-page detected Date: Wed, 16 Feb 2022 14:27:54 +0800 Message-Id: <20220216062809.57179-6-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644993381471100001 Content-Type: text/plain; charset="utf-8" In ram_load_postcopy() we'll try to detect non-same-page case and dump erro= r. This error is very helpful for debugging. Adding ramblock & offset into the error log too. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/ram.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 36b0a53afe..87bcb704d4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3706,8 +3706,12 @@ static int ram_load_postcopy(QEMUFile *f) } else if (tmp_page->host_addr !=3D host_page_from_ram_block_offset(block, addr)) { /* not the 1st TP within the HP */ - error_report("Non-same host page %p/%p", tmp_page->host_ad= dr, - host_page_from_ram_block_offset(block, addr)); + error_report("Non-same host page detected. Target host pa= ge %p, " + "received host page %p " + "(rb %s offset 0x"RAM_ADDR_FMT" target_pages = %d)", + tmp_page->host_addr, + host_page_from_ram_block_offset(block, addr), + block->idstr, addr, tmp_page->target_pages); ret =3D -EINVAL; break; } --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644994379014607.2148713234399; Tue, 15 Feb 2022 22:52:59 -0800 (PST) Received: from localhost ([::1]:50518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEBP-0002Uv-40 for importer@patchew.org; Wed, 16 Feb 2022 01:52:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoQ-0004A3-HI for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60942) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoO-0006Fc-Pq for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:14 -0500 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-53-fu2_qw0COyuFjw1DujZzqA-1; Wed, 16 Feb 2022 01:29:10 -0500 Received: by mail-pj1-f72.google.com with SMTP id g19-20020a17090a579300b001b9d80f3714so938922pji.7 for ; Tue, 15 Feb 2022 22:29:10 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Dc2Vi2zj/693dIJ2nS//TnSj/P3rpIaVxMb6s1Xx0U=; b=IfjbCz5Q7CHUPy3tczOoWrJYj4ldeXRuuC75joqprDdjHlJaJ22kW5P39P7NgdCng7QU3i mCnky8bZpc97thDLduNQr27iKxX/6GAn13DJr3JYH2v2dGV+L2QQotOKxoGqJUFPz1UVDC 9icUbNSf6tdfIxsiLpy6PxyNy7RM7Gs= X-MC-Unique: fu2_qw0COyuFjw1DujZzqA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Dc2Vi2zj/693dIJ2nS//TnSj/P3rpIaVxMb6s1Xx0U=; b=Pf5UI6YOZUufr0p7CNPWvNQeexkNWUAJ24jpEgEPtQQqK1PWplRDpdculiWHNvILz3 UAgSuJ/YNJ/HlkuakcQRoKr6n3ilNq6mJWKQb3QCA7ZXeOmvz6Y6IKDoCwMHFCq5giqn 0bx9A5uzkkMJciADgSNgCqZBpz6yaSic5RCAo33IulV5mxUh4DcblQV8ng/DLnuyWKWh ssFkNblUOYXukbCgY5VGzb9jG7Tv6m5o7Dip/DEYBUMgGnrDAj9zWO3GwKu1nZbDYKIE XxYq9RlPK0jBTkvr50jaYNagbZnFJTgDxgprlWp+NzoYbgfTU8hxfuocK9uUV4vO3G5i cQxw== X-Gm-Message-State: AOAM532KJqKTe2iail47k8KoN9OWjsE+G5Hn/42h7qmPEMcR1+Eyu91U gLBzQqEZJRjN6XUyvNBpgR0AoOdEYZm15svKesGf+cmCqoAB5qpKZUDyBz4eQNx+Uruz7lo+Ywb +yehq2Mg5pShpdiXmLlvxQCRkgdkdbrdkIRLdzYGpb6/6nl5UxdkanVMaZZoRv81d X-Received: by 2002:a17:902:9f96:b0:14f:1b7f:d5 with SMTP id g22-20020a1709029f9600b0014f1b7f00d5mr1439142plq.126.1644992948896; Tue, 15 Feb 2022 22:29:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzn7fuCz3WIYS+/waBLZ7Yr/451j0PJTgscnUQaZyZjZACXg1XBc1Qu+l8j5mVh4PxsmOLUOQ== X-Received: by 2002:a17:902:9f96:b0:14f:1b7f:d5 with SMTP id g22-20020a1709029f9600b0014f1b7f00d5mr1439114plq.126.1644992948428; Tue, 15 Feb 2022 22:29:08 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 06/20] migration: Add postcopy_thread_create() Date: Wed, 16 Feb 2022 14:27:55 +0800 Message-Id: <20220216062809.57179-7-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644994402150100001 Content-Type: text/plain; charset="utf-8" Postcopy create threads. A common manner is we init a sem and use it to sync with the thread. Namely, we have fault_thread_sem and listen_thread_sem and they're only used for this. Make it a shared infrastructure so it's easier to create yet another thread. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.h | 8 +++++--- migration/postcopy-ram.c | 23 +++++++++++++++++------ migration/postcopy-ram.h | 4 ++++ migration/savevm.c | 12 +++--------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 42c7395094..8445e1d14a 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -70,7 +70,11 @@ struct MigrationIncomingState { /* A hook to allow cleanup at the end of incoming migration */ void *transport_data; void (*transport_cleanup)(void *data); - + /* + * Used to sync thread creations. Note that we can't create threads in + * parallel with this sem. + */ + QemuSemaphore thread_sync_sem; /* * Free at the start of the main state load, set as the main thread fi= nishes * loading state. @@ -83,13 +87,11 @@ struct MigrationIncomingState { size_t largest_page_size; bool have_fault_thread; QemuThread fault_thread; - QemuSemaphore fault_thread_sem; /* Set this when we want the fault thread to quit */ bool fault_thread_quit; =20 bool have_listen_thread; QemuThread listen_thread; - QemuSemaphore listen_thread_sem; =20 /* For the kernel to send us notifications */ int userfault_fd; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 315f784965..d3ec22e6de 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -77,6 +77,20 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Er= ror **errp) &pnd); } =20 +/* + * NOTE: this routine is not thread safe, we can't call it concurrently. B= ut it + * should be good enough for migration's purposes. + */ +void postcopy_thread_create(MigrationIncomingState *mis, + QemuThread *thread, const char *name, + void *(*fn)(void *), int joinable) +{ + qemu_sem_init(&mis->thread_sync_sem, 0); + qemu_thread_create(thread, name, fn, mis, joinable); + qemu_sem_wait(&mis->thread_sync_sem); + qemu_sem_destroy(&mis->thread_sync_sem); +} + /* Postcopy needs to detect accesses to pages that haven't yet been copied * across, and efficiently map new pages in, the techniques for doing this * are target OS specific. @@ -901,7 +915,7 @@ static void *postcopy_ram_fault_thread(void *opaque) trace_postcopy_ram_fault_thread_entry(); rcu_register_thread(); mis->last_rb =3D NULL; /* last RAMBlock we sent part of */ - qemu_sem_post(&mis->fault_thread_sem); + qemu_sem_post(&mis->thread_sync_sem); =20 struct pollfd *pfd; size_t pfd_len =3D 2 + mis->postcopy_remote_fds->len; @@ -1172,11 +1186,8 @@ int postcopy_ram_incoming_setup(MigrationIncomingSta= te *mis) return -1; } =20 - qemu_sem_init(&mis->fault_thread_sem, 0); - qemu_thread_create(&mis->fault_thread, "postcopy/fault", - postcopy_ram_fault_thread, mis, QEMU_THREAD_JOINABL= E); - qemu_sem_wait(&mis->fault_thread_sem); - qemu_sem_destroy(&mis->fault_thread_sem); + postcopy_thread_create(mis, &mis->fault_thread, "postcopy/fault", + postcopy_ram_fault_thread, QEMU_THREAD_JOINABLE= ); mis->have_fault_thread =3D true; =20 /* Mark so that we get notified of accesses to unwritten areas */ diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 6d2b3cf124..07684c0e1d 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -135,6 +135,10 @@ void postcopy_remove_notifier(NotifierWithReturn *n); /* Call the notifier list set by postcopy_add_start_notifier */ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp); =20 +void postcopy_thread_create(MigrationIncomingState *mis, + QemuThread *thread, const char *name, + void *(*fn)(void *), int joinable); + struct PostCopyFD; =20 /* ufd is a pointer to the struct uffd_msg *TODO: more Portable! */ diff --git a/migration/savevm.c b/migration/savevm.c index 0ccd7e5e3f..967ff80547 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1863,7 +1863,7 @@ static void *postcopy_ram_listen_thread(void *opaque) =20 migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); - qemu_sem_post(&mis->listen_thread_sem); + qemu_sem_post(&mis->thread_sync_sem); trace_postcopy_ram_listen_thread_start(); =20 rcu_register_thread(); @@ -1988,14 +1988,8 @@ static int loadvm_postcopy_handle_listen(MigrationIn= comingState *mis) } =20 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); - qemu_thread_create(&mis->listen_thread, "postcopy/listen", - postcopy_ram_listen_thread, NULL, - QEMU_THREAD_DETACHED); - qemu_sem_wait(&mis->listen_thread_sem); - qemu_sem_destroy(&mis->listen_thread_sem); - + postcopy_thread_create(mis, &mis->listen_thread, "postcopy/listen", + postcopy_ram_listen_thread, QEMU_THREAD_DETACHE= D); trace_loadvm_postcopy_handle_listen("return"); =20 return 0; --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644994670347387.3200403698404; Tue, 15 Feb 2022 22:57:50 -0800 (PST) Received: from localhost ([::1]:59060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEG5-0008Ua-0x for importer@patchew.org; Wed, 16 Feb 2022 01:57:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoX-0004Cr-4d for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoV-0006G5-F7 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:20 -0500 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-77-NAHlIRsEPQCax3Ye7WhBCg-1; Wed, 16 Feb 2022 01:29:16 -0500 Received: by mail-pl1-f197.google.com with SMTP id a9-20020a170902710900b0014c8132e8b8so692190pll.10 for ; Tue, 15 Feb 2022 22:29:16 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Uuc2E+EfBukjB/OnF38Q+6+6JPtsSsK8uR7HjiUeUk=; b=D+qb+21PI1uwBqf5gF1pVfVI9nbYndp4UU/3XrAq/WHQIv4u/cqd6ov62gLt9elynrSAFN O8zzhuHVxZ63yhb4X2xQrZl4BhMDDszWI9BQFw/TG0UsZ9rs4OrIlJl+UqLsKFIL2141gJ jOwz0fYSyHK8DLjQ5zFB88YnjcZd2eE= X-MC-Unique: NAHlIRsEPQCax3Ye7WhBCg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Uuc2E+EfBukjB/OnF38Q+6+6JPtsSsK8uR7HjiUeUk=; b=3On6q8F1dEYrRofrbJOaXSoLK2uJkPVngYdvsV3W2M6YWoIUbU6IoPepjYgHWy4Zv1 rwp4PNt2b20GIchgBhQ2F5WyAQDoxBX4tCbGLr6uY3ldRGQjbzxFDlUxUwvQCtAjP684 +bH24w38+wXhpcEbrF4iAGbV0H3GgOqjPBCfru9FJKhRWF6OkIbwgEZDxXLeUolLXa1A wl2cNMOu8/Cfrej5i8W2evw+es1dBQvtWDKmMnWzLqvDHNZGV+/Nd8/P0CyPheZ104sH LgLWhwyIRRUOoDfrf0gZnsahre0KcYY2t7rfRieCx2NqxywNv/iQJwCe5zwjr+gMYJG+ r1kA== X-Gm-Message-State: AOAM532gEjY2foKj+X0aPQbj+tRjDmLGBReAMt2WbdMOI4GUUICsNVm2 OWBqnBe8LORvrF/KhjL613/6h1p8P5b4LsCKaaXJw0mpds36/jO2RrFyry3asl+/F8LoIIlWNMo rLc/pz6+MdbRBp3Mr2qfPc8JVudk+1ehx+hAd/nyaXOdTULbbCX1YqBzvAQZaZKK0 X-Received: by 2002:a17:902:dace:b0:14e:e471:a9c3 with SMTP id q14-20020a170902dace00b0014ee471a9c3mr1421561plx.49.1644992955567; Tue, 15 Feb 2022 22:29:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/OlJT5yRwQfYcUWN1GIn5VZDYnBGrVxOgEY+rNL9zJk151AOZ/4UruV/vGbOGY543JMAOxQ== X-Received: by 2002:a17:902:dace:b0:14e:e471:a9c3 with SMTP id q14-20020a170902dace00b0014ee471a9c3mr1421538plx.49.1644992955193; Tue, 15 Feb 2022 22:29:15 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 07/20] migration: Move static var in ram_block_from_stream() into global Date: Wed, 16 Feb 2022 14:27:56 +0800 Message-Id: <20220216062809.57179-8-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644994671966100001 Content-Type: text/plain; charset="utf-8" Static variable is very unfriendly to threading of ram_block_from_stream(). Move it into MigrationIncomingState. Make the incoming state pointer to be passed over to ram_block_from_stream(= ) on both caller sites. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.h | 3 ++- migration/ram.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 8445e1d14a..d8b9850eae 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -66,7 +66,8 @@ typedef struct { /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; - + /* Previously received RAM's RAMBlock pointer */ + RAMBlock *last_recv_block; /* A hook to allow cleanup at the end of incoming migration */ void *transport_data; void (*transport_cleanup)(void *data); diff --git a/migration/ram.c b/migration/ram.c index 87bcb704d4..25a3ab5150 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3184,12 +3184,14 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr= , void *host) * * Returns a pointer from within the RCU-protected ram_list. * + * @mis: the migration incoming state pointer * @f: QEMUFile where to read the data from * @flags: Page flags (mostly to see if it's a continuation of previous bl= ock) */ -static inline RAMBlock *ram_block_from_stream(QEMUFile *f, int flags) +static inline RAMBlock *ram_block_from_stream(MigrationIncomingState *mis, + QEMUFile *f, int flags) { - static RAMBlock *block; + RAMBlock *block =3D mis->last_recv_block; char id[256]; uint8_t len; =20 @@ -3216,6 +3218,8 @@ static inline RAMBlock *ram_block_from_stream(QEMUFil= e *f, int flags) return NULL; } =20 + mis->last_recv_block =3D block; + return block; } =20 @@ -3668,7 +3672,7 @@ static int ram_load_postcopy(QEMUFile *f) trace_ram_load_postcopy_loop((uint64_t)addr, flags); if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE)) { - block =3D ram_block_from_stream(f, flags); + block =3D ram_block_from_stream(mis, f, flags); if (!block) { ret =3D -EINVAL; break; @@ -3880,6 +3884,7 @@ void colo_flush_ram_cache(void) */ static int ram_load_precopy(QEMUFile *f) { + MigrationIncomingState *mis =3D migration_incoming_get_current(); int flags =3D 0, ret =3D 0, invalid_flags =3D 0, len =3D 0, i =3D 0; /* ADVISE is earlier, it shows the source has the postcopy capability = on */ bool postcopy_advised =3D postcopy_is_advised(); @@ -3918,7 +3923,7 @@ static int ram_load_precopy(QEMUFile *f) =20 if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { - RAMBlock *block =3D ram_block_from_stream(f, flags); + RAMBlock *block =3D ram_block_from_stream(mis, f, flags); =20 host =3D host_from_ram_block_offset(block, addr); /* --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644994930667440.4523484931367; Tue, 15 Feb 2022 23:02:10 -0800 (PST) Received: from localhost ([::1]:39180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEKH-0005dF-Bq for importer@patchew.org; Wed, 16 Feb 2022 02:02:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDod-0004Fz-9i for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:36762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDob-0006Go-Gd for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:26 -0500 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-AJwayvHvMqS6qqZU0vIvuw-1; Wed, 16 Feb 2022 01:29:23 -0500 Received: by mail-pj1-f71.google.com with SMTP id q40-20020a17090a17ab00b001bafa89b70aso868378pja.2 for ; Tue, 15 Feb 2022 22:29:23 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uqoEel/aQ2/EMHLZUVdA76gOV6xHTWZL7xjBPEinNUI=; b=Ic/SwIOU4ePiWlcVmb0cJiMOnv2c8EW0owX+W7J+Ryh2QgLnfIGDSZKAw5V950dlK2NCxY wSroJrfywTBf0Qw0YNTPVtngBAdpTaxaWJndSH2wyp5hhJm6rs54/TKffc7j9lkTsYVSPL fJtj3TIPvL4sEKZ1YN8NTc5tJyDx9h8= X-MC-Unique: AJwayvHvMqS6qqZU0vIvuw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uqoEel/aQ2/EMHLZUVdA76gOV6xHTWZL7xjBPEinNUI=; b=nbZfQZtwWu4DHv3UHE/8qgh2O64qU8ptmn8FlWpVMXqVwnCOD+vXVOffkMwN0xDW7z K0pLAKXYYvHg+fawhMDj1MswZQuHS3qtPX69LMfsxoUhrEGQfs2dOVdK0bx+967dBFzS 2J9A0vm4lN6MSi+QNUzlbpZHV+AzFAShHdD8SadWbChjWK05MsI/7S1U+EadKQMX8juj dZUY5RUTDYPzrDjC97O3lmzveIP5y8Wm00lh3s5rD0AKBpCYwjkxgCOi/6X/sJVvxXXt DLO4Vi7RxcrQY0wac4oCFxPqkOXZE9FGM+eOVOKw2sIp5IfYi4h/sx7SWSDl4lRVy2yp +veA== X-Gm-Message-State: AOAM532FuU5KIvMGokWGd3Q0CsV0oJgDwBPO4jBS3KHrHwl7FJ4b+o+3 +/l+HbKiS12r4twYsWqXA27hyT9o74LOd2fukNEgIanyS//aPxcYzBEEpvlerm+YDc4fJdpk6JK GYrVTUU7ZT7/eQoHhbYFkA54ywB6M53OhdxtbyVze3y1PCsbqI4NRYVlyCPMCL4Vg X-Received: by 2002:a05:6a00:1810:b0:4e1:2d4f:14aa with SMTP id y16-20020a056a00181000b004e12d4f14aamr1206051pfa.43.1644992962479; Tue, 15 Feb 2022 22:29:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnbVcMOLTbjpOKLhe6BgbMMLXwwWks8u0Ledv/ePC16s9RVg5PGtp8m6TRlyECT1jF3w+BLg== X-Received: by 2002:a05:6a00:1810:b0:4e1:2d4f:14aa with SMTP id y16-20020a056a00181000b004e12d4f14aamr1206020pfa.43.1644992962132; Tue, 15 Feb 2022 22:29:22 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 08/20] migration: Add pss.postcopy_requested status Date: Wed, 16 Feb 2022 14:27:57 +0800 Message-Id: <20220216062809.57179-9-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644994931544100001 Content-Type: text/plain; charset="utf-8" This boolean flag shows whether the current page during migration is trigge= red by postcopy or not. Then in ram_save_host_page() and deeper stack we'll be able to have a reference on the priority of this page. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/ram.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 25a3ab5150..1ed70b17d7 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -413,6 +413,8 @@ struct PageSearchStatus { unsigned long page; /* Set once we wrap around */ bool complete_round; + /* Whether current page is explicitly requested by postcopy */ + bool postcopy_requested; }; typedef struct PageSearchStatus PageSearchStatus; =20 @@ -1486,6 +1488,9 @@ retry: */ static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, bool *ag= ain) { + /* This is not a postcopy requested page */ + pss->postcopy_requested =3D false; + pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->page); if (pss->complete_round && pss->block =3D=3D rs->last_seen_block && pss->page >=3D rs->last_page) { @@ -1980,6 +1985,7 @@ static bool get_queued_page(RAMState *rs, PageSearchS= tatus *pss) * really rare. */ pss->complete_round =3D false; + pss->postcopy_requested =3D true; } =20 return !!block; --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644994286063375.7448052000814; Tue, 15 Feb 2022 22:51:26 -0800 (PST) Received: from localhost ([::1]:49990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKE9s-00022w-33 for importer@patchew.org; Wed, 16 Feb 2022 01:51:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDot-0004V5-EY for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoj-0006HO-41 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:34 -0500 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-ZoImtIK2PNqawnGJ6LSuIw-1; Wed, 16 Feb 2022 01:29:31 -0500 Received: by mail-pl1-f198.google.com with SMTP id v20-20020a1709028d9400b0014ca63d0f10so694657plo.5 for ; Tue, 15 Feb 2022 22:29:31 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZXUvDOAZVCZx2PDK+m45rb6PvTxxwhcJ0/eKmX4lZqw=; b=hHgafPmp81815da5oDnxKrBNRbPTcjl/roKDbOn4X09hLvn9VBszH8epJDphk9NXQldPN0 2ae1ZWq6cA2989bnLX5WmeKgiJ9361F0lU8Dzr63s0Y+HgPYLX7m7NeyLu7wA7kss2wXBx Fu7rYw9zl5plegN40WpOU5ezZK7RqNo= X-MC-Unique: ZoImtIK2PNqawnGJ6LSuIw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXUvDOAZVCZx2PDK+m45rb6PvTxxwhcJ0/eKmX4lZqw=; b=zT3lTx7VJrGq4pIa0KsGJBmoOrm5hg0tdhY7itCn5dk7HI6g6pYhEnztZerd1ghGB6 pKl2LAGaAEZPn1rB3wEVnTm1IKMm0zOtE9i7RhCXyjScQpaxp4+ZQKygw4y4tXYym4rY TDV0Ch18M/rpNQ5k9GAUicyX+2w4oCNu4Cr4HWQrOUGD6Tn+TqqdmF+ty1eYRdjhmb6Q dbq7SxwOTusyBoRvFq3+ks5NVdYtuBZAEfinGSwreFrKRRsSrvIp6z8kID8pbSPhlvfZ Z7BEPCQ4yCoIEUXYJAa0hsZcVDQw4HUgVIhfom3ciE9VH4uF2lhZ+GD7HGvei80pTJ7l muRw== X-Gm-Message-State: AOAM533+uDWUlAw3IZfQJcCGd7MFvwCunfxiir+pgqi0hcWw+Kcxb9Rv ugQklYtbnp/S8bZTqowxjo5VzJB3rdl9x7NdZVJAPr84IdqSOaq2LST0Y8LE/QhVMdT8CSY9UlZ TnbOwv9VbhVz0AK8IbhXqql1uhOIfa2OOc1B5z6ekYt7hjBaOyhK4Rvcy9uBQAqRz X-Received: by 2002:a05:6a00:a8b:b0:4cd:6030:4df3 with SMTP id b11-20020a056a000a8b00b004cd60304df3mr1621430pfl.40.1644992969891; Tue, 15 Feb 2022 22:29:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjUbM2ToiOaOt764b0VRyWBRyPC+Xb0s0RSEoBuGyj9Dtav2FJo6TRHrr5nSk2+IkwnH9cKw== X-Received: by 2002:a05:6a00:a8b:b0:4cd:6030:4df3 with SMTP id b11-20020a056a000a8b00b004cd60304df3mr1621404pfl.40.1644992969423; Tue, 15 Feb 2022 22:29:29 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 09/20] migration: Move migrate_allow_multifd and helpers into migration.c Date: Wed, 16 Feb 2022 14:27:58 +0800 Message-Id: <20220216062809.57179-10-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644994287625100001 Content-Type: text/plain; charset="utf-8" This variable, along with its helpers, is used to detect whether multiple channel will be supported for migration. In follow up patches, there'll be other capability that requires multi-channels. Hence move it outside multi= fd specific code and make it public. Meanwhile rename it from "multifd" to "multi_channels" to show its real meaning. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 22 +++++++++++++++++----- migration/migration.h | 3 +++ migration/multifd.c | 19 ++++--------------- migration/multifd.h | 2 -- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index bcc385b94b..6e4cc9cc87 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -180,6 +180,18 @@ static int migration_maybe_pause(MigrationState *s, int new_state); static void migrate_fd_cancel(MigrationState *s); =20 +static bool migrate_allow_multi_channels =3D true; + +void migrate_protocol_allow_multi_channels(bool allow) +{ + migrate_allow_multi_channels =3D allow; +} + +bool migrate_multi_channels_is_allowed(void) +{ + return migrate_allow_multi_channels; +} + static gint page_request_addr_cmp(gconstpointer ap, gconstpointer bp) { uintptr_t a =3D (uintptr_t) ap, b =3D (uintptr_t) bp; @@ -463,12 +475,12 @@ static void qemu_start_incoming_migration(const char = *uri, Error **errp) { const char *p =3D NULL; =20 - migrate_protocol_allow_multifd(false); /* reset it anyway */ + migrate_protocol_allow_multi_channels(false); /* reset it anyway */ qapi_event_send_migration(MIGRATION_STATUS_SETUP); if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || strstart(uri, "vsock:", NULL)) { - migrate_protocol_allow_multifd(true); + migrate_protocol_allow_multi_channels(true); socket_start_incoming_migration(p ? p : uri, errp); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { @@ -1255,7 +1267,7 @@ static bool migrate_caps_check(bool *cap_list, =20 /* incoming side only */ if (runstate_check(RUN_STATE_INMIGRATE) && - !migrate_multifd_is_allowed() && + !migrate_multi_channels_is_allowed() && cap_list[MIGRATION_CAPABILITY_MULTIFD]) { error_setg(errp, "multifd is not supported by current protocol"); return false; @@ -2313,11 +2325,11 @@ void qmp_migrate(const char *uri, bool has_blk, boo= l blk, } } =20 - migrate_protocol_allow_multifd(false); + migrate_protocol_allow_multi_channels(false); if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || strstart(uri, "vsock:", NULL)) { - migrate_protocol_allow_multifd(true); + migrate_protocol_allow_multi_channels(true); socket_start_outgoing_migration(s, p ? p : uri, &local_err); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { diff --git a/migration/migration.h b/migration/migration.h index d8b9850eae..d677a750c9 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -429,4 +429,7 @@ void migration_cancel(const Error *error); void populate_vfio_info(MigrationInfo *info); void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page); =20 +bool migrate_multi_channels_is_allowed(void); +void migrate_protocol_allow_multi_channels(bool allow); + #endif diff --git a/migration/multifd.c b/migration/multifd.c index 76b57a7177..180586dcde 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -517,7 +517,7 @@ void multifd_save_cleanup(void) { int i; =20 - if (!migrate_use_multifd() || !migrate_multifd_is_allowed()) { + if (!migrate_use_multifd() || !migrate_multi_channels_is_allowed()) { return; } multifd_send_terminate_threads(NULL); @@ -858,17 +858,6 @@ cleanup: multifd_new_send_channel_cleanup(p, sioc, local_err); } =20 -static bool migrate_allow_multifd =3D true; -void migrate_protocol_allow_multifd(bool allow) -{ - migrate_allow_multifd =3D allow; -} - -bool migrate_multifd_is_allowed(void) -{ - return migrate_allow_multifd; -} - int multifd_save_setup(Error **errp) { int thread_count; @@ -879,7 +868,7 @@ int multifd_save_setup(Error **errp) if (!migrate_use_multifd()) { return 0; } - if (!migrate_multifd_is_allowed()) { + if (!migrate_multi_channels_is_allowed()) { error_setg(errp, "multifd is not supported by current protocol"); return -1; } @@ -980,7 +969,7 @@ int multifd_load_cleanup(Error **errp) { int i; =20 - if (!migrate_use_multifd() || !migrate_multifd_is_allowed()) { + if (!migrate_use_multifd() || !migrate_multi_channels_is_allowed()) { return 0; } multifd_recv_terminate_threads(NULL); @@ -1129,7 +1118,7 @@ int multifd_load_setup(Error **errp) if (!migrate_use_multifd()) { return 0; } - if (!migrate_multifd_is_allowed()) { + if (!migrate_multi_channels_is_allowed()) { error_setg(errp, "multifd is not supported by current protocol"); return -1; } diff --git a/migration/multifd.h b/migration/multifd.h index 4dda900a0b..636e599395 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -13,8 +13,6 @@ #ifndef QEMU_MIGRATION_MULTIFD_H #define QEMU_MIGRATION_MULTIFD_H =20 -bool migrate_multifd_is_allowed(void); -void migrate_protocol_allow_multifd(bool allow); int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644994657294189.4580874567706; Tue, 15 Feb 2022 22:57:37 -0800 (PST) Received: from localhost ([::1]:58412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEFr-00084l-Ok for importer@patchew.org; Wed, 16 Feb 2022 01:57:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDov-0004aP-GX for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43376) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDot-0006I3-5Q for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:45 -0500 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-jQpEUNVGPpulyRF4QhRA1w-1; Wed, 16 Feb 2022 01:29:38 -0500 Received: by mail-pj1-f72.google.com with SMTP id a15-20020a17090ad80f00b001b8a1e1da50so941741pjv.6 for ; Tue, 15 Feb 2022 22:29:38 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=deZsk0norkQ4tHx9KvEcVkficttUycqp3/knKJfuBkc=; b=AH1d8/FUXudJNHdvtvUKdl7mbF9bsn+yGwe3P4vTnumKaQ7hPGOLftpGY57tmQowY/nI4D eXzAvMSMjoWYVuDuNkw65NamV2YIvpnjpVvsrBzdpago47uqlCEJ/vrH5PsHbLcgQq7yeB XUWITnfY5u5qms5VZl4Us7CDaxi1a/Q= X-MC-Unique: jQpEUNVGPpulyRF4QhRA1w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=deZsk0norkQ4tHx9KvEcVkficttUycqp3/knKJfuBkc=; b=jlbbMUUcQZQPT4ErBnyKhmk8tSrfdFssHNZPHd6N9cjmUBaWZk/pslCR2sckSMAzBH szWZJb5Tq1dSpHSLR6DdyGQl/bPjcH+1naQ6RLIS2anhVXqQ540xoiMZZAaUrVH9F8Tc q5PCeKSe/LcVnGvWxH33US9XkyA7HDhy+Sd+3ocH+C6yaOgj3+UW32LjlqQrRvyEuUO+ 0piq5H71RmFWTfBZbJ3X8fZWKAWDO0vc8I/nac+SqmefmTwJ5m6yWKZnMp8DkGTcfnTn F50CgSZw/Q33k/WJrMmb6zKqw5Tzhsv4lpiSs50JYqkWP3+1NrsYtFDcR+hJVxlr0jJ0 W7KQ== X-Gm-Message-State: AOAM530p120h0Dpo0oW1kmnQIqFxgy2/Ifi/aDr4Y/2WlyG1Q3TiSd+X BqWZbXx80yi+gRkR08jtuK1ChId9reTeYaFamX8ELcYpmT1/lg6wu50MesL6tluTMGWH6+woIRo brw7ctZMMWJyTeMQ4wI+nRuxU+OZbJHNqcAH+JlhqzuiaSMdh+PWVSZ8XwvkBA3Tj X-Received: by 2002:aa7:88d4:0:b0:4cc:ecd4:de1d with SMTP id k20-20020aa788d4000000b004ccecd4de1dmr1551951pff.63.1644992977222; Tue, 15 Feb 2022 22:29:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJycKDNu+Xacinh/zbJdTY6EUHcdTAVDz1cHex/n+okQPrCFt3hxEejCz0SSMrAfzqNRBJom/g== X-Received: by 2002:aa7:88d4:0:b0:4cc:ecd4:de1d with SMTP id k20-20020aa788d4000000b004ccecd4de1dmr1551920pff.63.1644992976575; Tue, 15 Feb 2022 22:29:36 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 10/20] migration: Enlarge postcopy recovery to capture !-EIO too Date: Wed, 16 Feb 2022 14:27:59 +0800 Message-Id: <20220216062809.57179-11-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644994658277100001 Content-Type: text/plain; charset="utf-8" We used to have quite a few places making sure -EIO happened and that's the only way to trigger postcopy recovery. That's based on the assumption that we'll only return -EIO for channel issues. It'll work in 99.99% cases but logically that won't cover some corner cases. One example is e.g. ram_block_from_stream() could fail with an interrupted network, then -EINVAL will be returned instead of -EIO. I remembered Dave Gilbert pointed that out before, but somehow this is overlooked. Neither did I encounter anything outside the -EIO error. However we'd better touch that up before it triggers a rare VM data loss du= ring live migrating. To cover as much those cases as possible, remove the -EIO restriction on triggering the postcopy recovery, because even if it's not a channel failur= e, we can't do anything better than halting QEMU anyway - the corpse of the process may even be used by a good hand to dig out useful memory regions, or the admin could simply kill the process later on. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 4 ++-- migration/postcopy-ram.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 6e4cc9cc87..67520d3105 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2877,7 +2877,7 @@ retry: out: res =3D qemu_file_get_error(rp); if (res) { - if (res =3D=3D -EIO && migration_in_postcopy()) { + if (res && migration_in_postcopy()) { /* * Maybe there is something we can do: it looks like a * network down issue, and we pause for a recovery. @@ -3478,7 +3478,7 @@ static MigThrError migration_detect_error(MigrationSt= ate *s) error_free(local_error); } =20 - if (state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE && ret =3D=3D -EIO) { + if (state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE && ret) { /* * For postcopy, we allow the network to be down for a * while. After that, it can be continued by a diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index d3ec22e6de..6be510fea4 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1038,7 +1038,7 @@ retry: msg.arg.pagefault.address); if (ret) { /* May be network failure, try to wait for recovery */ - if (ret =3D=3D -EIO && postcopy_pause_fault_thread(mis)) { + if (postcopy_pause_fault_thread(mis)) { /* We got reconnected somehow, try to continue */ goto retry; } else { --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644998191433374.7495217824238; Tue, 15 Feb 2022 23:56:31 -0800 (PST) Received: from localhost ([::1]:57300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKFAt-0005ik-Ft for importer@patchew.org; Wed, 16 Feb 2022 02:56:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDoy-0004iy-SU for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDow-0006Ir-T3 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:48 -0500 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-tRb1MBR4NyKt2Dju88U4nw-1; Wed, 16 Feb 2022 01:29:45 -0500 Received: by mail-pl1-f199.google.com with SMTP id a13-20020a170902ee8d00b0014f308fed09so693823pld.12 for ; Tue, 15 Feb 2022 22:29:45 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cKq1F7ChzJUEmtQ4wXBaDdmq6gB9HiH3cqClItWEPtI=; b=dgfI2IJupI7swmqj/5F9DJCEvgCZZA5ghRHqvUZyvloSXnGao06B74nTuQtqf0iWzKkF39 hPMyHw2qAAGJuGpBqg3aLqvAWvCdCsH17NyPW/LGz2CcgH9aFafclxoYL0t/YVS5qRb7NC mEzed0HdqQHMsLQVGs5Ej7uGAMVXz34= X-MC-Unique: tRb1MBR4NyKt2Dju88U4nw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cKq1F7ChzJUEmtQ4wXBaDdmq6gB9HiH3cqClItWEPtI=; b=iRAtPZ4BWJYB7VCASJxOK4r0rVMboVKtMKwknMImCxivvYpo02Hfst6kd92sleZHHX FViaEwUzMtmsE79dISz4jDatVPD7KA3mDI9w141Xdd3lIn96H0revpijsVRtqNPEeJbH +31HzEYP5tOCNs70HAS/v8JJRxRbDJd0RprPnbHY8yHYvfdLmPvfD0f55WrFa04fE/lP rKt9kd9PeRVapiOxIpwK7mMpZ5cptht79WXwBS6t2yx4zPuubPudHD+PXfdjh89YaV6z dzlQBwZKtfBNTCAtxyMTo/TJA98FdWJpjzT8cEF2ar4QvYeBKaPqcYXY7gs73L1yzBYn iJzA== X-Gm-Message-State: AOAM5314Oo7j1ewd44gfGb6n4dz7LtN4jzH+n+8T/+Dysdwvtob/GfON KC4KAy8C92O6htawSScpTc2z2J6bAaaK954H4+lXlYuZpLvAbxCTnNmdCYacSvtY0oOek0gJ8S8 f7/a2clKzDh9SHYCOJh7aCEV7S+3ZELBQcCqSUQCokzxbyB2TilTt1vnrfgZ4ECod X-Received: by 2002:a63:1826:0:b0:373:41d9:b14e with SMTP id y38-20020a631826000000b0037341d9b14emr1067625pgl.197.1644992984000; Tue, 15 Feb 2022 22:29:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqMPu4+JoKFzVnIfuVE0n5y/W/w0WK2mZI66JWyDjeXEA0Qp7RPvFMlS5qGMGqhD+4Ovwakg== X-Received: by 2002:a63:1826:0:b0:373:41d9:b14e with SMTP id y38-20020a631826000000b0037341d9b14emr1067608pgl.197.1644992983636; Tue, 15 Feb 2022 22:29:43 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 11/20] migration: postcopy_pause_fault_thread() never fails Date: Wed, 16 Feb 2022 14:28:00 +0800 Message-Id: <20220216062809.57179-12-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644998197492100001 Content-Type: text/plain; charset="utf-8" Per the title, remove the return code and simplify the callers as the errors will never be triggered. No functional change intended. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 6be510fea4..738cc55fa6 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -890,15 +890,11 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) affected_cpu); } =20 -static bool postcopy_pause_fault_thread(MigrationIncomingState *mis) +static void postcopy_pause_fault_thread(MigrationIncomingState *mis) { trace_postcopy_pause_fault_thread(); - qemu_sem_wait(&mis->postcopy_pause_sem_fault); - trace_postcopy_pause_fault_thread_continued(); - - return true; } =20 /* @@ -958,13 +954,7 @@ static void *postcopy_ram_fault_thread(void *opaque) * broken already using the event. We should hold until * the channel is rebuilt. */ - if (postcopy_pause_fault_thread(mis)) { - /* Continue to read the userfaultfd */ - } else { - error_report("%s: paused but don't allow to continue", - __func__); - break; - } + postcopy_pause_fault_thread(mis); } =20 if (pfd[1].revents) { @@ -1038,15 +1028,8 @@ retry: msg.arg.pagefault.address); if (ret) { /* May be network failure, try to wait for recovery */ - if (postcopy_pause_fault_thread(mis)) { - /* We got reconnected somehow, try to continue */ - goto retry; - } else { - /* This is a unavoidable fault */ - error_report("%s: postcopy_request_page() get %d", - __func__, ret); - break; - } + postcopy_pause_fault_thread(mis); + goto retry; } } =20 --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644998564757171.43520227047827; Wed, 16 Feb 2022 00:02:44 -0800 (PST) Received: from localhost ([::1]:37640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKFGt-0003NI-BQ for importer@patchew.org; Wed, 16 Feb 2022 03:02:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDp6-00050d-95 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25025) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDp4-0006JU-FE for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:29:55 -0500 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-536-jvlU9JsmOPyhihq78iyFgw-1; Wed, 16 Feb 2022 01:29:52 -0500 Received: by mail-pg1-f200.google.com with SMTP id t7-20020a634447000000b0036579648983so735642pgk.3 for ; Tue, 15 Feb 2022 22:29:52 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644992993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=klamX9g+kUedSn42RLdhUX1ILZJHYJuXlx1KfqUP520=; b=XIE5xmJJtpMVc+VzZkgFH87B6HtC24MPWRCT4QqhmdM62ujpbsAKca84GKr4olOFuE1Vml 4o5LfurBS0lfez1GBmYDl3mb7Fz7eUgYtDxYIYy5WyhnE5mSbpKObhwLCwUUzM8WAZcxuM lPeg7DnuqQ9LJXCKKECRgvj33EuSq/o= X-MC-Unique: jvlU9JsmOPyhihq78iyFgw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=klamX9g+kUedSn42RLdhUX1ILZJHYJuXlx1KfqUP520=; b=L9m6ofOKIDxXgUMCOJGNpiNOv5jjjDzlS93P+VocObAGq1steGntM+atiyPUKlrCp6 TRb1Uctj1lISGYDbz0GeRo84Izq1Wod8nBZoIGPfJpg4gXMBKtHyTvNS2AakWXwvpOdB XrpYLMT3D3Gpw7yWe8NYCP1vL1Ubuo8+AAEVavwUEuO1tBU1MVuo3qj4qWFtl9GhXgZK lCf0WoHAs7vTaKhOho0uox56CVKzBLMDulS6vublVZan2o6DnfBDQKwZMT4CpY0OQ6bu qcvdzLa19+T0KwJsGgTk81H0FaCCDRdoGEdW/7MvwQRPWceOGfSzbQEAyqSo4RlxdIoG pY+Q== X-Gm-Message-State: AOAM533bt8lZ9V2j/EqSftXqG5nn9F50tdxMKRZmSVll3Tmq0lbIDCjY 7r1brMj3LMDx10nmGW4Dz17oDwk3wdpLzovJsNu/APxhhuc5jRFkmpwxo3+wvfd2u1lCZNpdt4O +XOdSt2+yIEL2OODc5risLM0Aoxlnh5iXjmFdp07i5lf9sLrWhzNrbSeH94SChdsk X-Received: by 2002:a05:6a00:2345:b0:4bc:1d4d:dfe with SMTP id j5-20020a056a00234500b004bc1d4d0dfemr1433196pfj.15.1644992990943; Tue, 15 Feb 2022 22:29:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUEShFT2h4TClqxX7wt7K/HIZ7KRE9/V59Ls5ynDopVr7Eoh1A+Mwc1rUlaRg9nOsUH9eL5w== X-Received: by 2002:a05:6a00:2345:b0:4bc:1d4d:dfe with SMTP id j5-20020a056a00234500b004bc1d4d0dfemr1433178pfj.15.1644992990604; Tue, 15 Feb 2022 22:29:50 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 12/20] migration: Export ram_load_postcopy() Date: Wed, 16 Feb 2022 14:28:01 +0800 Message-Id: <20220216062809.57179-13-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644998566671100001 Content-Type: text/plain; charset="utf-8" Will be reused in postcopy fast load thread. Signed-off-by: Peter Xu --- migration/ram.c | 2 +- migration/ram.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 1ed70b17d7..f8bc3cd882 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3644,7 +3644,7 @@ int ram_postcopy_incoming_init(MigrationIncomingState= *mis) * * @f: QEMUFile where to send the data */ -static int ram_load_postcopy(QEMUFile *f) +int ram_load_postcopy(QEMUFile *f) { int flags =3D 0, ret =3D 0; bool place_needed =3D false; diff --git a/migration/ram.h b/migration/ram.h index 2c6dc3675d..ded0a3a086 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -61,6 +61,7 @@ void ram_postcopy_send_discard_bitmap(MigrationState *ms); /* For incoming postcopy discard */ int ram_discard_range(const char *block_name, uint64_t start, size_t lengt= h); int ram_postcopy_incoming_init(MigrationIncomingState *mis); +int ram_load_postcopy(QEMUFile *f); =20 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644995471193410.55165994281094; Tue, 15 Feb 2022 23:11:11 -0800 (PST) Received: from localhost ([::1]:47686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKET1-0003Bo-5W for importer@patchew.org; Wed, 16 Feb 2022 02:11:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpD-0005HY-IK for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52224) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpB-0006KI-53 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:03 -0500 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-277-6smBmgpQP3yStzTjvx8BdQ-1; Wed, 16 Feb 2022 01:29:59 -0500 Received: by mail-pj1-f72.google.com with SMTP id md16-20020a17090b23d000b001b8bd5e35e2so886000pjb.0 for ; Tue, 15 Feb 2022 22:29:59 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993000; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CNujgrUfFlsJU63rZmhvcxyCYrwdVvZMAYkK+aH2yQc=; b=ExxhKqYSinyxMvNsaTFSLgoF6sQBS2OlkcdTmnvxoXe3j9tFfS2YZ8AppLV2IvwP/TBoHC LpFINzFDe8f7n1ugR3oD+VzTHNvJWxx3q93tILrYaJ+o/Fdn4oC4Rx/nYcQsbbQ8nwdrC0 nvRYfXTAMZg9IECuPYTEZqlL70le88o= X-MC-Unique: 6smBmgpQP3yStzTjvx8BdQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CNujgrUfFlsJU63rZmhvcxyCYrwdVvZMAYkK+aH2yQc=; b=VRT9G4w+O5Fq7lKKDYJimU4LzbEZdkh0cR07dJCr5BZ5JHeBnXxizWe8ceMOn4gyj0 K8xsiLwmwlMi6yxw1kNMSmWTZ2wEXL3r2JL+El1Uo4dqDkgbSZaoYf6aJjHJfQgPDAQi hq9Isa49eft7EdUe+bMRLiGeXXDFDSIRXBIPYBhj0NDVP7hFFmPSTOUIH6HcieV6lbeW FMRCOqQLzuWCldN7cP2UmRYzq/LcYSlXPvxb/BgrdzH0QvA77AYJ5KV2i8JoCg4t8Vv6 afSD/5JrDj2WqPbXgNcy48PRKEsWcgJubXlcfdVtwXXZ3mpoJ1KZpF7cDw4EqKshFlUo hDWA== X-Gm-Message-State: AOAM5335Zrp5cNENUxBBjS7SUqJu1JZGUK+B99npijJBuVhBMrsjPD/e SjWjANZzqcyqJOWacEGQ5pSr2X6Ocm3Rnu3/37eBL74hkgMsCCXj+lvNGaZvajepEcK/qF2zhuJ lfe5vni3GoXxJ1PIFeD0SeExR1fDDS55IDsHuiVERa/nZDIfmfoJ0Pj0HXfyN3Bb0 X-Received: by 2002:a17:90a:8592:b0:1b9:7e8c:25dc with SMTP id m18-20020a17090a859200b001b97e8c25dcmr106872pjn.224.1644992998061; Tue, 15 Feb 2022 22:29:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwr1NCgXRM6r3wuWeI8KDs3T+5Hcz3Da+A4VzfmH2EaJOTY6lKomH87f+DBxnMKutQWdh/r3A== X-Received: by 2002:a17:90a:8592:b0:1b9:7e8c:25dc with SMTP id m18-20020a17090a859200b001b97e8c25dcmr106843pjn.224.1644992997594; Tue, 15 Feb 2022 22:29:57 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 13/20] migration: Move channel setup out of postcopy_try_recover() Date: Wed, 16 Feb 2022 14:28:02 +0800 Message-Id: <20220216062809.57179-14-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644995472983100001 Content-Type: text/plain; charset="utf-8" We used to use postcopy_try_recover() to replace migration_incoming_setup()= to setup incoming channels. That's fine for the old world, but in the new wor= ld there can be more than one channels that need setup. Better move the chann= el setup out of it so that postcopy_try_recover() only handles the last phase = of switching to the recovery phase. To do that in migration_fd_process_incoming(), move the postcopy_try_recove= r() call to be after migration_incoming_setup(), which will setup the channels. While in migration_ioc_process_incoming(), postpone the recover() routine r= ight before we'll jump into migration_incoming_process(). A side benefit is we don't need to pass in QEMUFile* to postcopy_try_recove= r() anymore. Remove it. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 67520d3105..b2e6446457 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -665,19 +665,20 @@ void migration_incoming_process(void) } =20 /* Returns true if recovered from a paused migration, otherwise false */ -static bool postcopy_try_recover(QEMUFile *f) +static bool postcopy_try_recover(void) { MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 if (mis->state =3D=3D MIGRATION_STATUS_POSTCOPY_PAUSED) { /* Resumed from a paused postcopy migration */ =20 - mis->from_src_file =3D f; + /* This should be set already in migration_incoming_setup() */ + assert(mis->from_src_file); /* Postcopy has standalone thread to do vm load */ - qemu_file_set_blocking(f, true); + qemu_file_set_blocking(mis->from_src_file, true); =20 /* Re-configure the return path */ - mis->to_src_file =3D qemu_file_get_return_path(f); + mis->to_src_file =3D qemu_file_get_return_path(mis->from_src_file); =20 migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_PAUSED, MIGRATION_STATUS_POSTCOPY_RECOVER); @@ -698,11 +699,10 @@ static bool postcopy_try_recover(QEMUFile *f) =20 void migration_fd_process_incoming(QEMUFile *f, Error **errp) { - if (postcopy_try_recover(f)) { + if (!migration_incoming_setup(f, errp)) { return; } - - if (!migration_incoming_setup(f, errp)) { + if (postcopy_try_recover()) { return; } migration_incoming_process(); @@ -718,11 +718,6 @@ void migration_ioc_process_incoming(QIOChannel *ioc, E= rror **errp) /* The first connection (multifd may have multiple) */ QEMUFile *f =3D qemu_fopen_channel_input(ioc); =20 - /* If it's a recovery, we're done */ - if (postcopy_try_recover(f)) { - return; - } - if (!migration_incoming_setup(f, errp)) { return; } @@ -743,6 +738,10 @@ void migration_ioc_process_incoming(QIOChannel *ioc, E= rror **errp) } =20 if (start_migration) { + /* If it's a recovery, we're done */ + if (postcopy_try_recover()) { + return; + } migration_incoming_process(); } } --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164499695524071.22971453464072; Tue, 15 Feb 2022 23:35:55 -0800 (PST) Received: from localhost ([::1]:36600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEqw-0007ga-3G for importer@patchew.org; Wed, 16 Feb 2022 02:35:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpN-0005bs-19 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpK-0006Yz-KM for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:12 -0500 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-418-JjuLV8ExPXCcHoYUXgkmhQ-1; Wed, 16 Feb 2022 01:30:06 -0500 Received: by mail-pj1-f69.google.com with SMTP id jf17-20020a17090b175100b001b90cf26a4eso952716pjb.3 for ; Tue, 15 Feb 2022 22:30:06 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.29.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9vJa4o2k4N8buai+eLYbslIYkZ3adJj7UP7RVfT+0Ck=; b=ih5MoROUM3ukJoPPjj6dAbPUAaDP1vC9S/RCZDsqg7+wf13nMF41QJXS8nYU0eOk82oJuX Jd350/1X1/sUruZZHWETEQQdak6MW2KH43u9Gl72C9lomMJMtXZCQdvn56b36gy8uI47+O 1gF7yGYkeqPcIoC8ziakIdKUc7+V+Sg= X-MC-Unique: JjuLV8ExPXCcHoYUXgkmhQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9vJa4o2k4N8buai+eLYbslIYkZ3adJj7UP7RVfT+0Ck=; b=1Lu/yeTrhddIgpg23UIZS5XGuzt2pmFHUsVBtkuR6L/H1zHOZzXrT30twWbFIcvmwG esEJ+AHSorKZ+YVcOF+MBMshAVkJUqk62kvhuhB0ol9NBuR5G6dtwaHxkw2B29Ck14hi yL6Mb9edx7qf4hhPYOOnOetg4+hbZxRrpKT7NupG6zHuff4bEhpAyBsCaqgGS6RZ5Y8A v44VUa9K1ICB9k2p8QbSeSpUhUtfE6FLHxcU3bf3Mdpx70XbX2OOIRM6UWi33iL2TD3l jIpmW5R4C+aqFhml3k3GnvjLip9Axd8LinxL11PomE29JxGh0G1SXU4LWOJVix8aeDv2 viUQ== X-Gm-Message-State: AOAM531lAtCY7nT8UzPwOIusQO97b84qaG8nEJkmXnZvP6LLHMosXcdZ 9/gGLaP0ymzRVE5M49Wp7RbPkcF+BPwbIvoTN+wDU/On8VElgUPOSJAP60gRzMN1DPApRxNb0LS RTglvoRISEKBfrIYEdEvJ2Kcwa1nhwurvdXP/X1Hf4OiYNjexuu9VkaBMFdmr8nEm X-Received: by 2002:a17:903:248:b0:14f:139f:191f with SMTP id j8-20020a170903024800b0014f139f191fmr1104647plh.71.1644993005136; Tue, 15 Feb 2022 22:30:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJx16iTkgqr1X+tJPD0XcvOSGfVzjdjNZFMwjSOdbFhnySO5GZ6TWsehg9JvK3lyQf6BYb5+0Q== X-Received: by 2002:a17:903:248:b0:14f:139f:191f with SMTP id j8-20020a170903024800b0014f139f191fmr1104615plh.71.1644993004749; Tue, 15 Feb 2022 22:30:04 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 14/20] migration: Add migration_incoming_transport_cleanup() Date: Wed, 16 Feb 2022 14:28:03 +0800 Message-Id: <20220216062809.57179-15-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644996956748100001 Content-Type: text/plain; charset="utf-8" Add a helper to cleanup the transport listener. When do it, we should also null-ify the cleanup hook and the data, then it's even safe to call it multiple times. Move the socket_address_list cleanup altogether, because that's a mirror of= the listener channels and only for the purpose of query-migrate. Hence when someone wants to cleanup the listener transport, it should also want to cle= anup the socket list too, always. No functional change intended. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 22 ++++++++++++++-------- migration/migration.h | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b2e6446457..6bb321cdd3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -279,6 +279,19 @@ MigrationIncomingState *migration_incoming_get_current= (void) return current_incoming; } =20 +void migration_incoming_transport_cleanup(MigrationIncomingState *mis) +{ + if (mis->socket_address_list) { + qapi_free_SocketAddressList(mis->socket_address_list); + mis->socket_address_list =3D NULL; + } + + if (mis->transport_cleanup) { + mis->transport_cleanup(mis->transport_data); + mis->transport_data =3D mis->transport_cleanup =3D NULL; + } +} + void migration_incoming_state_destroy(void) { struct MigrationIncomingState *mis =3D migration_incoming_get_current(= ); @@ -299,10 +312,8 @@ void migration_incoming_state_destroy(void) g_array_free(mis->postcopy_remote_fds, TRUE); mis->postcopy_remote_fds =3D NULL; } - if (mis->transport_cleanup) { - mis->transport_cleanup(mis->transport_data); - } =20 + migration_incoming_transport_cleanup(mis); qemu_event_reset(&mis->main_thread_load_event); =20 if (mis->page_requested) { @@ -310,11 +321,6 @@ void migration_incoming_state_destroy(void) mis->page_requested =3D NULL; } =20 - if (mis->socket_address_list) { - qapi_free_SocketAddressList(mis->socket_address_list); - mis->socket_address_list =3D NULL; - } - yank_unregister_instance(MIGRATION_YANK_INSTANCE); } =20 diff --git a/migration/migration.h b/migration/migration.h index d677a750c9..f17ccc657c 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -166,6 +166,7 @@ struct MigrationIncomingState { =20 MigrationIncomingState *migration_incoming_get_current(void); void migration_incoming_state_destroy(void); +void migration_incoming_transport_cleanup(MigrationIncomingState *mis); /* * Functions to work with blocktime context */ --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644997503741819.0210106015775; Tue, 15 Feb 2022 23:45:03 -0800 (PST) Received: from localhost ([::1]:45300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEzk-0005jy-J1 for importer@patchew.org; Wed, 16 Feb 2022 02:45:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpS-0005pR-Ml for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47829) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpR-0006aH-4b for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:18 -0500 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-493-xd_-KLZaPwic5ZZq9mQ6Lw-1; Wed, 16 Feb 2022 01:30:13 -0500 Received: by mail-pg1-f199.google.com with SMTP id 37-20020a630e65000000b0036c461afa9aso731312pgo.20 for ; Tue, 15 Feb 2022 22:30:13 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.30.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQVTOcSvujLUu+ruq0WAemac4DnT0xNNLGIpX9WC1+A=; b=KY6qYmhlcpabI6inlTkSsiy2EdagYBE+3hTNdmpMbtd9Se2fdV7muIIz6Z+qjYU37e5oGV oc8UxcpyU4lyqXK/aI2YBHnCaTLOoWqlBAQqYunzwDcXC1i9+cHv5PZ/wJtnk2nkLyKY3d U+5BBC6sAamxEZ6F3zd++xTx9x6IfKk= X-MC-Unique: xd_-KLZaPwic5ZZq9mQ6Lw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cQVTOcSvujLUu+ruq0WAemac4DnT0xNNLGIpX9WC1+A=; b=amkeoezf99xcMbtncgaubQGyqemNh1VLznD9fhIQaydZa8qyUjZHQRrCaqjbeM3AVM DjcDf+/LySuo5lpmEX+1HDCFvgCWU0uTc/Zs3VxuytjfaXOYdiJjyPBWDyV4KGiBvXoo N7GEo3uj/0ph04KAT5Ha2vCn9VY9havJoOuNgiCm64yK5qVbgNI+NiobNnF5wn1/H0Ir 19+22CnY6ARbnB7So1db+XeRmFl5IozC7d7StUyjizdd7BzM0dIQVR+aqF+hYRUtZZj7 UpktrwiyUvpxw0f4oa6x/X4WMmqoR8fCHa+v03/GQrQXdxAJLauFxK/sK2Ukz1UP8w6m Ds5Q== X-Gm-Message-State: AOAM531L2g4yPWp0zRJztlV4+ua0XQeDlnGck1XykPLtyBzuXFdShUKJ NZOWii0YfLs2L1VeyfvdVk04PuCmdAYzeNsduRBaCHVBqAw0I6v/OAjTdBBW1iwgVePdio4/V5d kWvC5zLhES0TyHmei3BmlsLjkUWQJp7XQDA396GHfH88YE4w02uE0Ub4jwQ6vTA6h X-Received: by 2002:a17:903:2490:b0:14d:57a5:a472 with SMTP id p16-20020a170903249000b0014d57a5a472mr1180839plw.17.1644993012231; Tue, 15 Feb 2022 22:30:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzu0n3wwEZiCjwqEhi0YZpBGpJJlp9fDhIGNsAw2KJwV3fbWbo41L4/xfQjzP87W3w2kX8s6A== X-Received: by 2002:a17:903:2490:b0:14d:57a5:a472 with SMTP id p16-20020a170903249000b0014d57a5a472mr1180819plw.17.1644993011854; Tue, 15 Feb 2022 22:30:11 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 15/20] migration: Allow migrate-recover to run multiple times Date: Wed, 16 Feb 2022 14:28:04 +0800 Message-Id: <20220216062809.57179-16-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644997505368100003 Content-Type: text/plain; charset="utf-8" Previously migration didn't have an easy way to cleanup the listening transport, migrate recovery only allows to execute once. That's done with a trick flag in postcopy_recover_triggered. Now the facility is already there. Drop postcopy_recover_triggered and instead allows a new migrate-recover to release the previous listener transport. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 13 ++----------- migration/migration.h | 1 - migration/savevm.c | 3 --- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 6bb321cdd3..16086897aa 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2159,11 +2159,8 @@ void qmp_migrate_recover(const char *uri, Error **er= rp) return; } =20 - if (qatomic_cmpxchg(&mis->postcopy_recover_triggered, - false, true) =3D=3D true) { - error_setg(errp, "Migrate recovery is triggered already"); - return; - } + /* If there's an existing transport, release it */ + migration_incoming_transport_cleanup(mis); =20 /* * Note that this call will never start a real migration; it will @@ -2171,12 +2168,6 @@ void qmp_migrate_recover(const char *uri, Error **er= rp) * to continue using that newly established channel. */ qemu_start_incoming_migration(uri, errp); - - /* Safe to dereference with the assert above */ - if (*errp) { - /* Reset the flag so user could still retry */ - qatomic_set(&mis->postcopy_recover_triggered, false); - } } =20 void qmp_migrate_pause(Error **errp) diff --git a/migration/migration.h b/migration/migration.h index f17ccc657c..a863032b71 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -139,7 +139,6 @@ struct MigrationIncomingState { struct PostcopyBlocktimeContext *blocktime_ctx; =20 /* notify PAUSED postcopy incoming migrations to try to continue */ - bool postcopy_recover_triggered; QemuSemaphore postcopy_pause_sem_dst; QemuSemaphore postcopy_pause_sem_fault; =20 diff --git a/migration/savevm.c b/migration/savevm.c index 967ff80547..254aa78234 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2589,9 +2589,6 @@ static bool postcopy_pause_incoming(MigrationIncoming= State *mis) =20 assert(migrate_postcopy_ram()); =20 - /* Clear the triggered bit to allow one recovery */ - mis->postcopy_recover_triggered =3D false; - /* * Unregister yank with either from/to src would work, since ioc behin= d it * is the same --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644999997174434.94104715412504; Wed, 16 Feb 2022 00:26:37 -0800 (PST) Received: from localhost ([::1]:36238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKFdz-0005qj-Va for importer@patchew.org; Wed, 16 Feb 2022 03:26:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpZ-00064L-L4 for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpX-0006dD-Eu for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:25 -0500 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-dWIVk8ODMfW5qHxgT1XEOA-1; Wed, 16 Feb 2022 01:30:20 -0500 Received: by mail-pg1-f200.google.com with SMTP id d192-20020a6336c9000000b00372eb4c4bf4so733983pga.8 for ; Tue, 15 Feb 2022 22:30:20 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.30.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6TAoGPC83WG2WE9uR3fdoGBug6yf6QOx7nZQCRz0NcE=; b=DbRMLobcpjy25uiqTx4CrfBQuJR81xVwlNzSaFOi3ER9GF/DC8u9F6TXkcN4RjB+Mb/ooV LtUfCYIrvFhG0P9rx1Y0LGaDxW8EcJKv9A3iKU1t/XrNbTXmli71wZPc0W2PmqUd8HKKfz jHCa0cd2dobcXic+tU6bRDn5NUvqJLg= X-MC-Unique: dWIVk8ODMfW5qHxgT1XEOA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6TAoGPC83WG2WE9uR3fdoGBug6yf6QOx7nZQCRz0NcE=; b=opW5uQW7ZNi50yFugAYvQff+v4VwPtGWmkmGHW3fsSCiRBiHWvsZ+f2tjv9bKDkail vJAWDQqdWS9F7pPavRm1KxzFxTHD+BgDRVflDzUwaEmgiFOi8U8e3TFPLLSGgUChIaDr PJo3wEK78+kheYXnbE02nPyfB1Xk2SW2JW9pC26Mjsv1y4V3R2DUPyS1FmrarYxzTyQs FElB+bKL59PjnupWZa+UA4aRqg37R5HFKMSOD4Fv5jC9VddtYOiCb45jo8Oj/YqVwhy+ RY1RJl+bsXmJ+xYKlGi07pji0IPglEztmBBxseV6EyI+FUFTKSQBwaAjT/et5GddHeM8 HWdw== X-Gm-Message-State: AOAM530LVjggap3DqmlwEMfXKr/7HtLRgk4mOn7+LRSqKcUNIwmTE00j XYZxhBh/MMeK/CI446GwReVY4wydcyZLgOZw9JABh79EKvH8GkvBDHW8L7gomsYbIbKf1MS+EK7 bdC8xfqefgfKdfTAkdRCghE20NZQN3qrESTZIo+6ir4g81S//EAB3m1Zbwx7a0oul X-Received: by 2002:a62:be19:0:b0:4e1:3d4a:b56e with SMTP id l25-20020a62be19000000b004e13d4ab56emr1268119pff.76.1644993019563; Tue, 15 Feb 2022 22:30:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwR5u9vsJAfXIH8mk1/17RROxT8C3yKJBioTQZlNDkqn7B0bixCVYFE/nYd9qP1yV3zjwQMA== X-Received: by 2002:a62:be19:0:b0:4e1:3d4a:b56e with SMTP id l25-20020a62be19000000b004e13d4ab56emr1268083pff.76.1644993019183; Tue, 15 Feb 2022 22:30:19 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 16/20] migration: Add postcopy-preempt capability Date: Wed, 16 Feb 2022 14:28:05 +0800 Message-Id: <20220216062809.57179-17-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644999999682100001 Content-Type: text/plain; charset="utf-8" Firstly, postcopy already preempts precopy due to the fact that we do unqueue_page() first before looking into dirty bits. However that's not enough, e.g., when there're host huge page enabled, when sending a precopy huge page, a postcopy request needs to wait until the who= le huge page that is sending to finish. That could introduce quite some delay, the bigger the huge page is the larger delay it'll bring. This patch adds a new capability to allow postcopy requests to preempt exis= ting precopy page during sending a huge page, so that postcopy requests can be serviced even faster. Meanwhile to send it even faster, bypass the precopy stream by providing a standalone postcopy socket for sending requested pages. Since the new behavior will not be compatible with the old behavior, this w= ill not be the default, it's enabled only when the new capability is set on both src/dst QEMUs. This patch only adds the capability itself, the logic will be added in foll= ow up patches. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 23 +++++++++++++++++++++++ migration/migration.h | 1 + qapi/migration.json | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 16086897aa..4c22bad304 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1235,6 +1235,11 @@ static bool migrate_caps_check(bool *cap_list, error_setg(errp, "Postcopy is not compatible with ignore-share= d"); return false; } + + if (cap_list[MIGRATION_CAPABILITY_MULTIFD]) { + error_setg(errp, "Multifd is not supported in postcopy"); + return false; + } } =20 if (cap_list[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { @@ -1278,6 +1283,13 @@ static bool migrate_caps_check(bool *cap_list, return false; } =20 + if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { + if (!cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + error_setg(errp, "Postcopy preempt requires postcopy-ram"); + return false; + } + } + return true; } =20 @@ -2622,6 +2634,15 @@ bool migrate_background_snapshot(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHO= T]; } =20 +bool migrate_postcopy_preempt(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]; +} + /* migration thread support */ /* * Something bad happened to the RP stream, mark an error @@ -4232,6 +4253,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS), DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS), DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RA= M), + DEFINE_PROP_MIG_CAP("x-postcopy-preempt", + MIGRATION_CAPABILITY_POSTCOPY_PREEMPT), DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO), DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM), DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), diff --git a/migration/migration.h b/migration/migration.h index a863032b71..af4bcb19c2 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -394,6 +394,7 @@ int migrate_decompress_threads(void); bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); bool migrate_background_snapshot(void); +bool migrate_postcopy_preempt(void); =20 /* Sending on the return path - generic and then for each message type */ void migrate_send_rp_shut(MigrationIncomingState *mis, diff --git a/qapi/migration.json b/qapi/migration.json index 5975a0e104..50878b5f3b 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -463,6 +463,12 @@ # procedure starts. The VM RAM is saved with running= VM. # (since 6.0) # +# @postcopy-preempt: If enabled, the migration process will allow postcopy +# requests to preempt precopy stream, so postcopy reque= sts +# will be handled faster. This is a performance featur= e and +# should not affect the correctness of postcopy migrati= on. +# (since 7.0) +# # Features: # @unstable: Members @x-colo and @x-ignore-shared are experimental. # @@ -476,7 +482,7 @@ 'block', 'return-path', 'pause-before-switchover', 'multifd', 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, - 'validate-uuid', 'background-snapshot'] } + 'validate-uuid', 'background-snapshot', 'postcopy-preempt'] } =20 ## # @MigrationCapabilityStatus: --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644998962021344.35579549085537; Wed, 16 Feb 2022 00:09:22 -0800 (PST) Received: from localhost ([::1]:43308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKFNJ-0007Yl-Vy for importer@patchew.org; Wed, 16 Feb 2022 03:09:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDph-0006NK-RO for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpe-0006gZ-Vz for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:33 -0500 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-673-jGyTKHHtOVyqmFkhJYABwQ-1; Wed, 16 Feb 2022 01:30:28 -0500 Received: by mail-pl1-f199.google.com with SMTP id p5-20020a170902bd0500b00148cb2d29ecso695739pls.4 for ; Tue, 15 Feb 2022 22:30:28 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.30.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NoA602llQnSul4NpoPgJmI8YHgdt3Ctq6VEht/htiWQ=; b=WJ7yq+AyGlXgkC7I9MfmKjNagC4UtADqrEXcMX3N3VMDsJssLZhJPwl/zG7agxAuA+Kibt 2xDyyEUrABBicbTgIcx2+1fShnESC87k9PmBnc3wZjA1rchshXwrsxLLiDTCATpsEfB5Hc VKxmMhoJdN3v75B9dJDr3wCiMen62m0= X-MC-Unique: jGyTKHHtOVyqmFkhJYABwQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NoA602llQnSul4NpoPgJmI8YHgdt3Ctq6VEht/htiWQ=; b=YkcDJgSRe3dUQ4vPtf2NUm/uvrCeQOllhmHy0olIZkH76L5UqxzR7SdxqD8vVhtLsf IIUwcuN7pLhMy4G2d475VrKbjZ5yIyI1xTG2pyK9esALEYMoMsL9NczjxwydedGVUmz4 kdgVj8iOuNbdM53vf9aA84bGcwvii9uVvU38yHYPux8IqDR/KdynXNwXZ1ionvtetZti M1doTgfPPIK8BDzFAeIuL4vlfOJZIUclX6OJA8FrwHl78d7NYONBJ0J0Vy3pKPpAsKNv v1rycLS3/3UYGqvUu3yYqkYfS/vKqnDNUydTJHtUAriPXquSCwYm0zZEOVViqbFTue01 h6CQ== X-Gm-Message-State: AOAM532Vm6wsbh8q/pR5fLXdfuNJ7qM6MTUtFQdWmUejSkhhgeBn6Q81 5EZe6q6sOQC6zONMOxo/C3kdZ5D19jbQWjAThT4Z+Mgby8ps/dnwRSJ8iKx3jvW5MZJuVe27L8V 2GDDPBMGfB1V325dfUZAqBvzYAWsdwS/x9XcPVw2UFmMbkRKH2t/9S3zFWeUQqN21 X-Received: by 2002:a17:902:6509:b0:14b:4c26:f43d with SMTP id b9-20020a170902650900b0014b4c26f43dmr1108620plk.135.1644993027147; Tue, 15 Feb 2022 22:30:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwf4mtsPxHKucaD7IuI+fTNmGGcb52taQINMGOOekQnamEJ6yGOUeVFfdzf7NoK+07EB/z76A== X-Received: by 2002:a17:902:6509:b0:14b:4c26:f43d with SMTP id b9-20020a170902650900b0014b4c26f43dmr1108582plk.135.1644993026572; Tue, 15 Feb 2022 22:30:26 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 17/20] migration: Postcopy preemption preparation on channel creation Date: Wed, 16 Feb 2022 14:28:06 +0800 Message-Id: <20220216062809.57179-18-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URG_BIZ=0.573 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644998964048100001 Content-Type: text/plain; charset="utf-8" Create a new socket for postcopy to be prepared to send postcopy requested pages via this specific channel, so as to not get blocked by precopy pages. A new thread is also created on dest qemu to receive data from this new cha= nnel based on the ram_load_postcopy() routine. The ram_load_postcopy(POSTCOPY) branch and the thread has not started to function, and that'll be done in follow up patches. Cleanup the new sockets on both src/dst QEMUs, meanwhile look after the new thread too to make sure it'll be recycled properly. Signed-off-by: Peter Xu --- migration/migration.c | 62 ++++++++++++++++++++++++---- migration/migration.h | 8 ++++ migration/postcopy-ram.c | 88 ++++++++++++++++++++++++++++++++++++++-- migration/postcopy-ram.h | 10 +++++ migration/ram.c | 25 ++++++++---- migration/ram.h | 4 +- migration/socket.c | 22 +++++++++- migration/socket.h | 1 + migration/trace-events | 3 ++ 9 files changed, 203 insertions(+), 20 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 4c22bad304..3d7f897b72 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -321,6 +321,12 @@ void migration_incoming_state_destroy(void) mis->page_requested =3D NULL; } =20 + if (mis->postcopy_qemufile_dst) { + migration_ioc_unregister_yank_from_file(mis->postcopy_qemufile_dst= ); + qemu_fclose(mis->postcopy_qemufile_dst); + mis->postcopy_qemufile_dst =3D NULL; + } + yank_unregister_instance(MIGRATION_YANK_INSTANCE); } =20 @@ -714,15 +720,21 @@ void migration_fd_process_incoming(QEMUFile *f, Error= **errp) migration_incoming_process(); } =20 +static bool migration_needs_multiple_sockets(void) +{ + return migrate_use_multifd() || migrate_postcopy_preempt(); +} + void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); Error *local_err =3D NULL; bool start_migration; + QEMUFile *f; =20 if (!mis->from_src_file) { /* The first connection (multifd may have multiple) */ - QEMUFile *f =3D qemu_fopen_channel_input(ioc); + f =3D qemu_fopen_channel_input(ioc); =20 if (!migration_incoming_setup(f, errp)) { return; @@ -730,13 +742,18 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) =20 /* * Common migration only needs one channel, so we can start - * right now. Multifd needs more than one channel, we wait. + * right now. Some features need more than one channel, we wait. */ - start_migration =3D !migrate_use_multifd(); + start_migration =3D !migration_needs_multiple_sockets(); } else { /* Multiple connections */ - assert(migrate_use_multifd()); - start_migration =3D multifd_recv_new_channel(ioc, &local_err); + assert(migration_needs_multiple_sockets()); + if (migrate_use_multifd()) { + start_migration =3D multifd_recv_new_channel(ioc, &local_err); + } else if (migrate_postcopy_preempt()) { + f =3D qemu_fopen_channel_input(ioc); + start_migration =3D postcopy_preempt_new_channel(mis, f); + } if (local_err) { error_propagate(errp, local_err); return; @@ -761,11 +778,20 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) bool migration_has_all_channels(void) { MigrationIncomingState *mis =3D migration_incoming_get_current(); - bool all_channels; =20 - all_channels =3D multifd_recv_all_channels_created(); + if (!mis->from_src_file) { + return false; + } + + if (migrate_use_multifd()) { + return multifd_recv_all_channels_created(); + } + + if (migrate_postcopy_preempt()) { + return mis->postcopy_qemufile_dst !=3D NULL; + } =20 - return all_channels && mis->from_src_file !=3D NULL; + return true; } =20 /* @@ -1858,6 +1884,12 @@ static void migrate_fd_cleanup(MigrationState *s) qemu_fclose(tmp); } =20 + if (s->postcopy_qemufile_src) { + migration_ioc_unregister_yank_from_file(s->postcopy_qemufile_src); + qemu_fclose(s->postcopy_qemufile_src); + s->postcopy_qemufile_src =3D NULL; + } + assert(!migration_is_active(s)); =20 if (s->state =3D=3D MIGRATION_STATUS_CANCELLING) { @@ -3233,6 +3265,11 @@ static void migration_completion(MigrationState *s) qemu_savevm_state_complete_postcopy(s->to_dst_file); qemu_mutex_unlock_iothread(); =20 + /* Shutdown the postcopy fast path thread */ + if (migrate_postcopy_preempt()) { + postcopy_preempt_shutdown_file(s); + } + trace_migration_completion_postcopy_end_after_complete(); } else { goto fail; @@ -4120,6 +4157,15 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) } } =20 + /* This needs to be done before resuming a postcopy */ + if (postcopy_preempt_setup(s, &local_err)) { + error_report_err(local_err); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); + migrate_fd_cleanup(s); + return; + } + if (resume) { /* Wakeup the main migration thread to do the recovery */ migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED, diff --git a/migration/migration.h b/migration/migration.h index af4bcb19c2..caa910d956 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -23,6 +23,7 @@ #include "io/channel-buffer.h" #include "net/announce.h" #include "qom/object.h" +#include "postcopy-ram.h" =20 struct PostcopyBlocktimeContext; =20 @@ -112,6 +113,11 @@ struct MigrationIncomingState { * enabled. */ unsigned int postcopy_channels; + /* QEMUFile for postcopy only; it'll be handled by a separate thread */ + QEMUFile *postcopy_qemufile_dst; + /* Postcopy priority thread is used to receive postcopy requested page= s */ + QemuThread postcopy_prio_thread; + bool postcopy_prio_thread_created; /* * An array of temp host huge pages to be used, one for each postcopy * channel. @@ -192,6 +198,8 @@ struct MigrationState { QEMUBH *cleanup_bh; /* Protected by qemu_file_lock */ QEMUFile *to_dst_file; + /* Postcopy specific transfer channel */ + QEMUFile *postcopy_qemufile_src; QIOChannelBuffer *bioc; /* * Protects to_dst_file/from_dst_file pointers. We need to make sure = we diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 738cc55fa6..30eddaacd1 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -32,6 +32,9 @@ #include "trace.h" #include "hw/boards.h" #include "exec/ramblock.h" +#include "socket.h" +#include "qemu-file-channel.h" +#include "yank_functions.h" =20 /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes @@ -566,6 +569,11 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingSta= te *mis) { trace_postcopy_ram_incoming_cleanup_entry(); =20 + if (mis->postcopy_prio_thread_created) { + qemu_thread_join(&mis->postcopy_prio_thread); + mis->postcopy_prio_thread_created =3D false; + } + if (mis->have_fault_thread) { Error *local_err =3D NULL; =20 @@ -1101,8 +1109,13 @@ static int postcopy_temp_pages_setup(MigrationIncomi= ngState *mis) int err, i, channels; void *temp_page; =20 - /* TODO: will be boosted when enable postcopy preemption */ - mis->postcopy_channels =3D 1; + if (migrate_postcopy_preempt()) { + /* If preemption enabled, need extra channel for urgent requests */ + mis->postcopy_channels =3D RAM_CHANNEL_MAX; + } else { + /* Both precopy/postcopy on the same channel */ + mis->postcopy_channels =3D 1; + } =20 channels =3D mis->postcopy_channels; mis->postcopy_tmp_pages =3D g_malloc0_n(sizeof(PostcopyTmpPage), chann= els); @@ -1169,7 +1182,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingStat= e *mis) return -1; } =20 - postcopy_thread_create(mis, &mis->fault_thread, "postcopy/fault", + postcopy_thread_create(mis, &mis->fault_thread, "qemu/fault-default", postcopy_ram_fault_thread, QEMU_THREAD_JOINABLE= ); mis->have_fault_thread =3D true; =20 @@ -1184,6 +1197,16 @@ int postcopy_ram_incoming_setup(MigrationIncomingSta= te *mis) return -1; } =20 + if (migrate_postcopy_preempt()) { + /* + * This thread needs to be created after the temp pages because it= 'll fetch + * RAM_CHANNEL_POSTCOPY PostcopyTmpPage immediately. + */ + postcopy_thread_create(mis, &mis->postcopy_prio_thread, "qemu/faul= t-fast", + postcopy_preempt_thread, QEMU_THREAD_JOINAB= LE); + mis->postcopy_prio_thread_created =3D true; + } + trace_postcopy_ram_enable_notify(); =20 return 0; @@ -1513,3 +1536,62 @@ void postcopy_unregister_shared_ufd(struct PostCopyF= D *pcfd) } } } + +bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile) +{ + mis->postcopy_qemufile_dst =3D file; + + trace_postcopy_preempt_new_channel(); + + /* Start the migration immediately */ + return true; +} + +int postcopy_preempt_setup(MigrationState *s, Error **errp) +{ + QIOChannel *ioc; + + if (!migrate_postcopy_preempt()) { + return 0; + } + + if (!migrate_multi_channels_is_allowed()) { + error_setg(errp, "Postcopy preempt is not supported as current " + "migration stream does not support multi-channels."); + return -1; + } + + ioc =3D socket_send_channel_create_sync(errp); + + if (ioc =3D=3D NULL) { + return -1; + } + + migration_ioc_register_yank(ioc); + s->postcopy_qemufile_src =3D qemu_fopen_channel_output(ioc); + + trace_postcopy_preempt_new_channel(); + + return 0; +} + +void *postcopy_preempt_thread(void *opaque) +{ + MigrationIncomingState *mis =3D opaque; + int ret; + + trace_postcopy_preempt_thread_entry(); + + rcu_register_thread(); + + qemu_sem_post(&mis->thread_sync_sem); + + /* Sending RAM_SAVE_FLAG_EOS to terminate this thread */ + ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, RAM_CHANNEL_POST= COPY); + + rcu_unregister_thread(); + + trace_postcopy_preempt_thread_exit(); + + return ret =3D=3D 0 ? NULL : (void *)-1; +} diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 07684c0e1d..34b1080cde 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -183,4 +183,14 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, uint= 64_t client_addr, int postcopy_request_shared_page(struct PostCopyFD *pcfd, RAMBlock *rb, uint64_t client_addr, uint64_t offset); =20 +/* Hard-code channels for now for postcopy preemption */ +enum PostcopyChannels { + RAM_CHANNEL_PRECOPY =3D 0, + RAM_CHANNEL_POSTCOPY =3D 1, + RAM_CHANNEL_MAX, +}; + +bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); +int postcopy_preempt_setup(MigrationState *s, Error **errp); + #endif diff --git a/migration/ram.c b/migration/ram.c index f8bc3cd882..36e3da6bb0 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3643,15 +3643,15 @@ int ram_postcopy_incoming_init(MigrationIncomingSta= te *mis) * rcu_read_lock is taken prior to this being called. * * @f: QEMUFile where to send the data + * @channel: the channel to use for loading */ -int ram_load_postcopy(QEMUFile *f) +int ram_load_postcopy(QEMUFile *f, int channel) { int flags =3D 0, ret =3D 0; bool place_needed =3D false; bool matches_target_page_size =3D false; MigrationIncomingState *mis =3D migration_incoming_get_current(); - /* Currently we only use channel 0. TODO: use all the channels */ - PostcopyTmpPage *tmp_page =3D &mis->postcopy_tmp_pages[0]; + PostcopyTmpPage *tmp_page =3D &mis->postcopy_tmp_pages[channel]; =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr; @@ -3716,10 +3716,10 @@ int ram_load_postcopy(QEMUFile *f) } else if (tmp_page->host_addr !=3D host_page_from_ram_block_offset(block, addr)) { /* not the 1st TP within the HP */ - error_report("Non-same host page detected. Target host pa= ge %p, " - "received host page %p " + error_report("Non-same host page detected on channel %d: " + "Target host page %p, received host page %p " "(rb %s offset 0x"RAM_ADDR_FMT" target_pages = %d)", - tmp_page->host_addr, + channel, tmp_page->host_addr, host_page_from_ram_block_offset(block, addr), block->idstr, addr, tmp_page->target_pages); ret =3D -EINVAL; @@ -4106,7 +4106,12 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) */ WITH_RCU_READ_LOCK_GUARD() { if (postcopy_running) { - ret =3D ram_load_postcopy(f); + /* + * Note! Here RAM_CHANNEL_PRECOPY is the precopy channel of + * postcopy migration, we have another RAM_CHANNEL_POSTCOPY to + * service fast page faults. + */ + ret =3D ram_load_postcopy(f, RAM_CHANNEL_PRECOPY); } else { ret =3D ram_load_precopy(f); } @@ -4268,6 +4273,12 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 +void postcopy_preempt_shutdown_file(MigrationState *s) +{ + qemu_put_be64(s->postcopy_qemufile_src, RAM_SAVE_FLAG_EOS); + qemu_fflush(s->postcopy_qemufile_src); +} + static SaveVMHandlers savevm_ram_handlers =3D { .save_setup =3D ram_save_setup, .save_live_iterate =3D ram_save_iterate, diff --git a/migration/ram.h b/migration/ram.h index ded0a3a086..5d90945a6e 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -61,7 +61,7 @@ void ram_postcopy_send_discard_bitmap(MigrationState *ms); /* For incoming postcopy discard */ int ram_discard_range(const char *block_name, uint64_t start, size_t lengt= h); int ram_postcopy_incoming_init(MigrationIncomingState *mis); -int ram_load_postcopy(QEMUFile *f); +int ram_load_postcopy(QEMUFile *f, int channel); =20 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 @@ -73,6 +73,8 @@ int64_t ramblock_recv_bitmap_send(QEMUFile *file, const char *block_name); int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *rb); bool ramblock_page_is_discarded(RAMBlock *rb, ram_addr_t start); +void postcopy_preempt_shutdown_file(MigrationState *s); +void *postcopy_preempt_thread(void *opaque); =20 /* ram cache */ int colo_init_ram_cache(void); diff --git a/migration/socket.c b/migration/socket.c index 05705a32d8..a7f345b353 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -26,7 +26,7 @@ #include "io/channel-socket.h" #include "io/net-listener.h" #include "trace.h" - +#include "postcopy-ram.h" =20 struct SocketOutgoingArgs { SocketAddress *saddr; @@ -39,6 +39,24 @@ void socket_send_channel_create(QIOTaskFunc f, void *dat= a) f, data, NULL, NULL); } =20 +QIOChannel *socket_send_channel_create_sync(Error **errp) +{ + QIOChannelSocket *sioc =3D qio_channel_socket_new(); + + if (!outgoing_args.saddr) { + object_unref(OBJECT(sioc)); + error_setg(errp, "Initial sock address not set!"); + return NULL; + } + + if (qio_channel_socket_connect_sync(sioc, outgoing_args.saddr, errp) <= 0) { + object_unref(OBJECT(sioc)); + return NULL; + } + + return QIO_CHANNEL(sioc); +} + int socket_send_channel_destroy(QIOChannel *send) { /* Remove channel */ @@ -158,6 +176,8 @@ socket_start_incoming_migration_internal(SocketAddress = *saddr, =20 if (migrate_use_multifd()) { num =3D migrate_multifd_channels(); + } else if (migrate_postcopy_preempt()) { + num =3D RAM_CHANNEL_MAX; } =20 if (qio_net_listener_open_sync(listener, saddr, num, errp) < 0) { diff --git a/migration/socket.h b/migration/socket.h index 891dbccceb..dc54df4e6c 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -21,6 +21,7 @@ #include "io/task.h" =20 void socket_send_channel_create(QIOTaskFunc f, void *data); +QIOChannel *socket_send_channel_create_sync(Error **errp); int socket_send_channel_destroy(QIOChannel *send); =20 void socket_start_incoming_migration(const char *str, Error **errp); diff --git a/migration/trace-events b/migration/trace-events index 1aec580e92..4474a76614 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -278,6 +278,9 @@ postcopy_request_shared_page(const char *sharer, const = char *rb, uint64_t rb_off postcopy_request_shared_page_present(const char *sharer, const char *rb, u= int64_t rb_offset) "%s already %s offset 0x%"PRIx64 postcopy_wake_shared(uint64_t client_addr, const char *rb) "at 0x%"PRIx64"= in %s" postcopy_page_req_del(void *addr, int count) "resolved page req %p total %= d" +postcopy_preempt_new_channel(void) "" +postcopy_preempt_thread_entry(void) "" +postcopy_preempt_thread_exit(void) "" =20 get_mem_fault_cpu_index(int cpu, uint32_t pid) "cpu: %d, pid: %u" =20 --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644997488003361.75993898456113; Tue, 15 Feb 2022 23:44:48 -0800 (PST) Received: from localhost ([::1]:44884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKEzX-0005TS-5y for importer@patchew.org; Wed, 16 Feb 2022 02:44:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpo-0006aU-3f for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35095) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpl-0006hM-JM for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:39 -0500 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-345-OD_h5D2nMIS2JWnHKGKoHA-1; Wed, 16 Feb 2022 01:30:35 -0500 Received: by mail-pf1-f198.google.com with SMTP id c192-20020a621cc9000000b004e0ff94313dso917579pfc.17 for ; Tue, 15 Feb 2022 22:30:35 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.30.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GumDlkpdl/U3x0kx0WMJa6VWuoEi7lzr6y1ZkQDLrB8=; b=RF820hwEtGzpVEku3x9P2fiG1+lY00qwQDDVg7/SxAZDhtZ1BZDo6T8P4cgEbDfGKfnJCK GcI0dmFjIFeetQGag3zWvXd6o95ss7pDeBL2MwHe4FNCXFDdoALdi4FjQ9113E7IrS4vof SnLlpXmXaE/UV/l8ST3CiIQfC7tR774= X-MC-Unique: OD_h5D2nMIS2JWnHKGKoHA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GumDlkpdl/U3x0kx0WMJa6VWuoEi7lzr6y1ZkQDLrB8=; b=8MNCrvlUGrh2aKvs6mtxdhOnKIxzqRhwiNLYxM4+1QbQQjoWF6AOzt/rUZSCp4Mu01 sKpPDew33ukZcz6R0B/cm27q/rjiKZcMOsWc0PDt1X1G2GK8S/YcxYOhK4+i6DZ0SK5C 6cCLy27DKosZ59nUm3HtNyHCXntx59cmBbzIULOdv9UgVmLBrpgrxcPj/aOLbKn1wAvD DqvRWQu0UN1o6MPDNG+RO5sse7153Bxts/ZetUZmpSVtgp0r0BsoeexLiCKcDJGBZy5h vB0WL8HainbS6FCnvm708b61Os68Fdrl59JjoSbEwPmpkFi/VGcF8PArzRmwmhgnRxfN LTUw== X-Gm-Message-State: AOAM531ziJGnCN/8Dq3e1DWEXuo2H5L62ATatRGw8lVHgsfsVsL04Y5q 3Hj0sikgDu6IO/CkTEZyWSHhdNNT2cLk36CuQASYG9GPbaAGxz3MPwosAFD+1UKZg/J5rGUh34g eDG4NZvj8KWTHKzVDQQlB/Nkt7Hnxd948guKpckz204C41kOsLLgiZ/xEEW5244la X-Received: by 2002:a17:902:bd43:b0:14b:4534:76d6 with SMTP id b3-20020a170902bd4300b0014b453476d6mr1279122plx.0.1644993034247; Tue, 15 Feb 2022 22:30:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyamkKg9XFSdGjVAHx8R9VI3sshO0j5EVjvdhS/zLPCwbv/qR3GL5FSmyObGYYhfa9TtH6OIA== X-Received: by 2002:a17:902:bd43:b0:14b:4534:76d6 with SMTP id b3-20020a170902bd4300b0014b453476d6mr1279079plx.0.1644993033629; Tue, 15 Feb 2022 22:30:33 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 18/20] migration: Postcopy preemption enablement Date: Wed, 16 Feb 2022 14:28:07 +0800 Message-Id: <20220216062809.57179-19-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644997504066100001 Content-Type: text/plain; charset="utf-8" This patch enables postcopy-preempt feature. It contains two major changes to the migration logic: (1) Postcopy requests are now sent via a different socket from precopy background migration stream, so as to be isolated from very high page request delays. (2) For huge page enabled hosts: when there's postcopy requests, they can n= ow intercept a partial sending of huge host pages on src QEMU. After this patch, we'll live migrate a VM with two channels for postcopy: (= 1) PRECOPY channel, which is the default channel that transfers background pag= es; and (2) POSTCOPY channel, which only transfers requested pages. There's no strict rule of which channel to use, e.g., if a requested page is already being transferred on precopy channel, then we will keep using the s= ame precopy channel to transfer the page even if it's explicitly requested. In= 99% of the cases we'll prioritize the channels so we send requested page via the postcopy channel as long as possible. On the source QEMU, when we found a postcopy request, we'll interrupt the PRECOPY channel sending process and quickly switch to the POSTCOPY channel. After we serviced all the high priority postcopy pages, we'll switch back to PRECOPY channel so that we'll continue to send the interrupted huge page ag= ain. There's no new thread introduced on src QEMU. On the destination QEMU, one new thread is introduced to receive page data = from the postcopy specific socket (done in the preparation patch). This patch has a side effect: after sending postcopy pages, previously we'll assume the guest will access follow up pages so we'll keep sending from the= re. Now it's changed. Instead of going on with a postcopy requested page, we'l= l go back and continue sending the precopy huge page (which can be intercepted b= y a postcopy request so the huge page can be sent partially before). Whether that's a problem is debatable, because "assuming the guest will continue to access the next page" may not really suite when huge pages are used, especially if the huge page is large (e.g. 1GB pages). So that local= ity hint is much meaningless if huge pages are used. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 2 + migration/migration.h | 2 +- migration/ram.c | 247 +++++++++++++++++++++++++++++++++++++++-- migration/trace-events | 7 ++ 4 files changed, 249 insertions(+), 9 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 3d7f897b72..d20db04097 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3153,6 +3153,8 @@ static int postcopy_start(MigrationState *ms) MIGRATION_STATUS_FAILED); } =20 + trace_postcopy_preempt_enabled(migrate_postcopy_preempt()); + return ret; =20 fail_closefb: diff --git a/migration/migration.h b/migration/migration.h index caa910d956..b8aacfe3af 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -68,7 +68,7 @@ typedef struct { struct MigrationIncomingState { QEMUFile *from_src_file; /* Previously received RAM's RAMBlock pointer */ - RAMBlock *last_recv_block; + RAMBlock *last_recv_block[RAM_CHANNEL_MAX]; /* A hook to allow cleanup at the end of incoming migration */ void *transport_data; void (*transport_cleanup)(void *data); diff --git a/migration/ram.c b/migration/ram.c index 36e3da6bb0..ffbe9a9a50 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -294,6 +294,20 @@ struct RAMSrcPageRequest { QSIMPLEQ_ENTRY(RAMSrcPageRequest) next_req; }; =20 +typedef struct { + /* + * Cached ramblock/offset values if preempted. They're only meaningfu= l if + * preempted=3D=3Dtrue below. + */ + RAMBlock *ram_block; + unsigned long ram_page; + /* + * Whether a postcopy preemption just happened. Will be reset after + * precopy recovered to background migration. + */ + bool preempted; +} PostcopyPreemptState; + /* State of RAM for migration */ struct RAMState { /* QEMUFile used for this migration */ @@ -348,6 +362,14 @@ struct RAMState { /* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests; + + /* Postcopy preemption informations */ + PostcopyPreemptState postcopy_preempt_state; + /* + * Current channel we're using on src VM. Only valid if postcopy-pree= mpt + * is enabled. + */ + int postcopy_channel; }; typedef struct RAMState RAMState; =20 @@ -355,6 +377,11 @@ static RAMState *ram_state; =20 static NotifierWithReturnList precopy_notifier_list; =20 +static void postcopy_preempt_reset(RAMState *rs) +{ + memset(&rs->postcopy_preempt_state, 0, sizeof(PostcopyPreemptState)); +} + /* Whether postcopy has queued requests? */ static bool postcopy_has_request(RAMState *rs) { @@ -1946,6 +1973,55 @@ void ram_write_tracking_stop(void) } #endif /* defined(__linux__) */ =20 +/* + * Check whether two addr/offset of the ramblock falls onto the same host = huge + * page. Returns true if so, false otherwise. + */ +static bool offset_on_same_huge_page(RAMBlock *rb, uint64_t addr1, + uint64_t addr2) +{ + size_t page_size =3D qemu_ram_pagesize(rb); + + addr1 =3D ROUND_DOWN(addr1, page_size); + addr2 =3D ROUND_DOWN(addr2, page_size); + + return addr1 =3D=3D addr2; +} + +/* + * Whether a previous preempted precopy huge page contains current request= ed + * page? Returns true if so, false otherwise. + * + * This should really happen very rarely, because it means when we were se= nding + * during background migration for postcopy we're sending exactly the page= that + * some vcpu got faulted on on dest node. When it happens, we probably do= n't + * need to do much but drop the request, because we know right after we re= store + * the precopy stream it'll be serviced. It'll slightly affect the order = of + * postcopy requests to be serviced (e.g. it'll be the same as we move cur= rent + * request to the end of the queue) but it shouldn't be a big deal. The m= ost + * imporant thing is we can _never_ try to send a partial-sent huge page o= n the + * POSTCOPY channel again, otherwise that huge page will got "split brain"= on + * two channels (PRECOPY, POSTCOPY). + */ +static bool postcopy_preempted_contains(RAMState *rs, RAMBlock *block, + ram_addr_t offset) +{ + PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; + + /* No preemption at all? */ + if (!state->preempted) { + return false; + } + + /* Not even the same ramblock? */ + if (state->ram_block !=3D block) { + return false; + } + + return offset_on_same_huge_page(block, offset, + state->ram_page << TARGET_PAGE_BITS); +} + /** * get_queued_page: unqueue a page from the postcopy requests * @@ -1961,9 +2037,17 @@ static bool get_queued_page(RAMState *rs, PageSearch= Status *pss) RAMBlock *block; ram_addr_t offset; =20 +again: block =3D unqueue_page(rs, &offset); =20 - if (!block) { + if (block) { + /* See comment above postcopy_preempted_contains() */ + if (postcopy_preempted_contains(rs, block, offset)) { + trace_postcopy_preempt_hit(block->idstr, offset); + /* This request is dropped */ + goto again; + } + } else { /* * Poll write faults too if background snapshot is enabled; that's * when we have vcpus got blocked by the write protected pages. @@ -2179,6 +2263,114 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) return ram_save_page(rs, pss); } =20 +static bool postcopy_needs_preempt(RAMState *rs, PageSearchStatus *pss) +{ + /* Not enabled eager preempt? Then never do that. */ + if (!migrate_postcopy_preempt()) { + return false; + } + + /* If the ramblock we're sending is a small page? Never bother. */ + if (qemu_ram_pagesize(pss->block) =3D=3D TARGET_PAGE_SIZE) { + return false; + } + + /* Not in postcopy at all? */ + if (!migration_in_postcopy()) { + return false; + } + + /* + * If we're already handling a postcopy request, don't preempt as this= page + * has got the same high priority. + */ + if (pss->postcopy_requested) { + return false; + } + + /* If there's postcopy requests, then check it up! */ + return postcopy_has_request(rs); +} + +/* Returns true if we preempted precopy, false otherwise */ +static void postcopy_do_preempt(RAMState *rs, PageSearchStatus *pss) +{ + PostcopyPreemptState *p_state =3D &rs->postcopy_preempt_state; + + trace_postcopy_preempt_triggered(pss->block->idstr, pss->page); + + /* + * Time to preempt precopy. Cache current PSS into preempt state, so t= hat + * after handling the postcopy pages we can recover to it. We need to= do + * so because the dest VM will have partial of the precopy huge page k= ept + * over in its tmp huge page caches; better move on with it when we ca= n. + */ + p_state->ram_block =3D pss->block; + p_state->ram_page =3D pss->page; + p_state->preempted =3D true; +} + +/* Whether we're preempted by a postcopy request during sending a huge pag= e */ +static bool postcopy_preempt_triggered(RAMState *rs) +{ + return rs->postcopy_preempt_state.preempted; +} + +static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss) +{ + PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; + + assert(state->preempted); + + pss->block =3D state->ram_block; + pss->page =3D state->ram_page; + /* This is not a postcopy request but restoring previous precopy */ + pss->postcopy_requested =3D false; + + trace_postcopy_preempt_restored(pss->block->idstr, pss->page); + + /* Reset preempt state, most importantly, set preempted=3D=3Dfalse */ + postcopy_preempt_reset(rs); +} + +static void postcopy_preempt_choose_channel(RAMState *rs, PageSearchStatus= *pss) +{ + int channel =3D pss->postcopy_requested ? RAM_CHANNEL_POSTCOPY : RAM_C= HANNEL_PRECOPY; + MigrationState *s =3D migrate_get_current(); + QEMUFile *next; + + if (channel !=3D rs->postcopy_channel) { + if (channel =3D=3D RAM_CHANNEL_PRECOPY) { + next =3D s->to_dst_file; + } else { + next =3D s->postcopy_qemufile_src; + } + /* Update and cache the current channel */ + rs->f =3D next; + rs->postcopy_channel =3D channel; + + /* + * If channel switched, reset last_sent_block since the old sent b= lock + * may not be on the same channel. + */ + rs->last_sent_block =3D NULL; + + trace_postcopy_preempt_switch_channel(channel); + } + + trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); +} + +/* We need to make sure rs->f always points to the default channel elsewhe= re */ +static void postcopy_preempt_reset_channel(RAMState *rs) +{ + if (migrate_postcopy_preempt() && migration_in_postcopy()) { + rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; + rs->f =3D migrate_get_current()->to_dst_file; + trace_postcopy_preempt_reset_channel(); + } +} + /** * ram_save_host_page: save a whole host page * @@ -2210,7 +2402,16 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) return 0; } =20 + if (migrate_postcopy_preempt() && migration_in_postcopy()) { + postcopy_preempt_choose_channel(rs, pss); + } + do { + if (postcopy_needs_preempt(rs, pss)) { + postcopy_do_preempt(rs, pss); + break; + } + /* Check the pages is dirty and if it is send it */ if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { tmppages =3D ram_save_target_page(rs, pss); @@ -2234,6 +2435,19 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) /* The offset we leave with is the min boundary of host page and block= */ pss->page =3D MIN(pss->page, hostpage_boundary); =20 + /* + * When with postcopy preempt mode, flush the data as soon as possible= for + * postcopy requests, because we've already sent a whole huge page, so= the + * dst node should already have enough resource to atomically filling = in + * the current missing page. + * + * More importantly, when using separate postcopy channel, we must do + * explicit flush or it won't flush until the buffer is full. + */ + if (migrate_postcopy_preempt() && pss->postcopy_requested) { + qemu_fflush(rs->f); + } + res =3D ram_save_release_protection(rs, pss, start_page); return (res < 0 ? res : pages); } @@ -2275,8 +2489,17 @@ static int ram_find_and_save_block(RAMState *rs) found =3D get_queued_page(rs, &pss); =20 if (!found) { - /* priority queue empty, so just search for something dirty */ - found =3D find_dirty_block(rs, &pss, &again); + /* + * Recover previous precopy ramblock/offset if postcopy has + * preempted precopy. Otherwise find the next dirty bit. + */ + if (postcopy_preempt_triggered(rs)) { + postcopy_preempt_restore(rs, &pss); + found =3D true; + } else { + /* priority queue empty, so just search for something dirt= y */ + found =3D find_dirty_block(rs, &pss, &again); + } } =20 if (found) { @@ -2404,6 +2627,8 @@ static void ram_state_reset(RAMState *rs) rs->last_page =3D 0; rs->last_version =3D ram_list.version; rs->xbzrle_enabled =3D false; + postcopy_preempt_reset(rs); + rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; } =20 #define MAX_WAIT 50 /* ms, half buffered_file limit */ @@ -3042,6 +3267,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } qemu_mutex_unlock(&rs->bitmap_mutex); =20 + postcopy_preempt_reset_channel(rs); + /* * Must occur before EOS (or any QEMUFile operation) * because of RDMA protocol. @@ -3111,6 +3338,8 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) ram_control_after_iterate(f, RAM_CONTROL_FINISH); } =20 + postcopy_preempt_reset_channel(rs); + if (ret >=3D 0) { multifd_send_sync_main(rs->f); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); @@ -3193,11 +3422,13 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr= , void *host) * @mis: the migration incoming state pointer * @f: QEMUFile where to read the data from * @flags: Page flags (mostly to see if it's a continuation of previous bl= ock) + * @channel: the channel we're using */ static inline RAMBlock *ram_block_from_stream(MigrationIncomingState *mis, - QEMUFile *f, int flags) + QEMUFile *f, int flags, + int channel) { - RAMBlock *block =3D mis->last_recv_block; + RAMBlock *block =3D mis->last_recv_block[channel]; char id[256]; uint8_t len; =20 @@ -3224,7 +3455,7 @@ static inline RAMBlock *ram_block_from_stream(Migrati= onIncomingState *mis, return NULL; } =20 - mis->last_recv_block =3D block; + mis->last_recv_block[channel] =3D block; =20 return block; } @@ -3678,7 +3909,7 @@ int ram_load_postcopy(QEMUFile *f, int channel) trace_ram_load_postcopy_loop((uint64_t)addr, flags); if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE)) { - block =3D ram_block_from_stream(mis, f, flags); + block =3D ram_block_from_stream(mis, f, flags, channel); if (!block) { ret =3D -EINVAL; break; @@ -3929,7 +4160,7 @@ static int ram_load_precopy(QEMUFile *f) =20 if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { - RAMBlock *block =3D ram_block_from_stream(mis, f, flags); + RAMBlock *block =3D ram_block_from_stream(mis, f, flags, RAM_C= HANNEL_PRECOPY); =20 host =3D host_from_ram_block_offset(block, addr); /* diff --git a/migration/trace-events b/migration/trace-events index 4474a76614..b1155d9da0 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -111,6 +111,12 @@ ram_load_complete(int ret, uint64_t seq_iter) "exit_co= de %d seq iteration %" PRI ram_write_tracking_ramblock_start(const char *block_id, size_t page_size, = void *addr, size_t length) "%s: page_size: %zu addr: %p length: %zu" ram_write_tracking_ramblock_stop(const char *block_id, size_t page_size, v= oid *addr, size_t length) "%s: page_size: %zu addr: %p length: %zu" unqueue_page(char *block, uint64_t offset, bool dirty) "ramblock '%s' offs= et 0x%"PRIx64" dirty %d" +postcopy_preempt_triggered(char *str, unsigned long page) "during sending = ramblock %s offset 0x%lx" +postcopy_preempt_restored(char *str, unsigned long page) "ramblock %s offs= et 0x%lx" +postcopy_preempt_hit(char *str, uint64_t offset) "ramblock %s offset 0x%"P= RIx64 +postcopy_preempt_send_host_page(char *str, uint64_t offset) "ramblock %s o= ffset 0x%"PRIx64 +postcopy_preempt_switch_channel(int channel) "%d" +postcopy_preempt_reset_channel(void) "" =20 # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %u" @@ -176,6 +182,7 @@ migration_thread_low_pending(uint64_t pending) "%" PRIu= 64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, uint64_t ban= dwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " band= width %" PRIu64 " max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=3D%d postcopy-stat= e=3D%d" process_incoming_migration_co_postcopy_end_main(void) "" +postcopy_preempt_enabled(bool value) "%d" =20 # channel.c migration_set_incoming_channel(void *ioc, const char *ioctype) "ioc=3D%p i= octype=3D%s" --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645000837296721.6794059446066; Wed, 16 Feb 2022 00:40:37 -0800 (PST) Received: from localhost ([::1]:58996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKFrX-0004oA-LU for importer@patchew.org; Wed, 16 Feb 2022 03:40:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpu-0006mh-Ld for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDps-0006i0-Bf for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:46 -0500 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-81-44jpwnaEOPiMK4d4Pdlh9A-1; Wed, 16 Feb 2022 01:30:42 -0500 Received: by mail-pf1-f198.google.com with SMTP id j204-20020a6280d5000000b004e107ad3488so919193pfd.15 for ; Tue, 15 Feb 2022 22:30:42 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.30.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MatQhmiuDazPhBd8ggzkvaXZ3W7gO+frvQyUVeWVm/o=; b=BEvKF7jAY7jGtOIBS+KuBYl+PDt8db5Kg8jWBf+prRr2QUNGugr7YpOh3cxeljuaGnSA/j PU1cKayQ8hfEzO4Tgd17BacWwzaez+al0Oi/cB0/7WMiiPySxZew5z9fxHkzELDL3eCMR+ 7mZJKR8VyUkGBPE9qaH/txqir+M63cg= X-MC-Unique: 44jpwnaEOPiMK4d4Pdlh9A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MatQhmiuDazPhBd8ggzkvaXZ3W7gO+frvQyUVeWVm/o=; b=amtlm5OTmi4FNg26ubAmNJUg3vvjQ3ZHTVtPkNDcaoLmDvnYbqiKa8AbtPEKkm7Wit Y7PJPHj6UThkCbMOpxo2JmPXAwY2kWpALSSlgMQK64PXoeOjsD8QL3PlxVMW4m5LlY+R WTnA62s0xJRhFpSf5+aRUkHwQVwUtOzddDnJqDHjW/YhuRTwz+j0ehfzjdoCYsz6TsZ/ koo80GTD63UNm06yP0vfLUtNpv0irNPxHitvALT4Hq5Yu5NQ799ixzjn0yuk5gHy6wQP 5GLGkOt8HpfmowNgBOOkGSjKnG6OSiT/TF3XPzkVlWdGgi9DPXCkrVU/d4UIfZGRhgey 4kJA== X-Gm-Message-State: AOAM531Dc6VcDwhM8Y2n7atG3Q2MbtsNdDwW5n7AV5lEi3M+3ZR36wlZ l1/U1EJgDkKyR/LNkt8Ib8YjpIzk4CevlJ2doqvdsi6Nh5xMyvB8G+AZLNizFNOB3uSNSbMAvdR uvY8/c2yEFcuWyHD9CAS9b1swkup3eWuebU5dJoRtKqmu7L3TWH6asdMtxyXjFOLi X-Received: by 2002:a63:d618:0:b0:36c:8f9a:f80e with SMTP id q24-20020a63d618000000b0036c8f9af80emr1131248pgg.248.1644993041179; Tue, 15 Feb 2022 22:30:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZusfyL4hUegvdFEXyiEr+x6CfjtbEftJWTdIboFFfuhyJGwsv3gdY49QvqkWbuG/59tZQTA== X-Received: by 2002:a63:d618:0:b0:36c:8f9a:f80e with SMTP id q24-20020a63d618000000b0036c8f9af80emr1131226pgg.248.1644993040703; Tue, 15 Feb 2022 22:30:40 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 19/20] migration: Postcopy recover with preempt enabled Date: Wed, 16 Feb 2022 14:28:08 +0800 Message-Id: <20220216062809.57179-20-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645000838355100001 Content-Type: text/plain; charset="utf-8" To allow postcopy recovery, the ram fast load (preempt-only) dest QEMU thre= ad needs similar handling on fault tolerance. When ram_load_postcopy() fails, instead of stopping the thread it halts with a semaphore, preparing to be kicked again when recovery is detected. A mutex is introduced to make sure there's no concurrent operation upon the socket. To make it simple, the fast ram load thread will take the mutex du= ring its whole procedure, and only release it if it's paused. The fast-path soc= ket will be properly released by the main loading thread safely when there's network failures during postcopy with that mutex held. Signed-off-by: Peter Xu Acked-by: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 17 +++++++++++++++-- migration/migration.h | 3 +++ migration/postcopy-ram.c | 24 ++++++++++++++++++++++-- migration/savevm.c | 17 +++++++++++++++++ migration/trace-events | 2 ++ 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index d20db04097..c68a281406 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -215,9 +215,11 @@ void migration_object_init(void) current_incoming->postcopy_remote_fds =3D g_array_new(FALSE, TRUE, sizeof(struct PostCopyFD)); qemu_mutex_init(¤t_incoming->rp_mutex); + qemu_mutex_init(¤t_incoming->postcopy_prio_thread_mutex); qemu_event_init(¤t_incoming->main_thread_load_event, false); qemu_sem_init(¤t_incoming->postcopy_pause_sem_dst, 0); qemu_sem_init(¤t_incoming->postcopy_pause_sem_fault, 0); + qemu_sem_init(¤t_incoming->postcopy_pause_sem_fast_load, 0); qemu_mutex_init(¤t_incoming->page_request_mutex); current_incoming->page_requested =3D g_tree_new(page_request_addr_cmp); =20 @@ -697,9 +699,9 @@ static bool postcopy_try_recover(void) =20 /* * Here, we only wake up the main loading thread (while the - * fault thread will still be waiting), so that we can receive + * rest threads will still be waiting), so that we can receive * commands from source now, and answer it if needed. The - * fault thread will be woken up afterwards until we are sure + * rest threads will be woken up afterwards until we are sure * that source is ready to reply to page requests. */ qemu_sem_post(&mis->postcopy_pause_sem_dst); @@ -3466,6 +3468,17 @@ static MigThrError postcopy_pause(MigrationState *s) qemu_file_shutdown(file); qemu_fclose(file); =20 + /* + * Do the same to postcopy fast path socket too if there is. No + * locking needed because no racer as long as we do this before se= tting + * status to paused. + */ + if (s->postcopy_qemufile_src) { + migration_ioc_unregister_yank_from_file(s->postcopy_qemufile_s= rc); + qemu_fclose(s->postcopy_qemufile_src); + s->postcopy_qemufile_src =3D NULL; + } + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_POSTCOPY_PAUSED); =20 diff --git a/migration/migration.h b/migration/migration.h index b8aacfe3af..945088064a 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -118,6 +118,8 @@ struct MigrationIncomingState { /* Postcopy priority thread is used to receive postcopy requested page= s */ QemuThread postcopy_prio_thread; bool postcopy_prio_thread_created; + /* Used to sync with the prio thread */ + QemuMutex postcopy_prio_thread_mutex; /* * An array of temp host huge pages to be used, one for each postcopy * channel. @@ -147,6 +149,7 @@ struct MigrationIncomingState { /* notify PAUSED postcopy incoming migrations to try to continue */ QemuSemaphore postcopy_pause_sem_dst; QemuSemaphore postcopy_pause_sem_fault; + QemuSemaphore postcopy_pause_sem_fast_load; =20 /* List of listening socket addresses */ SocketAddressList *socket_address_list; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 30eddaacd1..b3d23804bc 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1575,6 +1575,15 @@ int postcopy_preempt_setup(MigrationState *s, Error = **errp) return 0; } =20 +static void postcopy_pause_ram_fast_load(MigrationIncomingState *mis) +{ + trace_postcopy_pause_fast_load(); + qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); + qemu_sem_wait(&mis->postcopy_pause_sem_fast_load); + qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); + trace_postcopy_pause_fast_load_continued(); +} + void *postcopy_preempt_thread(void *opaque) { MigrationIncomingState *mis =3D opaque; @@ -1587,11 +1596,22 @@ void *postcopy_preempt_thread(void *opaque) qemu_sem_post(&mis->thread_sync_sem); =20 /* Sending RAM_SAVE_FLAG_EOS to terminate this thread */ - ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, RAM_CHANNEL_POST= COPY); + qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); + while (1) { + ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, RAM_CHANNEL_= POSTCOPY); + /* If error happened, go into recovery routine */ + if (ret) { + postcopy_pause_ram_fast_load(mis); + } else { + /* We're done */ + break; + } + } + qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); =20 rcu_unregister_thread(); =20 trace_postcopy_preempt_thread_exit(); =20 - return ret =3D=3D 0 ? NULL : (void *)-1; + return NULL; } diff --git a/migration/savevm.c b/migration/savevm.c index 254aa78234..2d32340d28 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2152,6 +2152,13 @@ static int loadvm_postcopy_handle_resume(MigrationIn= comingState *mis) */ qemu_sem_post(&mis->postcopy_pause_sem_fault); =20 + if (migrate_postcopy_preempt()) { + /* The channel should already be setup again; make sure of it */ + assert(mis->postcopy_qemufile_dst); + /* Kick the fast ram load thread too */ + qemu_sem_post(&mis->postcopy_pause_sem_fast_load); + } + return 0; } =20 @@ -2607,6 +2614,16 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) mis->to_src_file =3D NULL; qemu_mutex_unlock(&mis->rp_mutex); =20 + if (mis->postcopy_qemufile_dst) { + qemu_file_shutdown(mis->postcopy_qemufile_dst); + /* Take the mutex to make sure the fast ram load thread halted */ + qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); + migration_ioc_unregister_yank_from_file(mis->postcopy_qemufile_dst= ); + qemu_fclose(mis->postcopy_qemufile_dst); + mis->postcopy_qemufile_dst =3D NULL; + qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); + } + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_POSTCOPY_PAUSED); =20 diff --git a/migration/trace-events b/migration/trace-events index b1155d9da0..dfe36a3340 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -270,6 +270,8 @@ mark_postcopy_blocktime_begin(uint64_t addr, void *dd, = uint32_t time, int cpu, i mark_postcopy_blocktime_end(uint64_t addr, void *dd, uint32_t time, int af= fected_cpu) "addr: 0x%" PRIx64 ", dd: %p, time: %u, affected_cpu: %d" postcopy_pause_fault_thread(void) "" postcopy_pause_fault_thread_continued(void) "" +postcopy_pause_fast_load(void) "" +postcopy_pause_fast_load_continued(void) "" postcopy_ram_fault_thread_entry(void) "" postcopy_ram_fault_thread_exit(void) "" postcopy_ram_fault_thread_fds_core(int baseufd, int quitfd) "ufd: %d quitf= d: %d" --=20 2.32.0 From nobody Sun Feb 8 15:54:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645001286919689.5028709545192; Wed, 16 Feb 2022 00:48:06 -0800 (PST) Received: from localhost ([::1]:42952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKFyn-0005Jo-AJ for importer@patchew.org; Wed, 16 Feb 2022 03:48:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDq1-0006v3-QU for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48021) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKDpz-0006iq-7m for qemu-devel@nongnu.org; Wed, 16 Feb 2022 01:30:52 -0500 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-288-c27Kg6wUNk-xyq_lfq5GCg-1; Wed, 16 Feb 2022 01:30:49 -0500 Received: by mail-pj1-f69.google.com with SMTP id w3-20020a17090ac98300b001b8b914e91aso979116pjt.0 for ; Tue, 15 Feb 2022 22:30:49 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id 17sm42104657pfl.175.2022.02.15.22.30.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Feb 2022 22:30:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644993050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pw4Ya1U/DRCke3Ko0pEWT0PjTe4tXXv9qiy5ynKCT6Y=; b=dns6RAGZJKpuolaFIx1uuUHcKE9Uwd/tFRMHIfEY2k87gyw1tEkBk86fBOVUFXsYTcB+V5 FWjlVYwyho9YDBymjca0JcjyoAkl3yDyWcEkwBd1VbP2qdCHDlzGzFM0/wfZdxR1pWEaVa C/RdoCRVSFBJVxRRHpM2Sk+rsRwLafo= X-MC-Unique: c27Kg6wUNk-xyq_lfq5GCg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pw4Ya1U/DRCke3Ko0pEWT0PjTe4tXXv9qiy5ynKCT6Y=; b=qR0vnV2Hn0Y5P5+3W1OqRxGIbJpLdrfEWjqbyWhtq9slGvXbQ8mtjhUoskgldR1Yto UceD608grU/eVIoybJPs4vQTQ7Kz6QovuxcZ50vud3TGRMHSIpaaZGZupHPdlvO8xLZ7 ZaNAcOg8eMgL7FcyYM2UrFDM2Np98bwavJMFi643jQnij5kji9xWxlw2k0g3w5aVPXTK h/XLy2bR/2Mt5OTqb210y3QuiOUqZZq3VlTzUR/jNMejAHdb+7poDoDQlKExAwcmasQv 8EMREN/wgphG44wb0HbJxD5lM4dsLgDjFYyEDRSlt8JUMMtbVE313HgI6AmZo5N+QIUB LqzQ== X-Gm-Message-State: AOAM532nTwzvAWudxFwmSInSSa0PP69neLtdIJdOwW7HvhrORhVNWExX 1xj+pkbAXYea9ID7DeQUG8amtmB3tfuIMj4KH7j26ZdKQNLySXnUdXofj0gaJl+IRMUake2J7Vq CA14gVHLr65ppzFlC5+I99bT8Sg5+4QeBoALb6eu/d2fa3FetcYWJqwxGnieTRA+6 X-Received: by 2002:a17:902:d50b:b0:14d:ca2b:1b59 with SMTP id b11-20020a170902d50b00b0014dca2b1b59mr1513223plg.22.1644993048282; Tue, 15 Feb 2022 22:30:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHYzSxqWDeB3/+WsjZoem7hQc/LsKox76x3jYm3sxHrza1nSFZVrh5zmlpcq13Hg2k4dShDw== X-Received: by 2002:a17:902:d50b:b0:14d:ca2b:1b59 with SMTP id b11-20020a170902d50b00b0014dca2b1b59mr1513205plg.22.1644993047909; Tue, 15 Feb 2022 22:30:47 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 20/20] tests: Add postcopy preempt test Date: Wed, 16 Feb 2022 14:28:09 +0800 Message-Id: <20220216062809.57179-21-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216062809.57179-1-peterx@redhat.com> References: <20220216062809.57179-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645001289452100001 Content-Type: text/plain; charset="utf-8" Two tests are added: a normal postcopy preempt test, and a recovery test. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- tests/qtest/migration-test.c | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 7b42f6fd90..5053b40589 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -470,6 +470,7 @@ typedef struct { */ bool hide_stderr; bool use_shmem; + bool postcopy_preempt; /* only launch the target process */ bool only_target; /* Use dirty ring if true; dirty logging otherwise */ @@ -673,6 +674,11 @@ static int migrate_postcopy_prepare(QTestState **from_= ptr, migrate_set_capability(to, "postcopy-ram", true); migrate_set_capability(to, "postcopy-blocktime", true); =20 + if (args->postcopy_preempt) { + migrate_set_capability(from, "postcopy-preempt", true); + migrate_set_capability(to, "postcopy-preempt", true); + } + /* We want to pick a speed slow enough that the test completes * quickly, but that it doesn't complete precopy even on a slow * machine, so also set the downtime. @@ -719,13 +725,29 @@ static void test_postcopy(void) migrate_postcopy_complete(from, to); } =20 -static void test_postcopy_recovery(void) +static void test_postcopy_preempt(void) +{ + MigrateStart *args =3D migrate_start_new(); + QTestState *from, *to; + + args->postcopy_preempt =3D true; + + if (migrate_postcopy_prepare(&from, &to, args)) { + return; + } + migrate_postcopy_start(from, to); + migrate_postcopy_complete(from, to); +} + +/* @preempt: whether to use postcopy-preempt */ +static void test_postcopy_recovery(bool preempt) { MigrateStart *args =3D migrate_start_new(); QTestState *from, *to; g_autofree char *uri =3D NULL; =20 args->hide_stderr =3D true; + args->postcopy_preempt =3D preempt; =20 if (migrate_postcopy_prepare(&from, &to, args)) { return; @@ -781,6 +803,16 @@ static void test_postcopy_recovery(void) migrate_postcopy_complete(from, to); } =20 +static void test_postcopy_recovery_normal(void) +{ + test_postcopy_recovery(false); +} + +static void test_postcopy_recovery_preempt(void) +{ + test_postcopy_recovery(true); +} + static void test_baddest(void) { MigrateStart *args =3D migrate_start_new(); @@ -1458,7 +1490,10 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QOM); =20 qtest_add_func("/migration/postcopy/unix", test_postcopy); - qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery); + qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery_= normal); + qtest_add_func("/migration/postcopy/preempt/unix", test_postcopy_preem= pt); + qtest_add_func("/migration/postcopy/preempt/recovery", + test_postcopy_recovery_preempt); qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix", test_precopy_unix); qtest_add_func("/migration/precopy/tcp", test_precopy_tcp); --=20 2.32.0