Skip to content

Commit a3e03bc

Browse files
halil-pasicborntraeger
authored andcommitted
KVM: s390: index kvm->arch.idle_mask by vcpu_idx
While in practice vcpu->vcpu_idx == vcpu->vcp_id is often true, it may not always be, and we must not rely on this. Reason is that KVM decides the vcpu_idx, userspace decides the vcpu_id, thus the two might not match. Currently kvm->arch.idle_mask is indexed by vcpu_id, which implies that code like for_each_set_bit(vcpu_id, kvm->arch.idle_mask, online_vcpus) { vcpu = kvm_get_vcpu(kvm, vcpu_id); do_stuff(vcpu); } is not legit. Reason is that kvm_get_vcpu expects an vcpu_idx, not an vcpu_id. The trouble is, we do actually use kvm->arch.idle_mask like this. To fix this problem we have two options. Either use kvm_get_vcpu_by_id(vcpu_id), which would loop to find the right vcpu_id, or switch to indexing via vcpu_idx. The latter is preferable for obvious reasons. Let us make switch from indexing kvm->arch.idle_mask by vcpu_id to indexing it by vcpu_idx. To keep gisa_int.kicked_mask indexed by the same index as idle_mask lets make the same change for it as well. Fixes: 1ee0bc5 ("KVM: s390: get rid of local_int array") Signed-off-by: Halil Pasic <[email protected]> Reviewed-by: Christian Bornträger <[email protected]> Reviewed-by: Claudio Imbrenda <[email protected]> Cc: <[email protected]> # 3.15+ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Borntraeger <[email protected]>
1 parent 7119dec commit a3e03bc

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ struct kvm_arch{
963963
atomic64_t cmma_dirty_pages;
964964
/* subset of available cpu features enabled by user space */
965965
DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
966+
/* indexed by vcpu_idx */
966967
DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
967968
struct kvm_s390_gisa_interrupt gisa_int;
968969
struct kvm_s390_pv pv;

arch/s390/kvm/interrupt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
419419
static void __set_cpu_idle(struct kvm_vcpu *vcpu)
420420
{
421421
kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
422-
set_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask);
422+
set_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask);
423423
}
424424

425425
static void __unset_cpu_idle(struct kvm_vcpu *vcpu)
426426
{
427427
kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT);
428-
clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask);
428+
clear_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask);
429429
}
430430

431431
static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
@@ -3050,18 +3050,18 @@ int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len)
30503050

30513051
static void __airqs_kick_single_vcpu(struct kvm *kvm, u8 deliverable_mask)
30523052
{
3053-
int vcpu_id, online_vcpus = atomic_read(&kvm->online_vcpus);
3053+
int vcpu_idx, online_vcpus = atomic_read(&kvm->online_vcpus);
30543054
struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
30553055
struct kvm_vcpu *vcpu;
30563056

3057-
for_each_set_bit(vcpu_id, kvm->arch.idle_mask, online_vcpus) {
3058-
vcpu = kvm_get_vcpu(kvm, vcpu_id);
3057+
for_each_set_bit(vcpu_idx, kvm->arch.idle_mask, online_vcpus) {
3058+
vcpu = kvm_get_vcpu(kvm, vcpu_idx);
30593059
if (psw_ioint_disabled(vcpu))
30603060
continue;
30613061
deliverable_mask &= (u8)(vcpu->arch.sie_block->gcr[6] >> 24);
30623062
if (deliverable_mask) {
30633063
/* lately kicked but not yet running */
3064-
if (test_and_set_bit(vcpu_id, gi->kicked_mask))
3064+
if (test_and_set_bit(vcpu_idx, gi->kicked_mask))
30653065
return;
30663066
kvm_s390_vcpu_wakeup(vcpu);
30673067
return;

arch/s390/kvm/kvm-s390.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4026,7 +4026,7 @@ static int vcpu_pre_run(struct kvm_vcpu *vcpu)
40264026
kvm_s390_patch_guest_per_regs(vcpu);
40274027
}
40284028

4029-
clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.gisa_int.kicked_mask);
4029+
clear_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.gisa_int.kicked_mask);
40304030

40314031
vcpu->arch.sie_block->icptcode = 0;
40324032
cpuflags = atomic_read(&vcpu->arch.sie_block->cpuflags);

arch/s390/kvm/kvm-s390.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
7979

8080
static inline int is_vcpu_idle(struct kvm_vcpu *vcpu)
8181
{
82-
return test_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask);
82+
return test_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask);
8383
}
8484

8585
static inline int kvm_is_ucontrol(struct kvm *kvm)

0 commit comments

Comments
 (0)