[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH v2 7/8] arm/mem_access: Add short-descriptor based gpt
This commit adds functionality to walk the guest's page tables using the short-descriptor translation table format for both ARMv7 and ARMv8. The implementation is based on ARM DDI 0487A-g G4-4189 and ARM DDI 0406C-b B3-1506. Signed-off-by: Sergej Proskurin <proskurin@xxxxxxxxxxxxx> --- Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx> Cc: Julien Grall <julien.grall@xxxxxxx> --- xen/arch/arm/p2m.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index ea3be6f050..fa112b873c 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1558,8 +1558,129 @@ static int __p2m_walk_gpt_sd(struct p2m_domain *p2m, vaddr_t gva, paddr_t *ipa, unsigned int *perm_ro) { - /* Not implemented yet. */ - return -EFAULT; + int disabled = 1; + int32_t ttbr; + paddr_t mask; + pte_sd_t pte, *table; + struct page_info *page; + register_t ttbcr = READ_SYSREG(TCR_EL1); + unsigned int level = 0, n = ttbcr & TTBCR_N_MASK; + struct domain *d = p2m->domain; + + const paddr_t offsets[2] = { + ((paddr_t)(gva >> 20) & ((1ULL << (12 - n)) - 1)), + ((paddr_t)(gva >> 12) & ((1ULL << 8) - 1)) + }; + + /* TODO: Do the same (31 bit) with LPAE code!! */ + mask = ((1ULL << REGISTER_WIDTH_32_BIT) - 1) & + ~((1ULL << (REGISTER_WIDTH_32_BIT - n)) - 1); + + if ( n == 0 || !(gva & mask) ) + { + /* Use TTBR0 for GVA to IPA translation. */ + ttbr = READ_SYSREG64(TTBR0_EL1); + + /* If TTBCR.PD0 is set, translations using TTBR0 are disabled. */ + disabled = ( ttbcr & TTBCR_PD0 ) ? 1 : 0; + } + else + { + /* Use TTBR1 for GVA to IPA translation. */ + ttbr = READ_SYSREG64(TTBR1_EL1); + + /* If TTBCR.PD1 is set, translations using TTBR1 are disabled. */ + disabled = ( ttbcr & TTBCR_PD1 ) ? 1 : 0; + } + + if ( disabled ) + return -EFAULT; + + mask = (1ULL << (14 - n)) - 1; + page = get_page_from_gfn(d, paddr_to_pfn(ttbr & ~mask), NULL, P2M_ALLOC); + if ( !page ) + return -EFAULT; + + /* + * XXX: The 2nd level lookup table might comprise 4 concatenated 4K + * pages. Check how to map concatenated tables at once. + */ + table = __map_domain_page(page); + + /* Consider offset if n > 2. */ + if ( n > 2 ) + table = (pte_sd_t *)((unsigned long)table | (unsigned long)(ttbr & mask)); + + pte = table[offsets[level]]; + + unmap_domain_page(table); + put_page(page); + + switch ( pte.walk.dt ) { + case 0: /* Invalid mapping. */ + return -EFAULT; + + case 1: /* Large or small page. */ + level++; + + page = get_page_from_gfn(d, (pte.walk.base >> 2), NULL, P2M_ALLOC); + if ( !page ) + return -EFAULT; + + table = __map_domain_page(page); + table = (pte_sd_t *)((unsigned long)table | ((pte.walk.base & 0x3) << 10)); + + pte = table[offsets[level]]; + + unmap_domain_page(table); + put_page(page); + + if ( pte.walk.dt == 0 ) + break; + + if ( pte.walk.dt & 0x2 ) /* Small page. */ + { + mask = (1ULL << PAGE_SHIFT_4K) - 1; + *ipa = (pte.bits & ~mask) | (gva & mask); + } + else /* Large page. */ + { + mask = (1ULL << PAGE_SHIFT_64K) - 1; + *ipa = (pte.bits & ~mask) | (gva & mask); + } + + /* Set access permissions[2:0]. */ + *perm_ro = (pte.bits & 0x200) >> 9; + + break; + + case 2: /* Section. */ + case 3: /* Section or Supersection. */ + if ( !(pte.bits & (1ULL << 18)) ) /* Section */ + { + mask = (1ULL << 20) - 1; + *ipa = (pte.bits & ~mask) | (gva & mask); + } + else /* Supersection */ + { + mask = (1ULL << 24) - 1; + *ipa = (pte.bits & ~mask) | (gva & mask); + + mask = ((1ULL << 24) - 1) & ~((1ULL << 20) - 1); + *ipa |= (pte.bits & mask) << 32; + + mask = ((1ULL << 9) - 1) & ~((1ULL << 5) - 1); + *ipa |= (pte.bits & mask) << 36; + } + + /* Set access permission[2]. */ + *perm_ro = (pte.bits & 0x8000) >> 15; + } + + if ( pte.walk.dt == 0 ) + return -EFAULT; + + return 0; } /* -- 2.12.2 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |