Commit 1da602ec authored by Jacob Pan's avatar Jacob Pan Committed by Wei Liu
Browse files

hv_balloon: Fallback to generic_online_page() for non-HV hot added mem



The Hyper-V balloon driver installs a custom callback for handling page
onlining operations performed by the memory hotplug subsystem. This
custom callback is global, and overrides the default callback
(generic_online_page) that Linux otherwise uses. The custom callback
properly handles memory that is hot-added by the balloon driver as part
of a Hyper-V hot-add region.

But memory can also be hot-added directly by a device driver for a vPCI
device, particularly GPUs. In such a case, the custom callback installed by
the balloon driver runs, but won't find the page in its hot-add region list
and doesn't online it, which could cause driver initialization failures.

Fix this by having the balloon custom callback run generic_online_page()
when the page isn't part of a Hyper-V hot-add region, thereby doing the
default Linux behavior. This allows device driver hot-adds to work
properly. Similar cases are handled the same way in the virtio-mem driver.

Suggested-by: default avatarVikram Sethi <vsethi@nvidia.com>
Tested-by: default avatarMichael Frohlich <mfrohlich@microsoft.com>
Reviewed-by: default avatarMichael Kelley <mhklinux@outlook.com>
Signed-off-by: default avatarJacob Pan <jacob.pan@linux.microsoft.com>
Link: https://lore.kernel.org/r/20250107180918.1053933-1-jacob.pan@linux.microsoft.com


Signed-off-by: default avatarWei Liu <wei.liu@kernel.org>
Message-ID: <20250107180918.1053933-1-jacob.pan@linux.microsoft.com>
parent fcf5203e
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -766,7 +766,7 @@ static void hv_online_page(struct page *pg, unsigned int order)
	struct hv_hotadd_state *has;
	unsigned long pfn = page_to_pfn(pg);

	guard(spinlock_irqsave)(&dm_device.ha_lock);
	scoped_guard(spinlock_irqsave, &dm_device.ha_lock) {
		list_for_each_entry(has, &dm_device.ha_region_list, list) {
			/* The page belongs to a different HAS. */
			if (pfn < has->start_pfn ||
@@ -774,8 +774,10 @@ static void hv_online_page(struct page *pg, unsigned int order)
				continue;

			hv_bring_pgs_online(has, pfn, 1UL << order);
		break;
			return;
		}
	}
	generic_online_page(pg, order);
}

static int pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt)