Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp881134imw; Thu, 14 Jul 2022 12:39:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfiJ41mEptqx/xIKpku703eajeiL93Jg12E+gTW8CYgBE50AlAKlwFTN6bw89/TH+5XHEY X-Received: by 2002:a63:904c:0:b0:419:be58:16e2 with SMTP id a73-20020a63904c000000b00419be5816e2mr3125707pge.411.1657827574151; Thu, 14 Jul 2022 12:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657827574; cv=none; d=google.com; s=arc-20160816; b=k6k+oxcwWWCbrLugolEtsxaC72cKoZ4mYkMv1yEeZdHqfffIFEqsSMv8QCjvt7q6pg nD1X3VX6ITUbUJ89mJ88qE1I9FiXoPPVKnPw/dKfNgB9uEZuuXOKMFS+Kvn4WlQSdbC+ 8PRR22qmXSyJmGmK2ECGBt5Tye9DUPOSiQmcUA2d72ubxDjcNCzKFK801pDBWZNtsbaE DMF/067Jkv5rhge3LUq/Uzem8pWGDIxzZn5lPAdqL8Go8GxYUpLkbf7A/1khLVuQ9gtf BMAHeBmFZAeuuXBDPxTxcZVB7QVX5JW3cbtINhicVHjVM9mKMJkrvflC+uNDIQT8mNPq G5bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1Rdly467/LGJGsYiP4ibeql2PfhyEBP3ocGH7IsG3L8=; b=h0yAhw4a86/jQyMLI0ZdAzFy9JJLwsjT+cl2UOW3Jz7jFK6JQ3ZbcTEHkTbJe3bTR2 P6ejG2l+8EjU4m3DLyYxlwyCxTALjuSZjE9Ex5SBZcYU/G3Eq+DAG3eIf8ZqARYdRS35 C2BgLyBj2R5+1GC2yRCRj04rhSx9/HZSDvXrAmhlTYIbNZAOYQV1yw9/hTBQRsij29BH peCeqCZaJZjCZSWHZ02naYRFgSsSjiBDumh9hmePSpL5+U2P1sDXTUXCKk2osp8lJy3b dbEyAlJIKIaQpd0rRLtiIb7ERfQJasw86QCknlUuX/3sBnqU3//Oc63XXGrjJrcNcwlJ 0L5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=SufXYf3R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020a056a00198e00b00525425b20f0si3357002pfl.257.2022.07.14.12.39.19; Thu, 14 Jul 2022 12:39:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=SufXYf3R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240563AbiGNThF (ORCPT + 99 others); Thu, 14 Jul 2022 15:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232514AbiGNThA (ORCPT ); Thu, 14 Jul 2022 15:37:00 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 365805885D; Thu, 14 Jul 2022 12:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1657827419; x=1689363419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4rF/yuL+ZN9c5eOj3OIsnL8kWn7pgcEhED0vM6p8gv0=; b=SufXYf3RxK3ONsxpN3fkm2ya6xUxs9dDDnXtEIcKLQfvEO2jOWIFMXBL ORdh+LouKVZwsRVmzpDvW5m3Jzf5mFlkEsb4vk2fHFGTlmPhIPHZ8e8Oz q6xlUYq6RZJ63CqXc6j852K8g6KsusBtWp8/L4LVnbCk4l2ma8smZAOZ6 PhM9eLjtaoSQ7JmcQm+b5RiHRr6syA+K0blMlYajU12mswmcgxwIFh/Df H8/ZLAiJIJaTVKHmwO1/JlynX38gi3vrfR2qz67+6UhIFGUsCis3rNEli OTbwO3KNgdAqDgM9QcxEd6d46km8nPBg1Bd45ti+DwO6kpgDiG7GweJcy Q==; X-IronPort-AV: E=Sophos;i="5.92,272,1650956400"; d="scan'208";a="167895544" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Jul 2022 12:36:58 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 14 Jul 2022 12:36:56 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 14 Jul 2022 12:36:54 -0700 From: Horatiu Vultur To: , CC: , , , , , , Horatiu Vultur Subject: [PATCH net 1/5] net: lan966x: Fix taking rtnl_lock while holding spin_lock Date: Thu, 14 Jul 2022 21:40:36 +0200 Message-ID: <20220714194040.231651-2-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220714194040.231651-1-horatiu.vultur@microchip.com> References: <20220714194040.231651-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the HW deletes an entry in MAC table then it generates an interrupt. The SW will go through it's own list of MAC entries and if it is not found then it would notify the listeners about this. The problem is that when the SW will go through it's own list it would take a spin lock(lan966x->mac_lock) and when it notifies that the entry is deleted. But to notify the listeners it taking the rtnl_lock which is illegal. This is fixed by instead of notifying right away that the entry is deleted, move the entry on a temp list and once, it checks all the entries then just notify that the entries from temp list are deleted. Fixes: 5ccd66e01cbe ("net: lan966x: add support for interrupts from analyzer") Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_mac.c | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c index 005e56ea5da1..2d2b83c03796 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c @@ -325,10 +325,13 @@ static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row, { struct lan966x_mac_entry *mac_entry, *tmp; unsigned char mac[ETH_ALEN] __aligned(2); + struct list_head mac_deleted_entries; u32 dest_idx; u32 column; u16 vid; + INIT_LIST_HEAD(&mac_deleted_entries); + spin_lock(&lan966x->mac_lock); list_for_each_entry_safe(mac_entry, tmp, &lan966x->mac_entries, list) { bool found = false; @@ -362,20 +365,26 @@ static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row, } if (!found) { - /* Notify the bridge that the entry doesn't exist - * anymore in the HW and remove the entry from the SW - * list - */ - lan966x_mac_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE, - mac_entry->mac, mac_entry->vid, - lan966x->ports[mac_entry->port_index]->dev); - list_del(&mac_entry->list); - kfree(mac_entry); + /* Move the entry from SW list to a tmp list such that + * it would be deleted later + */ + list_add_tail(&mac_entry->list, &mac_deleted_entries); } } spin_unlock(&lan966x->mac_lock); + list_for_each_entry_safe(mac_entry, tmp, &mac_deleted_entries, list) { + /* Notify the bridge that the entry doesn't exist + * anymore in the HW + */ + lan966x_mac_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE, + mac_entry->mac, mac_entry->vid, + lan966x->ports[mac_entry->port_index]->dev); + list_del(&mac_entry->list); + kfree(mac_entry); + } + /* Now go to the list of columns and see if any entry was not in the SW * list, then that means that the entry is new so it needs to notify the * bridge. -- 2.33.0