linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
       [not found] ` <CAD=FV=URCo5xv3k3jWbxV1uRkUU5k6bcnuB1puZhxayEyVc6-A@mail.gmail.com>
@ 2022-07-19 10:41   ` Hillf Danton
  2022-07-19 15:30     ` Doug Anderson
  0 siblings, 1 reply; 11+ messages in thread
From: Hillf Danton @ 2022-07-19 10:41 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso,
	linux-mm, LKML

On Mon, 18 Jul 2022 17:27:28 -0700 Doug Anderson <dianders@chromium.org> wrote:
> 
> I've been tracking down an occasional hang at reboot on my system and
> I've ended up at this as the first bad commit. I will not pretend to
> understand the intricacies of the rwsem implementation, but I can
> describe what I saw. I have also produced a fairly small test case
> that reproduces the problem rather quickly.
> 
> First, what I saw:
> 
> My system failed to fully boot up and eventually the "hung task"
> detection kicked in. Many tasks in my system were hung all waiting on
> the "kernfs_rwsem". No tasks actually had the semaphore--it only had
> tasks waiting.
> 
> Of the tasks waiting, 3 of them were doing a down_write(). The rest
> were all waiting on down_read().
> 
> 2 of the tasks waiting on the down_write() were locked to CPU0. One of
> these tasks was a bound kworker. Another of these tasks was a threaded
> IRQ handler. The threaded IRQ handler was set to "real time" priority
> because in setup_irq_thread() you can see the call to
> sched_set_fifo().
> 
> At the time the hung task detector kicked in, the real time task was
> actually active on a CPU. Specifically it was running in the for (;;)
> loop in rwsem_down_write_slowpath(). rwsem_try_write_lock() had
> clearly just returned false which meant we didn't get the lock.
> Everything else was sitting in schedule().
> 
> I managed to get the real time task into kgdb and I could analyze its
> state as well as the state of "sem". The real time task was _not_ the
> first waiter. The kworker was the first waiter. The
> "waiter.handoff_set" was set to "true" for the real time task. The
> rwsem owner was OWNER_NULL.
> 
> Looking through the code and watching what was happening.
> 
> 1. The function rwsem_try_write_lock() was instantly returning false
> since `handoff` is set and we're not first.
> 2. After we get back into rwsem_down_write_slowpath() we'll see the
> handoff set and we'll try to spin on the owner. There is no owner, so
> this is a noop.
> 3. Since there's no owner, we'll go right back to the start of the loop.
> 
> So basically the real time thread (the threaded IRQ handler) was
> locked to CPU0 and spinning as fast as possible. The "first waiter"
> for the semaphore was blocked from running because it could only run
> on CPU0 but was _not_ real time priority.
> 
> -
> 
> So all the analysis above was done on the Chrome OS 5.15 kernel
> branch, which has ${SUBJECT} patch from the stable tree. The code
> looks reasonably the same on mainline.
> 
> ...and also, I coded up a test case that can reproduce this on
> mainline. It's ugly/hacky but it gets the job done. This reproduces
> the problem at the top of mainline as of commit 80e19f34c288 ("Merge
> tag 'hte/for-5.19' of
> git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux").
> 
> For me, I was only able to reproduce this without "lockdep" enabled.
> My lockdep configs were:
> 
> CONFIG_DEBUG_RT_MUTEXES=y
> CONFIG_DEBUG_SPINLOCK=y
> CONFIG_DEBUG_MUTEXES=y
> CONFIG_PROVE_RCU=y
> CONFIG_PROVE_LOCKING=y
> CONFIG_DEBUG_ATOMIC_SLEEP=y
> 
> I don't know for sure if lockdep is actually required to reproduce.
> 
> -
> 
> OK, so here's my hacky test case. In my case, I put a call to this
> test function in a convenient debugfs "show" function to make it easy
> to trigger. You can put it wherever.
> 
> struct test_data {
>         struct rw_semaphore *rwsem;
>         int i;
>         bool should_sleep;
> };
> 
> static int test_thread_fn(void *data)
> {
>         struct test_data *test_data = data;
>         struct rw_semaphore *rwsem = test_data->rwsem;
>         ktime_t start;
> 
>         trace_printk("Starting\n");
>         start = ktime_get();
>         while (ktime_to_ms(ktime_sub(ktime_get(), start)) < 60000) {
>                 trace_printk("About to grab\n");
>                 down_write(rwsem);
>                 trace_printk("Grabbed write %d\n", test_data->i);
>                 schedule();
>                 up_write(rwsem);
>                 trace_printk("Released write %d\n", test_data->i);
>                 if (test_data->should_sleep)
>                         msleep(1);
>         }
>         trace_printk("Done\n");
> 
>         return 0;
> }
> 
> static void test(void)
> {
>         static struct task_struct *t[10];
>         static struct test_data test_data[10];
>         static DECLARE_RWSEM(rwsem);
>         int i;
> 
>         trace_printk("About to create threads\n");
> 
>         for (i = 0; i < ARRAY_SIZE(t); i++) {
>                 test_data[i].rwsem = &rwsem;
>                 test_data[i].i = i;
> 
>                 if (i == ARRAY_SIZE(t) - 1) {
>                         /*
>                          * Last thread will be bound to CPU0 and realtime.
>                          * Have it sleep to give other threads a chance to
>                          * run and contend.
>                          */
>                         test_data[i].should_sleep = true;
>                         t[i] = kthread_create_on_cpu(test_thread_fn,
>                                                      &test_data[i], 0,
>                                                      "test0 FIFO-%u");
>                         sched_set_fifo(t[i]);
>                 } else if (i == ARRAY_SIZE(t) - 2) {
>                         /* 2nd to last thread will be bound to CPU0 */
>                         t[i] = kthread_create_on_cpu(test_thread_fn,
>                                                      &test_data[i], 0,
>                                                      "test0-%u");
>                 } else {
>                         /* All other threads are just normal */
>                         t[i] = kthread_create(test_thread_fn,
>                                               &test_data[i], "test");
>                 }
>                 wake_up_process(t[i]);
>                 msleep(10);
>         }
> }
> 
> -
> 
> With the reproducer above, I was able to:
> 
> 1. Validate that on chromeos-5.15 I could revert ${SUBJECT} patch and
> the problem went away.
> 
> 2. I could go to mainline at exactly the commit hash of ${SUBJECT}
> patch, see the problem, then revert ${SUBJECT} patch and see the
> problem go away.
> 
> Thus I'm fairly confident that the problem is related to ${SUBJECT} patch.
> 
> -
> 
> I'm hoping that someone on this thread can propose a fix. I'm happy to
> test, but I was hoping not to have to become an expert on the rwsem
> implementation to try to figure out the proper fix.
> 

See if it makes sense to only allow the first waiter to spin on owner.

Hillf

--- mainline/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -337,7 +337,7 @@ struct rwsem_waiter {
 	unsigned long timeout;
 
 	/* Writer only, not initialized in reader */
-	bool handoff_set;
+	bool handoff_set, first;
 };
 #define rwsem_first_waiter(sem) \
 	list_first_entry(&sem->wait_list, struct rwsem_waiter, list)
@@ -604,6 +604,7 @@ static inline bool rwsem_try_write_lock(
 
 	lockdep_assert_held(&sem->wait_lock);
 
+	waiter->first = first;
 	count = atomic_long_read(&sem->count);
 	do {
 		bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF);
@@ -1114,6 +1115,7 @@ rwsem_down_write_slowpath(struct rw_sema
 	waiter.type = RWSEM_WAITING_FOR_WRITE;
 	waiter.timeout = jiffies + RWSEM_WAIT_TIMEOUT;
 	waiter.handoff_set = false;
+	waiter.first = false;
 
 	raw_spin_lock_irq(&sem->wait_lock);
 	rwsem_add_waiter(sem, &waiter);
@@ -1158,7 +1160,7 @@ rwsem_down_write_slowpath(struct rw_sema
 		 * In this case, we attempt to acquire the lock again
 		 * without sleeping.
 		 */
-		if (waiter.handoff_set) {
+		if (waiter.handoff_set && waiter.first) {
 			enum owner_state owner_state;
 
 			preempt_disable();


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-07-19 10:41   ` [PATCH v5] locking/rwsem: Make handoff bit handling more consistent Hillf Danton
@ 2022-07-19 15:30     ` Doug Anderson
  2022-07-22 11:55       ` Hillf Danton
  0 siblings, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2022-07-19 15:30 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso,
	Linux Memory Management List, LKML

