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 6DB5CC433EF for ; Fri, 22 Jul 2022 13:44:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A1656B0072; Fri, 22 Jul 2022 09:44:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9506D6B0073; Fri, 22 Jul 2022 09:44:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 818B46B0074; Fri, 22 Jul 2022 09:44:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 73AE86B0072 for ; Fri, 22 Jul 2022 09:44:53 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 44FDC1C6779 for ; Fri, 22 Jul 2022 13:44:53 +0000 (UTC) X-FDA: 79714856466.28.C883F81 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 6619B100088 for ; Fri, 22 Jul 2022 13:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658497490; 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: in-reply-to:in-reply-to:references:references; bh=dWRpA1oxrDhiiXkeV9SXJ/F3tpuLhpf/KYwSClNmv+Q=; b=Uusg2UMZY1fOiOM3HjpP07qPeiB9sVa3K0WsCPdp5jCn0boeUXWBCBpNpY3JJgOG3in3P7 9+ZR8yJQyozqfFZbxNp2gvx0tC8j11M9ljjFSmb5ZqyekNVD8vthnGXMc7XL7i/cu4CNaG 4gwBeGv9T9+DuaA9tcmciUCRQ6xP2+E= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-szF5hW4zNA-wsZxPzgZLYQ-1; Fri, 22 Jul 2022 09:44:49 -0400 X-MC-Unique: szF5hW4zNA-wsZxPzgZLYQ-1 Received: by mail-qv1-f71.google.com with SMTP id na10-20020a0562142d4a00b00473fb0f94deso3060751qvb.21 for ; Fri, 22 Jul 2022 06:44:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dWRpA1oxrDhiiXkeV9SXJ/F3tpuLhpf/KYwSClNmv+Q=; b=X0svkdFglUg6Sc+AByHmGbUj7T/RyfTrtaswZD20zOxbX7aBkJTrtcmnm22HKUQKS1 h/J7H1kUnuSs6biOQ3KKUq1XEa3Hk+hM/xvw/8ylnZGj3i5gxRF9MJnjS6ZToZ+PhO5M tcdkcXWyLEI/SGdIz7zArdY1W2kPOnjq3QFzhLikiQH91QVc2tG25OsNbbIhNQQowQJ8 M80Dak+Ae/7GF3PYMirrxeL1CkUWMX47uTpOpF8Wfo6wq9RbImM095MkEbiv56BPVUxR XZw5lj+RBjPNXCVMqJe18rZjCvkVlfpJUvI3DT+g1AHfZMg2Bpwv5tAgz7aQtNJu2kIG WRTg== X-Gm-Message-State: AJIora+WUoQhnJPioXxR2JxuoyaXKuY3sVIBGNid3m8EGgYXmoKRpWfD +7EZ3A8Ai+IamRiuEI6PghMziJl4sGrjjgFWnR15XctPpJBbOhrWe/lmo9kThbH9djFwm7ys6yc igH6hXKdqVt8= X-Received: by 2002:a05:622a:1348:b0:31f:f43:7b0 with SMTP id w8-20020a05622a134800b0031f0f4307b0mr104025qtk.542.1658497489253; Fri, 22 Jul 2022 06:44:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vKzrn573LpWJtRxxYtx4oCk45bHJ2Ynw6wt+cSmM7wiFCel74/dsXZJXHafRdPD13PIVMvKg== X-Received: by 2002:a05:622a:1348:b0:31f:f43:7b0 with SMTP id w8-20020a05622a134800b0031f0f4307b0mr104007qtk.542.1658497489026; Fri, 22 Jul 2022 06:44:49 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id m12-20020a05620a290c00b006b5d9a1d326sm3784492qkp.83.2022.07.22.06.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 06:44:48 -0700 (PDT) Date: Fri, 22 Jul 2022 09:44:47 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Nadav Amit , Andrew Morton , Andrea Arcangeli Subject: Re: [PATCH v3 2/3] selftests: soft-dirty: Add test for mprotect Message-ID: References: <20220721183338.27871-1-peterx@redhat.com> <20220721183338.27871-3-peterx@redhat.com> <8fbbd68f-267c-1e0d-a578-7da4551c4c19@redhat.com> MIME-Version: 1.0 In-Reply-To: <8fbbd68f-267c-1e0d-a578-7da4551c4c19@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658497491; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dWRpA1oxrDhiiXkeV9SXJ/F3tpuLhpf/KYwSClNmv+Q=; b=a3YyarX4deLF6mpoT40aadc3FwdTBG3uXLBLuFogL7He5h7xmxT9NnxYddWexfOt4vO0Hu vkTYmIchYOMLGKh8C+p8mkp2J47T6iecthHGFidO/pJMKGvNlvSQgKBrKHd3gYy717HNHj Am4S56156BOoVSLYw+qVDoz0f5KDYqU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658497491; a=rsa-sha256; cv=none; b=DKaVEyshPajWALYs6D2hY+dcg0cCVw2dMU/t4y4ncocEXJMCG88BU/ztufdIw/Ffjy/2Bd gBVEuT7QrlssCctsKV5aRIwDeOB6LYWqaB8TJ5JDxO/xTHNegl05RQOz3uFVoTWZKvaNrY 2HLoPGAGOkgqTIczLYdBVN8pqS5797c= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Uusg2UMZ; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf14.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: w7qopf864pq9b85inoeei6px6fpuwsnu X-Rspamd-Queue-Id: 6619B100088 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Uusg2UMZ; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf14.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1658497491-147788 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 Fri, Jul 22, 2022 at 09:17:34AM +0200, David Hildenbrand wrote: > On 21.07.22 20:33, Peter Xu wrote: > > Add two soft-diryt test cases for mprotect() on both anon or file. > > s/soft-diryt/soft-dirty/ Fixed. > > > > > Signed-off-by: Peter Xu > > --- > > tools/testing/selftests/vm/soft-dirty.c | 69 ++++++++++++++++++++++++- > > 1 file changed, 68 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/vm/soft-dirty.c b/tools/testing/selftests/vm/soft-dirty.c > > index 08ab62a4a9d0..7d93906aa43f 100644 > > --- a/tools/testing/selftests/vm/soft-dirty.c > > +++ b/tools/testing/selftests/vm/soft-dirty.c > > @@ -121,13 +121,78 @@ 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; > > Instead of fname, unlink, open, close, unlink you can use a tmpfile > > FILE *file; > > file = tmpfile(); > if (!file) { > ksft_test_result_fail("tmpfile() failed\n"); > return; > } > test_fd = fileno(file); Note that tmpfile() should by default fetch from /tmp which is very possibly a tmpfs afaict. It's tricky in this special test case since I don't think tmpfs can trigger this bug (shmem doesn't define page_mkwrite). I wanted to create under this dir to make the best possible bet to trigger the bug. E.g. major fs will works like xfs, btrfs, extN. It'll stop work if someone clones the Linux repo under tmpfs but it's rare. > > > + > > + 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 { > > + unlink(fname); > > + test_fd = open(fname, O_RDWR | O_CREAT); > > + if (test_fd < 0) { > > + ksft_test_result_skip("Test %s huge page allocation\n", __func__); > > Wrong copy-paste I assume :) Yeh :) I'll fix it. > > > + return; > > + } > > + 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"); > > + } > > + > > Apart from that LGTM. Thanks, -- Peter Xu