From patchwork Mon Aug 3 13:09:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 6929571 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 120199F358 for ; Mon, 3 Aug 2015 13:11:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 19E5720627 for ; Mon, 3 Aug 2015 13:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 426EC20567 for ; Mon, 3 Aug 2015 13:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753826AbbHCNLO (ORCPT ); Mon, 3 Aug 2015 09:11:14 -0400 Received: from [193.47.165.129] ([193.47.165.129]:41039 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753829AbbHCNLM (ORCPT ); Mon, 3 Aug 2015 09:11:12 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 3 Aug 2015 16:10:49 +0300 Received: from rsws33.mtr.labs.mlnx (dev-r-vrt-064.mtr.labs.mlnx [10.212.64.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id t73DAlBP030542; Mon, 3 Aug 2015 16:10:49 +0300 From: Matan Barak To: Doug Ledford Cc: linux-rdma@vger.kernel.org, Jason Gunthorpe , Matan Barak , Somnath Kotur , Haggai Eran , Or Gerlitz Subject: [PATCH for-next V1 3/3] IB/core: Fix possible deadlock in write_gid Date: Mon, 3 Aug 2015 16:09:02 +0300 Message-Id: <1438607342-11964-4-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1438607342-11964-1-git-send-email-matanb@mellanox.com> References: <1438607342-11964-1-git-send-email-matanb@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fixing the possible deadlock in write_gid: write_gid -> write_lock() find_gid -> read_lock_irqsave() ** DEAD LOCK **LOCK Fixing it by changing the write_lock to write_lock_irqsave. Squash-into: 'IB/core: Add RoCE GID table management' Signed-off-by: Matan Barak --- drivers/infiniband/core/cache.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 58a44bd..d7fdcb7 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -121,15 +121,16 @@ static int write_gid(struct ib_device *ib_dev, u8 port, { int ret = 0; struct net_device *old_net_dev; + unsigned long flags; /* in rdma_cap_roce_gid_table, this funciton should be protected by a * sleep-able lock. */ - write_lock(&table->data_vec[ix].lock); + write_lock_irqsave(&table->data_vec[ix].lock, flags); if (rdma_cap_roce_gid_table(ib_dev, port)) { table->data_vec[ix].props |= GID_TABLE_ENTRY_INVALID; - write_unlock(&table->data_vec[ix].lock); + write_unlock_irqrestore(&table->data_vec[ix].lock, flags); /* GID_TABLE_WRITE_ACTION_MODIFY currently isn't supported by * RoCE providers and thus only updates the cache. */ @@ -139,7 +140,7 @@ static int write_gid(struct ib_device *ib_dev, u8 port, else if (action == GID_TABLE_WRITE_ACTION_DEL) ret = ib_dev->del_gid(ib_dev, port, ix, &table->data_vec[ix].context); - write_lock(&table->data_vec[ix].lock); + write_lock_irqsave(&table->data_vec[ix].lock, flags); } old_net_dev = table->data_vec[ix].attr.ndev; @@ -161,7 +162,7 @@ static int write_gid(struct ib_device *ib_dev, u8 port, table->data_vec[ix].props &= ~GID_TABLE_ENTRY_INVALID; - write_unlock(&table->data_vec[ix].lock); + write_unlock_irqrestore(&table->data_vec[ix].lock, flags); if (!ret && rdma_cap_roce_gid_table(ib_dev, port)) { struct ib_event event;