[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_not
From: |
Auger Eric |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper |
Date: |
Tue, 15 Jan 2019 14:00:43 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
Hi Cornelia,
On 1/15/19 1:03 PM, Cornelia Huck wrote:
> On Fri, 11 Jan 2019 17:58:00 +0100
> Eric Auger <address@hidden> wrote:
>
>> The code used to attach the eventfd handler for the ERR and
>> REQ irq indices can be factorized into a helper. In subsequent
>> patches we will extend this helper to support other irq indices.
>
> Looks like a nice refactoring to me.
thank you
>
>>
>> We test the notification is allowed outside of the helper:
>
> s/We test/We test whether/
>
>> respectively check vdev->pci_aer and VFIO_FEATURE_ENABLE_REQ.
>> Depending on the returned value we set vdev->pci_aer and
>> vdev->req_enabled. An error handle is introduced for future usage
>> although not strictly useful here.
>>
>> Signed-off-by: Eric Auger <address@hidden>
>> ---
>> hw/vfio/pci.c | 291 ++++++++++++++++++++++----------------------------
>> 1 file changed, 127 insertions(+), 164 deletions(-)
>>
>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> index c0cb1ec289..c589a4e666 100644
>> --- a/hw/vfio/pci.c
>> +++ b/hw/vfio/pci.c
>> @@ -105,6 +105,95 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
>> vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>> }
>>
>> +/*
>> + * vfio_register_event_notifier - setup/tear down eventfd
>> + * notification and handling for IRQ indices that span over
>> + * a single IRQ
>> + *
>> + * @vdev: VFIO device handle
>> + * @index: IRQ index the eventfd/handler is associated to
>
> s/to/with/ ?
>
>> + * @target_state: true means notifier needs to be set up
>> + * @handler to attach if @target_state is true
>> + * @errp error handle
>> + */
>> +static int vfio_register_event_notifier(VFIOPCIDevice *vdev,
>> + int index,
>> + bool target_state,
>> + void (*handler)(void *opaque),
>> + Error **errp)
>
> (...)
>
>> @@ -3069,8 +2998,29 @@ static void vfio_realize(PCIDevice *pdev, Error
>> **errp)
>> goto out_teardown;
>> }
>>
>> - vfio_register_err_notifier(vdev);
>> - vfio_register_req_notifier(vdev);
>> + if (vdev->pci_aer) {
>> + /*
>> + * Registers error notifier for devices supporting error recovery.
>> + * If we encounter a failure in this function, we report an error
>
> s/in this function/while registering it/ ?
>
>> + * and continue after disabling error recovery support for the
>> + * device.
>> + */
>> + vdev->pci_aer =
>> + !vfio_register_event_notifier(vdev, VFIO_PCI_ERR_IRQ_INDEX,
>> true,
>> + vfio_err_notifier_handler, &err);
>> + if (err) {
>> + warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> + }
>
> I think you need to reset err to NULL if you want to reuse the variable.
Yes you're right. Thanks for spotting this.
>
> Alternatively, you could keep the wrappers and define a local error
> variable there.
>
>> + }
>> +
>> + if (vdev->features & VFIO_FEATURE_ENABLE_REQ) {
>> + vdev->req_enabled =
>> + !vfio_register_event_notifier(vdev, VFIO_PCI_REQ_IRQ_INDEX,
>> true,
>> + vfio_req_notifier_handler, &err);
>> + if (err) {
>> + warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> + }
>> + }
>> vfio_setup_resetfn_quirk(vdev);
>>
>> return;
>> @@ -3106,9 +3056,22 @@ static void vfio_instance_finalize(Object *obj)
>> static void vfio_exitfn(PCIDevice *pdev)
>> {
>> VFIOPCIDevice *vdev = PCI_VFIO(pdev);
>> + Error *err = NULL;
>>
>> - vfio_unregister_req_notifier(vdev);
>> - vfio_unregister_err_notifier(vdev);
>> + if (vdev->req_enabled) {
>> + vfio_register_event_notifier(vdev, VFIO_PCI_REQ_IRQ_INDEX,
>> + false, NULL, &err);
>> + if (err) {
>> + warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> + }
>
> Likewise.
Thank you for the review!
Eric
>
>> + }
>> + if (vdev->pci_aer) {
>> + vfio_register_event_notifier(vdev, VFIO_PCI_ERR_IRQ_INDEX,
>> + false, NULL, &err);
>> + if (err) {
>> + warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> + }
>> + }
>> pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> vfio_disable_interrupts(vdev);
>> if (vdev->intx.mmap_timer) {
>
>
- [Qemu-devel] [PATCH 0/2] vfio-pci: Introduce vfio_register_event_notifier(), Eric Auger, 2019/01/11
- [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Eric Auger, 2019/01/11
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Cornelia Huck, 2019/01/15
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper,
Auger Eric <=
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Alexey Kardashevskiy, 2019/01/16
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Cornelia Huck, 2019/01/17
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Auger Eric, 2019/01/17
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Alexey Kardashevskiy, 2019/01/17
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Auger Eric, 2019/01/18
- Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper, Cornelia Huck, 2019/01/18
[Qemu-devel] [PATCH 2/2] vfio-pci: Use vfio_register_event_notifier in vfio_intx_enable_kvm, Eric Auger, 2019/01/11