aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/virtual/kvm/devices/arm-vgic.txt4
-rw-r--r--virt/kvm/arm/vgic.c16
2 files changed, 17 insertions, 3 deletions
diff --git a/Documentation/virtual/kvm/devices/arm-vgic.txt b/Documentation/virtual/kvm/devices/arm-vgic.txt
index 5d4fd4b944cd..3fb905429e8a 100644
--- a/Documentation/virtual/kvm/devices/arm-vgic.txt
+++ b/Documentation/virtual/kvm/devices/arm-vgic.txt
@@ -20,20 +20,24 @@ Groups:
20 KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit) 20 KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit)
21 Base address in the guest physical address space of the GIC distributor 21 Base address in the guest physical address space of the GIC distributor
22 register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2. 22 register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
23 This address needs to be 4K aligned and the region covers 4 KByte.
23 24
24 KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit) 25 KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit)
25 Base address in the guest physical address space of the GIC virtual cpu 26 Base address in the guest physical address space of the GIC virtual cpu
26 interface register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2. 27 interface register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
28 This address needs to be 4K aligned and the region covers 4 KByte.
27 29
28 KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit) 30 KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit)
29 Base address in the guest physical address space of the GICv3 distributor 31 Base address in the guest physical address space of the GICv3 distributor
30 register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 32 register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
33 This address needs to be 64K aligned and the region covers 64 KByte.
31 34
32 KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit) 35 KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit)
33 Base address in the guest physical address space of the GICv3 36 Base address in the guest physical address space of the GICv3
34 redistributor register mappings. There are two 64K pages for each 37 redistributor register mappings. There are two 64K pages for each
35 VCPU and all of the redistributor pages are contiguous. 38 VCPU and all of the redistributor pages are contiguous.
36 Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 39 Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
40 This address needs to be 64K aligned.
37 41
38 42
39 KVM_DEV_ARM_VGIC_GRP_DIST_REGS 43 KVM_DEV_ARM_VGIC_GRP_DIST_REGS
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 184c6dbd5165..0cc6ab6005a0 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1683,6 +1683,7 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
1683 struct vgic_dist *vgic = &kvm->arch.vgic; 1683 struct vgic_dist *vgic = &kvm->arch.vgic;
1684 int type_needed; 1684 int type_needed;
1685 phys_addr_t *addr_ptr, block_size; 1685 phys_addr_t *addr_ptr, block_size;
1686 phys_addr_t alignment;
1686 1687
1687 mutex_lock(&kvm->lock); 1688 mutex_lock(&kvm->lock);
1688 switch (type) { 1689 switch (type) {
@@ -1690,22 +1691,26 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
1690 type_needed = KVM_DEV_TYPE_ARM_VGIC_V2; 1691 type_needed = KVM_DEV_TYPE_ARM_VGIC_V2;
1691 addr_ptr = &vgic->vgic_dist_base; 1692 addr_ptr = &vgic->vgic_dist_base;
1692 block_size = KVM_VGIC_V2_DIST_SIZE; 1693 block_size = KVM_VGIC_V2_DIST_SIZE;
1694 alignment = SZ_4K;
1693 break; 1695 break;
1694 case KVM_VGIC_V2_ADDR_TYPE_CPU: 1696 case KVM_VGIC_V2_ADDR_TYPE_CPU:
1695 type_needed = KVM_DEV_TYPE_ARM_VGIC_V2; 1697 type_needed = KVM_DEV_TYPE_ARM_VGIC_V2;
1696 addr_ptr = &vgic->vgic_cpu_base; 1698 addr_ptr = &vgic->vgic_cpu_base;
1697 block_size = KVM_VGIC_V2_CPU_SIZE; 1699 block_size = KVM_VGIC_V2_CPU_SIZE;
1700 alignment = SZ_4K;
1698 break; 1701 break;
1699#ifdef CONFIG_ARM_GIC_V3 1702#ifdef CONFIG_ARM_GIC_V3
1700 case KVM_VGIC_V3_ADDR_TYPE_DIST: 1703 case KVM_VGIC_V3_ADDR_TYPE_DIST:
1701 type_needed = KVM_DEV_TYPE_ARM_VGIC_V3; 1704 type_needed = KVM_DEV_TYPE_ARM_VGIC_V3;
1702 addr_ptr = &vgic->vgic_dist_base; 1705 addr_ptr = &vgic->vgic_dist_base;
1703 block_size = KVM_VGIC_V3_DIST_SIZE; 1706 block_size = KVM_VGIC_V3_DIST_SIZE;
1707 alignment = SZ_64K;
1704 break; 1708 break;
1705 case KVM_VGIC_V3_ADDR_TYPE_REDIST: 1709 case KVM_VGIC_V3_ADDR_TYPE_REDIST:
1706 type_needed = KVM_DEV_TYPE_ARM_VGIC_V3; 1710 type_needed = KVM_DEV_TYPE_ARM_VGIC_V3;
1707 addr_ptr = &vgic->vgic_redist_base; 1711 addr_ptr = &vgic->vgic_redist_base;
1708 block_size = KVM_VGIC_V3_REDIST_SIZE; 1712 block_size = KVM_VGIC_V3_REDIST_SIZE;
1713 alignment = SZ_64K;
1709 break; 1714 break;
1710#endif 1715#endif
1711 default: 1716 default:
@@ -1718,10 +1723,15 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
1718 goto out; 1723 goto out;
1719 } 1724 }
1720 1725
1721 if (write) 1726 if (write) {
1722 r = vgic_ioaddr_assign(kvm, addr_ptr, *addr, block_size); 1727 if (!IS_ALIGNED(*addr, alignment))
1723 else 1728 r = -EINVAL;
1729 else
1730 r = vgic_ioaddr_assign(kvm, addr_ptr, *addr,
1731 block_size);
1732 } else {
1724 *addr = *addr_ptr; 1733 *addr = *addr_ptr;
1734 }
1725 1735
1726out: 1736out:
1727 mutex_unlock(&kvm->lock); 1737 mutex_unlock(&kvm->lock);