|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v4 8/9] arm/mem_access: Add short-descriptor based gpt
Hi Sergej, On 20/06/17 21:33, Sergej Proskurin wrote: TTBR is a register. It cannot be signed. Why are you using paddr_t here?Looking at the code, I see very limited point of having the offsets array as you don't use a loop and also use each offset in a single place. + ((paddr_t)(gva >> 20) & ((1ULL << (12 - n)) - 1)), Why the cast? After gva is a virtual address not physical one.Also, this code is a bit cryptic to read. Can we have some documentation at least? Furthermore, it would be clearer if you first mask then shift. As it helps to understand the code. If you use GENMASK (or GENMASK_ULL if you don't extend GENMASK), this will make everything more obvious: (gva & GENMASK(31 - n, 20)) >> 20 + ((paddr_t)(gva >> 12) & ((1ULL << 8) - 1)) (gva & GENMASK(20, 12)) >> 12 + }; + + mask = ((1ULL << BITS_PER_WORD) - 1) & + ~((1ULL << (BITS_PER_WORD - n)) - 1); Same remark as on the previous patch for BITS_PER_WORD + you could use GENMASK. Looking at the documentation. For short-descriptor, the register will be 32-bit. Whilst I can understand why you use READ_SYSREG64, you should at least document it. You also probably want to have ttbr uint32_t in that case. Ditto. + + /* If TTBCR.PD1 is set, translations using TTBR1 are disabled. */ + disabled = ttbcr & TTBCR_PD1; + + /* + * TTBR1 translation always works like n==0 TTBR0 translation (ARM DDI + * 0487B.a J1-6003). + */ + n = 0; + } + + if ( disabled ) + return -EFAULT; + + /* + * The address of the descriptor for the initial lookup has the following + * format: [ttbr<31:14-n>:gva<31-n:20>:00] (ARM DDI 0487B.a J1-6003). In + * this way, the first lookup level might comprise up to four consecutive + * pages. To avoid mapping all of the pages, we simply map the page that is + * needed by the first level translation by incorporating up to 2 MSBs of + * the GVA. + */ + mask = (1ULL << (14 - n)) - 1; mask = GENMASK(31, 14); GENMASK(12, 14 - n); + table = (short_desc_t *)((unsigned long)table | (unsigned long)(ttbr & mask)); + } + + /* + * As we have considered up to 2 MSBs of the GVA for mapping the first + * level translation table, we need to make sure that we limit the table + * offset that is is indexed by GVA<31-n:20> to max 10 bits to avoid + * exceeding the page size limit. + */ + mask = ((1ULL << 10) - 1); + pte = table[offsets[level] & mask]; This looks quite complex for just reading a pte. I think it would be worth to leverage the vgic_guest_access_memory for that (same in LPAE). It would also add safety if the offsets the table is mistakenly computed (from the current code, I can't convince myself the offset will always be right). Ditto. As perms is modified in few places over the code. I would prefer if you first reset *perms at suitable value in guest_walk_tables and the use |= everywhere. This would avoid any mistake in the future where the permission is not reported correctly. See above. It is quite strange that above you use plain PAGE_SHIFT_4K which is not really related to short-descriptor (you define it in lpae.h) and here you use short-descriptor name. Please try to stay consistent. My suggestion about perms would also avoid undefined permission if the region is read-only as none of the callers today will initialize perms. + if ( !pte.sec.xn ) + *perms |= GV2M_EXEC; + } + + return 0; } /* diff --git a/xen/include/asm-arm/guest_walk.h b/xen/include/asm-arm/guest_walk.h index 4ed8476e08..d0bed0c7a2 100644 --- a/xen/include/asm-arm/guest_walk.h +++ b/xen/include/asm-arm/guest_walk.h @@ -1,6 +1,22 @@ #ifndef _XEN_GUEST_WALK_H #define _XEN_GUEST_WALK_H +/* First level translation table descriptor types used by the AArch32 + * short-descriptor translation table format. */ +#define L1DESC_INVALID (0) +#define L1DESC_PAGE_TABLE (1) +#define L1DESC_SECTION (2) +#define L1DESC_SECTION_PXN (3) + +/* Defines for section and supersection shifts. */ +#define L1DESC_SECTION_SHIFT (20) +#define L1DESC_SUPERSECTION_SHIFT (24) +#define L1DESC_SUPERSECTION_EXT_BASE1_SHIFT (32) +#define L1DESC_SUPERSECTION_EXT_BASE2_SHIFT (36) + +/* Second level translation table descriptor types. */ +#define L2DESC_INVALID (0) I think those one belongs to short-desc.h. Cheers, -- Julien Grall _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |