From: Michal Hocko <mhocko@kernel.org> To: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: "Intel Graphics Development" <intel-gfx@lists.freedesktop.org>, "DRI Development" <dri-devel@lists.freedesktop.org>, LKML <linux-kernel@vger.kernel.org>, linux-mm@kvack.org, "Andrew Morton" <akpm@linux-foundation.org>, "David Rientjes" <rientjes@google.com>, "Christian König" <christian.koenig@amd.com>, "Jérôme Glisse" <jglisse@redhat.com>, "Daniel Vetter" <daniel.vetter@intel.com>, "Peter Zijlstra" <peterz@infradead.org> Subject: Re: [PATCH 2/4] kernel.h: Add non_block_start/end() Date: Mon, 10 Dec 2018 15:13:37 +0100 [thread overview] Message-ID: <20181210141337.GQ1286@dhcp22.suse.cz> (raw) In-Reply-To: <20181210103641.31259-3-daniel.vetter@ffwll.ch> I do not see any scheduler guys Cced and it would be really great to get their opinion here. On Mon 10-12-18 11:36:39, Daniel Vetter wrote: > In some special cases we must not block, but there's not a > spinlock, preempt-off, irqs-off or similar critical section already > that arms the might_sleep() debug checks. Add a non_block_start/end() > pair to annotate these. > > This will be used in the oom paths of mmu-notifiers, where blocking is > not allowed to make sure there's forward progress. Considering the only alternative would be to abuse preempt_{disable,enable}, and that really has a different semantic, I think this makes some sense. The cotext is preemptible but we do not want notifier to sleep on any locks, WQ etc. > Suggested by Michal Hocko. > > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Michal Hocko <mhocko@suse.com> > Cc: David Rientjes <rientjes@google.com> > Cc: "Christian König" <christian.koenig@amd.com> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > Cc: "Jérôme Glisse" <jglisse@redhat.com> > Cc: linux-mm@kvack.org > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> > --- > include/linux/kernel.h | 10 +++++++++- > include/linux/sched.h | 4 ++++ > kernel/sched/core.c | 6 +++--- > 3 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index d6aac75b51ba..c2cf31515b3d 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -251,7 +251,9 @@ extern int _cond_resched(void); > * might_sleep - annotation for functions that can sleep > * > * this macro will print a stack trace if it is executed in an atomic > - * context (spinlock, irq-handler, ...). > + * context (spinlock, irq-handler, ...). Additional sections where blocking is > + * not allowed can be annotated with non_block_start() and non_block_end() > + * pairs. > * > * This is a useful debugging help to be able to catch problems early and not > * be bitten later when the calling function happens to sleep when it is not > @@ -260,6 +262,10 @@ extern int _cond_resched(void); > # define might_sleep() \ > do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) > # define sched_annotate_sleep() (current->task_state_change = 0) > +# define non_block_start() \ > + do { current->non_block_count++; } while (0) > +# define non_block_end() \ > + do { WARN_ON(current->non_block_count-- == 0); } while (0) > #else > static inline void ___might_sleep(const char *file, int line, > int preempt_offset) { } > @@ -267,6 +273,8 @@ extern int _cond_resched(void); > int preempt_offset) { } > # define might_sleep() do { might_resched(); } while (0) > # define sched_annotate_sleep() do { } while (0) > +# define non_block_start() do { } while (0) > +# define non_block_end() do { } while (0) > #endif > > #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) > diff --git a/include/linux/sched.h b/include/linux/sched.h > index ecffd4e37453..41249dbf8f27 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -916,6 +916,10 @@ struct task_struct { > struct mutex_waiter *blocked_on; > #endif > > +#ifdef CONFIG_DEBUG_ATOMIC_SLEEP > + int non_block_count; > +#endif > + > #ifdef CONFIG_TRACE_IRQFLAGS > unsigned int irq_events; > unsigned long hardirq_enable_ip; > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 6fedf3a98581..969d7a71f30c 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6113,7 +6113,7 @@ void ___might_sleep(const char *file, int line, int preempt_offset) > rcu_sleep_check(); > > if ((preempt_count_equals(preempt_offset) && !irqs_disabled() && > - !is_idle_task(current)) || > + !is_idle_task(current) && !current->non_block_count) || > system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING || > oops_in_progress) > return; > @@ -6129,8 +6129,8 @@ void ___might_sleep(const char *file, int line, int preempt_offset) > "BUG: sleeping function called from invalid context at %s:%d\n", > file, line); > printk(KERN_ERR > - "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", > - in_atomic(), irqs_disabled(), > + "in_atomic(): %d, irqs_disabled(): %d, non_block: %d, pid: %d, name: %s\n", > + in_atomic(), irqs_disabled(), current->non_block_count, > current->pid, current->comm); > > if (task_stack_end_corrupted(current)) > -- > 2.20.0.rc1 > -- Michal Hocko SUSE Labs
WARNING: multiple messages have this Message-ID (diff)
From: Michal Hocko <mhocko@kernel.org> To: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: "Intel Graphics Development" <intel-gfx@lists.freedesktop.org>, "DRI Development" <dri-devel@lists.freedesktop.org>, LKML <linux-kernel@vger.kernel.org>, linux-mm@kvack.org, "Andrew Morton" <akpm@linux-foundation.org>, "David Rientjes" <rientjes@google.com>, "Christian König" <christian.koenig@amd.com>, "Jérôme Glisse" <jglisse@redhat.com>, "Daniel Vetter" <daniel.vetter@intel.com>, "Peter Zijlstra" <peterz@infradead.org> Subject: Re: [PATCH 2/4] kernel.h: Add non_block_start/end() Date: Mon, 10 Dec 2018 15:13:37 +0100 [thread overview] Message-ID: <20181210141337.GQ1286@dhcp22.suse.cz> (raw) In-Reply-To: <20181210103641.31259-3-daniel.vetter@ffwll.ch> I do not see any scheduler guys Cced and it would be really great to get their opinion here. On Mon 10-12-18 11:36:39, Daniel Vetter wrote: > In some special cases we must not block, but there's not a > spinlock, preempt-off, irqs-off or similar critical section already > that arms the might_sleep() debug checks. Add a non_block_start/end() > pair to annotate these. > > This will be used in the oom paths of mmu-notifiers, where blocking is > not allowed to make sure there's forward progress. Considering the only alternative would be to abuse preempt_{disable,enable}, and that really has a different semantic, I think this makes some sense. The cotext is preemptible but we do not want notifier to sleep on any locks, WQ etc. > Suggested by Michal Hocko. > > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Michal Hocko <mhocko@suse.com> > Cc: David Rientjes <rientjes@google.com> > Cc: "Christian K�nig" <christian.koenig@amd.com> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > Cc: "J�r�me Glisse" <jglisse@redhat.com> > Cc: linux-mm@kvack.org > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> > --- > include/linux/kernel.h | 10 +++++++++- > include/linux/sched.h | 4 ++++ > kernel/sched/core.c | 6 +++--- > 3 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index d6aac75b51ba..c2cf31515b3d 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -251,7 +251,9 @@ extern int _cond_resched(void); > * might_sleep - annotation for functions that can sleep > * > * this macro will print a stack trace if it is executed in an atomic > - * context (spinlock, irq-handler, ...). > + * context (spinlock, irq-handler, ...). Additional sections where blocking is > + * not allowed can be annotated with non_block_start() and non_block_end() > + * pairs. > * > * This is a useful debugging help to be able to catch problems early and not > * be bitten later when the calling function happens to sleep when it is not > @@ -260,6 +262,10 @@ extern int _cond_resched(void); > # define might_sleep() \ > do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) > # define sched_annotate_sleep() (current->task_state_change = 0) > +# define non_block_start() \ > + do { current->non_block_count++; } while (0) > +# define non_block_end() \ > + do { WARN_ON(current->non_block_count-- == 0); } while (0) > #else > static inline void ___might_sleep(const char *file, int line, > int preempt_offset) { } > @@ -267,6 +273,8 @@ extern int _cond_resched(void); > int preempt_offset) { } > # define might_sleep() do { might_resched(); } while (0) > # define sched_annotate_sleep() do { } while (0) > +# define non_block_start() do { } while (0) > +# define non_block_end() do { } while (0) > #endif > > #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) > diff --git a/include/linux/sched.h b/include/linux/sched.h > index ecffd4e37453..41249dbf8f27 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -916,6 +916,10 @@ struct task_struct { > struct mutex_waiter *blocked_on; > #endif > > +#ifdef CONFIG_DEBUG_ATOMIC_SLEEP > + int non_block_count; > +#endif > + > #ifdef CONFIG_TRACE_IRQFLAGS > unsigned int irq_events; > unsigned long hardirq_enable_ip; > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 6fedf3a98581..969d7a71f30c 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6113,7 +6113,7 @@ void ___might_sleep(const char *file, int line, int preempt_offset) > rcu_sleep_check(); > > if ((preempt_count_equals(preempt_offset) && !irqs_disabled() && > - !is_idle_task(current)) || > + !is_idle_task(current) && !current->non_block_count) || > system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING || > oops_in_progress) > return; > @@ -6129,8 +6129,8 @@ void ___might_sleep(const char *file, int line, int preempt_offset) > "BUG: sleeping function called from invalid context at %s:%d\n", > file, line); > printk(KERN_ERR > - "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", > - in_atomic(), irqs_disabled(), > + "in_atomic(): %d, irqs_disabled(): %d, non_block: %d, pid: %d, name: %s\n", > + in_atomic(), irqs_disabled(), current->non_block_count, > current->pid, current->comm); > > if (task_stack_end_corrupted(current)) > -- > 2.20.0.rc1 > -- Michal Hocko SUSE Labs
next prev parent reply other threads:[~2018-12-10 14:13 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-10 10:36 [PATCH 0/4] mmu notifier debug checks v2 Daniel Vetter 2018-12-10 10:36 ` [PATCH 1/4] mm: Check if mmu notifier callbacks are allowed to fail Daniel Vetter 2018-12-10 10:36 ` Daniel Vetter 2018-12-10 10:44 ` Koenig, Christian 2018-12-10 10:44 ` Koenig, Christian 2018-12-10 13:27 ` Michal Hocko 2018-12-10 13:27 ` Michal Hocko 2018-12-10 10:36 ` [PATCH 2/4] kernel.h: Add non_block_start/end() Daniel Vetter 2018-12-10 10:36 ` Daniel Vetter 2018-12-10 14:13 ` Michal Hocko [this message] 2018-12-10 14:13 ` Michal Hocko 2018-12-10 14:47 ` Peter Zijlstra 2018-12-10 14:47 ` Peter Zijlstra 2018-12-10 15:01 ` Michal Hocko 2018-12-10 15:22 ` Peter Zijlstra 2018-12-10 16:20 ` Michal Hocko 2018-12-10 16:30 ` Peter Zijlstra 2018-12-10 16:30 ` Peter Zijlstra 2018-12-12 10:26 ` Daniel Vetter 2018-12-12 10:26 ` Daniel Vetter 2018-12-10 10:36 ` [PATCH 3/4] mm, notifier: Catch sleeping/blocking for !blockable Daniel Vetter 2018-12-10 10:36 ` [PATCH 4/4] mm, notifier: Add a lockdep map for invalidate_range_start Daniel Vetter 2018-12-10 12:07 ` ✗ Fi.CI.CHECKPATCH: warning for mmu notifier debug checks v2 Patchwork 2018-12-10 12:28 ` ✓ Fi.CI.BAT: success " Patchwork 2018-12-10 15:54 ` ✗ Fi.CI.IGT: failure " Patchwork 2018-12-10 16:47 ` ✗ Fi.CI.BAT: failure for mmu notifier debug checks v2 (rev2) Patchwork 2019-05-20 21:39 [PATCH 1/4] mm: Check if mmu notifier callbacks are allowed to fail Daniel Vetter 2019-05-20 21:39 ` [PATCH 2/4] kernel.h: Add non_block_start/end() Daniel Vetter 2019-05-20 21:39 ` Daniel Vetter
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=20181210141337.GQ1286@dhcp22.suse.cz \ --to=mhocko@kernel.org \ --cc=akpm@linux-foundation.org \ --cc=christian.koenig@amd.com \ --cc=daniel.vetter@ffwll.ch \ --cc=daniel.vetter@intel.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ --cc=jglisse@redhat.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=peterz@infradead.org \ --cc=rientjes@google.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.