From patchwork Mon Oct 3 03:34:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 9485653 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_HI=-5,RP_MATCHES_RCVD=-0.1 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id 7FE032A82 for ; Sun, 2 Oct 2016 22:33:43 -0500 (CDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751187AbcJCDeR (ORCPT ); Sun, 2 Oct 2016 23:34:17 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:57438 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751021AbcJCDeQ (ORCPT ); Sun, 2 Oct 2016 23:34:16 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.86_2 #1 (Red Hat Linux)) id 1bqu13-0006yi-DT; Mon, 03 Oct 2016 03:34:09 +0000 Date: Mon, 3 Oct 2016 04:34:09 +0100 From: Al Viro To: Linus Torvalds Cc: Miklos Szeredi , Dave Chinner , CAI Qian , linux-xfs , Jens Axboe , Nick Piggin , linux-fsdevel Subject: [RFC] O_DIRECT vs EFAULT (was Re: [PATCH 10/12] new iov_iter flavour: pipe-backed) Message-ID: <20161003033409.GT19539@ZenIV.linux.org.uk> References: <20160917190023.GA8039@ZenIV.linux.org.uk> <20160923190032.GA25771@ZenIV.linux.org.uk> <20160923190326.GB2356@ZenIV.linux.org.uk> <20160923201025.GJ2356@ZenIV.linux.org.uk> <20160924040117.GP2356@ZenIV.linux.org.uk> <20160929225003.GQ19539@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org On Fri, Sep 30, 2016 at 09:30:21AM +0200, Miklos Szeredi wrote: > On Fri, Sep 30, 2016 at 12:50 AM, Al Viro wrote: > > On Thu, Sep 29, 2016 at 10:53:55PM +0200, Miklos Szeredi wrote: > > > >> The EFAULT logic seems to be missing across the board. And callers > >> don't expect a zero return value. Most will loop indefinitely. > > > > Nope. copy_page_to_iter() *never* returns -EFAULT. Including the iovec > > one - check copy_page_to_iter_iovec(). Any caller that does not expect > > a zero return value from that primitive is a bug, triggerable as soon as > > you feed it an iovec with NULL ->iov_base. > > Right. > > I was actually looking at iov_iter_get_pages() callers... FWIW, that's interesting - O_DIRECT readv()/writev() reacts to fault anywhere as "nothing done, return -EFAULT now", rather than a short read/write. Despite that some IO is actually done. Note, BTW, that we are not even consistent between the filesystems - local block ones do IO and give -EFAULT, while NFS, Lustre and FUSE do short read/write, reporting -EFAULT only upon shortening to nothing. So does ceph, except that shortening might be for more than one page. Considering how weak POSIX is in that area, we are probably not violating anything, but... it would be more convenient if we treated those as short read/write, same way for all filesystems. Linus, do you have any objections against such behaviour change? AFAICS, all it takes is this: --- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/direct-io.c b/fs/direct-io.c index 7c3ce73..3a8ebda 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -246,6 +246,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, bool is_async) if ((dio->op == REQ_OP_READ) && ((offset + transferred) > dio->i_size)) transferred = dio->i_size - offset; + if (ret == -EFAULT) + ret = 0; } if (ret == 0)