From patchwork Tue Jan 31 23:22: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: 51083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp90540wrn; Tue, 31 Jan 2023 15:24:37 -0800 (PST) X-Google-Smtp-Source: AK7set8NUsYtQ0jHjRoy8dU4z9LK9I77m6LUHfn5KV+Jsh8xHcnq6GzdQX0cN9hRppsNvYrCmGts X-Received: by 2002:a17:903:124c:b0:194:d664:be3a with SMTP id u12-20020a170903124c00b00194d664be3amr953899plh.16.1675207476978; Tue, 31 Jan 2023 15:24:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207476; cv=none; d=google.com; s=arc-20160816; b=ucAg8a4HpK0lT6Bk0Wq6zLFLMg/GWQWKF0suZ5bUqYwzownRJEfM8XQ+DHD6RLLIPU NrdLZ4r0XIPm2aBabaZZJfsbbU/wgDCat98Q7rsyYOc+MTNY3N0aJ0YakzjRRN1uIHHs 1dqNC4sC3C984fuhP8ICbXdwqq8B/845v6B0xSM1Io/tYwo8mMJuKFK4cgyxLVNOfji1 PnuLg5dh8TI6QtCG7UQRyT3XKlqNEGeKG6MbsdXSG/udgGjjoaCTQrtlsduUZpsElpAe NBxX9bvoZE6uoUk2mDc0PylXlKoWJfNhMcd08S8i2xrz98muhSB/tlaZE3YUCOJoSz+B WbAQ== 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=r0Xf7HwYTIa5HdBeaweSNt2PODdB5AMoLanWqL4vsmE=; b=0UndgkuNHaA7Pjud2bMpXUOJgV2LSHP/1480zFlPDg2p0BOnpE0tft8s791OkEB6pi 30lwWj+zzEa605UJWXLBbzplu8oll6JrUyggTDVyZqccqEy+fPKubVzrwmO3q50ByzXj slbNuZXtCL8wFDripEe25zKDBtm949mURxcwJw73ZTQV2Ic4opigRaDVIdnRxsE/Erdk +1LR6jNh7enhAKkqWKTE6KMypEKw+ZCb+CKegsqun6y7hpm+GiBNS/HZ8qcH7JNsAsQJ GiJp9hwYK3sDDiegR5moKWRLn1COCFPhkQoGr8BDzTaH41IuT/VPTpUSzgLczuUoYBUy 3Qow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=BUnktRU2; 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 w15-20020a1709027b8f00b00196263e2942si16515425pll.497.2023.01.31.15.24.25; Tue, 31 Jan 2023 15:24:36 -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=BUnktRU2; 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 S232158AbjAaXWc (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjAaXWa (ORCPT ); Tue, 31 Jan 2023 18:22:30 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B6C510421 for ; Tue, 31 Jan 2023 15:22:29 -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 30VIiH7A021428; Tue, 31 Jan 2023 23:22: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=r0Xf7HwYTIa5HdBeaweSNt2PODdB5AMoLanWqL4vsmE=; b=BUnktRU2vwxC/uFjHpEvn6ISYNM1vWBs/qmac0ANisN6YzjgOuGQ1LvA3c/63h2fQ8l+ HXFba+DVS68CjBHXNkqXR1tVQ4atC3AIe3dIuU3CqFRe2vxLJlJmPxP7SVWePb1RyhMQ P7bJtVRBQjxwAr01OY8hVDqPIPp+AwyJHr3C9hibR+3rPkndTb2qiDZpAVlX+6uJw08C xOz6tsFB+X0+BiN/qxX2dGax/BbJjOGdDysiBdWkDezURD2MIfWnievjhi1BK3k8lHaD fnFILnVqej6Ww1nEIQUd2doXiGHpYHVbtI/+i0pUfme55QzczLT3A/xhamLatR12Vg2T PQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvr8q23c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:25 +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 30VMuk9L031540; Tue, 31 Jan 2023 23:22:24 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 3nct5d8c94-2; Tue, 31 Jan 2023 23:22: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 1/6] vdpa: fix improper error message when adding vdpa dev Date: Tue, 31 Jan 2023 15:22:02 -0800 Message-Id: <1675207327-22289-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: L0k5arDU938cX72WhdbrMRGjMC5w9dFr X-Proofpoint-ORIG-GUID: L0k5arDU938cX72WhdbrMRGjMC5w9dFr 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?1756582355398795927?= X-GMAIL-MSGID: =?utf-8?q?1756582355398795927?= 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. kernel answers: Operation not supported $ vdpa dev add mgmtdev vdpasim_net name vdpasim0 max_vqp 2 Error: vdpa: All provided attributes are not supported. kernel answers: Operation not supported Signed-off-by: Si-Wei Liu Acked-by: Jason Wang --- drivers/vdpa/vdpa.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 8ef7aa1..5e57935 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -622,13 +622,20 @@ 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) { + if (config.mask && (config.mask & mdev->config_attr_mask) == 0) { NL_SET_ERR_MSG_MOD(info->extack, "All provided attributes are not supported"); err = -EOPNOTSUPP; goto err; } + if ((config.mask & mdev->config_attr_mask) != config.mask) { + NL_SET_ERR_MSG_MOD(info->extack, + "Some provided attributes are not supported"); + err = -EOPNOTSUPP; + goto err; + } + err = mdev->ops->dev_add(mdev, name, &config); err: up_write(&vdpa_dev_lock); From patchwork Tue Jan 31 23:22: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: 51084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp90651wrn; Tue, 31 Jan 2023 15:24:53 -0800 (PST) X-Google-Smtp-Source: AK7set+L/XiJrYJbKJuaPaWA7ySUgqmgDM5Z7ULtyy3e5cVBfKsJiaUDPQs/+uJeYFElZcqcDaC3 X-Received: by 2002:a17:90a:53:b0:22b:e5e1:9d3 with SMTP id 19-20020a17090a005300b0022be5e109d3mr32644070pjb.25.1675207492733; Tue, 31 Jan 2023 15:24:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207492; cv=none; d=google.com; s=arc-20160816; b=IuIogFHXT/fcl2YJyeFNsFvmNzJ01zBfRRAYptV6nsl0bLY1U4NDM80vHgtn0PaTSV MH38gKOUdRAxxA0wsm8qnriFF66yYFTkVaxhDXc1346vNpKIIJZGHZC6crCTM7e7V3jL cgWKJ1fGa+QqYdSc90kJG1dPU3bwGyeHHPlFu5HbaL80TBNt9pjZqPEkpnZll26yBpmI hrxopXE7y64k9UG6gdtSJfSPKfd6KZCum/gxysSJQj0ggKE5bOUY289Y8SFHjdBW6+wm kGOZaJt6Wu/Jrs/3PZ6c1IKo8OlFI7ChFMKFxsmYIKG9WIRdmciFbbNOsYDSQQigZ1HJ hGVA== 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=uNARmj9DqSK4eCVCfxVvrQGxRGB/k+87LR5p1WvHgfk=; b=sgss+3G0Xnfu843ffK5XLYguoYZSNCyVtmi1t1Y8kB6PMb/3pBbaweLdgBt6UnfZuW BlI0ToMTRbRAT4xPZ5PljL1FPTspLw8B9Wbl46+cP3ht5TJyMKcAvoCj08bie+H8ZPsD S4MBb7Ffg5Nt92UdirtHr2NkWXBJkUnYKx9O4fyW7LpATWEK9rJq+HhVn/gK6STe+ttC TebO8YR0yvRFDvYGx6v5NHIaUUJTYm0V7RTQWk0PExyW8v/JNiJBaTKzHpDgrvltsayJ hHlPkdAgIKhoSavDf2ZKqp9QGiKcs1RneX2PLMTFh+mSMsVJbgN9ZMN9O8FtngDh+kiH 6LIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=UL8g25Tu; 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 x14-20020a17090a2b0e00b00229a752dafdsi20192210pjc.142.2023.01.31.15.24.40; Tue, 31 Jan 2023 15:24:52 -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=UL8g25Tu; 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 S232198AbjAaXWi (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbjAaXWa (ORCPT ); Tue, 31 Jan 2023 18:22:30 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03C7844A7 for ; Tue, 31 Jan 2023 15:22:30 -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 30VIi8cs006462; Tue, 31 Jan 2023 23:22: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=uNARmj9DqSK4eCVCfxVvrQGxRGB/k+87LR5p1WvHgfk=; b=UL8g25TuoC2eBTr3pfCVHsUNt0VrHPGkep1+dY5IjItWwzPIuKZT+TLsYs/9qd4DMqPD P38e1fHIIVu9D1uHBsUQcZK4MbUzrIx3cQgrMY36wn1n+fUUlpgwR1DTQxLM1P8g9GgX /Hoqfchf2Wf5hBUt5nP5j+iPEahgOxGvrkPF0hsGb8HMPWgl5PcH8Tajgw7euPFG+6vl vauLEt/BRiMJyXAkfiZKdSMP3E2DDNQqDFhXuME5kSf3VYDSGT01HVGyDsUhcIcJiQBZ fYOIMZvuRoB1SrysDi6rs8rcYj/nT1f9Mz1oQR+y9LG7OmFUfxaKH/8I5Rbsys12QT4P sQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvp171fc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:25 +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 30VMuk9M031540; Tue, 31 Jan 2023 23:22:24 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 3nct5d8c94-3; Tue, 31 Jan 2023 23:22: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 2/6] vdpa: conditionally read STATUS in config space Date: Tue, 31 Jan 2023 15:22:03 -0800 Message-Id: <1675207327-22289-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: ufcRi-sJNv1PtvmeD0N4mw-BtCCUGQvB X-Proofpoint-ORIG-GUID: ufcRi-sJNv1PtvmeD0N4mw-BtCCUGQvB 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?1756582371773248486?= X-GMAIL-MSGID: =?utf-8?q?1756582371773248486?= 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 --- 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 5e57935..5f4883b 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -848,18 +848,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, @@ -872,6 +879,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 Tue Jan 31 23:22:04 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: 51086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp90882wrn; Tue, 31 Jan 2023 15:25:24 -0800 (PST) X-Google-Smtp-Source: AK7set+TPUZ0jF2HBrn8Mfdcpi94UPwU+30/ZPFPLA5klwdUA7MPnNSbqkZslCiuYjxjmniBPYR7 X-Received: by 2002:a17:903:2444:b0:195:f06f:84ff with SMTP id l4-20020a170903244400b00195f06f84ffmr678550pls.50.1675207524437; Tue, 31 Jan 2023 15:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207524; cv=none; d=google.com; s=arc-20160816; b=ZK93ffxh4oudfvE6rncNQc4Ucz9l1AoxTHvtomco4s5KE+0dgz/3sJT+O4eMxj4Xa8 IVDV+9RB5w+Ws5I9enScXuOxQfVJggYUwsIt+QqFt576j4LeHaVyUAftIyth10SPNcQP 4H6dc1ixab8NWwUmUuc0CGQGIMjfdlsvI2OLBrh3jwCulfFs8+CpQBd2lI1HdFX2bzK+ tdNUtnTuFAjP10lyglFSkmHDC1jTBPthm7Hpm5AOomPeuUA41EKLlej0QEYHOs+DzJRX qH+FbRBpHW5fWfvQAEcWMeNDmjNiYP8bAo5BwScAcZC+PZ+piVuoJsUM5UE+FttgtQKt YeEg== 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=fSu5LWhVuNzoustkxj8evl70EvKqh8oxSx7hEUWRRQk=; b=XeMo/iJ4mp5Ze0qwSpIp+GB7OIIcl5kpp+DePpl9pb1/ReQxodEQSa6JbFlrvJdHq9 Hed8TeyrKLtV6VFV0U4ly2wUsOwLq36+19g6lWfeftH9GTRrbUCbzCjArJCCq2Pbq8sb DdpAqQFUKw++c8ZPKHiUUyyvif0dUlTPLAPzm7EyaM1HRVb8HhhcNvUS0bRIBwp91kLe kH4QlOl6yceFew41aKSXAmZF+YEg19P5a7+KvniBSa8QbLjW8qPqdRusrIjkXi3u7Q54 BjWCOCwAlEaUrmX4x/HdI9BTntpd67zdbaxEUYHzKP7ebG3ysNvzyWugoUcAr9ME4sgz 0PiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=0ExPtRLm; 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 l6-20020a63be06000000b004eca59b9530si4934516pgf.408.2023.01.31.15.25.12; Tue, 31 Jan 2023 15:25: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=0ExPtRLm; 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 S232179AbjAaXWf (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231984AbjAaXWa (ORCPT ); Tue, 31 Jan 2023 18:22:30 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044C61C58E for ; Tue, 31 Jan 2023 15:22:30 -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 30VIiaOb023158; Tue, 31 Jan 2023 23:22: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=fSu5LWhVuNzoustkxj8evl70EvKqh8oxSx7hEUWRRQk=; b=0ExPtRLmiKhNaIItJSbT6vFjcGIo88SMh7rngeffCZ/JW3hqG43634SNiI8qizSZdxsU OZ9wNWuaJI74JTu1tHHI/qA5FuOb+nd0fHq1ususznqLUzOdidbaDNBzWCp4LTrQ9c8u KE1vSGc/y5HiMb7Wue3gdzgkxoEfU8Nb7K+ZX2mRAWMjreD0usSdIjEhkUS8OnvFvXUi 8Eeb00QUPFDwpODQcGmDFYjsru1Ksrks/IFyJCMQf5/czEjO4VkfqPstYwXUjeWEXMnK Y8OA96fnpUIoJAxnhEyc5j0FtPbn9GM+cgBfA9j+P6jV5o51+0+2k5XkURH/9FDzQEO0 pw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvr8q23d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:26 +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 30VMuk9N031540; Tue, 31 Jan 2023 23:22:24 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 3nct5d8c94-4; Tue, 31 Jan 2023 23:22: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 3/6] vdpa: validate provisioned device features against specified attribute Date: Tue, 31 Jan 2023 15:22:04 -0800 Message-Id: <1675207327-22289-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: pMD_w7JHg7ix7MOYx2lRBtdLIgNKzrvr X-Proofpoint-ORIG-GUID: pMD_w7JHg7ix7MOYx2lRBtdLIgNKzrvr 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?1756582405087466372?= X-GMAIL-MSGID: =?utf-8?q?1756582405087466372?= With device feature provisioning, there's a chance for misconfiguration that the vdpa feature attribute supplied in 'vdpa dev add' command doesn't get selected on the device_features to be provisioned. For instance, when a @mac attribute is specified, the corresponding feature bit _F_MAC in device_features should be set for consistency. If there's conflict on provisioned features against the attribute, it should be treated as an error to fail the ambiguous command. Noted the opposite is not necessarily true, for e.g. it's okay to have _F_MAC set in device_features without providing a corresponding @mac attribute, in which case the vdpa vendor driver could load certain default value for attribute that is not explicitly specified. Generalize this check in vdpa core so that there's no duplicate code in each vendor driver. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 5f4883b..6d02b8c 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 Tue Jan 31 23:22:05 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: 51093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp91133wrn; Tue, 31 Jan 2023 15:25:59 -0800 (PST) X-Google-Smtp-Source: AK7set8CbckNz3fu0Pclqt7BtHrTdQg1eGynn8Ms9MtN6jKXXVxaCxjyqUqp/duhcilM45lYD6au X-Received: by 2002:a05:6a20:3d81:b0:bc:ce49:798d with SMTP id s1-20020a056a203d8100b000bcce49798dmr309499pzi.41.1675207559556; Tue, 31 Jan 2023 15:25:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207559; cv=none; d=google.com; s=arc-20160816; b=wjHD7h7HNi7WWVoAvw7b3efPSIvnWi8kxkP0vi4jfL9Q80EQtj+19t2GCSTFcE9dsj ogtNTI4JGQtTPszjStvt/h5afmI+TE1qxp5UkbbDOa3Hiil+pHMv2NJ66+OevpGl+fee 5osPsuhBxywZIzae8PNx6Em7SeMYj05zSeSZ+Hu5gOv+5dThVjlv+iBR+/Dzz4dDqvnr tkco/EU9NDtFuv/xGk3nAP70wvkVWGmNvimuedJvvoI5Mn8MH1zoZdUlaLal8z0eNoE5 IIiXRtGwjF3ftKWbU37wDNLaeUhK7Vf1TH0CfEpxQDFG7RoCyOgy0euVzZQwE7zw7Cpo fgFQ== 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=t7qcF4HWMxrV8l58tGxaDXS4xRP41Hcy7/t+u7kgys0=; b=lVn73p9nLiwlDPggewryp9MibjvH/1eRAB9anWyFdCE6wY13vX3tNh1Ndp6/7BgsJt cnyEdfavNQfrynedU+OkKS3daRuNFfUbmIPNIHeu/bNSPzNXfBn+bZz9c3OZIZDoWTou TpTjr0wDf4q+mtd+33mcMtQrSrxYe5m1mqdkcUlBsglFIHReOENIQnQdMhlucsySq3+1 eFJJTmUuN1wR9JwjRCcssapWbAZ3+AclorzfNrFJdTPO7ZhAJwWkK070jCkNr7b7nVbt FgmTVZee+D0QzPue5oc2L8FkGBcNkHTZobL9j9b+5WUwITQkDfkg2dEzrzB68X8bk8bw 5Kvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=QzGDou7I; 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 x9-20020a63aa49000000b004d21beccd9esi16393773pgo.498.2023.01.31.15.25.47; Tue, 31 Jan 2023 15:25:59 -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=QzGDou7I; 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 S232222AbjAaXWq (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232154AbjAaXWc (ORCPT ); Tue, 31 Jan 2023 18:22:32 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A2C443921 for ; Tue, 31 Jan 2023 15:22:31 -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 30VIiPux014328; Tue, 31 Jan 2023 23:22: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=t7qcF4HWMxrV8l58tGxaDXS4xRP41Hcy7/t+u7kgys0=; b=QzGDou7II+0XJobEdCfj83zwQwvrnWGS/Id+S4qyZJPuzPwGYJJ7Bl3/r28bYi3z9kar upKUUPrU7+ro+nlkeWMk7r5s8DNIwa57di4KUhbYgzXtBrGo/Xp/GzHGRz324VN/Bsen 1ncOLctbloAb8JjqTEaYXtxVAQdlzgSlIoWpkRHr44n34y1yfk+FMp9Jk7uAjd/nyqk5 l5SUu6Sw8AlvIQW4a5qX60wA7MpiFfaIsuWkhf6p2ByM0NGkf6Y9Cy1JpCMVFuNt7kHl uOfOE5Ljfg67LH6r8yr0L3NZpwWciHLFM/aCKxayhDhp/L/1AsYY4FhutAieCVqiNJ9X bg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvq9q2nc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:26 +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 30VMuk9O031540; Tue, 31 Jan 2023 23:22:25 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 3nct5d8c94-5; Tue, 31 Jan 2023 23:22: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 4/6] virtio: VIRTIO_DEVICE_F_MASK for all per-device features Date: Tue, 31 Jan 2023 15:22:05 -0800 Message-Id: <1675207327-22289-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-ORIG-GUID: DNIQ03djdSKlZsZpxmdzs4RxcmtAX4HB X-Proofpoint-GUID: DNIQ03djdSKlZsZpxmdzs4RxcmtAX4HB 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?1756582441936997821?= X-GMAIL-MSGID: =?utf-8?q?1756582441936997821?= Introduce VIRTIO_DEVICE_F_MASK bitmask used for identification of per-device features. Feature bits VIRTIO_TRANSPORT_F_START through VIRTIO_TRANSPORT_F_END are reserved for transport features hence are not counted as per-device features against the 64bit feature space. Signed-off-by: Si-Wei Liu --- include/uapi/linux/virtio_config.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h index 3c05162..3bdc7ed 100644 --- a/include/uapi/linux/virtio_config.h +++ b/include/uapi/linux/virtio_config.h @@ -54,6 +54,14 @@ #define VIRTIO_TRANSPORT_F_START 28 #define VIRTIO_TRANSPORT_F_END 41 +/* + * 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 + */ +#define VIRTIO_DEVICE_F_MASK (~0ULL << (VIRTIO_TRANSPORT_F_END + 1) | \ + ((1ULL << VIRTIO_TRANSPORT_F_START) - 1)) + #ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've * suppressed them? */ From patchwork Tue Jan 31 23:22:06 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: 51090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp91093wrn; Tue, 31 Jan 2023 15:25:53 -0800 (PST) X-Google-Smtp-Source: AK7set94JqFjpXhkiK0yjFtYZ93uWvmM5GJS5LouDFUOziuUfwD5R60ddLunwaCqeka//MP7cpEC X-Received: by 2002:a17:902:c7d1:b0:196:58de:9f29 with SMTP id r17-20020a170902c7d100b0019658de9f29mr496455pla.47.1675207553278; Tue, 31 Jan 2023 15:25:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207553; cv=none; d=google.com; s=arc-20160816; b=SuCBytcKbVXLOLY4+GTsOzKL7y1XlVXqm49AX3nGnoHJKYD9na27fkI1VAsTlF6F5B veFzt/oWN9PxgppoApKZBNtRTzvkft/EuSam1iQYZIgsHSzXVT9Qu7jhd1YALi7L7Kmr DF1DADz3a3NzI/woqFuSTaSiJoE/vQ3H5engCKW4apcLPxhb8iqG7OkTyTQ+HiNg+6UB NnTQdRYxiKac5XBcQirGp0A5Oj8Rv4/7kcvFkbqrSd9JFS4oRKPBlQbZGSdGGjYsyZ+n rc3rDPcB8jhEggaGtVfbvC1P5AMivAfqhWinaSOFiPL83PTYHSp2DZHWkz968NhVouuj Q6XQ== 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=QOmgHByRE9rxe9H6Awf2sGRk9/4W2KF7M1XIRh/aqzs=; b=cIuVg70/3trGDDSb0n8WzivnS714mZqbxYI0onLHRbY8/yEtG1GgfUVHLG+WKx3quT hfrgSeUvlzbkrY5ElekizMwI2lkGhXV/lKFdhyqSmEsabO54+cL3U8ypIsML65QojSeC kIfKhfPhCB2m0l23C1f8JlzaaSwaXhsAqOFC6U+ogF6n+e5hzcYhYMrt0uXLv0d8Enxx AVPMmcpKNfazmzo7rK8fEh/HMXMo0O22QQNVEIh5skW+fW3Wxj71OeYmza6ulZCdoEEB vbKjiL6Kajn9aCCPlRGDbf4/yKQYabp7AClAUgJivMI6ai6QZ/c+8CZwl2aPiVo/4+21 8fJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b="OtJh/ict"; 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 g3-20020a170902e38300b0019609a4f16dsi15741501ple.461.2023.01.31.15.25.40; Tue, 31 Jan 2023 15:25:53 -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="OtJh/ict"; 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 S232209AbjAaXWl (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232149AbjAaXWb (ORCPT ); Tue, 31 Jan 2023 18:22:31 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8649343921 for ; Tue, 31 Jan 2023 15:22:30 -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 30VIi9FT006492; Tue, 31 Jan 2023 23:22: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=QOmgHByRE9rxe9H6Awf2sGRk9/4W2KF7M1XIRh/aqzs=; b=OtJh/ict3SBbLHy5rJ/+Td6UziToPlpUgEQM0QB2f6VRT7T2JbNczakdGQixcYg1dxmC jREFnUpBPsvbIxD4rLWkPbZ9+PiDmm9Zj4qSNKv8m0/UNEXmi8LjOx7J7amZZnHUPxeF 83SD3r39/hXSQgJiZ/hx3SI0iU1y6T5eCH1ZudQe+J9M4OBST5UuBD00ZkFKuy04dJUI QXWUwEY/7wxUsbwU2FBxF6B+1jzQF8Uxon4LzT/AfANfxIAjMstZjboqVzqLoVCM2fAa 0/yGinf5+OuvqrFAwTPNBKfMK3rkxN2+oS8VmdU16zAkpC7Zq6x8GAyIV5XFEs6j+iGD nQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvp171fd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:27 +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 30VMuk9P031540; Tue, 31 Jan 2023 23:22:25 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 3nct5d8c94-6; Tue, 31 Jan 2023 23:22: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 5/6] vdpa: validate device feature provisioning against supported class Date: Tue, 31 Jan 2023 15:22:06 -0800 Message-Id: <1675207327-22289-6-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: agwxh2A_7qT2XRrvzD3R-OlPYLFdh22H X-Proofpoint-ORIG-GUID: agwxh2A_7qT2XRrvzD3R-OlPYLFdh22H 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?1756582435257383748?= X-GMAIL-MSGID: =?utf-8?q?1756582435257383748?= Today when device features are explicitly provisioned, the features user supplied may contain device class specific features that are not supported by the parent managment device. On the other hand, when parent managment device supports more than one class, the device features to provision may be ambiguous if none of the class specific attributes is provided at the same time. Validate these cases and prompt appropriate user errors accordingly. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 6d02b8c..d5d6729 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; } @@ -571,8 +584,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i struct vdpa_dev_set_config config = {}; 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]) @@ -654,6 +669,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 Tue Jan 31 23:22:07 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: 51088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp91039wrn; Tue, 31 Jan 2023 15:25:45 -0800 (PST) X-Google-Smtp-Source: AK7set/1zWMF4NJF6lWlNlKmI9QbJLoL2I8GqL7w4JS/Xh08XZykqosfQhDfnoPy98qzlsqPzf8s X-Received: by 2002:a05:6a20:6a82:b0:bc:a2a9:1ad with SMTP id bi2-20020a056a206a8200b000bca2a901admr351967pzb.2.1675207544969; Tue, 31 Jan 2023 15:25:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207544; cv=none; d=google.com; s=arc-20160816; b=VWmFoEoOUIqioRRFhy+D80VZWC7IZfwjLm8WsLb/G9KxSpXF6UuK70J6KmP/yFzg/Y eN/9Ya/IBByYrC7UYDOyeR6h/ePiS+FCsMtilbpEQfDvx1WopsFZbFWdDuv2Ggn/jjn1 DSKWAtAUod5LTml1APVkK4py3A/Sfsy3Z2ctipWtL3einea6WIiz+lVq+CCFZnSlg6JX aqFZx7Yd0sl3FA2ZjgjoNGU0ln+uEonYOEXDn4Hh+qgTpWfE21SpIMY1tYDrAJ1uiSia fNOiY+DvRfCbm6BieSttcJb/+6FJps6xT3RUP7ksizLsirkBi9EZ+tVxh64av4L1ytjt ob9w== 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=jnAUD/EC5w/xiEdrQsRdwdzongF+OKWzxhSqAJOtUs8=; b=X4L1yk+gyvgo6kbh3ErWXFvmr27HtrxFq+yw2bBWGwTCwtYhrUw96XC4utFC627SJG SXoYaWLLXvDj+frUaT9XfbQntyi0Gs5Rl6ZLurpOvk/j4aN8nGjoiZerycu7IypNz674 uTZ8KjL9al+zvagtYS1gqsNsubXryPFgVOd3zQVBKrVWjQbwNqQ05vPIbB1V05bGNm60 ouU8qgMMefZs2w3OZa/yKvGBU8UvQTBMQ4HwWCevDVaOgXz9FsQxnJ/alLVsQl5wSNOI RS5wN2ON8RSAseJq1lZvVfvSYSnSw70i6KNkzSd7nSVAVtn0t21o1gTGM9jfYXrCdGmc hf9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=k4nxmUPs; 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 j71-20020a636e4a000000b004eda5171960si3675611pgc.627.2023.01.31.15.25.32; Tue, 31 Jan 2023 15:25:44 -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=k4nxmUPs; 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 S231597AbjAaXWo (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjAaXWb (ORCPT ); Tue, 31 Jan 2023 18:22:31 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A05A14E525 for ; Tue, 31 Jan 2023 15:22:30 -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 30VIiA5x032540; Tue, 31 Jan 2023 23:22: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=jnAUD/EC5w/xiEdrQsRdwdzongF+OKWzxhSqAJOtUs8=; b=k4nxmUPsY14OYMqY+k4Rh1q0QiX9myC+DfgjeRLzDRPny85Z8ijqZ2KMsro/REmiNEcQ UM/TcaORZnZ1hjgI7rj7mEiaFkXDrVsNwPDiD2990sMq5BbTcey4IA41hEMbVGmv0Spi 7PeHuMkMeVa/eoSLA/gXZ/p/wx7PkYgU0584KK/6Ut0x+865oY+p1rWOJWYpw5iTOeQm B3K26tUP5JAZeLc6436tcKAX7Zf8+8+01Qx4qf0R3fMuXamtrUuHKEwUiOa5txQUc2tN NoryRCoogEVl+wnSynPpQRL1yT1wD4OwQGUU0ZagXK6mX6MNtXq1greussVLvP7LnMKG Ew== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvrjxyx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:26 +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 30VMuk9Q031540; Tue, 31 Jan 2023 23:22:26 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 3nct5d8c94-7; Tue, 31 Jan 2023 23:22: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 6/6] vdpa/mlx5: support device features provisioning Date: Tue, 31 Jan 2023 15:22:07 -0800 Message-Id: <1675207327-22289-7-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: 3tHw9Dw2hkHiQmOz6OB-1BZ0B4rRP6Sd X-Proofpoint-ORIG-GUID: 3tHw9Dw2hkHiQmOz6OB-1BZ0B4rRP6Sd 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?1756582427000719119?= X-GMAIL-MSGID: =?utf-8?q?1756582427000719119?= 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. 3) Set config space field only when the corresponding feature is provisioned. 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 --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 72 +++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 3a6dbbc6..5d6dfd2 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; } @@ -3009,6 +3010,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: @@ -3060,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; @@ -3068,6 +3072,25 @@ 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 (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES) && + !(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"); @@ -3096,7 +3119,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; @@ -3118,20 +3140,26 @@ 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 (device_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 (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 + 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); - } 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; @@ -3142,11 +3170,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) @@ -3243,7 +3286,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);