Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3631293pxb; Mon, 24 Jan 2022 13:59:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHYaD2uY04TRSe050v0p2AGOKl3uO6Gz1sx92MvQy2BW+svmeG8aCbW5QyE6lOmjm9Hf2G X-Received: by 2002:a17:902:7b87:b0:149:9db9:fa6a with SMTP id w7-20020a1709027b8700b001499db9fa6amr16048508pll.16.1643061549005; Mon, 24 Jan 2022 13:59:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061549; cv=none; d=google.com; s=arc-20160816; b=TBKNwro4R6uLkC1ycWKbdARRMagCKbbCs7PEF6iNNF9CI4bgC5tQfv8luhUwsact/f DyrB1zbGIwwix1vq2VI73grqcx9/OlmVMSK6IuttydtKHcdtKzB/52lBI0g4rAdYDVQ0 Q5cEXPk+41vKfrePR6pAfkxm+15AFRWfyjazIeznV73Q0YkmBs1t4ONTXXb1rwKP4lCk 6MPtZhSnXRlLGdVa3j4OPXCKKLAhI6PGOMsuXA2ssCvLKeKrGny+eOjzfu19U5CS5uWl 5Z33q8GK023df0iSw5KD5UWJu3mIeRykBjGR918rrhLmIPhF9wV1NxQQb62gJkT2CiRX 0Wtg== 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=oGOLuN3bK9U3G5Jvmh5GJ0a33R96eBpD5pU8FdHWETs=; b=FYRYKYqqrz8XYe54hFJquCHr6x9fKjcT3uqmbsL1xCR7xnCiCp2o+Z8be/6HgWWskl 2C3DQRtrjDtYJmnpA7+whu5os4QdLTteqNfEpJhy70/w8yEv87qMuw0XoXbE9X0HaJ1O prlmsZarz2/dE/LOMb3ZfhDexSO8x8lnmJtKPmtNtQFNguyn2pgfA3LxRDt/fmcfyYaL DuW9ajCuDj8RIhoO9Vb7rtG2jXpE1yxXODSO2UoNyo+QUf9FWTMJkit5qexz3Y+AF2Rd YZN3XaxExsyrLcItKf5+tJxtGbOXHhDS4X+4NMaRD+Y9Ux5OjBcGcGPQ4eryeeWDyrGs TK/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qPUDwhPL; 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 q13si15019430pfu.195.2022.01.24.13.58.57; Mon, 24 Jan 2022 13:59:08 -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=qPUDwhPL; 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 S1574410AbiAXVtF (ORCPT + 99 others); Mon, 24 Jan 2022 16:49:05 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:36628 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1448735AbiAXVNn (ORCPT ); Mon, 24 Jan 2022 16:13:43 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 09BFB60C60; Mon, 24 Jan 2022 21:13:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD7E9C340E5; Mon, 24 Jan 2022 21:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058822; bh=LiungtrnGfVSW2X2GPi7o4c/ZYIPirnCDi7gCObCpHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qPUDwhPLNIQr4vdGONMRyJFTGm0IYF2Jghdcj+ovrJTF6ZRS2V/cXF2Dzn5/2XW8B qj1TuQvNZl6DwmWJ4taqM53e06C7zu+pEoj13/FF5iwt1O1a/vpiB0yysGl9MUtzsd UBN3NrvlJ+WC4gogGm2CXyA4bkOwzlc+Ra6v2aqA= 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.16 0414/1039] net/mlx5: Set command entry semaphore up once got index free Date: Mon, 24 Jan 2022 19:36:43 +0100 Message-Id: <20220124184139.230822450@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 a46284ca51720..f588503157d04 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -148,8 +148,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); } @@ -1602,8 +1606,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 */ @@ -1626,10 +1628,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); @@ -1683,7 +1681,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force */ complete(&ent->done); } - up(sem); } } } -- 2.34.1