From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 8B52A361666 for ; Sun, 10 May 2026 07:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778397717; cv=none; b=HT5YrBF5XB23pUshJ+Js45QNWmt2Gx39l0EYfiwN2YcWiZuOFmcIyJ3gFz3rvtp1lScsmvWugEYEwbLQi3O9upId7Osp57x607fRphqZXVxmCLC/5F6kyqUQlrG13YxY+j6EiJQuuvYSxb+C1df5iMn58hpNdnfqP5y8Na6quM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778397717; c=relaxed/simple; bh=Eop2gOA3gwI4NxwrccmTsCyo8IGxvIMlTtYUdNXnfjc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fdiSmypg50hbYVkNFaLE+qzIgNZ+C1Aj96mtHQ1TFOnrDN/Maxco8+ZU7unGanCPnKQ5Y9btwYbjzfoKhcn4PMEYskfY82+WyXP4WOTrPjShPG+yUSc1EQa5xrh0TYsM0oy8+sGdbIDbPiIdJKDwTlHFCXJfFy1R5qD7kXfaNa0= 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=aLBnGy9N; arc=none smtp.client-ip=209.85.216.73 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="aLBnGy9N" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-354c44bf176so3927228a91.0 for ; Sun, 10 May 2026 00:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778397716; x=1779002516; 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=YaP+quwBLhPvtJZMfRsNtJ+XJuXs1GsFB2cwxZcRVVs=; b=aLBnGy9NHNU5sCBhoJNumvcBbh0MgoIPu4qjPx41wXwUAy4wdEW4gHnMhCXc9dDEtP hAJp2PWmBCu6yWzAPwuolTPSPxJOWeW93Mdu/2gFDghJsfWDTwui7iX8hbxpQPBkP7os ugp90CKd9hr1k23py80ChMA77Xec0KUYALqx0sG/HfDzmyvyn7S6kJR0v2/W11z90WYf 5MvhX8eWbWz9evzbkHt1qt1m+4T4bHGXxvMs272x9/GFNu6LK0W2OOtpRNAEk6FcHDOo t/qKScTdHS7Mhik5wNtf74zigO4quqdGPwJ86dH8O+K/WHeGgfyDRRtIAmFqQyzbvwI6 6bvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778397716; x=1779002516; 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=YaP+quwBLhPvtJZMfRsNtJ+XJuXs1GsFB2cwxZcRVVs=; b=BhkDcGPaH9sOQGZQh/XnRV1peDuJmAZLz1xDtDYHsAt/HugWQSxFASy/pV2jkssRVZ MneXYYNiZ5FqY1kWVCIlQzK3CcI6tDqlgc8QAh4vfHL47OBGnmSib+noNNvU7JdTGsa2 Td8h2HNBeQzfdziLsKj3IDDK93nj2YwqTYv2OYZykjPOVv6w0DGzI6lY/VubZLwgQWJ6 VgIweFFgN4fqjKw5zVQv1Dbkv9ec+bq3Pgp/CKqUUXsd0Iz8uZOdU0xFi0LQvrza95k9 pbhY6CKDyoQX105e9a95BNMX8NqAsQ6Bv1YosA4ZjXTopnK2mMBc2nUUXNfZVsXeluLf 33RA== X-Forwarded-Encrypted: i=1; AFNElJ8pWCAlfw8vKYFo8HJg+wTqrty+zpBMmEr8AHnMNu3pQRInaViq1NFDkQauIbxbF/FZnLfOgVKct51ooTQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3QRpngyyKcDpny35iU+oY9xKl8UZnNYqYdLMBwfHb8lHT4dD7 7alXf0N76FuGLpc9FXfiMj91F20aJfWt01aeDjVz1Dc/bhGY1s9MC4IXBMc8o9txGFoQ9tMbUm0 GjMCUHtTEaR1g2jpz2PYBY5idow== X-Received: from pgjx18.prod.google.com ([2002:a63:fe52:0:b0:c7f:cb0a:3b6b]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:338f:b0:395:7fb:9362 with SMTP id adf61e73a8af0-3aa5a90db5cmr21705561637.19.1778397715646; Sun, 10 May 2026 00:21:55 -0700 (PDT) Date: Sun, 10 May 2026 07:21:47 +0000 In-Reply-To: <20260510072149.1279887-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: <20260510072149.1279887-1-joonwonkang@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260510072149.1279887-2-joonwonkang@google.com> Subject: [PATCH v5 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: 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