From nobody Thu Dec 18 05:23:38 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 95DDB1991CD for ; Sat, 11 Jan 2025 00:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736555441; cv=none; b=jg+1PrPNPkOQ+X6AlLl80HbaCyAkabvk6xEMpNgxoSzSRD17ddSrp77DPX7JtKdAJUrMq/wltNn+Le154uPPz6Ee/IWEG/7dEHoiUcgds7AkDZ9GYYCrHCqSBqf84FN3avMxj3nUnMWbfR95ZlV6cdtkWV+oq/Edr4JSCwTfkE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736555441; c=relaxed/simple; bh=L8D0b1+KiW9ahs+qBDC4G+scCazWGnThE6lO6mNZavo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PJdLV4XLaf87We6rUeoMJmaK8cRj35WCGwZLYxsDnGTvJT3TsCpFq8XS3CoZRBEyrnej6+SnpZddNvbDp1drCJyRssZ5AdpjqddvKavuLUKvgjiSMJYegZb92XVorlfWapNdkGB3bJ7NI44m31QHunMSK5VnO1tE+mNW8ZSUy/0= 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=Z5JrCNUY; arc=none smtp.client-ip=209.85.216.73 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="Z5JrCNUY" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef9dbeb848so4563138a91.0 for ; Fri, 10 Jan 2025 16:30:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736555439; x=1737160239; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=S8bBOr0/HNvEyebC3bb/WW1HKqndMpC6/ffxTDW/jVI=; b=Z5JrCNUYFVEFwq0KZ9FlqZ1Om7cI+IF/5d+hW+8qXsVFOZ+bChU3rvLHzK7CJOaQev FffoTNa/ir12uQqJW92M3KtmyXIo9xkuSG64LGFTasxAAl0yS5UGVQ2J18bR0BFYfsc2 Vv4iSm7+XLcLqfz1fiSXYzrR+XGvPP43Yxd89NXMPPbIJhB6/w9jc8si3DAvsilOPFUT fVwXfcZXQpeCy3MoIU7YZxTl8ZcmKUAgTcNveUySCH4hU0hyKwb1JTTd8q9VBivnIGD+ kLYFDjSz5Gdm6byhtV7omiS4gTEfeDhVOJTUVYFz+hiy177VGPS36WiBy4i96y/gnFmb YGpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736555439; x=1737160239; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=S8bBOr0/HNvEyebC3bb/WW1HKqndMpC6/ffxTDW/jVI=; b=rzFuSUDMUBrzIUDUxVfw849SpvL+q/ncZ5UG/EXwe8DRvQ417NvHOriiMS5e1BV6UU 7VkrD2guc9J+6/zVVl2m850jOq4iVPCkAoFYvONuAk1tDlaMdgr7uc2kLZwTr5kK+cCV kXVWKlFuaBBNz6rn2gifU2qVNErLUH0N7bZeUtfRR06iy0YkAR987CzNbF2cndRI1j6W OFJ5m6uEtGY5YMwY5XGnyG0dVgSdCylbOCJrbOQ1XNxlK/8xB+ZiMzsQPRhjNMJDMo/r zCz7ZfF7nFaVutmFOU+eRzWC/dXmMDaC2so/Ro1+GRjmdA2bwBMUDb8bONJahji7n0Vk KnPQ== X-Forwarded-Encrypted: i=1; AJvYcCU5k2R/VhwciohTxWRZIn+H6t+jrRKHiC6+Ze/d+RZym4bPN26TjaSsnOM2k83n3ciDJcwS5t9p3ILiuhs=@vger.kernel.org X-Gm-Message-State: AOJu0YwGKcChO0Zl/Nwvzi2gyFNd/4zqhDDmh1gt61aTyyAgXvtDmmef iaoFpdvMrQlEz19ZP0lylSez00BGksGTmG23bRfGPOI6CUVxGl2DWquJRkzJV/WW0TwKFnukkBi vdg== X-Google-Smtp-Source: AGHT+IG8OJ4cGazMV/P/Pm31Fw9xdVTCsOZDWRosn8YO8BNm6aYjr7+8IBYnSgIAeh1WsD1lcKtnyJmoRDE= X-Received: from pjbnd3.prod.google.com ([2002:a17:90b:4cc3:b0:2f4:432d:250c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1348:b0:2ee:cb5c:6c with SMTP id 98e67ed59e1d1-2f548ee54ccmr15776191a91.22.1736555439070; Fri, 10 Jan 2025 16:30:39 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 10 Jan 2025 16:30:02 -0800 In-Reply-To: <20250111003004.1235645-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250111003004.1235645-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250111003004.1235645-19-seanjc@google.com> Subject: [PATCH v2 18/20] KVM: selftests: Set per-iteration variables at the start of each iteration From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Set the per-iteration variables at the start of each iteration instead of setting them before the loop, and at the end of each iteration. To ensure the vCPU doesn't race ahead before the first iteration, simply have the vCPU worker want for sem_vcpu_cont, which conveniently avoids the need to special case posting sem_vcpu_cont from the loop. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 43 ++++++++------------ 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/s= elftests/kvm/dirty_log_test.c index e9854b5a28f1..40567257ebea 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -481,6 +481,8 @@ static void *vcpu_worker(void *data) { struct kvm_vcpu *vcpu =3D data; =20 + sem_wait(&sem_vcpu_cont); + while (!READ_ONCE(host_quit)) { /* Let the guest dirty the random pages */ vcpu_run(vcpu); @@ -675,15 +677,9 @@ static void run_test(enum vm_guest_mode mode, void *ar= g) sync_global_to_guest(vm, guest_test_virt_mem); sync_global_to_guest(vm, guest_num_pages); =20 - /* Start the iterations */ - iteration =3D 1; - sync_global_to_guest(vm, iteration); - WRITE_ONCE(host_quit, false); host_dirty_count =3D 0; host_clear_count =3D 0; - WRITE_ONCE(dirty_ring_vcpu_ring_full, false); - WRITE_ONCE(nr_writes, 0); - sync_global_to_guest(vm, nr_writes); + WRITE_ONCE(host_quit, false); =20 /* * Ensure the previous iteration didn't leave a dangling semaphore, i.e. @@ -695,12 +691,22 @@ static void run_test(enum vm_guest_mode mode, void *a= rg) sem_getvalue(&sem_vcpu_cont, &sem_val); TEST_ASSERT_EQ(sem_val, 0); =20 + TEST_ASSERT_EQ(vcpu_stop, false); + pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); =20 - while (iteration < p->iterations) { + for (iteration =3D 1; iteration < p->iterations; iteration++) { unsigned long i; =20 + sync_global_to_guest(vm, iteration); + + WRITE_ONCE(nr_writes, 0); + sync_global_to_guest(vm, nr_writes); + dirty_ring_prev_iteration_last_page =3D dirty_ring_last_page; + WRITE_ONCE(dirty_ring_vcpu_ring_full, false); + + sem_post(&sem_vcpu_cont); =20 /* * Let the vCPU run beyond the configured interval until it has @@ -785,26 +791,11 @@ static void run_test(enum vm_guest_mode mode, void *a= rg) bmap[1], host_num_pages, &ring_buf_idx); vm_dirty_log_verify(mode, bmap); - - /* - * Set host_quit before sem_vcpu_cont in the final iteration to - * ensure that the vCPU worker doesn't resume the guest. As - * above, the dirty ring test may stop and wait even when not - * explicitly request to do so, i.e. would hang waiting for a - * "continue" if it's allowed to resume the guest. - */ - if (++iteration =3D=3D p->iterations) - WRITE_ONCE(host_quit, true); - sync_global_to_guest(vm, iteration); - - WRITE_ONCE(nr_writes, 0); - sync_global_to_guest(vm, nr_writes); - - WRITE_ONCE(dirty_ring_vcpu_ring_full, false); - - sem_post(&sem_vcpu_cont); } =20 + WRITE_ONCE(host_quit, true); + sem_post(&sem_vcpu_cont); + pthread_join(vcpu_thread, NULL); =20 pr_info("Total bits checked: dirty (%lu), clear (%lu)\n", --=20 2.47.1.613.gc27f4b7a9f-goog