Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'af_unix-remove-old-gc-leftovers'

Kuniyuki Iwashima says:

====================
af_unix: Remove old GC leftovers.

This is a follow-up series for commit 4090fa373f0e ("af_unix: Replace
garbage collection algorithm.") which introduced the new GC for AF_UNIX.

Now we no longer need two ugly tricks for the old GC, let's remove them.
====================

Link: https://lore.kernel.org/r/20240401173125.92184-1-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+3 -51
-1
include/net/af_unix.h
··· 17 17 } 18 18 #endif 19 19 20 - extern spinlock_t unix_gc_lock; 21 20 extern unsigned int unix_tot_inflight; 22 21 void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver); 23 22 void unix_del_edges(struct scm_fp_list *fpl);
+2 -49
net/unix/af_unix.c
··· 1794 1794 if (too_many_unix_fds(current)) 1795 1795 return -ETOOMANYREFS; 1796 1796 1797 - /* Need to duplicate file references for the sake of garbage 1798 - * collection. Otherwise a socket in the fps might become a 1799 - * candidate for GC while the skb is not yet queued. 1800 - */ 1801 - UNIXCB(skb).fp = scm_fp_dup(scm->fp); 1802 - if (!UNIXCB(skb).fp) 1803 - return -ENOMEM; 1797 + UNIXCB(skb).fp = scm->fp; 1798 + scm->fp = NULL; 1804 1799 1805 1800 if (unix_prepare_fpl(UNIXCB(skb).fp)) 1806 1801 return -ENOMEM; ··· 1814 1819 static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb) 1815 1820 { 1816 1821 scm->fp = scm_fp_dup(UNIXCB(skb).fp); 1817 - 1818 - /* 1819 - * Garbage collection of unix sockets starts by selecting a set of 1820 - * candidate sockets which have reference only from being in flight 1821 - * (total_refs == inflight_refs). This condition is checked once during 1822 - * the candidate collection phase, and candidates are marked as such, so 1823 - * that non-candidates can later be ignored. While inflight_refs is 1824 - * protected by unix_gc_lock, total_refs (file count) is not, hence this 1825 - * is an instantaneous decision. 1826 - * 1827 - * Once a candidate, however, the socket must not be reinstalled into a 1828 - * file descriptor while the garbage collection is in progress. 1829 - * 1830 - * If the above conditions are met, then the directed graph of 1831 - * candidates (*) does not change while unix_gc_lock is held. 1832 - * 1833 - * Any operations that changes the file count through file descriptors 1834 - * (dup, close, sendmsg) does not change the graph since candidates are 1835 - * not installed in fds. 1836 - * 1837 - * Dequeing a candidate via recvmsg would install it into an fd, but 1838 - * that takes unix_gc_lock to decrement the inflight count, so it's 1839 - * serialized with garbage collection. 1840 - * 1841 - * MSG_PEEK is special in that it does not change the inflight count, 1842 - * yet does install the socket into an fd. The following lock/unlock 1843 - * pair is to ensure serialization with garbage collection. It must be 1844 - * done between incrementing the file count and installing the file into 1845 - * an fd. 1846 - * 1847 - * If garbage collection starts after the barrier provided by the 1848 - * lock/unlock, then it will see the elevated refcount and not mark this 1849 - * as a candidate. If a garbage collection is already in progress 1850 - * before the file count was incremented, then the lock/unlock pair will 1851 - * ensure that garbage collection is finished before progressing to 1852 - * installing the fd. 1853 - * 1854 - * (*) A -> B where B is on the queue of A or B is on the queue of C 1855 - * which is on the queue of listening socket A. 1856 - */ 1857 - spin_lock(&unix_gc_lock); 1858 - spin_unlock(&unix_gc_lock); 1859 1822 } 1860 1823 1861 1824 static void unix_destruct_scm(struct sk_buff *skb)
+1 -1
net/unix/garbage.c
··· 183 183 } 184 184 } 185 185 186 - DEFINE_SPINLOCK(unix_gc_lock); 186 + static DEFINE_SPINLOCK(unix_gc_lock); 187 187 unsigned int unix_tot_inflight; 188 188 189 189 void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver)