From nobody Sun May 19 16:31:30 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1601577286; cv=none; d=zohomail.com; s=zohoarc; b=H0dRzCZSni41tUQlr2BWImOX6iwiaLsyguLy4XDtsr9cUdsTdFMAEmKXfnFWHSDtcaoj+TweFlMDYfPHzHtVxxLao0jnuoWYR7LfZ0GjBiFC6Nqiazh225PB7hve0tHPG3D0pmDm5T5VgEh7a06YPkGoYF3zMVQYpdCPuklTzVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601577286; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n4IR530G0jn3KaGrAMU+kHWU9guPG9Q80wHEffp3OJw=; b=aIJi7cp6k8JbAPcMROQeXB8XvDY/7CoaFODvvnqPKAVWi122fL9waMTX5ZopExarFj95Qfqn9bUjHy1o0J+ig1e7S1kdlaNvS4QLS79Xjrq/ZUuZA3IWUeV3dSJoZRKtj8ikFhlILPH+28yfsi3f7RKnKilwn4gEVEW9vZ2Fv6A= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601577286007894.7702673753072; Thu, 1 Oct 2020 11:34:46 -0700 (PDT) Received: from localhost ([::1]:51418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kO3Pg-00027K-Mz for importer@patchew.org; Thu, 01 Oct 2020 14:34:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kO3I6-0002Uy-EW for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kO3I3-0003gD-8L for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:54 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-18DrE5bVMSmn7IHIq8Mg5g-1; Thu, 01 Oct 2020 14:26:45 -0400 Received: by mail-qt1-f198.google.com with SMTP id w92so4369524qte.19 for ; Thu, 01 Oct 2020 11:26:45 -0700 (PDT) Received: from xz-x1.redhat.com (toroon474qw-lp130-09-184-147-14-204.dsl.bell.ca. [184.147.14.204]) by smtp.gmail.com with ESMTPSA id v56sm7892699qtc.49.2020.10.01.11.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 11:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601576807; 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=n4IR530G0jn3KaGrAMU+kHWU9guPG9Q80wHEffp3OJw=; b=IeB2DjnhBODBRec4Q0vfrnhMUEMvA6pTAAVKya3Zc3l6hy/K56c26UoqjOhJwBJnpqdlon WPICf+5DsoDWppc9ohVTjFb2NT8H24hVbMELUDQQhwizWZm4lvXIcT3YsKnWz8WpkJBtqf AK64Ktpl578vqD5/z4WQ1SP5Aw6VNGo= X-MC-Unique: 18DrE5bVMSmn7IHIq8Mg5g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n4IR530G0jn3KaGrAMU+kHWU9guPG9Q80wHEffp3OJw=; b=ai3r/JQhi0hUQUz2BhZHOeZcTc/lLCk0VDwFkWxohxVlWB/nzwcMlDjQfRNqIayJBQ g4tC34A90eK3hkhE7d5Qc3Rs8jXB66zWlAK/9zJXbLC1TYS36yIIMWfpwgfjMx0vQ1O5 HXxOf73t2gUN1QpNGoWHZfNVD1QLEb0HsTS36tWtZ8PCMaNx4k+VqkwBlnQ8Jig6ee0f q6jV0IRha63TarIfksWjHeRl2QZiSSuQAi3TtKH5ZxmfeVwvL+yBzE8beeasLMuPFGap 2zoBY3RiofxrUx0RrtF7OpKtkIntW4D6oFCKhtWo7GO7EcIBylhaizAlwWPXIHYSJ4bB qxBA== X-Gm-Message-State: AOAM532qAqFFSgntptl2mGbpJA/7h+EZzwbcRN1NC2lRNrifTFIdXpAi Ru8/sk7a87NZds1G+9SRp8BHfV9rxWp+SrLBsQtH+k06Jg9dc+oGcP7MUP85tyM5Gz6mXc9kCFL PAqfXnpaXiLLAaW0= X-Received: by 2002:a05:620a:200d:: with SMTP id c13mr8627019qka.499.1601576804963; Thu, 01 Oct 2020 11:26:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCbbMFpMCsfRF4FMFhvulPIvAG8ebmJ825JzVhQZTzDeBWMmF7VftAMt+KMqW7p3K9CYAtpw== X-Received: by 2002:a05:620a:200d:: with SMTP id c13mr8627006qka.499.1601576804728; Thu, 01 Oct 2020 11:26:44 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 1/4] migration: Pass incoming state into qemu_ufd_copy_ioctl() Date: Thu, 1 Oct 2020 14:26:38 -0400 Message-Id: <20201001182641.80232-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001182641.80232-1-peterx@redhat.com> References: <20201001182641.80232-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=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/01 02:15:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "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) Content-Type: text/plain; charset="utf-8" It'll be used in follow up patches to access more fields out of it. Meanwh= ile fetch the userfaultfd inside the function. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 0a2f88a87d..722034dc01 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1128,10 +1128,12 @@ int postcopy_ram_incoming_setup(MigrationIncomingSt= ate *mis) return 0; } =20 -static int qemu_ufd_copy_ioctl(int userfault_fd, void *host_addr, +static int qemu_ufd_copy_ioctl(MigrationIncomingState *mis, void *host_add= r, void *from_addr, uint64_t pagesize, RAMBloc= k *rb) { + int userfault_fd =3D mis->userfault_fd; int ret; + if (from_addr) { struct uffdio_copy copy_struct; copy_struct.dst =3D (uint64_t)(uintptr_t)host_addr; @@ -1185,7 +1187,7 @@ int postcopy_place_page(MigrationIncomingState *mis, = void *host, void *from, * which would be slightly cheaper, but we'd have to be careful * of the order of updating our page state. */ - if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, from, pagesize, rb)) { + if (qemu_ufd_copy_ioctl(mis, host, from, pagesize, rb)) { int e =3D errno; error_report("%s: %s copy host: %p from: %p (size: %zd)", __func__, strerror(e), host, from, pagesize); @@ -1212,7 +1214,7 @@ int postcopy_place_page_zero(MigrationIncomingState *= mis, void *host, * but it's not available for everything (e.g. hugetlbpages) */ if (qemu_ram_is_uf_zeroable(rb)) { - if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, pagesize, r= b)) { + if (qemu_ufd_copy_ioctl(mis, host, NULL, pagesize, rb)) { int e =3D errno; error_report("%s: %s zero host: %p", __func__, strerror(e), host); --=20 2.26.2 From nobody Sun May 19 16:31:30 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1601577446; cv=none; d=zohomail.com; s=zohoarc; b=kuxxZ4OTcKIAchefKpyxtHIyfvRzeCqORioviS2kWMDheKisuWHwviNNStnxzBi8SInjMbFzkIoVubG89Otd+lcS+cGi/DTGhI3mQ5UJp6BlXYOaMzS3IvpVLXfm8UIVzWF2Aoc96aUipZaJHK7fPg2r4CqY2k29Ys7E/jnlMBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601577446; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hSeDqMHpB+FHPSAPyKgXEXUo5azyTlLZe7OlYAX6W4M=; b=fxWdTb1AI50uKGysEUxKF1o3t4F59y5HWwcoCuns0xEx2G7yPzl++uEhGuv0tdO6gpcwJOhLVt9oZP7urghFhac5ScWkaN0L6SRgHU3QUTvCRsjXy1YHAMfO1iU6ydP9D45NzYomcxWf4JGpJzXo0Vgt+nhETOqvvRU0S1XIhzM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601577446337592.5298000933856; Thu, 1 Oct 2020 11:37:26 -0700 (PDT) Received: from localhost ([::1]:56284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kO3SH-0004LB-2F for importer@patchew.org; Thu, 01 Oct 2020 14:37:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kO3I8-0002X8-PA for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kO3I3-0003gK-8p for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:56 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-43C1FY8-Nmy6tICj-n0NFw-1; Thu, 01 Oct 2020 14:26:47 -0400 Received: by mail-qt1-f200.google.com with SMTP id w10so3387501qtt.23 for ; Thu, 01 Oct 2020 11:26:47 -0700 (PDT) Received: from xz-x1.redhat.com (toroon474qw-lp130-09-184-147-14-204.dsl.bell.ca. [184.147.14.204]) by smtp.gmail.com with ESMTPSA id v56sm7892699qtc.49.2020.10.01.11.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 11:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601576808; 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=hSeDqMHpB+FHPSAPyKgXEXUo5azyTlLZe7OlYAX6W4M=; b=gq7IF7D8mXf1yxj80fC5kc9W7Mp4+97RGCpjRH0+meZVaZaaxC/Jc7/lX7G7HjAYsMq8Lt vyhT3AE6GaNBM/vdGpnYmm2uegeiAuHoOunSU2di9OHZyrI4c+AtxGjfLx3wnKQOBc9MlH sIozXuISsOyQqMdD7LEEOW33OCQx35Y= X-MC-Unique: 43C1FY8-Nmy6tICj-n0NFw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hSeDqMHpB+FHPSAPyKgXEXUo5azyTlLZe7OlYAX6W4M=; b=DmC/HRhu3HVgqOAIYNRiSgyD1o8/hOr9oN602SQg16Hi84GPmGtkrlwiBg+qkiALjb ylEdh7tIEQjY1G4ZbQLA+5HWcSWlPriMdr/N6yqA78boJb2hEsJaef6ZTbdx1ywU3YeR to2WdUcE8WiVnJc1eZth8oQ+VUmHpM+LOJ0BQ39gvtNIfmNLjpM+ZkNbfmOnrdliem2G ZsG21M+EJEEzxIJ9WfM82PwGDNbPIfH+KOB18jkTpBjQDHe1aZzcfG1rYmyT6kizwV8A PPIzxIb+sv7CdznQ29mul5sWxWZq6W69ZrbOGiabUB8sDSH7Qd1LnWjn2z+LKwnWwTuF u66A== X-Gm-Message-State: AOAM530R26TUp5qPV2akXuzxQAmqa9ziQXrKzzMHhoVO5Q5rAv636Ewt Ce5qcEJ9GqktkM8cGD2I5ya8dcKVcCQACGBA+8ovO3g5WYksBckH5DZyV/sMRBmSVtTbRn2u+tV JgnYgCuM5QK0oWyU= X-Received: by 2002:a37:a8ca:: with SMTP id r193mr9086770qke.83.1601576806236; Thu, 01 Oct 2020 11:26:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH2JQFWveiXshYj/QbHcZOWi8lDX3oNsf7ABft/q6bMzlU3uWrVxMCLsQcoYkJ9939TLSs7A== X-Received: by 2002:a37:a8ca:: with SMTP id r193mr9086752qke.83.1601576806025; Thu, 01 Oct 2020 11:26:46 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 2/4] migration: Introduce migrate_send_rp_message_req_pages() Date: Thu, 1 Oct 2020 14:26:39 -0400 Message-Id: <20201001182641.80232-3-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001182641.80232-1-peterx@redhat.com> References: <20201001182641.80232-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=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/01 02:15:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "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) Content-Type: text/plain; charset="utf-8" This is another layer wrapper for sending a page request to the source VM. = The new migrate_send_rp_message_req_pages() will be used elsewhere in coming patches. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 10 ++++++++-- migration/migration.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index aca7fdcd0b..b2dac6b39c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -316,8 +316,8 @@ error: * Start: Address offset within the RB * Len: Length in bytes required - must be a multiple of pagesize */ -int migrate_send_rp_req_pages(MigrationIncomingState *mis, RAMBlock *rb, - ram_addr_t start) +int migrate_send_rp_message_req_pages(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t start) { uint8_t bufc[12 + 1 + 255]; /* start (8), len (4), rbname up to 256 */ size_t msglen =3D 12; /* start + len */ @@ -353,6 +353,12 @@ int migrate_send_rp_req_pages(MigrationIncomingState *= mis, RAMBlock *rb, return migrate_send_rp_message(mis, msg_type, msglen, bufc); } =20 +int migrate_send_rp_req_pages(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t start) +{ + return migrate_send_rp_message_req_pages(mis, rb, start); +} + static bool migration_colo_enabled; bool migration_incoming_colo_enabled(void) { diff --git a/migration/migration.h b/migration/migration.h index deb411aaad..e853ccf8b1 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -333,6 +333,8 @@ void migrate_send_rp_pong(MigrationIncomingState *mis, uint32_t value); int migrate_send_rp_req_pages(MigrationIncomingState *mis, RAMBlock *rb, ram_addr_t start); +int migrate_send_rp_message_req_pages(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t start); void migrate_send_rp_recv_bitmap(MigrationIncomingState *mis, char *block_name); void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t valu= e); --=20 2.26.2 From nobody Sun May 19 16:31:30 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1601577673; cv=none; d=zohomail.com; s=zohoarc; b=bcRxmsoS+oic3V8eDX9U0XxAPgjeExTTixtmunIm3zX71/Ew1xx5f5ISke2UXLrTH5Xdc0eR3Nc2uVzANKYzrGEEX0ydG4kSZGIOCt7b9F9TecCGo3Jzo4hoE/fhadFx8R+jgyF6YCchKvoodU8f3bif08Pk7gzqx9MFgtb1nOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601577673; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4lGREouInGz4ZONx2G48G81QvMqfjMRUwn/lLNFZea8=; b=NP0Eo2PeRwlQZevZi0A4ReW78JwvvSx28EQlsdf+KwaVBveoibPAVqIUM+qRNfMhG0CVO8Ps2quiZPu7G/A9cruqbqkclJEAK+vxbTvyQSrE91qD+kZTZHFeF3sJIpGdVYoG34EyEgUq5Se7QZymRRIaFj3+lfPZ7xwIjq5Omsc= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601577673668794.541118856293; Thu, 1 Oct 2020 11:41:13 -0700 (PDT) Received: from localhost ([::1]:35016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kO3Vw-0007Zz-8S for importer@patchew.org; Thu, 01 Oct 2020 14:41:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kO3I8-0002WV-EQ for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kO3I4-0003gO-5T for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:56 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-esXLGqX7Nlm493X7X2Bkaw-1; Thu, 01 Oct 2020 14:26:48 -0400 Received: by mail-qt1-f197.google.com with SMTP id w92so4369611qte.19 for ; Thu, 01 Oct 2020 11:26:48 -0700 (PDT) Received: from xz-x1.redhat.com (toroon474qw-lp130-09-184-147-14-204.dsl.bell.ca. [184.147.14.204]) by smtp.gmail.com with ESMTPSA id v56sm7892699qtc.49.2020.10.01.11.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 11:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601576810; 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=4lGREouInGz4ZONx2G48G81QvMqfjMRUwn/lLNFZea8=; b=d7JHGI4caMTf8ak0x9UNFt9KzOQYk9Ef/Xbf4Y9f5XodpRefDZ/PM8KLOJxCmI2Ln6fWBY RTeP7In3jFd6db+NtREud73y8VgGdbeEaVt4I0QPVXR2M0EHKSaV1Tgzd0tz/QB7iPW8Ic s2nNwe47XUGcvSlB4hhHRd9duvrD3Yw= X-MC-Unique: esXLGqX7Nlm493X7X2Bkaw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4lGREouInGz4ZONx2G48G81QvMqfjMRUwn/lLNFZea8=; b=Pjhzy4dGF/0OURVTovebt/OaWSG9XCCfCWargErSLZJLX0RTsbRC8wkBUWSP0L8DXY OAAb2bdxZ6rS4ivqyXEQp44mQYBU27GCOv9MiJ0HBmYboRmHRV79peBPSc5l+7kSb6ft AgrFZFFqDAhWG1lV70em8P5YUkuKTf0x6GMALl7hhBUpFefEDb8YfqqscPi9flOhPFry NPvvkMK9yPaVkrP04Acr/bTGBBVQA56u0k7li29GJE6au9RfwJEmujk7ZbkBVmSMmjoe RUBOLOijRIIoZ/dsas4HE8ZXDGJHc9iDDoMOJvcNLmips2QGH3h2TkDA7FoQ3nWP4VHx /KOQ== X-Gm-Message-State: AOAM530GkoauQELUGnmT5Ogpe+FfCtu/NXIQXYei/WwfYLAUYGcfiJZC EWmzQy4yXBHeLpjJWJwiFuu8+14AsrMUJhK2tWuY8oVJBkTG16/y3DbIYO6thQDfuMywWfOv69p CKJjeF8qJQAThwGo= X-Received: by 2002:ac8:411c:: with SMTP id q28mr9043726qtl.254.1601576807702; Thu, 01 Oct 2020 11:26:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCsWPHrZ1XBigUJyel0/8m2J98nTCKY7+gk8DbXtZMlN12RUG5EzV7V0wJGLu/7YzTr4lMWg== X-Received: by 2002:ac8:411c:: with SMTP id q28mr9043704qtl.254.1601576807409; Thu, 01 Oct 2020 11:26:47 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 3/4] migration: Maintain postcopy faulted addresses Date: Thu, 1 Oct 2020 14:26:40 -0400 Message-Id: <20201001182641.80232-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001182641.80232-1-peterx@redhat.com> References: <20201001182641.80232-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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/01 04:25:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "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) Content-Type: text/plain; charset="utf-8" Maintain a list of faulted addresses on the destination host for which we're waiting on. This is implemented using a GTree rather than a real list to m= ake sure even there're plenty of vCPUs/threads that are faulting, the lookup wi= ll still be fast with O(log(N)) (because we'll do that after placing each page= ). It should bring a slight overhead, but ideally that shouldn't be a big prob= lem simply because in most cases the requested page list will be short. Actually we did similar things for postcopy blocktime measurements. This p= atch didn't use that simply because: (1) blocktime measurement is towards vcpu threads only, but here we need = to record all faulted addresses, including main thread and external thread (like, DPDK via vhost-user). (2) blocktime measurement will require UFFD_FEATURE_THREAD_ID, but here we don't want to add that extra dependency on the kernel version since n= ot necessary. E.g., we don't need to know which thread faulted on which page, we also don't care about multiple threads faulting on the same page. But we only care about what addresses are faulted so waiting f= or a page copying from src. (3) blocktime measurement is not enabled by default. However we need thi= s by default especially for postcopy recover. Another thing to mention is that this patch introduced a new mutex to seria= lize the receivedmap and the page_requested tree, however that serialization does not cover other procedures like UFFDIO_COPY. Signed-off-by: Peter Xu --- migration/migration.c | 43 +++++++++++++++++++++++++++++++++++++++- migration/migration.h | 19 +++++++++++++++++- migration/postcopy-ram.c | 18 ++++++++++++++--- migration/trace-events | 2 ++ 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b2dac6b39c..be8e3182b7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -143,6 +143,13 @@ static int migration_maybe_pause(MigrationState *s, int new_state); static void migrate_fd_cancel(MigrationState *s); =20 +static gint page_request_addr_cmp(gconstpointer ap, gconstpointer bp) +{ + uint64_t a =3D (uint64_t)(uintptr_t) ap, b =3D (uint64_t)(uintptr_t) b= p; + + return (a > b) - (a < b); +} + void migration_object_init(void) { MachineState *ms =3D MACHINE(qdev_get_machine()); @@ -165,6 +172,8 @@ void migration_object_init(void) 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_mutex_init(¤t_incoming->page_request_mutex); + current_incoming->page_requested =3D g_tree_new(page_request_addr_cmp); =20 if (!migration_object_check(current_migration, &err)) { error_report_err(err); @@ -240,6 +249,11 @@ void migration_incoming_state_destroy(void) =20 qemu_event_reset(&mis->main_thread_load_event); =20 + if (mis->page_requested) { + g_tree_destroy(mis->page_requested); + mis->page_requested =3D NULL; + } + if (mis->socket_address_list) { qapi_free_SocketAddressList(mis->socket_address_list); mis->socket_address_list =3D NULL; @@ -354,8 +368,35 @@ int migrate_send_rp_message_req_pages(MigrationIncomin= gState *mis, } =20 int migrate_send_rp_req_pages(MigrationIncomingState *mis, - RAMBlock *rb, ram_addr_t start) + RAMBlock *rb, ram_addr_t start, uint64_t had= dr) { + uint64_t aligned =3D haddr & (-qemu_target_page_size()); + bool received; + + WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { + received =3D ramblock_recv_bitmap_test_byte_offset(rb, start); + if (!received && !g_tree_lookup(mis->page_requested, + (gpointer)(uintptr_t)aligned)) { + /* + * The page has not been received, and it's not yet in the page + * request list. Queue it. Set the value of element to 1, so= that + * things like g_tree_lookup() will return TRUE (1) when found. + */ + g_tree_insert(mis->page_requested, (gpointer)(uintptr_t)aligne= d, + (gpointer)1); + mis->page_requested_count++; + trace_postcopy_page_req_add(aligned, mis->page_requested_count= ); + } + } + + /* + * If the page is there, skip sending the message. We don't even need= the + * lock because as long as the page arrived, it'll be there forever. + */ + if (received) { + return 0; + } + return migrate_send_rp_message_req_pages(mis, rb, start); } =20 diff --git a/migration/migration.h b/migration/migration.h index e853ccf8b1..8d2d1ce839 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -104,6 +104,23 @@ struct MigrationIncomingState { =20 /* List of listening socket addresses */ SocketAddressList *socket_address_list; + + /* A tree of pages that we requested to the source VM */ + GTree *page_requested; + /* For debugging purpose only, but would be nice to keep */ + int page_requested_count; + /* + * The mutex helps to maintain the requested pages that we sent to the + * source, IOW, to guarantee coherent between the page_requests tree a= nd + * the per-ramblock receivedmap. Note! This does not guarantee consis= tency + * of the real page copy procedures (using UFFDIO_[ZERO]COPY). E.g., = even + * if one bit in receivedmap is cleared, UFFDIO_COPY could have happen= ed + * for that page already. This is intended so that the mutex won't + * serialize and blocked by slow operations like UFFDIO_* ioctls. How= ever + * this should be enough to make sure the page_requested tree always + * contains valid information. + */ + QemuMutex page_request_mutex; }; =20 MigrationIncomingState *migration_incoming_get_current(void); @@ -332,7 +349,7 @@ void migrate_send_rp_shut(MigrationIncomingState *mis, void migrate_send_rp_pong(MigrationIncomingState *mis, uint32_t value); int migrate_send_rp_req_pages(MigrationIncomingState *mis, RAMBlock *rb, - ram_addr_t start); + ram_addr_t start, uint64_t haddr); int migrate_send_rp_message_req_pages(MigrationIncomingState *mis, RAMBlock *rb, ram_addr_t start); void migrate_send_rp_recv_bitmap(MigrationIncomingState *mis, diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 722034dc01..bf2943db28 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -684,7 +684,7 @@ int postcopy_request_shared_page(struct PostCopyFD *pcf= d, RAMBlock *rb, qemu_ram_get_idstr(rb), rb_offset); return postcopy_wake_shared(pcfd, client_addr, rb); } - migrate_send_rp_req_pages(mis, rb, aligned_rbo); + migrate_send_rp_req_pages(mis, rb, aligned_rbo, client_addr); return 0; } =20 @@ -979,7 +979,8 @@ retry: * Send the request to the source - we want to request one * of our host page sizes (which is >=3D TPS) */ - ret =3D migrate_send_rp_req_pages(mis, rb, rb_offset); + ret =3D migrate_send_rp_req_pages(mis, rb, rb_offset, + 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)) { @@ -1149,10 +1150,21 @@ static int qemu_ufd_copy_ioctl(MigrationIncomingSta= te *mis, void *host_addr, ret =3D ioctl(userfault_fd, UFFDIO_ZEROPAGE, &zero_struct); } if (!ret) { + qemu_mutex_lock(&mis->page_request_mutex); ramblock_recv_bitmap_set_range(rb, host_addr, pagesize / qemu_target_page_size()); + /* + * If this page resolves a page fault for a previous recorded faul= ted + * address, take a special note to maintain the requested page lis= t. + */ + if (g_tree_lookup(mis->page_requested, (gconstpointer)host_addr)) { + g_tree_remove(mis->page_requested, (gconstpointer)host_addr); + mis->page_requested_count--; + trace_postcopy_page_req_del((uint64_t)(uintptr_t)host_addr, + mis->page_requested_count); + } + qemu_mutex_unlock(&mis->page_request_mutex); mark_postcopy_blocktime_end((uintptr_t)host_addr); - } return ret; } diff --git a/migration/trace-events b/migration/trace-events index 338f38b3dd..9187b03725 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -162,6 +162,7 @@ postcopy_pause_return_path(void) "" postcopy_pause_return_path_continued(void) "" postcopy_pause_continued(void) "" postcopy_start_set_run(void) "" +postcopy_page_req_add(uint64_t addr, int count) "new page req 0x%"PRIx64"t= otal %d" source_return_path_thread_bad_end(void) "" source_return_path_thread_end(void) "" source_return_path_thread_entry(void) "" @@ -272,6 +273,7 @@ postcopy_ram_incoming_cleanup_blocktime(uint64_t total)= "total blocktime %" PRIu postcopy_request_shared_page(const char *sharer, const char *rb, uint64_t = rb_offset) "for %s in %s offset 0x%"PRIx64 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(uint64_t addr, int count) "resolved page req 0x%"PRI= x64" total %d" =20 get_mem_fault_cpu_index(int cpu, uint32_t pid) "cpu: %d, pid: %u" =20 --=20 2.26.2 From nobody Sun May 19 16:31:30 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1601577555; cv=none; d=zohomail.com; s=zohoarc; b=LCCfF2WWWOCOZRwqZPK8vO1hlDX8EWgi4ixZI9qyKq2ybVVU4lq3IAeqq4wiKjJJnEPDCWWIZCmzzZfd3CBOqfkVnPeeMKEUwHodHHaoFRF2g/Aaiz5fBDtKvEXUw82XSiTRW6G9tkQxl3aRHk831Pa4VLeLU8xxKB9x6aAIPt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601577555; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vTqG44HaVE95INGJpeolUfZAxcngngTH+B8YA3RSi24=; b=HtRCikIQzLB7rmD90FFSiUmWs287rNWMgkuVqgwuGYqRx66rd7e20DDUMVJSaYIuMJYw9ft8gb5IR7Gq3lXFT3CTIUZ8bIgMiWjOaUioSCAJa2yP9npex+TtYA2XTHctgpAhI83qi8Bsssb8+NAVsjFBjzAB7R9UQngW0rStkh0= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601577555932927.2126949439496; Thu, 1 Oct 2020 11:39:15 -0700 (PDT) Received: from localhost ([::1]:60014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kO3U2-0005zH-LZ for importer@patchew.org; Thu, 01 Oct 2020 14:39:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kO3I7-0002W0-0j for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kO3I4-0003gd-CB for qemu-devel@nongnu.org; Thu, 01 Oct 2020 14:26:54 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-fR67MO-cPbedlvzMkhtPCA-1; Thu, 01 Oct 2020 14:26:49 -0400 Received: by mail-qt1-f200.google.com with SMTP id e6so4379359qtg.13 for ; Thu, 01 Oct 2020 11:26:49 -0700 (PDT) Received: from xz-x1.redhat.com (toroon474qw-lp130-09-184-147-14-204.dsl.bell.ca. [184.147.14.204]) by smtp.gmail.com with ESMTPSA id v56sm7892699qtc.49.2020.10.01.11.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 11:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601576811; 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=vTqG44HaVE95INGJpeolUfZAxcngngTH+B8YA3RSi24=; b=HuJ0EpHv3JY29nP+wXlADD+QU31WB70SK2YWyySQBp7cmerkL+klqpNUYqa/xSJyhPOr4y y7O5rDZ5oIllQaeXIbqffEc1Z2q25rYbScED2Ea3q1UD5p8glj1PpDIfJ3lBfCsN3EYoTU t3YGKwFb0JHPM0wQutFQC9IHYdXfbws= X-MC-Unique: fR67MO-cPbedlvzMkhtPCA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vTqG44HaVE95INGJpeolUfZAxcngngTH+B8YA3RSi24=; b=tctKN0cslroQ8xfUo6A7/iCVb7cMm+KEUozfuyQeUXkkvPgBg9HpYDI3Ka1+nPsABI IjP8T7aI8JD7JfMoY1NU+1LPnA6GMksI2Aug2AtrxRW3361ZucAaUnaSaVbBF7ZbgSNr rxft8rtZ3RQ9yyfnet7PBq7b7sl8Y6nc3G5QcnAFa7I/2zGJvUc+08k0e/M82M+5leQl Mz+yfZw/cYYa6mG9HmjZe0tSQPINzUaLfIADZq91H7NYtKqqpCAdLXzbuvr5+Y8zV+D4 ndiETdtMjo/t0arTcmDGMRBB6UII7tgy4En3pxHaeM0dnU4Xyvwr+Txq2zAZiw3oAunW 6Rfg== X-Gm-Message-State: AOAM5316FZyZUrA/QpQF0cRZMpdy1sf2Wj0phtm/xwUpuAVbMBk9Cgc0 4iALRGMitS/u7xDj7SgeQBz29WZ+PEJQm8Ibj9otvTX3IbnuQseGpmK7bwpMvFAgSnotjZGoaHf pWKcceRjeFi9AOl0= X-Received: by 2002:ac8:8c:: with SMTP id c12mr8905001qtg.72.1601576808925; Thu, 01 Oct 2020 11:26:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZDtLlQteYplbCpYsyGMZpI0mSLwagzwIGj6zkReI+fQYLffo+9t59vmzt9WfOpSiO06xpqA== X-Received: by 2002:ac8:8c:: with SMTP id c12mr8904977qtg.72.1601576808633; Thu, 01 Oct 2020 11:26:48 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 4/4] migration: Sync requested pages after postcopy recovery Date: Thu, 1 Oct 2020 14:26:41 -0400 Message-Id: <20201001182641.80232-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001182641.80232-1-peterx@redhat.com> References: <20201001182641.80232-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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/01 04:25:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xiaohui Li , "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) Content-Type: text/plain; charset="utf-8" We synchronize the requested pages right after a postcopy recovery happens. This helps to synchronize the prioritized pages on source so that the fault= ed threads can be served faster. Reported-by: Xiaohui Li Signed-off-by: Peter Xu --- migration/savevm.c | 57 ++++++++++++++++++++++++++++++++++++++++++ migration/trace-events | 1 + 2 files changed, 58 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 34e4b71052..56a2bfb24c 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2011,6 +2011,49 @@ static int loadvm_postcopy_handle_run(MigrationIncom= ingState *mis) return LOADVM_QUIT; } =20 +/* We must be with page_request_mutex held */ +static gboolean postcopy_sync_page_req(gpointer key, gpointer value, + gpointer data) +{ + MigrationIncomingState *mis =3D data; + void *host_addr =3D (void *) key; + ram_addr_t rb_offset; + RAMBlock *rb; + int ret; + + rb =3D qemu_ram_block_from_host(host_addr, true, &rb_offset); + if (!rb) { + /* + * This should _never_ happen. However be nice for a migrating VM= to + * not crash/assert. Post an error (note: intended to not use *_o= nce + * because we do want to see all the illegal addresses; and this c= an + * never be triggered by the guest so we're safe) and move on next. + */ + error_report("%s: illegal host addr %p", __func__, host_addr); + /* Try the next entry */ + return FALSE; + } + + ret =3D migrate_send_rp_message_req_pages(mis, rb, rb_offset); + if (ret) { + /* Please refer to above comment. */ + error_report("%s: send rp message failed for addr %p", + __func__, host_addr); + return FALSE; + } + + trace_postcopy_page_req_sync((uint64_t)(uintptr_t)host_addr); + + return FALSE; +} + +static void migrate_send_rp_req_pages_pending(MigrationIncomingState *mis) +{ + WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { + g_tree_foreach(mis->page_requested, postcopy_sync_page_req, mis); + } +} + static int loadvm_postcopy_handle_resume(MigrationIncomingState *mis) { if (mis->state !=3D MIGRATION_STATUS_POSTCOPY_RECOVER) { @@ -2033,6 +2076,20 @@ static int loadvm_postcopy_handle_resume(MigrationIn= comingState *mis) /* Tell source that "we are ready" */ migrate_send_rp_resume_ack(mis, MIGRATION_RESUME_ACK_VALUE); =20 + /* + * After a postcopy recovery, the source should have lost the postcopy + * queue, or potentially the requested pages could have been lost duri= ng + * the network down phase. Let's re-sync with the source VM by re-sen= ding + * all the pending pages that we eagerly need, so these threads won't = get + * blocked too long due to the recovery. + * + * Without this procedure, the faulted destination VM threads (waiting= for + * page requests right before the postcopy is interrupted) can keep ha= nging + * until the pages are sent by the source during the background copyin= g of + * pages, or another thread faulted on the same address accidentally. + */ + migrate_send_rp_req_pages_pending(mis); + return 0; } =20 diff --git a/migration/trace-events b/migration/trace-events index 9187b03725..5d0b0662a8 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -49,6 +49,7 @@ vmstate_save(const char *idstr, const char *vmsd_name) "%= s, %s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" postcopy_pause_incoming(void) "" postcopy_pause_incoming_continued(void) "" +postcopy_page_req_sync(uint64_t host_addr) "sync page req 0x%"PRIx64 =20 # vmstate.c vmstate_load_field_error(const char *field, int ret) "field \"%s\" load fa= iled, ret =3D %d" --=20 2.26.2