From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967662; cv=none; d=zohomail.com; s=zohoarc; b=PiQ/iHvEKIJ3zp3tCzz+y5TueoODmw9PKD9rMIpeJR4ihSHo0qxMMY2hu3Jct1hnk9GVwkbMipgfYMgBxMVgqHXAFe9T6+bme3x9EjH4Vsu7Ixrj62b3Ae9vgtRsiOavWvxuTc5DJNV4BQcq7M9fdk1OJZrXf2E2Axbzd5VjsaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967662; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dxkFkxQl9dUhOcnAgC1JEv5y7NtRKpJgByrREEy6Z50=; b=gPVlSI++gTP5N0+2j8lspyFB03fW5r00GWrD6DZPFR7WSF8tmS2zhrco6Yq82l13poVEfF/7cjaP7yI5P2U/wWyDKREYlM8pyY3y6O3m6DNbDs7BqpGdaE6UOnzp5QLf2UOtimJb9VoP9K5oVIktQ94M/aQPoMEFXsllRpe046I= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967662780812.0808491649121; Wed, 14 Oct 2026 01:47:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGue1-0005NX-PT; Wed, 14 Oct 2026 04:47:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGudo-0005F1-Fa for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:16 -0400 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 1xGudj-0004Xg-EI for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:13 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-PFCaFyBGPm6LADk1QqLDYw-1; Wed, 14 Oct 2026 08:47:09 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C18519560BA; Wed, 14 Oct 2026 08:47:07 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2DA4C1800446; Wed, 14 Oct 2026 08:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967630; 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=dxkFkxQl9dUhOcnAgC1JEv5y7NtRKpJgByrREEy6Z50=; b=FKuJ71rvGoYfHa/1mPaIdIeeaopEa92Q00fChbNtLCbRcFkRNkf6DZmulIejbagR8gJqOx 05S87m58yFFxHQ9HMEnJcLCYtX5T0xiTDJShbjhJH5Yd8huAO9+kNjmSCDF/OGEv77d7eh 0J6nozILSjf5p04rERpPhm5X+/CxuxM= X-MC-Unique: PFCaFyBGPm6LADk1QqLDYw-1 X-Mimecast-MFC-AGG-ID: PFCaFyBGPm6LADk1QqLDYw_1791967628 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 01/17] igb: Add x-vf-migration property and DVSEC extended capability Date: Wed, 14 Oct 2026 10:46:39 +0200 Message-ID: <20261014084655.127254-2-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967665119158500 Add an "x-vf-migration" property to the IGB PF device and expose a DVSEC (Designated Vendor-Specific Extended Capability) at offset 0x160 in VF extended config space when migration is enabled. The DVSEC provides the register interface for VF live migration: - CAPS: supported features (state migration) - CTRL: command doorbell - STATUS: state and error reporting - BUF_ADDR: shared DMA buffer address (GPA) Move IgbVfState from igbvf.c to igb_common.h so it can be shared with the migration module, and add the migration state field. The DVSEC vendor ID field identifies who defined the DVSEC layout, not the device vendor. Use PCI_VENDOR_ID_REDHAT_QUMRANET (0x1AF4), the same vendor ID used by virtio devices, to attribute the DVSEC format and QEMU-defined migration protocol interface to QEMU/Red Hat, not Intel. AI-used-for: code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 5 +++ hw/net/igb_common.h | 16 ++++++++ hw/net/igb_migration.h | 71 ++++++++++++++++++++++++++++++++++ hw/net/igb.c | 2 + hw/net/igb_migration.c | 86 ++++++++++++++++++++++++++++++++++++++++++ hw/net/igbvf.c | 47 ++++++++++++++++++----- hw/net/meson.build | 2 +- 7 files changed, 219 insertions(+), 10 deletions(-) create mode 100644 hw/net/igb_migration.h create mode 100644 hw/net/igb_migration.c diff --git a/MAINTAINERS b/MAINTAINERS index 1312bbd1bd8e..3dd4654c9027 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2822,6 +2822,11 @@ F: tests/functional/x86_64/test_netdev_ethtool.py F: tests/qtest/igb-test.c F: tests/qtest/libqos/igb.c =20 +igb VF migration +M: C=C3=A9dric Le Goater +S: Maintained +F: hw/net/igb_migration.* + eepro100 M: Stefan Weil S: Maintained diff --git a/hw/net/igb_common.h b/hw/net/igb_common.h index b316a5bcfa5c..f0e2529e757b 100644 --- a/hw/net/igb_common.h +++ b/hw/net/igb_common.h @@ -26,7 +26,9 @@ #ifndef HW_NET_IGB_COMMON_H #define HW_NET_IGB_COMMON_H =20 +#include "hw/pci/pci_device.h" #include "igb_regs.h" +#include "igb_migration.h" =20 #define TYPE_IGBVF "igbvf" =20 @@ -154,4 +156,18 @@ uint64_t igb_mmio_read(void *opaque, hwaddr addr, unsi= gned size); void igb_mmio_write(void *opaque, hwaddr addr, uint64_t val, unsigned size= ); void igb_vf_reset(void *opaque, uint16_t vfn); =20 +OBJECT_DECLARE_SIMPLE_TYPE(IgbVfState, IGBVF) + +struct IgbVfState { + PCIDevice parent_obj; + + uint16_t vfn; + bool migration_enabled; + + MemoryRegion mmio; + MemoryRegion msix; + + IgbVfMigState mig; +}; + #endif diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h new file mode 100644 index 000000000000..ae1c85c9d553 --- /dev/null +++ b/hw/net/igb_migration.h @@ -0,0 +1,71 @@ +/* + * QEMU Intel 82576 SR/IOV VF Migration Support + * + * Copyright (c) 2026 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_NET_IGB_MIGRATION_H +#define HW_NET_IGB_MIGRATION_H + +#include "hw/pci/pci_device.h" + +/* + * Migration interface exposed as a DVSEC (Designated Vendor-Specific + * Extended Capability) in VF extended config space. + * + * DVSEC layout at IGB_MIG_DVSEC_OFFSET (0x160): + * + * +0x00 PCIe extended cap header (cap_id=3D0x23, ver=3D1, next) + * +0x04 DVSEC header 1 (len | rev | vendor_id) + * +0x08 DVSEC header 2 (DVSEC ID) + * +0x0A Reserved (padding for DWORD alignment) + * +0x0C CAPS (RO: F_STATE[0]) + * +0x10 CTRL (WO: doorbell command) + * +0x14 STATUS (RO: state[7:0], error_code[15:8]) + * +0x18 BUF_ADDR_LO (RW: shared buffer GPA low) + * +0x1C BUF_ADDR_HI (RW: shared buffer GPA high) + */ + +#define IGB_MIG_DVSEC_OFFSET 0x160 +#define IGB_MIG_DVSEC_SIZE 0x20 +#define IGB_MIG_DVSEC_VER 1 +#define IGB_MIG_DVSEC_ID 1 + +/* Register offsets relative to DVSEC base */ +#define IGB_MIG_CAPS 0x0C +#define IGB_MIG_CTRL 0x10 +#define IGB_MIG_STATUS 0x14 +#define IGB_MIG_BUF_ADDR_LO 0x18 +#define IGB_MIG_BUF_ADDR_HI 0x1C + +/* CAPS register layout */ +#define IGB_MIG_CAP_F_STATE (1u << 0) + +/* STATUS register: state in [7:0], error code [15:8] */ +#define IGB_MIG_STATUS_STATE_MASK 0xFF +#define IGB_MIG_STATUS_ERROR_CODE_SHIFT 8 +#define IGB_MIG_STATUS_ERR(code) \ + ((uint32_t)(code) << IGB_MIG_STATUS_ERROR_CODE_SHIFT) + +/* Device states (based on VFIO migration v2) */ +#define IGB_MIG_STATE_ERROR 0 +#define IGB_MIG_STATE_STOP 1 +#define IGB_MIG_STATE_RUNNING 2 +#define IGB_MIG_STATE_STOP_COPY 3 +#define IGB_MIG_STATE_RESUMING 4 + +typedef struct IgbVfMigState { + uint32_t mig_state; + uint64_t mig_data_buf_addr; +} IgbVfMigState; + +typedef struct IgbVfState IgbVfState; + +bool igbvf_add_migration_dvsec(IgbVfState *s, Error **errp); +uint32_t igbvf_mig_config_read(IgbVfState *s, uint32_t addr, int size); +bool igbvf_mig_config_write(IgbVfState *s, uint32_t addr, uint32_t val, + int size); + +#endif diff --git a/hw/net/igb.c b/hw/net/igb.c index c076807e7110..7268e5473fc3 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -79,6 +79,7 @@ struct IGBState { =20 IGBCore core; bool has_flr; + bool vf_migration; }; =20 #define IGB_CAP_SRIOV_OFFSET (0x160) @@ -597,6 +598,7 @@ static const VMStateDescription igb_vmstate =3D { static const Property igb_properties[] =3D { DEFINE_NIC_PROPERTIES(IGBState, conf), DEFINE_PROP_BOOL("x-pcie-flr-init", IGBState, has_flr, true), + DEFINE_PROP_BOOL("x-vf-migration", IGBState, vf_migration, false), }; =20 static void igb_class_init(ObjectClass *class, const void *data) diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c new file mode 100644 index 000000000000..7ed722f6f0e1 --- /dev/null +++ b/hw/net/igb_migration.c @@ -0,0 +1,86 @@ +/* + * QEMU Intel 82576 SR/IOV VF Migration Support + * + * Copyright (c) 2026 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/pci/pci_device.h" +#include "hw/pci/pcie.h" +#include "igb_common.h" +#include "igb_migration.h" + +bool igbvf_add_migration_dvsec(IgbVfState *s, Error **errp) +{ + PCIDevice *dev =3D PCI_DEVICE(s); + uint16_t offset =3D IGB_MIG_DVSEC_OFFSET; + uint32_t caps; + + pcie_add_capability(dev, PCI_EXT_CAP_ID_DVSEC, 1, offset, + IGB_MIG_DVSEC_SIZE); + + /* + * DVSEC header 1: length[31:20] | rev[19:16] | vendor_id[15:0] + * + * The vendor ID identifies who defined this DVSEC layout, not the + * device vendor. Use the Qumranet/Red Hat ID (0x1AF4) since this + * migration interface is a QEMU-defined protocol, not an Intel + * specification. + */ + pci_set_long(dev->config + offset + 0x4, + (IGB_MIG_DVSEC_SIZE << 20) | + (IGB_MIG_DVSEC_VER << 16) | + PCI_VENDOR_ID_REDHAT_QUMRANET); + + /* DVSEC header 2: DVSEC ID */ + pci_set_word(dev->config + offset + 0x8, IGB_MIG_DVSEC_ID); + + /* CAPS: features (state migration only) */ + caps =3D IGB_MIG_CAP_F_STATE; + pci_set_long(dev->config + offset + IGB_MIG_CAPS, caps); + + /* + * STATUS: initial state is ERROR. Driver should activate the + * control plane by setting the state to RUNNING. + */ + pci_set_long(dev->config + offset + IGB_MIG_STATUS, + IGB_MIG_STATE_ERROR); + + /* BUF_ADDR_LO and BUF_ADDR_HI are writable */ + memset(dev->wmask + offset + IGB_MIG_BUF_ADDR_LO, 0xff, 4); + memset(dev->wmask + offset + IGB_MIG_BUF_ADDR_HI, 0xff, 4); + + return true; +} + +uint32_t igbvf_mig_config_read(IgbVfState *s, uint32_t addr, int size) +{ + PCIDevice *dev =3D PCI_DEVICE(s); + + return pci_default_read_config(dev, addr, size); +} + +bool igbvf_mig_config_write(IgbVfState *s, uint32_t addr, uint32_t val, + int size) +{ + PCIDevice *dev =3D PCI_DEVICE(s); + uint32_t offset =3D addr - IGB_MIG_DVSEC_OFFSET; + + switch (offset) { + case IGB_MIG_CTRL: + /* Command handling will be added in a later commit */ + break; + + case IGB_MIG_BUF_ADDR_LO: + case IGB_MIG_BUF_ADDR_HI: + pci_default_write_config(dev, addr, val, size); + break; + + default: + break; + } + + return true; +} diff --git a/hw/net/igbvf.c b/hw/net/igbvf.c index 9a165c7063ee..bd6debc8310a 100644 --- a/hw/net/igbvf.c +++ b/hw/net/igbvf.c @@ -38,27 +38,21 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/range.h" #include "hw/core/hw-error.h" #include "hw/net/mii.h" #include "hw/pci/pci_device.h" #include "hw/pci/pcie.h" +#include "hw/pci/pcie_sriov.h" #include "hw/pci/msix.h" #include "net/eth.h" #include "net/net.h" #include "igb_common.h" #include "igb_core.h" +#include "igb_migration.h" #include "trace.h" #include "qapi/error.h" =20 -OBJECT_DECLARE_SIMPLE_TYPE(IgbVfState, IGBVF) - -struct IgbVfState { - PCIDevice parent_obj; - - MemoryRegion mmio; - MemoryRegion msix; -}; - static hwaddr vf_to_pf_addr(hwaddr addr, uint16_t vfn, bool write) { switch (addr) { @@ -199,10 +193,35 @@ static hwaddr vf_to_pf_addr(hwaddr addr, uint16_t vfn= , bool write) return HWADDR_MAX; } =20 +static bool igbvf_addr_in_dvsec(uint32_t addr, int len) +{ + return ranges_overlap(addr, len, + IGB_MIG_DVSEC_OFFSET, IGB_MIG_DVSEC_SIZE); +} + +static uint32_t igbvf_read_config(PCIDevice *dev, uint32_t addr, int size) +{ + IgbVfState *s =3D IGBVF(dev); + + if (s->migration_enabled && igbvf_addr_in_dvsec(addr, size)) { + return igbvf_mig_config_read(s, addr, size); + } + + return pci_default_read_config(dev, addr, size); +} + static void igbvf_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len) { + IgbVfState *s =3D IGBVF(dev); + trace_igbvf_write_config(addr, val, len); + + if (s->migration_enabled && igbvf_addr_in_dvsec(addr, len)) { + igbvf_mig_config_write(s, addr, val, len); + return; + } + pci_default_write_config(dev, addr, val, len); if (object_property_get_bool(OBJECT(pcie_sriov_get_pf(dev)), "x-pcie-flr-init", &error_abort)) { @@ -282,6 +301,15 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **= errp) } =20 pcie_ari_init(dev, 0x150); + + if (object_property_get_bool(OBJECT(pcie_sriov_get_pf(dev)), + "x-vf-migration", &error_abort)) { + s->vfn =3D pcie_sriov_vf_number(dev); + s->migration_enabled =3D true; + if (!igbvf_add_migration_dvsec(s, errp)) { + return; + } + } } =20 static void igbvf_qdev_reset_hold(Object *obj, ResetType type) @@ -309,6 +337,7 @@ static void igbvf_class_init(ObjectClass *class, const = void *data) =20 c->realize =3D igbvf_pci_realize; c->exit =3D igbvf_pci_uninit; + c->config_read =3D igbvf_read_config; c->vendor_id =3D PCI_VENDOR_ID_INTEL; c->device_id =3D E1000_DEV_ID_82576_VF; c->revision =3D 1; diff --git a/hw/net/meson.build b/hw/net/meson.build index 63b0e96245fb..a17bef951cfe 100644 --- a/hw/net/meson.build +++ b/hw/net/meson.build @@ -11,7 +11,7 @@ system_ss.add(when: 'CONFIG_E1000_PCI', if_true: files('e= 1000.c', 'e1000x_common system_ss.add(when: 'CONFIG_E1000E_PCI_EXPRESS', if_true: files('net_tx_pk= t.c', 'net_rx_pkt.c')) system_ss.add(when: 'CONFIG_E1000E_PCI_EXPRESS', if_true: files('e1000e.c'= , 'e1000e_core.c', 'e1000x_common.c')) system_ss.add(when: 'CONFIG_IGB_PCI_EXPRESS', if_true: files('net_tx_pkt.c= ', 'net_rx_pkt.c')) -system_ss.add(when: 'CONFIG_IGB_PCI_EXPRESS', if_true: files('igb.c', 'igb= vf.c', 'igb_core.c')) +system_ss.add(when: 'CONFIG_IGB_PCI_EXPRESS', if_true: files('igb.c', 'igb= vf.c', 'igb_core.c', 'igb_migration.c')) system_ss.add(when: 'CONFIG_RTL8139_PCI', if_true: files('rtl8139.c')) system_ss.add(when: 'CONFIG_TULIP', if_true: files('tulip.c')) system_ss.add(when: 'CONFIG_VMXNET3_PCI', if_true: files('net_tx_pkt.c', '= net_rx_pkt.c')) --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967671; cv=none; d=zohomail.com; s=zohoarc; b=DVZW0sKA0QUdgDj8QSz+U7qcIyb22Z2q4OBxTt5lFG4iGj3/l68EDyM7GUhlDCMRfGniIK1ue86t9Ooww7u/5IorJdnk/yL47r66/ULBO3JvePo4j84ejiJc7r73P3l5HEqV4XgsdagSHSHlGB45bm4aHud6G/pUt2Ihw4pyF7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967671; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QVTlceBdGKfLV6pzRmw8MfOPhrOsZ2iY1gRIqg26vGs=; b=lLFTMXThL3gYv4QRXiikbv1QQNMJBfoc69RTKypBDard9oZ5TE8n6FO8BjLOlPpzLinuT58AGlA0doSO6vFB0t1+Raq5olcUAGMW6t1wZr0/pT3Iu8wvuGOjJV8hkOvikIGLp399USMyEK7DEcJiMIwlkHZK2CgwNmPwemT5+/o= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967671795940.7043629063146; Wed, 14 Oct 2026 01:47:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGue1-0005Nh-Ur; Wed, 14 Oct 2026 04:47:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGudp-0005FA-MS for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:18 -0400 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 1xGudo-0004Xp-8B for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:17 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-82-HeOsVXhxP6CLmd9rqzDrLA-1; Wed, 14 Oct 2026 08:47:12 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B9C8318002C8; Wed, 14 Oct 2026 08:47:10 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BF8818001CA; Wed, 14 Oct 2026 08:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967635; 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=QVTlceBdGKfLV6pzRmw8MfOPhrOsZ2iY1gRIqg26vGs=; b=QxHK9CS/VH2uVpE5d0bnTFvXlQ4enCWNNP2XQVtUcj5pR+YVfDlkVF63+aYPvSHY7XLvtV tYLChEsTH0xefIr9eX7oHFBXoUS1k4gHDPILr6AJuonol5GvO8eqrsdVHDlYO5lB4D3wgZ A3tyvHFP4Rv7WPW6kZP5jaMO0175wHE= X-MC-Unique: HeOsVXhxP6CLmd9rqzDrLA-1 X-Mimecast-MFC-AGG-ID: HeOsVXhxP6CLmd9rqzDrLA_1791967631 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 02/17] igb: Add migration blocker when VF migration is enabled Date: Wed, 14 Oct 2026 10:46:40 +0200 Message-ID: <20261014084655.127254-3-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1791967674658158500 When x-vf-migration=3Don, the VF exposes a DVSEC-based migration interface to the L1 guest. If the L0 hypervisor were to migrate the QEMU instance itself, the in-flight VF migration state would be silently lost or corrupted. Register a migration blocker during realize so that any L0 migration attempt is rejected with a clear error message. Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_common.h | 1 + hw/net/igbvf.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/hw/net/igb_common.h b/hw/net/igb_common.h index f0e2529e757b..88e92e093680 100644 --- a/hw/net/igb_common.h +++ b/hw/net/igb_common.h @@ -163,6 +163,7 @@ struct IgbVfState { =20 uint16_t vfn; bool migration_enabled; + Error *migration_blocker; =20 MemoryRegion mmio; MemoryRegion msix; diff --git a/hw/net/igbvf.c b/hw/net/igbvf.c index bd6debc8310a..f2474da9ef2a 100644 --- a/hw/net/igbvf.c +++ b/hw/net/igbvf.c @@ -50,6 +50,7 @@ #include "igb_common.h" #include "igb_core.h" #include "igb_migration.h" +#include "migration/blocker.h" #include "trace.h" #include "qapi/error.h" =20 @@ -309,6 +310,13 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **= errp) if (!igbvf_add_migration_dvsec(s, errp)) { return; } + + error_setg(&s->migration_blocker, + "igbvf: VF migration via DVSEC is enabled (x-vf-migrati= on);" + " L0 migration is not supported"); + if (migrate_add_blocker(&s->migration_blocker, errp) < 0) { + return; + } } } =20 @@ -323,6 +331,7 @@ static void igbvf_pci_uninit(PCIDevice *dev) { IgbVfState *s =3D IGBVF(dev); =20 + migrate_del_blocker(&s->migration_blocker); pcie_aer_exit(dev); pcie_cap_exit(dev); msix_unuse_all_vectors(dev); --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967677; cv=none; d=zohomail.com; s=zohoarc; b=gm9nlglTKY4zCBoaRXm1sNE4Pwhk3BJwa3HWDyzdWkBik6LF0iKQWobAoGJY5EFZRN39ZdqbBdWuskKzk4AwIHMEBk2PpPt6tRykX61OTkRu5VwXySubkhK3n9rYX7+dR/yZEExOy4Q7EJL6xIHe48pctbCkuf2ZdT9InEqzkg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967677; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kn5ZMZk6eONf2Ptxa2axdEu8YJ5ExnL3tTNQ7WcxxXA=; b=OjxvG1XC7b7i1qb7LQHG//aB/Ux+QkKrijqOjm2ZtR1/5CauO8E0bELqCIv6MuvbDrdgvmukdMFgmWIXzToCc78BRWOUWuJZNRcrSH3BbftNkE2kV2afjt+mLZSOa/lR1W7tNcO/8/UWQvkeQegt8xHftxNJ+36S5yCTMxrsLIY= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967677633988.8301479928182; Wed, 14 Oct 2026 01:47:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGue5-0005QJ-Oa; Wed, 14 Oct 2026 04:47:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGudx-0005LZ-DN for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:26 -0400 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 1xGudv-0004Y9-C3 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:25 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-D8nvQTdjPcurx0kbbSF7KQ-1; Wed, 14 Oct 2026 08:47:15 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B561018005B2; Wed, 14 Oct 2026 08:47:13 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3826C1803A40; Wed, 14 Oct 2026 08:47:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967642; 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=kn5ZMZk6eONf2Ptxa2axdEu8YJ5ExnL3tTNQ7WcxxXA=; b=GZCuiZwQ1bxHFpNT4Xi7PLOzUyy3aFrejcaqPVm6FY0upDA2MlDFf35AIe+Su0eJTB6Id0 HI4pNlhnvyfUUBEkAXh1eqLW/0eRloTlXPcYL2nUZosHPoOPCziLP6u6tu2DLa97DWcV82 ATRgTgxjOSesiWgQudN9Ug9Aqs2Q+tw= X-MC-Unique: D8nvQTdjPcurx0kbbSF7KQ-1 X-Mimecast-MFC-AGG-ID: D8nvQTdjPcurx0kbbSF7KQ_1791967634 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 03/17] igb: Add migration state machine via extended config space Date: Wed, 14 Oct 2026 10:46:41 +0200 Message-ID: <20261014084655.127254-4-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-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: qemu development 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: 1791967678880158500 Implement the VFIO migration v2 state machine and command dispatch through the CTRL doorbell register in the DVSEC capability. Add three CTRL commands: - SET_STATE: transitions follow the VFIO migration protocol RUNNING <-> STOP STOP <-> STOP_COPY STOP <-> RESUMING ERROR -> STOP - SAVE: DMA-writes the device state to a guest buffer - LOAD: DMA-reads it back Add a DATA_SIZE register to report the state blob size. The save/load stubs are filled in by the next patch. AI-used-for: code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.h | 25 ++++- hw/net/igb_migration.c | 237 ++++++++++++++++++++++++++++++++++++++++- hw/net/trace-events | 8 ++ 3 files changed, 268 insertions(+), 2 deletions(-) diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index ae1c85c9d553..34d643854a28 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -26,10 +26,11 @@ * +0x14 STATUS (RO: state[7:0], error_code[15:8]) * +0x18 BUF_ADDR_LO (RW: shared buffer GPA low) * +0x1C BUF_ADDR_HI (RW: shared buffer GPA high) + * +0x20 DATA_SIZE (RO: state blob size in bytes) */ =20 #define IGB_MIG_DVSEC_OFFSET 0x160 -#define IGB_MIG_DVSEC_SIZE 0x20 +#define IGB_MIG_DVSEC_SIZE 0x24 #define IGB_MIG_DVSEC_VER 1 #define IGB_MIG_DVSEC_ID 1 =20 @@ -39,10 +40,20 @@ #define IGB_MIG_STATUS 0x14 #define IGB_MIG_BUF_ADDR_LO 0x18 #define IGB_MIG_BUF_ADDR_HI 0x1C +#define IGB_MIG_DATA_SIZE 0x20 =20 /* CAPS register layout */ #define IGB_MIG_CAP_F_STATE (1u << 0) =20 +/* CTRL register: command in [7:0] */ +#define IGB_MIG_CTRL_CMD_MASK 0xFF +#define IGB_MIG_CTRL_ARG_SHIFT 8 + +/* CTRL commands */ +#define IGB_MIG_CMD_SET_STATE 1 +#define IGB_MIG_CMD_SAVE 2 +#define IGB_MIG_CMD_LOAD 3 + /* STATUS register: state in [7:0], error code [15:8] */ #define IGB_MIG_STATUS_STATE_MASK 0xFF #define IGB_MIG_STATUS_ERROR_CODE_SHIFT 8 @@ -56,8 +67,20 @@ #define IGB_MIG_STATE_STOP_COPY 3 #define IGB_MIG_STATE_RESUMING 4 =20 +/* Error codes */ +#define IGB_MIG_ERR_UNK_CMD 1 +#define IGB_MIG_ERR_BAD_STATE 2 +#define IGB_MIG_ERR_NO_BUFFER 3 +#define IGB_MIG_ERR_DMA_FAILED 4 +#define IGB_MIG_ERR_BAD_SIZE 5 + +/* Shared buffer constants */ +#define IGB_VF_STATE_MAX_SIZE 4096 + typedef struct IgbVfMigState { uint32_t mig_state; + uint32_t mig_data[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + uint32_t mig_data_size; uint64_t mig_data_buf_addr; } IgbVfMigState; =20 diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 7ed722f6f0e1..174df22232a5 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -7,10 +7,231 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/log.h" #include "hw/pci/pci_device.h" #include "hw/pci/pcie.h" #include "igb_common.h" #include "igb_migration.h" +#include "system/address-spaces.h" +#include "trace.h" + +/* + * Per-VF state serialization / deserialization + */ + +static int igb_core_vf_save_state(IgbVfState *s, void *buf, size_t buf_siz= e) +{ + int size =3D 0; + + trace_igbvf_mig_save_state(s->vfn, size); + return size; +} + +static int igb_core_vf_max_data_size(IgbVfState *s) +{ + return sizeof(s->mig.mig_data); +} + +static int igb_core_vf_load_state(IgbVfState *s, const void *buf, size_t s= ize) +{ + trace_igbvf_mig_load_state(s->vfn, (uint32_t)size); + return 0; +} + +static int igbvf_mig_load(IgbVfState *s, const void *buf, size_t size) +{ + int ret; + + ret =3D igb_core_vf_load_state(s, buf, size); + if (ret < 0) { + return ret; + } + + return 0; +} + +/* + * Migration command handlers + */ + +static void igbvf_mig_update_data_size(IgbVfState *s, uint32_t size) +{ + IgbVfMigState *ms =3D &s->mig; + + g_assert(size <=3D IGB_VF_STATE_MAX_SIZE); + ms->mig_data_size =3D size; + pci_set_long(PCI_DEVICE(s)->config + + IGB_MIG_DVSEC_OFFSET + IGB_MIG_DATA_SIZE, size); +} + +static uint8_t igbvf_mig_cmd_save(IgbVfState *s) +{ + IgbVfMigState *ms =3D &s->mig; + MemTxResult r; + int ret; + + if (ms->mig_state !=3D IGB_MIG_STATE_STOP_COPY) { + return IGB_MIG_ERR_BAD_STATE; + } + + if (!ms->mig_data_buf_addr) { + return IGB_MIG_ERR_NO_BUFFER; + } + + ret =3D igb_core_vf_save_state(s, ms->mig_data, sizeof(ms->mig_data)); + if (ret < 0) { + return -ret; + } + igbvf_mig_update_data_size(s, ret); + + r =3D address_space_write(&address_space_memory, ms->mig_data_buf_addr, + MEMTXATTRS_UNSPECIFIED, + ms->mig_data, ms->mig_data_size); + if (r !=3D MEMTX_OK) { + return IGB_MIG_ERR_DMA_FAILED; + } + + return 0; +} + +static uint8_t igbvf_mig_cmd_load(IgbVfState *s, uint32_t data_size) +{ + IgbVfMigState *ms =3D &s->mig; + MemTxResult r; + int ret; + + if (ms->mig_state !=3D IGB_MIG_STATE_RESUMING) { + return IGB_MIG_ERR_BAD_STATE; + } + + if (data_size =3D=3D 0 || data_size > sizeof(ms->mig_data)) { + return IGB_MIG_ERR_BAD_SIZE; + } + + igbvf_mig_update_data_size(s, data_size); + + if (!ms->mig_data_buf_addr) { + return IGB_MIG_ERR_NO_BUFFER; + } + + r =3D address_space_read(&address_space_memory, ms->mig_data_buf_addr, + MEMTXATTRS_UNSPECIFIED, + ms->mig_data, ms->mig_data_size); + if (r !=3D MEMTX_OK) { + return IGB_MIG_ERR_DMA_FAILED; + } + + ret =3D igbvf_mig_load(s, ms->mig_data, ms->mig_data_size); + if (ret < 0) { + return -ret; + } + + return 0; +} + +static uint8_t igbvf_mig_set_state(IgbVfState *s, uint32_t new_state) +{ + IgbVfMigState *ms =3D &s->mig; + uint32_t old =3D ms->mig_state; + int ret; + + switch (new_state) { + case IGB_MIG_STATE_STOP: + if (old !=3D IGB_MIG_STATE_RUNNING && + old !=3D IGB_MIG_STATE_STOP_COPY && + old !=3D IGB_MIG_STATE_RESUMING && + old !=3D IGB_MIG_STATE_ERROR) { + return IGB_MIG_ERR_BAD_STATE; + } + /* Restore DATA_SIZE to default max */ + igbvf_mig_update_data_size(s, igb_core_vf_max_data_size(s)); + break; + + case IGB_MIG_STATE_RUNNING: + if (old !=3D IGB_MIG_STATE_STOP) { + return IGB_MIG_ERR_BAD_STATE; + } + break; + + case IGB_MIG_STATE_STOP_COPY: + if (old !=3D IGB_MIG_STATE_STOP) { + return IGB_MIG_ERR_BAD_STATE; + } + ret =3D igb_core_vf_save_state(s, ms->mig_data, sizeof(ms->mig_dat= a)); + if (ret < 0) { + return -ret; + } + igbvf_mig_update_data_size(s, ret); + break; + + case IGB_MIG_STATE_RESUMING: + if (old !=3D IGB_MIG_STATE_STOP) { + return IGB_MIG_ERR_BAD_STATE; + } + memset(ms->mig_data, 0, sizeof(ms->mig_data)); + igbvf_mig_update_data_size(s, 0); + break; + + default: + return IGB_MIG_ERR_BAD_STATE; + } + + ms->mig_state =3D new_state; + trace_igbvf_mig_set_state(s->vfn, old, new_state); + return 0; +} + +static void igbvf_mig_update_status(IgbVfState *s, uint8_t err) +{ + IgbVfMigState *ms =3D &s->mig; + PCIDevice *dev =3D PCI_DEVICE(s); + uint32_t status; + + status =3D ms->mig_state & IGB_MIG_STATUS_STATE_MASK; + + if (err) { + ms->mig_state =3D IGB_MIG_STATE_ERROR; + status =3D IGB_MIG_STATE_ERROR | IGB_MIG_STATUS_ERR(err); + } + + pci_set_long(dev->config + IGB_MIG_DVSEC_OFFSET + IGB_MIG_STATUS, stat= us); + trace_igbvf_mig_status(s->vfn, status); +} + +static void igbvf_mig_cmd_ctrl(IgbVfState *s, uint32_t val) +{ + IgbVfMigState *ms =3D &s->mig; + uint32_t cmd =3D val & IGB_MIG_CTRL_CMD_MASK; + uint32_t arg =3D val >> IGB_MIG_CTRL_ARG_SHIFT; + uint8_t err =3D 0; + + trace_igbvf_mig_cmd(s->vfn, cmd, arg, ms->mig_state); + + switch (cmd) { + case IGB_MIG_CMD_SET_STATE: + err =3D igbvf_mig_set_state(s, arg); + break; + + case IGB_MIG_CMD_SAVE: + err =3D igbvf_mig_cmd_save(s); + break; + + case IGB_MIG_CMD_LOAD: + err =3D igbvf_mig_cmd_load(s, arg); + break; + + default: + err =3D IGB_MIG_ERR_UNK_CMD; + break; + } + + if (err) { + qemu_log_mask(LOG_GUEST_ERROR, + "igbvf: VF%u CTRL cmd %u failed (error %u)\n", + s->vfn, cmd, err); + } + igbvf_mig_update_status(s, err); +} =20 bool igbvf_add_migration_dvsec(IgbVfState *s, Error **errp) { @@ -52,6 +273,9 @@ bool igbvf_add_migration_dvsec(IgbVfState *s, Error **er= rp) memset(dev->wmask + offset + IGB_MIG_BUF_ADDR_LO, 0xff, 4); memset(dev->wmask + offset + IGB_MIG_BUF_ADDR_HI, 0xff, 4); =20 + /* DATA_SIZE defaults to max; updated per command */ + igbvf_mig_update_data_size(s, igb_core_vf_max_data_size(s)); + return true; } =20 @@ -62,6 +286,16 @@ uint32_t igbvf_mig_config_read(IgbVfState *s, uint32_t = addr, int size) return pci_default_read_config(dev, addr, size); } =20 +static uint64_t igbvf_mig_get_buf_addr(IgbVfState *s) +{ + PCIDevice *dev =3D PCI_DEVICE(s); + uint32_t lo, hi; + + lo =3D pci_get_long(dev->config + IGB_MIG_DVSEC_OFFSET + IGB_MIG_BUF_A= DDR_LO); + hi =3D pci_get_long(dev->config + IGB_MIG_DVSEC_OFFSET + IGB_MIG_BUF_A= DDR_HI); + return ((uint64_t)hi << 32) | lo; +} + bool igbvf_mig_config_write(IgbVfState *s, uint32_t addr, uint32_t val, int size) { @@ -70,7 +304,8 @@ bool igbvf_mig_config_write(IgbVfState *s, uint32_t addr= , uint32_t val, =20 switch (offset) { case IGB_MIG_CTRL: - /* Command handling will be added in a later commit */ + s->mig.mig_data_buf_addr =3D igbvf_mig_get_buf_addr(s); + igbvf_mig_cmd_ctrl(s, val); break; =20 case IGB_MIG_BUF_ADDR_LO: diff --git a/hw/net/trace-events b/hw/net/trace-events index 001a20b0e2ac..23f6dbcfed82 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -295,6 +295,14 @@ igb_wrn_rx_desc_modes_not_supp(int desc_type) "Not sup= ported descriptor type: %d # igbvf.c igbvf_wrn_io_addr_unknown(uint64_t addr) "IO unknown register 0x%"PRIx64 =20 +# igb_migration.c +igbvf_mig_cmd(uint16_t vfn, uint32_t cmd, uint32_t arg, uint32_t state) "V= F%u: cmd %u arg %u (mig_state=3D%u)" +igbvf_mig_status(uint16_t vfn, uint32_t status) "VF%u: status 0x%x" +igbvf_mig_set_state(uint16_t vfn, uint32_t old_state, uint32_t new_state) = "VF%u: state %u -> %u" +igbvf_mig_save_state(uint16_t vfn, uint32_t size) "VF%u: saved %u bytes of= device state" +igbvf_mig_load_state(uint16_t vfn, uint32_t size) "VF%u: loaded %u bytes o= f device state" +igbvf_mig_reset(uint16_t vfn) "VF%u: migration state reset" + # spapr_llan.c spapr_vlan_get_rx_bd_from_pool_found(int pool, int32_t count, uint32_t rx_= bufs) "pool=3D%d count=3D%"PRId32" rxbufs=3D%"PRIu32 spapr_vlan_get_rx_bd_from_page(int buf_ptr, uint64_t bd) "use_buf_ptr=3D%d= bd=3D0x%016"PRIx64 --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967687; cv=none; d=zohomail.com; s=zohoarc; b=OZ8UgDkDnSDYVwThwuLPYO2wXktGbGNRYGh2Kwf0FxZw+FkmFTiUAoeXWCRxj9ZyiFXsxRptV8YNVrb7tKWTo6MmNkIXy1c39BZDywsZJOYe/Dx4avDASbEz11BWjST0IHzQuzZav8NHVknK31JT1GuAPoTvKe8r6kA9HAWcDzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967687; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MNcN8qWHBnBxaCUAyi9IZQKU123r3Q1m9fzcP/y+4hY=; b=VFEW0dsxMD3WSAGoX2K3PUt6qiZzJSbW1ZoAThSNB9eVCBvq24rfq1kT0exYoGyrVyiwpJ5RJD1sWy3szWdu/uGpWYU3zaSpzqw5Vb1bt92w73Juxl8yupb6lYDzR4qQd0G0AQmTKssoskM0cxCsSLt28x/Y80nLdG8FBPuJVTg= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967687743729.8198810510216; Wed, 14 Oct 2026 01:48:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGue9-0005UM-8y; Wed, 14 Oct 2026 04:47:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGue0-0005Nw-92 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:29 -0400 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 1xGudy-0004YS-KT for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:28 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-E6Hpcus8OIOHyHBQnPJqRw-1; Wed, 14 Oct 2026 08:47:18 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B748E195609E; Wed, 14 Oct 2026 08:47:16 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3249B1800495; Wed, 14 Oct 2026 08:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967645; 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=MNcN8qWHBnBxaCUAyi9IZQKU123r3Q1m9fzcP/y+4hY=; b=VL1dQcKVM8vr0yNX8EVogZKYFeB1uFw8AqB5lmqumNcwmItAAlWZuUh1epai8/LdrMpKIS SNHWaMnslxesr4+bzbcBIvbe5xVRP2ochyI7Z42v3M8meS9E5b3tPFwBxR48Rb6V5y3hWU zST0tBeZBcD6LH1cPp1HTq5gW4D70zM= X-MC-Unique: E6Hpcus8OIOHyHBQnPJqRw-1 X-Mimecast-MFC-AGG-ID: E6Hpcus8OIOHyHBQnPJqRw_1791967637 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 04/17] igb: Add VF state serialization for live migration Date: Wed, 14 Oct 2026 10:46:42 +0200 Message-ID: <20261014084655.127254-5-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967688897158500 Add the migration blob format and the SAVE/LOAD command plumbing. Define IgbMigBlob with a header (magic, version, VF number) and add error codes for blob validation (BAD_MAGIC, BAD_VERSION, BAD_VFN, BAD_DATA). On save, fill the header and report the blob size via DATA_SIZE. On load, validate the header fields before touching any device state. Subsequent patches extend the blob with register, TX context, RA, and VLVF substates. AI-used-for: code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.h | 4 +++ hw/net/igb_migration.c | 55 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index 34d643854a28..d05252992f9e 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -73,6 +73,10 @@ #define IGB_MIG_ERR_NO_BUFFER 3 #define IGB_MIG_ERR_DMA_FAILED 4 #define IGB_MIG_ERR_BAD_SIZE 5 +#define IGB_MIG_ERR_BAD_MAGIC 6 +#define IGB_MIG_ERR_BAD_VERSION 7 +#define IGB_MIG_ERR_BAD_VFN 8 +#define IGB_MIG_ERR_BAD_DATA 9 =20 /* Shared buffer constants */ #define IGB_VF_STATE_MAX_SIZE 4096 diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 174df22232a5..de982909bbf2 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -19,9 +19,36 @@ * Per-VF state serialization / deserialization */ =20 +#define IGB_MIG_BLOB_MAGIC 0x4D494742 /* "MIGB" */ +#define IGB_MIG_BLOB_VERSION 1 + +typedef struct IgbMigBlob { + uint32_t magic; + uint32_t version; + uint32_t vfn; +} IgbMigBlob; + +#define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) + +QEMU_BUILD_BUG_ON(IGB_MIG_BLOB_SIZE > IGB_VF_STATE_MAX_SIZE); + + static int igb_core_vf_save_state(IgbVfState *s, void *buf, size_t buf_siz= e) { - int size =3D 0; + int size =3D IGB_MIG_BLOB_SIZE; + IgbMigBlob *blob =3D buf; + + if (!buf) { + return size; + } + + if (size > buf_size) { + return -IGB_MIG_ERR_BAD_SIZE; + } + + blob->magic =3D cpu_to_le32(IGB_MIG_BLOB_MAGIC); + blob->version =3D cpu_to_le32(IGB_MIG_BLOB_VERSION); + blob->vfn =3D cpu_to_le32(s->vfn); =20 trace_igbvf_mig_save_state(s->vfn, size); return size; @@ -29,11 +56,35 @@ static int igb_core_vf_save_state(IgbVfState *s, void *= buf, size_t buf_size) =20 static int igb_core_vf_max_data_size(IgbVfState *s) { - return sizeof(s->mig.mig_data); + int size =3D igb_core_vf_save_state(s, NULL, 0); + + g_assert(size > 0 && size <=3D IGB_VF_STATE_MAX_SIZE); + return size; } =20 static int igb_core_vf_load_state(IgbVfState *s, const void *buf, size_t s= ize) { + const IgbMigBlob *blob =3D buf; + uint32_t magic, version, saved_vfn; + + /* Validate blob header */ + if (size < IGB_MIG_BLOB_SIZE) { + return -IGB_MIG_ERR_BAD_SIZE; + } + + magic =3D le32_to_cpu(blob->magic); + version =3D le32_to_cpu(blob->version); + saved_vfn =3D le32_to_cpu(blob->vfn); + if (magic !=3D IGB_MIG_BLOB_MAGIC) { + return -IGB_MIG_ERR_BAD_MAGIC; + } + if (version !=3D IGB_MIG_BLOB_VERSION) { + return -IGB_MIG_ERR_BAD_VERSION; + } + if (saved_vfn !=3D s->vfn) { + return -IGB_MIG_ERR_BAD_VFN; + } + trace_igbvf_mig_load_state(s->vfn, (uint32_t)size); return 0; } --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967788; cv=none; d=zohomail.com; s=zohoarc; b=fFQJJdd1mG9JB7WpYeohMNpVsjuw4FrUeJzLRRuxOLeEFgttG17oEC826HTOtoUTYD9pGqK6ypWEo9WprT9wFCD0O1SUNA/E+UiNPnyAk4Qsi/bk5/Nsre+KKOc2+VRboF3i3aXY8IZtn5QeMveV9ooXyQHXBQRwYt/nmgHejts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967788; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZlevP+DQ07XzyAne81NaqJe5jnhgHMpuZdVBuSnyelE=; b=narkjL5i5oP1sjmT6ITgOUzgvRVzN2F8ancHChjMNRuJtusHo+BvzIqxeOK7tRlpRylTRfy/tD+lYTTWuAMNffRm1sXymLBasTPy6inU0YuFG7tgwWaGB421rlWWS2t95WFitAq0XGQLGPbPdvd2zqngAFp1kR3YzUz9KucDOrQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967788010195.86541042268254; Wed, 14 Oct 2026 01:49:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGue6-0005Qa-DO; Wed, 14 Oct 2026 04:47:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGue0-0005Nx-I9 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:29 -0400 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 1xGudy-0004YF-Jy for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:28 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-h-eZ8RY9P5CnaGsDxh6Wbw-1; Wed, 14 Oct 2026 08:47:20 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 825F519560B4; Wed, 14 Oct 2026 08:47:19 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 34D5B1800446; Wed, 14 Oct 2026 08:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967644; 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=ZlevP+DQ07XzyAne81NaqJe5jnhgHMpuZdVBuSnyelE=; b=QgYkOmesbWPsnHF41uRh3EUFsytxilFV6AW2QuZSoZG7InoJtP7Z9dbDnHMMgrIVfvZov7 z5rdpOjA5WvL35zmrWWfRJQPOLUpMd1UxQ+kZrWoq7h9uZTEqk4z/SOZcJZPwvQ3mF5K0v OdoMZ3vN4G8IyBLxP95HJzTnvGZ4ESw= X-MC-Unique: h-eZ8RY9P5CnaGsDxh6Wbw-1 X-Mimecast-MFC-AGG-ID: h-eZ8RY9P5CnaGsDxh6Wbw_1791967639 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 05/17] igb: Add VF register state serialization Date: Wed, 14 Oct 2026 10:46:43 +0200 Message-ID: <20261014084655.127254-6-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967788914158500 Add save/load support for the per-VF register slice: control, interrupt (PVT), statistics, mailbox control, per-VF config (VMOLR/VMVIR/PSRTYPE), interrupt routing (VTIVAR), throttle registers (EITR), and the two RX/TX queue register sets. The register list is built dynamically by igb_vf_reg_list() so the load path can validate that the blob contains exactly the expected offsets, rejecting corrupted or version-mismatched blobs before any state is modified. Expose igb_pf_get_core() so the migration code in igbvf can reach the PF's IGBCore. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_core.h | 2 + hw/net/igb.c | 5 ++ hw/net/igb_migration.c | 170 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 176 insertions(+), 1 deletion(-) diff --git a/hw/net/igb_core.h b/hw/net/igb_core.h index d70b54e318f1..60724e2824ab 100644 --- a/hw/net/igb_core.h +++ b/hw/net/igb_core.h @@ -143,4 +143,6 @@ igb_receive_iov(IGBCore *core, const struct iovec *iov,= int iovcnt); void igb_start_recv(IGBCore *core); =20 +IGBCore *igb_pf_get_core(void *pf); + #endif diff --git a/hw/net/igb.c b/hw/net/igb.c index 7268e5473fc3..f39f2bc3a04e 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -133,6 +133,11 @@ void igb_vf_reset(void *opaque, uint16_t vfn) igb_core_vf_reset(&s->core, vfn); } =20 +IGBCore *igb_pf_get_core(void *pf) +{ + return &IGB(pf)->core; +} + static bool igb_io_get_reg_index(IGBState *s, uint32_t *idx) { diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index de982909bbf2..0c21a5e45f32 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -10,11 +10,19 @@ #include "qemu/log.h" #include "hw/pci/pci_device.h" #include "hw/pci/pcie.h" +#include "net/eth.h" +#include "net/net.h" #include "igb_common.h" +#include "igb_core.h" #include "igb_migration.h" #include "system/address-spaces.h" #include "trace.h" =20 +static IGBCore *igbvf_get_core(IgbVfState *s) +{ + return igb_pf_get_core(pcie_sriov_get_pf(PCI_DEVICE(s))); +} + /* * Per-VF state serialization / deserialization */ @@ -22,21 +30,125 @@ #define IGB_MIG_BLOB_MAGIC 0x4D494742 /* "MIGB" */ #define IGB_MIG_BLOB_VERSION 1 =20 +typedef struct IgbMigRegPair { + uint32_t offset; + uint32_t value; +} IgbMigRegPair; + +#define IGB_VF_MAX_FIXED_REGS 64 + typedef struct IgbMigBlob { uint32_t magic; uint32_t version; uint32_t vfn; + uint32_t num_regs; + IgbMigRegPair regs[IGB_VF_MAX_FIXED_REGS]; } IgbMigBlob; =20 #define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) =20 QEMU_BUILD_BUG_ON(IGB_MIG_BLOB_SIZE > IGB_VF_STATE_MAX_SIZE); =20 +/* Register offsets that constitute a VF's state slice */ +static int igb_vf_reg_list(uint16_t vfn, uint32_t *offsets) +{ + int n =3D 0; + int q0 =3D vfn; + int q1 =3D vfn + IGB_NUM_VM_POOLS; + + /* Per-VF control and interrupt registers */ + offsets[n++] =3D E1000_PVTCTRL(vfn) >> 2; + offsets[n++] =3D E1000_PVTEICS(vfn) >> 2; + offsets[n++] =3D E1000_PVTEIMC(vfn) >> 2; + offsets[n++] =3D E1000_PVTEICR(vfn) >> 2; + + /* Per-VF statistics */ + offsets[n++] =3D E1000_PVFGPRC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGPTC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGORC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGOTC(vfn) >> 2; + offsets[n++] =3D E1000_PVFMPRC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGPRLBC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGPTLBC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGORLBC(vfn) >> 2; + offsets[n++] =3D E1000_PVFGOTLBC(vfn) >> 2; + + /* + * Mailbox control registers only - the 16-dword payload buffer + * (VMBMEM) is transient and drained on quiesce. + */ + offsets[n++] =3D E1000_V2PMAILBOX(vfn) >> 2; + offsets[n++] =3D E1000_P2VMAILBOX(vfn) >> 2; + + /* Per-VF config */ + offsets[n++] =3D E1000_VMOLR(vfn) >> 2; + offsets[n++] =3D E1000_VMVIR(vfn) >> 2; + offsets[n++] =3D E1000_PSRTYPE(vfn) >> 2; + + /* + * VF receive addresses (RA/RA2) are saved dynamically in + * igb_core_vf_save_state by scanning for entries whose pool + * bits match this VF - the PF driver chooses the RA slot. + */ + + /* Interrupt routing */ + offsets[n++] =3D (E1000_VTIVAR + vfn * 4) >> 2; + offsets[n++] =3D (E1000_VTIVAR_MISC + vfn * 4) >> 2; + + /* + * EITR (Extended Interrupt Throttle Register) - 3 vectors per VF. + * Each VF has 3 MSI-X vectors, each with its own EITR controlling + * interrupt coalescing. Without saving these, interrupt + * throttling resets to zero after migration which can cause + * interrupt storms or latency changes. VF N uses PF EITR indices + * (22 - N*3) .. (24 - N*3). + */ + { + int eitr_base =3D 22 - vfn * 3; + offsets[n++] =3D E1000_EITR(eitr_base) >> 2; + offsets[n++] =3D E1000_EITR(eitr_base + 1) >> 2; + offsets[n++] =3D E1000_EITR(eitr_base + 2) >> 2; + } + + /* RX and TX queue registers for queues q0 and q1 */ +#define ADD_QUEUE_REGS(q) do { \ + offsets[n++] =3D E1000_RDBAL(q) >> 2; \ + offsets[n++] =3D E1000_RDBAH(q) >> 2; \ + offsets[n++] =3D E1000_RDLEN(q) >> 2; \ + offsets[n++] =3D E1000_SRRCTL(q) >> 2; \ + offsets[n++] =3D E1000_RDH(q) >> 2; \ + offsets[n++] =3D E1000_RDT(q) >> 2; \ + offsets[n++] =3D E1000_RXDCTL(q) >> 2; \ + offsets[n++] =3D E1000_RXCTL(q) >> 2; \ + offsets[n++] =3D E1000_RQDPC(q) >> 2; \ + offsets[n++] =3D E1000_TDBAL(q) >> 2; \ + offsets[n++] =3D E1000_TDBAH(q) >> 2; \ + offsets[n++] =3D E1000_TDLEN(q) >> 2; \ + offsets[n++] =3D E1000_TDH(q) >> 2; \ + offsets[n++] =3D E1000_TDT(q) >> 2; \ + offsets[n++] =3D E1000_TXDCTL(q) >> 2; \ + offsets[n++] =3D E1000_TXCTL(q) >> 2; \ + offsets[n++] =3D E1000_TDWBAL(q) >> 2; \ + offsets[n++] =3D E1000_TDWBAH(q) >> 2; \ +} while (0) + + ADD_QUEUE_REGS(q0); + ADD_QUEUE_REGS(q1); +#undef ADD_QUEUE_REGS + + g_assert(n <=3D IGB_VF_MAX_FIXED_REGS); + return n; +} =20 static int igb_core_vf_save_state(IgbVfState *s, void *buf, size_t buf_siz= e) { int size =3D IGB_MIG_BLOB_SIZE; + IGBCore *core =3D igbvf_get_core(s); IgbMigBlob *blob =3D buf; + uint32_t offsets[IGB_VF_MAX_FIXED_REGS]; + int num_regs; + + num_regs =3D igb_vf_reg_list(s->vfn, offsets); =20 if (!buf) { return size; @@ -50,6 +162,12 @@ static int igb_core_vf_save_state(IgbVfState *s, void *= buf, size_t buf_size) blob->version =3D cpu_to_le32(IGB_MIG_BLOB_VERSION); blob->vfn =3D cpu_to_le32(s->vfn); =20 + blob->num_regs =3D cpu_to_le32(num_regs); + for (int i =3D 0; i < num_regs; i++) { + blob->regs[i].offset =3D cpu_to_le32(offsets[i]); + blob->regs[i].value =3D cpu_to_le32(core->mac[offsets[i]]); + } + trace_igbvf_mig_save_state(s->vfn, size); return size; } @@ -62,10 +180,34 @@ static int igb_core_vf_max_data_size(IgbVfState *s) return size; } =20 +static bool igb_core_vf_validate_regs(uint16_t vfn, + const IgbMigRegPair *regs, + uint32_t num_regs) +{ + uint32_t expected[IGB_VF_MAX_FIXED_REGS]; + int num_expected; + + if (num_regs > IGB_VF_MAX_FIXED_REGS) { + return false; + } + + num_expected =3D igb_vf_reg_list(vfn, expected); + if (num_regs !=3D num_expected) { + return false; + } + for (int i =3D 0; i < num_regs; i++) { + if (le32_to_cpu(regs[i].offset) !=3D expected[i]) { + return false; + } + } + return true; +} + static int igb_core_vf_load_state(IgbVfState *s, const void *buf, size_t s= ize) { + IGBCore *core =3D igbvf_get_core(s); const IgbMigBlob *blob =3D buf; - uint32_t magic, version, saved_vfn; + uint32_t magic, version, saved_vfn, num_regs; =20 /* Validate blob header */ if (size < IGB_MIG_BLOB_SIZE) { @@ -85,6 +227,32 @@ static int igb_core_vf_load_state(IgbVfState *s, const = void *buf, size_t size) return -IGB_MIG_ERR_BAD_VFN; } =20 + /* + * Phase 1: Validate blob state before modifying any core state. + * A malformed blob must not leave the device partially updated. + */ + num_regs =3D le32_to_cpu(blob->num_regs); + if (!igb_core_vf_validate_regs(s->vfn, blob->regs, num_regs)) { + return -IGB_MIG_ERR_BAD_DATA; + } + + /* + * Phase 2: Apply state. All offsets and placements are + * validated; writes cannot fail. + */ + for (int i =3D 0; i < num_regs; i++) { + uint32_t offset =3D le32_to_cpu(blob->regs[i].offset); + uint32_t value =3D le32_to_cpu(blob->regs[i].value); + + core->mac[offset] =3D value; + + /* Replicate igb_set_eitr() side effect bypassed by direct write */ + if (offset >=3D EITR0 && offset < EITR0 + IGB_INTR_NUM) { + core->eitr_guest_value[offset - EITR0] =3D + value & ~E1000_EITR_CNT_IGNR; + } + } + trace_igbvf_mig_load_state(s->vfn, (uint32_t)size); return 0; } --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967795; cv=none; d=zohomail.com; s=zohoarc; b=QWFqvu3Q0ohUft1P3va8peR6cFbRhSkkdYgRBE1TX+raaZXDKH02c1/a6E6urtitvCXfyoLdNiEq/hHpt7xu8arN3SRcpxUtHqtp9dNjToNvdXSjfSOB56O/eM1hHrR6C+0WQttC94TxNJZ1matl4Kk/MZbZ08OBIp9It1BqBQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967795; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TfLjsqPCvOp1hw/c9bS1s68B+V5vmUAntXKrnqamUFY=; b=Qc/v8o0pqjVk0Kjx5ur6Khc9AqbmqW7psP/cLQlnllhW02J+A1/2s1QUJ/myF79gLhoSmyWeQXdTSTaBhsXPFEVqztYZVKwaxx1cjEdieNQaCKLIeATsWqpAIFOIQ7wKsltD4NDDs85B7FfWNAha5SojAQnJ59/l6lUn5k2qerk= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967795178458.70303379935206; Wed, 14 Oct 2026 01:49:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGue6-0005RI-VT; Wed, 14 Oct 2026 04:47:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGue1-0005Nz-Lf for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:29 -0400 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 1xGudy-0004YQ-KW for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:29 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-8gnq-wtWMx6E3V2r1BdQCg-1; Wed, 14 Oct 2026 08:47:23 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A8B4D180034C; Wed, 14 Oct 2026 08:47:22 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F42251800446; Wed, 14 Oct 2026 08:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967645; 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=TfLjsqPCvOp1hw/c9bS1s68B+V5vmUAntXKrnqamUFY=; b=IvY04w1iiFnbqAzdDJYMN119yOuxacxKdQ2jhRlgiOtsmg2E7bkTh9kxYgJQV5yfsz1JuB FTW9JnxrK2B5xMImF/ZgJ/6GQwTCkHMA3bpR/kgMMZ9OH1gcVslEWJCEJT0tDZaaRW3RHG 2HM+9jgcDJxs0fG3i0yH1NMhb/J2Xuk= X-MC-Unique: 8gnq-wtWMx6E3V2r1BdQCg-1 X-Mimecast-MFC-AGG-ID: 8gnq-wtWMx6E3V2r1BdQCg_1791967642 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 06/17] igb: Add VF post-load fixups for live migration Date: Wed, 14 Oct 2026 10:46:44 +0200 Message-ID: <20261014084655.127254-7-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-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: qemu development 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: 1791967796951158500 After restoring per-VF register state, propagate the VTIVAR interrupt vector routing to the shared IVAR0 register, which controls the actual hardware interrupt routing for VF queues. igb_core_vf_propagate_ivar() clears the IVAR0 entry before writing, unlike igb_set_vtivar() which only OR-s. The existing write handler could be refactored to use this helper in a follow-up. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_core.h | 2 ++ hw/net/igb_core.c | 37 +++++++++++++++++++++++++++++++++++++ hw/net/igb_migration.c | 3 +++ 3 files changed, 42 insertions(+) diff --git a/hw/net/igb_core.h b/hw/net/igb_core.h index 60724e2824ab..e066b9e029fd 100644 --- a/hw/net/igb_core.h +++ b/hw/net/igb_core.h @@ -145,4 +145,6 @@ igb_start_recv(IGBCore *core); =20 IGBCore *igb_pf_get_core(void *pf); =20 +void igb_core_vf_propagate_ivar(IGBCore *core, uint16_t vfn); + #endif diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 2a4883907353..ef941ecb86b4 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -4552,3 +4552,40 @@ igb_core_post_load(IGBCore *core) =20 return 0; } + +/* + * Propagate VTIVAR to IVAR0, which controls the actual hardware + * interrupt routing for VF queues. + */ +void igb_core_vf_propagate_ivar(IGBCore *core, uint16_t vfn) +{ + uint32_t vtivar =3D core->mac[VTIVAR + vfn]; + int n; + uint8_t ent; + uint32_t mask; + + n =3D igb_ivar_entry_rx(vfn); + mask =3D 0xffU << (8 * (n % 4)); + if (vtivar & E1000_IVAR_VALID) { + ent =3D E1000_IVAR_VALID | + (24 - vfn * IGBVF_MSIX_VEC_NUM - (2 - (vtivar & 0x7))); + core->mac[IVAR0 + n / 4] =3D + (core->mac[IVAR0 + n / 4] & ~mask) | + ((uint32_t)ent << (8 * (n % 4))); + } else { + core->mac[IVAR0 + n / 4] &=3D ~mask; + } + + n =3D igb_ivar_entry_tx(vfn); + mask =3D 0xffU << (8 * (n % 4)); + ent =3D vtivar >> 8; + if (ent & E1000_IVAR_VALID) { + ent =3D E1000_IVAR_VALID | + (24 - vfn * IGBVF_MSIX_VEC_NUM - (2 - (ent & 0x7))); + core->mac[IVAR0 + n / 4] =3D + (core->mac[IVAR0 + n / 4] & ~mask) | + ((uint32_t)ent << (8 * (n % 4))); + } else { + core->mac[IVAR0 + n / 4] &=3D ~mask; + } +} diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 0c21a5e45f32..831515639bd6 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -253,6 +253,9 @@ static int igb_core_vf_load_state(IgbVfState *s, const = void *buf, size_t size) } } =20 + /* Propagate VTIVAR to IVAR0, skipped by direct core->mac[] write */ + igb_core_vf_propagate_ivar(core, s->vfn); + trace_igbvf_mig_load_state(s->vfn, (uint32_t)size); return 0; } --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967726; cv=none; d=zohomail.com; s=zohoarc; b=UAvhHw4GT7pWk88SMGYLHRdJ4jJm/mJ00ACR930pqmF0BKx0cGUr4+exiM4eW84K1IUwjWEc3sNWwGb9YBDtGQVN+I368UaccLA1lwwZYBWJx9kA5B1v3H/ei2Hin/dT+Yfl6k3qUphHK8vHlQqzEusViRUBLLLYxI+8P+8oSwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967726; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=595O8+K/9C42+DRysyu4BvcnrUUkujwWh4BrgXVr9Dk=; b=WvJFTKvnMC9DS0mDVvFL5uZWWtnrX3OE8VSCrVAn+Wi3fgz/FXw45wcIt0a7E5W6DzjvV/mNW2/lQ3nqn19Z+7QGcrnZ81Wzmon/OhiZs5+rU4ff+Pau0ewCnv6hVJhD889HuKElJEBalDfjqiA5U7+Okw1zUIPjYR8QL6R8EBw= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967726737458.74717748758746; Wed, 14 Oct 2026 01:48:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuf9-0006Qn-9P; Wed, 14 Oct 2026 04:48:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueB-0005V7-5A for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:40 -0400 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 1xGue9-0004ZN-KX for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:38 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-1wx39ydbNbq8q0eiKPueCA-1; Wed, 14 Oct 2026 08:47:26 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6C1C419560BE; Wed, 14 Oct 2026 08:47:25 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 26F5718001CA; Wed, 14 Oct 2026 08:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967656; 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=595O8+K/9C42+DRysyu4BvcnrUUkujwWh4BrgXVr9Dk=; b=R7BWvvm0YBXVXFKT3EjTEbdOZ0WD+pNInGRw/rnaeBorYK5tp8C1nXLhHzgwPxGZckPPwK 0UUHTLfMSdgezIiYNPvMld5725sGRcDIFDzcGravQqNPGZMupSW9ybNteqh7KKZ0PhkxmO C8Dt/0b23oC9fyIGILHBt0s5fVQEj5w= X-MC-Unique: 1wx39ydbNbq8q0eiKPueCA-1 X-Mimecast-MFC-AGG-ID: 1wx39ydbNbq8q0eiKPueCA_1791967645 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 07/17] igb: Add VF TX context state serialization Date: Wed, 14 Oct 2026 10:46:45 +0200 Message-ID: <20261014084655.127254-8-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967727653158500 Save and restore the per-queue TX context descriptors and in-flight packet state for each of the VF's two TX queues. Without this, a partially described packet would be malformed or dropped on the destination after migration. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 831515639bd6..d0414ac89a28 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -37,12 +37,22 @@ typedef struct IgbMigRegPair { =20 #define IGB_VF_MAX_FIXED_REGS 64 =20 +typedef struct IgbMigTxCtx { + uint32_t ctx_desc[8]; /* 2 * adv_tx_context_desc (4 dwords eac= h) */ + uint32_t first_cmd_type_len; + uint32_t first_olinfo_status; + uint32_t first; + uint32_t skip_cp; +} IgbMigTxCtx; + typedef struct IgbMigBlob { uint32_t magic; uint32_t version; uint32_t vfn; uint32_t num_regs; IgbMigRegPair regs[IGB_VF_MAX_FIXED_REGS]; + uint32_t num_tx_ctx; + IgbMigTxCtx tx_ctx[2]; } IgbMigBlob; =20 #define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) @@ -140,6 +150,23 @@ static int igb_vf_reg_list(uint16_t vfn, uint32_t *off= sets) return n; } =20 +static void igb_core_vf_save_tx_ctx(IGBCore *core, int queue, + IgbMigTxCtx *tx) +{ + struct igb_tx *src =3D &core->tx[queue]; + + for (int i =3D 0; i < 2; i++) { + tx->ctx_desc[i * 4 + 0] =3D cpu_to_le32(src->ctx[i].vlan_macip_len= s); + tx->ctx_desc[i * 4 + 1] =3D cpu_to_le32(src->ctx[i].seqnum_seed); + tx->ctx_desc[i * 4 + 2] =3D cpu_to_le32(src->ctx[i].type_tucmd_mlh= l); + tx->ctx_desc[i * 4 + 3] =3D cpu_to_le32(src->ctx[i].mss_l4len_idx); + } + tx->first_cmd_type_len =3D cpu_to_le32(src->first_cmd_type_len); + tx->first_olinfo_status =3D cpu_to_le32(src->first_olinfo_status); + tx->first =3D cpu_to_le32(src->first); + tx->skip_cp =3D cpu_to_le32(src->skip_cp); +} + static int igb_core_vf_save_state(IgbVfState *s, void *buf, size_t buf_siz= e) { int size =3D IGB_MIG_BLOB_SIZE; @@ -147,6 +174,8 @@ static int igb_core_vf_save_state(IgbVfState *s, void *= buf, size_t buf_size) IgbMigBlob *blob =3D buf; uint32_t offsets[IGB_VF_MAX_FIXED_REGS]; int num_regs; + int q0 =3D s->vfn; + int q1 =3D s->vfn + IGB_NUM_VM_POOLS; =20 num_regs =3D igb_vf_reg_list(s->vfn, offsets); =20 @@ -168,6 +197,10 @@ static int igb_core_vf_save_state(IgbVfState *s, void = *buf, size_t buf_size) blob->regs[i].value =3D cpu_to_le32(core->mac[offsets[i]]); } =20 + blob->num_tx_ctx =3D cpu_to_le32(2); + igb_core_vf_save_tx_ctx(core, q0, &blob->tx_ctx[0]); + igb_core_vf_save_tx_ctx(core, q1, &blob->tx_ctx[1]); + trace_igbvf_mig_save_state(s->vfn, size); return size; } @@ -203,9 +236,32 @@ static bool igb_core_vf_validate_regs(uint16_t vfn, return true; } =20 +static void igb_core_vf_load_tx_ctx(IGBCore *core, int queue, + const IgbMigTxCtx *tx) +{ + struct igb_tx *dst =3D &core->tx[queue]; + + /* + * Preserve the destination's tx_pkt - it's a host-side object, + * not guest state + */ + for (int i =3D 0; i < 2; i++) { + dst->ctx[i].vlan_macip_lens =3D le32_to_cpu(tx->ctx_desc[i * 4 + 0= ]); + dst->ctx[i].seqnum_seed =3D le32_to_cpu(tx->ctx_desc[i * 4 + 1]= ); + dst->ctx[i].type_tucmd_mlhl =3D le32_to_cpu(tx->ctx_desc[i * 4 + 2= ]); + dst->ctx[i].mss_l4len_idx =3D le32_to_cpu(tx->ctx_desc[i * 4 + 3]= ); + } + dst->first_cmd_type_len =3D le32_to_cpu(tx->first_cmd_type_len); + dst->first_olinfo_status =3D le32_to_cpu(tx->first_olinfo_status); + dst->first =3D le32_to_cpu(tx->first); + dst->skip_cp =3D le32_to_cpu(tx->skip_cp); +} + static int igb_core_vf_load_state(IgbVfState *s, const void *buf, size_t s= ize) { IGBCore *core =3D igbvf_get_core(s); + int q0 =3D s->vfn; + int q1 =3D s->vfn + IGB_NUM_VM_POOLS; const IgbMigBlob *blob =3D buf; uint32_t magic, version, saved_vfn, num_regs; =20 @@ -236,6 +292,11 @@ static int igb_core_vf_load_state(IgbVfState *s, const= void *buf, size_t size) return -IGB_MIG_ERR_BAD_DATA; } =20 + uint32_t num_tx =3D le32_to_cpu(blob->num_tx_ctx); + if (num_tx !=3D 2) { + return -IGB_MIG_ERR_BAD_DATA; + } + /* * Phase 2: Apply state. All offsets and placements are * validated; writes cannot fail. @@ -253,6 +314,9 @@ static int igb_core_vf_load_state(IgbVfState *s, const = void *buf, size_t size) } } =20 + igb_core_vf_load_tx_ctx(core, q0, &blob->tx_ctx[0]); + igb_core_vf_load_tx_ctx(core, q1, &blob->tx_ctx[1]); + /* Propagate VTIVAR to IVAR0, skipped by direct core->mac[] write */ igb_core_vf_propagate_ivar(core, s->vfn); =20 --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967719; cv=none; d=zohomail.com; s=zohoarc; b=Cctbss+lAxUNGDA6UNU9sXaRSmWt5Ed/kX5rtPc96sJ+hLe3RR37B64J1sCbBTN6X7lN5nFWDYMOfQwwvxuf1yNg9rms/VNNbU2idEjsqUugM8P6sW/crdsBuOMp5HAy3LKMzwhSgqwYBAko+sFpQGwwB7fu9orqfdSvSCWiGtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967719; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AFWUKH2yvTE2qXkLbAJ6mhYut9W43/WbY2IFGiCLzSw=; b=hYb7UdXnuqKjpQTBwYqHkxGpZBXCP4GC2ExWLA5FLo2NHv90NhMdGUfEhpP9pq8d79CDW7ArjoVO4HVq+vwD6hc22pqW9n3PYte/FDPMe69Bx846Bt/ZS5NjjoS8zfI2OZjQwkbj3FIPQV4Sv6cU3xs6b8pJgAm+J7kTSCnxSmI= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967719668787.2356424560116; Wed, 14 Oct 2026 01:48:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuew-0005v2-RP; Wed, 14 Oct 2026 04:48:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueD-0005Wn-89 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:45 -0400 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 1xGue9-0004ZJ-DT for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:39 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-MXg-YrwnMXqhQJht3cN0JA-1; Wed, 14 Oct 2026 08:47:29 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F3DF6180059A; Wed, 14 Oct 2026 08:47:27 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C642718001CA; Wed, 14 Oct 2026 08:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967655; 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=AFWUKH2yvTE2qXkLbAJ6mhYut9W43/WbY2IFGiCLzSw=; b=e4cyatg9UDZyxmpWRYeb4oW7ZaWxUw1e4gv7YsgYmajY306RAc23f++aMhY5EbUO+AUWT0 3eXdW7c7HX4137087PmbUQffvLMpRGBeBBkX/nhzKS7d3pPKq1rZ/q8Og995y8leyOHg4r tVLPpQhhW9cjX00rWUWE8p6FUW163TM= X-MC-Unique: MXg-YrwnMXqhQJht3cN0JA-1 X-Mimecast-MFC-AGG-ID: MXg-YrwnMXqhQJht3cN0JA_1791967648 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 08/17] igb: Add VF RA entries state serialization Date: Wed, 14 Oct 2026 10:46:46 +0200 Message-ID: <20261014084655.127254-9-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1791967721687158500 The receive address (RA) table is scanned linearly by the hardware during RX filtering, so slot indices are irrelevant to the VF. The PF driver picks the slot when the VF requests a MAC address via the mailbox. On save, scan the RA/RA2 banks for entries whose pool bits include this VF. On load, clear this VF's stale RA entries from the destination (removing only this VF's pool bit, keeping entries shared with other VFs). Then place each saved entry by MAC address match or free slot. Add dry-run validation that simulates the post-clear table state and verifies every saved entry can be placed before any state is modified. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.h | 1 + hw/net/igb_migration.c | 222 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index d05252992f9e..676ec2d78301 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -77,6 +77,7 @@ #define IGB_MIG_ERR_BAD_VERSION 7 #define IGB_MIG_ERR_BAD_VFN 8 #define IGB_MIG_ERR_BAD_DATA 9 +#define IGB_MIG_ERR_UNSUPPORTED 10 =20 /* Shared buffer constants */ #define IGB_VF_STATE_MAX_SIZE 4096 diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index d0414ac89a28..57d750c06f4e 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -8,6 +8,7 @@ =20 #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/error-report.h" #include "hw/pci/pci_device.h" #include "hw/pci/pcie.h" #include "net/eth.h" @@ -36,6 +37,7 @@ typedef struct IgbMigRegPair { } IgbMigRegPair; =20 #define IGB_VF_MAX_FIXED_REGS 64 +#define IGB_VF_MAX_RA_REGS 48 /* (16 + 8) RA entries * 2 (RAL+RAH)= */ =20 typedef struct IgbMigTxCtx { uint32_t ctx_desc[8]; /* 2 * adv_tx_context_desc (4 dwords eac= h) */ @@ -51,6 +53,8 @@ typedef struct IgbMigBlob { uint32_t vfn; uint32_t num_regs; IgbMigRegPair regs[IGB_VF_MAX_FIXED_REGS]; + uint32_t num_ra; + IgbMigRegPair ra[IGB_VF_MAX_RA_REGS]; uint32_t num_tx_ctx; IgbMigTxCtx tx_ctx[2]; } IgbMigBlob; @@ -150,6 +154,201 @@ static int igb_vf_reg_list(uint16_t vfn, uint32_t *of= fsets) return n; } =20 +static const struct { + uint32_t base; + int count; +} ra_banks[] =3D { + { RA, 16 }, + { RA2, 8 }, +}; + +static int igb_core_vf_save_ra(IGBCore *core, uint16_t vfn, + IgbMigRegPair *regs) +{ + uint32_t vf_pool_bit =3D E1000_RAH_POOL_1 << vfn; + int n =3D 0; + + for (int i =3D 0; i < ARRAY_SIZE(ra_banks); i++) { + for (int j =3D 0; j < ra_banks[i].count; j++) { + uint32_t ral_off =3D ra_banks[i].base + j * 2; + uint32_t rah_off =3D ra_banks[i].base + j * 2 + 1; + uint32_t rah_val =3D core->mac[rah_off]; + + if ((rah_val & E1000_RAH_AV) && (rah_val & vf_pool_bit)) { + regs[n].offset =3D cpu_to_le32(ral_off); + regs[n].value =3D cpu_to_le32(core->mac[ral_off]); + n++; + regs[n].offset =3D cpu_to_le32(rah_off); + regs[n].value =3D cpu_to_le32(rah_val); + n++; + } + } + } + return n; +} + +/* + * Remove this VF's pool bit from all RA entries. If no pool bits + * remain the entry is unused; clear it entirely. This preserves other + * VFs' entries that may share the same RA slot (e.g. a multicast + * address used by multiple VFs). + */ +static void igb_core_vf_clear_ra(IGBCore *core, uint16_t vfn) +{ + uint32_t vf_pool_bit =3D E1000_RAH_POOL_1 << vfn; + + for (int i =3D 0; i < ARRAY_SIZE(ra_banks); i++) { + for (int j =3D 0; j < ra_banks[i].count; j++) { + uint32_t ral_off =3D ra_banks[i].base + j * 2; + uint32_t rah_off =3D ra_banks[i].base + j * 2 + 1; + uint32_t rah_val =3D core->mac[rah_off]; + + if (!(rah_val & E1000_RAH_AV) || !(rah_val & vf_pool_bit)) { + continue; + } + + rah_val &=3D ~vf_pool_bit; + if (!(rah_val & E1000_RAH_POOL_MASK)) { + core->mac[ral_off] =3D 0; + core->mac[rah_off] =3D 0; + } else { + core->mac[rah_off] =3D rah_val; + } + } + } +} + +/* + * The hardware scans all RA/RA2 entries during RX filtering and + * the VF driver has no awareness of which slot is used, so the L1 + * PF driver picks the slot. So the slot index is meaningless + * across migration; only the MAC + pool bit matters. + * + * For each saved entry: + * 1. Find a destination slot with the same MAC and add this VF's + * pool bit (preserves other VFs sharing the address). + * 2. Otherwise allocate a free slot. + * 3. Reject if the RA table is full. + */ +static int igb_core_vf_load_ra(IGBCore *core, uint16_t vfn, + const IgbMigRegPair *ra_pairs, + uint32_t num_ra) +{ + uint32_t vf_pool_bit =3D E1000_RAH_POOL_1 << vfn; + + /* RA entries are saved as (RAL, RAH) pairs */ + for (uint32_t p =3D 0; p + 1 < num_ra; p +=3D 2) { + uint32_t saved_ral =3D le32_to_cpu(ra_pairs[p].value); + uint32_t saved_rah =3D le32_to_cpu(ra_pairs[p + 1].value); + uint16_t saved_mac_hi =3D saved_rah & 0xFFFF; + int match =3D -1; + int free_slot_bank =3D -1; + int free_slot_idx =3D -1; + + for (int i =3D 0; i < ARRAY_SIZE(ra_banks); i++) { + for (int j =3D 0; j < ra_banks[i].count; j++) { + uint32_t ral_off =3D ra_banks[i].base + j * 2; + uint32_t rah_off =3D ra_banks[i].base + j * 2 + 1; + uint32_t rah_val =3D core->mac[rah_off]; + + if (rah_val & E1000_RAH_AV) { + if (core->mac[ral_off] =3D=3D saved_ral && + (rah_val & 0xFFFF) =3D=3D saved_mac_hi) { + match =3D rah_off; + break; + } + } else if (free_slot_bank < 0) { + free_slot_bank =3D i; + free_slot_idx =3D j; + } + } + if (match >=3D 0) { + break; + } + } + + if (match >=3D 0) { + core->mac[match] |=3D vf_pool_bit; + } else if (free_slot_bank >=3D 0) { + uint32_t ral_off =3D ra_banks[free_slot_bank].base + + free_slot_idx * 2; + uint32_t rah_off =3D ral_off + 1; + core->mac[ral_off] =3D saved_ral; + core->mac[rah_off] =3D (saved_rah & 0xFFFF) | + E1000_RAH_AV | vf_pool_bit; + } else { + return -IGB_MIG_ERR_BAD_DATA; + } + } + return 0; +} + +/* + * Dry-run check: can all saved RA entries be placed after clearing + * this VF's pool bits? Simulates the clear+load without writing. + * + * After clear, sole-owner entries are zeroed (becoming free slots) + * and shared entries just lose this VF's pool bit but keep their MAC. + * For each saved entry we check whether a MAC match survives in the + * post-clear state; entries that do not match need a free slot. + */ +static int igb_core_vf_can_load_ra(IGBCore *core, uint16_t vfn, + const IgbMigRegPair *ra_pairs, + uint32_t num_ra) +{ + uint32_t vf_pool_bit =3D E1000_RAH_POOL_1 << vfn; + int free_slots =3D 0; + + for (int i =3D 0; i < ARRAY_SIZE(ra_banks); i++) { + for (int j =3D 0; j < ra_banks[i].count; j++) { + uint32_t rah_off =3D ra_banks[i].base + j * 2 + 1; + uint32_t rah_val =3D core->mac[rah_off]; + + if (!(rah_val & E1000_RAH_AV)) { + free_slots++; + } else if ((rah_val & vf_pool_bit) && + !(rah_val & ~vf_pool_bit & E1000_RAH_POOL_MASK)) { + free_slots++; + } + } + } + + for (uint32_t p =3D 0; p + 1 < num_ra; p +=3D 2) { + uint32_t saved_ral =3D le32_to_cpu(ra_pairs[p].value); + uint16_t saved_mac_hi =3D le32_to_cpu(ra_pairs[p + 1].value) & 0xF= FFF; + bool found =3D false; + + for (int i =3D 0; i < ARRAY_SIZE(ra_banks) && !found; i++) { + for (int j =3D 0; j < ra_banks[i].count; j++) { + uint32_t ral_off =3D ra_banks[i].base + j * 2; + uint32_t rah_off =3D ra_banks[i].base + j * 2 + 1; + uint32_t rah_val =3D core->mac[rah_off]; + + if (!(rah_val & E1000_RAH_AV)) { + continue; + } + /* Sole-owner entries will be zeroed by clear */ + if ((rah_val & vf_pool_bit) && + !(rah_val & ~vf_pool_bit & E1000_RAH_POOL_MASK)) { + continue; + } + if (core->mac[ral_off] =3D=3D saved_ral && + (rah_val & 0xFFFF) =3D=3D saved_mac_hi) { + found =3D true; + break; + } + } + } + + if (!found) { + if (--free_slots < 0) { + return -IGB_MIG_ERR_UNSUPPORTED; + } + } + } + return 0; +} + static void igb_core_vf_save_tx_ctx(IGBCore *core, int queue, IgbMigTxCtx *tx) { @@ -201,6 +400,8 @@ static int igb_core_vf_save_state(IgbVfState *s, void *= buf, size_t buf_size) igb_core_vf_save_tx_ctx(core, q0, &blob->tx_ctx[0]); igb_core_vf_save_tx_ctx(core, q1, &blob->tx_ctx[1]); =20 + blob->num_ra =3D cpu_to_le32(igb_core_vf_save_ra(core, s->vfn, blob->r= a)); + trace_igbvf_mig_save_state(s->vfn, size); return size; } @@ -297,6 +498,17 @@ static int igb_core_vf_load_state(IgbVfState *s, const= void *buf, size_t size) return -IGB_MIG_ERR_BAD_DATA; } =20 + uint32_t num_ra =3D le32_to_cpu(blob->num_ra); + if (num_ra > IGB_VF_MAX_RA_REGS || (num_ra & 1)) { + return -IGB_MIG_ERR_BAD_DATA; + } + if (num_ra > 0) { + int ret =3D igb_core_vf_can_load_ra(core, s->vfn, blob->ra, num_ra= ); + if (ret < 0) { + return ret; + } + } + /* * Phase 2: Apply state. All offsets and placements are * validated; writes cannot fail. @@ -317,6 +529,16 @@ static int igb_core_vf_load_state(IgbVfState *s, const= void *buf, size_t size) igb_core_vf_load_tx_ctx(core, q0, &blob->tx_ctx[0]); igb_core_vf_load_tx_ctx(core, q1, &blob->tx_ctx[1]); =20 + igb_core_vf_clear_ra(core, s->vfn); + if (num_ra > 0) { + int ret =3D igb_core_vf_load_ra(core, s->vfn, blob->ra, num_ra); + if (ret < 0) { + error_report("igb: VF%u: RA load failed after pre-validation", + s->vfn); + return ret; + } + } + /* Propagate VTIVAR to IVAR0, skipped by direct core->mac[] write */ igb_core_vf_propagate_ivar(core, s->vfn); =20 --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967743; cv=none; d=zohomail.com; s=zohoarc; b=hvoxl+OJhF5ejV3Z4W7XHWbC/2/YleQmW1a2gNCHMdw2887NZocTxOlCA4UlR4royglYbtmwGGxoxRzaEmjxdrrs+hq7575yX1PJXzwcrWp0KPGWqBWvlKYIODOJJRcF/ij8TGpUXX8u4kHiwvXXRwYX6TdkLKZKvAU2SjYoifo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967743; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dovLJmklrP/XG0/w/IlronUilMNkJNurI7qp8nUr/Mo=; b=JT/tRdEV/AF2YKtj5z1ZhZTyckSOJxDlsNf7hM439V9/F0wLBb09LJy4gXDpypyXqUULo+OSB6JcMs3dBHnZMQtuvMCLxEP08iISnFyKFmWpM/BVSm2pSbx6LzF/UY91g33wll5EEZ8v3eHbJBnOmY8PhBRSxgEcwYQiTapKWhU= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967743694843.9983562369475; Wed, 14 Oct 2026 01:49:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuf8-0006IN-QB; Wed, 14 Oct 2026 04:48:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueD-0005Wp-8f for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:45 -0400 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 1xGueB-0004ZW-6p for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:40 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-nK0zHu00NxibmcwzZJ01hA-1; Wed, 14 Oct 2026 08:47:31 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A193B180061E; Wed, 14 Oct 2026 08:47:30 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 71CD41800446; Wed, 14 Oct 2026 08:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967658; 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=dovLJmklrP/XG0/w/IlronUilMNkJNurI7qp8nUr/Mo=; b=b12GC4aTJndtpyoApsmDZAVR/2awf8fVFrKD3FY/EPfhEibgDhvmvrH9YH6/DDJvqqOO5A phCpUZTIe+hPfn9OS0gZTHt0GBuqwSp2HjySHh65tm90PzJFFbZ434bRxFEFG3LE32QQbr FT/jttPfUsRx0ViiDGG3rD84XLRcW9s= X-MC-Unique: nK0zHu00NxibmcwzZJ01hA-1 X-Mimecast-MFC-AGG-ID: nK0zHu00NxibmcwzZJ01hA_1791967650 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 09/17] igb: Add VF VLAN filters (VLVF) serialization Date: Wed, 14 Oct 2026 10:46:47 +0200 Message-ID: <20261014084655.127254-10-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-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: qemu development 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: 1791967746122158500 VF VLAN filters are stored in the shared VLVF[0..31] table with per-VF pool bits in the POOLSEL field. On save, scan the 32 VLVF entries for this VF's pool bit and record the VLVF register value in the migration blob. On load, clear this VF's stale VLVF entries from the destination (removing only this VF's pool bit, keeping entries shared with other VFs). Then place each saved entry by VLAN ID match or free slot. Set the corresponding VFTA bit so the global VLAN filter accepts frames for the restored VLANs. Add dry-run validation that simulates the post-clear table state and verifies every saved entry can be placed before any state is modified. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.c | 166 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 57d750c06f4e..7cebf3500c0f 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -38,6 +38,7 @@ typedef struct IgbMigRegPair { =20 #define IGB_VF_MAX_FIXED_REGS 64 #define IGB_VF_MAX_RA_REGS 48 /* (16 + 8) RA entries * 2 (RAL+RAH)= */ +#define IGB_VF_MAX_VLVF_REGS E1000_VLVF_ARRAY_SIZE =20 typedef struct IgbMigTxCtx { uint32_t ctx_desc[8]; /* 2 * adv_tx_context_desc (4 dwords eac= h) */ @@ -57,6 +58,8 @@ typedef struct IgbMigBlob { IgbMigRegPair ra[IGB_VF_MAX_RA_REGS]; uint32_t num_tx_ctx; IgbMigTxCtx tx_ctx[2]; + uint32_t num_vlvf; + uint32_t vlvf[IGB_VF_MAX_VLVF_REGS]; } IgbMigBlob; =20 #define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) @@ -283,6 +286,93 @@ static int igb_core_vf_load_ra(IGBCore *core, uint16_t= vfn, return 0; } =20 +/* + * Scan VLVF entries for VLAN memberships assigned to this VF. + * Each VLVF entry has a per-pool bitmask (POOLSEL); save entries + * where this VF's pool bit is set. + */ +static int igb_core_vf_save_vlvf(IGBCore *core, uint16_t vfn, + uint32_t *vlvf_out) +{ + uint32_t vf_pool_bit =3D BIT(vfn) << E1000_VLVF_POOLSEL_SHIFT; + int n =3D 0; + + for (int i =3D 0; i < E1000_VLVF_ARRAY_SIZE; i++) { + uint32_t vlvf =3D core->mac[VLVF0 + i]; + + if ((vlvf & E1000_VLVF_VLANID_ENABLE) && (vlvf & vf_pool_bit)) { + vlvf_out[n++] =3D cpu_to_le32(vlvf); + } + } + return n; +} + +/* + * Clear this VF's pool bit from all destination VLVF entries. + * If no pools remain after clearing, disable the entry entirely. + */ +static void igb_core_vf_clear_vlvf(IGBCore *core, uint16_t vfn) +{ + uint32_t vf_pool_bit =3D BIT(vfn) << E1000_VLVF_POOLSEL_SHIFT; + + for (int i =3D 0; i < E1000_VLVF_ARRAY_SIZE; i++) { + uint32_t vlvf =3D core->mac[VLVF0 + i]; + + if (!(vlvf & E1000_VLVF_VLANID_ENABLE)) { + continue; + } + + vlvf &=3D ~vf_pool_bit; + if (!(vlvf & E1000_VLVF_POOLSEL_MASK)) { + vlvf &=3D ~E1000_VLVF_VLANID_ENABLE; + } + core->mac[VLVF0 + i] =3D vlvf; + } +} + +/* + * Restore VLVF entries by matching VLAN ID on the destination. + * Preserves other VFs' memberships and sets the VFTA bit so the + * global VLAN filter accepts frames for this VLAN. + */ +static int igb_core_vf_load_vlvf(IGBCore *core, uint16_t vfn, + const uint32_t *vlvf_in, uint32_t num) +{ + uint32_t vf_pool_bit =3D BIT(vfn) << E1000_VLVF_POOLSEL_SHIFT; + + for (uint32_t i =3D 0; i < num; i++) { + uint32_t saved =3D le32_to_cpu(vlvf_in[i]); + uint16_t vlan_id =3D saved & E1000_VLVF_VLANID_MASK; + int match =3D -1; + int free_slot =3D -1; + + for (int j =3D 0; j < E1000_VLVF_ARRAY_SIZE; j++) { + uint32_t vlvf =3D core->mac[VLVF0 + j]; + + if (vlvf & E1000_VLVF_VLANID_ENABLE) { + if ((vlvf & E1000_VLVF_VLANID_MASK) =3D=3D vlan_id) { + match =3D j; + break; + } + } else if (free_slot < 0) { + free_slot =3D j; + } + } + + if (match >=3D 0) { + core->mac[VLVF0 + match] |=3D vf_pool_bit; + } else if (free_slot >=3D 0) { + core->mac[VLVF0 + free_slot] =3D + E1000_VLVF_VLANID_ENABLE | vf_pool_bit | vlan_id; + } else { + return -IGB_MIG_ERR_BAD_DATA; + } + + core->mac[VFTA + (vlan_id >> 5)] |=3D BIT(vlan_id & 0x1f); + } + return 0; +} + /* * Dry-run check: can all saved RA entries be placed after clearing * this VF's pool bits? Simulates the clear+load without writing. @@ -349,6 +439,57 @@ static int igb_core_vf_can_load_ra(IGBCore *core, uint= 16_t vfn, return 0; } =20 +/* + * Dry-run check: can all saved VLVF entries be placed after clearing + * this VF's pool bits? Same logic as RA: sole-owner entries become + * free, shared entries keep their VLAN ID. + */ +static int igb_core_vf_can_load_vlvf(IGBCore *core, uint16_t vfn, + const uint32_t *vlvf_in, uint32_t num) +{ + uint32_t vf_pool_bit =3D BIT(vfn) << E1000_VLVF_POOLSEL_SHIFT; + int free_slots =3D 0; + + for (int j =3D 0; j < E1000_VLVF_ARRAY_SIZE; j++) { + uint32_t vlvf =3D core->mac[VLVF0 + j]; + + if (!(vlvf & E1000_VLVF_VLANID_ENABLE)) { + free_slots++; + } else if ((vlvf & vf_pool_bit) && + !(vlvf & ~vf_pool_bit & E1000_VLVF_POOLSEL_MASK)) { + free_slots++; + } + } + + for (uint32_t i =3D 0; i < num; i++) { + uint16_t vlan_id =3D le32_to_cpu(vlvf_in[i]) & E1000_VLVF_VLANID_M= ASK; + bool found =3D false; + + for (int j =3D 0; j < E1000_VLVF_ARRAY_SIZE; j++) { + uint32_t vlvf =3D core->mac[VLVF0 + j]; + + if (!(vlvf & E1000_VLVF_VLANID_ENABLE)) { + continue; + } + if ((vlvf & vf_pool_bit) && + !(vlvf & ~vf_pool_bit & E1000_VLVF_POOLSEL_MASK)) { + continue; + } + if ((vlvf & E1000_VLVF_VLANID_MASK) =3D=3D vlan_id) { + found =3D true; + break; + } + } + + if (!found) { + if (--free_slots < 0) { + return -IGB_MIG_ERR_UNSUPPORTED; + } + } + } + return 0; +} + static void igb_core_vf_save_tx_ctx(IGBCore *core, int queue, IgbMigTxCtx *tx) { @@ -402,6 +543,9 @@ static int igb_core_vf_save_state(IgbVfState *s, void *= buf, size_t buf_size) =20 blob->num_ra =3D cpu_to_le32(igb_core_vf_save_ra(core, s->vfn, blob->r= a)); =20 + blob->num_vlvf =3D cpu_to_le32(igb_core_vf_save_vlvf(core, s->vfn, + blob->vlvf)); + trace_igbvf_mig_save_state(s->vfn, size); return size; } @@ -509,6 +653,18 @@ static int igb_core_vf_load_state(IgbVfState *s, const= void *buf, size_t size) } } =20 + uint32_t num_vlvf =3D le32_to_cpu(blob->num_vlvf); + if (num_vlvf > IGB_VF_MAX_VLVF_REGS) { + return -IGB_MIG_ERR_BAD_DATA; + } + if (num_vlvf > 0) { + int ret =3D igb_core_vf_can_load_vlvf(core, s->vfn, + blob->vlvf, num_vlvf); + if (ret < 0) { + return ret; + } + } + /* * Phase 2: Apply state. All offsets and placements are * validated; writes cannot fail. @@ -539,6 +695,16 @@ static int igb_core_vf_load_state(IgbVfState *s, const= void *buf, size_t size) } } =20 + igb_core_vf_clear_vlvf(core, s->vfn); + if (num_vlvf > 0) { + int ret =3D igb_core_vf_load_vlvf(core, s->vfn, blob->vlvf, num_vl= vf); + if (ret < 0) { + error_report("igb: VF%u: VLVF load failed after pre-validation= ", + s->vfn); + return ret; + } + } + /* Propagate VTIVAR to IVAR0, skipped by direct core->mac[] write */ igb_core_vf_propagate_ivar(core, s->vfn); =20 --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967722; cv=none; d=zohomail.com; s=zohoarc; b=Ywte2BKllHqam/1+vdQzqzm56jQuICcUmewvwF2DdPzNSM8bVsyoqkziAzPc6UiRMZD8C3zgU6I2Axd/5ebTEjY8VMu1Awd0aLTE+hPMokVmou0DyFzCjNUrnXLZbfzhVFW63Zt90s8zb2dhpk9I+aHX6kVuRLgPPC6HEBqShxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967722; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/lwU7Lm7Uh19FovhUkBJV4SoFJWR0MWrOz36CSE2t08=; b=Egu8xtudSW9nrC4EHQFbKcSZAdB8bB/fUiB2goGa4BXfd8nfyyYS9ncQ67BuBvzEzJP8+fvMGQKwLWll3opPyh8tcnwj0wExyo+GqayjI/cSnHqBxuHRX/o5dXrWDC5GDt63JyeV6t66JtngzFU073OQVRKlQGhfUlDcAmyiI3U= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967722832732.9306950103728; Wed, 14 Oct 2026 01:48:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGueZ-0005hp-QQ; Wed, 14 Oct 2026 04:48:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueD-0005Wo-8d for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:45 -0400 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 1xGueA-0004ZR-Ea for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:40 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-5QxWv0kfMqevXYNz8pyRWA-1; Wed, 14 Oct 2026 08:47:34 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A5CA1956040; Wed, 14 Oct 2026 08:47:33 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D5921800642; Wed, 14 Oct 2026 08:47:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967657; 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=/lwU7Lm7Uh19FovhUkBJV4SoFJWR0MWrOz36CSE2t08=; b=OsghGbqu6gittjkbW778oQrwP9qAYuKItNMBkQrWPwLZxnJ7C5FZolTibLKff+96UIamep ddZxgYVU6DPPc+lP23PglFHrPGGR28AaQMEVpX0PxL07nNL0GGHQgXRka3/LjPcSYL3WQV z1HAwNFN57M2QScRT9x7Prno8o7GJEA= X-MC-Unique: 5QxWv0kfMqevXYNz8pyRWA-1 X-Mimecast-MFC-AGG-ID: 5QxWv0kfMqevXYNz8pyRWA_1791967653 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 10/17] igb: Save MTA/UTA hash tables and fixup on VF migration load Date: Wed, 14 Oct 2026 10:46:48 +0200 Message-ID: <20261014084655.127254-11-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967723671158500 The MTA and UTA are PF-wide shared hash tables with no per-VF ownership bits. A VF using multicast (VMOLR.ROMPE) or unicast (VMOLR.ROPE) hash filtering relies on entries that may differ between source and destination PFs. Save both tables in the migration blob and compare them on load. If the destination PF is missing entries that were present on the source, warn and OR them into the destination, to prevent silent multicast or unicast packet loss. Stale source entries may persist on the destination until the L1 driver reprograms the tables. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.c | 77 ++++++++++++++++++++++++++++++++++++++++++ hw/net/trace-events | 1 + 2 files changed, 78 insertions(+) diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 7cebf3500c0f..42d2587149ef 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -60,6 +60,8 @@ typedef struct IgbMigBlob { IgbMigTxCtx tx_ctx[2]; uint32_t num_vlvf; uint32_t vlvf[IGB_VF_MAX_VLVF_REGS]; + uint32_t mta[E1000_MC_TBL_SIZE]; + uint32_t uta[E1000_MC_TBL_SIZE]; } IgbMigBlob; =20 #define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) @@ -490,6 +492,22 @@ static int igb_core_vf_can_load_vlvf(IGBCore *core, ui= nt16_t vfn, return 0; } =20 +static void igb_core_vf_save_hash_tables(IGBCore *core, uint16_t vfn, + IgbMigBlob *blob) +{ + for (int i =3D 0; i < E1000_MC_TBL_SIZE; i++) { + blob->mta[i] =3D cpu_to_le32(core->mac[MTA + i]); + blob->uta[i] =3D cpu_to_le32(core->mac[UTA + i]); + + if (core->mac[MTA + i]) { + trace_igbvf_mig_save_hash_tables(vfn, "MTA", i, core->mac[MTA = + i]); + } + if (core->mac[UTA + i]) { + trace_igbvf_mig_save_hash_tables(vfn, "UTA", i, core->mac[UTA = + i]); + } + } +} + static void igb_core_vf_save_tx_ctx(IGBCore *core, int queue, IgbMigTxCtx *tx) { @@ -546,6 +564,8 @@ static int igb_core_vf_save_state(IgbVfState *s, void *= buf, size_t buf_size) blob->num_vlvf =3D cpu_to_le32(igb_core_vf_save_vlvf(core, s->vfn, blob->vlvf)); =20 + igb_core_vf_save_hash_tables(core, s->vfn, blob); + trace_igbvf_mig_save_state(s->vfn, size); return size; } @@ -581,6 +601,61 @@ static bool igb_core_vf_validate_regs(uint16_t vfn, return true; } =20 +/* + * Extract a register from the incoming blob. Used in Phase 1 + * validation where core->mac[] still holds the destination's state, + * not the source's. + */ +static uint32_t igb_core_vf_blob_get_reg(const IgbMigBlob *blob, + uint32_t offset) +{ + uint32_t num_regs =3D le32_to_cpu(blob->num_regs); + + for (int i =3D 0; i < num_regs; i++) { + if (le32_to_cpu(blob->regs[i].offset) =3D=3D offset) { + return le32_to_cpu(blob->regs[i].value); + } + } + return 0; +} + +/* + * OR missing hash table entries from the source into the destination. + * MTA/UTA are PF-wide shared tables with no per-VF ownership, so + * entries present on the source may be absent on the destination. + */ +static bool igb_core_vf_fixup_hash_tables(IGBCore *core, uint16_t vfn, + const IgbMigBlob *blob) +{ + uint32_t vmolr =3D igb_core_vf_blob_get_reg(blob, VMOLR0 + vfn); + bool check_mta =3D vmolr & E1000_VMOLR_ROMPE; + bool check_uta =3D vmolr & E1000_VMOLR_ROPE; + bool fixed_up =3D false; + + for (int i =3D 0; i < E1000_MC_TBL_SIZE; i++) { + uint32_t src_mta =3D le32_to_cpu(blob->mta[i]); + uint32_t src_uta =3D le32_to_cpu(blob->uta[i]); + uint32_t missing_mta =3D src_mta & ~core->mac[MTA + i]; + uint32_t missing_uta =3D src_uta & ~core->mac[UTA + i]; + + if (missing_mta && check_mta) { + warn_report("igb: VF%u: MTA[%d] source 0x%x destination 0x%x" + " (missing 0x%x, merged)", + vfn, i, src_mta, core->mac[MTA + i], missing_mta); + core->mac[MTA + i] |=3D missing_mta; + fixed_up =3D true; + } + if (missing_uta && check_uta) { + warn_report("igb: VF%u: UTA[%d] source 0x%x destination 0x%x" + " (missing 0x%x, merged)", + vfn, i, src_uta, core->mac[UTA + i], missing_uta); + core->mac[UTA + i] |=3D missing_uta; + fixed_up =3D true; + } + } + return fixed_up; +} + static void igb_core_vf_load_tx_ctx(IGBCore *core, int queue, const IgbMigTxCtx *tx) { @@ -705,6 +780,8 @@ static int igb_core_vf_load_state(IgbVfState *s, const = void *buf, size_t size) } } =20 + igb_core_vf_fixup_hash_tables(core, s->vfn, blob); + /* Propagate VTIVAR to IVAR0, skipped by direct core->mac[] write */ igb_core_vf_propagate_ivar(core, s->vfn); =20 diff --git a/hw/net/trace-events b/hw/net/trace-events index 23f6dbcfed82..a8cc72b69d0f 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -301,6 +301,7 @@ igbvf_mig_status(uint16_t vfn, uint32_t status) "VF%u: = status 0x%x" igbvf_mig_set_state(uint16_t vfn, uint32_t old_state, uint32_t new_state) = "VF%u: state %u -> %u" igbvf_mig_save_state(uint16_t vfn, uint32_t size) "VF%u: saved %u bytes of= device state" igbvf_mig_load_state(uint16_t vfn, uint32_t size) "VF%u: loaded %u bytes o= f device state" +igbvf_mig_save_hash_tables(uint16_t vfn, const char *name, int index, uint= 32_t value) "VF%u: %s[%d]=3D0x%x" igbvf_mig_reset(uint16_t vfn) "VF%u: migration state reset" =20 # spapr_llan.c --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967782; cv=none; d=zohomail.com; s=zohoarc; b=fPfmYGmSpGLnRlGq6yP2JO1LnQsCimlcoE9fzZ15oyLHH+bCAmMPs6SxBvvVAZSfjNV2c2MvhcEqRefcXRWeZVwXgwXir5avkwXHvAS7/ji6UfZNVHJIGgZUgBMdJSNNEK0+ifixXNgCXT2snSdTWX/sFD94eh9dQT7CyDbTVu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967782; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Nnv2Ido8yJh2Wdyw9LwIuuKdA7O+s2rbmSxYa/jZd1w=; b=mliHqcrAu8ezi3DlWu55p9TdO6GJb7iB92fDFH4/If8cm3mMgVHUAvZkRNzBNBNYP5whIJsA26gLbhjnhZ4b4JgdxScTDsBBLCk47m091r0oRK9wJroH6iT9kK0O96jUCijIcglEqAjitmr2wEe3wlvS2YCIDHzvBbxchVr82rc= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967781857855.7064998509284; Wed, 14 Oct 2026 01:49:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuey-0005wh-Ko; Wed, 14 Oct 2026 04:48:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueF-0005YO-NS for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:47 -0400 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 1xGueD-0004Za-12 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:43 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-lSZhv8gMM1Wu5lIxwKjIAQ-1; Wed, 14 Oct 2026 08:47:37 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 39C2D180044D; Wed, 14 Oct 2026 08:47:36 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BC2161800495; Wed, 14 Oct 2026 08:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967658; 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=Nnv2Ido8yJh2Wdyw9LwIuuKdA7O+s2rbmSxYa/jZd1w=; b=ImgpWvEdL7m+7xpSegzVfEqiVL2L3EFYo500DJlg+iUyojQHEIMecx51gFMQK/tTzm+Bqb 2m5F3mhgBF1ne0Vik3LhtWwsLRDwbbUvgnOJPlctnTjVZWbcWjMeA5AB+7l2CnXiVUtLWt Xa6ct8/30XFNw8EMrC1rOFXrORQyHkk= X-MC-Unique: lSZhv8gMM1Wu5lIxwKjIAQ-1 X-Mimecast-MFC-AGG-ID: lSZhv8gMM1Wu5lIxwKjIAQ_1791967656 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 11/17] igb: Add dirty page tracking for IGBVF migration Date: Wed, 14 Oct 2026 10:46:49 +0200 Message-ID: <20261014084655.127254-12-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1791967782901158500 Add per-VF dirty page tracking using bitmaps allocated per IOVA range. The DMA data path is instrumented via igb_core_dirty_track_dma() calls at all five DMA write sites: TX descriptor writeback (head pointer and status), RX descriptor writeback, RX header fragment, and RX payload fragment. The migration DVSEC exposes DIRTY_ENABLE, DIRTY_DISABLE and DIRTY_QUERY commands. Range parameters and query results are exchanged through the shared DMA buffer. Add the PRE_COPY device state to support pre-copy live migration with concurrent dirty tracking. PRE_COPY transitions: - RUNNING -> PRE_COPY - PRE_COPY -> STOP, RUNNING, STOP_COPY Dirty tracking is automatically disabled when leaving PRE_COPY or STOP_COPY. AI-used-for: code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_core.h | 4 + hw/net/igb_migration.h | 67 ++++++++- hw/net/igb_core.c | 42 ++++-- hw/net/igb_migration.c | 330 ++++++++++++++++++++++++++++++++++++++++- hw/net/trace-events | 11 +- 5 files changed, 432 insertions(+), 22 deletions(-) diff --git a/hw/net/igb_core.h b/hw/net/igb_core.h index e066b9e029fd..5a15433da2c2 100644 --- a/hw/net/igb_core.h +++ b/hw/net/igb_core.h @@ -40,6 +40,8 @@ #ifndef HW_NET_IGB_CORE_H #define HW_NET_IGB_CORE_H =20 +#include "igb_migration.h" + #define E1000E_MAC_SIZE (0x8000) #define IGB_EEPROM_SIZE (1024) =20 @@ -99,6 +101,8 @@ struct IGBCore { void (*owner_start_recv)(PCIDevice *d); =20 int64_t timadj; + + IGBVfDirtyState vf_dirty[IGB_MAX_VF_FUNCTIONS]; }; =20 void diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index 676ec2d78301..4968798509aa 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -21,7 +21,8 @@ * +0x04 DVSEC header 1 (len | rev | vendor_id) * +0x08 DVSEC header 2 (DVSEC ID) * +0x0A Reserved (padding for DWORD alignment) - * +0x0C CAPS (RO: F_STATE[0]) + * +0x0C CAPS (RO: F_STATE[0], F_DIRTY[1], + * max_ranges[11:8], pgsize[16:12]) * +0x10 CTRL (WO: doorbell command) * +0x14 STATUS (RO: state[7:0], error_code[15:8]) * +0x18 BUF_ADDR_LO (RW: shared buffer GPA low) @@ -44,6 +45,14 @@ =20 /* CAPS register layout */ #define IGB_MIG_CAP_F_STATE (1u << 0) +#define IGB_MIG_CAP_F_DIRTY (1u << 1) +#define IGB_MIG_CAPS_MAX_RANGES_SHIFT 8 +#define IGB_MIG_CAPS_MAX_RANGES 4 +#define IGB_MIG_CAPS_PGSIZE_SHIFT 12 +#define IGB_MIG_CAPS_PGSIZE_4K (1u << 12) +#define IGB_MIG_CAPS_PGSIZE_64K (1u << 16) +#define IGB_MIG_CAPS_PGSIZE_MASK (IGB_MIG_CAPS_PGSIZE_4K | \ + IGB_MIG_CAPS_PGSIZE_64K) =20 /* CTRL register: command in [7:0] */ #define IGB_MIG_CTRL_CMD_MASK 0xFF @@ -53,6 +62,9 @@ #define IGB_MIG_CMD_SET_STATE 1 #define IGB_MIG_CMD_SAVE 2 #define IGB_MIG_CMD_LOAD 3 +#define IGB_MIG_CMD_DIRTY_ENABLE 4 +#define IGB_MIG_CMD_DIRTY_DISABLE 5 +#define IGB_MIG_CMD_DIRTY_QUERY 6 =20 /* STATUS register: state in [7:0], error code [15:8] */ #define IGB_MIG_STATUS_STATE_MASK 0xFF @@ -66,6 +78,7 @@ #define IGB_MIG_STATE_RUNNING 2 #define IGB_MIG_STATE_STOP_COPY 3 #define IGB_MIG_STATE_RESUMING 4 +#define IGB_MIG_STATE_PRE_COPY 5 =20 /* Error codes */ #define IGB_MIG_ERR_UNK_CMD 1 @@ -78,6 +91,10 @@ #define IGB_MIG_ERR_BAD_VFN 8 #define IGB_MIG_ERR_BAD_DATA 9 #define IGB_MIG_ERR_UNSUPPORTED 10 +#define IGB_MIG_ERR_TOO_MANY_RANGES 11 +#define IGB_MIG_ERR_BAD_RANGE 12 +#define IGB_MIG_ERR_BAD_PGSIZE 13 +#define IGB_MIG_ERR_NOT_ENABLED 14 =20 /* Shared buffer constants */ #define IGB_VF_STATE_MAX_SIZE 4096 @@ -89,6 +106,51 @@ typedef struct IgbVfMigState { uint64_t mig_data_buf_addr; } IgbVfMigState; =20 +#define IGB_MIG_DIRTY_DEFAULT_PGSIZE 4096 + +typedef struct IGBVfDirtyRange { + uint64_t iova; + uint64_t size; + uint64_t page_size; + unsigned long *bitmap; + uint64_t nbits; +} IGBVfDirtyRange; + +typedef struct IGBVfDirtyState { + IGBVfDirtyRange ranges[IGB_MIG_CAPS_MAX_RANGES]; + uint32_t num_ranges; +} IGBVfDirtyState; + +/* + * DMA buffer layouts for dirty tracking commands. + * + * DIRTY_ENABLE: driver writes igb_mig_dirty_enable_req to buffer + * before cmd. + * DIRTY_QUERY: driver writes iova/size fields, device writes + * response + bitmap. + */ +struct igb_mig_dirty_enable_req { + uint32_t len; + uint32_t flags; + uint64_t pgsize; + uint64_t range_iova; + uint64_t range_size; + uint32_t reserved[4]; +}; + +struct igb_mig_dirty_query { + uint32_t len; + uint32_t flags; + uint64_t iova; + uint64_t size; + uint32_t bitmap_size; + uint32_t dirty_page_count; + uint64_t dma_writes; + uint32_t reserved[6]; + uint8_t bitmap[]; +}; + +typedef struct IGBCore IGBCore; typedef struct IgbVfState IgbVfState; =20 bool igbvf_add_migration_dvsec(IgbVfState *s, Error **errp); @@ -96,4 +158,7 @@ uint32_t igbvf_mig_config_read(IgbVfState *s, uint32_t a= ddr, int size); bool igbvf_mig_config_write(IgbVfState *s, uint32_t addr, uint32_t val, int size); =20 +void igb_core_dirty_track_dma(IGBCore *core, int vfn, + dma_addr_t addr, dma_addr_t len); + #endif diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index ef941ecb86b4..452bae06ee92 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -824,6 +824,16 @@ igb_rx_ring_init(IGBCore *core, E1000E_RxRing *rxr, in= t idx) rxr->i =3D &i[idx]; } =20 +static inline void +igb_pci_dma_write(IGBCore *core, PCIDevice *dev, + dma_addr_t addr, const void *buf, dma_addr_t len) +{ + pci_dma_write(dev, addr, buf, len); + if (pci_is_vf(dev)) { + igb_core_dirty_track_dma(core, pcie_sriov_vf_number(dev), addr, le= n); + } +} + static uint32_t igb_txdesc_writeback(IGBCore *core, dma_addr_t base, union e1000_adv_tx_desc *tx_desc, @@ -847,13 +857,15 @@ igb_txdesc_writeback(IGBCore *core, dma_addr_t base, =20 if (tdwba & 1) { uint32_t buffer =3D cpu_to_le32(core->mac[txi->dh]); - pci_dma_write(d, tdwba & ~3, &buffer, sizeof(buffer)); + igb_pci_dma_write(core, d, + tdwba & ~3, &buffer, sizeof(buffer)); } else { uint32_t status =3D le32_to_cpu(tx_desc->wb.status) | E1000_TXD_ST= AT_DD; =20 tx_desc->wb.status =3D cpu_to_le32(status); - pci_dma_write(d, base + offsetof(union e1000_adv_tx_desc, wb), - &tx_desc->wb, sizeof(tx_desc->wb)); + igb_pci_dma_write(core, d, + base + offsetof(union e1000_adv_tx_desc, wb), + &tx_desc->wb, sizeof(tx_desc->wb)); } =20 return igb_tx_wb_eic(core, txi->idx); @@ -1598,11 +1610,12 @@ igb_pci_dma_write_rx_desc(IGBCore *core, PCIDevice = *dev, dma_addr_t addr, uint8_t status =3D d->status; =20 d->status &=3D ~E1000_RXD_STAT_DD; - pci_dma_write(dev, addr, desc, len); + igb_pci_dma_write(core, dev, addr, desc, len); =20 if (status & E1000_RXD_STAT_DD) { d->status =3D status; - pci_dma_write(dev, addr + offset, &status, sizeof(status)); + igb_pci_dma_write(core, dev, + addr + offset, &status, sizeof(status)); } } else { union e1000_adv_rx_desc *d =3D &desc->adv; @@ -1611,11 +1624,12 @@ igb_pci_dma_write_rx_desc(IGBCore *core, PCIDevice = *dev, dma_addr_t addr, uint32_t status =3D d->wb.upper.status_error; =20 d->wb.upper.status_error &=3D ~E1000_RXD_STAT_DD; - pci_dma_write(dev, addr, desc, len); + igb_pci_dma_write(core, dev, addr, desc, len); =20 if (status & E1000_RXD_STAT_DD) { d->wb.upper.status_error =3D status; - pci_dma_write(dev, addr + offset, &status, sizeof(status)); + igb_pci_dma_write(core, dev, + addr + offset, &status, sizeof(status)); } } } @@ -1737,9 +1751,9 @@ igb_write_hdr_frag_to_rx_buffers(IGBCore *core, { assert(data_len <=3D pdma_st->rx_desc_header_buf_size - pdma_st->bastate.written[0]); - pci_dma_write(d, - pdma_st->ba[0] + pdma_st->bastate.written[0], - data, data_len); + igb_pci_dma_write(core, d, + pdma_st->ba[0] + pdma_st->bastate.written[0], + data, data_len); pdma_st->bastate.written[0] +=3D data_len; pdma_st->bastate.cur_idx =3D 1; } @@ -1804,10 +1818,10 @@ igb_write_payload_frag_to_rx_buffers(IGBCore *core, data, bytes_to_write); =20 - pci_dma_write(d, - pdma_st->ba[pdma_st->bastate.cur_idx] + - pdma_st->bastate.written[pdma_st->bastate.cur_idx], - data, bytes_to_write); + igb_pci_dma_write(core, d, + pdma_st->ba[pdma_st->bastate.cur_idx] + + pdma_st->bastate.written[pdma_st->bastate.cur_id= x], + data, bytes_to_write); =20 pdma_st->bastate.written[pdma_st->bastate.cur_idx] +=3D bytes_to_w= rite; data +=3D bytes_to_write; diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 42d2587149ef..efa2f5a8d333 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -9,6 +9,8 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/error-report.h" +#include "qemu/bitmap.h" +#include "qemu/units.h" #include "hw/pci/pci_device.h" #include "hw/pci/pcie.h" #include "net/eth.h" @@ -801,6 +803,292 @@ static int igbvf_mig_load(IgbVfState *s, const void *= buf, size_t size) return 0; } =20 +/* + * Per-VF dirty page tracking + * + * All VF DMA writes in igb_core.c go through igb_pci_dma_write(), + * which calls igb_core_dirty_track_dma() to mark the target page in a + * per-range bitmap before performing the actual DMA. + * + * The IGBCore::vf_dirty[] bitmaps live in IGBCore so they are easily + * accessible from the core TX and RX paths without reaching back into + * VF state. + */ + +void igb_core_dirty_track_dma(IGBCore *core, int vfn, + dma_addr_t addr, dma_addr_t len) +{ + IGBVfDirtyState *ds =3D &core->vf_dirty[vfn]; + bool matched =3D false; + uint32_t i; + + if (!ds->num_ranges) { + return; + } + + trace_igb_core_dirty_track_dma(vfn, addr, len); + + for (i =3D 0; i < ds->num_ranges; i++) { + IGBVfDirtyRange *r =3D &ds->ranges[i]; + uint64_t r_end =3D r->iova + r->size; + uint64_t dma_end =3D addr + len; + uint64_t start, end, start_page, end_page, page; + + if (addr >=3D r_end || dma_end <=3D r->iova) { + continue; + } + + matched =3D true; + start =3D MAX(addr, r->iova); + end =3D MIN(dma_end, r_end); + + start_page =3D (start - r->iova) / r->page_size; + end_page =3D (end - 1 - r->iova) / r->page_size; + + for (page =3D start_page; page <=3D end_page; page++) { + if (page < r->nbits) { + set_bit(page, r->bitmap); + } + } + } + + if (!matched) { + trace_igb_core_dirty_track_dma_drop(vfn, addr, len); + } +} + +static IGBVfDirtyState *igb_core_vf_dirty_state(IgbVfState *s) +{ + IGBCore *core =3D igbvf_get_core(s); + return &core->vf_dirty[s->vfn]; +} + +#define IGB_MIG_DIRTY_MAX_PAGES ((256ULL * GiB) / (4 * KiB)) + +static uint32_t igb_core_vf_dirty_enable(IgbVfState *s, uint64_t pgsize, + uint64_t range_iova, + uint64_t range_size) +{ + uint32_t caps =3D pci_get_long(PCI_DEVICE(s)->config + + IGB_MIG_DVSEC_OFFSET + IGB_MIG_CAPS); + IGBVfDirtyState *ds =3D igb_core_vf_dirty_state(s); + IGBVfDirtyRange *r; + + if (ds->num_ranges >=3D IGB_MIG_CAPS_MAX_RANGES) { + return IGB_MIG_ERR_TOO_MANY_RANGES; + } + + if (!range_size || range_iova + range_size < range_iova) { + return IGB_MIG_ERR_BAD_RANGE; + } + + /* Validate page size against CAPS supported page size bitmask */ + if (!is_power_of_2(pgsize) || !(pgsize & (caps & IGB_MIG_CAPS_PGSIZE_M= ASK))) { + return IGB_MIG_ERR_BAD_PGSIZE; + } + + if ((range_iova % pgsize) || (range_size % pgsize)) { + return IGB_MIG_ERR_BAD_PGSIZE; + } + + if (range_size / pgsize > IGB_MIG_DIRTY_MAX_PAGES) { + return IGB_MIG_ERR_BAD_RANGE; + } + + for (int i =3D 0; i < ds->num_ranges; i++) { + if (ranges_overlap(range_iova, range_size, + ds->ranges[i].iova, ds->ranges[i].size)) { + return IGB_MIG_ERR_BAD_RANGE; + } + } + + r =3D &ds->ranges[ds->num_ranges]; + r->iova =3D range_iova; + r->size =3D range_size; + r->page_size =3D pgsize; + r->nbits =3D range_size / pgsize; + r->bitmap =3D bitmap_new(r->nbits); + ds->num_ranges++; + return 0; +} + +static void igb_core_vf_dirty_disable(IgbVfState *s) +{ + IGBVfDirtyState *ds =3D igb_core_vf_dirty_state(s); + uint32_t i; + + for (i =3D 0; i < ds->num_ranges; i++) { + IGBVfDirtyRange *r =3D &ds->ranges[i]; + + g_free(r->bitmap); + r->bitmap =3D NULL; + r->nbits =3D 0; + } + ds->num_ranges =3D 0; + trace_igbvf_mig_dirty_disable(s->vfn); +} + +static bool igb_core_vf_dirty_enabled(IgbVfState *s) +{ + return igb_core_vf_dirty_state(s)->num_ranges > 0; +} + +static void igb_core_vf_dirty_query(IGBVfDirtyRange *r, + uint64_t range_iova, uint64_t range_si= ze, + void *buf, size_t buf_size, + size_t *out_size) +{ + uint64_t start_page =3D (range_iova - r->iova) / r->page_size; + uint64_t range_pages =3D range_size / r->page_size; + uint64_t count =3D MIN(range_pages, (uint64_t)buf_size * 8); + + memset(buf, 0, buf_size); + + if (start_page < r->nbits) { + uint64_t avail =3D r->nbits - start_page; + uint64_t n =3D MIN(count, avail); + + bitmap_copy_with_src_offset(buf, r->bitmap, start_page, n); + } + *out_size =3D bitmap_empty(buf, count) ? 0 : DIV_ROUND_UP(count, 8); +} + +static void igb_core_vf_dirty_query_commit(IGBVfDirtyRange *r, + uint64_t range_iova, + uint64_t range_size) +{ + uint64_t start_page =3D (range_iova - r->iova) / r->page_size; + + if (start_page < r->nbits) { + uint64_t avail =3D r->nbits - start_page; + uint64_t range_pages =3D range_size / r->page_size; + uint64_t n =3D MIN(range_pages, avail); + + bitmap_clear(r->bitmap, start_page, n); + } +} + +static uint8_t igbvf_mig_cmd_dirty_enable(IgbVfState *s) +{ + IgbVfMigState *ms =3D &s->mig; + struct igb_mig_dirty_enable_req req; + MemTxResult r; + uint32_t status; + + if (!ms->mig_data_buf_addr) { + return IGB_MIG_ERR_NO_BUFFER; + } + + r =3D address_space_read(&address_space_memory, ms->mig_data_buf_addr, + MEMTXATTRS_UNSPECIFIED, &req, sizeof(req)); + if (r !=3D MEMTX_OK) { + return IGB_MIG_ERR_DMA_FAILED; + } + + /* TODO: validate req.len and req.flags */ + + status =3D igb_core_vf_dirty_enable(s, le64_to_cpu(req.pgsize), + le64_to_cpu(req.range_iova), + le64_to_cpu(req.range_size)); + if (status !=3D 0) { + return status; + } + trace_igbvf_mig_dirty_enable(s->vfn, le64_to_cpu(req.pgsize), + le64_to_cpu(req.range_size) / + le64_to_cpu(req.pgsize)); + return 0; +} + +static IGBVfDirtyRange *igb_core_vf_dirty_range_valid(IGBVfDirtyState *ds, + uint64_t range_iova, + uint64_t range_size) +{ + if (!range_size) { + return NULL; + } + + for (uint32_t i =3D 0; i < ds->num_ranges; i++) { + IGBVfDirtyRange *r =3D &ds->ranges[i]; + + if (range_iova >=3D r->iova && + range_iova + range_size <=3D r->iova + r->size && + QEMU_IS_ALIGNED(range_iova, r->page_size) && + QEMU_IS_ALIGNED(range_size, r->page_size)) { + return r; + } + } + return NULL; +} + +static uint8_t igbvf_mig_cmd_dirty_query(IgbVfState *s) +{ + IgbVfMigState *ms =3D &s->mig; + IGBVfDirtyState *ds =3D &igbvf_get_core(s)->vf_dirty[s->vfn]; + uint64_t buf_addr =3D ms->mig_data_buf_addr; + uint64_t range_iova =3D 0, range_size =3D 0; + IGBVfDirtyRange *range; + uint32_t bmp_bytes, dirty_pages; + uint32_t val32; + size_t out_size; + g_autofree void *bitmap =3D NULL; + + if (!buf_addr) { + return IGB_MIG_ERR_NO_BUFFER; + } + + if (!igb_core_vf_dirty_enabled(s)) { + return IGB_MIG_ERR_NOT_ENABLED; + } + + address_space_read(&address_space_memory, + buf_addr + offsetof(struct igb_mig_dirty_query, iov= a), + MEMTXATTRS_UNSPECIFIED, &range_iova, sizeof(range_i= ova)); + range_iova =3D le64_to_cpu(range_iova); + address_space_read(&address_space_memory, + buf_addr + offsetof(struct igb_mig_dirty_query, siz= e), + MEMTXATTRS_UNSPECIFIED, &range_size, sizeof(range_s= ize)); + range_size =3D le64_to_cpu(range_size); + + range =3D igb_core_vf_dirty_range_valid(ds, range_iova, range_size); + if (!range) { + return IGB_MIG_ERR_BAD_RANGE; + } + + bmp_bytes =3D BITS_TO_LONGS(range_size / range->page_size) * + sizeof(unsigned long); + bitmap =3D g_malloc0(bmp_bytes); + + igb_core_vf_dirty_query(range, range_iova, range_size, + bitmap, bmp_bytes, &out_size); + + if (out_size) { + if (address_space_write(&address_space_memory, + buf_addr + + offsetof(struct igb_mig_dirty_query, bitma= p), + MEMTXATTRS_UNSPECIFIED, bitmap, out_size))= { + return IGB_MIG_ERR_DMA_FAILED; + } + } + + igb_core_vf_dirty_query_commit(range, range_iova, range_size); + + dirty_pages =3D bitmap_count_one(bitmap, range_size / range->page_size= ); + + val32 =3D cpu_to_le32(out_size); + address_space_write(&address_space_memory, + buf_addr + offsetof(struct igb_mig_dirty_query, + bitmap_size), + MEMTXATTRS_UNSPECIFIED, &val32, sizeof(val32)); + val32 =3D cpu_to_le32(dirty_pages); + address_space_write(&address_space_memory, + buf_addr + offsetof(struct igb_mig_dirty_query, + dirty_page_count), + MEMTXATTRS_UNSPECIFIED, &val32, sizeof(val32)); + + trace_igbvf_mig_dirty_query(s->vfn, (uint64_t)out_size, dirty_pages); + return 0; +} + /* * Migration command handlers */ @@ -821,7 +1109,8 @@ static uint8_t igbvf_mig_cmd_save(IgbVfState *s) MemTxResult r; int ret; =20 - if (ms->mig_state !=3D IGB_MIG_STATE_STOP_COPY) { + if (ms->mig_state !=3D IGB_MIG_STATE_STOP_COPY && + ms->mig_state !=3D IGB_MIG_STATE_PRE_COPY) { return IGB_MIG_ERR_BAD_STATE; } =20 @@ -890,22 +1179,33 @@ static uint8_t igbvf_mig_set_state(IgbVfState *s, ui= nt32_t new_state) case IGB_MIG_STATE_STOP: if (old !=3D IGB_MIG_STATE_RUNNING && old !=3D IGB_MIG_STATE_STOP_COPY && + old !=3D IGB_MIG_STATE_PRE_COPY && old !=3D IGB_MIG_STATE_RESUMING && old !=3D IGB_MIG_STATE_ERROR) { return IGB_MIG_ERR_BAD_STATE; } + if (old =3D=3D IGB_MIG_STATE_PRE_COPY || + old =3D=3D IGB_MIG_STATE_STOP_COPY || + old =3D=3D IGB_MIG_STATE_ERROR) { + igb_core_vf_dirty_disable(s); + } /* Restore DATA_SIZE to default max */ igbvf_mig_update_data_size(s, igb_core_vf_max_data_size(s)); break; =20 case IGB_MIG_STATE_RUNNING: - if (old !=3D IGB_MIG_STATE_STOP) { + if (old !=3D IGB_MIG_STATE_STOP && + old !=3D IGB_MIG_STATE_PRE_COPY) { return IGB_MIG_ERR_BAD_STATE; } + if (old =3D=3D IGB_MIG_STATE_PRE_COPY) { + igb_core_vf_dirty_disable(s); + } break; =20 case IGB_MIG_STATE_STOP_COPY: - if (old !=3D IGB_MIG_STATE_STOP) { + if (old !=3D IGB_MIG_STATE_STOP && + old !=3D IGB_MIG_STATE_PRE_COPY) { return IGB_MIG_ERR_BAD_STATE; } ret =3D igb_core_vf_save_state(s, ms->mig_data, sizeof(ms->mig_dat= a)); @@ -923,6 +1223,12 @@ static uint8_t igbvf_mig_set_state(IgbVfState *s, uin= t32_t new_state) igbvf_mig_update_data_size(s, 0); break; =20 + case IGB_MIG_STATE_PRE_COPY: + if (old !=3D IGB_MIG_STATE_RUNNING) { + return IGB_MIG_ERR_BAD_STATE; + } + break; + default: return IGB_MIG_ERR_BAD_STATE; } @@ -971,6 +1277,18 @@ static void igbvf_mig_cmd_ctrl(IgbVfState *s, uint32_= t val) err =3D igbvf_mig_cmd_load(s, arg); break; =20 + case IGB_MIG_CMD_DIRTY_ENABLE: + err =3D igbvf_mig_cmd_dirty_enable(s); + break; + + case IGB_MIG_CMD_DIRTY_DISABLE: + igb_core_vf_dirty_disable(s); + break; + + case IGB_MIG_CMD_DIRTY_QUERY: + err =3D igbvf_mig_cmd_dirty_query(s); + break; + default: err =3D IGB_MIG_ERR_UNK_CMD; break; @@ -1009,8 +1327,10 @@ bool igbvf_add_migration_dvsec(IgbVfState *s, Error = **errp) /* DVSEC header 2: DVSEC ID */ pci_set_word(dev->config + offset + 0x8, IGB_MIG_DVSEC_ID); =20 - /* CAPS: features (state migration only) */ - caps =3D IGB_MIG_CAP_F_STATE; + /* CAPS: features | max_ranges | supported page sizes (4K) */ + caps =3D IGB_MIG_CAP_F_STATE | IGB_MIG_CAP_F_DIRTY | + (IGB_MIG_CAPS_MAX_RANGES << IGB_MIG_CAPS_MAX_RANGES_SHIFT) | + IGB_MIG_CAPS_PGSIZE_4K; pci_set_long(dev->config + offset + IGB_MIG_CAPS, caps); =20 /* diff --git a/hw/net/trace-events b/hw/net/trace-events index a8cc72b69d0f..a171888db380 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -299,10 +299,17 @@ igbvf_wrn_io_addr_unknown(uint64_t addr) "IO unknown = register 0x%"PRIx64 igbvf_mig_cmd(uint16_t vfn, uint32_t cmd, uint32_t arg, uint32_t state) "V= F%u: cmd %u arg %u (mig_state=3D%u)" igbvf_mig_status(uint16_t vfn, uint32_t status) "VF%u: status 0x%x" igbvf_mig_set_state(uint16_t vfn, uint32_t old_state, uint32_t new_state) = "VF%u: state %u -> %u" -igbvf_mig_save_state(uint16_t vfn, uint32_t size) "VF%u: saved %u bytes of= device state" -igbvf_mig_load_state(uint16_t vfn, uint32_t size) "VF%u: loaded %u bytes o= f device state" +igbvf_mig_save_state(uint16_t vfn, int size, bool vfre, bool vfte, uint32_= t reg_vfre) "VF%u: saved %d bytes vfre=3D%d vfte=3D%d VFRE=3D0x%x" +igbvf_mig_load_state(uint16_t vfn, uint32_t size, bool vfre, bool vfte) "V= F%u: loaded %u bytes vfre=3D%d vfte=3D%d" igbvf_mig_save_hash_tables(uint16_t vfn, const char *name, int index, uint= 32_t value) "VF%u: %s[%d]=3D0x%x" igbvf_mig_reset(uint16_t vfn) "VF%u: migration state reset" +igbvf_mig_dirty_enable(uint16_t vfn, uint64_t pgsize, uint64_t nbits) "VF%= u: dirty tracking enabled pgsize=3D%"PRIu64" nbits=3D%"PRIu64 +igbvf_mig_dirty_disable(uint16_t vfn) "VF%u: dirty tracking disabled" +igbvf_mig_dirty_query(uint16_t vfn, uint64_t size, uint32_t dirty_pages) "= VF%u: dirty query returned %"PRIu64" bytes, %u dirty pages" +igb_core_dirty_track_dma(int vfn, uint64_t addr, uint64_t len) "VF%d: dirt= y DMA addr=3D0x%"PRIx64" len=3D%"PRIu64 +igb_core_dirty_track_dma_drop(int vfn, uint64_t addr, uint64_t len) "VF%d:= dirty DMA dropped addr=3D0x%"PRIx64" len=3D%"PRIu64" no matching range" +igbvf_mig_quiesce(uint16_t vfn, uint32_t vfre, uint32_t vfte) "VF%u: quies= ce VFRE=3D0x%x VFTE=3D0x%x" +igbvf_mig_unquiesce(uint16_t vfn, uint32_t vfre, uint32_t vfte) "VF%u: unq= uiesce VFRE=3D0x%x VFTE=3D0x%x" =20 # spapr_llan.c spapr_vlan_get_rx_bd_from_pool_found(int pool, int32_t count, uint32_t rx_= bufs) "pool=3D%d count=3D%"PRId32" rxbufs=3D%"PRIu32 --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967722; cv=none; d=zohomail.com; s=zohoarc; b=XYwm07WCvFf0lN8g4OPZ9p7JSTiZQIzGaSfO/KEpfEYVemcc9i9Hd9TGE9jXCguZ0MW6rclakb7U66C3pqqnVTRa/JkipNiTlg9CpoA4EvGkCmGPpM36zTaWr1KVGyhg3PnqTHWdej1nggAAnLZMf4WrCHVDAVN0ZYX7+s0Up64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967722; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=weYNgF9+56KYGJ1jmV7oNRyWQIz7MbqGlNWsKqCt10E=; b=Ub2IhG+hnY5968mKFdT4ydQuet4LeAKaKWjAH4/eRbPkbNpCWrQRPbozXzPLXSyrOOiYuoMaNFw1OxHwLuukhXHNaGxM+3hrN1mJ+vU7yPKoOBhw9KXCPEsERqQOII1VucCXsD5QtOO1IRQb2FLLsttwaWCcP2OdSSsJ7NvoJl4= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967722853917.3136798417873; Wed, 14 Oct 2026 01:48:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuem-0005iy-Ku; Wed, 14 Oct 2026 04:48:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueK-0005ZZ-Ul for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:52 -0400 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 1xGueJ-0004a5-5L for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:48 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-bKLuOSWwPlq2saB6v_gULQ-1; Wed, 14 Oct 2026 08:47:41 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B17EB195608E; Wed, 14 Oct 2026 08:47:40 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC7B51800642; Wed, 14 Oct 2026 08:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967665; 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=weYNgF9+56KYGJ1jmV7oNRyWQIz7MbqGlNWsKqCt10E=; b=UBkDmSmP+gOLS+mUmZTw98kdkrhT/3fs3EMn89R6VfSPcYR2vLHyl/fFWMuxejCChNT+TU D8wJUpV1lm4dlZN2olGqfvmsf9aMIFH3/KewfpxR8rDT//cXRsy34ikrISOQiGFwqBFyuS Taq9nOJ8wHc3JQXlYVe+aM2rdS01mJI= X-MC-Unique: bKLuOSWwPlq2saB6v_gULQ-1 X-Mimecast-MFC-AGG-ID: bKLuOSWwPlq2saB6v_gULQ_1791967660 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 12/17] igb: Quiesce VFs on STOP and include PF enable state in migration Date: Wed, 14 Oct 2026 10:46:50 +0200 Message-ID: <20261014084655.127254-13-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967723593158500 Quiesce VFs by clearing VFRE/VFTE on transitions to STOP or STOP_COPY, preventing DMA while device state is serialized. Restore saved VFRE/VFTE on STOP->RUNNING. Include per-VF VFRE/VFTE enable bits in the migration blob so the destination can restore the pre-quiesce state. Add a QUIESCED bit to STATUS for the driver to confirm DMA has drained. Clear VFLRE before state restore on the destination to prevent stale reset indications. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.h | 6 ++- hw/net/igb_migration.c | 86 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index 4968798509aa..841fc512d228 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -24,7 +24,8 @@ * +0x0C CAPS (RO: F_STATE[0], F_DIRTY[1], * max_ranges[11:8], pgsize[16:12]) * +0x10 CTRL (WO: doorbell command) - * +0x14 STATUS (RO: state[7:0], error_code[15:8]) + * +0x14 STATUS (RO: state[7:0], error_code[15:8], + * QUIESCED[16]) * +0x18 BUF_ADDR_LO (RW: shared buffer GPA low) * +0x1C BUF_ADDR_HI (RW: shared buffer GPA high) * +0x20 DATA_SIZE (RO: state blob size in bytes) @@ -71,6 +72,7 @@ #define IGB_MIG_STATUS_ERROR_CODE_SHIFT 8 #define IGB_MIG_STATUS_ERR(code) \ ((uint32_t)(code) << IGB_MIG_STATUS_ERROR_CODE_SHIFT) +#define IGB_MIG_STATUS_QUIESCED (1u << 16) =20 /* Device states (based on VFIO migration v2) */ #define IGB_MIG_STATE_ERROR 0 @@ -104,6 +106,8 @@ typedef struct IgbVfMigState { uint32_t mig_data[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; uint32_t mig_data_size; uint64_t mig_data_buf_addr; + bool mig_saved_vfre; + bool mig_saved_vfte; } IgbVfMigState; =20 #define IGB_MIG_DIRTY_DEFAULT_PGSIZE 4096 diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index efa2f5a8d333..80098e62daea 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -64,6 +64,8 @@ typedef struct IgbMigBlob { uint32_t vlvf[IGB_VF_MAX_VLVF_REGS]; uint32_t mta[E1000_MC_TBL_SIZE]; uint32_t uta[E1000_MC_TBL_SIZE]; + uint32_t vfre; + uint32_t vfte; } IgbMigBlob; =20 #define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) @@ -530,6 +532,7 @@ static void igb_core_vf_save_tx_ctx(IGBCore *core, int = queue, static int igb_core_vf_save_state(IgbVfState *s, void *buf, size_t buf_siz= e) { int size =3D IGB_MIG_BLOB_SIZE; + IgbVfMigState *ms =3D &s->mig; IGBCore *core =3D igbvf_get_core(s); IgbMigBlob *blob =3D buf; uint32_t offsets[IGB_VF_MAX_FIXED_REGS]; @@ -568,7 +571,12 @@ static int igb_core_vf_save_state(IgbVfState *s, void = *buf, size_t buf_size) =20 igb_core_vf_save_hash_tables(core, s->vfn, blob); =20 - trace_igbvf_mig_save_state(s->vfn, size); + blob->vfre =3D cpu_to_le32(ms->mig_saved_vfre); + blob->vfte =3D cpu_to_le32(ms->mig_saved_vfte); + + trace_igbvf_mig_save_state(s->vfn, size, ms->mig_saved_vfre, + ms->mig_saved_vfte, + core->mac[VFRE]); return size; } =20 @@ -681,6 +689,7 @@ static void igb_core_vf_load_tx_ctx(IGBCore *core, int = queue, =20 static int igb_core_vf_load_state(IgbVfState *s, const void *buf, size_t s= ize) { + IgbVfMigState *ms =3D &s->mig; IGBCore *core =3D igbvf_get_core(s); int q0 =3D s->vfn; int q1 =3D s->vfn + IGB_NUM_VM_POOLS; @@ -787,13 +796,25 @@ static int igb_core_vf_load_state(IgbVfState *s, cons= t void *buf, size_t size) /* Propagate VTIVAR to IVAR0, skipped by direct core->mac[] write */ igb_core_vf_propagate_ivar(core, s->vfn); =20 - trace_igbvf_mig_load_state(s->vfn, (uint32_t)size); + ms->mig_saved_vfre =3D !!le32_to_cpu(blob->vfre); + ms->mig_saved_vfte =3D !!le32_to_cpu(blob->vfte); + + trace_igbvf_mig_load_state(s->vfn, (uint32_t)size, + ms->mig_saved_vfre, + ms->mig_saved_vfte); return 0; } =20 static int igbvf_mig_load(IgbVfState *s, const void *buf, size_t size) { int ret; + IGBCore *core =3D igbvf_get_core(s); + + /* + * Pre-load: Clear the VFLRE bit before restoring state so the PF + * watchdog does not overwrite what we are about to load. + */ + core->mac[VFLRE] &=3D ~BIT(s->vfn); =20 ret =3D igb_core_vf_load_state(s, buf, size); if (ret < 0) { @@ -1169,6 +1190,43 @@ static uint8_t igbvf_mig_cmd_load(IgbVfState *s, uin= t32_t data_size) return 0; } =20 +/* Quiesce a VF by disabling its RX and TX at the PF level. */ +static void igb_core_vf_quiesce(IgbVfState *s) +{ + IgbVfMigState *ms =3D &s->mig; + IGBCore *core =3D igbvf_get_core(s); + + ms->mig_saved_vfre =3D !!(core->mac[VFRE] & BIT(s->vfn)); + ms->mig_saved_vfte =3D !!(core->mac[VFTE] & BIT(s->vfn)); + + core->mac[VFRE] &=3D ~BIT(s->vfn); + core->mac[VFTE] &=3D ~BIT(s->vfn); + trace_igbvf_mig_quiesce(s->vfn, core->mac[VFRE], core->mac[VFTE]); +} + +static void igb_core_vf_unquiesce(IgbVfState *s) +{ + IgbVfMigState *ms =3D &s->mig; + IGBCore *core =3D igbvf_get_core(s); + bool re =3D ms->mig_saved_vfre; + bool te =3D ms->mig_saved_vfte; + + if (re) { + core->mac[VFRE] |=3D BIT(s->vfn); + } else { + core->mac[VFRE] &=3D ~BIT(s->vfn); + } + if (te) { + core->mac[VFTE] |=3D BIT(s->vfn); + } else { + core->mac[VFTE] &=3D ~BIT(s->vfn); + } + + trace_igbvf_mig_unquiesce(s->vfn, core->mac[VFRE], core->mac[VFTE]); + + /* Interrupt mask restore and pending cause re-raise added later. */ +} + static uint8_t igbvf_mig_set_state(IgbVfState *s, uint32_t new_state) { IgbVfMigState *ms =3D &s->mig; @@ -1189,6 +1247,11 @@ static uint8_t igbvf_mig_set_state(IgbVfState *s, ui= nt32_t new_state) old =3D=3D IGB_MIG_STATE_ERROR) { igb_core_vf_dirty_disable(s); } + if (old =3D=3D IGB_MIG_STATE_RUNNING || + old =3D=3D IGB_MIG_STATE_PRE_COPY || + old =3D=3D IGB_MIG_STATE_ERROR) { + igb_core_vf_quiesce(s); + } /* Restore DATA_SIZE to default max */ igbvf_mig_update_data_size(s, igb_core_vf_max_data_size(s)); break; @@ -1201,6 +1264,9 @@ static uint8_t igbvf_mig_set_state(IgbVfState *s, uin= t32_t new_state) if (old =3D=3D IGB_MIG_STATE_PRE_COPY) { igb_core_vf_dirty_disable(s); } + if (old =3D=3D IGB_MIG_STATE_STOP) { + igb_core_vf_unquiesce(s); + } break; =20 case IGB_MIG_STATE_STOP_COPY: @@ -1208,8 +1274,14 @@ static uint8_t igbvf_mig_set_state(IgbVfState *s, ui= nt32_t new_state) old !=3D IGB_MIG_STATE_PRE_COPY) { return IGB_MIG_ERR_BAD_STATE; } + if (old =3D=3D IGB_MIG_STATE_PRE_COPY) { + igb_core_vf_quiesce(s); + } ret =3D igb_core_vf_save_state(s, ms->mig_data, sizeof(ms->mig_dat= a)); if (ret < 0) { + if (old =3D=3D IGB_MIG_STATE_PRE_COPY) { + igb_core_vf_unquiesce(s); + } return -ret; } igbvf_mig_update_data_size(s, ret); @@ -1251,6 +1323,16 @@ static void igbvf_mig_update_status(IgbVfState *s, u= int8_t err) status =3D IGB_MIG_STATE_ERROR | IGB_MIG_STATUS_ERR(err); } =20 + /* + * QUIESCED tells the driver it is safe to read device state. + * In STOP and STOP_COPY, igb_core_vf_quiesce() has already + * cleared VFRE/VFTE so no further VF DMA can occur. + */ + if (ms->mig_state =3D=3D IGB_MIG_STATE_STOP || + ms->mig_state =3D=3D IGB_MIG_STATE_STOP_COPY) { + status |=3D IGB_MIG_STATUS_QUIESCED; + } + pci_set_long(dev->config + IGB_MIG_DVSEC_OFFSET + IGB_MIG_STATUS, stat= us); trace_igbvf_mig_status(s->vfn, status); } --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967720; cv=none; d=zohomail.com; s=zohoarc; b=W2sD36EOIkpwPCZ78uUOc80wLchNzl1T+6wEmONK+cuEjZLhhme+w1wn/tCXUxiCRhd3QaWRug3aE9g5KLDTgMMiG0VWhJcpzH2D6fwjRa1P8Aq3hm8R++O3XZ1W/gFkXOuIQhDIyEqGMf2cpFw1zQL4d01IeNqzBnByJYPkjY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967720; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vy0Tf7aWlxD9+XRsYRHPkPvTpIAuohr7R2Rk3JZXnSU=; b=mhAjzOpZk4vA73jxlnZSbbQEkQNaZ+ZPjxYkadaW6BwHFV/URS4HVsaL2iNEBXzrGJo0xcjxs7bnAeOYbxRa44mcYoOB1eG1y76qeIgV0UlNW3FRvNe3/WfxIZ8I3XD8Qi0XfydQks+lYWXey4pGcQBEruhSoqUzG6x55AEMJjA= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967720735719.3062500044512; Wed, 14 Oct 2026 01:48:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuf4-00068E-O1; Wed, 14 Oct 2026 04:48:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueM-0005bH-DK for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:53 -0400 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 1xGueK-0004aC-FU for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:50 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-dAvgJxoaN4COjFxbWRRC-g-1; Wed, 14 Oct 2026 08:47:44 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5AF65180058A; Wed, 14 Oct 2026 08:47:43 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2F1F81800345; Wed, 14 Oct 2026 08:47:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967667; 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=vy0Tf7aWlxD9+XRsYRHPkPvTpIAuohr7R2Rk3JZXnSU=; b=SUhBM36+TQUUWBJdBkrwGsR3FR2bxV4tWGBYYm8YCkKf0K+paYZdkE+y4QZl5mRPnnF23p 8LXKA+gE1rdTkk8uZ1x4RhnTBzQmC1sfuWGMANN5+dVWX1I24CQ+9nGuf8Sf1Rp6oATXT4 SKCD3gpgFCn0cAPpy6hCWhvK2z3r0h8= X-MC-Unique: dAvgJxoaN4COjFxbWRRC-g-1 X-Mimecast-MFC-AGG-ID: dAvgJxoaN4COjFxbWRRC-g_1791967663 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 13/17] igb: Save and restore effective VF interrupt masks for migration Date: Wed, 14 Oct 2026 10:46:51 +0200 Message-ID: <20261014084655.127254-14-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1791967721594158500 The PVT shadow registers (PVTEIMS/PVTEIAC/PVTEIAM) record the last VF write, not the effective accumulated state. The actual effective mask lives in the PF aggregate EIMS/EIAC/EIAM registers. Capture the VF's effective mask bits from the PF aggregates at quiesce entry, before disabling VFRE/VFTE. Store them in the blob and restore via igb_core_vf_restore_irqs() on unquiesce paths. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_migration.h | 3 ++ hw/net/igb_migration.c | 68 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index 841fc512d228..96dfe99468d1 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -108,6 +108,9 @@ typedef struct IgbVfMigState { uint64_t mig_data_buf_addr; bool mig_saved_vfre; bool mig_saved_vfte; + uint32_t mig_saved_eims; + uint32_t mig_saved_eiac; + uint32_t mig_saved_eiam; } IgbVfMigState; =20 #define IGB_MIG_DIRTY_DEFAULT_PGSIZE 4096 diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 80098e62daea..72f01beb2ad0 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -66,6 +66,9 @@ typedef struct IgbMigBlob { uint32_t uta[E1000_MC_TBL_SIZE]; uint32_t vfre; uint32_t vfte; + uint32_t eims_bits; + uint32_t eiac_bits; + uint32_t eiam_bits; } IgbMigBlob; =20 #define IGB_MIG_BLOB_SIZE sizeof(IgbMigBlob) @@ -574,6 +577,14 @@ static int igb_core_vf_save_state(IgbVfState *s, void = *buf, size_t buf_size) blob->vfre =3D cpu_to_le32(ms->mig_saved_vfre); blob->vfte =3D cpu_to_le32(ms->mig_saved_vfte); =20 + /* + * Save VF's effective interrupt mask bits captured at quiesce + * entry, before VFRE/VFTE were disabled. + */ + blob->eims_bits =3D cpu_to_le32(ms->mig_saved_eims); + blob->eiac_bits =3D cpu_to_le32(ms->mig_saved_eiac); + blob->eiam_bits =3D cpu_to_le32(ms->mig_saved_eiam); + trace_igbvf_mig_save_state(s->vfn, size, ms->mig_saved_vfre, ms->mig_saved_vfte, core->mac[VFRE]); @@ -798,6 +809,9 @@ static int igb_core_vf_load_state(IgbVfState *s, const = void *buf, size_t size) =20 ms->mig_saved_vfre =3D !!le32_to_cpu(blob->vfre); ms->mig_saved_vfte =3D !!le32_to_cpu(blob->vfte); + ms->mig_saved_eims =3D le32_to_cpu(blob->eims_bits) & 0x7; + ms->mig_saved_eiac =3D le32_to_cpu(blob->eiac_bits) & 0x7; + ms->mig_saved_eiam =3D le32_to_cpu(blob->eiam_bits) & 0x7; =20 trace_igbvf_mig_load_state(s->vfn, (uint32_t)size, ms->mig_saved_vfre, @@ -1190,12 +1204,58 @@ static uint8_t igbvf_mig_cmd_load(IgbVfState *s, ui= nt32_t data_size) return 0; } =20 +/* + * Extended Interrupt registers + * + * EIMS Mask Set enable interrupt vectors (unmasked) + * EIAC Auto Clear auto-clear vectors in EICR on delivery + * EIAM Auto Mask auto-mask vectors (clear EIMS) on delivery + * + * All three are PF-wide aggregate registers. Each VF owns 3 bits (one + * per MSI-X vector) at position (22 - vfn*3). The VF writes to PVT + * shadows (PVTEIMS etc.) which the register handler ORs into the + * aggregates but EIMC clears the aggregate without updating the + * shadow. + */ +static void igb_core_vf_save_irqs(IGBCore *core, uint16_t vfn, + uint32_t *eims, uint32_t *eiac, + uint32_t *eiam) +{ + uint32_t shift =3D 22 - vfn * IGBVF_MSIX_VEC_NUM; + + *eims =3D (core->mac[EIMS] >> shift) & 0x7; + *eiac =3D (core->mac[EIAC] >> shift) & 0x7; + *eiam =3D (core->mac[EIAM] >> shift) & 0x7; +} + +static void igb_core_vf_restore_irqs(IGBCore *core, uint16_t vfn, + uint32_t eims, uint32_t eiac, + uint32_t eiam) +{ + uint32_t shift =3D 22 - vfn * IGBVF_MSIX_VEC_NUM; + uint32_t vf_mask =3D 0x7u << shift; + + core->mac[EIMS] =3D (core->mac[EIMS] & ~vf_mask) | ((eims & 0x7) << sh= ift); + core->mac[EIAC] =3D (core->mac[EIAC] & ~vf_mask) | ((eiac & 0x7) << sh= ift); + core->mac[EIAM] =3D (core->mac[EIAM] & ~vf_mask) | ((eiam & 0x7) << sh= ift); + core->mac[EICR] &=3D ~vf_mask; +} + /* Quiesce a VF by disabling its RX and TX at the PF level. */ static void igb_core_vf_quiesce(IgbVfState *s) { IgbVfMigState *ms =3D &s->mig; IGBCore *core =3D igbvf_get_core(s); =20 + /* + * Capture effective interrupt mask bits from PF aggregates before + * quiescing. PVT shadows only record the last write, not the + * accumulated state. + */ + igb_core_vf_save_irqs(core, s->vfn, + &ms->mig_saved_eims, &ms->mig_saved_eiac, + &ms->mig_saved_eiam); + ms->mig_saved_vfre =3D !!(core->mac[VFRE] & BIT(s->vfn)); ms->mig_saved_vfte =3D !!(core->mac[VFTE] & BIT(s->vfn)); =20 @@ -1224,7 +1284,13 @@ static void igb_core_vf_unquiesce(IgbVfState *s) =20 trace_igbvf_mig_unquiesce(s->vfn, core->mac[VFRE], core->mac[VFTE]); =20 - /* Interrupt mask restore and pending cause re-raise added later. */ + /* + * Restore VF's effective interrupt mask bits into PF aggregate + * registers. + */ + igb_core_vf_restore_irqs(core, s->vfn, + ms->mig_saved_eims, ms->mig_saved_eiac, + ms->mig_saved_eiam); } =20 static uint8_t igbvf_mig_set_state(IgbVfState *s, uint32_t new_state) --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967786; cv=none; d=zohomail.com; s=zohoarc; b=NgMagJYCYdaK7nAeylorjMQtSHZ+z49a+FuQggzCtZMNP6qO+Mgwxn+lg4BuX2IGg/HeCznQKaeIMCm1qD3CYN5zVMIh0brfmLkdyKo8B/ug0VYD0fayKRj90CQpI0njFgh0BqBvb01pV+ShX3517J15UEIQxYzkCpkKfy78S0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967786; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bBipUCO0pIVGluDuzY5tUM9V4yAIVJuvdld12lAMyio=; b=L6v385UlFGH8mC+8B24y88lQjaayF4HBrHQbsbE10VEqkEULmmbn6x9KnoI3tbpPD9skIMD4xQcNZMRFM9qeOPxemQbDjkNmhT0CHkn9eB9yrLVMQkLwQOmtKUdYyckrOwyHxL/cLdEyIYDMyrpiFjbvPwM0OYXI1KTXE22DtiY= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17919677867811010.0180128706709; Wed, 14 Oct 2026 01:49:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuf5-0006EF-S6; Wed, 14 Oct 2026 04:48:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueQ-0005dp-W4 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:58 -0400 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 1xGueP-0004aU-5m for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:54 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-GWTiqPw4P46DtcwJntDVJA-1; Wed, 14 Oct 2026 08:47:47 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0717619560B3; Wed, 14 Oct 2026 08:47:46 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CD6411800345; Wed, 14 Oct 2026 08:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967672; 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=bBipUCO0pIVGluDuzY5tUM9V4yAIVJuvdld12lAMyio=; b=SSWD/IxxUy/oDfBfeBSPUZzctXHuyoK9Jg1Lf6zT6syKv5BFz2TAYOxzRneFk9y3ejWhI7 dvl6Ou4AwqGjoKel1iENdltaBUxwfmVZqix2K6rqdZUOyDTyKGnEJPGv6DdbymX3hbF5AG k/Q8obvw1X9Ar15ZMXRWlTihwhFM0Kw= X-MC-Unique: GWTiqPw4P46DtcwJntDVJA-1 X-Mimecast-MFC-AGG-ID: GWTiqPw4P46DtcwJntDVJA_1791967666 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 14/17] igb: Re-raise pending VF interrupt causes on unquiesce Date: Wed, 14 Oct 2026 10:46:52 +0200 Message-ID: <20261014084655.127254-15-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967788821158500 After restoring VFRE/VFTE, the VF's RX and TX rings may be stalled because the guest driver is waiting for an interrupt that was pending at the time of migration. Add igb_core_vf_raise_causes() to re-inject pending EICR causes on unquiesce, resuming interrupt delivery to the guest and kicking the RX and TX rings. AI-used-for: analysis, code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_core.h | 1 + hw/net/igb_core.c | 14 ++++++++++++++ hw/net/igb_migration.c | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/hw/net/igb_core.h b/hw/net/igb_core.h index 5a15433da2c2..75780f68dffb 100644 --- a/hw/net/igb_core.h +++ b/hw/net/igb_core.h @@ -150,5 +150,6 @@ igb_start_recv(IGBCore *core); IGBCore *igb_pf_get_core(void *pf); =20 void igb_core_vf_propagate_ivar(IGBCore *core, uint16_t vfn); +void igb_core_vf_raise_causes(IGBCore *core, uint16_t vfn); =20 #endif diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 452bae06ee92..09e4e3926905 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -4603,3 +4603,17 @@ void igb_core_vf_propagate_ivar(IGBCore *core, uint1= 6_t vfn) core->mac[IVAR0 + n / 4] &=3D ~mask; } } + +/* + * Raise pending VF interrupt causes without re-propagating masks. + */ +void igb_core_vf_raise_causes(IGBCore *core, uint16_t vfn) +{ + uint32_t shift =3D 22 - vfn * IGBVF_MSIX_VEC_NUM; + uint32_t pvt_idx =3D PVTEICR0 + vfn * 0x40; + uint32_t causes =3D (core->mac[pvt_idx] & 0x7) << shift; + + if (causes) { + igb_set_eics(core, EICS, causes); + } +} diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index 72f01beb2ad0..ab80dbb5c6c6 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -1291,6 +1291,11 @@ static void igb_core_vf_unquiesce(IgbVfState *s) igb_core_vf_restore_irqs(core, s->vfn, ms->mig_saved_eims, ms->mig_saved_eiac, ms->mig_saved_eiam); + + /* Re-inject pending VF interrupt causes to resume RX/TX ring polling = */ + if (re || te) { + igb_core_vf_raise_causes(core, s->vfn); + } } =20 static uint8_t igbvf_mig_set_state(IgbVfState *s, uint32_t new_state) --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967788; cv=none; d=zohomail.com; s=zohoarc; b=BffX4+5yw4fq6+df6zZ3OB+RuYBnBaM69m60Sao5tKX9EOmlYyFaVapScrlsVOgH0ScVFBgO/nLj3yuqpzYW0pEDA6q2qYQ528FHpmpKi0wDoidAykzW9vextLo4dnVxnpH89nFgi7rBAC0h1KO/xWggU7gbfPTVgbWW6vr4Ltc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967788; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+o+Marw5FWNlQbRhb4nqCDgNy13bdt7p4Qdx355J3m4=; b=P8WjVyCQBIXuup04mnDhxAVF/oOXhim6nQasLDeNF0mCLfRPZYayqKejScucC9guUaziP7Bk10GJQgkTnIZaUU513ayN42siTF/jTt9tOBt9+cjL+7LHuTXsARIhKLUtpNW/0+QRIIgsIy0uP7IcjpzsttBUuJKhm46COWs05SU= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967788265588.9352265787634; Wed, 14 Oct 2026 01:49:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGufA-0006ag-Q3; Wed, 14 Oct 2026 04:48:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueU-0005h1-B5 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:48:00 -0400 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 1xGueR-0004ah-R7 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:47:57 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-Gjj-AP9LPJyZj5_0OLUesQ-1; Wed, 14 Oct 2026 08:47:49 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A6F5F180061E; Wed, 14 Oct 2026 08:47:48 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 78EF71800345; Wed, 14 Oct 2026 08:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967675; 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=+o+Marw5FWNlQbRhb4nqCDgNy13bdt7p4Qdx355J3m4=; b=WL3lkOlCIznY9PxoSqf/vHlF1mPXKXzoRL9GpYO63EpPjqcX7vzicP6wbdvHI00LqBTjFs vSYR3FoPkYlVRmF6SdrW1xWHsZS33ztnqaBY06CEQOx2rqE3itrstqzQpjkCTqKpbIMF95 LIaHdAGvLzNEs0pj2BvsIOJ+I0mb7W4= X-MC-Unique: Gjj-AP9LPJyZj5_0OLUesQ-1 X-Mimecast-MFC-AGG-ID: Gjj-AP9LPJyZj5_0OLUesQ_1791967668 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 15/17] igb: Add dirty page tracking statistics Date: Wed, 14 Oct 2026 10:46:53 +0200 Message-ID: <20261014084655.127254-16-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1791967788798158500 Add a GET_STATS command (cmd 7) to the migration DVSEC for monitoring dirty page tracking and DMA activity per VF. The device DMA-writes an igb_mig_stats_resp struct to the shared buffer. The dma_writes counter is also reported in the dirty query buffer so the driver gets it alongside the bitmap without an extra config read. Counters are reset on first DIRTY_ENABLE, so the driver can read final values after DIRTY_DISABLE. AI-used-for: code (prototype) Signed-off-by: C=C3=A9dric Le Goater --- hw/net/igb_core.h | 1 + hw/net/igb_migration.h | 22 +++++++++++++++ hw/net/igb_migration.c | 63 ++++++++++++++++++++++++++++++++++++++++-- hw/net/trace-events | 2 +- 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/hw/net/igb_core.h b/hw/net/igb_core.h index 75780f68dffb..e09cac48d7b1 100644 --- a/hw/net/igb_core.h +++ b/hw/net/igb_core.h @@ -103,6 +103,7 @@ struct IGBCore { int64_t timadj; =20 IGBVfDirtyState vf_dirty[IGB_MAX_VF_FUNCTIONS]; + IgbVfMigStats vf_mig_stats[IGB_MAX_VF_FUNCTIONS]; }; =20 void diff --git a/hw/net/igb_migration.h b/hw/net/igb_migration.h index 96dfe99468d1..3cb197036705 100644 --- a/hw/net/igb_migration.h +++ b/hw/net/igb_migration.h @@ -66,6 +66,7 @@ #define IGB_MIG_CMD_DIRTY_ENABLE 4 #define IGB_MIG_CMD_DIRTY_DISABLE 5 #define IGB_MIG_CMD_DIRTY_QUERY 6 +#define IGB_MIG_CMD_GET_STATS 7 =20 /* STATUS register: state in [7:0], error code [15:8] */ #define IGB_MIG_STATUS_STATE_MASK 0xFF @@ -101,6 +102,15 @@ /* Shared buffer constants */ #define IGB_VF_STATE_MAX_SIZE 4096 =20 +typedef struct IgbVfMigStats { + uint64_t dma_writes; + uint64_t dma_bytes; + uint32_t dirty_pages_set; + uint32_t dirty_pages_cleared; + uint32_t dirty_page_count; + uint32_t dirty_query_count; +} IgbVfMigStats; + typedef struct IgbVfMigState { uint32_t mig_state; uint32_t mig_data[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; @@ -157,6 +167,18 @@ struct igb_mig_dirty_query { uint8_t bitmap[]; }; =20 +/* + * GET_STATS: device writes igb_mig_stats_resp to buffer. + */ +struct igb_mig_stats_resp { + uint64_t dma_writes; + uint64_t dma_bytes; + uint32_t dirty_pages_set; + uint32_t dirty_pages_cleared; + uint32_t dirty_page_count; + uint32_t dirty_query_count; +}; + typedef struct IGBCore IGBCore; typedef struct IgbVfState IgbVfState; =20 diff --git a/hw/net/igb_migration.c b/hw/net/igb_migration.c index ab80dbb5c6c6..77ae25347eaa 100644 --- a/hw/net/igb_migration.c +++ b/hw/net/igb_migration.c @@ -854,6 +854,7 @@ void igb_core_dirty_track_dma(IGBCore *core, int vfn, dma_addr_t addr, dma_addr_t len) { IGBVfDirtyState *ds =3D &core->vf_dirty[vfn]; + IgbVfMigStats *stats =3D &core->vf_mig_stats[vfn]; bool matched =3D false; uint32_t i; =20 @@ -863,6 +864,9 @@ void igb_core_dirty_track_dma(IGBCore *core, int vfn, =20 trace_igb_core_dirty_track_dma(vfn, addr, len); =20 + stats->dma_writes++; + stats->dma_bytes +=3D len; + for (i =3D 0; i < ds->num_ranges; i++) { IGBVfDirtyRange *r =3D &ds->ranges[i]; uint64_t r_end =3D r->iova + r->size; @@ -882,7 +886,10 @@ void igb_core_dirty_track_dma(IGBCore *core, int vfn, =20 for (page =3D start_page; page <=3D end_page; page++) { if (page < r->nbits) { - set_bit(page, r->bitmap); + if (!test_and_set_bit(page, r->bitmap)) { + stats->dirty_pages_set++; + stats->dirty_page_count++; + } } } } @@ -909,6 +916,15 @@ static uint32_t igb_core_vf_dirty_enable(IgbVfState *s= , uint64_t pgsize, IGBVfDirtyState *ds =3D igb_core_vf_dirty_state(s); IGBVfDirtyRange *r; =20 + /* + * Reset stats on first enable so the driver can read them after + * disable + */ + if (ds->num_ranges =3D=3D 0) { + memset(&igbvf_get_core(s)->vf_mig_stats[s->vfn], 0, + sizeof(IgbVfMigStats)); + } + if (ds->num_ranges >=3D IGB_MIG_CAPS_MAX_RANGES) { return IGB_MIG_ERR_TOO_MANY_RANGES; } @@ -1058,12 +1074,14 @@ static IGBVfDirtyRange *igb_core_vf_dirty_range_val= id(IGBVfDirtyState *ds, static uint8_t igbvf_mig_cmd_dirty_query(IgbVfState *s) { IgbVfMigState *ms =3D &s->mig; + IgbVfMigStats *stats =3D &igbvf_get_core(s)->vf_mig_stats[s->vfn]; IGBVfDirtyState *ds =3D &igbvf_get_core(s)->vf_dirty[s->vfn]; uint64_t buf_addr =3D ms->mig_data_buf_addr; uint64_t range_iova =3D 0, range_size =3D 0; IGBVfDirtyRange *range; uint32_t bmp_bytes, dirty_pages; uint32_t val32; + uint64_t val64; size_t out_size; g_autofree void *bitmap =3D NULL; =20 @@ -1109,6 +1127,10 @@ static uint8_t igbvf_mig_cmd_dirty_query(IgbVfState = *s) =20 dirty_pages =3D bitmap_count_one(bitmap, range_size / range->page_size= ); =20 + stats->dirty_pages_cleared +=3D dirty_pages; + stats->dirty_page_count -=3D MIN(stats->dirty_page_count, dirty_pages); + stats->dirty_query_count++; + val32 =3D cpu_to_le32(out_size); address_space_write(&address_space_memory, buf_addr + offsetof(struct igb_mig_dirty_query, @@ -1119,8 +1141,13 @@ static uint8_t igbvf_mig_cmd_dirty_query(IgbVfState = *s) buf_addr + offsetof(struct igb_mig_dirty_query, dirty_page_count), MEMTXATTRS_UNSPECIFIED, &val32, sizeof(val32)); - - trace_igbvf_mig_dirty_query(s->vfn, (uint64_t)out_size, dirty_pages); + val64 =3D cpu_to_le64(stats->dma_writes); + address_space_write(&address_space_memory, + buf_addr + offsetof(struct igb_mig_dirty_query, + dma_writes), + MEMTXATTRS_UNSPECIFIED, &val64, sizeof(val64)); + trace_igbvf_mig_dirty_query(s->vfn, (uint64_t)out_size, dirty_pages, + stats->dma_writes); return 0; } =20 @@ -1381,6 +1408,32 @@ static uint8_t igbvf_mig_set_state(IgbVfState *s, ui= nt32_t new_state) return 0; } =20 +static uint8_t igbvf_mig_cmd_get_stats(IgbVfState *s) +{ + IgbVfMigState *ms =3D &s->mig; + IgbVfMigStats *stats =3D &igbvf_get_core(s)->vf_mig_stats[s->vfn]; + struct igb_mig_stats_resp resp; + MemTxResult r; + + if (!ms->mig_data_buf_addr) { + return IGB_MIG_ERR_NO_BUFFER; + } + + resp.dma_writes =3D cpu_to_le64(stats->dma_writes); + resp.dma_bytes =3D cpu_to_le64(stats->dma_bytes); + resp.dirty_pages_set =3D cpu_to_le32(stats->dirty_pages_set); + resp.dirty_pages_cleared =3D cpu_to_le32(stats->dirty_pages_cleared); + resp.dirty_page_count =3D cpu_to_le32(stats->dirty_page_count); + resp.dirty_query_count =3D cpu_to_le32(stats->dirty_query_count); + + r =3D address_space_write(&address_space_memory, ms->mig_data_buf_addr, + MEMTXATTRS_UNSPECIFIED, &resp, sizeof(resp)); + if (r !=3D MEMTX_OK) { + return IGB_MIG_ERR_DMA_FAILED; + } + return 0; +} + static void igbvf_mig_update_status(IgbVfState *s, uint8_t err) { IgbVfMigState *ms =3D &s->mig; @@ -1442,6 +1495,10 @@ static void igbvf_mig_cmd_ctrl(IgbVfState *s, uint32= _t val) err =3D igbvf_mig_cmd_dirty_query(s); break; =20 + case IGB_MIG_CMD_GET_STATS: + err =3D igbvf_mig_cmd_get_stats(s); + break; + default: err =3D IGB_MIG_ERR_UNK_CMD; break; diff --git a/hw/net/trace-events b/hw/net/trace-events index a171888db380..ea006fd4399f 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -305,7 +305,7 @@ igbvf_mig_save_hash_tables(uint16_t vfn, const char *na= me, int index, uint32_t v igbvf_mig_reset(uint16_t vfn) "VF%u: migration state reset" igbvf_mig_dirty_enable(uint16_t vfn, uint64_t pgsize, uint64_t nbits) "VF%= u: dirty tracking enabled pgsize=3D%"PRIu64" nbits=3D%"PRIu64 igbvf_mig_dirty_disable(uint16_t vfn) "VF%u: dirty tracking disabled" -igbvf_mig_dirty_query(uint16_t vfn, uint64_t size, uint32_t dirty_pages) "= VF%u: dirty query returned %"PRIu64" bytes, %u dirty pages" +igbvf_mig_dirty_query(uint16_t vfn, uint64_t size, uint32_t dirty_pages, u= int64_t dma_writes) "VF%u: dirty query returned %"PRIu64" bytes, %u dirty p= ages (dma_writes=3D%"PRIu64")" igb_core_dirty_track_dma(int vfn, uint64_t addr, uint64_t len) "VF%d: dirt= y DMA addr=3D0x%"PRIx64" len=3D%"PRIu64 igb_core_dirty_track_dma_drop(int vfn, uint64_t addr, uint64_t len) "VF%d:= dirty DMA dropped addr=3D0x%"PRIx64" len=3D%"PRIu64" no matching range" igbvf_mig_quiesce(uint16_t vfn, uint32_t vfre, uint32_t vfte) "VF%u: quies= ce VFRE=3D0x%x VFTE=3D0x%x" --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967754; cv=none; d=zohomail.com; s=zohoarc; b=Ix9FyhmPaaRcD+wp3JrTe5rH1WcMbfaaMuxDDz1DiqhYz4N6extNm+OHptd3jxlZqwLd6H0u/LBpftDx5bo0s/GPucvKR88JAev8IyWr5zsrFyQ9UKdN4OCXlMk/pijsUAabYckBYzxwZJisoWuyEzQGKxvOFwglbFjWLpKx3lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967754; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3xl8xPwLm4AwDavbTqymYCHSpa+nhNqAyMcn9AZsXXU=; b=lMWYHa4CNxH6KDlhiN0bbjmYjzS4i3a1H9fxPMoKJDFBHPTV0WvP1Mxb20SWETIqAk43MWqkKgpsz4ucrD7RY9lC85rJ5s4lWKSYpCPhxOrJCMcByzI6RAyH6/LPS1OOBKDuxI/UmJOGgJHzvqgRGu1oSc/f64S+djiL9Meaqzk= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967754098316.56569420413325; Wed, 14 Oct 2026 01:49:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGufC-0006d0-Cp; Wed, 14 Oct 2026 04:48:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueX-0005ht-3S for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:48:01 -0400 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 1xGueU-0004am-3h for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:48:00 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-q-5AIJ75NoKk_F_DiZi5zg-1; Wed, 14 Oct 2026 08:47:52 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5318119560BD; Wed, 14 Oct 2026 08:47:51 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 248E11800446; Wed, 14 Oct 2026 08:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967676; 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=3xl8xPwLm4AwDavbTqymYCHSpa+nhNqAyMcn9AZsXXU=; b=XqDfeSvG3jvdez9ZiBl0om28UmpVZgAtDrRRhBDjcKkv0Ai8633acOvH/dmtMfIEHCwi60 Fiia311GZQRv1lyabF9jouoTXQn6t3jYEgm/vnBn3V9vc3mhm6X3v6upMCzX84nsIWe2tX Pujaxbj1z7m6JjjpbWR+/UbR6Apge8U= X-MC-Unique: q-5AIJ75NoKk_F_DiZi5zg-1 X-Mimecast-MFC-AGG-ID: q-5AIJ75NoKk_F_DiZi5zg_1791967671 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 16/17] docs: Add igb VF migration testing setup guide Date: Wed, 14 Oct 2026 10:46:54 +0200 Message-ID: <20261014084655.127254-17-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1791967756301158500 Document the igb VF migration interface: DVSEC register layout, dirty page tracking, testing setup with nested virtualization. AI-used-for: docs Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + docs/system/device-emulation.rst | 1 + docs/system/devices/igb-migration.rst | 410 ++++++++++++++++++++++++++ docs/system/devices/igb.rst | 6 + 4 files changed, 418 insertions(+) create mode 100644 docs/system/devices/igb-migration.rst diff --git a/MAINTAINERS b/MAINTAINERS index 3dd4654c9027..5a878ae7af84 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2826,6 +2826,7 @@ igb VF migration M: C=C3=A9dric Le Goater S: Maintained F: hw/net/igb_migration.* +F: docs/system/devices/igb-migration.rst =20 eepro100 M: Stefan Weil diff --git a/docs/system/device-emulation.rst b/docs/system/device-emulatio= n.rst index 40054bb7dfcc..75f423b795cd 100644 --- a/docs/system/device-emulation.rst +++ b/docs/system/device-emulation.rst @@ -90,6 +90,7 @@ Emulated Devices devices/cxl.rst devices/emmc.rst devices/igb.rst + devices/igb-migration.rst devices/ivshmem-flat.rst devices/ivshmem.rst devices/keyboard.rst diff --git a/docs/system/devices/igb-migration.rst b/docs/system/devices/ig= b-migration.rst new file mode 100644 index 000000000000..f3b47a51c1f6 --- /dev/null +++ b/docs/system/devices/igb-migration.rst @@ -0,0 +1,410 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later +.. _igb-migration: + +igb VF Migration +---------------- + +Live migration of VFIO-passthrough devices (SR-IOV VFs, vGPUs) is a +growing requirement, but real hardware with migration support is scarce +and hard to debug. An emulated device provides a fully controlled +testbed for developing and validating the entire software stack +(vfio-pci variant drivers, VFIO core migration v2 framework, QEMU, +libvirt) and for tuning complex migration policies such as downtime +convergence. It also serves as an educational reference for +understanding VFIO migration end-to-end, from device state +serialization to dirty page tracking. + +The igb device supports an experimental VF migration interface that allows +the `igb-vfio-pci`_ variant driver to migrate VF state during live +migration using the standard VFIO migration v2 protocol with stop-copy +and pre-copy support. + +This is enabled with the ``x-vf-migration`` property:: + + -device igb,x-vf-migration=3Don,... + +Each emulated VF then advertises a DVSEC discovered by the +`igb-vfio-pci`_ variant driver at bind time. This feature is +experimental (``x-`` prefix, default off). + +Architecture +~~~~~~~~~~~~ + +The target scenario is nested virtualization:: + + L0 QEMU + igb PF with x-vf-migration=3Don + =E2=94=94=E2=94=80=E2=94=80 VFs with migration DVSEC + + L1 kernel + igb-vfio-pci variant driver + translates VFIO migration v2 ioctls =E2=86=92 DVSEC config writes + + L1 QEMU (stock, unmodified) + vfio-pci device model, standard migration fd + + L2 guest + standard igbvf driver, unaware of migration + +The L1 QEMU is completely unmodified : it sees a standard VFIO +migratable device and uses the normal migration fd path. The +`igb-vfio-pci`_ variant driver handles the translation between +VFIO migration v2 ioctls and DVSEC config writes. + +Design +~~~~~~ + +The migration interface is exposed through a DVSEC at offset 0x160 +in VF extended config space (see `DVSEC register layout`_ below for +the full register map). + +Device state is serialized as a versioned blob of per-VF register +(offset, value) pairs covering control, interrupt, RX/TX queue, +receive address (RA/RA2), etc. plus TX context descriptors, +VFRE/VFTE enable bits, effective VF interrupt masks (EIMS/EIAC/EIAM), +and PF-wide MTA/UTA hash tables for comparison on load. The buffer +address is a guest physical address +(GPA) written by the driver via ``virt_to_phys``; the device accesses +guest RAM directly through the system address space. + +Dirty page tracking is implemented with per-range bitmaps maintained +in IGBCore. All VF DMA paths in ``igb_core.c`` (TX data, RX data, +descriptor writeback) are instrumented to record touched pages. The +`igb-vfio-pci`_ variant driver registers tracked IOVA ranges and +queries dirty bitmaps through a shared buffer. Buffer structures +include len, flags, and reserved fields for future extensibility. + +The dirty bitmaps are maintained inside the device, which is not +realistic for discrete NICs without on-chip DRAM. + +DVSEC register layout +~~~~~~~~~~~~~~~~~~~~~ + +The migration DVSEC (36 bytes at offset ``0x160``) uses a command +doorbell model. All commands are synchronous, the device completes +the operation before the config write returns:: + + Offset Name Access Description + +0x00 ExtCap Hdr RO PCIe extended cap (id=3D0x23, ver=3D1) + +0x04 DVSEC Hdr 1 RO length[31:20] | rev[19:16] | vendor_id[15:= 0] + +0x08 DVSEC Hdr 2 RO DVSEC ID (1) + +0x0A Reserved - Padding for DWORD alignment + +0x0C CAPS RO F_STATE[0], F_DIRTY[1], max_ranges[11:8], = pgsize[16:12] + +0x10 CTRL WO Doorbell: cmd[7:0], arg[31:8] + +0x14 STATUS RO state[7:0], error_code[15:8], quiesced[16] + +0x18 BUF_ADDR_LO RW Shared DMA buffer GPA (low 32 bits) + +0x1C BUF_ADDR_HI RW Shared DMA buffer GPA (high 32 bits) + +0x20 DATA_SIZE RO State blob size in bytes + +CTRL commands:: + + Cmd Name Arg Description + 1 SET_STATE state[31:8] Set migration state + 2 SAVE - DMA-write state to buffer + 3 LOAD size[31:8] DMA-read state from buffer + 4 DIRTY_ENABLE - Enable dirty tracking (params in DM= A buffer) + 5 DIRTY_DISABLE - Disable dirty tracking + 6 DIRTY_QUERY - Query dirty bitmap (via DMA buffer) + 7 GET_STATS - Query statistics (via DMA buffer) + +The driver sets ``BUF_ADDR_LO/HI`` before issuing commands that use a +DMA buffer (SAVE, LOAD, DIRTY_ENABLE, DIRTY_QUERY, GET_STATS). The +buffer address is latched per CTRL write, so the driver can use +different buffers for different commands. The buffer address is a +guest physical address (GPA). + +State transitions follow the VFIO migration v2 state machine. The +driver issues ``SET_STATE`` with the target state in the arg field and +reads ``STATUS`` to confirm the transition. Device states:: + + 0 ERROR 1 STOP 2 RUNNING + 3 STOP_COPY 4 RESUMING 5 PRE_COPY + +``DATA_SIZE`` reflects the state blob size. At reset and in ``STOP`` +state it holds the maximum size the driver should allocate. After +``SET_STATE(STOP_COPY)`` or ``SAVE`` it holds the actual serialized +size. The driver reads it after entering ``STOP_COPY`` to allocate an +exact-sized DMA buffer before issuing ``SAVE``. + +The state blob is a versioned sequence of register (offset, value) +pairs with magic ``0x4D494742`` ("MIGB"). + +When ``STATUS`` state is ``ERROR`` (0), bits [15:8] contain an error +code identifying the failure:: + + 1 UNK_CMD Unknown CTRL command + 2 BAD_STATE Command issued in wrong migration state + 3 NO_BUFFER Command requires buffer but BUF_ADDR not set + 4 DMA_FAILED DMA transfer to/from buffer failed + 5 BAD_SIZE State blob too large or empty + 6 BAD_MAGIC State blob magic mismatch + 7 BAD_VERSION State blob version mismatch + 8 BAD_VFN VF number mismatch on LOAD + 9 BAD_DATA Malformed state blob data + 10 UNSUPPORTED VF uses unsupported features for migration + 11 TOO_MANY_RANGES Exceeds max_ranges from CAPS + 12 BAD_RANGE Invalid range (zero size, misaligned, not containe= d) + 13 BAD_PGSIZE Invalid or misaligned page size + 14 NOT_ENABLED Dirty query without prior enable + +Dirty page tracking +~~~~~~~~~~~~~~~~~~~ + +The migration interface supports per-VF dirty page tracking, advertised +by the ``F_DIRTY`` flag (bit 1) in ``CAPS``. This allows the variant +driver to enter ``PRE_COPY`` state while the VM continues to run, +iterating on dirty pages to reduce the final stop-and-copy window. + +The device maintains one dirty tracking engine per range, each with its +own bitmap scoped to the range boundaries. The ``CAPS`` register +advertises the maximum number of ranges in bits [11:8]. + +Dirty tracking is controlled through CTRL commands: + +- **DIRTY_ENABLE** (4): the driver fills an ``igb_mig_dirty_enable_req`` + struct in the DMA buffer with the page size, range IOVA, and range + size, then issues the command. The device allocates a bitmap for the + range and begins recording pages touched by DMA. Supported page sizes + are advertised in ``CAPS`` bits [16:12] (bit N =3D 2^N bytes). The driver + checks ``STATUS`` for errors after the command completes. +- **DIRTY_DISABLE** (5): tears down all ranges and stops tracking. +- **DIRTY_QUERY** (6): the driver writes (iova, size) into the + ``igb_mig_dirty_query`` DMA buffer, then issues the command. The + device validates the range, copies the dirty bitmap into the buffer, + and clears the tracked bits after successful DMA. The driver checks + ``STATUS`` for errors after the command. + +Dirty enable DMA buffer +~~~~~~~~~~~~~~~~~~~~~~~ + +The ``DIRTY_ENABLE`` command reads its parameters from the DMA buffer. +The ``len`` field holds the total structure size (including reserved +bytes) so the device can detect newer formats. ``flags`` and +``reserved`` must be zero:: + + Offset Field Type Description + 0x00 len uint32 Structure size in bytes + 0x04 flags uint32 Reserved, must be 0 + 0x08 pgsize uint64 Page granularity (must match a CAPS pgsiz= e bit) + 0x10 range_iova uint64 Tracked range start address + 0x18 range_size uint64 Tracked range size in bytes + 0x20 reserved[4] uint32 Reserved, must be 0 + +Dirty query DMA buffer +~~~~~~~~~~~~~~~~~~~~~~ + +The ``DIRTY_QUERY`` command uses a shared DMA buffer for both request +and response. The ``len`` field holds the total buffer size (header + +bitmap). ``flags`` and ``reserved`` must be zero:: + + Offset Field Written by Description + 0x00 len driver Total buffer size in bytes + 0x04 flags driver Reserved, must be 0 + 0x08 iova driver Query range start + 0x10 size driver Query range size + 0x18 bitmap_size device Bytes written to bitmap + 0x1C dirty_page_count device Number of set bits + 0x20 dma_writes device DMA write count (diagnostic) + 0x28 reserved[6] - Reserved, must be 0 + 0x40 bitmap[] device Dirty page bitmap + +Migration statistics +~~~~~~~~~~~~~~~~~~~~ + +The ``GET_STATS`` command DMA-writes a statistics response into the +driver-provided buffer. The driver sets ``BUF_ADDR_LO/HI`` and issues +the command; the device writes the response and returns:: + + Offset Field Type Description + 0x00 dma_writes uint64 DMA write operations tracked + 0x08 dma_bytes uint64 DMA bytes written + 0x10 dirty_pages_set uint32 Dirty pages marked since enable + 0x14 dirty_pages_cleared uint32 Dirty pages cleared by queries + 0x18 dirty_page_count uint32 Current dirty pages (set - cleare= d) + 0x1C dirty_query_count uint32 Number of QUERY operations + +The variant driver exposes these via debugfs at +``/sys/kernel/debug/vfio//migration/dirty/stats``. + +Testing setup +~~~~~~~~~~~~~ + +The target scenario is nested virtualization: L0 runs QEMU with an +igb PF (``x-vf-migration=3Don``), L1 runs the `igb-vfio-pci`_ variant +driver and an unmodified QEMU, and L2 runs a standard igbvf driver. +See `Architecture`_ above for the full stack diagram. + +NetworkManager configuration +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In a nested setup, the L1 VMs (source and destination) have emulated +igb PFs connected to the L0 bridge. By default, NetworkManager +acquires DHCP leases on those PF interfaces and on any igb VFs created +later. This causes the VF MAC address to be learned on the L0 bridge, +which can misdirect iperf3 traffic after migration. + +To prevent this, configure NetworkManager on **both L1 VMs** and on the +**L2 guest disk image**. + +L1 VMs (source and destination) +............................... + +1. Prevent NetworkManager from managing igbvf interfaces: + +.. code-block:: bash + + cat > /etc/NetworkManager/conf.d/99-no-igbvf.conf <" ipv4.method disabled ipv6= .method disabled + +3. Reload NetworkManager: + +.. code-block:: bash + + nmcli general reload + +L2 guest disk image +................... + +Use ``virt-customize`` to add the igbvf unmanaged config to the guest +image (offline, before any test run): + +.. code-block:: bash + + virt-customize -a /srv/migration/rhel10.qcow2 \ + --write /etc/NetworkManager/conf.d/99-no-igbvf.conf:'[keyfile] + unmanaged-devices=3Ddriver:igbvf' + +Network diagram +^^^^^^^^^^^^^^^ + +The diagram below shows the nested setup where the source and +destination hosts are themselves VMs (L1) running on a physical +host (L0) that emulates the igb NIC:: + + =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=90 + =E2=94=82 L0: physical host = =E2=94=82 + =E2=94=82 = =E2=94=82 + =E2=94=82 virbr0 192.168.199.1/24 = =E2=94=82 + =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 NFS server: /srv/migration = =E2=94=82 + =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 iperf3 client: iperf3 -c 192.168.= 199.200 -t 60 -i 1 =E2=94=82 + =E2=94=82 =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=82 L0 virbr0 bridge (192.168.199.0/24) = =E2=94=82 + =E2=94=82 =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=8C= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=90 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 virtio =E2=94=82 =E2=94= =82 emulated=E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82c0:ff:ee:=E2=94=82 =E2=94= =82 igb PF =E2=94=82 L0 QEMU (vm6) =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 :00:06 =E2=94=82 =E2=94= =82 + igbvf =E2=94=82 tracks DMA dirty pages =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=94= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=98 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 L1: vm6 (source) =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 enp1s0: 192.168.199.6 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 (management) =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 enp8s0 (igb PF, = no IP) =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 igb VF0 =E2=94= =80=E2=94=80=E2=96=BA igb-vfio-pci (VFIO) =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = dirty_sync =E2=86=92 L0 igbvf =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 virbr0 =E2=94=82 V= FIO passthrough =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 192.168.200.1/24 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2= =94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=90 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 L2: rhel10 gue= st =E2=94=82 =E2=94=82 =E2=94=82 =E2=94= =82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 =E2=94=82 =E2=94= =82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 virtio NIC igb VF= (enp7s0) =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 192.168.200.130/24 192.16= 8.199.200/24 =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 (SSH login) (iperf= 3 data path) =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2= =94=82 =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 iperf3 -s -D =E2= =94=82 (listens on 0.0.0.0) =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=98 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 virsh migrate --live =E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=96=BA vm7 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=82 iperf3 traffic =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 = =E2=94=82 + =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 = =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82 =E2=94=8C=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=90 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 virtio =E2=94=82 =E2=94=82 = =E2=94=82emulated =E2=94=82 L0 QEMU (vm7) =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82c0:ff:ee=E2=94=82 =E2=94=82 = =E2=94=82 igb PF =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 :00:07 =E2=94=82 =E2=94=82 = =E2=94=82 + igbvf =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=82 =E2=94=94=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=98 =E2=94=82 + =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82 + =E2=94=82 =E2=94=82 L1: vm7 (destination) =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 enp1s0: 192.168.199.7 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 (management) enp8s0 (igb PF, no IP) = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 igb VF0 =E2=94=80=E2=94=80= =E2=96=BA igb-vfio-pci (VFIO) =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 virbr0 =E2=94=82 VFIO passth= rough =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 192.168.200.1/24 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 L2: rhel10 (after migratio= n) =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2= =94=82 =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 virtio NIC igb VF (enp7s0) = =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 192.168.200.130/24 192.168.199.200/= 24 =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=82 iperf3 -s -D =E2=94=82 (co= nnection survives) =E2=94=82 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=82 =E2=94=82 + =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=82 + =E2=94=82 =E2=94=82 = =E2=94=82 + =E2=94=82 iperf3 traffic resumes =E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=98 =E2=94=82 + =E2=94=82 (same IP, same MAC, same L2 segment =E2=86=92 transparent= to client) =E2=94=82 + =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=98 + +Migration under iperf3 load works correctly: dirty page tracking +converges (from ~2000 pages per PRE_COPY iteration down to ~280 at +STOP_COPY), and STOP_COPY stays under 250ms. + +Todo +~~~~ + +1. Add VMState support for L0 migration (dirty bitmaps, tracking + engines, DVSEC registers, stats) +2. Add PRE_COPY state transfer to validate device INIT data (magic, + version, etc.) + +Ideas +~~~~~ + +1. **RX bandwidth throttle** (``x-mig-rx-limit``, uint32, default 0) + + Return false from ``can_receive`` when the per-VF packet count in the + current tracking interval exceeds the limit. Reduces DMA writes and + dirty pages realistically. + +2. **Migration phase timing** (GET_STATS extension) + + Add per-VF timestamps: ``precopy_start_ns``, ``stopcopy_start_ns``, + ``precopy_duration_ns``, ``stopcopy_duration_ns``, + ``state_transition_count``. Expose via GET_STATS. + +3. **Hot page simulation** (``x-mig-hot-pages``, uint32, default 0) + + Re-set the first N bitmap bits after each DIRTY_QUERY, simulating + workloads with hot pages that prevent convergence. + +4. **Error injection** (``x-mig-inject-error``, uint32, default 0) + + One-shot error code injection before command dispatch. A separate + ``x-mig-inject-dma-fail`` (bool) for persistent DMA failure testing. + +.. _igb-vfio-pci: https://github.com/legoater/vfio-pci-extras diff --git a/docs/system/devices/igb.rst b/docs/system/devices/igb.rst index 50f625fd77e4..00271dbc92c3 100644 --- a/docs/system/devices/igb.rst +++ b/docs/system/devices/igb.rst @@ -64,6 +64,12 @@ command: =20 pyvenv/bin/meson test --suite thorough func-x86_64-netdev_ethtool =20 +VF Migration (experimental) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +See :ref:`igb-migration` for details on the experimental VF live migration +interface. + References =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.56.0 From nobody Mon Nov 23 04:52:30 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791967790; cv=none; d=zohomail.com; s=zohoarc; b=ePzgy32ug4zZj4nxHhks3NxwCcKOh/XAcUWuRZ416IFZ09MgJHDELzhBK+7owdu+ZPQStQmefz8nyi3CpvJPox8KSFji1F2TLf1wu6gxe8QopTjxTAA9uA4FR1ozR4PDKsL77G171J8doCAPZ+g8HJh4UDjZUhVrtsbNGD6zq5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791967790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=frszv/8ZB8wT/sOTfNnRXI89W8XikBHKKqxWG2/H3iQ=; b=eLjRC7bXQK/qvhz0LDSgFYNRyk54itylK6j8eb9FCHmofUlG4JIL8EhRsbc7MIUNKaPX6y8oYzaldFjBlfpcaB07JmQu0TYN7qpGhQj9vRD5yunE1fKi6ZE8Pyce5RlkSwz+J0aEiwUBZmAVMdlR0LKSlUiGcG77cFyqHAu2Xy0= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791967790964106.39233166236534; Wed, 14 Oct 2026 01:49:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xGuf5-0006Cs-7U; Wed, 14 Oct 2026 04:48:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xGueX-0005hw-FP for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:48:01 -0400 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 1xGueU-0004aq-45 for qemu-devel@nongnu.org; Wed, 14 Oct 2026 04:48:01 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-184-UTbiPCgSM4i58KjdSYNFMg-1; Wed, 14 Oct 2026 08:47:55 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 574C71800656; Wed, 14 Oct 2026 08:47:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C4AC21800677; Wed, 14 Oct 2026 08:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791967677; 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=frszv/8ZB8wT/sOTfNnRXI89W8XikBHKKqxWG2/H3iQ=; b=LMPx/xyG2WYOlDSCoGJ5NmSKF08icO77jEmyeRBooUY1AQu4f/mC0e86S6YXorNhTfiVyN elqmI98IiXTasb9qtPzVRlGuzlSQvivpfn4oDEzNn6KtxktTGADxQB8UB4QKasVlALYMQE jdgE4I+bOPNaov0DhVkGqtxghl7gQhc= X-MC-Unique: UTbiPCgSM4i58KjdSYNFMg-1 X-Mimecast-MFC-AGG-ID: UTbiPCgSM4i58KjdSYNFMg_1791967674 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Sriram Yagnaraman , Jason Wang , Alex Williamson , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH v3 17/17] tests/qtest: Add igb VF migration tests Date: Wed, 14 Oct 2026 10:46:55 +0200 Message-ID: <20261014084655.127254-18-clg@redhat.com> In-Reply-To: <20261014084655.127254-1-clg@redhat.com> References: <20261014084655.127254-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1791967792907158500 Add qtests for the igb VF migration DVSEC interface covering: - DVSEC discovery: extended cap header, CAPS flags, CAPS read-only, BUF_ADDR read-back, VF activation (ERROR -> STOP -> RUNNING) - State machine: stop-copy and resuming paths with quiesced bit checks, invalid transitions, pre-copy transitions (RUNNING -> PRE_COPY -> STOP, RUNNING -> PRE_COPY -> STOP_COPY) - Save/load roundtrip: DATA_SIZE in STOP vs STOP_COPY, double save, blob header verification - Error recovery: full save/load cycle after ERROR -> STOP -> RUNNING - Blob validation: bad magic, bad version, bad VFN, corrupted blob (random word flips) - Command errors: unknown command, save/load in wrong state, missing save buffer, missing load buffer, size zero, size too big - Dirty tracking: enable/disable/query cycle, enable without buffer, query without enable, bad page size, unsupported page size, bad range, overflow, overlapping ranges, misaligned range, multiple ranges, double enable, query with wrong range, 64K page size The tests access the VF DVSEC via Q35 ECAM (PCIEXBAR enabled through legacy CF8/CFC) and use 16-bit writes for SR-IOV NumVFs/CTRL. AI-used-for: tests Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + tests/qtest/igb-migration-test.c | 921 +++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 3 files changed, 923 insertions(+) create mode 100644 tests/qtest/igb-migration-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 5a878ae7af84..37a2f3fac5fc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2826,6 +2826,7 @@ igb VF migration M: C=C3=A9dric Le Goater S: Maintained F: hw/net/igb_migration.* +F: tests/qtest/igb-migration-test.c F: docs/system/devices/igb-migration.rst =20 eepro100 diff --git a/tests/qtest/igb-migration-test.c b/tests/qtest/igb-migration-t= est.c new file mode 100644 index 000000000000..569c30ca6692 --- /dev/null +++ b/tests/qtest/igb-migration-test.c @@ -0,0 +1,921 @@ +/* + * QTest for igb VF migration DVSEC state machine and save/load + * + * Copyright (c) 2026 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qemu/module.h" +#include "hw/net/igb_migration.h" +#include "hw/net/igb_regs.h" + +/* Q35 MCH config register to enable ECAM */ +#define MCH_HOST_BRIDGE_PCIEXBAR 0x60 +#define Q35_ECAM_BASE 0xb0000000ULL + +/* PF on pcie.0 at slot 4 (devfn 0x20), bus 0 */ +#define PF_BUS 0 +#define PF_SLOT 4 +#define PF_DEVFN (PF_SLOT << 3) + +/* VF0 devfn =3D PF_devfn + VF_OFFSET (0x80) =3D 0xA0, same bus */ +#define VF0_BUS 0 +#define VF0_DEVFN (PF_DEVFN + 0x80) + +/* SR-IOV cap offset in igb PF */ +#define IGB_SRIOV_CAP_OFFSET 0x160 + +/* DVSEC offset in VF extended config space */ +#define DVSEC_BASE IGB_MIG_DVSEC_OFFSET + +/* Blob constants */ +#define BLOB_MAGIC 0x4D494742 + +/* DMA buffer GPA for state blob */ +#define DMA_BUF_GPA 0x100000ULL + +static void ecam_enable(QTestState *qts) +{ + /* Set PCIEXBAREN (bit 0) in MCH PCIEXBAR via legacy CF8/CFC */ + qtest_outl(qts, 0xcf8, 0x80000000 | MCH_HOST_BRIDGE_PCIEXBAR); + qtest_outl(qts, 0xcfc, Q35_ECAM_BASE | 1); +} + +static uint64_t ecam_addr(int bus, int devfn, int offset) +{ + return Q35_ECAM_BASE + ((uint64_t)bus << 20) + + ((uint64_t)devfn << 12) + offset; +} + +static uint32_t ecam_readl(QTestState *qts, int bus, int devfn, int offset) +{ + return qtest_readl(qts, ecam_addr(bus, devfn, offset)); +} + +static void ecam_writel(QTestState *qts, int bus, int devfn, + int offset, uint32_t val) +{ + qtest_writel(qts, ecam_addr(bus, devfn, offset), val); +} + +static void ecam_writew(QTestState *qts, int bus, int devfn, + int offset, uint16_t val) +{ + qtest_writew(qts, ecam_addr(bus, devfn, offset), val); +} + +static uint32_t dvsec_readl(QTestState *qts, int offset) +{ + return ecam_readl(qts, VF0_BUS, VF0_DEVFN, DVSEC_BASE + offset); +} + +static void dvsec_writel(QTestState *qts, int offset, uint32_t val) +{ + ecam_writel(qts, VF0_BUS, VF0_DEVFN, DVSEC_BASE + offset, val); +} + +static uint32_t dvsec_status(QTestState *qts) +{ + return dvsec_readl(qts, IGB_MIG_STATUS); +} + +static uint32_t dvsec_state(QTestState *qts) +{ + return dvsec_status(qts) & IGB_MIG_STATUS_STATE_MASK; +} + +static uint32_t dvsec_error(QTestState *qts) +{ + return (dvsec_status(qts) >> IGB_MIG_STATUS_ERROR_CODE_SHIFT) & 0xFF; +} + +static void dvsec_cmd(QTestState *qts, uint32_t cmd, uint32_t arg) +{ + dvsec_writel(qts, IGB_MIG_CTRL, + (cmd & IGB_MIG_CTRL_CMD_MASK) | + (arg << IGB_MIG_CTRL_ARG_SHIFT)); +} + +static void dvsec_set_state(QTestState *qts, uint32_t state) +{ + dvsec_cmd(qts, IGB_MIG_CMD_SET_STATE, state); +} + +static void dvsec_set_buf_addr(QTestState *qts, uint64_t gpa) +{ + dvsec_writel(qts, IGB_MIG_BUF_ADDR_LO, (uint32_t)gpa); + dvsec_writel(qts, IGB_MIG_BUF_ADDR_HI, (uint32_t)(gpa >> 32)); +} + +static void enable_sriov(QTestState *qts, uint16_t num_vfs) +{ + int sriov =3D IGB_SRIOV_CAP_OFFSET; + + ecam_writew(qts, PF_BUS, PF_DEVFN, sriov + PCI_SRIOV_NUM_VF, num_vfs); + ecam_writew(qts, PF_BUS, PF_DEVFN, sriov + PCI_SRIOV_CTRL, + PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); +} + +static void activate_vf(QTestState *qts) +{ + /* Initial state is ERROR; driver activates via ERROR -> STOP -> RUNNI= NG */ + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); +} + +static QTestState *start_igb_vm(void) +{ + QTestState *qts =3D qtest_init( + "-machine q35 -m 512M -nodefaults " + "-device igb,bus=3Dpcie.0,addr=3D4.0,x-vf-migration=3Don " + "-netdev hubport,hubid=3D0,id=3Dhs0"); + + ecam_enable(qts); + enable_sriov(qts, 1); + activate_vf(qts); + return qts; +} + +static void test_dvsec_presence(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* Check DVSEC header: extended cap id 0x23, DVSEC vendor Qumranet */ + uint32_t hdr =3D dvsec_readl(qts, 0x00); + g_assert_cmphex(hdr & 0xFFFF, =3D=3D, 0x0023); + + /* Check CAPS: F_STATE and F_DIRTY should be advertised */ + uint32_t caps =3D dvsec_readl(qts, IGB_MIG_CAPS); + g_assert(caps & IGB_MIG_CAP_F_STATE); + g_assert(caps & IGB_MIG_CAP_F_DIRTY); + + /* CAPS is read-only */ + dvsec_writel(qts, IGB_MIG_CAPS, 0); + g_assert_cmphex(dvsec_readl(qts, IGB_MIG_CAPS), =3D=3D, caps); + + /* BUF_ADDR_LO/HI are read-write */ + dvsec_writel(qts, IGB_MIG_BUF_ADDR_LO, 0xDEAD0000); + dvsec_writel(qts, IGB_MIG_BUF_ADDR_HI, 0x0000BEEF); + g_assert_cmphex(dvsec_readl(qts, IGB_MIG_BUF_ADDR_LO), =3D=3D, 0xDEAD0= 000); + g_assert_cmphex(dvsec_readl(qts, IGB_MIG_BUF_ADDR_HI), =3D=3D, 0x0000B= EEF); + + qtest_quit(qts); +} + +static void test_state_machine_stop_copy(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* RUNNING: not quiesced */ + g_assert(!(dvsec_status(qts) & IGB_MIG_STATUS_QUIESCED)); + + /* RUNNING -> STOP: quiesced */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + g_assert(dvsec_status(qts) & IGB_MIG_STATUS_QUIESCED); + + /* STOP -> STOP_COPY: quiesced */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + g_assert(dvsec_status(qts) & IGB_MIG_STATUS_QUIESCED); + + /* STOP_COPY -> STOP */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + /* STOP -> RUNNING: not quiesced */ + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert(!(dvsec_status(qts) & IGB_MIG_STATUS_QUIESCED)); + + qtest_quit(qts); +} + +static void test_state_machine_resuming(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* RUNNING -> STOP */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + /* STOP -> RESUMING */ + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RESUMING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* RESUMING -> STOP */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + /* STOP -> RUNNING */ + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + + qtest_quit(qts); +} + +static void test_state_machine_invalid(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* RUNNING -> STOP_COPY (invalid, must go through STOP) */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_STATE); + + qtest_quit(qts); +} + +static void test_state_machine_pre_copy(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* RUNNING -> PRE_COPY */ + dvsec_set_state(qts, IGB_MIG_STATE_PRE_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_PRE_COPY); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* PRE_COPY -> STOP (quiesce + disable dirty) */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + /* Back to RUNNING */ + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + + /* RUNNING -> PRE_COPY -> STOP_COPY */ + dvsec_set_state(qts, IGB_MIG_STATE_PRE_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_PRE_COPY); + + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP_COPY); + + /* STOP_COPY -> STOP */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + qtest_quit(qts); +} + +static void test_save_load_roundtrip(void) +{ + QTestState *qts =3D start_igb_vm(); + uint32_t buf[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* --- Save path --- */ + + /* RUNNING -> STOP */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + /* DATA_SIZE in STOP is the max allocation hint */ + uint32_t max_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + g_assert_cmpuint(max_size, >, 0); + g_assert_cmpuint(max_size, <=3D, IGB_VF_STATE_MAX_SIZE); + + /* STOP -> STOP_COPY */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP_COPY); + + /* DATA_SIZE in STOP_COPY is the actual serialized size */ + uint32_t data_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + g_assert_cmpuint(data_size, >, 0); + g_assert_cmpuint(data_size, <=3D, max_size); + + /* Issue SAVE */ + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Second SAVE is idempotent */ + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Read blob from DMA buffer */ + qtest_memread(qts, DMA_BUF_GPA, buf, data_size); + + /* Verify blob header */ + g_assert_cmphex(le32_to_cpu(buf[0]), =3D=3D, BLOB_MAGIC); + g_assert_cmpuint(le32_to_cpu(buf[1]), =3D=3D, 1); /* version */ + g_assert_cmpuint(le32_to_cpu(buf[2]), =3D=3D, 0); /* vfn */ + + /* STOP_COPY -> STOP */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + /* --- Load path --- */ + + /* STOP -> RESUMING */ + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RESUMING); + + /* Write blob to DMA buffer */ + qtest_memwrite(qts, DMA_BUF_GPA, buf, data_size); + + /* Issue LOAD */ + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, data_size); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RESUMING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* RESUMING -> STOP -> RUNNING */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_load_bad_magic(void) +{ + QTestState *qts =3D start_igb_vm(); + uint32_t buf[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Save to get a valid blob */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + uint32_t data_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + qtest_memread(qts, DMA_BUF_GPA, buf, data_size); + + /* Corrupt magic */ + buf[0] =3D cpu_to_le32(0xDEADBEEF); + + /* Try to load */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + qtest_memwrite(qts, DMA_BUF_GPA, buf, data_size); + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, data_size); + + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_MAGIC); + + qtest_quit(qts); +} + +static void test_load_bad_version(void) +{ + QTestState *qts =3D start_igb_vm(); + uint32_t buf[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Save to get a valid blob */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + uint32_t data_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + qtest_memread(qts, DMA_BUF_GPA, buf, data_size); + + /* Corrupt version */ + buf[1] =3D cpu_to_le32(0xFF); + + /* Try to load */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + qtest_memwrite(qts, DMA_BUF_GPA, buf, data_size); + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, data_size); + + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_VERSION); + + qtest_quit(qts); +} + +static void test_load_bad_vfn(void) +{ + QTestState *qts =3D start_igb_vm(); + uint32_t buf[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Save to get a valid blob */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + uint32_t data_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + qtest_memread(qts, DMA_BUF_GPA, buf, data_size); + + /* Corrupt VFN */ + buf[2] =3D cpu_to_le32(7); + + /* Try to load */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + qtest_memwrite(qts, DMA_BUF_GPA, buf, data_size); + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, data_size); + + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_VFN); + + qtest_quit(qts); +} + +static void test_error_recovery(void) +{ + QTestState *qts =3D start_igb_vm(); + uint32_t buf[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Trigger an error: invalid state transition */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + + /* Recover: ERROR -> STOP -> RUNNING */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Full save/load cycle should work after recovery */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + uint32_t data_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + qtest_memread(qts, DMA_BUF_GPA, buf, data_size); + + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + qtest_memwrite(qts, DMA_BUF_GPA, buf, data_size); + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, data_size); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + + qtest_quit(qts); +} + +static void test_save_no_buffer(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* Enter STOP_COPY without setting buffer address */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + + /* Issue SAVE without buffer */ + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_NO_BUFFER); + + qtest_quit(qts); +} + +static void test_load_corrupted_blob(void) +{ + QTestState *qts =3D start_igb_vm(); + uint32_t buf[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + uint32_t good[IGB_VF_STATE_MAX_SIZE / sizeof(uint32_t)]; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Save a valid blob */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_STOP_COPY); + uint32_t data_size =3D dvsec_readl(qts, IGB_MIG_DATA_SIZE); + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + qtest_memread(qts, DMA_BUF_GPA, good, data_size); + + uint32_t n_words =3D data_size / sizeof(uint32_t); + + /* Flip a random word in the blob 16 times; each must be rejected */ + for (int i =3D 0; i < 16; i++) { + memcpy(buf, good, data_size); + + uint32_t idx =3D g_test_rand_int_range(0, n_words); + buf[idx] ^=3D g_test_rand_int(); + + /* Reset to RESUMING for each attempt */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + qtest_memwrite(qts, DMA_BUF_GPA, buf, data_size); + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, data_size); + + uint32_t state =3D dvsec_state(qts); + g_assert(state =3D=3D IGB_MIG_STATE_ERROR || + state =3D=3D IGB_MIG_STATE_RESUMING); + } + + qtest_quit(qts); +} + +static void test_unknown_command(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_cmd(qts, 0xFF, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_UNK_CMD); + + qtest_quit(qts); +} + +static void test_save_wrong_state(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* SAVE while RUNNING (must be in STOP_COPY) */ + dvsec_cmd(qts, IGB_MIG_CMD_SAVE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_STATE); + + qtest_quit(qts); +} + +static void test_load_wrong_state(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* LOAD while STOP (must be in RESUMING) */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, 64); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_STATE); + + qtest_quit(qts); +} + +static void test_load_no_buffer(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* Enter RESUMING without setting buffer address */ + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + + /* Issue LOAD without buffer */ + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, 64); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_NO_BUFFER); + + qtest_quit(qts); +} + +static void test_load_size_zero(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + + /* LOAD with size 0 */ + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_SIZE); + + qtest_quit(qts); +} + +static void test_load_size_too_big(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + dvsec_set_state(qts, IGB_MIG_STATE_STOP); + dvsec_set_state(qts, IGB_MIG_STATE_RESUMING); + + /* LOAD with size exceeding max */ + dvsec_cmd(qts, IGB_MIG_CMD_LOAD, IGB_VF_STATE_MAX_SIZE + 1); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_SIZE); + + qtest_quit(qts); +} + +static void write_dirty_enable_req(QTestState *qts, uint64_t gpa, + uint64_t pgsize, uint64_t iova, + uint64_t size) +{ + struct igb_mig_dirty_enable_req req =3D { + .len =3D cpu_to_le32(sizeof(req)), + .pgsize =3D cpu_to_le64(pgsize), + .range_iova =3D cpu_to_le64(iova), + .range_size =3D cpu_to_le64(size), + }; + qtest_memwrite(qts, gpa, &req, sizeof(req)); +} + +static void test_dirty_enable_no_buffer(void) +{ + QTestState *qts =3D start_igb_vm(); + + /* DIRTY_ENABLE without setting buffer address */ + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_NO_BUFFER); + + qtest_quit(qts); +} + +static void test_dirty_query_not_enabled(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_QUERY, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_NOT_ENABLED); + + qtest_quit(qts); +} + +static void test_dirty_enable_bad_pgsize(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* page size 0x1234 is not a power of 2 and not in CAPS */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 0x1234, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_PGSIZE); + + qtest_quit(qts); +} + +static void test_dirty_enable_bad_range(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* zero range size */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_RANGE); + + qtest_quit(qts); +} + +static void test_dirty_enable_overflow(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* range_iova + range_size wraps uint64 */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, + UINT64_MAX - 0xFFF, 0x2000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_RANGE); + + qtest_quit(qts); +} + +static void test_dirty_enable_overlap(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* First range succeeds */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Second range overlaps the first */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0x8000, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_RANGE); + + qtest_quit(qts); +} + +static void test_dirty_enable_unsupported_pgsize(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* 512 is a power of 2 but not in CAPS pgsize bitmask */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 512, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_PGSIZE); + + qtest_quit(qts); +} + +static void test_dirty_enable_64k_pgsize(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* CAPS only advertises 4K, so 64K should be rejected */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 65536, 0, 0x100000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_PGSIZE); + + qtest_quit(qts); +} + +static void test_dirty_enable_misaligned(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* range_iova not aligned to page size */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0x1000 + 1, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_PGSIZE); + + qtest_quit(qts); +} + +static void test_dirty_enable_multiple_ranges(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* First range */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Second non-overlapping range */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0x100000, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_DISABLE, 0); + + qtest_quit(qts); +} + +static void test_dirty_enable_double(void) +{ + QTestState *qts =3D start_igb_vm(); + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* First enable succeeds */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Same range again overlaps itself */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_RANGE); + + qtest_quit(qts); +} + +static void test_dirty_query_bad_range(void) +{ + QTestState *qts =3D start_igb_vm(); + struct igb_mig_dirty_query qbuf =3D { 0 }; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Enable: 4K pages, 64K range at IOVA 0 */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + + /* Query a range that doesn't match */ + qbuf.len =3D cpu_to_le32(sizeof(qbuf) + 16); + qbuf.iova =3D cpu_to_le64(0x200000); + qbuf.size =3D cpu_to_le64(0x10000); + qtest_memwrite(qts, DMA_BUF_GPA, &qbuf, sizeof(qbuf)); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_QUERY, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_ERROR); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, IGB_MIG_ERR_BAD_RANGE); + + qtest_quit(qts); +} + +static void test_dirty_enable_query_cycle(void) +{ + QTestState *qts =3D start_igb_vm(); + struct igb_mig_dirty_query qbuf =3D { 0 }; + + dvsec_set_buf_addr(qts, DMA_BUF_GPA); + + /* Enable: 4K pages, 64K range at IOVA 0 */ + write_dirty_enable_req(qts, DMA_BUF_GPA, 4096, 0, 0x10000); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_ENABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Query: no DMA activity, bitmap should be empty */ + qbuf.len =3D cpu_to_le32(sizeof(qbuf) + 16); + qbuf.iova =3D cpu_to_le64(0); + qbuf.size =3D cpu_to_le64(0x10000); + qtest_memwrite(qts, DMA_BUF_GPA, &qbuf, sizeof(qbuf)); + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_QUERY, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + /* Read back dirty_page_count - should be 0 */ + qtest_memread(qts, DMA_BUF_GPA, &qbuf, sizeof(qbuf)); + g_assert_cmpuint(le32_to_cpu(qbuf.dirty_page_count), =3D=3D, 0); + + /* Disable */ + dvsec_cmd(qts, IGB_MIG_CMD_DIRTY_DISABLE, 0); + g_assert_cmpuint(dvsec_state(qts), =3D=3D, IGB_MIG_STATE_RUNNING); + g_assert_cmpuint(dvsec_error(qts), =3D=3D, 0); + + qtest_quit(qts); +} + +static void register_igb_migration_test(void) +{ + qtest_add_func("/igb/migration/dvsec-presence", test_dvsec_presence); + qtest_add_func("/igb/migration/state-machine/stop-copy", + test_state_machine_stop_copy); + qtest_add_func("/igb/migration/state-machine/resuming", + test_state_machine_resuming); + qtest_add_func("/igb/migration/state-machine/invalid", + test_state_machine_invalid); + qtest_add_func("/igb/migration/state-machine/pre-copy", + test_state_machine_pre_copy); + qtest_add_func("/igb/migration/save-load-roundtrip", + test_save_load_roundtrip); + qtest_add_func("/igb/migration/load-bad-magic", test_load_bad_magic); + qtest_add_func("/igb/migration/load-bad-version", test_load_bad_versio= n); + qtest_add_func("/igb/migration/load-bad-vfn", test_load_bad_vfn); + qtest_add_func("/igb/migration/error-recovery", test_error_recovery); + qtest_add_func("/igb/migration/save-no-buffer", test_save_no_buffer); + qtest_add_func("/igb/migration/load-corrupted-blob", + test_load_corrupted_blob); + qtest_add_func("/igb/migration/unknown-command", test_unknown_command); + qtest_add_func("/igb/migration/save-wrong-state", test_save_wrong_stat= e); + qtest_add_func("/igb/migration/load-wrong-state", test_load_wrong_stat= e); + qtest_add_func("/igb/migration/load-size-zero", test_load_size_zero); + qtest_add_func("/igb/migration/load-size-too-big", test_load_size_too_= big); + qtest_add_func("/igb/migration/load-no-buffer", test_load_no_buffer); + qtest_add_func("/igb/migration/dirty/enable-no-buffer", + test_dirty_enable_no_buffer); + qtest_add_func("/igb/migration/dirty/query-not-enabled", + test_dirty_query_not_enabled); + qtest_add_func("/igb/migration/dirty/enable-bad-pgsize", + test_dirty_enable_bad_pgsize); + qtest_add_func("/igb/migration/dirty/enable-bad-range", + test_dirty_enable_bad_range); + qtest_add_func("/igb/migration/dirty/enable-overflow", + test_dirty_enable_overflow); + qtest_add_func("/igb/migration/dirty/enable-overlap", + test_dirty_enable_overlap); + qtest_add_func("/igb/migration/dirty/enable-unsupported-pgsize", + test_dirty_enable_unsupported_pgsize); + qtest_add_func("/igb/migration/dirty/enable-64k-pgsize", + test_dirty_enable_64k_pgsize); + qtest_add_func("/igb/migration/dirty/enable-misaligned", + test_dirty_enable_misaligned); + qtest_add_func("/igb/migration/dirty/enable-multiple-ranges", + test_dirty_enable_multiple_ranges); + qtest_add_func("/igb/migration/dirty/enable-double", + test_dirty_enable_double); + qtest_add_func("/igb/migration/dirty/query-bad-range", + test_dirty_query_bad_range); + qtest_add_func("/igb/migration/dirty/enable-query-cycle", + test_dirty_enable_query_cycle); +} + +libqos_init(register_igb_migration_test); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 200abf6f36d6..8a469ee48d69 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -355,6 +355,7 @@ qos_test_ss.add( 'virtio-iommu-test.c', 'vmxnet3-test.c', 'igb-test.c', + 'igb-migration-test.c', 'ufs-test.c', 'riscv-iommu-test.c', ) --=20 2.56.0