Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3521835pxp; Tue, 8 Mar 2022 16:32:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVeTX7XAoWp+5wrnJGnXTIzMH3JPVP5ln8fMfQY5FYGQFxvh5ugUQBaMn6v/EvypfMvJsd X-Received: by 2002:a17:902:d482:b0:151:ef7f:f5aa with SMTP id c2-20020a170902d48200b00151ef7ff5aamr11635668plg.58.1646785967408; Tue, 08 Mar 2022 16:32:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646785967; cv=none; d=google.com; s=arc-20160816; b=KGUCVPURA26W9ey9u6fSXWFQZG/C9qkg4ozxtBgtjziExmF/rUAFenGnjcfm+0JirI 37wdXW3M+hS+K0ghvtNqy9DQerstc/OxwbqLHiWZK+B33FaCpljQYI9WVCy3e4fAw2B5 Vm1WFYFsmxTao0QHrk+wk//9YH/AZAW3Tz1WRx6ZzS2YeGXyZl0QFuo8UlAMkZG6rOlz U34SImOU7u5/450ljPG0GJP3hHxiKyhOowchTvZJBRZhRGJKyWGBEhhTGiVfJySsrBXU j+3byyKREil+nNJTes1jHvexeCavfKrQ6Dq3xAoYYlRfgBnsjauUuAgYCW5o1Thp5yrA d1NA== 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 :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=pZliwmLm6S8tya/djJ5W/U/prHZbfOKsGwUj10OUIn0=; b=Nve6hzuKUkbnTJixcGtsSSNwmDY817bUsM0lc5T4Y51S9Q3zV/croZ1vl0FIKZHK00 CKytgYdZuaM9U/VEKtT0L5cRUB2K5w2jJxWkB1WVK4H1r1cxTrBdF39/egyyiyEpHlD4 +J7sLsG1wlo3Pvi929TQ45QLcUmvm/hCrH/c7Bhmq6Uc3WZtcB5+cbCguPk87KcBRo6J C3J7O5H1VPE8yN7TChFHc/QpHVcxMrouwSdJJ5pXeLr9sSivWGyM2Vi7EKawJtgQrExz AGJWLP8yPfAVaL3iEotglINL5PXyI1X8QXGXgvkpl08w9opO8bUPeE+IRgOpGvS7zCy/ Rmjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qpLtvuz0; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z9-20020a656649000000b003748e862534si354516pgv.217.2022.03.08.16.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:32:47 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=qpLtvuz0; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 48B5910E56E; Tue, 8 Mar 2022 15:50:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348753AbiCHSI1 (ORCPT + 99 others); Tue, 8 Mar 2022 13:08:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241141AbiCHSIZ (ORCPT ); Tue, 8 Mar 2022 13:08:25 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C632B4C for ; Tue, 8 Mar 2022 10:07:26 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id cx5so75059pjb.1 for ; Tue, 08 Mar 2022 10:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pZliwmLm6S8tya/djJ5W/U/prHZbfOKsGwUj10OUIn0=; b=qpLtvuz0mEEMCmqJCiWKhn+xCPGesu6Pw3r09ZrgwzSL8mgKdriqPFXA9ih3Is4h9B SifskdlThgG6P5akCPbbqD9WE7XCGeo4X4REI2Xq16nnqJdjDh8Yg44L1Hb1N4TfG6tu n8UWwRuJGdgXt61SgxTM6sWov7sUP9PoJ1F6PcjaHjk4UA0ohjNiNuIFjIo8aiJ89BkM q1SFa5D5qa67somAsAgHXMVzggWN2AB2F3C/pooif71T2zLOfB4AZ8cqgO3NM+UdycIN 16Jx9ckYs0lUPqmnO2OwYbtPAh5PCfrByZLDoRJaA15JjjaLtO055sKJPEXWxnVf+m35 QGtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=pZliwmLm6S8tya/djJ5W/U/prHZbfOKsGwUj10OUIn0=; b=S/eCHvnY7+K2/dzecnVuBVFhje3xZ7SFmwxV9GolhObQpfB1vDmncsACPeGM65FWy5 lHCuuE1JxDZ9Qcvjmkd/N3yjPBjdMqtTXrFcGapSzHyGszKJjACHhHVTsBFT5rLQ+S6E hZSndtcP5L6HZcqyVIYInvmPt7j5zGOjSOy4DH6HWKQoZAAlnTXhNdwRWr8ZO+UekYGX Kj6hFFJicN30tOHLm5jyPkkM5BB/6zLvbhkFcjq1oFcYqFaBYTVIlYgBhPkpI4TrvpZa xxh8kUR8oCZbvWo+3ow0IkessBtZ6JR4N/i63m9Dyha/HA2yflRdBhTGZs4RBQbzG3fn ZKdA== X-Gm-Message-State: AOAM53132LVStY8VuRf9Wu0na2eJWMSlyh2OvIVTZ4BL5a61cUO/SdO3 zNb2Fql8Wlt2TTCXKyOIVJs= X-Received: by 2002:a17:902:758f:b0:14f:b5ee:cc5a with SMTP id j15-20020a170902758f00b0014fb5eecc5amr18930620pll.43.1646762846012; Tue, 08 Mar 2022 10:07:26 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:ec3e:a6ab:7b5b:ed81]) by smtp.gmail.com with ESMTPSA id x23-20020a63fe57000000b0036490068f12sm15462368pgj.90.2022.03.08.10.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 10:07:12 -0800 (PST) Sender: Minchan Kim From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , Chris Goldsworthy , Marcelo Tosatti , John Dias , Minchan Kim Subject: [PATCH] mm: fs: fix lru_cache_disabled race in bh_lru Date: Tue, 8 Mar 2022 10:07:09 -0800 Message-Id: <20220308180709.2017638-1-minchan@kernel.org> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 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 Fixes: 8cc621d2f45d (mm: fs: invalidate BH LRU during page migration) Signed-off-by: Minchan Kim --- fs/buffer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 8e112b6bd371..c76a8ef60a75 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1235,16 +1235,18 @@ static void bh_lru_install(struct buffer_head *bh) 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++) { -- 2.35.1.616.g0bdcbb4464-goog