From 56827c3630c7f0e913fdac1811c0de167c95f268 Mon Sep 17 00:00:00 2001 From: CY Fan Date: Wed, 9 Feb 2022 17:06:20 +0800 Subject: [PATCH] hyperhold: fix undefined reference to `__aeabi_uldivmod` error ohos inclusion category: bugfix issue: #I4T0KA CVE: NA ----------------- This patch fixes undefined reference to `__aeabi_uldivmod` error when make allmodconfig on arm32. In a 32-bit system, if a or b is a 64-bit value, you cannot simply use a/b, but need to use a special division function, such as do_div(a, b), div_u64(a, b) and so on. Signed-off-by: CY Fan --- drivers/hyperhold/hp_core.c | 6 +++--- drivers/hyperhold/hp_space.c | 2 +- include/linux/zswapd.h | 4 ++++ mm/memcg_control.c | 4 ++-- mm/zswapd.c | 22 +++++++++++----------- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/hyperhold/hp_core.c b/drivers/hyperhold/hp_core.c index 86a9e4704f2e..0d80b88452d0 100644 --- a/drivers/hyperhold/hp_core.c +++ b/drivers/hyperhold/hp_core.c @@ -287,7 +287,7 @@ int hyperhold_addr_extent(u64 addr) if (!CHECK_INITED) return -EINVAL; - eid = addr / hyperhold.spc.ext_size; + eid = div_u64(addr, hyperhold.spc.ext_size); spc = space_of(eid); if (!CHECK(spc, "invalid eid %u!\n", eid)) return -EINVAL; @@ -302,7 +302,7 @@ int hyperhold_addr_offset(u64 addr) if (!CHECK_INITED) return -EINVAL; - return addr % hyperhold.spc.ext_size; + return do_div(addr, hyperhold.spc.ext_size); } EXPORT_SYMBOL(hyperhold_addr_offset); @@ -578,7 +578,7 @@ static int hpio_submit(struct hpio *hpio) bio_set_dev(bio, dev->bdev); ext_size = space_of(hpio->eid)->ext_size; - sec = (u64)hpio->eid * ext_size / dev->sec_size; + sec = div_u64((u64)hpio->eid * ext_size, dev->sec_size); bio->bi_iter.bi_sector = sec; for (i = 0; i < hpio->nr_page; i++) { if (!hpio->pages[i]) diff --git a/drivers/hyperhold/hp_space.c b/drivers/hyperhold/hp_space.c index 95d42d064290..cb3d3439c5a6 100644 --- a/drivers/hyperhold/hp_space.c +++ b/drivers/hyperhold/hp_space.c @@ -41,7 +41,7 @@ bool init_space(struct hp_space *spc, u64 dev_size, u32 ext_size) return false; } spc->ext_size = ext_size; - spc->nr_ext = dev_size / ext_size; + spc->nr_ext = div_u64(dev_size, ext_size); atomic_set(&spc->last_alloc_bit, 0); atomic_set(&spc->nr_alloced, 0); init_waitqueue_head(&spc->empty_wq); diff --git a/include/linux/zswapd.h b/include/linux/zswapd.h index 44cd060b12e4..f549137f71b0 100644 --- a/include/linux/zswapd.h +++ b/include/linux/zswapd.h @@ -93,6 +93,10 @@ static struct group_swap_device *register_group_swap(struct group_swap_ops *ops, static void unregister_group_swap(struct group_swap_device *gsdev) { } + +static void memcg_eswap_info_show(struct seq_file *m) +{ +} #endif #endif /* _LINUX_ZSWAPD_H */ diff --git a/mm/memcg_control.c b/mm/memcg_control.c index d56a2ba665b6..985fcaa66943 100644 --- a/mm/memcg_control.c +++ b/mm/memcg_control.c @@ -339,11 +339,11 @@ static u64 memcg_ub_ufs2zram_ratio_read(struct cgroup_subsys_state *css, struct static int memcg_force_swapin_write(struct cgroup_subsys_state *css, struct cftype *cft, u64 val) { struct mem_cgroup *memcg = mem_cgroup_from_css(css); - unsigned long size; + u64 size; const unsigned int ratio = 100; size = memcg_data_size(memcg, SWAP_SIZE); - size = atomic64_read(&memcg->memcg_reclaimed.ub_ufs2zram_ratio) * size / ratio; + size = div_u64(atomic64_read(&memcg->memcg_reclaimed.ub_ufs2zram_ratio) * size, ratio); swapin_memcg(memcg, size); diff --git a/mm/zswapd.c b/mm/zswapd.c index 577d97974229..36e8ffd42b73 100644 --- a/mm/zswapd.c +++ b/mm/zswapd.c @@ -250,7 +250,7 @@ static bool get_memcg_anon_refault_status(struct mem_cgroup *memcg) { const unsigned int percent_constant = 100; unsigned long long anon_pagefault; - unsigned long anon_total; + unsigned long long anon_total; unsigned long long ratio; struct mem_cgroup_per_node *mz = NULL; struct lruvec *lruvec = NULL; @@ -274,8 +274,8 @@ static bool get_memcg_anon_refault_status(struct mem_cgroup *memcg) lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, MAX_NR_ZONES) + memcg_data_size(memcg, SWAP_PAGE) + memcg_data_size(memcg, CACHE_PAGE); - ratio = (anon_pagefault - memcg->memcg_reclaimed.reclaimed_pagefault) * - percent_constant / (anon_total + 1); + ratio = div64_u64((anon_pagefault - memcg->memcg_reclaimed.reclaimed_pagefault) * + percent_constant, (anon_total + 1)); if (ratio > atomic_read(&memcg->memcg_reclaimed.refault_threshold)) return true; @@ -294,8 +294,8 @@ static bool get_area_anon_refault_status(void) if (anon_pagefault == last_anon_pagefault || time == last_snapshot_time) return false; - ratio = (anon_pagefault - last_anon_pagefault) * percent_constant / - (jiffies_to_msecs(time - last_snapshot_time) + 1); + ratio = div_u64((anon_pagefault - last_anon_pagefault) * percent_constant, + (jiffies_to_msecs(time - last_snapshot_time) + 1)); anon_refault_ratio = ratio; if (ratio > get_area_anon_refault_threshold()) @@ -396,7 +396,7 @@ int get_zram_current_watermark(void) /* after_comp to before_comp */ diff_buffers *= get_compress_ratio(); /* page to ratio */ - diff_buffers = diff_buffers * percent_constant / nr_total; + diff_buffers = div64_s64(diff_buffers * percent_constant, nr_total); return min(zram_wm_ratio, zram_wm_ratio - diff_buffers); } @@ -410,7 +410,7 @@ bool zram_watermark_ok(void) ratio = get_zram_current_watermark(); nr_zram_used = get_zram_used_pages(); - nr_wm = totalram_pages() * ratio / percent_constant; + nr_wm = div_u64(totalram_pages() * ratio, percent_constant); if (nr_zram_used > nr_wm) return true; @@ -592,8 +592,8 @@ static bool zswapd_shrink_anon(pg_data_t *pgdat, struct scan_control *sc) nr_zram = memcg_data_size(memcg, CACHE_PAGE); nr_eswap = memcg_data_size(memcg, SWAP_PAGE); - zram_ratio = (nr_zram + nr_eswap) * percent_constant / - (nr_inactive + nr_active + nr_zram + nr_eswap + 1); + zram_ratio = div64_u64((nr_zram + nr_eswap) * percent_constant, + (nr_inactive + nr_active + nr_zram + nr_eswap + 1)); if (zram_ratio >= (u32)atomic_read(&memcg->memcg_reclaimed.ub_mem2zram_ratio)) { count_vm_event(ZSWAPD_MEMCG_RATIO_SKIP); continue; @@ -637,7 +637,7 @@ static u64 __calc_nr_to_reclaim(void) reclaim_size = min(reclaim_size, max_reclaim_size); /* MB to pages */ - return reclaim_size * SZ_1M / PAGE_SIZE; + return div_u64(reclaim_size * SZ_1M, PAGE_SIZE); } static void zswapd_shrink_node(pg_data_t *pgdat) @@ -706,7 +706,7 @@ u64 zram_watermark_diff(void) ratio = get_zram_current_watermark(); nr_zram_used = get_zram_used_pages(); - nr_wm = totalram_pages() * ratio / percent_constant; + nr_wm = div_u64(totalram_pages() * ratio, percent_constant); if (nr_zram_used > nr_wm) return (nr_zram_used - nr_wm) * PAGE_SIZE + SWAP_MORE_ZRAM; -- Gitee