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 EA3C3226195 for ; Thu, 19 Dec 2024 15:11:07 +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=1734621069; cv=none; b=NwNJ8ylnpv+bBT/VXnC0wjYannhE0u24G0Fz0xg3G8g3zwGt2y/12kBo+6m25di5TrOXaZB053IHuh/b4Wytxai5voqvnw/iaIOlQYw+d3swZuxI99o11c/jB5oHdqzgwqV4lLsF6OrvWHaWBOXDGu02wv0YbW1VPf9qg4qrjl0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734621069; c=relaxed/simple; bh=yGTIs/EKjFkM6KUjXgNR/dSGhVhfIj5acfUAd2KLinI=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=kIUmJDTNrplb8UynfnanBUu5OmwwQvJvaG2Qh06diorjTYHE2EswF6KYu6fokEangWzyMbazh6+g3Gp2f6gcLgwWLoZNoTDRox902j1hzO4Ts7DhZx/X7jfkJJ/xbIdHXiKIVdsojldlr0dl9KGUHgkJpzgdI/6w1Wy96QMoiUg= 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=HKKxdaTI; 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="HKKxdaTI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734621067; 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=Iu7fhtXPcdFzC/hegaXQPvjqwvRi2n+6vI2yRsHarTI=; b=HKKxdaTIMXYhZmcwmyXTwWYOnwNBWrmQDbRRVT8bpskcR/5izW9kZSTyyheRTzh4fYMO+M ekloIiJSFy7p1O1YuC5LNG8IjUTk6fH1L4cxyajoU48FgLJl0akt7c9hmNjZrqPniXbbdL T5+i8XhFwkf1p2WhJj/9vKTqm2UjEbg= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-E2NH2xFdMmGaGAqC1aJAgw-1; Thu, 19 Dec 2024 10:11:05 -0500 X-MC-Unique: E2NH2xFdMmGaGAqC1aJAgw-1 X-Mimecast-MFC-AGG-ID: E2NH2xFdMmGaGAqC1aJAgw Received: by mail-il1-f199.google.com with SMTP id e9e14a558f8ab-3a91a13f63fso7733295ab.3 for ; Thu, 19 Dec 2024 07:11:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734621065; x=1735225865; 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=Iu7fhtXPcdFzC/hegaXQPvjqwvRi2n+6vI2yRsHarTI=; b=An48g20wZ0sbfCQ8Zt76IQCP4XoNVHsMpm5gri8gAinc6XKCTtI7vNyH4Pv65I6NUP 6S5jtfp5tAOCJmi3M6dbfnJ1OdmIONgIm8u66cq9rOuTYdlfv6UOn6dZJjIgEFchKwJB nnDSw1VOsrBFY3ski3HG4T7LBc+zpOYkLkfoahWPhzmY2WOSBdh1m1BDyWrttrLDAAHY a3n52wb9o99LSR5DELOamWOmW5PwXhBPLZwxf6sz2M737i/pK3ZF3vW39ucOHooaVq00 h28JFI9vFMDe1N7JCCxqnwxPC4zBoKRigFJtFvErWQLtNBlX4Wuc4jznYebW5jmOE0Gp 0C9Q== X-Forwarded-Encrypted: i=1; AJvYcCVJ4EhHvRun2Rd7CO2VJ9+cfgWrjiNoDNGNT1YAXZpYs7DUA6Iu8GLGt4D9yaTZVihyL8STFy4SfDoYc9A=@vger.kernel.org X-Gm-Message-State: AOJu0YxHsT+/k2c/MjwQQqB2062rbkeVG6kmJvZgAhzmDGWNagFzvtJ8 9tpQL1BeJXCzX1m4LezJAevNeO5XriJyfTZVYywmmnQ6OAp1WKcV1HYNz4Io8bkyQLyXQtiUkVe DilKYEIzge0GXFRZVK5H5dH1uiQsMf6fFMky24vLRM+vfVZZO5GfVsugYVjex7w== X-Gm-Gg: ASbGnctnN+kR/Nnkb1GRBffozLwdPKsONxf/mEruakNHnWQMPyVuQ/R4RUS0f30S4mR mXB6iTQWL3WfSRGtgbYIFPwY39wa5OfiV5k/kUnDO9TcwiGDHBazobhN7wtV48ohy4otncDKBdx c4jiUZXDpcqSI7Mzy/pZe0Egs5G/sTgS41GiZS6AO9N3VwCN8A+xo6E3DRR9XF/5trf5auWvrKU hR2t3kj85S6+DcUlmJj8EIrGAv3yJgb5f0eto2vXkGKDJKahDcsL9l3 X-Received: by 2002:a05:6e02:12cd:b0:3ab:1b7a:593e with SMTP id e9e14a558f8ab-3bdc4659f97mr75083215ab.19.1734621065043; Thu, 19 Dec 2024 07:11:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfj0tO6tQB6lCjORiyzYKcsLEPLUe8+lv6dV1/+NEgzmo1+7Uv6bzv3dCbpIvc8MYawsVBAg== X-Received: by 2002:a05:6e02:12cd:b0:3ab:1b7a:593e with SMTP id e9e14a558f8ab-3bdc4659f97mr75082875ab.19.1734621064740; Thu, 19 Dec 2024 07:11:04 -0800 (PST) Received: from starship ([2607:fea8:fc01:8d8d:6adb:55ff:feaa:b156]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e68bf5073dsm322423173.29.2024.12.19.07.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 07:11:04 -0800 (PST) Message-ID: <9d4aa4b90ee005683c14ddcaba28c11f35cf9e6b.camel@redhat.com> Subject: Re: [PATCH 02/20] KVM: selftests: Sync dirty_log_test iteration to guest *before* resuming From: Maxim Levitsky To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu Date: Thu, 19 Dec 2024 10:11:03 -0500 In-Reply-To: References: <20241214010721.2356923-1-seanjc@google.com> <20241214010721.2356923-3-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 Wed, 2024-12-18 at 13:36 -0800, Sean Christopherson wrote: > On Tue, Dec 17, 2024, Maxim Levitsky wrote: > > On Fri, 2024-12-13 at 17:07 -0800, Sean Christopherson wrote: > > > 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); > > > > AFAIK, this patch doesn't 100% gurantee that this won't happen: > > > > The READ_ONCE that guest uses only guarntees no wierd compiler optimizations > > are used. The guest can still read the iteration value to a register, get > > #vmexit, after which the iteration will be increased and then write the old > > value. > > Hmm, right, it's not 100% guaranteed because of the register caching angle. But > it does guarantee that at most only write can retire with the previous iteration, > and patch 1 from you addresses that issue, so I think this is solid? > > Assuming we end up going with the "collect everything for the current iteration", > I'll expand the changelog to call out the dependency along with exactly what > protection this does and does not provide > > > Is this worth to reorder this to decrease the chances of this happening? I am > > not sure, as this will just make this problem rarer and thus harder to debug. > > Currently the test just assumes that this can happen and deals with this. > > The test deals with it by effectively disabling verification. IMO, that's just > hacking around a bug. > OK, let it be, but the changelog needs to be updated to state that the race is still possible. Best regards, Maxim Levitsky