Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp775959pxb; Tue, 12 Apr 2022 13:09:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwscN+HiTfl1ph0wr0ZzPq3o4EBWtuG+0UxmuJw9e1hYmU7hBQbb3+6zss+Jc/zQg7+7bf8 X-Received: by 2002:a63:c13:0:b0:39c:c530:7382 with SMTP id b19-20020a630c13000000b0039cc5307382mr24113286pgl.205.1649794140115; Tue, 12 Apr 2022 13:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649794140; cv=none; d=google.com; s=arc-20160816; b=B23ApjVLuY0dXoPt/LzkeSZhPcF8a4d2CzNnF2Yj568ZWDa2I/cn3glW5jmU63EJXl h8fTnFTgtecvcN/Buy/4g7RnRTiDDVXiTB1hGSitHDV5DQA4BEwR8y3NvYQLhjCRISfL GQ2+H0n0YadZZm8KD7c53zZGYl7Y1YSokEhvBlr7/dLww3e8j1Vazxa44aKKc36lALTE COA840TRMweSfUC9XJYDJz3g/hFIZSiS4yDfODMOr3Hal8NyJ243Bqt5B2X1/MKJjKaF Q8lxklyV7w1SV37loI0MZxBQwDR+7WNslqtbrG01IL682qWaluAjC55QZR+FZVeXkGp9 VhaQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mMrvrrg8mM+DL+jsj6MYDirdBsHVfhnI5DAY9eMzhGA=; b=HFSYYzVi1IR+0LR82n6bU9pQyuEm3ku6/GeUzKwSjKMPF/BLIlDd8UhURMH44m8CF7 taGlIuIVwzZFj8SOKBRrbFnapMx8nVTS/xitNeX8weE9Gu8zCMFsklz317jcwte5+K1f jOn04VfEhQMT4IQrzq+qzJs2qFwfq/dz5hq6T8VdtK5IwJ6XsBymGm048H05jx3aIOX/ gLUsviMA6vTij62xuMz870U/pRPbuADGf7YUGqAPW/i+/3lrhjO6CwLqF5Y0gu5UHVJ5 nZKywiOY7f3I9hon5YI3AGqc7CMdHX6GM3whEw88/ts8E7jO37zyVEy5SUkLi6UZhCuw lLFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z23-20020aa79497000000b004fa3a8dff75si2225745pfk.44.2022.04.12.13.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:09:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C16A82334; Tue, 12 Apr 2022 12:57:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242362AbiDLCJW (ORCPT + 99 others); Mon, 11 Apr 2022 22:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238348AbiDLCJU (ORCPT ); Mon, 11 Apr 2022 22:09:20 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B9C338AB; Mon, 11 Apr 2022 19:07:04 -0700 (PDT) Received: from kwepemi500004.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Kcps13qKFzBs9n; Tue, 12 Apr 2022 10:02:45 +0800 (CST) Received: from kwepemm600016.china.huawei.com (7.193.23.20) by kwepemi500004.china.huawei.com (7.221.188.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 12 Apr 2022 10:07:02 +0800 Received: from localhost.localdomain (10.67.165.24) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 12 Apr 2022 10:07:01 +0800 From: Guangbin Huang To: , , , CC: , , , , , Subject: [PATCH net-next v2 2/3] net: ethtool: move checks before rtnl_lock() in ethnl_set_rings Date: Tue, 12 Apr 2022 10:01:20 +0800 Message-ID: <20220412020121.14140-3-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220412020121.14140-1-huangguangbin2@huawei.com> References: <20220412020121.14140-1-huangguangbin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Jie Wang Currently these two checks in ethnl_set_rings are added after rtnl_lock() which will do useless works if the request is invalid. So this patch moves these checks before the rtnl_lock() to avoid these costs. Signed-off-by: Jie Wang Signed-off-by: Guangbin Huang --- net/ethtool/rings.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index 9ed60c507d97..fa3ec8d438f7 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -152,6 +152,24 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info) if (!ops->get_ringparam || !ops->set_ringparam) goto out_dev; + if (tb[ETHTOOL_A_RINGS_RX_BUF_LEN] && + !(ops->supported_ring_params & ETHTOOL_RING_USE_RX_BUF_LEN)) { + ret = -EOPNOTSUPP; + NL_SET_ERR_MSG_ATTR(info->extack, + tb[ETHTOOL_A_RINGS_RX_BUF_LEN], + "setting rx buf len not supported"); + goto out_dev; + } + + if (tb[ETHTOOL_A_RINGS_CQE_SIZE] && + !(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) { + ret = -EOPNOTSUPP; + NL_SET_ERR_MSG_ATTR(info->extack, + tb[ETHTOOL_A_RINGS_CQE_SIZE], + "setting cqe size not supported"); + goto out_dev; + } + if (tb[ETHTOOL_A_RINGS_TX_PUSH] && !(ops->supported_ring_params & ETHTOOL_RING_USE_TX_PUSH)) { ret = -EOPNOTSUPP; @@ -201,24 +219,6 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info) goto out_ops; } - if (kernel_ringparam.rx_buf_len != 0 && - !(ops->supported_ring_params & ETHTOOL_RING_USE_RX_BUF_LEN)) { - ret = -EOPNOTSUPP; - NL_SET_ERR_MSG_ATTR(info->extack, - tb[ETHTOOL_A_RINGS_RX_BUF_LEN], - "setting rx buf len not supported"); - goto out_ops; - } - - if (kernel_ringparam.cqe_size && - !(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) { - ret = -EOPNOTSUPP; - NL_SET_ERR_MSG_ATTR(info->extack, - tb[ETHTOOL_A_RINGS_CQE_SIZE], - "setting cqe size not supported"); - goto out_ops; - } - ret = dev->ethtool_ops->set_ringparam(dev, &ringparam, &kernel_ringparam, info->extack); if (ret < 0) -- 2.33.0