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 3BF49C433EF for ; Mon, 25 Jul 2022 14:28:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B254D8E0002; Mon, 25 Jul 2022 10:28:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AADFC8E0001; Mon, 25 Jul 2022 10:28:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 900B68E0002; Mon, 25 Jul 2022 10:28:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7F8938E0001 for ; Mon, 25 Jul 2022 10:28:13 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D8BE1A04E7 for ; Mon, 25 Jul 2022 14:28:13 +0000 (UTC) X-FDA: 79725852066.16.791936A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id B0C861600A4 for ; Mon, 25 Jul 2022 14:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658759292; 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=B8qUcwH3m8y+zN+ipPSVgiWBq6UiorsdAzJX2yubs9Y=; b=HzMncxW66r72xqIQIo4O/ryfvU4YmTAO8w1cFRVUUld3ShyEk3X+TcCIW1xBQaN3QH03av icqLNVzT+Cp2RExs/8TY3HjB09pTCAPFKGEZLxRo/coLGTUFuGmM+VoYk/IKTWTqIiVyue VddQNymJH3IWxzek0NCqkP3xiIBO39s= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-185-Y7OUiv33N4KkDDGM5eR7YA-1; Mon, 25 Jul 2022 10:28:11 -0400 X-MC-Unique: Y7OUiv33N4KkDDGM5eR7YA-1 Received: by mail-wm1-f70.google.com with SMTP id c17-20020a7bc011000000b003a2bfaf8d3dso6283721wmb.0 for ; Mon, 25 Jul 2022 07:28:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=B8qUcwH3m8y+zN+ipPSVgiWBq6UiorsdAzJX2yubs9Y=; b=OjC3PFhDOfzondUuB0Ng4UQqDj7Nc1K5j+p+NzuWgtnIGS0Qj9vtsjDoqyBhuARv7Q Gs0LCOpSnyhshK2tpaedzojql7Aih1Ga6i0KzgYttqLSwje0Ek7H2BYk6holyNg/I7S8 aEyesZTSGMsuDAcG6kSp4f6BDLY8PrH82nwQwJKLGkFR1c84NNA7EfcQDEUByQhAqNzs TYFx2wHWWMJNLZpJuDhLjH/J4mukIZmiWBSxksOT5P+gJN+tLqyJraASgS+D9YPXsNUK 8Qm4oWgVZUxBEG4Oon3oettkoASHjyN3RkkAdjFLo0EqUDz9Z/y7FvOern/Vzm7KEWbf yQuw== X-Gm-Message-State: AJIora/Oe5ldnzTXBrVNsHi6FRR26HHv42i5QT0H2vr/eRLwTRj9Mfjm 87FfCuv7Kgkp11+TwrS/28jSGdla4cR3gd5qCFSC8229geEkyFp+9R4jBtXm6oGb7WUkCbajGJa nkjsY0Ys46fw= X-Received: by 2002:a05:6000:887:b0:21e:24a0:f302 with SMTP id ca7-20020a056000088700b0021e24a0f302mr7664503wrb.466.1658759289351; Mon, 25 Jul 2022 07:28:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uWK+gDi8Y9cYa3Fq+hzZ2Ca6yCvNRZcmXHipnk9cmDimUYuuoouiW2jcYiUC/HjaTTGykKHQ== X-Received: by 2002:a05:6000:887:b0:21e:24a0:f302 with SMTP id ca7-20020a056000088700b0021e24a0f302mr7664476wrb.466.1658759288799; Mon, 25 Jul 2022 07:28:08 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:8c00:eee4:63f0:cef2:5ac0? (p200300cbc7048c00eee463f0cef25ac0.dip0.t-ipconnect.de. [2003:cb:c704:8c00:eee4:63f0:cef2:5ac0]) by smtp.gmail.com with ESMTPSA id 9-20020a05600c22c900b003a3270735besm14580518wmg.28.2022.07.25.07.28.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jul 2022 07:28:08 -0700 (PDT) Message-ID: <3b85bf1f-2383-7e26-c123-f300027bada0@redhat.com> Date: Mon, 25 Jul 2022 16:28:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v4 2/3] selftests: soft-dirty: Add test for mprotect To: Peter Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Nadav Amit , Andrea Arcangeli , Andrew Morton References: <20220725142048.30450-1-peterx@redhat.com> <20220725142048.30450-3-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220725142048.30450-3-peterx@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HzMncxW6; spf=none (imf08.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658759292; h=from:from:sender: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:dkim-signature; bh=B8qUcwH3m8y+zN+ipPSVgiWBq6UiorsdAzJX2yubs9Y=; b=wciTU4oG1//W2FxWI6EUp7KxUiYDJFym/3fJUB4cMy769uIer/QpHtIxoUrF8mza7UlO5+ 8HxSOECER4lCktJuzVPT55tfMsGc0cbrHhbRNNvmw/uPgFnlgCzV3l9MFaYMVb9upykBQu Y7JhQp6U3UNznEyDVylfkRS/zCNr75k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658759292; a=rsa-sha256; cv=none; b=Pu3Nwi7gh6F7Ra+VpCqti1dUG28AkxtK3ow6kiJq9iq7fZXNqoNQbcLaoFxFGBPh664FJJ uWY2hrOhFgGOm/qSX2yza+CXJsc7a7bFXtRVzB+3SDi5ggvo+4iPZBa1Hxpje3f46uMWoI WLyKUwXRDEqQK9VKQe41T5diinqp1pc= Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HzMncxW6; spf=none (imf08.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Stat-Signature: ig1ejkpw3cse9mtgrgawfdhn5x786pg7 X-Rspamd-Queue-Id: B0C861600A4 X-Rspamd-Server: rspam02 X-HE-Tag: 1658759292-998356 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 25.07.22 16:20, Peter Xu wrote: > Add two soft-dirty test cases for mprotect() on both anon or file. > > Signed-off-by: Peter Xu > --- > tools/testing/selftests/vm/soft-dirty.c | 67 ++++++++++++++++++++++++- > 1 file changed, 66 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/vm/soft-dirty.c b/tools/testing/selftests/vm/soft-dirty.c > index 08ab62a4a9d0..e3a43f5d4fa2 100644 > --- a/tools/testing/selftests/vm/soft-dirty.c > +++ b/tools/testing/selftests/vm/soft-dirty.c > @@ -121,13 +121,76 @@ static void test_hugepage(int pagemap_fd, int pagesize) > free(map); > } > > +static void test_mprotect(int pagemap_fd, int pagesize, bool anon) > +{ > + const char *type[] = {"file", "anon"}; > + const char *fname = "./soft-dirty-test-file"; > + int test_fd; > + char *map; > + > + if (anon) { > + map = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, > + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > + if (!map) > + ksft_exit_fail_msg("anon mmap failed\n"); > + } else { > + test_fd = open(fname, O_RDWR | O_CREAT); > + if (test_fd < 0) { > + ksft_test_result_skip("Test %s open() file failed\n", __func__); > + return; > + } > + unlink(fname); > + ftruncate(test_fd, pagesize); > + map = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, > + MAP_SHARED, test_fd, 0); > + if (!map) > + ksft_exit_fail_msg("file mmap failed\n"); > + } > + > + *map = 1; > + ksft_test_result(pagemap_is_softdirty(pagemap_fd, map) == 1, > + "Test %s-%s dirty bit of new written page\n", > + __func__, type[anon]); > + clear_softdirty(); > + ksft_test_result(pagemap_is_softdirty(pagemap_fd, map) == 0, > + "Test %s-%s soft-dirty clear after clear_refs\n", > + __func__, type[anon]); > + mprotect(map, pagesize, PROT_READ); > + ksft_test_result(pagemap_is_softdirty(pagemap_fd, map) == 0, > + "Test %s-%s soft-dirty clear after marking RO\n", > + __func__, type[anon]); > + mprotect(map, pagesize, PROT_READ|PROT_WRITE); > + ksft_test_result(pagemap_is_softdirty(pagemap_fd, map) == 0, > + "Test %s-%s soft-dirty clear after marking RW\n", > + __func__, type[anon]); > + *map = 2; > + ksft_test_result(pagemap_is_softdirty(pagemap_fd, map) == 1, > + "Test %s-%s soft-dirty after rewritten\n", > + __func__, type[anon]); > + > + munmap(map, pagesize); > + > + if (!anon) > + close(test_fd); > +} > + > +static void test_mprotect_anon(int pagemap_fd, int pagesize) > +{ > + test_mprotect(pagemap_fd, pagesize, true); > +} > + > +static void test_mprotect_file(int pagemap_fd, int pagesize) > +{ > + test_mprotect(pagemap_fd, pagesize, false); > +} > + > int main(int argc, char **argv) > { > int pagemap_fd; > int pagesize; > > ksft_print_header(); > - ksft_set_plan(5); > + ksft_set_plan(15); > > pagemap_fd = open(PAGEMAP_FILE_PATH, O_RDONLY); > if (pagemap_fd < 0) > @@ -138,6 +201,8 @@ int main(int argc, char **argv) > test_simple(pagemap_fd, pagesize); > test_vma_reuse(pagemap_fd, pagesize); > test_hugepage(pagemap_fd, pagesize); > + test_mprotect_anon(pagemap_fd, pagesize); > + test_mprotect_file(pagemap_fd, pagesize); > > close(pagemap_fd); > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb