All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Weimin Xiong" <xiongwm2026@163.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] vdpa/mlx5: fix MR state corruption on setup_vq_resources failure
Date: Thu, 16 Jul 2026 03:12:10 +0000	[thread overview]
Message-ID: <20260716031210.976121F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716030241.124412-1-xiongwm2026@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Moving the MR update to the end of mlx5_vdpa_change_map() causes hardware virtqueues to be programmed with the old Memory Region (MR) keys instead of the new ones, leading to device malfunction and hardware faults.
--

--- Patch [1]: [PATCH] vdpa/mlx5: fix MR state corruption on setup_vq_resources failure ---
commit 0e93d2962a61c5461c3028e043cb48591fa19ebe
Author: xiongweimin <xiongweimin@kylinos.cn>

vdpa/mlx5: fix MR state corruption on setup_vq_resources failure

This commit defers mlx5_vdpa_update_mr() until after setup_vq_resources()
and resume_vqs() to prevent MR state corruption if resource setup fails.

> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index ad0d5fbbbca84..8a6ddc00b8e07 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -3067,24 +3067,28 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
>  		teardown_vq_resources(ndev);
>  	}
>  
> -	mlx5_vdpa_update_mr(mvdev, new_mr, asid);
> -
>  	for (int i = 0; i < mvdev->max_vqs; i++)
>  		ndev->vqs[i].modified_fields |= MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY |
>  						MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY;
>  
>  	if (!(mvdev->status & VIRTIO_CONFIG_S_DRIVER_OK) || mvdev->suspended)
> -		return 0;
> +		goto done;
>  
>  	if (teardown) {
>  		restore_channels_info(ndev);
>  		err = setup_vq_resources(ndev, true);
>  		if (err)
> -			return err;
> +			goto out_err;

[Severity: High]
Does deferring the MR update cause the hardware virtqueues to be programmed
with the old MR keys?

setup_vq_resources() eventually calls create_virtqueue(), which reads the MR
keys from the mvdev->mres.mr array before it has been updated:

drivers/vdpa/mlx5/net/mlx5_vnet.c:create_virtqueue() {
    ...
    vq_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_GROUP]];
    if (vq_mr)
        MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey);
    ...
}

>  	}
>  
>  	resume_vqs(ndev, 0, ndev->cur_num_vqs);

Similarly, resume_vqs() modifies virtqueues using the stale MR keys:

drivers/vdpa/mlx5/net/mlx5_vnet.c:fill_modify_virtqueue_cmd() {
    ...
    vq_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_GROUP]];
    if (vq_mr)
        MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey);
    ...
}

> +	goto done;
>  
> +out_err:
> +	return err;
> +
> +done:
> +	mlx5_vdpa_update_mr(mvdev, new_mr, asid);

Since mlx5_vdpa_update_mr() happens here at the end, does it destroy the old MR
while the hardware is actively configured to use it?

Could this lead to IOMMU faults and memory corruption when the memory
map changes?

>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716030241.124412-1-xiongwm2026@163.com?part=1

  reply	other threads:[~2026-07-16  3:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  3:02 [PATCH] vdpa/mlx5: fix MR state corruption on setup_vq_resources failure Weimin Xiong
2026-07-16  3:12 ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-07-16  3:00 Weimin Xiong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260716031210.976121F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xiongwm2026@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.