qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: Matthew Rosato <mjrosato@linux.ibm.com>,
	Farhan Ali <alifm@linux.ibm.com>,
	qemu-devel@nongnu.org, qemu-s390x@nongnu.org
Cc: thuth@redhat.com, alex.williamson@redhat.com
Subject: Re: [PATCH v2 3/4] s390x/pci: Add PCI error handling for vfio pci devices
Date: Tue, 9 Sep 2025 09:59:16 +0200	[thread overview]
Message-ID: <cd025b10-aa5b-4c94-ae38-76df79b50fcb@redhat.com> (raw)
In-Reply-To: <5ed9c5ef-cb1d-428c-a822-9f378fabd755@linux.ibm.com>

On 9/3/25 19:49, Matthew Rosato wrote:
> On 9/3/25 1:12 PM, Farhan Ali wrote:
>>
>> On 9/1/2025 4:25 AM, Cédric Le Goater wrote:
>>> On 8/25/25 23:24, Farhan Ali wrote:
>>>> Add an s390x specific callback for vfio error handling. For s390x pci devices,
>>>> we have platform specific error information. We need to retrieve this error
>>>> information for passthrough devices. This is done via a memory region which
>>>> exposes that information.
>>>>
>>>> Once this error information is retrieved we can then inject an error into
>>>> the guest, and let the guest drive the recovery.
>>>>
>>>> Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
>>>> ---
>>>>    hw/s390x/s390-pci-bus.c          |  5 +++
>>>>    hw/s390x/s390-pci-vfio.c         | 76 ++++++++++++++++++++++++++++++++
>>>>    include/hw/s390x/s390-pci-bus.h  |  1 +
>>>>    include/hw/s390x/s390-pci-vfio.h |  2 +
>>>>    4 files changed, 84 insertions(+)
>>>>
>>>> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
>>>> index f87d2748b6..af42eb9938 100644
>>>> --- a/hw/s390x/s390-pci-bus.c
>>>> +++ b/hw/s390x/s390-pci-bus.c
>>>> @@ -158,6 +158,8 @@ static void s390_pci_perform_unplug(S390PCIBusDevice *pbdev)
>>>>    {
>>>>        HotplugHandler *hotplug_ctrl;
>>>>    +    qemu_mutex_destroy(&pbdev->err_handler_lock);
>>>> +
>>>>        if (pbdev->pft == ZPCI_PFT_ISM) {
>>>>            notifier_remove(&pbdev->shutdown_notifier);
>>>>        }
>>>> @@ -1140,6 +1142,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
>>>>            pbdev->iommu->pbdev = pbdev;
>>>>            pbdev->state = ZPCI_FS_DISABLED;
>>>>            set_pbdev_info(pbdev);
>>>> +        qemu_mutex_init(&pbdev->err_handler_lock);
>>>>              if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
>>>>                /*
>>>> @@ -1164,6 +1167,8 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
>>>>                pbdev->iommu->dma_limit = s390_pci_start_dma_count(s, pbdev);
>>>>                /* Fill in CLP information passed via the vfio region */
>>>>                s390_pci_get_clp_info(pbdev);
>>>> +            /* Setup error handler for error recovery */
>>>> +            s390_pci_setup_err_handler(pbdev);
>>>
>>> This can fail. Please add an 'Error **' parameter and change the returned
>>> value to bool.
>>>
>> I wanted to avoid hard failing here as we can have mismatch in kernel and QEMU support for the feature. For example we can have a newer QEMU version with the feature running on an older kernel. So wanted to treat any error in setting up the error handler would be more of an info/warn message.
> 
> +1, please do not cause a hard failure if the underlying host kernel is simply missing support...

It doesn't have to be a hard failure. The code could issue a
warn_report_err(). Similarly to what is done for the vfio_ap
device when IRQ notifying support is not available on the host.

This is minor.

C.

> 
>>>> +void s390_pci_setup_err_handler(S390PCIBusDevice *pbdev)
>>>> +{
>>>> +    int ret;
>>>> +    VFIOPCIDevice *vfio_pci =  container_of(pbdev->pdev, VFIOPCIDevice, pdev);
>>>> +    uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>>>> +                              sizeof(uint64_t))] = {};
>>>> +    struct vfio_device_feature *feature = (struct vfio_device_feature *)buf;
>>>> +
>>>> +    feature->argsz = sizeof(buf);
>>>> +    feature->flags = VFIO_DEVICE_FEATURE_PROBE | VFIO_DEVICE_FEATURE_ZPCI_ERROR;
>>>> +
>>>> +    ret = vfio_pci->vbasedev.io_ops->device_feature(&vfio_pci->vbasedev,
>>>> +                                                     feature);
>>>
>>> Please introduce vfio helpers to hide the internal indirection :
>>>
>>>    ->vbasedev.io_ops->device_feature(...)
>>>
>>>> +
>>>> +    if (ret) {
>>>
>>> Shouldn't we test the return value to decide if the error is
>>> an unimplemented feature or an unexpected error ?
>>
>> Yeah, I think it makes sense separate out error for unimplemented feature (ENOTTY) vs any other unexpected error. Will change this.
>>
> 
> ... But if you add differentiation here between the 2 types of errors then I would be fine with hard-fail for unexpected cases and info/warn for missing host kernel support.



  reply	other threads:[~2025-09-09  8:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-25 21:24 [PATCH v2 0/4] Error recovery for zPCI passthrough devices Farhan Ali
2025-08-25 21:24 ` [PATCH v2 1/4] [NOTFORMERGE] linux-headers: Update for zpci vfio device Farhan Ali
2025-08-25 21:24 ` [PATCH v2 2/4] vfio/pci: Add an architecture specific error handler Farhan Ali
2025-09-01 11:28   ` Cédric Le Goater
2025-09-03 16:49     ` Farhan Ali
2025-09-09 20:56       ` Cédric Le Goater
2025-08-25 21:24 ` [PATCH v2 3/4] s390x/pci: Add PCI error handling for vfio pci devices Farhan Ali
2025-09-01 11:25   ` Cédric Le Goater
2025-09-03 17:12     ` Farhan Ali
2025-09-03 17:49       ` Matthew Rosato
2025-09-09  7:59         ` Cédric Le Goater [this message]
2025-08-25 21:24 ` [PATCH v2 4/4] s390x/pci: Reset a device in error state Farhan Ali
2025-09-01 11:17   ` Cédric Le Goater
2025-09-03 17:13     ` Farhan Ali

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=cd025b10-aa5b-4c94-ae38-76df79b50fcb@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=alifm@linux.ibm.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=thuth@redhat.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).