From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 359B51F30A4 for ; Sun, 11 Jan 2026 06:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768112992; cv=none; b=tbc2R7UPIV7DoeqqiexVmOBwNAzZqfkIVFyhjZan3esCFGMmfM1aloP3XTx5ftvE5cpPbVujmNG9xHBCPIRcSeCnqUgD4h/STvTpoDSMpJ9eb8TkS63jZxklc53OwOSrZSPMv369e2lmo1NTnRWc6ZRJHXNjEyR8Uf/WUUJoSgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768112992; c=relaxed/simple; bh=jBqzGAPrybDMcPA1sSp012FV6F6PScUrNqkxyjb03ao=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IJLwG0QODi4WdP1H6j4YpQi+EHdXFfp49fhGG0E/7oiUgEZ33QG5ifduYLz5UDJPgVTL60sWibYItMGDBSsgi7vv79w50aa0M36HGWCIWicIQxoundvkYYkmZNsqh5g0QEv5IWVKsjyjMFuXHxKI7szhGUlLLtLTdc3RMhUuiTQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iBkVDWOr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=p8NgQd9H; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iBkVDWOr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="p8NgQd9H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768112988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IqILrVCS9tDmtote2rLypfKXBmD+4YEAa7AMdCllKvk=; b=iBkVDWOrRHHjJB0qQDDqckm3A84yFVXVylmivPMy8oMXDOp26r1xSN35av7HUTviPq6eEv mx2gOeDfs2A8D4lI52uM1HOpYhxIWF/xfUkA99UlCFyK+Gj0ZnUhJpb0Be2CHStK3xhVE1 COgMrNufD2pL+rzt1naYFfKPDUSyEnI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-7uTi2C_nMJuyYhRPjlMjHg-1; Sun, 11 Jan 2026 01:29:46 -0500 X-MC-Unique: 7uTi2C_nMJuyYhRPjlMjHg-1 X-Mimecast-MFC-AGG-ID: 7uTi2C_nMJuyYhRPjlMjHg_1768112985 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4775d8428e8so44695355e9.0 for ; Sat, 10 Jan 2026 22:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1768112985; x=1768717785; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=IqILrVCS9tDmtote2rLypfKXBmD+4YEAa7AMdCllKvk=; b=p8NgQd9HGXpY9tfzvtBtlmAr8X0/KkDCiIA8LJgW/K75S/uiKhGYamGXqeGCuz+n8z Y9Bj9NScYgIC/p/LBTdMFOW9E/1EJ8euS4ont8QvhV0emJQhpkQXYfiKq3RimmZsCA4g 6b6P32+/OmwCv1v881/O/eHg2dYwmtKphp6c1Z4KqddLIj45qlAgL7AvfA9ZgwW5QGWe cMgfyZFi7R3c3uGrSoTU/NoSF4cUuAiA9lMEia2b3r8Yi4UitJMnQDJ5v+a/Xu14jHK3 r0xquq3M9SDHDTi5Hs6YjGyiANb5FRUNt2/edX4I+i3IIGuFRNje2dfmpjS9Nbyfb74c UiIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768112985; x=1768717785; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IqILrVCS9tDmtote2rLypfKXBmD+4YEAa7AMdCllKvk=; b=prEjNbxYdaOCuhupIvnO3jeqJCQlQPebxqhihS9dOHHZiqwSSpC1pGbHuwFlvl3DgT wIMScgbBLI+uYCG5abSU+w4kXbYIySWxMpX7xdqT7zPUFPmOH0vOCnle6rtc9dlXeW2S Lz0U3St59APoEKjotRI0aPhfdUQkoR8eiLrQioC4lyqP66PIeGVKOzbD0zdoxKobKSK0 4Ti2vtLt+m4hlqJqR4NnNFC8kbeYaI3x1E8H3HORhA/JQWng4Zzg782a3OR+EUNRfQ4z 9qVMhqrqLubzOd6uadkPdu+FZ36F2LCASI1ZF9k6Kyx71NvrBe85h4XQAmb+lUJ0fJV4 ajPQ== X-Forwarded-Encrypted: i=1; AJvYcCXzjnf2Blhhl1urR4sUAzrWgkU7pIFd8vn/bgGao+6L15UlgLu3DBN63hlbA/LlUL0eTiqEDAG0ZrxIfRE=@vger.kernel.org X-Gm-Message-State: AOJu0YxcCZNgFxQWp2t2y5bTsgQgldfc06r/kHs5J9+emfLSnoCvi+Gl bswLu8swKgdHioJ+CqOOHqb+8sE/LM6cv5NjFSNwx9Xb6hcTBMd63+DjF2hRs5SBiDA2xg0nN2b fZ4sPMuLc5fheDaBjFDW7csqN4nKeyBgEe5Nz6AGAB/NRD5K1Kum7a1Efo109p4PiYw== X-Gm-Gg: AY/fxX4/KA5p8Lnh6q6pXu/na38SttWmsXt7i9OhZEAEd0QeXGNL/ZHqu9MFdW8Xqsc A/5Wmii5kH3WeZQJHtAVrA/2YEV79XquT84Cn9Ujk6BtFu0WQK+lhJ0LSIppVtFB51JICEFNlMX EMZRSUi3sZFCIuHbnM35uuzRx/m1n46Yfpic1yxrawpzTr423xD8fWQtGMeUnqWtz0PJQYh4A/L G7JKYB3YClIZYNMX8M4XotUTs8QiPzIIuLTYxI8YJWDABlPd2S/2GWquE7aZRwplmkT/1aZfYAT jYtPrpMJFvSgEQ8Ln46rWQ4xdgwK0272pORTOee1v0I4aaP3OmMf0nSU/lxt76e9g4YJSHmbbAf ht1iStxiTHwqxQbGLDx/kqA3Cc8vwR6w= X-Received: by 2002:a05:600c:8b2c:b0:47d:3690:7490 with SMTP id 5b1f17b1804b1-47d84b1849emr174581095e9.9.1768112985347; Sat, 10 Jan 2026 22:29:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGe7rEsXMZNMyBjemsPoyMhuDSMeJztwBU0aSiQDzL5RwbDPn81SkbLht2mUJ8G8HVblfB0mQ== X-Received: by 2002:a05:600c:8b2c:b0:47d:3690:7490 with SMTP id 5b1f17b1804b1-47d84b1849emr174580685e9.9.1768112984747; Sat, 10 Jan 2026 22:29:44 -0800 (PST) Received: from redhat.com (IGLD-80-230-35-22.inter.net.il. [80.230.35.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d7f68f69dsm287672195e9.1.2026.01.10.22.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 22:29:44 -0800 (PST) Date: Sun, 11 Jan 2026 01:29:40 -0500 From: "Michael S. Tsirkin" To: Bobby Eshleman Cc: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Stefan Hajnoczi , Jason Wang , Eugenio =?iso-8859-1?Q?P=E9rez?= , Xuan Zhuo , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , Broadcom internal kernel review list , Shuah Khan , Long Li , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kselftest@vger.kernel.org, berrange@redhat.com, Sargun Dhillon , Bobby Eshleman Subject: Re: [PATCH RFC net-next v13 01/13] vsock: add per-net vsock NS mode state Message-ID: <20260111012612-mutt-send-email-mst@kernel.org> References: <20251223-vsock-vmtest-v13-0-9d6db8e7c80b@meta.com> <20251223-vsock-vmtest-v13-1-9d6db8e7c80b@meta.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251223-vsock-vmtest-v13-1-9d6db8e7c80b@meta.com> On Tue, Dec 23, 2025 at 04:28:35PM -0800, Bobby Eshleman wrote: > From: Bobby Eshleman > > Add the per-net vsock NS mode state. This only adds the structure for > holding the mode and some of the functions for setting/getting and > checking the mode, but does not integrate the functionality yet. > > Future patches add the uAPI and transport-specific usage of these > structures and helpers. > > Signed-off-by: Bobby Eshleman I do not much like splitting out functionality like this, myself - there's little to no docs and one can't figure out whether this code does what it is supposed to do without reading the next patch. I would just squash this with that one. If you are splitting functionality along some API lines, you need detailed docs so one can review implementation separately from use. > --- > Changes in v13: > - remove net_mode because net->vsock.mode becomes immutable, no need to > save the mode when vsocks are created. > - add the new helpers for child_ns_mode to support ns_mode inheriting > the mode from child_ns_mode. > - because ns_mode is immutable and child_ns_mode can be changed multiple > times, remove the write-once lock. > - simplify vsock_net_check_mode() to no longer take mode arguments since > the mode can be accessed via the net pointers without fear of the mode > changing. > - add logic in vsock_net_check_mode() to infer VSOCK_NET_MODE_GLOBAL > from NULL namespaces in order to allow only net pointers to be passed > to vsock_net_check_mode(), while still allowing namespace-unaware > transports to force global mode. > > Changes in v10: > - change mode_locked to int (Stefano) > > Changes in v9: > - use xchg(), WRITE_ONCE(), READ_ONCE() for mode and mode_locked (Stefano) > - clarify mode0/mode1 meaning in vsock_net_check_mode() comment > - remove spin lock in net->vsock (not used anymore) > - change mode from u8 to enum vsock_net_mode in vsock_net_write_mode() > > Changes in v7: > - clarify vsock_net_check_mode() comments > - change to `orig_net_mode == VSOCK_NET_MODE_GLOBAL && orig_net_mode == vsk->orig_net_mode` > - remove extraneous explanation of `orig_net_mode` > - rename `written` to `mode_locked` > - rename `vsock_hdr` to `sysctl_hdr` > - change `orig_net_mode` to `net_mode` > - make vsock_net_check_mode() more generic by taking just net pointers > and modes, instead of a vsock_sock ptr, for reuse by transports > (e.g., vhost_vsock) > > Changes in v6: > - add orig_net_mode to store mode at creation time which will be used to > avoid breakage when namespace changes mode during socket/VM lifespan > > Changes in v5: > - use /proc/sys/net/vsock/ns_mode instead of /proc/net/vsock_ns_mode > - change from net->vsock.ns_mode to net->vsock.mode > - change vsock_net_set_mode() to vsock_net_write_mode() > - vsock_net_write_mode() returns bool for write success to avoid > need to use vsock_net_mode_can_set() > - remove vsock_net_mode_can_set() > --- > MAINTAINERS | 1 + > include/net/af_vsock.h | 42 ++++++++++++++++++++++++++++++++++++++++++ > include/net/net_namespace.h | 4 ++++ > include/net/netns/vsock.h | 17 +++++++++++++++++ > 4 files changed, 64 insertions(+) > > diff --git a/MAINTAINERS b/MAINTAINERS > index 454b8ed119e9..38d24e5a957c 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -27516,6 +27516,7 @@ L: netdev@vger.kernel.org > S: Maintained > F: drivers/vhost/vsock.c > F: include/linux/virtio_vsock.h > +F: include/net/netns/vsock.h > F: include/uapi/linux/virtio_vsock.h > F: net/vmw_vsock/virtio_transport.c > F: net/vmw_vsock/virtio_transport_common.c > diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h > index d40e978126e3..6f5bc9dbefa5 100644 > --- a/include/net/af_vsock.h > +++ b/include/net/af_vsock.h > @@ -10,6 +10,7 @@ > > #include > #include > +#include > #include > #include > > @@ -256,4 +257,45 @@ 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) > +{ > + return READ_ONCE(net->vsock.mode); > +} > + > +static inline void vsock_net_set_child_mode(struct net *net, > + enum vsock_net_mode mode) > +{ > + WRITE_ONCE(net->vsock.child_ns_mode, mode); > +} > + > +static inline enum vsock_net_mode vsock_net_child_mode(struct net *net) > +{ > + return READ_ONCE(net->vsock.child_ns_mode); > +} > + > +/* Return true if two namespaces pass the mode rules. Otherwise, return false. > + * > + * A NULL namespace is treated as VSOCK_NET_MODE_GLOBAL. > + * > + * Read more about modes in the comment header of net/vmw_vsock/af_vsock.c. > + */ > +static inline bool vsock_net_check_mode(struct net *ns0, struct net *ns1) > +{ > + enum vsock_net_mode mode0, mode1; > + > + /* Any vsocks within the same network namespace are always reachable, > + * regardless of the mode. > + */ > + if (net_eq(ns0, ns1)) > + return true; > + > + mode0 = ns0 ? vsock_net_mode(ns0) : VSOCK_NET_MODE_GLOBAL; > + mode1 = ns1 ? vsock_net_mode(ns1) : VSOCK_NET_MODE_GLOBAL; > + > + /* Different namespaces are only reachable if they are both > + * global mode. > + */ > + return mode0 == VSOCK_NET_MODE_GLOBAL && mode0 == mode1; > +} > #endif /* __AF_VSOCK_H__ */ > diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h > index cb664f6e3558..66d3de1d935f 100644 > --- a/include/net/net_namespace.h > +++ b/include/net/net_namespace.h > @@ -37,6 +37,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -196,6 +197,9 @@ struct net { > /* Move to a better place when the config guard is removed. */ > struct mutex rtnl_mutex; > #endif > +#if IS_ENABLED(CONFIG_VSOCKETS) > + struct netns_vsock vsock; > +#endif > } __randomize_layout; > > #include > diff --git a/include/net/netns/vsock.h b/include/net/netns/vsock.h > new file mode 100644 > index 000000000000..e2325e2d6ec5 > --- /dev/null > +++ b/include/net/netns/vsock.h > @@ -0,0 +1,17 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef __NET_NET_NAMESPACE_VSOCK_H > +#define __NET_NET_NAMESPACE_VSOCK_H > + > +#include > + > +enum vsock_net_mode { > + VSOCK_NET_MODE_GLOBAL, > + VSOCK_NET_MODE_LOCAL, > +}; > + > +struct netns_vsock { > + struct ctl_table_header *sysctl_hdr; > + enum vsock_net_mode mode; > + enum vsock_net_mode child_ns_mode; > +}; > +#endif /* __NET_NET_NAMESPACE_VSOCK_H */ > > -- > 2.47.3