linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] Lock warning cleanup
       [not found] <0/11>
@ 2020-02-09 22:24 ` Jules Irenge
  2020-02-09 22:44   ` [PATCH 07/11] fs_pin: Add missing annotation for pin_kill() declaration Jules Irenge
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jules Irenge @ 2020-02-09 22:24 UTC (permalink / raw)
  To: boqun.feng
  Cc: linux-kernel, linux-mm, kasan-dev, akpm, dvyukov, glider,
	aryabinin, bsegall, rostedt, dietmar.eggemann, vincent.guittot,
	juri.lelli, peterz, mingo, mgorman, dvhart, tglx, namhyung,
	jolsa, alexander.shishkin, mark.rutland, acme, viro,
	linux-fsdevel, Jules Irenge

This patch series adds missing annotations to functions that register warnings of context imbalance when built with Sparse tool.
The adds fix the warnings and give insight on what the functions are actually doing.

1. Within the futex subsystem, a __releases(&pi_state->.pi_mutex.wait_lock) is added because wake_futex_pi() only releases the lock at exit,
must_hold(q->lock_ptr) have been added to fixup_pi_state_owner() because the lock is held at entry and exit;
a __releases(&hb->lock) added to futex_wait_queue_me() as it only releases the lock.

2. Within fs_pin, a __releases(RCU) is added because the function exit RCU critical section at exit.

3. In kasan, an __acquires(&report_lock) has been added to start_report() and   __releases(&report_lock) to end_report() 

4. Within ring_buffer subsystem, a __releases(RCU) has been added perf_output_end() 

5. schedule subsystem recorded an addition of the __releases(rq->lock) annotation and a __must_hold(this_rq->lock)

6. At hrtimer subsystem, __acquires(timer) is added  to lock_hrtimer_base() as the function acquire the lock but never releases it.
Jules Irenge (11):
  hrtimer: Add missing annotation to lock_hrtimer_base()
  futex: Add missing annotation for wake_futex_pi()
  futex: Add missing annotation for fixup_pi_state_owner()
  perf/ring_buffer: Add missing annotation to perf_output_end()
  sched/fair: Add missing annotation for nohz_newidle_balance()
  sched/deadline: Add missing annotation for dl_task_offline_migration()
  fs_pin: Add missing annotation for pin_kill() declaration
  fs_pin: Add missing annotation for pin_kill() definition
  kasan: add missing annotation for start_report()
  kasan: add missing annotation for end_report()
  futex: Add missing annotation for futex_wait_queue_me()

 fs/fs_pin.c                 | 2 +-
 include/linux/fs_pin.h      | 2 +-
 kernel/events/ring_buffer.c | 2 +-
 kernel/futex.c              | 3 +++
 kernel/sched/deadline.c     | 1 +
 kernel/sched/fair.c         | 2 +-
 kernel/time/hrtimer.c       | 1 +
 mm/kasan/report.c           | 4 ++--
 8 files changed, 11 insertions(+), 6 deletions(-)

-- 
2.24.1


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

* [PATCH 07/11] fs_pin: Add missing annotation for pin_kill() declaration
  2020-02-09 22:24 ` [PATCH 00/11] Lock warning cleanup Jules Irenge
@ 2020-02-09 22:44   ` Jules Irenge
  2020-02-09 22:45   ` [PATCH 08/11] fs_pin: Add missing annotation for pin_kill() definition Jules Irenge
  2020-02-10  5:06   ` [PATCH 00/11] Lock warning cleanup Boqun Feng
  2 siblings, 0 replies; 5+ messages in thread
From: Jules Irenge @ 2020-02-09 22:44 UTC (permalink / raw)
  To: boqun.feng; +Cc: linux-fsdevel, viro, linux-kernel, Jules Irenge

Sparse reports warnings within the kernel acct.c file
at acct_exit_ns(), __se_sys_acct(), acct_on()

warning: context imbalance in acct_on()
	- different lock contexts for basic block
warning: context imbalance in __se_sys_acct()
	- different lock contexts for basic block
warning: context imbalance in acct_exit_ns()
	- wrong count at exit

The root cause is the missing annotation at pin_kill()

In fact acct_exit_ns(), __se_sys_sys_acct() and acct_on()
 do actually call rcu_read_lock()
then call pin_kill() which is defined elsewhere.
A close look at pin_kill()
- called 3 times in the core kernel and 2 times elsewhere-
shows that pin_kill() does actually call rcu_read_unlock().
Adding the annotation at declaration and definition of pin_kill()
not only fixes the warnings
but also improves on the readability of the code

Add the missing annotation __release(RCU)

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
 include/linux/fs_pin.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/fs_pin.h b/include/linux/fs_pin.h
index bdd09fd2520c..d2fcf1a5112f 100644
--- a/include/linux/fs_pin.h
+++ b/include/linux/fs_pin.h
@@ -21,4 +21,4 @@ static inline void init_fs_pin(struct fs_pin *p, void (*kill)(struct fs_pin *))
 
 void pin_remove(struct fs_pin *);
 void pin_insert(struct fs_pin *, struct vfsmount *);
