Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp265981img; Mon, 18 Mar 2019 02:37:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmZS1JY8zNhuHwWzMcOn7tzWxolIu/hh0a0P+jbeRLDJC8MaX6nQv5+xd93mLA50PlVLod X-Received: by 2002:a65:5cc3:: with SMTP id b3mr9991201pgt.82.1552901870412; Mon, 18 Mar 2019 02:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901870; cv=none; d=google.com; s=arc-20160816; b=jhI8oUoZgdZ+lEjBi3cjRXjoQlUvTdhpPHulXC+2q3TTNdc90KZTlHh6eob/2j8kyJ 7z4YSA12ZGHkMJ4JcCh4z/8WUcredoJZeqInAl0EfJ2QFr1rD/9HEU+i2rPtHWT9A0vj P4cGoZEgH8f2y1Ls0dYPdjVKQMDzqAnu9V/G0J1sEmPy404B48GV7DjxtwEYuLikMH51 1JjI0x4aIi5WqaF93V1w7rlvL6ItjI72nZZaJfk4rbfPIdn3bD2uq4PpVkuSZ83ANaPE t4sEJ2v96ak5zdtusapb5CoO4UY3gwQJxPrkkSytWhBL6WTxpSASRVtrGvPWJkkpYE1/ 4sbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=u3H0kO+hppRuPSZqZtrUJ91ytZYuHwWlb1WCrRZBnF4=; b=ecrI1Nfxn1U7ZdNdhlGaWWNOlmw3hOusFnpcxrTj9dxMglb/9v8DHtfsrKMnc3IL4r xU5Wq1IPonUR8770y/zGouqLvB9PI6AJJ4+XnbZ5eiICphuVhkJY0PBmCiGoN9tX65X2 ej49sQeb+DZQ5qWSLXS0FgT68BWGC/EkKOaYEg2jE9egusnoIeHtiEMLuKyUmsL3ByvP YLcE2dEh97Aojq6hOHg2VWrYkS7f6xg8xqieBoI/Wq6mhn6lyCPPt3zZVIFjzZ7JRBFo XeJKXG7t6RC//1pgUEY0HgwZ5N22gIX3lrt4CWmcC/LByNrwlJnBrH5hONwVdDNspfe2 J+4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LAcQ8ffe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si9027042pga.315.2019.03.18.02.37.35; Mon, 18 Mar 2019 02:37:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LAcQ8ffe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387421AbfCRJfB (ORCPT + 99 others); Mon, 18 Mar 2019 05:35:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:43358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728609AbfCRJe7 (ORCPT ); Mon, 18 Mar 2019 05:34:59 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 A01FF2083D; Mon, 18 Mar 2019 09:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901698; bh=JnLhwcZY6raWV65FCiKlnWeBel6RPAlvcNYE8qE3fXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LAcQ8ffemrMDr5DT355RbodcTkqcThugptB4fZi8wACGmXuWkn1PuGEeDFJj3f0Ji d6x8DmEJoYD+haAGA3VbPNWc2Kt2QyCjxeT/HsS47o/SjF4fMWLdMHr7PurCojp8Jo 0IeQjf5M0EJaGt2f88/4Hd/4umkXCZW9P7WhHiBo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Morgenstein , Tariq Toukan , "David S. Miller" Subject: [PATCH 4.14 20/34] net/mlx4_core: Fix locking in SRIOV mode when switching between events and polling Date: Mon, 18 Mar 2019 10:25:44 +0100 Message-Id: <20190318084147.497646192@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084144.657740413@linuxfoundation.org> References: <20190318084144.657740413@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jack Morgenstein [ Upstream commit c07d27927f2f2e96fcd27bb9fb330c9ea65612d0 ] In procedures mlx4_cmd_use_events() and mlx4_cmd_use_polling(), we need to guarantee that there are no FW commands in progress on the comm channel (for VFs) or wrapped FW commands (on the PF) when SRIOV is active. We do this by also taking the slave_cmd_mutex when SRIOV is active. This is especially important when switching from event to polling, since we free the command-context array during the switch. If there are FW commands in progress (e.g., waiting for a completion event), the completion event handler will access freed memory. Since the decision to use comm_wait or comm_poll is taken before grabbing the event_sem/poll_sem in mlx4_comm_cmd_wait/poll, we must take the slave_cmd_mutex as well (to guarantee that the decision to use events or polling and the call to the appropriate cmd function are atomic). Fixes: a7e1f04905e5 ("net/mlx4_core: Fix deadlock when switching between polling and event fw commands") Signed-off-by: Jack Morgenstein Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx4/cmd.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -2642,6 +2642,8 @@ int mlx4_cmd_use_events(struct mlx4_dev if (!priv->cmd.context) return -ENOMEM; + if (mlx4_is_mfunc(dev)) + mutex_lock(&priv->cmd.slave_cmd_mutex); down_write(&priv->cmd.switch_sem); for (i = 0; i < priv->cmd.max_cmds; ++i) { priv->cmd.context[i].token = i; @@ -2667,6 +2669,8 @@ int mlx4_cmd_use_events(struct mlx4_dev down(&priv->cmd.poll_sem); priv->cmd.use_events = 1; up_write(&priv->cmd.switch_sem); + if (mlx4_is_mfunc(dev)) + mutex_unlock(&priv->cmd.slave_cmd_mutex); return err; } @@ -2679,6 +2683,8 @@ void mlx4_cmd_use_polling(struct mlx4_de struct mlx4_priv *priv = mlx4_priv(dev); int i; + if (mlx4_is_mfunc(dev)) + mutex_lock(&priv->cmd.slave_cmd_mutex); down_write(&priv->cmd.switch_sem); priv->cmd.use_events = 0; @@ -2690,6 +2696,8 @@ void mlx4_cmd_use_polling(struct mlx4_de up(&priv->cmd.poll_sem); up_write(&priv->cmd.switch_sem); + if (mlx4_is_mfunc(dev)) + mutex_unlock(&priv->cmd.slave_cmd_mutex); } struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev)