From patchwork Mon Jan 30 20:30:38 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: 50500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2409996wrn; Mon, 30 Jan 2023 13:42:42 -0800 (PST) X-Google-Smtp-Source: AK7set9DQe9xX3QyOY33OfqAaEUEeY86InX+k42wfTeEy3IGX3oFtc/KQUE/7K7z3H9Tkcx5ZjmO X-Received: by 2002:a05:6402:360c:b0:4a0:c3f7:69c3 with SMTP id el12-20020a056402360c00b004a0c3f769c3mr20341184edb.29.1675114962077; Mon, 30 Jan 2023 13:42:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675114962; cv=none; d=google.com; s=arc-20160816; b=ksC7D2gMqSD/aOV2YwlEO+wCKmmUfb/OyHMZl7gIkOFGNP+CjAZwuVEwI/JYQTNh/f FkVc40TX2KNLtB61cQ+hePrBNz19kbHfSSefZ6QJ8sSJ2+MkKfv0FH61iQPgOJQJvZnl DDKAY/V0VJnl4FIMEeyOpynjhZ0XiRUrbkV2aBkOsEAoGsGQVf3G9cjdH6CipkOmzL2F z46L4mgFRBY8VSp7za3nGIGaNOQFTMKyYYC2okzvM9E9ExnuB1bEmCOV1QoTfVwnCewO e4mWBaaCfmIq/vaSOlxKind9oA4/UxeA55LKrEJKortndJPuvsUZfDlw5YUtvnMPbDN9 STqw== 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=lhju0h1EUcbyeuEdq4L/s7NYTb+ohRxWDG90UlxolsRZT5jZyFR/WDGmKFxEXV+25K ZoHlNmwx920VwRHIjKt52H3r0m2m3RYM/2E3lnDff1pntITnEkmwkj1vYBru46ZrDufU 7WQxhQlQbf/J+pdlMKW4DcExdMHwrngKOqZEXMp+WkTM/tks4hYcQAO2q3ubGvBaXYDL fjkkz6+VPyOnwOxUP2M5qdrMm6iy96JtbodWwblzHYvyo5jPbha0/9kYnYt3TxT6dO0d o0NewKxf7nMHUVLYPDI2F422hfe9g6VSainwAt8SJXSzSlIn0ztNvBIpPsZVgCI3s1tP udsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=Fc5Uuejz; 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 j6-20020a170906534600b008775fc70980si15433819ejo.776.2023.01.30.13.42.18; Mon, 30 Jan 2023 13:42:42 -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=Fc5Uuejz; 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 S231287AbjA3Vhc (ORCPT + 99 others); Mon, 30 Jan 2023 16:37:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbjA3Vh1 (ORCPT ); Mon, 30 Jan 2023 16:37:27 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B82A54684 for ; Mon, 30 Jan 2023 13:37: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 30UL4C0q002941; Mon, 30 Jan 2023 21:37:20 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=Fc5UuejzyKX1eulxJRQ7C9Wis7E4mq8OmR8nQDUIh42m7yiEt9nOqtpW4qAVELT1TuF8 gpJ9ybT/1+4L+33e+aI3S2l+pISkzP0PCaW0DANsHTV4ZxcnJ2y2u3k8NPcRQdaofSdp Qpku9cZvN3lCH0pBK2OA+IFyROasPpGCGbHEN7Y2aT03jpCZILqJctgPVX8jg5yXAkom vEFdu/XDALyxrTPhmRsP+u/NScWSUHUynzTYY5zvr2fGIz8RbrBH0Hw/JvxVY9yhJnSP 1hNAQroFMNlezqQbwQdEZW+/2g0xfDUvVF4hwStVXG3jCvSUBtKMTKlzCrxGWorAADvd Nw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvr8m3mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 21:37:20 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UK8hpx031798; Mon, 30 Jan 2023 21:37:20 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct54qa7f-2; Mon, 30 Jan 2023 21:37:19 +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: Mon, 30 Jan 2023 12:30:38 -0800 Message-Id: <1675110643-28143-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675110643-28143-1-git-send-email-si-wei.liu@oracle.com> References: <1675110643-28143-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-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300200 X-Proofpoint-GUID: tIB-dZhbioWU-kwptlMYpbIIVMNWrE4D X-Proofpoint-ORIG-GUID: tIB-dZhbioWU-kwptlMYpbIIVMNWrE4D 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?1756485346788013239?= X-GMAIL-MSGID: =?utf-8?q?1756485346788013239?= 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 Mon Jan 30 20:30:39 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: 50508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2410424wrn; Mon, 30 Jan 2023 13:43:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXsgDiu4f0wKv+mLaLYgqHWPvCDw/hYcwdfE/bfiOojr6RZgfeiSK2VajoATv2e7L/NWlkR3 X-Received: by 2002:a17:906:7050:b0:872:b17a:9b59 with SMTP id r16-20020a170906705000b00872b17a9b59mr51969072ejj.38.1675115036564; Mon, 30 Jan 2023 13:43:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675115036; cv=none; d=google.com; s=arc-20160816; b=PGPJbxFOzK+Zj2o4ifVz6q4sSXzZbEx/u0TPP7rlIRxhj9mnzW0YZH7bQRP2cWiDzK QlT0PyxNd8YxkIFcnRSnXe1GK9LyQsNC+wB/zzUk3M0hFuCm1WWazKae5JZcv/qN8sa7 skFQPWk1upBlKvgPKh78UmDxrPvBNTrI3475VQWVMvdV6vZT8ErVTy6LfCBpCVXYxaO5 +WMEy1pAlIKH7pD34R8sYJvrchEwqdRxKxDBZg7b9ey/CrrynpF91rqLlkcynneQaeh1 SJLwBV7xEqfrLCcekpn/0vVzFpXSv+bs5Ltg+yKMOZhFP+yGeVsCpHyzDWleiv1a52JU f31Q== 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=oM2N8xdFor5Trczgs+SyvmEojwQcreQjgBRXOOUjpH5TQea/YLR+jwMkYIX/SHawJy yCGTDuyRrSMDDrbDwE/Oj/RTaFfkAsrwEuZXKtDre1a/s6acdYEatTJk93lprCTz+N8B Py8n+7h46b1o8HrNTIjXFZjHEoVq1nEASM/VWpAOI4vFj6ybWufalYN9TVvoGnKF7dnL VNTBMjwv3XfOk5tdNHXcWdbGkuwLVJhdfad4i6vDCTlq2MN7wiKhBGJjT1gW2irQIDrC UoGD8QPSBF+rDge1FAM8i4JPgnQv/L1qa1FWMB4Jt6OHiRezZDDuQqnTUqAFJjQtARvo awIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=a1xcZxUU; 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 fk25-20020a056402399900b0049d3f37b767si15523701edb.268.2023.01.30.13.43.33; Mon, 30 Jan 2023 13:43: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=a1xcZxUU; 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 S230502AbjA3Vh3 (ORCPT + 99 others); Mon, 30 Jan 2023 16:37:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbjA3Vh1 (ORCPT ); Mon, 30 Jan 2023 16:37:27 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DFE35B9B for ; Mon, 30 Jan 2023 13:37:26 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30UL3pq0014361; Mon, 30 Jan 2023 21:37: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=uNARmj9DqSK4eCVCfxVvrQGxRGB/k+87LR5p1WvHgfk=; b=a1xcZxUUX4B1CUwszH/kqhkAjo3TarhMHYY22BWP4RhXBWDhdGcsUsBmrPItxik70Pqw oKC/vjAXoGEP8MP8+OBFMuWrzd86xZ61Ep5CiG4+cYsyd/9I/MsFunHnqfHVXo1zkmpN 9vlrWx4FODotvqtp/GZqla2RaOhd28HhSbR2Qiq/crGXaPSuLFvE54us4HpuH2RD4t7w Nujs7GdTbmNu8qFmyh/h42IvJuVTgI2UFLJsM3LC0KmhGLutuLPwsmV0jwz68GbT6PjM ojrp381PeFnTLEBF2OyKJ9qt2TWjHtjqOa5rIz/z9bDar9lHlWmpPloC/+qeP+l9asR3 Mg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvmhm28h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 21:37:21 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UK8hq0031798; Mon, 30 Jan 2023 21:37:20 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct54qa7f-3; Mon, 30 Jan 2023 21:37: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 2/6] vdpa: conditionally read STATUS in config space Date: Mon, 30 Jan 2023 12:30:39 -0800 Message-Id: <1675110643-28143-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675110643-28143-1-git-send-email-si-wei.liu@oracle.com> References: <1675110643-28143-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-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300200 X-Proofpoint-ORIG-GUID: 3ltj96ZDoRqd1SzWA8vopKolyb1VRO1F X-Proofpoint-GUID: 3ltj96ZDoRqd1SzWA8vopKolyb1VRO1F 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?1756485424349538699?= X-GMAIL-MSGID: =?utf-8?q?1756485424349538699?= 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: 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 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 Mon Jan 30 20:30:40 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: 50509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2410435wrn; Mon, 30 Jan 2023 13:43:58 -0800 (PST) X-Google-Smtp-Source: AK7set+UAYvu8lbtkcwbOyOnLFAbqIP7rPRxfv+/OXwwZOHaAiYKO49/g+JCa+oqLBaW1d7S3uOH X-Received: by 2002:a17:906:741:b0:87b:d3b3:94e9 with SMTP id z1-20020a170906074100b0087bd3b394e9mr14151878ejb.0.1675115038592; Mon, 30 Jan 2023 13:43:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675115038; cv=none; d=google.com; s=arc-20160816; b=zuxV7hqysfrd038cVO20me4jwRZZ+umGmq6cXxZsFpTeGiluP0KfEE0cJ8Dx7Qq/3b bjiLH/M3MCSI12TTUfTvWoEtC8qHQ6jEeBBb5aPoNJxyi1HgD8SzvaKlYV7131Dv8YRQ Rk0VpahhJKriub9cpRtwpQeIwKB2+gsNI9Lua16n8DrKxUDsVufmDOD9zIBZzxilc3uT J6Hs3JQljPZwLOv+RWN+/YX2lK9OEqBtTk3aU2mFYjmFqyrdm+rmsICyq/BaK4HAgPu1 KkbACXuFN74WU+kPhEnD+5x+rk73sowPlQMQ8m3EDfYTjucjDgVSR7nR5TApDqU8vOMO YL/g== 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=RN+UDy72HyBgJmHopDa7fQXA712fWArOTdIHCED6FlQ5flAckaBXHpLeRIflZxMgJD Q2snliKFNazQZNE/Wt30nEBU0JoEV8Ajlg93A0/9pOxmFrffmpBaS2qK1eAPGCJYRE1K deqHs3Z48NIxlXWmytE1zR+eOXgg7hYOcgp2knyJzMpc/SP/LroPrl/qx03wzssJvzOS wWlBRz6Uady6QS8DrCKLD4VTUa4yr7yiNNsFG/ZESuJ092SjFdlS5MuAsBd07skmX0Iq +02B7M/t3LCv2a+frhOzJiOqEJT193oiGKEd0TYHmV0K9V7I+lNFrdTuCaTsqImUMtGl MF1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=TbYhdL+i; 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 v7-20020aa7d807000000b0049e62402a6dsi16884144edq.41.2023.01.30.13.43.35; Mon, 30 Jan 2023 13:43:58 -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=TbYhdL+i; 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 S231283AbjA3Vhe (ORCPT + 99 others); Mon, 30 Jan 2023 16:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbjA3Vh1 (ORCPT ); Mon, 30 Jan 2023 16:37:27 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEFB835B0 for ; Mon, 30 Jan 2023 13:37:26 -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 30UL4N7p011380; Mon, 30 Jan 2023 21:37: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=fSu5LWhVuNzoustkxj8evl70EvKqh8oxSx7hEUWRRQk=; b=TbYhdL+iF5svJwfI1BM4C2JvHv87iIkiCAS/DowJkZLBPwdPw7WZgjZGLu4hu0dOt9m+ TnM0UH11OX1dzI/wams8lHSsWM8gQzSPpHuekqo6sc/B+iA4J5AtKQSkbI4afLEgrpw3 KZJ9BlgKMLfnEzJt9uMmq+/je27RntxJ61R6X6Z+oNN4gtnKayvjrqV6W1jVU7mbAV7G +EPIR6iiRD548qtQyohVlmhX3cSWiwYf+MDLLhWVcEoFPhvCuv0QQ9sa6er30H+/kdvP vu5PArK9QacyyJWz4DEdzEt9/5d5MTUBamBw41e8MdgAxNVlQXMl/L3WR2h/zSuUm3b9 oA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvq9m3x2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 21:37:22 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UK8hq1031798; Mon, 30 Jan 2023 21:37:21 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct54qa7f-4; Mon, 30 Jan 2023 21:37: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 3/6] vdpa: validate provisioned device features against specified attribute Date: Mon, 30 Jan 2023 12:30:40 -0800 Message-Id: <1675110643-28143-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675110643-28143-1-git-send-email-si-wei.liu@oracle.com> References: <1675110643-28143-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-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300200 X-Proofpoint-ORIG-GUID: gPS2wF2If1QoNG-JfcE7Ytne3-fWHdYV X-Proofpoint-GUID: gPS2wF2If1QoNG-JfcE7Ytne3-fWHdYV 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?1756485426745003232?= X-GMAIL-MSGID: =?utf-8?q?1756485426745003232?= 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 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 Mon Jan 30 20:30:41 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: 50502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2410057wrn; Mon, 30 Jan 2023 13:42:52 -0800 (PST) X-Google-Smtp-Source: AK7set+HXNimyc8UHGs0t61uuFa5QxvO7DwS0YuDNrYhYhxPQl/wwAIRhDhoisGCWW3Wct5bRY97 X-Received: by 2002:a17:906:d8c4:b0:87f:546d:7cb5 with SMTP id re4-20020a170906d8c400b0087f546d7cb5mr12312983ejb.37.1675114972392; Mon, 30 Jan 2023 13:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675114972; cv=none; d=google.com; s=arc-20160816; b=cJcyNFz2fsAUm8jEletWFBdf0ubrVrGT1GyyuZi+mZUhqC3aVAWaFaTQpJOqpKV60Q v/RBfSriZV3NQIfUbQvtOPgTL1Hyy7xhbPyPtpmCbV2PQUpZp+HS6LwZZQFcSkQ2W9cO LIgzjZihmhRf/EV7nz6HDBm0JAirj9uiNEL6TH912IDOx3a4CBzBCe+ajOWNzZWtybU0 a5oIV/y4khVUS7UJ6oUr6D2b7qCxeN0BGvTPqpAojigKm3YV+gkFV8SqsfhMXXzb3z7r UtkAvWCf+KqygHtpIuH7eIH7TxlZJoQ34Wh6jCdqzGV0qTJghB0r0G7H7OvGOZW7hSBG 5w5Q== 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=YnvZyA4+ET9j3YpuVfXt+WyGrPQ1Xu3klxbgh0cNAvcgmcpE50yKsHGPi5PnZf2Wjv 0tQrYIVyTRPn4ScC7ExLs4w2FKawpipAOYiP8RCc1mC9yLI5jvkVMFih7btOHb0U/20x HmBsM9W6B5Bv3QFu11AskXR/Zr7iB14MASLMLrqCpq8qAP8O8GxBkI8YEpOB3oXpuRkU 5oYL9j30MbO3KUxlG5gX6iaH7KLvf1yGWiopVkNTsIFHYqLEDb+Dd+lVbFrYX+9V9I4o xjhQgJeK1fj3l77qZJZPL8ztmqcMENrxivNaqHM8MhEyKPQSyEJAHBZr1c70INRw+Hp7 VP9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=iewcRZoL; 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 n26-20020a17090673da00b0084d33614fd0si16133837ejl.784.2023.01.30.13.42.28; Mon, 30 Jan 2023 13:42: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=iewcRZoL; 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 S231386AbjA3Vhl (ORCPT + 99 others); Mon, 30 Jan 2023 16:37:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjA3Vhc (ORCPT ); Mon, 30 Jan 2023 16:37:32 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B1C32E6B for ; Mon, 30 Jan 2023 13:37:31 -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 30UL3uD8004244; Mon, 30 Jan 2023 21:37: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=t7qcF4HWMxrV8l58tGxaDXS4xRP41Hcy7/t+u7kgys0=; b=iewcRZoL3kDhtcYYGSJ66GY8hW1qFJYpuZeLttuXAPc6MFcHtlS0nhgQxAok5BSMRyUE y3eiPgiax8qh6oD3w1aW8xpFet3Qg8UOFjU+QSVM26NTBkWOxcbBdO3w2sbWW5topVrD zSW7pwhtfIBjaLPsbfaC+mM6RoT5k0ZdcHaksS1N+NaEkZmcLPFlfTTtbbtZKAXzYWYo p4S6hEX0tBNiWzNqBG5ANGpBbtw/ZPTvJGCNyX3nm+C+xtE7r7cQ3/FlCXrD7Bypb7Zn 517u8JXEayV5B/JSp7W4ApipT3IHEgYKbCCingNLEXa31DrqQqO16UErKkO+xxU2JTki eA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvqwv3gj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 21:37:23 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UK8hq2031798; Mon, 30 Jan 2023 21:37:22 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct54qa7f-5; Mon, 30 Jan 2023 21:37: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 4/6] virtio: VIRTIO_DEVICE_F_MASK for all per-device features Date: Mon, 30 Jan 2023 12:30:41 -0800 Message-Id: <1675110643-28143-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675110643-28143-1-git-send-email-si-wei.liu@oracle.com> References: <1675110643-28143-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-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300200 X-Proofpoint-ORIG-GUID: t9Q0xg6tFlNqxE9pU81AP5Q1c_F5cLIM X-Proofpoint-GUID: t9Q0xg6tFlNqxE9pU81AP5Q1c_F5cLIM 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?1756485357086237346?= X-GMAIL-MSGID: =?utf-8?q?1756485357086237346?= 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 Mon Jan 30 20:30:42 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: 50504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2410160wrn; Mon, 30 Jan 2023 13:43:13 -0800 (PST) X-Google-Smtp-Source: AK7set9Dui2aKaN9Go+6VxIDat/6aqNTrrZEF/Wwy7HMhxZcIgrufBlGvQSVs0EDuBdxQzRiefGp X-Received: by 2002:a05:6402:1d8b:b0:4a2:3371:cb82 with SMTP id dk11-20020a0564021d8b00b004a23371cb82mr9358501edb.18.1675114992831; Mon, 30 Jan 2023 13:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675114992; cv=none; d=google.com; s=arc-20160816; b=wl+6749jjMrVHc7InL+qDgB9vITf17dhIor0LyPJPsPBqxCfh1HWND6pB5UBr9X26b QZBMq3kfnIuQspX9StXBmxH+zOrplWdkCiOhRcsKS6N+Qf0921c8VnnEGGl91Nsj6zul iUouz5uQDSEa/z8NyoJ0GwyJEz6rpaK0G2nPl9kPCDA4uAXdNyWGiKdWDOZml0zvFP6k fX9ONuOmtpzrLqBApRfPb/2YpFlBXd/90ZRoBdj3iE5Uq9lX9mkUeqoJwCtYlvNg8xK4 Ot88oCQnO20r24SIBRAmHxadJf7GhDO99xLs1/6kb1ADmbxvdDsEsvUwWfIWiXhWAbwH MseA== 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=yYrytxe+2n5jVdHCZDLhdmxhhn5658clDrxjSJpWDNfRlSF89HAj3CP+7X/NmbWLl6 w4bjdyVnvBeT2XEYwz97HqtfO+mMV1r7gQMJnWd+HoAS6We0pTNqkrlCSdZDMlXUvEyY 38TgJ4wH9SpQc63u5AKUr1y5EW+8gZAi4F95E+s/31PHhB6DDX7f6ZBnqq29EwiRi9Fp JLK0rMO0DdaFpM8CbCLOOWd7+L20MK9UrLM5ssbEtk50hGydUZajReD2c7mmoFa82Gc3 3z5j+bwkqTnRULAEFIpSPcgEtWuPqq+XgZQTSDodEi13HYOXUXPaoOoaAOCND6Tzhxz5 RTpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=WPW8FArF; 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 u4-20020a05640207c400b0049e1d359ae5si16985579edy.4.2023.01.30.13.42.49; Mon, 30 Jan 2023 13:43:12 -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=WPW8FArF; 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 S231331AbjA3Vhg (ORCPT + 99 others); Mon, 30 Jan 2023 16:37:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbjA3Vh3 (ORCPT ); Mon, 30 Jan 2023 16:37:29 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BC1435B0 for ; Mon, 30 Jan 2023 13:37:29 -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 30UL3rF3010564; Mon, 30 Jan 2023 21:37:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=QOmgHByRE9rxe9H6Awf2sGRk9/4W2KF7M1XIRh/aqzs=; b=WPW8FArF4BiRXbQBaxwN9chZPQos3A3KTIV8hcpYTAWbThIRgjimErwl6TYo7nZpnv/x pwKSMgXuPe2zVt+/mybtZgFLIAJGgvNZ1SFalFqZ6Owzs3gI1f5ZNit8wzcI7M+xwA+5 WjW/ZOBlfHqH33pbHiGP096KYfaDCx/YSR0qRMiOxTesO8ULlIMSk8jy9STEaokeZa13 iwTAJpu/hMhMH//lyq1sXSpGPqFG6rD6MUqNW0D174qfFrSDfllpqpJDz4CHwYSnwNOu HTumgEbozoi3TU1q3dpPIqww/kw7m+j97P+sSSs+LYjbAbo7qTzH+PKIr43Fo7RTkXK2 Tg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvrjv1w6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 21:37:24 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UK8hq3031798; Mon, 30 Jan 2023 21:37:23 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct54qa7f-6; Mon, 30 Jan 2023 21:37: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 5/6] vdpa: validate device feature provisioning against supported class Date: Mon, 30 Jan 2023 12:30:42 -0800 Message-Id: <1675110643-28143-6-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675110643-28143-1-git-send-email-si-wei.liu@oracle.com> References: <1675110643-28143-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-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300200 X-Proofpoint-GUID: 7zrxmWaF4b0rhv8LZ6ryazEQ9FuokYf6 X-Proofpoint-ORIG-GUID: 7zrxmWaF4b0rhv8LZ6ryazEQ9FuokYf6 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?1756485379023668917?= X-GMAIL-MSGID: =?utf-8?q?1756485379023668917?= 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 Mon Jan 30 20:30:43 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: 50501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2410037wrn; Mon, 30 Jan 2023 13:42:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXsai5pFXt44pErNNc8dL6DyvL3rZN2aVoxg1QBJQq3KiPOlEdCqpN/cEq0dvS0+XlOPb/Ec X-Received: by 2002:a05:6402:5110:b0:49d:fff2:d4d7 with SMTP id m16-20020a056402511000b0049dfff2d4d7mr70824473edd.30.1675114969187; Mon, 30 Jan 2023 13:42:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675114969; cv=none; d=google.com; s=arc-20160816; b=McYJFNwz/nYMRM/wxT1DLGLd/yAXBWhcpfoZ5uvcm5O0BnCIGTXWIMPZZcRvpUF5sv p5K4+TWxJNyXvQlNPlgD/5LvdKyj3P216aFR35SEe5GC8rIlTa0R2WYvNM29GOjgXgTc N3wm8KN2x8WQjp9Y6YEGBlbDD/8YKUDXLaZU5OV0I6IiZSHUc37NCvRnu8QdY84Yn6s3 hO6zQyfUN0e9hOrlnFzSwWy/3/GgMN+VoDMrSlzRQFa8DtJD1YvVna9MYborWVA+Nzz2 Po9dkzPgG35ZswH2YTuX3qSu8OV1zPd5xIkiH4rcyNXQoPodvZ/Vi4zXxTAz1elmRgI6 cVug== 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=sP3tTbhTOkye0mv3KSMC7Zqeg0EbHNGBivr0GK+rxa9JtOVXnMnTEfnhGc58j9lT4E S79ju8Pl4VaMZImtabsYUUSseNfGm/bQNjTPH35RsIMD8I15fBfxC9lbgD9gCQhfbsQd fgW9MTOnZjPiCnOKlxo7VX8Xcn8uQWqTWtJgLvj8XNCQ64trZ0g6ftCjmYlTOeHe2Dzh GDeSIbizCe8cjNr5gbAHDDgfjI21VzgbjPmqxNenkIsb89Imvmbds9aa0TQg+fJL2ZXS HBP2pCMLpyEaCnoa9AEqWqEXSITcxKEYP8XfwnksMRXxUZD3nWOYSboJlR/N5AbvMm7f C6Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=2EH6BXEE; 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 k18-20020a056402049200b004a08f3af297si13821860edv.277.2023.01.30.13.42.25; Mon, 30 Jan 2023 13:42:49 -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=2EH6BXEE; 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 S231338AbjA3Vhj (ORCPT + 99 others); Mon, 30 Jan 2023 16:37:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbjA3Vhb (ORCPT ); Mon, 30 Jan 2023 16:37:31 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E2EF35B0 for ; Mon, 30 Jan 2023 13:37:30 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30UL3kwK024697; Mon, 30 Jan 2023 21:37: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=jnAUD/EC5w/xiEdrQsRdwdzongF+OKWzxhSqAJOtUs8=; b=2EH6BXEEAM4IPLe2pCf4jpEELVO19QnZkUUUJGvbi3plajY5YzLn/GQa4JLWaXRNokR2 4Gkx+DcqCVrKk2Q5dkazhcmGY9WRuXkHlwv/JbXJrPVpn2F3+nXIFrUycJAsU2qugLLu xCRlzax1Zw/a822knkZrefRaYtElsKGvjEiU7XdhOnw63F4CCyAoUvXn0NMwIlmpciL7 6Ycip/DvZdzTrP/WwuOwgGFIGmdAO0noBedFqaKzbpgZto98dKZ1YXz9mIn+izFvpu97 s6O49HrrS0b4gsfwJ4B1ynZLQYUQpdTfr76hXcbBCSQQACx1Jlj7EgvIOr6fYC4KNJgq uw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvn9v2bx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 21:37:25 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UK8hq4031798; Mon, 30 Jan 2023 21:37:24 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nct54qa7f-7; Mon, 30 Jan 2023 21:37: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 6/6] vdpa/mlx5: support device features provisioning Date: Mon, 30 Jan 2023 12:30:43 -0800 Message-Id: <1675110643-28143-7-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675110643-28143-1-git-send-email-si-wei.liu@oracle.com> References: <1675110643-28143-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-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300200 X-Proofpoint-GUID: jd0OxAs6Hp7U268Eir-UTQTDSzwW7BDZ X-Proofpoint-ORIG-GUID: jd0OxAs6Hp7U268Eir-UTQTDSzwW7BDZ 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?1756485354035674074?= X-GMAIL-MSGID: =?utf-8?q?1756485354035674074?= 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);