Received: by 10.213.65.68 with SMTP id h4csp3014841imn; Mon, 9 Apr 2018 12:45:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx48MMKoheCtIEwMJhyjM+nvsfGsUyviqOnyI4Wos7f7MHWx6iL87XmXNQUZFFFX7q3ZC+FdF X-Received: by 10.98.67.141 with SMTP id l13mr258269pfi.166.1523303101605; Mon, 09 Apr 2018 12:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523303101; cv=none; d=google.com; s=arc-20160816; b=SfSGRK9lrQRP00vIZIsGqduJ7ik2EQZOOEsHBrG7dM7xkP6RZXKCuu5vLqcdfW0pfp 2sNFDrCoUTz8acmv0w/r0kl4/7OtyAl/UXRQaI6cHZRt64M3dYvJmAN6acXDc9iGDkIo /Ptxu9TKazslJI9LoR7/+nj17U8sT5y4V7ltVUULy2NfItVVeHxYvdFAni+ZRiD9P0o0 EyghxtBYs5YlEO/dV8TTU7GrXexbXpdVmJfUr9AJVUQH0becuyYYAjJ6w+uhxcE+ZiDG HfYW9zH8iLzSgwy9nhiV4Rcfn0f8n4noqVPWvCN40KDCvLSH7NIhO6j7ImtyIab23uhL ut5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Sv/5g1rGKsvyYCdIFFCkZCpNEcGLBxUkzgvuhFbJ9+w=; b=mhoo0jJHsAYJBMaNRdnwEOk2QpIkmZCZLLKIX/V5af8hFxeOPKm9Ro77Ha8MTu4L1w ZU9FV3/tJK3L3Ar5phsWVxaI+7J3r/uOcb8Gr0ADsgIeswa+V28tiOI646T3ybfiKihO 90pJIlgqOEOemFZoArJIoGsnExnWOVM/gS7QUyGX+F51ObE0jspn2G255hOCLbDnNx17 dN7jTq1n1SyYCG32S96hCCe/BHobCqyRo3Q8Zg9WRusyCNRE/02aNCAxQ38JnSNDFAot jPybEFJ1Dn0f4s+fsAp15lokA9xskRjxRwryMWoYlzSUgZ2qri23AznZt0qSvyH8QXrX DbeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=q8HdIbum; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a17si726601pff.43.2018.04.09.12.44.24; Mon, 09 Apr 2018 12:45:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=q8HdIbum; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754431AbeDITks (ORCPT + 99 others); Mon, 9 Apr 2018 15:40:48 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50462 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754141AbeDITkr (ORCPT ); Mon, 9 Apr 2018 15:40:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Sv/5g1rGKsvyYCdIFFCkZCpNEcGLBxUkzgvuhFbJ9+w=; b=q8HdIbumo2MVOKancxXBOzXZy fuFDOocDYCewO9mtYx9UzEJU41iGEsrOG4CcC2AJB6aU2lQxgDxwS/KRn3gcyB5sEGXsR+kScnSkE FuTD+Qcs4ZOJENsr5euey23veDK5TE5NiofcKJeoZqtrN+CRgEdrALx9tz8xYUHX+RFXc56fRWM24 ijuZMNzDRGqNPxBxGINw7FRnWwyHNN7Bp5KW3cvLIKEHCkBbsV2A9Pn2dSMVdEF/bl9ZYG59Oh57+ n/tvdkyLzaZR20Lyf81Iak3mNyrHa2Vi5ictu4dE8MSroG3sB/uQ+uZlcobZENp8aaKx85wVsgqX/ +V4lzpIRw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5cei-0000PI-Qb; Mon, 09 Apr 2018 19:40:44 +0000 Date: Mon, 9 Apr 2018 12:40:44 -0700 From: Matthew Wilcox To: Jaegeuk Kim Cc: Minchan Kim , Christopher Lameter , Andrew Morton , linux-mm , LKML , Johannes Weiner , Jan Kara , Chris Fries , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] mm: workingset: fix NULL ptr dereference Message-ID: <20180409194044.GA15295@bombadil.infradead.org> References: <20180409015815.235943-1-minchan@kernel.org> <20180409024925.GA21889@bombadil.infradead.org> <20180409030930.GA214930@rodete-desktop-imager.corp.google.com> <20180409111403.GA31652@bombadil.infradead.org> <20180409112514.GA195937@rodete-laptop-imager.corp.google.com> <20180409183827.GD17558@jaegeuk-macbookpro.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180409183827.GD17558@jaegeuk-macbookpro.roam.corp.google.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 09, 2018 at 11:38:27AM -0700, Jaegeuk Kim wrote: > On 04/09, Minchan Kim wrote: > > On Mon, Apr 09, 2018 at 04:14:03AM -0700, Matthew Wilcox wrote: > > > On Mon, Apr 09, 2018 at 12:09:30PM +0900, Minchan Kim wrote: > > > > On Sun, Apr 08, 2018 at 07:49:25PM -0700, Matthew Wilcox wrote: > > > > > On Mon, Apr 09, 2018 at 10:58:15AM +0900, Minchan Kim wrote: > > > > > > It assumes shadow entry of radix tree relies on the init state > > > > > > that node->private_list allocated should be list_empty state. > > > > > > Currently, it's initailized in SLAB constructor which means > > > > > > node of radix tree would be initialized only when *slub allocates > > > > > > new page*, not *new object*. So, if some FS or subsystem pass > > > > > > gfp_mask to __GFP_ZERO, slub allocator will do memset blindly. > > > > > > > > > > Wait, what? Who's declaring their radix tree with GFP_ZERO flags? > > > > > I don't see anyone using INIT_RADIX_TREE or RADIX_TREE or RADIX_TREE_INIT > > > > > with GFP_ZERO. > > > > > > > > Look at fs/f2fs/inode.c > > > > mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO); > > > > > > > > __add_to_page_cache_locked > > > > radix_tree_maybe_preload > > > > > > > > add_to_page_cache_lru > > > > > > > > What's the wrong with setting __GFP_ZERO with mapping->gfp_mask? > > > > > > Because it's a stupid thing to do. Pages are allocated and then filled > > > from disk. Zeroing them before DMAing to them is just a waste of time. > > > > Every FSes do address_space to read pages from storage? I'm not sure. > > > > If you're right, we need to insert WARN_ON to catch up __GFP_ZERO > > on mapping_set_gfp_mask at the beginning and remove all of those > > stupid thins. > > > > Jaegeuk, why do you need __GFP_ZERO? Could you explain? > > Comment says "__GFP_ZERO returns a zeroed page on success." > > The f2fs maintains two inodes to manage some metadata in the page cache, > which requires zeroed data when introducing a new structure. It's not > a big deal to avoid __GFP_ZERO for whatever performance reasons tho, does > it only matters with f2fs? This isn't a performance issue. The problem is that the mapping gfp flags are used not only for allocating pages, but also for allocating the page cache data structures that hold the pages. F2FS is the only filesystem that set the __GFP_ZERO bit, so it's the first time anyone's noticed that the page cache passes the __GFP_ZERO bit through to the radix tree allocation routines, which causes the radix tree nodes to be zeroed instead of constructed. I think the right solution to this is: diff --git a/mm/filemap.c b/mm/filemap.c index c2147682f4c3..a87a523eea8e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -785,7 +785,7 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask) VM_BUG_ON_PAGE(!PageLocked(new), new); VM_BUG_ON_PAGE(new->mapping, new); - error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); + error = radix_tree_preload(gfp_mask & ~(__GFP_HIGHMEM | __GFP_ZERO)); if (!error) { struct address_space *mapping = old->mapping; void (*freepage)(struct page *); @@ -841,7 +841,8 @@ static int __add_to_page_cache_locked(struct page *page, return error; } - error = radix_tree_maybe_preload(gfp_mask & ~__GFP_HIGHMEM); + error = radix_tree_maybe_preload(gfp_mask & + ~(__GFP_HIGHMEM | __GFP_ZERO)); if (error) { if (!huge) mem_cgroup_cancel_charge(page, memcg, false);