Skip to contentSkip to conversation

KVM NV + SVE host OS warning

DISCUSSION Marc Zyngier 3 participants 17 messages Sep 25, 2025 – Oct 9, 2025 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Marc Zyngier

author maintainer
#1 lore raw

[+Oliver for the SVE stuff]

Hi Jan,

Quoted 8 lines · Jan Kotas

Hello,

I’m experimenting with Nested Virtualization.
I use Linux kernel 6.16.3 from Debian backports running on Neoverse-V2.

When I try to boot a GuestOS, it hangs,
and I can see a warning in Host's dmesg:

Quoted 6 lines
[52417.934951] ------------[ cut here ]------------
[52417.934990] WARNING: CPU: 120 PID: 44115 at arch/arm64/include/asm/kvm_emulate.h:553 perform_access+0x14c/0x160
[52417.935087] Modules linked in: nfsv3 nfs netfs snd_seq_dummy snd_hrtimer snd_seq snd_seq_device snd_timer snd soundcore rfkill qrtr binfmt_misc nls_ascii nls_cp437 vfat fat aes_ce_blk aes_ce_cipher polyval_ce ghash_ce gf128mul sha3_ce sha512_ce sha1_ce acpi_ipmi dax_hmem arm_smccc_trng cxl_acpi ipmi_ssif i2c_smbus arm_spe_pmu arm_smmuv3_pmu coresight_trbe spi_nor mtd ipmi_devintf ipmi_msghandler coresight_stm coresight_tmc coresight_funnel stm_core coresight_etm4x coresight joydev evdev cppc_cpufreq nfsd auth_rpcgss nfs_acl lockd grace sunrpc efi_pstore configfs nfnetlink efivarfs ip_tables x_tables autofs4 ext4 crc16 mbcache jbd2 crc32c_cryptoapi hid_generic usbhid hid rndis_host cdc_ether usbnet mii dm_mod ast ixgbe drm_shmem_helper xhci_pci_renesas i2c_algo_bit xfrm_algo xhci_pci drm_client_lib mdio_devres drm_kms_helper xhci_hcd of_mdio nvme fixed_phy drm fwnode_mdio usbcore nvme_core libphy sbsa_gwdt mdio_bus nvme_keyring usb_common nvme_auth mdio i2c_tegra
[52417.935818] CPU: 120 UID: 254353 PID: 44115 Comm: kvm_vcpu0 Tainted: G        W           6.16.3+deb13-arm64 #1 PREEMPTLAZY  Debian 6.16.3-1~bpo13+1
[52417.935855] Tainted: [W]=WARN
[52417.935866] Hardware name: Supermicro ARS-121L-DNR/G1SMH, BIOS 2.1 04/17/2025

Fancy HW (/me goes selling a kidney...)

Quoted 38 lines
[52417.935879] pstate: 62400009 (nZCv daif +PAN -UAO +TCO -DIT -SSBS BTYPE=--)
[52417.935906] pc : perform_access+0x14c/0x160
[52417.935933] lr : perform_access+0x4c/0x160
[52417.935956] sp : ffff8000f30db850
[52417.935967] x29: ffff8000f30db850 x28: ffff000097245000 x27: 0000000000000000
[52417.936004] x26: 0000000000000000 x25: 0000000000000000 x24: ffff10002c701c28
[52417.936036] x23: 0000000000000000 x22: ffff000097245000 x21: ffff8000f30db8a0
[52417.936065] x20: ffffdbf14a19eac0 x19: ffff10002c701be0 x18: 0000000000000014
[52417.936095] x17: 000000040044ffff x16: 00100075b5503510 x15: 0000000000000000
[52417.936127] x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000
[52417.936157] x11: 0000000000001348 x10: 00000000000013b0 x9 : ffffdbf1491608b4
[52417.936188] x8 : 0000000000000001 x7 : 0000000000000000 x6 : 00000000000fffff
[52417.936218] x5 : 000000000036cb76 x4 : ffff10027148f7c0 x3 : ffffdbf14915f04c
[52417.936249] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000009
[52417.936280] Call trace:
[52417.936291]  perform_access+0x14c/0x160 (P)
[52417.936325]  kvm_handle_sys_reg+0x12c/0x2a0
[52417.936366]  handle_exit+0x68/0x190
[52417.936408]  kvm_arch_vcpu_ioctl_run+0x2d8/0xa10
[52417.936436]  kvm_vcpu_ioctl+0x1a8/0xb18
[52417.936459]  __arm64_sys_ioctl+0xb4/0x120
[52417.936510]  invoke_syscall+0x6c/0x100
[52417.936547]  el0_svc_common.constprop.0+0x48/0xf0
[52417.936581]  do_el0_svc+0x24/0x38
[52417.936613]  el0_svc+0xd4/0x190
[52417.936643]  el0t_64_sync_handler+0x10c/0x138
[52417.936667]  el0t_64_sync+0x198/0x1a0
[52417.936690] ---[ end trace 0000000000000000 ]---

The tracing revealed, it may be caused by a ZCR_EL2 write:
[109] ..... 52068.375927: kvm_sys_access: PC: 806608b8 SYS_ZCR_EL2 (3,4,1,2,0) write

The instruction from ELR also matches: msr zcr_el2, x1

The reason might be CPTR_EL2, its value just before this instruction is executed, is 0. However before the start of the VM execution, it has 0x22ff.

Quoted 7 lines

I can see accesses to this register in the trace log as well, just before ZCR_EL2 is accessed.
[109] ..... 52068.375922: kvm_sys_access: PC: 806608a4 SYS_CPTR_EL2 (3,4,1,1,2) read
[109] ..... 52068.375925: kvm_sys_access: PC: 806608ac SYS_CPTR_EL2 (3,4,1,1,2) write

I’m running Linux 6.16.0 as my Guest.
Nested Virtualization works fine with SVE disabled, so does SVE without NV. Could it be caused by a bug in userspace hypervisor code?

