From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD7D53587B9; Mon, 19 Jan 2026 14:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768833127; cv=none; b=Edyhbg2Hsf/EwYPktv5ZWkLfWjCLwSGDdHBnb9bHdhCzQ2wzCf23+gqKY7aR2z2QW7OGHB8ZVc2TvYDo2YvcgOmAZTZwJsoiQ760fo4DlYjCJBlWX+4SN0C3DAQjWbvNevAIwCZxwk46o6BGkZ65eHVLJoPAIQ/JlYsUiDZvWeU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768833127; c=relaxed/simple; bh=Hs96R0v+LlI8+ufCHnrjOfcRFqlmPYepVc9ZlwijYkQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kvRbnphMVDjVRgywuua1W/JrcLuneskINLOdOtOb5Nv5/Ys7gz2z6i6Ql3CDrAKOUcQpmsgzD+SnA8/PdgtELWOoA/N2LS5dp+x46yf5OMrx+a6brafw9dKyESP3DV9hCAFlKZ4rfn0L7Z1ILmFDegzEYTYa4GslKxfjrMx/Kng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SGy0RovL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SGy0RovL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E7B6C116C6; Mon, 19 Jan 2026 14:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768833127; bh=Hs96R0v+LlI8+ufCHnrjOfcRFqlmPYepVc9ZlwijYkQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=SGy0RovLRZvaYLdD3aLt2XozWXFHZ2SPjh0XzkFNl2IpZCqNfKbpohPSjP+CkYA5W aEDIBTUxdcWBbYnU3KtrfMHe5TsAKXEGECs6N51jAJPUhu88PNtp8Azp6+MW43kK/Z uEfkEN8/a0zOKDDuwCPPNeVm92Y4gfyRy18AgTsT52vNzujpnxil8MQSQmybO+WYgF PNkszLtFenchgwT4grC2xyOkZ4N1nQy7ehh5ey+mweQFxs7zP8eysRJJFfAyuXB5LE vMcRUJBOcDeCos62taDKTW6Ysim+u5nzgxm9Fe1bWw9i7xCtcmiHjSiIuE8oYx9jUC 2DlB0POinPT5g== Message-ID: <42b9825a-adef-4e80-bbf3-bf01b9fb0054@kernel.org> Date: Mon, 19 Jan 2026 15:32:03 +0100 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 8/8] selftests/mm: report SKIP in pfnmap if a check fails To: Ryan Roberts , Kevin Brodsky , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Lorenzo Stoakes , Mark Brown , Shuah Khan References: <20260107164842.3289559-1-kevin.brodsky@arm.com> <20260107164842.3289559-9-kevin.brodsky@arm.com> <09c214df-c3aa-48e4-9587-c54c667c6ce9@kernel.org> <46e50e9d-0e4a-4f81-8b43-61b897ad9c34@arm.com> From: "David Hildenbrand (Red Hat)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478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sF8BBgBCAAmAhsMFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAmic2qsF CSZYCKEACgkQTd4Q9wD/g1oq0xAAsAnw/OmsERdtdwRfAMpC74/++2wh9RvVQ0x8xXvoGJwZ rk0Jmck1ABIM//5sWDo7eDHk1uEcc95pbP9XGU6ZgeiQeh06+0vRYILwDk8Q/y06TrTb1n4n 7FRwyskKU1UWnNW86lvWUJuGPABXjrkfL41RJttSJHF3M1C0u2BnM5VnDuPFQKzhRRktBMK4 GkWBvXlsHFhn8Ev0xvPE/G99RAg9ufNAxyq2lSzbUIwrY918KHlziBKwNyLoPn9kgHD3hRBa Yakz87WKUZd17ZnPMZiXriCWZxwPx7zs6cSAqcfcVucmdPiIlyG1K/HIk2LX63T6oO2Libzz 7/0i4+oIpvpK2X6zZ2cu0k2uNcEYm2xAb+xGmqwnPnHX/ac8lJEyzH3lh+pt2slI4VcPNnz+ vzYeBAS1S+VJc1pcJr3l7PRSQ4bv5sObZvezRdqEFB4tUIfSbDdEBCCvvEMBgoisDB8ceYxO cFAM8nBWrEmNU2vvIGJzjJ/NVYYIY0TgOc5bS9wh6jKHL2+chrfDW5neLJjY2x3snF8q7U9G EIbBfNHDlOV8SyhEjtX0DyKxQKioTYPOHcW9gdV5fhSz5tEv+ipqt4kIgWqBgzK8ePtDTqRM qZq457g1/SXSoSQi4jN+gsneqvlTJdzaEu1bJP0iv6ViVf15+qHuY5iojCz8fa0= In-Reply-To: <46e50e9d-0e4a-4f81-8b43-61b897ad9c34@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/19/26 15:26, Ryan Roberts wrote: > On 19/01/2026 11:16, David Hildenbrand (Red Hat) wrote: >> On 1/7/26 17:48, Kevin Brodsky wrote: >>> pfnmap currently checks the target file in FIXTURE_SETUP(pfnmap), >>> meaning once for every test, and skips the test if any check fails. >>> >>> The target file is the same for every test so this is a little >>> overkill. More importantly, this approach means that the whole suite >>> will report PASS even if all the tests are skipped because kernel >>> configuration (e.g. CONFIG_STRICT_DEVMEM=y) prevented /dev/mem from >>> being mapped, for instance. >>> >>> Let's ensure that KSFT_SKIP is returned as exit code if any check >>> fails by performing the checks in pfnmap_init(), run once. That >>> function also takes care of finding the offset of the pages to be >>> mapped and saves it in a global. The file is still mapped/unmapped >>> for every test, as some of them modify the mapping. >>> >>> Signed-off-by: Kevin Brodsky >>> --- >>>   tools/testing/selftests/mm/pfnmap.c | 81 ++++++++++++++++++++--------- >>>   1 file changed, 55 insertions(+), 26 deletions(-) >>> >>> diff --git a/tools/testing/selftests/mm/pfnmap.c b/tools/testing/selftests/mm/ >>> pfnmap.c >>> index 35b0e3ed54cd..e41d5464130b 100644 >>> --- a/tools/testing/selftests/mm/pfnmap.c >>> +++ b/tools/testing/selftests/mm/pfnmap.c >>> @@ -25,8 +25,11 @@ >>>   #include "kselftest_harness.h" >>>   #include "vm_util.h" >>>   +#define DEV_MEM_NPAGES    2 >>> + >>>   static sigjmp_buf sigjmp_buf_env; >>>   static char *file = "/dev/mem"; >>> +static off_t file_offset; >>>     static void signal_handler(int sig) >>>   { >>> @@ -88,7 +91,7 @@ static int find_ram_target(off_t *offset, >>>               break; >>>             /* We need two pages. */ >>> -        if (end > start + 2 * pagesize) { >>> +        if (end > start + DEV_MEM_NPAGES * pagesize) { >>>               fclose(file); >>>               *offset = start; >>>               return 0; >>> @@ -97,9 +100,49 @@ static int find_ram_target(off_t *offset, >>>       return -ENOENT; >>>   } >>>   +static void pfnmap_init(void) >>> +{ >>> +    size_t pagesize = getpagesize(); >>> +    size_t size = DEV_MEM_NPAGES * pagesize; >>> +    int fd; >>> +    void *addr; >>> + >>> +    if (strncmp(file, "/dev/mem", strlen("/dev/mem")) == 0) { >>> +        int err = find_ram_target(&file_offset, pagesize); >>> + >>> +        if (err) >>> +            ksft_exit_skip("Cannot find ram target in '/proc/iomem': %s\n", >>> +                       strerror(-err)); >>> +    } else { >>> +        file_offset = 0; >>> +    } >>> + >>> +    /* >>> +     * Make sure we can open and map the file, and perform some basic >>> +     * checks; skip the whole suite if anything goes wrong. >>> +     * A fresh mapping is then created for every test case by >>> +     * FIXTURE_SETUP(pfnmap). >>> +     */ >>> +    fd = open(file, O_RDONLY); >>> +    if (fd < 0) >>> +        ksft_exit_skip("Cannot open '%s': %s\n", file, strerror(errno)); >>> + >>> +    addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, file_offset); >>> +    if (addr == MAP_FAILED) >>> +        ksft_exit_skip("Cannot mmap '%s': %s\n", file, strerror(errno)); >>> + >>> +    if (!check_vmflag_pfnmap(addr)) >>> +        ksft_exit_skip("Invalid file: '%s'. Not pfnmap'ed\n", file); >>> + >>> +    if (test_read_access(addr, size)) >>> +        ksft_exit_skip("Cannot read-access mmap'ed '%s'\n", file); >>> + >>> +    munmap(addr, size); >> >> Why not keep the fd open then and supply that to all tests without the need for >> them to open/close? >> >> Then, also the file cannot change etc. > > I had a private conversation with Kevin about this before he posted; my very > minor, theorectical concern about that was that it's possible to pass in a > custom file to be pfnmapped and I wondered if such a file could map a device > region that has read side effects? In that case I think you'd want to open it > fresh for each test to ensure consistent starting state? Are we aware of devices where we would actually require a new open, and not just a new mmap()? The reason we added support for other files was "other pfnmap'ed memory like NVIDIA's EGM". I'd assume that people rather should not pass in something that has any side-effects. > > But if you think that concern is unfounded, certainly just opening it once and > reusing will simplify. I would just keep it simple here, yes. If this ever becomes a real problem, my intuition would tell me that probably the caller is doing something unsupported that we just cannot easily identify+reject. -- Cheers David