um: Optimize TLB operations v2
Make the code to merge mmap/munmap/mprotect operations in tlb.c common for userspace and kernel. Kernel tlb operations can now be merged as well. Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com> Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
committed by
Richard Weinberger
parent
747b254ca2
commit
a9c52c2a28
@ -37,17 +37,19 @@ struct host_vm_change {
|
|||||||
} mprotect;
|
} mprotect;
|
||||||
} u;
|
} u;
|
||||||
} ops[1];
|
} ops[1];
|
||||||
|
int userspace;
|
||||||
int index;
|
int index;
|
||||||
struct mm_id *id;
|
struct mm_struct *mm;
|
||||||
void *data;
|
void *data;
|
||||||
int force;
|
int force;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define INIT_HVC(mm, force) \
|
#define INIT_HVC(mm, force, userspace) \
|
||||||
((struct host_vm_change) \
|
((struct host_vm_change) \
|
||||||
{ .ops = { { .type = NONE } }, \
|
{ .ops = { { .type = NONE } }, \
|
||||||
.id = &mm->context.id, \
|
.mm = mm, \
|
||||||
.data = NULL, \
|
.data = NULL, \
|
||||||
|
.userspace = userspace, \
|
||||||
.index = 0, \
|
.index = 0, \
|
||||||
.force = force })
|
.force = force })
|
||||||
|
|
||||||
@ -68,18 +70,40 @@ static int do_ops(struct host_vm_change *hvc, int end,
|
|||||||
op = &hvc->ops[i];
|
op = &hvc->ops[i];
|
||||||
switch (op->type) {
|
switch (op->type) {
|
||||||
case MMAP:
|
case MMAP:
|
||||||
ret = map(hvc->id, op->u.mmap.addr, op->u.mmap.len,
|
if (hvc->userspace)
|
||||||
op->u.mmap.prot, op->u.mmap.fd,
|
ret = map(&hvc->mm->context.id, op->u.mmap.addr,
|
||||||
op->u.mmap.offset, finished, &hvc->data);
|
op->u.mmap.len, op->u.mmap.prot,
|
||||||
|
op->u.mmap.fd,
|
||||||
|
op->u.mmap.offset, finished,
|
||||||
|
&hvc->data);
|
||||||
|
else
|
||||||
|
map_memory(op->u.mmap.addr, op->u.mmap.offset,
|
||||||
|
op->u.mmap.len, 1, 1, 1);
|
||||||
break;
|
break;
|
||||||
case MUNMAP:
|
case MUNMAP:
|
||||||
ret = unmap(hvc->id, op->u.munmap.addr,
|
if (hvc->userspace)
|
||||||
op->u.munmap.len, finished, &hvc->data);
|
ret = unmap(&hvc->mm->context.id,
|
||||||
|
op->u.munmap.addr,
|
||||||
|
op->u.munmap.len, finished,
|
||||||
|
&hvc->data);
|
||||||
|
else
|
||||||
|
ret = os_unmap_memory(
|
||||||
|
(void *) op->u.munmap.addr,
|
||||||
|
op->u.munmap.len);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MPROTECT:
|
case MPROTECT:
|
||||||
ret = protect(hvc->id, op->u.mprotect.addr,
|
if (hvc->userspace)
|
||||||
op->u.mprotect.len, op->u.mprotect.prot,
|
ret = protect(&hvc->mm->context.id,
|
||||||
finished, &hvc->data);
|
op->u.mprotect.addr,
|
||||||
|
op->u.mprotect.len,
|
||||||
|
op->u.mprotect.prot,
|
||||||
|
finished, &hvc->data);
|
||||||
|
else
|
||||||
|
ret = os_protect_memory(
|
||||||
|
(void *) op->u.mprotect.addr,
|
||||||
|
op->u.mprotect.len,
|
||||||
|
1, 1, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printk(KERN_ERR "Unknown op type %d in do_ops\n",
|
printk(KERN_ERR "Unknown op type %d in do_ops\n",
|
||||||
@ -100,9 +124,12 @@ static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len,
|
|||||||
{
|
{
|
||||||
__u64 offset;
|
__u64 offset;
|
||||||
struct host_vm_op *last;
|
struct host_vm_op *last;
|
||||||
int fd, ret = 0;
|
int fd = -1, ret = 0;
|
||||||
|
|
||||||
fd = phys_mapping(phys, &offset);
|
if (hvc->userspace)
|
||||||
|
fd = phys_mapping(phys, &offset);
|
||||||
|
else
|
||||||
|
offset = phys;
|
||||||
if (hvc->index != 0) {
|
if (hvc->index != 0) {
|
||||||
last = &hvc->ops[hvc->index - 1];
|
last = &hvc->ops[hvc->index - 1];
|
||||||
if ((last->type == MMAP) &&
|
if ((last->type == MMAP) &&
|
||||||
@ -277,9 +304,9 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
|
|||||||
pgd_t *pgd;
|
pgd_t *pgd;
|
||||||
struct host_vm_change hvc;
|
struct host_vm_change hvc;
|
||||||
unsigned long addr = start_addr, next;
|
unsigned long addr = start_addr, next;
|
||||||
int ret = 0;
|
int ret = 0, userspace = 1;
|
||||||
|
|
||||||
hvc = INIT_HVC(mm, force);
|
hvc = INIT_HVC(mm, force, userspace);
|
||||||
pgd = pgd_offset(mm, addr);
|
pgd = pgd_offset(mm, addr);
|
||||||
do {
|
do {
|
||||||
next = pgd_addr_end(addr, end_addr);
|
next = pgd_addr_end(addr, end_addr);
|
||||||
@ -314,9 +341,11 @@ static int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)
|
|||||||
pmd_t *pmd;
|
pmd_t *pmd;
|
||||||
pte_t *pte;
|
pte_t *pte;
|
||||||
unsigned long addr, last;
|
unsigned long addr, last;
|
||||||
int updated = 0, err;
|
int updated = 0, err = 0, force = 0, userspace = 0;
|
||||||
|
struct host_vm_change hvc;
|
||||||
|
|
||||||
mm = &init_mm;
|
mm = &init_mm;
|
||||||
|
hvc = INIT_HVC(mm, force, userspace);
|
||||||
for (addr = start; addr < end;) {
|
for (addr = start; addr < end;) {
|
||||||
pgd = pgd_offset(mm, addr);
|
pgd = pgd_offset(mm, addr);
|
||||||
if (!pgd_present(*pgd)) {
|
if (!pgd_present(*pgd)) {
|
||||||
@ -325,8 +354,7 @@ static int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)
|
|||||||
last = end;
|
last = end;
|
||||||
if (pgd_newpage(*pgd)) {
|
if (pgd_newpage(*pgd)) {
|
||||||
updated = 1;
|
updated = 1;
|
||||||
err = os_unmap_memory((void *) addr,
|
err = add_munmap(addr, last - addr, &hvc);
|
||||||
last - addr);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
panic("munmap failed, errno = %d\n",
|
panic("munmap failed, errno = %d\n",
|
||||||
-err);
|
-err);
|
||||||
@ -342,8 +370,7 @@ static int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)
|
|||||||
last = end;
|
last = end;
|
||||||
if (pud_newpage(*pud)) {
|
if (pud_newpage(*pud)) {
|
||||||
updated = 1;
|
updated = 1;
|
||||||
err = os_unmap_memory((void *) addr,
|
err = add_munmap(addr, last - addr, &hvc);
|
||||||
last - addr);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
panic("munmap failed, errno = %d\n",
|
panic("munmap failed, errno = %d\n",
|
||||||
-err);
|
-err);
|
||||||
@ -359,8 +386,7 @@ static int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)
|
|||||||
last = end;
|
last = end;
|
||||||
if (pmd_newpage(*pmd)) {
|
if (pmd_newpage(*pmd)) {
|
||||||
updated = 1;
|
updated = 1;
|
||||||
err = os_unmap_memory((void *) addr,
|
err = add_munmap(addr, last - addr, &hvc);
|
||||||
last - addr);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
panic("munmap failed, errno = %d\n",
|
panic("munmap failed, errno = %d\n",
|
||||||
-err);
|
-err);
|
||||||
@ -372,22 +398,25 @@ static int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)
|
|||||||
pte = pte_offset_kernel(pmd, addr);
|
pte = pte_offset_kernel(pmd, addr);
|
||||||
if (!pte_present(*pte) || pte_newpage(*pte)) {
|
if (!pte_present(*pte) || pte_newpage(*pte)) {
|
||||||
updated = 1;
|
updated = 1;
|
||||||
err = os_unmap_memory((void *) addr,
|
err = add_munmap(addr, PAGE_SIZE, &hvc);
|
||||||
PAGE_SIZE);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
panic("munmap failed, errno = %d\n",
|
panic("munmap failed, errno = %d\n",
|
||||||
-err);
|
-err);
|
||||||
if (pte_present(*pte))
|
if (pte_present(*pte))
|
||||||
map_memory(addr,
|
err = add_mmap(addr, pte_val(*pte) & PAGE_MASK,
|
||||||
pte_val(*pte) & PAGE_MASK,
|
PAGE_SIZE, 0, &hvc);
|
||||||
PAGE_SIZE, 1, 1, 1);
|
|
||||||
}
|
}
|
||||||
else if (pte_newprot(*pte)) {
|
else if (pte_newprot(*pte)) {
|
||||||
updated = 1;
|
updated = 1;
|
||||||
os_protect_memory((void *) addr, PAGE_SIZE, 1, 1, 1);
|
err = add_mprotect(addr, PAGE_SIZE, 0, &hvc);
|
||||||
}
|
}
|
||||||
addr += PAGE_SIZE;
|
addr += PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
if (!err)
|
||||||
|
err = do_ops(&hvc, hvc.index, 1);
|
||||||
|
|
||||||
|
if (err < 0)
|
||||||
|
panic("flush_tlb_kernel failed, errno = %d\n", err);
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user