From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 E273C22A4EB for ; Fri, 7 Nov 2025 03:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762484830; cv=none; b=Z9EZSXDO5X9wOOq+gynsfmead90Tymz2Uij4LHdcmyyyP9kLJJGTs8MoNP+ZJty2XgyUFSb1OhdIRcLKqBR1gRFw7hBSdJKOYjF5bOPCDbva/BGxpha0VvFg88xp7+XZkXTlVoOww/VnW3PZY7cVQw+rLcQovrXZsvpw1ewb6Ac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762484830; c=relaxed/simple; bh=808AlwEZ1o2mA4OcdatRSl+Gb85ZdMLrOwB3CyxK1Ks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AOctxRfc2oeYR1mg1Lp4WnTa2LwfbUCy/aI1+5cDBKG1UbB7ly7Dzb6PBdZ3BWNNvOtK3KGMJ226KFvVncIfMftKnqkWwvW/vmzcrI+5Z5Id0uZgNiPBYA8aU9igS4qfx+anafkPr8edsISiCTQm6Bw2yeJUhTBmgXCcfep//jM= 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=a06yzr2B; arc=none smtp.client-ip=209.85.128.175 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="a06yzr2B" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-7864cef1976so4062597b3.0 for ; Thu, 06 Nov 2025 19:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762484826; x=1763089626; 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=hR77XGy8gKTpCV+3sSlL3axBPG4R/F86P0C6FJqRU38=; b=a06yzr2BZTwGYHArjHp9LGVTPlbRMRUAT0X+aLCvbKOYdB/uHjGpJNkdYmuLtITb8N FN/4qcMRd8g3E0Cs814vxGEKkfOFXXVLZhvXoFyNeUxGPUbz2GZHTy2xkaT/9CD5D4e7 8/MWLBX+fZwSGrhWWSvT1J23CHiyEZYReXa+0mIjDVW4WYM5KDiIlGPJNoN02W36v3G9 dN853tmWvBjgeJG4CvSoIUs44A2era9m5KjEk6IP5J+6HXoXDcRMgJBEuuEjgB4M9W+H RKmFPZBewnny9dfsbO+hGTOeCYZsUIzcCGgK1MdVuJOviDttthrRQ3IXzv2qg679brxf rUHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762484826; x=1763089626; 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=hR77XGy8gKTpCV+3sSlL3axBPG4R/F86P0C6FJqRU38=; b=KS/27/miLJ2Vg4y+BoPg1birV7X972wBWB400vcn3s0H1vAkEaOsXsqkQh27G1dDZU ig7X0p4La9ydl5jnsqBYIFzge16cSYLqNEj8OAQXOivIjuOx2ZbNYIxFsXrgv8+sVDGj 6RNALfZLasnKa7NUq4FtEUlIn2L5xdPWWqJ4t+RVCnkAICA8C1NqVSgs5ZZ/WdGGx5Y0 NQEyeZemzSlrk5w99yEwydF5JhThOToKrr19mpaLa7CCFaJw6gPMJlTBivatfHVLNv3x oUPCZ1D/Jc2/aAK27lNo0AZcUOXEfz6VTE+ZKki4Csc6Qe/Nx8K9w+p0QprRMnONVhDy ucBQ== X-Forwarded-Encrypted: i=1; AJvYcCVUm0JPPOpio6GBNfqHzK8zoYZM7QrDlOdCZWtfxC61siNIQ6xwqx5EyW3zCvhnKoBT5v8jTgJsd0ivSE0=@vger.kernel.org X-Gm-Message-State: AOJu0YyPG7Ry9IxZRerxYNpkJuw90e16uEYg0cBqkyRZtecJO2+7hPJu MzguSbxn/V2naaRggLu5zr1/zeqJ/u+VoOciR3/HHR3IzgwF0TciJfv7 X-Gm-Gg: ASbGncvDOf1sst53ss24gA/fLhu7CKU1+bKW959672Mw/9L7WbJW5+wkkqXqMcFHQXm zp0UaFHSpkYN6qWo+qYRcPegv0QtH5SuJkX8QJJulHDSG3oj1FGFFnbeT+diqDzKvCVzJWqOlqa ARAVXzSHM14adk82ogGQKQzimCoI3SUocyNkLFZRfIqFXvepANmnTIyWuqamHtxcXD59Sg3lnbh rls1dWrwGBN696uqisdEk+3x8eLSUCdO887zSB5QJt5pBtwebEXFFQUYXplQAy7YIe7Ue7QKAv8 7TFhZQEkSUW61X+BinUSZ2o9vZwMKrjg6kA4U9eE1XS7nTHik6vbJWDbUAZhE/XiyLlYr8etCJX NKAWfabZrZQdAlpx1lVajmUXVP73O7uJWECYw+Eiwvyy4YW+3ecizbRnlvhHy1x9ZYaP1MUdWY5 JsvPpIwabMlcZeqRCDn8SQ61SIOE/aUy/5rsvq X-Google-Smtp-Source: AGHT+IFB590VLlupKmRJu3Xg8gkOtJWd0diOwJuCAD9JFt31fECUBp8uUIrK8y6sj/IrmT+p0bOb1A== X-Received: by 2002:a05:690c:d84:b0:783:7768:55e6 with SMTP id 00721157ae682-787caaeead8mr1823477b3.13.1762484826556; Thu, 06 Nov 2025 19:07:06 -0800 (PST) Received: from devvm11784.nha0.facebook.com ([2a03:2880:25ff:5b::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-787c68c4025sm2798627b3.26.2025.11.06.19.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 19:07:06 -0800 (PST) Date: Thu, 6 Nov 2025 19:07:04 -0800 From: Bobby Eshleman To: Stefano Garzarella Cc: Shuah Khan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , Broadcom internal kernel review list , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, berrange@redhat.com, Bobby Eshleman Subject: Re: [PATCH net-next v8 07/14] vhost/vsock: add netns support Message-ID: References: <20251023-vsock-vmtest-v8-0-dea984d02bb0@meta.com> <20251023-vsock-vmtest-v8-7-dea984d02bb0@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: On Thu, Nov 06, 2025 at 05:21:35PM +0100, Stefano Garzarella wrote: > On Thu, Oct 23, 2025 at 11:27:46AM -0700, Bobby Eshleman wrote: > > From: Bobby Eshleman > > > > Add the ability to isolate vhost-vsock flows using namespaces. > > > > The VM, via the vhost_vsock struct, inherits its namespace from the > > process that opens the vhost-vsock device. vhost_vsock lookup functions > > are modified to take into account the mode (e.g., if CIDs are matching > > but modes don't align, then return NULL). > > > > vhost_vsock now acquires a reference to the namespace. > > > > Signed-off-by: Bobby Eshleman > > --- > > Changes in v7: > > - remove the check_global flag of vhost_vsock_get(), that logic was both > > wrong and not necessary, reuse vsock_net_check_mode() instead > > - remove 'delete me' comment > > Changes in v5: > > - respect pid namespaces when assigning namespace to vhost_vsock > > --- > > drivers/vhost/vsock.c | 44 ++++++++++++++++++++++++++++++++++---------- > > 1 file changed, 34 insertions(+), 10 deletions(-) [...] > > static int vhost_vsock_dev_open(struct inode *inode, struct file *file) > > { > > + > > struct vhost_virtqueue **vqs; > > struct vhost_vsock *vsock; > > + struct net *net; > > int ret; > > > > /* This struct is large and allocation could fail, fall back to vmalloc > > @@ -669,6 +684,14 @@ 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); > > + > > + /* Cache the mode of the namespace so that if that netns mode changes, > > + * the vhost_vsock will continue to function as expected. > > + */ > > I think we should document this in the commit description and in both we > should add also the reason. (IIRC, it was to simplify everything and prevent > a VM from changing modes when running and then tracking all its packets) > Sounds good! > > + vsock->net_mode = vsock_net_mode(net); > > + > > vsock->guest_cid = 0; /* no CID assigned yet */ > > vsock->seqpacket_allow = false; > > > > @@ -708,7 +731,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk) > > */ > > > > /* If the peer is still valid, no need to reset connection */ > > - if (vhost_vsock_get(vsk->remote_addr.svm_cid)) > > + if (vhost_vsock_get(vsk->remote_addr.svm_cid, sock_net(sk), vsk->net_mode)) > > return; > > > > /* If the close timeout is pending, let it expire. This avoids races > > @@ -753,6 +776,7 @@ static int vhost_vsock_dev_release(struct inode *inode, struct file *file) > > virtio_vsock_skb_queue_purge(&vsock->send_pkt_queue); > > > > vhost_dev_cleanup(&vsock->dev); > > + put_net_track(vsock->net, &vsock->ns_tracker); > > Doing this after virtio_vsock_skb_queue_purge() should ensure that all skbs > have been drained, so there should be no one flying with this netns. Perhaps > this clarifies my doubts about the skb net, but should we do something > similar for loopback as well? 100% - for loopback the skb purge is done in the net exit hook, which is called just before netns destruction. Maybe it is worth commenting that context there too. > And maybe we should document that also in the virtio_vsock_skb_cb. > sgtm! Best, Bobby