|
|
97168e |
From 9ec96a236be84e34b16681e658d3910fc3877a44 Mon Sep 17 00:00:00 2001
|
|
|
97168e |
From: Matthew Rosato <mjrosato@linux.ibm.com>
|
|
|
97168e |
Date: Fri, 9 Dec 2022 14:57:00 -0500
|
|
|
97168e |
Subject: [PATCH 11/11] s390x/pci: reset ISM passthrough devices on shutdown
|
|
|
97168e |
and system reset
|
|
|
97168e |
MIME-Version: 1.0
|
|
|
97168e |
Content-Type: text/plain; charset=UTF-8
|
|
|
97168e |
Content-Transfer-Encoding: 8bit
|
|
|
97168e |
|
|
|
97168e |
RH-Author: Cédric Le Goater <clg@redhat.com>
|
|
|
97168e |
RH-MergeRequest: 250: s390x/pci: reset ISM passthrough devices on shutdown and system reset
|
|
|
97168e |
RH-Bugzilla: 2163713
|
|
|
97168e |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
97168e |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
97168e |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
97168e |
RH-Commit: [4/4] c857d022c7c2f43cdeb66c4f6acfd9272c925b35
|
|
|
97168e |
|
|
|
97168e |
ISM device firmware stores unique state information that can
|
|
|
97168e |
can cause a wholesale unmap of the associated IOMMU (e.g. when
|
|
|
97168e |
we get a termination signal for QEMU) to trigger firmware errors
|
|
|
97168e |
because firmware believes we are attempting to invalidate entries
|
|
|
97168e |
that are still in-use by the guest OS (when in fact that guest is
|
|
|
97168e |
in the process of being terminated or rebooted).
|
|
|
97168e |
To alleviate this, register both a shutdown notifier (for unexpected
|
|
|
97168e |
termination cases e.g. virsh destroy) as well as a reset callback
|
|
|
97168e |
(for cases like guest OS reboot). For each of these scenarios, trigger
|
|
|
97168e |
PCI device reset; this is enough to indicate to firmware that the IOMMU
|
|
|
97168e |
is no longer in-use by the guest OS, making it safe to invalidate any
|
|
|
97168e |
associated IOMMU entries.
|
|
|
97168e |
|
|
|
97168e |
Fixes: 15d0e7942d3b ("s390x/pci: don't fence interpreted devices without MSI-X")
|
|
|
97168e |
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
|
|
|
97168e |
Message-Id: <20221209195700.263824-1-mjrosato@linux.ibm.com>
|
|
|
97168e |
Reviewed-by: Eric Farman <farman@linux.ibm.com>
|
|
|
97168e |
[thuth: Adjusted the hunk in s390-pci-vfio.c due to different context]
|
|
|
97168e |
Signed-off-by: Thomas Huth <thuth@redhat.com>
|
|
|
97168e |
(cherry picked from commit 03451953c79e6b31f7860ee0c35b28e181d573c1)
|
|
|
97168e |
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
|
|
97168e |
---
|
|
|
97168e |
hw/s390x/s390-pci-bus.c | 28 ++++++++++++++++++++++++++++
|
|
|
97168e |
hw/s390x/s390-pci-vfio.c | 2 ++
|
|
|
97168e |
include/hw/s390x/s390-pci-bus.h | 5 +++++
|
|
|
97168e |
3 files changed, 35 insertions(+)
|
|
|
97168e |
|
|
|
97168e |
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
|
|
|
97168e |
index d8b1e44a02..2d92848b0f 100644
|
|
|
97168e |
--- a/hw/s390x/s390-pci-bus.c
|
|
|
97168e |
+++ b/hw/s390x/s390-pci-bus.c
|
|
|
97168e |
@@ -24,6 +24,8 @@
|
|
|
97168e |
#include "hw/pci/msi.h"
|
|
|
97168e |
#include "qemu/error-report.h"
|
|
|
97168e |
#include "qemu/module.h"
|
|
|
97168e |
+#include "sysemu/reset.h"
|
|
|
97168e |
+#include "sysemu/runstate.h"
|
|
|
97168e |
|
|
|
97168e |
#ifndef DEBUG_S390PCI_BUS
|
|
|
97168e |
#define DEBUG_S390PCI_BUS 0
|
|
|
97168e |
@@ -150,10 +152,30 @@ out:
|
|
|
97168e |
psccb->header.response_code = cpu_to_be16(rc);
|
|
|
97168e |
}
|
|
|
97168e |
|
|
|
97168e |
+static void s390_pci_shutdown_notifier(Notifier *n, void *opaque)
|
|
|
97168e |
+{
|
|
|
97168e |
+ S390PCIBusDevice *pbdev = container_of(n, S390PCIBusDevice,
|
|
|
97168e |
+ shutdown_notifier);
|
|
|
97168e |
+
|
|
|
97168e |
+ pci_device_reset(pbdev->pdev);
|
|
|
97168e |
+}
|
|
|
97168e |
+
|
|
|
97168e |
+static void s390_pci_reset_cb(void *opaque)
|
|
|
97168e |
+{
|
|
|
97168e |
+ S390PCIBusDevice *pbdev = opaque;
|
|
|
97168e |
+
|
|
|
97168e |
+ pci_device_reset(pbdev->pdev);
|
|
|
97168e |
+}
|
|
|
97168e |
+
|
|
|
97168e |
static void s390_pci_perform_unplug(S390PCIBusDevice *pbdev)
|
|
|
97168e |
{
|
|
|
97168e |
HotplugHandler *hotplug_ctrl;
|
|
|
97168e |
|
|
|
97168e |
+ if (pbdev->pft == ZPCI_PFT_ISM) {
|
|
|
97168e |
+ notifier_remove(&pbdev->shutdown_notifier);
|
|
|
97168e |
+ qemu_unregister_reset(s390_pci_reset_cb, pbdev);
|
|
|
97168e |
+ }
|
|
|
97168e |
+
|
|
|
97168e |
/* Unplug the PCI device */
|
|
|
97168e |
if (pbdev->pdev) {
|
|
|
97168e |
DeviceState *pdev = DEVICE(pbdev->pdev);
|
|
|
97168e |
@@ -1111,6 +1133,12 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
|
|
|
97168e |
pbdev->fh |= FH_SHM_VFIO;
|
|
|
97168e |
pbdev->forwarding_assist = false;
|
|
|
97168e |
}
|
|
|
97168e |
+ /* Register shutdown notifier and reset callback for ISM devices */
|
|
|
97168e |
+ if (pbdev->pft == ZPCI_PFT_ISM) {
|
|
|
97168e |
+ pbdev->shutdown_notifier.notify = s390_pci_shutdown_notifier;
|
|
|
97168e |
+ qemu_register_shutdown_notifier(&pbdev->shutdown_notifier);
|
|
|
97168e |
+ qemu_register_reset(s390_pci_reset_cb, pbdev);
|
|
|
97168e |
+ }
|
|
|
97168e |
} else {
|
|
|
97168e |
pbdev->fh |= FH_SHM_EMUL;
|
|
|
97168e |
/* Always intercept emulated devices */
|
|
|
97168e |
diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
|
|
|
97168e |
index 99806e2a84..69af35f4fe 100644
|
|
|
97168e |
--- a/hw/s390x/s390-pci-vfio.c
|
|
|
97168e |
+++ b/hw/s390x/s390-pci-vfio.c
|
|
|
97168e |
@@ -124,6 +124,8 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
|
|
|
97168e |
/* The following values remain 0 until we support other FMB formats */
|
|
|
97168e |
pbdev->zpci_fn.fmbl = 0;
|
|
|
97168e |
pbdev->zpci_fn.pft = 0;
|
|
|
97168e |
+ /* Store function type separately for type-specific behavior */
|
|
|
97168e |
+ pbdev->pft = cap->pft;
|
|
|
97168e |
|
|
|
97168e |
/*
|
|
|
97168e |
* If appropriate, reduce the size of the supported DMA aperture reported
|
|
|
97168e |
diff --git a/include/hw/s390x/s390-pci-bus.h b/include/hw/s390x/s390-pci-bus.h
|
|
|
97168e |
index 1c46e3a269..e0a9f9385b 100644
|
|
|
97168e |
--- a/include/hw/s390x/s390-pci-bus.h
|
|
|
97168e |
+++ b/include/hw/s390x/s390-pci-bus.h
|
|
|
97168e |
@@ -39,6 +39,9 @@
|
|
|
97168e |
#define UID_CHECKING_ENABLED 0x01
|
|
|
97168e |
#define ZPCI_DTSM 0x40
|
|
|
97168e |
|
|
|
97168e |
+/* zPCI Function Types */
|
|
|
97168e |
+#define ZPCI_PFT_ISM 5
|
|
|
97168e |
+
|
|
|
97168e |
OBJECT_DECLARE_SIMPLE_TYPE(S390pciState, S390_PCI_HOST_BRIDGE)
|
|
|
97168e |
OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBus, S390_PCI_BUS)
|
|
|
97168e |
OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBusDevice, S390_PCI_DEVICE)
|
|
|
97168e |
@@ -344,6 +347,7 @@ struct S390PCIBusDevice {
|
|
|
97168e |
uint16_t noi;
|
|
|
97168e |
uint16_t maxstbl;
|
|
|
97168e |
uint8_t sum;
|
|
|
97168e |
+ uint8_t pft;
|
|
|
97168e |
S390PCIGroup *pci_group;
|
|
|
97168e |
ClpRspQueryPci zpci_fn;
|
|
|
97168e |
S390MsixInfo msix;
|
|
|
97168e |
@@ -352,6 +356,7 @@ struct S390PCIBusDevice {
|
|
|
97168e |
MemoryRegion msix_notify_mr;
|
|
|
97168e |
IndAddr *summary_ind;
|
|
|
97168e |
IndAddr *indicator;
|
|
|
97168e |
+ Notifier shutdown_notifier;
|
|
|
97168e |
bool pci_unplug_request_processed;
|
|
|
97168e |
bool unplug_requested;
|
|
|
97168e |
bool interp;
|
|
|
97168e |
--
|
|
|
97168e |
2.37.3
|
|
|
97168e |
|