CC: [email protected] CC: Linux Memory Management List <[email protected]> TO: Tian Tao <[email protected]> CC: Nathan Chancellor <[email protected]> CC: Colin Ian King <[email protected]> CC: Vitaly Wool <[email protected]> CC: Andrew Morton <[email protected]> CC: Linux Memory Management List <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: 37dfbfbdca66834bc0f64ec9b35e09ac6c8898da commit: 52b41f44f603e5cf55056adf18087238fe146721 [11571/12022] mm/zswap: add the flag can_sleep_mapped :::::: branch date: 11 hours ago :::::: commit date: 4 days ago config: x86_64-randconfig-m001-20210222 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> smatch warnings: mm/zswap.c:1056 zswap_writeback_entry() warn: possible memory leak of 'tmp' mm/zswap.c:1323 zswap_frontswap_load() warn: possible memory leak of 'tmp' vim +/tmp +1056 mm/zswap.c 2b2811178e8555 Seth Jennings 2013-07-10 914 2b2811178e8555 Seth Jennings 2013-07-10 915 /* 2b2811178e8555 Seth Jennings 2013-07-10 916 * Attempts to free an entry by adding a page to the swap cache, 2b2811178e8555 Seth Jennings 2013-07-10 917 * decompressing the entry data into the page, and issuing a 2b2811178e8555 Seth Jennings 2013-07-10 918 * bio write to write the page back to the swap device. 2b2811178e8555 Seth Jennings 2013-07-10 919 * 2b2811178e8555 Seth Jennings 2013-07-10 920 * This can be thought of as a "resumed writeback" of the page 2b2811178e8555 Seth Jennings 2013-07-10 921 * to the swap device. We are basically resuming the same swap 2b2811178e8555 Seth Jennings 2013-07-10 922 * writeback path that was intercepted with the frontswap_store() 2b2811178e8555 Seth Jennings 2013-07-10 923 * in the first place. After the page has been decompressed into 2b2811178e8555 Seth Jennings 2013-07-10 924 * the swap cache, the compressed version stored by zswap can be 2b2811178e8555 Seth Jennings 2013-07-10 925 * freed. 2b2811178e8555 Seth Jennings 2013-07-10 926 */ 12d79d64bfd391 Dan Streetman 2014-08-06 927 static int zswap_writeback_entry(struct zpool *pool, unsigned long handle) 2b2811178e8555 Seth Jennings 2013-07-10 928 { 2b2811178e8555 Seth Jennings 2013-07-10 929 struct zswap_header *zhdr; 2b2811178e8555 Seth Jennings 2013-07-10 930 swp_entry_t swpentry; 2b2811178e8555 Seth Jennings 2013-07-10 931 struct zswap_tree *tree; 2b2811178e8555 Seth Jennings 2013-07-10 932 pgoff_t offset; 2b2811178e8555 Seth Jennings 2013-07-10 933 struct zswap_entry *entry; 2b2811178e8555 Seth Jennings 2013-07-10 934 struct page *page; 1ec3b5fe6eec78 Barry Song 2020-12-14 935 struct scatterlist input, output; 1ec3b5fe6eec78 Barry Song 2020-12-14 936 struct crypto_acomp_ctx *acomp_ctx; 1ec3b5fe6eec78 Barry Song 2020-12-14 937 52b41f44f603e5 Tian Tao 2021-02-19 938 u8 *src, *tmp = NULL; 2b2811178e8555 Seth Jennings 2013-07-10 939 unsigned int dlen; 0ab0abcf511545 Weijie Yang 2013-11-12 940 int ret; 2b2811178e8555 Seth Jennings 2013-07-10 941 struct writeback_control wbc = { 2b2811178e8555 Seth Jennings 2013-07-10 942 .sync_mode = WB_SYNC_NONE, 2b2811178e8555 Seth Jennings 2013-07-10 943 }; 2b2811178e8555 Seth Jennings 2013-07-10 944 52b41f44f603e5 Tian Tao 2021-02-19 945 if (!zpool_can_sleep_mapped(pool)) { 52b41f44f603e5 Tian Tao 2021-02-19 946 tmp = kmalloc(PAGE_SIZE, GFP_ATOMIC); 52b41f44f603e5 Tian Tao 2021-02-19 947 if (!tmp) 52b41f44f603e5 Tian Tao 2021-02-19 948 return -ENOMEM; 52b41f44f603e5 Tian Tao 2021-02-19 949 } 52b41f44f603e5 Tian Tao 2021-02-19 950 2b2811178e8555 Seth Jennings 2013-07-10 951 /* extract swpentry from data */ 12d79d64bfd391 Dan Streetman 2014-08-06 952 zhdr = zpool_map_handle(pool, handle, ZPOOL_MM_RO); 2b2811178e8555 Seth Jennings 2013-07-10 953 swpentry = zhdr->swpentry; /* here */ 2b2811178e8555 Seth Jennings 2013-07-10 954 tree = zswap_trees[swp_type(swpentry)]; 2b2811178e8555 Seth Jennings 2013-07-10 955 offset = swp_offset(swpentry); 2b2811178e8555 Seth Jennings 2013-07-10 956 2b2811178e8555 Seth Jennings 2013-07-10 957 /* find and ref zswap entry */ 2b2811178e8555 Seth Jennings 2013-07-10 958 spin_lock(&tree->lock); 0ab0abcf511545 Weijie Yang 2013-11-12 959 entry = zswap_entry_find_get(&tree->rbroot, offset); 2b2811178e8555 Seth Jennings 2013-07-10 960 if (!entry) { 2b2811178e8555 Seth Jennings 2013-07-10 961 /* entry was invalidated */ 2b2811178e8555 Seth Jennings 2013-07-10 962 spin_unlock(&tree->lock); 068619e32ff622 Vitaly Wool 2019-09-23 963 zpool_unmap_handle(pool, handle); 52b41f44f603e5 Tian Tao 2021-02-19 964 kfree(tmp); 2b2811178e8555 Seth Jennings 2013-07-10 965 return 0; 2b2811178e8555 Seth Jennings 2013-07-10 966 } 2b2811178e8555 Seth Jennings 2013-07-10 967 spin_unlock(&tree->lock); 2b2811178e8555 Seth Jennings 2013-07-10 968 BUG_ON(offset != entry->offset); 2b2811178e8555 Seth Jennings 2013-07-10 969 2b2811178e8555 Seth Jennings 2013-07-10 970 /* try to allocate swap cache page */ 2b2811178e8555 Seth Jennings 2013-07-10 971 switch (zswap_get_swap_cache_page(swpentry, &page)) { 67d13fe846c57a Weijie Yang 2013-11-12 972 case ZSWAP_SWAPCACHE_FAIL: /* no memory or invalidate happened */ 2b2811178e8555 Seth Jennings 2013-07-10 973 ret = -ENOMEM; 2b2811178e8555 Seth Jennings 2013-07-10 974 goto fail; 2b2811178e8555 Seth Jennings 2013-07-10 975 67d13fe846c57a Weijie Yang 2013-11-12 976 case ZSWAP_SWAPCACHE_EXIST: 2b2811178e8555 Seth Jennings 2013-07-10 977 /* page is already in the swap cache, ignore for now */ 09cbfeaf1a5a67 Kirill A. Shutemov 2016-04-01 978 put_page(page); 2b2811178e8555 Seth Jennings 2013-07-10 979 ret = -EEXIST; 2b2811178e8555 Seth Jennings 2013-07-10 980 goto fail; 2b2811178e8555 Seth Jennings 2013-07-10 981 2b2811178e8555 Seth Jennings 2013-07-10 982 case ZSWAP_SWAPCACHE_NEW: /* page is locked */ 2b2811178e8555 Seth Jennings 2013-07-10 983 /* decompress */ 1ec3b5fe6eec78 Barry Song 2020-12-14 984 acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); 1ec3b5fe6eec78 Barry Song 2020-12-14 985 2b2811178e8555 Seth Jennings 2013-07-10 986 dlen = PAGE_SIZE; 068619e32ff622 Vitaly Wool 2019-09-23 987 src = (u8 *)zhdr + sizeof(struct zswap_header); 1ec3b5fe6eec78 Barry Song 2020-12-14 988 52b41f44f603e5 Tian Tao 2021-02-19 989 if (!zpool_can_sleep_mapped(pool)) { 52b41f44f603e5 Tian Tao 2021-02-19 990 52b41f44f603e5 Tian Tao 2021-02-19 991 memcpy(tmp, src, entry->length); 52b41f44f603e5 Tian Tao 2021-02-19 992 src = tmp; 52b41f44f603e5 Tian Tao 2021-02-19 993 52b41f44f603e5 Tian Tao 2021-02-19 994 zpool_unmap_handle(pool, handle); 52b41f44f603e5 Tian Tao 2021-02-19 995 } 52b41f44f603e5 Tian Tao 2021-02-19 996 1ec3b5fe6eec78 Barry Song 2020-12-14 997 mutex_lock(acomp_ctx->mutex); 1ec3b5fe6eec78 Barry Song 2020-12-14 998 sg_init_one(&input, src, entry->length); 1ec3b5fe6eec78 Barry Song 2020-12-14 999 sg_init_table(&output, 1); 1ec3b5fe6eec78 Barry Song 2020-12-14 1000 sg_set_page(&output, page, PAGE_SIZE, 0); 1ec3b5fe6eec78 Barry Song 2020-12-14 1001 acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); 1ec3b5fe6eec78 Barry Song 2020-12-14 1002 ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); 1ec3b5fe6eec78 Barry Song 2020-12-14 1003 dlen = acomp_ctx->req->dlen; 1ec3b5fe6eec78 Barry Song 2020-12-14 1004 mutex_unlock(acomp_ctx->mutex); 1ec3b5fe6eec78 Barry Song 2020-12-14 1005 2b2811178e8555 Seth Jennings 2013-07-10 1006 BUG_ON(ret); 2b2811178e8555 Seth Jennings 2013-07-10 1007 BUG_ON(dlen != PAGE_SIZE); 2b2811178e8555 Seth Jennings 2013-07-10 1008 2b2811178e8555 Seth Jennings 2013-07-10 1009 /* page is up to date */ 2b2811178e8555 Seth Jennings 2013-07-10 1010 SetPageUptodate(page); 2b2811178e8555 Seth Jennings 2013-07-10 1011 } 2b2811178e8555 Seth Jennings 2013-07-10 1012 b349acc76b7f65 Weijie Yang 2013-11-12 1013 /* move it to the tail of the inactive list after end_writeback */ b349acc76b7f65 Weijie Yang 2013-11-12 1014 SetPageReclaim(page); b349acc76b7f65 Weijie Yang 2013-11-12 1015 2b2811178e8555 Seth Jennings 2013-07-10 1016 /* start writeback */ 2b2811178e8555 Seth Jennings 2013-07-10 1017 __swap_writepage(page, &wbc, end_swap_bio_write); 09cbfeaf1a5a67 Kirill A. Shutemov 2016-04-01 1018 put_page(page); 2b2811178e8555 Seth Jennings 2013-07-10 1019 zswap_written_back_pages++; 2b2811178e8555 Seth Jennings 2013-07-10 1020 2b2811178e8555 Seth Jennings 2013-07-10 1021 spin_lock(&tree->lock); 2b2811178e8555 Seth Jennings 2013-07-10 1022 /* drop local reference */ 0ab0abcf511545 Weijie Yang 2013-11-12 1023 zswap_entry_put(tree, entry); 2b2811178e8555 Seth Jennings 2013-07-10 1024 2b2811178e8555 Seth Jennings 2013-07-10 1025 /* 0ab0abcf511545 Weijie Yang 2013-11-12 1026 * There are two possible situations for entry here: 0ab0abcf511545 Weijie Yang 2013-11-12 1027 * (1) refcount is 1(normal case), entry is valid and on the tree 0ab0abcf511545 Weijie Yang 2013-11-12 1028 * (2) refcount is 0, entry is freed and not on the tree 0ab0abcf511545 Weijie Yang 2013-11-12 1029 * because invalidate happened during writeback 0ab0abcf511545 Weijie Yang 2013-11-12 1030 * search the tree and free the entry if find entry 2b2811178e8555 Seth Jennings 2013-07-10 1031 */ 0ab0abcf511545 Weijie Yang 2013-11-12 1032 if (entry == zswap_rb_search(&tree->rbroot, offset)) 0ab0abcf511545 Weijie Yang 2013-11-12 1033 zswap_entry_put(tree, entry); 2b2811178e8555 Seth Jennings 2013-07-10 1034 spin_unlock(&tree->lock); 2b2811178e8555 Seth Jennings 2013-07-10 1035 0ab0abcf511545 Weijie Yang 2013-11-12 1036 goto end; 0ab0abcf511545 Weijie Yang 2013-11-12 1037 0ab0abcf511545 Weijie Yang 2013-11-12 1038 /* 0ab0abcf511545 Weijie Yang 2013-11-12 1039 * if we get here due to ZSWAP_SWAPCACHE_EXIST c8ce1ff1030be8 Randy Dunlap 2021-02-19 1040 * a load may be happening concurrently. c8ce1ff1030be8 Randy Dunlap 2021-02-19 1041 * it is safe and okay to not free the entry. 0ab0abcf511545 Weijie Yang 2013-11-12 1042 * if we free the entry in the following put c8ce1ff1030be8 Randy Dunlap 2021-02-19 1043 * it is also okay to return !0 0ab0abcf511545 Weijie Yang 2013-11-12 1044 */ 2b2811178e8555 Seth Jennings 2013-07-10 1045 fail: 2b2811178e8555 Seth Jennings 2013-07-10 1046 spin_lock(&tree->lock); 0ab0abcf511545 Weijie Yang 2013-11-12 1047 zswap_entry_put(tree, entry); 2b2811178e8555 Seth Jennings 2013-07-10 1048 spin_unlock(&tree->lock); 0ab0abcf511545 Weijie Yang 2013-11-12 1049 0ab0abcf511545 Weijie Yang 2013-11-12 1050 end: 52b41f44f603e5 Tian Tao 2021-02-19 1051 if (zpool_can_sleep_mapped(pool)) 068619e32ff622 Vitaly Wool 2019-09-23 1052 zpool_unmap_handle(pool, handle); 52b41f44f603e5 Tian Tao 2021-02-19 1053 else 52b41f44f603e5 Tian Tao 2021-02-19 1054 kfree(tmp); 52b41f44f603e5 Tian Tao 2021-02-19 1055 2b2811178e8555 Seth Jennings 2013-07-10 @1056 return ret; 2b2811178e8555 Seth Jennings 2013-07-10 1057 } 2b2811178e8555 Seth Jennings 2013-07-10 1058 :::::: The code at line 1056 was first introduced by commit :::::: 2b2811178e85553405b86e3fe78357b9b95889ce zswap: add to mm/ :::::: TO: Seth Jennings <[email protected]> :::::: CC: Linus Torvalds <[email protected]> --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/[email protected]
.config.gz
Description: application/gzip
_______________________________________________ kbuild mailing list -- [email protected] To unsubscribe send an email to [email protected]
