Skip to contentSkip to conversation

wistron_btns needs executable BIOS image

PATCH New Jakub Bogusz 3 participants 5 messages Jul 31, 2017 – Jan 26, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wistron_btns needs executable BIOS image

Hello,

This patch (originally agains 3.1x, now I updated include to build against 4.12.x) fixes winstron_btns module issue with calling BIOS functions in non-executable memory.

Tested (on Linux 3.10.x and few later versions) on F-S Amilo 8210 laptop.

Signature · 1 line
Jakub Bogusz    http://qboosh.pl/

wistron_btns needs executable BIOS image.

drivers/input/misc/wistron_btns.c renamed from drivers/input/misc/wistron_btns.c.orig +3 -0
@@ -33,6 +33,7 @@
 #include <linux/types.h>
 #include <linux/platform_device.h>
 #include <linux/leds.h>
+#include <asm/set_memory.h>
 
 /* How often we poll keys - msecs */
 #define POLL_INTERVAL_DEFAULT	500 /* when idle */
@@ -124,6 +125,7 @@
 	if (entry_point >= 0xF0000) {
 		bios_code_map_base = base;
 		bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
+		set_memory_x((unsigned long)bios_code_map_base, 0x10000 >> PAGE_SHIFT);
 	} else {
 		iounmap(base);
 		bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
@@ -134,6 +136,7 @@
 			goto err;
 		}
 		bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
+		set_memory_x((unsigned long)bios_code_map_base, 0x4000 >> PAGE_SHIFT);
 	}
 	/* The Windows driver maps 0x10000 bytes, we keep only one page... */
 	bios_data_map_base = ioremap(0x400, 0xc00);
#1 lore raw

PATCH RESEND 1/1 wistron_btns needs executable BIOS image

Let's try once again... (take 3)

First time I sent this patch when I prepared it in 2013 for Linux 3.12, the second time after update for Linux 4.12 in 2017...
And it still applies to Linux 4.20.

Actual description in forwarded message.

Signature · 1 line
Jakub Bogusz    http://qboosh.pl/

Hello,

This patch (originally agains 3.1x, now I updated include to build against 4.12.x) fixes winstron_btns module issue with calling BIOS functions in non-executable memory.

Tested (on Linux 3.10.x and few later versions) on F-S Amilo 8210 laptop.

Signature · 1 line
Jakub Bogusz    http://qboosh.pl/

wistron_btns needs executable BIOS image.

drivers/input/misc/wistron_btns.c renamed from drivers/input/misc/wistron_btns.c.orig +3 -0
@@ -33,6 +33,7 @@
 #include <linux/types.h>
 #include <linux/platform_device.h>
 #include <linux/leds.h>
+#include <asm/set_memory.h>
 
 /* How often we poll keys - msecs */
 #define POLL_INTERVAL_DEFAULT	500 /* when idle */
@@ -124,6 +125,7 @@
 	if (entry_point >= 0xF0000) {
 		bios_code_map_base = base;
 		bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
+		set_memory_x((unsigned long)bios_code_map_base, 0x10000 >> PAGE_SHIFT);
 	} else {
 		iounmap(base);
 		bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
@@ -134,6 +136,7 @@
 			goto err;
 		}
 		bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
+		set_memory_x((unsigned long)bios_code_map_base, 0x4000 >> PAGE_SHIFT);
 	}
 	/* The Windows driver maps 0x10000 bytes, we keep only one page... */
 	bios_data_map_base = ioremap(0x400, 0xc00);
#2 lore raw
Quoted 5 lines · Jakub Bogusz

Let's try once again... (take 3)

First time I sent this patch when I prepared it in 2013 for Linux 3.12, the second time after update for Linux 4.12 in 2017...
And it still applies to Linux 4.20.

Adding Dmitry Torokhov and linux-input to Cc:
(that's what ./scripts/get_maintainer.pl says)

Quoted 52 lines

Actual description in forwarded message.

Signature · 21 lines
Jakub Bogusz    http://qboosh.pl/

From: Jakub Bogusz <[email protected]>
To: [email protected], [email protected]
Subject: [PATCH] wistron_btns needs executable BIOS image

Hello,

This patch (originally agains 3.1x, now I updated include to build
against 4.12.x) fixes winstron_btns module issue with calling BIOS
functions in non-executable memory.

Tested (on Linux 3.10.x and few later versions) on F-S Amilo 8210 laptop.


-- 
Jakub Bogusz    http://qboosh.pl/

wistron_btns needs executable BIOS image.

Signed-off-by: Jakub Bogusz <[email protected]>
drivers/input/misc/wistron_btns.c renamed from drivers/input/misc/wistron_btns.c.orig +3 -0
@@ -33,6 +33,7 @@
 #include <linux/types.h>
 #include <linux/platform_device.h>
 #include <linux/leds.h>
+#include <asm/set_memory.h>
 
 /* How often we poll keys - msecs */
 #define POLL_INTERVAL_DEFAULT	500 /* when idle */
@@ -124,6 +125,7 @@
 	if (entry_point >= 0xF0000) {
 		bios_code_map_base = base;
 		bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
+		set_memory_x((unsigned long)bios_code_map_base, 0x10000 >> PAGE_SHIFT);
 	} else {
 		iounmap(base);
 		bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
@@ -134,6 +136,7 @@
 			goto err;
 		}
 		bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
+		set_memory_x((unsigned long)bios_code_map_base, 0x4000 >> PAGE_SHIFT);
 	}
 	/* The Windows driver maps 0x10000 bytes, we keep only one page... */
 	bios_data_map_base = ioremap(0x400, 0xc00);
