All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: x86: Fix poll command
       [not found] <20230418104743.842683-1-alexjlzheng@tencent.com>
@ 2023-04-18 10:47 ` alexjlzheng
  2023-04-18 10:47 ` [PATCH 2/2] KVM: x86: Adjust return value of pic_poll_read() alexjlzheng
  1 sibling, 0 replies; 3+ messages in thread
From: alexjlzheng @ 2023-04-18 10:47 UTC (permalink / raw)
  To: seanjc
  Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel, Jinliang Zheng

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>
---
 arch/x86/kvm/i8259.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index 4756bcb5724f..861872e2641a 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -411,6 +411,8 @@ 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 {
 		ret = 0x07;
 		pic_update_irq(s->pics_state);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] KVM: x86: Adjust return value of pic_poll_read()
       [not found] <20230418104743.842683-1-alexjlzheng@tencent.com>
  2023-04-18 10:47 ` [PATCH 1/2] KVM: x86: Fix poll command alexjlzheng
@ 2023-04-18 10:47 ` alexjlzheng
  2023-04-18 15:19   ` Sean Christopherson
  1 sibling, 1 reply; 3+ messages in thread
From: alexjlzheng @ 2023-04-18 10:47 UTC (permalink / raw)
  To: seanjc
  Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel, Jinliang Zheng

From: Jinliang Zheng <alexjlzheng@tencent.com>

Returning 0x07 raises ambiguity when no interrupt is in pic_poll_read().
Although it will not cause a functional exception (Bit 7 is 0 means no
interrupt), it will easily make developers mistakenly think that a
spurious interrupt (IRQ 7) has been returned.

Return 0x00 instread of 0x07.

Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
 arch/x86/kvm/i8259.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index 861872e2641a..57978ad8311c 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -414,7 +414,8 @@ static u32 pic_poll_read(struct kvm_kpic_state *s, u32 addr1)
 		/* Bit 7 is 1, means there's an interrupt */
 		ret |= 0x80;
 	} else {
-		ret = 0x07;
+		/* Bit 7 is 0, means there's no interrupt */
+		ret = 0x00;
 		pic_update_irq(s->pics_state);
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] KVM: x86: Adjust return value of pic_poll_read()
  2023-04-18 10:47 ` [PATCH 2/2] KVM: x86: Adjust return value of pic_poll_read() alexjlzheng
@ 2023-04-18 15:19   ` Sean Christopherson
  0 siblings, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2023-04-18 15:19 UTC (permalink / raw)
  To: alexjlzheng
  Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel, Jinliang Zheng

On Tue, Apr 18, 2023, alexjlzheng@gmail.com wrote:
> From: Jinliang Zheng <alexjlzheng@tencent.com>
> 
> Returning 0x07 raises ambiguity when no interrupt is in pic_poll_read().
> Although it will not cause a functional exception (Bit 7 is 0 means no

From KVM's perspective, it's a functional change.  It _shouldn't_ impact the
overall functionality of the guest, but we have no idea what guest code exists
in the wild.

> interrupt), it will easily make developers mistakenly think that a
> spurious interrupt (IRQ 7) has been returned.
> 
> Return 0x00 instread of 0x07.

Again, I do not want to introduce a functional change in this code without evidence
that the change fixes something for a real world guest.  Based on your response[*],
that is not the case.

A comment explaining the KVM behavior would be very welcome, but I'm not taking
this patch.

[*] https://lore.kernel.org/all/20230418075923.752113-1-alexjlzheng@tencent.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-18 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230418104743.842683-1-alexjlzheng@tencent.com>
2023-04-18 10:47 ` [PATCH 1/2] KVM: x86: Fix poll command alexjlzheng
2023-04-18 10:47 ` [PATCH 2/2] KVM: x86: Adjust return value of pic_poll_read() alexjlzheng
2023-04-18 15:19   ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.