* [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure
@ 2023-07-10 20:41 Jacob Keller
2023-07-10 20:41 ` [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED Jacob Keller
2023-07-20 12:04 ` [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure Romanowski, Rafal
0 siblings, 2 replies; 4+ messages in thread
From: Jacob Keller @ 2023-07-10 20:41 UTC (permalink / raw)
To: Intel Wired LAN, Madhu Chittim, Anthony Nguyen
In iavf_adminq_task(), if kzalloc() fails to allocate the event.msg_buf,
the function will exit without releasing the adapter->crit_lock.
This is unlikely, but if it happens, the next access to that mutex will
deadlock.
Fix this by moving the unlock to the end of the function, and adding a new
label to allow jumping to the unlock portion of the function exit flow.
Fixes: fc2e6b3b132a ("iavf: Rework mutexes for better synchronisation")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/net/ethernet/intel/iavf/iavf_main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index 06ea61f30b6f..6d2f647066fb 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -3264,7 +3264,7 @@ static void iavf_adminq_task(struct work_struct *work)
event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
if (!event.msg_buf)
- goto out;
+ goto unlock;
do {
ret = iavf_clean_arq_element(hw, &event, &pending);
@@ -3279,7 +3279,6 @@ static void iavf_adminq_task(struct work_struct *work)
if (pending != 0)
memset(event.msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE);
} while (pending);
- mutex_unlock(&adapter->crit_lock);
if (iavf_is_reset_in_progress(adapter))
goto freedom;
@@ -3323,6 +3322,8 @@ static void iavf_adminq_task(struct work_struct *work)
freedom:
kfree(event.msg_buf);
+unlock:
+ mutex_unlock(&adapter->crit_lock);
out:
/* re-enable Admin queue interrupt cause */
iavf_misc_irq_enable(adapter);
base-commit: b4e87f37b7fc4e0408a1a67b60839c4f2e6fa40f
--
2.41.0.1.g9857a21e0017.dirty
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply related [flat|nested] 4+ messages in thread* [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED
2023-07-10 20:41 [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure Jacob Keller
@ 2023-07-10 20:41 ` Jacob Keller
2023-07-20 12:05 ` Romanowski, Rafal
2023-07-20 12:04 ` [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure Romanowski, Rafal
1 sibling, 1 reply; 4+ messages in thread
From: Jacob Keller @ 2023-07-10 20:41 UTC (permalink / raw)
To: Intel Wired LAN, Madhu Chittim, Anthony Nguyen
In iavf_adminq_task(), if the function can't acquire the
adapter->crit_lock, it checks if the driver is removing. If so, it simply
exits without re-enabling the interrupt. This is done to ensure that the
task stops processing as soon as possible once the driver is being removed.
However, if the IAVF_FLAG_PF_COMMS_FAILED is set, the function checks this
before attempting to acquire the lock. In this case, the function exits
early and re-enables the interrupt. This will happen even if the driver is
already removing.
Avoid this, by moving the check to after the adapter->crit_lock is
acquired. This way, if the driver is removing, we will not re-enable the
interrupt.
Fixes: fc2e6b3b132a ("iavf: Rework mutexes for better synchronisation")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/net/ethernet/intel/iavf/iavf_main.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index 6d2f647066fb..f329f81c793d 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -3250,9 +3250,6 @@ static void iavf_adminq_task(struct work_struct *work)
u32 val, oldval;
u16 pending;
- if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
- goto out;
-
if (!mutex_trylock(&adapter->crit_lock)) {
if (adapter->state == __IAVF_REMOVE)
return;
@@ -3261,6 +3258,9 @@ static void iavf_adminq_task(struct work_struct *work)
goto out;
}
+ if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
+ goto unlock;
+
event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
if (!event.msg_buf)
--
2.41.0.1.g9857a21e0017.dirty
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED
2023-07-10 20:41 ` [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED Jacob Keller
@ 2023-07-20 12:05 ` Romanowski, Rafal
0 siblings, 0 replies; 4+ messages in thread
From: Romanowski, Rafal @ 2023-07-20 12:05 UTC (permalink / raw)
To: Keller, Jacob E, Intel Wired LAN, Chittim, Madhu,
Nguyen, Anthony L
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Jacob Keller
> Sent: poniedziałek, 10 lipca 2023 22:41
> To: Intel Wired LAN <intel-wired-lan@lists.osuosl.org>; Chittim, Madhu
> <madhu.chittim@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>
> Subject: [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state
> before IAVF_FLAG_PF_COMMS_FAILED
>
> In iavf_adminq_task(), if the function can't acquire the
> adapter->crit_lock, it checks if the driver is removing. If so, it
> adapter->simply
> exits without re-enabling the interrupt. This is done to ensure that the task
> stops processing as soon as possible once the driver is being removed.
>
> However, if the IAVF_FLAG_PF_COMMS_FAILED is set, the function checks
> this before attempting to acquire the lock. In this case, the function exits
> early and re-enables the interrupt. This will happen even if the driver is
> already removing.
>
> Avoid this, by moving the check to after the adapter->crit_lock is acquired.
> This way, if the driver is removing, we will not re-enable the interrupt.
>
> Fixes: fc2e6b3b132a ("iavf: Rework mutexes for better synchronisation")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> ---
> drivers/net/ethernet/intel/iavf/iavf_main.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c
> b/drivers/net/ethernet/intel/iavf/iavf_main.c
> index 6d2f647066fb..f329f81c793d 100644
> --- a/drivers/net/ethernet/intel/iavf/iavf_main.c
> +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure
2023-07-10 20:41 [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure Jacob Keller
2023-07-10 20:41 ` [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED Jacob Keller
@ 2023-07-20 12:04 ` Romanowski, Rafal
1 sibling, 0 replies; 4+ messages in thread
From: Romanowski, Rafal @ 2023-07-20 12:04 UTC (permalink / raw)
To: Keller, Jacob E, Intel Wired LAN, Chittim, Madhu,
Nguyen, Anthony L
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Jacob Keller
> Sent: poniedziałek, 10 lipca 2023 22:41
> To: Intel Wired LAN <intel-wired-lan@lists.osuosl.org>; Chittim, Madhu
> <madhu.chittim@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>
> Subject: [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on
> allocation failure
>
> In iavf_adminq_task(), if kzalloc() fails to allocate the event.msg_buf, the
> function will exit without releasing the adapter->crit_lock.
>
> This is unlikely, but if it happens, the next access to that mutex will deadlock.
>
> Fix this by moving the unlock to the end of the function, and adding a new
> label to allow jumping to the unlock portion of the function exit flow.
>
> Fixes: fc2e6b3b132a ("iavf: Rework mutexes for better synchronisation")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> ---
> drivers/net/ethernet/intel/iavf/iavf_main.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c
> b/drivers/net/ethernet/intel/iavf/iavf_main.c
> index 06ea61f30b6f..6d2f647066fb 100644
> --- a/drivers/net/ethernet/intel/iavf/iavf_main.c
> +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
> @@ -3264,7 +3264,7 @@ static void iavf_adminq_task(struct work_struct
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-20 12:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-10 20:41 [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure Jacob Keller
2023-07-10 20:41 ` [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED Jacob Keller
2023-07-20 12:05 ` Romanowski, Rafal
2023-07-20 12:04 ` [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failure Romanowski, Rafal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox