Skip to content

Commit c40f2f8

Browse files
Ard Biesheuvelchazy
authored andcommitted
arm/arm64: KVM: add 'writable' parameter to kvm_phys_addr_ioremap
Add support for read-only MMIO passthrough mappings by adding a 'writable' parameter to kvm_phys_addr_ioremap. For the moment, mappings will be read-write even if 'writable' is false, but once the definition of PAGE_S2_DEVICE gets changed, those mappings will be created read-only. Acked-by: Marc Zyngier <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Christoffer Dall <[email protected]>
1 parent 37b5440 commit c40f2f8

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

arch/arm/include/asm/kvm_mmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void free_hyp_pgds(void);
5050
int kvm_alloc_stage2_pgd(struct kvm *kvm);
5151
void kvm_free_stage2_pgd(struct kvm *kvm);
5252
int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
53-
phys_addr_t pa, unsigned long size);
53+
phys_addr_t pa, unsigned long size, bool writable);
5454

5555
int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run);
5656

arch/arm/kvm/mmu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache,
674674
* @size: The size of the mapping
675675
*/
676676
int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
677-
phys_addr_t pa, unsigned long size)
677+
phys_addr_t pa, unsigned long size, bool writable)
678678
{
679679
phys_addr_t addr, end;
680680
int ret = 0;
@@ -687,6 +687,9 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
687687
for (addr = guest_ipa; addr < end; addr += PAGE_SIZE) {
688688
pte_t pte = pfn_pte(pfn, PAGE_S2_DEVICE);
689689

690+
if (writable)
691+
kvm_set_s2pte_writable(&pte);
692+
690693
ret = mmu_topup_memory_cache(&cache, 2, 2);
691694
if (ret)
692695
goto out;

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void free_hyp_pgds(void);
7777
int kvm_alloc_stage2_pgd(struct kvm *kvm);
7878
void kvm_free_stage2_pgd(struct kvm *kvm);
7979
int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
80-
phys_addr_t pa, unsigned long size);
80+
phys_addr_t pa, unsigned long size, bool writable);
8181

8282
int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run);
8383

virt/kvm/arm/vgic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,8 @@ int kvm_vgic_init(struct kvm *kvm)
18991899
}
19001900

19011901
ret = kvm_phys_addr_ioremap(kvm, kvm->arch.vgic.vgic_cpu_base,
1902-
vgic->vcpu_base, KVM_VGIC_V2_CPU_SIZE);
1902+
vgic->vcpu_base, KVM_VGIC_V2_CPU_SIZE,
1903+
true);
19031904
if (ret) {
19041905
kvm_err("Unable to remap VGIC CPU to VCPU\n");
19051906
goto out;

0 commit comments

Comments
 (0)