All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bobby Eshleman <bobbyeshleman@meta.com>
To: Michal Luczaj <mhal@rbox.co>
Cc: "Stefano Garzarella" <sgarzare@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Donald Hunter" <donald.hunter@gmail.com>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"George Zhang" <georgezhang@vmware.com>,
	"Andy King" <acking@vmware.com>,
	"Dmitry Torokhov" <dtor@vmware.com>,
	"Willem de Bruijn" <willemb@google.com>,
	virtualization@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	sargun@sargun.me, jlinbox@meta.com
Subject: Re: [PATCH net-next v8 4/7] vsock: add a netlink command to assign the g2h device to a netns
Date: Tue, 1 Dec 2026 13:05:55 -0800	[thread overview]
Message-ID: <aw82s6uxP1KqEKnf@devvm29614.prn0.facebook.com> (raw)
In-Reply-To: <c43c3882-00da-4f21-b80a-306abed6ca5f@rbox.co>

On Tue, Dec 01, 2026 at 05:19:31PM +0100, Michal Luczaj wrote:
> On 12/1/26 02:06, Bobby Eshleman wrote:
> > +/* Reset @sk if it can no longer reach the g2h device, as an unplug of the
> > + * device does (see virtio_vsock_reset_sock()).
> > + */
> > +static void vsock_g2h_reset_unreachable_sk(struct sock *sk)
> > +{
> > +	if (sk->sk_state == TCP_CLOSE || vsock_g2h_reachable_sk(vsock_sk(sk)))
> > +		return;
> > +
> > +	sk->sk_state = TCP_CLOSE;
> > +	sk->sk_err = ECONNRESET;
> > +	sk_error_report(sk);
> > +}
> 
> ...
> 
> > +/* Move the g2h device to @net, which keeps @net alive until the device leaves
> > + * again. Returns -ENODEV if no g2h transport is loaded, -EOPNOTSUPP if the
> > + * loaded one cannot be moved, and -EADDRINUSE if a guest in @net already uses
> > + * the device's CID.
> > + */
> > +static int vsock_g2h_net_assign(struct net *net, struct sk_buff *msg,
> > +				struct genl_info *info)
> > +{
> > +	struct netlink_ext_ack *extack = info->extack;
> > +	netns_tracker old_tracker;
> > +	struct net *old;
> > +	int ret;
> > +
> > +	mutex_lock(&vsock_register_mutex);
> > +
> > +	ret = -ENODEV;
> > +	if (!transport_g2h) {
> > +		NL_SET_ERR_MSG(extack, "no guest-to-host transport is loaded");
> > +		goto unlock;
> > +	}
> > +
> > +	ret = -EOPNOTSUPP;
> > +	if (!vsock_net_assignable(transport_g2h)) {
> > +		NL_SET_ERR_MSG(extack,
> > +			       "the loaded guest-to-host transport does not support namespace assignment");
> > +		goto unlock;
> > +	}
> > +
> > +	if (transport_h2g && !transport_h2g->has_remote_cid) {
> > +		NL_SET_ERR_MSG(extack,
> > +			       "the loaded host-to-guest transport cannot check the device's CID");
> > +		goto unlock;
> > +	}
> > +
> > +	ret = -EADDRINUSE;
> > +	if (transport_h2g &&
> > +	    transport_h2g->has_remote_cid(net,
> > +					  transport_g2h->get_local_cid())) {
> > +		NL_SET_ERR_MSG(extack,
> > +			       "a guest in the target namespace already uses the device's CID");
> > +		goto unlock;
> > +	}
> > +
> > +	ret = vsock_nl_dev_netns_fill(msg, info, net);
> > +	if (ret)
> > +		goto unlock;
> > +
> > +	ret = genlmsg_reply(msg, info);
> > +	msg = NULL;
> > +	if (ret)
> > +		goto unlock;
> > +
> > +	old = vsock_g2h_net_swap(net, &old_tracker);
> > +
> > +	/* See vsock_maybe_set_connected() comment about synchronizing with
> > +	 * connecting sockets.
> > +	 */
> > +	vsock_for_each_connected_socket(transport_g2h,
> > +					vsock_g2h_reset_unreachable_sk);
> > +
> 
> Are you sure a lockless (sk_lock-wise) reset is the right approach? I was
> hoping we could "reuse" vsock_g2h_reset_unreachable() from v7 to finally
> fix all those lockless transport resets. With this version, instead, we're
> introducing more lockless socket state writes.
> 
> thanks,
> Michal

I definitely agree with that goal. But since the lockless resets are a
broader vsock issue (virtio_vsock_reset_sock(),
vhost_vsock_reset_orphans(), vmci_transport_handle_detach()), I'd like
to treat them as pre-existing for this series and fix socket state
handling across vsock in follow-up patches.

Long term I agree with using lock_sock(), but in this series AFAICT it
mostly just prevents an inconsistent state that doesn't affect the user
much (mid-sweep RX RST resulting in TCP_CLOSING instead of TCP_CLOSE, w/
ECONNRESET). I'm just not sure I see a big enough win to justify the
extra complexity of iterator functions, the extra mutex, etc...
(additional ~75 lines of code) for this series in particular.

Best,
Bobby

  reply	other threads:[~2026-12-01 21:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:06 [PATCH net-next v8 0/7] vsock: assign the guest vsock device to a network namespace Bobby Eshleman
2026-12-01  1:06 ` [PATCH net-next v8 1/7] vsock: constify the transport in vsock_for_each_connected_socket() Bobby Eshleman
2026-12-01  1:06 ` [PATCH net-next v8 2/7] vsock: rename the vsock pernet operations Bobby Eshleman
2026-12-01  1:06 ` [PATCH net-next v8 3/7] vsock: pass the netns to ->has_remote_cid() Bobby Eshleman
2026-12-01  1:06 ` [PATCH net-next v8 4/7] vsock: add a netlink command to assign the g2h device to a netns Bobby Eshleman
2026-12-01 16:19   ` Michal Luczaj
2026-12-01 21:05     ` Bobby Eshleman [this message]
2026-12-02  1:08   ` sashiko-bot
2026-12-01  1:06 ` [PATCH net-next v8 5/7] vsock/virtio: support guest device network namespace Bobby Eshleman
2026-12-02  1:08   ` sashiko-bot
2026-12-01  1:06 ` [PATCH net-next v8 6/7] selftests/vsock: test the guest vsock " Bobby Eshleman
2026-12-01  1:06 ` [PATCH net-next v8 7/7] selftests/vsock: test the netns assign privilege checks Bobby Eshleman
2026-12-02  1:08 ` [PATCH net-next v8 0/7] vsock: assign the guest vsock device to a network namespace sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw82s6uxP1KqEKnf@devvm29614.prn0.facebook.com \
    --to=bobbyeshleman@meta.com \
    --cc=acking@vmware.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=dtor@vmware.com \
    --cc=edumazet@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=georgezhang@vmware.com \
    --cc=horms@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=jlinbox@meta.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mhal@rbox.co \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=sargun@sargun.me \
    --cc=sgarzare@redhat.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=willemb@google.com \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.