Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3158042rdb; Thu, 16 Nov 2023 01:36:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNR7N6urpER6S4v6P6z0KavjiSnFjTvPFQqeiKITgcVqLonIZ5HJLKOw7Yiiep7mYoNhJR X-Received: by 2002:a05:6870:1710:b0:1e9:bba3:4902 with SMTP id h16-20020a056870171000b001e9bba34902mr19114120oae.37.1700127371868; Thu, 16 Nov 2023 01:36:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700127371; cv=none; d=google.com; s=arc-20160816; b=RTILsPeFnMOKQIaABD+IIXuol8nk3g5j5wxdjlTS36cLHKp8sHT4PGCylAcRa9AjqB EsdDvwnbwTPxJwE/JphZAdQ11o/BzBfXBz/DIM+orbXPR6BnvNtflWlSY8mi/2riMMdj W9L0SVq+3+nlq8i1EKrx5IBtdhxF4T0kFKVTLblUKBO2060fjn9sXB/0Hr8Tpfwcjc8M PMJ5MhdvmD/WMuSUHFndc+kjOiO2KyLJgLq5o0dPgGkESbzv2oLc10BnMzbIVqriUSlA oAIGy8WwGLBPrrCgPLpM6++SBn+AI4wNTlC9aYXuL2hkAmgxkRBigU39ZVowzbuAuCxL ez8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=s14OcYbNsy58OOft6vgyTif8IMy6gRwapu3+F+eWkNg=; fh=X9WnwKkDfPYglX9NYtmkULqN2hpGKtAxg+ZpXZqA9NA=; b=ADYa+ReU93O1zGOpYiL7vMBL9N2N1+yp0Gw43k+Fpw5RtU1vuWA2OdbrQzpJ7Hex8f L+Gfp/sAOUJ0U9U+AgSpS+F0IEulMc6BylHxBlvDkopaHHMXK9nja7+9DdFtnW+Fa9+E M7Q8meRVN5xBr7wnN7m02vJt4O/aMIlwRcV3R+cuZjOBvX0kkmWlcqZ8ABl0mUatl8Xo Hev+rx5FnbjqbO7W/SzKebK53qbB/+s7RVwmt/iX5foRgBrp1lOibOsgbRSdhHzcOY5n h8ZzYUIptHqORtjCJ5YEOcXfvXPQnrn8y+rGo1fo15QWO89lqvFPg7G9WK+/ucf/jTv5 r5HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ehhQ/B6F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ay36-20020a056a00302400b006a15afe16c2si12044679pfb.296.2023.11.16.01.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 01:36:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ehhQ/B6F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 71BD280E854D; Thu, 16 Nov 2023 01:36:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235710AbjKPJft (ORCPT + 99 others); Thu, 16 Nov 2023 04:35:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235704AbjKPJfs (ORCPT ); Thu, 16 Nov 2023 04:35:48 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB6201B2 for ; Thu, 16 Nov 2023 01:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700127344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=s14OcYbNsy58OOft6vgyTif8IMy6gRwapu3+F+eWkNg=; b=ehhQ/B6FKHWG292AKpMVZMsJgkfdtL4W4wvZaOJetIKS23Zv1ea8cJ2GWKen+EOGkqRDAA sw0a/ghggmqmYMoDoduMS7QVr5yPHYXiSTNHVNJFDKJUWGJpTkI0kTajxt/j0dmK34sRDu darOguP50PPVrgXe2w74v7jOmQRhvtM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-_SrAnAy-M1iDTKAzeIVejQ-1; Thu, 16 Nov 2023 04:35:40 -0500 X-MC-Unique: _SrAnAy-M1iDTKAzeIVejQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EAF7185A780; Thu, 16 Nov 2023 09:35:40 +0000 (UTC) Received: from virt-mtcollins-01.lab.eng.rdu2.redhat.com (virt-mtcollins-01.lab.eng.rdu2.redhat.com [10.8.1.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34BF5492BFD; Thu, 16 Nov 2023 09:35:40 +0000 (UTC) From: Shaoqin Huang To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Shaoqin Huang , Paolo Bonzini , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] KVM: selftests: Initalize sem_vcpu_[cont|stop] before each test in dirty_log_test Date: Thu, 16 Nov 2023 04:35:36 -0500 Message-Id: <20231116093536.22256-1-shahuang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 16 Nov 2023 01:36:03 -0800 (PST) When execute the dirty_log_test on some aarch64 machine, it sometimes trigger the ASSERT: ==== Test Assertion Failure ==== dirty_log_test.c:384: dirty_ring_vcpu_ring_full pid=14854 tid=14854 errno=22 - Invalid argument 1 0x00000000004033eb: dirty_ring_collect_dirty_pages at dirty_log_test.c:384 2 0x0000000000402d27: log_mode_collect_dirty_pages at dirty_log_test.c:505 3 (inlined by) run_test at dirty_log_test.c:802 4 0x0000000000403dc7: for_each_guest_mode at guest_modes.c:100 5 0x0000000000401dff: main at dirty_log_test.c:941 (discriminator 3) 6 0x0000ffff9be173c7: ?? ??:0 7 0x0000ffff9be1749f: ?? ??:0 8 0x000000000040206f: _start at ??:? Didn't continue vcpu even without ring full The dirty_log_test fails when execute the dirty-ring test, this is because the sem_vcpu_cont and the sem_vcpu_stop is non-zero value when execute the dirty_ring_collect_dirty_pages() function. When those two sem_t variables are non-zero, the dirty_ring_wait_vcpu() at the beginning of the dirty_ring_collect_dirty_pages() will not wait for the vcpu to stop, but continue to execute the following code. In this case, before vcpu stop, if the dirty_ring_vcpu_ring_full is true, and the dirty_ring_collect_dirty_pages() has passed the check for the dirty_ring_vcpu_ring_full but hasn't execute the check for the continued_vcpu, the vcpu stop, and set the dirty_ring_vcpu_ring_full to false. Then dirty_ring_collect_dirty_pages() will trigger the ASSERT. Why sem_vcpu_cont and sem_vcpu_stop can be non-zero value? It's because the dirty_ring_before_vcpu_join() execute the sem_post(&sem_vcpu_cont) at the end of each dirty-ring test. It can cause two cases: 1. sem_vcpu_cont be non-zero. When we set the host_quit to be true, the vcpu_worker directly see the host_quit to be true, it quit. So the log_mode_before_vcpu_join() function will set the sem_vcpu_cont to 1, since the vcpu_worker has quit, it won't consume it. 2. sem_vcpu_stop be non-zero. When we set the host_quit to be true, the vcpu_worker has entered the guest state, the next time it exit from guest state, it will set the sem_vcpu_stop to 1, and then see the host_quit, no one will consume the sem_vcpu_stop. When execute more and more dirty-ring tests, the sem_vcpu_cont and sem_vcpu_stop can be larger and larger, which makes many code paths don't wait for the sem_t. Thus finally cause the problem. Fix this problem is easy, simply initialize the sem_t before every test. Thus whatever the state previous test left, it won't interfere the next test. Signed-off-by: Shaoqin Huang --- tools/testing/selftests/kvm/dirty_log_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 936f3a8d1b83..23b179534c0b 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -726,6 +726,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) return; } + sem_init(&sem_vcpu_stop, 0, 0); + sem_init(&sem_vcpu_cont, 0, 0); + /* * We reserve page table for 2 times of extra dirty mem which * will definitely cover the original (1G+) test range. Here @@ -871,9 +874,6 @@ int main(int argc, char *argv[]) int opt, i; sigset_t sigset; - sem_init(&sem_vcpu_stop, 0, 0); - sem_init(&sem_vcpu_cont, 0, 0); - guest_modes_append_default(); while ((opt = getopt(argc, argv, "c:hi:I:p:m:M:")) != -1) { -- 2.40.1