Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: liquidio: avoid sleeping allocation under octeon_devices_lock
@ 2026-08-25  8:50 Yang Zi
  2026-09-02 15:54 ` Simon Horman
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Zi @ 2026-08-25  8:50 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni; +Cc: andrew+netdev, kees, netdev, linux-kernel

octeon_allocate_device() holds the spinlock octeon_devices_lock while
calling octeon_allocate_device_mem(), which uses vzalloc(). vzalloc()
can sleep, so this is a "scheduling while atomic" bug that can trigger a
sleeping-in-atomic warning (or deadlock on a preemptible kernel).

The memory allocation does not touch octeon_device[], octeon_device_count
or the free-slot search, so it does not need the lock. Move the
octeon_allocate_device_mem() call ahead of the lock: allocate the device
memory first, then take the lock only to find a free slot and register
the new device in the octeon_device[] array. If no slot is available
(all MAX_OCTEON_DEVICES slots in use), free the freshly allocated memory
and return NULL as before.

The lock therefore continues to protect exactly the data it documents:
the octeon_device[] array and octeon_device_count.

Signed-off-by: Yang Zi <2959243019@qq.com>
---
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_device.c b/drivers/net/ethernet/cavium/liquidio/octeon_device.c
index e98118e7b9fd..405ce14d46f5 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_device.c
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_device.c
@@ -723,6 +723,10 @@ struct octeon_device *octeon_allocate_device(u32 pci_id,
     u32 oct_idx = 0;
     struct octeon_device *oct = NULL;
 
+    oct = octeon_allocate_device_mem(pci_id, priv_size);
+    if (!oct)
+        return NULL;
+
     spin_lock(&octeon_devices_lock);
 
     for (oct_idx = 0; oct_idx < MAX_OCTEON_DEVICES; oct_idx++)
@@ -730,16 +734,16 @@ struct octeon_device *octeon_allocate_device(u32 pci_id,
             break;
 
     if (oct_idx < MAX_OCTEON_DEVICES) {
-        oct = octeon_allocate_device_mem(pci_id, priv_size);
-        if (oct) {
-            octeon_device_count++;
-            octeon_device[oct_idx] = oct;
-        }
+        octeon_device_count++;
+        octeon_device[oct_idx] = oct;
     }
 
     spin_unlock(&octeon_devices_lock);
-    if (!oct)
+
+    if (oct_idx == MAX_OCTEON_DEVICES) {
+        vfree(oct);
         return NULL;
+    }
 
     spin_lock_init(&oct->pci_win_lock);
     spin_lock_init(&oct->mem_access_lock);



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: liquidio: avoid sleeping allocation under octeon_devices_lock
  2026-08-25  8:50 [PATCH] net: liquidio: avoid sleeping allocation under octeon_devices_lock Yang Zi
@ 2026-09-02 15:54 ` Simon Horman
  2026-09-03  0:58   ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Horman @ 2026-09-02 15:54 UTC (permalink / raw)
  To: Yang Zi
  Cc: davem, edumazet, kuba, pabeni, andrew+netdev, kees, netdev,
	linux-kernel

On Tue, Aug 25, 2026 at 04:50:55PM +0800, Yang Zi wrote:
> octeon_allocate_device() holds the spinlock octeon_devices_lock while
> calling octeon_allocate_device_mem(), which uses vzalloc(). vzalloc()
> can sleep, so this is a "scheduling while atomic" bug that can trigger a
> sleeping-in-atomic warning (or deadlock on a preemptible kernel).
> 
> The memory allocation does not touch octeon_device[], octeon_device_count
> or the free-slot search, so it does not need the lock. Move the
> octeon_allocate_device_mem() call ahead of the lock: allocate the device
> memory first, then take the lock only to find a free slot and register
> the new device in the octeon_device[] array. If no slot is available
> (all MAX_OCTEON_DEVICES slots in use), free the freshly allocated memory
> and return NULL as before.
> 
> The lock therefore continues to protect exactly the data it documents:
> the octeon_device[] array and octeon_device_count.
> 
> Signed-off-by: Yang Zi <2959243019@qq.com>

This patch has been marked as Not Applicable in patchwork.
I assume that is because it doesn't apply.
Which I believe, in turn, is because it is whitespace mangled:
the tabs appear to have been substituted for combinations
of spaces and non-breaking spaces.

