2011-04-14 21:37:28

by Nat Gurumoorthy

[permalink] [raw]
Subject: [PATCH v6 0/2] Make all it87 drivers SMP safe

There are 3 different drivers that touch the it87 hardware registers.
The 3 drivers have been written independently and access the it87 hardware
registers assuming they are the only driver accessing it. This change
attempts to serialize access to the hardware by using
"request_muxed_region" macro defined by Alan Cox. Call to this macro
will hold off the requestor if the resource is currently busy.
The use of the above macro makes it possible to get rid of
spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers.
This also greatly simplifies the implementation of it87_wdt.c driver.

01 - Changes to it87 watchdog driver to use "request_muxed_region"
drivers/watchdog/it8712f_wdt.c
drivers/watchdog/it87_wdt.c

02 - Chages to hwmon it87 driver to use "request_muxed_region"
drivers/hwmon/it87.c

drivers/hwmon/it87.c | 30 +++++++++++++-
drivers/watchdog/it8712f_wdt.c | 50 +++++++++++++++++++++---
drivers/watchdog/it87_wdt.c | 80 +++++++++++++++++++++------------------
3 files changed, 113 insertions(+), 47 deletions(-)

Signed-off-by: Nat Gurumoorthy <[email protected]>

Patch History:
v6:
- Pay attention to value returned by request_muxed_region. The first call to
request_muxed_region will attempt 10 times to reserve the region before it
gives up. This will typically get called from the driver init routines. If this
succeeds then subsequent calls wait forever for the resource to be available.

v5:
- Remove unnecessary while from superio_enter.

v4:
- Remove extra braces in superio_enter routines.

v3:
- Totally abandon the spinlock based approach and use "request_muxed_region" to
hold off requestors if the resource is busy.

v2:
- More verbose patch headers. Add In-Reply-To: field.


2011-04-14 21:38:45

by Nat Gurumoorthy

[permalink] [raw]
Subject: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

01 - Changes to it87 watchdog driver to use "request_muxed_region"
Serialize access to the hardware by using "request_muxed_region" macro defined
by Alan Cox. Call to this macro will hold off the requestor if the resource is
currently busy. The first call to request_muxed_region will attempt 10 times
to reserve the region before it gives up. This will typically get called from
the driver init routines. If this succeeds then subsequent calls wait forever
for the resource to be available.

The use of the above macro makes it possible to get rid of
spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers.
This also greatly simplifies the implementation of it87_wdt.c driver.

Signed-off-by: Nat Gurumoorthy <[email protected]>
---

diff --git a/drivers/watchdog/it8712f_wdt.c b/drivers/watchdog/it8712f_wdt.c
index 6143f52..8bf2524 100644
--- a/drivers/watchdog/it8712f_wdt.c
+++ b/drivers/watchdog/it8712f_wdt.c
@@ -51,7 +51,6 @@ MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");

static unsigned long wdt_open;
static unsigned expect_close;
-static spinlock_t io_lock;
static unsigned char revision;

/* Dog Food address - We use the game port address */
@@ -121,9 +120,46 @@ static inline void superio_select(int ldn)
outb(ldn, VAL);
}

-static inline void superio_enter(void)
+static inline int
+try_superio_enter(void)
{
- spin_lock(&io_lock);
+ int num_tries = 10;
+ /*
+ * Try to reserve REG and REG + 1 for exclusive access.
+ * Give up after 10 attempts.
+ */
+ while (num_tries--) {
+ if (!request_muxed_region(REG, 2, NAME)) {
+ if (num_tries)
+ continue;
+
+ /*
+ * Someone is holding the region. Give up.
+ */
+ pr_err("I/O address 0x%04x already in use\n", REG);
+ return -EBUSY;
+ }
+
+ break;
+ }
+
+ outb(0x87, REG);
+ outb(0x01, REG);
+ outb(0x55, REG);
+ outb(0x55, REG);
+ return 0;
+}
+
+static inline void
+superio_enter(void)
+{
+ /*
+ * Reserve REG and REG + 1 for exclusive access.
+ * Wait forever if you have to to gain access.
+ */
+ while (!request_muxed_region(REG, 2, NAME))
+ continue;
+
outb(0x87, REG);
outb(0x01, REG);
outb(0x55, REG);
@@ -134,7 +170,7 @@ static inline void superio_exit(void)
{
outb(0x02, REG);
outb(0x02, VAL);
- spin_unlock(&io_lock);
+ release_region(REG, 2);
}

static inline void it8712f_wdt_ping(void)
@@ -341,7 +377,9 @@ static int __init it8712f_wdt_find(unsigned short *address)
int err = -ENODEV;
int chip_type;

- superio_enter();
+ if (try_superio_enter())
+ return -EBUSY;
+
chip_type = superio_inw(DEVID);
if (chip_type != IT8712F_DEVID)
goto exit;
@@ -382,8 +420,6 @@ static int __init it8712f_wdt_init(void)
{
int err = 0;

- spin_lock_init(&io_lock);
-
if (it8712f_wdt_find(&address))
return -ENODEV;

diff --git a/drivers/watchdog/it87_wdt.c b/drivers/watchdog/it87_wdt.c
index b1bc72f..f1a0f03 100644
--- a/drivers/watchdog/it87_wdt.c
+++ b/drivers/watchdog/it87_wdt.c
@@ -137,7 +137,6 @@

static unsigned int base, gpact, ciract, max_units, chip_type;
static unsigned long wdt_status;
-static DEFINE_SPINLOCK(spinlock);

static int nogameport = DEFAULT_NOGAMEPORT;
static int exclusive = DEFAULT_EXCLUSIVE;
@@ -163,8 +162,46 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started, default="

/* Superio Chip */

-static inline void superio_enter(void)
+static inline int
+try_superio_enter(void)
{
+ int num_tries = 10;
+ /*
+ * Try to reserve REG and REG + 1 for exclusive access.
+ * Give up after 10 attempts.
+ */
+ while (num_tries--) {
+ if (!request_muxed_region(REG, 2, WATCHDOG_NAME)) {
+ if (num_tries)
+ continue;
+
+ /*
+ * Someone is holding the region. Give up.
+ */
+ pr_err("I/O address 0x%04x already in use\n", REG);
+ return -EBUSY;
+ }
+
+ break;
+ }
+
+ outb(0x87, REG);
+ outb(0x01, REG);
+ outb(0x55, REG);
+ outb(0x55, REG);
+ return 0;
+}
+
+static inline void
+superio_enter(void)
+{
+ /*
+ * Reserve REG and REG + 1 for exclusive access.
+ * Wait forever if you have to to gain access.
+ */
+ while (!request_muxed_region(REG, 2, WATCHDOG_NAME))
+ continue;
+
outb(0x87, REG);
outb(0x01, REG);
outb(0x55, REG);
@@ -175,6 +212,7 @@ static inline void superio_exit(void)
{
outb(0x02, REG);
outb(0x02, VAL);
+ release_region(REG, 2);
}

static inline void superio_select(int ldn)
@@ -257,9 +295,6 @@ static void wdt_keepalive(void)

static void wdt_start(void)
{
- unsigned long flags;
-
- spin_lock_irqsave(&spinlock, flags);
superio_enter();

superio_select(GPIO);
@@ -270,14 +305,10 @@ static void wdt_start(void)
wdt_update_timeout();

superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}

static void wdt_stop(void)
{
- unsigned long flags;
-
- spin_lock_irqsave(&spinlock, flags);
superio_enter();

superio_select(GPIO);
@@ -288,7 +319,6 @@ static void wdt_stop(void)
superio_outb(0x00, WDTVALMSB);

superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}

/**
@@ -303,8 +333,6 @@ static void wdt_stop(void)

static int wdt_set_timeout(int t)
{
- unsigned long flags;
-
if (t < 1 || t > max_units * 60)
return -EINVAL;

@@ -313,14 +341,12 @@ static int wdt_set_timeout(int t)
else
timeout = t;

- spin_lock_irqsave(&spinlock, flags);
if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
superio_enter();
superio_select(GPIO);
wdt_update_timeout();
superio_exit();
}
- spin_unlock_irqrestore(&spinlock, flags);
return 0;
}

@@ -339,11 +365,8 @@ static int wdt_set_timeout(int t)

static int wdt_get_status(int *status)
{
- unsigned long flags;
-
*status = 0;
if (testmode) {
- spin_lock_irqsave(&spinlock, flags);
superio_enter();
superio_select(GPIO);
if (superio_inb(WDTCTRL) & WDT_ZERO) {
@@ -353,7 +376,6 @@ static int wdt_get_status(int *status)
}

superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}
if (test_and_clear_bit(WDTS_KEEPALIVE, &wdt_status))
*status |= WDIOF_KEEPALIVEPING;
@@ -560,16 +582,15 @@ static int __init it87_wdt_init(void)
int rc = 0;
int try_gameport = !nogameport;
u8 chip_rev;
- unsigned long flags;

wdt_status = 0;

- spin_lock_irqsave(&spinlock, flags);
- superio_enter();
+ if (try_superio_enter())
+ return -EBUSY;
+
chip_type = superio_inw(CHIPID);
chip_rev = superio_inb(CHIPREV) & 0x0f;
superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);

switch (chip_type) {
case IT8702_ID:
@@ -603,7 +624,6 @@ static int __init it87_wdt_init(void)
return -ENODEV;
}

- spin_lock_irqsave(&spinlock, flags);
superio_enter();

superio_select(GPIO);
@@ -621,14 +641,12 @@ static int __init it87_wdt_init(void)
gpact = superio_inb(ACTREG);
superio_outb(0x01, ACTREG);
superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
if (request_region(base, 1, WATCHDOG_NAME))
set_bit(WDTS_USE_GP, &wdt_status);
else
rc = -EIO;
} else {
superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}

/* If we haven't Gameport support, try to get CIR support */
@@ -646,7 +664,6 @@ static int __init it87_wdt_init(void)
goto err_out;
}
base = CIR_BASE;
- spin_lock_irqsave(&spinlock, flags);
superio_enter();

superio_select(CIR);
@@ -660,7 +677,6 @@ static int __init it87_wdt_init(void)
}

superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}

