Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5005260ybl; Tue, 14 Jan 2020 01:48:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxJBSR/DmBaeUZwp/QbHXA1+MqYD+PYai6zVRqUnRuer8VI1WwcKOMR4vxmOqcosnQxGs0J X-Received: by 2002:aca:c38c:: with SMTP id t134mr15283890oif.175.1578995288247; Tue, 14 Jan 2020 01:48:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578995288; cv=none; d=google.com; s=arc-20160816; b=gJGaKSdrRB6OobvdoyKdjDwMm5JOSUcHdG1tOa/+rE/etORVD3zZVJnHAxP2S61a76 Hz+cix5WbIIjoaDdfzFlG1yLypYgt+DHJ/PpYGEyMQYJGQfOoG11BeFk3szPKaX0h7Lz +YyhWN9bCMSZgVu9dqEB3WGT2g2KeBm2DRHE/9r5spSHR1Pf2eGCE3T1m+vg8TaCdg0v lKLK4yZtcTIRuE4ulT3uEMKBKi+4ZtNhJVnb69v0Zpxow9EVHj6fhM1RU68E1jKXPAO9 SHQ2KXo1Nr84kHeZQBKmVRplYeRY9h/UCiny4/R2GgkKxRfUnzoU3N444Jyvc9c2EO5w MidQ== 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:dkim-signature; bh=MqMDjz/VvcVqy9TYrQgv7wG9Dsl85OcI1K5HrS1sw24=; b=u/C91JRJK8Hb+ULI3QnKyIgWOF85I65uQ5wtPj4nXzx14i3ZOBwuRoTOd97PucVmA9 BUs7Fh7cy495av5Gr84k9irz9+xUDacWXej2kVYrEUFxzSgDJwkWZQHsDtH2bDH4Tef6 4emiKXv78NKfqPnvpigkwdRfxXpy9H456d2TqekSlL4lvmZX7qurw/+I54K+cAAzIHnt 6bE7+8R+EGxs0baXJkZMz9IpTtlxED2sX6oOIdsgHbHMYAuorPFoWF7UzPE4i4zdHEEA zeabNKK/k09A89Kksov2hf6R6UhzxdL0e73RkR84uuHXjEzW2Mf3QblWYzzjpPbO523I sgRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UoNjdviU; 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=pass (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 f18si8390283otl.29.2020.01.14.01.47.56; Tue, 14 Jan 2020 01:48:08 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UoNjdviU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729049AbgANJqG (ORCPT + 99 others); Tue, 14 Jan 2020 04:46:06 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:36640 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725820AbgANJqF (ORCPT ); Tue, 14 Jan 2020 04:46:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578995164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MqMDjz/VvcVqy9TYrQgv7wG9Dsl85OcI1K5HrS1sw24=; b=UoNjdviUAVGLgzUZdOwpvxXGOr+as7b5SEnmvIazG69moCqZ4n28wORZ+Azn0b+qphLSJ+ QacaztUxgm509X/2mUnhoN040c/ZjUztyrT9y6llgBOmmdk7kh6JtyIW7Br3+ueAjY8AHZ lyqKPmmQnwBdZmq/vE087OKRxpC6Xmc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-QBsaalF3My6c6zFxcrOtcw-1; Tue, 14 Jan 2020 04:46:03 -0500 X-MC-Unique: QBsaalF3My6c6zFxcrOtcw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97CFF593A0; Tue, 14 Jan 2020 09:46:01 +0000 (UTC) Received: from ming.t460p (ovpn-8-27.pek2.redhat.com [10.72.8.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C87560BF1; Tue, 14 Jan 2020 09:45:54 +0000 (UTC) Date: Tue, 14 Jan 2020 17:45:50 +0800 From: Ming Lei To: Zhiqiang Liu Cc: axboe@kernel.dk, linux-block@vger.kernel.org, "linux-kernel@vger.kernel.org" , Mingfangsen , Guiyao , zhangsaisai , "wubo (T)" Subject: Re: [PATCH V2] brd: check parameter validation before register_blkdev func Message-ID: <20200114094550.GA18268@ming.t460p> References: <8b32ff09-74aa-3b92-38e4-aab12f47597b@huawei.com> <20200114091456.GA22268@ming.t460p> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200114091456.GA22268@ming.t460p> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 14, 2020 at 05:16:57PM +0800, Ming Lei wrote: > On Mon, Jan 13, 2020 at 09:43:23PM +0800, Zhiqiang Liu wrote: > > In brd_init func, rd_nr num of brd_device are firstly allocated > > and add in brd_devices, then brd_devices are traversed to add each > > brd_device by calling add_disk func. When allocating brd_device, > > the disk->first_minor is set to i * max_part, if rd_nr * max_part > > is larger than MINORMASK, two different brd_device may have the same > > devt, then only one of them can be successfully added. > > It is just because disk->first_minor is >= 0x100000, then same dev_t > can be allocated in blk_alloc_devt(). > > MKDEV(disk->major, disk->first_minor + part->partno) > > But block layer does support extended dynamic devt allocation, and brd > sets flag of GENHD_FL_EXT_DEVT too. > > So I think the correct fix is to fallback to extended dynamic allocation > when running out of consecutive minor space. > > How about the following approach? > > And of course, ext devt allocation may fail too, but that is another > generic un-solved issue: error handling isn't done for adding disk. > > diff --git a/drivers/block/brd.c b/drivers/block/brd.c > index a8730cc4db10..9aa7ce7c9abf 100644 > --- a/drivers/block/brd.c > +++ b/drivers/block/brd.c > @@ -398,7 +398,16 @@ static struct brd_device *brd_alloc(int i) > if (!disk) > goto out_free_queue; > disk->major = RAMDISK_MAJOR; > - disk->first_minor = i * max_part; > + > + /* > + * Clear .minors when running out of consecutive minor space since > + * GENHD_FL_EXT_DEVT is set, and we can allocate from extended devt > + */ > + if ((i * disk->minors) & ~MINORMASK) > + disk->minors = 0; > + else > + disk->first_minor = i * disk->minors; > + > disk->fops = &brd_fops; > disk->private_data = brd; > disk->flags = GENHD_FL_EXT_DEVT; But still suggest to limit 'max_part' <= 256, and the name is actually misleading, which just reserves consecutive minors. However, I don't think it is a good idea to add limit on device number. Thanks, Ming