KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
Subsystems (2)
PATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
When the last VM is terminated, the host kernel will invoke function hardware_disable_nolock() on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.
--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/riscv/kvm/main.c +8 -0
@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ +csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); }
Signature · 1 line
2.17.1
Anup Patel
maintainerPATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
Quoted 8 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.
Small correction in last sentence:
".... must be cleared before clearing hideleg CSR."
Quoted 11 lines
Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 66
Quoted 9 lines
arch/riscv/kvm/main.c +6
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/
Same correction as above.
Quoted 9 lines
arch/riscv/kvm/main.c +2
-1+csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
Quoted 4 lines
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Overall, this is a good fix but it is late in the development cycle so please add the "Fixes:" tag and also CC stable.
Regards,
Anup
PATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
Quoted 11 lines · Anup Patel
Quoted 8 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.
Quoted 3 lines
Small correction in last sentence:
".... must be cleared before clearing hideleg CSR."
OK
Quoted 12 lines
Quoted 12 lines
Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)
Quoted 10 lines
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 66
Quoted 8 lines
arch/riscv/kvm/main.c +6
-0void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ Same correction as above.
OK
Quoted 10 lines
Quoted 10 lines
arch/riscv/kvm/main.c +2
-1+csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
Quoted 8 lines
Quoted 4 lines
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscvOverall, this is a good fix but it is late in the development cycle so please add the "Fixes:" tag and also CC stable.
OK, I will add the "Fixes:" tag and also CC stable in my next version patch. Thank you
Quoted 4 lines
Reviewed-by Anup Patel <[email protected]>Regards,
Anup
PATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
In reply to Vincent ChenQuoted 20 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 68
Quoted 10 lines
arch/riscv/kvm/main.c +8
-0void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ +csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );
From hw design view, CSR_VSIE is enough, why apend CSR_HVIP clearing?
How can I reproduce it on qemu?
Quoted 11 lines
arch/riscv/kvm/main.c +0
-1csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
PATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
Quoted 22 lines · Guo Ren
Quoted 20 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)
Quoted 11 lines
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 68
Quoted 10 lines
arch/riscv/kvm/main.c +8
-0void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ +csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );From hw design view,
CSR_VSIEis enough, why apendCSR_HVIPclearing?
The CSR_HVIP is for the host OS to trigger virtual interrupts intended for VS-mode. Because the host OS has terminated all guest OS at this moment, I think the host OS also needs to clear CSR_HVIP as well.
Quoted 2 lines
How can I reproduce it on qemu?
After booting a guest OS to the shell, if you are lucky enough, you will see the console repeatedly prints "unexpected IRQ trap at vector 00" after using "halt -f" to terminate the guest OS.
(It is difficult to reproduce. This is because this bug happens only if $HVIP has pending interrupts whenever the guest OS is terminated)
Quoted 20 lines
Quoted 8 lines
arch/riscv/kvm/main.c +0
-1csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
Quoted 4 lines
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv--
Best Regards
Guo Ren
PATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
Quoted 41 lines · Vincent Chen
Quoted 22 lines · Guo Ren
Quoted 20 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)Quoted 11 lines
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 68
Quoted 10 lines
arch/riscv/kvm/main.c +8
-0void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ +csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );From hw design view,
CSR_VSIEis enough, why apendCSR_HVIPclearing?The
CSR_HVIPis for the host OS to trigger virtual interrupts intended for VS-mode. Because the host OS has terminated all guest OS at this moment, I think the host OS also needs to clearCSR_HVIPas well.Quoted 1 line
Quoted 7 lines
Quoted 1 line
How can I reproduce it on qemu?
After booting a guest OS to the shell, if you are lucky enough, you will see the console repeatedly prints "unexpected IRQ trap at vector 00" after using "halt -f" to terminate the guest OS.
(It is difficult to reproduce. This is because this bug happens only if $HVIP has pending interrupts whenever the guest OS is terminated)
Got it, thx.
Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
arch/riscv/kvm/main.c +0
-1csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
Quoted 4 lines
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv--
Best Regards
Guo Ren
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
Anup Patel
maintainerPATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
In reply to Guo RenQuoted 22 lines · Guo Ren
Quoted 20 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)
Quoted 11 lines
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 68
Quoted 10 lines
arch/riscv/kvm/main.c +8
-0void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ +csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );From hw design view,
CSR_VSIEis enough, why apendCSR_HVIPclearing?
Actually, both HVIP and VSIE are collectively responsible for injecting virtual interrupts. Rather than clearing just one of them, it's better to clear both in kvm_arch_hardware_disable() since this is in the non-performance critical path.
Regards,
Anup
Quoted 27 lines
How can I reproduce it on qemu?
Quoted 11 lines
arch/riscv/kvm/main.c +0
-1csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv--
Best Regards
Guo RenML: https://lore.kernel.org/linux-csky/
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR
Quoted 36 lines · Anup Patel
Quoted 22 lines · Guo Ren
Quoted 20 lines · Vincent Chen
When the last VM is terminated, the host kernel will invoke function
hardware_disable_nolock()on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR shall be cleared earlier than hideleg CSR.Signed-off-by Vincent Chen <[email protected]>--- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/riscv/kvm/main.c +0
-0@@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void)Quoted 11 lines
arch/riscv/kvm/main.c int kvm_arch_hardware_enable(void) · line 68
Quoted 10 lines
arch/riscv/kvm/main.c +8
-0void kvm_arch_hardware_disable (void ) { +/* +* After clearing the hideleg CSR, the host kernel will receive spurious +* interrupts if hvip CSR has pending interrupts and the corresponding +* enable bits in vsie CSR are asserted. To avoid it, hvip CSR and +* vsie CSR shall be cleared early than hideleg CSR. +*/ +csr_write (CSR_VSIE ,0 ); +csr_write (CSR_HVIP ,0 );From hw design view,
CSR_VSIEis enough, why apendCSR_HVIPclearing?
Quoted 4 lines
Actually, both HVIP and VSIE are collectively responsible for injecting virtual interrupts. Rather than clearing just one of them, it's better to clear both in
kvm_arch_hardware_disable()since this is in the non-performance critical path.
Clear enough, thx for the reply.
Quoted 31 lines
Regards,
AnupQuoted 27 lines
How can I reproduce it on qemu?
Quoted 11 lines
arch/riscv/kvm/main.c +0
-1csr_write (CSR_HEDELEG ,0 );csr_write (CSR_HIDELEG ,0 ); } --2.17.1
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv--
Best Regards
Guo RenML: https://lore.kernel.org/linux-csky/
--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/