AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/20 20:44 flow patch-triage
2m Args:
null

Results:
{
  "EnableConfigs": [
    "ZRAM",
    "ZSMALLOC",
    "ZRAM_WRITEBACK",
    "ZRAM_MULTI_COMP"
  ],
  "FocusSymbols": [
    "zs_defer_push",
    "zs_defer_drain",
    "zs_defer_drain_work",
    "zs_free",
    "zs_defer_init",
    "zs_defer_destroy",
    "zram_pcpu_sum",
    "slot_free",
    "write_same_filled_page",
    "write_incompressible_page",
    "zram_write_page",
    "recompress_slot",
    "zram_writeback_complete"
  ],
  "KMSANReasoning": "The patch modifies zram and zsmalloc by:\n1. Converting several zram statistics (pages_stored, compr_data_size, same_pages, huge_pages, notify_free) from atomic64 counters to per-CPU stats using u64_stats_sync.\n2. Introducing a per-CPU batching mechanism for deferred frees in zsmalloc (zs_defer_batch).\n\nAnalysis of memory initialization and info-leak risks:\n- In zram_drv.c, `struct zram_stats_sum sum` is explicitly zeroed with `memset(sum, 0, sizeof(*sum))` before summing values across CPUs.\n- The stats are exported to user space exclusively via formatted ASCII strings (`sysfs_emit` in `io_stat_show` and `mm_stat_show`), not as raw kernel structures with padding.\n- `zram-\u003epcpu_stats` is allocated with `alloc_percpu()` which returns zeroed memory.\n- In `zsmalloc.c`, while `zs_defer_batch` is allocated using `kmalloc_obj()`, `batch-\u003ecount` is immediately initialized to 0 upon allocation, and `zs_defer_drain()` only accesses elements of `batch-\u003ehandles` from index 0 up to `batch-\u003ecount - 1`. No uninitialized entries are ever read or exposed.\n- All newly introduced local variables in `slot_free` and `zram_writeback_complete` are explicitly initialized.\n\nApplicability:\nThe changes primarily involve per-CPU data structures and asynchronous deferred freeing. Any bugs introduced (e.g. use-after-free, double free, concurrency/locking races, or memory leaks) are detectable by KASAN, LOCKDEP, or standard kernel debug mechanisms. No uninitialized memory reads or information leaks are introduced or exposed; therefore, a dedicated KMSAN fuzzing session is not required.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch modifies both the zsmalloc memory allocator and the zram virtual block driver. In zsmalloc, it introduces asynchronous batched deferred freeing of objects using per-CPU lists and workqueues, which alters the memory deallocation and concurrency model. In zram, it migrates core operational statistics to per-CPU counters with 64-bit sequence sync locks across block write, slot free, discard, writeback, and recompression paths. Both drivers are software-defined and directly reachable from user space in standard virtualized environments.",
  "WorthFuzzing": true
}

