History

PCI: Allow per function PCI slots to fix slot reset on s390

On s390 systems, which use a machine level hypervisor, PCI devices are always accessed through a form of PCI pass-through which fundamentally operates on a per PCI function granularity. This is also reflected in the s390 PCI hotplug driver which creates hotplug slots for individual PCI functions. Its reset_slot() function, which is a wrapper for zpci_hot_reset_device(), thus also resets individual functions. Currently, the pci_create_slot() assigns the same pci_slot object to multifunction devices. This approach worked fine on s390 systems that only exposed virtual functions as individual PCI domains to the operating system. Since commit 44510d6fa0c0 ("s390/pci: Handling multifunctions") s390 supports exposing the topology of multifunction PCI devices by grouping them in a shared PCI domain. This creates a problem when resetting a function through the hotplug driver's slot_reset() interface. When attempting to reset a function through the hotplug driver, the shared slot assignment causes the wrong function to be reset instead of the intended one. It also leaks memory as we do create a pci_slot object for the function, but don't correctly free it in pci_slot_release(). Add a flag for struct pci_slot to allow per function PCI slots for functions managed through a hypervisor, which exposes individual PCI functions while retaining the topology. Since we can use all 8 bits for slot 'number' (for ARI devices), change slot 'number' u16 to account for special values PCI_SLOT_PLACEHOLDER and PCI_SLOT_ALL_DEVICES.

Farhan Ali committed 3 months ago

Commit dcc5bec1 parent c243e6c3 files · +30 −11Browse files

Unified · Split

3 files
  1. drivers/pci/pci.c +3 −2
  2. drivers/pci/slot.c +23 −6
  3. include/linux/pci.h +4 −3
drivers/pci/pci.c+3−2
@@ -4897,8 +4897,9 @@ static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, bool probe) · 4896 unmodified lines
48974897
48984898 static int pci_dev_reset_slot_function(struct pci_dev *dev, bool probe)
48994899 {
4900− if (dev->multifunction || dev->subordinate || !dev->slot ||
4901− dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
4900+ if (dev->subordinate || !dev->slot ||
4901+ dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET ||
4902+ (dev->multifunction && !dev->slot->per_func_slot))
49024903 return -ENOTTY;
49034904
49044905 return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
drivers/pci/slot.c+23−6
@@ -72,6 +72,23 @@ static ssize_t cur_speed_read_file(struct pci_slot *slot, char *buf) · 71 unmodified lines
7272 return bus_speed_read(slot->bus->cur_bus_speed, buf);
7373 }
7474
75+static bool pci_dev_matches_slot(struct pci_dev *dev, struct pci_slot *slot)
76+{
77+ if (slot->per_func_slot)
78+ return dev->devfn == slot->number;
79+
80+ return slot->number == PCI_SLOT_ALL_DEVICES ||
81+ PCI_SLOT(dev->devfn) == slot->number;
82+}
83+
84+static bool pci_slot_enabled_per_func(void)
85+{
86+ if (IS_ENABLED(CONFIG_S390))
87+ return true;
88+
89+ return false;
90+}
91+
7592 static void pci_slot_release(struct kobject *kobj)
7693 {
7794 struct pci_dev *dev;
@@ -82,8 +99,7 @@ static void pci_slot_release(struct kobject *kobj) · 4 unmodified lines
8299
83100 down_read(&pci_bus_sem);
84101 list_for_each_entry(dev, &slot->bus->devices, bus_list)
85− if (slot->number == PCI_SLOT_ALL_DEVICES ||
86− PCI_SLOT(dev->devfn) == slot->number)
102+ if (pci_dev_matches_slot(dev, slot))
87103 dev->slot = NULL;
88104 up_read(&pci_bus_sem);
89105
@@ -187,8 +203,7 @@ void pci_dev_assign_slot(struct pci_dev *dev) · 97 unmodified lines
187203
188204 mutex_lock(&pci_slot_mutex);
189205 list_for_each_entry(slot, &dev->bus->slots, list)
190− if (slot->number == PCI_SLOT_ALL_DEVICES ||
191− PCI_SLOT(dev->devfn) == slot->number)
206+ if (pci_dev_matches_slot(dev, slot))
192207 dev->slot = slot;
193208 mutex_unlock(&pci_slot_mutex);
194209 }
@@ -299,6 +314,9 @@ placeholder: · 104 unmodified lines
299314 slot->bus = pci_bus_get(parent);
300315 slot->number = slot_nr;
301316
317+ if (pci_slot_enabled_per_func())
318+ slot->per_func_slot = 1;
319+
302320 slot->kobj.kset = pci_slots_kset;
303321
304322 slot_name = make_slot_name(name);
@@ -319,8 +337,7 @@ placeholder: · 14 unmodified lines
319337
320338 down_read(&pci_bus_sem);
321339 list_for_each_entry(dev, &parent->devices, bus_list)
322− if (slot_nr == PCI_SLOT_ALL_DEVICES ||
323− PCI_SLOT(dev->devfn) == slot_nr)
340+ if (pci_dev_matches_slot(dev, slot))
324341 dev->slot = slot;
325342 up_read(&pci_bus_sem);
326343
include/linux/pci.h+4−3
@@ -79,17 +79,18 @@ · 78 unmodified lines
7979 * and, if ARI Forwarding is enabled, functions may appear to be on multiple
8080 * devices.
8181 */
82−#define PCI_SLOT_ALL_DEVICES 0xfe
82+#define PCI_SLOT_ALL_DEVICES 0xfeff
8383
8484 /* Used to identify a slot as a placeholder */
85−#define PCI_SLOT_PLACEHOLDER 0xff
85+#define PCI_SLOT_PLACEHOLDER 0xffff
8686
8787 /* pci_slot represents a physical slot */
8888 struct pci_slot {
8989 struct pci_bus *bus; /* Bus this slot is on */
9090 struct list_head list; /* Node in list of slots */
9191 struct hotplug_slot *hotplug; /* Hotplug info (move here) */
92− unsigned char number; /* Device nr, or PCI_SLOT_ALL_DEVICES */
92+ u16 number; /* Device nr, or PCI_SLOT_ALL_DEVICES */
93+ unsigned int per_func_slot:1; /* Allow per function slot */
9394 struct kobject kobj;
9495 };
9596

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t