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);