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 2FDA9371068 for ; Tue, 26 May 2026 06:33:54 +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=1779777236; cv=none; b=ILwz5KOqPqS4FMTN5Oqpenrw1Q/K4LHexuUOgs3v4t4a7APnw9XRGcxxSMUw76ZTMfxOtqIVxbYnc4BRqtCRUCP5keEDAESgJ5F353Y5jYvq5tNVkCa6+Teqld/02r8AdZvqMf4gWrQjWSGYD5drj7MDt3Yh+gEj6egivd8l3p4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779777236; c=relaxed/simple; bh=Df6c+qjlArSwEBbOGJaGHaPDLFOkUxUkwy5dxBP9NsM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HhThDhkAMQOO0ELgQdl6kumabXQee6mdMv/BV+JTOT0NSZY2wprSrSXOUH5Dc8R0JSc5/yLU4QfPMvFanlmRIYJKaT5yS8Z64wHp/FOFEzVdEAVxlK1MPDL+BGvGBcGZeItB3704tGDoKD9YWy7Srsi3wvMZQ7I8sK7I4ibIVVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EzQ9eDH2; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EzQ9eDH2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE61E1F000E9; Tue, 26 May 2026 06:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779777234; bh=u2IrXYs7DczBXOabIUF34kYQAn6UG03Kfsz/edIgftU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=EzQ9eDH2mXsWEtQfTYNMBbUfsy7DCcP29xZqhdB/2WspVLPe7Dg3FuMPVR0RHIDtc aa2eeiQijsEPhnENTCYFUCZpnlaMXd4tL0N2oztNZYAsYXd9bt55Oztzeb9So59YhS oTCTLQC9k/CoIW0p6v/BDKDJPNftFS6ZACdZg3pfSwcCKlFqDSS8CGdhH0iyfsbBEf GXXGGp9oJ7avCcSDq4x1brk05YmkmeBG1FQHK8zmyafy36sWlitp/t+ARYhHPoayGs +O+QUMncvBvEBTIsEHm1zm/Bxu+nUnRtmYhnrFaUO8Yhb4fYF694Udx12qmxl0n3gI yZu76VhbiSd5A== Date: Tue, 26 May 2026 08:33:49 +0200 From: Dennis Zhou To: Joonwon Kang Cc: dennis@kernel.org, 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 v6 2/4] percpu: Do not trust hint starts when they are not set Message-ID: References: <20260513085117.1024175-1-joonwonkang@google.com> <20260513085117.1024175-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: <20260513085117.1024175-2-joonwonkang@google.com> On Wed, May 13, 2026 at 08:51:14AM +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 > --- > v5-v6: No change. > v4: Remove the separate contig_hint == 0 case and handle the case in the > following code. Add more checks for scan_hint. > v3: Initial version. > > mm/percpu.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 3ecd86096641..0f6dd5260f56 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -640,12 +640,13 @@ static void pcpu_block_update(struct pcpu_block_md *block, int start, int end) > > if (contig > block->contig_hint) { > /* promote the old contig_hint to be the new scan_hint */ > - if (start > block->contig_hint_start) { > + if (block->contig_hint && start > block->contig_hint_start) { > if (block->contig_hint > block->scan_hint) { > block->scan_hint_start = > block->contig_hint_start; > block->scan_hint = block->contig_hint; > - } else if (start < block->scan_hint_start) { > + } else if (block->scan_hint && > + start < block->scan_hint_start) { > /* > * The old contig_hint == scan_hint. But, the > * new contig is larger so hold the invariant > @@ -664,10 +665,12 @@ static void pcpu_block_update(struct pcpu_block_md *block, int start, int end) > __ffs(start) > __ffs(block->contig_hint_start))) { > /* start has a better alignment so use it */ > block->contig_hint_start = start; > - if (start < block->scan_hint_start && > + if (block->scan_hint && > + start < block->scan_hint_start && > block->contig_hint > block->scan_hint) > block->scan_hint = 0; > - } else if (start > block->scan_hint_start || > + } else if ((block->scan_hint && > + start > block->scan_hint_start) || > block->contig_hint > block->scan_hint) { > /* > * Knowing contig == contig_hint, update the scan_hint > @@ -845,7 +848,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 +893,8 @@ 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 +927,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.54.0.563.g4f69b47b94-goog > Reviewed-by: Dennis Zhou Thanks, Dennis