All of lore.kernel.org
 help / color / mirror / Atom feed
From: andre.przywara@arm.com (Andre Przywara)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 20/20] arm/arm64: KVM: force alignment of VGIC dist/CPU/redist addresses
Date: Wed, 14 Jan 2015 16:31:24 +0000	[thread overview]
Message-ID: <1421253084-9663-21-git-send-email-andre.przywara@arm.com> (raw)
In-Reply-To: <1421253084-9663-1-git-send-email-andre.przywara@arm.com>

Although the GIC architecture requires us to map the MMIO regions
only at page aligned addresses, we currently do not enforce this from
the kernel side.
Restrict any vGICv2 regions to be 4K aligned and any GICv3 regions
to be 64K aligned. Document this requirement.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Changelog:
 (new in v7)

 Documentation/virtual/kvm/devices/arm-vgic.txt |    4 ++++
 virt/kvm/arm/vgic.c                            |   16 +++++++++++++---
 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 5d4fd4b..3fb9054 100644
--- a/Documentation/virtual/kvm/devices/arm-vgic.txt
+++ b/Documentation/virtual/kvm/devices/arm-vgic.txt
@@ -20,20 +20,24 @@ Groups:
     KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit)
       Base address in the guest physical address space of the GIC distributor
       register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
+      This address needs to be 4K aligned and the region covers 4 KByte.
 
     KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit)
       Base address in the guest physical address space of the GIC virtual cpu
       interface register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
+      This address needs to be 4K aligned and the region covers 4 KByte.
 
     KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit)
       Base address in the guest physical address space of the GICv3 distributor
       register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
+      This address needs to be 64K aligned and the region covers 64 KByte.
 
     KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit)
       Base address in the guest physical address space of the GICv3
       redistributor register mappings. There are two 64K pages for each
       VCPU and all of the redistributor pages are contiguous.
       Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
+      This address needs to be 64K aligned.
 
 
   KVM_DEV_ARM_VGIC_GRP_DIST_REGS
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 184c6db..0cc6ab6 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)
 	struct vgic_dist *vgic = &kvm->arch.vgic;
 	int type_needed;
 	phys_addr_t *addr_ptr, block_size;
+	phys_addr_t alignment;
 
 	mutex_lock(&kvm->lock);
 	switch (type) {
@@ -1690,22 +1691,26 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
 		type_needed = KVM_DEV_TYPE_ARM_VGIC_V2;
 		addr_ptr = &vgic->vgic_dist_base;
 		block_size = KVM_VGIC_V2_DIST_SIZE;
+		alignment = SZ_4K;
 		break;
 	case KVM_VGIC_V2_ADDR_TYPE_CPU:
 		type_needed = KVM_DEV_TYPE_ARM_VGIC_V2;
 		addr_ptr = &vgic->vgic_cpu_base;
 		block_size = KVM_VGIC_V2_CPU_SIZE;
+		alignment = SZ_4K;
 		break;
 #ifdef CONFIG_ARM_GIC_V3
 	case KVM_VGIC_V3_ADDR_TYPE_DIST:
 		type_needed = KVM_DEV_TYPE_ARM_VGIC_V3;
 		addr_ptr = &vgic->vgic_dist_base;
 		block_size = KVM_VGIC_V3_DIST_SIZE;
+		alignment = SZ_64K;
 		break;
 	case KVM_VGIC_V3_ADDR_TYPE_REDIST:
 		type_needed = KVM_DEV_TYPE_ARM_VGIC_V3;
 		addr_ptr = &vgic->vgic_redist_base;
 		block_size = KVM_VGIC_V3_REDIST_SIZE;
+		alignment = SZ_64K;
 		break;
 #endif
 	default:
@@ -1718,10 +1723,15 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
 		goto out;
 	}
 
-	if (write)
-		r = vgic_ioaddr_assign(kvm, addr_ptr, *addr, block_size);
-	else
+	if (write) {
+		if (!IS_ALIGNED(*addr, alignment))
+			r = -EINVAL;
+		else
+			r = vgic_ioaddr_assign(kvm, addr_ptr, *addr,
+					       block_size);
+	} else {
 		*addr = *addr_ptr;
+	}
 
 out:
 	mutex_unlock(&kvm->lock);
