From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fg-out-1718.google.com ([72.14.220.158]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NetoB-0004FY-UE for linux-mtd@lists.infradead.org; Tue, 09 Feb 2010 17:23:36 +0000 Received: by fg-out-1718.google.com with SMTP id e12so273433fga.0 for ; Tue, 09 Feb 2010 09:23:30 -0800 (PST) Subject: Re: [PATCH 01/17] MTD: create lockless versions of {get,put}_mtd_device This will be used to resolve deadlock in block translation layer. From: Maxim Levitsky To: Peter Zijlstra In-Reply-To: <1265735693.11509.253.camel@laptop> References: <1265734665-22656-1-git-send-email-maximlevitsky@gmail.com> <1265734665-22656-2-git-send-email-maximlevitsky@gmail.com> <1265735693.11509.253.camel@laptop> Content-Type: text/plain; charset="UTF-8" Date: Tue, 09 Feb 2010 19:23:26 +0200 Message-ID: <1265736206.9195.4.camel@maxim-laptop> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Cc: Alex Dubov , Artem Bityutskiy , joern , Vitaly Wool , linux-kernel , "stanley.miao" , linux-mtd , Thomas Gleixner , David Woodhouse List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Tue, 2010-02-09 at 18:14 +0100, Peter Zijlstra wrote: > On Tue, 2010-02-09 at 18:57 +0200, Maxim Levitsky wrote: > > These functions can be used as long as we don't need access to global mtd table, but have > > a pointer to the mtd device. > > > > Signed-off-by: Maxim Levitsky > > --- > > drivers/mtd/mtdcore.c | 60 ++++++++++++++++++++++++++++++---------------- > > include/linux/mtd/mtd.h | 3 +- > > 2 files changed, 41 insertions(+), 22 deletions(-) > > > +int __get_mtd_device(struct mtd_info *mtd) > > +{ > > + int err; > > + > > + if (!try_module_get(mtd->owner)) > > + return -ENODEV; > > + > > + if (mtd->get_device) { > > + > > + err = mtd->get_device(mtd); > > + > > + if (err) { > > + module_put(mtd->owner); > > + return err; > > + } > > + } > > + mtd->usecount++; > > + return 0; > > } > > > +void __put_mtd_device(struct mtd_info *mtd) > > +{ > > + --mtd->usecount; > > + BUG_ON(mtd->usecount < 0); > > + > > if (mtd->put_device) > > mtd->put_device(mtd); > > > > module_put(mtd->owner); > > } > > That's racy, use kref. > Couldn't agree with you more. However, these functions aren't intended for general use, and probably will be used by mtd translation layer only. I do have a lock that protects concurrent use of these functions. Thus, I better add a comment about this? Best regards, Maxim Levitsky From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755329Ab0BIRXd (ORCPT ); Tue, 9 Feb 2010 12:23:33 -0500 Received: from fg-out-1718.google.com ([72.14.220.153]:42324 "EHLO fg-out-1718.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754899Ab0BIRXc (ORCPT ); Tue, 9 Feb 2010 12:23:32 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=U3QoQYX0h+fyt4tgQ5TMwp3M7qs6vz9JkdDkqpvY/HPn4p5aZbFyZVsUlem5AzR2Rd 5Q5kwZ01ypo4YqdjIOdfge2YDsE1n9HzkJHD0mUHJCcwqt8xnwfGdf2OEiv8pvL/GL1u cgPARUG0l35P52U068Uws8yUZx+R5Hy7OUDpY= Subject: Re: [PATCH 01/17] MTD: create lockless versions of {get,put}_mtd_device This will be used to resolve deadlock in block translation layer. From: Maxim Levitsky To: Peter Zijlstra Cc: David Woodhouse , Artem Bityutskiy , linux-mtd , linux-kernel , Alex Dubov , joern , Thomas Gleixner , "stanley.miao" , Vitaly Wool In-Reply-To: <1265735693.11509.253.camel@laptop> References: <1265734665-22656-1-git-send-email-maximlevitsky@gmail.com> <1265734665-22656-2-git-send-email-maximlevitsky@gmail.com> <1265735693.11509.253.camel@laptop> Content-Type: text/plain; charset="UTF-8" Date: Tue, 09 Feb 2010 19:23:26 +0200 Message-ID: <1265736206.9195.4.camel@maxim-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2010-02-09 at 18:14 +0100, Peter Zijlstra wrote: > On Tue, 2010-02-09 at 18:57 +0200, Maxim Levitsky wrote: > > These functions can be used as long as we don't need access to global mtd table, but have > > a pointer to the mtd device. > > > > Signed-off-by: Maxim Levitsky > > --- > > drivers/mtd/mtdcore.c | 60 ++++++++++++++++++++++++++++++---------------- > > include/linux/mtd/mtd.h | 3 +- > > 2 files changed, 41 insertions(+), 22 deletions(-) > > > +int __get_mtd_device(struct mtd_info *mtd) > > +{ > > + int err; > > + > > + if (!try_module_get(mtd->owner)) > > + return -ENODEV; > > + > > + if (mtd->get_device) { > > + > > + err = mtd->get_device(mtd); > > + > > + if (err) { > > + module_put(mtd->owner); > > + return err; > > + } > > + } > > + mtd->usecount++; > > + return 0; > > } > > > +void __put_mtd_device(struct mtd_info *mtd) > > +{ > > + --mtd->usecount; > > + BUG_ON(mtd->usecount < 0); > > + > > if (mtd->put_device) > > mtd->put_device(mtd); > > > > module_put(mtd->owner); > > } > > That's racy, use kref. > Couldn't agree with you more. However, these functions aren't intended for general use, and probably will be used by mtd translation layer only. I do have a lock that protects concurrent use of these functions. Thus, I better add a comment about this? Best regards, Maxim Levitsky