Skip to content

Commit 22b2ca0

Browse files
committed
Merge tag 'kvm-x86-fixes-6.17-rc7' of https://github.com/kvm-x86/linux into HEAD
KVM x86 fixes and a selftest fix for 6.17-rcN - Use array_index_nospec() to sanitize the target vCPU ID when handling PV IPIs and yields as the ID is guest-controlled. - Drop a superfluous cpumask_empty() check when reclaiming SEV memory, as the common case, by far, is that at least one CPU will have entered the VM, and wbnoinvd_on_cpus_mask() will naturally handle the rare case where the set of have_run_cpus is empty. - Rename the is_signed_type() macro in kselftest_harness.h to is_signed_var() to fix a collision with linux/overflow.h. The collision generates compiler warnings due to the two macros having different implementations.
2 parents 1b237f1 + dce1b33 commit 22b2ca0

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

arch/x86/kvm/lapic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
810810
if (min > map->max_apic_id)
811811
return 0;
812812

813+
min = array_index_nospec(min, map->max_apic_id + 1);
814+
813815
for_each_set_bit(i, ipi_bitmap,
814816
min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
815817
if (map->phys_map[min + i]) {

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
}

arch/x86/kvm/x86.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9908,8 +9908,11 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
99089908
rcu_read_lock();
99099909
map = rcu_dereference(vcpu->kvm->arch.apic_map);
99109910

9911-
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
9912-
target = map->phys_map[dest_id]->vcpu;
9911+
if (likely(map) && dest_id <= map->max_apic_id) {
9912+
dest_id = array_index_nospec(dest_id, map->max_apic_id + 1);
9913+
if (map->phys_map[dest_id])
9914+
target = map->phys_map[dest_id]->vcpu;
9915+
}
99139916

99149917
rcu_read_unlock();
99159918

tools/testing/selftests/kselftest_harness.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,15 +751,15 @@
751751
for (; _metadata->trigger; _metadata->trigger = \
752752
__bail(_assert, _metadata))
753753

754-
#define is_signed_type(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1))
754+
#define is_signed_var(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1))
755755

756756
#define __EXPECT(_expected, _expected_str, _seen, _seen_str, _t, _assert) do { \
757757
/* Avoid multiple evaluation of the cases */ \
758758
__typeof__(_expected) __exp = (_expected); \
759759
__typeof__(_seen) __seen = (_seen); \
760760
if (!(__exp _t __seen)) { \
761761
/* Report with actual signedness to avoid weird output. */ \
762-
switch (is_signed_type(__exp) * 2 + is_signed_type(__seen)) { \
762+
switch (is_signed_var(__exp) * 2 + is_signed_var(__seen)) { \
763763
case 0: { \
764764
uintmax_t __exp_print = (uintmax_t)__exp; \
765765
uintmax_t __seen_print = (uintmax_t)__seen; \

0 commit comments

Comments
 (0)