From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00B6935966 for ; Wed, 18 Dec 2024 00:03:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734480185; cv=none; b=rdfSNCXDkcim/Vh1pdIr5EFKuOBBuobZp9eNk0jkSBY7sWxxokFtnUcmcqvUq1OhUbQAAZKqpOY9fvtwqomq+gw2aAMmh/yxnHmmwEF0IA8ug08/HWT2/TDXDN1jKU3SuLj2tnzAnQfVtjMEVdZh2bRakz/3TK5nRkaUZN0Xv3A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734480185; c=relaxed/simple; bh=FsozFYKSw64t1IC87qXIPAfB11JHhmbprN5KJscGNwk=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=sfFnab4bb4rRId489+UQyOLuGTz8h03gVAwBRZQ3FMwGXeeKCFHp6sQo83mSTa5oNs09jRNa0vHmwzk2A5yu6yRR7pAS+aJCze4CuLrb6Ne2AeM3Obb2VG1US/fvLUfwnDdaHL3N1iVKgP2LqmyUV+g4E5LbX4/jXm+Ks4L+g1Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xi9inIRo; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xi9inIRo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734480179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oy8ZDLJw1QkJ4PxJcxL0y9DkDZxPpsMmuhcLibDgiaE=; b=Xi9inIRo5yyHjwsFMVW0IPxTqOH8V8A3EDUueqJzt6nV/SSmlBAnDGuVHa2f5LxiUOr+ek wpehBGdx6uAh0hMKNQezLsCHXNHVviNqSmjUaNhxMQOYn6lB7X0MDCLyB+0Aoa6jGHmA04 520Wf8RR2l9+4q/mNwsiuyL2jhZnRjE= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-199-tUR8xdiwOyiyoRnEmyck3A-1; Tue, 17 Dec 2024 19:02:57 -0500 X-MC-Unique: tUR8xdiwOyiyoRnEmyck3A-1 X-Mimecast-MFC-AGG-ID: tUR8xdiwOyiyoRnEmyck3A Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a814c7d58eso56884255ab.1 for ; Tue, 17 Dec 2024 16:02:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734480176; x=1735084976; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oy8ZDLJw1QkJ4PxJcxL0y9DkDZxPpsMmuhcLibDgiaE=; b=Gco+XK2DMqSI86gVdUyYGwE3SlstwrPArcA3IFL2l0iXvZpCQdWkkcsARwVMhuCRo0 Vm2FHmwNMNjKzNF2HFB3mpgbRtiNStNg25eAZogCI/ZkGANVHMRdqGQAT0a5r8qreZrM fHS5bliQEloT7u0leEuFly2d2WVyDzyYNCVaYjgwNXv1NPcmndvVrWPIRkxMprs1tfFW /CUJfITmJfcGnb6lKfCDrfqI3W8PtXx0G2j/ZEYAYLBjkCoAMxczkFY1YSU4X6hdKCVl 5eIahXfRXbcOhw82sFLVcrbw78zSGMWfkzI5KzkWU8OYOcW292p1hU80CcHJ69cTBVph uuzw== X-Forwarded-Encrypted: i=1; AJvYcCVlGYVFDEgVY7S0dlWCerawImeSZo6EJkUhOWcJg42ZvktJIwwFtzsx0/6hb3aqCnpQKBHYUEKN2sa21J0=@vger.kernel.org X-Gm-Message-State: AOJu0YwC0l21nQLWL+QpE+ht0i1rpjlZjVizF0D8NtO4pP+hlWesxtfL ePoEPAYnNrFEwWcCezmU/ECkhwtJ+eAYsHiGBVi0FMGpeyrI/j+G4McgLIZd/+XsMCTEahgZBCF WYz8TleJ9GfC191wcd1stRPV5PZXU+cnIjaEJjv9RQSaw1LOGrXB7Cz2Y/F0rCloy4rUAhw== X-Gm-Gg: ASbGncvkWW5/GqIQ17buxMNxnCI3hwJIk0nXRd9QaTtnbCtEMDEVhJ/SMOSvfeu8LFw AXihmSadTxILIIR6dLModM4vdfE6/QNzmbsPEJe9eB2tVAMUNqBFUaWPw38tECsELfP9tPAMXC+ s9kAmd0SfbzehGmkb/UugDicIi4aFIN4gPjhx6u14tivHxq7IHDaPMyBLfr4wFT1XFceVBFThLm l3+8XW1sMFyixH1H8JxUYkmsVBeYJAms2+bnHiSQayQ+A2fZsJBgB3H X-Received: by 2002:a05:6e02:1aa6:b0:3a7:d84c:f2a0 with SMTP id e9e14a558f8ab-3bdc0ad2b96mr8370275ab.7.1734480176498; Tue, 17 Dec 2024 16:02:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBZuELW1Y66tYCiTErQpDFwPIVVaAfPI8SAvM3CSLNbY2tysakmVtv5/nMA67EocL3N5a6Ug== X-Received: by 2002:a05:6e02:1aa6:b0:3a7:d84c:f2a0 with SMTP id e9e14a558f8ab-3bdc0ad2b96mr8369995ab.7.1734480176131; Tue, 17 Dec 2024 16:02:56 -0800 (PST) Received: from starship ([2607:fea8:fc01:8d8d:6adb:55ff:feaa:b156]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e67428d17csm250617173.57.2024.12.17.16.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 16:02:55 -0800 (PST) Message-ID: <09fffc1c382a477cc97f5b28b051700707dacd20.camel@redhat.com> Subject: Re: [PATCH 16/20] KVM: selftests: Ensure guest writes min number of pages in dirty_log_test From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu Date: Tue, 17 Dec 2024 19:02:54 -0500 In-Reply-To: <20241214010721.2356923-17-seanjc@google.com> References: <20241214010721.2356923-1-seanjc@google.com> <20241214010721.2356923-17-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit On Fri, 2024-12-13 at 17:07 -0800, Sean Christopherson wrote: > 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 > --- > 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); This makes sense. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky