From patchwork Mon Apr 4 18:23:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 8743621 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 0DBBA9F336 for ; Mon, 4 Apr 2016 18:29:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5CE32024F for ; Mon, 4 Apr 2016 18:29:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97D2820155 for ; Mon, 4 Apr 2016 18:29:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756070AbcDDS3D (ORCPT ); Mon, 4 Apr 2016 14:29:03 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:40698 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752972AbcDDS3C (ORCPT ); Mon, 4 Apr 2016 14:29:02 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 400BB22C946; Mon, 4 Apr 2016 18:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=linux-iscsi.org; s=default.private; t=1459794235; bh=ktq8k0tkRNNpUPJrdoxk9cG0Py7MVFH pxMn0QfmAogY=; h=From:To:Cc:Subject:Date:Message-Id; b=aGOKNfTdnfGV kjc0xPxMm3urP80Rdpex2yMCDrNaK79H+Pz1fTH++bNHSdQ7UUno4IzV5Z4MAE/H9b1 bsnUxbYru+ayellx+Zcra0Fnp/ZEhvP6pS9kWtNJyzyKo35e1xtUW2+35hXYR1afL5Z J3KFk6IXUeuJ8y/vAZSau3Riw= From: "Nicholas A. Bellinger" To: target-devel Cc: linux-rdma , Bart Van Assche , Sagi Grimberg , Doug Ledford , Nicholas Bellinger Subject: [PATCH] ib_srpt: Add missing ioctx->buf + ->dma alloc_session_cb init Date: Mon, 4 Apr 2016 18:23:53 +0000 Message-Id: <1459794233-19187-1-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 From: Nicholas Bellinger This patch addresses the v4.6-rc1 breakage for ib_srpt, and adds the missing srpt_alloc_session_cb() to setup existing srpt_ioctx buf + dma resources for srpt_send_ioctx->ioctx. Also, add a srpt_free_sess_cmd_map_res() to do the clean during shutdown in srpt_release_channel_work(), and drop the now left-over ch->ioctx_ring[]. Reported-by: Bart Van Assche Cc: Bart Van Assche Cc: Sagi Grimberg Cc: Doug Ledford Signed-off-by: Nicholas Bellinger --- drivers/infiniband/ulp/srpt/ib_srpt.c | 79 +++++++++++++++++++++++++++-------- drivers/infiniband/ulp/srpt/ib_srpt.h | 2 - 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 0bd3cb2..c4e0a0a 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -1266,7 +1266,9 @@ static struct srpt_send_ioctx *srpt_get_send_ioctx(struct srpt_rdma_ch *ch) { struct se_session *se_sess; struct srpt_send_ioctx *ioctx; - int tag; + void *buf; + dma_addr_t dma; + int tag, index; BUG_ON(!ch); se_sess = ch->sess; @@ -1277,12 +1279,19 @@ static struct srpt_send_ioctx *srpt_get_send_ioctx(struct srpt_rdma_ch *ch) return NULL; } ioctx = &((struct srpt_send_ioctx *)se_sess->sess_cmd_map)[tag]; + buf = ioctx->ioctx.buf; + dma = ioctx->ioctx.dma; + index = ioctx->ioctx.index; + memset(ioctx, 0, sizeof(struct srpt_send_ioctx)); ioctx->ch = ch; spin_lock_init(&ioctx->spinlock); ioctx->state = SRPT_STATE_NEW; init_completion(&ioctx->tx_done); + ioctx->ioctx.buf = buf; + ioctx->ioctx.dma = dma; + ioctx->ioctx.index = index; ioctx->cmd.map_tag = tag; return ioctx; @@ -1961,6 +1970,24 @@ static void srpt_free_ch(struct kref *kref) kfree(ch); } +static void srpt_free_sess_cmd_map_res(struct se_session *se_sess) +{ + struct srpt_rdma_ch *ch = se_sess->fabric_sess_ptr; + struct srpt_device *sdev = ch->sport->sdev; + struct srpt_send_ioctx *ioctx; + u32 i, dma_size = ch->rsp_size; + + for (i = 0; i < ch->rq_size; i++) { + ioctx = &((struct srpt_send_ioctx *)se_sess->sess_cmd_map)[i]; + + if (!ib_dma_mapping_error(sdev->device, ioctx->ioctx.dma)) + ib_dma_unmap_single(sdev->device, ioctx->ioctx.dma, + dma_size, DMA_TO_DEVICE); + if (ioctx->ioctx.buf) + kfree(ioctx->ioctx.buf); + } +} + static void srpt_release_channel_work(struct work_struct *w) { struct srpt_rdma_ch *ch; @@ -1981,6 +2008,7 @@ static void srpt_release_channel_work(struct work_struct *w) target_wait_for_sess_cmds(se_sess); transport_deregister_session_configfs(se_sess); + srpt_free_sess_cmd_map_res(se_sess); transport_deregister_session(se_sess); ch->sess = NULL; @@ -1988,10 +2016,6 @@ static void srpt_release_channel_work(struct work_struct *w) srpt_destroy_ch_ib(ch); - srpt_free_ioctx_ring((struct srpt_ioctx **)ch->ioctx_ring, - ch->sport->sdev, ch->rq_size, - ch->rsp_size, DMA_TO_DEVICE); - mutex_lock(&sdev->mutex); list_del_init(&ch->list); if (ch->release_done) @@ -2003,6 +2027,35 @@ static void srpt_release_channel_work(struct work_struct *w) kref_put(&ch->kref, srpt_free_ch); } +static int srpt_alloc_session_cb(struct se_portal_group *se_tpg, + struct se_session *se_sess, void *p) +{ + struct srpt_rdma_ch *ch = p; + struct srpt_device *sdev = ch->sport->sdev; + struct srpt_send_ioctx *ioctx; + u32 i, dma_size = ch->rsp_size; + + for (i = 0; i < ch->rq_size; i++) { + ioctx = &((struct srpt_send_ioctx *)se_sess->sess_cmd_map)[i]; + ioctx->ioctx.index = i; + + ioctx->ioctx.buf = kmalloc(dma_size, GFP_KERNEL); + if (!ioctx->ioctx.buf) + goto err_free_res; + + ioctx->ioctx.dma = ib_dma_map_single(sdev->device, ioctx->ioctx.buf, + dma_size, DMA_TO_DEVICE); + if (ib_dma_mapping_error(sdev->device, ioctx->ioctx.dma)) + goto err_free_res; + } + + return 0; + +err_free_res: + srpt_free_sess_cmd_map_res(se_sess); + return -ENOMEM; +} + /** * srpt_cm_req_recv() - Process the event IB_CM_REQ_RECEIVED. * @@ -2136,20 +2189,13 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, INIT_LIST_HEAD(&ch->cmd_wait_list); ch->rsp_size = ch->sport->port_attrib.srp_max_rsp_size; - ch->ioctx_ring = (struct srpt_send_ioctx **) - srpt_alloc_ioctx_ring(ch->sport->sdev, ch->rq_size, - sizeof(*ch->ioctx_ring[0]), - ch->rsp_size, DMA_TO_DEVICE); - if (!ch->ioctx_ring) - goto free_ch; - ret = srpt_create_ch_ib(ch); if (ret) { rej->reason = cpu_to_be32( SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES); pr_err("rejected SRP_LOGIN_REQ because creating" " a new RDMA channel failed.\n"); - goto free_ring; + goto free_ch; } ret = srpt_ch_qp_rtr(ch, ch->qp); @@ -2175,7 +2221,8 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, try_again: ch->sess = target_alloc_session(&sport->port_tpg_1, ch->rq_size, sizeof(struct srpt_send_ioctx), - TARGET_PROT_NORMAL, p, ch, NULL); + TARGET_PROT_NORMAL, p, ch, + srpt_alloc_session_cb); if (IS_ERR(ch->sess)) { pr_info("Rejected login because no ACL has been" " configured yet for initiator %s.\n", p); @@ -2240,10 +2287,6 @@ release_channel: destroy_ib: srpt_destroy_ch_ib(ch); -free_ring: - srpt_free_ioctx_ring((struct srpt_ioctx **)ch->ioctx_ring, - ch->sport->sdev, ch->rq_size, - ch->rsp_size, DMA_TO_DEVICE); free_ch: kfree(ch); diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.h b/drivers/infiniband/ulp/srpt/ib_srpt.h index ca288f0..a0e3403 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.h +++ b/drivers/infiniband/ulp/srpt/ib_srpt.h @@ -251,7 +251,6 @@ enum rdma_ch_state { * @spinlock: Protects free_list and state. * @free_list: Head of list with free send I/O contexts. * @state: channel state. See also enum rdma_ch_state. - * @ioctx_ring: Send ring. * @list: Node for insertion in the srpt_device.rch_list list. * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This * list contains struct srpt_ioctx elements and is protected @@ -279,7 +278,6 @@ struct srpt_rdma_ch { spinlock_t spinlock; struct list_head free_list; enum rdma_ch_state state; - struct srpt_send_ioctx **ioctx_ring; struct list_head list; struct list_head cmd_wait_list; struct se_session *sess;