From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0ACF33064A for ; Wed, 29 Apr 2026 13:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777467797; cv=none; b=Ij72jfpa1gY1O1nf+MrXxIIpSNW4z2tlOWgxkzWfPbR0RNXpBPtYdTcGINtvt+ng9OmIAvw7RhcphsKpDEpNh9TzdO9HRrl9EWD0ScZQaKako6+toXckQ/pS4dggRoIAySOaZErXisk4ToIjOwSaeBhVTMmhwDlLdWwGjqKzKYI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777467797; c=relaxed/simple; bh=h3Sf2nZt6JNt+yED7CKiqyG7udaRJt6INYlivsdWARY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=njkAjefB4blK1/dxPPWWKRDCSVeBSdbOdYQdQlfSsT9/cRlIitfB55iL9r9Y+x3+pDAX29RHr+Sl/XUPVwzwfejZOugF/9i8Vuua4Sz1SHWppLlBxDdKmm/xdQS3kopVf5WuGv0L8rokljm9EEj1hP8K2UwG+Nd0lsyGwHJcb0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MO07s+zB; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MO07s+zB" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c76bfd7b9cdso5092369a12.3 for ; Wed, 29 Apr 2026 06:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777467795; x=1778072595; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lBkLeOGUAHoVLnjz8sOE6ZNCHGSpvXGjgM37tA68iII=; b=MO07s+zBmNTs/wFAwFnS8JGEeGG+cw9ZDdq2L8g7+REjZJuyL9aFCIWwMX3iGaThsk mkK0cNvTNsjlQW2pvq1UUtfCWD3fVJXofzaUgWijw55DC+qMkaShL9ULFwhdoQC+8QE1 teqgARw40GM3h09nUb9dC/EFJwO1owdSItSCH/YbSa0xSIteZBWwF1UfFdLrgUxAYTMr YDIHx5s8gkyzsu+T6Lz0gM1P+Qm7ttzzFM89MiHJd6ARbP9ga3SnEeJWClbjNthyeKua +BHF8BQJHneHe5LDmQ0l3BE2+n5r+iBzHyczpOrsBWJ5suXoCLoMdm+QRMB+g5P2UEJh MseQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777467795; x=1778072595; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lBkLeOGUAHoVLnjz8sOE6ZNCHGSpvXGjgM37tA68iII=; b=Ct/Yi6gBXzo/AXhUE2xrHQ+VfJgEQHnxnClu2AL9R+Sb+Nm8smZIeTzNYwOOYfO/yC hVv/AgBc6IJK4eLMq+MYp/HbrAHe20lgniOwTfZT10GSIclyRtov+V3mn13zXIOOue6o vnGao9QfHVajwAzYJuQzZemj7IkXR0in3HZiwwk79rPuy3m09zqBg4gUzJsQsQTVxDVU MGgE55Wuhq+4ALftFxcZX42fM6J0N/G9OGuOnoFmbUcOeAe3VdGiaJuiNRlzw5Ri3fv7 dbxFwK1YClMEpObUdTVTgdVQngCKFc6phMGzxoi5KXGNksTkjpN3mNbqn/yL4eNzxsyJ wc/g== X-Forwarded-Encrypted: i=1; AFNElJ8uX1MsGR4EkELAgtzYWu5RxhFEZKfyzYkQhynRWATZz0JoKL7ELKYwqCHPeWgDh8c2rpHw8vpqIha+RqM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1k6PMQ04ogVVHB9FrWQj4NzmaRQ9uwXEK6tOLMOXu948lv1La HPmjaP6p/LlJfhv7w7lptxRlQJNleE6WbZVyZO5IhiZRbR0UJ79iRCFPpaedOiwya/qLOaAjwf5 ILk7qOODdt3bNjZxGhmEzcQjiTg== X-Received: from pgll67.prod.google.com ([2002:a63:2546:0:b0:c6d:c043:2cb4]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7350:b0:3a2:d316:de52 with SMTP id adf61e73a8af0-3a3af54183fmr4098929637.31.1777467794680; Wed, 29 Apr 2026 06:03:14 -0700 (PDT) Date: Wed, 29 Apr 2026 13:03:13 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260429130313.2318006-1-joonwonkang@google.com> Subject: Re: [PATCH v3 2/3] percpu: Do not trust hint starts when they are not set From: Joonwon Kang To: dennis@kernel.org Cc: akpm@linux-foundation.org, cl@gentwo.org, dodam@google.com, joonwonkang@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, tj@kernel.org Content-Type: text/plain; charset="UTF-8" Hi, I am sorry for the late response. I was occupied by other issues lately. > 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. > Oh, by the commit message I meant indirectly that contig_scan_hint should not be trusted inside this hint update function while it can be outside. Let me clean up the logic below instead of changing the commit message. Since the control flow will always reach the first if-block below when contig_hint is zero, it should be simple enough. Thanks! > > 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 > >