Skip to content

Commit b057878

Browse files
jgross1David Vrabel
authored andcommitted
xen/pciback: support driver_override
Support the driver_override scheme introduced with commit 782a985 ("PCI: Introduce new device binding path using pci_dev.driver_override") As pcistub_probe() is called for all devices (it has to check for a match based on the slot address rather than device type) it has to check for driver_override set to "pciback" itself. Up to now for assigning a pci device to pciback you need something like: echo 0000:07:10.0 > /sys/bus/pci/devices/0000\:07\:10.0/driver/unbind echo 0000:07:10.0 > /sys/bus/pci/drivers/pciback/new_slot echo 0000:07:10.0 > /sys/bus/pci/drivers_probe while with the patch you can use the same mechanism as for similar drivers like pci-stub and vfio-pci: echo pciback > /sys/bus/pci/devices/0000\:07\:10.0/driver_override echo 0000:07:10.0 > /sys/bus/pci/devices/0000\:07\:10.0/driver/unbind echo 0000:07:10.0 > /sys/bus/pci/drivers_probe So e.g. libvirt doesn't need special handling for pciback. Signed-off-by: Juergen Gross <[email protected]> Signed-off-by: David Vrabel <[email protected]>
1 parent 9f8bee9 commit b057878

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

drivers/xen/xen-pciback/pci_stub.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "conf_space.h"
2626
#include "conf_space_quirks.h"
2727

28+
#define PCISTUB_DRIVER_NAME "pciback"
29+
2830
static char *pci_devs_to_hide;
2931
wait_queue_head_t xen_pcibk_aer_wait_queue;
3032
/*Add sem for sync AER handling and xen_pcibk remove/reconfigue ops,
@@ -508,15 +510,18 @@ static void pcistub_device_id_add_list(struct pcistub_device_id *new,
508510
kfree(new);
509511
}
510512

511-
static int pcistub_seize(struct pci_dev *dev)
513+
static int pcistub_seize(struct pci_dev *dev,
514+
struct pcistub_device_id *pci_dev_id)
512515
{
513516
struct pcistub_device *psdev;
514517
unsigned long flags;
515518
int err = 0;
516519

517520
psdev = pcistub_device_alloc(dev);
518-
if (!psdev)
521+
if (!psdev) {
522+
kfree(pci_dev_id);
519523
return -ENOMEM;
524+
}
520525

521526
spin_lock_irqsave(&pcistub_devices_lock, flags);
522527

@@ -537,8 +542,12 @@ static int pcistub_seize(struct pci_dev *dev)
537542

538543
spin_unlock_irqrestore(&pcistub_devices_lock, flags);
539544

540-
if (err)
545+
if (err) {
546+
kfree(pci_dev_id);
541547
pcistub_device_put(psdev);
548+
} else if (pci_dev_id)
549+
pcistub_device_id_add_list(pci_dev_id, pci_domain_nr(dev->bus),
550+
dev->bus->number, dev->devfn);
542551

543552
return err;
544553
}
@@ -547,11 +556,16 @@ static int pcistub_seize(struct pci_dev *dev)
547556
* other functions that take the sysfs lock. */
548557
static int pcistub_probe(struct pci_dev *dev, const struct pci_device_id *id)
549558
{
550-
int err = 0;
559+
int err = 0, match;
560+
struct pcistub_device_id *pci_dev_id = NULL;
551561

552562
dev_dbg(&dev->dev, "probing...\n");
553563

554-
if (pcistub_match(dev)) {
564+
match = pcistub_match(dev);
565+
566+
if ((dev->driver_override &&
567+
!strcmp(dev->driver_override, PCISTUB_DRIVER_NAME)) ||
568+
match) {
555569

556570
if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL
557571
&& dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
@@ -562,8 +576,16 @@ static int pcistub_probe(struct pci_dev *dev, const struct pci_device_id *id)
562576
goto out;
563577
}
564578

579+
if (!match) {
580+
pci_dev_id = kmalloc(sizeof(*pci_dev_id), GFP_ATOMIC);
581+
if (!pci_dev_id) {
582+
err = -ENOMEM;
583+
goto out;
584+
}
585+
}
586+
565587
dev_info(&dev->dev, "seizing device\n");
566-
err = pcistub_seize(dev);
588+
err = pcistub_seize(dev, pci_dev_id);
567589
} else
568590
/* Didn't find the device */
569591
err = -ENODEV;
@@ -975,7 +997,7 @@ static const struct pci_error_handlers xen_pcibk_error_handler = {
975997
static struct pci_driver xen_pcibk_pci_driver = {
976998
/* The name should be xen_pciback, but until the tools are updated
977999
* we will keep it as pciback. */
978-
.name = "pciback",
1000+
.name = PCISTUB_DRIVER_NAME,
9791001
.id_table = pcistub_ids,
9801002
.probe = pcistub_probe,
9811003
.remove = pcistub_remove,

0 commit comments

Comments
 (0)