x86/entry: Tiny idtentry_exit_cond_resched() cleanup
Subsystems (2)
cover x86/entry: Tiny idtentry_exit_cond_resched() cleanup
Tiny two patch series against idtentry_exit_cond_resched() after I noticed it.
Sebastian
PATCH 1/2 x86/entry: Use should_resched() in idtentry_exit_cond_resched()
The TIF_NEED_RESCHED bit is inlined on x86 into the preemption counter. So instead checking the preemption counter against zero via preempt_count() and later checking the TIF_NEED_RESCHED bit via need_resched() we could use should_resched() which does both checks in one go.
The functional difference is that we don't enter the if statement with preempt_count == 0 and TIF_NEED_RESCHED not set.
Use should_resched() instead need_resched() + preempt_count().
--- arch/x86/entry/common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/entry/common.c +2 -3
@@ -612,13 +612,12 @@ bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs)static void idtentry_exit_cond_resched (struct pt_regs *regs,bool may_sched) { -if (may_sched && !preempt_count ()) { +if (may_sched &&should_resched (0 )) {/* Sanity check RCU and thread stack */ rcu_irq_exit_check_preempt ();if (IS_ENABLED (CONFIG_DEBUG_ENTRY ))WARN_ON_ONCE (!on_thread_stack ()); -if (need_resched ()) -preempt_schedule_irq (); +preempt_schedule_irq (); }/* Covers both tracing and lockdep */ trace_hardirqs_on ();
Signature · 1 line
2.27.0
Re: [PATCH 1/2] x86/entry: Use should_resched() in idtentry_exit_cond_resched()
Quoted 20 lines · Sebastian Andrzej Siewior
The
TIF_NEED_RESCHEDbit is inlined on x86 into the preemption counter. So instead checking the preemption counter against zero viapreempt_count()and later checking theTIF_NEED_RESCHEDbit vianeed_resched()we could useshould_resched()which does both checks in one go.
The functional difference is that we don't enter the if statement withpreempt_count== 0 andTIF_NEED_RESCHEDnot set.Use
should_resched()insteadneed_resched()+preempt_count().Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- arch/x86/entry/common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)arch/x86/entry/common.c +0
-0
arch/x86/entry/common.c bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs) · line 619
Quoted 9 lines
arch/x86/entry/common.c +1
-1@@ -612,13 +612,12 @@ bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs)static void idtentry_exit_cond_resched (struct pt_regs *regs,bool may_sched) { -if (may_sched && !preempt_count ()) { +if (may_sched &&should_resched (0 )) {/* Sanity check RCU and thread stack */ rcu_irq_exit_check_preempt ();if (IS_ENABLED (CONFIG_DEBUG_ENTRY ))WARN_ON_ONCE (!on_thread_stack ());
This was done on purpose, your change avoids hitting this WARN.
The thing is, if we could preempt (but not nessecarily have to) we want to validate we're on the thread stack.
Quoted 9 lines
arch/x86/entry/common.c +1
-2-if (need_resched ()) -preempt_schedule_irq (); +preempt_schedule_irq (); }/* Covers both tracing and lockdep */ trace_hardirqs_on ();Signature · 1 line
2.27.0
Re: [PATCH 1/2] x86/entry: Use should_resched() in idtentry_exit_cond_resched()
Quoted 15 lines · Peter Zijlstra
arch/x86/entry/common.c bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs) · line 619
Quoted 12 lines
arch/x86/entry/common.c +1
-1@@ -612,13 +612,12 @@ bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs)static void idtentry_exit_cond_resched (struct pt_regs *regs,bool may_sched) { -if (may_sched && !preempt_count ()) { +if (may_sched &&should_resched (0 )) {/* Sanity check RCU and thread stack */ rcu_irq_exit_check_preempt ();if (IS_ENABLED (CONFIG_DEBUG_ENTRY ))WARN_ON_ONCE (!on_thread_stack ());This was done on purpose, your change avoids hitting this WARN.
Quoted 2 lines
The thing is, if we could preempt (but not nessecarily have to) we want to validate we're on the thread stack.
Okay then.
Sebastian
PATCH v2 1/1 x86/entry: Use should_resched() in idtentry_exit_cond_resched()
The TIF_NEED_RESCHED bit is inlined on x86 into the preemption counter. By using should_resched(0) instead of need_resched() the same check can be performed which uses the same variable as 'preempt_count()` which was issued before.
Use should_resched(0) instead need_resched().
---
v1…v2: Use should_resched() but keep the !preempt_count() check.
arch/x86/entry/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/entry/common.c +1 -1
@@ -615,11 +615,11 @@ static void idtentry_exit_cond_resched(struct pt_regs *regs, bool may_sched)if (may_sched && !preempt_count ()) {/* Sanity check RCU and thread stack */ rcu_irq_exit_check_preempt ();if (IS_ENABLED (CONFIG_DEBUG_ENTRY ))WARN_ON_ONCE (!on_thread_stack ()); -if (need_resched ()) +if (should_resched (0 ))preempt_schedule_irq (); }/* Covers both tracing and lockdep */ trace_hardirqs_on (); }
Signature · 1 line
2.27.0
PATCH 2/2 x86/entry: Remove `regs' parameter from idtentry_exit_cond_resched()
In reply to Sebastian Andrzej SiewiorThe `regs' parameter is not used in idtentry_exit_cond_resched() and can be removed.
Remove the `regs' parameter.
--- arch/x86/entry/common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/entry/common.c +3 -3
@@ -610,7 +610,7 @@ bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs)return false; } -static void idtentry_exit_cond_resched (struct pt_regs *regs,bool may_sched) +static void idtentry_exit_cond_resched (bool may_sched) {if (may_sched &&should_resched (0 )) {/* Sanity check RCU and thread stack */
@@ -664,7 +664,7 @@ void noinstr idtentry_exit_cond_rcu(struct pt_regs *regs, bool rcu_exit) }instrumentation_begin (); -idtentry_exit_cond_resched (regs,IS_ENABLED (CONFIG_PREEMPTION )); +idtentry_exit_cond_resched (IS_ENABLED (CONFIG_PREEMPTION ));instrumentation_end (); }else {/*
@@ -770,7 +770,7 @@ __visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) inhcall =get_and_clear_inhcall ();if (inhcall && !WARN_ON_ONCE (rcu_exit)) {instrumentation_begin (); -idtentry_exit_cond_resched (regs, true); +idtentry_exit_cond_resched (true);instrumentation_end ();restore_inhcall (inhcall); }else {
Signature · 1 line
2.27.0
Re: [PATCH 2/2] x86/entry: Remove `regs' parameter from idtentry_exit_cond_resched()
Quoted 15 lines · Sebastian Andrzej Siewior
The `regs' parameter is not used in
idtentry_exit_cond_resched()and can be removed.Remove the `regs' parameter.
Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- arch/x86/entry/common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/x86/entry/common.c +0
-0
arch/x86/entry/common.c bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs) · line 613
Quoted 5 lines
arch/x86/entry/common.c +1
-1@@ -610,7 +610,7 @@ bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs)return false; } -static void idtentry_exit_cond_resched (struct pt_regs *regs,bool may_sched) +static void idtentry_exit_cond_resched (bool may_sched)
This is a style question; so far all idtentry_*() functions have regs passed. In the lockdep-vs-nmi series I introduce idtentry_{enter,exit}_nmi() both having an unused regs argument.
Not sure which way around I feel on this.
Re: [PATCH 2/2] x86/entry: Remove `regs' parameter from idtentry_exit_cond_resched()
Quoted 8 lines · Peter Zijlstra
arch/x86/entry/common.c bool noinstr idtentry_enter_cond_rcu(struct pt_regs *regs) · line 613
Quoted 2 lines
arch/x86/entry/common.c +1
-1-static void idtentry_exit_cond_resched (struct pt_regs *regs,bool may_sched) +static void idtentry_exit_cond_resched (bool may_sched)This is a style question; so far all idtentry_*() functions have regs passed. In the lockdep-vs-nmi series I introduce idtentry_{enter,exit}_nmi() both having an unused regs argument.
Not sure which way around I feel on this.
Do as you are pleased. I was more attached to the previous patch that to this one :)
Sebastian