Return-Path: Received: from mail-by2nam03on0101.outbound.protection.outlook.com ([104.47.42.101]:39731 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932596AbeARVEf (ORCPT ); Thu, 18 Jan 2018 16:04:35 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Stephen Bates , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [added to the 4.1 stable tree] lib/genalloc.c: make the avail variable an atomic_long_t Date: Thu, 18 Jan 2018 21:01:06 +0000 Message-ID: <20180118205908.3220-192-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Stephen Bates This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 36a3d1dd4e16bcd0d2ddfb4a2ec7092f0ae0d931 ] If the amount of resources allocated to a gen_pool exceeds 2^32 then the avail atomic overflows and this causes problems when clients try and borrow resources from the pool. This is only expected to be an issue on 64 bit systems. Add the header to pull in atomic_long* operations. So that 32 bit systems continue to use atomic32_t but 64 bit systems can use atomic64_t. Link: http://lkml.kernel.org/r/1509033843-25667-1-git-send-email-sbates@rai= thlin.com Signed-off-by: Stephen Bates Reviewed-by: Logan Gunthorpe Reviewed-by: Mathieu Desnoyers Reviewed-by: Daniel Mentz Cc: Jonathan Corbet Cc: Andrew Morton Cc: Will Deacon Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/genalloc.h | 3 ++- lib/genalloc.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h index 1ccaab44abcc..ec78cd93c0c1 100644 --- a/include/linux/genalloc.h +++ b/include/linux/genalloc.h @@ -31,6 +31,7 @@ #define __GENALLOC_H__ =20 #include +#include =20 struct device; struct device_node; @@ -66,7 +67,7 @@ struct gen_pool { */ struct gen_pool_chunk { struct list_head next_chunk; /* next chunk in pool */ - atomic_t avail; + atomic_long_t avail; phys_addr_t phys_addr; /* physical starting address of memory chunk */ unsigned long start_addr; /* start address of memory chunk */ unsigned long end_addr; /* end address of memory chunk (inclusive) */ diff --git a/lib/genalloc.c b/lib/genalloc.c index d214866eeea2..59dafa4ff412 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -193,7 +193,7 @@ int gen_pool_add_virt(struct gen_pool *pool, unsigned l= ong virt, phys_addr_t phy chunk->phys_addr =3D phys; chunk->start_addr =3D virt; chunk->end_addr =3D virt + size - 1; - atomic_set(&chunk->avail, size); + atomic_long_set(&chunk->avail, size); =20 spin_lock(&pool->lock); list_add_rcu(&chunk->next_chunk, &pool->chunks); @@ -284,7 +284,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, siz= e_t size) nbits =3D (size + (1UL << order) - 1) >> order; rcu_read_lock(); list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) { - if (size > atomic_read(&chunk->avail)) + if (size > atomic_long_read(&chunk->avail)) continue; =20 end_bit =3D chunk_size(chunk) >> order; @@ -303,7 +303,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, siz= e_t size) =20 addr =3D chunk->start_addr + ((unsigned long)start_bit << order); size =3D nbits << order; - atomic_sub(size, &chunk->avail); + atomic_long_sub(size, &chunk->avail); break; } rcu_read_unlock(); @@ -369,7 +369,7 @@ void gen_pool_free(struct gen_pool *pool, unsigned long= addr, size_t size) remain =3D bitmap_clear_ll(chunk->bits, start_bit, nbits); BUG_ON(remain); size =3D nbits << order; - atomic_add(size, &chunk->avail); + atomic_long_add(size, &chunk->avail); rcu_read_unlock(); return; } @@ -443,7 +443,7 @@ size_t gen_pool_avail(struct gen_pool *pool) =20 rcu_read_lock(); list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) - avail +=3D atomic_read(&chunk->avail); + avail +=3D atomic_long_read(&chunk->avail); rcu_read_unlock(); return avail; } --=20 2.11.0