Please consider updating the way that you send patches -
e.g. using b4 or a different mail server - and reposting.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: liquidio: avoid sleeping allocation under octeon_devices_lock
  2026-09-02 15:54 ` Simon Horman
@ 2026-09-03  0:58   ` Jakub Kicinski
  2026-09-03 10:28     ` Simon Horman
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2026-09-03  0:58 UTC (permalink / raw)
  To: Simon Horman
  Cc: Yang Zi, davem, edumazet, pabeni, andrew+netdev, kees, netdev,
	linux-kernel

On Wed, 2 Sep 2026 16:54:23 +0100 Simon Horman wrote:
> On Tue, Aug 25, 2026 at 04:50:55PM +0800, Yang Zi wrote:
> > octeon_allocate_device() holds the spinlock octeon_devices_lock while
> > calling octeon_allocate_device_mem(), which uses vzalloc(). vzalloc()
> > can sleep, so this is a "scheduling while atomic" bug that can trigger a
> > sleeping-in-atomic warning (or deadlock on a preemptible kernel).
> > 
> > The memory allocation does not touch octeon_device[], octeon_device_count
> > or the free-slot search, so it does not need the lock. Move the
> > octeon_allocate_device_mem() call ahead of the lock: allocate the device
> > memory first, then take the lock only to find a free slot and register
> > the new device in the octeon_device[] array. If no slot is available
> > (all MAX_OCTEON_DEVICES slots in use), free the freshly allocated memory
> > and return NULL as before.
> > 
> > The lock therefore continues to protect exactly the data it documents:
> > the octeon_device[] array and octeon_device_count.
> > 
> > Signed-off-by: Yang Zi <2959243019@qq.com>  
> 
> This patch has been marked as Not Applicable in patchwork.
> I assume that is because it doesn't apply.
> Which I believe, in turn, is because it is whitespace mangled:
> the tabs appear to have been substituted for combinations
> of spaces and non-breaking spaces.
> 
> Please consider updating the way that you send patches -
> e.g. using b4 or a different mail server - and reposting.

Also we should consider deleting liquidio instead of fixing it?
It's _stupendously_ buggy, and Orphaned.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: liquidio: avoid sleeping allocation under octeon_devices_lock
  2026-09-03  0:58   ` Jakub Kicinski
@ 2026-09-03 10:28     ` Simon Horman
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2026-09-03 10:28 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Yang Zi, davem, edumazet, pabeni, andrew+netdev, kees, netdev,
	linux-kernel

On Wed, Sep 02, 2026 at 05:58:08PM -0700, Jakub Kicinski wrote:
> On Wed, 2 Sep 2026 16:54:23 +0100 Simon Horman wrote:
> > On Tue, Aug 25, 2026 at 04:50:55PM +0800, Yang Zi wrote:
> > > octeon_allocate_device() holds the spinlock octeon_devices_lock while
> > > calling octeon_allocate_device_mem(), which uses vzalloc(). vzalloc()
> > > can sleep, so this is a "scheduling while atomic" bug that can trigger a
> > > sleeping-in-atomic warning (or deadlock on a preemptible kernel).
> > > 
> > > The memory allocation does not touch octeon_device[], octeon_device_count
> > > or the free-slot search, so it does not need the lock. Move the
> > > octeon_allocate_device_mem() call ahead of the lock: allocate the device
> > > memory first, then take the lock only to find a free slot and register
> > > the new device in the octeon_device[] array. If no slot is available
> > > (all MAX_OCTEON_DEVICES slots in use), free the freshly allocated memory
> > > and return NULL as before.
> > > 
> > > The lock therefore continues to protect exactly the data it documents:
> > > the octeon_device[] array and octeon_device_count.
> > > 
> > > Signed-off-by: Yang Zi <2959243019@qq.com>  
> > 
> > This patch has been marked as Not Applicable in patchwork.
> > I assume that is because it doesn't apply.
> > Which I believe, in turn, is because it is whitespace mangled:
> > the tabs appear to have been substituted for combinations
> > of spaces and non-breaking spaces.
> > 
> > Please consider updating the way that you send patches -
> > e.g. using b4 or a different mail server - and reposting.
> 
> Also we should consider deleting liquidio instead of fixing it?
> It's _stupendously_ buggy, and Orphaned.

No objection from my side.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-03 10:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25  8:50 [PATCH] net: liquidio: avoid sleeping allocation under octeon_devices_lock Yang Zi
2026-09-02 15:54 ` Simon Horman
2026-09-03  0:58   ` Jakub Kicinski
2026-09-03 10:28     ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox