From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032164AbdIZVbW (ORCPT ); Tue, 26 Sep 2017 17:31:22 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53792 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030301AbdIZVbV (ORCPT ); Tue, 26 Sep 2017 17:31:21 -0400 Date: Tue, 26 Sep 2017 23:31:29 +0200 From: Greg Kroah-Hartman To: Federico Vaga Cc: Tejun Heo , linux-kernel@vger.kernel.org Subject: Re: kernFS/sysfs: mmap and vm_operations close Message-ID: <20170926213129.GA3418@kroah.com> References: <1630389.Mmh9faUyQX@number-5> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1630389.Mmh9faUyQX@number-5> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 26, 2017 at 05:50:55PM +0200, Federico Vaga wrote: > Hello, > > I'm writing a sysfs binary attribute that makes use of the `mmap` operation. Eeek, why? What are you using that for? sysfs binary attributes are for dumping binary data that the kernel doesn't touch/parse, through to hardware. Why use mmap for this? Do you have a pointer to your code somewhere? > I would like to implement my own `open()` and `close()` `vm_ops` but > apparently I'm not allowed to do it. Nope, you are not, not in sysfs :) > > -------- kernfs/file.c - kernfs_fop_mmap () - modern kernel ----- > -------- sysfs/bin.c - mmap () - old kernel ----- > > /* > * It is not possible to successfully wrap close. > * So error if someone is trying to use close. > */ > rc = -EINVAL; > if (vma->vm_ops && vma->vm_ops->close) > goto out_put; > ---------------------------------------------------------- > > What is the reason behind this choice? > Why "it is not possible to successfully wrap close" ? Because you shouldn't be doing that :) > Is there an alternative/hack in order to be notified when the mmap is not used > anymore and I can properly release my resources? Don't use mmap in sysfs :) > Due to HW resources limitation I "cannot" keep the device memory mapped when > nobody is using it, that's why I would like to be able to use vm_ops->close(). > In general, I would like to run my routine that release resources when the > user does `munmap` or `close` Don't use mmap in sysfs :) What problem are you trying to solve here that mmap seemed like the correct solution? thanks, greg k-h