Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1176814pxb; Fri, 20 Nov 2020 03:13:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyzrZ71oHjE0daWGlrNZnTSXPL340ZV4At1Z+QQLOyQ8uCU6SO3NgbOjzdtMZ4yFz8XH2k X-Received: by 2002:a17:906:15cc:: with SMTP id l12mr30849392ejd.363.1605870789022; Fri, 20 Nov 2020 03:13:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605870789; cv=none; d=google.com; s=arc-20160816; b=BZ10fBhJauDLcFvDbzzSFI+mHYaY1l2c/PdrkLZ3/d5tMoBljiQgAqg6RmP//HV4qb qNVyBTMwL+UpKoI+QOY1miqIC/kgi9DFZf4eSGYJ8UQZP9r6il+h7rkzJhqKNnZ4cJ5h 3d8CmY8i68wtLR3jgeQVCYaJDzsDf2EsF/iqFIAiwpqcd1FW15DMuVgF2IPHbW4njTvt fI6IYsyLbcTXuxUm8QflBXQUGPNR/AstwfhvkAqMPaDrgZqEPuB0heMvwCxfnnasu/GR puWcGCHRZdYODUguEtrVsh3nks/iyLJb1e5s+yiENWPHARK2o9cAHl4ayi86M9H4klEe S+Zg== 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=cp36dY7TZjtFkOUyOI0TewHLUn05K27t1rutAs9cKNQ=; b=jU+cWV7sLM2tpv1vjjDSkfMwtzAsp8CBdGCuTJYpY4dETET/TypLeRsJjCG/innzCt BMJWFP8QYN2M7Cl+stDkOv6iv/pWs3i4ndQzgcAnfSHZMocW3xqvhstKv+DQhAbSMbx7 WZVI83uazzIyMa2/JQSmhJM81RNOW7JKa4vdP6LWzWq5oqry+3cJy7ahVEYK19bXy4gu GtZssSRI0jGgSIC4Ut+obCztzBzsd8PXbuqbZerC4Irk3St3F53Ni9Up6NaQzOFgu8C4 NfzKpIIh1rGoUe4VAIWwhm2GZ9ns7Ufp4O7XuTFXQ2sWTTIXSP1XzBbB+y3s1MVuskK5 c6Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oQ874c1C; 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 bc3si1553263edb.258.2020.11.20.03.12.46; Fri, 20 Nov 2020 03:13:09 -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=oQ874c1C; 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 S1728506AbgKTLJP (ORCPT + 99 others); Fri, 20 Nov 2020 06:09:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:55132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728498AbgKTLHM (ORCPT ); Fri, 20 Nov 2020 06:07:12 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B6882245B; Fri, 20 Nov 2020 11:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1605870432; bh=t9uLRtx0vP9bKuog9h7FCpvLi1AhNsKDwZrA1tIGNYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oQ874c1C7N/hDumxS12XdaufUF65YqvVuBgbiV3katK31zdK5uGSnC5igl2bzss4o +Urmwb5AzkgnOUpYO+R/OFRugqVq63NCJ+jAz9pnnA02AFFwaggluWmnBBzB8XsQpT nqZuGg/2AkDXbJZVVc/5OqfEbsJK9VyeHK2z7nHA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eran Ben Elisha , Moshe Shemesh , Saeed Mahameed , Timo Rothenpieler Subject: [PATCH 5.4 10/17] net/mlx5: Add retry mechanism to the command entry index allocation Date: Fri, 20 Nov 2020 12:03:37 +0100 Message-Id: <20201120104541.571471236@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201120104541.058449969@linuxfoundation.org> References: <20201120104541.058449969@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: Eran Ben Elisha commit 410bd754cd73c4a2ac3856d9a03d7b08f9c906bf upstream. It is possible that new command entry index allocation will temporarily fail. The new command holds the semaphore, so it means that a free entry should be ready soon. Add one second retry mechanism before returning an error. Patch "net/mlx5: Avoid possible free of command entry while timeout comp handler" increase the possibility to bump into this temporarily failure as it delays the entry index release for non-callback commands. Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Signed-off-by: Eran Ben Elisha Reviewed-by: Moshe Shemesh Signed-off-by: Saeed Mahameed Cc: Timo Rothenpieler Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -883,6 +883,25 @@ static bool opcode_allowed(struct mlx5_c return cmd->allowed_opcode == opcode; } +static int cmd_alloc_index_retry(struct mlx5_cmd *cmd) +{ + unsigned long alloc_end = jiffies + msecs_to_jiffies(1000); + int idx; + +retry: + idx = cmd_alloc_index(cmd); + if (idx < 0 && time_before(jiffies, alloc_end)) { + /* Index allocation can fail on heavy load of commands. This is a temporary + * situation as the current command already holds the semaphore, meaning that + * another command completion is being handled and it is expected to release + * the entry index soon. + */ + cpu_relax(); + goto retry; + } + return idx; +} + static void cmd_work_handler(struct work_struct *work) { struct mlx5_cmd_work_ent *ent = container_of(work, struct mlx5_cmd_work_ent, work); @@ -900,7 +919,7 @@ static void cmd_work_handler(struct work sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem; down(sem); if (!ent->page_queue) { - alloc_ret = cmd_alloc_index(cmd); + alloc_ret = cmd_alloc_index_retry(cmd); if (alloc_ret < 0) { mlx5_core_err(dev, "failed to allocate command entry\n"); if (ent->callback) {