iommu_gas: pass size to iommu_map without rounding

Let the caller to iommu_map pass the size parameter without rounding
it up to a multiple of page size.  Let iommu_map round it up when
necessary, which is not all of the time, so that in some cases less
space is reserved.

Reviewed by:	alc, kib (previous version)
Tested by:	pho, br
Discussed with:	andrew
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D35424
This commit is contained in:
Doug Moore 2022-06-10 13:56:54 -05:00
parent 1d7c4b7d86
commit 19bb5a7244
3 changed files with 9 additions and 7 deletions

View File

@ -1483,7 +1483,8 @@ gicv3_iommu_init(device_t dev, device_t child, struct iommu_domain **domain)
ctx = iommu_get_dev_ctx(child);
if (ctx == NULL)
return (ENXIO);
error = iommu_map_msi(ctx, PAGE_SIZE, GITS_TRANSLATER,
/* Map the page containing the GITS_TRANSLATER register. */
error = iommu_map_msi(ctx, PAGE_SIZE, 0,
IOMMU_MAP_ENTRY_WRITE, IOMMU_MF_CANWAIT, &sc->ma);
*domain = iommu_get_ctx_domain(ctx);

View File

@ -594,8 +594,7 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag,
if (seg + 1 < tag->common.nsegments)
gas_flags |= IOMMU_MF_CANSPLIT;
error = iommu_map(domain, &tag->common,
round_page(offset + buflen1),
error = iommu_map(domain, &tag->common, buflen1,
offset, e_flags, gas_flags, ma + idx, &entry);
if (error != 0)
break;

View File

@ -364,7 +364,8 @@ iommu_gas_match_insert(struct iommu_gas_match_args *a)
* The page sized gap is created between consequent
* allocations to ensure that out-of-bounds accesses fault.
*/
a->entry->end = a->entry->start + a->size;
a->entry->end = a->entry->start +
roundup2(a->size + a->offset, IOMMU_PAGE_SIZE);
found = iommu_gas_rb_insert(a->domain, a->entry);
KASSERT(found, ("found dup %p start %jx size %jx",
@ -381,7 +382,8 @@ iommu_gas_lowermatch(struct iommu_gas_match_args *a, struct iommu_map_entry *ent
* If the subtree doesn't have free space for the requested allocation
* plus two guard pages, give up.
*/
if (entry->free_down < a->size + a->offset + 2 * IOMMU_PAGE_SIZE)
if (entry->free_down < 2 * IOMMU_PAGE_SIZE +
roundup2(a->size + a->offset, IOMMU_PAGE_SIZE))
return (ENOMEM);
if (entry->first >= a->common->lowaddr)
return (ENOMEM);
@ -415,7 +417,8 @@ iommu_gas_uppermatch(struct iommu_gas_match_args *a, struct iommu_map_entry *ent
* If the subtree doesn't have free space for the requested allocation
* plus two guard pages, give up.
*/
if (entry->free_down < a->size + a->offset + 2 * IOMMU_PAGE_SIZE)
if (entry->free_down < 2 * IOMMU_PAGE_SIZE +
roundup2(a->size + a->offset, IOMMU_PAGE_SIZE))
return (ENOMEM);
if (entry->last < a->common->highaddr)
return (ENOMEM);
@ -450,7 +453,6 @@ iommu_gas_find_space(struct iommu_domain *domain,
IOMMU_DOMAIN_ASSERT_LOCKED(domain);
KASSERT(entry->flags == 0, ("dirty entry %p %p", domain, entry));
KASSERT((size & IOMMU_PAGE_MASK) == 0, ("size %jx", (uintmax_t)size));
a.domain = domain;
a.size = size;