Skip to content

Commit 0bc380b

Browse files
borntraegerfrankjaa
authored andcommitted
KVM: s390/diag: fix racy access of physical cpu number in diag 9c handler
We do check for target CPU == -1, but this might change at the time we are going to use it. Hold the physical target CPU in a local variable to avoid out-of-bound accesses to the cpu arrays. Cc: Pierre Morel <pmorel@linux.ibm.com> Fixes: 87e28a1 ("KVM: s390: diag9c (directed yield) forwarding") Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Nico Boehr <nrb@linux.ibm.com> Reviewed-by: Pierre Morel <pmorel@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
1 parent 246be7d commit 0bc380b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

arch/s390/kvm/diag.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static int diag9c_forwarding_overrun(void)
166166
static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
167167
{
168168
struct kvm_vcpu *tcpu;
169+
int tcpu_cpu;
169170
int tid;
170171

171172
tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
@@ -181,14 +182,15 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
181182
goto no_yield;
182183

183184
/* target guest VCPU already running */
184-
if (READ_ONCE(tcpu->cpu) >= 0) {
185+
tcpu_cpu = READ_ONCE(tcpu->cpu);
186+
if (tcpu_cpu >= 0) {
185187
if (!diag9c_forwarding_hz || diag9c_forwarding_overrun())
186188
goto no_yield;
187189

188190
/* target host CPU already running */
189-
if (!vcpu_is_preempted(tcpu->cpu))
191+
if (!vcpu_is_preempted(tcpu_cpu))
190192
goto no_yield;
191-
smp_yield_cpu(tcpu->cpu);
193+
smp_yield_cpu(tcpu_cpu);
192194
VCPU_EVENT(vcpu, 5,
193195
"diag time slice end directed to %d: yield forwarded",
194196
tid);

0 commit comments

Comments
 (0)