All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Naveen N Rao (AMD)" <naveen@kernel.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Vasant Hegde <vasant.hegde@amd.com>,
	 Maxim Levitsky <mlevitsk@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: Re: [PATCH 3/3] KVM: x86: Decouple APICv activation state from apicv_inhibit_reasons
Date: Mon, 3 Feb 2025 15:46:48 -0800	[thread overview]
Message-ID: <Z6FVaLOsPqmAPNWu@google.com> (raw)
In-Reply-To: <60cef3e4-8e94-4cf1-92ae-34089e78a82d@redhat.com>

On Mon, Feb 03, 2025, Paolo Bonzini wrote:
> On 2/3/25 19:45, Sean Christopherson wrote:
> > Unless there's a very, very good reason to support a use case that generates
> > ExtInts during boot, but _only_ during boot, and otherwise doesn't have any APICv
> > ihibits, I'm leaning towards making SVM's IRQ window inhibit sticky, i.e. never
> > clear it.
> 
> BIOS tends to use PIT, so that may be too much.  With respect to Naveen's report
> of contention on apicv_update_lock, I would go with the sticky-bit idea but apply
> it to APICV_INHIBIT_REASON_PIT_REINJ.

That won't work, at least not with yet more changes, because KVM creates the
in-kernel PIT with reinjection enabled by default.  The stick-bit idea is that
if a bit is set and can never be cleared, then there's no need to track new
updates.  Since userspace needs to explicitly disable reinjection, the inhibit
can't be sticky.

I assume We could fudge around that easily enough by deferring the inhibit until
a vCPU is created (or run?), but piggybacking PIT_REINJ won't help the userspace
I/O APIC case.

> I don't love adding another inhibit reason but, together, these two should
> remove the contention on apicv_update_lock.  Another idea could be to move
> IRQWIN to per-vCPU reason but Maxim tells me that it's not so easy.

Oh, yeah, that reminds me of the other reason I would vote for a sticky flag:
if inhibition really is toggling rapidly, performance is going to be quite bad
because inhibiting APICv requires (a) zapping APIC SPTEs and (b) serializing
writers if multiple vCPUs trigger the 0=>1 transition.

And there's some amount of serialization even if there's only a single writer,
as KVM kicks all vCPUs to toggle APICv (and again to flush TLBs, if necessary).

Hmm, something doesn't add up.  Naveen's changelog says:

  KVM additionally inhibits AVIC for requesting a IRQ window every time it has
  to inject external interrupts resulting in a barrage of inhibits being set and
  cleared. This shows significant performance degradation compared to AVIC being
  disabled, due to high contention on apicv_update_lock.

But if this is a "real world" use case where the only source of ExtInt is the
PIT, and kernels typically only wire up the PIT to the BSP, why is there
contention on apicv_update_lock?  APICv isn't actually being toggled, so readers
blocking writers to handle KVM_REQ_APICV_UPDATE shouldn't be a problem.

Naveen, do you know why there's a contention on apicv_update_lock?  Are multiple
vCPUs actually trying to inject ExtInt?

  reply	other threads:[~2025-02-03 23:46 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03 17:03 [PATCH 0/3] KVM: x86: Address performance degradation due to APICv inhibits Naveen N Rao (AMD)
2025-02-03 17:03 ` [PATCH 1/3] KVM: x86: hyper-v: Convert synic_auto_eoi_used to an atomic Naveen N Rao (AMD)
2025-02-04  1:30   ` Maxim Levitsky
2025-02-04 13:09     ` Naveen N Rao
2025-02-04 19:33       ` Sean Christopherson
2025-02-05 11:00         ` Naveen N Rao
2025-02-03 17:03 ` [PATCH 2/3] KVM: x86: Remove use of apicv_update_lock when toggling guest debug state Naveen N Rao (AMD)
2025-02-04  2:00   ` Maxim Levitsky
2025-02-04 13:10     ` Naveen N Rao
2025-02-04 14:25     ` Naveen N Rao
2025-02-04 17:51       ` Sean Christopherson
2025-02-04 17:58         ` Paolo Bonzini
2025-02-04 19:42           ` Maxim Levitsky
2025-02-05 11:13         ` Naveen N Rao
2025-02-03 17:03 ` [PATCH 3/3] KVM: x86: Decouple APICv activation state from apicv_inhibit_reasons Naveen N Rao (AMD)
2025-02-03 18:45   ` Sean Christopherson
2025-02-03 22:22     ` Paolo Bonzini
2025-02-03 23:46       ` Sean Christopherson [this message]
2025-02-04  1:23         ` Maxim Levitsky
2025-02-04 19:18           ` Sean Christopherson
2025-02-04 20:08             ` Maxim Levitsky
2025-02-05  1:41               ` Sean Christopherson
2025-02-05 10:54                 ` Naveen N Rao
2025-02-05 11:36             ` Paolo Bonzini
2025-02-11 15:57               ` Naveen N Rao
2025-02-11 16:37                 ` Sean Christopherson
2025-02-11 18:13                   ` Naveen N Rao
2025-02-04 11:06         ` Naveen N Rao
2025-02-04 14:08           ` Paolo Bonzini
2025-02-11 14:37             ` Naveen N Rao

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=Z6FVaLOsPqmAPNWu@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=naveen@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@amd.com \
    --cc=vkuznets@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 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.