Skip to content

Commit 8fc4898

Browse files
committed
vmalloc: add un/map_kernel_range_noflush()
Impact: two more public map/unmap functions Implement map_kernel_range_noflush() and unmap_kernel_range_noflush(). These functions respectively map and unmap address range in kernel VM area but doesn't do any vcache or tlb flushing. These will be used by new percpu allocator. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Nick Piggin <nickpiggin@yahoo.com.au>
1 parent f0aa661 commit 8fc4898

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

‎include/linux/vmalloc.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ extern struct vm_struct *remove_vm_area(const void *addr);
9191

9292
extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
9393
struct page ***pages);
94+
extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
95+
pgprot_t prot, struct page **pages);
96+
extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
9497
extern void unmap_kernel_range(unsigned long addr, unsigned long size);
9598

9699
/* Allocate/destroy a 'vmalloc' VM area. */

‎mm/vmalloc.c‎

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
153153
*
154154
* Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
155155
*/
156-
static int vmap_page_range(unsigned long start, unsigned long end,
157-
pgprot_t prot, struct page **pages)
156+
static int vmap_page_range_noflush(unsigned long start, unsigned long end,
157+
pgprot_t prot, struct page **pages)
158158
{
159159
pgd_t *pgd;
160160
unsigned long next;
@@ -170,13 +170,22 @@ static int vmap_page_range(unsigned long start, unsigned long end,
170170
if (err)
171171
break;
172172
} while (pgd++, addr = next, addr != end);
173-
flush_cache_vmap(start, end);
174173

175174
if (unlikely(err))
176175
return err;
177176
return nr;
178177
}
179178

179+
static int vmap_page_range(unsigned long start, unsigned long end,
180+
pgprot_t prot, struct page **pages)
181+
{
182+
int ret;
183+
184+
ret = vmap_page_range_noflush(start, end, prot, pages);
185+
flush_cache_vmap(start, end);
186+
return ret;
187+
}
188+
180189
static inline int is_vmalloc_or_module_addr(const void *x)
181190
{
182191
/*
@@ -1033,6 +1042,58 @@ void __init vmalloc_init(void)
10331042
vmap_initialized = true;
10341043
}
10351044

1045+
/**
1046+
* map_kernel_range_noflush - map kernel VM area with the specified pages
1047+
* @addr: start of the VM area to map
1048+
* @size: size of the VM area to map
1049+
* @prot: page protection flags to use
1050+
* @pages: pages to map
1051+
*
1052+
* Map PFN_UP(@size) pages at @addr. The VM area @addr and @size
1053+
* specify should have been allocated using get_vm_area() and its
1054+
* friends.
1055+
*
1056+
* NOTE:
1057+
* This function does NOT do any cache flushing. The caller is
1058+
* responsible for calling flush_cache_vmap() on to-be-mapped areas
1059+
* before calling this function.
1060+
*
1061+
* RETURNS:
1062+
* The number of pages mapped on success, -errno on failure.
1063+
*/
1064+
int map_kernel_range_noflush(unsigned long addr, unsigned long size,
1065+
pgprot_t prot, struct page **pages)
1066+
{
1067+
return vmap_page_range_noflush(addr, addr + size, prot, pages);
1068+
}
1069+
1070+
/**
1071+
* unmap_kernel_range_noflush - unmap kernel VM area
1072+
* @addr: start of the VM area to unmap
1073+
* @size: size of the VM area to unmap
1074+
*
1075+
* Unmap PFN_UP(@size) pages at @addr. The VM area @addr and @size
1076+
* specify should have been allocated using get_vm_area() and its
1077+
* friends.
1078+
*
1079+
* NOTE:
1080+
* This function does NOT do any cache flushing. The caller is
1081+
* responsible for calling flush_cache_vunmap() on to-be-mapped areas
1082+
* before calling this function and flush_tlb_kernel_range() after.
1083+
*/
1084+
void unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
1085+
{
1086+
vunmap_page_range(addr, addr + size);
1087+
}
1088+
1089+
/**
1090+
* unmap_kernel_range - unmap kernel VM area and flush cache and TLB
1091+
* @addr: start of the VM area to unmap
1092+
* @size: size of the VM area to unmap
1093+
*
1094+
* Similar to unmap_kernel_range_noflush() but flushes vcache before
1095+
* the unmapping and tlb after.
1096+
*/
10361097
void unmap_kernel_range(unsigned long addr, unsigned long size)
10371098
{
10381099
unsigned long end = addr + size;

0 commit comments

Comments
 (0)