Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3450609rdb; Thu, 16 Nov 2023 09:44:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IG35F/XE76CV6y5Vjtf80w3YlALi3kdJkDjpynIlJVyc1z/6rPk6nvnun8hfZZXPAMdHVdo X-Received: by 2002:a17:902:bd4c:b0:1ce:8ed:2378 with SMTP id b12-20020a170902bd4c00b001ce08ed2378mr9705002plx.1.1700156647724; Thu, 16 Nov 2023 09:44:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700156647; cv=none; d=google.com; s=arc-20160816; b=AXlLgUu9vmDP2x1YO/+X3l7cg0YedClo3G9xvo9EPwW0GfbOKGeJDbNWqpbNE8s073 LS9n+E8CDJKpvgiii9IXxjOooQ+xYfVcNY9G9kUBuD/dAvBXe+Zsj/kpCFt9r7ScWn0B ybEYEcIHpaXPaTDDNk222ffbNlsPBJjuOxZa48eaWfMFDBzHuttDheYMnmoSWoj8douV iftnbgwJYQeHh0GJ1TaHLuPIZD3YE+mUNOhfdpyYc/KOwlAkci3nBi64VkkANdWdJg7r hcqhtv3+gxQWEvB80tp/YQ9Ik6uJkJP2ncRQH578h83eIlkRvEdm5ZM1UAb6UBm7zZvp Voww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=IsFJXxQHB5dGIDDamYKJ45Gko1PeTH7Pv3KoMdEvZ7g=; fh=xzMGM4da3g+492HKPG07mhHd8FeZWCZdfdmfzuWgRQQ=; b=cm+FVpSi58Gxi+lvi7aST3IQnxlGMd/n/mHyZozcTDZFldlCI+3kUDYJFykVQfENYa 40oUmmnECG6BB0NecBFjDCnaNuuC+z3/Udvi+k8GlCZsHfEaAYOiZfV2u9dQhTXWm0iP fpwirkPrlz3LneHXC0V7pVRTSdUq6P/h61JTMaW7wxSzYxEMVFmL1JcugbzGvikG4J29 N5/ZYB5BOoxRlV6jga+vuISsPNFZl6c2NUIpaDgXJ5iY/UNr7kJfWHJ8SMduZ3oUAgkN lSADBFLYWD2r2MMBOZBuy1EsS3GIjTSUbUrqMYOcSnhTPugHu74Q+wRzE88belWu7GHq yDkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bg12-20020a1709028e8c00b001c73626a1ffsi1249039plb.412.2023.11.16.09.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 09:44:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3992981C9A51; Thu, 16 Nov 2023 09:44:05 -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 S1345040AbjKPRn6 (ORCPT + 99 others); Thu, 16 Nov 2023 12:43:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjKPRn5 (ORCPT ); Thu, 16 Nov 2023 12:43:57 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62735A5 for ; Thu, 16 Nov 2023 09:43:52 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DB40A1595; Thu, 16 Nov 2023 09:44:37 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A2A733F6C4; Thu, 16 Nov 2023 09:43:50 -0800 (PST) Message-ID: Date: Thu, 16 Nov 2023 17:43:49 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommufd/selftest: Fix dirty_bitmap tests Content-Language: en-GB To: Joao Martins , kevin.tian@intel.com, jgg@ziepe.ca Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <90e083045243ef407dd592bb1deec89cd1f4ddf2.1700153535.git.robin.murphy@arm.com> <72f0e75b-6c91-4c17-beb2-3f198ed05cd0@oracle.com> From: Robin Murphy In-Reply-To: <72f0e75b-6c91-4c17-beb2-3f198ed05cd0@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=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 09:44:05 -0800 (PST) On 16/11/2023 5:28 pm, Joao Martins wrote: > On 16/11/2023 16:52, Robin Murphy wrote: >> The ASSERT_EQ() macro sneakily expands to two statements, so the loop >> here needs braces to ensure it captures both and actually terminates the >> test upon failure. > > Ugh > >> Where these tests are currently failing on my arm64 >> machine, this reduces the number of logged lines from a rather >> unreasonable ~197,000 down to 10. While we're at it, we can also clean >> up the tautologous "count" calculations whose assertions can never fail >> unless mathematics and/or the C language become fundamentally broken. >> >> Fixes: a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") >> Signed-off-by: Robin Murphy > > I was going to say that the second assert is useful, but we are already test the > number of bits we set against what the mock domain set after > mock_domain_set_dirty(). So the second is redundantly testing the same, and can > be removed as you are doing. Thanks for fixing this. Yeah, it's still effectively just counting half the number of loop iterations executed, but since there's no control flow that could exit the loop early and still reach the assertion, it must always be true following the previous assertion that out_dirty == nr == nbits/2. > I would suggest the subject to: > > iommufd/selftest: Fix _test_mock_dirty_bitmaps() > > Because dirty-bitmap tests seems to imply the whole fixture, which covers more > than the bitmaps. Sure, that sounds reasonable. Jason, Kevin, would you want a v2 for that or could it be fixed up when applying? >> --- >> tools/testing/selftests/iommu/iommufd_utils.h | 13 ++++++------- >> 1 file changed, 6 insertions(+), 7 deletions(-) >> >> diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h >> index 050e9751321c..ad9202335656 100644 >> --- a/tools/testing/selftests/iommu/iommufd_utils.h >> +++ b/tools/testing/selftests/iommu/iommufd_utils.h >> @@ -293,15 +293,13 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length, >> __u64 bitmap_size, __u32 flags, >> struct __test_metadata *_metadata) >> { >> - unsigned long i, count, nbits = bitmap_size * BITS_PER_BYTE; >> + unsigned long i, nbits = bitmap_size * BITS_PER_BYTE; >> unsigned long nr = nbits / 2; >> __u64 out_dirty = 0; >> >> /* Mark all even bits as dirty in the mock domain */ >> - for (count = 0, i = 0; i < nbits; count += !(i % 2), i++) >> - if (!(i % 2)) >> - set_bit(i, (unsigned long *)bitmap); >> - ASSERT_EQ(nr, count); >> + for (i = 0; i < nbits; i += 2) >> + set_bit(i, (unsigned long *)bitmap); >> >> test_cmd_mock_domain_set_dirty(fd, hwpt_id, length, iova, page_size, >> bitmap, &out_dirty); >> @@ -311,9 +309,10 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length, >> memset(bitmap, 0, bitmap_size); >> test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap, >> flags); >> - for (count = 0, i = 0; i < nbits; count += !(i % 2), i++) >> + /* Beware ASSERT_EQ() is two statements -- braces are not redundant! */ >> + for (i = 0; i < nbits; i++) { >> ASSERT_EQ(!(i % 2), test_bit(i, (unsigned long *)bitmap)); >> - ASSERT_EQ(count, out_dirty); >> + } >> >> memset(bitmap, 0, bitmap_size); >> test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap, > > Reviewed-by: Joao Martins > Tested-by: Joao Martins Thanks! Robin.