From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB483352004 for ; Mon, 13 Jul 2026 19:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783972153; cv=none; b=mQ2ip7eGCIgcYym/9cs5mXs3gHCGeB7nAofyavFKMbVzHP5HZ/fcidUcS1I6aInINq3Imxad1wSBS0U2OG8igm7ZT/3yYU1VyEC3yDedTn697T9VF3SizCwcyDl6XdQr0Njbvx2CegmADThO+FDMMscKr3iq3hw/Qbh9SWACaGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783972153; c=relaxed/simple; bh=YqPfGyzEnu85dsiLIl9Uj76TeDUhpa61vP7fkG6wRLQ=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=PmIb1OKgk+ERgrX8RSGNFdJOf8tkPkeg4YanKwEtykzrJDJdCWQV774XYdazNVu7gbQqDhNJhRKza1lGVA59+Z1Eay8bPMDElqohPD/pYbAWmhiujToWNIxps8vEDn4p8MZmpbW4YrpryTz5MSHCv1N7iCWkYUz42irORL/ySzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IlkhnCIZ; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IlkhnCIZ" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-493b779003fso15542855e9.3 for ; Mon, 13 Jul 2026 12:49:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783972150; x=1784576950; darn=vger.kernel.org; h=content-type:mime-version:user-agent:references:in-reply-to:subject :cc:to:from:message-id:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=WMwr5n18/CbOHAg6mvs2ojnRJYI20IvI8xkMW1rsQ+Y=; b=IlkhnCIZPjVCYx6OMLoJr50i5zf9dkIzz079dQ9+Da2N2tLUs7f1E9iIZ7AgHOu5PV 1wehJOg6/vAXyIi8rwvy954UTJVgBOjmb7A7NEbK1lHn9O2w4U0AeHovd75IayLNfQVH aGawDYVPspen77K10+8EckeHd67sz3y+1mnhFzfmadK3XwEprMxVXyTG6FWprPtBGpJc 9zIgcHlzKeVmaQcBibVg//VdYTF+v0y4ZgfwFzFK/OTTS3TMFHRP7DNTHSMpgYl7Q1/G hX1sk9cfilWvBeCmkHKUdFs4rJGUgQiKvgZyYtS2iSPBqaqTWStMxpoh9n3LrL2Bhlo7 qeaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783972150; x=1784576950; h=content-type:mime-version:user-agent:references:in-reply-to:subject :cc:to:from:message-id:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=WMwr5n18/CbOHAg6mvs2ojnRJYI20IvI8xkMW1rsQ+Y=; b=MM6sO2GglHzvy3WR+inPUw+/CK0iTF9rxbmTT7RDgjEEvoisk9GCdlfxzueiVlMBnD iBif3TVtJKNKulU0AMcqTIQXjpwHxD1gcDiJL9MXNAy+OkfRTFqHmQa4nGIUhUqV07J0 Xri5ukQzApMb7vagK2BXLR+lIf+VXgkgvfjxBCaFc7LSN3VJ3/JSAXu8UPvBm3K5zqyE IdPIo3kRRPbwdKpFAG1a/HpaOGMWxYa0Z7mzHYkpa3Kb50/Ps0X35r3hzObrJvUDBeIv kOrMj9AkpTgJuvzLMQ7O6/SGI0OGXX8bQ7tNbrwhMjOtuCN/SB65QKgN0xnycPa6ufhU mS0w== X-Forwarded-Encrypted: i=1; AHgh+RrhvAerUnDpZJVVYBvrRm5ufKbqGfMjly0Y8XFfJXcnUHaBVdffWzr4EYTh4PAk28kLPIKZUg6pCwRWGoc=@vger.kernel.org X-Gm-Message-State: AOJu0YxMOD8eBOoYtA8j06OSt0GQpLMdQbjHawXh141EolplwKXTBX0r //nMSIOO4U9CQecLHOX3khELR92sdLlQ14JD40dab0Pxq+TBiKQ7yjRm X-Gm-Gg: AfdE7cmivrvZzr9LzT5dlU69nAGNYxZjCBFlU0umSKeqsNC3ACvJcFtlzrLc6apNMCt XnbXzq4LV4SfOjrZzD1OZ2ERNDe4UEBpNohllNVrN+M8r/jK/iLCYG40VXPz8AUUSNRu9UOjco2 PUrIplPJ2iKQPEkNA1y5jJPGjmH8GS2JLJpyhHlrVA7lGkLbtd2lXuTLH0vue1UMA+EIfee8e0O XFdAf62o1KUTPNlA/AehOYV5++Nuy3BKfMtnPBJ4NloB8XSD3Lwx6kReP2XMawf7ZgS+UtDt+rD 0xhJDuwTnMiNq+pux1ZIn3x8dlGvM8Olbi2IMWBLtL2gX0LVerF5CFePyp+KAgiRd3DTQ1GysGx sXGMTgaOwzFF24msk+xhYApBKQT7XbuhBbGUAWOk7Yqad425oSlZXHjTSqMJaiSkNfpELbLtovq rssieCkx1RpupOJIElyM/tJEbp73yuCqgfWP2vQPK03yglqRsNVHOHTIcS3ragMbBrWjlXmgVYK dU0kaQDIIcCk6hMaEAc3AMiZDpEfSQRlclO+ctM7SM2O5Pay6Cv X-Received: by 2002:a05:600c:4e8e:b0:493:cc25:9c0e with SMTP id 5b1f17b1804b1-493f87e5945mr106652315e9.14.1783972149977; Mon, 13 Jul 2026 12:49:09 -0700 (PDT) Received: from jupiter.local.gmail.com (host-2-119-2-100.business.telecomitalia.it. [2.119.2.100]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49508725c0bsm18653015e9.2.2026.07.13.12.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 12:49:09 -0700 (PDT) Date: Mon, 13 Jul 2026 21:49:07 +0200 Message-ID: From: Hajime Tazaki To: daniel@thingy.jp Cc: ljs@kernel.org, akpm@linux-foundation.org, dhowells@redhat.com, linux-kernel@vger.kernel.org, sashiko-bot@kernel.org Subject: Re: [PATCH] ramfs: nommu: fix error rollback and reader races in ramfs_nommu_expand_for_mapping() In-Reply-To: <20260713115700.1349111-1-daniel@thingy.jp> References: <20260713115700.1349111-1-daniel@thingy.jp> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/26.3 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Hello Daniel, thanks for cc-ing me for the patch. On Mon, 13 Jul 2026 13:57:00 +0200, Daniel Palmer wrote: > > ramfs_nommu_expand_for_mapping() sets the new i_size before it has > allocated or inserted any of the contiguous backing pages. > > If alloc_pages() or add_to_page_cache_lru() fails, the inode is left > with an inflated i_size and possibly a partial run of pages. As > ramfs_nommu_setattr() treats a truncate to the current i_size as a > no-op, the expansion cannot be retried and shared mmap() of the file > fails with -ENOSYS. > > Setting i_size early also races with lockless readers: buffered reads > and splice do not take i_rwsem, so once the new size is visible a > concurrent read can instantiate a zero-filled folio, making the > expansion's add_to_page_cache_lru() fail with -EEXIST. > > Fix this by taking mapping->invalidate_lock around the insertion, > evicting any stray folios first, and only publishing i_size once > every page is in place. > > On failure, after freeing the pages that were allocated but > not inserted truncate the mapping back to empty so already inserted > pages are also disposed of. > > Fixes: 642fb4d1f1dd ("[PATCH] NOMMU: Provide shared-writable mmap support on ramfs") > Reported-by: Sashiko > Closes: https://sashiko.dev/#/message/20260523130445.1101818-1-daniel%40thingy.jp > Assisted-by: Claude:claude-5-fable # expanded my fix to address the reader race etc. > Signed-off-by: Daniel Palmer > --- I have tested this patch in addition to your previous patch (20260523130445.1101818-1-daniel@thingy.jp) over LTP test with my local nommu-revert patchset. I run the following test (which I have never looked at thus doesn't have much knowledge about the test itself). https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/memfd_create/memfd_create01.c without first patch, it indeed returns EFBIG on memfe_createfd() syscall. applying both patches with this test gives me still failure with the following messages: ``` /__w/linux/linux/lib/tst_test.c:2060: TINFO: LTP version: 20260529 /__w/linux/linux/lib/tst_test.c:2063: TINFO: Tested kernel: 7.1.0-rc1-gfd4e5701bb02-dirty #1 Mon Jul 13 18:17:11 UTC 2026 um(nommu)/x86_64 /__w/linux/linux/lib/tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz' /__w/linux/linux/lib/tst_test.c:1880: TINFO: Overall timeout per run is 0h 05m 24s /__w/linux/linux/testcases/kernel/syscalls/memfd_create/memfd_create01.c:241: TINFO: Basic tests + set/get seals /__w/linux/linux/testcases/kernel/syscalls/memfd_create/memfd_create01.c:243: TPASS: memfd_create(ltp_memfd_create01, 2) succeeded /__w/linux/linux/testcases/kernel/syscalls/memfd_create/memfd_create01.c:243: TPASS: ftruncate(3, 8192) succeeded /__w/linux/linux/testcases/kernel/syscalls/memfd_create/memfd_create_common.c:212: TBROK: fcntl(3,F_GET_SEALS,...) failed: EINVAL (22) Summary: passed 2 failed 0 broken 1 skipped 0 warnings 0 ``` which fails at the location below (in memfd_create_common.c#L207) int ret = SAFE_FCNTL((fd), F_GET_SEALS); so fcntl(fd, F_GET_SEALS) always fails with nommu due to lack of support of CONFIG_SHMEM and CONFIG_HUGETLBFS. ``` mm/memfd.c (in kernel) static unsigned int *memfd_file_seals_ptr(struct file *file) { if (shmem_file(file)) return &SHMEM_I(file_inode(file))->seals; #ifdef CONFIG_HUGETLBFS if (is_file_hugepages(file)) return &HUGETLBFS_I(file_inode(file))->seals; #endif return NULL; } ``` so I was wondering if it is still interesting to support the syscall (memfd_createfd) on nommu even the fcntl always fails. My test is used on riscv-nommu (buildroot) and UML + !MMU, which gives me the same results. -- Hajime