From: Reinette Chatre <reinette.chatre@intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
"jgg@nvidia.com" <jgg@nvidia.com>,
"yishaih@nvidia.com" <yishaih@nvidia.com>,
"shameerali.kolothum.thodi@huawei.com"
<shameerali.kolothum.thodi@huawei.com>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>
Cc: "tglx@linutronix.de" <tglx@linutronix.de>,
"darwi@linutronix.de" <darwi@linutronix.de>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"Jiang, Dave" <dave.jiang@intel.com>,
"Liu, Jing2" <jing2.liu@intel.com>,
"Raj, Ashok" <ashok.raj@intel.com>,
"Yu, Fenghua" <fenghua.yu@intel.com>,
"tom.zanussi@linux.intel.com" <tom.zanussi@linux.intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V4 10/11] vfio/pci: Support dynamic MSI-X
Date: Fri, 5 May 2023 10:21:22 -0700 [thread overview]
Message-ID: <ca71f97e-ce0b-945e-4e86-49f485fa7d5b@intel.com> (raw)
In-Reply-To: <BN9PR11MB5276ED7B47909222093E92438C729@BN9PR11MB5276.namprd11.prod.outlook.com>
Hi Kevin,
On 5/5/2023 1:10 AM, Tian, Kevin wrote:
>> From: Chatre, Reinette <reinette.chatre@intel.com>
>> Sent: Saturday, April 29, 2023 2:35 AM
>> On 4/27/2023 11:50 PM, Tian, Kevin wrote:
>>>> From: Chatre, Reinette <reinette.chatre@intel.com>
>>>> Sent: Friday, April 28, 2023 1:36 AM
...
>>>> +/*
>>>> + * Return Linux IRQ number of an MSI or MSI-X device interrupt vector.
>>>> + * If a Linux IRQ number is not available then a new interrupt will be
>>>> + * allocated if dynamic MSI-X is supported.
>>>> + */
>>>> +static int vfio_msi_alloc_irq(struct vfio_pci_core_device *vdev,
>>>> + unsigned int vector, bool msix)
>>>> +{
>>>> + struct pci_dev *pdev = vdev->pdev;
>>>> + struct msi_map map;
>>>> + int irq;
>>>> + u16 cmd;
>>>> +
>>>> + irq = pci_irq_vector(pdev, vector);
>>>> + if (irq > 0 || !msix || !vdev->has_dyn_msix)
>>>> + return irq;
>>>
>>> if (irq >= 0 || ...)
>>>
>>
>> I am not sure about this request because pci_irq_vector() cannot return 0.
>> The Linux interrupt number will be > 0 on success. 0 means "not found"
>> (see msi_get_virq()), which is translated to -EINVAL by pci_irq_vector().
>>
>
> There is a subtle difference between the description and the code of
> pci_irq_vector().
>
> /**
> * pci_irq_vector() - Get Linux IRQ number of a device interrupt vector
> * @dev: the PCI device to operate on
> * @nr: device-relative interrupt vector index (0-based); has different
> * meanings, depending on interrupt mode:
> *
> * * MSI-X the index in the MSI-X vector table
> * * MSI the index of the enabled MSI vectors
> * * INTx must be 0
> *
> * Return: the Linux IRQ number, or -EINVAL if @nr is out of range
> */
>
> From above '0' is a valid irq number.
>
> then in following code:
>
> irq = msi_get_virq(&dev->dev, nr);
> return irq ? irq : -EINVAL;
>
> '0' is obviously invalid for msi.
>
> I didn't realize the msi part when reading the patch. It left me in
> confusion that '0' is unhandled as here we only check ">0" while in
> other places "-EINVAL" is checked.
>
> Not big matter but it sounds slightly clearer to me to follow the
> description of pci_irq_vector() instead of its internal detail.
I can add an explicit check for '0' and, as you confirmed, this is
invalid for MSI and thus I think it should be treated as an error.
This is perhaps another candidate for a WARN considering that
pci_irq_vector() returning a '0' for MSI indicates a kernel problem .
I now consider taking guidance from pci_irq_get_affinity(). Note that
pci_irq_get_affinity() contains:
const struct cpumask *pci_irq_get_affinity(struct pci_dev *dev, int nr)
{
int idx, irq = pci_irq_vector(dev, nr);
...
if (WARN_ON_ONCE(irq <= 0))
return NULL;
...
}
Would you be ok with something like below?
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index b549f5c97cb8..a8e96254f953 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -393,6 +393,8 @@ static int vfio_msi_alloc_irq(struct vfio_pci_core_device *vdev,
u16 cmd;
irq = pci_irq_vector(pdev, vector);
+ if (WARN_ON_ONCE(irq == 0))
+ return -EINVAL;
if (irq > 0 || !msix || !vdev->has_dyn_msix)
return irq;
I would prefer that vfio_msi_alloc_irq() returns negative errors. This enables
callers to in turn just return the error code on failure (note that dynamic
allocation can return different error codes), not needing to translate 0 into
an error.
Reinette
next prev parent reply other threads:[~2023-05-05 17:21 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-27 17:35 [PATCH V4 00/11] vfio/pci: Support dynamic allocation of MSI-X interrupts Reinette Chatre
2023-04-27 17:35 ` [PATCH V4 01/11] vfio/pci: Consolidate irq cleanup on MSI/MSI-X disable Reinette Chatre
2023-04-28 6:28 ` Tian, Kevin
2023-04-27 17:35 ` [PATCH V4 02/11] vfio/pci: Remove negative check on unsigned vector Reinette Chatre
2023-04-28 6:29 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 03/11] vfio/pci: Prepare for dynamic interrupt context storage Reinette Chatre
2023-04-28 6:33 ` Tian, Kevin
2023-04-28 18:24 ` Reinette Chatre
2023-05-05 7:21 ` Tian, Kevin
2023-05-08 22:52 ` Reinette Chatre
2023-04-27 17:36 ` [PATCH V4 04/11] vfio/pci: Move to single error path Reinette Chatre
2023-04-28 6:34 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 05/11] vfio/pci: Use xarray for interrupt context storage Reinette Chatre
2023-04-28 6:35 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 06/11] vfio/pci: Remove interrupt context counter Reinette Chatre
2023-04-28 6:36 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 07/11] vfio/pci: Update stale comment Reinette Chatre
2023-04-28 6:42 ` Tian, Kevin
2023-04-28 18:24 ` Reinette Chatre
2023-04-27 17:36 ` [PATCH V4 08/11] vfio/pci: Use bitfield for struct vfio_pci_core_device flags Reinette Chatre
2023-04-28 6:43 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 09/11] vfio/pci: Probe and store ability to support dynamic MSI-X Reinette Chatre
2023-04-28 6:43 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 10/11] vfio/pci: Support " Reinette Chatre
2023-04-28 6:50 ` Tian, Kevin
2023-04-28 18:35 ` Reinette Chatre
2023-05-05 8:10 ` Tian, Kevin
2023-05-05 15:28 ` Alex Williamson
2023-05-06 8:15 ` Tian, Kevin
2023-05-05 17:21 ` Reinette Chatre [this message]
2023-05-06 8:13 ` Tian, Kevin
2023-04-27 17:36 ` [PATCH V4 11/11] vfio/pci: Clear VFIO_IRQ_INFO_NORESIZE for MSI-X Reinette Chatre
2023-04-28 6:50 ` Tian, Kevin
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=ca71f97e-ce0b-945e-4e86-49f485fa7d5b@intel.com \
--to=reinette.chatre@intel.com \
--cc=alex.williamson@redhat.com \
--cc=ashok.raj@intel.com \
--cc=darwi@linutronix.de \
--cc=dave.jiang@intel.com \
--cc=fenghua.yu@intel.com \
--cc=jgg@nvidia.com \
--cc=jing2.liu@intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=tglx@linutronix.de \
--cc=tom.zanussi@linux.intel.com \
--cc=yishaih@nvidia.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