Track whether saved CPR file descriptors can be used for LUO. Currently, only RAMBlock fds (RAM or device/firmware related memory) are used for LUO.
To find the locations to mark a CprFd as LUO, I simply searched for all direct and indirect callers of cpr_save_fd(). Most of them are for VFIO and can be ignored. Another option is to introduce additional argument to existing cpr_save_fd(). Just add additional function for simplicity. Signed-off-by: Dongli Zhang <[email protected]> --- backends/hostmem-memfd.c | 1 + backends/hostmem-shm.c | 1 + include/migration/cpr.h | 2 ++ migration/cpr.c | 8 ++++++++ system/physmem.c | 1 + 5 files changed, 13 insertions(+) diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 666593ff6c..c47bb09ba2 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -85,6 +85,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) return false; } cpr_save_fd(name, 0, fd); + cpr_mark_fd_luo(name, 0); have_fd: backend->aligned = true; diff --git a/backends/hostmem-shm.c b/backends/hostmem-shm.c index 4766db6aad..77ec329f70 100644 --- a/backends/hostmem-shm.c +++ b/backends/hostmem-shm.c @@ -49,6 +49,7 @@ shm_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) return false; } cpr_save_fd(backend_name, 0, fd); + cpr_mark_fd_luo(backend_name, 0); have_fd: /* Let's do the same as memory-backend-ram,share=on would do. */ diff --git a/include/migration/cpr.h b/include/migration/cpr.h index 5f30df7ec8..425f6ee956 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -23,6 +23,7 @@ typedef struct CprFd { unsigned int namelen; int id; int fd; + bool luo; QLIST_ENTRY(CprFd) next; } CprFd; @@ -37,6 +38,7 @@ typedef struct CprState { extern CprState cpr_state; void cpr_save_fd(const char *name, int id, int fd); +void cpr_mark_fd_luo(const char *name, int id); void cpr_delete_fd(const char *name, int id); int cpr_find_fd(const char *name, int id); void cpr_resave_fd(const char *name, int id, int fd); diff --git a/migration/cpr.c b/migration/cpr.c index 33ac74c1f3..9b6b85cedd 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -141,6 +141,14 @@ static CprFd *find_fd(const char *name, int id) return g_hash_table_lookup(get_cpr_fds_hash(), &key); } +void cpr_mark_fd_luo(const char *name, int id) +{ + CprFd *elem = find_fd(name, id); + + g_assert(elem); + elem->luo = true; +} + void cpr_delete_fd(const char *name, int id) { CprFd key = { diff --git a/system/physmem.c b/system/physmem.c index db3dda563d..263acb5727 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2458,6 +2458,7 @@ static int qemu_ram_get_shared_fd(const char *name, bool *reused, Error **errp) if (fd >= 0) { cpr_save_fd(name, 0, fd); + cpr_mark_fd_luo(name, 0); } *reused = false; return fd; -- 2.43.5
