qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>, qemu-devel@nongnu.org
Cc: yuanminghao <yuanmh12@chinatelecom.cn>,
	Igor Mammedov <imammedo@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	qemu-stable <qemu-stable@nongnu.org>
Subject: Re: [PATCH v1] vhost: Fix used memslot tracking when destroying a vhost device
Date: Wed, 16 Jul 2025 15:41:49 +0200	[thread overview]
Message-ID: <50aadfb3-be59-4803-b659-039d37eca597@redhat.com> (raw)
In-Reply-To: <c1a99ac3-bdb7-4825-99c8-b3a55241be84@tls.msk.ru>

On 16.07.25 15:31, Michael Tokarev wrote:
> On 03.06.2025 14:13, David Hildenbrand wrote:
>> When we unplug a vhost device, we end up calling vhost_dev_cleanup()
>> where we do a memory_listener_unregister().
>>
>> This memory_listener_unregister() call will end up disconnecting the
>> listener from the address space through listener_del_address_space().
>>
>> In that process, we effectively communicate the removal of all memory
>> regions from that listener, resulting in region_del() + commit()
>> callbacks getting triggered.
>>
>> So in case of vhost, we end up calling vhost_commit() with no remaining
>> memory slots (0).
>>
>> In vhost_commit() we end up overwriting the global variables
>> used_memslots / used_shared_memslots, used for detecting the number
>> of free memslots. With used_memslots / used_shared_memslots set to 0
>> by vhost_commit() during device removal, we'll later assume that the
>> other vhost devices still have plenty of memslots left when calling
>> vhost_get_free_memslots().
>>
>> Let's fix it by simply removing the global variables and depending
>> only on the actual per-device count.
>>
>> Easy to reproduce by adding two vhost-user devices to a VM and then
>> hot-unplugging one of them.
>>
>> While at it, detect unexpected underflows in vhost_get_free_memslots()
>> and issue a warning.
>>
>> Reported-by: yuanminghao <yuanmh12@chinatelecom.cn>
>> Link: https://lore.kernel.org/qemu-devel/20241121060755.164310-1-yuanmh12@chinatelecom.cn/
>> Fixes: 2ce68e4cf5be ("vhost: add vhost_has_free_slot() interface")
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> Cc: Michael S. Tsirkin <mst@redhat.com>
>> Cc: Stefano Garzarella <sgarzare@redhat.com>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> Is it a stable material (10.0.x) too?

Probably better to have it in stable, yes. Thanks!

-- 
Cheers,

David / dhildenb



      reply	other threads:[~2025-07-16 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-03 11:13 [PATCH v1] vhost: Fix used memslot tracking when destroying a vhost device David Hildenbrand
2025-06-11  8:21 ` Igor Mammedov
2025-07-16 13:31 ` Michael Tokarev
2025-07-16 13:41   ` David Hildenbrand [this message]

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=50aadfb3-be59-4803-b659-039d37eca597@redhat.com \
    --to=david@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=yuanmh12@chinatelecom.cn \
    /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;
as well as URLs for NNTP newsgroup(s).