Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp407764ybm; Tue, 26 May 2020 21:14:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKG0AwTImBDLrJtOHUfgoO2InkOuw6C3dXpyoJTLLb/wQLZLAqCvm/OGxJNyZ8mBIUWeZY X-Received: by 2002:aa7:da98:: with SMTP id q24mr18218888eds.259.1590552855506; Tue, 26 May 2020 21:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590552855; cv=none; d=google.com; s=arc-20160816; b=zcglAIAkvQcLYE298nqhMxX8bKFsttd7L0vGlr23bhr/JujGZSOheF04hvd7s0Li2Y 2tquaG/TRdWeKmgE0qtkrWiMapgSHdcR5QdASgtQSyO0dkKWer0rE+96+Sc2btvpoaRp Ybl7fUARlMTC0eDRdl6hRQk/Z94iaCXac0x+ay4sh8MB/eOBe4Wi1glgTc4/oVyVBQax FDbA9puD92vj2dCeBfnH/I3LYbL70cguMf7IGnY30Nr8Vr7vQYnOPrDHzy8/6NGswg1h JeHzLRZ5aifTnkJkrlYKRllfJuqiVlRamPX5JfGYkrXpQvuO3Q1snbaO4IApW0xpYiiy bOFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0jK21EhVqfBvbPITLkn+96MTGZW6Bo0ptE3mNnDRD3A=; b=IS2w7W3d6dTd9znbusYCmPef7kF//zQSZqUaZZVXdftMPf9PSmkwz2I51l+Q044/o0 h69IV3a126Lx8bqGR64/z9x2s795TSVv4V60lOqoznvbJ5f94QSpKhPW0frZyLJMjHLg NuWJat3eGPT+S3RAGuyWw0YJ+Ew3IL0dbIM+RiLyXN6sdxgIrnkzHbbqPJ3ZD/4vaiDi IjcEQikUhuIWGrFWvDCR3N7TLmjFixgkAa2OjOYFAbB4px9i9tliT1QS6wpBdiTd3vGU pjV+cYDlpr17fz6tuLnVIl1LJhOpIYEzL2a3842sDchPOWJ7vyMA1732EQsRv9zVmE0B Y13g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@omnibond-com.20150623.gappssmtp.com header.s=20150623 header.b=VJFY+sE6; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a21si1103590ejx.547.2020.05.26.21.13.52; Tue, 26 May 2020 21:14:15 -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=@omnibond-com.20150623.gappssmtp.com header.s=20150623 header.b=VJFY+sE6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389789AbgEZVyU (ORCPT + 99 others); Tue, 26 May 2020 17:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389025AbgEZVyS (ORCPT ); Tue, 26 May 2020 17:54:18 -0400 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40213C061A0F for ; Tue, 26 May 2020 14:54:17 -0700 (PDT) Received: by mail-vs1-xe43.google.com with SMTP id 62so12702741vsi.2 for ; Tue, 26 May 2020 14:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omnibond-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0jK21EhVqfBvbPITLkn+96MTGZW6Bo0ptE3mNnDRD3A=; b=VJFY+sE6R0lEkr2FcepjY3oBdZps0iISn6dQY5y2gFvrCz2MSn+lg0Aw+uDaS/9/K0 +fZwAZx9BypRwHJ5b5N2BEeEZyeipRgosXa0XlUo9pjdLYPG1fSAaMdUk96eMjNpibvN sDrOL4pEyDyi4h6gTIgKVUwNpMNz18HQr7oWqcjlAzA/rZPn1wFrocCdJe7W0BrPJnJK oEgCcRj6+GWXgVuL8ADPu1yXjAz7mj+yFngENH/Jcq0haWcO11IshEC4nog2VKbuUApP 6D8BcyICqXQJE8snuXfTXHHUKWTlc3Ac3y1G2MKe2ow4emUmUJRcYUjMrC973SHCcKXr QCAw== 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=0jK21EhVqfBvbPITLkn+96MTGZW6Bo0ptE3mNnDRD3A=; b=T+RXYlPk27W6AkFDrpIKAs/JIBzaW8cGhdomQMy5Ktr8eAG3C4896VjA/NAb21rXbq obKor6w7rXBQipJx7RR4tb4cU+sSVs3uMEAK1lWpHBQK34irRycBjvknInrAjKm/17I4 JnqufsU7NIQAYzvELPt8ki/8wUgujKvXnLLUE5KJ2a3H/9l2klZhJJHSSr/KpA2/+cIv MJCmqKJeQ7JGWSDK1+7voqporXb0I38fiIz/wU9mRl52UmksSsuYZdgZzJnBEmTJx/7O r0BNGP5QODdKIvzqS1xJ0mhln0bEgLzgrq4fqDr9Yq2rR16BRRtBqRx2z84ipRDhRS50 j2DQ== X-Gm-Message-State: AOAM533QFUiU+m5Fw79UMj+6bTrO12RSwA3DocA2PyQi1ghrT2+xTrYa UWADZujxEkfeF3leJ+CG0Bl4GLtP9GjVnvqUrORfGw== X-Received: by 2002:a05:6102:20cb:: with SMTP id i11mr2618905vsr.137.1590530055726; Tue, 26 May 2020 14:54:15 -0700 (PDT) MIME-Version: 1.0 References: <20200517214718.468-1-guoqing.jiang@cloud.ionos.com> <20200517214718.468-9-guoqing.jiang@cloud.ionos.com> In-Reply-To: <20200517214718.468-9-guoqing.jiang@cloud.ionos.com> From: Mike Marshall Date: Tue, 26 May 2020 17:54:04 -0400 Message-ID: Subject: Re: [PATCH 08/10] orangefs: use attach/detach_page_private To: Guoqing Jiang Cc: Andrew Morton , Al Viro , linux-fsdevel , LKML , Dave Chinner , Christoph Hellwig , Matthew Wilcox , Martin Brandenburg , devel@lists.orangefs.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I apologize for not mentioning that I ran this patch set through orangefs xfstests at 5.7 rc5 with no problems or regressions. -Mike On Sun, May 17, 2020 at 5:47 PM Guoqing Jiang wrote: > > Since the new pair function is introduced, we can call them to clean the > code in orangefs. > > Cc: Mike Marshall > Cc: Martin Brandenburg > Cc: devel@lists.orangefs.org > Signed-off-by: Guoqing Jiang > --- > No change since RFC V3. > > RFC V2 -> RFC V3 > 1. rename clear_page_private to detach_page_private. > > RFC -> RFC V2 > 1. change the name of new functions to attach/clear_page_private. > 2. avoid potential use-after-free as suggested by Dave Chinner. > > fs/orangefs/inode.c | 32 ++++++-------------------------- > 1 file changed, 6 insertions(+), 26 deletions(-) > > diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c > index 12ae630fbed7..48f0547d4850 100644 > --- a/fs/orangefs/inode.c > +++ b/fs/orangefs/inode.c > @@ -62,12 +62,7 @@ static int orangefs_writepage_locked(struct page *page, > } else { > ret = 0; > } > - if (wr) { > - kfree(wr); > - set_page_private(page, 0); > - ClearPagePrivate(page); > - put_page(page); > - } > + kfree(detach_page_private(page)); > return ret; > } > > @@ -409,9 +404,7 @@ static int orangefs_write_begin(struct file *file, > wr->len = len; > wr->uid = current_fsuid(); > wr->gid = current_fsgid(); > - SetPagePrivate(page); > - set_page_private(page, (unsigned long)wr); > - get_page(page); > + attach_page_private(page, wr); > okay: > return 0; > } > @@ -459,18 +452,12 @@ static void orangefs_invalidatepage(struct page *page, > wr = (struct orangefs_write_range *)page_private(page); > > if (offset == 0 && length == PAGE_SIZE) { > - kfree((struct orangefs_write_range *)page_private(page)); > - set_page_private(page, 0); > - ClearPagePrivate(page); > - put_page(page); > + kfree(detach_page_private(page)); > return; > /* write range entirely within invalidate range (or equal) */ > } else if (page_offset(page) + offset <= wr->pos && > wr->pos + wr->len <= page_offset(page) + offset + length) { > - kfree((struct orangefs_write_range *)page_private(page)); > - set_page_private(page, 0); > - ClearPagePrivate(page); > - put_page(page); > + kfree(detach_page_private(page)); > /* XXX is this right? only caller in fs */ > cancel_dirty_page(page); > return; > @@ -535,12 +522,7 @@ static int orangefs_releasepage(struct page *page, gfp_t foo) > > static void orangefs_freepage(struct page *page) > { > - if (PagePrivate(page)) { > - kfree((struct orangefs_write_range *)page_private(page)); > - set_page_private(page, 0); > - ClearPagePrivate(page); > - put_page(page); > - } > + kfree(detach_page_private(page)); > } > > static int orangefs_launder_page(struct page *page) > @@ -740,9 +722,7 @@ vm_fault_t orangefs_page_mkwrite(struct vm_fault *vmf) > wr->len = PAGE_SIZE; > wr->uid = current_fsuid(); > wr->gid = current_fsgid(); > - SetPagePrivate(page); > - set_page_private(page, (unsigned long)wr); > - get_page(page); > + attach_page_private(page, wr); > okay: > > file_update_time(vmf->vma->vm_file); > -- > 2.17.1 >