From patchwork Wed Jan 17 00:14:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10168323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 22A6E600CA for ; Wed, 17 Jan 2018 00:14:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 184ED26E47 for ; Wed, 17 Jan 2018 00:14:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CE3A27528; Wed, 17 Jan 2018 00:14:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5F0326E47 for ; Wed, 17 Jan 2018 00:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751741AbeAQAOX (ORCPT ); Tue, 16 Jan 2018 19:14:23 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:62902 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750832AbeAQAOV (ORCPT ); Tue, 16 Jan 2018 19:14:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1516149129; x=1547685129; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=PfesODSTvTU12J12Fe5QQwL5n0+ZL4A9zsSzVwLpYAc=; b=blTfrPvaf0GujclFsxE6l15GBsUedWl252J8d1VaRZHOwmCi32h26/5+ vP7Jz54apl5czk0Dfnlri2VeWcCsDRBlhjJac3FwdoS43tIBQWv2fbfwj k8l4EkPd2KQSIrTd0Q51o4q7NjQdT0vZ3yGBmJIO61/9OWv8O2rbYf+1s r5Si9LLRx0OeGIEs7GPUPd+OwQotLbuDUeV03obcVQMAGQ2jTz0vX3mdk RNXmmmGWFDiJh2aymQokkeeCx2QG6A0k4np6Mw1CSzaKxc9W4RftYY+XJ oLg5vVYmt7xfHLvwR77wEB0bfeb0Ufxr03Wp4xETw0wXGEawlWi9wM5hL g==; X-IronPort-AV: E=Sophos;i="5.46,369,1511798400"; d="scan'208";a="165530444" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 17 Jan 2018 08:32:07 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 16 Jan 2018 16:09:34 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jan 2018 16:14:19 -0800 From: Bart Van Assche To: Jason Gunthorpe Cc: Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche Subject: [PATCH v2 01/14] IB/srpt: Make it safe to use RCU for srpt_device.rch_list Date: Tue, 16 Jan 2018 16:14:05 -0800 Message-Id: <20180117001418.7852-2-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180117001418.7852-1-bart.vanassche@wdc.com> References: <20180117001418.7852-1-bart.vanassche@wdc.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The next patch will iterate over rch_list from a context from which it is not allowed to block. Hence make rch_list RCU-safe. Signed-off-by: Bart Van Assche --- drivers/infiniband/ulp/srpt/ib_srpt.c | 13 ++++++++++--- drivers/infiniband/ulp/srpt/ib_srpt.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index d78f60dcc2ba..4dd15378bc7c 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -1906,7 +1906,7 @@ static void srpt_free_ch(struct kref *kref) { struct srpt_rdma_ch *ch = container_of(kref, struct srpt_rdma_ch, kref); - kfree(ch); + kfree_rcu(ch, rcu); } static void srpt_release_channel_work(struct work_struct *w) @@ -1945,11 +1945,17 @@ static void srpt_release_channel_work(struct work_struct *w) srp_max_req_size, DMA_FROM_DEVICE); mutex_lock(&sdev->mutex); - list_del_init(&ch->list); + list_del_rcu(&ch->list); if (ch->release_done) complete(ch->release_done); mutex_unlock(&sdev->mutex); + synchronize_rcu(); + + mutex_lock(&sdev->mutex); + INIT_LIST_HEAD(&ch->list); + mutex_unlock(&sdev->mutex); + wake_up(&sdev->ch_releaseQ); kref_put(&ch->kref, srpt_free_ch); @@ -2064,6 +2070,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, goto reject; } + init_rcu_head(&ch->rcu); kref_init(&ch->kref); ch->zw_cqe.done = srpt_zerolength_write_done; INIT_WORK(&ch->release_work, srpt_release_channel_work); @@ -2190,7 +2197,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, } mutex_lock(&sdev->mutex); - list_add_tail(&ch->list, &sdev->rch_list); + list_add_tail_rcu(&ch->list, &sdev->rch_list); mutex_unlock(&sdev->mutex); goto out; diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.h b/drivers/infiniband/ulp/srpt/ib_srpt.h index 11ce8c94a051..0ab59c60f2ef 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.h +++ b/drivers/infiniband/ulp/srpt/ib_srpt.h @@ -244,6 +244,7 @@ enum rdma_ch_state { * @qp: IB queue pair used for communicating over this channel. * @cq: IB completion queue for this channel. * @zw_cqe: Zero-length write CQE. + * @rcu: RCU head. * @kref: kref for this channel. * @rq_size: IB receive queue size. * @max_rsp_size: Maximum size of an RSP response message in bytes. @@ -276,6 +277,7 @@ struct srpt_rdma_ch { struct ib_qp *qp; struct ib_cq *cq; struct ib_cqe zw_cqe; + struct rcu_head rcu; struct kref kref; int rq_size; u32 max_rsp_size;