LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] x86: use bitmap library functions
@ 2011-02-16 14:48 Akinobu Mita
  2011-02-16 15:38 ` Ingo Molnar
  2011-02-17 15:05 ` [tip:x86/asm] x86: Use " tip-bot for Akinobu Mita
  0 siblings, 2 replies; 5+ messages in thread
From: Akinobu Mita @ 2011-02-16 14:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: Akinobu Mita, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86

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 <akinobu.mita@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
---
 arch/x86/kernel/ioport.c |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index 8eec0ec..8c96897 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -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,
-- 
1.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: use bitmap library functions
  2011-02-16 14:48 [PATCH] x86: use bitmap library functions Akinobu Mita
@ 2011-02-16 15:38 ` Ingo Molnar
  2011-02-17  5:00   ` Akinobu Mita
  2011-02-17 15:05 ` [tip:x86/asm] x86: Use " tip-bot for Akinobu Mita
  1 sibling, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2011-02-16 15:38 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86


* Akinobu Mita <akinobu.mita@gmail.com> wrote:

> 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 <akinobu.mita@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> ---
>  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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: use bitmap library functions
  2011-02-16 15:38 ` Ingo Molnar
@ 2011-02-17  5:00   ` Akinobu Mita
  2011-02-17 13:59     ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Akinobu Mita @ 2011-02-17  5:00 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86

2011/2/17 Ingo Molnar <mingo@elte.hu>:
>
> * Akinobu Mita <akinobu.mita@gmail.com> wrote:
>
>> 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 <akinobu.mita@gmail.com>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>> Cc: x86@kernel.org
>> ---
>>  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.

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");
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: use bitmap library functions
  2011-02-17  5:00   ` Akinobu Mita
@ 2011-02-17 13:59     ` Ingo Molnar
  0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2011-02-17 13:59 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86


* Akinobu Mita <akinobu.mita@gmail.com> wrote:

> 2011/2/17 Ingo Molnar <mingo@elte.hu>:
> >
> > * Akinobu Mita <akinobu.mita@gmail.com> wrote:
> >
> >> 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 <akinobu.mita@gmail.com>
> >> Cc: Thomas Gleixner <tglx@linutronix.de>
> >> Cc: Ingo Molnar <mingo@redhat.com>
> >> Cc: "H. Peter Anvin" <hpa@zytor.com>
> >> Cc: x86@kernel.org
> >> ---
> >>  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.
> 
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:x86/asm] x86: Use bitmap library functions
  2011-02-16 14:48 [PATCH] x86: use bitmap library functions Akinobu Mita
  2011-02-16 15:38 ` Ingo Molnar
@ 2011-02-17 15:05 ` tip-bot for Akinobu Mita
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Akinobu Mita @ 2011-02-17 15:05 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, akinobu.mita, tglx, mingo

Commit-ID:  da1016df85ed67b6f7dbb765532c54bc35ba08d7
Gitweb:     http://git.kernel.org/tip/da1016df85ed67b6f7dbb765532c54bc35ba08d7
Author:     Akinobu Mita <akinobu.mita@gmail.com>
AuthorDate: Wed, 16 Feb 2011 23:48:35 +0900
Committer:  Ingo Molnar <mingo@elte.hu>
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.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
LKML-Reference: <1297867715-20394-1-git-send-email-akinobu.mita@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/ioport.c |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index 8eec0ec..8c96897 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -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,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-17 15:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-16 14:48 [PATCH] x86: use bitmap library functions Akinobu Mita
2011-02-16 15:38 ` Ingo Molnar
2011-02-17  5:00   ` Akinobu Mita
2011-02-17 13:59     ` Ingo Molnar
2011-02-17 15:05 ` [tip:x86/asm] x86: Use " tip-bot for Akinobu Mita

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).