From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDDE72DAFAC for ; Tue, 2 Dec 2025 22:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764712869; cv=none; b=OVv8Sg5pKkztSF6WGP9PyIjBTfjlB9HB8O48aaAAF4QNt0B+PbzaW32o7HiAXIu0E2TbdsomHgXcKnw4hlF9JmqzZxtET8htqNLtnm+707jaQdmf3y0Pa7iE9ye3YUa89r4XsXADVqy1feQuH0RMGf7b5C0ahJgedv6EebiklDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764712869; c=relaxed/simple; bh=Mqnyzq/dHBpiYdG/Xt/TKvJXJMP8zWCEKc3fUG6Hw0E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M0hiEtSttwnCMn6rzeEBN06xUE+3a3qEtDPKd8ltNWoN2BQBJEoiPtCa8uh9LSiYvRLfD3qV+y94gDj1mCDVrGB0/9HbIfJnA8lETc1dvHivqr5md0XLxfDeqDxdytQSz+uZ3yAlTszbHAO26XK98VOMH8N7BDLLttYFsrEtlCY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nLPdB8Qs; arc=none smtp.client-ip=209.85.128.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nLPdB8Qs" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-78802ac2296so54763857b3.3 for ; Tue, 02 Dec 2025 14:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764712867; x=1765317667; darn=lists.linux.dev; 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=xNqIfgM/6Ycxql9GvTaW4xpHm2HTdtIqMIBvJdvraLU=; b=nLPdB8QsfN1okgJc5ONYbsPaDrsMg9QAl9ynAiL3wxh50EGUKLd6jygFzsAh1RxBo3 6FbLf8djY0jaS9IULs5ID+3spUVIw+kf/nSoYGM3VzWj27VRKRBhQNEGE9Isb3dn2Dzj WLjkD8H/o4HqrUTD4r89+soffPu2ELN489iHpzOlgHI7Vg47l/pPn+IEo5WD8MsmBPdJ DV8B6fJAYGEuOgJLxuq37OnWZ946Wj7GPrQiIp2n33lwbLLTUDJKZfswbX6df7aFZ5mG Icxq/pkikiZfcqAYljn3Ad8B+hS7HjYadMtH6tqFzVvH4I9R4oBQiii0kRnL3mFzWbe6 Q2ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764712867; x=1765317667; 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=xNqIfgM/6Ycxql9GvTaW4xpHm2HTdtIqMIBvJdvraLU=; b=BxG+GTxTfGE1qIjPg+g2DNGbOiztvJ0zUZaIN+z4XBnl4pzAtySKMoDSIPm0tZqI+g rSwxdQ1zxlkIgfdFcPW1//dVawsBVgGRHGEIQOpEvIYjTCj8kJ0R/scOSKpZ5cH8p8bB 2FnkqvRAOIQgGq7jAJZq/iJDgCQMsHNvTF5TgIsO4tAg5SHtB64nvYTjGUN78nplvDCH EHS7tqKx5ea3wX635KutBpJ69WVkWEeKTSrUa7yhvmxwPcXdOHCoroR/Dgzo/NzYGJ2N Qdp/uejME7pOFbyNXebi8F2bZmz9bFpYxnwDjOUWEerCzPCWl/VuCFBVHc28KaKKiJe1 cFgA== X-Forwarded-Encrypted: i=1; AJvYcCUT/KhisoVfP7OJu2/NDUSSUix1JtGXxz+KAqfN7/k6jMgjzVYLHD931Bf6lOfUV1eN0KTYhPV/+Dw9xbAwWg==@lists.linux.dev X-Gm-Message-State: AOJu0Yy9JLLjmMELmyMJrH2LI/H1wdu5XBi1ph6U2oKUJ20Er3sNjWn2 JXl5b/ArqhBKvOguSQC6cQ8xfb9QtXuQnbCueXf2ji+KmJEEqJrcL/9C X-Gm-Gg: ASbGncv/FL7jgYuUAwr9yoIA2bjD9AiSDB+WaZ2gTndeZfmO+7Z45HmOmkoGNbOM0Uh dCsK8BpoPVyNNIMDdYc8H9ZpuDfmNrK0DCQqZBTUaqJ0XZ2L2Njhkx4gu6Pa98UuAP6RNWs7nhm y5mhaNpkFYB1oHt7waviH7UKbJPoZSBl485a9o8RDU6RafLe/gDxPfXwkEEnlFc6Lz7yM1Cpm8d i6lLaWnlwGhwBlRxpBvD3VnqCleVOXicdUdjKIeC1hWQildOB3ceQVTuPf6IwE9s681e5v9ljfZ j1/oG9KMfCM4dPkR+8YDclrSEca1EnRu+rGcr62q8R4qX3wQOm7nRIGgqB3n6c8mA8dwq3GZ7cU yDUPtEGmz09sWkAz3mua0y/rbKKINrF48QHa9SXFeE1/MXTiEFm+4dTS7I9WpTBstvfDNKzWj0V yrLVF2jsalfUDvfKxDmHsj1pVvAEap7VyU/2WbCNVCvFsn1Oo= X-Google-Smtp-Source: AGHT+IFKkR9nJxuAswYbUkRmscuBgN9zjQIp6HaO2rufMd5Ab/1ylKT04Hn5ts4J77BDYWjQzLjRWg== X-Received: by 2002:a05:690c:6206:b0:788:e74:b281 with SMTP id 00721157ae682-78c0beafabamr1238977b3.13.1764712866608; Tue, 02 Dec 2025 14:01:06 -0800 (PST) Received: from devvm11784.nha0.facebook.com ([2a03:2880:25ff:5d::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-78ad0d3f5a1sm67446487b3.12.2025.12.02.14.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 14:01:06 -0800 (PST) Date: Tue, 2 Dec 2025 14:01:04 -0800 From: Bobby Eshleman To: Paolo Abeni Cc: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Simon Horman , Stefan Hajnoczi , "Michael S. Tsirkin" , 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 , 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 net-next v12 04/12] vsock: add netns support to virtio transports Message-ID: References: <20251126-vsock-vmtest-v12-0-257ee21cd5de@meta.com> <20251126-vsock-vmtest-v12-4-257ee21cd5de@meta.com> <6cef5a68-375a-4bb6-84f8-fccc00cf7162@redhat.com> <06b7cfea-d366-44f7-943e-087ead2f25c2@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <06b7cfea-d366-44f7-943e-087ead2f25c2@redhat.com> On Tue, Dec 02, 2025 at 09:47:19PM +0100, Paolo Abeni wrote: > On 12/2/25 6:56 PM, Bobby Eshleman wrote: > > On Tue, Dec 02, 2025 at 11:18:14AM +0100, Paolo Abeni wrote: > >> On 11/27/25 8:47 AM, Bobby Eshleman wrote: > >>> @@ -674,6 +689,17 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file) > >>> goto out; > >>> } > >>> > >>> + net = current->nsproxy->net_ns; > >>> + vsock->net = get_net_track(net, &vsock->ns_tracker, GFP_KERNEL); > >>> + > >>> + /* Store the mode of the namespace at the time of creation. If this > >>> + * namespace later changes from "global" to "local", we want this vsock > >>> + * to continue operating normally and not suddenly break. For that > >>> + * reason, we save the mode here and later use it when performing > >>> + * socket lookups with vsock_net_check_mode() (see vhost_vsock_get()). > >>> + */ > >>> + vsock->net_mode = vsock_net_mode(net); > >> > >> I'm sorry for the very late feedback. I think that at very least the > >> user-space needs a way to query if the given transport is in local or > >> global mode, as AFAICS there is no way to tell that when socket creation > >> races with mode change. > > > > Are you thinking something along the lines of sockopt? > > I'd like to see a way for the user-space to query the socket 'namespace > mode'. > > sockopt could be an option; a possibly better one could be sock_diag. Or > you could do both using dumping the info with a shared helper invoked by > both code paths, alike what TCP is doing. > >> Also I'm a bit uneasy with the model implemented here, as 'local' socket > >> may cross netns boundaris and connect to 'local' socket in other netns > >> (if I read correctly patch 2/12). That in turns AFAICS break the netns > >> isolation. > > > > Local mode sockets are unable to communicate with local mode (and global > > mode too) sockets that are in other namespaces. The key piece of code > > for that is vsock_net_check_mode(), where if either modes is local the > > namespaces must be the same. > > Sorry, I likely misread the large comment in patch 2: > > https://lore.kernel.org/netdev/20251126-vsock-vmtest-v12-2-257ee21cd5de@meta.com/ > > >> Have you considered instead a slightly different model, where the > >> local/global model is set in stone at netns creation time - alike what > >> /proc/sys/net/ipv4/tcp_child_ehash_entries is doing[1] - and > >> inter-netns connectivity is explicitly granted by the admin (I guess > >> you will need new transport operations for that)? > >> > >> /P > >> > >> [1] tcp allows using per-netns established socket lookup tables - as > >> opposed to the default global lookup table (even if match always takes > >> in account the netns obviously). The mentioned sysctl specify such > >> configuration for the children namespaces, if any. > > > > I'll save this discussion if the above doesn't resolve your concerns. > I still have some concern WRT the dynamic mode change after netns > creation. I fear some 'unsolvable' (or very hard to solve) race I can't > see now. A tcp_child_ehash_entries-like model will avoid completely the > issue, but I understand it would be a significant change over the > current status. > > "Luckily" the merge window is on us and we have some time to discuss. Do > you have a specific use-case for the ability to change the netns mode > after creation? > > /P I don't think there is a hard requirement that the mode be change-able after creation. Though I'd love to avoid such a big change... or at least leave unchanged as much of what we've already reviewed as possible. In the scheme of defining the mode at creation and following the tcp_child_ehash_entries-ish model, what I'm imagining is: - /proc/sys/net/vsock/child_ns_mode can be set to "local" or "global" - /proc/sys/net/vsock/child_ns_mode is not immutable, can change any number of times - when a netns is created, the new netns mode is inherited from child_ns_mode, being assigned using something like: net->vsock.ns_mode = get_net_ns_by_pid(current->pid)->child_ns_mode - /proc/sys/net/vsock/ns_mode queries the current mode, returning "local" or "global", returning value of net->vsock.ns_mode - /proc/sys/net/vsock/ns_mode and net->vsock.ns_mode are immutable and reject writes Does that align with what you have in mind? Stefano, what are your thoughts? Best, Bobby