[PATCH v2] x86: disable PKU when running on Apple Virtualization

Akihiro Suda posted 1 patch 9 months, 1 week ago
arch/x86/kernel/cpu/common.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
[PATCH v2] x86: disable PKU when running on Apple Virtualization
Posted by Akihiro Suda 9 months, 1 week ago
OSPKE seems broken on Apple Virtualization.

  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

Tested on macOS 13.5.1 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>
---
v2: check oem_table_id rather than oem_id for better robustness
---
 arch/x86/kernel/cpu/common.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 7cce91b19fb2..8d78d34cd434 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -26,6 +26,7 @@
 #include <linux/pgtable.h>
 #include <linux/stackprotector.h>
 #include <linux/utsname.h>
+#include <linux/acpi.h>
 
 #include <asm/alternative.h>
 #include <asm/cmdline.h>
@@ -516,6 +517,21 @@ static bool pku_disabled;
 
 static __always_inline void setup_pku(struct cpuinfo_x86 *c)
 {
+	/*
+	 * OSPKE seems broken on Apple Virtualization.
+	 * https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
+	 *
+	 * TODO: conditionally enable pku depending on the DMI BIOS version when Apple
+	 * fixes the issue.
+	 *
+	 * However, this would be still not enough because DMI is missing when vmlinuz
+	 * is directly loaded into VM.
+	 */
+	if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
+		pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
+		pku_disabled = true;
+	}
+
 	if (c == &boot_cpu_data) {
 		if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
 			return;
-- 
2.45.2
Re: [PATCH v2] x86: disable PKU when running on Apple Virtualization
Posted by kernel test robot 9 months ago
Hi Akihiro,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/master linus/master v6.14-rc6 next-20250313]
[cannot apply to tip/auto-latest]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Akihiro-Suda/x86-disable-PKU-when-running-on-Apple-Virtualization/20250312-181106
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20250312100926.34954-1-akihiro.suda.cz%40hco.ntt.co.jp
patch subject: [PATCH v2] x86: disable PKU when running on Apple Virtualization
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20250314/202503141349.bpi8pvc4-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250314/202503141349.bpi8pvc4-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202503141349.bpi8pvc4-lkp@intel.com/

All errors (new ones prefixed by >>):

>> arch/x86/kernel/cpu/common.c:530:14: error: use of undeclared identifier 'acpi_gbl_FADT'
     530 |         if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
         |                     ^
   1 error generated.


vim +/acpi_gbl_FADT +530 arch/x86/kernel/cpu/common.c

   517	
   518	static __always_inline void setup_pku(struct cpuinfo_x86 *c)
   519	{
   520		/*
   521		 * OSPKE seems broken on Apple Virtualization.
   522		 * https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
   523		 *
   524		 * TODO: conditionally enable pku depending on the DMI BIOS version when Apple
   525		 * fixes the issue.
   526		 *
   527		 * However, this would be still not enough because DMI is missing when vmlinuz
   528		 * is directly loaded into VM.
   529		 */
 > 530		if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
   531			pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
   532			pku_disabled = true;
   533		}
   534	
   535		if (c == &boot_cpu_data) {
   536			if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
   537				return;
   538			/*
   539			 * Setting CR4.PKE will cause the X86_FEATURE_OSPKE cpuid
   540			 * bit to be set.  Enforce it.
   541			 */
   542			setup_force_cpu_cap(X86_FEATURE_OSPKE);
   543	
   544		} else if (!cpu_feature_enabled(X86_FEATURE_OSPKE)) {
   545			return;
   546		}
   547	
   548		cr4_set_bits(X86_CR4_PKE);
   549		/* Load the default PKRU value */
   550		pkru_write_default();
   551	}
   552	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2] x86: disable PKU when running on Apple Virtualization
