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 3086EC43217 for ; Mon, 17 Jan 2022 13:30:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 805936B0071; Mon, 17 Jan 2022 08:30:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B4E66B0073; Mon, 17 Jan 2022 08:30:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67DA66B0074; Mon, 17 Jan 2022 08:30:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 586FE6B0071 for ; Mon, 17 Jan 2022 08:30:47 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0CF2695C82 for ; Mon, 17 Jan 2022 13:30:47 +0000 (UTC) X-FDA: 79039864134.28.D50E0BD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 2BA9D40002 for ; Mon, 17 Jan 2022 13:30:45 +0000 (UTC) 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=DEDlOvAxf5W8MkgN2U6MW75EWRQeMQMQaovnQRcgffo=; b=sWeOK+ACOkqqrSHFGcOcHtqNUt affW2E23Y5H4gus5QTI9RNzR2H8EFMA+ssyXPEH7r0ChvHKzzQZMM6GhvSo9Y6sSIYLuUHknRms35 r4m4Ukllxqdjth6/xEcNDXSsNRIKty4SfiLeQ8WlVQaGLQ9nHIgFuvZKcOEU2QaAvMn3xKQx8Is36 wrlnbO+VINuUCt6Ifo4R91YldO2uIRPsLZbnaqNcpdpZpstOVzNqmwYWKYxnovCJ0GDEMR54Ffti6 jldfxY4Dt7+NOyW8Fv26ursPmOgw9jR1Mp4KN89hlw3J5Uicwo4lbSZWBnUkV7lQwn2lq4D66VNBa 0SAtDMtw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9S5F-008EUB-2d; Mon, 17 Jan 2022 13:30:05 +0000 Date: Mon, 17 Jan 2022 13:30:05 +0000 From: Matthew Wilcox To: Linus Torvalds Cc: David Howells , Alexander Viro , Anna Schumaker , Dave Wysochanski , Dominique Martinet , Jeff Layton , Latchesar Ionkov , Marc Dionne , Omar Sandoval , Shyam Prasad N , Steve French , Trond Myklebust , Peter Zijlstra , ceph-devel@vger.kernel.org, linux-afs@lists.infradead.org, linux-cachefs@redhat.com, CIFS , linux-fsdevel , Linux-MM , "open list:NFS, SUNRPC, AND..." , v9fs-developer@lists.sourceforge.net, Linux Kernel Mailing List Subject: Re: Out of order read() completion and buffer filling beyond returned amount Message-ID: References: <2752208.1642413437@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2BA9D40002 X-Stat-Signature: i1twnuzissyqshccndznjhh9dou56yy9 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sWeOK+AC; dmarc=none; 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 X-HE-Tag: 1642426245-568425 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 Mon, Jan 17, 2022 at 12:19:29PM +0200, Linus Torvalds wrote: > On Mon, Jan 17, 2022 at 11:57 AM David Howells wrote: > > > > Do you have an opinion on whether it's permissible for a filesystem to write > > into the read() buffer beyond the amount it claims to return, though still > > within the specified size of the buffer? > > I'm pretty sure that would seriously violate POSIX in the general > case, and maybe even break some programs that do fancy buffer > management (ie I could imagine some circular buffer thing that expects > any "unwritten" ('unread'?) parts to stay with the old contents) > > That said, that's for generic 'read()' cases for things like tty's or > pipes etc that can return partial reads in the first place. > > If it's a regular file, then any partial read *already* violates > POSIX, and nobody sane would do any such buffer management because > it's supposed to be a 'can't happen' thing. > > And since you mention DIO, that's doubly true, and is already outside > basic POSIX, and has already violated things like "all or nothing" > rules for visibility of writes-vs-reads (which admittedly most Linux > filesystems have violated even outside of DIO, since the strictest > reading of the rules are incredibly nasty anyway). But filesystems > like XFS which took some of the strict rules more seriously already > ignored them for DIO, afaik. I think for DIO, you're sacrificing the entire buffer with any filesystem. If the underlying file is split across multiple drives, or is even just fragmented on a single drive, we'll submit multiple BIOs which will complete independently (even for SCSI which writes sequentially; never mind NVMe which can DMA blocks asynchronously). It might be more apparent in a networking situation where errors are more common, but it's always been a possibility since Linux introduced DIO.