Patchwork [2/4] hotplug, x86: Add hotplug lock to missing places

login
register
mail settings
Submitter Toshi Kani
Date Aug. 17, 2013, 7:46 p.m.
Message ID <1376768819-28975-3-git-send-email-toshi.kani@hp.com>
Download mbox | patch
Permalink /patch/267999/
State Not Applicable
Headers show

Comments

Toshi Kani - Aug. 17, 2013, 7:46 p.m.
lock_device_hotplug() serializes CPU & Memory online/offline and hotplug
operations.  However, this lock is not held in the debug interfaces below
that initiate CPU online/offline operations.

 - _debug_hotplug_cpu(), cpu0 hotplug test interface enabled by
   CONFIG_DEBUG_HOTPLUG_CPU0.
 - cpu_probe_store() and cpu_release_store(), cpu hotplug test interface
   enabled by CONFIG_ARCH_CPU_PROBE_RELEASE.

This patch changes the above interfaces to hold lock_device_hotplug().

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
---
 arch/x86/kernel/topology.c |    2 ++
 drivers/base/cpu.c         |   16 ++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
Greg KH - Aug. 17, 2013, 11:15 p.m.
On Sat, Aug 17, 2013 at 01:46:57PM -0600, Toshi Kani wrote:
> lock_device_hotplug() serializes CPU & Memory online/offline and hotplug
> operations.  However, this lock is not held in the debug interfaces below
> that initiate CPU online/offline operations.
> 
>  - _debug_hotplug_cpu(), cpu0 hotplug test interface enabled by
>    CONFIG_DEBUG_HOTPLUG_CPU0.
>  - cpu_probe_store() and cpu_release_store(), cpu hotplug test interface
>    enabled by CONFIG_ARCH_CPU_PROBE_RELEASE.
> 
> This patch changes the above interfaces to hold lock_device_hotplug().
> 
> Signed-off-by: Toshi Kani <toshi.kani@hp.com>
> ---
>  arch/x86/kernel/topology.c |    2 ++
>  drivers/base/cpu.c         |   16 ++++++++++++++--
>  2 files changed, 16 insertions(+), 2 deletions(-)

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Rafael J. Wysocki - Aug. 18, 2013, 12:59 a.m.
On Saturday, August 17, 2013 01:46:57 PM Toshi Kani wrote:
> lock_device_hotplug() serializes CPU & Memory online/offline and hotplug
> operations.  However, this lock is not held in the debug interfaces below
> that initiate CPU online/offline operations.
> 
>  - _debug_hotplug_cpu(), cpu0 hotplug test interface enabled by
>    CONFIG_DEBUG_HOTPLUG_CPU0.
>  - cpu_probe_store() and cpu_release_store(), cpu hotplug test interface
>    enabled by CONFIG_ARCH_CPU_PROBE_RELEASE.
> 
> This patch changes the above interfaces to hold lock_device_hotplug().
> 
> Signed-off-by: Toshi Kani <toshi.kani@hp.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  arch/x86/kernel/topology.c |    2 ++
>  drivers/base/cpu.c         |   16 ++++++++++++++--
>  2 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c
> index 5823bbd..a3f35eb 100644
> --- a/arch/x86/kernel/topology.c
> +++ b/arch/x86/kernel/topology.c
> @@ -65,6 +65,7 @@ int __ref _debug_hotplug_cpu(int cpu, int action)
>  	if (!cpu_is_hotpluggable(cpu))
>  		return -EINVAL;
>  
> +	lock_device_hotplug();
>  	cpu_hotplug_driver_lock();
>  
>  	switch (action) {
> @@ -91,6 +92,7 @@ int __ref _debug_hotplug_cpu(int cpu, int action)
>  	}
>  
>  	cpu_hotplug_driver_unlock();
> +	unlock_device_hotplug();
>  
>  	return ret;
>  }
> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
> index 4c358bc..4cc6928 100644
> --- a/drivers/base/cpu.c
> +++ b/drivers/base/cpu.c
> @@ -88,7 +88,13 @@ static ssize_t cpu_probe_store(struct device *dev,
>  			       const char *buf,
>  			       size_t count)
>  {
> -	return arch_cpu_probe(buf, count);
> +	ssize_t ret;
> +
> +	lock_device_hotplug();
> +	ret = arch_cpu_probe(buf, count);
> +	unlock_device_hotplug();
> +
> +	return ret;
>  }
>  
>  static ssize_t cpu_release_store(struct device *dev,
> @@ -96,7 +102,13 @@ static ssize_t cpu_release_store(struct device *dev,
>  				 const char *buf,
>  				 size_t count)
>  {
> -	return arch_cpu_release(buf, count);
> +	ssize_t ret;
> +
> +	lock_device_hotplug();
> +	ret = arch_cpu_release(buf, count);
> +	unlock_device_hotplug();
> +
> +	return ret;
>  }
>  
>  static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
Toshi Kani - Aug. 19, 2013, 2:53 p.m.
On Sat, 2013-08-17 at 16:15 -0700, Greg KH wrote:
> On Sat, Aug 17, 2013 at 01:46:57PM -0600, Toshi Kani wrote:
> > lock_device_hotplug() serializes CPU & Memory online/offline and hotplug
> > operations.  However, this lock is not held in the debug interfaces below
> > that initiate CPU online/offline operations.
> > 
> >  - _debug_hotplug_cpu(), cpu0 hotplug test interface enabled by
> >    CONFIG_DEBUG_HOTPLUG_CPU0.
> >  - cpu_probe_store() and cpu_release_store(), cpu hotplug test interface
> >    enabled by CONFIG_ARCH_CPU_PROBE_RELEASE.
> > 
> > This patch changes the above interfaces to hold lock_device_hotplug().
> > 
> > Signed-off-by: Toshi Kani <toshi.kani@hp.com>
> > ---
> >  arch/x86/kernel/topology.c |    2 ++
> >  drivers/base/cpu.c         |   16 ++++++++++++++--
> >  2 files changed, 16 insertions(+), 2 deletions(-)
> 
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Thanks Greg!
-Toshi

Patch

diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c
index 5823bbd..a3f35eb 100644
--- a/arch/x86/kernel/topology.c
+++ b/arch/x86/kernel/topology.c
@@ -65,6 +65,7 @@  int __ref _debug_hotplug_cpu(int cpu, int action)
 	if (!cpu_is_hotpluggable(cpu))
 		return -EINVAL;
 
+	lock_device_hotplug();
 	cpu_hotplug_driver_lock();
 
 	switch (action) {
@@ -91,6 +92,7 @@  int __ref _debug_hotplug_cpu(int cpu, int action)
 	}
 
 	cpu_hotplug_driver_unlock();
+	unlock_device_hotplug();
 
 	return ret;
 }
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 4c358bc..4cc6928 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -88,7 +88,13 @@  static ssize_t cpu_probe_store(struct device *dev,
 			       const char *buf,
 			       size_t count)
 {
-	return arch_cpu_probe(buf, count);
+	ssize_t ret;
+
+	lock_device_hotplug();
+	ret = arch_cpu_probe(buf, count);
+	unlock_device_hotplug();
+
+	return ret;
 }
 
 static ssize_t cpu_release_store(struct device *dev,
@@ -96,7 +102,13 @@  static ssize_t cpu_release_store(struct device *dev,
 				 const char *buf,
 				 size_t count)
 {
-	return arch_cpu_release(buf, count);
+	ssize_t ret;
+
+	lock_device_hotplug();
+	ret = arch_cpu_release(buf, count);
+	unlock_device_hotplug();
+
+	return ret;
 }
 
 static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store);