From patchwork Sun Aug 1 10:36:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12412887 X-Patchwork-Delegate: kuba@kernel.org 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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 C8F44C4338F for ; Sun, 1 Aug 2021 10:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EE6961054 for ; Sun, 1 Aug 2021 10:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbhHAKlt (ORCPT ); Sun, 1 Aug 2021 06:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231470AbhHAKls (ORCPT ); Sun, 1 Aug 2021 06:41:48 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB984C06175F for ; Sun, 1 Aug 2021 03:41:39 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id z4so17847172wrv.11 for ; Sun, 01 Aug 2021 03:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/1WaO1XF2pP2CJ+ONM55A1kyCoUU1Cdv5L4sGMe68I8=; b=iZ3n3Cg2kAjXdU52jnluXOb5Z7HeSXXq9y2iN+VCMSSiRwVGyYL/26v000Ut+pWzlE MB9GlJDQlgXGJnMoRS0fLh6Xi5MGj4dxy31WdyGqkSuZe5WnfB7onJOPwo3X+Xwisz2X 6368oir0YvcRoM1s3SpSgKhtb4Bt/rx4e4w2oqNwsFz+i40RP5WlctvmRHp1C7R3RuAz ySEw49nr/ygxturJPCZe0c3NHVzMK/uTIPGiSXL4dNW7hm4w00NNtsIc2pZV1GuYw7SM QeYMG6CIdjcnCqwP9nw2TJ9rRzdjWTqYuNiTndZY1u+nii2sfUzlzxDAfqTq9vZj8D9F VqZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/1WaO1XF2pP2CJ+ONM55A1kyCoUU1Cdv5L4sGMe68I8=; b=SPNrOEjq7ih7jZOlWatSIa0EHyZ50q3JGHtywXs7SieEAM37U196dLVHRyy9ONLHSW JEaq7L4UISkqRl/itM7OX5BUlqmLDcyBIspC37LSGPG8vyxvgLBv2/je1Sz1uZ5tV1BD Ym5vWV12W2Lg6OwqQOgTk97LcLDOQgbWp8HhpBAA6KmXltDIncmVpjK4CgEOacdAL4F8 Ug/mM5Davcw3EIzk6W29gxG5424oUb9UUoKLQI62VvHorGEuK5aroc6QVJHyUuQvuFJp mBTHjXZwa0OAx/TcvbHYrt0z5wcLjz+ke5yfjFmChFXWRSxRFoGE5Rhib/SHOn8TyK6q YwdQ== X-Gm-Message-State: AOAM532tnteTp/XEIyU4GSFkrSUJDvkvH+jHSSK7iUA7sxMN1Klp9XZj 62OrR4ZNv4v/4Hy/1d+AwQeX2+2S6f6QCQ== X-Google-Smtp-Source: ABdhPJwsU/aDrYdIHGSQCXoSwt3J1JeYoOBznGcwJKjjNTtu5XVzwBssrGBDG27PR+U6WC1LtC9nLw== X-Received: by 2002:a5d:4ac5:: with SMTP id y5mr12349353wrs.125.1627814498017; Sun, 01 Aug 2021 03:41:38 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:9d9e:757:f317:c524? (p200300ea8f10c2009d9e0757f317c524.dip0.t-ipconnect.de. [2003:ea:8f10:c200:9d9e:757:f317:c524]) by smtp.googlemail.com with ESMTPSA id i7sm7969590wre.64.2021.08.01.03.41.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Aug 2021 03:41:37 -0700 (PDT) Subject: [PATCH net-next 1/4] ethtool: runtime-resume netdev parent before ethtool ioctl ops From: Heiner Kallweit To: Jakub Kicinski , David Miller Cc: "netdev@vger.kernel.org" References: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Message-ID: Date: Sun, 1 Aug 2021 12:36:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If a network device is runtime-suspended then: - network device may be flagged as detached and all ethtool ops (even if not accessing the device) will fail because netif_device_present() returns false - ethtool ops may fail because device is not accessible (e.g. because being in D3 in case of a PCI device) It may not be desirable that userspace can't use even simple ethtool ops that not access the device if interface or link is down. To be more friendly to userspace let's ensure that device is runtime-resumed when executing the respective ethtool op in kernel. Signed-off-by: Heiner Kallweit --- net/ethtool/ioctl.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index baa5d1004..b7ff9abe7 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -2589,7 +2590,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) int rc; netdev_features_t old_features; - if (!dev || !netif_device_present(dev)) + if (!dev) return -ENODEV; if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) @@ -2645,10 +2646,18 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) return -EPERM; } + if (dev->dev.parent) + pm_runtime_get_sync(dev->dev.parent); + + if (!netif_device_present(dev)) { + rc = -ENODEV; + goto out; + } + if (dev->ethtool_ops->begin) { rc = dev->ethtool_ops->begin(dev); - if (rc < 0) - return rc; + if (rc < 0) + goto out; } old_features = dev->features; @@ -2867,6 +2876,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) if (old_features != dev->features) netdev_features_change(dev); +out: + if (dev->dev.parent) + pm_runtime_put(dev->dev.parent); return rc; } From patchwork Sun Aug 1 10:37:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12412889 X-Patchwork-Delegate: kuba@kernel.org 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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 BE1ACC4338F for ; Sun, 1 Aug 2021 10:41:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E2FE604AC for ; Sun, 1 Aug 2021 10:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbhHAKlv (ORCPT ); Sun, 1 Aug 2021 06:41:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbhHAKlt (ORCPT ); Sun, 1 Aug 2021 06:41:49 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDE5C0613CF for ; Sun, 1 Aug 2021 03:41:40 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id u15so8670224wmj.1 for ; Sun, 01 Aug 2021 03:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=2WWj+94d/3vPbrhlJEinj3ISedWMhj8sWR62bmr9umo=; b=jskFl1+RI4WDC4zGvehfAKJY3UBe6UPFLXNuLJVwBHCkQx/b/AURVdbALoWiPexMTb bnwRavbX7ak0DNW0UfL/5s+fox17CbMPVGYUa0yR90HsfwcrIrHYPGw6oTL0WVe/chSx sYmhlpbh+OIAAsO+63ptsRwBjR0pqwHKb5W8RRrMmSrv8UCdTxpXDW5JhgWeVrNyxG0f CsGVOMiMJ+2Meb8QsVTN7c1G7VaFLx0P5UiVtbFmkvYk9sbjmA73ygPp/Eat6eKZ6Yl0 sDUuKdEc3JcziG2IYgMgrIzQy5MJxGMAqDOmhU/kTzd5TqSwUIjCaZhuzhqmV707qsu/ PW+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=2WWj+94d/3vPbrhlJEinj3ISedWMhj8sWR62bmr9umo=; b=temiGbMMne/dyHIzndo9HpJSIW6lkKRAqedl7v48hC8cvmtp5eLzkutcVsRlrx0kB7 o4pcQUsfjg/h24FBguIpn53eAaLqVJ2mMo7uO4c4EG9g2d1+YjFPN2+IQ4r3JbKBif44 BB1c5AvrgSzKZ/3KKtUZQpJdcH1VhApgXAgl9aWs6hAwopInabkSDxRCm1E0/62SVgOO WRIA+PiaSDznX87/ENZ2uXrvT+MBpmiSILgyiLkl+hhFNOZN6YnSzh8e3iwzycplQXMJ PXya8ms+fv+UY1i7IeCO65uPajRB5XIqBxMQtc08dRCO78spoVCMT8PRnM37Pe5C4Cgv vLJg== X-Gm-Message-State: AOAM530Icv6TGipV/GHX6ZXM+BChUdR8radJXKkPgw/ge1FMiA9Lellp NdX0wTPB8KZpxajmFjSB9nlFsQTGhshp5g== X-Google-Smtp-Source: ABdhPJxlz6rv/aZ9ITHj5k6xfOhABRKBYFWo5NAmIEQ4YlMaC/H0d+ACjU0m28to3lQKC/dGqWksig== X-Received: by 2002:a05:600c:3b9b:: with SMTP id n27mr12003718wms.188.1627814499006; Sun, 01 Aug 2021 03:41:39 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:9d9e:757:f317:c524? (p200300ea8f10c2009d9e0757f317c524.dip0.t-ipconnect.de. [2003:ea:8f10:c200:9d9e:757:f317:c524]) by smtp.googlemail.com with ESMTPSA id v15sm7601751wmj.39.2021.08.01.03.41.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Aug 2021 03:41:38 -0700 (PDT) Subject: [PATCH net-next 2/4] ethtool: move implementation of ethnl_ops_begin/complete to netlink.c From: Heiner Kallweit To: Jakub Kicinski , David Miller Cc: "netdev@vger.kernel.org" References: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Message-ID: <8de343c4-f34c-1f31-5be0-8ce6ca1dc19a@gmail.com> Date: Sun, 1 Aug 2021 12:37:39 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In preparation of subsequent extensions to both functions move the implementations from netlink.h to netlink.c. Signed-off-by: Heiner Kallweit --- net/ethtool/netlink.c | 14 ++++++++++++++ net/ethtool/netlink.h | 15 ++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 73e0f5b62..ac720d684 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -29,6 +29,20 @@ const struct nla_policy ethnl_header_policy_stats[] = { ETHTOOL_FLAGS_STATS), }; +int ethnl_ops_begin(struct net_device *dev) +{ + if (dev && dev->ethtool_ops->begin) + return dev->ethtool_ops->begin(dev); + else + return 0; +} + +void ethnl_ops_complete(struct net_device *dev) +{ + if (dev && dev->ethtool_ops->complete) + dev->ethtool_ops->complete(dev); +} + /** * ethnl_parse_header_dev_get() - parse request header * @req_info: structure to put results into diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 3fc395c86..077aac392 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -247,19 +247,8 @@ struct ethnl_reply_data { struct net_device *dev; }; -static inline int ethnl_ops_begin(struct net_device *dev) -{ - if (dev && dev->ethtool_ops->begin) - return dev->ethtool_ops->begin(dev); - else - return 0; -} - -static inline void ethnl_ops_complete(struct net_device *dev) -{ - if (dev && dev->ethtool_ops->complete) - dev->ethtool_ops->complete(dev); -} +int ethnl_ops_begin(struct net_device *dev); +void ethnl_ops_complete(struct net_device *dev); /** * struct ethnl_request_ops - unified handling of GET requests From patchwork Sun Aug 1 10:40:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12412891 X-Patchwork-Delegate: kuba@kernel.org 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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 AB4EEC432BE for ; Sun, 1 Aug 2021 10:41:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E706610CE for ; Sun, 1 Aug 2021 10:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231803AbhHAKlx (ORCPT ); Sun, 1 Aug 2021 06:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbhHAKlu (ORCPT ); Sun, 1 Aug 2021 06:41:50 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92BA8C06175F for ; Sun, 1 Aug 2021 03:41:41 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id l18so17822925wrv.5 for ; Sun, 01 Aug 2021 03:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=0VZIUu6dLplavofQc8GARE/eHYZjxQlYMRjSNgOND94=; b=Jqcsv0z5NXvM809recF4DcloV/kxXC4OCDjS54nP73XHQpp20GvZmDj5oy1K6IHIv7 y03NvlLkRN+IY6dKOQGEwwWZLbc3v3dKUTWHDYzoi+eOpxAgCJwI8IIX2cIH8i+nbvr8 Wt4W0EGhOHkh5bePvVguW8neg1xKn2jr4BWf3XivzaNcL3MeOMjY+EwIgAZyJfwFZqQC rjfc0zo/o6y0B1MncuDDJNSal5x/OqW+xEgT/r5rdjUAhQ/R2Aesyg/5FjLwxWS0ExN7 q9lpxbGExUNc48jXLUKe6WcSbvVMu+9DPgw1P3pbZPXe1GwoXWl0TzhU21Cmy0KnJKQ+ CEGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=0VZIUu6dLplavofQc8GARE/eHYZjxQlYMRjSNgOND94=; b=AvvBh0KsNqrHc//183ktJKtzfisnqMx2fQpgbtBWDpNo1Hj7SnjjQRmgLA5EA3W7n/ I4yRWLxu5ncc+dEgh6eHAdSMYbsGSZW+Zdw7sGvcWqBaW0PAHGQ7bWPUq2jh08aqLSV+ nXkaj49wv1n9YnloOmrew/tI4J0baqsT0EHipfhwExTmYjYI4jLxxoOD+fU7x9DlR1R/ kOLsvkrGDdg0K5rM7P9XJjY14XnENMfQWNsWftuHuZPYWhTDjcVT693DlZLr/Des+Lln kQaP9HvQ8h+oQTOgCrTvo/ypvuLH86Uwmt8SwMViyaTOHIotxks2FbdoXjenqBmYOhow 8CsQ== X-Gm-Message-State: AOAM531x1nOFZCb+ITi2lcPmaIXXEVhGeGu1+R/iaPzIztwnHE80+xZ9 XXPeHGsxn9ssyWpygHy+SnCgXWmpglYTnw== X-Google-Smtp-Source: ABdhPJxTX22o6b7JYWMhJ/H4opUDN3K4oeA6TvZCs5duiPtjwnG7S9zjewaM2l5ys2e462GcAgbvuA== X-Received: by 2002:adf:d219:: with SMTP id j25mr12309929wrh.82.1627814499995; Sun, 01 Aug 2021 03:41:39 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:9d9e:757:f317:c524? (p200300ea8f10c2009d9e0757f317c524.dip0.t-ipconnect.de. [2003:ea:8f10:c200:9d9e:757:f317:c524]) by smtp.googlemail.com with ESMTPSA id l41sm7696353wmp.23.2021.08.01.03.41.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Aug 2021 03:41:39 -0700 (PDT) Subject: [PATCH net-next 3/4] ethtool: move netif_device_present check from ethnl_parse_header_dev_get to ethnl_ops_begin From: Heiner Kallweit To: Jakub Kicinski , David Miller Cc: "netdev@vger.kernel.org" References: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Message-ID: <82cd410f-8e0e-86d1-031c-bbb43c315574@gmail.com> Date: Sun, 1 Aug 2021 12:40:05 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If device is runtime-suspended and not accessible then it may be flagged as not present. If checking whether device is present is done too early then we may bail out before we have the chance to runtime-resume the device. Therefore move this check to ethnl_ops_begin(). This is in preparation of a follow-up patch that tries to runtime-resume the device before executing ethtool ops. Signed-off-by: Heiner Kallweit --- net/ethtool/netlink.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index ac720d684..e628d17f5 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -31,7 +31,13 @@ const struct nla_policy ethnl_header_policy_stats[] = { int ethnl_ops_begin(struct net_device *dev) { - if (dev && dev->ethtool_ops->begin) + if (!dev) + return 0; + + if (!netif_device_present(dev)) + return -ENODEV; + + if (dev->ethtool_ops->begin) return dev->ethtool_ops->begin(dev); else return 0; @@ -115,12 +121,6 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info, return -EINVAL; } - if (dev && !netif_device_present(dev)) { - dev_put(dev); - NL_SET_ERR_MSG(extack, "device not present"); - return -ENODEV; - } - req_info->dev = dev; req_info->flags = flags; return 0; From patchwork Sun Aug 1 10:41:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12412893 X-Patchwork-Delegate: kuba@kernel.org 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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 B5C29C4338F for ; Sun, 1 Aug 2021 10:41:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EEBB604AC for ; Sun, 1 Aug 2021 10:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231882AbhHAKlz (ORCPT ); Sun, 1 Aug 2021 06:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231518AbhHAKlv (ORCPT ); Sun, 1 Aug 2021 06:41:51 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EAFDC0613CF for ; Sun, 1 Aug 2021 03:41:42 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id n11so8667354wmd.2 for ; Sun, 01 Aug 2021 03:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=IslbLMsuod0jSlf4z955FHKvdh7uY9Nxm+1MXV7oAlk=; b=Amq4X3Ai1G2uniprYP8QDwp5LueoyVPVghc0oS9tVGdUYF/WbiGsz/wYCrW5Z9WlOG 5cJY0gVh8mjSo3mKQzmhivY2xlFiVTopxPfBdAc+TQYCXv+S8xTWxKVX4LW3XCYPe2WW UmFWvYHE38mb3HW3fKJyQkrrPkKyFrIk3zvnrLCs6P1qQtPDwyOtENcNbPn+7njJc0P6 5IqYHGn2pJhf1ST96DLobOmLaaihTx29SAJMUbekWiwx8hH3ixWAwMEh5NfWLJvukr+1 G0z8C3OKZSnO9/cN3SBfQH6NnmFW+V3bWCx/Q8YOWyiQdixYxzTULaxrbiaDeVhyfWZD qrfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=IslbLMsuod0jSlf4z955FHKvdh7uY9Nxm+1MXV7oAlk=; b=Y1d6DmFn49RoDrKF5iHiSVlOsxZ803vM5Fzh9OQ4IGcTYXOgx31Um0hpVn/kAYAiIE HvX4zQuQ1hiKAoQX0OPzx2ShgGG0B8JSuvAvYCm7zzrds5vs24u5kQ0YteTa+uWPI4oy BJhQkY2cTQIEXHqhwbttRJ6Ro/ahUtzgUSeYMjIBZwlRhldurYXYAcI44nvfesG31ULb CfPDfqU6YjSzuUh/K5z22UbxJW/bX7gvE44VurYyDENQu/SxqLos0MTJ+j9m2xQsa6/x pWpfCzSnBNv4U2iqW8qMjJxatUeQuwmlYkCLR5xz29Apu7l73kulZievhDnq3LwdvRUr 0PUA== X-Gm-Message-State: AOAM530oXkaB+jfrbnhqRSV//5oqDHqoUDt4Zcce4VxkmCJ6ydb6kb0K NCdPgD46+57I0AL5uOHJWL8xm3WPzEQ+Xg== X-Google-Smtp-Source: ABdhPJx4hTxnhO83LsxZQwb6jMK1PkrMF+SQxb9K2q2Lfnxa/evMS+epgkVcVVAUBMEdM2nvrKKinQ== X-Received: by 2002:a1c:acca:: with SMTP id v193mr11838830wme.107.1627814500920; Sun, 01 Aug 2021 03:41:40 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:9d9e:757:f317:c524? (p200300ea8f10c2009d9e0757f317c524.dip0.t-ipconnect.de. [2003:ea:8f10:c200:9d9e:757:f317:c524]) by smtp.googlemail.com with ESMTPSA id v15sm7601822wmj.39.2021.08.01.03.41.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Aug 2021 03:41:40 -0700 (PDT) Subject: [PATCH net-next 4/4] ethtool: runtime-resume netdev parent in ethnl_ops_begin From: Heiner Kallweit To: Jakub Kicinski , David Miller Cc: "netdev@vger.kernel.org" References: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Message-ID: <05bae6c6-502e-4715-1283-fc4135702515@gmail.com> Date: Sun, 1 Aug 2021 12:41:31 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If a network device is runtime-suspended then: - network device may be flagged as detached and all ethtool ops (even if not accessing the device) will fail because netif_device_present() returns false - ethtool ops may fail because device is not accessible (e.g. because being in D3 in case of a PCI device) It may not be desirable that userspace can't use even simple ethtool ops that not access the device if interface or link is down. To be more friendly to userspace let's ensure that device is runtime-resumed when executing the respective ethtool op in kernel. Signed-off-by: Heiner Kallweit --- net/ethtool/netlink.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index e628d17f5..417aaf9ca 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -2,6 +2,7 @@ #include #include +#include #include "netlink.h" static struct genl_family ethtool_genl_family; @@ -31,22 +32,40 @@ const struct nla_policy ethnl_header_policy_stats[] = { int ethnl_ops_begin(struct net_device *dev) { + int ret; + if (!dev) return 0; - if (!netif_device_present(dev)) - return -ENODEV; + if (dev->dev.parent) + pm_runtime_get_sync(dev->dev.parent); - if (dev->ethtool_ops->begin) - return dev->ethtool_ops->begin(dev); - else - return 0; + if (!netif_device_present(dev)) { + ret = -ENODEV; + goto err; + } + + if (dev->ethtool_ops->begin) { + ret = dev->ethtool_ops->begin(dev); + if (ret) + goto err; + } + + return 0; +err: + if (dev->dev.parent) + pm_runtime_put(dev->dev.parent); + + return ret; } void ethnl_ops_complete(struct net_device *dev) { if (dev && dev->ethtool_ops->complete) dev->ethtool_ops->complete(dev); + + if (dev->dev.parent) + pm_runtime_put(dev->dev.parent); } /**