From patchwork Mon Feb 13 16:54:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13138721 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC49AC677F1 for ; Mon, 13 Feb 2023 16:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjBMQzF (ORCPT ); Mon, 13 Feb 2023 11:55:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbjBMQy5 (ORCPT ); Mon, 13 Feb 2023 11:54:57 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14DDA72B2; Mon, 13 Feb 2023 08:54:20 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 73145240009; Mon, 13 Feb 2023 16:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1676307258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UCfsIjm+4SX0CmTBbneMgRbbsxRe5MO/1rVyIJO8ItE=; b=CjwCasMJFLvnh+cEjTOvJsVDBJjKx9gE0P5pIeupGugc3J6Zg8edP8H+52ZLdmA9juW3ed 29+t82gYHQ6SK4ZdSGx2M90M/7xpd4H7fS93SSwxt4W7mS1hm4XZ6vY2LxizyJJRVKObIB mckMM/AbP1/1A1TkCFhbBQDg7ZEWgN7VmC+TZe1Zob6006vHlxT0k41CNAM5zYr+fKYqu3 7HjwxmHpwyXjOeVDGsy+ExO6Xtw7mchBGR/GeJJY/zOgfn6F51lhe7rvR5TMsidoh0n3to F3Q4aKo7yFd10FxiKiHq/BbZ0hmI25W+qAZvg1p7Up93EEEqP4WLXG0yGbgbBA== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan 1/6] ieee802154: Use netlink policies when relevant on scan parameters Date: Mon, 13 Feb 2023 17:54:09 +0100 Message-Id: <20230213165414.1168401-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213165414.1168401-1-miquel.raynal@bootlin.com> References: <20230213165414.1168401-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Instead of open-coding scan parameters (page, channels, duration, etc), let's use the existing NLA_POLICY* macros. This help greatly reducing the error handling and clarifying the overall logic. Fixes: 45755ce4bf46 ("ieee802154: Add support for user scanning requests") Suggested-by: Jakub Kicinski Signed-off-by: Miquel Raynal --- net/ieee802154/nl802154.c | 84 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c index 0d9becd678e3..64fa811e1f0b 100644 --- a/net/ieee802154/nl802154.c +++ b/net/ieee802154/nl802154.c @@ -187,8 +187,8 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = { [NL802154_ATTR_WPAN_DEV] = { .type = NLA_U64 }, - [NL802154_ATTR_PAGE] = { .type = NLA_U8, }, - [NL802154_ATTR_CHANNEL] = { .type = NLA_U8, }, + [NL802154_ATTR_PAGE] = NLA_POLICY_MAX(NLA_U8, IEEE802154_MAX_PAGE), + [NL802154_ATTR_CHANNEL] = NLA_POLICY_MAX(NLA_U8, IEEE802154_MAX_CHANNEL), [NL802154_ATTR_TX_POWER] = { .type = NLA_S32, }, @@ -221,13 +221,19 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = { [NL802154_ATTR_COORDINATOR] = { .type = NLA_NESTED }, - [NL802154_ATTR_SCAN_TYPE] = { .type = NLA_U8 }, - [NL802154_ATTR_SCAN_CHANNELS] = { .type = NLA_U32 }, - [NL802154_ATTR_SCAN_PREAMBLE_CODES] = { .type = NLA_U64 }, - [NL802154_ATTR_SCAN_MEAN_PRF] = { .type = NLA_U8 }, - [NL802154_ATTR_SCAN_DURATION] = { .type = NLA_U8 }, - [NL802154_ATTR_SCAN_DONE_REASON] = { .type = NLA_U8 }, - [NL802154_ATTR_BEACON_INTERVAL] = { .type = NLA_U8 }, + [NL802154_ATTR_SCAN_TYPE] = + NLA_POLICY_RANGE(NLA_U8, NL802154_SCAN_ED, NL802154_SCAN_RIT_PASSIVE), + [NL802154_ATTR_SCAN_CHANNELS] = + NLA_POLICY_MASK(NLA_U32, GENMASK(IEEE802154_MAX_CHANNEL, 0)), + [NL802154_ATTR_SCAN_PREAMBLE_CODES] = { .type = NLA_REJECT }, + [NL802154_ATTR_SCAN_MEAN_PRF] = { .type = NLA_REJECT }, + [NL802154_ATTR_SCAN_DURATION] = + NLA_POLICY_MAX(NLA_U8, IEEE802154_MAX_SCAN_DURATION), + [NL802154_ATTR_SCAN_DONE_REASON] = + NLA_POLICY_RANGE(NLA_U8, NL802154_SCAN_DONE_REASON_FINISHED, + NL802154_SCAN_DONE_REASON_ABORTED), + [NL802154_ATTR_BEACON_INTERVAL] = + NLA_POLICY_MAX(NLA_U8, IEEE802154_MAX_SCAN_DURATION), #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL [NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, }, @@ -1423,51 +1429,23 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info) goto free_request; } - if (info->attrs[NL802154_ATTR_PAGE]) { + /* Use current page by default */ + if (info->attrs[NL802154_ATTR_PAGE]) request->page = nla_get_u8(info->attrs[NL802154_ATTR_PAGE]); - if (request->page > IEEE802154_MAX_PAGE) { - pr_err("Invalid page %d > %d\n", - request->page, IEEE802154_MAX_PAGE); - err = -EINVAL; - goto free_request; - } - } else { - /* Use current page by default */ + else request->page = wpan_phy->current_page; - } - if (info->attrs[NL802154_ATTR_SCAN_CHANNELS]) { + /* Scan all supported channels by default */ + if (info->attrs[NL802154_ATTR_SCAN_CHANNELS]) request->channels = nla_get_u32(info->attrs[NL802154_ATTR_SCAN_CHANNELS]); - if (request->channels >= BIT(IEEE802154_MAX_CHANNEL + 1)) { - pr_err("Invalid channels bitfield %x ≥ %lx\n", - request->channels, - BIT(IEEE802154_MAX_CHANNEL + 1)); - err = -EINVAL; - goto free_request; - } - } else { - /* Scan all supported channels by default */ + else request->channels = wpan_phy->supported.channels[request->page]; - } - if (info->attrs[NL802154_ATTR_SCAN_PREAMBLE_CODES] || - info->attrs[NL802154_ATTR_SCAN_MEAN_PRF]) { - pr_err("Preamble codes and mean PRF not supported yet\n"); - err = -EINVAL; - goto free_request; - } - - if (info->attrs[NL802154_ATTR_SCAN_DURATION]) { + /* Use maximum duration order by default */ + if (info->attrs[NL802154_ATTR_SCAN_DURATION]) request->duration = nla_get_u8(info->attrs[NL802154_ATTR_SCAN_DURATION]); - if (request->duration > IEEE802154_MAX_SCAN_DURATION) { - pr_err("Duration is out of range\n"); - err = -EINVAL; - goto free_request; - } - } else { - /* Use maximum duration order by default */ + else request->duration = IEEE802154_MAX_SCAN_DURATION; - } if (wpan_dev->netdev) dev_hold(wpan_dev->netdev); @@ -1614,17 +1592,11 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info) request->wpan_dev = wpan_dev; request->wpan_phy = wpan_phy; - if (info->attrs[NL802154_ATTR_BEACON_INTERVAL]) { + /* Use maximum duration order by default */ + if (info->attrs[NL802154_ATTR_BEACON_INTERVAL]) request->interval = nla_get_u8(info->attrs[NL802154_ATTR_BEACON_INTERVAL]); - if (request->interval > IEEE802154_MAX_SCAN_DURATION) { - pr_err("Interval is out of range\n"); - err = -EINVAL; - goto free_request; - } - } else { - /* Use maximum duration order by default */ + else request->interval = IEEE802154_MAX_SCAN_DURATION; - } if (wpan_dev->netdev) dev_hold(wpan_dev->netdev); @@ -1640,7 +1612,7 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info) free_device: if (wpan_dev->netdev) dev_put(wpan_dev->netdev); -free_request: + kfree(request); return err; From patchwork Mon Feb 13 16:54:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13138720 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1338C636CC for ; Mon, 13 Feb 2023 16:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbjBMQzE (ORCPT ); Mon, 13 Feb 2023 11:55:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjBMQy6 (ORCPT ); Mon, 13 Feb 2023 11:54:58 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE145590; Mon, 13 Feb 2023 08:54:21 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 11F8D240004; Mon, 13 Feb 2023 16:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1676307260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eBBZ/jwuokh5y0Pd6SioqzZUZRMXGN1wN9N5bds3ZcY=; b=DOGNTtuVvhHhXqiE9iFyoHrSmOdJ/fNMtFCjWoteKf0+CeKq2S0A00tRoEuS2MXGW5wyZq 1y/x4+USXUoZo+s0G5FwDT2KYBEVoXs6yptAbYUvOd5OMVFW67trO45+X/J9Wz90aUHUsr VofbWdKbh7Sp6HhTtVeXeKeOqbPki38DIV3mK6Dz9+LV+k/iG0o2CCTeSu131WgbY+5xOJ ia8OmeNY0fs/eXr2Dh90WSZuRbfuGAeEnlhYX63M4aJwb7sugH0HsjCdiEcgpDc7mcNkdH Jh0Frl25vhz7OPFSoWsrex/AADAzowvYNMUXWVjSTWqJRL5dZ08dT17hJ4RxcA== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan 2/6] ieee802154: Convert scan error messages to extack Date: Mon, 13 Feb 2023 17:54:10 +0100 Message-Id: <20230213165414.1168401-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213165414.1168401-1-miquel.raynal@bootlin.com> References: <20230213165414.1168401-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Instead of printing error messages in the kernel log, let's use extack. When there is a netlink error returned that could be further specified with a string, use extack as well. Apply this logic to the very recent scan/beacon infrastructure. Fixes: 45755ce4bf46 ("ieee802154: Add support for user scanning requests") Fixes: 7ed3b259eca1 ("ieee802154: Add support for user beaconing requests") Suggested-by: Jakub Kicinski Signed-off-by: Miquel Raynal --- net/ieee802154/nl802154.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c index 64fa811e1f0b..d3b6e9e80941 100644 --- a/net/ieee802154/nl802154.c +++ b/net/ieee802154/nl802154.c @@ -1407,9 +1407,15 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info) u8 type; int err; - /* Monitors are not allowed to perform scans */ - if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR) + if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR) { + NL_SET_ERR_MSG(info->extack, "Monitors are not allowed to perform scans"); return -EPERM; + } + + if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) { + NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type"); + return -EINVAL; + } request = kzalloc(sizeof(*request), GFP_KERNEL); if (!request) @@ -1424,7 +1430,7 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info) request->type = type; break; default: - pr_err("Unsupported scan type: %d\n", type); + NL_SET_ERR_MSG_FMT(info->extack, "Unsupported scan type: %d", type); err = -EINVAL; goto free_request; } @@ -1576,12 +1582,13 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info) struct cfg802154_beacon_request *request; int err; - /* Only coordinators can send beacons */ - if (wpan_dev->iftype != NL802154_IFTYPE_COORD) + if (wpan_dev->iftype != NL802154_IFTYPE_COORD) { + NL_SET_ERR_MSG(info->extack, "Only coordinators can send beacons"); return -EOPNOTSUPP; + } if (wpan_dev->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) { - pr_err("Device is not part of any PAN\n"); + NL_SET_ERR_MSG(info->extack, "Device is not part of any PAN"); return -EPERM; } From patchwork Mon Feb 13 16:54:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13138718 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3516C6379F for ; Mon, 13 Feb 2023 16:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjBMQzA (ORCPT ); Mon, 13 Feb 2023 11:55:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbjBMQy7 (ORCPT ); Mon, 13 Feb 2023 11:54:59 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B507698; Mon, 13 Feb 2023 08:54:23 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 6581A240003; Mon, 13 Feb 2023 16:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1676307261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ud52JoUUkqAzh5uPtXzBoHn5JC0T3wyNnvrXvG9wzQ8=; b=Ea6BuM8fdHSr8Ej72WSKj4QIh+2CpcxU2F3HbB/J1I7gwgtlieuD6sFEgvw3CC3BXXxRK2 PnERRrO2p3mX/q1JTDD38cOj/BvcKmEk8a3C9yoaTMPM1oNh/jKs8Rc+0ejPH0cv+DhxB7 HcNxCzSCdoYviTva8nsYtZLATtysBW+Ljc8N97kg6xuUkVQRh8vNaL+w2ICLA+N5oOgV9X a6rk3eB0gz1Vjmfe6eY5QN46DTMetSPK4ZW9Wr3/SpnQA4rT6rBw6QKeOu8ZXFEzt+GAA+ 9F/eaqtV/5hCdgwKnF6adXPVXKmoEZh18oD4XVu9JNTbaN988MoGSKcHXnh0lQ== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal , Alexander Aring Subject: [PATCH wpan 3/6] ieee802154: Change error code on monitor scan netlink request Date: Mon, 13 Feb 2023 17:54:11 +0100 Message-Id: <20230213165414.1168401-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213165414.1168401-1-miquel.raynal@bootlin.com> References: <20230213165414.1168401-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Returning EPERM gives the impression that "right now" it is not possible, but "later" it could be, while what we want to express is the fact that this is not currently supported at all (might change in the future). So let's return EOPNOTSUPP instead. Fixes: 45755ce4bf46 ("ieee802154: Add support for user scanning requests") Suggested-by: Alexander Aring Signed-off-by: Miquel Raynal --- net/ieee802154/nl802154.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c index d3b6e9e80941..8ee7d2ef55ee 100644 --- a/net/ieee802154/nl802154.c +++ b/net/ieee802154/nl802154.c @@ -1409,7 +1409,7 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info) if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR) { NL_SET_ERR_MSG(info->extack, "Monitors are not allowed to perform scans"); - return -EPERM; + return -EOPNOTSUPP; } if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) { From patchwork Mon Feb 13 16:54:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13138722 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 084DFC636CC for ; Mon, 13 Feb 2023 16:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230232AbjBMQzH (ORCPT ); Mon, 13 Feb 2023 11:55:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbjBMQzC (ORCPT ); Mon, 13 Feb 2023 11:55:02 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AC0F20063; Mon, 13 Feb 2023 08:54:25 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 16BAA240006; Mon, 13 Feb 2023 16:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1676307263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VcItgcpjdYGStTDDBNRcZBHTnvUfT0kMegrHxomcHyw=; b=WbVneJBcfJDQ8SakjRgGIOXGdgCLMUifLtnIV6F7NTyrK4umPi9XCKeaRqzB0v3vvnPjjb 3AcEUbTvEXGR2ZKGMnsO0OaD/9prKJLhRF/Z0uq0GLzaAN9whJIpxhtnhun24PhldXJaBG wI+F797esUsr2tRFfSA/7NPxshxPrpL83owuiXxNTaDSph6uKf5HEtRco7BOR4mNjhAduP 3p0ZhCJ6xCZtgg9CCmGMmVPvX6N38f5k2M4VuVNHQSQ9QlZ3yaa1YmCTUDAwGArfChkSpe 2BqJ8Ssfte/BS5QW7xTVteIzj2LZ3AXddlM/62tn+NlmtroTiZWEsyNE3NRpLA== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal , Alexander Aring Subject: [PATCH wpan 4/6] mac802154: Send beacons using the MLME Tx path Date: Mon, 13 Feb 2023 17:54:12 +0100 Message-Id: <20230213165414.1168401-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213165414.1168401-1-miquel.raynal@bootlin.com> References: <20230213165414.1168401-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Using ieee802154_subif_start_xmit() to bypass the net queue when sending beacons is broken because it does not acquire the HARD_TX_LOCK(), hence not preventing datagram buffers to be smashed by beacons upon contention situation. Using the mlme_tx helper is not the best fit either but at least it is not buggy and has little-to-no performance hit. More details are given in the comment explaining this choice in the code. Fixes: 18fa625292e9 ("mac802154: Handle basic beaconing") Reported-by: Alexander Aring Signed-off-by: Miquel Raynal --- net/mac802154/scan.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c index 8f98efec7753..fff41e59099e 100644 --- a/net/mac802154/scan.c +++ b/net/mac802154/scan.c @@ -326,7 +326,25 @@ static int mac802154_transmit_beacon(struct ieee802154_local *local, return ret; } - return ieee802154_subif_start_xmit(skb, sdata->dev); + /* Using the MLME transmission helper for sending beacons is a bit + * overkill because we do not really care about the final outcome. + * + * Even though, going through the whole net stack with a regular + * dev_queue_xmit() is not relevant either because we want beacons to be + * sent "now" rather than go through the whole net stack scheduling + * (qdisc & co). + * + * Finally, using ieee802154_subif_start_xmit() would only be an option + * if we had a generic transmit helper which would acquire the + * HARD_TX_LOCK() to prevent buffer handling conflicts with regular + * packets. + * + * So for now we keep it simple and send beacons with our MLME helper, + * even if it stops the ieee802154 queue entirely during these + * transmissions, wich anyway does not have a huge impact on the + * performances given the current design of the stack. + */ + return ieee802154_mlme_tx(local, sdata, skb); } void mac802154_beacon_worker(struct work_struct *work) From patchwork Mon Feb 13 16:54:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13138723 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BB2DC636CC for ; Mon, 13 Feb 2023 16:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230319AbjBMQzT (ORCPT ); Mon, 13 Feb 2023 11:55:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjBMQzS (ORCPT ); Mon, 13 Feb 2023 11:55:18 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927161F916; Mon, 13 Feb 2023 08:54:31 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9550124000E; Mon, 13 Feb 2023 16:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1676307265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBQX3LuTYDPAWDw+UNzjgwxc82OmD0XMIiMOQ++fvhQ=; b=ARY5t1x4HuozPWpqOaqlA9+EfOCeh2YZVkbP44jnefTeHZY/RMpE/8dgLk4ImQR25d3hSQ PftFChpthNauBzf+ZmaR/KpFQxHzA6fqA4jqvAPB57XTIMMimOgxIxhxIsyWkp6MHLWtn3 hcljcevu3gr3QaLcwQiiPO+mDIoiu1lImRe0QTHy/hoBbHOd07IdCpUJNS0NQ1NQA4vV6s dm9Hbq22FDN7gPP6QQU5A/dGtsxMwgILIuPH1YLFiKjRqUOp86uu6h7aMcMaXHj2uMbgex dmbup14RyuwkjQrWet75X9aHMRbPdwtCGsNimO8bm5FbxWrzr8lS6wMiIt0Liw== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal , kernel test robot Subject: [PATCH wpan 5/6] mac802154: Fix an always true condition Date: Mon, 13 Feb 2023 17:54:13 +0100 Message-Id: <20230213165414.1168401-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213165414.1168401-1-miquel.raynal@bootlin.com> References: <20230213165414.1168401-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org At this stage we simply do not care about the delayed work value, because active scan is not yet supported, so we can blindly queue another work once a beacon has been sent. It fixes a smatch warning: mac802154_beacon_worker() warn: always true condition '(local->beacon_interval >= 0) => (0-u32max >= 0)' Reported-by: kernel test robot Signed-off-by: Miquel Raynal --- net/mac802154/scan.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c index fff41e59099e..9b0933a185eb 100644 --- a/net/mac802154/scan.c +++ b/net/mac802154/scan.c @@ -383,9 +383,8 @@ void mac802154_beacon_worker(struct work_struct *work) dev_err(&sdata->dev->dev, "Beacon could not be transmitted (%d)\n", ret); - if (local->beacon_interval >= 0) - queue_delayed_work(local->mac_wq, &local->beacon_work, - local->beacon_interval); + queue_delayed_work(local->mac_wq, &local->beacon_work, + local->beacon_interval); } int mac802154_stop_beacons_locked(struct ieee802154_local *local, From patchwork Mon Feb 13 16:54:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13138724 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ABA5C64EC7 for ; Mon, 13 Feb 2023 16:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbjBMQzV (ORCPT ); Mon, 13 Feb 2023 11:55:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjBMQzS (ORCPT ); Mon, 13 Feb 2023 11:55:18 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE2D1E5CA; Mon, 13 Feb 2023 08:54:36 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B632D24000C; Mon, 13 Feb 2023 16:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1676307267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Rr687/4/EsEsD4W31jyRusTeG5lpNTR5Q6FhRygF1w=; b=Yj1CptIP2Pb9000uc5hcUnnkozFLeOkOVkJE/jQ2QTONphRypsGGTygsLxL6FAR3MylQQ7 5b4YLS1beX+MiFd7VT/xq4pd53kZjHxYXHO8crZZ2rqDgeyeP6a3o31CrxdGWfyIqX4BIa M29ZMyxm86TbBo3HHj2hAwHiWSiEmU+4hc3UG+RiBdQaY9epz3P7eEqvkTBT4lzbAwp01C hwDTuB4m1AvbLQ5e22t5cMRud3iLYRe2Sn2xmAosohn7XsFVP4Jm0+eF6Xww1P03IrVssx IjS3hUl7cxXDaNrqkEnDrT+KfpBUb8xrSw03ZXM/jbWUfMoy6psM4xsrmC1/vA== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan 6/6] ieee802154: Drop device trackers Date: Mon, 13 Feb 2023 17:54:14 +0100 Message-Id: <20230213165414.1168401-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213165414.1168401-1-miquel.raynal@bootlin.com> References: <20230213165414.1168401-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In order to prevent a device from disappearing when a background job was started, dev_hold() and dev_put() calls were made. During the stabilization phase of the scan/beacon features, it was later decided that removing the device while a background job was ongoing was a valid use case, and we should instead stop the background job and then remove the device, rather than prevent the device from being removed. This is what is currently done, which means manually reference counting the device during background jobs is no longer needed. Fixes: 45755ce4bf46 ("ieee802154: Add support for user scanning requests") Fixes: 7ed3b259eca1 ("ieee802154: Add support for user beaconing requests") Reported-by: Jakub Kicinski Signed-off-by: Miquel Raynal --- net/ieee802154/nl802154.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c index 8ee7d2ef55ee..88380606af2c 100644 --- a/net/ieee802154/nl802154.c +++ b/net/ieee802154/nl802154.c @@ -1453,20 +1453,14 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info) else request->duration = IEEE802154_MAX_SCAN_DURATION; - if (wpan_dev->netdev) - dev_hold(wpan_dev->netdev); - err = rdev_trigger_scan(rdev, request); if (err) { pr_err("Failure starting scanning (%d)\n", err); - goto free_device; + goto free_request; } return 0; -free_device: - if (wpan_dev->netdev) - dev_put(wpan_dev->netdev); free_request: kfree(request); @@ -1555,9 +1549,6 @@ int nl802154_scan_done(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, if (err == -ESRCH) err = 0; - if (wpan_dev->netdev) - dev_put(wpan_dev->netdev); - return err; } EXPORT_SYMBOL_GPL(nl802154_scan_done); @@ -1605,21 +1596,15 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info) else request->interval = IEEE802154_MAX_SCAN_DURATION; - if (wpan_dev->netdev) - dev_hold(wpan_dev->netdev); - err = rdev_send_beacons(rdev, request); if (err) { pr_err("Failure starting sending beacons (%d)\n", err); - goto free_device; + goto free_request; } return 0; -free_device: - if (wpan_dev->netdev) - dev_put(wpan_dev->netdev); - +free_request: kfree(request); return err; @@ -1627,8 +1612,7 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info) void nl802154_beaconing_done(struct wpan_dev *wpan_dev) { - if (wpan_dev->netdev) - dev_put(wpan_dev->netdev); + /* NOP */ } EXPORT_SYMBOL_GPL(nl802154_beaconing_done);