Posted by kernel test robot 9 months ago
Hi Akihiro,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/master linus/master v6.14-rc6 next-20250313]
[cannot apply to tip/auto-latest]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Akihiro-Suda/x86-disable-PKU-when-running-on-Apple-Virtualization/20250312-181106
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20250312100926.34954-1-akihiro.suda.cz%40hco.ntt.co.jp
patch subject: [PATCH v2] x86: disable PKU when running on Apple Virtualization
config: i386-allnoconfig (https://download.01.org/0day-ci/archive/20250314/202503141345.LkDyBcmV-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250314/202503141345.LkDyBcmV-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202503141345.LkDyBcmV-lkp@intel.com/

All errors (new ones prefixed by >>):

   arch/x86/kernel/cpu/common.c: In function 'setup_pku':
>> arch/x86/kernel/cpu/common.c:530:21: error: 'acpi_gbl_FADT' undeclared (first use in this function); did you mean 'acpi_table_fadt'?
     530 |         if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
         |                     ^~~~~~~~~~~~~
         |                     acpi_table_fadt
   arch/x86/kernel/cpu/common.c:530:21: note: each undeclared identifier is reported only once for each function it appears in


vim +530 arch/x86/kernel/cpu/common.c

   517	
   518	static __always_inline void setup_pku(struct cpuinfo_x86 *c)
   519	{
   520		/*
   521		 * OSPKE seems broken on Apple Virtualization.
   522		 * https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
   523		 *
   524		 * TODO: conditionally enable pku depending on the DMI BIOS version when Apple
   525		 * fixes the issue.
   526		 *
   527		 * However, this would be still not enough because DMI is missing when vmlinuz
   528		 * is directly loaded into VM.
   529		 */
 > 530		if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
   531			pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
   532			pku_disabled = true;
   533		}
   534	
   535		if (c == &boot_cpu_data) {
   536			if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
   537				return;
   538			/*
   539			 * Setting CR4.PKE will cause the X86_FEATURE_OSPKE cpuid
   540			 * bit to be set.  Enforce it.
   541			 */
   542			setup_force_cpu_cap(X86_FEATURE_OSPKE);
   543	
   544		} else if (!cpu_feature_enabled(X86_FEATURE_OSPKE)) {
   545			return;
   546		}
   547	
   548		cr4_set_bits(X86_CR4_PKE);
   549		/* Load the default PKRU value */
   550		pkru_write_default();
   551	}
   552	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2] x86: disable PKU when running on Apple Virtualization
Posted by Ingo Molnar 9 months, 1 week ago
* Akihiro Suda <suda.gitsendemail@gmail.com> wrote:

> OSPKE seems broken on Apple Virtualization.
> 
>   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
> 
> Tested on macOS 13.5.1 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>
> ---
> v2: check oem_table_id rather than oem_id for better robustness

So this is rather weird, but I've applied the quirk as it upgrades 
broken guest side code into a boot time warning.

> +	/*
> +	 * OSPKE seems broken on Apple Virtualization.
> +	 * https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
> +	 *
> +	 * TODO: conditionally enable pku depending on the DMI BIOS version when Apple
> +	 * fixes the issue.
> +	 *
> +	 * However, this would be still not enough because DMI is missing when vmlinuz
> +	 * is directly loaded into VM.
> +	 */
> +	if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
> +		pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
> +		pku_disabled = true;
> +	}

Note that I updated the comments here (the git log gives enough 
information), plus enclosed this into #ifdef CONFIG_ACPI, as 
acpi_gbl_FADT is not available on !CONFIG_ACPI builds.

Thanks,

	Ingo
Re: [PATCH v2] x86: disable PKU when running on Apple Virtualization
Posted by Akihiro Suda 9 months, 1 week ago
Thank you Ingo, and sorry for adding #ifdef CONFIG_ACPI

Regards,
Akihiro Suda

