Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Anthony Krowiak <akrowiak@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev, linux-s390@vger.kernel.org,
	kvm@vger.kernel.org
Cc: Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>
Subject: Re: [PATCH v9 03/15] s390/vfio-ap: Functions to initialize/release vfio device migration data
Date: Wed, 14 Oct 2026 11:51:44 -0400	[thread overview]
Message-ID: <21a7ab10-2e9d-4167-afba-a0bb37e5cbc4@linux.ibm.com> (raw)
In-Reply-To: <sashiko-outbox-170040@kernel.org>



On 10/13/26 11:47 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] s390/vfio-ap: Data race on matrix_dev->info during mdev init
> --
>
> commit 61bb5cee71d03ac3e82343abe74a853a264da523
> Author: Anthony Krowiak <akrowiak@linux.ibm.com>
>
> s390/vfio-ap: Functions to initialize/release vfio device migration data
>
> Provides the functions that initialize and release the data structures
> used during live guest migration.
>
>> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
>> index 01439f0ca42ab..6829e423b5a46 100644
>> --- a/drivers/s390/crypto/vfio_ap_ops.c
>> +++ b/drivers/s390/crypto/vfio_ap_ops.c
>> @@ -782,18 +782,30 @@ static bool vfio_ap_mdev_filter_matrix(struct ap_matrix_mdev *matrix_mdev,
>>   
>>   static int vfio_ap_mdev_init_dev(struct vfio_device *vdev)
>>   {
>> -	struct ap_matrix_mdev *matrix_mdev =
>> -		container_of(vdev, struct ap_matrix_mdev, vdev);
>> +	struct ap_matrix_mdev *matrix_mdev;
>>   
>> +	mutex_lock(&matrix_dev->mdevs_lock);
>> +	matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev);
>>   	matrix_mdev->mdev = to_mdev_device(vdev->dev);
>>   	vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix);
> [Severity: Medium]
> Could this result in a data race on matrix_dev->info?
>
> The modified vfio_ap_mdev_init_dev() reads matrix_dev->info via
> vfio_ap_matrix_init() while holding only matrix_dev->mdevs_lock.
>
> However, vfio_ap_on_cfg_changed() updates matrix_dev->info via memcpy()
> while holding only matrix_dev->guests_lock:
>
> drivers/s390/crypto/vfio_ap_ops.c:vfio_ap_on_cfg_changed() {
>      ...
>      memcpy(&matrix_dev->info, cur_cfg_info, sizeof(*cur_cfg_info));
>      ...
> }
>
> Since memcpy() is not atomic and the two functions acquire different locks,
> can a concurrent AP configuration change cause vfio_ap_mdev_init_dev()
> to read a torn or partially updated ap_config_info struct, potentially
> leading to incorrect apm_max, aqm_max, or adm_max values?
>
> Note that follow-up patches in the series do not resolve this lock mismatch.

This is actually a pre-existing bug. Also, the chunk above is unrelated to
this patch series. This will be fixed in a separate patch.

>
>>   	matrix_mdev->pqap_hook = handle_pqap;
>>   	vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->shadow_apcb);
>>   	hash_init(matrix_mdev->qtable.queues);
>> +	mutex_unlock(&matrix_dev->mdevs_lock);
>>   
>>   	return 0;
>>   }


  reply	other threads:[~2026-10-14 15:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 15:32 [PATCH v9 00/15] s390/vfio-ap: Add live guest migration support Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 01/15] s390/vfio-ap: Provide function to get the number of queues assigned to mdev Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 02/15] s390/vfio-ap: Data structures for facilitating vfio device migration Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 03/15] s390/vfio-ap: Functions to initialize/release vfio device migration data Anthony Krowiak
2026-10-13 15:47   ` sashiko-bot
2026-10-14 15:51     ` Anthony Krowiak [this message]
2026-10-13 15:32 ` [PATCH v9 04/15] s390/vfio-ap: Reset migration state in VFIO_DEVICE_RESET ioctl handler Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 05/15] s390/vfio-ap: Callback to get/set vfio device mig state during guest migration Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 06/15] s390/vfio-ap: Transition guest migration state from STOP to STOP_COPY Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 07/15] s390/vfio-ap: File ops called to save the vfio device migration state Anthony Krowiak
2026-10-13 15:59   ` sashiko-bot
2026-10-14 18:07     ` Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 08/15] s390/vfio-ap: Transition device migration state from STOP to RESUMING Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 09/15] s390/vfio-ap: Prepare lock helpers and matrix init for cross-file use Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 10/15] s390/vfio-ap: Add method to set a new guest AP configuration Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 11/15] s390/vfio-ap: File ops called to resume the vfio device migration Anthony Krowiak
2026-10-13 16:14   ` sashiko-bot
2026-10-14 19:08     ` Anthony Krowiak
2026-10-14 19:53       ` Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 12/15] s390/vfio-ap: Transition device migration state to from/to STOP Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 13/15] s390/vfio-ap: Callback to get the size of data to be migrated during guest migration Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 14/15] s390/vfio-ap: Add 'migratable' feature to sysfs 'features' attribute Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 15/15] s390/vfio-ap: Add live guest migration chapter to vfio-ap.rst Anthony Krowiak

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=21a7ab10-2e9d-4167-afba-a0bb37e5cbc4@linux.ibm.com \
    --to=akrowiak@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox