The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Rik van Riel <riel@surriel.com>, linux-kernel@vger.kernel.org
Cc: kernel-team@meta.com, dave.hansen@linux.intel.com,
	luto@kernel.org, peterz@infradead.org, bp@alien8.de,
	x86@kernel.org, yu-cheng.yu@intel.com, stable@kernel.org
Subject: Re: [PATCH 2/3] x86/mm: Fix early boot use of INVPLGB
Date: Mon, 2 Jun 2025 10:21:53 -0700	[thread overview]
Message-ID: <3ab0fc2b-646e-4413-a485-cb9373f8b9d5@intel.com> (raw)
In-Reply-To: <20250602133402.3385163-3-riel@surriel.com>

On 6/2/25 06:30, Rik van Riel wrote:
> Use of the INVLPGB instruction is done based off the X86_FEATURE_INVLPGB
> CPU feature, which is provided directly by the hardware.
> 
> If invlpgb_kernel_range_flush is called before the kernel has read
> the value of invlpgb_count_max from the hardware, the normally
> bounded loop can become an infinite loop if invlpgb_count_max is
> initialized to zero.
> 
> Fix that issue by initializing invlpgb_count_max to 1.
> 
> This way INVPLGB at early boot time will be a little bit slower
> than normal (with initialized invplgb_count_max), and not an
> instant hang at bootup time.

The INVLPGB instruction has limits on how many invalidations it can
perform at once. That limit is enumerated in CPUID, read by the kernel,
and stored in 'invlpgb_count_max'. Ranged invalidation (like
invlpgb_kernel_range_flush()) break up their invalidations so that they
do not exceed the limit.

However, early boot code currently attempts to do ranged invalidations
before populating 'invlpgb_count_max'. There's a for() loop which is
basically:

	for (...; addr < end; addr += invlpgb_count_max*PAGE_SIZE)

It doesn't make much progress when invlpgb_count_max==0.

... then the rest

---

BTW, how was this code even _working_ without this patch? Are the early
boot ranged invalidations infrequent or something?

Acked-by: Dave Hansen <dave.hansen@linux.intel.com>

  reply	other threads:[~2025-06-02 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02 13:30 [PATCH 0/3] TLB flush fixes Rik van Riel
2025-06-02 13:30 ` [PATCH 1/3] x86/mm: Fix potential overflow in user_pcid_flush_mask Rik van Riel
2025-06-02 16:55   ` Dave Hansen
2025-06-03 21:20     ` Rik van Riel
2025-06-03 21:33       ` Dave Hansen
2025-06-02 13:30 ` [PATCH 2/3] x86/mm: Fix early boot use of INVPLGB Rik van Riel
2025-06-02 17:21   ` Dave Hansen [this message]
2025-06-02 13:30 ` [PATCH 3/3] x86/mm: Change cpa_flush() to call flush_kernel_range() directly Rik van Riel
2025-06-02 17:22   ` Dave Hansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ab0fc2b-646e-4413-a485-cb9373f8b9d5@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=stable@kernel.org \
    --cc=x86@kernel.org \
    --cc=yu-cheng.yu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox