Add IO mapping space reused support
Subsystems (3)
cover Add IO mapping space reused support
Richard Lee (2):
mm/vmalloc: Add IO mapping space reused interface.
ARM: ioremap: Add IO mapping space reused support.
arch/arm/mm/ioremap.c | 11 ++++++++- include/linux/vmalloc.h | 5 ++++ mm/vmalloc.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.4
RFC PATCH 1/2 mm/vmalloc: Add IO mapping space reused interface.
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:0x20000000 ~ 0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.
This patch add the IO mapping space reusing interface:
- find_vm_area_paddr: used to find the exsit vmalloc area using the IO physical address.
- vm_area_is_aready_to_free: before vfree the IO mapped areas using this to do the check that if this area is used by more than one consumer.
--- include/linux/vmalloc.h | 5 ++++ mm/vmalloc.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
include/linux/vmalloc.h +5 -0
@@ -34,6 +34,7 @@ struct vm_struct {struct page **pages;unsigned int nr_pages;phys_addr_t phys_addr; +unsigned int used;const void *caller; };
@@ -100,6 +101,10 @@ static inline size_t get_vm_area_size(const struct vm_struct *area)return area->size -PAGE_SIZE ; } +extern int vm_area_is_aready_to_free (phys_addr_t addr); +struct vm_struct *find_vm_area_paddr (phys_addr_t paddr,size_t size, +unsigned long *offset, +unsigned long flags);extern struct vm_struct *get_vm_area (unsigned long size,unsigned long flags);extern struct vm_struct *get_vm_area_caller (unsigned long size,unsigned long flags,const void *caller);
mm/vmalloc.c +63 -0
75 lines not on this page · raw message
Signature · 1 line
1.8.4
RFC PATCH 2/2 ARM: ioremap: Add IO mapping space reused support.
In reply to Richard LeeFor the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:0x20000000 ~ 0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.
This patch add IO mapping space reused support.
--- arch/arm/mm/ioremap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm/mm/ioremap.c +10 -1
@@ -260,7 +260,7 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn, {const struct mem_type *type;int err; -unsigned long addr; +unsigned long addr, off;struct vm_struct *area;phys_addr_t paddr =__pfn_to_phys (pfn);
@@ -301,6 +301,12 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn,if (WARN_ON (pfn_valid (pfn)))return NULL ; + area =find_vm_area_paddr (paddr, size, &off,VM_IOREMAP ); +if (area) { + addr = (unsigned long )area->addr; +return (void __iomem *)(offset + off + addr); + } + area =get_vm_area_caller (size,VM_IOREMAP , caller);if (!area)return NULL ;
@@ -410,6 +416,9 @@ void __iounmap(volatile void __iomem *io_addr)if (svm)return ; +if (!vm_area_is_aready_to_free ((unsigned long )addr)) +return ; +#if !defined(CONFIG_SMP ) && !defined(CONFIG_ARM_LPAE ) {struct vm_struct *vm;
Signature · 1 line
1.8.4
Re: [RFC][PATCH 2/2] ARM: ioremap: Add IO mapping space reused support.
Quoted 10 lines · On Monday 12 May 2014 10:19:55 Richard Lee wrote:
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.This patch add IO mapping space reused support.
Signed-off-by Richard Lee <[email protected]>
What happens if the first driver then unmaps the area?
Arnd
Re: [RFC][PATCH 2/2] ARM: ioremap: Add IO mapping space reused support.
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · On Monday 12 May 2014 10:19:55 Richard Lee wrote:
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.
Quoted 6 lines
Quoted 3 lines
This patch add IO mapping space reused support.
Signed-off-by Richard Lee <[email protected]>What happens if the first driver then unmaps the area?
If the first driver will unmap the area, it shouldn't do any thing except decreasing the 'used' counter.
Thanks,
BRs
Richard Lee
Quoted 1 line
Arnd
Re: [RFC][PATCH 1/2] mm/vmalloc: Add IO mapping space reused interface.
In reply to Richard LeeQuoted 4 lines · Richard Lee
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers.
What address or who the user is isn't really relevant.
Quoted 2 lines
And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.
s/malloc/vmalloc/
Quoted 3 lines
This patch add the IO mapping space reusing interface:
-find_vm_area_paddr: used to find the exsit vmalloc area using
s/exsit/exist/
Quoted 47 lines
the IO physical address.
-vm_area_is_aready_to_free: before vfree the IO mapped areas using this to do the check that if this area is used by more than one consumer.Signed-off-by Richard Lee <[email protected]>--- include/linux/vmalloc.h | 5 ++++ mm/vmalloc.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)include/linux/vmalloc.h +5
-0@@ -34,6 +34,7 @@ struct vm_struct {struct page **pages;unsigned int nr_pages;phys_addr_t phys_addr; +unsigned int used;const void *caller; };@@ -100,6 +101,10 @@ static inline size_t get_vm_area_size(const struct vm_struct *area)return area->size -PAGE_SIZE ; } +extern int vm_area_is_aready_to_free (phys_addr_t addr); +struct vm_struct *find_vm_area_paddr (phys_addr_t paddr,size_t size, +unsigned long *offset, +unsigned long flags);extern struct vm_struct *get_vm_area (unsigned long size,unsigned long flags);extern struct vm_struct *get_vm_area_caller (unsigned long size,unsigned long flags,const void *caller);mm/vmalloc.c +1
-0@@ -1293,6 +1293,7 @@ static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va, vm->addr = (void *)va->va_start; vm->size = va->va_end - va->va_start; vm->caller = caller; + vm->used =1 ; va->vm = vm; va->flags |=VM_VM_AREA ;spin_unlock (&vmap_area_lock);
mm/vmalloc.c struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, · line 1387
Quoted 4 lines
mm/vmalloc.c +1
-0@@ -1383,6 +1384,68 @@ struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, NUMA_NO_NODE, GFP_KERNEL, caller); } +int vm_area_is_aready_to_free (phys_addr_t addr)
aready is not a word.
mm/vmalloc.c struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, · line 1398
Quoted 11 lines
mm/vmalloc.c +11
-0+{ +struct vmap_area *va; + + va =find_vmap_area ((unsigned long )addr); +if (!va || !(va->flags &VM_VM_AREA ) || !va->vm) +return 1 ; + +if (va->vm->used <=1 ) +return 1 ; + + --va->vm->used;
What lock protects this? You should use atomic ops here.
Quoted 31 lines
mm/vmalloc.c +31
-0+ +return 0 ; +} + +/** +* find_vm_area_paddr - find a continuous kernel virtual area using the +* physical addreess. +* @paddr: base physical address +* @size: size of the physical area range +* @offset: the start offset of the vm area +* @flags: %VM_IOREMAP for I/O mappings +* +* Search for the kernel VM area, whoes physical address starting at @paddr, +* and if the exsit VM area's size is large enough, then just return it, or +* return NULL. +*/ +struct vm_struct *find_vm_area_paddr (phys_addr_t paddr,size_t size, +unsigned long *offset, +unsigned long flags) +{ +struct vmap_area *va; + +if (!(flags &VM_IOREMAP )) +return NULL ; + +rcu_read_lock (); +list_for_each_entry_rcu (va, &vmap_area_list, list) { +phys_addr_t phys_addr; + +if (!va || !(va->flags &VM_VM_AREA ) || !va->vm) +continue ;
mm/vmalloc.c struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, · line 1439
Quoted 10 lines
mm/vmalloc.c +10
-0+ + phys_addr = va->vm->phys_addr; + +if (paddr < phys_addr || paddr + size > phys_addr + va->vm->size) +continue ; + + *offset = paddr - phys_addr; + +if (va->vm->flags &VM_IOREMAP && va->vm->size >= size) { + va->vm->used++;
What lock protects this? It looks like you are modifying this with only a rcu reader lock.
Quoted 20 lines
mm/vmalloc.c +9
-1+rcu_read_unlock (); +return va->vm; + } + } +rcu_read_unlock (); + +return NULL ; +} +/** * find_vm_area - find a continuous kernel virtual area * @addr: base address -- 1.8.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RFC][PATCH 1/2] mm/vmalloc: Add IO mapping space reused interface.
Quoted 11 lines · Rob Herring
Quoted 4 lines · Richard Lee
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers.What address or who the user is isn't really relevant.
Quoted 2 lines
And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.
Quoted 8 lines
s/malloc/vmalloc/
Quoted 3 lines
This patch add the IO mapping space reusing interface:
-find_vm_area_paddr: used to find the exsit vmalloc area usings/exsit/exist/
Yes, see the next version.
[...]
Quoted 5 lines
Quoted 5 lines
mm/vmalloc.c +5
-0+{ +struct vmap_area *va; + + va =find_vmap_area ((unsigned long )addr); +if (!va || !(va->flags &VM_VM_AREA ) || !va->vm)
Quoted 9 lines
mm/vmalloc.c struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, · line 1398
Quoted 6 lines
mm/vmalloc.c +6
-0+return 1 ; + +if (va->vm->used <=1 ) +return 1 ; + + --va->vm->used;What lock protects this? You should use atomic ops here.
Yes, it is.
[...]
Quoted 14 lines
Quoted 14 lines
mm/vmalloc.c +14
-0+if (!(flags &VM_IOREMAP )) +return NULL ; + +rcu_read_lock (); +list_for_each_entry_rcu (va, &vmap_area_list, list) { +phys_addr_t phys_addr; + +if (!va || !(va->flags &VM_VM_AREA ) || !va->vm) +continue ; + + phys_addr = va->vm->phys_addr; + +if (paddr < phys_addr || paddr + size > phys_addr + va->vm->size) +continue ;
Quoted 8 lines
mm/vmalloc.c struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, · line 1439
Quoted 5 lines
mm/vmalloc.c +5
-0+ + *offset = paddr - phys_addr; + +if (va->vm->flags &VM_IOREMAP && va->vm->size >= size) { + va->vm->used++;What lock protects this? It looks like you are modifying this with only a rcu reader lock.
I'll try to use the proper lock ops for this later.
Thanks very much,
Richard
Quoted 21 lines
Quoted 21 lines
mm/vmalloc.c +9
-1+rcu_read_unlock (); +return va->vm; + } + } +rcu_read_unlock (); + +return NULL ; +} +/** * find_vm_area - find a continuous kernel virtual area * @addr: base address -- 1.8.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RFC][PATCH 2/2] ARM: ioremap: Add IO mapping space reused support.
In reply to Richard LeeQuoted 11 lines · On Tuesday 13 May 2014 09:45:08 Richard Lee wrote:
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · On Monday 12 May 2014 10:19:55 Richard Lee wrote:
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.This patch add IO mapping space reused support.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Richard Lee <[email protected]>What happens if the first driver then unmaps the area?
If the first driver will unmap the area, it shouldn't do any thing except decreasing the 'used' counter.
Ah, for some reason I didn't see your first patch that introduces that counter.
Arnd
Re: [RFC][PATCH 2/2] ARM: ioremap: Add IO mapping space reused support.
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Tuesday 13 May 2014 09:45:08 Richard Lee wrote:
Quoted 13 lines · Arnd Bergmann
Quoted 10 lines · On Monday 12 May 2014 10:19:55 Richard Lee wrote:
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.This patch add IO mapping space reused support.
Signed-off-by Richard Lee <[email protected]>
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
What happens if the first driver then unmaps the area?
If the first driver will unmap the area, it shouldn't do any thing except decreasing the 'used' counter.
Ah, for some reason I didn't see your first patch that introduces that counter.
It's "[PATCH 1/2] mm/vmalloc: Add IO mapping space reused".
Thanks,
BRs
Richard
Quoted 1 line
Arnd
Re: [RFC][PATCH 2/2] ARM: ioremap: Add IO mapping space reused support.
In reply to Richard LeeQuoted 9 lines · Richard Lee
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · On Monday 12 May 2014 10:19:55 Richard Lee wrote:
For the IO mapping, for the same physical address space maybe mapped more than one time, for example, in some SoCs:
0x20000000~0x20001000: are global control IO physical map, and this range space will be used by many drivers. And then if each driver will do the same ioremap operation, we will waste to much malloc virtual spaces.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
This patch add IO mapping space reused support.
Signed-off-by Richard Lee <[email protected]>What happens if the first driver then unmaps the area?
If the first driver will unmap the area, it shouldn't do any thing except decreasing the 'used' counter.
It's still racy. What if the first driver manage to decrement the used counter, unmaps the regions but doesn't yet free the vm_struct while another driver finds the vm_struct, increments the used count and assumes it can use it?
BTW, vm_area_is_aready_to_free() name implies a query but it has side-effects like decrementing the counter.
Signature · 1 line
Catalin