Skip to contentSkip to conversation

KVM: arm/arm64: vgic-its: Fix restoration of unmapped collections

PATCH In review Eric Auger 3 participants 7 messages Dec 13, 2019 KVM arm64

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH 1/1 KVM: arm/arm64: vgic-its: Fix restoration of unmapped collections

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Cc [email protected] # v4.11+
Fixes ea1ad53e1e31a ("KVM: arm64: vgic-its: Collection table save/restore")
---
 virt/kvm/arm/vgic/vgic-its.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic-its.c +2 -1
index 98c7360d9fb7..17920d1b350a 100644
@@ -2475,7 +2475,8 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
 	target_addr = (u32)(val >> KVM_ITS_CTE_RDBASE_SHIFT);
 	coll_id = val & KVM_ITS_CTE_ICID_MASK;
 
-	if (target_addr >= atomic_read(&kvm->online_vcpus))
+	if (target_addr != COLLECTION_NOT_MAPPED &&
+	    target_addr >= atomic_read(&kvm->online_vcpus))
 		return -EINVAL;
 
 	collection = find_collection(its, coll_id);
Signature · 1 line
2.20.1
maintainer
#1 lore raw

Hi Eric,

Quoted 27 lines · Eric Auger

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Cc [email protected] # v4.11+
Fixes ea1ad53e1e31a ("KVM: arm64: vgic-its: Collection table save/restore")
---
 virt/kvm/arm/vgic/vgic-its.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic-its.c +2 -1
index 98c7360d9fb7..17920d1b350a 100644
@@ -2475,7 +2475,8 @@ static int vgic_its_restore_cte(struct vgic_its
 *its, gpa_t gpa, int esz)
 	target_addr = (u32)(val >> KVM_ITS_CTE_RDBASE_SHIFT);
 	coll_id = val & KVM_ITS_CTE_ICID_MASK;
 
-	if (target_addr >= atomic_read(&kvm->online_vcpus))
+	if (target_addr != COLLECTION_NOT_MAPPED &&
+	    target_addr >= atomic_read(&kvm->online_vcpus))
 		return -EINVAL;
 
Quoted 1 line

collection = find_collection(its, coll_id);

Looks good to me. Out of curiosity, how was this spotted?

Thanks,

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
author
#2 lore raw

Hi Marc,

Quoted 26 lines · Marc Zyngier

Hi Eric,

Quoted 23 lines · Eric Auger

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Cc [email protected] # v4.11+
Fixes ea1ad53e1e31a ("KVM: arm64: vgic-its: Collection table

save/restore")

---
 virt/kvm/arm/vgic/vgic-its.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic-its.c +0 -0
index 98c7360d9fb7..17920d1b350a 100644
@@ -2475,7 +2475,8 @@ static int vgic_its_restore_cte(struct vgic_its
 *its, gpa_t gpa, int esz)
      target_addr = (u32)(val >> KVM_ITS_CTE_RDBASE_SHIFT);
      coll_id = val & KVM_ITS_CTE_ICID_MASK;
 
Quoted 8 lines
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +2 -1
-    if (target_addr >= atomic_read(&kvm->online_vcpus))
+    if (target_addr != COLLECTION_NOT_MAPPED &&
+        target_addr >= atomic_read(&kvm->online_vcpus))
          return -EINVAL;
 

     collection = find_collection(its, coll_id);

Looks good to me. Out of curiosity, how was this spotted?

I am currently writing some kvm-unit-tests to better test ITS and its migration.

Thanks

Eric

Quoted 4 lines

Thanks,

        M.

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Eric Auger

Hi Eric,

Quoted 5 lines · Eric Auger

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Have you actually seen a problem and this patch fixed it? To be honest, I'm surprised to find that we can map a LPI to an unmapped collection ;) (and prevent it to be delivered to vcpu with an INT_UNMAPPED_INTERRUPT error, until someone had actually mapped the collection). After a quick glance of spec (MAPTI), just as you said, this is valid.

If Marc has no objection to this fix, please add

Thanks,
Zenghui

Quoted 14 lines
Cc [email protected] # v4.11+
Fixes ea1ad53e1e31a ("KVM: arm64: vgic-its: Collection table save/restore")
---
  virt/kvm/arm/vgic/vgic-its.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic-its.c +0 -0
index 98c7360d9fb7..17920d1b350a 100644

virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz) · line 2482

Quoted 9 lines
virt/kvm/arm/vgic/vgic-its.c +2 -1
@@ -2475,7 +2475,8 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
  	target_addr = (u32)(val >> KVM_ITS_CTE_RDBASE_SHIFT);
  	coll_id = val & KVM_ITS_CTE_ICID_MASK;
 
-	if (target_addr >= atomic_read(&kvm->online_vcpus))
+	if (target_addr != COLLECTION_NOT_MAPPED &&
+	    target_addr >= atomic_read(&kvm->online_vcpus))
  		return -EINVAL;
 
  	collection = find_collection(its, coll_id);

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

