Re: [PATCH v5 07/22] x86/virt/tdx: Implement SEAMCALL function

From: Kai Huang
Date: Tue Aug 02 2022 - 22:37:28 EST


On Thu, 2022-07-21 at 13:52 +1200, Kai Huang wrote:
> Also, if I understand correctly above, your suggestion is we want to prevent any
> CMR memory going offline so it won't be hot-removed (assuming we can get CMRs
> during boot).  This looks contradicts to the requirement of being able to allow
> moving memory from core-mm to driver.  When we offline the memory, we cannot
> know whether the memory will be used by driver, or later hot-removed.

Hi Dave,

The high level flow of device hot-removal is:

acpi_scan_hot_remove()
-> acpi_scan_try_to_offline()
-> acpi_bus_offline()
-> device_offline()
-> memory_subsys_offline()
-> acpi_bus_trim()
-> acpi_memory_device_remove()


And memory_subsys_offline() can also be triggered via /sysfs:

echo 0 > /sys/devices/system/memory/memory30/online

After the memory block is offline, my understanding is kernel can theoretically
move it to, i.e. ZONE_DEVICE via memremap_pages().

As you can see memory_subsys_offline() is the entry point of memory device
offline (before it the code is generic for all ACPI device), and it cannot
distinguish whether the removal is from ACPI event, or from /sysfs, so it seems
we are unable to refuse to offline memory in memory_subsys_offline() when it is
called from ACPI event.

Any comments?

--
Thanks,
-Kai