On Tue, 12 May 2026, Krzysztof Wilczyński wrote: > Hello, > > > pci_mmap_resource() does not check IORESOURCE_DISABLED before mapping > > a PCI BAR resource into userspace. This allows new mmaps to succeed > > even after a device has been marked disabled or soft-unplugged by the > > driver to prevent further access. > > Which driver disables resources? Would this be some Amazon-specific thing > you are trying to fix? Or are you just manually disabling a given device > using sysfs, or something like this? > > For "soft-unplugged" device we have pci_dev_set_disconnected(), but this > does not check current flags set. > > What is your use case here? > > > Add the check to return -ENODEV when the resource is disabled, blocking > > new userspace mmaps of BAR resources after device removal. > > > > Tested by marking the PCI BAR resource as disabled and verifying that > > a subsequent mmap attempt fails with -ENODEV. > > Can you explain how did you do this? > > > @@ -1089,6 +1089,9 @@ static int pci_mmap_resource(struct kobject *kobj, const struct bin_attribute *a > > if (ret) > > return ret; > > > > + if (res->flags & IORESOURCE_DISABLED) > > + return -ENODEV; > > + > > This probably would be better if it checked IORESOURCE_DISABLED and > IORESOURCE_UNSET, but then probably using resource_assigned() would > be even better. Yes, resource_assigned() makes more sense. When considering Krzysztof's sysfs rework series in pci/sysfs, this all should be handled in .is_visible and not in pci_mmap_resource(). Also (FYI), alpha has its own pci_mmap_resource() (IIRC, it still has it even after Krzysztof's series). -- i.