From patchwork Thu Jan 4 15:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 185049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5686721dyb; Thu, 4 Jan 2024 07:38:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8X/9QUcyZbau/SMCG81dZkORrsHT+7d2OrNXi3NvM5UNbO8Bzp5tngO4o5l/tXkJnrgiH X-Received: by 2002:a17:902:eac2:b0:1d4:462a:60bd with SMTP id p2-20020a170902eac200b001d4462a60bdmr728759pld.55.1704382723077; Thu, 04 Jan 2024 07:38:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704382723; cv=none; d=google.com; s=arc-20160816; b=gnox/dgZ1qe+GLLF114vTxOspAE3bi5Fy3RBueN7/mVMWLnfwXeUuiNEqUD04xsYCK FiRfyEFRmOyjjCWvov5UM3k7+Y2z506CvZ5rqjs2gUzethsReD7PCvdnlwyDvTR96Utc qbkM9HVMkCeMBRM+9HdlKHxu3FepxkpZ8h8U06sIEh1rtiFsCP99Xq9wOOvFhrXi+/RU bbPmnmgh1ZE2rNKNVBAQYA2PfGRqYj8G7mqtTEM2lOae++Ke+iSPNCkY6xCf64ONS7Ju NvZvy4KSV0WdYvrwYYq5L2xrAgoMWhxfc0dYKDVrTodPseofwpaAb4p280I43K0HVJpA AxtQ== 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=Kbn/Pj7lGZv5FQhku3s01YJlXyJKSmX12DB6Cc5Zb3k=; fh=+YAWGNokPfoHg1oXKIXy6skWlEnaUutNlHrvMBZ3/ec=; b=MGz0NqmiGUF60uFH+qnVFt3aGqFlO6sWFhq/4MKbZuy8yPKx4uEvb1OLLYjS1C9RNu 9SSD06xdlqlc56OgKS03ORrw/jndWw7k57wTjVjphwvpwutF8kFeb6SPhiGJRNNTXBlx I/9N1neOuafPNFF7WaonWGWJaMDEGCPeE0O3NBl+UEqn/2LWeweD/w5eEz6s3FN3A8NI 5WaSoXUsOrfX4y+TVniloHOkPeApHDMA/zE6N00OHg4fJc21CDcHtStK+MAY43jnRMhg FCU2kpw5xDgo7ky9Z7+qhRhi2PC9FNJzGtf42McHj8jYpx6VdnUNd/PpNkLyyP3a9D21 WkzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="c28HWN+/"; spf=pass (google.com: domain of linux-kernel+bounces-16861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16861-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b13-20020a170902d88d00b001d48a73f1fdsi12431711plz.163.2024.01.04.07.38.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 07:38:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="c28HWN+/"; spf=pass (google.com: domain of linux-kernel+bounces-16861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16861-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BC0B22876F1 for ; Thu, 4 Jan 2024 15:38:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03D9424B28; Thu, 4 Jan 2024 15:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c28HWN+/" X-Original-To: linux-kernel@vger.kernel.org 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 C035824210 for ; Thu, 4 Jan 2024 15:38:05 +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=1704382684; 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=Kbn/Pj7lGZv5FQhku3s01YJlXyJKSmX12DB6Cc5Zb3k=; b=c28HWN+/SiDoOaWXdUs5Gsbikcb9xbdK1ln+41wEx2KN9J8zpY8LmL8exImeEgJNUCVFq3 X1onSOtsiKFpBiZJ5AZZ4O/q2najv+feJoIeTEqXxmbaWkyISichv1Io5sEXANq1h9bA3i 5sHHqkl0L6RAK4f22b12gnAYZ+3jv9I= 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-127-eYtrm4awOx6FqDMw3CHjEw-1; Thu, 04 Jan 2024 10:38:01 -0500 X-MC-Unique: eYtrm4awOx6FqDMw3CHjEw-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 AD0C628EC10A; Thu, 4 Jan 2024 15:38:00 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AD4BC15E6A; Thu, 4 Jan 2024 15:37:58 +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 1/3] vduse: validate block features only with block devices Date: Thu, 4 Jan 2024 16:37:51 +0100 Message-ID: <20240104153753.2931026-2-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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787174818135519175 X-GMAIL-MSGID: 1787174818135519175 This patch is preliminary work to enable network device type support to VDUSE. As VIRTIO_BLK_F_CONFIG_WCE shares the same value as VIRTIO_NET_F_HOST_TSO4, we need to restrict its check to Virtio-blk device type. Acked-by: Jason Wang Reviewed-by: Xie Yongji Signed-off-by: Maxime Coquelin Reviewed-by: Eugenio Pérez --- drivers/vdpa/vdpa_user/vduse_dev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 0ddd4b8abecb..0486ff672408 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1671,13 +1671,14 @@ static bool device_is_allowed(u32 device_id) return false; } -static bool features_is_valid(u64 features) +static bool features_is_valid(struct vduse_dev_config *config) { - if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) + if (!(config->features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) return false; /* Now we only support read-only configuration space */ - if (features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE)) + if ((config->device_id == VIRTIO_ID_BLOCK) && + (config->features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE))) return false; return true; @@ -1704,7 +1705,7 @@ static bool vduse_validate_config(struct vduse_dev_config *config) if (!device_is_allowed(config->device_id)) return false; - if (!features_is_valid(config->features)) + if (!features_is_valid(config)) return false; return true; From patchwork Thu Jan 4 15:37:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 185050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5687023dyb; Thu, 4 Jan 2024 07:39:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiODITCO3OsXQ1n+/Jb3a/zchjV18zhUBsi5547z0oKopAKpPssabHBB4gGuM8nbA7E7fG X-Received: by 2002:a17:902:ced0:b0:1d4:c4bd:4d11 with SMTP id d16-20020a170902ced000b001d4c4bd4d11mr959951plg.5.1704382752759; Thu, 04 Jan 2024 07:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704382752; cv=none; d=google.com; s=arc-20160816; b=Parwpac4sooWKlBQx7kBBCGwCCWWM+N7657xxqO7q4Z6Qb21Lc5f09Hi2B8pATonZn irQB2k0GGNyxjwBiPNv6d7Qd5nLsH1V/K2x9a+Df4zX1i5XqXHex0BazbuJbxDy/Rh1G ctxvHSyBJe/UZ5YC9eokESsK0ARZ/+Fno0x7mJQj/9W5sfYEjXKGBnjlg/trI+3gosSW BIQsg/TA228x3PAlp58aZD8tib5vbriJmhxrWyGzDTHm6rHTe/WTOVACK0DrRTISBAaW ErC+FS3J7zbSakZu7culm8qgQlj63sMMvhXBHuQaOx+9cQNmSFzbNXK+P1y4tqr+FAkA EBpQ== 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=jY+Y8f7msSBOyPpnVlDqciKOzAOrzUzlYnkERV/e6aE=; fh=+YAWGNokPfoHg1oXKIXy6skWlEnaUutNlHrvMBZ3/ec=; b=kkKONmwhqxWt6DcJM6P9nhizE+LXJb5k5Hm6dizqDyzts5n5IlXLVBpeVaRGq72Qhl DALwNikSZHkaUYdaRKOH88uMl3it9YAqJDyZWdWRenohOGLLj59PkW1/MxQUGZQVG20W xsZTg7QGYp5vMC9Se0Tws79TBlnp2IO3oHP3ZVH6lGfvrIZWF72ES1CJd6FLMnuVyQrI cqY95WU0daL5j8ZgOG3TumfGzLZs2TO29ogs8+E2eaqQ6zG7LKltkx0N3F/YbIe0ttaT jmk2TZbOAAz7eIANaPWIx7ZwKcuT5BNaayhSl2o360dH9MKbZV1V44B9VX9GK84YQlch UqcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jWoGjQtj; spf=pass (google.com: domain of linux-kernel+bounces-16863-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16863-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h1-20020a170902704100b001d3f1b83756si23852792plt.259.2024.01.04.07.39.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 07:39:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16863-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jWoGjQtj; spf=pass (google.com: domain of linux-kernel+bounces-16863-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16863-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7E10D2877AA for ; Thu, 4 Jan 2024 15:39:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04965250F3; Thu, 4 Jan 2024 15:38:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jWoGjQtj" X-Original-To: linux-kernel@vger.kernel.org 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 F1EBD249E9 for ; Thu, 4 Jan 2024 15:38:08 +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=1704382687; 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=jY+Y8f7msSBOyPpnVlDqciKOzAOrzUzlYnkERV/e6aE=; b=jWoGjQtj6j90C2x0XSpAyP5NmROuCOSIFHR9Lmwmy95wME4bOX5Rrp8deSC6b73VS+/cyv hNq8juj2rT/6xb6RvhhhTdZH/w38CvZ0VCoHr5ZmUWL9gbRKOEGVpAq7HdxAy+Ot4vhsPl m5VPgLI6wGLl5YO/eDyHdr0VIGsUQl8= 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-515-0ZYvtpH_MeCHbJRHQRxZqg-1; Thu, 04 Jan 2024 10:38:03 -0500 X-MC-Unique: 0ZYvtpH_MeCHbJRHQRxZqg-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 1302E862F78; Thu, 4 Jan 2024 15:38:03 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06558C15E6A; Thu, 4 Jan 2024 15:38:00 +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 2/3] vduse: Temporarily fail if control queue features requested Date: Thu, 4 Jan 2024 16:37:52 +0100 Message-ID: <20240104153753.2931026-3-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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787174848995801299 X-GMAIL-MSGID: 1787174848995801299 Virtio-net driver control queue implementation is not safe when used with VDUSE. If the VDUSE application does not reply to control queue messages, it currently ends up hanging the kernel thread sending this command. Some work is on-going to make the control queue implementation robust with VDUSE. Until it is completed, let's fail features check if any control-queue related feature is requested. Signed-off-by: Maxime Coquelin Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 0486ff672408..94f54ea2eb06 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "iova_domain.h" @@ -46,6 +47,15 @@ #define IRQ_UNBOUND -1 +#define VDUSE_NET_INVALID_FEATURES_MASK \ + (BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | \ + BIT_ULL(VIRTIO_NET_F_CTRL_RX) | \ + BIT_ULL(VIRTIO_NET_F_CTRL_VLAN) | \ + BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE) | \ + BIT_ULL(VIRTIO_NET_F_MQ) | \ + BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | \ + BIT_ULL(VIRTIO_NET_F_RSS)) + struct vduse_virtqueue { u16 index; u16 num_max; @@ -1680,6 +1690,9 @@ static bool features_is_valid(struct vduse_dev_config *config) if ((config->device_id == VIRTIO_ID_BLOCK) && (config->features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE))) return false; + else if ((config->device_id == VIRTIO_ID_NET) && + (config->features & VDUSE_NET_INVALID_FEATURES_MASK)) + return false; return true; } From patchwork Thu Jan 4 15:37:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 185051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5687111dyb; Thu, 4 Jan 2024 07:39:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHN834RPQRmy06DLNLstqWjXkvTRldpLfDz8sNXi23a1S+QoxAt8eVJcCO0RCjBVuqu8FT7 X-Received: by 2002:a17:906:340e:b0:a27:9148:fd44 with SMTP id c14-20020a170906340e00b00a279148fd44mr234267ejb.279.1704382761572; Thu, 04 Jan 2024 07:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704382761; cv=none; d=google.com; s=arc-20160816; b=Wey2J/jPU/zDAdpwIlVKWk4jtKzwC7lPczo8tDJokCimBZq3rjd5ryH8OyMtYin6P7 JaLPGEMAp8oQMaSWT8mx69rk3N38GUuIHkpUpkXjR7GlBpbcDaudKdNTTaRvrH8T+qhf aC73cdIvFi4gYfXoyESfiDjBfDYpdfDMDr4Sz7UxQGu6SEN5Xd1JPrLBV7UICV6Y7kuz Ekz4mwXZLTPtmBMBLXS/ZQc91DE5h54h5wYppGSJLPLk1e9Y1qlleJLD+0QPoLm//j2M da9geWsSroxPuBtl72vxpKrKWuJirX5QmKKNpbE6AsPt71YIh+wnfFRN9f4mJ6U99t3x UHdA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16864-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fu18-20020a170907b01200b00a27d9aabd67si3881404ejc.844.2024.01.04.07.39.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 07:39:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16864-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16864-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2DEE21F267A9 for ; Thu, 4 Jan 2024 15:39:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A14525115; Thu, 4 Jan 2024 15:38:14 +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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787174858570289972 X-GMAIL-MSGID: 1787174858570289972 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 Acked-by: Jason Wang Reviewed-by: Eugenio Pérez --- 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 }, };