Skip to content

Commit 394f3f0

Browse files
committed
tracing: Use vmap_page_range() to map memmap ring buffer
The code to map the physical memory retrieved by memmap currently allocates an array of pages to cover the physical memory and then calls vmap() to map it to a virtual address. Instead of using this temporary array of struct page descriptors, simply use vmap_page_range() that can directly map the contiguous physical memory to a virtual address. Link: https://lore.kernel.org/all/CAHk-=whUOfVucfJRt7E0AH+GV41ELmS4wJqxHDnui6Giddfkzw@mail.gmail.com/ Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Jann Horn <[email protected]> Link: https://lore.kernel.org/[email protected] Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 34ea8fa commit 394f3f0

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

kernel/trace/trace.c

+16-17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/irq_work.h>
5151
#include <linux/workqueue.h>
5252
#include <linux/sort.h>
53+
#include <linux/io.h> /* vmap_page_range() */
5354

5455
#include <asm/setup.h> /* COMMAND_LINE_SIZE */
5556

@@ -9796,29 +9797,27 @@ static int instance_mkdir(const char *name)
97969797
return ret;
97979798
}
97989799

9799-
static u64 map_pages(u64 start, u64 size)
9800+
static u64 map_pages(unsigned long start, unsigned long size)
98009801
{
9801-
struct page **pages;
9802-
phys_addr_t page_start;
9803-
unsigned int page_count;
9804-
unsigned int i;
9805-
void *vaddr;
9806-
9807-
page_count = DIV_ROUND_UP(size, PAGE_SIZE);
9802+
unsigned long vmap_start, vmap_end;
9803+
struct vm_struct *area;
9804+
int ret;
98089805

9809-
page_start = start;
9810-
pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
9811-
if (!pages)
9806+
area = get_vm_area(size, VM_IOREMAP);
9807+
if (!area)
98129808
return 0;
98139809

9814-
for (i = 0; i < page_count; i++) {
9815-
phys_addr_t addr = page_start + i * PAGE_SIZE;
9816-
pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
9810+
vmap_start = (unsigned long) area->addr;
9811+
vmap_end = vmap_start + size;
9812+
9813+
ret = vmap_page_range(vmap_start, vmap_end,
9814+
start, pgprot_nx(PAGE_KERNEL));
9815+
if (ret < 0) {
9816+
free_vm_area(area);
9817+
return 0;
98179818
}
9818-
vaddr = vmap(pages, page_count, VM_MAP, PAGE_KERNEL);
9819-
kfree(pages);
98209819

9821-
return (u64)(unsigned long)vaddr;
9820+
return (u64)vmap_start;
98229821
}
98239822

98249823
/**

0 commit comments

Comments
 (0)