liburing icon indicating copy to clipboard operation
liburing copied to clipboard

A little doubt about calling io_uring_alloc_huge when setting up IORING SETUP NO MMAP

Open yuzhishuo opened this issue 1 year ago • 0 comments

in liburing/src/setup.c:309, when IORING SETUP NO MMAP had been setted, why not allocate the struct io_rings memory that the io_uring_alloc_huge function been called.

I have this question because the size returned by rings size includes the members of the io rings structure, and if IORING SETUP NO MMAP is not set, when mapping user space, The starting location returned by the kernel is also the first address of the io_rings

That is to say, the size of memory allocated by user space and the size allocated by the kernel are not equal, right /??

					 struct io_uring_params *p)
{
	struct io_rings *rings;
	size_t size, sq_array_offset;
	void *ptr;

	/* make sure these are sane, as we already accounted them */
	ctx->sq_entries = p->sq_entries;
	ctx->cq_entries = p->cq_entries;

	size = rings_size(ctx, p->sq_entries, p->cq_entries, &sq_array_offset);   // HERE!!!!!
	if (size == SIZE_MAX)
		return -EOVERFLOW;

	if (!(ctx->flags & IORING_SETUP_NO_MMAP))
		rings = io_mem_alloc(size);
	else
		rings = io_rings_map(ctx, p->cq_off.user_addr, size);
static void *io_uring_validate_mmap_request(struct file *file,
					    loff_t pgoff, size_t sz)
{
	struct io_ring_ctx *ctx = file->private_data;
	loff_t offset = pgoff << PAGE_SHIFT;
	struct page *page;
	void *ptr;

	switch (offset & IORING_OFF_MMAP_MASK) {
	case IORING_OFF_SQ_RING:
	case IORING_OFF_CQ_RING:
		/* Don't allow mmap if the ring was setup without it */
		if (ctx->flags & IORING_SETUP_NO_MMAP)
			return ERR_PTR(-EINVAL);
		ptr = ctx->rings;                          // here 
		break;

yuzhishuo avatar Jan 14 '24 03:01 yuzhishuo