diff mbox series

[v2,net,6/7] net/sched: taprio: fix q->current_entry is NULL before its expiry

Message ID 20231107112023.676016-7-faizal.abdul.rahim@linux.intel.com (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series qbv cycle time extension/truncation | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1316 this patch: 1316
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 1343 this patch: 1343
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1344 this patch: 1344
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Abdul Rahim, Faizal Nov. 7, 2023, 11:20 a.m. UTC
Fix the issue of prematurely setting q->current_entry to NULL in the
setup_first_end_time() function when a new admin schedule arrives
while the oper schedule is still running but hasn't transitioned yet.
This premature setting causes problems because any reference to
q->current_entry, such as in taprio_dequeue(), will result in NULL
during this period, which is incorrect. q->current_entry should remain
valid until the currently running entry expires.

To address this issue, only set q->current_entry to NULL when there is
no oper schedule currently running.

Fixes: 5a781ccbd19e ("tc: Add support for configuring the taprio scheduler")
Signed-off-by: Faizal Rahim <faizal.abdul.rahim@linux.intel.com>
---
 net/sched/sch_taprio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Vladimir Oltean Nov. 9, 2023, 11:55 a.m. UTC | #1
On Tue, Nov 07, 2023 at 06:20:22AM -0500, Faizal Rahim wrote:
> Fix the issue of prematurely setting q->current_entry to NULL in the
> setup_first_end_time() function when a new admin schedule arrives
> while the oper schedule is still running but hasn't transitioned yet.
> This premature setting causes problems because any reference to
> q->current_entry, such as in taprio_dequeue(), will result in NULL
> during this period, which is incorrect. q->current_entry should remain
> valid until the currently running entry expires.
> 
> To address this issue, only set q->current_entry to NULL when there is
> no oper schedule currently running.
> 
> Fixes: 5a781ccbd19e ("tc: Add support for configuring the taprio scheduler")

The "Fixes" tag represents the commit where the code started becoming a
problem, not when the code that you're changing was first introduced.

I find it hard to believe that the problem was in commit 5a781ccbd19e
("tc: Add support for configuring the taprio scheduler"), because we
didn't support admin -> oper dynamic schedules back then.

> Signed-off-by: Faizal Rahim <faizal.abdul.rahim@linux.intel.com>
> ---
>  net/sched/sch_taprio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
> index 01b114edec30..c60e9e7ac193 100644
> --- a/net/sched/sch_taprio.c
> +++ b/net/sched/sch_taprio.c
> @@ -1375,7 +1375,8 @@ static void setup_first_end_time(struct taprio_sched *q,
>  			first->gate_close_time[tc] = ktime_add_ns(base, first->gate_duration[tc]);
>  	}
>  
> -	rcu_assign_pointer(q->current_entry, NULL);
> +	if (!hrtimer_active(&q->advance_timer))
> +		rcu_assign_pointer(q->current_entry, NULL);
>  }
>  
>  static void taprio_start_sched(struct Qdisc *sch,
> -- 
> 2.25.1
>
Abdul Rahim, Faizal Nov. 15, 2023, 11:56 a.m. UTC | #2
On 9/11/2023 7:55 pm, Vladimir Oltean wrote:
> On Tue, Nov 07, 2023 at 06:20:22AM -0500, Faizal Rahim wrote:
>> Fix the issue of prematurely setting q->current_entry to NULL in the
>> setup_first_end_time() function when a new admin schedule arrives
>> while the oper schedule is still running but hasn't transitioned yet.
>> This premature setting causes problems because any reference to
>> q->current_entry, such as in taprio_dequeue(), will result in NULL
>> during this period, which is incorrect. q->current_entry should remain
>> valid until the currently running entry expires.
>>
>> To address this issue, only set q->current_entry to NULL when there is
>> no oper schedule currently running.
>>
>> Fixes: 5a781ccbd19e ("tc: Add support for configuring the taprio scheduler")
> 
> The "Fixes" tag represents the commit where the code started becoming a
> problem, not when the code that you're changing was first introduced.
> 
> I find it hard to believe that the problem was in commit 5a781ccbd19e
> ("tc: Add support for configuring the taprio scheduler"), because we
> didn't support admin -> oper dynamic schedules back then.
> 

My bad, will update accordingly.

>> Signed-off-by: Faizal Rahim <faizal.abdul.rahim@linux.intel.com>
>> ---
>>   net/sched/sch_taprio.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
>> index 01b114edec30..c60e9e7ac193 100644
>> --- a/net/sched/sch_taprio.c
>> +++ b/net/sched/sch_taprio.c
>> @@ -1375,7 +1375,8 @@ static void setup_first_end_time(struct taprio_sched *q,
>>   			first->gate_close_time[tc] = ktime_add_ns(base, first->gate_duration[tc]);
>>   	}
>>   
>> -	rcu_assign_pointer(q->current_entry, NULL);
>> +	if (!hrtimer_active(&q->advance_timer))
>> +		rcu_assign_pointer(q->current_entry, NULL);
>>   }
>>   
>>   static void taprio_start_sched(struct Qdisc *sch,
>> -- 
>> 2.25.1
>>
diff mbox series

Patch

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 01b114edec30..c60e9e7ac193 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -1375,7 +1375,8 @@  static void setup_first_end_time(struct taprio_sched *q,
 			first->gate_close_time[tc] = ktime_add_ns(base, first->gate_duration[tc]);
 	}
 
-	rcu_assign_pointer(q->current_entry, NULL);
+	if (!hrtimer_active(&q->advance_timer))
+		rcu_assign_pointer(q->current_entry, NULL);
 }
 
 static void taprio_start_sched(struct Qdisc *sch,