From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Paolo Bonzini <pbonzini@redhat.com>, Ruihan Li <lrh2000@pku.edu.cn>
Cc: qemu-devel@nongnu.org, Eduardo Habkost <eduardo@habkost.net>,
Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH v2] target/i386: Give IRQs a chance when resetting HF_INHIBIT_IRQ_MASK
Date: Mon, 15 Apr 2024 20:30:02 +0200 [thread overview]
Message-ID: <78b7d022-1bb8-4b1d-ad52-db241582350c@linaro.org> (raw)
In-Reply-To: <CABgObfZmQoSBMQx=t0UYCa6t5d9RRZKy23zeW3orrBYnVQtKYQ@mail.gmail.com>
On 15/4/24 11:32, Paolo Bonzini wrote:
> On Mon, Apr 15, 2024 at 8:50 AM Ruihan Li <lrh2000@pku.edu.cn> wrote:
>>
>> When emulated with QEMU, interrupts will never come in the following
>> loop. However, if the NOP instruction is uncommented, interrupts will
>> fire as normal.
>>
>> loop:
>> cli
>> call do_sti
>> jmp loop
>>
>> do_sti:
>> sti
>> # nop
>> ret
>>
>> This behavior is different from that of a real processor. For example,
>> if KVM is enabled, interrupts will always fire regardless of whether the
>> NOP instruction is commented or not. Also, the Intel Software Developer
>> Manual states that after the STI instruction is executed, the interrupt
>> inhibit should end as soon as the next instruction (e.g., the RET
>> instruction if the NOP instruction is commented) is executed.
>
> Thanks, interesting bug!
>
> What do you think about writing this:
>
>> /* If several instructions disable interrupts, only the first does it. */
>> if (inhibit && !(s->flags & HF_INHIBIT_IRQ_MASK)) {
>> gen_set_hflag(s, HF_INHIBIT_IRQ_MASK);
>> - } else {
>> + inhibit_reset = false;
>> + } else if (!inhibit && (s->flags & HF_INHIBIT_IRQ_MASK)) {
>> gen_reset_hflag(s, HF_INHIBIT_IRQ_MASK);
>> + inhibit_reset = true;
>> + } else {
>> + inhibit_reset = false;
>> }
>
> in a slightly simpler manner:
>
> inhibit_reset = false;
> if (s->flags & HF_INHIBIT_IRQ_MASK) {
> gen_reset_hflag(s, HF_INHIBIT_IRQ_MASK);
> inhibit_reset = true;
> } else if (inhibit) {
> gen_set_hflag(s, HF_INHIBIT_IRQ_MASK);
> }
>
> No need to submit v3, I can do the change myself when applying.
Cc: qemu-stable@nongnu.org
prev parent reply other threads:[~2024-04-15 18:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 6:45 [PATCH v2] target/i386: Give IRQs a chance when resetting HF_INHIBIT_IRQ_MASK Ruihan Li
2024-04-15 9:32 ` Paolo Bonzini
2024-04-15 10:57 ` Ruihan Li
2024-04-15 18:30 ` Philippe Mathieu-Daudé [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78b7d022-1bb8-4b1d-ad52-db241582350c@linaro.org \
--to=philmd@linaro.org \
--cc=eduardo@habkost.net \
--cc=lrh2000@pku.edu.cn \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).