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; 24+ 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] 24+ messages in thread
* Re: [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c
@ 2022-06-02  1:53 kernel test robot
  0 siblings, 0 replies; 24+ messages in thread
From: kernel test robot @ 2022-06-02  1:53 UTC (permalink / raw)
  To: kbuild

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

:::::: 
:::::: Manual check reason: "low confidence static check warning: fs/btrfs/zlib.c:151:10: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]"
:::::: 

CC: llvm(a)lists.linux.dev
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-20220601]
[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: 35 hours ago
:::::: commit date: 35 hours ago
config: mips-randconfig-c004-20220531 (https://download.01.org/0day-ci/archive/20220602/202206020905.Tu4jT2D3-lkp(a)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
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mipsel-linux-gnu
        # 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
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips clang-analyzer 

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


clang-analyzer warnings: (new ones prefixed by >>)
           ^~~~~~
   drivers/md/dm-crypt.c:2619:2: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
           memset(key, '0', key_string_len);
           ^~~~~~
   drivers/md/dm-crypt.c:2641:2: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           memset(&cc->key, 0, cc->key_size * sizeof(u8));
           ^~~~~~
   drivers/md/dm-crypt.c:2641:2: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
           memset(&cc->key, 0, cc->key_size * sizeof(u8));
           ^~~~~~
   drivers/md/dm-crypt.c:2832:2: warning: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           strncpy(mac_alg, start, end - start);
           ^~~~~~~
   drivers/md/dm-crypt.c:2832:2: note: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11
           strncpy(mac_alg, start, end - start);
           ^~~~~~~
   drivers/md/dm-crypt.c:2897:9: warning: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   ret = snprintf(buf, CRYPTO_MAX_ALG_NAME, "essiv(%s,%s)",
                         ^~~~~~~~
   drivers/md/dm-crypt.c:2897:9: note: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11
                   ret = snprintf(buf, CRYPTO_MAX_ALG_NAME, "essiv(%s,%s)",
                         ^~~~~~~~
   drivers/md/dm-crypt.c:2947:11: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           else if (sscanf(keycount, "%u%c", &cc->tfms_count, &dummy) != 1 ||
                    ^~~~~~
   drivers/md/dm-crypt.c:2947:11: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
           else if (sscanf(keycount, "%u%c", &cc->tfms_count, &dummy) != 1 ||
                    ^~~~~~
   drivers/md/dm-crypt.c:2982:9: warning: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME,
                         ^~~~~~~~
   drivers/md/dm-crypt.c:2982:9: note: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11
                   ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME,
                         ^~~~~~~~
   drivers/md/dm-crypt.c:2985:9: warning: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME,
                         ^~~~~~~~
   drivers/md/dm-crypt.c:2985:9: note: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11
                   ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME,
                         ^~~~~~~~
   drivers/md/dm-crypt.c:3059:3: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   memset(cc->key, 0, cc->key_size * sizeof(u8));
                   ^~~~~~
   drivers/md/dm-crypt.c:3059:3: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
                   memset(cc->key, 0, cc->key_size * sizeof(u8));
                   ^~~~~~
   drivers/md/dm-crypt.c:3103:12: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   else if (sscanf(opt_string, "integrity:%u:", &val) == 1) {
                            ^~~~~~
   drivers/md/dm-crypt.c:3103:12: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
                   else if (sscanf(opt_string, "integrity:%u:", &val) == 1) {
                            ^~~~~~
   drivers/md/dm-crypt.c:3120:14: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   } else if (sscanf(opt_string, "sector_size:%hu%c", &cc->sector_size, &dummy) == 1) {
                              ^~~~~~
   drivers/md/dm-crypt.c:3120:14: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
                   } else if (sscanf(opt_string, "sector_size:%hu%c", &cc->sector_size, &dummy) == 1) {
                              ^~~~~~
   drivers/md/dm-crypt.c:3270:7: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           if ((sscanf(argv[2], "%llu%c", &tmpll, &dummy) != 1) ||
                ^~~~~~
   drivers/md/dm-crypt.c:3270:7: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
           if ((sscanf(argv[2], "%llu%c", &tmpll, &dummy) != 1) ||
                ^~~~~~
   drivers/md/dm-crypt.c:3284:6: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) {
               ^~~~~~
   drivers/md/dm-crypt.c:3284:6: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
           if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) {
               ^~~~~~
   drivers/md/dm-crypt.c:3577:5: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                                   memset(argv[2], '0', strlen(argv[2]));
                                   ^~~~~~
   drivers/md/dm-crypt.c:3577:5: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
                                   memset(argv[2], '0', strlen(argv[2]));
                                   ^~~~~~
   drivers/md/dm-crypt.c:3588:5: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                                   memset(cc->key, 0, cc->key_size * sizeof(u8));
                                   ^~~~~~
   drivers/md/dm-crypt.c:3588:5: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
                                   memset(cc->key, 0, cc->key_size * sizeof(u8));
                                   ^~~~~~
   Suppressed 60 warnings (60 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   45 warnings generated.
   fs/btrfs/free-space-cache.c:385:2: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           memset(io_ctl, 0, sizeof(struct btrfs_io_ctl));
           ^~~~~~
   fs/btrfs/free-space-cache.c:385:2: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
           memset(io_ctl, 0, sizeof(struct btrfs_io_ctl));
           ^~~~~~
   fs/btrfs/free-space-cache.c:755:2: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
           ret = -1;
           ^     ~~
   fs/btrfs/free-space-cache.c:755:2: note: Value stored to 'ret' is never read
           ret = -1;
           ^     ~~
   Suppressed 43 warnings (43 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   48 warnings generated.
>> fs/btrfs/zlib.c:151:10: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
                                           if (data_in) {
                                               ^~~~~~~
   fs/btrfs/zlib.c:100:2: note: 'data_in' declared without an initial value
           char *data_in;
           ^~~~~~~~~~~~~
   fs/btrfs/zlib.c:115:6: note: Assuming the condition is false
           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:115:2: note: Taking false branch
           if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
           ^
   fs/btrfs/zlib.c:125:6: note: Assuming 'out_page' is not equal to NULL
           if (out_page == NULL) {
               ^~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:125:2: note: Taking false branch
           if (out_page == NULL) {
           ^
   fs/btrfs/zlib.c:138:9: note: Assuming 'len' is > field 'total_in'
           while (workspace->strm.total_in < len) {
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:138:2: note: Loop condition is true.  Entering loop body
           while (workspace->strm.total_in < len) {
           ^
   fs/btrfs/zlib.c:143:23: note: Field 'avail_in' is equal to 0
                   if (workspace->strm.avail_in == 0) {
                                       ^
   fs/btrfs/zlib.c:143:3: note: Taking true branch
                   if (workspace->strm.avail_in == 0) {
                   ^
   fs/btrfs/zlib.c:145:19: note: Assuming '__UNIQUE_ID___x270' is >= '__UNIQUE_ID___y271'
                           in_buf_pages = min(DIV_ROUND_UP(bytes_left, PAGE_SIZE),
                                          ^
   include/linux/minmax.h:45:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:38:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:33:3: note: expanded from macro '__cmp_once'
                   __cmp(unique_x, unique_y, op); })
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:28:26: note: expanded from macro '__cmp'
   #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
                            ^~~~~~~~~~
   fs/btrfs/zlib.c:145:19: note: '?' condition is false
                           in_buf_pages = min(DIV_ROUND_UP(bytes_left, PAGE_SIZE),
                                          ^
   include/linux/minmax.h:45:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^
   include/linux/minmax.h:38:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
                   ^
   include/linux/minmax.h:33:3: note: expanded from macro '__cmp_once'
                   __cmp(unique_x, unique_y, op); })
                   ^
   include/linux/minmax.h:28:26: note: expanded from macro '__cmp'
   #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
                            ^
   fs/btrfs/zlib.c:147:8: note: Assuming 'in_buf_pages' is > 1
                           if (in_buf_pages > 1) {
                               ^~~~~~~~~~~~~~~~
   fs/btrfs/zlib.c:147:4: note: Taking true branch
                           if (in_buf_pages > 1) {
                           ^
   fs/btrfs/zlib.c:150:17: note: 'i' is < 'in_buf_pages'
                                   for (i = 0; i < in_buf_pages; i++) {
                                               ^
   fs/btrfs/zlib.c:150:5: note: Loop condition is true.  Entering loop body
                                   for (i = 0; i < in_buf_pages; i++) {
                                   ^
   fs/btrfs/zlib.c:151:10: note: Branch condition evaluates to a garbage value
                                           if (data_in) {
                                               ^~~~~~~
   fs/btrfs/zlib.c:158:6: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                                           memcpy(workspace->buf + i * PAGE_SIZE,
                                           ^~~~~~
   fs/btrfs/zlib.c:158:6: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                                           memcpy(workspace->buf + i * PAGE_SIZE,
                                           ^~~~~~
   fs/btrfs/zlib.c:164:9: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
                                   if (data_in) {
                                       ^~~~~~~
   fs/btrfs/zlib.c:100:2: note: 'data_in' declared without an initial value
           char *data_in;
           ^~~~~~~~~~~~~
   fs/btrfs/zlib.c:115:6: note: Assuming the condition is false
           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:115:2: note: Taking false branch
           if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
           ^
   fs/btrfs/zlib.c:125:6: note: Assuming 'out_page' is not equal to NULL
           if (out_page == NULL) {

vim +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] 24+ 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; 24+ 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] 24+ messages in thread

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

Thread overview: 24+ 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  1:53 [PATCH 3/3] btrfs: Replace kmap() with kmap_local_page() in zlib.c kernel test robot
2022-06-02 18:59 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.