-void pin_kill(struct fs_pin *);
+void pin_kill(struct fs_pin *) __releases(RCU);
-- 
2.24.1


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

* [PATCH 08/11] fs_pin: Add missing annotation for pin_kill() definition
  2020-02-09 22:24 ` [PATCH 00/11] Lock warning cleanup Jules Irenge
  2020-02-09 22:44   ` [PATCH 07/11] fs_pin: Add missing annotation for pin_kill() declaration Jules Irenge
@ 2020-02-09 22:45   ` Jules Irenge
  2020-02-10  5:06   ` [PATCH 00/11] Lock warning cleanup Boqun Feng
  2 siblings, 0 replies; 5+ messages in thread
From: Jules Irenge @ 2020-02-09 22:45 UTC (permalink / raw)
  To: boqun.feng; +Cc: linux-fsdevel, viro, linux-kernel, Jules Irenge

Sparse reports a warning at pin_kill()
warning: context imbalance in pin_kil() - unexpected unlock

The root cause is a missing annotation for pin_kill()

Add the missing annotation __releases(RCU)

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
 fs/fs_pin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fs_pin.c b/fs/fs_pin.c
index 47ef3c71ce90..972168453fba 100644
--- a/fs/fs_pin.c
+++ b/fs/fs_pin.c
@@ -27,7 +27,7 @@ void pin_insert(struct fs_pin *pin, struct vfsmount *m)
 	spin_unlock(&pin_lock);
 }
 