1/1 2026/10/20 20:44 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit a8d89ae963aa9b0d1b727be1b09253072ec3606f\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Oct 20 20:44:57 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c\nindex 024402438bd1d..affe758a9543d 100644\n--- a/drivers/block/zram/zram_drv.c\n+++ b/drivers/block/zram/zram_drv.c\n@@ -488,6 +488,56 @@ static ssize_t idle_store(struct device *dev, struct device_attribute *attr,\n \treturn len;\n }\n \n+struct zram_stats_sum {\n+\ts64 pages_stored;\n+\ts64 compr_data_size;\n+\ts64 same_pages;\n+\ts64 huge_pages;\n+\tu64 notify_free;\n+};\n+\n+#define zram_pcpu_add(zram_dev, field, val)\t\t\t\t\t\\\n+do {\t\t\t\t\t\t\t\t\t\\\n+\tstruct zram *__zram = (zram_dev);\t\t\t\t\\\n+\tstruct zram_pcpu_stats *__stats;\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\t__stats = get_cpu_ptr(__zram-\u003epcpu_stats);\t\t\t\\\n+\tu64_stats_update_begin(\u0026__stats-\u003esyncp);\t\t\t\\\n+\tWRITE_ONCE(__stats-\u003efield, __stats-\u003efield + (val));\t\t\\\n+\tu64_stats_update_end(\u0026__stats-\u003esyncp);\t\t\t\\\n+\tput_cpu_ptr(__zram-\u003epcpu_stats);\t\t\t\t\\\n+} while (0)\n+\n+static void zram_pcpu_sum(struct zram *zram, struct zram_stats_sum *sum)\n+{\n+\tint cpu;\n+\n+\tmemset(sum, 0, sizeof(*sum));\n+\n+\tfor_each_possible_cpu(cpu) {\n+\t\tstruct zram_pcpu_stats *stats;\n+\t\tunsigned int start;\n+\t\ts64 pages, bytes, same, huge;\n+\t\tu64 notify;\n+\n+\t\tstats = per_cpu_ptr(zram-\u003epcpu_stats, cpu);\n+\t\tdo {\n+\t\t\tstart = u64_stats_fetch_begin(\u0026stats-\u003esyncp);\n+\t\t\tpages = READ_ONCE(stats-\u003epages_stored);\n+\t\t\tbytes = READ_ONCE(stats-\u003ecompr_data_size);\n+\t\t\tsame = READ_ONCE(stats-\u003esame_pages);\n+\t\t\thuge = READ_ONCE(stats-\u003ehuge_pages);\n+\t\t\tnotify = READ_ONCE(stats-\u003enotify_free);\n+\t\t} while (u64_stats_fetch_retry(\u0026stats-\u003esyncp, start));\n+\n+\t\tsum-\u003epages_stored += pages;\n+\t\tsum-\u003ecompr_data_size += bytes;\n+\t\tsum-\u003esame_pages += same;\n+\t\tsum-\u003ehuge_pages += huge;\n+\t\tsum-\u003enotify_free += notify;\n+\t}\n+}\n+\n #ifdef CONFIG_ZRAM_WRITEBACK\n #define INVALID_BDEV_BLOCK\t\t(~0UL)\n \n@@ -919,6 +969,8 @@ static void zram_account_writeback_submit(struct zram *zram)\n static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)\n {\n \tunsigned long index = req-\u003epps-\u003eindex;\n+\tstruct zram_pcpu_stats *stats;\n+\ts64 huge, size;\n \tint err;\n \n \terr = blk_status_to_errno(req-\u003ebio.bi_status);\n@@ -947,9 +999,14 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)\n \t}\n \n \tclear_slot_flag(zram, index, ZRAM_IDLE);\n-\tif (test_slot_flag(zram, index, ZRAM_HUGE))\n-\t\tatomic64_dec(\u0026zram-\u003estats.huge_pages);\n-\tatomic64_sub(get_slot_size(zram, index), \u0026zram-\u003estats.compr_data_size);\n+\thuge = test_slot_flag(zram, index, ZRAM_HUGE) ? -1 : 0;\n+\tsize = get_slot_size(zram, index);\n+\tstats = get_cpu_ptr(zram-\u003epcpu_stats);\n+\tu64_stats_update_begin(\u0026stats-\u003esyncp);\n+\tWRITE_ONCE(stats-\u003ehuge_pages, stats-\u003ehuge_pages + huge);\n+\tWRITE_ONCE(stats-\u003ecompr_data_size, stats-\u003ecompr_data_size - size);\n+\tu64_stats_update_end(\u0026stats-\u003esyncp);\n+\tput_cpu_ptr(zram-\u003epcpu_stats);\n \tzs_free(zram-\u003emem_pool, get_slot_handle(zram, index));\n \tset_slot_handle(zram, index, req-\u003eblk_idx);\n \tset_slot_flag(zram, index, ZRAM_WB);\n@@ -1919,14 +1976,16 @@ static ssize_t io_stat_show(struct device *dev, struct device_attribute *attr,\n \t\t\t    char *buf)\n {\n \tstruct zram *zram = dev_to_zram(dev);\n+\tstruct zram_stats_sum sum;\n \tssize_t ret;\n \n \tguard(rwsem_read)(\u0026zram-\u003edev_lock);\n+\tzram_pcpu_sum(zram, \u0026sum);\n \tret = sysfs_emit(buf,\n \t\t\t\"%8llu %8llu 0 %8llu\\n\",\n \t\t\t(u64)atomic64_read(\u0026zram-\u003estats.failed_reads),\n \t\t\t(u64)atomic64_read(\u0026zram-\u003estats.failed_writes),\n-\t\t\t(u64)atomic64_read(\u0026zram-\u003estats.notify_free));\n+\t\t\tsum.notify_free);\n \n \treturn ret;\n }\n@@ -1936,6 +1995,7 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,\n {\n \tstruct zram *zram = dev_to_zram(dev);\n \tstruct zs_pool_stats pool_stats;\n+\tstruct zram_stats_sum sum;\n \tu64 orig_size, mem_used = 0;\n \tlong max_used;\n \tssize_t ret;\n@@ -1948,19 +2008,20 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,\n \t\tzs_pool_stats(zram-\u003emem_pool, \u0026pool_stats);\n \t}\n \n-\torig_size = atomic64_read(\u0026zram-\u003estats.pages_stored);\n+\tzram_pcpu_sum(zram, \u0026sum);\n+\torig_size = max_t(s64, sum.pages_stored, 0);\n \tmax_used = atomic_long_read(\u0026zram-\u003estats.max_used_pages);\n \n \tret = sysfs_emit(buf,\n \t\t\t\"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\\n\",\n \t\t\torig_size \u003c\u003c PAGE_SHIFT,\n-\t\t\t(u64)atomic64_read(\u0026zram-\u003estats.compr_data_size),\n+\t\t\t(u64)max_t(s64, sum.compr_data_size, 0),\n \t\t\tmem_used \u003c\u003c PAGE_SHIFT,\n \t\t\tzram-\u003elimit_pages \u003c\u003c PAGE_SHIFT,\n \t\t\tmax_used \u003c\u003c PAGE_SHIFT,\n-\t\t\t(u64)atomic64_read(\u0026zram-\u003estats.same_pages),\n+\t\t\t(u64)max_t(s64, sum.same_pages, 0),\n \t\t\tatomic_long_read(\u0026pool_stats.pages_compacted),\n-\t\t\t(u64)atomic64_read(\u0026zram-\u003estats.huge_pages),\n+\t\t\t(u64)max_t(s64, sum.huge_pages, 0),\n \t\t\t(u64)atomic64_read(\u0026zram-\u003estats.huge_pages_since));\n \n \treturn ret;\n@@ -2027,6 +2088,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)\n \n static void slot_free(struct zram *zram, unsigned long index)\n {\n+\ts64 pages = 0, bytes = 0, same = 0, huge = 0;\n+\tstruct zram_pcpu_stats *stats;\n \tunsigned long handle;\n \n #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME\n@@ -2044,7 +2107,7 @@ static void slot_free(struct zram *zram, unsigned long index)\n \t\t * ZRAM_HUGE flag for deferred decompression path.\n \t\t */\n \t\tif (!test_slot_flag(zram, index, ZRAM_WB))\n-\t\t\tatomic64_dec(\u0026zram-\u003estats.huge_pages);\n+\t\t\thuge = -1;\n \t\tclear_slot_flag(zram, index, ZRAM_HUGE);\n \t}\n \n@@ -2060,22 +2123,32 @@ static void slot_free(struct zram *zram, unsigned long index)\n \t */\n \tif (test_slot_flag(zram, index, ZRAM_SAME)) {\n \t\tclear_slot_flag(zram, index, ZRAM_SAME);\n-\t\tatomic64_dec(\u0026zram-\u003estats.same_pages);\n+\t\tsame = -1;\n \t\tgoto out;\n \t}\n \n \thandle = get_slot_handle(zram, index);\n \tif (!handle)\n-\t\treturn;\n+\t\tgoto stats;\n \n \tzs_free(zram-\u003emem_pool, handle);\n \n-\tatomic64_sub(get_slot_size(zram, index),\n-\t\t     \u0026zram-\u003estats.compr_data_size);\n+\tbytes = -(s64)get_slot_size(zram, index);\n out:\n-\tatomic64_dec(\u0026zram-\u003estats.pages_stored);\n+\tpages = -1;\n \tset_slot_handle(zram, index, 0);\n \tset_slot_size(zram, index, 0);\n+stats:\n+\tif (!(pages | bytes | same | huge))\n+\t\treturn;\n+\tstats = get_cpu_ptr(zram-\u003epcpu_stats);\n+\tu64_stats_update_begin(\u0026stats-\u003esyncp);\n+\tWRITE_ONCE(stats-\u003epages_stored, stats-\u003epages_stored + pages);\n+\tWRITE_ONCE(stats-\u003ecompr_data_size, stats-\u003ecompr_data_size + bytes);\n+\tWRITE_ONCE(stats-\u003esame_pages, stats-\u003esame_pages + same);\n+\tWRITE_ONCE(stats-\u003ehuge_pages, stats-\u003ehuge_pages + huge);\n+\tu64_stats_update_end(\u0026stats-\u003esyncp);\n+\tput_cpu_ptr(zram-\u003epcpu_stats);\n }\n \n static int read_same_filled_page(struct zram *zram, struct page *page,\n@@ -2237,14 +2310,20 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,\n static int write_same_filled_page(struct zram *zram, unsigned long fill,\n \t\t\t\t  unsigned long index)\n {\n+\tstruct zram_pcpu_stats *stats;\n+\n \tslot_lock(zram, index);\n \tslot_free(zram, index);\n \tset_slot_flag(zram, index, ZRAM_SAME);\n \tset_slot_handle(zram, index, fill);\n \tslot_unlock(zram, index);\n \n-\tatomic64_inc(\u0026zram-\u003estats.same_pages);\n-\tatomic64_inc(\u0026zram-\u003estats.pages_stored);\n+\tstats = get_cpu_ptr(zram-\u003epcpu_stats);\n+\tu64_stats_update_begin(\u0026stats-\u003esyncp);\n+\tWRITE_ONCE(stats-\u003esame_pages, stats-\u003esame_pages + 1);\n+\tWRITE_ONCE(stats-\u003epages_stored, stats-\u003epages_stored + 1);\n+\tu64_stats_update_end(\u0026stats-\u003esyncp);\n+\tput_cpu_ptr(zram-\u003epcpu_stats);\n \n \treturn 0;\n }\n@@ -2252,6 +2331,7 @@ static int write_same_filled_page(struct zram *zram, unsigned long fill,\n static int write_incompressible_page(struct zram *zram, struct page *page,\n \t\t\t\t     unsigned long index)\n {\n+\tstruct zram_pcpu_stats *stats;\n \tunsigned long handle;\n \tvoid *src;\n \n@@ -2282,10 +2362,14 @@ static int write_incompressible_page(struct zram *zram, struct page *page,\n \tset_slot_size(zram, index, PAGE_SIZE);\n \tslot_unlock(zram, index);\n \n-\tatomic64_add(PAGE_SIZE, \u0026zram-\u003estats.compr_data_size);\n-\tatomic64_inc(\u0026zram-\u003estats.huge_pages);\n+\tstats = get_cpu_ptr(zram-\u003epcpu_stats);\n+\tu64_stats_update_begin(\u0026stats-\u003esyncp);\n+\tWRITE_ONCE(stats-\u003ecompr_data_size, stats-\u003ecompr_data_size + PAGE_SIZE);\n+\tWRITE_ONCE(stats-\u003ehuge_pages, stats-\u003ehuge_pages + 1);\n+\tWRITE_ONCE(stats-\u003epages_stored, stats-\u003epages_stored + 1);\n+\tu64_stats_update_end(\u0026stats-\u003esyncp);\n+\tput_cpu_ptr(zram-\u003epcpu_stats);\n \tatomic64_inc(\u0026zram-\u003estats.huge_pages_since);\n-\tatomic64_inc(\u0026zram-\u003estats.pages_stored);\n \n \treturn 0;\n }\n@@ -2293,6 +2377,7 @@ static int write_incompressible_page(struct zram *zram, struct page *page,\n static int zram_write_page(struct zram *zram, struct page *page,\n \t\t\t   unsigned long index)\n {\n+\tstruct zram_pcpu_stats *stats;\n \tint ret = 0;\n \tunsigned long handle;\n \tunsigned int comp_len;\n@@ -2348,8 +2433,12 @@ static int zram_write_page(struct zram *zram, struct page *page,\n \tslot_unlock(zram, index);\n \n \t/* Update stats */\n-\tatomic64_inc(\u0026zram-\u003estats.pages_stored);\n-\tatomic64_add(comp_len, \u0026zram-\u003estats.compr_data_size);\n+\tstats = get_cpu_ptr(zram-\u003epcpu_stats);\n+\tu64_stats_update_begin(\u0026stats-\u003esyncp);\n+\tWRITE_ONCE(stats-\u003epages_stored, stats-\u003epages_stored + 1);\n+\tWRITE_ONCE(stats-\u003ecompr_data_size, stats-\u003ecompr_data_size + comp_len);\n+\tu64_stats_update_end(\u0026stats-\u003esyncp);\n+\tput_cpu_ptr(zram-\u003epcpu_stats);\n \n \treturn ret;\n }\n@@ -2449,6 +2538,7 @@ static int recompress_slot(struct zram *zram, unsigned long index,\n \t\t\t   u32 threshold, u32 prio)\n {\n \tstruct zcomp_strm *zstrm = NULL;\n+\tstruct zram_pcpu_stats *stats;\n \tunsigned long handle_old;\n \tunsigned long handle_new;\n \tunsigned int comp_len_old;\n@@ -2545,8 +2635,12 @@ static int recompress_slot(struct zram *zram, unsigned long index,\n \tset_slot_size(zram, index, comp_len_new);\n \tset_slot_comp_priority(zram, index, prio);\n \n-\tatomic64_add(comp_len_new, \u0026zram-\u003estats.compr_data_size);\n-\tatomic64_inc(\u0026zram-\u003estats.pages_stored);\n+\tstats = get_cpu_ptr(zram-\u003epcpu_stats);\n+\tu64_stats_update_begin(\u0026stats-\u003esyncp);\n+\tWRITE_ONCE(stats-\u003ecompr_data_size, stats-\u003ecompr_data_size + comp_len_new);\n+\tWRITE_ONCE(stats-\u003epages_stored, stats-\u003epages_stored + 1);\n+\tu64_stats_update_end(\u0026stats-\u003esyncp);\n+\tput_cpu_ptr(zram-\u003epcpu_stats);\n \n \treturn 0;\n }\n@@ -2724,7 +2818,7 @@ static void zram_bio_discard(struct zram *zram, struct bio *bio)\n \t\tslot_lock(zram, index);\n \t\tslot_free(zram, index);\n \t\tslot_unlock(zram, index);\n-\t\tatomic64_inc(\u0026zram-\u003estats.notify_free);\n+\t\tzram_pcpu_add(zram, notify_free, 1);\n \t\tindex++;\n \t\tn -= PAGE_SIZE;\n \t}\n@@ -2825,7 +2919,7 @@ static void zram_slot_free_notify(struct block_device *bdev,\n \n \tzram = bdev-\u003ebd_disk-\u003eprivate_data;\n \n-\tatomic64_inc(\u0026zram-\u003estats.notify_free);\n+\tzram_pcpu_add(zram, notify_free, 1);\n \tif (!slot_trylock(zram, index)) {\n \t\tatomic64_inc(\u0026zram-\u003estats.miss_free);\n \t\treturn;\n@@ -2866,6 +2960,8 @@ static void zram_destroy_comps(struct zram *zram)\n \n static void zram_reset_device(struct zram *zram)\n {\n+\tint cpu;\n+\n \tguard(rwsem_write)(\u0026zram-\u003edev_lock);\n \n \tzram-\u003elimit_pages = 0;\n@@ -2877,6 +2973,16 @@ static void zram_reset_device(struct zram *zram)\n \tzram_meta_free(zram, zram-\u003edisksize);\n \tzram-\u003edisksize = 0;\n \tzram_destroy_comps(zram);\n+\tfor_each_possible_cpu(cpu) {\n+\t\tstruct zram_pcpu_stats *stats;\n+\n+\t\tstats = per_cpu_ptr(zram-\u003epcpu_stats, cpu);\n+\t\tstats-\u003epages_stored = 0;\n+\t\tstats-\u003ecompr_data_size = 0;\n+\t\tstats-\u003esame_pages = 0;\n+\t\tstats-\u003ehuge_pages = 0;\n+\t\tstats-\u003enotify_free = 0;\n+\t}\n \tmemset(\u0026zram-\u003estats, 0, sizeof(zram-\u003estats));\n \treset_bdev(zram);\n }\n@@ -3083,15 +3189,23 @@ static int zram_add(void)\n \t\t\t\t\t\t  BLK_FEAT_SYNCHRONOUS,\n \t};\n \tstruct zram *zram;\n-\tint ret, device_id;\n+\tint cpu, ret, device_id;\n \n \tzram = kzalloc_obj(struct zram);\n \tif (!zram)\n \t\treturn -ENOMEM;\n \n+\tzram-\u003epcpu_stats = alloc_percpu(struct zram_pcpu_stats);\n+\tif (!zram-\u003epcpu_stats) {\n+\t\tret = -ENOMEM;\n+\t\tgoto out_free_dev;\n+\t}\n+\tfor_each_possible_cpu(cpu)\n+\t\tu64_stats_init(\u0026per_cpu_ptr(zram-\u003epcpu_stats, cpu)-\u003esyncp);\n+\n \tret = idr_alloc(\u0026zram_index_idr, zram, 0, 0, GFP_KERNEL);\n \tif (ret \u003c 0)\n-\t\tgoto out_free_dev;\n+\t\tgoto out_free_pcpu;\n \tdevice_id = ret;\n \n \tinit_rwsem(\u0026zram-\u003edev_lock);\n@@ -3133,6 +3247,8 @@ static int zram_add(void)\n \tput_disk(zram-\u003edisk);\n out_free_idr:\n \tidr_remove(\u0026zram_index_idr, device_id);\n+out_free_pcpu:\n+\tfree_percpu(zram-\u003epcpu_stats);\n out_free_dev:\n \tkfree(zram);\n \treturn ret;\n@@ -3182,6 +3298,7 @@ static int zram_remove(struct zram *zram)\n \tzram_reset_device(zram);\n \n \tput_disk(zram-\u003edisk);\n+\tfree_percpu(zram-\u003epcpu_stats);\n \tkfree(zram);\n \treturn 0;\n }\ndiff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h\nindex 7a55d751417e2..482e1c28ca1ce 100644\n--- a/drivers/block/zram/zram_drv.h\n+++ b/drivers/block/zram/zram_drv.h\n@@ -17,6 +17,7 @@\n \n #include \u003casm/byteorder.h\u003e\n #include \u003clinux/rwsem.h\u003e\n+#include \u003clinux/u64_stats_sync.h\u003e\n #include \u003clinux/zsmalloc.h\u003e\n \n #include \"zcomp.h\"\n@@ -90,15 +91,19 @@ struct zram_table_entry {\n \t};\n };\n \n+struct zram_pcpu_stats {\n+\tstruct u64_stats_sync syncp;\n+\ts64 pages_stored;\t/* no. of pages currently stored */\n+\ts64 compr_data_size;\t/* compressed size of pages stored */\n+\ts64 same_pages;\t\t/* no. of same element filled pages */\n+\ts64 huge_pages;\t\t/* no. of huge pages */\n+\tu64 notify_free;\t/* no. of swap slot free notifications */\n+};\n+\n struct zram_stats {\n-\tatomic64_t compr_data_size;\t/* compressed size of pages stored */\n \tatomic64_t failed_reads;\t/* can happen when memory is too low */\n \tatomic64_t failed_writes;\t/* can happen when memory is too low */\n-\tatomic64_t notify_free;\t/* no. of swap slot free notifications */\n-\tatomic64_t same_pages;\t\t/* no. of same element filled pages */\n-\tatomic64_t huge_pages;\t\t/* no. of huge pages */\n \tatomic64_t huge_pages_since;\t/* no. of huge pages since zram set up */\n-\tatomic64_t pages_stored;\t/* no. of pages currently stored */\n \tatomic_long_t max_used_pages;\t/* no. of maximum pages stored */\n \tatomic64_t miss_free;\t\t/* no. of missed free */\n #ifdef\tCONFIG_ZRAM_WRITEBACK\n@@ -134,6 +139,7 @@ struct zram {\n \tunsigned long limit_pages;\n \n \tstruct zram_stats stats;\n+\tstruct zram_pcpu_stats __percpu *pcpu_stats;\n \t/*\n \t * This is the limit on amount of *uncompressed* worth of data\n \t * we can store in a disk.\ndiff --git a/mm/zsmalloc.c b/mm/zsmalloc.c\nindex 7ef80e0da6267..eacd771bd5425 100644\n--- a/mm/zsmalloc.c\n+++ b/mm/zsmalloc.c\n@@ -43,6 +43,7 @@\n #include \u003clinux/zsmalloc.h\u003e\n #include \u003clinux/fs.h\u003e\n #include \u003clinux/workqueue.h\u003e\n+#include \u003clinux/llist.h\u003e\n #include \"zpdesc.h\"\n \n #define ZSPAGE_MAGIC\t0x58\n@@ -267,6 +268,21 @@ struct link_free {\n static struct kmem_cache *handle_cachep;\n static struct kmem_cache *zspage_cachep;\n \n+#define ZS_DEFER_BATCH\t64\n+\n+struct zs_defer_batch {\n+\tstruct llist_node node;\n+\tunsigned int count;\n+\tunsigned long handles[ZS_DEFER_BATCH];\n+};\n+\n+struct zs_defer_percpu {\n+\tstruct zs_defer_batch *active;\n+\tstruct llist_head pending;\n+\tstruct work_struct drain_work;\n+\tstruct zs_pool *pool;\n+};\n+\n struct zs_pool {\n \tconst char *name;\n \n@@ -282,12 +298,12 @@ struct zs_pool {\n #ifdef CONFIG_ZSMALLOC_STAT\n \tstruct dentry *stat_dentry;\n #endif\n-#ifdef CONFIG_COMPACTION\n \tstruct work_struct free_work;\n-#endif\n \t/* protect zspage migration/compaction */\n \trwlock_t lock;\n \tatomic_t compaction_in_progress;\n+\n+\tstruct zs_defer_percpu __percpu *defer;\n };\n \n static inline void zpdesc_inc_zone_page_state(struct zpdesc *zpdesc)\n@@ -428,13 +444,11 @@ static bool ZsHugePage(struct zspage *zspage)\n \treturn zspage-\u003ehuge;\n }\n \n-#ifdef CONFIG_COMPACTION\n static void kick_deferred_free(struct zs_pool *pool);\n static void init_deferred_free(struct zs_pool *pool);\n+#ifdef CONFIG_COMPACTION\n static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage);\n #else\n-static void kick_deferred_free(struct zs_pool *pool) {}\n-static void init_deferred_free(struct zs_pool *pool) {}\n static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {}\n #endif\n \n@@ -684,7 +698,6 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)\n }\n #endif\n \n-\n /*\n  * For each size class, zspages are divided into different groups\n  * depending on their usage ratio. This function returns fullness\n@@ -1293,7 +1306,6 @@ static unsigned long obj_malloc(struct zs_pool *pool,\n \treturn obj;\n }\n \n-\n /**\n  * zs_malloc - Allocate block of given size from pool.\n  * @pool: pool to allocate from\n@@ -1371,7 +1383,6 @@ static void obj_free(int class_size, unsigned long obj)\n \tunsigned int f_objidx;\n \tvoid *vaddr;\n \n-\n \tobj_to_location(obj, \u0026f_zpdesc, \u0026f_objidx);\n \tf_offset = offset_in_page(class_size * f_objidx);\n \tzspage = get_zspage(f_zpdesc);\n@@ -1447,7 +1458,7 @@ static inline void obj_class_get_and_lock(struct zs_pool *pool, unsigned long ha\n }\n #endif\n \n-void zs_free(struct zs_pool *pool, unsigned long handle)\n+static void __zs_free_one(struct zs_pool *pool, unsigned long handle)\n {\n \tstruct zspage *zspage;\n \tunsigned long obj;\n@@ -1455,9 +1466,6 @@ void zs_free(struct zs_pool *pool, unsigned long handle)\n \tint fullness;\n \tstruct zspage *zspage_to_free = NULL;\n \n-\tif (IS_ERR_OR_NULL((void *)handle))\n-\t\treturn;\n-\n \tobj_class_get_and_lock(pool, handle, \u0026obj, \u0026zspage, \u0026class);\n \n \tclass_stat_sub(class, ZS_OBJS_INUSE, 1);\n@@ -1483,6 +1491,78 @@ void zs_free(struct zs_pool *pool, unsigned long handle)\n \t}\n \tcache_free_handle(handle);\n }\n+\n+static void zs_defer_drain(struct zs_defer_percpu *defer)\n+{\n+\tstruct zs_pool *pool = defer-\u003epool;\n+\tstruct zs_defer_batch *batch, *n;\n+\tstruct llist_node *first;\n+\n+\tfirst = llist_del_all(\u0026defer-\u003epending);\n+\tllist_for_each_entry_safe(batch, n, first, node) {\n+\t\tunsigned int i;\n+\n+\t\tfor (i = 0; i \u003c batch-\u003ecount; i++)\n+\t\t\t__zs_free_one(pool, batch-\u003ehandles[i]);\n+\t\tkfree(batch);\n+\t\tcond_resched();\n+\t}\n+}\n+\n+static void zs_defer_drain_work(struct work_struct *work)\n+{\n+\tzs_defer_drain(container_of(work, struct zs_defer_percpu, drain_work));\n+}\n+\n+static bool zs_defer_push(struct zs_pool *pool, unsigned long handle)\n+{\n+\tstruct zs_defer_batch *new_batch = NULL, *batch;\n+\tstruct zs_defer_percpu *defer;\n+\tbool queue = false;\n+\n+\tif (!pool-\u003edefer)\n+\t\treturn false;\n+\n+\tdefer = get_cpu_ptr(pool-\u003edefer);\n+\tif (!defer-\u003eactive) {\n+\t\tput_cpu_ptr(pool-\u003edefer);\n+\t\tnew_batch = kmalloc_obj(*new_batch, GFP_NOWAIT | __GFP_NOWARN);\n+\t\tif (!new_batch)\n+\t\t\treturn false;\n+\t\tnew_batch-\u003ecount = 0;\n+\n+\t\tdefer = get_cpu_ptr(pool-\u003edefer);\n+\t\tif (!defer-\u003eactive) {\n+\t\t\tdefer-\u003eactive = new_batch;\n+\t\t\tnew_batch = NULL;\n+\t\t}\n+\t}\n+\n+\tbatch = defer-\u003eactive;\n+\tbatch-\u003ehandles[batch-\u003ecount++] = handle;\n+\tif (batch-\u003ecount == ZS_DEFER_BATCH) {\n+\t\tllist_add(\u0026batch-\u003enode, \u0026defer-\u003epending);\n+\t\tdefer-\u003eactive = NULL;\n+\t\tqueue = true;\n+\t}\n+\tput_cpu_ptr(pool-\u003edefer);\n+\n+\tif (unlikely(new_batch))\n+\t\tkfree(new_batch);\n+\n+\tif (queue)\n+\t\tqueue_work(system_dfl_wq, \u0026defer-\u003edrain_work);\n+\treturn true;\n+}\n+\n+void zs_free(struct zs_pool *pool, unsigned long handle)\n+{\n+\tif (IS_ERR_OR_NULL((void *)handle))\n+\t\treturn;\n+\n+\tif (!zs_defer_push(pool, handle))\n+\t\t__zs_free_one(pool, handle);\n+}\n EXPORT_SYMBOL_GPL(zs_free);\n \n static void zs_object_copy(struct size_class *class, unsigned long dst,\n@@ -1671,7 +1751,6 @@ static int putback_zspage(struct size_class *class, struct zspage *zspage)\n \treturn fullness;\n }\n \n-#ifdef CONFIG_COMPACTION\n /*\n  * To prevent zspage destroy during migration, zspage freeing should\n  * hold locks of all pages in the zspage.\n@@ -1714,6 +1793,8 @@ static void lock_zspage(struct zspage *zspage)\n \tzspage_read_unlock(zspage);\n }\n \n+#ifdef CONFIG_COMPACTION\n+\n static void replace_sub_page(struct size_class *class, struct zspage *zspage,\n \t\t\t\tstruct zpdesc *newzpdesc, struct zpdesc *oldzpdesc)\n {\n@@ -1866,6 +1947,18 @@ const struct movable_operations zsmalloc_mops = {\n \t.putback_page = zs_page_putback,\n };\n \n+static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)\n+{\n+\tstruct zpdesc *zpdesc = get_first_zpdesc(zspage);\n+\n+\tdo {\n+\t\tWARN_ON(!zpdesc_trylock(zpdesc));\n+\t\t__zpdesc_set_movable(zpdesc);\n+\t\tzpdesc_unlock(zpdesc);\n+\t} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);\n+}\n+#endif /* CONFIG_COMPACTION */\n+\n /*\n  * Caller should hold page_lock of all pages in the zspage\n  * In here, we cannot use zspage meta data.\n@@ -1904,7 +1997,7 @@ static void async_free_zspage(struct work_struct *work)\n \n static void kick_deferred_free(struct zs_pool *pool)\n {\n-\tschedule_work(\u0026pool-\u003efree_work);\n+\tqueue_work(system_dfl_wq, \u0026pool-\u003efree_work);\n }\n \n static void zs_flush_migration(struct zs_pool *pool)\n@@ -1917,20 +2010,6 @@ static void init_deferred_free(struct zs_pool *pool)\n \tINIT_WORK(\u0026pool-\u003efree_work, async_free_zspage);\n }\n \n-static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)\n-{\n-\tstruct zpdesc *zpdesc = get_first_zpdesc(zspage);\n-\n-\tdo {\n-\t\tWARN_ON(!zpdesc_trylock(zpdesc));\n-\t\t__zpdesc_set_movable(zpdesc);\n-\t\tzpdesc_unlock(zpdesc);\n-\t} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);\n-}\n-#else\n-static inline void zs_flush_migration(struct zs_pool *pool) { }\n-#endif\n-\n /*\n  *\n  * Based on the number of unused allocated objects calculate\n@@ -2127,6 +2206,48 @@ static int calculate_zspage_chain_size(int class_size)\n \treturn chain_size;\n }\n \n+static void zs_defer_destroy(struct zs_pool *pool)\n+{\n+\tstruct zs_defer_percpu __percpu *defer_pcp = pool-\u003edefer;\n+\tint cpu;\n+\n+\tif (!defer_pcp)\n+\t\treturn;\n+\n+\tpool-\u003edefer = NULL;\n+\tfor_each_possible_cpu(cpu) {\n+\t\tstruct zs_defer_percpu *defer = per_cpu_ptr(defer_pcp, cpu);\n+\n+\t\tcancel_work_sync(\u0026defer-\u003edrain_work);\n+\t\tif (defer-\u003eactive) {\n+\t\t\tllist_add(\u0026defer-\u003eactive-\u003enode, \u0026defer-\u003epending);\n+\t\t\tdefer-\u003eactive = NULL;\n+\t\t}\n+\t\tzs_defer_drain(defer);\n+\t}\n+\tfree_percpu(defer_pcp);\n+}\n+\n+static int zs_defer_init(struct zs_pool *pool)\n+{\n+\tint cpu;\n+\n+\tpool-\u003edefer = alloc_percpu(struct zs_defer_percpu);\n+\tif (!pool-\u003edefer)\n+\t\treturn -ENOMEM;\n+\n+\tfor_each_possible_cpu(cpu) {\n+\t\tstruct zs_defer_percpu *defer = per_cpu_ptr(pool-\u003edefer, cpu);\n+\n+\t\tdefer-\u003eactive = NULL;\n+\t\tinit_llist_head(\u0026defer-\u003epending);\n+\t\tdefer-\u003epool = pool;\n+\t\tINIT_WORK(\u0026defer-\u003edrain_work, zs_defer_drain_work);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /**\n  * zs_create_pool - Creates an allocation pool to work from.\n  * @name: pool name to be created\n@@ -2151,6 +2272,10 @@ struct zs_pool *zs_create_pool(const char *name)\n \trwlock_init(\u0026pool-\u003elock);\n \tatomic_set(\u0026pool-\u003ecompaction_in_progress, 0);\n \n+\tif (zs_defer_init(pool))\n+\t\tpr_info(\"deferred free unavailable for \u003c%s\u003e, freeing synchronously\\n\",\n+\t\t\tname);\n+\n \tpool-\u003ename = kstrdup(name, GFP_KERNEL);\n \tif (!pool-\u003ename)\n \t\tgoto err;\n@@ -2253,6 +2378,7 @@ void zs_destroy_pool(struct zs_pool *pool)\n \tint i;\n \n \tzs_unregister_shrinker(pool);\n+\tzs_defer_destroy(pool);\n \tzs_flush_migration(pool);\n \tzs_pool_stat_destroy(pool);\n \n"
}

