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 A41DF35B150; Thu, 23 Oct 2025 17:47:21 +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=1761241641; cv=none; b=n0plE7XVbTNuTucDrrlt3xqSZTlyDY3u5oVkKy2i5+HcSWEUL2LrHpGkMUBJAeC1tjNqWmuiQNCAzj3nKqQ+IbrSpj/CkIvPCwzEf6wRczjYBXBa/JKWyUxX2Ne0jzp6UF/Su/5G+XtiVLStLBExkBWv7H/+zu24IPB8ZG5z4Kg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761241641; c=relaxed/simple; bh=0UjbUuHWI+/B9+mpMQaomI/3XkufAKikbowYNANqJzM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qluhRPu1sGStgHhMQhrf9YHSpDaO1MORHnoONyG3RHdCxUQNMFNe+29q63FjPNRvQ8nPxPc8wDlYVHzjCpIKT78oWwePbN9vtMOS0LUr6vGa2vNzRBT9zTmUO6kLDVzM/XfuQlUeyCcNM0BNu0r0cp2OOYatx7X9AeengO12HCs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eHWuff3v; 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="eHWuff3v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 260DBC4CEE7; Thu, 23 Oct 2025 17:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761241641; bh=0UjbUuHWI+/B9+mpMQaomI/3XkufAKikbowYNANqJzM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eHWuff3vgCcM4s6HPc99FPHy/+VJy1z4r2xR9Bz/6yK7LYtewBpfK0r1kmkUrEPpQ kLNX0iPYF1s7aoir8pqg+Ux9hDMrQQXTKiyKQ945TJt8LTqiLQGaK/TteqSLHEeaSp z9nSJbdes+XLFleJbsQCLNZOf++fsbdCSQHP4aUQc0BWH/R/B8nb37Q8hA/3h9Y6Hr Vky829rcJ/zd6/sDXcrr+bEIT/MFpbYVvE7AfQ7kSioZD4jUgjMXcLfS7/aLXfo1lY TTZkOfm1HEahMlEAlRFYn6ozp2xsNS+nZvr9nnOY/EvMFPAodYVryDCs/reS3B0IUy YVCyXAFalfYBg== Date: Thu, 23 Oct 2025 10:47:20 -0700 From: "Darrick J. Wong" To: Kiryl Shutsemau Cc: Andrew Morton , David Hildenbrand , Hugh Dickins , Matthew Wilcox , Alexander Viro , Christian Brauner , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Rik van Riel , Harry Yoo , Johannes Weiner , Shakeel Butt , Baolin Wang , Dave Chinner , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kiryl Shutsemau Subject: Re: [PATCHv2 0/2] Fix SIGBUS semantics with large folios Message-ID: <20251023174720.GI6174@frogsfrogsfrogs> References: <20251023093251.54146-1-kirill@shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251023093251.54146-1-kirill@shutemov.name> On Thu, Oct 23, 2025 at 10:32:49AM +0100, Kiryl Shutsemau wrote: > From: Kiryl Shutsemau > > Accessing memory within a VMA, but beyond i_size rounded up to the next > page size, is supposed to generate SIGBUS. > > Darrick reported[1] an xfstests regression in v6.18-rc1. generic/749 > failed due to missing SIGBUS. This was caused by my recent changes that > try to fault in the whole folio where possible: > > 19773df031bc ("mm/fault: try to map the entire file folio in finish_fault()") > 357b92761d94 ("mm/filemap: map entire large folio faultaround") > > These changes did not consider i_size when setting up PTEs, leading to > xfstest breakage. > > However, the problem has been present in the kernel for a long time - > since huge tmpfs was introduced in 2016. The kernel happily maps > PMD-sized folios as PMD without checking i_size. And huge=always tmpfs > allocates PMD-size folios on any writes. > > I considered this corner case when I implemented a large tmpfs, and my > conclusion was that no one in their right mind should rely on receiving > a SIGBUS signal when accessing beyond i_size. I cannot imagine how it > could be useful for the workload. > > But apparently filesystem folks care a lot about preserving strict > SIGBUS semantics. > > Generic/749 was introduced last year with reference to POSIX, but no > real workloads were mentioned. It also acknowledged the tmpfs deviation > from the test case. > > POSIX indeed says[3]: > > References within the address range starting at pa and > continuing for len bytes to whole pages following the end of an > object shall result in delivery of a SIGBUS signal. > > The patchset fixes the regression introduced by recent changes as well > as more subtle SIGBUS breakage due to split failure on truncation. > This fixes generic/749 for me, thanks! Tested-by: "Darrick J. Wong" --D > v2: > - Fix try_to_unmap() flags; > - Add warning if try_to_unmap() fails to unmap the folio; > - Adjust comments and commit messages; > - Whitespace fixes; > v1: > - Drop RFC; > - Add Signed-off-bys; > > [1] https://lore.kernel.org/all/20251014175214.GW6188@frogsfrogsfrogs > [2] > https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/commit/tests/generic/749?h=for-next&id=e4a6b119e5 > 229599eac96235fb7e683b8a8bdc53 > [3] https://pubs.opengroup.org/onlinepubs/9799919799/ > Kiryl Shutsemau (2): > mm/memory: Do not populate page table entries beyond i_size > mm/truncate: Unmap large folio on split failure > > mm/filemap.c | 18 ++++++++++-------- > mm/memory.c | 13 +++++++++++-- > mm/truncate.c | 31 +++++++++++++++++++++++++------ > 3 files changed, 46 insertions(+), 16 deletions(-) > > -- > 2.50.1 > >