All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>
Subject: [PATCH 1/5] tests/migration-stress: Fix stress.c loop
Date: Thu, 26 Nov 2026 18:47:00 -0300	[thread overview]
Message-ID: <20261126214704.3108327-2-farosas@suse.de> (raw)
In-Reply-To: <20261126214704.3108327-1-farosas@suse.de>

The stress.c loop is touching memory out of bounds. The inner loop
variable 'k' is lagging 8 bytes behind the pointers doing the actual
XOR operation:

  for (j = 0; j < pagesPerMB; j++) {
      dataptr = data;
      for (k = 0; k < RAM_PAGE_SIZE; k += sizeof(long long)) {
          ramptr += sizeof(long long);
          dataptr += sizeof(long long);
          *(unsigned long long *)ramptr ^= *(unsigned long long *)dataptr;
      }
  }

I ran into this while tweaking the amount of memory necessary for
running the VM with the stress initrd.

Rewrite the loop without manual pointer arithmetic, use more easily
identifiable patterns and isolate it in an inlined function.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 tests/migration-stress/stress.c | 39 ++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/tests/migration-stress/stress.c b/tests/migration-stress/stress.c
index 88acf8dc257..44db4bef8f0 100644
--- a/tests/migration-stress/stress.c
+++ b/tests/migration-stress/stress.c
@@ -156,14 +156,31 @@ static unsigned long long now(void)
     return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
 }
 
+static inline void xor_1M(void *ram_start, void *data_page)
+{
+    unsigned long long *addr, *data;
+    int i, j, pages_per_mb = RAM_PAGE_SIZE >> 4;
+    int n = RAM_PAGE_SIZE / sizeof(unsigned long long);
+
+    addr = ram_start;
+
+    for (i = 0; i < pages_per_mb; i++) {
+        data = data_page;
+        j = n;
+
+        while (j--) {
+            *addr ^= *data;
+            addr++;
+            data++;
+        }
+    }
+}
+
 static void stressone(unsigned long long ramsizeMB)
 {
-    size_t pagesPerMB = 1024 * 1024 / RAM_PAGE_SIZE;
     g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
-    char *ramptr;
-    size_t i, j, k;
+    size_t i;
     g_autofree char *data = g_malloc(RAM_PAGE_SIZE);
-    char *dataptr;
     size_t nMB = 0;
     unsigned long long before, after;
 
@@ -181,17 +198,9 @@ static void stressone(unsigned long long ramsizeMB)
     before = now();
 
     while (1) {
-
-        ramptr = ram;
-        for (i = 0; i < ramsizeMB; i++, nMB++) {
-            for (j = 0; j < pagesPerMB; j++) {
-                dataptr = data;
-                for (k = 0; k < RAM_PAGE_SIZE; k += sizeof(long long)) {
-                    ramptr += sizeof(long long);
-                    dataptr += sizeof(long long);
-                    *(unsigned long long *)ramptr ^= *(unsigned long long *)dataptr;
-                }
-            }
+        for (i = 0; i < ramsizeMB; i++) {
+            xor_1M(ram, data);
+            nMB++;
 
             if (nMB == 1024) {
                 after = now();
-- 
2.53.0



  reply	other threads:[~2026-11-26 21:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
2026-11-26 21:47 ` Fabiano Rosas [this message]
2026-11-26 21:47 ` [PATCH 2/5] tests/migration-stress: Cleanups to stress.c Fabiano Rosas
2026-11-26 21:47 ` [PATCH 3/5] tests/qtest/migration: Move guest workload code into bootfile.c Fabiano Rosas
2026-11-26 21:47 ` [PATCH 4/5] tests/qtest/migration: Adapt wait_for_serial routine for stress.c Fabiano Rosas
2026-11-26 21:47 ` [PATCH 5/5] tests/qtest/migration: Make it possible to run stress.c Fabiano Rosas
2026-11-27 13:45 ` [PATCH 0/5] migration-test: Support running a real kernel Peter Xu
2026-11-27 14:01   ` Daniel P. Berrangé
2026-11-27 15:01     ` Peter Xu
2026-11-27 19:15       ` Fabiano Rosas
2026-11-27 15:18     ` Fabiano Rosas
2026-11-27 15:33       ` Daniel P. Berrangé

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=20261126214704.3108327-2-farosas@suse.de \
    --to=farosas@suse.de \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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.