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.5 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 B71B1C43461 for ; Tue, 11 May 2021 15:00:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D30661364 for ; Tue, 11 May 2021 15:00:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D30661364 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7AEAC6B006E; Tue, 11 May 2021 11:00:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75EE76B0070; Tue, 11 May 2021 11:00:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FED76B0072; Tue, 11 May 2021 11:00:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 45D886B0070 for ; Tue, 11 May 2021 11:00:15 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E688C180BD9DF for ; Tue, 11 May 2021 15:00:14 +0000 (UTC) X-FDA: 78129260748.05.EFA9D7F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf29.hostedemail.com (Postfix) with ESMTP id C50B82BC3 for ; Tue, 11 May 2021 15:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620745213; 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=KQy9BmsInGHBuMYQbKGo4/mFyEJldO4Fzjjuu4/Gw90=; b=KFhxB4fcPLKEgw2XuOFH5UBYoBvQuJ+PffL53gY5wC89UEgk+M9YIWcfk+EzaWqqZH4Y71 LixSQPU/oYR8/FI4ST55eXepgcu8ApASlao6wapa1LBPXryLQ0FVW+4KQul9SnotEXTs06 nxVHnR34k8hcFKFeGxX1DRgbTcJ7KW4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-49-hvws1s3FPPCaVECa_bfrMg-1; Tue, 11 May 2021 11:00:12 -0400 X-MC-Unique: hvws1s3FPPCaVECa_bfrMg-1 Received: by mail-wm1-f69.google.com with SMTP id j128-20020a1c55860000b02901384b712094so1170032wmb.2 for ; Tue, 11 May 2021 08:00:11 -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=KQy9BmsInGHBuMYQbKGo4/mFyEJldO4Fzjjuu4/Gw90=; b=mBD0SH3zxoh/QQmmBIcVv3ooF9yIExmctyQAptvJKYVM8wOTOfG4d+O4sO63IEDZLZ o4ARqpcPYmAfyVumOmv0e3ZOor1v9WBEo93ZlQI6CPieG17XqwU8VP3fOU+rnXJ1ngS4 yFWYMDX1HgY3j6ebI17z9kJGbTzhJ/qEfhjSU1MEVRhtLUt6Cz2wmA1lW1BZOIR2t7Sf rqJ/AfkeWJU+GGcGXN/22pCJDmrnhyU+IdEjiye/TBH6tqZro+lS60I5GefeYtmXFkL/ RLxc59oDerXM2/n/I94uB2CN45I2lpFmo4DvReD8YdBTEl/Njfoie4tYJDBa2G67IY7j CB4w== X-Gm-Message-State: AOAM533JuoPTvsn9ZR4KSXnWiceWNXohbDHr/qyP9VuP/U8G+dxqEcz2 3BwPsv/uCRfr+lXIZSKZAkus98+LsKAyB50FjBulxwIt+vh6TtYj+EPuU3Sa7PZsf5rZ3ddbbQk J1LGXrEAc6ucZTrhPiPTOqtJzgKI= X-Received: by 2002:a05:600c:21d5:: with SMTP id x21mr6111956wmj.149.1620745210693; Tue, 11 May 2021 08:00:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgE6ifBgFWpvncB4Yp/ueaUboNmb37R0/BTIg4dy1wyIvx0+2z3v12HkdeJg8oHTVE/aiLRx0h5iTD71Z5u+Q= X-Received: by 2002:a05:600c:21d5:: with SMTP id x21mr6111920wmj.149.1620745210398; Tue, 11 May 2021 08:00:10 -0700 (PDT) MIME-Version: 1.0 References: <20210511140113.1225981-1-agruenba@redhat.com> In-Reply-To: From: Andreas Gruenbacher Date: Tue, 11 May 2021 16:59:59 +0200 Message-ID: Subject: Re: [PATCH] [RFC] Trigger retry from fault vm operation To: Matthew Wilcox Cc: linux-fsdevel , cluster-devel , Linux-MM , LKML , Jan Kara X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KFhxB4fc; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf29.hostedemail.com: domain of agruenba@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=agruenba@redhat.com X-Stat-Signature: zm5w1s97tq18gubajdkfgngqp6fa9j7s X-Rspamd-Queue-Id: C50B82BC3 X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620745207-450811 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, May 11, 2021 at 4:34 PM Matthew Wilcox wrote: > On Tue, May 11, 2021 at 04:01:13PM +0200, Andreas Gruenbacher wrote: > > we have a locking problem in gfs2 that I don't have a proper solution for, so > > I'm looking for suggestions. > > > > What's happening is that a page fault triggers during a read or write > > operation, while we're holding a glock (the cluster-wide gfs2 inode > > lock), and the page fault requires another glock. We can recognize and > > handle the case when both glocks are the same, but when the page fault requires > > another glock, there is a chance that taking that other glock would deadlock. > > So we're looking at something like one file on a gfs2 filesystem being > mmaped() and then doing read() or write() to another gfs2 file with the > mmaped address being the passed to read()/write()? Yes, those kinds of scenarios. Here's an example that Jan Kara came up with: Two independent processes P1, P2. Two files F1, F2, and two mappings M1, M2 where M1 is a mapping of F1, M2 is a mapping of F2. Now P1 does DIO to F1 with M2 as a buffer, P2 does DIO to F2 with M1 as a buffer. They can race like: P1 P2 read() read() gfs2_file_read_iter() gfs2_file_read_iter() gfs2_file_direct_read() gfs2_file_direct_read() locks glock of F1 locks glock of F2 iomap_dio_rw() iomap_dio_rw() bio_iov_iter_get_pages() bio_iov_iter_get_pages() gfs2_fault() gfs2_fault() tries to grab glock of F2 tries to grab glock of F1 With cluster-wide locks, we can obviously end up with distributed deadlock scenarios as well, of course. > Have you looked at iov_iter_fault_in_readable() as a solution to > your locking order? That way, you bring the mmaped page in first > (see generic_perform_write()). Yes. The problem there is that we need to hold the inode glock from ->iomap_begin to ->iomap_end; that's what guarantees that the mapping returned by ->iomap_begin remains valid. > > When we realize that we may not be able to take the other glock in gfs2_fault, > > we need to communicate that to the read or write operation, which will then > > drop and re-acquire the "outer" glock and retry. However, there doesn't seem > > to be a good way to do that; we can only indicate that a page fault should fail > > by returning VM_FAULT_SIGBUS or similar; that will then be mapped to -EFAULT. > > We'd need something like VM_FAULT_RESTART that can be mapped to -EBUSY so that > > we can tell the retry case apart from genuine -EFAULT errors. > > We do have VM_FAULT_RETRY ... does that retry at the wrong level? There's also VM_FAULT_NOPAGE, but that only triggers a retry at the VM level and doesn't propagate out far enough. My impression is that VM_FAULT_RETRY is similar to VM_FAULT_NOPAGE except that it allows the lock dropping optimization implemented in maybe_unlock_mmap_for_io(). That error code can also only be used when FAULT_FLAG_ALLOW_RETRY is set it seems. Correct me if I'm getting this wrong. Thanks, Andreas