Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1400227 > unrolled thread
| Started by | Russell King - ARM Linux <linux@armlinux.org.uk> |
|---|---|
| First post | 2016-05-12 18:40 +0200 |
| Last post | 2016-05-25 17:50 +0200 |
| Articles | 6 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap Russell King - ARM Linux <linux@armlinux.org.uk> - 2016-05-12 18:40 +0200
Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap Dave Gerlach <d-gerlach@ti.com> - 2016-05-18 16:20 +0200
Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap Russell King - ARM Linux <linux@armlinux.org.uk> - 2016-05-18 20:00 +0200
Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap Arnd Bergmann <arnd@arndb.de> - 2016-05-18 22:30 +0200
Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap Russell King - ARM Linux <linux@armlinux.org.uk> - 2016-05-18 23:00 +0200
Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap Dave Gerlach <d-gerlach@ti.com> - 2016-05-25 17:50 +0200
| From | Russell King - ARM Linux <linux@armlinux.org.uk> |
|---|---|
| Date | 2016-05-12 18:40 +0200 |
| Subject | Re: [RFC PATCH 1/3] asm-generic: io: Add exec versions of ioremap |
| Message-ID | <ry1Oy-1bi-11@gated-at.bofh.it> |
On Mon, May 09, 2016 at 04:41:49PM -0500, Dave Gerlach wrote:
> diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
> index 66a978d05958..c6eef3c98074 100644
> --- a/arch/arm/mm/ioremap.c
> +++ b/arch/arm/mm/ioremap.c
> @@ -400,6 +400,20 @@ EXPORT_SYMBOL(ioremap_wc);
> * clocks that would affect normal memory for example. Please see
> * CONFIG_GENERIC_ALLOCATOR for allocating external memory.
> */
> +void __iomem *ioremap_exec(resource_size_t res_cookie, size_t size)
> +{
> + return arch_ioremap_caller(res_cookie, size, MT_MEMORY_RWX,
> + __builtin_return_address(0));
> +}
> +EXPORT_SYMBOL(ioremap_exec);
> +
> +void __iomem *ioremap_exec_nocache(resource_size_t res_cookie, size_t size)
> +{
> + return arch_ioremap_caller(res_cookie, size, MT_MEMORY_RWX_NONCACHED,
> + __builtin_return_address(0));
> +}
> +EXPORT_SYMBOL(ioremap_exec_nocache);
I think these should be called memremap_exec() and similar. Please
see the description of memremap() in kernel/memremap.c. If you're
going to be executing code, the region must not have I/O side effects
and according to the new definition of memremap() vs ioremap(), the
memremap() interfaces fit better.
Please also get these reviewed by Dan Williams who provided the
memremap() API.
Thanks.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
[toc] | [next] | [standalone]
| From | Dave Gerlach <d-gerlach@ti.com> |
|---|---|
| Date | 2016-05-18 16:20 +0200 |
| Message-ID | <rAaun-3d5-41@gated-at.bofh.it> |
| In reply to | #1400227 |
Hi,
On 05/12/2016 11:37 AM, Russell King - ARM Linux wrote:
> On Mon, May 09, 2016 at 04:41:49PM -0500, Dave Gerlach wrote:
>> diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
>> index 66a978d05958..c6eef3c98074 100644
>> --- a/arch/arm/mm/ioremap.c
>> +++ b/arch/arm/mm/ioremap.c
>> @@ -400,6 +400,20 @@ EXPORT_SYMBOL(ioremap_wc);
>> * clocks that would affect normal memory for example. Please see
>> * CONFIG_GENERIC_ALLOCATOR for allocating external memory.
>> */
>> +void __iomem *ioremap_exec(resource_size_t res_cookie, size_t size)
>> +{
>> + return arch_ioremap_caller(res_cookie, size, MT_MEMORY_RWX,
>> + __builtin_return_address(0));
>> +}
>> +EXPORT_SYMBOL(ioremap_exec);
>> +
>> +void __iomem *ioremap_exec_nocache(resource_size_t res_cookie, size_t size)
>> +{
>> + return arch_ioremap_caller(res_cookie, size, MT_MEMORY_RWX_NONCACHED,
>> + __builtin_return_address(0));
>> +}
>> +EXPORT_SYMBOL(ioremap_exec_nocache);
>
> I think these should be called memremap_exec() and similar. Please
> see the description of memremap() in kernel/memremap.c. If you're
> going to be executing code, the region must not have I/O side effects
> and according to the new definition of memremap() vs ioremap(), the
> memremap() interfaces fit better.
>
> Please also get these reviewed by Dan Williams who provided the
> memremap() API.
Ok thank you for the pointer. I agree, the memremap API looks like a
better fit for this. I think it likely makes the most sense to still add
these ioremap_exec and ioremap_exec_nocache and then call them through
the memremap API based on new flags. This will fit into the current use
model for memremap as it currently uses all of the other ioremap calls
internally, and doing it how I just described will let this code evolve
along with memremap.
I will put v2 together this way and send it out.
Regards,
Dave
>
> Thanks.
>
[toc] | [prev] | [next] | [standalone]
| From | Russell King - ARM Linux <linux@armlinux.org.uk> |
|---|---|
| Date | 2016-05-18 20:00 +0200 |
| Message-ID | <rAdVf-5eB-11@gated-at.bofh.it> |
| In reply to | #1403023 |
On Wed, May 18, 2016 at 09:12:20AM -0500, Dave Gerlach wrote: > Ok thank you for the pointer. I agree, the memremap API looks like a better > fit for this. I think it likely makes the most sense to still add these > ioremap_exec and ioremap_exec_nocache and then call them through the > memremap API based on new flags. This will fit into the current use model > for memremap as it currently uses all of the other ioremap calls internally, > and doing it how I just described will let this code evolve along with > memremap. I would _really_ prefer not to do that. Why? Because IO memory does not have the required properties to be executable. IO memory is normally memory which has side effects - and by side effects, I mean reading it can provoke hardware to perform some action. You don't want to be executing from such memory. So, in my mind, ioremap_exec makes absolutely no sense, and having it gives people a new interface to abuse - and abuse they will. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
[toc] | [prev] | [next] | [standalone]
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2016-05-18 22:30 +0200 |
| Message-ID | <rAggp-6OT-3@gated-at.bofh.it> |
| In reply to | #1403200 |
On Wednesday 18 May 2016 18:51:02 Russell King - ARM Linux wrote: > On Wed, May 18, 2016 at 09:12:20AM -0500, Dave Gerlach wrote: > > Ok thank you for the pointer. I agree, the memremap API looks like a better > > fit for this. I think it likely makes the most sense to still add these > > ioremap_exec and ioremap_exec_nocache and then call them through the > > memremap API based on new flags. This will fit into the current use model > > for memremap as it currently uses all of the other ioremap calls internally, > > and doing it how I just described will let this code evolve along with > > memremap. > > I would _really_ prefer not to do that. Why? Because IO memory does > not have the required properties to be executable. IO memory is normally > memory which has side effects - and by side effects, I mean reading it > can provoke hardware to perform some action. You don't want to be > executing from such memory. > > So, in my mind, ioremap_exec makes absolutely no sense, and having it > gives people a new interface to abuse - and abuse they will. Agreed, calling it ioremap when it is really memremap makes no sense. I also see another problem in the asm-generic portion: +#ifndef ARCH_HAS_IOREMAP_EXEC +#define ioremap_exec ioremap +#define ioremap_exec_nocache ioremap_nocache +#endif The ARM version of ioremap_exec() that gets added in this patch is cached (like memremap()), but then the asm-generic version is not? This is even more confusing, it should at least do roughly the same thing across architectures. There should also be some documentation about what the expected behavior is, e.g.: - is memremap_exec() by default cached or not? (I assume it would be like memremap()) - If we have an interface that does explicit uncached executable mapping, what about architectures on which this is not possible? Should they fall back to cached or non-executable, or cause a link error? Arnd
[toc] | [prev] | [next] | [standalone]
| From | Russell King - ARM Linux <linux@armlinux.org.uk> |
|---|---|
| Date | 2016-05-18 23:00 +0200 |
| Message-ID | <rAgJs-6ZU-21@gated-at.bofh.it> |
| In reply to | #1403265 |
On Wed, May 18, 2016 at 10:25:03PM +0200, Arnd Bergmann wrote: > The ARM version of ioremap_exec() that gets added in this patch is cached > (like memremap()), but then the asm-generic version is not? This is > even more confusing, it should at least do roughly the same thing across > architectures. > > There should also be some documentation about what the expected behavior is, e.g.: > > - is memremap_exec() by default cached or not? (I assume it would > be like memremap()) > - If we have an interface that does explicit uncached executable mapping, > what about architectures on which this is not possible? Should they > fall back to cached or non-executable, or cause a link error? Another important point is whether atomic instructions / kernel locks can be located within the mapped memory. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
[toc] | [prev] | [next] | [standalone]
| From | Dave Gerlach <d-gerlach@ti.com> |
|---|---|
| Date | 2016-05-25 17:50 +0200 |
| Message-ID | <rCJeh-2H3-7@gated-at.bofh.it> |
| In reply to | #1403279 |
On 05/18/2016 03:57 PM, Russell King - ARM Linux wrote: > On Wed, May 18, 2016 at 10:25:03PM +0200, Arnd Bergmann wrote: >> The ARM version of ioremap_exec() that gets added in this patch is cached >> (like memremap()), but then the asm-generic version is not? This is >> even more confusing, it should at least do roughly the same thing across >> architectures. >> >> There should also be some documentation about what the expected behavior is, e.g.: >> >> - is memremap_exec() by default cached or not? (I assume it would >> be like memremap()) >> - If we have an interface that does explicit uncached executable mapping, >> what about architectures on which this is not possible? Should they >> fall back to cached or non-executable, or cause a link error? Yes by default memremap_exec is cached, I do plan to add more explicit documentation. Well, I dont think that memremap_exec will be called directly but rather using a flag with memremap as arch_memremap_wb is now, to keep the memremap API unified, so a link error will prevent this. Also, the function may be present in code but not actually used in all cases, the example that comes to mind is the drivers/misc/sram.c code where other runtime options are perfectly valid for determining how to map memory even on architectures that can't memremap_exec_nocache. I think that a remap that can't deliver what you have asked for should return NULL here because if you are requesting executable, noncached memory you presumably will try to execute from it and fail, so the mapping should fail as it isn't actually valid if it can't do what you want. > > Another important point is whether atomic instructions / kernel locks > can be located within the mapped memory. > At this point I'd imagine most of the users of this would be copying small chunks of relocatable code (likely written in assembly) that would handle low-level tasks without the need for atomic instructions/locks, but is this something we should explicitly forbid in documentation? Regards, Dave
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web