Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp598265pxb; Tue, 5 Apr 2022 15:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytxQhMwI3bAZckOk0Cfc6cFrMvZpRAFTJ/+CickjT7PEJDrvu7Shtvn1etZb/g87UWoS4c X-Received: by 2002:a17:90b:3e8b:b0:1c7:852d:e843 with SMTP id rj11-20020a17090b3e8b00b001c7852de843mr6446867pjb.244.1649197629841; Tue, 05 Apr 2022 15:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649197629; cv=none; d=google.com; s=arc-20160816; b=JuqvyU0b6NRk7FYJNkEi9ONC8oGIS+8EYyoDxU8nQASeGorBr5WmHrCUTJYjy5kOMi 66zl/zAx0QNKM9Byw98tbYQGpDcCGMiyeJCwB55TUKfYpg5k9uOPI97fAfMZenv+nt3Y MM23/iFoubel2G9ZGHTWNJh0A22Is+SlJDo6Gilol6dyhMunOiZ8uJgMSLWEFrtDu+Uf R4XUVDA+KZz0nBYZPbXxY9/ttTp4vQMZuzjrWlwTP491Qy/cEAzqeVXjnFYpHt7/pEGc NYBEOQPDrqFpFGF6tgX1nPhLSATj+fwf2KBRybCYUWSDejKv1DE4Sof5A37vVJWxpmqA Z3kw== 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=d0/2xkKZjcOukkgW/t64uChrHaQSqn+sceHtjKmP4xM=; b=ef/rfv2+A4q7z0OrxRZlVfIh5ygacZ5kgB67nnyAYYXpEAk3tcNhdhCJB0kayI5g3t RPI79krG/HwqwLbbTYeLKjwumdYVjvJyh+wYDfgP23zHYl9wZ013b52ZcHtOmHDvaK22 DCz/L+E3e5n/gS2EbHtUNWswy+QECtJ5IFuP1qmlwwCAc2JnqQ7TzI0r2oS68aTO5vPr FFdmB68SoZvSqhVQgKQ+CDdvA/8py7H+UspzvXSBBRZQeKHJyh4z5QERVBYu7d3lGQlQ 2VBqLwNhnxBdFn+uRDu3PQwYwk2U1CIVmj6uBVJkEQUtSZDS2++BwuzdcUrZ+l3Nk1wt yY7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ngqbBJb2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 81-20020a630554000000b003816043eeb0si14023664pgf.165.2022.04.05.15.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:27:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ngqbBJb2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D90A1A0BE1; Tue, 5 Apr 2022 15:09:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384227AbiDEORv (ORCPT + 99 others); Tue, 5 Apr 2022 10:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239511AbiDEJdj (ORCPT ); Tue, 5 Apr 2022 05:33:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B06A04DF4C; Tue, 5 Apr 2022 02:22:16 -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 6D5BBB81C6F; Tue, 5 Apr 2022 09:22:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7C17C385A3; Tue, 5 Apr 2022 09:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150534; bh=fKGsAcnGkdDH2Ic2fcQgnLFdX1e9rvKJlOCEFRK4Q3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ngqbBJb23/ghLvG7i1S8bvwsHZvtgQMvEtp+6NLuQoz1aPJfs6X0+930lF/JfrjF/ KbomUkBfsjYQ9Sv5nDfbQ0rPKpMTkUhbotqdvJ2ZBYsWDwovZ2y72NE0fS3OygMrl8 HtapKGEM8gCAhh1sFhr2u9V2Fruca0tF+2B9Q1cM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minchan Kim , Chris Goldsworthy , Marcelo Tosatti , John Dias , Andrew Morton , Linus Torvalds Subject: [PATCH 5.15 083/913] mm: fs: fix lru_cache_disabled race in bh_lru Date: Tue, 5 Apr 2022 09:19:05 +0200 Message-Id: <20220405070342.311010162@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Minchan Kim commit c0226eb8bde854e016a594a16f5c0d98aca426fa upstream. Check lru_cache_disabled under bh_lru_lock. Otherwise, it could introduce race below and it fails to migrate pages containing buffer_head. CPU 0 CPU 1 bh_lru_install lru_cache_disable lru_cache_disabled = false atomic_inc(&lru_disable_count); invalidate_bh_lrus_cpu of CPU 0 bh_lru_lock __invalidate_bh_lrus bh_lru_unlock bh_lru_lock install the bh bh_lru_unlock WHen this race happens a CMA allocation fails, which is critical for the workload which depends on CMA. Link: https://lkml.kernel.org/r/20220308180709.2017638-1-minchan@kernel.org Fixes: 8cc621d2f45d ("mm: fs: invalidate BH LRU during page migration") Signed-off-by: Minchan Kim Cc: Chris Goldsworthy Cc: Marcelo Tosatti Cc: John Dias Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/buffer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1235,16 +1235,18 @@ static void bh_lru_install(struct buffer int i; check_irqs_on(); + bh_lru_lock(); + /* * the refcount of buffer_head in bh_lru prevents dropping the * attached page(i.e., try_to_free_buffers) so it could cause * failing page migration. * Skip putting upcoming bh into bh_lru until migration is done. */ - if (lru_cache_disabled()) + if (lru_cache_disabled()) { + bh_lru_unlock(); return; - - bh_lru_lock(); + } b = this_cpu_ptr(&bh_lrus); for (i = 0; i < BH_LRU_SIZE; i++) {