diff mbox

[v6,10/26] KVM: arm/arm64: Fix idmap size and alignment

Message ID 20180314165049.30105-11-marc.zyngier@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marc Zyngier March 14, 2018, 4:50 p.m. UTC
Although the idmap section of KVM can only be at most 4kB and
must be aligned on a 4kB boundary, the rest of the code expects
it to be page aligned. Things get messy when tearing down the
HYP page tables when PAGE_SIZE is 64K, and the idmap section isn't
64K aligned.

Let's fix this by computing aligned boundaries that the HYP code
will use.

Reported-by: James Morse <james.morse@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 virt/kvm/arm/mmu.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

James Morse March 15, 2018, 7:15 p.m. UTC | #1
On 14/03/18 16:50, Marc Zyngier wrote:
> Although the idmap section of KVM can only be at most 4kB and
> must be aligned on a 4kB boundary, the rest of the code expects
> it to be page aligned. Things get messy when tearing down the
> HYP page tables when PAGE_SIZE is 64K, and the idmap section isn't
> 64K aligned.
> 
> Let's fix this by computing aligned boundaries that the HYP code
> will use.

> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
> index 0e5cfffb4c21..a9e0513868e9 100644
> --- a/virt/kvm/arm/mmu.c
> +++ b/virt/kvm/arm/mmu.c
> @@ -1815,7 +1815,9 @@ int kvm_mmu_init(void)
>  	int err;
>  
>  	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
> +	hyp_idmap_start = ALIGN_DOWN(hyp_idmap_start, PAGE_SIZE);
>  	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
> +	hyp_idmap_end = ALIGN(hyp_idmap_end, PAGE_SIZE);
>  	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
>  
>  	/*


This makes the:
| hyp_idmap_start != (unsigned long)__hyp_idmap_text_start

check below look funny, but that must be for 32bit which only has 4K pages (I
think), so its behaviour hasn't changed.

Reviewed-by: James Morse <james.morse@arm.com>


Thanks,

James
Marc Zyngier March 16, 2018, 8:55 a.m. UTC | #2
On 15/03/18 19:15, James Morse wrote:
> On 14/03/18 16:50, Marc Zyngier wrote:
>> Although the idmap section of KVM can only be at most 4kB and
>> must be aligned on a 4kB boundary, the rest of the code expects
>> it to be page aligned. Things get messy when tearing down the
>> HYP page tables when PAGE_SIZE is 64K, and the idmap section isn't
>> 64K aligned.
>>
>> Let's fix this by computing aligned boundaries that the HYP code
>> will use.
> 
>> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
>> index 0e5cfffb4c21..a9e0513868e9 100644
>> --- a/virt/kvm/arm/mmu.c
>> +++ b/virt/kvm/arm/mmu.c
>> @@ -1815,7 +1815,9 @@ int kvm_mmu_init(void)
>>  	int err;
>>  
>>  	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
>> +	hyp_idmap_start = ALIGN_DOWN(hyp_idmap_start, PAGE_SIZE);
>>  	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
>> +	hyp_idmap_end = ALIGN(hyp_idmap_end, PAGE_SIZE);
>>  	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
>>  
>>  	/*
> 
> 
> This makes the:
> | hyp_idmap_start != (unsigned long)__hyp_idmap_text_start
> 
> check below look funny, but that must be for 32bit which only has 4K pages (I
> think), so its behaviour hasn't changed.

Yes, that's to handle the 2/2 split on 32bit where some funnies may
happen, see d2896d4b55b2 ("arm: KVM: Fix idmap overlap detection when
the kernel is idmap'ed").

> Reviewed-by: James Morse <james.morse@arm.com>

Thanks,

	M.
diff mbox

Patch

diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index 0e5cfffb4c21..a9e0513868e9 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -1815,7 +1815,9 @@  int kvm_mmu_init(void)
 	int err;
 
 	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
+	hyp_idmap_start = ALIGN_DOWN(hyp_idmap_start, PAGE_SIZE);
 	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
+	hyp_idmap_end = ALIGN(hyp_idmap_end, PAGE_SIZE);
 	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
 
 	/*