Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2942640iog; Mon, 20 Jun 2022 07:59:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzrQr/zVvrzmqgIy/dua74feYjt2eYebqaHQZlAdkqEAOmy9XNenvsg6qPqSnf3zQ43IjA X-Received: by 2002:a17:903:110e:b0:167:8847:5d9d with SMTP id n14-20020a170903110e00b0016788475d9dmr24121698plh.3.1655737172217; Mon, 20 Jun 2022 07:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655737172; cv=none; d=google.com; s=arc-20160816; b=rs9oLpnYxxcw8CRcmsyrqBrwDh1fPGkhJk6z1O/KNPElYcd5JhTUC6StXAx6+K+6L1 jur5LeUZwh/tOZg41N0aOnM/1MLeJTyFZQboPLEWbNAAYj3+iXpi0e91bJrhd5rjtuO9 gNcrDvnyEJfkHzE3rhQv51aA3JOKHJvhcYdkC+4wRXlzOnuNUnVGdCBw4MSfAK/8BlYW vIlRVyXYbQ+ZxwOqTLKrpvY76Fy8yeg50DhdmN85XTt1BuX7kUXy0ySvJ3rqsYb0p25L A2HVwhS1vrk8wzIF+LAYm3So13ZghzP2tN9xv35hrHFBVHL3KgEecSBw9/FeGHTx2a5A dXjw== 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=btQtZbbFkg00vxomdP2YanUHUpAZ6m3gog8WtBqG2Mk=; b=CTUi4QneBeSbpA4rfRavpk8Y3q8SVtybh1A2grHCbCtHoXaPOnSuXfHME8DLjidY+d rQrHILjbjsvMXb8999dao/HVuh+JgufDB3wRZo0Ft2ReH0PKgr3YtM1p7oeq5Ojn7vRl UW6uhCyqDIBu5E57u1H6faKSTfSsFkmDqtAxZBRliCO5xJN8Y7iSG82iS21IGbT47i9o +G+tJ9pljqP6PdKhVCcWWK76cRmxlqmzkiAO4AIYrswkXZCar5VJLEjVx01lFxSxTT4m knG56EGBTv0usQL87uhw2HeVh1Z2lnAFIN2LdSvwbigmCnYmOcvBKBTzqQA/rozVVupo xagg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R2VXcWZP; 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 d5-20020a170902aa8500b0016356bd88e5si17267939plr.419.2022.06.20.07.59.19; Mon, 20 Jun 2022 07:59:32 -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=R2VXcWZP; 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 S1346696AbiFTNfT (ORCPT + 99 others); Mon, 20 Jun 2022 09:35:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347110AbiFTNd5 (ORCPT ); Mon, 20 Jun 2022 09:33:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D75F2717E; Mon, 20 Jun 2022 06:13:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 570AEB811AE; Mon, 20 Jun 2022 13:05:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC147C341C8; Mon, 20 Jun 2022 13:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655730325; bh=vJjdRV6suW58wg8UxIw6dYY+UwjX1tnxBI4Y8tgNXmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R2VXcWZPD5RWeb3UTXkbzZsiXUig6JJYGn/kBDjHd1OH70B1Om0E3TKtQIdvV7kOf 1hXJbjTeUVw/jJYZF8Lz1Yl9Bjbrm9BzKr4Be8/MuPoDqaCOxL55rsHkWnM4HQwhxC FT9Jh2jm8FnP75SAuk7DvTGBifN10LSo0H/PQQu8= 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.15 018/106] quota: Prevent memory allocation recursion while holding dq_lock Date: Mon, 20 Jun 2022 14:50:37 +0200 Message-Id: <20220620124724.925186492@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124724.380838401@linuxfoundation.org> References: <20220620124724.380838401@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 a74aef99bd3d..09d1307959d0 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -79,6 +79,7 @@ #include #include #include +#include #include "../internal.h" /* ugh */ #include @@ -425,9 +426,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 +461,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 +473,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 +487,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 +499,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 +519,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