Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539AbbEKHpJ (ORCPT ); Mon, 11 May 2015 03:45:09 -0400 Received: from demumfd002.nsn-inter.net ([93.183.12.31]:42799 "EHLO demumfd002.nsn-inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192AbbEKHpG convert rfc822-to-8bit (ORCPT ); Mon, 11 May 2015 03:45:06 -0400 From: "Cantavenera, Giuseppe (EXT-Other - DE/Ulm)" To: ext Brian Norris CC: "linux-mtd@lists.infradead.org" , "Restelli, Lorenzo (EXT-Other - DE/Ulm)" , "dwmw2@infradead.org" , "stable@vger.kernel.org" , "Sverdlin, Alexander (Nokia - DE/Ulm)" , zhangxingcai , "fengfuqiu@huawei.com" , "tanhaijun@huawei.com" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] mtd: fix: avoid race condition when accessing mtd->usecount Thread-Topic: [PATCH] mtd: fix: avoid race condition when accessing mtd->usecount Thread-Index: AQHQfBzjoBQ0vQBeo0WApITUgZZ6AJ1xLPMAgAACHICAAAKIgIAFUZCQ Date: Mon, 11 May 2015 07:44:26 +0000 Message-ID: <362FEC998FA6CC42BC5BA5B7BA75E0970D5A08FA@DEMUMBX009.nsn-intra.net> References: <1429611622-2652-1-git-send-email-giuseppe.cantavenera.ext@nokia.com> <20150508001012.GV32500@ld-irv-0074> <20150508001745.GW32500@ld-irv-0074> <20150508002649.GX32500@ld-irv-0074> In-Reply-To: <20150508002649.GX32500@ld-irv-0074> Accept-Language: it-IT, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.159.42.157] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 2072 X-purgate-ID: 151667::1431330273-000011EF-1126A3C4/0/0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2251 Lines: 67 > -----Original Message----- > From: ext Brian Norris [mailto:computersforpeace@gmail.com] > Sent: Friday, May 08, 2015 2:27 AM > To: Cantavenera, Giuseppe (EXT-Other - DE/Ulm) > Cc: linux-mtd@lists.infradead.org; Restelli, Lorenzo (EXT-Other - > DE/Ulm); dwmw2@infradead.org; stable@vger.kernel.org; Sverdlin, > Alexander (Nokia - DE/Ulm); zhangxingcai; fengfuqiu@huawei.com; > tanhaijun@huawei.com; linux-kernel@vger.kernel.org > Subject: Re: [PATCH] mtd: fix: avoid race condition when accessing mtd- > >usecount > > On Thu, May 07, 2015 at 05:17:45PM -0700, Brian Norris wrote: > > On Thu, May 07, 2015 at 05:10:12PM -0700, Brian Norris wrote: > > > On Tue, Apr 21, 2015 at 12:20:22PM +0200, Giuseppe Cantavenera > wrote: > > > > @@ -484,7 +486,7 @@ int del_mtd_blktrans_dev(struct > mtd_blktrans_dev *old) > > > > if (old->open) { > > > > if (old->tr->release) > > > > old->tr->release(old); > > > > - __put_mtd_device(old->mtd); > > > > + put_mtd_device(old->mtd); > > > > > > This looks wrong. See: > > [...] > > > deregister_mtd_blktrans() > > > |_ mutex_lock(&mtd_table_mutex) > > > |_ tr->remove_dev() -> inftl_remove_dev() > > > |_ del_mtd_blktrans_dev() > > > |_ put_mtd_device() > > > |_ mutex_lock(&mtd_table_mutex) <--- AA deadlock > > > > What's more, this code in del_mtd_blktrans_dev() makes it obvious > that > > this hunk is wrong: > > > > int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old) > > { > > unsigned long flags; > > > > if (mutex_trylock(&mtd_table_mutex)) { > > mutex_unlock(&mtd_table_mutex); > > BUG(); > > } > > ... > > > > So rather than a comment, the code is showing that it's a BUG() to > not > > be holding mtd_table_mutex already. > Hello, Thanks for your comments and for pointing this out. Definitely yes.. we shouldn't change del_mtd_blktrans_dev(). > As an alternative to your patch, how about the following? I think it's the right way to go now. Thanks! Giuseppe -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/