[PATCH mptcp-next v2 3/5] mptcp: use READ_ONCE() over sysctls
Gang Yan <[email protected]>
| Newsgroups | dev.linux.lists.mptcp |
|---|---|
| Message-ID | <[email protected]> |
From: "Matthieu Baerts (NGI0)" <[email protected]> To avoid KCSAN issues. This patch is in theory for -net, and will need to be split in multiple patches, with different Fixes tags. But I prefer to wait for Eric's patches, as I noticed he already started to modify mptcp_is_enabled: https://lore.kernel.org/CANn89iLdwhhwLyO6zRjWMEY3t9g60ZE8ZhOVx33ucg_uRETbmQ@mail.gmail.com Still, keeping this patch in this series, not to forget about it. Also write the pm_type field derived from the path manager name with WRITE_ONCE() in proc_path_manager(), to pair with the READ_ONCE() on mptcp_get_pm_type() added by this patch. Reported-by: Eric Dumazet <[email protected]> Closes: https://lore.kernel.org/CANn89iL=os-60kDKqMDdyiXuPF5CG=eejS0vmthwpDGXz_Bp8A@mail.gmail.com Co-developed-by: Tao Cui <[email protected]> Signed-off-by: Tao Cui <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> --- net/mptcp/ctrl.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c index c0481b09c1a1..733706f06f1b 100644 --- a/net/mptcp/ctrl.c +++ b/net/mptcp/ctrl.c @@ -50,39 +50,39 @@ static struct mptcp_pernet *mptcp_get_pernet(const struct net *net) int mptcp_is_enabled(const struct net *net) { - return mptcp_get_pernet(net)->mptcp_enabled; + return READ_ONCE(mptcp_get_pernet(net)->mptcp_enabled); } unsigned int mptcp_get_add_addr_timeout(const struct net *net) { - return mptcp_get_pernet(net)->add_addr_timeout; + return READ_ONCE(mptcp_get_pernet(net)->add_addr_timeout); } int mptcp_is_checksum_enabled(const struct net *net) { - return mptcp_get_pernet(net)->checksum_enabled; + return READ_ONCE(mptcp_get_pernet(net)->checksum_enabled); } int mptcp_allow_join_id0(const struct net *net) { - return mptcp_get_pernet(net)->allow_join_initial_addr_port; + return READ_ONCE(mptcp_get_pernet(net)->allow_join_initial_addr_port); } unsigned int mptcp_stale_loss_cnt(const struct net *net) { - return mptcp_get_pernet(net)->stale_loss_cnt; + return READ_ONCE(mptcp_get_pernet(net)->stale_loss_cnt); } unsigned int mptcp_close_timeout(const struct sock *sk) { if (sock_flag(sk, SOCK_DEAD)) return TCP_TIMEWAIT_LEN; - return mptcp_get_pernet(sock_net(sk))->close_timeout; + return READ_ONCE(mptcp_get_pernet(sock_net(sk))->close_timeout); } int mptcp_get_pm_type(const struct net *net) { - return mptcp_get_pernet(net)->pm_type; + return READ_ONCE(mptcp_get_pernet(net)->pm_type); } void mptcp_get_path_manager(const struct net *net, char *name) @@ -251,7 +251,7 @@ static int proc_path_manager(const struct ctl_table *ctl, int write, pm_type = MPTCP_PM_TYPE_KERNEL; else if (strncmp(pm_name, "userspace", MPTCP_PM_NAME_MAX) == 0) pm_type = MPTCP_PM_TYPE_USERSPACE; - pernet->pm_type = pm_type; + WRITE_ONCE(pernet->pm_type, pm_type); } } @@ -572,7 +572,7 @@ void mptcp_active_detect_blackhole(struct sock *ssk, bool expired) net = sock_net(ssk); timeouts = inet_csk(ssk)->icsk_retransmits; - to_max = mptcp_get_pernet(net)->syn_retrans_before_tcp_fallback; + to_max = READ_ONCE(mptcp_get_pernet(net)->syn_retrans_before_tcp_fallback); if (timeouts == to_max || (timeouts < to_max && expired)) { subflow->mpc_drop = 1; -- 2.43.0