From: Guenter Roeck <guenter.roeck@ericsson.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>,
Durgadoss R <durgadoss.r@intel.com>,
Andi Kleen <ak@linux.intel.com>,
Jean Delvare <khali@linux-fr.org>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [lm-sensors] [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp
Date: Fri, 04 May 2012 13:34:19 +0000 [thread overview]
Message-ID: <20120504133419.GA20602@ericsson.com> (raw)
In-Reply-To: <20120504064606.GA11744@otc-wbsnb-06>
On Fri, May 04, 2012 at 02:46:06AM -0400, Kirill A. Shutemov wrote:
> On Thu, May 03, 2012 at 10:41:22PM -0700, Guenter Roeck wrote:
> > On Thu, May 03, 2012 at 07:18:56AM -0400, Kirill A. Shutemov wrote:
> > > From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> > >
> > > Let's rework code to allow arbitrary number of cores on a CPU, not
> > > limited by hardcoded array size.
> > >
> > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > > ---
> > > v2:
> > > - fix NULL pointer dereference. Thanks to R, Durgadoss;
> > > - use mutex instead of spinlock for list locking.
> > > ---
> > > drivers/hwmon/coretemp.c | 178 +++++++++++++++++++++++++++++++++-------------
> > > 1 files changed, 129 insertions(+), 49 deletions(-)
> > >
> > > diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
> > > index 54a70fe..1c66131 100644
> > > --- a/drivers/hwmon/coretemp.c
> > > +++ b/drivers/hwmon/coretemp.c
> > > @@ -36,6 +36,8 @@
> > > #include <linux/cpu.h>
> > > #include <linux/pci.h>
> > > #include <linux/smp.h>
> > > +#include <linux/list.h>
> > > +#include <linux/kref.h>
> > > #include <linux/moduleparam.h>
> > > #include <asm/msr.h>
> > > #include <asm/processor.h>
> > > @@ -52,11 +54,9 @@ module_param_named(tjmax, force_tjmax, int, 0444);
> > > MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
> > >
> > > #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */
> > > -#define NUM_REAL_CORES 16 /* Number of Real cores per cpu */
> > > #define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */
> > > #define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */
> > > #define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
> > > -#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO)
> > >
> > > #define TO_PHYS_ID(cpu) (cpu_data(cpu).phys_proc_id)
> > > #define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id)
> > > @@ -82,6 +82,9 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
> > > * @valid: If this is 1, the current temperature is valid.
> > > */
> > > struct temp_data {
> > > + struct list_head list;
> > > + struct kref refcount;
> >
> > Hi,
> >
> > the kref is not needed. The attribute access functions don't
> > need to be protected since the attributes for a core are deleted
> > before the core data itself is deleted. So it is not neccessary
> > to hold a lock while accessing/using temp_data in the attribute
> > access functions. All you need is to hold a mutex while you are
> > manipulating or walking the list.
>
> Without kref, what prevents following situation:
>
> CPU-A CPU-B
> tdata = get_temp_data();
> coretemp_remove_core() {
> device_remove_file();
> kfree(tdata);
> }
> <tdata dereference>
>
The remove function requires a semaphore which is held by the access function,
so device_remove_file() will only proceed after CPU-A is done with the sysfs access.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
WARNING: multiple messages have this Message-ID (diff)
From: Guenter Roeck <guenter.roeck@ericsson.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>,
Durgadoss R <durgadoss.r@intel.com>,
Andi Kleen <ak@linux.intel.com>,
Jean Delvare <khali@linux-fr.org>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp data
Date: Fri, 4 May 2012 06:34:19 -0700 [thread overview]
Message-ID: <20120504133419.GA20602@ericsson.com> (raw)
In-Reply-To: <20120504064606.GA11744@otc-wbsnb-06>
On Fri, May 04, 2012 at 02:46:06AM -0400, Kirill A. Shutemov wrote:
> On Thu, May 03, 2012 at 10:41:22PM -0700, Guenter Roeck wrote:
> > On Thu, May 03, 2012 at 07:18:56AM -0400, Kirill A. Shutemov wrote:
> > > From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> > >
> > > Let's rework code to allow arbitrary number of cores on a CPU, not
> > > limited by hardcoded array size.
> > >
> > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > > ---
> > > v2:
> > > - fix NULL pointer dereference. Thanks to R, Durgadoss;
> > > - use mutex instead of spinlock for list locking.
> > > ---
> > > drivers/hwmon/coretemp.c | 178 +++++++++++++++++++++++++++++++++-------------
> > > 1 files changed, 129 insertions(+), 49 deletions(-)
> > >
> > > diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
> > > index 54a70fe..1c66131 100644
> > > --- a/drivers/hwmon/coretemp.c
> > > +++ b/drivers/hwmon/coretemp.c
> > > @@ -36,6 +36,8 @@
> > > #include <linux/cpu.h>
> > > #include <linux/pci.h>
> > > #include <linux/smp.h>
> > > +#include <linux/list.h>
> > > +#include <linux/kref.h>
> > > #include <linux/moduleparam.h>
> > > #include <asm/msr.h>
> > > #include <asm/processor.h>
> > > @@ -52,11 +54,9 @@ module_param_named(tjmax, force_tjmax, int, 0444);
> > > MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
> > >
> > > #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */
> > > -#define NUM_REAL_CORES 16 /* Number of Real cores per cpu */
> > > #define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */
> > > #define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */
> > > #define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
> > > -#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO)
> > >
> > > #define TO_PHYS_ID(cpu) (cpu_data(cpu).phys_proc_id)
> > > #define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id)
> > > @@ -82,6 +82,9 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
> > > * @valid: If this is 1, the current temperature is valid.
> > > */
> > > struct temp_data {
> > > + struct list_head list;
> > > + struct kref refcount;
> >
> > Hi,
> >
> > the kref is not needed. The attribute access functions don't
> > need to be protected since the attributes for a core are deleted
> > before the core data itself is deleted. So it is not neccessary
> > to hold a lock while accessing/using temp_data in the attribute
> > access functions. All you need is to hold a mutex while you are
> > manipulating or walking the list.
>
> Without kref, what prevents following situation:
>
> CPU-A CPU-B
> tdata = get_temp_data();
> coretemp_remove_core() {
> device_remove_file();
> kfree(tdata);
> }
> <tdata dereference>
>
The remove function requires a semaphore which is held by the access function,
so device_remove_file() will only proceed after CPU-A is done with the sysfs access.
Guenter
next prev parent reply other threads:[~2012-05-04 13:34 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-30 13:18 [lm-sensors] [PATCH] hwmon: coretemp: fix oops on cpu unplug Kirill A. Shutemov
2012-04-30 13:18 ` Kirill A. Shutemov
2012-04-30 15:28 ` [lm-sensors] " Guenter Roeck
2012-04-30 15:28 ` Guenter Roeck
2012-04-30 16:19 ` [lm-sensors] " Kirill A. Shutemov
2012-04-30 16:19 ` Kirill A. Shutemov
2012-04-30 16:59 ` [lm-sensors] " Guenter Roeck
2012-04-30 16:59 ` Guenter Roeck
2012-05-01 15:20 ` [lm-sensors] " Guenter Roeck
2012-05-01 15:20 ` Guenter Roeck
2012-05-01 21:00 ` [lm-sensors] " Kirill A. Shutemov
2012-05-01 21:00 ` Kirill A. Shutemov
2012-05-01 21:25 ` [lm-sensors] " Guenter Roeck
2012-05-01 21:25 ` Guenter Roeck
2012-05-02 15:10 ` [lm-sensors] [PATCH] hwmon: coretemp: use list instead of fixed size array for temp data Kirill A. Shutemov
2012-05-02 15:10 ` Kirill A. Shutemov
2012-05-03 5:29 ` [lm-sensors] " R, Durgadoss
2012-05-03 5:29 ` R, Durgadoss
2012-05-03 10:04 ` Kirill A. Shutemov
2012-05-03 10:04 ` Kirill A. Shutemov
2012-05-03 11:18 ` [lm-sensors] [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp Kirill A. Shutemov
2012-05-03 11:18 ` [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp data Kirill A. Shutemov
2012-05-04 5:41 ` [lm-sensors] [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp Guenter Roeck
2012-05-04 5:41 ` [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp data Guenter Roeck
2012-05-04 6:46 ` [lm-sensors] [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp Kirill A. Shutemov
2012-05-04 6:46 ` [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp data Kirill A. Shutemov
2012-05-04 13:34 ` Guenter Roeck [this message]
2012-05-04 13:34 ` Guenter Roeck
2012-05-04 13:42 ` [lm-sensors] [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp Kirill A. Shutemov
2012-05-04 13:42 ` [PATCH, v2] hwmon: coretemp: use list instead of fixed size array for temp data Kirill A. Shutemov
2015-07-15 16:04 ` [lm-sensors] [PATCH] " Lukasz Odzioba
2015-07-15 16:04 ` Lukasz Odzioba
2015-07-15 21:07 ` [lm-sensors] " Jean Delvare
2015-07-15 21:07 ` Jean Delvare
2015-07-16 13:17 ` [lm-sensors] " Odzioba, Lukasz
2015-07-16 13:17 ` Odzioba, Lukasz
2015-07-17 16:55 ` [lm-sensors] " Guenter Roeck
2015-07-17 16:55 ` Guenter Roeck
2015-07-17 17:28 ` [lm-sensors] " Odzioba, Lukasz
2015-07-17 17:28 ` Odzioba, Lukasz
2015-07-17 18:01 ` [lm-sensors] " Guenter Roeck
2015-07-17 18:01 ` Guenter Roeck
2015-07-17 19:23 ` [lm-sensors] " Odzioba, Lukasz
2015-07-17 19:23 ` Odzioba, Lukasz
2015-07-17 21:33 ` [lm-sensors] " Jean Delvare
2015-07-17 21:33 ` Jean Delvare
2015-07-17 19:11 ` [lm-sensors] " Jean Delvare
2015-07-17 19:11 ` Jean Delvare
2015-07-17 19:36 ` [lm-sensors] " Guenter Roeck
2015-07-17 19:36 ` Guenter Roeck
2015-07-17 21:25 ` [lm-sensors] " Jean Delvare
2015-07-17 21:25 ` Jean Delvare
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120504133419.GA20602@ericsson.com \
--to=guenter.roeck@ericsson.com \
--cc=ak@linux.intel.com \
--cc=durgadoss.r@intel.com \
--cc=fenghua.yu@intel.com \
--cc=khali@linux-fr.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.