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 <[email protected]> --- accel/kvm/kvm-all.c | 9 +++++++++ include/system/kvm.h | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b8a0685f7a..47589f92e2 100644 --- a/accel/kvm/kvm-all.c +++ b/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); } @@ -2692,6 +2699,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; diff --git a/include/system/kvm.h b/include/system/kvm.h index f11729f432..fbe23608a1 100644 --- a/include/system/kvm.h +++ b/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. */ -- 2.42.0
