Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp261465img; Mon, 18 Mar 2019 02:31:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQhbswrsfmKiGl/BBCfP0bCsXPirKiQMktjK5lRBKNDpgbHByBbQiu2UIQgCTs2ivQdNDV X-Received: by 2002:a63:2403:: with SMTP id k3mr9829916pgk.200.1552901474726; Mon, 18 Mar 2019 02:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901474; cv=none; d=google.com; s=arc-20160816; b=yCofk0y8P0BrdKone/ml3xXOKGiLppeuDVC0XswOWAyFsZ6XD/tokCIxswGHM0nMCz ZBra6hVs1diu4xNTNHDX+0USTFWTXUAY4UdTcXnqw0LAGExOyxmNgPVpn3DnXe0TTc9m JQkbk+LJZTdOXUmy7+7aYNeGHGsK8188E0693T4V6kF9K80Hdo9GyYo1pOlZPVzpIScy qAST//hFzRIthJFDQGthOH3MhH08EC6P+iKkw3YmGLdB16GREJntcrltj9zrDbUMtU5M okSepyzbUD0EOFC8bJKqgSctfYqvZgbNAdsc6f61hEbWjNmQTQG4WSPssPUXTFWGd1Ti IazA== 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=Skh7urKqf1h6X0jRxxNg/bDfnjhttIFixB/mF3+yzn0=; b=bLTzPXC+T1Cgva2vJxy1pI8WleQ78yk4RhoGj/akEishRCpa/O5HJN/k912dO2P/uY a2aMwjyO1jBC3dDbuIZB+bEISTCYbR1yNu3JJ8uCtM5GIsXvWPHKKSHz8gmfhUfr6oFu zf2O/kNWSM1lPtwNfLoICXveEFSh05u1OZ2NVMxNRs56s1uDFNChLwrSGjdYR5xZPnn/ VVIaAp1mDPgOmXdgMHUAjU+wftOpdCqZFhogwX8al0zRqbzzaj9c8V3zX8UU2P8q3wwG wZCe7fEd/Vf9ZU5OhTg+o7FH4Irnj92VuSTy9P1z38VNRVLYfIWwc7e1/tv7onL6r4tr oqOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dOzQle62; 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 p12si8666625plo.206.2019.03.18.02.30.59; Mon, 18 Mar 2019 02:31:14 -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=dOzQle62; 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 S1728243AbfCRJ3c (ORCPT + 99 others); Mon, 18 Mar 2019 05:29:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:35888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728236AbfCRJ33 (ORCPT ); Mon, 18 Mar 2019 05:29:29 -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 AA12B2075C; Mon, 18 Mar 2019 09:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901368; bh=ucODM53MYhIx0yQbjAVYzFivSWf09l9qxNPDe8C15D8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dOzQle62A4If1Skxy1erXnHYrsjwYX9piU5w15HyNPQ4pM/LXtC3qyWhuaIvy3R6u mdrHqDlkO54/pWyWHI/lcnrTkBeD1WSkAN1HncWKcGULx/63d23IjXaREgibmfJfFn 2ekzK/sLclKxEWDyfr0pvhXstdi6VB3edvpsSQwI= 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.20 24/52] net/mlx4_core: Fix locking in SRIOV mode when switching between events and polling Date: Mon, 18 Mar 2019 10:25:11 +0100 Message-Id: <20190318083846.314312550@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318083843.398913295@linuxfoundation.org> References: <20190318083843.398913295@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.20-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 @@ -2645,6 +2645,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; @@ -2670,6 +2672,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; } @@ -2682,6 +2686,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; @@ -2693,6 +2699,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)