diff mbox series

[net-next,v9,4/5] r8169: Use spinlock to guard config register locking

Message ID 20230225034635.2220386-5-kai.heng.feng@canonical.com (mailing list archive)
State Superseded
Headers show
Series r8169: Temporarily disable ASPM on NAPI poll | expand

Commit Message

Kai-Heng Feng Feb. 25, 2023, 3:46 a.m. UTC
Right now r8169 doesn't have parallel access to its config register, but
the next patch makes the driver access config register at anytime.

So add a spinlock to protect the config register from any potential race.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v9:
 - Replace mutex with spinlock so it can be used in softirq context.

v8:
 - Swap the place when using the mutex. Protect when config register is
   unlocked.

v7:
 - This is a new patch.

 drivers/net/ethernet/realtek/r8169_main.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Kuppuswamy Sathyanarayanan Feb. 25, 2023, 6:16 a.m. UTC | #1
On 2/24/23 7:46 PM, Kai-Heng Feng wrote:
> Right now r8169 doesn't have parallel access to its config register, but
> the next patch makes the driver access config register at anytime.
> 
> So add a spinlock to protect the config register from any potential race.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v9:
>  - Replace mutex with spinlock so it can be used in softirq context.
> 
> v8:
>  - Swap the place when using the mutex. Protect when config register is
>    unlocked.
> 
> v7:
>  - This is a new patch.
> 
>  drivers/net/ethernet/realtek/r8169_main.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index a857650c2e82b..fb73b5386701f 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -613,6 +613,8 @@ struct rtl8169_private {
>  		struct work_struct work;
>  	} wk;
>  
> +	spinlock_t config_lock;
> +
>  	unsigned supports_gmii:1;
>  	unsigned aspm_manageable:1;
>  	dma_addr_t counters_phys_addr;
> @@ -662,10 +664,12 @@ static inline struct device *tp_to_dev(struct rtl8169_private *tp)
>  static void rtl_lock_config_regs(struct rtl8169_private *tp)
>  {
>  	RTL_W8(tp, Cfg9346, Cfg9346_Lock);
> +	spin_unlock_bh(&tp->config_lock);

You mean spin_lock_bh() here right?

>  }
>  
>  static void rtl_unlock_config_regs(struct rtl8169_private *tp)
>  {
> +	spin_lock_bh(&tp->config_lock);
>  	RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
>  }
>  
> @@ -5217,6 +5221,8 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>  		return rc;
>  	}
>  
> +	spin_lock_init(&tp->config_lock);
> +
>  	tp->mmio_addr = pcim_iomap_table(pdev)[region];
>  
>  	xid = (RTL_R32(tp, TxConfig) >> 20) & 0xfcf;
diff mbox series

Patch

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index a857650c2e82b..fb73b5386701f 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -613,6 +613,8 @@  struct rtl8169_private {
 		struct work_struct work;
 	} wk;
 
+	spinlock_t config_lock;
+
 	unsigned supports_gmii:1;
 	unsigned aspm_manageable:1;
 	dma_addr_t counters_phys_addr;
@@ -662,10 +664,12 @@  static inline struct device *tp_to_dev(struct rtl8169_private *tp)
 static void rtl_lock_config_regs(struct rtl8169_private *tp)
 {
 	RTL_W8(tp, Cfg9346, Cfg9346_Lock);
+	spin_unlock_bh(&tp->config_lock);
 }
 
 static void rtl_unlock_config_regs(struct rtl8169_private *tp)
 {
+	spin_lock_bh(&tp->config_lock);
 	RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
 }
 
@@ -5217,6 +5221,8 @@  static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		return rc;
 	}
 
+	spin_lock_init(&tp->config_lock);
+
 	tp->mmio_addr = pcim_iomap_table(pdev)[region];
 
 	xid = (RTL_R32(tp, TxConfig) >> 20) & 0xfcf;