Hi,

On Tue, Jul 19, 2022 at 3:41 AM Hillf Danton <hdanton@sina.com> wrote:
>
> On Mon, 18 Jul 2022 17:27:28 -0700 Doug Anderson <dianders@chromium.org> wrote:
> >
> > I've been tracking down an occasional hang at reboot on my system and
> > I've ended up at this as the first bad commit. I will not pretend to
> > understand the intricacies of the rwsem implementation, but I can
> > describe what I saw. I have also produced a fairly small test case
> > that reproduces the problem rather quickly.
> >
> > First, what I saw:
> >
> > My system failed to fully boot up and eventually the "hung task"
> > detection kicked in. Many tasks in my system were hung all waiting on
> > the "kernfs_rwsem". No tasks actually had the semaphore--it only had
> > tasks waiting.
> >
> > Of the tasks waiting, 3 of them were doing a down_write(). The rest
> > were all waiting on down_read().
> >
> > 2 of the tasks waiting on the down_write() were locked to CPU0. One of
> > these tasks was a bound kworker. Another of these tasks was a threaded
> > IRQ handler. The threaded IRQ handler was set to "real time" priority
> > because in setup_irq_thread() you can see the call to
> > sched_set_fifo().
> >
> > At the time the hung task detector kicked in, the real time task was
> > actually active on a CPU. Specifically it was running in the for (;;)
> > loop in rwsem_down_write_slowpath(). rwsem_try_write_lock() had
> > clearly just returned false which meant we didn't get the lock.
> > Everything else was sitting in schedule().
> >
> > I managed to get the real time task into kgdb and I could analyze its
> > state as well as the state of "sem". The real time task was _not_ the
> > first waiter. The kworker was the first waiter. The
> > "waiter.handoff_set" was set to "true" for the real time task. The
> > rwsem owner was OWNER_NULL.
> >
> > Looking through the code and watching what was happening.
> >
> > 1. The function rwsem_try_write_lock() was instantly returning false
> > since `handoff` is set and we're not first.
> > 2. After we get back into rwsem_down_write_slowpath() we'll see the
> > handoff set and we'll try to spin on the owner. There is no owner, so
> > this is a noop.
> > 3. Since there's no owner, we'll go right back to the start of the loop.
> >
> > So basically the real time thread (the threaded IRQ handler) was
> > locked to CPU0 and spinning as fast as possible. The "first waiter"
> > for the semaphore was blocked from running because it could only run
> > on CPU0 but was _not_ real time priority.
> >
> > -
> >
> > So all the analysis above was done on the Chrome OS 5.15 kernel
> > branch, which has ${SUBJECT} patch from the stable tree. The code
> > looks reasonably the same on mainline.
> >
> > ...and also, I coded up a test case that can reproduce this on
> > mainline. It's ugly/hacky but it gets the job done. This reproduces
> > the problem at the top of mainline as of commit 80e19f34c288 ("Merge
> > tag 'hte/for-5.19' of
> > git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux").
> >
> > For me, I was only able to reproduce this without "lockdep" enabled.
> > My lockdep configs were:
> >
> > CONFIG_DEBUG_RT_MUTEXES=y
> > CONFIG_DEBUG_SPINLOCK=y
> > CONFIG_DEBUG_MUTEXES=y
> > CONFIG_PROVE_RCU=y
> > CONFIG_PROVE_LOCKING=y
> > CONFIG_DEBUG_ATOMIC_SLEEP=y
> >
> > I don't know for sure if lockdep is actually required to reproduce.
> >
> > -
> >
> > OK, so here's my hacky test case. In my case, I put a call to this
> > test function in a convenient debugfs "show" function to make it easy
> > to trigger. You can put it wherever.
> >
> > struct test_data {
> >         struct rw_semaphore *rwsem;
> >         int i;
> >         bool should_sleep;
> > };
> >
> > static int test_thread_fn(void *data)
> > {
> >         struct test_data *test_data = data;
> >         struct rw_semaphore *rwsem = test_data->rwsem;
> >         ktime_t start;
> >
> >         trace_printk("Starting\n");
> >         start = ktime_get();
> >         while (ktime_to_ms(ktime_sub(ktime_get(), start)) < 60000) {
> >                 trace_printk("About to grab\n");
> >                 down_write(rwsem);
> >                 trace_printk("Grabbed write %d\n", test_data->i);
> >                 schedule();
> >                 up_write(rwsem);
> >                 trace_printk("Released write %d\n", test_data->i);
> >                 if (test_data->should_sleep)
> >                         msleep(1);
> >         }
> >         trace_printk("Done\n");
> >
> >         return 0;
> > }
> >
> > static void test(void)
> > {
> >         static struct task_struct *t[10];
> >         static struct test_data test_data[10];
> >         static DECLARE_RWSEM(rwsem);
> >         int i;
> >
> >         trace_printk("About to create threads\n");
> >
> >         for (i = 0; i < ARRAY_SIZE(t); i++) {
> >                 test_data[i].rwsem = &rwsem;
> >                 test_data[i].i = i;
> >
> >                 if (i == ARRAY_SIZE(t) - 1) {
> >                         /*
> >                          * Last thread will be bound to CPU0 and realtime.
> >                          * Have it sleep to give other threads a chance to
> >                          * run and contend.
> >                          */
> >                         test_data[i].should_sleep = true;
> >                         t[i] = kthread_create_on_cpu(test_thread_fn,
> >                                                      &test_data[i], 0,
> >                                                      "test0 FIFO-%u");
> >                         sched_set_fifo(t[i]);
> >                 } else if (i == ARRAY_SIZE(t) - 2) {
> >                         /* 2nd to last thread will be bound to CPU0 */
> >                         t[i] = kthread_create_on_cpu(test_thread_fn,
> >                                                      &test_data[i], 0,
> >                                                      "test0-%u");
> >                 } else {
> >                         /* All other threads are just normal */
> >                         t[i] = kthread_create(test_thread_fn,
> >                                               &test_data[i], "test");
> >                 }
> >                 wake_up_process(t[i]);
> >                 msleep(10);
> >         }
> > }
> >
> > -
> >
> > With the reproducer above, I was able to:
> >
> > 1. Validate that on chromeos-5.15 I could revert ${SUBJECT} patch and
> > the problem went away.
> >
> > 2. I could go to mainline at exactly the commit hash of ${SUBJECT}
> > patch, see the problem, then revert ${SUBJECT} patch and see the
> > problem go away.
> >
> > Thus I'm fairly confident that the problem is related to ${SUBJECT} patch.
> >
> > -
> >
> > I'm hoping that someone on this thread can propose a fix. I'm happy to
> > test, but I was hoping not to have to become an expert on the rwsem
> > implementation to try to figure out the proper fix.
> >
>
> See if it makes sense to only allow the first waiter to spin on owner.
>
> Hillf
>
> --- mainline/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -337,7 +337,7 @@ struct rwsem_waiter {
>         unsigned long timeout;
>
>         /* Writer only, not initialized in reader */
> -       bool handoff_set;
> +       bool handoff_set, first;
>  };
>  #define rwsem_first_waiter(sem) \
>         list_first_entry(&sem->wait_list, struct rwsem_waiter, list)
> @@ -604,6 +604,7 @@ static inline bool rwsem_try_write_lock(
>
>         lockdep_assert_held(&sem->wait_lock);
>
> +       waiter->first = first;
>         count = atomic_long_read(&sem->count);
>         do {
>                 bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF);
> @@ -1114,6 +1115,7 @@ rwsem_down_write_slowpath(struct rw_sema
>         waiter.type = RWSEM_WAITING_FOR_WRITE;
>         waiter.timeout = jiffies + RWSEM_WAIT_TIMEOUT;
>         waiter.handoff_set = false;
> +       waiter.first = false;
>
>         raw_spin_lock_irq(&sem->wait_lock);
>         rwsem_add_waiter(sem, &waiter);
> @@ -1158,7 +1160,7 @@ rwsem_down_write_slowpath(struct rw_sema
>                  * In this case, we attempt to acquire the lock again
>                  * without sleeping.
>                  */
> -               if (waiter.handoff_set) {
> +               if (waiter.handoff_set && waiter.first) {

Your patch does fix my test case, so FWIW:

Tested-by: Douglas Anderson <dianders@chromium.org>

I haven't done any stress testing other than my test case, though, so
I can't speak to whether there might be any other unintended issues.


-Doug


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-07-19 15:30     ` Doug Anderson
@ 2022-07-22 11:55       ` Hillf Danton
  2022-07-22 14:02         ` Doug Anderson
  0 siblings, 1 reply; 11+ messages in thread
From: Hillf Danton @ 2022-07-22 11:55 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

On Tue, 19 Jul 2022 08:30:02 -0700 Doug Anderson wrote:
> 
> I haven't done any stress testing other than my test case, though, so
> I can't speak to whether there might be any other unintended issues.

The diff below is prepared for any regressions I can imagine in stress
tests by adding changes to both read and write acquirer slow pathes.

On the read side, make lock stealing more aggressive; on the other hand,
write acquirers try to set HANDOFF after a RWSEM_WAIT_TIMEOUT nap to
force the reader acquirers to take the slow path.

Hillf

--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -992,13 +992,7 @@ rwsem_down_read_slowpath(struct rw_semap
 	struct rwsem_waiter waiter;
 	DEFINE_WAKE_Q(wake_q);
 
-	/*
-	 * To prevent a constant stream of readers from starving a sleeping
-	 * waiter, don't attempt optimistic lock stealing if the lock is
-	 * currently owned by readers.
-	 */
-	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
-	    (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))
+	if (WARN_ON_ONCE(count & RWSEM_FLAG_READFAIL))
 		goto queue;
 
 	/*
@@ -1169,7 +1163,11 @@ rwsem_down_write_slowpath(struct rw_sema
 				goto trylock_again;
 		}
 
-		schedule();
+		if (RWSEM_FLAG_HANDOFF & atomic_long_read(&sem->count))
+			schedule();
+		else
+			schedule_timeout(1 + RWSEM_WAIT_TIMEOUT);
+
 		lockevent_inc(rwsem_sleep_writer);
 		set_current_state(state);
 trylock_again:
--


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-07-22 11:55       ` Hillf Danton
@ 2022-07-22 14:02         ` Doug Anderson
  2022-07-23  0:17           ` Hillf Danton
  0 siblings, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2022-07-22 14:02 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

Hi,

On Fri, Jul 22, 2022 at 4:55 AM Hillf Danton <hdanton@sina.com> wrote:
>
> On Tue, 19 Jul 2022 08:30:02 -0700 Doug Anderson wrote:
> >
> > I haven't done any stress testing other than my test case, though, so
> > I can't speak to whether there might be any other unintended issues.
>
> The diff below is prepared for any regressions I can imagine in stress
> tests by adding changes to both read and write acquirer slow pathes.
>
> On the read side, make lock stealing more aggressive; on the other hand,
> write acquirers try to set HANDOFF after a RWSEM_WAIT_TIMEOUT nap to
> force the reader acquirers to take the slow path.
>
> Hillf
>
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -992,13 +992,7 @@ rwsem_down_read_slowpath(struct rw_semap
>         struct rwsem_waiter waiter;
>         DEFINE_WAKE_Q(wake_q);
>
> -       /*
> -        * To prevent a constant stream of readers from starving a sleeping
> -        * waiter, don't attempt optimistic lock stealing if the lock is
> -        * currently owned by readers.
> -        */
> -       if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
> -           (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))
> +       if (WARN_ON_ONCE(count & RWSEM_FLAG_READFAIL))
>                 goto queue;
>
>         /*
> @@ -1169,7 +1163,11 @@ rwsem_down_write_slowpath(struct rw_sema
>                                 goto trylock_again;
>                 }
>
> -               schedule();
> +               if (RWSEM_FLAG_HANDOFF & atomic_long_read(&sem->count))
> +                       schedule();
> +               else
> +                       schedule_timeout(1 + RWSEM_WAIT_TIMEOUT);
> +
>                 lockevent_inc(rwsem_sleep_writer);
>                 set_current_state(state);
>  trylock_again:
> --

Thanks! I added this diff to your previous diff and my simple test
still passes and I don't see your WARN_ON triggered.

How do we move forward? Are you going to officially submit a patch
with both of your diffs squashed together? Are we waiting for
additional review from someone?

-Doug


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-07-22 14:02         ` Doug Anderson
@ 2022-07-23  0:17           ` Hillf Danton
  2022-07-23  1:27             ` Hillf Danton
  2022-08-05 17:14             ` Doug Anderson
  0 siblings, 2 replies; 11+ messages in thread
From: Hillf Danton @ 2022-07-23  0:17 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
> 
> Thanks! I added this diff to your previous diff and my simple test
> still passes and I don't see your WARN_ON triggered.

Thanks!
> 
> How do we move forward? Are you going to officially submit a patch
> with both of your diffs squashed together? Are we waiting for
> additional review from someone?

Given it is not unusual for us to miss anything important, lets take
a RWSEM_WAIT_TIMEOUT nap now or two.

Hillf


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-07-23  0:17           ` Hillf Danton
@ 2022-07-23  1:27             ` Hillf Danton
  2022-08-05 17:14             ` Doug Anderson
  1 sibling, 0 replies; 11+ messages in thread
From: Hillf Danton @ 2022-07-23  1:27 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Doug Anderson, Waiman Long, MM, Peter Zijlstra, Will Deacon,
	Davidlohr Bueso, Dmitry Vyukov, Eric Dumazet, Andrew Morton,
	LKML

On Sat, 23 Jul 2022 08:17:13 +0800 Hillf Danton wrote:
> On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
> > 
> > Thanks! I added this diff to your previous diff and my simple test
> > still passes and I don't see your WARN_ON triggered.
> 
> Thanks!
> > 
> > How do we move forward? Are you going to officially submit a patch
> > with both of your diffs squashed together? Are we waiting for
> > additional review from someone?
> 
> Given it is not unusual for us to miss anything important, lets take
> a RWSEM_WAIT_TIMEOUT nap now or two.

Meanwhile I feel good to, based on what you discovered in rwsem, nominate
Doug Anderson for the 2022 Google OSPB Award, as one of the winners in
2020.

> 
> Hillf


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-07-23  0:17           ` Hillf Danton
  2022-07-23  1:27             ` Hillf Danton
@ 2022-08-05 17:14             ` Doug Anderson
  2022-08-05 19:02               ` Waiman Long
  1 sibling, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2022-08-05 17:14 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

Hi,

On Fri, Jul 22, 2022 at 5:17 PM Hillf Danton <hdanton@sina.com> wrote:
>
> On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
> >
> > Thanks! I added this diff to your previous diff and my simple test
> > still passes and I don't see your WARN_ON triggered.
>
> Thanks!
> >
> > How do we move forward? Are you going to officially submit a patch
> > with both of your diffs squashed together? Are we waiting for
> > additional review from someone?
>
> Given it is not unusual for us to miss anything important, lets take
> a RWSEM_WAIT_TIMEOUT nap now or two.

It appears that another fix has landed in the meantime. Commit
6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to ignore handoff
bit if not set by first waiter").

...unfortunately with that patch my test cases still hangs. :(


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-08-05 17:14             ` Doug Anderson
@ 2022-08-05 19:02               ` Waiman Long
  2022-08-05 19:16                 ` Doug Anderson
  0 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2022-08-05 19:02 UTC (permalink / raw)
  To: Doug Anderson, Hillf Danton
  Cc: Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML


On 8/5/22 13:14, Doug Anderson wrote:
> Hi,
>
> On Fri, Jul 22, 2022 at 5:17 PM Hillf Danton <hdanton@sina.com> wrote:
>> On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
>>> Thanks! I added this diff to your previous diff and my simple test
>>> still passes and I don't see your WARN_ON triggered.
>> Thanks!
>>> How do we move forward? Are you going to officially submit a patch
>>> with both of your diffs squashed together? Are we waiting for
>>> additional review from someone?
>> Given it is not unusual for us to miss anything important, lets take
>> a RWSEM_WAIT_TIMEOUT nap now or two.
> It appears that another fix has landed in the meantime. Commit
> 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to ignore handoff
> bit if not set by first waiter").
>
> ...unfortunately with that patch my test cases still hangs. :(

The aim of commit 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to 
ignore handoff bit if not set by first waiter") is to restore slowpath 
writer behavior to be the same as before commit d257cc8cb8d5 
("locking/rwsem: Make handoff bit handling more consistent").

If the hang still exists, there may be other cause for it. Could you 
share more information about what the test case is doing and any kernel 
splat that you have?

Thanks,
Longman




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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-08-05 19:02               ` Waiman Long
@ 2022-08-05 19:16                 ` Doug Anderson
  2022-08-30 16:18                   ` Doug Anderson
  0 siblings, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2022-08-05 19:16 UTC (permalink / raw)
  To: Waiman Long
  Cc: Hillf Danton, Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

Hi,

On Fri, Aug 5, 2022 at 12:02 PM Waiman Long <longman@redhat.com> wrote:
>
>
> On 8/5/22 13:14, Doug Anderson wrote:
> > Hi,
> >
> > On Fri, Jul 22, 2022 at 5:17 PM Hillf Danton <hdanton@sina.com> wrote:
> >> On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
> >>> Thanks! I added this diff to your previous diff and my simple test
> >>> still passes and I don't see your WARN_ON triggered.
> >> Thanks!
> >>> How do we move forward? Are you going to officially submit a patch
> >>> with both of your diffs squashed together? Are we waiting for
> >>> additional review from someone?
> >> Given it is not unusual for us to miss anything important, lets take
> >> a RWSEM_WAIT_TIMEOUT nap now or two.
> > It appears that another fix has landed in the meantime. Commit
> > 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to ignore handoff
> > bit if not set by first waiter").
> >
> > ...unfortunately with that patch my test cases still hangs. :(
>
> The aim of commit 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to
> ignore handoff bit if not set by first waiter") is to restore slowpath
> writer behavior to be the same as before commit d257cc8cb8d5
> ("locking/rwsem: Make handoff bit handling more consistent").

Ah, OK. I just saw another fix to the same commit and assumed that
perhaps it was intended to address the same issue.


> If the hang still exists, there may be other cause for it. Could you
> share more information about what the test case is doing and any kernel
> splat that you have?

It's all described in my earlier reply including my full test case:

https://lore.kernel.org/r/CAD=FV=URCo5xv3k3jWbxV1uRkUU5k6bcnuB1puZhxayEyVc6-A@mail.gmail.com

Previously I tested Hillf's patches and they fixed it for me.

-Doug


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-08-05 19:16                 ` Doug Anderson
@ 2022-08-30 16:18                   ` Doug Anderson
  2022-08-31 11:08                     ` Hillf Danton
  0 siblings, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2022-08-30 16:18 UTC (permalink / raw)
  To: Waiman Long, Hillf Danton
  Cc: Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

Hi,

On Fri, Aug 5, 2022 at 12:16 PM Doug Anderson <dianders@chromium.org> wrote:
>
> Hi,
>
> On Fri, Aug 5, 2022 at 12:02 PM Waiman Long <longman@redhat.com> wrote:
> >
> >
> > On 8/5/22 13:14, Doug Anderson wrote:
> > > Hi,
> > >
> > > On Fri, Jul 22, 2022 at 5:17 PM Hillf Danton <hdanton@sina.com> wrote:
> > >> On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
> > >>> Thanks! I added this diff to your previous diff and my simple test
> > >>> still passes and I don't see your WARN_ON triggered.
> > >> Thanks!
> > >>> How do we move forward? Are you going to officially submit a patch
> > >>> with both of your diffs squashed together? Are we waiting for
> > >>> additional review from someone?
> > >> Given it is not unusual for us to miss anything important, lets take
> > >> a RWSEM_WAIT_TIMEOUT nap now or two.
> > > It appears that another fix has landed in the meantime. Commit
> > > 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to ignore handoff
> > > bit if not set by first waiter").
> > >
> > > ...unfortunately with that patch my test cases still hangs. :(
> >
> > The aim of commit 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to
> > ignore handoff bit if not set by first waiter") is to restore slowpath
> > writer behavior to be the same as before commit d257cc8cb8d5
> > ("locking/rwsem: Make handoff bit handling more consistent").
>
> Ah, OK. I just saw another fix to the same commit and assumed that
> perhaps it was intended to address the same issue.
>
>
> > If the hang still exists, there may be other cause for it. Could you
> > share more information about what the test case is doing and any kernel
> > splat that you have?
>
> It's all described in my earlier reply including my full test case:
>
> https://lore.kernel.org/r/CAD=FV=URCo5xv3k3jWbxV1uRkUU5k6bcnuB1puZhxayEyVc6-A@mail.gmail.com
>
> Previously I tested Hillf's patches and they fixed it for me.

Hillf: do you have any plan here for your patches?

I spent some time re-testing this today atop mainline, specifically
atop commit dcf8e5633e2e ("tracing: Define the is_signed_type() macro
once"). Some notes:

1. I can confirm that my test case still reproduces a hang on
mainline, though it seems a bit harder to reproduce (sometimes I have
to run for a few minutes). I didn't spend lots of time confirming that
the hang is exactly the same, but the same testcase reproduces it so
it probably is. If it's important I can drop into kgdb and dig around
to confirm.

2. Blindly applying the first (and resolving the trivial merge
conflict) or both of your proposed patches no longer fixes the hang on
mainline.

3. Reverting Waiman's commit 6eebd5fb2083 ("locking/rwsem: Allow
slowpath writer to ignore handoff bit if not set by first waiter") and
then applying your two fixes _does_ still fix the patch on mainline. I
ran for 20 minutes w/ no reproduction.

So it seems like Waiman's recent commit interacts with your fix in a bad way. :(

-Doug







-Doug


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

* Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
  2022-08-30 16:18                   ` Doug Anderson
@ 2022-08-31 11:08                     ` Hillf Danton
  0 siblings, 0 replies; 11+ messages in thread
From: Hillf Danton @ 2022-08-31 11:08 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Waiman Long, Peter Zijlstra, Will Deacon, Davidlohr Bueso, MM, LKML

On Tue, 30 Aug 2022 09:18:09 -0700 Doug Anderson <dianders@chromium.org> wrote:
> On Fri, Aug 5, 2022 at 12:16 PM Doug Anderson <dianders@chromium.org> wrote:
> > On Fri, Aug 5, 2022 at 12:02 PM Waiman Long <longman@redhat.com> wrote:
> > > On 8/5/22 13:14, Doug Anderson wrote:
> > > > Hi,
> > > >
> > > > On Fri, Jul 22, 2022 at 5:17 PM Hillf Danton <hdanton@sina.com> wrote:
> > > >> On Fri, 22 Jul 2022 07:02:42 -0700 Doug Anderson wrote:
> > > >>> Thanks! I added this diff to your previous diff and my simple test
> > > >>> still passes and I don't see your WARN_ON triggered.
> > > >> Thanks!
> > > >>> How do we move forward? Are you going to officially submit a patch
> > > >>> with both of your diffs squashed together? Are we waiting for
> > > >>> additional review from someone?
> > > >> Given it is not unusual for us to miss anything important, lets take
> > > >> a RWSEM_WAIT_TIMEOUT nap now or two.
> > > > It appears that another fix has landed in the meantime. Commit
> > > > 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to ignore handoff
> > > > bit if not set by first waiter").
> > > >
> > > > ...unfortunately with that patch my test cases still hangs. :(
> > >
> > > The aim of commit 6eebd5fb2083 ("locking/rwsem: Allow slowpath writer to
> > > ignore handoff bit if not set by first waiter") is to restore slowpath
> > > writer behavior to be the same as before commit d257cc8cb8d5
> > > ("locking/rwsem: Make handoff bit handling more consistent").
> >
> > Ah, OK. I just saw another fix to the same commit and assumed that
> > perhaps it was intended to address the same issue.
> >
> >
> > > If the hang still exists, there may be other cause for it. Could you
> > > share more information about what the test case is doing and any kernel
> > > splat that you have?
> >
> > It's all described in my earlier reply including my full test case:
> >
> > https://lore.kernel.org/r/CAD=FV=URCo5xv3k3jWbxV1uRkUU5k6bcnuB1puZhxayEyVc6-A@mail.gmail.com
> >
> > Previously I tested Hillf's patches and they fixed it for me.
> 
> Hillf: do you have any plan here for your patches?

It would take more patience to fix the hang, in addition to ticks and
minutes that are always good at fixing, because those in charge of
locking know better and deeper, and always have more issues to fix with
tighter time budget.

The option I can imagine is to wait fix from the locking folks after
putting my $0.02 next to your $2 on the table.

Hillf
> 
> I spent some time re-testing this today atop mainline, specifically
> atop commit dcf8e5633e2e ("tracing: Define the is_signed_type() macro
> once"). Some notes:
> 
> 1. I can confirm that my test case still reproduces a hang on
> mainline, though it seems a bit harder to reproduce (sometimes I have
> to run for a few minutes). I didn't spend lots of time confirming that
> the hang is exactly the same, but the same testcase reproduces it so
> it probably is. If it's important I can drop into kgdb and dig around
> to confirm.
> 
> 2. Blindly applying the first (and resolving the trivial merge
> conflict) or both of your proposed patches no longer fixes the hang on
> mainline.
> 
> 3. Reverting Waiman's commit 6eebd5fb2083 ("locking/rwsem: Allow
> slowpath writer to ignore handoff bit if not set by first waiter") and
> then applying your two fixes _does_ still fix the patch on mainline. I
> ran for 20 minutes w/ no reproduction.
> 
> So it seems like Waiman's recent commit interacts with your fix in a bad way. :(
> 
> -Doug


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

end of thread, other threads:[~2022-08-31 11:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211116012912.723980-1-longman@redhat.com>
     [not found] ` <CAD=FV=URCo5xv3k3jWbxV1uRkUU5k6bcnuB1puZhxayEyVc6-A@mail.gmail.com>
2022-07-19 10:41   ` [PATCH v5] locking/rwsem: Make handoff bit handling more consistent Hillf Danton
2022-07-19 15:30     ` Doug Anderson
2022-07-22 11:55       ` Hillf Danton
2022-07-22 14:02         ` Doug Anderson
2022-07-23  0:17           ` Hillf Danton
2022-07-23  1:27             ` Hillf Danton
2022-08-05 17:14             ` Doug Anderson
2022-08-05 19:02               ` Waiman Long
2022-08-05 19:16                 ` Doug Anderson
2022-08-30 16:18                   ` Doug Anderson
2022-08-31 11:08                     ` Hillf Danton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox