Skip to content

Commit 023e9fd

Browse files
chazyrkrcmar
authored andcommitted
KVM: PPC: Move xics_debugfs_init out of create
As we are about to hold the kvm->lock during the create operation on KVM devices, we should move the call to xics_debugfs_init into its own function, since holding a mutex over extended amounts of time might not be a good idea. Introduce an init operation on the kvm_device_ops struct which cannot fail and call this, if configured, after the device has been created. Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
1 parent 29b4817 commit 023e9fd

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

arch/powerpc/kvm/book3s_xics.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,6 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
13411341
return ret;
13421342
}
13431343

1344-
xics_debugfs_init(xics);
1345-
13461344
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
13471345
if (cpu_has_feature(CPU_FTR_ARCH_206)) {
13481346
/* Enable real mode support */
@@ -1354,9 +1352,17 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
13541352
return 0;
13551353
}
13561354

1355+
static void kvmppc_xics_init(struct kvm_device *dev)
1356+
{
1357+
struct kvmppc_xics *xics = (struct kvmppc_xics *)dev->private;
1358+
1359+
xics_debugfs_init(xics);
1360+
}
1361+
13571362
struct kvm_device_ops kvm_xics_ops = {
13581363
.name = "kvm-xics",
13591364
.create = kvmppc_xics_create,
1365+
.init = kvmppc_xics_init,
13601366
.destroy = kvmppc_xics_free,
13611367
.set_attr = xics_set_attr,
13621368
.get_attr = xics_get_attr,

include/linux/kvm_host.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,12 @@ struct kvm_device_ops {
11151115
const char *name;
11161116
int (*create)(struct kvm_device *dev, u32 type);
11171117

1118+
/*
1119+
* init is called after create if create is successful and is called
1120+
* outside of holding kvm->lock.
1121+
*/
1122+
void (*init)(struct kvm_device *dev);
1123+
11181124
/*
11191125
* Destroy is responsible for freeing dev.
11201126
*

virt/kvm/kvm_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,9 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
28382838
return ret;
28392839
}
28402840

2841+
if (ops->init)
2842+
ops->init(dev);
2843+
28412844
ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
28422845
if (ret < 0) {
28432846
ops->destroy(dev);

0 commit comments

Comments
 (0)