From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9E06B29D294 for ; Tue, 21 Apr 2026 23:29:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776814140; cv=none; b=GmB4TUSXyintvJH8ubRxCy2/L/khx31putVORoH6wTpEqqZROWQRiGBF/9dGxKcVDNcUjWWa/1HJXZ0b8SBpzxbBuGE7nPqmVGkrybJg39NmUSJhtx2lvpfmgLK0fZ0gIUIkQmyb+HezzHCDd/LW8Cci6U+i/IPGWRfYw6PDHGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776814140; c=relaxed/simple; bh=yhS4w2iWbQXVD+c51oA2tUzJ48+g97qaeOGGP78n24c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mYgyuTG4UzLSYxutjMC92QgvOzEZhdhduDsLtjTrs/BASb+QtG8TndlmzvqNtP0rtzjlU0M9Mz8pN4kD/YIopYptDrBLGmh5w4hMLWlasRyM++kvgJCVIT7XZrxGx4CTtrzPZ5OWs23SzP5kmn6jhCIJP5wTCTPzXzB8L4gJHao= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uC9WHgNb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uC9WHgNb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F137AC2BCB0; Tue, 21 Apr 2026 23:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776814140; bh=yhS4w2iWbQXVD+c51oA2tUzJ48+g97qaeOGGP78n24c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uC9WHgNbcrEwpY9K7QCOmayEeQDTWcdMR4d0pcK3UVmff5/XtLW40S0xzobd/nhrv jlWIZNygRYlxzeKp9DFFQx1gauYTAnLuM9Q0x3bqQv5y6Y6XVez79Dobepvi6dwqIg QSJImbp7Xp3COjJHMOfHaralVGrOU6HG4/Nt+SJCA/b5ycNpumOHoOXEPIv0AS0Nq5 fhKfMg1MVeydNzMum7k8xWL5CONvVF4XBxiKiPULNQeMIazzQsK7hbS21nFRn9TwZj dy7487mcln4R7A9mHygWbeooaxi4u4H7zqKdJX5UoDRaoklXiIXuJByTr0A2HST7yd NQeee9mP3NYSg== Date: Tue, 21 Apr 2026 16:28:58 -0700 From: Dennis Zhou To: Joonwon Kang Cc: tj@kernel.org, cl@gentwo.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dodam@google.com Subject: Re: [PATCH v3 2/3] percpu: Do not trust hint starts when they are not set Message-ID: References: <20260410174417.1450834-1-joonwonkang@google.com> <20260410174417.1450834-2-joonwonkang@google.com> 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-Disposition: inline In-Reply-To: <20260410174417.1450834-2-joonwonkang@google.com> On Fri, Apr 10, 2026 at 05:44:16PM +0000, Joonwon Kang wrote: > contig_hint_start can be trusted outside the hint update function since > it will be updated everytime contig_hint is broken. On the other hand, > scan_hint_start might still be invalid anywhere in the code due to the > broken scan_hint not being updated promptly. If those starts are trusted > when they are not set, it could lead to false invalidation or update of > the hints. > > Signed-off-by: Joonwon Kang > --- > v3: Initial version. > > mm/percpu.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 3ecd86096641..f16533ed4a49 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -638,6 +638,13 @@ static void pcpu_block_update(struct pcpu_block_md *block, int start, int end) > if (end == block->nr_bits) > block->right_free = contig; > > + if (block->contig_hint == 0) { > + block->contig_hint = contig; > + block->contig_hint_start = start; > + block->scan_hint = 0; > + return; > + } > + This change isn't described in the commit log. I'd prefer to clean up the logic below than adding this additional if empty case. > if (contig > block->contig_hint) { > /* promote the old contig_hint to be the new scan_hint */ > if (start > block->contig_hint_start) { > @@ -845,7 +852,8 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, > PCPU_BITMAP_BLOCK_BITS, > s_off + bits); > > - if (pcpu_region_overlap(s_block->scan_hint_start, > + if (s_block->scan_hint && > + pcpu_region_overlap(s_block->scan_hint_start, > s_block->scan_hint_start + s_block->scan_hint, > s_off, > s_off + bits)) > @@ -889,7 +897,7 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, > /* reset the block */ > e_block++; > } else { > - if (e_off > e_block->scan_hint_start) > + if (e_block->scan_hint && e_off > e_block->scan_hint_start) > e_block->scan_hint = 0; > > e_block->left_free = 0; > @@ -922,7 +930,8 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, > if (nr_empty_pages) > pcpu_update_empty_pages(chunk, -nr_empty_pages); > > - if (pcpu_region_overlap(chunk_md->scan_hint_start, > + if (chunk_md->scan_hint && > + pcpu_region_overlap(chunk_md->scan_hint_start, > chunk_md->scan_hint_start + > chunk_md->scan_hint, > bit_off, > -- > 2.53.0.1213.gd9a14994de-goog >