All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: Add an explicit might_sleep() to iput
@ 2020-05-27 14:17 KP Singh
  2020-05-27 19:09 ` Al Viro
  0 siblings, 1 reply; 4+ messages in thread
From: KP Singh @ 2020-05-27 14:17 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, bpf
  Cc: Brendan Jackman, Alexei Starovoitov, Daniel Borkmann,
	Alexander Viro, Christoph Hellwig

From: KP Singh <kpsingh@google.com>

It is currently mentioned in the comments to the function that iput
might sleep when the inode is destroyed. Have it call might_sleep, as
dput already does.

Adding an explicity might_sleep() would help in quickly realizing that
iput is called from a place where sleeping is not allowed when
CONFIG_DEBUG_ATOMIC_SLEEP is enabled as noticed in the dicussion:

  https://lore.kernel.org/bpf/20200527021111.GA197666@google.com/

Signed-off-by: KP Singh <kpsingh@google.com>
Reviewed-by: Brendan Jackman <jackmanb@chromium.org>
---
 fs/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/inode.c b/fs/inode.c
index cc6e701b7e5d..f55e72e76266 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1583,6 +1583,7 @@ static void iput_final(struct inode *inode)
  */
 void iput(struct inode *inode)
 {
+	might_sleep();
 	if (!inode)
 		return;
 	BUG_ON(inode->i_state & I_CLEAR);
-- 
2.27.0.rc0.183.gde8f92d652-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: Add an explicit might_sleep() to iput
  2020-05-27 14:17 [PATCH] fs: Add an explicit might_sleep() to iput KP Singh
@ 2020-05-27 19:09 ` Al Viro
  2020-05-27 19:50   ` KP Singh
  0 siblings, 1 reply; 4+ messages in thread
From: Al Viro @ 2020-05-27 19:09 UTC (permalink / raw)
  To: KP Singh
  Cc: linux-kernel, linux-fsdevel, bpf, Brendan Jackman,
	Alexei Starovoitov, Daniel Borkmann, Christoph Hellwig

On Wed, May 27, 2020 at 04:17:53PM +0200, KP Singh wrote:
> From: KP Singh <kpsingh@google.com>
> 
> It is currently mentioned in the comments to the function that iput
> might sleep when the inode is destroyed. Have it call might_sleep, as
> dput already does.
> 
> Adding an explicity might_sleep() would help in quickly realizing that
> iput is called from a place where sleeping is not allowed when
> CONFIG_DEBUG_ATOMIC_SLEEP is enabled as noticed in the dicussion:

You do realize that there are some cases where iput() *is* guaranteed
to be non-blocking, right?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: Add an explicit might_sleep() to iput
  2020-05-27 19:09 ` Al Viro
@ 2020-05-27 19:50   ` KP Singh
  2020-05-27 20:05     ` Al Viro
  0 siblings, 1 reply; 4+ messages in thread
From: KP Singh @ 2020-05-27 19:50 UTC (permalink / raw)
  To: Al Viro
  Cc: open list, linux-fsdevel, bpf, Brendan Jackman,
	Alexei Starovoitov, Daniel Borkmann, Christoph Hellwig

On Wed, May 27, 2020 at 9:09 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Wed, May 27, 2020 at 04:17:53PM +0200, KP Singh wrote:
> > From: KP Singh <kpsingh@google.com>
> >
> > It is currently mentioned in the comments to the function that iput
> > might sleep when the inode is destroyed. Have it call might_sleep, as
> > dput already does.
> >
> > Adding an explicity might_sleep() would help in quickly realizing that
> > iput is called from a place where sleeping is not allowed when
> > CONFIG_DEBUG_ATOMIC_SLEEP is enabled as noticed in the dicussion:
>
> You do realize that there are some cases where iput() *is* guaranteed
> to be non-blocking, right?

Yes, but the same could be said about dput too right?

Are there any callers that rely on these cases? (e.g. when the caller is
sure that it's not dropping the last reference to the inode).

- KP

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: Add an explicit might_sleep() to iput
  2020-05-27 19:50   ` KP Singh
@ 2020-05-27 20:05     ` Al Viro
  0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2020-05-27 20:05 UTC (permalink / raw)
  To: KP Singh
  Cc: open list, linux-fsdevel, bpf, Brendan Jackman,
	Alexei Starovoitov, Daniel Borkmann, Christoph Hellwig

On Wed, May 27, 2020 at 09:50:46PM +0200, KP Singh wrote:
> On Wed, May 27, 2020 at 9:09 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> >
> > On Wed, May 27, 2020 at 04:17:53PM +0200, KP Singh wrote:
> > > From: KP Singh <kpsingh@google.com>
> > >
> > > It is currently mentioned in the comments to the function that iput
> > > might sleep when the inode is destroyed. Have it call might_sleep, as
> > > dput already does.
> > >
> > > Adding an explicity might_sleep() would help in quickly realizing that
> > > iput is called from a place where sleeping is not allowed when
> > > CONFIG_DEBUG_ATOMIC_SLEEP is enabled as noticed in the dicussion:
> >
> > You do realize that there are some cases where iput() *is* guaranteed
> > to be non-blocking, right?
> 
> Yes, but the same could be said about dput too right?

Theoretically, but note that even there dput(NULL) won't trigger that.

> Are there any callers that rely on these cases? (e.g. when the caller is
> sure that it's not dropping the last reference to the inode).

Not sure - there might be.  Try and see if it gives false positives,
but I would rather have it done in -next circa -rc1, so we could see
what falls out and withdraw that if there turn out to be some.

One thing I definitely want to avoid is a flow of BS patches of
"warning is given, therefore we must do something, this is something,
let's do it" variety.  Right now we have just under 700 callers in
the tree, most of them in individual filesystems; I'm not up to
auditing that pile on the moments notice...

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-27 20:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 14:17 [PATCH] fs: Add an explicit might_sleep() to iput KP Singh
2020-05-27 19:09 ` Al Viro
2020-05-27 19:50   ` KP Singh
2020-05-27 20:05     ` Al Viro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.