x86: kvm: reset the bootstrap processor when it gets an INIT
Paolo Bonzini
maintainerPATCH 1/1 x86: kvm: reset the bootstrap processor when it gets an INIT
After receiving an INIT signal (either via the local APIC, or through KVM_SET_MP_STATE), the bootstrap processor should reset immediately and start execution at 0xfffffff0. Also, SIPIs have no effect on the bootstrap processor. However, KVM currently does not differentiate between the BSP and APs.
Implement this so that userspace can correctly implement CPU soft resets even when the in-kernel APIC is in use. Another small change is needed, because INITs sent to the bootstrap processor do not go through a halt state; it is incorrect to go through kvm_vcpu_block. I think this also fixes a race before between sending the INIT and SIPI interrupts; if the two were close enough, the receiving VCPU could have received the SIPI before entering kvm_vcpu_block. It would them stay in kvm_vcpu_block until the next kvm_vcpu_kick. In practice this was not a problem, because the Intel SDM suggests to send two SIPIs with some time passing between them; the second SIPI would unblock the VCPU.
The tests in vcpu_needs_reset are organized so that the hypervisor will go through the same number of compare-and-jump sequences as before in the common case.
--- arch/x86/kvm/lapic.c | 3 ++- arch/x86/kvm/x86.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)
arch/x86/kvm/lapic.c +2 -1
@@ -710,7 +710,8 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,case APIC_DM_STARTUP :apic_debug ("SIPI to vcpu %d vector 0x%02x\n" , vcpu->vcpu_id, vector); -if (vcpu->arch.mp_state ==KVM_MP_STATE_INIT_RECEIVED ) { +if (!kvm_vcpu_is_bsp (apic->vcpu) && + vcpu->arch.mp_state ==KVM_MP_STATE_INIT_RECEIVED ) { result =1 ; vcpu->arch.sipi_vector = vector; vcpu->arch.mp_state =KVM_MP_STATE_SIPI_RECEIVED ;
arch/x86/kvm/x86.c +19 -4
@@ -5784,15 +5784,29 @@ out:return r; } +static inline int vcpu_needs_reset (struct kvm_vcpu *vcpu) +{ +/* Shortcut the test in the common case. */ +if (likely (vcpu->arch.mp_state ==KVM_MP_STATE_RUNNABLE )) +return 0 ; + +if (kvm_vcpu_is_bsp (vcpu)) +return vcpu->arch.mp_state ==KVM_MP_STATE_INIT_RECEIVED ; +else +return vcpu->arch.mp_state ==KVM_MP_STATE_SIPI_RECEIVED ; +}static int __vcpu_run (struct kvm_vcpu *vcpu) {int r;struct kvm *kvm = vcpu->kvm; -if (unlikely (vcpu->arch.mp_state ==KVM_MP_STATE_SIPI_RECEIVED )) { -pr_debug ("vcpu %d received sipi with vector # %x\n" , - vcpu->vcpu_id, vcpu->arch.sipi_vector); +if (unlikely (vcpu_needs_reset (vcpu))) { +if (kvm_vcpu_is_bsp (vcpu)) +pr_debug ("vcpu %d received init\n" , vcpu->vcpu_id); +else +pr_debug ("vcpu %d received sipi with vector # %x\n" , + vcpu->vcpu_id, vcpu->arch.sipi_vector);kvm_lapic_reset (vcpu); r =kvm_vcpu_reset (vcpu);if (r)
@@ -5812,6 +5826,8 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)if (vcpu->arch.mp_state ==KVM_MP_STATE_RUNNABLE && !vcpu->arch.apf.halted) r =vcpu_enter_guest (vcpu); +else if (unlikely (vcpu_needs_reset (vcpu))) + r = -EINTR ;else {srcu_read_unlock (&kvm->srcu, vcpu->srcu_idx);kvm_vcpu_block (vcpu);
@@ -5825,7 +5841,6 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)case KVM_MP_STATE_RUNNABLE : vcpu->arch.apf.halted = false;break ; -case KVM_MP_STATE_SIPI_RECEIVED :default : r = -EINTR ;break ;
Signature · 1 line
1.8.1.4
Quoted 6 lines · Paolo Bonzini
After receiving an INIT signal (either via the local APIC, or through
KVM_SET_MP_STATE), the bootstrap processor should reset immediately and start execution at0xfffffff0. Also, SIPIs have no effect on the bootstrap processor. However, KVM currently does not differentiate between the BSP and APs.
Userspace is capable of resetting vcpu by itself, so adding code to handle KVM_SET_MP_STATE(INIT) looks unnecessary to me. I think the simple patch below (not tested) should handle INIT for in-kernel irq chip and userspace does not need special handling for cpu reset. It already knows how to reset cpu on system_reset, so reseting only cpus should not be different.
arch/x86/kvm/lapic.c +3 -1
@@ -731,7 +731,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,case APIC_DM_INIT :if (!trig_mode || level) { result =1 ; - vcpu->arch.mp_state =KVM_MP_STATE_INIT_RECEIVED ; + vcpu->arch.mp_state =kvm_vcpu_is_bsp (vcpu) ? +KVM_MP_STATE_SIPI_RECEIVED : +KVM_MP_STATE_INIT_RECEIVED ;kvm_make_request (KVM_REQ_EVENT , vcpu);kvm_vcpu_kick (vcpu); }else {
--
Gleb.
Paolo Bonzini
maintainerIl 10/03/2013 12:46, Gleb Natapov ha scritto:
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines
After receiving an INIT signal (either via the local APIC, or through
KVM_SET_MP_STATE), the bootstrap processor should reset immediately and start execution at0xfffffff0. Also, SIPIs have no effect on the bootstrap processor. However, KVM currently does not differentiate between the BSP and APs.
Quoted 6 lines
Userspace is capable of resetting vcpu by itself, so adding code to handle
KVM_SET_MP_STATE(INIT)looks unnecessary to me. I think the simple patch below (not tested) should handle INIT for in-kernel irq chip and userspace does not need special handling for cpu reset. It already knows how to reset cpu onsystem_reset, so reseting only cpus should not be different.
At least you'll need the last two hunks, moving the check for KVM_MP_STATE_SIPI_RECEIVED before kvm_vcpu_block, but yes---something like this could work.
However, it would effectively redefine the meaning of KVM_MP_STATE_INIT_RECEIVED and KVM_MP_STATE_SIPI_RECEIVED, respectively to KVM_MP_STATE_WAIT_FOR_SIPI and KVM_MP_STATE_RESETTING. I wasn't sure if this is considered an API change (personally, I would treat it as one).
Paolo
Quoted 19 lines
arch/x86/kvm/lapic.c +3
-2@@ -731,7 +731,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,case APIC_DM_INIT :if (!trig_mode || level) { result =1 ; - vcpu->arch.mp_state =KVM_MP_STATE_INIT_RECEIVED ; + vcpu->arch.mp_state =kvm_vcpu_is_bsp (vcpu) ? +KVM_MP_STATE_SIPI_RECEIVED : +KVM_MP_STATE_INIT_RECEIVED ;kvm_make_request (KVM_REQ_EVENT , vcpu);kvm_vcpu_kick (vcpu); }else { --Gleb.
Quoted 15 lines · Paolo Bonzini
Il 10/03/2013 12:46, Gleb Natapov ha scritto:
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines
After receiving an INIT signal (either via the local APIC, or through
KVM_SET_MP_STATE), the bootstrap processor should reset immediately and start execution at0xfffffff0. Also, SIPIs have no effect on the bootstrap processor. However, KVM currently does not differentiate between the BSP and APs.Quoted 6 lines
Userspace is capable of resetting vcpu by itself, so adding code to handle
KVM_SET_MP_STATE(INIT)looks unnecessary to me. I think the simple patch below (not tested) should handle INIT for in-kernel irq chip and userspace does not need special handling for cpu reset. It already knows how to reset cpu onsystem_reset, so reseting only cpus should not be different.
Quoted 4 lines
At least you'll need the last two hunks, moving the check for
KVM_MP_STATE_SIPI_RECEIVEDbeforekvm_vcpu_block, but yes---something like this could work.
I do not see why. kvm_vcpu_block() exits if vpu is in KVM_MP_STATE_SIPI_RECEIVED state.
Quoted 5 lines
However, it would effectively redefine the meaning of
KVM_MP_STATE_INIT_RECEIVEDandKVM_MP_STATE_SIPI_RECEIVED, respectively toKVM_MP_STATE_WAIT_FOR_SIPIandKVM_MP_STATE_RESETTING. I wasn't sure if this is considered an API change (personally, I would treat it as one).
If it is kernel module internal it definitely is not API change. INIT/SIPI handling is a bit ad-hoc right now anyway as Jan noticed. For instance INIT does not really resets VCPU. Only after SIPI it is really reset, so KVM_MP_STATE_SIPI_RECEIVED is really KVM_MP_STATE_RESET_ME_RIGHT_NOW state.
--
Gleb.
Paolo Bonzini
maintainerIl 10/03/2013 16:35, Gleb Natapov ha scritto:
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
However, it would effectively redefine the meaning of
KVM_MP_STATE_INIT_RECEIVEDandKVM_MP_STATE_SIPI_RECEIVED, respectively toKVM_MP_STATE_WAIT_FOR_SIPIandKVM_MP_STATE_RESETTING. I wasn't sure if this is considered an API change (personally, I would treat it as one).If it is kernel module internal it definitely is not API change. INIT/SIPI handling is a bit ad-hoc right now anyway as Jan noticed. For instance INIT does not really resets VCPU. Only after SIPI it is really reset, so
KVM_MP_STATE_SIPI_RECEIVEDis reallyKVM_MP_STATE_RESET_ME_RIGHT_NOWstate.
Yeah, and the current definition is ambiguous (without hypervisor patches, there's no way to use it as the names would suggest), so perhaps the right thing to do is to rename the states (old names kept for backwards compatibility only) and work from there.
Paolo
Quoted 12 lines · Paolo Bonzini
Il 10/03/2013 16:35, Gleb Natapov ha scritto:
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
However, it would effectively redefine the meaning of
KVM_MP_STATE_INIT_RECEIVEDandKVM_MP_STATE_SIPI_RECEIVED, respectively toKVM_MP_STATE_WAIT_FOR_SIPIandKVM_MP_STATE_RESETTING. I wasn't sure if this is considered an API change (personally, I would treat it as one).If it is kernel module internal it definitely is not API change. INIT/SIPI handling is a bit ad-hoc right now anyway as Jan noticed. For instance INIT does not really resets VCPU. Only after SIPI it is really reset, so
KVM_MP_STATE_SIPI_RECEIVEDis reallyKVM_MP_STATE_RESET_ME_RIGHT_NOWstate.
Quoted 5 lines
Yeah, and the current definition is ambiguous (without hypervisor patches, there's no way to use it as the names would suggest), so perhaps the right thing to do is to rename the states (old names kept for backwards compatibility only) and work from there.
I do not see how renaming clarify things. From userspace point of view KVM_MP_STATE_SIPI_RECEIVED does not exists. If AP is hard reset userspase makes it UNINIT, if soft reset it makes it INIT_RECEIVED, if BSP it makes it running no matter what type of reset.
--
Gleb.
Paolo Bonzini
maintainerIl 10/03/2013 19:10, Gleb Natapov ha scritto:
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines
Il 10/03/2013 16:35, Gleb Natapov ha scritto:
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
However, it would effectively redefine the meaning of
KVM_MP_STATE_INIT_RECEIVEDandKVM_MP_STATE_SIPI_RECEIVED, respectively toKVM_MP_STATE_WAIT_FOR_SIPIandKVM_MP_STATE_RESETTING. I wasn't sure if this is considered an API change (personally, I would treat it as one).If it is kernel module internal it definitely is not API change. INIT/SIPI handling is a bit ad-hoc right now anyway as Jan noticed. For instance INIT does not really resets VCPU. Only after SIPI it is really reset, so
KVM_MP_STATE_SIPI_RECEIVEDis reallyKVM_MP_STATE_RESET_ME_RIGHT_NOWstate.
Quoted 7 lines
Quoted 5 lines
Yeah, and the current definition is ambiguous (without hypervisor patches, there's no way to use it as the names would suggest), so perhaps the right thing to do is to rename the states (old names kept for backwards compatibility only) and work from there.
I do not see how renaming clarify things. From userspace point of view
KVM_MP_STATE_SIPI_RECEIVEDdoes not exists.
Not really true---we do exit with that state and EINTR when we get a SIPI. Perhaps that can be changed.
Quoted 3 lines
If AP is hard reset
userspase makes it UNINIT, if soft reset it makes itINIT_RECEIVED, if BSP it makes it running no matter what type of reset.
The current name just suggests .
And when getting an INIT in the in-kernel LAPIC, this:
- vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED;
+ vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ?
+ KVM_MP_STATE_SIPI_RECEIVED :
+ KVM_MP_STATE_INIT_RECEIVED;
makes much less sense than this:
- vcpu->arch.mp_state = KVM_MP_STATE_WAIT_FOR_SIPI;
+ vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ?
+ KVM_MP_STATE_RESET_NOW :
+ KVM_MP_STATE_WAIT_FOR_SIPI;
However, there's also Jan's plans for nVMX. Peeking at his queue (see
http://git.kiszka.org/?p=linux-kvm.git;a=commitdiff;h=037fb24ec) I think it's better to always reflect INITs to the hypervisor like I did in these patches.
Paolo
Quoted 19 lines · Paolo Bonzini
Il 10/03/2013 19:10, Gleb Natapov ha scritto:
Quoted 18 lines · Paolo Bonzini
Quoted 17 lines
Il 10/03/2013 16:35, Gleb Natapov ha scritto:
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
However, it would effectively redefine the meaning of
KVM_MP_STATE_INIT_RECEIVEDandKVM_MP_STATE_SIPI_RECEIVED, respectively toKVM_MP_STATE_WAIT_FOR_SIPIandKVM_MP_STATE_RESETTING. I wasn't sure if this is considered an API change (personally, I would treat it as one).If it is kernel module internal it definitely is not API change. INIT/SIPI handling is a bit ad-hoc right now anyway as Jan noticed. For instance INIT does not really resets VCPU. Only after SIPI it is really reset, so
KVM_MP_STATE_SIPI_RECEIVEDis reallyKVM_MP_STATE_RESET_ME_RIGHT_NOWstate.Yeah, and the current definition is ambiguous (without hypervisor patches, there's no way to use it as the names would suggest), so perhaps the right thing to do is to rename the states (old names kept for backwards compatibility only) and work from there.
Quoted 6 lines
Quoted 2 lines
I do not see how renaming clarify things. From userspace point of view
KVM_MP_STATE_SIPI_RECEIVEDdoes not exists.Not really true---we do exit with that state and EINTR when we get a SIPI. Perhaps that can be changed.
That's implementation detail. We can jump to the beginning of the function instead. Nowhere we document that entering KVM_MP_STATE_SIPI_RECEIVED state cause KVM_RUN return with EINTR.
Quoted 15 lines
Quoted 3 lines
If AP is hard reset
userspase makes it UNINIT, if soft reset it makes itINIT_RECEIVED, if BSP it makes it running no matter what type of reset.The current name just suggests .
And when getting an INIT in the in-kernel LAPIC, this:arch/x86/kvm/lapic.c +3
-1- vcpu->arch.mp_state =KVM_MP_STATE_INIT_RECEIVED ; + vcpu->arch.mp_state =kvm_vcpu_is_bsp (vcpu) ? +KVM_MP_STATE_SIPI_RECEIVED : +KVM_MP_STATE_INIT_RECEIVED ;makes much less sense than this:
Review
Quoted 4 lines
(quoted diff) +3
-1- vcpu->arch.mp_state = KVM_MP_STATE_WAIT_FOR_SIPI; + vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ? + KVM_MP_STATE_RESET_NOW : + KVM_MP_STATE_WAIT_FOR_SIPI;
Both of them are equally incorrect. INIT should cause reset, and only if vmx is off. An userspace reset is also completely broken in that regard. Renaming things gives us nothing, only bring unneeded churn. If the names were internal I wouldn't mind, but they are APIs.
Quoted 5 lines
However, there's also Jan's plans for nVMX. Peeking at his queue (see
http://git.kiszka.org/?p=linux-kvm.git;a=commitdiff;h=037fb24ec) I think it's better to always reflect INITs to the hypervisor like I did in these patches.
The commit was before we decided that we should not abuse mp_state for signaling.
--
Gleb.
Paolo Bonzini
maintainerIl 11/03/2013 11:28, Gleb Natapov ha scritto:
Quoted 6 lines
Quoted 2 lines
Not really true---we do exit with that state and EINTR when we get a SIPI. Perhaps that can be changed.
That's implementation detail. We can jump to the beginning of the function instead. Nowhere we document that entering
KVM_MP_STATE_SIPI_RECEIVEDstate causeKVM_RUNreturn with EINTR.
Yes, that would be nice.
Quoted 24 lines
Quoted 15 lines
Quoted 3 lines
If AP is hard reset
userspase makes it UNINIT, if soft reset it makes itINIT_RECEIVED, if BSP it makes it running no matter what type of reset.The current name just suggests .
And when getting an INIT in the in-kernel LAPIC, this:(quoted diff) +3
-1- vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; + vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ? + KVM_MP_STATE_SIPI_RECEIVED : + KVM_MP_STATE_INIT_RECEIVED;makes much less sense than this:
Review
Quoted 4 lines
(quoted diff) +3
-1- vcpu->arch.mp_state = KVM_MP_STATE_WAIT_FOR_SIPI; + vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ? + KVM_MP_STATE_RESET_NOW : + KVM_MP_STATE_WAIT_FOR_SIPI;Both of them are equally incorrect. INIT should cause reset, and only if vmx is off. An userspace reset is also completely broken in that regard. Renaming things gives us nothing, only bring unneeded churn. If the names were internal I wouldn't mind, but they are APIs.
Quoted 7 lines
Quoted 5 lines
However, there's also Jan's plans for nVMX. Peeking at his queue (see
http://git.kiszka.org/?p=linux-kvm.git;a=commitdiff;h=037fb24ec) I think it's better to always reflect INITs to the hypervisor like I did in these patches.The commit was before we decided that we should not abuse
mp_statefor signaling.
Agreed, but we still have the problem of how to signal from userspace. For that do you have any other suggestion than mp_state? And if we keep mp_state to signal from userspace, giving INIT_RECEIVED the "wait-for-SIPI" semantics would be wrong.
Paolo
Quoted 10 lines · Paolo Bonzini
Il 11/03/2013 11:28, Gleb Natapov ha scritto:
Quoted 6 lines
Quoted 2 lines
Not really true---we do exit with that state and EINTR when we get a SIPI. Perhaps that can be changed.
That's implementation detail. We can jump to the beginning of the function instead. Nowhere we document that entering
KVM_MP_STATE_SIPI_RECEIVEDstate causeKVM_RUNreturn with EINTR.Yes, that would be nice.
That's not performance critical path, so I guess no one bothered.
Quoted 29 lines
Quoted 29 lines
Quoted 15 lines
Quoted 3 lines
If AP is hard reset
userspase makes it UNINIT, if soft reset it makes itINIT_RECEIVED, if BSP it makes it running no matter what type of reset.The current name just suggests .
And when getting an INIT in the in-kernel LAPIC, this:(quoted diff) +3
-1- vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; + vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ? + KVM_MP_STATE_SIPI_RECEIVED : + KVM_MP_STATE_INIT_RECEIVED;makes much less sense than this:
Review
Quoted 4 lines
(quoted diff) +3
-1- vcpu->arch.mp_state = KVM_MP_STATE_WAIT_FOR_SIPI; + vcpu->arch.mp_state = kvm_vcpu_is_bsp(vcpu) ? + KVM_MP_STATE_RESET_NOW : + KVM_MP_STATE_WAIT_FOR_SIPI;Both of them are equally incorrect. INIT should cause reset, and only if vmx is off. An userspace reset is also completely broken in that regard. Renaming things gives us nothing, only bring unneeded churn. If the names were internal I wouldn't mind, but they are APIs.
Quoted 5 lines
However, there's also Jan's plans for nVMX. Peeking at his queue (see
http://git.kiszka.org/?p=linux-kvm.git;a=commitdiff;h=037fb24ec) I think it's better to always reflect INITs to the hypervisor like I did in these patches.
Quoted 8 lines
Quoted 2 lines
The commit was before we decided that we should not abuse
mp_statefor signaling.Agreed, but we still have the problem of how to signal from userspace. For that do you have any other suggestion than
mp_state? And if we keepmp_stateto signal from userspace, givingINIT_RECEIVEDthe "wait-for-SIPI" semantics would be wrong.
I don't see how can we use mp_state for signaling from userspace either. Currently soft reset always reset vcpus, so it is OK for userspace to generate reset vcpu state and put it into kernel, mp_state is just one of the updated states, but when INIT will be just another signal that may or may not reset cpu or have other side effects like #vmexit this will not longer work. We will have to have another interface for injecting INIT from userspace and userspace soft-reset will use it instead of doing reset by itself.
--
Gleb.
Paolo Bonzini
maintainerIl 11/03/2013 12:51, Gleb Natapov ha scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Agreed, but we still have the problem of how to signal from userspace. For that do you have any other suggestion than
mp_state? And if we keepmp_stateto signal from userspace, givingINIT_RECEIVEDthe "wait-for-SIPI" semantics would be wrong.
Quoted 8 lines
I don't see how can we use
mp_statefor signaling from userspace either. Currently soft reset always reset vcpus, so it is OK for userspace to generate reset vcpu state and put it into kernel,mp_stateis just one of the updated states, but when INIT will be just another signal that may or may not reset cpu or have other side effects like #vmexit this will not longer work. We will have to have another interface for injecting INIT from userspace and userspace soft-reset will use it instead of doing reset by itself.
Setting the mp_state to INIT_RECEIVED is that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
If we move away from the INIT_RECEIVED and SIPI_RECEIVED states for in-kernel APIC -> VCPU communication, then the KVM_SET_MP_STATE ioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away from mp_state.
Paolo
Quoted 16 lines · Paolo Bonzini
Il 11/03/2013 12:51, Gleb Natapov ha scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Agreed, but we still have the problem of how to signal from userspace. For that do you have any other suggestion than
mp_state? And if we keepmp_stateto signal from userspace, givingINIT_RECEIVEDthe "wait-for-SIPI" semantics would be wrong.Quoted 8 lines
I don't see how can we use
mp_statefor signaling from userspace either. Currently soft reset always reset vcpus, so it is OK for userspace to generate reset vcpu state and put it into kernel,mp_stateis just one of the updated states, but when INIT will be just another signal that may or may not reset cpu or have other side effects like #vmexit this will not longer work. We will have to have another interface for injecting INIT from userspace and userspace soft-reset will use it instead of doing reset by itself.
Quoted 3 lines
Setting the
mp_statetoINIT_RECEIVEDis that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.
It does not for AP either. If AP has vmx on mp_sate should not be set to INIT_RECEIVED. mp_sate is a state as you can see from its name and we already had a discussion on the generic device API about importance of separating sending commands from setting state. There is a difference between setting mp_sate during migration and signaling INIT#.
Quoted 5 lines
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
We are discussing two different things here. I'll try to separate them.
1. BSP is broken WRT #INIT
2. nested is broken WRT #INIT
You are fixing 1 with your patches, for that I proposed much easier solution (at last from kernel point of view): if BSP reset it in userspace and make it runnable. Nested virt is still broken, but this is not what you are fixing.
For 2 much more involved fix is needed. Jan fixes it and it will require signaling INIT# from userspace by other means than mp_sate because signaling INIT# does not automatically means that mp_sate changes to INIT_RECEIVED.
Quoted 7 lines
If we move away from the
INIT_RECEIVEDandSIPI_RECEIVEDstates for in-kernel APIC -> VCPU communication, then theKVM_SET_MP_STATEioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away frommp_state.
We are not moving away from mp_state, we are moving away from using mp_state for signaling because with nested virt INIT does not always change mp_state, not only that it can change mp_state long after signal is received after vmx off is done.
--
Gleb.
Quoted 52 lines · Gleb Natapov
Quoted 16 lines · Paolo Bonzini
Il 11/03/2013 12:51, Gleb Natapov ha scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Agreed, but we still have the problem of how to signal from userspace. For that do you have any other suggestion than
mp_state? And if we keepmp_stateto signal from userspace, givingINIT_RECEIVEDthe "wait-for-SIPI" semantics would be wrong.Quoted 8 lines
I don't see how can we use
mp_statefor signaling from userspace either. Currently soft reset always reset vcpus, so it is OK for userspace to generate reset vcpu state and put it into kernel,mp_stateis just one of the updated states, but when INIT will be just another signal that may or may not reset cpu or have other side effects like #vmexit this will not longer work. We will have to have another interface for injecting INIT from userspace and userspace soft-reset will use it instead of doing reset by itself.Quoted 3 lines
Setting the
mp_statetoINIT_RECEIVEDis that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.It does not for AP either. If AP has vmx on
mp_sateshould not be set toINIT_RECEIVED.mp_sateis a state as you can see from its name and we already had a discussion on the generic device API about importance of separating sending commands from setting state. There is a difference between settingmp_sateduring migration and signaling INIT#.Quoted 5 lines
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
We are discussing two different things here. I'll try to separate them.
1. BSP is broken WRT #INIT
2. nested is broken WRT #INITYou are fixing 1 with your patches, for that I proposed much easier solution (at last from kernel point of view): if BSP reset it in userspace and make it runnable. Nested virt is still broken, but this is not what you are fixing.
For 2 much more involved fix is needed. Jan fixes it and it will require signaling INIT# from userspace by other means than
mp_satebecause signaling INIT# does not automatically means thatmp_satechanges toINIT_RECEIVED.Quoted 7 lines
If we move away from the
INIT_RECEIVEDandSIPI_RECEIVEDstates for in-kernel APIC -> VCPU communication, then theKVM_SET_MP_STATEioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away frommp_state.
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.
Right.
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 5 lines · Jan Kiszka
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.
Quoted 8 lines
Right.
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
--
Gleb.
Quoted 8 lines · Gleb Natapov
Quoted 7 lines · Jan Kiszka
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Why shouldn't it? Besides edge, there is also level-triggered INIT.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Gleb Natapov
Quoted 13 lines · Jan Kiszka
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
Quoted 5 lines
Quoted 2 lines
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Why shouldn't it? Besides edge, there is also level-triggered INIT.
OK, so level-triggered INIT can be de-asserted what about edge triggered one? :)
--
Gleb.
Quoted 16 lines · Gleb Natapov
Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Gleb Natapov
Quoted 13 lines · Jan Kiszka
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Why shouldn't it? Besides edge, there is also level-triggered INIT.
OK, so level-triggered INIT can be de-asserted what about edge triggered one? :)
It should be lost while in root mode.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Gleb Natapov
Quoted 18 lines · Jan Kiszka
Quoted 16 lines · Gleb Natapov
Quoted 5 lines · Jan Kiszka
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Quoted 8 lines
Right.
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Why shouldn't it? Besides edge, there is also level-triggered INIT.
OK, so level-triggered INIT can be de-asserted what about edge triggered one? :)
It should be lost while in root mode.
Ah, that's great. Removes some potential complications.
--
Gleb.
Quoted 21 lines · Gleb Natapov
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Gleb Natapov
Quoted 18 lines · Jan Kiszka
Quoted 16 lines · Gleb Natapov
Quoted 5 lines · Jan Kiszka
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Quoted 8 lines
Right.
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Why shouldn't it? Besides edge, there is also level-triggered INIT.
OK, so level-triggered INIT can be de-asserted what about edge triggered one? :)
It should be lost while in root mode.
Ah, that's great. Removes some potential complications.
Again, that's my interpretation. I didn't check this against real HW yet. It just makes most sense, given what I read.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Paolo Bonzini
maintainerIl 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Paolo
Paolo Bonzini
maintainerIl 11/03/2013 14:54, Gleb Natapov ha scritto:
Quoted 8 lines
Quoted 2 lines
Setting the
mp_statetoINIT_RECEIVEDis that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.It does not for AP either. If AP has vmx on
mp_sateshould not be set toINIT_RECEIVED.mp_sateis a state as you can see from its name and we already had a discussion on the generic device API about importance of separating sending commands from setting state. There is a difference between settingmp_stateduring migration and signaling INIT#.
What does migration have to do with this?
Quoted 5 lines
Quoted 5 lines
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
Quoted 8 lines
We are discussing two different things here. I'll try to separate them.
1. BSP is broken WRT #INIT
2. nested is broken WRT #INITYou are fixing 1 with your patches, for that I proposed much easier solution (at last from kernel point of view): if BSP reset it in userspace and make it runnable. Nested virt is still broken, but this is not what you are fixing.
It's not what I'm fixing, but I don't want to make the fix for nested virt unnecessarily more complicated. Nested virt needs to know about INIT and SIPI; redefining the meaning of INIT_RECEIVED and SIPI_RECEIVED makes it more complicated to reflect these events to L1.
Quoted 4 lines
For 2 much more involved fix is needed. Jan fixes it and it will require signaling INIT# from userspace by other means than
mp_satebecause signaling INIT# does not automatically means thatmp_satechanges toINIT_RECEIVED.
In your interpretation of INIT_RECEIVED, no. In mine, yes...
Quoted 8 lines
Quoted 6 lines
If we move away from the
INIT_RECEIVEDandSIPI_RECEIVEDstates for in-kernel APIC -> VCPU communication, then theKVM_SET_MP_STATEioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away frommp_state.We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling
That's what I meant; sorry for the unclear abbreviation.
Quoted 2 lines
because with nested virt INIT does not always
changemp_state
Why not? It does change mp_state, it changes how you react to the change. Which is why it's good to have the reset done in kernel space, not in user space.
Paolo
Quoted 6 lines
, not only that it can change
mp_statelong after signal is received after vmx off is done.--
Gleb.
Quoted 25 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
Quoted 7 lines
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 4 lines · Paolo Bonzini
Il 11/03/2013 14:54, Gleb Natapov ha scritto:
Quoted 3 lines
Quoted 2 lines
Setting the
mp_statetoINIT_RECEIVEDis that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.
Quoted 8 lines
Quoted 5 lines
It does not for AP either. If AP has vmx on
mp_sateshould not be set toINIT_RECEIVED.mp_sateis a state as you can see from its name and we already had a discussion on the generic device API about importance of separating sending commands from setting state. There is a difference between settingmp_stateduring migration and signaling INIT#.What does migration have to do with this?
get|set_mpstate is used by migration. Actually this is primary reason for this interface existence.
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
We are discussing two different things here. I'll try to separate them.
1. BSP is broken WRT #INIT
2. nested is broken WRT #INIT
Quoted 6 lines
Quoted 4 lines
You are fixing 1 with your patches, for that I proposed much easier solution (at last from kernel point of view): if BSP reset it in userspace and make it runnable. Nested virt is still broken, but this is not what you are fixing.
It's not what I'm fixing, but I don't want to make the fix for nested
What are you fixing then?
Quoted 11 lines
virt unnecessarily more complicated. Nested virt needs to know about INIT and SIPI; redefining the meaning of
INIT_RECEIVEDandSIPI_RECEIVEDmakes it more complicated to reflect these events to L1.Quoted 4 lines
For 2 much more involved fix is needed. Jan fixes it and it will require signaling INIT# from userspace by other means than
mp_satebecause signaling INIT# does not automatically means thatmp_satechanges toINIT_RECEIVED.In your interpretation of
INIT_RECEIVED, no. In mine, yes...
Your code shows different. With your patch setting mp_state to INIT_RECEIVED makes vcpu non tunable. This is incorrect if INIT_RECEIVED is "INIT# is triggered" interface.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
If we move away from the
INIT_RECEIVEDandSIPI_RECEIVEDstates for in-kernel APIC -> VCPU communication, then theKVM_SET_MP_STATEioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away frommp_state.We are not moving away from
mp_state, we are moving away from usingmp_statefor signalingThat's what I meant; sorry for the unclear abbreviation.
Then we disagree.
Quoted 5 lines
Quoted 3 lines
because with nested virt INIT does not always
changemp_stateWhy not?
Because mp_state is the current state the vcpu is in. It can be uninitialized, runnable, halted or wait for sipi. SDM says that if nested virt is enabled vcpu does not enter wait for sipi state on INIT#.
Quoted 2 lines
It does change
mp_state, it changes how you react to the
change.
How does it? CPU was runnable before it is still runnable after.
Quoted 3 lines
Which is why it's good to have the reset done in kernel space,
not in user space.
Without nested virt it does not really matter and if it is does not really matter you do not add code to the kernel just because it is good. With nested virt INIT# processing needs to go to the kernel. In some cases INIT will cause reset, but you do not "do reset in kernel space", you do "INIT# handling in kernel space".
--
Gleb.
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
Quoted 7 lines
Quoted 3 lines
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
--
Gleb.
Quoted 31 lines · Gleb Natapov
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
It has to. Otherwise, it would hit the host on vmxoff.
The spec says: "The INIT signal is blocked whenever a logical processor is in VMX root operation. It is not blocked in VMX non-root operation. Instead, INITs cause VM exits [...]."
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Gleb Natapov
Quoted 37 lines · Jan Kiszka
Quoted 25 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
Quoted 7 lines
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
Quoted 7 lines
Quoted 1 line
vmexit clears it?
It has to. Otherwise, it would hit the host on vmxoff.
The spec says: "The INIT signal is blocked whenever a logical processor is in VMX root operation. It is not blocked in VMX non-root operation. Instead, INITs cause VM exits [...]."
BTW, we have a similar behaviour with SVM, just that GIF and the INIT interception flags controls the processing: When in guest mode and interception is enabled, INIT causes vmexit. When in host mode and GIF is 0, INIT is blocked and held pending until reaching guest mode again or switching on GIF explicitly.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Paolo Bonzini
maintainerIl 11/03/2013 18:20, Gleb Natapov ha scritto:
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines
Il 11/03/2013 14:54, Gleb Natapov ha scritto:
Quoted 8 lines
Quoted 2 lines
Setting the
mp_statetoINIT_RECEIVEDis that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.It does not for AP either. If AP has vmx on
mp_sateshould not be set toINIT_RECEIVED.mp_sateis a state as you can see from its name and we already had a discussion on the generic device API about importance of separating sending commands from setting state. There is a difference between settingmp_stateduring migration and signaling INIT#.
Quoted 4 lines
Quoted 1 line
What does migration have to do with this?
get|set_mpstate is used by migration. Actually this is primary reason for this interface existence.
Does it have to be the only one?
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
We are discussing two different things here. I'll try to separate them.
1. BSP is broken WRT #INIT
2. nested is broken WRT #INIT
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
You are fixing 1 with your patches, for that I proposed much easier solution (at last from kernel point of view): if BSP reset it in userspace and make it runnable. Nested virt is still broken, but this is not what you are fixing.
It's not what I'm fixing, but I don't want to make the fix for nested
What are you fixing then?
Nested virt is not what I am fixing, but I'm trying to keep an eye on that (and the other INIT race) while doing these patches.
Quoted 9 lines
Quoted 9 lines
virt unnecessarily more complicated. Nested virt needs to know about INIT and SIPI; redefining the meaning of
INIT_RECEIVEDandSIPI_RECEIVEDmakes it more complicated to reflect these events to L1.Quoted 4 lines
For 2 much more involved fix is needed. Jan fixes it and it will require signaling INIT# from userspace by other means than
mp_satebecause signaling INIT# does not automatically means thatmp_satechanges toINIT_RECEIVED.
Quoted 5 lines
Quoted 1 line
In your interpretation of
INIT_RECEIVED, no. In mine, yes...Your code shows different. With your patch setting
mp_statetoINIT_RECEIVEDmakes vcpu non tunable. This is incorrect ifINIT_RECEIVEDis "INIT# is triggered" interface.
What do you mean by "non tunable"? In non-nested mode, the VCPU will reset immediately, as soon as it is re-entered. In nested mode, the VCPU will eat the INIT_RECEIVED and turn it into a vmexit.
At least according to AMD's docs, the VMM has to reassert INIT if it wants the processor to actually process it [15.20.8 INIT support]. Intel's does not say it explicitly, but it doesn't say the opposite either. It seems to be the only that makes sense.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
If we move away from the
INIT_RECEIVEDandSIPI_RECEIVEDstates for in-kernel APIC -> VCPU communication, then theKVM_SET_MP_STATEioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away frommp_state.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signalingThat's what I meant; sorry for the unclear abbreviation.
Then we disagree.
We do. Let's see _where_ exactly we disagree.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
because with nested virt INIT does not always
changemp_stateWhy not?
Because
mp_stateis the current state the vcpu is in. It can be uninitialized, runnable, halted or wait for sipi. SDM says that if nested virt is enabled vcpu does not enter wait for sipi state on INIT#.
Yes, but it still has to do something (a vmexit) and go back to RUNNING.
So it needs signaling from userspace to the kernel.
Quoted 8 lines
Quoted 2 lines
Which is why it's good to have the reset done in kernel space,
not in user space.Without nested virt it does not really matter and if it is does not really matter you do not add code to the kernel just because it is good. With nested virt INIT# processing needs to go to the kernel. In some cases INIT will cause reset, but you do not "do reset in kernel space", you do "INIT# handling in kernel space".
We agree on this. What I add is: let's define the API so that it is nested-friendly. This means having a signaling mechanism for userspace.
I think you do not want mp_state to be this signaling mechanism. Why
not? Can an existing ioctl be the alternative or do we need to invent a new one?
Paolo
Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Gleb Natapov
Quoted 34 lines · Jan Kiszka
Quoted 32 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
--
Gleb.
Quoted 12 lines · Paolo Bonzini
Il 11/03/2013 18:20, Gleb Natapov ha scritto:
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines
Il 11/03/2013 14:54, Gleb Natapov ha scritto:
Quoted 8 lines
Quoted 2 lines
Setting the
mp_statetoINIT_RECEIVEDis that interface, and it already works, for APs at least. This patch extends it to work for the BSP as well.It does not for AP either. If AP has vmx on
mp_sateshould not be set toINIT_RECEIVED.mp_sateis a state as you can see from its name and we already had a discussion on the generic device API about importance of separating sending commands from setting state. There is a difference between settingmp_stateduring migration and signaling INIT#.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
What does migration have to do with this?
get|set_mpstate is used by migration. Actually this is primary reason for this interface existence.
Does it have to be the only one?
Nope, but it does prevent it from been used as even injection mechanism.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 6 lines
In the corresponding userspace patch, I don't need to touch the CPU state at all. I can just signal the kernel. If I touch the CPU, I'll break the nested case, no matter how it is implemented. So far, the userspace did not have to worry about nested, and that's something that should be kept that way.
We are discussing two different things here. I'll try to separate them.
1. BSP is broken WRT #INIT
2. nested is broken WRT #INITYou are fixing 1 with your patches, for that I proposed much easier solution (at last from kernel point of view): if BSP reset it in userspace and make it runnable. Nested virt is still broken, but this is not what you are fixing.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
It's not what I'm fixing, but I don't want to make the fix for nested
What are you fixing then?
Nested virt is not what I am fixing, but I'm trying to keep an eye on that (and the other INIT race) while doing these patches.
So you do fixing 1 then?
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
virt unnecessarily more complicated. Nested virt needs to know about INIT and SIPI; redefining the meaning of
INIT_RECEIVEDandSIPI_RECEIVEDmakes it more complicated to reflect these events to L1.Quoted 4 lines
For 2 much more involved fix is needed. Jan fixes it and it will require signaling INIT# from userspace by other means than
mp_satebecause signaling INIT# does not automatically means thatmp_satechanges toINIT_RECEIVED.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
In your interpretation of
INIT_RECEIVED, no. In mine, yes...Your code shows different. With your patch setting
mp_statetoINIT_RECEIVEDmakes vcpu non tunable. This is incorrect ifINIT_RECEIVEDis "INIT# is triggered" interface.What do you mean by "non tunable"? In non-nested mode, the VCPU will
Sorry, it should have been "not runnable".
Quoted 3 lines
reset immediately, as soon as it is re-entered. In nested mode, the VCPU will eat the
INIT_RECEIVEDand turn it into a vmexit.
It should not eat it. It should be pending until vmxoff. And processing INIT_RECEIVED separately far away from other events that causes vmexit is cumbersome. INIT# is just an event that can be masked, why treat it differently from IRQs?
Quoted 4 lines
At least according to AMD's docs, the VMM has to reassert INIT if it wants the processor to actually process it [15.20.8 INIT support]. Intel's does not say it explicitly, but it doesn't say the opposite either. It seems to be the only that makes sense.
Well [1] claims differently. Page 10 "VMX and INIT blocking".
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
If we move away from the
INIT_RECEIVEDandSIPI_RECEIVEDstates for in-kernel APIC -> VCPU communication, then theKVM_SET_MP_STATEioctl will have to convert them to the right bits in the requests field or in the APIC state. But I'm starting to see less benefit from moving away frommp_state.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signalingThat's what I meant; sorry for the unclear abbreviation.
Then we disagree.
We do. Let's see _where_ exactly we disagree.
My guess would be this: for me mp_state is current vcpu state, for you it is a way of passing events _and_ current vcpu state when you do not pass events there. Correct me if I am wrong.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
because with nested virt INIT does not always
changemp_state
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Why not?
Because
mp_stateis the current state the vcpu is in. It can be uninitialized, runnable, halted or wait for sipi. SDM says that if nested virt is enabled vcpu does not enter wait for sipi state on INIT#.Yes, but it still has to do something (a vmexit) and go back to RUNNING.
Or go back to HALT and when you overwrote current running state how do you know which one is that?. And how is it different from IRQs or NMI. We do not pass them in mp_state, not because we can't, just introduce EVENT_PENDING state, because it does not make sense.
Quoted 2 lines
So it needs signaling from userspace to the kernel.
And do I say it does not need it? I am saying mp_state is not it.
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
Which is why it's good to have the reset done in kernel space,
not in user space.Without nested virt it does not really matter and if it is does not really matter you do not add code to the kernel just because it is good. With nested virt INIT# processing needs to go to the kernel. In some cases INIT will cause reset, but you do not "do reset in kernel space", you do "INIT# handling in kernel space".
Quoted 6 lines
We agree on this. What I add is: let's define the API so that it is nested-friendly. This means having a signaling mechanism for userspace.
I think you do not wantmp_stateto be this signaling mechanism. Why
not? Can an existing ioctl be the alternative or do we need to invent a new one?
I explained why not above and in my previous emails. For the second question it is implementation detail. I hope we can extend existing interface, but if we cannot we add another one.
--
Gleb.
Quoted 42 lines · Gleb Natapov
Quoted 41 lines · Jan Kiszka
Quoted 39 lines · Gleb Natapov
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
Quoted 7 lines
Quoted 3 lines
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
Quoted 8 lines
Quoted 2 lines
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Interesting. And confusing. If a VMM cannot "consume" INIT events by reentering the guest nor postpone those events up to that point if they arrived in root mode, the whole vmexit-on-INIT thing is practically useless. I wonder what use case Intel had in mind while designing this.
That article claims they tested it, though via MSI injection, so they are probably right, at least for the used CPU type.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 50 lines · Jan Kiszka
Quoted 49 lines · Gleb Natapov
Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Gleb Natapov
Quoted 34 lines · Jan Kiszka
Quoted 32 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
Quoted 7 lines
Quoted 1 line
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Interesting. And confusing. If a VMM cannot "consume" INIT events by reentering the guest nor postpone those events up to that point if they arrived in root mode, the whole vmexit-on-INIT thing is practically useless. I wonder what use case Intel had in mind while designing this.
I actually find it very useful. On INIT vmexit hypervisor may call vmxoff and do proper reset. I find it less useful on AMD where you need to send self INIT IPI, but then how you can send self SIPI?
Quoted 8 lines
That article claims they tested it, though via MSI injection, so they are probably right, at least for the used CPU type.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
--
Gleb.
Quoted 53 lines · Gleb Natapov
Quoted 52 lines · Jan Kiszka
Quoted 50 lines · Gleb Natapov
Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Gleb Natapov
Quoted 34 lines · Jan Kiszka
Quoted 32 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Quoted 8 lines
Quoted 5 lines
Interesting. And confusing. If a VMM cannot "consume" INIT events by reentering the guest nor postpone those events up to that point if they arrived in root mode, the whole vmexit-on-INIT thing is practically useless. I wonder what use case Intel had in mind while designing this.
I actually find it very useful. On INIT vmexit hypervisor may call vmxoff and do proper reset. I find it less useful on AMD where you need to send self INIT IPI, but then how you can send self SIPI?
Where's the difference? On Intel, SIPI is also not deliverable until after vmxoff. So that signal has to come from the INIT sender, just like on AMD.
However, AMD allows you to NOT do a reset after leaving virtualization mode. On Intel, INIT is obviously irreversible, thus of limited use.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 59 lines · Jan Kiszka
Quoted 58 lines · Gleb Natapov
Quoted 57 lines · Jan Kiszka
Quoted 42 lines · Gleb Natapov
Quoted 41 lines · Jan Kiszka
Quoted 39 lines · Gleb Natapov
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
Quoted 7 lines
Quoted 3 lines
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
Quoted 8 lines
Quoted 2 lines
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Interesting. And confusing. If a VMM cannot "consume" INIT events by reentering the guest nor postpone those events up to that point if they arrived in root mode, the whole vmexit-on-INIT thing is practically useless. I wonder what use case Intel had in mind while designing this.
Quoted 8 lines
Quoted 3 lines
I actually find it very useful. On INIT vmexit hypervisor may call vmxoff and do proper reset. I find it less useful on AMD where you need to send self INIT IPI, but then how you can send self SIPI?
Where's the difference? On Intel, SIPI is also not deliverable until after vmxoff. So that signal has to come from the INIT sender, just like on AMD.
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vector
On AMD;
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
self INIT IPI
???
Quoted 3 lines
However, AMD allows you to NOT do a reset after leaving virtualization mode. On Intel, INIT is obviously irreversible, thus of limited use.
Why would hypervisor send INIT to one of its CPUs if it does not want to reset it? :)
--
Gleb.
Quoted 68 lines · Gleb Natapov
Quoted 59 lines · Jan Kiszka
Quoted 58 lines · Gleb Natapov
Quoted 57 lines · Jan Kiszka
Quoted 42 lines · Gleb Natapov
Quoted 41 lines · Jan Kiszka
Quoted 39 lines · Gleb Natapov
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from
mp_state, we are moving away from usingmp_statefor signaling because with nested virt INIT does not always changemp_state, not only that it can changemp_statelong after signal is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
Quoted 7 lines
Quoted 3 lines
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
Quoted 8 lines
Quoted 2 lines
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Interesting. And confusing. If a VMM cannot "consume" INIT events by reentering the guest nor postpone those events up to that point if they arrived in root mode, the whole vmexit-on-INIT thing is practically useless. I wonder what use case Intel had in mind while designing this.
Quoted 8 lines
Quoted 3 lines
I actually find it very useful. On INIT vmexit hypervisor may call vmxoff and do proper reset. I find it less useful on AMD where you need to send self INIT IPI, but then how you can send self SIPI?
Where's the difference? On Intel, SIPI is also not deliverable until after vmxoff. So that signal has to come from the INIT sender, just like on AMD.
Quoted 7 lines
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vector
Is SIPI sticky as well, even if the CPU is not in the wait-for-SIPI state (but runnable and in vmxon) while receiving it?
Quoted 11 lines
On AMD;
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
self INIT IPI
???
Quoted 5 lines
Quoted 3 lines
However, AMD allows you to NOT do a reset after leaving virtualization mode. On Intel, INIT is obviously irreversible, thus of limited use.
Why would hypervisor send INIT to one of its CPUs if it does not want to reset it? :)
First of all, to trigger a vmexit. What will happen with this event should be the hand of the hypervisor - ideally.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 77 lines · Jan Kiszka
Quoted 68 lines · Gleb Natapov
Quoted 59 lines · Jan Kiszka
Quoted 58 lines · Gleb Natapov
Quoted 57 lines · Jan Kiszka
Quoted 42 lines · Gleb Natapov
Quoted 41 lines · Jan Kiszka
Quoted 39 lines · Gleb Natapov
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Paolo Bonzini
Il 11/03/2013 15:05, Gleb Natapov ha scritto:
Quoted 8 lines · Jan Kiszka
Quoted 7 lines
Quoted 4 lines
We are not moving away from mp_state, we are moving away from using
mp_state for signaling because with nested virt INIT does not always
change mp_state, not only that it can change mp_state long after signal
is received after vmx off is done.Right.
Quoted 8 lines
Quoted 6 lines
BTW, for that to happen, we will also need to influence the INIT level. Unless I misread the spec, INIT is blocked while in root mode, and if you deassert INIT before leaving root (vmxoff, vmenter), nothing actually happens. So what matters is the INIT signal level at the exit of root mode.
You are talking about INIT# signal received via CPU pin, right? I think INIT send by IPI cannot go away.
Neither can go away. For INIT sent by IPI, 10.4.7 says:
Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT-disassert IPI has no affect on the state of the APIC, other than to reload the arbitration ID register with the value in the APIC ID register.
18.27.1 also says that "In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts".
Quoted 7 lines
Quoted 3 lines
For INIT#, the ICH9 chipset says that "INIT# is driven low for 16 PCI clocks" when a soft reset is requested. So we can guess that INIT# is also edge-triggered.
Ah, ok. So, virtually, INIT stays asserted until it can be delivered in form of a reset or a vmexit.
vmexit clears it?
Quoted 8 lines
Quoted 2 lines
It has to. Otherwise, it would hit the host on vmxoff.
Why do you thing this is not happening?
Look at [1] page 10 "VMX and INIT blocking". Do you think they were lucky to hit CPU while it was in a root mode?
[1] http://www.invisiblethingslab.com/resources/2011/Software%20Attacks%20on%20Intel%20VT-d.pdf
Interesting. And confusing. If a VMM cannot "consume" INIT events by reentering the guest nor postpone those events up to that point if they arrived in root mode, the whole vmexit-on-INIT thing is practically useless. I wonder what use case Intel had in mind while designing this.
Quoted 8 lines
Quoted 3 lines
I actually find it very useful. On INIT vmexit hypervisor may call vmxoff and do proper reset. I find it less useful on AMD where you need to send self INIT IPI, but then how you can send self SIPI?
Where's the difference? On Intel, SIPI is also not deliverable until after vmxoff. So that signal has to come from the INIT sender, just like on AMD.
Quoted 7 lines
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vector
Quoted 3 lines
Is SIPI sticky as well, even if the CPU is not in the wait-for-SIPI state (but runnable and in vmxon) while receiving it?
That what they seams to be saying:
However, an INIT and SIPI interrupts sent to a CPU during time when it is in a VMX mode are remembered and delivered, perhaps hours later, when the CPU exits the VMX mode
Otherwise their exploit will not work.
--
Gleb.
Quoted 11 lines · Gleb Natapov
Quoted 11 lines
Quoted 7 lines
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vectorIs SIPI sticky as well, even if the CPU is not in the wait-for-SIPI state (but runnable and in vmxon) while receiving it?
Quoted 6 lines
That what they seams to be saying:
However, an INIT and SIPI interrupts sent to a CPU during time when it is in a VMX mode are remembered and delivered, perhaps hours later, when the CPU exits the VMX modeOtherwise their exploit will not work.
Very weird, specifically as SIPI is not just a binary event but carries payload. Will another SIPI event overwrite the previously "saved" vector? We are deep into an underspecified area...
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Gleb Natapov
Quoted 11 lines
Quoted 7 lines
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vectorIs SIPI sticky as well, even if the CPU is not in the wait-for-SIPI state (but runnable and in vmxon) while receiving it?
That what they seams to be saying:
However, an INIT and SIPI interrupts sent to a CPU during time when it is in a VMX mode are remembered and delivered, perhaps hours later, when the CPU exits the VMX mode
Quoted 5 lines
Quoted 1 line
Otherwise their exploit will not work.
Very weird, specifically as SIPI is not just a binary event but carries payload. Will another SIPI event overwrite the previously "saved" vector? We are deep into an underspecified area...
My guess is that VMX INIT blocking is done by the same mechanism as INIT blocking during SMM. Obviously after exit from SMM pending INIT/SIPI have to be processed.
--
Gleb.
Quoted 18 lines · Gleb Natapov
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Gleb Natapov
Quoted 11 lines
Quoted 7 lines
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vectorIs SIPI sticky as well, even if the CPU is not in the wait-for-SIPI state (but runnable and in vmxon) while receiving it?
That what they seams to be saying:
However, an INIT and SIPI interrupts sent to a CPU during time when it is in a VMX mode are remembered and delivered, perhaps hours later, when the CPU exits the VMX mode
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Otherwise their exploit will not work.
Very weird, specifically as SIPI is not just a binary event but carries payload. Will another SIPI event overwrite the previously "saved" vector? We are deep into an underspecified area...
My guess is that VMX INIT blocking is done by the same mechanism as INIT blocking during SMM. Obviously after exit from SMM pending INIT/SIPI have to be processed.
I think this should be further examined via a test case that can run on real HW. Is kvm-unit-test ready for this? Then we "just" need to implement what you were already asking for: minimalistic nVMX tests...
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 24 lines · Jan Kiszka
Quoted 23 lines · Gleb Natapov
Quoted 22 lines · Jan Kiszka
Quoted 11 lines · Gleb Natapov
Quoted 11 lines
Quoted 7 lines
On Intel:
CPU 1 CPU 2 in a guest mode
send INIT
send SIPI
INIT vmexit
vmxoff
reset and start from SIPI vectorIs SIPI sticky as well, even if the CPU is not in the wait-for-SIPI state (but runnable and in vmxon) while receiving it?
Quoted 6 lines
That what they seams to be saying:
However, an INIT and SIPI interrupts sent to a CPU during time when it is in a VMX mode are remembered and delivered, perhaps hours later, when the CPU exits the VMX modeOtherwise their exploit will not work.
Very weird, specifically as SIPI is not just a binary event but carries payload. Will another SIPI event overwrite the previously "saved" vector? We are deep into an underspecified area...
Quoted 8 lines
Quoted 3 lines
My guess is that VMX INIT blocking is done by the same mechanism as INIT blocking during SMM. Obviously after exit from SMM pending INIT/SIPI have to be processed.
I think this should be further examined via a test case that can run on real HW. Is kvm-unit-test ready for this? Then we "just" need to implement what you were already asking for: minimalistic nVMX tests...
I do not think kvm-unit-test will run on bare metal. I once implemented framework for interrupt injection testing that ran on bare metal too. It was very handy to compare KVM behaviour with real HW, but it was since folded into kvm-unit-test.
--
Gleb.