All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoffer Dall <cdall@linaro.org>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PULL 15/37] KVM: arm64: vgic-its: Check the device id matches TYPER DEVBITS range
Date: Tue,  9 May 2017 12:44:44 +0200	[thread overview]
Message-ID: <20170509104506.30929-16-cdall@linaro.org> (raw)
In-Reply-To: <20170509104506.30929-1-cdall@linaro.org>

From: Eric Auger <eric.auger@redhat.com>

On MAPD we currently check the device id can be stored in the device table.
Let's first check it can be encoded within the range defined by TYPER
DEVBITS.

Also check the collection ID belongs to the 16 bit range as GITS_TYPER
CIL field equals to 0.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
---
 virt/kvm/arm/vgic/vgic-its.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
index 7b95b73..bd1362e 100644
--- a/virt/kvm/arm/vgic/vgic-its.c
+++ b/virt/kvm/arm/vgic/vgic-its.c
@@ -227,6 +227,7 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,
 #define GIC_LPI_OFFSET 8192
 
 #define VITS_TYPER_IDBITS 16
+#define VITS_TYPER_DEVBITS 16
 
 /*
  * Finds and returns a collection in the ITS collection table.
@@ -427,7 +428,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,
 	 * To avoid memory waste in the guest, we keep the number of IDBits and
 	 * DevBits low - as least for the time being.
 	 */
-	reg |= 0x0f << GITS_TYPER_DEVBITS_SHIFT;
+	reg |= GIC_ENCODE_SZ(VITS_TYPER_DEVBITS, 5) << GITS_TYPER_DEVBITS_SHIFT;
 	reg |= GIC_ENCODE_SZ(VITS_TYPER_IDBITS, 5) << GITS_TYPER_IDBITS_SHIFT;
 	reg |= GIC_ENCODE_SZ(abi->ite_esz, 4) << GITS_TYPER_ITT_ENTRY_SIZE_SHIFT;
 
@@ -672,16 +673,30 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,
  * Check whether an ID can be stored into the corresponding guest table.
  * For a direct table this is pretty easy, but gets a bit nasty for
  * indirect tables. We check whether the resulting guest physical address
- * is actually valid (covered by a memslot and guest accessbible).
+ * is actually valid (covered by a memslot and guest accessible).
  * For this we have to read the respective first level entry.
  */
