Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7784883rdb; Thu, 4 Jan 2024 07:39:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTMUCQAlIJkzcuZ48i2BwE1UTCfOhyPFHzCIPiRZOgraGxPNfngE1kYrVUB67zAYH6tQN3 X-Received: by 2002:a05:6214:2468:b0:67f:aafc:d54b with SMTP id im8-20020a056214246800b0067faafcd54bmr980209qvb.122.1704382747840; Thu, 04 Jan 2024 07:39:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704382747; cv=none; d=google.com; s=arc-20160816; b=CjTadNK//uohWpljF9l/w3psw07JSCpA642HxZu+Lr1bGQgXyJLGuAOG8a92pcYjFu 3WGwbSB98Qbh+p9T58EVFQir6nDQJiHA9ULPUXAYeMd++MVaaq6eiZkf7Y62Z14IlpRX rYOnqNtNGoG6ftHjL5EFlKAyTTmnw8WVLgDdUfAWBPVryOFISomGJhxbhh4iH8ZTJII6 SOFdEin2R21nQrsreAGbwO26aZrKvr09GxDLVL4DI2mUEZsX4+Xr9D7vjtR8+WVypVzT Tnn2eSXSHCCg8wDCOuKi550qNwFowdmXjIEaoyiKyK1CX7/jhyXKX8p8yoRulGdUnas1 lKAw== 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=UPM6vc4WNmoCS+D/6DliXw39ErXumh08Y6Auv1yi7Xw=; fh=+YAWGNokPfoHg1oXKIXy6skWlEnaUutNlHrvMBZ3/ec=; b=WivI7hT+cEOBySHP7c1yNAuotScVj8t7wBDCmdLz3/RPHhl4I2KM/GhLgJjmaT2tR1 5pklIdQ+r3GLmztk9EfoEwpupZXlLYjczL8rJFnG2LWYTCgC4ZzDdQ4FatKloUK54cQZ jAzVxIdEVU9ePvsLbgqE5Swioc3oXcmNPTWxFWZXgEnUD9PcwshL/lQ7rxPsVtIFr6PY 9ST98UjmlyDlRiH8R68pmYQo2cQO+kvVmA0D1n04Ac+PmNUpwgac5K0yhO45t/pPIfwn BaIaLaCOYHZskcaB16Fb2d1fSp2nLGJUTuqS6RTxj5L4DIw89ewXvKfVTfVeP1YKXqIH R5VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RWqyI4kA; spf=pass (google.com: domain of linux-kernel+bounces-16864-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c13-20020a0ca9cd000000b0067f94720d1bsi18766404qvb.235.2024.01.04.07.39.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 07:39:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16864-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RWqyI4kA; spf=pass (google.com: domain of linux-kernel+bounces-16864-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16864-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 963661C222EF for ; Thu, 4 Jan 2024 15:39:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 587BE250E7; Thu, 4 Jan 2024 15:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RWqyI4kA" X-Original-To: linux-kernel@vger.kernel.org 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 2863E24B2C for ; Thu, 4 Jan 2024 15:38:09 +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=1704382689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UPM6vc4WNmoCS+D/6DliXw39ErXumh08Y6Auv1yi7Xw=; b=RWqyI4kAt2rS6gqHGKlUCTtGy3ypuNjz5zNitaN7/4gA/xq5zOeYdRFFVDPjKi71xVblTR xiJt0bzBKJuFZBSEnAlncgJmK8RkGOgDauWL8pyXzCYUfrpIxttH72YwUoK+UBwgVDK2j3 3T4jHJ4e/7z3HjpdvFolMqd0mFNZV9w= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-k-i8HbLzOcWdZy7sgA89mg-1; Thu, 04 Jan 2024 10:38:06 -0500 X-MC-Unique: k-i8HbLzOcWdZy7sgA89mg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 8EA0D3C2AF6D; Thu, 4 Jan 2024 15:38:05 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 938ABC15E6A; Thu, 4 Jan 2024 15:38:03 +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 Subject: [PATCH v6 3/3] vduse: enable Virtio-net device type Date: Thu, 4 Jan 2024 16:37:53 +0100 Message-ID: <20240104153753.2931026-4-maxime.coquelin@redhat.com> In-Reply-To: <20240104153753.2931026-1-maxime.coquelin@redhat.com> References: <20240104153753.2931026-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-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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. 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 94f54ea2eb06..4057b34ff995 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -151,6 +151,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) @@ -1694,6 +1695,10 @@ static bool features_is_valid(struct vduse_dev_config *config) (config->features & VDUSE_NET_INVALID_FEATURES_MASK)) return false; + if ((config->device_id == VIRTIO_ID_NET) && + !(config->features & (1ULL << VIRTIO_F_VERSION_1))) + return false; + return true; } @@ -1801,6 +1806,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; @@ -2044,6 +2053,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