Commit 3cffd930 authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Doug Ledford

IB/iser: Add module parameter for always register memory

This module parameter forces memory registration even for
a continuous memory region. It is true by default as sending
an all-physical rkey with remote permissions might be insecure.
Signed-off-by: default avatarSagi Grimberg <sagig@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent bb6c96d7
...@@ -97,6 +97,11 @@ unsigned int iser_max_sectors = ISER_DEF_MAX_SECTORS; ...@@ -97,6 +97,11 @@ unsigned int iser_max_sectors = ISER_DEF_MAX_SECTORS;
module_param_named(max_sectors, iser_max_sectors, uint, S_IRUGO | S_IWUSR); module_param_named(max_sectors, iser_max_sectors, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(max_sectors, "Max number of sectors in a single scsi command (default:1024"); MODULE_PARM_DESC(max_sectors, "Max number of sectors in a single scsi command (default:1024");
bool iser_always_reg = true;
module_param_named(always_register, iser_always_reg, bool, S_IRUGO);
MODULE_PARM_DESC(always_register,
"Always register memory, even for continuous memory regions (default:true)");
bool iser_pi_enable = false; bool iser_pi_enable = false;
module_param_named(pi_enable, iser_pi_enable, bool, S_IRUGO); module_param_named(pi_enable, iser_pi_enable, bool, S_IRUGO);
MODULE_PARM_DESC(pi_enable, "Enable T10-PI offload support (default:disabled)"); MODULE_PARM_DESC(pi_enable, "Enable T10-PI offload support (default:disabled)");
......
...@@ -611,6 +611,7 @@ extern int iser_debug_level; ...@@ -611,6 +611,7 @@ extern int iser_debug_level;
extern bool iser_pi_enable; extern bool iser_pi_enable;
extern int iser_pi_guard; extern int iser_pi_guard;
extern unsigned int iser_max_sectors; extern unsigned int iser_max_sectors;
extern bool iser_always_reg;
int iser_assign_reg_ops(struct iser_device *device); int iser_assign_reg_ops(struct iser_device *device);
......
...@@ -803,11 +803,12 @@ static int ...@@ -803,11 +803,12 @@ static int
iser_reg_prot_sg(struct iscsi_iser_task *task, iser_reg_prot_sg(struct iscsi_iser_task *task,
struct iser_data_buf *mem, struct iser_data_buf *mem,
struct iser_fr_desc *desc, struct iser_fr_desc *desc,
bool use_dma_key,
struct iser_mem_reg *reg) struct iser_mem_reg *reg)
{ {
struct iser_device *device = task->iser_conn->ib_conn.device; struct iser_device *device = task->iser_conn->ib_conn.device;
if (mem->dma_nents == 1) if (use_dma_key)
return iser_reg_dma(device, mem, reg); return iser_reg_dma(device, mem, reg);
return device->reg_ops->reg_mem(task, mem, &desc->pi_ctx->rsc, reg); return device->reg_ops->reg_mem(task, mem, &desc->pi_ctx->rsc, reg);
...@@ -817,11 +818,12 @@ static int ...@@ -817,11 +818,12 @@ static int
iser_reg_data_sg(struct iscsi_iser_task *task, iser_reg_data_sg(struct iscsi_iser_task *task,
struct iser_data_buf *mem, struct iser_data_buf *mem,
struct iser_fr_desc *desc, struct iser_fr_desc *desc,
bool use_dma_key,
struct iser_mem_reg *reg) struct iser_mem_reg *reg)
{ {
struct iser_device *device = task->iser_conn->ib_conn.device; struct iser_device *device = task->iser_conn->ib_conn.device;
if (mem->dma_nents == 1) if (use_dma_key)
return iser_reg_dma(device, mem, reg); return iser_reg_dma(device, mem, reg);
return device->reg_ops->reg_mem(task, mem, &desc->rsc, reg); return device->reg_ops->reg_mem(task, mem, &desc->rsc, reg);
...@@ -836,14 +838,17 @@ int iser_reg_rdma_mem(struct iscsi_iser_task *task, ...@@ -836,14 +838,17 @@ int iser_reg_rdma_mem(struct iscsi_iser_task *task,
struct iser_mem_reg *reg = &task->rdma_reg[dir]; struct iser_mem_reg *reg = &task->rdma_reg[dir];
struct iser_mem_reg *data_reg; struct iser_mem_reg *data_reg;
struct iser_fr_desc *desc = NULL; struct iser_fr_desc *desc = NULL;
bool use_dma_key;
int err; int err;
err = iser_handle_unaligned_buf(task, mem, dir); err = iser_handle_unaligned_buf(task, mem, dir);
if (unlikely(err)) if (unlikely(err))
return err; return err;
if (mem->dma_nents != 1 || use_dma_key = (mem->dma_nents == 1 && !iser_always_reg &&
scsi_get_prot_op(task->sc) != SCSI_PROT_NORMAL) { scsi_get_prot_op(task->sc) == SCSI_PROT_NORMAL);
if (!use_dma_key) {
desc = device->reg_ops->reg_desc_get(ib_conn); desc = device->reg_ops->reg_desc_get(ib_conn);
reg->mem_h = desc; reg->mem_h = desc;
} }
...@@ -853,7 +858,7 @@ int iser_reg_rdma_mem(struct iscsi_iser_task *task, ...@@ -853,7 +858,7 @@ int iser_reg_rdma_mem(struct iscsi_iser_task *task,
else else
data_reg = &task->desc.data_reg; data_reg = &task->desc.data_reg;
err = iser_reg_data_sg(task, mem, desc, data_reg); err = iser_reg_data_sg(task, mem, desc, use_dma_key, data_reg);
if (unlikely(err)) if (unlikely(err))
goto err_reg; goto err_reg;
...@@ -866,7 +871,8 @@ int iser_reg_rdma_mem(struct iscsi_iser_task *task, ...@@ -866,7 +871,8 @@ int iser_reg_rdma_mem(struct iscsi_iser_task *task,
if (unlikely(err)) if (unlikely(err))
goto err_reg; goto err_reg;
err = iser_reg_prot_sg(task, mem, desc, prot_reg); err = iser_reg_prot_sg(task, mem, desc,
use_dma_key, prot_reg);
if (unlikely(err)) if (unlikely(err))
goto err_reg; goto err_reg;
} }
......
...@@ -133,11 +133,15 @@ static int iser_create_device_ib_res(struct iser_device *device) ...@@ -133,11 +133,15 @@ static int iser_create_device_ib_res(struct iser_device *device)
(unsigned long)comp); (unsigned long)comp);
} }
device->mr = ib_get_dma_mr(device->pd, IB_ACCESS_LOCAL_WRITE | if (!iser_always_reg) {
IB_ACCESS_REMOTE_WRITE | int access = IB_ACCESS_LOCAL_WRITE |
IB_ACCESS_REMOTE_READ); IB_ACCESS_REMOTE_WRITE |
if (IS_ERR(device->mr)) IB_ACCESS_REMOTE_READ;
goto dma_mr_err;
device->mr = ib_get_dma_mr(device->pd, access);
if (IS_ERR(device->mr))
goto dma_mr_err;
}
INIT_IB_EVENT_HANDLER(&device->event_handler, device->ib_device, INIT_IB_EVENT_HANDLER(&device->event_handler, device->ib_device,
iser_event_handler); iser_event_handler);
...@@ -147,7 +151,8 @@ static int iser_create_device_ib_res(struct iser_device *device) ...@@ -147,7 +151,8 @@ static int iser_create_device_ib_res(struct iser_device *device)
return 0; return 0;
handler_err: handler_err:
ib_dereg_mr(device->mr); if (device->mr)
ib_dereg_mr(device->mr);
dma_mr_err: dma_mr_err:
for (i = 0; i < device->comps_used; i++) for (i = 0; i < device->comps_used; i++)
tasklet_kill(&device->comps[i].tasklet); tasklet_kill(&device->comps[i].tasklet);
...@@ -173,7 +178,6 @@ static int iser_create_device_ib_res(struct iser_device *device) ...@@ -173,7 +178,6 @@ static int iser_create_device_ib_res(struct iser_device *device)
static void iser_free_device_ib_res(struct iser_device *device) static void iser_free_device_ib_res(struct iser_device *device)
{ {
int i; int i;
BUG_ON(device->mr == NULL);
for (i = 0; i < device->comps_used; i++) { for (i = 0; i < device->comps_used; i++) {
struct iser_comp *comp = &device->comps[i]; struct iser_comp *comp = &device->comps[i];
...@@ -184,7 +188,8 @@ static void iser_free_device_ib_res(struct iser_device *device) ...@@ -184,7 +188,8 @@ static void iser_free_device_ib_res(struct iser_device *device)
} }
(void)ib_unregister_event_handler(&device->event_handler); (void)ib_unregister_event_handler(&device->event_handler);
(void)ib_dereg_mr(device->mr); if (device->mr)
(void)ib_dereg_mr(device->mr);
ib_dealloc_pd(device->pd); ib_dealloc_pd(device->pd);
kfree(device->comps); kfree(device->comps);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment