From patchwork Mon Feb 6 23:07:55 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: 53546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2514390wrn; Mon, 6 Feb 2023 15:10:24 -0800 (PST) X-Google-Smtp-Source: AK7set/2TvpkAC+sY2wy77ARc1DrTHuj4p2t1zsu1fWQOpAlhOU92MBttfib2z4xCrhUcE5YErCW X-Received: by 2002:a05:6a20:1444:b0:bc:ec65:a73f with SMTP id a4-20020a056a20144400b000bcec65a73fmr1103156pzi.58.1675725024029; Mon, 06 Feb 2023 15:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725024; cv=none; d=google.com; s=arc-20160816; b=AUkp7OKVPlhyrwPIpg0U5H+gWvAEk9tr1LKgVLnF5l6pUWvHzrAnfiL2DUntip8DOc hdYVSh1LOvfkzB0PmbafTS/KFTkDlV9mTitjbQ4QNVXjDSD8COqA+ctu6/jDi8d2Q6Lx sSM7hzdi6+mJUaImsSXr1frfzADkeYRZYjG9mwB7T61CbAhhAzaMFCH//LEMEji0s4aM 1WYKkDdzwvWiZCY/gZcyyDj9zFv+J1HwJ0UgKLVCQFqboKxiKulqgnmYYYcU5Xv+oMvx Mc9/Ni6wlw7A+tSofbMyNkImWjJIDIaUJ7mT8upg/d/2De1yzG8aBdJyiF353lbGIPOi ckzw== 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=tuNvVHwc3+Dm80SEhxuy+f0EmMpFr/j+KqRE+d6N+2YRkyGWKG33KaceUReJJ/zWkr pqwIRZOgJ7EwLQpVBnwQEjfcy4WCTzysUznr6CeWVe8PFjJodtBIogR/AnLyzLywQDXu m6R5VZmtEtABc50tn8Z793MsWzGJwAVTqSRSUa+uQwNlaZB8Xw72il/pSVIkxD88QtZC v4XDE0zAuZgU+nFspe2JEha/cqz2EQTqMshOx0oUzhhrSj0F+Et/P93ugdLtNDU7I3Nh d11uWLhAxP61M+2qsGtb2N5PDbVdtN+SCzML0t5+wVFlOiFv25tCLeLRthQKBKCzdzIF D9gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=qwwhdXQd; 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 e13-20020a62aa0d000000b005906af305c5si13058051pff.39.2023.02.06.15.10.09; Mon, 06 Feb 2023 15:10:24 -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=qwwhdXQd; 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 S230321AbjBFXJA (ORCPT + 99 others); Mon, 6 Feb 2023 18:09:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230237AbjBFXIs (ORCPT ); Mon, 6 Feb 2023 18:08:48 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4AC832E4C for ; Mon, 6 Feb 2023 15:08:25 -0800 (PST) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 316KECEt024746; Mon, 6 Feb 2023 23:08:21 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=qwwhdXQdZXD7FMgnNscW+P863qCVCOh6tvRjiV04MQPunqc9lj5Jhx9v0NO1nRcuMobU hWqi3wN+fEBca8diO/AofPibovmbC7EZQGsI6JPJudatoILZHMXSmYkIrjCjEI9i4DQl 94t1c9+qeLB0G87hiKd+GHDRVue5X/ByGnMvpD4Eh/fhIIwGtbo3I5p2jz6ndQPO+7fU 8IiNKiFCpRYHGP7VMJjaEv1477sfeAaySkYhmJociEKFHsVNN8MMM/tIPA/xYZmhvP2x D/YBD4jBDWwn+6ay2mgDNN+6X1vwYcOcC/3/Ze+2LFH0Z4wB0AcJ+T4hTnBwv6vt8ijF /g== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhf8a458p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:08:21 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LbeUJ040865; Mon, 6 Feb 2023 23:08:20 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nhdtb99m7-2; Mon, 06 Feb 2023 23:08:20 +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: Mon, 6 Feb 2023 15:07:55 -0800 Message-Id: <1675724880-7216-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675724880-7216-1-git-send-email-si-wei.liu@oracle.com> References: <1675724880-7216-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-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-ORIG-GUID: jc3UYtVBS5crri5Ryl2hBVF1nOIRFXDi X-Proofpoint-GUID: jc3UYtVBS5crri5Ryl2hBVF1nOIRFXDi 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?1757125042696741947?= X-GMAIL-MSGID: =?utf-8?q?1757125042696741947?= 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 Mon Feb 6 23:07:56 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: 53547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2514461wrn; Mon, 6 Feb 2023 15:10:34 -0800 (PST) X-Google-Smtp-Source: AK7set9F90Wlc8wjzbD4qtaQjyhx2uQaOVzfY9qNZ0Lmn6KVEVIFVNwqYGN55Ogkd4PwdcPh/sef X-Received: by 2002:a05:6a20:4422:b0:be:9893:fd82 with SMTP id ce34-20020a056a20442200b000be9893fd82mr1358295pzb.23.1675725034329; Mon, 06 Feb 2023 15:10:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725034; cv=none; d=google.com; s=arc-20160816; b=rsVRlSgS3OcAWtr9fOupx53xOVlz7xTjwlQfl7UGKYxQSMrm/Zaxqfk4+WB1RwTqp7 m/CFR3mLTsrbMNse+ViKa/n+QKlEEReEEfXOFcHuVmIy6LYU30s4qYp9aM058Y35nOzk BMonauNGIIPBijsL4CwHY7kg/pUVgpPGkfKLpE7UHfyzBAfTrxRRN2AuP2Y1VUlc2lsw Y620yu0HS602NCByQqk1bKPrLESZ8eMnRpw1EVxVm6wmIscZcBEprv1tn2UwMtUsI1w0 SFsiDdD1MXxyMMvRN7WJbzmZnDWxAUD9songCvom31t2ahK35Ucw6Ih4HjUo3uL0Qgn6 /yJA== 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=Qu7xVQBjH3QyINlgGCfvRYdJpf2OQd6ZDfiujBCmENo=; b=D41H3QiPMzE0+5pyrE2jBEIUWorTfoEzwjBHd2Mi1Rq3j/iGIBcNF4lASf4e/0eUOo i5dXRRkVyOlKk/OvJFuMICt57G75ieldegC2LTAM6e9jmlwxTNzviqeR0HPgDNOAjxlW UMIAl5+CrwKU7uiUhAgWBm5C4nq+6+RJ+fz1ou+vU/CWYBLTCA79sBISc+9ysvfkGyeH Z9WxalRfbBizH6QD1wmDpKjQBgqg9c0T97j3ECnForsizYQB2lMMEZzgSqbtAX0ZVo7X lE+I3k/jePHzjvp9nPRBseg8dzXnqXPZrSW8vsBQp1HmVoZCKa+Z6Sqk80R67MHxu0KA N37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=jwjdbVup; 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 g2-20020aa79dc2000000b0058b9025bd61si12753382pfq.53.2023.02.06.15.10.21; Mon, 06 Feb 2023 15:10: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=jwjdbVup; 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 S230121AbjBFXJC (ORCPT + 99 others); Mon, 6 Feb 2023 18:09:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjBFXIs (ORCPT ); Mon, 6 Feb 2023 18:08:48 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D503032518 for ; Mon, 6 Feb 2023 15:08:25 -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 316KE2cp029642; Mon, 6 Feb 2023 23:08:21 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=Qu7xVQBjH3QyINlgGCfvRYdJpf2OQd6ZDfiujBCmENo=; b=jwjdbVupt1DL9lAebZ6X95nhiRPZrkyLLP2z4h7GZLKmuHV8OR/PEBLfT2pZgY3vI+R0 lrXGjBxK9fGxAgbPudJD5Ks1TufABcWSDHVHOxyfD42btIXwwDtBrr5B3fhTFE5+vF11 FS0G0werPDjvwAs410Vz36IfVVmxWDsSQsvAQ7UqKdRo5r3+acVMFElOPB98kAWWMqjc IfOBD3smi1558c8iOohyLD4+HLsl/SKVI5u6swNPkkSYK33OQpHq5GYDW2B7mjpwJvrk 2tz/EmWSLbXwhwPEGu/QVDHIX8CRX08oPFaWrKpx6OGgN9HG+pdsCGiC2ycoiYIrCdxF QQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhdsdm92w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:08:21 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LbeUK040865; Mon, 6 Feb 2023 23:08:20 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nhdtb99m7-3; Mon, 06 Feb 2023 23:08:20 +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: Mon, 6 Feb 2023 15:07:56 -0800 Message-Id: <1675724880-7216-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675724880-7216-1-git-send-email-si-wei.liu@oracle.com> References: <1675724880-7216-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-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-ORIG-GUID: EnboAqUy1AWuiPc9-H8a8pgd6zaWJ0To X-Proofpoint-GUID: EnboAqUy1AWuiPc9-H8a8pgd6zaWJ0To 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?1757125053254039637?= X-GMAIL-MSGID: =?utf-8?q?1757125053254039637?= 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 Mon Feb 6 23:07:57 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: 53548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2514493wrn; Mon, 6 Feb 2023 15:10:39 -0800 (PST) X-Google-Smtp-Source: AK7set96WF7tgKeAU/YHGq5+UJ0q06axSKRtBwbq0ku2Sz6HnTRr/ikCHVk6VWqF3ayV4yWSlCfC X-Received: by 2002:a17:90b:1e4d:b0:22c:b496:88e with SMTP id pi13-20020a17090b1e4d00b0022cb496088emr1532714pjb.12.1675725039017; Mon, 06 Feb 2023 15:10:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725038; cv=none; d=google.com; s=arc-20160816; b=v7PFdQ57m+hfh7P+pZfbsqDmE/Esw0tG+7/NpwWWqe2xjfjI2CriwFVnJDOQGrZZY5 arBLL5I2f3mgeyAfI90DNyKgDk4zNR5Q9rYfnYn9X40I8C/CQgjrurvboIO0Xr3OPACH TDw7OXOWu6Pu+IqeFYSEjeAXRbrR/VIMfwsdKs9NeGs6MAb6GUZDpPIEFOxzS1JFEGXy XcxSXLmsR1haVBFn8jR0W6Pjdz1mgkB2+15HdSZ40uuT1z4UmCoFjLBEwVGzPc54TYIp TORn778YTdUrQlsNpxivsidCl1CTXwhGuYlEiy0j4TYQRVZtOjiPeWUXPAXqHacD+HtR uGHg== 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=0CriircPtC5ExQ5QJKfnKlayKOe8WG6ZDKh8VqSRLTw=; b=GfFIWXPtzjWbNaa7hyuvm8NkOmhQq6zG5Zrc/8bfT/Cve7ml91XkGsdNVPKarefuRT tNqOX/FvApZI+j3Bkt3c7oggUBDdwluZaZP3YOhfpM+AEdApNWvJuxpBrxHa2EwqR4b7 D1lbgVDuxodzBOGCyJiGx4bIilBX5wiwxFQdDuIGiAjQFduXatPyFkAtpH6A/hpjy+KK ykXKqGP9LAVIxAe2o6gMUsIz0TSCv/Oy4Pr+CMaPTITgl2b5tZ1HIr7kaZoEeK2O6BU4 cyR5A+lPGCZ2e2sFADz3fF8ZfLyJH0HXj85N6AA4zh1zaDYmTg5GgAmJXb0urapF9CoY SBAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=c42TLK9z; 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 q44-20020a17090a17af00b002307e81266bsi12388019pja.118.2023.02.06.15.10.26; Mon, 06 Feb 2023 15:10:38 -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=c42TLK9z; 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 S230240AbjBFXJG (ORCPT + 99 others); Mon, 6 Feb 2023 18:09:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjBFXIs (ORCPT ); Mon, 6 Feb 2023 18:08:48 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6138C32E5A for ; Mon, 6 Feb 2023 15:08:26 -0800 (PST) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 316KDrxR022748; Mon, 6 Feb 2023 23:08:21 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=0CriircPtC5ExQ5QJKfnKlayKOe8WG6ZDKh8VqSRLTw=; b=c42TLK9zAy5cH9RVcQ1WiD+YsAeZg4kqZvgt5KSATvuQIzJplBAW1dCbFg0MucMN2Jx8 La7z1NvnfC+p9hEbp/6TCAUsR542KvW7h8WZntKfrhUvS6TP3Sr8Z5joU30ixcAEFFr5 f0vPcb8mgWGnM8N5SFQSKoenC62av67uhWka9famS7bAXRkm0Yx77ah6+BiJlnAlZn41 utF224U82cTEMgeiqQ016vNpMIm0iY49oAM1nlZLKhRXrGBYdKji7ixj3ewL7yEyFunk IJesq0g2YP2BXEoweEuk+i5G+UuYrvcVFRoZMSzYImdKmZfMcW0JJSjMDWUkRL8CkicK 9A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhfdcc7yp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:08:21 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LbeUL040865; Mon, 6 Feb 2023 23:08:20 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nhdtb99m7-4; Mon, 06 Feb 2023 23:08:20 +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: Mon, 6 Feb 2023 15:07:57 -0800 Message-Id: <1675724880-7216-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675724880-7216-1-git-send-email-si-wei.liu@oracle.com> References: <1675724880-7216-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-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-GUID: sRrFU8Bv-7TT4wizrpanzkwostdS30vE X-Proofpoint-ORIG-GUID: sRrFU8Bv-7TT4wizrpanzkwostdS30vE 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?1757125058342902413?= X-GMAIL-MSGID: =?utf-8?q?1757125058342902413?= 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 Mon Feb 6 23:07: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: 53549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2514610wrn; Mon, 6 Feb 2023 15:10:57 -0800 (PST) X-Google-Smtp-Source: AK7set/4f8XIjp/b71yRJFlfIzYUK8SmZAJDLcOlg6hJDNgbBx6dvnxZSEISEFMiOwPcLvfqrhNL X-Received: by 2002:a17:902:dac8:b0:198:f1d0:f9f2 with SMTP id q8-20020a170902dac800b00198f1d0f9f2mr710768plx.61.1675725056988; Mon, 06 Feb 2023 15:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725056; cv=none; d=google.com; s=arc-20160816; b=g4iJv0t0mds8ar6y0XNuWXl4Wu5biT/beHfMNKEwyClWl5iliqYRwJZQUftBM5dksD U4BjM3PfN5v5oovTjcEJrz/lYfwuOXvHHXYdq9iwW+dGT38NQAp++FZg03o4rfNcwiHh ZEuNv3bFcjcf1+YK9DYH056+ln68HGnz7yls4L2Qd9TOjElP4r0Ew5ZNcHl8A6TaJ1LT +CfppLHsBAh9je/hjgTxoX1j55iJdNA82Iz44HBsnan/16+xeXIqTbSAPFrGB/ol3dnn ves0adXEWlfXwF/iWnfZ1ogQeWbvJwaiFhKpMIg4VNZBvkTZ4B9QguZofbPIrvjYtMYZ CIEg== 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=d3JugFvzxOjps33xev2euAm7g4qNmWk7oY4Vz08lzVM=; b=CR95tfP0aZMW1RZrO8+Zr5cN0GlEvlKZrkPQ0soYBpXcx/56kjuF8ku2IFlEVmwRCa sWzFfAjAq9XuMQNi0yRJG71Bu5sy/1kOEgQCwYM6aNKJXpjpmyaWU+9UomOLDrG8CL4H NUWMI938IDogxJH2U703uCW/fXV+9EF76gHHIChNE87qYmFJM8NeK25WJUxac3BHv0Tv WkLpzv+fFpdFeFmSZYklobuI0mgVSeY1dHvC6tUWpDtmnfRWFcndUHElF06RjPj7x0+q l0OgcA3y10HLHXDRQ9/RvH+CpZ8DRIDFn9UDvjFDXrqERrIMxzDpx+LNUC8o0Jr29HKG S4jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b="ihlmU/NY"; 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 a7-20020a170902ecc700b00198df327f0esi11853734plh.314.2023.02.06.15.10.44; Mon, 06 Feb 2023 15:10:56 -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="ihlmU/NY"; 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 S230136AbjBFXJL (ORCPT + 99 others); Mon, 6 Feb 2023 18:09:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjBFXIx (ORCPT ); Mon, 6 Feb 2023 18:08:53 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB8F432502 for ; Mon, 6 Feb 2023 15:08:26 -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 316KEHnU009025; Mon, 6 Feb 2023 23:08: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=d3JugFvzxOjps33xev2euAm7g4qNmWk7oY4Vz08lzVM=; b=ihlmU/NY9OGsyvGAYPPFILw6XvknbadZmcGNTcDaQ1Oj7hbpe8SduKV4177sTH/jxjqh VoejgoZLRAB1Znw38ZLL9AeTZAhK/q+nh8mEfFwfufE7ox/IGmU0VxSkLbOPn7BScCbm LfYQ95g5uFVR8Z0XTpLdJsxpR1Yw1UAzOmM1sNqgrQYhgNZX401yzxHdKnqTs8DH3Ymz JmLRFvOZWYsMs2K/JtKmQpmLRSLRQ0en2ADr/6D+KiQbuNxgnNMYfPqPlM2Ez2CZVg4o PSnv31PulHWL+ugQMLjyH4Jfh7/d6bwJX40MfZq8hu0ydfdWwFunpc9mRy+jSXscoJ4a ZQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhe9nc6cv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:08:22 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LbeUM040865; Mon, 6 Feb 2023 23:08:21 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nhdtb99m7-5; Mon, 06 Feb 2023 23:08:21 +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: Mon, 6 Feb 2023 15:07:58 -0800 Message-Id: <1675724880-7216-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675724880-7216-1-git-send-email-si-wei.liu@oracle.com> References: <1675724880-7216-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-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-ORIG-GUID: iWFrxHEx4hm5fSuG5CKTktHBfuddtAVG X-Proofpoint-GUID: iWFrxHEx4hm5fSuG5CKTktHBfuddtAVG 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?1757125077257973951?= X-GMAIL-MSGID: =?utf-8?q?1757125077257973951?= Today when device features are explicitly provisioned, the features user supplied may contain device class specific features that are not supported by the parent management device. On the other hand, when parent management 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 | 59 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1eba978..8da5120 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -460,12 +460,28 @@ 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; + + for (int i = 0; mdev->id_table[i].device; i++) { + if (mdev->id_table[i].device > 63) + continue; + supported_classes |= BIT_ULL(mdev->id_table[i].device); + n++; + } + 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 +491,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 +577,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 +672,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 Mon Feb 6 23:07: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: 53551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2514865wrn; Mon, 6 Feb 2023 15:11:32 -0800 (PST) X-Google-Smtp-Source: AK7set8QhNdpAM3yK8xfjhwOhTsLAOmBW5Dflz/98MjMb4de155h+Qso5uAUruIuQcn9Z34G8H0W X-Received: by 2002:a17:902:e2d3:b0:194:afe4:3011 with SMTP id l19-20020a170902e2d300b00194afe43011mr495158plc.52.1675725092215; Mon, 06 Feb 2023 15:11:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725092; cv=none; d=google.com; s=arc-20160816; b=GwlyPh9ySXru0Ypw8UqaIx5jJMlQTMqarmxtqh/kR9grUEwjE7eRVrCgLEcs46BCOF NjSSlFPETNWQ7JnmVFvGl6SJkq0cAugqOnEjCbOqYHkQnuJ2tY/AmJ5ZeV3K5ktr5+D/ TTfdqUiA1iwsa22Pe7B6P/UTHUuOIzlzTiV+jfmrsyzyVDZUMYr7k8XiqfA21h7+Z+R2 271ho2GuYJKsXWcr7ZpovyGAOlQzBj9EMUEsb3Y1gRXAeXl92wu2LBJtbeYJOazd/0J/ rUAGWYOAXbAtivlAEcq4j/2KB43p50gU4MhswQBZNgqRD2hShevGMu1oFduMzsbjImU6 YpqA== 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=JJWHSduRoQrbMlgcL9i/NZDlDLMD04ksn4nHHzB3RNE=; b=j8Wnln+euhnXSeGxeAg8UTkHBu33kbJSTKwMcURFoV0hkDRIFfeqA71WCQegRp8ItX hMl0BfcJ3HV5Y/kyESyx4p8aYC3VM8C2PqNZ+SzbG8dXyA/aVQTbfAg3vK2/f70kYqcH 5qHV05GuZNX3yP8hHNEhYJNOejDVVwwDwh8xk2ndY04YalvOe2h9PYfB4kyNKvV7/Oj6 W4ysizEDlBTF6MSv+hKwwBFE2AjnVTjEOk5HROOwTl4rwkmykH5BhXe4P9eEQqalmcvC LtQcFv3sRS4J41VY117N5ohoc67Ho8fCr+ZgU45qfcCJpRIk9W7yDGa4V65RsXCytRd0 5juQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=R2GTMnyQ; 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 t6-20020a170902bc4600b00188ef2314acsi12273090plz.527.2023.02.06.15.11.19; Mon, 06 Feb 2023 15:11:32 -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=R2GTMnyQ; 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 S229990AbjBFXJd (ORCPT + 99 others); Mon, 6 Feb 2023 18:09:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjBFXIz (ORCPT ); Mon, 6 Feb 2023 18:08:55 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7EE132E6F for ; Mon, 6 Feb 2023 15:08: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 316KDoUk031601; Mon, 6 Feb 2023 23:08:22 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=JJWHSduRoQrbMlgcL9i/NZDlDLMD04ksn4nHHzB3RNE=; b=R2GTMnyQTVl4LgV4fJBaG8PBz/V9NYNP/BLeiTAmjtZxt6bZ6FPh2FZEhPUlRAzMO7SH rIq3z6tmR77eRB55VlI8lDqhQiWH/17MkKZr2FQFzpGX0vPpckXueSw7oKpA1F8hRNkk AQVwYsaTeyVsobO2YOrQ65nJZzExvqMLobFFmj5iaDn+mmr39ijD/u6CXAnYkgzWnOK/ y8Xs2zbZ8QHVzvrSdKu+e964+0g1uIdTbV8RO5QoN8cmvTZfm7ybGjC9R0s37gtDsWw/ StjvdfsvkOdOE5DIdFAY1OiOFIewdJY8FVbOkH72DztBNkl4YXr/yH0BMGSlFOc2ViyU 7A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhe53c8a6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:08:22 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LbeUN040865; Mon, 6 Feb 2023 23:08:21 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nhdtb99m7-6; Mon, 06 Feb 2023 23:08:21 +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: make MTU/STATUS presence conditional on feature bits Date: Mon, 6 Feb 2023 15:07:59 -0800 Message-Id: <1675724880-7216-6-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675724880-7216-1-git-send-email-si-wei.liu@oracle.com> References: <1675724880-7216-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-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-ORIG-GUID: FSoQbLt5vBBRTi94mhaFCetKyraoJHPu X-Proofpoint-GUID: FSoQbLt5vBBRTi94mhaFCetKyraoJHPu 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?1757125114319947605?= X-GMAIL-MSGID: =?utf-8?q?1757125114319947605?= 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 present 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 Mon Feb 6 23:08: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: 53550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2514783wrn; Mon, 6 Feb 2023 15:11:22 -0800 (PST) X-Google-Smtp-Source: AK7set9ihjqnYB0Qw5LsnZM5klF7zaZDkYdu4Hzl6AdL4U9RIw7ROyJl9alVbKE+7qerMxAh4Mvn X-Received: by 2002:a17:902:e3c4:b0:199:1804:246e with SMTP id r4-20020a170902e3c400b001991804246emr453668ple.41.1675725082147; Mon, 06 Feb 2023 15:11:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725082; cv=none; d=google.com; s=arc-20160816; b=EDNgKsKCETe65eQt1wUPRyEcOrDGV8cxTkdZktE0vOnKcLG/t0B5Z28X530ArbjDDd MKd/IsVM+y601hwjTNyuLCgYT38AYb+pM4AJRIF/0awrqrK975VRtilEtFZuDpEzfMxZ g6ng4Yi+2JVz5VP/w14KZX0AEisSE3utiTmF6xf5zmj6fYkw5rv/t2NwABhtWGMNpj05 N8dcVN5GRr7kxTpESHyyKdp6R4FXLzLCS0Kfuyk6aonOvh75d2D4xyHnGKp1h7ZtrWAG Z85enFtRHRZMASBQ8rigDfQbntXedywOxjKfuIKo5EtvsrcLtoDmrltQHXba0Xmv1UPX wvzQ== 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=9jOxWRKfGQrPvyThoIL2nkqwCTwWn4JHfQboUAfZaXU=; b=tDJObt6TyA36d+TCkLtLH6B52UpzecgdFoIloSWQ5BldiDxJeD+I2EkJu8HCdH1PXl 4fDo9w0L7aT+ErfI9S3fn31GqXP5g/1+m7D+h4WHOnv6pZ20C7KfTtbiXXqIbDFnmzqo NlJnypt1rwQjxbzatx+TbADFuhJR5crjOSJE3+eOh2BBLUbnsQZz81El9t8TdJDkEVS1 S3c8ValribEKGyjKjOqdB3BLFDMFUOkPOr7Q96xLkd0ijekgCzcLFD5/s0TK60ZXq5oE KYlHmWbUvHvyiwmI3DvKWyffPVBMqG4Rb26yMiLNvZUavjzTTiLsT0TSBdxMgHSwoCob MRqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=kwvLN6Ad; 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 i10-20020a17090332ca00b001992e74d05csi300839plr.29.2023.02.06.15.11.09; Mon, 06 Feb 2023 15:11:22 -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=kwvLN6Ad; 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 S230364AbjBFXJP (ORCPT + 99 others); Mon, 6 Feb 2023 18:09:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjBFXIx (ORCPT ); Mon, 6 Feb 2023 18:08:53 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B0632E63 for ; Mon, 6 Feb 2023 15:08: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 316KE5lo028054; Mon, 6 Feb 2023 23:08: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=9jOxWRKfGQrPvyThoIL2nkqwCTwWn4JHfQboUAfZaXU=; b=kwvLN6AdDO7d2ai9CTY6TUr9kyQGVXFTqXJcLOFOcB/F5xI6rt9B65p5axH6rNKA4uLk CK+He5Yu+RlViOcGtbjRRX2qv+ZXN6swQiBjwJB4bK3txC4RzLoHvu58YS29nz98ERAa LPaXbudwqkHW/j9jkPic5SkclkfyWnymMT+fzNTtX4UjOxrInVLAGGxh77mAu3RVtJdy i0kp8eAStoZusK4ltMvucJfvF7BdhoAT7lXhm3fMXrB+xOzpDvVS/sQZPADmKHSCogOW BZPrVcZIDWibF3jlfEvb1k5Pqr1mseP/XKZhxae3WIh1tWPEHOwHaf1xsWsjF2sAIEyA aQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhdy147ve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:08:23 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LbeUO040865; Mon, 6 Feb 2023 23:08:22 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nhdtb99m7-7; Mon, 06 Feb 2023 23:08: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 6/6] vdpa/mlx5: support device features provisioning Date: Mon, 6 Feb 2023 15:08:00 -0800 Message-Id: <1675724880-7216-7-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675724880-7216-1-git-send-email-si-wei.liu@oracle.com> References: <1675724880-7216-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-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-GUID: xp7rfTzRFBMAZ-6xtY0i0dPFeQKFAFET X-Proofpoint-ORIG-GUID: xp7rfTzRFBMAZ-6xtY0i0dPFeQKFAFET 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?1757125104036130036?= X-GMAIL-MSGID: =?utf-8?q?1757125104036130036?= 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);