From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 DE7DD48035B for ; Wed, 6 May 2026 14:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778077268; cv=none; b=WBxikLnax3MI1gDZRLcV+4n4eTBYblySvMtJx5qw5F8+qDWG70xlxHZNNEwlV+0LNEED+HI1MjOno/k6m4ciK8mBBrnehxXXDsIFYRcZLFHd4zFJkihxCtxWhMT471edLxaIaam3V1gCIYlpX5HTAjpPRTITaJxltkVJbqAL1uA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778077268; c=relaxed/simple; bh=D2VLzcuGiYnf2ICq8FrVjqtoVi+L6/JB5Ckg5zlxFlM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JkIfsV8EwJAkFDNBDj8m6K96NYirvzvgcvaAPUZU02Tu0dCK716F8EPyhYAHNWgyg/xmNIUuzMDjTNVRdNHg4KmDh5RjpAYs8GsNviD9PG3roCbKriD8aXbjAITwg0nfOTvh+II0VxEon3+O1Yf98J0iOBuF6O/dGWhDDzZi2EE= 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=pb4IYZyY; arc=none smtp.client-ip=209.85.210.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="pb4IYZyY" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82f6b984b3aso3126102b3a.3 for ; Wed, 06 May 2026 07:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778077266; x=1778682066; 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=9H9L9M+JOU3eNnCYVuR6T/rOOaeJDpAoAd4t4ID0R20=; b=pb4IYZyYKMrd2LxZGlO67EXlpcZdbMPfYg69hRZhdjCqycRHZe0cjT311qKfq/0TsG +FdKWipuq5skaj4oEQxwJ6qSDA8PHFZnowpqb/J09sJWF7brBriIK5KHSM7wljmZkAKW UpaUrC81WsbWETRcJ7nUH2t2V+s5J7dPA2IEi+C3nO3ZmfjBSjgPKUvZdYeWqiXGXaFC KAC4DRtPnVZkmVx3/3qP6qvE6x0xKYEs1vcbeR5pmXZ7imf0ixLRZ2kV5/Go+3B6opiw UYMLg2ttKBYNCmg9l8AaEdzg6mutTCi8BIIanpIGhjKRvaYqoo9KwZVTVlVGcA0SrFa5 ewuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778077266; x=1778682066; 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=9H9L9M+JOU3eNnCYVuR6T/rOOaeJDpAoAd4t4ID0R20=; b=mZoJgPN74d6zmBSGEC3PP/wTyHWTwrv/kIzqQA/oa2v65J4BlLn+fJUq9ys5ZWu4hu 4yFJh+W3LQ02dICSiyEvgtFtLGgAY8EsN0Ab76HLG5PsbSY3n5dTbJ5YnJMPal8M+T0i Lhh59wh/MKn0VgjcX06MaCYuh1AS7bQsZqVmXr2MaG4BON4mPGN8aVHSoDzAXZ/IZD5i yfMvcZRMBQuelXMi0O3hKjkn72oG3kc63x/IKFnUc6YA1ASb6uRVKFc/rPLtI/q6RF8c 1G7yoget95bQYvaE2Geq2N+0bg227GO0Avhn/29cbTpz8lgAvUU+VgHZdmano5MXsgeJ XIgA== X-Forwarded-Encrypted: i=1; AFNElJ+ljpox6FWGrdcpDGgqg3taxFgWmeLwPBz1Yior3sgfrThNft3bs2Lq0yMUQo1Bnfbd57geeoKa38uu14g=@vger.kernel.org X-Gm-Message-State: AOJu0YwXkk3Xatk8fZ5mV2R5xzFM2VKoSQK+ZkJYCaoq6ZCOfcJ5JEYQ /vGlOIi5KpG6iDKDjH6kVn4IY1eIIu61sQK0yfJKf4VJsziM/RVBoaY9clfO1YOne82UyhcPq0C KCtl+tdOE0Khf8pOu6X7d1qdvzg== X-Received: from pfoh13.prod.google.com ([2002:aa7:86cd:0:b0:82f:c34b:9799]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4191:b0:82f:85c8:fc19 with SMTP id d2e1a72fcca58-83a5b9de7c7mr3359443b3a.11.1778077266093; Wed, 06 May 2026 07:21:06 -0700 (PDT) Date: Wed, 6 May 2026 14:20:57 +0000 In-Reply-To: <20260506142100.1289509-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: <20260506142100.1289509-1-joonwonkang@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260506142100.1289509-2-joonwonkang@google.com> Subject: [PATCH v4 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 --- 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.545.g6539524ca2-goog