2/1 2026/10/20 20:44 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "ZRAM",
    "ZSMALLOC",
    "ZRAM_WRITEBACK",
    "ZRAM_MULTI_COMP"
  ],
  "FocusSymbols": [
    "zs_defer_push",
    "zs_defer_drain",
    "zs_defer_drain_work",
    "zs_free",
    "zs_defer_init",
    "zs_defer_destroy",
    "zram_pcpu_sum",
    "slot_free",
    "write_same_filled_page",
    "write_incompressible_page",
    "zram_write_page",
    "recompress_slot",
    "zram_writeback_complete"
  ],
  "Reasoning": "The patch modifies both the zsmalloc memory allocator and the zram virtual block driver. In zsmalloc, it introduces asynchronous batched deferred freeing of objects using per-CPU lists and workqueues, which alters the memory deallocation and concurrency model. In zram, it migrates core operational statistics to per-CPU counters with 64-bit sequence sync locks across block write, slot free, discard, writeback, and recompression paths. Both drivers are software-defined and directly reachable from user space in standard virtualized environments.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit a8d89ae963aa9b0d1b727be1b09253072ec3606f
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Oct 20 20:44:57 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 024402438bd1d..affe758a9543d 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -488,6 +488,56 @@ static ssize_t idle_store(struct device *dev, struct device_attribute *attr,
 	return len;
 }
 
+struct zram_stats_sum {
+	s64 pages_stored;
+	s64 compr_data_size;
+	s64 same_pages;
+	s64 huge_pages;
+	u64 notify_free;
+};
+
+#define zram_pcpu_add(zram_dev, field, val)					\
+do {									\
+	struct zram *__zram = (zram_dev);				\
+	struct zram_pcpu_stats *__stats;				\
+									\
+	__stats = get_cpu_ptr(__zram->pcpu_stats);			\
+	u64_stats_update_begin(&__stats->syncp);			\
+	WRITE_ONCE(__stats->field, __stats->field + (val));		\
+	u64_stats_update_end(&__stats->syncp);			\
+	put_cpu_ptr(__zram->pcpu_stats);				\
+} while (0)
+
+static void zram_pcpu_sum(struct zram *zram, struct zram_stats_sum *sum)
+{
+	int cpu;
+
+	memset(sum, 0, sizeof(*sum));
+
+	for_each_possible_cpu(cpu) {
+		struct zram_pcpu_stats *stats;
+		unsigned int start;
+		s64 pages, bytes, same, huge;
+		u64 notify;
+
+		stats = per_cpu_ptr(zram->pcpu_stats, cpu);
+		do {
+			start = u64_stats_fetch_begin(&stats->syncp);
+			pages = READ_ONCE(stats->pages_stored);
+			bytes = READ_ONCE(stats->compr_data_size);
+			same = READ_ONCE(stats->same_pages);
+			huge = READ_ONCE(stats->huge_pages);
+			notify = READ_ONCE(stats->notify_free);
+		} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+		sum->pages_stored += pages;
+		sum->compr_data_size += bytes;
+		sum->same_pages += same;
+		sum->huge_pages += huge;
+		sum->notify_free += notify;
+	}
+}
+
 #ifdef CONFIG_ZRAM_WRITEBACK
 #define INVALID_BDEV_BLOCK		(~0UL)
 
@@ -919,6 +969,8 @@ static void zram_account_writeback_submit(struct zram *zram)
 static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
 {
 	unsigned long index = req->pps->index;
+	struct zram_pcpu_stats *stats;
+	s64 huge, size;
 	int err;
 
 	err = blk_status_to_errno(req->bio.bi_status);
@@ -947,9 +999,14 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
 	}
 
 	clear_slot_flag(zram, index, ZRAM_IDLE);
-	if (test_slot_flag(zram, index, ZRAM_HUGE))
-		atomic64_dec(&zram->stats.huge_pages);
-	atomic64_sub(get_slot_size(zram, index), &zram->stats.compr_data_size);
+	huge = test_slot_flag(zram, index, ZRAM_HUGE) ? -1 : 0;
+	size = get_slot_size(zram, index);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->huge_pages, stats->huge_pages + huge);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size - size);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 	zs_free(zram->mem_pool, get_slot_handle(zram, index));
 	set_slot_handle(zram, index, req->blk_idx);
 	set_slot_flag(zram, index, ZRAM_WB);
@@ -1919,14 +1976,16 @@ static ssize_t io_stat_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
 	struct zram *zram = dev_to_zram(dev);
+	struct zram_stats_sum sum;
 	ssize_t ret;
 
 	guard(rwsem_read)(&zram->dev_lock);
+	zram_pcpu_sum(zram, &sum);
 	ret = sysfs_emit(buf,
 			"%8llu %8llu 0 %8llu\n",
 			(u64)atomic64_read(&zram->stats.failed_reads),
 			(u64)atomic64_read(&zram->stats.failed_writes),
-			(u64)atomic64_read(&zram->stats.notify_free));
+			sum.notify_free);
 
 	return ret;
 }
@@ -1936,6 +1995,7 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
 {
 	struct zram *zram = dev_to_zram(dev);
 	struct zs_pool_stats pool_stats;
+	struct zram_stats_sum sum;
 	u64 orig_size, mem_used = 0;
 	long max_used;
 	ssize_t ret;
@@ -1948,19 +2008,20 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
 		zs_pool_stats(zram->mem_pool, &pool_stats);
 	}
 
-	orig_size = atomic64_read(&zram->stats.pages_stored);
+	zram_pcpu_sum(zram, &sum);
+	orig_size = max_t(s64, sum.pages_stored, 0);
 	max_used = atomic_long_read(&zram->stats.max_used_pages);
 
 	ret = sysfs_emit(buf,
 			"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
 			orig_size << PAGE_SHIFT,
-			(u64)atomic64_read(&zram->stats.compr_data_size),
+			(u64)max_t(s64, sum.compr_data_size, 0),
 			mem_used << PAGE_SHIFT,
 			zram->limit_pages << PAGE_SHIFT,
 			max_used << PAGE_SHIFT,
-			(u64)atomic64_read(&zram->stats.same_pages),
+			(u64)max_t(s64, sum.same_pages, 0),
 			atomic_long_read(&pool_stats.pages_compacted),
-			(u64)atomic64_read(&zram->stats.huge_pages),
+			(u64)max_t(s64, sum.huge_pages, 0),
 			(u64)atomic64_read(&zram->stats.huge_pages_since));
 
 	return ret;
@@ -2027,6 +2088,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
 
 static void slot_free(struct zram *zram, unsigned long index)
 {
+	s64 pages = 0, bytes = 0, same = 0, huge = 0;
+	struct zram_pcpu_stats *stats;
 	unsigned long handle;
 
 #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
@@ -2044,7 +2107,7 @@ static void slot_free(struct zram *zram, unsigned long index)
 		 * ZRAM_HUGE flag for deferred decompression path.
 		 */
 		if (!test_slot_flag(zram, index, ZRAM_WB))
-			atomic64_dec(&zram->stats.huge_pages);
+			huge = -1;
 		clear_slot_flag(zram, index, ZRAM_HUGE);
 	}
 
@@ -2060,22 +2123,32 @@ static void slot_free(struct zram *zram, unsigned long index)
 	 */
 	if (test_slot_flag(zram, index, ZRAM_SAME)) {
 		clear_slot_flag(zram, index, ZRAM_SAME);
-		atomic64_dec(&zram->stats.same_pages);
+		same = -1;
 		goto out;
 	}
 
 	handle = get_slot_handle(zram, index);
 	if (!handle)
-		return;
+		goto stats;
 
 	zs_free(zram->mem_pool, handle);
 
-	atomic64_sub(get_slot_size(zram, index),
-		     &zram->stats.compr_data_size);
+	bytes = -(s64)get_slot_size(zram, index);
 out:
-	atomic64_dec(&zram->stats.pages_stored);
+	pages = -1;
 	set_slot_handle(zram, index, 0);
 	set_slot_size(zram, index, 0);
+stats:
+	if (!(pages | bytes | same | huge))
+		return;
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + pages);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + bytes);
+	WRITE_ONCE(stats->same_pages, stats->same_pages + same);
+	WRITE_ONCE(stats->huge_pages, stats->huge_pages + huge);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 }
 
 static int read_same_filled_page(struct zram *zram, struct page *page,
@@ -2237,14 +2310,20 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
 static int write_same_filled_page(struct zram *zram, unsigned long fill,
 				  unsigned long index)
 {
+	struct zram_pcpu_stats *stats;
+
 	slot_lock(zram, index);
 	slot_free(zram, index);
 	set_slot_flag(zram, index, ZRAM_SAME);
 	set_slot_handle(zram, index, fill);
 	slot_unlock(zram, index);
 
-	atomic64_inc(&zram->stats.same_pages);
-	atomic64_inc(&zram->stats.pages_stored);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->same_pages, stats->same_pages + 1);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 
 	return 0;
 }
@@ -2252,6 +2331,7 @@ static int write_same_filled_page(struct zram *zram, unsigned long fill,
 static int write_incompressible_page(struct zram *zram, struct page *page,
 				     unsigned long index)
 {
+	struct zram_pcpu_stats *stats;
 	unsigned long handle;
 	void *src;
 
@@ -2282,10 +2362,14 @@ static int write_incompressible_page(struct zram *zram, struct page *page,
 	set_slot_size(zram, index, PAGE_SIZE);
 	slot_unlock(zram, index);
 
-	atomic64_add(PAGE_SIZE, &zram->stats.compr_data_size);
-	atomic64_inc(&zram->stats.huge_pages);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + PAGE_SIZE);
+	WRITE_ONCE(stats->huge_pages, stats->huge_pages + 1);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 	atomic64_inc(&zram->stats.huge_pages_since);
-	atomic64_inc(&zram->stats.pages_stored);
 
 	return 0;
 }
@@ -2293,6 +2377,7 @@ static int write_incompressible_page(struct zram *zram, struct page *page,
 static int zram_write_page(struct zram *zram, struct page *page,
 			   unsigned long index)
 {
+	struct zram_pcpu_stats *stats;
 	int ret = 0;
 	unsigned long handle;
 	unsigned int comp_len;
@@ -2348,8 +2433,12 @@ static int zram_write_page(struct zram *zram, struct page *page,
 	slot_unlock(zram, index);
 
 	/* Update stats */
-	atomic64_inc(&zram->stats.pages_stored);
-	atomic64_add(comp_len, &zram->stats.compr_data_size);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + comp_len);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 
 	return ret;
 }
@@ -2449,6 +2538,7 @@ static int recompress_slot(struct zram *zram, unsigned long index,
 			   u32 threshold, u32 prio)
 {
 	struct zcomp_strm *zstrm = NULL;
+	struct zram_pcpu_stats *stats;
 	unsigned long handle_old;
 	unsigned long handle_new;
 	unsigned int comp_len_old;
@@ -2545,8 +2635,12 @@ static int recompress_slot(struct zram *zram, unsigned long index,
 	set_slot_size(zram, index, comp_len_new);
 	set_slot_comp_priority(zram, index, prio);
 
-	atomic64_add(comp_len_new, &zram->stats.compr_data_size);
-	atomic64_inc(&zram->stats.pages_stored);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + comp_len_new);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 
 	return 0;
 }
@@ -2724,7 +2818,7 @@ static void zram_bio_discard(struct zram *zram, struct bio *bio)
 		slot_lock(zram, index);
 		slot_free(zram, index);
 		slot_unlock(zram, index);
-		atomic64_inc(&zram->stats.notify_free);
+		zram_pcpu_add(zram, notify_free, 1);
 		index++;
 		n -= PAGE_SIZE;
 	}
@@ -2825,7 +2919,7 @@ static void zram_slot_free_notify(struct block_device *bdev,
 
 	zram = bdev->bd_disk->private_data;
 
-	atomic64_inc(&zram->stats.notify_free);
+	zram_pcpu_add(zram, notify_free, 1);
 	if (!slot_trylock(zram, index)) {
 		atomic64_inc(&zram->stats.miss_free);
 		return;
@@ -2866,6 +2960,8 @@ static void zram_destroy_comps(struct zram *zram)
 
 static void zram_reset_device(struct zram *zram)
 {
+	int cpu;
+
 	guard(rwsem_write)(&zram->dev_lock);
 
 	zram->limit_pages = 0;
@@ -2877,6 +2973,16 @@ static void zram_reset_device(struct zram *zram)
 	zram_meta_free(zram, zram->disksize);
 	zram->disksize = 0;
 	zram_destroy_comps(zram);
+	for_each_possible_cpu(cpu) {
+		struct zram_pcpu_stats *stats;
+
+		stats = per_cpu_ptr(zram->pcpu_stats, cpu);
+		stats->pages_stored = 0;
+		stats->compr_data_size = 0;
+		stats->same_pages = 0;
+		stats->huge_pages = 0;
+		stats->notify_free = 0;
+	}
 	memset(&zram->stats, 0, sizeof(zram->stats));
 	reset_bdev(zram);
 }
@@ -3083,15 +3189,23 @@ static int zram_add(void)
 						  BLK_FEAT_SYNCHRONOUS,
 	};
 	struct zram *zram;
-	int ret, device_id;
+	int cpu, ret, device_id;
 
 	zram = kzalloc_obj(struct zram);
 	if (!zram)
 		return -ENOMEM;
 
+	zram->pcpu_stats = alloc_percpu(struct zram_pcpu_stats);
+	if (!zram->pcpu_stats) {
+		ret = -ENOMEM;
+		goto out_free_dev;
+	}
+	for_each_possible_cpu(cpu)
+		u64_stats_init(&per_cpu_ptr(zram->pcpu_stats, cpu)->syncp);
+
 	ret = idr_alloc(&zram_index_idr, zram, 0, 0, GFP_KERNEL);
 	if (ret < 0)
-		goto out_free_dev;
+		goto out_free_pcpu;
 	device_id = ret;
 
 	init_rwsem(&zram->dev_lock);
@@ -3133,6 +3247,8 @@ static int zram_add(void)
 	put_disk(zram->disk);
 out_free_idr:
 	idr_remove(&zram_index_idr, device_id);
+out_free_pcpu:
+	free_percpu(zram->pcpu_stats);
 out_free_dev:
 	kfree(zram);
 	return ret;
@@ -3182,6 +3298,7 @@ static int zram_remove(struct zram *zram)
 	zram_reset_device(zram);
 
 	put_disk(zram->disk);
+	free_percpu(zram->pcpu_stats);
 	kfree(zram);
 	return 0;
 }
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 7a55d751417e2..482e1c28ca1ce 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -17,6 +17,7 @@
 
 #include <asm/byteorder.h>
 #include <linux/rwsem.h>
+#include <linux/u64_stats_sync.h>
 #include <linux/zsmalloc.h>
 
 #include "zcomp.h"
@@ -90,15 +91,19 @@ struct zram_table_entry {
 	};
 };
 
