From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 451123E3D9A for ; Wed, 13 May 2026 08:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778662285; cv=none; b=nnIXTY5OD0Zyq+k5bMyx14tgjPYULMnmfoSISNeeVMsL0V+4DQQfIHsm72K3mVtzctSMl8zaP0PZeA0xyjIBN9xuZBdYYGVTD1BzUjn7ynVUpa3wYX3/9iQLc5WCD/LZRjwURGYu+UwLHqWh5lleqDak07hBdpgdC63HTWS5Asw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778662285; c=relaxed/simple; bh=LHqkQ8txwFUMqFxinHT8fw6+ackq5CC8CG4pO2jbZUs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VikWQuzs3xLUqoV/gqeZltqQhYiv0P8vgo/MQB8tNRqipcX4qQKlGaPht5FqVyUArf/KN/TFmf7zFPIfVglgKyDI8rXjcKCgSEorGXuUPUq2UQEtwgbivLRJSAnEsu870cLhAyxI4DMs43zm4cuGakTE5c8z9UWEx2k/07zb4xs= 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=BL8rZoVi; arc=none smtp.client-ip=209.85.214.201 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="BL8rZoVi" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b9a3c3c4eeso71229315ad.3 for ; Wed, 13 May 2026 01:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778662282; x=1779267082; 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=D/ysDW4vpFGuyFwOzyTH39ntXv4ZsW/SAVTNkmI/e2Q=; b=BL8rZoVi9NjsIHa0YlY+85BrWuODwT6vT7oJBcsIo51K51Nuk1Lfw8bRbKpMdqvUIp v+13ryiVazIKtGJZJN+sRxXDG2H9Q1Iffo/BHSGzFMuIteSedfcRMWOXmDMgkzRd5w8P CdlrgEystPEfBk17UVFwJz96QdY3gAYuEX13d8UYTw8LsrzWt/YgkE01vn1XmLDakSbJ 5Yjty2/ss3hc6zX8blBLZxuoOlUAFSCGCCB2XBXUgX3Lbd2OpRyCoVUSHvxLj41rKUIZ RE+6kAsHy0TjJY/N89E5k/YMDVCtADdLS8mIYUhzHPdmekcrUp/8hrfZWyAv1DVQaWox JKoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778662282; x=1779267082; 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=D/ysDW4vpFGuyFwOzyTH39ntXv4ZsW/SAVTNkmI/e2Q=; b=YSbxt5GEpx/cl8Kgcs3Ph8ZchccGS3QLn2H7wVM+42QIOdfbMbEatziYHCgBfqzxxa NreQl+1u+Ro4WFcLug+uUT58fBsXJYeSOig+EFONTCZpn3zVmLsWyoTzBSa2PY+Fy3tA EcbBi9Dqkwv2HGEPdEuRyemiQViJ+GCp8P5B9Z0yhXJbnH0Yi0EX7JhB0cVXWOsfpcjW f5vRYzHCWzpw/9QPV43kIFDZdz9r72R1s+MB8JcDehZElKix/4E53VijFHLQzT1f1K2n CAGABuzlqK/1l1CACUr9bABIGDCoY6cb2w9YXhb7kFPTW1qaLw1ZZKHR40xv3AXTBHso cAEA== X-Forwarded-Encrypted: i=1; AFNElJ/rOmLwJIvUh6R6a+xwhYiqs3+MB0si3YixVV8h4euQdzPJxAjQUCy4URJQF5q8XSPLw606gbNDJl6Q2YE=@vger.kernel.org X-Gm-Message-State: AOJu0YyVAUlXrxag+U9HFxYofHf0Shhit/J9maYq6LxHHhWCZ3pCwaTx mKxNTuMNM+YPmjTCh0NHIwc2tH/vv7c9aTUKpLgqdZpcgZ9EkkyaVVA7pag0rNfWpZ0K1IKknBx /Ot3CJJkRgiDaqe+eZAXG7zaRUA== X-Received: from plblv14.prod.google.com ([2002:a17:903:2a8e:b0:2b4:5d58:bb86]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:758c:b0:2ba:22db:e1e0 with SMTP id d9443c01a7336-2bd2f4f5c6dmr14392825ad.10.1778662282217; Wed, 13 May 2026 01:51:22 -0700 (PDT) Date: Wed, 13 May 2026 08:51:14 +0000 In-Reply-To: <20260513085117.1024175-1-joonwonkang@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260513085117.1024175-1-joonwonkang@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260513085117.1024175-2-joonwonkang@google.com> Subject: [PATCH v6 2/4] percpu: Do not trust hint starts when they are not set From: Joonwon Kang To: dennis@kernel.org, tj@kernel.org, cl@gentwo.org Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dodam@google.com, joonwonkang@google.com Content-Type: text/plain; charset="UTF-8" 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