From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796332859; b=lohZaHweDHdxvRp6YEiZlFyFqjha5AsltdQbA+RnXTWsFedIQbs08hVJ+/iOOW3R8enW o1x++GNBCXUacNzHQHtW/8oRPselgw1mXVWh4dcfA5k1GjZr6C4ReQGnCE7EMKbEcbnD3 ask6B+hB44vG2xyS3mF8jxm2OUDR1Gg1oUEbQkUikfVRjWN+62+Yuu7t5ZFyZnokSSb1i 0gIz/Z8+p1aFTkRLruOb8mi6aKGtwzf82YqkGJ5rIcTl7cF9+Qe1ZZgOAoAgxxPzPi0Wj B2aJJ8MZotPo99lN50VzY8JwbwP6Qv9U37Ub23MU1AFPtkXrYHzCbeCfmDWWv5YJiWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796332859; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=/8aesvc2zH1fz3okZmlVxQiGc34dxKVwQ4V6bRNezVU=; b=ZGV0y5ir17LbQVvMIuonBXj44EzvH20Tg+ocAanegSdZx8Jk17BBNlvYsjGfbTmNWyIg aj49PAgKcxNBLXPEl9Zn68zpetHBdcoE1YCNBT3BesZMuprHJaW2z9IVcRqduGlwT16yt +Tc3UWEqen165iZSPLTztuxtcN203W4vJ9+QLeJ4Z8sXGKG57PMnBJjhHZdW+3tS85FKx 8qYzon6zTGBthsiqTtj008uHOH+okcOcbTpa6TRI6tomqtzGxRXQ20Zqys3M+YawN6bex FnNQJQ78m6lUWYTkM4XSaEzr9mAbkR44sHVoYIid5d/otN47UWpLdAefhFZU2xIkEng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bGUpP1ST; arc=none smtp.remote-ip=209.85.210.198 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 737FA60A260B for ; Thu, 3 Dec 2026 21:20:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 737FA60A260B 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--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bGUpP1ST Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-89f84753b43so195952b3a.1 for ; Thu, 03 Dec 2026 13:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796332859; x=1796937659; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/8aesvc2zH1fz3okZmlVxQiGc34dxKVwQ4V6bRNezVU=; b=bGUpP1STQE2X1trL5xTLcXgqPmzREWenRYhIO70jcJF+yFvE5CaPUwqMU9vasHiAN/ X3B9l3Ob2hJyfm6zuKYVuQg/BbO7D9E3ugJK+kZP9aKR7ci6rxGmkgyLY+ivMsoUdvH8 Pie6wK+1FljArBPK93niGXxKFry+AzX6L7FkkdmbGgh15o262O9QEPbdgBbdkotPdrgx ab4pwAU2LL181J5cjPmyHajQNp7UonQL74rJVK6+0wygMlSxpnKBkyY8bWQHG+sGO/Au cl3MprhY9zo6VUZCz25AjAKrBLRYqMhbkIhN4mKL4PprcGzKd20qXHygl0NrSSZ/niKu C/mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796332859; x=1796937659; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/8aesvc2zH1fz3okZmlVxQiGc34dxKVwQ4V6bRNezVU=; b=WjZ2q3g7gq3gnFPeQMV5F+asJT9SQuqSThJIsWhqhLCp811jQygcwhAiTFf8mo8Aiq ENoTIq5878W8jErxYB3GC0eGECgHzBp92w2WQ8C1Mrh5iJKpfbkijTeNKcLSz5pX34Pz IJfbCODFgzrrLj0N3VhmJv5GhOp9lqw42irggwUlMd0HvF8Sp4W98p09s2o+PPZAoGOT GxrdRYyKn3JB9u5IGMu4AontNAhEIVVZL5ArjtFV97EbCn3mD5mc5iyu+PVz9yU7WMiS VewkO7fT4M+AjHLLc6iOjlEp95c2OJ31iv/aRmnTy9NQCgihGnkewIrJUcZj0IIicdib lvxQ== X-Forwarded-Encrypted: i=1; AL+hErFSSlpLWXVQrQQhsrPIf4wh27clJR4/j2Tz6Z/Wz+ir1212iXJlpmWjb+pow3reNi+dQRLXDmDrBT4dC2g=@vger.kernel.org X-Gm-Message-State: APuU4Z8rBdBFBa+A/RPfSEKJ0lp3gHufRwVrJNSIXozscGGPdJSPZ/Yb WoLNxzfMrDcZ9M20UuZwQrIruRRf0naDWoCPC56/ayU1NhNDb+0QZLbj5A4lrtdnhHnMhcEdep4 sacP7paFdl6LcBS/OEkt5Ug== X-Received: from pgfv23-n2.prod.google.com ([2002:a05:6a02:8757:20b0:cdb:a0a4:6a40]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:57ef:b0:3b5:a3:4425 with SMTP id 98e67ed59e1d1-3b500a34698mr27375404a91.42.1796332858499; Thu, 03 Dec 2026 13:20:58 -0800 (PST) Date: Thu, 3 Dec 2026 21:20:53 +0000 In-Reply-To: <20261203212054.2957430-1-jthoughton@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203212054.2957430-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261203212054.2957430-5-jthoughton@google.com> Subject: [PATCH v2 4/4] KVM: selftests: Verify KVM doesn't reset unused dirty ring entries From: James Houghton To: Sean Christopherson , Paolo Bonzini Cc: Peter Xu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+55eaa971f4924b62c9a5@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" Before running the vCPU in the dirty ring test, mark the first two (unused) entries of the ring as harvested and verify that KVM_RESET_DIRTY_RINGS doesn't reset any entries, i.e. that KVM doesn't advance reset_index beyond dirty_index. Clear the flags afterwards, so that the bogus RESET flags can't race with KVM pushing to the entries. Signed-off-by: James Houghton --- tools/testing/selftests/kvm/dirty_log_test.c | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 8189eaac713c..b03ce06ce100 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -375,6 +375,28 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, "with collected (%u)", cleared, count); } +static void dirty_ring_reset_unused_entries(struct kvm_vcpu *vcpu) +{ + struct kvm_dirty_gfn *dirty_gfns = vcpu_map_dirty_ring(vcpu); + + /* + * Mark unused entries as harvested, and verify KVM doesn't reset any + * entries, as KVM hasn't pushed anything to the ring. + */ + dirty_gfn_set_collected(&dirty_gfns[0]); + dirty_gfn_set_collected(&dirty_gfns[1]); + + TEST_ASSERT_EQ(kvm_vm_reset_dirty_ring(vcpu->vm), 0); + + /* + * Clear the bogus RESET flags, otherwise a reset that runs while KVM + * is pushing to the entries could reset them before userspace has + * collected them. + */ + dirty_gfns[0].flags = 0; + dirty_gfns[1].flags = 0; +} + static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; @@ -687,6 +709,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) TEST_ASSERT_EQ(vcpu_stop, false); + if (host_log_mode == LOG_MODE_DIRTY_RING) + dirty_ring_reset_unused_entries(vcpu); + kvm_pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); for (iteration = 1; iteration <= p->iterations; iteration++) { -- 2.56.1.915.g69d5ec7298-goog