-- 
1.7.9.5

  parent reply	other threads:[~2015-01-14 16:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 16:31 [PATCH v7 00/20] KVM GICv3 emulation Andre Przywara
2015-01-14 16:31 ` [PATCH v7 01/20] arm/arm64: KVM: rework MPIDR assignment and add accessors Andre Przywara
2015-01-14 16:31 ` [PATCH v7 02/20] arm/arm64: KVM: pass down user space provided GIC type into vGIC code Andre Przywara
2015-01-14 16:31 ` [PATCH v7 03/20] arm/arm64: KVM: refactor vgic_handle_mmio() function Andre Przywara
2015-01-14 16:31 ` [PATCH v7 04/20] arm/arm64: KVM: wrap 64 bit MMIO accesses with two 32 bit ones Andre Przywara
2015-01-14 16:31 ` [PATCH v7 05/20] arm/arm64: KVM: introduce per-VM ops Andre Przywara
2015-01-14 16:31 ` [PATCH v7 06/20] arm/arm64: KVM: move kvm_register_device_ops() into vGIC probing Andre Przywara
2015-01-14 16:31 ` [PATCH v7 07/20] arm/arm64: KVM: dont rely on a valid GICH base address Andre Przywara
2015-01-14 16:31 ` [PATCH v7 08/20] arm/arm64: KVM: make the maximum number of vCPUs a per-VM value Andre Przywara
2015-01-15 12:18   ` Christoffer Dall
2015-01-14 16:31 ` [PATCH v7 09/20] arm/arm64: KVM: make the value of ICC_SRE_EL1 a per-VM variable Andre Przywara
2015-01-14 16:31 ` [PATCH v7 10/20] arm/arm64: KVM: refactor MMIO accessors Andre Przywara
2015-01-14 16:31 ` [PATCH v7 11/20] arm/arm64: KVM: refactor/wrap vgic_set/get_attr() Andre Przywara
2015-01-14 16:31 ` [PATCH v7 12/20] arm/arm64: KVM: add vgic.h header file Andre Przywara
2015-01-14 16:31 ` [PATCH v7 13/20] arm/arm64: KVM: split GICv2 specific emulation code from vgic.c Andre Przywara
2015-01-14 16:31 ` [PATCH v7 14/20] arm/arm64: KVM: add opaque private pointer to MMIO data Andre Przywara
2015-01-14 16:31 ` [PATCH v7 15/20] arm/arm64: KVM: add virtual GICv3 distributor emulation Andre Przywara
2015-01-15 12:21   ` Christoffer Dall
2015-01-16 14:11     ` Andre Przywara
2015-01-16 18:55       ` Christoffer Dall
2015-01-14 16:31 ` [PATCH v7 16/20] arm64: GICv3: introduce symbolic names for GICv3 ICC_SGI1R_EL1 fields Andre Przywara
2015-01-14 16:31 ` [PATCH v7 17/20] arm64: KVM: add SGI generation register emulation Andre Przywara
2015-01-14 16:31 ` [PATCH v7 18/20] arm/arm64: KVM: enable kernel side of GICv3 emulation Andre Przywara
2015-01-15 12:25   ` Christoffer Dall
2015-01-14 16:31 ` [PATCH v7 19/20] arm/arm64: KVM: allow userland to request a virtual GICv3 Andre Przywara
2015-01-15 12:27   ` Christoffer Dall
2015-01-14 16:31 ` Andre Przywara [this message]
2015-01-15 12:29   ` [PATCH v7 20/20] arm/arm64: KVM: force alignment of VGIC dist/CPU/redist addresses Christoffer Dall
2015-01-19 10:55 ` [PATCH v7 00/20] KVM GICv3 emulation Andre Przywara
2015-01-19 13:07   ` Christoffer Dall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421253084-9663-21-git-send-email-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.