From: Paolo Bonzini <pbonzini@redhat.com>
To: Maxim Levitsky <mlevitsk@redhat.com>, kvm@vger.kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Sean Christopherson <seanjc@google.com>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH 1/3] KVM: x86: VMX: __kvm_apic_update_irr must update the IRR atomically
Date: Tue, 18 Jul 2023 13:41:08 +0200 [thread overview]
Message-ID: <bda79e85-c0bf-8d59-2750-d922a59bb859@redhat.com> (raw)
In-Reply-To: <20230718091310.119672-2-mlevitsk@redhat.com>
On 7/18/23 11:13, Maxim Levitsky wrote:
> + irr_val = READ_ONCE(*((u32 *)(regs + APIC_IRR + i * 0x10)));
Let's separate out the complicated arithmetic, as it recurs below too:
u32 *p_irr = (u32 *)(regs + APIC_IRR + i * 0x10);
> + while (!try_cmpxchg(((u32 *)(regs + APIC_IRR + i * 0x10)),
> + &irr_val, irr_val | pir_val));
> +
> prev_irr_val = irr_val;
> - irr_val |= xchg(&pir[i], 0);
> - *((u32 *)(regs + APIC_IRR + i * 0x10)) = irr_val;
> - if (prev_irr_val != irr_val) {
> - max_updated_irr =
> - __fls(irr_val ^ prev_irr_val) + vec;
> - }
> + irr_val |= pir_val;
> +
> + if (prev_irr_val != irr_val)
> + max_updated_irr = __fls(irr_val ^ prev_irr_val) + vec;
We can write this a bit more cleanly too, and avoid unnecessary
try_cmpxchg too:
prev_irr_val = irr_val;
do
irr_val = prev_irr_val | pir_val;
while (prev_irr_val != irr_val &&
!try_cmpxchg(p_irr, &prev_irr_val, irr_val));
if (prev_irr_val != irr_val)
max_updated_irr = __fls(irr_val ^ prev_irr_val) + vec;
If this looks okay to you, I'll queue the patches for -rc3 and also Cc
them for inclusion in stable kernels.
Paolo
next prev parent reply other threads:[~2023-07-18 11:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 9:13 [PATCH 0/3] Fix 'Spurious APIC interrupt (vector 0xFF) on CPU#n' issue Maxim Levitsky
2023-07-18 9:13 ` [PATCH 1/3] KVM: x86: VMX: __kvm_apic_update_irr must update the IRR atomically Maxim Levitsky
2023-07-18 11:41 ` Paolo Bonzini [this message]
2023-07-18 13:35 ` Maxim Levitsky
2023-07-18 9:13 ` [PATCH 2/3] KVM: x86: VMX: set irr_pending in kvm_apic_update_irr Maxim Levitsky
2023-07-18 9:13 ` [PATCH 3/3] KVM: x86: check the kvm_cpu_get_interrupt result before using it Maxim Levitsky
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=bda79e85-c0bf-8d59-2750-d922a59bb859@redhat.com \
--to=pbonzini@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®