From patchwork Thu Aug 19 19:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1518827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XHUEo+oc; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GrFWJ6WHSz9sXN for ; Fri, 20 Aug 2021 05:41:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234121AbhHSTlw (ORCPT ); Thu, 19 Aug 2021 15:41:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31469 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233919AbhHSTlv (ORCPT ); Thu, 19 Aug 2021 15:41:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629402075; 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; bh=KbLSMirlq5Y+iVmHzWlYIbw7fbWKCdO5EJW42CUPvac=; b=XHUEo+ochMOuxLW/JV0DiwrbSFE63Vqf8jdifT2AVgELKSbWZV5aVlUbx6flgsoOKTVHVM KpkZMmKCJ143MQcrawgqoiq2u3jiHwn3/pf7mqoy+ayoPXOhVBIv0prCwy7EUnD3mhL8fE c0LCd1b3zs08IlxqJdfA2z/AkIx9Ins= 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-461-FXi0vIJyP16Ci7bMW74UjQ-1; Thu, 19 Aug 2021 15:41:13 -0400 X-MC-Unique: FXi0vIJyP16Ci7bMW74UjQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E568A801AC5; Thu, 19 Aug 2021 19:41:11 +0000 (UTC) Received: from max.com (unknown [10.40.194.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56EED1B46B; Thu, 19 Aug 2021 19:41:05 +0000 (UTC) From: Andreas Gruenbacher To: Linus Torvalds , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Paul Mackerras 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 , kvm-ppc@vger.kernel.org Subject: [PATCH v6 00/19] gfs2: Fix mmap + page fault deadlocks Date: Thu, 19 Aug 2021 21:40:43 +0200 Message-Id: <20210819194102.1491495-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org Hi all, here's another update on top of v5.14-rc6. Changes: * Per request from Linus, change fault_in_{readable,writeable} to return the number of bytes *not* faulted in, like copy_to_user() and copy_from_user() does. Convert fault_in_iov_iter_readable and fault_in_iov_iter_writeable to those same semantics. * Per suggestion from Linus, introduce a new FOLL_NOFAULT flag to prevent get_user_pages from faulting in pages. This is similar to FOLL_FAST_ONLY, but less fragile and available on all architectures. Use that for turning off page faults during iov_iter_get_pages() and iov_iter_get_pages_alloc(). * Introduce a new HIF_MAY_DEMOTE flag that allows a glock to be taken away from a holder when a conflicting locking request comes in. This allows glock holders to hang on to glocks as long as no conflicting locking requests occur. This avoids returning short reads and writes when pages need to be faulted in. * Limit the number of pages that are faulted in at once to a more sensible size instead of faulting in all pages at once. When faulting in pages doesn't lead to success, fault in a single page in the next attempt. When that still doesn't succeed, give up. This should prevent endless loops when fault_in_iov_iter_*() and bio_iov_iter_get_pages() disagree. * It turns out that taking the inode glock in gfs2_write_lock and releasing it in gfs2_write_unlock was entirely pointless, so move the locking into gfs2_file_buffered_write instead. This then also allows to eliminate ip->i_gh. This iteration fixes the issues with fstest generic/208. For immediate consideration by Al Viro: iov_iter: Fix iov_iter_get_pages{,_alloc} page fault return value For immediate consideration by Paul Mackerras: powerpc/kvm: Fix kvm_use_magic_page Thanks, Andreas Andreas Gruenbacher (16): iov_iter: Fix iov_iter_get_pages{,_alloc} page fault return value powerpc/kvm: Fix kvm_use_magic_page Turn fault_in_pages_{readable,writeable} into fault_in_{readable,writeable} Turn iov_iter_fault_in_readable into fault_in_iov_iter_readable iov_iter: Introduce fault_in_iov_iter_writeable gfs2: Add wrapper for iomap_file_buffered_write gfs2: Clean up function may_grant gfs2: Move the inode glock locking to gfs2_file_buffered_write gfs2: Fix mmap + page fault deadlocks for buffered I/O iomap: Fix iomap_dio_rw return value for user copies iomap: Support partial direct I/O on user copy failures iomap: Add done_before argument to iomap_dio_rw gup: Introduce FOLL_NOFAULT flag to disable page faults iov_iter: Introduce nofault flag to disable page faults gfs2: Fix mmap + page fault deadlocks for direct I/O gfs2: Eliminate ip->i_gh Bob Peterson (3): gfs2: Eliminate vestigial HIF_FIRST gfs2: Remove redundant check from gfs2_glock_dq gfs2: Introduce flag for glock holder auto-demotion arch/powerpc/kernel/kvm.c | 3 +- arch/powerpc/kernel/signal_32.c | 4 +- arch/powerpc/kernel/signal_64.c | 2 +- arch/x86/kernel/fpu/signal.c | 7 +- drivers/gpu/drm/armada/armada_gem.c | 7 +- fs/btrfs/file.c | 7 +- fs/btrfs/ioctl.c | 5 +- fs/ext4/file.c | 5 +- fs/f2fs/file.c | 2 +- fs/fuse/file.c | 2 +- fs/gfs2/bmap.c | 60 +---- fs/gfs2/file.c | 244 ++++++++++++++++++-- fs/gfs2/glock.c | 340 +++++++++++++++++++++------- fs/gfs2/glock.h | 20 ++ fs/gfs2/incore.h | 5 +- fs/iomap/buffered-io.c | 2 +- fs/iomap/direct-io.c | 21 +- fs/ntfs/file.c | 2 +- fs/xfs/xfs_file.c | 6 +- fs/zonefs/super.c | 4 +- include/linux/iomap.h | 11 +- include/linux/mm.h | 3 +- include/linux/pagemap.h | 58 +---- include/linux/uio.h | 4 +- lib/iov_iter.c | 103 +++++++-- mm/filemap.c | 4 +- mm/gup.c | 139 +++++++++++- 27 files changed, 784 insertions(+), 286 deletions(-)