Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3910300ybl; Mon, 13 Jan 2020 04:52:38 -0800 (PST) X-Google-Smtp-Source: APXvYqw6knrTLiRmUBt5dVpkc3BGrUfMAN/i9Be5KMpKhtPZ4jQVd5ttClrtRijSbLujF78Iepph X-Received: by 2002:a9d:68cc:: with SMTP id i12mr12525011oto.207.1578919958334; Mon, 13 Jan 2020 04:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578919958; cv=none; d=google.com; s=arc-20160816; b=iVnjA03FYtpetrdB85Eep5hTz3NJC59D5sUiL2o6423EarIoDw060YB2LOhlCN3+ZM gZwAXXyU+ouQFUx6p5BHdBRTOrBsIhTLqtUCM8m9TtVtiOtdEYG0SEmNquZu63cyo//1 4fpIdRAj+OJDzXkTuqLj2L9pPUV5GZHVYpDM6vwnRI+11xW6rYc+JT24u1hKvCLv9gAL vWQng65thqr2LehH+RLq27sRQZmfWl8F3NQ36fTYtllRnD9SXJIX+rVl6Ld8cE/BEFB4 agQoR4fwy64LMoiHEFXuTzQikjFTMWn9/FPF97c3kqqc2xX9Rx2rIGQH19fLuw90Kj4R uuYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=XKNQ+tt211jA+KEwDchLFrOvUoUdF8I/APDhUfyLJLs=; b=OEzc9knYu5oEnXCb6icXYMI0tPjaxLF8h4JD+ymUZn8axHZzZdG96wV1/0gxBfw+VG csfhR/jl+q4AUP37TuUiBmvAhsESnt6Cwwj/UdmL2XVrTIeHwuR0mBefgewJZBvjByf4 6f9W5Nh9CCVm8B85nB1+jBfsw78WhEprRF0OSOqsz98cL38mNjn3GVzAiU9fRSGa1Y8+ xFlG6O4PmylnjwyKIGLSyaW47vbBbqXAmheMx5rsLjy6tEcm8e6SWcjkhHhsP0rq6YPS cUt1IwzJ1oZWW0mBAktZUACeSJyjQFBOvZ3Ng5jBzuPLgW1PE43QDBoxa5y/d84jhvKL Q9Rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l204si5562616oig.31.2020.01.13.04.52.26; Mon, 13 Jan 2020 04:52:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728689AbgAMMvd (ORCPT + 99 others); Mon, 13 Jan 2020 07:51:33 -0500 Received: from mx2.suse.de ([195.135.220.15]:44914 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbgAMMvc (ORCPT ); Mon, 13 Jan 2020 07:51:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CEAC2ACC9; Mon, 13 Jan 2020 12:51:30 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 28CC0E3C1F; Mon, 13 Jan 2020 13:51:29 +0100 (CET) Date: Mon, 13 Jan 2020 13:51:29 +0100 From: Michal Kubecek To: netdev@vger.kernel.org Cc: Kai-Heng Feng , davem@davemloft.ne, jeffrey.t.kirsher@intel.com, "David S. Miller" , Florian Fainelli , Jiri Pirko , Pablo Neira Ayuso , Maxime Chevallier , Jakub Kicinski , Li RongQing , open list Subject: Re: [PATCH 2/2] ethtool: Call begin() and complete() in __ethtool_get_link_ksettings() Message-ID: <20200113125129.GD25361@unicorn.suse.cz> References: <20200110074159.18473-1-kai.heng.feng@canonical.com> <20200110074159.18473-2-kai.heng.feng@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200110074159.18473-2-kai.heng.feng@canonical.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 10, 2020 at 03:41:59PM +0800, Kai-Heng Feng wrote: > Device like igb gets runtime suspended when there's no link partner. We > can't get correct speed under that state: > $ cat /sys/class/net/enp3s0/speed > 1000 > > In addition to that, an error can also be spotted in dmesg: > [ 385.991957] igb 0000:03:00.0 enp3s0: PCIe link lost > > It's because the igb device doesn't get runtime resumed before calling > get_link_ksettings(). > > So let's call begin() and complete() like what dev_ethtool() does, to > runtime resume/suspend or power up/down the device properly. > > Once this fix is in place, igb can show the speed correctly without link > partner: > $ cat /sys/class/net/enp3s0/speed > -1 I agree that we definitely should make sure ->begin() and ->complete() are always called around ethtool_ops calls. But even if nesting should be safe now (for in-tree drivers, that is), I'm not really happy about calling them even in places where we positively know we are always inside a begin / complete block as e.g. vxlan or net_failover do. (And also linkinfo.c and linkmodes.c but it may be easier to call ->get_link_ksettings() directly there.) How about having two helpers: one simple for "ethtool context" where we know we already are between ->begin() and ->complete() and one with the begin/complete calls for the rest? Another interesting question is if any of the callers which do not have their own begin()/complete() wrap does actually need anything more than speed and duplex (I didn't do a full check). Michal > Signed-off-by: Kai-Heng Feng > --- > net/ethtool/ioctl.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c > index 182bffbffa78..c768dbf45fc4 100644 > --- a/net/ethtool/ioctl.c > +++ b/net/ethtool/ioctl.c > @@ -423,13 +423,26 @@ struct ethtool_link_usettings { > int __ethtool_get_link_ksettings(struct net_device *dev, > struct ethtool_link_ksettings *link_ksettings) > { > + int rc; > + > ASSERT_RTNL(); > > if (!dev->ethtool_ops->get_link_ksettings) > return -EOPNOTSUPP; > > + if (dev->ethtool_ops->begin) { > + rc = dev->ethtool_ops->begin(dev); > + if (rc < 0) > + return rc; > + } > + > memset(link_ksettings, 0, sizeof(*link_ksettings)); > - return dev->ethtool_ops->get_link_ksettings(dev, link_ksettings); > + rc = dev->ethtool_ops->get_link_ksettings(dev, link_ksettings); > + > + if (dev->ethtool_ops->complete) > + dev->ethtool_ops->complete(dev); > + > + return rc; > } > EXPORT_SYMBOL(__ethtool_get_link_ksettings); > > -- > 2.17.1 >