]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
KVM: SEV: don't check have_run_cpus in sev_writeback_caches()
authorYury Norov <yury.norov@gmail.com>
Mon, 11 Aug 2025 20:30:39 +0000 (16:30 -0400)
committerSean Christopherson <seanjc@google.com>
Mon, 18 Aug 2025 21:31:27 +0000 (14:31 -0700)
Drop KVM's check on an empty cpumask when flushing caches when memory is
being reclaimed from an SEV VM, as smp_call_function_many_cond() naturally
(and correctly) handles an empty cpumask.  This avoids an extra O(n)
lookup in the common case where at least one pCPU has enterred the guest,
which could be noticeable in some setups, e.g. if a small VM is pinned to
the last few pCPUs in the system.

Fixes: 6f38f8c57464 ("KVM: SVM: Flush cache only on CPUs running SEV guest")
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
[sean: rewrite changelog to capture performance angle]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/sev.c

index 2fbdebf79fbb243df98c01b19da8e7a82c00d716..0635bd71c10e78331e392f1db4fca4a77551f1c5 100644 (file)
@@ -718,13 +718,6 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages)
 
 static void sev_writeback_caches(struct kvm *kvm)
 {
-       /*
-        * Note, the caller is responsible for ensuring correctness if the mask
-        * can be modified, e.g. if a CPU could be doing VMRUN.
-        */
-       if (cpumask_empty(to_kvm_sev_info(kvm)->have_run_cpus))
-               return;
-
        /*
         * Ensure that all dirty guest tagged cache entries are written back
         * before releasing the pages back to the system for use.  CLFLUSH will
@@ -739,6 +732,9 @@ static void sev_writeback_caches(struct kvm *kvm)
         * serializing multiple calls and having responding CPUs (to the IPI)
         * mark themselves as still running if they are running (or about to
         * run) a vCPU for the VM.
+        *
+        * Note, the caller is responsible for ensuring correctness if the mask
+        * can be modified, e.g. if a CPU could be doing VMRUN.
         */
        wbnoinvd_on_cpus_mask(to_kvm_sev_info(kvm)->have_run_cpus);
 }