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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70B99C433EF for ; Mon, 17 Jan 2022 13:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234315AbiAQNao (ORCPT ); Mon, 17 Jan 2022 08:30:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234121AbiAQNan (ORCPT ); Mon, 17 Jan 2022 08:30:43 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A9E1C061574; Mon, 17 Jan 2022 05:30:43 -0800 (PST) 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: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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.