From: Uros Bizjak <ubizjak@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: nVMX: clean up posted interrupt descriptor try_cmpxchg
Date: Sat, 25 Jun 2022 09:37:19 +0200 [thread overview]
Message-ID: <CAFULd4byUDS6U527qLuh78KmvM2OWbtappDfxLSiT_iMUz8Ghw@mail.gmail.com> (raw)
In-Reply-To: <20220624154552.2736417-1-pbonzini@redhat.com>
On Fri, Jun 24, 2022 at 5:45 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Rely on try_cmpxchg64 for re-reading the PID on failure, using READ_ONCE
> only right before the first iteration.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/vmx/posted_intr.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
> index 73f60aa480fe..1b56c5e5c9fb 100644
> --- a/arch/x86/kvm/vmx/posted_intr.c
> +++ b/arch/x86/kvm/vmx/posted_intr.c
> @@ -34,7 +34,7 @@ static inline struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu)
> return &(to_vmx(vcpu)->pi_desc);
> }
>
> -static int pi_try_set_control(struct pi_desc *pi_desc, u64 old, u64 new)
> +static int pi_try_set_control(struct pi_desc *pi_desc, u64 *pold, u64 new)
> {
> /*
> * PID.ON can be set at any time by a different vCPU or by hardware,
> @@ -42,7 +42,7 @@ static int pi_try_set_control(struct pi_desc *pi_desc, u64 old, u64 new)
> * update must be retried with a fresh snapshot an ON change causes
> * the cmpxchg to fail.
> */
> - if (!try_cmpxchg64(&pi_desc->control, &old, new))
> + if (!try_cmpxchg64(&pi_desc->control, pold, new))
> return -EBUSY;
>
> return 0;
> @@ -96,8 +96,9 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
> if (!x2apic_mode)
> dest = (dest << 8) & 0xFF00;
>
> + old.control = READ_ONCE(pi_desc->control);
> do {
> - old.control = new.control = READ_ONCE(pi_desc->control);
> + new.control = old.control;
>
> /*
> * Clear SN (as above) and refresh the destination APIC ID to
> @@ -111,7 +112,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
> * descriptor was modified on "put" to use the wakeup vector.
> */
> new.nv = POSTED_INTR_VECTOR;
> - } while (pi_try_set_control(pi_desc, old.control, new.control));
> + } while (pi_try_set_control(pi_desc, &old.control, new.control));
>
> local_irq_restore(flags);
>
> @@ -156,12 +157,12 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
>
> WARN(pi_desc->sn, "PI descriptor SN field set before blocking");
>
> + old.control = READ_ONCE(pi_desc->control);
> do {
> - old.control = new.control = READ_ONCE(pi_desc->control);
> -
> /* set 'NV' to 'wakeup vector' */
> + new.control = old.control;
This assignment should be above the comment, similar to vmx_vcpu_pi_load.
Uros.
> new.nv = POSTED_INTR_WAKEUP_VECTOR;
> - } while (pi_try_set_control(pi_desc, old.control, new.control));
> + } while (pi_try_set_control(pi_desc, &old.control, new.control));
>
> /*
> * Send a wakeup IPI to this CPU if an interrupt may have been posted
> --
> 2.31.1
>
prev parent reply other threads:[~2022-06-25 7:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-24 15:45 [PATCH] KVM: nVMX: clean up posted interrupt descriptor try_cmpxchg Paolo Bonzini
2022-06-25 7:37 ` Uros Bizjak [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=CAFULd4byUDS6U527qLuh78KmvM2OWbtappDfxLSiT_iMUz8Ghw@mail.gmail.com \
--to=ubizjak@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/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).