Skip to contentSkip to conversation

hwmon: (f71805f) Use request_muxed_region for Super-IO accesses

PATCH Superseded Guenter Roeck 2 participants 11 messages Apr 4, 2019 – Apr 5, 2019

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/4 hwmon: (f71805f) Use request_muxed_region for Super-IO accesses

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Unable to handle kernel paging request at virtual address ffffffbffee0002e
pgd = ffffffc1d68d4000
[ffffffbffee0002e] *pgd=0000000000000000, *pud=0000000000000000
Internal error: Oops: 94000046 [#1] PREEMPT SMP
Modules linked in: f71805f(+) hwmon
CPU: 3 PID: 1659 Comm: insmod Not tainted 4.5.0+ #88
Hardware name: linux,dummy-virt (DT)
task: ffffffc1f6665400 ti: ffffffc1d6418000 task.ti: ffffffc1d6418000
PC is at f71805f_find+0x6c/0x358 [f71805f]

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes e53004e20a58e ("hwmon: New f71805f driver")
Cc John Garry <[email protected]>
---
 drivers/hwmon/f71805f.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/hwmon/f71805f.c +12 -3
index 73c681162653..623736d2a7c1 100644
@@ -96,17 +96,23 @@ superio_select(int base, int ld)
 	outb(ld, base + 1);
 }
 
-static inline void
+static inline int
 superio_enter(int base)
 {
+	if (!request_muxed_region(base, 2, DRVNAME))
+		return -EBUSY;
+
 	outb(0x87, base);
 	outb(0x87, base);
+
+	return 0;
 }
 
 static inline void
 superio_exit(int base)
 {
 	outb(0xaa, base);
+	release_region(base, 2);
 }
 
 /*
@@ -1561,7 +1567,7 @@ static int __init f71805f_device_add(unsigned short address,
 static int __init f71805f_find(int sioaddr, unsigned short *address,
 			       struct f71805f_sio_data *sio_data)
 {
-	int err = -ENODEV;
+	int err;
 	u16 devid;
 
 	static const char * const names[] = {
@@ -1569,8 +1575,11 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
 		"F71872F/FG or F71806F/FG",
 	};
 
-	superio_enter(sioaddr);
+	err = superio_enter(sioaddr);
+	if (err)
+		return err;
 
+	err = -ENODEV;
 	devid = superio_inw(sioaddr, SIO_REG_MANID);
 	if (devid != SIO_FINTEK_ID)
 		goto exit;
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 2/4 hwmon: (pc87427) Use request_muxed_region for Super-IO accesses

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes ba224e2c4f0a7 ("hwmon: New PC87427 hardware monitoring driver")
Cc John Garry <[email protected]>
---
 drivers/hwmon/pc87427.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/hwmon/pc87427.c +13 -1
index d1a3f2040c00..58eee8fa3e6d 100644
@@ -106,6 +106,13 @@ static const char *logdev_str[2] = { DRVNAME " FMC", DRVNAME " HMC" };
 #define LD_IN		1
 #define LD_TEMP		1
 
+static inline int superio_enter(int sioaddr)
+{
+	if (!request_muxed_region(sioaddr, 2, DRVNAME))
+		return -EBUSY;
+	return 0;
+}
+
 static inline void superio_outb(int sioaddr, int reg, int val)
 {
 	outb(reg, sioaddr);
@@ -122,6 +129,7 @@ static inline void superio_exit(int sioaddr)
 {
 	outb(0x02, sioaddr);
 	outb(0x02, sioaddr + 1);
+	release_region(sioaddr, 2);
 }
 
 /*
@@ -1195,7 +1203,11 @@ static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
 {
 	u16 val;
 	u8 cfg, cfg_b;
-	int i, err = 0;
+	int i, err;
+
+	err = superio_enter(sioaddr);
+	if (err)
+		return err;
 
 	/* Identify device */
 	val = force_id ? force_id : superio_inb(sioaddr, SIOREG_DEVID);
Signature · 1 line
2.7.4
author maintainer
#3 lore raw

PATCH 3/4 hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

In reply to Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Cc John Garry <[email protected]>
---
 drivers/hwmon/smsc47b397.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47b397.c +11 -2
index c0775084dde0..60e193f2e970 100644
@@ -72,14 +72,19 @@ static inline void superio_select(int ld)
 	superio_outb(0x07, ld);
 }
 
