diff mbox series

[net] net/sched: make psched_mtu() RTNL-less safe

Message ID 20230711000429.558248-1-pctammela@mojatatu.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] net/sched: make psched_mtu() RTNL-less safe | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1408 this patch: 1408
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 1368 this patch: 1368
netdev/verify_signedoff fail author Signed-off-by missing
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1447 this patch: 1447
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Pedro Tammela July 11, 2023, 12:04 a.m. UTC
Eric Dumazet says[1]:
---
Speaking of psched_mtu(), I see that net/sched/sch_pie.c is using it
without holding RTNL, so dev->mtu can be changed underneath.
KCSAN could issue a warning.
---

Annotate dev->mtu with READ_ONCE() so KCSAN don't issue a warning.

[1] https://lore.kernel.org/all/CANn89iJoJO5VtaJ-2=_d2aOQhb0Xw8iBT_Cxqp2HyuS-zj6azw@mail.gmail.com/

Fixes: d4b36210c2e6 ("net: pkt_sched: PIE AQM scheme")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
---
 include/net/pkt_sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kuniyuki Iwashima July 11, 2023, 12:14 a.m. UTC | #1
From: Pedro Tammela <pctammela@mojatatu.com>
Date: Mon, 10 Jul 2023 21:04:29 -0300
> Eric Dumazet says[1]:
> ---

I think we shouldn't use `---` here, or the message below will
be dropped while merging.


> Speaking of psched_mtu(), I see that net/sched/sch_pie.c is using it
> without holding RTNL, so dev->mtu can be changed underneath.
> KCSAN could issue a warning.
> ---
> 
> Annotate dev->mtu with READ_ONCE() so KCSAN don't issue a warning.
> 
> [1] https://lore.kernel.org/all/CANn89iJoJO5VtaJ-2=_d2aOQhb0Xw8iBT_Cxqp2HyuS-zj6azw@mail.gmail.com/
> 
> Fixes: d4b36210c2e6 ("net: pkt_sched: PIE AQM scheme")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
> ---
>  include/net/pkt_sched.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h
> index e98aac9d5ad5..15960564e0c3 100644
> --- a/include/net/pkt_sched.h
> +++ b/include/net/pkt_sched.h
> @@ -134,7 +134,7 @@ extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
>   */
>  static inline unsigned int psched_mtu(const struct net_device *dev)
>  {
> -	return dev->mtu + dev->hard_header_len;
> +	return READ_ONCE(dev->mtu) + dev->hard_header_len;
>  }
>  
>  static inline struct net *qdisc_net(struct Qdisc *q)
> -- 
> 2.39.2
Pedro Tammela July 11, 2023, 2:13 a.m. UTC | #2
On 10/07/2023 21:14, Kuniyuki Iwashima wrote:
> From: Pedro Tammela <pctammela@mojatatu.com>
> Date: Mon, 10 Jul 2023 21:04:29 -0300
>> Eric Dumazet says[1]:
>> ---
> 
> I think we shouldn't use `---` here, or the message below will
> be dropped while merging.

Thanks for catching this. Will resend.

> 
> 
>> Speaking of psched_mtu(), I see that net/sched/sch_pie.c is using it
>> without holding RTNL, so dev->mtu can be changed underneath.
>> KCSAN could issue a warning.
>> ---
>>
>> Annotate dev->mtu with READ_ONCE() so KCSAN don't issue a warning.
>>
>> [1] https://lore.kernel.org/all/CANn89iJoJO5VtaJ-2=_d2aOQhb0Xw8iBT_Cxqp2HyuS-zj6azw@mail.gmail.com/
>>
>> Fixes: d4b36210c2e6 ("net: pkt_sched: PIE AQM scheme")
>> Suggested-by: Eric Dumazet <edumazet@google.com>
>> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
>> ---
>>   include/net/pkt_sched.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h
>> index e98aac9d5ad5..15960564e0c3 100644
>> --- a/include/net/pkt_sched.h
>> +++ b/include/net/pkt_sched.h
>> @@ -134,7 +134,7 @@ extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
>>    */
>>   static inline unsigned int psched_mtu(const struct net_device *dev)
>>   {
>> -	return dev->mtu + dev->hard_header_len;
>> +	return READ_ONCE(dev->mtu) + dev->hard_header_len;
>>   }
>>   
>>   static inline struct net *qdisc_net(struct Qdisc *q)
>> -- 
>> 2.39.2
diff mbox series

Patch

diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h
index e98aac9d5ad5..15960564e0c3 100644
--- a/include/net/pkt_sched.h
+++ b/include/net/pkt_sched.h
@@ -134,7 +134,7 @@  extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
  */
 static inline unsigned int psched_mtu(const struct net_device *dev)
 {
-	return dev->mtu + dev->hard_header_len;
+	return READ_ONCE(dev->mtu) + dev->hard_header_len;
 }
 
 static inline struct net *qdisc_net(struct Qdisc *q)