+struct zram_pcpu_stats {
+	struct u64_stats_sync syncp;
+	s64 pages_stored;	/* no. of pages currently stored */
+	s64 compr_data_size;	/* compressed size of pages stored */
+	s64 same_pages;		/* no. of same element filled pages */
+	s64 huge_pages;		/* no. of huge pages */
+	u64 notify_free;	/* no. of swap slot free notifications */
+};
+
 struct zram_stats {
-	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t failed_reads;	/* can happen when memory is too low */
 	atomic64_t failed_writes;	/* can happen when memory is too low */
-	atomic64_t notify_free;	/* no. of swap slot free notifications */
-	atomic64_t same_pages;		/* no. of same element filled pages */
-	atomic64_t huge_pages;		/* no. of huge pages */
 	atomic64_t huge_pages_since;	/* no. of huge pages since zram set up */
-	atomic64_t pages_stored;	/* no. of pages currently stored */
 	atomic_long_t max_used_pages;	/* no. of maximum pages stored */
 	atomic64_t miss_free;		/* no. of missed free */
 #ifdef	CONFIG_ZRAM_WRITEBACK
@@ -134,6 +139,7 @@ struct zram {
 	unsigned long limit_pages;
 
 	struct zram_stats stats;
+	struct zram_pcpu_stats __percpu *pcpu_stats;
 	/*
 	 * This is the limit on amount of *uncompressed* worth of data
 	 * we can store in a disk.
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7ef80e0da6267..eacd771bd5425 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -43,6 +43,7 @@
 #include <linux/zsmalloc.h>
 #include <linux/fs.h>
 #include <linux/workqueue.h>
+#include <linux/llist.h>
 #include "zpdesc.h"
 
 #define ZSPAGE_MAGIC	0x58
@@ -267,6 +268,21 @@ struct link_free {
 static struct kmem_cache *handle_cachep;
 static struct kmem_cache *zspage_cachep;
 
+#define ZS_DEFER_BATCH	64
+
+struct zs_defer_batch {
+	struct llist_node node;
+	unsigned int count;
+	unsigned long handles[ZS_DEFER_BATCH];
+};
+
+struct zs_defer_percpu {
+	struct zs_defer_batch *active;
+	struct llist_head pending;
+	struct work_struct drain_work;
+	struct zs_pool *pool;
+};
+
 struct zs_pool {
 	const char *name;
 
@@ -282,12 +298,12 @@ struct zs_pool {
 #ifdef CONFIG_ZSMALLOC_STAT
 	struct dentry *stat_dentry;
 #endif
-#ifdef CONFIG_COMPACTION
 	struct work_struct free_work;
-#endif
 	/* protect zspage migration/compaction */
 	rwlock_t lock;
 	atomic_t compaction_in_progress;
+
+	struct zs_defer_percpu __percpu *defer;
 };
 
 static inline void zpdesc_inc_zone_page_state(struct zpdesc *zpdesc)
@@ -428,13 +444,11 @@ static bool ZsHugePage(struct zspage *zspage)
 	return zspage->huge;
 }
 
-#ifdef CONFIG_COMPACTION
 static void kick_deferred_free(struct zs_pool *pool);
 static void init_deferred_free(struct zs_pool *pool);
+#ifdef CONFIG_COMPACTION
 static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage);
 #else
-static void kick_deferred_free(struct zs_pool *pool) {}
-static void init_deferred_free(struct zs_pool *pool) {}
 static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {}
 #endif
 
@@ -684,7 +698,6 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
 }
 #endif
 
