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 94994C05027 for ; Fri, 3 Feb 2023 13:21:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 153436B0074; Fri, 3 Feb 2023 08:21:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DC8F6B0075; Fri, 3 Feb 2023 08:21:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBE9C6B0078; Fri, 3 Feb 2023 08:21:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D9F856B0074 for ; Fri, 3 Feb 2023 08:21:23 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9E1C340193 for ; Fri, 3 Feb 2023 13:21:23 +0000 (UTC) X-FDA: 80426042046.14.01899A0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id E90B140027 for ; Fri, 3 Feb 2023 13:21:21 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tyPVIsUV; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675430482; 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=2HifOJA9xEveZM8S1gjqMUhg2gHpRif7oy7buFyjGZM=; b=3jHjw9bb/yupZjcnDWkQMt7MTJn/GuizXqRtZJCa6DQ5FTPfWurVGMk03Yb8VJcDXBvucn emgbd7SWOEfkk3uAssEERZ4OUpiz2SQEb5pKVKZMnzqST9bOqDa+NXluWFJ8wX6ACqX/TY A9vczjZoyHYRdlcaDjqMVBoES0dAi9Y= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tyPVIsUV; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675430482; a=rsa-sha256; cv=none; b=JqPSU7XxGEYMdSyn7e1LuVWIujOOZdPAtHUuZIVAXM3ZljgG3R6EqGiDvfUz2L9crVnloo c7z7ayWN89wTMkzbDAqtCaybVjv5cKcDYgs5cx4RpnVKddzQv97U0hOweaDNcCk0T5w/08 aPNJ3xNKjxBUHmHsc/zeZhQEh7WOCEU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2HifOJA9xEveZM8S1gjqMUhg2gHpRif7oy7buFyjGZM=; b=tyPVIsUVRpIoIoazplnubKmX1v VwBTgmYii/7IPUTEh3FWs/+3N1G7cKSAAwVe5uNCqYKeI5R5ip0/9MzqHlwdJQb1C/1gHW0SVBgZD TTNWZnJdMQQ+nx9ncuzJ4NH67LYSnA5bg+XBwru4I25XIPz8EY3tDHScxiFgW3OBr5d+97Or/4Pe8 vW784qBalVKSP+hbLlpcQpt3/rC47rVDm3QvjeTJ8u2q9haDI7oHiRDw05qhuodbvBiKedIqGpPAd IvuCLnuK7HNTfy/Txxb8YdoJ6dHlD/16YEZ1SYt+fl7Ryd0Ix8Jzhp8YXQfvgVjMyBHZI43i0mIGF bWT8hCpg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNw0D-00EKdy-V5; Fri, 03 Feb 2023 13:21:18 +0000 Date: Fri, 3 Feb 2023 13:21:17 +0000 From: Matthew Wilcox To: Andreas Dilger Cc: linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, Hugh Dickins , linux-kernel@vger.kernel.org, fstests@vger.kernel.org Subject: Re: [PATCH 0/5] Fix a minor POSIX conformance problem Message-ID: References: <20230202204428.3267832-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E90B140027 X-Stat-Signature: jrmfdib56gofg4gykc9ogyse578wm77b X-Rspam-User: X-HE-Tag: 1675430481-795371 X-HE-Meta: U2FsdGVkX1+2CNVYWlA2QCQuRQg+tmmkZ81kQ3YUPor9LdtNKX4njqXcpVmz9z5OqGbytn974BTLBSHmF5jwvr+EOSh/BVEqNKGNkBPgSPU0HEyh0G+xwwxHjUCQmTDG0Q1oyULmvvpAJ+o9/sP9NZ5u9GkDgYpQBQQZWRBF4hSbYlPMbiuifDBrTuqJ8BXvifxLZFoXFF6glaA8wLFot7WflcBF/mFU2ODUzmSDYpSNRAj1/hwlPrxrXfujmEbZqUhgJqaG2JWAlirjbO0XZCxOABCXQCbAL7h0RcZAa3qsEVVapxX0Ec/sGebLwtFKDHTTYsBG+ZXpUWdjypXke6XeOuPotS1mkkwOT+64vvsGMtd0NgroO79BJvnFrddA0WxmjWHU4jz6qNf7pYhx9A1BjmbcIWj7HPHRlnJtrG9ce5p+0qqd9fiuYlRC/IVJqOYEwjdJDCLqrb7RYezi5eDa36/RZCfkabxHfXVICMePCQElv3cQVXWw4IKhhVSS+0APnp/zgRsAxqqG0NHAM2fzv4B/u63J+4QvYVdCMPboe2jrERvY0bfhtUL3RTte13rHus3QgcKnxanLpcK5IsrPOGlH5mMI4u/sEY39xQXugZGZ8I5dq1Jfpn3DYfiQFV368Ag+W3KkMtzZdGVGuECFpXR/dwLSngiUN9n96SQpoZxdls7ZJ+VbBPLFex8oKuF12v7zC8dn7nqttE15jk3Pl8cCLfl4m4w3uo+guljzYIUcEjkDEh/kt5HaVYYsTF9+6+Hndrc+eiqLMsjnd74vuutQp1/CN/vp1hizV3CbTL2aVcw90Dmq5rKA3lUiZ3b2t+TCz7Zw2GWfyGu7/RFpUuzwbCS/zl2kvEjOVPZKE29YzbhbTPOln52D598VYoQ2TyCGkp/Yn4D4Fj51UDdBwL6InggktP/UP4BGL0tbcPHUkgQolCPsJoNC0BN9hSBlbg/5qYo8kX1jjjM ekuVONs9 Lxykf2vwfxJx6i3s64tIAS/gywXVuvHTISpvKOvasibZd9kDF8Yfeq5res+EPG9KHsyD+8dGjqBDG1FQmkskZA7+bNkAIMo7mQpcIgXpSdfW+ijhxJzOxwuiHa7dZTDlJWTo3FfD+vHkNuac3z2jDmQG4qotI91EUpmg2wCYtCKZgpXj7JU8r9maUnEjC9NkKDgpCbZdN2b9RUOjYPzZvExnIWO8bpgWkFzsz4WCdaDrYZe/0GBheFOn0knXrbHjbEdZ+nxhk/aWZ42FOUm43fL49NdMMJR/TmvN/IqBuuLhK/hE= 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 Thu, Feb 02, 2023 at 04:08:49PM -0700, Andreas Dilger wrote: > On Feb 2, 2023, at 1:44 PM, Matthew Wilcox (Oracle) wrote: > > > > POSIX requires that on ftruncate() expansion, the new bytes must read > > as zeroes. If someone's mmap()ed the file and stored past EOF, for > > most filesystems the bytes in that page will be not-zero. It's a > > pretty minor violation; someone could race you and write to the file > > between the ftruncate() call and you reading from it, but it's a bit > > of a QOI violation. > > Is it possible to have mmap return SIGBUS for the writes beyond EOF? Well, no. The hardware only tells us about accesses on a per-page basis. We could SIGBUS on writes that _start_ after EOF, but this test doesn't do that (it starts before EOF and extends past EOF). And once the page is mapped writable, there's no page fault taken for subsequent writes. > On the one hand, that might indicate incorrect behavior of the application, > and on the other hand, it seems possible that the application doesn't > know it is writing beyond EOF and expects that data to be read back OK? POSIX says: "The system shall always zero-fill any partial page at the end of an object. Further, the system shall never write out any modified portions of the last page of an object which are beyond its end. 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." https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html So the application can't expect to read back anything it's written (and if you look at page writeback, we currently zero beyond EOF at writeback time). > IMHO, this seems better to stop the root of the problem (mmap() allowing > bad writes), rather than trying to fix it after the fact. That would be nice, but we're rather stuck with the hardware that exists. IIUC Cray-1 had byte-granularity range registers, but page-granularity is what we have.