Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp881797imw; Thu, 14 Jul 2022 12:40:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1spGoQe9Rl7devD02oU18Qe9msro+eWlGFn3UUtfbarOkLftUMK+xsoZPxwWECwTVl5DjxK X-Received: by 2002:a63:2c10:0:b0:411:4fd8:9fc8 with SMTP id s16-20020a632c10000000b004114fd89fc8mr9137443pgs.313.1657827632403; Thu, 14 Jul 2022 12:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657827632; cv=none; d=google.com; s=arc-20160816; b=h6byNMWcJ038UdW0dc9xaEsTEUm6m6K8s1DY8OLMVE9RoRUBvqKuudCQb9OAkr82kh L112ThAlgRauKJJBK0JrAIEHqocrF/CDlmzr0KwnKbbPm+cekmG2GoeYmnHAhoX6Q2hP lK+Xr16vH/q4FLAJUfsxrngdjAlG7lDvTmBu3PmLKQEzp+i4/HmMsbrsnnCRMuvjJf9d DdZ6Wx5YPg0uVL/NkoVqwh4jSIPSDnwFklNcz0LxROAm29X8j1hDRXoAW0hu+2empQzk LITH4prWYh66OT0v0CeSX/I6cdnwqevaz7gxb0Z5mL0IuWIMdb5URvkLAD9w3ygvL5tl /tKg== 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=siQokHOe3pU203GJTSamklBHKxAre5GYNBw7w9KlniU=; b=wdoHGlK8x6iAWiZ8CUN9I9PCks4rWKxX4XrTKRyS3IanTVsOkm9FcQf/t0r39mQTj+ fkwUv6KkJpYjFQGGOfDPiZYJSt4GmoaEylOgorKvuE4I7WpiBbiPRts/42b+ZcYTzCfJ OIwsx7i8NZDB0VaoX0EyY7zECts4dKKdGls7rZHtJS8SHLtAUyzH1++ml27G6pmVrYMk 3HxIdZEhOqAzSYROltlSiIbhTYVHMtSWCWnkz1Xhj8Rvb4NBuHp/6ynyr2j9AR3tsibg My1wGuTYmlUt3RKjVBcjGlurkU1m25L3tCrYWZDrJWRZO/ahr7Q1kbMxr28sxixbxJVz bsJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=x3HYGJOt; 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 h184-20020a6383c1000000b00415366cf294si2683276pge.272.2022.07.14.12.40.17; Thu, 14 Jul 2022 12:40:32 -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=x3HYGJOt; 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 S240576AbiGNThH (ORCPT + 99 others); Thu, 14 Jul 2022 15:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238905AbiGNThB (ORCPT ); Thu, 14 Jul 2022 15:37:01 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C5115B062; Thu, 14 Jul 2022 12:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1657827420; x=1689363420; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LtHpDNLMAcK5rBLsj0TfF3HcbTfILzQaOwVoqU00jaw=; b=x3HYGJOt4+2UZtVKRYL/mlNusEGqCQM3EVVs6VYiBd2b1qpj8l5qzaSN xaVnQgzBH0WxU7CjTb+XDMPxjYr5jO3GtgIG8LNeIDJDkjWbq+a9Ofo8m gES1HE0f83YUC8aj/GWwqCYtPYPfc7DyC0MmzuT318nb8jbtSGItoPKYT iNpH2ztwKAPloGpNAT8fisg7F3iMjyBIqxTG6auptKyRdXTZ2YuR7KDV2 SoDOG1JSnDZ6//FvFJOTjP/rCewZRc3zdMTFaA4NYYIE9a+SEQSRzkMBX 4pnhD4+CF/8xVHPhU1jp4FUY3rtNvE38luKlx+zZB5UdCHKLJ5BP4Bt4M w==; X-IronPort-AV: E=Sophos;i="5.92,272,1650956400"; d="scan'208";a="167895546" 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:58 -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:56 -0700 From: Horatiu Vultur To: , CC: , , , , , , Horatiu Vultur Subject: [PATCH net 2/5] net: lan966x: Fix usage of lan966x->mac_lock when entry is added Date: Thu, 14 Jul 2022 21:40:37 +0200 Message-ID: <20220714194040.231651-3-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 To add an entry to the MAC table, it is required first to setup the entry and then issue a command for the MAC to learn the entry. So if it happens for two threads to add simultaneously an entry in MAC table then it would be a race condition. Fix this by using lan966x->mac_lock to protect the HW access. Fixes: fc0c3fe7486f2 ("net: lan966x: Add function lan966x_mac_ip_learn()") Signed-off-by: Horatiu Vultur --- drivers/net/ethernet/microchip/lan966x/lan966x_mac.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c index 2d2b83c03796..4f8fd5cde950 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c @@ -75,6 +75,9 @@ static int __lan966x_mac_learn(struct lan966x *lan966x, int pgid, unsigned int vid, enum macaccess_entry_type type) { + int ret; + + spin_lock(&lan966x->mac_lock); lan966x_mac_select(lan966x, mac, vid); /* Issue a write command */ @@ -86,7 +89,10 @@ static int __lan966x_mac_learn(struct lan966x *lan966x, int pgid, ANA_MACACCESS_MAC_TABLE_CMD_SET(MACACCESS_CMD_LEARN), lan966x, ANA_MACACCESS); - return lan966x_mac_wait_for_completion(lan966x); + ret = lan966x_mac_wait_for_completion(lan966x); + spin_unlock(&lan966x->mac_lock); + + return ret; } /* The mask of the front ports is encoded inside the mac parameter via a call -- 2.33.0