-
 /*
  * For each size class, zspages are divided into different groups
  * depending on their usage ratio. This function returns fullness
@@ -1293,7 +1306,6 @@ static unsigned long obj_malloc(struct zs_pool *pool,
 	return obj;
 }
 
-
 /**
  * zs_malloc - Allocate block of given size from pool.
  * @pool: pool to allocate from
@@ -1371,7 +1383,6 @@ static void obj_free(int class_size, unsigned long obj)
 	unsigned int f_objidx;
 	void *vaddr;
 
-
 	obj_to_location(obj, &f_zpdesc, &f_objidx);
 	f_offset = offset_in_page(class_size * f_objidx);
 	zspage = get_zspage(f_zpdesc);
@@ -1447,7 +1458,7 @@ static inline void obj_class_get_and_lock(struct zs_pool *pool, unsigned long ha
 }
 #endif
 
-void zs_free(struct zs_pool *pool, unsigned long handle)
+static void __zs_free_one(struct zs_pool *pool, unsigned long handle)
 {
 	struct zspage *zspage;
 	unsigned long obj;
@@ -1455,9 +1466,6 @@ void zs_free(struct zs_pool *pool, unsigned long handle)
 	int fullness;
 	struct zspage *zspage_to_free = NULL;
 
-	if (IS_ERR_OR_NULL((void *)handle))
-		return;
-
 	obj_class_get_and_lock(pool, handle, &obj, &zspage, &class);
 
 	class_stat_sub(class, ZS_OBJS_INUSE, 1);
@@ -1483,6 +1491,78 @@ void zs_free(struct zs_pool *pool, unsigned long handle)
 	}
 	cache_free_handle(handle);
 }
+
+static void zs_defer_drain(struct zs_defer_percpu *defer)
+{
+	struct zs_pool *pool = defer->pool;
+	struct zs_defer_batch *batch, *n;
+	struct llist_node *first;
+
+	first = llist_del_all(&defer->pending);
+	llist_for_each_entry_safe(batch, n, first, node) {
+		unsigned int i;
+
+		for (i = 0; i < batch->count; i++)
+			__zs_free_one(pool, batch->handles[i]);
+		kfree(batch);
+		cond_resched();
+	}
+}
+
+static void zs_defer_drain_work(struct work_struct *work)
+{
+	zs_defer_drain(container_of(work, struct zs_defer_percpu, drain_work));
+}
+
+static bool zs_defer_push(struct zs_pool *pool, unsigned long handle)
+{
+	struct zs_defer_batch *new_batch = NULL, *batch;
+	struct zs_defer_percpu *defer;
+	bool queue = false;
+
+	if (!pool->defer)
+		return false;
+
+	defer = get_cpu_ptr(pool->defer);
+	if (!defer->active) {
+		put_cpu_ptr(pool->defer);
+		new_batch = kmalloc_obj(*new_batch, GFP_NOWAIT | __GFP_NOWARN);
+		if (!new_batch)
+			return false;
+		new_batch->count = 0;
+
+		defer = get_cpu_ptr(pool->defer);
+		if (!defer->active) {
+			defer->active = new_batch;
+			new_batch = NULL;
+		}
+	}
+
+	batch = defer->active;
+	batch->handles[batch->count++] = handle;
+	if (batch->count == ZS_DEFER_BATCH) {
+		llist_add(&batch->node, &defer->pending);
+		defer->active = NULL;
+		queue = true;
+	}
+	put_cpu_ptr(pool->defer);
+
+	if (unlikely(new_batch))
+		kfree(new_batch);
+
+	if (queue)
+		queue_work(system_dfl_wq, &defer->drain_work);
+	return true;
+}
+
+void zs_free(struct zs_pool *pool, unsigned long handle)
+{
+	if (IS_ERR_OR_NULL((void *)handle))
+		return;
+
+	if (!zs_defer_push(pool, handle))
+		__zs_free_one(pool, handle);
+}
 EXPORT_SYMBOL_GPL(zs_free);
 
 static void zs_object_copy(struct size_class *class, unsigned long dst,
@@ -1671,7 +1751,6 @@ static int putback_zspage(struct size_class *class, struct zspage *zspage)
 	return fullness;
 }
 
-#ifdef CONFIG_COMPACTION
 /*
  * To prevent zspage destroy during migration, zspage freeing should
  * hold locks of all pages in the zspage.
@@ -1714,6 +1793,8 @@ static void lock_zspage(struct zspage *zspage)
 	zspage_read_unlock(zspage);
 }
 
+#ifdef CONFIG_COMPACTION
+
 static void replace_sub_page(struct size_class *class, struct zspage *zspage,
 				struct zpdesc *newzpdesc, struct zpdesc *oldzpdesc)
 {
@@ -1866,6 +1947,18 @@ const struct movable_operations zsmalloc_mops = {
 	.putback_page = zs_page_putback,
 };
 
+static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
+{
+	struct zpdesc *zpdesc = get_first_zpdesc(zspage);
+
+	do {
+		WARN_ON(!zpdesc_trylock(zpdesc));
+		__zpdesc_set_movable(zpdesc);
+		zpdesc_unlock(zpdesc);
+	} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
+}
+#endif /* CONFIG_COMPACTION */
+
 /*
  * Caller should hold page_lock of all pages in the zspage
  * In here, we cannot use zspage meta data.
@@ -1904,7 +1997,7 @@ static void async_free_zspage(struct work_struct *work)
 
 static void kick_deferred_free(struct zs_pool *pool)
 {
-	schedule_work(&pool->free_work);
+	queue_work(system_dfl_wq, &pool->free_work);
 }
 
 static void zs_flush_migration(struct zs_pool *pool)
@@ -1917,20 +2010,6 @@ static void init_deferred_free(struct zs_pool *pool)
 	INIT_WORK(&pool->free_work, async_free_zspage);
 }
 
-static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
-{
-	struct zpdesc *zpdesc = get_first_zpdesc(zspage);
-
-	do {
-		WARN_ON(!zpdesc_trylock(zpdesc));
-		__zpdesc_set_movable(zpdesc);
-		zpdesc_unlock(zpdesc);
-	} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
-}
-#else
-static inline void zs_flush_migration(struct zs_pool *pool) { }
-#endif
-
 /*
  *
  * Based on the number of unused allocated objects calculate
@@ -2127,6 +2206,48 @@ static int calculate_zspage_chain_size(int class_size)
 	return chain_size;
 }
 
+static void zs_defer_destroy(struct zs_pool *pool)
+{
+	struct zs_defer_percpu __percpu *defer_pcp = pool->defer;
+	int cpu;
+
+	if (!defer_pcp)
+		return;
+
+	pool->defer = NULL;
+	for_each_possible_cpu(cpu) {
+		struct zs_defer_percpu *defer = per_cpu_ptr(defer_pcp, cpu);
+
+		cancel_work_sync(&defer->drain_work);
+		if (defer->active) {
+			llist_add(&defer->active->node, &defer->pending);
+			defer->active = NULL;
+		}
+		zs_defer_drain(defer);
+	}
+	free_percpu(defer_pcp);
+}
+
+static int zs_defer_init(struct zs_pool *pool)
+{
+	int cpu;
+
+	pool->defer = alloc_percpu(struct zs_defer_percpu);
+	if (!pool->defer)
+		return -ENOMEM;
+
+	for_each_possible_cpu(cpu) {
+		struct zs_defer_percpu *defer = per_cpu_ptr(pool->defer, cpu);
+
+		defer->active = NULL;
+		init_llist_head(&defer->pending);
+		defer->pool = pool;
+		INIT_WORK(&defer->drain_work, zs_defer_drain_work);
+	}
+
+	return 0;
+}
+
 /**
  * zs_create_pool - Creates an allocation pool to work from.
  * @name: pool name to be created
@@ -2151,6 +2272,10 @@ struct zs_pool *zs_create_pool(const char *name)
 	rwlock_init(&pool->lock);
 	atomic_set(&pool->compaction_in_progress, 0);
 
+	if (zs_defer_init(pool))
+		pr_info("deferred free unavailable for <%s>, freeing synchronously\n",
+			name);
+
 	pool->name = kstrdup(name, GFP_KERNEL);
 	if (!pool->name)
 		goto err;
@@ -2253,6 +2378,7 @@ void zs_destroy_pool(struct zs_pool *pool)
 	int i;
 
 	zs_unregister_shrinker(pool);
+	zs_defer_destroy(pool);
 	zs_flush_migration(pool);
 	zs_pool_stat_destroy(pool);
 

3/2 2026/10/20 20:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 12268
							output: 41
							thoughts: 687
						

Thoughts:
**My Assessment of This Patch: High Priority Fuzzing Target**

Okay, let's break this down. First, the diff targets two key areas: `zram` and `zsmalloc`. Zram, a virtual block device driver, and zsmalloc, a memory allocator heavily used by zram (and zswap), are both core components within the Linux kernel, especially in virtualized environments like QEMU and GCE.

The changes in `zram_drv.c` and `.h` are a shift to percpu stats. Replacing atomic64 counters with `zram_pcpu_stats`, and so forth, impacts critical paths for I/O, stats collection, and device management. This touches on write, read, slot freeing, discards, and more. This is certainly worth a close look with the fuzzers.

But the real red flag here is in `zsmalloc.c`. This isn't just a simple tweak; it introduces asynchronous, percpu *deferred freeing* with the new `zs_defer_batch`, workqueues, linked lists, and `zs_defer_push`. They are deferring freeing of memory objects, only falling back to immediate freeing when the batch is full. This means they are trying to improve performance by batching these `zs_free` calls.

This fundamentally alters the memory management of zsmalloc, changing the timing of object lifecycles, and introducing new locking semantics with percpu data. Deferred freeing is a classic recipe for introducing concurrency bugs, including races, use-after-free conditions, double frees, memory leaks, and lockdep issues. Considering this is core memory management code, there's a strong likelihood these changes will be interesting for fuzzing.

My experience tells me this is *definitely* fuzzable. Zram is easily configured in standard virtualized environments, and tools like syzkaller can easily exercise its block device functionality (read/write, sysfs attributes, trim/discard, etc.). We can quickly verify the required configs with `grepper` (looking for `CONFIG_ZRAM` and `CONFIG_ZSMALLOC`) and go from there. This is a high-priority target. I need to get this on the schedule.



4/2 2026/10/20 20:45 tool grepper
0m Args:
{
  "Expression": "config ZRAM|config ZSMALLOC",
  "PathPrefixes": [
    "drivers/block/zram/",
    "mm/"
  ]
}

Results:
{
  "Output": "drivers/block/zram/Kconfig-1-# SPDX-License-Identifier: GPL-2.0\ndrivers/block/zram/Kconfig:2:config ZRAM\ndrivers/block/zram/Kconfig-3-\ttristate \"Compressed RAM block device support\"\n--\ndrivers/block/zram/Kconfig-16-\ndrivers/block/zram/Kconfig:17:config ZRAM_BACKEND_LZ4\ndrivers/block/zram/Kconfig-18-\tbool \"lz4 compression support\"\n--\ndrivers/block/zram/Kconfig-22-\ndrivers/block/zram/Kconfig:23:config ZRAM_BACKEND_LZ4HC\ndrivers/block/zram/Kconfig-24-\tbool \"lz4hc compression support\"\n--\ndrivers/block/zram/Kconfig-28-\ndrivers/block/zram/Kconfig:29:config ZRAM_BACKEND_ZSTD\ndrivers/block/zram/Kconfig-30-\tbool \"zstd compression support\"\n--\ndrivers/block/zram/Kconfig-34-\ndrivers/block/zram/Kconfig:35:config ZRAM_BACKEND_DEFLATE\ndrivers/block/zram/Kconfig-36-\tbool \"deflate compression support\"\n--\ndrivers/block/zram/Kconfig-40-\ndrivers/block/zram/Kconfig:41:config ZRAM_BACKEND_842\ndrivers/block/zram/Kconfig-42-\tbool \"842 compression support\"\n--\ndrivers/block/zram/Kconfig-46-\ndrivers/block/zram/Kconfig:47:config ZRAM_BACKEND_FORCE_LZO\ndrivers/block/zram/Kconfig-48-\tdepends on ZRAM\n--\ndrivers/block/zram/Kconfig-52-\ndrivers/block/zram/Kconfig:53:config ZRAM_BACKEND_LZO\ndrivers/block/zram/Kconfig-54-\tbool \"lzo and lzo-rle compression support\" if !ZRAM_BACKEND_FORCE_LZO\n--\ndrivers/block/zram/Kconfig=60=choice\n--\ndrivers/block/zram/Kconfig-64-\ndrivers/block/zram/Kconfig:65:config ZRAM_DEF_COMP_LZORLE\ndrivers/block/zram/Kconfig-66-\tbool \"lzo-rle\"\n--\ndrivers/block/zram/Kconfig-68-\ndrivers/block/zram/Kconfig:69:config ZRAM_DEF_COMP_LZO\ndrivers/block/zram/Kconfig-70-\tbool \"lzo\"\n--\ndrivers/block/zram/Kconfig-72-\ndrivers/block/zram/Kconfig:73:config ZRAM_DEF_COMP_LZ4\ndrivers/block/zram/Kconfig-74-\tbool \"lz4\"\n--\ndrivers/block/zram/Kconfig-76-\ndrivers/block/zram/Kconfig:77:config ZRAM_DEF_COMP_LZ4HC\ndrivers/block/zram/Kconfig-78-\tbool \"lz4hc\"\n--\ndrivers/block/zram/Kconfig-80-\ndrivers/block/zram/Kconfig:81:config ZRAM_DEF_COMP_ZSTD\ndrivers/block/zram/Kconfig-82-\tbool \"zstd\"\n--\ndrivers/block/zram/Kconfig-84-\ndrivers/block/zram/Kconfig:85:config ZRAM_DEF_COMP_DEFLATE\ndrivers/block/zram/Kconfig-86-\tbool \"deflate\"\n--\ndrivers/block/zram/Kconfig-88-\ndrivers/block/zram/Kconfig:89:config ZRAM_DEF_COMP_842\ndrivers/block/zram/Kconfig-90-\tbool \"842\"\n--\ndrivers/block/zram/Kconfig=93=endchoice\ndrivers/block/zram/Kconfig-94-\ndrivers/block/zram/Kconfig:95:config ZRAM_DEF_COMP\ndrivers/block/zram/Kconfig-96-\tstring\n--\ndrivers/block/zram/Kconfig-106-\ndrivers/block/zram/Kconfig:107:config ZRAM_WRITEBACK\ndrivers/block/zram/Kconfig-108-       bool \"Write back incompressible or idle page to backing device\"\n--\ndrivers/block/zram/Kconfig-120-\ndrivers/block/zram/Kconfig:121:config ZRAM_TRACK_ENTRY_ACTIME\ndrivers/block/zram/Kconfig-122-\tbool \"Track access time of zram entries\"\n--\ndrivers/block/zram/Kconfig-128-\ndrivers/block/zram/Kconfig:129:config ZRAM_MEMORY_TRACKING\ndrivers/block/zram/Kconfig-130-\tbool \"Track zRam block status\"\n--\ndrivers/block/zram/Kconfig-139-\ndrivers/block/zram/Kconfig:140:config ZRAM_MULTI_COMP\ndrivers/block/zram/Kconfig-141-\tbool \"Enable multiple compression streams\"\n--\nmm/Kconfig=114=config ZSWAP_COMPRESSOR_DEFAULT\n--\nmm/Kconfig-124-\nmm/Kconfig:125:config ZSMALLOC\nmm/Kconfig-126-\ttristate\n--\nmm/Kconfig=131=comment \"Zsmalloc is a common backend allocator for zswap \u0026 zram\"\nmm/Kconfig-132-\nmm/Kconfig:133:config ZSMALLOC_STAT\nmm/Kconfig-134-\tbool \"Export zsmalloc statistics\"\n--\nmm/Kconfig-141-\nmm/Kconfig:142:config ZSMALLOC_CHAIN_SIZE\nmm/Kconfig-143-\tint \"Maximum number of physical pages per-zspage\"\n"
}

5/2 2026/10/20 20:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 14955
							output: 35
							thoughts: 21
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into ZRAM Configuration**

Okay, time to get my hands dirty. I need to understand the configuration options for ZRAM, so I'm heading straight to the source. Let's see... the `drivers/block/zram/Kconfig` file should hold the key. My immediate focus is on that `config ZRAM` directive. This should be where the core ZRAM support is defined, and likely where I'll find the main switch to enable or disable it, along with any relevant dependencies or dependencies on other features. Let's see what kinds of things we can change. Time to dig in and understand.



6/2 2026/10/20 20:45 tool read-file
0m Args:
{
  "File": "drivers/block/zram/Kconfig",
  "FirstLine": 1,
  "LineCount": 20
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0\n   2:\tconfig ZRAM\n   3:\t\ttristate \"Compressed RAM block device support\"\n   4:\t\tdepends on BLOCK \u0026\u0026 SYSFS \u0026\u0026 MMU\n   5:\t\tselect ZSMALLOC\n   6:\t\thelp\n   7:\t\t  Creates virtual block devices called /dev/zramX (X = 0, 1, ...).\n   8:\t\t  Pages written to these disks are compressed and stored in memory\n   9:\t\t  itself. These disks allow very fast I/O and compression provides\n  10:\t\t  good amounts of memory savings.\n  11:\t\n  12:\t\t  It has several use cases, for example: /tmp storage, use as swap\n  13:\t\t  disks and maybe many more.\n  14:\t\n  15:\t\t  See Documentation/admin-guide/blockdev/zram.rst for more information.\n  16:\t\n  17:\tconfig ZRAM_BACKEND_LZ4\n  18:\t\tbool \"lz4 compression support\"\n  19:\t\tdepends on ZRAM\n  20:\t\tselect LZ4_COMPRESS\n"
}

7/2 2026/10/20 20:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 15449
							output: 32
							thoughts: 15
						

Thoughts:
Okay, here's the summary, tailored for an expert audience, in the first person, reflecting the described thought process:

**Diving into the ZSMALLOC Configuration Space**

Alright, I'm thinking, "Let's not just focus on the core implementation; we need to perform a systematic check." My immediate thought is, "I should double check all relevant configuration options." It's likely I haven't missed anything here, but I can't be sure until I confirm. I need to make sure I haven't missed anything when setting this all up. So, my attention now turns to the mm/Kconfig files, specifically around the ZSMALLOC configuration options. I need to ensure that the dependencies, defaults, and potentially any conditional logic within those config files are completely aligned with the design, and also to see what changes there are that I may have overlooked. Any subtle interaction or unintended consequence lurking in the configuration space could derail the whole thing, or introduce a subtle bug. Time to meticulously trace through the relevant config options.



8/2 2026/10/20 20:45 tool read-file
0m Args:
{
  "File": "mm/Kconfig",
  "FirstLine": 120,
  "LineCount": 25
}

Results:
{
  "Contents": " 120:\t       default \"lz4\" if ZSWAP_COMPRESSOR_DEFAULT_LZ4\n 121:\t       default \"lz4hc\" if ZSWAP_COMPRESSOR_DEFAULT_LZ4HC\n 122:\t       default \"zstd\" if ZSWAP_COMPRESSOR_DEFAULT_ZSTD\n 123:\t       default \"\"\n 124:\t\n 125:\tconfig ZSMALLOC\n 126:\t\ttristate\n 127:\t\n 128:\tmenu \"Zsmalloc allocator options\"\n 129:\t\tdepends on ZSMALLOC\n 130:\t\n 131:\tcomment \"Zsmalloc is a common backend allocator for zswap \u0026 zram\"\n 132:\t\n 133:\tconfig ZSMALLOC_STAT\n 134:\t\tbool \"Export zsmalloc statistics\"\n 135:\t\tselect DEBUG_FS\n 136:\t\thelp\n 137:\t\t  This option enables code in the zsmalloc to collect various\n 138:\t\t  statistics about what's happening in zsmalloc and exports that\n 139:\t\t  information to userspace via debugfs.\n 140:\t\t  If unsure, say N.\n 141:\t\n 142:\tconfig ZSMALLOC_CHAIN_SIZE\n 143:\t\tint \"Maximum number of physical pages per-zspage\"\n 144:\t\tdefault 8\n"
}

9/2 2026/10/20 20:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 16086
							output: 32
							thoughts: 1962
						

Thoughts:
**Focusing on Key Changes in ZRAM and ZSMALLOC**

Okay, let's break this down. My primary focus is understanding the implications of these code changes, particularly in relation to fuzzing and targeted testing. I see that `ZRAM` directly selects `ZSMALLOC` – a crucial link. `ZSMALLOC` can also be selected by `ZSWAP` or `ZRAM`, and that direct config is important. I'm also noting the presence of `CONFIG_ZRAM_WRITEBACK`. It enables `zram_writeback_complete` which is modified in the patch, so that's definitely relevant. Specifically the stats updates in that function.

Looking further, `CONFIG_COMPACTION` is also important, and the changes within `mm/zsmalloc.c` include several new static functions, like `zs_defer_push`, `zs_defer_drain`, etc., and modified functions like `zs_free`, `__zs_free_one`. `zs_free` is exported, that's interesting and I need to keep that in mind. The new and moved functions related to deferred frees are also significant. Also, changes in zram_drv.c are there, including new `zram_pcpu_sum`, modified `zram_writeback_complete`, along with changes in block operations.

Now, the critical part for focusing the fuzzer: Which symbols make the most sense as "FocusSymbols"? I want to avoid generic, ubiquitous functions. Static functions in `.c` files *can* be used. I initially thought `zs_free` might be too ubiquitous, but then I realized it's *only* used by `zram` and `zswap` users. That's a good target! Based on the instructions, I want to list functions that specifically implement the logic being altered, or direct API entrypoints for the subsystem feature under review.

Therefore, the key symbols for fuzzing will be: `zs_defer_drain`, `zs_defer_drain_work`, `zs_defer_push`, `zram_pcpu_sum`, `slot_free`, `zs_free`, `zram_write_page`, `zram_writeback_complete`, `recompress_slot`. These should give us good coverage of the changes. I will also make sure to check what block device operations the zram provides and any sysfs interactions. Those provide entry points to focus on.

Finally, I need to check the configurations. `CONFIG_ZRAM`, `CONFIG_ZRAM_WRITEBACK` and `CONFIG_ZSMALLOC` are relevant, and `CONFIG_ZRAM_WRITEBACK` only depends on `ZRAM`. The patch doesn't seem to affect `ZRAM_MULTI_COMP`. `recompress_slot` is also under `#ifdef CONFIG_ZRAM_MULTI_COMP`? Need to double check and keep an eye on that.



10/2 2026/10/20 20:46 tool grepper
0m Args:
{
  "Expression": "recompress_slot",
  "PathPrefixes": [
    "drivers/block/zram/"
  ]
}

Results:
{
  "Output": "drivers/block/zram/zram_drv.c=2491=static void scan_slots_for_recompress(struct zram *zram, u32 mode, u32 prio,\n--\ndrivers/block/zram/zram_drv.c-2535- */\ndrivers/block/zram/zram_drv.c:2536:static int recompress_slot(struct zram *zram, unsigned long index,\ndrivers/block/zram/zram_drv.c-2537-\t\t\t   struct page *page, u64 *num_recomp_pages,\n--\ndrivers/block/zram/zram_drv.c=2648=static ssize_t recompress_store(struct device *dev,\n--\ndrivers/block/zram/zram_drv.c-2769-\ndrivers/block/zram/zram_drv.c:2770:\t\terr = recompress_slot(zram, pps-\u003eindex, page,\ndrivers/block/zram/zram_drv.c-2771-\t\t\t\t      \u0026num_recomp_pages, threshold, prio);\n"
}

11/2 2026/10/20 20:46 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 18992
							output: 36
							thoughts: 31
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert in the field:

**Debugging ZRAM Multi-Compilation**

Alright, let's get down to brass tacks. I need to quickly determine whether the `recompress_slot` or `recompress_store` functions are conditionalized behind the `#ifdef CONFIG_ZRAM_MULTI_COMP` preprocessor directive. This is a fundamental first step in understanding the compilation path and how the multi-compression feature impacts the code flow. Knowing this will immediately inform the next questions I need to ask: are these functions active in the current build configuration? Are they going to be a source of problems I need to trace? This initial check is a cornerstone to effective debugging of any conditional compilation issues. I'll need to know whether the code is compiled, and therefore even visible to the compiler, or if it is just a commented-out snippet of code.



12/2 2026/10/20 20:46 tool grepper
0m Args:
{
  "Expression": "CONFIG_ZRAM_MULTI_COMP",
  "PathPrefixes": [
    "drivers/block/zram/"
  ]
}

Results:
{
  "Output": "drivers/block/zram/zram_drv.c=219=static inline bool is_partial_io(struct bio_vec *bvec)\n--\ndrivers/block/zram/zram_drv.c-224-\ndrivers/block/zram/zram_drv.c:225:#if defined CONFIG_ZRAM_WRITEBACK || defined CONFIG_ZRAM_MULTI_COMP\ndrivers/block/zram/zram_drv.c-226-struct zram_pp_slot {\n--\ndrivers/block/zram/zram_drv.c=1887=static ssize_t comp_algorithm_store(struct device *dev,\n--\ndrivers/block/zram/zram_drv.c-1898-\ndrivers/block/zram/zram_drv.c:1899:#ifdef CONFIG_ZRAM_MULTI_COMP\ndrivers/block/zram/zram_drv.c-1900-static ssize_t recomp_algorithm_show(struct device *dev,\n--\ndrivers/block/zram/zram_drv.c=2467=static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec,\n--\ndrivers/block/zram/zram_drv.c-2474-\ndrivers/block/zram/zram_drv.c:2475:#ifdef CONFIG_ZRAM_MULTI_COMP\ndrivers/block/zram/zram_drv.c-2476-#define RECOMPRESS_IDLE\t\t(1 \u003c\u003c 0)\n--\ndrivers/block/zram/zram_drv.c=3122=static DEVICE_ATTR_RW(compressed_writeback);\ndrivers/block/zram/zram_drv.c-3123-#endif\ndrivers/block/zram/zram_drv.c:3124:#ifdef CONFIG_ZRAM_MULTI_COMP\ndrivers/block/zram/zram_drv.c-3125-static DEVICE_ATTR_RW(recomp_algorithm);\n--\ndrivers/block/zram/zram_drv.c=3130=static struct attribute *zram_disk_attrs[] = {\n--\ndrivers/block/zram/zram_drv.c-3150-\t\u0026dev_attr_debug_stat.attr,\ndrivers/block/zram/zram_drv.c:3151:#ifdef CONFIG_ZRAM_MULTI_COMP\ndrivers/block/zram/zram_drv.c-3152-\t\u0026dev_attr_recomp_algorithm.attr,\n--\ndrivers/block/zram/zram_drv.h=103=struct zram_stats {\n--\ndrivers/block/zram/zram_drv.h-115-\ndrivers/block/zram/zram_drv.h:116:#ifdef CONFIG_ZRAM_MULTI_COMP\ndrivers/block/zram/zram_drv.h-117-#define ZRAM_PRIMARY_COMP\t0U\n"
}

13/2 2026/10/20 20:46 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19991
							output: 277
							thoughts: 558
						

Thoughts:
**Triage Confirmation: ZRAM Fuzzing Target**

Okay, here's the breakdown of my thought process on this ZRAM fuzzing target. First thing, I zeroed in on the `recompress_slot` function and confirmed it's indeed guarded by `#ifdef CONFIG_ZRAM_MULTI_COMP` in `drivers/block/zram/zram_drv.c`, specifically at line 2475. This is important because the patch in question modifies how percpu stats are handled within this function. The presence of `ZRAM_MULTI_COMP` becomes highly relevant to the patch, therefore I checked its dependencies in `drivers/block/zram/Kconfig`. It's a clean `depends on ZRAM`, so no complicating factors there.

Next, I went through the triage instructions methodically, double-checking all the critical aspects.

1.  **Reachability:** ZRAM and zsmalloc are software-based. They function perfectly well within standard virtualized environments. Userspace interaction is straightforward via sysfs: create, configure, mount, direct I/O, trim, recompress, writeback, reset, read stats. Therefore, they are reachable. This is a crucial check.

2.  **WorthFuzzing:** This is a definitive yes. The changes in `mm/zsmalloc.c` introduce asynchronous deferred object freeing with per-cpu batches and workqueues, which is a good fuzz target. Moreover, modifications within `drivers/block/zram/` update statistics tracking from atomic counters to per-cpu stats using `u64_stats_sync`. This touches hot read/write/free/discard/writeback/recompression paths, meaning it's highly worth fuzzing.

3.  **FocusSymbols:** This is where I pulled out the targeted functions. A bunch of specific functions that aren't ubiquitous and are good targets.
    *   `zs_defer_push`, `zs_defer_drain`, `zs_defer_drain_work`, `zs_defer_init`, `zs_defer_destroy`, `zs_free` (zsmalloc deferred freeing)
    *   `zram_pcpu_sum`
    *   `slot_free`
    *   `write_same_filled_page`, `write_incompressible_page`, `zram_write_page`, `recompress_slot`, `zram_writeback_complete` (zram compression and writeback)

4.  **EnableConfigs:** Confirmed:
    *   `ZRAM`
    *   `ZSMALLOC`
    *   `ZRAM_WRITEBACK`
    *   `ZRAM_MULTI_COMP`

Everything here checks out based on my deep dive into the kernel source. Now, it's time to call `set-results`. I can confidently report that this is a solid fuzzing target, and the configuration and functions are all well-supported.



14/2 2026/10/20 20:46 tool set-results
0m Args:
{
  "EnableConfigs": [
    "ZRAM",
    "ZSMALLOC",
    "ZRAM_WRITEBACK",
    "ZRAM_MULTI_COMP"
  ],
  "FocusSymbols": [
    "zs_defer_push",
    "zs_defer_drain",
    "zs_defer_drain_work",
    "zs_free",
    "zs_defer_init",
    "zs_defer_destroy",
    "zram_pcpu_sum",
    "slot_free",
    "write_same_filled_page",
    "write_incompressible_page",
    "zram_write_page",
    "recompress_slot",
    "zram_writeback_complete"
  ],
  "Reasoning": "The patch modifies both the zsmalloc memory allocator and the zram virtual block driver. In zsmalloc, it introduces asynchronous batched deferred freeing of objects using per-CPU lists and workqueues, which alters the memory deallocation and concurrency model. In zram, it migrates core operational statistics to per-CPU counters with 64-bit sequence sync locks across block write, slot free, discard, writeback, and recompression paths. Both drivers are software-defined and directly reachable from user space in standard virtualized environments.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "ZRAM",
    "ZSMALLOC",
    "ZRAM_WRITEBACK",
    "ZRAM_MULTI_COMP"
  ],
  "FocusSymbols": [
    "zs_defer_push",
    "zs_defer_drain",
    "zs_defer_drain_work",
    "zs_free",
    "zs_defer_init",
    "zs_defer_destroy",
    "zram_pcpu_sum",
    "slot_free",
    "write_same_filled_page",
    "write_incompressible_page",
    "zram_write_page",
    "recompress_slot",
    "zram_writeback_complete"
  ],
  "Reasoning": "The patch modifies both the zsmalloc memory allocator and the zram virtual block driver. In zsmalloc, it introduces asynchronous batched deferred freeing of objects using per-CPU lists and workqueues, which alters the memory deallocation and concurrency model. In zram, it migrates core operational statistics to per-CPU counters with 64-bit sequence sync locks across block write, slot free, discard, writeback, and recompression paths. Both drivers are software-defined and directly reachable from user space in standard virtualized environments.",
  "WorthFuzzing": true
}

