From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Federico Vaga <federico.vaga@vaga.pv.it>
Cc: Tejun Heo <tj@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: kernFS/sysfs: mmap and vm_operations close
Date: Tue, 26 Sep 2017 23:31:29 +0200 [thread overview]
Message-ID: <20170926213129.GA3418@kroah.com> (raw)
In-Reply-To: <1630389.Mmh9faUyQX@number-5>
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
next prev parent reply other threads:[~2017-09-26 21:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-26 15:50 kernFS/sysfs: mmap and vm_operations close Federico Vaga
2017-09-26 21:31 ` Greg Kroah-Hartman [this message]
2017-09-27 6:41 ` Federico Vaga
2017-09-27 7:45 ` Greg Kroah-Hartman
2017-09-27 9:38 ` Federico Vaga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170926213129.GA3418@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=federico.vaga@vaga.pv.it \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox