From patchwork Wed Oct 25 17:32:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436493 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 628DE30F97 for ; Wed, 25 Oct 2023 17:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="hVLljGW+" Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFFC182 for ; Wed, 25 Oct 2023 10:34:40 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7789577b53fso1759585a.3 for ; Wed, 25 Oct 2023 10:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255279; x=1698860079; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=qX3EL2q6pN74SwRInbjnbLAH7jYoC+JLJCmE0WvVx0s=; b=hVLljGW++ht2jJMtN9VLgaFHB5jWbwRh6KqmaC9a42XlrSj0h/s37a3XBDBqNn+Dvc 6H7gpO5txgBvFE7mXpknX4PUotT7IbZ43+uSywmDFdG1zSqArxOgI6FM8gVNsLIfZyWQ FozqJ0O20O17/kWzrrJ3Gtp3eu44XSaFFwzik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255279; x=1698860079; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qX3EL2q6pN74SwRInbjnbLAH7jYoC+JLJCmE0WvVx0s=; b=Hgshg7x41DMNXlR74Q+SjoG+W4M8zWmVP9xPkReMsqE1nqfuLu/31ju6QTS8HEoPJ/ lqnFTLWA4p+UThGCsRdXdtnNND0yLegjXMcBo0tD/xelav/3zFqCCc9jGSCfSr67yHJe aSq+YIEyYfyrh7PBUfZBty7CPts8BvkhwFw1XATNx9p5Fys0HAbJaZiioY7Pud5oaEiS zVswqZj3ikqzQAblntFC8I8vHZWG7kK7UuGrJ4dXY+ns7PJAIdAW30jj5pS0mpUfwmqW D1EEGmR3aDKGeHaTnqkZhgjlMzrlH6l04RlMhRHqwqU1DshNaxRfg/2T/iBGzNWlzVWz 3OUg== X-Gm-Message-State: AOJu0YweSoh9bPO59/pxeCKCVHv8koigYjXbLoqX0WibYuDE0XR3t3/B irrSbv6eC1itKnR19vODc4DxSummdMqxU8jSi3mv+nqMEz3f+4dveX+tEEN0r6vb/xHwoCLFzEu KCnxh5rIg8PF1QP2o5uFeI/niV/R0fwVhS0TUD2NQRVo4AtATHSAXKBSZypIIBPjyH8xNasQRbS D8VJ+vfgDLJke5 X-Google-Smtp-Source: AGHT+IFp9bGKQ4w8/MwEaeQRNWEE1mGnGVHX8bh4pF339G1+0DlNED741jUjMoH59k57ABJUCkqgkA== X-Received: by 2002:a05:620a:4609:b0:779:de52:8743 with SMTP id br9-20020a05620a460900b00779de528743mr10541880qkb.27.1698255278944; Wed, 25 Oct 2023 10:34:38 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:38 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 2/5] net: ethtool: Add validation for WAKE_FILTER Date: Wed, 25 Oct 2023 10:32:57 -0700 Message-Id: <20231025173300.1776832-3-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org A driver implementing WAKE_FILTER must first install at least one rule with RX_CLS_FLOW_WAKE for WAKE_FILTER to be effective. Iterate over RXNFC rules to validate that condition while trying to enable WAKE_FILTER. Signed-off-by: Florian Fainelli --- net/ethtool/common.c | 42 ++++++++++++++++++++++++++++++++++++++++++ net/ethtool/common.h | 3 +++ net/ethtool/ioctl.c | 3 +++ net/ethtool/wol.c | 3 +++ 4 files changed, 51 insertions(+) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 143dae872fb2..bab901b35731 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -742,3 +742,45 @@ ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size) } } EXPORT_SYMBOL_GPL(ethtool_forced_speed_maps_init); + +static int __ethtool_check_rxnfc_wake_filter(struct ethtool_rxnfc *rule_info, + void *priv) +{ + bool *verdict = priv; + + if (rule_info->fs.ring_cookie == RX_CLS_FLOW_WAKE) { + *verdict = true; + return 1; + } + + return 0; +} + +/** + * ethtool_dev_check_wake_filter: Tests if a network device can use the + * WAKE_FILTER Wake-on-LAN option. + * @dev: network device to test + * @wol: %ethtool_wolinfo structure with Wake-on-LAN configuration + * + * Returns true if there is no support for %WAKE_FILTER, no support + * for RXNFC ethtool operations, or if there is at least one WAKE_FILTER + * installed. + */ +bool ethtool_dev_check_wake_filter(struct net_device *dev, + const struct ethtool_wolinfo *wol) +{ + bool verdict = false; + int ret; + + if (!(wol->wolopts & WAKE_FILTER)) + return true; + + if (!dev->ethtool_ops->get_rxnfc || + !dev->ethtool_ops->set_rxnfc) + return true; + + ret = __ethtool_for_each_rxnfc(dev, __ethtool_check_rxnfc_wake_filter, + &verdict); + + return ret < 0 ? false : verdict; +} diff --git a/net/ethtool/common.h b/net/ethtool/common.h index 28b8aaaf9bcb..6cd3286d5038 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -56,4 +56,7 @@ int ethtool_get_module_eeprom_call(struct net_device *dev, bool __ethtool_dev_mm_supported(struct net_device *dev); +bool ethtool_dev_check_wake_filter(struct net_device *dev, + const struct ethtool_wolinfo *wol); + #endif /* _ETHTOOL_COMMON_H */ diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 0b0ce4f81c01..954446185158 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1457,6 +1457,9 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) !memcmp(wol.sopass, cur_wol.sopass, sizeof(wol.sopass))) return 0; + if (!ethtool_dev_check_wake_filter(dev, &wol)) + return -EOPNOTSUPP; + ret = dev->ethtool_ops->set_wol(dev, &wol); if (ret) return ret; diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index 0ed56c9ac1bc..65fbe743a070 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -132,6 +132,9 @@ ethnl_set_wol(struct ethnl_req_info *req_info, struct genl_info *info) tb[ETHTOOL_A_WOL_SOPASS], &mod); } + if (!ethtool_dev_check_wake_filter(dev, &wol)) + return -EOPNOTSUPP; + if (!mod) return 0; ret = dev->ethtool_ops->set_wol(dev, &wol);