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=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham 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 4EC1BC43219 for ; Fri, 26 Apr 2019 13:11:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 234322077B for ; Fri, 26 Apr 2019 13:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726044AbfDZNLQ (ORCPT ); Fri, 26 Apr 2019 09:11:16 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:35310 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfDZNLQ (ORCPT ); Fri, 26 Apr 2019 09:11:16 -0400 Received: by mail-ot1-f68.google.com with SMTP id m10so2597574otp.2 for ; Fri, 26 Apr 2019 06:11:15 -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=ZiEqINjWIRfIVbP9F5CJ9LmrqEpNmidWj1MJ0FFZ5/M=; b=mTzA4xhfgPHcUaaVA+AW+pURYHVMMNp2LqXyvAphm49ZVJ6DD+f7EAbzwZaC+jBui9 +sS3fit8C2ceXY6MFW4x+LmCuq7BqqQRiiKymTs6toawx+cX5fFMzmNmsMcHr2drve4R RQScFCb2cahPhJA+C4KqUgVsimI3xhVv/0Vdbbfn7S58vnWX7FowEM55Q2yb6Os5XX7N s4aaIwUpitlgfZQ1ZG7FF4BdxhafcAgR9eLyjyDQFEayEYMiny7zKHb+m2r3ZdhTtnUA YUljdtfLRoJNZh55MPjpFOjbYo94guFw0ISRdRCMLIJ4u9PlMGa4AGtQ3885F9YKDwlh cVYA== X-Gm-Message-State: APjAAAXOxE3zIKkK2v7M0XzH9jOhLaTT3QY7XNSzJD1A3r4K6yov30vb vLJhXCe+58Jq6ccK0gmKpBGaKq7W5HepjEaSgbac/Q== X-Google-Smtp-Source: APXvYqyrBQFW7e0yI6GQM1YP6SGu3J05anOT/doOEscD6yRtuKRQvZxrIcYLjLgJUNCujZUTITvA1SwpvF+uMOD2QtY= X-Received: by 2002:a9d:61c6:: with SMTP id h6mr7568358otk.316.1556284275288; Fri, 26 Apr 2019 06:11:15 -0700 (PDT) MIME-Version: 1.0 References: <20190425160913.1878-1-agruenba@redhat.com> <20190426083016.GA11637@quack2.suse.cz> In-Reply-To: <20190426083016.GA11637@quack2.suse.cz> From: Andreas Gruenbacher Date: Fri, 26 Apr 2019 15:11:03 +0200 Message-ID: Subject: Re: [PATCH v3 1/2] iomap: Add a page_prepare callback To: Jan Kara Cc: cluster-devel , Christoph Hellwig , Bob Peterson , Dave Chinner , Ross Lagerwall , Mark Syms , =?UTF-8?B?RWR3aW4gVMO2csO2aw==?= , linux-fsdevel , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Fri, 26 Apr 2019 at 10:30, Jan Kara wrote: > > On Thu 25-04-19 18:09:12, Andreas Gruenbacher wrote: > > Move the page_done callback into a separate iomap_page_ops structure and > > add a page_prepare calback to be called before a page is written to. In > > gfs2, we'll want to start a transaction in page_prepare and end it in > > page_done, and other filesystems that implement data journaling will > > require the same kind of mechanism. > > ... > > > @@ -674,9 +675,17 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, > > if (fatal_signal_pending(current)) > > return -EINTR; > > > > + if (page_ops) { > > + status = page_ops->page_prepare(inode, pos, len, iomap); > > + if (status) > > + return status; > > + } > > + > > Looks OK for now I guess, although I'm not sure if later some fs won't need > to get hold of the actual page in ->page_prepare() and then we will need to > switch to ->page_prepare() returning the page to use. But let's leave that > for a time when such fs wants to use iomap. Alright. > > @@ -780,8 +794,8 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, > > ret = __iomap_write_end(inode, pos, len, copied, page, iomap); > > } > > > > - if (iomap->page_done) > > - iomap->page_done(inode, pos, copied, page, iomap); > > + if (page_ops) > > + page_ops->page_done(inode, pos, copied, page, iomap); > > Looking at the code now, this is actually flawed (preexisting problem): > __iomap_write_end or generic_write_end() will release the page reference > and so you cannot just pass it to ->page_done(). That is a potential > use-after-free... Ouch. I'm sending a fix. Thanks, Andreas From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Gruenbacher Date: Fri, 26 Apr 2019 15:11:03 +0200 Subject: [Cluster-devel] [PATCH v3 1/2] iomap: Add a page_prepare callback In-Reply-To: <20190426083016.GA11637@quack2.suse.cz> References: <20190425160913.1878-1-agruenba@redhat.com> <20190426083016.GA11637@quack2.suse.cz> Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Fri, 26 Apr 2019 at 10:30, Jan Kara wrote: > > On Thu 25-04-19 18:09:12, Andreas Gruenbacher wrote: > > Move the page_done callback into a separate iomap_page_ops structure and > > add a page_prepare calback to be called before a page is written to. In > > gfs2, we'll want to start a transaction in page_prepare and end it in > > page_done, and other filesystems that implement data journaling will > > require the same kind of mechanism. > > ... > > > @@ -674,9 +675,17 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, > > if (fatal_signal_pending(current)) > > return -EINTR; > > > > + if (page_ops) { > > + status = page_ops->page_prepare(inode, pos, len, iomap); > > + if (status) > > + return status; > > + } > > + > > Looks OK for now I guess, although I'm not sure if later some fs won't need > to get hold of the actual page in ->page_prepare() and then we will need to > switch to ->page_prepare() returning the page to use. But let's leave that > for a time when such fs wants to use iomap. Alright. > > @@ -780,8 +794,8 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, > > ret = __iomap_write_end(inode, pos, len, copied, page, iomap); > > } > > > > - if (iomap->page_done) > > - iomap->page_done(inode, pos, copied, page, iomap); > > + if (page_ops) > > + page_ops->page_done(inode, pos, copied, page, iomap); > > Looking at the code now, this is actually flawed (preexisting problem): > __iomap_write_end or generic_write_end() will release the page reference > and so you cannot just pass it to ->page_done(). That is a potential > use-after-free... Ouch. I'm sending a fix. Thanks, Andreas