-static bool vgic_its_check_id(struct vgic_its *its, u64 baser, int id)
+static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id)
 {
 	int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
+	u64 indirect_ptr, type = GITS_BASER_TYPE(baser);
+	int esz = GITS_BASER_ENTRY_SIZE(baser);
 	int index;
-	u64 indirect_ptr;
 	gfn_t gfn;
-	int esz = GITS_BASER_ENTRY_SIZE(baser);
+
+	switch (type) {
+	case GITS_BASER_TYPE_DEVICE:
+		if (id >= BIT_ULL(VITS_TYPER_DEVBITS))
+			return false;
+		break;
+	case GITS_BASER_TYPE_COLLECTION:
+		/* as GITS_TYPER.CIL == 0, ITS supports 16-bit collection ID */
+		if (id >= BIT_ULL(16))
+			return false;
+		break;
+	default:
+		return false;
+	}
 
 	if (!(baser & GITS_BASER_INDIRECT)) {
 		phys_addr_t addr;
-- 
2.9.0

WARNING: multiple messages have this Message-ID (diff)
From: cdall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PULL 15/37] KVM: arm64: vgic-its: Check the device id matches TYPER DEVBITS range
Date: Tue,  9 May 2017 12:44:44 +0200	[thread overview]
Message-ID: <20170509104506.30929-16-cdall@linaro.org> (raw)
In-Reply-To: <20170509104506.30929-1-cdall@linaro.org>

From: Eric Auger <eric.auger@redhat.com>

On MAPD we currently check the device id can be stored in the device table.
Let's first check it can be encoded within the range defined by TYPER
DEVBITS.

Also check the collection ID belongs to the 16 bit range as GITS_TYPER
CIL field equals to 0.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
---
 virt/kvm/arm/vgic/vgic-its.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
index 7b95b73..bd1362e 100644
--- a/virt/kvm/arm/vgic/vgic-its.c
+++ b/virt/kvm/arm/vgic/vgic-its.c
@@ -227,6 +227,7 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,
 #define GIC_LPI_OFFSET 8192
 
 #define VITS_TYPER_IDBITS 16
+#define VITS_TYPER_DEVBITS 16
 
 /*
  * Finds and returns a collection in the ITS collection table.
@@ -427,7 +428,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,
 	 * To avoid memory waste in the guest, we keep the number of IDBits and
 	 * DevBits low - as least for the time being.
 	 */
-	reg |= 0x0f << GITS_TYPER_DEVBITS_SHIFT;
+	reg |= GIC_ENCODE_SZ(VITS_TYPER_DEVBITS, 5) << GITS_TYPER_DEVBITS_SHIFT;
 	reg |= GIC_ENCODE_SZ(VITS_TYPER_IDBITS, 5) << GITS_TYPER_IDBITS_SHIFT;
 	reg |= GIC_ENCODE_SZ(abi->ite_esz, 4) << GITS_TYPER_ITT_ENTRY_SIZE_SHIFT;
 
@@ -672,16 +673,30 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,
  * Check whether an ID can be stored into the corresponding guest table.
  * For a direct table this is pretty easy, but gets a bit nasty for
  * indirect tables. We check whether the resulting guest physical address
- * is actually valid (covered by a memslot and guest accessbible).
+ * is actually valid (covered by a memslot and guest accessible).
  * For this we have to read the respective first level entry.
  */
-static bool vgic_its_check_id(struct vgic_its *its, u64 baser, int id)
+static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id)
 {
 	int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
+	u64 indirect_ptr, type = GITS_BASER_TYPE(baser);
+	int esz = GITS_BASER_ENTRY_SIZE(baser);
 	int index;
-	u64 indirect_ptr;
 	gfn_t gfn;
-	int esz = GITS_BASER_ENTRY_SIZE(baser);
+
+	switch (type) {
+	case GITS_BASER_TYPE_DEVICE:
+		if (id >= BIT_ULL(VITS_TYPER_DEVBITS))
+			return false;
+		break;
+	case GITS_BASER_TYPE_COLLECTION:
+		/* as GITS_TYPER.CIL == 0, ITS supports 16-bit collection ID */
+		if (id >= BIT_ULL(16))
+			return false;
+		break;
+	default:
+		return false;
+	}
 
 	if (!(baser & GITS_BASER_INDIRECT)) {
 		phys_addr_t addr;
-- 
2.9.0

  parent reply	other threads:[~2017-05-09 10:44 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09 10:44 [PULL 00/37] KVM/ARM Changes for v4.12 - Round 2 Christoffer Dall
2017-05-09 10:44 ` Christoffer Dall
2017-05-09 10:44 ` [PULL 01/37] arm64: KVM: Fix decoding of Rt/Rt2 when trapping AArch32 CP accesses Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 02/37] KVM: arm/arm64: Move shared files to virt/kvm/arm Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 03/37] KVM: arm/arm64: Add ITS save/restore API documentation Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 04/37] KVM: arm/arm64: Add GICV3 pending table save " Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 05/37] KVM: arm/arm64: vgic-its: rename itte into ite Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 06/37] arm/arm64: vgic: turn vgic_find_mmio_region into public Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 07/37] KVM: arm64: vgic-its: KVM_DEV_ARM_VGIC_GRP_ITS_REGS group Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 08/37] KVM: arm/arm64: vgic: expose (un)lock_all_vcpus Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 09/37] KVM: arm64: vgic-its: Implement vgic_its_has_attr_regs and attr_regs_access Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 10/37] KVM: arm64: vgic-its: Implement vgic_mmio_uaccess_write_its_creadr Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 11/37] KVM: arm64: vgic-its: Introduce migration ABI infrastructure Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 12/37] KVM: arm64: vgic-its: Implement vgic_mmio_uaccess_write_its_iidr Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 13/37] KVM: arm64: vgic-its: Interpret MAPD Size field and check related errors Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 14/37] KVM: arm64: vgic-its: Interpret MAPD ITT_addr field Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` Christoffer Dall [this message]
2017-05-09 10:44   ` [PULL 15/37] KVM: arm64: vgic-its: Check the device id matches TYPER DEVBITS range Christoffer Dall
2017-05-09 10:44 ` [PULL 16/37] KVM: arm64: vgic-v3: vgic_v3_lpi_sync_pending_status Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 17/37] KVM: arm64: vgic-its: Read config and pending bit in add_lpi() Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 18/37] KVM: arm64: vgic-its: KVM_DEV_ARM_ITS_SAVE/RESTORE_TABLES Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 19/37] KVM: arm64: vgic-its: vgic_its_alloc_ite/device Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 20/37] KVM: arm64: vgic-its: Add infrastructure for table lookup Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 21/37] KVM: arm64: vgic-its: Collection table save/restore Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 22/37] KVM: arm64: vgic-its: vgic_its_check_id returns the entry's GPA Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 23/37] KVM: arm64: vgic-its: Device table save/restore Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 24/37] KVM: arm64: vgic-its: ITT save and restore Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 25/37] KVM: arm64: vgic-its: Fix pending table sync Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 26/37] KVM: arm64: vgic-v3: KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 27/37] KVM: arm/arm64: Clarification and relaxation to ITS save/restore ABI Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 28/37] KVM: arm/arm64: vgic: Rename kvm_vgic_vcpu_init to kvm_vgic_vcpu_enable Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 29/37] KVM: Add kvm_vcpu_get_idx to get vcpu index in kvm->vcpus Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:44 ` [PULL 30/37] KVM: arm/arm64: Refactor vgic_register_redist_iodevs Christoffer Dall
2017-05-09 10:44   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 31/37] KVM: arm/arm64: Make vgic_v3_check_base more broadly usable Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 32/37] KVM: arm/arm64: Slightly rework kvm_vgic_addr Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 33/37] KVM: arm/arm64: Register iodevs when setting redist base and creating VCPUs Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 34/37] KVM: arm/arm64: Get rid of its->initialized field Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 35/37] KVM: arm/arm64: Register ITS iodev when setting base address Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 36/37] KVM: arm/arm64: Don't call map_resources when restoring ITS tables Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:45 ` [PULL 37/37] KVM: arm/arm64: vgic-its: Cleanup after failed ITT restore Christoffer Dall
2017-05-09 10:45   ` Christoffer Dall
2017-05-09 10:52 ` [PULL 00/37] KVM/ARM Changes for v4.12 - Round 2 Paolo Bonzini
2017-05-09 10:52   ` Paolo Bonzini

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=20170509104506.30929-16-cdall@linaro.org \
    --to=cdall@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /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.