Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp865044rwr; Wed, 3 May 2023 07:13:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4oPhMqBQSi+rLApxn7qK3BzlH8nKS4Ky0dlkr/mV6uJILTPYmPZpI0YEJL4Sj5pI3MUIvq X-Received: by 2002:a17:903:244b:b0:1ab:109e:a53f with SMTP id l11-20020a170903244b00b001ab109ea53fmr5955883pls.2.1683123202722; Wed, 03 May 2023 07:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683123202; cv=none; d=google.com; s=arc-20160816; b=ClsV1waKajej1h3spRchuSP3uCbXkWUJY9HCwxVd6EuGlr1mFT7tczjssIfron89KU OW2EgUaBiglI9bNwy/dy+ZmdM5d6xPW5XUg3IZJdR1T+unw3PZKefTIYiCbEEL9R2H6m TDoRVySglrlgC23wscVYY32dGuQrXiBaua1sbc3vAMOgrj2oWYY1VSNI06QwgBRqGuYX 027fB8Yf4cInOv4xnuaqVSolKEqyqVZnvkp48T2HjsOi+kWPx+Cl8aaTTzP2+WpI/mMX xcrQJqZ3Uj8Q/t7bqQXVMFIwIkZISHFaOU0Y5Un02oJwWiN485HjU//vMvLZCmDZ3GrQ JXEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=0MoVzGjxxWPTbyT7NHsMM7ST+GXUWd2MvKkYa9A75U0=; b=b5d93KM4yVtxvjW2Dr9DuSi0in24EIcPzNPPZO2+pabLbLVytvr+KBVWbZ98aQDCQF Iiv2ESsjqqG6aK7RjZcPIXNFqAAIAxX1b09nE34d+BoY39XIWsua40B8uXUKh2gacUtv HabNWEMZHHuxkSnhWkMZh1PzmTxqrZWa3Y1ix/T3dL4hLFC2N8rHl53u31SGiyD1/bdH gEyMWIL7VagAsxHuTLAPOevSWpRX/IDb5NvRUx613vwOPooPuXwaf3te3YDBO6XtaQbC C0CPP9Eq74efy0ENSQMvkoNd+JRQYS0pzKnZAHbAOSXVAUOnGd6upXlA53JVvI0emm1p rvLQ== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m24-20020a17090aab1800b0024e2bb99e67si1569507pjq.7.2023.05.03.07.13.07; Wed, 03 May 2023 07:13:22 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbjECOBF (ORCPT + 99 others); Wed, 3 May 2023 10:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjECOBD (ORCPT ); Wed, 3 May 2023 10:01:03 -0400 Received: from mail-m11876.qiye.163.com (mail-m11876.qiye.163.com [115.236.118.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5555C5597; Wed, 3 May 2023 07:00:59 -0700 (PDT) Received: from [IPV6:240e:3b7:327f:5c30:3c7d:9d61:755a:9449] (unknown [IPV6:240e:3b7:327f:5c30:3c7d:9d61:755a:9449]) by mail-m11876.qiye.163.com (Hmail) with ESMTPA id DD8973C0341; Wed, 3 May 2023 22:00:49 +0800 (CST) Message-ID: Date: Wed, 3 May 2023 22:00:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 From: Ding Hui Subject: Re: [PATCH net v4 2/2] iavf: Fix out-of-bounds when setting channels on remove To: Leon Romanovsky Cc: dinghui@sangfor.com.cn, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, intel-wired-lan@lists.osuosl.org, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, keescook@chromium.org, grzegorzx.szczurek@intel.com, mateusz.palczewski@intel.com, mitch.a.williams@intel.com, gregory.v.rose@intel.com, jeffrey.t.kirsher@intel.com, michal.kubiak@intel.com, simon.horman@corigine.com, madhu.chittim@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, pengdonglin@sangfor.com.cn, huangcun@sangfor.com.cn References: <20230503031541.27855-1-dinghui@sangfor.com.cn> <20230503031541.27855-3-dinghui@sangfor.com.cn> <20230503082458.GH525452@unreal> Content-Language: en-US In-Reply-To: <20230503082458.GH525452@unreal> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZH0MeVksZS05LGh0eHUpLSlUTARMWGhIXJBQOD1 lXWRgSC1lBWUlPSx5BSBlMQUhJTB1BThhIS0FIGEwfQUIfTUpBTE5OGkFCT09CWVdZFhoPEhUdFF lBWU9LSFVKSktISkxVSktLVUtZBg++ X-HM-Tid: 0a87e1ea708f2eb2kusndd8973c0341 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6ORg6Qzo4Lj0TIzkvPjdCTR0Q Cx4aCwpVSlVKTUNISklJT05LQkxIVTMWGhIXVR8SFRwTDhI7CBoVHB0UCVUYFBZVGBVFWVdZEgtZ QVlJT0seQUgZTEFISUwdQU4YSEtBSBhMH0FCH01KQUxOThpBQk9PQllXWQgBWUFPQ09NNwY+ X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 On 2023/5/3 4:24 下午, Leon Romanovsky wrote: > On Wed, May 03, 2023 at 11:15:41AM +0800, Ding Hui wrote: >> >> If we detected removing is in processing, we can avoid unnecessary >> waiting and return error faster. >> >> On the other hand in timeout handling, we should keep the original >> num_active_queues and reset num_req_queues to 0. >> >> Fixes: 4e5e6b5d9d13 ("iavf: Fix return of set the new channel count") >> Signed-off-by: Ding Hui >> Cc: Donglin Peng >> Cc: Huang Cun >> Reviewed-by: Simon Horman >> Reviewed-by: Michal Kubiak >> --- >> v3 to v4: >> - nothing changed >> >> v2 to v3: >> - fix review tag >> >> v1 to v2: >> - add reproduction script >> >> --- >> drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c >> index 6f171d1d85b7..d8a3c0cfedd0 100644 >> --- a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c >> +++ b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c >> @@ -1857,13 +1857,15 @@ static int iavf_set_channels(struct net_device *netdev, >> /* wait for the reset is done */ >> for (i = 0; i < IAVF_RESET_WAIT_COMPLETE_COUNT; i++) { >> msleep(IAVF_RESET_WAIT_MS); >> + if (test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) >> + return -EOPNOTSUPP; > > This makes no sense without locking as change to __IAVF_IN_REMOVE_TASK > can happen any time. > The state doesn't need to be that precise here, it is optimized only for the fast path. During the lifecycle of the adapter, the __IAVF_IN_REMOVE_TASK state will only be set and not cleared. If we didn't detect the "removing" state, we also can fallback to timeout handling. So I don't think the locking is necessary here, what do the maintainers at Intel think? > Thanks > >> if (adapter->flags & IAVF_FLAG_RESET_PENDING) >> continue; >> break; >> } >> if (i == IAVF_RESET_WAIT_COMPLETE_COUNT) { >> adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; >> - adapter->num_active_queues = num_req; >> + adapter->num_req_queues = 0; >> return -EOPNOTSUPP; >> } >> >> -- >> 2.17.1 >> >> > -- Thanks, -dinghui