From patchwork Sat Dec 14 01:07:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908234 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 4CC5A1799F for ; Sat, 14 Dec 2024 01:07:26 +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=1734138449; cv=none; b=Bd/JGNdngmleQztuxfvrdSPCn2lfi+Ka2Pd31vW6miQB9ApxV3bhQCwsT0u8Di4UELOhUouJpi3NkssgLNppM2mGHrSnjD0582b5EPp36kQboYvYsvqyIhR21pPUyoq7yOcQB0oFUk4TXLPQnFQ88rQT8VMb9bFspHjLP1CnLq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138449; c=relaxed/simple; bh=cSnwUK/2rXGD+rrAuQ2cWaSYdAoHz1OuzoU7A8Ugyzw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GS4cYVPuKpYGtStww6ehj3RJOTgsAfNG6w3b8Hq7gsztqoYaTY0JFtGVUQln70ZiZCX7AS/yUeRB7nDPtrqJHtCbIUkKM1Ms1XDkoHdb99smKfo+hYu2QsT49tbmLAjYVL9O4fnzpAOcZPb2UuE7LND3R6JyZdwteXwV4JtdZY4= 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=p8Igj+q/; 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="p8Igj+q/" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so3109441a91.3 for ; Fri, 13 Dec 2024 17:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138445; x=1734743245; 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=FDkeem6MqewIEXRWoJcJJSDt8+RewhtQwmeUHyoVvwQ=; b=p8Igj+q/GB/05CyWdpM+D2gC13AKjgcSTCKkYZvIWWi0G1V97/D/g85yIgBFOAcpUU hxhHAoPvZRGA9JPz8QpFBerjqDtVzZyxYV4sgZaGKu+wZ2qHAQJXzRY/JX/LH8Su0+2+ O9A49qfvmxZa0jK/KCh6GFSlVEUB51l0+ojpmJxzD2NPt61dptpZwff0wKpQS7FQS/L0 hZgDuY6xJzJP4KgSwuIBeajitheja8I+uhZmzdmMq5B7Vr0GRi5a4MkPjHdw3iA4n1FR VE+XRxO0Z43SB0WepodwIrUu4oOFKhexTLAlN33ahyvdv1sM21CajGimX9DqHg7912Ov Xaqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138445; x=1734743245; 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=FDkeem6MqewIEXRWoJcJJSDt8+RewhtQwmeUHyoVvwQ=; b=slVy5P0ZVV/YQh1ZHBsO/rcImBmRrHDvkQoaEBeU2RiauN8k3644wohsnIrl5a3Gme sJr9UI9RLReY/HG8F/ju3/7HGnWxIYflXCm228TVBBwtjcdK6PVBxsxj7X13U5U/ysM4 dVxD6uwOWCRQZC2F7K5IbaVJI8M6fCvSzOLkBqF5Xz1d8wRFdtICOfCqP1fyGwU6wYKi b7NhJWvmy7U1OeGhlzjp84940tMmuowDxk7vYbaIX5/SMIh8eNp9PqDdJfiB4aA7VrWb F6XC7bR1F5p8duhqxoT2pkTDaECiEDhrCZDJPkQLjRvVrybh/NWQiuViKUn1cnVi1NL3 4vKA== X-Gm-Message-State: AOJu0YzEastKXlGR8H9MgwI8yTRSRne/v9A623sYMidQoq2Pe14mUnFW FsgChVpiV8fTOG495X9N3mo/SM0geUvfLZZqhB2XaQVlmQbsTZsYvPX2VsdjauVfaQakTVqnjnw tyw== X-Google-Smtp-Source: AGHT+IFK32cTaqoqTJNazGtX5TzExs7AH57kjcR5A7Qc6S14R9Qqh2LtvZ+1ec7OP+laMIvBdbl42YkuaIU= X-Received: from pjf15.prod.google.com ([2002:a17:90b:3f0f:b0:2ea:aa56:49c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d450:b0:2ee:d024:e4fc with SMTP id 98e67ed59e1d1-2f2901b3661mr7398519a91.33.1734138445502; Fri, 13 Dec 2024 17:07:25 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:02 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-2-seanjc@google.com> Subject: [PATCH 01/20] KVM: selftests: Support multiple write retires in dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson From: Maxim Levitsky If dirty_log_test is run nested, it is possible for entries in the emulated PML log to appear before the actual memory write is committed to the RAM, due to the way KVM retries memory writes as a response to a MMU fault. In addition to that in some very rare cases retry can happen more than once, which will lead to the test failure because once the write is finally committed it may have a very outdated iteration value. Detect and avoid this case. Cc: Peter Xu Signed-off-by: Maxim Levitsky Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 52 +++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index aacf80f57439..cdae103314fc 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -152,6 +152,7 @@ static atomic_t vcpu_sync_stop_requested; * sem_vcpu_stop and before vcpu continues to run. */ static bool dirty_ring_vcpu_ring_full; + /* * This is only used for verifying the dirty pages. Dirty ring has a very * tricky case when the ring just got full, kvm will do userspace exit due to @@ -166,7 +167,51 @@ static bool dirty_ring_vcpu_ring_full; * dirty gfn we've collected, so that if a mismatch of data found later in the * verifying process, we let it pass. */ -static uint64_t dirty_ring_last_page; +static uint64_t dirty_ring_last_page = -1ULL; + +/* + * In addition to the above, it is possible (especially if this + * test is run nested) for the above scenario to repeat multiple times: + * + * The following can happen: + * + * - L1 vCPU: Memory write is logged to PML but not committed. + * + * - L1 test thread: Ignores the write because its last dirty ring entry + * Resets the dirty ring which: + * - Resets the A/D bits in EPT + * - Issues tlb flush (invept), which is intercepted by L0 + * + * - L0: frees the whole nested ept mmu root as the response to invept, + * and thus ensures that when memory write is retried, it will fault again + * + * - L1 vCPU: Same memory write is logged to the PML but not committed again. + * + * - L1 test thread: Ignores the write because its last dirty ring entry (again) + * Resets the dirty ring which: + * - Resets the A/D bits in EPT (again) + * - Issues tlb flush (again) which is intercepted by L0 + * + * ... + * + * N times + * + * - L1 vCPU: Memory write is logged in the PML and then committed. + * Lots of other memory writes are logged and committed. + * ... + * + * - L1 test thread: Sees the memory write along with other memory writes + * in the dirty ring, and since the write is usually not + * the last entry in the dirty-ring and has a very outdated + * iteration, the test fails. + * + * + * Note that this is only possible when the write was the last log entry + * write during iteration N-1, thus remember last iteration last log entry + * and also don't fail when it is reported in the next iteration, together with + * an outdated iteration count. + */ +static uint64_t dirty_ring_prev_iteration_last_page; enum log_mode_t { /* Only use KVM_GET_DIRTY_LOG for logging */ @@ -316,6 +361,8 @@ 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)) @@ -613,7 +660,8 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) */ min_iter = iteration - 1; continue; - } else if (page == dirty_ring_last_page) { + } else if (page == dirty_ring_last_page || + page == dirty_ring_prev_iteration_last_page) { /* * Please refer to comments in * dirty_ring_last_page. From patchwork Sat Dec 14 01:07:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908235 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 3BB0518622 for ; Sat, 14 Dec 2024 01:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138450; cv=none; b=iY+6a/esZKywHAahQ1739rRhEIUM84MOfMvMkeKCBqCD8shTEm74aJYyCziGKvP1iP2iBkkykgqvtZTMMXPnEdoL4OyNvj3FuRySz/Gzx3b8BnvNnRyeptLXYIF1RAIIDJ+7dGYpsMh9pCXb0ilA9DDhz8J9PlBQLqAvBBbfv7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138450; c=relaxed/simple; bh=IZGgI2DCqaJpVpnMfmrHDxlduEJifpBvSH6SMCXlxBM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FVD9zR6rT+OSLaIRlAV/C0DYBxf3cvgQCL9fUxKl/SF/+xgfvJvRBf/CNwmYYZSe4KWjAbCdV+vuqRhLBbM4cB/tDGH3c06Wrl5FqJOkgeJ1Hf5BcGu//P07rp5lPF3eZgqkK97b/mE9/v+wpsPvQsAduVDupCvG4LCXGpvdYhE= 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=rXAWyY8S; arc=none smtp.client-ip=209.85.214.201 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="rXAWyY8S" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-20d15285c87so27169495ad.3 for ; Fri, 13 Dec 2024 17:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138447; x=1734743247; 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=eu7VheiDTVKr2LqSu+n9QlVxflc27k4rZOjnfcC28j8=; b=rXAWyY8Sv0RCMfhCPz0UHONPsRI8+dz3TY3YzDcfICwkJdhamKOW7JAAVFvhE112Yi PiR8SZ43QDsYJj8VN3VK6+Q2JOqUJOcTiliEyUI5awEwok8/9U+VL+zfhdqvlQkbPM7S 5DY4Yj0oBVTL//7D9OGDFcL7yV5zUz8weOn/PnjCPjX/34UiiMNeeA1ajouVcBc/Lsru LlhUdMxwkqGSaQBc5AlNFhwC6DAg6ypWonAAztJkhschxDMG8/NJzMbh5nXBrJHWUPBR j6Ffhm4Vw+QS4vSrAQpDJ6J/zp+8zEhHH0sV+yEu3wqNFS46Ay25xVUy2+QT1wdyhKLS NDKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138447; x=1734743247; 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=eu7VheiDTVKr2LqSu+n9QlVxflc27k4rZOjnfcC28j8=; b=OCwhLgrf5tlgcgqVWPm1z2T6i/9rpyuplVKqMSlF8LGLKX6FoVWEcK5C6mAei7jBQs w86M5QAlq/6PKTy4HpSZkWZJotXCIWeVmavRB46nhqGxEcXbC2mil8l/xv6vhGddcAfX p9Bch4FHke/BLwBihAYRCpkZH3nVthKc40ZKQGURCcwMRJgWia+NFRKFr2G1GsBfnj0Z aRrCFbdqXy5VukijKFW8KY/ToqSqHdrhReYOFPTOw/fRnXtWhLbRYoY/jMM3uvdEi4UA jyWIbGl6sEUJ8NQSSVLZEBpadp2EKRpvjFQDk9Ys294nU3nKHuW9aO9DUDKAszdk/mPC /qmA== X-Gm-Message-State: AOJu0YztHZGBM9ENVaArCiWYEgun2srCBL0vH+1srt1O2sKkdGQ5fvwn SHHovLvk2PBE4CicC3U20ElxQT1Fkw7+fQymz68yhvhyVk/GepqfkayAO0mc91fn5X8bmDPrIT2 BRA== X-Google-Smtp-Source: AGHT+IHo1lFfCdYYSF7/JbyGHm3sFAr7BgyjSeNg7ivUxMiio3zLw8UbtxvqO5CTt5MTe7jJoiLSR2DQHRk= X-Received: from pjtd5.prod.google.com ([2002:a17:90b:45:b0:2ef:9b30:69d3]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f54d:b0:215:e98c:c5d9 with SMTP id d9443c01a7336-218929a21c6mr49455455ad.18.1734138447390; Fri, 13 Dec 2024 17:07:27 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:03 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-3-seanjc@google.com> Subject: [PATCH 02/20] KVM: selftests: Sync dirty_log_test iteration to guest *before* resuming From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Sync the new iteration to the guest prior to restarting the vCPU, otherwise it's possible for the vCPU to dirty memory for the next iteration using the current iteration's value. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index cdae103314fc..41c158cf5444 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -859,9 +859,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) */ if (++iteration == p->iterations) WRITE_ONCE(host_quit, true); - - sem_post(&sem_vcpu_cont); sync_global_to_guest(vm, iteration); + + sem_post(&sem_vcpu_cont); } pthread_join(vcpu_thread, NULL); From patchwork Sat Dec 14 01:07:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908236 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 B21621A260 for ; Sat, 14 Dec 2024 01:07:29 +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=1734138451; cv=none; b=kuy8NBrZEIp77EDL8taSFE4Ebef8APj9Rm9AFeZhp6dkGKMrXnY4w0ojVwmaoCh+WEU7nyF/5EbN68Qt+PLLlG0kLo7YpviybrZr22LQuIc6PPIkrUPoaxbDl3hozbXXtkwvr32JEmKpQTiScsod1MOb3LGc6NWPzHOucmk5WYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138451; c=relaxed/simple; bh=VpeIAx4HgBrBdjrulL38P4sjULv3zDVf3Ct1h85Wlb0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Mljiyo+8+YOGbbaWW1B0kqXwtM8c4OvSHkxClnJe/wT3VWdRye+d3RE3oPIIqzoYSdqITMoVTV3+7SrO6X4MtZKkvD622pCX97y1IoY99w36oupZucV09q/2HpN6XLzItntlfTrtyvlVL/7DrMnI7k4lfeebVOU3k2AtegwxLIg= 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=3NNu6Cc1; 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="3NNu6Cc1" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2efa0eb9cfeso1935219a91.0 for ; Fri, 13 Dec 2024 17:07:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138449; x=1734743249; 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=CWJNZezGcooW6XpZeQGEoIGegjFgZChrjwFhXc5Ge/w=; b=3NNu6Cc1s8H9q/JS2uTP25VecEuegE9TR0TPWaeNPAsRhuuaT2pKko9ZIqK8VnYL0U Ckwxj+lv59eLxq+5yKXSeUi1nA0dTAWcir/ZM8m3EfP3ZW1xq2jnI3O/3/RDXScCuV65 TV3N+2gB44fqbU/0+QcUVfgeAml6oS7n+SZeb37NBvXUKzX6j/4dTbDUcvToDCTUMSdO dBO5v8oVQdA2jQnOsuCWAynoIk2DfxEjPGg0mbbY+AVHqqe7wumrcBEfy3XHky/DNhE1 F2fwvVo5CpThl181z/k/1NIRjQP6TuESxzbz/2Cz42Nr2csdHPPW7guYf0lury6042L+ 6g6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138449; x=1734743249; 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=CWJNZezGcooW6XpZeQGEoIGegjFgZChrjwFhXc5Ge/w=; b=BgZ3KhAMjmIyk9e1FWAnzaT3D/7V8qRnrvmypJbIDxlsTmIBVvKPPyshcrj/oviXSD 4W3poag08QQr6YvbDhIgqWl4f8ZB1Gz7IZZwpEZjBUxZJ73SHiqPmpSSihlYnHfMK+/t sN71HetE79RuvRGMd+whqKn1Hoirnmk9iSPIflRH9EFclRBH+Zry7xxG3YFoNP2FQ6CA QMwWrJ+HjAYtHIldQo15w1f2xEn2B1O0cqc2EokDj3prW3LYy5gLx524YsyKwWncYT4H ca7zbEQ0NZuaAFeXUAFuHGwAOO3WgG5Zzwk5QYFmtcC0z+7sc5wZQeHs2EftpFdOh3CW kXnw== X-Gm-Message-State: AOJu0YyL8M930xM5+ReO+jln2J9W8iQeSjpw1g74eJHnRmSyDMgvohxe mKm9nR1jG8BkC7qrfGbJmVlPma2AOdi83vlmmOUcqNfXPVZjPGh7pHfChuK4nUJltrXII/JrWZN zKg== X-Google-Smtp-Source: AGHT+IEy2Sg+GijSqGqxRvlytRT21UvxmkoF/622NIZfTiAYN57h5uvq1E/T5Vrd05ut5ibH3MC26jcm9ag= X-Received: from pjbsr5.prod.google.com ([2002:a17:90b:4e85:b0:2ef:8ef8:2701]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d8c:b0:2ee:5a82:433a with SMTP id 98e67ed59e1d1-2f2919d7bffmr6717799a91.17.1734138449286; Fri, 13 Dec 2024 17:07:29 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:04 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-4-seanjc@google.com> Subject: [PATCH 03/20] KVM: selftests: Drop signal/kick from dirty ring testcase From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Drop the signal/kick from dirty_log_test's dirty ring handling, as kicking the vCPU adds marginal value, at the cost of adding significant complexity to the test. Asynchronously interrupting the vCPU isn't novel; unless the kernel is fully tickless, the vCPU will be interrupted by IRQs for any decently large interval. And exiting to userspace mode in the middle of a sequence isn't novel either, as the vCPU will do so every time the ring becomes full. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 106 +++---------------- 1 file changed, 15 insertions(+), 91 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 41c158cf5444..d9911e20337f 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -236,24 +236,6 @@ static enum log_mode_t host_log_mode; static pthread_t vcpu_thread; static uint32_t test_dirty_ring_count = TEST_DIRTY_RING_COUNT; -static void vcpu_kick(void) -{ - pthread_kill(vcpu_thread, SIG_IPI); -} - -/* - * In our test we do signal tricks, let's use a better version of - * sem_wait to avoid signal interrupts - */ -static void sem_wait_until(sem_t *sem) -{ - int ret; - - do - ret = sem_wait(sem); - while (ret == -1 && errno == EINTR); -} - static bool clear_log_supported(void) { return kvm_has_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); @@ -292,17 +274,14 @@ static void vcpu_handle_sync_stop(void) /* It means main thread is sleeping waiting */ atomic_set(&vcpu_sync_stop_requested, false); sem_post(&sem_vcpu_stop); - sem_wait_until(&sem_vcpu_cont); + sem_wait(&sem_vcpu_cont); } } -static void default_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) +static void default_after_vcpu_run(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; - TEST_ASSERT(ret == 0 || (ret == -1 && err == EINTR), - "vcpu run failed: errno=%d", err); - TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC, "Invalid guest sync status: exit_reason=%s", exit_reason_str(run->exit_reason)); @@ -371,7 +350,6 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns, "%u != %u", cur->slot, slot); TEST_ASSERT(cur->offset < num_pages, "Offset overflow: " "0x%llx >= 0x%x", cur->offset, num_pages); - //pr_info("fetch 0x%x page %llu\n", *fetch_index, cur->offset); __set_bit_le(cur->offset, bitmap); dirty_ring_last_page = cur->offset; dirty_gfn_set_collected(cur); @@ -382,13 +360,6 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns, return count; } -static void dirty_ring_wait_vcpu(void) -{ - /* This makes sure that hardware PML cache flushed */ - vcpu_kick(); - sem_wait_until(&sem_vcpu_stop); -} - static void dirty_ring_continue_vcpu(void) { pr_info("Notifying vcpu to continue\n"); @@ -400,18 +371,6 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, uint32_t *ring_buf_idx) { uint32_t count = 0, cleared; - bool continued_vcpu = false; - - dirty_ring_wait_vcpu(); - - if (!dirty_ring_vcpu_ring_full) { - /* - * This is not a ring-full event, it's safe to allow - * vcpu to continue - */ - dirty_ring_continue_vcpu(); - continued_vcpu = true; - } /* Only have one vcpu */ count = dirty_ring_collect_one(vcpu_map_dirty_ring(vcpu), @@ -427,16 +386,13 @@ 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 (!continued_vcpu) { - TEST_ASSERT(dirty_ring_vcpu_ring_full, - "Didn't continue vcpu even without ring full"); + if (READ_ONCE(dirty_ring_vcpu_ring_full)) dirty_ring_continue_vcpu(); - } pr_info("Iteration %ld collected %u pages\n", iteration, count); } -static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) +static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; @@ -444,17 +400,14 @@ static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) if (get_ucall(vcpu, NULL) == UCALL_SYNC) { /* We should allow this to continue */ ; - } else if (run->exit_reason == KVM_EXIT_DIRTY_RING_FULL || - (ret == -1 && err == EINTR)) { + } else if (run->exit_reason == KVM_EXIT_DIRTY_RING_FULL) { /* Update the flag first before pause */ - WRITE_ONCE(dirty_ring_vcpu_ring_full, - run->exit_reason == KVM_EXIT_DIRTY_RING_FULL); + WRITE_ONCE(dirty_ring_vcpu_ring_full, true); sem_post(&sem_vcpu_stop); - pr_info("vcpu stops because %s...\n", - dirty_ring_vcpu_ring_full ? - "dirty ring is full" : "vcpu is kicked out"); - sem_wait_until(&sem_vcpu_cont); + 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: " "exit_reason=%s", @@ -473,7 +426,7 @@ struct log_mode { void *bitmap, uint32_t num_pages, uint32_t *ring_buf_idx); /* Hook to call when after each vcpu run */ - void (*after_vcpu_run)(struct kvm_vcpu *vcpu, int ret, int err); + void (*after_vcpu_run)(struct kvm_vcpu *vcpu); } log_modes[LOG_MODE_NUM] = { { .name = "dirty-log", @@ -544,47 +497,24 @@ static void log_mode_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, mode->collect_dirty_pages(vcpu, slot, bitmap, num_pages, ring_buf_idx); } -static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) +static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu) { struct log_mode *mode = &log_modes[host_log_mode]; if (mode->after_vcpu_run) - mode->after_vcpu_run(vcpu, ret, err); + mode->after_vcpu_run(vcpu); } static void *vcpu_worker(void *data) { - int ret; struct kvm_vcpu *vcpu = data; uint64_t pages_count = 0; - struct kvm_signal_mask *sigmask = alloca(offsetof(struct kvm_signal_mask, sigset) - + sizeof(sigset_t)); - sigset_t *sigset = (sigset_t *) &sigmask->sigset; - - /* - * SIG_IPI is unblocked atomically while in KVM_RUN. It causes the - * ioctl to return with -EINTR, but it is still pending and we need - * to accept it with the sigwait. - */ - sigmask->len = 8; - pthread_sigmask(0, NULL, sigset); - sigdelset(sigset, SIG_IPI); - vcpu_ioctl(vcpu, KVM_SET_SIGNAL_MASK, sigmask); - - sigemptyset(sigset); - sigaddset(sigset, SIG_IPI); while (!READ_ONCE(host_quit)) { - /* Clear any existing kick signals */ pages_count += TEST_PAGES_PER_LOOP; /* Let the guest dirty the random pages */ - ret = __vcpu_run(vcpu); - if (ret == -1 && errno == EINTR) { - int sig = -1; - sigwait(sigset, &sig); - assert(sig == SIG_IPI); - } - log_mode_after_vcpu_run(vcpu, ret, errno); + vcpu_run(vcpu); + log_mode_after_vcpu_run(vcpu); } pr_info("Dirtied %"PRIu64" pages\n", pages_count); @@ -838,7 +768,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) * we need to stop vcpu when verify data. */ atomic_set(&vcpu_sync_stop_requested, true); - sem_wait_until(&sem_vcpu_stop); + sem_wait(&sem_vcpu_stop); /* * NOTE: for dirty ring, it's possible that we didn't stop at * GUEST_SYNC but instead we stopped because ring is full; @@ -905,7 +835,6 @@ int main(int argc, char *argv[]) .interval = TEST_HOST_LOOP_INTERVAL, }; int opt, i; - sigset_t sigset; sem_init(&sem_vcpu_stop, 0, 0); sem_init(&sem_vcpu_cont, 0, 0); @@ -964,11 +893,6 @@ int main(int argc, char *argv[]) srandom(time(0)); - /* Ensure that vCPU threads start with SIG_IPI blocked. */ - sigemptyset(&sigset); - sigaddset(&sigset, SIG_IPI); - pthread_sigmask(SIG_BLOCK, &sigset, NULL); - if (host_log_mode_option == LOG_MODE_ALL) { /* Run each log mode */ for (i = 0; i < LOG_MODE_NUM; i++) { From patchwork Sat Dec 14 01:07:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908237 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 BD1223CF58 for ; Sat, 14 Dec 2024 01:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138453; cv=none; b=kDkWxeubW+AOmIxTFr6qnjn7KPIfwK0jsxGwKAfs0lT2clSe7fVpF8XDuNlq/R2l8/l93lnZNhQRK/+NEUB2HVPKKkCa+1K+v56KKvEv5SYrFfK0fTMN2HJunKu1kLGJeQoG/NJpbqo4FOqKjUxXgCIB/A2DMu2XaIiVUk7/MXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138453; c=relaxed/simple; bh=40+uE3sPtrY0nnt1koHNIUnQu2u+jT00mNRygEsPKEo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WhYNhVxhxEISjBZh4iKsb5Bay03iihypc+rdjpo69nm8f/v2H6Kw7yR0rFyaD+rBBVQkQaClpMcqiVCqeIFmH8yIbx8XBzFGcKsJcnob4N6QZDHwI4mKFzO7+Z1Od7g6kWg3DDLW+58vP7lTkIzG4SqyLPxA3Y+/tQGv3RKbpeM= 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=xcdTdCHp; arc=none smtp.client-ip=209.85.215.202 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="xcdTdCHp" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7e9fb5352dfso2335524a12.3 for ; Fri, 13 Dec 2024 17:07:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138451; x=1734743251; 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=MI6Qma5wvtLLYEaqt0UatWEv3JJNRMjOF7eSoljdSCM=; b=xcdTdCHpyFZ7Vb4NDcq5rVIMnbFBAcjguVtPt0zgRpo5dzGiN6gNUeQKdzW534sdfW x2QYhW5hazgcpLB3KpcLpd5PPBhAeBtBdy9l1u84YYRkzXZYT8uYcRDM7jtdJIL8cjWU xunsfjb7C8CvUK6jc9as+yPtl9naj5IKmNrns9BkBxTLsanNTbePGUB1D1l9YUHOgu/C A4LvQYTyg+wwaMk3VvRYIXGD5+VIub95DCoCu3bR0nIjiqMf+LeWgy+XXCILqKkh7nwu z3PDUmtOqBqNiKKKJC0kFMPLiyn1065IzZg+fNSRs5mffCcKOsFnkmgLWhXlFUn/8piA FsXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138451; x=1734743251; 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=MI6Qma5wvtLLYEaqt0UatWEv3JJNRMjOF7eSoljdSCM=; b=uLBukMNwFCm2DkZLCL/hVy609bPeOFMrrdl0dTOoukMngvuBA8GJCFo61m6EQdkvol 7Rx43vVEyMmE5hUJ2WV1e4OTe2qAFI1rCoS0bkn/f5yR1rEL1EE4XpUcVRo3+FmQMnm5 JvcdBtcScEHK2EAVg3kbLMuWKH5vjEbUXKJVSeHAICYc8DAEyylIdPwjeZPit6CO0V68 z/l2uJp7CHGlXpF+9/y4aunAsSQkeNziWZ21QuF+DhNtcMaNls0XmHt86gCk1L175UeS zf1kpmYtSfiDKtSa69qIId7SKP9svSzz5OFZLHNbVorkNY3Rac7fYSQWQ07DL9SWmla4 0SlQ== X-Gm-Message-State: AOJu0Yw6vg4TJlYxYplEDLHQojiPs/6WCfiIBCodFdVKyj8NWjBFrsgv eXdwUEIQ1ghZu3Rm5E2ruDtNdhF7VtNUEdDEoce1P1n9DbmtGJNhsNob1wg+twDjwlHi8r67RPL DMg== X-Google-Smtp-Source: AGHT+IEgTSVvvWEd78/T/3yZBa8sTV/azpOr4QdU93yuP7UZZJ/l4/0iwkxtnud9GUNGgYiWrbJ3HVCNU3U= X-Received: from pfcf8.prod.google.com ([2002:a05:6a00:2388:b0:726:d6e6:a38]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:734b:b0:1e1:bef7:af57 with SMTP id adf61e73a8af0-1e1dfd70b1cmr7762017637.21.1734138451136; Fri, 13 Dec 2024 17:07:31 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:05 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-5-seanjc@google.com> Subject: [PATCH 04/20] KVM: selftests: Drop stale srandom() initialization from dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Drop an srandom() initialization that was leftover from the conversion to use selftests' guest_random_xxx() APIs. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index d9911e20337f..55a744373c80 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -891,8 +891,6 @@ int main(int argc, char *argv[]) pr_info("Test iterations: %"PRIu64", interval: %"PRIu64" (ms)\n", p.iterations, p.interval); - srandom(time(0)); - if (host_log_mode_option == LOG_MODE_ALL) { /* Run each log mode */ for (i = 0; i < LOG_MODE_NUM; i++) { From patchwork Sat Dec 14 01:07:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908238 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 7CCB880BEC for ; Sat, 14 Dec 2024 01:07: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=1734138454; cv=none; b=qU/2CdI1JbhdhMA8LPFfE+i5N7+8ltiQrlzRAm/ecr0qoP+OqKnQL7k9KUyP5EWO4NLC/OlJFD0T0laeFatw22NSc+vgzThTPZRKcmUwLfJ/HAeghH3J+qz/CsEqZAmw7kzndCQ4AyO2R3BipeGarAVpAYMhfgBimoKwQC4yxRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138454; c=relaxed/simple; bh=4pS0dReh/up25k1SmFevQedfviIhDfa09ijAKDGjf8s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EBIG1JkpNbKg8cFnGloxDj9qppdLRqpEP3KeSBf/7RZASWsUPIgUPKdssdBdFGDV6fiAA8KXtrKZIg8gD2H9Nms/6hkT29qgp9Z3GDYOHM5ZW62DcU4HbglotsMye0Sm5L5cizaLruE0BCtuv4+aXl01op8V0qgQVwC6Ev2MrK4= 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=s5Fbfe8+; 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="s5Fbfe8+" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9dbeb848so2112983a91.0 for ; Fri, 13 Dec 2024 17:07:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138453; x=1734743253; 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=9KFGe38o+KQQhYANMpHrh9BBXbfP6MTs5wlchBkgdrs=; b=s5Fbfe8+X01LYdENhRRVQVArOK2pyVlokD/1E96t6+9jDCQ2jY4kSemoZuk9J+L/aX eroYUNJeMhCDYsRAytFauu9RherPOcz+x3siQqSb4+uYN3u+KE4bbEX9tLS3iXfJVh7r rczmxISzu6flrPF94+XqAwThhIp5t/Lbdwwz3wNZiOeLHFtU50HLeS03k8mWjOfrLfSY LDX5lJI+g/l0nks+V0i/G1YOLoIm6ZuVUJ5jUA1ieODxKccifqYPWHqJpISAKK53ozeq Ojoxu0oaUCnfigPymylzlhHnA7LrIaTRV25hiXvsRd14AMldLrhSFmSrFc4K3OBuq47W nqoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138453; x=1734743253; 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=9KFGe38o+KQQhYANMpHrh9BBXbfP6MTs5wlchBkgdrs=; b=cCYyxe5GGhtSCV71TJatQ13uBmoRJaQiNJORQgoIlgRbeq2fC6i5rC1VwELNxIkVxx fKZP9C0gsQKAj/iHpTrR77jUrv6Zbdk24sW89pkyfXfPB73DGKTdQQbzA2fQw+gmZW+F VyYxDxyU0en+uFXXVHTq3MpNJFFyiLo11pKBiDhSxtlE7In2E+Y5f6aoBTMIEvrKm3Bq ly7ljwuOHVNkWWT5L0kVIwYBEJLCgrn9msBI8v1he/P9hrzB6wICHzN0PU7NrmByMlQ0 FHvgnR11sVZjr3v/5r/8HEBGmT4o6cuRKJFb2GE8J5A8PkP7E6aib8xQBL0YJz0UmFJX vdXQ== X-Gm-Message-State: AOJu0Yz7BiSoF0JGgkgM4dI/QrFfioREuhmAs+SfotQdLbuXBDprxgq5 6s1yuIG2Jre40Jvj6pNq53ocgk6aMq5wHDa6dYAvTZmSbuXaG1tsz1Cg3xcLQHQDIIhNca50YtK vhA== X-Google-Smtp-Source: AGHT+IFLzgs5F8QCfrknTflXosKen4RqTbGemD8kyxhrrln2JSECS9E0IPHmRH8Lkh7TOiPqadAmPbZYuqc= X-Received: from pjh7.prod.google.com ([2002:a17:90b:3f87:b0:2ef:a732:f48d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d450:b0:2ee:599e:f411 with SMTP id 98e67ed59e1d1-2f2901b0befmr6154981a91.34.1734138452942; Fri, 13 Dec 2024 17:07:32 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:06 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-6-seanjc@google.com> Subject: [PATCH 05/20] KVM: selftests: Precisely track number of dirty/clear pages for each iteration From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Track and print the number of dirty and clear pages for each iteration. This provides parity between all log modes, and will allow collecting the dirty ring multiple times per iteration without spamming the console. Opportunistically drop the "Dirtied N pages" print, which is redundant and wrong. For the dirty ring testcase, the vCPU isn't guaranteed to complete a loop. And when the vCPU does complete a loot, there are no guarantees that it has *dirtied* that many pages; because the writes are to random address, the vCPU may have written the same page over and over, i.e. only dirtied one page. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 55a744373c80..08cbecd1a135 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -388,8 +388,6 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, if (READ_ONCE(dirty_ring_vcpu_ring_full)) dirty_ring_continue_vcpu(); - - pr_info("Iteration %ld collected %u pages\n", iteration, count); } static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) @@ -508,24 +506,20 @@ static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu) static void *vcpu_worker(void *data) { struct kvm_vcpu *vcpu = data; - uint64_t pages_count = 0; while (!READ_ONCE(host_quit)) { - pages_count += TEST_PAGES_PER_LOOP; /* Let the guest dirty the random pages */ vcpu_run(vcpu); log_mode_after_vcpu_run(vcpu); } - pr_info("Dirtied %"PRIu64" pages\n", pages_count); - return NULL; } static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) { + uint64_t page, nr_dirty_pages = 0, nr_clean_pages = 0; uint64_t step = vm_num_host_pages(mode, 1); - uint64_t page; uint64_t *value_ptr; uint64_t min_iter = 0; @@ -544,7 +538,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) if (__test_and_clear_bit_le(page, bmap)) { bool matched; - host_dirty_count++; + nr_dirty_pages++; /* * If the bit is set, the value written onto @@ -605,7 +599,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) " incorrect (iteration=%"PRIu64")", page, *value_ptr, iteration); } else { - host_clear_count++; + nr_clean_pages++; /* * If cleared, the value written can be any * value smaller or equals to the iteration @@ -639,6 +633,12 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) } } } + + pr_info("Iteration %2ld: dirty: %-6lu clean: %-6lu\n", + iteration, nr_dirty_pages, nr_clean_pages); + + host_dirty_count += nr_dirty_pages; + host_clear_count += nr_clean_pages; } static struct kvm_vm *create_vm(enum vm_guest_mode mode, struct kvm_vcpu **vcpu, From patchwork Sat Dec 14 01:07:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908239 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 4E37B1422AB for ; Sat, 14 Dec 2024 01:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138456; cv=none; b=r/phwRRGKNqpzYwh8JIqVcGjhFltZIp0+qcf70uSP17mcrdmt7px+6Vr7d4EbQ8Do2wlRoV8LbIdE3KBEK2M0ANGZcqiA4uYw+CvQo+l4rkQHUZkJqTAnbZhcG3Tdsv0bi+WqPMt09xyy1ZeN1a28OiUW87uNblCD7v+gWWbS7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138456; c=relaxed/simple; bh=ChtkTwOdtM2CUHYRr5Q44jb7j5O7SxNDxq57Jgyawzk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=n840d4vseCxtH3r/SIWpjeObCNQaNio/l0Hii4CyisCwdbz5hTPZVINrpXpMQr7we//aP4PbzrS8VSL/G9+MeWS1QD6PUqUdgWBFR2+8GseG3i6Ve2bE9QAp+9Bwd/BWAoFfGznbD+P5jxoajzgCr4VntuFoBPf26cEpF622sRI= 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=V2SqFCBt; arc=none smtp.client-ip=209.85.210.202 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="V2SqFCBt" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-728e3ae8112so1833250b3a.0 for ; Fri, 13 Dec 2024 17:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138455; x=1734743255; 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=S4Qc03cR1N5CABN65ZcLjYJSL9LWVrIe/DGU28OwxCc=; b=V2SqFCBtzIxBdTqHO8ImQFRE5+NsddNwO2H2wfS1CjEGjwL01pILZi7MRwO2o1c3Bl Ydr0m2GKyoaRNe6IHwGKBFG52FTkB+ZEgSb41jv4NCgoStPZ3tFe/noMiM4Dr8YLWZyH /h5wvlMe/MIDncF7BNdsuIvsX3Gu699Ow3OCd5Aj/UeFRdgrNWQMjVXBKUmwFEMj2mKG OmpyCq92X3ZMYDMrYkryH0M4crk6pI7uqkGOf7NpplfONKoqBfbYmeIH/yGc8I8CumOL Jv1OYGHhjh2M9EQYohESuQ+Sgcj6iHJm1ynQbsXINd8cpE9l6owi+2w6HNB3B3SewsCg fzZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138455; x=1734743255; 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=S4Qc03cR1N5CABN65ZcLjYJSL9LWVrIe/DGU28OwxCc=; b=Dt9FigV/7hTqs22rXq/tSUWCh3ekRiC+k5O4x25M2gEJs91zgOuJRPdL54V6mtEWhh gtabetxbooajXg9SsZ4HYixcvfA99IUcOGVdzJ14hMsZRe0xMyfBqXuNxlhMOOGZrKIt nfHura5hOTjPiX4/KHSxfeCoOsqwnuM+DmIWOQQATnTROlXj4ZuQBEVT+lAESjJir2UH 3cFzX9ljCt/aXeCLeJLIE7FJAOe8MJ7ekhkg6gQpvIS+3uL1ROHclZfyJ7L9lmuEamRo WxIAC/LqQ0d2IMEx4KzD/x9LtH1furzxqKzltWL1MDVRQFYoj8gJo5ZY88c1a6n8Gy1d o+cA== X-Gm-Message-State: AOJu0YzNzicQLBQ1E49trum66yA9KEJ/0Zi5dFckKfJjQ1ulZkvrQAIq AR7/Ex9xCBmeIRoplGhYXM2pTAHhQ8MgIwuCvH/83wlXQOej1/J/ry2BiWVBvduFMkOxlsCmSMc rzw== X-Google-Smtp-Source: AGHT+IG76QYly7Ply8m0CQfOF1OiirHYULNiCeYsTc6x5fGj00WXQFhcZFDKzqpfuelhdSo8iO789Lb6YjM= X-Received: from pffk21.prod.google.com ([2002:aa7:88d5:0:b0:725:f376:f548]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:430f:b0:724:f8d4:2b6e with SMTP id d2e1a72fcca58-7290c0fcdadmr6078557b3a.4.1734138454729; Fri, 13 Dec 2024 17:07:34 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:07 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-7-seanjc@google.com> Subject: [PATCH 06/20] KVM: selftests: Read per-page value into local var when verifying dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Cache the page's value during verification in a local variable, re-reading from the pointer is ugly and error prone, e.g. allows for bugs like checking the pointer itself instead of the value. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 08cbecd1a135..5a04a7bd73e0 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -520,11 +520,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) { uint64_t page, nr_dirty_pages = 0, nr_clean_pages = 0; uint64_t step = vm_num_host_pages(mode, 1); - uint64_t *value_ptr; uint64_t min_iter = 0; for (page = 0; page < host_num_pages; page += step) { - value_ptr = host_test_mem + page * host_page_size; + uint64_t val = *(uint64_t *)(host_test_mem + page * host_page_size); /* If this is a special page that we were tracking... */ if (__test_and_clear_bit_le(page, host_bmap_track)) { @@ -545,11 +544,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) * the corresponding page should be either the * previous iteration number or the current one. */ - matched = (*value_ptr == iteration || - *value_ptr == iteration - 1); + matched = (val == iteration || val == iteration - 1); if (host_log_mode == LOG_MODE_DIRTY_RING && !matched) { - if (*value_ptr == iteration - 2 && min_iter <= iteration - 2) { + if (val == iteration - 2 && min_iter <= iteration - 2) { /* * Short answer: this case is special * only for dirty ring test where the @@ -597,7 +595,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) TEST_ASSERT(matched, "Set page %"PRIu64" value %"PRIu64 " incorrect (iteration=%"PRIu64")", - page, *value_ptr, iteration); + page, val, iteration); } else { nr_clean_pages++; /* @@ -619,11 +617,11 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) * we'll see that page P is cleared, with * value "iteration-1". */ - TEST_ASSERT(*value_ptr <= iteration, + TEST_ASSERT(val <= iteration, "Clear page %"PRIu64" value %"PRIu64 " incorrect (iteration=%"PRIu64")", - page, *value_ptr, iteration); - if (*value_ptr == iteration) { + page, val, iteration); + if (val == iteration) { /* * This page is _just_ modified; it * should report its dirtyness in the From patchwork Sat Dec 14 01:07:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908240 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 5EA95169397 for ; Sat, 14 Dec 2024 01:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138458; cv=none; b=sAHqZLNVzNadbtYRosbfbgmYVkTiSQ9vHBvBEaGIX4F2MSka7EWRLOi/ZeQqSR25J9o5HZLGJ4n7YMYCPPH+xNYWzVr+0jUI6ZshO10kePzzYsGAZVrHJgT74pVtjjp13tfz43hWm1vZKoRoc5jhb1c154kSUYdjMHrf+vtQt24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138458; c=relaxed/simple; bh=ZXFEpYMLr4IBsF5/Te2IiwI3CIA8N20TTqGyTm77KTs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fsqoNlQLhX/AHsCF+EdyY0wKvSVqeQCiePEn5oKNZirLgmKEZqsA/IRQ/G+9uZqO4tNKx++rO6X2+Y0Qh5fCNYLDXQmvxiJ+5wHTtStqGKOyq7anR14CPi3xrzHSeUAREI7iVs8kRF/MnvweC9h4XGhc2WuYDmcP2HREEkOmUok= 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=OihDxFjC; arc=none smtp.client-ip=209.85.215.202 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="OihDxFjC" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7f712829f05so1527138a12.0 for ; Fri, 13 Dec 2024 17:07:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138456; x=1734743256; 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=opd7yOFDvSrhfHppvwX3Nzd5Pe0NZ+57ED0TYTOUSNg=; b=OihDxFjCP9fgv1g+wBnU3wZ1te0uVrFiVMLrlQzbiy8X5bvLVm/xRtzojw5voMImXN g7xre5s4BAKNPKwgKBhJd9XEAHjFQWgXLh8qOOk8jNrQe4stfI+Fg1+wvlFD3XPZq4Vf /vWom3F91ULJ8F2ytbkjcdm/prJ7i6dXt16580y1vwLc7oZfgdNrltVnhl7v0U3JTg6Z LeU/Lgd3FKyfvcbDoUTXrRsxlGthvvKCN0DNAC/n/Zgko2Qll9nt0PX/Cv9jePHh06I7 0WgkpAH3Pg/M/7VXmbConhCQA3u3TFw3mnltknnOWMWqsJzk88u7twUDD7I3xDPT/kSu l9vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138456; x=1734743256; 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=opd7yOFDvSrhfHppvwX3Nzd5Pe0NZ+57ED0TYTOUSNg=; b=pGL+pGD7GtXRMbD0TvW37ZxlQFddL/PsjFMrs8/7ccnx3Vcg8kJ4p4CmI6Soiyp1Hs mB5B/GO0AdkOHC1jN4bMekYTtr7VKRNR+Cyf5NPMKVuoVqN08oNJZQiPnAITTkjZOcq1 ft8aZhsZWCBmUz7+8C5W3Lf59Ez4kgktLvLUT9N0Yyv7M5qGWF8gHi1WZcHvDYdhbut6 o8igG4E/Y6HcV4f75Q2D+bWU9IqFe6MNDUtXGBnbp8CIgnlK2UhpISIjb1P2W5WAR8UK ki78JiARGbeOJvrjIgKZKIPpmzZlsr6xZ65XYLppxuoHpSE/igYLWFwiCPskBm7K4xg7 HMKQ== X-Gm-Message-State: AOJu0YyCkmNcE1kbDCDsFgzPb5kAxlrIOBzg0FqGOGtXVcAZfQtb+S3S NJp7Gnp5rsBiYwgaUTjPGWJZj0q8bIABvPxtf7BsWUM56eFrFj3Q8NMv+EJlusjZb/wS+jq1XC1 kKA== X-Google-Smtp-Source: AGHT+IHJnU2Z0jejJt0UsQNSm1boPEU7u8IfB6VxZK1FebykXxv6VAPXu+SYcUA64noqLsO90ouhS+F2fsc= X-Received: from pjtu8.prod.google.com ([2002:a17:90a:c888:b0:2d3:d4ca:5fb0]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:944:b0:215:65f3:27f2 with SMTP id d9443c01a7336-21892999322mr82028905ad.8.1734138456660; Fri, 13 Dec 2024 17:07:36 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:08 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-8-seanjc@google.com> Subject: [PATCH 07/20] KVM: selftests: Continuously reap dirty ring while vCPU is running From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson 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 Reviewed-by: Maxim Levitsky --- 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 From patchwork Sat Dec 14 01:07:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908241 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 BCB9E17C7B1 for ; Sat, 14 Dec 2024 01:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138460; cv=none; b=bYQ1oSt+5EyXz/cAkqytFtqGlvcKQ71OJ45hwboqZ3TXB3y5imJmT+sTwFCtY9gJ55pZjP9w8PBwX/eFjUgfENnRMdlwvMHBBZ/8bd8cfrtyVsYsoGs2NGOuy1KEjwPvnfZmHne2pEiyfNQxAPceSLUlBzrnB7W+vhvsNO6Caa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138460; c=relaxed/simple; bh=Inh2cv3fTNpaNX1dqJtMDaDtbEiwB1dIP0CX7Q96HQM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Y177CO5c9JPyBwClor7tM2HV/kfkd/1UrVN5N4hbVxRuTolwt7UnLq7kllNQJUOuBRn7w0qlKS6c4B+tpDCmYE9oDpq+JkF+viuczrcEn2AgIKP7wCUvDWNzEqNRhQNB43U7vJ0g35UkBXmqGWo/K+NTg2Mm0PDnbdwhnzcZ3lE= 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=4qfWwg0N; arc=none smtp.client-ip=209.85.210.202 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="4qfWwg0N" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725e3c6ad0dso3128921b3a.0 for ; Fri, 13 Dec 2024 17:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138458; x=1734743258; 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=m1k/pYfn2qosYE12LM1QCowrsBblB7GzrYsx0S4ECrU=; b=4qfWwg0NyRqdpgh/GGpMRn06nadjeILEuy8PEbsD6X8uP9YMVDxz8mDryUeCIfl7oV FFB317e7iY9T1a+TgoZc0E08jZQHj5xfFWDtN0qtwAFAksdU/cFCH66vYR+xL820QO7E H+7fn4fHJLFpJNs40x7azr90Gy6K5Y4a8OEl2eti9sdrdnR5MkKTze+6EQQaxZHiEwDf j4BqD5r+tdpcsvYOHMtzdCSf+QEsOhfexBou8H65fkLkAm2B+wcQsj+OeUhksoCdsRfy Q/rpqiDnekNYDM2RB/vv5OGVOZBLLng900FsWvNvl357WwUyfAM9AlBd+EDtGVyButas 2iWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138458; x=1734743258; 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=m1k/pYfn2qosYE12LM1QCowrsBblB7GzrYsx0S4ECrU=; b=JbE7FDAdw8l55RYexZiqqxOYAAeF/rlxUjQrN4Iv4tx9+bFNJU0SKl2uFyNNAJmvCA q12K450w7GCPcd9gtKvjrwjAUBIowZAgiI5ToKw1orgkBhi72DEiHqLGCipcvPDPItFj q1cfqKjxJa5dAsirzrmB6iVgMqF7bXJgJESUYICQlJAJnhCEvt8gBwjyVg1w77qmcJRF P3UrAVbJY0H8xpSke8kyHM9lN5JiEqdOm99JKYwX9EWtCultHX3bNnp2CKCthMJGf4X4 cS7oUCydmmdtwVOfJEQ6y6yPIxKBaLC2MrzdSfwo4JBzAzFXF+yrf9SBbW1xPtDNGa8i fcmw== X-Gm-Message-State: AOJu0Yxj8VUhaD0OCMxfjl5PjbdPbHHU76BLxjiRZLdGD8sLZkFbRN0J MPc+0wyWBo0DfeDE8fRJM1arVzvGdqOWyHAHrP20h4cpRjP122DVGyI/wKbyret/h7uZ7P7CDT6 aaQ== X-Google-Smtp-Source: AGHT+IEwXyFPF5Hijf5EmkYKER23oPL4AIpsifDIk3rn9u8VryCKpp9q2+rsJUb/wfR1Com5bqjGGaRhg1Y= X-Received: from pfbbs2.prod.google.com ([2002:a05:6a00:4442:b0:725:e2fd:dcf9]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:cd5:b0:725:9dc7:4f8b with SMTP id d2e1a72fcca58-7290c1902fbmr5987759b3a.15.1734138458154; Fri, 13 Dec 2024 17:07:38 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:09 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-9-seanjc@google.com> Subject: [PATCH 08/20] KVM: selftests: Limit dirty_log_test's s390x workaround to s390x From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson From: Maxim Levitsky s390 specific workaround causes the dirty-log mode of the test to dirty all guest memory on the first iteration, which is very slow when the test is run in a nested VM. Limit this workaround to s390x. Signed-off-by: Maxim Levitsky Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 2aee047b8b1c..55a385499434 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -98,6 +98,7 @@ static void guest_code(void) uint64_t addr; int i; +#ifdef __s390x__ /* * On s390x, all pages of a 1M segment are initially marked as dirty * when a page of the segment is written to for the very first time. @@ -108,6 +109,7 @@ static void guest_code(void) addr = guest_test_virt_mem + i * guest_page_size; vcpu_arch_put_guest(*(uint64_t *)addr, READ_ONCE(iteration)); } +#endif while (true) { for (i = 0; i < TEST_PAGES_PER_LOOP; i++) { From patchwork Sat Dec 14 01:07:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908242 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 5DE23189B8B for ; Sat, 14 Dec 2024 01:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138461; cv=none; b=sgKgGLbDDt6hkSGmAOmkxAUjnyi4fOku0+aMzuaLs+zM52yL0FiVpQWifLdvT4r758fuaaMdJ/6vALxTZnNCQo8mSSLTUDdpzvhinczM13S52Esco1JLKgUKzKsyZxz3l4DowqCyB1m1UVU8VB/7gZZRv/6pQ4e9ZPdxKzDtat8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138461; c=relaxed/simple; bh=OgTTk595VIyjaFheqBqRfYqIoPT5CZ9K1t127fuPGa4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b4DY+rqsYLff6S56QIzFbs3QhXVd/MgFoX9v8zjrQ5B+vcuUPIeyBd3e1UXdehvj6T77GDfFhA/awQJNa7mY+I5DKa8mjVCLcEM1QI576oXA1wFalSOzK4DnEtb6YoYGdmggBtZcddiTA+srZYU815rLFxaJ3TcGzJJhzbIDgsE= 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=Kj/Z0Pmz; arc=none smtp.client-ip=209.85.214.201 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="Kj/Z0Pmz" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2162f80040aso20220595ad.1 for ; Fri, 13 Dec 2024 17:07:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138460; x=1734743260; 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=FAzPo3qg+GcWGQlv0+FYKxHsP1523EqIgag6kKt+kTY=; b=Kj/Z0PmzldV5EsrSdmlgEl3jWCkgez3RBbLXjpSLtjzXHU11QUAQbPcFW+o4RA4JGu BopPNu7GSdoSCPgJkOVL3WkKZLUWrjo5WH9P2Dnh6vtWmW7ZhYonpCMUcMEkwEBi8rEa 4Plr2MVpg9q3hWEhCbw7PZQZkc0q2vX21/omy+f7sO3KFbd3PZ04jpnpHKVJm9Hevymu QsgY7bRrb8nCrv/Q6xBc1+w0+2VkzHzZsDRzXh4CUUSzkDQu+hN8aBgMFbjRTIZcXSJG r0srUFcYfQQcYsifZz0RWCytyMW19mF8QTsiF3EG45Craq3yCQ2hh9WBI7rWMzwItHlD 2Ztg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138460; x=1734743260; 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=FAzPo3qg+GcWGQlv0+FYKxHsP1523EqIgag6kKt+kTY=; b=WRivsoO1aEiv3umme6IKueGetSCqGRgwZaGXcHK3PwLzjyRHjecI3F2Ig6wKduD5Sv Z/mBEbZg67w55CNUIgY3FaD8Oi/J/rTDxYiUUc2aVqRMiWzJjqPMuzGVOWq4yHgzMehY YmQfw/FLjrzI5sQ/S/M3KKY5yLMg748nAJLM/0tu5MqCGYzti4BZ2ksnn1WBlg2Oxnnu 42PG/N0uUaSDSHhPW1O5SCUE3z1qrEbva3bnuNX5CQ0alfZRCVf6iHPqwBdVu/vd+A63 rvO0UINoiy8mJ3xUOKqJ/J1e771bPspEfo24sGrcFESiW1OJtlsNPCiHw0mh1U0RM48R uCrA== X-Gm-Message-State: AOJu0YzmA70z6SE4d/FjSF+XZgGSh+FOQe9mNcussp7Xq7GNi5jXTTWb hlwQ/H/KvT+XC/5g1vfWoefe0Bv5UOF3zc15q8UYEICm8b8Q6ZhsJsdp3OLZyiNi3Iihti6+BhB sYg== X-Google-Smtp-Source: AGHT+IEx6xV8z10SAfTW31+ni8NBIZeIzTyZ6UR4kfmgK36HNJYqi0QxFoc4iypAwYbfX3m4FftoXPhh3r8= X-Received: from pjbqo12.prod.google.com ([2002:a17:90b:3dcc:b0:2ee:4b69:50e1]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ef49:b0:20c:9821:69af with SMTP id d9443c01a7336-21892a40599mr66605485ad.45.1734138459850; Fri, 13 Dec 2024 17:07:39 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:10 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-10-seanjc@google.com> Subject: [PATCH 09/20] KVM: selftests: Honor "stop" request in dirty ring test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Now that the vCPU doesn't dirty every page on the first iteration for architectures that support the dirty ring, honor vcpu_stop in the dirty ring's vCPU worker, i.e. stop when the main thread says "stop". This will allow plumbing vcpu_stop into the guest so that the vCPU doesn't need to periodically exit to userspace just to see if it should stop. Add a comment explaining that marking all pages as dirty is problematic for the dirty ring, as it results in the guest getting stuck on "ring full". This could be addressed by adding a GUEST_SYNC() in that initial loop, but it's not clear how that would interact with s390's behavior. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 55a385499434..8d31e275a23d 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -387,8 +387,7 @@ static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) /* A ucall-sync or ring-full event is allowed */ if (get_ucall(vcpu, NULL) == UCALL_SYNC) { - /* We should allow this to continue */ - ; + vcpu_handle_sync_stop(); } else if (run->exit_reason == KVM_EXIT_DIRTY_RING_FULL) { /* Update the flag first before pause */ WRITE_ONCE(dirty_ring_vcpu_ring_full, true); @@ -697,6 +696,15 @@ static void run_test(enum vm_guest_mode mode, void *arg) #ifdef __s390x__ /* Align to 1M (segment size) */ guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20); + + /* + * The workaround in guest_code() to write all pages prior to the first + * iteration isn't compatible with the dirty ring, as the dirty ring + * support relies on the vCPU to actually stop when vcpu_stop is set so + * that the vCPU doesn't hang waiting for the dirty ring to be emptied. + */ + TEST_ASSERT(host_log_mode != LOG_MODE_DIRTY_RING, + "Test needs to be updated to support s390 dirty ring"); #endif pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem); From patchwork Sat Dec 14 01:07:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908243 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 40F5718FC79 for ; Sat, 14 Dec 2024 01:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138463; cv=none; b=fDSqjGaOq5p4iI4oUVyRBQuc4xn9rptHa9AiPrL8HEGbAsYaJHAxI4BlmRYCqghFufCIm5MUES1r/JfiB1wZJYC9csjPWdt2CqZuPUXlwwZDrwCk1N80KZsLDSA27TZV1QonAmc+AbsuVCGbUFd19FZUbluyeRUk7HKdJ/5KyR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138463; c=relaxed/simple; bh=ddHNUXZbIAzXk6KHAJvbKhibmhSrWuehmK8bBf359Vg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oPvsjKfsVMH8L+RIDt3ZFC35EM5bKEv4DEn3sedPeV8sZlWwvSYrmaZUW1pzwi4/lS4kFp+jynr5f+laL0X4RRD7r/I7zO2SlXoxAK9cdYAuCS39EplDR2MM51ni3LvL15BdHxytv2eYMCbghHkTpY4pklFZ8KQasTZ32Yh2drs= 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=skf3jYEx; arc=none smtp.client-ip=209.85.215.201 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="skf3jYEx" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-8019f05c61aso1565213a12.3 for ; Fri, 13 Dec 2024 17:07:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138461; x=1734743261; 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=gikAV9mXGZZ8J4IjiEskNOiSEWIeGcim2h3UhPVuaNA=; b=skf3jYEx4mZtUUlGxcU23oH9puFDyLQmijhF1Bq3NsNv9MBnRXrOLzGkwylP2b0Ga5 TRmS0zr1dMXI0ZyFKKe+Fg0UO/zn3nKNscSTTrdPuQEGWHiosZiOCMz+roiogOndXqT4 bdZW3+opHyghacYszdjwQ+ROYD93Iaf1/IDUzqmoEImrPBvh/EfuAOx5E8e5/yvzGKU8 XW6wZrnMA+F8LXXHEVQ26St9eyNmx3M0jOUJDHf85ADzPGBoi0av5k828iedV1SSIcs7 IKnLtMjM3vjeBJp6kbIHNt86zaUuFurJ6eopUMSk2zylaE8Na5zPRWTQe/Z3Bya0L39C DmIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138461; x=1734743261; 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=gikAV9mXGZZ8J4IjiEskNOiSEWIeGcim2h3UhPVuaNA=; b=VQmV6TBKw3BgjmtPjuDmuaNmmLdP7JZmBSHjJ7Sbez8zrsqtfveJXEvPrciA+38akZ fVotSjbLLZFvTsOcRCefO5vHN++m3ivU18SLlB97Jl8OOFYyCzY3akqPZZ/hlYy5qZg7 9ZRxWmIgTj6w95nt6vA8Mx0k5QMvN3Qv2jc84v2NBdeOcLSj3AEMYIN6xxl+G+WUT2CJ q8XtY5nTsJeP0I0eMrfWHfZATm7DBNh2LDbjOicOqhQvsET7ictDc6kIHMQTBe6CMXqY PcgAiT9f6OXmuNtuuPG16YNLo7wZu3dwturkYmLzZokwTu+3BFGv/UpYddzHxe2pdwjc 3Qpg== X-Gm-Message-State: AOJu0YzIfBji6SYhzyt7BfuxJOq+NMzr7oRkZRPA/Gka5YTkKFqpVr7I y0daP9g1+q8p0UempHzmIjHMhftwEab5onhZAnMAwSEJz3PB8E7GEtB9XWzRVOQjgWmEzKfLnCw N3A== X-Google-Smtp-Source: AGHT+IF3TqbeoScu7UoYVm9frXxX3k5VLFgkgBtc5cIYr2EdAAom1j5OMBSTm/VohiO94wCYgNv1x/5GDTA= X-Received: from pjbpq2.prod.google.com ([2002:a17:90b:3d82:b0:2ea:3a1b:f493]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:53d0:b0:2ea:a9ac:eee1 with SMTP id 98e67ed59e1d1-2f28fb5fd68mr7648207a91.10.1734138461665; Fri, 13 Dec 2024 17:07:41 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:11 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-11-seanjc@google.com> Subject: [PATCH 10/20] KVM: selftests: Keep dirty_log_test vCPU in guest until it needs to stop From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson In the dirty_log_test guest code, exit to userspace only when the vCPU is explicitly told to stop. Periodically exiting just to check if a flag has been set is unnecessary, weirdly complex, and wastes time handling exits that could be used to dirty memory. Opportunistically convert 'i' to a uint64_t to guard against the unlikely scenario that guest_num_pages exceeds the storage of an int. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 43 ++++++++++---------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 8d31e275a23d..40c8f5551c8e 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -31,9 +31,6 @@ /* Default guest test virtual memory offset */ #define DEFAULT_GUEST_TEST_MEM 0xc0000000 -/* How many pages to dirty for each guest loop */ -#define TEST_PAGES_PER_LOOP 1024 - /* How many host loops to run (one KVM_GET_DIRTY_LOG for each loop) */ #define TEST_HOST_LOOP_N 32UL @@ -75,6 +72,7 @@ static uint64_t host_page_size; static uint64_t guest_page_size; static uint64_t guest_num_pages; static uint64_t iteration; +static bool vcpu_stop; /* * Guest physical memory offset of the testing memory slot. @@ -96,9 +94,10 @@ static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM; static void guest_code(void) { uint64_t addr; - int i; #ifdef __s390x__ + uint64_t i; + /* * On s390x, all pages of a 1M segment are initially marked as dirty * when a page of the segment is written to for the very first time. @@ -112,7 +111,7 @@ static void guest_code(void) #endif while (true) { - for (i = 0; i < TEST_PAGES_PER_LOOP; i++) { + while (!READ_ONCE(vcpu_stop)) { addr = guest_test_virt_mem; addr += (guest_random_u64(&guest_rng) % guest_num_pages) * guest_page_size; @@ -140,14 +139,7 @@ static uint64_t host_track_next_count; /* Whether dirty ring reset is requested, or finished */ static sem_t sem_vcpu_stop; static sem_t sem_vcpu_cont; -/* - * This is only set by main thread, and only cleared by vcpu thread. It is - * used to request vcpu thread to stop at the next GUEST_SYNC, since GUEST_SYNC - * is the only place that we'll guarantee both "dirty bit" and "dirty data" - * will match. E.g., SIG_IPI won't guarantee that if the vcpu is interrupted - * after setting dirty bit but before the data is written. - */ -static atomic_t vcpu_sync_stop_requested; + /* * This is updated by the vcpu thread to tell the host whether it's a * ring-full event. It should only be read until a sem_wait() of @@ -272,9 +264,7 @@ static void clear_log_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, /* Should only be called after a GUEST_SYNC */ static void vcpu_handle_sync_stop(void) { - if (atomic_read(&vcpu_sync_stop_requested)) { - /* It means main thread is sleeping waiting */ - atomic_set(&vcpu_sync_stop_requested, false); + if (READ_ONCE(vcpu_stop)) { sem_post(&sem_vcpu_stop); sem_wait(&sem_vcpu_cont); } @@ -801,11 +791,24 @@ static void run_test(enum vm_guest_mode mode, void *arg) } /* - * See vcpu_sync_stop_requested definition for details on why - * we need to stop vcpu when verify data. + * Stop the vCPU prior to collecting and verifying the dirty + * log. If the vCPU is allowed to run during collection, then + * pages that are written during this iteration may be missed, + * i.e. collected in the next iteration. And if the vCPU is + * writing memory during verification, pages that this thread + * sees as clean may be written with this iteration's value. */ - atomic_set(&vcpu_sync_stop_requested, true); + WRITE_ONCE(vcpu_stop, true); + sync_global_to_guest(vm, vcpu_stop); sem_wait(&sem_vcpu_stop); + + /* + * Clear vcpu_stop after the vCPU thread has acknowledge the + * stop request and is waiting, i.e. is definitely not running! + */ + WRITE_ONCE(vcpu_stop, false); + sync_global_to_guest(vm, vcpu_stop); + /* * NOTE: for dirty ring, it's possible that we didn't stop at * GUEST_SYNC but instead we stopped because ring is full; @@ -813,8 +816,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) * the flush of the last page, and since we handle the last * page specially verification will succeed anyway. */ - assert(host_log_mode == LOG_MODE_DIRTY_RING || - atomic_read(&vcpu_sync_stop_requested) == false); vm_dirty_log_verify(mode, bmap); /* From patchwork Sat Dec 14 01:07:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908244 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 E6D011917E6 for ; Sat, 14 Dec 2024 01:07:43 +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=1734138465; cv=none; b=eCghWSZmUibEtVbQ+qI/UMUoHIl+lenFb0DwALbzr1M+uGlyI9LTsIHZ20EUWAYYJei5jDXJar+jSC6E33xBVrPaR+6kOjA/5iNokiUPZU/wjGMj5EQpDySWK9EpSdMIwffGH789LxNO2GIMzy5on0p9rJxA8fe0lduZ2TLHKnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138465; c=relaxed/simple; bh=3sfvgMqPiGr/4hRycKbPGFa+ObbRBz+P/dL5LYIATKQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T6tYKhuEHILpTl3wmifu4i3JBKuZXfAgw25svrlwMMSEE+FTqpv3D1uslK1BpQseFcVxV+yaRwlkVhkDRUiaJsLtlXONZ/9wJHXG4V1rdJr0CcmgQiplTrwihcDLTCeLpQGyQGy5gG+8oUb7cESikRD7yj5a2/OxpG2YkjsrHYc= 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=A8LbnI+x; 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="A8LbnI+x" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2eedd15c29eso2040806a91.3 for ; Fri, 13 Dec 2024 17:07:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138463; x=1734743263; 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=YB7ROV39Pzlxg3CsT+e1YkqRcv/fedX8ByOvnUPuqfA=; b=A8LbnI+xIsAvTqlyukc1yVRx4tejiaNyu/a4+/94cvGB9W252yqIkxT4rJCe1xG4ki z+1acdIjdnwxDjV5jkpD5HhB956dW/9rRqxrcDTrkUaE163xdvOEdIrrxg14GbkFBWT9 t2LYCyjCv3+cHyF3jbX5CDuYlBE1ZSwQe/ZdWhKhir5996+dNUbYLrW0DGJQb5mGui7J wGYFx5kYaNg/pdwyc+Bkfb/I3+00CLreDSD9dM5Kl4kGk19rXac6pBhxNPvCRHX4q69b HpPOTXYka95xQo8Wi9H+u4/mbJlnF6Sdej2UdIlrgkSuAURri4O1Is9f5Z8tS2GSwyjw EyBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138463; x=1734743263; 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=YB7ROV39Pzlxg3CsT+e1YkqRcv/fedX8ByOvnUPuqfA=; b=ZIzF9IiUcZVipNJJPIBLoJSthRYBA9uonADXF8wqbRbnK+l+n4c44ooMNmj9DCtlML YueuzGUYIErOysLOgd/WfKU7Xk8tLRKAE1nb/3wRGsmihmAllG48b2MW26c2Kh1WItkA ZSUXTPB34qX/38Sx5o/FxSWSgi8FbjFYJEih89l5v/G+KsQwfFJmdz9YvNg0CI4lUwT2 ZclvTwcKECMSHr55h1UEvT1ydWRhzIgY9M9oK4q1b0Vp1iAyoXWMMcqMpB3CGYdqWdGp KIA45kTeVm/BfHO56Pp1StsN0Fyns0GNeeCj2JUh0WCX1tDa8SXQNKKoLxBEiMsUyBeI r7bg== X-Gm-Message-State: AOJu0YxoYR7sGFVxTEa3a62AQKTP5M5s0J5PkPqDbfGxi3r0brTHNfAR iDY+boicy89G8oK+nCI67ZAUUshFMeXQ69FP1SS5LFSwPpWITEBSRnrb79+nzhJ8SrEz6TfWgZf Phw== X-Google-Smtp-Source: AGHT+IGLm+tWav0mdJroXvXIQGQc9a1oseLEfkqvEWloBr+EUUQt8A3f4c9LKw5WCptpE+rDX+y7oQPeGEI= X-Received: from pjuj8.prod.google.com ([2002:a17:90a:d008:b0:2e0:aba3:662a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4c8a:b0:2ee:8008:b583 with SMTP id 98e67ed59e1d1-2f28fb7216emr7811449a91.16.1734138463343; Fri, 13 Dec 2024 17:07:43 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:12 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-12-seanjc@google.com> Subject: [PATCH 11/20] KVM: selftests: Post to sem_vcpu_stop if and only if vcpu_stop is true From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson When running dirty_log_test using the dirty ring, post to sem_vcpu_stop only when the main thread has explicitly requested that the vCPU stop. Synchronizing the vCPU and main thread whenever the dirty ring happens to be full is unnecessary, as KVM's ABI is to actively prevent the vCPU from running until the ring is no longer full. I.e. attempting to run the vCPU will simply result in KVM_EXIT_DIRTY_RING_FULL without ever entering the guest. And if KVM doesn't exit, e.g. let's the vCPU dirty more pages, then that's a KVM bug worth finding. Posting to sem_vcpu_stop on ring full also makes it difficult to get the test logic right, e.g. it's easy to let the vCPU keep running when it shouldn't, as a ring full can essentially happen at any given time. Opportunistically rework the handling of dirty_ring_vcpu_ring_full to leave it set for the remainder of the iteration in order to simplify the surrounding logic. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 40c8f5551c8e..8544e8425f9c 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -379,12 +379,8 @@ static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu) if (get_ucall(vcpu, NULL) == UCALL_SYNC) { vcpu_handle_sync_stop(); } else if (run->exit_reason == KVM_EXIT_DIRTY_RING_FULL) { - /* Update the flag first before pause */ WRITE_ONCE(dirty_ring_vcpu_ring_full, true); - sem_post(&sem_vcpu_stop); - pr_info("Dirty ring full, waiting for it to be collected\n"); - sem_wait(&sem_vcpu_cont); - WRITE_ONCE(dirty_ring_vcpu_ring_full, false); + vcpu_handle_sync_stop(); } else { TEST_ASSERT(false, "Invalid guest sync status: " "exit_reason=%s", @@ -743,7 +739,6 @@ 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; @@ -775,19 +770,12 @@ 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 (READ_ONCE(dirty_ring_vcpu_ring_full)) - saw_dirty_ring_full = true; - if (i && !saw_dirty_ring_full) + if (i && !READ_ONCE(dirty_ring_vcpu_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); - } } /* @@ -829,6 +817,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) WRITE_ONCE(host_quit, true); sync_global_to_guest(vm, iteration); + WRITE_ONCE(dirty_ring_vcpu_ring_full, false); + sem_post(&sem_vcpu_cont); } From patchwork Sat Dec 14 01:07:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908245 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 A75B71922DC for ; Sat, 14 Dec 2024 01:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138467; cv=none; b=CSBmUJSSFE1Oskual1VtuxFEo2BKXmuiXS42l/SNAkfwe7u85AH/GULzxajwFa/o9e1fSGlcIuF87v2J/WTih0oSjEIEuirleS9l/hLOG+NgZXfndubJEmTw2d3aMu6s4+GvpROpUN+HmcJRl0DfBc3Eiu8WMUhpeFcxx9UEFMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138467; c=relaxed/simple; bh=QVWmEN93U4wXoW46HSHclbwWmnJqdA1R3pFC8wdRuNY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oH7x0BCSoij4ImKsnQkv+KdU6BD/T4j3rkfn+6tXNiA5i4ouVAw8z9OkijNtC4AaLUH/9UwREHCKMktsZ+RvB7n/YlKLdB5QRprfDvvLrDImoX8RFyyR2SSNptBbOIJOeewyTHkJxunTkpoTU8cy77NuupqjB24z+gXf2c8mhno= 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=huFZsV8i; arc=none smtp.client-ip=209.85.210.201 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="huFZsV8i" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-725e4bee252so1931133b3a.1 for ; Fri, 13 Dec 2024 17:07:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138465; x=1734743265; 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=bHCBDGsUVxz6SdxgZL4telXbGroEPmY7oNy/cAKGEh8=; b=huFZsV8ix67y/CtSdBH9UwyPXgzRjw9UA3PvnFvoXjHrzhuc8dFo4pgJIFpJ+jb1O1 YwdjYTuaYk2b5Zvmg3gQNlTrSjnyfslGRMbNDjesouGEKw0jKDpjfYAmGaKxpux9TTUa f/JrBnYADH/mtRGMsBdVcV51gvk9+2ruPl9IoMHMZkwZDq+iy5WKPX4SzPg7mCN59F8V j1Xxpafi3uHfdADD35rhHpcTg053zf8PTZEwefBH8FnJkeceXlQ+hn0FsQ3eMaZTDCil /j/uA6shixfj/Ve6lGqMYuJVE/fO0xNOFlgoin3xHHshqJlK4DV2I+gKcSvOZ21v7FBs iprA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138465; x=1734743265; 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=bHCBDGsUVxz6SdxgZL4telXbGroEPmY7oNy/cAKGEh8=; b=qR1iqvDz8+JRIJBySpKLd1sYG+doE6iXMuxUG35GuJN3Au5Ai9PDtdLmPNvqtORN8c Jq4VEtjzxApetYQp1iVaMHZWAZW89jZ0uRP+HPIfom1Rx6Vi4pV/ygEXB/vv3vtQ0Abd DO6bXrZCy/yREqc8QOhThMDuJSYmfcebbkr5lKTyWNhf/0jVEetaMLiI/vTHhqfybv76 KdQm/BX3uIuaQ+1EaoNlNNtj7I52ELWNWcetEhZSKyzm5LnYSau0SwMVZ78toCXhT+vT eXlt3XeMO2esydceI14bnn3JSj00LqUiLcXOT+DChALh95Y7H8oqePayjcwMgL91LRVe 1IRg== X-Gm-Message-State: AOJu0YzpwyksJhiOiLseTsjD2MA3F4stden4+CJZa5gg79EMg/08ejSy bBJoBiVDW+9USusrHtQjmlThuoGWgCAfwXXSG8v1yjrqQcZLdDSBlFivTwRmCsNSJwMy67ffVXB V/g== X-Google-Smtp-Source: AGHT+IHI7aNGyUVYAZRaIfM3tqmWl5rQShpzYJGmkFTVL8PahcKsfjqTBmmhSQLHOzhneJg36ly7uAtGOuQ= X-Received: from pfvf8.prod.google.com ([2002:a05:6a00:1ac8:b0:725:d24b:1b95]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1483:b0:728:e906:e45a with SMTP id d2e1a72fcca58-7290c269159mr7557525b3a.24.1734138465060; Fri, 13 Dec 2024 17:07:45 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:13 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-13-seanjc@google.com> Subject: [PATCH 12/20] KVM: selftests: Use continue to handle all "pass" scenarios in dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson When verifying pages in dirty_log_test, immediately continue on all "pass" scenarios to make the logic consistent in how it handles pass vs. fail. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 8544e8425f9c..d7cf1840bd80 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -510,8 +510,6 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) } if (__test_and_clear_bit_le(page, bmap)) { - bool matched; - nr_dirty_pages++; /* @@ -519,9 +517,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) * the corresponding page should be either the * previous iteration number or the current one. */ - matched = (val == iteration || val == iteration - 1); + if (val == iteration || val == iteration - 1) + continue; - if (host_log_mode == LOG_MODE_DIRTY_RING && !matched) { + if (host_log_mode == LOG_MODE_DIRTY_RING) { if (val == iteration - 2 && min_iter <= iteration - 2) { /* * Short answer: this case is special @@ -567,10 +566,8 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) } } - TEST_ASSERT(matched, - "Set page %"PRIu64" value %"PRIu64 - " incorrect (iteration=%"PRIu64")", - page, val, iteration); + TEST_FAIL("Dirty page %lu value (%lu) != iteration (%lu)", + page, val, iteration); } else { nr_clean_pages++; /* From patchwork Sat Dec 14 01:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908246 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 69B61193425 for ; Sat, 14 Dec 2024 01:07:47 +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=1734138468; cv=none; b=Qt31XpxP9lC/ypg1mPJuJaP+1CBt8tzetliBcqRIesp0OfIVayJESex7pkz8RP+KJPPLeWCsS75nMM+NH5lUFOsQJkEfLddI0TUtxf3HoSLH1L7LWObZ/MHFjwSKVhroN2APRSXKjH1xEIH1XZB5neCJoaOVU0990euWoOU071s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138468; c=relaxed/simple; bh=Y7iSeB/iFN2r5nReVSRRpd3Yjr16tNr3Xsa+8UTAWN4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qcucv4GFGQfBy0EPvbHB9XrSWJZBuMFcV0jOY4IRmhQYVS9W7NM/Nh+4FYaQL8nZCvE1ChPjkL494bOnh4xQEGkJIQ1n9JG8nEj5Fiy9RvRZq3uiveWLRqdSjYsF8hTjjYqcqKerfqheG72l8RceCOyVcGVztcBgJ7yyIZqj8Ho= 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=DKMbef6h; 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="DKMbef6h" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef9864e006so3111853a91.2 for ; Fri, 13 Dec 2024 17:07:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138467; x=1734743267; 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=eF/Qtxj8u+rXx6pztbYRnhJ4md/Ws0Wq0EpKN7FU8Sw=; b=DKMbef6hFSAU6h1IRlvxFnkqA2MbTVIWGXO3tirQ/m7MJKcYHjo2p0AethVTxbH+0/ 7JldOAMvLn4iSbp502kJMn5aBMNuAQ9RtbmLAMKOxS1+roKv1GJSYQkdqqE8f32lne7t N+q7rf8+3/U2BQaumuAJPLkdf7KIwb5fC3Km2EhQVJOgjIvfOas2lfyZSLkRZ901ThO8 t4QZOq3j5yXG+ietxwXa3MjpLpijptw4t18tTb4ZWpGVsxPUFfk/jS5NemXM6S0O7wsi FrjlaESPqgKkgJRoOT+R/OBOLaDHKgfSzOpmbq04GKG8l3f1Gkq3kmOb/VPO98ABC0jA mGow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138467; x=1734743267; 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=eF/Qtxj8u+rXx6pztbYRnhJ4md/Ws0Wq0EpKN7FU8Sw=; b=tENF0VaXL61xuk6hUi1xIjuCjXcAlORzfZe1DbQBRxp3u5rFcptjoK+Bl8QPAaxyZC xqaysPPF1nI7yjxWLDedJce2T8QUEFWMUli7rJXIgzRo8RUOU1jO72GIFZ+YHEgZpK6L qT5r1yGhzamrC1lN27T5OI6UjLZr2i9kHD2B3huGCNHSStsGg83MHFxMYfdERMkYZfQb 4ihaeX/ZBYf1uut0FFjbNrs7JCUcMyvC0VsVW62eWGk68ISHwg0wFo9m8+7kKvBQMzLB HYXeR1YIZ7XgnenivKufpmduaj3obMsOTBde8sWcaKTShOKNslLAN/zp0nPy+lUgy6Iw mHWQ== X-Gm-Message-State: AOJu0YzRKu2jvp+M9sxpot+IoezOoMi+1gURJHzO78jpAJwCerWYpNVC pSYrbMkndp4h3IVSq7Fz9ysUhycjcIvfJlCA1XCLvP7ZkqVAil98FObmaDyg0VZmkdKlLNij0KQ 8rQ== X-Google-Smtp-Source: AGHT+IH0qFw1WgPjMXBzEGus8ENQhTcYTwf7/Lt7Vb5caWVGm2/gGGV3oi0MjPa5CrhahTjY2DcpyW9W95w= X-Received: from pjbsc16.prod.google.com ([2002:a17:90b:5110:b0:2e9:5043:f55b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5345:b0:2ee:d96a:5831 with SMTP id 98e67ed59e1d1-2f2900a6003mr7323795a91.30.1734138466757; Fri, 13 Dec 2024 17:07:46 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:14 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-14-seanjc@google.com> Subject: [PATCH 13/20] KVM: selftests: Print (previous) last_page on dirty page value mismatch From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Print out the last dirty pages from the current and previous iteration on verification failures. In many cases, bugs (especially test bugs) occur on the edges, i.e. on or near the last pages, and being able to correlate failures with the last pages can aid in debug. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index d7cf1840bd80..fe8cc7f77e22 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -566,8 +566,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) } } - TEST_FAIL("Dirty page %lu value (%lu) != iteration (%lu)", - page, val, iteration); + TEST_FAIL("Dirty page %lu value (%lu) != iteration (%lu) " + "(last = %lu, prev_last = %lu)", + page, val, iteration, dirty_ring_last_page, + dirty_ring_prev_iteration_last_page); } else { nr_clean_pages++; /* @@ -590,9 +592,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) * value "iteration-1". */ TEST_ASSERT(val <= iteration, - "Clear page %"PRIu64" value %"PRIu64 - " incorrect (iteration=%"PRIu64")", - page, val, iteration); + "Clear page %lu value (%lu) > iteration (%lu) " + "(last = %lu, prev_last = %lu)", + page, val, iteration, dirty_ring_last_page, + dirty_ring_prev_iteration_last_page); if (val == iteration) { /* * This page is _just_ modified; it From patchwork Sat Dec 14 01:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908247 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 3D7A31991A9 for ; Sat, 14 Dec 2024 01:07:49 +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=1734138471; cv=none; b=E/sYtwYrJwkN1Ar1IWnFwkczem/SOpQjD8tfwZWIsZJs+ZcgmPFLuNELgl4+UHnsmJegQrEEpxzbQvMuBSj3ZPXaRRhVvqnh1yclDea+vqMzOSkeQa/V9vb9SxlVru3QkJgH6PsJl4qdp0Ox2YSZ7JmI4BS2uJlM8t2Q+iXcHDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138471; c=relaxed/simple; bh=uHBTQ1MR91fKk9C6yhATyFnfaltG5kAv8HeS2SlSvw8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NPve8LUs1+yXMX2HI1EWHQle5OWvEfU3fTVVLzzlM7DQTS0lH8cw+RjLbHsZZlkjDf1tX/osE2ZE7hp1p/pcPU7Rh+8t3KUzdyoviczU2UNi+TrltmDr1Q3j7B0KHJ8kbW9pRFOFEnZN0S3lTxjvNVHfezVJwkae5CqG6d2LXig= 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=CV736Lo7; 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="CV736Lo7" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ee5668e09bso2185967a91.3 for ; Fri, 13 Dec 2024 17:07:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138468; x=1734743268; 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=k/WoCua5rXlbcFyljn1VWee9B6n0EVLZHTgnpdWpUBU=; b=CV736Lo7BjlFb2B/S12bJOTcbliN+/aMHPuIkYx7v9qG6rrLYB2Shjb8HgMYjE7KKO VAjkAlEBzA8T6ACINzyzlmrnfchrI2TQdKrKM02vUR3VKgyiT18TRk1uxFTw9tMTrvsp xZ52jNqX1TVPsMrkly5CtN1+9lQ7cuz54DygQZfyQSqy+hrlgldhfaJePukKmgTUqcYI pFCMXmpjg6k/Bm0+KssKhn1moQSFJAHM9Bq0oGoow4/mPGdgDAB7WfyGIwDHM28Mjcfq NOM1JDPhX8NX4N6NT1B8qN5UA2DJ2AR7aRDAJ+201xRRAIIj4SfO6Wv/3uTSsrfIo/93 bJOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138468; x=1734743268; 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=k/WoCua5rXlbcFyljn1VWee9B6n0EVLZHTgnpdWpUBU=; b=WpnIaeEzAcWXl7AOANfH0WPg5c1jyrRZhpsdaunDQc5j5xS9hCPKhyk9L+AuGSnkbz FPlf8iuAzLFHeV+Qfqv4jg2QYNFJtTt9IEccDTFcnR/QKD6myM/lOlYqUjNa3zdqqVWm IY6rsWt4wy4na52lE3G4jgo4w6SySZKNSoc4aJ6OQCZbKBpwD/Vn65TO9eFYsaBqFaNs ZVDHPQ6FRlD2+UeZpxOv8NgtfR/nYvn/3gwlOEnp6adajSsgjpP8YziceRTL+j24k/Jz CGVxPRvYPw5Q50t6DyHaE5NCAagC3LclUMUJGFYS71QSUwJaqcvq6Nj9nI1cT0BSAs4W okjQ== X-Gm-Message-State: AOJu0YwJvKu85YiNM5f4Z4TOUGc/xBjy+RE2yjkrvtSfG6v3V51jTVgf Q0P/TvAoNgRj8AoiJZzhxO8qktMo9PQ7djzRFRRA3eFFWuMERA4NrzyNrTLyGszYk7a+WL5eExF uLA== X-Google-Smtp-Source: AGHT+IFOeCbT2lDeMqrjnzPUROIbOyM0ueRQ9T8pig2LcktQB+XboaiyKqT5ZsgtmelIG0HO7XsfyTiWA8U= X-Received: from pjbph7.prod.google.com ([2002:a17:90b:3bc7:b0:2ef:d283:5089]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2807:b0:2ee:fd53:2b03 with SMTP id 98e67ed59e1d1-2f2900a66f4mr6687922a91.25.1734138468592; Fri, 13 Dec 2024 17:07:48 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:15 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-15-seanjc@google.com> Subject: [PATCH 14/20] KVM: selftests: Collect *all* dirty entries in each dirty_log_test iteration From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Collect all dirty entries during each iteration of dirty_log_test by doing a final collection after the vCPU has been stopped. To deal with KVM's destructive approach to getting the dirty bitmaps, use a second bitmap for the post-stop collection. Collecting all entries that were dirtied during an iteration simplifies the verification logic *and* improves test coverage. - If a page is written during iteration X, but not seen as dirty until X+1, the test can get a false pass if the page is also written during X+1. - If a dirty page used a stale value from a previous iteration, the test would grant a false pass. - If a missed dirty log occurs in the last iteration, the test would fail to detect the issue. E.g. modifying mark_page_dirty_in_slot() to dirty an unwritten gfn: if (memslot && kvm_slot_dirty_track_enabled(memslot)) { unsigned long rel_gfn = gfn - memslot->base_gfn; u32 slot = (memslot->as_id << 16) | memslot->id; if (!vcpu->extra_dirty && gfn_to_memslot(kvm, gfn + 1) == memslot) { vcpu->extra_dirty = true; mark_page_dirty_in_slot(kvm, memslot, gfn + 1); } if (kvm->dirty_ring_size && vcpu) kvm_dirty_ring_push(vcpu, slot, rel_gfn); else if (memslot->dirty_bitmap) set_bit_le(rel_gfn, memslot->dirty_bitmap); } isn't detected with the current approach, even with an interval of 1ms (when running nested in a VM; bare metal would be even *less* likely to detect the bug due to the vCPU being able to dirty more memory). Whereas collecting all dirty entries consistently detects failures with an interval of 700ms or more (the longer interval means a higher probability of an actual write to the prematurely-dirtied page). Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 149 ++++++------------- 1 file changed, 45 insertions(+), 104 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index fe8cc7f77e22..3a4e411353d7 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -134,7 +134,6 @@ static uint64_t host_num_pages; /* For statistics only */ static uint64_t host_dirty_count; static uint64_t host_clear_count; -static uint64_t host_track_next_count; /* Whether dirty ring reset is requested, or finished */ static sem_t sem_vcpu_stop; @@ -422,15 +421,6 @@ struct log_mode { }, }; -/* - * We use this bitmap to track some pages that should have its dirty - * bit set in the _next_ iteration. For example, if we detected the - * page value changed to current iteration but at the same time the - * page bit is cleared in the latest bitmap, then the system must - * report that write in the next get dirty log call. - */ -static unsigned long *host_bmap_track; - static void log_modes_dump(void) { int i; @@ -491,79 +481,52 @@ static void *vcpu_worker(void *data) return NULL; } -static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) +static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long **bmap) { uint64_t page, nr_dirty_pages = 0, nr_clean_pages = 0; uint64_t step = vm_num_host_pages(mode, 1); - uint64_t min_iter = 0; for (page = 0; page < host_num_pages; page += step) { uint64_t val = *(uint64_t *)(host_test_mem + page * host_page_size); + bool bmap0_dirty = __test_and_clear_bit_le(page, bmap[0]); - /* If this is a special page that we were tracking... */ - if (__test_and_clear_bit_le(page, host_bmap_track)) { - host_track_next_count++; - TEST_ASSERT(test_bit_le(page, bmap), - "Page %"PRIu64" should have its dirty bit " - "set in this iteration but it is missing", - page); - } - - if (__test_and_clear_bit_le(page, bmap)) { + /* + * Ensure both bitmaps are cleared, as a page can be written + * multiple times per iteration, i.e. can show up in both + * bitmaps, and the dirty ring is additive, i.e. doesn't purge + * bitmap entries from previous collections. + */ + if (__test_and_clear_bit_le(page, bmap[1]) || bmap0_dirty) { nr_dirty_pages++; /* - * If the bit is set, the value written onto - * the corresponding page should be either the - * previous iteration number or the current one. + * If the page is dirty, the value written to memory + * should be the current iteration number. */ - if (val == iteration || val == iteration - 1) + if (val == iteration) continue; if (host_log_mode == LOG_MODE_DIRTY_RING) { - if (val == iteration - 2 && min_iter <= iteration - 2) { - /* - * Short answer: this case is special - * only for dirty ring test where the - * page is the last page before a kvm - * dirty ring full in iteration N-2. - * - * Long answer: Assuming ring size R, - * one possible condition is: - * - * main thr vcpu thr - * -------- -------- - * iter=1 - * write 1 to page 0~(R-1) - * full, vmexit - * collect 0~(R-1) - * kick vcpu - * write 1 to (R-1)~(2R-2) - * full, vmexit - * iter=2 - * collect (R-1)~(2R-2) - * kick vcpu - * write 1 to (2R-2) - * (NOTE!!! "1" cached in cpu reg) - * write 2 to (2R-1)~(3R-3) - * full, vmexit - * iter=3 - * collect (2R-2)~(3R-3) - * (here if we read value on page - * "2R-2" is 1, while iter=3!!!) - * - * This however can only happen once per iteration. - */ - min_iter = iteration - 1; + /* + * The last page in the ring from this iteration + * or the previous can be written with the value + * from the previous iteration (relative to the + * last page's iteration), as the value to be + * written may be cached in a CPU register. + */ + if (page == dirty_ring_last_page || + page == dirty_ring_prev_iteration_last_page) continue; - } else if (page == dirty_ring_last_page || - page == dirty_ring_prev_iteration_last_page) { - /* - * Please refer to comments in - * dirty_ring_last_page. - */ - continue; - } + } else if (!val && iteration == 1 && bmap0_dirty) { + /* + * When testing get+clear, the dirty bitmap + * starts with all bits set, and so the first + * iteration can observe a "dirty" page that + * was never written, but only in the first + * bitmap (collecting the bitmap also clears + * all dirty pages). + */ + continue; } TEST_FAIL("Dirty page %lu value (%lu) != iteration (%lu) " @@ -574,36 +537,13 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap) nr_clean_pages++; /* * If cleared, the value written can be any - * value smaller or equals to the iteration - * number. Note that the value can be exactly - * (iteration-1) if that write can happen - * like this: - * - * (1) increase loop count to "iteration-1" - * (2) write to page P happens (with value - * "iteration-1") - * (3) get dirty log for "iteration-1"; we'll - * see that page P bit is set (dirtied), - * and not set the bit in host_bmap_track - * (4) increase loop count to "iteration" - * (which is current iteration) - * (5) get dirty log for current iteration, - * we'll see that page P is cleared, with - * value "iteration-1". + * value smaller than the iteration number. */ - TEST_ASSERT(val <= iteration, - "Clear page %lu value (%lu) > iteration (%lu) " + TEST_ASSERT(val < iteration, + "Clear page %lu value (%lu) >= iteration (%lu) " "(last = %lu, prev_last = %lu)", page, val, iteration, dirty_ring_last_page, dirty_ring_prev_iteration_last_page); - if (val == iteration) { - /* - * This page is _just_ modified; it - * should report its dirtyness in the - * next run - */ - __set_bit_le(page, host_bmap_track); - } } } @@ -639,7 +579,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) struct test_params *p = arg; struct kvm_vcpu *vcpu; struct kvm_vm *vm; - unsigned long *bmap; + unsigned long *bmap[2]; uint32_t ring_buf_idx = 0; int sem_val; @@ -695,8 +635,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem); - bmap = bitmap_zalloc(host_num_pages); - host_bmap_track = bitmap_zalloc(host_num_pages); + bmap[0] = bitmap_zalloc(host_num_pages); + bmap[1] = bitmap_zalloc(host_num_pages); /* Add an extra memory slot for testing dirty logging */ vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, @@ -723,7 +663,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) WRITE_ONCE(host_quit, false); host_dirty_count = 0; host_clear_count = 0; - host_track_next_count = 0; WRITE_ONCE(dirty_ring_vcpu_ring_full, false); /* @@ -774,7 +713,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) continue; log_mode_collect_dirty_pages(vcpu, TEST_MEM_SLOT_INDEX, - bmap, host_num_pages, + bmap[0], host_num_pages, &ring_buf_idx); } @@ -804,6 +743,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) * the flush of the last page, and since we handle the last * page specially verification will succeed anyway. */ + log_mode_collect_dirty_pages(vcpu, TEST_MEM_SLOT_INDEX, + bmap[1], host_num_pages, + &ring_buf_idx); vm_dirty_log_verify(mode, bmap); /* @@ -824,12 +766,11 @@ static void run_test(enum vm_guest_mode mode, void *arg) pthread_join(vcpu_thread, NULL); - pr_info("Total bits checked: dirty (%"PRIu64"), clear (%"PRIu64"), " - "track_next (%"PRIu64")\n", host_dirty_count, host_clear_count, - host_track_next_count); + pr_info("Total bits checked: dirty (%lu), clear (%lu)\n", + host_dirty_count, host_clear_count); - free(bmap); - free(host_bmap_track); + free(bmap[0]); + free(bmap[1]); kvm_vm_free(vm); } From patchwork Sat Dec 14 01:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908248 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 810AC19FA7C for ; Sat, 14 Dec 2024 01:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138473; cv=none; b=NzkH+ipqf6M91L6z1w3TriBElwyC1Rw6THKGqr22a1GT6ojBCfBXBq7UhjzxmXmBkCLtbMvj0xGcRMlfv7GIf4huUlOY+3CK5K4UFwEiXfb/Jwz36v4lxa6AAmm2M3uteQxTjfNRlVP2xZzds+7ok+Gzn6eBfy8PRNHTmmMaPsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138473; c=relaxed/simple; bh=9MuurmYA9iq2LDQ2mxAkARGTen0azUhe64tjUM5enDU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TzfwqcP67Jr6d1rBno/ewV1YFZmWaLnI9mQPWU/uitxYd82792lQcZHIprvZtC7CFiW1/CQCYx9+aYa9tlxTh5OT5mSEYVTxVXzHzWOSmiYI7MsJlbx/gbZgqpcyjm4bvvOqbIpgRh68/VEZ0JPVSUhs8ivvsopPqhkRe0EVuRU= 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=bij5tzJK; arc=none smtp.client-ip=209.85.215.201 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="bij5tzJK" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7f8b37ede6bso2553123a12.1 for ; Fri, 13 Dec 2024 17:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138470; x=1734743270; 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=aODg1HUrgqSkB9GJzL0iLaYYCcyPgozuZpHxFrW0940=; b=bij5tzJKP93JCUpE4eH2M7jy00dkTbHT5R/1v1wRhqrGSIfDDzBJXkLFuG4P/rjvya lZRn35KdNUK5dIQg1YlE2Ibegg+07TWeNOdT7z2FgnCr7nF4YPg6TMDMIk3pbBBGRqeo mhEZr/0qhEmktZy52Rx0PDnJ03kGkWfebvhNbpVzTZazO7wXjjKybheDVu/zGx8xjQgX hC3Hix2hPXRnfvdj3yNuhMqMjH4y6sdckgCQYwiqKb1+VDPzFp4U3SNnurczT9JGgW5B vBqe3Hx8Z+c9dv3VPBCp7gkWDZdUCIwJprLEJ5rnmbkddgLKACQRzgt6k08fhPuqIA44 A++Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138470; x=1734743270; 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=aODg1HUrgqSkB9GJzL0iLaYYCcyPgozuZpHxFrW0940=; b=CtNB0UlFxrv3OXjXYqv+8Q7zrrY/7saY0XtJdKROX2v00LhmFkVuvk6s3MpAFYIatY 1AZSnmNMuGzQ+E1957PxvyMCvYomTlV8ZT3fi552UP8/6X79fkFW1L24TixYDlXfRRjC BP0XXWC3jfYMzICOFbnxU9sPSDIM305jj+Z+nCkuKaC7WLEf/19KYnwlhlAxjh657B4r REhY0rJZ2soYeXDVKaMtcWtMHg5j2mj8T7Ji3Md0Gai7JBCv/ynyZl8MAdt512YLkbpO J3DC4r3BbOYeEEjih1Jcv2EPp21EsifbjYkI64vPuUUxlkwQ70PNYnaubdkNIALFhfB0 HNEg== X-Gm-Message-State: AOJu0YxJvJccngWSIcVs2Bb8dwk8wntVW9ud1/v7GQPJ9R7tvF6sCzxr OWvMKWimBt7GqjCWHIoAbT6TBGsDHowzwsU2CHElvP5MvlN83xsHO3CwTnvIe59BYSASQiFgu+n 2lg== X-Google-Smtp-Source: AGHT+IEVD/Y7FXciDQf4D6/qqct1VpWHqA1Sl9Mi4Dpk2L8jDoPr27DKPwgTnmxBz1qbfJxMcCuqPjOJvVg= X-Received: from pjbsy3.prod.google.com ([2002:a17:90b:2d03:b0:2ef:8d43:14d8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d44d:b0:2ee:7870:8835 with SMTP id 98e67ed59e1d1-2f2901b548dmr7699775a91.33.1734138470050; Fri, 13 Dec 2024 17:07:50 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:16 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-16-seanjc@google.com> Subject: [PATCH 15/20] KVM: sefltests: Verify value of dirty_log_test last page isn't bogus From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Add a sanity check that a completely garbage value wasn't written to the last dirty page in the ring, e.g. that it doesn't contain the *next* iteration's value. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 3a4e411353d7..500257b712e3 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -514,8 +514,9 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long **bmap) * last page's iteration), as the value to be * written may be cached in a CPU register. */ - if (page == dirty_ring_last_page || - page == dirty_ring_prev_iteration_last_page) + if ((page == dirty_ring_last_page || + page == dirty_ring_prev_iteration_last_page) && + val < iteration) continue; } else if (!val && iteration == 1 && bmap0_dirty) { /* From patchwork Sat Dec 14 01:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908249 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 208761AAE1D for ; Sat, 14 Dec 2024 01:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138473; cv=none; b=i5G+UBdu3wq2dDYqkkX2g4zSI+MmEslsAXC+baalGdUOvq64Xwx6vKWS9yeRM3AoUhVIJSuyeEL7Op882AMtY0Lq0sT0+V9lpzwSDA6VH443aQ9ozjKraqr2nIaVNPL0Xdtn9qbHyZ5s5C0Z0Ihfc0Yn+F7+gokV3/wpcYTtUJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138473; c=relaxed/simple; bh=s82yfUral0BohE54IlxUWxNUqQShfk9wROTZ0YeYQLo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uQ62EMT3R5QebUP9WVyRsdRnjFjdVZH5LlFte0zp2zXCD2gXkEIa0MInHdH1a265sBG9x1Jlqx0H8cBixKbBCMKpsoI7BrzMfjwS05xxlrxAbk6APd0qpqXhZJQat0nPU4OVevQQ5elB0sgFPfa8kXQzbtZgQtlCvpkwv0KXmX8= 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=ebE9QEXk; arc=none smtp.client-ip=209.85.214.202 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="ebE9QEXk" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21640607349so28481225ad.0 for ; Fri, 13 Dec 2024 17:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138471; x=1734743271; 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=YWWtymQ8Nn5N0UWTLn3mSIvyTdUGCBiZBYn7TuhHiD0=; b=ebE9QEXkR20I8IRtJFTzXEG3bF6iInfwctjmwySXuYfh4Rp010xmd6saYQ+4gCdo7r bWxXw3N6uvq35x1e3be1MiDl5WB4Rulh+NABTwW6eaIRpTEKjcSWOm86wXmraJOmSpOo NY3nB2iv1rqub1UlZelLRl40DxoxhRI8zDk1cYqICWsF3kJP7x+5bXw1pD5/O8FxE5kL aGq2GAVeNkfC/i04AZ9/MTx1HHtNyC5/j1zkmkvI72Efy3LvRTRlNiAb3oEt1n9X22Pt rYK+q3tfCEjhgxA+PbQM0TeslcHjmTVE+BCa2hRIWOJRbZNUoR4Gzmc1Cbl+Bo+yEtSV QHxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138471; x=1734743271; 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=YWWtymQ8Nn5N0UWTLn3mSIvyTdUGCBiZBYn7TuhHiD0=; b=jXRaylPyg5mDN5T0Q6Ya2lADnIb8l00GxGb9g6FrGWOxsHdlFaJr1L79zzwA7YzATU gqQA7Z4k7lP3mBMz9m/ptjkIRJsFj9Yl5Xgbr7G09HaMWOc4nWn8vZYdi5z8fxDmQ1Q5 GCPd1NUyu00CAGC5Nph/WgmvJZo0TzRdVtuqiiY0RT2JQTu9Ga6M5KTiPQAkwWxcT2GJ MEtjnlSBiClJxG3P114cWzlLudPhwhJ5lWtha2A0ZTQZPrwHDBlHXme+h3hOFGFt9Bph xdHcKoYrzoOpGXcC/5jaSrmfQoucWa5WXPovu4BQoYJkPz/vkETSgMVImVFXNyVZD2wS eGJQ== X-Gm-Message-State: AOJu0Yyjp/62dJZtzcLg153ijhhBVpPIZ+3Jze5cRXcobuGpb4+ZDeGT ghWIADm2rzV2wG3kAtQ9ewPX0aXSK6pBiyDhiadF3VObRP/sy4nYSwIEMyTcJx9g2aaoOoimyeL WNw== X-Google-Smtp-Source: AGHT+IFU4BypwuzzTQOeGtuvKNhTd3bHMKO+gfxWQLVd3JADZrqnkPL2M0DVn+Td+hPRNqfQ4ImRbaLlQMY= X-Received: from pjbsj5.prod.google.com ([2002:a17:90b:2d85:b0:2ef:7352:9e97]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:cf0f:b0:216:5af7:5a6a with SMTP id d9443c01a7336-21892a01ad5mr68834145ad.32.1734138471497; Fri, 13 Dec 2024 17:07:51 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:17 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-17-seanjc@google.com> Subject: [PATCH 16/20] KVM: selftests: Ensure guest writes min number of pages in dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Ensure the vCPU fully completes at least one write in each dirty_log_test iteration, as failure to dirty any pages complicates verification and forces the test to be overly conservative about possible values. E.g. verification needs to allow the last dirty page from a previous iteration to have *any* value, because the vCPU could get stuck for multiple iterations, which is unlikely but can happen in heavily overloaded and/or nested virtualization setups. Somewhat arbitrarily set the minimum to 0x100/256; high enough to be interesting, but not so high as to lead to pointlessly long runtimes. Reported-by: Maxim Levitsky Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 30 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 500257b712e3..8eb51597f762 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -37,6 +37,12 @@ /* Interval for each host loop (ms) */ #define TEST_HOST_LOOP_INTERVAL 10UL +/* + * Ensure the vCPU is able to perform a reasonable number of writes in each + * iteration to provide a lower bound on coverage. + */ +#define TEST_MIN_WRITES_PER_ITERATION 0x100 + /* Dirty bitmaps are always little endian, so we need to swap on big endian */ #if defined(__s390x__) # define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7) @@ -72,6 +78,7 @@ static uint64_t host_page_size; static uint64_t guest_page_size; static uint64_t guest_num_pages; static uint64_t iteration; +static uint64_t nr_writes; static bool vcpu_stop; /* @@ -107,6 +114,7 @@ static void guest_code(void) for (i = 0; i < guest_num_pages; i++) { addr = guest_test_virt_mem + i * guest_page_size; vcpu_arch_put_guest(*(uint64_t *)addr, READ_ONCE(iteration)); + nr_writes++; } #endif @@ -118,6 +126,7 @@ static void guest_code(void) addr = align_down(addr, host_page_size); vcpu_arch_put_guest(*(uint64_t *)addr, READ_ONCE(iteration)); + nr_writes++; } GUEST_SYNC(1); @@ -665,6 +674,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) host_dirty_count = 0; host_clear_count = 0; WRITE_ONCE(dirty_ring_vcpu_ring_full, false); + WRITE_ONCE(nr_writes, 0); + sync_global_to_guest(vm, nr_writes); /* * Ensure the previous iteration didn't leave a dangling semaphore, i.e. @@ -683,10 +694,22 @@ static void run_test(enum vm_guest_mode mode, void *arg) dirty_ring_prev_iteration_last_page = dirty_ring_last_page; - /* Give the vcpu thread some time to dirty some pages */ - for (i = 0; i < p->interval; i++) { + /* + * Let the vCPU run beyond the configured interval until it has + * performed the minimum number of writes. This verifies the + * guest is making forward progress, e.g. isn't stuck because + * of a KVM bug, and puts a firm floor on test coverage. + */ + for (i = 0; i < p->interval || nr_writes < TEST_MIN_WRITES_PER_ITERATION; i++) { + /* + * Sleep in 1ms chunks to keep the interval math simple + * and so that the test doesn't run too far beyond the + * specified interval. + */ usleep(1000); + sync_global_from_guest(vm, nr_writes); + /* * Reap dirty pages while the guest is running so that * dirty ring full events are resolved, i.e. so that a @@ -760,6 +783,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) 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); From patchwork Sat Dec 14 01:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908250 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 B17651ADFEB for ; Sat, 14 Dec 2024 01:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138476; cv=none; b=Vt7qRRXI7L+Un8rC2qVjtvnMyV71H8pf1guB+mZoK+JgXGC+pL/BeIeUyDT7SWSduEoYMjS++bol2VLdEl6Bk07wCtvZmmE5jYSRQ4LyFcMhTtp0z0+5dhSQIPTmpQd7VbYv9wtJJD02aRDbEgpdMCHEPr9ZXNYMKRmYlRkfV94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138476; c=relaxed/simple; bh=15fjBvur3l72YTctDs8wzcqD8BFstsOioZDobvlDBPk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fx2MJX6agEHR6p97QF3BoAgWopqJHTVPCtCXyAONnjeOO3ZLilz/Uhe+zbmLFKYselPdDnmRCY3CS2o9HjVZx47hlKi3xmeqqhR8aJigMkEUivHBy3fUvVO2CMKSqPza/1CqVfrjaVylfRRkqKw9GYJfz/GzwW2md0g8DluCoDw= 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=dQePBnFw; arc=none smtp.client-ip=209.85.210.202 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="dQePBnFw" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725e2413114so1788004b3a.1 for ; Fri, 13 Dec 2024 17:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138473; x=1734743273; 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=l6O5Kjy9lNdBNSlyw7J2d7cJV0mm9IEhLLTToQ8CHPk=; b=dQePBnFwXpMIfDmew92avrGAWDye97SyhD7Zl8s2hcHE4KThG/c53G9hhnyaEEmcOY qFAh6LjuVmc4dPGF+Q3u51iLkLrc1mAaNiSzQ/S8bOKFo9UWtbHFiOtk96PxkfN3Rrog hdGf5fnfz+p3qVr+5651Z0iuEOVYOtZnn8nAO47U4xS7xrzf5WK6buvHPWZcPzqMTyTX R+8rgvB5u4wCiBLmL2XPlPoxsn3lgG/f3qS0psurhtaPwtl6w4+xu2yHH4kItYtSdcSm P7+B6PE2EYu5fQ1bH2IUpdLxrCSOCFIH3LUrfc0dRDzzdCvD5ORPuIh+mN82lDAAQPqE bNPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138473; x=1734743273; 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=l6O5Kjy9lNdBNSlyw7J2d7cJV0mm9IEhLLTToQ8CHPk=; b=BGeIRr4uJEG8D68y1OFBk80AceHGuDbi8yMEH8GSo/cK9Q9JWK+35bsDeHhkqsHjRA f9/CNQaGqxmmRk/hjwJFH6xKn+XUTQC2eaP9Z+sk4TCrBF5ibHm/WPihF6yKg8Jh+X+Z BnP2iFzvOqOEJDmkhFqNVEHdRXEx/o2Pb3wWSZQIhyQ5BKRRPF8TgoCuhFMzjVYWBpF1 8Iob5p88IueD2g1uI1RaiVsJldCL0piNSdqUCGcSkgjpS6Aa9SxWq2Q5GLwtsLIhHLHj IzwYTLKmez6nxXGUOTk1A4zyzSzQi/yrao6rulsW5xzmIwicevPfyb0WgbDEKK/8bCcG W1eQ== X-Gm-Message-State: AOJu0YyFtfOc9uqkP5bAs88C2GuICt5GdCqcjG6lPfooNS60EZO9bQLm UGijD69bhNG8z9/BU6q5d3TxkqYHt2tO5zLhclaKVBre8qGirvgv9hWpOmjMrY29SuVEqn/FtH0 m7w== X-Google-Smtp-Source: AGHT+IFbjgenJSEGTWdLgFOWtExnq+ivKP1l9rQ765/WWBXl0wC/gywOgYMd4e6dYdWbXXmt3f8FtKaH6qI= X-Received: from pfbgg9.prod.google.com ([2002:a05:6a00:6309:b0:728:e4d7:e3d3]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:288e:b0:725:e957:1dd1 with SMTP id d2e1a72fcca58-7290c25b8d8mr6933616b3a.17.1734138473024; Fri, 13 Dec 2024 17:07:53 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:18 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-18-seanjc@google.com> Subject: [PATCH 17/20] KVM: selftests: Tighten checks around prev iter's last dirty page in ring From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Now that each iteration collects all dirty entries and ensures the guest *completes* at least one write, tighten the exemptions for the last dirty page of the previous iteration. Specifically, the only legal value (other than the current iteration) is N-1. Unlike the last page for the current iteration, the in-progress write from the previous iteration is guaranteed to have completed, otherwise the test would have hung. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 8eb51597f762..18d41537e737 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -517,14 +517,22 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long **bmap) if (host_log_mode == LOG_MODE_DIRTY_RING) { /* - * The last page in the ring from this iteration - * or the previous can be written with the value - * from the previous iteration (relative to the - * last page's iteration), as the value to be - * written may be cached in a CPU register. + * The last page in the ring from previous + * iteration can be written with the value + * from the previous iteration, as the value to + * be written may be cached in a CPU register. */ - if ((page == dirty_ring_last_page || - page == dirty_ring_prev_iteration_last_page) && + if (page == dirty_ring_prev_iteration_last_page && + val == iteration - 1) + continue; + + /* + * Any value from a previous iteration is legal + * for the last entry, as the write may not yet + * have retired, i.e. the page may hold whatever + * it had before this iteration started. + */ + if (page == dirty_ring_last_page && val < iteration) continue; } else if (!val && iteration == 1 && bmap0_dirty) { From patchwork Sat Dec 14 01:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908251 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 759371B372C for ; Sat, 14 Dec 2024 01:07:55 +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=1734138476; cv=none; b=B88J20lNxIi0qeTcpvYVRPeK/PmSl7MPb5AIdHdC1gnCBcOISDqQqOjpwIO0d6FbyPa5rKjxX/ID2sZZLbB2ICZ1CyvRsWeXUtsCg0IXEu7Ws0+4ynQaDWFbIhF8o/i7eUrMNNTbxuDWv48b7C6I0bWYtwrTK9I+gfcj+BEjY4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138476; c=relaxed/simple; bh=Kr5ySemqhB8x0c8j9nsPd7eiJY6MO4EMZGp4hkHhkd8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kVkOA8M9PoPRAoylqJDYAYB2NHBBUYVIsjg/WzFrEFkw/Ch61T8WwqDZQr/GBEvXboeroSL3V1pUXA2wWOg5C25SBffWDahXSa+SFmOTpjZxkqAt8QzXG1evL8DjxWjSD39Bl0KL6U4NBXJqYWD1gAdB90CQnpKHHi3SQlDTdw4= 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=cKI3orlS; 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="cKI3orlS" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef8c7ef51dso1925972a91.1 for ; Fri, 13 Dec 2024 17:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138475; x=1734743275; 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=Os40ssNAIeaE2KoVXFwHg6MBfdGS9M+rTKqJ6LN+iOY=; b=cKI3orlSBC+2NeRm+KHjYDI65Es+dTRorEq1MRh+I4n3nhEK29dqySngp1ti2dlAYh 5KmjFjGVh+YCL1A9jqkquf3NBD8CZzsmC+Z4CVbmu2LuINjjAux02FA5lNDcCWxYkuYM 3crtBodHOrxUn6vgQqyMmN3rtW5+FYuxiTNvGRhTcqwluerN3cjELhARCF2PSxbAFNyi VtsyrbEK62tJsgY6kYzrIq1p/F70dkASqfi25RixSIJ33TB7XUgp8h/mXq5vir3u2TOz cbpOcDP3sBDSNORFMZjmIAUs1rQ9Y8iy6tjosjQCpSdcx3e7BgZMowirpL+UFq969mkB gWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138475; x=1734743275; 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=Os40ssNAIeaE2KoVXFwHg6MBfdGS9M+rTKqJ6LN+iOY=; b=OLDfRmZsuWkjBNWjL/JnU4Xbpb0ueqGWJhhJ11NjoZffTuX2AjSPaj20rsh+MfRSbK 7gp1JlOcQC4onJqfeLYGvCmPpeqjiMQ7wsOVsgajU8V/EEMBzhSkxdQ4YsdhlJCm/zXE JOp/HzuHJPclT86lSOf1rBRCdRual5c3wEqr1sqHT+0/WkUWcTxIeHKeok1GQ/mKlhgd v5R+G3XTohCyMvs//YKjk0TjNFOf36MEuOSSkN6J/bea4BgAL5hfj61vSuBReTLj+vSy KCXNh310+qaz3lNEonTDkeOUaSjBolxZrqJMNI1+cLh14fbz0oo8f8+jHqCZLChQHHJz B17Q== X-Gm-Message-State: AOJu0Yypb9adh/VARwG/5EVacU4RSQpCDCVI+n+dejnei9O1js2pyXIj /vUhC2JLvsip6QP/q4TjWup5EVwBe1vKR9/B/+CplDMRoWAWdohRrGIGCp2d9l+2G1keqs9oBEU 65w== X-Google-Smtp-Source: AGHT+IEZ+CgAMrCPJQOZACHcPD8CU7pR7etrO0c0IAnvZOB3YGn0IBxaunMGHCwATRbOfD17c9JSoaKnYEU= X-Received: from pjh13.prod.google.com ([2002:a17:90b:3f8d:b0:2ef:701e:21c1]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c02:b0:2ee:7e53:bfae with SMTP id 98e67ed59e1d1-2f29166c324mr6418476a91.10.1734138474915; Fri, 13 Dec 2024 17:07:54 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:19 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-19-seanjc@google.com> Subject: [PATCH 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 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/selftests/kvm/dirty_log_test.c index 18d41537e737..f156459bf1ae 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 = data; + 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 *arg) sync_global_to_guest(vm, guest_test_virt_mem); sync_global_to_guest(vm, guest_num_pages); - /* Start the iterations */ - iteration = 1; - sync_global_to_guest(vm, iteration); - WRITE_ONCE(host_quit, false); host_dirty_count = 0; host_clear_count = 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); /* * 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 *arg) sem_getvalue(&sem_vcpu_cont, &sem_val); TEST_ASSERT_EQ(sem_val, 0); + TEST_ASSERT_EQ(vcpu_stop, false); + pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); - while (iteration < p->iterations) { + for (iteration = 1; iteration < p->iterations; iteration++) { unsigned long i; + sync_global_to_guest(vm, iteration); + + WRITE_ONCE(nr_writes, 0); + sync_global_to_guest(vm, nr_writes); + dirty_ring_prev_iteration_last_page = dirty_ring_last_page; + WRITE_ONCE(dirty_ring_vcpu_ring_full, false); + + sem_post(&sem_vcpu_cont); /* * Let the vCPU run beyond the configured interval until it has @@ -779,26 +785,11 @@ static void run_test(enum vm_guest_mode mode, void *arg) 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 == 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); } + WRITE_ONCE(host_quit, true); + sem_post(&sem_vcpu_cont); + pthread_join(vcpu_thread, NULL); pr_info("Total bits checked: dirty (%lu), clear (%lu)\n", From patchwork Sat Dec 14 01:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908252 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 F3D091B4F09 for ; Sat, 14 Dec 2024 01:07:56 +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=1734138478; cv=none; b=EkjdSqdaqB4X0KnQhOyYFc3Xdrk9D04zICO0VKhd1lhFVdsg+HIGl8Itq0OoH1vfQZnxuE3GoCOHwugmPrMKzdSMouR9hMdExJkTFP7vfpjddbFz1j69yYltPo6/TgYPeXgXhmZRh79JkKrwUCHN7LMbF4yQZ8zZBtDNWlTOBus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138478; c=relaxed/simple; bh=pDZnzwMtFKKjkZf545bumaOuduTyj6ts49mWaHJuc48=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GwGLPoJ5HQNriZmkYDOPVNROlaMpXMnhH8ypEx2IKs4LbmtVqogBrIXDOfms2t2h4Xjgne6k31CaLWPGWuJFpwcWgdGz9IhpIHdUxo6eU8HrMTbE5J3w0B92hdyEYedTOXweYcTm7mrIFS/l8V8yPUNzBMr7sxj+gt8mUCHho9Y= 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=fA110riY; 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="fA110riY" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef6ef9ba3fso2154732a91.2 for ; Fri, 13 Dec 2024 17:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138476; x=1734743276; 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=kyzGkI3IvXN3TGddEZhxOSkoRVtkhVr6EY69RLW1Hj0=; b=fA110riYQ7mzw5tmwiKZ7tpYjPzOM3B4uHCvbg2DixVyaIjotu8vlpuSs+47OdJnTy +NQZLKomqM1VYMF8G67Kh2Lja1Vs6Pvsiu/MalWrhIr2Z/SjVaDRqE/fP9mwr5334lJe mbgBvZkDjGj85v5OEz2x22X+ONEGjHZivdiaRz23qyCG/Dc6shJdtldXtbVx4sJp3PIx YmFaXA1oQfoJJtpiqUsKbsVQxDjotxqpBuGxBzhS/+Mupnw2coVI9y1adnnvcE2h/Lnc shRLm4CVi1oB+yYDNx2PJ6+tkY5kbjTlaayOHSe8vSHyMYghyjKs/FJdseSeHTIQHJnE wpKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138476; x=1734743276; 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=kyzGkI3IvXN3TGddEZhxOSkoRVtkhVr6EY69RLW1Hj0=; b=U3xn1Bu7OnsfUdXFvEFEkAM6SiXHwgfS3Vz2LaBjdQUcUCuZ68Fo7agBjIru/tcjfB TOSXlOy0zhEuY2+ZDruSuyDqVKoRRo6ZgeBNzb+/rYui0WONmgQnI5q2+k2+0GmbqOop utzGAA9hu7qic+giFQxm8rzLMLbRbtZeHdHTAgOZlsgLidME0LD6HGR4MNMY0yTpeaYW Awilh96BpWw6ZWB8vnjGBcsbc/hKGRb3OF4XHPA8HJr+w5CNGMmQL4EP2bVZ9qtTeKbB bNoOJR8N3BlBlzFbP/kVwTdxy4tQ+KaMWhIKbSJg4pfJyPB7FnpugeqAu6Snp2xVMn17 6Xjw== X-Gm-Message-State: AOJu0Yx3xsSHOTIiqjqAni9URUNbqbB41XEyhLZLH4gCyIO9DDdSEBbo is+6fwNz/6BoeDpbYReGK/BvbG+jRbTe0U4+1rbT23pqLXcKbb7vhVzWKdQIFZTsTEvviVEB2iw S2w== X-Google-Smtp-Source: AGHT+IHq855LEa56OvCOBHncsQaNtJqisSGX9xNUcKPK+XU9hXvCIFgOs5mq84Ykeo76A1ifl8AZTDtOY18= X-Received: from pjboi16.prod.google.com ([2002:a17:90b:3a10:b0:2e2:9021:cf53]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:6cc:b0:2ee:a76a:830 with SMTP id 98e67ed59e1d1-2f290d9876bmr7822126a91.24.1734138476607; Fri, 13 Dec 2024 17:07:56 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:20 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-20-seanjc@google.com> Subject: [PATCH 19/20] KVM: selftests: Fix an off-by-one in the number of dirty_log_test iterations From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Actually run all requested iterations, instead of iterations-1 (the count starts at '1' due to the need to avoid '0' as an in-memory value for a dirty page). Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- tools/testing/selftests/kvm/dirty_log_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index f156459bf1ae..ccc5d9800bbf 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -695,7 +695,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); - for (iteration = 1; iteration < p->iterations; iteration++) { + for (iteration = 1; iteration <= p->iterations; iteration++) { unsigned long i; sync_global_to_guest(vm, iteration); From patchwork Sat Dec 14 01:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13908253 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 CC37B1AE863 for ; Sat, 14 Dec 2024 01:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138480; cv=none; b=EIf+6pzuOUdxKa+iCMiNjG6/l2onBhXVAYG0EJG/fW2wPqbzgsRToH3oUySys7D+pYODtY5L6nBtywpbvxnTu/rgtdGP8w0kWwHy364X+H51aeGsG7xa/VjzIyRUsiIgCslz0JoRZxBvU67P94gJmaJse78TD1nj/hfI3eXHcNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734138480; c=relaxed/simple; bh=Ceumk1Ttpyk4h+LMc7F3vGAe0OUH9kkpzA38uyhTPLo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ypwp3XcPIz5jnQyTQnxwNujb/Rn4p6472k55vQNlwqdkOSDqzjewZmsbsedXK8rsKPWgfcp+j3rWTB3dgrnp+9r12b3G++irHtZ84UWUnFzVJfKK26YpJMfoH/uVAQWFNIsgNYJLPu6Au6UUQABBynRNWL96YLWi7scmtpmt1QU= 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=BmKUmjeR; arc=none smtp.client-ip=209.85.210.201 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="BmKUmjeR" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-72467cd273dso2863526b3a.1 for ; Fri, 13 Dec 2024 17:07:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734138478; x=1734743278; 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=9M8UqaW8Gm4S/67GPRyVYas3GRYQeNLXsPFj+ckb7wg=; b=BmKUmjeRJtm6INrLzmWGeOLn3IWx2Hdnf5+iFOYj9EdPipFPx5MqsT4iBbiBWvW1CR gVqoxgAtTBSOMN7J3vPjsGAICDCBDZmFc9Q7jVpVCR3r6M+c63CWnvb6ypGV3LaaBgg6 0g4xRB6APM9mX2vTddmGCkkFxKfAUozZ1LZC5jvX5WO9mtziBHHGY37pOW589yrSTInu ZEtUH7AJ+uUBypLcDNLlF4A2ceXN3Vd8eMCVB92bJxmUiWcracKY9LTCoPY+dQTwXqKg KEscnAYmXnNvpw5WErgGqZDNen9223B8f83hdh3tlPDFIvGawiFl+FFa9T6FHRlvjFCY A4XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734138478; x=1734743278; 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=9M8UqaW8Gm4S/67GPRyVYas3GRYQeNLXsPFj+ckb7wg=; b=F5r5Rwktk/cuZp9ervS2x6G7Pcpee3t34tBFjduGgepjSlJiX76+4Ng1D3D2et/8DS yjMmM+czt9mOn+L152qSejrQBEeNDMPzJYwQtMCcVJzJezEvcjpV6/75k30bb52WZs4x k/SamKTff8+5v13OL9rHZltNmE6k3c7FH0+CktLfYC4D2Kjk0u8nhrowWr5powYcOISi 5mQEGsYFOS5COuApmEWMBVkd7sewGmsNUZ5sJrMmoIO0+jtMeSEYg/IGailbaElB4x8J S7HZoqc4sNUlXjZICkJt08AabDhAV3LmSHdXO5R590JB8OZPq+FFTBrzmAFhVUwlpZyW vTSg== X-Gm-Message-State: AOJu0YzJ8Ftyj8B1lYOJ3qg6jsA8VzZrCzU4AqYgnAUWiHfZzlKlm3iU 4hkM92aYH9JDJs9IC4BABFnDF9GMDNptUOmCqIwgyWpz1Y0IqhR8B1ZRY5w1oL4+O4ZZaGiNGCn AvA== X-Google-Smtp-Source: AGHT+IE0D0ZgxVI141VOT2+yGr3JOUwPdzWtmGseuD8KjVBk4OygIKGBmnd0d+BjrhKNBNRpBSMJYgZYLo8= X-Received: from pgcp7.prod.google.com ([2002:a63:7407:0:b0:801:9858:ef95]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9189:b0:1e1:a434:296f with SMTP id adf61e73a8af0-1e1dabe1a2dmr8727195637.10.1734138478053; Fri, 13 Dec 2024 17:07:58 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Dec 2024 17:07:21 -0800 In-Reply-To: <20241214010721.2356923-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241214010721.2356923-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241214010721.2356923-21-seanjc@google.com> Subject: [PATCH 20/20] KVM: selftests: Allow running a single iteration of dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Now that dirty_log_test doesn't require running multiple iterations to verify dirty pages, and actually runs the requested number of iterations, drop the requirement that the test run at least "3" (which was really "2" at the time the test was written) iterations. Opportunistically use atoi_positive() to do the heavy lifting. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index ccc5d9800bbf..05b06476bea4 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -880,7 +880,7 @@ int main(int argc, char *argv[]) } } - TEST_ASSERT(p.iterations > 2, "Iterations must be greater than two"); + TEST_ASSERT(p.iterations > 0, "Iterations must be greater than two"); TEST_ASSERT(p.interval > 0, "Interval must be greater than zero"); pr_info("Test iterations: %"PRIu64", interval: %"PRIu64" (ms)\n",