.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright 2012 Michael Ellerman, IBM Corporation. |
---|
3 | 4 | * Copyright 2012 Benjamin Herrenschmidt, IBM Corporation. |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License, version 2, as |
---|
7 | | - * published by the Free Software Foundation. |
---|
8 | 5 | */ |
---|
9 | 6 | |
---|
10 | 7 | #include <linux/kernel.h> |
---|
.. | .. |
---|
310 | 307 | */ |
---|
311 | 308 | if (new.out_ee) { |
---|
312 | 309 | kvmppc_book3s_queue_irqprio(icp->vcpu, |
---|
313 | | - BOOK3S_INTERRUPT_EXTERNAL_LEVEL); |
---|
| 310 | + BOOK3S_INTERRUPT_EXTERNAL); |
---|
314 | 311 | if (!change_self) |
---|
315 | 312 | kvmppc_fast_vcpu_kick(icp->vcpu); |
---|
316 | 313 | } |
---|
.. | .. |
---|
593 | 590 | u32 xirr; |
---|
594 | 591 | |
---|
595 | 592 | /* First, remove EE from the processor */ |
---|
596 | | - kvmppc_book3s_dequeue_irqprio(icp->vcpu, |
---|
597 | | - BOOK3S_INTERRUPT_EXTERNAL_LEVEL); |
---|
| 593 | + kvmppc_book3s_dequeue_irqprio(icp->vcpu, BOOK3S_INTERRUPT_EXTERNAL); |
---|
598 | 594 | |
---|
599 | 595 | /* |
---|
600 | 596 | * ICP State: Accept_Interrupt |
---|
.. | .. |
---|
754 | 750 | * We can remove EE from the current processor, the update |
---|
755 | 751 | * transaction will set it again if needed |
---|
756 | 752 | */ |
---|
757 | | - kvmppc_book3s_dequeue_irqprio(icp->vcpu, |
---|
758 | | - BOOK3S_INTERRUPT_EXTERNAL_LEVEL); |
---|
| 753 | + kvmppc_book3s_dequeue_irqprio(icp->vcpu, BOOK3S_INTERRUPT_EXTERNAL); |
---|
759 | 754 | |
---|
760 | 755 | do { |
---|
761 | 756 | old_state = new_state = READ_ONCE(icp->state); |
---|
.. | .. |
---|
832 | 827 | * |
---|
833 | 828 | * Note: If EOI is incorrectly used by SW to lower the CPPR |
---|
834 | 829 | * value (ie more favored), we do not check for rejection of |
---|
835 | | - * a pending interrupt, this is a SW error and PAPR sepcifies |
---|
| 830 | + * a pending interrupt, this is a SW error and PAPR specifies |
---|
836 | 831 | * that we don't have to deal with it. |
---|
837 | 832 | * |
---|
838 | 833 | * The sending of an EOI to the ICS is handled after the |
---|
.. | .. |
---|
1017 | 1012 | return 0; |
---|
1018 | 1013 | } |
---|
1019 | 1014 | |
---|
1020 | | -static int xics_debug_open(struct inode *inode, struct file *file) |
---|
1021 | | -{ |
---|
1022 | | - return single_open(file, xics_debug_show, inode->i_private); |
---|
1023 | | -} |
---|
1024 | | - |
---|
1025 | | -static const struct file_operations xics_debug_fops = { |
---|
1026 | | - .open = xics_debug_open, |
---|
1027 | | - .read = seq_read, |
---|
1028 | | - .llseek = seq_lseek, |
---|
1029 | | - .release = single_release, |
---|
1030 | | -}; |
---|
| 1015 | +DEFINE_SHOW_ATTRIBUTE(xics_debug); |
---|
1031 | 1016 | |
---|
1032 | 1017 | static void xics_debugfs_init(struct kvmppc_xics *xics) |
---|
1033 | 1018 | { |
---|
.. | .. |
---|
1167 | 1152 | * Deassert the CPU interrupt request. |
---|
1168 | 1153 | * icp_try_update will reassert it if necessary. |
---|
1169 | 1154 | */ |
---|
1170 | | - kvmppc_book3s_dequeue_irqprio(icp->vcpu, |
---|
1171 | | - BOOK3S_INTERRUPT_EXTERNAL_LEVEL); |
---|
| 1155 | + kvmppc_book3s_dequeue_irqprio(icp->vcpu, BOOK3S_INTERRUPT_EXTERNAL); |
---|
1172 | 1156 | |
---|
1173 | 1157 | /* |
---|
1174 | 1158 | * Note that if we displace an interrupt from old_state.xisr, |
---|
.. | .. |
---|
1350 | 1334 | return -ENXIO; |
---|
1351 | 1335 | } |
---|
1352 | 1336 | |
---|
1353 | | -static void kvmppc_xics_free(struct kvm_device *dev) |
---|
| 1337 | +/* |
---|
| 1338 | + * Called when device fd is closed. kvm->lock is held. |
---|
| 1339 | + */ |
---|
| 1340 | +static void kvmppc_xics_release(struct kvm_device *dev) |
---|
1354 | 1341 | { |
---|
1355 | 1342 | struct kvmppc_xics *xics = dev->private; |
---|
1356 | 1343 | int i; |
---|
1357 | 1344 | struct kvm *kvm = xics->kvm; |
---|
| 1345 | + struct kvm_vcpu *vcpu; |
---|
| 1346 | + |
---|
| 1347 | + pr_devel("Releasing xics device\n"); |
---|
| 1348 | + |
---|
| 1349 | + /* |
---|
| 1350 | + * Since this is the device release function, we know that |
---|
| 1351 | + * userspace does not have any open fd referring to the |
---|
| 1352 | + * device. Therefore there can not be any of the device |
---|
| 1353 | + * attribute set/get functions being executed concurrently, |
---|
| 1354 | + * and similarly, the connect_vcpu and set/clr_mapped |
---|
| 1355 | + * functions also cannot be being executed. |
---|
| 1356 | + */ |
---|
1358 | 1357 | |
---|
1359 | 1358 | debugfs_remove(xics->dentry); |
---|
| 1359 | + |
---|
| 1360 | + /* |
---|
| 1361 | + * We should clean up the vCPU interrupt presenters first. |
---|
| 1362 | + */ |
---|
| 1363 | + kvm_for_each_vcpu(i, vcpu, kvm) { |
---|
| 1364 | + /* |
---|
| 1365 | + * Take vcpu->mutex to ensure that no one_reg get/set ioctl |
---|
| 1366 | + * (i.e. kvmppc_xics_[gs]et_icp) can be done concurrently. |
---|
| 1367 | + * Holding the vcpu->mutex also means that execution is |
---|
| 1368 | + * excluded for the vcpu until the ICP was freed. When the vcpu |
---|
| 1369 | + * can execute again, vcpu->arch.icp and vcpu->arch.irq_type |
---|
| 1370 | + * have been cleared and the vcpu will not be going into the |
---|
| 1371 | + * XICS code anymore. |
---|
| 1372 | + */ |
---|
| 1373 | + mutex_lock(&vcpu->mutex); |
---|
| 1374 | + kvmppc_xics_free_icp(vcpu); |
---|
| 1375 | + mutex_unlock(&vcpu->mutex); |
---|
| 1376 | + } |
---|
1360 | 1377 | |
---|
1361 | 1378 | if (kvm) |
---|
1362 | 1379 | kvm->arch.xics = NULL; |
---|
1363 | 1380 | |
---|
1364 | | - for (i = 0; i <= xics->max_icsid; i++) |
---|
| 1381 | + for (i = 0; i <= xics->max_icsid; i++) { |
---|
1365 | 1382 | kfree(xics->ics[i]); |
---|
1366 | | - kfree(xics); |
---|
| 1383 | + xics->ics[i] = NULL; |
---|
| 1384 | + } |
---|
| 1385 | + /* |
---|
| 1386 | + * A reference of the kvmppc_xics pointer is now kept under |
---|
| 1387 | + * the xics_device pointer of the machine for reuse. It is |
---|
| 1388 | + * freed when the VM is destroyed for now until we fix all the |
---|
| 1389 | + * execution paths. |
---|
| 1390 | + */ |
---|
1367 | 1391 | kfree(dev); |
---|
| 1392 | +} |
---|
| 1393 | + |
---|
| 1394 | +static struct kvmppc_xics *kvmppc_xics_get_device(struct kvm *kvm) |
---|
| 1395 | +{ |
---|
| 1396 | + struct kvmppc_xics **kvm_xics_device = &kvm->arch.xics_device; |
---|
| 1397 | + struct kvmppc_xics *xics = *kvm_xics_device; |
---|
| 1398 | + |
---|
| 1399 | + if (!xics) { |
---|
| 1400 | + xics = kzalloc(sizeof(*xics), GFP_KERNEL); |
---|
| 1401 | + *kvm_xics_device = xics; |
---|
| 1402 | + } else { |
---|
| 1403 | + memset(xics, 0, sizeof(*xics)); |
---|
| 1404 | + } |
---|
| 1405 | + |
---|
| 1406 | + return xics; |
---|
1368 | 1407 | } |
---|
1369 | 1408 | |
---|
1370 | 1409 | static int kvmppc_xics_create(struct kvm_device *dev, u32 type) |
---|
1371 | 1410 | { |
---|
1372 | 1411 | struct kvmppc_xics *xics; |
---|
1373 | 1412 | struct kvm *kvm = dev->kvm; |
---|
1374 | | - int ret = 0; |
---|
1375 | 1413 | |
---|
1376 | | - xics = kzalloc(sizeof(*xics), GFP_KERNEL); |
---|
| 1414 | + pr_devel("Creating xics for partition\n"); |
---|
| 1415 | + |
---|
| 1416 | + /* Already there ? */ |
---|
| 1417 | + if (kvm->arch.xics) |
---|
| 1418 | + return -EEXIST; |
---|
| 1419 | + |
---|
| 1420 | + xics = kvmppc_xics_get_device(kvm); |
---|
1377 | 1421 | if (!xics) |
---|
1378 | 1422 | return -ENOMEM; |
---|
1379 | 1423 | |
---|
1380 | 1424 | dev->private = xics; |
---|
1381 | 1425 | xics->dev = dev; |
---|
1382 | 1426 | xics->kvm = kvm; |
---|
1383 | | - |
---|
1384 | | - /* Already there ? */ |
---|
1385 | | - if (kvm->arch.xics) |
---|
1386 | | - ret = -EEXIST; |
---|
1387 | | - else |
---|
1388 | | - kvm->arch.xics = xics; |
---|
1389 | | - |
---|
1390 | | - if (ret) { |
---|
1391 | | - kfree(xics); |
---|
1392 | | - return ret; |
---|
1393 | | - } |
---|
| 1427 | + kvm->arch.xics = xics; |
---|
1394 | 1428 | |
---|
1395 | 1429 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
---|
1396 | | - if (cpu_has_feature(CPU_FTR_ARCH_206)) { |
---|
| 1430 | + if (cpu_has_feature(CPU_FTR_ARCH_206) && |
---|
| 1431 | + cpu_has_feature(CPU_FTR_HVMODE)) { |
---|
1397 | 1432 | /* Enable real mode support */ |
---|
1398 | 1433 | xics->real_mode = ENABLE_REALMODE; |
---|
1399 | 1434 | xics->real_mode_dbg = DEBUG_REALMODE; |
---|
.. | .. |
---|
1414 | 1449 | .name = "kvm-xics", |
---|
1415 | 1450 | .create = kvmppc_xics_create, |
---|
1416 | 1451 | .init = kvmppc_xics_init, |
---|
1417 | | - .destroy = kvmppc_xics_free, |
---|
| 1452 | + .release = kvmppc_xics_release, |
---|
1418 | 1453 | .set_attr = xics_set_attr, |
---|
1419 | 1454 | .get_attr = xics_get_attr, |
---|
1420 | 1455 | .has_attr = xics_has_attr, |
---|
.. | .. |
---|
1430 | 1465 | return -EPERM; |
---|
1431 | 1466 | if (xics->kvm != vcpu->kvm) |
---|
1432 | 1467 | return -EPERM; |
---|
1433 | | - if (vcpu->arch.irq_type) |
---|
| 1468 | + if (vcpu->arch.irq_type != KVMPPC_IRQ_DEFAULT) |
---|
1434 | 1469 | return -EBUSY; |
---|
1435 | 1470 | |
---|
1436 | 1471 | r = kvmppc_xics_create_icp(vcpu, xcpu); |
---|