Skip to content

Commit 06c4f99

Browse files
committed
Merge tag 'kvm-riscv-fixes-7.1-1' of https://github.com/kvm-riscv/linux into HEAD
KVM/riscv fixes for 7.1, take #1 - Fix invalid HVA warning in steal-time recording - Return SBI_ERR_FAILURE to guest upon OOM in pmu_event_info() and pmu_snapshot_set_shmem() - Fix NULL pointer dereference in SBI v0.1 SEND_IPI handler - Fix sign extension of value for MMIO loads
2 parents 37f32d5 + c783253 commit 06c4f99

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

arch/riscv/kvm/vcpu_insn.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
415415
shift = 8 * (sizeof(ulong) - len);
416416
} else if ((insn & INSN_MASK_LBU) == INSN_MATCH_LBU) {
417417
len = 1;
418-
shift = 8 * (sizeof(ulong) - len);
419418
#ifdef CONFIG_64BIT
420419
} else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) {
421420
len = 8;
@@ -649,22 +648,22 @@ int kvm_riscv_vcpu_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
649648
case 1:
650649
data8 = *((u8 *)run->mmio.data);
651650
SET_RD(insn, &vcpu->arch.guest_context,
652-
(ulong)data8 << shift >> shift);
651+
(long)((ulong)data8 << shift) >> shift);
653652
break;
654653
case 2:
655654
data16 = *((u16 *)run->mmio.data);
656655
SET_RD(insn, &vcpu->arch.guest_context,
657-
(ulong)data16 << shift >> shift);
656+
(long)((ulong)data16 << shift) >> shift);
658657
break;
659658
case 4:
660659
data32 = *((u32 *)run->mmio.data);
661660
SET_RD(insn, &vcpu->arch.guest_context,
662-
(ulong)data32 << shift >> shift);
661+
(long)((ulong)data32 << shift) >> shift);
663662
break;
664663
case 8:
665664
data64 = *((u64 *)run->mmio.data);
666665
SET_RD(insn, &vcpu->arch.guest_context,
667-
(ulong)data64 << shift >> shift);
666+
(long)((ulong)data64 << shift) >> shift);
668667
break;
669668
default:
670669
return -EOPNOTSUPP;

arch/riscv/kvm/vcpu_pmu.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,10 @@ int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long s
453453
}
454454

455455
kvpmu->sdata = kzalloc(snapshot_area_size, GFP_ATOMIC);
456-
if (!kvpmu->sdata)
457-
return -ENOMEM;
456+
if (!kvpmu->sdata) {
457+
sbiret = SBI_ERR_FAILURE;
458+
goto out;
459+
}
458460

459461
/* No need to check writable slot explicitly as kvm_vcpu_write_guest does it internally */
460462
if (kvm_vcpu_write_guest(vcpu, saddr, kvpmu->sdata, snapshot_area_size)) {
@@ -499,8 +501,10 @@ int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low
499501
}
500502

501503
einfo = kzalloc(shmem_size, GFP_KERNEL);
502-
if (!einfo)
503-
return -ENOMEM;
504+
if (!einfo) {
505+
ret = SBI_ERR_FAILURE;
506+
goto out;
507+
}
504508

505509
ret = kvm_vcpu_read_guest(vcpu, shmem, einfo, shmem_size);
506510
if (ret) {

arch/riscv/kvm/vcpu_sbi_sta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
4646
gfn = shmem >> PAGE_SHIFT;
4747
hva = kvm_vcpu_gfn_to_hva(vcpu, gfn);
4848

49-
if (WARN_ON(kvm_is_error_hva(hva))) {
49+
if (kvm_is_error_hva(hva)) {
5050
vcpu->arch.sta.shmem = INVALID_GPA;
5151
return;
5252
}

arch/riscv/kvm/vcpu_sbi_v01.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
5555

5656
for_each_set_bit(i, &hmask, BITS_PER_LONG) {
5757
rvcpu = kvm_get_vcpu_by_id(vcpu->kvm, i);
58+
if (!rvcpu)
59+
continue;
5860
ret = kvm_riscv_vcpu_set_interrupt(rvcpu, IRQ_VS_SOFT);
5961
if (ret < 0)
6062
break;

0 commit comments

Comments
 (0)