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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9331DC678DB for ; Sat, 4 Mar 2023 16:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229609AbjCDQ7y convert rfc822-to-8bit (ORCPT ); Sat, 4 Mar 2023 11:59:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbjCDQ7w (ORCPT ); Sat, 4 Mar 2023 11:59:52 -0500 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5464216306 for ; Sat, 4 Mar 2023 08:59:44 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 12B716382EFB; Sat, 4 Mar 2023 17:59:42 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id VJ8KBk6rlIxq; Sat, 4 Mar 2023 17:59:41 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 8477A61418B6; Sat, 4 Mar 2023 17:59:41 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 2ZH0VCMlkC3U; Sat, 4 Mar 2023 17:59:41 +0100 (CET) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 6554A6382EFB; Sat, 4 Mar 2023 17:59:41 +0100 (CET) Date: Sat, 4 Mar 2023 17:59:41 +0100 (CET) From: Richard Weinberger To: chengzhihao1 Cc: ZhaoLong Wang , Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel , yi zhang Message-ID: <1472678614.203878.1677949181290.JavaMail.zimbra@nod.at> In-Reply-To: <2d3b033a-5329-be95-fe38-2cceb17b9014@huawei.com> References: <20230304014141.2099204-1-wangzhaolong1@huawei.com> <2d3b033a-5329-be95-fe38-2cceb17b9014@huawei.com> Subject: Re: [PATCH] ubi: Fix deadlock caused by recursively holding work_sem MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF97 (Linux)/8.8.12_GA_3809) Thread-Topic: Fix deadlock caused by recursively holding work_sem Thread-Index: QdXMMi4X/w+/jvDCBA4SuSPx9dKZyQ== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Ursprüngliche Mail ----- > Von: "chengzhihao1" >> During the processing of the bgt, if the sync_erase() return -EBUSY >> or some other error code in __erase_worker(),schedule_erase() called >> again lead to the down_read(ubi->work_sem) hold twice and may get >> block by down_write(ubi->work_sem) in ubi_update_fastmap(), >> which cause deadlock. >> >> ubi bgt other task >> do_work >> down_read(&ubi->work_sem) ubi_update_fastmap >> erase_worker # Blocked by down_read >> __erase_worker down_write(&ubi->work_sem) >> schedule_erase >> schedule_ubi_work >> down_read(&ubi->work_sem) >> >> Fix this by changing input parameter @nested of the schedule_erase() to >> 'true' to avoid recursively acquiring the down_read(&ubi->work_sem). >> >> Also, fix the incorrect comment about @nested parameter of the >> schedule_erase() because when down_write(ubi->work_sem) is held, the >> @nested is also need be true. >> >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217093 >> Fixes: 2e8f08deabbc ("ubi: Fix races around ubi_refill_pools()") >> Signed-off-by: ZhaoLong Wang >> --- >> drivers/mtd/ubi/wl.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) > > Reviewed-by: Zhihao Cheng Applied to -next. Thanks everyone! Thanks, //richard