maintainer
#3 lore raw
Quoted 55 lines · Eric Wong
Quoted 5 lines · Jakub Bogusz

Let's try once again... (take 3)

First time I sent this patch when I prepared it in 2013 for Linux 3.12, the second time after update for Linux 4.12 in 2017...
And it still applies to Linux 4.20.

Adding Dmitry Torokhov and linux-input to Cc:
(that's what ./scripts/get_maintainer.pl says)

Quoted 44 lines

Actual description in forwarded message.

--
Jakub Bogusz http://qboosh.pl/

From: Jakub Bogusz <[email protected]>
To: [email protected], [email protected]
Subject: [PATCH] wistron_btns needs executable BIOS image

Hello,

This patch (originally agains 3.1x, now I updated include to build against 4.12.x) fixes winstron_btns module issue with calling BIOS functions in non-executable memory.

Tested (on Linux 3.10.x and few later versions) on F-S Amilo 8210 laptop.

--
Jakub Bogusz http://qboosh.pl/

wistron_btns needs executable BIOS image.

drivers/input/misc/wistron_btns.c 2013-11-16 09:24:37.356028732 +0100 renamed from drivers/input/misc/wistron_btns.c.orig 2013-11-16 09:05:55.612742472 +0100 +2 -0
@@ -33,6 +33,7 @@
 #include <linux/types.h>
 #include <linux/platform_device.h>
 #include <linux/leds.h>
+#include <asm/set_memory.h>
 
 /* How often we poll keys - msecs */
 #define POLL_INTERVAL_DEFAULT        500 /* when idle */
@@ -124,6 +125,7 @@
      if (entry_point >= 0xF0000) {
              bios_code_map_base = base;
              bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
+             set_memory_x((unsigned long)bios_code_map_base, 0x10000 >> PAGE_SHIFT);
      } else {
              iounmap(base);
              bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
Quoted 8 lines

drivers/input/misc/wistron_btns.c 2013-11-16 09:24:37.356028732 +0100 line 142

Quoted 8 lines
drivers/input/misc/wistron_btns.c 2013-11-16 09:24:37.356028732 +0100 renamed from drivers/input/misc/wistron_btns.c.orig 2013-11-16 09:05:55.612742472 +0100 +1 -0
@@ -134,6 +136,7 @@
                      goto err;
              }
              bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
+             set_memory_x((unsigned long)bios_code_map_base, 0x4000 >> PAGE_SHIFT);
      }
      /* The Windows driver maps 0x10000 bytes, we keep only one page... */
      bios_data_map_base = ioremap(0x400, 0xc00);

It is really weird have __iomem region to have executable bit set. I wonder if, along with the setting memory to X, we should not change that ioremap() to memremap()?

Thanks.

Signature · 1 line
Dmitry
#4 lore raw
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Eric Wong
Quoted 5 lines · Jakub Bogusz

Let's try once again... (take 3)

First time I sent this patch when I prepared it in 2013 for Linux 3.12, the second time after update for Linux 4.12 in 2017...
And it still applies to Linux 4.20.

Adding Dmitry Torokhov and linux-input to Cc:
(that's what ./scripts/get_maintainer.pl says)

Thanks. I was aware only of MAINTAINERS file.

[...]

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

wistron_btns needs executable BIOS image.

drivers/input/misc/wistron_btns.c 2013-11-16 09:24:37.356028732 +0100 renamed from drivers/input/misc/wistron_btns.c.orig 2013-11-16 09:05:55.612742472 +0100 +2 -0
@@ -33,6 +33,7 @@
 #include <linux/types.h>
 #include <linux/platform_device.h>
 #include <linux/leds.h>
+#include <asm/set_memory.h>
 
 /* How often we poll keys - msecs */
 #define POLL_INTERVAL_DEFAULT        500 /* when idle */
@@ -124,6 +125,7 @@
      if (entry_point >= 0xF0000) {
              bios_code_map_base = base;
              bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
+             set_memory_x((unsigned long)bios_code_map_base, 0x10000 >> PAGE_SHIFT);
      } else {
              iounmap(base);
              bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
@@ -134,6 +136,7 @@
                      goto err;
              }
              bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
Quoted 8 lines
Quoted 4 lines

drivers/input/misc/wistron_btns.c 2013-11-16 09:24:37.356028732 +0100 line 142

Quoted 4 lines
drivers/input/misc/wistron_btns.c 2013-11-16 09:24:37.356028732 +0100 renamed from drivers/input/misc/wistron_btns.c.orig 2013-11-16 09:05:55.612742472 +0100 +1 -0
+             set_memory_x((unsigned long)bios_code_map_base, 0x4000 >> PAGE_SHIFT);
      }
      /* The Windows driver maps 0x10000 bytes, we keep only one page... */
      bios_data_map_base = ioremap(0x400, 0xc00);

It is really weird have __iomem region to have executable bit set. I wonder if, along with the setting memory to X, we should not change that ioremap() to memremap()?

Maybe... this is area of BIOS ROM, not I/O. But I'm not sure about cacheability.

Looking at recent kernel code (4.19 to be exact) ioremap ends in __ioremap_caller with _PAGE_CACHE_MODE_UC_MINUS, while memremap would end in __ioremap_caller with e.g. (depending on flags) _PAGE_CACHE_MODE_WT.

Unfortunately now I have rare access to this hardware (FS Amilo) to test.

Signature · 1 line
Jakub Bogusz    http://qboosh.pl/