From nobody Sun May 24 19:33:16 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66E2F39DBDF for ; Fri, 22 May 2026 17:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779469354; cv=none; b=Bqp39tamSIeUCHsL82+/OIogLseO8/+Dz4hgI4pWghcRt1YVMTeCjcTAqOUJtj4AaSb4jmyxoaJr2H9meDB+ciwGqDxWi6wo/POrJPEbV1GG0w1zW8yfVFUmh155j5L2wY6j3NC0ft5qOgAAq2FX6H9YX74qrqTf3b60BgnpgIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779469354; c=relaxed/simple; bh=n+Ek3Ws8wWLqyf1VtzuVpf5o4IGoK6S7xtRI88xbYMw=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Iyj/CK5kXGDIJ983aNKHf3cykSEkuIBPZ9CtmWwgLBm2YVjnUlJnUL0z2YrwlDQtrh05pCVccUbunTAxIhZwDZ2c0clEY8mLQyKC6nweU2Neh5GTBNC0CuXk5Q5dS9s78hRO7QGQ9mSKAVIr7cknHprl3F5kolHEX00wS9G5dKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RWcEXjZv; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RWcEXjZv" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3662668b825so14728211a91.3 for ; Fri, 22 May 2026 10:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779469352; x=1780074152; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=TVQTo/y4OvxKNW+AzFT5BpwwAI18QisLaW74bb9QAcc=; b=RWcEXjZvOkqyUhF0gbWeBiTrSp1IzvTgBYGXxEooJEPeZDYeOsJVI7ORzdMh89UGnU /m7i5SCqg8/NPQZqliV1+zkMTlkbyXXsKMQPg7CSByeux3lpZvo5WNixySofAezPnb4E AAlGwp1WrMwdT11Z8cD3SlzFYLsViVeO/hgNO6CvkxK5W/CdB4hPhXYoOmRbPI1uTImz ys6JE7VKRoegi69j4e+SNDuN7XHERKSb35jhqmsFh5Blrr0JUvQzVhmS7TG4HrYfACDk rSf944sxRwdtU0NfOC/b+3bYL7cCZfQOOJm2brHajtKjxjTxOHjbpTmWu4vyTx1bjaMA 2zTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779469352; x=1780074152; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TVQTo/y4OvxKNW+AzFT5BpwwAI18QisLaW74bb9QAcc=; b=jffe91U4640/mb+aAJ5K9VAgcdDN91lqcNyPRIIAJvZQdQ+nQ9G0aNIGXJOLY5MJnM aGC8W4hAFR9BGAn3QseXmu+qaH2/8X4uLms3yiep14oKrSAs5KJyxFzrqAyIix5FBRpB b8BTxM9E7BLbBAIVNw3lmb9GuIxdf5QVqEXgjtknF8DxxIjVfhOX/eBwXqJuakXkILc7 g0OnL2jlHY21THN9zOSzbszYxosQCEqPKcdMD/Qa1Fg+NfP4q30hzmPFsMkYy+jqv9QP FiVL+4q6bzjG7g4ynbbRF6XjgRCTz85/fSJKjXHqm4T/1Nmbde1BvcLke8kIP2h5JWQN SbEQ== X-Forwarded-Encrypted: i=1; AFNElJ9bkwO0t+/nkQKBKe0//ONieZvpfRaLPh/C219Z6Iqz37moauZJOjb5CubyN/TA92Uz0iFIyUFLrMU6m2U=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0fm6c1TbmWx3TJZ+6nxP6C7YmJork+m+VPb1v96025UJCY4pp UBTFe6YxUQOHkLVcEL3PpzS7kwbgP7cRCiWZedrgxfKqErKL4ObFdKBeBdjfJpwOkeMHGmUXpga zr//l4Q== X-Received: from pjqh12.prod.google.com ([2002:a17:90a:a88c:b0:365:ee77:7689]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b82:b0:368:1088:bb1d with SMTP id 98e67ed59e1d1-36a677c5eb0mr4585071a91.15.1779469352254; Fri, 22 May 2026 10:02:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 22 May 2026 10:02:30 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.794.g4f17f83d09-goog Message-ID: <20260522170230.3518669-1-seanjc@google.com> Subject: [PATCH] KVM: selftests: Randomize dirty_log_test's delay before reaping the bitmap From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wu Fei , Wu Fei , Sean Christopherson Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the dirty log test, randomize the delay before the initial call to get the dirty log bitmap for a given iteration, so that the amount of memory dirtied by the guest varies from iteration to iteration, and so that the user can effectively control the duration (by increasing the interval). Always waiting 1ms effectively hides a KVM RISC-V bug as the test reaps the dirty bitmap before the guest has a chance to trigger the problematic flow in KVM. Reported-by: Wu Fei Closes: https://lore.kernel.org/all/202605111130.64BBUXDN013040@mse-fl2.zte= .com.cn Cc: Wu Fei Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/s= elftests/kvm/dirty_log_test.c index 12446a4b6e8d..74ca096bf976 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -694,7 +694,17 @@ static void run_test(enum vm_guest_mode mode, void *ar= g) pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); =20 for (iteration =3D 1; iteration <=3D p->iterations; iteration++) { - unsigned long i; + unsigned long i, reap_i; + + /* + * Select a random point in the time interval to reap the dirty + * bitmap/ring while the guest is running, i.e. randomize how + * long the guest gets to initially run and thus how many pages + * it can dirty, before collecting the dirty bitmap/ring. See + * the loop below for details. + */ + reap_i =3D random() % p->interval; + printf("Reaping after a %lu ms delay\n", reap_i); =20 sync_global_to_guest(vm, iteration); =20 @@ -729,13 +739,17 @@ static void run_test(enum vm_guest_mode mode, void *a= rg) * that's effectively blocked. Collecting while the * guest is running also verifies KVM doesn't lose any * state. - * + */ + if (i < reap_i) + continue; + + /* * For bitmap modes, KVM overwrites the entire bitmap, * i.e. collecting the bitmaps is destructive. Collect - * the bitmap only on the first pass, otherwise this - * test would lose track of dirty pages. + * the bitmap while the guest is running only once, + * otherwise this test would lose track of dirty pages. */ - if (i && host_log_mode !=3D LOG_MODE_DIRTY_RING) + if (i > reap_i && host_log_mode !=3D LOG_MODE_DIRTY_RING) continue; =20 /* @@ -745,7 +759,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) * the ring on every pass would make it unlikely the * vCPU would ever fill the fing). */ - if (i && !READ_ONCE(dirty_ring_vcpu_ring_full)) + if (i > reap_i && !READ_ONCE(dirty_ring_vcpu_ring_full)) continue; =20 log_mode_collect_dirty_pages(vcpu, TEST_MEM_SLOT_INDEX, base-commit: 66939c1603bd5579e63278f9dc72cba5b79da9b5 --=20 2.54.0.794.g4f17f83d09-goog