[PATCH 03/27] PCI: Protect against concurrent change of housekeeping cpumask

Frederic Weisbecker posted 27 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH 03/27] PCI: Protect against concurrent change of housekeeping cpumask
Posted by Frederic Weisbecker 3 months, 2 weeks ago
HK_TYPE_DOMAIN will soon integrate cpuset isolated partitions and
therefore be made modifyable at runtime. Synchronize against the cpumask
update using appropriate locking.

Queue and wait for the PCI call to complete while holding the
housekeeping rwsem. This way the housekeeping update side doesn't need
to propagate its changes to PCI.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 drivers/pci/pci-driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 67db34fd10ee..459d211a408b 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -362,7 +362,7 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
 	dev->is_probed = 1;
 
 	cpu_hotplug_disable();
-
+	housekeeping_lock();
 	/*
 	 * Prevent nesting work_on_cpu() for the case where a Virtual Function
 	 * device is probed from work_on_cpu() of the Physical device.
@@ -392,6 +392,7 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
 		error = local_pci_probe(&ddi);
 out:
 	dev->is_probed = 0;
+	housekeeping_unlock();
 	cpu_hotplug_enable();
 	return error;
 }
-- 
2.48.1
Re: [PATCH 03/27] PCI: Protect against concurrent change of housekeeping cpumask
Posted by Bjorn Helgaas 3 months, 2 weeks ago
On Fri, Jun 20, 2025 at 05:22:44PM +0200, Frederic Weisbecker wrote:
> HK_TYPE_DOMAIN will soon integrate cpuset isolated partitions and
> therefore be made modifyable at runtime. Synchronize against the cpumask
> update using appropriate locking.

s/modifyable/modifiable/

> Queue and wait for the PCI call to complete while holding the
> housekeeping rwsem. This way the housekeeping update side doesn't need
> to propagate its changes to PCI.

What PCI call are we waiting for?  I see housekeeping_lock(), but I
assume that's doing some housekeeping-related mutual exclusion, not
waiting for PCI work.

I don't know how to use housekeeping_lock() or when it's needed.  Can
you add some guidance here and at the housekeeping_lock() definition?

> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> ---
>  drivers/pci/pci-driver.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 67db34fd10ee..459d211a408b 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -362,7 +362,7 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
>  	dev->is_probed = 1;
>  
>  	cpu_hotplug_disable();
> -
> +	housekeeping_lock();
>  	/*
>  	 * Prevent nesting work_on_cpu() for the case where a Virtual Function
>  	 * device is probed from work_on_cpu() of the Physical device.
> @@ -392,6 +392,7 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
>  		error = local_pci_probe(&ddi);
>  out:
>  	dev->is_probed = 0;
> +	housekeeping_unlock();
>  	cpu_hotplug_enable();
>  	return error;
>  }
> -- 
> 2.48.1
>
Re: [PATCH 03/27] PCI: Protect against concurrent change of housekeeping cpumask
Posted by Frederic Weisbecker 3 months, 2 weeks ago
Le Fri, Jun 20, 2025 at 11:17:10AM -0500, Bjorn Helgaas a écrit :
> On Fri, Jun 20, 2025 at 05:22:44PM +0200, Frederic Weisbecker wrote:
> > HK_TYPE_DOMAIN will soon integrate cpuset isolated partitions and
> > therefore be made modifyable at runtime. Synchronize against the cpumask
> > update using appropriate locking.
> 
> s/modifyable/modifiable/
> 
> > Queue and wait for the PCI call to complete while holding the
> > housekeeping rwsem. This way the housekeeping update side doesn't need
> > to propagate its changes to PCI.
> 
> What PCI call are we waiting for?  I see housekeeping_lock(), but I
> assume that's doing some housekeeping-related mutual exclusion, not
> waiting for PCI work.

It's waiting for the call to work_on_cpu() to complete (along with
the CPU election through housekeeping_cpumask()).

> 
> I don't know how to use housekeeping_lock() or when it's needed.  Can
> you add some guidance here and at the housekeeping_lock() definition?

You're right, it's missing documentation, context and guidance. I'll
try to fill that in the next iteration. Also the lock is likely going
to be replaced by RCU instead.

Thanks.

-- 
Frederic Weisbecker
SUSE Labs