linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] archs: add ioremap_change_write_prot
@ 2010-10-24  8:41 Marco Stornelli
  2010-10-26 10:56 ` Marco Stornelli
  2010-10-26 16:24 ` Thomas Gleixner
  0 siblings, 2 replies; 6+ messages in thread
From: Marco Stornelli @ 2010-10-24  8:41 UTC (permalink / raw)
  To: Linux Kernel; +Cc: x86, Tim Bird, andi

From: Marco Stornelli <marco.stornelli@gmail.com>

This patch adds a new function called ioremap_change_write_prot.
Goal of this patch is to create a general function for all archs to be
able to change a write protection of a memory mapped area. x86
has already got a similar framework, so this function is only
a wrapper. Next target will be arm and powerpc. This function
will be used by Pramfs (see its latest review).

Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
---

diff -Nurp linux-2.6.36-orig/arch/x86/mm/ioremap.c linux-2.6.36/arch/x86/mm/ioremap.c
--- linux-2.6.36-orig/arch/x86/mm/ioremap.c	2010-09-13 01:07:37.000000000 +0200
+++ linux-2.6.36/arch/x86/mm/ioremap.c	2010-10-24 10:03:36.000000000 +0200
@@ -50,6 +50,27 @@ int ioremap_change_attr(unsigned long va
 	return err;
 }
 
+int ioremap_change_write_prot(unsigned long vaddr, unsigned long size,
+			       unsigned int rw)
+{
+	unsigned long nrpages = size >> PAGE_SHIFT;
+	int ret;
+
+	/* Page aligned */
+	vaddr &= PAGE_MASK;
+
+	if (size & (PAGE_SIZE - 1))
+		nrpages++;
+
+	if (rw)
+		ret = set_memory_rw(vaddr, nrpages);
+	else
+		ret = set_memory_ro(vaddr, nrpages);
+
+	return ret;
+}
+EXPORT_SYMBOL(ioremap_change_write_prot);
+
 /*
  * Remap an arbitrary physical address space into the kernel virtual
  * address space. Needed when the kernel wants to access high addresses
--- linux-2.6.36-orig/arch/Kconfig	2010-09-13 01:07:37.000000000 +0200
+++ linux-2.6.36/arch/Kconfig	2010-10-23 09:29:56.000000000 +0200
@@ -83,6 +83,9 @@ config USER_RETURN_NOTIFIER
 config HAVE_IOREMAP_PROT
 	bool
 
+config HAVE_IOREMAP_CHANGE_WRITE_PROT
+	bool
+
 config HAVE_KPROBES
 	bool
 
--- linux-2.6.36-orig/arch/x86/Kconfig	2010-09-13 01:07:37.000000000 +0200
+++ linux-2.6.36/arch/x86/Kconfig	2010-10-23 09:09:06.000000000 +0200
@@ -26,6 +26,7 @@ config X86
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS if (!M386 && !M486)
 	select HAVE_IOREMAP_PROT
+	select HAVE_IOREMAP_CHANGE_WRITE_PROT
 	select HAVE_KPROBES
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select ARCH_WANT_FRAME_POINTERS
diff -Nurp linux-2.6.36-orig/arch/x86/include/asm/io.h linux-2.6.36/arch/x86/include/asm/io.h
--- linux-2.6.36-orig/arch/x86/include/asm/io.h	2010-09-13 01:07:37.000000000 +0200
+++ linux-2.6.36/arch/x86/include/asm/io.h	2010-10-23 09:11:37.000000000 +0200
@@ -333,6 +333,8 @@ extern void unxlate_dev_mem_ptr(unsigned
 
 extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
 				unsigned long prot_val);
+extern int ioremap_change_write_prot(unsigned long vaddr, unsigned long size,
+				unsigned int rw);
 extern void __iomem *ioremap_wc(resource_size_t offset, unsigned long size);
 
 /*


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

* Re: [PATCH] archs: add ioremap_change_write_prot
  2010-10-24  8:41 [PATCH] archs: add ioremap_change_write_prot Marco Stornelli
@ 2010-10-26 10:56 ` Marco Stornelli
  2010-10-26 13:14   ` Andi Kleen
  2010-10-26 16:24 ` Thomas Gleixner
  1 sibling, 1 reply; 6+ messages in thread
From: Marco Stornelli @ 2010-10-26 10:56 UTC (permalink / raw)
  To: Linux Kernel; +Cc: x86, Tim Bird, andi, Andrew Morton

2010/10/24 Marco Stornelli <marco.stornelli@gmail.com>:
> From: Marco Stornelli <marco.stornelli@gmail.com>
>
> This patch adds a new function called ioremap_change_write_prot.
> Goal of this patch is to create a general function for all archs to be
> able to change a write protection of a memory mapped area. x86
> has already got a similar framework, so this function is only
> a wrapper. Next target will be arm and powerpc. This function
> will be used by Pramfs (see its latest review).
>
> Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>

Sorry to re-open the topic, but I'd like to receive any
comments/feedback about this patch.

Marco

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

* Re: [PATCH] archs: add ioremap_change_write_prot
  2010-10-26 10:56 ` Marco Stornelli
@ 2010-10-26 13:14   ` Andi Kleen
  0 siblings, 0 replies; 6+ messages in thread
From: Andi Kleen @ 2010-10-26 13:14 UTC (permalink / raw)
  To: Marco Stornelli; +Cc: Linux Kernel, x86, Tim Bird, andi, Andrew Morton

> Sorry to re-open the topic, but I'd like to receive any
> comments/feedback about this patch.

The name of the wrapper seems wrong -- this has nothing to do with IO.

I must admit I'm also not a fan of wrappers, why not call the set_memory_*
functions directly and implement them for the other archs too?

Other than that it seems reasonable.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only.

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

* Re: [PATCH] archs: add ioremap_change_write_prot
  2010-10-24  8:41 [PATCH] archs: add ioremap_change_write_prot Marco Stornelli
  2010-10-26 10:56 ` Marco Stornelli
@ 2010-10-26 16:24 ` Thomas Gleixner
  2010-10-27  6:55   ` Marco Stornelli
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2010-10-26 16:24 UTC (permalink / raw)
  To: Marco Stornelli; +Cc: Linux Kernel, x86, Tim Bird, andi

On Sun, 24 Oct 2010, Marco Stornelli wrote:

> From: Marco Stornelli <marco.stornelli@gmail.com>
> 
> This patch adds a new function called ioremap_change_write_prot.
> Goal of this patch is to create a general function for all archs to be
> able to change a write protection of a memory mapped area. x86
> has already got a similar framework, so this function is only
> a wrapper. Next target will be arm and powerpc. This function
> will be used by Pramfs (see its latest review).

Sorry for the delay. I'm traveling.
 
> Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
> ---
> 
> diff -Nurp linux-2.6.36-orig/arch/x86/mm/ioremap.c linux-2.6.36/arch/x86/mm/ioremap.c
> --- linux-2.6.36-orig/arch/x86/mm/ioremap.c	2010-09-13 01:07:37.000000000 +0200
> +++ linux-2.6.36/arch/x86/mm/ioremap.c	2010-10-24 10:03:36.000000000 +0200
> @@ -50,6 +50,27 @@ int ioremap_change_attr(unsigned long va
>  	return err;
>  }
  
> +int ioremap_change_write_prot(unsigned long vaddr, unsigned long size,
> +			       unsigned int rw)
> +{
> +	unsigned long nrpages = size >> PAGE_SHIFT;
> +	int ret;
> +
> +	/* Page aligned */
> +	vaddr &= PAGE_MASK;
> +
> +	if (size & (PAGE_SIZE - 1))
> +		nrpages++;
> +
> +	if (rw)
> +		ret = set_memory_rw(vaddr, nrpages);
> +	else
> +		ret = set_memory_ro(vaddr, nrpages);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(ioremap_change_write_prot);

