* [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier
@ 2024-01-15 6:34 Kunwu Chan
2024-01-15 15:41 ` Wang, Wei W
2024-02-22 21:37 ` Alex Williamson
0 siblings, 2 replies; 5+ messages in thread
From: Kunwu Chan @ 2024-01-15 6:34 UTC (permalink / raw)
To: alex.williamson; +Cc: kvm, linux-kernel, Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.
This is a blocking notifier callback, so errno isn't a proper return
value. Use WARN_ON to small allocation failures.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
v2: Use WARN_ON instead of return errno
---
drivers/vfio/pci/vfio_pci_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 1cbc990d42e0..61aa19666050 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -2047,6 +2047,7 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb,
pci_name(pdev));
pdev->driver_override = kasprintf(GFP_KERNEL, "%s",
vdev->vdev.ops->name);
+ WARN_ON(!pdev->driver_override);
} else if (action == BUS_NOTIFY_BOUND_DRIVER &&
pdev->is_virtfn && physfn == vdev->pdev) {
struct pci_driver *drv = pci_dev_driver(pdev);
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier
2024-01-15 6:34 [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier Kunwu Chan
@ 2024-01-15 15:41 ` Wang, Wei W
2024-01-15 16:28 ` Alex Williamson
2024-02-22 21:37 ` Alex Williamson
1 sibling, 1 reply; 5+ messages in thread
From: Wang, Wei W @ 2024-01-15 15:41 UTC (permalink / raw)
To: Kunwu Chan, alex.williamson@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
On Monday, January 15, 2024 2:35 PM, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory which can be
> NULL upon failure.
>
> This is a blocking notifier callback, so errno isn't a proper return value. Use
> WARN_ON to small allocation failures.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
> v2: Use WARN_ON instead of return errno
> ---
> drivers/vfio/pci/vfio_pci_core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 1cbc990d42e0..61aa19666050 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -2047,6 +2047,7 @@ static int vfio_pci_bus_notifier(struct notifier_block
> *nb,
> pci_name(pdev));
> pdev->driver_override = kasprintf(GFP_KERNEL, "%s",
> vdev->vdev.ops->name);
> + WARN_ON(!pdev->driver_override);
Saw Alex's comments on v1. Curious why not return "NOTIFY_BAD" on errors though
less likely? Similar examples could be found in kvm_pm_notifier_call, kasan_mem_notifier etc.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier
2024-01-15 15:41 ` Wang, Wei W
@ 2024-01-15 16:28 ` Alex Williamson
2024-01-16 12:08 ` Wang, Wei W
0 siblings, 1 reply; 5+ messages in thread
From: Alex Williamson @ 2024-01-15 16:28 UTC (permalink / raw)
To: Wang, Wei W; +Cc: Kunwu Chan, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
On Mon, 15 Jan 2024 15:41:02 +0000
"Wang, Wei W" <wei.w.wang@intel.com> wrote:
> On Monday, January 15, 2024 2:35 PM, Kunwu Chan wrote:
> > kasprintf() returns a pointer to dynamically allocated memory which can be
> > NULL upon failure.
> >
> > This is a blocking notifier callback, so errno isn't a proper return value. Use
> > WARN_ON to small allocation failures.
> >
> > Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> > ---
> > v2: Use WARN_ON instead of return errno
> > ---
> > drivers/vfio/pci/vfio_pci_core.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> > index 1cbc990d42e0..61aa19666050 100644
> > --- a/drivers/vfio/pci/vfio_pci_core.c
> > +++ b/drivers/vfio/pci/vfio_pci_core.c
> > @@ -2047,6 +2047,7 @@ static int vfio_pci_bus_notifier(struct notifier_block
> > *nb,
> > pci_name(pdev));
> > pdev->driver_override = kasprintf(GFP_KERNEL, "%s",
> > vdev->vdev.ops->name);
> > + WARN_ON(!pdev->driver_override);
>
> Saw Alex's comments on v1. Curious why not return "NOTIFY_BAD" on errors though
> less likely? Similar examples could be found in kvm_pm_notifier_call, kasan_mem_notifier etc.
If the statement is that there are notifier call chains that return
NOTIFY_BAD, I would absolutely agree, but the return value needs to be
examined from the context of the caller. BUS_NOTIFY_ADD_DEVICE is
notified via bus_notify() in device_add(). What does it accomplish to
return NOTIFY_BAD in a chain that ignores the return value? At best
we're preventing callbacks further down the chain from being called.
That doesn't seem obviously beneficial either.
The scenario here is similar to that in fail_iommu_bus_notify() where
they've chosen to trigger a pr_warn() if they're unable to crease sysfs
entries. In fact, a pci_warn(), maybe even pci_err() might be a better
alternative here than a WARN_ON(). Thanks,
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier
2024-01-15 16:28 ` Alex Williamson
@ 2024-01-16 12:08 ` Wang, Wei W
0 siblings, 0 replies; 5+ messages in thread
From: Wang, Wei W @ 2024-01-16 12:08 UTC (permalink / raw)
To: Alex Williamson
Cc: Kunwu Chan, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
On Tuesday, January 16, 2024 12:29 AM, Alex Williamson wrote:
> > On Monday, January 15, 2024 2:35 PM, Kunwu Chan wrote:
> > > kasprintf() returns a pointer to dynamically allocated memory which
> > > can be NULL upon failure.
> > >
> > > This is a blocking notifier callback, so errno isn't a proper return
> > > value. Use WARN_ON to small allocation failures.
> > >
> > > Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> > > ---
> > > v2: Use WARN_ON instead of return errno
> > > ---
> > > drivers/vfio/pci/vfio_pci_core.c | 1 +
> > > 1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/vfio/pci/vfio_pci_core.c
> > > b/drivers/vfio/pci/vfio_pci_core.c
> > > index 1cbc990d42e0..61aa19666050 100644
> > > --- a/drivers/vfio/pci/vfio_pci_core.c
> > > +++ b/drivers/vfio/pci/vfio_pci_core.c
> > > @@ -2047,6 +2047,7 @@ static int vfio_pci_bus_notifier(struct
> > > notifier_block *nb,
> > > pci_name(pdev));
> > > pdev->driver_override = kasprintf(GFP_KERNEL, "%s",
> > > vdev->vdev.ops->name);
> > > + WARN_ON(!pdev->driver_override);
> >
> > Saw Alex's comments on v1. Curious why not return "NOTIFY_BAD" on
> > errors though less likely? Similar examples could be found in
> kvm_pm_notifier_call, kasan_mem_notifier etc.
>
> If the statement is that there are notifier call chains that return NOTIFY_BAD, I
> would absolutely agree, but the return value needs to be examined from the
> context of the caller. BUS_NOTIFY_ADD_DEVICE is notified via bus_notify() in
> device_add(). What does it accomplish to return NOTIFY_BAD in a chain that
> ignores the return value? At best we're preventing callbacks further down the
> chain from being called.
> That doesn't seem obviously beneficial either.
OK, thanks for the clarification. My curiosity came from the statement "This is a
blocking notifier callback, so errno isn't a proper return value". Probably the
commit log needs some rewording.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier
2024-01-15 6:34 [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier Kunwu Chan
2024-01-15 15:41 ` Wang, Wei W
@ 2024-02-22 21:37 ` Alex Williamson
1 sibling, 0 replies; 5+ messages in thread
From: Alex Williamson @ 2024-02-22 21:37 UTC (permalink / raw)
To: Kunwu Chan; +Cc: kvm, linux-kernel
On Mon, 15 Jan 2024 14:34:34 +0800
Kunwu Chan <chentao@kylinos.cn> wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
>
> This is a blocking notifier callback, so errno isn't a proper return
> value. Use WARN_ON to small allocation failures.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
> v2: Use WARN_ON instead of return errno
> ---
> drivers/vfio/pci/vfio_pci_core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 1cbc990d42e0..61aa19666050 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -2047,6 +2047,7 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb,
> pci_name(pdev));
> pdev->driver_override = kasprintf(GFP_KERNEL, "%s",
> vdev->vdev.ops->name);
> + WARN_ON(!pdev->driver_override);
> } else if (action == BUS_NOTIFY_BOUND_DRIVER &&
> pdev->is_virtfn && physfn == vdev->pdev) {
> struct pci_driver *drv = pci_dev_driver(pdev);
Applied to vfio next branch for v6.9. Thanks,
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-22 21:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15 6:34 [PATCH v2] vfio: Use WARN_ON for low-probability allocation failure issue in vfio_pci_bus_notifier Kunwu Chan
2024-01-15 15:41 ` Wang, Wei W
2024-01-15 16:28 ` Alex Williamson
2024-01-16 12:08 ` Wang, Wei W
2024-02-22 21:37 ` Alex Williamson
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).