Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Sep 2023 21:46:47 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 2701cbf16165 - releng/14.0 - vfs cache: fix a hang when bumping vnode limit too high
Message-ID:  <202309242146.38OLkluf030345@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch releng/14.0 has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=2701cbf16165adbd782c6eea816d4b7214a1d2b8

commit 2701cbf16165adbd782c6eea816d4b7214a1d2b8
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-09-02 14:27:33 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-09-24 21:45:23 +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.
    
    Approved by:    re (gjb)
    (cherry picked from commit 32988c1499f8698b41e15ed40a46d271e757bba3)
    (cherry picked from commit 41fad6503c1e5259e65d4f14110a5decb7653b02)
---
 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202309242146.38OLkluf030345>