lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220612105937.30862-1-wuchi.zero@gmail.com>
Date:   Sun, 12 Jun 2022 18:59:37 +0800
From:   wuchi <wuchi.zero@...il.com>
To:     akpm@...ux-foundation.org, alexs@...nel.org, sjhuang@...vatar.ai,
        sfr@...b.auug.org.au
Cc:     linux-kernel@...r.kernel.org
Subject: [PATCH] lib/genalloc: Set chunk size to real size which gen_pool managed.

The demand size (chunk->avail > size > round_down(chunk->avail)) will
lead to meaningless algo calls in gen_pool_alloc_algo_owner without the
patch, alse move the follow code:
	size = nbits << order
out of read-side critical section.

Signed-off-by: wuchi <wuchi.zero@...il.com>
---
 lib/genalloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/genalloc.c b/lib/genalloc.c
index 00fc50d0a640..1b1843613fb8 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -193,6 +193,7 @@ int gen_pool_add_owner(struct gen_pool *pool, unsigned long virt, phys_addr_t ph
 	if (unlikely(chunk == NULL))
 		return -ENOMEM;
 
+	size = nbits << pool->min_alloc_order;
 	chunk->phys_addr = phys;
 	chunk->start_addr = virt;
 	chunk->end_addr = virt + size - 1;
@@ -293,6 +294,7 @@ unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
 		return 0;
 
 	nbits = (size + (1UL << order) - 1) >> order;
+	size = nbits << order;
 	rcu_read_lock();
 	list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
 		if (size > atomic_long_read(&chunk->avail))
@@ -314,7 +316,6 @@ unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
 		}
 
 		addr = chunk->start_addr + ((unsigned long)start_bit << order);
-		size = nbits << order;
 		atomic_long_sub(size, &chunk->avail);
 		if (owner)
 			*owner = chunk->owner;
@@ -499,6 +500,7 @@ void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr, size_t size,
 		*owner = NULL;
 
 	nbits = (size + (1UL << order) - 1) >> order;
+	size = nbits << order;
 	rcu_read_lock();
 	list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
 		if (addr >= chunk->start_addr && addr <= chunk->end_addr) {
@@ -506,7 +508,6 @@ void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr, size_t size,
 			start_bit = (addr - chunk->start_addr) >> order;
 			remain = bitmap_clear_ll(chunk->bits, start_bit, nbits);
 			BUG_ON(remain);
-			size = nbits << order;
 			atomic_long_add(size, &chunk->avail);
 			if (owner)
 				*owner = chunk->owner;
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