if (timeout < 1 || timeout > max_units * 60) {
@@ -711,21 +727,17 @@ err_out_reboot:
err_out_region:
release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
if (!test_bit(WDTS_USE_GP, &wdt_status)) {
- spin_lock_irqsave(&spinlock, flags);
superio_enter();
superio_select(CIR);
superio_outb(ciract, ACTREG);
superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}
err_out:
if (try_gameport) {
- spin_lock_irqsave(&spinlock, flags);
superio_enter();
superio_select(GAMEPORT);
superio_outb(gpact, ACTREG);
superio_exit();
- spin_unlock_irqrestore(&spinlock, flags);
}

return rc;
@@ -733,10 +745,6 @@ err_out:

static void __exit it87_wdt_exit(void)
{
- unsigned long flags;
- int nolock;
-
- nolock = !spin_trylock_irqsave(&spinlock, flags);
superio_enter();
superio_select(GPIO);
superio_outb(0x00, WDTCTRL);
@@ -752,8 +760,6 @@ static void __exit it87_wdt_exit(void)
superio_outb(ciract, ACTREG);
}
superio_exit();
- if (!nolock)
- spin_unlock_irqrestore(&spinlock, flags);

misc_deregister(&wdt_miscdev);
unregister_reboot_notifier(&wdt_notifier);
--
1.7.3.1

2011-04-14 21:39:05

by Nat Gurumoorthy

[permalink] [raw]
Subject: [PATCH v6 2/2] Use "request_muxed_region" in it87 hwmon drivers

02 - Chages to hwmon it87 driver to use "request_muxed_region"
Serialize access to the hardware by using "request_muxed_region" macro defined
by Alan Cox. Call to this macro will hold off the requestor if the resource is
currently busy. The first call to request_muxed_region will attempt 10 times
to reserve the region before it gives up. This will typically get called from
the driver init routines. If this succeeds then subsequent calls wait forever
for the resource to be available.

Signed-off-by: Nat Gurumoorthy <[email protected]>
---

diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 316b648..2c349be 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -108,13 +108,34 @@ superio_select(int ldn)
outb(ldn, VAL);
}

