diff options
Diffstat (limited to 'mm/memory.c')
-rw-r--r-- | mm/memory.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/mm/memory.c b/mm/memory.c index e7066e71dfa3..044feb7e7134 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -1448,6 +1448,100 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, | |||
1448 | } | 1448 | } |
1449 | EXPORT_SYMBOL(remap_pfn_range); | 1449 | EXPORT_SYMBOL(remap_pfn_range); |
1450 | 1450 | ||
1451 | static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, | ||
1452 | unsigned long addr, unsigned long end, | ||
1453 | pte_fn_t fn, void *data) | ||
1454 | { | ||
1455 | pte_t *pte; | ||
1456 | int err; | ||
1457 | struct page *pmd_page; | ||
1458 | spinlock_t *ptl = ptl; /* Suppress gcc warning */ | ||
1459 | |||
1460 | pte = (mm == &init_mm) ? | ||
1461 | pte_alloc_kernel(pmd, addr) : | ||
1462 | pte_alloc_map_lock(mm, pmd, addr, &ptl); | ||
1463 | if (!pte) | ||
1464 | return -ENOMEM; | ||
1465 | |||
1466 | BUG_ON(pmd_huge(*pmd)); | ||
1467 | |||
1468 | pmd_page = pmd_page(*pmd); | ||
1469 | |||
1470 | do { | ||
1471 | err = fn(pte, pmd_page, addr, data); | ||
1472 | if (err) | ||
1473 | break; | ||
1474 | } while (pte++, addr += PAGE_SIZE, addr != end); | ||
1475 | |||
1476 | if (mm != &init_mm) | ||
1477 | pte_unmap_unlock(pte-1, ptl); | ||
1478 | return err; | ||
1479 | } | ||
1480 | |||
1481 | static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, | ||
1482 | unsigned long addr, unsigned long end, | ||
1483 | pte_fn_t fn, void *data) | ||
1484 | { | ||
1485 | pmd_t *pmd; | ||
1486 | unsigned long next; | ||
1487 | int err; | ||
1488 | |||
1489 | pmd = pmd_alloc(mm, pud, addr); | ||
1490 | if (!pmd) | ||
1491 | return -ENOMEM; | ||
1492 | do { | ||
1493 | next = pmd_addr_end(addr, end); | ||
1494 | err = apply_to_pte_range(mm, pmd, addr, next, fn, data); | ||
1495 | if (err) | ||
1496 | break; | ||
1497 | } while (pmd++, addr = next, addr != end); | ||
1498 | return err; | ||
1499 | } | ||
1500 | |||
1501 | static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd, | ||
1502 | unsigned long addr, unsigned long end, | ||
1503 | pte_fn_t fn, void *data) | ||
1504 | { | ||
1505 | pud_t *pud; | ||
1506 | unsigned long next; | ||
1507 | int err; | ||
1508 | |||
1509 | pud = pud_alloc(mm, pgd, addr); | ||
1510 | if (!pud) | ||
1511 | return -ENOMEM; | ||
1512 | do { | ||
1513 | next = pud_addr_end(addr, end); | ||
1514 | err = apply_to_pmd_range(mm, pud, addr, next, fn, data); | ||
1515 | if (err) | ||
1516 | break; | ||
1517 | } while (pud++, addr = next, addr != end); | ||
1518 | return err; | ||
1519 | } | ||
1520 | |||
1521 | /* | ||
1522 | * Scan a region of virtual memory, filling in page tables as necessary | ||
1523 | * and calling a provided function on each leaf page table. | ||
1524 | */ | ||
1525 | int apply_to_page_range(struct mm_struct *mm, unsigned long addr, | ||
1526 | unsigned long size, pte_fn_t fn, void *data) | ||
1527 | { | ||
1528 | pgd_t *pgd; | ||
1529 | unsigned long next; | ||
1530 | unsigned long end = addr + size; | ||
1531 | int err; | ||
1532 | |||
1533 | BUG_ON(addr >= end); | ||
1534 | pgd = pgd_offset(mm, addr); | ||
1535 | do { | ||
1536 | next = pgd_addr_end(addr, end); | ||
1537 | err = apply_to_pud_range(mm, pgd, addr, next, fn, data); | ||
1538 | if (err) | ||
1539 | break; | ||
1540 | } while (pgd++, addr = next, addr != end); | ||
1541 | return err; | ||
1542 | } | ||
1543 | EXPORT_SYMBOL_GPL(apply_to_page_range); | ||
1544 | |||
1451 | /* | 1545 | /* |
1452 | * handle_pte_fault chooses page fault handler according to an entry | 1546 | * handle_pte_fault chooses page fault handler according to an entry |
1453 | * which was read non-atomically. Before making any commitment, on | 1547 | * which was read non-atomically. Before making any commitment, on |