Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4149286pxb; Mon, 27 Sep 2021 10:23:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxihriQQR4eVU0bEvEqI/S/AsGdzWTlAxJJXbw5WsDdqttCWHxiJOXr08w4EenUDwIfw8O6 X-Received: by 2002:a50:becb:: with SMTP id e11mr1327475edk.161.1632763412676; Mon, 27 Sep 2021 10:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632763412; cv=none; d=google.com; s=arc-20160816; b=JLYDVZXEjgtx05NhhDhf3cYoFYTzI3z2qseiE0uUbaQ+QLFoHd6lmOflONoyMrPt9t w4tbpCsZmd3PbIAu5X1Pmu2aWIYwgM8QtSFOvsOwQXMX8CEe8fDj+9Tzu4MQrqAx7SdH a34D8vtKU5EsBN2bnd91cBsxauHdVEi9O+GKQOYXfnW2vwHPUFTH6HXSEOxyVnbkbYNS CSwMV8mgwIVaduGWllE8mzS2qfHW6GvxhQVIsrSP3n4BfQEr4peY9nmNQZcEDFoST+sj ebRPJVk1KRPMe2dRAbfKwKEiXe8KVRvdR4MukoYJjlxYadP3cQbz3379ZKyARFiQp06K kATw== 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=L58UROmUrNvrO8HC5bB75VulDHyGaY3HRHCsVUcONQ4=; b=Q6+sl38ncOVUiz9g9pJsyy14iQ22hslitSLTyJR2R3CyNBH3P+5OP2M3FgJkVdXqFL cP5ROYQhNI3qnJD7W0jeB8Nr9pTioRHM7ZC9LhxKtsL+XluI9F5fW0prGTC4jnGrTVHX Ekr/is4v2r54I0EKJcukMWVHpt12GXHsCYkU9jnyWIEWRGqRbWYDQ0vkfM+Vr1P2YmtV CCirNjrKQbPPbJMmU6cgw9T3FBZdakmf/L/+uOmyi263VMugzyegyk3yZcjyV+SqtRB3 SrP/MwuRx59owPRqNv/s1wVeUd6n5yIZWN49norAt7VwIo4VUU3MrgyO1S6oWscn12nN gC8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QI1u2dMa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si18120511edw.118.2021.09.27.10.23.05; Mon, 27 Sep 2021 10:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QI1u2dMa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237355AbhI0RXI (ORCPT + 99 others); Mon, 27 Sep 2021 13:23:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:36996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236043AbhI0RTs (ORCPT ); Mon, 27 Sep 2021 13:19:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E61666134F; Mon, 27 Sep 2021 17:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762782; bh=OqdgJlHVsssfnQqqHpKrNqiku44QOGpoNOBJS8fWfhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QI1u2dMaeh5GYL8OR/oPHeZjF+NHRrzYBg72KpNwgQaljRj7Mkk4rt3YUagb5CVHw AqWHie5tKs6P8FSOvn4hYFPookaVYvmRvRj4n4VyFKyMlFgSV/r6uXnWIT8eRihbO5 YUoDTRVqu0ibiR/5N2u4gIYN53FKBmT8JGNxELfs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Dionne , David Howells , linux-afs@lists.infradead.org, Sasha Levin Subject: [PATCH 5.14 048/162] afs: Fix page leak Date: Mon, 27 Sep 2021 19:01:34 +0200 Message-Id: <20210927170235.164647293@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170233.453060397@linuxfoundation.org> References: <20210927170233.453060397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ Upstream commit 581b2027af0018944ba301d68e7af45c6d1128b5 ] There's a loop in afs_extend_writeback() that adds extra pages to a write we want to make to improve the efficiency of the writeback by making it larger. This loop stops, however, if we hit a page we can't write back from immediately, but it doesn't get rid of the page ref we speculatively acquired. This was caused by the removal of the cleanup loop when the code switched from using find_get_pages_contig() to xarray scanning as the latter only gets a single page at a time, not a batch. Fix this by putting the page on a ref on an early break from the loop. Unfortunately, we can't just add that page to the pagevec we're employing as we'll go through that and add those pages to the RPC call. This was found by the generic/074 test. It leaks ~4GiB of RAM each time it is run - which can be observed with "top". Fixes: e87b03f5830e ("afs: Prepare for use of THPs") Reported-by: Marc Dionne Signed-off-by: David Howells Reviewed-and-tested-by: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/163111666635.283156.177701903478910460.stgit@warthog.procyon.org.uk/ Signed-off-by: Sasha Levin --- fs/afs/write.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index c0534697268e..66b235266893 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -471,13 +471,18 @@ static void afs_extend_writeback(struct address_space *mapping, } /* Has the page moved or been split? */ - if (unlikely(page != xas_reload(&xas))) + if (unlikely(page != xas_reload(&xas))) { + put_page(page); break; + } - if (!trylock_page(page)) + if (!trylock_page(page)) { + put_page(page); break; + } if (!PageDirty(page) || PageWriteback(page)) { unlock_page(page); + put_page(page); break; } @@ -487,6 +492,7 @@ static void afs_extend_writeback(struct address_space *mapping, t = afs_page_dirty_to(page, priv); if (f != 0 && !new_content) { unlock_page(page); + put_page(page); break; } -- 2.33.0