Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp266150img; Mon, 18 Mar 2019 02:38:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUO2rZsCJUdM2m7Zppydesq/08QvJzSdkbPKRcSOGiemPNhppMsP/lY8UIhfSvQ5kr3YuU X-Received: by 2002:a17:902:20e3:: with SMTP id v32mr18897552plg.213.1552901886389; Mon, 18 Mar 2019 02:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901886; cv=none; d=google.com; s=arc-20160816; b=m+uHRmdc5w2GGiFkesyLK5c9/hN8vk4soGCiXfp5idk+Kw7i5RfvOqULGoF9m4vPlM XsJ+BDhsxXlniN9aP+1j73n6g2aLRzC/7S4r5byTM8dp12XVJbUT9cMBNoZE2/F+ACI3 bQDvfuxOcBJrmf6lg69imw1v8uI8s+c88MU5CWCrGR0AAbOPhnu0snqsSUfvLc/IEbjD DGrhGg2I8Hn/lzgYNLnPMnlYm6SFpRarn2pTnL/0If8L9j5+KuenKDlEagp3oEp35R9h oTVaYNxr/Vqi4jExJQSsfn456HjRLNz8/roxXRYWffskYPIyZSeVhannLywn+vM4vM1F xyTQ== 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=84UG6P+CkskZPw4yGUvSUAsjSTXx1hK/WiUWYbK1pxc=; b=HFEhVRuqs0wK7et+YOpY86KK24oYXJGglOLGUu1LDX0JM2CbwI4eBsLomYsATt9Our 8O9ZwROY5cuiAezW6/gEZGuGKI99OfxeR5elMNpGZzGZzaQF+MzoE7UOGmS81IuGU/Ax N588Ah/8A+BN+OM/w0ZM8L+KSEpP9JDDKmzAuUNe0USUZ1h0UZ8zjks7WOhB0yncEMlA iCer+yo0m0b57Ha8n0PZyt1qJW6LUc2r2xE14BiaZs7A7QUp7RlB02mSNgoRT9qA8Usk Ox2m/71tSE6YyiDS1gTMdyiGHOnFdxvuHMbrfaFmAaQhvgRDWnBCQUVRNYtvvTwfAVRF 3mnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z9FT3zZ+; 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 t5si9452407pgn.484.2019.03.18.02.37.51; Mon, 18 Mar 2019 02:38:06 -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=z9FT3zZ+; 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 S2387685AbfCRJge (ORCPT + 99 others); Mon, 18 Mar 2019 05:36:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:44854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387672AbfCRJgc (ORCPT ); Mon, 18 Mar 2019 05:36:32 -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 9C4902075C; Mon, 18 Mar 2019 09:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901791; bh=SnHexK42CKNPnP8JdHH9iO3j9dXrA9qlBmdKIgRwjv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z9FT3zZ+2/cYC+wK31Ivbvhf8m/lsfqftPF1A+jEhxENwaIoH82PuJD+iKx/b4SfZ 3At0GkH1pKgUa42y4dtUb1pKggblkeOrSL0nZhEOmncDd1f527RpWlhSMg2iiaKR3R u88Lhp3YHqxYdgDx0mchW9QxGK3Ngsd1Amqp9o0Q= 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.9 15/31] net/mlx4_core: Fix locking in SRIOV mode when switching between events and polling Date: Mon, 18 Mar 2019 10:25:50 +0100 Message-Id: <20190318084211.005775481@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084210.397476003@linuxfoundation.org> References: <20190318084210.397476003@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.9-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 @@ -2633,6 +2633,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; @@ -2658,6 +2660,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; } @@ -2670,6 +2674,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; @@ -2681,6 +2687,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)