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=-8.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 40F56C2BA2B for ; Thu, 16 Apr 2020 05:36:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0E41320771 for ; Thu, 16 Apr 2020 05:36:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E41320771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5F4B28E0082; Thu, 16 Apr 2020 01:36:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A5ED8E0001; Thu, 16 Apr 2020 01:36:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BC078E0082; Thu, 16 Apr 2020 01:36:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id 319498E0001 for ; Thu, 16 Apr 2020 01:36:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E9D736129 for ; Thu, 16 Apr 2020 05:36:25 +0000 (UTC) X-FDA: 76712607930.28.hair33_381c3680d9350 X-HE-Tag: hair33_381c3680d9350 X-Filterd-Recvd-Size: 4817 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Apr 2020 05:36:25 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id m21so1144664pff.13 for ; Wed, 15 Apr 2020 22:36:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0GGMjsf7bes7SO0tixSZYBmOOrlUUrx9KPMpJ3HujiA=; b=csdZnbUK92oF4Sieughp42bx9Tc+NqPDSTYzF9qyJIZselM3V7e8EnQPlraJbyVkGN TEovxLVEystRY8ogCIecllrTiR+Qo767s5XD9BRMD6tTHRSrcw91mbYzY6Bgg9pdznlx ooiHTXH2O47JTR6YfdnF56ih4BJ3TcV+ZBQEwv+7OeBmCUYlPwtYHaJfx/qN+mXGtaUR aEFKBqAHiYrQonE0EYBIj80+Tt+anlGiVfhYW9au1cgP+gLypJ9itkxg5EggAjog5pJ+ VvQLCQ6Zmhii/td0xta7Vqs3S42A/2ZeB0tlXVYcKamUf/AlNF3V8W/hyflRlNDvo3Al IMfg== X-Gm-Message-State: AGi0PuZAX7gl4fdDNBRGXAp4z2F4W9a3mBLHNjd0OeVOPK/iSpj9cJdo C+ftQ0jd0AE6IcBFLVYcuDE= X-Google-Smtp-Source: APiQypKbKv0BkBHKUzEiqUuVeGbX7gfEsR18Wnsdwe3iyXHjlLh95ibBMf8/BWrc5gEIAQNARJvn0Q== X-Received: by 2002:a65:68c7:: with SMTP id k7mr30843871pgt.248.1587015384681; Wed, 15 Apr 2020 22:36:24 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id w5sm15602046pfw.154.2020.04.15.22.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 22:36:23 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id C714B40277; Thu, 16 Apr 2020 05:36:22 +0000 (UTC) Date: Thu, 16 Apr 2020 05:36:22 +0000 From: Luis Chamberlain To: Ming Lei 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: <20200416053622.GJ11244@42.do-not-panic.com> References: <20200414041902.16769-1-mcgrof@kernel.org> <20200414041902.16769-4-mcgrof@kernel.org> <20200416023122.GB2717677@T590> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200416023122.GB2717677@T590> User-Agent: Mutt/1.10.1 (2018-07-13) 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 Thu, Apr 16, 2020 at 10:31:22AM +0800, Ming Lei wrote: > 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. Alright, then yes, this should not be needed. Luis