]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
sunrpc: fix race in cache cleanup causing stale nextcheck time
authorLong Li <leo.lilong@huawei.com>
Sat, 1 Mar 2025 06:48:36 +0000 (14:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:05:29 +0000 (11:05 +0100)
commit05aba2d316db1a59992c691f5ef8a1912a78f27b
treeff25682f9187a8e0bdf7df7cd9612c0ca84c9430
parent979408dbd76fdde5d3b3efbac2cb94aaa9b7fb9e
sunrpc: fix race in cache cleanup causing stale nextcheck time

[ Upstream commit 2298abcbe11e9b553d03c0f1d084da786f7eff88 ]

When cache cleanup runs concurrently with cache entry removal, a race
condition can occur that leads to incorrect nextcheck times. This can
delay cache cleanup for the cache_detail by up to 1800 seconds:

1. cache_clean() sets nextcheck to current time plus 1800 seconds
2. While scanning a non-empty bucket, concurrent cache entry removal can
   empty that bucket
3. cache_clean() finds no cache entries in the now-empty bucket to update
   the nextcheck time
4. This maybe delays the next scan of the cache_detail by up to 1800
   seconds even when it should be scanned earlier based on remaining
   entries

Fix this by moving the hash_lock acquisition earlier in cache_clean().
This ensures bucket emptiness checks and nextcheck updates happen
atomically, preventing the race between cleanup and entry removal.

Signed-off-by: Long Li <leo.lilong@huawei.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/sunrpc/cache.c