Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3060877rwb; Mon, 15 Aug 2022 17:09:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR7BBxgoX79qswISX3RbBouob3hnA2OG+qsADkvJzQpxXRKr2in9s1VvtCnSF+KqUZ3+I8MW X-Received: by 2002:a05:6402:3293:b0:43e:4a21:af84 with SMTP id f19-20020a056402329300b0043e4a21af84mr16718875eda.170.1660608586002; Mon, 15 Aug 2022 17:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660608585; cv=none; d=google.com; s=arc-20160816; b=UgNXV4ZwQTBbCAoUqa9jbUw+9RlNb/3rzMqr6tpgLLWeG9Y6pl8GyQzIEyj3wjaPeX Bcf/sEGPbkSfY63wHPxwbL7Adv8yt+EZGtHECQviegeQ8HyD+km8jUAlj84FzM/pCXjf EPHJexqiRLOhQi5usV/df8i+BwA4+6aWR9D2UVwMUttbDcsx6kHnLLWawi2CuG4XXs/I 1BwFk8LAMh8ToE0MxF8Pw5uvY5QGXGGDxX83hBstoMui2UevSuLt7+DJgYUubVqYLVPG thvSXi9/bJZeX+FY/l4IjFLwo0BI+KmZ0PcaNNJsHWAAsyFkmbiJ6F1pU+vGl2aKhFFu NCmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nceFQT7s7GGLtgrXrPTeaWGz5SO9IFEiXys6E+IJeB4=; b=S55WS8bD5vr5rSDSrS9ZwaUV5NMfXYEKZ+btpccpJMuvC7lYfYQRZNuVQKneEY3qm/ gXdypS9x7f2kbSD8779O8FF8ocInPmXmP95fjNkWAwI7nz6TVIjRA/FvxRHj2lQLDWsG St0kZsgvnZi4YQTHfP5TOruwOW7cYT7tAU1c1AMSfcGUhFZn3ND5hQxUhP3wOMomJY3G zYHUO+T1zN/fxhlMF5qqi3sWUAj/eOJuThqkbsZ1yryrtqnNiTFCc8rV2/JHYaedfkMu pcLNNK4roQJ+4L2zZ2rYRsaRKYp1bvmkbPr6lkmqQyXctwojNoC22FSJAdF3vbfgncrE 4dqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vxii4nro; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd12-20020a170907628c00b00732fa9d3df0si8767040ejc.795.2022.08.15.17.09.17; Mon, 15 Aug 2022 17:09:45 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=vxii4nro; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351830AbiHPAFQ (ORCPT + 99 others); Mon, 15 Aug 2022 20:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355618AbiHOX5K (ORCPT ); Mon, 15 Aug 2022 19:57:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C41163ACA; Mon, 15 Aug 2022 13:20:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4CD5A60FB8; Mon, 15 Aug 2022 20:20:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3931AC433D6; Mon, 15 Aug 2022 20:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594799; bh=f4SZ4mcsekZdIZR9EDgaIVdoZev4KSJk5zIiug8otjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vxii4nroFKPkfqNdlbpr/OtJ0/NFw2Oraf6I73ENlA04xPDJ6572BuUKsvMScAMDW TNMplAWpKt/wKS1HLMdssT/ehICbqA6SROHZ1dE3LKJZmVo6qYOsNLGAT72vPm5jlR fby7hLJGnz8IYL+YO8QPSvU068CyBIdFsWd7uXFQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Przemyslaw Patynowski , Jun Zhang , Bharathi Sreenivas , Tony Nguyen , Sasha Levin Subject: [PATCH 5.19 0563/1157] iavf: Fix max_rate limiting Date: Mon, 15 Aug 2022 19:58:39 +0200 Message-Id: <20220815180502.126907857@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Przemyslaw Patynowski [ Upstream commit ec60d54cb9a3d43a02c5612a03093c18233e6601 ] Fix max_rate option in TC, check for proper quanta boundaries. Check for minimum value provided and if it fits expected 50Mbps quanta. Without this patch, iavf could send settings for max_rate limiting that would be accepted from by PF even the max_rate option is less than expected 50Mbps quanta. It results in no rate limiting on traffic as rate limiting will be floored to 0. Example: tc qdisc add dev $vf root mqprio num_tc 3 map 0 2 1 queues \ 2@0 2@2 2@4 hw 1 mode channel shaper bw_rlimit \ max_rate 50Mbps 500Mbps 500Mbps Should limit TC0 to circa 50 Mbps tc qdisc add dev $vf root mqprio num_tc 3 map 0 2 1 queues \ 2@0 2@2 2@4 hw 1 mode channel shaper bw_rlimit \ max_rate 0Mbps 100Kbit 500Mbps Should return error Fixes: d5b33d024496 ("i40evf: add ndo_setup_tc callback to i40evf") Signed-off-by: Przemyslaw Patynowski Signed-off-by: Jun Zhang Tested-by: Bharathi Sreenivas Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/iavf/iavf.h | 1 + drivers/net/ethernet/intel/iavf/iavf_main.c | 25 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/iavf/iavf.h b/drivers/net/ethernet/intel/iavf/iavf.h index 0ea0361cd86b..c241fbc30f93 100644 --- a/drivers/net/ethernet/intel/iavf/iavf.h +++ b/drivers/net/ethernet/intel/iavf/iavf.h @@ -92,6 +92,7 @@ struct iavf_vsi { #define IAVF_HKEY_ARRAY_SIZE ((IAVF_VFQF_HKEY_MAX_INDEX + 1) * 4) #define IAVF_HLUT_ARRAY_SIZE ((IAVF_VFQF_HLUT_MAX_INDEX + 1) * 4) #define IAVF_MBPS_DIVISOR 125000 /* divisor to convert to Mbps */ +#define IAVF_MBPS_QUANTA 50 #define IAVF_VIRTCHNL_VF_RESOURCE_SIZE (sizeof(struct virtchnl_vf_resource) + \ (IAVF_MAX_VF_VSI * \ diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index 2e2c153ce46a..51ae10eb348c 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -3322,6 +3322,7 @@ static int iavf_validate_ch_config(struct iavf_adapter *adapter, struct tc_mqprio_qopt_offload *mqprio_qopt) { u64 total_max_rate = 0; + u32 tx_rate_rem = 0; int i, num_qps = 0; u64 tx_rate = 0; int ret = 0; @@ -3336,12 +3337,32 @@ static int iavf_validate_ch_config(struct iavf_adapter *adapter, return -EINVAL; if (mqprio_qopt->min_rate[i]) { dev_err(&adapter->pdev->dev, - "Invalid min tx rate (greater than 0) specified\n"); + "Invalid min tx rate (greater than 0) specified for TC%d\n", + i); return -EINVAL; } - /*convert to Mbps */ + + /* convert to Mbps */ tx_rate = div_u64(mqprio_qopt->max_rate[i], IAVF_MBPS_DIVISOR); + + if (mqprio_qopt->max_rate[i] && + tx_rate < IAVF_MBPS_QUANTA) { + dev_err(&adapter->pdev->dev, + "Invalid max tx rate for TC%d, minimum %dMbps\n", + i, IAVF_MBPS_QUANTA); + return -EINVAL; + } + + (void)div_u64_rem(tx_rate, IAVF_MBPS_QUANTA, &tx_rate_rem); + + if (tx_rate_rem != 0) { + dev_err(&adapter->pdev->dev, + "Invalid max tx rate for TC%d, not divisible by %d\n", + i, IAVF_MBPS_QUANTA); + return -EINVAL; + } + total_max_rate += tx_rate; num_qps += mqprio_qopt->qopt.count[i]; } -- 2.35.1