x86: use bitmap library functions
PATCH 1/1 x86: use bitmap library functions
Use bitmap_set()/bitmap_clear() to fill/zero a region of a bitmap instead of doing set_bit()/clear_bit() each bit.
--- arch/x86/kernel/ioport.c | 20 +++++--------------- 1 files changed, 5 insertions(+), 15 deletions(-)
arch/x86/kernel/ioport.c +5 -15
@@ -14,22 +14,9 @@#include <linux/slab.h> #include <linux/thread_info.h> #include <linux/syscalls.h> +#include <linux/bitmap.h> #include <asm/syscalls.h> -/* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */ -static void set_bitmap (unsigned long *bitmap,unsigned int base, -unsigned int extent,int new_value) -{ -unsigned int i; - -for (i = base; i < base + extent; i++) { -if (new_value) -__set_bit (i, bitmap); -else -__clear_bit (i, bitmap); - } -} -/* * this changes the io permissions bitmap in the current task. */
@@ -69,7 +56,10 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)*/ tss = &per_cpu (init_tss,get_cpu ()); -set_bitmap (t->io_bitmap_ptr, from, num, !turn_on); +if (turn_on) +bitmap_clear (t->io_bitmap_ptr, from, num); +else +bitmap_set (t->io_bitmap_ptr, from, num);/* * Search for a (possibly new) maximum. This is simple and stupid,
Signature · 1 line
1.7.4
Quoted 11 lines · Akinobu Mita
Use bitmap_set()/bitmap_clear() to fill/zero a region of a bitmap instead of doing set_bit()/clear_bit() each bit.
Signed-off-by Akinobu Mita <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>--- arch/x86/kernel/ioport.c | 20 +++++--------------- 1 files changed, 5 insertions(+), 15 deletions(-)
Before we can merge this it would be nice to tested this using sys_ioperm(), to make sure port IO still gets denied/allowed as expected. You can check /proc/ioperm to see which ports are (probably) safe to read: 0x80/0xed is usually safe to read/write.
Ingo
2011/2/17 Ingo Molnar <[email protected]>:
Quoted 15 lines · Akinobu Mita
Quoted 4 lines
Use bitmap_set()/bitmap_clear() to fill/zero a region of a bitmap instead of doing set_bit()/clear_bit() each bit.
Quoted 8 lines
Signed-off-by Akinobu Mita <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>---
arch/x86/kernel/ioport.c | 20 +++++---------------1 files changed, 5 insertions(+), 15 deletions(-)
Quoted 4 lines
Before we can merge this it would be nice to tested this using
sys_ioperm(), to make sure port IO still gets denied/allowed as expected. You can check/proc/iopermto see which ports are (probably) safe to read: 0x80/0xed is usually safe to read/write.
I have tested with this program and there is no difference in behavior with this patch.
#include <sys/io.h>
#include <stdio.h>
#include <err.h>
int main(void)
{
unsigned long from = 0xed;
unsigned long num = 1;
int ret;
int i;
ret = ioperm(from, num, 1);
if (ret)
err(1, "ioperm");
for (i = 0; i < num; i++)
ret = inb(from + i);
printf("OK\n");
ret = ioperm(from, num, 0);
if (ret)
err(1, "ioperm");
printf("will receive a segmentation fault\n");
ret = inb(from);
errx(1, "Oops");
}Quoted 16 lines · Akinobu Mita
2011/2/17 Ingo Molnar <[email protected]>:
Quoted 15 lines · Akinobu Mita
Quoted 12 lines
Use bitmap_set()/bitmap_clear() to fill/zero a region of a bitmap instead of doing set_bit()/clear_bit() each bit.
Signed-off-by Akinobu Mita <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>---
arch/x86/kernel/ioport.c | 20 +++++---------------1 files changed, 5 insertions(+), 15 deletions(-)
Quoted 7 lines
Quoted 4 lines
Before we can merge this it would be nice to tested this using
sys_ioperm(), to make sure port IO still gets denied/allowed as expected. You can check/proc/iopermto see which ports are (probably) safe to read: 0x80/0xed is usually safe to read/write.I have tested with this program and there is no difference in behavior with this patch.
Great - i've queued it up in tip:x86/asm.
Thanks,
Ingo
[tip:x86/asm] x86: Use bitmap library functions
In reply to Akinobu MitaCommit-ID: da1016df85ed67b6f7dbb765532c54bc35ba08d7 Gitweb: http://git.kernel.org/tip/da1016df85ed67b6f7dbb765532c54bc35ba08d7 Author: Akinobu Mita <[email protected]> AuthorDate: Wed, 16 Feb 2011 23:48:35 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Feb 2011 14:59:22 +0100
x86: Use bitmap library functions
Use bitmap_set()/bitmap_clear() to fill/zero a region of a bitmap instead of doing set_bit()/clear_bit() each bit.
This change has been tested with ioperm() and there's no change in behavior.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/ioport.c | 20 +++++--------------- 1 files changed, 5 insertions(+), 15 deletions(-)
arch/x86/kernel/ioport.c +5 -15
@@ -14,22 +14,9 @@#include <linux/slab.h> #include <linux/thread_info.h> #include <linux/syscalls.h> +#include <linux/bitmap.h> #include <asm/syscalls.h> -/* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */ -static void set_bitmap (unsigned long *bitmap,unsigned int base, -unsigned int extent,int new_value) -{ -unsigned int i; - -for (i = base; i < base + extent; i++) { -if (new_value) -__set_bit (i, bitmap); -else -__clear_bit (i, bitmap); - } -} -/* * this changes the io permissions bitmap in the current task. */
@@ -69,7 +56,10 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)*/ tss = &per_cpu (init_tss,get_cpu ()); -set_bitmap (t->io_bitmap_ptr, from, num, !turn_on); +if (turn_on) +bitmap_clear (t->io_bitmap_ptr, from, num); +else +bitmap_set (t->io_bitmap_ptr, from, num);/* * Search for a (possibly new) maximum. This is simple and stupid,