From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA8071FBCB7 for ; Wed, 18 Dec 2024 00:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734480007; cv=none; b=XR3572l5CHuMSiUnNnd2NYp1Lcr9mGxbk7whhvHBPgMRTHJRUZ6dUvT1lolYQNMmfbAhs0V1nMmeecX1wX6U6W8Y/IRlnGIyFaya18apQJQyepKG/KFXabE/bnwJ2o8XL5O3hbSGni3hqQ/RbfgRdufxJCaiuWsf208kEEn3Msw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734480007; c=relaxed/simple; bh=SleDlVMQqj5Io+jnSUfKNvetPmxTTTd68cIBXfEucIc=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=TLCVoyFMWqA5PArohZpXFJNpeBdxaBkIJLMtxvZlkQcAM6llM/QJemgY8D4MHien8mgiPohumzPPOGOfP6y/uGUOviBubKtwALugTrOdWeo1SAMZob2HsoSlMx4zwW/4vofQBhoCMWVOxiky/tTNX/sFvcZHclO5N0Fjinx6GUs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=P7Wkwzwh; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P7Wkwzwh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734480004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B9qTG2CUzXDnW++v7sE/8F+PXM4P/68p1aafZpzsDtc=; b=P7Wkwzwh18pWet1ZH+WW3tkf82jrpRh4JeJ7GYQRXSa1X4DmIzT9sy71EEKA8ZykZf+dYZ 00YOt2GimirzZe8kswzCeeIfyP6W3ohzgiCDCUO2pKIVhcIIcNU6uxASSxjhZOzR/hrtp6 xIciOA8empTHHBb8LAbKi+0ABDmoqII= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-3bLB7XFvMiSBE172fUUt7g-1; Tue, 17 Dec 2024 19:00:02 -0500 X-MC-Unique: 3bLB7XFvMiSBE172fUUt7g-1 X-Mimecast-MFC-AGG-ID: 3bLB7XFvMiSBE172fUUt7g Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a81570ea43so56594485ab.0 for ; Tue, 17 Dec 2024 16:00:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734480002; x=1735084802; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=B9qTG2CUzXDnW++v7sE/8F+PXM4P/68p1aafZpzsDtc=; b=HimQvxqZeuuGnFvVXxWqKXzrUmL3apJEeX4aM2sNS86Wrm6Sfa4E4nkVxkX7XQtQJ6 IjuPTfA8j5mSukxhFbxyOeG8zwfLT5EX9rtWuyIKOm1R6pzRgFQ1w6juFdaGlJcHgBJm aJs+6cpveiItqD8uTNn/p2Kb24QVENT9CxqETxthLx36ohewj8h0bEbxefMh77Z65j+q 8a7QsZTwXmzUDjrnwTgs/llLEqlYCZLYTQWSsaC2gChrEKboaDH6sLfCbiLk5osDc9CZ xY4sMeYXyPkktTP5TYLbo0XasK01ZgYkVBPnLk+qN/ICF/iXzoLR/xyyINjKpum3IXDp 3jZg== X-Forwarded-Encrypted: i=1; AJvYcCUntDOLBpAfAujR4ZPAkp0lRllQdZ2HMv/xWoDYZr95srfbehnnkhvtlMbHLLqwrKmNuaDHLg48nih8ii8=@vger.kernel.org X-Gm-Message-State: AOJu0YyyTum5DCeSqfl/y4GitaRInbndBKjGn/f7AmxVJn4YRJ+0j1M9 sSV7T62x3+UrAtoQeBvIp0y+8YnDggd0N+7uat6BDvah3cmbg293tO5q9ThaRsOcBwgnlnRmhHJ 2knwK7F5+Vecn8yF7u30MtCBYxxsC1QEGBhD5zT6hOBFvLJZQBNs6Trkj+o6WerBBh8Of6A== X-Gm-Gg: ASbGncsC6fd88zWk2piuf1MKoFtxaql+qewVGFj9lQQBUzWSpGbc2b7c4RARQWTtLWy h3Y/Cgx+z96JC35HfBdDyHKnqn8v0gsbKkhq+t46jqMH+S9vq2BNK/59NT3Be1VCtHdz4oAtjSz RtOpROuhApp0PJW90A9UB91ZfwLZ+8X2qYLft2expf0T/lNeUR+zoTwzkPG8qDtr2qgJhnK0LVA Fdi2HGdmBmybGHg+Xj4ZEYW5v1ZmyMs6a1z+zDzO4hKBrSLcMH/40GF X-Received: by 2002:a05:6e02:1a62:b0:3a7:7124:bd2b with SMTP id e9e14a558f8ab-3bdc437b5a1mr8371025ab.15.1734480001869; Tue, 17 Dec 2024 16:00:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjLQr1P+5FhEYSL6bfCst12hiBbYYtqLq49XVoeIDwshRqaVBDwI+REbhW0YHjpYYeYM7tpw== X-Received: by 2002:a05:6e02:1a62:b0:3a7:7124:bd2b with SMTP id e9e14a558f8ab-3bdc437b5a1mr8370895ab.15.1734480001524; Tue, 17 Dec 2024 16:00:01 -0800 (PST) Received: from starship ([2607:fea8:fc01:8d8d:6adb:55ff:feaa:b156]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e5e32a2dfdsm1919571173.105.2024.12.17.16.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 16:00:01 -0800 (PST) Message-ID: Subject: Re: [PATCH 07/20] KVM: selftests: Continuously reap dirty ring while vCPU is running From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu Date: Tue, 17 Dec 2024 19:00:00 -0500 In-Reply-To: <20241214010721.2356923-8-seanjc@google.com> References: <20241214010721.2356923-1-seanjc@google.com> <20241214010721.2356923-8-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit On Fri, 2024-12-13 at 17:07 -0800, Sean Christopherson wrote: > Continue collecting entries from the dirty ring for the entire time the > vCPU is running. Collecting exactly once all but guarantees the vCPU will > encounter a "ring full" event and stop. While testing ring full is > interesting, stopping and doing nothing is not, especially for larger > intervals as the test effectively does nothing for a much longer time. > > To balance continuous collection with letting the guest make forward > progress, chunk the interval waiting into 1ms loops (which also makes > the math dead simple). > > To maintain coverage for "ring full", collect entries on subsequent > iterations if and only if the ring has been filled at least once. I.e. > let the ring fill up (if the interval allows), but after that contiuously > empty it so that the vCPU can keep running. > > Opportunistically drop unnecessary zero-initialization of "count". > > Signed-off-by: Sean Christopherson > --- > tools/testing/selftests/kvm/dirty_log_test.c | 63 ++++++++++++++------ > 1 file changed, 46 insertions(+), 17 deletions(-) > > diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c > index 5a04a7bd73e0..2aee047b8b1c 100644 > --- a/tools/testing/selftests/kvm/dirty_log_test.c > +++ b/tools/testing/selftests/kvm/dirty_log_test.c > @@ -340,8 +340,6 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns, > struct kvm_dirty_gfn *cur; > uint32_t count = 0; > > - dirty_ring_prev_iteration_last_page = dirty_ring_last_page; > - > while (true) { > cur = &dirty_gfns[*fetch_index % test_dirty_ring_count]; > if (!dirty_gfn_is_dirtied(cur)) > @@ -360,17 +358,11 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns, > return count; > } > > -static void dirty_ring_continue_vcpu(void) > -{ > - pr_info("Notifying vcpu to continue\n"); > - sem_post(&sem_vcpu_cont); > -} > - > static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, > void *bitmap, uint32_t num_pages, > uint32_t *ring_buf_idx) > { > - uint32_t count = 0, cleared; > + uint32_t count, cleared; > > /* Only have one vcpu */ > count = dirty_ring_collect_one(vcpu_map_dirty_ring(vcpu), > @@ -385,9 +377,6 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, > */ > TEST_ASSERT(cleared == count, "Reset dirty pages (%u) mismatch " > "with collected (%u)", cleared, count); > - > - if (READ_ONCE(dirty_ring_vcpu_ring_full)) > - dirty_ring_continue_vcpu(); > } > > static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) > @@ -404,7 +393,6 @@ static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) > sem_post(&sem_vcpu_stop); > pr_info("Dirty ring full, waiting for it to be collected\n"); > sem_wait(&sem_vcpu_cont); > - pr_info("vcpu continues now.\n"); > WRITE_ONCE(dirty_ring_vcpu_ring_full, false); > } else { > TEST_ASSERT(false, "Invalid guest sync status: " > @@ -755,11 +743,52 @@ static void run_test(enum vm_guest_mode mode, void *arg) > pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); > > while (iteration < p->iterations) { > + bool saw_dirty_ring_full = false; > + unsigned long i; > + > + dirty_ring_prev_iteration_last_page = dirty_ring_last_page; > + > /* Give the vcpu thread some time to dirty some pages */ > - usleep(p->interval * 1000); > - log_mode_collect_dirty_pages(vcpu, TEST_MEM_SLOT_INDEX, > - bmap, host_num_pages, > - &ring_buf_idx); > + for (i = 0; i < p->interval; i++) { > + usleep(1000); > + > + /* > + * Reap dirty pages while the guest is running so that > + * dirty ring full events are resolved, i.e. so that a > + * larger interval doesn't always end up with a vCPU > + * that's effectively blocked. Collecting while the > + * guest is running also verifies KVM doesn't lose any > + * state. > + * > + * 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. > + */ > + if (i && host_log_mode != LOG_MODE_DIRTY_RING) > + continue; > + > + /* > + * For the dirty ring, empty the ring on subsequent > + * passes only if the ring was filled at least once, > + * to verify KVM's handling of a full ring (emptying > + * the ring on every pass would make it unlikely the > + * vCPU would ever fill the fing). > + */ > + if (READ_ONCE(dirty_ring_vcpu_ring_full)) > + saw_dirty_ring_full = true; > + if (i && !saw_dirty_ring_full) > + continue; > + > + log_mode_collect_dirty_pages(vcpu, TEST_MEM_SLOT_INDEX, > + bmap, host_num_pages, > + &ring_buf_idx); > + > + if (READ_ONCE(dirty_ring_vcpu_ring_full)) { > + pr_info("Dirty ring emptied, restarting vCPU\n"); > + sem_post(&sem_vcpu_cont); > + } > + } > > /* > * See vcpu_sync_stop_requested definition for details on why This looks reasonable. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky