Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2333570pxv; Sat, 24 Jul 2021 12:41:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4I16Q3Z7MEWW9OIJshToHu0BHvnQGitpqScsWghv3jPyj1CEM8UMgyk16IefQSjqK6sRR X-Received: by 2002:aa7:df12:: with SMTP id c18mr12744756edy.62.1627155669303; Sat, 24 Jul 2021 12:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627155669; cv=none; d=google.com; s=arc-20160816; b=R5XO9HQs1nsPtKpCUwgyFSdva2tVkNO5kBk5+1mDgaVFYl+zfI7hYMwnQ9L+g7IXPv kp9ZYNTTSEeIzPrjaMncZAEQdTUkpgiNb2Tl3ur/V+AP7y6LTEoxlBGrluY6Hd025Gle Vo34ppMZ1hQjxfMEE04JXGBMgBe7tDgirO+4TYUbf5k7pevVeUWT362C1cvEgWWq62nF nyEmQuYfVkdpdtqkW/ARBjdNmkgfzBFE5sbYTkbcVm/4QNju57XhmJXcg+uWMrKj+SZy aAQaQzJFKjGumyyJkUp6wG11TnkaGQI2TkpPdGpHHx8VEEf7LWHKK5jr7/9mO+GUCKnR NcuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FlV78agUrABREXpDwHnFobASjjrmkrmXAkGCJNUidbE=; b=cMophNg/OF/jB6KpOXuW9An6/H+75LEHdEYJon1XNDrCrhxWCEKAaeUFYRRcdTH4HW flCuu0SiR5fxMGNALlNRsBVUiGTP/pqLNDHU1iqQGy/mfMICYGfbJJmxmqTVgaDa6Z/K axWY6FhhTaa29aXaS5W3X+1FV4YG+nAlMbKB7UD69trUQtjsaAEJ4ZGCXh1fqtJvJDbS jlC5HRzylgVabW26NMNtiCWyM7MvOKxZqlFk6P5LOew0py01VnDTfXPCJ4RAv04Vftme LFZ8qznu/1TqETshrTvvdbFI40VIrlkGnTqozslMbY4x9/eWzv7CuVQhitdcOCxXNpTg 8FOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YyLsbm0H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w7si2527518edc.94.2021.07.24.12.40.46; Sat, 24 Jul 2021 12:41:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YyLsbm0H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbhGXSzA (ORCPT + 99 others); Sat, 24 Jul 2021 14:55:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35031 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbhGXSyy (ORCPT ); Sat, 24 Jul 2021 14:54:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627155325; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FlV78agUrABREXpDwHnFobASjjrmkrmXAkGCJNUidbE=; b=YyLsbm0HpN4TknOPvoz7M/Q+4oEVdRtMrZRkW52ePKlr9VVmlpD09WXxEYzQMIDJl3QdmN rmVKafK7I+5XIxVZ/Hg1Sa/BN3Qp9noRXarr6439qptzzUBQ5o46grc/t4QGyeutXCamK1 LG9uSbyi5H9Cv3TFy0KKsM7vPgaaaNY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143--w01YonrMLiV3vWGsDxy9g-1; Sat, 24 Jul 2021 15:35:21 -0400 X-MC-Unique: -w01YonrMLiV3vWGsDxy9g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE26C1084F55; Sat, 24 Jul 2021 19:35:19 +0000 (UTC) Received: from max.com (unknown [10.40.194.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78D92544F1; Sat, 24 Jul 2021 19:35:17 +0000 (UTC) From: Andreas Gruenbacher To: Linus Torvalds , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" Cc: Jan Kara , Matthew Wilcox , cluster-devel@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, Andreas Gruenbacher Subject: [PATCH v4 6/8] iomap: Support restarting direct I/O requests after user copy failures Date: Sat, 24 Jul 2021 21:34:47 +0200 Message-Id: <20210724193449.361667-7-agruenba@redhat.com> In-Reply-To: <20210724193449.361667-1-agruenba@redhat.com> References: <20210724193449.361667-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In iomap_dio_rw, when iomap_apply returns an -EFAULT error, complete the request synchronously. Either return a partial result (when the IOMAP_DIO_FAULT_RETRY flag is set and the caller is thus prepared to handle partial results), or reset the iterator to the start to allow a restart. Signed-off-by: Andreas Gruenbacher --- fs/iomap/direct-io.c | 13 +++++++++++++ include/linux/iomap.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 51831ce93f6e..1ba825bab08b 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -565,6 +565,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, ret = iomap_apply(inode, pos, count, iomap_flags, ops, dio, iomap_dio_actor); if (ret <= 0) { + if (ret == -EFAULT) { + /* + * Finish synchronously and revert the iterator + * when failing the request to allow a retry. + */ + wait_for_completion = true; + if (dio->size && + (dio_flags & IOMAP_DIO_FAULT_RETRY)) + ret = 0; + else + iov_iter_revert(iter, dio->size); + } + /* magic error code to fall back to buffered I/O */ if (ret == -ENOTBLK) { wait_for_completion = true; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 8aea35f1a003..9dbba9f7c945 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -267,6 +267,13 @@ struct iomap_dio_ops { */ #define IOMAP_DIO_OVERWRITE_ONLY (1 << 1) +/* + * When a page fault occurs, return a partial synchronous result and allow + * the caller to retry the rest of the operation after dealing with the page + * fault. + */ +#define IOMAP_DIO_FAULT_RETRY (1 << 2) + ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, size_t done_before); -- 2.26.3