From: Thomas Huth <thuth@redhat.com>
To: Matthew Rosato <mjrosato@linux.ibm.com>, qemu-s390x@nongnu.org
Cc: farman@linux.ibm.com, pmorel@linux.ibm.com,
schnelle@linux.ibm.com, pasic@linux.ibm.com,
borntraeger@linux.ibm.com, richard.henderson@linaro.org,
david@redhat.com, iii@linux.ibm.com, qemu-devel@nongnu.org
Subject: Re: [PATCH] s390x/pci: reset ISM passthrough devices on shutdown and system reset
Date: Mon, 12 Dec 2022 12:34:01 +0100 [thread overview]
Message-ID: <8a0aa955-6637-789a-cac3-063c384111dc@redhat.com> (raw)
In-Reply-To: <20221209195700.263824-1-mjrosato@linux.ibm.com>
On 09/12/2022 20.57, Matthew Rosato wrote:
> ISM device firmware stores unique state information that can
> can cause a wholesale unmap of the associated IOMMU (e.g. when
> we get a termination signal for QEMU) to trigger firmware errors
> because firmware believes we are attempting to invalidate entries
> that are still in-use by the guest OS (when in fact that guest is
> in the process of being terminated or rebooted).
> To alleviate this, register both a shutdown notifier (for unexpected
> termination cases e.g. virsh destroy) as well as a reset callback
> (for cases like guest OS reboot). For each of these scenarios, trigger
> PCI device reset; this is enough to indicate to firmware that the IOMMU
> is no longer in-use by the guest OS, making it safe to invalidate any
> associated IOMMU entries.
>
> Fixes: 15d0e7942d3b ("s390x/pci: don't fence interpreted devices without MSI-X")
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> ---
> hw/s390x/s390-pci-bus.c | 28 ++++++++++++++++++++++++++++
> hw/s390x/s390-pci-vfio.c | 2 ++
> include/hw/s390x/s390-pci-bus.h | 5 +++++
> 3 files changed, 35 insertions(+)
>
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index 977e7daa15..02751f3597 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -24,6 +24,8 @@
> #include "hw/pci/msi.h"
> #include "qemu/error-report.h"
> #include "qemu/module.h"
> +#include "sysemu/reset.h"
> +#include "sysemu/runstate.h"
>
> #ifndef DEBUG_S390PCI_BUS
> #define DEBUG_S390PCI_BUS 0
> @@ -150,10 +152,30 @@ out:
> psccb->header.response_code = cpu_to_be16(rc);
> }
>
> +static void s390_pci_shutdown_notifier(Notifier *n, void *opaque)
> +{
> + S390PCIBusDevice *pbdev = container_of(n, S390PCIBusDevice,
> + shutdown_notifier);
> +
> + pci_device_reset(pbdev->pdev);
> +}
> +
> +static void s390_pci_reset_cb(void *opaque)
> +{
> + S390PCIBusDevice *pbdev = opaque;
> +
> + pci_device_reset(pbdev->pdev);
> +}
> +
> static void s390_pci_perform_unplug(S390PCIBusDevice *pbdev)
> {
> HotplugHandler *hotplug_ctrl;
>
> + if (pbdev->pft == ZPCI_PFT_ISM) {
> + notifier_remove(&pbdev->shutdown_notifier);
> + qemu_unregister_reset(s390_pci_reset_cb, pbdev);
> + }
> +
> /* Unplug the PCI device */
> if (pbdev->pdev) {
> DeviceState *pdev = DEVICE(pbdev->pdev);
> @@ -1111,6 +1133,12 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
> pbdev->fh |= FH_SHM_VFIO;
> pbdev->forwarding_assist = false;
> }
> + /* Register shutdown notifier and reset callback for ISM devices */
> + if (pbdev->pft == ZPCI_PFT_ISM) {
> + pbdev->shutdown_notifier.notify = s390_pci_shutdown_notifier;
> + qemu_register_shutdown_notifier(&pbdev->shutdown_notifier);
> + qemu_register_reset(s390_pci_reset_cb, pbdev);
> + }
> } else {
> pbdev->fh |= FH_SHM_EMUL;
> /* Always intercept emulated devices */
> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
> index 5f0adb0b4a..419763f829 100644
> --- a/hw/s390x/s390-pci-vfio.c
> +++ b/hw/s390x/s390-pci-vfio.c
> @@ -122,6 +122,8 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
> /* The following values remain 0 until we support other FMB formats */
> pbdev->zpci_fn.fmbl = 0;
> pbdev->zpci_fn.pft = 0;
> + /* Store function type separately for type-specific behavior */
> + pbdev->pft = cap->pft;
> }
Thanks, queued:
https://gitlab.com/thuth/qemu/-/commits/s390x-next/
I had to adjust the hunk in s390_pci_read_base() due to a conflict with your
earlier patch, please check whether it looks sane to you.
Thomas
next prev parent reply other threads:[~2022-12-12 11:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 19:57 [PATCH] s390x/pci: reset ISM passthrough devices on shutdown and system reset Matthew Rosato
2022-12-12 11:34 ` Thomas Huth [this message]
2022-12-12 13:33 ` Matthew Rosato
2022-12-12 15:03 ` Eric Farman
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=8a0aa955-6637-789a-cac3-063c384111dc@redhat.com \
--to=thuth@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=farman@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=pmorel@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=schnelle@linux.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).