Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp618789pxb; Tue, 5 Apr 2022 16:08:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/r+Wc8Bh1EwGdZUN0QZSiDUPJFN1lssN5B1O3OflpobM3Pw7clHtxtWTm7yAeYcHXJvSX X-Received: by 2002:a17:902:8ec4:b0:156:b8a6:f9d8 with SMTP id x4-20020a1709028ec400b00156b8a6f9d8mr5963914plo.122.1649200109572; Tue, 05 Apr 2022 16:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649200109; cv=none; d=google.com; s=arc-20160816; b=MchRA3mMr54ufxgoSrGiGZ1E6N7ImLVQCVORTBJLRHOiOrq4p9FlKEp97eWxvlXfHL 0AUf9E7U3Y5kF54CWDjM28Ijjw8TS2t2E+LjxB20xFFDsHjygtddijb0ONjgpTHQndXF qeORcO6oOHxHUe4zEaIMf5LPGUfEZ5hU7GI/tNwr07K7ppLcIjxussNMLRp9mkasAjQT /KXeKVVUNRkkpEb3D12Q/SpJOEHsAQXIKpdqMhqPlCepXOm49QwEceZKvuJP9AcnX5I4 7d8JpGQemzP5unGBqa82dU/OHIHJ2uK2V2/uqksKThOjTBLbVbJ8xRyXV0GMOwqWs+We 4mGg== 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=swHCvxKXuMoF68o4KTmqm4Szi7JCWUhCEIOk2Hep/ng=; b=tJI5MIZpg1EMvr+cFVMaxaJDYg4Apq7J3qpAMbJ3AVLi1XsayZOB6CponmbCcQ+q+/ 4+ayvotoX1hwZc9K+F8ULcummygg9+dBZCQ2Xd802/sXh25cVhfInae18UVV+MZ2nbU5 24er4e6BDpxj3cL//x3PZccM+PXPIdQXnhbaOBpJLFZ/FnZOWpxEK10UUwjWPZBF7C2W ETugHeW2FpYEUw8s7VMxKsbZ+xS/d4XSqIQ3fUuWFwvvp2R2m+YQ1PsKmdY/f4i5AZt5 pGw6vKXNsxSurE9FitArkRXRiZe2AlYJ6m7QRAT+pupQJlj+EsSDCmAYImTCApYIx8+I 7LYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="TAlWLhf/"; 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 pj14-20020a17090b4f4e00b001bf207bdb67si3671936pjb.47.2022.04.05.16.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:08:29 -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="TAlWLhf/"; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D74A21770A0; Tue, 5 Apr 2022 15:52:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389065AbiDEOm6 (ORCPT + 99 others); Tue, 5 Apr 2022 10:42:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244212AbiDEJlK (ORCPT ); Tue, 5 Apr 2022 05:41:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCAABB086; Tue, 5 Apr 2022 02:25:37 -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 dfw.source.kernel.org (Postfix) with ESMTPS id AC3AD61368; Tue, 5 Apr 2022 09:25:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEB6BC385A2; Tue, 5 Apr 2022 09:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150736; bh=FUcnqxzjXH5u3vbw4nDqrygn9TouK/7YERh2EEo0v3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TAlWLhf/lZgqzogPazChfTbzWMOomfJ0Q/pzeVYATyJjKGY107wUXXHCEDtIeeXCa uiRCRTvmiyXPLEKi0dzzbaaFCjAcAGC+YUs4wHuegdk5P9MmUJkv/MsMa87ThimS8z ZKRnnq+KBRfKexNtiVIVdcKsYR+SJen5gJidNad8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mingzhe Zou , Coly Li Subject: [PATCH 5.15 161/913] bcache: fixup multiple threads crash Date: Tue, 5 Apr 2022 09:20:23 +0200 Message-Id: <20220405070344.668773120@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: Mingzhe Zou commit 887554ab96588de2917b6c8c73e552da082e5368 upstream. When multiple threads to check btree nodes in parallel, the main thread wait for all threads to stop or CACHE_SET_IO_DISABLE flag: wait_event_interruptible(check_state->wait, atomic_read(&check_state->started) == 0 || test_bit(CACHE_SET_IO_DISABLE, &c->flags)); However, the bch_btree_node_read and bch_btree_node_read_done maybe call bch_cache_set_error, then the CACHE_SET_IO_DISABLE will be set. If the flag already set, the main thread return error. At the same time, maybe some threads still running and read NULL pointer, the kernel will crash. This patch change the event wait condition, the main thread must wait for all threads to stop. Fixes: 8e7102273f597 ("bcache: make bch_btree_check() to be multithreaded") Signed-off-by: Mingzhe Zou Cc: stable@vger.kernel.org # v5.7+ Signed-off-by: Coly Li Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/btree.c | 6 ++++-- drivers/md/bcache/writeback.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -2060,9 +2060,11 @@ int bch_btree_check(struct cache_set *c) } } + /* + * Must wait for all threads to stop. + */ wait_event_interruptible(check_state->wait, - atomic_read(&check_state->started) == 0 || - test_bit(CACHE_SET_IO_DISABLE, &c->flags)); + atomic_read(&check_state->started) == 0); for (i = 0; i < check_state->total_threads; i++) { if (check_state->infos[i].result) { --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -998,9 +998,11 @@ void bch_sectors_dirty_init(struct bcach } } + /* + * Must wait for all threads to stop. + */ wait_event_interruptible(state->wait, - atomic_read(&state->started) == 0 || - test_bit(CACHE_SET_IO_DISABLE, &c->flags)); + atomic_read(&state->started) == 0); out: kfree(state);