Commit 40ef8756 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

dm writecache: allow allocations larger than 2GiB

The function kvmalloc_node limits the allocation size to INT_MAX. This
limit will be overflowed if dm-writecache attempts to map a device with
1TiB or larger length. This commit changes kvmalloc_array to vmalloc_array
to avoid the limit.

The commit also changes vmalloc(array_size()) to vmalloc_array().
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
parent 9cf11ce0
...@@ -299,7 +299,7 @@ static int persistent_memory_claim(struct dm_writecache *wc) ...@@ -299,7 +299,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
long i; long i;
wc->memory_map = NULL; wc->memory_map = NULL;
pages = kvmalloc_array(p, sizeof(struct page *), GFP_KERNEL); pages = vmalloc_array(p, sizeof(struct page *));
if (!pages) { if (!pages) {
r = -ENOMEM; r = -ENOMEM;
goto err2; goto err2;
...@@ -330,7 +330,7 @@ static int persistent_memory_claim(struct dm_writecache *wc) ...@@ -330,7 +330,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
r = -ENOMEM; r = -ENOMEM;
goto err3; goto err3;
} }
kvfree(pages); vfree(pages);
wc->memory_vmapped = true; wc->memory_vmapped = true;
} }
...@@ -341,7 +341,7 @@ static int persistent_memory_claim(struct dm_writecache *wc) ...@@ -341,7 +341,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
return 0; return 0;
err3: err3:
kvfree(pages); vfree(pages);
err2: err2:
dax_read_unlock(id); dax_read_unlock(id);
err1: err1:
...@@ -962,7 +962,7 @@ static int writecache_alloc_entries(struct dm_writecache *wc) ...@@ -962,7 +962,7 @@ static int writecache_alloc_entries(struct dm_writecache *wc)
if (wc->entries) if (wc->entries)
return 0; return 0;
wc->entries = vmalloc(array_size(sizeof(struct wc_entry), wc->n_blocks)); wc->entries = vmalloc_array(wc->n_blocks, sizeof(struct wc_entry));
if (!wc->entries) if (!wc->entries)
return -ENOMEM; return -ENOMEM;
for (b = 0; b < wc->n_blocks; b++) { for (b = 0; b < wc->n_blocks; b++) {
......
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