Prohibit ioremap() on kernel managed RAM
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
Note that I've applied this patch to my devel tree, which has been pushed out; please note that I'm making use of others 'net connections to do this.
Hi,
Quoted 11 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
So cases such as the omapfb driver which use reserve_bootmem() (in arch/arm/plat-omap/fb.c) and then later use ioremap_wc() to remap reserved memory (in drivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.
Is that correct?
Thanks!
--
Regards,
George
Quoted 11 lines · George G. Davis
Hi,
Quoted 8 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
Quoted 8 lines
Quoted 3 lines
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.
Another solution would be to allow the unmapping of sections from the kernel linear mapping. I think x86 does this already for the AGP aperture.
Signature · 1 line
Catalin
Quoted 23 lines
-----Original Message-----
From: Catalin Marinas [mailto:catalin.marinas at arm.com]
Sent: Friday, April 30, 2010 10:09 PM
To: George G. Davis
Cc: Russell King; Shilimkar, Santosh; linux-arm-kernel at lists.infradead.org
Subject: Re: [RFC] Prohibitioremap()on kernel managed RAMQuoted 15 lines · George G. Davis
Hi,
Quoted 11 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
Quoted 8 lines
Quoted 4 lines
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.Another solution would be to allow the unmapping of sections from the kernel linear mapping. I think x86 does this already for the AGP aperture.
This seems to be good solution if it's doable. Reserving memory in the boot is not so flexible and might end up in waste of memory.
Regards,
Santosh
Quoted 2 lines · Santosh
This seems to be good solution if it's doable. Reserving memory in the boot is not so flexible and might end up in waste of memory.
However, allocating large pages (larger than 4K) is unreliable due to fragmentation. There's two factors here - the larger the allocation, and the longer the system has been running, the more likely such an allocation is to fail.
Since we'd need to enforce a minimum allocation size of 1MB in order to unmap the direct mapping, we're asking for an order-8 page - and I think you'll find that'll be fairly unreliable if you want to keep allocating and freeing it.
The DMA allocators can handle anything up to MAX_ORDER-order allocations provided it has enough virtual memory space available to it - so if you want to go down this route, you might as well switch to using that. (However, eventually the DMA allocator also needs fixing to avoid the dual-mappings that it creates.)
Hi,
Quoted 16 lines · Catalin Marinas
Quoted 15 lines · George G. Davis
Hi,
Quoted 11 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
Quoted 8 lines
Quoted 4 lines
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.Another solution would be to allow the unmapping of sections from the kernel linear mapping. I think x86 does this already for the AGP aperture.
I've yet to grok that code but have been curious about how this is done for x86 graphics. : )
--
Regards,
George
Quoted 3 lines
Signature · 2 lines
-- Catalin
Quoted 22 lines · George G. Davis
Quoted 21 lines · Catalin Marinas
Quoted 19 lines · George G. Davis
Hi,
Quoted 11 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.
Quoted 6 lines
Quoted 3 lines
Another solution would be to allow the unmapping of sections from the kernel linear mapping. I think x86 does this already for the AGP aperture.
I've yet to grok that code but have been curious about how this is done for x86 graphics. : )
I don't know exactly but I've got reports in the past that kmemleak was trying to scan the AGP aperture on x86 and it wasn't actually mapped, though it was allocated via alloc_bootmem().
Another option I noticed on x86 is the use of functions like io_mapping_create_wc() which call iomap_create_wc() and io_reserve_memtype(). The latter calls kernel_map_sync_memtype() which seems to change the attributes of the kernel linear mapping for the given physical address.
Signature · 1 line
Catalin
Hi,
Quoted 34 lines · Catalin Marinas
Quoted 22 lines · George G. Davis
Quoted 21 lines · Catalin Marinas
Quoted 19 lines · George G. Davis
Hi,
Quoted 11 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.Quoted 6 lines
Quoted 3 lines
Another solution would be to allow the unmapping of sections from the kernel linear mapping. I think x86 does this already for the AGP aperture.
I've yet to grok that code but have been curious about how this is done for x86 graphics. : )
I don't know exactly but I've got reports in the past that kmemleak was trying to scan the AGP aperture on x86 and it wasn't actually mapped, though it was allocated via
alloc_bootmem().
Quoted 5 lines
Another option I noticed on x86 is the use of functions like
io_mapping_create_wc()which calliomap_create_wc()andio_reserve_memtype(). The latter callskernel_map_sync_memtype()which seems to change the attributes of the kernel linear mapping for the given physical address.
Ah, ok, interesting, __ioremap_caller() in arch/x86/mm/ioremap.c has:
/*
* Don't allow anybody to remap normal RAM that we're using..
*/
for (pfn = phys_addr >> PAGE_SHIFT;
(pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
pfn++) {
int is_ram = page_is_ram(pfn);
if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
return NULL;
WARN_ON_ONCE(is_ram);
}I'm still not clear on all the ins and outs of reserving the AGP aperture but it looks like it's done via agp_generic_create_gatt_table() in drivers/char/agp/generic.c where alloc_gatt_pages() does a call to __get_free_pages(), for x86, and does SetPageReserved() for each page and then uses set_memory_uc() to update the memory type attributes.
So could we similarly we relax this "Prohibit ioremap() on kernel managed RAM" change for reserved pages? Like so:
/* * Don't allow RAM to be mapped - this causes problems with ARMv6+ */ if (WARN_ON(pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn))) return NULL;
Thanks again!
--
Regards,
George
Quoted 3 lines
Signature · 2 lines
-- Catalin
Quoted 9 lines · George G. Davis
So could we similarly we relax this "Prohibit
ioremap()on kernel managed RAM" change for reserved pages? Like so:/* * Don't allow RAM to be mapped - this causes problems with ARMv6+ */ if (WARN_ON(pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn))) return NULL;
Only once the rest of the solution gets implemented; making this change on its own doesn't mean very much or have very much effect.
Hi,
Quoted 11 lines · Russell King - ARM Linux
Quoted 9 lines · George G. Davis
So could we similarly we relax this "Prohibit
ioremap()on kernel managed RAM" change for reserved pages? Like so:/* * Don't allow RAM to be mapped - this causes problems with ARMv6+ */ if (WARN_ON(pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn))) return NULL;
Quoted 2 lines
Only once the rest of the solution gets implemented; making this change on its own doesn't mean very much or have very much effect.
That's fine, I'm just (trying ; ) to think ahead.
Thanks!
--
Regards,
George
Quoted 11 lines · George G. Davis
Hi,
Quoted 8 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
Quoted 8 lines
Quoted 3 lines
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.
Correct; and there's two reasons why they'll break in the near future. The first is down to ioremap not wanting to allow remapping of already existing memory.
The second is that when we switch to using LMB instead of bootmem, this makes the use of reserve_bootmem() a problem in fb.c.
There's really one option for this - in the machine's fixup handler, you can walk the meminfo array and kick out some memory from that. This will prevent the kernel mapping that memory and make pfn_valid() fail for that memory range. Another advantage of this is that it won't break when we switch to LMB.
Hi,
Quoted 25 lines · Russell King - ARM Linux
Quoted 11 lines · George G. Davis
Hi,
Quoted 8 lines · Russell King
Quoted 2 lines
Above change is necessary but what an alternative approach is for this. There are many use case where ioremap* is needed.
This is a very difficult issue to answer; the only way we can safely remap RAM with different attributes is if we disable the existing mappings - but since we create those with 1MB sections, that's far from easy to achieve.
Quoted 8 lines
Quoted 3 lines
I think a viable safe solution is to set aside some RAM at boot (which the kernel doesn't manage at all) and then use ioremap on that; that approach will still work with this patch in place.
So cases such as the omapfb driver which use
reserve_bootmem()(inarch/arm/plat-omap/fb.c) and then later useioremap_wc()to remap reserved memory (indrivers/video/omap2/omapfb/omapfb-main.c) will no longer work with this change.Correct; and there's two reasons why they'll break in the near future. The first is down to ioremap not wanting to allow remapping of already existing memory.
Quoted 8 lines
The second is that when we switch to using LMB instead of bootmem, this makes the use of
reserve_bootmem()a problem infb.c.There's really one option for this - in the machine's fixup handler, you can walk the meminfo array and kick out some memory from that. This will prevent the kernel mapping that memory and make
pfn_valid()fail for that memory range. Another advantage of this is that it won't break when we switch to LMB.
I guess another option is to pass mem= on the cmdline to leave memory free for ioremap'ing as needed. Yuck. : )
Thanks!
--
Regards,
George