aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/xen/mmu.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/xen/mmu.c')
-rw-r--r--arch/x86/xen/mmu.c153
1 files changed, 122 insertions, 31 deletions
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index 0ccccb67a99..3dd53f997b1 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -48,6 +48,8 @@
48#include <linux/memblock.h> 48#include <linux/memblock.h>
49#include <linux/seq_file.h> 49#include <linux/seq_file.h>
50 50
51#include <trace/events/xen.h>
52
51#include <asm/pgtable.h> 53#include <asm/pgtable.h>
52#include <asm/tlbflush.h> 54#include <asm/tlbflush.h>
53#include <asm/fixmap.h> 55#include <asm/fixmap.h>
@@ -194,6 +196,8 @@ void xen_set_domain_pte(pte_t *ptep, pte_t pteval, unsigned domid)
194 struct multicall_space mcs; 196 struct multicall_space mcs;
195 struct mmu_update *u; 197 struct mmu_update *u;
196 198
199 trace_xen_mmu_set_domain_pte(ptep, pteval, domid);
200
197 mcs = xen_mc_entry(sizeof(*u)); 201 mcs = xen_mc_entry(sizeof(*u));
198 u = mcs.args; 202 u = mcs.args;
199 203
@@ -225,6 +229,24 @@ static void xen_extend_mmu_update(const struct mmu_update *update)
225 *u = *update; 229 *u = *update;
226} 230}
227 231
232static void xen_extend_mmuext_op(const struct mmuext_op *op)
233{
234 struct multicall_space mcs;
235 struct mmuext_op *u;
236
237 mcs = xen_mc_extend_args(__HYPERVISOR_mmuext_op, sizeof(*u));
238
239 if (mcs.mc != NULL) {
240 mcs.mc->args[1]++;
241 } else {
242 mcs = __xen_mc_entry(sizeof(*u));
243 MULTI_mmuext_op(mcs.mc, mcs.args, 1, NULL, DOMID_SELF);
244 }
245
246 u = mcs.args;
247 *u = *op;
248}
249
228static void xen_set_pmd_hyper(pmd_t *ptr, pmd_t val) 250static void xen_set_pmd_hyper(pmd_t *ptr, pmd_t val)
229{ 251{
230 struct mmu_update u; 252 struct mmu_update u;
@@ -245,6 +267,8 @@ static void xen_set_pmd_hyper(pmd_t *ptr, pmd_t val)
245 267
246static void xen_set_pmd(pmd_t *ptr, pmd_t val) 268static void xen_set_pmd(pmd_t *ptr, pmd_t val)
247{ 269{
270 trace_xen_mmu_set_pmd(ptr, val);
271
248 /* If page is not pinned, we can just update the entry 272 /* If page is not pinned, we can just update the entry
249 directly */ 273 directly */
250 if (!xen_page_pinned(ptr)) { 274 if (!xen_page_pinned(ptr)) {
@@ -282,22 +306,30 @@ static bool xen_batched_set_pte(pte_t *ptep, pte_t pteval)
282 return true; 306 return true;
283} 307}
284 308
285static void xen_set_pte(pte_t *ptep, pte_t pteval) 309static inline void __xen_set_pte(pte_t *ptep, pte_t pteval)
286{ 310{
287 if (!xen_batched_set_pte(ptep, pteval)) 311 if (!xen_batched_set_pte(ptep, pteval))
288 native_set_pte(ptep, pteval); 312 native_set_pte(ptep, pteval);
289} 313}
290 314
315static void xen_set_pte(pte_t *ptep, pte_t pteval)
316{
317 trace_xen_mmu_set_pte(ptep, pteval);
318 __xen_set_pte(ptep, pteval);
319}
320
291static void xen_set_pte_at(struct mm_struct *mm, unsigned long addr, 321static void xen_set_pte_at(struct mm_struct *mm, unsigned long addr,
292 pte_t *ptep, pte_t pteval) 322 pte_t *ptep, pte_t pteval)
293{ 323{
294 xen_set_pte(ptep, pteval); 324 trace_xen_mmu_set_pte_at(mm, addr, ptep, pteval);
325 __xen_set_pte(ptep, pteval);
295} 326}
296 327
297pte_t xen_ptep_modify_prot_start(struct mm_struct *mm, 328pte_t xen_ptep_modify_prot_start(struct mm_struct *mm,
298 unsigned long addr, pte_t *ptep) 329 unsigned long addr, pte_t *ptep)
299{ 330{
300 /* Just return the pte as-is. We preserve the bits on commit */ 331 /* Just return the pte as-is. We preserve the bits on commit */
332 trace_xen_mmu_ptep_modify_prot_start(mm, addr, ptep, *ptep);
301 return *ptep; 333 return *ptep;
302} 334}
303 335
@@ -306,6 +338,7 @@ void xen_ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
306{ 338{
307 struct mmu_update u; 339 struct mmu_update u;
308 340
341 trace_xen_mmu_ptep_modify_prot_commit(mm, addr, ptep, pte);
309 xen_mc_batch(); 342 xen_mc_batch();
310 343
311 u.ptr = virt_to_machine(ptep).maddr | MMU_PT_UPDATE_PRESERVE_AD; 344 u.ptr = virt_to_machine(ptep).maddr | MMU_PT_UPDATE_PRESERVE_AD;
@@ -530,6 +563,8 @@ static void xen_set_pud_hyper(pud_t *ptr, pud_t val)
530 563
531static void xen_set_pud(pud_t *ptr, pud_t val) 564static void xen_set_pud(pud_t *ptr, pud_t val)
532{ 565{
566 trace_xen_mmu_set_pud(ptr, val);
567
533 /* If page is not pinned, we can just update the entry 568 /* If page is not pinned, we can just update the entry
534 directly */ 569 directly */
535 if (!xen_page_pinned(ptr)) { 570 if (!xen_page_pinned(ptr)) {
@@ -543,17 +578,20 @@ static void xen_set_pud(pud_t *ptr, pud_t val)
543#ifdef CONFIG_X86_PAE 578#ifdef CONFIG_X86_PAE
544static void xen_set_pte_atomic(pte_t *ptep, pte_t pte) 579static void xen_set_pte_atomic(pte_t *ptep, pte_t pte)
545{ 580{
581 trace_xen_mmu_set_pte_atomic(ptep, pte);
546 set_64bit((u64 *)ptep, native_pte_val(pte)); 582 set_64bit((u64 *)ptep, native_pte_val(pte));
547} 583}
548 584
549static void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 585static void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
550{ 586{
587 trace_xen_mmu_pte_clear(mm, addr, ptep);
551 if (!xen_batched_set_pte(ptep, native_make_pte(0))) 588 if (!xen_batched_set_pte(ptep, native_make_pte(0)))
552 native_pte_clear(mm, addr, ptep); 589 native_pte_clear(mm, addr, ptep);
553} 590}
554 591
555static void xen_pmd_clear(pmd_t *pmdp) 592static void xen_pmd_clear(pmd_t *pmdp)
556{ 593{
594 trace_xen_mmu_pmd_clear(pmdp);
557 set_pmd(pmdp, __pmd(0)); 595 set_pmd(pmdp, __pmd(0));
558} 596}
559#endif /* CONFIG_X86_PAE */ 597#endif /* CONFIG_X86_PAE */
@@ -629,6 +667,8 @@ static void xen_set_pgd(pgd_t *ptr, pgd_t val)
629{ 667{
630 pgd_t *user_ptr = xen_get_user_pgd(ptr); 668 pgd_t *user_ptr = xen_get_user_pgd(ptr);
631 669
670 trace_xen_mmu_set_pgd(ptr, user_ptr, val);
671
632 /* If page is not pinned, we can just update the entry 672 /* If page is not pinned, we can just update the entry
633 directly */ 673 directly */
634 if (!xen_page_pinned(ptr)) { 674 if (!xen_page_pinned(ptr)) {
@@ -788,14 +828,12 @@ static void xen_pte_unlock(void *v)
788 828
789static void xen_do_pin(unsigned level, unsigned long pfn) 829static void xen_do_pin(unsigned level, unsigned long pfn)
790{ 830{
791 struct mmuext_op *op; 831 struct mmuext_op op;
792 struct multicall_space mcs;
793 832
794 mcs = __xen_mc_entry(sizeof(*op)); 833 op.cmd = level;
795 op = mcs.args; 834 op.arg1.mfn = pfn_to_mfn(pfn);
796 op->cmd = level; 835
797 op->arg1.mfn = pfn_to_mfn(pfn); 836 xen_extend_mmuext_op(&op);
798 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
799} 837}
800 838
801static int xen_pin_page(struct mm_struct *mm, struct page *page, 839static int xen_pin_page(struct mm_struct *mm, struct page *page,
@@ -863,6 +901,8 @@ static int xen_pin_page(struct mm_struct *mm, struct page *page,
863 read-only, and can be pinned. */ 901 read-only, and can be pinned. */
864static void __xen_pgd_pin(struct mm_struct *mm, pgd_t *pgd) 902static void __xen_pgd_pin(struct mm_struct *mm, pgd_t *pgd)
865{ 903{
904 trace_xen_mmu_pgd_pin(mm, pgd);
905
866 xen_mc_batch(); 906 xen_mc_batch();
867 907
868 if (__xen_pgd_walk(mm, pgd, xen_pin_page, USER_LIMIT)) { 908 if (__xen_pgd_walk(mm, pgd, xen_pin_page, USER_LIMIT)) {
@@ -988,6 +1028,8 @@ static int xen_unpin_page(struct mm_struct *mm, struct page *page,
988/* Release a pagetables pages back as normal RW */ 1028/* Release a pagetables pages back as normal RW */
989static void __xen_pgd_unpin(struct mm_struct *mm, pgd_t *pgd) 1029static void __xen_pgd_unpin(struct mm_struct *mm, pgd_t *pgd)
990{ 1030{
1031 trace_xen_mmu_pgd_unpin(mm, pgd);
1032
991 xen_mc_batch(); 1033 xen_mc_batch();
992 1034
993 xen_do_pin(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd))); 1035 xen_do_pin(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd)));
@@ -1196,6 +1238,8 @@ static void xen_flush_tlb(void)
1196 struct mmuext_op *op; 1238 struct mmuext_op *op;
1197 struct multicall_space mcs; 1239 struct multicall_space mcs;
1198 1240
1241 trace_xen_mmu_flush_tlb(0);
1242
1199 preempt_disable(); 1243 preempt_disable();
1200 1244
1201 mcs = xen_mc_entry(sizeof(*op)); 1245 mcs = xen_mc_entry(sizeof(*op));
@@ -1214,6 +1258,8 @@ static void xen_flush_tlb_single(unsigned long addr)
1214 struct mmuext_op *op; 1258 struct mmuext_op *op;
1215 struct multicall_space mcs; 1259 struct multicall_space mcs;
1216 1260
1261 trace_xen_mmu_flush_tlb_single(addr);
1262
1217 preempt_disable(); 1263 preempt_disable();
1218 1264
1219 mcs = xen_mc_entry(sizeof(*op)); 1265 mcs = xen_mc_entry(sizeof(*op));
@@ -1240,6 +1286,8 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
1240 } *args; 1286 } *args;
1241 struct multicall_space mcs; 1287 struct multicall_space mcs;
1242 1288
1289 trace_xen_mmu_flush_tlb_others(cpus, mm, va);
1290
1243 if (cpumask_empty(cpus)) 1291 if (cpumask_empty(cpus))
1244 return; /* nothing to do */ 1292 return; /* nothing to do */
1245 1293
@@ -1275,10 +1323,11 @@ static void set_current_cr3(void *v)
1275 1323
1276static void __xen_write_cr3(bool kernel, unsigned long cr3) 1324static void __xen_write_cr3(bool kernel, unsigned long cr3)
1277{ 1325{
1278 struct mmuext_op *op; 1326 struct mmuext_op op;
1279 struct multicall_space mcs;
1280 unsigned long mfn; 1327 unsigned long mfn;
1281 1328
1329 trace_xen_mmu_write_cr3(kernel, cr3);
1330
1282 if (cr3) 1331 if (cr3)
1283 mfn = pfn_to_mfn(PFN_DOWN(cr3)); 1332 mfn = pfn_to_mfn(PFN_DOWN(cr3));
1284 else 1333 else
@@ -1286,13 +1335,10 @@ static void __xen_write_cr3(bool kernel, unsigned long cr3)
1286 1335
1287 WARN_ON(mfn == 0 && kernel); 1336 WARN_ON(mfn == 0 && kernel);
1288 1337
1289 mcs = __xen_mc_entry(sizeof(*op)); 1338 op.cmd = kernel ? MMUEXT_NEW_BASEPTR : MMUEXT_NEW_USER_BASEPTR;
1290 1339 op.arg1.mfn = mfn;
1291 op = mcs.args;
1292 op->cmd = kernel ? MMUEXT_NEW_BASEPTR : MMUEXT_NEW_USER_BASEPTR;
1293 op->arg1.mfn = mfn;
1294 1340
1295 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF); 1341 xen_extend_mmuext_op(&op);
1296 1342
1297 if (kernel) { 1343 if (kernel) {
1298 percpu_write(xen_cr3, cr3); 1344 percpu_write(xen_cr3, cr3);
@@ -1451,19 +1497,52 @@ static void __init xen_release_pmd_init(unsigned long pfn)
1451 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn))); 1497 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
1452} 1498}
1453 1499
1500static inline void __pin_pagetable_pfn(unsigned cmd, unsigned long pfn)
1501{
1502 struct multicall_space mcs;
1503 struct mmuext_op *op;
1504
1505 mcs = __xen_mc_entry(sizeof(*op));
1506 op = mcs.args;
1507 op->cmd = cmd;
1508 op->arg1.mfn = pfn_to_mfn(pfn);
1509
1510 MULTI_mmuext_op(mcs.mc, mcs.args, 1, NULL, DOMID_SELF);
1511}
1512
1513static inline void __set_pfn_prot(unsigned long pfn, pgprot_t prot)
1514{
1515 struct multicall_space mcs;
1516 unsigned long addr = (unsigned long)__va(pfn << PAGE_SHIFT);
1517
1518 mcs = __xen_mc_entry(0);
1519 MULTI_update_va_mapping(mcs.mc, (unsigned long)addr,
1520 pfn_pte(pfn, prot), 0);
1521}
1522
1454/* This needs to make sure the new pte page is pinned iff its being 1523/* This needs to make sure the new pte page is pinned iff its being
1455 attached to a pinned pagetable. */ 1524 attached to a pinned pagetable. */
1456static void xen_alloc_ptpage(struct mm_struct *mm, unsigned long pfn, unsigned level) 1525static inline void xen_alloc_ptpage(struct mm_struct *mm, unsigned long pfn,
1526 unsigned level)
1457{ 1527{
1458 struct page *page = pfn_to_page(pfn); 1528 bool pinned = PagePinned(virt_to_page(mm->pgd));
1529
1530 trace_xen_mmu_alloc_ptpage(mm, pfn, level, pinned);
1531
1532 if (pinned) {
1533 struct page *page = pfn_to_page(pfn);
1459 1534
1460 if (PagePinned(virt_to_page(mm->pgd))) {
1461 SetPagePinned(page); 1535 SetPagePinned(page);
1462 1536
1463 if (!PageHighMem(page)) { 1537 if (!PageHighMem(page)) {
1464 make_lowmem_page_readonly(__va(PFN_PHYS((unsigned long)pfn))); 1538 xen_mc_batch();
1539
1540 __set_pfn_prot(pfn, PAGE_KERNEL_RO);
1541
1465 if (level == PT_PTE && USE_SPLIT_PTLOCKS) 1542 if (level == PT_PTE && USE_SPLIT_PTLOCKS)
1466 pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn); 1543 __pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn);
1544
1545 xen_mc_issue(PARAVIRT_LAZY_MMU);
1467 } else { 1546 } else {
1468 /* make sure there are no stray mappings of 1547 /* make sure there are no stray mappings of
1469 this page */ 1548 this page */
@@ -1483,15 +1562,23 @@ static void xen_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
1483} 1562}
1484 1563
1485/* This should never happen until we're OK to use struct page */ 1564/* This should never happen until we're OK to use struct page */
1486static void xen_release_ptpage(unsigned long pfn, unsigned level) 1565static inline void xen_release_ptpage(unsigned long pfn, unsigned level)
1487{ 1566{
1488 struct page *page = pfn_to_page(pfn); 1567 struct page *page = pfn_to_page(pfn);
1568 bool pinned = PagePinned(page);
1489 1569
1490 if (PagePinned(page)) { 1570 trace_xen_mmu_release_ptpage(pfn, level, pinned);
1571
1572 if (pinned) {
1491 if (!PageHighMem(page)) { 1573 if (!PageHighMem(page)) {
1574 xen_mc_batch();
1575
1492 if (level == PT_PTE && USE_SPLIT_PTLOCKS) 1576 if (level == PT_PTE && USE_SPLIT_PTLOCKS)
1493 pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, pfn); 1577 __pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, pfn);
1494 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn))); 1578
1579 __set_pfn_prot(pfn, PAGE_KERNEL);
1580
1581 xen_mc_issue(PARAVIRT_LAZY_MMU);
1495 } 1582 }
1496 ClearPagePinned(page); 1583 ClearPagePinned(page);
1497 } 1584 }
@@ -1626,15 +1713,17 @@ static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
1626void __init xen_setup_machphys_mapping(void) 1713void __init xen_setup_machphys_mapping(void)
1627{ 1714{
1628 struct xen_machphys_mapping mapping; 1715 struct xen_machphys_mapping mapping;
1629 unsigned long machine_to_phys_nr_ents;
1630 1716
1631 if (HYPERVISOR_memory_op(XENMEM_machphys_mapping, &mapping) == 0) { 1717 if (HYPERVISOR_memory_op(XENMEM_machphys_mapping, &mapping) == 0) {
1632 machine_to_phys_mapping = (unsigned long *)mapping.v_start; 1718 machine_to_phys_mapping = (unsigned long *)mapping.v_start;
1633 machine_to_phys_nr_ents = mapping.max_mfn + 1; 1719 machine_to_phys_nr = mapping.max_mfn + 1;
1634 } else { 1720 } else {
1635 machine_to_phys_nr_ents = MACH2PHYS_NR_ENTRIES; 1721 machine_to_phys_nr = MACH2PHYS_NR_ENTRIES;
1636 } 1722 }
1637 machine_to_phys_order = fls(machine_to_phys_nr_ents - 1); 1723#ifdef CONFIG_X86_32
1724 WARN_ON((machine_to_phys_mapping + (machine_to_phys_nr - 1))
1725 < machine_to_phys_mapping);
1726#endif
1638} 1727}
1639 1728
1640#ifdef CONFIG_X86_64 1729#ifdef CONFIG_X86_64
@@ -1829,6 +1918,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
1829# endif 1918# endif
1830#else 1919#else
1831 case VSYSCALL_LAST_PAGE ... VSYSCALL_FIRST_PAGE: 1920 case VSYSCALL_LAST_PAGE ... VSYSCALL_FIRST_PAGE:
1921 case VVAR_PAGE:
1832#endif 1922#endif
1833 case FIX_TEXT_POKE0: 1923 case FIX_TEXT_POKE0:
1834 case FIX_TEXT_POKE1: 1924 case FIX_TEXT_POKE1:
@@ -1869,7 +1959,8 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
1869#ifdef CONFIG_X86_64 1959#ifdef CONFIG_X86_64
1870 /* Replicate changes to map the vsyscall page into the user 1960 /* Replicate changes to map the vsyscall page into the user
1871 pagetable vsyscall mapping. */ 1961 pagetable vsyscall mapping. */
1872 if (idx >= VSYSCALL_LAST_PAGE && idx <= VSYSCALL_FIRST_PAGE) { 1962 if ((idx >= VSYSCALL_LAST_PAGE && idx <= VSYSCALL_FIRST_PAGE) ||
1963 idx == VVAR_PAGE) {
1873 unsigned long vaddr = __fix_to_virt(idx); 1964 unsigned long vaddr = __fix_to_virt(idx);
1874 set_pte_vaddr_pud(level3_user_vsyscall, vaddr, pte); 1965 set_pte_vaddr_pud(level3_user_vsyscall, vaddr, pte);
1875 } 1966 }