[PATCH v3 04/21] KVM: arm64: Use generic allocator for hyp stage-1 page-tables

Alexandru Elisei alexandru.elisei at arm.com
Wed Sep 2 10:48:51 EDT 2020


Hi Will,

On 9/2/20 12:35 PM, Will Deacon wrote:
> On Fri, Aug 28, 2020 at 05:32:16PM +0100, Alexandru Elisei wrote:
>> On 8/25/20 10:39 AM, Will Deacon wrote:
>>> Now that we have a shiny new page-table allocator, replace the hyp
>>> page-table code with calls into the new API. This also allows us to
>>> remove the extended idmap code, as we can now simply ensure that the
>>> VA size is large enough to map everything we need.
>>>
>>> Cc: Marc Zyngier <maz at kernel.org>
>>> Cc: Quentin Perret <qperret at google.com>
>>> Signed-off-by: Will Deacon <will at kernel.org>
>>> ---
>>>  arch/arm64/include/asm/kvm_mmu.h       |  78 +----
>>>  arch/arm64/include/asm/kvm_pgtable.h   |   5 +
>>>  arch/arm64/include/asm/pgtable-hwdef.h |   6 -
>>>  arch/arm64/include/asm/pgtable-prot.h  |   6 -
>>>  arch/arm64/kvm/mmu.c                   | 414 +++----------------------
>>>  5 files changed, 45 insertions(+), 464 deletions(-)
>>>
>>> [..]
>>> @@ -2356,6 +2028,7 @@ static int kvm_map_idmap_text(pgd_t *pgd)
>>>  int kvm_mmu_init(void)
>>>  {
>>>  	int err;
>>> +	u32 hyp_va_bits;
>>>  
>>>  	hyp_idmap_start = __pa_symbol(__hyp_idmap_text_start);
>>>  	hyp_idmap_start = ALIGN_DOWN(hyp_idmap_start, PAGE_SIZE);
>>> @@ -2369,6 +2042,8 @@ int kvm_mmu_init(void)
>>>  	 */
>>>  	BUG_ON((hyp_idmap_start ^ (hyp_idmap_end - 1)) & PAGE_MASK);
>>>  
>>> +	hyp_va_bits = 64 - ((idmap_t0sz & TCR_T0SZ_MASK) >> TCR_T0SZ_OFFSET);
>> idmap_t0sz is defined in mm/mmu.c as: TCR_T0SZ(VA_BITS) = (UL(64) - VA_BITS) <<
>> TCR_T0SZ_OFFSET. Looks to me like hyp_va_bits == VA_BITS.
> Careful! It can get rewritten in head.S if we determine that physical memory
> is in an awkward place and not covered by VA_BITS in an identity mapping.

I wasn't aware of that, I see now that in head.S we can change idmap_t0sz if
VA_BITS is not enough, I wasn't away of that, thank you for pointing it out!

Thanks,
Alex



More information about the linux-arm-kernel mailing list