Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3977326pxb; Tue, 25 Jan 2022 00:28:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbZYFkPXIYUy/0zP6g0S1U7LATAFh6wk+RNc3wem2Lh6K1M18LHMXFtYpIM8+U1RxJw3Qq X-Received: by 2002:a17:906:4781:: with SMTP id cw1mr16463112ejc.116.1643099304689; Tue, 25 Jan 2022 00:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099304; cv=none; d=google.com; s=arc-20160816; b=MgcexZ6t/68IPdK5gcqXBBTTFN65pKrwBfad9+NeaCdsoyIOPUQARMdMHl681ljLXy 3dgjHhD6il48e4tYHp+aZgj0gk2G5OwMsvXuQHu7goZ/X0AE3VG1cvFQvcAkH80dwXlE l1SkkDUvn86ITfeyoZB+JmNqkbJyvPB/Fe/dmCXJzFixHMm6z9NvuBn81ojmW2XPBzWd W8U92yS2GDHdl/OGcd8n04OPRdUXfoXIRo+XOupTFke2vLwuFS6YnQuqpb/N1nPqBkK5 JyeXvYzfSeRnSK9QIWlQD5rL19S6A+Jlaw7cqz+1uxSZnehLL3Kthw+ogFnv8JvBs+uh TViw== 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=svxJiI0vdwCwxxgzkcW8ddziVAIvbSo/N9fkVwagomY=; b=tZiUgRr8lpdPqbDqsWYNN9AByWQpy2HhJFcntS4oGSYpkP1PbxcU0w/BVZeCkv8V0N mvHpGqZXWKXQewzMg3kBzV8FvFk/FVficeu10kGckQ3VSh0Bw7nhXW5BHq2UdXq7rdkr NFLg9f0bQI+ZDIa97pVouZAhL9/IJdxYVNMiJce2Rq5RaZypII7O5Q1aiOGf2k6yxZ8B 2zllK+BEkGE6GyejUEUCSWypu32Drt3q4sBjCR6JfC+A9BW8Vkfx9shbPdUaLCGfGWol 5XrAay9vrAtrCiEnft8AND7+RnVU4ouOY07/QXUIpKgzRHOycs97ob07tiRtGs/UDGvg cJvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="b5mW+c/g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si10881639edd.153.2022.01.25.00.27.59; Tue, 25 Jan 2022 00:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="b5mW+c/g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S3423203AbiAYCdO (ORCPT + 99 others); Mon, 24 Jan 2022 21:33:14 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:34424 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383317AbiAXU1I (ORCPT ); Mon, 24 Jan 2022 15:27:08 -0500 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 24DAAB81229; Mon, 24 Jan 2022 20:27:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FF71C340E5; Mon, 24 Jan 2022 20:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056025; bh=mjBorZuh81adqdEcOrTZhe5u/IELOWwaGcD5RCrxOGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b5mW+c/gVUkQJDW+TTcgF+4FCtqLyx8HNriRcUWn0huL7XxyRzDKHL5a6Jm4Hz0fw 4MjY1scImaRBvtlchYy3FJjuu/V7ZvsDj0/tcR1Tt31x0/RNM8k4S/ti3R9lvoTHSa VTE/T4oF+yC5+Mlhsfd0DAs2JYMBy5u8qhX0FJ8I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Moshe Shemesh , Eran Ben Elisha , Saeed Mahameed , Sasha Levin Subject: [PATCH 5.15 345/846] net/mlx5: Set command entry semaphore up once got index free Date: Mon, 24 Jan 2022 19:37:42 +0100 Message-Id: <20220124184112.833270532@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Moshe Shemesh [ Upstream commit 8e715cd613a1e872b9d918e912d90b399785761a ] Avoid a race where command work handler may fail to allocate command entry index, by holding the command semaphore down till command entry index is being freed. Fixes: 410bd754cd73 ("net/mlx5: Add retry mechanism to the command entry index allocation") Signed-off-by: Moshe Shemesh Reviewed-by: Eran Ben Elisha Signed-off-by: Saeed Mahameed Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index bea35530c2d0b..a0704be46e507 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -147,8 +147,12 @@ static void cmd_ent_put(struct mlx5_cmd_work_ent *ent) if (!refcount_dec_and_test(&ent->refcnt)) return; - if (ent->idx >= 0) - cmd_free_index(ent->cmd, ent->idx); + if (ent->idx >= 0) { + struct mlx5_cmd *cmd = ent->cmd; + + cmd_free_index(cmd, ent->idx); + up(ent->page_queue ? &cmd->pages_sem : &cmd->sem); + } cmd_free_ent(ent); } @@ -1594,8 +1598,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force vector = vec & 0xffffffff; for (i = 0; i < (1 << cmd->log_sz); i++) { if (test_bit(i, &vector)) { - struct semaphore *sem; - ent = cmd->ent_arr[i]; /* if we already completed the command, ignore it */ @@ -1618,10 +1620,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) cmd_ent_put(ent); - if (ent->page_queue) - sem = &cmd->pages_sem; - else - sem = &cmd->sem; ent->ts2 = ktime_get_ns(); memcpy(ent->out->first.data, ent->lay->out, sizeof(ent->lay->out)); dump_command(dev, ent, 0); @@ -1675,7 +1673,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force */ complete(&ent->done); } - up(sem); } } } -- 2.34.1