* [PATCH v2] KVM: x86: Fix poll command
@ 2023-04-13 12:11 alexjlzheng
2023-04-14 17:50 ` Sean Christopherson
0 siblings, 1 reply; 5+ messages in thread
From: alexjlzheng @ 2023-04-13 12:11 UTC (permalink / raw)
To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa
Cc: 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():
1. Set Bit 7 when there is an interrupt
2. Return 0 when there is no interrupt
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
Changes since Version V2:
- Keep the logic of pic_poll_read(), only fix the return value
---
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 4756bcb5724f..6627f8a52f23 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -411,8 +411,9 @@ 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);
+ ret |= 0x80;
} else {
- ret = 0x07;
+ ret = 0x00;
pic_update_irq(s->pics_state);
}
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] KVM: x86: Fix poll command
2023-04-13 12:11 [PATCH v2] KVM: x86: Fix poll command alexjlzheng
@ 2023-04-14 17:50 ` Sean Christopherson
2023-04-15 3:30 ` alexjlzheng
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2023-04-14 17:50 UTC (permalink / raw)
To: alexjlzheng
Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
linux-kernel, Jinliang Zheng
On Thu, Apr 13, 2023, alexjlzheng@gmail.com wrote:
> From: Jinliang Zheng <alexjlzheng@tencent.com>
>
> According to the hardware manual, when the Poll command is issued, the
Please add "8259", i.e. "According to the 8259 hardware manual".
> 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():
> 1. Set Bit 7 when there is an interrupt
> 2. Return 0 when there is no interrupt
I don't think #2 is justified. The spec says:
The interrupt requests are ordered in priority from 0 through 7 (0 highest).
I.e. the current code enumerates the _lowest_ priority when there is no interrupt,
which seems more correct than reporting the highest priority possible.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] KVM: x86: Fix poll command
2023-04-14 17:50 ` Sean Christopherson
@ 2023-04-15 3:30 ` alexjlzheng
2023-04-17 16:51 ` Sean Christopherson
0 siblings, 1 reply; 5+ messages in thread
From: alexjlzheng @ 2023-04-15 3:30 UTC (permalink / raw)
To: seanjc
Cc: alexjlzheng, alexjlzheng, bp, dave.hansen, hpa, kvm, linux-kernel,
mingo, pbonzini, tglx, x86
On Fri, 14 Apr 2023, Sean Christopherson <seanjc@google.com> wrote:
> On Thu, Apr 13, 2023, alexjlzheng@gmail.com wrote:
> > From: Jinliang Zheng <alexjlzheng@tencent.com>
> >
> > According to the hardware manual, when the Poll command is issued, the
>
> Please add "8259", i.e. "According to the 8259 hardware manual".
Ok, I will pay attention next time.
>
> > 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():
> > 1. Set Bit 7 when there is an interrupt
> > 2. Return 0 when there is no interrupt
>
> I don't think #2 is justified. The spec says:
>
> The interrupt requests are ordered in priority from 0 through 7 (0 highest).
This is only true when don't use rotation for priority or just reset the 8259a.
It's prossible to change priorities, i.e. Specific Rotation Mode or Automatic
Rotation Mode.
>
> I.e. the current code enumerates the _lowest_ priority when there is no interrupt,
> which seems more correct than reporting the highest priority possible.
The practice and interpretation of returning to the lowest priority interrupt
when there are no active interrupts in the PIC doesn't seem reasonable, as far as I
understand. For #2, in my opinion, the correct interpretation of the current code
may be that a spurious interrupt is returned(IRQ 7 is used for that according to
the 8259 hardware manual).
For #2, the main purpose of returning 0 is to set Bit 7 of the return value to 0
to indicate that there is no interrupt.
Thank you very much.
Jinliang Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] KVM: x86: Fix poll command
2023-04-15 3:30 ` alexjlzheng
@ 2023-04-17 16:51 ` Sean Christopherson
2023-04-18 7:59 ` alexjlzheng
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2023-04-17 16:51 UTC (permalink / raw)
To: alexjlzheng
Cc: alexjlzheng, bp, dave.hansen, hpa, kvm, linux-kernel, mingo,
pbonzini, tglx, x86
On Sat, Apr 15, 2023, alexjlzheng@gmail.com wrote:
> On Fri, 14 Apr 2023, Sean Christopherson <seanjc@google.com> wrote:
> > On Thu, Apr 13, 2023, alexjlzheng@gmail.com wrote:
> > > Fix the implementation of pic_poll_read():
> > > 1. Set Bit 7 when there is an interrupt
> > > 2. Return 0 when there is no interrupt
> >
> > I don't think #2 is justified. The spec says:
> >
> > The interrupt requests are ordered in priority from 0 through 7 (0 highest).
>
> This is only true when don't use rotation for priority or just reset the 8259a.
> It's prossible to change priorities, i.e. Specific Rotation Mode or Automatic
> Rotation Mode.
>
> >
> > I.e. the current code enumerates the _lowest_ priority when there is no interrupt,
> > which seems more correct than reporting the highest priority possible.
>
> The practice and interpretation of returning to the lowest priority interrupt
> when there are no active interrupts in the PIC doesn't seem reasonable, as far as I
> understand. For #2, in my opinion, the correct interpretation of the current code
> may be that a spurious interrupt is returned(IRQ 7 is used for that according to
> the 8259 hardware manual).
>
> For #2, the main purpose of returning 0 is to set Bit 7 of the return value to 0
> to indicate that there is no interrupt.
Is there an actual real world chunk of guest code that is broken by KVM's behavior
for the "no interrupt" case? Because if not, my strong preference is to leave the
code as-is.
I have no objection to setting bit 7 when there is an interrupt, as that behavior
is explicitly called out and KVM is clearly in the wrong.
But for the "no interrupt" case, there are a lot of "mays" and "seems" in both of
our responses, i.e. it's not obvious that the current code is outright wrong, nor
that it is correct either. Given the lack of clarity, unless there's a guest that's
actually broken by KVM's current implementation, I see no benefit to changing KVM's
behavior, only the potential for breaking existing KVM guests.
And if the "no interrupt" case really does need to be fixed, please split it to
a separate patch.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] KVM: x86: Fix poll command
2023-04-17 16:51 ` Sean Christopherson
@ 2023-04-18 7:59 ` alexjlzheng
0 siblings, 0 replies; 5+ messages in thread
From: alexjlzheng @ 2023-04-18 7:59 UTC (permalink / raw)
To: seanjc
Cc: alexjlzheng, alexjlzheng, bp, dave.hansen, hpa, kvm, linux-kernel,
mingo, pbonzini, tglx, x86
On Mon, 17 Apr 2023, Sean Christopherson <seanjc@google.com> wrote:
> On Sat, Apr 15, 2023, alexjlzheng@gmail.com wrote:
> > On Fri, 14 Apr 2023, Sean Christopherson <seanjc@google.com> wrote:
> > > On Thu, Apr 13, 2023, alexjlzheng@gmail.com wrote:
> > > > Fix the implementation of pic_poll_read():
> > > > 1. Set Bit 7 when there is an interrupt
> > > > 2. Return 0 when there is no interrupt
> > >
> > > I don't think #2 is justified. The spec says:
> > >
> > > The interrupt requests are ordered in priority from 0 through 7 (0 highest).
> >
> > This is only true when don't use rotation for priority or just reset the 8259a.
> > It's prossible to change priorities, i.e. Specific Rotation Mode or Automatic
> > Rotation Mode.
> >
> > >
> > > I.e. the current code enumerates the _lowest_ priority when there is no interrupt,
> > > which seems more correct than reporting the highest priority possible.
> >
> > The practice and interpretation of returning to the lowest priority interrupt
> > when there are no active interrupts in the PIC doesn't seem reasonable, as far as I
> > understand. For #2, in my opinion, the correct interpretation of the current code
> > may be that a spurious interrupt is returned(IRQ 7 is used for that according to
> > the 8259 hardware manual).
> >
> > For #2, the main purpose of returning 0 is to set Bit 7 of the return value to 0
> > to indicate that there is no interrupt.
>
> Is there an actual real world chunk of guest code that is broken by KVM's behavior
> for the "no interrupt" case? Because if not, my strong preference is to leave the
> code as-is.
>
> I have no objection to setting bit 7 when there is an interrupt, as that behavior
> is explicitly called out and KVM is clearly in the wrong.
Very happy that we have reached a consensus on #1.
>
> But for the "no interrupt" case, there are a lot of "mays" and "seems" in both of
> our responses, i.e. it's not obvious that the current code is outright wrong, nor
> that it is correct either. Given the lack of clarity, unless there's a guest that's
> actually broken by KVM's current implementation, I see no benefit to changing KVM's
> behavior, only the potential for breaking existing KVM guests.
For #2, neither returning 0 nor 7 will affect the behavior of interrupt handling in
the guest os. Because their Bit 7 are all 0, the guest os will interpret them as no
interrupt. However, keeping it as it is (return 7) will reduce the readability of
the pic_poll_read() code. When developers compare the code in kvm_pic_read_irq(),
they may think that what is returned in #2 is a spurious interrupt, but this is not.
>
> And if the "no interrupt" case really does need to be fixed, please split it to
> a separate patch.
For the reasons above, I suggest fix #2. I will split it to a separate patch.
Thank you.
Jinliang Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-04-18 7:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-13 12:11 [PATCH v2] KVM: x86: Fix poll command alexjlzheng
2023-04-14 17:50 ` Sean Christopherson
2023-04-15 3:30 ` alexjlzheng
2023-04-17 16:51 ` Sean Christopherson
2023-04-18 7:59 ` alexjlzheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox