All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Akihiro Suda <suda.gitsendemail@gmail.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	stable@vger.kernel.org, suda.kyoto@gmail.com,
	regressions@lists.linux.dev, aruna.ramakrishna@oracle.com,
	tglx@linutronix.de, Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Subject: Re: [PATCH] x86/pkeys: Disable PKU when XFEATURE_PKRU is missing
Date: Wed, 19 Mar 2025 22:39:33 +0100	[thread overview]
Message-ID: <Z9s5lam2QzWCOOKi@gmail.com> (raw)
In-Reply-To: <20250314084818.2826-1-akihiro.suda.cz@hco.ntt.co.jp>


* Akihiro Suda <suda.gitsendemail@gmail.com> wrote:

> Even when X86_FEATURE_PKU and X86_FEATURE_OSPKE are available,
> XFEATURE_PKRU can be missing.
> In such a case, pkeys has to be disabled to avoid hanging up.
> 
>   WARNING: CPU: 0 PID: 1 at arch/x86/kernel/fpu/xstate.c:1003 get_xsave_addr_user+0x28/0x40
>   (...)
>   Call Trace:
>    <TASK>
>    ? get_xsave_addr_user+0x28/0x40
>    ? __warn.cold+0x8e/0xea
>    ? get_xsave_addr_user+0x28/0x40
>    ? report_bug+0xff/0x140
>    ? handle_bug+0x3b/0x70
>    ? exc_invalid_op+0x17/0x70
>    ? asm_exc_invalid_op+0x1a/0x20
>    ? get_xsave_addr_user+0x28/0x40
>    copy_fpstate_to_sigframe+0x1be/0x380
>    ? __put_user_8+0x11/0x20
>    get_sigframe+0xf1/0x280
>    x64_setup_rt_frame+0x67/0x2c0
>    arch_do_signal_or_restart+0x1b3/0x240
>    syscall_exit_to_user_mode+0xb0/0x130
>    do_syscall_64+0xab/0x1a0
>    entry_SYSCALL_64_after_hwframe+0x77/0x7f
> 
> This fix is known to be needed on Apple Virtualization.
> Tested with macOS 13.5.2 running on MacBook Pro 2020 with
> Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz.
> 
> Fixes: 70044df250d0 ("x86/pkeys: Update PKRU to enable all pkeys before XSAVE")
> Link: https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
> Link: https://github.com/lima-vm/lima/issues/3334
> 
> Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
> ---
>  arch/x86/kernel/cpu/common.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index e9464fe411ac..4c2c268af214 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -517,7 +517,8 @@ static bool pku_disabled;
>  static __always_inline void setup_pku(struct cpuinfo_x86 *c)
>  {
>  	if (c == &boot_cpu_data) {
> -		if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
> +		if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU) ||
> +		    !cpu_has_xfeatures(XFEATURE_PKRU, NULL))
>  			return;

Note that silent quirks are counterproductive, as they don't give VM 
vendors any incentives to fix their VM for such bugs.

So I changed your quirk to be:

--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -519,6 +519,17 @@ static __always_inline void setup_pku(struct cpuinfo_x86 *c)
 	if (c == &boot_cpu_data) {
 		if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
 			return;
+		if (!cpu_has_xfeatures(XFEATURE_PKRU, NULL)) {
+			/*
+			 * Missing XFEATURE_PKRU is not really a valid CPU
+			 * configuration at this point, but apparently
+			 * Apple Virtualization is affected by this,
+			 * so return with a FW warning instead of crashing
+			 * the bootup:
+			 */
+			WARN_ONCE(1, FW_BUG "Invalid XFEATURE_PKRU configuration.\n");
+			return;
+		}
 		/*
 		 * Setting CR4.PKE will cause the X86_FEATURE_OSPKE cpuid
 		 * bit to be set.  Enforce it.

This is noisy in the syslog, but it's a WARN_ONCE() and it doesn't 
crash the bootup.

Thanks,

	Ingo

  parent reply	other threads:[~2025-03-19 21:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 14:35 [REGRESSION][BISECTED] x86: kernel 6.12 crashes during get_xsave_addr_user on Apple Virtualization Akihiro Suda
2025-03-11 18:25 ` Aruna Ramakrishna
2025-03-12  5:57   ` Akihiro Suda
2025-03-12  6:18     ` Akihiro Suda
2025-03-12  9:31       ` [PATCH] x86: disable PKU when running " Akihiro Suda
2025-03-12  9:32       ` Akihiro Suda
2025-03-12 10:09       ` [PATCH v2] " Akihiro Suda
2025-03-12 10:21         ` Greg KH
2025-03-13 17:02         ` Ingo Molnar
2025-03-13 23:59           ` Akihiro Suda
2025-03-13 17:11         ` [tip: x86/urgent] x86/pkeys: Disable " tip-bot2 for Akihiro Suda
2025-03-14  6:26         ` [PATCH v2] x86: disable " kernel test robot
2025-03-14  6:26         ` kernel test robot
2025-03-13 17:58 ` [REGRESSION][BISECTED] x86: kernel 6.12 crashes during get_xsave_addr_user " Dave Hansen
2025-03-13 18:01   ` Ingo Molnar
2025-03-14  6:22   ` Akihiro Suda
2025-03-14  8:48     ` [PATCH] x86/pkeys: Disable PKU when XFEATURE_PKRU is missing Akihiro Suda
2025-03-14  8:49       ` kernel test robot
2025-03-19 21:00       ` [tip: x86/urgent] x86/pkeys: Add quirk to disable " tip-bot2 for Akihiro Suda
2025-03-19 21:39       ` Ingo Molnar [this message]
2025-03-20 14:21         ` [PATCH] x86/pkeys: Disable " Akihiro Suda
2025-03-20 15:11         ` Borislav Petkov
2025-03-20 19:46           ` Ingo Molnar
2025-03-19 22:11       ` [tip: x86/urgent] x86/pkeys: Add quirk to disable " tip-bot2 for Akihiro Suda
2025-03-14 15:07     ` [REGRESSION][BISECTED] x86: kernel 6.12 crashes during get_xsave_addr_user on Apple Virtualization Dave Hansen
2025-03-15 13:09       ` Akihiro Suda
2025-03-15 13:48         ` Borislav Petkov
2025-03-15 15:10           ` Akihiro Suda
2025-03-15 19:02             ` Borislav Petkov
2025-03-15 18:45         ` 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=Z9s5lam2QzWCOOKi@gmail.com \
    --to=mingo@kernel.org \
    --cc=akihiro.suda.cz@hco.ntt.co.jp \
    --cc=aruna.ramakrishna@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=regressions@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=suda.gitsendemail@gmail.com \
    --cc=suda.kyoto@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.