From e837ec7dcd0b26cfffbf9ccc336872c4e9e6c757 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 25 Oct 2016 20:49:21 +0000 Subject: [PATCH 1/5] scst_user: Port to Linux kernel v4.9 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7016 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 33a2cc7ed..34f5fb1be 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -1267,8 +1267,13 @@ static int dev_user_map_buf(struct scst_user_cmd *ucmd, unsigned long ubuff, (ucmd->cmd != NULL) ? ucmd->cmd->bufflen : -1); down_read(&tsk->mm->mmap_sem); +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) rc = get_user_pages(ubuff, ucmd->num_data_pages, 1/*writable*/, 0/*don't force*/, ucmd->data_pages, NULL); +#else + rc = get_user_pages(ubuff, ucmd->num_data_pages, FOLL_WRITE, + ucmd->data_pages, NULL); +#endif up_read(&tsk->mm->mmap_sem); /* get_user_pages() flushes dcache */ From 120c66f9243938a89587fb96426fc45ea9d616dd Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 25 Oct 2016 20:50:15 +0000 Subject: [PATCH 2/5] ib_srpt: Cache global L_Key This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7017 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 7 ++++--- srpt/src/ib_srpt.h | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 3e70ac758..608395170 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -958,7 +958,7 @@ static int srpt_post_recv(struct srpt_device *sdev, struct srpt_rdma_ch *ch, list.addr = ioctx->ioctx.dma + ioctx->ioctx.offset; list.length = srp_max_req_size; - list.lkey = sdev->mr->lkey; + list.lkey = sdev->lkey; wr.next = NULL; wr.sg_list = &list; @@ -1001,7 +1001,7 @@ static int srpt_post_send(struct srpt_rdma_ch *ch, list.addr = ioctx->ioctx.dma; list.length = len; - list.lkey = sdev->mr->lkey; + list.lkey = sdev->lkey; wr.next = NULL; wr.wr_id = encode_wr_id(SRPT_SEND, ioctx->ioctx.index); @@ -3299,7 +3299,7 @@ static int srpt_map_sg_to_ib_sge(struct srpt_rdma_ch *ch, while (rsize > 0 && tsize > 0) { sge->addr = dma_addr; - sge->lkey = ch->sport->sdev->mr->lkey; + sge->lkey = ch->sport->sdev->lkey; if (rsize >= dma_len) { sge->length = @@ -4357,6 +4357,7 @@ static void srpt_add_one(struct ib_device *device) pr_err("ib_get_dma_mr() failed: %ld\n", PTR_ERR(sdev->mr)); goto err_pd; } + sdev->lkey = sdev->mr->lkey; sdev->srq_size = min(max(srpt_srq_size, MIN_SRPT_SRQ_SIZE), sdev->dev_attr.max_srq_wr); diff --git a/srpt/src/ib_srpt.h b/srpt/src/ib_srpt.h index 70c2c1c4c..03c0d5528 100644 --- a/srpt/src/ib_srpt.h +++ b/srpt/src/ib_srpt.h @@ -442,7 +442,8 @@ struct srpt_port { * struct srpt_device - Information associated by SRPT with a single HCA. * @device: Backpointer to the struct ib_device managed by the IB core. * @pd: IB protection domain. - * @mr: L_Key (local key) with write access to all local memory. + * @mr: MR with write access to all local memory. + * @lkey: L_Key (local key) with write access to all local memory. * @srq: Per-HCA SRQ (shared receive queue). * @cm_id: Connection identifier. * @dev_attr: Attributes of the InfiniBand device as obtained during the @@ -460,6 +461,7 @@ struct srpt_device { struct ib_srq *srq; struct ib_cm_id *cm_id; struct ib_device_attr dev_attr; + u32 lkey; int srq_size; bool use_srq; struct srpt_recv_ioctx **ioctx_ring; From 8c04ce53f4f75f5e836c9a09cbbef10d2447af5b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 25 Oct 2016 20:50:34 +0000 Subject: [PATCH 3/5] ib_srpt: Port to Linux kernel v4.9 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7018 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 14 ++++++++++++++ srpt/src/ib_srpt.c | 10 +++++++++- srpt/src/ib_srpt.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 98b21fd60..8bb03ea6c 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -25,6 +25,7 @@ #include /* kmalloc() */ #include /* sync_page_range() */ #include /* struct scsi_cmnd */ +#include /* */ @@ -512,6 +513,19 @@ typedef void (*rcu_callback_t)(struct rcu_head *); __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) #endif +/* */ +/* commit ed082d36 */ +#ifndef ib_alloc_pd +static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) +{ + return ib_alloc_pd(device); +} +#define ib_alloc_pd(device, flags) \ + ({ \ + (void)(flags), ib_alloc_pd_backport(device); \ + }) +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) && \ diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 608395170..f6bae1923 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -4346,18 +4346,22 @@ static void srpt_add_one(struct ib_device *device) sdev->dev_attr = device->attrs; #endif - sdev->pd = ib_alloc_pd(device); + sdev->pd = ib_alloc_pd(device, 0); if (IS_ERR(sdev->pd)) { pr_err("ib_alloc_pd() failed: %ld\n", PTR_ERR(sdev->pd)); goto free_dev; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) sdev->mr = ib_get_dma_mr(sdev->pd, IB_ACCESS_LOCAL_WRITE); if (IS_ERR(sdev->mr)) { pr_err("ib_get_dma_mr() failed: %ld\n", PTR_ERR(sdev->mr)); goto err_pd; } sdev->lkey = sdev->mr->lkey; +#else + sdev->lkey = sdev->pd->local_dma_lkey; +#endif sdev->srq_size = min(max(srpt_srq_size, MIN_SRPT_SRQ_SIZE), sdev->dev_attr.max_srq_wr); @@ -4481,8 +4485,10 @@ err_ring: if (sdev->use_srq) ib_destroy_srq(sdev->srq); err_mr: +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) ib_dereg_mr(sdev->mr); err_pd: +#endif ib_dealloc_pd(sdev->pd); free_dev: kfree(sdev); @@ -4554,7 +4560,9 @@ static void srpt_remove_one(struct ib_device *device, void *client_data) if (sdev->use_srq) ib_destroy_srq(sdev->srq); +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) ib_dereg_mr(sdev->mr); +#endif ib_dealloc_pd(sdev->pd); kfree(sdev); diff --git a/srpt/src/ib_srpt.h b/srpt/src/ib_srpt.h index 03c0d5528..b410dd69e 100644 --- a/srpt/src/ib_srpt.h +++ b/srpt/src/ib_srpt.h @@ -457,7 +457,9 @@ struct srpt_port { struct srpt_device { struct ib_device *device; struct ib_pd *pd; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) struct ib_mr *mr; +#endif struct ib_srq *srq; struct ib_cm_id *cm_id; struct ib_device_attr dev_attr; From bfe9d77412c8f9dc040d195a2bfe4d00620df223 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 25 Oct 2016 22:21:46 +0000 Subject: [PATCH 4/5] isert-scst: Cache L_Key This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7019 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/iser.h | 1 + iscsi-scst/kernel/isert-scst/iser_pdu.c | 2 +- iscsi-scst/kernel/isert-scst/iser_rdma.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/isert-scst/iser.h b/iscsi-scst/kernel/isert-scst/iser.h index 7b8c0536d..143d863c4 100644 --- a/iscsi-scst/kernel/isert-scst/iser.h +++ b/iscsi-scst/kernel/isert-scst/iser.h @@ -234,6 +234,7 @@ struct isert_device { struct ib_device *ib_dev; struct ib_pd *pd; struct ib_mr *mr; + u32 lkey; struct list_head devs_node; /* conn_list and refcnt protected by dev_list_mutex */ diff --git a/iscsi-scst/kernel/isert-scst/iser_pdu.c b/iscsi-scst/kernel/isert-scst/iser_pdu.c index 25ee75ddd..7a0810185 100644 --- a/iscsi-scst/kernel/isert-scst/iser_pdu.c +++ b/iscsi-scst/kernel/isert-scst/iser_pdu.c @@ -201,7 +201,7 @@ static int isert_alloc_for_rdma(struct isert_cmnd *pdu, int sge_cnt, isert_wr_set_fields(&pdu->wr[i], isert_conn, pdu); for (i = 0; i < sge_cnt; ++i) - pdu->sg_pool[i].lkey = isert_conn->isert_dev->mr->lkey; + pdu->sg_pool[i].lkey = isert_conn->isert_dev->lkey; goto out; diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index 7699abc74..8c6424acf 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -1092,6 +1092,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev) isert_dev->ib_dev = ib_dev; isert_dev->pd = pd; isert_dev->mr = mr; + isert_dev->lkey = mr->lkey; INIT_LIST_HEAD(&isert_dev->conn_list); From 599a059cf8ad647d189cbea294b19192bf578c84 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 25 Oct 2016 22:22:07 +0000 Subject: [PATCH 5/5] isert-scst: Port to Linux kernel v4.9 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7020 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/iser.h | 2 ++ iscsi-scst/kernel/isert-scst/iser_rdma.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/isert-scst/iser.h b/iscsi-scst/kernel/isert-scst/iser.h index 143d863c4..8531896ba 100644 --- a/iscsi-scst/kernel/isert-scst/iser.h +++ b/iscsi-scst/kernel/isert-scst/iser.h @@ -233,7 +233,9 @@ struct isert_connection { struct isert_device { struct ib_device *ib_dev; struct ib_pd *pd; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) struct ib_mr *mr; +#endif u32 lkey; struct list_head devs_node; diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index 8c6424acf..c35ccbbb5 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -951,7 +951,9 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev) struct isert_device *isert_dev; int cqe_num, err; struct ib_pd *pd; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) struct ib_mr *mr; +#endif struct ib_cq *cq; char wq_name[64]; int i, j; @@ -996,19 +998,21 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev) goto fail_alloc_cq_desc; } - pd = ib_alloc_pd(ib_dev); + pd = ib_alloc_pd(ib_dev, 0); if (unlikely(IS_ERR(pd))) { err = PTR_ERR(pd); PRINT_ERROR("Failed to alloc iser dev pd, err:%d", err); goto fail_pd; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) mr = ib_get_dma_mr(pd, IB_ACCESS_LOCAL_WRITE); if (unlikely(IS_ERR(mr))) { err = PTR_ERR(mr); PRINT_ERROR("Failed to get dma mr, err: %d", err); goto fail_mr; } +#endif cqe_num = min(isert_dev->device_attr.max_cqe, ISER_CQ_ENTRIES); cqe_num = cqe_num / isert_dev->num_cqs; @@ -1091,8 +1095,12 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev) isert_dev->ib_dev = ib_dev; isert_dev->pd = pd; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) isert_dev->mr = mr; isert_dev->lkey = mr->lkey; +#else + isert_dev->lkey = pd->local_dma_lkey; +#endif INIT_LIST_HEAD(&isert_dev->conn_list); @@ -1110,8 +1118,10 @@ fail_cq: if (isert_dev->cq_desc[j].cq_workqueue) destroy_workqueue(isert_dev->cq_desc[j].cq_workqueue); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) ib_dereg_mr(mr); fail_mr: +#endif ib_dealloc_pd(pd); fail_pd: vfree(isert_dev->cq_desc); @@ -1154,9 +1164,11 @@ static void isert_device_release(struct isert_device *isert_dev) destroy_workqueue(cq_desc->cq_workqueue); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) err = ib_dereg_mr(isert_dev->mr); if (unlikely(err)) PRINT_ERROR("Failed to destroy mr, err:%d", err); +#endif ib_dealloc_pd(isert_dev->pd); vfree(isert_dev->cq_desc);