15/1 2026/10/20 20:46 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

16/2 2026/10/20 20:46 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch modifies zram and zsmalloc by:\n1. Converting several zram statistics (pages_stored, compr_data_size, same_pages, huge_pages, notify_free) from atomic64 counters to per-CPU stats using u64_stats_sync.\n2. Introducing a per-CPU batching mechanism for deferred frees in zsmalloc (zs_defer_batch).\n\nAnalysis of memory initialization and info-leak risks:\n- In zram_drv.c, `struct zram_stats_sum sum` is explicitly zeroed with `memset(sum, 0, sizeof(*sum))` before summing values across CPUs.\n- The stats are exported to user space exclusively via formatted ASCII strings (`sysfs_emit` in `io_stat_show` and `mm_stat_show`), not as raw kernel structures with padding.\n- `zram-\u003epcpu_stats` is allocated with `alloc_percpu()` which returns zeroed memory.\n- In `zsmalloc.c`, while `zs_defer_batch` is allocated using `kmalloc_obj()`, `batch-\u003ecount` is immediately initialized to 0 upon allocation, and `zs_defer_drain()` only accesses elements of `batch-\u003ehandles` from index 0 up to `batch-\u003ecount - 1`. No uninitialized entries are ever read or exposed.\n- All newly introduced local variables in `slot_free` and `zram_writeback_complete` are explicitly initialized.\n\nApplicability:\nThe changes primarily involve per-CPU data structures and asynchronous deferred freeing. Any bugs introduced (e.g. use-after-free, double free, concurrency/locking races, or memory leaks) are detectable by KASAN, LOCKDEP, or standard kernel debug mechanisms. No uninitialized memory reads or information leaks are introduced or exposed; therefore, a dedicated KMSAN fuzzing session is not required.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit a8d89ae963aa9b0d1b727be1b09253072ec3606f
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Oct 20 20:44:57 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 024402438bd1d..affe758a9543d 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -488,6 +488,56 @@ static ssize_t idle_store(struct device *dev, struct device_attribute *attr,
 	return len;
 }
 
+struct zram_stats_sum {
+	s64 pages_stored;
+	s64 compr_data_size;
+	s64 same_pages;
+	s64 huge_pages;
+	u64 notify_free;
+};
+
+#define zram_pcpu_add(zram_dev, field, val)					\
+do {									\
+	struct zram *__zram = (zram_dev);				\
+	struct zram_pcpu_stats *__stats;				\
+									\
+	__stats = get_cpu_ptr(__zram->pcpu_stats);			\
+	u64_stats_update_begin(&__stats->syncp);			\
+	WRITE_ONCE(__stats->field, __stats->field + (val));		\
+	u64_stats_update_end(&__stats->syncp);			\
+	put_cpu_ptr(__zram->pcpu_stats);				\
+} while (0)
+
+static void zram_pcpu_sum(struct zram *zram, struct zram_stats_sum *sum)
+{
+	int cpu;
+
+	memset(sum, 0, sizeof(*sum));
+
+	for_each_possible_cpu(cpu) {
+		struct zram_pcpu_stats *stats;
+		unsigned int start;
+		s64 pages, bytes, same, huge;
+		u64 notify;
+
+		stats = per_cpu_ptr(zram->pcpu_stats, cpu);
+		do {
+			start = u64_stats_fetch_begin(&stats->syncp);
+			pages = READ_ONCE(stats->pages_stored);
+			bytes = READ_ONCE(stats->compr_data_size);
+			same = READ_ONCE(stats->same_pages);
+			huge = READ_ONCE(stats->huge_pages);
+			notify = READ_ONCE(stats->notify_free);
+		} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+		sum->pages_stored += pages;
+		sum->compr_data_size += bytes;
+		sum->same_pages += same;
+		sum->huge_pages += huge;
+		sum->notify_free += notify;
+	}
+}
+
 #ifdef CONFIG_ZRAM_WRITEBACK
 #define INVALID_BDEV_BLOCK		(~0UL)
 
@@ -919,6 +969,8 @@ static void zram_account_writeback_submit(struct zram *zram)
 static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
 {
 	unsigned long index = req->pps->index;
+	struct zram_pcpu_stats *stats;
+	s64 huge, size;
 	int err;
 
 	err = blk_status_to_errno(req->bio.bi_status);
@@ -947,9 +999,14 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
 	}
 
 	clear_slot_flag(zram, index, ZRAM_IDLE);
-	if (test_slot_flag(zram, index, ZRAM_HUGE))
-		atomic64_dec(&zram->stats.huge_pages);
-	atomic64_sub(get_slot_size(zram, index), &zram->stats.compr_data_size);
+	huge = test_slot_flag(zram, index, ZRAM_HUGE) ? -1 : 0;
+	size = get_slot_size(zram, index);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->huge_pages, stats->huge_pages + huge);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size - size);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 	zs_free(zram->mem_pool, get_slot_handle(zram, index));
 	set_slot_handle(zram, index, req->blk_idx);
 	set_slot_flag(zram, index, ZRAM_WB);
@@ -1919,14 +1976,16 @@ static ssize_t io_stat_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
 	struct zram *zram = dev_to_zram(dev);
+	struct zram_stats_sum sum;
 	ssize_t ret;
 
 	guard(rwsem_read)(&zram->dev_lock);
+	zram_pcpu_sum(zram, &sum);
 	ret = sysfs_emit(buf,
 			"%8llu %8llu 0 %8llu\n",
 			(u64)atomic64_read(&zram->stats.failed_reads),
 			(u64)atomic64_read(&zram->stats.failed_writes),
-			(u64)atomic64_read(&zram->stats.notify_free));
+			sum.notify_free);
 
 	return ret;
 }
@@ -1936,6 +1995,7 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
 {
 	struct zram *zram = dev_to_zram(dev);
 	struct zs_pool_stats pool_stats;
+	struct zram_stats_sum sum;
 	u64 orig_size, mem_used = 0;
 	long max_used;
 	ssize_t ret;
@@ -1948,19 +2008,20 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
 		zs_pool_stats(zram->mem_pool, &pool_stats);
 	}
 
-	orig_size = atomic64_read(&zram->stats.pages_stored);
+	zram_pcpu_sum(zram, &sum);
+	orig_size = max_t(s64, sum.pages_stored, 0);
 	max_used = atomic_long_read(&zram->stats.max_used_pages);
 
 	ret = sysfs_emit(buf,
 			"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
 			orig_size << PAGE_SHIFT,
-			(u64)atomic64_read(&zram->stats.compr_data_size),
+			(u64)max_t(s64, sum.compr_data_size, 0),
 			mem_used << PAGE_SHIFT,
 			zram->limit_pages << PAGE_SHIFT,
 			max_used << PAGE_SHIFT,
-			(u64)atomic64_read(&zram->stats.same_pages),
+			(u64)max_t(s64, sum.same_pages, 0),
 			atomic_long_read(&pool_stats.pages_compacted),
-			(u64)atomic64_read(&zram->stats.huge_pages),
+			(u64)max_t(s64, sum.huge_pages, 0),
 			(u64)atomic64_read(&zram->stats.huge_pages_since));
 
 	return ret;
@@ -2027,6 +2088,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
 
 static void slot_free(struct zram *zram, unsigned long index)
 {
+	s64 pages = 0, bytes = 0, same = 0, huge = 0;
+	struct zram_pcpu_stats *stats;
 	unsigned long handle;
 
 #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
@@ -2044,7 +2107,7 @@ static void slot_free(struct zram *zram, unsigned long index)
 		 * ZRAM_HUGE flag for deferred decompression path.
 		 */
 		if (!test_slot_flag(zram, index, ZRAM_WB))
-			atomic64_dec(&zram->stats.huge_pages);
+			huge = -1;
 		clear_slot_flag(zram, index, ZRAM_HUGE);
 	}
 
@@ -2060,22 +2123,32 @@ static void slot_free(struct zram *zram, unsigned long index)
 	 */
 	if (test_slot_flag(zram, index, ZRAM_SAME)) {
 		clear_slot_flag(zram, index, ZRAM_SAME);
-		atomic64_dec(&zram->stats.same_pages);
+		same = -1;
 		goto out;
 	}
 
 	handle = get_slot_handle(zram, index);
 	if (!handle)
-		return;
+		goto stats;
 
 	zs_free(zram->mem_pool, handle);
 
-	atomic64_sub(get_slot_size(zram, index),
-		     &zram->stats.compr_data_size);
+	bytes = -(s64)get_slot_size(zram, index);
 out:
-	atomic64_dec(&zram->stats.pages_stored);
+	pages = -1;
 	set_slot_handle(zram, index, 0);
 	set_slot_size(zram, index, 0);
+stats:
+	if (!(pages | bytes | same | huge))
+		return;
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + pages);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + bytes);
+	WRITE_ONCE(stats->same_pages, stats->same_pages + same);
+	WRITE_ONCE(stats->huge_pages, stats->huge_pages + huge);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 }
 
 static int read_same_filled_page(struct zram *zram, struct page *page,
@@ -2237,14 +2310,20 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
 static int write_same_filled_page(struct zram *zram, unsigned long fill,
 				  unsigned long index)
 {
+	struct zram_pcpu_stats *stats;
+
 	slot_lock(zram, index);
 	slot_free(zram, index);
 	set_slot_flag(zram, index, ZRAM_SAME);
 	set_slot_handle(zram, index, fill);
 	slot_unlock(zram, index);
 
-	atomic64_inc(&zram->stats.same_pages);
-	atomic64_inc(&zram->stats.pages_stored);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->same_pages, stats->same_pages + 1);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 
 	return 0;
 }
