diff mbox series

sfc: extend the locking on mcdi->seqno

Message ID 20220301222822.19241-1-dossche.niels@gmail.com (mailing list archive)
State Accepted
Commit f1fb205efb0ccca55626fd4ef38570dd16b44719
Delegated to: Netdev Maintainers
Headers show
Series sfc: extend the locking on mcdi->seqno | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Niels Dossche March 1, 2022, 10:28 p.m. UTC
seqno could be read as a stale value outside of the lock. The lock is
already acquired to protect the modification of seqno against a possible
race condition. Place the reading of this value also inside this locking
to protect it against a possible race condition.

Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---
 drivers/net/ethernet/sfc/mcdi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin Habets March 3, 2022, 8:12 a.m. UTC | #1
On Tue, Mar 01, 2022 at 11:28:22PM +0100, Niels Dossche wrote:
> seqno could be read as a stale value outside of the lock. The lock is
> already acquired to protect the modification of seqno against a possible
> race condition. Place the reading of this value also inside this locking
> to protect it against a possible race condition.
> 
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>

Acked-by: Martin Habets <habetsm.xilinx@gmail.com>

> ---
>  drivers/net/ethernet/sfc/mcdi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c
> index be6bfd6b7ec7..50baf62b2cbc 100644
> --- a/drivers/net/ethernet/sfc/mcdi.c
> +++ b/drivers/net/ethernet/sfc/mcdi.c
> @@ -163,9 +163,9 @@ static void efx_mcdi_send_request(struct efx_nic *efx, unsigned cmd,
>  	/* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
>  	spin_lock_bh(&mcdi->iface_lock);
>  	++mcdi->seqno;
> +	seqno = mcdi->seqno & SEQ_MASK;
>  	spin_unlock_bh(&mcdi->iface_lock);
>  
> -	seqno = mcdi->seqno & SEQ_MASK;
>  	xflags = 0;
>  	if (mcdi->mode == MCDI_MODE_EVENTS)
>  		xflags |= MCDI_HEADER_XFLAGS_EVREQ;
> -- 
> 2.35.1
patchwork-bot+netdevbpf@kernel.org March 3, 2022, 2:20 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Tue,  1 Mar 2022 23:28:22 +0100 you wrote:
> seqno could be read as a stale value outside of the lock. The lock is
> already acquired to protect the modification of seqno against a possible
> race condition. Place the reading of this value also inside this locking
> to protect it against a possible race condition.
> 
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
> 
> [...]

Here is the summary with links:
  - sfc: extend the locking on mcdi->seqno
    https://git.kernel.org/netdev/net/c/f1fb205efb0c

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c
index be6bfd6b7ec7..50baf62b2cbc 100644
--- a/drivers/net/ethernet/sfc/mcdi.c
+++ b/drivers/net/ethernet/sfc/mcdi.c
@@ -163,9 +163,9 @@  static void efx_mcdi_send_request(struct efx_nic *efx, unsigned cmd,
 	/* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
 	spin_lock_bh(&mcdi->iface_lock);
 	++mcdi->seqno;
+	seqno = mcdi->seqno & SEQ_MASK;
 	spin_unlock_bh(&mcdi->iface_lock);
 
-	seqno = mcdi->seqno & SEQ_MASK;
 	xflags = 0;
 	if (mcdi->mode == MCDI_MODE_EVENTS)
 		xflags |= MCDI_HEADER_XFLAGS_EVREQ;