Lines Matching refs:area

24 	struct iopt_area *area;
39 iter->area = iopt_area_iter_first(iopt, iova, iova);
40 if (!iter->area)
42 if (!iter->area->pages) {
43 iter->area = NULL;
46 return iter->area;
53 if (!iter->area)
55 last_iova = iopt_area_last_iova(iter->area);
60 iter->area = iopt_area_iter_next(iter->area, iter->cur_iova,
62 if (!iter->area)
64 if (iter->cur_iova != iopt_area_iova(iter->area) ||
65 !iter->area->pages) {
66 iter->area = NULL;
69 return iter->area;
187 * The area takes a slice of the pages from start_bytes to start_byte + length
189 static int iopt_insert_area(struct io_pagetable *iopt, struct iopt_area *area,
199 area->iommu_prot = iommu_prot;
200 area->page_offset = start_byte % PAGE_SIZE;
201 if (area->page_offset & (iopt->iova_alignment - 1))
204 area->node.start = iova;
205 if (check_add_overflow(iova, length - 1, &area->node.last))
208 area->pages_node.start = start_byte / PAGE_SIZE;
209 if (check_add_overflow(start_byte, length - 1, &area->pages_node.last))
211 area->pages_node.last = area->pages_node.last / PAGE_SIZE;
212 if (WARN_ON(area->pages_node.last >= pages->npages))
216 * The area is inserted with a NULL pages indicating it is not fully
219 area->iopt = iopt;
220 interval_tree_insert(&area->node, &iopt->area_itree);
226 struct iopt_area *area;
228 area = kzalloc(sizeof(*area), GFP_KERNEL_ACCOUNT);
229 if (!area)
231 RB_CLEAR_NODE(&area->node.rb);
232 RB_CLEAR_NODE(&area->pages_node.rb);
233 return area;
246 elm->area = iopt_area_alloc();
247 if (!elm->area)
283 rc = iopt_insert_area(iopt, elm->area, elm->pages, iova,
295 static void iopt_abort_area(struct iopt_area *area)
298 WARN_ON(area->pages);
299 if (area->iopt) {
300 down_write(&area->iopt->iova_rwsem);
301 interval_tree_remove(&area->node, &area->iopt->area_itree);
302 up_write(&area->iopt->iova_rwsem);
304 kfree(area);
313 if (elm->area)
314 iopt_abort_area(elm->area);
329 rc = iopt_area_fill_domains(elm->area, elm->pages);
339 iopt_area_unfill_domains(undo_elm->area, undo_elm->pages);
364 * area->pages must be set inside the domains_rwsem to ensure
368 elm->area->pages = elm->pages;
370 elm->area = NULL;
418 if (elm.area)
419 iopt_abort_area(elm.area);
432 struct iopt_area *area;
441 iopt_for_each_contig_area(&iter, area, iopt, iova, last_iova) {
443 unsigned long last = min(last_iova, iopt_area_last_iova(area));
450 elm->start_byte = iopt_area_start_byte(area, iter.cur_iova);
451 elm->pages = area->pages;
471 struct iopt_area *area;
477 * The domains_rwsem must be held in read mode any time any area->pages
479 * concurrently with cleaning up the area.
484 while ((area = iopt_area_iter_first(iopt, start, last))) {
485 unsigned long area_last = iopt_area_last_iova(area);
486 unsigned long area_first = iopt_area_iova(area);
489 /* Userspace should not race map/unmap's of the same area */
490 if (!area->pages) {
508 if (area->num_accesses) {
509 size_t length = iopt_area_length(area);
512 area->prevent_access = true;
524 pages = area->pages;
525 area->pages = NULL;
528 iopt_area_unfill_domains(area, pages);
529 iopt_abort_area(area);
692 * This is used when removing a domain from the iopt. Every area in the iopt
699 struct iopt_area *area;
713 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area;
714 area = iopt_area_iter_next(area, 0, ULONG_MAX)) {
715 struct iopt_pages *pages = area->pages;
722 WARN_ON(!area->storage_domain);
723 if (area->storage_domain == domain)
724 area->storage_domain = storage_domain;
727 iopt_area_unmap_domain(area, domain);
732 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area;
733 area = iopt_area_iter_next(area, 0, ULONG_MAX)) {
734 struct iopt_pages *pages = area->pages;
740 interval_tree_remove(&area->pages_node, &pages->domains_itree);
741 WARN_ON(area->storage_domain != domain);
742 area->storage_domain = NULL;
743 iopt_area_unfill_domain(area, pages, domain);
753 * Fill the domain with PFNs from every area in the iopt. On failure the domain
760 struct iopt_area *area;
766 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area;
767 area = iopt_area_iter_next(area, 0, ULONG_MAX)) {
768 struct iopt_pages *pages = area->pages;
774 rc = iopt_area_fill_domain(area, domain);
779 if (!area->storage_domain) {
781 area->storage_domain = domain;
782 interval_tree_insert(&area->pages_node,
790 end_area = area;
791 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area;
792 area = iopt_area_iter_next(area, 0, ULONG_MAX)) {
793 struct iopt_pages *pages = area->pages;
795 if (area == end_area)
801 interval_tree_remove(&area->pages_node,
803 area->storage_domain = NULL;
805 iopt_area_unfill_domain(area, pages, domain);
811 /* All existing area's conform to an increased page size */
816 struct iopt_area *area;
821 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area;
822 area = iopt_area_iter_next(area, 0, ULONG_MAX))
823 if ((iopt_area_iova(area) & align_mask) ||
824 (iopt_area_length(area) & align_mask) ||
825 (area->page_offset & align_mask))
880 /* No area exists that is outside the allowed domain aperture */
988 * iopt_area_split - Split an area into two parts at iova
989 * @area: The area to split
990 * @iova: Becomes the last of a new area
992 * This splits an area into two. It is part of the VFIO compatibility to allow
996 static int iopt_area_split(struct iopt_area *area, unsigned long iova)
998 unsigned long alignment = area->iopt->iova_alignment;
999 unsigned long last_iova = iopt_area_last_iova(area);
1000 unsigned long start_iova = iopt_area_iova(area);
1002 struct io_pagetable *iopt = area->iopt;
1003 struct iopt_pages *pages = area->pages;
1013 if (!pages || area->prevent_access)
1017 iopt_area_start_byte(area, new_start) & (alignment - 1))
1035 if (area->num_accesses) {
1044 if (area->storage_domain && !iopt->disable_large_pages) {
1049 interval_tree_remove(&area->node, &iopt->area_itree);
1050 rc = iopt_insert_area(iopt, lhs, area->pages, start_iova,
1051 iopt_area_start_byte(area, start_iova),
1053 area->iommu_prot);
1057 rc = iopt_insert_area(iopt, rhs, area->pages, new_start,
1058 iopt_area_start_byte(area, new_start),
1059 last_iova - new_start + 1, area->iommu_prot);
1064 * If the original area has filled a domain, domains_itree has to be
1067 if (area->storage_domain) {
1068 interval_tree_remove(&area->pages_node, &pages->domains_itree);
1073 lhs->storage_domain = area->storage_domain;
1074 lhs->pages = area->pages;
1075 rhs->storage_domain = area->storage_domain;
1076 rhs->pages = area->pages;
1078 kfree(area);
1090 interval_tree_insert(&area->node, &iopt->area_itree);
1107 struct iopt_area *area;
1109 area = iopt_area_iter_first(iopt, iovas[i], iovas[i]);
1110 if (!area)
1112 rc = iopt_area_split(area, iovas[i]);