[PATCH 1/1] vmgenid: emit uevent with new generation ID

From: Babis Chalios
Date: Tue Jul 30 2024 - 05:51:53 EST


There are many system services that need to be notified when the VM they
are running in is resumed from a snapshot. One example are network
managers which need to renew DHCP leases and/or re-create MAC addresses
for virtual interfaces. Other example are daemons that manage system
clocks which need reset upon snapshot resume.

Send a uevent notification to user space from the VMGenID driver when
we receive the ACPI notification about a new generation ID. This way, we
notify user space software about the VM cloning event and give it a
chance to adapt to the new environment.

Signed-off-by: Babis Chalios <bchalios@xxxxxxxxx>
---
drivers/virt/vmgenid.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c
index 66135eac3abff..5410620a017f5 100644
--- a/drivers/virt/vmgenid.c
+++ b/drivers/virt/vmgenid.c
@@ -26,6 +26,7 @@ struct vmgenid_state {
static void vmgenid_notify(struct device *device)
{
struct vmgenid_state *state = device->driver_data;
+ char *envp[] = { "NEW_VMGENID=1", NULL };
u8 old_id[VMGENID_SIZE];

memcpy(old_id, state->this_id, sizeof(old_id));
@@ -33,6 +34,7 @@ static void vmgenid_notify(struct device *device)
if (!memcmp(old_id, state->this_id, sizeof(old_id)))
return;
add_vmfork_randomness(state->this_id, sizeof(state->this_id));
+ kobject_uevent_env(&device->kobj, KOBJ_CHANGE, envp);
}

static void setup_vmgenid_state(struct vmgenid_state *state, void *virt_addr)
--
2.34.1