mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
virtio-mem: generalize check for added memory
Let's check by traversing busy system RAM resources instead, to avoid relying on memory block states. Don't use walk_system_ram_range(), as that works on pages and we want to use the bare addresses we have easily at hand. This is a preparation for Big Block Mode (BBM), which won't have memory block states. Reviewed-by: Wei Yang <richard.weiyang@linux.alibaba.com> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com> Signed-off-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20201112133815.13332-12-david@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
f2d799d591
commit
989ff82527
1 changed files with 15 additions and 4 deletions
|
@ -1833,6 +1833,20 @@ static void virtio_mem_delete_resource(struct virtio_mem *vm)
|
|||
vm->parent_resource = NULL;
|
||||
}
|
||||
|
||||
static int virtio_mem_range_has_system_ram(struct resource *res, void *arg)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool virtio_mem_has_memory_added(struct virtio_mem *vm)
|
||||
{
|
||||
const unsigned long flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
|
||||
|
||||
return walk_iomem_res_desc(IORES_DESC_NONE, flags, vm->addr,
|
||||
vm->addr + vm->region_size, NULL,
|
||||
virtio_mem_range_has_system_ram) == 1;
|
||||
}
|
||||
|
||||
static int virtio_mem_probe(struct virtio_device *vdev)
|
||||
{
|
||||
struct virtio_mem *vm;
|
||||
|
@ -1954,10 +1968,7 @@ static void virtio_mem_remove(struct virtio_device *vdev)
|
|||
* the system. And there is no way to stop the driver/device from going
|
||||
* away. Warn at least.
|
||||
*/
|
||||
if (vm->nb_mb_state[VIRTIO_MEM_MB_STATE_OFFLINE] ||
|
||||
vm->nb_mb_state[VIRTIO_MEM_MB_STATE_OFFLINE_PARTIAL] ||
|
||||
vm->nb_mb_state[VIRTIO_MEM_MB_STATE_ONLINE] ||
|
||||
vm->nb_mb_state[VIRTIO_MEM_MB_STATE_ONLINE_PARTIAL]) {
|
||||
if (virtio_mem_has_memory_added(vm)) {
|
||||
dev_warn(&vdev->dev, "device still has system memory added\n");
|
||||
} else {
|
||||
virtio_mem_delete_resource(vm);
|
||||
|
|
Loading…
Add table
Reference in a new issue