From patchwork Tue Jan 31 23:22:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 51086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp90882wrn; Tue, 31 Jan 2023 15:25:24 -0800 (PST) X-Google-Smtp-Source: AK7set+TPUZ0jF2HBrn8Mfdcpi94UPwU+30/ZPFPLA5klwdUA7MPnNSbqkZslCiuYjxjmniBPYR7 X-Received: by 2002:a17:903:2444:b0:195:f06f:84ff with SMTP id l4-20020a170903244400b00195f06f84ffmr678550pls.50.1675207524437; Tue, 31 Jan 2023 15:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207524; cv=none; d=google.com; s=arc-20160816; b=ZK93ffxh4oudfvE6rncNQc4Ucz9l1AoxTHvtomco4s5KE+0dgz/3sJT+O4eMxj4Xa8 IVDV+9RB5w+Ws5I9enScXuOxQfVJggYUwsIt+QqFt576j4LeHaVyUAftIyth10SPNcQP 4H6dc1ixab8NWwUmUuc0CGQGIMjfdlsvI2OLBrh3jwCulfFs8+CpQBd2lI1HdFX2bzK+ tdNUtnTuFAjP10lyglFSkmHDC1jTBPthm7Hpm5AOomPeuUA41EKLlej0QEYHOs+DzJRX qH+FbRBpHW5fWfvQAEcWMeNDmjNiYP8bAo5BwScAcZC+PZ+piVuoJsUM5UE+FttgtQKt YeEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=fSu5LWhVuNzoustkxj8evl70EvKqh8oxSx7hEUWRRQk=; b=XeMo/iJ4mp5Ze0qwSpIp+GB7OIIcl5kpp+DePpl9pb1/ReQxodEQSa6JbFlrvJdHq9 Hed8TeyrKLtV6VFV0U4ly2wUsOwLq36+19g6lWfeftH9GTRrbUCbzCjArJCCq2Pbq8sb DdpAqQFUKw++c8ZPKHiUUyyvif0dUlTPLAPzm7EyaM1HRVb8HhhcNvUS0bRIBwp91kLe kH4QlOl6yceFew41aKSXAmZF+YEg19P5a7+KvniBSa8QbLjW8qPqdRusrIjkXi3u7Q54 BjWCOCwAlEaUrmX4x/HdI9BTntpd67zdbaxEUYHzKP7ebG3ysNvzyWugoUcAr9ME4sgz 0PiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=0ExPtRLm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a63be06000000b004eca59b9530si4934516pgf.408.2023.01.31.15.25.12; Tue, 31 Jan 2023 15:25:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=0ExPtRLm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232179AbjAaXWf (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231984AbjAaXWa (ORCPT ); Tue, 31 Jan 2023 18:22:30 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044C61C58E for ; Tue, 31 Jan 2023 15:22:30 -0800 (PST) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIiaOb023158; Tue, 31 Jan 2023 23:22:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=fSu5LWhVuNzoustkxj8evl70EvKqh8oxSx7hEUWRRQk=; b=0ExPtRLmiKhNaIItJSbT6vFjcGIo88SMh7rngeffCZ/JW3hqG43634SNiI8qizSZdxsU OZ9wNWuaJI74JTu1tHHI/qA5FuOb+nd0fHq1ususznqLUzOdidbaDNBzWCp4LTrQ9c8u KE1vSGc/y5HiMb7Wue3gdzgkxoEfU8Nb7K+ZX2mRAWMjreD0usSdIjEhkUS8OnvFvXUi 8Eeb00QUPFDwpODQcGmDFYjsru1Ksrks/IFyJCMQf5/czEjO4VkfqPstYwXUjeWEXMnK Y8OA96fnpUIoJAxnhEyc5j0FtPbn9GM+cgBfA9j+P6jV5o51+0+2k5XkURH/9FDzQEO0 pw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvr8q23d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:26 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VMuk9N031540; Tue, 31 Jan 2023 23:22:24 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nct5d8c94-4; Tue, 31 Jan 2023 23:22:24 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] vdpa: validate provisioned device features against specified attribute Date: Tue, 31 Jan 2023 15:22:04 -0800 Message-Id: <1675207327-22289-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: pMD_w7JHg7ix7MOYx2lRBtdLIgNKzrvr X-Proofpoint-ORIG-GUID: pMD_w7JHg7ix7MOYx2lRBtdLIgNKzrvr X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756582405087466372?= X-GMAIL-MSGID: =?utf-8?q?1756582405087466372?= With device feature provisioning, there's a chance for misconfiguration that the vdpa feature attribute supplied in 'vdpa dev add' command doesn't get selected on the device_features to be provisioned. For instance, when a @mac attribute is specified, the corresponding feature bit _F_MAC in device_features should be set for consistency. If there's conflict on provisioned features against the attribute, it should be treated as an error to fail the ambiguous command. Noted the opposite is not necessarily true, for e.g. it's okay to have _F_MAC set in device_features without providing a corresponding @mac attribute, in which case the vdpa vendor driver could load certain default value for attribute that is not explicitly specified. Generalize this check in vdpa core so that there's no duplicate code in each vendor driver. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 5f4883b..6d02b8c 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -601,8 +601,26 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); } if (nl_attrs[VDPA_ATTR_DEV_FEATURES]) { + u64 missing = 0x0ULL; + config.device_features = nla_get_u64(nl_attrs[VDPA_ATTR_DEV_FEATURES]); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR] && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MAC))) + missing |= BIT_ULL(VIRTIO_NET_F_MAC); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU] && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MTU))) + missing |= BIT_ULL(VIRTIO_NET_F_MTU); + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP] && + config.net.max_vq_pairs > 1 && + !(config.device_features & BIT_ULL(VIRTIO_NET_F_MQ))) + missing |= BIT_ULL(VIRTIO_NET_F_MQ); + if (missing) { + NL_SET_ERR_MSG_FMT_MOD(info->extack, + "Missing features 0x%llx for provided attributes", + missing); + return -EINVAL; + } config.mask |= BIT_ULL(VDPA_ATTR_DEV_FEATURES); }