Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2930614iog; Mon, 20 Jun 2022 07:43:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7Vt3F1GAVXiWjJ+reNC6tBm5dcMq7NVJkB8S0Un6+LSCj03Sg1uVJTAXy4p9Vtw5Tthi2 X-Received: by 2002:a17:902:e749:b0:16a:2839:9e5 with SMTP id p9-20020a170902e74900b0016a283909e5mr4892890plf.48.1655736218028; Mon, 20 Jun 2022 07:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736218; cv=none; d=google.com; s=arc-20160816; b=ha/fCWmB2Y5bTwyk55CRjig5vN3iojhjJhpOk//4m1z/5hxsgL4Hg3y/McBbwiRIJJ ZG4wmGClptDd/Zft0U+gNJsxsaBEuv/iL4nmiRy0/GhnCmso90vzyB4M514zh3ctRuvU SXRCP32zW8Zf1WYAbVmgpiKhhtvUiYvR6gyzLW/y4Wv8dI3IKTSgI7CvjbtbXYcMfpcg zyIFR8KUuyufLH4Y4B08NaHgxqL0JJ4ZpzpP/79zIAMiB8PjNKfQTve/vIPOBuhCzMEH VI6RQsShoB4GiCws752eSLvcvywMouRqzwaomZ8+z2/CnWf+szPWfpFMcAivRGnXVj0d WSvg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9RRPOSx5uVc3HhQlhkKZ3NC3sjF/I2iWoEc+4L+XrlY=; b=MvBgVXsyAlzIYJsRTLeYmQWNAQ+yvWHhh8lTGZClTJoYZQywPBUZE1gxIJ9rbpA8eL pWVSkxGxegyDRJRKOWO3QaoJ0+j/Rpbj2OfL0c83HyXY/KAh1YJJJ0L/Alukb0Lr+3Cs j1HTQETsgVTPv6Od7ypS5pK92zuqbvmTJvsTiHa/L1wQDEt0b9bqi4UcsTFCrKaCcXVd gi7+weze9qQ8BnL8fNM7DQynecShWzLqzXrbwjChyIC2Ep4U7TV9sb7ttLHSDP36pHu5 wXjJ6ZivOHuvd8n9ukYZESxTijbx0ZPd3UYFUjdKkkUxUDrcpvlmFP1VuVBugzqWPyLc 9hSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cgfV04eK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 142-20020a630294000000b0040c74ec4000si9617788pgc.341.2022.06.20.07.43.25; Mon, 20 Jun 2022 07:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=cgfV04eK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245301AbiFTNLI (ORCPT + 99 others); Mon, 20 Jun 2022 09:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244685AbiFTNH0 (ORCPT ); Mon, 20 Jun 2022 09:07:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470E51B7A7; Mon, 20 Jun 2022 06:01:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9D2EB61530; Mon, 20 Jun 2022 13:00:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92EE8C36AF2; Mon, 20 Jun 2022 13:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655730043; bh=OYZepqnZF5ehymvjwu9IgTMcBX0/iTdvqxfft0sm+Io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cgfV04eKwEEgOJbi0XgvSumZX5OFc7XHk269eEhw5zJ1wKv9o6136mnTyJKUjY4pW T9IxaWSqt33WDopX9T3ZTEMQKp5LlBD2Ih235Qs+vSGDUc9wolQf46dC9GfTjwtgRT GXWs/P/jbqjiyk3udMfm4JT2t0ulxtZa7F6riA6w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Matthew Wilcox (Oracle)" , Jan Kara , Sasha Levin Subject: [PATCH 5.10 15/84] quota: Prevent memory allocation recursion while holding dq_lock Date: Mon, 20 Jun 2022 14:50:38 +0200 Message-Id: <20220620124721.342085455@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124720.882450983@linuxfoundation.org> References: <20220620124720.882450983@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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-kernel@vger.kernel.org From: Matthew Wilcox (Oracle) [ Upstream commit 537e11cdc7a6b3ce94fa25ed41306193df9677b7 ] 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. Link: https://lore.kernel.org/r/20220605143815.2330891-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/quota/dquot.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 09fb8459bb5c..65f123d5809b 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -79,6 +79,7 @@ #include #include #include +#include #include "../internal.h" /* ugh */ #include @@ -427,9 +428,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) @@ -460,6 +463,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; } @@ -471,9 +475,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 @@ -483,6 +489,7 @@ int dquot_commit(struct dquot *dquot) else ret = -EIO; out_lock: + memalloc_nofs_restore(memalloc); mutex_unlock(&dquot->dq_lock); return ret; } @@ -494,9 +501,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; @@ -512,6 +521,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