From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 723BBC433EF for ; Fri, 18 Mar 2022 19:23:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF9168D0002; Fri, 18 Mar 2022 15:23:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA8098D0001; Fri, 18 Mar 2022 15:23:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6FE08D0002; Fri, 18 Mar 2022 15:23:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id A5A808D0001 for ; Fri, 18 Mar 2022 15:23:50 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6D6616092B for ; Fri, 18 Mar 2022 19:23:50 +0000 (UTC) X-FDA: 79258481820.03.D62AD2E Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf05.hostedemail.com (Postfix) with ESMTP id 9A3B7100021 for ; Fri, 18 Mar 2022 19:23:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id EF71D1F45C19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1647631428; bh=WlSxsl1AsukIIoT+HgzKCmviZWgGsHJPvRrOsuv2jMo=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=jM4edW6w09UWqtmSOGEzQOsPEfY7cXe6gIGCHOxMZ8c6Hv82Sf4WL9YJL10v99060 4w8ErN+CrDUNSGP6uJBC3TycxdVc28S5a/5RB3ENmDEH/FBNF9sYd+Hk0kZfLuYtdI htUPBgQvPM215lCR+lJ6iLDxdi+E2MeIGtiFqAcM6t6lhqazkBrThN0cAOSVvQk1p3 dJIRPlMw2Z/9nWO4cnp78zSe8R0Llz4N9v6cI9Yrj4hCgiOGFYvxzUWojB3LaMFob3 1rTZdwbc5zeeWClc/PQELSFfvpaH1bnfX7D+jYg/e87DrpoprnTCE1NjOk4YPVE1iW EZ4Ynd4Mw6Xjw== From: Gabriel Krisman Bertazi To: Muhammad Usama Anjum Cc: Andrew Morton , Shuah Khan , kernel@collabora.com, david@redhat.com, Will Deacon , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH V5 2/2] selftests: vm: Add test for Soft-Dirty PTE bit Organization: Collabora References: <20220317103323.94799-1-usama.anjum@collabora.com> <20220317103323.94799-2-usama.anjum@collabora.com> Date: Fri, 18 Mar 2022 15:23:43 -0400 In-Reply-To: <20220317103323.94799-2-usama.anjum@collabora.com> (Muhammad Usama Anjum's message of "Thu, 17 Mar 2022 15:33:22 +0500") Message-ID: <87ilsbyshs.fsf@collabora.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Rspam-User: X-Rspamd-Queue-Id: 9A3B7100021 X-Stat-Signature: hesnw9bnxamog17w7q96n4pgyiss1yje Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=jM4edW6w; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf05.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-Rspamd-Server: rspam03 X-HE-Tag: 1647631429-329179 X-Bogosity: Ham, tests=bogofilter, spamicity=0.002159, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Muhammad Usama Anjum writes: > new file mode 100644 > index 0000000000000..3153ebac6909b > --- /dev/null > +++ b/tools/testing/selftests/vm/soft-dirty.c > @@ -0,0 +1,146 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "../kselftest.h" > +#include "vm_util.h" > + > +#define PAGEMAP_FILE_PATH "/proc/self/pagemap" > +#define TEST_ITERATIONS 10000 > + > +static void test_simple(int pagemap_fd, int pagesize) > +{ > + int i; > + char *map; > + > + map = aligned_alloc(pagesize, pagesize); > + if (!map) > + ksft_exit_fail_msg("mmap failed\n"); > + > + clear_softdirty(); > + > + for (i = 0 ; i < TEST_ITERATIONS; i++) { > + if (pagemap_is_softdirty(pagemap_fd, map) == 1) { > + ksft_print_msg("dirty bit was 1, but should be 0 (i=%d)\n", i); > + break; > + } > + > + clear_softdirty(); > + // Write something to the page to get the dirty bit enabled on the page > + map[0] = i % 255; you don't need this mod at all but at least it should be 256 :). I think Either 'map[0] = !map[0]' or keeping the original 'map[0]++' is fine. > + > + if (pagemap_is_softdirty(pagemap_fd, map) == 0) { > + ksft_print_msg("dirty bit was 0, but should be 1 (i=%d)\n", i); > + break; > + } > + > + clear_softdirty(); > + } > + free(map); > + > + ksft_test_result(i == TEST_ITERATIONS, "Test %s\n", __func__); > +} > + > +static void test_vma_reuse(int pagemap_fd, int pagesize) > +{ > + char *map, *map2; > + > + map = mmap(NULL, pagesize, (PROT_READ | PROT_WRITE), (MAP_PRIVATE | MAP_ANON), -1, 0); > + if (map == MAP_FAILED) > + ksft_exit_fail_msg("mmap failed"); > + > + clear_softdirty(); > + > + /* Write to the page before unmapping and map the same size region again to check > + * if same memory region is gotten next time and if dirty bit is preserved across > + * this type of allocations. > + */ This reads weird. It should *not* be preserved across different mappings. Also, we are not testing if the same region is reused, we are depending on it to test the sd bit. /* Ensures the soft-dirty bit is reset accross different mappings on the same address. */ > + map[0]++; This is inconsistent with the other two tests. > + > + munmap(map, pagesize); > + > + map2 = mmap(NULL, pagesize, (PROT_READ | PROT_WRITE), (MAP_PRIVATE | MAP_ANON), -1, 0); > + if (map2 == MAP_FAILED) > + ksft_exit_fail_msg("mmap failed"); > + > + ksft_test_result(map == map2, "Test %s reused memory location\n", __func__); if map != map2, the test itself is broken, meaning we should skip it, not fail, i guess. -- Gabriel Krisman Bertazi