[Devel] [PATCH VZ9 v2 1/2] fs/fuse kio: implement memory region to support zero-copy between userapce and kernel space.

Vasily Averin vvs at openvz.org
Sat May 25 21:18:28 MSK 2024


On 5/23/24 13:54, Liu Kui wrote:
> +/*
> + * Register a MR
> + */
> +int pcs_reg_mr(struct pcs_mr_set *mrs, u64 start, u64 len)
> +{
> +	int ret = 0;
> +	struct pcs_mr *mr;
> +	struct pcs_umem *umem;
> +
> +	if (!len)
> +		return -EINVAL;
> +
> +	if (!can_do_mlock())
> +		return -EPERM;
> +
> +	if (atomic_inc_return(&mrs->mr_num) > PCS_MAX_MR) {
> +		atomic_dec(&mrs->mr_num);
> +		return -ENOMEM;
> +	}
> +
> +	umem = pcs_umem_get(start, len);
> +	if (IS_ERR(umem))

atomic_dec(&mrs->mr_num) is still missing here.
Did you resend old patch version perhaps?

> +		return PTR_ERR(umem);
> +
> +	mr = kzalloc(sizeof(*mr), GFP_KERNEL);
> +	if (!mr) {
> +		ret = -ENOMEM;
> +		goto err_out;
> +	}
> +
> +	mr->mrs = mrs;
> +	mr->va = start;
> +	mr->len = len;
> +	mr->umem = umem;
> +	kref_init(&mr->ref);
> +
> +	ret = xa_alloc_cyclic(&mrs->mr_xa, &mr->id, mr,
> +			XA_LIMIT(1, PCS_MAX_MR), &mrs->mr_next, GFP_KERNEL);
> +	if (ret < 0) {
> +		kfree(mr);
> +		goto err_out;
> +	}
> +
> +	mr->id_valid = 1;
> +
> +	return mr->id;
> +
> +err_out:
> +	pcs_umem_release(umem);
> +	atomic_dec(&mrs->mr_num);
> +	return ret;
> +}



More information about the Devel mailing list