From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D56B1E489 for ; Tue, 17 Dec 2024 23:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734479940; cv=none; b=lFUgngjlLMtDhWLEiz+dOKrTk36x7bocYPnW5Edh79lUOJoAIYACFRdSAxJOKva0UYQFtXUPedQ+Vdrgazq9VMdS5WfYSv1C9i/2Rj12n0W1xWIS4ZmIK9KlxLTteTALfh9P8MDeH+iknGUZlSbKoUz+DRGn7nyzlEoDBLmZ/DI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734479940; c=relaxed/simple; bh=253X2/Ygyqv2mDIgmCRCiJ2f6echdqbAGCfdLInW6S8=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=bjS/8GEk1An/Zr0oGmMKszuiOKYNqjzr9ZvwtLu1uRfxgtHBUrJDV0HzpejPKsT4blwdKRw8YRz9Qm9IplBrmOgUc+srjmJsT2z4KlkYjUHVsuQdaTxrHnFG1XPXPHmCsGhEd/+WUKdg2sAvqPzLMYRnBB/v7QiUgUVzWYaxEEQ= 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=LjGq7mLW; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LjGq7mLW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734479937; 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=ctAzpqF3UG/0IGfBE9fGS9dSSJ927UqahSGZ4siHpoA=; b=LjGq7mLWdjgi/UDdYXnaZY8yy34NWCx50YjYWphXMvanjgseRr5ozZkw/ShUPiBfjB5Pvg iymzKIHowDSimR7sO6BNZ9XwwYjhrXuePt6Pzb4H74yLh1bHBFnYbfgXi919BC9/RGIRE+ DXDd68ZmSgnqB1wXOeeQz2VKCheaVC8= 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-124-82IFi2T7PP6fbnYX44Q_ig-1; Tue, 17 Dec 2024 18:58:56 -0500 X-MC-Unique: 82IFi2T7PP6fbnYX44Q_ig-1 X-Mimecast-MFC-AGG-ID: 82IFi2T7PP6fbnYX44Q_ig Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a817be161bso2510565ab.1 for ; Tue, 17 Dec 2024 15:58:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734479935; x=1735084735; 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=ctAzpqF3UG/0IGfBE9fGS9dSSJ927UqahSGZ4siHpoA=; b=HXCGOpcSnwUcCVmZh+gWsAuj7LVXDaH7HNr8IbxeShLp1dRCcJF+Kf67/uPfRFuy+G xGcevDqG2cfqpX+MgQafNCM+3XDYDf1rlRdIOVMVreVLPizl2e00dDLbxMtAHCBFa/9G 7APFrpkaiZDZoQsvps+PC4py0zasDlmWUGHf2EfvRK9OfF+wOOZTNJhNMTFzEzMgfMJX zhrt+p7v4aBdEmWwjWFOM4AoeE5bFP/ygjCwUvqcuql004skvTl5QPnMz2unEezq319d 3zhWf5DnfYuo0vigMCcy+mr/rTfYO1WxLeYijX/tm9dTp59TbjlwjbLDEAYC3d0uj789 aSEA== X-Forwarded-Encrypted: i=1; AJvYcCVCP+/7kZiDEj524dNy0azATjUMCsdlWoOCNyZpGtplILJbUwpMckEcldm8pm7BSnTCOlZGQHWe0I/+FUE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/Ar41IWpaEQw1VmEqg+PelVuS3b7MfoGRMKHYbQGdV6epnwOU RRPrlm318eDdyF4Qqxg1ZO9YmKFekOm4N91mEuQ5vnmVbPIBO8otNW2hKkI9hKnSIKAlH3AVMv1 Jsz8k/i6sSESzE7LsfW54qPJMrLss6UF0YE4a9S6wkm9UetDI9gneF1HUv6Gwfw== X-Gm-Gg: ASbGncs+T7qN0FtEj6aNSo9tjeOzsllbZMdaDSNe69hUm5eZ2AD59kDWNKo+insuyMW ExzQuksy1fENelpN20qjWtOV/hwJJcRG9wG/vP/qqF7qdbQNOvdNE7SmxrRGPf1zOmfoKwpfrgM /7Y2W04ZE8A+CTYH9rMNWSIQbSkrYBFo9np58vKOX88ddMYp0onkqatn16BplTt5sNatm4/Z1Wb 5oGY76DtdhU2jX5pDYO7DVrW4aYC/h+KTqAFzY1LazFFUo3rV04qV/J X-Received: by 2002:a05:6e02:1c81:b0:3a7:7bab:33f8 with SMTP id e9e14a558f8ab-3bb0ac12cbamr52792865ab.12.1734479935333; Tue, 17 Dec 2024 15:58:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGA+uenBegmVd3ZbmklJV5z9+lx0na5Cd6JyRPWDb28FbNFSzXQThlGzm9jXpNBxqxJhvkv+Q== X-Received: by 2002:a05:6e02:1c81:b0:3a7:7bab:33f8 with SMTP id e9e14a558f8ab-3bb0ac12cbamr52792705ab.12.1734479935042; Tue, 17 Dec 2024 15:58:55 -0800 (PST) Received: from starship ([2607:fea8:fc01:8d8d:6adb:55ff:feaa:b156]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e5e3c69e42sm1901805173.156.2024.12.17.15.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 15:58:54 -0800 (PST) Message-ID: Subject: Re: [PATCH 02/20] KVM: selftests: Sync dirty_log_test iteration to guest *before* resuming 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 18:58:53 -0500 In-Reply-To: <20241214010721.2356923-3-seanjc@google.com> 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 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. 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. Best regards, Maxim Levitsky