Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp756184yba; Wed, 15 May 2019 09:23:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiY8eLsP55wzfArUycbHc/KZDtr+dtisPLLRc2qCBXVyx7A74q/u0V0e++ZTAWkPGHTkNC X-Received: by 2002:a17:902:7486:: with SMTP id h6mr44299676pll.58.1557937381943; Wed, 15 May 2019 09:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557937381; cv=none; d=google.com; s=arc-20160816; b=fOgjPTguCu9xcz8XtkJYZYQWan3JvN4+MUa9S1sbXYER3w/A4avxyr7/TuCwlbRHxD MefGciRG5sk68q8XnL6maecprYGBNKaRbH07Uttb00K8pEmjDISjQkE84/M+sUDpP7sQ lSaT7ye9twdlTookA/SpvUoQ+d5DA06JaONTpC9dEmob13Ptw73FMJABK0wdnZn+0yX3 cNiTglzErzsuP1arQg6sRQqJvHe2A81pWDuKngLp+A1Thna1wrzIQI9AJQjQwew+DKrQ y+IMplK3A4M393jbah9BHmCIuJx01owFrL+l+fbI5G5kV7ptScrCY82gndixIVAKnv6a jJpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=HUZ3RFvSEuxd/E6mGQTbrOB818XnGI4nvYooNtMS1EY=; b=IkF0S5XOPmHUVLNUhXxyo8iuTLaCrosXP5jl5Fo5nPpBOInJj5M+F/Ze4XSJd/9OA7 8cmm1aAR5IdFCQqj5FevlXFaqBQYUYvCoMvRuQFQFr2mYnTR78ve68bOE8757/OZ7wec ziv7oJDmW/lszyKeo0SAv3rZri4r8lU6H+Cvb7isXMtZgA5dQlaYon/zjYd2kYsKhfr5 Ezsb2hJEdrbdO4A5X13Ytfqrh58X3bql7V8iL1tXdJobZrwcBN05plBWgoD1uOEvKY6N SIf4RvriuW7yExQ3YCUA6BlIFtJ4FdlDf18lHAqaTQSarPUWftPOqFAMhvippHC12L+g mavQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si2047714pls.124.2019.05.15.09.22.46; Wed, 15 May 2019 09:23:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbfEOQU6 (ORCPT + 99 others); Wed, 15 May 2019 12:20:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49660 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbfEOQU6 (ORCPT ); Wed, 15 May 2019 12:20:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E137985A03; Wed, 15 May 2019 16:20:57 +0000 (UTC) Received: from localhost (unknown [10.18.25.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54516608B9; Wed, 15 May 2019 16:20:55 +0000 (UTC) Date: Wed, 15 May 2019 12:20:54 -0400 From: Mike Snitzer To: Helen Koike Cc: dm-devel@redhat.com, kernel@collabora.com, linux-kernel@vger.kernel.org, Alasdair Kergon Subject: Re: dm ioctl: fix hang in early create error condition Message-ID: <20190515162054.GA14934@redhat.com> References: <20190513192530.1167-1-helen.koike@collabora.com> <20190514013716.GA10260@lobo> <78dda04b-925f-49eb-f88a-6d940bcc4754@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <78dda04b-925f-49eb-f88a-6d940bcc4754@collabora.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 15 May 2019 16:20:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 15 2019 at 12:12pm -0400, Helen Koike wrote: > Hi, > > On 5/13/19 10:37 PM, Mike Snitzer wrote: > > On Mon, May 13 2019 at 3:25P -0400, > > Helen Koike wrote: > > > >> The dm_early_create() function (which deals with "dm-mod.create=" kernel > >> command line option) calls dm_hash_insert() who gets an extra reference > >> to the md object. > >> > >> In case of failure, this reference wasn't being released, causing > >> dm_destroy() to hang, thus hanging the whole boot process. > >> > >> Fix this by calling __hash_remove() in the error path. > >> > >> Fixes: 6bbc923dfcf57d ("dm: add support to directly boot to a mapped device") > >> Cc: stable@vger.kernel.org > >> Signed-off-by: Helen Koike > >> > >> --- > >> Hi, > >> > >> I tested this patch by adding a new test case in the following test > >> script: > >> > >> https://gitlab.collabora.com/koike/dm-cmdline-test/commit/d2d7a0ee4a49931cdb59f08a837b516c2d5d743d > >> > >> This test was failing, but with this patch it works correctly. > >> > >> Thanks > >> Helen > > > > Thanks for the patch but I'd prefer the following simpler fix. What do > > you think? > > > > That said, I can provide a follow-on patch (inspired by the patch you > > provided) that encourages more code sharing between dm_early_create() > > and dev_create() by factoring out __dev_create(). > > Sounds great. > > > > > diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c > > index c740153b4e52..0eb0b462c736 100644 > > --- a/drivers/md/dm-ioctl.c > > +++ b/drivers/md/dm-ioctl.c > > @@ -2117,6 +2117,7 @@ int __init dm_early_create(struct dm_ioctl *dmi, > > err_destroy_table: > > dm_table_destroy(t); > > err_destroy_dm: > > + (void) __hash_remove(__find_device_hash_cell(dmi)); > > dm_put(md); > > dm_destroy(md); > > return r; > > > > This doesn't really work for two reasons: > > 1) __find_device_hash_cell() requires a mutual exclusivity between name, > uuid and dev. In dm_early_create(), dmi can have more then one of these. __find_device_hash_cell's exclusivity requirements are strange; I'll try to understand what requires this. > 2) I can fix (1) by calling __get_name_cell(), as the name is mandatory > anyway, but this function also grabs another reference to the md object, > so I need to add an extra dm_put(md) there: > > err_destroy_table: > dm_table_destroy(t); > +err_hash_remove: > + (void) __hash_remove(__get_name_cell(dmi->name)); > + dm_put(md); > err_destroy_dm: > dm_put(md); > dm_destroy(md); > > > What do you think? Is this ok? I think so. Please submit a v2 and I'll rebase my followon patch accordingly and will get it posted. Thanks, Mike