All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: svt-core@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, den@openvz.org
Subject: [PATCH v2-hci-8.0 2/2] migration/cpr: lock the ramblocks #VSTOR-145529
Date: Fri, 18 Sep 2026 16:36:29 +0200	[thread overview]
Message-ID: <20260918143629.236874-3-den@openvz.org> (raw)
In-Reply-To: <20260918143629.236874-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

The ramblock entries live in the same registry as the descriptors and
are reached the same way, from RAM block setup and teardown, so they
need the same protection.

Take the lock in their accessors too. qemu_ram_free() already holds the
ramlist mutex when it calls in here, and nothing takes the two in the
other order.

Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 migration/cpr.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/migration/cpr.c b/migration/cpr.c
index e2a76c96a2b..a149e790c10 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -239,8 +239,13 @@ static CprRamBlock *find_ramblock(CprRamBlockList *head, const char *name)
 
 void cpr_save_ramblock(const char *name, cpr_ramblock_t ram)
 {
-    CprRamBlock *elem = find_ramblock(&cpr_state.ramblocks, name);
-    cpr_ramblock_t old_ram = elem ? elem->ram : (cpr_ramblock_t) {0, 0};
+    CprRamBlock *elem;
+    cpr_ramblock_t old_ram;
+
+    QEMU_LOCK_GUARD(&cpr_state_lock);
+
+    elem = find_ramblock(&cpr_state.ramblocks, name);
+    old_ram = elem ? elem->ram : (cpr_ramblock_t) {0, 0};
 
     if (old_ram.addr == 0) {
         do_cpr_save_ramblock(name, ram);
@@ -255,7 +260,11 @@ void cpr_save_ramblock(const char *name, cpr_ramblock_t ram)
 
 void cpr_delete_ramblock(const char *name)
 {
-    CprRamBlock *elem = find_ramblock(&cpr_state.ramblocks, name);
+    CprRamBlock *elem;
+
+    QEMU_LOCK_GUARD(&cpr_state_lock);
+
+    elem = find_ramblock(&cpr_state.ramblocks, name);
 
     if (elem) {
         QLIST_REMOVE(elem, next);
@@ -268,8 +277,13 @@ void cpr_delete_ramblock(const char *name)
 
 cpr_ramblock_t cpr_find_ramblock(const char *name)
 {
-    CprRamBlock *elem = find_ramblock(&cpr_state.ramblocks, name);
-    cpr_ramblock_t ram = elem ? elem->ram : (cpr_ramblock_t) {0, 0};
+    CprRamBlock *elem;
+    cpr_ramblock_t ram;
+
+    QEMU_LOCK_GUARD(&cpr_state_lock);
+
+    elem = find_ramblock(&cpr_state.ramblocks, name);
+    ram = elem ? elem->ram : (cpr_ramblock_t) {0, 0};
 
     trace_cpr_find_ramblock(name, (void *) ram.addr, ram.length);
     return ram;
@@ -279,6 +293,8 @@ bool cpr_walk_ramblock(cpr_walk_ramblock_cb cb)
 {
     CprRamBlock *elem;
 
+    QEMU_LOCK_GUARD(&cpr_state_lock);
+
     QLIST_FOREACH(elem, &cpr_state.ramblocks, next) {
         g_assert(elem->ram.addr && elem->ram.length);
         if (!cb(elem->ram, elem->name)) {
-- 
2.53.0


      parent reply	other threads:[~2026-09-18 14:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 14:36 [PATCH v2-hci-8.0 0/2] migration/cpr: lock the cpr state #VSTOR-145529 Denis V. Lunev
2026-09-18 14:36 ` [PATCH v2-hci-8.0 1/2] migration/cpr: lock the saved fds #VSTOR-145529 Denis V. Lunev
2026-09-18 14:36 ` Denis V. Lunev [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918143629.236874-3-den@openvz.org \
    --to=den@openvz.org \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.