Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3055310ybl; Mon, 20 Jan 2020 15:01:44 -0800 (PST) X-Google-Smtp-Source: APXvYqwLWk+S50lFRcDMxdZCHzh4eaxk1H4incyoatztSgD5pgulNonVaJTaoAwyMTVJRFMLVmPv X-Received: by 2002:a9d:22:: with SMTP id 31mr1263344ota.173.1579561304145; Mon, 20 Jan 2020 15:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579561304; cv=none; d=google.com; s=arc-20160816; b=o+OC5HiSUDOfw8/wiPB+0vR1/m+Z+YuUJ/W/YfYZVzW5HsKefgnFh0ATvbOzmrj0vk qLgYMNkBXYnvzrMSfDzN+Gcod/IE8TLwXQQBpvLMTTnaFXp35PF2ukLE5uM8qDgm8MTN NQYER3LkCHed9/LpWr/B2dZ/6dWPSA/aTgW83EZUuGdo1OnhpFDhoW3h7VjbKsk62Z+J 0cvVdIeap23dEQeLaVEsZJM1tU1qoPz4MZ1PsOXtk3ZcP6sifDcQ6hoj5jkVLegJEEki 84EHfrfoDrgTqPZW4QKyzHxpv8Jpp68HJPhjhx/kMUscuyg3Qto/NiTk8dsxnmfmAlQs avCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:dkim-signature; bh=UYSjWv1dfnioBe8F1SvdnjqlkR0e7zTphIpvFJSRRIE=; b=yg0IcIpDKRecsoYYWcPfg4VMfu02SHDaUi8HCfUc+Lo+iZJh3L37AOBapJ65sVwrYR e9/LlLlzse2PF23LDZAqwdwEdbGcyEYAMSjtFPdFOSWZkMHb+pvhXtMDFA+2FM5odbKp F7+UJ7EgB2epXkYTR/QQyTeN7tWCyNCq8j4T5lt2b4duLwJEr6rX8nXEf/aI+EkENn/T YQ/MtVlCWqqyleRC34V3JMia+fmZSnLkMj4a7c5OROjkGby5VEvrZ44K2WreeP0xxRJ8 vDpsQWAOSNLiJzPiLSP/rtbq8f/yAnkBP7Pm4RjVNZuWb2vMKjeEZCwM4tjyeyhwaoGx BmSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WMoUJnxP; 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 i3si9088928otc.272.2020.01.20.15.01.28; Mon, 20 Jan 2020 15:01:44 -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=WMoUJnxP; 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 S1726901AbgATW7P (ORCPT + 99 others); Mon, 20 Jan 2020 17:59:15 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58630 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726816AbgATW7O (ORCPT ); Mon, 20 Jan 2020 17:59:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579561154; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UYSjWv1dfnioBe8F1SvdnjqlkR0e7zTphIpvFJSRRIE=; b=WMoUJnxPrxB3Lp6s0xqQE2I42FEfi8x6pN8GOOmRzyovzTaSEeuxf24WjXyk6R9I6D7j83 PxYg5hlYwI4AgFBIZ9+CdbhtXaEDpT7kHpAyqXWtc71+AZ1wOk+JUee13x7tucvp1kAKkW hYbR312d+kIH0Twz+l7klogrenh1Q7k= 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-305-FxJAN8_wOWiCy0tquRdetw-1; Mon, 20 Jan 2020 17:59:10 -0500 X-MC-Unique: FxJAN8_wOWiCy0tquRdetw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F5CB18FF661; Mon, 20 Jan 2020 22:59:09 +0000 (UTC) Received: from ming.t460p (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF5D61001B2D; Mon, 20 Jan 2020 22:59:02 +0000 (UTC) Date: Tue, 21 Jan 2020 06:58:58 +0800 From: Ming Lei To: Zhiqiang Liu Cc: Jens Axboe , linux-block@vger.kernel.org, "linux-kernel@vger.kernel.org" , Mingfangsen , Guiyao , zhangsaisai , "wubo (T)" Subject: Re: [PATCH V3] brd: check and limit max_part par Message-ID: <20200120225858.GB19571@ming.t460p> References: <20200115022725.GA14585@ming.t460p> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 20, 2020 at 09:14:50PM +0800, Zhiqiang Liu wrote: >=20 >=20 > On 2020/1/15 10:27, Ming Lei wrote: >=20 > >=20 > >> MODULE_PARM_DESC(rd_nr, "Maximum number of brd devices"); > >> > >> unsigned long rd_size =3D CONFIG_BLK_DEV_RAM_SIZE; > >> module_param(rd_size, ulong, 0444); > >> MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes."); > >> > >> -static int max_part =3D 1; > >> -module_param(max_part, int, 0444); > >> +static unsigned int max_part =3D 1; > >> +module_param(max_part, uint, 0444); > >=20 > > The above change isn't needed. > Thanks for your suggestion. > I will remove that in v4 patch. > >=20 > >> MODULE_PARM_DESC(max_part, "Num Minors to reserve between devices")= ; > >> > >> MODULE_LICENSE("GPL"); > >> @@ -393,7 +393,14 @@ static struct brd_device *brd_alloc(int i) > >> if (!disk) > >> goto out_free_queue; > >> disk->major =3D RAMDISK_MAJOR; > >> - disk->first_minor =3D 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 dev= t. > >> + */ > >> + if ((i * disk->minors) & ~MINORMASK) > >> + disk->minors =3D 0; > >> + else > >> + disk->first_minor =3D i * disk->minors; > >=20 > > The above looks a bit ugly, one nice way could be to change in > > brd_alloc(): > >=20 > > disk =3D brd->brd_disk =3D alloc_disk(((i * max_part) & ~MINORMASK) = ? > > 0 : max_part); >=20 > I will change it as your suggestion. >=20 > >=20 > >> disk->fops =3D &brd_fops; > >> disk->private_data =3D brd; > >> disk->queue =3D brd->brd_queue; > >> @@ -468,6 +475,21 @@ static struct kobject *brd_probe(dev_t dev, int= *part, void *data) > >> return kobj; > >> } > >> > >> +static inline void brd_check_and_reset_par(void) > >> +{ > >> + if (unlikely(!rd_nr)) > >> + rd_nr =3D 1; > >=20 > > zero rd_nr should work as expected, given user can create dev file vi= a > > mknod, and brd_probe() will be called for populate brd disk/queue whe= n > > the disk file is opened. > >=20 > >> +static inline void brd_check_and_reset_par(void) > >> +{ > >> + =A0 =A0 =A0 if (unlikely(!rd_nr)) > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rd_nr =3D 1; > >> + > >> + =A0 =A0 =A0 if (unlikely(!max_part)) > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 max_part =3D 1; > >=20 > > Another limit is that 'max_part' needs to be divided exactly by (1U <= < > > MINORBITS), something like: > >=20 > > max_part =3D 1UL << fls(max_part) >=20 > Do we have to limit that 'max_part' needs to be divided exactly by (1U = << > > MINORBITS)? As your suggestion, the i * max_part is larger than MINOR= MASK, > we can allocate from extended devt. Exact dividing is for reserving same minors for all disks with RAMDISK_MAJOR, otherwise there is still chance to get same dev_t when adding partitions. Extended devt is for covering more disks, not related with 'max_part'. Thanks, Ming