Unlikely. The warning indicates that we are incrementing PC while there is a pending exception. Having both at the same time is a very bad bug -- hence the warning.

Looking at the code with the above in mind, something immediately jumps at me. Can you try the following (against 6.17, but you'll surely be able to apply it against 6.16):

arch/arm64/kvm/sys_regs.c +1 -1
index 91053aa832d08..a07ad5c92583d 100644
@@ -2705,7 +2705,7 @@ static bool access_zcr_el2(struct kvm_vcpu *vcpu,
 
 	if (guest_hyp_sve_traps_enabled(vcpu)) {
 		kvm_inject_nested_sve_trap(vcpu);
-		return true;
+		return false;
 	}
 
 	if (!p->is_write) {

This should make the warning go away -- not sure about anything else. Note that I do not have access to an NV+SVE capable machine, so you're are basically on your own, unless Oliver has a box he can reproduce this on.

I would also recommend to update to 6.17 -- 6.16 was the first release with NV, and while it may work, it will also have a lot of ugly bugs.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw

Hi Marc,

Thank you for a quick response.

Quoted 96 lines · Marc Zyngier

EXTERNAL MAIL

[+Oliver for the SVE stuff]

Hi Jan,

Quoted 8 lines · Jan Kotas

Hello,

I’m experimenting with Nested Virtualization.
I use Linux kernel 6.16.3 from Debian backports running on Neoverse-V2.

When I try to boot a GuestOS, it hangs,
and I can see a warning in Host's dmesg:

Quoted 6 lines
[52417.934951] ------------[ cut here ]------------
[52417.934990] WARNING: CPU: 120 PID: 44115 at arch/arm64/include/asm/kvm_emulate.h:553 perform_access+0x14c/0x160
[52417.935087] Modules linked in: nfsv3 nfs netfs snd_seq_dummy snd_hrtimer snd_seq snd_seq_device snd_timer snd soundcore rfkill qrtr binfmt_misc nls_ascii nls_cp437 vfat fat aes_ce_blk aes_ce_cipher polyval_ce ghash_ce gf128mul sha3_ce sha512_ce sha1_ce acpi_ipmi dax_hmem arm_smccc_trng cxl_acpi ipmi_ssif i2c_smbus arm_spe_pmu arm_smmuv3_pmu coresight_trbe spi_nor mtd ipmi_devintf ipmi_msghandler coresight_stm coresight_tmc coresight_funnel stm_core coresight_etm4x coresight joydev evdev cppc_cpufreq nfsd auth_rpcgss nfs_acl lockd grace sunrpc efi_pstore configfs nfnetlink efivarfs ip_tables x_tables autofs4 ext4 crc16 mbcache jbd2 crc32c_cryptoapi hid_generic usbhid hid rndis_host cdc_ether usbnet mii dm_mod ast ixgbe drm_shmem_helper xhci_pci_renesas i2c_algo_bit xfrm_algo xhci_pci drm_client_lib mdio_devres drm_kms_helper xhci_hcd of_mdio nvme fixed_phy drm fwnode_mdio usbcore nvme_core libphy sbsa_gwdt mdio_bus nvme_keyring usb_common nvme_auth mdio i2c_tegra
[52417.935818] CPU: 120 UID: 254353 PID: 44115 Comm: kvm_vcpu0 Tainted: G        W           6.16.3+deb13-arm64 #1 PREEMPTLAZY  Debian 6.16.3-1~bpo13+1
[52417.935855] Tainted: [W]=WARN
[52417.935866] Hardware name: Supermicro ARS-121L-DNR/G1SMH, BIOS 2.1 04/17/2025

Fancy HW (/me goes selling a kidney...)

Quoted 38 lines
[52417.935879] pstate: 62400009 (nZCv daif +PAN -UAO +TCO -DIT -SSBS BTYPE=--)
[52417.935906] pc : perform_access+0x14c/0x160
[52417.935933] lr : perform_access+0x4c/0x160
[52417.935956] sp : ffff8000f30db850
[52417.935967] x29: ffff8000f30db850 x28: ffff000097245000 x27: 0000000000000000
[52417.936004] x26: 0000000000000000 x25: 0000000000000000 x24: ffff10002c701c28
[52417.936036] x23: 0000000000000000 x22: ffff000097245000 x21: ffff8000f30db8a0
[52417.936065] x20: ffffdbf14a19eac0 x19: ffff10002c701be0 x18: 0000000000000014
[52417.936095] x17: 000000040044ffff x16: 00100075b5503510 x15: 0000000000000000
[52417.936127] x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000
[52417.936157] x11: 0000000000001348 x10: 00000000000013b0 x9 : ffffdbf1491608b4
[52417.936188] x8 : 0000000000000001 x7 : 0000000000000000 x6 : 00000000000fffff
[52417.936218] x5 : 000000000036cb76 x4 : ffff10027148f7c0 x3 : ffffdbf14915f04c
[52417.936249] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000009
[52417.936280] Call trace:
[52417.936291]  perform_access+0x14c/0x160 (P)
[52417.936325]  kvm_handle_sys_reg+0x12c/0x2a0
[52417.936366]  handle_exit+0x68/0x190
[52417.936408]  kvm_arch_vcpu_ioctl_run+0x2d8/0xa10
[52417.936436]  kvm_vcpu_ioctl+0x1a8/0xb18
[52417.936459]  __arm64_sys_ioctl+0xb4/0x120
[52417.936510]  invoke_syscall+0x6c/0x100
[52417.936547]  el0_svc_common.constprop.0+0x48/0xf0
[52417.936581]  do_el0_svc+0x24/0x38
[52417.936613]  el0_svc+0xd4/0x190
[52417.936643]  el0t_64_sync_handler+0x10c/0x138
[52417.936667]  el0t_64_sync+0x198/0x1a0
[52417.936690] ---[ end trace 0000000000000000 ]---

The tracing revealed, it may be caused by a ZCR_EL2 write:
[109] ..... 52068.375927: kvm_sys_access: PC: 806608b8 SYS_ZCR_EL2 (3,4,1,2,0) write

The instruction from ELR also matches: msr zcr_el2, x1

The reason might be CPTR_EL2, its value just before this instruction is executed, is 0. However before the start of the VM execution, it has 0x22ff.

Quoted 7 lines

I can see accesses to this register in the trace log as well, just before ZCR_EL2 is accessed.
[109] ..... 52068.375922: kvm_sys_access: PC: 806608a4 SYS_CPTR_EL2 (3,4,1,1,2) read
[109] ..... 52068.375925: kvm_sys_access: PC: 806608ac SYS_CPTR_EL2 (3,4,1,1,2) write

I’m running Linux 6.16.0 as my Guest.
Nested Virtualization works fine with SVE disabled, so does SVE without NV. Could it be caused by a bug in userspace hypervisor code?

Unlikely. The warning indicates that we are incrementing PC while there is a pending exception. Having both at the same time is a very bad bug -- hence the warning.

Looking at the code with the above in mind, something immediately jumps at me. Can you try the following (against 6.17, but you'll surely be able to apply it against 6.16):

arch/arm64/kvm/sys_regs.c +1 -1
index 91053aa832d08..a07ad5c92583d 100644
@@ -2705,7 +2705,7 @@ static bool access_zcr_el2(struct kvm_vcpu *vcpu,
 
 if (guest_hyp_sve_traps_enabled(vcpu)) {
 kvm_inject_nested_sve_trap(vcpu);
- return true;
+ return false;
 }
 
 if (!p->is_write) {
Quoted 7 lines

This should make the warning go away -- not sure about anything else. Note that I do not have access to an NV+SVE capable machine, so you're are basically on your own, unless Oliver has a box he can reproduce this on.

I would also recommend to update to 6.17 -- 6.16 was the first release with NV, and while it may work, it will also have a lot of ugly bugs.

I will try, but as I don’t own this machine, changing kernels might be… challenging.
If there’s anything else I can provide to help track it down, please let me know.

Quoted 7 lines

Thanks,

M.

Signature · 1 line
Without deviation from the norm, progress is not possible.

Regards,
Jan

author maintainer
#3 lore raw
Quoted 13 lines · Jan Kotas

Hi Marc,

Thank you for a quick response.

Quoted 8 lines · Marc Zyngier

EXTERNAL MAIL

[+Oliver for the SVE stuff]

Hi Jan,

[...]

Quoted 6 lines
Quoted 3 lines

I would also recommend to update to 6.17 -- 6.16 was the first release with NV, and while it may work, it will also have a lot of ugly bugs.

I will try, but as I don’t own this machine, changing kernels might be… challenging.

Well, you're already passing something on the command-line that is documented as "experimental and should be used with extreme caution". Changing the kernel is a walk in the park compared to that ;-).

Quoted 2 lines

If there’s anything else I can provide to help track it down, please let me know.

Testing the provided patch would be good -- I would if I could.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#4 lore raw
Quoted 22 lines · Marc Zyngier
Quoted 13 lines · Jan Kotas

Hi Marc,

Thank you for a quick response.

Quoted 8 lines · Marc Zyngier

EXTERNAL MAIL

[+Oliver for the SVE stuff]

Hi Jan,

[...]

Quoted 4 lines
Quoted 3 lines

I would also recommend to update to 6.17 -- 6.16 was the first release with NV, and while it may work, it will also have a lot of ugly bugs.

Quoted 6 lines
Quoted 2 lines

I will try, but as I don’t own this machine, changing kernels might be… challenging.

Well, you're already passing something on the command-line that is documented as "experimental and should be used with extreme caution". Changing the kernel is a walk in the park compared to that ;-).

+1, also it'd be good to know what you're doing in the L1 and the L2 that leads to this bug.

I just tried the original test setup I used when doing NV SVE and things appear to work (kvmarm/next + initramfs at L1 + L2, tested with sve-stress selftest).

Quoted 4 lines
Quoted 2 lines

If there’s anything else I can provide to help track it down, please let me know.

Testing the provided patch would be good -- I would if I could.

Although I didn't repro the bug, the patch itself LGTM.

Thanks,
Oliver

#5 lore raw

Hello,

I was finally able to do some validation, sorry for a long delay.

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Regards,
Jan

Quoted 51 lines · Oliver Upton

EXTERNAL MAIL

Quoted 22 lines · Marc Zyngier
Quoted 13 lines · Jan Kotas

Hi Marc,

Thank you for a quick response.

Quoted 8 lines · Marc Zyngier

EXTERNAL MAIL

[+Oliver for the SVE stuff]

Hi Jan,

[...]

Quoted 4 lines
Quoted 3 lines

I would also recommend to update to 6.17 -- 6.16 was the first release with NV, and while it may work, it will also have a lot of ugly bugs.

Quoted 6 lines
Quoted 2 lines

I will try, but as I don’t own this machine, changing kernels might be… challenging.

Well, you're already passing something on the command-line that is documented as "experimental and should be used with extreme caution". Changing the kernel is a walk in the park compared to that ;-).

+1, also it'd be good to know what you're doing in the L1 and the L2 that leads to this bug.

I just tried the original test setup I used when doing NV SVE and things appear to work (kvmarm/next + initramfs at L1 + L2, tested with sve-stress selftest).

Quoted 4 lines
Quoted 2 lines

If there’s anything else I can provide to help track it down, please let me know.

Testing the provided patch would be good -- I would if I could.

Although I didn't repro the bug, the patch itself LGTM.

Thanks,
Oliver

#6 lore raw
Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 7 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

Quoted 6 lines

I checked the ESR_EL2 register and it has 0x66000000:

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

Thanks,
Oliver

#7 lore raw

Hi Oliver,

Quoted 21 lines · Oliver Upton

EXTERNAL MAIL

Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 9 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Quoted 8 lines
Quoted 4 lines

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

I’m running a minimal, unmodified Linux 6.16.0, for my integration tests. It only has a CPU, a GIC, a few UARTs, and uses initramfs.

In my VMM I only set KVM_ARM_VCPU_HAS_EL2, without HAS_EL2_E2H0. To start the kernel I set the X0-X3 registers.
It worked fine, so far, for all other cases than SVE && NV.

Quoted 4 lines

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

I checked the place, where it’s failing.
It looks like Guest clears CPTR_EL2 from 0x33ff to 0. CPACR_EL1 is 0 at this point. This doesn’t seem to be correct.

8062192c:   mrs     x0, cptr_el2
80621930:   and     x0, x0, #0xfffffffffffffeff
80621934:   msr     cptr_el2, x0
80621938:   isb

And accessing ZCR_EL2 is trapped, and causes an exception.

8062193c:   mov     x1, #0xf
80621940:   msr     zcr_el2, x1

Looks like the Guest OS executes
.Lcptr_nvhe_\@: // nVHE case
from el2_setup.h.

Quoted 2 lines

Thanks,
Oliver

Regards,
Jan

#8 lore raw
Quoted 58 lines · Jan Kotas

Hi Oliver,

Quoted 21 lines · Oliver Upton

EXTERNAL MAIL

Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 9 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Quoted 8 lines
Quoted 4 lines

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

I’m running a minimal, unmodified Linux 6.16.0, for my integration tests. It only has a CPU, a GIC, a few UARTs, and uses initramfs.

In my VMM I only set KVM_ARM_VCPU_HAS_EL2, without HAS_EL2_E2H0. To start the kernel I set the X0-X3 registers.
It worked fine, so far, for all other cases than SVE && NV.

Quoted 4 lines

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

I checked the place, where it’s failing.
It looks like Guest clears CPTR_EL2 from 0x33ff to 0. CPACR_EL1 is 0 at this point. This doesn’t seem to be correct.

8062192c:   mrs     x0, cptr_el2
80621930:   and     x0, x0, #0xfffffffffffffeff
80621934:   msr     cptr_el2, x0
80621938:   isb
Quoted 7 lines

And accessing ZCR_EL2 is trapped, and causes an exception.

8062193c:   mov     x1, #0xf
80621940:   msr     zcr_el2, x1

Looks like the Guest OS executes
.Lcptr_nvhe_\@: // nVHE case
from el2_setup.h.

I did some more debugging.
I checked __check_hvhe and it looks like it jumps to fail. HCR_EL2 has 0x100030080000000.
E2H is set to 0, even though it should be RES1?
I changed the value using a debugger, so the check passed. The code took a different branch and it seems the SVE init passed.

Quoted 5 lines
Quoted 2 lines

Thanks,
Oliver

Regards,
Jan

author maintainer
#9 lore raw
Quoted 63 lines · Jan Kotas
Quoted 63 lines · Jan Kotas

Hi Oliver,

Quoted 21 lines · Oliver Upton

EXTERNAL MAIL

Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 9 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Quoted 8 lines
Quoted 4 lines

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

I’m running a minimal, unmodified Linux 6.16.0, for my integration tests. It only has a CPU, a GIC, a few UARTs, and uses initramfs.

In my VMM I only set KVM_ARM_VCPU_HAS_EL2, without HAS_EL2_E2H0. To start the kernel I set the X0-X3 registers.
It worked fine, so far, for all other cases than SVE && NV.

Quoted 4 lines

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

I checked the place, where it’s failing.
It looks like Guest clears CPTR_EL2 from 0x33ff to 0. CPACR_EL1 is 0 at this point. This doesn’t seem to be correct.

8062192c:   mrs     x0, cptr_el2
80621930:   and     x0, x0, #0xfffffffffffffeff
80621934:   msr     cptr_el2, x0
80621938:   isb

And accessing ZCR_EL2 is trapped, and causes an exception.

8062193c:   mov     x1, #0xf
80621940:   msr     zcr_el2, x1
Quoted 8 lines
Quoted 3 lines

Looks like the Guest OS executes
.Lcptr_nvhe_\@: // nVHE case
from el2_setup.h.

I did some more debugging.
I checked __check_hvhe and it looks like it jumps to fail. HCR_EL2 has 0x100030080000000.
E2H is set to 0, even though it should be RES1?

The value itself doesn't matter for KVM. However, the guest can write anything it wants, and that value will hold *in the register*.

Quoted 2 lines

I changed the value using a debugger, so the check passed. The code took a different branch and it seems the SVE init passed.

Oh crap. You are on V2, which doesn't have FGT, so ID_AA64MMFR4_EL1 doesn't trap, and the kernel end-up assuming that the CPU is nVHE capable. Nothing works after that.

I'm afraid there is no real fix for this, only hacks...

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#10 lore raw

Hi Marc,

Thanks for looking into this.

Quoted 82 lines · Marc Zyngier

EXTERNAL MAIL

Quoted 63 lines · Jan Kotas
Quoted 63 lines · Jan Kotas

Hi Oliver,

Quoted 21 lines · Oliver Upton

EXTERNAL MAIL

Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 9 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Quoted 8 lines
Quoted 4 lines

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

I’m running a minimal, unmodified Linux 6.16.0, for my integration tests. It only has a CPU, a GIC, a few UARTs, and uses initramfs.

In my VMM I only set KVM_ARM_VCPU_HAS_EL2, without HAS_EL2_E2H0. To start the kernel I set the X0-X3 registers.
It worked fine, so far, for all other cases than SVE && NV.

Quoted 4 lines

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

I checked the place, where it’s failing.
It looks like Guest clears CPTR_EL2 from 0x33ff to 0. CPACR_EL1 is 0 at this point. This doesn’t seem to be correct.

8062192c:   mrs     x0, cptr_el2
80621930:   and     x0, x0, #0xfffffffffffffeff
80621934:   msr     cptr_el2, x0
80621938:   isb

And accessing ZCR_EL2 is trapped, and causes an exception.

8062193c:   mov     x1, #0xf
80621940:   msr     zcr_el2, x1
Quoted 8 lines
Quoted 3 lines

Looks like the Guest OS executes
.Lcptr_nvhe_\@: // nVHE case
from el2_setup.h.

I did some more debugging.
I checked __check_hvhe and it looks like it jumps to fail. HCR_EL2 has 0x100030080000000.
E2H is set to 0, even though it should be RES1?

The value itself doesn't matter for KVM. However, the guest can write anything it wants, and that value will hold *in the register*.

Quoted 8 lines
Quoted 2 lines

I changed the value using a debugger, so the check passed. The code took a different branch and it seems the SVE init passed.

Oh crap. You are on V2, which doesn't have FGT, so ID_AA64MMFR4_EL1 doesn't trap, and the kernel end-up assuming that the CPU is nVHE capable. Nothing works after that.

I'm afraid there is no real fix for this, only hacks...

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Quoted 5 lines

M.

Signature · 1 line
Without deviation from the norm, progress is not possible.

Regards,
Jan

author maintainer
#11 lore raw
Quoted 95 lines · Jan Kotas

Hi Marc,

Thanks for looking into this.

Quoted 89 lines · Marc Zyngier

EXTERNAL MAIL

Quoted 63 lines · Jan Kotas
Quoted 63 lines · Jan Kotas

Hi Oliver,

Quoted 21 lines · Oliver Upton

EXTERNAL MAIL

Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 9 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Quoted 8 lines
Quoted 4 lines

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

I’m running a minimal, unmodified Linux 6.16.0, for my integration tests. It only has a CPU, a GIC, a few UARTs, and uses initramfs.

In my VMM I only set KVM_ARM_VCPU_HAS_EL2, without HAS_EL2_E2H0. To start the kernel I set the X0-X3 registers.
It worked fine, so far, for all other cases than SVE && NV.

Quoted 4 lines

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

I checked the place, where it’s failing.
It looks like Guest clears CPTR_EL2 from 0x33ff to 0. CPACR_EL1 is 0 at this point. This doesn’t seem to be correct.

8062192c:   mrs     x0, cptr_el2
80621930:   and     x0, x0, #0xfffffffffffffeff
80621934:   msr     cptr_el2, x0
80621938:   isb

And accessing ZCR_EL2 is trapped, and causes an exception.

8062193c:   mov     x1, #0xf
80621940:   msr     zcr_el2, x1
Quoted 8 lines
Quoted 3 lines

Looks like the Guest OS executes
.Lcptr_nvhe_\@: // nVHE case
from el2_setup.h.

I did some more debugging.
I checked __check_hvhe and it looks like it jumps to fail. HCR_EL2 has 0x100030080000000.
E2H is set to 0, even though it should be RES1?

The value itself doesn't matter for KVM. However, the guest can write anything it wants, and that value will hold *in the register*.

Quoted 2 lines

I changed the value using a debugger, so the check passed. The code took a different branch and it seems the SVE init passed.

Oh crap. You are on V2, which doesn't have FGT, so ID_AA64MMFR4_EL1 doesn't trap, and the kernel end-up assuming that the CPU is nVHE capable. Nothing works after that.

Quoted 5 lines
Quoted 1 line

I'm afraid there is no real fix for this, only hacks...

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

There are no traps for HCR_EL2.

Quoted 2 lines

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Where did you read that from?

If you apply the following change to your guest, does it start behaving?

	M.
arch/arm64/include/asm/el2_setup.h +1 -1
index 46033027510cc..392c9f4016f2e 100644
@@ -34,7 +34,7 @@
 	mrs_s	x1, SYS_ID_AA64MMFR4_EL1
 	sbfx	x1, x1, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH
 	cmp	x1, #0
-	b.ge	.LnVHE_\@
+//	b.ge	.LnVHE_\@
 
 	orr	x0, x0, #HCR_E2H
 .LnVHE_\@:
Signature · 1 line
Without deviation from the norm, progress is not possible.
#12 lore raw
Quoted 110 lines · Marc Zyngier

EXTERNAL MAIL

Quoted 95 lines · Jan Kotas

Hi Marc,

Thanks for looking into this.

Quoted 89 lines · Marc Zyngier

EXTERNAL MAIL

Quoted 63 lines · Jan Kotas
Quoted 63 lines · Jan Kotas

Hi Oliver,

Quoted 21 lines · Oliver Upton

EXTERNAL MAIL

Quoted 3 lines · Jan Kotas

Hello,

I was finally able to do some validation, sorry for a long delay.

No worries, thanks for testing.

Quoted 9 lines

First I applied the "Don't advance PC" patch on top of 6.16.9. It fixed the error message, but the Guest didn’t boot. I didn’t debug it further.

Then I applied it on top of 6.17 along with Oliver’s second patch. Guest OS stops booting because of an exception, when accessing ZCR_EL2.

I checked the ESR_EL2 register and it has 0x66000000:

Quoted 8 lines
Quoted 4 lines

Access to SVE functionality trapped as a result of CPACR_EL1.ZEN, CPTR_EL2.ZEN, CPTR_EL2.TZ, or CPTR_EL3.EZ

I’ll continue the debug to make sure the issue is not on our end.

Could you please share the repro steps? Also, is the guest kernel unmodified? FWIW, I tested kvmarm/next as the kernel at all levels, kvmtool as the VMM and E2H=RES1.

I’m running a minimal, unmodified Linux 6.16.0, for my integration tests. It only has a CPU, a GIC, a few UARTs, and uses initramfs.

In my VMM I only set KVM_ARM_VCPU_HAS_EL2, without HAS_EL2_E2H0. To start the kernel I set the X0-X3 registers.
It worked fine, so far, for all other cases than SVE && NV.

Quoted 4 lines

While the trap to L0 is unavoidable, reinjecting the SVE trap depends on the L0 view of CPTR_EL2 which originates from the in-memory value. Unless there's a bug lurking this should always be in agreement with the effective value programmed in CPACR_EL1.

I checked the place, where it’s failing.
It looks like Guest clears CPTR_EL2 from 0x33ff to 0. CPACR_EL1 is 0 at this point. This doesn’t seem to be correct.

8062192c:   mrs     x0, cptr_el2
80621930:   and     x0, x0, #0xfffffffffffffeff
80621934:   msr     cptr_el2, x0
80621938:   isb

And accessing ZCR_EL2 is trapped, and causes an exception.

8062193c:   mov     x1, #0xf
80621940:   msr     zcr_el2, x1
Quoted 8 lines
Quoted 3 lines

Looks like the Guest OS executes
.Lcptr_nvhe_\@: // nVHE case
from el2_setup.h.

I did some more debugging.
I checked __check_hvhe and it looks like it jumps to fail. HCR_EL2 has 0x100030080000000.
E2H is set to 0, even though it should be RES1?

The value itself doesn't matter for KVM. However, the guest can write anything it wants, and that value will hold *in the register*.

Quoted 2 lines

I changed the value using a debugger, so the check passed. The code took a different branch and it seems the SVE init passed.

Oh crap. You are on V2, which doesn't have FGT, so ID_AA64MMFR4_EL1 doesn't trap, and the kernel end-up assuming that the CPU is nVHE capable. Nothing works after that.

Quoted 5 lines
Quoted 1 line

I'm afraid there is no real fix for this, only hacks...

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

Quoted 6 lines

There are no traps for HCR_EL2.

Quoted 2 lines

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Where did you read that from?

I checked the X1 register, after: mrs x1, hcr_el2 in __check_hvhe.

Quoted 16 lines

If you apply the following change to your guest, does it start behaving?

M.

arch/arm64/include/asm/el2_setup.h +0 -0
index 46033027510cc..392c9f4016f2e 100644
@@ -34,7 +34,7 @@

mrs_s x1, SYS_ID_AA64MMFR4_EL1
sbfx x1, x1, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH cmp x1, #0
- b.ge .LnVHE_\@
+// b.ge .LnVHE_\@

Quoted 3 lines

orr x0, x0, #HCR_E2H
.LnVHE_\@:

With this change Guest OS starts the boot process.

[ 0.000000] CPU features: detected: Virtualization Host Extensions
[ 6.998696] SMP: Total of 4 processors activated.
[ 7.257045] CPU: All CPU(s) started at EL2
[ 185.781062] SVE: maximum available vector length 16 bytes per vector
[ 186.104159] SVE: default vector length 16 bytes per vector

I also observed something interesting.
When PSCI method is set to HVC, I get a kernel panic. This wasn’t a problem in all other test cases.

[ 3.391773] smp: Bringing up secondary CPUs ...
[ 3.680981] Unhandled 64-bit el1h sync exception on CPU0, ESR 0x000000005a000000 -- HVC (AArch64)
[ 3.681680] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.16.0 #6 VOLUNTARY 
[ 3.682305] Hardware name: TEST_GUEST (DT)
[ 3.682747] pstate: a0000009 (NzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 3.683057] pc : __arm_smccc_hvc+0x8/0x30
[ 3.684216] lr : __invoke_psci_fn_hvc+0x3c/0x68
[ 3.685649] sp : ffff800080cabb00
[ 3.685739] x29: ffff800080cabb10 x28: 0000000000000028 x27: 0000000000000000
[ 3.686066] x26: 0000000000000000 x25: ffff80008003cac8 x24: ffff7fffbf294000
[ 3.686275] x23: 0000000000000001 x22: ffff800080c414f8 x21: ffff8000803ab888
[ 3.686445] x20: 0000000000000001 x19: ffff0000010d8000 x18: 00000000363e3f75
[ 3.686616] x17: 000000003a5017c7 x16: 00000000c25a262c x15: 0000b6183cc00fe2
[ 3.686806] x14: 0000000000000000 x13: 000000000000003e x12: ffff0000010d8000
[ 3.686981] x11: ffff00003fd97d54 x10: 0000000000000001 x9 : 0000000000000000
[ 3.687175] x8 : 0000000000000001 x7 : 0000000000000000 x6 : 0000000000000000
[ 3.687346] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000
[ 3.687505] x2 : 000000008073e454 x1 : 0000000000000100 x0 : 00000000c4000003
[ 3.687723] Kernel panic - not syncing: Unhandled exception
[ 3.687835] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.16.0 #6 VOLUNTARY 
[ 3.688028] Hardware name: TEST_GUEST (DT)
[ 3.688105] Call trace:
[ 3.688164] show_stack+0x18/0x24 (C)
[ 3.688377] dump_stack_lvl+0x38/0x90
[ 3.689093] dump_stack+0x18/0x24
[ 3.689339] panic+0x378/0x38c
[ 3.689724] arm64_exit_nmi.isra.0+0x0/0x94
[ 3.690216] el1h_64_sync_handler+0x8c/0x118
[ 3.690506] el1h_64_sync+0x6c/0x70
[ 3.690647] __arm_smccc_hvc+0x8/0x30 (P)
[ 3.691187] psci_0_1_cpu_on+0x2c/0x60
[ 3.691500] cpu_psci_cpu_boot+0x40/0x7c
[ 3.692400] __cpu_up+0x44/0x1d4
[ 3.692703] bringup_cpu+0x48/0x190
[ 3.692924] cpuhp_invoke_callback+0x120/0x230
[ 3.693127] __cpuhp_invoke_callback_range+0xa8/0x13c
[ 3.693337] _cpu_up+0x16c/0x398
[ 3.693550] cpu_up+0xa8/0x11c
[ 3.693762] bringup_nonboot_cpus+0x68/0xd4
[ 3.694451] smp_init+0x30/0x88
[ 3.694629] kernel_init_freeable+0x150/0x348
[ 3.694945] kernel_init+0x20/0x128
[ 3.695265] ret_from_fork+0x10/0x20
[ 15.461588] ---[ end Kernel panic - not syncing: Unhandled exception ]---

On a side note, thank you for giving me some pointers. With HAS_EL2_E2H the original Guest OS boots fine in nVHE.

[    0.204744] CPU: All CPU(s) started at EL2
[   18.483737] SVE: maximum available vector length 16 bytes per vector
[   18.500959] SVE: default vector length 16 bytes per vector
[   25.999475] kvm [1]: Hyp nVHE mode initialized successfully
Quoted 2 lines
Signature · 1 line
Without deviation from the norm, progress is not possible.

Regards,
Jan

author maintainer
#13 lore raw
Quoted 5 lines · Jan Kotas
Quoted 5 lines
Quoted 4 lines

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

Quoted 8 lines
Quoted 6 lines

There are no traps for HCR_EL2.

Quoted 2 lines

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Where did you read that from?

I checked the X1 register, after: mrs x1, hcr_el2 in __check_hvhe.

That's too late. At this point, the write to HCR_EL2 will have already occurred,

Quoted 24 lines
Quoted 18 lines

If you apply the following change to your guest, does it start behaving?

M.

arch/arm64/include/asm/el2_setup.h +0 -0
index 46033027510cc..392c9f4016f2e 100644
@@ -34,7 +34,7 @@

mrs_s x1, SYS_ID_AA64MMFR4_EL1
sbfx x1, x1, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH cmp x1, #0
- b.ge .LnVHE_\@
+// b.ge .LnVHE_\@

Quoted 3 lines

orr x0, x0, #HCR_E2H
.LnVHE_\@:

With this change Guest OS starts the boot process.

Quoted 5 lines
[ 0.000000] CPU features: detected: Virtualization Host Extensions
[ 6.998696] SMP: Total of 4 processors activated.
[ 7.257045] CPU: All CPU(s) started at EL2
[ 185.781062] SVE: maximum available vector length 16 bytes per vector
[ 186.104159] SVE: default vector length 16 bytes per vector

Great. That confirms my suspicion that we cannot advertise VHE on CPUs that do not have FEAT_FGT. Oh well. I'll post a patch to forbid VHE guests on these machines.

Quoted 3 lines

I also observed something interesting.
When PSCI method is set to HVC, I get a kernel panic. This wasn’t a problem in all other test cases.

Well, that's completely expected. HVC is handled by EL2. You run at EL2. You end-up calling yourself, which you don't really expect.

SMC is the way for EL2 guests, as if they were on bare-metal.

Quoted 7 lines

On a side note, thank you for giving me some pointers. With HAS_EL2_E2H the original Guest OS boots fine in nVHE.

[    0.204744] CPU: All CPU(s) started at EL2
[   18.483737] SVE: maximum available vector length 16 bytes per vector
[   18.500959] SVE: default vector length 16 bytes per vector
[   25.999475] kvm [1]: Hyp nVHE mode initialized successfully

Yup. I'll kill the ability to run VHE guests on crappy old HW then.

Thanks for giving it a go!

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#14 lore raw
Quoted 19 lines · Marc Zyngier

EXTERNAL MAIL

Quoted 10 lines · Jan Kotas
Quoted 10 lines
Quoted 4 lines

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

There are no traps for HCR_EL2.

Quoted 2 lines

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Where did you read that from?

I checked the X1 register, after: mrs x1, hcr_el2 in __check_hvhe.

That's too late. At this point, the write to HCR_EL2 will have already occurred,

I see, thanks.

Quoted 30 lines
Quoted 24 lines
Quoted 18 lines

If you apply the following change to your guest, does it start behaving?

M.

arch/arm64/include/asm/el2_setup.h +0 -0
index 46033027510cc..392c9f4016f2e 100644
@@ -34,7 +34,7 @@

mrs_s x1, SYS_ID_AA64MMFR4_EL1
sbfx x1, x1, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH cmp x1, #0
- b.ge .LnVHE_\@
+// b.ge .LnVHE_\@

Quoted 3 lines

orr x0, x0, #HCR_E2H
.LnVHE_\@:

With this change Guest OS starts the boot process.

Quoted 5 lines
[ 0.000000] CPU features: detected: Virtualization Host Extensions
[ 6.998696] SMP: Total of 4 processors activated.
[ 7.257045] CPU: All CPU(s) started at EL2
[ 185.781062] SVE: maximum available vector length 16 bytes per vector
[ 186.104159] SVE: default vector length 16 bytes per vector
Quoted 3 lines

Great. That confirms my suspicion that we cannot advertise VHE on CPUs that do not have FEAT_FGT. Oh well. I'll post a patch to forbid VHE guests on these machines.

OK. Makes sense. I’ll test the patch once it’s posted.

Quoted 18 lines
Quoted 4 lines

I also observed something interesting.
When PSCI method is set to HVC, I get a kernel panic. This wasn’t a problem in all other test cases.

Well, that's completely expected. HVC is handled by EL2. You run at EL2. You end-up calling yourself, which you don't really expect.

SMC is the way for EL2 guests, as if they were on bare-metal.

Quoted 7 lines

On a side note, thank you for giving me some pointers. With HAS_EL2_E2H the original Guest OS boots fine in nVHE.

[    0.204744] CPU: All CPU(s) started at EL2
[   18.483737] SVE: maximum available vector length 16 bytes per vector
[   18.500959] SVE: default vector length 16 bytes per vector
[   25.999475] kvm [1]: Hyp nVHE mode initialized successfully
Quoted 5 lines

Yup. I'll kill the ability to run VHE guests on crappy old HW then.

Thanks for giving it a go!

M.

Thank you for these issues!

Regards,
Jan

author maintainer
#15 lore raw
In reply to Marc Zyngier
Quoted 50 lines · Marc Zyngier
Quoted 5 lines · Jan Kotas
Quoted 5 lines
Quoted 4 lines

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

Quoted 8 lines
Quoted 6 lines

There are no traps for HCR_EL2.

Quoted 2 lines

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Where did you read that from?

I checked the X1 register, after: mrs x1, hcr_el2 in __check_hvhe.

That's too late. At this point, the write to HCR_EL2 will have already occurred,

Quoted 24 lines
Quoted 18 lines

If you apply the following change to your guest, does it start behaving?

M.

arch/arm64/include/asm/el2_setup.h +0 -0
index 46033027510cc..392c9f4016f2e 100644
@@ -34,7 +34,7 @@

mrs_s x1, SYS_ID_AA64MMFR4_EL1
sbfx x1, x1, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH cmp x1, #0
- b.ge .LnVHE_\@
+// b.ge .LnVHE_\@

Quoted 3 lines

orr x0, x0, #HCR_E2H
.LnVHE_\@:

With this change Guest OS starts the boot process.

Quoted 5 lines
[ 0.000000] CPU features: detected: Virtualization Host Extensions
[ 6.998696] SMP: Total of 4 processors activated.
[ 7.257045] CPU: All CPU(s) started at EL2
[ 185.781062] SVE: maximum available vector length 16 bytes per vector
[ 186.104159] SVE: default vector length 16 bytes per vector
Quoted 3 lines

Great. That confirms my suspicion that we cannot advertise VHE on CPUs that do not have FEAT_FGT. Oh well. I'll post a patch to forbid VHE guests on these machines.

As an alternative, and in an effort to keep at least VHE guests running on V2 (and other machines suffering from the same situation), I have posted a potential workaround at [1] for the guest to reliably detect the situation.

Could you please test it with your setup and report whether this allows you to boot a VHE guest? You will need to patch the guest.

Note that this still won't let you recursively virtualise EL2 (the HW can do it, but KVM in the guest doesn't know it), but that's better than nothing.

Thanks,

	M.

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Without deviation from the norm, progress is not possible.
#16 lore raw
Quoted 68 lines · Marc Zyngier

EXTERNAL MAIL

Quoted 50 lines · Marc Zyngier
Quoted 5 lines · Jan Kotas
Quoted 5 lines
Quoted 4 lines

Is it possible to trap/emulate HCR_EL2, and make sure E2H is always 1, in cases when only KVM_ARM_VCPU_HAS_EL2 is set?
Would that help?

Quoted 8 lines
Quoted 6 lines

There are no traps for HCR_EL2.

Quoted 2 lines

As a test, I tried forcing this bit before running VCPUs, but reading it via MRS got a value without it being set.

Where did you read that from?

I checked the X1 register, after: mrs x1, hcr_el2 in __check_hvhe.

That's too late. At this point, the write to HCR_EL2 will have already occurred,

Quoted 24 lines
Quoted 18 lines

If you apply the following change to your guest, does it start behaving?

M.

arch/arm64/include/asm/el2_setup.h +0 -0
index 46033027510cc..392c9f4016f2e 100644
@@ -34,7 +34,7 @@

mrs_s x1, SYS_ID_AA64MMFR4_EL1
sbfx x1, x1, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH cmp x1, #0
- b.ge .LnVHE_\@
+// b.ge .LnVHE_\@

Quoted 3 lines

orr x0, x0, #HCR_E2H
.LnVHE_\@:

With this change Guest OS starts the boot process.

Quoted 5 lines
[ 0.000000] CPU features: detected: Virtualization Host Extensions
[ 6.998696] SMP: Total of 4 processors activated.
[ 7.257045] CPU: All CPU(s) started at EL2
[ 185.781062] SVE: maximum available vector length 16 bytes per vector
[ 186.104159] SVE: default vector length 16 bytes per vector
Quoted 3 lines

Great. That confirms my suspicion that we cannot advertise VHE on CPUs that do not have FEAT_FGT. Oh well. I'll post a patch to forbid VHE guests on these machines.

As an alternative, and in an effort to keep at least VHE guests running on V2 (and other machines suffering from the same situation), I have posted a potential workaround at [1] for the guest to reliably detect the situation.

Quoted 6 lines

Could you please test it with your setup and report whether this allows you to boot a VHE guest? You will need to patch the guest.

Note that this still won't let you recursively virtualise EL2 (the HW can do it, but KVM in the guest doesn't know it), but that's better than nothing.

Thanks Marc,
I tried it in my Guest, on top of 6.17.0. It seems to be working.

Without HAS_EL2_E2H0:
CPU features: detected: Virtualization Host Extensions
CPU: All CPU(s) started at EL2
kvm [1]: VHE mode initialized successfully

With HAS_EL2_E2H0:
CPU: All CPU(s) started at EL2
kvm [1]: Hyp nVHE mode initialized successfully

In both cases SVE is also initialized properly.

Thanks,
Jan

Quoted 9 lines

Thanks,

M.

[1] https://urldefense.com/v3/__https://lore.kernel.org/r/[email protected]__;!!EHscmS1ygiU1lA!CSDHrEzxKt79BarWMdScZJ0yCSntOw-6rDX_3Xz6ic8fKw0huyf-Gu3y6C84cPTu-4Zu1KUk$

Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#17 lore raw
Quoted 25 lines · Jan Kotas
Quoted 8 lines · Marc Zyngier

As an alternative, and in an effort to keep at least VHE guests running on V2 (and other machines suffering from the same situation), I have posted a potential workaround at [1] for the guest to reliably detect the situation.

Quoted 6 lines

Could you please test it with your setup and report whether this allows you to boot a VHE guest? You will need to patch the guest.

Note that this still won't let you recursively virtualise EL2 (the HW can do it, but KVM in the guest doesn't know it), but that's better than nothing.

Thanks Marc,
I tried it in my Guest, on top of 6.17.0. It seems to be working.

Without HAS_EL2_E2H0:
CPU features: detected: Virtualization Host Extensions
CPU: All CPU(s) started at EL2
kvm [1]: VHE mode initialized successfully

Quoted 5 lines

With HAS_EL2_E2H0:
CPU: All CPU(s) started at EL2
kvm [1]: Hyp nVHE mode initialized successfully

In both cases SVE is also initialized properly.

Great. Would you mind replying to the patch with a Tested-by: tag?

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.