Revert "btrfs: compression: drop kmap/kunmap from zlib"
This reverts commit 696ab562e6
.
The kmaps in compression code are still needed and cause crashes on
32bit machines (ARM, x86). Reproducible eg. by running fstest btrfs/004
with enabled LZO or ZSTD compression.
Link: https://lore.kernel.org/all/CAJCQCtT+OuemovPO7GZk8Y8=qtOObr0XTDp8jh4OHD6y84AFxw@mail.gmail.com/
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=214839
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
56ee254d23
commit
55276e14df
@ -126,7 +126,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
cpage_out = page_address(out_page);
|
cpage_out = kmap(out_page);
|
||||||
pages[0] = out_page;
|
pages[0] = out_page;
|
||||||
nr_pages = 1;
|
nr_pages = 1;
|
||||||
|
|
||||||
@ -148,22 +148,26 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < in_buf_pages; i++) {
|
for (i = 0; i < in_buf_pages; i++) {
|
||||||
if (in_page)
|
if (in_page) {
|
||||||
|
kunmap(in_page);
|
||||||
put_page(in_page);
|
put_page(in_page);
|
||||||
|
}
|
||||||
in_page = find_get_page(mapping,
|
in_page = find_get_page(mapping,
|
||||||
start >> PAGE_SHIFT);
|
start >> PAGE_SHIFT);
|
||||||
data_in = page_address(in_page);
|
data_in = kmap(in_page);
|
||||||
memcpy(workspace->buf + i * PAGE_SIZE,
|
memcpy(workspace->buf + i * PAGE_SIZE,
|
||||||
data_in, PAGE_SIZE);
|
data_in, PAGE_SIZE);
|
||||||
start += PAGE_SIZE;
|
start += PAGE_SIZE;
|
||||||
}
|
}
|
||||||
workspace->strm.next_in = workspace->buf;
|
workspace->strm.next_in = workspace->buf;
|
||||||
} else {
|
} else {
|
||||||
if (in_page)
|
if (in_page) {
|
||||||
|
kunmap(in_page);
|
||||||
put_page(in_page);
|
put_page(in_page);
|
||||||
|
}
|
||||||
in_page = find_get_page(mapping,
|
in_page = find_get_page(mapping,
|
||||||
start >> PAGE_SHIFT);
|
start >> PAGE_SHIFT);
|
||||||
data_in = page_address(in_page);
|
data_in = kmap(in_page);
|
||||||
start += PAGE_SIZE;
|
start += PAGE_SIZE;
|
||||||
workspace->strm.next_in = data_in;
|
workspace->strm.next_in = data_in;
|
||||||
}
|
}
|
||||||
@ -192,6 +196,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
* the stream end if required
|
* the stream end if required
|
||||||
*/
|
*/
|
||||||
if (workspace->strm.avail_out == 0) {
|
if (workspace->strm.avail_out == 0) {
|
||||||
|
kunmap(out_page);
|
||||||
if (nr_pages == nr_dest_pages) {
|
if (nr_pages == nr_dest_pages) {
|
||||||
out_page = NULL;
|
out_page = NULL;
|
||||||
ret = -E2BIG;
|
ret = -E2BIG;
|
||||||
@ -202,7 +207,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
cpage_out = page_address(out_page);
|
cpage_out = kmap(out_page);
|
||||||
pages[nr_pages] = out_page;
|
pages[nr_pages] = out_page;
|
||||||
nr_pages++;
|
nr_pages++;
|
||||||
workspace->strm.avail_out = PAGE_SIZE;
|
workspace->strm.avail_out = PAGE_SIZE;
|
||||||
@ -229,6 +234,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
goto out;
|
goto out;
|
||||||
} else if (workspace->strm.avail_out == 0) {
|
} else if (workspace->strm.avail_out == 0) {
|
||||||
/* get another page for the stream end */
|
/* get another page for the stream end */
|
||||||
|
kunmap(out_page);
|
||||||
if (nr_pages == nr_dest_pages) {
|
if (nr_pages == nr_dest_pages) {
|
||||||
out_page = NULL;
|
out_page = NULL;
|
||||||
ret = -E2BIG;
|
ret = -E2BIG;
|
||||||
@ -239,7 +245,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
cpage_out = page_address(out_page);
|
cpage_out = kmap(out_page);
|
||||||
pages[nr_pages] = out_page;
|
pages[nr_pages] = out_page;
|
||||||
nr_pages++;
|
nr_pages++;
|
||||||
workspace->strm.avail_out = PAGE_SIZE;
|
workspace->strm.avail_out = PAGE_SIZE;
|
||||||
@ -258,8 +264,13 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
*total_in = workspace->strm.total_in;
|
*total_in = workspace->strm.total_in;
|
||||||
out:
|
out:
|
||||||
*out_pages = nr_pages;
|
*out_pages = nr_pages;
|
||||||
if (in_page)
|
if (out_page)
|
||||||
|
kunmap(out_page);
|
||||||
|
|
||||||
|
if (in_page) {
|
||||||
|
kunmap(in_page);
|
||||||
put_page(in_page);
|
put_page(in_page);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +287,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
|||||||
unsigned long buf_start;
|
unsigned long buf_start;
|
||||||
struct page **pages_in = cb->compressed_pages;
|
struct page **pages_in = cb->compressed_pages;
|
||||||
|
|
||||||
data_in = page_address(pages_in[page_in_index]);
|
data_in = kmap(pages_in[page_in_index]);
|
||||||
workspace->strm.next_in = data_in;
|
workspace->strm.next_in = data_in;
|
||||||
workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE);
|
workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE);
|
||||||
workspace->strm.total_in = 0;
|
workspace->strm.total_in = 0;
|
||||||
@ -298,6 +309,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
|||||||
|
|
||||||
if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) {
|
if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) {
|
||||||
pr_warn("BTRFS: inflateInit failed\n");
|
pr_warn("BTRFS: inflateInit failed\n");
|
||||||
|
kunmap(pages_in[page_in_index]);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
while (workspace->strm.total_in < srclen) {
|
while (workspace->strm.total_in < srclen) {
|
||||||
@ -324,13 +336,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
|||||||
|
|
||||||
if (workspace->strm.avail_in == 0) {
|
if (workspace->strm.avail_in == 0) {
|
||||||
unsigned long tmp;
|
unsigned long tmp;
|
||||||
|
kunmap(pages_in[page_in_index]);
|
||||||
page_in_index++;
|
page_in_index++;
|
||||||
if (page_in_index >= total_pages_in) {
|
if (page_in_index >= total_pages_in) {
|
||||||
data_in = NULL;
|
data_in = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
data_in = page_address(pages_in[page_in_index]);
|
data_in = kmap(pages_in[page_in_index]);
|
||||||
workspace->strm.next_in = data_in;
|
workspace->strm.next_in = data_in;
|
||||||
tmp = srclen - workspace->strm.total_in;
|
tmp = srclen - workspace->strm.total_in;
|
||||||
workspace->strm.avail_in = min(tmp, PAGE_SIZE);
|
workspace->strm.avail_in = min(tmp, PAGE_SIZE);
|
||||||
@ -342,6 +354,8 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
done:
|
done:
|
||||||
zlib_inflateEnd(&workspace->strm);
|
zlib_inflateEnd(&workspace->strm);
|
||||||
|
if (data_in)
|
||||||
|
kunmap(pages_in[page_in_index]);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
zero_fill_bio(cb->orig_bio);
|
zero_fill_bio(cb->orig_bio);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user