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 6080C1EB1B0 for ; Fri, 21 Mar 2025 19:49:50 +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=1742586592; cv=none; b=ulGkZrSEzCgSuu7JWa/4Qjv4xrw29LCptH1RV1xVu9VVwsb0ehuP8FXfO7+43+Hx3sgYR1KuYKVWw/yb2V3ykZNpa/9CRM54h6ruryW5CIJwhFl1oC5nMVElx7a4Jz9k79ymqVoHdNiVVFxb1sQoVIieMyCUI6uzf67Db+j4jd0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742586592; c=relaxed/simple; bh=UFdqBVJRDVk8Hlcf3jTu50jsbpG+mU166GYiFitWazE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: In-Reply-To:Content-Type:Content-Disposition; b=FAr6iyfTPCwuZSpN2QSTZDhaRa//33DwkHUQLuMCCzdcgnoEvxHxGFIMDwAf2SDjtjye9p1R8I4c6fBvxMhJxQ2GKeL0XaKHqrSFk4KUGMtJ3HWWn5QqzbpesGrLT3hwpXgCt/EtIUzVPT0OPphoSk+yRipoqNgZP2aQVu6e+KI= 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=O4BoVJ00; 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="O4BoVJ00" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742586589; 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=ReERJAqHieSO06A2On5uvAOfqLYlr/FeJgCmLUNx8kQ=; b=O4BoVJ00Fs+0i/3ynJVBoLhMsI11msoBxLm3IbfwjsUTnZtjkOXXutG0ymCJlEFaNRlPcp Vv/8FqDoFUOeW+MH90yfyXsnPgwPSt6PixYC38JSNMhq8Dxdfp3IIXTgP2i7kOWlYk1Pic yBXOQYJVM+uTM2NrE1heehvz8Txp2zM= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-jlm-VCVyOh6ennW8usn9eQ-1; Fri, 21 Mar 2025 15:49:48 -0400 X-MC-Unique: jlm-VCVyOh6ennW8usn9eQ-1 X-Mimecast-MFC-AGG-ID: jlm-VCVyOh6ennW8usn9eQ_1742586587 Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2ff6aaa18e8so3554237a91.1 for ; Fri, 21 Mar 2025 12:49:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742586587; x=1743191387; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ReERJAqHieSO06A2On5uvAOfqLYlr/FeJgCmLUNx8kQ=; b=ilBs7h9dTSXlRaqnKX+VmBwQY5qDxXS5pxXRJk3AL48r6xs8JumxRjpbnedqgLPiZz obYWjJ/Y4Nh2Ark8Q/fKCewCJi6rPOnkiY+gGBrhCR5XUEissIrrizgC3Oh4PyJIp8Mc 0k4nEBChMAPoo1Pujie/YYuTJCuiZI4nGRvhYPN51owm3UgU6Dt72F2aiL/4XWqx7+B2 vCVqEqg3/p2rjuPxOrLwiGkOJ4CYzeJ6jY8+xQ5mQBZBlPrkyw4L+8IPRaIeY6FWjG9o wihmRypgo5hocrFeJv4zzuNF/BBuiQYRJWuYnWoGCtzB8eiYft81Bx1wAoYAfv6IaQAJ 53jg== X-Forwarded-Encrypted: i=1; AJvYcCWnGPxfI0sjsKjokVh4zjUDoKL+YYowmIaplpv86hW8liiMNzOqesc1Ds5DTRzBCnvbGy46Ltjc2P3X9/j24A==@lists.linux.dev X-Gm-Message-State: AOJu0Yy6KLf/Mhdh+L3OvHE86FNuoM0creu2CRYANApOlhUDmgJgJ1+v 5nepTXhHfL3WfNXmN7dz+HyaVj1JGOptaoxVD1ck4HmWd5WHguc+J4wIs8zTKxXNJdXKQP979cO m4gdjQ3DtbJZvtsv/HY3MfJPePOSlr+2nQ3VXnRu5GxlG1ry0nrYvYdZexy4abW3j X-Gm-Gg: ASbGncsGCU8pfYwm7Cj2KCXIR1bb34bhxnr6+id80SmaNe9qY/Ztqnul+R47hYgT4kt cQSrBiXn43n4HZM0MEX5J3gFGJykIttKnstb8476Qe8QdkYaNz+4rjx4kKeT3hUspCaooeBh03N aP/EVYCZbL3KZC/WwhRWgF+yv3Fh4/1LFPAhkeAdmbZGoKA625a1upbLQpga82BZJByaIFogOmg 7BiVCcVXJKVXJEauLEb9G9lttWYD673HDmSTktS9SdEP99l0CCb+9utIY655GWKCAIsQcp77+35 Q6MJqH9L X-Received: by 2002:a05:6a21:6182:b0:1f5:55b7:1bb4 with SMTP id adf61e73a8af0-1fe42f2ca16mr8343016637.11.1742586586909; Fri, 21 Mar 2025 12:49:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgaPER9WdLR23YdQNltOTaAZ+YfxNnRQHaimB6OsbRkGfsA5VnV3pJYV1//O3S4oQcK/34rw== X-Received: by 2002:a05:6a21:6182:b0:1f5:55b7:1bb4 with SMTP id adf61e73a8af0-1fe42f2ca16mr8342982637.11.1742586586558; Fri, 21 Mar 2025 12:49:46 -0700 (PDT) Received: from redhat.com ([195.133.138.172]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af8a2841c02sm1900123a12.39.2025.03.21.12.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Mar 2025 12:49:46 -0700 (PDT) Date: Fri, 21 Mar 2025 15:49:38 -0400 From: "Michael S. Tsirkin" To: Bobby Eshleman Cc: Stefano Garzarella , Jakub Kicinski , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Stefan Hajnoczi , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Bryan Tan , Vishnu Dasa , Broadcom internal kernel review list , "David S. Miller" , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v2 0/3] vsock: add namespace support to vhost-vsock Message-ID: <20250321154922-mutt-send-email-mst@kernel.org> References: <20250312-vsock-netns-v2-0-84bffa1aa97a@gmail.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20250312-vsock-netns-v2-0-84bffa1aa97a@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: _xZa5w5isaYusfyY76seR6EvCxCVlbgXBXneTLnlBmQ_1742586587 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Mar 12, 2025 at 01:59:34PM -0700, Bobby Eshleman wrote: > Picking up Stefano's v1 [1], this series adds netns support to > vhost-vsock. Unlike v1, this series does not address guest-to-host (g2h) > namespaces, defering that for future implementation and discussion. > > Any vsock created with /dev/vhost-vsock is a global vsock, accessible > from any namespace. Any vsock created with /dev/vhost-vsock-netns is a > "scoped" vsock, accessible only to sockets in its namespace. If a global > vsock or scoped vsock share the same CID, the scoped vsock takes > precedence. > > If a socket in a namespace connects with a global vsock, the CID becomes > unavailable to any VMM in that namespace when creating new vsocks. If > disconnected, the CID becomes available again. yea that's a sane way to do it. Thanks! > Testing > > QEMU with /dev/vhost-vsock-netns support: > https://github.com/beshleman/qemu/tree/vsock-netns > > Test: Scoped vsocks isolated by namespace > > host# ip netns add ns1 > host# ip netns add ns2 > host# ip netns exec ns1 \ > qemu-system-x86_64 \ > -m 8G -smp 4 -cpu host -enable-kvm \ > -serial mon:stdio \ > -drive if=virtio,file=${IMAGE1} \ > -device vhost-vsock-pci,netns=on,guest-cid=15 > host# ip netns exec ns2 \ > qemu-system-x86_64 \ > -m 8G -smp 4 -cpu host -enable-kvm \ > -serial mon:stdio \ > -drive if=virtio,file=${IMAGE2} \ > -device vhost-vsock-pci,netns=on,guest-cid=15 > > host# socat - VSOCK-CONNECT:15:1234 > 2025/03/10 17:09:40 socat[255741] E connect(5, AF=40 cid:15 port:1234, 16): No such device > > host# echo foobar1 | sudo ip netns exec ns1 socat - VSOCK-CONNECT:15:1234 > host# echo foobar2 | sudo ip netns exec ns2 socat - VSOCK-CONNECT:15:1234 > > vm1# socat - VSOCK-LISTEN:1234 > foobar1 > vm2# socat - VSOCK-LISTEN:1234 > foobar2 > > Test: Global vsocks accessible to any namespace > > host# qemu-system-x86_64 \ > -m 8G -smp 4 -cpu host -enable-kvm \ > -serial mon:stdio \ > -drive if=virtio,file=${IMAGE2} \ > -device vhost-vsock-pci,guest-cid=15,netns=off > > host# echo foobar | sudo ip netns exec ns1 socat - VSOCK-CONNECT:15:1234 > > vm# socat - VSOCK-LISTEN:1234 > foobar > > Test: Connecting to global vsock makes CID unavailble to namespace > > host# qemu-system-x86_64 \ > -m 8G -smp 4 -cpu host -enable-kvm \ > -serial mon:stdio \ > -drive if=virtio,file=${IMAGE2} \ > -device vhost-vsock-pci,guest-cid=15,netns=off > > vm# socat - VSOCK-LISTEN:1234 > > host# sudo ip netns exec ns1 socat - VSOCK-CONNECT:15:1234 > host# ip netns exec ns1 \ > qemu-system-x86_64 \ > -m 8G -smp 4 -cpu host -enable-kvm \ > -serial mon:stdio \ > -drive if=virtio,file=${IMAGE1} \ > -device vhost-vsock-pci,netns=on,guest-cid=15 > > qemu-system-x86_64: -device vhost-vsock-pci,netns=on,guest-cid=15: vhost-vsock: unable to set guest cid: Address already in use > > Signed-off-by: Bobby Eshleman > --- > Changes in v2: > - only support vhost-vsock namespaces > - all g2h namespaces retain old behavior, only common API changes > impacted by vhost-vsock changes > - add /dev/vhost-vsock-netns for "opt-in" > - leave /dev/vhost-vsock to old behavior > - removed netns module param > - Link to v1: https://lore.kernel.org/r/20200116172428.311437-1-sgarzare@redhat.com > > Changes in v1: > - added 'netns' module param to vsock.ko to enable the > network namespace support (disabled by default) > - added 'vsock_net_eq()' to check the "net" assigned to a socket > only when 'netns' support is enabled > - Link to RFC: https://patchwork.ozlabs.org/cover/1202235/ > > --- > Stefano Garzarella (3): > vsock: add network namespace support > vsock/virtio_transport_common: handle netns of received packets > vhost/vsock: use netns of process that opens the vhost-vsock-netns device > > drivers/vhost/vsock.c | 96 +++++++++++++++++++++++++++------ > include/linux/miscdevice.h | 1 + > include/linux/virtio_vsock.h | 2 + > include/net/af_vsock.h | 10 ++-- > net/vmw_vsock/af_vsock.c | 85 +++++++++++++++++++++++------ > net/vmw_vsock/hyperv_transport.c | 2 +- > net/vmw_vsock/virtio_transport.c | 5 +- > net/vmw_vsock/virtio_transport_common.c | 14 ++++- > net/vmw_vsock/vmci_transport.c | 4 +- > net/vmw_vsock/vsock_loopback.c | 4 +- > 10 files changed, 180 insertions(+), 43 deletions(-) > --- > base-commit: 0ea09cbf8350b70ad44d67a1dcb379008a356034 > change-id: 20250312-vsock-netns-45da9424f726 > > Best regards, > -- > Bobby Eshleman