Skip to content

Commit 6a97c4d

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "arm64: - Fix ITS EventID sanitisation when restoring an interrupt translation table. - Fix PPI memory leak when failing to initialise a vcpu. - Correctly return an error when the validation of a hypervisor trace descriptor fails, and limit this validation to protected mode only. RISC-V: - 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 s390: - Fix bugs in vSIE (nested virtualization) and UCONTROL, caused by the page table rewrite. x86: - Apply erratum Rust-for-Linux#1235 workaround (disable AVIC IPI virtualization) on Hygon Family 18h, just like on AMD Family 17h. - When KVM_CAP_X86_APIC_BUS_CYCLES_NS is queried on a specific VM, return the VM's configured APIC bus frequency instead of the default. This is less confusing (read: not wrong) and makes it easier to fill in CPUID information that communicates the APIC bus frequency to the guest. Selftests: - Do not include glibc-internal <bits/endian.h>; it worked by chance and broke building KVM selftests with musl" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: SVM: Disable AVIC IPI virtualization on Hygon Family 18h (erratum Rust-for-Linux#1235) KVM: selftests: Verify that KVM returns the configured APIC cycle length KVM: x86: Return the VM's configured APIC bus frequency when queried KVM: selftests: elf: Include <endian.h> instead of <bits/endian.h> KVM: s390: Properly reset zero bit in PGSTE KVM: s390: vsie: Fix redundant rmap entries KVM: s390: vsie: Fix unshadowing logic KVM: s390: Fix leaking kvm_s390_mmu_cache in case of errors KVM: s390: vsie: Fix memory leak when unshadowing KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc KVM: arm64: vgic: Free private_irqs when init fails after allocation KVM: arm64: vgic-its: Reject restored DTE with out-of-range num_eventid_bits RISC-V: KVM: Fix sign extension for MMIO loads RISC-V: KVM: Fix NULL pointer dereference in SBI v0.1 SEND_IPI handler riscv: kvm: return SBI_ERR_FAILURE for pmu_event_info() when OOM riscv: kvm: return SBI_ERR_FAILURE for pmu_snapshot_set_shmem() when OOM RISC-V: KVM: Fix invalid HVA warning in steal-time recording
2 parents 3526d74 + 9a12fa5 commit 6a97c4d

16 files changed

Lines changed: 115 additions & 31 deletions

File tree

arch/arm64/kvm/arm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
555555
kvm_destroy_mpidr_data(vcpu->kvm);
556556

557557
err = kvm_vgic_vcpu_init(vcpu);
558-
if (err)
558+
if (err) {
559+
kvm_vgic_vcpu_destroy(vcpu);
559560
return err;
561+
}
560562

561563
err = kvm_share_hyp(vcpu, vcpu + 1);
562564
if (err)

arch/arm64/kvm/hyp/nvhe/trace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,16 @@ static int hyp_trace_buffer_load(struct hyp_trace_buffer *trace_buffer,
164164
return ret;
165165
}
166166

167-
static bool hyp_trace_desc_validate(struct hyp_trace_desc *desc, size_t desc_size)
167+
static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_size)
168168
{
169169
struct ring_buffer_desc *rb_desc;
170170
unsigned int cpu;
171171
size_t nr_bpages;
172172
void *desc_end;
173173

174+
if (!is_protected_kvm_enabled())
175+
return true;
176+
174177
/*
175178
* Both desc_size and bpages_backing_size are untrusted host-provided
176179
* values. We rely on __pkvm_host_donate_hyp() to enforce their validity.
@@ -212,8 +215,10 @@ int __tracing_load(unsigned long desc_hva, size_t desc_size)
212215
if (ret)
213216
return ret;
214217

215-
if (!hyp_trace_desc_validate(desc, desc_size))
218+
if (!hyp_trace_desc_is_valid(desc, desc_size)) {
219+
ret = -EINVAL;
216220
goto err_release_desc;
221+
}
217222

218223
hyp_spin_lock(&trace_buffer.lock);
219224

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,10 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,
23072307
/* dte entry is valid */
23082308
offset = (entry & KVM_ITS_DTE_NEXT_MASK) >> KVM_ITS_DTE_NEXT_SHIFT;
23092309

2310+
/* Mimic the MAPD behaviour and reject invalid EID bits. */
2311+
if (num_eventid_bits > VITS_TYPER_IDBITS)
2312+
return -EINVAL;
2313+
23102314
if (!vgic_its_check_id(its, baser, id, NULL))
23112315
return -EINVAL;
23122316

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;

arch/s390/kvm/dat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ static int dat_split_ste(struct kvm_s390_mmu_cache *mc, union pmd *pmdp, gfn_t g
267267
/* No need to take locks as the page table is not installed yet. */
268268
pgste_init.prefix_notif = old.s.fc1.prefix_notif;
269269
pgste_init.vsie_notif = old.s.fc1.vsie_notif;
270+
pgste_init.vsie_gmem = old.s.fc1.vsie_notif;
270271
pgste_init.pcl = uses_skeys && init.h.i;
271272
dat_init_pgstes(pt, pgste_init.val);
272273
} else {

arch/s390/kvm/dat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ union pgste {
145145
unsigned long cmma_d : 1; /* Dirty flag for CMMA bits */
146146
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
147147
unsigned long vsie_notif : 1; /* Referenced in a shadow table */
148-
unsigned long : 5;
148+
unsigned long vsie_gmem : 1; /* Contains nested guest memory */
149+
unsigned long : 4;
149150
unsigned long : 8;
150151
};
151152
struct {

arch/s390/kvm/gaccess.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
14451445
} else {
14461446
pgste = _gmap_ptep_xchg(sg->parent, ptep_h, newpte, pgste, f->gfn, false);
14471447
pgste.vsie_notif = 1;
1448+
pgste.vsie_gmem = 1;
14481449
}
14491450
pgste_set_unlock(ptep_h, pgste);
14501451
if (rc)

0 commit comments

Comments
 (0)