Re: [PATCH net v2 1/2] net: ravb: Fix missing rtnl lock in suspend path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 27.01.2025 12:28, Kory Maincent wrote:
> On Thu, 23 Jan 2025 18:33:58 +0100
> Kory Maincent <kory.maincent@xxxxxxxxxxx> wrote:
>  
>>>>  
>>>> @@ -3247,7 +3253,9 @@ static int ravb_resume(struct device *dev)
>>>>  
>>>>  	/* If WoL is enabled restore the interface. */
>>>>  	if (priv->wol_enabled) {
>>>> +		rtnl_lock();
>>>>  		ret = ravb_wol_restore(ndev);
>>>> +		rtnl_unlock();
>>>>  		if (ret)
>>>>  			return ret;
>>>>  	} else {
>>>> @@ -3257,7 +3265,9 @@ static int ravb_resume(struct device *dev)
>>>>  	}
>>>>  
>>>>  	/* Reopening the interface will restore the device to the working
>>>> state. */
>>>> +	rtnl_lock();
>>>>  	ret = ravb_open(ndev);
>>>> +	rtnl_unlock();
>>>>  	if (ret < 0)
>>>>  		goto out_rpm_put;
>>
>>> I don't like the multiple lock/unlock calls in each function. I think v1
>>> was better, where we take the lock once in each function and then unlock
>>> when it is no longer needed or when we're about to return.
>>
>> You will need to achieve a consensus on it with Claudiu. His point of view has
>> that the locking scheme looks complicated.
>>
>> On my side I don't have really an opinion, maybe a small preference for v1
>> which is protecting wol_enabled flag even if it is not needed.
> 
> Claudiu any remarks?

Sorry for the delay. I still consider it safe as proposed (taking the lock
around the individual functions) due to the above reasons:

1/ in ravb_suspend():
- the execution just returns after ravb_wol_setup()
- there is no need to lock around runtime PM function
  (pm_runtime_force_suspend()) as the execution through it reach this
  driver only though the driver specific runtime PM function which is a nop
  (and FMPOV it should be removed)

2/ in ravb_resume():
- locking only around ravb_wol_restore() and ravb_open() mimics what is
  done when the interface is open/closed through user space; in that
  scenario the ravb_close()/ravb_open() are called with rtnl_lock() held
  through devinet_ioctl()
- and for the above mentioned reason there is no need to lock around
  pm_runtime_force_resume()

Please follow the approach preferred by the maintainers.

Thank you,
Claudiu

> If not I will come back to the first version as asked by Paul who is the
> Maintainer of the ravb driver.
> 
> Sergey have asked to remove the duplicate of the if condition.
> Paul is this ok for you?
> 
> @@ -3245,19 +3250,21 @@ static int ravb_resume(struct device *dev)
>         if (!netif_running(ndev))
>                 return 0;
>  
> +       rtnl_lock();
>         /* If WoL is enabled restore the interface. */
> -       if (priv->wol_enabled) {
> +       if (priv->wol_enabled)
>                 ret = ravb_wol_restore(ndev);
> -               if (ret)
> -                       return ret;
> -       } else {
> +       else
>                 ret = pm_runtime_force_resume(dev);
> -               if (ret)
> -                       return ret;
> +
> +       if (ret) {
> +               rtnl_unlock();
> +               return ret;
>         }
>  
>         /* Reopening the interface will restore the device to the working
> state. */
>         ret = ravb_open(ndev);
> +       rtnl_unlock();
>         if (ret < 0)
>                 goto out_rpm_put;
> 
> 
> Note: Sergey, I have received your mail as spam. 
> 
> Regards,





[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux