From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753358AbdASQEp (ORCPT ); Thu, 19 Jan 2017 11:04:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:59727 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752811AbdASQEn (ORCPT ); Thu, 19 Jan 2017 11:04:43 -0500 Date: Thu, 19 Jan 2017 17:03:48 +0100 (CET) From: Jiri Kosina X-X-Sender: jkosina@pobox.suse.cz To: Greg Kroah-Hartman cc: Omar Sandoval , linux-kernel@vger.kernel.org Subject: Re: debugfs vs. device removal In-Reply-To: <20170119155345.GA11660@kroah.com> Message-ID: References: <20170119154841.GA6416@vader> <20170119155345.GA11660@kroah.com> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 19 Jan 2017, Greg Kroah-Hartman wrote: > > In the block layer, we abuse sysfs to export some per-device debugging > > information. I was looking into moving this to debugfs, but I realized > > that debugfs doesn't have a mechanism to ensure that a file associated > > with a device is safe to use when the device is removed. > > What do you mean by "safe"? The race conditions where you remove a file > and still have it open should all now be resolved in 4.8 and 4.9, di dwe > miss something? This is something else -- Omar is right, hid-debugfs interface is buggy. It basically doesn't synchronize the data dumping with device removal, so if device is removed and deallocated and the race is hit, it tries to dereference struct hid_device which has already been freed. I'll look into fixing this later today or tomorrow. Basically we'd need to synchronize between hid_remove_device() and anything in hid-debug and whenever removal is pending, not to try to get any data out of it any more and bail immediately. Something like rwlock (debugfs being the reader and device removal being the writer) should work. Thanks, -- Jiri Kosina SUSE Labs