From patchwork Tue Jan 9 11:10:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 186320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp35749dyi; Tue, 9 Jan 2024 03:11:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYsyCA0z9YBiqyP4iXVJqJeEzhtCA1jajjD4q7fkXKz5qnGBmxZAeei2O48mcKFSiZibi9 X-Received: by 2002:a05:6a20:9483:b0:199:6496:290f with SMTP id hs3-20020a056a20948300b001996496290fmr5014599pzb.73.1704798700626; Tue, 09 Jan 2024 03:11:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704798700; cv=none; d=google.com; s=arc-20160816; b=fH5mIZ+SYMC5HjAN47iS0Tl2lN5XwFnroIitVo04L9qGhLOKrbJrO7WU5JuW23EJ3G VpqX39ljsFFM9L9KRcmLK7L9h01fO346lA6KZHHYvRSGjwer9HUsHnbOfmhiZAhs//ug o7iCHAN5AcrWhnpfSL+ObF9JyDfu77NwnG/BDqlJrVKBJP5m9OnmJ+zOiu5oukX7180C j+1EZPCvqFlUbiZ+u+Iu2OEsEtX+uiXsBFBoHfqtSsVrFkqCwkeLt3fzwIHLtpLEpo0J 5iOVaypT3S/J3hD0NTX6xABriTccfWZ1ww1Vfk8nQYbi0F29+Qdml3obIgI/HRGnUjy1 T2og== 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=BtHMmViNUHkBlyTq+yA+WPFdZXCFstzRWGlzClhIP3k=; fh=PsGcTskB5yyh6wdt5mtIwU0t1QS6fyE7OUFROq1ott8=; b=K8K0t5/QyTh9BfEOZjk/0KHjSg3yoQLr73ukizk6D/b1v0YgonZ5QFGxA1Wa6RWtGR qx91n5tBcuWoOL/oc/3ywmAyX+bW/OyTtd9Y/lJocaA9sj8A4sXhYwikLMNKt3hMWebM 9mYJaETB46GH+h0vDlBj+qKZjuy+HKRUz02fY/StApXKmA94nctokAtX9/vMa+y8Aa+n EGHhzH3aJva07bOiCSFU0DAWZAYpJDiaruqQML5fZ99G3rkNRzBYl/sWx0NyM2EpKfAl dTCgL2nf6utYkPfuXNYXDYqWuGRj3CKUETt/Nt7umV67nDaoCgwMWEy2vwTslETcpFea rIpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PQQ+FcLb; spf=pass (google.com: domain of linux-kernel+bounces-20746-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20746-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l27-20020a635b5b000000b005ce0b70d2b0si1256763pgm.102.2024.01.09.03.11.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:11:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20746-ouuuleilei=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=PQQ+FcLb; spf=pass (google.com: domain of linux-kernel+bounces-20746-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20746-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B4F0BB232A2 for ; Tue, 9 Jan 2024 11:11:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC0363717D; Tue, 9 Jan 2024 11:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PQQ+FcLb" 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 AB4EA36B09 for ; Tue, 9 Jan 2024 11:10:37 +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=1704798636; 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=BtHMmViNUHkBlyTq+yA+WPFdZXCFstzRWGlzClhIP3k=; b=PQQ+FcLbHwkJG6CNAgPZ5klHmYh9NWAsoMhD0iY+kxTvzgz31sLMMANCnGJ5MALLydrU9X fAkllvPTa0pEFNigmdBH0y0L+pSNLbM5ciWLlU3mEGDLbgDA8+S+3e/mtVF1ev5Nakzr6r 1xjYFB8SJtHoQUAUTSXbOeOV0TojwzA= 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-417-wdiVT_Z_ML2xKOwrFtk9Cw-1; Tue, 09 Jan 2024 06:10:33 -0500 X-MC-Unique: wdiVT_Z_ML2xKOwrFtk9Cw-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 1AE47106CFF5; Tue, 9 Jan 2024 11:10:33 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 194B4492BE6; Tue, 9 Jan 2024 11:10:30 +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_P=C3=A9r?= =?utf-8?q?ez?= Subject: [PATCH v7 1/3] vduse: validate block features only with block devices Date: Tue, 9 Jan 2024 12:10:23 +0100 Message-ID: <20240109111025.1320976-2-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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787611001768768264 X-GMAIL-MSGID: 1787611001768768264 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 Reviewed-by: Eugenio Pérez Signed-off-by: Maxime Coquelin --- 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..a5af6d4077b8 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 & BIT_ULL(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 & BIT_ULL(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 Tue Jan 9 11:10:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 186319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp35616dyi; Tue, 9 Jan 2024 03:11:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdwdFuPY1s1mnMizWhvd3f9RlUGFTTVXjKb0A8yJrOMRQFKsS4ORAWe523+VGj5hrxpk16 X-Received: by 2002:a05:6a20:8e01:b0:199:e6d0:646f with SMTP id y1-20020a056a208e0100b00199e6d0646fmr965272pzj.62.1704798685010; Tue, 09 Jan 2024 03:11:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704798684; cv=none; d=google.com; s=arc-20160816; b=QZ13jFpR6VFwB5RI8aox0Z2Vw6cMB1UOfWZUTAalpD3RLeCeQgq/wF4xZvE2erhi7a xWwt4WHIgb9UVy073HnAA0mVUTJKUkFNqzIuvDpxRCBs8MRGzRvn0uwSaL3phkuRtqzW LYwpVsuAg7JJsNk8Dl16BZrTJslzgS/5H9InkYEuOTcNEnxyeeF7srFPgjxfe7+C1ig6 SNuwwmXnjQbPBc2WDn5s3kaJ2qqDHBCMAJGsixFSHlS/HdsuwvhAfgITBU7usY+lJhc1 XG/X1tJbGytQmBynv+ifqrGA3MF1qB7ZC3D9GP/A6d3oH+NhNwWtiAro2Uz/Mz9aFPoN nWKg== 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=yiFLDt6JZCuOrzbfaqayxRzUmPMlKKOFGuVamAlGo7c=; fh=+YAWGNokPfoHg1oXKIXy6skWlEnaUutNlHrvMBZ3/ec=; b=rhfKc7sI2wI6xQS5TWEdeLRYI/k2oTnnomEHvDCAWogY9jC0C2RoX0L5bJtpniO6W+ SwzLYTCJHyjZ5Vckvb7TXbYioGoBmvh1ClzXOifUbZIE3MHRZeIxqnOwTD4bayNRZ3Du fUy3tckstmKNr3P6XYM/22OvMeJgq5SIoAerfMDoxvyyhohD48IMYuC1FD+rokxy8C64 F2OIHjLw5/00zI9zOF/d87sybvoj17O34UcF2Kd8t9I5C9fS8LiLE29NT1AaDEu6s5dx GVOfcBWDSN1NRwQe72YnkjBCNLXi6YRK8EGPdq96B7uV63bZ4lYQGN81DlvyZ2iSUHJm VEkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MRUW+bGn; spf=pass (google.com: domain of linux-kernel+bounces-20747-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20747-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 mp16-20020a17090b191000b0028c00f24794si6833227pjb.178.2024.01.09.03.11.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:11:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20747-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=MRUW+bGn; spf=pass (google.com: domain of linux-kernel+bounces-20747-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20747-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 C6024285D13 for ; Tue, 9 Jan 2024 11:11:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BDCA36AFB; Tue, 9 Jan 2024 11:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MRUW+bGn" 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 2F92437160 for ; Tue, 9 Jan 2024 11:10:39 +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=1704798639; 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=yiFLDt6JZCuOrzbfaqayxRzUmPMlKKOFGuVamAlGo7c=; b=MRUW+bGnCTU+Nz9DCiy2x5O7SOcxxQWgOUvtOOG72R6J78bZOTWg4KPxzJkb1Hp1PMcZ5b JlsXgWcJvKBOjgFjZVbSuhKdTFo38LdepoIuBF5nLr2lTmEH89BU8V9qsModwNg9/YtUf9 j1OtnSsRcryeinPdJwzW6q8DB8MsRM0= 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-384-5SSujEQiMWe-y5D1a8AYHQ-1; Tue, 09 Jan 2024 06:10:35 -0500 X-MC-Unique: 5SSujEQiMWe-y5D1a8AYHQ-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 3EEAF3806735; Tue, 9 Jan 2024 11:10:35 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66ECE492BE6; Tue, 9 Jan 2024 11:10:33 +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 v7 2/3] vduse: Temporarily fail if control queue feature requested Date: Tue, 9 Jan 2024 12:10:24 +0100 Message-ID: <20240109111025.1320976-3-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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787610986036727924 X-GMAIL-MSGID: 1787610986036727924 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 control-queue feature is requested. Signed-off-by: Maxime Coquelin Acked-by: Eugenio Pérez Reviewed-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index a5af6d4077b8..00f3f562ab5d 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -8,6 +8,7 @@ * */ +#include "linux/virtio_net.h" #include #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #include #include "iova_domain.h" @@ -1680,6 +1682,9 @@ static bool features_is_valid(struct vduse_dev_config *config) if ((config->device_id == VIRTIO_ID_BLOCK) && (config->features & BIT_ULL(VIRTIO_BLK_F_CONFIG_WCE))) return false; + else if ((config->device_id == VIRTIO_ID_NET) && + (config->features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))) + return false; return true; } From patchwork Tue Jan 9 11:10:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 186322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp36316dyi; Tue, 9 Jan 2024 03:12:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhfmzAEkWER7p3ZjPtXRlvy6Oj0o4AoGFKKTw0YBe/mNQNVcUyxlLjU3el2UUlnuf7HFU6 X-Received: by 2002:a17:90a:a90:b0:28c:17de:c8ce with SMTP id 16-20020a17090a0a9000b0028c17dec8cemr2765615pjw.2.1704798775965; Tue, 09 Jan 2024 03:12:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704798775; cv=none; d=google.com; s=arc-20160816; b=maf+xmreR1+XP3q6xdUYbnTOAj5fGexDUrC+VmcAYcTkedLHmPOfb3STUTIZBWaune k/C8bLHZlody2AWacGzVApceGiwYZyXScJM0/ZUOpxF29l0eIKrsDUrb8BaJKK/hXm9j tYoniFCidJb/WstYDqHMWDQFFeCTjT7f7RTyAD6F1HWlX1j8FZHU5cW/XdaPy6h3Vyhm Id85C/IdHiGkMBWn2103SqZnkpQ0bvRw5hgFA94AzuY+iwLD1mBR7N5Q5hIb3V2doGiO xr0LqAOVb8e6sPP8I515UE7YsEdaw791vxlt7AY/7XUzxn5UNdz3Eey71aTa/Tgu3N2/ /2iA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20748-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h11-20020a17090acf0b00b0028d0fc8a26csi6836923pju.21.2024.01.09.03.12.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:12:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20748-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20748-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5F709B24A1E for ; Tue, 9 Jan 2024 11:11:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BFB1381D1; Tue, 9 Jan 2024 11:10:51 +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_P=C3=A9r?= =?utf-8?q?ez?= 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787611081394357942 X-GMAIL-MSGID: 1787611081394357942 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 Reviewed-by: Xie Yongji --- 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 }, };