From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255466; cv=none; d=zohomail.com; s=zohoarc; b=Bj+UrWCmHeSBzyTd8ZNkr3B1C1XYhsDCL6sLmGQ/U5SMfP2kUnY0/U6R+ep0Id0Nm0o2NEEhUYWd+9/y9vuBq96h79nMsNDCH7w9S3K//0dJ/p4oWbC4djp/Bd693u5HIgwSIy5AHc8BFTwrqmL1I9aBlTOxgrVInZ8uO/8Ge7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255466; 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=8rItSmHQy9xxj9V+72hLHz9ijTCM7snxw/G8w0FVdk4=; b=dcik20f45UeBjYFdYLgsFrl5om7m6+Q11mkBAaLsk29V+Y7R85vVT525xRbC39yEDg4NsUhBwP/ba3GWy8CpUwFfn0gJstB8SD/oM1j8iD+JzEOqBGb9oizuXIeoa976ftuS6rtjtoEVv5JbC2nk2ywPOIltuFRpOU8PP02K7U8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255466485721.9323986336602; Sun, 12 Feb 2023 18:31:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROar-0001Uc-40; Sun, 12 Feb 2023 21:29:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROao-0001UF-Df for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROak-00031z-W8 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:22 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-25-1GDLdBUhMweklYHMtihDJw-1; Sun, 12 Feb 2023 21:29:17 -0500 Received: by mail-wm1-f70.google.com with SMTP id n7-20020a05600c3b8700b003dc55dcb298so6032804wms.8 for ; Sun, 12 Feb 2023 18:29:16 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id l16-20020a05600c2cd000b003daffc2ecdesm16430469wmc.13.2023.02.12.18.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255358; 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=8rItSmHQy9xxj9V+72hLHz9ijTCM7snxw/G8w0FVdk4=; b=d9XOcCKHaG/H5KEMrmv51+eMYnC/tzRs+ZFaH4+SRAK/hH+LZGLnOu/DJOWVMMpWP0g2aH 6QM4WlLBz6JdfDKxKHT2ktl3EKsgkIYKFPOA+RgXw47QiXK29dDEyP1+HG5urURnm69cR/ 5Z7zVPZfthC2D/xBIOEEFuProJ+Yw1c= X-MC-Unique: 1GDLdBUhMweklYHMtihDJw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8rItSmHQy9xxj9V+72hLHz9ijTCM7snxw/G8w0FVdk4=; b=n5FfIJgEOv0WKyAuRERxL4djj7eS4Xl1IpE6YQXw3Rbf6pX11GwK28JLaHWgfntzIy TI17T5upOIy/sQAhWMYqTsG5Hnh7DX5tR6+PfF7orc00acj5EFaBsbOOc220Ln93IflA CsZsmPoRUruzsmcZg1X0lfG+6jv8hU6TeKhVANvRUt3qr93oKOOQnUn5SNmAStK1np8a bg5mdoQ0gmt80l4NC2fqlibkKFr+YkVJU+zj/zci2KtLmZTKh7G3VZbsYfYQsP0QVSSK Eanfw4uLDuc+8vijwM2hLIontNs81ji9Q/OeGiiw6f5o4SRht5WEVvXZlk4Ww2Ph8nP5 BCEQ== X-Gm-Message-State: AO0yUKVScCEoi0WpElP6uial5v0zekpsrRvTQK8N6qtE4ogENvy830pg BdU/XXN7OxAUMsPPBgcL09PSD6o5+Bo7hzahpNd4T9X0AckoMhtHsxgwS2wZopIQq398R0Q3E6X GydVizT1FNaSWSLoR40jyFsRe0e8riDGzwjf5dGQvTe1g/xy1hQZBh6uZuiJnciJegfS/s0v0 X-Received: by 2002:a05:600c:4910:b0:3e0:c97:f1d0 with SMTP id f16-20020a05600c491000b003e00c97f1d0mr18207066wmp.20.1676255354937; Sun, 12 Feb 2023 18:29:14 -0800 (PST) X-Google-Smtp-Source: AK7set/ww/d2643oNug0nlnjcNUWNPiNWXySW6dxXJ/KV7fEsCzQ2LuBuPl77Vi7JV7UXNHhrTTW+Q== X-Received: by 2002:a05:600c:4910:b0:3e0:c97:f1d0 with SMTP id f16-20020a05600c491000b003e00c97f1d0mr18207044wmp.20.1676255354316; Sun, 12 Feb 2023 18:29:14 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 01/22] migration: Remove spurious files Date: Mon, 13 Feb 2023 03:28:50 +0100 Message-Id: <20230213022911.68490-2-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255467218100004 From: Juan Quintela I introduced spurious files on my tree during a rebase: commit ebfc57871506b3fe36cc41f69ee3ad31a34afd63 Author: Zhenzhong Duan Date: Mon Oct 17 15:53:51 2022 +0800 multifd: Fix flush of zero copy page send request Make IO channel flush call after the inflight request has been drained in multifd thread, or else we may missed to flush the inflight request. Signed-off-by: Zhenzhong Duan Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela To make things worse, it appears like Zhenzhong is the one to blame. for(int i=3D0; i < 1000000; i++) { printf("I will not do rebases when I am tired\n"); } Sorry, Juan. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Juan Quintela --- .../x86_64-quintela-devices.mak | 7 - .../x86_64-quintela2-devices.mak | 6 - migration/multifd.c.orig | 1274 ----------------- 3 files changed, 1287 deletions(-) delete mode 100644 configs/devices/x86_64-softmmu/x86_64-quintela-devices.= mak delete mode 100644 configs/devices/x86_64-softmmu/x86_64-quintela2-devices= .mak delete mode 100644 migration/multifd.c.orig diff --git a/configs/devices/x86_64-softmmu/x86_64-quintela-devices.mak b/c= onfigs/devices/x86_64-softmmu/x86_64-quintela-devices.mak deleted file mode 100644 index ee2bb8c5c9..0000000000 --- a/configs/devices/x86_64-softmmu/x86_64-quintela-devices.mak +++ /dev/null @@ -1,7 +0,0 @@ -# Boards: -# -CONFIG_ISAPC=3Dn -CONFIG_I440FX=3Dn -CONFIG_Q35=3Dn -CONFIG_MICROVM=3Dy - diff --git a/configs/devices/x86_64-softmmu/x86_64-quintela2-devices.mak b/= configs/devices/x86_64-softmmu/x86_64-quintela2-devices.mak deleted file mode 100644 index f7e4dae842..0000000000 --- a/configs/devices/x86_64-softmmu/x86_64-quintela2-devices.mak +++ /dev/null @@ -1,6 +0,0 @@ -# Boards: -# -CONFIG_ISAPC=3Dy -CONFIG_I440FX=3Dy -CONFIG_Q35=3Dy -CONFIG_MICROVM=3Dy diff --git a/migration/multifd.c.orig b/migration/multifd.c.orig deleted file mode 100644 index ad89293b4e..0000000000 --- a/migration/multifd.c.orig +++ /dev/null @@ -1,1274 +0,0 @@ -/* - * Multifd common code - * - * Copyright (c) 2019-2020 Red Hat Inc - * - * Authors: - * Juan Quintela - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - */ - -#include "qemu/osdep.h" -#include "qemu/rcu.h" -#include "exec/target_page.h" -#include "sysemu/sysemu.h" -#include "exec/ramblock.h" -#include "qemu/error-report.h" -#include "qapi/error.h" -#include "ram.h" -#include "migration.h" -#include "socket.h" -#include "tls.h" -#include "qemu-file.h" -#include "trace.h" -#include "multifd.h" - -#include "qemu/yank.h" -#include "io/channel-socket.h" -#include "yank_functions.h" - -/* Multiple fd's */ - -#define MULTIFD_MAGIC 0x11223344U -#define MULTIFD_VERSION 1 - -typedef struct { - uint32_t magic; - uint32_t version; - unsigned char uuid[16]; /* QemuUUID */ - uint8_t id; - uint8_t unused1[7]; /* Reserved for future use */ - uint64_t unused2[4]; /* Reserved for future use */ -} __attribute__((packed)) MultiFDInit_t; - -/* Multifd without compression */ - -/** - * nocomp_send_setup: setup send side - * - * For no compression this function does nothing. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_send_setup(MultiFDSendParams *p, Error **errp) -{ - return 0; -} - -/** - * nocomp_send_cleanup: cleanup send side - * - * For no compression this function does nothing. - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp) -{ - return; -} - -/** - * nocomp_send_prepare: prepare date to be able to send - * - * For no compression we just have to calculate the size of the - * packet. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) -{ - MultiFDPages_t *pages =3D p->pages; - - for (int i =3D 0; i < p->normal_num; i++) { - p->iov[p->iovs_num].iov_base =3D pages->block->host + p->normal[i]; - p->iov[p->iovs_num].iov_len =3D p->page_size; - p->iovs_num++; - } - - p->next_packet_size =3D p->normal_num * p->page_size; - p->flags |=3D MULTIFD_FLAG_NOCOMP; - return 0; -} - -/** - * nocomp_recv_setup: setup receive side - * - * For no compression this function does nothing. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_recv_setup(MultiFDRecvParams *p, Error **errp) -{ - return 0; -} - -/** - * nocomp_recv_cleanup: setup receive side - * - * For no compression this function does nothing. - * - * @p: Params for the channel that we are using - */ -static void nocomp_recv_cleanup(MultiFDRecvParams *p) -{ -} - -/** - * nocomp_recv_pages: read the data from the channel into actual pages - * - * For no compression we just need to read things into the correct place. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp) -{ - uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; - - if (flags !=3D MULTIFD_FLAG_NOCOMP) { - error_setg(errp, "multifd %u: flags received %x flags expected %x", - p->id, flags, MULTIFD_FLAG_NOCOMP); - return -1; - } - for (int i =3D 0; i < p->normal_num; i++) { - p->iov[i].iov_base =3D p->host + p->normal[i]; - p->iov[i].iov_len =3D p->page_size; - } - return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); -} - -static MultiFDMethods multifd_nocomp_ops =3D { - .send_setup =3D nocomp_send_setup, - .send_cleanup =3D nocomp_send_cleanup, - .send_prepare =3D nocomp_send_prepare, - .recv_setup =3D nocomp_recv_setup, - .recv_cleanup =3D nocomp_recv_cleanup, - .recv_pages =3D nocomp_recv_pages -}; - -static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] =3D { - [MULTIFD_COMPRESSION_NONE] =3D &multifd_nocomp_ops, -}; - -void multifd_register_ops(int method, MultiFDMethods *ops) -{ - assert(0 < method && method < MULTIFD_COMPRESSION__MAX); - multifd_ops[method] =3D ops; -} - -static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) -{ - MultiFDInit_t msg =3D {}; - int ret; - - msg.magic =3D cpu_to_be32(MULTIFD_MAGIC); - msg.version =3D cpu_to_be32(MULTIFD_VERSION); - msg.id =3D p->id; - memcpy(msg.uuid, &qemu_uuid.data, sizeof(msg.uuid)); - - ret =3D qio_channel_write_all(p->c, (char *)&msg, sizeof(msg), errp); - if (ret !=3D 0) { - return -1; - } - return 0; -} - -static int multifd_recv_initial_packet(QIOChannel *c, Error **errp) -{ - MultiFDInit_t msg; - int ret; - - ret =3D qio_channel_read_all(c, (char *)&msg, sizeof(msg), errp); - if (ret !=3D 0) { - return -1; - } - - msg.magic =3D be32_to_cpu(msg.magic); - msg.version =3D be32_to_cpu(msg.version); - - if (msg.magic !=3D MULTIFD_MAGIC) { - error_setg(errp, "multifd: received packet magic %x " - "expected %x", msg.magic, MULTIFD_MAGIC); - return -1; - } - - if (msg.version !=3D MULTIFD_VERSION) { - error_setg(errp, "multifd: received packet version %u " - "expected %u", msg.version, MULTIFD_VERSION); - return -1; - } - - if (memcmp(msg.uuid, &qemu_uuid, sizeof(qemu_uuid))) { - char *uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); - char *msg_uuid =3D qemu_uuid_unparse_strdup((const QemuUUID *)msg.= uuid); - - error_setg(errp, "multifd: received uuid '%s' and expected " - "uuid '%s' for channel %hhd", msg_uuid, uuid, msg.id); - g_free(uuid); - g_free(msg_uuid); - return -1; - } - - if (msg.id > migrate_multifd_channels()) { - error_setg(errp, "multifd: received channel version %u " - "expected %u", msg.version, MULTIFD_VERSION); - return -1; - } - - return msg.id; -} - -static MultiFDPages_t *multifd_pages_init(size_t size) -{ - MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); - - pages->allocated =3D size; - pages->offset =3D g_new0(ram_addr_t, size); - - return pages; -} - -static void multifd_pages_clear(MultiFDPages_t *pages) -{ - pages->num =3D 0; - pages->allocated =3D 0; - pages->packet_num =3D 0; - pages->block =3D NULL; - g_free(pages->offset); - pages->offset =3D NULL; - g_free(pages); -} - -static void multifd_send_fill_packet(MultiFDSendParams *p) -{ - MultiFDPacket_t *packet =3D p->packet; - int i; - - packet->flags =3D cpu_to_be32(p->flags); - packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); - packet->normal_pages =3D cpu_to_be32(p->normal_num); - packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); - packet->packet_num =3D cpu_to_be64(p->packet_num); - - if (p->pages->block) { - strncpy(packet->ramblock, p->pages->block->idstr, 256); - } - - for (i =3D 0; i < p->normal_num; i++) { - /* there are architectures where ram_addr_t is 32 bit */ - uint64_t temp =3D p->normal[i]; - - packet->offset[i] =3D cpu_to_be64(temp); - } -} - -static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) -{ - MultiFDPacket_t *packet =3D p->packet; - RAMBlock *block; - int i; - - packet->magic =3D be32_to_cpu(packet->magic); - if (packet->magic !=3D MULTIFD_MAGIC) { - error_setg(errp, "multifd: received packet " - "magic %x and expected magic %x", - packet->magic, MULTIFD_MAGIC); - return -1; - } - - packet->version =3D be32_to_cpu(packet->version); - if (packet->version !=3D MULTIFD_VERSION) { - error_setg(errp, "multifd: received packet " - "version %u and expected version %u", - packet->version, MULTIFD_VERSION); - return -1; - } - - p->flags =3D be32_to_cpu(packet->flags); - - packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); - /* - * If we received a packet that is 100 times bigger than expected - * just stop migration. It is a magic number. - */ - if (packet->pages_alloc > p->page_count) { - error_setg(errp, "multifd: received packet " - "with size %u and expected a size of %u", - packet->pages_alloc, p->page_count) ; - return -1; - } - - p->normal_num =3D be32_to_cpu(packet->normal_pages); - if (p->normal_num > packet->pages_alloc) { - error_setg(errp, "multifd: received packet " - "with %u pages and expected maximum pages are %u", - p->normal_num, packet->pages_alloc) ; - return -1; - } - - p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); - p->packet_num =3D be64_to_cpu(packet->packet_num); - - if (p->normal_num =3D=3D 0) { - return 0; - } - - /* make sure that ramblock is 0 terminated */ - packet->ramblock[255] =3D 0; - block =3D qemu_ram_block_by_name(packet->ramblock); - if (!block) { - error_setg(errp, "multifd: unknown ram block %s", - packet->ramblock); - return -1; - } - - p->host =3D block->host; - for (i =3D 0; i < p->normal_num; i++) { - uint64_t offset =3D be64_to_cpu(packet->offset[i]); - - if (offset > (block->used_length - p->page_size)) { - error_setg(errp, "multifd: offset too long %" PRIu64 - " (max " RAM_ADDR_FMT ")", - offset, block->used_length); - return -1; - } - p->normal[i] =3D offset; - } - - return 0; -} - -struct { - MultiFDSendParams *params; - /* array of pages to sent */ - MultiFDPages_t *pages; - /* global number of generated multifd packets */ - uint64_t packet_num; - /* send channels ready */ - QemuSemaphore channels_ready; - /* - * Have we already run terminate threads. There is a race when it - * happens that we got one error while we are exiting. - * We will use atomic operations. Only valid values are 0 and 1. - */ - int exiting; - /* multifd ops */ - MultiFDMethods *ops; -} *multifd_send_state; - -/* - * How we use multifd_send_state->pages and channel->pages? - * - * We create a pages for each channel, and a main one. Each time that - * we need to send a batch of pages we interchange the ones between - * multifd_send_state and the channel that is sending it. There are - * two reasons for that: - * - to not have to do so many mallocs during migration - * - to make easier to know what to free at the end of migration - * - * This way we always know who is the owner of each "pages" struct, - * and we don't need any locking. It belongs to the migration thread - * or to the channel thread. Switching is safe because the migration - * thread is using the channel mutex when changing it, and the channel - * have to had finish with its own, otherwise pending_job can't be - * false. - */ - -static int multifd_send_pages(QEMUFile *f) -{ - int i; - static int next_channel; - MultiFDSendParams *p =3D NULL; /* make happy gcc */ - MultiFDPages_t *pages =3D multifd_send_state->pages; - uint64_t transferred; - - if (qatomic_read(&multifd_send_state->exiting)) { - return -1; - } - - qemu_sem_wait(&multifd_send_state->channels_ready); - /* - * next_channel can remain from a previous migration that was - * using more channels, so ensure it doesn't overflow if the - * limit is lower now. - */ - next_channel %=3D migrate_multifd_channels(); - for (i =3D next_channel;; i =3D (i + 1) % migrate_multifd_channels()) { - p =3D &multifd_send_state->params[i]; - - qemu_mutex_lock(&p->mutex); - if (p->quit) { - error_report("%s: channel %d has already quit!", __func__, i); - qemu_mutex_unlock(&p->mutex); - return -1; - } - if (!p->pending_job) { - p->pending_job++; - next_channel =3D (i + 1) % migrate_multifd_channels(); - break; - } - qemu_mutex_unlock(&p->mutex); - } - assert(!p->pages->num); - assert(!p->pages->block); - - p->packet_num =3D multifd_send_state->packet_num++; - multifd_send_state->pages =3D p->pages; - p->pages =3D pages; - transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; - qemu_file_acct_rate_limit(f, transferred); - ram_counters.multifd_bytes +=3D transferred; - stat64_add(&ram_atomic_counters.transferred, transferred); - qemu_mutex_unlock(&p->mutex); - qemu_sem_post(&p->sem); - - return 1; -} - -int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) -{ - MultiFDPages_t *pages =3D multifd_send_state->pages; - bool changed =3D false; - - if (!pages->block) { - pages->block =3D block; - } - - if (pages->block =3D=3D block) { - pages->offset[pages->num] =3D offset; - pages->num++; - - if (pages->num < pages->allocated) { - return 1; - } - } else { - changed =3D true; - } - - if (multifd_send_pages(f) < 0) { - return -1; - } - - if (changed) { - return multifd_queue_page(f, block, offset); - } - - return 1; -} - -static void multifd_send_terminate_threads(Error *err) -{ - int i; - - trace_multifd_send_terminate_threads(err !=3D NULL); - - if (err) { - MigrationState *s =3D migrate_get_current(); - migrate_set_error(s, err); - if (s->state =3D=3D MIGRATION_STATUS_SETUP || - s->state =3D=3D MIGRATION_STATUS_PRE_SWITCHOVER || - s->state =3D=3D MIGRATION_STATUS_DEVICE || - s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - migrate_set_state(&s->state, s->state, - MIGRATION_STATUS_FAILED); - } - } - - /* - * We don't want to exit each threads twice. Depending on where - * we get the error, or if there are two independent errors in two - * threads at the same time, we can end calling this function - * twice. - */ - if (qatomic_xchg(&multifd_send_state->exiting, 1)) { - return; - } - - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - qemu_mutex_lock(&p->mutex); - p->quit =3D true; - qemu_sem_post(&p->sem); - if (p->c) { - qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - } - qemu_mutex_unlock(&p->mutex); - } -} - -void multifd_save_cleanup(void) -{ - int i; - - if (!migrate_use_multifd() || !migrate_multi_channels_is_allowed()) { - return; - } - multifd_send_terminate_threads(NULL); - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - if (p->running) { - qemu_thread_join(&p->thread); - } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - Error *local_err =3D NULL; - - if (p->registered_yank) { - migration_ioc_unregister_yank(p->c); - } - socket_send_channel_destroy(p->c); - p->c =3D NULL; - qemu_mutex_destroy(&p->mutex); - qemu_sem_destroy(&p->sem); - qemu_sem_destroy(&p->sem_sync); - g_free(p->name); - p->name =3D NULL; - multifd_pages_clear(p->pages); - p->pages =3D NULL; - p->packet_len =3D 0; - g_free(p->packet); - p->packet =3D NULL; - g_free(p->iov); - p->iov =3D NULL; - g_free(p->normal); - p->normal =3D NULL; - multifd_send_state->ops->send_cleanup(p, &local_err); - if (local_err) { - migrate_set_error(migrate_get_current(), local_err); - error_free(local_err); - } - } - qemu_sem_destroy(&multifd_send_state->channels_ready); - g_free(multifd_send_state->params); - multifd_send_state->params =3D NULL; - multifd_pages_clear(multifd_send_state->pages); - multifd_send_state->pages =3D NULL; - g_free(multifd_send_state); - multifd_send_state =3D NULL; -} - -static int multifd_zero_copy_flush(QIOChannel *c) -{ - int ret; - Error *err =3D NULL; - - ret =3D qio_channel_flush(c, &err); - if (ret < 0) { - error_report_err(err); - return -1; - } - if (ret =3D=3D 1) { - dirty_sync_missed_zero_copy(); - } - - return ret; -} - -int multifd_send_sync_main(QEMUFile *f) -{ - int i; - bool flush_zero_copy; - - if (!migrate_use_multifd()) { - return 0; - } - if (multifd_send_state->pages->num) { - if (multifd_send_pages(f) < 0) { - error_report("%s: multifd_send_pages fail", __func__); - return -1; - } - } - - /* - * When using zero-copy, it's necessary to flush the pages before any = of - * the pages can be sent again, so we'll make sure the new version of = the - * pages will always arrive _later_ than the old pages. - * - * Currently we achieve this by flushing the zero-page requested writes - * per ram iteration, but in the future we could potentially optimize = it - * to be less frequent, e.g. only after we finished one whole scanning= of - * all the dirty bitmaps. - */ - - flush_zero_copy =3D migrate_use_zero_copy_send(); - - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - trace_multifd_send_sync_main_signal(p->id); - - qemu_mutex_lock(&p->mutex); - - if (p->quit) { - error_report("%s: channel %d has already quit", __func__, i); - qemu_mutex_unlock(&p->mutex); - return -1; - } - - p->packet_num =3D multifd_send_state->packet_num++; - p->flags |=3D MULTIFD_FLAG_SYNC; - p->pending_job++; - qemu_file_acct_rate_limit(f, p->packet_len); - ram_counters.multifd_bytes +=3D p->packet_len; - stat64_add(&ram_atomic_counters.transferred, p->packet_len); - qemu_mutex_unlock(&p->mutex); - qemu_sem_post(&p->sem); - - if (flush_zero_copy && p->c && (multifd_zero_copy_flush(p->c) < 0)= ) { - return -1; - } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - trace_multifd_send_sync_main_wait(p->id); - qemu_sem_wait(&p->sem_sync); - } - trace_multifd_send_sync_main(multifd_send_state->packet_num); - - return 0; -} - -static void *multifd_send_thread(void *opaque) -{ - MultiFDSendParams *p =3D opaque; - Error *local_err =3D NULL; - int ret =3D 0; - bool use_zero_copy_send =3D migrate_use_zero_copy_send(); - - trace_multifd_send_thread_start(p->id); - rcu_register_thread(); - - if (multifd_send_initial_packet(p, &local_err) < 0) { - ret =3D -1; - goto out; - } - /* initial packet */ - p->num_packets =3D 1; - - while (true) { - qemu_sem_wait(&p->sem); - - if (qatomic_read(&multifd_send_state->exiting)) { - break; - } - qemu_mutex_lock(&p->mutex); - - if (p->pending_job) { - uint64_t packet_num =3D p->packet_num; - uint32_t flags =3D p->flags; - p->normal_num =3D 0; - - if (use_zero_copy_send) { - p->iovs_num =3D 0; - } else { - p->iovs_num =3D 1; - } - - for (int i =3D 0; i < p->pages->num; i++) { - p->normal[p->normal_num] =3D p->pages->offset[i]; - p->normal_num++; - } - - if (p->normal_num) { - ret =3D multifd_send_state->ops->send_prepare(p, &local_er= r); - if (ret !=3D 0) { - qemu_mutex_unlock(&p->mutex); - break; - } - } - multifd_send_fill_packet(p); - p->flags =3D 0; - p->num_packets++; - p->total_normal_pages +=3D p->normal_num; - p->pages->num =3D 0; - p->pages->block =3D NULL; - qemu_mutex_unlock(&p->mutex); - - trace_multifd_send(p->id, packet_num, p->normal_num, flags, - p->next_packet_size); - - if (use_zero_copy_send) { - /* Send header first, without zerocopy */ - ret =3D qio_channel_write_all(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret !=3D 0) { - break; - } - } else { - /* Send header using the same writev call */ - p->iov[0].iov_len =3D p->packet_len; - p->iov[0].iov_base =3D p->packet; - } - - ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_num,= NULL, - 0, p->write_flags, &local_er= r); - if (ret !=3D 0) { - break; - } - - qemu_mutex_lock(&p->mutex); - p->pending_job--; - qemu_mutex_unlock(&p->mutex); - - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&p->sem_sync); - } - qemu_sem_post(&multifd_send_state->channels_ready); - } else if (p->quit) { - qemu_mutex_unlock(&p->mutex); - break; - } else { - qemu_mutex_unlock(&p->mutex); - /* sometimes there are spurious wakeups */ - } - } - -out: - if (local_err) { - trace_multifd_send_error(p->id); - multifd_send_terminate_threads(local_err); - error_free(local_err); - } - - /* - * Error happen, I will exit, but I can't just leave, tell - * who pay attention to me. - */ - if (ret !=3D 0) { - qemu_sem_post(&p->sem_sync); - qemu_sem_post(&multifd_send_state->channels_ready); - } - - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); - - rcu_unregister_thread(); - trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_p= ages); - - return NULL; -} - -static bool multifd_channel_connect(MultiFDSendParams *p, - QIOChannel *ioc, - Error *error); - -static void multifd_tls_outgoing_handshake(QIOTask *task, - gpointer opaque) -{ - MultiFDSendParams *p =3D opaque; - QIOChannel *ioc =3D QIO_CHANNEL(qio_task_get_source(task)); - Error *err =3D NULL; - - if (qio_task_propagate_error(task, &err)) { - trace_multifd_tls_outgoing_handshake_error(ioc, error_get_pretty(e= rr)); - } else { - trace_multifd_tls_outgoing_handshake_complete(ioc); - } - - if (!multifd_channel_connect(p, ioc, err)) { - /* - * Error happen, mark multifd_send_thread status as 'quit' althoug= h it - * is not created, and then tell who pay attention to me. - */ - p->quit =3D true; - qemu_sem_post(&multifd_send_state->channels_ready); - qemu_sem_post(&p->sem_sync); - } -} - -static void *multifd_tls_handshake_thread(void *opaque) -{ - MultiFDSendParams *p =3D opaque; - QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(p->c); - - qio_channel_tls_handshake(tioc, - multifd_tls_outgoing_handshake, - p, - NULL, - NULL); - return NULL; -} - -static void multifd_tls_channel_connect(MultiFDSendParams *p, - QIOChannel *ioc, - Error **errp) -{ - MigrationState *s =3D migrate_get_current(); - const char *hostname =3D s->hostname; - QIOChannelTLS *tioc; - - tioc =3D migration_tls_client_create(s, ioc, hostname, errp); - if (!tioc) { - return; - } - - object_unref(OBJECT(ioc)); - trace_multifd_tls_outgoing_handshake_start(ioc, tioc, hostname); - qio_channel_set_name(QIO_CHANNEL(tioc), "multifd-tls-outgoing"); - p->c =3D QIO_CHANNEL(tioc); - qemu_thread_create(&p->thread, "multifd-tls-handshake-worker", - multifd_tls_handshake_thread, p, - QEMU_THREAD_JOINABLE); -} - -static bool multifd_channel_connect(MultiFDSendParams *p, - QIOChannel *ioc, - Error *error) -{ - trace_multifd_set_outgoing_channel( - ioc, object_get_typename(OBJECT(ioc)), - migrate_get_current()->hostname, error); - - if (!error) { - if (migrate_channel_requires_tls_upgrade(ioc)) { - multifd_tls_channel_connect(p, ioc, &error); - if (!error) { - /* - * tls_channel_connect will call back to this - * function after the TLS handshake, - * so we mustn't call multifd_send_thread until then - */ - return true; - } else { - return false; - } - } else { - migration_ioc_register_yank(ioc); - p->registered_yank =3D true; - p->c =3D ioc; - qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); - } - return true; - } - - return false; -} - -static void multifd_new_send_channel_cleanup(MultiFDSendParams *p, - QIOChannel *ioc, Error *err) -{ - migrate_set_error(migrate_get_current(), err); - /* Error happen, we need to tell who pay attention to me */ - qemu_sem_post(&multifd_send_state->channels_ready); - qemu_sem_post(&p->sem_sync); - /* - * Although multifd_send_thread is not created, but main migration - * thread neet to judge whether it is running, so we need to mark - * its status. - */ - p->quit =3D true; - object_unref(OBJECT(ioc)); - error_free(err); -} - -static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) -{ - MultiFDSendParams *p =3D opaque; - QIOChannel *sioc =3D QIO_CHANNEL(qio_task_get_source(task)); - Error *local_err =3D NULL; - - trace_multifd_new_send_channel_async(p->id); - if (qio_task_propagate_error(task, &local_err)) { - goto cleanup; - } else { - p->c =3D QIO_CHANNEL(sioc); - qio_channel_set_delay(p->c, false); - p->running =3D true; - if (!multifd_channel_connect(p, sioc, local_err)) { - goto cleanup; - } - return; - } - -cleanup: - multifd_new_send_channel_cleanup(p, sioc, local_err); -} - -int multifd_save_setup(Error **errp) -{ - int thread_count; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); - uint8_t i; - - if (!migrate_use_multifd()) { - return 0; - } - if (!migrate_multi_channels_is_allowed()) { - error_setg(errp, "multifd is not supported by current protocol"); - return -1; - } - - thread_count =3D migrate_multifd_channels(); - multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); - multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); - multifd_send_state->pages =3D multifd_pages_init(page_count); - qemu_sem_init(&multifd_send_state->channels_ready, 0); - qatomic_set(&multifd_send_state->exiting, 0); - multifd_send_state->ops =3D multifd_ops[migrate_multifd_compression()]; - - for (i =3D 0; i < thread_count; i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - qemu_mutex_init(&p->mutex); - qemu_sem_init(&p->sem, 0); - qemu_sem_init(&p->sem_sync, 0); - p->quit =3D false; - p->pending_job =3D 0; - p->id =3D i; - p->pages =3D multifd_pages_init(page_count); - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); - p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); - p->name =3D g_strdup_printf("multifdsend_%d", i); - /* We need one extra place for the packet header */ - p->iov =3D g_new0(struct iovec, page_count + 1); - p->normal =3D g_new0(ram_addr_t, page_count); - p->page_size =3D qemu_target_page_size(); - p->page_count =3D page_count; - - if (migrate_use_zero_copy_send()) { - p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; - } else { - p->write_flags =3D 0; - } - - socket_send_channel_create(multifd_new_send_channel_async, p); - } - - for (i =3D 0; i < thread_count; i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - Error *local_err =3D NULL; - int ret; - - ret =3D multifd_send_state->ops->send_setup(p, &local_err); - if (ret) { - error_propagate(errp, local_err); - return ret; - } - } - return 0; -} - -struct { - MultiFDRecvParams *params; - /* number of created threads */ - int count; - /* syncs main thread and channels */ - QemuSemaphore sem_sync; - /* global number of generated multifd packets */ - uint64_t packet_num; - /* multifd ops */ - MultiFDMethods *ops; -} *multifd_recv_state; - -static void multifd_recv_terminate_threads(Error *err) -{ - int i; - - trace_multifd_recv_terminate_threads(err !=3D NULL); - - if (err) { - MigrationState *s =3D migrate_get_current(); - migrate_set_error(s, err); - if (s->state =3D=3D MIGRATION_STATUS_SETUP || - s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - migrate_set_state(&s->state, s->state, - MIGRATION_STATUS_FAILED); - } - } - - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_lock(&p->mutex); - p->quit =3D true; - /* - * We could arrive here for two reasons: - * - normal quit, i.e. everything went fine, just finished - * - error quit: We close the channels so the channel threads - * finish the qio_channel_read_all_eof() - */ - if (p->c) { - qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - } - qemu_mutex_unlock(&p->mutex); - } -} - -int multifd_load_cleanup(Error **errp) -{ - int i; - - if (!migrate_use_multifd() || !migrate_multi_channels_is_allowed()) { - return 0; - } - multifd_recv_terminate_threads(NULL); - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - if (p->running) { - p->quit =3D true; - /* - * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle co= de, - * however try to wakeup it without harm in cleanup phase. - */ - qemu_sem_post(&p->sem_sync); - qemu_thread_join(&p->thread); - } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - migration_ioc_unregister_yank(p->c); - object_unref(OBJECT(p->c)); - p->c =3D NULL; - qemu_mutex_destroy(&p->mutex); - qemu_sem_destroy(&p->sem_sync); - g_free(p->name); - p->name =3D NULL; - p->packet_len =3D 0; - g_free(p->packet); - p->packet =3D NULL; - g_free(p->iov); - p->iov =3D NULL; - g_free(p->normal); - p->normal =3D NULL; - multifd_recv_state->ops->recv_cleanup(p); - } - qemu_sem_destroy(&multifd_recv_state->sem_sync); - g_free(multifd_recv_state->params); - multifd_recv_state->params =3D NULL; - g_free(multifd_recv_state); - multifd_recv_state =3D NULL; - - return 0; -} - -void multifd_recv_sync_main(void) -{ - int i; - - if (!migrate_use_multifd()) { - return; - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - trace_multifd_recv_sync_main_wait(p->id); - qemu_sem_wait(&multifd_recv_state->sem_sync); - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - WITH_QEMU_LOCK_GUARD(&p->mutex) { - if (multifd_recv_state->packet_num < p->packet_num) { - multifd_recv_state->packet_num =3D p->packet_num; - } - } - trace_multifd_recv_sync_main_signal(p->id); - qemu_sem_post(&p->sem_sync); - } - trace_multifd_recv_sync_main(multifd_recv_state->packet_num); -} - -static void *multifd_recv_thread(void *opaque) -{ - MultiFDRecvParams *p =3D opaque; - Error *local_err =3D NULL; - int ret; - - trace_multifd_recv_thread_start(p->id); - rcu_register_thread(); - - while (true) { - uint32_t flags; - - if (p->quit) { - break; - } - - ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret =3D=3D 0) { /* EOF */ - break; - } - if (ret =3D=3D -1) { /* Error */ - break; - } - - qemu_mutex_lock(&p->mutex); - ret =3D multifd_recv_unfill_packet(p, &local_err); - if (ret) { - qemu_mutex_unlock(&p->mutex); - break; - } - - flags =3D p->flags; - /* recv methods don't know how to handle the SYNC flag */ - p->flags &=3D ~MULTIFD_FLAG_SYNC; - trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, - p->next_packet_size); - p->num_packets++; - p->total_normal_pages +=3D p->normal_num; - qemu_mutex_unlock(&p->mutex); - - if (p->normal_num) { - ret =3D multifd_recv_state->ops->recv_pages(p, &local_err); - if (ret !=3D 0) { - break; - } - } - - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&multifd_recv_state->sem_sync); - qemu_sem_wait(&p->sem_sync); - } - } - - if (local_err) { - multifd_recv_terminate_threads(local_err); - error_free(local_err); - } - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); - - rcu_unregister_thread(); - trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_p= ages); - - return NULL; -} - -int multifd_load_setup(Error **errp) -{ - int thread_count; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); - uint8_t i; - - /* - * Return successfully if multiFD recv state is already initialised - * or multiFD is not enabled. - */ - if (multifd_recv_state || !migrate_use_multifd()) { - return 0; - } - - if (!migrate_multi_channels_is_allowed()) { - error_setg(errp, "multifd is not supported by current protocol"); - return -1; - } - thread_count =3D migrate_multifd_channels(); - multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); - multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); - qatomic_set(&multifd_recv_state->count, 0); - qemu_sem_init(&multifd_recv_state->sem_sync, 0); - multifd_recv_state->ops =3D multifd_ops[migrate_multifd_compression()]; - - for (i =3D 0; i < thread_count; i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_init(&p->mutex); - qemu_sem_init(&p->sem_sync, 0); - p->quit =3D false; - p->id =3D i; - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); - p->name =3D g_strdup_printf("multifdrecv_%d", i); - p->iov =3D g_new0(struct iovec, page_count); - p->normal =3D g_new0(ram_addr_t, page_count); - p->page_count =3D page_count; - p->page_size =3D qemu_target_page_size(); - } - - for (i =3D 0; i < thread_count; i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - Error *local_err =3D NULL; - int ret; - - ret =3D multifd_recv_state->ops->recv_setup(p, &local_err); - if (ret) { - error_propagate(errp, local_err); - return ret; - } - } - return 0; -} - -bool multifd_recv_all_channels_created(void) -{ - int thread_count =3D migrate_multifd_channels(); - - if (!migrate_use_multifd()) { - return true; - } - - if (!multifd_recv_state) { - /* Called before any connections created */ - return false; - } - - return thread_count =3D=3D qatomic_read(&multifd_recv_state->count); -} - -/* - * Try to receive all multifd channels to get ready for the migration. - * Sets @errp when failing to receive the current channel. - */ -void multifd_recv_new_channel(QIOChannel *ioc, Error **errp) -{ - MultiFDRecvParams *p; - Error *local_err =3D NULL; - int id; - - id =3D multifd_recv_initial_packet(ioc, &local_err); - if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, - "failed to receive packet" - " via multifd channel %d: ", - qatomic_read(&multifd_recv_state->count)); - return; - } - trace_multifd_recv_new_channel(id); - - p =3D &multifd_recv_state->params[id]; - if (p->c !=3D NULL) { - error_setg(&local_err, "multifd: received id '%d' already setup'", - id); - multifd_recv_terminate_threads(local_err); - error_propagate(errp, local_err); - return; - } - p->c =3D ioc; - object_ref(OBJECT(ioc)); - /* initial packet */ - p->num_packets =3D 1; - - p->running =3D true; - qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); - qatomic_inc(&multifd_recv_state->count); -} --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255401; cv=none; d=zohomail.com; s=zohoarc; b=gd80mSMhw8nKl92o4YeqmBiXqdPLGdlWiwjNMPDUgmKepe4ztyNyAHERV18WNrgqTty+IlLx54NSEgbADz2Hwt76E/rmA8Bw9yYZVfkI4kuwisXqejgLTy93bu3/jgLSKjUpNIXD3wgG5dbL9Vs2Gj4rfZElIxHOVHi70FrOkTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255401; h=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=JInKtzC6RF655Lncv3TKfNncp1aYsh6hnMBdswU/+NM=; b=QQEfwtf9ZoeCI00qSMPwVj1Q2erpq8ftk1FhUy8ZhkWnfvEHxnQTNsrRy0FlO5ZisKwy0Y1AfzP46mAC+iHhMiHBcGM1EqXDOY2mdyIAX7caK48JPBmyH53+KB4nl2yjGfIfnR5C62LTQPlInXWQJxuTj/ZCiSnoC7sfPeaqxmk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255401955910.6476898924362; Sun, 12 Feb 2023 18:30:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROao-0001UE-AV; Sun, 12 Feb 2023 21:29:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROam-0001TU-TX for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROal-00032G-GE for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:20 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-119-AYznwXpSOr65IHnYObNK8g-1; Sun, 12 Feb 2023 21:29:17 -0500 Received: by mail-wm1-f69.google.com with SMTP id b19-20020a05600c4e1300b003e10d3e1c23so8016844wmq.1 for ; Sun, 12 Feb 2023 18:29:17 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id h8-20020a05600c314800b003e11ad0750csm11591970wmo.47.2023.02.12.18.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JInKtzC6RF655Lncv3TKfNncp1aYsh6hnMBdswU/+NM=; b=jV5nXhFlb4rvHKZ5LkrnX3zo7rI8kFuHv/D2g8zHZc5vCe7DQbZI9ohQDQLhQLlnlutksV aR+SJBGK3I7HX9aoszySPEyBkq4YcJe0jBlv9kXm3lg25JnvhE1kx8Fjz2OJMF4PWfg3jb LKtzpp1foW1381O/EPAml0Ton5mfvZg= X-MC-Unique: AYznwXpSOr65IHnYObNK8g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JInKtzC6RF655Lncv3TKfNncp1aYsh6hnMBdswU/+NM=; b=slo70bOeOyJOGiQqEEZFPpFQ8ycJ+PcUoFuExcETsPujl5hcrEdV5AbuvBge0YO9Bl 0hXO01O7SYl2VtIJr3ejDF6MCuc2p/4MapEhwrTvxB8azDZFbhieurDUUQg6izYHzoUv qQDyBTRYntgdP61P89FX0U5ZPfPWxs+ATTCljyMQqZ6O+nh5D78Fd3KpdgtaD0iuW2if Lfh0y2Le4othgaNFrYhFSSO4RC4k8u6i6MQwxs7szTeKTufPmgFhM3ceFq+iS9IMrhfv G8Ub+NzoibQAY7725crd/UTS6Jwxh6Xhj9q6n4NPmvsWfZ6e1+wVZCUr7e+TFXmrXRci OCPA== X-Gm-Message-State: AO0yUKXTLDbsGDmS0G1BQDFaHc6exMlj8iQFO2xppaZweYY6zsmMhfzg hGCvL7zSWG183OW8UkXj7HgiGzltnVFnzMJtpdtPp1e8YUm4ePITx2jLOC4HRZIKtB+3UmUJVrN 7ehCQBEFLTzmw07PZec757A8bLR6wBZ1mqwp15OycgGuUj59lGjwadiriGsR3Bo1kA7JWRej1 X-Received: by 2002:a05:600c:43c7:b0:3dc:5d34:dbe5 with SMTP id f7-20020a05600c43c700b003dc5d34dbe5mr17913186wmn.28.1676255356009; Sun, 12 Feb 2023 18:29:16 -0800 (PST) X-Google-Smtp-Source: AK7set/rjwBb1Vl5Kn13Q3fwIW6CDKguDIQoZ6LxM9T832naRAaIwrS7qzrpAyVC0aeKaOSZ6J7vtw== X-Received: by 2002:a05:600c:43c7:b0:3dc:5d34:dbe5 with SMTP id f7-20020a05600c43c700b003dc5d34dbe5mr17913169wmn.28.1676255355752; Sun, 12 Feb 2023 18:29:15 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Li Zhang Subject: [PULL 02/22] multifd: cleanup the function multifd_channel_connect Date: Mon, 13 Feb 2023 03:28:51 +0100 Message-Id: <20230213022911.68490-3-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255403176100003 Content-Type: text/plain; charset="utf-8" From: Li Zhang Cleanup multifd_channel_connect Signed-off-by: Li Zhang Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/multifd.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index b7ad7002e0..c8132ab7e8 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -843,30 +843,29 @@ static bool multifd_channel_connect(MultiFDSendParams= *p, ioc, object_get_typename(OBJECT(ioc)), migrate_get_current()->hostname, error); =20 - if (!error) { - if (migrate_channel_requires_tls_upgrade(ioc)) { - multifd_tls_channel_connect(p, ioc, &error); - if (!error) { - /* - * tls_channel_connect will call back to this - * function after the TLS handshake, - * so we mustn't call multifd_send_thread until then - */ - return true; - } else { - return false; - } + if (error) { + return false; + } + if (migrate_channel_requires_tls_upgrade(ioc)) { + multifd_tls_channel_connect(p, ioc, &error); + if (!error) { + /* + * tls_channel_connect will call back to this + * function after the TLS handshake, + * so we mustn't call multifd_send_thread until then + */ + return true; } else { - migration_ioc_register_yank(ioc); - p->registered_yank =3D true; - p->c =3D ioc; - qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); - } - return true; + return false; + } + } else { + migration_ioc_register_yank(ioc); + p->registered_yank =3D true; + p->c =3D ioc; + qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, + QEMU_THREAD_JOINABLE); } - - return false; + return true; } =20 static void multifd_new_send_channel_cleanup(MultiFDSendParams *p, --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255482; cv=none; d=zohomail.com; s=zohoarc; b=UVXvDlSuqUkeigqhH4Zx1jRNP3glmf5O5d5YSxmLlQCf1S9Nl2BdGxvnKrR9r79Ih88sBSsecIG2lNsXm+91kgsmB3tOhv1kcYcf0YOt2BRl6t2W014uWDn0txQEBJPlYHa+wm6miSjptkn/Mnz4nOInar4elmKfNt54uPu4wS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255482; h=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=fijRSvjFkArAa0ryGscnf/miuX0tMpTEdiQbyj+yK9k=; b=UU7DHpZa9fjV8G27ol1+C8fyY38RMFIaeOPMgSKFoLlBEkiA793cc4av0e7OmpMgyEg9xhgu9N72gzyd9Fdq6LlyY1W+qyeqqyCmfgJQFMA+uB6TTDq8qMCkT5QRu1ORSijpWXjDqOMwAWe7MbWRDPeHCgIVh/A/xhlXDTJeV6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255482248524.681902434512; Sun, 12 Feb 2023 18:31:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROar-0001Ud-19; Sun, 12 Feb 2023 21:29:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROap-0001UP-9m for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROan-00032h-U4 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:23 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-258-zzP_RVIWNl-qQthrvExIrQ-1; Sun, 12 Feb 2023 21:29:19 -0500 Received: by mail-wm1-f72.google.com with SMTP id x10-20020a05600c21ca00b003dc5584b516so8362262wmj.7 for ; Sun, 12 Feb 2023 18:29:19 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id a1-20020a05600c348100b003db0ee277b2sm15824328wmq.5.2023.02.12.18.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fijRSvjFkArAa0ryGscnf/miuX0tMpTEdiQbyj+yK9k=; b=eBAtsp/VFp42xU/K4CsK5onAuRsPbQr6frn0noIBNHF4Ywv8CDVCCKojSH4rmtktS3Eir6 Q+8osQsb+NunkKXvRl8+WO+SB6AmOJ2IsJMwo9v04ZGfelMfmF69VRTou1vLXGEoljOVTN BNtmnyGJ3Rnl83wB1MDrmrIFBg8/rIw= X-MC-Unique: zzP_RVIWNl-qQthrvExIrQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fijRSvjFkArAa0ryGscnf/miuX0tMpTEdiQbyj+yK9k=; b=e97ZOHoxcX66Iltym4qlOtFCPYTtl2wpGBFfu7WbMdRvfAFQZoDDdKRY14Nz4L4RlV HO0DjlXHv/NNtxygxRd/s3X/VI6P8vcuZFfHFFYuXFATLpj44Qiz8BcL1KUHPKiqsyj0 c3M6/By+diQ7ut+MRFtPj4md6+IIsg642EtmmAqPqwWTdL6x0N8b6/IAkW94Vd7FkVMZ hJER/jlW/wRI08m5tMWTfUCh+QUIwDQs3oqQnUrmPhtnDwGd785SDZTZGTaKkWdnut5E j66YEQ4ZAX826lfDA686sBLT8sKp7dUkE+JEc+JH3KpF1bI/j+H/u4UFXncn7uIWQWdf s7MA== X-Gm-Message-State: AO0yUKU6hw+LYoJFi28ME0Z4QyFzUf8sxPehB9n0mqOQeLlXA3pGX0Fk Umyj0OcHC6izX67fc0XrTg8kIr+p986cjb7AGX44naHEgjJ92Vxg6aOygQ2ZPuLyUa93Iqg7hLV ELJ7eWqh0mjBc5UtBQpSyjRtfKFrIrWwGfwUesywllAOVG8hOZVR+ZqHWrJjWcz5KG/QugEoK X-Received: by 2002:a05:600c:2e95:b0:3da:50b0:e96a with SMTP id p21-20020a05600c2e9500b003da50b0e96amr17717824wmn.29.1676255357746; Sun, 12 Feb 2023 18:29:17 -0800 (PST) X-Google-Smtp-Source: AK7set/ePT7yZrSLaWTYTHkBPJUuVE73ZelgzSYQoSEBhGWKGcLJkV+9MQOnbGiclZ+GH13iJCa+/g== X-Received: by 2002:a05:600c:2e95:b0:3da:50b0:e96a with SMTP id p21-20020a05600c2e9500b003da50b0e96amr17717809wmn.29.1676255357431; Sun, 12 Feb 2023 18:29:17 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Li Zhang Subject: [PULL 03/22] multifd: Remove some redundant code Date: Mon, 13 Feb 2023 03:28:52 +0100 Message-Id: <20230213022911.68490-4-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255483198100001 Content-Type: text/plain; charset="utf-8" From: Li Zhang Clean up some unnecessary code Signed-off-by: Li Zhang Signed-off-by: Juan Quintela --- migration/multifd.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index c8132ab7e8..7aa030fb19 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -892,19 +892,15 @@ static void multifd_new_send_channel_async(QIOTask *t= ask, gpointer opaque) Error *local_err =3D NULL; =20 trace_multifd_new_send_channel_async(p->id); - if (qio_task_propagate_error(task, &local_err)) { - goto cleanup; - } else { + if (!qio_task_propagate_error(task, &local_err)) { p->c =3D QIO_CHANNEL(sioc); qio_channel_set_delay(p->c, false); p->running =3D true; - if (!multifd_channel_connect(p, sioc, local_err)) { - goto cleanup; + if (multifd_channel_connect(p, sioc, local_err)) { + return; } - return; } =20 -cleanup: multifd_new_send_channel_cleanup(p, sioc, local_err); } =20 @@ -1115,10 +1111,7 @@ static void *multifd_recv_thread(void *opaque) =20 ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, p->packet_len, &local_err); - if (ret =3D=3D 0) { /* EOF */ - break; - } - if (ret =3D=3D -1) { /* Error */ + if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ break; } =20 --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255437; cv=none; d=zohomail.com; s=zohoarc; b=HKZcWZ4CxlXZltgBMkaEMt9G2DFewpHYjoE0M6ERPXOgmfLevZJxe8JEoj8Vgvkali+RBvjDQFHu7orTMF0zx8wuoDs3XRQ8DeSWetDhsrhLbU8Fi50Me/Fy4vCMk5jFhHacIpUjqx1ElOipTZxApsXwURVCk/HXOF2kzEH5sgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255437; 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=b/tLJflEkA6J3GovCPFypAU4x8ouQ3kjA7NCUdKqBBg=; b=bu4lgAh5c5U8BwS7T1tmjjQq6f98/V0UIF2TQMaBaw9iQbcC2BIXKvz2/1osH8dADV7ePXwEmd/xPQSiPIxfNfQikmhao4gPcL129DSmE/LfCt73v/1UeRIWhRrKr1+M3Ebh821RLOWFh0xLE2yPLQrO7F8BY/KIZ3ZDAYYei64= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255437849314.33570674047223; Sun, 12 Feb 2023 18:30:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROau-0001W1-MQ; Sun, 12 Feb 2023 21:29:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROas-0001Va-OQ for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROap-000334-RI for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:26 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-377-IEetd2B1NBmEUZwoeaDTDQ-1; Sun, 12 Feb 2023 21:29:21 -0500 Received: by mail-wm1-f71.google.com with SMTP id k9-20020a05600c1c8900b003dc5dec2ac6so8369080wms.4 for ; Sun, 12 Feb 2023 18:29:21 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id i16-20020a05600c4b1000b003dc4fd6e624sm11953001wmp.19.2023.02.12.18.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255363; 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=b/tLJflEkA6J3GovCPFypAU4x8ouQ3kjA7NCUdKqBBg=; b=Eyo9GCTd4gtI4I9PTh1BEn9Y4Ealg+mmPcEAUffIynF9t43wKTriQUnM32BUkfDYxUSUsi ZhG5RpL9sC2CJtVUm/SfVDfBG7rq9df31Yje1GyOM3LWiVNs0kckcvdi2y9bysgnp003fh gcjUsrdnocOnrEeHs52L/w9D5SiR8Gw= X-MC-Unique: IEetd2B1NBmEUZwoeaDTDQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b/tLJflEkA6J3GovCPFypAU4x8ouQ3kjA7NCUdKqBBg=; b=Ig+7uM1fmnyWuV/bGrkm0JAhh7DTmt62rsFzJroh0h9/QBJBq/AIKU34i/cB9oQAgs h90fcybY+XI3xI93KslGlMfAmoA189e/eXV5VoCbRjsNtm/XIDVa4ktwgDzbcxoG8V26 97rzob9rlX+8Ye4059Ra8VQv6CUlywfHqJBMVGsIoJ7Z2I5SYNzeyULK5JolfBUxaWjK MO8BH34jTHVnOjDe0BEhCamKAGp99ROweRo85Z6SzoEuDzA+XOE/qgAicH47LMMuXY73 K9bq1NhUCtMjJq8M3yXuCellcrePv1MUI27erk7twI23IFF/sv5m84uxQFoUDbZx9Ft+ GRsw== X-Gm-Message-State: AO0yUKUVMaNFnayJkKDWVdUq18RpjuXyZx1Z9Ryf6IFM1UABPHHBGe6r QBVNB09SCXUVAaM6GaOtRqGt39Vz7wWX+2ex4cJyJ1tuMh6PBjwVzrQuizIDq+/OPf35SlzMmh2 ggpo3+7G8k30Ch4c7urAdUxyQfMl8i75usOFUVyaET/Bbj6SVoXOhpV8j8914wZrqJFWy6FCy X-Received: by 2002:a05:600c:4494:b0:3dc:5a13:c7d1 with SMTP id e20-20020a05600c449400b003dc5a13c7d1mr21808506wmo.16.1676255360042; Sun, 12 Feb 2023 18:29:20 -0800 (PST) X-Google-Smtp-Source: AK7set/olIM1Gqnu3NRVRYwcVri0Fr9mLN6HYf7vmZFIaYizK5WPPQUNR/v9gAbfhITolsf0XbqrCg== X-Received: by 2002:a05:600c:4494:b0:3dc:5a13:c7d1 with SMTP id e20-20020a05600c449400b003dc5a13c7d1mr21808484wmo.16.1676255359439; Sun, 12 Feb 2023 18:29:19 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu Subject: [PULL 04/22] linux-headers: Update to v6.1 Date: Mon, 13 Feb 2023 03:28:53 +0100 Message-Id: <20230213022911.68490-5-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255439045100003 From: Peter Xu Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Acked-by: Cornelia Huck Signed-off-by: Juan Quintela --- include/standard-headers/drm/drm_fourcc.h | 34 ++++- include/standard-headers/linux/ethtool.h | 63 +++++++- include/standard-headers/linux/fuse.h | 6 +- .../linux/input-event-codes.h | 1 + include/standard-headers/linux/virtio_blk.h | 19 +++ linux-headers/asm-generic/hugetlb_encode.h | 26 ++-- linux-headers/asm-generic/mman-common.h | 2 + linux-headers/asm-mips/mman.h | 2 + linux-headers/asm-riscv/kvm.h | 4 + linux-headers/linux/kvm.h | 1 + linux-headers/linux/psci.h | 14 ++ linux-headers/linux/userfaultfd.h | 4 + linux-headers/linux/vfio.h | 142 ++++++++++++++++++ 13 files changed, 298 insertions(+), 20 deletions(-) diff --git a/include/standard-headers/drm/drm_fourcc.h b/include/standard-h= eaders/drm/drm_fourcc.h index 48b620cbef..b868488f93 100644 --- a/include/standard-headers/drm/drm_fourcc.h +++ b/include/standard-headers/drm/drm_fourcc.h @@ -98,18 +98,42 @@ extern "C" { #define DRM_FORMAT_INVALID 0 =20 /* color index */ +#define DRM_FORMAT_C1 fourcc_code('C', '1', ' ', ' ') /* [7:0] C0:C1:C2:C= 3:C4:C5:C6:C7 1:1:1:1:1:1:1:1 eight pixels/byte */ +#define DRM_FORMAT_C2 fourcc_code('C', '2', ' ', ' ') /* [7:0] C0:C1:C2:C= 3 2:2:2:2 four pixels/byte */ +#define DRM_FORMAT_C4 fourcc_code('C', '4', ' ', ' ') /* [7:0] C0:C1 4:4 = two pixels/byte */ #define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C */ =20 -/* 8 bpp Red */ +/* 1 bpp Darkness (inverse relationship between channel value and brightne= ss) */ +#define DRM_FORMAT_D1 fourcc_code('D', '1', ' ', ' ') /* [7:0] D0:D1:D2:D= 3:D4:D5:D6:D7 1:1:1:1:1:1:1:1 eight pixels/byte */ + +/* 2 bpp Darkness (inverse relationship between channel value and brightne= ss) */ +#define DRM_FORMAT_D2 fourcc_code('D', '2', ' ', ' ') /* [7:0] D0:D1:D2:D= 3 2:2:2:2 four pixels/byte */ + +/* 4 bpp Darkness (inverse relationship between channel value and brightne= ss) */ +#define DRM_FORMAT_D4 fourcc_code('D', '4', ' ', ' ') /* [7:0] D0:D1 4:4 = two pixels/byte */ + +/* 8 bpp Darkness (inverse relationship between channel value and brightne= ss) */ +#define DRM_FORMAT_D8 fourcc_code('D', '8', ' ', ' ') /* [7:0] D */ + +/* 1 bpp Red (direct relationship between channel value and brightness) */ +#define DRM_FORMAT_R1 fourcc_code('R', '1', ' ', ' ') /* [7:0] R0:R1:R2:R= 3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte */ + +/* 2 bpp Red (direct relationship between channel value and brightness) */ +#define DRM_FORMAT_R2 fourcc_code('R', '2', ' ', ' ') /* [7:0] R0:R1:R2:R= 3 2:2:2:2 four pixels/byte */ + +/* 4 bpp Red (direct relationship between channel value and brightness) */ +#define DRM_FORMAT_R4 fourcc_code('R', '4', ' ', ' ') /* [7:0] R0:R1 4:4 = two pixels/byte */ + +/* 8 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */ =20 -/* 10 bpp Red */ +/* 10 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R10 fourcc_code('R', '1', '0', ' ') /* [15:0] x:R 6:10= little endian */ =20 -/* 12 bpp Red */ +/* 12 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R12 fourcc_code('R', '1', '2', ' ') /* [15:0] x:R 4:12= little endian */ =20 -/* 16 bpp Red */ +/* 16 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R little= endian */ =20 /* 16 bpp RG */ @@ -204,7 +228,9 @@ extern "C" { #define DRM_FORMAT_VYUY fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:= Y0:Cr0 8:8:8:8 little endian */ =20 #define DRM_FORMAT_AYUV fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:= Cr 8:8:8:8 little endian */ +#define DRM_FORMAT_AVUY8888 fourcc_code('A', 'V', 'U', 'Y') /* [31:0] A:Cr= :Cb:Y 8:8:8:8 little endian */ #define DRM_FORMAT_XYUV8888 fourcc_code('X', 'Y', 'U', 'V') /* [31:0] X:Y:= Cb:Cr 8:8:8:8 little endian */ +#define DRM_FORMAT_XVUY8888 fourcc_code('X', 'V', 'U', 'Y') /* [31:0] X:Cr= :Cb:Y 8:8:8:8 little endian */ #define DRM_FORMAT_VUY888 fourcc_code('V', 'U', '2', '4') /* [23:0] Cr:Cb:= Y 8:8:8 little endian */ #define DRM_FORMAT_VUY101010 fourcc_code('V', 'U', '3', '0') /* Y followed= by U then V, 10:10:10. Non-linear modifier only */ =20 diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-he= aders/linux/ethtool.h index 4537da20cc..1dc56cdc0a 100644 --- a/include/standard-headers/linux/ethtool.h +++ b/include/standard-headers/linux/ethtool.h @@ -736,6 +736,51 @@ enum ethtool_module_power_mode { ETHTOOL_MODULE_POWER_MODE_HIGH, }; =20 +/** + * enum ethtool_podl_pse_admin_state - operational state of the PoDL PSE + * functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState + * @ETHTOOL_PODL_PSE_ADMIN_STATE_UNKNOWN: state of PoDL PSE functions are + * unknown + * @ETHTOOL_PODL_PSE_ADMIN_STATE_DISABLED: PoDL PSE functions are disabled + * @ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED: PoDL PSE functions are enabled + */ +enum ethtool_podl_pse_admin_state { + ETHTOOL_PODL_PSE_ADMIN_STATE_UNKNOWN =3D 1, + ETHTOOL_PODL_PSE_ADMIN_STATE_DISABLED, + ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED, +}; + +/** + * enum ethtool_podl_pse_pw_d_status - power detection status of the PoDL = PSE. + * IEEE 802.3-2018 30.15.1.1.3 aPoDLPSEPowerDetectionStatus: + * @ETHTOOL_PODL_PSE_PW_D_STATUS_UNKNOWN: PoDL PSE + * @ETHTOOL_PODL_PSE_PW_D_STATUS_DISABLED: "The enumeration =E2=80=9Cdisab= led=E2=80=9D is + * asserted true when the PoDL PSE state diagram variable mr_pse_enable is + * false" + * @ETHTOOL_PODL_PSE_PW_D_STATUS_SEARCHING: "The enumeration =E2=80=9Csear= ching=E2=80=9D is + * asserted true when either of the PSE state diagram variables + * pi_detecting or pi_classifying is true." + * @ETHTOOL_PODL_PSE_PW_D_STATUS_DELIVERING: "The enumeration =E2=80=9Cdel= iveringPower=E2=80=9D + * is asserted true when the PoDL PSE state diagram variable pi_powered is + * true." + * @ETHTOOL_PODL_PSE_PW_D_STATUS_SLEEP: "The enumeration =E2=80=9Csleep=E2= =80=9D is asserted + * true when the PoDL PSE state diagram variable pi_sleeping is true." + * @ETHTOOL_PODL_PSE_PW_D_STATUS_IDLE: "The enumeration =E2=80=9Cidle=E2= =80=9D is asserted true + * when the logical combination of the PoDL PSE state diagram variables + * pi_prebiased*!pi_sleeping is true." + * @ETHTOOL_PODL_PSE_PW_D_STATUS_ERROR: "The enumeration =E2=80=9Cerror=E2= =80=9D is asserted + * true when the PoDL PSE state diagram variable overload_held is true." + */ +enum ethtool_podl_pse_pw_d_status { + ETHTOOL_PODL_PSE_PW_D_STATUS_UNKNOWN =3D 1, + ETHTOOL_PODL_PSE_PW_D_STATUS_DISABLED, + ETHTOOL_PODL_PSE_PW_D_STATUS_SEARCHING, + ETHTOOL_PODL_PSE_PW_D_STATUS_DELIVERING, + ETHTOOL_PODL_PSE_PW_D_STATUS_SLEEP, + ETHTOOL_PODL_PSE_PW_D_STATUS_IDLE, + ETHTOOL_PODL_PSE_PW_D_STATUS_ERROR, +}; + /** * struct ethtool_gstrings - string set for data tagging * @cmd: Command number =3D %ETHTOOL_GSTRINGS @@ -1840,6 +1885,20 @@ static inline int ethtool_validate_duplex(uint8_t du= plex) #define MASTER_SLAVE_STATE_SLAVE 3 #define MASTER_SLAVE_STATE_ERR 4 =20 +/* These are used to throttle the rate of data on the phy interface when t= he + * native speed of the interface is higher than the link speed. These shou= ld + * not be used for phy interfaces which natively support multiple speeds (= e.g. + * MII or SGMII). + */ +/* No rate matching performed. */ +#define RATE_MATCH_NONE 0 +/* The phy sends pause frames to throttle the MAC. */ +#define RATE_MATCH_PAUSE 1 +/* The phy asserts CRS to prevent the MAC from transmitting. */ +#define RATE_MATCH_CRS 2 +/* The MAC is programmed with a sufficiently-large IPG. */ +#define RATE_MATCH_OPEN_LOOP 3 + /* Which connector port. */ #define PORT_TP 0x00 #define PORT_AUI 0x01 @@ -2033,8 +2092,8 @@ enum ethtool_reset_flags { * reported consistently by PHYLIB. Read-only. * @master_slave_cfg: Master/slave port mode. * @master_slave_state: Master/slave port state. + * @rate_matching: Rate adaptation performed by the PHY * @reserved: Reserved for future use; see the note on reserved space. - * @reserved1: Reserved for future use; see the note on reserved space. * @link_mode_masks: Variable length bitmaps. * * If autonegotiation is disabled, the speed and @duplex represent the @@ -2085,7 +2144,7 @@ struct ethtool_link_settings { uint8_t transceiver; uint8_t master_slave_cfg; uint8_t master_slave_state; - uint8_t reserved1[1]; + uint8_t rate_matching; uint32_t reserved[7]; uint32_t link_mode_masks[]; /* layout of link_mode_masks fields: diff --git a/include/standard-headers/linux/fuse.h b/include/standard-heade= rs/linux/fuse.h index bda06258be..713d259768 100644 --- a/include/standard-headers/linux/fuse.h +++ b/include/standard-headers/linux/fuse.h @@ -194,6 +194,9 @@ * - add FUSE_SECURITY_CTX init flag * - add security context to create, mkdir, symlink, and mknod requests * - add FUSE_HAS_INODE_DAX, FUSE_ATTR_DAX + * + * 7.37 + * - add FUSE_TMPFILE */ =20 #ifndef _LINUX_FUSE_H @@ -225,7 +228,7 @@ #define FUSE_KERNEL_VERSION 7 =20 /** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 36 +#define FUSE_KERNEL_MINOR_VERSION 37 =20 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 @@ -533,6 +536,7 @@ enum fuse_opcode { FUSE_SETUPMAPPING =3D 48, FUSE_REMOVEMAPPING =3D 49, FUSE_SYNCFS =3D 50, + FUSE_TMPFILE =3D 51, =20 /* CUSE specific operations */ CUSE_INIT =3D 4096, diff --git a/include/standard-headers/linux/input-event-codes.h b/include/s= tandard-headers/linux/input-event-codes.h index 50790aee5a..815f7a1dff 100644 --- a/include/standard-headers/linux/input-event-codes.h +++ b/include/standard-headers/linux/input-event-codes.h @@ -862,6 +862,7 @@ #define ABS_TOOL_WIDTH 0x1c =20 #define ABS_VOLUME 0x20 +#define ABS_PROFILE 0x21 =20 #define ABS_MISC 0x28 =20 diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard= -headers/linux/virtio_blk.h index 2dcc90826a..e81715cd70 100644 --- a/include/standard-headers/linux/virtio_blk.h +++ b/include/standard-headers/linux/virtio_blk.h @@ -40,6 +40,7 @@ #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ +#define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */ =20 /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -119,6 +120,21 @@ struct virtio_blk_config { uint8_t write_zeroes_may_unmap; =20 uint8_t unused1[3]; + + /* the next 3 entries are guarded by VIRTIO_BLK_F_SECURE_ERASE */ + /* + * The maximum secure erase sectors (in 512-byte sectors) for + * one segment. + */ + __virtio32 max_secure_erase_sectors; + /* + * The maximum number of secure erase segments in a + * secure erase command. + */ + __virtio32 max_secure_erase_seg; + /* Secure erase commands must be aligned to this number of sectors. */ + __virtio32 secure_erase_sector_alignment; + } QEMU_PACKED; =20 /* @@ -153,6 +169,9 @@ struct virtio_blk_config { /* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 =20 +/* Secure erase command */ +#define VIRTIO_BLK_T_SECURE_ERASE 14 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 diff --git a/linux-headers/asm-generic/hugetlb_encode.h b/linux-headers/asm= -generic/hugetlb_encode.h index 4f3d5aaa11..de687009bf 100644 --- a/linux-headers/asm-generic/hugetlb_encode.h +++ b/linux-headers/asm-generic/hugetlb_encode.h @@ -20,18 +20,18 @@ #define HUGETLB_FLAG_ENCODE_SHIFT 26 #define HUGETLB_FLAG_ENCODE_MASK 0x3f =20 -#define HUGETLB_FLAG_ENCODE_16KB (14 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_64KB (16 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_512KB (19 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_1MB (20 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_2MB (21 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_8MB (23 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_16MB (24 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_32MB (25 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_256MB (28 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_512MB (29 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_1GB (30 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_2GB (31 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_16GB (34 << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_16KB (14U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_64KB (16U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_512KB (19U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_1MB (20U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_2MB (21U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_8MB (23U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_16MB (24U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_32MB (25U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_256MB (28U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_512MB (29U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_1GB (30U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_2GB (31U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_16GB (34U << HUGETLB_FLAG_ENCODE_SHIFT) =20 #endif /* _ASM_GENERIC_HUGETLB_ENCODE_H_ */ diff --git a/linux-headers/asm-generic/mman-common.h b/linux-headers/asm-ge= neric/mman-common.h index 6c1aa92a92..6ce1f1ceb4 100644 --- a/linux-headers/asm-generic/mman-common.h +++ b/linux-headers/asm-generic/mman-common.h @@ -77,6 +77,8 @@ =20 #define MADV_DONTNEED_LOCKED 24 /* like DONTNEED, but drop locked pages to= o */ =20 +#define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */ + /* compatibility flags */ #define MAP_FILE 0 =20 diff --git a/linux-headers/asm-mips/mman.h b/linux-headers/asm-mips/mman.h index 1be428663c..c6e1fc77c9 100644 --- a/linux-headers/asm-mips/mman.h +++ b/linux-headers/asm-mips/mman.h @@ -103,6 +103,8 @@ =20 #define MADV_DONTNEED_LOCKED 24 /* like DONTNEED, but drop locked pages to= o */ =20 +#define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */ + /* compatibility flags */ #define MAP_FILE 0 =20 diff --git a/linux-headers/asm-riscv/kvm.h b/linux-headers/asm-riscv/kvm.h index 7351417afd..8985ff234c 100644 --- a/linux-headers/asm-riscv/kvm.h +++ b/linux-headers/asm-riscv/kvm.h @@ -48,6 +48,7 @@ struct kvm_sregs { /* CONFIG registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_config { unsigned long isa; + unsigned long zicbom_block_size; }; =20 /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ @@ -98,6 +99,9 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_M, KVM_RISCV_ISA_EXT_SVPBMT, KVM_RISCV_ISA_EXT_SSTC, + KVM_RISCV_ISA_EXT_SVINVAL, + KVM_RISCV_ISA_EXT_ZIHINTPAUSE, + KVM_RISCV_ISA_EXT_ZICBOM, KVM_RISCV_ISA_EXT_MAX, }; =20 diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index ebdafa576d..b2783c5202 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1175,6 +1175,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220 #define KVM_CAP_S390_ZPCI_OP 221 #define KVM_CAP_S390_CPU_TOPOLOGY 222 +#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 diff --git a/linux-headers/linux/psci.h b/linux-headers/linux/psci.h index 213b2a0f70..e60dfd8907 100644 --- a/linux-headers/linux/psci.h +++ b/linux-headers/linux/psci.h @@ -48,12 +48,26 @@ #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU PSCI_0_2_FN64(7) =20 #define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10) +#define PSCI_1_0_FN_CPU_FREEZE PSCI_0_2_FN(11) +#define PSCI_1_0_FN_CPU_DEFAULT_SUSPEND PSCI_0_2_FN(12) +#define PSCI_1_0_FN_NODE_HW_STATE PSCI_0_2_FN(13) #define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14) #define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15) +#define PSCI_1_0_FN_STAT_RESIDENCY PSCI_0_2_FN(16) +#define PSCI_1_0_FN_STAT_COUNT PSCI_0_2_FN(17) + #define PSCI_1_1_FN_SYSTEM_RESET2 PSCI_0_2_FN(18) +#define PSCI_1_1_FN_MEM_PROTECT PSCI_0_2_FN(19) +#define PSCI_1_1_FN_MEM_PROTECT_CHECK_RANGE PSCI_0_2_FN(19) =20 +#define PSCI_1_0_FN64_CPU_DEFAULT_SUSPEND PSCI_0_2_FN64(12) +#define PSCI_1_0_FN64_NODE_HW_STATE PSCI_0_2_FN64(13) #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) +#define PSCI_1_0_FN64_STAT_RESIDENCY PSCI_0_2_FN64(16) +#define PSCI_1_0_FN64_STAT_COUNT PSCI_0_2_FN64(17) + #define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18) +#define PSCI_1_1_FN64_MEM_PROTECT_CHECK_RANGE PSCI_0_2_FN64(19) =20 /* PSCI v0.2 power state encoding for CPU_SUSPEND function */ #define PSCI_0_2_POWER_STATE_ID_MASK 0xffff diff --git a/linux-headers/linux/userfaultfd.h b/linux-headers/linux/userfa= ultfd.h index a3a377cd44..ba5d0df52f 100644 --- a/linux-headers/linux/userfaultfd.h +++ b/linux-headers/linux/userfaultfd.h @@ -12,6 +12,10 @@ =20 #include =20 +/* ioctls for /dev/userfaultfd */ +#define USERFAULTFD_IOC 0xAA +#define USERFAULTFD_IOC_NEW _IO(USERFAULTFD_IOC, 0x00) + /* * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR. In diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index ede44b5572..bee7e42198 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -986,6 +986,148 @@ enum vfio_device_mig_state { VFIO_DEVICE_STATE_RUNNING_P2P =3D 5, }; =20 +/* + * Upon VFIO_DEVICE_FEATURE_SET, allow the device to be moved into a low p= ower + * state with the platform-based power management. Device use of lower po= wer + * states depends on factors managed by the runtime power management core, + * including system level support and coordinating support among dependent + * devices. Enabling device low power entry does not guarantee lower power + * usage by the device, nor is a mechanism provided through this feature to + * know the current power state of the device. If any device access happe= ns + * (either from the host or through the vfio uAPI) when the device is in t= he + * low power state, then the host will move the device out of the low power + * state as necessary prior to the access. Once the access is completed, = the + * device may re-enter the low power state. For single shot low power sup= port + * with wake-up notification, see + * VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP below. Access to mmap'd + * device regions is disabled on LOW_POWER_ENTRY and may only be resumed a= fter + * calling LOW_POWER_EXIT. + */ +#define VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY 3 + +/* + * This device feature has the same behavior as + * VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY with the exception that the user + * provides an eventfd for wake-up notification. When the device moves ou= t of + * the low power state for the wake-up, the host will not allow the device= to + * re-enter a low power state without a subsequent user call to one of the= low + * power entry device feature IOCTLs. Access to mmap'd device regions is + * disabled on LOW_POWER_ENTRY_WITH_WAKEUP and may only be resumed after t= he + * low power exit. The low power exit can happen either through LOW_POWER= _EXIT + * or through any other access (where the wake-up notification has been + * generated). The access to mmap'd device regions will not trigger low p= ower + * exit. + * + * The notification through the provided eventfd will be generated only wh= en + * the device has entered and is resumed from a low power state after + * calling this device feature IOCTL. A device that has not entered low p= ower + * state, as managed through the runtime power management core, will not + * generate a notification through the provided eventfd on access. Callin= g the + * LOW_POWER_EXIT feature is optional in the case where notification has b= een + * signaled on the provided eventfd that a resume from low power has occur= red. + */ +struct vfio_device_low_power_entry_with_wakeup { + __s32 wakeup_eventfd; + __u32 reserved; +}; + +#define VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP 4 + +/* + * Upon VFIO_DEVICE_FEATURE_SET, disallow use of device low power states as + * previously enabled via VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY or + * VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP device features. + * This device feature IOCTL may itself generate a wakeup eventfd notifica= tion + * in the latter case if the device had previously entered a low power sta= te. + */ +#define VFIO_DEVICE_FEATURE_LOW_POWER_EXIT 5 + +/* + * Upon VFIO_DEVICE_FEATURE_SET start/stop device DMA logging. + * VFIO_DEVICE_FEATURE_PROBE can be used to detect if the device supports + * DMA logging. + * + * DMA logging allows a device to internally record what DMAs the device is + * initiating and report them back to userspace. It is part of the VFIO + * migration infrastructure that allows implementing dirty page tracking + * during the pre copy phase of live migration. Only DMA WRITEs are logged, + * and this API is not connected to VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE. + * + * When DMA logging is started a range of IOVAs to monitor is provided and= the + * device can optimize its logging to cover only the IOVA range given. Each + * DMA that the device initiates inside the range will be logged by the de= vice + * for later retrieval. + * + * page_size is an input that hints what tracking granularity the device + * should try to achieve. If the device cannot do the hinted page size then + * it's the driver choice which page size to pick based on its support. + * On output the device will return the page size it selected. + * + * ranges is a pointer to an array of + * struct vfio_device_feature_dma_logging_range. + * + * The core kernel code guarantees to support by minimum num_ranges that f= it + * into a single kernel page. User space can try higher values but should = give + * up if the above can't be achieved as of some driver limitations. + * + * A single call to start device DMA logging can be issued and a matching = stop + * should follow at the end. Another start is not allowed in the meantime. + */ +struct vfio_device_feature_dma_logging_control { + __aligned_u64 page_size; + __u32 num_ranges; + __u32 __reserved; + __aligned_u64 ranges; +}; + +struct vfio_device_feature_dma_logging_range { + __aligned_u64 iova; + __aligned_u64 length; +}; + +#define VFIO_DEVICE_FEATURE_DMA_LOGGING_START 6 + +/* + * Upon VFIO_DEVICE_FEATURE_SET stop device DMA logging that was started + * by VFIO_DEVICE_FEATURE_DMA_LOGGING_START + */ +#define VFIO_DEVICE_FEATURE_DMA_LOGGING_STOP 7 + +/* + * Upon VFIO_DEVICE_FEATURE_GET read back and clear the device DMA log + * + * Query the device's DMA log for written pages within the given IOVA rang= e. + * During querying the log is cleared for the IOVA range. + * + * bitmap is a pointer to an array of u64s that will hold the output bitmap + * with 1 bit reporting a page_size unit of IOVA. The mapping of IOVA to b= its + * is given by: + * bitmap[(addr - iova)/page_size] & (1ULL << (addr % 64)) + * + * The input page_size can be any power of two value and does not have to + * match the value given to VFIO_DEVICE_FEATURE_DMA_LOGGING_START. The dri= ver + * will format its internal logging to match the reporting page size, poss= ibly + * by replicating bits if the internal page size is lower than requested. + * + * The LOGGING_REPORT will only set bits in the bitmap and never clear or + * perform any initialization of the user provided bitmap. + * + * If any error is returned userspace should assume that the dirty log is + * corrupted. Error recovery is to consider all memory dirty and try to + * restart the dirty tracking, or to abort/restart the whole migration. + * + * If DMA logging is not enabled, an error will be returned. + * + */ +struct vfio_device_feature_dma_logging_report { + __aligned_u64 iova; + __aligned_u64 length; + __aligned_u64 page_size; + __aligned_u64 bitmap; +}; + +#define VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT 8 + /* -------- API for Type1 VFIO IOMMU -------- */ =20 /** --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255465; cv=none; d=zohomail.com; s=zohoarc; b=KMCo7/g0rGtlpNnHrtT0Eehkax21OPBPBvCgwM/eCF9XXZKLHnwQjEUTt4+XZx1lt7wjsxOmUY9fs8FpC+sUNcfIzml7DipbLlCVsmAj6gp4rn9h2R+2LnwxFI1Oj2zvyfYuj/yUYXe1Gjqm7LQ+kMkihEKs2veb8/Tetv/W9Fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255465; h=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=0OmubI2NEZicuPkXPyraesqovkN5V1ARkv7LLLCRMM0=; b=QZ+X9S7QHDrAqEdFnU0v/Lpa2hc/kxnuoH/072pWQgLLO0qJNpIcI+OMDSyER0Bc7FbCKTS8DfLV454J4SWy0JpHnGVcMNfkP9AxDeTcoymgJUi9iMiIND1VerI10wEKaB2LEEsQjTW7NpxFeJhleHTZ7XW551lMNgRUE9Ncsyk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255465601153.7534722268964; Sun, 12 Feb 2023 18:31:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROau-0001W0-Kw; Sun, 12 Feb 2023 21:29:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROat-0001Vn-CE for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROar-00033C-Qk for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:27 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-391-EVKUUyaUMse4mBemrU4VJg-1; Sun, 12 Feb 2023 21:29:23 -0500 Received: by mail-wm1-f70.google.com with SMTP id e38-20020a05600c4ba600b003dc434dabbdso8365467wmp.6 for ; Sun, 12 Feb 2023 18:29:23 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id m3-20020adfe0c3000000b002c4084d3472sm9273865wri.58.2023.02.12.18.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0OmubI2NEZicuPkXPyraesqovkN5V1ARkv7LLLCRMM0=; b=Mg6tnxl7S/i9hAM2gBsekAb29F25NGBbNQi4hxz6TZqeqc4+3jN6IGTunL+988Y9dNgfz9 jc0rNMwC9feOtAr7ze4nCA84ObTW3NFMPxkm9swjp8fX3GAd0ygmgYN2zW+NeJXmlsCRgg hSEAeokuEEsib1jLvYDbfJonqmwWfjA= X-MC-Unique: EVKUUyaUMse4mBemrU4VJg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0OmubI2NEZicuPkXPyraesqovkN5V1ARkv7LLLCRMM0=; b=m5jCXrUIfj7M+89sYDcx4SKnLgg+ajkNt7Fiqw/adn+cSjRm6seXKyPaYmmJU05tG/ owGaJttDMOBfL7ycPx6CKOWx5frkPiCkGDzM/c2no/c13WpyIJPr4aXOw/yZ0WFHUfJa g5URy17MbzXQyjt1OyMX0QFYdEvl3jPTEe3dB0P5CVkyqohBIlxSMAmROTqERAeKeAg2 MjgASSz72kkq80cngOAVT/ZdwUAoFsH+q/Od1L4QkVnoEviJsaXaWhQzDK+UkFCWdU0X s7Ks+jyhCWEMcStL98ZTjmrNTm9aFVqY8T9WQusf1I654CJRmt6wW8AyxeJnzkzlLWRR mLAg== X-Gm-Message-State: AO0yUKXjr9RuuKfvJqbvoPMGbH6gZqv0SY9uNTaQaeJIiu2I2qzyc7L1 7saSXcEDEDzFXpuHMosQPINTaRZggyrlCtHVBaTBcSqaq7HSxMrb2DanwDcG/YmX6iIV48aKpvT kJGKFNuXustqb7TbKKLj+kZ/jVoi8yhQBBEZCRiq75zgfh4PawfL3BOXBf7KGvbagDGSoEpql X-Received: by 2002:a05:6000:1045:b0:2c5:598c:14b0 with SMTP id c5-20020a056000104500b002c5598c14b0mr721873wrx.20.1676255361678; Sun, 12 Feb 2023 18:29:21 -0800 (PST) X-Google-Smtp-Source: AK7set9mEuAJuUUFAaKDkoF4K/Bpi3uxYbwIt8gZFY4JpKNCbwFLbmvekq3ibmA7XAgTGLiovhsauA== X-Received: by 2002:a05:6000:1045:b0:2c5:598c:14b0 with SMTP id c5-20020a056000104500b002c5598c14b0mr721855wrx.20.1676255361324; Sun, 12 Feb 2023 18:29:21 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu Subject: [PULL 05/22] util/userfaultfd: Support /dev/userfaultfd Date: Mon, 13 Feb 2023 03:28:54 +0100 Message-Id: <20230213022911.68490-6-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255467176100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Teach QEMU to use /dev/userfaultfd when it existed and fallback to the system call if either it's not there or doesn't have enough permission. Firstly, as long as the app has permission to access /dev/userfaultfd, it always have the ability to trap kernel faults which QEMU mostly wants. Meanwhile, in some context (e.g. containers) the userfaultfd syscall can be forbidden, so it can be the major way to use postcopy in a restricted environment with strict seccomp setup. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- util/userfaultfd.c | 32 ++++++++++++++++++++++++++++++++ util/trace-events | 1 + 2 files changed, 33 insertions(+) diff --git a/util/userfaultfd.c b/util/userfaultfd.c index 4953b3137d..fdff4867e8 100644 --- a/util/userfaultfd.c +++ b/util/userfaultfd.c @@ -18,10 +18,42 @@ #include #include #include +#include + +typedef enum { + UFFD_UNINITIALIZED =3D 0, + UFFD_USE_DEV_PATH, + UFFD_USE_SYSCALL, +} uffd_open_mode; =20 int uffd_open(int flags) { #if defined(__NR_userfaultfd) + static uffd_open_mode open_mode; + static int uffd_dev; + + /* Detect how to generate uffd desc when run the 1st time */ + if (open_mode =3D=3D UFFD_UNINITIALIZED) { + /* + * Make /dev/userfaultfd the default approach because it has better + * permission controls, meanwhile allows kernel faults without any + * privilege requirement (e.g. SYS_CAP_PTRACE). + */ + uffd_dev =3D open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); + if (uffd_dev >=3D 0) { + open_mode =3D UFFD_USE_DEV_PATH; + } else { + /* Fallback to the system call */ + open_mode =3D UFFD_USE_SYSCALL; + } + trace_uffd_detect_open_mode(open_mode); + } + + if (open_mode =3D=3D UFFD_USE_DEV_PATH) { + assert(uffd_dev >=3D 0); + return ioctl(uffd_dev, USERFAULTFD_IOC_NEW, flags); + } + return syscall(__NR_userfaultfd, flags); #else return -EINVAL; diff --git a/util/trace-events b/util/trace-events index c8f53d7d9f..16f78d8fe5 100644 --- a/util/trace-events +++ b/util/trace-events @@ -93,6 +93,7 @@ qemu_vfio_region_info(const char *desc, uint64_t region_o= fs, uint64_t region_siz qemu_vfio_pci_map_bar(int index, uint64_t region_ofs, uint64_t region_size= , int ofs, void *host) "map region bar#%d addr 0x%"PRIx64" size 0x%"PRIx64"= ofs 0x%x host %p" =20 #userfaultfd.c +uffd_detect_open_mode(int mode) "%d" uffd_query_features_nosys(int err) "errno: %i" uffd_query_features_api_failed(int err) "errno: %i" uffd_create_fd_nosys(int err) "errno: %i" --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255518; cv=none; d=zohomail.com; s=zohoarc; b=i+izv8Kg6d//lBTi7w3nOnA4eSnGFHwwW2kD/AwkF/sI6DjDik0QJvMbuzGGDyKUmry+/us8ZBIusJGIEiroix2GzZ7wQQKNqQC4XP4NmSnBDZHfY5rxntPrqLZbSoOqX8wcNFGkSAt51u5CI+sWafuix86vVIejPT+K0RKDV+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255518; h=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=OVgMt+TdJwmeIvY3Hw47YNm8dYS4wVaPDdNlXTwlDwQ=; b=FYkpNpKBK8+dvg/pFuP9lAHl5m6r9eG8nGU5dDw778eMxn4A8r7WuCIcIHwIWcMMOa+ZE0uKPIennhhzImg3hllVLMb289eYFjuI0g5gwytrLXyghDg5VXKjtxFGknevF02aIVVYOwjCZdFfGljyphQPsQrnnUjYw1t+YXI3xo8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255518923720.1428584678882; Sun, 12 Feb 2023 18:31:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROb3-0001YL-83; Sun, 12 Feb 2023 21:29:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROaz-0001XG-IG for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROay-00034A-57 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:33 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-434-_hMom6VdOlCnSFURYXzUJw-1; Sun, 12 Feb 2023 21:29:24 -0500 Received: by mail-wm1-f69.google.com with SMTP id d14-20020a05600c34ce00b003dd07ce79c8so6040637wmq.1 for ; Sun, 12 Feb 2023 18:29:24 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id t9-20020adfeb89000000b002be0b1e556esm9231047wrn.59.2023.02.12.18.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OVgMt+TdJwmeIvY3Hw47YNm8dYS4wVaPDdNlXTwlDwQ=; b=BfI+jxykmmJSctwsiOhTEA/lJzwGr/s4mQi2G5I1GWmp9ODjsZDR7NDzu7OqK7eF/sWe1+ zTRqi3Tn8hy5VsaeoZsffjmWrBeQbcfJZt8wkS0d06oWD3Zh8e7tSlpNU8BDalym2wLRaT LsRYAkysS+SlFUJJupbcpXJcYnrEqww= X-MC-Unique: _hMom6VdOlCnSFURYXzUJw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OVgMt+TdJwmeIvY3Hw47YNm8dYS4wVaPDdNlXTwlDwQ=; b=0DwNG2Q/k6w+A4wrO/jwRVr7vaMy6YcOS8083RH+576SJiZ+YG0XqQk6+ns8DZM3t5 iYfFEVPwZQyXO0w5QgboxYvEW2aXR2HJly13pEn2YdB1v2/G7KFZXxFtCsRHCvuRGxEa iUF78bAmnmhwPMVbQghj+2wcfo0rfFRE7nKFGqbc4PTf1zN4oXLfX7JOttYs8CtHLpUF aTBVziSmoz1Hf5Sj9oZvs+3lwoWXmiFn6m7/JTl8lEitrfP2zkcwllK7LY361kW5dTsd n+0VLaq4gtqz18cpZZYCqATebRbBpCRhZ+DcR/Tds3MxZJyoNvWxIcXPpc1R8PISqLls OWxQ== X-Gm-Message-State: AO0yUKXy3EvJBMvFb8kzOCacC52yNjXjr8Hj3qd12TxtlfUSJte2R6FX OqXfzpejMdJbafBzG5blWBcuXVdtPiISaoZrvi64kpWC0PXW9FhfLc/nBu8oYaRVesOdcMngTDn cANMZaIetvzetjb7MSSaXZQRJjnNttDolKjheboEKM8Uh/UIscl5hsNOwSC7mmzjlt92niIqv X-Received: by 2002:a5d:595f:0:b0:2c5:585d:74c5 with SMTP id e31-20020a5d595f000000b002c5585d74c5mr1617024wri.22.1676255363548; Sun, 12 Feb 2023 18:29:23 -0800 (PST) X-Google-Smtp-Source: AK7set+1AvjRljtPucQVqwFkeTx727Y5hrIJrWAWmfJIZuoPIp9WAfMkp3jkVQMcApV1qaza2muSpA== X-Received: by 2002:a5d:595f:0:b0:2c5:585d:74c5 with SMTP id e31-20020a5d595f000000b002c5585d74c5mr1617009wri.22.1676255363296; Sun, 12 Feb 2023 18:29:23 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 06/22] migration: Simplify ram_find_and_save_block() Date: Mon, 13 Feb 2023 03:28:55 +0100 Message-Id: <20230213022911.68490-7-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255519352100001 Content-Type: text/plain; charset="utf-8" From: Juan Quintela We will need later that find_dirty_block() return errors, so simplify the loop. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index b966e148c2..dd809fec1f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2542,7 +2542,6 @@ static int ram_find_and_save_block(RAMState *rs) { PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; int pages =3D 0; - bool again, found; =20 /* No dirty page as there is zero RAM */ if (!ram_bytes_total()) { @@ -2564,18 +2563,17 @@ static int ram_find_and_save_block(RAMState *rs) pss_init(pss, rs->last_seen_block, rs->last_page); =20 do { - again =3D true; - found =3D get_queued_page(rs, pss); - - if (!found) { + if (!get_queued_page(rs, pss)) { /* priority queue empty, so just search for something dirty */ - found =3D find_dirty_block(rs, pss, &again); + bool again =3D true; + if (!find_dirty_block(rs, pss, &again)) { + if (!again) { + break; + } + } } - - if (found) { - pages =3D ram_save_host_page(rs, pss); - } - } while (!pages && again); + pages =3D ram_save_host_page(rs, pss); + } while (!pages); =20 rs->last_seen_block =3D pss->block; rs->last_page =3D pss->page; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255539; cv=none; d=zohomail.com; s=zohoarc; b=n25mUhuOFtVQzAiXUr1j8q9i3fyvkMispCKbuf7pLSJp4jR50TV//uEYiCVo61z9GC/1lBnXc8hIW0RIqx4My6qka04MDIfHAMKCIX1l9A+818SrlO5o8t4ZhcvfPdJZApV9SSuQWIKKY+tNP1X6b2MwV/16YERXLLZsIadMEC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255539; h=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=wLDENILmbbXHoQfh+JsgdVt2FdytPOKPN5jSF0gsIbE=; b=lTX5qYV8kw6L8+6w96Iw6P1reA6zkLBnR532kSIBO+r+1ar7Rlg+XZ/cIebRq1PvnVBYqt5rCW6c0vXrLXLmtUr6cwPzOhgPrzBkDGjlinYMxvxGENyHOpEt7DboNn1ksFXYNuKeO9SUe3AzXZGHjNEhbxxl0l896tWXksNAEAg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167625553899724.37171971071507; Sun, 12 Feb 2023 18:32:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROb1-0001XI-3K; Sun, 12 Feb 2023 21:29:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROax-0001Wp-Le for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROaw-00033s-3r for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:31 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-503-SFStxAt4PSO7ol5_GBgpIQ-1; Sun, 12 Feb 2023 21:29:26 -0500 Received: by mail-wm1-f71.google.com with SMTP id o31-20020a05600c511f00b003dc53da325dso8356323wms.8 for ; Sun, 12 Feb 2023 18:29:26 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id s11-20020adfdb0b000000b002c3e1e1dcd7sm9351257wri.104.2023.02.12.18.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wLDENILmbbXHoQfh+JsgdVt2FdytPOKPN5jSF0gsIbE=; b=bSBSnCDLGVJ5tq737X+kZX+ENLk2y9Kvtq1iQp7ykEQstn6mC1vrZ9mN0c2LS/2zGVSImz fWscSt6RFVdPqZ+jxnFDXdEGXn+2cxYMgaWlLbB0xz3LsbYeOGffFj9pyaPKfmUA8ta2ea gx7MADuYM5Xqe/l+OaPLxHyOZ2hoY08= X-MC-Unique: SFStxAt4PSO7ol5_GBgpIQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wLDENILmbbXHoQfh+JsgdVt2FdytPOKPN5jSF0gsIbE=; b=cHcVrumOE4rovX9jrQrMnPyf30Y9jXIVgGneeSiGuArQTPPSUkF1StXZRGJC2qXQ3r 24M/ScFb62bUml8M0ejoz/6Z/oTjpYmC3ztEolTTPBYZFe9jrhyHoxXzxbnMCWgHkfhC Hclxa4+zDJzFoo43WlUVRXCt7pe2tFOILMqoCkMLOPrbexFgj4HrCcogag3THTgKQ7DV EZPk0BvM5Lf6q6jLAqVU/ZOgyNAi7l5NJzea3SDVOM1BHvv9L1D322kkNZFwvd8/4oqp uODNlA5e0ZLLwQYelpngFClWAtzvWB3wCdbtNT5zkujGix3N6pHm2rNczHmyR7ZsvIBg jWOg== X-Gm-Message-State: AO0yUKVJknlt6j3dKfBOtIfHBZoafrSTCOEnL+4DCFjSCt/2ACMYoHFO 5/5tD66BjxBzDHc/G1xdObtBkAJ0Nr1nIjUYLLl7WeQI3sfvoC24LiqDJN1iaso0TPK2DzpRB7R TASyEdPp20lvgcypCC8oqaksKAAm7umoWaLNeZxYTpA5u/IQVrvlvylnakbqGdI45/T7McNp6 X-Received: by 2002:a5d:4690:0:b0:2c5:4659:3e76 with SMTP id u16-20020a5d4690000000b002c546593e76mr6850626wrq.18.1676255365260; Sun, 12 Feb 2023 18:29:25 -0800 (PST) X-Google-Smtp-Source: AK7set/AkBoA8CyAL0GJ1g2wkOw3Cz9udImTmfN8gkOPL2DMEdstXcGyRw9TWI/l2tbPukHMj6LEEQ== X-Received: by 2002:a5d:4690:0:b0:2c5:4659:3e76 with SMTP id u16-20020a5d4690000000b002c546593e76mr6850609wrq.18.1676255364971; Sun, 12 Feb 2023 18:29:24 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 07/22] migration: Make find_dirty_block() return a single parameter Date: Mon, 13 Feb 2023 03:28:56 +0100 Message-Id: <20230213022911.68490-8-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255539428100001 Content-Type: text/plain; charset="utf-8" From: Juan Quintela We used to return two bools, just return a single int with the following meaning: old return / again / new return false false PAGE_ALL_CLEAN false true PAGE_TRY_AGAIN true true PAGE_DIRTY_FOUND /* We don't care about again at all = */ Signed-off-by: Juan Quintela --- migration/ram.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index dd809fec1f..cf577fce5c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1546,17 +1546,23 @@ retry: return pages; } =20 +#define PAGE_ALL_CLEAN 0 +#define PAGE_TRY_AGAIN 1 +#define PAGE_DIRTY_FOUND 2 /** * find_dirty_block: find the next dirty page and update any state * associated with the search process. * - * Returns true if a page is found + * Returns: + * PAGE_ALL_CLEAN: no dirty page found, give up + * PAGE_TRY_AGAIN: no dirty page found, retry for next block + * PAGE_DIRTY_FOUND: dirty page found * * @rs: current RAM state * @pss: data about the state of the current dirty page scan * @again: set to false if the search has scanned the whole of RAM */ -static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, bool *ag= ain) +static int find_dirty_block(RAMState *rs, PageSearchStatus *pss) { /* Update pss->page for the next dirty bit in ramblock */ pss_find_next_dirty(pss); @@ -1567,8 +1573,7 @@ static bool find_dirty_block(RAMState *rs, PageSearch= Status *pss, bool *again) * We've been once around the RAM and haven't found anything. * Give up. */ - *again =3D false; - return false; + return PAGE_ALL_CLEAN; } if (!offset_in_ramblock(pss->block, ((ram_addr_t)pss->page) << TARGET_PAGE_BITS)) { @@ -1597,13 +1602,10 @@ static bool find_dirty_block(RAMState *rs, PageSear= chStatus *pss, bool *again) } } /* Didn't find anything this time, but try again on the new block = */ - *again =3D true; - return false; + return PAGE_TRY_AGAIN; } else { - /* Can go around again, but... */ - *again =3D true; - /* We've found something so probably don't need to */ - return true; + /* We've found something */ + return PAGE_DIRTY_FOUND; } } =20 @@ -2562,18 +2564,23 @@ static int ram_find_and_save_block(RAMState *rs) =20 pss_init(pss, rs->last_seen_block, rs->last_page); =20 - do { + while (true){ if (!get_queued_page(rs, pss)) { /* priority queue empty, so just search for something dirty */ - bool again =3D true; - if (!find_dirty_block(rs, pss, &again)) { - if (!again) { + int res =3D find_dirty_block(rs, pss); + if (res !=3D PAGE_DIRTY_FOUND) { + if (res =3D=3D PAGE_ALL_CLEAN) { break; + } else if (res =3D=3D PAGE_TRY_AGAIN) { + continue; } } } pages =3D ram_save_host_page(rs, pss); - } while (!pages); + if (pages) { + break; + } + } =20 rs->last_seen_block =3D pss->block; rs->last_page =3D pss->page; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255401; cv=none; d=zohomail.com; s=zohoarc; b=lg1DjAkAKa6tl5VOZR7DJSTihD1vJMgXMEO/z4C5QSgU9qL3OPpZEwn7zMjlG2i+bogjr7cq2+KdMZKH6o3eUhpCdrusErp6O05a3VAfE6MJKi0BPw1ZrlIQQh8gaegKQYLwotwD5sqatUhVJsAIjSVwBpxlvIr6eOwVlMP9ggE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255401; 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=UptCkJZZ1oFnZpYoUHipdojg2SHE5Vc15YVv+FVTq60=; b=XmkRIwS7MvGhR2ew26+1nP8uj2GvQq/GFVfJfAtg0umb0xq5qHAqCJ6rcF3wA6XACUtMR9o0Lv1wE9PM+RGGJaa9s006v8W7ETnP1SuKNeVeDAUs1goOjcKWJUdI06pdEhV+i3wX22eTLlxjX0ORjsiTpghoyTmI0YRE56IcUHA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167625540194034.503644428973644; Sun, 12 Feb 2023 18:30:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROaz-0001XC-BI; Sun, 12 Feb 2023 21:29:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROay-0001Wy-0L for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROaw-00033w-Gp for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:31 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-544-PKx16lsoO5KaEwtWTzsTZg-1; Sun, 12 Feb 2023 21:29:28 -0500 Received: by mail-wm1-f70.google.com with SMTP id o31-20020a05600c511f00b003dc53da325dso8356344wms.8 for ; Sun, 12 Feb 2023 18:29:28 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id s21-20020a1cf215000000b003e001119927sm15091501wmc.24.2023.02.12.18.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255370; 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=UptCkJZZ1oFnZpYoUHipdojg2SHE5Vc15YVv+FVTq60=; b=C/R1S3Qj05XImtPv4bua4UgfLw8mvoZ7vNEVOTbNHmBTjC6Y9Kl+CskRvTSNReN6GaWWqG mYwUGfZ/jicTObehWLDZe1clzm+OFVvnhJJawdW416/s6ewQxboi5TZWAwAVqu9SkxnXZe PlDzRvvD26dCgfTPuYM1oR0Ug0/Av5E= X-MC-Unique: PKx16lsoO5KaEwtWTzsTZg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UptCkJZZ1oFnZpYoUHipdojg2SHE5Vc15YVv+FVTq60=; b=n9lCo4VH3PG98hgs3xxhV83C08zAfBE9UPEuOwfz6fdjXfEqHi5VghuVkybdwURiuU 4KYLWu6rFQOMx2jVp7Y3DU2EszMi6eRv0fAHNqIe8rGlg/9fjCsos5JbL9jOjrlO64dg VSylvjaZSVvV9soVyYE+m6zA5clC3rgfnm6CUHwiEgjn1QXwVwflKjx3ZPs5aE8xndOk GcaYpKXqCp+qEA5ergUTI2pL8PHxMQyDWmK5i3TsXC/Nd1Yq1IYV65hGb4cTafIHwdfP pSCumDvzGpVFX1Tv3Uegpln6mDcZCMxxUcE9kGIWJRJEXgKvIQYbgjqMVX6ugl02AfV/ lPzg== X-Gm-Message-State: AO0yUKXf7ldfHBOqjfI5m3h6xNzByRECAxwOib2R8ivpfF3LVE/toAsv OowqkZb0POFF1XbV5TUvEZwdt37UiX9Dx+2R7yHFU7V60NCD3j2IorSj2j9S7mbYc12veKOZyoc DZ0RgD60ONk/SYdzVm/Dm6tT1CpgduNahH+n023MDUYDR+zqcQ8icryiEuq2TWF5uFFI9Sv48 X-Received: by 2002:a05:600c:920:b0:3df:d817:df98 with SMTP id m32-20020a05600c092000b003dfd817df98mr18108859wmp.10.1676255366925; Sun, 12 Feb 2023 18:29:26 -0800 (PST) X-Google-Smtp-Source: AK7set/ZZNvjk2tGZ5tQzckq/asqm2AH0dpNmfP8JVO5494f3UTMZP5AV7bWiTgPrGjmhPGeypFXpw== X-Received: by 2002:a05:600c:920:b0:3df:d817:df98 with SMTP id m32-20020a05600c092000b003dfd817df98mr18108841wmp.10.1676255366678; Sun, 12 Feb 2023 18:29:26 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 08/22] migration: Split ram_bytes_total_common() in two functions Date: Mon, 13 Feb 2023 03:28:57 +0100 Message-Id: <20230213022911.68490-9-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255403110100001 From: Juan Quintela It is just a big if in the middle of the function, and we need two functions anways. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Juan Quintela --- Reindent to make Phillipe happy (and CODING_STYLE) --- migration/ram.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index cf577fce5c..1727fe5ef6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2601,28 +2601,30 @@ void acct_update_position(QEMUFile *f, size_t size,= bool zero) } } =20 -static uint64_t ram_bytes_total_common(bool count_ignored) +static uint64_t ram_bytes_total_with_ignored(void) { RAMBlock *block; uint64_t total =3D 0; =20 RCU_READ_LOCK_GUARD(); =20 - if (count_ignored) { - RAMBLOCK_FOREACH_MIGRATABLE(block) { - total +=3D block->used_length; - } - } else { - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - total +=3D block->used_length; - } + RAMBLOCK_FOREACH_MIGRATABLE(block) { + total +=3D block->used_length; } return total; } =20 uint64_t ram_bytes_total(void) { - return ram_bytes_total_common(false); + RAMBlock *block; + uint64_t total =3D 0; + + RCU_READ_LOCK_GUARD(); + + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + total +=3D block->used_length; + } + return total; } =20 static void xbzrle_load_setup(void) @@ -3227,7 +3229,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) (*rsp)->pss[RAM_CHANNEL_PRECOPY].pss_channel =3D f; =20 WITH_RCU_READ_LOCK_GUARD() { - qemu_put_be64(f, ram_bytes_total_common(true) | RAM_SAVE_FLAG_MEM_= SIZE); + qemu_put_be64(f, ram_bytes_total_with_ignored() + | RAM_SAVE_FLAG_MEM_SIZE); =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { qemu_put_byte(f, strlen(block->idstr)); --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255494; cv=none; d=zohomail.com; s=zohoarc; b=NKUY+o5dWRc0QgKUMHd3lNTEWtN3SPfd22Y8AZL6YwlOeZfY2GEza6YNCApJdhV+Ol+28xmJX8uPZc6o9x8sutiYrOeVNIDxhOKSlT8e3Ddh5WIfwS2BN/3uKVYqzHNyqvRbKmQj8Z9JlHBvDFs8OuMUg9W5/QG8iKjuyN3Ob6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255494; 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=x9OoujK3z66uinkW5o8sulP0PBTebtU4f6y178F9c/w=; b=Dg4v/W7ZCcF4Rg/gefgRr5EkxrjfYEb5hoKB4XGxIfAGBcqcdTDcYgyCgc4Pi+EA6ljBH4xsqCI/1IzO4sqKp26VqYRK+JDSX7/VWkoxrLeuIaeNUOz0bdHIA2tQgebw0SKQ6X2AC23vpKP6SWhj/fmI1j1OUOkqNAJz7p5mAaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167625549439362.658240486749264; Sun, 12 Feb 2023 18:31:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROb7-0001Zp-Ny; Sun, 12 Feb 2023 21:29:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb6-0001ZK-Vx for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb5-000358-Fr for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:40 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-281-RTe50vzsPPuB0-LGGk4lSg-1; Sun, 12 Feb 2023 21:29:30 -0500 Received: by mail-wr1-f69.google.com with SMTP id i4-20020a5d5224000000b002c559840c76so63752wra.3 for ; Sun, 12 Feb 2023 18:29:29 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id a7-20020a056000050700b002c3e3ee7d1asm9338278wrf.79.2023.02.12.18.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255378; 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=x9OoujK3z66uinkW5o8sulP0PBTebtU4f6y178F9c/w=; b=cbCtnHfQe2nmbdn9BhihHuB+0mdDcS3r1hBwq6XmUTrGJECYCd48t5MYkBRmGpGH5vhBDN /HpQFk5kTXiLxN9bXwC07AFhNOPQZioAw3R66PzhHTfp3cDaSx5FAA2egUXDMp38nfx3Cl l0WGoo/kBrML1G9oeT8N2Ultp7XKgsk= X-MC-Unique: RTe50vzsPPuB0-LGGk4lSg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x9OoujK3z66uinkW5o8sulP0PBTebtU4f6y178F9c/w=; b=XG2Mempcas7sn/Vu5xIhWC4bSED1ET7ae90CTcdpgIbOjHEeylyoWmd2qtZ5Dl1fr7 UVOhsq2xUzSB4eZ7V7d0xkMlUY0NLN50tVBjTr0t/268rj4gPUKRRpki6Jn597jPOApr 3s7FTmJjKxu45BKhub1b8vuNTbunYRwoxz9GD8zBCcHMZwguNunqbghULBqkXQYTz+N4 50HvJS74cEDFiyBMA83mekSfFYGcH+X6C2IG1c9dAYLjGPVY8CMmjS1/gMsoX+0yei++ MvTrUxOT6rPVDUrCE7TmlvRWOICYQzfhvPp3Nk0e5aKPDJU/2ke6vdh793a/lvCs5JuP 3UwA== X-Gm-Message-State: AO0yUKUmS+ZF56Hfttouvn2qMaZh5p8K/0VwtuYRIEZUF0G/NHSB0+Xy dqRDRUH8T56LSEQGJGsmsiG4ft7bkdH+sMCXrjfhTCzabYH21r9K3htMUDLG8zZjZUz3DzT40qH 4AOgxXN9ZAdWbw5GzNJ625V5fIm8fIa5FDxm4Pc1u2wvBSIYqW3mkrKtmzkSFX8oZJLOh1gja X-Received: by 2002:adf:dc04:0:b0:2c3:ea92:3494 with SMTP id t4-20020adfdc04000000b002c3ea923494mr18343390wri.55.1676255368416; Sun, 12 Feb 2023 18:29:28 -0800 (PST) X-Google-Smtp-Source: AK7set+I1g+CjQEsCE9I+sUqcpmuWn8GMN5Pg5a9hM8lnrQcitUKUf6RFY2A0VQFHTwHB+L4NfTg3g== X-Received: by 2002:adf:dc04:0:b0:2c3:ea92:3494 with SMTP id t4-20020adfdc04000000b002c3ea923494mr18343372wri.55.1676255368146; Sun, 12 Feb 2023 18:29:28 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 09/22] migration: Calculate ram size once Date: Mon, 13 Feb 2023 03:28:58 +0100 Message-Id: <20230213022911.68490-10-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255495247100009 From: Juan Quintela We are recalculating ram size continously, when we know that it don't change during migration. Create a field in RAMState to track it. Signed-off-by: Juan Quintela Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- migration/ram.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 1727fe5ef6..6abfe075f2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -330,6 +330,8 @@ struct RAMState { PageSearchStatus pss[RAM_CHANNEL_MAX]; /* UFFD file descriptor, used in 'write-tracking' migration */ int uffdio_fd; + /* total ram size in bytes */ + uint64_t ram_bytes_total; /* Last block that we have visited searching for dirty pages */ RAMBlock *last_seen_block; /* Last dirty target page we have sent */ @@ -2546,7 +2548,7 @@ static int ram_find_and_save_block(RAMState *rs) int pages =3D 0; =20 /* No dirty page as there is zero RAM */ - if (!ram_bytes_total()) { + if (!rs->ram_bytes_total) { return pages; } =20 @@ -3009,13 +3011,14 @@ static int ram_state_init(RAMState **rsp) qemu_mutex_init(&(*rsp)->bitmap_mutex); qemu_mutex_init(&(*rsp)->src_page_req_mutex); QSIMPLEQ_INIT(&(*rsp)->src_page_requests); + (*rsp)->ram_bytes_total =3D ram_bytes_total(); =20 /* * Count the total number of pages used by ram blocks not including any * gaps due to alignment or unplugs. * This must match with the initial values of dirty bitmap. */ - (*rsp)->migration_dirty_pages =3D ram_bytes_total() >> TARGET_PAGE_BIT= S; + (*rsp)->migration_dirty_pages =3D (*rsp)->ram_bytes_total >> TARGET_PA= GE_BITS; ram_state_reset(*rsp); =20 return 0; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255495; cv=none; d=zohomail.com; s=zohoarc; b=L3gyqY2xikig5bmlShq6NXJj6jf4y9PkImMjo1CTsMnWzGiWa+3zmhJULgiFq4dIiZfNLhBe04UiEZQ+kFlb5b0Hi+zbztVrDT3RVnxbS09GmbHWFkgkRCQgLrjWuopW1bU7O+Cej7jgL6UXKVX5o2uxaE+xXlSrlg1O3/+MlTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255495; h=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=PZlebtb52gHEYf4LdFiVz+W2gRdaAlvhDiXn8io+x3s=; b=iXdqMYiCIZm+HhDoTQB4dQoi4+eKWyDXg5xUCT4sNak9XmCbLEsYNU1I6WWV08/pDiu9xBWwo/4faftzcBM5rrILzx97taytOH+JeaXImuBVn0LQq5CcSnijmycK8usi8fW4xav6P8ox1XP1eMENRvrNkZgT9x/vm9mI7boZvhg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255495223227.29291267144583; Sun, 12 Feb 2023 18:31:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROb4-0001Ya-V1; Sun, 12 Feb 2023 21:29:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb1-0001Xt-UO for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROaz-00034T-W7 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:35 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-509-7L6fRShaOK-aJ7V4XyCaCg-1; Sun, 12 Feb 2023 21:29:31 -0500 Received: by mail-wm1-f70.google.com with SMTP id n7-20020a05600c3b8700b003dc55dcb298so6033052wms.8 for ; Sun, 12 Feb 2023 18:29:31 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id bi5-20020a05600c3d8500b003d9aa76dc6asm16368498wmb.0.2023.02.12.18.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZlebtb52gHEYf4LdFiVz+W2gRdaAlvhDiXn8io+x3s=; b=ByDP8yVc6HnWPj4LBjES9k6j8F/6QaZpwkwXKejqBvJrW4NilUPE0oj+aZm8h6hWe77/wD sarFEllEiYvCisFQ+1y+4Syd0qKmHOxoL/YSE82iWIfd9jzB5AFuW+fD6imEVwsL4nrkAb viT3uXUAJmzt2l8jzj6n/qlV19yPOCo= X-MC-Unique: 7L6fRShaOK-aJ7V4XyCaCg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PZlebtb52gHEYf4LdFiVz+W2gRdaAlvhDiXn8io+x3s=; b=Dh4tRNEwh+VnFcbgvqNXHWr/dXF/MkRmdcmJMjcP+R9hkXI5avrmnFiHTSlK5E569S MRbUr51UgsvaxEhS14vuXJEqoCePAwTJXxoUQF6HhZEV8rEPzDBAVzd/qFC8VQA1Rog9 mTv6ziXdAdS8Xru29i4amjcXmIFPyT6Y6daKqORvNdL9cD9bh9VoZQfHyFFqOzJ6h9vV IU3VLaFrY85Z5iRduBoPsvoayA/PIgGJpjqxBwbq2Vv8ennWKczVdCLNxGhdGBNNbKZo E3tT9xP+0c8eMuCD7KGQzPa5yTc4AL57mztIfoExgLtNx7smjOooviiG1sf9cpSC7nZB 2zOA== X-Gm-Message-State: AO0yUKX/uG9y4PMZWSDOKp4j8ET6eVb32HevshRdRY7WsUSnL1XjXyWI Bgw5AKVsWrjAIKfokG0XUFehAKa6Fvo3XY3gcA4td3J7Uzey9jRqC57N6LyqHRdjocBg/iSZjys sCNp/dOwZ1+jCD7mUoE8q7NN/2FrngLN3dNcWellzssq5wCESadv6h+++eazdzCdTXQKywBR0 X-Received: by 2002:a5d:5088:0:b0:2c5:4c7c:6aad with SMTP id a8-20020a5d5088000000b002c54c7c6aadmr6289449wrt.8.1676255370139; Sun, 12 Feb 2023 18:29:30 -0800 (PST) X-Google-Smtp-Source: AK7set8/GQc1nte9GQy9mwEksu9qfWqfwiFlIzARDdce28uDL0iyRZPoyWc9DPV4HT3Wb6MpMnVIhw== X-Received: by 2002:a5d:5088:0:b0:2c5:4c7c:6aad with SMTP id a8-20020a5d5088000000b002c54c7c6aadmr6289433wrt.8.1676255369924; Sun, 12 Feb 2023 18:29:29 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 10/22] migration: Make ram_save_target_page() a pointer Date: Mon, 13 Feb 2023 03:28:59 +0100 Message-Id: <20230213022911.68490-11-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255497231100019 Content-Type: text/plain; charset="utf-8" From: Juan Quintela We are going to create a new function for multifd latest in the series. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 6abfe075f2..0890816a30 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -452,6 +452,13 @@ void dirty_sync_missed_zero_copy(void) ram_counters.dirty_sync_missed_zero_copy++; } =20 +struct MigrationOps { + int (*ram_save_target_page)(RAMState *rs, PageSearchStatus *pss); +}; +typedef struct MigrationOps MigrationOps; + +MigrationOps *migration_ops; + CompressionStats compression_counters; =20 struct CompressParam { @@ -2295,14 +2302,14 @@ static bool save_compress_page(RAMState *rs, PageSe= archStatus *pss, } =20 /** - * ram_save_target_page: save one target page + * ram_save_target_page_legacy: save one target page * * Returns the number of pages written * * @rs: current RAM state * @pss: data about the page we want to send */ -static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) +static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss) { RAMBlock *block =3D pss->block; ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; @@ -2428,7 +2435,7 @@ static int ram_save_host_page_urgent(PageSearchStatus= *pss) =20 if (page_dirty) { /* Be strict to return code; it must be 1, or what else? */ - if (ram_save_target_page(rs, pss) !=3D 1) { + if (migration_ops->ram_save_target_page(rs, pss) !=3D 1) { error_report_once("%s: ram_save_target_page failed", __fun= c__); ret =3D -1; goto out; @@ -2497,7 +2504,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) if (preempt_active) { qemu_mutex_unlock(&rs->bitmap_mutex); } - tmppages =3D ram_save_target_page(rs, pss); + tmppages =3D migration_ops->ram_save_target_page(rs, pss); if (tmppages >=3D 0) { pages +=3D tmppages; /* @@ -2697,6 +2704,8 @@ static void ram_save_cleanup(void *opaque) xbzrle_cleanup(); compress_threads_save_cleanup(); ram_state_cleanup(rsp); + g_free(migration_ops); + migration_ops =3D NULL; } =20 static void ram_state_reset(RAMState *rs) @@ -3252,6 +3261,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 + migration_ops =3D g_malloc0(sizeof(MigrationOps)); + migration_ops->ram_save_target_page =3D ram_save_target_page_legacy; ret =3D multifd_send_sync_main(f); if (ret < 0) { return ret; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255530; cv=none; d=zohomail.com; s=zohoarc; b=TFzFSaVtlWxpMf1pU1ogV0nqUxJsvNU9bVHUBZG5m3sDK44VmAw/ySH1qhyo/0qxwrTLUqGJ3pMcdKqXoAdXpC7xkwiaj3kxe+uaY7+DS43UkhAD8MYak4AYF6lMKpEymCOfstRYDyWr3MW4S4G09qP8wcCWDtWlbreuEg2hTTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255530; h=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=qOi00Pqh/ujyWTtG6wmGTly8NpXv3aJEdCMEVs3nCBo=; b=Y11ftg2KLCsTT3lBsICltUBd67E2a/AWPd3eYDicToB2wOXmrXcrhp8+pTC5rs5vkNNHvcWSK1smzgC7e0uvJ/bKj6Y9Df9EO+XrL92mtp4SJf25gm8znao4kiAqUrasfRyBNQM5O1djrBFTPJZQI5gE0U0huzX7P2kF191QAzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255530114716.8566371902904; Sun, 12 Feb 2023 18:32:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROb5-0001Z6-Kw; Sun, 12 Feb 2023 21:29:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb3-0001YN-BR for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb1-00034Z-MO for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:36 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-554-z7X9KB-cM6CmMpdtblyUow-1; Sun, 12 Feb 2023 21:29:33 -0500 Received: by mail-wm1-f71.google.com with SMTP id o8-20020a05600c510800b003dfdf09ffc2so5423070wms.5 for ; Sun, 12 Feb 2023 18:29:33 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id z17-20020a5d6551000000b002c54c8e70b1sm6275033wrv.9.2023.02.12.18.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qOi00Pqh/ujyWTtG6wmGTly8NpXv3aJEdCMEVs3nCBo=; b=Aga7YYeNM8vo8byEXN9g0n8q9cCV6C8NxmB7xpkxU2RHYfI6FFfsa2wryDTOyD0zp2JXnU XlMyZrbExHD9iVVPJ7/hChqlXCn8EFKSnKeGf72ae+jiEn+ZJ1QpRR1Zrtz0KynAdMzjX+ u7CpZpUaR1Il+ff+bn35VONYDbiAIm0= X-MC-Unique: z7X9KB-cM6CmMpdtblyUow-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qOi00Pqh/ujyWTtG6wmGTly8NpXv3aJEdCMEVs3nCBo=; b=hkl5siw5P3Kqi9EH1NNiHfDp/13zqmPStwAPbgh6iv+NKcF2KdhmJOBfYjB9dMUHEF pWiE8iwUUKVKlArmDHEDyBVyfq6zp5LPz32Nd9FkdAiypZ5KupadWtZjjEswm0Q2eJFP 5ybPe6iAWLVi6NO7eMy5QO//v1BuFBJokfp1VIoJNPzLi5f9yGToykAEByCwrq6OHKLk DoLeZrOrRftEaS/AvNRu+b3lg0ePFQbQAKDmEIU03ZS/rwDf+wHsblpOGhO5rLrkvrUH cA9g4mZfD6Lp+K6FnkbOvL5C3+/km8reyfggBroIrxgjBKDYOXnQRBeEaQOXVRAIiVBE v5zA== X-Gm-Message-State: AO0yUKX27GpooRKxtTg6SinuZFQKLsIhe4eyZda4Y4wst6tLzRebnAib 49Ug+dMQa9rt0frqhKZZmRmSUH4/L4bIms2/wkGJznT/8OCpG7Wp5wdlD2Qz/4aDW6eesYEXPpD 0eEBbGMML2+9SGZaliWn0aUefD7RuSg4s74wVFq/NZTGMDJBS03VXvMFsufpbHPNXJXeHCTXq X-Received: by 2002:adf:eb88:0:b0:2c5:4bd4:b3a8 with SMTP id t8-20020adfeb88000000b002c54bd4b3a8mr7133141wrn.4.1676255372026; Sun, 12 Feb 2023 18:29:32 -0800 (PST) X-Google-Smtp-Source: AK7set93r9z3DMHPpOkkw0GymiD+Q9tAwTIKRBZwn0QmaSQgLXHYJg2jzv/gVIO1TxUcoI75MMe6/g== X-Received: by 2002:adf:eb88:0:b0:2c5:4bd4:b3a8 with SMTP id t8-20020adfeb88000000b002c54bd4b3a8mr7133127wrn.4.1676255371764; Sun, 12 Feb 2023 18:29:31 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 11/22] migration: I messed state_pending_exact/estimate Date: Mon, 13 Feb 2023 03:29:00 +0100 Message-Id: <20230213022911.68490-12-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255531429100002 Content-Type: text/plain; charset="utf-8" From: Juan Quintela I called the helper function from the wrong top level function. This code was introduced in: commit c8df4a7aeffcb46020f610526eea621fa5b0cd47 Author: Juan Quintela Date: Mon Oct 3 02:00:03 2022 +0200 migration: Split save_live_pending() into state_pending_* We split the function into to: - state_pending_estimate: We estimate the remaining state size without stopping the machine. - state pending_exact: We calculate the exact amount of remaining state. Thanks to Avihai Horon for finding it. Fixes:c8df4a7aeffcb46020f610526eea621fa5b0cd47 When we introduced that patch, we enden calling state_pending_estimate() helper from qemu_savevm_statepending_exact() and state_pending_exact() helper from qemu_savevm_statepending_estimate() This patch fixes it. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/savevm.c | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index e9cf4999ad..ce181e21e1 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1551,31 +1551,6 @@ void qemu_savevm_state_pending_estimate(uint64_t *re= s_precopy_only, *res_compatible =3D 0; *res_postcopy_only =3D 0; =20 - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { - if (!se->ops || !se->ops->state_pending_exact) { - continue; - } - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } - } - se->ops->state_pending_exact(se->opaque, - res_precopy_only, res_compatible, - res_postcopy_only); - } -} - -void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) -{ - SaveStateEntry *se; - - *res_precopy_only =3D 0; - *res_compatible =3D 0; - *res_postcopy_only =3D 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (!se->ops || !se->ops->state_pending_estimate) { continue; @@ -1591,6 +1566,31 @@ void qemu_savevm_state_pending_exact(uint64_t *res_p= recopy_only, } } =20 +void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) +{ + SaveStateEntry *se; + + *res_precopy_only =3D 0; + *res_compatible =3D 0; + *res_postcopy_only =3D 0; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (!se->ops || !se->ops->state_pending_exact) { + continue; + } + if (se->ops->is_active) { + if (!se->ops->is_active(se->opaque)) { + continue; + } + } + se->ops->state_pending_exact(se->opaque, + res_precopy_only, res_compatible, + res_postcopy_only); + } +} + void qemu_savevm_state_cleanup(void) { SaveStateEntry *se; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255493; cv=none; d=zohomail.com; s=zohoarc; b=kNaRK9ZgRqZk++775Ix6yn2Q/GW4vqzxZz2jQlu6BouwpcQEOwpXXbioqdfOmdUwhhuAO+GO8r71WRmP/N/Sz+BFv7ZWCLb8cmXSBsF/E+RXnzuXI5ZyaLKCkH55LQzuRfdvqLDpivJSPJBpnQWvc915BM+XNGypCzq9PRYB1hU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255493; h=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=9ImAledL35n3b32So8PCwQBc3/Z1i939uMWYRhKZc5U=; b=etb+G+39hxPZY+UR/FzLQHDohfJfQcLjwBmbuSmOFyjdaV9g19kKNDB5rq4yK/EmlE+k3CBSzUXvmldXGze84wSBxuE3ajLoxI1nw7ftMUdj8ZHRdYa1eryYSd1c0cukf7DnfPDvwBxcLodEjXyorOb7Xky2APS+BvqE1t0634Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255493474454.2677230445711; Sun, 12 Feb 2023 18:31:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pROb6-0001ZH-IU; Sun, 12 Feb 2023 21:29:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb5-0001Ys-Ck for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb3-00034r-B8 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:39 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-562-W3ngZc5TPUaLCaVyVGbBiQ-1; Sun, 12 Feb 2023 21:29:35 -0500 Received: by mail-wm1-f71.google.com with SMTP id bd21-20020a05600c1f1500b003dc5cb10dcfso5414558wmb.9 for ; Sun, 12 Feb 2023 18:29:35 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c220400b003dfe8c4c497sm15677380wml.39.2023.02.12.18.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ImAledL35n3b32So8PCwQBc3/Z1i939uMWYRhKZc5U=; b=fwqyOF63ar3ZT6KVP+MyipZUUC6X67GtejjdhMOu52dyNSY5KH+bK/6gAXtduAITSz4OSf WTecYnqKRsLhsNSxcIc5iRmLL0SunTy7yIoHMiIYmCUaX3568+mo345dHXma5cvfqLwcfD SwwwDQTgFuOBUmc/2nPgpv9RBwvZ4AY= X-MC-Unique: W3ngZc5TPUaLCaVyVGbBiQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9ImAledL35n3b32So8PCwQBc3/Z1i939uMWYRhKZc5U=; b=ydZTyG14uMNHTo6SI7e6SJO3ScDvo4drwdS3NywWQXahOBDMsCmRuuEcR3E2CqIi9I 2f1132WuFFmvSSh3yjQJoXM7S5o/I8K7n1S5ErRgyh5rYn1hpb7NoZnV8u5o6Y8/yi0A F8ylioXhOLDU1GXc1waC2SRgd7Yw7wWFMF5Egta8KKjERLsaX+cZOzXZ4SpJGVN1Dx9X gD59zlUSZ4TUq6sBgB2/hQQe0I//gACYH/BWwP8ZGOxM+ixxMCJHbpgzd4oUWdyCOE2v vT/Bu9+brdzJjdxhhnZ46ggQYcKJm72va30Y+tZrkCCJiEglRxDf/UslylXjYa5pFT1R x9/g== X-Gm-Message-State: AO0yUKXYusje1LfeeQ+uCkptkFpJP9vb+KDuVoN3PM1FEzJSJb4V1Cae nWqIDDns3PCO0eThmxB0mHWkbupA8JYpWSSOAq97ZQ8qYqX8DlW2UTyuJBnjZHo6M1WSalge5a3 p5ccC6+a5NF4gbajKzNDAAm6ZIt9K7UJE+J+chJ9qZziZ11jN5k+JAk2KnD6u9hUlGMWDa222 X-Received: by 2002:a05:600c:180f:b0:3dc:50c2:cc1 with SMTP id n15-20020a05600c180f00b003dc50c20cc1mr17322912wmp.23.1676255373749; Sun, 12 Feb 2023 18:29:33 -0800 (PST) X-Google-Smtp-Source: AK7set+0BGW5iw5jbfgot5KqDh7ALMHXa0fJzk0JRh3cdvx5BFLx/ad7iR/pu5G4Iby0RR0V+l5/bQ== X-Received: by 2002:a05:600c:180f:b0:3dc:50c2:cc1 with SMTP id n15-20020a05600c180f00b003dc50c20cc1mr17322892wmp.23.1676255373462; Sun, 12 Feb 2023 18:29:33 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , ling xu , Zhou Zhao , Jun Jin Subject: [PULL 12/22] AVX512 support for xbzrle_encode_buffer Date: Mon, 13 Feb 2023 03:29:01 +0100 Message-Id: <20230213022911.68490-13-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255495276100011 Content-Type: text/plain; charset="utf-8" From: ling xu This commit is the same with [PATCH v6 1/2], and provides avx512 support fo= r xbzrle_encode_buffer function to accelerate xbzrle encoding speed. Runtime check of avx512 support and benchmark for this feature are added. Compared with C version of xbzrle_encode_buffer function, avx512 version can achieve 50%-70% performance improvement on benchmarking. In addition, if dirty data is randomly located in 4K page, the avx512 version can achieve almost 140% performance gain. Signed-off-by: ling xu Co-authored-by: Zhou Zhao Co-authored-by: Jun Jin Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- meson.build | 17 +++++ migration/xbzrle.h | 4 ++ migration/ram.c | 34 +++++++++- migration/xbzrle.c | 124 ++++++++++++++++++++++++++++++++++ meson_options.txt | 2 + scripts/meson-buildoptions.sh | 3 + 6 files changed, 181 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 4ba3bf3431..c626ccfa82 100644 --- a/meson.build +++ b/meson.build @@ -2351,6 +2351,22 @@ config_host_data.set('CONFIG_AVX512F_OPT', get_optio= n('avx512f') \ int main(int argc, char *argv[]) { return bar(argv[argc - 1]); } '''), error_message: 'AVX512F not available').allowed()) =20 +config_host_data.set('CONFIG_AVX512BW_OPT', get_option('avx512bw') \ + .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot ena= ble AVX512BW') \ + .require(cc.links(''' + #pragma GCC push_options + #pragma GCC target("avx512bw") + #include + #include + static int bar(void *a) { + + __m512i *x =3D a; + __m512i res=3D _mm512_abs_epi8(*x); + return res[1]; + } + int main(int argc, char *argv[]) { return bar(argv[0]); } + '''), error_message: 'AVX512BW not available').allowed()) + have_pvrdma =3D get_option('pvrdma') \ .require(rdma.found(), error_message: 'PVRDMA requires OpenFabrics libra= ries') \ .require(cc.compiles(gnu_source_prefix + ''' @@ -3783,6 +3799,7 @@ summary_info +=3D {'debug stack usage': get_option('d= ebug_stack_usage')} summary_info +=3D {'mutex debugging': get_option('debug_mutex')} summary_info +=3D {'memory allocator': get_option('malloc')} summary_info +=3D {'avx2 optimization': config_host_data.get('CONFIG_AVX2_= OPT')} +summary_info +=3D {'avx512bw optimization': config_host_data.get('CONFIG_A= VX512BW_OPT')} summary_info +=3D {'avx512f optimization': config_host_data.get('CONFIG_AV= X512F_OPT')} summary_info +=3D {'gprof enabled': get_option('gprof')} summary_info +=3D {'gcov': get_option('b_coverage')} diff --git a/migration/xbzrle.h b/migration/xbzrle.h index a0db507b9c..6feb49160a 100644 --- a/migration/xbzrle.h +++ b/migration/xbzrle.h @@ -18,4 +18,8 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_b= uf, int slen, uint8_t *dst, int dlen); =20 int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen); +#if defined(CONFIG_AVX512BW_OPT) +int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int sl= en, + uint8_t *dst, int dlen); +#endif #endif diff --git a/migration/ram.c b/migration/ram.c index 0890816a30..18ac68b181 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -83,6 +83,34 @@ /* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 =20 +int (*xbzrle_encode_buffer_func)(uint8_t *, uint8_t *, int, + uint8_t *, int) =3D xbzrle_encode_buffer; +#if defined(CONFIG_AVX512BW_OPT) +#include "qemu/cpuid.h" +static void __attribute__((constructor)) init_cpu_flag(void) +{ + unsigned max =3D __get_cpuid_max(0, NULL); + int a, b, c, d; + if (max >=3D 1) { + __cpuid(1, a, b, c, d); + /* We must check that AVX is not just available, but usable. */ + if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=3D 7) { + int bv; + __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); + __cpuid_count(7, 0, a, b, c, d); + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512BW)) { + xbzrle_encode_buffer_func =3D xbzrle_encode_buffer_avx512; + } + } + } +} +#endif + XBZRLECacheStats xbzrle_counters; =20 /* used by the search for pages to send */ @@ -806,9 +834,9 @@ static int save_xbzrle_page(RAMState *rs, PageSearchSta= tus *pss, memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE); =20 /* XBZRLE encoding (if there is no overflow) */ - encoded_len =3D xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_= buf, - TARGET_PAGE_SIZE, XBZRLE.encoded_bu= f, - TARGET_PAGE_SIZE); + encoded_len =3D xbzrle_encode_buffer_func(prev_cached_page, XBZRLE.cur= rent_buf, + TARGET_PAGE_SIZE, XBZRLE.encod= ed_buf, + TARGET_PAGE_SIZE); =20 /* * Update the cache contents, so that it corresponds to the data diff --git a/migration/xbzrle.c b/migration/xbzrle.c index 1ba482ded9..05366e86c0 100644 --- a/migration/xbzrle.c +++ b/migration/xbzrle.c @@ -174,3 +174,127 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint= 8_t *dst, int dlen) =20 return d; } + +#if defined(CONFIG_AVX512BW_OPT) +#pragma GCC push_options +#pragma GCC target("avx512bw") +#include +int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int sl= en, + uint8_t *dst, int dlen) +{ + uint32_t zrun_len =3D 0, nzrun_len =3D 0; + int d =3D 0, i =3D 0, num =3D 0; + uint8_t *nzrun_start =3D NULL; + /* add 1 to include residual part in main loop */ + uint32_t count512s =3D (slen >> 6) + 1; + /* countResidual is tail of data, i.e., countResidual =3D slen % 64 */ + uint32_t count_residual =3D slen & 0b111111; + bool never_same =3D true; + uint64_t mask_residual =3D 1; + mask_residual <<=3D count_residual; + mask_residual -=3D 1; + __m512i r =3D _mm512_set1_epi32(0); + + while (count512s) { + if (d + 2 > dlen) { + return -1; + } + + int bytes_to_check =3D 64; + uint64_t mask =3D 0xffffffffffffffff; + if (count512s =3D=3D 1) { + bytes_to_check =3D count_residual; + mask =3D mask_residual; + } + __m512i old_data =3D _mm512_mask_loadu_epi8(r, + mask, old_buf + i); + __m512i new_data =3D _mm512_mask_loadu_epi8(r, + mask, new_buf + i); + uint64_t comp =3D _mm512_cmpeq_epi8_mask(old_data, new_data); + count512s--; + + bool is_same =3D (comp & 0x1); + while (bytes_to_check) { + if (is_same) { + if (nzrun_len) { + d +=3D uleb128_encode_small(dst + d, nzrun_len); + if (d + nzrun_len > dlen) { + return -1; + } + nzrun_start =3D new_buf + i - nzrun_len; + memcpy(dst + d, nzrun_start, nzrun_len); + d +=3D nzrun_len; + nzrun_len =3D 0; + } + /* 64 data at a time for speed */ + if (count512s && (comp =3D=3D 0xffffffffffffffff)) { + i +=3D 64; + zrun_len +=3D 64; + break; + } + never_same =3D false; + num =3D __builtin_ctzll(~comp); + num =3D (num < bytes_to_check) ? num : bytes_to_check; + zrun_len +=3D num; + bytes_to_check -=3D num; + comp >>=3D num; + i +=3D num; + if (bytes_to_check) { + /* still has different data after same data */ + d +=3D uleb128_encode_small(dst + d, zrun_len); + zrun_len =3D 0; + } else { + break; + } + } + if (never_same || zrun_len) { + /* + * never_same only acts if + * data begins with diff in first count512s + */ + d +=3D uleb128_encode_small(dst + d, zrun_len); + zrun_len =3D 0; + never_same =3D false; + } + /* has diff, 64 data at a time for speed */ + if ((bytes_to_check =3D=3D 64) && (comp =3D=3D 0x0)) { + i +=3D 64; + nzrun_len +=3D 64; + break; + } + num =3D __builtin_ctzll(comp); + num =3D (num < bytes_to_check) ? num : bytes_to_check; + nzrun_len +=3D num; + bytes_to_check -=3D num; + comp >>=3D num; + i +=3D num; + if (bytes_to_check) { + /* mask like 111000 */ + d +=3D uleb128_encode_small(dst + d, nzrun_len); + /* overflow */ + if (d + nzrun_len > dlen) { + return -1; + } + nzrun_start =3D new_buf + i - nzrun_len; + memcpy(dst + d, nzrun_start, nzrun_len); + d +=3D nzrun_len; + nzrun_len =3D 0; + is_same =3D true; + } + } + } + + if (nzrun_len !=3D 0) { + d +=3D uleb128_encode_small(dst + d, nzrun_len); + /* overflow */ + if (d + nzrun_len > dlen) { + return -1; + } + nzrun_start =3D new_buf + i - nzrun_len; + memcpy(dst + d, nzrun_start, nzrun_len); + d +=3D nzrun_len; + } + return d; +} +#pragma GCC pop_options +#endif diff --git a/meson_options.txt b/meson_options.txt index 559a571b6b..e5f199119e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -104,6 +104,8 @@ option('avx2', type: 'feature', value: 'auto', description: 'AVX2 optimizations') option('avx512f', type: 'feature', value: 'disabled', description: 'AVX512F optimizations') +option('avx512bw', type: 'feature', value: 'auto', + description: 'AVX512BW optimizations') option('keyring', type: 'feature', value: 'auto', description: 'Linux keyring support') =20 diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 0f71e92dcb..c2982ea087 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -70,6 +70,7 @@ meson_options_help() { printf "%s\n" ' attr attr/xattr support' printf "%s\n" ' auth-pam PAM access control' printf "%s\n" ' avx2 AVX2 optimizations' + printf "%s\n" ' avx512bw AVX512BW optimizations' printf "%s\n" ' avx512f AVX512F optimizations' printf "%s\n" ' blkio libblkio block device driver' printf "%s\n" ' bochs bochs image format support' @@ -198,6 +199,8 @@ _meson_option_parse() { --disable-auth-pam) printf "%s" -Dauth_pam=3Ddisabled ;; --enable-avx2) printf "%s" -Davx2=3Denabled ;; --disable-avx2) printf "%s" -Davx2=3Ddisabled ;; + --enable-avx512bw) printf "%s" -Davx512bw=3Denabled ;; + --disable-avx512bw) printf "%s" -Davx512bw=3Ddisabled ;; --enable-avx512f) printf "%s" -Davx512f=3Denabled ;; --disable-avx512f) printf "%s" -Davx512f=3Ddisabled ;; --enable-gcov) printf "%s" -Db_coverage=3Dtrue ;; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255476; cv=none; d=zohomail.com; s=zohoarc; b=U5rejGq02AJlbaE0bdl4weoJNDHt00XqR8Jlj5V9FFkoWsUvlq1E2js7VF13L8KivNQ4ae3oxuoHNOygeQ8SNi0CmO6atWnNZxJvnPwL725W/o4UZ53XjIc08elotAyxVPLKfeUzNiUQjbZkInpr7ViKnxKjJHa7QBVgCeqgeMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255476; h=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=hhzdc6EJT0N0Bv1boe7/qcEnx6KstP3OPe2f+kkOVWo=; b=TEB0x6nN6N0gUhS//h8d6zs8AhZnKq9TQLvHY8x+I0y/vqy8qXaSwFfZI8Bg6qtwaVKrQ+nm21U/S28mpPHMyDTPxEgAyUQg21THDeiIh1J/DBw2XooWOq1IO76gP0JNyp6A4QI8fiMogl/AdGkuCf+tIKk1ZgmcuRNn0/VpfiM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255476452796.9516700787303; Sun, 12 Feb 2023 18:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObC-0001aX-56; Sun, 12 Feb 2023 21:29:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb7-0001Zt-Pw for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb5-000356-D9 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:41 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-55-MsX3DMGaOe69Hub0KkEi1w-1; Sun, 12 Feb 2023 21:29:37 -0500 Received: by mail-wm1-f69.google.com with SMTP id bg9-20020a05600c3c8900b003e1e7d3db06so1721508wmb.5 for ; Sun, 12 Feb 2023 18:29:37 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id j37-20020a05600c1c2500b003daf6e3bc2fsm22711207wms.1.2023.02.12.18.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hhzdc6EJT0N0Bv1boe7/qcEnx6KstP3OPe2f+kkOVWo=; b=IT4hhlhcZC9CTxrqDBbMBJ+JsEMKzmEGNNp4uUWF4s6yyKu0ZS//KtcTGFOznNsJuTQ0ZA 24g1ekyHAqD/1NxWU+vKeywSPM4mImPFE3XDrIGec7+c2JIk0ykAJLOdmVXS21erTNwk6y mONhopGRK6rYGvdKxp5uwaU54xFTQyM= X-MC-Unique: MsX3DMGaOe69Hub0KkEi1w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hhzdc6EJT0N0Bv1boe7/qcEnx6KstP3OPe2f+kkOVWo=; b=17illUOGg28k+vziD9PG2YQguez+rPRLkKwst9aCLBJZgHF0vy1RGh2KFr2tWMl/9h NXjZBZ93AqP5Tb5bawAvYmefYAuSw60PFNeT8ig5eD+3YlWRSSKbqt0KIZYSfAMlvK4w kZc0SrJb0lcFGeD3KdlonjBHmbLQkEtmjUGaA58ZseLtH+bZ9k0ExNBynQlmRTCC5S8/ OQ0OMpF6hMya9g/7sBkvsDbroqAkc0iGDJww6/7W9YENTT1rbnxxVKXl8Kes8q8oxhTz txv1ZdEgzTvcAWEYQtfXVA26HWERlPw3FnXU6nLsPinpWVrpgrQCYccy6DSADzV0cIHP mDOw== X-Gm-Message-State: AO0yUKW63aepoSGDjf9AtgLbSbPY7uYPPmjw2osKpLjq5tbiUjk3e5JX ziSK55o3veybDjLUFuW4/vYY+tOtcLvvXPVFuEq1ZN03loMRJaO5eyR6QjxtqcH8yg3MsfZ5AS6 W1tM8JzjNHHXlOrr8LOIhvnNczadC4CFQdDCSCX5mBGQffPbSxGxvC/QNwCPJrOlwqB/ho/Id X-Received: by 2002:a05:600c:807:b0:3dc:eaef:c1bb with SMTP id k7-20020a05600c080700b003dceaefc1bbmr17747252wmp.35.1676255375570; Sun, 12 Feb 2023 18:29:35 -0800 (PST) X-Google-Smtp-Source: AK7set+HRn39XPbz+We7XDXZ8pC6Lva0i+CXOixUrg9uDH6YJtB8bYiRhhCXYcds8gfBqJt4XY0dIA== X-Received: by 2002:a05:600c:807:b0:3dc:eaef:c1bb with SMTP id k7-20020a05600c080700b003dceaefc1bbmr17747234wmp.35.1676255375211; Sun, 12 Feb 2023 18:29:35 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , ling xu , Zhou Zhao , Jun Jin Subject: [PULL 13/22] Update bench-code for addressing CI problem Date: Mon, 13 Feb 2023 03:29:02 +0100 Message-Id: <20230213022911.68490-14-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255477173100002 Content-Type: text/plain; charset="utf-8" From: ling xu Unit test code is in test-xbzrle.c, and benchmark code is in xbzrle-bench.c for performance benchmarking. we have modified xbzrle-bench.c to address CI problem. Signed-off-by: ling xu Co-authored-by: Zhou Zhao Co-authored-by: Jun Jin Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- tests/bench/xbzrle-bench.c | 469 +++++++++++++++++++++++++++++++++++++ tests/unit/test-xbzrle.c | 39 ++- tests/bench/meson.build | 6 + 3 files changed, 509 insertions(+), 5 deletions(-) create mode 100644 tests/bench/xbzrle-bench.c diff --git a/tests/bench/xbzrle-bench.c b/tests/bench/xbzrle-bench.c new file mode 100644 index 0000000000..8848a3a32d --- /dev/null +++ b/tests/bench/xbzrle-bench.c @@ -0,0 +1,469 @@ +/* + * Xor Based Zero Run Length Encoding unit tests. + * + * Copyright 2013 Red Hat, Inc. and/or its affiliates + * + * Authors: + * Orit Wasserman + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "../migration/xbzrle.h" + +#if defined(CONFIG_AVX512BW_OPT) +#define XBZRLE_PAGE_SIZE 4096 +static bool is_cpu_support_avx512bw; +#include "qemu/cpuid.h" +static void __attribute__((constructor)) init_cpu_flag(void) +{ + unsigned max =3D __get_cpuid_max(0, NULL); + int a, b, c, d; + is_cpu_support_avx512bw =3D false; + if (max >=3D 1) { + __cpuid(1, a, b, c, d); + /* We must check that AVX is not just available, but usable. */ + if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=3D 7) { + int bv; + __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); + __cpuid_count(7, 0, a, b, c, d); + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512BW)) { + is_cpu_support_avx512bw =3D true; + } + } + } + return ; +} + +struct ResTime { + float t_raw; + float t_512; +}; + + +/* Function prototypes +int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int sl= en, + uint8_t *dst, int dlen); +*/ +static void encode_decode_zero(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0; + int dlen =3D 0, dlen512 =3D 0; + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006); + + for (i =3D diff_len; i > 0; i--) { + buffer[1000 + i] =3D i; + buffer512[1000 + i] =3D i; + } + + buffer[1000 + diff_len + 3] =3D 103; + buffer[1000 + diff_len + 5] =3D 105; + + buffer512[1000 + diff_len + 3] =3D 103; + buffer512[1000 + diff_len + 5] =3D 105; + + /* encode zero page */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(buffer, buffer, XBZRLE_PAGE_SIZE, compre= ssed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(dlen =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(buffer512, buffer512, XBZRLE_P= AGE_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(dlen512 =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(buffer512); + g_free(compressed512); + +} + +static void test_encode_decode_zero_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_zero(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Zero test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_unchanged(struct ResTime *res) +{ + uint8_t *compressed =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0; + int dlen =3D 0, dlen512 =3D 0; + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006); + + for (i =3D diff_len; i > 0; i--) { + test[1000 + i] =3D i + 4; + test512[1000 + i] =3D i + 4; + } + + test[1000 + diff_len + 3] =3D 107; + test[1000 + diff_len + 5] =3D 109; + + test512[1000 + diff_len + 3] =3D 107; + test512[1000 + diff_len + 5] =3D 109; + + /* test unchanged buffer */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(test, test, XBZRLE_PAGE_SIZE, compressed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(dlen =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(test512, test512, XBZRLE_PAGE_= SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(dlen512 =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(test); + g_free(compressed); + g_free(test512); + g_free(compressed512); + +} + +static void test_encode_decode_unchanged_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_unchanged(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Unchanged test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_1_byte(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc(XBZRLE_PAGE_SIZE); + int dlen =3D 0, rc =3D 0, dlen512 =3D 0, rc512 =3D 0; + uint8_t buf[2]; + uint8_t buf512[2]; + + test[XBZRLE_PAGE_SIZE - 1] =3D 1; + test512[XBZRLE_PAGE_SIZE - 1] =3D 1; + + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compress= ed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(dlen =3D=3D (uleb128_encode_small(&buf[0], 4095) + 2)); + + rc =3D xbzrle_decode_buffer(compressed, dlen, buffer, XBZRLE_PAGE_SIZE= ); + g_assert(rc =3D=3D XBZRLE_PAGE_SIZE); + g_assert(memcmp(test, buffer, XBZRLE_PAGE_SIZE) =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(buffer512, test512, XBZRLE_PAG= E_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(dlen512 =3D=3D (uleb128_encode_small(&buf512[0], 4095) + 2)); + + rc512 =3D xbzrle_decode_buffer(compressed512, dlen512, buffer512, + XBZRLE_PAGE_SIZE); + g_assert(rc512 =3D=3D XBZRLE_PAGE_SIZE); + g_assert(memcmp(test512, buffer512, XBZRLE_PAGE_SIZE) =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_1_byte_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_1_byte(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("1 byte test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_overflow(struct ResTime *res) +{ + uint8_t *compressed =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0, rc =3D 0, rc512 =3D 0; + + for (i =3D 0; i < XBZRLE_PAGE_SIZE / 2 - 1; i++) { + test[i * 2] =3D 1; + test512[i * 2] =3D 1; + } + + /* encode overflow */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + rc =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compressed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(rc =3D=3D -1); + + t_start512 =3D clock(); + rc512 =3D xbzrle_encode_buffer_avx512(buffer512, test512, XBZRLE_PAGE_= SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(rc512 =3D=3D -1); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_overflow_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_overflow(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Overflow test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_range_avx512(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0, rc =3D 0, rc512 =3D 0; + int dlen =3D 0, dlen512 =3D 0; + + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006); + + for (i =3D diff_len; i > 0; i--) { + buffer[1000 + i] =3D i; + test[1000 + i] =3D i + 4; + buffer512[1000 + i] =3D i; + test512[1000 + i] =3D i + 4; + } + + buffer[1000 + diff_len + 3] =3D 103; + test[1000 + diff_len + 3] =3D 107; + + buffer[1000 + diff_len + 5] =3D 105; + test[1000 + diff_len + 5] =3D 109; + + buffer512[1000 + diff_len + 3] =3D 103; + test512[1000 + diff_len + 3] =3D 107; + + buffer512[1000 + diff_len + 5] =3D 105; + test512[1000 + diff_len + 5] =3D 109; + + /* test encode/decode */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compress= ed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + rc =3D xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE); + g_assert(rc < XBZRLE_PAGE_SIZE); + g_assert(memcmp(test, buffer, XBZRLE_PAGE_SIZE) =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(test512, buffer512, XBZRLE_PAG= E_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + rc512 =3D xbzrle_decode_buffer(compressed512, dlen512, test512, XBZRLE= _PAGE_SIZE); + g_assert(rc512 < XBZRLE_PAGE_SIZE); + g_assert(memcmp(test512, buffer512, XBZRLE_PAGE_SIZE) =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_range_avx512(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Encode decode test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_random(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0, rc =3D 0, rc512 =3D 0; + int dlen =3D 0, dlen512 =3D 0; + + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1); + /* store the index of diff */ + int dirty_index[diff_len]; + for (int j =3D 0; j < diff_len; j++) { + dirty_index[j] =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1); + } + for (i =3D diff_len - 1; i >=3D 0; i--) { + buffer[dirty_index[i]] =3D i; + test[dirty_index[i]] =3D i + 4; + buffer512[dirty_index[i]] =3D i; + test512[dirty_index[i]] =3D i + 4; + } + + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compress= ed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + rc =3D xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE); + g_assert(rc < XBZRLE_PAGE_SIZE); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(test512, buffer512, XBZRLE_PAG= E_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + rc512 =3D xbzrle_decode_buffer(compressed512, dlen512, test512, XBZRLE= _PAGE_SIZE); + g_assert(rc512 < XBZRLE_PAGE_SIZE); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_random_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_random(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Random test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} +#endif + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_rand_int(); + #if defined(CONFIG_AVX512BW_OPT) + if (likely(is_cpu_support_avx512bw)) { + g_test_add_func("/xbzrle/encode_decode_zero", test_encode_decode_z= ero_avx512); + g_test_add_func("/xbzrle/encode_decode_unchanged", + test_encode_decode_unchanged_avx512); + g_test_add_func("/xbzrle/encode_decode_1_byte", test_encode_decode= _1_byte_avx512); + g_test_add_func("/xbzrle/encode_decode_overflow", + test_encode_decode_overflow_avx512); + g_test_add_func("/xbzrle/encode_decode", test_encode_decode_avx512= ); + g_test_add_func("/xbzrle/encode_decode_random", test_encode_decode= _random_avx512); + } + #endif + return g_test_run(); +} diff --git a/tests/unit/test-xbzrle.c b/tests/unit/test-xbzrle.c index ef951b6e54..547046d093 100644 --- a/tests/unit/test-xbzrle.c +++ b/tests/unit/test-xbzrle.c @@ -16,6 +16,35 @@ =20 #define XBZRLE_PAGE_SIZE 4096 =20 +int (*xbzrle_encode_buffer_func)(uint8_t *, uint8_t *, int, + uint8_t *, int) =3D xbzrle_encode_buffer; +#if defined(CONFIG_AVX512BW_OPT) +#include "qemu/cpuid.h" +static void __attribute__((constructor)) init_cpu_flag(void) +{ + unsigned max =3D __get_cpuid_max(0, NULL); + int a, b, c, d; + if (max >=3D 1) { + __cpuid(1, a, b, c, d); + /* We must check that AVX is not just available, but usable. */ + if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=3D 7) { + int bv; + __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); + __cpuid_count(7, 0, a, b, c, d); + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512BW)) { + xbzrle_encode_buffer_func =3D xbzrle_encode_buffer_avx512; + } + } + } + return ; +} +#endif + static void test_uleb(void) { uint32_t i, val; @@ -54,7 +83,7 @@ static void test_encode_decode_zero(void) buffer[1000 + diff_len + 5] =3D 105; =20 /* encode zero page */ - dlen =3D xbzrle_encode_buffer(buffer, buffer, XBZRLE_PAGE_SIZE, compre= ssed, + dlen =3D xbzrle_encode_buffer_func(buffer, buffer, XBZRLE_PAGE_SIZE, c= ompressed, XBZRLE_PAGE_SIZE); g_assert(dlen =3D=3D 0); =20 @@ -78,7 +107,7 @@ static void test_encode_decode_unchanged(void) test[1000 + diff_len + 5] =3D 109; =20 /* test unchanged buffer */ - dlen =3D xbzrle_encode_buffer(test, test, XBZRLE_PAGE_SIZE, compressed, + dlen =3D xbzrle_encode_buffer_func(test, test, XBZRLE_PAGE_SIZE, compr= essed, XBZRLE_PAGE_SIZE); g_assert(dlen =3D=3D 0); =20 @@ -96,7 +125,7 @@ static void test_encode_decode_1_byte(void) =20 test[XBZRLE_PAGE_SIZE - 1] =3D 1; =20 - dlen =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compress= ed, + dlen =3D xbzrle_encode_buffer_func(buffer, test, XBZRLE_PAGE_SIZE, com= pressed, XBZRLE_PAGE_SIZE); g_assert(dlen =3D=3D (uleb128_encode_small(&buf[0], 4095) + 2)); =20 @@ -121,7 +150,7 @@ static void test_encode_decode_overflow(void) } =20 /* encode overflow */ - rc =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compressed, + rc =3D xbzrle_encode_buffer_func(buffer, test, XBZRLE_PAGE_SIZE, compr= essed, XBZRLE_PAGE_SIZE); g_assert(rc =3D=3D -1); =20 @@ -152,7 +181,7 @@ static void encode_decode_range(void) test[1000 + diff_len + 5] =3D 109; =20 /* test encode/decode */ - dlen =3D xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compress= ed, + dlen =3D xbzrle_encode_buffer_func(test, buffer, XBZRLE_PAGE_SIZE, com= pressed, XBZRLE_PAGE_SIZE); =20 rc =3D xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE); diff --git a/tests/bench/meson.build b/tests/bench/meson.build index 279a8fcc33..7477a1f401 100644 --- a/tests/bench/meson.build +++ b/tests/bench/meson.build @@ -3,6 +3,12 @@ qht_bench =3D executable('qht-bench', sources: 'qht-bench.c', dependencies: [qemuutil]) =20 +if have_system +xbzrle_bench =3D executable('xbzrle-bench', + sources: 'xbzrle-bench.c', + dependencies: [qemuutil,migration]) +endif + executable('atomic_add-bench', sources: files('atomic_add-bench.c'), dependencies: [qemuutil], --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255504; cv=none; d=zohomail.com; s=zohoarc; b=ONetVPRQIblqpnfBslvb1tZZemKkw/JYsIuCTYk2fwB9Je1eLSv3JLdneTLPwrzPFdEdnSs95X/Aeb0uAj8ovSl6uo5cBPyn258EykaY+7bJhoygAA+ua8R/j9ai/6ZOnDlCsvsTdSX7RoKk/ccSZfUT7bZCB9s8vsFex4hifE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255504; h=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=HIGquDGecZVqlPAzTK4Da5XIicRI3uO45jZdci3i9h8=; b=EuR+UUOdIJaFBfmd/7MZw0gK1Z4sWalLKTqRM2CN7rs/uerDWxKfG7zj9eDLqqL4wEV5OMjrJxWcoVN2pb8+p2YhZCB5t8B6MJHdlnlDFHTy0miFlHzo/9Eoj/MQz/hL1Bz6TnA7+uye7TXKe/4wHECpNvFuDON4NKYWcrtYwLA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255504430467.64670251364976; Sun, 12 Feb 2023 18:31:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObE-0001bW-3B; Sun, 12 Feb 2023 21:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb8-0001aB-Nf for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb6-00035O-Rm for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:42 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-480-2HAJ6fjEPVWe7IaHfbSkBQ-1; Sun, 12 Feb 2023 21:29:38 -0500 Received: by mail-wm1-f70.google.com with SMTP id bi16-20020a05600c3d9000b003dfeeaa8143so5419415wmb.6 for ; Sun, 12 Feb 2023 18:29:38 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id t15-20020a05600c328f00b003dc5b59ed7asm11965633wmp.11.2023.02.12.18.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HIGquDGecZVqlPAzTK4Da5XIicRI3uO45jZdci3i9h8=; b=FeN+Y9moNZzZlIZJkU4kZwPVTQYUFSAP9QrEZuh61/FS7XdF/kLRkMVeD5I9a2NiXydgQv rFDm9/xdJJ+L6zXcFxoCe2z1twV1NjL/q3MVBP8yAWQkDix6VvFJ2QjvPev6zjKgLWQC1D TYxwRSJb4GL2UnMBvPjWHQsAVJ1Z0CI= X-MC-Unique: 2HAJ6fjEPVWe7IaHfbSkBQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HIGquDGecZVqlPAzTK4Da5XIicRI3uO45jZdci3i9h8=; b=J9YgGJiTb0Em9WJTcQGhoIT+p5jIgL7xLeiSuXhcbbAaDY1ouOTbJv4TYurCGfkE0q MsiojenkNxPUim3x8B346yJnJeGdT7EeScMEhHmm0bKECl2vDLsd6edjmbwK0lecrJf6 G/V7xobG73HgeEmSEDQCmqx2sf2xY7lAuhxAhmGp4Zfh7uuEbFWAx5Bxa9yBibzI2um/ 4yX4OpWbqRgq4yCCYWlIjG4C/HVO+SJl7sez/kgpbBFqFeYDJlE0RGoLvho/LOs9U84U CUNhpGkxG/xNwNQeSZLGEoIb2FSHClTp29lrMCkgIQFAz9tvWRBV/ePt9j3ShgHWb5bJ JiRw== X-Gm-Message-State: AO0yUKUGMEB3bDnbiLlp/5SU5VfOesLlhfx2R6YQ1uCmX2QOJ2nX2FpB CY95dvLBMb0NhlmjA5mlCEyNjHJXN7YWvjekoHvfi+NYb6lRqEaoDy0Jt/WIGPnQYva8S7IH+/I Ztqi9aADr6o0g41XZ5Ln4hBLNG/UJeVs7wDaF4+SUcSNZ6qJK4MSaJEDX+DzZMCMjR3eEOo2j X-Received: by 2002:a05:600c:3b8d:b0:3df:f9e6:2c5c with SMTP id n13-20020a05600c3b8d00b003dff9e62c5cmr17592751wms.38.1676255377064; Sun, 12 Feb 2023 18:29:37 -0800 (PST) X-Google-Smtp-Source: AK7set9zPcgMaVaPBGZuhMYsjxKDISmwsHzK1SuzoJN0Lk5HxfXE9X47Sml0VYLB3d4ypuUbCRbROQ== X-Received: by 2002:a05:600c:3b8d:b0:3df:f9e6:2c5c with SMTP id n13-20020a05600c3b8d00b003dff9e62c5cmr17592736wms.38.1676255376820; Sun, 12 Feb 2023 18:29:36 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu Subject: [PULL 14/22] migration: Rework multi-channel checks on URI Date: Mon, 13 Feb 2023 03:29:03 +0100 Message-Id: <20230213022911.68490-15-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255505288100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu The whole idea of multi-channel checks was not properly done, IMHO. Currently we check multi-channel in a lot of places, but actually that's not needed because we only need to check it right after we get the URI and that should be it. If the URI check succeeded, we should never need to check it again because we must have it. If it check fails, we should fail immediately on either the qmp_migrate or qmp_migrate_incoming, instead of failingg it later after the connection established. Neither should we fail any set capabiliities like what we used to do here: 5ad15e8614 ("migration: allow enabling mutilfd for specific protocol only",= 2021-10-19) Because logically the URI will only be set later after the capability is set, so it doesn't make a lot of sense to check the URI type when setting the capability, because we're checking the cap with an old URI passed in, and that may not even be the URI we're going to use later. This patch mostly reverted all such checks for before, dropping the variable migrate_allow_multi_channels and helpers. Instead, add a common helper to check URI for multi-channels for either qmp_migrate and qmp_migrate_incoming and that should do all the proper checks. The failure will only trigger with the "migrate" or "migrate_incoming" command, or when user specified "-incoming xxx" where "xxx" is not "defer". Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 3 --- migration/migration.c | 49 +++++++++++++++++++++------------------- migration/multifd.c | 12 ++-------- migration/postcopy-ram.c | 6 ----- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 66511ce532..c351872360 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -474,7 +474,4 @@ 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/migration.c b/migration/migration.c index 7a14aa98d8..f242d657e8 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -184,16 +184,27 @@ 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; +static bool migration_needs_multiple_sockets(void) +{ + return migrate_use_multifd() || migrate_postcopy_preempt(); +} =20 -void migrate_protocol_allow_multi_channels(bool allow) +static bool uri_supports_multi_channels(const char *uri) { - migrate_allow_multi_channels =3D allow; + return strstart(uri, "tcp:", NULL) || strstart(uri, "unix:", NULL) || + strstart(uri, "vsock:", NULL); } =20 -bool migrate_multi_channels_is_allowed(void) +static bool +migration_channels_and_uri_compatible(const char *uri, Error **errp) { - return migrate_allow_multi_channels; + if (migration_needs_multiple_sockets() && + !uri_supports_multi_channels(uri)) { + error_setg(errp, "Migration requires multi-channel URIs (e.g. tcp)= "); + return false; + } + + return true; } =20 static gint page_request_addr_cmp(gconstpointer ap, gconstpointer bp) @@ -493,12 +504,15 @@ static void qemu_start_incoming_migration(const char = *uri, Error **errp) { const char *p =3D NULL; =20 - migrate_protocol_allow_multi_channels(false); /* reset it anyway */ + /* URI is not suitable for migration? */ + if (!migration_channels_and_uri_compatible(uri, errp)) { + return; + } + qapi_event_send_migration(MIGRATION_STATUS_SETUP); if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || strstart(uri, "vsock:", NULL)) { - migrate_protocol_allow_multi_channels(true); socket_start_incoming_migration(p ? p : uri, errp); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { @@ -723,11 +737,6 @@ 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(); @@ -1378,15 +1387,6 @@ static bool migrate_caps_check(bool *cap_list, } #endif =20 - - /* incoming side only */ - if (runstate_check(RUN_STATE_INMIGRATE) && - !migrate_multi_channels_is_allowed() && - cap_list[MIGRATION_CAPABILITY_MULTIFD]) { - error_setg(errp, "multifd is not supported by current protocol"); - return false; - } - if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { if (!cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { error_setg(errp, "Postcopy preempt requires postcopy-ram"); @@ -2471,6 +2471,11 @@ void qmp_migrate(const char *uri, bool has_blk, bool= blk, MigrationState *s =3D migrate_get_current(); const char *p =3D NULL; =20 + /* URI is not suitable for migration? */ + if (!migration_channels_and_uri_compatible(uri, errp)) { + return; + } + if (!migrate_prepare(s, has_blk && blk, has_inc && inc, has_resume && resume, errp)) { /* Error detected, put into errp */ @@ -2483,11 +2488,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool= blk, } } =20 - migrate_protocol_allow_multi_channels(false); if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || strstart(uri, "vsock:", NULL)) { - 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/multifd.c b/migration/multifd.c index 7aa030fb19..99a59830c8 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -516,7 +516,7 @@ void multifd_save_cleanup(void) { int i; =20 - if (!migrate_use_multifd() || !migrate_multi_channels_is_allowed()) { + if (!migrate_use_multifd()) { return; } multifd_send_terminate_threads(NULL); @@ -913,10 +913,6 @@ int multifd_save_setup(Error **errp) if (!migrate_use_multifd()) { return 0; } - if (!migrate_multi_channels_is_allowed()) { - error_setg(errp, "multifd is not supported by current protocol"); - return -1; - } =20 thread_count =3D migrate_multifd_channels(); multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); @@ -1021,7 +1017,7 @@ int multifd_load_cleanup(Error **errp) { int i; =20 - if (!migrate_use_multifd() || !migrate_multi_channels_is_allowed()) { + if (!migrate_use_multifd()) { return 0; } multifd_recv_terminate_threads(NULL); @@ -1172,10 +1168,6 @@ int multifd_load_setup(Error **errp) return 0; } =20 - if (!migrate_multi_channels_is_allowed()) { - error_setg(errp, "multifd is not supported by current protocol"); - return -1; - } thread_count =3D migrate_multifd_channels(); multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 53299b7a5e..9a9d0ecf49 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1635,12 +1635,6 @@ int postcopy_preempt_setup(MigrationState *s, Error = **errp) return 0; } =20 - 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; - } - /* Kick an async task to connect */ socket_send_channel_create(postcopy_preempt_send_channel_new, s); =20 --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255403; cv=none; d=zohomail.com; s=zohoarc; b=L4zXX8LgcftuebIRnrAqi88BIeVsR71nP+pVxOSN+/yyVmo43UVg88PCwMayy4Yl7rmpWxBXKuIYgxovNCxqc8go8nUCD6iw0ReTs9guoZuidZ1dDhnIeauW2M/e5TgO06BwVJO2Qb6wVkb4aPBt9RBobWZ0Vjy6OBe5WL0vmqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255403; h=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=qidzccTnvZWTjmehoyXsqH06VDAcPWrPLs1KbiNU6rE=; b=Fv7w9wFxqTn5VGUNaI1uh0BOE6WjWz7E5uUrVvYDhbSxeYhi9a6WZxfUOqXPn6mzeIq3apppW5AV12nMLb57unnF3WWr5YewWa0LY/ZSGtwp2JaTDulk7/BEcQuv5V5XQ1R4KzdrXGbuS6bY4fEIYC3/tqtvtHAZcomrwzmnIvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255403515605.2408068345496; Sun, 12 Feb 2023 18:30:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObE-0001cN-OA; Sun, 12 Feb 2023 21:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObA-0001aS-3D for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb8-00036B-IL for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:43 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-216-0kW1QF5aOtim6ZxM40lIFQ-1; Sun, 12 Feb 2023 21:29:40 -0500 Received: by mail-wm1-f72.google.com with SMTP id o8-20020a05600c510800b003dfdf09ffc2so5423156wms.5 for ; Sun, 12 Feb 2023 18:29:40 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id v14-20020adfe28e000000b0027cb20605e3sm9290353wri.105.2023.02.12.18.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qidzccTnvZWTjmehoyXsqH06VDAcPWrPLs1KbiNU6rE=; b=OJ0IxUkyc/kO/ekftPKtu95lYtdtzyBwQkrRhISQlpwtgr9FHbfT+b7Q5Ez8NtSDuWUgeI mSKRciyONQ9C9vqtkg0vmDWzm2cA9KQ8OQEPyHqqlr0HGvBdaA3R7dGQe4G2mOwbTIJ94T hTtCQQ+hhSYtlzqdiDVHSkM4nHwow6k= X-MC-Unique: 0kW1QF5aOtim6ZxM40lIFQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qidzccTnvZWTjmehoyXsqH06VDAcPWrPLs1KbiNU6rE=; b=dUDmI0o7qZUrWTUIAb8qASNHrgNr0lWa24/3GfiAuQMzRPXtsFd+riaUU1T1MHkDNb dx84Z9ss9kRdUMvob/EKbkoz8vIecu9erkF+z+6GvmWmg5iZ2insKg5yhXu6orqjF5uh PB3wNgca8ZiyVqHWEvt54Q7rVY2iCGpYcm8GYkXzM8ykVfpcwkSlSXfSaj7guGKKTi6i N9v9qHuZVeQpqs10VDkZmzK609XOrxUb5xHt8ay3vnr+fJj4EBgK5pOqiffHZ+rKS2E+ UEtevoQOnrcv9L5vK7fLOCZ2cT2mwiLvh5ghs8nojQyhOz/AehGyKaRwGnK/SFjwXFWz ALNg== X-Gm-Message-State: AO0yUKUK83+POpzzUCjcYzdKaTTBPyuzubQK+neJ6lWonOPmj2Gxg7rl Kq30AhK5yo0mfmkiJfvVPML3i6USi0WdlsSjxRkxGpteL9YeJqOV1PY5lUXqACWrsEFnNiMjgVi NF0FpIUREihvdRsPMLU8OB/xK+ysuPxHcVHNTEI0qvyhOs/WJkHDVMBHeyFRzUqtNXRWpWpHK X-Received: by 2002:a5d:6209:0:b0:2c3:ed14:8323 with SMTP id y9-20020a5d6209000000b002c3ed148323mr20756786wru.38.1676255378855; Sun, 12 Feb 2023 18:29:38 -0800 (PST) X-Google-Smtp-Source: AK7set9CJkfVgcqqvmA2PK8UJ3ZRBCf5Ar3fjAkw0fGNmk0DoEJTWdD9PBXp0gaOgpZ5dijRQ5W3gA== X-Received: by 2002:a5d:6209:0:b0:2c3:ed14:8323 with SMTP id y9-20020a5d6209000000b002c3ed148323mr20756766wru.38.1676255378547; Sun, 12 Feb 2023 18:29:38 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu Subject: [PULL 15/22] migration: Cleanup postcopy_preempt_setup() Date: Mon, 13 Feb 2023 03:29:04 +0100 Message-Id: <20230213022911.68490-16-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255404820100009 Content-Type: text/plain; charset="utf-8" From: Peter Xu Since we just dropped the only case where postcopy_preempt_setup() can return an error, it doesn't need a retval anymore because it never fails. Move the preempt check to the caller, preparing it to be used elsewhere to do nothing but as simple as kicking the async connection. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/postcopy-ram.h | 2 +- migration/migration.c | 8 ++------ migration/postcopy-ram.c | 8 +------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 25881c4127..d5604cbcf1 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -191,7 +191,7 @@ enum PostcopyChannels { }; =20 void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); -int postcopy_preempt_setup(MigrationState *s, Error **errp); +void postcopy_preempt_setup(MigrationState *s); int postcopy_preempt_wait_channel(MigrationState *s); =20 #endif diff --git a/migration/migration.c b/migration/migration.c index f242d657e8..fb0ecf5649 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -4347,12 +4347,8 @@ 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 (migrate_postcopy_preempt()) { + postcopy_preempt_setup(s); } =20 if (resume) { diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 9a9d0ecf49..de6d4a3fd4 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1629,16 +1629,10 @@ int postcopy_preempt_wait_channel(MigrationState *s) return s->postcopy_qemufile_src ? 0 : -1; } =20 -int postcopy_preempt_setup(MigrationState *s, Error **errp) +void postcopy_preempt_setup(MigrationState *s) { - if (!migrate_postcopy_preempt()) { - return 0; - } - /* Kick an async task to connect */ socket_send_channel_create(postcopy_preempt_send_channel_new, s); - - return 0; } =20 static void postcopy_pause_ram_fast_load(MigrationIncomingState *mis) --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255467; cv=none; d=zohomail.com; s=zohoarc; b=IDPo7xY21VsW7zn05MKeFohOKSDrc90rpNMdkgCkwz1gVDssf/FPfXwV0j+04UvkMwRwhgIR8hP1JKItWAIk9slni3nAi3J1Wut2AKzB+aOfEAfMJ2q1vkGMLuk2zwXk+k/el7R6N7Ggl1n2GInYakSE5s9vf1+/dtv9K5gT7cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255467; h=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=6F1ytG82HghmM9+Be+OnSoaHtAltN0OwlcsGh3hnda0=; b=d0fIB8HYN+rBxem07+XP7mVvGuYOuB6YZdLmjOA+fq3UzE5R0/QJ4SxTaFEcv7MAiguZVmMqBbTOrB4DAoocagXgBCwa7TDhrj0iAXfgmidG7Slcr6E/QZ8SdPAdi/CiaQkYhVSK6SQ20jRDhXILYXbcmZmg7X1FGzyqt5hBQ9o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255467827736.8686494608471; Sun, 12 Feb 2023 18:31:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObF-0001cX-9M; Sun, 12 Feb 2023 21:29:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObB-0001at-Af for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pROb9-00036U-TV for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:45 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-604-zBqCv4sEOYKuSVDwVTCMPg-1; Sun, 12 Feb 2023 21:29:42 -0500 Received: by mail-wm1-f69.google.com with SMTP id h9-20020a05600c350900b003e000facbb1so8357132wmq.9 for ; Sun, 12 Feb 2023 18:29:41 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id c5-20020a5d4cc5000000b002c558869934sm1603931wrt.81.2023.02.12.18.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6F1ytG82HghmM9+Be+OnSoaHtAltN0OwlcsGh3hnda0=; b=HfR8jrIldU0mslAfrPaWC8mZtkXF2lqX7qRrd6gyDtohCqxoT+b18eS9wYdxZuuFbOEYNJ 2e2Vzbp3n3kLoOm2+VHI6lQqMyB9BRNI/GPWax2S8LDBgXofuOYlx0YAWOys3fQbJH61aE Hj/1eQIElfFggJXTkNgu0nyAmqF/bGQ= X-MC-Unique: zBqCv4sEOYKuSVDwVTCMPg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6F1ytG82HghmM9+Be+OnSoaHtAltN0OwlcsGh3hnda0=; b=aLcx72S90VNR41WeQ5GzqzKu8nmnN0zxW+UGYe33QfAMOkvVEQurvCiYB7SryWTb6M f/lDHCDp8vFfYQVBCgRrTu3FUxP7CX/i04XB4QVxGQMt5tzkC2sOgALuRIsZbC9at4fV boMexMHhXIxGtrrP70ghWXrR8Qpu/O6KKKuEbZuriFMLtit9XsmBk0UZtgPg66ZXzKg+ Q62lMaA90v80wpMf0IXu0ltG5nSY1532gg5Zey4ID/s9XrPw5fKSMQGYcGt+2ijXVrcb 1yKHYPGFr6eZiYu4xbhT+wXaM/Tw8L/eTp1THtL5THd1Drfki4Eqq3Ua1++1K4xcCLU0 nxpg== X-Gm-Message-State: AO0yUKW6M3Es93ydYIcWNdNuGWOW4fTrA6Gybq/wKKnuCuNU0vTvU0Co Raru+xRA46/NvvAhCpWOj/4CgTgjxgOoM0v70izASgYvdLatDwRWJYBnt+NC1SeUMAMOEID2B7a uYf2T57fZIUCZqTve+Kcf6RUCDjLuTrONcpA7ptdCSdJlwKNCHU4gqLCbajM6IPkuPXaUsDri X-Received: by 2002:a5d:6b83:0:b0:2c5:52f9:8e9b with SMTP id n3-20020a5d6b83000000b002c552f98e9bmr2916197wrx.29.1676255380515; Sun, 12 Feb 2023 18:29:40 -0800 (PST) X-Google-Smtp-Source: AK7set+w4tiiIr32cTPrOtsSdtBgrgswV6Foynst5WMlEHb8p54k7WY+DzrCcRZ8/v/aYqZB73LJYQ== X-Received: by 2002:a5d:6b83:0:b0:2c5:52f9:8e9b with SMTP id n3-20020a5d6b83000000b002c552f98e9bmr2916177wrx.29.1676255380247; Sun, 12 Feb 2023 18:29:40 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu Subject: [PULL 16/22] migration: Add a semaphore to count PONGs Date: Mon, 13 Feb 2023 03:29:05 +0100 Message-Id: <20230213022911.68490-17-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255469150100009 Content-Type: text/plain; charset="utf-8" From: Peter Xu This is mostly useless, but useful for us to know whether the main channel is correctly established without changing the migration protocol. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 6 ++++++ migration/migration.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/migration/migration.h b/migration/migration.h index c351872360..4cb1cb6fa8 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -276,6 +276,12 @@ struct MigrationState { */ bool rp_thread_created; QemuSemaphore rp_sem; + /* + * We post to this when we got one PONG from dest. So far it's an + * easy way to know the main channel has successfully established + * on dest QEMU. + */ + QemuSemaphore rp_pong_acks; } rp_state; =20 double mbps; diff --git a/migration/migration.c b/migration/migration.c index fb0ecf5649..a2e362541d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3025,6 +3025,7 @@ retry: case MIG_RP_MSG_PONG: tmp32 =3D ldl_be_p(buf); trace_source_return_path_thread_pong(tmp32); + qemu_sem_post(&ms->rp_state.rp_pong_acks); break; =20 case MIG_RP_MSG_REQ_PAGES: @@ -4524,6 +4525,7 @@ static void migration_instance_finalize(Object *obj) qemu_sem_destroy(&ms->postcopy_pause_sem); qemu_sem_destroy(&ms->postcopy_pause_rp_sem); qemu_sem_destroy(&ms->rp_state.rp_sem); + qemu_sem_destroy(&ms->rp_state.rp_pong_acks); qemu_sem_destroy(&ms->postcopy_qemufile_src_sem); error_free(ms->error); } @@ -4570,6 +4572,7 @@ static void migration_instance_init(Object *obj) qemu_sem_init(&ms->postcopy_pause_sem, 0); qemu_sem_init(&ms->postcopy_pause_rp_sem, 0); qemu_sem_init(&ms->rp_state.rp_sem, 0); + qemu_sem_init(&ms->rp_state.rp_pong_acks, 0); qemu_sem_init(&ms->rate_limit_sem, 0); qemu_sem_init(&ms->wait_unplug_sem, 0); qemu_sem_init(&ms->postcopy_qemufile_src_sem, 0); --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255493; cv=none; d=zohomail.com; s=zohoarc; b=GHIA0nau1Gm4TlFfgia8p4f6xjA+xmPscKDaozFVEYqL2XK6TzfIM8xzZpEohYbOVOzTGbRkLRBR4Vdo8IMLpYjxpIVxULm2FpnRu7cyoxvjrByKkdsKkfuMZEHi9BlbS/nH9mVAkD/45Mk3qSRhGxDxAqH9lEHgoSUk7IA5vKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255493; h=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=Jra5L+q+fwbERxylIBvIFg8T16r+MQ4cEjJ+sgpzLz8=; b=QLNthv3xl3T7BKZzwO1LEqmxZkfr7DWs9bxjfe9qQ9qymvD0hD9rfV+kkogsMS6B0OAbHvF1tdqeXDl8ZWfs8SGB786oJAVTJOouq5SMcu0MvaF4iUWt6Snng3910r6ymGYisacW/y4gWHjutcOIEygaAYRq3b339Y2685IixEg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255493131563.1419623313003; Sun, 12 Feb 2023 18:31:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObF-0001d4-RN; Sun, 12 Feb 2023 21:29:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObE-0001bY-6F for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObB-00036m-Fp for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:47 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-246-88hhU8eTODuXAoMF8unJgg-1; Sun, 12 Feb 2023 21:29:43 -0500 Received: by mail-wm1-f70.google.com with SMTP id b19-20020a05600c4e1300b003e10d3e1c23so8017240wmq.1 for ; Sun, 12 Feb 2023 18:29:43 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id t15-20020a5d534f000000b002c55306f6edsm3335702wrv.54.2023.02.12.18.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jra5L+q+fwbERxylIBvIFg8T16r+MQ4cEjJ+sgpzLz8=; b=Kqm6UoR+nNMhIWm/531aJVLDYVsQU+J/fzgnH3y3+Yl87p5/hDQNpn8fw9l93lhpzlDI1F Gr0sMed4MzxX6lL0PFyammv/dxKZIvB/+f7PfH6JOeCKHkaH6l1fPv+9PsRfYW8/Y76AR+ s1cCvrHq8wFbTRJOGEs/eh1zy7Hn720= X-MC-Unique: 88hhU8eTODuXAoMF8unJgg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jra5L+q+fwbERxylIBvIFg8T16r+MQ4cEjJ+sgpzLz8=; b=MKFqCNk90xgwwrLx+HPuyIehPhWFtCSImaKCEfgJ1mWZVugp3PQ+hFquSSEgSzf3ZF Ztrd+u541bNDV8+a90zniqCHo6olKur8Iu0XXON8c1tCtRUJHMOhkdNsycSBqwaDGyW8 XrzN5eqGQGmJwV9dvz/nDAH9NZc3/ue9mLYbHI1hyOK+lU9oHbY9wAovqH7YUbJwrud+ rWl8NSRd+VulJFAj1VN6M7ZUpqmGYp6pTn3hWNRv6PGWcZ869FvSF826ipwGCdYbluGp 9vmrJetUznCasTOZWamE/pG7wA7WMAa+V88et7S+riJuFsKsSUGOcV6iVL0vuBUMnY1D UL5A== X-Gm-Message-State: AO0yUKVB6CjxcSnLOksCccIOlZguryesh1qtP5pPffehaQz+oth81Jky h1IS9LId46gkicRyhcFRRWbV/yYsB2ezIPNDHF4vMGphhpfXZwUzjdrmGoy5XSjOsjO5mQg66Md g2cSmOJcCoKFM3C0UmiPl9250ePdvn06v5p6+hEOn3O7lOFhBds6XhsGt8SVa9AL1JeEOZvs/ X-Received: by 2002:a5d:4912:0:b0:2c5:4ea0:611d with SMTP id x18-20020a5d4912000000b002c54ea0611dmr3825476wrq.1.1676255382101; Sun, 12 Feb 2023 18:29:42 -0800 (PST) X-Google-Smtp-Source: AK7set8KGbx7CHyQlvaBrd5oYHW4ojI4IhMf2kmc2hamwOfsbO14tR4BkQeGsTcGgYlCl1SdSYT06g== X-Received: by 2002:a5d:4912:0:b0:2c5:4ea0:611d with SMTP id x18-20020a5d4912000000b002c54ea0611dmr3825458wrq.1.1676255381755; Sun, 12 Feb 2023 18:29:41 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu Subject: [PULL 17/22] migration: Postpone postcopy preempt channel to be after main Date: Mon, 13 Feb 2023 03:29:06 +0100 Message-Id: <20230213022911.68490-18-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255495271100010 Content-Type: text/plain; charset="utf-8" From: Peter Xu Postcopy with preempt-mode enabled needs two channels to communicate. The order of channel establishment is not guaranteed. It can happen that the dest QEMU got the preempt channel connection request before the main channel is established, then the migration may make no progress even during precopy due to the wrong order. To fix it, create the preempt channel only if we know the main channel is established. For a general postcopy migration, we delay it until postcopy_start(), that's where we already went through some part of precopy on the main channel. To make sure dest QEMU has already established the channel, we wait until we got the first PONG received. That's something we do at the start of precopy when postcopy enabled so it's guaranteed to happen sooner or later. For a postcopy recovery, we delay it to qemu_savevm_state_resume_prepare() where we'll have round trips of data on bitmap synchronizations, which means the main channel must have been established. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 6 ++++ migration/postcopy-ram.h | 2 +- migration/migration.c | 72 ++++++++++++++++++++++++++++++---------- migration/postcopy-ram.c | 17 ++++++++-- migration/savevm.c | 6 +++- 5 files changed, 82 insertions(+), 21 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 4cb1cb6fa8..2da2f8a164 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -116,6 +116,12 @@ struct MigrationIncomingState { unsigned int postcopy_channels; /* QEMUFile for postcopy only; it'll be handled by a separate thread */ QEMUFile *postcopy_qemufile_dst; + /* + * When postcopy_qemufile_dst is properly setup, this sem is posted. + * One can wait on this semaphore to wait until the preempt channel is + * properly setup. + */ + QemuSemaphore postcopy_qemufile_dst_done; /* Postcopy priority thread is used to receive postcopy requested page= s */ QemuThread postcopy_prio_thread; bool postcopy_prio_thread_created; diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index d5604cbcf1..b4867a32d5 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -192,6 +192,6 @@ enum PostcopyChannels { =20 void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); void postcopy_preempt_setup(MigrationState *s); -int postcopy_preempt_wait_channel(MigrationState *s); +int postcopy_preempt_establish_channel(MigrationState *s); =20 #endif diff --git a/migration/migration.c b/migration/migration.c index a2e362541d..a5c22e327d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -235,6 +235,8 @@ void migration_object_init(void) 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_sem_init(¤t_incoming->postcopy_qemufile_dst_done, 0); + qemu_mutex_init(¤t_incoming->page_request_mutex); current_incoming->page_requested =3D g_tree_new(page_request_addr_cmp); =20 @@ -737,6 +739,31 @@ void migration_fd_process_incoming(QEMUFile *f, Error = **errp) migration_incoming_process(); } =20 +/* + * Returns true when we want to start a new incoming migration process, + * false otherwise. + */ +static bool migration_should_start_incoming(bool main_channel) +{ + /* Multifd doesn't start unless all channels are established */ + if (migrate_use_multifd()) { + return migration_has_all_channels(); + } + + /* Preempt channel only starts when the main channel is created */ + if (migrate_postcopy_preempt()) { + return main_channel; + } + + /* + * For all the rest types of migration, we should only reach here when + * it's the main channel that's being created, and we should always + * proceed with this channel. + */ + assert(main_channel); + return true; +} + void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); @@ -798,7 +825,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) } } =20 - if (migration_has_all_channels()) { + if (migration_should_start_incoming(default_channel)) { /* If it's a recovery, we're done */ if (postcopy_try_recover()) { return; @@ -3159,6 +3186,13 @@ static int await_return_path_close_on_source(Migrati= onState *ms) return ms->rp_state.error; } =20 +static inline void +migration_wait_main_channel(MigrationState *ms) +{ + /* Wait until one PONG message received */ + qemu_sem_wait(&ms->rp_state.rp_pong_acks); +} + /* * Switch from normal iteration to postcopy * Returns non-0 on error @@ -3173,9 +3207,12 @@ static int postcopy_start(MigrationState *ms) bool restart_block =3D false; int cur_state =3D MIGRATION_STATUS_ACTIVE; =20 - if (postcopy_preempt_wait_channel(ms)) { - migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED); - return -1; + if (migrate_postcopy_preempt()) { + migration_wait_main_channel(ms); + if (postcopy_preempt_establish_channel(ms)) { + migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAIL= ED); + return -1; + } } =20 if (!migrate_pause_before_switchover()) { @@ -3586,6 +3623,20 @@ static int postcopy_do_resume(MigrationState *s) return ret; } =20 + /* + * If preempt is enabled, re-establish the preempt channel. Note that + * we do it after resume prepare to make sure the main channel will be + * created before the preempt channel. E.g. with weak network, the + * dest QEMU may get messed up with the preempt and main channels on + * the order of connection setup. This guarantees the correct order. + */ + ret =3D postcopy_preempt_establish_channel(s); + if (ret) { + error_report("%s: postcopy_preempt_establish_channel(): %d", + __func__, ret); + return ret; + } + /* * Last handshake with destination on the resume (destination will * switch to postcopy-active afterwards) @@ -3647,14 +3698,6 @@ static MigThrError postcopy_pause(MigrationState *s) if (s->state =3D=3D MIGRATION_STATUS_POSTCOPY_RECOVER) { /* Woken up by a recover procedure. Give it a shot */ =20 - if (postcopy_preempt_wait_channel(s)) { - /* - * Preempt enabled, and new channel create failed; loop - * back to wait for another recovery. - */ - continue; - } - /* * Firstly, let's wake up the return path now, with a new * return path channel. @@ -4347,11 +4390,6 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) } } =20 - /* This needs to be done before resuming a postcopy */ - if (migrate_postcopy_preempt()) { - postcopy_preempt_setup(s); - } - if (resume) { /* Wakeup the main migration thread to do the recovery */ migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED, diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index de6d4a3fd4..f54f44d899 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1197,6 +1197,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingSta= te *mis) } =20 if (migrate_postcopy_preempt()) { + /* + * The preempt channel is established in asynchronous way. Wait + * for its completion. + */ + qemu_sem_wait(&mis->postcopy_qemufile_dst_done); /* * This thread needs to be created after the temp pages because * it'll fetch RAM_CHANNEL_POSTCOPY PostcopyTmpPage immediately. @@ -1544,6 +1549,7 @@ void postcopy_preempt_new_channel(MigrationIncomingSt= ate *mis, QEMUFile *file) */ qemu_file_set_blocking(file, true); mis->postcopy_qemufile_dst =3D file; + qemu_sem_post(&mis->postcopy_qemufile_dst_done); trace_postcopy_preempt_new_channel(); } =20 @@ -1612,14 +1618,21 @@ out: postcopy_preempt_send_channel_done(s, ioc, local_err); } =20 -/* Returns 0 if channel established, -1 for error. */ -int postcopy_preempt_wait_channel(MigrationState *s) +/* + * This function will kick off an async task to establish the preempt + * channel, and wait until the connection setup completed. Returns 0 if + * channel established, -1 for error. + */ +int postcopy_preempt_establish_channel(MigrationState *s) { /* If preempt not enabled, no need to wait */ if (!migrate_postcopy_preempt()) { return 0; } =20 + /* Kick off async task to establish preempt channel */ + postcopy_preempt_setup(s); + /* * We need the postcopy preempt channel to be established before * starting doing anything. diff --git a/migration/savevm.c b/migration/savevm.c index ce181e21e1..b5e6962bb6 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2200,7 +2200,11 @@ 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 */ + /* + * The preempt channel will be created in async manner, now let's + * wait for it and make sure it's created. + */ + qemu_sem_wait(&mis->postcopy_qemufile_dst_done); assert(mis->postcopy_qemufile_dst); /* Kick the fast ram load thread too */ qemu_sem_post(&mis->postcopy_pause_sem_fast_load); --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255559; cv=none; d=zohomail.com; s=zohoarc; b=VewTftaOS3Sz6jYXxwtL/wG1eyOe9NoATS7jVc8Rxyy5dqQLDTU05oXXEWFg4qEpQRfJ676yBoiFLrI3du/Tz/nr0k0f2wFyLK9iXGfTqp3SPNztcBMKtM+xxqi7FkqLMd8eWQYXZLUB1jf9fYSzk+IayQ7JXI0VgZSjjf4zSbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255559; h=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=dUfdlqTOaMY/BDBu9wtEDIhadSAGMERvz+eZij4EHiY=; b=DBFIbPdbXGfYJKwroOANvxKd/icCNTN/KQRdUDVf8Nh7vief4KBLhLswgaQpAnuigb0DBQNoxbSzpNuTgZepVQYLURINjUJqSIO6HaqWMZcbgPkrMG1AWd+TUGaYWjGgxCrf1Lc3ze3GchGwLu+rEQpwSbeuhB4zfiGXv09Tk4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255559374302.92457755146404; Sun, 12 Feb 2023 18:32:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObP-0001hj-CB; Sun, 12 Feb 2023 21:29:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObN-0001h2-PA for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObM-00039k-1X for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:57 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-528-wXNrvfLDON-Mwjo8NmsZHA-1; Sun, 12 Feb 2023 21:29:45 -0500 Received: by mail-wm1-f72.google.com with SMTP id r14-20020a05600c35ce00b003e10bfcd160so6034819wmq.6 for ; Sun, 12 Feb 2023 18:29:45 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id k7-20020a05600c080700b003daf672a616sm11843175wmp.22.2023.02.12.18.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dUfdlqTOaMY/BDBu9wtEDIhadSAGMERvz+eZij4EHiY=; b=DTaUPAiz7BRzUCF5DkfSaWQffxx9z+KF/20shFXFCGezptgkor8HV2SWxiZY6+gEJODDwN DlNWuAzKWpv8sjUJ1sLlsHNFoGk716nEVKaMbj5pTPVAYr61NFrf+a5+b575kx5goeAlEw TwJrMO0czycY/xIdcxYB2fxMp3hav6U= X-MC-Unique: wXNrvfLDON-Mwjo8NmsZHA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dUfdlqTOaMY/BDBu9wtEDIhadSAGMERvz+eZij4EHiY=; b=tWMI7NKWajl8QHW4aRthr1FYcZ5VVSbtk0tMqXbSkSObTMbSiAQP0GCsTpkleL096m Jcuun5waY52sk+qvOZc2MPedWnjrL4af4iz0s1hSQqmHSxykBs58L47ktOI8a5jRofI5 1pwzFB2646dY3onK9CXWrsLC9bSlRaM3h5nHRHpSimIqgpth/nONc7dKBrWUWN1bmFnV JN6utEvlXT0zt80mIPHxq+Vns/SXshoFVv4598ikkKso7XNwDGmfp2XXmYbAGQYEnfnJ FIzyBLj2ntG5QrB+r1tGY7JP5OQHBbyzEiyFos6RWryfa69SIop/DcVhO2KfsbBjldsY +crw== X-Gm-Message-State: AO0yUKWznrz543Pl5i/WI6gj0H+Tf9f+2oBchJNtmOWBdAqlLMIGH/cJ cLiwbg1tybNxZQG7A0CQ2EDNfWab9iGJUUp1ViNHzJPbJSTpM98xlm5l506u/PjU5cLv5f5VTfe dUkpR9ys84fUYR0AbOAFOVsq+ZhLMiw4gydoa+TylIXwx/kQfrq+tiivWzOykwm5g7VkbeRVC X-Received: by 2002:a05:600c:16c4:b0:3da:270b:ba6b with SMTP id l4-20020a05600c16c400b003da270bba6bmr19254508wmn.41.1676255383829; Sun, 12 Feb 2023 18:29:43 -0800 (PST) X-Google-Smtp-Source: AK7set8Qn//cbEFCcD4e2+XicGyA204Lx92VcE6cIPopwYnuJH8nb0AvOSENVD2dZOQN6mpvOm8Cmg== X-Received: by 2002:a05:600c:16c4:b0:3da:270b:ba6b with SMTP id l4-20020a05600c16c400b003da270bba6bmr19254490wmn.41.1676255383583; Sun, 12 Feb 2023 18:29:43 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Leonardo Bras , Peter Xu Subject: [PULL 18/22] migration/multifd: Change multifd_load_cleanup() signature and usage Date: Mon, 13 Feb 2023 03:29:07 +0100 Message-Id: <20230213022911.68490-19-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255561524100003 Content-Type: text/plain; charset="utf-8" From: Leonardo Bras Since it's introduction in commit f986c3d256 ("migration: Create multifd migration threads"), multifd_load_cleanup() never returned any value different than 0, neither set up any error on errp. Even though, on process_incoming_migration_bh() an if clause uses it's return value to decide on setting autostart =3D false, which will never happen. In order to simplify the codebase, change multifd_load_cleanup() signature to 'void multifd_load_cleanup(void)', and for every usage remove error handling or decision made based on return value !=3D 0. Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Reviewed-by: Peter Xu Signed-off-by: Juan Quintela --- migration/multifd.h | 2 +- migration/migration.c | 14 ++++---------- migration/multifd.c | 6 ++---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index ff3aa2e2e9..9a7e1a8826 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -16,7 +16,7 @@ int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); -int multifd_load_cleanup(Error **errp); +void multifd_load_cleanup(void); bool multifd_recv_all_channels_created(void); void multifd_recv_new_channel(QIOChannel *ioc, Error **errp); void multifd_recv_sync_main(void); diff --git a/migration/migration.c b/migration/migration.c index a5c22e327d..5bf332fdd2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -559,13 +559,7 @@ static void process_incoming_migration_bh(void *opaque) */ qemu_announce_self(&mis->announce_timer, migrate_announce_params()); =20 - if (multifd_load_cleanup(&local_err) !=3D 0) { - error_report_err(local_err); - autostart =3D false; - } - /* If global state section was not received or we are in running - state, we need to obey autostart. Any other state is set with - runstate_set. */ + multifd_load_cleanup(); =20 dirty_bitmap_mig_before_vm_start(); =20 @@ -665,9 +659,9 @@ fail: migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED); qemu_fclose(mis->from_src_file); - if (multifd_load_cleanup(&local_err) !=3D 0) { - error_report_err(local_err); - } + + multifd_load_cleanup(); + exit(EXIT_FAILURE); } =20 diff --git a/migration/multifd.c b/migration/multifd.c index 99a59830c8..cac8496edc 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1013,12 +1013,12 @@ static void multifd_recv_terminate_threads(Error *e= rr) } } =20 -int multifd_load_cleanup(Error **errp) +void multifd_load_cleanup(void) { int i; =20 if (!migrate_use_multifd()) { - return 0; + return; } multifd_recv_terminate_threads(NULL); for (i =3D 0; i < migrate_multifd_channels(); i++) { @@ -1058,8 +1058,6 @@ int multifd_load_cleanup(Error **errp) multifd_recv_state->params =3D NULL; g_free(multifd_recv_state); multifd_recv_state =3D NULL; - - return 0; } =20 void multifd_recv_sync_main(void) --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255530; cv=none; d=zohomail.com; s=zohoarc; b=I4sKnJidMAvT5ec8HvkB+zLkYieGlSOPUXr7+3Ejx8K2J31W3f8qNDwt7aj32WARPxewBllvdKWnWE+2sKJMIKTUB0uTKAHlwSeD7Y2vrMnKA0jXGOQZYwhToAE7z8Xa7N1TeqCjnfHg8TFvl8aCJXu6bQOpPGKkmhYrkjNBb+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255530; h=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=tSe+Gdu1AJDo4dQjmBB0UPRFbXEKMEpLnQVbJ+wkYp0=; b=RYghi4N1YdEtsdPwG+NhqNZW0LS9nTfaFfLIWZNohRrVsg92UpXizeImAKkeVx5+h9Xzxwfr6AsIDCPo5gyHRXxofYN6nhaEzHOqv9HTbWwd5CRfQ/o7MXvmfsKhwQDcaFh3Hvv3bh7bXdlHY0eu/5dBT1PT4wsm6clfoHJSU3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255530232601.5684131266065; Sun, 12 Feb 2023 18:32:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObH-0001es-GY; Sun, 12 Feb 2023 21:29:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObG-0001d8-HX for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObF-00037V-3t for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:50 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-537-xt6JjolzOhGCo1i8iU144g-1; Sun, 12 Feb 2023 21:29:47 -0500 Received: by mail-wm1-f72.google.com with SMTP id l38-20020a05600c1d2600b003ddff4b9a40so6033349wms.9 for ; Sun, 12 Feb 2023 18:29:47 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id h16-20020a5d6890000000b002c553509db7sm2979924wru.52.2023.02.12.18.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tSe+Gdu1AJDo4dQjmBB0UPRFbXEKMEpLnQVbJ+wkYp0=; b=jKXKO6meLxNJtFsUScFu2LmmQmbrP4JS94q1TP+bnlQOxg17ZwJS2K/GOJ2g101vl/DjVZ adIcomAp1nkcQ1R5wWK7bdE4XwD5kMLfRVWmGal1ZH52pp1zRe3vnLFbOgoQE/VR5s0iuR GFsAUVMfMp/lU3b1V2h2AsTkixcR8TE= X-MC-Unique: xt6JjolzOhGCo1i8iU144g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tSe+Gdu1AJDo4dQjmBB0UPRFbXEKMEpLnQVbJ+wkYp0=; b=20QXfmY4YTcQIVc268Po2Vhd5PQiCE1Iai+Zt5gfevFveDRjUJPHv1o0Wpl3JlNChR rUSCHU2vKbseTdLb2bUp84+DTqRM07C+WumUzf3AVuBv7F1IjKIdJXmIuIMWinOLnnVN VuIbOHLLWVOyMqY84Fnyn3YxZoCND9Cy/xwTRr8mUfm0HwDixLVG5h3U2Brf7GQQld9H 4SmRrorlw/r+kI+KHVz/pbeqaUmEPgP54nK929WeUh97LUVAClsPVAW0dE++IpC5tdOB oqFv1H8mFcwJ9QALHl/9wYGPPnb4pnvt852YwQ68pfEBSshC345kEtNcfbWs8GAZTFyx au3Q== X-Gm-Message-State: AO0yUKVNGvqQP4PdvM/Ex/cwl2Eul55+qvoTIhBkkqBgE/79a6ZWjcPS atVEPEd7QI+98b6dkVBr8H2Qzz5o3aH7A7dsx2/eIfh0T+2Owu9FDN6naeIzGy6oxjMnVrTdSHK 8xinQ44B8lppD1AIgQxu30Fy1fdXp2lS0v4KCzc+uE+5aWiLl/+xxINsuwb0WcqGGM8kAv40k X-Received: by 2002:adf:e608:0:b0:2c3:e0a0:93f with SMTP id p8-20020adfe608000000b002c3e0a0093fmr18298435wrm.8.1676255385554; Sun, 12 Feb 2023 18:29:45 -0800 (PST) X-Google-Smtp-Source: AK7set+WKuAYOVOi5T8g/gwIH4YXlwRtin+i6T7IHgekqnQDqwh6cmXscxDcqMGyyd1yN/d6+Bf2LQ== X-Received: by 2002:adf:e608:0:b0:2c3:e0a0:93f with SMTP id p8-20020adfe608000000b002c3e0a0093fmr18298417wrm.8.1676255385331; Sun, 12 Feb 2023 18:29:45 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Leonardo Bras , Peter Xu Subject: [PULL 19/22] migration/multifd: Remove unnecessary assignment on multifd_load_cleanup() Date: Mon, 13 Feb 2023 03:29:08 +0100 Message-Id: <20230213022911.68490-20-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255531420100001 Content-Type: text/plain; charset="utf-8" From: Leonardo Bras Before assigning "p->quit =3D true" for every multifd channel, multifd_load_cleanup() will call multifd_recv_terminate_threads() which already does the same assignment, while protected by a mutex. So there is no point doing the same assignment again. Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Reviewed-by: Peter Xu Signed-off-by: Juan Quintela --- migration/multifd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/migration/multifd.c b/migration/multifd.c index cac8496edc..3dd569d0c9 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1025,7 +1025,6 @@ void multifd_load_cleanup(void) MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 if (p->running) { - p->quit =3D true; /* * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle co= de, * however try to wakeup it without harm in cleanup phase. --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255444; cv=none; d=zohomail.com; s=zohoarc; b=Zcegx2uN/2IutF2yDDkmhOT1BrZbcIY1F3rLeGGoCARce7BU5u/NzcZnGYzEiQbNWCk4vcjYOb7mXjnLSWKXcep/pUf72Jluh9vGhrGSpfiLh5FBPVutUJ6+moiCAkv41aKWortv6+j4mAq52HV5A0xq1aMI7XsYy7u7APQKSas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255444; h=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=W0nw1KUXQEI1xmDznSZCB7Y0xnFRisWgzKRd5bzpoYs=; b=GOKul9dvYfZvVcjnPwR3fBzS43bY1BFCul+cQ1vWEHUZEO+8GO5GKpM7iaKJhtNgelQQLdhcEeKVLAe4u34xX0V2PQr9WO74/BilI+qyfq4hCRe5/zHTWRI2fD78xPsVHvsLQKrR18T+Ru1fMF8oSX2GwrKayeUlDYc6rVI/Yz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255444223488.55566483289545; Sun, 12 Feb 2023 18:30:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObK-0001fz-5Y; Sun, 12 Feb 2023 21:29:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObI-0001fO-GY for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObH-00037l-0u for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:52 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-572-ER3vT6_LPK2RKfhHlnixcg-1; Sun, 12 Feb 2023 21:29:49 -0500 Received: by mail-wm1-f71.google.com with SMTP id j20-20020a05600c1c1400b003dc5dd44c0cso5417477wms.8 for ; Sun, 12 Feb 2023 18:29:49 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id h18-20020a5d4312000000b002c54d970fd8sm5217585wrq.36.2023.02.12.18.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W0nw1KUXQEI1xmDznSZCB7Y0xnFRisWgzKRd5bzpoYs=; b=izVUHUS6O72zYnoDEThDasLwdqv0y3xtZjyrF3HSf93hBmcfFZXRDGQc3imb+E5ywp/sc6 UPJ4RZUPlPuplXKNlAUHppZS+yvvltheKhNKHm2yJyOz6G5aiWPRRNa0ExHHNP5CJZ1dSS vApo7CpwSHKvev3wI4czexF9uSeEV+E= X-MC-Unique: ER3vT6_LPK2RKfhHlnixcg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W0nw1KUXQEI1xmDznSZCB7Y0xnFRisWgzKRd5bzpoYs=; b=2uDk0JPbVLVB2SKqWm3FqQvSHORTwlOMtRbSoH7vhq69op9evM2JKmDgpJvp86HC7y j/BBg/4dbYAsIUBjKQZM1ICM+7jVhf4G6o840QE+uME0/qKUzX7b1YY19IcpIUQcrfi7 4TliCi5+Cp8XfSEQ7gjRW8jwzO4z6bT3mwg8L+Szof0eBf+b7WQPWdE061QZ8HZXVhQg slwMvR8ixvjwTQAyB5OAxqlaN/YpyqNNcyQCbPRkR+S7YgliQ5c9qnERD3iWHftZICHv aRNHixce6hLHTbzoVMeEG6JZkZ39n+fQAGBwjclLJnBXPlA7TlytpshfAwtHqsF+wZfl m8MQ== X-Gm-Message-State: AO0yUKUmkiXK9tFPBH0TcXUwaSug6+/Nv+S2IWChC4PpxbFrI8lBSxj0 t9mzOJ9hQvnFvfkjEGT1t4cf8KEhY459wh/+lENHOYOL3xfxHA6HV/6UuBPVCEzOaVJnwRfOUA/ /cFvv/dXHwVgMVgT2Lgan4mNVXMi/v8mp66EJfNFZSqXm76wf8e628dBsvKUerm6s1jshnxfk X-Received: by 2002:a5d:54c2:0:b0:2c5:5574:5d5f with SMTP id x2-20020a5d54c2000000b002c555745d5fmr2753745wrv.57.1676255387500; Sun, 12 Feb 2023 18:29:47 -0800 (PST) X-Google-Smtp-Source: AK7set+IfMyiKrMVGyZxcMV28tfgSW1ky+Zg7v8is/7d+LHfzSAxPDuD2M7ITqxcYPHG9kILEX7i7g== X-Received: by 2002:a5d:54c2:0:b0:2c5:5574:5d5f with SMTP id x2-20020a5d54c2000000b002c555745d5fmr2753729wrv.57.1676255387278; Sun, 12 Feb 2023 18:29:47 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Leonardo Bras , Peter Xu Subject: [PULL 20/22] migration/multifd: Join all multifd threads in order to avoid leaks Date: Mon, 13 Feb 2023 03:29:09 +0100 Message-Id: <20230213022911.68490-21-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255444999100001 Content-Type: text/plain; charset="utf-8" From: Leonardo Bras Current approach will only join threads that are still running. For the threads not joined, resources or private memory are always kept in the process space and never reclaimed before process end, and this risks serious memory leaks. This should usually not represent a big problem, since multifd migration is usually just ran at most a few times, and after it succeeds there is not much to be done before exiting the process. Yet still, it should not hurt performance to join all of them. Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Reviewed-by: Peter Xu Signed-off-by: Juan Quintela --- migration/multifd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/multifd.c b/migration/multifd.c index 3dd569d0c9..840d5814e4 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1030,8 +1030,9 @@ void multifd_load_cleanup(void) * however try to wakeup it without harm in cleanup phase. */ qemu_sem_post(&p->sem_sync); - qemu_thread_join(&p->thread); } + + qemu_thread_join(&p->thread); } for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255476; cv=none; d=zohomail.com; s=zohoarc; b=HIwoJi7SkTwhnVQ+/+2nwqFmlhcTs96JLGTODbgeGmiCLq+2/HGAEXm9eOylPnZlYXPUom4bfBIsY+t4ZhhD5wRE+30S6imxefdfwlkgf/rhDq6HZM7rC/CUSsqdxRd0I6IzPI2aI6826p1H+S6PG87BFUJxLdHMRbEauvx2Fh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255476; h=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=1yhUeN6PMDjGLlmfRv43ztKFKB+CFUSApjprBMF/DVs=; b=Mmjtk6lAza9hs/MLQe8SaBRT/zmdYB4a3qvAT/ucVO/MrjT4lEiavfPq48shFmQh9JgC1on2YGDnZBFLMT9OscDvRfeyzyc4iWrdxDlWxOdK+jNhx7wj8UxzzdO8fGVNPdj5HlRkA6XRfn9j6CjVdsmMmYxLq1W+QNRRIrZ+z/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255476772264.5860433248524; Sun, 12 Feb 2023 18:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObL-0001gL-Q2; Sun, 12 Feb 2023 21:29:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObK-0001g1-Ah for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObI-00039C-N3 for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:54 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-642-A61-4is6NqWlbLrrdja-vQ-1; Sun, 12 Feb 2023 21:29:51 -0500 Received: by mail-wm1-f70.google.com with SMTP id e38-20020a05600c4ba600b003dc434dabbdso8365882wmp.6 for ; Sun, 12 Feb 2023 18:29:50 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id j40-20020a05600c1c2800b003dc4480df80sm17346274wms.34.2023.02.12.18.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1yhUeN6PMDjGLlmfRv43ztKFKB+CFUSApjprBMF/DVs=; b=cFRWuHbvypJNcwea3nEaFnSgPt6xDLxntEKtqETqyj4gmGrjmhYymaEzFMJd3H70tnWlsC qRAeHUKDbYVUNBbdmYQCdfy/4f7ZJOn+hoNVL/W6Ljonn8xdjsfmK94a8hnDfc+9eM11k9 gCmmNrKia6BFPL3rsaPioIEL83+TZhc= X-MC-Unique: A61-4is6NqWlbLrrdja-vQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1yhUeN6PMDjGLlmfRv43ztKFKB+CFUSApjprBMF/DVs=; b=L25KbWWPynpJLZC99fnfbhp094oirij4oh7wQw5F39d3VoZt2O9S6e/AXO5qsYvrY1 0k6ud9tzPORI1iPloEYEhuUsgjM4RDyiJDvuT4o2oNLbKXMJy83+hzCLIdTgQJYIDPHb T6qza+jaOsMXUr/B96SB5BEmEepg55XIpYq2WdaS3I7lnu+Kmxe3RiL7p4QK2/qSGr4G DYrVDNgAy2frGcWnRULx71achwhgd8GvJTM8HKjTpCneMnhJh6rCh36IcmDZu7LpsXFB CqDyGM/LcscgnybyVZmnIBxN17MpQh+wJb0hmDYAeKULyaYgWSs17JHLM/mwMHTnZZlw b1FA== X-Gm-Message-State: AO0yUKXQEMSxBWC2jM75Iw8XhEGF8cX/KoyiZqh2oq70OQCkH7eb6Ikk QWIGrL3hY1D5qXP8UQsCuiMlO6yGumTphHQAFeVScRc92y0WHygZXWjI+V+G5WERHC3Q6e8XjZj d6zhtNUFJQwxvQCS3WvaLdx77ej0eQXGvky8NS3mgFatZI5sfPaLQ1300IcFAAKgI51vvK3N+ X-Received: by 2002:a05:600c:1694:b0:3de:27c3:ef13 with SMTP id k20-20020a05600c169400b003de27c3ef13mr17673799wmn.9.1676255389416; Sun, 12 Feb 2023 18:29:49 -0800 (PST) X-Google-Smtp-Source: AK7set8MM5ZCkie7NV7W++wxJDBegmWHyipkHejCobgGbh9/xnuobYvLzGnVHhdOuw7GmHpn5yPvNA== X-Received: by 2002:a05:600c:1694:b0:3de:27c3:ef13 with SMTP id k20-20020a05600c169400b003de27c3ef13mr17673782wmn.9.1676255389180; Sun, 12 Feb 2023 18:29:49 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Leonardo Bras , Peter Xu Subject: [PULL 21/22] migration/multifd: Move load_cleanup inside incoming_state_destroy Date: Mon, 13 Feb 2023 03:29:10 +0100 Message-Id: <20230213022911.68490-22-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255477165100001 Content-Type: text/plain; charset="utf-8" From: Leonardo Bras Currently running migration_incoming_state_destroy() without first running multifd_load_cleanup() will cause a yank error: qemu-system-x86_64: ../util/yank.c:107: yank_unregister_instance: Assertion `QLIST_EMPTY(&entry->yankfns)' failed. (core dumped) The above error happens in the target host, when multifd is being used for precopy, and then postcopy is triggered and the migration finishes. This will crash the VM in the target host. To avoid that, move multifd_load_cleanup() inside migration_incoming_state_destroy(), so that the load cleanup becomes part of the incoming state destroying process. Running multifd_load_cleanup() twice can become an issue, though, but the only scenario it could be ran twice is on process_incoming_migration_bh(). So removing this extra call is necessary. On the other hand, this multifd_load_cleanup() call happens way before the migration_incoming_state_destroy() and having this happening before dirty_bitmap_mig_before_vm_start() and vm_start() may be a need. So introduce a new function multifd_load_shutdown() that will mainly stop all multifd threads and close their QIOChannels. Then use this function instead of multifd_load_cleanup() to make sure nothing else is received before dirty_bitmap_mig_before_vm_start(). Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Reviewed-by: Peter Xu Signed-off-by: Juan Quintela --- migration/multifd.h | 1 + migration/migration.c | 4 +++- migration/multifd.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/migration/multifd.h b/migration/multifd.h index 9a7e1a8826..7cfc265148 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -17,6 +17,7 @@ int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); void multifd_load_cleanup(void); +void multifd_load_shutdown(void); bool multifd_recv_all_channels_created(void); void multifd_recv_new_channel(QIOChannel *ioc, Error **errp); void multifd_recv_sync_main(void); diff --git a/migration/migration.c b/migration/migration.c index 5bf332fdd2..90fca70cb7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -315,6 +315,8 @@ void migration_incoming_state_destroy(void) { struct MigrationIncomingState *mis =3D migration_incoming_get_current(= ); =20 + multifd_load_cleanup(); + if (mis->to_src_file) { /* Tell source that we are done */ migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) = !=3D 0); @@ -559,7 +561,7 @@ static void process_incoming_migration_bh(void *opaque) */ qemu_announce_self(&mis->announce_timer, migrate_announce_params()); =20 - multifd_load_cleanup(); + multifd_load_shutdown(); =20 dirty_bitmap_mig_before_vm_start(); =20 diff --git a/migration/multifd.c b/migration/multifd.c index 840d5814e4..5e85c3ea9b 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1013,6 +1013,13 @@ static void multifd_recv_terminate_threads(Error *er= r) } } =20 +void multifd_load_shutdown(void) +{ + if (migrate_use_multifd()) { + multifd_recv_terminate_threads(NULL); + } +} + void multifd_load_cleanup(void) { int i; --=20 2.39.1 From nobody Fri May 17 08:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676255491; cv=none; d=zohomail.com; s=zohoarc; b=md5fbK7LugJ+1BGjUqfTAdd+85B+x4RoCkU0clqcCHVfgPpRSdbGCSWnzMqb96Bd/kN01VIvYTlibnHlMwBv5BTKrAbSxsSsGUNWsAPKsQTiA7IQjwmJUxmZB3aFlGckVeg4TW5b84PHMR/dp5hjpcS8/oRnTJKbzkPrtnHy1/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676255491; h=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=Wri2CO6/ED+3PLHQRO4xHrfVHwULI1GD8MLKUb731II=; b=Byq1Gn+BVDNgiPgStK6N5xRqFhDHTftQbNNhtkjiLXQse0wqZt4ECpORArAKxej6Xy6oK0atvJGXqRBMTO7TiA4W+ZpaQ84GL9RsVMN+3rhdpzC8YYxFhqrZ3jp6CJ67bwfoMjqvAicpXipqmpOzkWvE5d8SORG87vFD+D4Wcyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676255491530450.0594312206165; Sun, 12 Feb 2023 18:31:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRObN-0001h1-GS; Sun, 12 Feb 2023 21:29:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObM-0001gl-9w for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRObK-00039X-MJ for qemu-devel@nongnu.org; Sun, 12 Feb 2023 21:29:55 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-QAn_8IVhOwaVIOatNUUDUQ-1; Sun, 12 Feb 2023 21:29:52 -0500 Received: by mail-wm1-f72.google.com with SMTP id n7-20020a05600c3b8700b003dc55dcb298so6033407wms.8 for ; Sun, 12 Feb 2023 18:29:52 -0800 (PST) Received: from redhat.com ([46.136.252.173]) by smtp.gmail.com with ESMTPSA id t9-20020adfeb89000000b002be0b1e556esm9231583wrn.59.2023.02.12.18.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 18:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676255394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wri2CO6/ED+3PLHQRO4xHrfVHwULI1GD8MLKUb731II=; b=gb3Xb+V4rMZNP0euKTOvDvRgH9saCDL6wlk4QMRPoA3nBcPMBBrOrIds0PdZO9sHMvaWbN 2GesPM3sYW/zz9QP+c3TuMiZU3GO0Yr3QPkf4iO8x1ZNK9vEyZBFA0e2wYQGdXTRagKAgF 4g2VxXxxX7CiWLgPM7uAitwalxv0IZ8= X-MC-Unique: QAn_8IVhOwaVIOatNUUDUQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wri2CO6/ED+3PLHQRO4xHrfVHwULI1GD8MLKUb731II=; b=J3HVAh5g5zFL5Oi6wIyQcBbZnv+ZjCaFGz6Dgzg4JbhSzYgu5goO+MzB/OEt+u8TwE qaWKX2IRxwomnhCRnaUMkXA3P18FRhEZ/3iY+RPLa6PJq4ihhfhq4YiasJHi/lveFy4s 63Lcy3+ocQaSZ50RdfLmxZlhWPl6XpKJ5RtJiL9Ok8adYLmHR9FFzZDsThpuadEdb4gJ IlNBnPZ5HVFTRDqfODbNI5VkV8ibgZyqsq6Kn8iqiVWN0YGec342butqcz/xEq5PdBdq 9kyvzsrL9LE/cP5xE1jdZPmBq4M8Qor+GbNkoZ5jLtq944JzepI6VhNMNG9DCBRRbcZ6 fBMw== X-Gm-Message-State: AO0yUKVF4qygx5oemL58KMadUFe0i27bzb/rKpJhCNlWL+oziKTNLbNZ aGImVqEz8n8mZ2/CNW3JNDZk/6qXJsn9rRiHIjPQPVBXwHVMZgT+hI9A/wBhqhls51TsUNfSeL6 uAHRjGVl1JH1bVDJ1GhWdiABYUdW/s5KOJIUpKtZTqoxosTZtxMJQkv864Gg8Jy3DxRShszKN X-Received: by 2002:a5d:6845:0:b0:2c3:e0a0:94f with SMTP id o5-20020a5d6845000000b002c3e0a0094fmr18388367wrw.37.1676255391045; Sun, 12 Feb 2023 18:29:51 -0800 (PST) X-Google-Smtp-Source: AK7set9w/r02MOuyNF6ZqzSL2cS4DS8i6O5G9fomfHgKEJeNVNkj+CcjrykNGeyX93lI34+24dt6Yg== X-Received: by 2002:a5d:6845:0:b0:2c3:e0a0:94f with SMTP id o5-20020a5d6845000000b002c3e0a0094fmr18388350wrw.37.1676255390787; Sun, 12 Feb 2023 18:29:50 -0800 (PST) From: Xxx Xx X-Google-Original-From: Xxx Xx To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Juan Quintela , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , "Dr. David Alan Gilbert" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake Subject: [PULL 22/22] ram: Document migration ram flags Date: Mon, 13 Feb 2023 03:29:11 +0100 Message-Id: <20230213022911.68490-23-xxx.xx@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213022911.68490-1-xxx.xx@gmail.com> References: <20230213022911.68490-1-xxx.xx@gmail.com> MIME-Version: 1.0 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676255493256100003 Content-Type: text/plain; charset="utf-8" From: Juan Quintela 0x80 is RAM_SAVE_FLAG_HOOK, it is in qemu-file now. Bigger usable flag is 0x200, noticing that. We can reuse RAM_SAVe_FLAG_FULL. Reviewed-by: Eric Blake Signed-off-by: Juan Quintela --- migration/ram.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 18ac68b181..521912385d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -67,21 +67,25 @@ /***********************************************************/ /* ram save/restore */ =20 -/* RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it - * worked for pages that where filled with the same char. We switched +/* + * RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it + * worked for pages that were filled with the same char. We switched * it to only search for the zero value. And to avoid confusion with - * RAM_SSAVE_FLAG_COMPRESS_PAGE just rename it. + * RAM_SAVE_FLAG_COMPRESS_PAGE just rename it. */ - -#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ +/* + * RAM_SAVE_FLAG_FULL was obsoleted in 2009, it can be reused now + */ +#define RAM_SAVE_FLAG_FULL 0x01 #define RAM_SAVE_FLAG_ZERO 0x02 #define RAM_SAVE_FLAG_MEM_SIZE 0x04 #define RAM_SAVE_FLAG_PAGE 0x08 #define RAM_SAVE_FLAG_EOS 0x10 #define RAM_SAVE_FLAG_CONTINUE 0x20 #define RAM_SAVE_FLAG_XBZRLE 0x40 -/* 0x80 is reserved in migration.h start with 0x100 next */ +/* 0x80 is reserved in qemu-file.h for RAM_SAVE_FLAG_HOOK */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 +/* We can't use any flag that is bigger than 0x200 */ =20 int (*xbzrle_encode_buffer_func)(uint8_t *, uint8_t *, int, uint8_t *, int) =3D xbzrle_encode_buffer; --=20 2.39.1