Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2940256rwb; Mon, 15 Aug 2022 14:29:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7t3qoiURckZL9m19tmkIXJBLh8nlzTZ5aStb8F+fdwmeSPJZW9PBFQ/cvEI36wE4EBjOz1 X-Received: by 2002:a17:907:7fa9:b0:738:4132:612d with SMTP id qk41-20020a1709077fa900b007384132612dmr5666061ejc.508.1660598966738; Mon, 15 Aug 2022 14:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660598966; cv=none; d=google.com; s=arc-20160816; b=Q8Wop9ksT7twSebT3uPa4t/FyhVDHIJ61jBxapIwagvzTfsRodboAIwOus2vHFxMi2 2Ltr74ABnhzGE59j8awbQZjb9Rf/aCrXHaLEomeTcvbVHm5ySzbcJ3FwEZ135QmyTnvS 1QYssC+5GEapHOX4x3+TRwvXCuSU2eMt9tKZnRUU7YVtejCkFxYIi97W6IZ29xwhM0uv 4zt+W4PQpiS8xN8BU8HWe+vHeXc9LkZ39tWCSfktFP2jKhDbPzrb3g8XzkXxB9oYiNt1 4mjbB3YrU28zhlIuSp/Ot9o08R9Y27PhV7H/rAPgipX2zhK1DasgMEUCO5it1an9dbKg jAog== 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=fTd8zX7087OZ1LWOjTz7swd+SmahjFJPf9POZycjVSABSQ+7SnxfPfp5atCWiw50jD R2HswoR+dIgJJ99L7GdZy+HszovAI/VOrDFv2GqsdRC2HkakksvrtY+OIUZr11G4+vAw u2jKN9cB4e3rOZaB62hAYkJHKjOJjEkGJlsc2eAOXYv2J1G5t4QJULXRvVduI3I++OD4 Lp2pf2q/IVVPKZDVvVmqUhArvgkcm4YSX1O3y2s3DBBkXUa7ecq/0SG+wUP/YIhiNH7R kLcIyykBYWmJK4rUr3bVkPQUpDvcSpdqUMPxEhXrvbzl/xyIcK5qeXrbqCuqONSbXZ+6 H1yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uc7nG+Gt; 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 s24-20020a170906355800b0072f1c8d0ec4si7062550eja.584.2022.08.15.14.28.58; Mon, 15 Aug 2022 14:29:26 -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=uc7nG+Gt; 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 S1346670AbiHOVYh (ORCPT + 99 others); Mon, 15 Aug 2022 17:24:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346565AbiHOVSF (ORCPT ); Mon, 15 Aug 2022 17:18:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB132DAB2; Mon, 15 Aug 2022 12:21:26 -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 ams.source.kernel.org (Postfix) with ESMTPS id 66567B81109; Mon, 15 Aug 2022 19:21:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95C78C433C1; Mon, 15 Aug 2022 19:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591284; bh=f4SZ4mcsekZdIZR9EDgaIVdoZev4KSJk5zIiug8otjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uc7nG+Gtkk/3TDMIZih5I3rft/lm9bBFX30oKCgN1blo2j/sUSWnYhccggy/blKGK 5Y/a5qqYv5EqqegYDLg4Hpb3DdYhBFizpcEK0hBW4eIl0kzr++JNdBqCFXsU+65t7W VHuX7vyc0w6j5IjUEdTLX1c094D8mS4LcBymsLKg= 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.18 0529/1095] iavf: Fix max_rate limiting Date: Mon, 15 Aug 2022 19:58:48 +0200 Message-Id: <20220815180451.428677159@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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