From: Matthew Rosato <[email protected]> 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: [email protected] Fixes: 5d1abf2344 ("s390x/pci: enforce zPCI state checking") Reviewed-by: Christian Borntraeger <[email protected]> Reviewed-by: Farhan Ali <[email protected]> Signed-off-by: Matthew Rosato <[email protected]> Signed-off-by: Christian Borntraeger <[email protected]> Message-ID: <[email protected]> Signed-off-by: Cornelia Huck <[email protected]> (cherry picked from commit b8c8ec1d752661e1904d089c77d8617c4b6bfb5a) Signed-off-by: Michael Tokarev <[email protected]> diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index ef20f7645eb..b7de23c7d2c 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -770,10 +770,16 @@ int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra) goto err; } - if (end < iommu->pba || start > iommu->pal) { + if (end < start || end < iommu->pba || start > iommu->pal) { error = ERR_EVENT_OORANGE; goto err; } + /* + * If the specified range at least partially overlaps the registered + * aperture, clamp the request to the aperture and ignore the rest. + */ + sstart = MAX(start, iommu->pba); + end = MIN(end, iommu->pal + 1); retry: start = sstart; -- 2.47.3
