Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937368AbdIZP70 (ORCPT ); Tue, 26 Sep 2017 11:59:26 -0400 Received: from mx.kolabnow.com ([95.128.36.42]:53688 "EHLO mx.kolabnow.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935993AbdIZP7Z (ORCPT ); Tue, 26 Sep 2017 11:59:25 -0400 X-Greylist: delayed 505 seconds by postgrey-1.27 at vger.kernel.org; Tue, 26 Sep 2017 11:59:24 EDT From: Federico Vaga To: Greg Kroah-Hartman , Tejun Heo Reply-To: federico.vaga@vaga.pv.it Cc: linux-kernel@vger.kernel.org Subject: kernFS/sysfs: mmap and vm_operations close Date: Tue, 26 Sep 2017 17:50:55 +0200 Message-ID: <1630389.Mmh9faUyQX@number-5> Organization: VAGA MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1164 Lines: 35 Hello, I'm writing a sysfs binary attribute that makes use of the `mmap` operation. I would like to implement my own `open()` and `close()` `vm_ops` but apparently I'm not allowed to do it. -------- 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" ? Is there an alternative/hack in order to be notified when the mmap is not used anymore and I can properly release my resources? 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` thank you very much :) -- Federico Vaga http://www.federicovaga.it