All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
@ 2022-05-31 14:53 Fabio M. De Francesco
  2022-05-31 14:53 ` [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c Fabio M. De Francesco
                   ` (4 more replies)
  0 siblings, 5 replies; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-05-31 14:53 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel
  Cc: Fabio M. De Francesco

This is the first series of patches aimed towards the conversion of Btrfs
filesystem from the use of kmap() to kmap_local_page().

The use of kmap() is being deprecated in favor of kmap_local_page() where
it is feasible. With kmap_local_page() the mapping is per thread, CPU
local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in Btrfs wherever the
mappings are per thread and not globally visible.

Tested on QEMU + KVM 32 bits VM with 4GB of RAM and HIGHMEM64G enabled.

tweed32:~ # uname -a
Linux tweed32 5.18.0-torvalds-debug-x86_32+ #2 SMP PREEMPT_DYNAMIC Tue \
May 31 15:20:07 CEST 2022 i686 athlon i386 GNU/Linux

tweed32:~ # btrfs check -p ~zoek/dev/btrfs.file
Opening filesystem to check...
Checking filesystem on /home/zoek/dev/btrfs.file
UUID: 897d65c5-1167-45b4-b811-2bfe74a320ca
[1/7] checking root items                      (0:00:00 elapsed, 1774 items checked)
[2/7] checking extents                         (0:00:00 elapsed, 135 items checked)
[3/7] checking free space tree                 (0:00:00 elapsed, 4 items checked)
[4/7] checking fs roots                        (0:00:00 elapsed, 104 items checked)
[5/7] checking csums (without verifying data)  (0:00:00 elapsed, 205 items checked)
[6/7] checking root refs                       (0:00:00 elapsed, 3 items checked)
[7/7] checking quota groups skipped (not enabled on this FS)
found 47394816 bytes used, no error found
total csum bytes: 44268
total tree bytes: 2064384
total fs tree bytes: 1720320
total extent tree bytes: 180224
btree space waste bytes: 465350
file data blocks allocated: 45330432
 referenced 45330432