@@ -2252,6 +2331,7 @@ static int write_same_filled_page(struct zram *zram, unsigned long fill,
 static int write_incompressible_page(struct zram *zram, struct page *page,
 				     unsigned long index)
 {
+	struct zram_pcpu_stats *stats;
 	unsigned long handle;
 	void *src;
 
@@ -2282,10 +2362,14 @@ static int write_incompressible_page(struct zram *zram, struct page *page,
 	set_slot_size(zram, index, PAGE_SIZE);
 	slot_unlock(zram, index);
 
-	atomic64_add(PAGE_SIZE, &zram->stats.compr_data_size);
-	atomic64_inc(&zram->stats.huge_pages);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + PAGE_SIZE);
+	WRITE_ONCE(stats->huge_pages, stats->huge_pages + 1);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 	atomic64_inc(&zram->stats.huge_pages_since);
-	atomic64_inc(&zram->stats.pages_stored);
 
 	return 0;
 }
@@ -2293,6 +2377,7 @@ static int write_incompressible_page(struct zram *zram, struct page *page,
 static int zram_write_page(struct zram *zram, struct page *page,
 			   unsigned long index)
 {
+	struct zram_pcpu_stats *stats;
 	int ret = 0;
 	unsigned long handle;
 	unsigned int comp_len;
@@ -2348,8 +2433,12 @@ static int zram_write_page(struct zram *zram, struct page *page,
 	slot_unlock(zram, index);
 
 	/* Update stats */
-	atomic64_inc(&zram->stats.pages_stored);
-	atomic64_add(comp_len, &zram->stats.compr_data_size);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + comp_len);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 
 	return ret;
 }
@@ -2449,6 +2538,7 @@ static int recompress_slot(struct zram *zram, unsigned long index,
 			   u32 threshold, u32 prio)
 {
 	struct zcomp_strm *zstrm = NULL;
+	struct zram_pcpu_stats *stats;
 	unsigned long handle_old;
 	unsigned long handle_new;
 	unsigned int comp_len_old;
@@ -2545,8 +2635,12 @@ static int recompress_slot(struct zram *zram, unsigned long index,
 	set_slot_size(zram, index, comp_len_new);
 	set_slot_comp_priority(zram, index, prio);
 
-	atomic64_add(comp_len_new, &zram->stats.compr_data_size);
-	atomic64_inc(&zram->stats.pages_stored);
+	stats = get_cpu_ptr(zram->pcpu_stats);
+	u64_stats_update_begin(&stats->syncp);
+	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + comp_len_new);
+	WRITE_ONCE(stats->pages_stored, stats->pages_stored + 1);
+	u64_stats_update_end(&stats->syncp);
+	put_cpu_ptr(zram->pcpu_stats);
 
 	return 0;
 }
@@ -2724,7 +2818,7 @@ static void zram_bio_discard(struct zram *zram, struct bio *bio)
 		slot_lock(zram, index);
 		slot_free(zram, index);
 		slot_unlock(zram, index);
-		atomic64_inc(&zram->stats.notify_free);
+		zram_pcpu_add(zram, notify_free, 1);
 		index++;
 		n -= PAGE_SIZE;
 	}
@@ -2825,7 +2919,7 @@ static void zram_slot_free_notify(struct block_device *bdev,
 
 	zram = bdev->bd_disk->private_data;
 
-	atomic64_inc(&zram->stats.notify_free);
+	zram_pcpu_add(zram, notify_free, 1);
 	if (!slot_trylock(zram, index)) {
 		atomic64_inc(&zram->stats.miss_free);
 		return;
@@ -2866,6 +2960,8 @@ static void zram_destroy_comps(struct zram *zram)
 
 static void zram_reset_device(struct zram *zram)
 {
+	int cpu;
+
 	guard(rwsem_write)(&zram->dev_lock);
 
 	zram->limit_pages = 0;
@@ -2877,6 +2973,16 @@ static void zram_reset_device(struct zram *zram)
 	zram_meta_free(zram, zram->disksize);
 	zram->disksize = 0;
 	zram_destroy_comps(zram);
+	for_each_possible_cpu(cpu) {
+		struct zram_pcpu_stats *stats;
+
+		stats = per_cpu_ptr(zram->pcpu_stats, cpu);
+		stats->pages_stored = 0;
+		stats->compr_data_size = 0;
+		stats->same_pages = 0;
+		stats->huge_pages = 0;
+		stats->notify_free = 0;
+	}
 	memset(&zram->stats, 0, sizeof(zram->stats));
 	reset_bdev(zram);
 }
@@ -3083,15 +3189,23 @@ static int zram_add(void)
 						  BLK_FEAT_SYNCHRONOUS,
 	};
 	struct zram *zram;
-	int ret, device_id;
+	int cpu, ret, device_id;
 
 	zram = kzalloc_obj(struct zram);
 	if (!zram)
 		return -ENOMEM;
 
+	zram->pcpu_stats = alloc_percpu(struct zram_pcpu_stats);
+	if (!zram->pcpu_stats) {
+		ret = -ENOMEM;
+		goto out_free_dev;
+	}
+	for_each_possible_cpu(cpu)
+		u64_stats_init(&per_cpu_ptr(zram->pcpu_stats, cpu)->syncp);
+
 	ret = idr_alloc(&zram_index_idr, zram, 0, 0, GFP_KERNEL);
 	if (ret < 0)
-		goto out_free_dev;
+		goto out_free_pcpu;
 	device_id = ret;
 
 	init_rwsem(&zram->dev_lock);
@@ -3133,6 +3247,8 @@ static int zram_add(void)
 	put_disk(zram->disk);
 out_free_idr:
 	idr_remove(&zram_index_idr, device_id);
+out_free_pcpu:
+	free_percpu(zram->pcpu_stats);
 out_free_dev:
 	kfree(zram);
 	return ret;
@@ -3182,6 +3298,7 @@ static int zram_remove(struct zram *zram)
 	zram_reset_device(zram);
 
 	put_disk(zram->disk);
+	free_percpu(zram->pcpu_stats);
 	kfree(zram);
 	return 0;
 }
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 7a55d751417e2..482e1c28ca1ce 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -17,6 +17,7 @@
 
 #include <asm/byteorder.h>
 #include <linux/rwsem.h>
+#include <linux/u64_stats_sync.h>
 #include <linux/zsmalloc.h>
 
 #include "zcomp.h"
@@ -90,15 +91,19 @@ struct zram_table_entry {
 	};
 };
 
+struct zram_pcpu_stats {
+	struct u64_stats_sync syncp;
+	s64 pages_stored;	/* no. of pages currently stored */
+	s64 compr_data_size;	/* compressed size of pages stored */
+	s64 same_pages;		/* no. of same element filled pages */
+	s64 huge_pages;		/* no. of huge pages */
+	u64 notify_free;	/* no. of swap slot free notifications */
+};
+
 struct zram_stats {
-	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t failed_reads;	/* can happen when memory is too low */
 	atomic64_t failed_writes;	/* can happen when memory is too low */
-	atomic64_t notify_free;	/* no. of swap slot free notifications */
-	atomic64_t same_pages;		/* no. of same element filled pages */
-	atomic64_t huge_pages;		/* no. of huge pages */
 	atomic64_t huge_pages_since;	/* no. of huge pages since zram set up */
-	atomic64_t pages_stored;	/* no. of pages currently stored */
 	atomic_long_t max_used_pages;	/* no. of maximum pages stored */
 	atomic64_t miss_free;		/* no. of missed free */
 #ifdef	CONFIG_ZRAM_WRITEBACK
@@ -134,6 +139,7 @@ struct zram {
 	unsigned long limit_pages;
 
 	struct zram_stats stats;
+	struct zram_pcpu_stats __percpu *pcpu_stats;
 	/*
 	 * This is the limit on amount of *uncompressed* worth of data
 	 * we can store in a disk.
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7ef80e0da6267..eacd771bd5425 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -43,6 +43,7 @@
 #include <linux/zsmalloc.h>
 #include <linux/fs.h>
 #include <linux/workqueue.h>
+#include <linux/llist.h>
 #include "zpdesc.h"
 
 #define ZSPAGE_MAGIC	0x58
@@ -267,6 +268,21 @@ struct link_free {
 static struct kmem_cache *handle_cachep;
 static struct kmem_cache *zspage_cachep;
 
+#define ZS_DEFER_BATCH	64
+
+struct zs_defer_batch {
+	struct llist_node node;
+	unsigned int count;
+	unsigned long handles[ZS_DEFER_BATCH];
+};
+
+struct zs_defer_percpu {
+	struct zs_defer_batch *active;
+	struct llist_head pending;
+	struct work_struct drain_work;
+	struct zs_pool *pool;
+};
+
 struct zs_pool {
 	const char *name;
 
@@ -282,12 +298,12 @@ struct zs_pool {
 #ifdef CONFIG_ZSMALLOC_STAT
 	struct dentry *stat_dentry;
 #endif
-#ifdef CONFIG_COMPACTION
 	struct work_struct free_work;
-#endif
 	/* protect zspage migration/compaction */
 	rwlock_t lock;
 	atomic_t compaction_in_progress;
+
+	struct zs_defer_percpu __percpu *defer;
 };
 
 static inline void zpdesc_inc_zone_page_state(struct zpdesc *zpdesc)
@@ -428,13 +444,11 @@ static bool ZsHugePage(struct zspage *zspage)
 	return zspage->huge;
 }
 
-#ifdef CONFIG_COMPACTION
 static void kick_deferred_free(struct zs_pool *pool);
 static void init_deferred_free(struct zs_pool *pool);
+#ifdef CONFIG_COMPACTION
 static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage);
 #else
-static void kick_deferred_free(struct zs_pool *pool) {}
-static void init_deferred_free(struct zs_pool *pool) {}
 static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {}
 #endif
 
@@ -684,7 +698,6 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
 }
 #endif
 
-
 /*
  * For each size class, zspages are divided into different groups
  * depending on their usage ratio. This function returns fullness
@@ -1293,7 +1306,6 @@ static unsigned long obj_malloc(struct zs_pool *pool,
 	return obj;
 }
 
-
 /**
  * zs_malloc - Allocate block of given size from pool.
  * @pool: pool to allocate from
@@ -1371,7 +1383,6 @@ static void obj_free(int class_size, unsigned long obj)
 	unsigned int f_objidx;
 	void *vaddr;
 
-
 	obj_to_location(obj, &f_zpdesc, &f_objidx);
 	f_offset = offset_in_page(class_size * f_objidx);
 	zspage = get_zspage(f_zpdesc);
@@ -1447,7 +1458,7 @@ static inline void obj_class_get_and_lock(struct zs_pool *pool, unsigned long ha
 }
 #endif
 
-void zs_free(struct zs_pool *pool, unsigned long handle)
+static void __zs_free_one(struct zs_pool *pool, unsigned long handle)
 {
 	struct zspage *zspage;
 	unsigned long obj;
@@ -1455,9 +1466,6 @@ void zs_free(struct zs_pool *pool, unsigned long handle)
 	int fullness;
 	struct zspage *zspage_to_free = NULL;
 
-	if (IS_ERR_OR_NULL((void *)handle))
-		return;
-
 	obj_class_get_and_lock(pool, handle, &obj, &zspage, &class);
 
 	class_stat_sub(class, ZS_OBJS_INUSE, 1);
@@ -1483,6 +1491,78 @@ void zs_free(struct zs_pool *pool, unsigned long handle)
 	}
 	cache_free_handle(handle);
 }
+
+static void zs_defer_drain(struct zs_defer_percpu *defer)
+{
+	struct zs_pool *pool = defer->pool;
+	struct zs_defer_batch *batch, *n;
+	struct llist_node *first;
+
+	first = llist_del_all(&defer->pending);
+	llist_for_each_entry_safe(batch, n, first, node) {
+		unsigned int i;
+
+		for (i = 0; i < batch->count; i++)
+			__zs_free_one(pool, batch->handles[i]);
+		kfree(batch);
+		cond_resched();
+	}
+}
+
+static void zs_defer_drain_work(struct work_struct *work)
+{
+	zs_defer_drain(container_of(work, struct zs_defer_percpu, drain_work));
+}
+
+static bool zs_defer_push(struct zs_pool *pool, unsigned long handle)
+{
+	struct zs_defer_batch *new_batch = NULL, *batch;
+	struct zs_defer_percpu *defer;
+	bool queue = false;
+
+	if (!pool->defer)
+		return false;
+
+	defer = get_cpu_ptr(pool->defer);
+	if (!defer->active) {
+		put_cpu_ptr(pool->defer);
+		new_batch = kmalloc_obj(*new_batch, GFP_NOWAIT | __GFP_NOWARN);
+		if (!new_batch)
+			return false;
+		new_batch->count = 0;
+
+		defer = get_cpu_ptr(pool->defer);
+		if (!defer->active) {
+			defer->active = new_batch;
+			new_batch = NULL;
+		}
+	}
+
+	batch = defer->active;
+	batch->handles[batch->count++] = handle;
+	if (batch->count == ZS_DEFER_BATCH) {
+		llist_add(&batch->node, &defer->pending);
+		defer->active = NULL;
+		queue = true;
+	}
+	put_cpu_ptr(pool->defer);
+
+	if (unlikely(new_batch))
+		kfree(new_batch);
+
+	if (queue)
+		queue_work(system_dfl_wq, &defer->drain_work);
+	return true;
+}
+
+void zs_free(struct zs_pool *pool, unsigned long handle)
+{
+	if (IS_ERR_OR_NULL((void *)handle))
+		return;
+
+	if (!zs_defer_push(pool, handle))
+		__zs_free_one(pool, handle);
+}
 EXPORT_SYMBOL_GPL(zs_free);
 
 static void zs_object_copy(struct size_class *class, unsigned long dst,
@@ -1671,7 +1751,6 @@ static int putback_zspage(struct size_class *class, struct zspage *zspage)
 	return fullness;
 }
 
-#ifdef CONFIG_COMPACTION
 /*
  * To prevent zspage destroy during migration, zspage freeing should
  * hold locks of all pages in the zspage.
@@ -1714,6 +1793,8 @@ static void lock_zspage(struct zspage *zspage)
 	zspage_read_unlock(zspage);
 }
 
+#ifdef CONFIG_COMPACTION
+
 static void replace_sub_page(struct size_class *class, struct zspage *zspage,
 				struct zpdesc *newzpdesc, struct zpdesc *oldzpdesc)
 {
@@ -1866,6 +1947,18 @@ const struct movable_operations zsmalloc_mops = {
 	.putback_page = zs_page_putback,
 };
 
+static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
+{
+	struct zpdesc *zpdesc = get_first_zpdesc(zspage);
+
+	do {
+		WARN_ON(!zpdesc_trylock(zpdesc));
+		__zpdesc_set_movable(zpdesc);
+		zpdesc_unlock(zpdesc);
+	} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
+}
+#endif /* CONFIG_COMPACTION */
+
 /*
  * Caller should hold page_lock of all pages in the zspage
  * In here, we cannot use zspage meta data.
@@ -1904,7 +1997,7 @@ static void async_free_zspage(struct work_struct *work)
 
 static void kick_deferred_free(struct zs_pool *pool)
 {
-	schedule_work(&pool->free_work);
+	queue_work(system_dfl_wq, &pool->free_work);
 }
 
 static void zs_flush_migration(struct zs_pool *pool)
@@ -1917,20 +2010,6 @@ static void init_deferred_free(struct zs_pool *pool)
 	INIT_WORK(&pool->free_work, async_free_zspage);
 }
 
-static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
-{
-	struct zpdesc *zpdesc = get_first_zpdesc(zspage);
-
-	do {
-		WARN_ON(!zpdesc_trylock(zpdesc));
-		__zpdesc_set_movable(zpdesc);
-		zpdesc_unlock(zpdesc);
-	} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
-}
-#else
-static inline void zs_flush_migration(struct zs_pool *pool) { }
-#endif
-
 /*
  *
  * Based on the number of unused allocated objects calculate
@@ -2127,6 +2206,48 @@ static int calculate_zspage_chain_size(int class_size)
 	return chain_size;
 }
 
+static void zs_defer_destroy(struct zs_pool *pool)
+{
+	struct zs_defer_percpu __percpu *defer_pcp = pool->defer;
+	int cpu;
+
+	if (!defer_pcp)
+		return;
+
+	pool->defer = NULL;
+	for_each_possible_cpu(cpu) {
+		struct zs_defer_percpu *defer = per_cpu_ptr(defer_pcp, cpu);
+
+		cancel_work_sync(&defer->drain_work);
+		if (defer->active) {
+			llist_add(&defer->active->node, &defer->pending);
+			defer->active = NULL;
+		}
+		zs_defer_drain(defer);
+	}
+	free_percpu(defer_pcp);
+}
+
+static int zs_defer_init(struct zs_pool *pool)
+{
+	int cpu;
+
+	pool->defer = alloc_percpu(struct zs_defer_percpu);
+	if (!pool->defer)
+		return -ENOMEM;
+
+	for_each_possible_cpu(cpu) {
+		struct zs_defer_percpu *defer = per_cpu_ptr(pool->defer, cpu);
+
+		defer->active = NULL;
+		init_llist_head(&defer->pending);
+		defer->pool = pool;
+		INIT_WORK(&defer->drain_work, zs_defer_drain_work);
+	}
+
+	return 0;
+}
+
 /**
  * zs_create_pool - Creates an allocation pool to work from.
  * @name: pool name to be created
@@ -2151,6 +2272,10 @@ struct zs_pool *zs_create_pool(const char *name)
 	rwlock_init(&pool->lock);
 	atomic_set(&pool->compaction_in_progress, 0);
 
+	if (zs_defer_init(pool))
+		pr_info("deferred free unavailable for <%s>, freeing synchronously\n",
+			name);
+
 	pool->name = kstrdup(name, GFP_KERNEL);
 	if (!pool->name)
 		goto err;
@@ -2253,6 +2378,7 @@ void zs_destroy_pool(struct zs_pool *pool)
 	int i;
 
 	zs_unregister_shrinker(pool);
+	zs_defer_destroy(pool);
 	zs_flush_migration(pool);
 	zs_pool_stat_destroy(pool);
 

17/3 2026/10/20 20:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 11480
							output: 33
							thoughts: 2145
						

Thoughts:
**Patch Analysis: zram Statistics and Deferred Freeing in zsmalloc**

Okay, let's break this down. This patch touches zram statistics and introduces deferred freeing in zsmalloc. First, I see modifications to `drivers/block/zram/zram_drv.c` and `.h`. The main change here seems to be the introduction of `struct zram_pcpu_stats`. This moves certain zram statistics, like `pages_stored` and `compr_data_size`, from global atomic64 counters to per-CPU counters. That's good; it should reduce contention, particularly on multi-core systems. The code uses `zram_pcpu_sum` to aggregate these per-CPU statistics. Importantly, I see `memset(sum, 0, sizeof(*sum))` is used, ensuring that the `sum` struct is initialized to zero before accumulation, eliminating potential uninitialized memory reads. The `io_stat_show` and `mm_stat_show` functions then display these calculated sums via `sysfs_emit`. The `zram_reset_device` function now also resets the `pcpu_stats` correctly, and the `zram_add/remove` functions handle the per-CPU memory allocation/deallocation properly. `alloc_percpu` is used, so it's initialized. Also, `u64_stats_init` is called, even if it's a no-op on our architecture.

Now, the more interesting bit: `mm/zsmalloc.c`. The core of this patch seems to be implementing deferred freeing. The idea is to batch free operations to improve efficiency. This uses `zs_defer_batch`, `zs_defer_percpu`, `zs_defer_push`, `zs_defer_drain`, and `zs_defer_destroy`. The allocation of `new_batch` uses `kmalloc_obj`, which *doesn't* zero the memory, but the code seems safe. The `count` member is explicitly initialized to 0, and the `handles` array is only ever read up to `count`. Crucially, nothing reads beyond the valid `count` in the `handles` array, and nothing copies the `batch` to userspace. In `zs_defer_destroy`, the code correctly drains the pending batches. My initial concern about uninitialized reads in `new_batch` is unfounded; the code *does* initialize `new_batch->count = 0` and only accesses `handles` up to that `count`.

I then see that `zram_stats_sum` is zeroed by memset and, therefore, safe from uninitialized reads. `alloc_percpu` also zero-initializes the allocated memory for the per-CPU stats. I'm satisfied that there is no risk of information leaks.

I then check `zs_flush_migration`. It appears to be redefined with `CONFIG_COMPACTION`, and my first thought is that the behaviour may be changed, but that doesn't appear to be the case.

Okay, I've checked the important parts. The patch seems solid regarding memory safety and potential information leaks.



18/3 2026/10/20 20:46 tool grepper
0m Args:
{
  "Expression": "zs_flush_migration",
  "PathPrefixes": [
    "mm/zsmalloc.c"
  ]
}

Results:
{
  "Output": "mm/zsmalloc.c=1998=static void kick_deferred_free(struct zs_pool *pool)\n--\nmm/zsmalloc.c-2002-\nmm/zsmalloc.c:2003:static void zs_flush_migration(struct zs_pool *pool)\nmm/zsmalloc.c-2004-{\n--\nmm/zsmalloc.c=2376=void zs_destroy_pool(struct zs_pool *pool)\n--\nmm/zsmalloc.c-2381-\tzs_defer_destroy(pool);\nmm/zsmalloc.c:2382:\tzs_flush_migration(pool);\nmm/zsmalloc.c-2383-\tzs_pool_stat_destroy(pool);\n"
}

19/3 2026/10/20 20:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 14532
							output: 36
							thoughts: 21
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `mm/zsmalloc.c`**

Okay, time to get my hands dirty. I need to zero in on a specific point in the `mm/zsmalloc.c` file. Given my prior experience with memory management, especially in the context of zsmalloc, I have a good idea of what's happening around this area. My intuition tells me that line 2000 is likely a critical point, maybe within a key function or a data structure declaration. Let's start there. I'll load up the source code and jump directly to that line. From there, I'll quickly scan the surrounding context: the preceding and following lines, the function definitions, the comments... all to get a high-level understanding of what's going on at that particular location. I'm expecting to either find the root of an issue I'm tracking down or a starting point for deeper investigation. My goal is to grasp the code's behavior at that level of granularity to gain an understanding of it at a conceptual level. Let's see what that snippet reveals.



20/3 2026/10/20 20:46 tool read-file
0m Args:
{
  "File": "mm/zsmalloc.c",
  "FirstLine": 1995,
  "LineCount": 40
}

Results:
{
  "Contents": "1995:\t\t}\n1996:\t};\n1997:\t\n1998:\tstatic void kick_deferred_free(struct zs_pool *pool)\n1999:\t{\n2000:\t\tqueue_work(system_dfl_wq, \u0026pool-\u003efree_work);\n2001:\t}\n2002:\t\n2003:\tstatic void zs_flush_migration(struct zs_pool *pool)\n2004:\t{\n2005:\t\tflush_work(\u0026pool-\u003efree_work);\n2006:\t}\n2007:\t\n2008:\tstatic void init_deferred_free(struct zs_pool *pool)\n2009:\t{\n2010:\t\tINIT_WORK(\u0026pool-\u003efree_work, async_free_zspage);\n2011:\t}\n2012:\t\n2013:\t/*\n2014:\t *\n2015:\t * Based on the number of unused allocated objects calculate\n2016:\t * and return the number of pages that we can free.\n2017:\t */\n2018:\tstatic unsigned long zs_can_compact(struct size_class *class)\n2019:\t{\n2020:\t\tunsigned long obj_wasted;\n2021:\t\tunsigned long obj_allocated = class_stat_read(class, ZS_OBJS_ALLOCATED);\n2022:\t\tunsigned long obj_used = class_stat_read(class, ZS_OBJS_INUSE);\n2023:\t\n2024:\t\tif (obj_allocated \u003c= obj_used)\n2025:\t\t\treturn 0;\n2026:\t\n2027:\t\tobj_wasted = obj_allocated - obj_used;\n2028:\t\tobj_wasted /= class-\u003eobjs_per_zspage;\n2029:\t\n2030:\t\treturn obj_wasted * class-\u003epages_per_zspage;\n2031:\t}\n2032:\t\n2033:\tstatic unsigned long __zs_compact(struct zs_pool *pool,\n2034:\t\t\t\t\t  struct size_class *class)\n"
}

