[PATCH-v2 0/2] target: Pre-allocation fixes for v3.12-rc

22 views
Skip to first unread message

Nicholas A. Bellinger

unread,
Sep 24, 2013, 4:29:32 PM9/24/13
to target-devel, Michael S. Tsirkin, Asias He, Kent Overstreet, Nicholas Bellinger
From: Nicholas Bellinger <n...@linux-iscsi.org>

Hi folks,

Here are two updated pre-allocation conversion related fixes that are
being queued up for v3.12-rc.

The first is a small vhost/scsi patch to fix a typo where GFP_KERNEL
instead of GFP_ATOMIC was used with percpu_ida_alloc() from interrupt
context in vhost_scsi_get_tag().

And the second is a patch for transport_alloc_session_tags() that
allows a high order kzalloc() failure of se_session->sess_cmd_map
memory to fallback to vzalloc, if necessary.

v2 changes:

- Use __GFP_NOWARN | __GFP_REPEAT for sess_cmd_map kzalloc (mst)
- vhost/scsi: Handle possible tag < 0 failure with GFP_ATOMIC (nab)

Thanks,

--nab

Nicholas Bellinger (2):
vhost/scsi: Use GFP_ATOMIC with percpu_ida_alloc for obtaining tag
target: Fall back to vzalloc upon ->sess_cmd_map kzalloc failure

drivers/target/target_core_transport.c | 20 +++++++++++++++-----
drivers/vhost/scsi.c | 7 ++++++-
2 files changed, 21 insertions(+), 6 deletions(-)

--
1.7.10.4

Nicholas A. Bellinger

unread,
Sep 24, 2013, 4:29:33 PM9/24/13
to target-devel, Michael S. Tsirkin, Asias He, Kent Overstreet, Nicholas Bellinger
From: Nicholas Bellinger <n...@linux-iscsi.org>

Fix GFP_KERNEL -> GFP_ATOMIC usage of percpu_ida_alloc() within
vhost_scsi_get_tag(), as this code is expected to be called directly
from interrupt context.

v2 changes:

- Handle possible tag < 0 failure with GFP_ATOMIC

Acked-by: Michael S. Tsirkin <m...@redhat.com>
Acked-by: Asias He <as...@redhat.com>
Cc: Kent Overstreet <k...@daterainc.com>
Signed-off-by: Nicholas Bellinger <n...@linux-iscsi.org>
---
drivers/vhost/scsi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 4b79a1f..e231b00 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -728,7 +728,12 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq,
}
se_sess = tv_nexus->tvn_se_sess;

- tag = percpu_ida_alloc(&se_sess->sess_tag_pool, GFP_KERNEL);
+ tag = percpu_ida_alloc(&se_sess->sess_tag_pool, GFP_ATOMIC);
+ if (tag < 0) {
+ pr_err("Unable to obtain tag for tcm_vhost_cmd\n");
+ return ERR_PTR(-ENOMEM);
+ }
+
cmd = &((struct tcm_vhost_cmd *)se_sess->sess_cmd_map)[tag];
sg = cmd->tvc_sgl;
pages = cmd->tvc_upages;
--
1.7.10.4

Nicholas A. Bellinger

unread,
Sep 24, 2013, 4:29:34 PM9/24/13
to target-devel, Michael S. Tsirkin, Asias He, Kent Overstreet, Nicholas Bellinger
From: Nicholas Bellinger <n...@linux-iscsi.org>

This patch changes transport_alloc_session_tags() to fall back to
use vzalloc when kzalloc fails for big tag_num that end up generating
larger order allocations.

Also use is_vmalloc_addr() in transport_alloc_session_tags() failure
path, and normal transport_free_session() path to determine when
vfree() needs to be called instead of kfree().

v2 changes:
- Use __GFP_NOWARN | __GFP_REPEAT for sess_cmd_map kzalloc (mst)

Cc: Michael S. Tsirkin <m...@redhat.com>
Cc: Asias He <as...@redhat.com>
Cc: Kent Overstreet <k...@daterainc.com>
Signed-off-by: Nicholas Bellinger <n...@linux-iscsi.org>
---
drivers/target/target_core_transport.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4aace78..a033c4b 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -236,17 +236,24 @@ int transport_alloc_session_tags(struct se_session *se_sess,
{
int rc;

- se_sess->sess_cmd_map = kzalloc(tag_num * tag_size, GFP_KERNEL);
+ se_sess->sess_cmd_map = kzalloc(tag_num * tag_size,
+ GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
if (!se_sess->sess_cmd_map) {
- pr_err("Unable to allocate se_sess->sess_cmd_map\n");
- return -ENOMEM;
+ se_sess->sess_cmd_map = vzalloc(tag_num * tag_size);
+ if (!se_sess->sess_cmd_map) {
+ pr_err("Unable to allocate se_sess->sess_cmd_map\n");
+ return -ENOMEM;
+ }
}

rc = percpu_ida_init(&se_sess->sess_tag_pool, tag_num);
if (rc < 0) {
pr_err("Unable to init se_sess->sess_tag_pool,"
" tag_num: %u\n", tag_num);
- kfree(se_sess->sess_cmd_map);
+ if (is_vmalloc_addr(se_sess->sess_cmd_map))
+ vfree(se_sess->sess_cmd_map);
+ else
+ kfree(se_sess->sess_cmd_map);
se_sess->sess_cmd_map = NULL;
return -ENOMEM;
}
@@ -412,7 +419,10 @@ void transport_free_session(struct se_session *se_sess)
{
if (se_sess->sess_cmd_map) {
percpu_ida_destroy(&se_sess->sess_tag_pool);
- kfree(se_sess->sess_cmd_map);
+ if (is_vmalloc_addr(se_sess->sess_cmd_map))
+ vfree(se_sess->sess_cmd_map);
+ else
+ kfree(se_sess->sess_cmd_map);
}
kmem_cache_free(se_sess_cache, se_sess);
}
--
1.7.10.4

Reply all
Reply to author
Forward
0 new messages