qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fabiano Rosas <farosas@suse.de>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	peterx@redhat.com, Li Zhijian <lizhijian@fujitsu.com>
Subject: [PULL 02/12] qtest/migration/rdma: Enforce RLIMIT_MEMLOCK >= 128MB requirement
Date: Tue, 20 May 2025 13:07:41 -0400	[thread overview]
Message-ID: <20250520170751.786787-3-peterx@redhat.com> (raw)
In-Reply-To: <20250520170751.786787-1-peterx@redhat.com>

From: Li Zhijian <lizhijian@fujitsu.com>

Ensure successful migration over RDMA by verifying that RLIMIT_MEMLOCK is
set to at least 128MB. This allocation is necessary due to the requirement
to pin significant portions of guest memory, typically exceeding 100MB
in this test, while the remainder is transmitted as compressed zero pages.

Otherwise, it will fail with:
stderr:
qemu-system-x86_64: cannot get rkey
qemu-system-x86_64: error while loading state section id 2(ram)
qemu-system-x86_64: load of migration failed: Operation not permitted
qemu-system-x86_64: rdma migration: recv polling control error!
qemu-system-x86_64: RDMA is in an error state waiting migration to abort!
qemu-system-x86_64: failed to save SaveStateEntry with id(name): 2(ram): -1
qemu-system-x86_64: Channel error: Operation not permitted

Reported-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Link: https://lore.kernel.org/r/20250509014211.1272640-1-lizhijian@fujitsu.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tests/qtest/migration/precopy-tests.c | 34 +++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tests/qtest/migration/precopy-tests.c b/tests/qtest/migration/precopy-tests.c
index 87b0a7e8ef..5be1cd5742 100644
--- a/tests/qtest/migration/precopy-tests.c
+++ b/tests/qtest/migration/precopy-tests.c
@@ -101,6 +101,35 @@ static void test_precopy_unix_dirty_ring(void)
 
 #ifdef CONFIG_RDMA
 
+#include <sys/resource.h>
+
+/*
+ * During migration over RDMA, it will try to pin portions of guest memory,
+ * typically exceeding 100MB in this test, while the remainder will be
+ * transmitted as compressed zero pages.
+ *
+ * REQUIRED_MEMLOCK_SZ indicates the minimal mlock size in the current context.
+ */
+#define REQUIRED_MEMLOCK_SZ (128 << 20) /* 128MB */
+
+/* check 'ulimit -l' */
+static bool mlock_check(void)
+{
+    uid_t uid;
+    struct rlimit rlim;
+
+    uid = getuid();
+    if (uid == 0) {
+        return true;
+    }
+
+    if (getrlimit(RLIMIT_MEMLOCK, &rlim) != 0) {
+        return false;
+    }
+
+    return rlim.rlim_cur >= REQUIRED_MEMLOCK_SZ;
+}
+
 #define RDMA_MIGRATION_HELPER "scripts/rdma-migration-helper.sh"
 static int new_rdma_link(char *buffer)
 {
@@ -136,6 +165,11 @@ static void test_precopy_rdma_plain(void)
 {
     char buffer[128] = {};
 
+    if (!mlock_check()) {
+        g_test_skip("'ulimit -l' is too small, require >=128M");
+        return;
+    }
+
     if (new_rdma_link(buffer)) {
         g_test_skip("No rdma link available\n"
                     "# To enable the test:\n"
-- 
2.49.0



  parent reply	other threads:[~2025-05-20 17:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20 17:07 [PULL 00/12] Migration 20250520 patches Peter Xu
2025-05-20 17:07 ` [PULL 01/12] scripts/vmstate-static-checker.py: Add new hpet entry for num_timers Peter Xu
2025-05-20 17:07 ` Peter Xu [this message]
2025-05-20 17:07 ` [PULL 03/12] qtest/migration/rdma: Add test for rdma migration with ipv6 Peter Xu
2025-05-20 17:07 ` [PULL 04/12] ci: Re-enable python subtests in qtest migration suite Peter Xu
2025-05-20 17:07 ` [PULL 05/12] ci: Fix build-previous-qemu when the version tag is absent Peter Xu
2025-05-20 17:07 ` [PULL 06/12] ci: Reduce the size of artifacts for build-previous-qemu Peter Xu
2025-05-20 17:07 ` [PULL 07/12] migration: write zero pages when postcopy enabled Peter Xu
2025-05-20 17:07 ` [PULL 08/12] migration: enable multifd and postcopy together Peter Xu
2025-05-20 17:07 ` [PULL 09/12] tests/qtest/migration: add postcopy tests with multifd Peter Xu
2025-05-20 17:07 ` [PULL 10/12] migration/multifd: Don't send device state packets with zerocopy flag Peter Xu
2025-05-20 17:07 ` [PULL 11/12] migration: Allow caps to be set when preempt or multifd cap enabled Peter Xu
2025-05-20 17:07 ` [PULL 12/12] migration/hmp: Add "info migrate -a", reorg the dump Peter Xu
2025-05-22 18:47 ` [PULL 00/12] Migration 20250520 patches Stefan Hajnoczi

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=20250520170751.786787-3-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=farosas@suse.de \
    --cc=lizhijian@fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).