Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1235422ybz; Thu, 16 Apr 2020 05:35:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIlhzHBL50iWBjGrYAHgUKB4GTEXyfyOQV07BThr0fmb4wQ22xy2pwYq+7+CRtYhVSYwrL/ X-Received: by 2002:a17:906:dc02:: with SMTP id yy2mr2486245ejb.11.1587040537676; Thu, 16 Apr 2020 05:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587040537; cv=none; d=google.com; s=arc-20160816; b=RIhmvNa79zE9LrcIKt8B6x2/JDRx6uV4ETcEkP6pa/8pl9/wYnCxgyN4pAwycKjgW8 DA4hHLjbt85pF/ERy7SrgYYqtP3WasXJ+wFq494OnZq3j9uSG8ZLmfoIkf8HCWeTYpG9 /YUBQx8DB7tGnkwP22oyAXXyA+3wPVK9MIdC5ryP9acWcvs9Cl07VuOOJ/JPOaLO4w8z 7DR06j4YwgP+Uvjh+u500j9+ZXdDeqLUXnbOlAfgdqTwjazN+rnwD+OAtnYOwpzPWqMo VkoPTy+pxkxBrC6A9wU4Whp/CyecJdv9PlTL+w7RtCIJ6j5kSvzWcgvpL+e86aKfJZK2 rwWw== 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=yhppd+1nmDyrx3K5Pvi8EHeHxMQtYXBXb7GqHVDkb0k=; b=Dp2TEh3uTFpO7WTfcJnEZs9ZyGQcJSeX8n3L9FFG0Q0ovPVJremuPxRerLuE6L6oqT QleROTNto0ctNg9zC0Tn/bKL4QxU8oEFVt78XzoDFWoOzyqqDgtYCeiF33aJwZhi7Ebl 25GPs4csr7+L9SiTDG6SRhou0an0tbTiSTDNaLUIu9Th7zDedGW03MYfSe5c+dtkg7NB j0FfCM2pqCsbwBbwisp36PMvXIhP9O0+sPydQbYUvNp/1Nuv+ekrPIQN7End/XwCK6nC 1YHKl8UavX2XWm86idhTkqVwtDkmJ0HVH+QvU4obJ7i/TuOQzzNMOwLhpVu2OMGMm3t1 RZFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 4si12045931ejz.429.2020.04.16.05.35.14; Thu, 16 Apr 2020 05:35:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2635592AbgDPMb4 (ORCPT + 99 others); Thu, 16 Apr 2020 08:31:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:50842 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439151AbgDPMbn (ORCPT ); Thu, 16 Apr 2020 08:31:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9FD7FAC6D; Thu, 16 Apr 2020 12:31:40 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 155541E1250; Thu, 16 Apr 2020 14:31:40 +0200 (CEST) Date: Thu, 16 Apr 2020 14:31:40 +0200 From: Jan Kara To: Christoph Hellwig Cc: Jan Kara , Yufen Yu , axboe@kernel.dk, tj@kernel.org, bvanassche@acm.org, tytso@mit.edu, gregkh@linuxfoundation.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/8] bdi: add a ->dev_name field to struct backing_dev_info Message-ID: <20200416123140.GN23739@quack2.suse.cz> References: <20200416071519.807660-1-hch@lst.de> <20200416071519.807660-4-hch@lst.de> <5bfcd35a-2463-3769-be93-911c4e3c38bb@huawei.com> <20200416120223.GI23739@quack2.suse.cz> <20200416121901.GA26483@lst.de> <20200416122235.GA26982@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200416122235.GA26982@lst.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 16-04-20 14:22:35, Christoph Hellwig wrote: > On Thu, Apr 16, 2020 at 02:19:01PM +0200, Christoph Hellwig wrote: > > On Thu, Apr 16, 2020 at 02:02:23PM +0200, Jan Kara wrote: > > > Yes, that can indeed happen. E.g. I remember that drivers/scsi/sd.c calls > > > device_add_disk() + del_gendisk() repeatedly for one request_queue and that > > > would result in leaking the name (and possibly cause use-after-free > > > issues). > > > > Sd calls device_add_disk once in ->probe, and del_gendisk once in > > sd_remove. Note that sd_probe allocates a new scsi_disk structure and > > a new gendisk everytime, but it does indeed reuse the request_queue > > and thus bdi. > > > > > I think dev_name has to be just a static array inside > > > backing_dev_info which gets overwritten on reregistration. The question is > > > how big should be this array... Some grepping shows that 40 bytes should be > > > enough for everybody except fs/vboxsf/super.c which puts 'fc->source' into > > > the name which can be presumably rather large. Anyway, I'd make it 40 and > > > just truncate it case in case it does not fit. bdi_dev_name() is used for > > > informational purposes anyway... > > > > We could just make it a variable sized array at the end of the structure > > and size it based on the len. > > Which doesn't always work as the size might not always be the same. > But I think the fundamental problem is that we are trying to re-register > previous unregistered bdis. We really should not have bdi_alloc > separate from bdi_register and solve this properly. Yes, that would be easier then but it seems like a much larger change because currently bdi is disassociated from request_queue only in __blk_release_queue() (blk_exit_queue()). I guess the separate bdi registration / deregistration is partially a leftover from times when bdi was still embedded in request_queue but now it's difficult to undo it. Honza -- Jan Kara SUSE Labs, CR