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 5CBC61F9F79 for ; Tue, 17 Dec 2024 23:59:55 +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=1734479998; cv=none; b=VkIw9o8AJFx8sXjrdpgPl/XylMFvz2LgqzhBoFuX/ywHUAhl51Wf55WpZIKH/P1lg+j75kA8al46q0LuTvRU0teenHydQqcBTK9Tdgygx3nx9V13jSEgr9tQaOWQmIzMzEiL0nG70LpAK4tzI2KZJhqhSU4Ubq4qvDVymj5ztII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734479998; c=relaxed/simple; bh=fsAyV5klwA3VGeTat+gH7+ziK6NrS00UgT0xJ1bDgjE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=ke9+BCamHI87Zui6IXH1qUZSqOc/nIFn3zDTEw+HlsuqqgNJC1SrSpKVW+KJjNLIiqc7KpASCrmckW3DUakzMVhgf5lqaTscvPtH8hYH/bWQSX3mPW279f4yBY4DYa1INB8BGg+j6Q1f9gVGBPE7vMlyS81Lt+zToPIYTUDoC/w= 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=D0hOVvW1; 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="D0hOVvW1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734479995; 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=3XICajvF+UE5msVoxqjl7D4goByHARb39vCTHT5As9o=; b=D0hOVvW1g8v4S1cXKGe8aqstxAPmVIlwBlxeiWGLdC2PGfdnqr/GjvTkdbmn3aXU84CSoh HLbTnyKug/uGlG4lVSPuNfRHEYncEtif9NL/I07bdngoZdEVwU2SDG7hOj9Ivue/5Dh28s SXt8jK5d6jgekOZTu/Q5V8hn2Z31uc8= 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-427-HrWDVvz6Ob6KsFfMzHMmhA-1; Tue, 17 Dec 2024 18:59:53 -0500 X-MC-Unique: HrWDVvz6Ob6KsFfMzHMmhA-1 X-Mimecast-MFC-AGG-ID: HrWDVvz6Ob6KsFfMzHMmhA Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a81357cdc7so2563705ab.1 for ; Tue, 17 Dec 2024 15:59:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734479993; x=1735084793; 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=3XICajvF+UE5msVoxqjl7D4goByHARb39vCTHT5As9o=; b=L7+U+oPY4+gD+0waeg0y29v+rcEBLL6SYnjMyf8XcKi8xWkPiuEXY0xNfg1+EOJ79U AoEPSRp7WhaY1NjxUl0/qI5kKhcFQOw7hKb5rZHgNfCCypfUR+k3T7d5DWuO8dEH7xAB YxCgvHOu2QKl6Vqp0TLIcuECtMR0zTwNA2jauh8SLlq546tDpnfl/EotAvT7ok5337Ml 17y9rTBMhRW2ueDU5c6DaczhHXNzb9dSJWeC5uj2aA+opdRmaABneM/6NhiWPg5Pf9fA io5hoRRunJ0Xjh4I07JEH6oQTn4OT6ng4+DnihEhEHqcDSYd9eXKpmAn52lICJn7ufOH c8mQ== X-Forwarded-Encrypted: i=1; AJvYcCUhkCRx68clqsnTLmHNJW5qSsKGvCV9hQen4u8FvAgZ/4m6jLa15lzMSjsBFHFVJo0gBgw6ZtnHOKBCbNM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywgobuzqv/ASeTiVfhMQhPLSfiRBwaVVeMQyiJ87ehmfsh6gr9F d9O7n9/l1fbk9eLEWV/WzDLjKmp20G5xoQ2DK2pXV7nOoE57hXGzTyjtPW4Gov0iJyqfI4fHmgF Ug2cSEdaWQwIJJJQ9IlaJu+8yfShfYIiTSenLXxyObetG0mgTR9MlWeEgyinPPA== X-Gm-Gg: ASbGncsytc1ZWOPgmRNshCL7NQwJM/vR9WyDsZjSvj4HCFoke4KI1S1Z0khypuyuDK5 cgqn6ZnOubZCeOPJqEWqMSnWaKpSXCCl3fhfA8iNVsVHG25K4Xz8/NEKIWOZmokd+Qx4cemCMbv 0FqqkRI23pKuWPOrJT1hIyLT00218lLscKSYI9SpKY9ovIKu4ExRPONVaIQ6/lu/96ebUe57lMA zofyf3MXG8HcF+Yn9X8GN+mvwzECjFla7QMPxgtEth1lVMK2NfKk7QT X-Received: by 2002:a92:c145:0:b0:3a8:13d5:bd2c with SMTP id e9e14a558f8ab-3bb076fd9d6mr48150745ab.2.1734479993203; Tue, 17 Dec 2024 15:59:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhCDMg38v5g9RlVDFusVQ/aIduylu6YABtGkFjlLrb/bza5klf0U79dLAhaVsglSJoEdEX8Q== X-Received: by 2002:a92:c145:0:b0:3a8:13d5:bd2c with SMTP id e9e14a558f8ab-3bb076fd9d6mr48150695ab.2.1734479992908; Tue, 17 Dec 2024 15:59:52 -0800 (PST) Received: from starship ([2607:fea8:fc01:8d8d:6adb:55ff:feaa:b156]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e5e378241dsm1890850173.116.2024.12.17.15.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 15:59:52 -0800 (PST) Message-ID: Subject: Re: [PATCH 06/20] KVM: selftests: Read per-page value into local var when verifying 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 18:59:51 -0500 In-Reply-To: <20241214010721.2356923-7-seanjc@google.com> References: <20241214010721.2356923-1-seanjc@google.com> <20241214010721.2356923-7-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: > 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. You should note that there are no functional changes in this patch. Besides this, Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky > > Signed-off-by: Sean Christopherson > --- > 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