Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1088807imm; Wed, 23 May 2018 10:04:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqYODxjR75FEx3ZXAJTe0rd3o08jiHdk11XhdWeITCHYGpdfPGgyatqDromU9F6hq0sRwF3 X-Received: by 2002:a17:902:781:: with SMTP id 1-v6mr3787305plj.150.1527095098059; Wed, 23 May 2018 10:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527095098; cv=none; d=google.com; s=arc-20160816; b=exwietc0vqY12607ik9LRgqFB2m2pbSjP1tKSCRYvuulUFOjLyOIyLN1qYvV1Km0pP NVyAeajiJdOTLl40GBLFnKHM5pOGkCQOZqy71EECzA8yGfrQngHN+VlwBkDSUN1RzYRD CluwHxQIpJjKsOXLV9aJN43K4x811DXF+l9zPNgV8Rk1va3dzTKn3YZoOm7VR/Rlzk1x A/m7XM8VACjJq1kwa2dWh8/tLHrsxL7tC6R1Db07y/jXUkNFDOkImzDrCUb4SdgwGmlo WilJ5ZyCN3GX76Uigc0cDCy9gDBVoq6eUG2aXT3P6lk3XKPiH4Zkn+UFcZErefCsRLHw OQqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=5s8amwJ6ZhkgysovByNKbfJ+OuTpba5ljvqv1X7H/8k=; b=mJLk2hf09sQF1QQSfr0No+L9AldwmV0j1UKY0VfvkUDujtw0DmeKzE8U6gCzTgTa0t JzWdG92HuzCm4Uo/DNTrjHetD5v9HJQcNaB1do/3P2Mlgi+0ICGGNHYltXdFGR/B70Z0 aCjwA03JOQd3NsR0apFOuZHWAaDkws8JIe1Dl6DC4ECPKV+gpCXL/82SyEh9y7ELiCqB gYYz3dof7ec6zQbgPo0lvxP02HxIxWlBCrf7mi89pNGK3i+yxJhEdkP59InYhSxhU5Qe WUq9gUdWlQ1K9W+MKzJVu2cYIZczNmw65KFsqjTdHi24+1s97+EZ1IDM//LUWCZ3Ss0/ CG2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 94-v6si16662879pla.500.2018.05.23.10.04.25; Wed, 23 May 2018 10:04:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933739AbeEWREH (ORCPT + 99 others); Wed, 23 May 2018 13:04:07 -0400 Received: from mga18.intel.com ([134.134.136.126]:37707 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932649AbeEWRED (ORCPT ); Wed, 23 May 2018 13:04:03 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2018 10:04:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,433,1520924400"; d="scan'208";a="49426336" Received: from theros.lm.intel.com (HELO linux.intel.com) ([10.232.112.164]) by fmsmga002.fm.intel.com with ESMTP; 23 May 2018 10:04:02 -0700 Date: Wed, 23 May 2018 11:04:02 -0600 From: Ross Zwisler To: Dan Williams Cc: Ross Zwisler , linux-nvdimm , "Luck, Tony" , Peter Zijlstra , Linux Kernel Mailing List , X86 ML , Christoph Hellwig , Andy Lutomirski , Ingo Molnar , Borislav Petkov , Al Viro , linux-fsdevel , Thomas Gleixner , Linus Torvalds , Andrew Morton Subject: Re: [PATCH v3 7/9] dax: report bytes remaining in dax_iomap_actor() Message-ID: <20180523170402.GA1847@linux.intel.com> Mail-Followup-To: Ross Zwisler , Dan Williams , linux-nvdimm , "Luck, Tony" , Peter Zijlstra , Linux Kernel Mailing List , X86 ML , Christoph Hellwig , Andy Lutomirski , Ingo Molnar , Borislav Petkov , Al Viro , linux-fsdevel , Thomas Gleixner , Linus Torvalds , Andrew Morton References: <152539236455.31796.7516599166555186700.stgit@dwillia2-desk3.amr.corp.intel.com> <152539240242.31796.4162676712193177396.stgit@dwillia2-desk3.amr.corp.intel.com> <20180523163442.GB29519@linux.intel.com> <20180523164708.GD29519@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 23, 2018 at 09:53:38AM -0700, Dan Williams wrote: > On Wed, May 23, 2018 at 9:47 AM, Ross Zwisler > wrote: > > On Wed, May 23, 2018 at 09:39:04AM -0700, Dan Williams wrote: > >> On Wed, May 23, 2018 at 9:34 AM, Ross Zwisler > >> wrote: > >> > On Thu, May 03, 2018 at 05:06:42PM -0700, Dan Williams wrote: > >> >> In preparation for protecting the dax read(2) path from media errors > >> >> with copy_to_iter_mcsafe() (via dax_copy_to_iter()), convert the > >> >> implementation to report the bytes successfully transferred. > >> >> > >> >> Cc: > >> >> Cc: Ingo Molnar > >> >> Cc: Borislav Petkov > >> >> Cc: Tony Luck > >> >> Cc: Al Viro > >> >> Cc: Thomas Gleixner > >> >> Cc: Andy Lutomirski > >> >> Cc: Peter Zijlstra > >> >> Cc: Andrew Morton > >> >> Cc: Linus Torvalds > >> >> Signed-off-by: Dan Williams > >> >> --- > >> >> fs/dax.c | 20 +++++++++++--------- > >> >> 1 file changed, 11 insertions(+), 9 deletions(-) > >> >> > >> >> diff --git a/fs/dax.c b/fs/dax.c > >> >> index a64afdf7ec0d..34a2d435ae4b 100644 > >> >> --- a/fs/dax.c > >> >> +++ b/fs/dax.c > >> >> @@ -991,6 +991,7 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, > >> >> struct iov_iter *iter = data; > >> >> loff_t end = pos + length, done = 0; > >> >> ssize_t ret = 0; > >> >> + size_t xfer; > >> >> int id; > >> >> > >> >> if (iov_iter_rw(iter) == READ) { > >> >> @@ -1054,19 +1055,20 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, > >> >> * vfs_write(), depending on which operation we are doing. > >> >> */ > >> >> if (iov_iter_rw(iter) == WRITE) > >> >> - map_len = dax_copy_from_iter(dax_dev, pgoff, kaddr, > >> >> + xfer = dax_copy_from_iter(dax_dev, pgoff, kaddr, > >> >> map_len, iter); > >> >> else > >> >> - map_len = dax_copy_to_iter(dax_dev, pgoff, kaddr, > >> >> + xfer = dax_copy_to_iter(dax_dev, pgoff, kaddr, > >> >> map_len, iter); > >> >> - if (map_len <= 0) { > >> >> - ret = map_len ? map_len : -EFAULT; > >> >> - break; > >> >> - } > >> >> > >> >> - pos += map_len; > >> >> - length -= map_len; > >> >> - done += map_len; > >> >> + pos += xfer; > >> >> + length -= xfer; > >> >> + done += xfer; > >> >> + > >> >> + if (xfer == 0) > >> >> + ret = -EFAULT; > >> >> + if (xfer < map_len) > >> >> + break; > >> > > >> > I'm confused by this error handling. So if we hit an error on a given iov and > >> > we don't transfer the expected number of bytes, we have two cases: > >> > > >> > 1) We transferred *something* on this iov but not everything - return success. > >> > 2) We didn't transfer anything on this iov - return -EFAULT. > >> > > >> > Both of these are true regardless of data transferred on previous iovs. > >> > > >> > Why the distinction? If a given iov is interrupted, regardless of whether it > >> > transferred 0 bytes or 1, shouldn't the error path be the same? > >> > >> This is is the semantics of read(2) / write(2). Quoting the pwrite man page: > >> > >> Note that is not an error for a successful call to > >> transfer fewer bytes than > >> requested (see read(2) and write(2)). > > > > Consider this case: > > > > I have 4 IOVs, each of a full page. The first three transfer their full page, > > but on the third we hit an error. > > > > If we transferred 0 bytes in the fourth page, we'll return -EFAULT. > > > > If we transferred 1 byte in the fourth page, we'll return the total length > > transferred, so 3 pages + 1 byte. > > > > Why? pwrite(2) says it returns the number of bytes written, which can be less > > than the total requested. Why not just return the length transferred in both > > cases, instead of returning -EFAULT for one of them? > > Ah, now I see. Yes, that's a bug. Once we have successfully completed > any iovec we should be returning bytes transferred not -EFAULT. Actually, your code is fine. This is handled by the: return done ? done : ret; at the end of the function. So if we've transferred any data at all, we'll return the number of bytes transferred, and if we didn't we'll return -EFAULT because 0 is the special case which means EOF according to pread(2)/pwrite(2). Looks good, then. Thanks for answering my questions. Reviewed-by: Ross Zwisler