lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 18 Mar 2022 15:23:43 -0400
From:   Gabriel Krisman Bertazi <krisman@...labora.com>
To:     Muhammad Usama Anjum <usama.anjum@...labora.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Shuah Khan <shuah@...nel.org>, kernel@...labora.com,
        david@...hat.com, Will Deacon <will@...nel.org>,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        linux-kselftest@...r.kernel.org
Subject: Re: [PATCH V5 2/2] selftests: vm: Add test for Soft-Dirty PTE bit

Muhammad Usama Anjum <usama.anjum@...labora.com> 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 <stdio.h>
> +#include <string.h>
> +#include <stdbool.h>
> +#include <fcntl.h>
> +#include <stdint.h>
> +#include <malloc.h>
> +#include <sys/mman.h>
> +#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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