Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2310734ybz; Thu, 30 Apr 2020 14:55:00 -0700 (PDT) X-Google-Smtp-Source: APiQypLOElbm9NLnGcjuDD8+rlSK4PuKf48SwQAoa5kzRe7hZoDGo7fKXg1a0MFazSUHPQ+CCcCN X-Received: by 2002:a17:906:4310:: with SMTP id j16mr563846ejm.102.1588283700151; Thu, 30 Apr 2020 14:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588283700; cv=none; d=google.com; s=arc-20160816; b=YVp+rgFcEzp5uiXdcJvRBr4MrZkvxN7Gn3VB9woQf/v7hJZlTcxrxB+dQZn7sfRanj ma0WHcstDoA9sluPCPpEHa35S46EKZtMoyGL5QmNFCwJMCP5dvt6YYlE5PxdldwuRkJx J1IzNTcoxBgas2BERRNTi58b2JnlI3UaQxtEPPqjbYI+Gw2FOC50xIEn4T2+ZRl8hFP7 1xclknUU5L9W+zLy1MuI+6WErw0n+RJGgbnAn09XQBJ+mphtXdObvuCi16BlcsH9DaVj bE2K1CbSPieqQuF6uCWu7ThvKYbyikjH7gDgIpX5Yj/vn6s9Xt3KXrFaA9LT687s8U/M sNdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=0x0u2gx9fn/eR0FN5+bPGwv0n6eHZLnbohIE4ZZX1xA=; b=XPxzw/6QEe3cthdgkwJHvPHEhRCX+kVw8igeJ8Im5JRcSeP8NpmcvH9iWtW1V393Lv pkqZLmayJtl+Uthx7/0DI9O5CnBKoqKIJW8WRHwBnN2FWL1yf927gRL4oeDDhMZtFp/q u3kBR4nHINF8AoR9DPYsLInFSndIrIB8JN9PudmdwsK8D9eRgFZvUhxMMlVqNshHv/nL XiAJltyEN53Ygt5RovXaKc9uxh/HPZYFk7RzkrA7R8Ok6R5S171TgtXyHHCnPWPDVFsY GlmLpo+0LQ67GrXvD2OhBUsXS2KgXgOvkKD0b/XS427n5mQbKq/Au70gc75iNf7qY3Lg 5AuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=EKSoG5Ew; 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 u21si553426ejz.518.2020.04.30.14.54.37; Thu, 30 Apr 2020 14:55:00 -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=@cloud.ionos.com header.s=google header.b=EKSoG5Ew; 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 S1727890AbgD3VxB (ORCPT + 99 others); Thu, 30 Apr 2020 17:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727886AbgD3Vwq (ORCPT ); Thu, 30 Apr 2020 17:52:46 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4575BC035494 for ; Thu, 30 Apr 2020 14:52:46 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id a8so5831765edv.2 for ; Thu, 30 Apr 2020 14:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0x0u2gx9fn/eR0FN5+bPGwv0n6eHZLnbohIE4ZZX1xA=; b=EKSoG5Ew33JLpPLoDYTtE+/Mgaiip4zvgBvwtrD+hzLSfo0W4PoRueJtf0vHDfylth bljRy4d4FM68XWGdNeOkwmfpot8DYA8ccYVAgwhAOhIi49XGb7to4+pAAZneDZCwf4G6 IkFcj1IZ9Qq8NOMnothYcg8j2FPeyvEg43skasH+eZw77B+t7Qfs+j68ULZzmwKal/h3 9saDCk1g1y7x4x+j5cKc0w4eHvhoxpHehsWHYcMrqIF522cmVjrQX9TO1JsfPCvOuR/I zHxuTKM5R0LSq/EtBs1ZI6S/nV/ouTfbgPwVZmpLRJi6srnLa57HKoMQe8NfaoufTaQa mUJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0x0u2gx9fn/eR0FN5+bPGwv0n6eHZLnbohIE4ZZX1xA=; b=Jqg8Xs91dBKbb5BTKsSFxmNk5k1992an+RoHc52TeJH9f8/aI6IgkrYZPP0qeK1QEv Cm9ifkXH7kNcYNXNy0/4d+6PnVKPIYEld24IOh40+YJKkgA+EJMxEqjb3JR+ZJzGHY1C WXNyLcEXReB84eQUHF1zi/VD8AR9ELTtM98Jj1FeQvXvEpOKCW61uxfBabqSXd3ky1Jo GPYhzPLPvy64RJ0ooH4NspjAckpSMTL4s7tidBfK2mZo+PRfH8rxuw8ngOL5LN/V5hDT KZETLYX1eOELLSg/vQY6ALq5Bz64PGN5NEYZ9sQvnedArlTqHJsmAzEzm3eJNJE70SA0 TxVA== X-Gm-Message-State: AGi0PuaXQFDuNxHAj1CfdMAjH2BoUScs468VPc7WGtjBZJ8xse8V9UDy WqMW1N0tFU7bF4ngTQRBtgDsPw== X-Received: by 2002:aa7:ce0f:: with SMTP id d15mr995432edv.327.1588283565020; Thu, 30 Apr 2020 14:52:45 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:b82f:dfc:5e2a:e7cc]) by smtp.gmail.com with ESMTPSA id f13sm92022ejd.2.2020.04.30.14.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 14:52:44 -0700 (PDT) From: Guoqing Jiang To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: hch@infradead.org, david@fromorbit.com, willy@infradead.org, Guoqing Jiang , Mike Marshall , Martin Brandenburg , devel@lists.orangefs.org Subject: [RFC PATCH V2 8/9] orangefs: use attach/clear_page_private Date: Thu, 30 Apr 2020 23:44:49 +0200 Message-Id: <20200430214450.10662-9-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> References: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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..139c450aca68 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(clear_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(clear_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(clear_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(clear_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