6.6.158-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 504/1193 net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yael Chemla <[email protected]>
[ Upstream commit 7ee07f601f8f507c9faf25c68a49396ab8950596 ]
In mlx5_eswitch_termtbl_put(), the zero-ref cleanup check reads tt->ref_count after termtbl_mutex has been released. Two concurrent callers on the same mlx5_termtbl_handle race: one decrements ref_count to zero, removes the hash entry, and calls kfree(tt) while the other has already dropped the mutex and is about to evaluate
if (!tt->ref_count), producing a use-after-free.
Fix this by capturing the result of the decrement into a stack-local last variable before dropping the mutex. The cleanup decision is now made entirely under termtbl_mutex, and tt is not touched after kfree.
--- .../ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c +5 -2
@@ -163,12 +163,15 @@ void mlx5_eswitch_termtbl_put(struct mlx5_eswitch *esw, struct mlx5_termtbl_handle *tt) { + bool last; +mutex_lock (&esw->offloads.termtbl_mutex); -if (--tt->ref_count ==0 ) + last = (--tt->ref_count ==0 ); +if (last)hash_del (&tt->termtbl_hlist);mutex_unlock (&esw->offloads.termtbl_mutex); -if (!tt->ref_count) { +if (last) {mlx5_del_flow_rules (tt->rule);mlx5_destroy_flow_table (tt->termtbl);kfree (tt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 505/1193 net/mlx5: E-Switch, prevent mc_list repopulation during vport disable
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lama Kayal <[email protected]>
[ Upstream commit c0c6f4ba8a37688f7b4d4044898d88f0450d44c2 ]
In mlx5_esw_vport_disable(), move esw_apply_vport_rx_mode() ahead of esw_vport_change_handle_locked() so vport->allmulti_rule is NULL before the change handler observes it.
During FW-fatal recovery the disable runs while dev->state == INTERNAL_ERROR. The promisc query inside esw_update_vport_rx_mode() fails and returns early, leaving vport->allmulti_rule intact, so esw_update_vport_mc_promisc() runs and adds MLX5_ACTION_ADD entries to vport->mc_list whose flow rules are then installed in the FDB by esw_add_mc_addr(). esw_destroy_legacy_table() tears down the FDB with those refs still held, corrupting the sub-tree and leaving dangling flow_rule pointers in vport->mc_list.
Two-stage failure on echo 1 > /sys/bus/pci/devices/<bdf>/reset:
refcount_t: underflow; use-after-free.
tree_put_node+0xef/0x110 [mlx5_core] clean_tree+0x44/0xd0 [mlx5_core] (x5) mlx5_fs_core_cleanup+0x57/0x1c0 [mlx5_core] mlx5_unload+0x65/0xd0 [mlx5_core] ... mlx5_health_try_recover BUG: unable to handle page fault for address: 0000000003000055 down_write+0x1c/0x60 mlx5_del_flow_rules+0x33/0x1f0 [mlx5_core] esw_del_mc_addr+0x7b/0x170 [mlx5_core] esw_apply_vport_addr_list+0x56/0xf0 [mlx5_core] esw_vport_change_handle_locked+0x28b/0x310 [mlx5_core] mlx5_esw_vport_enable+0x270/0x4a0 [mlx5_core] ... mlx5_load ... mlx5_health_try_recover
esw_apply_vport_rx_mode(false, false) clears vport->allmulti_rule via its local state machine even when the FW del fails. With the rule NULL the !IS_ERR_OR_NULL(allmulti_rule) gate in the change handler closes, no rules are installed during disable, and the reload starts with a clean mc_list.
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +7 -1
@@ -972,13 +972,19 @@ void mlx5_esw_vport_disable(struct mlx5_eswitch *esw, struct mlx5_vport *vport) (vport->info.ipsec_crypto_enabled || vport->info.ipsec_packet_enabled)) esw->enabled_ipsec_vf_count--; +/* Clear rx-mode before esw_vport_change_handle_locked(): on +* MLX5_VPORT_PROMISC_CHANGE it calls esw_update_vport_mc_promisc() +* when vport->allmulti_rule is set, repopulating mc_list with FDB +* rules that dangle once the FDB is destroyed. NULL allmulti_rule +* here skips that path. +*/ +esw_apply_vport_rx_mode (esw, vport, false, false);/* We don't assume VFs will cleanup after themselves. * Calling vport change handler while vport is disabled will cleanup * the vport resources. */ esw_vport_change_handle_locked (vport); vport->enabled_events =0 ; -esw_apply_vport_rx_mode (esw, vport, false, false);esw_vport_cleanup (esw, vport); esw->enabled_vports--;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 506/1193 net_sched: sch_fq_pie: implement lockless fq_pie_dump()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 13a9965de32457d59aa3162d657aa4c5e512c146 ]
Instead of relying on RTNL, fq_pie_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in fq_pie_change().
Stable-dep-of: 4864f58c53eb ("net/sched: fq_pie: clamp quantum in change path")
--- net/sched/sch_fq_pie.c | 61 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 27 deletions(-)
net/sched/sch_fq_pie.c +34 -27
@@ -298,8 +298,8 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt,if (tb[TCA_FQ_PIE_LIMIT ]) {u32 limit =nla_get_u32 (tb[TCA_FQ_PIE_LIMIT ]); - q->p_params.limit = limit; - sch->limit = limit; +WRITE_ONCE (q->p_params.limit, limit); +WRITE_ONCE (sch->limit, limit); }if (tb[TCA_FQ_PIE_FLOWS ]) {if (q->flows) {
@@ -321,39 +321,45 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt,u32 target =nla_get_u32 (tb[TCA_FQ_PIE_TARGET ]);/* convert to pschedtime */ - q->p_params.target = -PSCHED_NS2TICKS ((u64 )target *NSEC_PER_USEC ); +WRITE_ONCE (q->p_params.target, +PSCHED_NS2TICKS ((u64 )target *NSEC_PER_USEC )); }/* tupdate is in jiffies */ if (tb[TCA_FQ_PIE_TUPDATE ]) - q->p_params.tupdate = -usecs_to_jiffies (nla_get_u32 (tb[TCA_FQ_PIE_TUPDATE ])); +WRITE_ONCE (q->p_params.tupdate, +usecs_to_jiffies (nla_get_u32 (tb[TCA_FQ_PIE_TUPDATE ])));if (tb[TCA_FQ_PIE_ALPHA ]) - q->p_params.alpha =nla_get_u32 (tb[TCA_FQ_PIE_ALPHA ]); +WRITE_ONCE (q->p_params.alpha, +nla_get_u32 (tb[TCA_FQ_PIE_ALPHA ]));if (tb[TCA_FQ_PIE_BETA ]) - q->p_params.beta =nla_get_u32 (tb[TCA_FQ_PIE_BETA ]); +WRITE_ONCE (q->p_params.beta, +nla_get_u32 (tb[TCA_FQ_PIE_BETA ]));if (tb[TCA_FQ_PIE_QUANTUM ]) - q->quantum =nla_get_u32 (tb[TCA_FQ_PIE_QUANTUM ]); +WRITE_ONCE (q->quantum,nla_get_u32 (tb[TCA_FQ_PIE_QUANTUM ]));if (tb[TCA_FQ_PIE_MEMORY_LIMIT ]) - q->memory_limit =nla_get_u32 (tb[TCA_FQ_PIE_MEMORY_LIMIT ]); +WRITE_ONCE (q->memory_limit, +nla_get_u32 (tb[TCA_FQ_PIE_MEMORY_LIMIT ]));if (tb[TCA_FQ_PIE_ECN_PROB ]) - q->ecn_prob =nla_get_u32 (tb[TCA_FQ_PIE_ECN_PROB ]); +WRITE_ONCE (q->ecn_prob, +nla_get_u32 (tb[TCA_FQ_PIE_ECN_PROB ]));if (tb[TCA_FQ_PIE_ECN ]) - q->p_params.ecn =nla_get_u32 (tb[TCA_FQ_PIE_ECN ]); +WRITE_ONCE (q->p_params.ecn, +nla_get_u32 (tb[TCA_FQ_PIE_ECN ]));if (tb[TCA_FQ_PIE_BYTEMODE ]) - q->p_params.bytemode =nla_get_u32 (tb[TCA_FQ_PIE_BYTEMODE ]); +WRITE_ONCE (q->p_params.bytemode, +nla_get_u32 (tb[TCA_FQ_PIE_BYTEMODE ]));if (tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR ]) - q->p_params.dq_rate_estimator = -nla_get_u32 (tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR ]); +WRITE_ONCE (q->p_params.dq_rate_estimator, +nla_get_u32 (tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR ]));/* Drop excess packets if new limit is lower */ while (sch->q.qlen > sch->limit) {
@@ -471,22 +477,23 @@ static int fq_pie_dump(struct Qdisc *sch, struct sk_buff *skb)return -EMSGSIZE ;/* convert target from pschedtime to us */ -if (nla_put_u32 (skb,TCA_FQ_PIE_LIMIT , sch->limit) || -nla_put_u32 (skb,TCA_FQ_PIE_FLOWS , q->flows_cnt) || +if (nla_put_u32 (skb,TCA_FQ_PIE_LIMIT ,READ_ONCE (sch->limit)) || +nla_put_u32 (skb,TCA_FQ_PIE_FLOWS ,READ_ONCE (q->flows_cnt)) ||nla_put_u32 (skb,TCA_FQ_PIE_TARGET , - ((u32 )PSCHED_TICKS2NS (q->p_params.target)) / + ((u32 )PSCHED_TICKS2NS (READ_ONCE (q->p_params.target))) /NSEC_PER_USEC ) ||nla_put_u32 (skb,TCA_FQ_PIE_TUPDATE , -jiffies_to_usecs (q->p_params.tupdate)) || -nla_put_u32 (skb,TCA_FQ_PIE_ALPHA , q->p_params.alpha) || -nla_put_u32 (skb,TCA_FQ_PIE_BETA , q->p_params.beta) || -nla_put_u32 (skb,TCA_FQ_PIE_QUANTUM , q->quantum) || -nla_put_u32 (skb,TCA_FQ_PIE_MEMORY_LIMIT , q->memory_limit) || -nla_put_u32 (skb,TCA_FQ_PIE_ECN_PROB , q->ecn_prob) || -nla_put_u32 (skb,TCA_FQ_PIE_ECN , q->p_params.ecn) || -nla_put_u32 (skb,TCA_FQ_PIE_BYTEMODE , q->p_params.bytemode) || +jiffies_to_usecs (READ_ONCE (q->p_params.tupdate))) || +nla_put_u32 (skb,TCA_FQ_PIE_ALPHA ,READ_ONCE (q->p_params.alpha)) || +nla_put_u32 (skb,TCA_FQ_PIE_BETA ,READ_ONCE (q->p_params.beta)) || +nla_put_u32 (skb,TCA_FQ_PIE_QUANTUM ,READ_ONCE (q->quantum)) || +nla_put_u32 (skb,TCA_FQ_PIE_MEMORY_LIMIT , +READ_ONCE (q->memory_limit)) || +nla_put_u32 (skb,TCA_FQ_PIE_ECN_PROB ,READ_ONCE (q->ecn_prob)) || +nla_put_u32 (skb,TCA_FQ_PIE_ECN ,READ_ONCE (q->p_params.ecn)) || +nla_put_u32 (skb,TCA_FQ_PIE_BYTEMODE ,READ_ONCE (q->p_params.bytemode)) ||nla_put_u32 (skb,TCA_FQ_PIE_DQ_RATE_ESTIMATOR , - q->p_params.dq_rate_estimator)) +READ_ONCE (q->p_params.dq_rate_estimator))) goto nla_put_failure;return nla_nest_end (skb, opts);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 507/1193 net/sched: fq_pie: clamp quantum in change path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 4864f58c53eb47257d55e01f47d4a9f355f7f970 ]
fq_pie_change() accepts any quantum value from userspace, including 1. With a crafted size table qdisc_pkt_len reaches ~2 GiB, so quantum=1 makes the deficit-refill loop spin ~2^31 times under the qdisc lock (a soft lockup / denial of service).
Add max(256U, ...) matching fq_codel_change().
Conditions to recreate the bug:
CONFIG_NET_SCH_FQ_PIE=y. Requires CAP_NET_ADMIN (namespace-local via unshare -Urn suffices).
tc qdisc add dev dummy0 root fq_pie
tc qdisc change dev dummy0 root fq_pie quantum 1 stab data 32768 size_log 15 cell_log 0
--- net/sched/sch_fq_pie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sched/sch_fq_pie.c +2 -1
@@ -339,7 +339,8 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt, nla_get_u32(tb[TCA_FQ_PIE_BETA]));if (tb[TCA_FQ_PIE_QUANTUM ]) -WRITE_ONCE (q->quantum,nla_get_u32 (tb[TCA_FQ_PIE_QUANTUM ])); +WRITE_ONCE (q->quantum, +max (256U ,nla_get_u32 (tb[TCA_FQ_PIE_QUANTUM ])));if (tb[TCA_FQ_PIE_MEMORY_LIMIT ]) WRITE_ONCE(q->memory_limit,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 508/1193 net/sched: sfq: clamp quantum in change path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit fb9f88a33c516ea5c0bcd9a22ca288b246b34567 ]
sfq_change() accepts any non-negative quantum (only rejects (int)ctl->quantum < 0). With a crafted size table qdisc_pkt_len reaches ~2 GiB, so quantum=1 makes the deficit-refill loop spin ~2^31 times under the qdisc lock (a soft lockup / denial of service).
Add max(256U, ...) matching fq_codel_change(). Reject quantum > 1<<20 with -EINVAL, matching fq_codel_change() and the init clamp.
Conditions to recreate the bug:
CONFIG_NET_SCH_SFQ=y. Requires CAP_NET_ADMIN (namespace-local via unshare -Urn suffices).
tc qdisc add dev dummy0 root sfq
tc qdisc change dev dummy0 root sfq quantum 1 stab data 32768 size_log 15 cell_log 0
--- net/sched/sch_sfq.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/sched/sch_sfq.c +6 -1
@@ -657,6 +657,11 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,return -EINVAL ; } +if (ctl->quantum >1 <<20 ) { +NL_SET_ERR_MSG_MOD (extack,"quantum too large" ); +return -EINVAL ; + } +if (ctl->perturb_period <0 || ctl->perturb_period >INT_MAX /HZ ) {NL_SET_ERR_MSG_MOD (extack,"invalid perturb period" );
@@ -685,7 +690,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,/* update and validate configuration */ if (ctl->quantum) - quantum = ctl->quantum; + quantum =max (256U , ctl->quantum);if (ctl->flows) maxflows =min_t (u32, ctl->flows,SFQ_MAX_FLOWS );if (ctl->divisor) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 509/1193 net/sched: hhf: clamp quantum in change and init paths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit eb56a495f59baf6cad5ed80e3ffb9078098b1346 ]
hhf_change() accepts any quantum from userspace, including 1. With a crafted size table qdisc_pkt_len reaches ~2 GiB, so quantum=1 makes the deficit-refill loop spin ~2^31 times under the qdisc lock (a soft lockup / denial of service).
Add max(256U, ...) in hhf_change() matching fq_codel_change(). Clamp hhf_init() to [256, 1<<20] matching the siblings, and remove the old fallback that only set quantum=256 on overflow.
Conditions to recreate the bug:
CONFIG_NET_SCH_HHF=y. Requires CAP_NET_ADMIN (namespace-local via unshare -Urn suffices).
tc qdisc add dev dummy0 root hhf
tc qdisc change dev dummy0 root hhf quantum 1 stab data 32768 size_log 15 cell_log 0
--- net/sched/sch_hhf.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
net/sched/sch_hhf.c +2 -6
@@ -550,7 +550,7 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt,return err;if (tb[TCA_HHF_QUANTUM ]) - new_quantum =nla_get_u32 (tb[TCA_HHF_QUANTUM ]); + new_quantum =max (256U ,nla_get_u32 (tb[TCA_HHF_QUANTUM ]));if (tb[TCA_HHF_NON_HH_WEIGHT ]) new_hhf_non_hh_weight =nla_get_u32 (tb[TCA_HHF_NON_HH_WEIGHT ]);
@@ -606,7 +606,7 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt,int i; sch->limit =1000 ; - q->quantum =psched_mtu (qdisc_dev (sch)); + q->quantum =clamp_t (u32,psched_mtu (qdisc_dev (sch)),256 ,1 <<20 );get_random_bytes (&q->perturbation,sizeof (q->perturbation));INIT_LIST_HEAD (&q->new_buckets);INIT_LIST_HEAD (&q->old_buckets);
@@ -617,10 +617,6 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt, q->hhf_evict_timeout =HZ ;/* 1 sec */ q->hhf_non_hh_weight =2 ; -if ((int )q->quantum <=0 || - (u64 )q->quantum * q->hhf_non_hh_weight >INT_MAX ) - q->quantum =256 ; -if (opt) {int err =hhf_change (sch, opt, extack);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 510/1193 net/sched: pie: clamp psched_mtu in pie_drop_early
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 54370e44c002770ae61fc889f28f699e91616ffc ]
pie_drop_early() calls psched_mtu() with no clamp. With mtu=0x80000000 the bytemode divide silently zeroes the drop probability, disabling AQM. Clamp to [1, 1<<20].
Conditions to recreate the bug:
CONFIG_NET_SCH_PIE=y. Requires CAP_NET_ADMIN (namespace-local via unshare -Urn suffices).
tc qdisc add dev dummy0 root pie
tc qdisc change dev dummy0 root pie stab data 32768 size_log 15 cell_log 0
--- net/sched/sch_pie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_pie.c +1 -1
@@ -35,7 +35,7 @@ bool pie_drop_early(struct Qdisc *sch, struct pie_params *params, {u64 rnd;u64 local_prob = vars->prob; -u32 mtu =psched_mtu (qdisc_dev (sch)); +u32 mtu =clamp_t (u32,psched_mtu (qdisc_dev (sch)),1 ,1 <<20 );/* If there is still burst allowance left skip random early drop */ if (vars->burst_time >0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 511/1193 net/sched: drr: clamp quantum in change class
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 8382abec0f1568d0a5590d75a3df92f23fcf5196 ]
drr_change_class() rejects explicit quantum==0 but falls back to psched_mtu() with no floor. With a crafted size table qdisc_pkt_len reaches ~2 GiB, so quantum=1 (or a zero psched_mtu on a headerless device) makes the deficit-refill loop spin under the qdisc lock.
Add clamp_t(u32, quantum, 256, 1<<20) after the zero reject and on the fallback path. The explicit-zero reject is preserved.
Conditions to recreate the bug:
CONFIG_NET_SCH_DRR=y. Requires CAP_NET_ADMIN (namespace-local via unshare -Urn suffices).
tc qdisc add dev dummy0 root drr
tc class add dev dummy0 parent 1: classid 1:1 drr quantum 1
--- net/sched/sch_drr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sched/sch_drr.c +2 -1
@@ -82,8 +82,9 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,NL_SET_ERR_MSG (extack,"Specified DRR quantum cannot be zero" );return -EINVAL ; } + quantum =clamp_t (u32, quantum,256 ,1 <<20 ); }else - quantum =psched_mtu (qdisc_dev (sch)); + quantum =clamp_t (u32, (u32 )psched_mtu (qdisc_dev (sch)),256 ,1 <<20 );if (cl !=NULL ) {if (tca[TCA_RATE ]) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 512/1193 net/sched: ets: clamp quantum in parse and fallback paths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 1c38487f46b243bfeefec0c0c86023a3904f2214 ]
ets_qdisc_change() falls back to psched_mtu() with no floor for bands without an explicit quantum. With a crafted size table qdisc_pkt_len reaches ~2 GiB, so a zero psched_mtu on a headerless device makes the deficit-refill loop spin under the qdisc lock.
Move the floor into ets_quantum_parse() so explicitly configured quanta are also clamped to [256, 1<<20], not just the fallback path.
Conditions to recreate the bug:
CONFIG_NET_SCH_ETS=y. Requires CAP_NET_ADMIN (namespace-local via unshare -Urn suffices).
tc qdisc add dev dummy0 root ets bands 3 strict 2 quanta 1 1
--- net/sched/sch_ets.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
net/sched/sch_ets.c +5 -7
@@ -83,11 +83,7 @@ static int ets_quantum_parse(struct Qdisc *sch, const struct nlattr *attr,unsigned int *quantum, struct netlink_ext_ack *extack) { - *quantum =nla_get_u32 (attr); -if (!*quantum) { -NL_SET_ERR_MSG (extack,"ETS quantum cannot be zero" ); -return -EINVAL ; - } + *quantum =clamp_t (u32,nla_get_u32 (attr),256 ,1 <<20 );return 0 ; }
@@ -634,11 +630,13 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt,return err; }/* If there are more bands than strict + quanta provided, the remaining -* ones are ETS with quantum of MTU. Initialize the missing values here. +* ones are ETS with quantum of max(MTU, 256). Initialize the missing +* values here. */ for (i = nstrict; i < nbands; i++) {if (!quanta[i]) - quanta[i] =psched_mtu (qdisc_dev (sch)); + quanta[i] =clamp_t (u32, (u32 )psched_mtu (qdisc_dev (sch)), +256 ,1 <<20 ); }/* Before commit, make sure we can allocate all new qdiscs */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 513/1193 workqueue: Introduce from_work() helper for cleaner callback declarations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Allen Pais <[email protected]>
[ Upstream commit 60b2ebf48526567b53e0188dbd1a4df8e646bcc1 ]
To streamline the transition from tasklets to worqueues, a new helper function, from_work(), is introduced. This helper, inspired by existing from_() patterns, utilizes container_of() and eliminates the redundancy of declaring variable types, leading to more concise and readable code.
The modified code snippet demonstrates the enhanced clarity achieved with from_wq():
void callback(struct work_struct *w)
{
- struct some_data_structure *local = container_of(w,
struct some_data_structure, work);
+ struct some_data_structure *local = from_work(local, w, work);
This change aims to facilitate a smoother transition and uphold code quality standards.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git disable_work-v3
Stable-dep-of: 38b6be101006 ("net: macb: fix NULL pointer dereference on unbind with fixed-link")
--- include/linux/workqueue.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/workqueue.h +3 -0
@@ -487,6 +487,9 @@ alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...);#define create_singlethread_workqueue (name) \ alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name) +#define from_work (var, callback_work, work_fieldname) \ + container_of(callback_work, typeof(*var), work_fieldname) +extern void destroy_workqueue (struct workqueue_struct *wq);struct workqueue_attrs *alloc_workqueue_attrs (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 514/1193 net: macb: rename bp->sgmii_phy field to bp->phy
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Théo Lebrun <[email protected]>
[ Upstream commit 3f7e51cd5fbf4d970b14956ee9464515bb40666f ]
The bp->sgmii_phy field is initialised at probe by init_reset_optional() if bp->phy_interface == PHY_INTERFACE_MODE_SGMII. It gets used by:
- zynqmp_config: "cdns,zynqmp-gem" or "xlnx,zynqmp-gem" compatibles.
- mpfs_config: "microchip,mpfs-macb" compatible.
- versal_config: "xlnx,versal-gem" compatible.
Make name more generic as EyeQ5 requires the PHY in SGMII & RGMII cases.
Drop "for ZynqMP SGMII mode" comment that is already a lie, as it gets used on Microchip platforms as well. And soon it won't be SGMII-only.
Stable-dep-of: 38b6be101006 ("net: macb: fix NULL pointer dereference on unbind with fixed-link")
--- drivers/net/ethernet/cadence/macb.h | 2 +- drivers/net/ethernet/cadence/macb_main.c | 26 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/net/ethernet/cadence/macb.h +1 -1
@@ -1313,7 +1313,7 @@ struct macb {struct macb_ptp_info *ptp_info;/* macb-ptp interface */ -struct phy *sgmii_phy;/* for ZynqMP SGMII mode */ +struct phy *phy;#ifdef MACB_EXT_DESC uint8_t hw_dma_cap;
drivers/net/ethernet/cadence/macb_main.c +13 -13
@@ -3107,7 +3107,7 @@ static int macb_open(struct net_device *dev)macb_init_hw (bp); - err =phy_power_on (bp->sgmii_phy); + err =phy_power_on (bp->phy);if (err) goto reset_hw;
@@ -3123,7 +3123,7 @@ static int macb_open(struct net_device *dev)return 0 ; phy_off: -phy_power_off (bp->sgmii_phy); +phy_power_off (bp->phy); reset_hw:macb_reset_hw (bp);
@@ -3154,7 +3154,7 @@ static int macb_close(struct net_device *dev)phylink_stop (bp->phylink);phylink_disconnect_phy (bp->phylink); -phy_power_off (bp->sgmii_phy); +phy_power_off (bp->phy);spin_lock_irqsave (&bp->lock, flags);macb_reset_hw (bp);
@@ -4865,13 +4865,13 @@ static int init_reset_optional(struct platform_device *pdev)if (bp->phy_interface ==PHY_INTERFACE_MODE_SGMII ) {/* Ensure PHY device used in SGMII mode is ready */ - bp->sgmii_phy =devm_phy_optional_get (&pdev->dev,NULL ); + bp->phy =devm_phy_optional_get (&pdev->dev,NULL ); -if (IS_ERR (bp->sgmii_phy)) -return dev_err_probe (&pdev->dev,PTR_ERR (bp->sgmii_phy), +if (IS_ERR (bp->phy)) +return dev_err_probe (&pdev->dev,PTR_ERR (bp->phy),"failed to get SGMII PHY\n" ); - ret =phy_init (bp->sgmii_phy); + ret =phy_init (bp->phy);if (ret)return dev_err_probe (&pdev->dev, ret,"failed to init SGMII PHY\n" );
@@ -4900,7 +4900,7 @@ static int init_reset_optional(struct platform_device *pdev)/* Fully reset controller at hardware level if mapped in device tree */ ret =device_reset_optional (&pdev->dev);if (ret) { -phy_exit (bp->sgmii_phy); +phy_exit (bp->phy);return dev_err_probe (&pdev->dev, ret,"failed to reset controller" ); }
@@ -4908,7 +4908,7 @@ static int init_reset_optional(struct platform_device *pdev) err_out_phy_exit:if (ret) -phy_exit (bp->sgmii_phy); +phy_exit (bp->phy);return ret; }
@@ -5309,7 +5309,7 @@ static int macb_probe(struct platform_device *pdev)mdiobus_free (bp->mii_bus); err_out_phy_exit: -phy_exit (bp->sgmii_phy); +phy_exit (bp->phy); err_out_free_netdev:free_netdev (dev);
@@ -5333,7 +5333,7 @@ static int macb_remove(struct platform_device *pdev)if (dev) { bp =netdev_priv (dev);unregister_netdev (dev); -phy_exit (bp->sgmii_phy); +phy_exit (bp->phy);mdiobus_unregister (bp->mii_bus);mdiobus_free (bp->mii_bus);
@@ -5363,7 +5363,7 @@ static int __maybe_unused macb_suspend(struct device *dev)u32 tmp;if (!device_may_wakeup (&bp->dev->dev)) -phy_exit (bp->sgmii_phy); +phy_exit (bp->phy);if (!netif_running (netdev))return 0 ;
@@ -5479,7 +5479,7 @@ static int __maybe_unused macb_resume(struct device *dev)int err;if (!device_may_wakeup (&bp->dev->dev)) -phy_init (bp->sgmii_phy); +phy_init (bp->phy);if (!netif_running (netdev))return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/1193 net: macb: fix NULL pointer dereference on unbind with fixed-link
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Karumanchi <[email protected]>
[ Upstream commit 38b6be101006d3e7af972999f45d4f1e8250587a ]
When the device tree describes a fixed-link and has no "mdio" child node, macb_mii_init() returns early without allocating the MDIO bus, leaving bp->mii_bus as NULL.
Two cleanup paths then dereference this NULL bus:
1. On driver unbind, macb_remove() unconditionally calls mdiobus_unregister(bp->mii_bus), which oopses:
Unable to handle kernel NULL pointer dereference at virtual address 00000000000004a8 pc : mdiobus_unregister+0x14/0xa4 lr : macb_remove+0x38/0xa4 Call trace: mdiobus_unregister+0x14/0xa4 (P) macb_remove+0x38/0xa4 platform_remove+0x20/0x30 device_release_driver_internal+0x1c8/0x224 unbind_store+0xb4/0xbc
2. On the probe error path in macb_probe(), reached when macb_mii_init() has succeeded but a subsequent step fails, the err_out_unregister_mdio label runs the same unconditional cleanup.
mdiobus_unregister() and mdiobus_free() do not guard against a NULL bus, so guard the calls in both macb_remove() and the probe error path.
--- drivers/net/ethernet/cadence/macb_main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +8 -4
@@ -5305,8 +5305,10 @@ static int macb_probe(struct platform_device *pdev)return 0 ; err_out_unregister_mdio: -mdiobus_unregister (bp->mii_bus); -mdiobus_free (bp->mii_bus); +if (bp->mii_bus) { +mdiobus_unregister (bp->mii_bus); +mdiobus_free (bp->mii_bus); + } err_out_phy_exit:phy_exit (bp->phy);
@@ -5334,8 +5336,10 @@ static int macb_remove(struct platform_device *pdev) bp =netdev_priv (dev);unregister_netdev (dev);phy_exit (bp->phy); -mdiobus_unregister (bp->mii_bus); -mdiobus_free (bp->mii_bus); +if (bp->mii_bus) { +mdiobus_unregister (bp->mii_bus); +mdiobus_free (bp->mii_bus); + }tasklet_kill (&bp->hresp_err_tasklet);pm_runtime_disable (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 516/1193 bpf: Reject non-scalar bpf_loop iteration counts
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit c3fd8e5fd100f122bad503bdc0e9277219533253 ]
bpf_loop() declares its nr_loops argument as ARG_ANYTHING. Privileged programs may pass pointer values to such arguments, so check_func_arg() lets a pointer-valued R1 reach the helper-specific checks.
Since commit bb124da69c47 ("bpf: keep track of max number of bpf_loop callback iterations"), the verifier marks R1 precise and reads its upper bound to limit callback simulation. Precision backtracking only accepts scalar registers, so passing a pointer instead triggers the "backtracking misuse" verifier warning. Kernels with panic_on_warn enabled subsequently panic.
Introduce ARG_SCALAR for helper arguments that only accept scalar values and use it for bpf_loop() nr_loops. Generic helper argument validation then rejects pointers before loop inlining and precision processing.
--- include/linux/bpf.h | 1 + kernel/bpf/bpf_iter.c | 2 +- kernel/bpf/verifier.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
include/linux/bpf.h +1 -0
@@ -742,6 +742,7 @@ enum bpf_arg_type {ARG_PTR_TO_CTX ,/* pointer to context */ ARG_ANYTHING ,/* any (initialized) argument is ok */ +ARG_SCALAR ,/* scalar argument */ ARG_PTR_TO_SPIN_LOCK ,/* pointer to bpf_spin_lock */ ARG_PTR_TO_SOCK_COMMON ,/* pointer to sock_common */ ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */
kernel/bpf/bpf_iter.c +1 -1
@@ -771,7 +771,7 @@ const struct bpf_func_proto bpf_loop_proto = { .func = bpf_loop, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1_type = ARG_ANYTHING, + .arg1_type = ARG_SCALAR, .arg2_type = ARG_PTR_TO_FUNC, .arg3_type = ARG_PTR_TO_STACK_OR_NULL, .arg4_type = ARG_ANYTHING,
kernel/bpf/verifier.c +1 -0
@@ -8243,6 +8243,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_CONST_SIZE] = &scalar_types, [ARG_CONST_SIZE_OR_ZERO] = &scalar_types, [ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types, + [ARG_SCALAR] = &scalar_types, [ARG_CONST_MAP_PTR] = &const_map_ptr_types, [ARG_PTR_TO_CTX] = &context_types, [ARG_PTR_TO_SOCK_COMMON] = &sock_types,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 517/1193 ALSA: caiaq: Decoupling ep1_in_urb in caiaq dev
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Edward Adam Davis <[email protected]>
[ Upstream commit 402a9d6aab7ac787ab075adeb562c3db8b8f564b ]
The epq_in_urb object belonging to the caiaq device is coupled within the struct snd_usb_caiaqdev. After usb_submit_urb(epq_in_urb, GFP_KERNEL) executes successfully, epq_in_urb is successfully added to the urbp_list queue of the dummy HCD driver (userspace specifies dummy_hcd as the HCD layer driver for the caiaq USB device).
When init_card() calls snd_usb_caiaq_send_command() which subsequently fails due to a timeout, and proceeds to call snd_card_free() to release the card, the embedded ep1_in_urb object is also freed. When the dummy HCD driver detects that the URB has been unlinked, it returns the URB (by usb_hcd_giveback_urb()), which triggers [1].
Decouple the ep1_in_urb object from the struct snd_usb_caiaqdev and switch to using a pointer instead. Separately allocate and manage the memory for ep1_in_urb to prevent the release of the snd_card memory object from interfering with it.
midi_out_urb has the same issue as ep1_in_urb and is handled in the same way.
[1]
BUG: KASAN: slab-use-after-free in usb_free_urb+0x24/0x120 drivers/usb/core/urb.c:96 Write of size 4 at addr ffff88803cee1050 by task ktimers/1/29 Call Trace: usb_free_urb+0x24/0x120 drivers/usb/core/urb.c:96 dummy_timer+0xaac/0x4d50 drivers/usb/gadget/udc/dummy_hcd.c:2019 __run_hrtimer kernel/time/hrtimer.c:2067 [inline] __hrtimer_run_queues+0x3eb/0xaf0 kernel/time/hrtimer.c:2124 hrtimer_run_softirq+0x1e1/0x2e0 kernel/time/hrtimer.c:2141 Allocated by task 36: snd_card_new+0x7b/0x110 sound/core/init.c:184 create_card sound/usb/caiaq/device.c:429 [inline] snd_probe+0x236/0x1af0 sound/usb/caiaq/device.c:544 Freed by task 36: snd_card_free_when_closed sound/core/init.c:630 [inline] snd_card_free+0x138/0x1d0 sound/core/init.c:662 snd_probe+0x162b/0x1af0 sound/usb/caiaq/device.c:553
--- sound/usb/caiaq/device.c | 36 ++++++++++++++++++++++++------------ sound/usb/caiaq/device.h | 4 ++-- sound/usb/caiaq/midi.c | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-)
sound/usb/caiaq/device.c +24 -12
@@ -192,8 +192,8 @@ static void usb_ep1_command_reply_dispatch (struct urb* urb)break ; } - cdev->ep1_in_urb.actual_length =0 ; - ret =usb_submit_urb (&cdev->ep1_in_urb,GFP_ATOMIC ); + cdev->ep1_in_urb->actual_length =0 ; + ret =usb_submit_urb (cdev->ep1_in_urb,GFP_ATOMIC );if (ret <0 )dev_err (dev,"unable to submit urb. OOM!?\n" ); }
@@ -408,6 +408,10 @@ static void card_free(struct snd_card *card)#endif snd_usb_caiaq_audio_free (cdev);usb_put_dev (cdev->chip.dev); +usb_free_urb (cdev->ep1_in_urb); + cdev->ep1_in_urb =NULL ; +usb_free_urb (cdev->midi_out_urb); + cdev->midi_out_urb =NULL ; } static int create_card(struct usb_device *usb_dev,
@@ -457,22 +461,30 @@ static int init_card(struct snd_usb_caiaqdev *cdev)return -EIO ; } -usb_init_urb (&cdev->ep1_in_urb); -usb_init_urb (&cdev->midi_out_urb); + cdev->ep1_in_urb =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!cdev->ep1_in_urb) +return -ENOMEM ; -usb_fill_bulk_urb (&cdev->ep1_in_urb, usb_dev, + cdev->midi_out_urb =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!cdev->midi_out_urb) { +usb_free_urb (cdev->ep1_in_urb); + cdev->ep1_in_urb =NULL ; +return -ENOMEM ; + } + +usb_fill_bulk_urb (cdev->ep1_in_urb, usb_dev,usb_rcvbulkpipe (usb_dev,0x1 ), cdev->ep1_in_buf,EP1_BUFSIZE , usb_ep1_command_reply_dispatch, cdev); -usb_fill_bulk_urb (&cdev->midi_out_urb, usb_dev, +usb_fill_bulk_urb (cdev->midi_out_urb, usb_dev,usb_sndbulkpipe (usb_dev,0x1 ), cdev->midi_out_buf,EP1_BUFSIZE , snd_usb_caiaq_midi_output_done, cdev);/* sanity checks of EPs before actually submitting */ -if (usb_urb_ep_type_check (&cdev->ep1_in_urb) || -usb_urb_ep_type_check (&cdev->midi_out_urb)) { +if (usb_urb_ep_type_check (cdev->ep1_in_urb) || +usb_urb_ep_type_check (cdev->midi_out_urb)) {dev_err (dev,"invalid EPs\n" );return -EINVAL ; }
@@ -480,7 +492,7 @@ static int init_card(struct snd_usb_caiaqdev *cdev)init_waitqueue_head (&cdev->ep1_wait_queue);init_waitqueue_head (&cdev->prepare_wait_queue); -if (usb_submit_urb (&cdev->ep1_in_urb,GFP_KERNEL ) !=0 ) +if (usb_submit_urb (cdev->ep1_in_urb,GFP_KERNEL ) !=0 )return -EIO ; err =snd_usb_caiaq_send_command (cdev,EP1_CMD_GET_DEVICE_INFO ,NULL ,0 );
@@ -530,7 +542,7 @@ static int init_card(struct snd_usb_caiaqdev *cdev)return 0 ; err_kill_urb: -usb_kill_urb (&cdev->ep1_in_urb); +usb_kill_urb (cdev->ep1_in_urb);return err; }
@@ -576,8 +588,8 @@ static void snd_disconnect(struct usb_interface *intf)#endif snd_usb_caiaq_audio_disconnect (cdev); -usb_kill_urb (&cdev->ep1_in_urb); -usb_kill_urb (&cdev->midi_out_urb); +usb_kill_urb (cdev->ep1_in_urb); +usb_kill_urb (cdev->midi_out_urb);snd_card_free_when_closed (card); }
sound/usb/caiaq/device.h +2 -2
@@ -60,8 +60,8 @@ struct snd_usb_caiaq_cb_info;struct snd_usb_caiaqdev {struct snd_usb_audio chip; -struct urb ep1_in_urb; -struct urb midi_out_urb; +struct urb *ep1_in_urb; +struct urb *midi_out_urb;struct urb **data_urbs_in;struct urb **data_urbs_out;struct snd_usb_caiaq_cb_info *data_cb_info;
sound/usb/caiaq/midi.c +3 -3
@@ -43,7 +43,7 @@ static int snd_usb_caiaq_midi_output_close(struct snd_rawmidi_substream *substre {struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data;if (cdev->midi_out_active) { -usb_kill_urb (&cdev->midi_out_urb); +usb_kill_urb (cdev->midi_out_urb); cdev->midi_out_active =0 ; }return 0 ;
@@ -64,9 +64,9 @@ static void snd_usb_caiaq_midi_send(struct snd_usb_caiaqdev *cdev,return ; cdev->midi_out_buf[2 ] = len; - cdev->midi_out_urb.transfer_buffer_length = len+3 ; + cdev->midi_out_urb->transfer_buffer_length = len+3 ; - ret =usb_submit_urb (&cdev->midi_out_urb,GFP_ATOMIC ); + ret =usb_submit_urb (cdev->midi_out_urb,GFP_ATOMIC );if (ret <0 )dev_err (dev, "snd_usb_caiaq_midi_send(%p): usb_submit_urb() failed,"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 518/1193 ASoC: bcm: bcm63xx: Publish the OF module aliases
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: hpp.iscas <[email protected]>
[ Upstream commit 32689f0fc54fd801f1cd11637666e534984cb04a ]
The BCM63xx I2S platform driver matches brcm,bcm63xx-i2s using snd_soc_bcm_audio_match. With SND_BCM63XX_I2S_WHISTLER=m, the platform bus emits an OF modalias but snd-soc-63xx does not publish that table.
Export the existing OF IDs for module autoloading. The PCM companion and the probe path remain unchanged.
--- sound/soc/bcm/bcm63xx-i2s-whistler.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/bcm/bcm63xx-i2s-whistler.c +1 -0
@@ -285,6 +285,7 @@ static const struct of_device_id snd_soc_bcm_audio_match[] = { {.compatible = "brcm,bcm63xx-i2s"}, { } }; +MODULE_DEVICE_TABLE (of, snd_soc_bcm_audio_match);#endif static struct platform_driver bcm63xx_i2s_driver = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 519/1193 ASoC: Intel: SST: Publish the PCI module aliases
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: hpp.iscas <[email protected]>
[ Upstream commit d112159df5c6cc5ee6ab91cc32bf6ed29939df38 ]
The legacy SST PCI driver matches Intel Tangier devices using intel_sst_ids, but its only explicit module alias is "sst". That alias does not match PCI modalias events when this driver is built as a module.
Publish its PCI table. The independently configurable SOF driver does not provide aliases for the legacy SST module.
--- sound/soc/intel/atom/sst/sst_pci.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/intel/atom/sst/sst_pci.c +1 -0
@@ -178,6 +178,7 @@ static const struct pci_device_id intel_sst_ids[] = { { PCI_DEVICE_DATA(INTEL, SST_TNG, 0) }, { 0, } }; +MODULE_DEVICE_TABLE (pci, intel_sst_ids);static struct pci_driver sst_driver = { .name = SST_DRV_NAME,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 520/1193 netfilter: nfnetlink_log: cope with concurrent instance destruction
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 387d744fa7e499d2c3748a4e60e02ebb24e7fb16 ]
Instances are refcounted. However, only memory release happens on the 1 -> 0 transition; the unlink from hashes can occur with any refcount.
Uncooperative userspace can force a situation where a queue is pending for destruction from netlink event while a different socket with same portid processes an UNBIND request.
With right timing, this will unhash the instance again:
Oops: general protection fault, [..] Call Trace: <TASK> nfulnl_recv_config+0x31a/0xd50 nfnetlink_rcv_msg+0x7c2/0xeb0
--- net/netfilter/nfnetlink_log.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/netfilter/nfnetlink_log.c +9 -4
@@ -228,13 +228,18 @@ static void __nfulnl_flush(struct nfulnl_instance *inst);static void __instance_destroy (struct nfulnl_instance *inst) { +spin_lock (&inst->lock); +if (inst->copy_mode ==NFULNL_COPY_DISABLED ) { +/* attempt to UNBIND a queue already pending +* destruction via netlink close event. Ignore. +*/ +spin_unlock (&inst->lock); +return ; + } +/* first pull it out of the global list */ hlist_del_rcu (&inst->hlist); -/* then flush all pending packets from skb */ - -spin_lock (&inst->lock); -/* lockless readers wont be able to use us */ inst->copy_mode =NFULNL_COPY_DISABLED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 521/1193 netfilter: ip6_tables: set F_PROTO when proto value is nonzero
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit da4afc5a956d407443988e97a4d4ca14c2e999c7 ]
The ip6tables traverser doesn't search the extension header chain unless userspace did set the IP6T_F_PROTO flag.
This also means that userspace that sets the e->ipv6.proto flag can bypass the protocol check for the rule by not setting this flag.
That in turn means that all ip6_tables modules and targets that want to reject rules without '-p' flag MUST also check for that flag.
Not all do, likely because they got copied from iptables which lacks this flag (no extension headers).
Instead of fixing up all the relevant targets, emulate ip6tables behaviour in the kernel (like nft_compat.c) and set the flag if the protocol is set.
--- net/ipv6/netfilter/ip6_tables.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ipv6/netfilter/ip6_tables.c +5 -0
@@ -647,6 +647,11 @@ check_entry_size_and_hooks(struct ip6t_entry *e,/* Clear counters and comefrom */ e->counters = ((struct xt_counters ) {0 ,0 }); e->comefrom =0 ; + +/* set F_PROTO, else ip6_packet_match won't do the right thing. */ +if (e->ipv6.proto) + e->ipv6.flags |=IP6T_F_PROTO ; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 522/1193 ASoC: mt6351: Publish the OF module alias
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: hpp.iscas <[email protected]>
[ Upstream commit 9c3882ec10399c14c59b7e4599d33c4395367c37 ]
The MT6351 codec platform driver uses mt6351_of_match to bind devices with compatible mediatek,mt6351-sound. The codec can be a separate module, but the OF table is not exported to module alias metadata.
Publish the existing table without changing codec matching, register access or the machine-driver configuration.
--- sound/soc/codecs/mt6351.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/codecs/mt6351.c +1 -0
@@ -1479,6 +1479,7 @@ static const struct of_device_id mt6351_of_match[] = { {.compatible = "mediatek,mt6351-sound",}, {} }; +MODULE_DEVICE_TABLE (of, mt6351_of_match);static struct platform_driver mt6351_codec_driver = { .driver = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 523/1193 virtio_console: do not free control-out buffers on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit 894f98e73983f37354214a89a3a7fd35bf9e3072 ]
__send_control_msg() publishes &portdev->cpkt as the control-out virtqueue cookie. remove_vqs() walks every virtqueue and passes leftover cookies to free_buf(), which treats them as struct port_buffer and reads sgpages.
If a control message is still on c_ovq when the device is unbound, free_buf() reads past the ports_device object.
KASAN reported slab-out-of-bounds in free_buf():
free_buf
remove_vqs
virtcons_remove
unbind_store
The object was the ports_device allocated in virtcons_probe().
Drain c_ovq without freeing. The packet lives in portdev and is released with it.
Message-ID: <[email protected]>
--- drivers/char/virtio_console.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +18 -3
@@ -1930,13 +1930,28 @@ static const struct file_operations portdev_fops = {static void remove_vqs (struct ports_device *portdev) {struct virtqueue *vq; +bool multiport =use_multiport (portdev);virtio_device_for_each_vq (portdev->vdev, vq) {struct port_buffer *buf; +unsigned int len; -flush_bufs (vq, true); -while ((buf =virtqueue_detach_unused_buf (vq))) -free_buf (buf, true); +/* +* c_ovq cookies are &portdev->cpkt, not port_buffer. +* Detach them but do not free_buf(). +*/ +if (multiport && vq == portdev->c_ovq) { +spin_lock (&portdev->c_ovq_lock); +while (virtqueue_get_buf (vq, &len)) + ; +while (virtqueue_detach_unused_buf (vq)) + ; +spin_unlock (&portdev->c_ovq_lock); + }else { +flush_bufs (vq, true); +while ((buf =virtqueue_detach_unused_buf (vq))) +free_buf (buf, true); + }cond_resched (); } portdev->vdev->config->del_vqs (portdev->vdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 524/1193 vdpa: introduce dedicated descriptor group for virtqueue
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Si-Wei Liu <[email protected]>
[ Upstream commit a72cac6067fdfde280ece0ec5c055659a8de6508 ]
In some cases, the access to the virtqueue's descriptor area, device and driver areas (precluding indirect descriptor table in guest memory) may have to be confined to a different address space than where its buffers reside. Without loss of simplicity and generality with already established terminology, let's fold up these 3 areas and call them as a whole as descriptor table group, or descriptor group for short. Specifically, in case of split virtqueues, descriptor group consists of regions for Descriptor Table, Available Ring and Used Ring; for packed virtqueues layout, descriptor group contains Descriptor Ring, Driver and Device Event Suppression structures.
The group ID for a dedicated descriptor group can be obtained through a new .get_vq_desc_group() op. If driver implements this op, it means that the descriptor, device and driver areas of the virtqueue may reside in a dedicated group than where its buffers reside, a.k.a the default virtqueue group through the .get_vq_group() op.
In principle, the descriptor group may or may not have same group ID as the default group. Even if the descriptor group has a different ID, meaning the vq's descriptor group areas can optionally move to a separate address space than where guest memory resides, the descriptor group may still start from a default address space, same as where its buffers reside. To move the descriptor group to a different address space, .set_group_asid() has to be called to change the ASID binding for the group, which is no different than what needs to be done on any other virtqueue group. On the other hand, the .reset() semantics also applies on descriptor table group, meaning the device reset will clear all ASID bindings and move all virtqueue groups including descriptor group back to the default address space, i.e. in ASID 0.
QEMU's shadow virtqueue is going to utilize dedicated descriptor group to speed up map and unmap operations, yielding tremendous downtime reduction by avoiding the full and slow remap cycle in SVQ switching.
Message-Id: <[email protected]>
Stable-dep-of: ccb1dc7c527f ("vhost/vdpa: reject VRING_NUM larger than device max")
--- include/linux/vdpa.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/linux/vdpa.h +11 -0
@@ -204,6 +204,16 @@ struct vdpa_map_file {* @vdev: vdpa device * @idx: virtqueue index * Returns u32: group id for this virtqueue +* @get_vq_desc_group: Get the group id for the descriptor table of +* a specific virtqueue (optional) +* @vdev: vdpa device +* @idx: virtqueue index +* Returns u32: group id for the descriptor table +* portion of this virtqueue. Could be different +* than the one from @get_vq_group, in which case +* the access to the descriptor table can be +* confined to a separate asid, isolating from +* the virtqueue's buffer address access. * @get_device_features: Get virtio features supported by the device * @vdev: vdpa device * Returns the virtio features support by the
@@ -360,6 +370,7 @@ struct vdpa_config_ops {/* Device ops */ u32 (*get_vq_align)(struct vdpa_device *vdev);u32 (*get_vq_group)(struct vdpa_device *vdev,u16 idx); +u32 (*get_vq_desc_group)(struct vdpa_device *vdev,u16 idx);u64 (*get_device_features)(struct vdpa_device *vdev);u64 (*get_backend_features)(const struct vdpa_device *vdev);int (*set_driver_features)(struct vdpa_device *vdev,u64 features);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 525/1193 vhost-vdpa: introduce descriptor group backend feature
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Si-Wei Liu <[email protected]>
[ Upstream commit 7db0d6027e69f47431800b510192436563ba415b ]
Userspace knows if the device has dedicated descriptor group or not by checking this feature bit.
It's only exposed if the vdpa driver backend implements the .get_vq_desc_group() operation callback. Userspace trying to negotiate this feature when it or the dependent _F_IOTLB_ASID feature hasn't been exposed will result in an error.
Message-Id: <[email protected]>
Stable-dep-of: ccb1dc7c527f ("vhost/vdpa: reject VRING_NUM larger than device max")
--- drivers/vhost/vdpa.c | 17 +++++++++++++++++ include/uapi/linux/vhost_types.h | 5 +++++ 2 files changed, 22 insertions(+)
drivers/vhost/vdpa.c +17 -0
@@ -387,6 +387,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; } +static bool vhost_vdpa_has_desc_group (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return ops->get_vq_desc_group; +} +static long vhost_vdpa_get_features (struct vhost_vdpa *v,u64 __user *featurep) {struct vdpa_device *vdpa = v->vdpa;
@@ -699,6 +707,7 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,if (copy_from_user (&features, featurep,sizeof (features)))return -EFAULT ;if (features & ~(VHOST_VDPA_BACKEND_FEATURES | +BIT_ULL (VHOST_BACKEND_F_DESC_ASID ) |BIT_ULL (VHOST_BACKEND_F_SUSPEND ) |BIT_ULL (VHOST_BACKEND_F_RESUME ) |BIT_ULL (VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK )))
@@ -709,6 +718,12 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,if ((features &BIT_ULL (VHOST_BACKEND_F_RESUME )) && !vhost_vdpa_can_resume (v))return -EOPNOTSUPP ; +if ((features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID )) && + !(features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) +return -EINVAL ; +if ((features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID )) && + !vhost_vdpa_has_desc_group (v)) +return -EOPNOTSUPP ;vhost_set_backend_features (&v->vdev, features);return 0 ; }
@@ -762,6 +777,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, features |=BIT_ULL (VHOST_BACKEND_F_SUSPEND );if (vhost_vdpa_can_resume (v)) features |=BIT_ULL (VHOST_BACKEND_F_RESUME ); +if (vhost_vdpa_has_desc_group (v)) + features |=BIT_ULL (VHOST_BACKEND_F_DESC_ASID ); features |=vhost_vdpa_get_backend_features (v);if (copy_to_user (featurep, &features,sizeof (features))) r = -EFAULT ;
include/uapi/linux/vhost_types.h +5 -0
@@ -185,5 +185,10 @@ struct vhost_vdpa_iova_range {* DRIVER_OK */ #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device may expose the virtqueue's descriptor area, driver area and +* device area to a different group for ASID binding than where its +* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. +*/ +#define VHOST_BACKEND_F_DESC_ASID 0x7#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 526/1193 vdpa: introduce .reset_map operation callback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Si-Wei Liu <[email protected]>
[ Upstream commit d2cf1b6e3b85dcb2bb3e8cd7924beede34fbbf0e ]
Some device specific IOMMU parent drivers have long standing bogus behavior that mistakenly clean up the maps during .reset. By definition, this is violation to the on-chip IOMMU ops (i.e. .set_map, or .dma_map & .dma_unmap) in those offending drivers, as the removal of internal maps is completely agnostic to the upper layer, causing inconsistent view between the userspace and the kernel. Some userspace app like QEMU gets around of this brokenness by proactively removing and adding back all the maps around vdpa device reset, but such workaround actually penalize other well-behaved driver setup, where vdpa reset always comes with the associated mapping cost, especially for kernel vDPA devices (use_va=false) that have high cost on pinning. It's imperative to rectify this behavior and remove the problematic code from all those non-compliant parent drivers.
The reason why a separate .reset_map op is introduced is because this allows a simple on-chip IOMMU model without exposing too much device implementation detail to the upper vdpa layer. The .dma_map/unmap or .set_map driver API is meant to be used to manipulate the IOTLB mappings, and has been abstracted in a way similar to how a real IOMMU device maps or unmaps pages for certain memory ranges. However, apart from this there also exists other mapping needs, in which case 1:1 passthrough mapping has to be used by other users (read virtio-vdpa). To ease parent/vendor driver implementation and to avoid abusing DMA ops in an unexpacted way, these on-chip IOMMU devices can start with 1:1 passthrough mapping mode initially at the time of creation. Then the .reset_map op can be used to switch iotlb back to this initial state without having to expose a complex two-dimensional IOMMU device model.
The .reset_map is not a MUST for every parent that implements the .dma_map or .set_map API, because device may work with DMA ops directly by implement their own to manipulate system memory mappings, so don't have to use .reset_map to achieve a simple IOMMU device model for 1:1 passthrough mapping.
Message-Id: <[email protected]>
Stable-dep-of: ccb1dc7c527f ("vhost/vdpa: reject VRING_NUM larger than device max")
--- include/linux/vdpa.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/vdpa.h +10 -0
@@ -327,6 +327,15 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping to the default +* state (optional) +* Needed for devices that are using device +* specific DMA translation and prefer mapping +* to be decoupled from the virtio life cycle, +* i.e. device .reset op does not reset mapping +* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device
@@ -405,6 +414,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque);int (*dma_unmap)(struct vdpa_device *vdev,unsigned int asid,u64 iova,u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 527/1193 vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Si-Wei Liu <[email protected]>
[ Upstream commit 4398776f7a6d532c466f9e41f601c9a291fac5ef ]
Userspace needs this feature flag to distinguish if vhost-vdpa iotlb in the kernel can be trusted to persist IOTLB mapping across vDPA reset. Without it, userspace has no way to tell apart if it's running on an older kernel, which could silently drop all iotlb mapping across vDPA reset, especially with broken parent driver implementation for the .reset driver op. The broken driver may incorrectly drop all mappings of its own as part of .reset, which inadvertently ends up with corrupted mapping state between vhost-vdpa userspace and the kernel. As a workaround, to make the mapping behaviour predictable across reset, userspace has to pro-actively remove all mappings before vDPA reset, and then restore all the mappings afterwards. This workaround is done unconditionally on top of all parent drivers today, due to the parent driver implementation issue and no means to differentiate. This workaround had been utilized in QEMU since day one when the corresponding vhost-vdpa userspace backend came to the world.
There are 3 cases that backend may claim this feature bit on for:
- parent device that has to work with platform IOMMU
- parent device with on-chip IOMMU that has the expected .reset_map support in driver
- parent device with vendor specific IOMMU implementation with persistent IOTLB mapping already that has to specifically declare this backend feature
The reason why .reset_map is being one of the pre-condition for persistent iotlb is because without it, vhost-vdpa can't switch back iotlb to the initial state later on, especially for the on-chip IOMMU case which starts with identity mapping at device creation. virtio-vdpa requires on-chip IOMMU to perform 1:1 passthrough translation from PA to IOVA as-is to begin with, and .reset_map is the only means to turn back iotlb to the identity mapping mode after vhost-vdpa is gone.
The difference in behavior did not matter as QEMU unmaps all the memory unregistering the memory listener at vhost_vdpa_dev_start( started = false), but the backend acknowledging this feature flag allows QEMU to make sure it is safe to skip this unmap & map in the case of vhost stop & start cycle.
In that sense, this feature flag is actually a signal for userspace to know that the driver bug has been solved. Not offering it indicates that userspace cannot trust the kernel will retain the maps.
Message-Id: <[email protected]>
Stable-dep-of: ccb1dc7c527f ("vhost/vdpa: reject VRING_NUM larger than device max")
--- drivers/vhost/vdpa.c | 15 +++++++++++++++ include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+)
drivers/vhost/vdpa.c +15 -0
@@ -420,6 +420,15 @@ static u64 vhost_vdpa_get_backend_features(const struct vhost_vdpa *v)return ops->get_backend_features (vdpa); } +static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map || +vhost_vdpa_get_backend_features (v) &BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST ); +} +static long vhost_vdpa_set_features (struct vhost_vdpa *v,u64 __user *featurep) {struct vdpa_device *vdpa = v->vdpa;
@@ -708,6 +717,7 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,return -EFAULT ;if (features & ~(VHOST_VDPA_BACKEND_FEATURES |BIT_ULL (VHOST_BACKEND_F_DESC_ASID ) | +BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST ) |BIT_ULL (VHOST_BACKEND_F_SUSPEND ) |BIT_ULL (VHOST_BACKEND_F_RESUME ) |BIT_ULL (VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK )))
@@ -724,6 +734,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,if ((features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID )) && !vhost_vdpa_has_desc_group (v))return -EOPNOTSUPP ; +if ((features &BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST )) && + !vhost_vdpa_has_persistent_map (v)) +return -EOPNOTSUPP ;vhost_set_backend_features (&v->vdev, features);return 0 ; }
@@ -779,6 +792,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, features |=BIT_ULL (VHOST_BACKEND_F_RESUME );if (vhost_vdpa_has_desc_group (v)) features |=BIT_ULL (VHOST_BACKEND_F_DESC_ASID ); +if (vhost_vdpa_has_persistent_map (v)) + features |=BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST ); features |=vhost_vdpa_get_backend_features (v);if (copy_to_user (featurep, &features,sizeof (features))) r = -EFAULT ;
include/uapi/linux/vhost_types.h +2 -0
@@ -190,5 +190,7 @@ struct vhost_vdpa_iova_range {* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. */ #define VHOST_BACKEND_F_DESC_ASID 0x7 +/* IOTLB don't flush memory mapping across device reset */ +#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 528/1193 vdpa: introduce .compat_reset operation callback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Si-Wei Liu <[email protected]>
[ Upstream commit a26f2e4e68ee3130e5d5acb4f58807041aaea905 ]
Some device specific IOMMU parent drivers have long standing bogus behaviour that mistakenly clean up the maps during .reset. By definition, this is violation to the on-chip IOMMU ops (i.e. .set_map, or .dma_map & .dma_unmap) in those offending drivers, as the removal of internal maps is completely agnostic to the upper layer, causing inconsistent view between the userspace and the kernel. Some userspace app like QEMU gets around of this brokenness by proactively removing and adding back all the maps around vdpa device reset, but such workaround actually penaltize other well-behaved driver setup, where vdpa reset always comes with the associated mapping cost, especially for kernel vDPA devices (use_va=false) that have high cost on pinning. It's imperative to rectify this behaviour and remove the problematic code from all those non-compliant parent drivers.
However, we cannot unconditionally remove the bogus map-cleaning code from the buggy .reset implementation, as there might exist userspace apps that already rely on the behaviour on some setup. Introduce a .compat_reset driver op to keep compatibility with older userspace. New and well behaved parent driver should not bother to implement such op, but only those drivers that are doing or used to do non-compliant map-cleaning reset will have to.
Message-Id: <[email protected]>
Stable-dep-of: ccb1dc7c527f ("vhost/vdpa: reject VRING_NUM larger than device max")
--- include/linux/vdpa.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/vdpa.h +13 -0
@@ -252,6 +252,17 @@ struct vdpa_map_file {* @reset: Reset device * @vdev: vdpa device * Returns integer: success (0) or error (< 0) +* @compat_reset: Reset device with compatibility quirks to +* accommodate older userspace. Only needed by +* parent driver which used to have bogus reset +* behaviour, and has to maintain such behaviour +* for compatibility with older userspace. +* Historically compliant driver only has to +* implement .reset, Historically non-compliant +* driver should implement both. +* @vdev: vdpa device +* @flags: compatibility quirks for reset +* Returns integer: success (0) or error (< 0) * @suspend: Suspend the device (optional) * @vdev: vdpa device * Returns integer: success (0) or error (< 0)
@@ -393,6 +404,8 @@ struct vdpa_config_ops {u8 (*get_status)(struct vdpa_device *vdev);void (*set_status)(struct vdpa_device *vdev,u8 status);int (*reset)(struct vdpa_device *vdev); +int (*compat_reset)(struct vdpa_device *vdev,u32 flags); +#define VDPA_RESET_F_CLEAN_MAP 1int (*suspend)(struct vdpa_device *vdev);int (*resume)(struct vdpa_device *vdev);size_t (*get_config_size)(struct vdpa_device *vdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 529/1193 vhost-vdpa: clean iotlb map during reset for older userspace
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Si-Wei Liu <[email protected]>
[ Upstream commit bc91df5c70ac720eca18bd1f4a288f2582713d3e ]
Using .compat_reset op from the previous patch, the buggy .reset behaviour can be kept as-is on older userspace apps, which don't ack the IOTLB_PERSIST backend feature. As this compatibility quirk is limited to those drivers that used to be buggy in the past, it won't affect change the behaviour or affect ABI on the setups with API compliant driver.
The separation of .compat_reset from the regular .reset allows vhost-vdpa able to know which driver had broken behaviour before, so it can apply the corresponding compatibility quirk to the individual driver whenever needed. Compared to overloading the existing .reset with flags, .compat_reset won't cause any extra burden to the implementation of every compliant driver.
[mst: squashed in two fixup commits]
Message-Id: <[email protected]>
Message-Id: <[email protected]>
Message-Id: <[email protected]>
Stable-dep-of: ccb1dc7c527f ("vhost/vdpa: reject VRING_NUM larger than device max")
--- drivers/vhost/vdpa.c | 20 ++++++++++++++++---- drivers/virtio/virtio_vdpa.c | 2 +- include/linux/vdpa.h | 7 +++++-- 3 files changed, 22 insertions(+), 7 deletions(-)
drivers/vhost/vdpa.c +16 -4
@@ -208,13 +208,24 @@ static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)irq_bypass_unregister_producer (&vq->call_ctx.producer); } -static int vhost_vdpa_reset (struct vhost_vdpa *v) +static int _compat_vdpa_reset (struct vhost_vdpa *v) {struct vdpa_device *vdpa = v->vdpa; +u32 flags =0 ; - v->in_batch =0 ; +if (v->vdev.vqs) { + flags |= !vhost_backend_has_feature (v->vdev.vqs[0 ], +VHOST_BACKEND_F_IOTLB_PERSIST ) ? +VDPA_RESET_F_CLEAN_MAP :0 ; + } + +return vdpa_reset (vdpa, flags); +} -return vdpa_reset (vdpa); +static int vhost_vdpa_reset (struct vhost_vdpa *v) +{ + v->in_batch =0 ; +return _compat_vdpa_reset (v); }static long vhost_vdpa_bind_mm (struct vhost_vdpa *v)
@@ -293,7 +304,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)vhost_vdpa_unsetup_vq_irq (v, i);if (status ==0 ) { - ret =vdpa_reset (vdpa); + ret =_compat_vdpa_reset (v);if (ret)return ret; }else
@@ -1333,6 +1344,7 @@ static void vhost_vdpa_cleanup(struct vhost_vdpa *v)vhost_vdpa_free_domain (v);vhost_dev_cleanup (&v->vdev);kfree (v->vdev.vqs); + v->vdev.vqs =NULL ; }static int vhost_vdpa_open (struct inode *inode,struct file *filep)
drivers/virtio/virtio_vdpa.c +1 -1
@@ -100,7 +100,7 @@ static void virtio_vdpa_reset(struct virtio_device *vdev) {struct vdpa_device *vdpa =vd_get_vdpa (vdev); -vdpa_reset (vdpa); +vdpa_reset (vdpa,0 ); }static bool virtio_vdpa_notify (struct virtqueue *vq)
include/linux/vdpa.h +5 -2
@@ -519,14 +519,17 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev)return vdev->dma_dev; } -static inline int vdpa_reset (struct vdpa_device *vdev) +static inline int vdpa_reset (struct vdpa_device *vdev,u32 flags) {const struct vdpa_config_ops *ops = vdev->config;int ret;down_write (&vdev->cf_lock); vdev->features_valid = false; - ret = ops->reset (vdev); +if (ops->compat_reset && flags) + ret = ops->compat_reset (vdev, flags); +else + ret = ops->reset (vdev);up_write (&vdev->cf_lock);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 530/1193 vhost/vdpa: reject VRING_NUM larger than device max
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit ccb1dc7c527f8c925925cf92afc76ae590dac311 ]
vhost_vring_set_num() accepts any non-zero power-of-two queue size that fits in 16 bits. vhost-vdpa then passes that value to set_vq_num() without comparing it with get_vq_num_max().
A process with access to /dev/vhost-vdpa-* can therefore configure a queue larger than the device advertises. With vdpa_sim, the worker can walk descriptors beyond the mapped descriptor ring. KASAN reports a 16-byte out-of-bounds read, corresponding to one vring_desc, in the vringh IOTLB path:
BUG: KASAN: out-of-bounds in _copy_from_iter Read of size 16 copy_from_iotlb copydesc_iotlb vringh_getdesc_iotlb vdpasim_net_work
Cache get_vq_num_max() immediately after reset. Some backends derive it from writable queue-size state, so querying it after SET_NUM may return the current size instead of the device capability. Invalidate the cached value before reset so a failed reset leaves SET_NUM disabled.
For VHOST_SET_VRING_NUM, copy the complete vring state once and use the same index and size for validation, vq->num, and set_vq_num(). This ensures that validation and use operate on the same copied values.
Message-ID: <[email protected]>
--- drivers/vhost/vdpa.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-)
drivers/vhost/vdpa.c +37 -7
@@ -53,6 +53,7 @@ struct vhost_vdpa {struct cdev cdev;atomic_t opened;u32 nvqs; +u16 vq_num_max;int virtio_id;int minor;struct eventfd_ctx *config_ctx;
@@ -211,7 +212,9 @@ static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)static int _compat_vdpa_reset (struct vhost_vdpa *v) {struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config;u32 flags =0 ; +int ret;if (v->vdev.vqs) { flags |= !vhost_backend_has_feature(v->vdev.vqs[0],
@@ -219,7 +222,14 @@ static int _compat_vdpa_reset(struct vhost_vdpa *v) VDPA_RESET_F_CLEAN_MAP :0 ; } -return vdpa_reset (vdpa, flags); + v->vq_num_max =0 ; + ret =vdpa_reset (vdpa, flags); +if (!ret) { +/* Some backends derive the max from mutable queue state. */ + v->vq_num_max = ops->get_vq_num_max (vdpa); + } + +return ret; }static int vhost_vdpa_reset (struct vhost_vdpa *v)
@@ -605,9 +615,15 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,u32 idx;long r; - r =get_user (idx, (u32 __user *)argp); -if (r <0 ) -return r; +if (cmd ==VHOST_SET_VRING_NUM ) { +if (copy_from_user (&s, argp,sizeof (s))) +return -EFAULT ; + idx = s.index; + }else { + r =get_user (idx, (u32 __user *)argp); +if (r <0 ) +return r; + }if (idx >= v->nvqs)return -ENOBUFS ;
@@ -616,6 +632,23 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, vq = &v->vqs[idx];switch (cmd) { +case VHOST_SET_VRING_NUM : +mutex_lock (&vq->mutex); +if (vq->private_data) { + r = -EBUSY ; + }else if (!s.num || s.num >0xffff || + s.num > v->vq_num_max || + (s.num & (s.num -1 ))) { + r = -EINVAL ; + }else { + vq->num = s.num; + r =0 ; + } +mutex_unlock (&vq->mutex); +if (r) +return r; + ops->set_vq_num (vdpa, idx, s.num); +return 0 ;case VHOST_VDPA_SET_VRING_ENABLE :if (copy_from_user (&s, argp,sizeof (s)))return -EFAULT ;
@@ -705,9 +738,6 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, ops->set_vq_cb (vdpa, idx, &cb);break ; -case VHOST_SET_VRING_NUM : - ops->set_vq_num (vdpa, idx, vq->num); -break ; }return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 531/1193 vhost-vdpa: dont install the eventfd_ctx_fdget() error in config_ctx
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Zhang <[email protected]>
[ Upstream commit e74a9fa50749b9940b4fb13199652325e08d3c4a ]
vhost_vdpa_set_config_call() swaps the eventfd_ctx_fdget() return value into v->config_ctx before checking it, so on failure the field briefly holds an ERR_PTR:
ctx = fd == VHOST_FILE_UNBIND ? NULL : eventfd_ctx_fdget(fd);
swap(ctx, v->config_ctx);
if (!IS_ERR_OR_NULL(ctx))
eventfd_ctx_put(ctx);
if (IS_ERR(v->config_ctx)) {
long ret = PTR_ERR(v->config_ctx);
v->config_ctx = NULL;
return ret;
}Commit 0bde59c1723a ("vhost-vdpa: set v->config_ctx to NULL if eventfd_ctx_fdget() fails") added that clearing, and spelled out the invariant the rest of the file relies on: "we consider 'v->config_ctx' valid if it is not NULL". The window between the swap and the clearing still breaks it. vhost_vdpa_config_cb() only tests for NULL, so a config interrupt delivered inside the window hands the ERR_PTR to eventfd_signal().
Check the fd before installing it instead. That closes the window and matches how vhost_vring_ioctl() handles the same failure for the vq call fd.
It also stops a rejected fd from tearing down a config interrupt that was
working: until now the swap replaced the live context and put it, so after an EBADF the device silently stopped delivering config interrupts until userspace installed a new fd.
Message-ID: <[email protected]>
--- drivers/vhost/vdpa.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/vhost/vdpa.c +4 -8
@@ -519,18 +519,14 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)return -EFAULT ; ctx = fd ==VHOST_FILE_UNBIND ?NULL :eventfd_ctx_fdget (fd); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); +swap (ctx, v->config_ctx); -if (!IS_ERR_OR_NULL (ctx)) +if (ctx)eventfd_ctx_put (ctx); -if (IS_ERR (v->config_ctx)) { -long ret =PTR_ERR (v->config_ctx); - - v->config_ctx =NULL ; -return ret; - } - v->vdpa->config->set_config_cb (v->vdpa, &cb);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 532/1193 vdpa_sim_blk: reject out-of-range sector starts
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit 0a8693f00c408d85f086ad85d29e7030bf1e2055 ]
vdpasim_blk_check_range() logs an invalid start sector but continues validating the request. The subsequent unsigned capacity subtraction can underflow and let an out-of-range buffer offset reach the data path.
The invalid offset is used by three request paths. VIRTIO_BLK_T_OUT copies guest data to blk->buffer + offset through vringh_iov_pull_iotlb(), causing an out-of-bounds write in _copy_from_iter() or memcpy(). VIRTIO_BLK_T_IN copies from blk->buffer + offset to the guest through vringh_iov_push_iotlb(), causing an out-of-bounds read in _copy_to_iter(). VIRTIO_BLK_T_WRITE_ZEROES passes blk->buffer + offset to memset(), causing an out-of-bounds write.
Reject starts at or beyond the capacity before the subtraction. Treat the capacity boundary as invalid because the IN and OUT paths round byte counts down to sectors for validation but later copy the original byte counts. A sub-sector request at the capacity boundary would otherwise still access past the end of the buffer.
I found this bug myself, though the patch was written with AI assistance.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +2 -1
@@ -79,10 +79,11 @@ static void vdpasim_blk_buffer_unlock(struct vdpasim_blk *blk)static bool vdpasim_blk_check_range (struct vdpasim *vdpasim,u64 start_sector,u64 num_sectors,u64 max_sectors) { -if (start_sector >VDPASIM_BLK_CAPACITY ) { +if (start_sector >=VDPASIM_BLK_CAPACITY ) {dev_dbg (&vdpasim->vdpa.dev,"starting sector exceeds the capacity - start: 0x%llx capacity: 0x%x\n" , start_sector,VDPASIM_BLK_CAPACITY ); +return false; }if (num_sectors > max_sectors) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 533/1193 vdpa_sim_net: check TX pull result before RX copy
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit 0d195797a80b77f2ec56718cd26d3ee65d0093e8 ]
vringh_iov_pull_iotlb() returns a signed byte count. A failed TX pull is currently added to the unsigned byte counter and then passed as a size_t length to receive_filter() and vringh_iov_push_iotlb(). A negative error can therefore become a large length in the RX path.
Handle non-positive pull results before every length use. Count the TX error and complete the consumed TX descriptor with zero bytes.
I found this bug myself, though the patch was written with AI assistance.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +6 -1
@@ -225,10 +225,15 @@ static void vdpasim_net_work(struct vdpasim *vdpasim)break ; } - ++tx_pkts; read =vringh_iov_pull_iotlb (&txq->vring, &txq->out_iov, net->buffer,PAGE_SIZE ); +if (read <=0 ) { + ++tx_errors; +vdpasim_net_complete (txq,0 ); +continue ; + } + ++tx_pkts; tx_bytes += read;if (!receive_filter (vdpasim, read)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 534/1193 virtio-pci: return IRQ_HANDLED after non-zero ISR
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Stellman <[email protected]>
[ Upstream commit 93fa09455fb1a9624b73d42ac1f83771f4818e80 ]
vp_interrupt() reads the ISR before dispatching config-change and vring handling. Reading the ISR also clears it, so once the read returns non-zero the interrupt was from this device and has already been consumed.
Currently vp_interrupt() returns the result of vp_vring_interrupt(). For a config-change interrupt with no vring work, that can return IRQ_NONE even though the ISR was non-zero and the interrupt was handled.
Call vp_vring_interrupt() for any queue work, but once the ISR is non-zero return IRQ_HANDLED.
Tested with QEMU virtio-blk-pci forced to INTx using vectors=0 and pci=nomsi. On an idle device, 200 config-change interrupts were generated using QMP block_resize.
Before this change, irq_handler_exit reported ret=unhandled and /proc/irq/11/spurious increased from 0 to 200 unhandled interrupts. After this change, irq_handler_exit reported ret=handled and the unhandled count remained at 0.
The issue was found during an LLM-assisted Quality Playbook review.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_pci_common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.c +3 -1
@@ -96,7 +96,9 @@ static irqreturn_t vp_interrupt(int irq, void *opaque)if (isr &VIRTIO_PCI_ISR_CONFIG )vp_config_changed (irq, opaque); -return vp_vring_interrupt (irq, opaque); +vp_vring_interrupt (irq, opaque); + +return IRQ_HANDLED ; } static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 535/1193 virtio_input: reset device if input_register_device() fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiong Weimin <[email protected]>
[ Upstream commit 81489b32a21c9360f8750d1fb600155d27452e19 ]
Probe marks the device DRIVER_OK with virtio_device_ready() before calling input_register_device(). If registration fails, the error path cleared vi->ready and called del_vqs() while the device was still live, so the device could keep DMA to queues that were already torn down.
Match remove/freeze: call virtio_reset_device() on that path before tearing down the virtqueues.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_input.c | 1 + 1 file changed, 1 insertion(+)
drivers/virtio/virtio_input.c +1 -0
@@ -327,6 +327,7 @@ static int virtinput_probe(struct virtio_device *vdev)spin_lock_irqsave (&vi->lock, flags); vi->ready = false;spin_unlock_irqrestore (&vi->lock, flags); +virtio_reset_device (vdev); err_mt_init_slots:input_free_device (vi->idev); err_input_alloc:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 536/1193 virtio_input: stop callbacks before unregistering input device
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit d7808b37da0a619cf1fa541c2384e783fecc2480 ]
virtinput_remove() unregisters the input device before resetting the virtio device. virtinput_recv_events() drops vi->lock around input_event(), so clearing vi->ready does not stop a callback that passed the entry check. It can still use vi->idev, requeue buffers and kick the queue.
Reset first, as virtinput_freeze() already does. With the preceding core change, reset waits for callbacks before input_unregister_device() can free vi->idev. Recheck vi->ready after taking the lock again: keep draining completed events so an input packet is not truncated, but stop requeueing buffers and kicking the queue.
With evdev attached, input_unregister_handle() currently waits for an RCU grace period, which also waits out IRQ callbacks. This masks the lifetime bug on PCI and MMIO, but does not protect sleepable callbacks on other transports.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_input.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/virtio/virtio_input.c +6 -2
@@ -46,9 +46,12 @@ static void virtinput_recv_events(struct virtqueue *vq)le16_to_cpu (event->code), le32_to_cpu(event->value));spin_lock_irqsave (&vi->lock, flags); +if (!vi->ready) +continue ;virtinput_queue_evtbuf (vi, event); } -virtqueue_kick (vq); +if (vi->ready) +virtqueue_kick (vq); }spin_unlock_irqrestore (&vi->lock, flags); }
@@ -347,8 +350,9 @@ static void virtinput_remove(struct virtio_device *vdev) vi->ready = false;spin_unlock_irqrestore (&vi->lock, flags); -input_unregister_device (vi->idev); +/* Callbacks use vi->idev. */ virtio_reset_device (vdev); +input_unregister_device (vi->idev);while ((buf =virtqueue_detach_unused_buf (vi->sts)) !=NULL )kfree (buf); vdev->config->del_vqs (vdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 537/1193 ipv6: lockless IPV6_UNICAST_HOPS implementation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit b0adfba7ee770fef20b1b6d86706c28f7fccfb07 ]
Some np->hop_limit accesses are racy, when socket lock is not held.
Add missing annotations and switch to full lockless implementation.
Stable-dep-of: 0ae10b6be49b ("net: ipv6: Fix UDP length overflow with PMTU discover and big MTU")
--- include/linux/ipv6.h | 12 +----------- include/net/ipv6.h | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/ipv6_sockglue.c | 20 +++++++++++--------- net/ipv6/mcast.c | 2 +- net/ipv6/ndisc.c | 2 +- 6 files changed, 16 insertions(+), 24 deletions(-)
include/linux/ipv6.h +1 -11
@@ -213,17 +213,7 @@ struct ipv6_pinfo {__be32 flow_label;__u32 frag_size; -/* -* Packed in 16bits. -* Omit one shift by putting the signed field at MSB. -*/ -#if defined(__BIG_ENDIAN_BITFIELD) - __s16 hop_limit:9; - __u16 __unused_1:7; -#else - __u16 __unused_1:7; - __s16 hop_limit:9; -#endif +s16 hop_limit;#if defined(__BIG_ENDIAN_BITFIELD)/* Packed in 16bits. */
include/net/ipv6.h +1 -1
@@ -916,7 +916,7 @@ static inline int ip6_sk_dst_hoplimit(stif (ipv6_addr_is_multicast (&fl6->daddr)) hlimit = np->mcast_hops;else - hlimit = np->hop_limit; + hlimit =READ_ONCE (np->hop_limit);if (hlimit <0 ) hlimit =ip6_dst_hoplimit (dst);return hlimit;
net/ipv6/ip6_output.c +1 -1
@@ -328,7 +328,7 @@ int ip6_xmit(const struct sock *sk, stru* Fill in the IPv6 header */ if (np) - hlimit = np->hop_limit; + hlimit =READ_ONCE (np->hop_limit);if (hlimit <0 ) hlimit =ip6_dst_hoplimit (dst);
net/ipv6/ipv6_sockglue.c +11 -9
@@ -414,6 +414,16 @@ int do_ipv6_setsockopt(struct sock *sk,if (ip6_mroute_opt (optname))return ip6_mroute_setsockopt (sk, optname, optval, optlen); +/* Handle options that can be set without locking the socket. */ +switch (optname) { +case IPV6_UNICAST_HOPS : +if (optlen <sizeof (int )) +return -EINVAL ; +if (val >255 || val <-1 ) +return -EINVAL ; +WRITE_ONCE (np->hop_limit, val); +return 0 ; + }if (needs_rtnl)rtnl_lock ();sockopt_lock_sock (sk);
@@ -732,14 +742,6 @@ done: }break ; } -case IPV6_UNICAST_HOPS : -if (optlen <sizeof (int )) - goto e_inval; -if (val >255 || val <-1 ) - goto e_inval; - np->hop_limit = val; - retv =0 ; -break ;case IPV6_MULTICAST_HOPS :if (sk->sk_type ==SOCK_STREAM )
@@ -1346,7 +1348,7 @@ int do_ipv6_getsockopt(struct sock *sk,struct dst_entry *dst;if (optname ==IPV6_UNICAST_HOPS ) - val = np->hop_limit; + val =READ_ONCE (np->hop_limit);else val = np->mcast_hops;
net/ipv6/mcast.c +1 -1
@@ -1743,7 +1743,7 @@ static void ip6_mc_hdr(const struct sock hdr->payload_len =htons (len); hdr->nexthdr = proto; - hdr->hop_limit =inet6_sk (sk)->hop_limit; + hdr->hop_limit =READ_ONCE (inet6_sk (sk)->hop_limit); hdr->saddr = *saddr; hdr->daddr = *daddr;
net/ipv6/ndisc.c +1 -1
@@ -505,7 +505,7 @@ void ndisc_send_skb(struct sk_buff *skb,csum_partial (icmp6h, skb->len, 0)); -ip6_nd_hdr (skb, saddr, daddr,inet6_sk (sk)->hop_limit, skb->len); +ip6_nd_hdr (skb, saddr, daddr,READ_ONCE (inet6_sk (sk)->hop_limit), skb->len); idev =__in6_dev_get (dst->dev);IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );
Greg Kroah-Hartman
maintainerPATCH 538/1193 ipv6: lockless IPV6_MULTICAST_LOOP implementation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit d986f52124e062753e33b6fe303be5904a997eac ]
Add inet6_{test|set|clear|assign}_bit() helpers.
Note that I am using bits from inet->inet_flags, this might change in the future if we need more flags.
While solving data-races accessing np->mc_loop, this patch also allows to implement lockless accesses to np->mcast_hops in the following patch.
Also constify sk_mc_loop() argument.
Stable-dep-of: 0ae10b6be49b ("net: ipv6: Fix UDP length overflow with PMTU discover and big MTU")
--- include/linux/ipv6.h | 18 ++++++++++++++---- include/net/inet_sock.h | 1 + include/net/sock.h | 2 +- net/core/sock.c | 4 ++-- net/ipv6/af_inet6.c | 2 +- net/ipv6/ipv6_sockglue.c | 18 ++++++++---------- net/ipv6/ndisc.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 8 ++------ 8 files changed, 30 insertions(+), 25 deletions(-)
include/linux/ipv6.h +14 -4
@@ -218,11 +218,9 @@ struct ipv6_pinfo {#if defined(__BIG_ENDIAN_BITFIELD)/* Packed in 16bits. */ __s16 mcast_hops:9; - __u16 __unused_2:6, - mc_loop:1; + __u16 __unused_2:7,#else - __u16 mc_loop:1, - __unused_2:6; + __u16 __unused_2:7; __s16 mcast_hops:9;#endif int ucast_oif;
@@ -283,6 +281,18 @@ struct ipv6_pinfo {struct inet6_cork cork; }; +/* We currently use available bits from inet_sk(sk)->inet_flags, +* this could change in the future. +*/ +#define inet6_test_bit (nr, sk) \ + test_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags) +#define inet6_set_bit (nr, sk) \ + set_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags) +#define inet6_clear_bit (nr, sk) \ + clear_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags) +#define inet6_assign_bit (nr, sk, val) \ + assign_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags, val) +/* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */ struct raw6_sock {/* inet_sock has to be the first member of raw6_sock */
include/net/inet_sock.h +1 -0
@@ -268,6 +268,7 @@ enum {INET_FLAGS_NODEFRAG =17 ,INET_FLAGS_BIND_ADDRESS_NO_PORT =18 ,INET_FLAGS_DEFER_CONNECT =19 , + INET_FLAGS_MC6_LOOP = 20, };/* cmsg flags for inet */
include/net/sock.h +1 -1
@@ -2313,7 +2313,7 @@ static inline void sock_confirm_neigh(st } } -bool sk_mc_loop (struct sock *sk); +bool sk_mc_loop (const struct sock *sk);static inline bool sk_can_gso (const struct sock *sk) {
net/core/sock.c +2 -2
@@ -761,7 +761,7 @@ out:return ret; } -bool sk_mc_loop (struct sock *sk) +bool sk_mc_loop (const struct sock *sk) {if (dev_recursion_level ())return false;
@@ -773,7 +773,7 @@ bool sk_mc_loop(struct sock *sk)return inet_test_bit (MC_LOOP , sk);#if IS_ENABLED (CONFIG_IPV6 )case AF_INET6 : -return inet6_sk (sk)->mc_loop; +return inet6_test_bit (MC6_LOOP , sk);#endif }return true;
net/ipv6/af_inet6.c +1 -1
@@ -220,7 +220,7 @@ lookup_protocol:inet_sk (sk)->pinet6 = np =inet6_sk_generic (sk); np->hop_limit =-1 ; np->mcast_hops =IPV6_DEFAULT_MCASTHOPS ; - np->mc_loop =1 ; +inet6_set_bit (MC6_LOOP , sk); np->mc_all =1 ; np->pmtudisc =IPV6_PMTUDISC_WANT ; np->repflow = net->ipv6.sysctl.flowlabel_reflect &FLOWLABEL_REFLECT_ESTABLISHED ;
net/ipv6/ipv6_sockglue.c +8 -10
@@ -423,6 +423,13 @@ int do_ipv6_setsockopt(struct sock *sk,return -EINVAL ;WRITE_ONCE (np->hop_limit, val);return 0 ; +case IPV6_MULTICAST_LOOP : +if (optlen <sizeof (int )) +return -EINVAL ; +if (val != valbool) +return -EINVAL ; +inet6_assign_bit (MC6_LOOP , sk, valbool); +return 0 ; }if (needs_rtnl)rtnl_lock ();
@@ -754,15 +761,6 @@ done: retv =0 ;break ; -case IPV6_MULTICAST_LOOP : -if (optlen <sizeof (int )) - goto e_inval; -if (val != valbool) - goto e_inval; - np->mc_loop = valbool; - retv =0 ; -break ; -case IPV6_UNICAST_IF : {struct net_device *dev =NULL ;
@@ -1366,7 +1364,7 @@ int do_ipv6_getsockopt(struct sock *sk, }case IPV6_MULTICAST_LOOP : - val = np->mc_loop; + val =inet6_test_bit (MC6_LOOP , sk);break ;case IPV6_MULTICAST_IF :
net/ipv6/ndisc.c +1 -1
@@ -2011,7 +2011,7 @@ static int __net_init ndisc_net_init(str np =inet6_sk (sk); np->hop_limit =255 ;/* Do not loopback ndisc messages */ - np->mc_loop =0 ; +inet6_clear_bit (MC6_LOOP , sk);return 0 ; }
net/netfilter/ipvs/ip_vs_sync.c +2 -6
@@ -1295,17 +1295,13 @@ static void set_sock_size(struct sock *sstatic void set_mcast_loop (struct sock *sk,u_char loop) {/* setsockopt(sock, SOL_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); */ -lock_sock (sk);inet_assign_bit (MC_LOOP , sk, loop);#ifdef CONFIG_IP_VS_IPV6 -if (sk->sk_family ==AF_INET6 ) { -struct ipv6_pinfo *np =inet6_sk (sk); - +if (READ_ONCE (sk->sk_family) ==AF_INET6 ) {/* IPV6_MULTICAST_LOOP */ - np->mc_loop = loop ?1 :0 ; +inet6_assign_bit (MC6_LOOP , sk, loop); }#endif -release_sock (sk); }/*
Greg Kroah-Hartman
maintainerPATCH 539/1193 ipv6: lockless IPV6_MULTICAST_HOPS implementation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 2da23eb07c91241d962f3ff05565065484cd8929 ]
This fixes data-races around np->mcast_hops,
and make IPV6_MULTICAST_HOPS lockless.
Note that np->mcast_hops is never negative,
thus can fit an u8 field instead of s16.
Stable-dep-of: 0ae10b6be49b ("net: ipv6: Fix UDP length overflow with PMTU discover and big MTU")
--- include/linux/ipv6.h | 9 +-------- include/net/ipv6.h | 2 +- net/dccp/ipv6.c | 2 +- net/ipv6/ipv6_sockglue.c | 28 +++++++++++++++------------- net/ipv6/tcp_ipv6.c | 3 ++- net/netfilter/ipvs/ip_vs_sync.c | 2 +- 6 files changed, 21 insertions(+), 25 deletions(-)
include/linux/ipv6.h +1 -8
@@ -214,15 +214,8 @@ struct ipv6_pinfo {__u32 frag_size;s16 hop_limit; +u8 mcast_hops; -#if defined(__BIG_ENDIAN_BITFIELD) -/* Packed in 16bits. */ - __s16 mcast_hops:9; - __u16 __unused_2:7, -#else - __u16 __unused_2:7; - __s16 mcast_hops:9; -#endif int ucast_oif;int mcast_oif;
include/net/ipv6.h +1 -1
@@ -914,7 +914,7 @@ static inline int ip6_sk_dst_hoplimit(stint hlimit;if (ipv6_addr_is_multicast (&fl6->daddr)) - hlimit = np->mcast_hops; + hlimit =READ_ONCE (np->mcast_hops);else hlimit =READ_ONCE (np->hop_limit);if (hlimit <0 )
net/dccp/ipv6.c +1 -1
@@ -677,7 +677,7 @@ ipv6_pktoptions:if (np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo) np->mcast_oif =inet6_iif (opt_skb);if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim) - np->mcast_hops =ipv6_hdr (opt_skb)->hop_limit; +WRITE_ONCE (np->mcast_hops,ipv6_hdr (opt_skb)->hop_limit);if (np->rxopt.bits.rxflow || np->rxopt.bits.rxtclass) np->rcv_flowinfo =ip6_flowinfo (ipv6_hdr (opt_skb));if (np->repflow)
net/ipv6/ipv6_sockglue.c +15 -13
@@ -430,6 +430,16 @@ int do_ipv6_setsockopt(struct sock *sk,return -EINVAL ;inet6_assign_bit (MC6_LOOP , sk, valbool);return 0 ; +case IPV6_MULTICAST_HOPS : +if (sk->sk_type ==SOCK_STREAM ) +return retv; +if (optlen <sizeof (int )) +return -EINVAL ; +if (val >255 || val <-1 ) +return -EINVAL ; +WRITE_ONCE (np->mcast_hops, + val ==-1 ?IPV6_DEFAULT_MCASTHOPS : val); +return 0 ; }if (needs_rtnl)rtnl_lock ();
@@ -750,16 +760,6 @@ done:break ; } -case IPV6_MULTICAST_HOPS : -if (sk->sk_type ==SOCK_STREAM ) -break ; -if (optlen <sizeof (int )) - goto e_inval; -if (val >255 || val <-1 ) - goto e_inval; - np->mcast_hops = (val ==-1 ?IPV6_DEFAULT_MCASTHOPS : val); - retv =0 ; -break ;case IPV6_UNICAST_IF : {
@@ -1179,7 +1179,8 @@ int do_ipv6_getsockopt(struct sock *sk,put_cmsg (&msg,SOL_IPV6 ,IPV6_PKTINFO ,sizeof (src_info), &src_info); }if (np->rxopt.bits.rxhlim) { -int hlim = np->mcast_hops; +int hlim =READ_ONCE (np->mcast_hops); +put_cmsg (&msg,SOL_IPV6 ,IPV6_HOPLIMIT ,sizeof (hlim), &hlim); }if (np->rxopt.bits.rxtclass) {
@@ -1196,7 +1197,8 @@ int do_ipv6_getsockopt(struct sock *sk,put_cmsg (&msg,SOL_IPV6 ,IPV6_2292PKTINFO ,sizeof (src_info), &src_info); }if (np->rxopt.bits.rxohlim) { -int hlim = np->mcast_hops; +int hlim =READ_ONCE (np->mcast_hops); +put_cmsg (&msg,SOL_IPV6 ,IPV6_2292HOPLIMIT ,sizeof (hlim), &hlim); }if (np->rxopt.bits.rxflow) {
@@ -1348,7 +1350,7 @@ int do_ipv6_getsockopt(struct sock *sk,if (optname ==IPV6_UNICAST_HOPS ) val =READ_ONCE (np->hop_limit);else - val = np->mcast_hops; + val =READ_ONCE (np->mcast_hops);if (val <0 ) {rcu_read_lock ();
net/ipv6/tcp_ipv6.c +2 -1
@@ -1517,7 +1517,8 @@ ipv6_pktoptions:if (np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo) np->mcast_oif =tcp_v6_iif (opt_skb);if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim) - np->mcast_hops =ipv6_hdr (opt_skb)->hop_limit; +WRITE_ONCE (np->mcast_hops, +ipv6_hdr (opt_skb)->hop_limit);if (np->rxopt.bits.rxflow || np->rxopt.bits.rxtclass) np->rcv_flowinfo =ip6_flowinfo (ipv6_hdr (opt_skb));if (np->repflow)
net/netfilter/ipvs/ip_vs_sync.c +1 -1
@@ -1319,7 +1319,7 @@ static void set_mcast_ttl(struct sock *sstruct ipv6_pinfo *np =inet6_sk (sk);/* IPV6_MULTICAST_HOPS */ - np->mcast_hops = ttl; + WRITE_ONCE(np->mcast_hops, ttl); }#endif release_sock (sk);
Greg Kroah-Hartman
maintainerPATCH 540/1193 ipv6: lockless IPV6_MTU implementation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 15f926c4457aa65b1ac83bda1bbdcaad3f48e4e7 ]
np->frag_size can be read/written without holding socket lock.
Add missing annotations and make IPV6_MTU setsockopt() lockless.
Stable-dep-of: 0ae10b6be49b ("net: ipv6: Fix UDP length overflow with PMTU discover and big MTU")
--- net/ipv6/ip6_output.c | 19 +++++++++++-------- net/ipv6/ipv6_sockglue.c | 15 +++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-)
net/ipv6/ip6_output.c +11 -8
@@ -906,9 +906,11 @@ int ip6_fragment(struct net *net, struct mtu =IPV6_MIN_MTU ; } -if (np && np->frag_size < mtu) { -if (np->frag_size) - mtu = np->frag_size; +if (np) { +u32 frag_size =READ_ONCE (np->frag_size); + +if (frag_size && frag_size < mtu) + mtu = frag_size; }if (mtu < hlen +sizeof (struct frag_hdr ) +8 ) goto fail_toobig;
@@ -1350,7 +1352,7 @@ static int ip6_setup_cork(struct sock *s struct rt6_info *rt) {struct ipv6_pinfo *np =inet6_sk (sk); -unsigned int mtu; +unsigned int mtu, frag_size;struct ipv6_txoptions *nopt, *opt = ipc6->opt;/* callers pass dst together with a reference, set it first so
@@ -1399,10 +1401,11 @@ static int ip6_setup_cork(struct sock *selse mtu = np->pmtudisc >=IPV6_PMTUDISC_PROBE ?READ_ONCE (rt->dst.dev->mtu) :dst_mtu (xfrm_dst_path (&rt->dst)); -if (np->frag_size < mtu) { -if (np->frag_size) - mtu = np->frag_size; - } + + frag_size =READ_ONCE (np->frag_size); +if (frag_size && frag_size < mtu) + mtu = frag_size; + cork->base.fragsize = mtu; cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags =0 ;
net/ipv6/ipv6_sockglue.c +7 -8
@@ -440,6 +440,13 @@ int do_ipv6_setsockopt(struct sock *sk,WRITE_ONCE (np->mcast_hops, val ==-1 ?IPV6_DEFAULT_MCASTHOPS : val);return 0 ; +case IPV6_MTU : +if (optlen <sizeof (int )) +return -EINVAL ; +if (val && val <IPV6_MIN_MTU ) +return -EINVAL ; +WRITE_ONCE (np->frag_size, val); +return 0 ; }if (needs_rtnl)rtnl_lock ();
@@ -909,14 +916,6 @@ done: np->pmtudisc = val; retv =0 ;break ; -case IPV6_MTU : -if (optlen <sizeof (int )) - goto e_inval; -if (val && val <IPV6_MIN_MTU ) - goto e_inval; - np->frag_size = val; - retv =0 ; -break ;case IPV6_RECVERR :if (optlen <sizeof (int )) goto e_inval;
Greg Kroah-Hartman
maintainerPATCH 541/1193 net: ipv6: Fix UDP length overflow with PMTU discover and big MTU
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alice Mikityanska <[email protected]>
[ Upstream commit 0ae10b6be49b425827659b23bcce498f80eb7182 ]
This commit bounds cork->base.fragsize to IP6_MAX_MTU for UDP sockets to avoid a possible overflow of UDP length that triggers a WARN in udp_set_len_short when setsockopt IPV6_MTU_DISCOVER is set to IPV6_PMTUDISC_DO or IPV6_PMTUDISC_PROBE, and a large packet is sent over a netdev with an unusually large MTU.
Steps to reproduce (included in the new selftest):
1. Set device MTU bigger than IP6_MAX_MTU. cork->base.fragsize will be set to that MTU in ip6_setup_cork.
2. Set IPV6_MTU_DISCOVER to IPV6_PMTUDISC_PROBE or IPV6_PMTUDISC_DO. It lets maxnonfragsize be set to device MTU (cork->fragsize) in __ip6_append_data, rather than to IP6_MAX_MTU.
3. Send 65528 bytes of payload (+8 bytes of UDP header, +40 bytes of IPv6 header). Device MTU allows it (it's only one byte bigger than IP6_MAX_MTU, and the device MTU is bigger than that).
4. The UDP length in the built packet is 65536, which overflows the 16-bit length field and triggers the WARN in udp_set_len_short.
To avoid breaking sending UDP jumbograms over raw IPv6 sockets, limit the change to UDP sockets only.
The original overflow bug with IPv6 and IPV6_PMTUDISC_DO seems to predate git history (verified reproduction on 2.6.21), was fixed later, and then reappeared in commit 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward"), which is chosen as the Fixes tag here. The overflow with IPV6_PMTUDISC_PROBE reproduces since its introduction in commit 628a5c561890 ("[INET]: Add IP(V6)_PMTUDISC_RPOBE").
--- net/ipv6/ip6_output.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/ip6_output.c +2 -0
@@ -1406,6 +1406,8 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,if (frag_size && frag_size < mtu) mtu = frag_size; +if (sk_is_udp (sk)) + mtu =min (mtu,IP6_MAX_MTU ); cork->base.fragsize = mtu; cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 542/1193 net: ipv6: Clamp to IP6_MAX_MTU in ip6_dst_mtu_maybe_forward
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alice Mikityanska <[email protected]>
[ Upstream commit 199271ebc71c1e0913b2fad988a7bff330a8828a ]
Commit 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward") dropped the IP6_MAX_MTU clamp that used to be present in ip6_mtu(). A similar IPv4 commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward") preserves the IP_MAX_MTU clamp.
Restore the upper bound in the IPv6 flow to avoid potential 16-bit overflows in forwarding paths.
--- include/net/ip6_route.h | 2 ++ 1 file changed, 2 insertions(+)
include/net/ip6_route.h +2 -0
@@ -339,6 +339,8 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dstrcu_read_unlock (); out: + mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); +return mtu -lwtunnel_headroom (dst->lwtstate, mtu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 543/1193 net: ethernet: cortina: Fix budget accounting
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit a0de06d0da78a3db53de65dfd7452cc6d111f703 ]
The gmac_rx() function returns the remaining NAPI budget, but its caller treats the return value as the number of packets received. An idle poll therefore reports a full budget and remains scheduled.
Return the number of received packets instead. Preserve the existing free queue refill accounting by adding that count directly; continuing to subtract it from the budget would invert the refill behavior.
--- drivers/net/ethernet/cortina/gemini.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/cortina/gemini.c +5 -3
@@ -1455,6 +1455,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)unsigned int frame_len, frag_len;struct gmac_rxdesc *rx =NULL ;struct gmac_queue_page *gpage; +unsigned int received =0 ;union gmac_rxdesc_0 word0;union gmac_rxdesc_1 word1;union gmac_rxdesc_3 word3;
@@ -1550,7 +1551,8 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)napi_gro_frags (&port->napi); skb =NULL ; frag_nr =0 ; - --budget; + budget--; + received++; }continue ;
@@ -1570,7 +1572,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) port->rx_skb = skb; port->rx_frag_nr = frag_nr;writew (r, ptr_reg); -return budget; +return received; }static int gmac_napi_poll (struct napi_struct *napi,int budget)
@@ -1591,7 +1593,7 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget) ++port->rx_napi_exits; } - port->freeq_refill += (budget - received); + port->freeq_refill += received;if (port->freeq_refill > freeq_threshold) { port->freeq_refill -= freeq_threshold;geth_fill_freeq (geth, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 544/1193 net: ethernet: cortina: Finish RX updates before NAPI completion
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit baa26841cb9a2cdc7e0e99d6854a4e3359bf7393 ]
napi_complete_done() releases ownership of the NAPI instance, but the Gemini poll keeps the RX statistics writer section open and updates the free queue after calling it. A new poll can therefore start while the old writer is still active.
Finish the statistics and free queue updates before releasing ownership. Only re-enable RX interrupts when napi_complete_done() reports successful completion.
--- drivers/net/ethernet/cortina/gemini.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/cortina/gemini.c +6 -6
@@ -1586,12 +1586,10 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)u64_stats_update_begin (&port->rx_stats_syncp); received =gmac_rx (napi->dev, budget); -if (received < budget) { -napi_gro_flush (napi, false); -napi_complete_done (napi, received); -gmac_enable_rx_irq (napi->dev,1 ); +if (received < budget) ++port->rx_napi_exits; - } + +u64_stats_update_end (&port->rx_stats_syncp); port->freeq_refill += received;if (port->freeq_refill > freeq_threshold) {
@@ -1599,7 +1597,9 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)geth_fill_freeq (geth, true); } -u64_stats_update_end (&port->rx_stats_syncp); +if (received < budget &&napi_complete_done (napi, received)) +gmac_enable_rx_irq (napi->dev,1 ); +return received; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 545/1193 net: ethernet: cortina: Count dropped frames as NAPI work
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit b856c552f556bc0341c1dbe0bf88e630fd1dc4b7 ]
The RX loop only consumes budget when it successfully delivers a frame. Error paths keep consuming descriptors without reducing the budget, so a stream of bad frames can process the entire receive ring in one poll.
Move the budget accounting to a common end-of-frame path. This counts each completed frame as NAPI work whether it was delivered or dropped, matching the behavior of the vendor driver.
--- drivers/net/ethernet/cortina/gemini.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/cortina/gemini.c +10 -5
@@ -1506,7 +1506,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) skb =NULL ; frag_nr =0 ; } -continue ; + goto next_desc; } page = gpage->page;
@@ -1528,7 +1528,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) }else if (!skb) {put_page (page); -continue ; + goto next_desc; }if (word3.bits32 &EOF_BIT )
@@ -1551,10 +1551,8 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)napi_gro_frags (&port->napi); skb =NULL ; frag_nr =0 ; - budget--; - received++; } -continue ; + goto next_desc; err_drop:if (skb) {
@@ -1567,6 +1565,13 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)put_page (page); port->stats.rx_dropped++; + +next_desc: +/* Final or single-descriptor fragment, advance things */ +if (word3.bits32 &EOF_BIT ) { + budget--; + received++; + } } port->rx_skb = skb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 546/1193 net: ethernet: cortina: No mapping is a dropped rx
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 2cb156213093a62b80cf40b1ec71738e93491971 ]
Increase stats.rx_dropped++ even if this is the first fragment (skb == NULL) so we are doing proper accounting.
Stable-dep-of: 6520198c430c ("net: ethernet: cortina: Count RX drops once per frame")
--- drivers/net/ethernet/cortina/gemini.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cortina/gemini.c +1 -1
@@ -1500,9 +1500,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) gpage =gmac_get_queue_page (geth, port, mapping +PAGE_SIZE );if (!gpage) {dev_err (geth->dev,"could not find mapping\n" ); + port->stats.rx_dropped++;if (skb) {napi_free_frags (&port->napi); - port->stats.rx_dropped++; skb =NULL ; frag_nr =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 547/1193 net: ethernet: cortina: Count RX drops once per frame
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 6520198c430c81bcc367f0dd5e32f2fb740b9d51 ]
The absence of a partial skb means either that the driver is not assembling a frame or that the current frame was already dropped. Consequently, repeated descriptor errors can increment rx_dropped more than once, while an orphaned descriptor chain can reach EOF without being counted at all.
Track the dropping state across NAPI polls. Clear it at frame boundaries and route mapping failures and orphaned continuations through the common drop path so each discarded frame is counted exactly once.
--- drivers/net/ethernet/cortina/gemini.c | 41 +++++++++++++++------------ 1 file changed, 23 insertions(+), 18 deletions(-)
drivers/net/ethernet/cortina/gemini.c +23 -18
@@ -123,6 +123,7 @@ struct gemini_ethernet_port {unsigned int rx_coalesce_nsecs;struct sk_buff *rx_skb;unsigned int rx_frag_nr; +bool rx_dropping;unsigned int freeq_refill;struct gmac_txq txq[TX_QUEUE_NUM ];
@@ -1456,6 +1457,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)struct gmac_rxdesc *rx =NULL ;struct gmac_queue_page *gpage;unsigned int received =0 ; +bool dropping = port->rx_dropping;union gmac_rxdesc_0 word0;union gmac_rxdesc_1 word1;union gmac_rxdesc_3 word3;
@@ -1477,6 +1479,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) w = rw.bits.wptr;while (budget && w != r) { + page =NULL ; rx = port->rxq_ring + r; word0 = rx->word0; word1 = rx->word1;
@@ -1490,6 +1493,16 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) frame_len = word1.bits.byte_count; page_offs = mapping & ~PAGE_MASK ; +if (word3.bits32 &SOF_BIT ) { +if (skb) { +napi_free_frags (&port->napi); + port->stats.rx_dropped++; + skb =NULL ; + frag_nr =0 ; + } + dropping = false; + } +if (!mapping) {netdev_err (netdev,"rxq[%u]: HW BUG: zero DMA desc\n" , r);
@@ -1500,24 +1513,11 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) gpage =gmac_get_queue_page (geth, port, mapping +PAGE_SIZE );if (!gpage) {dev_err (geth->dev,"could not find mapping\n" ); - port->stats.rx_dropped++; -if (skb) { -napi_free_frags (&port->napi); - skb =NULL ; - frag_nr =0 ; - } - goto next_desc; + goto err_drop; } page = gpage->page;if (word3.bits32 &SOF_BIT ) { -if (skb) { -napi_free_frags (&port->napi); - port->stats.rx_dropped++; - skb =NULL ; - frag_nr =0 ; - } - skb =gmac_skb_if_good_frame (port, word0, frame_len);if (!skb) goto err_drop;
@@ -1527,8 +1527,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) frag_nr =0 ; }else if (!skb) { -put_page (page); - goto next_desc; + goto err_drop; }if (word3.bits32 &EOF_BIT )
@@ -1561,21 +1560,26 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) frag_nr =0 ; } -if (mapping) +if (page)put_page (page); - port->stats.rx_dropped++; +if (!dropping) { + port->stats.rx_dropped++; + dropping = true; + } next_desc:/* Final or single-descriptor fragment, advance things */ if (word3.bits32 &EOF_BIT ) { budget--; received++; + dropping = false; } } port->rx_skb = skb; port->rx_frag_nr = frag_nr; + port->rx_dropping = dropping;writew (r, ptr_reg);return received; }
@@ -1906,6 +1910,7 @@ static int gmac_stop(struct net_device *netdev)napi_disable (&port->napi); port->rx_skb =NULL ; port->rx_frag_nr =0 ; + port->rx_dropping = false;gmac_enable_irq (netdev,0 );gmac_cleanup_rxq (netdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 548/1193 net: ethernet: cortina: Count RX descriptors for freeq refill
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit e89e88ad41d9f31c829c2af39c48313e8e48d5b0 ]
The software free queue provides one buffer fragment for every descriptor moved to an RX queue. The refill heuristic instead advances by NAPI work, which counts frames. A fragmented or discarded frame can consume several queue entries while adding only one to the refill count.
Count the RX descriptors as they are consumed and report that separately from NAPI work. Use the descriptor count to drive free queue refills.
--- drivers/net/ethernet/cortina/gemini.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/cortina/gemini.c +8 -3
@@ -1445,7 +1445,8 @@ static struct sk_buff *gmac_skb_if_good_frame(struct gemini_ethernet_port *port,return skb; } -static unsigned int gmac_rx (struct net_device *netdev,unsigned int budget) +static unsigned int gmac_rx (struct net_device *netdev,unsigned int budget, +unsigned int *freeq_consumed) {struct gemini_ethernet_port *port =netdev_priv (netdev);unsigned short m = (1 << port->rxq_order) -1 ;
@@ -1453,6 +1454,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)void __iomem *ptr_reg = port->rxq_rwptr;unsigned int frag_nr = port->rx_frag_nr;struct sk_buff *skb = port->rx_skb; +unsigned int consumed =0 ;unsigned int frame_len, frag_len;struct gmac_rxdesc *rx =NULL ;struct gmac_queue_page *gpage;
@@ -1488,6 +1490,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) r++; r &= m; + consumed++; frag_len = word0.bits.buffer_size; frame_len = word1.bits.byte_count;
@@ -1580,6 +1583,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget) port->rx_skb = skb; port->rx_frag_nr = frag_nr; port->rx_dropping = dropping; + *freeq_consumed = consumed;writew (r, ptr_reg);return received; }
@@ -1589,18 +1593,19 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)struct gemini_ethernet_port *port =netdev_priv (napi->dev);struct gemini_ethernet *geth = port->geth;unsigned int freeq_threshold; +unsigned int freeq_consumed;unsigned int received; freeq_threshold =1 << (geth->freeq_order -1 );u64_stats_update_begin (&port->rx_stats_syncp); - received =gmac_rx (napi->dev, budget); + received =gmac_rx (napi->dev, budget, &freeq_consumed);if (received < budget) ++port->rx_napi_exits;u64_stats_update_end (&port->rx_stats_syncp); - port->freeq_refill += received; + port->freeq_refill += freeq_consumed;if (port->freeq_refill > freeq_threshold) { port->freeq_refill -= freeq_threshold;geth_fill_freeq (geth, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/1193 drm/logicvc: Drop the select of the nonexistent CONFIG_DRM_KMS_DMA_HELPER
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit f97802dd98b27e45c04293f9926f07642578b23f ]
CONFIG_DRM_KMS_CMA_HELPER was removed by commit 09717af7d13d ("drm:
Remove CONFIG_DRM_KMS_CMA_HELPER option"). When commit 6bcfe8eaeef0 ("drm/fb: rename FB CMA helpers to FB DMA helpers") later renamed the select in this Kconfig to CONFIG_DRM_KMS_DMA_HELPER, no symbol of that name existed, and git log -S finds no Kconfig file that has defined one since. The select is silently ignored. The driver already selects CONFIG_DRM_GEM_DMA_HELPER, which is what it needs.
Remove the dead line.
--- drivers/gpu/drm/logicvc/Kconfig | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/logicvc/Kconfig +0 -1
@@ -3,7 +3,6 @@ config DRM_LOGICVC depends on DRM depends on OF || COMPILE_TEST select DRM_KMS_HELPER - select DRM_KMS_DMA_HELPER select DRM_GEM_DMA_HELPER select REGMAP select REGMAP_MMIO
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 550/1193 ALSA: hda: Introduce auto cleanup macros for PM
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 5d8c9c987fbdd65677315198c2b1f35a440d7cdf ]
The temporary power up/down of the codec via snd_hda_power_up() and _down() (or snd_hda_power_up_pm() and _down_pm()) is seen in various places. This patch introduces simple auto-cleanup macros for those call patterns, so that the drivers don't have to call the corresponding power-down calls explicitly.
Namely,
err = snd_hda_power_up(codec); if (err < 0) return err; .... snd_power_down(codec);
can drop the *_down() call by replacing with
CLASS(snd_hda_power, pm)(codec); if (pm.err < 0) return pm.err;
Stable-dep-of: 728478874312 ("ALSA: hda: Report a change when only the channel status bytes move")
--- include/sound/hda_codec.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
include/sound/hda_codec.h +30 -0
@@ -509,6 +509,36 @@ static inline bool hda_codec_need_resume(struct hda_codec *codec)return !codec->relaxed_resume && codec->jacktbl.used; } +/* +* PM with auto-cleanup: call like CLASS(snd_hda_power, pm)(codec) +* If the error handling is needed, refer pm.err. +*/ +struct __hda_power_obj { +struct hda_codec *codec; +int err; +}; + +static inline struct __hda_power_obj __snd_hda_power_up (struct hda_codec *codec) +{ +struct __hda_power_obj T = { .codec = codec }; +T .err =snd_hda_power_up (codec); +return T ; +} + +static inline struct __hda_power_obj __snd_hda_power_up_pm (struct hda_codec *codec) +{ +struct __hda_power_obj T = { .codec = codec }; +T .err =snd_hda_power_up_pm (codec); +return T ; +} + +DEFINE_CLASS(snd_hda_power, struct __hda_power_obj, +snd_hda_power_down ((_T).codec),__snd_hda_power_up (codec), + struct hda_codec *codec) +DEFINE_CLASS(snd_hda_power_pm, struct __hda_power_obj, +snd_hda_power_down_pm ((_T).codec),__snd_hda_power_up_pm (codec), + struct hda_codec *codec) +#ifdef CONFIG_SND_HDA_PATCH_LOADER /* * patch firmware
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 551/1193 ALSA: hda/common: Use cleanup macros for PM controls
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 8dad6b3dac2794c52d63b2336138392eddc17936 ]
The new macro CLASS(snd_hda_power_pm) can replace the manual snd_hda_power_up_pm() and _down() calls gracefully.
A part of the code in codec_exec_verb() is factored out to a function, so that the auto-cleanup can be well scoped.
Merely cleanups and no functional changes.
Stable-dep-of: 728478874312 ("ALSA: hda: Report a change when only the channel status bytes move")
--- sound/pci/hda/hda_codec.c | 30 +++++++++++++++++++----------- sound/pci/hda/hda_proc.c | 4 +--- sound/pci/hda/hda_sysfs.c | 11 ++++------- 3 files changed, 24 insertions(+), 21 deletions(-)
sound/pci/hda/hda_codec.c +19 -11
@@ -31,6 +31,23 @@#define codec_has_clkstop (codec) \ ((codec)->core.power_caps & AC_PWRST_CLKSTOP) +static int call_exec_verb (struct hda_bus *bus,struct hda_codec *codec, +unsigned int cmd,unsigned int flags, +unsigned int *res) +{ +int err; + +CLASS (snd_hda_power_pm, pm)(codec); +mutex_lock (&bus->core.cmd_mutex); +if (flags &HDA_RW_NO_RESPONSE_FALLBACK ) + bus->no_response_fallback =1 ; + err =snd_hdac_bus_exec_verb_unlocked (&bus->core, codec->core.addr, + cmd, res); + bus->no_response_fallback =0 ; +mutex_unlock (&bus->core.cmd_mutex); +return err; +} +/* * Send and receive a verb - passed to exec_verb override for hdac_device */
@@ -45,15 +62,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,return -1 ; again: -snd_hda_power_up_pm (codec); -mutex_lock (&bus->core.cmd_mutex); -if (flags &HDA_RW_NO_RESPONSE_FALLBACK ) - bus->no_response_fallback =1 ; - err =snd_hdac_bus_exec_verb_unlocked (&bus->core, codec->core.addr, - cmd, res); - bus->no_response_fallback =0 ; -mutex_unlock (&bus->core.cmd_mutex); -snd_hda_power_down_pm (codec); + err =call_exec_verb (bus, codec, cmd, flags, res);if (!codec_in_pm (codec) && res && err == -EAGAIN ) {if (bus->response_reset) { codec_dbg(codec,
@@ -645,12 +654,11 @@ static void hda_jackpoll_work(struct work_struct *work)return ;/* the power-up/down sequence triggers the runtime resume */ -snd_hda_power_up (codec); +CLASS (snd_hda_power, pm)(codec);/* update jacks manually if polling is required, too */ snd_hda_jack_set_dirty_all (codec);snd_hda_jack_poll_all (codec);schedule_delayed_work (&codec->jackpoll_work, codec->jackpoll_interval); -snd_hda_power_down (codec); }/* release all pincfg lists */
sound/pci/hda/hda_proc.c +1 -3
@@ -782,7 +782,7 @@ static void print_codec_info(struct snd_info_entry *entry, fg = codec->core.afg;if (!fg)return ; -snd_hda_power_up (codec); +CLASS (snd_hda_power, pm)(codec);snd_iprintf (buffer,"Default PCM:\n" );print_pcm_caps (buffer, codec, fg);snd_iprintf (buffer,"Default Amp-In caps: " );
@@ -795,7 +795,6 @@ static void print_codec_info(struct snd_info_entry *entry, nodes =snd_hda_get_sub_nodes (codec, fg, &nid);if (! nid || nodes <0 ) {snd_iprintf (buffer,"Invalid AFG subtree\n" ); -snd_hda_power_down (codec);return ; }
@@ -932,7 +931,6 @@ static void print_codec_info(struct snd_info_entry *entry,kfree (conn); } -snd_hda_power_down (codec); }/*
sound/pci/hda/hda_sysfs.c +4 -7
@@ -131,21 +131,18 @@ static int reconfig_codec(struct hda_codec *codec) {int err; -snd_hda_power_up (codec); +CLASS (snd_hda_power, pm)(codec);codec_info (codec,"hda-codec: reconfiguring\n" ); err =snd_hda_codec_reset (codec);if (err <0 ) {codec_err (codec,"The codec is being used, can't reconfigure.\n" ); - goto error; +return err; } err =device_reprobe (hda_codec_dev (codec));if (err <0 ) - goto error; - err =snd_card_register (codec->card); - error: -snd_hda_power_down (codec); -return err; +return err; +return snd_card_register (codec->card); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 552/1193 ALSA: hda/common: Use guard() for mutex locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 62dd3851d2450a5fb2259da1f0391b5870e07577 ]
Replace the manual mutex lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Stable-dep-of: 728478874312 ("ALSA: hda: Report a change when only the channel status bytes move")
--- sound/pci/hda/hda_codec.c | 89 ++++++++++++++-------------------- sound/pci/hda/hda_controller.c | 24 ++++----- sound/pci/hda/hda_sysfs.c | 66 ++++++++++--------------- 3 files changed, 74 insertions(+), 105 deletions(-)
sound/pci/hda/hda_codec.c +37 -52
@@ -38,13 +38,12 @@ static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec,int err;CLASS (snd_hda_power_pm, pm)(codec); -mutex_lock (&bus->core.cmd_mutex); +guard (mutex)(&bus->core.cmd_mutex);if (flags &HDA_RW_NO_RESPONSE_FALLBACK ) bus->no_response_fallback =1 ; err =snd_hdac_bus_exec_verb_unlocked (&bus->core, codec->core.addr, cmd, res); bus->no_response_fallback =0 ; -mutex_unlock (&bus->core.cmd_mutex);return err; }
@@ -541,11 +540,11 @@ unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)#ifdef CONFIG_SND_HDA_RECONFIG {unsigned int cfg =0 ; -mutex_lock (&codec->user_mutex); - pin =look_up_pincfg (codec, &codec->user_pins, nid); -if (pin) - cfg = pin->cfg; -mutex_unlock (&codec->user_mutex); + scoped_guard(mutex, &codec->user_mutex) { + pin =look_up_pincfg (codec, &codec->user_pins, nid); +if (pin) + cfg = pin->cfg; + }if (cfg)return cfg; }
@@ -2211,13 +2210,12 @@ static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,if (WARN_ON (codec->spdif_out.used <= idx))return -EINVAL ; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx); ucontrol->value.iec958.status[0 ] = spdif->status &0xff ; ucontrol->value.iec958.status[1 ] = (spdif->status >>8 ) &0xff ; ucontrol->value.iec958.status[2 ] = (spdif->status >>16 ) &0xff ; ucontrol->value.iec958.status[3 ] = (spdif->status >>24 ) &0xff ; -mutex_unlock (&codec->spdif_mutex);return 0 ; }
@@ -2320,7 +2318,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,if (WARN_ON (codec->spdif_out.used <= idx))return -EINVAL ; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx); nid = spdif->nid; spdif->status = ucontrol->value.iec958.status[0] |
@@ -2333,7 +2331,6 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, spdif->ctls = val;if (change && nid != (u16)-1 )set_dig_out_convert (codec, nid, val &0xff , (val >>8 ) &0xff ); -mutex_unlock (&codec->spdif_mutex);return change; }
@@ -2348,10 +2345,9 @@ static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,if (WARN_ON (codec->spdif_out.used <= idx))return -EINVAL ; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx); ucontrol->value.integer.value[0 ] = spdif->ctls &AC_DIG1_ENABLE ; -mutex_unlock (&codec->spdif_mutex);return 0 ; }
@@ -2378,7 +2374,7 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,if (WARN_ON (codec->spdif_out.used <= idx))return -EINVAL ; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx); nid = spdif->nid; val = spdif->ctls & ~AC_DIG1_ENABLE ;
@@ -2388,7 +2384,6 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, spdif->ctls = val;if (change && nid != (u16)-1 )set_spdif_ctls (codec, nid, val &0xff ,-1 ); -mutex_unlock (&codec->spdif_mutex);return change; }
@@ -2533,10 +2528,9 @@ void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)if (WARN_ON (codec->spdif_out.used <= idx))return ; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx); spdif->nid = (u16)-1 ; -mutex_unlock (&codec->spdif_mutex); }EXPORT_SYMBOL_GPL (snd_hda_spdif_ctls_unassign);
@@ -2555,14 +2549,13 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)if (WARN_ON (codec->spdif_out.used <= idx))return ; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx);if (spdif->nid != nid) { spdif->nid = nid; val = spdif->ctls;set_spdif_ctls (codec, nid, val &0xff , (val >>8 ) &0xff ); } -mutex_unlock (&codec->spdif_mutex); }EXPORT_SYMBOL_GPL (snd_hda_spdif_ctls_assign);
@@ -2637,14 +2630,13 @@ static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,unsigned int val = !!ucontrol->value.integer.value[0 ];int change; -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); change = codec->spdif_in_enable != val;if (change) { codec->spdif_in_enable = val;snd_hdac_regmap_write (&codec->core, nid,AC_VERB_SET_DIGI_CONVERT_1 , val); } -mutex_unlock (&codec->spdif_mutex);return change; }
@@ -3203,7 +3195,8 @@ int snd_hda_codec_prepare(struct hda_codec *codec, struct snd_pcm_substream *substream) {int ret; -mutex_lock (&codec->bus->prepare_mutex); + +guard (mutex)(&codec->bus->prepare_mutex);if (hinfo->ops.prepare) ret = hinfo->ops.prepare (hinfo, codec, stream, format, substream);
@@ -3211,7 +3204,6 @@ int snd_hda_codec_prepare(struct hda_codec *codec, ret = -ENODEV ;if (ret >=0 )purify_inactive_streams (codec); -mutex_unlock (&codec->bus->prepare_mutex);return ret; }EXPORT_SYMBOL_GPL (snd_hda_codec_prepare);
@@ -3228,10 +3220,9 @@ void snd_hda_codec_cleanup(struct hda_codec *codec,struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { - mutex_lock(&codec->bus->prepare_mutex); + guard(mutex)(&codec->bus->prepare_mutex);if (hinfo->ops.cleanup) hinfo->ops.cleanup (hinfo, codec, substream); -mutex_unlock (&codec->bus->prepare_mutex); }EXPORT_SYMBOL_GPL (snd_hda_codec_cleanup);
@@ -3662,12 +3653,11 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)int snd_hda_multi_out_dig_open (struct hda_codec *codec,struct hda_multi_out *mout) { -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex);if (mout->dig_out_used ==HDA_DIG_ANALOG_DUP )/* already opened as analog dup; reset it once */ cleanup_dig_out_stream (codec, mout->dig_out_nid); mout->dig_out_used =HDA_DIG_EXCLUSIVE ; -mutex_unlock (&codec->spdif_mutex);return 0 ; }EXPORT_SYMBOL_GPL (snd_hda_multi_out_dig_open);
@@ -3686,9 +3676,8 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,unsigned int format, struct snd_pcm_substream *substream) { - mutex_lock(&codec->spdif_mutex); + guard(mutex)(&codec->spdif_mutex);setup_dig_out_stream (codec, mout->dig_out_nid, stream_tag, format); -mutex_unlock (&codec->spdif_mutex);return 0 ; }EXPORT_SYMBOL_GPL (snd_hda_multi_out_dig_prepare);
@@ -3701,9 +3690,8 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_prepare);int snd_hda_multi_out_dig_cleanup (struct hda_codec *codec,struct hda_multi_out *mout) { -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex);cleanup_dig_out_stream (codec, mout->dig_out_nid); -mutex_unlock (&codec->spdif_mutex);return 0 ; }EXPORT_SYMBOL_GPL (snd_hda_multi_out_dig_cleanup);
@@ -3716,9 +3704,8 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_cleanup);int snd_hda_multi_out_dig_close (struct hda_codec *codec,struct hda_multi_out *mout) { -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex); mout->dig_out_used =0 ; -mutex_unlock (&codec->spdif_mutex);return 0 ; }EXPORT_SYMBOL_GPL (snd_hda_multi_out_dig_close);
@@ -3757,7 +3744,7 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec, &mout->spdif_formats, &mout->spdif_maxbps); } -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex);if (mout->share_spdif) {if ((runtime->hw.rates & mout->spdif_rates) && (runtime->hw.formats & mout->spdif_formats)) {
@@ -3770,7 +3757,6 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,/* FIXME: need notify? */ } } -mutex_unlock (&codec->spdif_mutex); }return snd_pcm_hw_constraint_step (substream->runtime,0 ,SNDRV_PCM_HW_PARAM_CHANNELS ,2 );
@@ -3799,23 +3785,23 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,struct hda_spdif_out *spdif;int i; -mutex_lock (&codec->spdif_mutex); - spdif =snd_hda_spdif_out_of_nid (codec, mout->dig_out_nid); -if (mout->dig_out_nid && mout->share_spdif && - mout->dig_out_used !=HDA_DIG_EXCLUSIVE ) { -if (chs ==2 && spdif !=NULL && -snd_hda_is_supported_format (codec, mout->dig_out_nid, - format) && - !(spdif->status &IEC958_AES0_NONAUDIO )) { - mout->dig_out_used =HDA_DIG_ANALOG_DUP ; -setup_dig_out_stream (codec, mout->dig_out_nid, - stream_tag, format); - }else { - mout->dig_out_used =0 ; -cleanup_dig_out_stream (codec, mout->dig_out_nid); + scoped_guard(mutex, &codec->spdif_mutex) { + spdif =snd_hda_spdif_out_of_nid (codec, mout->dig_out_nid); +if (mout->dig_out_nid && mout->share_spdif && + mout->dig_out_used !=HDA_DIG_EXCLUSIVE ) { +if (chs ==2 && spdif !=NULL && +snd_hda_is_supported_format (codec, mout->dig_out_nid, + format) && + !(spdif->status &IEC958_AES0_NONAUDIO )) { + mout->dig_out_used =HDA_DIG_ANALOG_DUP ; +setup_dig_out_stream (codec, mout->dig_out_nid, + stream_tag, format); + }else { + mout->dig_out_used =0 ; +cleanup_dig_out_stream (codec, mout->dig_out_nid); + } } } -mutex_unlock (&codec->spdif_mutex);/* front */ snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
@@ -3882,12 +3868,11 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,if (mout->extra_out_nid[i])snd_hda_codec_cleanup_stream (codec, mout->extra_out_nid[i]); -mutex_lock (&codec->spdif_mutex); +guard (mutex)(&codec->spdif_mutex);if (mout->dig_out_nid && mout->dig_out_used ==HDA_DIG_ANALOG_DUP ) {cleanup_dig_out_stream (codec, mout->dig_out_nid); mout->dig_out_used =0 ; } -mutex_unlock (&codec->spdif_mutex);return 0 ; }EXPORT_SYMBOL_GPL (snd_hda_multi_out_analog_cleanup);
sound/pci/hda/hda_controller.c +12 -12
@@ -92,12 +92,12 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)struct azx_dev *azx_dev =get_azx_dev (substream);trace_azx_pcm_close (chip, azx_dev); -mutex_lock (&chip->open_mutex); -azx_release_device (azx_dev); -if (hinfo->ops.close) - hinfo->ops.close (hinfo, apcm->codec, substream); -snd_hda_power_down (apcm->codec); -mutex_unlock (&chip->open_mutex); + scoped_guard(mutex, &chip->open_mutex) { +azx_release_device (azx_dev); +if (hinfo->ops.close) + hinfo->ops.close (hinfo, apcm->codec, substream); +snd_hda_power_down (apcm->codec); + }snd_hda_codec_pcm_put (apcm->info);return 0 ; }
@@ -1132,12 +1132,12 @@ static int probe_codec(struct azx *chip, int addr)int err;unsigned int res =-1 ; -mutex_lock (&bus->cmd_mutex); - chip->probing =1 ; -azx_send_cmd (bus, cmd); - err =azx_get_response (bus, addr, &res); - chip->probing =0 ; -mutex_unlock (&bus->cmd_mutex); + scoped_guard(mutex, &bus->cmd_mutex) { + chip->probing =1 ; +azx_send_cmd (bus, cmd); + err =azx_get_response (bus, addr, &res); + chip->probing =0 ; + }if (err <0 || res ==-1 )return -EIO ;dev_dbg (chip->card->dev,"codec #%d probed OK\n" , addr);
sound/pci/hda/hda_sysfs.c +25 -41
153 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 553/1193 ALSA: hda: Report a change when only the channel status bytes move
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 7284788743121ec8bed556b00f830dc52ad9955d ]
The put() callback of "IEC958 Playback Default" returns whether the converted register value moved. The convert_from_spdif_status() helper reads part of the first two channel status bytes and none of the last two, while the get() callback returns all four. So a write that lands only in the bits it does not read changes what userspace reads back and reports no change. Of the 31 bits above the mode bit, 20 are such bits in consumer mode and 29 in professional mode. The core notifies only on a positive return.
Toggling status[2] bit 0 on an HDA HDMI codec moves the read-back from 04 00 00 00 to 04 00 01 00 with no event. Toggling the non-audio bit in status[0] gives one.
Compare the stored status as well, the way the ac97 code does. The write to the codec stays gated on the converted value.
--- sound/pci/hda/hda_codec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +3 -1
@@ -2313,6 +2313,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,int idx = kcontrol->private_value;struct hda_spdif_out *spdif;hda_nid_t nid; +unsigned int old_status;unsigned short val;int change;
@@ -2321,6 +2322,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,guard (mutex)(&codec->spdif_mutex); spdif =snd_array_elem (&codec->spdif_out, idx); nid = spdif->nid; + old_status = spdif->status; spdif->status = ucontrol->value.iec958.status[0 ] | ((unsigned int )ucontrol->value.iec958.status[1 ] <<8 ) | ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
@@ -2331,7 +2333,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, spdif->ctls = val;if (change && nid != (u16)-1 )set_dig_out_convert (codec, nid, val &0xff , (val >>8 ) &0xff ); -return change; +return change || spdif->status != old_status; }#define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 554/1193 ice: add missing xa_destroy for sched_node_ids
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Keller <[email protected]>
[ Upstream commit 53432c4c3e869076350aef319534431af8ba99c1 ]
Commit 16dfa49406bc ("ice: Introduce new parameters in ice_sched_node") added a sched_node_ids xarray to the port info structure, but never called xa_destroy on it.
Since xarrays can allocate internal memory, this can result in a memory leak even if every element in the xarray has been removed.
The xarray is currently embedded in the port_info structure. This appears to have been done because its use is within functions that take the port_info as a primary argument.
However, this complicates managing the lifecycle of the field. The port_info structure is allocated in ice_init_hw() using devm, and it is not released until the devm cleanup when the driver is unloaded.
The ice_init_hw() function is called in many places, including devlink reload, and possibly during DDP load after updating the Tx scheduler layout.
Adding a call of xa_destroy to the ice_deinit_hw() causes Sashiko to raise multiple concerns due to potential ordering issues and possible ways that port_info could be a dangling reference.
To handle this, move the sched_node_ids out of port_info and into the hw structure. All users of the array already have a pointer to hw anyways, and there is only one sched_node_ids per adapter. While here, remove the overly verbose comment explaining the nature of the sched_node_ids xarray.
Add the missing xa_destroy to the cleanup path and to ice_deinit_hw(), ensuring that we properly release the xarray memory.
This was caught by Sashiko during development of unrelated code.
--- drivers/net/ethernet/intel/ice/ice_common.c | 9 ++++++--- drivers/net/ethernet/intel/ice/ice_sched.c | 4 ++-- drivers/net/ethernet/intel/ice/ice_type.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +6 -3
@@ -1149,14 +1149,13 @@ int ice_init_hw(struct ice_hw *hw) hw->evb_veb = true; -/* init xarray for identifying scheduling nodes uniquely */ -xa_init_flags (&hw->port_info->sched_node_ids,XA_FLAGS_ALLOC ); +xa_init_flags (&hw->sched_node_ids,XA_FLAGS_ALLOC );/* Query the allocated resources for Tx scheduler */ status =ice_sched_query_res_alloc (hw);if (status) {ice_debug (hw,ICE_DBG_SCHED ,"Failed to get scheduler allocated resources\n" ); - goto err_unroll_alloc; + goto err_unroll_xarray; }ice_sched_get_psm_clk_freq (hw);
@@ -1235,6 +1234,8 @@ int ice_init_hw(struct ice_hw *hw)ice_cleanup_fltr_mgmt_struct (hw); err_unroll_sched:ice_sched_cleanup_all (hw); +err_unroll_xarray: +xa_destroy (&hw->sched_node_ids); err_unroll_alloc:devm_kfree (ice_hw_to_dev (hw), hw->port_info); err_unroll_cqinit:
@@ -1267,6 +1268,8 @@ void ice_deinit_hw(struct ice_hw *hw)/* Clear VSI contexts if not already cleared */ ice_clear_all_vsi_ctx (hw); + +xa_destroy (&hw->sched_node_ids); }/**
drivers/net/ethernet/intel/ice/ice_sched.c +2 -2
@@ -379,7 +379,7 @@ void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node)devm_kfree (ice_hw_to_dev (hw), node->children);kfree (node->name); -xa_erase (&pi->sched_node_ids, node->id); +xa_erase (&hw->sched_node_ids, node->id);devm_kfree (ice_hw_to_dev (hw), node); }
@@ -989,7 +989,7 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,if (!new_node->name)return -ENOMEM ; - status =xa_alloc (&pi->sched_node_ids, &new_node->id,NULL ,XA_LIMIT (0 ,UINT_MAX ), + status =xa_alloc (&hw->sched_node_ids, &new_node->id,NULL ,XA_LIMIT (0 ,UINT_MAX ),GFP_KERNEL );if (status) { ice_debug(hw, ICE_DBG_SCHED, "xa_alloc failed for sched node status =%d\n",
drivers/net/ethernet/intel/ice/ice_type.h +1 -1
@@ -716,7 +716,6 @@ struct ice_port_info {/* List contain profile ID(s) and other params per layer */ struct list_head rl_prof_list[ICE_AQC_TOPO_MAX_LEVEL_NUM ];struct ice_qos_cfg qos_cfg; -struct xarray sched_node_ids; u8 is_vf:1; u8 is_custom_tx_enabled:1; };
@@ -855,6 +854,7 @@ struct ice_hw {u8 sw_entry_point_layer;u16 max_children[ICE_AQC_TOPO_MAX_LEVEL_NUM ];struct list_head agg_list;/* lists all aggregator */ +struct xarray sched_node_ids;struct ice_vsi_ctx *vsi_ctx[ICE_MAX_VSI ];u8 evb_veb;/* true for VEB, false for VEPA */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 555/1193 Bluetooth: btusb: Fix UAF of btusb_data by rx_work
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit 1c12c3117639e78940959d956519c758c57d0849 ]
btusb_close() and btusb_flush() cancel data->rx_work with the asynchronous cancel_delayed_work(), so if btusb_rx_work() is already running on another CPU it keeps running after the cancel returns.
btusb_disconnect() calls hci_unregister_dev(), which invokes btusb_close(), and then frees the btusb_data. A still running btusb_rx_work() then dereferences the freed data:
while ((skb = skb_dequeue(&data->acl_q))) data->recv_acl(data->hdev, skb);
Use cancel_delayed_work_sync() instead. In btusb_close() the cancel also has to happen after btusb_stop_traffic(), otherwise an URB completion racing with the cancel can requeue the work right after it has been waited for.
--- drivers/bluetooth/btusb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/bluetooth/btusb.c +10 -4
@@ -1961,18 +1961,24 @@ static int btusb_close(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); -cancel_delayed_work (&data->rx_work);cancel_work_sync (&data->work);cancel_work_sync (&data->waker); -skb_queue_purge (&data->acl_q); -clear_bit (BTUSB_ISOC_RUNNING , &data->flags);clear_bit (BTUSB_BULK_RUNNING , &data->flags);clear_bit (BTUSB_INTR_RUNNING , &data->flags);clear_bit (BTUSB_DIAG_RUNNING , &data->flags);btusb_stop_traffic (data); + +/* rx_work must only be canceled once the URBs that can rearm it are +* gone, and it must be canceled synchronously since btusb_disconnect() +* frees the btusb_data it dereferences right after hci_unregister_dev(). +*/ +cancel_delayed_work_sync (&data->rx_work); + +skb_queue_purge (&data->acl_q); +btusb_free_frags (data); err =usb_autopm_get_interface (data->intf);
@@ -1998,7 +2004,7 @@ static int btusb_flush(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); -cancel_delayed_work (&data->rx_work); +cancel_delayed_work_sync (&data->rx_work);skb_queue_purge (&data->acl_q);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/1193 net: macb: destroy the phylink instance on the probe error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 7d059f390750152b9bd69df934198651b94fc26d ]
macb_mii_init() creates a phylink instance on both of its success paths, but the probe unwind frees the netdev without destroying it, so a failing macb_alloc_tieoff() or register_netdev() leaks the instance.
Destroy it at err_out_unregister_mdio, which is only reachable once macb_mii_init() has succeeded, so bp->phylink is valid there.
--- drivers/net/ethernet/cadence/macb_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5309,6 +5309,7 @@ static int macb_probe(struct platform_device *pdev)mdiobus_unregister (bp->mii_bus);mdiobus_free (bp->mii_bus); } +phylink_destroy (bp->phylink); err_out_phy_exit:phy_exit (bp->phy);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/1193 watchdog: fix hrtimer start when pretimeout is zero
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Arcari <[email protected]>
[ Upstream commit 0fa37512eb747e4ffdcf367274f9e72845f1bca4 ]
Per the watchdog API, a pretimeout value of 0 disables the feature. However, watchdog_hrtimer_pretimeout_start() fails to verify if the pretimeout is non-zero before arming the timer.
This omission inadvertently starts the software pretimeout timer, which could result in the pretimeout handler executing incorrectly when the watchdog timeout is reached.
Fix this by adding a check for wdd->pretimeout before calling hrtimer_start(), ensuring the disabled state is respected.
--- drivers/watchdog/watchdog_hrtimer_pretimeout.c | 1 + 1 file changed, 1 insertion(+)
drivers/watchdog/watchdog_hrtimer_pretimeout.c +1 -0
@@ -30,6 +30,7 @@ void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd)void watchdog_hrtimer_pretimeout_start (struct watchdog_device *wdd) {if (!(wdd->info->options &WDIOF_PRETIMEOUT ) && + wdd->pretimeout && !watchdog_pretimeout_invalid (wdd, wdd->pretimeout)) hrtimer_start(&wdd->wd_data->pretimeout_timer, ktime_set(wdd->timeout - wdd->pretimeout, 0),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 558/1193 watchdog: msc313e: Avoid division by zero
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 3c73a37f5e40972ce26d8eeb98e8b938d719b069 ]
clk_get_rate() could return 0. Avoid a division by zero panic.
--- drivers/watchdog/msc313e_wdt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/watchdog/msc313e_wdt.c +5 -1
@@ -98,6 +98,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct msc313e_wdt_priv *priv; +unsigned long rate; priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -117,7 +118,10 @@ static int msc313e_wdt_probe(struct platform_device *pdev) priv->wdev.ops = &msc313e_wdt_ops, priv->wdev.parent = dev; priv->wdev.min_timeout =MSC313E_WDT_MIN_TIMEOUT ; - priv->wdev.max_timeout =U32_MAX /clk_get_rate (priv->clk); + rate =clk_get_rate (priv->clk); +if (!rate) +return -EINVAL ; + priv->wdev.max_timeout =U32_MAX / rate; priv->wdev.timeout =MSC313E_WDT_DEFAULT_TIMEOUT ;/* If the period is non-zero the WDT is running */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 559/1193 watchdog: msc313e: Fix clock leak and spurious timer in settimeout()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 3db30f315935c2fb0d95f46b7a593b5b4d3ec3d0 ]
msc313e_wdt_settimeout() unconditionally calls msc313e_wdt_start() which introduces two severe bugs:
1. If the watchdog is already active, calling start() again will increase the reference count of the clock again. However stop() is only called once, the reference count is unbalance.
2. If the watchdog is stopped, calling settimeout() will start the hardware timer accidentally.
Factor out the register-writing logic into a helper function. Only call it in settimeout() if the watchdog is running. Otherwise, simply update wdev->timeout.
--- drivers/watchdog/msc313e_wdt.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/watchdog/msc313e_wdt.c +16 -6
@@ -32,20 +32,26 @@ struct msc313e_wdt_priv {struct clk *clk; }; +static void msc313e_wdt_set_hw_timeout (struct msc313e_wdt_priv *priv, +unsigned int timeout) +{ +u32 t = timeout *clk_get_rate (priv->clk); + +writew (t &0xffff , priv->base +REG_WDT_MAX_PRD_L ); +writew ((t >>16 ) &0xffff , priv->base +REG_WDT_MAX_PRD_H ); +writew (1 , priv->base +REG_WDT_CLR ); +} +static int msc313e_wdt_start (struct watchdog_device *wdev) {struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); -u32 timeout;int err; err =clk_prepare_enable (priv->clk);if (err)return err; - timeout = wdev->timeout *clk_get_rate (priv->clk); -writew (timeout &0xffff , priv->base +REG_WDT_MAX_PRD_L ); -writew ((timeout >>16 ) &0xffff , priv->base +REG_WDT_MAX_PRD_H ); -writew (1 , priv->base +REG_WDT_CLR ); +msc313e_wdt_set_hw_timeout (priv, wdev->timeout);return 0 ; }
@@ -70,9 +76,13 @@ static int msc313e_wdt_stop(struct watchdog_device *wdev)static int msc313e_wdt_settimeout (struct watchdog_device *wdev,unsigned int new_time) { +struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); + wdev->timeout = new_time; -return msc313e_wdt_start (wdev); +if (watchdog_hw_running (wdev) ||watchdog_active (wdev)) +msc313e_wdt_set_hw_timeout (priv, wdev->timeout); +return 0 ; }static const struct watchdog_info msc313e_wdt_ident = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 560/1193 watchdog: msc313e: Enable clock before accessing hardware registers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 3db2df24e7f11fb117718f6abe326628d91bc500 ]
msc313e_wdt_probe() reads from hardware registers without ensuring the required clock is enabled. Furthermore, if the bootloader leaves the watchdog running, msc313e_wdt_probe() sets WDOG_HW_RUNNING without increasing the clock's reference count.
While the clock is currently supplied as a fixed clock by the device tree (xtal_div2 in arch/arm/boot/dts/sigmastar/mstar-v7.dtsi) which masks the physical issue, this still violates the API usage.
Call clk_prepare_enable() before reading WDT registers. If the WDT is running, leave the clock enabled so the CCF reference counter is balanced.
--- drivers/watchdog/msc313e_wdt.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/watchdog/msc313e_wdt.c +21 -2
@@ -109,6 +109,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct msc313e_wdt_priv *priv;unsigned long rate; +int ret; priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -134,9 +135,21 @@ static int msc313e_wdt_probe(struct platform_device *pdev) priv->wdev.max_timeout =U32_MAX / rate; priv->wdev.timeout =MSC313E_WDT_DEFAULT_TIMEOUT ; + ret =clk_prepare_enable (priv->clk); +if (ret) +return ret; +/* If the period is non-zero the WDT is running */ -if (readw (priv->base +REG_WDT_MAX_PRD_L ) | (readw (priv->base +REG_WDT_MAX_PRD_H ) <<16 )) +if (readw (priv->base +REG_WDT_MAX_PRD_L ) | (readw (priv->base +REG_WDT_MAX_PRD_H ) <<16 )) {set_bit (WDOG_HW_RUNNING , &priv->wdev.status); +/* +* Keep the clock enabled. The watchdog core will skip the next +* start() and a future stop() will balance the CCF reference +* count. +*/ + }else { +clk_disable_unprepare (priv->clk); + }watchdog_set_drvdata (&priv->wdev, priv);platform_set_drvdata (pdev, priv);
@@ -145,7 +158,13 @@ static int msc313e_wdt_probe(struct platform_device *pdev)watchdog_stop_on_reboot (&priv->wdev);watchdog_stop_on_unregister (&priv->wdev); -return devm_watchdog_register_device (dev, &priv->wdev); + ret =devm_watchdog_register_device (dev, &priv->wdev); + +/* If the WDT is running and anything goes wrong, disable the clock. */ +if (ret &&test_bit (WDOG_HW_RUNNING , &priv->wdev.status)) +clk_disable_unprepare (priv->clk); + +return ret; }static int __maybe_unused msc313e_wdt_suspend (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 561/1193 watchdog: msc313e: Fix spurious reset on suspend
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 4f6817c9eff4aa1078e16652d82e4b7ef4ffae3e ]
If the hardware watchdog was started by the bootloader and the device is suspended before userspace opens it, the ping worker (from watchdog core) is frozen and the active hardware timer continues running. This leads to a spurious system reset.
Check both watchdog_active() and watchdog_hw_running() when deciding whether to start or stop the watchdog during suspend and resume.
Additionally, call watchdog_stop_ping_on_suspend() to ensure the ping worker be correctly paused and restarted during suspend and resume.
--- drivers/watchdog/msc313e_wdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/watchdog/msc313e_wdt.c +3 -2
@@ -157,6 +157,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev)watchdog_init_timeout (&priv->wdev, timeout, dev);watchdog_stop_on_reboot (&priv->wdev);watchdog_stop_on_unregister (&priv->wdev); +watchdog_stop_ping_on_suspend (&priv->wdev); ret =devm_watchdog_register_device (dev, &priv->wdev);
@@ -171,7 +172,7 @@ static int __maybe_unused msc313e_wdt_suspend(struct device *dev) {struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); -if (watchdog_active (&priv->wdev)) +if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev))msc313e_wdt_stop (&priv->wdev);return 0 ;
@@ -181,7 +182,7 @@ static int __maybe_unused msc313e_wdt_resume(struct device *dev) {struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); -if (watchdog_active (&priv->wdev)) +if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev))msc313e_wdt_start (&priv->wdev);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 562/1193 watchdog: msc313e: Fix undefined behavior
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit ab390021b2a3bb4cc875f28a6f76d13de90d7457 ]
readw() returns a u16. Left shifting a u16 by 16 bits yields undefined behavior.
Cast to u32 explicitly before the shift.
--- drivers/watchdog/msc313e_wdt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/watchdog/msc313e_wdt.c +11 -1
@@ -32,6 +32,16 @@ struct msc313e_wdt_priv {struct clk *clk; }; +static u32 msc313e_wdt_get_hw_timeout (struct msc313e_wdt_priv *priv) +{ +u16 low, high; + + low =readw (priv->base +REG_WDT_MAX_PRD_L ); + high =readw (priv->base +REG_WDT_MAX_PRD_H ); + +return ((u32 )high <<16 ) | low; +} +static void msc313e_wdt_set_hw_timeout (struct msc313e_wdt_priv *priv,unsigned int timeout) {
@@ -140,7 +150,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev)return ret;/* If the period is non-zero the WDT is running */ -if (readw (priv->base +REG_WDT_MAX_PRD_L ) | (readw (priv->base +REG_WDT_MAX_PRD_H ) <<16 )) { +if (msc313e_wdt_get_hw_timeout (priv)) {set_bit (WDOG_HW_RUNNING , &priv->wdev.status);/* * Keep the clock enabled. The watchdog core will skip the next
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 563/1193 watchdog: msc313e: Sync timeout value if WDT was running at boot
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 01504d14e47b34779911250dd308a03f6ef681c2 ]
If WDT was running at boot, the hardware timeout might be set to values other than the final software timeout.
To be consistent, set the hardware timeout to match the final software timeout (i.e., after watchdog_init_timeout()) if WDT was running.
--- drivers/watchdog/msc313e_wdt.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/watchdog/msc313e_wdt.c +9 -8
@@ -145,12 +145,21 @@ static int msc313e_wdt_probe(struct platform_device *pdev) priv->wdev.max_timeout =U32_MAX / rate; priv->wdev.timeout =MSC313E_WDT_DEFAULT_TIMEOUT ; +watchdog_set_drvdata (&priv->wdev, priv); +platform_set_drvdata (pdev, priv); + +watchdog_init_timeout (&priv->wdev, timeout, dev); +watchdog_stop_on_reboot (&priv->wdev); +watchdog_stop_on_unregister (&priv->wdev); +watchdog_stop_ping_on_suspend (&priv->wdev); + ret =clk_prepare_enable (priv->clk);if (ret)return ret;/* If the period is non-zero the WDT is running */ if (msc313e_wdt_get_hw_timeout (priv)) { +msc313e_wdt_set_hw_timeout (priv, priv->wdev.timeout);set_bit (WDOG_HW_RUNNING , &priv->wdev.status);/* * Keep the clock enabled. The watchdog core will skip the next
@@ -161,14 +170,6 @@ static int msc313e_wdt_probe(struct platform_device *pdev)clk_disable_unprepare (priv->clk); } -watchdog_set_drvdata (&priv->wdev, priv); -platform_set_drvdata (pdev, priv); - -watchdog_init_timeout (&priv->wdev, timeout, dev); -watchdog_stop_on_reboot (&priv->wdev); -watchdog_stop_on_unregister (&priv->wdev); -watchdog_stop_ping_on_suspend (&priv->wdev); - ret =devm_watchdog_register_device (dev, &priv->wdev);/* If the WDT is running and anything goes wrong, disable the clock. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 564/1193 net/micrel: Fix typos in micrel driver code comments
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yicong Hui <[email protected]>
[ Upstream commit c2b733da93bf607d6c6f925b4d40598e6bb516be ]
Fix various typos and misspellings in code comments in the drivers/net/ethernet/micrel directory
Stable-dep-of: 66ef5adb7544 ("net: ks8851: Fix receiver error in 100BASE-TX mode following software power-down")
--- drivers/net/ethernet/micrel/ks8842.c | 4 ++-- drivers/net/ethernet/micrel/ks8851_common.c | 2 +- drivers/net/ethernet/micrel/ks8851_spi.c | 4 ++-- drivers/net/ethernet/micrel/ksz884x.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/micrel/ks8842.c +2 -2
@@ -242,7 +242,7 @@ static void ks8842_reset(struct ks8842_adapter *adapter)msleep (10 );iowrite16 (0 , adapter->hw_addr +REG_GRR ); }else { -/* The KS8842 goes haywire when doing softare reset +/* The KS8842 goes haywire when doing software reset * a work around in the timberdale IP is implemented to * do a hardware reset instead ks8842_write16(adapter, 3, 1, REG_GRR);
@@ -312,7 +312,7 @@ static void ks8842_reset_hw(struct ks8842_adapter *adapter)/* aggressive back off in half duplex */ ks8842_enable_bits (adapter,32 ,1 <<8 ,REG_SGCR1 ); -/* enable no excessive collison drop */ +/* enable no excessive collision drop */ ks8842_enable_bits (adapter,32 ,1 <<3 ,REG_SGCR2 );/* Enable port 1 force flow control / back pressure / transmit / recv */
drivers/net/ethernet/micrel/ks8851_common.c +1 -1
@@ -493,7 +493,7 @@ static int ks8851_net_open(struct net_device *dev)* ks8851_net_stop - close network device * @dev: The device being closed. * -* Called to close down a network device which has been active. Cancell any +* Called to close down a network device which has been active. Cancel any * work, shutdown the RX and TX process and then place the chip into a low * power state whilst it is not being used. */
drivers/net/ethernet/micrel/ks8851_spi.c +2 -2
@@ -41,7 +41,7 @@ static int msg_enable;* * The @lock ensures that the chip is protected when certain operations are * in progress. When the read or write packet transfer is in progress, most -* of the chip registers are not ccessible until the transfer is finished and +* of the chip registers are not accessible until the transfer is finished and * the DMA has been de-asserted. */ struct ks8851_net_spi {
@@ -298,7 +298,7 @@ static unsigned int calc_txlen(unsigned int len)/** * ks8851_tx_work - process tx packet(s) -* @work: The work strucutre what was scheduled. +* @work: The work structure what was scheduled. * * This is called when a number of packets have been scheduled for * transmission and need to be sent to the device.
drivers/net/ethernet/micrel/ksz884x.c +2 -2
@@ -1166,7 +1166,7 @@ struct ksz_port_info {* @tx_cfg: Cached transmit control settings. * @rx_cfg: Cached receive control settings. * @intr_mask: Current interrupt mask. -* @intr_set: Current interrup set. +* @intr_set: Current interrupt set. * @intr_blocked: Interrupt blocked. * @rx_desc_info: Receive descriptor information. * @tx_desc_info: Transmit descriptor information.
@@ -2096,7 +2096,7 @@ static void sw_dis_prio_rate(struct ksz_hw *hw, int port) }/** -* sw_init_prio_rate - initialize switch prioirty rate +* sw_init_prio_rate - initialize switch priority rate * @hw: The hardware instance. * * This routine initializes the priority rate function of the switch.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 565/1193 net: ks8851: Fix receiver error in 100BASE-TX mode following software power-down
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
[ Upstream commit 66ef5adb75446627f8b6c26cd04f2adc86d4de56 ]
KSZ8851 errata sheet DS80000716D-page 4 Module 3 [1] states that, when issuing a software power-down (PMECR[1:0] = 10) followed by a power-on (PMECR[1:0] = 00), the receiver circuit can fail to start properly preventing communication. The Transmitter will still send data, but no data will be received.
The errata sheet also includes a workaround, which states that, it is recommended that the software power-down feature not be used.
Implement that workaround and drop the entry into software power-down mode. The ks8851_write_mac_addr() calls entry into normal power-on mode at the very beginning of the function, therefore dropping the second call to enter software power-down mode is sufficient here. The ks8851_net_stop() can only be called after ks8851_net_start() was already called, and ks8851_net_start() also makes the MAC enter normal power-on mode, therefore it is also fine to drop the call to enter software power-down mode from ks8851_net_stop().
This will lead to a slight increase in power consumption, but it also fixes a sporadic reliability problem on at least KSZ8851-16MLL, which is where the problem was reported and this fix was tested.
[1] https://ww1.microchip.com/downloads/en/DeviceDoc/80000716D.pdf
--- drivers/net/ethernet/micrel/ks8851_common.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/micrel/ks8851_common.c +1 -7
@@ -143,9 +143,6 @@ static int ks8851_write_mac_addr(struct net_device *dev)ks8851_wrreg16 (ks,KS_MAR (i), val); } -if (!netif_running (dev)) -ks8851_set_powermode (ks,PMECR_PM_SOFTDOWN ); -ks8851_unlock (ks);return 0 ;
@@ -494,8 +491,7 @@ static int ks8851_net_open(struct net_device *dev)* @dev: The device being closed. * * Called to close down a network device which has been active. Cancel any -* work, shutdown the RX and TX process and then place the chip into a low -* power state whilst it is not being used. +* work and shutdown the RX and TX process. */ static int ks8851_net_stop (struct net_device *dev) {
@@ -522,8 +518,6 @@ static int ks8851_net_stop(struct net_device *dev)/* shutdown TX process */ ks8851_wrreg16 (ks,KS_TXCR ,0x0000 ); -/* set powermode to soft power down to save power */ -ks8851_set_powermode (ks,PMECR_PM_SOFTDOWN );ks8851_unlock (ks);/* ensure any queued tx buffers are dumped */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 566/1193 hwmon: (gpio-fan) take fan_data->lock in gpio_fan_shutdown()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
[ Upstream commit bb2424c3502cc72292eedade46960c331d5f28fb ]
set_fan_speed() writes the control GPIOs one bit at a time. Every other caller locks around it; gpio_fan_shutdown() doesn't. If it races a locked caller, the GPIO writes can interleave and leave the fan at a speed neither caller asked for.
--- drivers/hwmon/gpio-fan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/gpio-fan.c +4 -1
@@ -561,8 +561,11 @@ static void gpio_fan_shutdown(struct platform_device *pdev) {struct gpio_fan_data *fan_data =platform_get_drvdata (pdev); -if (fan_data->gpios) +if (fan_data->gpios) { +mutex_lock (&fan_data->lock);set_fan_speed (fan_data,0 ); +mutex_unlock (&fan_data->lock); + } }static int gpio_fan_suspend (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 567/1193 hwmon: (aspeed-pwm-tacho) Propagate reset deassert errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 09a9e1746a87845d7d8e2b4e23bb613306effdff ]
aspeed_pwm_tacho_probe() installs its reset cleanup action and configures the
controller after an unchecked reset deassertion.
Stop probing when the reset controller rejects the transition, before the hwmon device becomes visible.
--- drivers/hwmon/aspeed-pwm-tacho.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/aspeed-pwm-tacho.c +3 -1
@@ -921,7 +921,9 @@ static int aspeed_pwm_tacho_probe(struct platform_device *pdev) "missing or invalid reset controller device tree entry");return PTR_ERR (priv->rst); } -reset_control_deassert (priv->rst); + ret =reset_control_deassert (priv->rst); +if (ret) +return ret; ret =devm_add_action_or_reset (dev, aspeed_pwm_tacho_remove, priv);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 568/1193 octeontx2-pf: reset HTB scheduler topology before freeing queues
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratheesh Kannoth <[email protected]>
[ Upstream commit ef39fca8508597fa565cf2be72a884a712fb98af ]
HTB offload programs NIX_AF_TLxX_TOPOLOGY on QoS-allocated scheduler queues via otx2_qos_txschq_set_parent_topology(), but teardown freed those queues without clearing TOPOLOGY. The AF only restores PARENT and SCHEDULE on free, so PRIO_ANCHOR/RR_PRIO settings can survive in the shared scheduler pool and affect later allocations.
Add otx2_qos_reset_schq_topology() and otx2_qos_free_hw_schq() to zero TL4 through TL2 TOPOLOGY before each schq is returned to the AF during hierarchy teardown and cfg rollback. Skip the aggregation level (TL1):
it is a per-tx-link queue shared by the PF, default Tx hierarchy and VFs, and is not freed back to the AF by nix_txschq_free_one().
--- .../net/ethernet/marvell/octeontx2/nic/qos.c | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +55 -5
@@ -235,13 +235,63 @@ static int otx2_qos_txschq_set_parent_topology(struct otx2_nic *pfvf,return rc; } +static int otx2_qos_reset_schq_topology (struct otx2_nic *pfvf,u16 lvl, +u16 schq) +{ +struct mbox *mbox = &pfvf->mbox; +struct nix_txschq_config *cfg; +int rc; + +if (lvl <NIX_TXSCH_LVL_TL4 || lvl >=NIX_TXSCH_LVL_TL1 ) +return 0 ; + +mutex_lock (&mbox->lock); + + cfg =otx2_mbox_alloc_msg_nix_txschq_cfg (mbox); +if (!cfg) { +mutex_unlock (&mbox->lock); +return -ENOMEM ; + } + + cfg->lvl = lvl; + cfg->num_regs =1 ; + +if (lvl ==NIX_TXSCH_LVL_TL4 ) + cfg->reg[0 ] =NIX_AF_TL4X_TOPOLOGY (schq); +else if (lvl ==NIX_TXSCH_LVL_TL3 ) + cfg->reg[0 ] =NIX_AF_TL3X_TOPOLOGY (schq); +else if (lvl ==NIX_TXSCH_LVL_TL2 ) + cfg->reg[0 ] =NIX_AF_TL2X_TOPOLOGY (schq); + + cfg->regval[0 ] =0 ; + + rc =otx2_sync_mbox_msg (mbox); + +mutex_unlock (&mbox->lock); + +return rc; +} + +static void otx2_qos_free_hw_schq (struct otx2_nic *pfvf,u16 lvl,u16 schq) +{ +int err; + + err =otx2_qos_reset_schq_topology (pfvf, lvl, schq); +if (err) +netdev_warn (pfvf->netdev, +"QoS: failed to reset topology for schq %u at level %u: %d\n" , + schq, lvl, err); + +otx2_txschq_free_one (pfvf, lvl, schq); +} +static void otx2_qos_free_hw_node_schq (struct otx2_nic *pfvf,struct otx2_qos_node *parent) {struct otx2_qos_node *node;list_for_each_entry_reverse (node, &parent->child_schq_list, list) -otx2_txschq_free_one (pfvf, node->level, node->schq); +otx2_qos_free_hw_schq (pfvf, node->level, node->schq); } static void otx2_qos_free_hw_node(struct otx2_nic *pfvf,
@@ -252,7 +302,7 @@ static void otx2_qos_free_hw_node(struct otx2_nic *pfvf,list_for_each_entry_safe (node, tmp, &parent->child_list, list) {otx2_qos_free_hw_node (pfvf, node);otx2_qos_free_hw_node_schq (pfvf, node); -otx2_txschq_free_one (pfvf, node->level, node->schq); +otx2_qos_free_hw_schq (pfvf, node->level, node->schq); } }
@@ -266,7 +316,7 @@ static void otx2_qos_free_hw_cfg(struct otx2_nic *pfvf,otx2_qos_free_hw_node_schq (pfvf, node);/* free node hw mappings */ -otx2_txschq_free_one (pfvf, node->level, node->schq); +otx2_qos_free_hw_schq (pfvf, node->level, node->schq);mutex_unlock (&pfvf->qos.qos_lock); }
@@ -899,7 +949,7 @@ static void otx2_qos_free_cfg(struct otx2_nic *pfvf, struct otx2_qos_cfg *cfg)for (lvl =0 ; lvl <NIX_TXSCH_LVL_CNT ; lvl++) {for (idx =0 ; idx < cfg->schq[lvl]; idx++) { schq = cfg->schq_list[lvl][idx]; -otx2_txschq_free_one (pfvf, lvl, schq); +otx2_qos_free_hw_schq (pfvf, lvl, schq); } }
@@ -907,7 +957,7 @@ static void otx2_qos_free_cfg(struct otx2_nic *pfvf, struct otx2_qos_cfg *cfg)for (idx =0 ; idx < cfg->schq_contig[lvl]; idx++) {if (cfg->schq_index_used[lvl][idx]) { schq = cfg->schq_contig_list[lvl][idx]; -otx2_txschq_free_one (pfvf, lvl, schq); +otx2_qos_free_hw_schq (pfvf, lvl, schq); } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 569/1193 vxlan: use generic function for tunnel IPv4 route lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit 6f19b2c136d98a84d79030b53e23d405edfdc783 ]
The route lookup can be done now via generic function udp_tunnel_dst_lookup() to replace the custom implementations in vxlan_get_route().
Note that this patch only touches IPv4, while IPv6 still uses vxlan6_get_route(). After IPv6 route lookup gets converted as well, vxlan_xmit_one() can be simplified by removing local variables that will be passed via "struct ip_tunnel_key", such as remote_ip, local_ip, flow_flags, label.
Stable-dep-of: be83178bfc44 ("vxlan: initialize _md in vxlan_xmit_one()")
--- drivers/net/vxlan/vxlan_core.c | 114 ++++++++++++--------------------- 1 file changed, 41 insertions(+), 73 deletions(-)
drivers/net/vxlan/vxlan_core.c +41 -73
@@ -2266,57 +2266,6 @@ static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst,return 0 ; } -static struct rtable *vxlan_get_route (struct vxlan_dev *vxlan,struct net_device *dev, -struct vxlan_sock *sock4, -struct sk_buff *skb,int oif,u8 tos, -__be32 daddr,__be32 *saddr,__be16 dport,__be16 sport, -__u8 flow_flags,struct dst_cache *dst_cache, -const struct ip_tunnel_info *info) -{ -bool use_cache =ip_tunnel_dst_cache_usable (skb, info); -struct rtable *rt =NULL ; -struct flowi4 fl4; - -if (!sock4) -return ERR_PTR (-EIO ); - -if (tos && !info) - use_cache = false; -if (use_cache) { - rt =dst_cache_get_ip4 (dst_cache, saddr); -if (rt) -return rt; - } - -memset (&fl4,0 ,sizeof (fl4)); - fl4.flowi4_oif = oif; - fl4.flowi4_tos =RT_TOS (tos); - fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto =IPPROTO_UDP ; - fl4.daddr = daddr; - fl4.saddr = *saddr; - fl4.fl4_dport = dport; - fl4.fl4_sport = sport; - fl4.flowi4_flags = flow_flags; - - rt =ip_route_output_key (vxlan->net, &fl4); -if (!IS_ERR (rt)) { -if (rt->dst.dev == dev) { -netdev_dbg (dev,"circular route to %pI4\n" , &daddr); -ip_rt_put (rt); -return ERR_PTR (-ELOOP ); - } - - *saddr = fl4.saddr; -if (use_cache) -dst_cache_set_ip4 (dst_cache, &rt->dst, fl4.saddr); - }else { -netdev_dbg (dev,"no route to %pI4\n" , &daddr); -return ERR_PTR (-ENETUNREACH ); - } -return rt; -} -#if IS_ENABLED (CONFIG_IPV6 ) static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan, struct net_device *dev,
@@ -2469,30 +2418,38 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, {struct dst_cache *dst_cache;struct ip_tunnel_info *info; +struct ip_tunnel_key *pkey; +struct ip_tunnel_key key;struct vxlan_dev *vxlan =netdev_priv (dev);const struct iphdr *old_iph =ip_hdr (skb);union vxlan_addr *dst; -union vxlan_addr remote_ip, local_ip; +union vxlan_addr remote_ip;struct vxlan_metadata _md;struct vxlan_metadata *md = &_md;unsigned int pkt_len = skb->len;__be16 src_port =0 , dst_port;struct dst_entry *ndst =NULL ; -__u8 tos, ttl, flow_flags =0 ; +__u8 tos, ttl;int ifindex;int err;u32 flags = vxlan->cfg.flags; +bool use_cache;bool udp_sum = false;bool xnet = !net_eq (vxlan->net,dev_net (vxlan->dev));__be32 vni =0 ;#if IS_ENABLED (CONFIG_IPV6 ) +union vxlan_addr local_ip;__be32 label;#endif info =skb_tunnel_info (skb); + use_cache =ip_tunnel_dst_cache_usable (skb, info);if (rdst) { dst = &rdst->remote_ip; +memset (&key,0 ,sizeof (key)); + pkey = &key; +if (vxlan_addr_any (dst)) {if (did_rsc) {/* short-circuited back to local bridge */
@@ -2506,7 +2463,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; vni = (rdst->remote_vni) ? : default_vni; ifindex = rdst->remote_ifindex; - local_ip = vxlan->cfg.saddr; + +if (dst->sa.sa_family ==AF_INET ) { + key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr; + key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr; + }else { + key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr; + key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr; + } + dst_cache = &rdst->dst_cache; md->gbp = skb->mark;if (flags &VXLAN_F_TTL_INHERIT ) {
@@ -2520,12 +2485,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos = vxlan->cfg.tos;if (tos ==1 ) tos =ip_tunnel_get_dsfield (old_iph, skb); +if (tos && !info) + use_cache = false;if (dst->sa.sa_family ==AF_INET ) udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM_TX );else udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM6_TX );#if IS_ENABLED (CONFIG_IPV6 ) + local_ip = vxlan->cfg.saddr; label = vxlan->cfg.label;#endif }else {
@@ -2537,14 +2505,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, remote_ip.sa.sa_family =ip_tunnel_info_af (info);if (remote_ip.sa.sa_family ==AF_INET ) { remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst; - local_ip.sin.sin_addr.s_addr = info->key.u.ipv4.src; }else { remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst; +#if IS_ENABLED (CONFIG_IPV6 ) local_ip.sin6.sin6_addr = info->key.u.ipv6.src; +#endif } dst = &remote_ip; + pkey = &info->key; dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; - flow_flags = info->key.flow_flags; vni =tunnel_id_to_key32 (info->key.tun_id); ifindex =0 ; dst_cache = &info->dst_cache;
@@ -2568,15 +2537,14 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,struct vxlan_sock *sock4 =rcu_dereference (vxlan->vn4_sock);struct rtable *rt;__be16 df =0 ; +__be32 saddr;if (!ifindex) ifindex = sock4->sock->sk->sk_bound_dev_if; - rt =vxlan_get_route (vxlan, dev, sock4, skb, ifindex, tos, - dst->sin.sin_addr.s_addr, - &local_ip.sin.sin_addr.s_addr, - dst_port, src_port, flow_flags, - dst_cache, info); + rt =udp_tunnel_dst_lookup (skb, dev, vxlan->net, ifindex, + &saddr, pkey, src_port, dst_port, + tos, use_cache ? dst_cache :NULL );if (IS_ERR (rt)) { err =PTR_ERR (rt); goto tx_error;
@@ -2612,16 +2580,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, }else if (err) {if (info) {struct ip_tunnel_info *unclone; -struct in_addr src, dst; unclone =skb_tunnel_info_unclone (skb);if (unlikely (!unclone)) goto tx_error; - src = remote_ip.sin.sin_addr; - dst = local_ip.sin.sin_addr; - unclone->key.u.ipv4.src = src.s_addr; - unclone->key.u.ipv4.dst = dst.s_addr; + unclone->key.u.ipv4.src = pkey->u.ipv4.dst; + unclone->key.u.ipv4.dst = saddr; }vxlan_encap_bypass (skb, vxlan, vxlan, vni, false);dst_release (ndst);
@@ -2635,8 +2600,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (err <0 ) goto tx_error; -udp_tunnel_xmit_skb (rt, sock4->sock->sk, skb, local_ip.sin.sin_addr.s_addr, - dst->sin.sin_addr.s_addr, tos, ttl, df, +udp_tunnel_xmit_skb (rt, sock4->sock->sk, skb, saddr, + pkey->u.ipv4.dst, tos, ttl, df, src_port, dst_port, xnet, !udp_sum);#if IS_ENABLED (CONFIG_IPV6 ) } else {
@@ -3146,11 +3111,14 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)struct vxlan_sock *sock4 =rcu_dereference (vxlan->vn4_sock);struct rtable *rt; - rt =vxlan_get_route (vxlan, dev, sock4, skb,0 , info->key.tos, - info->key.u.ipv4.dst, - &info->key.u.ipv4.src, dport, sport, - info->key.flow_flags, &info->dst_cache, - info); +if (!sock4) +return -EIO ; + + rt =udp_tunnel_dst_lookup (skb, dev, vxlan->net,0 , + &info->key.u.ipv4.src, + &info->key, + sport, dport, info->key.tos, + &info->dst_cache);if (IS_ERR (rt))return PTR_ERR (rt);ip_rt_put (rt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 570/1193 ipv6: remove "proto" argument from udp_tunnel6_dst_lookup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit 7e937dcf96d0489b3cdd1cff9dfd049617d28492 ]
The function is now UDP-specific, the protocol is always IPPROTO_UDP.
This is similar to what already done for IPv4 in commit 78f3655adcb5 ("ipv4: remove "proto" argument from udp_tunnel_dst_lookup()").
Stable-dep-of: be83178bfc44 ("vxlan: initialize _md in vxlan_xmit_one()")
--- drivers/net/bareudp.c | 5 ++--- include/net/udp_tunnel.h | 2 +- net/ipv6/ip6_udp_tunnel.c | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-)
drivers/net/bareudp.c +2 -3
@@ -394,7 +394,7 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,return -ESHUTDOWN ; dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, &saddr, info, -IPPROTO_UDP , use_cache); + use_cache);if (IS_ERR (dst))return PTR_ERR (dst);
@@ -524,8 +524,7 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,return -ESHUTDOWN ; dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, - &saddr, info,IPPROTO_UDP , - use_cache); + &saddr, info, use_cache);if (IS_ERR (dst))return PTR_ERR (dst);
include/net/udp_tunnel.h +1 -1
@@ -174,7 +174,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,struct socket *sock, struct in6_addr *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache); + bool use_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id,
net/ipv6/ip6_udp_tunnel.c +1 -3
@@ -120,7 +120,6 @@ EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb);* @sock: Socket which provides route info * @saddr: Memory to store the src ip address * @info: Tunnel information -* @protocol: IP protocol * @use_cache: Flag to enable cache usage * This function performs a route lookup on a UDP tunnel *
@@ -134,7 +133,6 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,struct socket *sock, struct in6_addr *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache) { struct dst_entry *dst = NULL;
@@ -154,7 +152,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,#endif memset (&fl6,0 ,sizeof (fl6)); fl6.flowi6_mark = skb->mark; - fl6.flowi6_proto = protocol; + fl6.flowi6_proto =IPPROTO_UDP ; fl6.daddr = info->key.u.ipv6.dst; fl6.saddr = info->key.u.ipv6.src; prio = info->key.tos;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 571/1193 ipv6: add new arguments to udp_tunnel6_dst_lookup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit 946fcfdbc5b97e26d31339ebca2d9a51a4f975ff ]
We want to make the function more generic so that it can be used by other UDP tunnel implementations such as geneve and vxlan. To do that, add the following arguments:
- source and destination UDP port;
- ifindex of the output interface, needed by vxlan;
- the tos, because in some cases it is not taken from struct ip_tunnel_info (for example, when it's inherited from the inner packet);
- the dst cache, because not all tunnel types (e.g. vxlan) want to use the one from struct ip_tunnel_info.
With these parameters, the function no longer needs the full struct ip_tunnel_info as argument and we can pass only the relevant part of it (struct ip_tunnel_key).
This is similar to what already done for IPv4 in commit 72fc68c6356b ("ipv4: add new arguments to udp_tunnel_dst_lookup()").
Stable-dep-of: be83178bfc44 ("vxlan: initialize _md in vxlan_xmit_one()")
--- drivers/net/bareudp.c | 10 +++++++--- include/net/udp_tunnel.h | 7 ++++--- net/ipv6/ip6_udp_tunnel.c | 33 ++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 21 deletions(-)
drivers/net/bareudp.c +7 -3
@@ -393,8 +393,10 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,if (!sock)return -ESHUTDOWN ; - dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, &saddr, info, - use_cache); + dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock,0 , &saddr, + key,0 ,0 , key->tos, + use_cache ? + (struct dst_cache *) &info->dst_cache :NULL );if (IS_ERR (dst))return PTR_ERR (dst);
@@ -524,7 +526,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,return -ESHUTDOWN ; dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, - &saddr, info, use_cache); +0 , &saddr, &info->key, +0 ,0 , info->key.tos, + use_cache ? &info->dst_cache :NULL );if (IS_ERR (dst))return PTR_ERR (dst);
include/net/udp_tunnel.h +4 -3
@@ -171,10 +171,11 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,struct dst_entry *udp_tunnel6_dst_lookup (struct sk_buff *skb,struct net_device *dev,struct net *net, -struct socket *sock, +struct socket *sock,int oif,struct in6_addr *saddr, -const struct ip_tunnel_info *info, -bool use_cache); +const struct ip_tunnel_key *key, +__be16 sport,__be16 dport,u8 dsfield, +struct dst_cache *dst_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id,
net/ipv6/ip6_udp_tunnel.c +18 -15
@@ -118,9 +118,13 @@ EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb);* @dev: Tunnel device * @net: Network namespace of tunnel device * @sock: Socket which provides route info +* @oif: Index of the output interface * @saddr: Memory to store the src ip address -* @info: Tunnel information -* @use_cache: Flag to enable cache usage +* @key: Tunnel information +* @sport: UDP source port +* @dport: UDP destination port +* @dsfield: The traffic class field +* @dst_cache: The dst cache to use for lookup * This function performs a route lookup on a UDP tunnel * * It returns a valid dst pointer and stores src address to be used in
@@ -131,20 +135,17 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,struct net_device *dev, struct net *net, struct socket *sock, + int oif, struct in6_addr *saddr, - const struct ip_tunnel_info *info, - bool use_cache) + const struct ip_tunnel_key *key, + __be16 sport, __be16 dport, u8 dsfield, + struct dst_cache *dst_cache) { struct dst_entry *dst = NULL; -#ifdef CONFIG_DST_CACHE -struct dst_cache *dst_cache; -#endif struct flowi6 fl6; -__u8 prio; #ifdef CONFIG_DST_CACHE - dst_cache = (struct dst_cache *)&info->dst_cache; - if (use_cache) { + if (dst_cache) { dst = dst_cache_get_ip6(dst_cache, saddr); if (dst) return dst;
@@ -153,10 +154,12 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,memset (&fl6,0 ,sizeof (fl6)); fl6.flowi6_mark = skb->mark; fl6.flowi6_proto =IPPROTO_UDP ; - fl6.daddr = info->key.u.ipv6.dst; - fl6.saddr = info->key.u.ipv6.src; - prio = info->key.tos; - fl6.flowlabel =ip6_make_flowinfo (prio, info->key.label); + fl6.flowi6_oif = oif; + fl6.daddr = key->u.ipv6.dst; + fl6.saddr = key->u.ipv6.src; + fl6.fl6_sport = sport; + fl6.fl6_dport = dport; + fl6.flowlabel =ip6_make_flowinfo (dsfield, key->label); dst = ipv6_stub->ipv6_dst_lookup_flow (net, sock->sk, &fl6,NULL );
@@ -170,7 +173,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,return ERR_PTR (-ELOOP ); }#ifdef CONFIG_DST_CACHE -if (use_cache) +if (dst_cache)dst_cache_set_ip6 (dst_cache, dst, &fl6.saddr);#endif *saddr = fl6.saddr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 572/1193 vxlan: use generic function for tunnel IPv6 route lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit 2aceb896ee18ae35b21b14c978d8c2ef8c7b439d ]
The route lookup can be done now via generic function udp_tunnel6_dst_lookup() to replace the custom implementation in vxlan6_get_route().
This is similar to what already done for IPv4 in commit 6f19b2c136d9 ("vxlan: use generic function for tunnel IPv4 route lookup").
Stable-dep-of: be83178bfc44 ("vxlan: initialize _md in vxlan_xmit_one()")
--- drivers/net/vxlan/vxlan_core.c | 136 ++++++++------------------------- 1 file changed, 30 insertions(+), 106 deletions(-)
drivers/net/vxlan/vxlan_core.c +30 -106
@@ -2266,63 +2266,6 @@ static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst,return 0 ; } -#if IS_ENABLED (CONFIG_IPV6 ) -static struct dst_entry *vxlan6_get_route (struct vxlan_dev *vxlan, -struct net_device *dev, -struct vxlan_sock *sock6, -struct sk_buff *skb,int oif,u8 tos, -__be32 label, -const struct in6_addr *daddr, -struct in6_addr *saddr, -__be16 dport,__be16 sport, -struct dst_cache *dst_cache, -const struct ip_tunnel_info *info) -{ -bool use_cache =ip_tunnel_dst_cache_usable (skb, info); -struct dst_entry *ndst; -struct flowi6 fl6; - -if (!sock6) -return ERR_PTR (-EIO ); - -if (tos && !info) - use_cache = false; -if (use_cache) { - ndst =dst_cache_get_ip6 (dst_cache, saddr); -if (ndst) -return ndst; - } - -memset (&fl6,0 ,sizeof (fl6)); - fl6.flowi6_oif = oif; - fl6.daddr = *daddr; - fl6.saddr = *saddr; - fl6.flowlabel =ip6_make_flowinfo (tos, label); - fl6.flowi6_mark = skb->mark; - fl6.flowi6_proto =IPPROTO_UDP ; - fl6.fl6_dport = dport; - fl6.fl6_sport = sport; - - ndst = ipv6_stub->ipv6_dst_lookup_flow (vxlan->net, sock6->sock->sk, - &fl6,NULL ); -if (IS_ERR (ndst)) { -netdev_dbg (dev,"no route to %pI6\n" , daddr); -return ERR_PTR (-ENETUNREACH ); - } - -if (unlikely (ndst->dev == dev)) { -netdev_dbg (dev,"circular route to %pI6\n" , daddr); -dst_release (ndst); -return ERR_PTR (-ELOOP ); - } - - *saddr = fl6.saddr; -if (use_cache) -dst_cache_set_ip6 (dst_cache, ndst, saddr); -return ndst; -} -#endif -/* Bypass encapsulation if the destination is local */ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, struct vxlan_dev *dst_vxlan, __be32 vni,
@@ -2376,7 +2319,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,static int encap_bypass_if_local (struct sk_buff *skb,struct net_device *dev,struct vxlan_dev *vxlan, -union vxlan_addr *daddr, +int addr_family,__be16 dst_port,int dst_ifindex,__be32 vni,struct dst_entry *dst,u32 rt_flags)
@@ -2396,7 +2339,7 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev,dst_release (dst); dst_vxlan =vxlan_find_vni (vxlan->net, dst_ifindex, vni, - daddr->sa.sa_family, dst_port, + addr_family, dst_port, vxlan->cfg.flags);if (!dst_vxlan) {DEV_STATS_INC (dev, tx_errors);
@@ -2422,13 +2365,12 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,struct ip_tunnel_key key;struct vxlan_dev *vxlan =netdev_priv (dev);const struct iphdr *old_iph =ip_hdr (skb); -union vxlan_addr *dst; -union vxlan_addr remote_ip;struct vxlan_metadata _md;struct vxlan_metadata *md = &_md;unsigned int pkt_len = skb->len;__be16 src_port =0 , dst_port;struct dst_entry *ndst =NULL ; +int addr_family;__u8 tos, ttl;int ifindex;int err;
@@ -2437,20 +2379,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,bool udp_sum = false;bool xnet = !net_eq (vxlan->net,dev_net (vxlan->dev));__be32 vni =0 ; -#if IS_ENABLED (CONFIG_IPV6 ) -union vxlan_addr local_ip; -__be32 label; -#endif info =skb_tunnel_info (skb); use_cache =ip_tunnel_dst_cache_usable (skb, info);if (rdst) { - dst = &rdst->remote_ip;memset (&key,0 ,sizeof (key)); pkey = &key; -if (vxlan_addr_any (dst)) { +if (vxlan_addr_any (&rdst->remote_ip)) {if (did_rsc) {/* short-circuited back to local bridge */ vxlan_encap_bypass(skb, vxlan, vxlan,
@@ -2460,11 +2397,12 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, goto drop; } + addr_family = vxlan->cfg.saddr.sa.sa_family; dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; vni = (rdst->remote_vni) ? : default_vni; ifindex = rdst->remote_ifindex; -if (dst->sa.sa_family ==AF_INET ) { +if (addr_family ==AF_INET ) { key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr; key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr; }else {
@@ -2478,23 +2416,21 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, ttl =ip_tunnel_get_ttl (old_iph, skb); }else { ttl = vxlan->cfg.ttl; -if (!ttl &&vxlan_addr_multicast (dst)) +if (!ttl &&vxlan_addr_multicast (&rdst->remote_ip)) ttl =1 ; } - tos = vxlan->cfg.tos;if (tos ==1 ) tos =ip_tunnel_get_dsfield (old_iph, skb);if (tos && !info) use_cache = false; -if (dst->sa.sa_family ==AF_INET ) +if (addr_family ==AF_INET ) udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM_TX );else udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM6_TX );#if IS_ENABLED (CONFIG_IPV6 ) - local_ip = vxlan->cfg.saddr; - label = vxlan->cfg.label; + key.label = vxlan->cfg.label;#endif }else {if (!info) {
@@ -2502,17 +2438,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, dev->name); goto drop; } - remote_ip.sa.sa_family =ip_tunnel_info_af (info); -if (remote_ip.sa.sa_family ==AF_INET ) { - remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst; - }else { - remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst; -#if IS_ENABLED (CONFIG_IPV6 ) - local_ip.sin6.sin6_addr = info->key.u.ipv6.src; -#endif - } - dst = &remote_ip; pkey = &info->key; + addr_family =ip_tunnel_info_af (info); dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; vni =tunnel_id_to_key32 (info->key.tun_id); ifindex =0 ;
@@ -2524,16 +2451,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, } ttl = info->key.ttl; tos = info->key.tos; -#if IS_ENABLED (CONFIG_IPV6 ) - label = info->key.label; -#endif udp_sum = !!(info->key.tun_flags &TUNNEL_CSUM ); } src_port =udp_flow_src_port (dev_net (dev), skb, vxlan->cfg.port_min, vxlan->cfg.port_max, true);rcu_read_lock (); -if (dst->sa.sa_family ==AF_INET ) { +if (addr_family ==AF_INET ) {struct vxlan_sock *sock4 =rcu_dereference (vxlan->vn4_sock);struct rtable *rt;__be16 df =0 ;
@@ -2552,7 +2476,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (!info) {/* Bypass encapsulation if the destination is local */ - err =encap_bypass_if_local (skb, dev, vxlan, dst, + err =encap_bypass_if_local (skb, dev, vxlan,AF_INET , dst_port, ifindex, vni, &rt->dst, rt->rt_flags);if (err)
@@ -2606,15 +2530,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,#if IS_ENABLED (CONFIG_IPV6 ) } else {struct vxlan_sock *sock6 =rcu_dereference (vxlan->vn6_sock); +struct in6_addr saddr;if (!ifindex) ifindex = sock6->sock->sk->sk_bound_dev_if; - ndst =vxlan6_get_route (vxlan, dev, sock6, skb, ifindex, tos, - label, &dst->sin6.sin6_addr, - &local_ip.sin6.sin6_addr, - dst_port, src_port, - dst_cache, info); + ndst =udp_tunnel6_dst_lookup (skb, dev, vxlan->net, sock6->sock, + ifindex, &saddr, pkey, + src_port, dst_port, tos, + use_cache ? dst_cache :NULL );if (IS_ERR (ndst)) { err =PTR_ERR (ndst); ndst =NULL ;
@@ -2624,7 +2548,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (!info) {u32 rt6i_flags =dst_rt6_info (ndst)->rt6i_flags; - err =encap_bypass_if_local (skb, dev, vxlan, dst, + err =encap_bypass_if_local (skb, dev, vxlan,AF_INET6 , dst_port, ifindex, vni, ndst, rt6i_flags);if (err)
@@ -2639,16 +2563,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, }else if (err) {if (info) {struct ip_tunnel_info *unclone; -struct in6_addr src, dst; unclone =skb_tunnel_info_unclone (skb);if (unlikely (!unclone)) goto tx_error; - src = remote_ip.sin6.sin6_addr; - dst = local_ip.sin6.sin6_addr; - unclone->key.u.ipv6.src = src; - unclone->key.u.ipv6.dst = dst; + unclone->key.u.ipv6.src = pkey->u.ipv6.dst; + unclone->key.u.ipv6.dst = saddr; }vxlan_encap_bypass (skb, vxlan, vxlan, vni, false);
@@ -2665,9 +2586,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, goto tx_error;udp_tunnel6_xmit_skb (ndst, sock6->sock->sk, skb, dev, - &local_ip.sin6.sin6_addr, - &dst->sin6.sin6_addr, tos, ttl, - label, src_port, dst_port, !udp_sum); + &saddr, &pkey->u.ipv6.dst, tos, ttl, + pkey->label, src_port, dst_port, !udp_sum);#endif }vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX , pkt_len);
@@ -3127,10 +3047,14 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)struct vxlan_sock *sock6 =rcu_dereference (vxlan->vn6_sock);struct dst_entry *ndst; - ndst =vxlan6_get_route (vxlan, dev, sock6, skb,0 , info->key.tos, - info->key.label, &info->key.u.ipv6.dst, - &info->key.u.ipv6.src, dport, sport, - &info->dst_cache, info); +if (!sock6) +return -EIO ; + + ndst =udp_tunnel6_dst_lookup (skb, dev, vxlan->net, sock6->sock, +0 , &info->key.u.ipv6.src, + &info->key, + sport, dport, info->key.tos, + &info->dst_cache);if (IS_ERR (ndst))return PTR_ERR (ndst);dst_release (ndst);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 573/1193 vxlan: Pull inner IP header in vxlan_xmit_one().
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
[ Upstream commit 31392048f55f98cb01ca709d32d06d926ab9760a ]
Ensure the inner IP header is part of the skb's linear data before setting old_iph. Otherwise, on a non-linear skb, old_iph could point outside of the packet data.
Unlike classical VXLAN, which always encapsulates Ethernet packets, VXLAN-GPE can transport IP packets directly. In that case, we need to look at skb->protocol to figure out if an Ethernet header is present.
Stable-dep-of: be83178bfc44 ("vxlan: initialize _md in vxlan_xmit_one()")
--- drivers/net/vxlan/vxlan_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +8 -1
@@ -2364,7 +2364,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,struct ip_tunnel_key *pkey;struct ip_tunnel_key key;struct vxlan_dev *vxlan =netdev_priv (dev); -const struct iphdr *old_iph =ip_hdr (skb); +const struct iphdr *old_iph;struct vxlan_metadata _md;struct vxlan_metadata *md = &_md;unsigned int pkt_len = skb->len;
@@ -2378,8 +2378,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,bool use_cache;bool udp_sum = false;bool xnet = !net_eq (vxlan->net,dev_net (vxlan->dev)); +bool no_eth_encap;__be32 vni =0 ; + no_eth_encap = flags &VXLAN_F_GPE && skb->protocol !=htons (ETH_P_TEB ); +if (!skb_vlan_inet_prepare (skb, no_eth_encap)) + goto drop; + + old_iph =ip_hdr (skb); + info =skb_tunnel_info (skb); use_cache =ip_tunnel_dst_cache_usable (skb, info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 574/1193 vxlan: initialize _md in vxlan_xmit_one()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit be83178bfc44588f6e3adb827ed874c683193466 ]
If a VXLAN device is configured with both VXLAN_F_COLLECT_METADATA and VXLAN_F_GBP, and a packet is transmitted through it using an external ip_tunnel_info that lacks the IP_TUNNEL_VXLAN_OPT_BIT flag, md is left pointing to the uninitialized _md stack variable:
if (test_bit(IP_TUNNEL_VXLAN_OPT_BIT, info->key.tun_flags)) {
if (info->options_len < sizeof(*md))
goto drop;
md = ip_tunnel_info_opts(info);
}Because IP_TUNNEL_VXLAN_OPT_BIT is not set, md is not updated and remains pointing to _md. Later, vxlan_build_skb() is called with md, which eventually calls vxlan_build_gbp_hdr():
if (vxflags & VXLAN_F_GBP)
vxlan_build_gbp_hdr(vxh, md);
Inside vxlan_build_gbp_hdr(), md->gbp is read:
if (!md->gbp)
return;
gbp = (struct vxlanhdr_gbp *)vxh;
...
if (md->gbp & VXLAN_GBP_DONT_LEARN)
gbp->dont_learn = 1;If the stack contains garbage, this causes:
1) VXLAN_HF_GBP flag to be spuriously set in the VXLAN header.
2) gbp->dont_learn and gbp->policy_applied to be set from stack bits.
3) gbp->policy_id to receive 16 bits of uninitialized kernel stack data, leaking it onto the wire.
Fix this by zero-initializing _md. If IP_TUNNEL_VXLAN_OPT_BIT is not present, md->gbp remains 0, and vxlan_build_gbp_hdr() returns early without modifying the VXLAN header.
--- drivers/net/vxlan/vxlan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +1 -1
@@ -2365,7 +2365,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,struct ip_tunnel_key key;struct vxlan_dev *vxlan =netdev_priv (dev);const struct iphdr *old_iph; -struct vxlan_metadata _md; +struct vxlan_metadata _md = {};struct vxlan_metadata *md = &_md;unsigned int pkt_len = skb->len;__be16 src_port =0 , dst_port;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 575/1193 ppp_synctty: ensure a writeable skb header
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingfang Deng <[email protected]>
[ Upstream commit 8aaeb56aff2a557a88f83ae866da2c91ad247e59 ]
ppp_sync_txmunge() checks headroom before prepending the address and control bytes, but does not ensure that the skb header is writable. A received skb can reach this function through PPP channel bridging without passing through ppp_start_xmit(), which calls skb_cow_head().
For example, a PPPoE frame may share its buffer with a clone queued to an AF_PACKET socket. If it is bridged to a synchronous tty channel, the address/control bytes can overwrite data still visible to that socket.
Use skb_cow_head() to ensure both sufficient headroom and a writable header.
--- drivers/net/ppp/ppp_synctty.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/net/ppp/ppp_synctty.c +3 -11
@@ -526,17 +526,9 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)/* prepend address/control fields if necessary */ if ((ap->flags &SC_COMP_AC ) ==0 || islcp) { -if (skb_headroom (skb) <2 ) { -struct sk_buff *npkt =dev_alloc_skb (skb->len +2 ); -if (npkt ==NULL ) { -kfree_skb (skb); -return NULL ; - } -skb_reserve (npkt,2 ); -skb_copy_from_linear_data (skb, -skb_put (npkt, skb->len), skb->len); -consume_skb (skb); - skb = npkt; +if (skb_cow_head (skb,2 )) { +kfree_skb (skb); +return NULL ; }skb_push (skb,2 ); skb->data[0 ] =PPP_ALLSTATIONS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 576/1193 net: stmmac: initialize ptp_lock at probe time
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit 0338c68e22abd2ee509ec2e32508a50896618c32 ]
priv->ptp_lock is only initialized in stmmac_ptp_register(), which runs during __stmmac_open(). However, the lock is also used while the interface is down and has never been opened: tc_taprio_configure() invokes the PTP gettime64() callback to compute the EST base time when offloading a TAPRIO schedule, and stmmac_get_time() takes priv->ptp_lock. Using an uninitialized rwlock is undefined behaviour. Move the rwlock_init() to __stmmac_dvr_probe(), together with the other private locks, so that ptp_lock is always valid regardless of the interface state.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -7588,6 +7588,7 @@ int stmmac_dvr_probe(struct device *device,stmmac_napi_add (ndev);mutex_init (&priv->lock); +rwlock_init (&priv->ptp_lock);/* If a specific clk_csr value is passed from the platform * this means that the CSR Clock Range selection cannot be
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +0 -1
@@ -301,7 +301,6 @@ void stmmac_ptp_register(struct stmmac_priv *priv) stmmac_ptp_clock_ops.n_per_out = priv->dma_cap.pps_out_num; stmmac_ptp_clock_ops.n_ext_ts = priv->dma_cap.aux_snapshot_n; -rwlock_init (&priv->ptp_lock);mutex_init (&priv->aux_ts_lock); priv->ptp_clock_ops = stmmac_ptp_clock_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 577/1193 selftests/powerpc/tm: Fix tcheck() reading uninitialised CR value
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thibault Ferrante <[email protected]>
[ Upstream commit ed28b16eab705071d28edaace47189c2eb3aa108 ]
tcheck() is used to check the current transaction state (active, suspended, doomed) via the "tcheck" instruction, which writes its result into CR field 0. The inline asm declared a GPR output operand for this result but never actually moved the CR into it.
Every caller (tcheck_doomed(), tcheck_active(), tcheck_suspended(), tcheck_transactional()) has effectively been testing bits of an unrelated, arbitrary register value since this helper was introduced.
The "& 4" mask discards the TDOOMED and TS_lsb (suspended) bits before they ever reach the callers, so tcheck_doomed() and tcheck_suspended() can never return true, and tcheck_transactional() degrades to being equivalent to tcheck_active().
Fix tcheck() to actually move CR into the output register with mfcr, and widen the mask from "& 4" to "& 0xf" so the full CR0 nibble (TDOOMED | TS_msb | TS_lsb | reserved) is preserved for the callers.
This bug has been present since tcheck() was introduced.
--- tools/testing/selftests/powerpc/tm/tm.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/powerpc/tm/tm.h +6 -2
@@ -105,8 +105,12 @@ static inline bool failure_is_nesting(void)static inline int tcheck (void ) {long cr; - asmvolatile ("tcheck 0" :"=r" (cr) : :"cr0" ); -return (cr >>28 ) &4 ; + asmvolatile ("tcheck 0;" +"mfcr %0;" + :"=r" (cr) + : + :"cr0" ); +return (cr >>28 ) &0xf ; }static inline bool tcheck_doomed (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 578/1193 perf/core: Check sample_type in perf_sample_save_callchain
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yabin Cui <[email protected]>
[ Upstream commit f226805bc5f60adf03783d8e4cbfe303ccecd64e ]
Check sample_type in perf_sample_save_callchain() to prevent saving callchain data when it isn't required.
Stable-dep-of: 88aa1223bfff ("perf/x86/intel: Correct pt_regs->flags update for PEBS path")
--- arch/x86/events/amd/ibs.c | 3 +-- arch/x86/events/intel/ds.c | 6 ++---- include/linux/perf_event.h | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/events/amd/ibs.c +1 -2
@@ -1135,8 +1135,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)* recorded as part of interrupt regs. Thus we need to use rip from * interrupt regs while unwinding call stack. */ -if (event->attr.sample_type &PERF_SAMPLE_CALLCHAIN ) -perf_sample_save_callchain (&data, event, iregs); +perf_sample_save_callchain (&data, event, iregs); throttle =perf_event_overflow (event, &data, ®s); out:
arch/x86/events/intel/ds.c +2 -4
@@ -1656,8 +1656,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,* previous PMI context or an (I)RET happened between the record and * PMI. */ -if (sample_type &PERF_SAMPLE_CALLCHAIN ) -perf_sample_save_callchain (data, event, iregs); +perf_sample_save_callchain (data, event, iregs);/* * We use the interrupt regs as a base because the PEBS record does not
@@ -1824,8 +1823,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,* previous PMI context or an (I)RET happened between the record and * PMI. */ -if (sample_type &PERF_SAMPLE_CALLCHAIN ) -perf_sample_save_callchain (data, event, iregs); +perf_sample_save_callchain (data, event, iregs); *regs = *iregs;/* The ip in basic is EventingIP */
include/linux/perf_event.h +5 -0
@@ -1229,6 +1229,11 @@ static inline void perf_sample_save_callchain(struct perf_sample_data *data, {int size =1 ; +if (!(event->attr.sample_type &PERF_SAMPLE_CALLCHAIN )) +return ; +if (WARN_ON_ONCE (data->sample_flags &PERF_SAMPLE_CALLCHAIN )) +return ; + data->callchain =perf_callchain (event, regs); size += data->callchain->nr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 579/1193 perf/x86/intel/ds: Clarify adaptive PEBS processing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kan Liang <[email protected]>
[ Upstream commit 7087bfb0adc9a12ec3b463b1d38072c5efce5d6c ]
Modify the pebs_basic and pebs_meminfo structs to make the bitfields more explicit to ease readability of the code.
Stable-dep-of: 88aa1223bfff ("perf/x86/intel: Correct pt_regs->flags update for PEBS path")
--- arch/x86/events/intel/ds.c | 43 ++++++++++++++----------------- arch/x86/include/asm/perf_event.h | 16 ++++++++++-- 2 files changed, 34 insertions(+), 25 deletions(-)
arch/x86/events/intel/ds.c +20 -23
@@ -1783,8 +1783,6 @@ static void adaptive_pebs_save_regs(struct pt_regs *regs, }#define PEBS_LATENCY_MASK 0xffff -#define PEBS_CACHE_LATENCY_OFFSET 32 -#define PEBS_RETIRE_LATENCY_OFFSET 32/* * With adaptive PEBS the layout depends on what fields are configured.
@@ -1798,8 +1796,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);struct pebs_basic *basic = __pebs;void *next_record = basic +1 ; -u64 sample_type; -u64 format_size; +u64 sample_type, format_group;struct pebs_meminfo *meminfo =NULL ;struct pebs_gprs *gprs =NULL ;struct x86_perf_regs *perf_regs;
@@ -1811,7 +1808,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, perf_regs->xmm_regs =NULL ; sample_type = event->attr.sample_type; - format_size = basic->format_size; + format_group = basic->format_group;perf_sample_data_init (data,0 , event->hw.last_period); data->period = event->hw.last_period;
@@ -1832,7 +1829,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,if (sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) {if (x86_pmu.flags &PMU_FL_RETIRE_LATENCY ) - data->weight.var3_w = format_size >>PEBS_RETIRE_LATENCY_OFFSET &PEBS_LATENCY_MASK ; + data->weight.var3_w = basic->retire_latency;else data->weight.var3_w =0 ; }
@@ -1842,12 +1839,12 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,* But PERF_SAMPLE_TRANSACTION needs gprs->ax. * Save the pointer here but process later. */ -if (format_size &PEBS_DATACFG_MEMINFO ) { +if (format_group &PEBS_DATACFG_MEMINFO ) { meminfo = next_record; next_record = meminfo +1 ; } -if (format_size &PEBS_DATACFG_GP ) { +if (format_group &PEBS_DATACFG_GP ) { gprs = next_record; next_record = gprs +1 ;
@@ -1860,14 +1857,13 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,adaptive_pebs_save_regs (regs, gprs); } -if (format_size &PEBS_DATACFG_MEMINFO ) { +if (format_group &PEBS_DATACFG_MEMINFO ) {if (sample_type &PERF_SAMPLE_WEIGHT_TYPE ) { -u64 weight = meminfo->latency; +u64 latency = x86_pmu.flags &PMU_FL_INSTR_LATENCY ? + meminfo->cache_latency : meminfo->mem_latency; -if (x86_pmu.flags &PMU_FL_INSTR_LATENCY ) { - data->weight.var2_w = weight &PEBS_LATENCY_MASK ; - weight >>=PEBS_CACHE_LATENCY_OFFSET ; - } +if (x86_pmu.flags &PMU_FL_INSTR_LATENCY ) + data->weight.var2_w = meminfo->instr_latency;/* * Although meminfo::latency is defined as a u64,
@@ -1875,12 +1871,13 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,* in practice on Ice Lake and earlier platforms. */ if (sample_type &PERF_SAMPLE_WEIGHT ) { - data->weight.full = weight ?: + data->weight.full = latency ?:intel_get_tsx_weight (meminfo->tsx_tuning); }else { - data->weight.var1_dw = (u32)(weight &PEBS_LATENCY_MASK ) ?: + data->weight.var1_dw = (u32 )latency ?:intel_get_tsx_weight (meminfo->tsx_tuning); } + data->sample_flags |=PERF_SAMPLE_WEIGHT_TYPE ; }
@@ -1901,16 +1898,16 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, } } -if (format_size &PEBS_DATACFG_XMMS ) { +if (format_group &PEBS_DATACFG_XMMS ) {struct pebs_xmm *xmm = next_record; next_record = xmm +1 ; perf_regs->xmm_regs = xmm->xmm; } -if (format_size &PEBS_DATACFG_LBRS ) { +if (format_group &PEBS_DATACFG_LBRS ) {struct lbr_entry *lbr = next_record; -int num_lbr = ((format_size >>PEBS_DATACFG_LBR_SHIFT ) +int num_lbr = ((format_group >>PEBS_DATACFG_LBR_SHIFT ) &0xff ) +1 ; next_record = next_record + num_lbr *sizeof (struct lbr_entry );
@@ -1920,11 +1917,11 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, } } -WARN_ONCE (next_record != __pebs + (format_size >>48 ), -"PEBS record size %llu, expected %llu, config %llx\n" , - format_size >>48 , +WARN_ONCE (next_record != __pebs + basic->format_size, +"PEBS record size %u, expected %llu, config %llx\n" , + basic->format_size, (u64)(next_record - __pebs), - basic->format_size); + format_group); } static inline void *
arch/x86/include/asm/perf_event.h +14 -2
@@ -425,7 +425,9 @@ static inline bool is_topdown_idx(int idx)*/ struct pebs_basic { -u64 format_size; +u64 format_group:32 , + retire_latency:16 , + format_size:16 ;u64 ip;u64 applicable_counters;u64 tsc;
@@ -434,7 +436,17 @@ struct pebs_basic {struct pebs_meminfo {u64 address;u64 aux; -u64 latency; +union { +/* pre Alder Lake */ +u64 mem_latency; +/* Alder Lake and later */ +struct { +u64 instr_latency:16 ; +u64 pad2:16 ; +u64 cache_latency:16 ; +u64 pad3:16 ; + }; + };u64 tsx_tuning; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 580/1193 perf/x86/intel/ds: Remove redundant assignments to sample.period
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Changbin Du <[email protected]>
[ Upstream commit 75a9001bab36f0456f6aae1ab0aa487db456464a ]
The perf_sample_data_init() has already set the period of sample, so no need to do it again.
Stable-dep-of: 88aa1223bfff ("perf/x86/intel: Correct pt_regs->flags update for PEBS path")
--- arch/x86/events/intel/ds.c | 3 --- 1 file changed, 3 deletions(-)
arch/x86/events/intel/ds.c +0 -3
@@ -1632,8 +1632,6 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,perf_sample_data_init (data,0 , event->hw.last_period); - data->period = event->hw.last_period; -/* * Use latency for weight (only avail with PEBS-LL) */
@@ -1810,7 +1808,6 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, sample_type = event->attr.sample_type; format_group = basic->format_group;perf_sample_data_init (data,0 , event->hw.last_period); - data->period = event->hw.last_period;setup_pebs_time (event, data, basic->tsc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 581/1193 perf/x86/intel/ds: Factor out PEBS group processing code to functions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit 167cde7dc9b36b7a88f3c29d836fabce13023327 ]
Adaptive PEBS and arch-PEBS share lots of same code to process these PEBS groups, like basic, GPR and meminfo groups. Extract these shared code to generic functions to avoid duplicated code.
Stable-dep-of: 88aa1223bfff ("perf/x86/intel: Correct pt_regs->flags update for PEBS path")
--- arch/x86/events/intel/ds.c | 170 +++++++++++++++++++++++-------------- 1 file changed, 104 insertions(+), 66 deletions(-)
arch/x86/events/intel/ds.c +104 -66
@@ -1782,6 +1782,90 @@ static void adaptive_pebs_save_regs(struct pt_regs *regs,#define PEBS_LATENCY_MASK 0xffff +static inline void __setup_perf_sample_data (struct perf_event *event, +struct pt_regs *iregs, +struct perf_sample_data *data) +{ +perf_sample_data_init (data,0 , event->hw.last_period); + +/* +* We must however always use iregs for the unwinder to stay sane; the +* record BP,SP,IP can point into thin air when the record is from a +* previous PMI context or an (I)RET happened between the record and +* PMI. +*/ +perf_sample_save_callchain (data, event, iregs); +} + +static inline void __setup_pebs_basic_group (struct perf_event *event, +struct pt_regs *regs, +struct perf_sample_data *data, +u64 sample_type,u64 ip, +u64 tsc,u16 retire) +{ +/* The ip in basic is EventingIP */ +set_linear_ip (regs, ip); + regs->flags =PERF_EFLAGS_EXACT ; +setup_pebs_time (event, data, tsc); + +if (sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) + data->weight.var3_w = retire; +} + +static inline void __setup_pebs_gpr_group (struct perf_event *event, +struct pt_regs *regs, +struct pebs_gprs *gprs, +u64 sample_type) +{ +if (event->attr.precise_ip <2 ) { +set_linear_ip (regs, gprs->ip); + regs->flags &= ~PERF_EFLAGS_EXACT ; + } + +if (sample_type & (PERF_SAMPLE_REGS_INTR |PERF_SAMPLE_REGS_USER )) +adaptive_pebs_save_regs (regs, gprs); +} + +static inline void __setup_pebs_meminfo_group (struct perf_event *event, +struct perf_sample_data *data, +u64 sample_type,u64 latency, +u16 instr_latency,u64 address, +u64 aux,u64 tsx_tuning,u64 ax) +{ +if (sample_type &PERF_SAMPLE_WEIGHT_TYPE ) { +u64 tsx_latency =intel_get_tsx_weight (tsx_tuning); + + data->weight.var2_w = instr_latency; + +/* +* Although meminfo::latency is defined as a u64, +* only the lower 32 bits include the valid data +* in practice on Ice Lake and earlier platforms. +*/ +if (sample_type &PERF_SAMPLE_WEIGHT ) + data->weight.full = latency ?: tsx_latency; +else + data->weight.var1_dw = (u32 )latency ?: tsx_latency; + + data->sample_flags |=PERF_SAMPLE_WEIGHT_TYPE ; + } + +if (sample_type &PERF_SAMPLE_DATA_SRC ) { + data->data_src.val =get_data_src (event, aux); + data->sample_flags |=PERF_SAMPLE_DATA_SRC ; + } + +if (sample_type &PERF_SAMPLE_ADDR_TYPE ) { + data->addr = address; + data->sample_flags |=PERF_SAMPLE_ADDR ; + } + +if (sample_type &PERF_SAMPLE_TRANSACTION ) { + data->txn =intel_get_tsx_transaction (tsx_tuning, ax); + data->sample_flags |=PERF_SAMPLE_TRANSACTION ; + } +} +/* * With adaptive PEBS the layout depends on what fields are configured. */
@@ -1792,12 +1876,14 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, struct pt_regs *regs) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +u64 sample_type = event->attr.sample_type;struct pebs_basic *basic = __pebs;void *next_record = basic +1 ; -u64 sample_type, format_group;struct pebs_meminfo *meminfo =NULL ;struct pebs_gprs *gprs =NULL ;struct x86_perf_regs *perf_regs; +u64 format_group; +u16 retire;if (basic ==NULL )return ;
@@ -1805,31 +1891,17 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, perf_regs = container_of(regs, struct x86_perf_regs, regs); perf_regs->xmm_regs =NULL ; - sample_type = event->attr.sample_type; format_group = basic->format_group; -perf_sample_data_init (data,0 , event->hw.last_period); -setup_pebs_time (event, data, basic->tsc); - -/* -* We must however always use iregs for the unwinder to stay sane; the -* record BP,SP,IP can point into thin air when the record is from a -* previous PMI context or an (I)RET happened between the record and -* PMI. -*/ -perf_sample_save_callchain (data, event, iregs); +__setup_perf_sample_data (event, iregs, data); *regs = *iregs; -/* The ip in basic is EventingIP */ -set_linear_ip (regs, basic->ip); - regs->flags =PERF_EFLAGS_EXACT ; -if (sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) { -if (x86_pmu.flags &PMU_FL_RETIRE_LATENCY ) - data->weight.var3_w = basic->retire_latency; -else - data->weight.var3_w =0 ; - } +/* basic group */ + retire = x86_pmu.flags &PMU_FL_RETIRE_LATENCY ? + basic->retire_latency :0 ; +__setup_pebs_basic_group (event, regs, data, sample_type, + basic->ip, basic->tsc, retire);/* * The record for MEMINFO is in front of GP
@@ -1845,54 +1917,20 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, gprs = next_record; next_record = gprs +1 ; -if (event->attr.precise_ip <2 ) { -set_linear_ip (regs, gprs->ip); - regs->flags &= ~PERF_EFLAGS_EXACT ; - } - -if (sample_type & (PERF_SAMPLE_REGS_INTR |PERF_SAMPLE_REGS_USER )) -adaptive_pebs_save_regs (regs, gprs); +__setup_pebs_gpr_group (event, regs, gprs, sample_type); }if (format_group &PEBS_DATACFG_MEMINFO ) { -if (sample_type &PERF_SAMPLE_WEIGHT_TYPE ) { -u64 latency = x86_pmu.flags &PMU_FL_INSTR_LATENCY ? - meminfo->cache_latency : meminfo->mem_latency; - -if (x86_pmu.flags &PMU_FL_INSTR_LATENCY ) - data->weight.var2_w = meminfo->instr_latency; - -/* -* Although meminfo::latency is defined as a u64, -* only the lower 32 bits include the valid data -* in practice on Ice Lake and earlier platforms. -*/ -if (sample_type &PERF_SAMPLE_WEIGHT ) { - data->weight.full = latency ?: -intel_get_tsx_weight (meminfo->tsx_tuning); - }else { - data->weight.var1_dw = (u32 )latency ?: -intel_get_tsx_weight (meminfo->tsx_tuning); - } - - data->sample_flags |=PERF_SAMPLE_WEIGHT_TYPE ; - } - -if (sample_type &PERF_SAMPLE_DATA_SRC ) { - data->data_src.val =get_data_src (event, meminfo->aux); - data->sample_flags |=PERF_SAMPLE_DATA_SRC ; - } - -if (sample_type &PERF_SAMPLE_ADDR_TYPE ) { - data->addr = meminfo->address; - data->sample_flags |=PERF_SAMPLE_ADDR ; - } - -if (sample_type &PERF_SAMPLE_TRANSACTION ) { - data->txn =intel_get_tsx_transaction (meminfo->tsx_tuning, - gprs ? gprs->ax :0 ); - data->sample_flags |=PERF_SAMPLE_TRANSACTION ; - } +u64 latency = x86_pmu.flags &PMU_FL_INSTR_LATENCY ? + meminfo->cache_latency : meminfo->mem_latency; +u64 instr_latency = x86_pmu.flags &PMU_FL_INSTR_LATENCY ? + meminfo->instr_latency :0 ; +u64 ax = gprs ? gprs->ax :0 ; + +__setup_pebs_meminfo_group (event, data, sample_type, latency, + instr_latency, meminfo->address, + meminfo->aux, meminfo->tsx_tuning, + ax); }if (format_group &PEBS_DATACFG_XMMS ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 582/1193 perf/x86/intel: Correct pt_regs->flags update for PEBS path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit 88aa1223bfffb1a0a98c639e9e1f71058f0d9178 ]
pt_regs->flags holds the saved CPU FLAGS register. In the PEBS path, it was incorrectly set to PERF_EFLAGS_EXACT instead of being populated from the PEBS flags snapshot.
Update pt_regs->flags from PEBS GPR flags if GPRs group is present.
--- arch/x86/events/intel/ds.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/events/intel/ds.c +9 -1
@@ -1805,7 +1805,7 @@ static inline void __setup_pebs_basic_group(struct perf_event *event, {/* The ip in basic is EventingIP */ set_linear_ip (regs, ip); - regs->flags =PERF_EFLAGS_EXACT ; + regs->flags |=PERF_EFLAGS_EXACT ;setup_pebs_time (event, data, tsc);if (sample_type &PERF_SAMPLE_WEIGHT_STRUCT )
@@ -1817,9 +1817,17 @@ static inline void __setup_pebs_gpr_group(struct perf_event *event, struct pebs_gprs *gprs, u64 sample_type) { +/* +* Update flags with PEBS data. PERF_EFLAGS_EXACT must be set +* in previous basic group handling. +*/ + regs->flags = gprs->flags |PERF_EFLAGS_EXACT ; +if (event->attr.precise_ip <2 ) {set_linear_ip (regs, gprs->ip); regs->flags &= ~PERF_EFLAGS_EXACT ; + }else if (regs->flags &X86_VM_MASK ) { + regs->flags ^= (PERF_EFLAGS_VM |X86_VM_MASK ); }if (sample_type & (PERF_SAMPLE_REGS_INTR |PERF_SAMPLE_REGS_USER ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 583/1193 net/sched: cls_route: free emptied bucket on filter move
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit 1853f30cf5c84971f99788a76207c6f745380896 ]
route4_change can move an existing filter to a different top-level
bucket: route4_set_parms recomputes the handle from TCA_ROUTE4_TO/ FROM/IIF, and the handle-mismatch check is gated on the 'new' flag, so for an existing filter the new handle may differ from the old one and land in a different bucket. When this happens, the filter is unlinked from the old bucket, but the bucket itself is never freed once it goes empty. The stale empty bucket remains in head->table[], causing route4_delete to report *last=false even after the last live filter is gone. That pins the empty tcf_proto and causes a leak.
Fix this by refcounting the filters linked to a bucket and freeing the bucket when the count drops to zero. The existing scan in route4_delete goes away with it.
The count is updated at all sites that link or unlink a filter during add, change and delete, and the bucket is dropped from head->table[] as soon as it reaches zero.
Conditions to recreate the bug:
CONFIG_NET_CLS_ROUTE4=y, CONFIG_NET_SCH_INGRESS=y, CONFIG_NET_CLS_ACT=y.
tc qdisc replace dev lo clsact
tc filter add dev lo ingress protocol ip pref 100 route from 1 to 1 tc filter change dev lo ingress protocol ip pref 100 handle 0x10001 \
route from 1 to 2
tc filter del dev lo ingress protocol ip pref 100 handle 0x10002 \
route from 1 to 2
tc filter show dev lo ingress | grep -c 'pref 100 route chain 0 '
--- net/sched/cls_route.c | 45 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
net/sched/cls_route.c +22 -23
@@ -11,6 +11,7 @@#include <linux/kernel.h> #include <linux/string.h> #include <linux/errno.h> +#include <linux/refcount.h> #include <linux/skbuff.h> #include <net/dst.h> #include <net/route.h>
@@ -41,6 +42,7 @@ struct route4_head {struct route4_bucket {/* 16 FROM buckets + 16 IIF buckets + 1 wildcard bucket */ struct route4_filter __rcu *ht[16 +16 +1 ]; +refcount_t filters_ref;struct rcu_head rcu; };
@@ -336,7 +338,7 @@ static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,struct route4_filter *nf;struct route4_bucket *b;unsigned int h =0 ; -int i, h1; +int h1;if (!head || !f)return -EINVAL ;
@@ -362,23 +364,14 @@ static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,tcf_exts_get_net (&f->exts);tcf_queue_work (&f->rwork, route4_delete_filter_work); -/* Strip RTNL protected tree */ -for (i =0 ; i <=32 ; i++) { -struct route4_filter *rt; - - rt =rtnl_dereference (b->ht[i]); -if (rt) - goto out; +if (refcount_dec_and_test (&b->filters_ref)) { +RCU_INIT_POINTER (head->table[to_hash (h)],NULL ); +kfree_rcu (b, rcu); } - -/* OK, session has no flows */ -RCU_INIT_POINTER (head->table[to_hash (h)],NULL ); -kfree_rcu (b, rcu);break ; } } -out: *last = true;for (h1 =0 ; h1 <=256 ; h1++) {if (rcu_access_pointer (head->table[h1])) {
@@ -455,6 +448,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,if (b ==NULL )return -ENOBUFS ; +refcount_set (&b->filters_ref,1 );rcu_assign_pointer (head->table[h1], b); }else {unsigned int h2 =from_hash (nhandle >>16 );
@@ -464,6 +458,8 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, fp = rtnl_dereference(fp->next))if (fp->handle == f->handle)return -EEXIST ; + +refcount_inc (&b->filters_ref); }if (tb[TCA_ROUTE4_TO ])
@@ -497,7 +493,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,struct route4_bucket *b;struct nlattr *opt = tca[TCA_OPTIONS ];struct nlattr *tb[TCA_ROUTE4_MAX +1 ]; -unsigned int h, th; +unsigned int h;int err;bool new = true;
@@ -555,17 +551,20 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,rcu_assign_pointer (*fp, f);if (fold) { - th =to_hash (fold->handle); + b = fold->bkt; h =from_hash (fold->handle >>16 ); - b =rtnl_dereference (head->table[th]); -if (b) { - fp = &b->ht[h]; -for (pfp =rtnl_dereference (*fp); pfp; - fp = &pfp->next, pfp =rtnl_dereference (*fp)) { -if (pfp == fold) { -rcu_assign_pointer (*fp, fold->next); -break ; + fp = &b->ht[h]; +for (pfp =rtnl_dereference (*fp); pfp; + fp = &pfp->next, pfp =rtnl_dereference (*fp)) { +if (pfp == fold) { +rcu_assign_pointer (*fp, fold->next); +if (refcount_dec_and_test (&b->filters_ref)) { +unsigned int th =to_hash (fold->handle); + +RCU_INIT_POINTER (head->table[th],NULL ); +kfree_rcu (b, rcu); } +break ; } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 584/1193 net/sched: cls_route: Reject handle aliasing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit b74a8455a2f271f54695b6a8ec1f113824a46c0e ]
route4_set_parms() rejects a duplicate by scanning the destination chain for f->handle, but f->handle is the handle the filter has before the update, not the one it is about to be linked under. The comparison and the insertion therefore use different handles, which causes breakage.
When a change moves the filter to a chain that already holds nhandle, the scan looks for the old handle instead, misses the collision and links a second filter with the same handle:
tc filter add dev lo ingress protocol ip pref 100 \
route from 1 to 1 classid 1:1 action ok
tc filter add dev lo ingress protocol ip pref 100 \
route from 2 to 2 classid 1:2 action drop
tc filter change dev lo ingress protocol ip pref 100 handle 0x10001 \
route from 2 to 2 classid 1:1 action ok
tc filter show dev lo ingress
... fh 0x00020002 flowid 1:2 to 2 from 2
... fh 0x00020002 flowid 1:1 to 2 from 2
The newcomer is appended after the incumbent, and both end up with the same f->id. route4_get() returns the first match, so the second filter can no longer be addressed by handle, and route4_classify() stops at the first filter whose f->id matches. The second filter is dumped but is effectively dead.
Fix this by comparing against nhandle.
--- net/sched/cls_route.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/sched/cls_route.c +5 -1
@@ -456,8 +456,12 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,for (fp =rtnl_dereference (b->ht[h2]); fp; fp =rtnl_dereference (fp->next)) -if (fp->handle == f->handle) +if (fp->handle == nhandle) { +NL_SET_ERR_MSG_FMT (extack, +"Handle %x is already in use" , + nhandle);return -EEXIST ; + }refcount_inc (&b->filters_ref); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 585/1193 net/sched: cls_route: make netlink errors meaningful
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pedro Tammela <[email protected]>
[ Upstream commit ef765c25875941564edf447302ff339363441e58 ]
Use netlink extended ack and parsing policies to return more meaningful errors instead of the relying solely on errnos.
Stable-dep-of: 41e85e54e564 ("net/sched: cls_route: Fix in-place replace")
--- net/sched/cls_route.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
net/sched/cls_route.c +21 -16
@@ -385,9 +385,9 @@ static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,static const struct nla_policy route4_policy[TCA_ROUTE4_MAX +1 ] = { [TCA_ROUTE4_CLASSID ] = { .type =NLA_U32 }, - [TCA_ROUTE4_TO ] = { .type =NLA_U32 }, - [TCA_ROUTE4_FROM ] = { .type =NLA_U32 }, - [TCA_ROUTE4_IIF ] = { .type =NLA_U32 }, + [TCA_ROUTE4_TO ] =NLA_POLICY_MAX (NLA_U32 ,0xFF ), + [TCA_ROUTE4_FROM ] =NLA_POLICY_MAX (NLA_U32 ,0xFF ), + [TCA_ROUTE4_IIF ] =NLA_POLICY_MAX (NLA_U32 ,0x7FFF ), }; static int route4_set_parms(struct net *net, struct tcf_proto *tp,
@@ -407,33 +407,37 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,return err;if (tb[TCA_ROUTE4_TO ]) { -if (new && handle &0x8000 ) +if (new && handle &0x8000 ) { +NL_SET_ERR_MSG (extack,"Invalid handle" );return -EINVAL ; + } to =nla_get_u32 (tb[TCA_ROUTE4_TO ]); -if (to >0xFF ) -return -EINVAL ; nhandle = to; } +if (tb[TCA_ROUTE4_FROM ] && tb[TCA_ROUTE4_IIF ]) { +NL_SET_ERR_MSG_ATTR (extack, tb[TCA_ROUTE4_FROM ], +"'from' and 'fromif' are mutually exclusive" ); +return -EINVAL ; + } +if (tb[TCA_ROUTE4_FROM ]) { -if (tb[TCA_ROUTE4_IIF ]) -return -EINVAL ; id =nla_get_u32 (tb[TCA_ROUTE4_FROM ]); -if (id >0xFF ) -return -EINVAL ; nhandle |= id <<16 ; }else if (tb[TCA_ROUTE4_IIF ]) { id =nla_get_u32 (tb[TCA_ROUTE4_IIF ]); -if (id >0x7FFF ) -return -EINVAL ; nhandle |= (id |0x8000 ) <<16 ; }else nhandle |=0xFFFF <<16 ;if (handle && new) { nhandle |= handle &0x7F00 ; -if (nhandle != handle) +if (nhandle != handle) { +NL_SET_ERR_MSG_FMT (extack, +"Handle mismatch constructed: %x (expected: %x)" , + handle, nhandle);return -EINVAL ; + } }if (!nhandle) {
@@ -495,7 +499,6 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,struct route4_filter __rcu **fp;struct route4_filter *fold, *f1, *pfp, *f =NULL ;struct route4_bucket *b; -struct nlattr *opt = tca[TCA_OPTIONS ];struct nlattr *tb[TCA_ROUTE4_MAX +1 ];unsigned int h;int err;
@@ -506,10 +509,12 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } -if (opt ==NULL ) +if (NL_REQ_ATTR_CHECK (extack,NULL , tca,TCA_OPTIONS )) { +NL_SET_ERR_MSG_MOD (extack,"Missing options" );return -EINVAL ; + } - err =nla_parse_nested_deprecated (tb,TCA_ROUTE4_MAX , opt, + err =nla_parse_nested_deprecated (tb,TCA_ROUTE4_MAX , tca[TCA_OPTIONS ], route4_policy,NULL );if (err <0 )return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 586/1193 net/sched: cls_route: Fix in-place replace
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit 41e85e54e5649a1617698438b0ce64c6f9d83d69 ]
Building on the previous patch, route4_set_parms rejects a duplicate by scanning the destination chain for nhandle, but the scan doesn't exclude the older version it is replacing, so an in-place replace will match the older version's handle and fail.
Fix this by passing the older filter as a parameter to route4_set_parms (replacing "new") and skipping it in the scan.
Excluding the older version is not enough on its own. nhandle is built out of TCA_ROUTE4_TO, TCA_ROUTE4_FROM and TCA_ROUTE4_IIF alone, while the 0x7F00 bits, which only tell apart filters sharing one key, are folded in on the create path. Letting the replace through would therefore rename the filter it replaces: replacing handle 0x10101 stored it back as 0x10001, and a sibling at 0x10201 could then no longer be replaced at all, since its own nhandle collided with the renamed filter.
tc filter add ... handle 0x10101 route from 1 to 1 classid 1:1 tc filter add ... handle 0x10201 route from 1 to 1 classid 1:2 tc filter replace ... handle 0x10101 route from 1 to 1 classid 1:9 ... fh 0x00010001 flowid 1:9 to 1 from 1 ... fh 0x00010201 flowid 1:2 to 1 from 1 tc filter replace ... handle 0x10201 route from 1 to 1 classid 1:8 Error: Handle 10001 is already in use.
So carry those bits over when the key the request builds is the key the older filter already has. An in-place replace then keeps the handle userspace named the filter by, while a request that does change the key still renames it, as it did before.
--- net/sched/cls_route.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
net/sched/cls_route.c +13 -14
@@ -393,8 +393,9 @@ static const struct nla_policy route4_policy[TCA_ROUTE4_MAX + 1] = {static int route4_set_parms (struct net *net,struct tcf_proto *tp,unsigned long base,struct route4_filter *f,u32 handle,struct route4_head *head, -struct nlattr **tb,struct nlattr *est,int new, -u32 flags,struct netlink_ext_ack *extack) +struct nlattr **tb,struct nlattr *est, +struct route4_filter *fold,u32 flags, +struct netlink_ext_ack *extack) {u32 id =0 , to =0 , nhandle =0x8000 ;struct route4_filter *fp;
@@ -407,7 +408,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,return err;if (tb[TCA_ROUTE4_TO ]) { -if (new && handle &0x8000 ) { +if (!fold && handle &0x8000 ) {NL_SET_ERR_MSG (extack,"Invalid handle" );return -EINVAL ; }
@@ -430,14 +431,14 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, }else nhandle |=0xFFFF <<16 ; -if (handle && new) { +if (handle && (!fold || nhandle == (handle & ~0x7F00 ))) nhandle |= handle &0x7F00 ; -if (nhandle != handle) { -NL_SET_ERR_MSG_FMT (extack, -"Handle mismatch constructed: %x (expected: %x)" , - handle, nhandle); -return -EINVAL ; - } + +if (handle && !fold && nhandle != handle) { +NL_SET_ERR_MSG_FMT (extack, +"Handle mismatch constructed: %x (expected: %x)" , + handle, nhandle); +return -EINVAL ; }if (!nhandle) {
@@ -460,7 +461,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,for (fp =rtnl_dereference (b->ht[h2]); fp; fp =rtnl_dereference (fp->next)) -if (fp->handle == nhandle) { +if (fp != fold && fp->handle == nhandle) {NL_SET_ERR_MSG_FMT (extack,"Handle %x is already in use" , nhandle);
@@ -502,7 +503,6 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,struct nlattr *tb[TCA_ROUTE4_MAX +1 ];unsigned int h;int err; -bool new = true;if (!handle) {NL_SET_ERR_MSG (extack,"Creating with handle of 0 is invalid" );
@@ -539,11 +539,10 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, f->tp = fold->tp; f->bkt = fold->bkt; - new = false; } err =route4_set_parms (net, tp, base, f, handle, head, tb, - tca[TCA_RATE ], new, flags, extack); + tca[TCA_RATE ], fold, flags, extack);if (err <0 ) goto errout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 587/1193 net/sched: cls_api: Dont replay RTM_GETCHAIN in tc_ctl_chain().
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit dff39930ad5e53d202bfdfb14687d1d2fd753b4d ]
If a netlink socket sends RTM_GETCHAIN requests repeatedly without recv()ing the responses, tc_ctl_chain() hogs CPU and triggers Hung Task splat. [0]
As caught in the stack trace, netlink_attachskb() could confuse tc_ctl_chain() by returning -EAGAIN when the userspace netlink socket's receive buffer is full.
The replay: label exists since commit 32a4f5ecd738 ("net: sched:
introduce chain object to uapi") but was not used initially.
Since commit 9f407f1768d3 ("net: sched: introduce chain templates"), the label is needed for RTM_NEWCHAIN because tcf_proto_lookup_ops() may release RTNL to call request_module().
However, the replay logic is unnecessary for RTM_GETCHAIN.
Let's apply the replay logic only for RTM_NEWCHAIN.
[0]:
INFO: task repro:1018 is blocked on a mutex likely owned by task repro:1022. task:repro state:R running task stack:14096 pid:1022 tgid:1014 ppid:961 task_flags:0x400040 flags:0x00080000 Call Trace: <TASK> ? clockevents_program_event (kernel/time/clockevents.c:372) ? pskb_expand_head (net/core/skbuff.c:615) ? skb_release_data (net/core/skbuff.c:1122) ? netlink_attachskb (./include/linux/skbuff.h:1323 ./include/linux/skbuff.h:1332 net/netlink/af_netlink.c:1232) ? __netlink_lookup (./include/linux/rcupdate.h:882 ./include/linux/rhashtable.h:711 net/netlink/af_netlink.c:499) ? tc_chain_notify (net/sched/cls_api.c:3045) ? tc_chain_notify (./include/linux/skbuff.h:1384 net/sched/cls_api.c:3041) ? netlink_unicast (net/netlink/af_netlink.c:1335) ? rtnl_unicast (./include/net/netlink.h:1198 net/core/rtnetlink.c:985) ? tc_ctl_chain (net/sched/cls_api.c:3242) ? rtnetlink_rcv_msg (net/core/rtnetlink.c:7146) ? netlink_unicast (net/netlink/af_netlink.c:1354) ? __pfx_rtnetlink_rcv_msg (net/core/rtnetlink.c:7177) ? netlink_rcv_skb (net/netlink/af_netlink.c:2556) ? netlink_unicast (net/netlink/af_netlink.c:1319) ? netlink_sendmsg (net/netlink/af_netlink.c:1900) ? __sock_sendmsg (net/socket.c:800) ? __sys_sendto (net/socket.c:2281) ? __x64_sys_sendto (net/socket.c:2288 net/socket.c:2284 net/socket.c:2284) ? do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:84) ? entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) </TASK>
--- net/sched/cls_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/cls_api.c +1 -1
@@ -3224,7 +3224,7 @@ static int tc_ctl_chain(struct sk_buff *skb, struct nlmsghdr *n,tcf_chain_put (chain); errout_block:tcf_block_release (q, block, true); -if (err == -EAGAIN ) +if (err == -EAGAIN && n->nlmsg_type ==RTM_NEWCHAIN )/* Replay the request. */ goto replay;return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 588/1193 net: sun4i-emac: fix missing of_node_put() for phy_node
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Youhong <[email protected]>
[ Upstream commit af406abfecad2f48d8f1fc646d3994f0982bac62 ]
of_parse_phandle() returns a node pointer with an elevated refcount. Add the missing of_node_put() on the probe error path after register_netdev() fails and in emac_remove().
--- drivers/net/ethernet/allwinner/sun4i-emac.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/allwinner/sun4i-emac.c +2 -0
@@ -1067,6 +1067,7 @@ static int emac_probe(struct platform_device *pdev)return 0 ; out_release_sram: +of_node_put (db->phy_node);sunxi_sram_release (&pdev->dev); out_clk_disable_unprepare:clk_disable_unprepare (db->clk);
@@ -1094,6 +1095,7 @@ static int emac_remove(struct platform_device *pdev) }unregister_netdev (ndev); +of_node_put (db->phy_node);sunxi_sram_release (&pdev->dev);clk_disable_unprepare (db->clk);irq_dispose_mapping (ndev->irq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 589/1193 net: hinic: fix mailbox segment buffer overflow
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
[ Upstream commit 5d4d985957434867bbe85e4fa5e638f3e48ad522 ]
check_mbox_seq_id_and_seg_len() validates that seq_id does not exceed SEQ_ID_MAX_VAL (42) and seg_len does not exceed MBOX_SEG_LEN (48). However, this allows the last segment (seq_id=42) to carry a full 48-byte payload, writing to offset 42*48=2016 for 48 bytes (ending at byte 2064). The receive buffer is only MBOX_MAX_BUF_SZ (2048) bytes, resulting in a 16-byte heap buffer overflow.
The hinic3 driver already handles this correctly by defining MBOX_LAST_SEG_MAX_LEN and rejecting the last segment when it exceeds the remaining buffer space. Apply the same fix to the hinic driver.
--- drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +3 -1
@@ -128,6 +128,7 @@ enum hinic_mbox_tx_status {#define SEQ_ID_START_VAL 0#define SEQ_ID_MAX_VAL 42 +#define MBOX_LAST_SEG_MAX_LEN (MBOX_MAX_BUF_SZ - SEQ_ID_MAX_VAL * MBOX_SEG_LEN)#define NO_DMA_ATTRIBUTE_VAL 0
@@ -372,7 +373,8 @@ recv_pf_from_vf_mbox_handler(struct hinic_mbox_func_to_func *func_to_func,static bool check_mbox_seq_id_and_seg_len (struct hinic_recv_mbox *recv_mbox,u8 seq_id,u8 seg_len) { -if (seq_id >SEQ_ID_MAX_VAL || seg_len >MBOX_SEG_LEN ) +if (seq_id >SEQ_ID_MAX_VAL || seg_len >MBOX_SEG_LEN || + (seq_id ==SEQ_ID_MAX_VAL && seg_len >MBOX_LAST_SEG_MAX_LEN ))return false;if (seq_id ==0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 590/1193 octeontx2-af: fix PF/CGX debugfs PCI bus lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratheesh Kannoth <[email protected]>
[ Upstream commit 4f4b743c2d2bbc336cb164d9d3d2ed6956ad8437 ]
rvu_dbg_rvu_pf_cgx_map_display() locates each RVU PF PCI device via pci_get_domain_bus_and_slot() when printing the PF-to-CGX map. It assumed PF0 always sits on PCI bus 1 and derived other PF bus numbers as pf + 1, but the AF device can be enumerated on a different bus.
Use rvu->pdev->bus->number as the base bus instead, so each PF lookup uses pf + start on systems where RVU functions are on contiguous buses but do not start at bus 1.
--- .../net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +8 -2
@@ -852,19 +852,25 @@ static int rvu_dbg_rvu_pf_cgx_map_display(struct seq_file *filp, void *unused)int pf, domain, blkid;u8 cgx_id, lmac_id;u16 pcifunc; +u8 start; - domain =2 ; + domain =pci_domain_nr (rvu->pdev->bus); mac_ops =get_mac_ops (rvu_first_cgx_pdata (rvu));/* There can be no CGX devices at all */ if (!mac_ops)return 0 ;seq_printf (filp,"PCI dev\t\tRVU PF Func\tNIX block\t%s\tLMAC\n" , mac_ops->name); + +/* All the PF devices are on contiguous PCI bus numbers, but the PF0(AF) +* may not start from 1 always. Hence get domain and bus from PCI device. +*/ + start = rvu->pdev->bus->number;for (pf =0 ; pf < rvu->hw->total_pfs; pf++) {if (!is_pf_cgxmapped (rvu, pf))continue ; - pdev =pci_get_domain_bus_and_slot (domain, pf +1 ,0 ); + pdev =pci_get_domain_bus_and_slot (domain, pf + start,0 );if (!pdev)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 591/1193 net/rds: fix tcp stream corruption with large pages
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Marsden <[email protected]>
[ Upstream commit 2ac09b5353fe6858411fdc8c6efa60d832e20f13 ]
rds_message_map_pages() assigns PAGE_SIZE bytes to every scatterlist entry, even when total_len ends in a partial page. The RDS congestion map is defined as 8192 bytes, so on systems with PAGE_SIZE greater than 8192 the scatterlist maps bytes beyond the end of the congestion map. RDS-TCP transmits the SG contents according to those lengths, so the extra bytes become part of the TCP RDS stream and are interpreted as subsequent RDS message headers, corrupting the stream.
Limit the final scatterlist mapping to the number of bytes remaining. This has no effect on systems with a 4K page size and allows RDS-TCP to be used on systems with 16K and larger page sizes.
The RDS selftest, which previously hung on 16K pages, now passes.
--- net/rds/message.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/rds/message.c +3 -1
@@ -365,7 +365,9 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned infor (i =0 ; i < rm->data.op_nents; ++i) {sg_set_page (&rm->data.op_sg[i],virt_to_page ((void *)page_addrs[i]), -PAGE_SIZE ,0 ); + i == rm->data.op_nents -1 + ? total_len - (i *PAGE_SIZE ) + :PAGE_SIZE ,0 ); }return rm;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 592/1193 openvswitch: fix wrong flag value in get_ipv6_ext_hdrs()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eelco Chaudron <[email protected]>
[ Upstream commit e184a4a6f423550a25adce867036cdb1ff471745 ]
The ESP and AH cases in get_ipv6_ext_hdrs() used IPPROTO_FRAGMENT instead of OFPIEH12_FRAG when checking for out-of-order extension headers, causing the fragment header to not be recognised as a valid predecessor.
The original code used IPPROTO_FRAGMENT (44) as a bitmask constant where OFPIEH12_FRAG (1 << 4 = 16) was intended. IPPROTO_FRAGMENT encodes bits 2, 3 and 5 (OFPIEH12_AUTH | OFPIEH12_DEST | OFPIEH12_ROUTER), but not bit 4 (OFPIEH12_FRAG). This caused incorrect OFPIEH12_UNSEQ verdicts in both the ESP and AH arms: the ESP arm failed to whitelist OFPIEH12_FRAG, while the AH arm accidentally whitelisted OFPIEH12_AUTH.
With the fix, a packet with two AH headers now also gets OFPIEH12_UNSEQ in addition to OFPIEH12_UNREP, matching the ESP arm which already sets UNSEQ on a repeat, which is the intended behavior.
--- net/openvswitch/flow.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/openvswitch/flow.c +2 -2
@@ -292,7 +292,7 @@ static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh,if (*ext_hdrs &OFPIEH12_ESP ) *ext_hdrs |=OFPIEH12_UNREP ;if ((*ext_hdrs & ~(OFPIEH12_HOP |OFPIEH12_DEST | -OFPIEH12_ROUTER |IPPROTO_FRAGMENT | +OFPIEH12_ROUTER |OFPIEH12_FRAG |OFPIEH12_AUTH |OFPIEH12_UNREP )) || dest_options_header_count >=2 ) { *ext_hdrs |=OFPIEH12_UNSEQ ;
@@ -305,7 +305,7 @@ static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh, *ext_hdrs |=OFPIEH12_UNREP ;if ((*ext_hdrs & ~(OFPIEH12_HOP |OFPIEH12_DEST |OFPIEH12_ROUTER | -IPPROTO_FRAGMENT |OFPIEH12_UNREP )) || +OFPIEH12_FRAG |OFPIEH12_UNREP )) || dest_options_header_count >=2 ) { *ext_hdrs |=OFPIEH12_UNSEQ ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 593/1193 sunvdc: unmap LDC cookies when the descriptor send fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stian Halseth <[email protected]>
[ Upstream commit 0c6da21fa35e03fc74f09895433ccd6d4a9c3530 ]
__send_request() maps the request's pages into the LDC channel's map table (ldc_map_sg()), fills in the descriptor and marks it VIO_DESC_READY before ringing the doorbell via __vdc_tx_trigger(). When the trigger fails, the error path only prints a message: the descriptor stays READY and the cookies are never unmapped. The mapping is normally released in vdc_end_one() when the peer completes the descriptor - but a descriptor whose doorbell was never sent will never complete, and since dr->prod is not advanced on failure, the reset path (vdc_requeue_inflight(), which walks [cons, prod)) never visits it either. The map table entries are leaked permanently.
Since commit a11f6ca9aef9 ("sunvdc: Do not spin in an infinite loop when vio_ldc_send() returns EAGAIN") trigger failures occur in practice under load, so every resulting I/O error also leaks one request's worth of entries from the fixed-size (8192 entries per channel) map table. Because the allocator hands out contiguous ranges, fragmentation makes large multi-segment requests fail first as the table drains, until ldc_map_sg() fails permanently and the disk is dead until reboot.
It also makes any retry-based recovery unusable: requeuing the request on -EAGAIN remaps the pages on every attempt, overwriting desc->cookies and orphaning the previous mapping, so the table drains at the retry rate. This is the memory exhaustion observed when the requeue approach was first tested in October 2025.
Roll back on failure: unmap the cookies, mark the descriptor FREE again and clear the request entry. If the trigger failed with -ENOTCONN, __vdc_tx_trigger() has already reset the port, which tears down and reallocates both the dring and the LDC channel including its map table - nothing to roll back, and the stale descriptor must not be touched.
--- drivers/block/sunvdc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/block/sunvdc.c +17 -0
@@ -526,6 +526,23 @@ static int __send_request(struct request *req) err =__vdc_tx_trigger (port);if (err <0 ) { printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err); +/* +* If the port was reset (-ENOTCONN), the dring and the +* LDC channel including all of its mappings are already +* torn down and reallocated - there is nothing to undo +* and @desc must not be touched. +* +* For any other failure the descriptor was never handed +* to the peer: unmap the cookies and free the descriptor +* again, so that a later retry of the request does not +* leak LDC map table entries. +*/ +if (err != -ENOTCONN ) { +ldc_unmap (port->vio.lp, desc->cookies, + desc->ncookies); + desc->hdr.state =VIO_DESC_FREE ; + rqe->req =NULL ; + } }else { port->req_id++; dr->prod =vio_dring_next (dr, dr->prod);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 594/1193 scsi: target: iscsi: Fix hang for aborted WRITE_PENDING commands
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maurizio Lombardi <[email protected]>
[ Upstream commit d5869dae5080e976d4b03cc33eb7ceb527f242bf ]
When a LUN_RESET aborts a WRITE command that is in the TRANSPORT_WRITE_PENDING state, the target core sets CMD_T_ABORTED and waits for the frontend to finish processing.
If the initiator subsequently sends the remaining dataout PDUs, __iscsit_check_dataout_hdr() catches the payload, stops the dataout timer if the sequence is final and finally dumps the data. However, the iSCSI target doesn't trigger the completion process for these aborted commands. Because of this, the abort path hangs indefinitely in target_put_cmd_and_wait(), leading to a deadlocked target worker thread.
Fix this by explicitly calling target_complete_cmd() when the final dataout PDU is received for an aborted WRITE command. target_complete_cmd() detects the CMD_T_ABORTED flag and cleanly routes the command into target_abort_work, allowing the abort completion to successfully unblock.
--- drivers/target/iscsi/iscsi_target.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target.c +3 -1
@@ -1567,8 +1567,10 @@ __iscsit_check_dataout_hdr(struct iscsit_conn *conn, void *buf,*/ if (se_cmd->transport_state &CMD_T_ABORTED ) {if (hdr->flags &ISCSI_FLAG_CMD_FINAL && - --cmd->outstanding_r2ts <1 ) + --cmd->outstanding_r2ts <1 ) {iscsit_stop_dataout_timer (cmd); +target_complete_cmd (se_cmd,SAM_STAT_TASK_ABORTED ); + }return iscsit_dump_data_payload (conn, payload_length,1 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 595/1193 ksmbd: prevent out-of-bounds reads in share config responses
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit f25e93768fcc5d8287e50b1ec52a42e4c276df34 ]
Validate IPC share configuration payload sizes before consuming variable-length fields. Bound veto list parsing and account for the separator byte when deriving the path length.
--- fs/smb/server/mgmt/share_config.c | 38 +++++++++++++++++++++++-------- fs/smb/server/transport_ipc.c | 21 +++++++++++------ 2 files changed, 42 insertions(+), 17 deletions(-)
fs/smb/server/mgmt/share_config.c +28 -10
@@ -88,9 +88,9 @@ static struct ksmbd_share_config *__share_lookup(const char *name)static int parse_veto_list (struct ksmbd_share_config *share,char *veto_list, -int veto_list_sz) +size_t veto_list_sz) { -int sz =0 ; +size_t sz;if (!veto_list_sz)return 0 ;
@@ -98,7 +98,7 @@ static int parse_veto_list(struct ksmbd_share_config *share,while (veto_list_sz >0 ) {struct ksmbd_veto_pattern *p; - sz =strlen (veto_list); + sz =strnlen (veto_list, veto_list_sz);if (!sz)break ;
@@ -106,7 +106,7 @@ static int parse_veto_list(struct ksmbd_share_config *share,if (!p)return -ENOMEM ; - p->pattern =kstrdup (veto_list,GFP_KERNEL ); + p->pattern =kstrndup (veto_list, sz,GFP_KERNEL );if (!p->pattern) {kfree (p);return -ENOMEM ;
@@ -114,6 +114,9 @@ static int parse_veto_list(struct ksmbd_share_config *share,list_add (&p->list, &share->veto_list); +if (sz == veto_list_sz) +break ; + veto_list += sz +1 ; veto_list_sz -= (sz +1 ); }
@@ -160,13 +163,27 @@ static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work, share->name =kstrdup (name,GFP_KERNEL );if (!test_share_config_flag (share,KSMBD_SHARE_FLAG_PIPE )) { -int path_len =PATH_MAX ; +size_t path_len; -if (resp->payload_sz) +if (resp->payload_sz <= resp->veto_list_sz) { + ret = -EINVAL ; + }else { path_len = resp->payload_sz - resp->veto_list_sz; - - share->path =kstrndup (ksmbd_share_config_path (resp), path_len, -GFP_KERNEL ); +if (resp->veto_list_sz) + path_len--; + +if (!path_len) { + ret = -EINVAL ; + }else { + share->path =kstrndup ( +ksmbd_share_config_path (resp), + path_len,GFP_KERNEL ); +if (!share->path) + ret = -ENOMEM ; +else + ret =0 ; + } + }if (share->path) { share->path_sz =strlen (share->path); while (share->path_sz > 1 &&
@@ -179,7 +196,8 @@ static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work, share->force_directory_mode = resp->force_directory_mode; share->force_uid = resp->force_uid; share->force_gid = resp->force_gid; - ret =parse_veto_list (share, +if (!ret) + ret =parse_veto_list (share,KSMBD_SHARE_CONFIG_VETO_LIST (resp), resp->veto_list_sz);if (!ret && share->path) {
fs/smb/server/transport_ipc.c +14 -7
@@ -524,14 +524,21 @@ static int ipc_validate_msg(struct ipc_msg_table_entry *entry)if (entry->msg_sz <sizeof (struct ksmbd_share_config_response ))return -EINVAL ; -if (resp->payload_sz) { -if (resp->payload_sz < resp->veto_list_sz) -return -EINVAL ; +if (strnlen (resp->share_name,sizeof (resp->share_name)) == +sizeof (resp->share_name)) +return -EINVAL ; -if (check_add_overflow (sizeof (struct ksmbd_share_config_response ), - resp->payload_sz, &msg_sz)) -return -EINVAL ; - } +if (resp->veto_list_sz > resp->payload_sz) +return -EINVAL ; + +if (resp->flags !=KSMBD_SHARE_FLAG_INVALID && + !(resp->flags &KSMBD_SHARE_FLAG_PIPE ) && + resp->payload_sz <= resp->veto_list_sz) +return -EINVAL ; + +if (check_add_overflow (sizeof (struct ksmbd_share_config_response ), + resp->payload_sz, &msg_sz)) +return -EINVAL ;break ; }case KSMBD_EVENT_LOGIN_REQUEST_EXT :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 596/1193 powerpc/ps3: Fix repository.c build failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit 5ba79d37403d86082ab4083b0f51ec3008a942cb upstream.
GCC fails to build ps3_defconfig with the following errors:
arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]
78 | memcpy((char *)&n, text, strnlen(text, sizeof(n)));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
78 | memcpy((char *)&n, text, strnlen(text, sizeof(n)));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().
Drop the redundant char * cast while at it.
--- arch/powerpc/platforms/ps3/repository.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +4 -1
@@ -6,6 +6,8 @@* Copyright 2006 Sony Corp. */ +#include <linux/minmax.h> +#include <asm/lv1call.h> #include "platform.h"
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,static u64 make_first_field (const char *text,u64 index) {u64 n =0 ; +size_t len =min (strlen (text),sizeof (n)); -memcpy ((char *)&n, text,strnlen (text,sizeof (n))); +memcpy (&n, text, len);return PS3_VENDOR_ID_NONE + (n >>32 ) + index; }
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 597/1193 powerpc/eeh: Fix recursive locking on devices without EEH sensitive driver
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivaprasad G Bhat <[email protected]>
commit c5e68706527968282e49de205cc2b935823cb88a upstream.
The commit 1010b4c012b0 ("powerpc/eeh: Make EEH driver device hotplug safe") refactored the EEH code such that the pci_rescan_remove_lock is held at the beginning of eeh_handle_normal_event() and the eeh_reset_device() is called with that lock being held. Looks like the commit missed to remove the existing lock/unlock inside eeh_rmv_device() which is no longer necessary. This is causing the eehd to hang on the lock which it actually holds when that code path is taken.
[<0>] 0xc00000011c78f870
[<0>] __switch_to+0xfc/0x1a0 [<0>] pci_lock_rescan_remove+0x30/0x44 [<0>] eeh_rmv_device+0x290/0x2e0 [<0>] eeh_pe_dev_traverse+0x80/0x130 [<0>] eeh_reset_device+0xcc/0x23c [<0>] eeh_handle_normal_event+0x830/0xa80 [<0>] eeh_event_handler+0xf8/0x190 [<0>] kthread+0x194/0x1b0 [<0>] start_kernel_thread+0x14/0x18
The issue is seen for cases where the errors are detected on the PHB directly AND|OR for devices where the driver error_detected() returns PCI_ERS_RESULT_NEED_RESET, and driver being not EEH sensitive(i.e no error handlers like slot_reset(), resume() etc defined).
--- arch/powerpc/kernel/eeh_driver.c | 2 -- 1 file changed, 2 deletions(-)
arch/powerpc/kernel/eeh_driver.c +0 -2
@@ -533,9 +533,7 @@ static void eeh_rmv_device(struct eeh_deif (rmv_data)list_add (&edev->rmv_entry, &rmv_data->removed_vf_list); }else { -pci_lock_rescan_remove ();pci_stop_and_remove_bus_device (dev); -pci_unlock_rescan_remove (); } }
Greg Kroah-Hartman
maintainerPATCH 598/1193 crypto: x86/aria - add missing vzeroupper in AVX2 code
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit ac53977611428db3bc0b4ac0225e19c3e08ae50b upstream.
Since the AVX2 optimized ARIA code uses YMM registers, execute vzeroupper before returning from it. This is needed to avoid degrading the performance of any later SSE code that may happen to be executed.
--- arch/x86/crypto/aria-aesni-avx2-asm_64.S | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/crypto/aria-aesni-avx2-asm_64.S +6 -0
@@ -988,6 +988,7 @@ SYM_TYPED_FUNC_START(aria_aesni_avx2_enc %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15, %rax); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_aesni_avx2_encrypt_32way)
@@ -1013,6 +1014,7 @@ SYM_TYPED_FUNC_START(aria_aesni_avx2_dec %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15, %rax); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_aesni_avx2_decrypt_32way)
@@ -1215,6 +1217,7 @@ SYM_TYPED_FUNC_START(aria_aesni_avx2_ctr %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15, %r10); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_aesni_avx2_ctr_crypt_32way)
@@ -1366,6 +1369,7 @@ SYM_TYPED_FUNC_START(aria_aesni_avx2_gfn %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15, %rax); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_aesni_avx2_gfni_encrypt_32way)
@@ -1391,6 +1395,7 @@ SYM_TYPED_FUNC_START(aria_aesni_avx2_gfn %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15, %rax); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_aesni_avx2_gfni_decrypt_32way)
@@ -1435,6 +1440,7 @@ SYM_TYPED_FUNC_START(aria_aesni_avx2_gfn %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15, %r10); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_aesni_avx2_gfni_ctr_crypt_32way)
Greg Kroah-Hartman
maintainerPATCH 599/1193 crypto: x86/aria - add missing vzeroupper in AVX-512 code
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 60892a384aa1e65d0e703e1c513417bdf0c80777 upstream.
Since the AVX-512 optimized ARIA code uses ZMM registers, execute vzeroupper before returning from it. This is needed to avoid degrading the performance of any later SSE code that may happen to be executed.
--- arch/x86/crypto/aria-gfni-avx512-asm_64.S | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/crypto/aria-gfni-avx512-asm_64.S +3 -0
@@ -800,6 +800,7 @@ SYM_TYPED_FUNC_START(aria_gfni_avx512_en %zmm9, %zmm8, %zmm11, %zmm10, %zmm12, %zmm13, %zmm14, %zmm15, %rax); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_gfni_avx512_encrypt_64way)
@@ -825,6 +826,7 @@ SYM_TYPED_FUNC_START(aria_gfni_avx512_de %zmm9, %zmm8, %zmm11, %zmm10, %zmm12, %zmm13, %zmm14, %zmm15, %rax); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_gfni_avx512_decrypt_64way)
@@ -966,6 +968,7 @@ SYM_TYPED_FUNC_START(aria_gfni_avx512_ct %zmm9, %zmm8, %zmm11, %zmm10, %zmm12, %zmm13, %zmm14, %zmm15, %r10); + vzeroupper; FRAME_END RET; SYM_FUNC_END(aria_gfni_avx512_ctr_crypt_64way)
Greg Kroah-Hartman
maintainerPATCH 600/1193 x86/mm: Fix user-space data loss with MADV_FREE and THP
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vernon Yang <[email protected]>
commit f7491d7c81db0e7c304a7bd757a76d2fbeaff80e upstream.
Some of users of Polars (a data analytics library) have lost production data from this bug. They seem to have just the right combination of huge pages, MADV_FREE and heavy reclaim pressure.
pmd_modify() masks the old value with (_HPAGE_CHG_MASK & ~_PAGE_DIRTY), silently discarding the hardware dirty bit. The subsequent pmd_mksaveddirty() call is supposed to transfer _PAGE_DIRTY into _PAGE_SAVED_DIRTY when write-protecting, but the dirty bit was already stripped from the value, so there is nothing left to transfer.
Contrast with pte_modify(), which keeps _PAGE_DIRTY_BITS in its mask, and pud_modify(), which keeps _HPAGE_CHG_MASK untouched: pmd_modify() is the odd one out. Any pmd_modify() on a writable, dirty PMD loses the dirty state.
One visible consequence is data loss with MADV_FREE on PMD-mapped THP:
memset(buf, 0x5A, size); // PMD-mapped THP, PMD dirty
madvise(buf, size, MADV_FREE); // PMD cleaned but left writable,
// folio marked lazyfree
memset(buf, 0x5A, size); // hardware sets _PAGE_DIRTY again
mprotect(buf, size, PROT_READ); // pmd_modify() drops the dirty bit
mprotect(buf, size, PROT_READ|PROT_WRITE);
// ... memory pressure ...Reclaim (e.g. under memcg pressure) then finds the lazyfree folio with no dirty bit set anywhere and frees it in __discard_anon_folio_pmd_locked(), even though the data was rewritten after MADV_FREE; subsequent reads fault in fresh zero pages. NUMA hinting alone can trigger the same loss, as do_huge_pmd_numa_page() restores the PMD through pmd_modify() as well.
PMD-mapped file THPs are affected too: mprotect()/NUMA hinting dropping the dirty bit means rewritten data is never written back.
Fix it by keeping _PAGE_DIRTY in the preserved mask, exactly like pte_modify() and pud_modify() do. The existing pmd_mksaveddirty()/pmd_clear_saveddirty() pair then performs the hardware-dirty <-> saved-dirty transition based on the write bit, preserving the shadow-stack encoding rules.
--- arch/x86/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +1 -1
@@ -814,7 +814,7 @@ static inline pmd_t pmd_modify(pmd_t pmdpmdval_t val =pmd_val (pmd), oldval = val;pmd_t pmd_result; - val &= (_HPAGE_CHG_MASK & ~_PAGE_DIRTY); + val &= _HPAGE_CHG_MASK; val |=check_pgprot (newprot) & ~_HPAGE_CHG_MASK; val =flip_protnone_guard (oldval, val,PHYSICAL_PMD_PAGE_MASK );
Greg Kroah-Hartman
maintainerPATCH 601/1193 ipv6: fix fib6 walker UAF on seq stop
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit 19b4ed644d68098cc62ab612727f40d30f43476c upstream.
ipv6_route_iter_active() treats a walker in FWS_U at the table root as already unlinked. fib6_del_route() can move a still-linked walker into that same state when the current leaf is the last route at the root, so ipv6_route_native_seq_stop() skips fib6_walker_unlink(). The seq private object can then be freed while it remains on net->ipv6.fib6_walkers. A later route deletion walks the dangling list and uses the freed walker.
Use the list head as membership state and reinitialize it when unlinking. Keep the existing w->node check so a never-started iterator with a zeroed private object is not treated as linked.
The same stop helper is used by /proc/net/ipv6_route and by the BPF ipv6_route iterator. The BPF show path only widens the race.
--- net/ipv6/ip6_fib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/ip6_fib.c +2 -2
@@ -85,7 +85,7 @@ static void fib6_walker_link(struct netstatic void fib6_walker_unlink (struct net *net,struct fib6_walker *w) {write_lock_bh (&net->ipv6.fib6_walker_lock); -list_del (&w->lh); +list_del_init (&w->lh);write_unlock_bh (&net->ipv6.fib6_walker_lock); }
@@ -2715,7 +2715,7 @@ static void *ipv6_route_seq_start(structstatic bool ipv6_route_iter_active (struct ipv6_route_iter *iter) {struct fib6_walker *w = &iter->w; -return w->node && !(w->state ==FWS_U && w->node == w->root); +return w->node && !list_empty (&w->lh); }static void ipv6_route_native_seq_stop (struct seq_file *seq,void *v)
Greg Kroah-Hartman
maintainerPATCH 602/1193 tracing: Fix memory corruption from the histogram stacktrace modifier
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
commit a5e70ba87ca8ebc79b4e63de302d03b0625fe153 upstream.
parse_field() sets HIST_FIELD_FL_STACKTRACE from the ".stacktrace" modifier before it looks the field name up, and nothing afterwards checks that the name resolved to a field which holds a stacktrace. create_hist_field() picks HIST_FIELD_FN_STACK on the strength of the field pointer alone, which reads a __data_loc word from the record and follows its low 16 bits as an offset into the same record. event_hist_trigger() takes the first word there as an entry count and copies that many longs into a 31 entry array:
n_entries = *stack; memcpy(entries, ++stack, n_entries * sizeof(unsigned long));
Neither end of that copy is bounded, and the count is whatever the event holds at the offset, so any field will do:
# cd /sys/kernel/tracing/events/sched/sched_process_fork # echo 'hist:keys=parent_pid.stacktrace' > trigger # (true)
BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:rb_insert_color+0x18/0x130 timerqueue_linked_add+0x7e/0xd0 enqueue_hrtimer+0x39/0xb0 __hrtimer_run_queues+0x10f/0x1f0 </IRQ> RIP: 0010:memcpy+0xc/0x30 event_hist_trigger+0x165/0x690
The timer interrupt landed on the rbtree the copy had already run over. No debug options are needed for this; KASAN reports the same write as an out-of-bounds read of 13835058055416381440 bytes.
Documentation/trace/histogram.rst already states the rule, "must be a long[] type", so enforce it once the name has been resolved. Names which resolve to no field at all, "hitcount.stacktrace" and the common_* pseudo-fields, are refused for the same reason: they hold no stacktrace to read.
--- kernel/trace/trace_events_hist.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +10 -2
@@ -2307,6 +2307,7 @@ parse_field(struct hist_trigger_data *histruct ftrace_event_field *field =NULL ;char *field_name, *modifier, *str;struct trace_array *tr = file->tr; +bool stack_modifier = false; modifier = str =kstrdup (field_str,GFP_KERNEL );if (!modifier)
@@ -2329,9 +2330,10 @@ parse_field(struct hist_trigger_data *hi *flags |=HIST_FIELD_FL_EXECNAME ; else if (strcmp(modifier, "syscall") == 0) *flags |= HIST_FIELD_FL_SYSCALL; - else if (strcmp(modifier, "stacktrace") == 0) + else if (strcmp(modifier, "stacktrace") == 0) { *flags |= HIST_FIELD_FL_STACKTRACE; - else if (strcmp(modifier, "log2") == 0) + stack_modifier = true; + } else if (strcmp(modifier, "log2") == 0) *flags |= HIST_FIELD_FL_LOG2; else if (strcmp(modifier, "usecs") == 0) *flags |= HIST_FIELD_FL_TIMESTAMP_USECS;
@@ -2398,6 +2400,12 @@ parse_field(struct hist_trigger_data *hi } } } + +if (stack_modifier && + (!field || field->filter_type !=FILTER_STACKTRACE )) { +hist_err (tr,HIST_ERR_BAD_FIELD_MODIFIER ,errpos (field_str)); + field =ERR_PTR (-EINVAL ); + } out:kfree (str);
Greg Kroah-Hartman
maintainerPATCH 603/1193 ALSA: ctxfi: Fix CA20K2 S/PDIF passthrough
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roman Prucha <[email protected]>
commit b26a7a80e6bbf8dd17dacb127d12435d79375cf2 upstream.
dao_rsc_init() encodes the DAIO configuration as
conf = (desc->msr & 0x7) | (desc->passthru << 3);
S/PDIF passthrough uses msr=1 and passthru=1, resulting in conf=9.
daio_mgr_dao_init() masks conf with 0xf, but handles only values 1, 2, 4 and 8 when programming ATXCTL_NUC. As a result, conf=9 falls through to the default case and leaves NUC at its previous setting.
On a Creative X-Fi Titanium HD SB1270 (CA20K2), this breaks AC3 IEC61937 passthrough when snd_ctxfi runs with reference_rate=48000,multiple=2. The receiver detects a non-audio stream but cannot decode the AC3 payload.
With the unmodified driver, multiple=1 makes the same stream work. Handle conf=9 through the same NUC=0 path as conf=1.
The change was runtime tested on the SB1270 with multiple=2 using IEC958 stereo PCM, pre-encoded AC3 IEC61937 passthrough and ALSA A52 live 5.1 encoding.
--- sound/pci/ctxfi/cthw20k2.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/ctxfi/cthw20k2.c +1 -0
@@ -993,6 +993,7 @@ static int daio_mgr_dao_init(void *blk,/* S/PDIF output */ switch ((conf &0xf )) {case 1 : +case 9 :set_field (&ctl->txctl[idx],ATXCTL_NUC ,0 );break ;case 2 :
Greg Kroah-Hartman
maintainerPATCH 604/1193 ALSA: usbusx2y: fix in04_last array size mismatch with in04_buf
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 861111a14740e12c36d363e9830f8daa734279c9 upstream.
The in04_last array in struct usx2ydev is declared as char[24], but in04_buf is allocated as sizeof(struct us428_ctls) which is 21 bytes. In i_usx2y_in04_int(), when ctl_snapshot_last == -2 (initialization path):
memcpy(usx2y->in04_last, usx2y->in04_buf, sizeof(usx2y->in04_last));
This copies 24 bytes from a 21-byte slab allocation, reading 3 bytes past the end of the source object.
Introduce a USX2Y_IN04_SIZE constant defined as sizeof(struct us428_ctls) and use it consistently for the in04_last array, the in04_buf allocation, the URB transfer length, and the comparison loop, replacing the bare 24 and 21 literals throughout.
--- sound/usb/usx2y/usbusx2y.c | 6 +++--- sound/usb/usx2y/usbusx2y.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-)
sound/usb/usx2y/usbusx2y.c +3 -3
@@ -197,7 +197,7 @@ static void i_usx2y_in04_int(struct urbmemcpy (usx2y->in04_last, usx2y->in04_buf,sizeof (usx2y->in04_last)); us428ctls->ctl_snapshot_last =-1 ; }else { -for (i =0 ; i <21 ; i++) { +for (i =0 ; i <USX2Y_IN04_SIZE ; i++) {if (usx2y->in04_last[i] != ((char *)usx2y->in04_buf)[i]) {if (diff <0 ) diff = i;
@@ -306,7 +306,7 @@ int usx2y_in04_init(struct usx2ydev *usx goto error; } - usx2y->in04_buf =kmalloc (21 ,GFP_KERNEL ); + usx2y->in04_buf =kmalloc (USX2Y_IN04_SIZE ,GFP_KERNEL );if (!usx2y->in04_buf) { err = -ENOMEM ; goto error;
@@ -314,7 +314,7 @@ int usx2y_in04_init(struct usx2ydev *usxinit_waitqueue_head (&usx2y->in04_wait_queue);usb_fill_int_urb (usx2y->in04_urb, usx2y->dev,usb_rcvintpipe (usx2y->dev,0x4 ), - usx2y->in04_buf,21 , + usx2y->in04_buf,USX2Y_IN04_SIZE , i_usx2y_in04_int, usx2y,10 );if (usb_urb_ep_type_check (usx2y->in04_urb)) {
sound/usb/usx2y/usbusx2y.h +3 -1
@@ -5,6 +5,8 @@#include "../midi.h" #include "usbus428ctldefs.h" +#define USX2Y_IN04_SIZE sizeof(struct us428_ctls) +#define NRURBS 2/* Default value used for nr of packs per urb.
@@ -55,7 +57,7 @@ struct usx2ydev {int stride;struct urb *in04_urb;void *in04_buf; -char in04_last[24 ]; +char in04_last[USX2Y_IN04_SIZE ];unsigned int in04_int_calls;struct snd_usx2y_urb_seq *us04;wait_queue_head_t in04_wait_queue;
Greg Kroah-Hartman
maintainerPATCH 605/1193 dm/amdgpu: fix malformed link_settings debugfs output
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Wentland <[email protected]>
commit 622b4e8505aa7453a53d17fa3a288871f270fc8b upstream.
[Why]dp_link_settings_read() passed strlen() of each format string as the size argument to snprintf() and then advanced rd_buf_ptr by that same fixed amount. The format-string length has no relation to the formatted output length, so snprintf() truncated each field at a NUL it wrote inside the buffer while the pointer was advanced past it. The result is a buffer peppered with embedded NUL bytes and fields that are silently cut short, so the data read back from the debugfs node does not reflect the actual link settings.
[How]
Use scnprintf() with the real remaining buffer size (rd_buf_size - (rd_buf_ptr - rd_buf)) and advance rd_buf_ptr by its return value, which is the number of characters actually written. This both bounds each write to the space left in rd_buf and keeps the output a single, properly terminated string. The now-unused str_len local is removed.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 20 +++++--------- 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +8 -12
@@ -190,7 +190,6 @@ static ssize_t dp_link_settings_read(strchar *rd_buf_ptr =NULL ;const uint32_t rd_buf_size =100 ;uint32_t result =0 ; -uint8_t str_len =0 ;int r;if (*pos &3 || size &3 )
@@ -202,29 +201,26 @@ static ssize_t dp_link_settings_read(str rd_buf_ptr = rd_buf; - str_len =strlen ("Current: %d 0x%x %d " ); -snprintf (rd_buf_ptr, str_len,"Current: %d 0x%x %d " , + rd_buf_ptr +=scnprintf (rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf), +"Current: %d 0x%x %d " , link->cur_link_settings.lane_count, link->cur_link_settings.link_rate, link->cur_link_settings.link_spread); - rd_buf_ptr += str_len; - str_len =strlen ("Verified: %d 0x%x %d " ); -snprintf (rd_buf_ptr, str_len,"Verified: %d 0x%x %d " , + rd_buf_ptr +=scnprintf (rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf), +"Verified: %d 0x%x %d " , link->verified_link_cap.lane_count, link->verified_link_cap.link_rate, link->verified_link_cap.link_spread); - rd_buf_ptr += str_len; - str_len =strlen ("Reported: %d 0x%x %d " ); -snprintf (rd_buf_ptr, str_len,"Reported: %d 0x%x %d " , + rd_buf_ptr +=scnprintf (rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf), +"Reported: %d 0x%x %d " , link->reported_link_cap.lane_count, link->reported_link_cap.link_rate, link->reported_link_cap.link_spread); - rd_buf_ptr += str_len; - str_len =strlen ("Preferred: %d 0x%x %d " ); -snprintf (rd_buf_ptr, str_len,"Preferred: %d 0x%x %d\n" , + rd_buf_ptr +=scnprintf (rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf), +"Preferred: %d 0x%x %d\n" , link->preferred_link_setting.lane_count, link->preferred_link_setting.link_rate, link->preferred_link_setting.link_spread);
Greg Kroah-Hartman
maintainerPATCH 606/1193 watchdog: sunxi_wdt: preserve boot-enabled watchdog
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
commit aab55360fa11a2c054798a484ac67ad606f563e4 upstream.
sunxi_wdt_probe() unconditionally stops the watchdog even when firmware left it running. This opens an unprotected interval during boot and prevents CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED from taking over the active watchdog.
Detect an enabled watchdog and decode its programmed interval. Preserve representable timeouts, and round the 0.5-second interval up to the minimum representable one-second timeout. Use the configured timeout for reserved interval encodings. Set the Linux reset mode and ping the watchdog without clearing its enable bit, then mark it hardware-running before registration so the watchdog core services it until userspace takes control. Leave disabled watchdogs untouched.
--- drivers/watchdog/sunxi_wdt.c | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
drivers/watchdog/sunxi_wdt.c +44 -1
@@ -128,6 +128,38 @@ static int sunxi_wdt_ping(struct watchdoreturn 0 ; } +static bool sunxi_wdt_is_running (struct watchdog_device *wdt_dev) +{ +struct sunxi_wdt_dev *sunxi_wdt =watchdog_get_drvdata (wdt_dev); +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs; + +return readl (sunxi_wdt->wdt_base + regs->wdt_mode) &WDT_MODE_EN ; +} + +static unsigned int sunxi_wdt_get_timeout (struct watchdog_device *wdt_dev) +{ +struct sunxi_wdt_dev *sunxi_wdt =watchdog_get_drvdata (wdt_dev); +const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs; +unsigned int timeout; +u32 interval; + + interval =readl (sunxi_wdt->wdt_base + regs->wdt_mode); + interval >>= regs->wdt_timeout_shift; + interval &=WDT_TIMEOUT_MASK ; +/* Round the 0.5-second interval up to the minimum representable timeout. */ +if (!interval) +return WDT_MIN_TIMEOUT ; + +for (timeout =WDT_MIN_TIMEOUT ; + timeout <ARRAY_SIZE (wdt_timeout_map); timeout++) { +if (wdt_timeout_map[timeout] == interval) +return timeout; + } + +/* Reserved interval encoding. */ +return 0 ; +} +static int sunxi_wdt_set_timeout (struct watchdog_device *wdt_dev,unsigned int timeout) {
@@ -248,6 +280,7 @@ static int sunxi_wdt_probe(struct platfo {struct device *dev = &pdev->dev;struct sunxi_wdt_dev *sunxi_wdt; +unsigned int running_timeout;int err; sunxi_wdt =devm_kzalloc (dev,sizeof (*sunxi_wdt),GFP_KERNEL );
@@ -275,7 +308,17 @@ static int sunxi_wdt_probe(struct platfowatchdog_set_drvdata (&sunxi_wdt->wdt_dev, sunxi_wdt); -sunxi_wdt_stop (&sunxi_wdt->wdt_dev); +if (sunxi_wdt_is_running (&sunxi_wdt->wdt_dev)) { + running_timeout =sunxi_wdt_get_timeout (&sunxi_wdt->wdt_dev); +if (running_timeout) + sunxi_wdt->wdt_dev.timeout = running_timeout; + + err =sunxi_wdt_start (&sunxi_wdt->wdt_dev); +if (err) +return err; + +set_bit (WDOG_HW_RUNNING , &sunxi_wdt->wdt_dev.status); + }watchdog_stop_on_reboot (&sunxi_wdt->wdt_dev); err =devm_watchdog_register_device (dev, &sunxi_wdt->wdt_dev);
Greg Kroah-Hartman
maintainerPATCH 607/1193 ufs: create the root dentry after loading cylinder metadata
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
commit 55a4c98abb9694b067c6a031d11501f06b6b523c upstream.
ufs_fill_super() installed sb->s_root before it loaded the cylinder group structures for a writable mount:
sb->s_root = d_make_root(inode); ... if (!sb_rdonly(sb)) if (!ufs_read_cylinder_structures(sb)) goto failed;
When ufs_read_cylinder_structures() failed, the error path freed the in-core superblock information and set sb->s_fs_info to NULL while sb->s_root stayed installed. get_tree_bdev() then reached deactivate_locked_super(), and because s_root was present, generic_shutdown_super() called sync_filesystem() and the put_super operation. Both dereference UFS_SB(sb), which is now NULL, so a mount that fails only while reading the cylinder groups oopses during teardown. A crafted image whose first cylinder group cannot be read reaches this path.
Load the cylinder group metadata first and create the root dentry last, so the superblock is published to the VFS only once it is fully set up. ufs_setup_cstotal() and ufs_read_cylinder_structures() take only the super_block and do not use the root inode, so the reordering is safe.
--- fs/ufs/super.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
fs/ufs/super.c +9 -8
@@ -1268,6 +1268,15 @@ magic_found: sb->s_maxbytes =ufs_max_bytes (sb); sb->s_max_links =UFS_LINK_MAX ; +ufs_setup_cstotal (sb); +/* +* Read cylinder group structures +*/ +if (!sb_rdonly (sb)) +if (!ufs_read_cylinder_structures (sb)) + goto failed; + +/* create the root dentry last, once UFS_SB(sb) is fully set up */ inode =ufs_iget (sb,UFS_ROOTINO );if (IS_ERR (inode)) { ret =PTR_ERR (inode);
@@ -1279,14 +1288,6 @@ magic_found: goto failed; } -ufs_setup_cstotal (sb); -/* -* Read cylinder group structures -*/ -if (!sb_rdonly (sb)) -if (!ufs_read_cylinder_structures (sb)) - goto failed; -UFSD ("EXIT\n" );return 0 ;
Greg Kroah-Hartman
maintainerPATCH 608/1193 ufs: validate cylinder group metadata before caching it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
commit c9d263be26806d388129fab8c6904bed197fc6af upstream.
ufs_read_cylinder() copies the cylinder group index and the rotor positions straight from the on-disk group and caches them without any check:
ucpi->c_cgx = fs32_to_cpu(sb, ucg->cg_cgx); ucpi->c_rotor = fs32_to_cpu(sb, ucg->cg_rotor); ucpi->c_frotor = fs32_to_cpu(sb, ucg->cg_frotor); ucpi->c_irotor = fs32_to_cpu(sb, ucg->cg_irotor);
They are then used as indices during allocation and free:
- c_cgx indexes the cylinder summary array as UFS_SB(sb)->fs_cs(ucpi->c_cgx), so a value past s_ncg writes a 32 bit count outside the s_csp allocation.
- c_frotor becomes a bitmap scan start, start = c_frotor >> 3, and then length = ((s_fpg + 7) >> 3) - start. A start beyond the block bitmap wraps the unsigned length to a huge value, so ubh_scanc() walks far past the cylinder group buffers. c_irotor drives the inode bitmap the same way.
A crafted image can set any of these freely, turning an ordinary allocation into an out of bounds access.
Reject a cylinder group whose recorded index does not match the group being read, or whose rotors fall outside the group, before the metadata is cached. Valid filesystems keep cg_cgx equal to the group number and the rotors within the group, so only malformed images are rejected.
--- fs/ufs/cylinder.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/ufs/cylinder.c +10 -0
@@ -66,6 +66,16 @@ static void ufs_read_cylinder (struct su ucpi->c_clustersumoff =fs32_to_cpu (sb, ucg->cg_u.cg_44.cg_clustersumoff); ucpi->c_clusteroff =fs32_to_cpu (sb, ucg->cg_u.cg_44.cg_clusteroff); ucpi->c_nclusterblks =fs32_to_cpu (sb, ucg->cg_u.cg_44.cg_nclusterblks); + +/* these on-disk values become array and bitmap indices */ +if (ucpi->c_cgx != cgno || + ucpi->c_rotor >= uspi->s_fpg || + ucpi->c_frotor >= uspi->s_fpg || + ucpi->c_irotor >= uspi->s_ipg) { +ufs_error (sb, __func__, +"inconsistent metadata in cylinder group %u\n" , cgno); + goto failed; + }UFSD ("EXIT\n" );return ;
Greg Kroah-Hartman
maintainerPATCH 609/1193 tunnels: Drop stale dst when building an ICMP error for PMTUD
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
commit b58d749633203d92c265317b45fccee555090352 upstream.
Bridged UDP tunnels such as VXLAN and GENEVE build an ICMP error packet around an overlay packet if the packet is going to exceed the underlay path MTU. The ICMP error packet is then injected back into the Rx path with the source and destination addresses swapped, so that it will be delivered to the overlay source.
If the overlay packet was routed to the UDP tunnel or locally generated, then it is already carrying a valid dst entry and this entry is not dropped when transforming the packet to an ICMP error packet. This causes the IP layer to reuse the dst entry, leading to the ICMP error packet being dropped or routed out of the UDP tunnel interface in case of forwarding.
Prior to the blamed commit this could not happen, as skb_tunnel_check_pmtu() did not build ICMP errors for PACKET_HOST packets. Such packets were instead encapsulated and, unless the DF bit was set in the outer header, fragmented by the underlay.
Fix this by making sure that the ICMP error packet does not have a valid dst entry, thereby forcing the IP layer to perform a route lookup.
Adjust the bridged PMTU exception selftests accordingly. When the local sender in ns_a pings the overlay destination with a deadline (-w), ping exits on the first socket error before any reply is received and returns a non-zero exit code. The test therefore only passed because the ICMP error was never delivered. Use a packet count (-c) like the ns_c line above it, so that the ICMP error counts against the packet budget and the exit code depends on whether echo replies were received. This passes with and without the fix.
--- net/ipv4/ip_tunnel_core.c | 6 ++++++ tools/testing/selftests/net/pmtu.sh | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
net/ipv4/ip_tunnel_core.c +6 -0
@@ -250,6 +250,9 @@ static int iptunnel_pmtud_build_icmp(streth_header (skb, skb->dev,ntohs (eh.h_proto), eh.h_source, eh.h_dest,0 );skb_reset_mac_header (skb); +if (skb_valid_dst (skb)) +skb_dst_drop (skb); +return skb->len; }
@@ -353,6 +356,9 @@ static int iptunnel_pmtud_build_icmpv6(seth_header (skb, skb->dev,ntohs (eh.h_proto), eh.h_source, eh.h_dest,0 );skb_reset_mac_header (skb); +if (skb_valid_dst (skb)) +skb_dst_drop (skb); +return skb->len; }
tools/testing/selftests/net/pmtu.sh +1 -1
@@ -1363,7 +1363,7 @@ test_pmtu_ipvX_over_bridged_vxlanY_or_ge mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1 - run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 1 + run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1 # Check that exceptions were created pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
Greg Kroah-Hartman
maintainerPATCH 610/1193 tick/broadcast: Plug clockevents replacement race
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
commit 113a9796effe3376d2ec5aabcca1fef4fef4cd62 upstream.
朱恺乾 reported and decoded the following race condition when a broadcast device is replaced:
CPUA CPUB
__tick_broadcast_oneshot_control()
bc = tick_broadcast_device.evtdev;
tick_install_broadcast_device(dev)
clockevents_exchange_device(cur, dev)
shutdown(cur);
detach(cur);
cur->handler = noop;
tick_broadcast_device.evtdev = dev; tick_broadcast_set_event(bc, next_event); <- FAIL: arms a detached device.
If the original broadcast device has a restricted interrupt affinity mask and the last CPU in that mask goes offline then the BUG() in tick_cleanup_dead_cpu() triggers because the clockevent device is not in detached state.
The reason for this is that tick_install_broadcast_device() is not serialized vs. tick broadcast operations.
The obvious cure is to serialize tick_install_broadcast_device() with tick_broadcast_lock against a concurrent tick broadcast operation.
That requires to split clockevents_exchange_device() into two parts, one which does the exchange, shutdown and detach operation and the other which drops the module reference count. This is required because the module reference cannot be dropped while holding tick_broadcast_lock.
Let clockevents_exchange_device() do both operations as before, but let the broadcast device code take the two step approach and do the device exchange under tick_broadcast_lock and drop the module reference count after releasing it.
--- kernel/time/clockevents.c | 33 ++++++++++++++++++++------------- kernel/time/tick-broadcast.c | 36 ++++++++++++++++++++++-------------- kernel/time/tick-internal.h | 2 ++ 3 files changed, 44 insertions(+), 27 deletions(-)
kernel/time/clockevents.c +20 -13
@@ -557,34 +557,41 @@ void clockevents_handle_noop(struct cloc { } -/** -* clockevents_exchange_device - release and request clock devices -* @old: device to release (can be NULL) -* @new: device to request (can be NULL) -* -* Called from various tick functions with clockevents_lock held and -* interrupts disabled. -*/ -void clockevents_exchange_device (struct clock_event_device *old, -struct clock_event_device *new) +void __clockevents_exchange_device (struct clock_event_device *old, +struct clock_event_device *new) {/* * Caller releases a clock event device. We queue it into the * released list and do a notify add later. */ if (old) { -module_put (old->owner);clockevents_switch_state (old,CLOCK_EVT_STATE_DETACHED );list_move (&old->list, &clockevents_released); }if (new) { -BUG_ON (!clockevent_state_detached (new)); +WARN_ON (!clockevent_state_detached (new));clockevents_shutdown (new); } }/** +* clockevents_exchange_device - release and request clock devices +* @old: device to release (can be NULL) +* @new: device to request (can be NULL) +* +* Called from various tick functions with clockevents_lock held and +* interrupts disabled. +*/ +void clockevents_exchange_device (struct clock_event_device *old, +struct clock_event_device *new) +{ +__clockevents_exchange_device (old, new); +if (old) +module_put (old->owner); +} + +/** * clockevents_suspend - suspend clock devices */ void clockevents_suspend (void )
@@ -650,7 +657,7 @@ void tick_cleanup_dead_cpu(int cpu)if (cpumask_test_cpu (cpu, dev->cpumask) &&cpumask_weight (dev->cpumask) ==1 && !tick_is_broadcast_device (dev)) { -BUG_ON (!clockevent_state_detached (dev)); +WARN_ON (!clockevent_state_detached (dev));list_del (&dev->list); } }
kernel/time/tick-broadcast.c +22 -14
@@ -162,23 +162,31 @@ static bool tick_set_oneshot_wakeup_devi*/ void tick_install_broadcast_device (struct clock_event_device *dev,int cpu) { -struct clock_event_device *cur = tick_broadcast_device.evtdev; +struct clock_event_device *cur; -if (tick_set_oneshot_wakeup_device (dev, cpu)) -return ; + scoped_guard(raw_spinlock_irqsave, &tick_broadcast_lock) { -if (!tick_check_broadcast_device (cur, dev)) -return ; +if (tick_set_oneshot_wakeup_device (dev, cpu)) +return ; -if (!try_module_get (dev->owner)) -return ; + cur = tick_broadcast_device.evtdev; +if (!tick_check_broadcast_device (cur, dev)) +return ; -clockevents_exchange_device (cur, dev); +if (!try_module_get (dev->owner)) +return ; + +__clockevents_exchange_device (cur, dev); +if (cur) + cur->event_handler = clockevents_handle_noop; +WRITE_ONCE (tick_broadcast_device.evtdev, dev); +if (!cpumask_empty (tick_broadcast_mask)) +tick_broadcast_start_periodic (dev); + } + +/* Module release must be outside of the lock */ if (cur) - cur->event_handler = clockevents_handle_noop; - tick_broadcast_device.evtdev = dev; -if (!cpumask_empty (tick_broadcast_mask)) -tick_broadcast_start_periodic (dev); +module_put (cur->owner);if (!(dev->features &CLOCK_EVT_FEAT_ONESHOT ))return ;
@@ -1209,7 +1217,7 @@ int tick_broadcast_oneshot_active(void)*/ bool tick_broadcast_oneshot_available (void ) { -struct clock_event_device *bc = tick_broadcast_device.evtdev; +struct clock_event_device *bc =READ_ONCE (tick_broadcast_device.evtdev);return bc ? bc->features &CLOCK_EVT_FEAT_ONESHOT : false; }
@@ -1217,7 +1225,7 @@ bool tick_broadcast_oneshot_available(vo#else int __tick_broadcast_oneshot_control (enum tick_broadcast_state state) { -struct clock_event_device *bc = tick_broadcast_device.evtdev; +struct clock_event_device *bc =READ_ONCE (tick_broadcast_device.evtdev);if (!bc || (bc->features &CLOCK_EVT_FEAT_HRTIMER ))return -EBUSY ;
kernel/time/tick-internal.h +2 -0
@@ -48,6 +48,8 @@ static inline void clockevent_set_state( }extern void clockevents_shutdown (struct clock_event_device *dev); +extern void __clockevents_exchange_device (struct clock_event_device *old, +struct clock_event_device *new);extern void clockevents_exchange_device (struct clock_event_device *old,struct clock_event_device *new); extern void clockevents_switch_state(struct clock_event_device *dev,
Greg Kroah-Hartman
maintainerPATCH 611/1193 tracing/user_events: Dont destroy fields when event removal fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Martin <[email protected]>
commit 2deb753127d7b7035e893955c5e91875e767d1f8 upstream.
destroy_user_event() destroys the event's fields before attempting to remove the trace event call. If user_event_set_call_visible() fails, e.g. because the event is still enabled and trace_remove_event_call() returns -EBUSY, the event is left registered with an irreversibly destroyed field list. Any subsequent interaction with the event then operates on an empty field list while it is still fully visible in tracefs.
Move the field destruction after the call removal, and splice the field list back onto the event when the removal fails so the event remains in a consistent state.
--- kernel/trace/trace_events_user.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
kernel/trace/trace_events_user.c +20 -6
@@ -1104,10 +1104,9 @@ static void user_event_destroy_validator } } -static void user_event_destroy_fields (struct user_event *user) +static void user_event_destroy_fields (struct list_head *head) {struct ftrace_event_field *field, *next; -struct list_head *head = &user->fields;list_for_each_entry_safe (field, next, head, link) {list_del (&field->link);
@@ -1494,17 +1493,32 @@ static int user_event_set_call_visible(sstatic int destroy_user_event (struct user_event *user) { +LIST_HEAD (fields);int ret =0 ;lockdep_assert_held (&event_mutex); -/* Must destroy fields before call removal */ -user_event_destroy_fields (user); +/* +* Detach the fields before removing the call. Removing the event +* frees the field list memory (trace_destroy_fields() is run on +* successful removal and kmem_cache_free()s the fields), but the +* fields here are allocated and owned by user_events. Destroy +* them separately once removal has succeeded. +*/ +list_splice_init (&user->fields, &fields); ret =user_event_set_call_visible (user, false); -if (ret) +if (ret) { +/* +* Removal failed and the event stays registered, recover +* the fields so it is left in a consistent state. +*/ +list_splice (&fields, &user->fields);return ret; + } + +user_event_destroy_fields (&fields);dyn_event_remove (&user->devent);hash_del (&user->node);
@@ -2149,7 +2163,7 @@ static int user_event_parse(struct user_ put_user_lock:mutex_unlock (&event_mutex); put_user: -user_event_destroy_fields (user); +user_event_destroy_fields (&user->fields);user_event_destroy_validators (user);kfree (user->call.print_fmt);kfree (user);
Greg Kroah-Hartman
maintainerPATCH 612/1193 tracing: Free histogram the var ref when its initialization fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
commit 516001d53e6b2ea95a251ee2ef54a1a689a3fd58 upstream.
create_var_ref() allocates a VAR_REF hist_field and then calls init_var_ref() to fill it in. When that fails the field is leaked.
commit 656fe2ba85e8 ("tracing: Use hist trigger's var_ref array to destroy var_refs") made destroy_hist_field() return early for HIST_FIELD_FL_VAR_REF, since var refs are freed by walking the trigger's var_refs[] array instead. create_var_ref() adds the field to that array only after init_var_ref() has succeeded, so on this path the field is in neither place and nothing frees it. The call was correct when it was written, before var refs were taken out of destroy_hist_field().
init_var_ref() cannot free it either. The caller owns the field, so init_var_ref() undoes only its own string allocations and leaves the field alone. Freeing it there would leave create_var_ref() passing freed memory to destroy_hist_field(), which reads its flags.
Call __destroy_hist_field(), which frees the field without consulting the flag.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -2211,7 +2211,7 @@ static struct hist_field *create_var_ref ref_field =create_hist_field (var_field->hist_data,NULL , flags,NULL );if (ref_field) {if (init_var_ref (ref_field, var_field, system, event_name)) { -destroy_hist_field (ref_field,0 ); +__destroy_hist_field (ref_field);return NULL ; }
Greg Kroah-Hartman
maintainerPATCH 613/1193 tracing: Free histogram var refs regardless of how often they are referenced
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
commit 4bddcb346a6cf4615ca77f69a589623b877ca267 upstream.
Using the same variable three or more times in one hist trigger leaks the variable reference and its strings when the trigger is removed.
commit 656fe2ba85e8 ("tracing: Use hist trigger's var_ref array to destroy var_refs") made a trigger's var_refs[] array the only owner of a var ref:destroy_hist_field() returns early for HIST_FIELD_FL_VAR_REF, so the field expressions never destroy one. One entry, freed once, no count needed.
commit 8bcebc77e85f ("tracing: Fix histogram code when expression has same var as value") then made repeated references share one object and added a count of them. Only the increment side exists, since those expressions still return early and never drop a reference, so __destroy_hist_field() sees how many references were created rather than how many are left. It frees when the decremented count is 0 or 1, so two references work and three or more leak.
Sharing kept one array entry per object, and create_var_ref() searches and appends within a single trigger, so nothing outside it holds the object. Removing a trigger whose variables are still referenced is already refused by check_var_refs() with -EBUSY. Drop the count and free unconditionally.
--- kernel/trace/trace_events_hist.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
kernel/trace/trace_events_hist.c +1 -15
@@ -163,7 +163,6 @@ struct hist_field {struct hist_field *operands[HIST_FIELD_OPERANDS_MAX ];struct hist_trigger_data *hist_data;enum hist_field_fn fn_num; -unsigned int ref;unsigned int size;unsigned int offset;unsigned int is_signed;
@@ -1895,16 +1894,8 @@ out:return field_op; } -static void get_hist_field (struct hist_field *hist_field) -{ - hist_field->ref++; -} -static void __destroy_hist_field (struct hist_field *hist_field) { -if (--hist_field->ref >1 ) -return ; -kfree (hist_field->var.name);kfree (hist_field->name);
@@ -1951,8 +1942,6 @@ static struct hist_field *create_hist_fiif (!hist_field)return NULL ; - hist_field->ref =1 ; - hist_field->hist_data = hist_data;if (flags &HIST_FIELD_FL_EXPR || flags &HIST_FIELD_FL_ALIAS )
@@ -2200,10 +2189,8 @@ static struct hist_field *create_var_reffor (i =0 ; i < hist_data->n_var_refs; i++) { ref_field = hist_data->var_refs[i];if (ref_field->var.idx == var_field->var.idx && - ref_field->var.hist_data == var_field->hist_data) { -get_hist_field (ref_field); + ref_field->var.hist_data == var_field->hist_data)return ref_field; - } }/* Sanity check to avoid out-of-bound write on 'hist_data->var_refs' */ if (hist_data->n_var_refs >=TRACING_MAP_VARS_MAX )
@@ -3242,7 +3229,6 @@ static struct hist_field *create_var(str goto out; } - var->ref =1 ; var->flags =HIST_FIELD_FL_VAR ; var->var.idx = idx; var->var.hist_data = var->hist_data = hist_data;
Greg Kroah-Hartman
maintainerPATCH 614/1193 tracing: Free histogram the field rejected for a bad modifier
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
commit 230234d12ce42ab04132a32c3a848f07a5d27a71 upstream.
Writing a hist trigger whose value or variable carries a modifier that is not allowed there leaks the fields that were built for it.
__create_val_field() takes the field from parse_expr() and stores it in hist_data->fields[] only after the modifier checks have run:
hist_field = parse_expr(hist_data, file, field_str, flags, var_name,
&n_subexprs);
...
if (hist_field->flags & HIST_FIELD_FL_VAR) {
if (hist_field->flags & (...))
goto err;
} else {
if (hist_field->flags & (...))
goto err;
}
hist_data->fields[val_idx] = hist_field;Both checks jump past that store, and the err label returns without freeing anything. The error unwinds to create_hist_data(), which calls destroy_hist_data() -> destroy_hist_fields(), and that reaches a field only by walking fields[]. A field that never got there is unreachable.
commit e0213434fe3e ("tracing: Do not let histogram values have some modifiers") set ret to -EINVAL and fell through to the store, which left the field owned by fields[] and freed along with the rest of hist_data. Splitting the check into a value case and a variable case replaced that fall-through with a goto that skips it.
With CONFIG_DEBUG_KMEMLEAK, 200 writes of
# echo 'hist:keys=prev_pid:vals=next_pid.log2' > \ events/sched/sched_switch/trigger
each correctly rejected with -EINVAL, leave 332 unreferenced objects (63744 bytes) reported at create_hist_field(); 200 install and remove cycles of a valid trigger leave none. A '.log2' field is two allocations, since create_hist_field() puts the plain field in operands[0] of the log2 field, and both are reported.
Use destroy_hist_field() rather than __destroy_hist_field() so that operands[0] is freed as well. It returns early for HIST_FIELD_FL_VAR_REF, which is what an operand owned by hist_data->var_refs[] needs; the rejected field itself is never a var ref, because a var ref never carries a modifier flag.
--- kernel/trace/trace_events_hist.c | 1 + 1 file changed, 1 insertion(+)
kernel/trace/trace_events_hist.c +1 -0
@@ -4283,6 +4283,7 @@ static int __create_val_field(struct hisreturn ret; err:hist_err (file->tr,HIST_ERR_BAD_FIELD_MODIFIER ,errpos (field_str)); +destroy_hist_field (hist_field,0 );return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 615/1193 tracing: Let histogram values keep the percent and graph modifiers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
commit 3d617bfd79330ae3acf94862c18bb3ccf5f5a0f9 upstream.
The .percent and .graph modifiers exist only for histogram values, but a value carrying either of them has been rejected since v6.3. The example in Documentation/trace/histogram.rst,
# echo 'hist:keys=prev_comm:vals=hitcount.percent:nohitcount' > \ events/sched/sched_switch/trigger
returns -EINVAL.
parse_field() sets the two flags only when the field is neither a key nor a variable, that is, only on a value:
} else if (strncmp(modifier, "percent", 7) == 0) {
if (*flags & (HIST_FIELD_FL_VAR | HIST_FIELD_FL_KEY))
goto error;
*flags |= HIST_FIELD_FL_PERCENT;__create_val_field() then rejects a value for carrying them, so no field can reach hist_trigger_print_val(), where both are implemented.
commit e0213434fe3e ("tracing: Do not let histogram values have some modifiers") added the check after a value with .buckets oopsed in hist_field_name(). That happens because .buckets and .log2 make create_hist_field() build a nested field in operands[0] which hist_field_name() then walks into. The percent and graph flags do not create an operand and are not read by hist_field_name(); they are only used when printing a value.
Stop rejecting the two flags on a value. The check for variables is left alone, where they are unreachable anyway because parse_field() rejects a variable carrying them first.
With the two flags removed, the trigger above installs and prints as documented:
{ prev_comm: rcu_preempt } hitcount (%): 0.00
{ prev_comm: init } hitcount (%): 99.98
Totals:
Hits: 237896--- kernel/trace/trace_events_hist.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +1 -2
@@ -4265,8 +4265,7 @@ static int __create_val_field(struct his goto err; }else {/* Value */ -if (hist_field->flags & (HIST_FIELD_FL_GRAPH |HIST_FIELD_FL_PERCENT | -HIST_FIELD_FL_BUCKET |HIST_FIELD_FL_LOG2 | +if (hist_field->flags & (HIST_FIELD_FL_BUCKET |HIST_FIELD_FL_LOG2 |HIST_FIELD_FL_SYM |HIST_FIELD_FL_SYM_OFFSET |HIST_FIELD_FL_SYSCALL |HIST_FIELD_FL_STACKTRACE )) goto err;
Greg Kroah-Hartman
maintainerPATCH 616/1193 tracing: Keep the entry count when the histogram stats allocation fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
commit 06f5634ec5584954177f9a22e36b3bfb398a971b upstream.
print_entries() uses n_entries both as the number of sort entries and as its own return value, so the -ENOMEM it stores when the stats allocation fails overwrites the count that the cleanup still needs:
n_entries = tracing_map_sort_entries(map, ...);
if (n_entries < 0)
return n_entries;
...
if (!stats) {
n_entries = -ENOMEM;
goto out;
}
...
out:
tracing_map_destroy_sort_entries(sort_entries, n_entries);tracing_map_destroy_sort_entries() takes an unsigned int and loops up to it, so -ENOMEM arrives as 4294967284. It walks an array of at most map->max_elts pointers and calls destroy_sort_entry(), which dereferences and frees, on whatever lies past the end.
Reading the hist file of a trigger with a .percent value, with that allocation forced to fail:
BUG: KASAN: vmalloc-out-of-bounds in tracing_map_destroy_sort_entries+0xa0/0xb0 Read of size 8 at addr ffffc90000045000 by task init/1 tracing_map_destroy_sort_entries+0xa0/0xb0 hist_show+0x6f7/0x1df0 seq_read_iter+0x2b8/0x1190 vfs_read+0x176/0xa40 The buggy address belongs to a 4-page vmalloc region starting at ffffc90000041000 allocated at tracing_map_sort_entries+0x5c/0xd50
A few pages further the fault is fatal. The registers at the oops confirm the bound: the loop's end pointer less the array start, over the pointer size, is 4294967284.
Return the error in a separate variable and leave n_entries holding the count, the way tracing_map_sort_entries() does on its own error path.
The stats block is only entered for a value carrying .percent or .graph, which __create_val_field() has rejected since v6.3, so this cannot be reached in mainline as it stands. It becomes reachable again with "tracing: hist: let values keep the percent and graph modifiers", so it should be applied first.
--- kernel/trace/trace_events_hist.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/trace/trace_events_hist.c +5 -3
@@ -5638,7 +5638,7 @@ static int print_entries(struct seq_file {struct tracing_map_sort_entry **sort_entries =NULL ;struct tracing_map *map = hist_data->map; -int i, j, n_entries; +int i, j, n_entries, ret;struct hist_val_stat *stats =NULL ;u64 val;
@@ -5648,6 +5648,8 @@ static int print_entries(struct seq_fileif (n_entries <0 )return n_entries; + ret = n_entries; +/* Calculate the max and the total for each field if needed. */ for (j =0 ; j < hist_data->n_vals; j++) { if (!(hist_data->fields[j]->flags &
@@ -5657,7 +5659,7 @@ static int print_entries(struct seq_file stats =kcalloc (hist_data->n_vals,sizeof (*stats),GFP_KERNEL );if (!stats) { - n_entries = -ENOMEM ; + ret = -ENOMEM ; goto out; } }
@@ -5678,7 +5680,7 @@ static int print_entries(struct seq_file out:tracing_map_destroy_sort_entries (sort_entries, n_entries); -return n_entries; +return ret; } static void hist_trigger_show(struct seq_file *m,
Greg Kroah-Hartman
maintainerPATCH 617/1193 ASoC: sprd: validate compress buffer sizes against fixed allocations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit 7a4ce92d150b9e7ecf1a710a34d8cdeb590d3751 upstream.
sprd_platform_compr_open() allocates the stage 0 IRAM buffer (32K data area) and the stage 1 DDR buffer (2M data area) with fixed sizes, but sprd_platform_compr_copy() derives all copy lengths from the user controlled runtime->fragment_size and the write() count, never comparing them against the physical buffer sizes. The compress core only checks fragment_size * fragments for an u32 overflow in snd_compress_check_input(), so a local user can configure a logical buffer of up to ~4GB via SNDRV_COMPRESS_SET_PARAMS, far exceeding the fixed allocations.
A fragment_size larger than the 32K IRAM data area makes the stage 0 copy_from_user() overflow past the IRAM allocation, and a buffer_size larger than the 2M DDR buffer makes the wrapping copy at the end of sprd_platform_compr_copy() write fully user controlled data past the buffer. No SNDRV_PCM_TRIGGER_START is needed, a write() in SETUP state reaches the copy callback directly.
Reject parameters that do not fit into the fixed buffers in set_params(), and fix the advertised max fragment size: 128K never fitted into the 32K IRAM buffer. The caps values may have been carried over from the qdsp6 driver, which allocates its buffers according to the advertised maxima, unlike this driver. With 32K as max fragment size the advertised limits are self-consistent: 32K * 64 = 2M equals the DDR buffer size.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- sound/soc/sprd/sprd-pcm-compress.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
sound/soc/sprd/sprd-pcm-compress.c +14 -1
@@ -17,7 +17,7 @@/* Default values if userspace does not set */ #define SPRD_COMPR_MIN_FRAGMENT_SIZE SZ_8K -#define SPRD_COMPR_MAX_FRAGMENT_SIZE SZ_128K +#define SPRD_COMPR_MAX_FRAGMENT_SIZE SZ_32K#define SPRD_COMPR_MIN_NUM_FRAGMENTS 4#define SPRD_COMPR_MAX_NUM_FRAGMENTS 64
@@ -272,6 +272,19 @@ static int sprd_platform_compr_set_paramint ret;/* +* The stage 0 IRAM buffer and the stage 1 DDR buffer are allocated +* with fixed sizes at open time, so the requested fragment size and +* fragments must fit into them, otherwise sprd_platform_compr_copy() +* would overflow the buffers. Note the compress core only checks the +* fragment size and fragments against an u32 overflow, not against +* the buffer sizes advertised by get_caps. +*/ +if (params->buffer.fragment_size >SPRD_COMPR_IRAM_BUF_SIZE || + (u64 )params->buffer.fragment_size * params->buffer.fragments > +SPRD_COMPR_AREA_BUF_SIZE ) +return -EINVAL ; + +/* * Configure the DMA engine 2-stage transfer mode. Channel 1 set as the * destination channel, and channel 0 set as the source channel, that * means once the source channel's transaction is done, it will trigger
Greg Kroah-Hartman
maintainerPATCH 618/1193 ASoC: sti: initialize IRQ lock before requesting IRQ
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 04405aeef4f8d7bcac6dcb1947acafdb4420c2c3 upstream.
uni_reader_init() registers the shared IRQ before initializing reader->irq_lock. A pending interrupt can invoke the handler while the lock is still uninitialized.
Initialize the lock before registering the IRQ so the interrupt path always sees valid lock state.
--- sound/soc/sti/uniperif_reader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/sti/uniperif_reader.c +2 -2
@@ -422,6 +422,8 @@ int uni_reader_init(struct platform_devielse reader->hw = &uni_reader_pcm_hw; +spin_lock_init (&reader->irq_lock); + ret =devm_request_irq (&pdev->dev, reader->irq, uni_reader_irq_handler,IRQF_SHARED ,dev_name (&pdev->dev), reader);
@@ -430,8 +432,6 @@ int uni_reader_init(struct platform_devireturn -EBUSY ; } -spin_lock_init (&reader->irq_lock); -return 0 ; }EXPORT_SYMBOL_GPL (uni_reader_init);
Greg Kroah-Hartman
maintainerPATCH 619/1193 Bluetooth: btrtl: Dont leak return code when parsing firmware format v2
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rong Zhang <[email protected]>
commit 83e3e515fd261600ed8491fb0a8bcdfb115c904e upstream.
When key_id from chip is zero, rtlbt_parse_firmware_v2() intentionally ignores all security headers. However, the implementation simply breaks from a switch statement and leaks uninitialized return code rc' (if the first section is a security one) or the previous section's rc'.
Fix it by really skipping a loop with `continue'. For consistency and readability, also do the same for the default case.
--- drivers/bluetooth/btrtl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/bluetooth/btrtl.c +2 -3
@@ -560,7 +560,7 @@ static int rtlbt_parse_firmware_v2(struc* headers. */ if (!key_id) -break ; +continue ; rc =btrtl_parse_section (hdev, btrtl_dev, opcode, ptr, section_len);break ;
@@ -569,8 +569,7 @@ static int rtlbt_parse_firmware_v2(struc ptr, section_len);break ;default : - rc =0 ; -break ; +continue ; }if (rc <0 ) { rtl_dev_err(hdev, "RTL: Parse section (%u) err %d",