From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE7EEC38142 for ; Tue, 31 Jan 2023 23:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232163AbjAaXXm (ORCPT ); Tue, 31 Jan 2023 18:23:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232231AbjAaXXd (ORCPT ); Tue, 31 Jan 2023 18:23:33 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 514F813DD6 for ; Tue, 31 Jan 2023 15:23:07 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIiA60032540; Tue, 31 Jan 2023 23:22:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=Kal1PptRBxlONzgXZQOXmRbMOcCwGDMUheRFMVNnurI=; b=yeqcJS67lcoZe8A0+4R9eLuk41xD3digiv3Bay72Q998tpQ1AoWQzxJFeVMw6O93NLe3 cT3IdGMiiQS9/igxHoG/MNQlBLCvNpZPdXZsLGm1HFJjwOyJFGsi8pSqzcb9H/DOxB/D pB2tBKlwo9LAYmPa8NFc/bAu9TgEcR7DrUHV3DRkhskZ1dtHG0ztDEq3viO/NMyjYNw7 5GB1e0tWu1l3mYb+b0tjiiuUcrWS62oO9P6lk8JtW0fumkP3KjObOE3HCQMbnnaRiXtV M9YntD5UhuKQgvVV5d55s1YAHAepJivaGL5PBrcdIecBg7DvAFdpGc70Yj4x0ZD1e3pK nA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvrjxyxd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:43 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVj033826; Tue, 31 Jan 2023 23:22:42 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-2; Tue, 31 Jan 2023 23:22:42 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] vdpa: fix improper error message when adding vdpa dev Date: Tue, 31 Jan 2023 15:22:19 -0800 Message-Id: <1675207345-22328-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: EP3D4CsxfbRv-TvQ-aM1fTI77SlGqbsm X-Proofpoint-ORIG-GUID: EP3D4CsxfbRv-TvQ-aM1fTI77SlGqbsm Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In below example, before the fix, mtu attribute is supported by the parent mgmtdev, but the error message showing "All provided are not supported" is just misleading. $ vdpa mgmtdev show vdpasim_net: supported_classes net max_supported_vqs 3 dev_features MTU MAC CTRL_VQ CTRL_MAC_ADDR ANY_LAYOUT VERSION_1 ACCESS_PL= ATFORM $ vdpa dev add mgmtdev vdpasim_net name vdpasim0 mtu 5000 max_vqp 2 Error: vdpa: All provided attributes are not supported. kernel answers: Operation not supported After fix, the relevant error message will be like: $ vdpa dev add mgmtdev vdpasim_net name vdpasim0 mtu 5000 max_vqp 2 Error: vdpa: Some provided attributes are not supported: 0x1000. kernel answers: Operation not supported Signed-off-by: Si-Wei Liu Reviewed-by: Eli Cohen Reviewed-by: Parav Pandit --- drivers/vdpa/vdpa.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 8ef7aa1..3a82ca78 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -622,9 +622,11 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff= *skb, struct genl_info *i err =3D PTR_ERR(mdev); goto err; } + if ((config.mask & mdev->config_attr_mask) !=3D config.mask) { - NL_SET_ERR_MSG_MOD(info->extack, - "All provided attributes are not supported"); + NL_SET_ERR_MSG_FMT_MOD(info->extack, + "Some provided attributes are not supported: 0x%llx", + config.mask & ~mdev->config_attr_mask); err =3D -EOPNOTSUPP; goto err; } --=20 1.8.3.1 From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FB2AC636CC for ; Tue, 31 Jan 2023 23:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbjAaXXs (ORCPT ); Tue, 31 Jan 2023 18:23:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232171AbjAaXXf (ORCPT ); Tue, 31 Jan 2023 18:23:35 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9463424CA1 for ; Tue, 31 Jan 2023 15:23:09 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIi4gG014086; Tue, 31 Jan 2023 23:22:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=3qVacz3Bma3en7YMTykpbmYhLaBsLJgzc5BjnHjFnJA=; b=k6l4wN64gFpL3lp+HcNkE3QzviBL3xh4hfQQWJFoMpa6ldVIfpvtWCvVi2eN+orAdsRX itic0UXoC2zovvVw7Jn7YEYsP/VdOYRBUtg6qpx1tnKi3Wzb+WhYVpu82jCc7cuuJtWm JaMwlj+ZiRCT2JWXugyYmvPUjPBdN7qwaFuZMJGLSkq0xIexU9xHXlqTW+r8/Xiw45TM fbRV6eKgUotJmJwZ+islqfBTwGppc4+dnROyy3HqXj+jtrYD3Qcb0MUhzg0vPq0Ius1N 6zMs9k1sUGdXzy0ejBqYYWG//EdT9aWR7zC3IYTBeFgYrKU5IF7nnzbqc1pBJIbaZivT FQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvn9y061-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:44 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVl033826; Tue, 31 Jan 2023 23:22:43 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-3; Tue, 31 Jan 2023 23:22:43 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] vdpa: conditionally read STATUS in config space Date: Tue, 31 Jan 2023 15:22:20 -0800 Message-Id: <1675207345-22328-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: iRhEFxuIEPNNz8VEkJEJOpiEcLFjVI3i X-Proofpoint-ORIG-GUID: iRhEFxuIEPNNz8VEkJEJOpiEcLFjVI3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The spec says: status only exists if VIRTIO_NET_F_STATUS is set Similar to MAC and MTU, vdpa_dev_net_config_fill() should read STATUS conditionally depending on the feature bits. Signed-off-by: Si-Wei Liu Reviewed-by: Parav Pandit --- drivers/vdpa/vdpa.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 3a82ca78..21c8aa3 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -843,18 +843,25 @@ static int vdpa_dev_net_mac_config_fill(struct sk_buf= f *msg, u64 features, sizeof(config->mac), config->mac); } =20 +static int vdpa_dev_net_status_config_fill(struct sk_buff *msg, u64 featur= es, + const struct virtio_net_config *config) +{ + u16 val_u16; + + if ((features & BIT_ULL(VIRTIO_NET_F_STATUS)) =3D=3D 0) + return 0; + + val_u16 =3D __virtio16_to_cpu(true, config->status); + return nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16); +} + static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_bu= ff *msg) { struct virtio_net_config config =3D {}; u64 features_device; - u16 val_u16; =20 vdev->config->get_config(vdev, 0, &config, sizeof(config)); =20 - val_u16 =3D __virtio16_to_cpu(true, config.status); - if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16)) - return -EMSGSIZE; - features_device =3D vdev->config->get_device_features(vdev); =20 if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device, @@ -867,6 +874,9 @@ static int vdpa_dev_net_config_fill(struct vdpa_device = *vdev, struct sk_buff *ms if (vdpa_dev_net_mac_config_fill(msg, features_device, &config)) return -EMSGSIZE; =20 + if (vdpa_dev_net_status_config_fill(msg, features_device, &config)) + return -EMSGSIZE; + return vdpa_dev_net_mq_config_fill(msg, features_device, &config); } =20 --=20 1.8.3.1 From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F21AC636CC for ; Tue, 31 Jan 2023 23:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232216AbjAaXX4 (ORCPT ); Tue, 31 Jan 2023 18:23:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjAaXXq (ORCPT ); Tue, 31 Jan 2023 18:23:46 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C565924C for ; Tue, 31 Jan 2023 15:23:21 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIhvYq013722; Tue, 31 Jan 2023 23:22:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=zNHCg0bm+sv//yDfaYhZHGrfS2qHTDN9BuTwB00O5ag=; b=St279jvAs2LI2CGYpDItzlvkAFVa8OaRIgJn52/saXwM7+QY4/NzlkE+8D5ngDoGtj7z aDxqIaiTUTc2SDxLh3EjUunJQqCOyau45277Pr+tVQQ3mlmZNXD3SSrW5E0QBXYBXIDn oabpf/5XgD5D9xcU1qt8XFxBnj5XrGag5ztmU/rARFtKHmy161ZlV3W6Os/HfKWSyxjv VMZtNymnKqyMEUq0pHnDxToeYn1DP2t6vTc9zJMzRnvO/sy4SiKXdDm3xFTihB8LI/DM glhlkpPyr6Ii3od/MulZCmaR8otQC/YVyxDZcsDeO7l552ovjLWb4xmnI2iL6WERAlI9 ag== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvn9y063-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:45 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVm033826; Tue, 31 Jan 2023 23:22:44 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-4; Tue, 31 Jan 2023 23:22:44 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] vdpa: validate provisioned device features against specified attribute Date: Tue, 31 Jan 2023 15:22:21 -0800 Message-Id: <1675207345-22328-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: -KGqXAya8ci2Y3dMu5ShAG6TV53IXYj_ X-Proofpoint-ORIG-GUID: -KGqXAya8ci2Y3dMu5ShAG6TV53IXYj_ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With device feature provisioning, there's a chance for misconfiguration that the vdpa feature attribute supplied in 'vdpa dev add' command doesn't get selected on the device_features to be provisioned. For instance, when a @mac attribute is specified, the corresponding feature bit _F_MAC in device_features should be set for consistency. If there's conflict on provisioned features against the attribute, it should be treated as an error to fail the ambiguous command. Noted the opposite is not necessarily true, for e.g. it's okay to have _F_MAC set in device_features without providing a corresponding @mac attribute, in which case the vdpa vendor driver could load certain default value for attribute that is not explicitly specified. Generalize this check in vdpa core so that there's no duplicate code in each vendor driver. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 21c8aa3..1eba978 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -601,8 +601,26 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff= *skb, struct genl_info *i config.mask |=3D BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); } if (nl_attrs[VDPA_ATTR_DEV_FEATURES]) { + u64 missing =3D 0x0ULL; + config.device_features =3D nla_get_u64(nl_attrs[VDPA_ATTR_DEV_FEATURES]); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR] && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MAC))) + missing |=3D BIT_ULL(VIRTIO_NET_F_MAC); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU] && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MTU))) + missing |=3D BIT_ULL(VIRTIO_NET_F_MTU); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP] && + config.net.max_vq_pairs > 1 && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MQ))) + missing |=3D BIT_ULL(VIRTIO_NET_F_MQ); + if (missing) { + NL_SET_ERR_MSG_FMT_MOD(info->extack, + "Missing features 0x%llx for provided attributes", + missing); + return -EINVAL; + } config.mask |=3D BIT_ULL(VDPA_ATTR_DEV_FEATURES); } =20 --=20 1.8.3.1 From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFA3DC38142 for ; Tue, 31 Jan 2023 23:23:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbjAaXX6 (ORCPT ); Tue, 31 Jan 2023 18:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjAaXXv (ORCPT ); Tue, 31 Jan 2023 18:23:51 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4AF61B4 for ; Tue, 31 Jan 2023 15:23:27 -0800 (PST) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIiQsn014351; Tue, 31 Jan 2023 23:22:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=t7qcF4HWMxrV8l58tGxaDXS4xRP41Hcy7/t+u7kgys0=; b=bcFHlrIJEo3HTxMg2jAzLl3Stjmo2AayMg1EYSD+jkfHHI6kp4O6HETAZMcWqexdFHzh 0PUqxnra4JnBhWqbJmVz5uAMhcNpKcj0K/nQvCvr6E8UuSW7LIqQ9GTsK5lGWRPFqbtq vXw48588t91lmL6DvD2LIr2mNWwwa/H7Cl1Wc7TkcultV4LAZmhItxWwYOuvXJPz7R5M Vp5+DkTSrcuiATf2wjbRbCbDuEWkJMa10MBx1TB9Lv8CaS/e9t5D2VOt5vk6CLr5VaQj vLGkCuQ3GIEsVjDR3zDB9kBFCCci0rS03dmq/SKBFs4YbHpCE63TyfFKbv0ApwJLHVp/ 1g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvq9q2nr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:45 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVn033826; Tue, 31 Jan 2023 23:22:45 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-5; Tue, 31 Jan 2023 23:22:45 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] virtio: VIRTIO_DEVICE_F_MASK for all per-device features Date: Tue, 31 Jan 2023 15:22:22 -0800 Message-Id: <1675207345-22328-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-ORIG-GUID: u7wZNLAmazzAqxLaCvdUbo6fcJwSzJ-B X-Proofpoint-GUID: u7wZNLAmazzAqxLaCvdUbo6fcJwSzJ-B Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce VIRTIO_DEVICE_F_MASK bitmask used for identification of per-device features. Feature bits VIRTIO_TRANSPORT_F_START through VIRTIO_TRANSPORT_F_END are reserved for transport features hence are not counted as per-device features against the 64bit feature space. Signed-off-by: Si-Wei Liu --- include/uapi/linux/virtio_config.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio= _config.h index 3c05162..3bdc7ed 100644 --- a/include/uapi/linux/virtio_config.h +++ b/include/uapi/linux/virtio_config.h @@ -54,6 +54,14 @@ #define VIRTIO_TRANSPORT_F_START 28 #define VIRTIO_TRANSPORT_F_END 41 =20 +/* + * Bitmask for all per-device features: feature bits VIRTIO_TRANSPORT_F_ST= ART + * through VIRTIO_TRANSPORT_F_END are unset, i.e. 0xfffffc000fffffff for + * all 64bit features + */ +#define VIRTIO_DEVICE_F_MASK (~0ULL << (VIRTIO_TRANSPORT_F_END + 1) | \ + ((1ULL << VIRTIO_TRANSPORT_F_START) - 1)) + #ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've * suppressed them? */ --=20 1.8.3.1 From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADBE1C38142 for ; Tue, 31 Jan 2023 23:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230028AbjAaXYW (ORCPT ); Tue, 31 Jan 2023 18:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbjAaXYL (ORCPT ); Tue, 31 Jan 2023 18:24:11 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C52513D42 for ; Tue, 31 Jan 2023 15:23:40 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIi4tb032498; Tue, 31 Jan 2023 23:22:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=X8vNUi+5b0IaJnlztUNKoNbbjRp2qUPlQkLB5sClFlY=; b=jhp+p44jA9agosdrZWgrnJFkGDiujlmFRXd9jFNiYVoWEXuT/KuzYkAdY6DksoLIAYzH g2bVwBBD8PtSptmOVySSv3BP947gI4NJiU0giadJU0dUz+6syDmatf8Dz7rjvkcsDE/H zva7AHzXbxAQ44UKZ+2dnAUR1ePZi479IteZnrDIAbZKsTDQKqFwqIMbBtqv86nqPrWJ bsKFhIytzJKCsX0BK+P9dODzHP8VYinQfsD14ttE9Gv+6Fl5vFjR9F4rOIZ0jAu+cYCf UmlN/8NjE1g/5kHvcijE+Q5hWaNMW9E2C3IPeys5khRp7IWczuo3W1IA7v1+5ejA2/7H Ow== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvrjxyxk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:47 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVo033826; Tue, 31 Jan 2023 23:22:46 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-6; Tue, 31 Jan 2023 23:22:46 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] vdpa: validate device feature provisioning against supported class Date: Tue, 31 Jan 2023 15:22:23 -0800 Message-Id: <1675207345-22328-6-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: MJ9Igy1v62s08vACfewGNhbJKzOeqzTH X-Proofpoint-ORIG-GUID: MJ9Igy1v62s08vACfewGNhbJKzOeqzTH Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Today when device features are explicitly provisioned, the features user supplied may contain device class specific features that are not supported by the parent managment device. On the other hand, when parent managment device supports more than one class, the device features to provision may be ambiguous if none of the class specific attributes is provided at the same time. Validate these cases and prompt appropriate user errors accordingly. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 51 ++++++++++++++++++++++++++++++++++++++++++-------= -- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1eba978..35a72d6 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -460,12 +460,30 @@ static int vdpa_nl_mgmtdev_handle_fill(struct sk_buff= *msg, const struct vdpa_mg return 0; } =20 +static u64 vdpa_mgmtdev_get_classes(const struct vdpa_mgmt_dev *mdev, + unsigned int *nclasses) +{ + u64 supported_classes =3D 0; + unsigned int n =3D 0; + int i =3D 0; + + while (mdev->id_table[i].device) { + if (mdev->id_table[i].device <=3D 63) { + supported_classes |=3D BIT_ULL(mdev->id_table[i].device); + n++; + } + i++; + } + if (nclasses) + *nclasses =3D n; + + return supported_classes; +} + static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_b= uff *msg, u32 portid, u32 seq, int flags) { - u64 supported_classes =3D 0; void *hdr; - int i =3D 0; int err; =20 hdr =3D genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags, VDPA_CMD_MG= MTDEV_NEW); @@ -475,14 +493,9 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_de= v *mdev, struct sk_buff *m if (err) goto msg_err; =20 - while (mdev->id_table[i].device) { - if (mdev->id_table[i].device <=3D 63) - supported_classes |=3D BIT_ULL(mdev->id_table[i].device); - i++; - } - if (nla_put_u64_64bit(msg, VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES, - supported_classes, VDPA_ATTR_UNSPEC)) { + vdpa_mgmtdev_get_classes(mdev, NULL), + VDPA_ATTR_UNSPEC)) { err =3D -EMSGSIZE; goto msg_err; } @@ -571,8 +584,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff= *skb, struct genl_info *i struct vdpa_dev_set_config config =3D {}; struct nlattr **nl_attrs =3D info->attrs; struct vdpa_mgmt_dev *mdev; + unsigned int ncls =3D 0; const u8 *macaddr; const char *name; + u64 classes; int err =3D 0; =20 if (!info->attrs[VDPA_ATTR_DEV_NAME]) @@ -649,6 +664,24 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff= *skb, struct genl_info *i goto err; } =20 + classes =3D vdpa_mgmtdev_get_classes(mdev, &ncls); + if (config.mask & VDPA_DEV_NET_ATTRS_MASK && + !(classes & BIT_ULL(VIRTIO_ID_NET))) { + NL_SET_ERR_MSG_MOD(info->extack, + "Network class attributes provided on unsupported management device= "); + err =3D -EINVAL; + goto err; + } + if (!(config.mask & VDPA_DEV_NET_ATTRS_MASK) && + config.mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES) && + classes & BIT_ULL(VIRTIO_ID_NET) && ncls > 1 && + config.device_features & VIRTIO_DEVICE_F_MASK) { + NL_SET_ERR_MSG_MOD(info->extack, + "Management device supports multi-class while device features speci= fied are ambiguous"); + err =3D -EINVAL; + goto err; + } + err =3D mdev->ops->dev_add(mdev, name, &config); err: up_write(&vdpa_dev_lock); --=20 1.8.3.1 From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 281E5C38142 for ; Tue, 31 Jan 2023 23:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231718AbjAaXYY (ORCPT ); Tue, 31 Jan 2023 18:24:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232305AbjAaXYT (ORCPT ); Tue, 31 Jan 2023 18:24:19 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 878415A348 for ; Tue, 31 Jan 2023 15:23:46 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIi8KY006403; Tue, 31 Jan 2023 23:22:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=jBMajAB9G57vQkrNzc3zhBcJ+CNOgFjKuu+oW+pIhbI=; b=1l3K44/sOyMyiBBFNyxXwi/L9zrW/Vc7H2hXKgLfkHwop6uuh/c8aT5QwgSvRESP3Fs7 FXsjisfomvLATZdIHFXwkugBslTP8/8pXuOwKL67Q3ymionPRm+5Sl0pFLpAa0WTR22G w+h8vRZi/SF392on1gdn2iMzThPEX7nHwjXd8vkt1ML3ICnCeQNztLK7IuT5dEeJve8M 95ZrhZWGuiudL+5uXzMuv34fWsczkXaT3DvQzRoJwJIeP+yinQJLJFTxps/0l/WpW8Ue miRmaOMTgaUhxJHaMkz5AGWpV4Gt1oUAEYyHWysfd9z/nXbkV1/un5a1AWWqeB9dbY+F xA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvp171fr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:47 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVp033826; Tue, 31 Jan 2023 23:22:47 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-7; Tue, 31 Jan 2023 23:22:47 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] vdpa/mlx5: conditionally show MTU and STATUS in config space Date: Tue, 31 Jan 2023 15:22:24 -0800 Message-Id: <1675207345-22328-7-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: O-lnltgzBHJSzogCVGl15IVauHYM3XrS X-Proofpoint-ORIG-GUID: O-lnltgzBHJSzogCVGl15IVauHYM3XrS Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The spec says: mtu only exists if VIRTIO_NET_F_MTU is set status only exists if VIRTIO_NET_F_STATUS is set We should only show MTU and STATUS conditionally depending on the feature bits. Signed-off-by: Si-Wei Liu --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index 3a6dbbc6..3d49eae 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block *nb, u= nsigned long event, void *p struct mlx5_vdpa_wq_ent *wqent; =20 if (event =3D=3D MLX5_EVENT_TYPE_PORT_CHANGE) { + if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS))) + return NOTIFY_DONE; switch (eqe->sub_type) { case MLX5_PORT_CHANGE_SUBTYPE_DOWN: case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: @@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *= v_mdev, const char *name, goto err_alloc; } =20 - err =3D query_mtu(mdev, &mtu); - if (err) - goto err_alloc; + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) { + err =3D query_mtu(mdev, &mtu); + if (err) + goto err_alloc; =20 - ndev->config.mtu =3D cpu_to_mlx5vdpa16(mvdev, mtu); + ndev->config.mtu =3D cpu_to_mlx5vdpa16(mvdev, mtu); + } =20 - if (get_link_state(mvdev)) - ndev->config.status |=3D cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); - else - ndev->config.status &=3D cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP); + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { + if (get_link_state(mvdev)) + ndev->config.status |=3D cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); + else + ndev->config.status &=3D cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP= ); + } =20 if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN); --=20 1.8.3.1 From nobody Sat Sep 13 17:03:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C659C38142 for ; Tue, 31 Jan 2023 23:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbjAaXYk (ORCPT ); Tue, 31 Jan 2023 18:24:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbjAaXYi (ORCPT ); Tue, 31 Jan 2023 18:24:38 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0472438034 for ; Tue, 31 Jan 2023 15:24:07 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIiVEW032729; Tue, 31 Jan 2023 23:22:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=T6xMGlzsTmhSgD4IX7LW02mSnDlYmQ6gxm+xmDouPXM=; b=KhuNTpPHHSrMArZM/48omH/XVDPbpzEOHIj4s9gGFqmUFhrjrKIF9cLz5qC9FJGSd75F VzoxJItkjzeEuesfazDt1xb6Lf9snLDz7zH3gDIf+M++gpEv3iVSZVFMyDOMKKycLVik jHirZHtClzanw+Z3MMoTudR2xA2kYzfmMjwER2+kk2QwlRXPEyxRAZrDFyPB7+QVfFgk eRL1v47fo7Ha00S66gfzxwFfhIatjqLhOGAIIymgVqHOd0tS4ls1C2Kz2oRU/H2P4nBA RbOe9H3ZtmBISlCAk8vdF/0idrfktM5e6POJmlsUwmfcXe8yiJkpQnXj5LLCq1AwWP5J aQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvrjxyxm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:48 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VN9OVr033826; Tue, 31 Jan 2023 23:22:48 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct56fb9w-8; Tue, 31 Jan 2023 23:22:48 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] vdpa/mlx5: support device features provisioning Date: Tue, 31 Jan 2023 15:22:25 -0800 Message-Id: <1675207345-22328-8-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> References: <1675207345-22328-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: Is-TpYzejA4d64fOzmdGgD-dyr-80sKZ X-Proofpoint-ORIG-GUID: Is-TpYzejA4d64fOzmdGgD-dyr-80sKZ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch implements features provisioning for mlx5_vdpa. 1) Validate the provisioned features are a subset of the parent features. 2) Clearing features that are not wanted by userspace. For example: # vdpa mgmtdev show pci/0000:41:04.2: supported_classes net max_supported_vqs 65 dev_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS CTRL_= VQ CTRL_VLAN MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 1) Provision vDPA device with all features derived from the parent # vdpa dev add name vdpa1 mgmtdev pci/0000:41:04.2 # vdpa dev config show vdpa1: mac e4:11:c6:d3:45:f0 link up link_announce false max_vq_pairs 1= mtu 1500 negotiated_features CSUM GUEST_CSUM MTU HOST_TSO4 HOST_TSO6 STATUS CT= RL_VQ CTRL_VLAN MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 2) Provision vDPA device with a subset of parent features # vdpa dev add name vdpa1 mgmtdev pci/0000:41:04.2 device_features 0x30= 0020000 # vdpa dev config show vdpa1: negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM Signed-off-by: Si-Wei Liu --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 49 ++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index 3d49eae..b40dd1a 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2183,6 +2183,7 @@ static u64 get_supported_features(struct mlx5_core_de= v *mdev) mlx_vdpa_features |=3D BIT_ULL(VIRTIO_NET_F_STATUS); mlx_vdpa_features |=3D BIT_ULL(VIRTIO_NET_F_MTU); mlx_vdpa_features |=3D BIT_ULL(VIRTIO_NET_F_CTRL_VLAN); + mlx_vdpa_features |=3D BIT_ULL(VIRTIO_NET_F_MAC); =20 return mlx_vdpa_features; } @@ -3062,6 +3063,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_= mdev, const char *name, struct mlx5_vdpa_dev *mvdev; struct mlx5_vdpa_net *ndev; struct mlx5_core_dev *mdev; + u64 device_features; u32 max_vqs; u16 mtu; int err; @@ -3070,6 +3072,24 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v= _mdev, const char *name, return -ENOSPC; =20 mdev =3D mgtdev->madev->mdev; + device_features =3D mgtdev->mgtdev.supported_features; + if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) { + if (add_config->device_features & ~device_features) { + dev_warn(mdev->device, + "The provisioned features 0x%llx are not supported by this device wit= h features 0x%llx\n", + add_config->device_features, device_features); + return -EINVAL; + } + device_features &=3D add_config->device_features; + } + if (!(device_features & BIT_ULL(VIRTIO_F_VERSION_1) && + device_features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM))) { + dev_warn(mdev->device, + "Must provision minimum features 0x%llx for this device", + BIT_ULL(VIRTIO_F_VERSION_1) | BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)); + return -EOPNOTSUPP; + } + if (!(MLX5_CAP_DEV_VDPA_EMULATION(mdev, virtio_queue_type) & MLX5_VIRTIO_EMULATION_CAP_VIRTIO_QUEUE_TYPE_SPLIT)) { dev_warn(mdev->device, "missing support for split virtqueues\n"); @@ -3098,7 +3118,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_= mdev, const char *name, if (IS_ERR(ndev)) return PTR_ERR(ndev); =20 - ndev->mvdev.mlx_features =3D mgtdev->mgtdev.supported_features; ndev->mvdev.max_vqs =3D max_vqs; mvdev =3D &ndev->mvdev; mvdev->mdev =3D mdev; @@ -3137,7 +3156,9 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_= mdev, const char *name, =20 if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN); - } else { + /* No bother setting mac address in config if not going to provision _F_M= AC */ + } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) =3D=3D 0 = || + device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { err =3D mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac); if (err) goto err_alloc; @@ -3148,11 +3169,26 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *= v_mdev, const char *name, err =3D mlx5_mpfs_add_mac(pfmdev, config->mac); if (err) goto err_alloc; - - ndev->mvdev.mlx_features |=3D BIT_ULL(VIRTIO_NET_F_MAC); + } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) =3D=3D 0)= { + /* + * We used to clear _F_MAC feature bit if seeing + * zero mac address when device features are not + * specifically provisioned. Keep the behaviour + * so old scripts do not break. + */ + device_features &=3D ~BIT_ULL(VIRTIO_NET_F_MAC); + } else if (device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { + /* Don't provision zero mac address for _F_MAC */ + mlx5_vdpa_warn(&ndev->mvdev, + "No mac address provisioned?\n"); + err =3D -EINVAL; + goto err_alloc; } =20 - config->max_virtqueue_pairs =3D cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); + if (device_features & BIT_ULL(VIRTIO_NET_F_MQ)) + config->max_virtqueue_pairs =3D cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); + + ndev->mvdev.mlx_features =3D device_features; mvdev->vdev.dma_dev =3D &mdev->pdev->dev; err =3D mlx5_vdpa_alloc_resources(&ndev->mvdev); if (err) @@ -3249,7 +3285,8 @@ static int mlx5v_probe(struct auxiliary_device *adev, mgtdev->mgtdev.id_table =3D id_table; mgtdev->mgtdev.config_attr_mask =3D BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR= ) | BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP) | - BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU); + BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) | + BIT_ULL(VDPA_ATTR_DEV_FEATURES); mgtdev->mgtdev.max_supported_vqs =3D MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues) + 1; mgtdev->mgtdev.supported_features =3D get_supported_features(mdev); --=20 1.8.3.1