drivers/infiniband/sw/rxe/rxe_mmap.c

Source file repositories/reference/linux-study-clean/drivers/infiniband/sw/rxe/rxe_mmap.c

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/sw/rxe/rxe_mmap.c
Extension
.c
Size
3832 bytes
Lines
162
Domain
Driver Families
Bucket
drivers/infiniband
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (size > ip->info.size) {
			rxe_dbg_dev(rxe, "mmap region is larger than the object!\n");
			spin_unlock_bh(&rxe->pending_lock);
			ret = -EINVAL;
			goto done;
		}

		goto found_it;
	}
	rxe_dbg_dev(rxe, "unable to find pending mmap info\n");
	spin_unlock_bh(&rxe->pending_lock);
	ret = -EINVAL;
	goto done;

found_it:
	/*
	 * Increment refcount and check whether it is being freed atm while
	 * holding lock to prevent UAF
	 */
	if (!kref_get_unless_zero(&ip->ref)) {
		spin_unlock_bh(&rxe->pending_lock);
		ret = -ENXIO;
		goto done;
	}

	list_del_init(&ip->pending_mmaps);
	spin_unlock_bh(&rxe->pending_lock);

	vma->vm_ops = &rxe_vm_ops;
	vma->vm_private_data = ip;

	ret = remap_vmalloc_range(vma, ip->obj, 0);
	if (ret) {
		vma->vm_private_data = NULL;
		vma->vm_ops = NULL;
		kref_put(&ip->ref, rxe_mmap_release);
		rxe_dbg_dev(rxe, "err %d from remap_vmalloc_range\n", ret);
		goto done;
	}

done:
	return ret;
}

/*
 * Allocate information for rxe_mmap
 */
struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *rxe, u32 size,
					   struct ib_udata *udata, void *obj)
{
	struct rxe_mmap_info *ip;

	if (!udata)
		return ERR_PTR(-EINVAL);

	ip = kmalloc_obj(*ip);
	if (!ip)
		return ERR_PTR(-ENOMEM);

	size = PAGE_ALIGN(size);

	spin_lock_bh(&rxe->mmap_offset_lock);

	if (rxe->mmap_offset == 0)
		rxe->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA);

	ip->info.offset = rxe->mmap_offset;
	rxe->mmap_offset += ALIGN(size, SHMLBA);

	spin_unlock_bh(&rxe->mmap_offset_lock);

	INIT_LIST_HEAD(&ip->pending_mmaps);
	ip->info.size = size;
	ip->context =
		container_of(udata, struct uverbs_attr_bundle, driver_udata)
			->context;
	ip->obj = obj;
	kref_init(&ip->ref);

	return ip;
}

Annotation

Implementation Notes