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
Unknown Object (File)
Wed, Apr 24, 8:14 AM
Unknown Object (File)
Fri, Apr 5, 10:41 AM
Unknown Object (File)
Fri, Apr 5, 10:37 AM
Unknown Object (File)
Fri, Apr 5, 10:37 AM
Unknown Object (File)
Fri, Apr 5, 10:37 AM
Unknown Object (File)
Fri, Apr 5, 10:37 AM
Unknown Object (File)
Fri, Apr 5, 10:18 AM
Unknown Object (File)
Jan 28 2024, 10:26 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:1823SPELL1Possible Spelling Mistake
Unit
No Test Coverage
Build Status
Buildable 45744
Build 42632: arc lint + arc unit

Event Timeline

Note: this patch is a step towards D35303.

sys/kern/uipc_usrreq.c
1828

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.

1978–1979
1991

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

sys/kern/uipc_usrreq.c
1991

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
1991

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

sys/kern/uipc_usrreq.c
1987

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

Add assertion befor vput().

sys/kern/uipc_usrreq.c
1216

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
1216

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
1216

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.