From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751537AbdISP6k convert rfc822-to-8bit (ORCPT ); Tue, 19 Sep 2017 11:58:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11917 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750990AbdISP6i (ORCPT ); Tue, 19 Sep 2017 11:58:38 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DB2AE7E457 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=longman@redhat.com Subject: Re: [PATCH v6 1/2] blktrace: Fix potentail deadlock between delete & sysfs ops To: Christoph Hellwig Cc: Jens Axboe , Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-nilfs@vger.kernel.org, cluster-devel@redhat.com, Bart Van Assche References: <1505760831-7747-1-git-send-email-longman@redhat.com> <1505760831-7747-2-git-send-email-longman@redhat.com> <20170919000155.GA30806@infradead.org> <20170919143811.GB15944@infradead.org> From: Waiman Long Organization: Red Hat Message-ID: Date: Tue, 19 Sep 2017 11:58:34 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20170919143811.GB15944@infradead.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Content-Language: en-US X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 19 Sep 2017 15:58:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/19/2017 10:38 AM, Christoph Hellwig wrote: > On Tue, Sep 19, 2017 at 08:49:12AM -0400, Waiman Long wrote: >> On 09/18/2017 08:01 PM, Christoph Hellwig wrote: >>> Taking a look at this it seems like using a lock in struct block_device >>> isn't the right thing to do anyway - all the action is on fields in >>> struct blk_trace, so having a lock inside that would make a lot more >>> sense. >>> >>> It would also help to document what exactly we're actually protecting. >> I think I documented in the patch that the lock has to protect changes >> in the blktrace structure as well as the allocation and destruction of >> it. Because of that, it can't be put inside the blktrace structure. The >> original code use the bd_mutex of the block_device structure. I just >> change the code to use another bd_fsfreeze_mutex in the same structure. > Either way it has absolutely nothing to do with struct block_device, > given that struct blk_trace hangs off the request_queue. > > Reusing a mutex just because it happens to live in a structure also > generally is a bad idea if the protected data is in no way related. I was trying not to add a new mutex to a structure just for blktrace as it is an optional feature that is enabled only if the CONFIG_BLK_DEV_IO_TRACE config option is defined and it will only need to be taken occasionally. As filesystem freeze looks orthogonal to blktrace and the mutex also looks to be used sparingly, I think it is a good match to overload it to control blktrace as well. I could modify the patch to use a mutex in the request_queue structure. The current sysfs_lock mutex has about 74 references. So I am not totally sure if it is safe to reuse. So the only option is to add something like #ifdef CONFIG_BLK_DEV_IO_TRACE struct mutex blktrace_mutex; #endif to the request_queue structure. That structure is large enough that adding a mutex won't increase the size much percentage-wise. I would like to keep the current patch as is as I don't see any problem with it. However, I can revise the patch as discussed above if you guys prefer that alternative. Cheers, Longman