]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: Isolate apicv_update_lock and apicv_nr_irq_window_req in a cacheline
authorSean Christopherson <seanjc@google.com>
Fri, 23 Jan 2026 22:45:14 +0000 (14:45 -0800)
committerSean Christopherson <seanjc@google.com>
Mon, 2 Mar 2026 22:51:36 +0000 (14:51 -0800)
Force apicv_update_lock and apicv_nr_irq_window_req to reside in their own
cacheline to avoid generating significant contention due to false sharing
when KVM is contantly creating IRQ windows.  E.g. apicv_inhibit_reasons is
read on every VM-Enter; disabled_exits is read on page faults, on PAUSE
exits, if a vCPU is scheduled out, etc.; kvmclock_offset is read every time
a vCPU needs to refresh kvmclock, and so on and so forth.

Isolating the write-mostly fields from all other (read-mostly) fields
improves performance by 7-8% when running netperf TCP_RR between two guests
on the same physical host when using an in-kernel PIT in re-inject mode.

Reported-by: Naveen N Rao (AMD) <naveen@kernel.org>
Closes: https://lore.kernel.org/all/yrxhngndj37edud6tj5y3vunaf7nirwor4n63yf4275wdocnd3@c77ujgialc6r
Tested-by: Naveen N Rao (AMD) <naveen@kernel.org>
Link: https://patch.msgid.link/20260123224514.2509129-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h

index 68db00dc09a02c949c761691a0c04f74083060f5..883b85b3e1de08cabd1506ceb5947ebc1534b2b9 100644 (file)
@@ -1441,13 +1441,23 @@ struct kvm_arch {
        bool apic_access_memslot_enabled;
        bool apic_access_memslot_inhibited;
 
+       /*
+        * Force apicv_update_lock and apicv_nr_irq_window_req to reside in a
+        * dedicated cacheline.  They are write-mostly, whereas most everything
+        * else in kvm_arch is read-mostly.  Note that apicv_inhibit_reasons is
+        * read-mostly: toggling VM-wide inhibits is rare; _checking_ for
+        * inhibits is common.
+        */
+       ____cacheline_aligned
        /*
         * Protects apicv_inhibit_reasons and apicv_nr_irq_window_req (with an
         * asterisk, see kvm_inc_or_dec_irq_window_inhibit() for details).
         */
        struct rw_semaphore apicv_update_lock;
-       unsigned long apicv_inhibit_reasons;
        atomic_t apicv_nr_irq_window_req;
+       ____cacheline_aligned
+
+       unsigned long apicv_inhibit_reasons;
 
        gpa_t wall_clock;