From patchwork Tue Mar 22 21:39:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12789061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F285C433F5 for ; Tue, 22 Mar 2022 21:39:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC0846B0092; Tue, 22 Mar 2022 17:39:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6BD66B0093; Tue, 22 Mar 2022 17:39:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90DDF6B0095; Tue, 22 Mar 2022 17:39:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 7D5B26B0092 for ; Tue, 22 Mar 2022 17:39:37 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5B918602 for ; Tue, 22 Mar 2022 21:39:37 +0000 (UTC) X-FDA: 79273339194.02.789301E Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf13.hostedemail.com (Postfix) with ESMTP id EF3732001F for ; Tue, 22 Mar 2022 21:39:36 +0000 (UTC) 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 85E34B81DB1; Tue, 22 Mar 2022 21:39:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4321CC340EC; Tue, 22 Mar 2022 21:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647985175; bh=yP8ZE/+Cvg9nj9MqmFGn11xg9p3WZXmau+nnxD21NZ4=; h=Date:To:From:In-Reply-To:Subject:From; b=YNTI3VSA1OcG3jaSSJEMwd4bbIIznnMcVrUqGGxSGyuiise8Jl7WwP8VlxpenZsko UfWjPHrTAv3iQYgsWu/OR4Qk6C20WInLEXUGrWK1jzhJrO0gPnE1zh2oEKmCubh1BE cwwyLO9+sOh7yqQyp2n1lTEtd832G/nsm445OWzc= Date: Tue, 22 Mar 2022 14:39:34 -0700 To: stable@vger.kernel.org,mtosatti@redhat.com,joaodias@google.com,cgoldswo@codeaurora.org,minchan@kernel.org,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220322143803.04a5e59a07e48284f196a2f9@linux-foundation.org> Subject: [patch 021/227] mm: fs: fix lru_cache_disabled race in bh_lru Message-Id: <20220322213935.4321CC340EC@smtp.kernel.org> X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 5yf1irpyfhw76rwr5r1mrbq7wzu7ts7f Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=YNTI3VSA; dmarc=none; spf=pass (imf13.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Queue-Id: EF3732001F X-HE-Tag: 1647985176-601250 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Minchan Kim Subject: mm: fs: fix lru_cache_disabled race in bh_lru 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 --- fs/buffer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/buffer.c~mm-fs-fix-lru_cache_disabled-race-in-bh_lru +++ a/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++) {