Re: [PATCH v2] vdpa/mlx5: Bound the KLM count of the user MR
From: Dragos Tatulea
Date: Fri Nov 20 2026 - 13:09:19 EST
On 20.11.26 14:23, Vladimir Petrzhikovskii wrote:
> create_user_mr() builds one indirect MKey that covers the whole vhost
> IOTLB. It fills each gap between two mappings with null KLMs, one per
> GiB, and never checks the total number of KLMs against the device
> limit, MLX5_CAP_GEN(log_max_klm_list_size).
>
> With a virtio-IOMMU the guest chooses the IOVAs: the VMM (QEMU)
> forwards each map the guest makes to the vhost-vDPA device. If the
> guest maps one page at IOVA 0 and one at IOVA 2^58, the driver needs
> more than 2^28 KLMs. create_indirect_key() computes the buffer size in
> an int, which overflows: the driver allocates 336 bytes, and
> fill_indir() then writes 16 bytes per KLM, 4 GiB in total, far past
> the end of the buffer.
>
> For a huge gap the count is also wrong: the number of null KLMs of one
> gap does not fit in the int that holds it, and rounding the gap up to
> whole GiB wraps.
>
> Refuse a map that needs more KLMs than the device supports, or more
> than fit in a CREATE_MKEY command, before any key is created. A normal
> guest is unaffected: memory at 0-3 GiB and 4-68 GiB needs 68 KLMs.
>
What do you mean by normal here? This sentence is not needed. Not
sure if it is worth a respin though.
> Found by an LLM code review agent auditing vhost-vDPA backends. We have
> no mlx5 hardware, so the fix is untested on it.
>
> Fixes: 94abbccdf291 ("vdpa/mlx5: Add shared memory registration code")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Nikolai Kalinin <nikolai@xxxxxxxxxxxx>
> Signed-off-by: Nikolai Kalinin <nikolai@xxxxxxxxxxxx>
> Signed-off-by: Vladimir Petrzhikovskii <vladimir@xxxxxx>
Reviewed-by: Dragos Tatulea <dtatulea@xxxxxxxxxx>
Thanks for your patch.
Thanks,
Dragos