Skip to content

Commit 3c42e19

Browse files
davidhildenbrandmstsirkin
authored andcommitted
virtio-mem: Drop manual check for already present memory
Registering our parent resource will fail if any memory is still present (e.g., because somebody unloaded the driver and tries to reload it). No need for the manual check. Move our "unplug all" handling to after registering the resource. Cc: "Michael S. Tsirkin" <[email protected]> Cc: Pankaj Gupta <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent ebf7155 commit 3c42e19

File tree

1 file changed

+12
-43
lines changed

1 file changed

+12
-43
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,23 +1616,6 @@ static int virtio_mem_init_vq(struct virtio_mem *vm)
16161616
return 0;
16171617
}
16181618

1619-
/*
1620-
* Test if any memory in the range is present in Linux.
1621-
*/
1622-
static bool virtio_mem_any_memory_present(unsigned long start,
1623-
unsigned long size)
1624-
{
1625-
const unsigned long start_pfn = PFN_DOWN(start);
1626-
const unsigned long end_pfn = PFN_UP(start + size);
1627-
unsigned long pfn;
1628-
1629-
for (pfn = start_pfn; pfn != end_pfn; pfn++)
1630-
if (present_section_nr(pfn_to_section_nr(pfn)))
1631-
return true;
1632-
1633-
return false;
1634-
}
1635-
16361619
static int virtio_mem_init(struct virtio_mem *vm)
16371620
{
16381621
const uint64_t phys_limit = 1UL << MAX_PHYSMEM_BITS;
@@ -1664,32 +1647,6 @@ static int virtio_mem_init(struct virtio_mem *vm)
16641647
virtio_cread(vm->vdev, struct virtio_mem_config, region_size,
16651648
&vm->region_size);
16661649

1667-
/*
1668-
* If we still have memory plugged, we might have to unplug all
1669-
* memory first. However, if somebody simply unloaded the driver
1670-
* we would have to reinitialize the old state - something we don't
1671-
* support yet. Detect if we have any memory in the area present.
1672-
*/
1673-
if (vm->plugged_size) {
1674-
uint64_t usable_region_size;
1675-
1676-
virtio_cread(vm->vdev, struct virtio_mem_config,
1677-
usable_region_size, &usable_region_size);
1678-
1679-
if (virtio_mem_any_memory_present(vm->addr,
1680-
usable_region_size)) {
1681-
dev_err(&vm->vdev->dev,
1682-
"reloading the driver is not supported\n");
1683-
return -EINVAL;
1684-
}
1685-
/*
1686-
* Note: it might happen that the device is busy and
1687-
* unplugging all memory might take some time.
1688-
*/
1689-
dev_info(&vm->vdev->dev, "unplugging all memory required\n");
1690-
vm->unplug_all_required = 1;
1691-
}
1692-
16931650
/*
16941651
* We always hotplug memory in memory block granularity. This way,
16951652
* we have to wait for exactly one memory block to online.
@@ -1760,6 +1717,8 @@ static int virtio_mem_create_resource(struct virtio_mem *vm)
17601717
if (!vm->parent_resource) {
17611718
kfree(name);
17621719
dev_warn(&vm->vdev->dev, "could not reserve device region\n");
1720+
dev_info(&vm->vdev->dev,
1721+
"reloading the driver is not supported\n");
17631722
return -EBUSY;
17641723
}
17651724

@@ -1816,6 +1775,16 @@ static int virtio_mem_probe(struct virtio_device *vdev)
18161775
if (rc)
18171776
goto out_del_vq;
18181777

1778+
/*
1779+
* If we still have memory plugged, we have to unplug all memory first.
1780+
* Registering our parent resource makes sure that this memory isn't
1781+
* actually in use (e.g., trying to reload the driver).
1782+
*/
1783+
if (vm->plugged_size) {
1784+
vm->unplug_all_required = 1;
1785+
dev_info(&vm->vdev->dev, "unplugging all memory is required\n");
1786+
}
1787+
18191788
/* register callbacks */
18201789
vm->memory_notifier.notifier_call = virtio_mem_memory_notifier_cb;
18211790
rc = register_memory_notifier(&vm->memory_notifier);

0 commit comments

Comments
 (0)