Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp254336rdd; Tue, 9 Jan 2024 03:12:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/SZADiwP3z1mCVJ29mcNEFEVqWJCEjUmF53aGLKj648GtTwGRuUkNKlTQNbFpteV0PO3V X-Received: by 2002:a17:902:6b81:b0:1d4:f1c:6378 with SMTP id p1-20020a1709026b8100b001d40f1c6378mr4971356plk.27.1704798746750; Tue, 09 Jan 2024 03:12:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704798746; cv=none; d=google.com; s=arc-20160816; b=oaRpZd1egWJQ6zVWXQzFxAJ3734lQtsInzEfhHWlwERzElCFIu+WH9/kN/EK2DopQW rsaV4Zv1tvmmV/OfdWI4H9ZKs2LWYRpaZHMGeP52M5O7YhlwqOU9Vb8yvOE1OVCy2T1Y rvrWvi0qGRFIMzvLeUpRYxd8nbLH3rlFGuTF09o6gd4vLbbzvyoRAUsEB12Q1DhZrV5O MExYr3RluIBZMWxeGrPV0DXU+arM+xwIpxd3yUQ/i6t4HKc2A2bYZa2W/cK7U7D7bKrO M1l1cPr0rM9Aef9B1rEFXyMzYlL2p+ZQa2x3fXn02ma7pGgzpH4ZIVDo/3TmBFzZm780 iuuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1DDFZxrU+9MYVeduyTCL7aynBvhEel3T3b/VCxzLnYk=; fh=PsGcTskB5yyh6wdt5mtIwU0t1QS6fyE7OUFROq1ott8=; b=rKLACyLy6xCUoHQ67p3R1z/VFb4C3s94K9TCGAoNjC3MxQxekhfin3rHYIp+l5d6kw ZU/0j/nNJVheNQb57588y7tYMEjcif0SkIBT43PTB85SyfM9MMol1C4D89voj44Sqpgq CH7FLSGu81cEMT7wAsO0ITvm4bmQ6MgFOgZCzWkzmP9TQJz2pGUVdi+qomPXm++jCKaQ a2izrwdjtRWG5GczCUGRn2jsoJa9nU2fBGkMCLg3JbNj+plvGS6dbV6YaIIgO7tpczAN EgaQKENIQHG+iLDaKIZMIShJmw0jdZSDcgWPMGi866UltRbS5mO3DCPor7e6UxOvSowy zZmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RY/zZuDD"; spf=pass (google.com: domain of linux-kernel+bounces-20748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n6-20020a170902e54600b001d4ca3c0f2fsi1326220plf.304.2024.01.09.03.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:12:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RY/zZuDD"; spf=pass (google.com: domain of linux-kernel+bounces-20748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1F3D8B2416D for ; Tue, 9 Jan 2024 11:11:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB5CB381AA; Tue, 9 Jan 2024 11:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RY/zZuDD" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 A625D36AFF for ; Tue, 9 Jan 2024 11:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704798646; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1DDFZxrU+9MYVeduyTCL7aynBvhEel3T3b/VCxzLnYk=; b=RY/zZuDDpEeUjL9xDREeFpOLnPDR90Lk+ASXDMFSSFYqly1RPqyUHcfA+mYCWgXwYAR5Ec Mj8TRiyDn/x0CXOET5mgm4zaNqwgocHMi1SmBmfni816NM8L3u12zkIbyJkRskPE0Lap6X pzO69Y9ORQiWLR0/BLmZCILbWLriN34= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-0VDSwIlePUOcLGfVcmQ_2A-1; Tue, 09 Jan 2024 06:10:37 -0500 X-MC-Unique: 0VDSwIlePUOcLGfVcmQ_2A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E4FD85A58B; Tue, 9 Jan 2024 11:10:37 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B765492BE6; Tue, 9 Jan 2024 11:10:35 +0000 (UTC) From: Maxime Coquelin To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, xieyongji@bytedance.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, david.marchand@redhat.com, lulu@redhat.com Cc: Maxime Coquelin , =?UTF-8?q?Eugenio=20P=C3=A9rez?= Subject: [PATCH v7 3/3] vduse: enable Virtio-net device type Date: Tue, 9 Jan 2024 12:10:25 +0100 Message-ID: <20240109111025.1320976-4-maxime.coquelin@redhat.com> In-Reply-To: <20240109111025.1320976-1-maxime.coquelin@redhat.com> References: <20240109111025.1320976-1-maxime.coquelin@redhat.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=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 This patch adds Virtio-net device type to the supported devices types. Initialization fails if the device does not support VIRTIO_F_VERSION_1 feature, in order to guarantee the configuration space is read-only. It also fails with -EPERM if the CAP_NET_ADMIN is missing. Acked-by: Jason Wang Reviewed-by: Eugenio PĂ©rez Signed-off-by: Maxime Coquelin --- drivers/vdpa/vdpa_user/vduse_dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 00f3f562ab5d..8924bbc55635 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -143,6 +143,7 @@ static struct workqueue_struct *vduse_irq_bound_wq; static u32 allowed_device_id[] = { VIRTIO_ID_BLOCK, + VIRTIO_ID_NET, }; static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa) @@ -1686,6 +1687,10 @@ static bool features_is_valid(struct vduse_dev_config *config) (config->features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))) return false; + if ((config->device_id == VIRTIO_ID_NET) && + !(config->features & BIT_ULL(VIRTIO_F_VERSION_1))) + return false; + return true; } @@ -1793,6 +1798,10 @@ static int vduse_create_dev(struct vduse_dev_config *config, int ret; struct vduse_dev *dev; + ret = -EPERM; + if ((config->device_id == VIRTIO_ID_NET) && !capable(CAP_NET_ADMIN)) + goto err; + ret = -EEXIST; if (vduse_find_dev(config->name)) goto err; @@ -2036,6 +2045,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = { static struct virtio_device_id id_table[] = { { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID }, + { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, { 0 }, }; -- 2.43.0