author
#4 lore raw

Hi Zenghui,

Quoted 10 lines · Zenghui Yu

Hi Eric,

Quoted 5 lines · Eric Auger

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Have you actually seen a problem and this patch fixed it?

It is not with a linux guest but with kvm-unit-test.

To be honest,

Quoted 8 lines

I'm surprised to find that we can map a LPI to an unmapped collection ;) (and prevent it to be delivered to vcpu with an INT_UNMAPPED_INTERRUPT error, until someone had actually mapped the collection). After a quick glance of spec (MAPTI), just as you said, this is valid.

If Marc has no objection to this fix, please add

Thank you for the review.

Eric

Quoted 29 lines

Thanks,
Zenghui

Quoted 23 lines
Cc [email protected] # v4.11+
Fixes ea1ad53e1e31a ("KVM: arm64: vgic-its: Collection table

save/restore")

---
  virt/kvm/arm/vgic/vgic-its.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic-its.c +2 -0
index 98c7360d9fb7..17920d1b350a 100644
@@ -2475,7 +2475,8 @@ static int vgic_its_restore_cte(struct vgic_its
 *its, gpa_t gpa, int esz)
       target_addr = (u32)(val >> KVM_ITS_CTE_RDBASE_SHIFT);
       coll_id = val & KVM_ITS_CTE_ICID_MASK;
   -    if (target_addr >= atomic_read(&kvm->online_vcpus))
+    if (target_addr != COLLECTION_NOT_MAPPED &&
+        target_addr >= atomic_read(&kvm->online_vcpus))
           return -EINVAL;
         collection = find_collection(its, coll_id);
maintainer
#5 lore raw
In reply to Zenghui Yu

Hi Zenghui,

Quoted 9 lines · Zenghui Yu

Hi Eric,

Quoted 5 lines · Eric Auger

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Quoted 5 lines

Have you actually seen a problem and this patch fixed it? To be honest, I'm surprised to find that we can map a LPI to an unmapped collection ;) (and prevent it to be delivered to vcpu with an INT_UNMAPPED_INTERRUPT error, until someone had actually mapped the collection). After a quick glance of spec (MAPTI), just as you said, this is valid.

Yes, this is one of the (many) odd bits in the architecture. And there is a bizarre wording in the MAPC description when V=0:

"Behavior is unpredictable if there are interrupts that are mapped to the specified collection, with the restriction that further translation requests from that device are ignored."

It is really odd that:

- it is unpredictable to unmap the collection with mapped interrupts, but mapping interrupts to an unmapped collection is fine

- the notion of "interrupts from that device" doesn't match any of the MAPC parameters

Do you hate the GIC already? ;-)

Quoted 3 lines

If Marc has no objection to this fix, please add

Thanks for that, I've applied it to the patch and will push out the update as soon as ra.kernel.org is reachable again.

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
reviewer
#6 lore raw

Hi Marc,

Quoted 21 lines · Marc Zyngier

Hi Zenghui,

Quoted 9 lines · Zenghui Yu

Hi Eric,

Quoted 5 lines · Eric Auger

Saving/restoring an unmapped collection is a valid scenario. For example this happens if a MAPTI command was sent, featuring an unmapped collection. At the moment the CTE fails to be restored. Only compare against the number of online vcpus if the rdist base is set.

Quoted 5 lines

Have you actually seen a problem and this patch fixed it? To be honest, I'm surprised to find that we can map a LPI to an unmapped collection ;) (and prevent it to be delivered to vcpu with an INT_UNMAPPED_INTERRUPT error, until someone had actually mapped the collection). After a quick glance of spec (MAPTI), just as you said, this is valid.

Yes, this is one of the (many) odd bits in the architecture. And there is a bizarre wording in the MAPC description when V=0:

Quoted 8 lines

"Behavior is unpredictable if there are interrupts that are mapped to the specified collection, with the restriction that further translation requests from that device are ignored."

It is really odd that:

- it is unpredictable to unmap the collection with mapped interrupts, but mapping interrupts to an unmapped collection is fine

Yes, looks odd... Without Eric's patch, I won't even notice it.

I guess that unmapping the collection with mapped interrupts will make it difficult for Hardware to manage those interrupts' internal states, but only a guess.

Quoted 2 lines

- the notion of "interrupts from that device" doesn't match any of the MAPC parameters

Looks like a writing mistake, a better statement *might be* "further translation requests targeting that ICID are ignored"?

Quoted 1 line

Do you hate the GIC already? ;-)

Not yet! (I'd like to continue being messed with GIC and see when I will hate it :)

Quoted 7 lines
Quoted 4 lines

If Marc has no objection to this fix, please add

Thanks for that, I've applied it to the patch and will push out the update as soon as ra.kernel.org is reachable again.

Thanks,
Zenghui