-static inline void superio_enter(void)
+static inline int superio_enter(void)
 {
+	if (!request_muxed_region(REG, 2, DRVNAME))
+		return -EBUSY;
+
 	outb(0x55, REG);
+	return 0;
 }
 
 static inline void superio_exit(void)
 {
 	outb(0xAA, REG);
+	release_region(REG, 2);
 }
 
 #define SUPERIO_REG_DEVID	0x20
@@ -300,8 +305,12 @@ static int __init smsc47b397_find(void)
 	u8 id, rev;
 	char *name;
 	unsigned short addr;
+	int err;
+
+	err = superio_enter();
+	if (err)
+		return err;
 
-	superio_enter();
 	id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
 	switch (id) {
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

PATCH 4/4 hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

In reply to Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Cc John Garry <[email protected]>
---
 drivers/hwmon/smsc47m1.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47m1.c +11 -2
index c7b6a425e2c0..0736ca6a3aee 100644
@@ -73,16 +73,21 @@ superio_inb(int reg)
 /* logical device for fans is 0x0A */
 #define superio_select() superio_outb(0x07, 0x0A)
 
-static inline void
+static inline int
 superio_enter(void)
 {
+	if (!request_muxed_region(REG, 2, DRVNAME))
+		return -EBUSY;
+
 	outb(0x55, REG);
+	return 0;
 }
 
 static inline void
 superio_exit(void)
 {
 	outb(0xAA, REG);
+	release_region(REG, 2);
 }
 
 #define SUPERIO_REG_ACT		0x30
@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data)
 {
 	u8 val;
 	unsigned short addr;
+	int err;
+
+	err = superio_enter();
+	if (err)
+		return err;
 
-	superio_enter();
 	val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
 	/*
Signature · 1 line
2.7.4
Acked-by on v1 1/4
#10 lore raw
In reply to Guenter Roeck
Quoted 15 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Unable to handle kernel paging request at virtual address ffffffbffee0002e
pgd = ffffffc1d68d4000
[ffffffbffee0002e] *pgd=0000000000000000, *pud=0000000000000000
Internal error: Oops: 94000046 [#1] PREEMPT SMP
Modules linked in: f71805f(+) hwmon
CPU: 3 PID: 1659 Comm: insmod Not tainted 4.5.0+ #88
Hardware name: linux,dummy-virt (DT)
task: ffffffc1f6665400 ti: ffffffc1d6418000 task.ti: ffffffc1d6418000
PC is at f71805f_find+0x6c/0x358 [f71805f]

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Quoted 8 lines

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes e53004e20a58e ("hwmon: New f71805f driver")
Cc John Garry <[email protected]>
Quoted 57 lines
---
 drivers/hwmon/f71805f.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/hwmon/f71805f.c +12 -3
index 73c681162653..623736d2a7c1 100644
@@ -96,17 +96,23 @@ superio_select(int base, int ld)
 	outb(ld, base + 1);
 }
 
-static inline void
+static inline int
 superio_enter(int base)
 {
+	if (!request_muxed_region(base, 2, DRVNAME))
+		return -EBUSY;
+
 	outb(0x87, base);
 	outb(0x87, base);
+
+	return 0;
 }
 
 static inline void
 superio_exit(int base)
 {
 	outb(0xaa, base);
+	release_region(base, 2);
 }
 
 /*
@@ -1561,7 +1567,7 @@ static int __init f71805f_device_add(unsigned short address,
 static int __init f71805f_find(int sioaddr, unsigned short *address,
 			       struct f71805f_sio_data *sio_data)
 {
-	int err = -ENODEV;
+	int err;
 	u16 devid;
 
 	static const char * const names[] = {
@@ -1569,8 +1575,11 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
 		"F71872F/FG or F71806F/FG",
 	};
 
-	superio_enter(sioaddr);
+	err = superio_enter(sioaddr);
+	if (err)
+		return err;
 
+	err = -ENODEV;
 	devid = superio_inw(sioaddr, SIO_REG_MANID);
 	if (devid != SIO_FINTEK_ID)
 		goto exit;
Acked-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] hwmon: (pc87427) Use request_muxed_region for Super-IO accesses

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Quoted 8 lines

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes ba224e2c4f0a7 ("hwmon: New PC87427 hardware monitoring driver")
Cc John Garry <[email protected]>
Quoted 45 lines
---
 drivers/hwmon/pc87427.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/hwmon/pc87427.c +13 -1
index d1a3f2040c00..58eee8fa3e6d 100644
@@ -106,6 +106,13 @@ static const char *logdev_str[2] = { DRVNAME " FMC", DRVNAME " HMC" };
 #define LD_IN		1
 #define LD_TEMP		1
 
+static inline int superio_enter(int sioaddr)
+{
+	if (!request_muxed_region(sioaddr, 2, DRVNAME))
+		return -EBUSY;
+	return 0;
+}
+
 static inline void superio_outb(int sioaddr, int reg, int val)
 {
 	outb(reg, sioaddr);
@@ -122,6 +129,7 @@ static inline void superio_exit(int sioaddr)
 {
 	outb(0x02, sioaddr);
 	outb(0x02, sioaddr + 1);
+	release_region(sioaddr, 2);
 }
 
 /*
@@ -1195,7 +1203,11 @@ static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
 {
 	u16 val;
 	u8 cfg, cfg_b;
-	int i, err = 0;
+	int i, err;
+
+	err = superio_enter(sioaddr);
+	if (err)
+		return err;
 
 	/* Identify device */
 	val = force_id ? force_id : superio_inb(sioaddr, SIOREG_DEVID);
Acked-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Quoted 7 lines

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Quoted 46 lines
---
 drivers/hwmon/smsc47b397.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47b397.c +11 -2
index c0775084dde0..60e193f2e970 100644
@@ -72,14 +72,19 @@ static inline void superio_select(int ld)
 	superio_outb(0x07, ld);
 }
 
