From: "Cédric Le Goater" <clg@redhat.com>
To: Tony Krowiak <akrowiak@linux.ibm.com>, qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, mjrosato@linux.ibm.com,
jjherne@linux.ibm.com, pasic@linux.ibm.com, fiuczy@linux.ibm.com,
thuth@redhat.com, farman@linux.ibm.com,
borntraeger@linux.ibm.com, cohuck@redhat.com
Subject: Re: [PATCH v2 2/2] s390x/ap: Wire up the device request notifier interface
Date: Fri, 2 Jun 2023 16:28:49 +0200 [thread overview]
Message-ID: <c272e7b2-4b72-fc7f-49ed-e1fec60e1aa3@redhat.com> (raw)
In-Reply-To: <20230602141125.448833-3-akrowiak@linux.ibm.com>
Hello Tony,
On 6/2/23 16:11, Tony Krowiak wrote:
> Let's wire up the device request notifier interface to handle device unplug
> requests for AP.
>
> Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
> Link: https://lore.kernel.org/qemu-devel/20230530225544.280031-1-akrowiak@linux.ibm.com/
> ---
> hw/vfio/ap.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 113 insertions(+)
>
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index e0dd561e85a3..6e21d1da5a70 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -18,6 +18,8 @@
> #include "hw/vfio/vfio-common.h"
> #include "hw/s390x/ap-device.h"
> #include "qemu/error-report.h"
> +#include "qemu/event_notifier.h"
> +#include "qemu/main-loop.h"
> #include "qemu/module.h"
> #include "qemu/option.h"
> #include "qemu/config-file.h"
> @@ -33,6 +35,7 @@
> struct VFIOAPDevice {
> APDevice apdev;
> VFIODevice vdev;
> + EventNotifier req_notifier;
> };
>
> OBJECT_DECLARE_SIMPLE_TYPE(VFIOAPDevice, VFIO_AP_DEVICE)
> @@ -84,10 +87,110 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
> return vfio_get_group(groupid, &address_space_memory, errp);
> }
>
> +static void vfio_ap_req_notifier_handler(void *opaque)
> +{
> + VFIOAPDevice *vapdev = opaque;
> + Error *err = NULL;
> +
> + if (!event_notifier_test_and_clear(&vapdev->req_notifier)) {
> + return;
> + }
> +
> + qdev_unplug(DEVICE(vapdev), &err);
> +
> + if (err) {
> + warn_reportf_err(err, VFIO_MSG_PREFIX, vapdev->vdev.name);
> + }
> +}
> +
> +static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> + unsigned int irq, Error **errp)
> +{
> + int fd;
> + size_t argsz;
> + IOHandler *fd_read;
> + EventNotifier *notifier;
> + struct vfio_irq_info *irq_info;
> + VFIODevice *vdev = &vapdev->vdev;
> +
> + switch (irq) {
Do you have plan for more interrupts ? If not, you could convert the
'switch' statement to a simple 'if' and remove the fd_read variable.
> + case VFIO_AP_REQ_IRQ_INDEX:
> + notifier = &vapdev->req_notifier;
> + fd_read = vfio_ap_req_notifier_handler;
> + break;
> + default:
> + error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
> + return;
> + }
> +
> + if (vdev->num_irqs < irq + 1) {
> + error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)",
> + irq, vdev->num_irqs);
> + return;
> + }
> +
> + argsz = sizeof(*irq_info);
> + irq_info = g_malloc0(argsz);
> + irq_info->index = irq;
> + irq_info->argsz = argsz;
> +
> + if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> + irq_info) < 0 || irq_info->count < 1) {
> + error_setg_errno(errp, errno, "vfio: Error getting irq info");
> + goto out_free_info;
> + }
> +
> + if (event_notifier_init(notifier, 0)) {
> + error_setg_errno(errp, errno,
> + "vfio: Unable to init event notifier for irq (%d)",
> + irq);
> + goto out_free_info;
> + }
> +
> + fd = event_notifier_get_fd(notifier);
> + qemu_set_fd_handler(fd, fd_read, NULL, vapdev);
> +
> + if (vfio_set_irq_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd,
> + errp)) {
> + qemu_set_fd_handler(fd, NULL, NULL, vapdev);
> + event_notifier_cleanup(notifier);
> + }
> +
> +out_free_info:
> + g_free(irq_info);
> +
> +}
> +
> +static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
> + unsigned int irq)
> +{
> + Error *err = NULL;
> + EventNotifier *notifier;
> +
> + switch (irq) {
> + case VFIO_AP_REQ_IRQ_INDEX:
> + notifier = &vapdev->req_notifier;
> + break;
> + default:
> + error_report("vfio: Unsupported device irq(%d)", irq);
> + return;
> + }
> +
> + if (vfio_set_irq_signaling(&vapdev->vdev, irq, 0,
> + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
> + warn_reportf_err(err, VFIO_MSG_PREFIX, vapdev->vdev.name);
> + }
> +
> + qemu_set_fd_handler(event_notifier_get_fd(notifier),
> + NULL, NULL, vapdev);
> + event_notifier_cleanup(notifier);
> +}
> +
> static void vfio_ap_realize(DeviceState *dev, Error **errp)
> {
> int ret;
> char *mdevid;
> + Error *err = NULL;
> VFIOGroup *vfio_group;
> APDevice *apdev = AP_DEVICE(dev);
> VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
> @@ -116,6 +219,15 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
> goto out_get_dev_err;
> }
>
> + vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err);
> + if (err) {
> + /*
> + * Report this error, but do not make it a failing condition.
> + * Lack of this IRQ in the host does not prevent normal operation.
> + */
> + error_report_err(err);
May be issue a warning instead ?
Thanks,
C.
> + }
> +
> return;
>
> out_get_dev_err:
> @@ -129,6 +241,7 @@ static void vfio_ap_unrealize(DeviceState *dev)
> VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
> VFIOGroup *group = vapdev->vdev.group;
>
> + vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX);
> vfio_ap_put_device(vapdev);
> vfio_put_group(group);
> }
next prev parent reply other threads:[~2023-06-02 14:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-02 14:11 [PATCH v2 0/2] s390x/ap: fix hang when mdev attached to guest is removed Tony Krowiak
2023-06-02 14:11 ` [PATCH v2 1/2] linux-headers: Update with vfio_ap IRQ index mapping Tony Krowiak
2023-07-03 16:31 ` Cédric Le Goater
2023-07-03 20:31 ` Anthony Krowiak
2023-06-02 14:11 ` [PATCH v2 2/2] s390x/ap: Wire up the device request notifier interface Tony Krowiak
2023-06-02 14:28 ` Cédric Le Goater [this message]
2023-06-02 15:00 ` Anthony Krowiak
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=c272e7b2-4b72-fc7f-49ed-e1fec60e1aa3@redhat.com \
--to=clg@redhat.com \
--cc=akrowiak@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=farman@linux.ibm.com \
--cc=fiuczy@linux.ibm.com \
--cc=jjherne@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=pasic@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).