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 03/11] vfio/pci: Prepare for dynamic interrupt context storage
Date: Fri, 28 Apr 2023 11:24:03 -0700 [thread overview]
Message-ID: <07a693e9-b926-6c25-ea55-8465410e214c@intel.com> (raw)
In-Reply-To: <BN9PR11MB5276242E8D9F4C082E6D2CB68C6B9@BN9PR11MB5276.namprd11.prod.outlook.com>
Hi Kevin,
On 4/27/2023 11:33 PM, Tian, Kevin wrote:
>> From: Chatre, Reinette <reinette.chatre@intel.com>
>> Sent: Friday, April 28, 2023 1:36 AM
>>
>> @@ -55,17 +80,28 @@ static void vfio_send_intx_eventfd(void *opaque,
>> void *unused)
>> {
>> struct vfio_pci_core_device *vdev = opaque;
>>
>> - if (likely(is_intx(vdev) && !vdev->virq_disabled))
>> - eventfd_signal(vdev->ctx[0].trigger, 1);
>> + if (likely(is_intx(vdev) && !vdev->virq_disabled)) {
>> + struct vfio_pci_irq_ctx *ctx;
>> +
>> + ctx = vfio_irq_ctx_get(vdev, 0);
>> + if (!ctx)
>> + return;
>
> if this error happens it implies a kernel bug since the same check
> has been done in vfio_intx_enable(). Then should be a WARN_ON().
Sure. Considering that if these are triggered it may result
in many instances, so perhaps WARN_ON_ONCE()?
> ditto for other intx functions which can be called only after intx
> is enabled.
It seems the instances in this category can be identified as the places
where the array contents is currently used without any checks.
I am planning on the following changes:
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index d8dae99cf6d9..b549f5c97cb8 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -92,7 +92,7 @@ static void vfio_send_intx_eventfd(void *opaque, void *unused)
struct vfio_pci_irq_ctx *ctx;
ctx = vfio_irq_ctx_get(vdev, 0);
- if (!ctx)
+ if (WARN_ON_ONCE(!ctx))
return;
eventfd_signal(ctx->trigger, 1);
}
@@ -107,7 +107,7 @@ bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev)
bool masked_changed = false;
ctx = vfio_irq_ctx_get(vdev, 0);
- if (!ctx)
+ if (WARN_ON_ONCE(!ctx))
return masked_changed;
spin_lock_irqsave(&vdev->irqlock, flags);
@@ -154,7 +154,7 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused)
int ret = 0;
ctx = vfio_irq_ctx_get(vdev, 0);
- if (!ctx)
+ if (WARN_ON_ONCE(!ctx))
return ret;
spin_lock_irqsave(&vdev->irqlock, flags);
@@ -200,7 +200,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
int ret = IRQ_NONE;
ctx = vfio_irq_ctx_get(vdev, 0);
- if (!ctx)
+ if (WARN_ON_ONCE(!ctx))
return ret;
spin_lock_irqsave(&vdev->irqlock, flags);
@@ -264,7 +264,7 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd)
int ret;
ctx = vfio_irq_ctx_get(vdev, 0);
- if (!ctx)
+ if (WARN_ON_ONCE(!ctx))
return -EINVAL;
if (ctx->trigger) {
@@ -320,6 +320,7 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev)
dev_dbg(&vdev->pdev->dev, "%s:%d Disabling INTx\n", __func__, __LINE__);
ctx = vfio_irq_ctx_get(vdev, 0);
+ WARN_ON_ONCE(!ctx);
if (ctx) {
vfio_virqfd_disable(&ctx->unmask);
vfio_virqfd_disable(&ctx->mask);
@@ -586,7 +587,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev,
struct vfio_pci_irq_ctx *ctx = vfio_irq_ctx_get(vdev, 0);
int32_t fd = *(int32_t *)data;
- if (!ctx)
+ if (WARN_ON_ONCE(!ctx))
return -EINVAL;
if (fd >= 0)
return vfio_virqfd_enable((void *) vdev,
next prev parent reply other threads:[~2023-04-28 18:24 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 [this message]
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
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=07a693e9-b926-6c25-ea55-8465410e214c@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
all inboxes | Powered by JetHome®