-static inline void superio_enter(void)
+static inline int superio_enter(void)
 {
+	if (!request_muxed_region(REG, 2, DRVNAME))
+		return -EBUSY;
+
 	outb(0x55, REG);
+	return 0;
 }
 
 static inline void superio_exit(void)
 {
 	outb(0xAA, REG);
+	release_region(REG, 2);
 }
 
 #define SUPERIO_REG_DEVID	0x20
@@ -300,8 +305,12 @@ static int __init smsc47b397_find(void)
 	u8 id, rev;
 	char *name;
 	unsigned short addr;
+	int err;
+
+	err = superio_enter();
+	if (err)
+		return err;
 
-	superio_enter();
 	id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
 	switch (id) {
Acked-by on v1 4/4
#6 lore raw

Re: [PATCH 4/4] hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Quoted 8 lines

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Cc John Garry <[email protected]>
Quoted 47 lines
---
 drivers/hwmon/smsc47m1.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47m1.c +11 -2
index c7b6a425e2c0..0736ca6a3aee 100644
@@ -73,16 +73,21 @@ superio_inb(int reg)
 /* logical device for fans is 0x0A */
 #define superio_select() superio_outb(0x07, 0x0A)
 
-static inline void
+static inline int
 superio_enter(void)
 {
+	if (!request_muxed_region(REG, 2, DRVNAME))
+		return -EBUSY;
+
 	outb(0x55, REG);
+	return 0;
 }
 
 static inline void
 superio_exit(void)
 {
 	outb(0xAA, REG);
+	release_region(REG, 2);
 }
 
 #define SUPERIO_REG_ACT		0x30
@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data)
 {
 	u8 val;
 	unsigned short addr;
+	int err;
+
+	err = superio_enter();
+	if (err)
+		return err;
 
-	superio_enter();
 	val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
 	/*
#7 lore raw

Re: [PATCH 4/4] hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

Quoted 3 lines · John Garry
Quoted 2 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

BTW, these may still require attention:

sch56xx-common
smsc47m1
w83627hf
vt1211

Thanks,
John

Quoted 63 lines
Quoted 11 lines

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Cc John Garry <[email protected]>
Quoted 48 lines
---
 drivers/hwmon/smsc47m1.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47m1.c +11 -2
index c7b6a425e2c0..0736ca6a3aee 100644
@@ -73,16 +73,21 @@ superio_inb(int reg)
 /* logical device for fans is 0x0A */
 #define superio_select() superio_outb(0x07, 0x0A)
 
-static inline void
+static inline int
 superio_enter(void)
 {
+    if (!request_muxed_region(REG, 2, DRVNAME))
+        return -EBUSY;
+
     outb(0x55, REG);
+    return 0;
 }
 
 static inline void
 superio_exit(void)
 {
     outb(0xAA, REG);
+    release_region(REG, 2);
 }
 
 #define SUPERIO_REG_ACT        0x30
@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct
 smsc47m1_sio_data *sio_data)
 {
     u8 val;
     unsigned short addr;
+    int err;
+
+    err = superio_enter();
+    if (err)
+        return err;
 
-    superio_enter();
     val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
     /*
author maintainer
#8 lore raw

Re: [PATCH 4/4] hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

Quoted 9 lines · John Garry
Quoted 3 lines · John Garry
Quoted 2 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

BTW, these may still require attention:

sch56xx-common
smsc47m1

Those two already call request_muxed_region() in superio_enter(). Though error handling in the latter is less than perfect - I may send a patch to fix it.

Quoted 1 line

w83627hf > vt1211

I missed those two. Patches will follow.

Thanks,
Guenter

Quoted 70 lines

Thanks,
John

Quoted 63 lines
Quoted 11 lines

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Cc John Garry <[email protected]>
Quoted 48 lines

---
 drivers/hwmon/smsc47m1.c | 13 +++++++++++--

 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47m1.c +5 -1
index c7b6a425e2c0..0736ca6a3aee 100644
@@ -73,16 +73,21 @@ superio_inb(int reg)
  /* logical device for fans is 0x0A */
  #define superio_select() superio_outb(0x07, 0x0A)
 
-static inline void
+static inline int
  superio_enter(void)
  {
+    if (!request_muxed_region(REG, 2, DRVNAME))
+        return -EBUSY;
+
      outb(0x55, REG);
+    return 0;
  }
 

 static inline void
 superio_exit(void)
 {
     outb(0xAA, REG);
+    release_region(REG, 2);
 }

 #define SUPERIO_REG_ACT        0x30

drivers/hwmon/smsc47m1.c +5 -1
@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct
 smsc47m1_sio_data *sio_data)
  {
      u8 val;
      unsigned short addr;
+    int err;
+
+    err = superio_enter();
+    if (err)
+        return err;
 
-    superio_enter();
      val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 

     /*

author maintainer
#9 lore raw

Re: [PATCH 4/4] hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses

Quoted 6 lines · Guenter Roeck
Quoted 5 lines · John Garry
Quoted 3 lines · John Garry
Quoted 2 lines · Guenter Roeck

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Quoted 9 lines
Quoted 4 lines

BTW, these may still require attention:

sch56xx-common
smsc47m1

Those two already call request_muxed_region() in superio_enter(). Though error handling in the latter is less than perfect - I may send a patch to fix it.

... and that was because this patch has the wrong subject, and its error handling is incomplete. I'll resend.

Guenter

Quoted 78 lines
Quoted 1 line

w83627hf > vt1211

I missed those two. Patches will follow.

Thanks,
Guenter

Quoted 70 lines

Thanks,
John

Quoted 63 lines
Quoted 11 lines

Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized.

Fixes 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Cc John Garry <[email protected]>
Quoted 48 lines

---
 drivers/hwmon/smsc47m1.c | 13 +++++++++++--

 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47m1.c +5 -1
index c7b6a425e2c0..0736ca6a3aee 100644
@@ -73,16 +73,21 @@ superio_inb(int reg)
  /* logical device for fans is 0x0A */
  #define superio_select() superio_outb(0x07, 0x0A)
 
-static inline void
+static inline int
  superio_enter(void)
  {
+    if (!request_muxed_region(REG, 2, DRVNAME))
+        return -EBUSY;
+
      outb(0x55, REG);
+    return 0;
  }
 

 static inline void
 superio_exit(void)
 {
     outb(0xAA, REG);
+    release_region(REG, 2);
 }

 #define SUPERIO_REG_ACT        0x30

drivers/hwmon/smsc47m1.c +5 -1
@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct
 smsc47m1_sio_data *sio_data)
  {
      u8 val;
      unsigned short addr;
+    int err;
+
+    err = superio_enter();
+    if (err)
+        return err;
 
-    superio_enter();
      val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 

     /*