Why inventing a new interface if we have one already ?

    set_memory_* which has a few more variants than ro/rw

Also this is not related to ioremap, these are functions which works on
almost anything when there are other restrictions in place.

So implementing set_memory_ro(), set_memory_rw() for those archs which
you need it for makes more sense than creating a misnomed and
misplaced wrapper.

Thanks,

	tglx

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

* Re: [PATCH] archs: add ioremap_change_write_prot
  2010-10-26 16:24 ` Thomas Gleixner
@ 2010-10-27  6:55   ` Marco Stornelli
  2010-10-27  7:59     ` Andi Kleen
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Stornelli @ 2010-10-27  6:55 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Linux Kernel, x86, Tim Bird, andi

2010/10/26 Thomas Gleixner <tglx@linutronix.de>:
>
> Why inventing a new interface if we have one already ?
>
>    set_memory_* which has a few more variants than ro/rw
>
> Also this is not related to ioremap, these are functions which works on
> almost anything when there are other restrictions in place.
>
> So implementing set_memory_ro(), set_memory_rw() for those archs which
> you need it for makes more sense than creating a misnomed and
> misplaced wrapper.
>
> Thanks,
>
>        tglx
>

Andi and Thomas, thanks for your response. I was trying to use an
homogeneous interface, I see that only x86 has got set_memory_*, but
ok I can use these ones. About the name I used, I was trying to use a
way to change the protection after an ioremap, so for x86 means a call
to these functions, but other archs could mean other checks.

However it needs to adds a define or something similar to know if the
archs implements or not this interface. Suggestions about this point?

Thanks.

Marco

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

* Re: [PATCH] archs: add ioremap_change_write_prot
  2010-10-27  6:55   ` Marco Stornelli
@ 2010-10-27  7:59     ` Andi Kleen
  0 siblings, 0 replies; 6+ messages in thread
From: Andi Kleen @ 2010-10-27  7:59 UTC (permalink / raw)
  To: Marco Stornelli; +Cc: Thomas Gleixner, Linux Kernel, x86, Tim Bird, andi

> However it needs to adds a define or something similar to know if the
> archs implements or not this interface. Suggestions about this point?

That's fine, you can do that in Kconfig. I think you already had that
in the earlier patch: just give it a better name.

-Andi
-- 
ak@linux.intel.com -- Speaking for myself only.

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

end of thread, other threads:[~2010-10-27  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-24  8:41 [PATCH] archs: add ioremap_change_write_prot Marco Stornelli
2010-10-26 10:56 ` Marco Stornelli
2010-10-26 13:14   ` Andi Kleen
2010-10-26 16:24 ` Thomas Gleixner
2010-10-27  6:55   ` Marco Stornelli
2010-10-27  7:59     ` Andi Kleen

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).