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=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 0C13BC2D0DA for ; Thu, 26 Dec 2019 14:39:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB155206CB for ; Thu, 26 Dec 2019 14:39:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbfLZOjk (ORCPT ); Thu, 26 Dec 2019 09:39:40 -0500 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:39447 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726535AbfLZOjk (ORCPT ); Thu, 26 Dec 2019 09:39:40 -0500 Received: from callcc.thunk.org (96-72-84-49-static.hfc.comcastbusiness.net [96.72.84.49] (may be forged)) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id xBQEdZh2009503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 26 Dec 2019 09:39:36 -0500 Received: by callcc.thunk.org (Postfix, from userid 15806) id D82B9420485; Thu, 26 Dec 2019 09:39:34 -0500 (EST) Date: Thu, 26 Dec 2019 09:39:34 -0500 From: "Theodore Y. Ts'o" To: Naoto Kobayashi Cc: adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Subject: Re: [PATCH] ext4: Prevent ext4_kvmalloc re-entring the filesystem and deadlocking Message-ID: <20191226143934.GC3158@mit.edu> References: <20191226071008.7812-1-naoto.kobayashi4c@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191226071008.7812-1-naoto.kobayashi4c@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Dec 26, 2019 at 04:10:08PM +0900, Naoto Kobayashi wrote: > Although __vmalloc() doesn't support GFP_NOFS[1], > ext4_kvmalloc/kvzalloc caller may be under GFP_NOFS context > (e.g. fs/ext4/resize.c::add_new_gdb). In such cases, the memory > reclaim can re-entr the filesystem and potentially deadlock. > > To prevent the memory relcaim re-entring the filesystem, > use memalloc_nofs_save/restore that gets __vmalloc() to drop > __GFP_FS flag. > > [1] linux-tree/Documentation/core-api/gfp-mask-fs-io.rst > > Signed-off-by: Naoto Kobayashi Good catch! However, we're not actually using ext4_kvzalloc() anywhere, at least not any more. And also, all the users of ext4_kvmalloc() are using GFP_NOFS (otherwise, they would have been converted over to use the generic kvmalloc() helper function). So... a cleaner fix would be to (a) delete ext4_kvmazalloc(), (b) rename ext4_kvmalloc() to ext4_kvmalloc_nofs(), and drop its flags argument, and then the calls memalloc_nfs_save/restore() to ext4_kvmalloc_nofs() --- and so we won't need the if (!(flags & __GFP_FS)) test. Could you make those changes and resend the patch? Thanks, - Ted