Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp760099pxb; Tue, 5 Apr 2022 22:07:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxY28OQsE6Dg39BKt+fh1h4sVnkpR8RM72i4CrtbFx8v1pQeaR6hDpNi2RsHEwsni0tQbA X-Received: by 2002:a63:f147:0:b0:399:2b1f:7aff with SMTP id o7-20020a63f147000000b003992b1f7affmr5698474pgk.341.1649221650643; Tue, 05 Apr 2022 22:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649221650; cv=none; d=google.com; s=arc-20160816; b=xLK9H8xc4/jTDoqMl0qHVDUk6cbR7bpnSi+DXHdpGc7XWK016H1z8XDdv0doIOzPID yom4c/I5nZoh4C+bN/sXMMrPgjGFv2YqybUdafGm90AOo15WPyzA8+A97PT8DwPZn3K8 JvUxFL45dRMWjk0nt6jRzQ6SAb020C6t2GcfdoGL6w1AlQbf/ZhY4wcH46OOkPLGCvGN KgSJctgBN0XRV+p1IfyNdCd5cK7Noh485420pAFV9F2NHR+SRUWlGQ9//1CKbwUR9kCV 6U1CVIB5REU2yERrEfK7N7Zth3Tq2XtI7Izv3KFbZbxPK7Psgm3Ea47PQWaEJWf/omQa bm+Q== 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=az5h5YnSrZ17iw7zxEcLtRUZ9njZQlGy2VNjqXKEBwsEVRaxxxsOZ3ihQVtdFvbMFb fIuQDIRMwvw/2ygG4pBQbyAnODfCzRCQt/SyAV//0ZXD3qa/Lzk2Hk303IYb32yqkYOx OLzhyWS5rnwPVdemTrFlHEORTtqHCfbhjBpsiSZ/dnuwg6Um0bdYds3XqvHQllRFHoj9 FzMKDpmc0qswfwWNQJo8F99/bqlxL2hDv0Y29LijnH81wYqFiQV6mSqXlPRLDQVXOrPl 3S32n0fd2hDvFC0B3nXS9DQzOSyKEzA7P2zI9JcK5wPfK951nsaBxpLu6E4Nq2R9eyLv lM2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wiI/Nh5K"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id c192-20020a621cc9000000b004fb66ae93ffsi14054674pfc.162.2022.04.05.22.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 22:07:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wiI/Nh5K"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 0F9E53E4C2B; Tue, 5 Apr 2022 20:31:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351686AbiDELE7 (ORCPT + 99 others); Tue, 5 Apr 2022 07:04:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237425AbiDEImO (ORCPT ); Tue, 5 Apr 2022 04:42:14 -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 6DEE5DF85; Tue, 5 Apr 2022 01:34:48 -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 1E5D3B81B13; Tue, 5 Apr 2022 08:34:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8068DC385A1; Tue, 5 Apr 2022 08:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147685; bh=fKGsAcnGkdDH2Ic2fcQgnLFdX1e9rvKJlOCEFRK4Q3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wiI/Nh5K9kJQrs9safV9bp0RhGI0EYBWCGH8luJl/wxofn2sOy8GsjMThEYxKupFh 3UPCq+7IkZddiJUut1o+epyH1v/os/PqEw3QNn1kgRBpq20KtTlS21I9DQhQzbYbbm IHO/CPPzXV1q346umdeP+fUHUeXgulcuxeZCB/7k= 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.16 0086/1017] mm: fs: fix lru_cache_disabled race in bh_lru Date: Tue, 5 Apr 2022 09:16:39 +0200 Message-Id: <20220405070356.745892359@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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++) {