[PATCH v3] KVM: x86: Fix poll command

alexjlzheng@gmail.com posted 1 patch 2 years, 8 months ago
arch/x86/kvm/i8259.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH v3] KVM: x86: Fix poll command
Posted by alexjlzheng@gmail.com 2 years, 8 months ago
From: Jinliang Zheng <alexjlzheng@tencent.com>

According to the hardware manual, when the Poll command is issued, the
byte returned by the I/O read is 1 in Bit 7 when there is an interrupt,
and the highest priority binary code in Bits 2:0. The current pic
simulation code is not implemented strictly according to the above
expression.

Fix the implementation of pic_poll_read(), set Bit 7 when there is an
interrupt.

Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
V2 -> V3: Keep the return value(0x07) unchanged if there's no interrupt
V1 -> V2: Keep the logic of pic_poll_read(), only fix the return value

 arch/x86/kvm/i8259.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index 4756bcb5724f..8dec646e764b 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -411,7 +411,10 @@ static u32 pic_poll_read(struct kvm_kpic_state *s, u32 addr1)
 		pic_clear_isr(s, ret);
 		if (addr1 >> 7 || ret != 2)
 			pic_update_irq(s->pics_state);
+		/* Bit 7 is 1, means there's an interrupt */
+		ret |= 0x80;
 	} else {
+		/* Bit 7 is 0, means there's no interrupt */
 		ret = 0x07;
 		pic_update_irq(s->pics_state);
 	}
-- 
2.31.1
Re: [PATCH v3] KVM: x86: Fix poll command
Posted by Sean Christopherson 2 years, 6 months ago
On Wed, 19 Apr 2023 10:19:25 +0800, alexjlzheng@gmail.com wrote:
> According to the hardware manual, when the Poll command is issued, the
> byte returned by the I/O read is 1 in Bit 7 when there is an interrupt,
> and the highest priority binary code in Bits 2:0. The current pic
> simulation code is not implemented strictly according to the above
> expression.
> 
> Fix the implementation of pic_poll_read(), set Bit 7 when there is an
> interrupt.
> 
> [...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86: Fix poll command
      https://github.com/kvm-x86/linux/commit/0d42522bdee7

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes