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 X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 220D4C4320A for ; Tue, 3 Aug 2021 19:19:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08E8060F56 for ; Tue, 3 Aug 2021 19:19:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239843AbhHCTTb (ORCPT ); Tue, 3 Aug 2021 15:19:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52516 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239731AbhHCTTL (ORCPT ); Tue, 3 Aug 2021 15:19:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628018339; 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=NoMbSsZN/tNyp+zwu0JwzF1/xZWL1oDU01iWZBbKHSw=; b=e0e7GRGy5Tuggx+jp1MeT8o0EPqXm/vhiWYalFdp9OX74tmSYXgbxjGiOYiLu5gnMhcSk3 DVm/qWXdauY2edhqTg/3uKnHAVHtR0EN91U0CCQI/aj4zxaklIhrqxNC6dQ5kiY26k9MmP JzI0AFFLQ2tz3rgJVy+KZm2t4wkqjkw= 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-454-Li2gt2TaO2auf2N6DTaiaw-1; Tue, 03 Aug 2021 15:18:58 -0400 X-MC-Unique: Li2gt2TaO2auf2N6DTaiaw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F29D51006C80; Tue, 3 Aug 2021 19:18:56 +0000 (UTC) Received: from max.com (unknown [10.40.193.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B5A060C0F; Tue, 3 Aug 2021 19:18:54 +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 v5 09/12] iomap: Support restarting direct I/O requests after user copy failures Date: Tue, 3 Aug 2021 21:18:15 +0200 Message-Id: <20210803191818.993968-10-agruenba@redhat.com> In-Reply-To: <20210803191818.993968-1-agruenba@redhat.com> References: <20210803191818.993968-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 and fail to allow restarting the request. 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 8054f5d6c273..35c3f2bae65a 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -561,6 +561,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_PARTIAL)) + 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 479c1da3e221..bcae4814b8e3 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_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