[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aQ1Gyp87UYnr/VAO@devvm11784.nha0.facebook.com>
Date: Thu, 6 Nov 2025 17:09:30 -0800
From: Bobby Eshleman <bobbyeshleman@...il.com>
To: Stefano Garzarella <sgarzare@...hat.com>
Cc: Shuah Khan <shuah@...nel.org>, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Stefan Hajnoczi <stefanha@...hat.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Eugenio Pérez <eperezma@...hat.com>,
"K. Y. Srinivasan" <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>,
Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
Bryan Tan <bryan-bt.tan@...adcom.com>,
Vishnu Dasa <vishnu.dasa@...adcom.com>,
Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
virtualization@...ts.linux.dev, netdev@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, linux-hyperv@...r.kernel.org,
berrange@...hat.com, Bobby Eshleman <bobbyeshleman@...a.com>
Subject: Re: [PATCH net-next v8 01/14] vsock: a per-net vsock NS mode state
On Thu, Nov 06, 2025 at 05:16:29PM +0100, Stefano Garzarella wrote:
> On Thu, Oct 23, 2025 at 11:27:40AM -0700, Bobby Eshleman wrote:
> > From: Bobby Eshleman <bobbyeshleman@...a.com>
[...]
> > @@ -65,6 +66,7 @@ struct vsock_sock {
> > u32 peer_shutdown;
> > bool sent_request;
> > bool ignore_connecting_rst;
> > + enum vsock_net_mode net_mode;
> >
> > /* Protected by lock_sock(sk) */
> > u64 buffer_size;
> > @@ -256,4 +258,58 @@ static inline bool vsock_msgzerocopy_allow(const struct vsock_transport *t)
> > {
> > return t->msgzerocopy_allow && t->msgzerocopy_allow();
> > }
> > +
> > +static inline enum vsock_net_mode vsock_net_mode(struct net *net)
> > +{
> > + enum vsock_net_mode ret;
> > +
> > + spin_lock_bh(&net->vsock.lock);
> > + ret = net->vsock.mode;
>
> Do we really need a spin_lock just to set/get a variable?
> What about WRITE_ONCE/READ_ONCE and/or atomic ?
>
> Not a strong opinion, just to check if we can do something like this:
>
> static inline enum vsock_net_mode vsock_net_mode(struct net *net)
> {
> return READ_ONCE(net->vsock.mode);
> }
>
> static inline bool vsock_net_write_mode(struct net *net, u8 mode)
> {
> // Or using test_and_set_bit() if you prefer
> if (xchg(&net->vsock.mode_locked, true))
> return false;
>
> WRITE_ONCE(net->vsock.mode, mode);
> return true;
> }
>
I think that works and seems worth it to avoid the lock on the read
side. I'll move this over for the next rev.
[...]
Best,
Bobby
Powered by blists - more mailing lists