@samitouri / QOSamiQemu / commits / b8c8ec1d75

s390x/pci: Shrink RPCIT ranges to registered window

Today, if a RPCIT instruction is presented from the guest whose range exceeds the previously-registered IOAT, QEMU will process the range so long as 1) the specified range at least partially overlaps with what was previously registered and 2) the guest has valid IOAT entries in its table. If the entries are not present (invalid), then the RPCIT will unnecessarily spend time reporting the invalid region/segment entries. Optimize this path by exiting immediately if the requested range falls completely outside of the previously-registered range or if the requested range ends before it starts (which would only occur if the guest-specified address + length would overflow a u64). Otherwise, clamp the request to only the portion of the range that overlaps with what was previously registered, effectively ignoring the portion outside of the registered range. Cc: qemu-stable@nongnu.org Fixes: 5d1abf2344 ("s390x/pci: enforce zPCI state checking") Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Reviewed-by: Farhan Ali <alifm@linux.ibm.com> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Message-ID: <20260707070728.147203-4-borntraeger@linux.ibm.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>

Matthew Rosato committed Jul 7, 2026 at 09:07 UTC b8c8ec1d752661e1904d089c77d8617c4b6bfb5a
1 file changed +7 -1
hw/s390x/s390-pci-inst.c
+7 -1
@@ -770,10 +770,16 @@ int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra)
770 goto err;
771 }
772
773 - if (end < iommu->pba || start > iommu->pal) {
773 + if (end < start || end < iommu->pba || start > iommu->pal) {
774 error = ERR_EVENT_OORANGE;
775 goto err;
776 }
777 + /*
778 + * If the specified range at least partially overlaps the registered
779 + * aperture, clamp the request to the aperture and ignore the rest.
780 + */
781 + sstart = MAX(start, iommu->pba);
782 + end = MIN(end, iommu->pal + 1);
783
784 retry:
785 start = sstart;