Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6291362iob; Tue, 10 May 2022 15:04:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE/P2ePa9RzLXy9HhxQqDZJ7QbY/oNtMaK3xEgJkTITl4eT/T1Aimc++kZWCLVaam59kl3 X-Received: by 2002:a17:906:9b87:b0:6fa:8b03:5837 with SMTP id dd7-20020a1709069b8700b006fa8b035837mr9394130ejc.362.1652220262382; Tue, 10 May 2022 15:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652220262; cv=none; d=google.com; s=arc-20160816; b=zv6A+iwpFB18TUmK/u6WVAC2rnuqZcXwXws02gzJr0LrvDK9Pzo9nob5onr5Wr85v+ 03F/u+CMsXHUIl/PrZGLfeSNoL7tyxvwF6q3Q2xgFIEmBEqmYSOMlkowkrAiAa4VgXib biQGQ9K/780KKosEPCBh1zf7l7sdBxwb7EjYXuwnIZ7bdjStsV9GMk+CyShhrF9D5yGD hC74S67yXi4l8EXx1ifX9wshwMhKVtYkTFVpdA+2y3o0llVG5fYiIZzG9w1+f4r5HxtB GQGKERZZ8ZOMxWYe2NdjHO63ugIG54lhNOIhqkheA+BUlqipDbbLSUB4Fzg750mavlLS ldWA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VqzYQWaE3U6Md069DLcjv0VE85vq9dx3dtZINFsHva0=; b=qCDdEsA2RIFHsznd6iF+hEDY5mEdqk+L3jkrrsvXrng6Toe/NNq2S4LnFnsWVNFM9N tD4QLlazOrqN2FipctBiglOYZ0HO68XvHZJO5YptbKXpU97mP2sYtxrKLIhiaho8t2m6 P/E6Z/NPCArAjX8vYCnzNJklM+JCIBIf6NOucM249iln8ghev1rmYdiVZoi4dESnw7/4 z0ATWHqe/CgQTOndXnxOHO96Aiqmssnmjw5DDkVtznGFMBVAlFqPnxtBlkQI5shyMf8c 0dx+sGlvNRums5EuHw5UiQ+oAcDq7TuF2nwkBb4bPpKkECSmE996p0qH7rtgfkosco9y Vq5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R98m76Ok; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a05640211d100b00425d40720f1si523745edw.156.2022.05.10.15.03.58; Tue, 10 May 2022 15:04:22 -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=@linuxfoundation.org header.s=korg header.b=R98m76Ok; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244961AbiEJN7z (ORCPT + 99 others); Tue, 10 May 2022 09:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244843AbiEJNiI (ORCPT ); Tue, 10 May 2022 09:38:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA1562CFC; Tue, 10 May 2022 06:26:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A3D9CB81DA8; Tue, 10 May 2022 13:26:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A668C385A6; Tue, 10 May 2022 13:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189187; bh=O6BESBseo/1PxSG1YQz7m3Aoqpw3BtYVHDjNoochBjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R98m76OkHffd8PUUgK1hl/zIdF5AqRBrf8y/N5sqPnLr1DIOC22DHfktewRNXnHte kW9IdWriPIhkWoF3/f+skxZlYtRJfiiD8vH9xKr6UKSeAEo3Hia0civfb5W0T+wE61 oi47NPfoSOB6J89GS0mbUaUofoAnJq15I7QGA89M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Moshe Shemesh , Maher Sanalla , Shay Drory , Saeed Mahameed Subject: [PATCH 5.10 41/70] net/mlx5: Avoid double clear or set of sync reset requested Date: Tue, 10 May 2022 15:08:00 +0200 Message-Id: <20220510130734.064449793@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.861729621@linuxfoundation.org> References: <20220510130732.861729621@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 From: Moshe Shemesh commit fc3d3db07b35885f238e1fa06b9f04a8fa7a62d0 upstream. Double clear of reset requested state can lead to NULL pointer as it will try to delete the timer twice. This can happen for example on a race between abort from FW and pci error or reset. Avoid such case using test_and_clear_bit() to verify only one time reset requested state clear flow. Similarly use test_and_set_bit() to verify only one time reset requested state set flow. Fixes: 7dd6df329d4c ("net/mlx5: Handle sync reset abort event") Signed-off-by: Moshe Shemesh Reviewed-by: Maher Sanalla Reviewed-by: Shay Drory Signed-off-by: Saeed Mahameed Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c | 28 ++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c @@ -134,14 +134,19 @@ static void mlx5_stop_sync_reset_poll(st del_timer_sync(&fw_reset->timer); } -static void mlx5_sync_reset_clear_reset_requested(struct mlx5_core_dev *dev, bool poll_health) +static int mlx5_sync_reset_clear_reset_requested(struct mlx5_core_dev *dev, bool poll_health) { struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset; + if (!test_and_clear_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags)) { + mlx5_core_warn(dev, "Reset request was already cleared\n"); + return -EALREADY; + } + mlx5_stop_sync_reset_poll(dev); - clear_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags); if (poll_health) mlx5_start_health_poll(dev); + return 0; } #define MLX5_RESET_POLL_INTERVAL (HZ / 10) @@ -185,13 +190,17 @@ static int mlx5_fw_reset_set_reset_sync_ return mlx5_reg_mfrl_set(dev, MLX5_MFRL_REG_RESET_LEVEL3, 0, 2, false); } -static void mlx5_sync_reset_set_reset_requested(struct mlx5_core_dev *dev) +static int mlx5_sync_reset_set_reset_requested(struct mlx5_core_dev *dev) { struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset; + if (test_and_set_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags)) { + mlx5_core_warn(dev, "Reset request was already set\n"); + return -EALREADY; + } mlx5_stop_health_poll(dev, true); - set_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags); mlx5_start_sync_reset_poll(dev); + return 0; } static void mlx5_fw_live_patch_event(struct work_struct *work) @@ -225,7 +234,9 @@ static void mlx5_sync_reset_request_even err ? "Failed" : "Sent"); return; } - mlx5_sync_reset_set_reset_requested(dev); + if (mlx5_sync_reset_set_reset_requested(dev)) + return; + err = mlx5_fw_reset_set_reset_sync_ack(dev); if (err) mlx5_core_warn(dev, "PCI Sync FW Update Reset Ack Failed. Error code: %d\n", err); @@ -325,7 +336,8 @@ static void mlx5_sync_reset_now_event(st struct mlx5_core_dev *dev = fw_reset->dev; int err; - mlx5_sync_reset_clear_reset_requested(dev, false); + if (mlx5_sync_reset_clear_reset_requested(dev, false)) + return; mlx5_core_warn(dev, "Sync Reset now. Device is going to reset.\n"); @@ -354,10 +366,8 @@ static void mlx5_sync_reset_abort_event( reset_abort_work); struct mlx5_core_dev *dev = fw_reset->dev; - if (!test_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags)) + if (mlx5_sync_reset_clear_reset_requested(dev, true)) return; - - mlx5_sync_reset_clear_reset_requested(dev, true); mlx5_core_warn(dev, "PCI Sync FW Update Reset Aborted.\n"); }