From patchwork Mon Feb 6 23:11:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 53553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515550wrn; Mon, 6 Feb 2023 15:13:01 -0800 (PST) X-Google-Smtp-Source: AK7set88/IRABhhkQdAcbPlhXQjwcPwxqawNFvfAR6iOfr5sptWxjk9mIxuy1/e3gBx3bHIbPDbV X-Received: by 2002:a17:902:e185:b0:199:2dc6:bb1d with SMTP id y5-20020a170902e18500b001992dc6bb1dmr391247pla.19.1675725181176; Mon, 06 Feb 2023 15:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725181; cv=none; d=google.com; s=arc-20160816; b=MEH5wGzzNJ9qZH30Lqy03nw2iUiAXGloZ5IqVsroiVguv6HBOzF+SmJ3pw8XsWpHkp s5Y0Y0SDDPeyVlg7VrqcIFXq+oqkOFsmUCkWCGbH111zi1ut/06fBIUVb2CzleRozoFY cjt17umauRrd+9rJdW68JkBEcTy9QMFwniD3fi5gQsFbNZBqhIZuJ1/7Gfg3ll86xg5G 6MbrZGEXTvSi6icoeTlb7Z5imxnDDnWNNBtkS+syVy9kTQYWWmv3Hky2jmljJ6eqKXBl +365aQaIdYB6KSp8GOnVEuC7J/1arYyAdtKwcGHhmn7CEq+Gb7vFVWnGaAYZcLSH+Pyo J6Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=j/lEJg/ReXobH4hd+iLRobue9kWLN1CWVWeI2l8aOjc=; b=Ogdv/R6BJZr+gAVwU0v33vVE6nlGQGNqG/7TxAV8JvX80DeTTkJX4sy3bvBb9BiYnQ h0nuxigmQ2ppa2W94AoapagoBsjMjcUm/MUma0Mq0oKgmaFJTd/JJYYfeFwGMKx5Ymz6 0y9by6cviBWV/Zk2ZvwiLJW2h5aKB1J+CFcG3Scvh8WjCxWWMM0RX2K7wFWjGebtYgBJ 9aJxZTiWk1agUTxYrna7Q7jDM4yGflfWUD15Is3HsCaVPEzTtqDehYBbo1gajwjgL1QC luwC9EQXXDxy36fXg9c2U3J+ywH31LUWR0eOeKmgFeTSCBB20k48BQ0Y66R4oYpxgsPy TKsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=WB3eTk+S; 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 i2-20020a170902c94200b0019488aa379asi13325746pla.181.2023.02.06.15.12.48; Mon, 06 Feb 2023 15:13:01 -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=WB3eTk+S; 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 S229740AbjBFXMe (ORCPT + 99 others); Mon, 6 Feb 2023 18:12:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjBFXMb (ORCPT ); Mon, 6 Feb 2023 18:12:31 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C527A5FDE for ; Mon, 6 Feb 2023 15:12: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 316KE2p5029602; Mon, 6 Feb 2023 23:12: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=j/lEJg/ReXobH4hd+iLRobue9kWLN1CWVWeI2l8aOjc=; b=WB3eTk+SgwsCzELNpHj1CqMpsrcyUnmWzL2NPge8m/zz8Gn30O/zUXzOv5wEsFFIDttU gdFWo/0idlAM9nIkaMldtqxE9VTFvy6g6OayaZ3jl7PFq7+C0FMlvrz0wDcPV84kzh0L wg7JFPko41Ty65spVCxyWrwhI/n0JuFatvmmKhc/u5YjXhUcelkOfqs3hlMn77BNE7LZ N7SLY2z2W1ZAyw6SysPRmVyyWK9kmdIP8p6G2D+ONFDAgF8Dx/jV+8kRwV7oNTwInuMQ uZ2+iMIVb3uyTpbmxst5YGM4X3/LgmXpFyzTtseqt56gH6p0qEm4N/UhuWFI0O4lK77t Jg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhdsdm98y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:12:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LpWgq021033; Mon, 6 Feb 2023 23:12:25 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nhdt4sj6f-2; Mon, 06 Feb 2023 23:12: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 RESENT v4 1/6] vdpa: fix improper error message when adding vdpa dev Date: Mon, 6 Feb 2023 15:11:59 -0800 Message-Id: <1675725124-7375-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> References: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-ORIG-GUID: NxvGEQMqPTMj-jDk_enlwONQlORkSbJd X-Proofpoint-GUID: NxvGEQMqPTMj-jDk_enlwONQlORkSbJd 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?1757125207407617035?= X-GMAIL-MSGID: =?utf-8?q?1757125207407617035?= In below example, before the fix, mtu attribute is supported by the parent mgmtdev, but the error message showing "All provided are not supported" is just misleading. $ vdpa mgmtdev show vdpasim_net: supported_classes net max_supported_vqs 3 dev_features MTU MAC CTRL_VQ CTRL_MAC_ADDR ANY_LAYOUT VERSION_1 ACCESS_PLATFORM $ vdpa dev add mgmtdev vdpasim_net name vdpasim0 mtu 5000 max_vqp 2 Error: vdpa: All provided attributes are not supported. kernel answers: Operation not supported After fix, the relevant error message will be like: $ vdpa dev add mgmtdev vdpasim_net name vdpasim0 mtu 5000 max_vqp 2 Error: vdpa: Some provided attributes are not supported: 0x1000. kernel answers: Operation not supported Fixes: d8ca2fa5be1b ("vdpa: Enable user to set mac and mtu of vdpa device") Signed-off-by: Si-Wei Liu Reviewed-by: Parav Pandit Reviewed-by: Eli Cohen --- drivers/vdpa/vdpa.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 8ef7aa1..3a82ca78 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -622,9 +622,11 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i err = PTR_ERR(mdev); goto err; } + if ((config.mask & mdev->config_attr_mask) != config.mask) { - NL_SET_ERR_MSG_MOD(info->extack, - "All provided attributes are not supported"); + NL_SET_ERR_MSG_FMT_MOD(info->extack, + "Some provided attributes are not supported: 0x%llx", + config.mask & ~mdev->config_attr_mask); err = -EOPNOTSUPP; goto err; } From patchwork Mon Feb 6 23:12:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 53552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515485wrn; Mon, 6 Feb 2023 15:12:54 -0800 (PST) X-Google-Smtp-Source: AK7set893eqLWiwcaw+J1+FeycMVoj+oS51QHmDT2Ac1QDvbkFqqrrapmYv0hsY3UB6RaVCsEdPI X-Received: by 2002:a17:902:9a45:b0:198:f1c4:dd5a with SMTP id x5-20020a1709029a4500b00198f1c4dd5amr523203plv.17.1675725173738; Mon, 06 Feb 2023 15:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725173; cv=none; d=google.com; s=arc-20160816; b=zoVK5Z/LO4upvAB91hvOQLMl3TMIP227sxwkZDgssvl30eOUIjW/kbYUmN2J2Dy1yi q1sokijhThmGYVqvkSocW+ye5Rp03CLOlXDFCL5rn95KfWN3csFlHdoU7haM5SKKPMaj efBgzEyG9Tos03JyTIn091C7/BIyLlSyN1YLr9qQg3arL8MoPimrZHdXasyQN87L09i6 BrWByDj6qV0PrDIhH2CBLfPg6uJAhEWoTJdo2eJe88TRbVGmwjzN4qDUXPrwTTgJ+Jx3 ZKjxu4DGFzVFhWuKZuVytGplnihuJNbazQxAVXt0OfYdV05QthWBr3/sXE3g4/n7b/B3 z07Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Qu7xVQBjH3QyINlgGCfvRYdJpf2OQd6ZDfiujBCmENo=; b=GHic99hz/fEGfgcHBMAjJUtz1+W1aX9rCPjtmIpFCjoGbAxDIKD32zVs5rN8EQaT6u 5bXmQP9Aj6U54XfB+9GCvIsl/TZfYsFGkOuMaha/jo2aLEJYfJ66vd6u1yE5iCFtH/c8 XigoHFeycXuiLb4biZFDbpk8vJrEpS9DbKzJefeWqjnvwtiYlhFhjNl28Gn0Y2q7PviT ynHP5uRRNn/On18zW13FcxFdXm4VvQgqLW+SWouguBs8M+B7c73EHXaFLrZScfALfj7N JTZVIcLzFHozKtsMbEj+mWE1Gt0QYb5RxNmv9bKrO9LYy75l1uxuh3sw4V3aTbx82K+l nlNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=Vo72+tj9; 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 u6-20020a170902e80600b00198fbf41935si8739726plg.76.2023.02.06.15.12.41; Mon, 06 Feb 2023 15:12: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=Vo72+tj9; 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 S229657AbjBFXMc (ORCPT + 99 others); Mon, 6 Feb 2023 18:12:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjBFXMb (ORCPT ); Mon, 6 Feb 2023 18:12:31 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 178B43AA9 for ; Mon, 6 Feb 2023 15:12:30 -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 316KE5p1028043; Mon, 6 Feb 2023 23:12: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=Qu7xVQBjH3QyINlgGCfvRYdJpf2OQd6ZDfiujBCmENo=; b=Vo72+tj9qTKIsQzCl06l7/pvPMZ8ENcIEgXrnFkXJfMxAxu8a/qG6Y7+PcqhcJF/slZx 12PKvWVhuVY67YvwHC98xaoPy5MvOwyCrpoPWNIaQy3PW0xc4NSjZH3RYR8oGVtaKudb 96iqmWK1LwJIUxHydECHmYFhaBEhC7+plitl1WdHUcjZDow6PCtTYfefIInjwgLKjYy/ Qsnv8a3JlSWLWXNUjVCgkg6Gfqs0J5bRYIqGcu05HjVvUOb3NzDzWXwdnjQ00c+fi0sC X932WN+Caj6tT+N+OpxSwvfoJ16K7WFLY9nYtztO69a9SO15fOu3hfNaK4GpmMyKipBD 5A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhdy1480k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:12:26 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LpWgr021033; Mon, 6 Feb 2023 23:12:25 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nhdt4sj6f-3; Mon, 06 Feb 2023 23:12: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 RESENT v4 2/6] vdpa: conditionally read STATUS in config space Date: Mon, 6 Feb 2023 15:12:00 -0800 Message-Id: <1675725124-7375-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> References: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-GUID: CWXNbnUoI1Kyj90cUxoll5WntXaSGl8Y X-Proofpoint-ORIG-GUID: CWXNbnUoI1Kyj90cUxoll5WntXaSGl8Y 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?1757125199797706315?= X-GMAIL-MSGID: =?utf-8?q?1757125199797706315?= The spec says: status only exists if VIRTIO_NET_F_STATUS is set Similar to MAC and MTU, vdpa_dev_net_config_fill() should read STATUS conditionally depending on the feature bits. Signed-off-by: Si-Wei Liu Reviewed-by: Parav Pandit Reviewed-by: Eli Cohen --- drivers/vdpa/vdpa.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 3a82ca78..21c8aa3 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -843,18 +843,25 @@ static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features, sizeof(config->mac), config->mac); } +static int vdpa_dev_net_status_config_fill(struct sk_buff *msg, u64 features, + const struct virtio_net_config *config) +{ + u16 val_u16; + + if ((features & BIT_ULL(VIRTIO_NET_F_STATUS)) == 0) + return 0; + + val_u16 = __virtio16_to_cpu(true, config->status); + return nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16); +} + static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg) { struct virtio_net_config config = {}; u64 features_device; - u16 val_u16; vdev->config->get_config(vdev, 0, &config, sizeof(config)); - val_u16 = __virtio16_to_cpu(true, config.status); - if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16)) - return -EMSGSIZE; - features_device = vdev->config->get_device_features(vdev); if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device, @@ -867,6 +874,9 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms if (vdpa_dev_net_mac_config_fill(msg, features_device, &config)) return -EMSGSIZE; + if (vdpa_dev_net_status_config_fill(msg, features_device, &config)) + return -EMSGSIZE; + return vdpa_dev_net_mq_config_fill(msg, features_device, &config); } From patchwork Mon Feb 6 23:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 53556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2516550wrn; Mon, 6 Feb 2023 15:15:23 -0800 (PST) X-Google-Smtp-Source: AK7set+bocZ4VZ+tlT3Ihmd/ZiB2YN9n/FCz5C2vwOfow2p6hMnJODALuW2jj55usXXoS2zmO7Ky X-Received: by 2002:a17:907:3e0a:b0:87f:d08:1064 with SMTP id hp10-20020a1709073e0a00b0087f0d081064mr1897310ejc.6.1675725323471; Mon, 06 Feb 2023 15:15:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725323; cv=none; d=google.com; s=arc-20160816; b=iYo30fmSaKbM7igNyaGgkN3X2bwUqEXM9f/P+GdRJVsLvQvV8Daqtlc4D3xD6xxlTI u2eU5p/cGq67WnaiO7BovavfIFYsO7iQ0B1tX9rqb7/rrbNsjjJjA5vdf0aowscUddd1 toHjv6LC3ADWpmzw+2dgyTnqMlJTAhN65VOU8qF0/ZyiBx0yNplxB5N6DT+WpsOZ950E JawZgZsCPHdTHiO+afEUjT0tnWe3gNdISToQDsq6jn3Aa+ukwsq/XZWY6g+NvOtRbYov Cy2+hThAXoqMYhO1Y/C1E6l8ZqRbHr04DXZqH0Ru/UxXZqXYlIiddYf63gWa1SEgv3pX 48LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=0CriircPtC5ExQ5QJKfnKlayKOe8WG6ZDKh8VqSRLTw=; b=S7i/e4M0k9PSRQF8SwJwUJZ7nty7bPQF3eVhuXqrk0Rh+rgYjz+AY6V4QR3EpFe+0z xEYPNln3g9xMQox4sCAGWp2i5QpZIW+WoTZESX5Byb1QLZSt4ygZIDKjEa1jJvvwUuIq BghvuoY6Q3UoZG09sFSgSkCcfgtB3tmhhH/UJTxF9ANrF4g7cLtdzSr3xHE22YUeqzU9 ubBAXqrd4MnZLR5JoklqKfd1f69g0tpnenK9VK4GsfxDuBiPmcjwzGslIN38hfW5ANZD uPizD/+YzUX1U3HdSXNgDNc22gYFNzPYODx0XqGFhwPSrhI9XRqqYjCNReF2ZiA6/wis k5gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=iVWUXcQi; 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 h20-20020a170906111400b00872236c2747si11329460eja.305.2023.02.06.15.14.59; Mon, 06 Feb 2023 15:15:23 -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=iVWUXcQi; 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 S230018AbjBFXMm (ORCPT + 99 others); Mon, 6 Feb 2023 18:12:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjBFXMg (ORCPT ); Mon, 6 Feb 2023 18:12:36 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B548C30EA6 for ; Mon, 6 Feb 2023 15:12:33 -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 316KE2p6029602; Mon, 6 Feb 2023 23:12:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=0CriircPtC5ExQ5QJKfnKlayKOe8WG6ZDKh8VqSRLTw=; b=iVWUXcQi3PZ5p5b14zda5RyTLGqGx9+eL3FaftoBoXA+coVyfjZEhqUh3c9lJ4JhiWav rLlVpgMbXYLshDjIzr+a7827NGpGTqY1vbuL/ntWpPviwx0H7UZgJy077vTU/K7al3Ki JGAa73z70CYh/22wj2Icu8QPh3u/S0xySsnWuZlhj1Qn8zPV8Y04MNu7mdc3oFrfbPMF IeLid+9UpfJAdW0lNuFRLb3JuiZ27Fae/TzrdkFYcXJlO5BZRFMXDjp8YFtI6TMDw9Is 9bHfsx0Yd9KZKNsh4pwzajeJBOnmj6V1MlMfF91AW3GhAKO0qa3xc4OTsvclMi7LsKYx iw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhdsdm991-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:12:27 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LpWgs021033; Mon, 6 Feb 2023 23:12:26 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nhdt4sj6f-4; Mon, 06 Feb 2023 23:12: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 RESENT v4 3/6] vdpa: validate provisioned device features against specified attribute Date: Mon, 6 Feb 2023 15:12:01 -0800 Message-Id: <1675725124-7375-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> References: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-ORIG-GUID: vXQnM26dD8UEN7y1bMMm6xxbR58_yLxk X-Proofpoint-GUID: vXQnM26dD8UEN7y1bMMm6xxbR58_yLxk 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?1757125356770082581?= X-GMAIL-MSGID: =?utf-8?q?1757125356770082581?= With device feature provisioning, there's a chance for misconfiguration that the vdpa feature attribute supplied in 'vdpa dev add' command doesn't get selected on the device_features to be provisioned. For instance, when a @mac attribute is specified, the corresponding feature bit _F_MAC in device_features should be set for consistency. If there's conflict on provisioned features against the attribute, it should be treated as an error to fail the ambiguous command. Noted the opposite is not necessarily true, for e.g. it's okay to have _F_MAC set in device_features without providing a corresponding @mac attribute, in which case the vdpa vendor driver could load certain default value for attribute that is not explicitly specified. Generalize this check in vdpa core so that there's no duplicate code in each vendor driver. Signed-off-by: Si-Wei Liu Reviewed-by: Eli Cohen --- drivers/vdpa/vdpa.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 21c8aa3..1eba978 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -601,8 +601,26 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); } if (nl_attrs[VDPA_ATTR_DEV_FEATURES]) { + u64 missing = 0x0ULL; + config.device_features = nla_get_u64(nl_attrs[VDPA_ATTR_DEV_FEATURES]); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR] && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MAC))) + missing |= BIT_ULL(VIRTIO_NET_F_MAC); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU] && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MTU))) + missing |= BIT_ULL(VIRTIO_NET_F_MTU); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP] && + config.net.max_vq_pairs > 1 && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MQ))) + missing |= BIT_ULL(VIRTIO_NET_F_MQ); + if (missing) { + NL_SET_ERR_MSG_FMT_MOD(info->extack, + "Missing features 0x%llx for provided attributes", + missing); + return -EINVAL; + } config.mask |= BIT_ULL(VDPA_ATTR_DEV_FEATURES); } From patchwork Mon Feb 6 23:12: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: 53555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2516414wrn; Mon, 6 Feb 2023 15:15:00 -0800 (PST) X-Google-Smtp-Source: AK7set8Cx5h7J25LW1qiZZQG7KRe5VF0hEtXAJQqQBB5SiPJxKIm9lgtCtjY1//CxOQL5ZoP1dTZ X-Received: by 2002:a50:c05d:0:b0:49d:34ae:c7aa with SMTP id u29-20020a50c05d000000b0049d34aec7aamr1354730edd.29.1675725300649; Mon, 06 Feb 2023 15:15:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725300; cv=none; d=google.com; s=arc-20160816; b=kd4q5/ALSyZEtDKugIVQEs3tFTgnHJxxrRz8MvvPPfmU3+FirTETTSjTcfw4FyWL5i Um9sjr2tfeomHJefJaKQioAigL+Rd52qXyyYAby5xVtt46b8ZvNmOTnTbecxhcc2HSfk cUW0oSfQvuaSGghlqB+3lgenPFuqMdye/WsfrI0y5g0O0nyYJr+64Mz1qlv0aLf+YdJF U/+s6dy32uk+rfMDpYSX3Hk6dRRdF0FqFoZWcouWJ8D8AmRwPIE6q+UHW9H0wUiCPrIK lZcqyW/441T9yGhJzibFL2ze2lv2tSPVREahvhEYnGB0686eh4Pnp0xIBIMePc3xpsw+ WlIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=d3JugFvzxOjps33xev2euAm7g4qNmWk7oY4Vz08lzVM=; b=uJLG7mJtMyT9TBe3uRS493Csp5bJIFkYn12HxK4vqa9s8pyS8Vz0DsR+kN/7FD8PM/ 1ipJmzYNtA7ViYhLhJAXfZnF887ri27o9CX4Gq2nXWfZHiG1FkOP7FI2/FJ59UIqIz3P LnqxYXzDfGuOBBObhvikJpoNZV+EtqvFfBUN2tHuoaf0cbJqrbhnyqp6OatecaDVdD1I WkpaydAqKkkUcWQBYisvC8S3rg5Jt2eaXlBc2fJuXqo1szILEjdN47lPXtCBP7NtVKu1 zAY02fEyGzLRJLpP+JlbKWkjdALSjOqrLwmXW1JgxldavkqzsJLPJWw6/yobQ2Lu5BJV 3z0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=ZTGXVzJO; 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 fg14-20020a056402548e00b004a0db7e4383si12730651edb.394.2023.02.06.15.14.15; Mon, 06 Feb 2023 15:15:00 -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=ZTGXVzJO; 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 S229939AbjBFXMk (ORCPT + 99 others); Mon, 6 Feb 2023 18:12:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbjBFXMe (ORCPT ); Mon, 6 Feb 2023 18:12:34 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 218F831E07 for ; Mon, 6 Feb 2023 15:12:33 -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 316KDrhf003911; Mon, 6 Feb 2023 23:12:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=d3JugFvzxOjps33xev2euAm7g4qNmWk7oY4Vz08lzVM=; b=ZTGXVzJO4bSE/0v+jxfEf9XTuSzyyotNX2Yr1sT8ZUDVbokDhqLrYXLrLP+OYRPVXQ3Q O/CJGi2I2Q6qU8plhsB2VPWkS3lrRBZVZRKzS1RAHVSVgcVadQZmAl++AGTP0Gzhxtdf 0pl444B7XsndMHsWr/nZWKSP0ruzEUkZuhnQ22nb+MBsTdmxRVJaKf7vNP29KPRkxf+U IcxiE5EoiIkiwA7ZSsuEf1fG7tKaZjv8VnjhCED5yeqAuHI9iUgHu1GC1X6ToRs6DjW3 +NFGkS4Ri+ITH9CiGs5Ll0Ex0qsHhD+fEEXD0W8v3zTEmXKZDHZtwDdICP+5GOQwhPZh 0A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nheytv8br-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:12:28 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LpWgt021033; Mon, 6 Feb 2023 23:12:27 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nhdt4sj6f-5; Mon, 06 Feb 2023 23:12:27 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH RESENT v4 4/6] vdpa: validate device feature provisioning against supported class Date: Mon, 6 Feb 2023 15:12:02 -0800 Message-Id: <1675725124-7375-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> References: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-GUID: KZV65-0zqrh8RBL-x8u4yUftGOYLTUxQ X-Proofpoint-ORIG-GUID: KZV65-0zqrh8RBL-x8u4yUftGOYLTUxQ 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?1757125332760110671?= X-GMAIL-MSGID: =?utf-8?q?1757125332760110671?= Today when device features are explicitly provisioned, the features user supplied may contain device class specific features that are not supported by the parent management device. On the other hand, when parent management device supports more than one class, the device features to provision may be ambiguous if none of the class specific attributes is provided at the same time. Validate these cases and prompt appropriate user errors accordingly. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 59 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1eba978..8da5120 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -460,12 +460,28 @@ static int vdpa_nl_mgmtdev_handle_fill(struct sk_buff *msg, const struct vdpa_mg return 0; } +static u64 vdpa_mgmtdev_get_classes(const struct vdpa_mgmt_dev *mdev, + unsigned int *nclasses) +{ + u64 supported_classes = 0; + unsigned int n = 0; + + for (int i = 0; mdev->id_table[i].device; i++) { + if (mdev->id_table[i].device > 63) + continue; + supported_classes |= BIT_ULL(mdev->id_table[i].device); + n++; + } + if (nclasses) + *nclasses = n; + + return supported_classes; +} + static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *msg, u32 portid, u32 seq, int flags) { - u64 supported_classes = 0; void *hdr; - int i = 0; int err; hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags, VDPA_CMD_MGMTDEV_NEW); @@ -475,14 +491,9 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m if (err) goto msg_err; - while (mdev->id_table[i].device) { - if (mdev->id_table[i].device <= 63) - supported_classes |= BIT_ULL(mdev->id_table[i].device); - i++; - } - if (nla_put_u64_64bit(msg, VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES, - supported_classes, VDPA_ATTR_UNSPEC)) { + vdpa_mgmtdev_get_classes(mdev, NULL), + VDPA_ATTR_UNSPEC)) { err = -EMSGSIZE; goto msg_err; } @@ -566,13 +577,25 @@ static int vdpa_nl_cmd_mgmtdev_get_doit(struct sk_buff *skb, struct genl_info *i BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) | \ BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) +/* + * Bitmask for all per-device features: feature bits VIRTIO_TRANSPORT_F_START + * through VIRTIO_TRANSPORT_F_END are unset, i.e. 0xfffffc000fffffff for + * all 64bit features. If the features are extended beyond 64 bits, or new + * "holes" are reserved for other type of features than per-device, this + * macro would have to be updated. + */ +#define VIRTIO_DEVICE_F_MASK (~0ULL << (VIRTIO_TRANSPORT_F_END + 1) | \ + ((1ULL << VIRTIO_TRANSPORT_F_START) - 1)) + static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info) { struct vdpa_dev_set_config config = {}; struct nlattr **nl_attrs = info->attrs; struct vdpa_mgmt_dev *mdev; + unsigned int ncls = 0; const u8 *macaddr; const char *name; + u64 classes; int err = 0; if (!info->attrs[VDPA_ATTR_DEV_NAME]) @@ -649,6 +672,24 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i goto err; } + classes = vdpa_mgmtdev_get_classes(mdev, &ncls); + if (config.mask & VDPA_DEV_NET_ATTRS_MASK && + !(classes & BIT_ULL(VIRTIO_ID_NET))) { + NL_SET_ERR_MSG_MOD(info->extack, + "Network class attributes provided on unsupported management device"); + err = -EINVAL; + goto err; + } + if (!(config.mask & VDPA_DEV_NET_ATTRS_MASK) && + config.mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES) && + classes & BIT_ULL(VIRTIO_ID_NET) && ncls > 1 && + config.device_features & VIRTIO_DEVICE_F_MASK) { + NL_SET_ERR_MSG_MOD(info->extack, + "Management device supports multi-class while device features specified are ambiguous"); + err = -EINVAL; + goto err; + } + err = mdev->ops->dev_add(mdev, name, &config); err: up_write(&vdpa_dev_lock); From patchwork Mon Feb 6 23:12: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: 53554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515778wrn; Mon, 6 Feb 2023 15:13:30 -0800 (PST) X-Google-Smtp-Source: AK7set+HA8kh8LroJ+lV0szcVzGFFAAw+UEk1K9LJSf2Ow/6UjEIbkFrdWu8LkJ4pVNZfHkXF4fp X-Received: by 2002:a50:9e0f:0:b0:4a2:1263:bbab with SMTP id z15-20020a509e0f000000b004a21263bbabmr1304160ede.17.1675725210559; Mon, 06 Feb 2023 15:13:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725210; cv=none; d=google.com; s=arc-20160816; b=u23I+SulEtatN0XisJ4WR/lpsRrYRB9cRPEM3Cyz1qCNCVPCDayaSeB8g0dd9dm3zt a9yUjDy1ljsy3ZcPVZqLCXiPR3g265Aw4l/G9pdoyMxZG7yLGLu+KbXzupgGhsM2x1n2 4/ap9gst/mJnjnJS7S8mnN+1zXY9+uRoyVlcBIoxXYudBvIsJoMPp66JB0qqTOfzMBSt Hpw1LQAD1PNDhiDIxlg/Zuzw5voGiYPS9M4tEqcad+IMkk733tv6LnXHO9aCVOohPfw9 uG7BuphwV5jEI5U03LpkiGzdFlfwSm8HeDyIq26KMFjbmbE+Cy1x51o5lH6eEryERmow dfCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=JJWHSduRoQrbMlgcL9i/NZDlDLMD04ksn4nHHzB3RNE=; b=mtNhLzNU7IKAzUiwhztxe5fmeDc3OsmRC16C6+t1R+h5E3X6gygLm3pMTdQYNe9AEC z5/d9gYsA0D7pCXtH0d/mvPD2Lnu0RADz1swa8ZLB0oscl2aqYTE6Cgw/wYszcw80Byv M1bBkrnA6eqHXw6qizwAz7SJx6599eK2nFGKZl+sAiT6vcgsvjdDB/VVDMu4xtbquu1n 0tXe3d7VXMYqa0ANZrVa4/OmJ5o0US1rF6k6MRqOpCpntEIz7jJZ3ldQU4Qwji5jRpFX 1kFfrVbLFs4VrynG2+zJLARrnggk8VAMznJgT1tAZIi1ZDdCxCvZvxtlkeaRX8fGdZm4 9x+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=x2nIiYTN; 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 fk6-20020a056402398600b004a229343cfcsi15235443edb.573.2023.02.06.15.13.07; Mon, 06 Feb 2023 15:13:30 -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=x2nIiYTN; 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 S229899AbjBFXMi (ORCPT + 99 others); Mon, 6 Feb 2023 18:12:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjBFXMd (ORCPT ); Mon, 6 Feb 2023 18:12:33 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2DDC30EB8 for ; Mon, 6 Feb 2023 15:12:32 -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 316KE5p2028043; Mon, 6 Feb 2023 23:12:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=JJWHSduRoQrbMlgcL9i/NZDlDLMD04ksn4nHHzB3RNE=; b=x2nIiYTNGczQaIOdBstbzWcdoXa7z95s8TL4aQfxSoar8zCpOQ5sghms3cUqgsSPt7cf 10bAmhvT4FZ0SafToaL5TFSKEKnryGlXV2SBe9mL8VcS8SNKcQzlH9uX6WD45b0Z5xVC 6c/vd82kp+54NRiqKDr6lDvh3u3zE9wH+8Kci0aKE8flyHACsUFxrEP7vcM3pal6lEst t7AFGMaufpvD8Ps5N+CNDe3CYRl3N/uodQoCDn4cxioi/zm7GX9ZkLutW4fBq+5gBORb pu8K0yRyaCBtPF9qHYdf2BS4cxOtf6KPprYi8TYwN6hLM/ITPCIMGTeMvnG2x+TQoZ4x Rw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nhdy1480n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:12:29 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LpWgu021033; Mon, 6 Feb 2023 23:12:28 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nhdt4sj6f-6; Mon, 06 Feb 2023 23:12:28 +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 RESENT v4 5/6] vdpa/mlx5: make MTU/STATUS presence conditional on feature bits Date: Mon, 6 Feb 2023 15:12:03 -0800 Message-Id: <1675725124-7375-6-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> References: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-GUID: zUaAnA7IFojCL89xCfzRrIUH7VFpo6eB X-Proofpoint-ORIG-GUID: zUaAnA7IFojCL89xCfzRrIUH7VFpo6eB 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?1757125238078013558?= X-GMAIL-MSGID: =?utf-8?q?1757125238078013558?= The spec says: mtu only exists if VIRTIO_NET_F_MTU is set status only exists if VIRTIO_NET_F_STATUS is set We should only present MTU and STATUS conditionally depending on the feature bits. Signed-off-by: Si-Wei Liu Reviewed-by: Eli Cohen --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 3a6dbbc6..867ac18 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p struct mlx5_vdpa_wq_ent *wqent; if (event == MLX5_EVENT_TYPE_PORT_CHANGE) { + if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS))) + return NOTIFY_DONE; switch (eqe->sub_type) { case MLX5_PORT_CHANGE_SUBTYPE_DOWN: case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: @@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, goto err_alloc; } - err = query_mtu(mdev, &mtu); - if (err) - goto err_alloc; + if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_MTU)) { + err = query_mtu(mdev, &mtu); + if (err) + goto err_alloc; - ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); + ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); + } - if (get_link_state(mvdev)) - ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); - else - ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP); + if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { + if (get_link_state(mvdev)) + ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); + else + ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP); + } if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN); From patchwork Mon Feb 6 23:12: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: 53557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2519447wrn; Mon, 6 Feb 2023 15:21:32 -0800 (PST) X-Google-Smtp-Source: AK7set8xsAdA5iCmizihNG9Q25lQQHvL2pfbQ69CkvmUT44BuW2BEFOqUNAR6weGyua2vnBdzyc5 X-Received: by 2002:a50:8e17:0:b0:4aa:c4bb:d432 with SMTP id 23-20020a508e17000000b004aac4bbd432mr1319412edw.11.1675725692319; Mon, 06 Feb 2023 15:21:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675725692; cv=none; d=google.com; s=arc-20160816; b=ncFWrUCSlZsUpqjNqYElKXQ2Tvj17IYzPVNb3/cQdAoZkNnFIGsQ8YjEVh+Ee5UGDb wyDE4SFJFV/efXvttDxWnDStCgUPObpGFFCuWPFx/jFZTMfr69+jKYZgDGDp53OqeTAx Hg/u28JRZaYs/gGqT6ClE4nz53BVrInp65wkG1y03BH1YBhXm1kmthRIa47loD2eEvRc jL9XyW4uiPZHbTOsjdVTIwsvgICl0V1D9EjDz90TbtfzBjetn56D4Mj+joiq35OCTRbc kmktcJj8WR7YqB7yZL/GpEH7CP/E+TY/8PXO7sJ6p3IkHIsVhAKnh7ih7zytv56YIdjA AAAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=9jOxWRKfGQrPvyThoIL2nkqwCTwWn4JHfQboUAfZaXU=; b=FHh8OtcZ4Vl5Mm/E26bqZjrcn3TCUDlj+IOVvEavmOFyLEe6zFoCjfEgH65V+7OZAM Y0tjJG6gQiXkqTZPdjsACG859bBPupHDJPKjcpD80lPWDiGXuuainURlFcEnxztD+4TC Xo+BKPoc0fqpgJy+6kp2THHRxtJOn/tsXyvGd2unVjYFPBCU7VhNF01YwdcFbe03Ne75 6ALyaalSsHu88OVHSSrlexWe3/XPHvIcATvtYelYxUyIE8GJlcOw0gwUpMZuJ431xiEJ Kluzes+4vjaOSkkRmZGpKomPdg2PLUFyZBZSX2GpFyT6Unf66PsmnPL9bSp0Sib2RAw5 k+yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=VEro653H; 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 m2-20020a056402430200b004a2343e90c4si18451307edc.380.2023.02.06.15.21.06; Mon, 06 Feb 2023 15:21:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=VEro653H; 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 S230215AbjBFXMw (ORCPT + 99 others); Mon, 6 Feb 2023 18:12:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbjBFXMk (ORCPT ); Mon, 6 Feb 2023 18:12:40 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C92D030EBA for ; Mon, 6 Feb 2023 15:12:35 -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 316KDrhg003911; Mon, 6 Feb 2023 23:12:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=9jOxWRKfGQrPvyThoIL2nkqwCTwWn4JHfQboUAfZaXU=; b=VEro653H0ZP4A7PrSPjfGB88CFXtcsuI0x9szlLig42aa8lPBKuk/ANI7GFubecgIiO1 bTc7etX3ropJXNyYMwXu0B9v8Vriw2WY1P6XuXofQBiqx64sm0WGWJxvlJe4XcXxi7T5 dxPYNDHUVYVcr+2Y+34zpSp6wEAUBDtONZUpNGiWcNhS4vrptr059PCGReJ1wdnFPwTa oG+xNvwODSuUS+VMJdLLzE2yoaPuWBtCHpIFR76XChXlBvgdx8itveqU05Ky9uBXwctd aV1swNsrCAeJYOb4+Ujy++e2v5LTGtj8rlgJ+dkp8NSvBKj7+TnaiHSFk0ZLW1O86x/C Qg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nheytv8bs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Feb 2023 23:12:30 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 316LpWgv021033; Mon, 6 Feb 2023 23:12:29 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3nhdt4sj6f-7; Mon, 06 Feb 2023 23:12:29 +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 RESENT v4 6/6] vdpa/mlx5: support device features provisioning Date: Mon, 6 Feb 2023 15:12:04 -0800 Message-Id: <1675725124-7375-7-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> References: <1675725124-7375-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060202 X-Proofpoint-GUID: 3e-g0ooCm_h4wxz9nyS_caIs6c4uEhSf X-Proofpoint-ORIG-GUID: 3e-g0ooCm_h4wxz9nyS_caIs6c4uEhSf 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?1757125743263683532?= X-GMAIL-MSGID: =?utf-8?q?1757125743263683532?= This patch implements features provisioning for mlx5_vdpa. 1) Validate the provisioned features are a subset of the parent features. 2) Clearing features that are not wanted by userspace. For example: # vdpa mgmtdev show pci/0000:41:04.2: supported_classes net max_supported_vqs 65 dev_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ CTRL_VLAN MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 1) Provision vDPA device with all features derived from the parent # vdpa dev add name vdpa1 mgmtdev pci/0000:41:04.2 # vdpa dev config show vdpa1: mac e4:11:c6:d3:45:f0 link up link_announce false max_vq_pairs 1 mtu 1500 negotiated_features CSUM GUEST_CSUM MTU HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ CTRL_VLAN MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 2) Provision vDPA device with a subset of parent features # vdpa dev add name vdpa1 mgmtdev pci/0000:41:04.2 device_features 0x300020000 # vdpa dev config show vdpa1: negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM Signed-off-by: Si-Wei Liu Reviewed-by: Eli Cohen --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 53 +++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 867ac18..b40dd1a 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2183,6 +2183,7 @@ static u64 get_supported_features(struct mlx5_core_dev *mdev) mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_STATUS); mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MTU); mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_CTRL_VLAN); + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MAC); return mlx_vdpa_features; } @@ -3062,6 +3063,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, struct mlx5_vdpa_dev *mvdev; struct mlx5_vdpa_net *ndev; struct mlx5_core_dev *mdev; + u64 device_features; u32 max_vqs; u16 mtu; int err; @@ -3070,6 +3072,24 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, return -ENOSPC; mdev = mgtdev->madev->mdev; + device_features = mgtdev->mgtdev.supported_features; + if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) { + if (add_config->device_features & ~device_features) { + dev_warn(mdev->device, + "The provisioned features 0x%llx are not supported by this device with features 0x%llx\n", + add_config->device_features, device_features); + return -EINVAL; + } + device_features &= add_config->device_features; + } + if (!(device_features & BIT_ULL(VIRTIO_F_VERSION_1) && + device_features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM))) { + dev_warn(mdev->device, + "Must provision minimum features 0x%llx for this device", + BIT_ULL(VIRTIO_F_VERSION_1) | BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)); + return -EOPNOTSUPP; + } + if (!(MLX5_CAP_DEV_VDPA_EMULATION(mdev, virtio_queue_type) & MLX5_VIRTIO_EMULATION_CAP_VIRTIO_QUEUE_TYPE_SPLIT)) { dev_warn(mdev->device, "missing support for split virtqueues\n"); @@ -3098,7 +3118,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, if (IS_ERR(ndev)) return PTR_ERR(ndev); - ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features; ndev->mvdev.max_vqs = max_vqs; mvdev = &ndev->mvdev; mvdev->mdev = mdev; @@ -3120,7 +3139,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, goto err_alloc; } - if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_MTU)) { + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) { err = query_mtu(mdev, &mtu); if (err) goto err_alloc; @@ -3128,7 +3147,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); } - if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { if (get_link_state(mvdev)) ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); else @@ -3137,7 +3156,9 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN); - } else { + /* No bother setting mac address in config if not going to provision _F_MAC */ + } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0 || + device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac); if (err) goto err_alloc; @@ -3148,11 +3169,26 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, err = mlx5_mpfs_add_mac(pfmdev, config->mac); if (err) goto err_alloc; - - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_MAC); + } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0) { + /* + * We used to clear _F_MAC feature bit if seeing + * zero mac address when device features are not + * specifically provisioned. Keep the behaviour + * so old scripts do not break. + */ + device_features &= ~BIT_ULL(VIRTIO_NET_F_MAC); + } else if (device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { + /* Don't provision zero mac address for _F_MAC */ + mlx5_vdpa_warn(&ndev->mvdev, + "No mac address provisioned?\n"); + err = -EINVAL; + goto err_alloc; } - config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); + if (device_features & BIT_ULL(VIRTIO_NET_F_MQ)) + config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); + + ndev->mvdev.mlx_features = device_features; mvdev->vdev.dma_dev = &mdev->pdev->dev; err = mlx5_vdpa_alloc_resources(&ndev->mvdev); if (err) @@ -3249,7 +3285,8 @@ static int mlx5v_probe(struct auxiliary_device *adev, mgtdev->mgtdev.id_table = id_table; mgtdev->mgtdev.config_attr_mask = BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR) | BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP) | - BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU); + BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) | + BIT_ULL(VDPA_ATTR_DEV_FEATURES); mgtdev->mgtdev.max_supported_vqs = MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues) + 1; mgtdev->mgtdev.supported_features = get_supported_features(mdev);