Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp476720pxb; Tue, 19 Oct 2021 06:49:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwThlx4JfsGYrjrKHTd3EgAQDYLeCyVgGiTfMNkPvbWEQ6IZvtTUe+ZQfwxuu9GrHe2+7lE X-Received: by 2002:a17:906:3192:: with SMTP id 18mr37669721ejy.246.1634651363910; Tue, 19 Oct 2021 06:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634651363; cv=none; d=google.com; s=arc-20160816; b=OYEUWqSziZ6D9DTBSUtCpUlH9W2kJX/NnwksfYbS4S3JNPPIZ9XqdXTIVumetCtpWK yTt5FRN1IW2sfAHIoLmzCwLtPDrjhR2i/CwXsP6vtrQBPMwlzy0r+xW6lzr7qcVnk0/G blRGQ79Y75wyPrQRb38Vo/hT0aONuH6r86+0RywTnDSpdy28KQdpr5Ah/qW0QcU0AqpQ Ua0Vk9kudCmiBrd3TRZEq+cCfJ+Es+DPSQ/BETbbrAVvKwoEe23zgiZkALXM2gKzMeq1 cIqSpfIQOVMvlwb7xeBlnXPNKRklq7nIhu9XV93zMSRnjXpdEdLQkzLq/4z7DRIkkIzO VEIw== 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=GMMEkGGRgFD/FgwggFSt2zozeSaxloIxf+v0cQoYfqo=; b=pM3SSjIIKN77x8wczWCrUUN/tu9BKYNsCSj/Dk7mMGwInApJfoPYEeFbaghU3v8ZbU JD97m+/FjXe6ggkB5v8/nXtizfN3apjzBLatdCihjJ9AEEj4kx6DdzxkqdqfeFG2UqDx qAURSNHlBEk0WZfG5au+tqCQyPKBk1KVmB/clBBPfY7oB4AGEFxHCwh7v0eV3+CCTYPN Dcq64v2jTBCL59B0mlIoERh3n/mkMaWvIIn4qwubDM9A7uQf9tcvZMZb+PaOdsAs+wSI LGANTiJoA9HZAHlr8O8cEZO6ODhlbAypJZQT0CDOPuectG1eMOWhVroR9INlAmsL3Ke8 DRtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="D/TpC9Cm"; 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 dp18si25291361ejc.464.2021.10.19.06.48.52; Tue, 19 Oct 2021 06:49:23 -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="D/TpC9Cm"; 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 S236000AbhJSNrM (ORCPT + 99 others); Tue, 19 Oct 2021 09:47:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35205 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235960AbhJSNq5 (ORCPT ); Tue, 19 Oct 2021 09:46:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634651084; 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=GMMEkGGRgFD/FgwggFSt2zozeSaxloIxf+v0cQoYfqo=; b=D/TpC9CmfvsCHngFdpDFKRX6Cyuk/+Pys8q6EJFoB+gcXrgUTh9sNWE9BgE866GA5wiBRN uVByVPyV+cWij/SqU9RSt5QI8UGvxjBY/sS7mWR0nWBXtR4NPslR5dQ5NrJhihK0MkaG2R rxqX59t7XZCA9XyrhnXTXN1ztf5/PCU= 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-100-HKKK6yfmOYWiDVVxLiY4bQ-1; Tue, 19 Oct 2021 09:44:41 -0400 X-MC-Unique: HKKK6yfmOYWiDVVxLiY4bQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97A061054F90; Tue, 19 Oct 2021 13:44:38 +0000 (UTC) Received: from max.com (unknown [10.40.193.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id A41DD10016FC; Tue, 19 Oct 2021 13:44:04 +0000 (UTC) From: Andreas Gruenbacher To: Linus Torvalds , Catalin Marinas Cc: Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Paul Mackerras , Jan Kara , Matthew Wilcox , cluster-devel@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, kvm-ppc@vger.kernel.org, linux-btrfs@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH v8 13/17] iomap: Support partial direct I/O on user copy failures Date: Tue, 19 Oct 2021 15:42:00 +0200 Message-Id: <20211019134204.3382645-14-agruenba@redhat.com> In-Reply-To: <20211019134204.3382645-1-agruenba@redhat.com> References: <20211019134204.3382645-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In iomap_dio_rw, when iomap_apply returns an -EFAULT error and the IOMAP_DIO_PARTIAL flag is set, complete the request synchronously and return a partial result. This allows the caller to deal with the page fault and retry the remainder of the request. Signed-off-by: Andreas Gruenbacher Reviewed-by: Darrick J. Wong --- fs/iomap/direct-io.c | 6 ++++++ include/linux/iomap.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index a2a368e824c0..a434fb7887b2 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -581,6 +581,12 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (iov_iter_rw(iter) == READ && iomi.pos >= dio->i_size) iov_iter_revert(iter, iomi.pos - dio->i_size); + if (ret == -EFAULT && dio->size && (dio_flags & IOMAP_DIO_PARTIAL)) { + if (!(iocb->ki_flags & IOCB_NOWAIT)) + wait_for_completion = true; + ret = 0; + } + /* 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 24f8489583ca..2a213b0d1e1f 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -330,6 +330,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_PARTIAL (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); -- 2.26.3