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=-6.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 9F11EC4338F for ; Mon, 16 Aug 2021 19:14:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8696660F4B for ; Mon, 16 Aug 2021 19:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbhHPTO5 (ORCPT ); Mon, 16 Aug 2021 15:14:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33206 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbhHPTOz (ORCPT ); Mon, 16 Aug 2021 15:14:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629141263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lWy3l2+IfO7xO6oKpqVQHj7y0vYczHZZ4SIluKLQLb8=; b=YJyhDttYZdTjcGRCCm6w9yFTHcwG8r/HoEac9mMvlxx7UtCgjfeKes8aFtyh1ixUN5fn5Z JdcjMdiAEd7K1ifY5QuMV1Oi5JZponCffUDVcGiXgmHc9I9e8TeiBWt0w/iIAW13Yz15y8 7YbDF7xQJXld5QsPZ2UluZg8bykBwYg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-PWkqwUtVNDOJu6Lhv76KTw-1; Mon, 16 Aug 2021 15:14:22 -0400 X-MC-Unique: PWkqwUtVNDOJu6Lhv76KTw-1 Received: by mail-wm1-f72.google.com with SMTP id g70-20020a1c20490000b02902e6753bf473so103130wmg.0 for ; Mon, 16 Aug 2021 12:14:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lWy3l2+IfO7xO6oKpqVQHj7y0vYczHZZ4SIluKLQLb8=; b=rkOG0qs7BcEqishE6DM4whIr9GLjGPkq/Wa3zrGku/pEbNj3O2Vh5s4vluM5aVCj9W 4F2GobROC6WLgkzpGf7nT9RB0sf5/qOzaygvRmqkcAfSvrW8asGUutH8BK2xyvSsGmLW zC7T9vAjkcvLFmVZ8XhM1U7n54wf5sOl6SNbQfYVL+LFnzB+JliYD8Dh40fKhuhf5+nV 8e4rmANX146DhTz+X/8dr4F8GFRMwiXx79bsYnAf9IUaLHw6wuO5wk/RpGYe8IioT8r0 zS9bruSHwWU8bYiEwccpPxuqZ7X+un+gDHQe7X5GAIkkjYw7rAuZ09ugPQYEomUKG9jR j2Wg== X-Gm-Message-State: AOAM532HJ1K/3VWgCaeSWzB+6PDhaHD4CfW0Q37tDQj1+i40KuJwjGp7 Ajd5sBZLDDvGmSBOoli5Fo7R1R8FlcCn38DE3sEBGT06x3JKdGZVFggfZWMcNHeG3fa0utvfYqJ Tj3+0DJ+1FAUbvMexiC9x0IF61xyaNS3b6NEkpFcR X-Received: by 2002:a5d:674b:: with SMTP id l11mr18978891wrw.357.1629141260958; Mon, 16 Aug 2021 12:14:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3e2hMfKU0iq3mIOu2m32crL3qBkqbuiWv8L806qkeQbGdArMICY3wU0R/Jc0O1nkrsAQGzAuFreIkqVtHZaU= X-Received: by 2002:a5d:674b:: with SMTP id l11mr18978869wrw.357.1629141260774; Mon, 16 Aug 2021 12:14:20 -0700 (PDT) MIME-Version: 1.0 References: <20210803191818.993968-1-agruenba@redhat.com> In-Reply-To: From: Andreas Gruenbacher Date: Mon, 16 Aug 2021 21:14:09 +0200 Message-ID: Subject: Re: [PATCH v5 00/12] gfs2: Fix mmap + page fault deadlocks To: Linus Torvalds Cc: Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Paul Mackerras , Jan Kara , Matthew Wilcox , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com, kvm-ppc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 3, 2021 at 9:45 PM Linus Torvalds wrote: > On Tue, Aug 3, 2021 at 12:18 PM Andreas Gruenbacher wrote: > > With this patch queue, fstest generic/208 (aio-dio-invalidate-failure.c) > > endlessly spins in gfs2_file_direct_write. It looks as if there's a bug > > in get_user_pages_fast when called with FOLL_FAST_ONLY: > > > > (1) The test case performs an aio write into a 32 MB buffer. > > > > (2) The buffer is initially not in memory, so when iomap_dio_rw() -> > > ... -> bio_iov_iter_get_pages() is called with the iter->noio flag > > set, we get to get_user_pages_fast() with FOLL_FAST_ONLY set. > > get_user_pages_fast() returns 0, which causes > > bio_iov_iter_get_pages to return -EFAULT. > > > > (3) Then gfs2_file_direct_write faults in the entire buffer with > > fault_in_iov_iter_readable(), which succeeds. > > > > (4) With the buffer in memory, we retry the iomap_dio_rw() -> > > ... -> bio_iov_iter_get_pages() -> ... -> get_user_pages_fast(). > > This should succeed now, but get_user_pages_fast() still returns 0. > > Hmm. Have you tried to figure out why that "still returns 0" happens? The call stack is: gup_pte_range gup_pmd_range gup_pud_range gup_p4d_range gup_pgd_range lockless_pages_from_mm internal_get_user_pages_fast get_user_pages_fast iov_iter_get_pages __bio_iov_iter_get_pages bio_iov_iter_get_pages iomap_dio_bio_actor iomap_dio_actor iomap_apply iomap_dio_rw gfs2_file_direct_write In gup_pte_range, pte_special(pte) is true and so we return 0. > One option - for debugging only - would be to introduce a new flag to > get_user_pages_fast() that says "print out reason if failed" and make > the retry (but not the original one) have that flag set. > > There are a couple of things of note when it comes to "get_user_pages_fast()": > > (a) some architectures don't even enable it > > (b) it can be very picky about the page table contents, and wants the > accessed bit to already be set (or the dirty bit, in the case of a > write). > > but (a) shouldn't be an issue on any common platform and (b) shouldn't > be an issue with fault_in_iov_iter_readable() that actually does a > __get_user() so it will access through the page tables. > > (It might be more of an issue with fault_in_iov_iter_writable() due to > walking the page tables by hand - if we don't do the proper > access/dirty setting, I could see get_user_pages_fast() failing). > > Anyway, for reason (a) I do think that eventually we should probably > introduce FOLL_NOFAULT, and allow the full "slow" page table walk - > just not calling down to handle_mm_fault() if it fails. > > But (a) should be a non-issue in your test environment, and so it > would be interesting to hear what it is that fails. Because scanning > through the patches, they all _look_ fine to me (apart from the one > comment about return values, which is more about being consistent with > copy_to/from_user() and making the code simpler - not about > correctness) > > Linus > Thanks, Andreas