@@ -68,6 +68,7 @@ struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state);
6868DEFINE_PER_CPU (struct rcu_data , rcu_preempt_data );
6969static struct rcu_state * rcu_state = & rcu_preempt_state ;
7070
71+ static void rcu_read_unlock_special (struct task_struct * t );
7172static int rcu_preempted_readers_exp (struct rcu_node * rnp );
7273
7374/*
@@ -147,7 +148,7 @@ static void rcu_preempt_note_context_switch(int cpu)
147148 struct rcu_data * rdp ;
148149 struct rcu_node * rnp ;
149150
150- if (t -> rcu_read_lock_nesting &&
151+ if (t -> rcu_read_lock_nesting > 0 &&
151152 (t -> rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED ) == 0 ) {
152153
153154 /* Possibly blocking in an RCU read-side critical section. */
@@ -190,6 +191,14 @@ static void rcu_preempt_note_context_switch(int cpu)
190191 rnp -> gp_tasks = & t -> rcu_node_entry ;
191192 }
192193 raw_spin_unlock_irqrestore (& rnp -> lock , flags );
194+ } else if (t -> rcu_read_lock_nesting < 0 &&
195+ t -> rcu_read_unlock_special ) {
196+
197+ /*
198+ * Complete exit from RCU read-side critical section on
199+ * behalf of preempted instance of __rcu_read_unlock().
200+ */
201+ rcu_read_unlock_special (t );
193202 }
194203
195204 /*
@@ -284,7 +293,7 @@ static struct list_head *rcu_next_node_entry(struct task_struct *t,
284293 * notify RCU core processing or task having blocked during the RCU
285294 * read-side critical section.
286295 */
287- static void rcu_read_unlock_special (struct task_struct * t )
296+ static noinline void rcu_read_unlock_special (struct task_struct * t )
288297{
289298 int empty ;
290299 int empty_exp ;
@@ -309,7 +318,7 @@ static void rcu_read_unlock_special(struct task_struct *t)
309318 }
310319
311320 /* Hardware IRQ handlers cannot block. */
312- if (in_irq ()) {
321+ if (in_irq () || in_serving_softirq () ) {
313322 local_irq_restore (flags );
314323 return ;
315324 }
@@ -342,6 +351,11 @@ static void rcu_read_unlock_special(struct task_struct *t)
342351#ifdef CONFIG_RCU_BOOST
343352 if (& t -> rcu_node_entry == rnp -> boost_tasks )
344353 rnp -> boost_tasks = np ;
354+ /* Snapshot and clear ->rcu_boosted with rcu_node lock held. */
355+ if (t -> rcu_boosted ) {
356+ special |= RCU_READ_UNLOCK_BOOSTED ;
357+ t -> rcu_boosted = 0 ;
358+ }
345359#endif /* #ifdef CONFIG_RCU_BOOST */
346360 t -> rcu_blocked_node = NULL ;
347361
@@ -358,7 +372,6 @@ static void rcu_read_unlock_special(struct task_struct *t)
358372#ifdef CONFIG_RCU_BOOST
359373 /* Unboost if we were boosted. */
360374 if (special & RCU_READ_UNLOCK_BOOSTED ) {
361- t -> rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BOOSTED ;
362375 rt_mutex_unlock (t -> rcu_boost_mutex );
363376 t -> rcu_boost_mutex = NULL ;
364377 }
@@ -387,13 +400,22 @@ void __rcu_read_unlock(void)
387400 struct task_struct * t = current ;
388401
389402 barrier (); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
390- -- t -> rcu_read_lock_nesting ;
391- barrier (); /* decrement before load of ->rcu_read_unlock_special */
392- if (t -> rcu_read_lock_nesting == 0 &&
393- unlikely (ACCESS_ONCE (t -> rcu_read_unlock_special )))
394- rcu_read_unlock_special (t );
403+ if (t -> rcu_read_lock_nesting != 1 )
404+ -- t -> rcu_read_lock_nesting ;
405+ else {
406+ t -> rcu_read_lock_nesting = INT_MIN ;
407+ barrier (); /* assign before ->rcu_read_unlock_special load */
408+ if (unlikely (ACCESS_ONCE (t -> rcu_read_unlock_special )))
409+ rcu_read_unlock_special (t );
410+ barrier (); /* ->rcu_read_unlock_special load before assign */
411+ t -> rcu_read_lock_nesting = 0 ;
412+ }
395413#ifdef CONFIG_PROVE_LOCKING
396- WARN_ON_ONCE (ACCESS_ONCE (t -> rcu_read_lock_nesting ) < 0 );
414+ {
415+ int rrln = ACCESS_ONCE (t -> rcu_read_lock_nesting );
416+
417+ WARN_ON_ONCE (rrln < 0 && rrln > INT_MIN / 2 );
418+ }
397419#endif /* #ifdef CONFIG_PROVE_LOCKING */
398420}
399421EXPORT_SYMBOL_GPL (__rcu_read_unlock );
@@ -589,7 +611,8 @@ static void rcu_preempt_check_callbacks(int cpu)
589611 rcu_preempt_qs (cpu );
590612 return ;
591613 }
592- if (per_cpu (rcu_preempt_data , cpu ).qs_pending )
614+ if (t -> rcu_read_lock_nesting > 0 &&
615+ per_cpu (rcu_preempt_data , cpu ).qs_pending )
593616 t -> rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS ;
594617}
595618
@@ -695,9 +718,12 @@ static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp)
695718
696719 raw_spin_lock_irqsave (& rnp -> lock , flags );
697720 for (;;) {
698- if (!sync_rcu_preempt_exp_done (rnp ))
721+ if (!sync_rcu_preempt_exp_done (rnp )) {
722+ raw_spin_unlock_irqrestore (& rnp -> lock , flags );
699723 break ;
724+ }
700725 if (rnp -> parent == NULL ) {
726+ raw_spin_unlock_irqrestore (& rnp -> lock , flags );
701727 wake_up (& sync_rcu_preempt_exp_wq );
702728 break ;
703729 }
@@ -707,7 +733,6 @@ static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp)
707733 raw_spin_lock (& rnp -> lock ); /* irqs already disabled */
708734 rnp -> expmask &= ~mask ;
709735 }
710- raw_spin_unlock_irqrestore (& rnp -> lock , flags );
711736}
712737
713738/*
@@ -1174,7 +1199,7 @@ static int rcu_boost(struct rcu_node *rnp)
11741199 t = container_of (tb , struct task_struct , rcu_node_entry );
11751200 rt_mutex_init_proxy_locked (& mtx , t );
11761201 t -> rcu_boost_mutex = & mtx ;
1177- t -> rcu_read_unlock_special |= RCU_READ_UNLOCK_BOOSTED ;
1202+ t -> rcu_boosted = 1 ;
11781203 raw_spin_unlock_irqrestore (& rnp -> lock , flags );
11791204 rt_mutex_lock (& mtx ); /* Side effect: boosts task t's priority. */
11801205 rt_mutex_unlock (& mtx ); /* Keep lockdep happy. */
0 commit comments