21/3 2026/10/20 20:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 15403
							output: 36
							thoughts: 33
						

Thoughts:
Okay, here's my take on those thoughts, framed as a first-person expert summary:

**Digging into zsmalloc's Deferred Operations**

Alright, time to get my hands dirty. I need to zero in on how zsmalloc handles deferrals, specifically the push and drain mechanisms. My immediate focus is on `zs_defer_push` and `zs_defer_drain`, the core functions. I’ll need to meticulously examine the implementation of those functions within `mm/zsmalloc.c`, of course. I'll need to pay close attention to the surrounding code as well, as deferred operations often involve a complex web of interactions with other zsmalloc subsystems. I'll be looking for potential race conditions, edge cases, and memory leaks that might be lurking in the interactions between push and drain calls. Knowing zsmalloc, it's probably going to require some real deep diving to understand all the locking and data structures involved, but this is critical for understanding its performance characteristics and stability.



22/3 2026/10/20 20:46 tool read-file
0m Args:
{
  "File": "mm/zsmalloc.c",
  "FirstLine": 1490,
  "LineCount": 80
}

Results:
{
  "Contents": "1490:\t\t\tatomic_long_sub(class-\u003epages_per_zspage, \u0026pool-\u003epages_allocated);\n1491:\t\t}\n1492:\t\tcache_free_handle(handle);\n1493:\t}\n1494:\t\n1495:\tstatic void zs_defer_drain(struct zs_defer_percpu *defer)\n1496:\t{\n1497:\t\tstruct zs_pool *pool = defer-\u003epool;\n1498:\t\tstruct zs_defer_batch *batch, *n;\n1499:\t\tstruct llist_node *first;\n1500:\t\n1501:\t\tfirst = llist_del_all(\u0026defer-\u003epending);\n1502:\t\tllist_for_each_entry_safe(batch, n, first, node) {\n1503:\t\t\tunsigned int i;\n1504:\t\n1505:\t\t\tfor (i = 0; i \u003c batch-\u003ecount; i++)\n1506:\t\t\t\t__zs_free_one(pool, batch-\u003ehandles[i]);\n1507:\t\t\tkfree(batch);\n1508:\t\t\tcond_resched();\n1509:\t\t}\n1510:\t}\n1511:\t\n1512:\tstatic void zs_defer_drain_work(struct work_struct *work)\n1513:\t{\n1514:\t\tzs_defer_drain(container_of(work, struct zs_defer_percpu, drain_work));\n1515:\t}\n1516:\t\n1517:\tstatic bool zs_defer_push(struct zs_pool *pool, unsigned long handle)\n1518:\t{\n1519:\t\tstruct zs_defer_batch *new_batch = NULL, *batch;\n1520:\t\tstruct zs_defer_percpu *defer;\n1521:\t\tbool queue = false;\n1522:\t\n1523:\t\tif (!pool-\u003edefer)\n1524:\t\t\treturn false;\n1525:\t\n1526:\t\tdefer = get_cpu_ptr(pool-\u003edefer);\n1527:\t\tif (!defer-\u003eactive) {\n1528:\t\t\tput_cpu_ptr(pool-\u003edefer);\n1529:\t\t\tnew_batch = kmalloc_obj(*new_batch, GFP_NOWAIT | __GFP_NOWARN);\n1530:\t\t\tif (!new_batch)\n1531:\t\t\t\treturn false;\n1532:\t\t\tnew_batch-\u003ecount = 0;\n1533:\t\n1534:\t\t\tdefer = get_cpu_ptr(pool-\u003edefer);\n1535:\t\t\tif (!defer-\u003eactive) {\n1536:\t\t\t\tdefer-\u003eactive = new_batch;\n1537:\t\t\t\tnew_batch = NULL;\n1538:\t\t\t}\n1539:\t\t}\n1540:\t\n1541:\t\tbatch = defer-\u003eactive;\n1542:\t\tbatch-\u003ehandles[batch-\u003ecount++] = handle;\n1543:\t\tif (batch-\u003ecount == ZS_DEFER_BATCH) {\n1544:\t\t\tllist_add(\u0026batch-\u003enode, \u0026defer-\u003epending);\n1545:\t\t\tdefer-\u003eactive = NULL;\n1546:\t\t\tqueue = true;\n1547:\t\t}\n1548:\t\tput_cpu_ptr(pool-\u003edefer);\n1549:\t\n1550:\t\tif (unlikely(new_batch))\n1551:\t\t\tkfree(new_batch);\n1552:\t\n1553:\t\tif (queue)\n1554:\t\t\tqueue_work(system_dfl_wq, \u0026defer-\u003edrain_work);\n1555:\t\treturn true;\n1556:\t}\n1557:\t\n1558:\tvoid zs_free(struct zs_pool *pool, unsigned long handle)\n1559:\t{\n1560:\t\tif (IS_ERR_OR_NULL((void *)handle))\n1561:\t\t\treturn;\n1562:\t\n1563:\t\tif (!zs_defer_push(pool, handle))\n1564:\t\t\t__zs_free_one(pool, handle);\n1565:\t}\n1566:\tEXPORT_SYMBOL_GPL(zs_free);\n1567:\t\n1568:\tstatic void zs_object_copy(struct size_class *class, unsigned long dst,\n1569:\t\t\t\t\tunsigned long src)\n"
}

23/3 2026/10/20 20:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 16830
							output: 433
							thoughts: 2880
						

Thoughts:
**KMSAN Assessment: No Uninitialized Memory Risks Detected**

Alright, let's break this down. My goal here is to determine whether this patch introducing per-CPU stats and deferred object freeing in zram requires KMSAN (Kernel Memory Sanitizer) testing. The rule is clear: KMSAN is only needed if this patch introduces *unique* uninitialized memory or information leak risks that are not already detectable by KASAN (Kernel Address Sanitizer), LOCKDEP, or other standard kernel bug detectors. So, is that the case?

First, I examined `zs_defer_push`. I meticulously traced the potential read paths of the `defer->active` batch and `batch->handles`. The critical check here is to make certain that no uninitialized memory is ever read. It appears that `defer->active` is correctly handled, being either new or already active. Also, `batch->count` is initialized to zero, and the code consistently only reads up to the valid `count` elements in `batch->handles`. There are race conditions here to be sure, and they're asynchronous frees, use-after-free conditions, double-frees and potential memory leaks with the deferred queue, but this is handled by KASAN and standard tools, not KMSAN.

Next, I looked at how the zram statistics are accessed and presented. `zram_pcpu_sum` sums the per-CPU stats. I confirmed that the sum struct (`sum`) is initialized with `memset` to zero *before* any data is read. Additionally, the per-CPU statistics themselves are allocated using `alloc_percpu`, which guarantees zero initialization. These stats are then printed via `sysfs_emit`, meaning that formatted text strings are passed to user space, not the raw binary structs, so, no memory leaks or issues.

I verified the initialization of variables in functions such as `zram_writeback_complete` and `slot_free` to ensure that all local variables, especially counter variables, were explicitly initialized.

Finally, I checked `zram_add`, which shows how the per-CPU stats were allocated using `alloc_percpu`.

The patch *does* modify how data is freed (deferred freeing with `zsmalloc`) and how per-CPU stats are handled. This means there are new opportunities for concurrency bugs (race conditions, use-after-free, double-free conditions), which are what I checked for.

*   No data structures are being directly exposed to user space with uninitialized content.
*   All variables and data structures are correctly initialized.
*   The deferred freeing mechanism is protected such that only valid memory is read.

Therefore, since the patch *does not* introduce any new *unique* risks of uninitialized memory use or information leaks, I am confident in declaring that KMSAN is not required. The bugs potentially introduced (races and freed memory) are the kinds of errors caught by KASAN, not KMSAN. NeedsKMSAN should be set to `false`.



24/3 2026/10/20 20:47 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch modifies zram and zsmalloc by:\n1. Converting several zram statistics (pages_stored, compr_data_size, same_pages, huge_pages, notify_free) from atomic64 counters to per-CPU stats using u64_stats_sync.\n2. Introducing a per-CPU batching mechanism for deferred frees in zsmalloc (zs_defer_batch).\n\nAnalysis of memory initialization and info-leak risks:\n- In zram_drv.c, `struct zram_stats_sum sum` is explicitly zeroed with `memset(sum, 0, sizeof(*sum))` before summing values across CPUs.\n- The stats are exported to user space exclusively via formatted ASCII strings (`sysfs_emit` in `io_stat_show` and `mm_stat_show`), not as raw kernel structures with padding.\n- `zram-\u003epcpu_stats` is allocated with `alloc_percpu()` which returns zeroed memory.\n- In `zsmalloc.c`, while `zs_defer_batch` is allocated using `kmalloc_obj()`, `batch-\u003ecount` is immediately initialized to 0 upon allocation, and `zs_defer_drain()` only accesses elements of `batch-\u003ehandles` from index 0 up to `batch-\u003ecount - 1`. No uninitialized entries are ever read or exposed.\n- All newly introduced local variables in `slot_free` and `zram_writeback_complete` are explicitly initialized.\n\nApplicability:\nThe changes primarily involve per-CPU data structures and asynchronous deferred freeing. Any bugs introduced (e.g. use-after-free, double free, concurrency/locking races, or memory leaks) are detectable by KASAN, LOCKDEP, or standard kernel debug mechanisms. No uninitialized memory reads or information leaks are introduced or exposed; therefore, a dedicated KMSAN fuzzing session is not required.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch modifies zram and zsmalloc by:\n1. Converting several zram statistics (pages_stored, compr_data_size, same_pages, huge_pages, notify_free) from atomic64 counters to per-CPU stats using u64_stats_sync.\n2. Introducing a per-CPU batching mechanism for deferred frees in zsmalloc (zs_defer_batch).\n\nAnalysis of memory initialization and info-leak risks:\n- In zram_drv.c, `struct zram_stats_sum sum` is explicitly zeroed with `memset(sum, 0, sizeof(*sum))` before summing values across CPUs.\n- The stats are exported to user space exclusively via formatted ASCII strings (`sysfs_emit` in `io_stat_show` and `mm_stat_show`), not as raw kernel structures with padding.\n- `zram-\u003epcpu_stats` is allocated with `alloc_percpu()` which returns zeroed memory.\n- In `zsmalloc.c`, while `zs_defer_batch` is allocated using `kmalloc_obj()`, `batch-\u003ecount` is immediately initialized to 0 upon allocation, and `zs_defer_drain()` only accesses elements of `batch-\u003ehandles` from index 0 up to `batch-\u003ecount - 1`. No uninitialized entries are ever read or exposed.\n- All newly introduced local variables in `slot_free` and `zram_writeback_complete` are explicitly initialized.\n\nApplicability:\nThe changes primarily involve per-CPU data structures and asynchronous deferred freeing. Any bugs introduced (e.g. use-after-free, double free, concurrency/locking races, or memory leaks) are detectable by KASAN, LOCKDEP, or standard kernel debug mechanisms. No uninitialized memory reads or information leaks are introduced or exposed; therefore, a dedicated KMSAN fuzzing session is not required.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)