* [PATCH] smc91c92_cs : add a spinlock to avoid race condition
@ 2016-08-16 13:39 Pavel Andrianov
2016-08-19 4:07 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Andrianov @ 2016-08-16 13:39 UTC (permalink / raw)
To: Mugunthan V N
Cc: Pavel Andrianov, David S. Miller, Antonio Quartulli,
Felipe Balbi, Florian Westphal, netdev, linux-kernel,
vaishali.thakkar, ldv-project
smc_reset may be executed in parallel with timer function media_check.
To avoid data race in smc_set_xcvr a spinlock was added.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Pavel Andrianov <andrianov@ispras.ru>
---
drivers/net/ethernet/smsc/smc91c92_cs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/smsc/smc91c92_cs.c b/drivers/net/ethernet/smsc/smc91c92_cs.c
index db3c696..69d865c 100644
--- a/drivers/net/ethernet/smsc/smc91c92_cs.c
+++ b/drivers/net/ethernet/smsc/smc91c92_cs.c
@@ -1637,6 +1637,7 @@ static void smc_reset(struct net_device *dev)
unsigned int ioaddr = dev->base_addr;
struct smc_private *smc = netdev_priv(dev);
int i;
+ unsigned long flags;
netdev_dbg(dev, "smc91c92 reset called.\n");
@@ -1647,6 +1648,7 @@ static void smc_reset(struct net_device *dev)
outw(RCR_SOFTRESET, ioaddr + RCR);
udelay(10);
+ spin_lock_irqsave(&smc->lock, flags);
/* Clear the transmit and receive configuration registers. */
outw(RCR_CLEAR, ioaddr + RCR);
outw(TCR_CLEAR, ioaddr + TCR);
@@ -1699,6 +1701,7 @@ static void smc_reset(struct net_device *dev)
SMC_SELECT_BANK(2);
outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
ioaddr + INTERRUPT);
+ spin_unlock_irqrestore(&smc->lock, flags);
}
/*======================================================================
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] smc91c92_cs : add a spinlock to avoid race condition
2016-08-16 13:39 [PATCH] smc91c92_cs : add a spinlock to avoid race condition Pavel Andrianov
@ 2016-08-19 4:07 ` David Miller
2016-08-19 4:41 ` Vaishali Thakkar
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2016-08-19 4:07 UTC (permalink / raw)
To: andrianov
Cc: mugunthanvnm, a, felipe.balbi, fw, netdev, linux-kernel,
vaishali.thakkar, ldv-project
From: Pavel Andrianov <andrianov@ispras.ru>
Date: Tue, 16 Aug 2016 16:39:06 +0300
> smc_reset may be executed in parallel with timer function media_check.
> To avoid data race in smc_set_xcvr a spinlock was added.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Pavel Andrianov <andrianov@ispras.ru>
This is not sufficient.
You have to block basically the entire function, because both
smc_reset and media_check program the bank selection so could
corrupt eachother's register accesses.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] smc91c92_cs : add a spinlock to avoid race condition
2016-08-19 4:07 ` David Miller
@ 2016-08-19 4:41 ` Vaishali Thakkar
2016-08-19 6:00 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Vaishali Thakkar @ 2016-08-19 4:41 UTC (permalink / raw)
To: David Miller, andrianov
Cc: mugunthanvnm, a, felipe.balbi, fw, netdev, linux-kernel, ldv-project
On Friday 19 August 2016 09:37 AM, David Miller wrote:
> From: Pavel Andrianov <andrianov@ispras.ru>
> Date: Tue, 16 Aug 2016 16:39:06 +0300
>
>> smc_reset may be executed in parallel with timer function media_check.
>> To avoid data race in smc_set_xcvr a spinlock was added.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Pavel Andrianov <andrianov@ispras.ru>
>
> This is not sufficient.
>
> You have to block basically the entire function, because both
> smc_reset and media_check program the bank selection so could
> corrupt eachother's register accesses.
Hmm, but then there is a use of udelay as well. Would it be still
fine to acquire a spinlock on whole function?
>
--
Vaishali
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] smc91c92_cs : add a spinlock to avoid race condition
2016-08-19 4:41 ` Vaishali Thakkar
@ 2016-08-19 6:00 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2016-08-19 6:00 UTC (permalink / raw)
To: vaishali.thakkar
Cc: andrianov, mugunthanvnm, a, felipe.balbi, fw, netdev,
linux-kernel, ldv-project
From: Vaishali Thakkar <vaishali.thakkar@oracle.com>
Date: Fri, 19 Aug 2016 10:11:32 +0530
>
>
> On Friday 19 August 2016 09:37 AM, David Miller wrote:
>> From: Pavel Andrianov <andrianov@ispras.ru>
>> Date: Tue, 16 Aug 2016 16:39:06 +0300
>>
>>> smc_reset may be executed in parallel with timer function media_check.
>>> To avoid data race in smc_set_xcvr a spinlock was added.
>>>
>>> Found by Linux Driver Verification project (linuxtesting.org).
>>>
>>> Signed-off-by: Pavel Andrianov <andrianov@ispras.ru>
>>
>> This is not sufficient.
>>
>> You have to block basically the entire function, because both
>> smc_reset and media_check program the bank selection so could
>> corrupt eachother's register accesses.
>
> Hmm, but then there is a use of udelay as well. Would it be still
> fine to acquire a spinlock on whole function?
I don't know, but what I'm telling you is that you have to execute
register programming these two functions do atomically so that the
bank selection doesn't check get changed midstream.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-08-19 6:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-16 13:39 [PATCH] smc91c92_cs : add a spinlock to avoid race condition Pavel Andrianov
2016-08-19 4:07 ` David Miller
2016-08-19 4:41 ` Vaishali Thakkar
2016-08-19 6:00 ` David Miller
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).