git: 32988c1499f8 - main - vfs cache: fix a hang when bumping vnode limit too high
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 02 Sep 2023 14:47:37 UTC
The branch main has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=32988c1499f8698b41e15ed40a46d271e757bba3
commit 32988c1499f8698b41e15ed40a46d271e757bba3
Author: Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-09-02 14:27:33 +0000
Commit: Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-09-02 14:45:27 +0000
vfs cache: fix a hang when bumping vnode limit too high
Overflow in cache_changesize would make the value flip to 0 and stay
there as 0 << 1 does not do anything.
Note callers limit the outcome to something below u_int.
Also note there entire vnode handling thing both in vfs layer as a whole
and this file can't decide whether to long, u_long or u_int.
---
sys/kern/vfs_cache.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 92c926a16afb..5b0cd64146ad 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -2597,10 +2597,10 @@ cache_enter_time_flags(struct vnode *dvp, struct vnode *vp, struct componentname
cache_enter_time(dvp, vp, cnp, tsp, dtsp);
}
-static u_int
-cache_roundup_2(u_int val)
+static u_long
+cache_roundup_2(u_long val)
{
- u_int res;
+ u_long res;
for (res = 1; res <= val; res <<= 1)
continue;
@@ -2616,7 +2616,7 @@ nchinittbl(u_long elements, u_long *hashmask)
hashsize = cache_roundup_2(elements) / 2;
- hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), M_VFSCACHE, M_WAITOK);
+ hashtbl = malloc(hashsize * sizeof(*hashtbl), M_VFSCACHE, M_WAITOK);
for (i = 0; i < hashsize; i++)
CK_SLIST_INIT(&hashtbl[i]);
*hashmask = hashsize - 1;
@@ -2762,7 +2762,7 @@ cache_changesize(u_long newmaxvnodes)
struct namecache *ncp;
uint32_t hash;
u_long newncsize;
- int i;
+ u_long i;
newncsize = newmaxvnodes * ncsizefactor;
newmaxvnodes = cache_roundup_2(newmaxvnodes * 2);