Skip to content

Commit 923fcb3

Browse files
YuryNorovsean-jc
authored andcommitted
KVM: SEV: don't check have_run_cpus in sev_writeback_caches()
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: 6f38f8c ("KVM: SVM: Flush cache only on CPUs running SEV guest") Signed-off-by: Yury Norov (NVIDIA) <[email protected]> [sean: rewrite changelog to capture performance angle] Signed-off-by: Sean Christopherson <[email protected]>
1 parent c87bd4d commit 923fcb3

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,6 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages)
718718

719719
static void sev_writeback_caches(struct kvm *kvm)
720720
{
721-
/*
722-
* Note, the caller is responsible for ensuring correctness if the mask
723-
* can be modified, e.g. if a CPU could be doing VMRUN.
724-
*/
725-
if (cpumask_empty(to_kvm_sev_info(kvm)->have_run_cpus))
726-
return;
727-
728721
/*
729722
* Ensure that all dirty guest tagged cache entries are written back
730723
* before releasing the pages back to the system for use. CLFLUSH will
@@ -739,6 +732,9 @@ static void sev_writeback_caches(struct kvm *kvm)
739732
* serializing multiple calls and having responding CPUs (to the IPI)
740733
* mark themselves as still running if they are running (or about to
741734
* run) a vCPU for the VM.
735+
*
736+
* Note, the caller is responsible for ensuring correctness if the mask
737+
* can be modified, e.g. if a CPU could be doing VMRUN.
742738
*/
743739
wbnoinvd_on_cpus_mask(to_kvm_sev_info(kvm)->have_run_cpus);
744740
}

0 commit comments

Comments
 (0)