Skip to content

Commit 5c2b217

Browse files
committed
Merge tag 'kvmarm-fixes-6.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into kvm-master
KVM/arm64 fixes for 6.7, part #2 - Ensure a vCPU's redistributor is unregistered from the MMIO bus if vCPU creation fails - Fix building KVM selftests for arm64 from the top-level Makefile
2 parents a26b7cd + 0c12e6c commit 5c2b217

File tree

6 files changed

+52
-31
lines changed

6 files changed

+52
-31
lines changed

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
410410
kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache);
411411
kvm_timer_vcpu_terminate(vcpu);
412412
kvm_pmu_vcpu_destroy(vcpu);
413-
413+
kvm_vgic_vcpu_destroy(vcpu);
414414
kvm_arm_vcpu_destroy(vcpu);
415415
}
416416

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static void kvm_vgic_dist_destroy(struct kvm *kvm)
368368
vgic_v4_teardown(kvm);
369369
}
370370

371-
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
371+
static void __kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
372372
{
373373
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
374374

@@ -379,29 +379,39 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
379379
vgic_flush_pending_lpis(vcpu);
380380

381381
INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
382-
vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF;
382+
if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
383+
vgic_unregister_redist_iodev(vcpu);
384+
vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF;
385+
}
383386
}
384387

385-
static void __kvm_vgic_destroy(struct kvm *kvm)
388+
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
389+
{
390+
struct kvm *kvm = vcpu->kvm;
391+
392+
mutex_lock(&kvm->slots_lock);
393+
__kvm_vgic_vcpu_destroy(vcpu);
394+
mutex_unlock(&kvm->slots_lock);
395+
}
396+
397+
void kvm_vgic_destroy(struct kvm *kvm)
386398
{
387399
struct kvm_vcpu *vcpu;
388400
unsigned long i;
389401

390-
lockdep_assert_held(&kvm->arch.config_lock);
402+
mutex_lock(&kvm->slots_lock);
391403

392404
vgic_debug_destroy(kvm);
393405

394406
kvm_for_each_vcpu(i, vcpu, kvm)
395-
kvm_vgic_vcpu_destroy(vcpu);
407+
__kvm_vgic_vcpu_destroy(vcpu);
408+
409+
mutex_lock(&kvm->arch.config_lock);
396410

397411
kvm_vgic_dist_destroy(kvm);
398-
}
399412

400-
void kvm_vgic_destroy(struct kvm *kvm)
401-
{
402-
mutex_lock(&kvm->arch.config_lock);
403-
__kvm_vgic_destroy(kvm);
404413
mutex_unlock(&kvm->arch.config_lock);
414+
mutex_unlock(&kvm->slots_lock);
405415
}
406416

407417
/**
@@ -469,25 +479,26 @@ int kvm_vgic_map_resources(struct kvm *kvm)
469479
type = VGIC_V3;
470480
}
471481

472-
if (ret) {
473-
__kvm_vgic_destroy(kvm);
482+
if (ret)
474483
goto out;
475-
}
484+
476485
dist->ready = true;
477486
dist_base = dist->vgic_dist_base;
478487
mutex_unlock(&kvm->arch.config_lock);
479488

480489
ret = vgic_register_dist_iodev(kvm, dist_base, type);
481-
if (ret) {
490+
if (ret)
482491
kvm_err("Unable to register VGIC dist MMIO regions\n");
483-
kvm_vgic_destroy(kvm);
484-
}
485-
mutex_unlock(&kvm->slots_lock);
486-
return ret;
487492

493+
goto out_slots;
488494
out:
489495
mutex_unlock(&kvm->arch.config_lock);
496+
out_slots:
490497
mutex_unlock(&kvm->slots_lock);
498+
499+
if (ret)
500+
kvm_vgic_destroy(kvm);
501+
491502
return ret;
492503
}
493504

arch/arm64/kvm/vgic/vgic-mmio-v3.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu)
820820
return ret;
821821
}
822822

823-
static void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
823+
void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
824824
{
825825
struct vgic_io_device *rd_dev = &vcpu->arch.vgic_cpu.rd_iodev;
826826

@@ -833,6 +833,8 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm)
833833
unsigned long c;
834834
int ret = 0;
835835

836+
lockdep_assert_held(&kvm->slots_lock);
837+
836838
kvm_for_each_vcpu(c, vcpu, kvm) {
837839
ret = vgic_register_redist_iodev(vcpu);
838840
if (ret)

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq);
241241
int vgic_v3_save_pending_tables(struct kvm *kvm);
242242
int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count);
243243
int vgic_register_redist_iodev(struct kvm_vcpu *vcpu);
244+
void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu);
244245
bool vgic_v3_check_base(struct kvm *kvm);
245246

246247
void vgic_v3_load(struct kvm_vcpu *vcpu);

tools/testing/selftests/kvm/Makefile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ else
1717
ARCH_DIR := $(ARCH)
1818
endif
1919

20-
ifeq ($(ARCH),arm64)
21-
tools_dir := $(top_srcdir)/tools
22-
arm64_tools_dir := $(tools_dir)/arch/arm64/tools/
23-
GEN_HDRS := $(top_srcdir)/tools/arch/arm64/include/generated/
24-
CFLAGS += -I$(GEN_HDRS)
25-
26-
$(GEN_HDRS): $(wildcard $(arm64_tools_dir)/*)
27-
$(MAKE) -C $(arm64_tools_dir) O=$(tools_dir)
28-
endif
29-
3020
LIBKVM += lib/assert.c
3121
LIBKVM += lib/elf.c
3222
LIBKVM += lib/guest_modes.c
@@ -234,6 +224,22 @@ CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
234224
ifeq ($(ARCH),s390)
235225
CFLAGS += -march=z10
236226
endif
227+
ifeq ($(ARCH),arm64)
228+
tools_dir := $(top_srcdir)/tools
229+
arm64_tools_dir := $(tools_dir)/arch/arm64/tools/
230+
231+
ifneq ($(abs_objdir),)
232+
arm64_hdr_outdir := $(abs_objdir)/tools/
233+
else
234+
arm64_hdr_outdir := $(tools_dir)/
235+
endif
236+
237+
GEN_HDRS := $(arm64_hdr_outdir)arch/arm64/include/generated/
238+
CFLAGS += -I$(GEN_HDRS)
239+
240+
$(GEN_HDRS): $(wildcard $(arm64_tools_dir)/*)
241+
$(MAKE) -C $(arm64_tools_dir) OUTPUT=$(arm64_hdr_outdir)
242+
endif
237243

238244
no-pie-option := $(call try-run, echo 'int main(void) { return 0; }' | \
239245
$(CC) -Werror $(CFLAGS) -no-pie -x c - -o "$$TMP", -no-pie)

virt/kvm/kvm_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5540,14 +5540,15 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
55405540
return r < 0 ? r : 0;
55415541
}
55425542

5543-
/* Caller must hold slots_lock. */
55445543
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
55455544
int len, struct kvm_io_device *dev)
55465545
{
55475546
int i;
55485547
struct kvm_io_bus *new_bus, *bus;
55495548
struct kvm_io_range range;
55505549

5550+
lockdep_assert_held(&kvm->slots_lock);
5551+
55515552
bus = kvm_get_bus(kvm, bus_idx);
55525553
if (!bus)
55535554
return -ENOMEM;

0 commit comments

Comments
 (0)