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 67ECCC369C2 for ; Tue, 22 Apr 2025 11:03:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 955016B0005; Tue, 22 Apr 2025 07:03:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9034A6B0007; Tue, 22 Apr 2025 07:03:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A4D16B0008; Tue, 22 Apr 2025 07:03:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 57CBF6B0005 for ; Tue, 22 Apr 2025 07:03:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 80B041401C9 for ; Tue, 22 Apr 2025 11:03:16 +0000 (UTC) X-FDA: 83361393192.18.CA01C65 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id B52EE8000F for ; Tue, 22 Apr 2025 11:03:14 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745319794; 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; bh=qCNLfPs34XI7stfndzi8Z1SsQzJb6baZLe3zq4/K/2o=; b=DytGXcscdMdd93HaxWQVtJ7zqlEWXUaLfHzLnhgmEGskWVqLxX/xBn+FvgzAjdP27O8LWv pPkZGWu75EmjRYUrniIlrdkmpMdA8LDLGhreFmYTVhi8m+m7LUxVHjR5EXWBAkgCTMvdgy dfUKgGieFejX2hoCesweC0Kf3UhaewQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745319794; a=rsa-sha256; cv=none; b=3+nm4R2oHeiYSVBPAlrdzgh5mchCgCzlBXK+9IzmI82LpAnuRRKCHi/bCh4ITBMBms827p /tFb+cMpWXW1LLpFASDnpnQWNihZAXRtgWpOuJpG+z8w6YhXIHd1OdnttxenFgRiD/dF9r LT9yw2yq+Fmg4G5G6mgHks4L7odMNBI= 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 A2B54152B; Tue, 22 Apr 2025 04:03:09 -0700 (PDT) Received: from [10.57.90.106] (unknown [10.57.90.106]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAC0C3F5A1; Tue, 22 Apr 2025 04:03:10 -0700 (PDT) Message-ID: Date: Tue, 22 Apr 2025 12:03:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/4] tools/selftests: expand all guard region tests to file-backed Content-Language: en-GB To: Lorenzo Stoakes Cc: Andrew Morton , Suren Baghdasaryan , "Liam R . Howlett" , Matthew Wilcox , Vlastimil Babka , "Paul E . McKenney" , Jann Horn , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, John Hubbard , Juan Yescas , Kalesh Singh References: <7d5e0f61-66d9-471c-b6ef-bf68dbffa614@lucifer.local> From: Ryan Roberts In-Reply-To: <7d5e0f61-66d9-471c-b6ef-bf68dbffa614@lucifer.local> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B52EE8000F X-Stat-Signature: fi73kzdwebxcak6hitg9396io9ft8qog X-HE-Tag: 1745319794-611845 X-HE-Meta: U2FsdGVkX1/nwPvG4GtFrHhK8lavjsq907c1q01sq+GSMAZg+fUAZSteikvTfTG9xzzXsjZ0IkdDDG8ABIrKBrMniXTGqEwMluySdXAkMYT6X7EsezBKQFrWoB95RYiu1JvwDkrqVRhEhOP6u4169JUjKai2CUwtZF+RmJu33mkswe7Dkf8DpE+NYDNII869o8rlVyTVxM4FBJ77oMZEQcse3QZ2HIbMwEEEI3tnn6+NdSx1BGSMDJ34HRsimACcOERDKqWeS+xSRS5gySKaIUjjyW/OrGgiKrUAYitd4q6tY70V40/P7zewg8iJ1SRjr/NyA/1iWWJkxs6HY7mdO0L9nuFLK3KMSMGvfSQu3rCximjoq7dmnILlu6v1IsMZqa4q0ElJyWtnBPMyb/fS2IPn8XZjUQ15/exaF0unxKpwEFlmU8H2b/kJZssav4YRlumwbEzyS0+9VklTmq2wbvAEMwk8eofQzpgXVdJ+/NneNmSxvJQd3RtUj1Cfj4nBpr+lVFqEeEFNpEZWt0e/M//hS2bP+FJqhooad2xjLe5LoCIeTKm3s47mC0j+9XTQHG9EG3iGhC+1td+eVczEr+uzKN/LvOrbNjVpXyx69QyGlsJnDzub+ZgIAZvH4ows23DssBOFQObIrYL01oXUUUNrQWQK1BvfsaLIJueeU3Ix4THFMmbUviqZ+BuSjAl3j/9Yw9zjJcsdji0noi1iT73Pm2yZJBi7L0v5sQcyVWrJn73LrtawqkOdfj54n2uQ/HXIgVwzOfCdf7+w/swHSC5pQKkp+ijgfcZXTweiMGzdH/tqlcZ7aBQf2tNZYIxytQ4cNiVSd74SPU4CNEnEKXAwloTf8krXQDB1W6o21KvykEzMMHfGwMO5iAJMHIgHoAw1kBL/nl0UMORNgbJfm1GeUrPFvySl+qXyh0/DUUhuTfKhj4TzWgan6HCGcVbceXVdKLqI9FklwIuJQIm 9r8aZoCT oqpE5SkR/wGpJH+v3lf7IwpdPRX7eKYsAAg4uf5Ibn6SCVak1HTXeWoGLkKpeCW9wJwZU2kCMDvRyvOdtbiU/AUdw0z6AYnsETJrLBDJiZVxht2AH7SvJmZJH0xXX+8dndnKr2ckgYKZmyVW4axRX5OEfJw== 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: List-Subscribe: List-Unsubscribe: On 22/04/2025 11:47, Lorenzo Stoakes wrote: > On Tue, Apr 22, 2025 at 11:37:57AM +0100, Ryan Roberts wrote: >> On 13/02/2025 18:17, Lorenzo Stoakes wrote: >>> Extend the guard region tests to allow for test fixture variants for anon, >>> shmem, and local file files. >>> >>> This allows us to assert that each of the expected behaviours of anonymous >>> memory also applies correctly to file-backed (both shmem and an a file >>> created locally in the current working directory) and thus asserts the same >>> correctness guarantees as all the remaining tests do. >>> >>> The fixture teardown is now performed in the parent process rather than >>> child forked ones, meaning cleanup is always performed, including unlinking >>> any generated temporary files. >>> >>> Additionally the variant fixture data type now contains an enum value >>> indicating the type of backing store and the mmap() invocation is >>> abstracted to allow for the mapping of whichever backing store the variant >>> is testing. >>> >>> We adjust tests as necessary to account for the fact they may now reference >>> files rather than anonymous memory. >> >> Hi Lorenzo, >> >> I'm getting a test failure in v6.15-rc3 on arm64: >> >> ----8<---- >> # RUN guard_regions.shmem.uffd ... >> # guard-regions.c:1467:uffd:Expected ioctl(uffd, UFFDIO_REGISTER, ®) (-1) == >> 0 (0) >> # uffd: Test terminated by assertion >> # FAIL guard_regions.shmem.uffd >> not ok 45 guard_regions.shmem.uffd >> ----8<---- >> >> The ioctl is returning EINVAL. > > Hm strange, that works fine on x86-64. Is > userfaultfd enabled in your config, to ask a silly question? Yep, and the anon version of the test is passing, as are all the uffd tests. > > It'd be odd for this to vary depending upon arch. > > So a factor here is a _stupidity_ in the testing - does your system mount /tmp > as tmpfs or an actual file system? As the test code unconditionally assumes /tmp > is indeed going to get you a shmem file. Ahh that's probably it. I'm on Ubuntu and it looks like /tmp is just a dir on the rootfs (XFS in my case). Forcing a tmpfs to /tmp solved it. Looks like uffd-unit-tests (see shmem_allocate_area()) is just using memfd. Would it be reasonable to take that approach? Or just use anon+shared via mmap? Thanks, Ryan > > It's shameful to be honest. But actually I suspect this more than anything > else... > >> >> [...] >> >>> @@ -1281,6 +1398,9 @@ TEST_F(guard_regions, uffd) >>> struct uffdio_register reg; >>> struct uffdio_range range; >>> >>> + if (!is_anon_backed(variant)) >> >> Perhaps this should be filtering out shmem too? Although the manual for >> userfaultfd implies that shmem is supported: > > Yeah it should work with it fine. > >> >> """ >> Up to Linux 4.11, userfaultfd can be used only with anonymous private memory >> mappings. Since Linux 4.11, userfaultfd can be also used with hugetlbfs and >> shared memory mappings. >> """ >> >> But I'm not sure if that's referring specifically to UFFDIO_REGISTER_MODE_MISSING? >> >> Any ideas before I start debugging further? >> >> Thanks, >> Ryan >> >>> + SKIP(return, "uffd only works on anon backing"); >>> + >>> /* Set up uffd. */ >>> uffd = userfaultfd(0); >>> if (uffd == -1 && errno == EPERM) >>> @@ -1290,8 +1410,8 @@ TEST_F(guard_regions, uffd) >>> ASSERT_EQ(ioctl(uffd, UFFDIO_API, &api), 0); >>> >>> /* Map 10 pages. */ >>> - ptr = mmap(NULL, 10 * page_size, PROT_READ | PROT_WRITE, >>> - MAP_ANON | MAP_PRIVATE, -1, 0); >>> + ptr = mmap_(self, variant, NULL, 10 * page_size, >>> + PROT_READ | PROT_WRITE, 0, 0); >>> ASSERT_NE(ptr, MAP_FAILED); >>> >>> /* Register the range with uffd. */ >>