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 4E4E33E3C45 for ; Fri, 10 Apr 2026 17:44:25 +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=1775843066; cv=none; b=ZW6COURmkkE9EGG6GkpjU7oNtkRU+KJCdSj8/f7kK9ImjATyOHs0cjSMBz2vXBvRMslDVazzwlx24Z9ovIRwsz4CI3aqNM2IbIpB2qz5I5G7vgzBMaDEfALo/81zHcVVTktiQalr6EvwnHouW3MFq547QBVOCFjFhhavfLr70NY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843066; c=relaxed/simple; bh=SDZKcD0AQ2YCkreF1ugBAd778tPfuZzOQDRE8jGvGno=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W3VfHSNtAr5CuK4V1vPdJtHmaf5p/qJY4515+Kqzxkj7MwE0ydPDNVEm3Le2nRVvMe6a8p5miVWuX/FUBoEnvpCyRND/z9YxOi6itO82CtpFOpQffL4iTJCgZ9RPr9HhBA/4mrlzo5em0P7tFoYIc5LeOUh3rmwLrPYwqHGR32k= 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=wfiaVOiA; 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="wfiaVOiA" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c70ea91bfe1so1336515a12.1 for ; Fri, 10 Apr 2026 10:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775843065; x=1776447865; 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=W7Ka07oUOZomwbpEjcVO6ENMHmqIY1HgspyQLxIrvAo=; b=wfiaVOiA3RZ9uCWhzifpGRYcyn03rWJgxqOMvQL4yYWrr6xdeU7HeukcFqejunQkKB HwXKxcDMl9QBWM4qvXF7+EBsdYmAraPUNe12PbFU5qQxgRexbJkHqJaYiBiYwgTqR51K SKy4AJgu/3LfB1CKPO5Pk37IWb4MR6LpQA9Lbx7dX4+F+W4atmd3agUSTSL1Xux42YN7 kZBMgJwjw2xeyHCuHqGCNsBLBXqRWtiQUQaS3pvJaecPglSmmVg9fFR/pSEN4DneulRX qJSk3o3nHYXE1NnkD76B0bL7Df3KmG782QRLAUodg/6WeAt6v2mvRsJifxN+wMjwe1Hm iepA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775843065; x=1776447865; 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=W7Ka07oUOZomwbpEjcVO6ENMHmqIY1HgspyQLxIrvAo=; b=gC7iVozH5ds43uI9YrZhDSVZnwdtec0q0wgNrwyeJiy8i0OYdl14ah7Ox1nDmVKehk L/oXDzeR5zG5IdfSJdQeGoAV6r0KYIbSa455f06JuPgoccgCmvnpi9sTGJHhgeEBDHPY S5vaoEMM48cDBKlRyv18R8sMmThaQFO8q0XZjQ+lY7kMNcnhQ62R3vAwvvR84B42xI1W Cuxv4xdYEubRZfb1ApgPBqMC0BdfExgPPJTrHPQva7O1tDB9/o9DcBhk3zk3llt+30t9 X76Ka09wl/OjiS+V1e4vwYGXd0vSpUrBsDtMPEwFeSp2sWmJUzTgl9kEjKy7+tk+UyKI Wy2A== X-Forwarded-Encrypted: i=1; AJvYcCV5LDjvnDtz0JYNmcdIs4MrITwkWMaYSga03GAg/7+gFob2RReojMzhCm4lT443deCfDktBELcAg6WUO8U=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5e96rNIknNRmXiPd67H53P+ZHiEExEivTsm35FOAFDOVa+Ure iswk9IG/amRGKgLFH1CUNqIdi56K7C6h1tU7y4RjhkkZH2ZwUQLWlT0Rv44a2Jbhbuhl4zYtcPx WcGY7EnYC6+Kt3EdsX4mDXjWFZg== X-Received: from pfqn30.prod.google.com ([2002:aa7:985e:0:b0:829:700a:a1d2]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2791:b0:82c:f035:6748 with SMTP id d2e1a72fcca58-82f0c253756mr4814567b3a.42.1775843064389; Fri, 10 Apr 2026 10:44:24 -0700 (PDT) Date: Fri, 10 Apr 2026 17:44:16 +0000 In-Reply-To: <20260410174417.1450834-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: <20260410174417.1450834-1-joonwonkang@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260410174417.1450834-2-joonwonkang@google.com> Subject: [PATCH v3 2/3] 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, Joonwon Kang 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 --- 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; + } + 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