From: Jakub Kicinski Date: Fri, 13 Jan 2023 04:41:37 +0000 (-0800) Subject: net: sched: gred: prevent races when adding offloads to stats X-Git-Tag: v6.1.9~190 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58bdab02b2250acdb18fc8e7d1a10d2a43fb54f6;p=platform%2Fkernel%2Flinux-starfive.git net: sched: gred: prevent races when adding offloads to stats [ Upstream commit 339346d49ae0859fe19b860998867861d37f1a76 ] Naresh reports seeing a warning that gred is calling u64_stats_update_begin() with preemption enabled. Arnd points out it's coming from _bstats_update(). We should be holding the qdisc lock when writing to stats, they are also updated from the datapath. Reported-by: Linux Kernel Functional Testing Link: https://lore.kernel.org/all/CA+G9fYsTr9_r893+62u6UGD3dVaCE-kN9C-Apmb2m=hxjc1Cqg@mail.gmail.com/ Fixes: e49efd5288bd ("net: sched: gred: support reporting stats from offloads") Link: https://lore.kernel.org/r/20230113044137.1383067-1-kuba@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c index a661b06..872d127 100644 --- a/net/sched/sch_gred.c +++ b/net/sched/sch_gred.c @@ -377,6 +377,7 @@ static int gred_offload_dump_stats(struct Qdisc *sch) /* Even if driver returns failure adjust the stats - in case offload * ended but driver still wants to adjust the values. */ + sch_tree_lock(sch); for (i = 0; i < MAX_DPs; i++) { if (!table->tab[i]) continue; @@ -393,6 +394,7 @@ static int gred_offload_dump_stats(struct Qdisc *sch) sch->qstats.overlimits += hw_stats->stats.qstats[i].overlimits; } _bstats_update(&sch->bstats, bytes, packets); + sch_tree_unlock(sch); kfree(hw_stats); return ret;