Fabio M. De Francesco (3):
  btrfs: Replace kmap() with kmap_local_page() in inode.c
  btrfs: Replace kmap() with kmap_local_page() in lzo.c
  btrfs: Replace kmap() with kmap_local_page() in zlib.c

 fs/btrfs/inode.c |  6 +++---
 fs/btrfs/lzo.c   | 28 ++++++++++++----------------
 fs/btrfs/zlib.c  | 40 ++++++++++++++++++++--------------------
 3 files changed, 35 insertions(+), 39 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c
  2022-05-31 14:53 [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
@ 2022-05-31 14:53 ` Fabio M. De Francesco
  2022-05-31 15:46   ` Christoph Hellwig
  2022-05-31 14:53 ` [PATCH 2/3] btrfs: Replace kmap() with kmap_local_page() in lzo.c Fabio M. De Francesco
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-05-31 14:53 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel
  Cc: Fabio M. De Francesco

The use of kmap() is being deprecated in favor of kmap_local_page() where
it is feasible. With kmap_local_page(), the mapping is per thread, CPU
local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in inode.c wherever the
mappings are per thread and not globally visible.

Tested on QEMU + KVM 32 bits VM with 4GB of RAM and HIGHMEM64G enabled.

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 fs/btrfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 81737eff92f3..7d84d57a0653 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -10779,15 +10779,15 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
 			ret = -ENOMEM;
 			goto out_pages;
 		}
-		kaddr = kmap(pages[i]);
+		kaddr = kmap_local_page(pages[i]);
 		if (copy_from_iter(kaddr, bytes, from) != bytes) {
-			kunmap(pages[i]);
+			kunmap_local(kaddr);
 			ret = -EFAULT;
 			goto out_pages;
 		}
 		if (bytes < PAGE_SIZE)
 			memset(kaddr + bytes, 0, PAGE_SIZE - bytes);
-		kunmap(pages[i]);
+		kunmap_local(kaddr);
 	}
 
 	for (;;) {
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 2/3] btrfs: Replace kmap() with kmap_local_page() in lzo.c
  2022-05-31 14:53 [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
  2022-05-31 14:53 ` [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c Fabio M. De Francesco
@ 2022-05-31 14:53 ` Fabio M. De Francesco
  2022-05-31 15:53   ` Christoph Hellwig
  2022-05-31 14:53 ` [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c Fabio M. De Francesco
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-05-31 14:53 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel
  Cc: Fabio M. De Francesco

The use of kmap() is being deprecated in favor of kmap_local_page() where
it is feasible. With kmap_local_page(), the mapping is per thread, CPU
local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in lzo.c wherever the
mappings are per thread and not globally visible.

Tested on QEMU + KVM 32 bits VM with 4GB of RAM and HIGHMEM64G enabled.

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 fs/btrfs/lzo.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 430ad36b8b08..89bc5f825e0a 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -155,7 +155,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
 		out_pages[*cur_out / PAGE_SIZE] = cur_page;
 	}
 
-	kaddr = kmap(cur_page);
+	kaddr = kmap_local_page(cur_page);
 	write_compress_length(kaddr + offset_in_page(*cur_out),
 			      compressed_size);
 	*cur_out += LZO_LEN;
@@ -167,7 +167,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
 		u32 copy_len = min_t(u32, sectorsize - *cur_out % sectorsize,
 				     orig_out + compressed_size - *cur_out);
 
-		kunmap(cur_page);
+		kunmap_local(kaddr);
 
 		if ((*cur_out / PAGE_SIZE) >= max_nr_page)
 			return -E2BIG;
@@ -180,7 +180,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
 				return -ENOMEM;
 			out_pages[*cur_out / PAGE_SIZE] = cur_page;
 		}
-		kaddr = kmap(cur_page);
+		kaddr = kmap_local_page(cur_page);
 
 		memcpy(kaddr + offset_in_page(*cur_out),
 		       compressed_data + *cur_out - orig_out, copy_len);
@@ -202,7 +202,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
 	*cur_out += sector_bytes_left;
 
 out:
-	kunmap(cur_page);
+	kunmap_local(kaddr);
 	return 0;
 }
 
@@ -248,12 +248,12 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
 		/* Compress at most one sector of data each time */
 		in_len = min_t(u32, start + len - cur_in, sectorsize - sector_off);
 		ASSERT(in_len);
-		data_in = kmap(page_in);
+		data_in = kmap_local_page(page_in);
 		ret = lzo1x_1_compress(data_in +
 				       offset_in_page(cur_in), in_len,
 				       workspace->cbuf, &out_len,
 				       workspace->mem);
-		kunmap(page_in);
+		kunmap_local(data_in);
 		if (ret < 0) {
 			pr_debug("BTRFS: lzo in loop returned %d\n", ret);
 			ret = -EIO;
@@ -310,7 +310,6 @@ static void copy_compressed_segment(struct compressed_bio *cb,
 	u32 orig_in = *cur_in;
 
 	while (*cur_in < orig_in + len) {
-		char *kaddr;
 		struct page *cur_page;
 		u32 copy_len = min_t(u32, PAGE_SIZE - offset_in_page(*cur_in),
 					  orig_in + len - *cur_in);
@@ -318,11 +317,8 @@ static void copy_compressed_segment(struct compressed_bio *cb,
 		ASSERT(copy_len);
 		cur_page = cb->compressed_pages[*cur_in / PAGE_SIZE];
 
-		kaddr = kmap(cur_page);
-		memcpy(dest + *cur_in - orig_in,
-			kaddr + offset_in_page(*cur_in),
-			copy_len);
-		kunmap(cur_page);
+		memcpy_from_page(dest + *cur_in - orig_in, cur_page,
+				 offset_in_page(*cur_in), copy_len);
 
 		*cur_in += copy_len;
 	}
@@ -342,9 +338,9 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 	/* Bytes decompressed so far */
 	u32 cur_out = 0;
 
-	kaddr = kmap(cb->compressed_pages[0]);
+	kaddr = kmap_local_page(cb->compressed_pages[0]);
 	len_in = read_compress_length(kaddr);
-	kunmap(cb->compressed_pages[0]);
+	kunmap_local(kaddr);
 	cur_in += LZO_LEN;
 
 	/*
@@ -378,9 +374,9 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 		       (cur_in + LZO_LEN - 1) / sectorsize);
 		cur_page = cb->compressed_pages[cur_in / PAGE_SIZE];
 		ASSERT(cur_page);
-		kaddr = kmap(cur_page);
+		kaddr = kmap_local_page(cur_page);
 		seg_len = read_compress_length(kaddr + offset_in_page(cur_in));
-		kunmap(cur_page);
+		kunmap_local(kaddr);
 		cur_in += LZO_LEN;
 
 		if (seg_len > WORKSPACE_CBUF_LENGTH) {
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
  2022-05-31 14:53 [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
  2022-05-31 14:53 ` [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c Fabio M. De Francesco
  2022-05-31 14:53 ` [PATCH 2/3] btrfs: Replace kmap() with kmap_local_page() in lzo.c Fabio M. De Francesco
@ 2022-05-31 14:53 ` Fabio M. De Francesco
  2022-05-31 15:53   ` Christoph Hellwig
  2022-05-31 20:35   ` kernel test robot
  2022-06-01 13:25 ` [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() David Sterba
  2022-06-02 15:20 ` Christoph Hellwig
  4 siblings, 2 replies; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-05-31 14:53 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel
  Cc: Fabio M. De Francesco

The use of kmap() is being deprecated in favor of kmap_local_page() where
it is feasible. With kmap_local_page(), the mapping is per thread, CPU
local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in zlib.c wherever the
mappings are per thread and not globally visible.

Tested on QEMU + KVM 32 bits VM with 4GB of RAM and HIGHMEM64G enabled.

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 fs/btrfs/zlib.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 767a0c6c9694..7c10e78bd3d4 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -126,7 +126,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 		ret = -ENOMEM;
 		goto out;
 	}
-	cpage_out = kmap(out_page);
+	cpage_out = kmap_local_page(out_page);
 	pages[0] = out_page;
 	nr_pages = 1;
 
@@ -148,26 +148,26 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 				int i;
 
 				for (i = 0; i < in_buf_pages; i++) {
-					if (in_page) {
-						kunmap(in_page);
+					if (data_in) {
+						kunmap_local(data_in);
 						put_page(in_page);
 					}
 					in_page = find_get_page(mapping,
 								start >> PAGE_SHIFT);
-					data_in = kmap(in_page);
+					data_in = kmap_local_page(in_page);
 					memcpy(workspace->buf + i * PAGE_SIZE,
 					       data_in, PAGE_SIZE);
 					start += PAGE_SIZE;
 				}
 				workspace->strm.next_in = workspace->buf;
 			} else {
-				if (in_page) {
-					kunmap(in_page);
+				if (data_in) {
+					kunmap_local(data_in);
 					put_page(in_page);
 				}
 				in_page = find_get_page(mapping,
 							start >> PAGE_SHIFT);
-				data_in = kmap(in_page);
+				data_in = kmap_local_page(in_page);
 				start += PAGE_SIZE;
 				workspace->strm.next_in = data_in;
 			}
@@ -196,7 +196,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 		 * the stream end if required
 		 */
 		if (workspace->strm.avail_out == 0) {
-			kunmap(out_page);
+			kunmap_local(cpage_out);
 			if (nr_pages == nr_dest_pages) {
 				out_page = NULL;
 				ret = -E2BIG;
@@ -207,7 +207,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 				ret = -ENOMEM;
 				goto out;
 			}
-			cpage_out = kmap(out_page);
+			cpage_out = kmap_local_page(out_page);
 			pages[nr_pages] = out_page;
 			nr_pages++;
 			workspace->strm.avail_out = PAGE_SIZE;
@@ -234,7 +234,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 			goto out;
 		} else if (workspace->strm.avail_out == 0) {
 			/* get another page for the stream end */
-			kunmap(out_page);
+			kunmap_local(cpage_out);
 			if (nr_pages == nr_dest_pages) {
 				out_page = NULL;
 				ret = -E2BIG;
@@ -245,7 +245,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 				ret = -ENOMEM;
 				goto out;
 			}
-			cpage_out = kmap(out_page);
+			cpage_out = kmap_local_page(out_page);
 			pages[nr_pages] = out_page;
 			nr_pages++;
 			workspace->strm.avail_out = PAGE_SIZE;
@@ -264,11 +264,11 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 	*total_in = workspace->strm.total_in;
 out:
 	*out_pages = nr_pages;
-	if (out_page)
-		kunmap(out_page);
+	if (cpage_out)
+		kunmap_local(cpage_out);
 
-	if (in_page) {
-		kunmap(in_page);
+	if (data_in) {
+		kunmap_local(data_in);
 		put_page(in_page);
 	}
 	return ret;
@@ -287,7 +287,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 	unsigned long buf_start;
 	struct page **pages_in = cb->compressed_pages;
 
-	data_in = kmap(pages_in[page_in_index]);
+	data_in = kmap_local_page(pages_in[page_in_index]);
 	workspace->strm.next_in = data_in;
 	workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE);
 	workspace->strm.total_in = 0;
@@ -309,7 +309,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 
 	if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) {
 		pr_warn("BTRFS: inflateInit failed\n");
-		kunmap(pages_in[page_in_index]);
+		kunmap_local(data_in);
 		return -EIO;
 	}
 	while (workspace->strm.total_in < srclen) {
@@ -336,13 +336,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 
 		if (workspace->strm.avail_in == 0) {
 			unsigned long tmp;
-			kunmap(pages_in[page_in_index]);
+			kunmap_local(data_in);
 			page_in_index++;
 			if (page_in_index >= total_pages_in) {
 				data_in = NULL;
 				break;
 			}
-			data_in = kmap(pages_in[page_in_index]);
+			data_in = kmap_local_page(pages_in[page_in_index]);
 			workspace->strm.next_in = data_in;
 			tmp = srclen - workspace->strm.total_in;
 			workspace->strm.avail_in = min(tmp, PAGE_SIZE);
@@ -355,7 +355,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 done:
 	zlib_inflateEnd(&workspace->strm);
 	if (data_in)
-		kunmap(pages_in[page_in_index]);
+		kunmap_local(data_in);
 	if (!ret)
 		zero_fill_bio(cb->orig_bio);
 	return ret;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c
  2022-05-31 14:53 ` [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c Fabio M. De Francesco
@ 2022-05-31 15:46   ` Christoph Hellwig
  0 siblings, 0 replies; 23+ messages in thread
From: Christoph Hellwig @ 2022-05-31 15:46 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/3] btrfs: Replace kmap() with kmap_local_page() in lzo.c
  2022-05-31 14:53 ` [PATCH 2/3] btrfs: Replace kmap() with kmap_local_page() in lzo.c Fabio M. De Francesco
@ 2022-05-31 15:53   ` Christoph Hellwig
  0 siblings, 0 replies; 23+ messages in thread
From: Christoph Hellwig @ 2022-05-31 15:53 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel

On Tue, May 31, 2022 at 04:53:34PM +0200, Fabio M. De Francesco wrote:
> The use of kmap() is being deprecated in favor of kmap_local_page() where
> it is feasible. With kmap_local_page(), the mapping is per thread, CPU
> local and not globally visible.
> 
> Therefore, use kmap_local_page() / kunmap_local() in lzo.c wherever the
> mappings are per thread and not globally visible.

This looks fine:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
  2022-05-31 14:53 ` [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c Fabio M. De Francesco
@ 2022-05-31 15:53   ` Christoph Hellwig
  2022-05-31 20:35   ` kernel test robot
  1 sibling, 0 replies; 23+ messages in thread
From: Christoph Hellwig @ 2022-05-31 15:53 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
  2022-05-31 14:53 ` [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c Fabio M. De Francesco
  2022-05-31 15:53   ` Christoph Hellwig
@ 2022-05-31 20:35   ` kernel test robot
  2022-06-01 19:57       ` Fabio M. De Francesco
  1 sibling, 1 reply; 23+ messages in thread
From: kernel test robot @ 2022-05-31 20:35 UTC (permalink / raw)
  To: Fabio M. De Francesco, Chris Mason, Josef Bacik, David Sterba,
	Ira Weiny, linux-btrfs, linux-kernel
  Cc: llvm, kbuild-all, Fabio M. De Francesco

Hi "Fabio,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.18 next-20220531]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Fabio-M-De-Francesco/btrfs-Replace-kmap-with-kmap_local_page/20220531-225557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: x86_64-randconfig-a012 (https://download.01.org/0day-ci/archive/20220601/202206010437.EX5Nj7cu-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c825abd6b0198fb088d9752f556a70705bc99dfd)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a549d3a90067e82e5e7d44d78a98e4a4feb628c3
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Fabio-M-De-Francesco/btrfs-Replace-kmap-with-kmap_local_page/20220531-225557
        git checkout a549d3a90067e82e5e7d44d78a98e4a4feb628c3
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/btrfs/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> fs/btrfs/zlib.c:125:6: warning: variable 'data_in' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (out_page == NULL) {
               ^~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:270:6: note: uninitialized use occurs here
           if (data_in) {
               ^~~~~~~
   fs/btrfs/zlib.c:125:2: note: remove the 'if' if its condition is always false
           if (out_page == NULL) {
           ^~~~~~~~~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:115:6: warning: variable 'data_in' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/zlib.h:148:25: note: expanded from macro 'Z_OK'
   #define Z_OK            0
                           ^
   fs/btrfs/zlib.c:270:6: note: uninitialized use occurs here
           if (data_in) {
               ^~~~~~~
   fs/btrfs/zlib.c:115:2: note: remove the 'if' if its condition is always false
           if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:100:15: note: initialize the variable 'data_in' to silence this warning
           char *data_in;
                        ^
                         = NULL
>> fs/btrfs/zlib.c:125:6: warning: variable 'cpage_out' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (out_page == NULL) {
               ^~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:267:6: note: uninitialized use occurs here
           if (cpage_out)
               ^~~~~~~~~
   fs/btrfs/zlib.c:125:2: note: remove the 'if' if its condition is always false
           if (out_page == NULL) {
           ^~~~~~~~~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:115:6: warning: variable 'cpage_out' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/zlib.h:148:25: note: expanded from macro 'Z_OK'
   #define Z_OK            0
                           ^
   fs/btrfs/zlib.c:267:6: note: uninitialized use occurs here
           if (cpage_out)
               ^~~~~~~~~
   fs/btrfs/zlib.c:115:2: note: remove the 'if' if its condition is always false
           if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:101:17: note: initialize the variable 'cpage_out' to silence this warning
           char *cpage_out;
                          ^
                           = NULL
   4 warnings generated.


vim +125 fs/btrfs/zlib.c

c8b978188c9a0fd Chris Mason           2008-10-29   93  
c4bf665a3197554 David Sterba          2019-10-01   94  int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
c4bf665a3197554 David Sterba          2019-10-01   95  		u64 start, struct page **pages, unsigned long *out_pages,
c4bf665a3197554 David Sterba          2019-10-01   96  		unsigned long *total_in, unsigned long *total_out)
c8b978188c9a0fd Chris Mason           2008-10-29   97  {
261507a02ccba9a Li Zefan              2010-12-17   98  	struct workspace *workspace = list_entry(ws, struct workspace, list);
c8b978188c9a0fd Chris Mason           2008-10-29   99  	int ret;
c8b978188c9a0fd Chris Mason           2008-10-29  100  	char *data_in;
c8b978188c9a0fd Chris Mason           2008-10-29  101  	char *cpage_out;
c8b978188c9a0fd Chris Mason           2008-10-29  102  	int nr_pages = 0;
c8b978188c9a0fd Chris Mason           2008-10-29  103  	struct page *in_page = NULL;
c8b978188c9a0fd Chris Mason           2008-10-29  104  	struct page *out_page = NULL;
c8b978188c9a0fd Chris Mason           2008-10-29  105  	unsigned long bytes_left;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  106  	unsigned int in_buf_pages;
38c31464089f639 David Sterba          2017-02-14  107  	unsigned long len = *total_out;
4d3a800ebb12999 David Sterba          2017-02-14  108  	unsigned long nr_dest_pages = *out_pages;
e5d74902362f1a0 David Sterba          2017-02-14  109  	const unsigned long max_out = nr_dest_pages * PAGE_SIZE;
c8b978188c9a0fd Chris Mason           2008-10-29  110  
c8b978188c9a0fd Chris Mason           2008-10-29  111  	*out_pages = 0;
c8b978188c9a0fd Chris Mason           2008-10-29  112  	*total_out = 0;
c8b978188c9a0fd Chris Mason           2008-10-29  113  	*total_in = 0;
c8b978188c9a0fd Chris Mason           2008-10-29  114  
f51d2b59120ff36 David Sterba          2017-09-15  115  	if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
62e855771dacf7c Jeff Mahoney          2016-09-20  116  		pr_warn("BTRFS: deflateInit failed\n");
60e1975acb48fc3 Zach Brown            2014-05-09  117  		ret = -EIO;
c8b978188c9a0fd Chris Mason           2008-10-29  118  		goto out;
c8b978188c9a0fd Chris Mason           2008-10-29  119  	}
c8b978188c9a0fd Chris Mason           2008-10-29  120  
7880991344f7364 Sergey Senozhatsky    2014-07-07  121  	workspace->strm.total_in = 0;
7880991344f7364 Sergey Senozhatsky    2014-07-07  122  	workspace->strm.total_out = 0;
c8b978188c9a0fd Chris Mason           2008-10-29  123  
b0ee5e1ec44afda David Sterba          2021-06-14  124  	out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6ba Li Zefan              2010-11-09 @125  	if (out_page == NULL) {
60e1975acb48fc3 Zach Brown            2014-05-09  126  		ret = -ENOMEM;
4b72029dc3fd6ba Li Zefan              2010-11-09  127  		goto out;
4b72029dc3fd6ba Li Zefan              2010-11-09  128  	}
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  129  	cpage_out = kmap_local_page(out_page);
c8b978188c9a0fd Chris Mason           2008-10-29  130  	pages[0] = out_page;
c8b978188c9a0fd Chris Mason           2008-10-29  131  	nr_pages = 1;
c8b978188c9a0fd Chris Mason           2008-10-29  132  
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  133  	workspace->strm.next_in = workspace->buf;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  134  	workspace->strm.avail_in = 0;
7880991344f7364 Sergey Senozhatsky    2014-07-07  135  	workspace->strm.next_out = cpage_out;
09cbfeaf1a5a67b Kirill A. Shutemov    2016-04-01  136  	workspace->strm.avail_out = PAGE_SIZE;
c8b978188c9a0fd Chris Mason           2008-10-29  137  
7880991344f7364 Sergey Senozhatsky    2014-07-07  138  	while (workspace->strm.total_in < len) {
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  139  		/*
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  140  		 * Get next input pages and copy the contents to
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  141  		 * the workspace buffer if required.
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  142  		 */
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  143  		if (workspace->strm.avail_in == 0) {
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  144  			bytes_left = len - workspace->strm.total_in;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  145  			in_buf_pages = min(DIV_ROUND_UP(bytes_left, PAGE_SIZE),
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  146  					   workspace->buf_size / PAGE_SIZE);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  147  			if (in_buf_pages > 1) {
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  148  				int i;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  149  
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  150  				for (i = 0; i < in_buf_pages; i++) {
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  151  					if (data_in) {
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  152  						kunmap_local(data_in);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  153  						put_page(in_page);
55276e14df4324a David Sterba          2021-10-27  154  					}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  155  					in_page = find_get_page(mapping,
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  156  								start >> PAGE_SHIFT);
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  157  					data_in = kmap_local_page(in_page);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  158  					memcpy(workspace->buf + i * PAGE_SIZE,
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  159  					       data_in, PAGE_SIZE);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  160  					start += PAGE_SIZE;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  161  				}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  162  				workspace->strm.next_in = workspace->buf;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  163  			} else {
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  164  				if (data_in) {
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  165  					kunmap_local(data_in);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  166  					put_page(in_page);
55276e14df4324a David Sterba          2021-10-27  167  				}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  168  				in_page = find_get_page(mapping,
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  169  							start >> PAGE_SHIFT);
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  170  				data_in = kmap_local_page(in_page);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  171  				start += PAGE_SIZE;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  172  				workspace->strm.next_in = data_in;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  173  			}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  174  			workspace->strm.avail_in = min(bytes_left,
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  175  						       (unsigned long) workspace->buf_size);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  176  		}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  177  
7880991344f7364 Sergey Senozhatsky    2014-07-07  178  		ret = zlib_deflate(&workspace->strm, Z_SYNC_FLUSH);
c8b978188c9a0fd Chris Mason           2008-10-29  179  		if (ret != Z_OK) {
62e855771dacf7c Jeff Mahoney          2016-09-20  180  			pr_debug("BTRFS: deflate in loop returned %d\n",
c8b978188c9a0fd Chris Mason           2008-10-29  181  			       ret);
7880991344f7364 Sergey Senozhatsky    2014-07-07  182  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc3 Zach Brown            2014-05-09  183  			ret = -EIO;
c8b978188c9a0fd Chris Mason           2008-10-29  184  			goto out;
c8b978188c9a0fd Chris Mason           2008-10-29  185  		}
c8b978188c9a0fd Chris Mason           2008-10-29  186  
c8b978188c9a0fd Chris Mason           2008-10-29  187  		/* we're making it bigger, give up */
7880991344f7364 Sergey Senozhatsky    2014-07-07  188  		if (workspace->strm.total_in > 8192 &&
7880991344f7364 Sergey Senozhatsky    2014-07-07  189  		    workspace->strm.total_in <
7880991344f7364 Sergey Senozhatsky    2014-07-07  190  		    workspace->strm.total_out) {
130d5b415a091e4 David Sterba          2014-06-20  191  			ret = -E2BIG;
c8b978188c9a0fd Chris Mason           2008-10-29  192  			goto out;
c8b978188c9a0fd Chris Mason           2008-10-29  193  		}
c8b978188c9a0fd Chris Mason           2008-10-29  194  		/* we need another page for writing out.  Test this
c8b978188c9a0fd Chris Mason           2008-10-29  195  		 * before the total_in so we will pull in a new page for
c8b978188c9a0fd Chris Mason           2008-10-29  196  		 * the stream end if required
c8b978188c9a0fd Chris Mason           2008-10-29  197  		 */
7880991344f7364 Sergey Senozhatsky    2014-07-07  198  		if (workspace->strm.avail_out == 0) {
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  199  			kunmap_local(cpage_out);
c8b978188c9a0fd Chris Mason           2008-10-29  200  			if (nr_pages == nr_dest_pages) {
c8b978188c9a0fd Chris Mason           2008-10-29  201  				out_page = NULL;
60e1975acb48fc3 Zach Brown            2014-05-09  202  				ret = -E2BIG;
c8b978188c9a0fd Chris Mason           2008-10-29  203  				goto out;
c8b978188c9a0fd Chris Mason           2008-10-29  204  			}
b0ee5e1ec44afda David Sterba          2021-06-14  205  			out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6ba Li Zefan              2010-11-09  206  			if (out_page == NULL) {
60e1975acb48fc3 Zach Brown            2014-05-09  207  				ret = -ENOMEM;
4b72029dc3fd6ba Li Zefan              2010-11-09  208  				goto out;
4b72029dc3fd6ba Li Zefan              2010-11-09  209  			}
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  210  			cpage_out = kmap_local_page(out_page);
c8b978188c9a0fd Chris Mason           2008-10-29  211  			pages[nr_pages] = out_page;
c8b978188c9a0fd Chris Mason           2008-10-29  212  			nr_pages++;
09cbfeaf1a5a67b Kirill A. Shutemov    2016-04-01  213  			workspace->strm.avail_out = PAGE_SIZE;
7880991344f7364 Sergey Senozhatsky    2014-07-07  214  			workspace->strm.next_out = cpage_out;
c8b978188c9a0fd Chris Mason           2008-10-29  215  		}
c8b978188c9a0fd Chris Mason           2008-10-29  216  		/* we're all done */
7880991344f7364 Sergey Senozhatsky    2014-07-07  217  		if (workspace->strm.total_in >= len)
c8b978188c9a0fd Chris Mason           2008-10-29  218  			break;
7880991344f7364 Sergey Senozhatsky    2014-07-07  219  		if (workspace->strm.total_out > max_out)
c8b978188c9a0fd Chris Mason           2008-10-29  220  			break;
c8b978188c9a0fd Chris Mason           2008-10-29  221  	}
7880991344f7364 Sergey Senozhatsky    2014-07-07  222  	workspace->strm.avail_in = 0;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  223  	/*
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  224  	 * Call deflate with Z_FINISH flush parameter providing more output
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  225  	 * space but no more input data, until it returns with Z_STREAM_END.
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  226  	 */
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  227  	while (ret != Z_STREAM_END) {
7880991344f7364 Sergey Senozhatsky    2014-07-07  228  		ret = zlib_deflate(&workspace->strm, Z_FINISH);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  229  		if (ret == Z_STREAM_END)
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  230  			break;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  231  		if (ret != Z_OK && ret != Z_BUF_ERROR) {
7880991344f7364 Sergey Senozhatsky    2014-07-07  232  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc3 Zach Brown            2014-05-09  233  			ret = -EIO;
c8b978188c9a0fd Chris Mason           2008-10-29  234  			goto out;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  235  		} else if (workspace->strm.avail_out == 0) {
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  236  			/* get another page for the stream end */
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  237  			kunmap_local(cpage_out);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  238  			if (nr_pages == nr_dest_pages) {
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  239  				out_page = NULL;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  240  				ret = -E2BIG;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  241  				goto out;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  242  			}
b0ee5e1ec44afda David Sterba          2021-06-14  243  			out_page = alloc_page(GFP_NOFS);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  244  			if (out_page == NULL) {
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  245  				ret = -ENOMEM;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  246  				goto out;
c8b978188c9a0fd Chris Mason           2008-10-29  247  			}
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  248  			cpage_out = kmap_local_page(out_page);
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  249  			pages[nr_pages] = out_page;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  250  			nr_pages++;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  251  			workspace->strm.avail_out = PAGE_SIZE;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  252  			workspace->strm.next_out = cpage_out;
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  253  		}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  254  	}
3fd396afc05fc90 Mikhail Zaslonko      2020-01-30  255  	zlib_deflateEnd(&workspace->strm);
c8b978188c9a0fd Chris Mason           2008-10-29  256  
7880991344f7364 Sergey Senozhatsky    2014-07-07  257  	if (workspace->strm.total_out >= workspace->strm.total_in) {
60e1975acb48fc3 Zach Brown            2014-05-09  258  		ret = -E2BIG;
c8b978188c9a0fd Chris Mason           2008-10-29  259  		goto out;
c8b978188c9a0fd Chris Mason           2008-10-29  260  	}
c8b978188c9a0fd Chris Mason           2008-10-29  261  
c8b978188c9a0fd Chris Mason           2008-10-29  262  	ret = 0;
7880991344f7364 Sergey Senozhatsky    2014-07-07  263  	*total_out = workspace->strm.total_out;
7880991344f7364 Sergey Senozhatsky    2014-07-07  264  	*total_in = workspace->strm.total_in;
c8b978188c9a0fd Chris Mason           2008-10-29  265  out:
c8b978188c9a0fd Chris Mason           2008-10-29  266  	*out_pages = nr_pages;
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  267  	if (cpage_out)
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  268  		kunmap_local(cpage_out);
55276e14df4324a David Sterba          2021-10-27  269  
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  270  	if (data_in) {
a549d3a90067e82 Fabio M. De Francesco 2022-05-31  271  		kunmap_local(data_in);
09cbfeaf1a5a67b Kirill A. Shutemov    2016-04-01  272  		put_page(in_page);
55276e14df4324a David Sterba          2021-10-27  273  	}
c8b978188c9a0fd Chris Mason           2008-10-29  274  	return ret;
c8b978188c9a0fd Chris Mason           2008-10-29  275  }
c8b978188c9a0fd Chris Mason           2008-10-29  276  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-05-31 14:53 [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
                   ` (2 preceding siblings ...)
  2022-05-31 14:53 ` [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c Fabio M. De Francesco
@ 2022-06-01 13:25 ` David Sterba
  2022-06-02 16:22   ` Ira Weiny
  2022-06-02 18:01   ` Fabio M. De Francesco
  2022-06-02 15:20 ` Christoph Hellwig
  4 siblings, 2 replies; 23+ messages in thread
From: David Sterba @ 2022-06-01 13:25 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel

On Tue, May 31, 2022 at 04:53:32PM +0200, Fabio M. De Francesco wrote:
> This is the first series of patches aimed towards the conversion of Btrfs
> filesystem from the use of kmap() to kmap_local_page().

We've already had patches converting kmaps and you're changing the last
ones, so this is could be the last series, with two exceptions.

1) You've changed lzo.c and zlib. but the same kmap/kunmap pattern is
   used in zstd.c.

2) kmap_atomic in inode.c, so that's technically not kmap but it's said
   to be deprecated and also can be replaced by kmap_local_page. The
   context in check_compressed_csum is atomic (in end io) so the kmap
   hasn't been used there.

> tweed32:~ # btrfs check -p ~zoek/dev/btrfs.file

That won't verify if the kmap conversion is OK, it's a runtime thing
while 'check' verifies the data on device. Have you run any kind of
stress test with enabled compression before running the check?

> Opening filesystem to check...
> Checking filesystem on /home/zoek/dev/btrfs.file
> UUID: 897d65c5-1167-45b4-b811-2bfe74a320ca
> [1/7] checking root items                      (0:00:00 elapsed, 1774 items checked)
> [2/7] checking extents                         (0:00:00 elapsed, 135 items checked)
> [3/7] checking free space tree                 (0:00:00 elapsed, 4 items checked)
> [4/7] checking fs roots                        (0:00:00 elapsed, 104 items checked)
> [5/7] checking csums (without verifying data)  (0:00:00 elapsed, 205 items checked)
> [6/7] checking root refs                       (0:00:00 elapsed, 3 items checked)
> [7/7] checking quota groups skipped (not enabled on this FS)
> found 47394816 bytes used, no error found
> total csum bytes: 44268
> total tree bytes: 2064384
> total fs tree bytes: 1720320
> total extent tree bytes: 180224
> btree space waste bytes: 465350
> file data blocks allocated: 45330432
>  referenced 45330432
> 
> Fabio M. De Francesco (3):
>   btrfs: Replace kmap() with kmap_local_page() in inode.c
>   btrfs: Replace kmap() with kmap_local_page() in lzo.c
>   btrfs: Replace kmap() with kmap_local_page() in zlib.c

Please send patches converting zstd.c and the remaining kmap_atomic
usage in inode.c, otherwise the 3 patches are now in misc-next, thanks.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
  2022-05-31 20:35   ` kernel test robot
@ 2022-06-01 19:57       ` Fabio M. De Francesco
  0 siblings, 0 replies; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-06-01 19:57 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel, kernel test robot
  Cc: llvm, kbuild-all

On martedì 31 maggio 2022 22:35:30 CEST kernel test robot wrote:
> Hi "Fabio,
> 
> Thank you for the patch! Perhaps something to improve:
> 

[snip]

> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
> >> fs/btrfs/zlib.c:125:6: warning: variable 'data_in' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (out_page == NULL) {
>                ^~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:270:6: note: uninitialized use occurs here
>            if (data_in) {
>                ^~~~~~~
>    fs/btrfs/zlib.c:125:2: note: remove the 'if' if its condition is 
always false
>            if (out_page == NULL) {
>            ^~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:115:6: warning: variable 'data_in' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    include/linux/zlib.h:148:25: note: expanded from macro 'Z_OK'
>    #define Z_OK            0
>                            ^
>    fs/btrfs/zlib.c:270:6: note: uninitialized use occurs here
>            if (data_in) {
>                ^~~~~~~
>    fs/btrfs/zlib.c:115:2: note: remove the 'if' if its condition is 
always false
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>            
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:100:15: note: initialize the variable 'data_in' to 
silence this warning
>            char *data_in;
>                         ^
>                          = NULL
> >> fs/btrfs/zlib.c:125:6: warning: variable 'cpage_out' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (out_page == NULL) {
>                ^~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:267:6: note: uninitialized use occurs here
>            if (cpage_out)
>                ^~~~~~~~~
>    fs/btrfs/zlib.c:125:2: note: remove the 'if' if its condition is 
always false
>            if (out_page == NULL) {
>            ^~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:115:6: warning: variable 'cpage_out' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    include/linux/zlib.h:148:25: note: expanded from macro 'Z_OK'
>    #define Z_OK            0
>                            ^
>    fs/btrfs/zlib.c:267:6: note: uninitialized use occurs here
>            if (cpage_out)
>                ^~~~~~~~~
>    fs/btrfs/zlib.c:115:2: note: remove the 'if' if its condition is 
always false
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>            
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:101:17: note: initialize the variable 'cpage_out' to 
silence this warning
>            char *cpage_out;
>                           ^
>                            = NULL
>    4 warnings generated.

I'll initialize these variables in v2.

Thanks,

Fabio



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
@ 2022-06-01 19:57       ` Fabio M. De Francesco
  0 siblings, 0 replies; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-06-01 19:57 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3429 bytes --]

On martedì 31 maggio 2022 22:35:30 CEST kernel test robot wrote:
> Hi "Fabio,
> 
> Thank you for the patch! Perhaps something to improve:
> 

[snip]

> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
> >> fs/btrfs/zlib.c:125:6: warning: variable 'data_in' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (out_page == NULL) {
>                ^~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:270:6: note: uninitialized use occurs here
>            if (data_in) {
>                ^~~~~~~
>    fs/btrfs/zlib.c:125:2: note: remove the 'if' if its condition is 
always false
>            if (out_page == NULL) {
>            ^~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:115:6: warning: variable 'data_in' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    include/linux/zlib.h:148:25: note: expanded from macro 'Z_OK'
>    #define Z_OK            0
>                            ^
>    fs/btrfs/zlib.c:270:6: note: uninitialized use occurs here
>            if (data_in) {
>                ^~~~~~~
>    fs/btrfs/zlib.c:115:2: note: remove the 'if' if its condition is 
always false
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>            
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:100:15: note: initialize the variable 'data_in' to 
silence this warning
>            char *data_in;
>                         ^
>                          = NULL
> >> fs/btrfs/zlib.c:125:6: warning: variable 'cpage_out' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (out_page == NULL) {
>                ^~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:267:6: note: uninitialized use occurs here
>            if (cpage_out)
>                ^~~~~~~~~
>    fs/btrfs/zlib.c:125:2: note: remove the 'if' if its condition is 
always false
>            if (out_page == NULL) {
>            ^~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:115:6: warning: variable 'cpage_out' is used 
uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    include/linux/zlib.h:148:25: note: expanded from macro 'Z_OK'
>    #define Z_OK            0
>                            ^
>    fs/btrfs/zlib.c:267:6: note: uninitialized use occurs here
>            if (cpage_out)
>                ^~~~~~~~~
>    fs/btrfs/zlib.c:115:2: note: remove the 'if' if its condition is 
always false
>            if (Z_OK != zlib_deflateInit(&workspace->strm, workspace-
>level)) {
>            
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    fs/btrfs/zlib.c:101:17: note: initialize the variable 'cpage_out' to 
silence this warning
>            char *cpage_out;
>                           ^
>                            = NULL
>    4 warnings generated.

I'll initialize these variables in v2.

Thanks,

Fabio


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-05-31 14:53 [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
                   ` (3 preceding siblings ...)
  2022-06-01 13:25 ` [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() David Sterba
@ 2022-06-02 15:20 ` Christoph Hellwig
  2022-06-02 15:55   ` Ira Weiny
  2022-06-02 16:28   ` David Sterba
  4 siblings, 2 replies; 23+ messages in thread
From: Christoph Hellwig @ 2022-06-02 15:20 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Ira Weiny, linux-btrfs,
	linux-kernel

Turns out that while this looks good, it actually crashes when
running xfstests.  I think this is due to the fact that kmap sets
the page address, which kmap_local_page does not.

btrfs/150 1s ... [  168.252943] run fstests btrfs/150 at 2022-06-02 15:17:11
[  169.462292] BTRFS info (device vdb): flagging fs with big metadata feature
[  169.463728] BTRFS info (device vdb): disk space caching is enabled
[  169.464953] BTRFS info (device vdb): has skinny extents
[  170.596218] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4
devid 1 transid 5 /dev)
[  170.599471] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4 devid 2 transid 5 /dev)
[  170.657170] BTRFS info (device vdc): flagging fs with big metadata feature
[  170.659509] BTRFS info (device vdc): use zlib compression, level 3
[  170.661190] BTRFS info (device vdc): disk space caching is enabled
[  170.670706] BTRFS info (device vdc): has skinny extents
[  170.714181] BTRFS info (device vdc): checking UUID tree
[  170.735058] BUG: kernel NULL pointer dereference, address: 0000000000000008
[  170.736478] #PF: supervisor read access in kernel mode
[  170.737457] #PF: error_code(0x0000) - not-present page
[  170.738529] PGD 0 P4D 0 
[  170.739211] Oops: 0000 [#1] PREEMPT SMP PTI
[  170.740101] CPU: 0 PID: 43 Comm: kworker/u4:3 Not tainted 5.18.0-rc7+ #1539
[  170.741478] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
[  170.743246] Workqueue: btrfs-delalloc btrfs_work_helper
[  170.744282] RIP: 0010:zlib_compress_pages+0x128/0x670
[  170.745346] Code: 00 00 00 16 00 00 48 01 e8 31 ed 48 c1 f8 06 48 c1 e0 0c 48 01 f8 49 89 0
[  170.749042] RSP: 0018:ffffc9000038bc70 EFLAGS: 00010286
[  170.750037] RAX: 0000000000000001 RBX: ffffc9000038bdb8 RCX: 0000000000000001
[  170.751351] RDX: 0000000000002000 RSI: ffffffff82f532fb RDI: ffff888000000000
[  170.752695] RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000001
[  170.754106] R10: 0000000000000000 R11: ffff8881039a5b30 R12: ffff888107befb48
[  170.755449] R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000000
[  170.756922] FS:  0000000000000000(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000
[  170.758642] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  170.759714] CR2: 0000000000000008 CR3: 000000010ab60000 CR4: 00000000000006f0
[  170.761082] Call Trace:
[  170.761553]  <TASK>
[  170.761968]  ? _raw_spin_unlock+0x24/0x40
[  170.762776]  btrfs_compress_pages+0xda/0x120
[  170.763682]  compress_file_range+0x3b9/0x840
[  170.764570]  async_cow_start+0xd/0x30
[  170.765308]  ? submit_compressed_extents+0x3c0/0x3c0
[  170.766241]  btrfs_work_helper+0xf5/0x3f0
[  170.767009]  ? lock_is_held_type+0xe2/0x140
[  170.767817]  process_one_work+0x239/0x550
[  170.768633]  ? process_one_work+0x550/0x550
[  170.769447]  worker_thread+0x4d/0x3a0
[  170.770210]  ? process_one_work+0x550/0x550
[  170.771019]  kthread+0xe2/0x110
[  170.771623]  ? kthread_complete_and_exit+0x20/0x20
[  170.772697]  ret_from_fork+0x22/0x30
[  170.773454]  </TASK>


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-02 15:20 ` Christoph Hellwig
@ 2022-06-02 15:55   ` Ira Weiny
  2022-06-02 16:28   ` David Sterba
  1 sibling, 0 replies; 23+ messages in thread
From: Ira Weiny @ 2022-06-02 15:55 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Fabio M. De Francesco, Chris Mason, Josef Bacik, David Sterba,
	linux-btrfs, linux-kernel

On Thu, Jun 02, 2022 at 08:20:08AM -0700, Christoph Hellwig wrote:
> Turns out that while this looks good, it actually crashes when
> running xfstests.  I think this is due to the fact that kmap sets
> the page address, which kmap_local_page does not.

:-(

I know that Fabio is working on getting xfstests set up and we have been
discussing the use of page address in the fs/btrfs code.

Stay tuned,
Ira

> 
> btrfs/150 1s ... [  168.252943] run fstests btrfs/150 at 2022-06-02 15:17:11
> [  169.462292] BTRFS info (device vdb): flagging fs with big metadata feature
> [  169.463728] BTRFS info (device vdb): disk space caching is enabled
> [  169.464953] BTRFS info (device vdb): has skinny extents
> [  170.596218] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4
> devid 1 transid 5 /dev)
> [  170.599471] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4 devid 2 transid 5 /dev)
> [  170.657170] BTRFS info (device vdc): flagging fs with big metadata feature
> [  170.659509] BTRFS info (device vdc): use zlib compression, level 3
> [  170.661190] BTRFS info (device vdc): disk space caching is enabled
> [  170.670706] BTRFS info (device vdc): has skinny extents
> [  170.714181] BTRFS info (device vdc): checking UUID tree
> [  170.735058] BUG: kernel NULL pointer dereference, address: 0000000000000008
> [  170.736478] #PF: supervisor read access in kernel mode
> [  170.737457] #PF: error_code(0x0000) - not-present page
> [  170.738529] PGD 0 P4D 0 
> [  170.739211] Oops: 0000 [#1] PREEMPT SMP PTI
> [  170.740101] CPU: 0 PID: 43 Comm: kworker/u4:3 Not tainted 5.18.0-rc7+ #1539
> [  170.741478] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
> [  170.743246] Workqueue: btrfs-delalloc btrfs_work_helper
> [  170.744282] RIP: 0010:zlib_compress_pages+0x128/0x670
> [  170.745346] Code: 00 00 00 16 00 00 48 01 e8 31 ed 48 c1 f8 06 48 c1 e0 0c 48 01 f8 49 89 0
> [  170.749042] RSP: 0018:ffffc9000038bc70 EFLAGS: 00010286
> [  170.750037] RAX: 0000000000000001 RBX: ffffc9000038bdb8 RCX: 0000000000000001
> [  170.751351] RDX: 0000000000002000 RSI: ffffffff82f532fb RDI: ffff888000000000
> [  170.752695] RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000001
> [  170.754106] R10: 0000000000000000 R11: ffff8881039a5b30 R12: ffff888107befb48
> [  170.755449] R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000000
> [  170.756922] FS:  0000000000000000(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000
> [  170.758642] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [  170.759714] CR2: 0000000000000008 CR3: 000000010ab60000 CR4: 00000000000006f0
> [  170.761082] Call Trace:
> [  170.761553]  <TASK>
> [  170.761968]  ? _raw_spin_unlock+0x24/0x40
> [  170.762776]  btrfs_compress_pages+0xda/0x120
> [  170.763682]  compress_file_range+0x3b9/0x840
> [  170.764570]  async_cow_start+0xd/0x30
> [  170.765308]  ? submit_compressed_extents+0x3c0/0x3c0
> [  170.766241]  btrfs_work_helper+0xf5/0x3f0
> [  170.767009]  ? lock_is_held_type+0xe2/0x140
> [  170.767817]  process_one_work+0x239/0x550
> [  170.768633]  ? process_one_work+0x550/0x550
> [  170.769447]  worker_thread+0x4d/0x3a0
> [  170.770210]  ? process_one_work+0x550/0x550
> [  170.771019]  kthread+0xe2/0x110
> [  170.771623]  ? kthread_complete_and_exit+0x20/0x20
> [  170.772697]  ret_from_fork+0x22/0x30
> [  170.773454]  </TASK>
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-01 13:25 ` [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() David Sterba
@ 2022-06-02 16:22   ` Ira Weiny
  2022-06-02 16:46     ` Matthew Wilcox
  2022-06-02 18:01   ` Fabio M. De Francesco
  1 sibling, 1 reply; 23+ messages in thread
From: Ira Weiny @ 2022-06-02 16:22 UTC (permalink / raw)
  To: David Sterba
  Cc: Fabio M. De Francesco, Chris Mason, Josef Bacik, David Sterba,
	linux-btrfs, linux-kernel, Matthew Wilcox

On Wed, Jun 01, 2022 at 03:25:45PM +0200, David Sterba wrote:
> On Tue, May 31, 2022 at 04:53:32PM +0200, Fabio M. De Francesco wrote:
> > This is the first series of patches aimed towards the conversion of Btrfs
> > filesystem from the use of kmap() to kmap_local_page().
> 
> We've already had patches converting kmaps and you're changing the last
> ones, so this is could be the last series, with two exceptions.
> 
> 1) You've changed lzo.c and zlib. but the same kmap/kunmap pattern is
>    used in zstd.c.

I checked out zstd.c and one of the issues there is the way that the input
workspace is mapped page by page while iterating those pages.

This got me thinking about what Willy said at LSFmm concerning something like
kmap_local_range().  Mapping more than 1 page at a time could save some
unmap/remap of output pages required for kmap_local_page() ordering.

Unfortunately, I think the length of the input is probably to long in many
cases.  And some remapping may still be required.

Cc: Willy

As an aside, Willy, I'm thinking that a kmap_local_range() should return a
folio in some way.  Would you agree?

Ira

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-02 15:20 ` Christoph Hellwig
  2022-06-02 15:55   ` Ira Weiny
@ 2022-06-02 16:28   ` David Sterba
  2022-06-05 15:11     ` Fabio M. De Francesco
  1 sibling, 1 reply; 23+ messages in thread
From: David Sterba @ 2022-06-02 16:28 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Fabio M. De Francesco, Chris Mason, Josef Bacik, David Sterba,
	Ira Weiny, linux-btrfs, linux-kernel

On Thu, Jun 02, 2022 at 08:20:08AM -0700, Christoph Hellwig wrote:
> Turns out that while this looks good, it actually crashes when
> running xfstests.  I think this is due to the fact that kmap sets
> the page address, which kmap_local_page does not.
> 
> btrfs/150 1s ... [  168.252943] run fstests btrfs/150 at 2022-06-02 15:17:11
> [  169.462292] BTRFS info (device vdb): flagging fs with big metadata feature
> [  169.463728] BTRFS info (device vdb): disk space caching is enabled
> [  169.464953] BTRFS info (device vdb): has skinny extents
> [  170.596218] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4
> devid 1 transid 5 /dev)
> [  170.599471] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4 devid 2 transid 5 /dev)
> [  170.657170] BTRFS info (device vdc): flagging fs with big metadata feature
> [  170.659509] BTRFS info (device vdc): use zlib compression, level 3
> [  170.661190] BTRFS info (device vdc): disk space caching is enabled
> [  170.670706] BTRFS info (device vdc): has skinny extents
> [  170.714181] BTRFS info (device vdc): checking UUID tree
> [  170.735058] BUG: kernel NULL pointer dereference, address: 0000000000000008
> [  170.736478] #PF: supervisor read access in kernel mode
> [  170.737457] #PF: error_code(0x0000) - not-present page
> [  170.738529] PGD 0 P4D 0 
> [  170.739211] Oops: 0000 [#1] PREEMPT SMP PTI
> [  170.740101] CPU: 0 PID: 43 Comm: kworker/u4:3 Not tainted 5.18.0-rc7+ #1539
> [  170.741478] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
> [  170.743246] Workqueue: btrfs-delalloc btrfs_work_helper
> [  170.744282] RIP: 0010:zlib_compress_pages+0x128/0x670

I've just hit the crash too, so I've removed the patches from misc-next
until there's fixed version.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-02 16:22   ` Ira Weiny
@ 2022-06-02 16:46     ` Matthew Wilcox
  0 siblings, 0 replies; 23+ messages in thread
From: Matthew Wilcox @ 2022-06-02 16:46 UTC (permalink / raw)
  To: Ira Weiny
  Cc: David Sterba, Fabio M. De Francesco, Chris Mason, Josef Bacik,
	David Sterba, linux-btrfs, linux-kernel

On Thu, Jun 02, 2022 at 09:22:15AM -0700, Ira Weiny wrote:
> On Wed, Jun 01, 2022 at 03:25:45PM +0200, David Sterba wrote:
> > On Tue, May 31, 2022 at 04:53:32PM +0200, Fabio M. De Francesco wrote:
> > > This is the first series of patches aimed towards the conversion of Btrfs
> > > filesystem from the use of kmap() to kmap_local_page().
> > 
> > We've already had patches converting kmaps and you're changing the last
> > ones, so this is could be the last series, with two exceptions.
> > 
> > 1) You've changed lzo.c and zlib. but the same kmap/kunmap pattern is
> >    used in zstd.c.
> 
> I checked out zstd.c and one of the issues there is the way that the input
> workspace is mapped page by page while iterating those pages.
> 
> This got me thinking about what Willy said at LSFmm concerning something like
> kmap_local_range().  Mapping more than 1 page at a time could save some
> unmap/remap of output pages required for kmap_local_page() ordering.

Umm ... Not entirely sure what I said, but it'd be really hard to kmap
multiple pages with the current PAE implementation.  I've steered away
from doing that for now, and kmap_local_folio() just guarantees the
page that the offset lands in is mapped.

I don't think the right answer is having a kmap_folio() that will map
the entire folio.  I'd be more tempted to add vmap_folio() for that.
My understanding is that PAE systems have more address space available
for vmap than they do for kmap.

> Unfortunately, I think the length of the input is probably to long in many
> cases.  And some remapping may still be required.
> 
> Cc: Willy
> 
> As an aside, Willy, I'm thinking that a kmap_local_range() should return a
> folio in some way.  Would you agree?

I imagine it taking a folio to describe the range that's being accessed.
But maybe it should be a phys_addr_t?  I tend to prefer phys_addr_t over
pfn + offset as it's more compact on 64-bit systems and the same on
32-bit systems.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-01 13:25 ` [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() David Sterba
  2022-06-02 16:22   ` Ira Weiny
@ 2022-06-02 18:01   ` Fabio M. De Francesco
  1 sibling, 0 replies; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-06-02 18:01 UTC (permalink / raw)
  To: dsterba, Fabio M. De Francesco, Chris Mason, Josef Bacik,
	David Sterba, Ira Weiny, linux-btrfs, linux-kernel,
	Christoph Hellwig, Matthew Wilcox

On mercoledì 1 giugno 2022 15:25:45 CEST David Sterba wrote:
> On Tue, May 31, 2022 at 04:53:32PM +0200, Fabio M. De Francesco wrote:
> > This is the first series of patches aimed towards the conversion of 
Btrfs
> > filesystem from the use of kmap() to kmap_local_page().
> 
> We've already had patches converting kmaps and you're changing the last
> ones, so this is could be the last series, with two exceptions.
> 
> 1) You've changed lzo.c and zlib.

and inode.c.

> but the same kmap/kunmap pattern is
>    used in zstd.c.

I thought that these mappings I had worked on were safe to convert.

Instead I wasn't sure that the others I left untouched in zstd.c could so 
easily and mechanically be converted without prior code inspection and 
proper tests.

I did see those in zstd.c, but I decided to postpone those conversions 
because I'm not yet sure if and how the virtual addresses we get currently 
from kmap() are re-used.

I saw assignments like "workspace->in_buf.src = kmap(in_page);". Is 
"in_buf" re-used across different contexts? (I see that Btrfs uses a dozen 
workqueues). 

I also see that kunmap() is called in the same functions that assign 
virtual addresses to "in_buf" and this makes me think that those addresses 
are not handled across contexts, otherwise you already have bugs. But may 
very well be that somewhere in the calls chain the code flushes workqueues 
before returning to the callers (it would mean that when kunmap() is called 
we can be sure that those workqueues are done with using those addresses). 

Furthermore, what can you say about the tens of page_address() spread 
across the whole fs/btrfs? 

If those page_address() take pages from HIGHMEM which were mapped using 
kmap_local_page(), the filesystem will oops the kernel...

About this issue, please see a bug fix ("[PATCH v2] fs/ext2: Avoid 
page_address on pages returned by ext2_get_page") at 
https://lore.kernel.org/lkml/
20210714185448.8707ac239e9f12b3a7f5b9f9@urjc.es/#r

Do they only use physical memory from ZONE_NORMAL?

Can you please confirm that it is safe to convert those left kmap() to 
kmap_local_page() and that those page_address() are safe?

If so, I have no problems to convert what I had left for later. Otherwise 
I'll need to carefully inspect the code.

> 2) kmap_atomic in inode.c, so that's technically not kmap but it's said
>    to be deprecated and also can be replaced by kmap_local_page. The
>    context in check_compressed_csum is atomic (in end io) so the kmap
>    hasn't been used there.

I was not 100% sure about the preemption requirements for those call sites 
so I had not converted them yet. Are you saying that there is no need for 
preempt_disable() at the following sites?

# git grep kmap_atomic fs/btrfs
fs/btrfs/compression.c:                 kaddr = kmap_atomic(page);
fs/btrfs/inode.c:                       kaddr = kmap_atomic(cpage);
fs/btrfs/inode.c:               kaddr = kmap_atomic(page);
fs/btrfs/inode.c:       kaddr = kmap_atomic(page);

> > tweed32:~ # btrfs check -p ~zoek/dev/btrfs.file
> 
> That won't verify if the kmap conversion is OK, it's a runtime thing
> while 'check' verifies the data on device. Have you run any kind of
> stress test with enabled compression before running the check?

Ah, thanks. I didn't know this thing.

I installed (x)fstests a couple of days ago. I think it helps to test this 
and other conversions to local mappings, but I haven't yet had time to 
learn how to use it.

Does (x)fstests cover the compression code? Are there any specific tests I 
should target?

> Please send patches converting zstd.c and the remaining kmap_atomic
> usage in inode.c, otherwise the 3 patches are now in misc-next, thanks.

New version is required in any case because LKP reported four uninitialized 
variables in patch 3/3. 

I'm just reading the reports that both you and Christoph hit. At first 
sight they seem to be due to page_address() calls (but I may be wrong, just 
had few minutes to reply so late) :( 

I was wrong in thinking that these call sites could be converted safely. 
I'll do the tests before posting v2.

Thanks,

Fabio

P.S.: I've just read a message from Ira Weiny about something he saw in the 
unmapping order in zstd_compress_pages(). We must think how to address 
mapping /unmapping order properly.





^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
  2022-05-31 14:53 ` [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c Fabio M. De Francesco
  2022-05-31 15:53   ` Christoph Hellwig
@ 2022-06-06 12:11 ` Dan Carpenter
  1 sibling, 0 replies; 23+ messages in thread
From: kernel test robot @ 2022-06-02 18:59 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 16837 bytes --]

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220531145335.13954-4-fmdefrancesco@gmail.com>
References: <20220531145335.13954-4-fmdefrancesco@gmail.com>
TO: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
TO: Chris Mason <chris.mason@fusionio.com>
TO: Josef Bacik <josef@toxicpanda.com>
TO: David Sterba <dsterba@suse.com>
TO: Ira Weiny <ira.weiny@intel.com>
TO: linux-btrfs(a)vger.kernel.org
TO: linux-kernel(a)vger.kernel.org
CC: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>

Hi "Fabio,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.18 next-20220602]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Fabio-M-De-Francesco/btrfs-Replace-kmap-with-kmap_local_page/20220531-225557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20220603/202206030230.ttuhGnvx-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/zlib.c:151 zlib_compress_pages() error: uninitialized symbol 'data_in'.
fs/btrfs/zlib.c:267 zlib_compress_pages() error: uninitialized symbol 'cpage_out'.

Old smatch warnings:
fs/btrfs/zlib.c:164 zlib_compress_pages() error: uninitialized symbol 'data_in'.
fs/btrfs/zlib.c:227 zlib_compress_pages() error: uninitialized symbol 'ret'.
fs/btrfs/zlib.c:270 zlib_compress_pages() error: uninitialized symbol 'data_in'.

vim +/data_in +151 fs/btrfs/zlib.c

c8b978188c9a0f Chris Mason           2008-10-29   93  
c4bf665a319755 David Sterba          2019-10-01   94  int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
c4bf665a319755 David Sterba          2019-10-01   95  		u64 start, struct page **pages, unsigned long *out_pages,
c4bf665a319755 David Sterba          2019-10-01   96  		unsigned long *total_in, unsigned long *total_out)
c8b978188c9a0f Chris Mason           2008-10-29   97  {
261507a02ccba9 Li Zefan              2010-12-17   98  	struct workspace *workspace = list_entry(ws, struct workspace, list);
c8b978188c9a0f Chris Mason           2008-10-29   99  	int ret;
c8b978188c9a0f Chris Mason           2008-10-29  100  	char *data_in;
c8b978188c9a0f Chris Mason           2008-10-29  101  	char *cpage_out;
c8b978188c9a0f Chris Mason           2008-10-29  102  	int nr_pages = 0;
c8b978188c9a0f Chris Mason           2008-10-29  103  	struct page *in_page = NULL;
c8b978188c9a0f Chris Mason           2008-10-29  104  	struct page *out_page = NULL;
c8b978188c9a0f Chris Mason           2008-10-29  105  	unsigned long bytes_left;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  106  	unsigned int in_buf_pages;
38c31464089f63 David Sterba          2017-02-14  107  	unsigned long len = *total_out;
4d3a800ebb1299 David Sterba          2017-02-14  108  	unsigned long nr_dest_pages = *out_pages;
e5d74902362f1a David Sterba          2017-02-14  109  	const unsigned long max_out = nr_dest_pages * PAGE_SIZE;
c8b978188c9a0f Chris Mason           2008-10-29  110  
c8b978188c9a0f Chris Mason           2008-10-29  111  	*out_pages = 0;
c8b978188c9a0f Chris Mason           2008-10-29  112  	*total_out = 0;
c8b978188c9a0f Chris Mason           2008-10-29  113  	*total_in = 0;
c8b978188c9a0f Chris Mason           2008-10-29  114  
f51d2b59120ff3 David Sterba          2017-09-15  115  	if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
62e855771dacf7 Jeff Mahoney          2016-09-20  116  		pr_warn("BTRFS: deflateInit failed\n");
60e1975acb48fc Zach Brown            2014-05-09  117  		ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  118  		goto out;
c8b978188c9a0f Chris Mason           2008-10-29  119  	}
c8b978188c9a0f Chris Mason           2008-10-29  120  
7880991344f736 Sergey Senozhatsky    2014-07-07  121  	workspace->strm.total_in = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  122  	workspace->strm.total_out = 0;
c8b978188c9a0f Chris Mason           2008-10-29  123  
b0ee5e1ec44afd David Sterba          2021-06-14  124  	out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6b Li Zefan              2010-11-09  125  	if (out_page == NULL) {
60e1975acb48fc Zach Brown            2014-05-09  126  		ret = -ENOMEM;
4b72029dc3fd6b Li Zefan              2010-11-09  127  		goto out;
4b72029dc3fd6b Li Zefan              2010-11-09  128  	}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  129  	cpage_out = kmap_local_page(out_page);
c8b978188c9a0f Chris Mason           2008-10-29  130  	pages[0] = out_page;
c8b978188c9a0f Chris Mason           2008-10-29  131  	nr_pages = 1;
c8b978188c9a0f Chris Mason           2008-10-29  132  
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  133  	workspace->strm.next_in = workspace->buf;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  134  	workspace->strm.avail_in = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  135  	workspace->strm.next_out = cpage_out;
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  136  	workspace->strm.avail_out = PAGE_SIZE;
c8b978188c9a0f Chris Mason           2008-10-29  137  
7880991344f736 Sergey Senozhatsky    2014-07-07  138  	while (workspace->strm.total_in < len) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  139  		/*
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  140  		 * Get next input pages and copy the contents to
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  141  		 * the workspace buffer if required.
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  142  		 */
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  143  		if (workspace->strm.avail_in == 0) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  144  			bytes_left = len - workspace->strm.total_in;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  145  			in_buf_pages = min(DIV_ROUND_UP(bytes_left, PAGE_SIZE),
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  146  					   workspace->buf_size / PAGE_SIZE);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  147  			if (in_buf_pages > 1) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  148  				int i;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  149  
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  150  				for (i = 0; i < in_buf_pages; i++) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31 @151  					if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  152  						kunmap_local(data_in);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  153  						put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  154  					}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  155  					in_page = find_get_page(mapping,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  156  								start >> PAGE_SHIFT);
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  157  					data_in = kmap_local_page(in_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  158  					memcpy(workspace->buf + i * PAGE_SIZE,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  159  					       data_in, PAGE_SIZE);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  160  					start += PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  161  				}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  162  				workspace->strm.next_in = workspace->buf;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  163  			} else {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  164  				if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  165  					kunmap_local(data_in);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  166  					put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  167  				}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  168  				in_page = find_get_page(mapping,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  169  							start >> PAGE_SHIFT);
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  170  				data_in = kmap_local_page(in_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  171  				start += PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  172  				workspace->strm.next_in = data_in;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  173  			}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  174  			workspace->strm.avail_in = min(bytes_left,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  175  						       (unsigned long) workspace->buf_size);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  176  		}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  177  
7880991344f736 Sergey Senozhatsky    2014-07-07  178  		ret = zlib_deflate(&workspace->strm, Z_SYNC_FLUSH);
c8b978188c9a0f Chris Mason           2008-10-29  179  		if (ret != Z_OK) {
62e855771dacf7 Jeff Mahoney          2016-09-20  180  			pr_debug("BTRFS: deflate in loop returned %d\n",
c8b978188c9a0f Chris Mason           2008-10-29  181  			       ret);
7880991344f736 Sergey Senozhatsky    2014-07-07  182  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc Zach Brown            2014-05-09  183  			ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  184  			goto out;
c8b978188c9a0f Chris Mason           2008-10-29  185  		}
c8b978188c9a0f Chris Mason           2008-10-29  186  
c8b978188c9a0f Chris Mason           2008-10-29  187  		/* we're making it bigger, give up */
7880991344f736 Sergey Senozhatsky    2014-07-07  188  		if (workspace->strm.total_in > 8192 &&
7880991344f736 Sergey Senozhatsky    2014-07-07  189  		    workspace->strm.total_in <
7880991344f736 Sergey Senozhatsky    2014-07-07  190  		    workspace->strm.total_out) {
130d5b415a091e David Sterba          2014-06-20  191  			ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  192  			goto out;
c8b978188c9a0f Chris Mason           2008-10-29  193  		}
c8b978188c9a0f Chris Mason           2008-10-29  194  		/* we need another page for writing out.  Test this
c8b978188c9a0f Chris Mason           2008-10-29  195  		 * before the total_in so we will pull in a new page for
c8b978188c9a0f Chris Mason           2008-10-29  196  		 * the stream end if required
c8b978188c9a0f Chris Mason           2008-10-29  197  		 */
7880991344f736 Sergey Senozhatsky    2014-07-07  198  		if (workspace->strm.avail_out == 0) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  199  			kunmap_local(cpage_out);
c8b978188c9a0f Chris Mason           2008-10-29  200  			if (nr_pages == nr_dest_pages) {
c8b978188c9a0f Chris Mason           2008-10-29  201  				out_page = NULL;
60e1975acb48fc Zach Brown            2014-05-09  202  				ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  203  				goto out;
c8b978188c9a0f Chris Mason           2008-10-29  204  			}
b0ee5e1ec44afd David Sterba          2021-06-14  205  			out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6b Li Zefan              2010-11-09  206  			if (out_page == NULL) {
60e1975acb48fc Zach Brown            2014-05-09  207  				ret = -ENOMEM;
4b72029dc3fd6b Li Zefan              2010-11-09  208  				goto out;
4b72029dc3fd6b Li Zefan              2010-11-09  209  			}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  210  			cpage_out = kmap_local_page(out_page);
c8b978188c9a0f Chris Mason           2008-10-29  211  			pages[nr_pages] = out_page;
c8b978188c9a0f Chris Mason           2008-10-29  212  			nr_pages++;
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  213  			workspace->strm.avail_out = PAGE_SIZE;
7880991344f736 Sergey Senozhatsky    2014-07-07  214  			workspace->strm.next_out = cpage_out;
c8b978188c9a0f Chris Mason           2008-10-29  215  		}
c8b978188c9a0f Chris Mason           2008-10-29  216  		/* we're all done */
7880991344f736 Sergey Senozhatsky    2014-07-07  217  		if (workspace->strm.total_in >= len)
c8b978188c9a0f Chris Mason           2008-10-29  218  			break;
7880991344f736 Sergey Senozhatsky    2014-07-07  219  		if (workspace->strm.total_out > max_out)
c8b978188c9a0f Chris Mason           2008-10-29  220  			break;
c8b978188c9a0f Chris Mason           2008-10-29  221  	}
7880991344f736 Sergey Senozhatsky    2014-07-07  222  	workspace->strm.avail_in = 0;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  223  	/*
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  224  	 * Call deflate with Z_FINISH flush parameter providing more output
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  225  	 * space but no more input data, until it returns with Z_STREAM_END.
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  226  	 */
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  227  	while (ret != Z_STREAM_END) {
7880991344f736 Sergey Senozhatsky    2014-07-07  228  		ret = zlib_deflate(&workspace->strm, Z_FINISH);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  229  		if (ret == Z_STREAM_END)
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  230  			break;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  231  		if (ret != Z_OK && ret != Z_BUF_ERROR) {
7880991344f736 Sergey Senozhatsky    2014-07-07  232  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc Zach Brown            2014-05-09  233  			ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  234  			goto out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  235  		} else if (workspace->strm.avail_out == 0) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  236  			/* get another page for the stream end */
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  237  			kunmap_local(cpage_out);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  238  			if (nr_pages == nr_dest_pages) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  239  				out_page = NULL;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  240  				ret = -E2BIG;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  241  				goto out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  242  			}
b0ee5e1ec44afd David Sterba          2021-06-14  243  			out_page = alloc_page(GFP_NOFS);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  244  			if (out_page == NULL) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  245  				ret = -ENOMEM;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  246  				goto out;
c8b978188c9a0f Chris Mason           2008-10-29  247  			}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  248  			cpage_out = kmap_local_page(out_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  249  			pages[nr_pages] = out_page;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  250  			nr_pages++;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  251  			workspace->strm.avail_out = PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  252  			workspace->strm.next_out = cpage_out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  253  		}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  254  	}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  255  	zlib_deflateEnd(&workspace->strm);
c8b978188c9a0f Chris Mason           2008-10-29  256  
7880991344f736 Sergey Senozhatsky    2014-07-07  257  	if (workspace->strm.total_out >= workspace->strm.total_in) {
60e1975acb48fc Zach Brown            2014-05-09  258  		ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  259  		goto out;
c8b978188c9a0f Chris Mason           2008-10-29  260  	}
c8b978188c9a0f Chris Mason           2008-10-29  261  
c8b978188c9a0f Chris Mason           2008-10-29  262  	ret = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  263  	*total_out = workspace->strm.total_out;
7880991344f736 Sergey Senozhatsky    2014-07-07  264  	*total_in = workspace->strm.total_in;
c8b978188c9a0f Chris Mason           2008-10-29  265  out:
c8b978188c9a0f Chris Mason           2008-10-29  266  	*out_pages = nr_pages;
a549d3a90067e8 Fabio M. De Francesco 2022-05-31 @267  	if (cpage_out)
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  268  		kunmap_local(cpage_out);
55276e14df4324 David Sterba          2021-10-27  269  
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  270  	if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  271  		kunmap_local(data_in);
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  272  		put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  273  	}
c8b978188c9a0f Chris Mason           2008-10-29  274  	return ret;
c8b978188c9a0f Chris Mason           2008-10-29  275  }
c8b978188c9a0f Chris Mason           2008-10-29  276  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-02 16:28   ` David Sterba
@ 2022-06-05 15:11     ` Fabio M. De Francesco
  2022-06-06 10:32       ` David Sterba
  0 siblings, 1 reply; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-06-05 15:11 UTC (permalink / raw)
  To: dsterba, Christoph Hellwig, Fabio M. De Francesco, Chris Mason,
	Josef Bacik, David Sterba, Ira Weiny, linux-btrfs, linux-kernel

On giovedì 2 giugno 2022 18:28:40 CEST David Sterba wrote:
> On Thu, Jun 02, 2022 at 08:20:08AM -0700, Christoph Hellwig wrote:
> > Turns out that while this looks good, it actually crashes when
> > running xfstests.  I think this is due to the fact that kmap sets
> > the page address, which kmap_local_page does not.
> > 
> > btrfs/150 1s ... [  168.252943] run fstests btrfs/150 at 2022-06-02 
15:17:11
> > [  169.462292] BTRFS info (device vdb): flagging fs with big metadata 
feature
> > [  169.463728] BTRFS info (device vdb): disk space caching is enabled
> > [  169.464953] BTRFS info (device vdb): has skinny extents
> > [  170.596218] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4
> > devid 1 transid 5 /dev)
> > [  170.599471] BTRFS: device fsid 37c6bae1-d3e5-47f8-87d5-87cd7240a1b4 
devid 2 transid 5 /dev)
> > [  170.657170] BTRFS info (device vdc): flagging fs with big metadata 
feature
> > [  170.659509] BTRFS info (device vdc): use zlib compression, level 3
> > [  170.661190] BTRFS info (device vdc): disk space caching is enabled
> > [  170.670706] BTRFS info (device vdc): has skinny extents
> > [  170.714181] BTRFS info (device vdc): checking UUID tree
> > [  170.735058] BUG: kernel NULL pointer dereference, address: 
0000000000000008
> > [  170.736478] #PF: supervisor read access in kernel mode
> > [  170.737457] #PF: error_code(0x0000) - not-present page
> > [  170.738529] PGD 0 P4D 0 
> > [  170.739211] Oops: 0000 [#1] PREEMPT SMP PTI
> > [  170.740101] CPU: 0 PID: 43 Comm: kworker/u4:3 Not tainted 5.18.0-
rc7+ #1539
> > [  170.741478] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), 
BIOS 1.14.0-2 04/01/2014
> > [  170.743246] Workqueue: btrfs-delalloc btrfs_work_helper
> > [  170.744282] RIP: 0010:zlib_compress_pages+0x128/0x670
> 
> I've just hit the crash too, so I've removed the patches from misc-next
> until there's fixed version.
> 
Finally I've been able to run xfstests on a QEMU + KVM 32 bits VM. Since I 
have very little experience with filesystems it was a bit hard to setup and 
run.

I can confirm that the problems are only from conversions in patch 3/3. 

Since I've been spending long time to setup xfstests and make it run, I 
haven't yet had time to address the issued in patch 3/3 and making the 
further changes I've been asked for.

Can you please start with taking only patches 1/3 and 2/3 and dropping 3/3?
I'd really appreciate it because, if you can, I'll see that part of my work 
has already been helpful somewhat and have no need to carry those patches 
on to the next series :-) 

The next series will contain everything it has been left out, so that it 
will complete the conversions to local mappings in fs/btrfs. However I will  
need some days more to be done with this task.

I'd like to share the output of xfstests on "compress" group + test 150 
(which is not in that group, although it is the test that both you and 
Christoph ran and which seems to be the only one failing).
 
tweed32:/usr/lib/xfstests # ./check -g compress
FSTYP         -- btrfs
PLATFORM      -- Linux/i686 tweed32 5.18.0-torvalds-debug-x86_32+ #7 SMP 
PREEMPT_DYNAMIC Sat Jun 4 23:47:27 CEST 2022
MKFS_OPTIONS  -- /dev/loop1
MOUNT_OPTIONS -- /dev/loop1 /mnt/scratch

btrfs/024 2s ...  6s
btrfs/026 5s ...  8s
btrfs/037 3s ...  5s
btrfs/038 3s ...  6s
btrfs/041 3s ...  5s
btrfs/062        39s
btrfs/063        21s
btrfs/067        34s
btrfs/068        12s
btrfs/070       [not run] btrfs and this test needs 5 or more disks in 
SCRATCH_DEV_POOL
btrfs/071       [not run] btrfs and this test needs 5 or more disks in 
SCRATCH_DEV_POOL
btrfs/072        37s
btrfs/073        22s
btrfs/074        39s
btrfs/076 2s ...  2s
btrfs/103 3s ...  3s
btrfs/106 3s ...  3s
btrfs/109 2s ...  3s
btrfs/113 3s ...  3s
btrfs/138 47s ...  48s
btrfs/149 3s ...  3s
btrfs/183 3s ...  3s
btrfs/205 3s ...  4s
btrfs/234 4s ...  5s
btrfs/246 3s ...  2s
btrfs/251 2s ...  3s
Ran: btrfs/024 btrfs/026 btrfs/037 btrfs/038 btrfs/041 btrfs/062 btrfs/063 
btrfs/067 btrfs/068 btrfs/070 btrfs/071 btrfs/072 btrfs/073 btrfs/074 
btrfs/076 btrfs/103 btrfs/106 btrfs/109 btrfs/113 btrfs/138 btrfs/149 
btrfs/183 btrfs/205 btrfs/234 btrfs/246 btrfs/251
Not run: btrfs/070 btrfs/071
Passed all 26 tests

tweed32:/usr/lib/xfstests # ./check tests/btrfs/150
FSTYP         -- btrfs
PLATFORM      -- Linux/i686 tweed32 5.18.0-torvalds-debug-x86_32+ #7 SMP 
PREEMPT_DYNAMIC Sat Jun 4 23:47:27 CEST 2022
MKFS_OPTIONS  -- /dev/loop1
MOUNT_OPTIONS -- /dev/loop1 /mnt/scratch

btrfs/150 2s ...  2s
Ran: btrfs/150
Passed all 1 tests

tweed32:/usr/lib/xfstests # cat results/btrfs/150.dmesg
[ 2461.321352] run fstests btrfs/150 at 2022-06-05 16:11:18
[ 2461.718527] BTRFS: device fsid 9337d043-0ca4-4890-b294-7e9505ee13b9 
devid 1 transid 6 /dev/loop1 scanned by systemd-udevd (31060)
[ 2461.721721] BTRFS: device fsid 9337d043-0ca4-4890-b294-7e9505ee13b9 
devid 2 transid 6 /dev/loop2 scanned by mkfs.btrfs (31508)
[ 2461.730540] BTRFS info (device loop1): flagging fs with big metadata 
feature
[ 2461.730543] BTRFS info (device loop1): use zlib compression, level 3
[ 2461.730544] BTRFS info (device loop1): using free space tree
[ 2461.730545] BTRFS info (device loop1): has skinny extents
[ 2461.739677] BTRFS info (device loop1): checking UUID tree
[ 2461.916511] BTRFS info (device loop1): flagging fs with big metadata 
feature
[ 2461.916515] BTRFS info (device loop1): using free space tree
[ 2461.916516] BTRFS info (device loop1): has skinny extents

Please let me know if you require further tests on patches 1/3 and 2/3 and 
on the next series.

Thanks,

Fabio

P.S.: The rest of this message has some details about the kernel and the 
CPU and memory of the VM these tests have been run on. I suppose these 
stats are not so much interesting, so feel free to skip them :-)

tweed32:/usr/lib/xfstests # uname -a
Linux tweed32 5.18.0-torvalds-debug-x86_32+ #7 SMP PREEMPT_DYNAMIC Sat Jun 
4 23:47:27 CEST 2022 i686 athlon i386 GNU/Linux

tweed32:/usr/lib/xfstests # cat /proc/cpuinfo 
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 6
model           : 6
model name      : QEMU Virtual CPU version 2.5+
stepping        : 3
microcode       : 0x1000065
cpu MHz         : 3699.978
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fdiv_bug        : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 4
wp              : yes
flags           : fpu de pse tsc msr pae mce cx8 apic sep pge cmov pat mmx 
fxsr sse sse2 cpuid tsc_known_freq pni x2apic hypervisor vmmcall
bugs            : fxsave_leak sysret_ss_attrs spectre_v1 spectre_v2 
spec_store_bypass
bogomips        : 7402.28
clflush size    : 32
cache_alignment : 32
address sizes   : 36 bits physical, 32 bits virtual
power management:

processor       : 1
vendor_id       : AuthenticAMD
cpu family      : 6
model           : 6
model name      : QEMU Virtual CPU version 2.5+

OK, no need to go on with the other CPUs. 
The total amount of virtual CPU is 4. 

tweed32:/usr/lib/xfstests # cat /proc/meminfo 
MemTotal:        4011272 kB
MemFree:         2949956 kB
MemAvailable:    3148368 kB
Buffers:           15700 kB
Cached:           298640 kB
SwapCached:            0 kB
Active:           115992 kB
Inactive:         727008 kB
Active(anon):      21300 kB
Inactive(anon):   538392 kB
Active(file):      94692 kB
Inactive(file):   188616 kB
Unevictable:        3088 kB
Mlocked:               0 kB
HighTotal:       3286900 kB <- Highmem looks enabled properly
HighFree:        2436812 kB
LowTotal:         724372 kB
LowFree:          513144 kB
SwapTotal:       2098152 kB
SwapFree:        2094536 kB
Dirty:               188 kB
Writeback:             0 kB
AnonPages:        531784 kB
Mapped:           218340 kB
Shmem:             31032 kB
KReclaimable:      63896 kB
Slab:             181828 kB
SReclaimable:      63896 kB
SUnreclaim:       117932 kB
KernelStack:        4280 kB
PageTables:        15992 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     4103788 kB
Committed_AS:    4012104 kB
VmallocTotal:     122880 kB
VmallocUsed:        1468 kB
VmallocChunk:          0 kB
Percpu:             6304 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      907256 kB
DirectMap2M:           0 kB



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-05 15:11     ` Fabio M. De Francesco
@ 2022-06-06 10:32       ` David Sterba
  2022-06-06 14:32         ` Fabio M. De Francesco
  0 siblings, 1 reply; 23+ messages in thread
From: David Sterba @ 2022-06-06 10:32 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: dsterba, Christoph Hellwig, Chris Mason, Josef Bacik,
	David Sterba, Ira Weiny, linux-btrfs, linux-kernel

On Sun, Jun 05, 2022 at 05:11:48PM +0200, Fabio M. De Francesco wrote:
> On giovedì 2 giugno 2022 18:28:40 CEST David Sterba wrote:
> > On Thu, Jun 02, 2022 at 08:20:08AM -0700, Christoph Hellwig wrote:
> > I've just hit the crash too, so I've removed the patches from misc-next
> > until there's fixed version.
> > 
> Finally I've been able to run xfstests on a QEMU + KVM 32 bits VM. Since I 
> have very little experience with filesystems it was a bit hard to setup and 
> run.
> 
> I can confirm that the problems are only from conversions in patch 3/3. 

Thanks.

> Since I've been spending long time to setup xfstests and make it run, I 
> haven't yet had time to address the issued in patch 3/3 and making the 
> further changes I've been asked for.
> 
> Can you please start with taking only patches 1/3 and 2/3 and dropping 3/3?
> I'd really appreciate it because, if you can, I'll see that part of my work 
> has already been helpful somewhat and have no need to carry those patches 
> on to the next series :-) 

Yes I can pick 1 and 2. Removing the whole series is needed in case it
crashes tests as it affects everybody.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
@ 2022-06-06 12:11 ` Dan Carpenter
  0 siblings, 0 replies; 23+ messages in thread
From: Dan Carpenter @ 2022-06-06 12:11 UTC (permalink / raw)
  To: kbuild, Fabio M. De Francesco, Chris Mason, Josef Bacik,
	David Sterba, Ira Weiny, linux-btrfs, linux-kernel
  Cc: lkp, kbuild-all, Fabio M. De Francesco

Hi "Fabio,

url:    https://github.com/intel-lab-lkp/linux/commits/Fabio-M-De-Francesco/btrfs-Replace-kmap-with-kmap_local_page/20220531-225557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20220603/202206030230.ttuhGnvx-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/zlib.c:151 zlib_compress_pages() error: uninitialized symbol 'data_in'.
fs/btrfs/zlib.c:267 zlib_compress_pages() error: uninitialized symbol 'cpage_out'.

Old smatch warnings:
fs/btrfs/zlib.c:164 zlib_compress_pages() error: uninitialized symbol 'data_in'.
fs/btrfs/zlib.c:227 zlib_compress_pages() error: uninitialized symbol 'ret'.
fs/btrfs/zlib.c:270 zlib_compress_pages() error: uninitialized symbol 'data_in'.

vim +/data_in +151 fs/btrfs/zlib.c

c8b978188c9a0f Chris Mason           2008-10-29   93  
c4bf665a319755 David Sterba          2019-10-01   94  int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
c4bf665a319755 David Sterba          2019-10-01   95  		u64 start, struct page **pages, unsigned long *out_pages,
c4bf665a319755 David Sterba          2019-10-01   96  		unsigned long *total_in, unsigned long *total_out)
c8b978188c9a0f Chris Mason           2008-10-29   97  {
261507a02ccba9 Li Zefan              2010-12-17   98  	struct workspace *workspace = list_entry(ws, struct workspace, list);
c8b978188c9a0f Chris Mason           2008-10-29   99  	int ret;
c8b978188c9a0f Chris Mason           2008-10-29  100  	char *data_in;
                                                              ^^^^^^^

c8b978188c9a0f Chris Mason           2008-10-29  101  	char *cpage_out;
c8b978188c9a0f Chris Mason           2008-10-29  102  	int nr_pages = 0;
c8b978188c9a0f Chris Mason           2008-10-29  103  	struct page *in_page = NULL;
c8b978188c9a0f Chris Mason           2008-10-29  104  	struct page *out_page = NULL;
c8b978188c9a0f Chris Mason           2008-10-29  105  	unsigned long bytes_left;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  106  	unsigned int in_buf_pages;
38c31464089f63 David Sterba          2017-02-14  107  	unsigned long len = *total_out;
4d3a800ebb1299 David Sterba          2017-02-14  108  	unsigned long nr_dest_pages = *out_pages;
e5d74902362f1a David Sterba          2017-02-14  109  	const unsigned long max_out = nr_dest_pages * PAGE_SIZE;
c8b978188c9a0f Chris Mason           2008-10-29  110  
c8b978188c9a0f Chris Mason           2008-10-29  111  	*out_pages = 0;
c8b978188c9a0f Chris Mason           2008-10-29  112  	*total_out = 0;
c8b978188c9a0f Chris Mason           2008-10-29  113  	*total_in = 0;
c8b978188c9a0f Chris Mason           2008-10-29  114  
f51d2b59120ff3 David Sterba          2017-09-15  115  	if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
62e855771dacf7 Jeff Mahoney          2016-09-20  116  		pr_warn("BTRFS: deflateInit failed\n");
60e1975acb48fc Zach Brown            2014-05-09  117  		ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  118  		goto out;

cpage_out is not initialized before the goto.

c8b978188c9a0f Chris Mason           2008-10-29  119  	}
c8b978188c9a0f Chris Mason           2008-10-29  120  
7880991344f736 Sergey Senozhatsky    2014-07-07  121  	workspace->strm.total_in = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  122  	workspace->strm.total_out = 0;
c8b978188c9a0f Chris Mason           2008-10-29  123  
b0ee5e1ec44afd David Sterba          2021-06-14  124  	out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6b Li Zefan              2010-11-09  125  	if (out_page == NULL) {
60e1975acb48fc Zach Brown            2014-05-09  126  		ret = -ENOMEM;
4b72029dc3fd6b Li Zefan              2010-11-09  127  		goto out;
4b72029dc3fd6b Li Zefan              2010-11-09  128  	}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  129  	cpage_out = kmap_local_page(out_page);
c8b978188c9a0f Chris Mason           2008-10-29  130  	pages[0] = out_page;
c8b978188c9a0f Chris Mason           2008-10-29  131  	nr_pages = 1;
c8b978188c9a0f Chris Mason           2008-10-29  132  
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  133  	workspace->strm.next_in = workspace->buf;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  134  	workspace->strm.avail_in = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  135  	workspace->strm.next_out = cpage_out;
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  136  	workspace->strm.avail_out = PAGE_SIZE;
c8b978188c9a0f Chris Mason           2008-10-29  137  
7880991344f736 Sergey Senozhatsky    2014-07-07  138  	while (workspace->strm.total_in < len) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  139  		/*
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  140  		 * Get next input pages and copy the contents to
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  141  		 * the workspace buffer if required.
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  142  		 */
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  143  		if (workspace->strm.avail_in == 0) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  144  			bytes_left = len - workspace->strm.total_in;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  145  			in_buf_pages = min(DIV_ROUND_UP(bytes_left, PAGE_SIZE),
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  146  					   workspace->buf_size / PAGE_SIZE);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  147  			if (in_buf_pages > 1) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  148  				int i;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  149  
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  150  				for (i = 0; i < in_buf_pages; i++) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31 @151  					if (data_in) {
                                                                                            ^^^^^^^
Uninitialized.

a549d3a90067e8 Fabio M. De Francesco 2022-05-31  152  						kunmap_local(data_in);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  153  						put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  154  					}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  155  					in_page = find_get_page(mapping,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  156  								start >> PAGE_SHIFT);
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  157  					data_in = kmap_local_page(in_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  158  					memcpy(workspace->buf + i * PAGE_SIZE,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  159  					       data_in, PAGE_SIZE);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  160  					start += PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  161  				}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  162  				workspace->strm.next_in = workspace->buf;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  163  			} else {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  164  				if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  165  					kunmap_local(data_in);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  166  					put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  167  				}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  168  				in_page = find_get_page(mapping,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  169  							start >> PAGE_SHIFT);
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  170  				data_in = kmap_local_page(in_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  171  				start += PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  172  				workspace->strm.next_in = data_in;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  173  			}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  174  			workspace->strm.avail_in = min(bytes_left,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  175  						       (unsigned long) workspace->buf_size);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  176  		}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  177  
7880991344f736 Sergey Senozhatsky    2014-07-07  178  		ret = zlib_deflate(&workspace->strm, Z_SYNC_FLUSH);
c8b978188c9a0f Chris Mason           2008-10-29  179  		if (ret != Z_OK) {
62e855771dacf7 Jeff Mahoney          2016-09-20  180  			pr_debug("BTRFS: deflate in loop returned %d\n",
c8b978188c9a0f Chris Mason           2008-10-29  181  			       ret);
7880991344f736 Sergey Senozhatsky    2014-07-07  182  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc Zach Brown            2014-05-09  183  			ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  184  			goto out;
c8b978188c9a0f Chris Mason           2008-10-29  185  		}
c8b978188c9a0f Chris Mason           2008-10-29  186  
c8b978188c9a0f Chris Mason           2008-10-29  187  		/* we're making it bigger, give up */
7880991344f736 Sergey Senozhatsky    2014-07-07  188  		if (workspace->strm.total_in > 8192 &&
7880991344f736 Sergey Senozhatsky    2014-07-07  189  		    workspace->strm.total_in <
7880991344f736 Sergey Senozhatsky    2014-07-07  190  		    workspace->strm.total_out) {
130d5b415a091e David Sterba          2014-06-20  191  			ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  192  			goto out;
c8b978188c9a0f Chris Mason           2008-10-29  193  		}
c8b978188c9a0f Chris Mason           2008-10-29  194  		/* we need another page for writing out.  Test this
c8b978188c9a0f Chris Mason           2008-10-29  195  		 * before the total_in so we will pull in a new page for
c8b978188c9a0f Chris Mason           2008-10-29  196  		 * the stream end if required
c8b978188c9a0f Chris Mason           2008-10-29  197  		 */
7880991344f736 Sergey Senozhatsky    2014-07-07  198  		if (workspace->strm.avail_out == 0) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  199  			kunmap_local(cpage_out);
c8b978188c9a0f Chris Mason           2008-10-29  200  			if (nr_pages == nr_dest_pages) {
c8b978188c9a0f Chris Mason           2008-10-29  201  				out_page = NULL;
60e1975acb48fc Zach Brown            2014-05-09  202  				ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  203  				goto out;
c8b978188c9a0f Chris Mason           2008-10-29  204  			}
b0ee5e1ec44afd David Sterba          2021-06-14  205  			out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6b Li Zefan              2010-11-09  206  			if (out_page == NULL) {
60e1975acb48fc Zach Brown            2014-05-09  207  				ret = -ENOMEM;
4b72029dc3fd6b Li Zefan              2010-11-09  208  				goto out;
4b72029dc3fd6b Li Zefan              2010-11-09  209  			}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  210  			cpage_out = kmap_local_page(out_page);
c8b978188c9a0f Chris Mason           2008-10-29  211  			pages[nr_pages] = out_page;
c8b978188c9a0f Chris Mason           2008-10-29  212  			nr_pages++;
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  213  			workspace->strm.avail_out = PAGE_SIZE;
7880991344f736 Sergey Senozhatsky    2014-07-07  214  			workspace->strm.next_out = cpage_out;
c8b978188c9a0f Chris Mason           2008-10-29  215  		}
c8b978188c9a0f Chris Mason           2008-10-29  216  		/* we're all done */
7880991344f736 Sergey Senozhatsky    2014-07-07  217  		if (workspace->strm.total_in >= len)
c8b978188c9a0f Chris Mason           2008-10-29  218  			break;
7880991344f736 Sergey Senozhatsky    2014-07-07  219  		if (workspace->strm.total_out > max_out)
c8b978188c9a0f Chris Mason           2008-10-29  220  			break;
c8b978188c9a0f Chris Mason           2008-10-29  221  	}
7880991344f736 Sergey Senozhatsky    2014-07-07  222  	workspace->strm.avail_in = 0;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  223  	/*
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  224  	 * Call deflate with Z_FINISH flush parameter providing more output
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  225  	 * space but no more input data, until it returns with Z_STREAM_END.
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  226  	 */
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  227  	while (ret != Z_STREAM_END) {
7880991344f736 Sergey Senozhatsky    2014-07-07  228  		ret = zlib_deflate(&workspace->strm, Z_FINISH);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  229  		if (ret == Z_STREAM_END)
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  230  			break;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  231  		if (ret != Z_OK && ret != Z_BUF_ERROR) {
7880991344f736 Sergey Senozhatsky    2014-07-07  232  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc Zach Brown            2014-05-09  233  			ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  234  			goto out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  235  		} else if (workspace->strm.avail_out == 0) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  236  			/* get another page for the stream end */
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  237  			kunmap_local(cpage_out);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  238  			if (nr_pages == nr_dest_pages) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  239  				out_page = NULL;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  240  				ret = -E2BIG;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  241  				goto out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  242  			}
b0ee5e1ec44afd David Sterba          2021-06-14  243  			out_page = alloc_page(GFP_NOFS);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  244  			if (out_page == NULL) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  245  				ret = -ENOMEM;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  246  				goto out;
c8b978188c9a0f Chris Mason           2008-10-29  247  			}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  248  			cpage_out = kmap_local_page(out_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  249  			pages[nr_pages] = out_page;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  250  			nr_pages++;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  251  			workspace->strm.avail_out = PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  252  			workspace->strm.next_out = cpage_out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  253  		}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  254  	}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  255  	zlib_deflateEnd(&workspace->strm);
c8b978188c9a0f Chris Mason           2008-10-29  256  
7880991344f736 Sergey Senozhatsky    2014-07-07  257  	if (workspace->strm.total_out >= workspace->strm.total_in) {
60e1975acb48fc Zach Brown            2014-05-09  258  		ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  259  		goto out;
c8b978188c9a0f Chris Mason           2008-10-29  260  	}
c8b978188c9a0f Chris Mason           2008-10-29  261  
c8b978188c9a0f Chris Mason           2008-10-29  262  	ret = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  263  	*total_out = workspace->strm.total_out;
7880991344f736 Sergey Senozhatsky    2014-07-07  264  	*total_in = workspace->strm.total_in;
c8b978188c9a0f Chris Mason           2008-10-29  265  out:
c8b978188c9a0f Chris Mason           2008-10-29  266  	*out_pages = nr_pages;
a549d3a90067e8 Fabio M. De Francesco 2022-05-31 @267  	if (cpage_out)
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  268  		kunmap_local(cpage_out);
55276e14df4324 David Sterba          2021-10-27  269  
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  270  	if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  271  		kunmap_local(data_in);
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  272  		put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  273  	}
c8b978188c9a0f Chris Mason           2008-10-29  274  	return ret;
c8b978188c9a0f Chris Mason           2008-10-29  275  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
@ 2022-06-06 12:11 ` Dan Carpenter
  0 siblings, 0 replies; 23+ messages in thread
From: Dan Carpenter @ 2022-06-06 12:11 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 16099 bytes --]

Hi "Fabio,

url:    https://github.com/intel-lab-lkp/linux/commits/Fabio-M-De-Francesco/btrfs-Replace-kmap-with-kmap_local_page/20220531-225557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20220603/202206030230.ttuhGnvx-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/zlib.c:151 zlib_compress_pages() error: uninitialized symbol 'data_in'.
fs/btrfs/zlib.c:267 zlib_compress_pages() error: uninitialized symbol 'cpage_out'.

Old smatch warnings:
fs/btrfs/zlib.c:164 zlib_compress_pages() error: uninitialized symbol 'data_in'.
fs/btrfs/zlib.c:227 zlib_compress_pages() error: uninitialized symbol 'ret'.
fs/btrfs/zlib.c:270 zlib_compress_pages() error: uninitialized symbol 'data_in'.

vim +/data_in +151 fs/btrfs/zlib.c

c8b978188c9a0f Chris Mason           2008-10-29   93  
c4bf665a319755 David Sterba          2019-10-01   94  int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
c4bf665a319755 David Sterba          2019-10-01   95  		u64 start, struct page **pages, unsigned long *out_pages,
c4bf665a319755 David Sterba          2019-10-01   96  		unsigned long *total_in, unsigned long *total_out)
c8b978188c9a0f Chris Mason           2008-10-29   97  {
261507a02ccba9 Li Zefan              2010-12-17   98  	struct workspace *workspace = list_entry(ws, struct workspace, list);
c8b978188c9a0f Chris Mason           2008-10-29   99  	int ret;
c8b978188c9a0f Chris Mason           2008-10-29  100  	char *data_in;
                                                              ^^^^^^^

c8b978188c9a0f Chris Mason           2008-10-29  101  	char *cpage_out;
c8b978188c9a0f Chris Mason           2008-10-29  102  	int nr_pages = 0;
c8b978188c9a0f Chris Mason           2008-10-29  103  	struct page *in_page = NULL;
c8b978188c9a0f Chris Mason           2008-10-29  104  	struct page *out_page = NULL;
c8b978188c9a0f Chris Mason           2008-10-29  105  	unsigned long bytes_left;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  106  	unsigned int in_buf_pages;
38c31464089f63 David Sterba          2017-02-14  107  	unsigned long len = *total_out;
4d3a800ebb1299 David Sterba          2017-02-14  108  	unsigned long nr_dest_pages = *out_pages;
e5d74902362f1a David Sterba          2017-02-14  109  	const unsigned long max_out = nr_dest_pages * PAGE_SIZE;
c8b978188c9a0f Chris Mason           2008-10-29  110  
c8b978188c9a0f Chris Mason           2008-10-29  111  	*out_pages = 0;
c8b978188c9a0f Chris Mason           2008-10-29  112  	*total_out = 0;
c8b978188c9a0f Chris Mason           2008-10-29  113  	*total_in = 0;
c8b978188c9a0f Chris Mason           2008-10-29  114  
f51d2b59120ff3 David Sterba          2017-09-15  115  	if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
62e855771dacf7 Jeff Mahoney          2016-09-20  116  		pr_warn("BTRFS: deflateInit failed\n");
60e1975acb48fc Zach Brown            2014-05-09  117  		ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  118  		goto out;

cpage_out is not initialized before the goto.

c8b978188c9a0f Chris Mason           2008-10-29  119  	}
c8b978188c9a0f Chris Mason           2008-10-29  120  
7880991344f736 Sergey Senozhatsky    2014-07-07  121  	workspace->strm.total_in = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  122  	workspace->strm.total_out = 0;
c8b978188c9a0f Chris Mason           2008-10-29  123  
b0ee5e1ec44afd David Sterba          2021-06-14  124  	out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6b Li Zefan              2010-11-09  125  	if (out_page == NULL) {
60e1975acb48fc Zach Brown            2014-05-09  126  		ret = -ENOMEM;
4b72029dc3fd6b Li Zefan              2010-11-09  127  		goto out;
4b72029dc3fd6b Li Zefan              2010-11-09  128  	}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  129  	cpage_out = kmap_local_page(out_page);
c8b978188c9a0f Chris Mason           2008-10-29  130  	pages[0] = out_page;
c8b978188c9a0f Chris Mason           2008-10-29  131  	nr_pages = 1;
c8b978188c9a0f Chris Mason           2008-10-29  132  
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  133  	workspace->strm.next_in = workspace->buf;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  134  	workspace->strm.avail_in = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  135  	workspace->strm.next_out = cpage_out;
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  136  	workspace->strm.avail_out = PAGE_SIZE;
c8b978188c9a0f Chris Mason           2008-10-29  137  
7880991344f736 Sergey Senozhatsky    2014-07-07  138  	while (workspace->strm.total_in < len) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  139  		/*
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  140  		 * Get next input pages and copy the contents to
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  141  		 * the workspace buffer if required.
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  142  		 */
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  143  		if (workspace->strm.avail_in == 0) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  144  			bytes_left = len - workspace->strm.total_in;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  145  			in_buf_pages = min(DIV_ROUND_UP(bytes_left, PAGE_SIZE),
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  146  					   workspace->buf_size / PAGE_SIZE);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  147  			if (in_buf_pages > 1) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  148  				int i;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  149  
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  150  				for (i = 0; i < in_buf_pages; i++) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31 @151  					if (data_in) {
                                                                                            ^^^^^^^
Uninitialized.

a549d3a90067e8 Fabio M. De Francesco 2022-05-31  152  						kunmap_local(data_in);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  153  						put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  154  					}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  155  					in_page = find_get_page(mapping,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  156  								start >> PAGE_SHIFT);
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  157  					data_in = kmap_local_page(in_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  158  					memcpy(workspace->buf + i * PAGE_SIZE,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  159  					       data_in, PAGE_SIZE);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  160  					start += PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  161  				}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  162  				workspace->strm.next_in = workspace->buf;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  163  			} else {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  164  				if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  165  					kunmap_local(data_in);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  166  					put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  167  				}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  168  				in_page = find_get_page(mapping,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  169  							start >> PAGE_SHIFT);
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  170  				data_in = kmap_local_page(in_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  171  				start += PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  172  				workspace->strm.next_in = data_in;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  173  			}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  174  			workspace->strm.avail_in = min(bytes_left,
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  175  						       (unsigned long) workspace->buf_size);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  176  		}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  177  
7880991344f736 Sergey Senozhatsky    2014-07-07  178  		ret = zlib_deflate(&workspace->strm, Z_SYNC_FLUSH);
c8b978188c9a0f Chris Mason           2008-10-29  179  		if (ret != Z_OK) {
62e855771dacf7 Jeff Mahoney          2016-09-20  180  			pr_debug("BTRFS: deflate in loop returned %d\n",
c8b978188c9a0f Chris Mason           2008-10-29  181  			       ret);
7880991344f736 Sergey Senozhatsky    2014-07-07  182  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc Zach Brown            2014-05-09  183  			ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  184  			goto out;
c8b978188c9a0f Chris Mason           2008-10-29  185  		}
c8b978188c9a0f Chris Mason           2008-10-29  186  
c8b978188c9a0f Chris Mason           2008-10-29  187  		/* we're making it bigger, give up */
7880991344f736 Sergey Senozhatsky    2014-07-07  188  		if (workspace->strm.total_in > 8192 &&
7880991344f736 Sergey Senozhatsky    2014-07-07  189  		    workspace->strm.total_in <
7880991344f736 Sergey Senozhatsky    2014-07-07  190  		    workspace->strm.total_out) {
130d5b415a091e David Sterba          2014-06-20  191  			ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  192  			goto out;
c8b978188c9a0f Chris Mason           2008-10-29  193  		}
c8b978188c9a0f Chris Mason           2008-10-29  194  		/* we need another page for writing out.  Test this
c8b978188c9a0f Chris Mason           2008-10-29  195  		 * before the total_in so we will pull in a new page for
c8b978188c9a0f Chris Mason           2008-10-29  196  		 * the stream end if required
c8b978188c9a0f Chris Mason           2008-10-29  197  		 */
7880991344f736 Sergey Senozhatsky    2014-07-07  198  		if (workspace->strm.avail_out == 0) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  199  			kunmap_local(cpage_out);
c8b978188c9a0f Chris Mason           2008-10-29  200  			if (nr_pages == nr_dest_pages) {
c8b978188c9a0f Chris Mason           2008-10-29  201  				out_page = NULL;
60e1975acb48fc Zach Brown            2014-05-09  202  				ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  203  				goto out;
c8b978188c9a0f Chris Mason           2008-10-29  204  			}
b0ee5e1ec44afd David Sterba          2021-06-14  205  			out_page = alloc_page(GFP_NOFS);
4b72029dc3fd6b Li Zefan              2010-11-09  206  			if (out_page == NULL) {
60e1975acb48fc Zach Brown            2014-05-09  207  				ret = -ENOMEM;
4b72029dc3fd6b Li Zefan              2010-11-09  208  				goto out;
4b72029dc3fd6b Li Zefan              2010-11-09  209  			}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  210  			cpage_out = kmap_local_page(out_page);
c8b978188c9a0f Chris Mason           2008-10-29  211  			pages[nr_pages] = out_page;
c8b978188c9a0f Chris Mason           2008-10-29  212  			nr_pages++;
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  213  			workspace->strm.avail_out = PAGE_SIZE;
7880991344f736 Sergey Senozhatsky    2014-07-07  214  			workspace->strm.next_out = cpage_out;
c8b978188c9a0f Chris Mason           2008-10-29  215  		}
c8b978188c9a0f Chris Mason           2008-10-29  216  		/* we're all done */
7880991344f736 Sergey Senozhatsky    2014-07-07  217  		if (workspace->strm.total_in >= len)
c8b978188c9a0f Chris Mason           2008-10-29  218  			break;
7880991344f736 Sergey Senozhatsky    2014-07-07  219  		if (workspace->strm.total_out > max_out)
c8b978188c9a0f Chris Mason           2008-10-29  220  			break;
c8b978188c9a0f Chris Mason           2008-10-29  221  	}
7880991344f736 Sergey Senozhatsky    2014-07-07  222  	workspace->strm.avail_in = 0;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  223  	/*
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  224  	 * Call deflate with Z_FINISH flush parameter providing more output
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  225  	 * space but no more input data, until it returns with Z_STREAM_END.
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  226  	 */
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  227  	while (ret != Z_STREAM_END) {
7880991344f736 Sergey Senozhatsky    2014-07-07  228  		ret = zlib_deflate(&workspace->strm, Z_FINISH);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  229  		if (ret == Z_STREAM_END)
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  230  			break;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  231  		if (ret != Z_OK && ret != Z_BUF_ERROR) {
7880991344f736 Sergey Senozhatsky    2014-07-07  232  			zlib_deflateEnd(&workspace->strm);
60e1975acb48fc Zach Brown            2014-05-09  233  			ret = -EIO;
c8b978188c9a0f Chris Mason           2008-10-29  234  			goto out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  235  		} else if (workspace->strm.avail_out == 0) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  236  			/* get another page for the stream end */
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  237  			kunmap_local(cpage_out);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  238  			if (nr_pages == nr_dest_pages) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  239  				out_page = NULL;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  240  				ret = -E2BIG;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  241  				goto out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  242  			}
b0ee5e1ec44afd David Sterba          2021-06-14  243  			out_page = alloc_page(GFP_NOFS);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  244  			if (out_page == NULL) {
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  245  				ret = -ENOMEM;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  246  				goto out;
c8b978188c9a0f Chris Mason           2008-10-29  247  			}
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  248  			cpage_out = kmap_local_page(out_page);
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  249  			pages[nr_pages] = out_page;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  250  			nr_pages++;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  251  			workspace->strm.avail_out = PAGE_SIZE;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  252  			workspace->strm.next_out = cpage_out;
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  253  		}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  254  	}
3fd396afc05fc9 Mikhail Zaslonko      2020-01-30  255  	zlib_deflateEnd(&workspace->strm);
c8b978188c9a0f Chris Mason           2008-10-29  256  
7880991344f736 Sergey Senozhatsky    2014-07-07  257  	if (workspace->strm.total_out >= workspace->strm.total_in) {
60e1975acb48fc Zach Brown            2014-05-09  258  		ret = -E2BIG;
c8b978188c9a0f Chris Mason           2008-10-29  259  		goto out;
c8b978188c9a0f Chris Mason           2008-10-29  260  	}
c8b978188c9a0f Chris Mason           2008-10-29  261  
c8b978188c9a0f Chris Mason           2008-10-29  262  	ret = 0;
7880991344f736 Sergey Senozhatsky    2014-07-07  263  	*total_out = workspace->strm.total_out;
7880991344f736 Sergey Senozhatsky    2014-07-07  264  	*total_in = workspace->strm.total_in;
c8b978188c9a0f Chris Mason           2008-10-29  265  out:
c8b978188c9a0f Chris Mason           2008-10-29  266  	*out_pages = nr_pages;
a549d3a90067e8 Fabio M. De Francesco 2022-05-31 @267  	if (cpage_out)
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  268  		kunmap_local(cpage_out);
55276e14df4324 David Sterba          2021-10-27  269  
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  270  	if (data_in) {
a549d3a90067e8 Fabio M. De Francesco 2022-05-31  271  		kunmap_local(data_in);
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  272  		put_page(in_page);
55276e14df4324 David Sterba          2021-10-27  273  	}
c8b978188c9a0f Chris Mason           2008-10-29  274  	return ret;
c8b978188c9a0f Chris Mason           2008-10-29  275  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page()
  2022-06-06 10:32       ` David Sterba
@ 2022-06-06 14:32         ` Fabio M. De Francesco
  0 siblings, 0 replies; 23+ messages in thread
From: Fabio M. De Francesco @ 2022-06-06 14:32 UTC (permalink / raw)
  To: dsterba, Fabio M. De Francesco, Christoph Hellwig, Chris Mason,
	Josef Bacik, David Sterba, Ira Weiny, linux-btrfs, linux-kernel

On lunedì 6 giugno 2022 12:32:44 CEST David Sterba wrote:
>
> [snip] 
> 
> Yes I can pick 1 and 2. Removing the whole series is needed in case it
> crashes tests as it affects everybody.
> 
Thanks!

If everything goes smoothly, you will receive the remaining conversions 
within the next days. I still have to make several of them  (both from 
kmap() as well as from kmap_local()) and the ones already done and placed 
in my queue still need to be properly tested.

Again, thanks,

Fabio




^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2022-06-06 14:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 14:53 [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
2022-05-31 14:53 ` [PATCH 1/3] btrfs: Replace kmap() with kmap_local_page() in inode.c Fabio M. De Francesco
2022-05-31 15:46   ` Christoph Hellwig
2022-05-31 14:53 ` [PATCH 2/3] btrfs: Replace kmap() with kmap_local_page() in lzo.c Fabio M. De Francesco
2022-05-31 15:53   ` Christoph Hellwig
2022-05-31 14:53 ` [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c Fabio M. De Francesco
2022-05-31 15:53   ` Christoph Hellwig
2022-05-31 20:35   ` kernel test robot
2022-06-01 19:57     ` Fabio M. De Francesco
2022-06-01 19:57       ` Fabio M. De Francesco
2022-06-01 13:25 ` [PATCH 0/3] btrfs: Replace kmap() with kmap_local_page() David Sterba
2022-06-02 16:22   ` Ira Weiny
2022-06-02 16:46     ` Matthew Wilcox
2022-06-02 18:01   ` Fabio M. De Francesco
2022-06-02 15:20 ` Christoph Hellwig
2022-06-02 15:55   ` Ira Weiny
2022-06-02 16:28   ` David Sterba
2022-06-05 15:11     ` Fabio M. De Francesco
2022-06-06 10:32       ` David Sterba
2022-06-06 14:32         ` Fabio M. De Francesco
2022-06-02 18:59 [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c kernel test robot
2022-06-06 12:11 ` Dan Carpenter
2022-06-06 12:11 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.