Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1655543pxv; Fri, 23 Jul 2021 14:01:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKA03liJkkRDRs3UnZm6d1RUdak7lZnwDBZ4bXAB4Srydm9uVaR9zUd55TSflg/91fI1be X-Received: by 2002:a05:6638:14d6:: with SMTP id l22mr5623222jak.99.1627074095797; Fri, 23 Jul 2021 14:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627074095; cv=none; d=google.com; s=arc-20160816; b=R8ylXpOhfzdRDAJkge/u1y2KSEt+XyiGo+QvCE1zOvM20YJOvW7GYYCUUEaA1pP5xa gC/jmh0fGlUlx0zRjUgHBILU2k5zq2LUgsXNV+vcY+QFVW0QggABlAyj5u5dAg50n939 hj3lws+eIR8y15XKwJMlFK6WzBrDfwFfPFo0LQg/qTVTKpc+c9d3CrqGKQ/j77wOgPJx ohKVKCtvuYehy9zoC8p2XlNwf5Cd+HG0LaUwXOYFLYiFVo7yAvpYTjzwZ0KFNJjwl9z2 gfaBOqe1d9XoyNI0AI0hR/7S3xVBH3YMaz49s/mP3Z4ZyAKgK5ygPpNt5n8AQBzs1uE0 AIAw== 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=Z5USnk4oWsRd3FH8wsMXQrumYbkYOqMoj1HmwKEKTOA=; b=T3BqSaAQ3YhyDdweWcHQdU16H1xBGOPV7hZk3RHUKMlK/usUu3GQHpRmZ1F+WEzhmz fstO/tqVdhN403hNy120OHsk183WvJJjWJYdvdy8pZ1MW2UhPlHgtEIUux6VGkfVdT4t rAPSHT7xv/aN8osHzrz7mZBxCPJbaYbnKN1PaE56TBkmqbbVbw2a3hjE7z2SIUYhJ/Ug 9R+ghkszm+vu7U20U/Ox//WHwYrBLve9z3aUTcrrx9Pg5ay7D9Qt9yn6P/RnLgEsotVm KXQgUzewZZDs1gDz+nDRenAIfAItxtWNevMLb8r5UCNogwn62ApNo5HJuNj9O9RCDQbB waig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fTyF858L; 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 u11si45334757jau.121.2021.07.23.14.01.24; Fri, 23 Jul 2021 14:01:35 -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=fTyF858L; 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 S231951AbhGWUSi (ORCPT + 99 others); Fri, 23 Jul 2021 16:18:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22051 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231809AbhGWUSc (ORCPT ); Fri, 23 Jul 2021 16:18:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627073945; 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=Z5USnk4oWsRd3FH8wsMXQrumYbkYOqMoj1HmwKEKTOA=; b=fTyF858LmwykaN7y0rKLfU72dqQ9cosJJqXGQk7cbyHJ7hI2sCtZth2r+GrOnBalFK2vhY c93VndYkWwUjLrV7mqmQTQQ6LJqFEv7Zub/coGFllw9oDqHeChclJ+C6zBaZyqPLrfk9Ip tLmD3vqLdVschgsX7SkL0Y+2sZNJQL8= 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-564-MxGRGdVCMoaYazztEfS8xw-1; Fri, 23 Jul 2021 16:59:03 -0400 X-MC-Unique: MxGRGdVCMoaYazztEfS8xw-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 90B3F1853029; Fri, 23 Jul 2021 20:59:02 +0000 (UTC) Received: from max.com (unknown [10.40.194.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D4C610074FD; Fri, 23 Jul 2021 20:59:00 +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 v3 5/7] iomap: Support restarting direct I/O requests after user copy failures Date: Fri, 23 Jul 2021 22:58:38 +0200 Message-Id: <20210723205840.299280-6-agruenba@redhat.com> In-Reply-To: <20210723205840.299280-1-agruenba@redhat.com> References: <20210723205840.299280-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, complete the request synchronously and reset the iterator to the start position. This allows callers to deal with the failure and retry the operation. In gfs2, we need to disable page faults while we're holding glocks to prevent deadlocks. This patch is the minimum solution I could find to make iomap_dio_rw work with page faults disabled. It's still expensive because any I/O that was carried out before hitting -EFAULT needs to be retried. A possible improvement would be to add an IOMAP_DIO_FAULT_RETRY or similar flag that would allow iomap_dio_rw to return a short result when hitting -EFAULT. Callers could then retry only the rest of the request after dealing with the page fault. Asynchronous requests turn into synchronous requests up to the point of the page fault in any case, but they could be retried asynchronously after dealing with the page fault. To make that work, the completion notification would have to include the bytes read or written before the page fault(s) as well, and we'd need an additional iomap_dio_rw argument for that. Signed-off-by: Andreas Gruenbacher --- fs/iomap/direct-io.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index cc0b4bc8861b..b0a494211bb4 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -561,6 +561,15 @@ __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) { + /* + * To allow retrying the request, fail + * synchronously and reset the iterator. + */ + wait_for_completion = true; + iov_iter_revert(dio->submit.iter, dio->size); + } + /* magic error code to fall back to buffered I/O */ if (ret == -ENOTBLK) { wait_for_completion = true; -- 2.26.3