From patchwork Thu May 12 14:33:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12847782 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 9682EC433EF for ; Thu, 12 May 2022 14:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355386AbiELOeA (ORCPT ); Thu, 12 May 2022 10:34:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355346AbiELOdx (ORCPT ); Thu, 12 May 2022 10:33:53 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 218A825F7AC; Thu, 12 May 2022 07:33:36 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id C2A11FF813; Thu, 12 May 2022 14:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1652366015; 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=V87QhPEf4fMiwaTvp/KGJROCR2XIjXq5O9RjBC7s++M=; b=acGc/jj1fCb5b37McJP9Szmodr/aG3mUA7LKTP1ub+DwX15PGVFZ0xWK6o+3jglOWaDpRD McJ5N+3fsf0TjDpyTn6ZN1xtveZcQFMr6LhCV90WxCB7wA2RWfLMILtxde4zT0PzWxaf9U 6oopz3TOG5FRV2HDGw2cyrXRdNtP99zNFekyOJKLsfTXYoqrZNaHLnDM48+xubkNsC/pd/ ncIEWWcGfqV4zFXcYD266CgoLhH5fyYLufeDRk+oPT4y451V3ygZRJ3UIG3VK7NV2Jq1s1 S1joC5vAdsRSUwbSLBJ2/c8VFA3i6Gru/9mZCwnffyc4QdAhkodOKeMhM+Gs0Q== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-next v2 11/11] net: mac802154: Add a warning in the slow path Date: Thu, 12 May 2022 16:33:14 +0200 Message-Id: <20220512143314.235604-12-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220512143314.235604-1-miquel.raynal@bootlin.com> References: <20220512143314.235604-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 be able to detect possible conflicts between the net interface core and the ieee802154 core, let's add a warning in the slow path: we want to be sure that whenever we start an asynchronous MLME transmission (which can be fully asynchronous) the net core somehow agrees that this transmission is possible, ie. the device was not stopped. Warning in this case would allow us to track down more easily possible issues with the MLME logic if we ever get reports. Unlike in the hot path, such a situation cannot be handled. Signed-off-by: Miquel Raynal --- net/mac802154/tx.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/net/mac802154/tx.c b/net/mac802154/tx.c index a3c9f194c025..d61b076239c3 100644 --- a/net/mac802154/tx.c +++ b/net/mac802154/tx.c @@ -132,6 +132,25 @@ int ieee802154_sync_and_hold_queue(struct ieee802154_local *local) return ret; } +static bool ieee802154_netif_is_down(struct ieee802154_local *local) +{ + struct ieee802154_sub_if_data *sdata; + bool is_down = false; + + rcu_read_lock(); + list_for_each_entry_rcu(sdata, &local->interfaces, list) { + if (!sdata->dev) + continue; + + is_down = !(sdata->dev->flags & IFF_UP); + if (is_down) + break; + } + rcu_read_unlock(); + + return is_down; +} + int ieee802154_mlme_tx(struct ieee802154_local *local, struct sk_buff *skb) { int ret; @@ -145,6 +164,12 @@ int ieee802154_mlme_tx(struct ieee802154_local *local, struct sk_buff *skb) if (!local->open_count) return -EBUSY; + /* Warn if the ieee802154 core thinks MLME frames can be sent while the + * net interface expects this cannot happen. + */ + if (WARN_ON_ONCE(ieee802154_netif_is_down(local))) + return -EHOSTDOWN; + ieee802154_sync_and_hold_queue(local); ieee802154_tx(local, skb);