Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3592808pxb; Mon, 24 Jan 2022 13:03:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1FyhsEF0Tu/HJ6DSYDA8QiH1RrhELhNdaMiqVmhANRwKoRxiuesvXyWyAGc7iOXw+hMXf X-Received: by 2002:a17:902:f54b:b0:14b:1651:58ca with SMTP id h11-20020a170902f54b00b0014b165158camr16347260plf.58.1643058200489; Mon, 24 Jan 2022 13:03:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058200; cv=none; d=google.com; s=arc-20160816; b=gq63CthjFdgx+DYPqm2mO6SBifKmbFmCmtQwGqaWME7su68rYG1jlGunOJKtuTcL8u X91X1ovLYtNBBpFJgObxR2RAGEqSIh/YyH8FhNZPWSxiqEVfOwPvV303odKNr9uE/rBz FvZbOWvPp1/7xI6rCZXUzsL337ix2w8BJww2hLegEB8Q/AGW+HGaPV4J3VurH7Xe/cOL kccM8X/cwOt8EzZGnGDDpo5Om1I3XWKUbDVfDTlDSoNfW/5UUgYvRDPKxwO28/g06fdm KsuxgKl6O++BdR0XPDLskE9+RKx+mkRIfRnLuxI2drMw+I68Ve1ysXs3iNh8yfA3CY1R QH4A== 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=49n2HSJpgADEpwoKuefDRHcEDvkDu/oflGRnaVm5NzI=; b=yiNzQhQXA3rlRLGdodz++JOFwB1nl3lahLWgGN1mLeU29lWBYmthaaqJMAFahNfWET ntVjm0GzlFP4dax+9YPyreHf9Xwzi9+dOVyzpixDzJXJF1VzelQh8SIdppsS4kSEXRgJ Cxa2nTEcDpyVhqnO3oo71kFIi5IolsVl7luAeWzbaxta0aZNwOoj6XBZaHh/6CaYIAbS l0rASIwP/N1gBUX8DoPdr5RtnMYSf5y37QGDoGrbYPhcjve0ZizYhPQ7DN6r2xriKQMT 8zCZ2zNFyZM4CpKUFgfas/kxNnIRT43CuIHGd9JavnK4KM1aHmXK7wBN6vd45xAgXNFB 4eoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QOEnNnjp; 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 y1si14308606pga.254.2022.01.24.13.03.08; Mon, 24 Jan 2022 13:03:20 -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=QOEnNnjp; 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 S1382647AbiAXU0D (ORCPT + 99 others); Mon, 24 Jan 2022 15:26:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344220AbiAXUDp (ORCPT ); Mon, 24 Jan 2022 15:03:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63074C02B740; Mon, 24 Jan 2022 11:30:10 -0800 (PST) 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 2057BB8122F; Mon, 24 Jan 2022 19:30:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DDD4C340E5; Mon, 24 Jan 2022 19:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052607; bh=wMh5zDc0gL+V8vlUgdXNvVyQzuDbs091M1h//hPJaC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QOEnNnjpJw9JAm56pXZzh9Ujz7qGk7vsKCkdkrjrnT1RlO18dFZ7enO9HtZdtz3kl Th4WCq3Y7If0vdKPYRHAQ3pa/SC7uSFftTwybe1bVEJZDUsGCYbE7jRzb4sNFsPQGM xRlvqMa+bNSSHLYrONBklkSzKNysX5MfNKaVyuY8= 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.4 115/320] net/mlx5: Set command entry semaphore up once got index free Date: Mon, 24 Jan 2022 19:41:39 +0100 Message-Id: <20220124183957.614213488@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 bf091a6c0cd2d..cedb102ce8d2f 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); } @@ -1577,8 +1581,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 */ @@ -1601,10 +1603,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); @@ -1658,7 +1656,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force */ complete(&ent->done); } - up(sem); } } } -- 2.34.1