Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp9297484ioo; Sun, 5 Jun 2022 10:17:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf4EuVqIEvgnLmKPp713SOy0d4+Bq0AUFWmF8zlXiiV0gNjyu/2JmLQAA+To7T062iHy8Z X-Received: by 2002:a17:907:9722:b0:706:19d0:80b5 with SMTP id jg34-20020a170907972200b0070619d080b5mr17982089ejc.33.1654449460514; Sun, 05 Jun 2022 10:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654449460; cv=none; d=google.com; s=arc-20160816; b=gmhjTwzO1A3gKIXw9ZbjvRKRLSyrupzbBPEOj8CDZ+HDNS/Mnk48pTGSE6SKrezfyu INQ70nP1QwxFqLz/r5d9uH22DOC41p5r+8WYX3SaYABxG8JaTjd6Kkgmz94gqHtzBQuV O+EJcuHE8Bt0yY7/WOA6oC+vxHEMN57rj6RWerB3p0q7YI8CyBayVk167uXxT1yEngwt emV0dkzurWxiXePRacrHEvv8IcwyRiwaXyv0R6rWM0PRbGv9FcxOrudXf+ogvgkmBNmY eD6rRD/tFWKH5AEJEkHwvXqSJSE5WDWHosvP/1xLgButgcyrcdYBxtsKpUy9t7/8HqEG XzGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uBRhQRR/tN31opvAhjL6O3F8yw8vziQWAC+xAJKQG7Y=; b=WChy+hI8XPDPuboIYaCZQ+gqUEKk3m32FGVUf58emppZfAq1H1iurD+wrvP65Zu/K3 e0mS3NoV7XzUogaZk6CzHL9ZlovVStteN7NjH/NPWrucU+ewiSNFEiCGuqNocoUyT1sR OBxfta3IANYJ4ecrRdnG5Rqlv11gMhfJQYlYMkDrSH9ymeYXAKQGxybV4qiY2GwaNdon J6RRKpoUG1zbNpqzAwBlVIXOwNgkgkig+gdC4yUfHENGdLx3vH0pa1/+rYAMbptRr5bL N+NPMbUpHG5QoZAUaZd2SogePfEy2M8wWVzR4LzKNnCIrLswQwa/EcFXVmIKCgS4rhuG omHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kyBAPQ2E; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a25-20020a1709064a5900b006fef1a9ef8esi7780821ejv.324.2022.06.05.10.17.02; Sun, 05 Jun 2022 10:17:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kyBAPQ2E; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345044AbiFEOid (ORCPT + 99 others); Sun, 5 Jun 2022 10:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345040AbiFEOib (ORCPT ); Sun, 5 Jun 2022 10:38:31 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4709DFBF; Sun, 5 Jun 2022 07:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=uBRhQRR/tN31opvAhjL6O3F8yw8vziQWAC+xAJKQG7Y=; b=kyBAPQ2EzL+54K5R18CvAvQNSY 7az/EotbUPE4HGEVknJY0cIJfgusEmPNfL1Okchrzg+eqi4dgaLNv0mniD1uBRe0xy/4iTSG2jhOb cR+YfL+oTtX0NJ8GN8Pan4UpP8OhPnuNdrMR/OZoBhQhtI6klTdta3tDxHpw3Rwd3easXRmLGF+Nt qglBCF+F3u2tS35iA4Xp4iTA/y6HKOvd35WUrXpinSXNeF4F7dbBDKBZmVBRUhkEMzOnN2DUV0URi Nc8eOMSYhhWNxXr/gAF5Wh+pDvF3Qa9+0FF66Sri7Jk8sp+VojeKDJACX1pEVEMA3EDVBLwWwAwbH XVm4wvzw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nxrOU-009mNq-MT; Sun, 05 Jun 2022 14:38:18 +0000 From: "Matthew Wilcox (Oracle)" To: Jan Kara Cc: "Matthew Wilcox (Oracle)" , tytso@mit.edu, Andreas Dilger , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/3] quota: Prevent memory allocation recursion while holding dq_lock Date: Sun, 5 Jun 2022 15:38:13 +0100 Message-Id: <20220605143815.2330891-2-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220605143815.2330891-1-willy@infradead.org> References: <20220605143815.2330891-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As described in commit 02117b8ae9c0 ("f2fs: Set GF_NOFS in read_cache_page_gfp while doing f2fs_quota_read"), we must not enter filesystem reclaim while holding the dq_lock. Prevent this more generally by using memalloc_nofs_save() while holding the lock. Signed-off-by: Matthew Wilcox (Oracle) --- fs/quota/dquot.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index a74aef99bd3d..cdb22d6d7488 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -425,9 +425,11 @@ EXPORT_SYMBOL(mark_info_dirty); int dquot_acquire(struct dquot *dquot) { int ret = 0, ret2 = 0; + unsigned int memalloc; struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); mutex_lock(&dquot->dq_lock); + memalloc = memalloc_nofs_save(); if (!test_bit(DQ_READ_B, &dquot->dq_flags)) { ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot); if (ret < 0) @@ -458,6 +460,7 @@ int dquot_acquire(struct dquot *dquot) smp_mb__before_atomic(); set_bit(DQ_ACTIVE_B, &dquot->dq_flags); out_iolock: + memalloc_nofs_restore(memalloc); mutex_unlock(&dquot->dq_lock); return ret; } @@ -469,9 +472,11 @@ EXPORT_SYMBOL(dquot_acquire); int dquot_commit(struct dquot *dquot) { int ret = 0; + unsigned int memalloc; struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); mutex_lock(&dquot->dq_lock); + memalloc = memalloc_nofs_save(); if (!clear_dquot_dirty(dquot)) goto out_lock; /* Inactive dquot can be only if there was error during read/init @@ -481,6 +486,7 @@ int dquot_commit(struct dquot *dquot) else ret = -EIO; out_lock: + memalloc_nofs_restore(memalloc); mutex_unlock(&dquot->dq_lock); return ret; } @@ -492,9 +498,11 @@ EXPORT_SYMBOL(dquot_commit); int dquot_release(struct dquot *dquot) { int ret = 0, ret2 = 0; + unsigned int memalloc; struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); mutex_lock(&dquot->dq_lock); + memalloc = memalloc_nofs_save(); /* Check whether we are not racing with some other dqget() */ if (dquot_is_busy(dquot)) goto out_dqlock; @@ -510,6 +518,7 @@ int dquot_release(struct dquot *dquot) } clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); out_dqlock: + memalloc_nofs_restore(memalloc); mutex_unlock(&dquot->dq_lock); return ret; } -- 2.35.1