]> www.infradead.org Git - users/hch/misc.git/commit
mptcp: pm: reuse sending nlmsg code in get_addr
authorGeliang Tang <tanggeliang@kylinos.cn>
Fri, 7 Feb 2025 13:59:30 +0000 (14:59 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 11 Feb 2025 11:46:37 +0000 (12:46 +0100)
commit8556f4aecc9a0620c1e411d6da1fe232d1c14138
tree97de20205490ca7d76123f2b37517a8267124e36
parentd47b80758f4c5d72a82cd8416cbf34617ded5c0b
mptcp: pm: reuse sending nlmsg code in get_addr

The netlink messages are sent both in mptcp_pm_nl_get_addr() and
mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive.
This is because the netlink PM and userspace PM use different locks to
protect the address entry that needs to be sent via the netlink message.
The former uses rcu read lock, and the latter uses msk->pm.lock.

The current get_addr() flow looks like this:

lock();
entry = get_entry();
send_nlmsg(entry);
unlock();

After holding the lock, get the entry from the list, send the entry, and
finally release the lock.

This patch changes the process by getting the entry while holding the lock,
then making a copy of the entry so that the lock can be released. Finally,
the copy of the entry is sent without locking:

lock();
entry = get_entry();
*copy = *entry;
unlock();

send_nlmsg(copy);

This way we can reuse the send_nlmsg() code in get_addr() interfaces
between the netlink PM and userspace PM. They only need to implement their
own get_addr() interfaces to hold the different locks, get the entry from
the different lists, then release the locks.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/mptcp/pm.c
net/mptcp/pm_netlink.c
net/mptcp/pm_userspace.c
net/mptcp/protocol.h