-static inline void
-superio_enter(void)
-{
+static inline int
+try_superio_enter(void)
+{
+ int num_tries = 10;
+ /*
+ * Try to reserve REG and REG + 1 for exclusive access.
+ * Give up after 10 attempts.
+ */
+ while (num_tries--) {
+ if (!request_muxed_region(REG, 2, DRVNAME)) {
+ if (num_tries)
+ continue;
+
+ /*
+ * Someone is holding the region. Give up.
+ */
+ pr_err("I/O address 0x%04x already in use\n", REG);
+ return -EBUSY;
+ }
+
+ break;
+ }
+
outb(0x87, REG);
outb(0x01, REG);
outb(0x55, REG);
outb(0x55, REG);
+ return 0;
}

static inline void
@@ -122,6 +143,7 @@ superio_exit(void)
{
outb(0x02, REG);
outb(0x02, VAL);
+ release_region(REG, 2);
}

/* Logical device 4 registers */
@@ -1546,7 +1568,9 @@ static int __init it87_find(unsigned short *address,
u16 chip_type;
const char *board_vendor, *board_name;

- superio_enter();
+ if (try_superio_enter())
+ return -EBUSY;
+
chip_type = force_id ? force_id : superio_inw(DEVID);

switch (chip_type) {
--
1.7.3.1

2011-04-14 22:50:42

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Thu, 2011-04-14 at 17:37 -0400, Nat Gurumoorthy wrote:
> 01 - Changes to it87 watchdog driver to use "request_muxed_region"
> Serialize access to the hardware by using "request_muxed_region" macro defined
> by Alan Cox. Call to this macro will hold off the requestor if the resource is
> currently busy. The first call to request_muxed_region will attempt 10 times
> to reserve the region before it gives up. This will typically get called from
> the driver init routines. If this succeeds then subsequent calls wait forever
> for the resource to be available.
>
> The use of the above macro makes it possible to get rid of
> spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers.
> This also greatly simplifies the implementation of it87_wdt.c driver.
>
> Signed-off-by: Nat Gurumoorthy <[email protected]>
> ---
>
> diff --git a/drivers/watchdog/it8712f_wdt.c b/drivers/watchdog/it8712f_wdt.c
> index 6143f52..8bf2524 100644
> --- a/drivers/watchdog/it8712f_wdt.c
> +++ b/drivers/watchdog/it8712f_wdt.c
> @@ -51,7 +51,6 @@ MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
>
> static unsigned long wdt_open;
> static unsigned expect_close;
> -static spinlock_t io_lock;
> static unsigned char revision;
>
> /* Dog Food address - We use the game port address */
> @@ -121,9 +120,46 @@ static inline void superio_select(int ldn)
> outb(ldn, VAL);
> }
>
> -static inline void superio_enter(void)
> +static inline int
> +try_superio_enter(void)
> {
> - spin_lock(&io_lock);
> + int num_tries = 10;
> + /*
> + * Try to reserve REG and REG + 1 for exclusive access.
> + * Give up after 10 attempts.
> + */
> + while (num_tries--) {
> + if (!request_muxed_region(REG, 2, NAME)) {
> + if (num_tries)
> + continue;
> +
> + /*
> + * Someone is holding the region. Give up.
> + */
> + pr_err("I/O address 0x%04x already in use\n", REG);
> + return -EBUSY;
> + }
> +
> + break;
> + }
> +
This is way too complicated. Just return an error if
request_muxed_region fails, like all other callers of
request_muxed_region do.

Guenter

2011-04-15 01:19:01

by Nat Gurumoorthy

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Thu, Apr 14, 2011 at 3:49 PM, Guenter Roeck
<[email protected]> wrote:
> This is way too complicated. Just return an error if
> request_muxed_region fails, like all other callers of
> request_muxed_region do.
>
Guenter,
This maybe a little complicated but it is a solution that will
correctly deal with the following scenario:
Hardware: it8712f
cpu: Multicore
kernel: smp
Modules being loaded during initialization: it8712f_wtd and w83697hf

The problem is one of the cores is halfway through initializing
it8712f_wdt and another core is just starting to run the
"w83697hf_check_wdt" which is going to call "request_region" to
reserve 0x2e 0x2f region. Just after that call on the other core
it8712f_wdt_init calls it8712f_wdt_disable which calls superio_enter
which will call "request_muxed_region" for the exact same region. This
is guaranteed to fail because as of now w83697hf is one of the many
non compliant drivers who are calling "request_region". The w83697hf
will do the probe and conclude there is no w83697hf chip in the system
and abort rest of the driver initialization. Meanwhile the it8712f_wtd
driver initialization will fail. This will be one of those
intermittent failures that make most kernel device driver writers
prematurely bald :-).

The way I have reworked the driver will survive the above scenario.

Regards
Nat

> Guenter
>
>
>



--
Regards
Nat Gurumoorthy AB6SJ

2011-04-15 02:40:55

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Thu, Apr 14, 2011 at 09:18:57PM -0400, Natarajan Gurumoorthy wrote:
> On Thu, Apr 14, 2011 at 3:49 PM, Guenter Roeck
> <[email protected]> wrote:
> > This is way too complicated. Just return an error if
> > request_muxed_region fails, like all other callers of
> > request_muxed_region do.
> >
> Guenter,
> This maybe a little complicated but it is a solution that will
> correctly deal with the following scenario:
> Hardware: it8712f
> cpu: Multicore
> kernel: smp
> Modules being loaded during initialization: it8712f_wtd and w83697hf
>
> The problem is one of the cores is halfway through initializing
> it8712f_wdt and another core is just starting to run the
> "w83697hf_check_wdt" which is going to call "request_region" to
> reserve 0x2e 0x2f region. Just after that call on the other core
> it8712f_wdt_init calls it8712f_wdt_disable which calls superio_enter
> which will call "request_muxed_region" for the exact same region. This
> is guaranteed to fail because as of now w83697hf is one of the many
> non compliant drivers who are calling "request_region". The w83697hf
> will do the probe and conclude there is no w83697hf chip in the system
> and abort rest of the driver initialization. Meanwhile the it8712f_wtd
> driver initialization will fail. This will be one of those
> intermittent failures that make most kernel device driver writers
> prematurely bald :-).
>
> The way I have reworked the driver will survive the above scenario.
>
Unless I am missing something, the problem is that there is another driver
calling request_region() instead of request_muxed_region().

w83697hf_check_wdt() (and other drivers doing the same) should call
request_muxed_region(). Otherwise, the same problem could happen with the
caller(s) of request_region() - those calls could fail as well.
Plus, other callers of request_muxed_reason() not implementing
your retry code could end up with the same problem, ie with spurious failures.

I think we will have to find a solution which does not require retries
when calling request_muxed_region(). On the other side, others know
this code much better than I do, so maybe someone has a better solution.

Thanks,
Guenter

2011-04-15 03:14:38

by Nat Gurumoorthy

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Thu, Apr 14, 2011 at 7:40 PM, Guenter Roeck
<[email protected]> wrote:
> Unless I am missing something, the problem is that there is another driver
> calling request_region() instead of request_muxed_region().
>
> w83697hf_check_wdt() (and other drivers doing the same) should call
> request_muxed_region(). Otherwise, the same problem could happen with the
> caller(s) of request_region() - those calls could fail as well.
> Plus, other callers of request_muxed_reason() not implementing
> your retry code could end up with the same problem, ie with spurious failures.
>
> I think we will have to find a solution which does not require retries
> when calling request_muxed_region(). On the other side, others know
> this code much better than I do, so maybe someone has a better solution.
>
Guenter,
Your conclusion is on the money. request_muxed_region will fail if
someone else called request_region for the same region. The knife cuts
both ways and reguest_region will fail when a request_muxed_region
calll has been made for the same zone. I am not sure what happens
when the second driver calls request_muxed_region for only part of the
region that has been reserved by another driver. This is of course one
of the problems. The other problem is that there are drivers which
don't call either of those 2 interfaces and just go ahead and clobber
the 0x2e 0x2f zone because they think they own all of it. I created a
list drivers in hwmon and watchdog directories that need to be fixed
in one of my earlier emails. John Delvare replied that are other
drivers in parport that all need fixing. I got started on this because
we use 2 different it87 drivers (hwmon/it87.c and
watchdog/it8712f_wdt.c) concurrently and had to solve this problem.

Regards
Nat


> Thanks,
> Guenter
>



--
Regards
Nat Gurumoorthy AB6SJ

2011-04-15 05:59:46

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Thu, Apr 14, 2011 at 11:14:32PM -0400, Natarajan Gurumoorthy wrote:
> On Thu, Apr 14, 2011 at 7:40 PM, Guenter Roeck
> <[email protected]> wrote:
> > Unless I am missing something, the problem is that there is another driver
> > calling request_region() instead of request_muxed_region().
> >
> > w83697hf_check_wdt() (and other drivers doing the same) should call
> > request_muxed_region(). Otherwise, the same problem could happen with the
> > caller(s) of request_region() - those calls could fail as well.
> > Plus, other callers of request_muxed_reason() not implementing
> > your retry code could end up with the same problem, ie with spurious failures.
> >
> > I think we will have to find a solution which does not require retries
> > when calling request_muxed_region(). On the other side, others know
> > this code much better than I do, so maybe someone has a better solution.
> >
> Guenter,
> Your conclusion is on the money. request_muxed_region will fail if
> someone else called request_region for the same region. The knife cuts
> both ways and reguest_region will fail when a request_muxed_region
> calll has been made for the same zone. I am not sure what happens
> when the second driver calls request_muxed_region for only part of the
> region that has been reserved by another driver. This is of course one
> of the problems. The other problem is that there are drivers which
> don't call either of those 2 interfaces and just go ahead and clobber
> the 0x2e 0x2f zone because they think they own all of it. I created a
> list drivers in hwmon and watchdog directories that need to be fixed
> in one of my earlier emails. John Delvare replied that are other
> drivers in parport that all need fixing. I got started on this because
> we use 2 different it87 drivers (hwmon/it87.c and
> watchdog/it8712f_wdt.c) concurrently and had to solve this problem.
>
I have seen the list. I don't think you should fix everything in one go.
First step might be to get the w83697hf and it87 to work together, then
go from there.

Is there a reason for loading (or trying to load) both the it87 and
the w83697hf driver at the same time ? Those drivers are usually only
loaded if the respective chip is known to exist. If there is no reason
to try loading both drivers, a simple workaround would be to not do it.

Thanks,
Guenter

2011-04-15 08:46:14

by Nat Gurumoorthy

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Thu, Apr 14, 2011 at 10:58 PM, Guenter Roeck
<[email protected]> wrote:
> I have seen the list. I don't think you should fix everything in one go.
> First step might be to get the w83697hf and it87 to work together, then
> go from there.
>
> Is there a reason for loading (or trying to load) both the it87 and
> the w83697hf driver at the same time ? Those drivers are usually only
> loaded if the respective chip is known to exist. If there is no reason
> to try loading both drivers, a simple workaround would be to not do it.
>
Guenter,
I agree the above should never happen. The only way the 2
drivers will be loaded at the same time is a misconfigured kernel
where these 2 drivers get built and the rc scripts end up loading them
too. If we are agreed that I suggest we make the superio_enter routine
be the following:

static inline void
superio_enter(void)
{
/*
* Reserve REG and REG + 1 for exclusive access.
*/
while (!request_muxed_region(REG, 2, WATCHDOG_NAME))
continue;

outb(0x87, REG);
outb(0x01, REG);
outb(0x55, REG);
outb(0x55, REG);
}

What I am suggesting is not returning an error and instead keep
calling "request_muxed_region" till it succeeds. If superio_enter
returns an error then we will have to rewrite a large chunk of
it8712f_wdt to deal with it. There are 8-9 calls to superio_enter. We
will have supreio_enter returning errors at awkward places in the
driver where the current logic has no code to deal with errors.

In case of properly written drivers the while loop will eventually
exit. I agree this is ugly as sin but it limits the perturbation of
the driver. Feedback please.

Regards
Nat


> Thanks,
> Guenter
>
>



--
Regards
Nat Gurumoorthy AB6SJ

2011-04-15 11:06:19

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

On Fri, Apr 15, 2011 at 04:46:04AM -0400, Natarajan Gurumoorthy wrote:
> On Thu, Apr 14, 2011 at 10:58 PM, Guenter Roeck
> <[email protected]> wrote:
> > I have seen the list. I don't think you should fix everything in one go.
> > First step might be to get the w83697hf and it87 to work together, then
> > go from there.
> >
> > Is there a reason for loading (or trying to load) both the it87 and
> > the w83697hf driver at the same time ? Those drivers are usually only
> > loaded if the respective chip is known to exist. If there is no reason
> > to try loading both drivers, a simple workaround would be to not do it.
> >
> Guenter,
> I agree the above should never happen. The only way the 2
> drivers will be loaded at the same time is a misconfigured kernel
> where these 2 drivers get built and the rc scripts end up loading them
> too. If we are agreed that I suggest we make the superio_enter routine
> be the following:
>
> static inline void
> superio_enter(void)
> {
> /*
> * Reserve REG and REG + 1 for exclusive access.
> */
> while (!request_muxed_region(REG, 2, WATCHDOG_NAME))
> continue;
>
At least for my part, I would not agree to that. If another driver misbehaves
and does not release the region, one of your CPU cores will be stuck
in an endless loop.

> outb(0x87, REG);
> outb(0x01, REG);
> outb(0x55, REG);
> outb(0x55, REG);
> }
>
> What I am suggesting is not returning an error and instead keep
> calling "request_muxed_region" till it succeeds. If superio_enter
> returns an error then we will have to rewrite a large chunk of
> it8712f_wdt to deal with it. There are 8-9 calls to superio_enter. We
> will have supreio_enter returning errors at awkward places in the
> driver where the current logic has no code to deal with errors.
>
Can't help it. I browsed through it earlier and didn't think it was that bad.
Just pass the error on to the next level until you can return it.

Guenter

> In case of properly written drivers the while loop will eventually
> exit. I agree this is ugly as sin but it limits the perturbation of
> the driver. Feedback please.
>
> Regards
> Nat
>
>
> > Thanks,
> > Guenter
> >
> >
>
>
>
> --
> Regards
> Nat Gurumoorthy AB6SJ

2011-04-15 21:06:57

by Jarod Wilson

[permalink] [raw]
Subject: Re: [PATCH v6 0/2] Make all it87 drivers SMP safe

On Apr 14, 2011, at 5:36 PM, Nat Gurumoorthy wrote:

> There are 3 different drivers that touch the it87 hardware registers.
> The 3 drivers have been written independently and access the it87 hardware
> registers assuming they are the only driver accessing it. This change
> attempts to serialize access to the hardware by using
> "request_muxed_region" macro defined by Alan Cox. Call to this macro
> will hold off the requestor if the resource is currently busy.
> The use of the above macro makes it possible to get rid of
> spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers.
> This also greatly simplifies the implementation of it87_wdt.c driver.
>
> 01 - Changes to it87 watchdog driver to use "request_muxed_region"
> drivers/watchdog/it8712f_wdt.c
> drivers/watchdog/it87_wdt.c
>
> 02 - Chages to hwmon it87 driver to use "request_muxed_region"
> drivers/hwmon/it87.c
>
> drivers/hwmon/it87.c | 30 +++++++++++++-
> drivers/watchdog/it8712f_wdt.c | 50 +++++++++++++++++++++---
> drivers/watchdog/it87_wdt.c | 80 +++++++++++++++++++++------------------
> 3 files changed, 113 insertions(+), 47 deletions(-)

FYI,

$ head -n 4 drivers/media/rc/ite-cir.c
/*
* Driver for ITE Tech Inc. IT8712F/IT8512 CIR
*
* Copyright (C) 2010 Juan Jes?s Garc?a de Soria <[email protected]>


--
Jarod Wilson
[email protected]


2011-04-18 07:33:40

by Hans de Goede

[permalink] [raw]
Subject: Re: [lm-sensors] [PATCH v6 1/2] Use "request_muxed_region" in it87 watchdog drivers

Hi,

On 04/15/2011 10:46 AM, Natarajan Gurumoorthy wrote:
> On Thu, Apr 14, 2011 at 10:58 PM, Guenter Roeck
> <[email protected]> wrote:
>> I have seen the list. I don't think you should fix everything in one go.
>> First step might be to get the w83697hf and it87 to work together, then
>> go from there.
>>
>> Is there a reason for loading (or trying to load) both the it87 and
>> the w83697hf driver at the same time ? Those drivers are usually only
>> loaded if the respective chip is known to exist. If there is no reason
>> to try loading both drivers, a simple workaround would be to not do it.
>>
> Guenter,
> I agree the above should never happen. The only way the 2
> drivers will be loaded at the same time is a misconfigured kernel
> where these 2 drivers get built and the rc scripts end up loading them
> too. If we are agreed that I suggest we make the superio_enter routine
> be the following:
>
> static inline void
> superio_enter(void)
> {
> /*
> * Reserve REG and REG + 1 for exclusive access.
> */
> while (!request_muxed_region(REG, 2, WATCHDOG_NAME))
> continue;
>

Natajaran,

Please stop being so stubborn. XXX people have told you not to put a
while loop here, but simply to check for an error and propagate
it (in all places where superio_enter gets called).

Your bogus argument of the driver then failing to load when another
non muxed superio driver loads is really far fetched. No system ever
has 2 super io chips. So as long as all ite drivers use the muxed
version all will be fine.

And if some unforeseen scenario happens where the request_muxed_region
fails, we will get a bug report about a driver failing to load (*). Which
is a lot better for the end user then being stuck in an endless loop.

Regards,

Hans

*) And deal with that then.