On Mon, Aug 15, 2022 at 05:05:23PM +0300, Vitaliy Makkoveev wrote: > This diff takes a references on sliced sockets and keeps them until > sounslice() called. I don't propose to commit it as is, may be sorele() > should be reworked to call sofree() itself.
Exclusive netlock makes the current code safe. Of course if we want to unlock socket creation and closing something like your diff is needed. I like when you move forward. The part below makes sense. Before detaching a pcb, remove global visibility. Note that pf_inp_unlink(inp) should also be done early as protcol input functions may get a cached pcb from pf. Can you move the if (inp->inp_pf_sk) block also to top. This is only half way, but a step in the right direction. Another thread may already have a reference to inpcb. (not yet, but when we run more in parallel). Maybe an inp mutex can fix this. I am working on this for UDP input anyway. > void > Index: sys/netinet/in_pcb.c > =================================================================== > RCS file: /cvs/src/sys/netinet/in_pcb.c,v > retrieving revision 1.270 > diff -u -p -r1.270 in_pcb.c > --- sys/netinet/in_pcb.c 8 Aug 2022 12:06:30 -0000 1.270 > +++ sys/netinet/in_pcb.c 15 Aug 2022 14:02:37 -0000 > @@ -582,7 +582,16 @@ in_pcbdetach(struct inpcb *inp) > > NET_ASSERT_LOCKED(); > > + mtx_enter(&table->inpt_mtx); > + LIST_REMOVE(inp, inp_lhash); > + LIST_REMOVE(inp, inp_hash); > + TAILQ_REMOVE(&table->inpt_queue, inp, inp_queue); > + table->inpt_count--; > + mtx_leave(&table->inpt_mtx); > + > so->so_pcb = NULL; > + inp->inp_socket = NULL; > + > /* > * As long as the NET_LOCK() is the default lock for Internet > * sockets, do not release it to not introduce new sleeping > @@ -608,12 +617,6 @@ in_pcbdetach(struct inpcb *inp) > pf_inp_unlink(inp); > } > #endif > - mtx_enter(&table->inpt_mtx); > - LIST_REMOVE(inp, inp_lhash); > - LIST_REMOVE(inp, inp_hash); > - TAILQ_REMOVE(&table->inpt_queue, inp, inp_queue); > - table->inpt_count--; > - mtx_leave(&table->inpt_mtx); > > in_pcbunref(inp); > }
