hc
2024-02-19 890e1df1bec891d9203724541e81f8fbe5183388
kernel/drivers/xen/xen-pciback/pci_stub.c
....@@ -6,6 +6,7 @@
66 */
77
88 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
+#define dev_fmt pr_fmt
910
1011 #include <linux/module.h>
1112 #include <linux/init.h>
....@@ -303,6 +304,8 @@
303304 /* And cleanup up our emulated fields. */
304305 xen_pcibk_config_reset_dev(dev);
305306 xen_pcibk_config_free_dyn_fields(dev);
307
+
308
+ dev_data->allow_interrupt_control = 0;
306309
307310 xen_unregister_device_domain_owner(dev);
308311
....@@ -624,11 +627,11 @@
624627 if (found_psdev->pdev) {
625628 int domid = xen_find_device_domain_owner(dev);
626629
627
- pr_warn("****** removing device %s while still in-use by domain %d! ******\n",
630
+ dev_warn(&dev->dev, "****** removing device %s while still in-use by domain %d! ******\n",
628631 pci_name(found_psdev->dev), domid);
629
- pr_warn("****** driver domain may still access this device's i/o resources!\n");
630
- pr_warn("****** shutdown driver domain before binding device\n");
631
- pr_warn("****** to other drivers or domains\n");
632
+ dev_warn(&dev->dev, "****** driver domain may still access this device's i/o resources!\n");
633
+ dev_warn(&dev->dev, "****** shutdown driver domain before binding device\n");
634
+ dev_warn(&dev->dev, "****** to other drivers or domains\n");
632635
633636 /* N.B. This ends up calling pcistub_put_pci_dev which ends up
634637 * doing the FLR. */
....@@ -709,14 +712,12 @@
709712 ret = xen_pcibk_get_pcifront_dev(psdev->dev, psdev->pdev,
710713 &aer_op->domain, &aer_op->bus, &aer_op->devfn);
711714 if (!ret) {
712
- dev_err(&psdev->dev->dev,
713
- DRV_NAME ": failed to get pcifront device\n");
715
+ dev_err(&psdev->dev->dev, "failed to get pcifront device\n");
714716 return PCI_ERS_RESULT_NONE;
715717 }
716718 wmb();
717719
718
- dev_dbg(&psdev->dev->dev,
719
- DRV_NAME ": aer_op %x dom %x bus %x devfn %x\n",
720
+ dev_dbg(&psdev->dev->dev, "aer_op %x dom %x bus %x devfn %x\n",
720721 aer_cmd, aer_op->domain, aer_op->bus, aer_op->devfn);
721722 /*local flag to mark there's aer request, xen_pcibk callback will use
722723 * this flag to judge whether we need to check pci-front give aer
....@@ -784,13 +785,12 @@
784785 PCI_FUNC(dev->devfn));
785786
786787 if (!psdev || !psdev->pdev) {
787
- dev_err(&dev->dev,
788
- DRV_NAME " device is not found/assigned\n");
788
+ dev_err(&dev->dev, "device is not found/assigned\n");
789789 goto end;
790790 }
791791
792792 if (!psdev->pdev->sh_info) {
793
- dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
793
+ dev_err(&dev->dev, "device is not connected or owned"
794794 " by HVM, kill it\n");
795795 kill_domain_by_device(psdev);
796796 goto end;
....@@ -842,13 +842,12 @@
842842 PCI_FUNC(dev->devfn));
843843
844844 if (!psdev || !psdev->pdev) {
845
- dev_err(&dev->dev,
846
- DRV_NAME " device is not found/assigned\n");
845
+ dev_err(&dev->dev, "device is not found/assigned\n");
847846 goto end;
848847 }
849848
850849 if (!psdev->pdev->sh_info) {
851
- dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
850
+ dev_err(&dev->dev, "device is not connected or owned"
852851 " by HVM, kill it\n");
853852 kill_domain_by_device(psdev);
854853 goto end;
....@@ -900,13 +899,12 @@
900899 PCI_FUNC(dev->devfn));
901900
902901 if (!psdev || !psdev->pdev) {
903
- dev_err(&dev->dev,
904
- DRV_NAME " device is not found/assigned\n");
902
+ dev_err(&dev->dev, "device is not found/assigned\n");
905903 goto end;
906904 }
907905
908906 if (!psdev->pdev->sh_info) {
909
- dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
907
+ dev_err(&dev->dev, "device is not connected or owned"
910908 " by HVM, kill it\n");
911909 kill_domain_by_device(psdev);
912910 goto end;
....@@ -954,13 +952,12 @@
954952 PCI_FUNC(dev->devfn));
955953
956954 if (!psdev || !psdev->pdev) {
957
- dev_err(&dev->dev,
958
- DRV_NAME " device is not found/assigned\n");
955
+ dev_err(&dev->dev, "device is not found/assigned\n");
959956 goto end;
960957 }
961958
962959 if (!psdev->pdev->sh_info) {
963
- dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
960
+ dev_err(&dev->dev, "device is not connected or owned"
964961 " by HVM, kill it\n");
965962 kill_domain_by_device(psdev);
966963 goto end;
....@@ -1431,6 +1428,65 @@
14311428 }
14321429 static DRIVER_ATTR_RW(permissive);
14331430
1431
+static ssize_t allow_interrupt_control_store(struct device_driver *drv,
1432
+ const char *buf, size_t count)
1433
+{
1434
+ int domain, bus, slot, func;
1435
+ int err;
1436
+ struct pcistub_device *psdev;
1437
+ struct xen_pcibk_dev_data *dev_data;
1438
+
1439
+ err = str_to_slot(buf, &domain, &bus, &slot, &func);
1440
+ if (err)
1441
+ goto out;
1442
+
1443
+ psdev = pcistub_device_find(domain, bus, slot, func);
1444
+ if (!psdev) {
1445
+ err = -ENODEV;
1446
+ goto out;
1447
+ }
1448
+
1449
+ dev_data = pci_get_drvdata(psdev->dev);
1450
+ /* the driver data for a device should never be null at this point */
1451
+ if (!dev_data) {
1452
+ err = -ENXIO;
1453
+ goto release;
1454
+ }
1455
+ dev_data->allow_interrupt_control = 1;
1456
+release:
1457
+ pcistub_device_put(psdev);
1458
+out:
1459
+ if (!err)
1460
+ err = count;
1461
+ return err;
1462
+}
1463
+
1464
+static ssize_t allow_interrupt_control_show(struct device_driver *drv,
1465
+ char *buf)
1466
+{
1467
+ struct pcistub_device *psdev;
1468
+ struct xen_pcibk_dev_data *dev_data;
1469
+ size_t count = 0;
1470
+ unsigned long flags;
1471
+
1472
+ spin_lock_irqsave(&pcistub_devices_lock, flags);
1473
+ list_for_each_entry(psdev, &pcistub_devices, dev_list) {
1474
+ if (count >= PAGE_SIZE)
1475
+ break;
1476
+ if (!psdev->dev)
1477
+ continue;
1478
+ dev_data = pci_get_drvdata(psdev->dev);
1479
+ if (!dev_data || !dev_data->allow_interrupt_control)
1480
+ continue;
1481
+ count +=
1482
+ scnprintf(buf + count, PAGE_SIZE - count, "%s\n",
1483
+ pci_name(psdev->dev));
1484
+ }
1485
+ spin_unlock_irqrestore(&pcistub_devices_lock, flags);
1486
+ return count;
1487
+}
1488
+static DRIVER_ATTR_RW(allow_interrupt_control);
1489
+
14341490 static void pcistub_exit(void)
14351491 {
14361492 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_new_slot);
....@@ -1440,6 +1496,8 @@
14401496 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_quirks);
14411497 driver_remove_file(&xen_pcibk_pci_driver.driver,
14421498 &driver_attr_permissive);
1499
+ driver_remove_file(&xen_pcibk_pci_driver.driver,
1500
+ &driver_attr_allow_interrupt_control);
14431501 driver_remove_file(&xen_pcibk_pci_driver.driver,
14441502 &driver_attr_irq_handlers);
14451503 driver_remove_file(&xen_pcibk_pci_driver.driver,
....@@ -1530,6 +1588,9 @@
15301588 if (!err)
15311589 err = driver_create_file(&xen_pcibk_pci_driver.driver,
15321590 &driver_attr_permissive);
1591
+ if (!err)
1592
+ err = driver_create_file(&xen_pcibk_pci_driver.driver,
1593
+ &driver_attr_allow_interrupt_control);
15331594
15341595 if (!err)
15351596 err = driver_create_file(&xen_pcibk_pci_driver.driver,