2025年3月14日(金) 2:02 Ingo Molnar <mingo@kernel.org>:
>
>
> * Akihiro Suda <suda.gitsendemail@gmail.com> wrote:
>
> > OSPKE seems broken on Apple Virtualization.
> >
> >   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
> >
> > Tested on macOS 13.5.1 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>
> > ---
> > v2: check oem_table_id rather than oem_id for better robustness
>
> So this is rather weird, but I've applied the quirk as it upgrades
> broken guest side code into a boot time warning.
>
> > +     /*
> > +      * OSPKE seems broken on Apple Virtualization.
> > +      * https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
> > +      *
> > +      * TODO: conditionally enable pku depending on the DMI BIOS version when Apple
> > +      * fixes the issue.
> > +      *
> > +      * However, this would be still not enough because DMI is missing when vmlinuz
> > +      * is directly loaded into VM.
> > +      */
> > +     if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
> > +             pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
> > +             pku_disabled = true;
> > +     }
>
> Note that I updated the comments here (the git log gives enough
> information), plus enclosed this into #ifdef CONFIG_ACPI, as
> acpi_gbl_FADT is not available on !CONFIG_ACPI builds.
>
> Thanks,
>
>         Ingo
Re: [PATCH v2] x86: disable PKU when running on Apple Virtualization
Posted by Greg KH 9 months, 1 week ago
On Wed, Mar 12, 2025 at 07:09:26PM +0900, Akihiro Suda wrote:
> OSPKE seems broken on Apple Virtualization.
> 
>   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
> 
> Tested on macOS 13.5.1 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>
> ---
> v2: check oem_table_id rather than oem_id for better robustness
> ---
>  arch/x86/kernel/cpu/common.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index 7cce91b19fb2..8d78d34cd434 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -26,6 +26,7 @@
>  #include <linux/pgtable.h>
>  #include <linux/stackprotector.h>
>  #include <linux/utsname.h>
> +#include <linux/acpi.h>
>  
>  #include <asm/alternative.h>
>  #include <asm/cmdline.h>
> @@ -516,6 +517,21 @@ static bool pku_disabled;
>  
>  static __always_inline void setup_pku(struct cpuinfo_x86 *c)
>  {
> +	/*
> +	 * OSPKE seems broken on Apple Virtualization.
> +	 * https://lore.kernel.org/regressions/CAG8fp8QvH71Wi_y7b7tgFp7knK38rfrF7rRHh-gFKqeS0gxY6Q@mail.gmail.com/T/#u
> +	 *
> +	 * TODO: conditionally enable pku depending on the DMI BIOS version when Apple
> +	 * fixes the issue.
> +	 *
> +	 * However, this would be still not enough because DMI is missing when vmlinuz
> +	 * is directly loaded into VM.
> +	 */
> +	if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
> +		pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
> +		pku_disabled = true;
> +	}
> +
>  	if (c == &boot_cpu_data) {
>  		if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
>  			return;
> -- 
> 2.45.2
> 
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an
  older released kernel, yet you do not have a cc: stable line in the
  signed-off-by area at all, which means that the patch will not be
  applied to any older kernel releases.  To properly fix this, please
  follow the documented rules in the
  Documentation/process/stable-kernel-rules.rst file for how to resolve
  this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot
[tip: x86/urgent] x86/pkeys: Disable PKU when running on Apple Virtualization
Posted by tip-bot2 for Akihiro Suda 9 months, 1 week ago
The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     0457ee8d3da0e497c42ca68b7c3c70e9b39cba98
Gitweb:        https://git.kernel.org/tip/0457ee8d3da0e497c42ca68b7c3c70e9b39cba98
Author:        Akihiro Suda <suda.gitsendemail@gmail.com>
AuthorDate:    Wed, 12 Mar 2025 19:09:26 +09:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 13 Mar 2025 17:59:46 +01:00

x86/pkeys: Disable PKU when running on Apple Virtualization

Protection keys seem broken on Apple Virtualization, they produce this warning:

  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

Work it around by applying a quirk: look up 'Apple Vz' in the
ACPI FADT table in setup_pku() and disabling PKU.

Tested on macOS 13.5.1 running on MacBook Pro 2020 with
Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz.

[ mingo: Fixed !ACPI build bug, updated the comments and the changelog. ]

Fixes: 70044df250d0 ("x86/pkeys: Update PKRU to enable all pkeys before XSAVE")
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://github.com/lima-vm/lima/issues/3334
Link: https://lore.kernel.org/r/20250312100926.34954-1-akihiro.suda.cz@hco.ntt.co.jp
---
 arch/x86/kernel/cpu/common.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 7cce91b..c1bab70 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -26,6 +26,7 @@
 #include <linux/pgtable.h>
 #include <linux/stackprotector.h>
 #include <linux/utsname.h>
+#include <linux/acpi.h>
 
 #include <asm/alternative.h>
 #include <asm/cmdline.h>
@@ -510,12 +511,23 @@ static __init int x86_nofsgsbase_setup(char *arg)
 __setup("nofsgsbase", x86_nofsgsbase_setup);
 
 /*
- * Protection Keys are not available in 32-bit mode.
+ * Protection Keys are not available in 32-bit mode and in
+ * certain virtual guest environments.
  */
 static bool pku_disabled;
 
 static __always_inline void setup_pku(struct cpuinfo_x86 *c)
 {
+#ifdef CONFIG_ACPI
+	/*
+	 * OSPKE seems broken on Apple Virtualization:
+	 */
+	if (!memcmp(acpi_gbl_FADT.header.oem_table_id, "Apple Vz", 8)) {
+		pr_info("pku: disabled on Apple Virtualization platform (Intel) due to a bug\n");
+		pku_disabled = true;
+	}
+#endif
+
 	if (c == &boot_cpu_data) {
 		if (pku_disabled || !cpu_feature_enabled(X86_FEATURE_PKU))
 			return;