From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D102AC2BA19 for ; Thu, 16 Apr 2020 02:31:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 933D72076C for ; Thu, 16 Apr 2020 02:31:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TCFUfL8V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 933D72076C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5BCCE8E006F; Wed, 15 Apr 2020 22:31:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56E728E0001; Wed, 15 Apr 2020 22:31:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45CAE8E006F; Wed, 15 Apr 2020 22:31:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 2B60F8E0001 for ; Wed, 15 Apr 2020 22:31:47 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DB1BB52A0 for ; Thu, 16 Apr 2020 02:31:46 +0000 (UTC) X-FDA: 76712142612.29.tooth98_2c9c432b5981b X-HE-Tag: tooth98_2c9c432b5981b X-Filterd-Recvd-Size: 4299 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Apr 2020 02:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587004306; 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=MvV/kU/pFrjkbAJ+eW/cY6VL5dwLgz9Jc5F00dhkTB0=; b=TCFUfL8VmU4pgAuynaRGA1B4g6UyhBHNZmlDNyYyy5xBVfWe3tTEmo+tocerAxLTQjS8bH SKU1i1q9AfqKYV7eOwR/mmgRfYzXhdTz9amwyj9Sma6oLykAtcUPVhuLcou7FCEf/+Xoos 3F4kmaPu8Q/M6uuHv+rLNi1AYimrsoc= 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-458-fZPwCsSMMmSAl1giz5QxOw-1; Wed, 15 Apr 2020 22:31:42 -0400 X-MC-Unique: fZPwCsSMMmSAl1giz5QxOw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADBBC1005509; Thu, 16 Apr 2020 02:31:39 +0000 (UTC) Received: from T590 (ovpn-8-29.pek2.redhat.com [10.72.8.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 947DA272A1; Thu, 16 Apr 2020 02:31:27 +0000 (UTC) Date: Thu, 16 Apr 2020 10:31:22 +0800 From: Ming Lei To: Luis Chamberlain Cc: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, nstange@suse.de, akpm@linux-foundation.org, mhocko@suse.com, yukuai3@huawei.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Omar Sandoval , Hannes Reinecke , Michal Hocko Subject: Re: [PATCH 3/5] blktrace: refcount the request_queue during ioctl Message-ID: <20200416023122.GB2717677@T590> References: <20200414041902.16769-1-mcgrof@kernel.org> <20200414041902.16769-4-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200414041902.16769-4-mcgrof@kernel.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Apr 14, 2020 at 04:19:00AM +0000, Luis Chamberlain wrote: > Ensure that the request_queue is refcounted during its full > ioctl cycle. This avoids possible races against removal, given > blk_get_queue() also checks to ensure the queue is not dying. > > This small race is possible if you defer removal of the request_queue > and userspace fires off an ioctl for the device in the meantime. > > Cc: Bart Van Assche > Cc: Omar Sandoval > Cc: Hannes Reinecke > Cc: Nicolai Stange > Cc: Greg Kroah-Hartman > Cc: Michal Hocko > Cc: yu kuai > Reviewed-by: Bart Van Assche > Signed-off-by: Luis Chamberlain > --- > kernel/trace/blktrace.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c > index 15086227592f..17e144d15779 100644 > --- a/kernel/trace/blktrace.c > +++ b/kernel/trace/blktrace.c > @@ -701,6 +701,9 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg) > if (!q) > return -ENXIO; > > + if (!blk_get_queue(q)) > + return -ENXIO; > + > mutex_lock(&q->blk_trace_mutex); > > switch (cmd) { > @@ -729,6 +732,9 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg) > } > > mutex_unlock(&q->blk_trace_mutex); > + > + blk_put_queue(q); > + > return ret; > } Actually when bdev is opened, one extra refcount is held on gendisk, so gendisk won't go away. And __device_add_disk() does grab one extra refcount on request queue, so request queue shouldn't go away when ioctl is running. Can you describe a bit more what the issue is to be addressed by this patch? Thanks, Ming