From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B7F72C027C for ; Wed, 12 Aug 2026 01:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786498157; cv=none; b=frncC63mUc7eTzYcsYSvorSbfOMuXhOcA6pAZMe0Md69LGFggER46QTMLg139XrX2GfCCgfIEyz6Y7vz5gPNhi1CUe03U5EfT1HDMuNUFHc5i7jcJSU+LQI4Fae+VyndApaY7muvjvurD3v1gmDcSB0CZRMFyaMHdvbEqxO6aLI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786498157; c=relaxed/simple; bh=c9efuhmVCjVf5pw9oyQuNK/Uez1LkoUqWJ+fPlLB6Tk=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=dLVIzcT20+95flmyAr5og+0yWSXJZXSKz3vOoDEWkLGpJ9svjQyXRFpcD85hdFAbqJBGB5x9ESozV5vj+8e2oKt8w87f+heuM0Hiag7zkGFVR2OnO7bor6MaHmPoaGwIdKHugi2SpL5BjMsSP3S7Zr9978hWIX+Ia7AkCv8K01s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=lebhn8hK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="lebhn8hK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4969F1F000E9; Wed, 12 Aug 2026 01:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1786498155; bh=7DyvY/YHLOg9UQpM7rEyMdWQpm6s3uUpeaxg5jZbaQQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=lebhn8hKMRA0/WLMRMGCHsbQDXYJUTUh6x4EEOCp8ZbdPu5C+3wGbUZs3aqSwK6aR QNOIh+f7uT2EPwzP7ZZxXzGMaICmg8NPBF+SAHItFMZsvePpfigP6015XfzemRck2a MxDT9cAkA8TeqydlMsV0Gc4kBNStS12VQ311adG0= Date: Tue, 11 Aug 2026 18:29:14 -0700 From: Andrew Morton To: Hui Su Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sashiko Subject: Re: [PATCH] kasan: fix quarantine_size accounting during cache removal Message-Id: <20260811182914.ed2cba4ef1a8a88335b9edab@linux-foundation.org> In-Reply-To: <20260811073332.1351893-1-sh_def@163.com> References: <20260811073332.1351893-1-sh_def@163.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 11 Aug 2026 15:33:32 +0800 Hui Su wrote: > quarantine_size tracks the total number of bytes stored in > global_quarantine[]. It is incremented when per-CPU quarantine objects > are moved into the global quarantine and decremented when a global > batch is evicted by kasan_quarantine_reduce(). > > kasan_quarantine_remove_cache() also removes objects from the global > quarantine. qlist_move_cache() rebuilds the source batch and updates > its .bytes field, but quarantine_size is not adjusted accordingly. > > As a result, quarantine_size remains over-counted by the size of the > removed objects. The stale accounting accumulates across cache removals. > Once the inflated value exceeds quarantine_max_size, > kasan_quarantine_reduce() can evict a batch even though the actual > number of bytes in global_quarantine[] is still below > quarantine_max_size, shortening the quarantine window. > > Fix the accounting by recording each batch's size before > qlist_move_cache() and subtracting the number of bytes actually removed > from quarantine_size while holding quarantine_lock. > > A KUnit reproducer used during testing observed the over-count grow by > 4698864 bytes after one kasan_quarantine_remove_cache() call with the > fix reverted. With this change applied, the over-count did not grow. > Thanks. > @@ -365,9 +365,14 @@ void kasan_quarantine_remove_cache(struct kmem_cache *cache) Sashiko might have found an unrelated pre-existing bug in here. https://sashiko.dev/#/patchset/20260811073332.1351893-1-sh_def@163.com