All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Rosato <mjrosato@linux.ibm.com>
To: Konstantin Shkolnyy <kshk@linux.ibm.com>
Cc: alifm@linux.ibm.com, farman@linux.ibm.com,
	richard.henderson@linaro.org, iii@linux.ibm.com,
	david@kernel.org, cohuck@redhat.com, pasic@linux.ibm.com,
	borntraeger@linux.ibm.com, qemu-s390x@nongnu.org,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v11 15/16] s390x/pci: Implement migration for emulated devices
Date: Mon, 5 Oct 2026 15:39:18 -0400	[thread overview]
Message-ID: <59791e4a-ac5a-434f-b938-b7f3d154d3dc@linux.ibm.com> (raw)
In-Reply-To: <20260930145255.140164-16-kshk@linux.ibm.com>


> +/* Return a unique bus "path" for zpci device */
> +static char *s390_pci_bus_get_dev_path(DeviceState *dev)
> +{
> +    S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
> +    return g_strdup_printf("uid-%04x", pbdev->uid);
> +}
> +
> +static void s390_pcibus_class_init(ObjectClass *oc, const void *data)
> +{
> +    BusClass *bc = BUS_CLASS(oc);
> +    bc->get_dev_path = s390_pci_bus_get_dev_path;
> +}
> +
>  static const TypeInfo s390_pcibus_info = {
>      .name = TYPE_S390_PCI_BUS,
>      .parent = TYPE_BUS,
>      .instance_size = sizeof(S390PCIBus),
> +    /*
> +     * Implement get_dev_path() to provide each zpci device with a unique
> +     * stable UID-based bus "path". The "path" is used as part of idstr in the
> +     * migration stream, making idstr unique and instance_id always 0.
> +     * For migration to succeed, (idstr+instance_id) must match those generated
> +     * during QEMU start. Without unique idstr, QEMU will generate variable
> +     * instance_id to distinguish devices, and that instance_id can change
> +     * if a device is unplugged and plugged back, preventing migration.
> +     */
> +    .class_init = s390_pcibus_class_init,

This patch is already pretty big.  I wonder if adding
s390_pci_bus_get_dev_path + setting get_dev_path could be its own patch
prior to this one - up to you.

[...]

> +static bool s390_pci_device_post_load_errp(void *opaque, int version_id,
> +                                           Error **errp)
> +{
> +    S390PCIBusDevice *pbdev = S390_PCI_DEVICE(opaque);
> +
> +    /*
> +     * Guard against the scenario that s390_pcihost_plug() of the target PCI
> +     * device succeeded in the source QEMU, but failed on this destination
> +     * QEMU, before migration state load. In this case we'll find !pbdev->pdev
> +     * but the pbdev->state != ZPCI_FS_RESERVED as just loaded from the stream.
> +     * Such value combination is invalid and migration should fail.
> +     */
> +    if (pbdev->state != ZPCI_FS_RESERVED && !pbdev->pdev) {
> +        error_setg(errp, "zpci device uid 0x%x state %d has no PCI device",
> +                   pbdev->uid, pbdev->state);
> +        return false;
> +    }
> +
> +    pbdev->zpci_fn.fid = pbdev->fid;
> +    pbdev->zpci_fn.uid = pbdev->uid;
> +
> +    /*
> +     * Now that pbdev->idx has been loaded, use it to place pbdev back into
> +     * the table. This may replace a different not-yet-state-loaded pbdev,
> +     * but pre_load() handles this case.
> +     */
> +    g_hash_table_replace(s390_get_phb()->zpci_table, &pbdev->idx, pbdev);
> +
> +    /*
> +     * Regenerate IOMMU state, including IOTLB contents and QEMU memory regions.
> +     */
> +    if (pbdev->iommu_enabled) {
> +        if (!pbdev->iommu) {
> +            error_setg(errp, "iommu is NULL");
> +            return false;
> +        }
> +        if (!s390_pci_ioat_validate(pbdev, pbdev->pba, pbdev->pal,
> +                                    pbdev->g_iota, errp)) {
> +            if (*errp) {
> +                error_prepend(errp,
> +                              "invalid pba, pal or g_iota in migration stream: ");
> +            } else {
> +                error_setg(errp,
> +                           "invalid pba, pal or g_iota in migration stream");
> +            }
> +            return false;
> +        }
> +        if (s390_pci_is_translation_enabled(pbdev->g_iota)) {
> +            s390_pci_iommu_enable(pbdev);
> +            s390_pci_ioat_replay(pbdev);
> +        } else {
> +            /* TODO: unreachable until vfio passthrough migration is enabled */
> +            s390_pci_iommu_direct_map_enable(pbdev);

I would further clarify that this is because rtr_avail is always set to
false for emulated devices today.

Also, besides vfio migration, it could also be reachable if were to ever
allow rtr_avail for emulated devices.

But I wonder: if we can never reach this code today, should this then be
a g_assert_not_reached() and improve the comment above to indicate that
if/when either emulated devices are allowed to set rtr_avail or
migration of VFIO devices are added, this path needs to be updated to
call s390_pci_iommu_direct_map_enable(pbdev)?

If/when either of those things happen in the future it would already
need to be on a machine-version boundary whether this call were in-place
or not.  And then we don't worry about devices driving this codepath
that should not be able to do so.

[...]

>  struct S390pciState {
>      PCIHostState parent_obj;
>      uint32_t next_idx;
> @@ -386,11 +390,14 @@ struct S390pciState {
>      S390PCIBus *bus;
>      GHashTable *iommu_table;
>      GHashTable *zpci_table;
> -    QTAILQ_HEAD(, SeiContainer) pending_sei;
> +    SeiContainerList pending_sei;
> +    /* Only used temporarily between migration pre_load and post_load. */
> +    SeiContainerList pending_sei_stash;

Hrm, I don't love that -- but I can't think of a better solution either.

I guess if we find anything else that needs this kind of treatment in
the future we should create a single object chained off of S390pciState
to hold all of them vs adding more of these to S390pciState.

Thanks,
Matt


  reply	other threads:[~2026-10-05 19:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 14:52 [PATCH v11 00/16] s390x/pci: Implement migration for emulated devices Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 01/16] s390x/pci: implement IOMMU replay Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 02/16] s390x/pci: Create function to contain translation status check Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 03/16] s390x/pci: Move iommu_mr from S390PCIIOMMU to S390PCIBusDevice Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 04/16] s390x/pci: Move dm_mr " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 05/16] s390x/pci: Move iotlb " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 06/16] s390x/pci: Remove a ptr to S390PCIBusDevice from S390PCIIOMMU Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 07/16] s390x/pci: Move/rename enabled from S390PCIIOMMU to S390PCIBusDevice Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 08/16] s390x/pci: Move dma_limit " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 09/16] s390x/pci: Move g_iota " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 10/16] s390x/pci: Move pba " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 11/16] s390x/pci: Move pal " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 12/16] s390x/pci: Move max_dma_limit " Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 13/16] s390x/pci: Add a comment explaining S390PCIIOMMU purpose Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 14/16] s390x/pci: Factor ioat sanity checks into a separate function Konstantin Shkolnyy
2026-10-02 18:28   ` Matthew Rosato
2026-10-03  0:43     ` Konstantin Shkolnyy
2026-10-05 13:23       ` Konstantin Shkolnyy
2026-10-05 13:46         ` Matthew Rosato
2026-10-05 16:20           ` Konstantin Shkolnyy
2026-10-05 13:30       ` Matthew Rosato
2026-09-30 14:52 ` [PATCH v11 15/16] s390x/pci: Implement migration for emulated devices Konstantin Shkolnyy
2026-10-05 19:39   ` Matthew Rosato [this message]
2026-10-05 22:20   ` Farhan Ali
2026-10-05 22:31     ` Konstantin Shkolnyy
2026-09-30 14:52 ` [PATCH v11 16/16] s390x/pci: Create function to contain fmb_timer start Konstantin Shkolnyy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59791e4a-ac5a-434f-b938-b7f3d154d3dc@linux.ibm.com \
    --to=mjrosato@linux.ibm.com \
    --cc=alifm@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@kernel.org \
    --cc=farman@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=kshk@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.