@samitouri / QOSamiQemu / commits / 4d65b12d2e

virtio-mem: remove replay_populated/replay_discarded implementation

The replay iteration logic has been moved into the RamDiscardManager, which now iterates at source granularity using is_populated(). The source-level replay_populated/replay_discarded methods and their helpers are no longer called. Remove the now-dead replay methods, the VirtIOMEMReplayData struct, the virtio_mem_for_each_plugged/unplugged_section() helpers (only used by the replay methods), and the virtio_mem_section_cb typedef. Reviewed-by: Peter Xu <peterx@redhat.com> Acked-by: David Hildenbrand <david@kernel.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20260604-rdm5-v5-5-5768e6a0943d@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com>

Marc-André Lureau committed Jun 4, 2026 at 17:43 UTC 4d65b12d2e51c1a30bef8ef2c643ba08a1d7eaf9
1 file changed -112
hw/virtio/virtio-mem.c
-112
@@ -259,72 +259,6 @@ static int virtio_mem_for_each_plugged_range(VirtIOMEM *vmem, void *arg,
259 return ret;
260 }
261
262 -typedef int (*virtio_mem_section_cb)(MemoryRegionSection *s, void *arg);
263 -
264 -static int virtio_mem_for_each_plugged_section(const VirtIOMEM *vmem,
265 - const MemoryRegionSection *s,
266 - void *arg,
267 - virtio_mem_section_cb cb)
268 -{
269 - unsigned long first_bit, last_bit;
270 - uint64_t offset, size;
271 - int ret = 0;
272 -
273 - first_bit = s->offset_within_region / vmem->block_size;
274 - first_bit = find_next_bit(vmem->bitmap, vmem->bitmap_size, first_bit);
275 - while (first_bit < vmem->bitmap_size) {
276 - MemoryRegionSection tmp = *s;
277 -
278 - offset = first_bit * vmem->block_size;
279 - last_bit = find_next_zero_bit(vmem->bitmap, vmem->bitmap_size,
280 - first_bit + 1) - 1;
281 - size = (last_bit - first_bit + 1) * vmem->block_size;
282 -
283 - if (!memory_region_section_intersect_range(&tmp, offset, size)) {
284 - break;
285 - }
286 - ret = cb(&tmp, arg);
287 - if (ret) {
288 - break;
289 - }
290 - first_bit = find_next_bit(vmem->bitmap, vmem->bitmap_size,
291 - last_bit + 2);
292 - }
293 - return ret;
294 -}
295 -
296 -static int virtio_mem_for_each_unplugged_section(const VirtIOMEM *vmem,
297 - const MemoryRegionSection *s,
298 - void *arg,
299 - virtio_mem_section_cb cb)
300 -{
301 - unsigned long first_bit, last_bit;
302 - uint64_t offset, size;
303 - int ret = 0;
304 -
305 - first_bit = s->offset_within_region / vmem->block_size;
306 - first_bit = find_next_zero_bit(vmem->bitmap, vmem->bitmap_size, first_bit);
307 - while (first_bit < vmem->bitmap_size) {
308 - MemoryRegionSection tmp = *s;
309 -
310 - offset = first_bit * vmem->block_size;
311 - last_bit = find_next_bit(vmem->bitmap, vmem->bitmap_size,
312 - first_bit + 1) - 1;
313 - size = (last_bit - first_bit + 1) * vmem->block_size;
314 -
315 - if (!memory_region_section_intersect_range(&tmp, offset, size)) {
316 - break;
317 - }
318 - ret = cb(&tmp, arg);
319 - if (ret) {
320 - break;
321 - }
322 - first_bit = find_next_zero_bit(vmem->bitmap, vmem->bitmap_size,
323 - last_bit + 2);
324 - }
325 - return ret;
326 -}
327 -
262 static void virtio_mem_notify_unplug(VirtIOMEM *vmem, uint64_t offset,
263 uint64_t size)
264 {
@@ -1667,50 +1601,6 @@ static bool virtio_mem_rds_is_populated(const RamDiscardSource *rds,
1601 return virtio_mem_is_range_plugged(vmem, start_gpa, end_gpa - start_gpa);
1602 }
1603
1670 -struct VirtIOMEMReplayData {
1671 - ReplayRamDiscardState fn;
1672 - void *opaque;
1673 -};
1674 -
1675 -static int virtio_mem_rds_replay_cb(MemoryRegionSection *s, void *arg)
1676 -{
1677 - struct VirtIOMEMReplayData *data = arg;
1678 -
1679 - return data->fn(s, data->opaque);
1680 -}
1681 -
1682 -static int virtio_mem_rds_replay_populated(const RamDiscardSource *rds,
1683 - const MemoryRegionSection *s,
1684 - ReplayRamDiscardState replay_fn,
1685 - void *opaque)
1686 -{
1687 - const VirtIOMEM *vmem = VIRTIO_MEM(rds);
1688 - struct VirtIOMEMReplayData data = {
1689 - .fn = replay_fn,
1690 - .opaque = opaque,
1691 - };
1692 -
1693 - g_assert(s->mr == &vmem->memdev->mr);
1694 - return virtio_mem_for_each_plugged_section(vmem, s, &data,
1695 - virtio_mem_rds_replay_cb);
1696 -}
1697 -
1698 -static int virtio_mem_rds_replay_discarded(const RamDiscardSource *rds,
1699 - const MemoryRegionSection *s,
1700 - ReplayRamDiscardState replay_fn,
1701 - void *opaque)
1702 -{
1703 - const VirtIOMEM *vmem = VIRTIO_MEM(rds);
1704 - struct VirtIOMEMReplayData data = {
1705 - .fn = replay_fn,
1706 - .opaque = opaque,
1707 - };
1708 -
1709 - g_assert(s->mr == &vmem->memdev->mr);
1710 - return virtio_mem_for_each_unplugged_section(vmem, s, &data,
1711 - virtio_mem_rds_replay_cb);
1712 -}
1713 -
1604 static void virtio_mem_unplug_request_check(VirtIOMEM *vmem, Error **errp)
1605 {
1606 if (vmem->unplugged_inaccessible == ON_OFF_AUTO_OFF) {
@@ -1766,8 +1656,6 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
1656
1657 rdsc->get_min_granularity = virtio_mem_rds_get_min_granularity;
1658 rdsc->is_populated = virtio_mem_rds_is_populated;
1769 - rdsc->replay_populated = virtio_mem_rds_replay_populated;
1770 - rdsc->replay_discarded = virtio_mem_rds_replay_discarded;
1659 }
1660
1661 static const TypeInfo virtio_mem_info = {