From patchwork Fri Feb 3 05:01:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 52307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp649308wrn; Thu, 2 Feb 2023 21:05:35 -0800 (PST) X-Google-Smtp-Source: AK7set+WPxpYt0TffM3JrpW5xM82GyGoPTmXgoI6zcYF7V+a6G+FhPvrAYDmgPoIfRc8lEeQkzGx X-Received: by 2002:a17:907:2d28:b0:88d:f759:15ae with SMTP id gs40-20020a1709072d2800b0088df75915aemr12594015ejc.42.1675400734809; Thu, 02 Feb 2023 21:05:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675400734; cv=none; d=google.com; s=arc-20160816; b=R22Fu1eolth1ki6+Yg2/5pR5dZjtUTA+25JPLUGqCAc0bjK1g2Gxe3/jU6d6lhps6x 31KlDzTyp0t3eHygHMtNkTe6hKMhK8gf+Rv+w3zkvV9mjd39ulxoGVi3hQUpG2UYlFT3 7d4vlCEWL8DyA88HifwsMiF/Jne2AJNCmma61O+PoCVIp1qFfob8KCGYOM9C5cFrDya7 /aRvMlcI853wRaBqkYOdcV7epU7hC8IsNLrKTqjM5odXnibKpe8R/ny24X5uJQ/KlbOo n/MXNOM5Al6rE/dnmC/xktuNF4CNVVfyEjv6oRk3mGqQllyyjJsUAAqIy1QnlJ+ZOul6 J7bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=j/lEJg/ReXobH4hd+iLRobue9kWLN1CWVWeI2l8aOjc=; b=CTnglMTW9YuqLxvRYPDEinJUDB9MyNe2VfHp8ZSfVQJBLNxA3aYFE8RMth8iuEPRpp HhhmdleKSDZaumsTJPmSZy30dMZBZugZ+Aygaqfd4D/gfKrJmAyTZ9Tly1nOtDNBHV1/ HED9y0vl/4aJr2VmyNfdNMLTfoLB7lNpUBpAOlsItnNiib4+HX0RxDeqm+1YaLVE5gYY TBACVf3B3fLY9i/qTmWwhxHeuqRoZ5qQq6A1VqV1x0ds0qXnXmXIru9efr5l8VmQdj3l Z7baMithAr+0YlLshuO6IJs7CTr8YoZjlan9reD3fXUFz8sjXEEV1Kuvv4PQlZnkUaCp ympw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=GfrQljOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iy19-20020a170907819300b0087bd6ca5a89si1773836ejc.62.2023.02.02.21.05.11; Thu, 02 Feb 2023 21:05:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=GfrQljOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbjBCFCo (ORCPT + 99 others); Fri, 3 Feb 2023 00:02:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjBCFCb (ORCPT ); Fri, 3 Feb 2023 00:02:31 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FC474C0C for ; Thu, 2 Feb 2023 21:02:28 -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 3130Ndv3020583; Fri, 3 Feb 2023 05:02:23 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=j/lEJg/ReXobH4hd+iLRobue9kWLN1CWVWeI2l8aOjc=; b=GfrQljOiRNBZeD3+uEcY2KviulHljO+Emjo4VX8gdhaHCe2Hcnv46cHe6YupEyYrXqyF NSU18R56RP/Y+uP4fZjWXykxJYgOqWKJ/eSxqapv64o1oV26VgrzpTgP/IclMFRp8jvg OZIRQ9WoG7vDwPnt+hqZosqCG+tnVJxVEATg8f0FWYJ28WM8JVtk6DMIteGPqK5zsqxN Yo+YW4luX5pLfBBTAXufIeTvLCSVdDiRMlz/Ped5oYkqgXYUSLMFWCSZcOwbDGkeVlYo 7XdVQBv5g9JFP2jHBNANMIx82+aOsULIlDwB0lhSvej8Xa2pW9nAR7kUeEAxv5lpstDZ NA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfmbg4uqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 Feb 2023 05:02:23 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31340RuM006053; Fri, 3 Feb 2023 05:02:22 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct5a2tm8-2; Fri, 03 Feb 2023 05:02:22 +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 v3 1/6] vdpa: fix improper error message when adding vdpa dev Date: Thu, 2 Feb 2023 21:01:58 -0800 Message-Id: <1675400523-12519-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675400523-12519-1-git-send-email-si-wei.liu@oracle.com> References: <1675400523-12519-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-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030044 X-Proofpoint-ORIG-GUID: l4IR-6dWlbopkxxcNf_lkb5xt0N3O2r6 X-Proofpoint-GUID: l4IR-6dWlbopkxxcNf_lkb5xt0N3O2r6 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756785001342315311?= X-GMAIL-MSGID: =?utf-8?q?1756785001342315311?= 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_PLATFORM $ 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 Fixes: d8ca2fa5be1b ("vdpa: Enable user to set mac and mtu of vdpa device") Signed-off-by: Si-Wei Liu Reviewed-by: Parav Pandit Reviewed-by: Eli Cohen --- 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 = PTR_ERR(mdev); goto err; } + if ((config.mask & mdev->config_attr_mask) != 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 = -EOPNOTSUPP; goto err; } From patchwork Fri Feb 3 05:01:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 52309 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp649663wrn; Thu, 2 Feb 2023 21:06:47 -0800 (PST) X-Google-Smtp-Source: AK7set8hUIiqjHlWR/T2vJC+/bZ2/P52Us1yO4GPX/riRjp+MDJlDTLbZpFMe18Ps3sYTaDREZ+C X-Received: by 2002:a17:907:2130:b0:87b:daf7:cf3b with SMTP id qo16-20020a170907213000b0087bdaf7cf3bmr8822320ejb.47.1675400807332; Thu, 02 Feb 2023 21:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675400807; cv=none; d=google.com; s=arc-20160816; b=xEuCQ1Xp/wW3e6ltzbKOqw8ipJok7yhADoWGeK22dq/Be3faMbuezJr61I+Kgk/f/C KMVmaUe8+kyMS1+A0qlXGPTIzTwaSjus2gsqU68SCBExOES20urRtKA09szqUNbFsvO1 euXzzWWcXkgtUwCf1MgIYA3Xvk1xPt2XtvY3Fnvu8mhAxMc+N9/lw/V5NpZYoXB1UR8w sMwQBLuWXf/P0JCY5LeScSmH47iRzi346tUQi9/9ep8nDAedMpdDEovSvxibY2v2GlMt Su35OxKDufQ1Ghga7e0/exvv9BWaB4doGCXVT80aEPxjdq93n2++jZ0hRpGPe8Ikr+kf TzJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Ejnp7C0WH2CJJTjLdJGDsNeQ6ndq2k8gOgYfgezuMYI=; b=bDz/egeNtx8GJjx+NOwziLMLr/H3CHpJ+ITC1FOYfiOypbv9/Vb2Ey1VAlUisxDZAj T0trnuFibOxHhQDoi+b9cIZbb1j2aFHXQbOzRwxHUW8fQTmcUWGHe/SZgXYYUwgrmRDD Bmqu/IkNIpNW2bPLmUQmLCz33q+SsvfShJ2EYMMvMJzKwl0iSp5Qtw42fdfgSHiWFY1F akFD/LQFyTMQhOvaSdIEg+KY096ODSyWsRXjM3Tykoy3459M7rC/4RU/F3KBcFDMv3xg ondcn+NjRIz6YMy4fMKPD8sz8k6T4c5KzTZpGMGpbEmBRwD5qHTcSYxfJc5y5dVMWeAw lIfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=DTdhMRo9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v16-20020a17090610d000b007c0c7c42636si2370967ejv.683.2023.02.02.21.06.23; Thu, 02 Feb 2023 21:06:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=DTdhMRo9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231905AbjBCFDJ (ORCPT + 99 others); Fri, 3 Feb 2023 00:03:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjBCFCg (ORCPT ); Fri, 3 Feb 2023 00:02:36 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B163374C3A for ; Thu, 2 Feb 2023 21:02:28 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3130NY0q028366; Fri, 3 Feb 2023 05:02:24 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=Ejnp7C0WH2CJJTjLdJGDsNeQ6ndq2k8gOgYfgezuMYI=; b=DTdhMRo9NUiVkb9cq3QUMo/6+I/PxI5E9p4oAOZ6XtS2JHsPU9VkkyCSfsdo4dUtjdH5 qNz1LaTHKqlDo2EznEckKj/uistnuglkYqBf0q1MoBKWueUluis8jOxNqC5Gqi61mP97 3/EhXgsyPVrLHoUCvD6ubS43a3Nwr/1xOtFAmACSaTOM+wTpI4fVCJtaGZR975vFj3TV bMFruvPg5oi3agP9ezqc1/4o03qEpWYzbY8aJf6IvycL6ETbsvBPC9DsoSTViWyZ+1kn 4LfrdCsb5z8jdsY1fROQIAB5oR0lHo56fGW1sOazdueK+rDT0/7aaIuQpvniVaTvICBG yg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfn9ymrqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 Feb 2023 05:02:24 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31340RuN006053; Fri, 3 Feb 2023 05:02:23 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct5a2tm8-3; Fri, 03 Feb 2023 05:02:23 +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 v3 2/6] vdpa: conditionally read STATUS in config space Date: Thu, 2 Feb 2023 21:01:59 -0800 Message-Id: <1675400523-12519-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675400523-12519-1-git-send-email-si-wei.liu@oracle.com> References: <1675400523-12519-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-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030044 X-Proofpoint-ORIG-GUID: g8pWt_9SIT-4NKne5pO83jvaFbB6N3jM X-Proofpoint-GUID: g8pWt_9SIT-4NKne5pO83jvaFbB6N3jM X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756785076795683175?= X-GMAIL-MSGID: =?utf-8?q?1756785076795683175?= 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 Reviewed-by: Eli Cohen --- 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_buff *msg, u64 features, sizeof(config->mac), config->mac); } +static int vdpa_dev_net_status_config_fill(struct sk_buff *msg, u64 features, + const struct virtio_net_config *config) +{ + u16 val_u16; + + if ((features & BIT_ULL(VIRTIO_NET_F_STATUS)) == 0) + return 0; + + val_u16 = __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_buff *msg) { struct virtio_net_config config = {}; u64 features_device; - u16 val_u16; vdev->config->get_config(vdev, 0, &config, sizeof(config)); - val_u16 = __virtio16_to_cpu(true, config.status); - if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16)) - return -EMSGSIZE; - features_device = vdev->config->get_device_features(vdev); 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; + if (vdpa_dev_net_status_config_fill(msg, features_device, &config)) + return -EMSGSIZE; + return vdpa_dev_net_mq_config_fill(msg, features_device, &config); } From patchwork Fri Feb 3 05:02:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 52306 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp649009wrn; Thu, 2 Feb 2023 21:04:43 -0800 (PST) X-Google-Smtp-Source: AK7set8gq0ribDvfjLa8fkaZ2EnjcL5Wogu6cs8qDDX+EGRMw3/XuY5BfQIPOZ94uLZ48XzLHcpF X-Received: by 2002:a17:907:3e82:b0:860:c12c:14f9 with SMTP id hs2-20020a1709073e8200b00860c12c14f9mr11442501ejc.40.1675400683610; Thu, 02 Feb 2023 21:04:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675400683; cv=none; d=google.com; s=arc-20160816; b=OJ5fOPtzCwsu5uR8ORysBTPrbRIz578s9a6APWbzErrXtfhlABaYrcsRBjDZTh5iEB j6yahcSgxtVjni0sZ3p/HWSASU9QAPDedCSz75FgHldeLjkd84pGQ9nEIe9rwqLNgthN UspTjBTgCV1N7Iyb1tuN4CHqqZcOoOCtm4KzIRV1EYVHNdxm1pb3A8As5iIJZt2zl58N wAirT5i+Vpr/NvVTQFOrkGWXk3rSnYAKXdUq2L0raBh5QG/JAmhS11lNFUtnWmQQccu3 kON+ogk0y3Nefc+NL7IGvu3ZFZG7ObvJjFtquzgvHjV7WrGiAMd8dF6qSoK2xyARulSk nn1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=zNHCg0bm+sv//yDfaYhZHGrfS2qHTDN9BuTwB00O5ag=; b=HA/yw/ziZWkHHL9pgju30fI4zrfswVbSFzAyIJPE4Y/Fb4ueAKSNGnL7Y8VTLxpiK4 pipi9fuvgNUZWxg1a3In84jgsw7X/5p0tGm+uySmUmvFBm3HMusAn8+s8dMpWxx9uSvc jlO60x8SGT6DG8+qzlWQGGAagUYk+W7xgBUJd6l4zl/NgwHpoW+1XOEFv8PVb47hoGHK qzCmHYkMG9CEh5WxkQJ5IvdLhrCsO0WDn7EAOzgNgC973hVNVX9gNz+jT0IKoh577X0/ pyWE+bKaSdWx6uEQNJ8zxzpop75TgPRE69mlO8QH+4kYo4dq5j2Mf4HlYyan94V3rPqt FFdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=h6ZOheHJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a056402354700b004a7ca3446d4si1731704edd.256.2023.02.02.21.04.19; Thu, 02 Feb 2023 21:04:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=h6ZOheHJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbjBCFC6 (ORCPT + 99 others); Fri, 3 Feb 2023 00:02:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjBCFCg (ORCPT ); Fri, 3 Feb 2023 00:02:36 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B148C74C19 for ; Thu, 2 Feb 2023 21:02:30 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3130NouW028457; Fri, 3 Feb 2023 05:02:25 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=h6ZOheHJd1t0EKkMn2unqbzFwxB8l7aVb7BuEHBlHQyMJExSTR+IBerQlFB9SAVYQdQ4 ot6et4872/ov9knVmADFD71LjAY0aBF8jARdaEYPNCf2dNy3nJEcJliKnmlZAcX7HfLj iQCM77qbn34W4/IlnRIhpyqMdKNpu6C3UMQ1uQWkxRDdyleDfeHdTNiiuvDaLU9YZnGe gLm8F1NZKo9B9LdlUlrCiz9/UmtCI7XgF/FVZO5EGzKEwy9y4r/f7BUCENyjYuVx8z6l HreUvwWy4dETFKO61ATjlf/IZVWWdOSKgEqeTb/8dSnJ1X+6eRQpP0Zgn5p3z9HmtC8F jg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfn9ymrqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 Feb 2023 05:02:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31340RuO006053; Fri, 3 Feb 2023 05:02:24 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct5a2tm8-4; Fri, 03 Feb 2023 05:02:24 +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 v3 3/6] vdpa: validate provisioned device features against specified attribute Date: Thu, 2 Feb 2023 21:02:00 -0800 Message-Id: <1675400523-12519-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675400523-12519-1-git-send-email-si-wei.liu@oracle.com> References: <1675400523-12519-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-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030044 X-Proofpoint-ORIG-GUID: lbRc_IPHDLIyWlPENHCDMtjeop61vsAO X-Proofpoint-GUID: lbRc_IPHDLIyWlPENHCDMtjeop61vsAO X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756784947124721294?= X-GMAIL-MSGID: =?utf-8?q?1756784947124721294?= 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 Reviewed-by: Eli Cohen --- 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 |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); } if (nl_attrs[VDPA_ATTR_DEV_FEATURES]) { + u64 missing = 0x0ULL; + config.device_features = 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 |= 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 |= 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 |= 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 |= BIT_ULL(VDPA_ATTR_DEV_FEATURES); } From patchwork Fri Feb 3 05:02:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 52305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp648829wrn; Thu, 2 Feb 2023 21:04:13 -0800 (PST) X-Google-Smtp-Source: AK7set8Ue2ILjwLBHvKyxxdDY6T4WZOtfEh0Cbr1AmSpuve6TVJzY+ZngE//hOIdB/3IrUzT/F33 X-Received: by 2002:a17:906:7e42:b0:883:b1b4:e798 with SMTP id z2-20020a1709067e4200b00883b1b4e798mr8732355ejr.10.1675400653641; Thu, 02 Feb 2023 21:04:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675400653; cv=none; d=google.com; s=arc-20160816; b=IO3gJYoHX6wiox3lP01rMzlOgC0Od/rarZi8UWhXOBSm1TI63SutswuR+r3gS/OCCH MTaXbWLuTanGI32Ic2wqZR1sd5bduph5ib3aIQ+l9AZxCycDGKrg3FiE84DyQvxCA0an jdZLqhk6Y/hZBpSOjrb5NtH/LUCn8/SSEQB5HTono6m1FBw8r20Q18+fTmU9sPGMtHyr gelWcJZttUAKTEUlZDv33bDwBz9U3X1b3g1rZ+aDDKjrm97/fI/bNPxIKUSS3JvAWkaB sP+jHMsJjUKiGdr4M2DJ8LGpt9rXdiTiRHM1CoFziG7GhKxnK1Jh1cGA5xfs0eTjh6T6 CBFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=90PclZH5smGZrRUKyhlf4EA2JpBj5eesUZ1CnMBH5tI=; b=uYT5sz9LwhFVmmNGYf2/NY4W5xZN98wUgiwfUkMsP08a0hxJ4aK7lsuj+QVSNU+xk3 Rt0xLU2qq7Xmpnz3/4utqlxIQrkZErhPt0fnualRC4cdogPsMOVRJ2JcjP7owzcKUX37 NjLTNhufjhtxtI4EltAijXjBw2e1huj4p08PtdBG02xReXFSIv0rYh41dyhifyPOXebD VRF7ji3M24DjuF2TZFhdMMSvPb/CTMFwPFCFzI3ouslIsZtFczg3agLjIIJ8Wcnq9ALu 8jdsYpGHksnOUPPBS2Xx1Neak9c9JNCfRdXG+5AZ5GH+trnMsq79hdlXEqZV0KP7WMjK a9aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=yicUr3AL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb2-20020a170907924200b0087bd3430c13si1711710ejb.359.2023.02.02.21.03.48; Thu, 02 Feb 2023 21:04:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=yicUr3AL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbjBCFCy (ORCPT + 99 others); Fri, 3 Feb 2023 00:02:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230144AbjBCFCg (ORCPT ); Fri, 3 Feb 2023 00:02:36 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B154E74C2B for ; Thu, 2 Feb 2023 21:02:30 -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 3130OA8A005801; Fri, 3 Feb 2023 05:02:26 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=90PclZH5smGZrRUKyhlf4EA2JpBj5eesUZ1CnMBH5tI=; b=yicUr3ALVdRQNK/1M8HYhVSra/F7w6MGWZCHgzRSiszChFeCBvbYExVek3rQHyHHQzff 0kvsu/EvyuibJOY6kBPEWPq0RfyxXH1vSXegyteQsCsecDRKApyvHJdU7EwnPVp40/bu xt47dM3uMKDXpURNUzRl/MEo5POy7Lra3DF4x4dhAnf1FaMKlacVTGUXZoITDSQNcfUh XZX6GY212Eou9LX4wbRZDyRRuelw/ZXtBW127QxdmhmI/XRk43cGYzl8Rn3+iJX5oLNS EwgY7B9roGRpUVkmNXjtQBNaKDZu/Itx/IDEMgkJmroMb6qdVQ6ziLDWgQDb8645Dzda YQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfkfe4wxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 Feb 2023 05:02:26 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31340RuP006053; Fri, 3 Feb 2023 05:02:25 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct5a2tm8-5; Fri, 03 Feb 2023 05:02:25 +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 v3 4/6] vdpa: validate device feature provisioning against supported class Date: Thu, 2 Feb 2023 21:02:01 -0800 Message-Id: <1675400523-12519-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675400523-12519-1-git-send-email-si-wei.liu@oracle.com> References: <1675400523-12519-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-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030044 X-Proofpoint-GUID: cINSHcYYRUl5v3yBw4llRx1HaIZyOQZN X-Proofpoint-ORIG-GUID: cINSHcYYRUl5v3yBw4llRx1HaIZyOQZN X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756784915579491380?= X-GMAIL-MSGID: =?utf-8?q?1756784915579491380?= 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 | 61 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1eba978..4aa2160 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; } +static u64 vdpa_mgmtdev_get_classes(const struct vdpa_mgmt_dev *mdev, + unsigned int *nclasses) +{ + u64 supported_classes = 0; + unsigned int n = 0; + int i = 0; + + while (mdev->id_table[i].device) { + if (mdev->id_table[i].device <= 63) { + supported_classes |= BIT_ULL(mdev->id_table[i].device); + n++; + } + i++; + } + if (nclasses) + *nclasses = n; + + return supported_classes; +} + static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *msg, u32 portid, u32 seq, int flags) { - u64 supported_classes = 0; void *hdr; - int i = 0; int err; hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags, VDPA_CMD_MGMTDEV_NEW); @@ -475,14 +493,9 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m if (err) goto msg_err; - while (mdev->id_table[i].device) { - if (mdev->id_table[i].device <= 63) - supported_classes |= 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 = -EMSGSIZE; goto msg_err; } @@ -566,13 +579,25 @@ static int vdpa_nl_cmd_mgmtdev_get_doit(struct sk_buff *skb, struct genl_info *i BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) | \ BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) +/* + * Bitmask for all per-device features: feature bits VIRTIO_TRANSPORT_F_START + * through VIRTIO_TRANSPORT_F_END are unset, i.e. 0xfffffc000fffffff for + * all 64bit features. If the features are extended beyond 64 bits, or new + * "holes" are reserved for other type of features than per-device, this + * macro would have to be updated. + */ +#define VIRTIO_DEVICE_F_MASK (~0ULL << (VIRTIO_TRANSPORT_F_END + 1) | \ + ((1ULL << VIRTIO_TRANSPORT_F_START) - 1)) + static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info) { struct vdpa_dev_set_config config = {}; struct nlattr **nl_attrs = info->attrs; struct vdpa_mgmt_dev *mdev; + unsigned int ncls = 0; const u8 *macaddr; const char *name; + u64 classes; int err = 0; if (!info->attrs[VDPA_ATTR_DEV_NAME]) @@ -649,6 +674,24 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i goto err; } + classes = 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 = -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 specified are ambiguous"); + err = -EINVAL; + goto err; + } + err = mdev->ops->dev_add(mdev, name, &config); err: up_write(&vdpa_dev_lock); From patchwork Fri Feb 3 05:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 52310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp649662wrn; Thu, 2 Feb 2023 21:06:47 -0800 (PST) X-Google-Smtp-Source: AK7set9902RaiEJkbEDmtWiURzCidtu/Jh2zo+mGdpCIiNYlIY3L9R8cpKM90jj6Q9FclapybDKa X-Received: by 2002:a17:907:c78a:b0:878:7349:5ce6 with SMTP id tz10-20020a170907c78a00b0087873495ce6mr10049912ejc.71.1675400807333; Thu, 02 Feb 2023 21:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675400807; cv=none; d=google.com; s=arc-20160816; b=EZQutY7Gg7bDC8N0UAibdTDtodk5ewoN3SPo8McNeyXlexXLuiCB9JpvVY8rGnaHZW k404b0Qbkzr1m1sjlvBKM5IYZpO1n5bH1QyAKF86m4YXmecUfTDJD2fZAymvnR3cDMz/ NuWz4iCWlhBX43TsZUWeOpJ4IzIbO5qy5+rGTHS5vCH7pnTbOiuR4kIIgJeXu/zg04CG 2CPpMtNhSLWYZGcGPmrSc8SqrEOXhKZzUhLH0ouSjr05aUBVtnOKB6j5ZaUdCs0S76FH qt+EMpF5ZT3keEodEkRSJgSR1WER4lfnJEUKeqNZZAAAq6KVe8OhgYsOibo3WQyAe+4c 96xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=EAIkrvgOSInyby1SydfKYi7b+/iUp1Fgo8LJ0wjyTXo=; b=IEFsRKAJeezjgXVhc5cZR+6JXrKkRj578vtFFmN1IdU9Rqhja6s/L/ETh/C+f4Ims9 m3B45fTvQXU3dM2G+eYzrYUnoaWioWs6iIPQdF3yxV6bXccLt75ukXpzbBpcYPjymXmO aDHaTiagYhNsp+04m3JrlWx/iScyPpHIHzmTDldcL4Oq1g2xrEAHlBjISwVJLFfNqZqB qdomJCL/bIELaDvxSnP8a/+UhRXcZKRgGt7qy0geoY8lO0Xag+INpldN+V/pzG2S+yjK QHRQf5FDr3cZVmg3qxO6G029BeDA/VSfP/DcxkKzdBVVETRJIoBgU4RlBpi7Io/4VzlB F+Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=sbckgEXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 18-20020a170906001200b00864aa239277si2158253eja.896.2023.02.02.21.06.23; Thu, 02 Feb 2023 21:06:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=sbckgEXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbjBCFDW (ORCPT + 99 others); Fri, 3 Feb 2023 00:03:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231185AbjBCFCj (ORCPT ); Fri, 3 Feb 2023 00:02:39 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E67F74C03 for ; Thu, 2 Feb 2023 21:02:32 -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 3130O26s005762; Fri, 3 Feb 2023 05:02:27 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=EAIkrvgOSInyby1SydfKYi7b+/iUp1Fgo8LJ0wjyTXo=; b=sbckgEXlCfS+AtaDIYm78KncHEA68C0WAKQdH/DVVIdUQkpr+I+YaRmnW8sbO2lY38OX k9aLTks84outovHRAGUx3PSW3DRJoaZvTCUr9jbssV/Ga2UJ3BIXdvxYJH32UZn1z3fr GwD53eNgHnstJV4UDqcACdtV4WKLrTXPqbPNLQM0haWBdCgBNdMrbg8Kw/e77oQ6zT25 871yJFra2IaSORyM0Zhgdn7o3Cw836ZR/sHXsYpcn+ubno/Aepi0Y/QMunUR7ycpkg0M 5ghCmB1exuCxGVtMnyBVmsKX/T15pXyv0fLS1s+gf/mIYp+1734s8iohjhM9frppBd0I vA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfkfe4wxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 Feb 2023 05:02:27 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31340RuQ006053; Fri, 3 Feb 2023 05:02:26 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct5a2tm8-6; Fri, 03 Feb 2023 05:02:26 +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 v3 5/6] vdpa/mlx5: conditionally show MTU and STATUS in config space Date: Thu, 2 Feb 2023 21:02:02 -0800 Message-Id: <1675400523-12519-6-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675400523-12519-1-git-send-email-si-wei.liu@oracle.com> References: <1675400523-12519-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-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030044 X-Proofpoint-GUID: DnnmqFI2u_S88diulMEjDHhehVM337lr X-Proofpoint-ORIG-GUID: DnnmqFI2u_S88diulMEjDHhehVM337lr X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756785076805895594?= X-GMAIL-MSGID: =?utf-8?q?1756785076805895594?= 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 Reviewed-by: Eli Cohen --- 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..867ac18 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, unsigned long event, void *p struct mlx5_vdpa_wq_ent *wqent; if (event == 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; } - err = query_mtu(mdev, &mtu); - if (err) - goto err_alloc; + if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_MTU)) { + err = query_mtu(mdev, &mtu); + if (err) + goto err_alloc; - ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); + ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); + } - if (get_link_state(mvdev)) - ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); - else - ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP); + if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { + if (get_link_state(mvdev)) + ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); + else + ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP); + } if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN); From patchwork Fri Feb 3 05:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 52308 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp649342wrn; Thu, 2 Feb 2023 21:05:48 -0800 (PST) X-Google-Smtp-Source: AK7set/rvuf/0i3NNV8qzVnrU6xaK7WueDOppPxRmkUXu4e8mIy5i3fKwUr77UV15ZLU6tppuMfV X-Received: by 2002:a05:6402:144:b0:4a0:e10d:fc0b with SMTP id s4-20020a056402014400b004a0e10dfc0bmr8444775edu.35.1675400747909; Thu, 02 Feb 2023 21:05:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675400747; cv=none; d=google.com; s=arc-20160816; b=zGtscLHOpSUDyaNwxmln62emiSKvoZMMSqmEp+4tRFgS0WzqT4+2Lq+yodhGBDqbo/ NGvBl5nucYVr0wtS1QIoUb0zyV651NuJwRWH1NJIuxNWa1KgHz40HwYeZQ4uXPyil9Qe ObYfJE+D8JJWJ4kMW/c0OyMQ5uIjUTNQBFPar6yQxKTAWFgNSrxYWYqMlki80RR3mqYE /H7IPCa7TaZyJSeE+Eq8FXjuAtLWZXum51adJoN7XjJVIxomX3b5edHsJtsGncZcv6e2 I6BJcghiDv1XWDEhCzmmBiFoerlv3BwBroFjFNRHveegKzW68s/uzrAteNqpjtmyqflc dtnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=bzsrikSqzLTTwIke+OEYxq9wDoMZGz3PJ1oVwfZNlY8=; b=cw9TslTYROQwbTRDfDhDKK7vpeprubnYj2HaadfGCvH8k06q9GdZSZsYYr/OgHp4ZV LBi7o9DdkrBvrzwImzhzi3yigwWo1PIEdL6VxGGbprP7zf59ohOqXL0Thp0ftHQH59EL QPjA1FQo2yV2ra2DzPFXdXNy8S76ChshgSG7GTbqlV0vNR+z+HM7TcJ3LtqD/tGKj77s qSPqIbXp7w9BgnPgoikdy/FS+0G+71U9bY7cAAhI/mM0p6Tc6F+NFk8N0V+nCHXmdH+u pvn6H2DYqnWfGg4tpqSTO1KVgdnVEYH8RUBBWQkkuksxsiivBS2zr407lVtYRlxjl4j2 iv4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=mrQPzX4C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i40-20020a0564020f2800b004a2758d0cc5si1815176eda.226.2023.02.02.21.05.24; Thu, 02 Feb 2023 21:05:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=mrQPzX4C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231778AbjBCFDE (ORCPT + 99 others); Fri, 3 Feb 2023 00:03:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjBCFCg (ORCPT ); Fri, 3 Feb 2023 00:02:36 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1975975198 for ; Thu, 2 Feb 2023 21:02:32 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3130NouX028457; Fri, 3 Feb 2023 05:02:28 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=bzsrikSqzLTTwIke+OEYxq9wDoMZGz3PJ1oVwfZNlY8=; b=mrQPzX4C57ipC/iqNHmn+oxbYELZO+vw/8K7RVN/Sit/vFJdMMW+RzPKXWJDOELQVz2Q perC+istTVuAy87UGlPqskEs6KfsO/me7etUTi1Cg/raEN4mYHom1fcwY+HrSSgEBvwn n/vYCajpbOTxxXsThC1Pk4njzvb/6DbqbtVU1a4JP1mfaMytQB/Eny21V9VGawCU3BW6 qbiX0RGRwdSC3yyxPgtIEnGAvYOvBYNJYZPF/KNozZ5qWYCWyz0BKgwnLGhgN2W9YJYw DXCOt1PI2yGd9Qrt8YjXpKMftoHyRiZsAYIR3RZd7TK+/XFC75cRiy1bUh1irvi2vEhc nQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfn9ymrqv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 Feb 2023 05:02:28 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31340RuS006053; Fri, 3 Feb 2023 05:02:27 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct5a2tm8-7; Fri, 03 Feb 2023 05:02:27 +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 v3 6/6] vdpa/mlx5: support device features provisioning Date: Thu, 2 Feb 2023 21:02:03 -0800 Message-Id: <1675400523-12519-7-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675400523-12519-1-git-send-email-si-wei.liu@oracle.com> References: <1675400523-12519-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-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030044 X-Proofpoint-ORIG-GUID: yu7w6tjNpRwxa1xpimgSykgZOpVcw94Q X-Proofpoint-GUID: yu7w6tjNpRwxa1xpimgSykgZOpVcw94Q X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756785014529679847?= X-GMAIL-MSGID: =?utf-8?q?1756785014529679847?= 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 CTRL_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 0x300020000 # vdpa dev config show vdpa1: negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM Signed-off-by: Si-Wei Liu Reviewed-by: Eli Cohen --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 53 +++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 867ac18..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_dev *mdev) mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_STATUS); mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MTU); mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_CTRL_VLAN); + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MAC); 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; mdev = mgtdev->madev->mdev; + device_features = 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 with features 0x%llx\n", + add_config->device_features, device_features); + return -EINVAL; + } + device_features &= 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); - ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features; ndev->mvdev.max_vqs = max_vqs; mvdev = &ndev->mvdev; mvdev->mdev = mdev; @@ -3120,7 +3139,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, goto err_alloc; } - if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_MTU)) { + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) { err = query_mtu(mdev, &mtu); if (err) goto err_alloc; @@ -3128,7 +3147,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); } - if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { if (get_link_state(mvdev)) ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); else @@ -3137,7 +3156,9 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, 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_MAC */ + } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0 || + device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { err = 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 = mlx5_mpfs_add_mac(pfmdev, config->mac); if (err) goto err_alloc; - - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_MAC); + } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 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 &= ~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 = -EINVAL; + goto err_alloc; } - config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); + if (device_features & BIT_ULL(VIRTIO_NET_F_MQ)) + config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); + + ndev->mvdev.mlx_features = device_features; mvdev->vdev.dma_dev = &mdev->pdev->dev; err = mlx5_vdpa_alloc_resources(&ndev->mvdev); if (err) @@ -3249,7 +3285,8 @@ static int mlx5v_probe(struct auxiliary_device *adev, mgtdev->mgtdev.id_table = id_table; mgtdev->mgtdev.config_attr_mask = 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 = MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues) + 1; mgtdev->mgtdev.supported_features = get_supported_features(mdev);