KVM: arm64: Clarify vcpu reset behaviour
Subsystems (2)
PATCH 1/1 KVM: arm64: Clarify vcpu reset behaviour
Although the KVM_ARM_VCPU_INIT documentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.
Describe this state explicitly.
--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/virt/kvm/api.rst +10 -0
@@ -3115,6 +3115,16 @@ optional features it should have. This will cause a reset of the cpu registers to their initial values. If this is not called, KVM_RUN will return ENOEXEC for that vcpu. +The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits set + * Aarch32: SVC, D, A, I and F bits set + - General Purpose registers, including PC and SP: set to 0 + - FPSIMD/NEON registers: set to 0 + - SVE registers: set to 0 + - System registers: Reset to their architecturally defined + values as for a warm reset to EL1 (resp. SVC) + Note that because some registers reflect machine topology, all vcpus should be created before this ioctl is invoked.
Signature · 7 lines
2.29.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Marc,
Quoted 5 lines · Marc Zyngier
Although the
KVM_ARM_VCPU_INITdocumentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.Describe this state explicitly.
This is a good idea.
Quoted 11 lines
Signed-off-by Marc Zyngier <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/virt/kvm/api.rst +0
-0
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3120
Quoted 6 lines
Documentation/virt/kvm/api.rst +3
-0@@ -3115,6 +3115,16 @@ optional features it should have. This will cause a reset of the cpu registers to their initial values. If this is not called, KVM_RUN will return ENOEXEC for that vcpu. +The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits set
That value matches the macro VCPU_RESET_STATE_EL1.
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3121
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ * Aarch32: SVC, D, A, I and F bits set
VCPU_RESET_STATE_SVC doesn't have a D bit; according to ARM DDI 0487G.a, page G1-5965, CPSR doesn't have a D bit either (I might be reading it wrong).
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3122
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ - General Purpose registers, including PC and SP: set to 0
They are zero'ed explicitly in kvm_reset_vcpu().
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3123
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ - FPSIMD/NEON registers: set to 0
I haven't been able to find where they are initialized explicitly, I assume they aren't. They are zero because the kvm_vcpu struct is allocated via kmem_cache_zalloc() in kvm_vm_ioctl_create_vcpu(), so this is correct.
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3124
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ - SVE registers: set to 0
They are zero'ed explicitly in kvm_vcpu_reset_sve().
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3126
Quoted 2 lines
Documentation/virt/kvm/api.rst +2
-0+ - System registers: Reset to their architecturally defined + values as for a warm reset to EL1 (resp. SVC)
This is done in kvm_reset_vcpu() -> kvm_reset_sys_regs(), which from what I can tell does the right thing, but I haven't checked each and every register.
Assuming the D bit for CPSR/SPSR was a typo and with it removed:
Thanks,
Alex
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3130
Quoted 4 lines
Documentation/virt/kvm/api.rst +1
-0+ Note that because some registers reflect machine topology, all vcpus should be created before this ioctl is invoked.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 11 lines · Alexandru Elisei
Hi Marc,
Quoted 5 lines · Marc Zyngier
Although the
KVM_ARM_VCPU_INITdocumentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.Describe this state explicitly.
This is a good idea.
Yeah, it turns out this is something we need for pKVM, because the reset state is slightly different.
Quoted 21 lines
Quoted 12 lines
Signed-off-by Marc Zyngier <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/virt/kvm/api.rst +0
-0Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3120
Quoted 6 lines
Documentation/virt/kvm/api.rst +3
-0@@ -3115,6 +3115,16 @@ optional features it should have. This will cause a reset of the cpu registers to their initial values. If this is not called, KVM_RUN will return ENOEXEC for that vcpu. +The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits setThat value matches the macro
VCPU_RESET_STATE_EL1.
Quoted 3 lines
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3121
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ * Aarch32: SVC, D, A, I and F bits set
VCPU_RESET_STATE_SVCdoesn't have a D bit; according to ARM DDI 0487G.a, page G1-5965, CPSR doesn't have a D bit either (I might be reading it wrong).
Meh, copy paste. Thanks for that,
Quoted 10 lines
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3122
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ - General Purpose registers, including PC and SP: set to 0They are zero'ed explicitly in
kvm_reset_vcpu().Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3123
Quoted 1 line
Documentation/virt/kvm/api.rst +1
-0+ - FPSIMD/NEON registers: set to 0I haven't been able to find where they are initialized explicitly, I assume they aren't. They are zero because the
kvm_vcpustruct is allocated viakmem_cache_zalloc()inkvm_vm_ioctl_create_vcpu(), so this is correct.
Indeed. However, this outlines an interesting buglet. Userspace is allowed to call KVM_ARM_VCPU_INIT at any point, and get the vcpu back to the reset state.
The lack of explicit wipeout of the FPSIMD file is on its own a bug which crept in with e47c2055c6 ("KVM: arm64: Make struct kvm_regs userspace-only"), when kvm_cpu_context started to use user_pt_regs directly.
I'll fix that separately, thanks for pushing me to have a closer look.
Quoted 12 lines
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3124
Quoted 2 lines
Documentation/virt/kvm/api.rst +1
-0+ - SVE registers: set to 0They are zero'ed explicitly in
kvm_vcpu_reset_sve().Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3126
Quoted 2 lines
Documentation/virt/kvm/api.rst +2
-0+ - System registers: Reset to their architecturally defined + values as for a warm reset to EL1 (resp. SVC)This is done in
kvm_reset_vcpu()->kvm_reset_sys_regs(), which from what I can tell does the right thing, but I haven't checked each and every register.
Quoted 3 lines
Assuming the D bit for CPSR/SPSR was a typo and with it removed:
Reviewed-by Alexandru Elisei <[email protected]>
Thanks for that. I'll send the other fix separately.
M.
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 16 lines · Marc Zyngier
Although the
KVM_ARM_VCPU_INITdocumentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.Describe this state explicitly.
Signed-off-by Marc Zyngier <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/virt/kvm/api.rst +0
-0
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3121
Quoted 7 lines
Documentation/virt/kvm/api.rst +4
-0@@ -3115,6 +3115,16 @@ optional features it should have. This will cause a reset of the cpu registers to their initial values. If this is not called, KVM_RUN will return ENOEXEC for that vcpu. +The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits set + * Aarch32: SVC, D, A, I and F bits set
nit, but capitalisation should be "AArch32"
Is "SVC" sufficient, or do we also need to describe Arm vs Thumb?
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 22 lines · Will Deacon
Quoted 21 lines · Marc Zyngier
Although the
KVM_ARM_VCPU_INITdocumentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.Describe this state explicitly.
Signed-off-by Marc Zyngier <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/virt/kvm/api.rst +0
-0@@ -3115,6 +3115,16 @@ optional features it should have. This willcause a reset of the cpu
registers to their initial values. If this is not called,KVM_RUN
will
return ENOEXEC for that vcpu.
Quoted 8 lines
Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3121
Quoted 4 lines
Documentation/virt/kvm/api.rst +4
-0+The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits set + * Aarch32: SVC, D, A, I and F bits setnit, but capitalisation should be "AArch32"
Is "SVC" sufficient, or do we also need to describe Arm vs Thumb?
SVC doesn't describe the instruction set, but we don't say that PSR.T is set, which implies ARM.
I can add something like "All other bits are set to 0", if that makes it clearer.
Thanks,
M.
Signature · 6 lines
Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
Acked-byQuoted 31 lines · Marc Zyngier
Quoted 30 lines · Will Deacon
Quoted 22 lines · Marc Zyngier
Although the
KVM_ARM_VCPU_INITdocumentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.Describe this state explicitly.
Signed-off-by Marc Zyngier <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/virt/kvm/api.rst +0
-0@@ -3115,6 +3115,16 @@ optional features it should have. This willcause a reset of the cpu
registers to their initial values. If this is not called,KVM_RUN
will
return ENOEXEC for that vcpu.Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3121
Quoted 4 lines
Documentation/virt/kvm/api.rst +4
-0+The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits set + * Aarch32: SVC, D, A, I and F bits setnit, but capitalisation should be "AArch32"
Quoted 4 lines
Quoted 1 line
Is "SVC" sufficient, or do we also need to describe Arm vs Thumb?
SVC doesn't describe the instruction set, but we don't say that PSR.T is set, which implies ARM.
Ah yes, thanks.
Quoted 2 lines
I can add something like "All other bits are set to 0", if that makes it clearer.
I think that would be worth adding. With that and the minor typo fix:
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 38 lines · Will Deacon
Quoted 31 lines · Marc Zyngier
Quoted 30 lines · Will Deacon
Quoted 22 lines · Marc Zyngier
Although the
KVM_ARM_VCPU_INITdocumentation mention that the registers are reset to their "initial values", it doesn't describe what these values are.Describe this state explicitly.
Signed-off-by Marc Zyngier <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/virt/kvm/api.rst +0
-0@@ -3115,6 +3115,16 @@ optional features it should have. This willcause a reset of the cpu
registers to their initial values. If this is not called,KVM_RUN
will
return ENOEXEC for that vcpu.Documentation/virt/kvm/api.rst optional features it should have. This will cause a reset of the cpu · line 3121
Quoted 4 lines
Documentation/virt/kvm/api.rst +4
-0+The initial values are defined as: + - Processor state: + * AArch64: EL1h, D, A, I and F bits set + * Aarch32: SVC, D, A, I and F bits setnit, but capitalisation should be "AArch32"
Quoted 4 lines
Quoted 1 line
Is "SVC" sufficient, or do we also need to describe Arm vs Thumb?
SVC doesn't describe the instruction set, but we don't say that PSR.T is set, which implies ARM.
Quoted 8 lines
Ah yes, thanks.
Quoted 2 lines
I can add something like "All other bits are set to 0", if that makes it clearer.
I think that would be worth adding. With that and the minor typo fix:
Acked-by Will Deacon <[email protected]>
Now fixed.
Thanks,
M.
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel