Skip to content

Commit 074b851

Browse files
Dimitri SivanichAl Viro
authored andcommitted
vfs: fix panic in __d_lookup() with high dentry hashtable counts
When the number of dentry cache hash table entries gets too high (2147483648 entries), as happens by default on a 16TB system, use of a signed integer in the dcache_init() initialization loop prevents the dentry_hashtable from getting initialized, causing a panic in __d_lookup(). Fix this in dcache_init() and similar areas. Signed-off-by: Dimitri Sivanich <sivanich@sgi.com> Acked-by: David S. Miller <davem@davemloft.net> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 1d6f209 commit 074b851

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎fs/dcache.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,7 @@ __setup("dhash_entries=", set_dhash_entries);
29682968

29692969
static void __init dcache_init_early(void)
29702970
{
2971-
int loop;
2971+
unsigned int loop;
29722972

29732973
/* If hashes are distributed across NUMA nodes, defer
29742974
* hash allocation until vmalloc space is available.
@@ -2986,13 +2986,13 @@ static void __init dcache_init_early(void)
29862986
&d_hash_mask,
29872987
0);
29882988

2989-
for (loop = 0; loop < (1 << d_hash_shift); loop++)
2989+
for (loop = 0; loop < (1U << d_hash_shift); loop++)
29902990
INIT_HLIST_BL_HEAD(dentry_hashtable + loop);
29912991
}
29922992

29932993
static void __init dcache_init(void)
29942994
{
2995-
int loop;
2995+
unsigned int loop;
29962996

29972997
/*
29982998
* A constructor could be added for stable state like the lists,
@@ -3016,7 +3016,7 @@ static void __init dcache_init(void)
30163016
&d_hash_mask,
30173017
0);
30183018

3019-
for (loop = 0; loop < (1 << d_hash_shift); loop++)
3019+
for (loop = 0; loop < (1U << d_hash_shift); loop++)
30203020
INIT_HLIST_BL_HEAD(dentry_hashtable + loop);
30213021
}
30223022

‎fs/inode.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ __setup("ihash_entries=", set_ihash_entries);
16511651
*/
16521652
void __init inode_init_early(void)
16531653
{
1654-
int loop;
1654+
unsigned int loop;
16551655

16561656
/* If hashes are distributed across NUMA nodes, defer
16571657
* hash allocation until vmalloc space is available.
@@ -1669,13 +1669,13 @@ void __init inode_init_early(void)
16691669
&i_hash_mask,
16701670
0);
16711671

1672-
for (loop = 0; loop < (1 << i_hash_shift); loop++)
1672+
for (loop = 0; loop < (1U << i_hash_shift); loop++)
16731673
INIT_HLIST_HEAD(&inode_hashtable[loop]);
16741674
}
16751675

16761676
void __init inode_init(void)
16771677
{
1678-
int loop;
1678+
unsigned int loop;
16791679

16801680
/* inode slab cache */
16811681
inode_cachep = kmem_cache_create("inode_cache",
@@ -1699,7 +1699,7 @@ void __init inode_init(void)
16991699
&i_hash_mask,
17001700
0);
17011701

1702-
for (loop = 0; loop < (1 << i_hash_shift); loop++)
1702+
for (loop = 0; loop < (1U << i_hash_shift); loop++)
17031703
INIT_HLIST_HEAD(&inode_hashtable[loop]);
17041704
}
17051705

‎kernel/pid.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,12 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns)
543543
*/
544544
void __init pidhash_init(void)
545545
{
546-
int i, pidhash_size;
546+
unsigned int i, pidhash_size;
547547

548548
pid_hash = alloc_large_system_hash("PID", sizeof(*pid_hash), 0, 18,
549549
HASH_EARLY | HASH_SMALL,
550550
&pidhash_shift, NULL, 4096);
551-
pidhash_size = 1 << pidhash_shift;
551+
pidhash_size = 1U << pidhash_shift;
552552

553553
for (i = 0; i < pidhash_size; i++)
554554
INIT_HLIST_HEAD(&pid_hash[i]);

‎mm/page_alloc.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,6 +5236,7 @@ void *__init alloc_large_system_hash(const char *tablename,
52365236
max = ((unsigned long long)nr_all_pages << PAGE_SHIFT) >> 4;
52375237
do_div(max, bucketsize);
52385238
}
5239+
max = min(max, 0x80000000ULL);
52395240

52405241
if (numentries > max)
52415242
numentries = max;

‎net/ipv4/tcp.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,8 @@ void __init tcp_init(void)
32403240
{
32413241
struct sk_buff *skb = NULL;
32423242
unsigned long limit;
3243-
int i, max_share, cnt;
3243+
int max_share, cnt;
3244+
unsigned int i;
32443245
unsigned long jiffy = jiffies;
32453246

32463247
BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb));
@@ -3283,7 +3284,7 @@ void __init tcp_init(void)
32833284
&tcp_hashinfo.bhash_size,
32843285
NULL,
32853286
64 * 1024);
3286-
tcp_hashinfo.bhash_size = 1 << tcp_hashinfo.bhash_size;
3287+
tcp_hashinfo.bhash_size = 1U << tcp_hashinfo.bhash_size;
32873288
for (i = 0; i < tcp_hashinfo.bhash_size; i++) {
32883289
spin_lock_init(&tcp_hashinfo.bhash[i].lock);
32893290
INIT_HLIST_HEAD(&tcp_hashinfo.bhash[i].chain);

0 commit comments

Comments
 (0)