Browse Source

accel/kvm: notify when KVM VM file fd is about to be changed

Various subsystems might need to take some steps before the KVM file descriptor
for a virtual machine is changed. So a new boolean attribute is added to the
vmfd_notifier structure which is passed to the notifier callbacks.
vmfd_notifer.pre is true for pre-notification of vmfd change and false for
post notification. Notifier callback implementations can simply check
the boolean value for (vmfd_notifer*)->pre and can take actions for pre or
post vmfd change based on the value.

Subsequent patches will add callback implementations for specific components
that need this pre-notification.

Signed-off-by: Ani Sinha <anisinha@redhat.com>
Link: https://lore.kernel.org/r/20260225035000.385950-9-anisinha@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
master
Ani Sinha 1 month ago
committed by Paolo Bonzini
parent
commit
0f53f021ad
  1. 9
      accel/kvm/kvm-all.c
  2. 6
      include/system/kvm.h

9
accel/kvm/kvm-all.c

@ -2654,6 +2654,13 @@ static int kvm_reset_vmfd(MachineState *ms)
memory_listener_unregister(&kml->listener);
memory_listener_unregister(&kvm_io_listener);
vmfd_notifier.pre = true;
ret = kvm_vmfd_change_notify(&err);
if (ret < 0) {
return ret;
}
assert(!err);
if (s->vmfd >= 0) {
close(s->vmfd);
}
@ -2695,6 +2702,8 @@ static int kvm_reset_vmfd(MachineState *ms)
* notify everyone that vmfd has changed.
*/
vmfd_notifier.vmfd = s->vmfd;
vmfd_notifier.pre = false;
ret = kvm_vmfd_change_notify(&err);
if (ret < 0) {
return ret;

6
include/system/kvm.h

@ -571,12 +571,14 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private);
/* argument to vmfd change notifier */
typedef struct VmfdChangeNotifier {
int vmfd;
bool pre;
} VmfdChangeNotifier;
/**
* kvm_vmfd_add_change_notifier - register a notifier to get notified when
* a KVM vm file descriptor changes as a part of the confidential guest "reset"
* process. Various subsystems should use this mechanism to take actions such
* a KVM vm file descriptor changes or about to be changed as a part of the
* confidential guest "reset" process.
* Various subsystems should use this mechanism to take actions such
* as creating new fds against this new vm file descriptor.
* @n: notifier with return value.
*/

Loading…
Cancel
Save