From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2F8BC43381 for ; Sun, 24 Feb 2019 11:10:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 90FF920840 for ; Sun, 24 Feb 2019 11:10:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="Q/T/mNYm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728141AbfBXLJp (ORCPT ); Sun, 24 Feb 2019 06:09:45 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43203 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbfBXLJp (ORCPT ); Sun, 24 Feb 2019 06:09:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id d17so6816577wre.10 for ; Sun, 24 Feb 2019 03:09:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZYkxib2bHQyPOnLibTYSmGiYQIiLGIUz11ERuVmHvQo=; b=Q/T/mNYmfEaodkjJdQZvPr7dOrvSsZokP1hJcWUNU2+8QViX4/6JNHReL1PBmQUAIe CllRtHpXBOSusFhOVv+RYzA1G933cT5eLrZYQPua/SgXTps/0VlL/pTeoMry48ksyQl9 C3t5iYk3cwpXwXgRHgxRi646w/0/j7B4VBVpgj+zKiku0qp7vpwYYjdmw0VlTgVW+MAi kYbSJLUQ00ZGm6LRWu7cZ45PJAqe5nGb8YcBMEWY7DC7JfHpNorL/SW4Dd/0YSjZdLYV al3fMU2q3jRIk+sv46AHRonecpXFbV2G1hdSAS41JjlDUT7jAU5ve3QdUF6798Zgod7F NFpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZYkxib2bHQyPOnLibTYSmGiYQIiLGIUz11ERuVmHvQo=; b=Dsp5UnqzUpjQJHc02TJniOSD4tQiW7YLbmXFu1BFIUmfa9eN4q6AT1dn5nSWlyUyyb /JGajgd48uRqWd+JiL9m2wWqc37X7F5GhdlKop39uIRkAcNV1TS0he6xCF2Qq93W+L+5 hkrlAWrqQd/UmxYP2Kf0POvLhZgycH5Ixad9NAQ8B680DHeONYgKyV3wccpQuDZmGzoE Dt/zCsT4GfL1KWHjURvftV4CvL8UrsKKLd1HEhxy793uca1xgFxsc4aRP4cCsTScin+c aRUOKz3H4BDgUEEvU8bo64S7K/LCJUaMLrnps4Y2U5AHmbv3IXj4MfpUrUXm+X+eVYoF sZ5Q== X-Gm-Message-State: AHQUAua6tgCN7C9eQEBhqQx7vBavoKnrf/I3WMcRvU7Rn+3b+FDUXNi4 nqx4K/D/ZtqG3VWy6JH583kMPg== X-Google-Smtp-Source: AHgI3IahlWSvStcuz5bawmONViR7ODi5L3Hp4XxzkwbI/NxypKlPmT6xWLdHZi3bTgGlrQ29vr65wQ== X-Received: by 2002:adf:ff81:: with SMTP id j1mr9145376wrr.261.1551006583545; Sun, 24 Feb 2019 03:09:43 -0800 (PST) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id d21sm21172459wrc.44.2019.02.24.03.09.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Feb 2019 03:09:43 -0800 (PST) Date: Sun, 24 Feb 2019 12:00:03 +0100 From: Jiri Pirko To: Jakub Kicinski Cc: davem@davemloft.net, mkubecek@suse.cz, andrew@lunn.ch, f.fainelli@gmail.com, netdev@vger.kernel.org, oss-drivers@netronome.com Subject: Re: [PATCH net-next v3 5/6] devlink: hold a reference to the netdevice around ethtool compat Message-ID: <20190224110003.GI2759@nanopsycho.orion> References: <20190222220758.7117-1-jakub.kicinski@netronome.com> <20190222220758.7117-6-jakub.kicinski@netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190222220758.7117-6-jakub.kicinski@netronome.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Fri, Feb 22, 2019 at 11:07:56PM CET, jakub.kicinski@netronome.com wrote: >When ethtool is calling into devlink compat code make sure we have >a reference on the netdevice on which the operation was invoked. > >v3: move the hold/lock logic into devlink_compat_* functions (Florian) > >Signed-off-by: Jakub Kicinski >--- > net/core/devlink.c | 34 +++++++++++++++++++++++----------- > net/core/ethtool.c | 13 ++----------- > 2 files changed, 25 insertions(+), 22 deletions(-) > >diff --git a/net/core/devlink.c b/net/core/devlink.c >index a13055160be0..78c6ea1870ca 100644 >--- a/net/core/devlink.c >+++ b/net/core/devlink.c >@@ -6430,27 +6430,39 @@ void devlink_compat_running_version(struct net_device *dev, > { > struct devlink *devlink; > >+ dev_hold(dev); >+ rtnl_unlock(); Ha, I got it now. You rely on dev_hold to make sure the devlink instance does not dissappear. But until this patch, that is not guaranteed (or I'm missing it). >+ > devlink = netdev_to_devlink(dev); >- if (!devlink || !devlink->ops || !devlink->ops->info_get) >- return; >+ if (devlink && devlink->ops && devlink->ops->info_get) { >+ mutex_lock(&devlink->lock); >+ __devlink_compat_running_version(devlink, buf, len); >+ mutex_unlock(&devlink->lock); >+ } > >- mutex_lock(&devlink->lock); >- __devlink_compat_running_version(devlink, buf, len); >- mutex_unlock(&devlink->lock); >+ rtnl_lock(); >+ dev_put(dev); > } > > int devlink_compat_flash_update(struct net_device *dev, const char *file_name) > { > struct devlink *devlink; >- int ret; >+ int ret = -EOPNOTSUPP; >+ >+ dev_hold(dev); >+ rtnl_unlock(); > > devlink = netdev_to_devlink(dev); >- if (!devlink || !devlink->ops || !devlink->ops->flash_update) >- return -EOPNOTSUPP; >+ if (devlink && devlink->ops && devlink->ops->flash_update) { >+ mutex_lock(&devlink->lock); >+ ret = devlink->ops->flash_update(devlink, file_name, >+ NULL, NULL); >+ mutex_unlock(&devlink->lock); >+ } >+ >+ rtnl_lock(); >+ dev_put(dev); > >- mutex_lock(&devlink->lock); >- ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL); >- mutex_unlock(&devlink->lock); > return ret; > } > >diff --git a/net/core/ethtool.c b/net/core/ethtool.c >index 1320e8dce559..47558ffae423 100644 >--- a/net/core/ethtool.c >+++ b/net/core/ethtool.c >@@ -805,11 +805,9 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, > if (ops->get_eeprom_len) > info.eedump_len = ops->get_eeprom_len(dev); > >- rtnl_unlock(); > if (!info.fw_version[0]) > devlink_compat_running_version(dev, info.fw_version, > sizeof(info.fw_version)); >- rtnl_lock(); > > if (copy_to_user(useraddr, &info, sizeof(info))) > return -EFAULT; >@@ -2040,15 +2038,8 @@ static noinline_for_stack int ethtool_flash_device(struct net_device *dev, > return -EFAULT; > efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; > >- if (!dev->ethtool_ops->flash_device) { >- int ret; >- >- rtnl_unlock(); >- ret = devlink_compat_flash_update(dev, efl.data); >- rtnl_lock(); >- >- return ret; >- } >+ if (!dev->ethtool_ops->flash_device) >+ return devlink_compat_flash_update(dev, efl.data); > > return dev->ethtool_ops->flash_device(dev, &efl); > } >-- >2.19.2 >