Page MenuHomeFreeBSD

unix: provide an option to return locked from unp_connectat()
ClosedPublic

Authored by glebius on May 23 2022, 9:01 PM.
Tags
None
Referenced Files
F96160801: D35298.diff
Mon, Sep 23, 10:20 PM
Unknown Object (File)
Tue, Sep 17, 2:47 PM
Unknown Object (File)
Tue, Sep 17, 7:59 AM
Unknown Object (File)
Sun, Sep 15, 10:06 PM
Unknown Object (File)
Wed, Sep 11, 7:08 AM
Unknown Object (File)
Wed, Sep 4, 8:14 PM
Unknown Object (File)
Fri, Aug 30, 2:01 AM
Unknown Object (File)
Aug 24 2024, 1:59 PM
Subscribers

Details

Summary

Use this new version in unix/dgram socket when sending to a target
address. This removes extra lock release/acquisition and possible
counter-intuitive ENOTCONN.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Warnings
SeverityLocationCodeMessage
Warningsys/kern/uipc_usrreq.c:724SPELL1Possible Spelling Mistake
Warningsys/kern/uipc_usrreq.c:1825SPELL1Possible Spelling Mistake
Unit
No Test Coverage
Build Status
Buildable 45679
Build 42567: arc lint + arc unit

Event Timeline

Note: this patch is a step towards D35303.

sys/kern/uipc_usrreq.c
1830

I don't have a concrete suggestion right now, but I don't like these kinds of "naked" boolean flags. IMO it'd be better to have a separate function.

1980
1986

vput() can sleep when releasing the final reference, so we can't hold PCB locks here.

sys/kern/uipc_usrreq.c
1986

Thinking a bit more, unp2 should already hold a use-ref on the vnode, and this ref is protected by the PCB lock. So after the VOP_UNP_CONNECT() call I believe the use count on vp will be >= 2. The problem is that unp2's PCB lock is released after calling sonewconn(), and after that point the use count can drop to 1. But in the !connreq case (i.e., the SOCK_DGRAM case), I think the vput() call is effectively guaranteed not to sleep. Not sure if that's sufficient for you.

glebius added inline comments.
sys/kern/uipc_usrreq.c
1986

Thanks for input! I will put that into a comment.

sys/kern/uipc_usrreq.c
1989

So let's assert !(return_locked && connreq)?

Add assertion befor vput().

sys/kern/uipc_usrreq.c
1222

Instead use unp2 = unp_pcb_lock_peer(unp) and check for NULL. I believe it is possible for the socket to be disconnected again while PCB locks are dropped.

sys/kern/uipc_usrreq.c
1222

I can't understand. The whole idea of this revision is that unp_connectat() doesn't drop the locks and such situation is impossible.

markj added inline comments.
sys/kern/uipc_usrreq.c
1222

Ah, got it.

This revision is now accepted and ready to land.Jun 1 2022, 4:19 PM
This revision was landed with ongoing or failed builds.Jun 24 2022, 4:11 PM
This revision was automatically updated to reflect the committed changes.