-void pin_kill(struct fs_pin *p)
+void pin_kill(struct fs_pin *p) __releases(RCU)
 {
 	wait_queue_entry_t wait;
 
-- 
2.24.1


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

* Re: [PATCH 00/11] Lock warning cleanup
  2020-02-09 22:24 ` [PATCH 00/11] Lock warning cleanup Jules Irenge
  2020-02-09 22:44   ` [PATCH 07/11] fs_pin: Add missing annotation for pin_kill() declaration Jules Irenge
  2020-02-09 22:45   ` [PATCH 08/11] fs_pin: Add missing annotation for pin_kill() definition Jules Irenge
@ 2020-02-10  5:06   ` Boqun Feng
  2020-02-10 23:09     ` Jules Irenge
  2 siblings, 1 reply; 5+ messages in thread
From: Boqun Feng @ 2020-02-10  5:06 UTC (permalink / raw)
  To: Jules Irenge
  Cc: linux-kernel, linux-mm, kasan-dev, akpm, dvyukov, glider,
	aryabinin, bsegall, rostedt, dietmar.eggemann, vincent.guittot,
	juri.lelli, peterz, mingo, mgorman, dvhart, tglx, namhyung,
	jolsa, alexander.shishkin, mark.rutland, acme, viro,
	linux-fsdevel

Hi Jules,

On Sun, Feb 09, 2020 at 10:24:42PM +0000, Jules Irenge wrote:
> This patch series adds missing annotations to functions that register warnings of context imbalance when built with Sparse tool.
> The adds fix the warnings and give insight on what the functions are actually doing.
> 
> 1. Within the futex subsystem, a __releases(&pi_state->.pi_mutex.wait_lock) is added because wake_futex_pi() only releases the lock at exit,
> must_hold(q->lock_ptr) have been added to fixup_pi_state_owner() because the lock is held at entry and exit;
> a __releases(&hb->lock) added to futex_wait_queue_me() as it only releases the lock.
> 
> 2. Within fs_pin, a __releases(RCU) is added because the function exit RCU critical section at exit.
> 
> 3. In kasan, an __acquires(&report_lock) has been added to start_report() and   __releases(&report_lock) to end_report() 
> 
> 4. Within ring_buffer subsystem, a __releases(RCU) has been added perf_output_end() 
> 
> 5. schedule subsystem recorded an addition of the __releases(rq->lock) annotation and a __must_hold(this_rq->lock)
> 
> 6. At hrtimer subsystem, __acquires(timer) is added  to lock_hrtimer_base() as the function acquire the lock but never releases it.
> Jules Irenge (11):
>   hrtimer: Add missing annotation to lock_hrtimer_base()
>   futex: Add missing annotation for wake_futex_pi()
>   futex: Add missing annotation for fixup_pi_state_owner()

Given that those three patches have been sent and reviewed, please do
increase the version number (this time, for example, using v2) when
sending the updated ones. Also please add a few sentences after the
commit log describing what you have changed between versions.

Here is an example:

	https://lore.kernel.org/lkml/20200124231834.63628-4-pmalani@chromium.org/

Regards,
Boqun

>   perf/ring_buffer: Add missing annotation to perf_output_end()
>   sched/fair: Add missing annotation for nohz_newidle_balance()
>   sched/deadline: Add missing annotation for dl_task_offline_migration()
>   fs_pin: Add missing annotation for pin_kill() declaration
>   fs_pin: Add missing annotation for pin_kill() definition
>   kasan: add missing annotation for start_report()
>   kasan: add missing annotation for end_report()
>   futex: Add missing annotation for futex_wait_queue_me()
> 
>  fs/fs_pin.c                 | 2 +-
>  include/linux/fs_pin.h      | 2 +-
>  kernel/events/ring_buffer.c | 2 +-
>  kernel/futex.c              | 3 +++
>  kernel/sched/deadline.c     | 1 +
>  kernel/sched/fair.c         | 2 +-
>  kernel/time/hrtimer.c       | 1 +
>  mm/kasan/report.c           | 4 ++--
>  8 files changed, 11 insertions(+), 6 deletions(-)
> 
> -- 
> 2.24.1
> 

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

* Re: [PATCH 00/11] Lock warning cleanup
  2020-02-10  5:06   ` [PATCH 00/11] Lock warning cleanup Boqun Feng
@ 2020-02-10 23:09     ` Jules Irenge
  0 siblings, 0 replies; 5+ messages in thread
From: Jules Irenge @ 2020-02-10 23:09 UTC (permalink / raw)
  To: Boqun Feng
  Cc: Jules Irenge, linux-kernel, linux-mm, kasan-dev, akpm, dvyukov,
	glider, aryabinin, bsegall, rostedt, dietmar.eggemann,
	vincent.guittot, juri.lelli, peterz, mingo, mgorman, dvhart,
	tglx, namhyung, jolsa, alexander.shishkin, mark.rutland, acme,
	viro, linux-fsdevel



On Mon, 10 Feb 2020, Boqun Feng wrote:

> Hi Jules,
> 
> On Sun, Feb 09, 2020 at 10:24:42PM +0000, Jules Irenge wrote:
> > This patch series adds missing annotations to functions that register warnings of context imbalance when built with Sparse tool.
> > The adds fix the warnings and give insight on what the functions are actually doing.
> > 
> > 1. Within the futex subsystem, a __releases(&pi_state->.pi_mutex.wait_lock) is added because wake_futex_pi() only releases the lock at exit,
> > must_hold(q->lock_ptr) have been added to fixup_pi_state_owner() because the lock is held at entry and exit;
> > a __releases(&hb->lock) added to futex_wait_queue_me() as it only releases the lock.
> > 
> > 2. Within fs_pin, a __releases(RCU) is added because the function exit RCU critical section at exit.
> > 
> > 3. In kasan, an __acquires(&report_lock) has been added to start_report() and   __releases(&report_lock) to end_report() 
> > 
> > 4. Within ring_buffer subsystem, a __releases(RCU) has been added perf_output_end() 
> > 
> > 5. schedule subsystem recorded an addition of the __releases(rq->lock) annotation and a __must_hold(this_rq->lock)
> > 
> > 6. At hrtimer subsystem, __acquires(timer) is added  to lock_hrtimer_base() as the function acquire the lock but never releases it.
> > Jules Irenge (11):
> >   hrtimer: Add missing annotation to lock_hrtimer_base()
> >   futex: Add missing annotation for wake_futex_pi()
> >   futex: Add missing annotation for fixup_pi_state_owner()
> 
> Given that those three patches have been sent and reviewed, please do
> increase the version number (this time, for example, using v2) when
> sending the updated ones. Also please add a few sentences after the
> commit log describing what you have changed between versions.
> 
> Here is an example:
> 
> 	https://lore.kernel.org/lkml/20200124231834.63628-4-pmalani@chromium.org/
> 
> Regards,
> Boqun
> 
> >   perf/ring_buffer: Add missing annotation to perf_output_end()
> >   sched/fair: Add missing annotation for nohz_newidle_balance()
> >   sched/deadline: Add missing annotation for dl_task_offline_migration()
> >   fs_pin: Add missing annotation for pin_kill() declaration
> >   fs_pin: Add missing annotation for pin_kill() definition
> >   kasan: add missing annotation for start_report()
> >   kasan: add missing annotation for end_report()
> >   futex: Add missing annotation for futex_wait_queue_me()
> > 
> >  fs/fs_pin.c                 | 2 +-
> >  include/linux/fs_pin.h      | 2 +-
> >  kernel/events/ring_buffer.c | 2 +-
> >  kernel/futex.c              | 3 +++
> >  kernel/sched/deadline.c     | 1 +
> >  kernel/sched/fair.c         | 2 +-
> >  kernel/time/hrtimer.c       | 1 +
> >  mm/kasan/report.c           | 4 ++--
> >  8 files changed, 11 insertions(+), 6 deletions(-)
> > 
> > -- 
> > 2.24.1
> > 
> 

Thanks for the feedback, I take good notes. I am working on the 
second version.

Kind regards,
Jules

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

end of thread, other threads:[~2020-02-10 23:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <0/11>
2020-02-09 22:24 ` [PATCH 00/11] Lock warning cleanup Jules Irenge
2020-02-09 22:44   ` [PATCH 07/11] fs_pin: Add missing annotation for pin_kill() declaration Jules Irenge
2020-02-09 22:45   ` [PATCH 08/11] fs_pin: Add missing annotation for pin_kill() definition Jules Irenge
2020-02-10  5:06   ` [PATCH 00/11] Lock warning cleanup Boqun Feng
2020-02-10 23:09     ` Jules Irenge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).