6.18.66-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 324/990 cpufreq: Preserve global boost state on failed updates
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
[ Upstream commit a0cde2b601bc32b76d61e50141c619790e5e2e41 ]
cpufreq_boost_trigger_state() restores the opposite of the requested state when updating policy boost state fails. For example, a failed write of 0 when global boost is already disabled enables the global flag without enabling any policies.
Save the original global boost state and restore it on failure.
--- drivers/cpufreq/cpufreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +3 -1
@@ -2809,6 +2809,7 @@ static int cpufreq_boost_trigger_state(int state) {struct cpufreq_policy *policy;unsigned long flags; +bool boost_enabled;int ret = -EOPNOTSUPP ;/*
@@ -2817,6 +2818,7 @@ static int cpufreq_boost_trigger_state(int state)*/ write_lock_irqsave (&cpufreq_driver_lock, flags); + boost_enabled = cpufreq_driver->boost_enabled; cpufreq_driver->boost_enabled = state;write_unlock_irqrestore (&cpufreq_driver_lock, flags);
@@ -2843,7 +2845,7 @@ static int cpufreq_boost_trigger_state(int state)cpus_read_unlock ();write_lock_irqsave (&cpufreq_driver_lock, flags); - cpufreq_driver->boost_enabled = !state; + cpufreq_driver->boost_enabled = boost_enabled;write_unlock_irqrestore (&cpufreq_driver_lock, flags); pr_err("%s: Cannot %s BOOST\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 325/990 cpufreq: Serialize global boost updates
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
[ Upstream commit 3d5720dff09f3b90d9ab2a6707e4bb8d69542f4a ]
Concurrent global boost sysfs writes can interleave their global flag and per-policy updates. An enabling write can set the global flag, then a disabling write can clear it and finish before the enabling write updates the policies. Both writes succeed, leaving boost enabled on the policies while the global flag is disabled.
Serialize the complete global boost update, including rollback on failure, with a mutex.
--- drivers/cpufreq/cpufreq.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/cpufreq/cpufreq.c +4 -0
@@ -2805,6 +2805,8 @@ int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state) }EXPORT_SYMBOL_GPL (cpufreq_boost_set_sw); +static DEFINE_MUTEX (cpufreq_boost_mutex); +static int cpufreq_boost_trigger_state (int state) {struct cpufreq_policy *policy;
@@ -2812,6 +2814,8 @@ static int cpufreq_boost_trigger_state(int state)bool boost_enabled;int ret = -EOPNOTSUPP ; +guard (mutex)(&cpufreq_boost_mutex); +/* * Don't compare 'cpufreq_driver->boost_enabled' with 'state' here to * make sure all policies are in sync with global boost flag.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 326/990 Bluetooth: reject invalid LE supervision timeout relationships
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Pepper <[email protected]>
[ Upstream commit c1d50a71cdee90a0c68b7a67221d8aae96d14a0c ]
The LE parameter validator calculates an unsigned maximum latency by subtracting one from a truncated quotient. If the quotient is zero, this wraps and accepts invalid parameters. Exact quotient boundaries also accept equality where the supervision timeout must be greater.
Compare the products directly after checking the field bounds. The validated interval and latency limits keep the products within int. This enforces the strict timeout relationship without division or unsigned subtraction.
Sashiko identified the underflow while reviewing the soft interval preference RFC. The bug is already present in its unpatched base; keep this common-validator fix independent of that preference policy.
--- include/net/bluetooth/hci_core.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
include/net/bluetooth/hci_core.h +3 -10
@@ -2271,8 +2271,6 @@ static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,static inline int hci_check_conn_params (u16 min,u16 max,u16 latency,u16 to_multiplier) { -u16 max_latency; -if (min > max) {BT_WARN ("min %d > max %d" , min, max);return -EINVAL ;
@@ -2298,19 +2296,14 @@ static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,return -EINVAL ; } -if (max >= to_multiplier *8 ) { -BT_WARN ("max %d >= to_multiplier %d * 8" , max, to_multiplier); -return -EINVAL ; - } - - max_latency = (to_multiplier *4 / max) -1 ;if (latency >499 ) {BT_WARN ("latency %d > 499" , latency);return -EINVAL ; } -if (latency > max_latency) { -BT_WARN ("latency %d > max_latency %d" , latency, max_latency); +if ((latency +1 ) * max >= to_multiplier *4 ) { +BT_WARN ("latency %d, max %d and timeout %d are incompatible" , + latency, max, to_multiplier);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 327/990 net/mlx5e: IPoIB, Fix QPN lookup race
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prathamesh Deshpande <[email protected]>
[ Upstream commit 29066b0fc046a2965129a74325b98d9abb4647a9 ]
The parent RX completion path can load a QPN hash entry before mlx5i_pkey_del_qpn() unlinks and frees it, then dereference freed memory.
Use RCU hlist operations and defer freeing with kfree_rcu(). The existing RCU read-side section in mlx5e_napi_poll() covers the lookup. Keep ht_lock for writers and acquire it before looking up the entry to delete.
--- .../ethernet/mellanox/mlx5/core/ipoib/ipoib.h | 2 +- .../mellanox/mlx5/core/ipoib/ipoib_vlan.c | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h +1 -1
@@ -82,7 +82,7 @@ void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev);int mlx5i_pkey_add_qpn (struct net_device *netdev,u32 qpn);int mlx5i_pkey_del_qpn (struct net_device *netdev,u32 qpn); -/* Get the net-device corresponding to the given underlay QPN */ +/* Get the net-device for a QPN. Caller must hold rcu_read_lock(). */ struct net_device *mlx5i_pkey_get_netdev (struct net_device *netdev,u32 qpn);/* Shared ndo functions */
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c +15 -11
@@ -31,6 +31,7 @@*/ #include <linux/hash.h> +#include <linux/rculist.h> #include "ipoib.h" #define MLX5I_MAX_LOG_PKEY_SUP 7
@@ -39,11 +40,12 @@ struct qpn_to_netdev {struct net_device *netdev;struct hlist_node hlist;u32 underlay_qpn; +struct rcu_head rcu; };struct mlx5i_pkey_qpn_ht {struct hlist_head buckets[1 <<MLX5I_MAX_LOG_PKEY_SUP ]; -spinlock_t ht_lock;/* Synchronise with NAPI */ +spinlock_t ht_lock;/* Serialize hash table updates */ };int mlx5i_pkey_qpn_ht_init (struct net_device *netdev)
@@ -68,13 +70,14 @@ void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev)kfree (ipriv->qpn_htbl); } -static struct qpn_to_netdev *mlx5i_find_qpn_to_netdev_node (struct hlist_head *buckets, -u32 qpn) +static struct qpn_to_netdev * +mlx5i_find_qpn_to_netdev_node (struct mlx5i_pkey_qpn_ht *ht,u32 qpn) { -struct hlist_head *h = &buckets[hash_32 (qpn,MLX5I_MAX_LOG_PKEY_SUP )]; +struct hlist_head *h = &ht->buckets[hash_32 (qpn,MLX5I_MAX_LOG_PKEY_SUP )];struct qpn_to_netdev *node; -hlist_for_each_entry (node, h, hlist) { +hlist_for_each_entry_rcu (node, h, hlist, +lockdep_is_held (&ht->ht_lock)) {if (node->underlay_qpn == qpn)return node; }
@@ -96,7 +99,7 @@ int mlx5i_pkey_add_qpn(struct net_device *netdev, u32 qpn) new_node->netdev = netdev; new_node->underlay_qpn = qpn;spin_lock_bh (&ht->ht_lock); -hlist_add_head (&new_node->hlist, &ht->buckets[key]); +hlist_add_head_rcu (&new_node->hlist, &ht->buckets[key]);spin_unlock_bh (&ht->ht_lock);return 0 ;
@@ -109,16 +112,17 @@ int mlx5i_pkey_del_qpn(struct net_device *netdev, u32 qpn)struct mlx5i_pkey_qpn_ht *ht = ipriv->qpn_htbl;struct qpn_to_netdev *node; - node =mlx5i_find_qpn_to_netdev_node (ht->buckets, qpn); +spin_lock_bh (&ht->ht_lock); + node =mlx5i_find_qpn_to_netdev_node (ht, qpn);if (!node) { +spin_unlock_bh (&ht->ht_lock);mlx5_core_warn (epriv->mdev,"QPN to netdev delete from HT failed\n" );return -EINVAL ; } -spin_lock_bh (&ht->ht_lock); -hlist_del_init (&node->hlist); +hlist_del_rcu (&node->hlist);spin_unlock_bh (&ht->ht_lock); -kfree (node); +kfree_rcu (node, rcu);return 0 ; }
@@ -128,7 +132,7 @@ struct net_device *mlx5i_pkey_get_netdev(struct net_device *netdev, u32 qpn)struct mlx5i_priv *ipriv =netdev_priv (netdev);struct qpn_to_netdev *node; - node =mlx5i_find_qpn_to_netdev_node (ipriv->qpn_htbl->buckets, qpn); + node =mlx5i_find_qpn_to_netdev_node (ipriv->qpn_htbl, qpn);if (!node)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 328/990 netlink: Do not call the unbind callback with the table locked
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anil Kaushik <[email protected]>
[ Upstream commit a36b9e205cb3c452ab96cc783e63465d466fe615 ]
When netlink_bind() fails to insert the socket, it calls netlink_undo_bind() with the table locked. genl_unbind() then takes cb_lock, while genl_unregister_family() and genl_register_family() take cb_lock for writing and then wait in netlink_table_grab() for the table users to go away:
netlink_bind() genl_unregister_family()
netlink_lock_table() down_write(&cb_lock)
netlink_insert() fails
netlink_undo_bind() netlink_table_grab()
genl_unbind() waits for nl_table_users == 0
down_read(&cb_lock)An unprivileged user can get here by binding to a port ID that is in use, with nl_groups set. Lockdep does not see it, as nl_table_users is a plain counter.
Unlock the table first, as the comment in netlink_release() asks for.
--- net/netlink/af_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netlink/af_netlink.c +2 -1
@@ -1032,8 +1032,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, netlink_insert(sk, nladdr->nl_pid) :netlink_autobind (sock);if (err) { +netlink_unlock_table ();netlink_undo_bind (BITS_PER_TYPE (u32), groups, sk); - goto unlock; +return err; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 329/990 net/mlx5e: Add missing Ethernet multicast octets to vport_rx_bytes sum
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Or Har-Toov <[email protected]>
[ Upstream commit 9c1adbe7fa6cbc02c25db2039532918acf846400 ]
mlx5e_rep_update_hw_counters() adds transmitted_eth_multicast.packets to vport_rx_packets but does not add transmitted_eth_multicast.octets to vport_rx_bytes. As a result, Ethernet multicast sent by a VF/SF is counted in its representor's rx_packets but not in rx_bytes.
Fix by adding transmitted_eth_multicast.octets to the vport_rx_bytes sum.
--- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -0
@@ -239,6 +239,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vport_rep)MLX5_GET_CTR (out, transmitted_ib_unicast.octets) +MLX5_GET_CTR (out, transmitted_eth_unicast.octets) +MLX5_GET_CTR (out, transmitted_ib_multicast.octets) + +MLX5_GET_CTR (out, transmitted_eth_multicast.octets) +MLX5_GET_CTR (out, transmitted_eth_broadcast.octets); rep_stats->vport_tx_bytes =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 330/990 calipso: do not charge request socket options to the listener
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit b4a2cc6d748d3056a25812dcf5f5377a59afd02f ]
calipso_req_setattr() and calipso_req_delattr() allocate ireq->ipv6_opt with ipv6_renew_options(), which charges the listener sk_omem_alloc through sock_kmalloc().
tcp_v6_reqsk_destructor() frees ireq->ipv6_opt without uncharging it, so each request socket leaks its options size from the listener budget. Once sysctl_optmem_max is reached, sock_kmalloc() fails, calipso_req_setattr() returns -ENOBUFS, and tcp_v6_route_req() drops all subsequent SYN packets. __sk_destruct() also reports an optmem leakage when the listener is destroyed.
Uncharging in tcp_v6_reqsk_destructor() would not be correct: after a migration, req->rsk_listener is no longer the socket that was charged.
These options belong to the request socket, there is no reason to charge them to the listener. Change ipv6_renew_options() to use kmalloc() when its sk argument is NULL, and use this from calipso_req_setattr() and calipso_req_delattr(),
like cipso_v4_req_setattr() which uses kzalloc().
Note:
After this patch, calipso_req_setattr() and calipso_req_delattr() no longer need the listener. Commit 10876da918fa ("calipso: Fix null-ptr-deref in calipso_req_{set,del}attr().") could be reverted in net-next (also removing the then unused sk variables), so that CALIPSO works with SYN cookies.
--- net/ipv6/calipso.c | 12 ++++-------- net/ipv6/exthdrs.c | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-)
net/ipv6/calipso.c +4 -8
@@ -1220,7 +1220,7 @@ static int calipso_req_setattr(struct request_sock *req,if (IS_ERR (new))return PTR_ERR (new); - txopts =ipv6_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new); + txopts =ipv6_renew_options (NULL , req_inet->ipv6_opt,IPV6_HOPOPTS , new);kfree (new);
@@ -1228,10 +1228,8 @@ static int calipso_req_setattr(struct request_sock *req,return PTR_ERR (txopts); txopts =xchg (&req_inet->ipv6_opt, txopts); -if (txopts) { -atomic_sub (txopts->tot_len, &sk->sk_omem_alloc); +if (txopts)txopt_put (txopts); - }return 0 ; }
@@ -1261,14 +1259,12 @@ static void calipso_req_delattr(struct request_sock *req)if (calipso_opt_del (req_inet->ipv6_opt->hopopt, &new))return ;/* Nothing to do */ - txopts =ipv6_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new); + txopts =ipv6_renew_options (NULL , req_inet->ipv6_opt,IPV6_HOPOPTS , new);if (!IS_ERR (txopts)) { txopts =xchg (&req_inet->ipv6_opt, txopts); -if (txopts) { -atomic_sub (txopts->tot_len, &sk->sk_omem_alloc); +if (txopts)txopt_put (txopts); - } }kfree (new); }
net/ipv6/exthdrs.c +3 -2
@@ -1284,7 +1284,7 @@ static void ipv6_renew_option(int renewtype,* not copied into the new set of options. * * The new set of options is allocated from the socket option memory -* buffer of @sk. +* buffer of @sk, or with kmalloc() if @sk is NULL. */ struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
@@ -1312,7 +1312,8 @@ ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,return NULL ; tot_len +=sizeof (*opt2); - opt2 =sock_kmalloc (sk, tot_len,GFP_ATOMIC ); + opt2 = sk ?sock_kmalloc (sk, tot_len,GFP_ATOMIC ) : +kmalloc (tot_len,GFP_ATOMIC );if (!opt2)return ERR_PTR (-ENOBUFS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 331/990 ipv6: Check the Home Address option again before its address is used
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 30c71476d842b094651bd7712f6c8ee8716147d0 ]
ipv6_dest_hao() checks the Home Address option and sets IP6CB(skb)->dsthao to the offset of the destination options header. Later mip6_addr_swap() and mip6_destopt_reject() call ipv6_find_tlv() with that offset and use the 16 address bytes. They assume that the same header is still there.
But the seg6 and ioam6 lwtunnels, the End.B6 actions, ipv6_rpl_srh_rcv() and BPF lwt progs move or rewrite the IPv6 headers and keep IP6CB(skb). Then ipv6_find_tlv() parses other bytes. It returns when the type matches, before it checks that the option is inside the header. Nobody checks the length of the option again. Thus mip6_addr_swap() can write after the data of the skb. mip6_destopt_reject() can copy that memory to an xfrm report.
In ipv6_find_tlv(), check the length of an option before its type. The returned option is then inside the header, and the header is inside the linear data. In both callers, ignore an option with a length other than 16, as if ipv6_find_tlv() found none. Then the ICMPv6 error goes to the source address of the IPv6 header, and the xfrm report has no XFRMA_COADDR attribute. Nothing changes for a header that ip6_parse_tlv() accepted and that is still in its place. For the other callers an incomplete option is now absent:
- ip6_find_1stfragopt() and mip6_rthdr_offset() can return another offset for the fragment header or the xfrm header, also in a forwarded packet.
- calipso_skbuff_optptr() returns NULL. netlbl_skbuff_getattr() and netlbl_cache_add() then see no option. calipso_skbuff_delattr() returns 0 and the packet continues unchanged. Today it returns -EINVAL and SELinux drops the packet. It already returns 0 when an earlier option is incomplete. The receiver drops such a header in ip6_parse_tlv().
The code that moves the headers still does not reset the offset or the other fields of IP6CB(skb). If the bytes there look like a header with a Home Address option of length 16, both callers still use its address.
The first tag also covers ipv6_find_tlv(), because its early return did no harm before mip6_addr_swap(). The second tag is for mip6_destopt_reject().
--- net/ipv6/exthdrs_core.c | 7 ++++--- net/ipv6/icmp.c | 7 ++++++- net/ipv6/mip6.c | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-)
net/ipv6/exthdrs_core.c +4 -3
@@ -138,9 +138,6 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type)int opttype = nh[offset];int optlen; -if (opttype == type) -return offset; -switch (opttype) {case IPV6_TLV_PAD1 : optlen =1 ;
@@ -153,6 +150,10 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type) goto bad;break ; } +/* Some callers read the option, so it must be in the header. */ +if (opttype == type) +return offset; + offset += optlen; len -= optlen; }
net/ipv6/icmp.c +6 -1
@@ -339,7 +339,12 @@ static void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *optif (likely (off >=0 )) { hao = (struct ipv6_destopt_hao *) (skb_network_header (skb) + off); -swap (iph->saddr, hao->addr); +/* +* The header can have moved or changed after +* ipv6_dest_hao() checked the length. +*/ +if (hao->length ==16 ) +swap (iph->saddr, hao->addr); } } }
net/ipv6/mip6.c +8 -1
@@ -211,9 +211,16 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb,if (likely (opt->dsthao)) { offset =ipv6_find_tlv (skb, opt->dsthao,IPV6_TLV_HAO ); -if (likely (offset >=0 )) +if (likely (offset >=0 )) { hao = (struct ipv6_destopt_hao *) (skb_network_header (skb) + offset); +/* +* The header can have moved or changed after +* ipv6_dest_hao() checked the length. +*/ +if (hao->length !=16 ) + hao =NULL ; + } } stamp =skb_get_ktime (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 332/990 ata: libata-scsi: fix MODE SELECT handling of data after the mode page
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 6fde0444d07ec954f3d885375e0402ff2f2e5064 ]
ata_scsi_mode_select_xlat() only supports one mode page per MODE SELECT command, and rejects a parameter list with data after the mode page with INVALID FIELD IN PARAMETER LIST. However:
- It does not set the field pointer, so the sense data reports 0xffff as the FIELD POINTER.
- It only checks for data after the mode page after the mode page handler has been called. ata_mselect_control_ata_feature() has then already updated the CDL enabled flag of the device, even though the command is rejected and the CDL setting of the device is not changed.
- For the control mode page, ata_mselect_control_spg0() does not need an ATA command, so the check is skipped, and the data after the mode page is silently ignored.
Check for data after the mode page before calling the mode page handlers, and set the FIELD POINTER to the first byte after the mode page, i.e. to the first byte of the next mode page.
The reason why only one mode page per command is supported is that a MODE SELECT command is translated into at most one ATA command, so update the comment accordingly.
--- drivers/ata/libata-scsi.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/ata/libata-scsi.c +11 -7
@@ -4359,6 +4359,17 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)if (pg_len > len) goto invalid_param_len; +/* +* A MODE SELECT command is translated into at most one ATA command, so +* only one mode page per command is supported. Reject any data after +* the mode page before calling the mode page handlers, which may +* already update the device flags. +*/ +if (len > pg_len) { + fp = p - buffer + pg_len; + goto invalid_param; + } +switch (pg) {case CACHE_MPAGE :if (ata_mselect_caching (qc, p, pg_len, &fp) <0 ) {
@@ -4381,13 +4392,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param; } -/* -* Only one page has changeable data, so we only support setting one -* page at a time. -*/ -if (len > pg_len) - goto invalid_param; -return 0 ; invalid_fld:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 333/990 ata: libata-scsi: do not accept subpage code FFh in MODE SELECT
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit b29c40dc150b0b4218c4d6844770892eb6b2f6b5 ]
When the SUBPAGE CODE of the mode page in a MODE SELECT parameter list is FFh, ata_scsi_mode_select_xlat() rejects it for the control mode page, but accepts it for all other mode pages, i.e. for the caching mode page, the only other mode page that it supports.
However, FFh is not the subpage code of an actual mode page: SPC-7 (7.5.2) only defines it as the MODE SENSE request code for all subpages. SUBPAGE CODE FFh only means "all subpages" in requests, i.e. in the MODE SENSE CDB for mode pages and in the LOG SELECT CDB for log pages (see SPC-5, 6.8), while the SUBPAGE CODE of a mode page in a MODE SELECT parameter list identifies a specific mode page. Also, SAT-2 and later versions of SAT define the Caching mode page with the SPF bit set to zero (see SAT-6, 10.4.9), i.e. without a SUBPAGE CODE field.
Remove the ALL_SUB_MPAGES case, so that SUBPAGE CODE FFh is rejected like any other unsupported subpage.
--- drivers/ata/libata-scsi.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/ata/libata-scsi.c +2 -10
@@ -4332,19 +4332,11 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) }/* -* Supported subpages: all subpages and ATA feature sub-page f2h of -* the control page. +* The only supported subpage is the ATA feature sub-page f2h of the +* control page. */ if (spg) {switch (spg) { -case ALL_SUB_MPAGES : -/* All subpages is not supported for the control page */ -if (pg ==CONTROL_MPAGE ) { - fp = (p[0 ] &0x40 ) ?1 :0 ; - fp += hdr_len + bd_len; - goto invalid_param; - } -break ;case ATA_FEATURE_SUB_MPAGE :if (qc->dev->flags &ATA_DFLAG_CDL && pg ==CONTROL_MPAGE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 334/990 ata: libata-scsi: reject MODE SELECT mode pages with a wrong SPF bit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit a1eb72c477ec1320c540f27ce1e2f717d4518e62 ]
ata_scsi_mode_select_xlat() accepts the caching and control mode pages both in page_0 format and in sub_page format with SUBPAGE CODE 00h.
However, SAT-2 and later versions of SAT define the SPF bit of the Caching mode page and of the Control mode page as not changeable and set to zero (see SAT-6, 10.4.9 and 10.4.6), and SPC-7 (6.12, MODE SELECT(10) command) requires the device server to terminate a MODE SELECT command with INVALID FIELD IN PARAMETER LIST if the application client sets any field that is reported as not changeable to a value other than its current value.
Reject a mode page with the SPF bit set to one and SUBPAGE CODE 00h, with the FIELD POINTER set to the byte containing the SPF bit. The only mode page with the SPF bit set to one that remains accepted is the ATA Feature Control mode page (control mode page, sub-page f2h), for which SAT-6 (12.3.4) requires the SPF bit to be set to one. The opposite case does not need a check: a mode page in page_0 format always has subpage code 00h, so it can never be the ATA Feature Control mode page.
This also allows the mode page handlers to rely on the format of their mode page, which a later patch will make use of.
--- drivers/ata/libata-scsi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/ata/libata-scsi.c +10 -0
@@ -4317,7 +4317,17 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)if (len <4 ) goto invalid_param_len; +/* +* Mode pages with subpage code 00h use the page_0 format: SAT +* defines the SPF bit of the Caching and Control mode pages, +* for subpage code 00h, as not changeable and set to zero. +*/ spg = p[1 ]; +if (!spg) { + fp = hdr_len + bd_len; + goto invalid_param; + } + pg_len =get_unaligned_be16 (&p[2 ]); p +=4 ; len -=4 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 335/990 ata: libata-scsi: fix MODE SELECT field pointer for unsupported subpages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 2a4c61cf94d48ec8560473d4fd5383583ce8809c ]
When the mode page of a MODE SELECT parameter list has an unsupported SUBPAGE CODE, ata_scsi_mode_select_xlat() sets the FIELD POINTER of the INVALID FIELD IN PARAMETER LIST sense data to the SUBPAGE CODE byte of the mode page header (byte 1 of the page) if the SPF bit is set, and to the PAGE CODE byte (byte 0 of the page) otherwise.
However, the SPF bit is tested on p[0] after p has already been advanced past the mode page header, so the test reads bit 6 of the first byte of the mode page data instead. If the parameter list ends with the mode page header, it even reads the byte that follows the parameter list in buffer, which is not initialized when no data beyond the parameter list was transferred.
The test is not needed anyway: spg can only be non-zero for a mode page in sub_page format, i.e. with the SPF bit set, and the field in error is the SUBPAGE CODE. Always set the FIELD POINTER to the SUBPAGE CODE byte, which follows the mode parameter header, the block descriptors and the PAGE CODE byte.
--- drivers/ata/libata-scsi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/ata/libata-scsi.c +1 -2
@@ -4353,8 +4353,7 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)break ; fallthrough;default : - fp = (p[0 ] &0x40 ) ?1 :0 ; - fp += hdr_len + bd_len; + fp = hdr_len + bd_len +1 ; goto invalid_param; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 336/990 ata: libata-scsi: fix MODE SELECT field pointer for block descriptor length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit a3e52dcf0fbaa1a103accef3e8861cdc250ee5d6 ]
ata_scsi_mode_select_xlat() only accepts MODE SELECT parameter lists without block descriptors or with a single 8 byte block descriptor. For any other BLOCK DESCRIPTOR LENGTH, it terminates the command with INVALID FIELD IN PARAMETER LIST, and the FIELD POINTER should point at the BLOCK DESCRIPTOR LENGTH field, i.e. at byte 3 of the mode parameter header(6) or at byte 6 of the mode parameter header(10), as SPC requires the FIELD POINTER of a multiple-byte field to point at its first byte.
However, the mode parameter header length and the BLOCK DESCRIPTOR LENGTH are added to the offset of the field, so the FIELD POINTER points 3 or 6 bytes after the end of the block descriptors instead. For example, a MODE SELECT(10) with a BLOCK DESCRIPTOR LENGTH of 16 reports byte 30 instead of byte 6.
Do not add the mode parameter header length and the BLOCK DESCRIPTOR LENGTH to the offset of the BLOCK DESCRIPTOR LENGTH field.
--- drivers/ata/libata-scsi.c | 1 - 1 file changed, 1 deletion(-)
drivers/ata/libata-scsi.c +0 -1
@@ -4302,7 +4302,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param_len;if (bd_len !=0 && bd_len !=8 ) { fp = (six_byte) ?3 :6 ; - fp += bd_len + hdr_len; goto invalid_param; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 337/990 ata: libata-scsi: pass the whole mode page to the MODE SELECT handlers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 0fdb8eef88a886751e33600d446a66c529384f11 ]
ata_scsi_mode_select_xlat() strips the mode page header before calling the mode page handlers, which report the position of an invalid field as an offset relative to the mode page data. It then converts this offset into an offset in the parameter list by adding the length of the mode parameter header and of the block descriptors, but not the length of the mode page header. As a result, the FIELD POINTER of the INVALID FIELD IN PARAMETER LIST sense data points 2 bytes (page_0 format) or 4 bytes (sub_page format) before the byte that is actually invalid. For example, changing byte 3 of the caching mode page in a MODE SELECT(10) parameter list without block descriptors reports byte 9 instead of byte 11.
Pass the whole mode page, starting with its mode page header, to the handlers instead, like the ata_msense_*() functions, which generate the whole mode page. Offsets in buf are then the byte numbers of the mode page, as used in the mode page definitions of SPC, SBC and SAT, the handlers can compare buf with the mode page generated by the matching ata_msense_*() function without adjusting offsets, and the conversion done by ata_scsi_mode_select_xlat() becomes correct. This also allows reporting an invalid PAGE LENGTH at the PAGE LENGTH field, which was not part of buf before. As ata_scsi_mode_select_xlat() rejects SUBPAGE CODE FFh and mode pages with a wrong SPF bit, each handler only gets its mode page in a single format, so the mode page header length is known.
Document what buf, len and fp are, and the return values, in kernel-doc comments for all the handlers.
--- drivers/ata/libata-scsi.c | 133 +++++++++++++++++++++++--------------- 1 file changed, 82 insertions(+), 51 deletions(-)
drivers/ata/libata-scsi.c +82 -51
@@ -4055,14 +4055,22 @@ static unsigned int ata_scsi_zbc_out_xlat(struct ata_queued_cmd *qc)/** * ata_mselect_caching - Simulate MODE SELECT for caching info page * @qc: Storage for translated ATA taskfile -* @buf: input buffer -* @len: number of valid bytes in the input buffer -* @fp: out parameter for the failed field on error +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error * * Prepare a taskfile to modify caching information for the device. * +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. +* * LOCKING: * None. +* +* RETURNS: +* 0 if a taskfile was prepared, -EINVAL if the mode page is invalid. */ static int ata_mselect_caching (struct ata_queued_cmd *qc,const u8 *buf,int len,u16 *fp)
@@ -4073,26 +4081,19 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,u8 wce;int i; -/* -* The first two bytes of def_cache_mpage are a header, so offsets -* in mpage are off by 2 compared to buf. Same for len. -*/ - -if (len !=CACHE_MPAGE_LEN -2 ) { - *fp =min (len,CACHE_MPAGE_LEN -2 ); +if (len !=CACHE_MPAGE_LEN ) { + *fp =1 ;return -EINVAL ; } - wce = buf[0 ] & (1 <<2 ); + wce = buf[2 ] & (1 <<2 );/* * Check that read-only bits are not modified. */ ata_msense_caching (dev->id, mpage, false); -for (i =0 ; i <CACHE_MPAGE_LEN -2 ; i++) { -if (i ==0 ) -continue ; -if (mpage[i +2 ] != buf[i]) { +for (i =3 ; i <CACHE_MPAGE_LEN ; i++) { +if (mpage[i] != buf[i]) { *fp = i;return -EINVAL ; }
@@ -4106,8 +4107,26 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,return 0 ; } -/* -* Simulate MODE SELECT control mode page, sub-page 0. +/** +* ata_mselect_control_spg0 - Simulate MODE SELECT for control sub-page 0 +* @qc: Storage for translated ATA taskfile +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error +* +* Simulate MODE SELECT control mode page, sub-page 0. +* +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. +* +* LOCKING: +* None. +* +* RETURNS: +* 0, as no ATA command needs to be sent, or -EINVAL if the mode page is +* invalid. */ static int ata_mselect_control_spg0 (struct ata_queued_cmd *qc,const u8 *buf,int len,u16 *fp)
@@ -4117,26 +4136,19 @@ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc,u8 d_sense;int i; -/* -* The first two bytes of def_control_mpage are a header, so offsets -* in mpage are off by 2 compared to buf. Same for len. -*/ - -if (len !=CONTROL_MPAGE_LEN -2 ) { - *fp =min (len,CONTROL_MPAGE_LEN -2 ); +if (len !=CONTROL_MPAGE_LEN ) { + *fp =1 ;return -EINVAL ; } - d_sense = buf[0 ] & (1 <<2 ); + d_sense = buf[2 ] & (1 <<2 );/* * Check that read-only bits are not modified. */ ata_msense_control_spg0 (dev, mpage, false); -for (i =0 ; i <CONTROL_MPAGE_LEN -2 ; i++) { -if (i ==0 ) -continue ; -if (mpage[2 + i] != buf[i]) { +for (i =3 ; i <CONTROL_MPAGE_LEN ; i++) { +if (mpage[i] != buf[i]) { *fp = i;return -EINVAL ; }
@@ -4148,9 +4160,27 @@ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc,return 0 ; } -/* -* Translate MODE SELECT control mode page, sub-page f2h (ATA feature mode -* page) into a SET FEATURES command. +/** +* ata_mselect_control_ata_feature - Translate ATA Feature Control page +* @qc: Storage for translated ATA taskfile +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error +* +* Translate MODE SELECT control mode page, sub-page f2h (ATA feature mode +* page) into a SET FEATURES command. +* +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. +* +* LOCKING: +* None. +* +* RETURNS: +* 1 if a taskfile was prepared, -EINVAL if the mode page is invalid or if +* CDL cannot be enabled. */ static int ata_mselect_control_ata_feature (struct ata_queued_cmd *qc,const u8 *buf,int len,u16 *fp)
@@ -4159,17 +4189,13 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,struct ata_taskfile *tf = &qc->tf;u8 cdl_action; -/* -* The first four bytes of ATA Feature Control mode page are a header, -* so offsets in mpage are off by 4 compared to buf. Same for len. -*/ -if (len !=ATA_FEATURE_SUB_MPAGE_LEN -4 ) { - *fp =min (len,ATA_FEATURE_SUB_MPAGE_LEN -4 ); +if (len !=ATA_FEATURE_SUB_MPAGE_LEN ) { + *fp =2 ;return -EINVAL ; }/* Check cdl_ctrl */ -switch (buf[0 ] &0x03 ) { +switch (buf[4 ] &0x03 ) {case 0 :/* Disable CDL */ ata_dev_dbg (dev,"Disabling CDL\n" );
@@ -4191,7 +4217,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, dev->flags |=ATA_DFLAG_CDL_ENABLED ;break ;default : - *fp =0 ; + *fp =4 ;return -EINVAL ; }
@@ -4207,15 +4233,24 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,/** * ata_mselect_control - Simulate MODE SELECT for control page * @qc: Storage for translated ATA taskfile -* @spg: target sub-page of the control page -* @buf: input buffer -* @len: number of valid bytes in the input buffer -* @fp: out parameter for the failed field on error +* @spg: Sub-page of the control page, 0 or ATA_FEATURE_SUB_MPAGE +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error * -* Prepare a taskfile to modify caching information for the device. +* Call the handler of sub-page @spg of the control mode page. +* +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. * * LOCKING: * None. +* +* RETURNS: +* 0 if no ATA command needs to be sent, 1 if a taskfile was prepared, +* -EINVAL if the mode page is invalid. */ static int ata_mselect_control (struct ata_queued_cmd *qc,u8 spg,const u8 *buf,int len,u16 *fp)
@@ -4327,17 +4362,13 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param; } - pg_len =get_unaligned_be16 (&p[2 ]); - p +=4 ; - len -=4 ; + pg_len =get_unaligned_be16 (&p[2 ]) +4 ; }else {if (len <2 ) goto invalid_param_len; spg =0 ; - pg_len = p[1 ]; - p +=2 ; - len -=2 ; + pg_len = p[1 ] +2 ; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 338/990 ata: libata-scsi: set the field pointer when rejecting CDL
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shao Mingyin <[email protected]>
[ Upstream commit 7c972e73641cbe5f77f63c336de15c7a30268d49 ]
ata_mselect_control_ata_feature() rejects enabling CDL while NCQ priority is enabled, but unlike its other error branches it returns without setting *fp.
ata_scsi_mode_select_xlat() initializes fp to 0xffff and, when the handler fails, adds the offset of the mode page in the parameter list to it, i.e. the length of the mode parameter header and of the block descriptors. As fp is a u16, this wraps around, so the resulting sense data reports the byte before the mode page, i.e. the last byte of the mode parameter header or of the block descriptors, as the FIELD POINTER, instead of the byte containing the CDL_CTRL field that requests enabling CDL.
Set *fp to 4, i.e. to the byte containing the CDL_CTRL field, like the branch rejecting an invalid CDL_CTRL value does.
--- drivers/ata/libata-scsi.c | 1 + 1 file changed, 1 insertion(+)
drivers/ata/libata-scsi.c +1 -0
@@ -4210,6 +4210,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,if (dev->flags &ATA_DFLAG_NCQ_PRIO_ENABLED ) {ata_dev_err (dev,"NCQ priority must be disabled to enable CDL\n" ); + *fp =4 ;return -EINVAL ; }ata_dev_dbg (dev,"Enabling CDL\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 339/990 tracing/probes: bound symstr stores to reserved length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifan Zhang <[email protected]>
[ Upstream commit 2fc0b3070d6d5dcecfed43cd0e62aa0fd4b4315c ]
Traceprobe calculates dynamic string sizes before storing the values. A probed pointer can change between those passes, so fetch_store_symstrlen() can reserve space for a short symbol while fetch_store_symstring() observes a longer one. The store path then overwrites the trace record.
Format the symbol into a temporary KSYM_SYMBOL_LEN buffer and copy only the bytes that fit in the reserved field, including a trailing NUL. Update __data_loc with the length actually stored so consumers do not read beyond the truncated value.
--- kernel/trace/trace_probe_tmpl.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/trace/trace_probe_tmpl.h +13 -1
@@ -87,15 +87,27 @@ fetch_store_symstrlen(unsigned long addr) static nokprobe_inline intfetch_store_symstring (unsigned long addr,void *dest,void *base) { +char namebuf[KSYM_SYMBOL_LEN ];int maxlen =get_loc_len (*(u32 *)dest);void *__dest; +int len;if (unlikely (!maxlen))return -ENOMEM ; __dest =get_loc_data (dest, base); + len =sprint_symbol (namebuf, addr); +if (len <0 ) { + *(u32 *)dest =make_data_loc (0 , __dest - base); +return 0 ; + } + + len =min (len, maxlen -1 ); +memcpy (__dest, namebuf, len); + ((char *)__dest)[len] ='\0' ; + *(u32 *)dest =make_data_loc (len +1 , __dest - base); -return sprint_symbol (__dest, addr); +return len +1 ; }/* common part of process_fetch_insn*/
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 340/990 liveupdate: kho: move to kernel/liveupdate
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pasha Tatashin <[email protected]>
[ Upstream commit 48a1b2321d763b5edeaf20bd4576d8c4b5df772b ]
Move KHO to kernel/liveupdate/ in preparation of placing all Live Update core kernel related files to the same place.
Stable-dep-of: 58c5852ca96c ("kho: check fdt_phys in is_kho_boot()")
---
Documentation/core-api/kho/concepts.rst | 2 +-
MAINTAINERS | 2 +-
init/Kconfig | 2 +
kernel/Kconfig.kexec | 34 ----------------
kernel/Makefile | 4 +-
kernel/liveupdate/Kconfig | 40 +++++++++++++++++++
kernel/liveupdate/Makefile | 5 +++
kernel/{ => liveupdate}/kexec_handover.c | 4 +-
.../{ => liveupdate}/kexec_handover_debug.c | 0
.../{ => liveupdate}/kexec_handover_debugfs.c | 0
.../kexec_handover_internal.h | 0
11 files changed, 52 insertions(+), 41 deletions(-)
create mode 100644 kernel/liveupdate/Kconfig
create mode 100644 kernel/liveupdate/Makefile
rename kernel/{ => liveupdate}/kexec_handover.c (99%)
rename kernel/{ => liveupdate}/kexec_handover_debug.c (100%)
rename kernel/{ => liveupdate}/kexec_handover_debugfs.c (100%)
rename kernel/{ => liveupdate}/kexec_handover_internal.h (100%)Documentation/core-api/kho/concepts.rst +1 -1
@@ -70,5 +70,5 @@ in the FDT. That state is called the KHO finalization phase. Public API ========== -.. kernel-doc:: kernel/kexec_handover.c +.. kernel-doc:: kernel/liveupdate/kexec_handover.c :export:
MAINTAINERS +1 -1
@@ -13818,7 +13818,7 @@ S: Maintained F: Documentation/admin-guide/mm/kho.rst F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h -F: kernel/kexec_handover* +F: kernel/liveupdate/kexec_handover* F: lib/test_kho.c F: tools/testing/selftests/kho/
init/Kconfig +2 -0
@@ -2151,6 +2151,8 @@ config TRACEPOINTS source "kernel/Kconfig.kexec" +source "kernel/liveupdate/Kconfig" + endmenu # General setup source "arch/Kconfig"
kernel/Kconfig.kexec +0 -34
@@ -94,40 +94,6 @@ config KEXEC_JUMP Jump between original kernel and kexeced kernel and invoke code in physical address mode via KEXEC -config KEXEC_HANDOVER - bool "kexec handover" - depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE - depends on !DEFERRED_STRUCT_PAGE_INIT - select MEMBLOCK_KHO_SCRATCH - select KEXEC_FILE - select LIBFDT - select CMA - help - Allow kexec to hand over state across kernels by generating and - passing additional metadata to the target kernel. This is useful - to keep data or state alive across the kexec. For this to work, - both source and target kernels need to have this option enabled. - -config KEXEC_HANDOVER_DEBUG - bool "Enable Kexec Handover debug checks" - depends on KEXEC_HANDOVER - help - This option enables extra sanity checks for the Kexec Handover - subsystem. Since, KHO performance is crucial in live update - scenarios and the extra code might be adding overhead it is - only optionally enabled. - -config KEXEC_HANDOVER_DEBUGFS - bool "kexec handover debugfs interface" - default KEXEC_HANDOVER - depends on KEXEC_HANDOVER - select DEBUG_FS - help - Allow to control kexec handover device tree via debugfs - interface, i.e. finalize the state or aborting the finalization. - Also, enables inspecting the KHO fdt trees with the debugfs binary - blobs. - config CRASH_DUMP bool "kernel crash dumps" default ARCH_DEFAULT_CRASH_DUMP
kernel/Makefile +1 -3
@@ -52,6 +52,7 @@ obj-y += printk/ obj-y += irq/ obj-y += rcu/ obj-y += livepatch/ +obj-y += liveupdate/ obj-y += dma/ obj-y += entry/ obj-y += unwind/
@@ -82,9 +83,6 @@ obj-$(CONFIG_CRASH_DUMP_KUNIT_TEST) += crash_core_test.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC_FILE) += kexec_file.o obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o -obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o -obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) += kexec_handover_debug.o -obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS) += kexec_handover_debugfs.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup/
kernel/liveupdate/Kconfig new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "Live Update and Kexec HandOver" + depends on !DEFERRED_STRUCT_PAGE_INIT + +config KEXEC_HANDOVER + bool "kexec handover" + depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE + depends on !DEFERRED_STRUCT_PAGE_INIT + select MEMBLOCK_KHO_SCRATCH + select KEXEC_FILE + select LIBFDT + select CMA + help + Allow kexec to hand over state across kernels by generating and + passing additional metadata to the target kernel. This is useful + to keep data or state alive across the kexec. For this to work, + both source and target kernels need to have this option enabled. + +config KEXEC_HANDOVER_DEBUG + bool "Enable Kexec Handover debug checks" + depends on KEXEC_HANDOVER + help + This option enables extra sanity checks for the Kexec Handover + subsystem. Since, KHO performance is crucial in live update + scenarios and the extra code might be adding overhead it is + only optionally enabled. + +config KEXEC_HANDOVER_DEBUGFS + bool "kexec handover debugfs interface" + default KEXEC_HANDOVER + depends on KEXEC_HANDOVER + select DEBUG_FS + help + Allow to control kexec handover device tree via debugfs + interface, i.e. finalize the state or aborting the finalization. + Also, enables inspecting the KHO fdt trees with the debugfs binary + blobs. + +endmenu
kernel/liveupdate/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) += kexec_handover_debug.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS) += kexec_handover_debugfs.o
kernel/liveupdate/kexec_handover.c renamed from kernel/kexec_handover.c +2 -2
@@ -28,8 +28,8 @@* KHO is tightly coupled with mm init and needs access to some of mm * internal APIs. */ -#include "../mm/internal.h" -#include "kexec_internal.h" +#include "../../mm/internal.h" +#include "../kexec_internal.h" #include "kexec_handover_internal.h" #define KHO_FDT_COMPATIBLE "kho-v1"
kernel/liveupdate/kexec_handover_debug.c renamed from kernel/kexec_handover_debug.c +0 -0
kernel/liveupdate/kexec_handover_debugfs.c renamed from kernel/kexec_handover_debugfs.c +0 -0
kernel/liveupdate/kexec_handover_internal.h renamed from kernel/kexec_handover_internal.h +0 -0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 341/990 kho: check fdt_phys in is_kho_boot()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Thelen <[email protected]>
[ Upstream commit 58c5852ca96c58cdfdb9646870b217fc54d06a97 ]
is_kho_boot() is called early in boot before the linear memory map is initialized, so calling phys_to_virt() via kho_get_fdt() there is invalid.
On arm64 (and similarly in upcoming riscv64 support), this triggers BUG_ONs in debug builds, such as:
kernel BUG at ./arch/arm64/include/asm/memory.h:377!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP Call trace: is_kho_boot+0x2c/0x38 (P) efi_init+0x94/0xf8 setup_arch+0xf0/0x240 start_kernel+0x84/0x490 __primary_switched+0x88/0x98
Use kho_in.fdt_phys in is_kho_boot() directly instead of translating it to a virtual address.
--- kernel/liveupdate/kexec_handover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/liveupdate/kexec_handover.c +1 -1
@@ -1204,7 +1204,7 @@ static const void *kho_get_fdt(void)*/ bool is_kho_boot (void ) { -return !!kho_get_fdt (); +return !!kho_in.fdt_phys; }EXPORT_SYMBOL_GPL (is_kho_boot);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 342/990 drm/xe: Prevent VF memory IRQ from accessing a torn-down engine
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Satyanarayana K V P <[email protected]>
[ Upstream commit db58638d5d0531beafafa498cffa516779876ee5 ]
The VF memory IRQ handler iterates over HW engines whose names are set. Engine teardown clears hwe->gt but leaves hwe->name set, so the handler can select an engine whose GT has already been invalidated. This can cause a NULL pointer dereference in xe_hw_engine_handle_irq().
Invalidate the engine name during teardown so subsequent engine scans skip it.
--- drivers/gpu/drm/xe/xe_hw_engine.c | 17 ++++++++++++++--- drivers/gpu/drm/xe/xe_irq.c | 3 +++ drivers/gpu/drm/xe/xe_memirq.c | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_hw_engine.c +14 -3
@@ -276,11 +276,22 @@ static const struct engine_info engine_infos[] = {static void hw_engine_fini (void *arg) {struct xe_hw_engine *hwe = arg; +struct xe_gt *gt = hwe->gt; + +if (gt) { +struct xe_device *xe =gt_to_xe (gt); +unsigned long flags; -if (hwe->exl_port) -xe_execlist_port_destroy (hwe->exl_port); +if (hwe->exl_port) +xe_execlist_port_destroy (hwe->exl_port); - hwe->gt =NULL ; +spin_lock_irqsave (&xe->irq.lock, flags); + hwe->name =NULL ; + hwe->gt =NULL ; +spin_unlock_irqrestore (&xe->irq.lock, flags); + }else { + hwe->name =NULL ; + } }/**
drivers/gpu/drm/xe/xe_irq.c +3 -0
@@ -855,6 +855,7 @@ static irqreturn_t xe_irq_msix_default_hwe_handler(int irq, void *arg)struct xe_hw_engine *hwe;enum xe_hw_engine_id id;struct xe_tile *tile; +unsigned long flags;struct xe_gt *gt;if (!atomic_read (&xe->irq.enabled))
@@ -869,8 +870,10 @@ static irqreturn_t xe_irq_msix_default_hwe_handler(int irq, void *arg)if (gt->tile != tile)continue ; +spin_lock_irqsave (&xe->irq.lock, flags);for_each_hw_engine (hwe, gt, id)xe_memirq_hwe_handler (memirq, hwe); +spin_unlock_irqrestore (&xe->irq.lock, flags); } }
drivers/gpu/drm/xe/xe_memirq.c +3 -0
@@ -473,6 +473,7 @@ void xe_memirq_handler(struct xe_memirq *memirq)struct xe_hw_engine *hwe;enum xe_hw_engine_id id;struct iosys_map map; +unsigned long flags;unsigned int gtid;struct xe_gt *gt;
@@ -487,8 +488,10 @@ void xe_memirq_handler(struct xe_memirq *memirq)if (gt->tile != tile)continue ; +spin_lock_irqsave (&xe->irq.lock, flags);for_each_hw_engine (hwe, gt, id)xe_memirq_hwe_handler (memirq, hwe); +spin_unlock_irqrestore (&xe->irq.lock, flags); }/* GuC and media GuC (if present) must be checked separately */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 343/990 drm/xe/tuning: Restrict Anyhit NULL-query tuning to render engines
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nitin Gote <[email protected]>
[ Upstream commit ddef200c67d445f978f323d947c8993570ae4756 ]
The "Disable NULL query for Anyhit Shader" tuning uses xe_rtp_match_first_render_or_compute to program RT_CTRL once per GT. On a GT with no render (RCS) engine, that match falls back to a compute (CCS) engine instead, so the tuning is still written even though RT_CTRL's ray-tracing logic has no hardware behind it there.
A CRI compute-only GT hits exactly this path, causing igt@xe_debugfs@check-gt-reg-sr to report a save-restore mismatch:
Mismatch on 0xe530, expected 0x400 got 0x0
Restrict the rule to ENGINE_CLASS(RENDER) so it only applies where ray-tracing hardware is actually present. Every other in-tree platform in this version range (BMG, LNL, PTL, NVL) always has a render engine, which xe_rtp_match_first_render_or_compute already resolves ahead of any compute engine, so this is a no-op for them.
--- drivers/gpu/drm/xe/xe_tuning.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_tuning.c +1 -1
@@ -100,7 +100,7 @@ static const struct xe_rtp_entry_sr engine_tunings[] = { }, {XE_RTP_NAME ("Tuning: Disable NULL query for Anyhit Shader" ),XE_RTP_RULES (GRAPHICS_VERSION_RANGE (2000 ,XE_RTP_END_VERSION_UNDEFINED ), -FUNC (xe_rtp_match_first_render_or_compute)), +ENGINE_CLASS (RENDER )),XE_RTP_ACTIONS (SET (RT_CTRL ,DIS_NULL_QUERY )) }, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 344/990 drm/xe/lrc: Restore CTX_CS_INDIRECT_CTX_OFFSET programming for pre-Xe2
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helen Koike <[email protected]>
[ Upstream commit badac1974e098dba1a0a7f413e53f5b6ae24ab10 ]
CTX_CS_INDIRECT_CTX_OFFSET default value is not retrieved from the GPU by inhibit+context save mechanism since it is not part of the Engine Context. Thus, at restore, 0x0 is programmed back to the GPU, which is an invalid value according to the PRM.
This causes sporadic hangs on Alder Lake when executing test IntelAngleEnd2EndTestCases (error VK_DEVICE_LOST).
Fix it by partially reverting commit c9dfd66cb91e ("drm/xe/lrc: Allow INDIRECT_CTX for more engine classes"). Re-add the programming of CTX_CS_INDIRECT_CTX_OFFSET for pre-Xe2 (in theory it should apply to all platforms, but we got an unexpected behaviour on Xe2 that still requires investigation).
--- drivers/gpu/drm/xe/regs/xe_lrc_layout.h | 3 +++ drivers/gpu/drm/xe/xe_lrc.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/regs/xe_lrc_layout.h +3 -0
@@ -40,4 +40,7 @@#define INDIRECT_CTX_RING_START_UDW (0x08 + 1)#define INDIRECT_CTX_RING_CTL (0x0a + 1) +#define CTX_INDIRECT_CTX_OFFSET_MASK REG_GENMASK(15, 6) +#define CTX_INDIRECT_CTX_OFFSET_DEFAULT REG_FIELD_PREP(CTX_INDIRECT_CTX_OFFSET_MASK, 0xd) +#endif
drivers/gpu/drm/xe/xe_lrc.c +4 -4
@@ -1371,15 +1371,15 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe)finish_bo (&state);kfree (state.buffer); -/* -* Enable INDIRECT_CTX leaving INDIRECT_CTX_OFFSET at its default: it -* varies per engine class, but the default is good enough -*/ xe_lrc_write_ctx_reg (lrc,CTX_CS_INDIRECT_CTX , (xe_bo_ggtt_addr (lrc->bo) + state.offset) |/* Size in CLs. */ (state.written *sizeof (u32) /64 )); +if (GRAPHICS_VER (lrc_to_xe (lrc)) <20 ) +xe_lrc_write_ctx_reg (lrc, +CTX_CS_INDIRECT_CTX_OFFSET , +CTX_INDIRECT_CTX_OFFSET_DEFAULT );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 345/990 drm/xe: Fix build with DRM_XE=y and CONFIGFS_FS=m
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Vivi <[email protected]>
[ Upstream commit da475c094342b6d5c8bc020b19d6900130bed047 ]
When xe is built-in but configfs is a module, xe_configfs.o is not linked into xe, while IS_ENABLED(CONFIG_CONFIGFS_FS) in xe_configfs.h still exposes the real declarations, leading to undefined references.
Use IS_REACHABLE() so this case falls back to the stubs, the same as CONFIGFS_FS=n.
--- drivers/gpu/drm/xe/xe_configfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_configfs.h +1 -1
@@ -12,7 +12,7 @@struct pci_dev ; -#if IS_ENABLED (CONFIG_CONFIGFS_FS ) +#if IS_REACHABLE (CONFIG_CONFIGFS_FS )int xe_configfs_init (void );void xe_configfs_exit (void );void xe_configfs_check_device (struct pci_dev *pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 346/990 drm/xe/xe_survivability: Redesign survivability mode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Riana Tauro <[email protected]>
[ Upstream commit f4e9fc967afdb53b1203f894fb4b68451a7fe202 ]
Redesign survivability mode to have only one value per file.
1) Retain the survivability_mode sysfs to indicate the type
cat /sys/bus/pci/devices/0000\:03\:00.0/survivability_mode (Boot / Runtime)
2) Add survivability_info directory to expose boot breadcrumbs. Entries in survivability mode sysfs are only visible when boot breadcrumb registers are populated.
/sys/bus/pci/devices/0000:03:00.0/survivability_info ├── aux_info0 ├── aux_info1 ├── aux_info2 ├── aux_info3 ├── aux_info4 ├── capability_info ├── postcode_trace └── postcode_trace_overflow
Capability Info:
Provides data about boot status and has bits that indicate the support for the other breadcrumbs
Postcode Trace / Postcode Trace Overflow :
Each postcode is represented as an 8-bit value and represents a boot failure event. When a new failure event is logged by Pcode the existing postcodes are shifted left. These entries provide a history of 8 postcodes.
Auxiliary Info:
Some failures have additional debug information.
Stable-dep-of: a890a885b982 ("drm/xe/hw_error: Guard csc_hw_error_work() with runtime PM")
--- drivers/gpu/drm/xe/xe_survivability_mode.c | 222 +++++++++++------- .../gpu/drm/xe/xe_survivability_mode_types.h | 22 +- 2 files changed, 154 insertions(+), 90 deletions(-)
drivers/gpu/drm/xe/xe_survivability_mode.c +140 -82
@@ -19,8 +19,6 @@#include "xe_pcode_api.h" #include "xe_vsec.h" -#define MAX_SCRATCH_MMIO 8 -/** * DOC: Survivability Mode *
@@ -48,19 +46,38 @@* * Refer :ref:`xe_configfs` for more details on how to use configfs * -* Survivability mode is indicated by the below admin-only readable sysfs which provides additional -* debug information:: +* Survivability mode is indicated by the below admin-only readable sysfs entry. It +* provides information about the type of survivability mode (Boot/Runtime). +* +* .. code-block:: shell +* +* # cat /sys/bus/pci/devices/<device>/survivability_mode +* Boot +* +* +* Any additional debug information if present will be visible under the directory +* ``survivability_info``:: +* +* /sys/bus/pci/devices/<device>/survivability_info/ +* ├── aux_info0 +* ├── aux_info1 +* ├── aux_info2 +* ├── aux_info3 +* ├── aux_info4 +* ├── capability_info +* ├── fdo_mode +* ├── postcode_trace +* └── postcode_trace_overflow +* +* This directory has the following attributes * -* /sys/bus/pci/devices/<device>/survivability_mode +* - ``capability_info`` : Indicates Boot status and support for additional information * -* Capability Information: -* Provides boot status -* Postcode Information: -* Provides information about the failure -* Overflow Information -* Provides history of previous failures -* Auxiliary Information -* Certain failures may have information in addition to postcode information +* - ``postcode_trace``, ``postcode_trace_overflow`` : Each postcode is a 8bit value and +* represents a boot failure event. When a new failure event is logged by PCODE the +* existing postcodes are shifted left. These entries provide a history of 8 postcodes. +* +* - ``aux_info<n>`` : Some failures have additional debug information * * Runtime Survivability * =====================
@@ -68,60 +85,76 @@* Certain runtime firmware errors can cause the device to enter a wedged state * (:ref:`xe-device-wedging`) requiring a firmware flash to restore normal operation. * Runtime Survivability Mode indicates that a firmware flash is necessary to recover the device and -* is indicated by the presence of survivability mode sysfs:: +* is indicated by the presence of survivability mode sysfs. +* Survivability mode sysfs provides information about the type of survivability mode. * -* /sys/bus/pci/devices/<device>/survivability_mode +* .. code-block:: shell * -* Survivability mode sysfs provides information about the type of survivability mode. +* # cat /sys/bus/pci/devices/<device>/survivability_mode +* Runtime * * When such errors occur, userspace is notified with the drm device wedged uevent and runtime * survivability mode. User can then initiate a firmware flash using userspace tools like fwupd * to restore device to normal operation. */ +static const char *const reg_map[] = { + [CAPABILITY_INFO ] ="Capability Info" , + [POSTCODE_TRACE ] ="Postcode trace" , + [POSTCODE_TRACE_OVERFLOW ] ="Postcode trace overflow" , + [AUX_INFO0 ] ="Auxiliary Info 0" , + [AUX_INFO1 ] ="Auxiliary Info 1" , + [AUX_INFO2 ] ="Auxiliary Info 2" , + [AUX_INFO3 ] ="Auxiliary Info 3" , + [AUX_INFO4 ] ="Auxiliary Info 4" , +}; + +struct xe_survivability_attribute { +struct device_attribute attr; +u8 index; +}; + +static struct +xe_survivability_attribute *dev_attr_to_survivability_attr (struct device_attribute *attr) +{ + return container_of(attr, struct xe_survivability_attribute, attr); +} +static u32 aux_history_offset (u32 reg_value) {return REG_FIELD_GET (AUXINFO_HISTORY_OFFSET , reg_value); } -static void set_survivability_info (struct xe_mmio *mmio,struct xe_survivability_info *info, -int id,char *name) +static void set_survivability_info (struct xe_mmio *mmio,u32 *info,int id) { -strscpy (info[id].name, name,sizeof (info[id].name)); - info[id].reg =PCODE_SCRATCH (id).raw; - info[id].value =xe_mmio_read32 (mmio,PCODE_SCRATCH (id)); + info[id] =xe_mmio_read32 (mmio,PCODE_SCRATCH (id)); }static void populate_survivability_info (struct xe_device *xe) {struct xe_survivability *survivability = &xe->survivability; -struct xe_survivability_info *info = survivability->info; +u32 *info = survivability->info;struct xe_mmio *mmio;u32 id =0 , reg_value; -char name[NAME_MAX ];int index; mmio =xe_root_tile_mmio (xe); -set_survivability_info (mmio, info, id,"Capability Info" ); - reg_value = info[id].value; +set_survivability_info (mmio, info,CAPABILITY_INFO ); + reg_value = info[CAPABILITY_INFO ];if (reg_value &HISTORY_TRACKING ) { - id++; -set_survivability_info (mmio, info, id,"Postcode Info" ); +set_survivability_info (mmio, info,POSTCODE_TRACE ); -if (reg_value &OVERFLOW_SUPPORT ) { - id =REG_FIELD_GET (OVERFLOW_REG_OFFSET , reg_value); -set_survivability_info (mmio, info, id,"Overflow Info" ); - } +if (reg_value &OVERFLOW_SUPPORT ) +set_survivability_info (mmio, info,POSTCODE_TRACE_OVERFLOW ); }if (reg_value &AUXINFO_SUPPORT ) { id =REG_FIELD_GET (AUXINFO_REG_OFFSET , reg_value); -for (index =0 ; id && reg_value; index++, reg_value = info[id].value, - id =aux_history_offset (reg_value)) { -snprintf (name,NAME_MAX ,"Auxiliary Info %d" , index); -set_survivability_info (mmio, info, id, name); +for (index =0 ; id >=AUX_INFO0 && id <MAX_SCRATCH_REG ; index++) { +set_survivability_info (mmio, info, id); + id =aux_history_offset (info[id]); } } }
@@ -130,15 +163,14 @@ static void log_survivability_info(struct pci_dev *pdev) {struct xe_device *xe =pdev_to_xe_device (pdev);struct xe_survivability *survivability = &xe->survivability; -struct xe_survivability_info *info = survivability->info; +u32 *info = survivability->info;int id;dev_info (&pdev->dev,"Survivability Boot Status : Critical Failure (%d)\n" , survivability->boot_status); -for (id =0 ; id <MAX_SCRATCH_MMIO ; id++) { -if (info[id].reg) -dev_info (&pdev->dev,"%s: 0x%x - 0x%x\n" , info[id].name, - info[id].reg, info[id].value); +for (id =0 ; id <MAX_SCRATCH_REG ; id++) { +if (info[id]) +dev_info (&pdev->dev,"%s: 0x%x\n" , reg_map[id], info[id]); } }
@@ -156,25 +188,38 @@ static ssize_t survivability_mode_show(struct device *dev,struct pci_dev *pdev =to_pci_dev (dev);struct xe_device *xe =pdev_to_xe_device (pdev);struct xe_survivability *survivability = &xe->survivability; -struct xe_survivability_info *info = survivability->info; -int index =0 , count =0 ; - count +=sysfs_emit_at (buff, count,"Survivability mode type: %s\n" , - survivability->type ?"Runtime" :"Boot" ); +return sysfs_emit (buff,"%s\n" , survivability->type ?"Runtime" :"Boot" ); +} -if (!check_boot_failure (xe)) -return count; +static DEVICE_ATTR_ADMIN_RO (survivability_mode); -for (index =0 ; index <MAX_SCRATCH_MMIO ; index++) { -if (info[index].reg) - count +=sysfs_emit_at (buff, count,"%s: 0x%x - 0x%x\n" , info[index].name, - info[index].reg, info[index].value); - } +static ssize_t survivability_info_show (struct device *dev, +struct device_attribute *attr,char *buff) +{ +struct xe_survivability_attribute *sa =dev_attr_to_survivability_attr (attr); +struct pci_dev *pdev =to_pci_dev (dev); +struct xe_device *xe =pdev_to_xe_device (pdev); +struct xe_survivability *survivability = &xe->survivability; +u32 *info = survivability->info; -return count; +return sysfs_emit (buff,"0x%x\n" , info[sa->index]); } -static DEVICE_ATTR_ADMIN_RO (survivability_mode); +#define SURVIVABILITY_ATTR_RO (name, _index) \ + struct xe_survivability_attribute attr_##name = { \ + .attr = __ATTR(name, 0400, survivability_info_show, NULL), \ + .index = _index, \ + } + +SURVIVABILITY_ATTR_RO (capability_info,CAPABILITY_INFO ); +SURVIVABILITY_ATTR_RO (postcode_trace,POSTCODE_TRACE ); +SURVIVABILITY_ATTR_RO (postcode_trace_overflow,POSTCODE_TRACE_OVERFLOW ); +SURVIVABILITY_ATTR_RO (aux_info0,AUX_INFO0 ); +SURVIVABILITY_ATTR_RO (aux_info1,AUX_INFO1 ); +SURVIVABILITY_ATTR_RO (aux_info2,AUX_INFO2 ); +SURVIVABILITY_ATTR_RO (aux_info3,AUX_INFO3 ); +SURVIVABILITY_ATTR_RO (aux_info4,AUX_INFO4 );static void xe_survivability_mode_fini (void *arg) {
@@ -182,17 +227,48 @@ static void xe_survivability_mode_fini(void *arg)struct pci_dev *pdev =to_pci_dev (xe->drm.dev);struct device *dev = &pdev->dev; -sysfs_remove_file (&dev->kobj, &dev_attr_survivability_mode.attr); +device_remove_file (dev, &dev_attr_survivability_mode); } +static umode_t survivability_info_attrs_visible (struct kobject *kobj,struct attribute *attr, +int idx) +{ +struct xe_device *xe =kdev_to_xe_device (kobj_to_dev (kobj)); +struct xe_survivability *survivability = &xe->survivability; +u32 *info = survivability->info; + +if (info[idx]) +return 0400 ; + +return 0 ; +} + +/* Attributes are ordered according to enum scratch_reg */ +static struct attribute *survivability_info_attrs[] = { + &attr_capability_info.attr.attr, + &attr_postcode_trace.attr.attr, + &attr_postcode_trace_overflow.attr.attr, + &attr_aux_info0.attr.attr, + &attr_aux_info1.attr.attr, + &attr_aux_info2.attr.attr, + &attr_aux_info3.attr.attr, + &attr_aux_info4.attr.attr, +NULL , +}; + +static const struct attribute_group survivability_info_group = { + .name ="survivability_info" , + .attrs = survivability_info_attrs, + .is_visible = survivability_info_attrs_visible, +}; +static int create_survivability_sysfs (struct pci_dev *pdev) {struct device *dev = &pdev->dev;struct xe_device *xe =pdev_to_xe_device (pdev);int ret; -/* create survivability mode sysfs */ - ret =sysfs_create_file (&dev->kobj, &dev_attr_survivability_mode.attr); + ret =device_create_file (dev, &dev_attr_survivability_mode);if (ret) {dev_warn (dev,"Failed to create survivability sysfs files\n" );return ret;
@@ -203,6 +279,12 @@ static int create_survivability_sysfs(struct pci_dev *pdev)if (ret)return ret; +if (check_boot_failure (xe)) { + ret =devm_device_add_group (dev, &survivability_info_group); +if (ret) +return ret; + } +return 0 ; }
@@ -239,25 +321,6 @@ static int enable_boot_survivability_mode(struct pci_dev *pdev)return ret; } -static int init_survivability_mode (struct xe_device *xe) -{ -struct xe_survivability *survivability = &xe->survivability; -struct xe_survivability_info *info; - - survivability->size =MAX_SCRATCH_MMIO ; - - info =devm_kcalloc (xe->drm.dev, survivability->size,sizeof (*info), -GFP_KERNEL ); -if (!info) -return -ENOMEM ; - - survivability->info = info; - -populate_survivability_info (xe); - -return 0 ; -} -/** * xe_survivability_mode_is_boot_enabled- check if boot survivability mode is enabled * @xe: xe device instance
@@ -325,9 +388,7 @@ int xe_survivability_mode_runtime_enable(struct xe_device *xe)return -EINVAL ; } - ret =init_survivability_mode (xe); -if (ret) -return ret; +populate_survivability_info (xe); ret =create_survivability_sysfs (pdev);if (ret)
@@ -356,14 +417,11 @@ int xe_survivability_mode_boot_enable(struct xe_device *xe) {struct xe_survivability *survivability = &xe->survivability;struct pci_dev *pdev =to_pci_dev (xe->drm.dev); -int ret;if (!xe_survivability_mode_is_requested (xe))return 0 ; - ret =init_survivability_mode (xe); -if (ret) -return ret; +populate_survivability_info (xe);/* Log breadcrumbs but do not enter survivability mode for Critical boot errors */ if (survivability->boot_status ==CRITICAL_FAILURE ) {
drivers/gpu/drm/xe/xe_survivability_mode_types.h +14 -8
@@ -9,23 +9,29 @@#include <linux/limits.h> #include <linux/types.h> +enum scratch_reg { +CAPABILITY_INFO , +POSTCODE_TRACE , +POSTCODE_TRACE_OVERFLOW , +AUX_INFO0 , +AUX_INFO1 , +AUX_INFO2 , +AUX_INFO3 , +AUX_INFO4 , +MAX_SCRATCH_REG , +}; +enum xe_survivability_type {XE_SURVIVABILITY_TYPE_BOOT ,XE_SURVIVABILITY_TYPE_RUNTIME , }; -struct xe_survivability_info { -char name[NAME_MAX ]; -u32 reg; -u32 value; -}; -/** * struct xe_survivability: Contains survivability mode information */ struct xe_survivability { -/** @info: struct that holds survivability info from scratch registers */ -struct xe_survivability_info *info; +/** @info: survivability debug info */ +u32 info[MAX_SCRATCH_REG ];/** @size: number of scratch registers */ u32 size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 347/990 drm/xe/xe_survivability: Simplify runtime survivability error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mallesh Koujalagi <[email protected]>
[ Upstream commit 2b8c1d7fe0d521f9d264ef08c15760235e61c341 ]
xe_survivability_mode_runtime_enable() returns an int, but its caller csc_hw_error_work() ignores the return value and cannot take any meaningful recovery action on failure. The function logs errors via dev_err() and proceeds to declare the device wedged regardless of sysfs creation failure, making the return value redundant.
Change the return type to void and remove the unnecessary error handling in the caller.
v2:
- Return is not require after the sysfs creation fail. (Rodrigo/Riana)
- Change int to void return type. (Rodrigo)
- Remove extra message from csc_hw_error_work().
v3:
- Remove ret variable. (Raag)
v4:
- Drop ret variable from other part of code.
v5:
- Reframe as refactoring instead of bug fix. (Raag)
- Remove Fixes tag and update subject line.
Stable-dep-of: a890a885b982 ("drm/xe/hw_error: Guard csc_hw_error_work() with runtime PM")
--- drivers/gpu/drm/xe/xe_hw_error.c | 5 +---- drivers/gpu/drm/xe/xe_survivability_mode.c | 14 ++++---------- drivers/gpu/drm/xe/xe_survivability_mode.h | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-)
drivers/gpu/drm/xe/xe_hw_error.c +1 -4
@@ -55,11 +55,8 @@ static void csc_hw_error_work(struct work_struct *work) {struct xe_tile *tile =container_of (work,typeof (*tile), csc_hw_error_work);struct xe_device *xe =tile_to_xe (tile); -int ret; - ret =xe_survivability_mode_runtime_enable (xe); -if (ret) -drm_err (&xe->drm,"Failed to enable runtime survivability mode\n" ); +xe_survivability_mode_runtime_enable (xe); }static void csc_hw_error_handler (struct xe_tile *tile,const enum hardware_error hw_err)
drivers/gpu/drm/xe/xe_survivability_mode.c +4 -10
@@ -374,25 +374,21 @@ bool xe_survivability_mode_is_requested(struct xe_device *xe)* Runtime survivability mode is enabled when certain errors cause the device to be * in non-recoverable state. The device is declared wedged with the appropriate * recovery method and survivability mode sysfs exposed to userspace -* -* Return: 0 if runtime survivability mode is enabled, negative error code otherwise. */ -int xe_survivability_mode_runtime_enable (struct xe_device *xe) +void xe_survivability_mode_runtime_enable (struct xe_device *xe) {struct xe_survivability *survivability = &xe->survivability;struct pci_dev *pdev =to_pci_dev (xe->drm.dev); -int ret;if (!IS_DGFX (xe) ||IS_SRIOV_VF (xe) || xe->info.platform <XE_BATTLEMAGE ) {dev_err (&pdev->dev,"Runtime Survivability Mode not supported\n" ); -return -EINVAL ; +return ; }populate_survivability_info (xe); - ret =create_survivability_sysfs (pdev); -if (ret) -dev_err (&pdev->dev,"Failed to create survivability mode sysfs\n" ); +if (create_survivability_sysfs (pdev)) +dev_err (&pdev->dev,"Failed to create survivability sysfs\n" ); survivability->type =XE_SURVIVABILITY_TYPE_RUNTIME ;dev_err (&pdev->dev,"Runtime Survivability mode enabled\n" );
@@ -400,8 +396,6 @@ int xe_survivability_mode_runtime_enable(struct xe_device *xe)xe_device_set_wedged_method (xe,DRM_WEDGE_RECOVERY_VENDOR );xe_device_declare_wedged (xe);dev_err (&pdev->dev,"Firmware flash required, Please refer to the userspace documentation for more details!\n" ); - -return 0 ; }/**
drivers/gpu/drm/xe/xe_survivability_mode.h +1 -1
@@ -11,7 +11,7 @@struct xe_device ;int xe_survivability_mode_boot_enable (struct xe_device *xe); -int xe_survivability_mode_runtime_enable (struct xe_device *xe); +void xe_survivability_mode_runtime_enable (struct xe_device *xe);bool xe_survivability_mode_is_boot_enabled (struct xe_device *xe);bool xe_survivability_mode_is_requested (struct xe_device *xe);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 348/990 drm/xe/hw_error: Guard csc_hw_error_work() with runtime PM
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raag Jadav <[email protected]>
[ Upstream commit a890a885b982f73e6e984e828ffda06b5121c4b6 ]
xe_device_declare_wedged() callers are expected to hold a runtime PM reference. Fix it.
--- drivers/gpu/drm/xe/xe_hw_error.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/xe/xe_hw_error.c +2 -0
@@ -12,6 +12,7 @@#include "xe_device.h" #include "xe_hw_error.h" #include "xe_mmio.h" +#include "xe_pm.h" #include "xe_survivability_mode.h" #define HEC_UNCORR_FW_ERR_BITS 4
@@ -56,6 +57,7 @@ static void csc_hw_error_work(struct work_struct *work)struct xe_tile *tile =container_of (work,typeof (*tile), csc_hw_error_work);struct xe_device *xe =tile_to_xe (tile); +guard (xe_pm_runtime)(xe);xe_survivability_mode_runtime_enable (xe); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 349/990 drm/xe: Rebind BOs evicted before the first LR queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arvind Yadav <[email protected]>
[ Upstream commit b52dcc698250e08eabdc4554a6fdb4d6f909133f ]
A VM bind can evict BOs before the first LR exec queue is added. There is no preempt fence to trigger at that point.
When the queue is added later, its new preempt fence is not triggered. The exec IOCTL does not validate or rebind BOs in preempt fence mode, and the rebind worker skips that work because no preempt fence is waiting. The first exec can then use stale mappings.
Trigger the new preempt fence in xe_vm_add_compute_exec_queue() when the VM has evicted BOs or pending rebinds. This keeps the queue suspended until the rebind worker validates the BOs and restores their mappings.
--- drivers/gpu/drm/xe/xe_vm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_vm.c +8 -1
@@ -258,8 +258,15 @@ int xe_vm_add_compute_exec_queue(struct xe_vm *vm, struct xe_exec_queue *q)* Check to see if a preemption on VM is in flight or userptr * invalidation, if so trigger this preempt fence to sync state with * other preempt fences on the VM. +* +* Also trigger it if eviction or rebinding is pending. BOs evicted +* before the first exec queue was added had no preempt fence to +* trigger. Suspend this queue until the rebind worker restores +* the mappings. */ - wait =__xe_vm_userptr_needs_repin (vm) ||preempt_fences_waiting (vm); + wait =__xe_vm_userptr_needs_repin (vm) ||preempt_fences_waiting (vm) || + !list_empty (&vm->gpuvm.evict.list) || + !list_empty (&vm->rebind_list);if (wait)dma_fence_enable_sw_signaling (pfence);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 350/990 drm/xe: Toggle the D3Cold enable flag at runtime resume
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vinay Belgaumkar <[email protected]>
[ Upstream commit e42459b16cbf1cbcebfc1ab406140cca204fd831 ]
We enable this flag during runtime suspend, need to set it back to false early during resume to maintain consistency in pci driver's internal state. d3cold_toggle() updates the root port's ability to go into d3cold via the dev->no_d3cold flag. With this patch, we are ensuring this internal state remains consistent with that of the endpoint.
v2: Clarify the commit message (Matt Auld)
v3: Add fixes (Karthik Poosa)
--- drivers/gpu/drm/xe/xe_pci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/xe/xe_pci.c +3 -0
@@ -1057,6 +1057,9 @@ static int xe_pci_runtime_resume(struct device *dev)struct xe_device *xe =pdev_to_xe_device (pdev);int err; +if (xe->d3cold.allowed) +d3cold_toggle (pdev,D3COLD_DISABLE ); + err =pci_set_power_state (pdev,PCI_D0 );if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 351/990 drm/xe/xe_late_bind_fw: Fix firmware leak on missing manifest entry
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Badal Nilawar <[email protected]>
[ Upstream commit 74f1a6f03f2d46537f929a1b13f7dcd378437a4d ]
Release firmware when the "LTES" manifest entry is not found in the firmware header.
--- drivers/gpu/drm/xe/xe_late_bind_fw.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_late_bind_fw.c +8 -7
@@ -335,19 +335,19 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)if (fw->size >XE_LB_MAX_PAYLOAD_SIZE ) {drm_err (&xe->drm,"Firmware %s size %zu is larger than max pay load size %u\n" , lb_fw->blob_path, fw->size,XE_LB_MAX_PAYLOAD_SIZE ); -release_firmware (fw); -return -ENODATA ; + ret = -ENODATA ; + goto release_fw; } ret =parse_lb_layout (lb_fw, fw->data, fw->size,"LTES" );if (ret) -return ret; + goto release_fw; lb_fw->payload_size = fw->size; lb_fw->payload =drmm_kzalloc (&xe->drm, lb_fw->payload_size,GFP_KERNEL );if (!lb_fw->payload) { -release_firmware (fw); -return -ENOMEM ; + ret = -ENOMEM ; + goto release_fw; } drm_info(&xe->drm, "Using %s firmware from %s version %u.%u.%u.%u\n",
@@ -356,10 +356,11 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id) lb_fw->version.hotfix, lb_fw->version.build);memcpy ((void *)lb_fw->payload, fw->data, lb_fw->payload_size); -release_firmware (fw);INIT_WORK (&lb_fw->work, xe_late_bind_work); -return 0 ; +release_fw: +release_firmware (fw); +return ret; }static int xe_late_bind_fw_init (struct xe_late_bind *late_bind)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 352/990 gpiolib: fix GPIO descriptor leak in gpiod_get_array()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit b2a161687acdc297aa91fec7fa0966b5aecf0d16 ]
In gpiod_get_array(), descs->ndescs is used as the loop induction variable and is only incremented at the end of each iteration. When krealloc() fails on the first iteration (when index is 0), descs->desc[0] has already been acquired via gpiod_get_index(), but descs->ndescs is still 0. Consequently, gpiod_put_array() frees descs without releasing descs->desc[0], leaking the descriptor.
Fix this by using a dedicated loop induction variable and incrementing descs->ndescs immediately upon storing the retrieved descriptor. Additionally, since the fast-path array_info setup only executes for the first element (index 0), simplify the bitmap_set() calls to start at bit 0 for count bits instead of calculating offsets from the loop index.
--- drivers/gpio/gpiolib.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/gpio/gpiolib.c +14 -20
@@ -5042,21 +5042,21 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,if (!descs)return ERR_PTR (-ENOMEM ); -for (descs->ndescs =0 ; descs->ndescs < count; descs->ndescs++) { - desc =gpiod_get_index (dev, con_id, descs->ndescs, flags); +for (int i =0 ; i < count; i++) { + desc =gpiod_get_index (dev, con_id, i, flags);if (IS_ERR (desc)) {gpiod_put_array (descs);return ERR_CAST (desc); } - descs->desc[descs->ndescs] = desc; + descs->desc[descs->ndescs++] = desc; gdev =gpiod_to_gpio_device (desc);/* * If pin hardware number of array member 0 is also 0, select * its chip as a candidate for fast bitmap processing path. */ -if (descs->ndescs ==0 &&gpiod_hwgpio (desc) ==0 ) { +if (i ==0 &&gpiod_hwgpio (desc) ==0 ) {struct gpio_descs *array; bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ?
@@ -5081,10 +5081,8 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, array_info->desc = descs->desc; array_info->size = count; array_info->gdev = gdev; -bitmap_set (array_info->get_mask, descs->ndescs, - count - descs->ndescs); -bitmap_set (array_info->set_mask, descs->ndescs, - count - descs->ndescs); +bitmap_set (array_info->get_mask,0 , count); +bitmap_set (array_info->set_mask,0 , count); descs->info = array_info; }
@@ -5094,38 +5092,34 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,/* Unmark array members which don't belong to the 'fast' chip */ if (array_info->gdev != gdev) { -__clear_bit (descs->ndescs, array_info->get_mask); -__clear_bit (descs->ndescs, array_info->set_mask); +__clear_bit (i, array_info->get_mask); +__clear_bit (i, array_info->set_mask); }/* * Detect array members which belong to the 'fast' chip * but their pins are not in hardware order. */ -else if (gpiod_hwgpio (desc) != descs->ndescs) { +else if (gpiod_hwgpio (desc) != i) {/* * Don't use fast path if all array members processed so * far belong to the same chip as this one but its pin * hardware number is different from its array index. */ -if (bitmap_full (array_info->get_mask, descs->ndescs)) { +if (bitmap_full (array_info->get_mask, i)) { array_info =NULL ; }else { -__clear_bit (descs->ndescs, - array_info->get_mask); -__clear_bit (descs->ndescs, - array_info->set_mask); +__clear_bit (i, array_info->get_mask); +__clear_bit (i, array_info->set_mask); } }else { dflags =READ_ONCE (desc->flags);/* Exclude open drain or open source from fast output */ if (test_bit (GPIOD_FLAG_OPEN_DRAIN , &dflags) ||test_bit (GPIOD_FLAG_OPEN_SOURCE , &dflags)) -__clear_bit (descs->ndescs, - array_info->set_mask); +__clear_bit (i, array_info->set_mask);/* Identify 'fast' pins which require invertion */ if (gpiod_is_active_low (desc)) -__set_bit (descs->ndescs, - array_info->invert_mask); +__set_bit (i, array_info->invert_mask); } }if (array_info)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 353/990 gpiolib: fix fast-path cancellation in gpiod_get_array()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 51c85306270972f672737dc5e28332e2b41b26f1 ]
In gpiod_get_array(), when a pin on the same chip is not in hardware order and the preceding pins form a contiguous block, the fast path is cancelled by setting array_info to NULL. However, descs->info was already populated with the array_info pointer during the first iteration, leaving descs->info pointing to the aborted array_info. Consequently, subsequent array operations still use the fast path with remaining bits set in the masks and wrong hardware pin numbers.
Clear descs->info alongside array_info when cancelling the fast path so callers do not erroneously use the aborted array_info.
--- drivers/gpio/gpiolib.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib.c +1 -0
@@ -5106,6 +5106,7 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,* hardware number is different from its array index. */ if (bitmap_full (array_info->get_mask, i)) { + descs->info =NULL ; array_info =NULL ; }else {__clear_bit (i, array_info->get_mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 354/990 gpiolib: of: return -ENOENT from of_gpio_count() stub
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit e20e4b8cda2b4d7dd32dbd2c0875a15d92545f04 ]
gpiod_count() and its firmware backends are expected to return either a positive number of GPIOs or a negative error code (-ENOENT) when no GPIOs are assigned. However, the !CONFIG_OF_GPIO stub for of_gpio_count() returns 0 instead of -ENOENT. This causes gpiod_count() to skip the platform_gpio_count() fallback (which triggers when count < 0) and erroneously return 0 to callers.
Change the stub to return -ENOENT to match the real of_gpio_count() implementation and the other error-returning stubs in gpiolib-of.h.
--- drivers/gpio/gpiolib-of.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-of.h +1 -1
@@ -42,7 +42,7 @@ static inline bool of_gpiochip_instance_match(struct gpio_chip *gc,static inline int of_gpio_count (const struct fwnode_handle *fwnode,const char *con_id) { -return 0 ; +return -ENOENT ; }#endif /* CONFIG_OF_GPIO */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 355/990 ASoC: soc-core: copy the DAI link names into the card
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyler Baker <[email protected]>
[ Upstream commit 33a130f6ed8c75ed59b12889a417a57fb80d0abf ]
snd_soc_of_get_dai_link_codecs() and snd_soc_of_get_dai_link_cpus() keep a DAI name owned by the component, which is freed when the component unbinds, so the card cannot bind again afterwards.
Copy the name onto the card device, as simple-card and audio-graph-card do since commit aa173b70d372 ("ASoC: generic: keep fallback dai_name stable across rebind").
--- sound/soc/soc-core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/soc/soc-core.c +16 -0
@@ -3701,6 +3701,18 @@ void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link) }EXPORT_SYMBOL_GPL (snd_soc_of_put_dai_link_codecs); +/* dai_name belongs to the component, which can unbind before the card. */ +static int snd_soc_of_dup_dai_name (struct device *dev, +struct snd_soc_dai_link_component *dlc) +{ +if (!dlc->dai_name) +return 0 ; + + dlc->dai_name =devm_kstrdup_const (dev, dlc->dai_name,GFP_KERNEL ); + +return dlc->dai_name ?0 : -ENOMEM ; +} +/* * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree * @dev: Card device
@@ -3730,6 +3742,8 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,/* Parse the list */ for_each_link_codecs (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
@@ -3785,6 +3799,8 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev,/* Parse the list */ for_each_link_cpus (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 356/990 ASoC: qcom: sdw: remove redundant code
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit d02460317ed9c95aa2c5f6ff1c70e22e1857d95d ]
remove redundant code and pointers to handle sdw_stream_runtime by making use of qcom_snd_sdw_get_stream(). This removes need of machine specific shutdown and hw_params sdw callbacks and also need to store sdw_stream_runtime pointers in machine drivers.
Stable-dep-of: 704251f9dad3 ("ASoC: qcom: x1e80100: recreate the headset jack on card rebind")
--- sound/soc/qcom/sc8280xp.c | 33 +++------------------------------ sound/soc/qcom/sdw.c | 24 ++++++++++++------------ sound/soc/qcom/sdw.h | 6 +----- sound/soc/qcom/sm8250.c | 33 +++------------------------------ sound/soc/qcom/x1e80100.c | 33 +++------------------------------ 5 files changed, 22 insertions(+), 107 deletions(-)
sound/soc/qcom/sc8280xp.c +3 -30
@@ -18,7 +18,6 @@struct sc8280xp_snd_data {bool stream_prepared[AFE_PORT_MAX ];struct snd_soc_card *card; -struct sdw_stream_runtime *sruntime[AFE_PORT_MAX ];struct snd_soc_jack jack;struct snd_soc_jack dp_jack[8 ];bool jack_setup;
@@ -68,17 +67,6 @@ static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd)return qcom_snd_wcd_jack_setup (rtd, &data->jack, &data->jack_setup); } -static void sc8280xp_snd_shutdown (struct snd_pcm_substream *substream) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sc8280xp_snd_data *pdata =snd_soc_card_get_drvdata (rtd->card); -struct sdw_stream_runtime *sruntime =qcom_snd_sdw_get_stream (substream); - - pdata->sruntime[cpu_dai->id] =NULL ; -sdw_release_stream (sruntime); -} -static int sc8280xp_be_hw_params_fixup (struct snd_soc_pcm_runtime *rtd,struct snd_pcm_hw_params *params) {
@@ -108,25 +96,13 @@ static int sc8280xp_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,return 0 ; } -static int sc8280xp_snd_hw_params (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sc8280xp_snd_data *pdata =snd_soc_card_get_drvdata (rtd->card); - -return qcom_snd_sdw_hw_params (substream, params, &pdata->sruntime[cpu_dai->id]); -} -static int sc8280xp_snd_prepare (struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 );struct sc8280xp_snd_data *data =snd_soc_card_get_drvdata (rtd->card); -struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id]; -return qcom_snd_sdw_prepare (substream, sruntime, - &data->stream_prepared[cpu_dai->id]); +return qcom_snd_sdw_prepare (substream, &data->stream_prepared[cpu_dai->id]); }static int sc8280xp_snd_hw_free (struct snd_pcm_substream *substream)
@@ -134,16 +110,13 @@ static int sc8280xp_snd_hw_free(struct snd_pcm_substream *substream)struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct sc8280xp_snd_data *data =snd_soc_card_get_drvdata (rtd->card);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id]; -return qcom_snd_sdw_hw_free (substream, sruntime, - &data->stream_prepared[cpu_dai->id]); +return qcom_snd_sdw_hw_free (substream, &data->stream_prepared[cpu_dai->id]); }static const struct snd_soc_ops sc8280xp_be_ops = { .startup = qcom_snd_sdw_startup, - .shutdown = sc8280xp_snd_shutdown, - .hw_params = sc8280xp_snd_hw_params, + .shutdown = qcom_snd_sdw_shutdown, .hw_free = sc8280xp_snd_hw_free, .prepare = sc8280xp_snd_prepare, };
sound/soc/qcom/sdw.c +12 -12
@@ -124,19 +124,21 @@ int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)EXPORT_SYMBOL_GPL (qcom_snd_sdw_startup);int qcom_snd_sdw_prepare (struct snd_pcm_substream *substream, -struct sdw_stream_runtime *sruntime,bool *stream_prepared) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +struct sdw_stream_runtime *sruntime;int ret; -if (!sruntime) -return 0 ;if (!qcom_snd_is_sdw_dai (cpu_dai->id))return 0 ; + sruntime =qcom_snd_sdw_get_stream (substream); +if (!sruntime) +return 0 ; +if (*stream_prepared)return 0 ;
@@ -183,26 +185,24 @@ struct sdw_stream_runtime *qcom_snd_sdw_get_stream(struct snd_pcm_substream *sub }EXPORT_SYMBOL_GPL (qcom_snd_sdw_get_stream); -int qcom_snd_sdw_hw_params (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params, -struct sdw_stream_runtime **psruntime) +void qcom_snd_sdw_shutdown (struct snd_pcm_substream *substream) { - *psruntime =qcom_snd_sdw_get_stream (substream); - -return 0 ; +struct sdw_stream_runtime *sruntime =qcom_snd_sdw_get_stream (substream); +sdw_release_stream (sruntime); } -EXPORT_SYMBOL_GPL (qcom_snd_sdw_hw_params); +EXPORT_SYMBOL_GPL (qcom_snd_sdw_shutdown); -int qcom_snd_sdw_hw_free (struct snd_pcm_substream *substream, -struct sdw_stream_runtime *sruntime,bool *stream_prepared) +int qcom_snd_sdw_hw_free (struct snd_pcm_substream *substream,bool *stream_prepared) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +struct sdw_stream_runtime *sruntime;if (!qcom_snd_is_sdw_dai (cpu_dai->id))return 0 ; + sruntime =qcom_snd_sdw_get_stream (substream);if (sruntime && *stream_prepared) {sdw_disable_stream (sruntime);sdw_deprepare_stream (sruntime);
sound/soc/qcom/sdw.h +1 -5
@@ -7,14 +7,10 @@#include <linux/soundwire/sdw.h> int qcom_snd_sdw_startup (struct snd_pcm_substream *substream); +void qcom_snd_sdw_shutdown (struct snd_pcm_substream *substream);int qcom_snd_sdw_prepare (struct snd_pcm_substream *substream, -struct sdw_stream_runtime *runtime,bool *stream_prepared);struct sdw_stream_runtime *qcom_snd_sdw_get_stream (struct snd_pcm_substream *stream); -int qcom_snd_sdw_hw_params (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params, -struct sdw_stream_runtime **psruntime);int qcom_snd_sdw_hw_free (struct snd_pcm_substream *substream, -struct sdw_stream_runtime *sruntime,bool *stream_prepared);#endif
sound/soc/qcom/sm8250.c +3 -30
@@ -21,7 +21,6 @@struct sm8250_snd_data {bool stream_prepared[AFE_PORT_MAX ];struct snd_soc_card *card; -struct sdw_stream_runtime *sruntime[AFE_PORT_MAX ];struct snd_soc_jack jack;struct snd_soc_jack usb_offload_jack;bool usb_offload_jack_setup;
@@ -112,36 +111,13 @@ static int sm8250_snd_startup(struct snd_pcm_substream *substream)return qcom_snd_sdw_startup (substream); } -static void sm8250_snd_shutdown (struct snd_pcm_substream *substream) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sm8250_snd_data *data =snd_soc_card_get_drvdata (rtd->card); -struct sdw_stream_runtime *sruntime =qcom_snd_sdw_get_stream (substream); - - data->sruntime[cpu_dai->id] =NULL ; -sdw_release_stream (sruntime); -} - -static int sm8250_snd_hw_params (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sm8250_snd_data *pdata =snd_soc_card_get_drvdata (rtd->card); - -return qcom_snd_sdw_hw_params (substream, params, &pdata->sruntime[cpu_dai->id]); -} -static int sm8250_snd_prepare (struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 );struct sm8250_snd_data *data =snd_soc_card_get_drvdata (rtd->card); -struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id]; -return qcom_snd_sdw_prepare (substream, sruntime, - &data->stream_prepared[cpu_dai->id]); +return qcom_snd_sdw_prepare (substream, &data->stream_prepared[cpu_dai->id]); }static int sm8250_snd_hw_free (struct snd_pcm_substream *substream)
@@ -149,16 +125,13 @@ static int sm8250_snd_hw_free(struct snd_pcm_substream *substream)struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct sm8250_snd_data *data =snd_soc_card_get_drvdata (rtd->card);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id]; -return qcom_snd_sdw_hw_free (substream, sruntime, - &data->stream_prepared[cpu_dai->id]); +return qcom_snd_sdw_hw_free (substream, &data->stream_prepared[cpu_dai->id]); }static const struct snd_soc_ops sm8250_be_ops = { .startup = sm8250_snd_startup, - .shutdown = sm8250_snd_shutdown, - .hw_params = sm8250_snd_hw_params, + .shutdown = qcom_snd_sdw_shutdown, .hw_free = sm8250_snd_hw_free, .prepare = sm8250_snd_prepare, };
sound/soc/qcom/x1e80100.c +3 -30
@@ -18,7 +18,6 @@struct x1e80100_snd_data {bool stream_prepared[AFE_PORT_MAX ];struct snd_soc_card *card; -struct sdw_stream_runtime *sruntime[AFE_PORT_MAX ];struct snd_soc_jack jack;struct snd_soc_jack dp_jack[8 ];bool jack_setup;
@@ -50,17 +49,6 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)return qcom_snd_wcd_jack_setup (rtd, &data->jack, &data->jack_setup); } -static void x1e80100_snd_shutdown (struct snd_pcm_substream *substream) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); -struct sdw_stream_runtime *sruntime =qcom_snd_sdw_get_stream (substream); - - data->sruntime[cpu_dai->id] =NULL ; -sdw_release_stream (sruntime); -} -static int x1e80100_be_hw_params_fixup (struct snd_soc_pcm_runtime *rtd,struct snd_pcm_hw_params *params) {
@@ -85,16 +73,6 @@ static int x1e80100_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,return 0 ; } -static int x1e80100_snd_hw_params (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); - -return qcom_snd_sdw_hw_params (substream, params, &data->sruntime[cpu_dai->id]); -} -static int x1e80100_snd_hw_map_channels (unsigned int *ch_map,int num) {switch (num) {
@@ -128,7 +106,6 @@ static int x1e80100_snd_prepare(struct snd_pcm_substream *substream)struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 );struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); -struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];unsigned int channels = substream->runtime->channels;unsigned int rx_slot[4 ];int ret;
@@ -149,8 +126,7 @@ static int x1e80100_snd_prepare(struct snd_pcm_substream *substream)break ; } -return qcom_snd_sdw_prepare (substream, sruntime, - &data->stream_prepared[cpu_dai->id]); +return qcom_snd_sdw_prepare (substream, &data->stream_prepared[cpu_dai->id]); }static int x1e80100_snd_hw_free (struct snd_pcm_substream *substream)
@@ -158,16 +134,13 @@ static int x1e80100_snd_hw_free(struct snd_pcm_substream *substream)struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card);struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id]; -return qcom_snd_sdw_hw_free (substream, sruntime, - &data->stream_prepared[cpu_dai->id]); +return qcom_snd_sdw_hw_free (substream, &data->stream_prepared[cpu_dai->id]); }static const struct snd_soc_ops x1e80100_be_ops = { .startup = qcom_snd_sdw_startup, - .shutdown = x1e80100_snd_shutdown, - .hw_params = x1e80100_snd_hw_params, + .shutdown = qcom_snd_sdw_shutdown, .hw_free = x1e80100_snd_hw_free, .prepare = x1e80100_snd_prepare, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 357/990 ASoC: dt-bindings: qcom: add LPASS LPI MI2S dai ids
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit e46957f27c6004f3ab5ec456f4e848950364ebc1 ]
Add new dai ids entries for LPASS LPI MI2S and SENARY MI2S audio lines.
Stable-dep-of: 704251f9dad3 ("ASoC: qcom: x1e80100: recreate the headset jack on card rebind")
--- .../bindings/sound/qcom,q6dsp-lpass-ports.yaml | 5 ++++- include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/sound/qcom,q6dsp-lpass-ports.yaml +4 -1
@@ -126,13 +126,16 @@ patternProperties: reg: contains: # MI2S DAI ID range PRIMARY_MI2S_RX - QUATERNARY_MI2S_TX and - # QUINARY_MI2S_RX - QUINARY_MI2S_TX + # QUINARY_MI2S_RX - QUINARY_MI2S_TX and + # LPI_MI2S_RX_0 - SENARY_MI2S_TX items: oneOf: - minimum: 16 maximum: 23 - minimum: 127 maximum: 128 + - minimum: 137 + maximum: 148 then: required: - qcom,sd-lines
include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h +12 -0
@@ -140,6 +140,18 @@#define DISPLAY_PORT_RX_6 134#define DISPLAY_PORT_RX_7 135#define USB_RX 136 +#define LPI_MI2S_RX_0 137 +#define LPI_MI2S_TX_0 138 +#define LPI_MI2S_RX_1 139 +#define LPI_MI2S_TX_1 140 +#define LPI_MI2S_RX_2 141 +#define LPI_MI2S_TX_2 142 +#define LPI_MI2S_RX_3 143 +#define LPI_MI2S_TX_3 144 +#define LPI_MI2S_RX_4 145 +#define LPI_MI2S_TX_4 146 +#define SENARY_MI2S_RX 147 +#define SENARY_MI2S_TX 148#define LPASS_CLK_ID_PRI_MI2S_IBIT 1#define LPASS_CLK_ID_PRI_MI2S_EBIT 2
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 358/990 ASoC: qcom: common: validate cpu dai id during parsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit d49ee8faefecd4d2eb5c6c9f419f4db9488d68aa ]
lpass ports numbers have been added but the afe/apm driver never got updated with new max port value that it uses to store dai specific data. There are more than one places these values are cached and always become out of sync.
This will result in array out of bounds and weird driver behaviour.
To catch such issues, first add a single place where we can define max port and second add a check in common parsing code which can error out before corrupting the memory with out of bounds array access.
This should help both avoid and catch these type of mistakes in future.
Stable-dep-of: 704251f9dad3 ("ASoC: qcom: x1e80100: recreate the headset jack on card rebind")
--- sound/soc/qcom/common.c | 6 ++++++ sound/soc/qcom/common.h | 3 +++ sound/soc/qcom/lpass.h | 3 ++- sound/soc/qcom/qdsp6/q6afe.h | 3 ++- sound/soc/qcom/qdsp6/q6apm.h | 3 ++- 5 files changed, 15 insertions(+), 3 deletions(-)
sound/soc/qcom/common.c +6 -0
@@ -120,6 +120,12 @@ int qcom_snd_parse_of(struct snd_soc_card *card) link->id = args.args[0 ]; +if (link->id >=LPASS_MAX_PORT ) { +dev_err (dev,"%s: Invalid cpu dai id %d\n" , link->name, link->id); + ret = -EINVAL ; + goto err; + } +if (platform) { link->platforms->of_node = of_parse_phandle(platform, "sound-dai",
sound/soc/qcom/common.h +3 -0
@@ -4,8 +4,11 @@#ifndef __QCOM_SND_COMMON_H__#define __QCOM_SND_COMMON_H__ +#include <dt-bindings/sound/qcom,q6afe.h> #include <sound/soc.h> +#define LPASS_MAX_PORT (SENARY_MI2S_TX + 1) +int qcom_snd_parse_of (struct snd_soc_card *card);int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd,struct snd_soc_jack *jack,bool *jack_setup);
sound/soc/qcom/lpass.h +2 -1
@@ -14,10 +14,11 @@#include <linux/regmap.h> #include <dt-bindings/sound/qcom,lpass.h> #include <dt-bindings/sound/qcom,q6afe.h> +#include "common.h" #include "lpass-hdmi.h" #define LPASS_AHBIX_CLOCK_FREQUENCY 131072000 -#define LPASS_MAX_PORTS (DISPLAY_PORT_RX_7 + 1) +#define LPASS_MAX_PORTS (LPASS_MAX_PORT)#define LPASS_MAX_MI2S_PORTS (8)#define LPASS_MAX_DMA_CHANNELS (8)#define LPASS_MAX_HDMI_DMA_CHANNELS (4)
sound/soc/qcom/qdsp6/q6afe.h +2 -1
@@ -2,8 +2,9 @@#ifndef __Q6AFE_H__#define __Q6AFE_H__ +#include "../common.h" -#define AFE_PORT_MAX 137 +#define AFE_PORT_MAX (LPASS_MAX_PORT)#define MSM_AFE_PORT_TYPE_RX 0#define MSM_AFE_PORT_TYPE_TX 1
sound/soc/qcom/qdsp6/q6apm.h +2 -1
@@ -14,9 +14,10 @@#include <linux/of_platform.h> #include <linux/jiffies.h> #include <linux/soc/qcom/apr.h> +#include "../common.h" #include "audioreach.h" -#define APM_PORT_MAX 127 +#define APM_PORT_MAX LPASS_MAX_PORT#define APM_PORT_MAX_AUDIO_CHAN_CNT 8#define PCM_CHANNEL_NULL 0#define PCM_CHANNEL_FL 1/* Front left channel. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 359/990 ASoC: qcom: common: add DAI-node TDM slot helpers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prasad Kumpatla <[email protected]>
[ Upstream commit 1e844ecbc9cbd7c88543c5a84c0d1e434f46fd8b ]
Add common helpers to parse standard dai-tdm-slot-* properties from the CPU and codec child nodes of a backend DAI link and apply the result to the active DAIs.
QCOM machine drivers already use qcom_snd_parse_of() to build links from DT, but they lacked a shared helper to translate endpoint TDM properties into snd_soc_dai_set_tdm_slot() calls. Boards therefore had to carry ad hoc parsing or rely on non-standard DT properties.
The helpers parse endpoint masks, validate the shared slot count and slot width, and program CPU and codec DAIs with the resulting slot configuration. A cfg-based apply helper is provided for callers that already parsed the DT data and want to avoid a second DT traversal.
Stable-dep-of: 704251f9dad3 ("ASoC: qcom: x1e80100: recreate the headset jack on card rebind")
--- sound/soc/qcom/common.c | 155 ++++++++++++++++++++++++++++++++++++++++ sound/soc/qcom/common.h | 14 ++++ 2 files changed, 169 insertions(+)
sound/soc/qcom/common.c +155 -0
@@ -23,6 +23,161 @@ static const struct snd_soc_dapm_widget qcom_jack_snd_widgets[] = { SND_SOC_DAPM_SPK("DP7 Jack", NULL), }; +static struct device_node *qcom_snd_get_link_node (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +struct snd_soc_card *card = rtd->card; +struct of_phandle_args args; +int ret; + +if (!card->dev || !card->dev->of_node) +return NULL ; + +for_each_available_child_of_node_scoped (card->dev->of_node, np) { + struct device_node *cpu_np __free(device_node) = +of_get_child_by_name (np,"cpu" ); + +if (!cpu_np) +continue ; + + ret =of_parse_phandle_with_args (cpu_np,"sound-dai" ,"#sound-dai-cells" ,0 , + &args); +if (ret) +continue ; + +if (args.np == rtd->dai_link->cpus[0 ].of_node && + args.args_count ==1 && args.args[0 ] == cpu_dai->id) { +of_node_put (args.np); +return of_node_get (np); + } + +of_node_put (args.np); + } + +return NULL ; +} + +static int qcom_snd_parse_tdm_slot (struct device_node *np, +struct qcom_snd_tdm_slot_cfg *cfg) +{ +memset (cfg,0 ,sizeof (*cfg)); + +return snd_soc_of_parse_tdm_slot (np, &cfg->tx_mask, &cfg->rx_mask, + &cfg->slots, &cfg->slot_width); +} + +static int qcom_snd_normalize_tdm_slots (struct qcom_snd_tdm_slot_cfg *cpu_cfg, +struct qcom_snd_tdm_slot_cfg *codec_cfg) +{ +unsigned int slots; +unsigned int slot_width; + +if (cpu_cfg->slots && codec_cfg->slots && cpu_cfg->slots != codec_cfg->slots) +return -EINVAL ; + +if (cpu_cfg->slot_width && codec_cfg->slot_width && + cpu_cfg->slot_width != codec_cfg->slot_width) +return -EINVAL ; + + slots = cpu_cfg->slots ?: codec_cfg->slots; +if (!slots) +return 0 ; + + slot_width = cpu_cfg->slot_width ?: codec_cfg->slot_width; +if (!slot_width) +return -EINVAL ; + + cpu_cfg->slots = slots; + codec_cfg->slots = slots; + cpu_cfg->slot_width = slot_width; + codec_cfg->slot_width = slot_width; + +return 0 ; +} + +static int qcom_snd_parse_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd, +struct qcom_snd_tdm_slot_cfg *cpu_cfg, +struct qcom_snd_tdm_slot_cfg *codec_cfg) +{ + struct device_node *link_np __free(device_node) = qcom_snd_get_link_node(rtd); +int ret; + +if (!link_np) +return -EINVAL ; + + struct device_node *cpu_np __free(device_node) = +of_get_child_by_name (link_np,"cpu" ); + struct device_node *codec_np __free(device_node) = +of_get_child_by_name (link_np,"codec" ); +if (!cpu_np || !codec_np) +return -EINVAL ; + + ret =qcom_snd_parse_tdm_slot (cpu_np, cpu_cfg); +if (ret) +return ret; + +return qcom_snd_parse_tdm_slot (codec_np, codec_cfg); +} + +int qcom_snd_get_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd, +struct qcom_snd_tdm_slot_cfg *cpu_cfg, +struct qcom_snd_tdm_slot_cfg *codec_cfg) +{ +int ret; + + ret =qcom_snd_parse_dai_tdm_slots (rtd, cpu_cfg, codec_cfg); +if (ret) +return ret; + +return qcom_snd_normalize_tdm_slots (cpu_cfg, codec_cfg); +} +EXPORT_SYMBOL_GPL (qcom_snd_get_dai_tdm_slots); + +int qcom_snd_apply_dai_tdm_slots_cfg (struct snd_soc_pcm_runtime *rtd, +const struct qcom_snd_tdm_slot_cfg *cpu_cfg, +const struct qcom_snd_tdm_slot_cfg *codec_cfg) +{ +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +struct snd_soc_dai *codec_dai; +int i; +int ret; + +if (!cpu_cfg->slots) +return 0 ; + + ret =snd_soc_dai_set_tdm_slot (cpu_dai, cpu_cfg->tx_mask, cpu_cfg->rx_mask, + cpu_cfg->slots, cpu_cfg->slot_width); +if (ret) +return ret; + +for_each_rtd_codec_dais (rtd, i, codec_dai) { + ret =snd_soc_dai_set_tdm_slot (codec_dai, + codec_cfg->tx_mask, + codec_cfg->rx_mask, + codec_cfg->slots, + codec_cfg->slot_width); +if (ret) +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (qcom_snd_apply_dai_tdm_slots_cfg); + +int qcom_snd_apply_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd) +{ +struct qcom_snd_tdm_slot_cfg cpu_cfg; +struct qcom_snd_tdm_slot_cfg codec_cfg; +int ret; + + ret =qcom_snd_get_dai_tdm_slots (rtd, &cpu_cfg, &codec_cfg); +if (ret) +return ret == -EINVAL ?0 : ret; + +return qcom_snd_apply_dai_tdm_slots_cfg (rtd, &cpu_cfg, &codec_cfg); +} +EXPORT_SYMBOL_GPL (qcom_snd_apply_dai_tdm_slots); +int qcom_snd_parse_of (struct snd_soc_card *card) {struct device_node *np;
sound/soc/qcom/common.h +14 -0
@@ -9,7 +9,21 @@#define LPASS_MAX_PORT (SENARY_MI2S_TX + 1) +struct qcom_snd_tdm_slot_cfg { +unsigned int tx_mask; +unsigned int rx_mask; +unsigned int slots; +unsigned int slot_width; +}; +int qcom_snd_parse_of (struct snd_soc_card *card); +int qcom_snd_get_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd, +struct qcom_snd_tdm_slot_cfg *cpu_cfg, +struct qcom_snd_tdm_slot_cfg *codec_cfg); +int qcom_snd_apply_dai_tdm_slots_cfg (struct snd_soc_pcm_runtime *rtd, +const struct qcom_snd_tdm_slot_cfg *cpu_cfg, +const struct qcom_snd_tdm_slot_cfg *codec_cfg); +int qcom_snd_apply_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd);int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd,struct snd_soc_jack *jack,bool *jack_setup); int qcom_snd_dp_jack_setup(struct snd_soc_pcm_runtime *rtd,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 360/990 ASoC: qcom: common: Add generic headset jack helpers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongyang Zhao <[email protected]>
[ Upstream commit 7f8dd07370f8c17f8f98f0fa98691635828b0dac ]
qcom_snd_wcd_jack_setup() combines creation of the card-level headset jack with the WCD-specific operation of attaching jack detection to codecs on the TX codec DMA links. External codecs connected over MI2S also provide component jack detection, but cannot use the WCD-specific DAI filtering.
Factor the common jack allocation, DAPM pin registration and headset button mappings into a private initializer. Reuse it from the existing WCD path and add a generic setup helper which attaches the jack to every codec component in a runtime.
Treat -ENOTSUPP as a no-op because snd_soc_component_set_jack() uses it for components which do not provide a set_jack callback.
Add a matching cleanup helper so machine drivers can detach component jack detection when the DAI link exits. The WCD setup behavior remains unchanged.
Stable-dep-of: 704251f9dad3 ("ASoC: qcom: x1e80100: recreate the headset jack on card rebind")
--- sound/soc/qcom/common.c | 61 +++++++++++++++++++++++++++++++++++------ sound/soc/qcom/common.h | 3 ++ 2 files changed, 56 insertions(+), 8 deletions(-)
sound/soc/qcom/common.c +53 -8
@@ -356,13 +356,11 @@ static struct snd_soc_jack_pin qcom_headset_jack_pins[] = { }, }; -int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd, -struct snd_soc_jack *jack,bool *jack_setup) +static int qcom_snd_headset_jack_init (struct snd_soc_card *card, +struct snd_soc_jack *jack, +bool *jack_setup) { -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 ); -struct snd_soc_card *card = rtd->card; -int rval, i; +int rval;if (!*jack_setup) { rval = snd_soc_card_jack_new_pins(card, "Headset Jack",
@@ -386,6 +384,55 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, *jack_setup = true; } +return 0 ; +} + +int qcom_snd_headset_jack_setup (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_jack *jack,bool *jack_setup) +{ +struct snd_soc_dai *codec_dai; +struct snd_soc_card *card = rtd->card; +int rval, i; + + rval =qcom_snd_headset_jack_init (card, jack, jack_setup); +if (rval) +return rval; + +for_each_rtd_codec_dais (rtd, i, codec_dai) { + rval =snd_soc_component_set_jack (codec_dai->component, jack,NULL ); +if (rval !=0 && rval != -ENOTSUPP ) { +dev_warn (card->dev,"Failed to set jack: %d\n" , rval); +qcom_snd_headset_jack_cleanup (rtd); +return rval; + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (qcom_snd_headset_jack_setup); + +void qcom_snd_headset_jack_cleanup (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_dai *codec_dai; +int i; + +for_each_rtd_codec_dais (rtd, i, codec_dai) +snd_soc_component_set_jack (codec_dai->component,NULL ,NULL ); +} +EXPORT_SYMBOL_GPL (qcom_snd_headset_jack_cleanup); + +int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_jack *jack,bool *jack_setup) +{ +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +struct snd_soc_card *card = rtd->card; +int rval, i; + + rval =qcom_snd_headset_jack_init (card, jack, jack_setup); +if (rval) +return rval; +switch (cpu_dai->id) {case TX_CODEC_DMA_TX_0 :case TX_CODEC_DMA_TX_1 :
@@ -404,8 +451,6 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd,default :break ; } - -return 0 ; }EXPORT_SYMBOL_GPL (qcom_snd_wcd_jack_setup);
sound/soc/qcom/common.h +3 -0
@@ -24,6 +24,9 @@ int qcom_snd_apply_dai_tdm_slots_cfg(struct snd_soc_pcm_runtime *rtd,const struct qcom_snd_tdm_slot_cfg *cpu_cfg, const struct qcom_snd_tdm_slot_cfg *codec_cfg);int qcom_snd_apply_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd); +int qcom_snd_headset_jack_setup (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_jack *jack,bool *jack_setup); +void qcom_snd_headset_jack_cleanup (struct snd_soc_pcm_runtime *rtd);int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd,struct snd_soc_jack *jack,bool *jack_setup); int qcom_snd_dp_jack_setup(struct snd_soc_pcm_runtime *rtd,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 361/990 ASoC: qcom: x1e80100: recreate the headset jack on card rebind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyler Baker <[email protected]>
[ Upstream commit 704251f9dad3cb5f93ef64ff2d547868d42de319 ]
The headset jack is only created while jack_setup is false and nothing clears it, so after a card rebind it is not created again and the codecs keep a pointer to the freed jack.
Clear it on link exit, as sc8280xp does.
--- sound/soc/qcom/x1e80100.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
sound/soc/qcom/x1e80100.c +18 -0
@@ -49,6 +49,23 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)return qcom_snd_wcd_jack_setup (rtd, &data->jack, &data->jack_setup); } +static void x1e80100_snd_exit (struct snd_soc_pcm_runtime *rtd) +{ +struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); + +switch (cpu_dai->id) { +case DISPLAY_PORT_RX_0 : + case DISPLAY_PORT_RX_1 ... DISPLAY_PORT_RX_7: +return ; +default : +break ; + } + +qcom_snd_headset_jack_cleanup (rtd); + data->jack_setup = false; +} +static int x1e80100_be_hw_params_fixup (struct snd_soc_pcm_runtime *rtd,struct snd_pcm_hw_params *params) {
@@ -153,6 +170,7 @@ static void x1e80100_add_be_ops(struct snd_soc_card *card)for_each_card_prelinks (card, i, link) {if (link->no_pcm ==1 ) { link->init = x1e80100_snd_init; + link->exit = x1e80100_snd_exit; link->be_hw_params_fixup = x1e80100_be_hw_params_fixup; link->ops = &x1e80100_be_ops; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 362/990 ASoC: amd: ps: guard adata->sdw dereferences with NULL check in IRQ handler
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vijendar Mukunda <[email protected]>
[ Upstream commit 41e06aaef9c000c1bb52d8a6f73ae66c9bd36d83 ]
The ACP external IRQ handler is registered before sdw_amd_probe() assigns adata->sdw, so a stray interrupt in the probe window could reach the adata->sdw->pdev[i] dereference with adata->sdw still NULL.
The same window exists on the teardown side: after sdw_amd_exit() frees the context but before adata->sdw is cleared by the caller.
Add NULL checks for adata->sdw in acp63_irq_handler() before dereferencing ->pdev[0] and ->pdev[1], and in handle_acp70_sdw_wake_event() for the same reason. The interrupt-status register write that acknowledges the IRQ is kept outside the guard so the hardware bit is always cleared regardless of whether the SoundWire context is live.
--- sound/soc/amd/ps/pci-ps.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
sound/soc/amd/ps/pci-ps.c +20 -12
@@ -26,16 +26,20 @@ static void handle_acp70_sdw_wake_event(struct acp63_dev_data *adata)struct amd_sdw_manager *amd_manager;if (adata->acp70_sdw0_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw0_wake_event =0 ; }if (adata->acp70_sdw1_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw1_wake_event =0 ; } }
@@ -209,18 +213,22 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) ext_intr_stat =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT );if (ext_intr_stat &ACP_SDW0_STAT ) {writel (ACP_SDW0_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; } ext_intr_stat1 =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 );if (ext_intr_stat1 &ACP_SDW1_STAT ) {writel (ACP_SDW1_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 363/990 ASoC: SOF: amd: guard adata->sdw dereferences with NULL check in IRQ handler
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vijendar Mukunda <[email protected]>
[ Upstream commit 34ea81a7f284a13d825279fdede36b7f793f9936 ]
The ACP external IRQ handler is registered before sdw_amd_probe() assigns adata->sdw, so a stray interrupt in the probe window could reach the adata->sdw->pdev[i] dereference with adata->sdw still NULL.
The same window exists on the teardown side: after sdw_amd_exit() frees the context but before adata->sdw is cleared by the caller.
Add NULL checks for adata->sdw in acp_irq_handler() before dereferencing ->pdev[0] and ->pdev[1], and in amd_sof_handle_acp70_sdw_wake_event() for the same reason. The interrupt-status register write that acknowledges the IRQ is kept outside the guard so the hardware bit is always cleared regardless of whether the SoundWire context is live.
--- sound/soc/sof/amd/acp.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
sound/soc/sof/amd/acp.c +20 -12
@@ -394,16 +394,20 @@ static void amd_sof_handle_acp70_sdw_wake_event(struct acp_dev_data *adata)struct amd_sdw_manager *amd_manager;if (adata->acp70_sdw0_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw0_wake_event =0 ; }if (adata->acp70_sdw1_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw1_wake_event =0 ; } }
@@ -495,10 +499,12 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id) val =snd_sof_dsp_read (sdev,ACP_DSP_BAR , desc->ext_intr_stat);if (val &ACP_SDW0_IRQ_MASK ) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev);snd_sof_dsp_write (sdev,ACP_DSP_BAR , desc->ext_intr_stat,ACP_SDW0_IRQ_MASK ); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }
@@ -515,11 +521,13 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id)if (desc->ext_intr_stat1) { val =snd_sof_dsp_read (sdev,ACP_DSP_BAR , desc->ext_intr_stat1);if (val &ACP_SDW1_IRQ_MASK ) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev);snd_sof_dsp_write (sdev,ACP_DSP_BAR , desc->ext_intr_stat1,ACP_SDW1_IRQ_MASK ); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }switch (adata->pci_rev) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 364/990 ASoC: amd: acp: es83xx: Enable speaker amplifier after the codec output
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Leyva <[email protected]>
[ Upstream commit f392763d73356760eac3e4ab7c87b0855be0d4bb ]
The speaker amplifier GPIO is driven from a SUPPLY widget. DAPM powers supplies before the rest of the path, so the amplifier is enabled while the ES8316 headphone driver and charge pump, which also feed the speakers, are still powering up. This results in an audible pop every time the speaker output is powered on.
Move the speaker GPIO handling to the Speaker endpoint widget, which DAPM powers up last and powers down first, and give the codec output a short time to settle before enabling the amplifier.
The headphone path is left unchanged: the Headphone endpoint widget shares its power-up rank with the codec output drivers, so moving it would not guarantee the same ordering, and it could not be tested.
--- sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c +9 -7
@@ -19,6 +19,7 @@#include <linux/input.h> #include <linux/io.h> #include <linux/acpi.h> +#include <linux/delay.h> #include <linux/dmi.h> #include <linux/string_choices.h> #include "../acp-mach.h"
@@ -61,6 +62,8 @@ static const struct snd_pcm_hw_constraint_list constraints_channels = {#define ES83xx_12288_KHZ_MCLK_FREQ (48000 * 256)#define ES83xx_48_MHZ_MCLK_FREQ (48000 * 1000) +#define ES83XX_AMP_ON_DELAY_MS 50 +static int acp3x_es83xx_headphone_power_event (struct snd_soc_dapm_widget *w,struct snd_kcontrol *kcontrol,int event); static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w,
@@ -115,7 +118,7 @@ static struct snd_soc_jack_pin es83xx_jack_pins[] = { };static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = { -SND_SOC_DAPM_SPK ("Speaker" ,NULL ), +SND_SOC_DAPM_SPK ("Speaker" , acp3x_es83xx_speaker_power_event),SND_SOC_DAPM_HP ("Headphone" ,NULL ),SND_SOC_DAPM_MIC ("Headset Mic" ,NULL ),SND_SOC_DAPM_MIC ("Internal Mic" ,NULL ),
@@ -123,9 +126,6 @@ static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = {SND_SOC_DAPM_SUPPLY ("Headphone Power" ,SND_SOC_NOPM ,0 ,0 , acp3x_es83xx_headphone_power_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), -SND_SOC_DAPM_SUPPLY ("Speaker Power" ,SND_SOC_NOPM ,0 ,0 , - acp3x_es83xx_speaker_power_event, - SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), };static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = {
@@ -139,7 +139,6 @@ static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = {*/ {"Speaker", NULL, "HPOL"}, {"Speaker", NULL, "HPOR"}, - {"Speaker", NULL, "Speaker Power"}, };
@@ -185,10 +184,13 @@ static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w,struct acp3x_es83xx_private *priv =get_mach_priv (w->dapm->card);dev_dbg (priv->codec_dev,"speaker power event: %d\n" , event); -if (SND_SOC_DAPM_EVENT_ON (event)) +if (SND_SOC_DAPM_EVENT_ON (event)) { +/* Let the codec output settle before enabling the amplifier */ +msleep (ES83XX_AMP_ON_DELAY_MS ); priv->speaker_on = true; -else + }else { priv->speaker_on = false; + }gpiod_set_value_cansleep (priv->gpio_speakers, priv->speaker_on);gpiod_set_value_cansleep (priv->gpio_headphone, priv->headphone_on);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 365/990 btrfs: zoned: only change active zone counter on successful (de)activation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 5e79f39fbeea78703ac389c67a810406fa09bc94 ]
btrfs_zone_activate() unconditionally decrements the reserved_active_zones counter regardless if btrfs_dev_set_active_zone() fails to set the zone active, i.e. because it raced with another call that already set the bit in the bitmask, or not.
This can lead to a double decrement of the counter in case the bit has already been set.
Only decrement the counter *iff* btrfs_dev_set_active_zone() successfully marked the zone in the bitmap.
Mirror this behaviour when clearing the bit again.
--- fs/btrfs/zoned.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
fs/btrfs/zoned.c +18 -8
@@ -1126,11 +1126,13 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,return pos; } -static bool btrfs_dev_set_active_zone (struct btrfs_device *device,u64 pos) +static bool btrfs_dev_set_active_zone (struct btrfs_device *device,u64 pos,bool *new) {struct btrfs_zoned_device_info *zone_info = device->zone_info;unsigned int zno = (pos >> zone_info->zone_size_shift); + *new = false; +/* We can use any number of zones */ if (zone_info->max_active_zones ==0 )return true;
@@ -1142,23 +1144,29 @@ static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos)if (test_and_set_bit (zno, zone_info->active_zones)) {/* Someone already set the bit */ atomic_inc (&zone_info->active_zones_left); + }else { + *new = true; } }return true; } -static void btrfs_dev_clear_active_zone (struct btrfs_device *device,u64 pos) +static bool btrfs_dev_clear_active_zone (struct btrfs_device *device,u64 pos) {struct btrfs_zoned_device_info *zone_info = device->zone_info;unsigned int zno = (pos >> zone_info->zone_size_shift);/* We can use any number of zones */ if (zone_info->max_active_zones ==0 ) -return ; +return false; -if (test_and_clear_bit (zno, zone_info->active_zones)) +if (test_and_clear_bit (zno, zone_info->active_zones)) {atomic_inc (&zone_info->active_zones_left); +return true; + } + +return false; } int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical,
@@ -2384,6 +2392,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)u64 physical;const bool is_data = (block_group->flags &BTRFS_BLOCK_GROUP_DATA );bool ret; +bool new;int i;if (!btrfs_is_zoned (block_group->fs_info))
@@ -2434,12 +2443,12 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) goto out_unlock; } -if (!btrfs_dev_set_active_zone (device, physical)) { +if (!btrfs_dev_set_active_zone (device, physical, &new)) {/* Cannot activate the zone */ ret = false; goto out_unlock; } -if (!is_data) +if (!is_data && new) zinfo->reserved_active_zones--; }
@@ -2486,6 +2495,7 @@ static int call_zone_finish(struct btrfs_block_group *block_group,struct btrfs_device *device = stripe->dev;const u64 physical = stripe->physical;struct btrfs_zoned_device_info *zinfo = device->zone_info; +bool cleared;int ret;if (!device->bdev)
@@ -2507,9 +2517,9 @@ static int call_zone_finish(struct btrfs_block_group *block_group,return ret; } -if (!(block_group->flags &BTRFS_BLOCK_GROUP_DATA )) + cleared =btrfs_dev_clear_active_zone (device, physical); +if (!(block_group->flags &BTRFS_BLOCK_GROUP_DATA ) && cleared) zinfo->reserved_active_zones++; -btrfs_dev_clear_active_zone (device, physical);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/990 btrfs: zoned: fix possible UAF in wait_eb_writebacks()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 8ca411c7ad2c02ae65ae208a3f7483d6e0159c4f ]
wait_eb_writebacks() iterates the fs_info->buffer_tree xarray and waits for the writeback of these extent-buffers. Waiting for writeback needs to be done without the rcu_read_lock() held (because it can sleep) and thus the loop drops the rcu_read_lock() before calling into wait_on_extent_buffer_writeback(). But extent_buffers are freed through RCU, so if btrfs_release_extent_buffer_rcu() is scheduled while we're still waiting on the writeback, the extent_buffer will be freed causing a use-after-free.
Similar to what is done in find_extent_buffer_nolock(), get a reference to the extent_buffer before calling into wait_on_extent_buffer_writeback() so a successful writeback does not free the extent_buffer while we still have a reference to it.
--- fs/btrfs/zoned.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/btrfs/zoned.c +8 -0
@@ -2482,8 +2482,16 @@ static void wait_eb_writebacks(struct btrfs_block_group *block_group)continue ;if (eb->start >= end)break ; +/* +* Skip if we can't get the refcount for the extent buffer, +* i.e. because it was already written back. Otherwise an eb +* disappering underneath us can cause a use-after-free. +*/ +if (!refcount_inc_not_zero (&eb->refs)) +continue ;rcu_read_unlock ();wait_on_extent_buffer_writeback (eb); +free_extent_buffer (eb);rcu_read_lock (); }rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/990 btrfs: zoned: requeue block group if zone reset bails out
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit c5f878eefdd4f559422a68bf49b6f59e7c10e70e ]
btrfs_reset_unused_block_groups() drops the block-group from fs_info->unused_bgs before performing the work that can actually fail, the actual submission of a REQ_OP_ZONE_RESET.
Every failed operation after this leaves the block-group dangling, physically reset, but the in-memory structures aren't and it is not requeued to be reset on fs_info->unused_bgs.
Instead of bailing out, re-add this block-group to fs_info->unused_bgs list.
--- fs/btrfs/zoned.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/btrfs/zoned.c +22 -6
@@ -3107,6 +3107,8 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num {struct btrfs_fs_info *fs_info = space_info->fs_info;const sector_t zone_size_sectors = fs_info->zone_size >>SECTOR_SHIFT ; +LIST_HEAD (retry_list); +int ret =0 ;if (!btrfs_is_zoned (fs_info))return 0 ;
@@ -3148,11 +3150,10 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num }if (!found) {spin_unlock (&fs_info->unused_bgs_lock); -return 0 ; + goto out; }list_del_init (&bg->bg_list); -btrfs_put_block_group (bg);spin_unlock (&fs_info->unused_bgs_lock);/*
@@ -3166,7 +3167,6 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numfor (int i =0 ; i < map->num_stripes; i++) {struct btrfs_io_stripe *stripe = &map->stripes[i];unsigned int nofs_flags; -int ret; nofs_flags =memalloc_nofs_save (); ret = blkdev_zone_mgmt(stripe->dev->bdev, REQ_OP_ZONE_RESET,
@@ -3176,7 +3176,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numif (ret) {up_read (&fs_info->dev_replace.rwsem); -return ret; + goto requeue; } }up_read (&fs_info->dev_replace.rwsem);
@@ -3187,7 +3187,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numif (bg->ro) {spin_unlock (&bg->lock);spin_unlock (&space_info->lock); -continue ; + goto requeue; } reclaimed = bg->alloc_offset;
@@ -3215,10 +3215,26 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numbtrfs_return_free_space (space_info, reclaimed);spin_unlock (&space_info->lock); +btrfs_put_block_group (bg); +if (num_bytes <= reclaimed)break ; num_bytes -= reclaimed; +continue ; + +requeue: +list_add_tail (&bg->bg_list, &retry_list); + +if (ret) + goto out; } -return 0 ; +out: +if (!list_empty (&retry_list)) { +spin_lock (&fs_info->unused_bgs_lock); +list_splice_tail (&retry_list, &fs_info->unused_bgs); +spin_unlock (&fs_info->unused_bgs_lock); + } + +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/990 btrfs: zoned: dont wait for ordered extents in do_zone_finish()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit bcad7df05237382237ad1517411721d839174009 ]
do_zone_finish() calls btrfs_wait_ordered_roots(), which holds fs_info->ordered_operations_mutex while waiting for writeback. It can be reached from writeback itself:
cow_file_range()
`-> btrfs_reserve_extent()
`-> find_free_extent()
`-> btrfs_zone_finish_one_bg()
`-> do_zone_finish()If another task holds the mutex and waits for that writeback, this deadlocks.
In general, we want to ensure all writes in the block group to complete before finishing the zone, as relocation does. However, the current callers do not need the wait (or cannot wait) in do_zone_finish():
- Relocation already waits for reservations and ordered extents itself before calling btrfs_zone_finish().
- btrfs_delete_unused_bgs() checks that ->reserved is zero and sets the block group read-only while holding groups_sem, so there can be no in-flight data write.
- btrfs_zone_finish_one_bg() is called from the allocation path and cannot wait.
Dropping the wait is still safe. Once the block group is read-only, ->reserved can only drop, and for data it only drops after the ordered extent's I/O has completed. So if ->reserved is zero, no data write is left in flight. If it is non-zero, do_zone_finish() returns -EAGAIN, which all callers handle.
This makes btrfs_zone_finish_one_bg() fail with -EAGAIN when it races with an allocation in the selected block group.
--- fs/btrfs/zoned.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/zoned.c +4 -3
@@ -2575,9 +2575,10 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ/* Ensure all writes in this block group finish */ btrfs_wait_block_group_reservations (block_group); -/* No need to wait for NOCOW writers. Zoned mode does not allow that */ -btrfs_wait_ordered_roots (fs_info,U64_MAX , block_group); -/* Wait for extent buffers to be written. */ +/* +* No need to wait for NOCOW writers, as zoned mode does not +* allow that, only wait for extent buffers to be written. +*/ if (is_metadata)wait_eb_writebacks (block_group);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/990 btrfs: zoned: fix lockdep splat on mount
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 04df03585f0d8ef2727e043119bba2cdfac2d8d7 ]
When mounting a filesystem on a zoned drive passed into a VM via a virtio-blk disk lockdep sporadically complains about a possible deadlock between BTRFS' dev_replace::rwsem and virtio-blk's vdev_mutex:
======================================================
WARNING: possible circular locking dependency detected
7.3.0-rc6+ #317 Not tainted
------------------------------------------------------
mount/7418 is trying to acquire lock:
ffff888102c07860 (&vblk->vdev_mutex){+.+.}-{4:4}, at: virtblk_report_zones+0xda/0x440
but task is already holding lock:
ffff8881fd725ea8 (&fs_info->dev_replace.rwsem){++++}-{4:4}, at: btrfs_load_block_group_zone_info+0x186/0xe50
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #4 (&fs_info->dev_replace.rwsem){++++}-{4:4}:
down_read+0x42/0x170
btrfs_map_block+0x1a6/0xe70
btrfs_submit_bbio+0x1a3/0x910
submit_one_bio+0x93/0xd0
btrfs_readahead+0x1c4/0x200
read_pages+0x56/0x200
page_cache_ra_order+0x27c/0x410
filemap_get_pages+0x12f/0x4a0
filemap_read+0xed/0x400
vfs_read+0x240/0x340
ksys_read+0x61/0xd0
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e-> #3 (mapping.invalidate_lock#3){++++}-{4:4}:
down_read+0x42/0x170
filemap_fault+0xb0/0x1a40
__do_fault+0x34/0xc0
__handle_mm_fault+0x919/0x1db0
handle_mm_fault+0x97/0x240
do_user_addr_fault+0x21d/0x690
exc_page_fault+0x8e/0x230
asm_exc_page_fault+0x26/0x30-> #2 (vm_lock){++++}-{0:0}:
__vma_start_exclude_readers+0x91/0x1b0
__vma_start_write+0x47/0xd0
vma_expand+0x4c/0x2a0
relocate_vma_down+0x126/0x200
setup_arg_pages+0x240/0x3e0
load_elf_binary+0x1be/0x1860
bprm_execve+0x2d2/0x7b0
kernel_execve+0x107/0x130
kernel_init+0xc2/0x130
ret_from_fork+0x1ff/0x2f0
ret_from_fork_asm+0x1a/0x30-> #1 (&mm->mmap_lock){++++}-{4:4}:
__might_fault+0x68/0xa0
_copy_to_user+0x22/0x70
blkdev_copy_zone_to_user+0x22/0x40
virtblk_report_zones+0x297/0x440
blkdev_report_zones_ioctl+0xfd/0x130
blkdev_ioctl+0x20f/0x2c0
__x64_sys_ioctl+0x86/0xd0
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e-> #0 (&vblk->vdev_mutex){+.+.}-{4:4}:
__lock_acquire+0x15a8/0x2850
lock_acquire+0xea/0x2f0
__mutex_lock+0xa7/0x10d0
virtblk_report_zones+0xda/0x440
blkdev_report_zones_cached+0x162/0x190
btrfs_get_dev_zones+0xdc/0x2c0
btrfs_load_block_group_zone_info+0x2b6/0xe50
btrfs_read_block_groups+0x338/0xc80
open_ctree+0x1aca/0x24b3
btrfs_get_tree.cold+0x105/0x26c
vfs_get_tree+0x28/0xb0
__do_sys_fsconfig+0x324/0x690
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7eother info that might help us debug this:
Chain exists of: &vblk->vdev_mutex --> mapping.invalidate_lock#3 --> &fs_info->dev_replace.rwsem Possible unsafe locking scenario:
CPU0 CPU1
---- ----
rlock(&fs_info->dev_replace.rwsem);
lock(mapping.invalidate_lock#3);
lock(&fs_info->dev_replace.rwsem); lock(&vblk->vdev_mutex);
*** DEADLOCK ***
locks held by mount/7418: 3, last CPU#0:
#0: ffff888110aa6868 (&fc->uapi_mutex){+.+.}-{4:4}, at: __do_sys_fsconfig+0x2ae/0x690
#1: ffff888112ba20e8 (&type->s_umount_key#31/1){+.+.}-{4:4}, at: sget_fc+0x148/0x8d0
#2: ffff8881fd725ea8 (&fs_info->dev_replace.rwsem){++++}-{4:4}, at: btrfs_load_block_group_zone_info+0x186/0xe50
Holding the rwsem was widened in 0090d6e1b210 ("btrfs: zoned: fix use-after-free due to race with dev replace"), but it now also covers calling into blkdev_report_zones_cached(). The device replace ioctl() only works on a mounted filesystem and the only caller with setting 'new' to false is read_one_block_group() which is only called during mount, so it is safe to drop the rwsem before calling into blkdev_report_zones_cached().
--- fs/btrfs/zoned.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +3 -4
@@ -1378,11 +1378,13 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,return 0 ; } +ASSERT (!test_bit (BTRFS_FS_OPEN , &fs_info->flags)); +up_read (&dev_replace->rwsem); + nofs_flag =memalloc_nofs_save (); ret =btrfs_get_dev_zone (device, info->physical, &zone);memalloc_nofs_restore (nofs_flag);if (ret) { -up_read (&dev_replace->rwsem);if (ret != -EIO && ret != -EOPNOTSUPP )return ret; info->alloc_offset =WP_MISSING_DEV ;
@@ -1394,7 +1396,6 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,"zoned: unexpected conventional zone %llu on device %s (devid %llu)" , zone.start <<SECTOR_SHIFT ,rcu_dereference (device->name), device->devid); -up_read (&dev_replace->rwsem);return -EIO ; }
@@ -1422,8 +1423,6 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,break ; } -up_read (&dev_replace->rwsem); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/990 btrfs: zstd: prevent leak of workspace below maximum level
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit bb66a38f5812f2c04abd4eb6e586a12b5a95172a ]
When putting a workspace we always protect the workspace for the maximum level from reclaim, since it can be used not just for that level but as well for any level below it. However the logic is flawed because if we do the put for a workspace at level 10 for example (maximum is level 15) and there is currently no idle workspace for the maximum level because all are currently being used, we don't add the workspace to the LRU list and that can result in leaking it if we don't get more compression or decompression requests for level 10 or any level below 10.
Fix this by skipping the addition to the LRU list only if the level of the workspace matches the maximum level too (besides the list of idle workspaces for the maximum level being empty).
--- fs/btrfs/zstd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/zstd.c +2 -1
@@ -347,7 +347,8 @@ void zstd_put_workspace(struct btrfs_fs_info *fs_info, struct list_head *ws)/* A node is only taken off the lru if we are the corresponding level */ if (clip_level (workspace->req_level) == workspace->level) {/* Hide a max level workspace from reclaim */ -if (list_empty (&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL -1 ])) { +if (workspace->level ==ZSTD_BTRFS_MAX_LEVEL -1 && +list_empty (&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL -1 ])) {INIT_LIST_HEAD (&workspace->lru_list); }else { workspace->last_used = jiffies;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/990 btrfs: handle zero num_stripes in btrfs_chunk_item_size()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Yongkang <[email protected]>
[ Upstream commit 8416012aa6e794a6464e073ab236f4ff862935ac ]
validate_sys_chunk_array() calls btrfs_chunk_item_size() with the on-disk num_stripes before btrfs_check_chunk_valid() has checked the chunk. With CONFIG_BTRFS_ASSERT=y, a zero-stripe system chunk trips ASSERT(num_stripes) instead of being rejected:
assertion failed: num_stripes, in fs/btrfs/volumes.h:714 kernel BUG at fs/btrfs/volumes.h:714!
RIP: 0010:btrfs_validate_super+0x3ce7/0x4210 Call Trace: open_ctree btrfs_get_tree vfs_get_tree do_new_mount
Drop the assertion and compute the size as the chunk header plus num_stripes stripes. The size is unchanged for num_stripes > 0, and a zero-stripe chunk now reaches btrfs_check_chunk_valid(), which rejects it, so the mount fails with -EUCLEAN.
--- fs/btrfs/volumes.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/volumes.h +2 -3
@@ -712,9 +712,8 @@ static inline enum btrfs_map_op btrfs_op(const struct bio *bio)static inline unsigned long btrfs_chunk_item_size (int num_stripes) { -ASSERT (num_stripes); -return sizeof (struct btrfs_chunk ) + -sizeof (struct btrfs_stripe ) * (num_stripes -1 ); +return offsetof(struct btrfs_chunk , stripe) + +sizeof (struct btrfs_stripe ) * num_stripes; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/990 tcp: try to avoid safer when ACKs are thinned
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilpo Järvinen <[email protected]>
[ Upstream commit 7885ce0147401d5f6908ad4da660334031d836b7 ]
Add newly acked pkts EWMA. When ACK thinning occurs, select between safer and unsafe cep delta in AccECN processing based on it. If the packets ACKed per ACK tends to be large, don't conservatively assume ACE field overflow.
This patch uses the existing 2-byte holes in the rx group for new u16 variables withtout creating more holes. Below are the pahole outcomes before and after this patch:
[BEFORE THIS PATCH]
struct tcp_sock {
[...]
u32 delivered_ecn_bytes[3]; /* 2744 12 */
/* XXX 4 bytes hole, try to pack */
[...]
__cacheline_group_end__tcp_sock_write_rx[0]; /* 2816 0 */
[...]
/* size: 3264, cachelines: 51, members: 177 */
}[AFTER THIS PATCH]
struct tcp_sock {
[...]
u32 delivered_ecn_bytes[3]; /* 2744 12 */
u16 pkts_acked_ewma; /* 2756 2 */
/* XXX 2 bytes hole, try to pack */
[...]
__cacheline_group_end__tcp_sock_write_rx[0]; /* 2816 0 */
[...]
/* size: 3264, cachelines: 51, members: 178 */
}Stable-dep-of: c2213d9b61c1 ("tcp: rate limit receive queue collapsing")
--- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 1 + net/ipv4/tcp.c | 2 ++ net/ipv4/tcp_input.c | 20 ++++++++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -0
@@ -105,6 +105,7 @@ u32 received_ce read_mostly read_w u32[3] received_ecn_bytes read_mostly read_write u8:4 received_ce_pending read_mostly read_write u32[3] delivered_ecn_bytes read_write +u16 pkts_acked_ewma read_write u8:2 syn_ect_snt write_mostly read_write u8:2 syn_ect_rcv read_mostly read_write u8:2 accecn_minlen write_mostly read_write
include/linux/tcp.h +1 -0
@@ -348,6 +348,7 @@ struct tcp_sock {u32 rate_interval_us;/* saved rate sample: time elapsed */ u32 rcv_rtt_last_tsecr;u32 delivered_ecn_bytes[3 ]; +u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ u64 first_tx_mstamp;/* start of window send phase */ u64 delivered_mstamp;/* time we reached "delivered" */ u64 bytes_acked;/* RFC4898 tcpEStatsAppHCThruOctetsAcked
net/ipv4/tcp.c +2 -0
@@ -3426,6 +3426,7 @@ int tcp_disconnect(struct sock *sk, int flags)tcp_accecn_init_counters (tp); tp->prev_ecnfield =0 ; tp->accecn_opt_tstamp =0 ; + tp->pkts_acked_ewma =0 ;if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release) icsk->icsk_ca_ops->release (sk);memset (icsk->icsk_ca_priv,0 ,sizeof (icsk->icsk_ca_priv));
@@ -5243,6 +5244,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rate_interval_us); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_last_tsecr); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_ecn_bytes); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, pkts_acked_ewma); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, first_tx_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_acked);
net/ipv4/tcp_input.c +19 -1
@@ -489,6 +489,10 @@ static void tcp_count_delivered(struct tcp_sock *tp, u32 delivered,tcp_count_delivered_ce (tp, delivered); } +#define PKTS_ACKED_WEIGHT 6 +#define PKTS_ACKED_PREC 6 +#define ACK_COMP_THRESH 4 +/* Returns the ECN CE delta */ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, u32 delivered_pkts, u32 delivered_bytes,
@@ -500,6 +504,7 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,u32 delta, safe_delta, d_ceb;bool opt_deltas_valid;u32 corrected_ace; +u32 ewma;/* Reordered ACK or uncertain due to lack of data to send and ts */ if (!(flag & (FLAG_FORWARD_PROGRESS |FLAG_TS_PROGRESS )))
@@ -508,6 +513,18 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, opt_deltas_valid =tcp_accecn_process_option (tp, skb, delivered_bytes, flag); +if (delivered_pkts) { +if (!tp->pkts_acked_ewma) { + ewma = delivered_pkts <<PKTS_ACKED_PREC ; + }else { + ewma = tp->pkts_acked_ewma; + ewma = (((ewma <<PKTS_ACKED_WEIGHT ) - ewma) + + (delivered_pkts <<PKTS_ACKED_PREC )) >> +PKTS_ACKED_WEIGHT ; + } + tp->pkts_acked_ewma =min_t (u32, ewma,0xFFFFU ); + } +if (!(flag &FLAG_SLOWPATH )) {/* AccECN counter might overflow on large ACKs */ if (delivered_pkts <=TCP_ACCECN_CEP_ACE_MASK )
@@ -556,7 +573,8 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,if (d_ceb < safe_delta * tp->mss_cache >>TCP_ACCECN_SAFETY_SHIFT )return delta; - } + }else if (tp->pkts_acked_ewma > (ACK_COMP_THRESH <<PKTS_ACKED_PREC )) +return delta;return safe_delta; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/990 tcp: move tp->delivered and tp->delivered_ce to tcp_sock_write_tx group
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 9f810527a343fd72671fe7661ebb3694396f45ed ]
These counters are changed whenever sent data is acknowleged.
They do not belong to tcp_sock_write_txrx group, because TCP receivers do not touch them.
Stable-dep-of: c2213d9b61c1 ("tcp: rate limit receive queue collapsing")
--- Documentation/networking/net_cachelines/tcp_sock.rst | 4 ++-- include/linux/tcp.h | 4 ++-- net/ipv4/tcp.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +2 -2
@@ -99,8 +99,8 @@ u32 snd_cwnd_stamp u32 prior_cwnd u32 prr_delivered u32 prr_out read_mostly read_mostly tcp_rate_skb_sent,tcp_newly_delivered(tx);tcp_ack,tcp_rate_gen,tcp_clean_rtx_queue(rx) -u32 delivered read_mostly read_write tcp_rate_skb_sent, tcp_newly_delivered(tx);tcp_ack, tcp_rate_gen, tcp_clean_rtx_queue (rx) -u32 delivered_ce read_mostly read_write tcp_rate_skb_sent(tx);tcp_rate_gen(rx) +u32 delivered read_write tcp_rate_skb_sent, tcp_newly_delivered(tx);tcp_ack, tcp_rate_gen, tcp_clean_rtx_queue (rx) +u32 delivered_ce read_write tcp_rate_skb_sent(tx);tcp_rate_gen(rx) u32 received_ce read_mostly read_write u32[3] received_ecn_bytes read_mostly read_write u8:4 received_ce_pending read_mostly read_write
include/linux/tcp.h +2 -2
@@ -265,6 +265,8 @@ struct tcp_sock {u32 data_segs_out;/* RFC4898 tcpEStatsPerfDataSegsOut * total number of data segments sent. */ +u32 delivered;/* Total data packets delivered incl. rexmits */ +u32 delivered_ce;/* Like the above but only ECE marked packets */ u64 bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut * total number of data bytes sent. */
@@ -312,8 +314,6 @@ struct tcp_sock {u32 srtt_us;/* smoothed round trip time << 3 in usecs */ u32 packets_out;/* Packets which are "in flight" */ u32 snd_up;/* Urgent pointer */ -u32 delivered;/* Total data packets delivered incl. rexmits */ -u32 delivered_ce;/* Like the above but only ECE marked packets */ u32 received_ce;/* Like the above but for rcvd CE marked pkts */ u32 received_ecn_bytes[3 ];/* received byte counters for three ECN * types: INET_ECN_ECT_1, INET_ECN_ECT_0,
net/ipv4/tcp.c +2 -2
@@ -5198,6 +5198,8 @@ static void __init tcp_struct_check(void)/* TX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, segs_out); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, data_segs_out); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, bytes_sent); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, snd_sml); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, chrono_start);
@@ -5224,8 +5226,6 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, srtt_us); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, packets_out); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, snd_up); - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered); - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/990 tcp: move tp->segs_in and tp->segs_out to tcp_sock_write_txrx group
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 2b28dd212a8ad67b100137626a3d008b1e40a740 ]
segs_in is changed for each incoming packet, including ACK packets. segs_out is changed for each outgoing packet, including ACK packets.
They belong to tcp_sock_write_txrx group.
Stable-dep-of: c2213d9b61c1 ("tcp: rate limit receive queue collapsing")
--- .../networking/net_cachelines/tcp_sock.rst | 4 ++-- include/linux/tcp.h | 18 +++++++++--------- net/ipv4/tcp.c | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +2 -2
@@ -13,13 +13,13 @@ u16 tcp_header_len read_mostly read_m u16 gso_segs read_mostly tcp_xmit_size_goal __be32 pred_flags read_write read_mostly tcp_select_window(tx);tcp_rcv_established(rx) u64 bytes_received read_write tcp_rcv_nxt_update(rx) -u32 segs_in read_write tcp_v6_rcv(rx) +u32 segs_in read_write read_write tcp_segs_in(),tcp_v6_rcv(rx),tcp_v4_rcv() u32 data_segs_in read_write tcp_v6_rcv(rx) u32 rcv_nxt read_mostly read_write tcp_cleanup_rbuf,tcp_send_ack,tcp_inq_hint,tcp_transmit_skb,tcp_receive_window(tx);tcp_v6_do_rcv,tcp_rcv_established,tcp_data_queue,tcp_receive_window,tcp_rcv_nxt_update(write)(rx) u32 copied_seq read_mostly tcp_cleanup_rbuf,tcp_rcv_space_adjust,tcp_inq_hint u32 rcv_wup read_write __tcp_cleanup_rbuf,tcp_receive_window,tcp_receive_established u32 snd_nxt read_write read_mostly tcp_rate_check_app_limited,__tcp_transmit_skb,tcp_event_new_data_sent(write)(tx);tcp_rcv_established,tcp_ack,tcp_clean_rtx_queue(rx) -u32 segs_out read_write __tcp_transmit_skb +u32 segs_out read_write read_write __tcp_transmit_skb u32 data_segs_out read_write __tcp_transmit_skb,tcp_update_skb_after_send u64 bytes_sent read_write __tcp_transmit_skb u64 bytes_acked read_write tcp_snd_una_update/tcp_ack
include/linux/tcp.h +9 -9
@@ -259,17 +259,14 @@ struct tcp_sock {/* TX read-write hotpath cache lines */ __cacheline_group_begin (tcp_sock_write_tx)____cacheline_aligned ; -u32 segs_out;/* RFC4898 tcpEStatsPerfSegsOut -* The total number of segments sent. -*/ -u32 data_segs_out;/* RFC4898 tcpEStatsPerfDataSegsOut -* total number of data segments sent. -*/ u32 delivered;/* Total data packets delivered incl. rexmits */ u32 delivered_ce;/* Like the above but only ECE marked packets */ u64 bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut * total number of data bytes sent. */ +u32 data_segs_out;/* RFC4898 tcpEStatsPerfDataSegsOut +* total number of data segments sent. +*/ u32 snd_sml;/* Last byte of the most recently transmitted small packet */ u8 chrono_type;/* current chronograph type */ u32 chrono_start;/* Start time in jiffies of a TCP chrono */
@@ -326,6 +323,12 @@ struct tcp_sock {* Options received (usually on last packet, some only on SYN packets). */ struct tcp_options_received rx_opt; +u32 segs_in;/* RFC4898 tcpEStatsPerfSegsIn +* total number of segments in. +*/ +u32 segs_out;/* RFC4898 tcpEStatsPerfSegsOut +* The total number of segments sent. +*/ __cacheline_group_end (tcp_sock_write_txrx);/* RX read-write hotpath cache lines */
@@ -335,9 +338,6 @@ struct tcp_sock {* sum(delta(rcv_nxt)), or how many bytes * were acked. */ -u32 segs_in;/* RFC4898 tcpEStatsPerfSegsIn -* total number of segments in. -*/ u32 data_segs_in;/* RFC4898 tcpEStatsPerfDataSegsIn * total number of data segments in. */
net/ipv4/tcp.c +2 -2
@@ -5196,7 +5196,6 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_rx, snd_ssthresh);/* TX read-write hotpath cache lines */ - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, segs_out); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, data_segs_out); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_ce);
@@ -5232,10 +5231,11 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_tstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rx_opt); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, segs_in); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, segs_out);/* RX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_received); - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, segs_in); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, data_segs_in); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_wup); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, max_packets_out);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/990 tcp: move tp->first_tx_mstamp and tp->delivered_mstamp to tcp_sock_write_tx
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 07db42c4b3eb60a21645ad88211b69933eab0a03 ]
These fields are touched in when payload is sent.
Stable-dep-of: c2213d9b61c1 ("tcp: rate limit receive queue collapsing")
--- include/linux/tcp.h | 4 ++-- net/ipv4/tcp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/tcp.h +2 -2
@@ -264,6 +264,8 @@ struct tcp_sock {u64 bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut * total number of data bytes sent. */ +u64 first_tx_mstamp;/* start of window send phase */ +u64 delivered_mstamp;/* time we reached "delivered" */ u32 data_segs_out;/* RFC4898 tcpEStatsPerfDataSegsOut * total number of data segments sent. */
@@ -349,8 +351,6 @@ struct tcp_sock {u32 rcv_rtt_last_tsecr;u32 delivered_ecn_bytes[3 ];u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ -u64 first_tx_mstamp;/* start of window send phase */ -u64 delivered_mstamp;/* time we reached "delivered" */ u64 bytes_acked;/* RFC4898 tcpEStatsAppHCThruOctetsAcked * sum(delta(snd_una)), or how many bytes * were acked.
net/ipv4/tcp.c +2 -2
@@ -5200,6 +5200,8 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, bytes_sent); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, first_tx_mstamp); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, snd_sml); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, chrono_start); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, chrono_stat);
@@ -5245,8 +5247,6 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_last_tsecr); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, pkts_acked_ewma); - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, first_tx_mstamp); - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_acked); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/990 tcp: move tp->bytes_acked to tcp_sock_write_tx group
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit dd033ec406b4d9eade3e0fd998ec9bfa50db42ba ]
tp->bytes_acked is touched in TX path only.
Stable-dep-of: c2213d9b61c1 ("tcp: rate limit receive queue collapsing")
--- Documentation/networking/net_cachelines/tcp_sock.rst | 2 +- include/linux/tcp.h | 8 ++++---- net/ipv4/tcp.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -1
@@ -22,7 +22,7 @@ u32 snd_nxt read_write read_m u32 segs_out read_write read_write __tcp_transmit_skb u32 data_segs_out read_write __tcp_transmit_skb,tcp_update_skb_after_send u64 bytes_sent read_write __tcp_transmit_skb -u64 bytes_acked read_write tcp_snd_una_update/tcp_ack +u64 bytes_acked read_write tcp_snd_una_update/tcp_ack u32 dsack_dups u32 snd_una read_mostly read_write tcp_wnd_end,tcp_urg_mode,tcp_minshall_check,tcp_cwnd_validate(tx);tcp_ack,tcp_may_update_window,tcp_clean_rtx_queue(write),tcp_ack_tstamp(rx) u32 snd_sml read_write tcp_minshall_check,tcp_minshall_update
include/linux/tcp.h +4 -4
@@ -261,6 +261,10 @@ struct tcp_sock {__cacheline_group_begin (tcp_sock_write_tx)____cacheline_aligned ;u32 delivered;/* Total data packets delivered incl. rexmits */ u32 delivered_ce;/* Like the above but only ECE marked packets */ +u64 bytes_acked;/* RFC4898 tcpEStatsAppHCThruOctetsAcked +* sum(delta(snd_una)), or how many bytes +* were acked. +*/ u64 bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut * total number of data bytes sent. */
@@ -351,10 +355,6 @@ struct tcp_sock {u32 rcv_rtt_last_tsecr;u32 delivered_ecn_bytes[3 ];u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ -u64 bytes_acked;/* RFC4898 tcpEStatsAppHCThruOctetsAcked -* sum(delta(snd_una)), or how many bytes -* were acked. -*/ struct {u32 rtt_us;u32 seq;
net/ipv4/tcp.c +1 -1
@@ -5199,6 +5199,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, data_segs_out); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_ce); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, bytes_acked); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, bytes_sent); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, first_tx_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_mstamp);
@@ -5247,7 +5248,6 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_last_tsecr); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, pkts_acked_ewma); - CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_acked); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/990 tcp: rate limit receive queue collapsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c2213d9b61c1d6e99645a636630ee767c7542f78 ]
When a socket is over its receive buffer limit and its sk_rcvbuf can not grow, every incoming segment that needs memory goes through tcp_prune_queue(), which runs tcp_collapse_ofo_queue() and tcp_collapse() on the receive queue. Both walk their whole queue, even when there is nothing left to collapse.
A peer can trigger this walk per packet, without refilling memory:
1) The segment lands last in the out-of-order queue. Since commit b0e01253a764 ("tcp: refine tcp_prune_ofo_queue() logic"), tcp_prune_ofo_queue() drops nothing, the segment is dropped and the queues are unchanged. The peer can send it again forever.
2) The segment lands second to last: one skb is pruned, and one small segment fills that space again.
3) The out-of-order queue is empty and the receive queue alone is over the limit (application not reading). Collapsing frees nothing, the out-of-order segment is dropped, and the window is not closed.
4) Collapsing frees just one skb, enough to queue the segment. The next segment is over the limit again.
Only allow a collapse if at least 1/8 of sk_rcvbuf of new memory was queued in the receive queues since the previous collapse. This restores the "12.5 % of the queue capacity" amortization of the 2018 SegmentSmack fixes (CVE-2018-5390), using the same unit as the sk_rcvbuf limit, so that peers sending small (bloated) segments are not penalized.
The credit is the net growth of sk_rmem_alloc in tcp_queue_rcv() and tcp_data_queue_ofo(), so that:
- Coalescing a segment into the tailroom of the previous skb charges no memory, and earns no credit.
- An out-of-order segment replacing or covering queued skbs only earns the memory it adds.
- Duplicates earn nothing.
- Data moved from the out-of-order queue to the receive queue (tcp_ofo_queue()) is not credited twice.
In-order data is credited too, so that a receive queue filled by bloated in-order segments can still be collapsed when a hole appears.
In-order segments are rate limited as well: a peer could otherwise send small in-order segments that each trigger a collapse freeing a single skb, enough to queue the segment, while the out-of-order queue holds many skbs that can not be collapsed.
The credit is tracked in a new u32 tp->rcv_collapse_credit, placed in a hole of the tcp_sock_write_rx group: no other field moves, and tcp_sock size is unchanged. tcp_queue_rcv() now samples sk_rmem_alloc, and writes the credit until it saturates at sk_rcvbuf, so that the fast path stops writing it after a full buffer of new memory. Saturating at the goal would not work: sk_rcvbuf, and the goal with it, can grow later (for instance in tcp_clamp_window(), just before the goal is checked), and a socket over its limit can not earn more credit until the application reads.
When collapsing is not allowed, tcp_prune_queue() goes directly to tcp_prune_ofo_queue(), which is cheap in the cases above.
A regular flow can see a difference when it goes over its limit before 1/8 of sk_rcvbuf of new memory was queued since the previous collapse:
out-of-order skbs can be pruned (even for an in-order segment filling a hole), and an in-order segment that still does not fit is dropped, with a zero window advertised, where a collapse might have made room.
--- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 1 + net/ipv4/tcp.c | 2 + net/ipv4/tcp_input.c | 55 +++++++++++++++---- 4 files changed, 48 insertions(+), 11 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -0
@@ -106,6 +106,7 @@ u32[3] received_ecn_bytes read_mostly read_w u8:4 received_ce_pending read_mostly read_write u32[3] delivered_ecn_bytes read_write u16 pkts_acked_ewma read_write +u32 rcv_collapse_credit read_write tcp_queue_rcv,tcp_data_queue_ofo,tcp_prune_queue u8:2 syn_ect_snt write_mostly read_write u8:2 syn_ect_rcv read_mostly read_write u8:2 accecn_minlen write_mostly read_write
include/linux/tcp.h +1 -0
@@ -355,6 +355,7 @@ struct tcp_sock {u32 rcv_rtt_last_tsecr;u32 delivered_ecn_bytes[3 ];u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ +u32 rcv_collapse_credit;/* memory queued since last collapse */ struct {u32 rtt_us;u32 seq;
net/ipv4/tcp.c +2 -0
@@ -3477,6 +3477,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->rx_opt.dsack =0 ; tp->rx_opt.num_sacks =0 ; tp->rcv_ooopack =0 ; + tp->rcv_collapse_credit =0 ;/* Clean up fastopen related fields */
@@ -5248,6 +5249,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_last_tsecr); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, pkts_acked_ewma); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_collapse_credit); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space); }
net/ipv4/tcp_input.c +44 -11
100 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/990 NFSv4.1: retain MDS I/O until both thresholds are met
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit eab627dcd18a18a44a2cbee47df3058d3637ba0d ]
When both size and I/O thresholds are configured, pnfs_within_mdsthreshold() uses size && io to decide whether to keep I/O on the MDS. Both variables indicate an unmet threshold, so reaching only one threshold returns false and may trigger pNFS layout acquisition while the other threshold remains unmet.
Use logical OR instead of AND to stay with MDS I/O until both thresholds are met, as recommended by RFC 8881 Section 5.12.6. The new RFC contains the same threshold selection rule as RFC 5661 which is referenced in function comment.
--- fs/nfs/pnfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/pnfs.c +1 -1
@@ -2059,7 +2059,7 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx,break ; }if (size_set && io_set) { -if (size && io) +if (size || io) ret = true; }else if (size || io) ret = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/990 NFS: honor UTIME_NOW atime with explicit mtime
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 2ffcf17d26dabef5793aeadf75a23c595a72be08 ]
When utimensat() requests UTIME_NOW for atime and an explicit mtime, the VFS sets ATTR_ATIME but not ATTR_ATIME_SET (as it should). The delegated explicit-mtime path calls nfs_set_timestamps_to_ts(), which skips atime, but nfs_setattr() then clears ATTR_ATIME, allowing the syscall to succeed without updating atime.
The delegated explicit-mtime path already updates ctime locally. The VFS also supplies the requested atime value in ia_atime, even when ATTR_ATIME_SET is absent.
Check ATTR_ATIME instead of ATTR_ATIME_SET to also apply the UTIME_NOW atime value supplied by the VFS.
--- fs/nfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/inode.c +1 -1
@@ -662,7 +662,7 @@ static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr)inode_maybe_inc_iversion (inode, updated); cache_flags |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ; } -if (attr->ia_valid &ATTR_ATIME_SET ) { +if (attr->ia_valid &ATTR_ATIME ) {inode_set_atime_to_ts (inode, attr->ia_atime); cache_flags |=NFS_INO_INVALID_ATIME ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/990 nfs: fix utimensat() for atime with delegated timestamps
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 16d99dce938ecbbc703843a31fb951acca46af27 ]
xfstest generic/221 is failing with delegated timestamps enabled. When the client holds a WRITE_ATTRS_DELEG delegation, and a userland process does a utimensat() for only the atime, the ctime is not properly updated. The problem is that the client tries to cache the atime update, but there is no mtime update, so the delegated attribute update never updates the ctime.
Delegated timestamps don't have a mechanism to update the ctime in accordance with atime-only changes due to utimensat() and the like. Change the client to issue an RPC in this case, so that the ctime gets properly updated alongside the atime.
Stable-dep-of: a38d7cc8c90f ("NFS: update ctime for atime-only UTIME_NOW requests")
--- fs/nfs/inode.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
fs/nfs/inode.c +1 -8
@@ -758,14 +758,7 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, }else if (nfs_have_delegated_atime (inode) && attr->ia_valid &ATTR_ATIME && !(attr->ia_valid &ATTR_MTIME )) { -if (attr->ia_valid &ATTR_ATIME_SET ) { -if (uid_eq (task_uid, owner_uid)) { -spin_lock (&inode->i_lock); -nfs_set_timestamps_to_ts (inode, attr); -spin_unlock (&inode->i_lock); - attr->ia_valid &= ~(ATTR_ATIME |ATTR_ATIME_SET ); - } - }else { +if (!(attr->ia_valid &ATTR_ATIME_SET )) {nfs_update_delegated_atime (inode); attr->ia_valid &= ~ATTR_ATIME ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/990 NFS: update ctime for atime-only UTIME_NOW requests
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit a38d7cc8c90f0d093550487c2905b51db0be1522 ]
When an NFS client holds a timestamp delegation, utimensat() with atime set to UTIME_NOW and mtime set to UTIME_OMIT reaches nfs_setattr() with ATTR_TIMES_SET but without ATTR_ATIME_SET.
There may be other paths that can reach here as well.
The delegated-atime fast path treats this as an implicit atime update, clears ATTR_ATIME and returns success without updating ctime.
Add check for ATTR_TIMES_SET along with ATTR_ATIME_SET (OR) so explicit timestamp requests use the normal SETATTR path while incidental atime updates can keep using the local shortcut.
--- fs/nfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/inode.c +1 -1
@@ -758,7 +758,7 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, }else if (nfs_have_delegated_atime (inode) && attr->ia_valid &ATTR_ATIME && !(attr->ia_valid &ATTR_MTIME )) { -if (!(attr->ia_valid &ATTR_ATIME_SET )) { +if (!(attr->ia_valid & (ATTR_ATIME_SET |ATTR_TIMES_SET ))) {nfs_update_delegated_atime (inode); attr->ia_valid &= ~ATTR_ATIME ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/990 NFS: Fix inverted cross-directory rename check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit b9d518902ff1969f93d2b4787951d98e50ab0181 ]
nfs_rename_is_unsafe_cross_dir() returns false for cross-directory renames, causing nfs_rename() to skip nfs_sync_inode() even when filehandles may expire on rename. Same-directory renames may instead trigger unnecessary synchronization.
Current condition directly contradicts the function name/comments.
Return false for same-directory renames so cross-directory renames reach the existing filehandle-volatility check. Keep the conservative fallback unchanged..
--- fs/nfs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/dir.c +1 -1
@@ -2687,7 +2687,7 @@ static bool nfs_rename_is_unsafe_cross_dir(struct dentry *old_dentry, {struct nfs_server *server =NFS_SB (old_dentry->d_sb); -if (old_dentry->d_parent != new_dentry->d_parent) +if (old_dentry->d_parent == new_dentry->d_parent)return false;if (server->fh_expire_type &NFS_FH_RENAME_UNSAFE )return !(server->fh_expire_type &NFS_FH_NOEXPIRE_WITH_OPEN );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/990 NFS: restore directory index when resuming readdir
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 89b91409b2342e7629b1271eba315a0f06495247 ]
nfs_readdir() restores the cached folio index and cookie when resuming directory iteration, but leaves current_index at zero. In 32-bit index mode, nfs_readdir_search_for_cookie() then reports a folio-relative offset instead of the absolute entry position.
Restore current_index from the saved logical folio index before searching the cache.
This solution relies on the current behavior of nfs_readdir_seek_next_array(), where folio_index advances by one and current_index advances by nfs_readdir_array_maxentries() for each full, nonterminal folio.
--- fs/nfs/dir.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfs/dir.c +2 -0
@@ -1255,6 +1255,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)spin_lock (&file->f_lock); desc->dir_cookie = dir_ctx->dir_cookie; desc->folio_index = dir_ctx->page_index; + desc->current_index = (loff_t )desc->folio_index * +nfs_readdir_array_maxentries (); desc->last_cookie = dir_ctx->last_cookie; desc->attr_gencount = dir_ctx->attr_gencount; desc->eof = dir_ctx->eof;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/990 SUNRPC: wake poll waiters when an empty pipe is unlinked
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 702d55edc017632a0c39c1d4bdd579bdbadfd730 ]
When an empty rpc_pipefs pipe is unlinked, rpc_purge_list() returns without waking the pipe wait queue. An existing epoll waiter can remain blocked even though rpc_pipe_poll() reports EPOLLHUP and EPOLLERR for the disconnected pipe.
Wake the wait queue after clearing RPC_I(inode)->pipe so existing poll waiters are notified regardless of whether messages were purged.
--- net/sunrpc/rpc_pipe.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/rpc_pipe.c +1 -0
@@ -191,6 +191,7 @@ rpc_close_pipes(struct dentry *dentry)cancel_delayed_work_sync (&pipe->queue_timeout);rpc_inode_setowner (inode,NULL );RPC_I (inode)->pipe =NULL ; +wake_up (&RPC_I (inode)->waitq);inode_unlock (inode); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/990 SUNRPC: preserve fatal network errors during RPC binding
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 30150b94c70eff4bf916d7d367ecf75de25d5337 ]
call_bind_status() initializes status to -EIO. When an unbound transport's port lookup fails with -ENETDOWN or -ENETUNREACH and RPC_TASK_NETUNREACH_FATAL is set, the function exits the switch without updating status. The RPC task then reports -EIO instead of the network error.
This can occur during NFSv3 port discovery with nconnect, when an additional transport has not yet bound.
Preserve task->tk_status in the fatal branch. Leave the nonfatal retry handling unchanged.
--- net/sunrpc/clnt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/clnt.c +3 -1
@@ -2125,8 +2125,10 @@ call_bind_status(struct rpc_task *task) goto retry_timeout;case -ENETDOWN :case -ENETUNREACH : -if (task->tk_flags &RPC_TASK_NETUNREACH_FATAL ) +if (task->tk_flags &RPC_TASK_NETUNREACH_FATAL ) { + status = task->tk_status;break ; + } fallthrough;case -ECONNREFUSED :/* connection problems */ case -ECONNRESET :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/990 SUNRPC: preserve timeout policy when cloning clients
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 5b0ac1f82201c2ab2d9c31ed568cc782bac6a399 ]
rpc_clone_client() and rpc_clone_client_set_auth() leave the timeout argument unset, causing rpc_new_client() to use the transport defaults instead of the parent's configured timeout. This also affects pNFS data-server clients and changes their request timeout and initial RTT calculations.
Use the parent's cl_timeout when no timeout is specified. Preserve explicitly supplied timeout overrides.
--- net/sunrpc/clnt.c | 2 ++ 1 file changed, 2 insertions(+)
net/sunrpc/clnt.c +2 -0
@@ -653,6 +653,8 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args, } args->servername = xprt->servername; args->nodename = clnt->cl_nodename; +if (!args->timeout) + args->timeout = clnt->cl_timeout; new =rpc_new_client (args, xps, xprt, clnt);if (IS_ERR (new))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/990 SUNRPC: preserve transport security policy when cloning clients
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 7783534ce5fee57adf1b9025745c9af2e1ce2ccd ]
RPC client cloning does not copy the parent's transport security policy into the new client. Clones consequently lose their TLS policy and certificate/key serials, even though the shared transport remains protected.
When NFSv4 migration replaces a cloned client's TLS transport, the missing security policy causes xs_setup_tcp_tls() to return -EACCES.
Copy the parent's cl_xprtsec into the clone arguments before creating the new client.
--- net/sunrpc/clnt.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/clnt.c +1 -0
@@ -653,6 +653,7 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args, } args->servername = xprt->servername; args->nodename = clnt->cl_nodename; + args->xprtsec = clnt->cl_xprtsec;if (!args->timeout) args->timeout = clnt->cl_timeout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/990 SUNRPC: Balance switch queue length on transport removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 8acd94f02a960c8936df25a7af9c02c8ea87064d ]
When call_connect_status() moves a task off a transport marked for removal, it decrements xprt->queuelen but leaves the switch's xps_queuelen unchanged. The stale count persists after the task finishes and skews multipath transport selection.
Decrement xps_queuelen alongside xprt->queuelen, matching the normal transport release path.
--- net/sunrpc/clnt.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/clnt.c +1 -0
@@ -2262,6 +2262,7 @@ call_connect_status(struct rpc_task *task)xprt_release (task); value =atomic_long_dec_return (&xprt->queuelen); +atomic_long_dec (&xps->xps_queuelen);if (value ==0 )rpc_xprt_switch_remove_xprt (xps, saved, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/990 SUNRPC: Balance queue accounting when relocating a task
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit f14b157168ac106cfac6d577e08726488b1b886c ]
When rpc_task_set_transport() relocates a movable task from an offline transport, it releases the request and drops the transport reference without decrementing the old transport's queuelen or the switch's xps_queuelen. Releasing the task later only accounts for the replacement transport.
The stale counts affect transport selection and can prevent xprt_delete_locked() from removing an otherwise idle transport.
Use rpc_task_release_xprt() to balance the previous assignment before selecting a replacement. Pass clnt explicitly because rpc_task_set_client() can assign a transport before tk_client is initialized.
--- net/sunrpc/clnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/clnt.c +1 -1
@@ -1197,7 +1197,7 @@ void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt) (task->tk_flags & RPC_TASK_MOVEABLE)))return ;xprt_release (task); -xprt_put (task->tk_xprt); +rpc_task_release_xprt (clnt, task->tk_xprt); }if (task->tk_flags &RPC_TASK_NO_ROUND_ROBIN ) task->tk_xprt =rpc_task_get_first_xprt (clnt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/990 NFS/localio: hold the client across an asynchronous LOCALIO probe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit 000a87910213562ff09f5bc38cd366ce34fccf71 ]
nfs_local_probe_async() queues the client's own cl_local_probe_work without a reference on the client, and nfs_free_client() does not cancel it. The work takes a reference only once it runs. If the last nfs_put_client() comes first, for example at umount after an NFSv3 I/O queued a throttled probe, the client is freed with its work queued, and the work then runs on freed memory.
Take the reference when the work is queued, and drop it when the work has run. If the work is already queued, it already holds a reference, and the one just taken is dropped.
--- fs/nfs/localio.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/nfs/localio.c +10 -3
@@ -204,15 +204,22 @@ void nfs_local_probe_async_work(struct work_struct *work)struct nfs_client *clp = container_of(work, struct nfs_client, cl_local_probe_work); -if (!refcount_inc_not_zero (&clp->cl_count)) -return ;nfs_local_probe (clp); +/* The reference nfs_local_probe_async() took for this work */ nfs_put_client (clp); } +/* +* The work is part of the client, so it holds a reference on the client +* from when it is queued until it has run: the last nfs_put_client() +* cannot free the client under a queued probe. +*/ void nfs_local_probe_async (struct nfs_client *clp) { -queue_work (nfsiod_workqueue, &clp->cl_local_probe_work); +if (!refcount_inc_not_zero (&clp->cl_count)) +return ; +if (!queue_work (nfsiod_workqueue, &clp->cl_local_probe_work)) +nfs_put_client (clp);/* already queued, with its reference */ }EXPORT_SYMBOL_GPL (nfs_local_probe_async);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/990 ublk: publish a new device by its id only once it is set up
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Korenberg <[email protected]>
[ Upstream commit e5c463e5074a940c644d54d8fc29aba06709aab0 ]
ADD_DEV stores the device in ublk_index_idr when it allocates the id, and control commands find it there as soon as ublk_add_chdev() has initialized its struct device, before the char device is added. If dev_set_name() or cdev_device_add() then fails, ublk_add_chdev() drops the initial reference to free the device. A DEL_DEV that found the device meanwhile waits for ublk_ctl_mutex, then calls ublk_remove():cdev_device_del() of a device that was never added, and a second put of the initial reference, which frees the device under the callers still holding references.
Reserve the id with a NULL entry, which idr_find() and the idr iterators skip, and store the device once ublk_add_chdev() succeeded.
--- drivers/block/ublk_drv.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +21 -2
@@ -2905,14 +2905,18 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx)int i = idx;int err; +/* +* Only reserve the id: the device is published by +* ublk_publish_dev_number() once it is fully set up. +*/ spin_lock (&ublk_idr_lock);/* allocate id, if @id >= 0, we're requesting that specific id */ if (i >=0 ) { - err =idr_alloc (&ublk_index_idr, ub, i, i +1 ,GFP_NOWAIT ); + err =idr_alloc (&ublk_index_idr,NULL , i, i +1 ,GFP_NOWAIT );if (err == -ENOSPC ) err = -EEXIST ; }else { - err =idr_alloc (&ublk_index_idr, ub,0 ,UBLK_MAX_UBLKS , + err =idr_alloc (&ublk_index_idr,NULL ,0 ,UBLK_MAX_UBLKS ,GFP_NOWAIT ); }spin_unlock (&ublk_idr_lock);
@@ -2923,6 +2927,19 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx)return err; } +/* +* Make the device visible to control commands by its id. Before its char +* device is added, DEL_DEV could find it and remove a char device that was +* never added, and drop the reference that ublk_add_chdev() drops on +* failure. +*/ +static void ublk_publish_dev_number (struct ublk_device *ub) +{ +spin_lock (&ublk_idr_lock); +WARN_ON_ONCE (idr_replace (&ublk_index_idr, ub, ub->ub_number) !=NULL ); +spin_unlock (&ublk_idr_lock); +} +static void ublk_free_dev_number (struct ublk_device *ub) {spin_lock (&ublk_idr_lock);
@@ -3409,6 +3426,8 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)* ublk_add_chdev() will cleanup everything if it fails. */ ret =ublk_add_chdev (ub); +if (!ret) +ublk_publish_dev_number (ub); goto out_unlock; out_deinit_queues:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/990 net: skbuff: preserve fclone lifetime when freeing stolen heads
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 86706ffa990ecd46a4326f8eecbccbbd60a6cb8d ]
skb_morph() can give an skb from skbuff_fclone_cache a page-fragment head without changing its fclone tag. IPv4 reassembly can produce such an skb, which can subsequently reach the GRO stolen-head path.
napi_skb_free_stolen_head() puts the shell into the ordinary NAPI skb cache without dropping its fclone_ref. If the embedded companion is still live, KASAN poisons it along with the original, and later cache reuse or eviction can overwrite or free the allocation underneath it. A mirrored batman-adv DAT packet retained in a plug qdisc reproduces a KASAN use-after-free in plug_dequeue().
Use kfree_skbmem() for fclones in napi_skb_free_stolen_head(), retaining NAPI caching for ordinary skb heads. Also use kfree_skbmem() in kfree_skb_partial(), whose stolen-head branch has the same assumption about the allocation cache. This releases the shell according to its allocation kind and preserves any live companion without freeing the data that has been transferred to the receiving skb.
--- net/core/skbuff.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/core/skbuff.c +5 -1
@@ -1458,6 +1458,10 @@ void napi_skb_free_stolen_head(struct sk_buff *skb)skb_orphan (skb); skb->slow_gro =0 ; } +if (skb->fclone !=SKB_FCLONE_UNAVAILABLE ) { +kfree_skbmem (skb); +return ; + }napi_skb_cache_put (skb); }
@@ -6126,7 +6130,7 @@ void kfree_skb_partial(struct sk_buff *skb, bool head_stolen) {if (head_stolen) {skb_release_head_state (skb); -kmem_cache_free (net_hotdata.skbuff_cache, skb); +kfree_skbmem (skb); }else {__kfree_skb (skb); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/990 xsk: fix list corruption in xsk_buff_add_frag()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 94ae1259175f566ed5a33f37b09b6f32a1b2d8af ]
In aligned mode, a fill ring address maps straight to its pool->heads[] entry. If user space posts the same address twice, a driver can pass xsk_buff_add_frag() a buffer that is the head of the frame or is already on pool->xskb_list or pool->free_list.
Re-adding a linked node corrupts the list. With buffers A, B, C, B, xsk_rcv_zc() emits two descriptors instead of four and leaves the list head pointing at a self-linked B. When the Rx ring later has no room for a frame, the xsk_buff_free() cleanup follows B into pool->free_list and passes the list head to xp_free():
BUG: kernel NULL pointer dereference, address: 00000000000000c0 RIP: 0010:xp_free+0x1a/0x50 Call Trace: xsk_rcv_zc+0xca/0x200
The head is not on any list and needs a separate check. Adding it as its own frag lets bpf_xdp_adjust_tail() free the in-use head and wrap sinfo->nr_frags to 255.
Reject such buffers before adding them to the frags array, as commit e37b2abca804 ("xsk: fix NULL pointer dereference in __xsk_rcv()") does in the copy path. Callers already drop the frame on failure.
Unaligned mode is not affected, as each fill ring entry gets its own xskb from pool->free_heads[].
Reproduced with a KUnit test feeding synthetic buffers to xsk_rcv_zc(), by Nagato Shiratana.
--- include/net/xdp_sock_drv.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/net/xdp_sock_drv.h +5 -2
@@ -156,15 +156,18 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)static inline bool xsk_buff_add_frag (struct xdp_buff *head,struct xdp_buff *xdp) { + struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp);const void *data = xdp->data; -struct xdp_buff_xsk *frag; + +/* Duplicate fill ring entries map to the same xskb in aligned mode */ +if (unlikely (xdp == head || !list_empty (&frag->list_node))) +return false;if (!__xdp_buff_add_frag (head,virt_to_netmem (data),offset_in_page (data), xdp->data_end - data, xdp->frame_sz, false))return false; - frag = container_of(xdp, struct xdp_buff_xsk, xdp);list_add_tail (&frag->list_node, &frag->pool->xskb_list);return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/990 i40e: xsk: fix xsk_buff_add_frag() error handling in Rx
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit a259b7ec09efec032d5521dc2eb751a959c11d15 ]
When xsk_buff_add_frag() fails, i40e_clean_rx_irq_zc() frees the frame but stays on the current descriptor, so the next poll restarts from the freed head. If the frags array was full, the retry passes on a frame missing the freed frags, with its head already on the free list. If the buffer is a duplicate, every poll fails the same way and the queue stalls.
Free the current buffer along with the frame and move on to the next descriptor, as ice does. The rest of the dropped frame is received as a new frame. xp_free() skips a duplicate already freed with the frame.
--- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +14 -6
@@ -459,16 +459,24 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)xsk_buff_set_size (bi, size);xsk_buff_dma_sync_for_cpu (bi); -if (!first) +if (++next_to_process == count) + next_to_process =0 ; + +if (!first) { first = bi; -else if (!xsk_buff_add_frag (first, bi)) { + }else if (!xsk_buff_add_frag (first, bi)) { +/* Drop what has been gathered so far. xp_free() skips +* @bi if it duplicates a buffer that is already on a +* pool list. Remaining buffers of this packet, if any, +* will be processed as a new packet. +*/ xsk_buff_free (first); -break ; +xsk_buff_free (bi); + next_to_clean = next_to_process; + first =NULL ; +continue ; } -if (++next_to_process == count) - next_to_process =0 ; -if (i40e_is_non_eop (rx_ring, rx_desc))continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/990 ice: xsk: fix leaking Rx buffers in multi-buffer path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 8b7bd01b9c56c0d1f65d0e2ad304b775e0d709e3 ]
ice_clean_rx_irq_zc() consumes a descriptor without freeing its buffer when a frag has zero length or when xsk_buff_add_frag() fails, which happens if the frags array is full or the fill ring has duplicates. Such buffers are lost to user space until the socket is closed.
Free the buffer in both cases. xp_free() skips a duplicate already freed with the frame.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_xsk.c +4 -1
@@ -619,8 +619,11 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring,if (!first) { first = xdp; - }else if (likely (size) && !xsk_buff_add_frag (first, xdp)) { + }else if (unlikely (!size)) { +xsk_buff_free (xdp); + }else if (!xsk_buff_add_frag (first, xdp)) {xsk_buff_free (first); +xsk_buff_free (xdp); first =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/990 ice: xsk: do not free in-flight frags on XDP_TX completion
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 5a9b5e315e101dfa02af5d8d3b27d893ba3e5566 ]
ice_xmit_xdp_tx_zc() takes the frags of a multi-buffer frame off pool->xskb_list but leaves XDP_FLAGS_HAS_FRAGS set on the head. When the head completes, xsk_buff_free() frees whatever is on the list at that point, which are the frags of a frame still being received.
If ice_xmit_xdp_tx_zc() completes such a head while cleaning the ring before sending another frame, xsk_buff_get_frag() returns NULL and xsk_buff_xdp_get_dma() dereferences it.
Clear the flag on the head once its frags are on the ring. As xdp_get_buff_len() then covers only the head, count Rx bytes before running the XDP program, like libeth does.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_xsk.c +8 -1
@@ -494,6 +494,11 @@ static int ice_xmit_xdp_tx_zc(struct xdp_buff *xdp, tx_desc->cmd_type_offset_bsz |=cpu_to_le64 (ICE_TX_DESC_CMD_EOP <<ICE_TXD_QW1_CMD_S ); +/* Each frag is now freed via its own Tx buffer. Completing the head +* must not release what is on the pool's frag list at that time. +*/ +xdp_buff_clear_frags_flag (head); +return ICE_XDP_TX ; busy:
@@ -593,6 +598,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring,struct sk_buff *skb;u16 stat_err_bits;u16 vlan_tci; +u32 xdp_len; rx_desc =ICE_RX_DESC (rx_ring, ntc);
@@ -635,6 +641,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, ((struct libeth_xdp_buff *)first)->desc = rx_desc; + xdp_len =xdp_get_buff_len (first); xdp_res =ice_run_xdp_zc (rx_ring, first, xdp_prog, xdp_ring, xsk_pool);if (likely (xdp_res & (ICE_XDP_TX |ICE_XDP_REDIR ))) {
@@ -649,7 +656,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, goto construct_skb; } - total_rx_bytes +=xdp_get_buff_len (first); + total_rx_bytes += xdp_len; total_rx_packets++; first =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/990 libeth: xsk: do not free in-flight frags on XDP_TX completion
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 90e5d84086d95ac45197028b98ad9059b245fc1c ]
libeth_xsk_tx_queue_bulk() takes the frags of a multi-buffer frame off pool->xskb_list but leaves XDP_FLAGS_HAS_FRAGS set on the head. When the head completes, libeth_xsk_buff_free_slow() frees whatever is on the list at that point.
The XDPSQ can be completed by a bulk flush while the frags of a frame are being queued, or by its cleanup timer while a partial Rx frame is stashed. Those frags are then freed while in use, and the frame being queued is sent truncated.
Clear the flag on the head once all of its frags are queued.
--- include/net/libeth/xsk.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
include/net/libeth/xsk.h +8 -2
@@ -77,11 +77,17 @@ libeth_xsk_tx_queue_bulk(struct libeth_xdp_tx_bulk *bq,if (!libeth_xsk_tx_queue_head (bq, xdp)) goto out; -for (const struct libeth_xdp_buff *head = xdp; ; ) { +for (struct libeth_xdp_buff *head = xdp; ; ) { xdp =container_of (xsk_buff_get_frag (&head->base),typeof (*xdp), base); -if (!xdp) +if (!xdp) { +/* Each frag is now freed via its own SQE. Freeing +* the head must not release what is on the pool's +* frag list at that time. +*/ +xdp_buff_clear_frags_flag (&head->base);break ; + }if (unlikely (bq->count ==LIBETH_XDP_TX_BULK ) &&unlikely (!flush_bulk (bq,LIBETH_XDP_TX_XSK ))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/990 i40e: xsk: fix multi-buffer XDP_PASS skb construction
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chenguang Zhao <[email protected]>
[ Upstream commit 76b41e83e69ae4ab23cc3535e36b780ea17e76c2 ]
When AF_XDP ZC receives a multi-buffer frame and the XDP program returns XDP_PASS, i40e_construct_skb_zc() copies frags into a new skb. The copy used skb_frag_page() as the memcpy source (page metadata instead of packet data) and passed a virtual address to __skb_fill_page_desc_noacc(), which expects a struct page *.
Use skb_frag_address() for the copy, attach frags with skb_add_rx_frag() so len/data_len/truesize are updated, and on dev_alloc_page() failure free the skb via the shared out path so xsk_buff_free() still runs and previously attached pages are released by kfree_skb.
--- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +5 -8
@@ -318,22 +318,19 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring, goto out;for (int i =0 ; i < nr_frags; i++) { -struct skb_shared_info *skinfo =skb_shinfo (skb);skb_frag_t *frag = &sinfo->frags[i]; +unsigned int frag_size =skb_frag_size (frag);struct page *page; -void *addr; page =dev_alloc_page ();if (!page) {dev_kfree_skb (skb); -return NULL ; + skb =NULL ; + goto out; } - addr =page_to_virt (page); -memcpy (addr,skb_frag_page (frag),skb_frag_size (frag)); - -__skb_fill_page_desc_noacc (skinfo, skinfo->nr_frags++, - addr,0 ,skb_frag_size (frag)); +memcpy (page_to_virt (page),skb_frag_address (frag), frag_size); +skb_add_rx_frag (skb, i, page,0 , frag_size,PAGE_SIZE ); } out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/990 ice: xsk: free stashed Rx frame when cleaning the ring
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit d5e7a86b7cd6c38a628635baace7eb2fdce14a43 ]
ice_clean_rx_irq_zc() stashes a partially received multi-buffer frame in rx_ring->xsk, with its frags on pool->xskb_list. next_to_clean is already past its buffers, so ice_xsk_clean_rx_ring(), which walks next_to_clean..next_to_use, misses the frame, and ice_vsi_cfg_rxq() later clears the pointer via ring->xdp.data.
The buffers are lost to user space and, as the pool outlives the ring across ifdown/ifup or a reset, the stale frags are taken as frags of the next frame. Before commit 93f53db9f9dc ("ice: switch to Page Pool"), the frame was tracked by rx_ring->first_desc and leaked the same way.
Free the stashed frame when cleaning the ring.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/ice/ice_xsk.c +5 -0
@@ -913,6 +913,11 @@ void ice_xsk_clean_rx_ring(struct ice_rx_ring *rx_ring)if (xdp_rxq_info_is_reg (&rx_ring->xdp_rxq))xdp_rxq_info_unreg (&rx_ring->xdp_rxq); +if (rx_ring->xsk) { +xsk_buff_free (&rx_ring->xsk->base); + rx_ring->xsk =NULL ; + } +while (ntc != ntu) {struct xdp_buff *xdp = *ice_xdp_buf (rx_ring, ntc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/990 idpf: free stashed XSk Rx frame when releasing the queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 3cbee39da8251098e2631a106fafcaebc7c8e66b ]
idpf_xskrq_poll() stashes a partially received multi-buffer frame in rxq->xsk, with its frags on pool->xskb_list. Nothing frees or clears rxq->xsk on queue release, as idpf_rx_desc_rel() only returns the page stash sharing its storage for non-XSk queues.
On ifdown, the buffers are lost to user space and, as the pool outlives the queue, the stale frags are taken as frags of the next frame. If the pool is disabled on a running interface, the queue restarts in page mode with rxq->xdp.data still pointing to an xskb of the pool, which is freed later. The page path then takes it for a partial frame, writes frag info through it and returns it to a page pool.
Free the stashed frame and clear the pointer when the XSk state of the queue is cleared, while the pool is still attached.
--- drivers/net/ethernet/intel/idpf/xsk.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/idpf/xsk.c +5 -0
@@ -132,6 +132,11 @@ void idpf_xsk_clear_queue(void *q, enum virtchnl2_queue_type type)if (!idpf_queue_has_clear (XSK , rxq))return ; +if (rxq->xsk) { +libeth_xsk_buff_free_slow (rxq->xsk); + rxq->xsk =NULL ; + } + rxq->pool =NULL ;break ;case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/990 net: usb: lan78xx: resume phylink on non-reset USB resume
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefano Munari <[email protected]>
[ Upstream commit be9587c47db16faaca5415f533637755c65a4eb0 ]
lan78xx_suspend() calls phylink_suspend(dev->phylink, false) on an open interface, which always stops phylink and halts the PHY. The matching phylink_resume() is only called from lan78xx_reset_resume(). When the USB device stays powered across system sleep (e.g. s2idle) and the USB core calls .resume instead, the link stays down until the interface is brought down and up by hand. The ifdown triggers:
WARNING: drivers/net/phy/phy.c:1670 at phy_stop+0x44/0xc8 called from state HALTED
Move phylink_resume() to the end of lan78xx_resume(), which both resume paths go through, and call it only if the resume succeeded and the interface was open, mirroring lan78xx_suspend(). As a side effect, lan78xx_reset_resume() no longer starts phylink on a closed interface.
Tested on a Raspberry Pi 3B+ (LAN7515) with s2idle: the link now comes back up on its own after resume and ifdown no longer warns.
--- drivers/net/usb/lan78xx.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/usb/lan78xx.c +7 -9
@@ -5377,6 +5377,12 @@ static int lan78xx_resume(struct usb_interface *intf) out:mutex_unlock (&dev->dev_mutex); +if (!ret && dev_open) { +rtnl_lock (); +phylink_resume (dev->phylink); +rtnl_unlock (); + } +return ret; }
@@ -5391,15 +5397,7 @@ static int lan78xx_reset_resume(struct usb_interface *intf)if (ret <0 )return ret; - ret =lan78xx_resume (intf); -if (ret <0 ) -return ret; - -rtnl_lock (); -phylink_resume (dev->phylink); -rtnl_unlock (); - -return 0 ; +return lan78xx_resume (intf); }static const struct usb_device_id products[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/990 net: raw: fix ICMP unreachable sent when receive queue is full
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 45441a94d50200f1478c52857725e6df624bf2ad ]
It's found in a raw socket application. When the application doesn't read packets in time, the client receives ICMP Protocol Unreachable, which makes the client abort the session.
The reason is that the server hits the sk_rcvbuf limit, and raw_v4_input() skips the socket before setting 'delivered', so it returns 0. Then ip_protocol_deliver_rcu() sees 'raw' is 0, thinks no one handles this protocol and calls icmp_send() to send ICMP Protocol Unreachable.
IPv6 has the same issue, ip6_protocol_deliver_rcu() sends ICMPv6 Parameter Problem instead.
Also, we'd better run icmp_filter() and ip_mc_sf_allow() (icmpv6_filter() for IPv6) before we check sk_rcvbuf, otherwise packets rejected by ICMP_FILTER/ICMPV6_FILTER or the multicast filter are counted in sk_drops. So move the check right before skb_clone().
--- net/ipv4/raw.c | 15 ++++++++------- net/ipv6/raw.c | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-)
net/ipv4/raw.c +8 -7
@@ -184,18 +184,19 @@ static int raw_v4_input(struct net *net, struct sk_buff *skb, iph->saddr, iph->daddr, dif, sdif))continue ; -if (atomic_read (&sk->sk_rmem_alloc) >= -READ_ONCE (sk->sk_rcvbuf)) { -sk_drops_inc (sk); -continue ; - } - delivered =1 ;if ((iph->protocol !=IPPROTO_ICMP || !icmp_filter (sk, skb)) &&ip_mc_sf_allow (sk, iph->daddr, iph->saddr, skb->dev->ifindex, sdif)) { -struct sk_buff *clone =skb_clone (skb,GFP_ATOMIC ); +struct sk_buff *clone; + +if (atomic_read (&sk->sk_rmem_alloc) >= +READ_ONCE (sk->sk_rcvbuf)) { +sk_drops_inc (sk); +continue ; + } + clone =skb_clone (skb,GFP_ATOMIC );/* Not releasing hash table! */ if (clone)raw_rcv (sk, clone);
net/ipv6/raw.c +8 -7
@@ -161,12 +161,6 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) inet6_iif(skb), inet6_sdif(skb)))continue ; -if (atomic_read (&sk->sk_rmem_alloc) >= -READ_ONCE (sk->sk_rcvbuf)) { -sk_drops_inc (sk); -continue ; - } - delivered = true;switch (nexthdr) {case IPPROTO_ICMPV6 :
@@ -197,8 +191,15 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)if (filtered <0 )break ;if (filtered ==0 ) { -struct sk_buff *clone =skb_clone (skb,GFP_ATOMIC ); +struct sk_buff *clone; + +if (atomic_read (&sk->sk_rmem_alloc) >= +READ_ONCE (sk->sk_rcvbuf)) { +sk_drops_inc (sk); +continue ; + } + clone =skb_clone (skb,GFP_ATOMIC );/* Not releasing hash table! */ if (clone)rawv6_rcv (sk, clone);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/990 spi: virtio: move teardown to .remove()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Valla <[email protected]>
[ Upstream commit 9060f5ba658c9b0a7332be55b3d8abfc2b08618b ]
The .remove() callback is not marked as optional for a virtio_driver, and thus a missing one is a bug. Moreover, the virtio framework expects a driver to reset the device it controls during teardown and explicitly checks for this reading the device status and WARNing in case it is still running. Any devm cleanup action gets however called after that check, leading to the WARN_ON condition to always be true for spi-virtio; thus, an empty remove() is not an option.
Move the cleanup actions to the .remove() callback of the driver and adapt the surrounding code to the new behavior.
--- drivers/spi/spi-virtio.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/spi/spi-virtio.c +15 -11
@@ -320,10 +320,8 @@ static int virtio_spi_find_vqs(struct virtio_spi_priv *priv) }/* Function must not be called before virtio_spi_find_vqs() has been run */ -static void virtio_spi_del_vq (void *data) +static void virtio_spi_del_vq (struct virtio_device *vdev) { -struct virtio_device *vdev = data; -virtio_reset_device (vdev); vdev->config->del_vqs (vdev); }
@@ -354,21 +352,26 @@ static int virtio_spi_probe(struct virtio_device *vdev)if (ret)return dev_err_probe (&vdev->dev, ret,"Cannot setup virtqueues\n" ); -/* Register cleanup for virtqueues using devm */ - ret =devm_add_action_or_reset (&vdev->dev, virtio_spi_del_vq, vdev); -if (ret) -return dev_err_probe (&vdev->dev, ret,"Cannot register virtqueue cleanup\n" ); -virtio_device_ready (vdev); -/* Use devm version to register controller */ - ret =devm_spi_register_controller (&vdev->dev, ctrl); -if (ret) + ret =spi_register_controller (ctrl); +if (ret) { +virtio_spi_del_vq (vdev);return dev_err_probe (&vdev->dev, ret,"Cannot register controller\n" ); + }return 0 ; } +static void virtio_spi_remove (struct virtio_device *vdev) +{ +struct spi_controller *ctrl =dev_get_drvdata (&vdev->dev); + +spi_unregister_controller (ctrl); + +virtio_spi_del_vq (vdev); +} +static int virtio_spi_freeze (struct device *dev) {struct spi_controller *ctrl =dev_get_drvdata (dev);
@@ -422,6 +425,7 @@ static struct virtio_driver virtio_spi_driver = { }, .id_table = virtio_spi_id_table, .probe = virtio_spi_probe, + .remove = virtio_spi_remove, };module_virtio_driver (virtio_spi_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/990 af_unix: Convert unsigned long to u64 for GC.
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit d5f898d4c47217ce42506698a3a98741393217b7 ]
Lim Chanyoun reported that unix_vertex_max_scc_index could wrap around on 32-bit kernels, which confuses GC into purging a live socket receive queue.
I apparently designed GC with u64 in mind to avoid wraparound. [0]
Let's make it true on 32-bit kernels.
Note that unix_vertex.{out_degree,index} are converted for consistency; they are bounded by the number of allocated objects and do not exceed UINT_MAX on 32-bit kernels.
--- net/unix/garbage.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
net/unix/garbage.c +14 -14
@@ -78,9 +78,9 @@ struct unix_vertex {struct list_head edges;struct list_head entry;struct list_head scc_entry; -unsigned long out_degree; -unsigned long index; -unsigned long scc_index; +u64 out_degree; +u64 index; +u64 scc_index; };struct unix_edge {
@@ -148,8 +148,8 @@ enum unix_vertex_index { UNIX_VERTEX_INDEX_START, }; -static unsigned long unix_vertex_unvisited_index =UNIX_VERTEX_INDEX_MARK1 ; -static unsigned long unix_vertex_max_scc_index =UNIX_VERTEX_INDEX_START ; +static u64 unix_vertex_unvisited_index =UNIX_VERTEX_INDEX_MARK1 ; +static u64 unix_vertex_max_scc_index =UNIX_VERTEX_INDEX_START ;static void unix_add_edge (struct scm_fp_list *fpl,struct unix_edge *edge) {
@@ -373,7 +373,7 @@ static bool unix_vertex_dead(struct unix_vertex *vertex) }static LIST_HEAD (unix_visited_vertices); -static unsigned long unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ; +static u64 unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ;static bool unix_scc_dead (struct list_head *scc) {
@@ -451,14 +451,14 @@ static bool unix_scc_cyclic(struct list_head *scc)return false; } -static unsigned long __unix_walk_scc (struct unix_vertex *vertex, -unsigned long *last_index, -struct sk_buff_head *hitlist) +static u64 __unix_walk_scc (struct unix_vertex *vertex, +u64 *last_index, +struct sk_buff_head *hitlist) { -unsigned long cyclic_sccs =0 ;LIST_HEAD (vertex_stack);struct unix_edge *edge;LIST_HEAD (edge_stack); +u64 cyclic_sccs =0 ; next_vertex:/* Push vertex to vertex_stack and mark it as on-stack
@@ -554,12 +554,12 @@ static unsigned long __unix_walk_scc(struct unix_vertex *vertex,return cyclic_sccs; } -static unsigned long unix_graph_cyclic_sccs; +static u64 unix_graph_cyclic_sccs;static void unix_walk_scc (struct sk_buff_head *hitlist) { -unsigned long last_index =UNIX_VERTEX_INDEX_START ; -unsigned long cyclic_sccs =0 ; +u64 last_index =UNIX_VERTEX_INDEX_START ; +u64 cyclic_sccs =0 ; unix_vertex_max_scc_index =UNIX_VERTEX_INDEX_START ;
@@ -582,7 +582,7 @@ static void unix_walk_scc(struct sk_buff_head *hitlist)static void unix_walk_scc_fast (struct sk_buff_head *hitlist) { -unsigned long cyclic_sccs = unix_graph_cyclic_sccs; +u64 cyclic_sccs = unix_graph_cyclic_sccs;while (!list_empty (&unix_unvisited_vertices)) {struct unix_vertex *vertex;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/990 af_unix: Remove gc_in_progress check in unix_peek_fpl().
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 0edbc945eb9edd0086f25b151a79cfe4adc0dfa8 ]
unix_vertex_dead() and unix_peek_fpl() are synchronised with unix_peek_seq to prevent GC from purging a live socket's recvq.
unix_peek_fpl() skips the synchronisation if gc_in_progress is false.
However, on weakly ordered arch, GC might have already started working while the write to gc_in_progress is buffered.
This does not occur on x86.
This is an unlikely path that happens only when AF_UNIX fd is peeked so not worth complicating.
Instead of adding memory barriers in unix_gc() and unix_peek_fpl(), let's simply remove the broken short-circuit.
--- net/unix/garbage.c | 3 --- 1 file changed, 3 deletions(-)
net/unix/garbage.c +0 -3
@@ -330,9 +330,6 @@ void unix_peek_fpl(struct scm_fp_list *fpl)if (!fpl || !fpl->count_unix)return ; -if (!READ_ONCE (gc_in_progress)) -return ; -/* Invalidate the final refcnt check in unix_vertex_dead(). */ spin_lock (&unix_peek_lock);raw_write_seqcount_barrier (&unix_peek_seq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/990 net/mlx5: Bridge, fix bogus MDB offload errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gal Pressman <[email protected]>
[ Upstream commit c714f324eac17b2df03419b5cd5368687efd8e27 ]
MDB add operations are queued on the switchdev deferred queue (SWITCHDEV_F_DEFER), while vlan object deletions are handled synchronously.
A 'bridge vlan del' can overtake an MDB add that is still queued, and the vlan is already gone by the time the driver is called.
The two operations are independent in practice: in my test, the MDB add is triggered by assigning the VF an IPv6 address (hence joining a solicited-node multicast group), while another process deletes the vlan from its representor.
Racing 'bridge mdb add' against concurrent 'bridge vlan del' could result in:
[ 5390.967651] mlx5_core 0000:08:00.0: E-Switch: Failed to lookup bridge port vlan metadata (vport=1)
[ 5390.969120] mlx5_core 0000:08:00.1: E-Switch: Failed to lookup bridge port vlan metadata to create MDB (MAC=33:33:ff:12:00:05,vid=2204,vport=1)
[ 5390.971676] mlx5_core 0000:08:00.1 eth4: Failed to add Port Multicast Database entry (object id=2) with error: -EINVAL (-22).
Failure in updating the port's Multicast Database could lead to
multicast forwarding issues.The error cannot reach anyone that could do anything with it, switchdev returned success to the bridge as soon as the MDB object was queued, and the errno only flags the entry as offload failed.
The end result is correct either way, if the MDB has been offloaded before the vlan was deleted, mlx5_esw_bridge_port_mdb_vlan_flush() would have removed it.
The FDB path already treats this as a harmless race, mlx5_esw_bridge_port_vlan_lookup() reports it on 'info' logging level and skips the offload. mlxsw did the same in [1].
Skip the MDB offload, report on 'info' logging level and return -EOPNOTSUPP: switchdev_port_obj_add_deferred() does not log it, and br_switchdev_mdb_complete() skips the port group flag update.
[1] Commit 17b334a876fe ("mlxsw: spectrum_switchdev: Don't warn about valid situations")
--- .../ethernet/mellanox/mlx5/core/esw/bridge.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +11 -10
@@ -1867,26 +1867,27 @@ int mlx5_esw_bridge_port_mdb_add(struct net_device *dev, u16 vport_num, u16 esw_ port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads);if (!port) { -esw_warn (br_offloads->esw->dev, +/* MDB is added asynchronously from the switchdev deferred +* queue while port might have been deleted concurrently. +*/ +esw_info (br_offloads->esw->dev,"Failed to lookup bridge port to add MDB (MAC=%pM,vport=%u)\n" , addr, vport_num); -NL_SET_ERR_MSG_FMT_MOD (extack, -"Failed to lookup bridge port to add MDB (MAC=%pM,vport=%u)" , - addr, vport_num); -return -EINVAL ; +return -EOPNOTSUPP ; } bridge = port->bridge;if (bridge->flags &MLX5_ESW_BRIDGE_VLAN_FILTERING_FLAG && vid) { vlan =mlx5_esw_bridge_vlan_lookup (vid, port);if (!vlan) { -esw_warn (br_offloads->esw->dev, +/* MDB is added asynchronously from the switchdev +* deferred queue while vlan might have been deleted +* concurrently. +*/ +esw_info (br_offloads->esw->dev,"Failed to lookup bridge port vlan metadata to create MDB (MAC=%pM,vid=%u,vport=%u)\n" , addr, vid, vport_num); -NL_SET_ERR_MSG_FMT_MOD (extack, -"Failed to lookup vlan metadata for MDB (MAC=%pM,vid=%u,vport=%u)" , - addr, vid, vport_num); -return -EINVAL ; +return -EOPNOTSUPP ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/990 ipv6: ignore link state in gateway check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yaroslav Dudkov <[email protected]>
[ Upstream commit b76bcf3fff9332076d92de47a80d12fd3d5268e2 ]
IPv6 route cannot be added in table when all
following conditions are true:
- gateway is not link-local address
- ignore_routes_with_linkdown=1 on device
- nexthop has no carrier
- gateway is not present or covered by any route in table already Also multipath routes addition is invalidated by kernel even if only one of added nexthops satisfies all above conditions.
Reproducer:
ip netns add t
ip -n t link add va type veth peer name vb ip -n t link set va up
ip -n t addr add fd00::1/64 dev va nodad
ip netns exec t sysctl -w \
net.ipv6.conf.va.ignore_routes_with_linkdown=1
ip -n t -6 route add 2001:db8::/64 via fd00::2 dev va
# added ip -n t -6 route add 2001:db8::/64 table 100 via fd00::2 dev va # RTNETLINK answers: No route to host ip -n t -6 route show table all ip netns del t
Route should be added because:
- RT6_LOOKUP_F_IGNORE_LINKSTATE in commit d5d32e4b7668 ("net: ipv6: Do not consider link state for nexthop validation") was added for this
- the same route is valid in main table (when no specifying table id while adding route)
- fib6_nh_init() initializes nexthops with no carrier
- IPv4 already does this (fib_check_nh_v4_gw() ignores link state using the FIB_LOOKUP_IGNORE_LINKSTATE flag)
Before commit b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info") rt6_lookup() was used for checking if nexthop is valid, rt6_lookup called rt6_device_match() which does not check the link state. After change rt6_lookup() to fib6_lookup() find_match() under fib6_lookup() started to invalidate linkdown devices, because RT6_LOOKUP_F_IGNORE_LINKSTATE is not passed to it.
Adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags for ip6_route_check_nh() solves the problem. RT6_LOOKUP_F_IGNORE_LINKSTATE is already used inside the first search ip6_nh_lookup_table() and fixes the bug in second search fib6_lookup(). Also RT6_LOOKUP_F_IGNORE_LINKSTATE isn't read inside fib6_select_path().
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -3461,9 +3461,9 @@ static int ip6_route_check_nh(struct net *net,netdevice_tracker *dev_tracker, struct inet6_dev **idev) { + int flags = RT6_LOOKUP_F_IFACE | RT6_LOOKUP_F_IGNORE_LINKSTATE;const struct in6_addr *gw_addr = &cfg->fc_gateway;struct net_device *dev = _dev ? *_dev :NULL ; -int flags =RT6_LOOKUP_F_IFACE ;struct fib6_result res = {};int err = -EHOSTUNREACH ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/990 team: Add matching error label for failed action
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikola Z. Ivanov <[email protected]>
[ Upstream commit aee0f01b4f118844cb126a5f27e91c2adf087c59 ]
Follow the "action" - "err_action" pairing of labels found across the source code of team net device.
Currently in team_port_add the err_set_slave_promisc label is reused for exiting on error when setting allmulti level of the new slave.
Stable-dep-of: ff618cb00a64 ("team: fix promisc/allmulti leak in team_port_add error path")
--- drivers/net/team/team_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/team/team_core.c +2 -1
@@ -1260,7 +1260,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev,if (err) {if (dev->flags &IFF_PROMISC )dev_set_promiscuity (port_dev,-1 ); - goto err_set_slave_promisc; + goto err_set_slave_allmulti; } }
@@ -1287,6 +1287,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev,return 0 ; err_set_dev_type: +err_set_slave_allmulti: err_set_slave_promisc:__team_option_inst_del_port (team, port);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/990 team: fix promisc/allmulti leak in team_port_add error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit ff618cb00a645f1e3f89068c5fbda3f3a7f4ae63 ]
team_port_add() increments the port's promiscuity and allmulti counts before calling team_dev_type_check_change(). If the latter fails, the error path does not undo these increments, leaving the port in promiscuous and allmulti mode even though it was not successfully added to the team.
Undo the promiscuity increment under err_set_slave_allmulti and the allmulti increment under err_set_dev_type, so each error label only reverts what was successfully applied, matching the cleanup performed by team_port_del().
With the promiscuity rollback now living under err_set_slave_allmulti, the inline dev_set_promiscuity(port_dev, -1) in the dev_set_allmulti() failure branch becomes redundant: that branch already jumps to err_set_slave_allmulti, which undoes the promiscuity increment. Drop the inline call to avoid doing it twice.
Found by source code audit.
--- drivers/net/team/team_core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/team/team_core.c +5 -4
@@ -1257,11 +1257,8 @@ static int team_port_add(struct team *team, struct net_device *port_dev,/* set allmulti level to new slave */ if (dev->flags &IFF_ALLMULTI ) { err =dev_set_allmulti (port_dev,1 ); -if (err) { -if (dev->flags &IFF_PROMISC ) -dev_set_promiscuity (port_dev,-1 ); +if (err) goto err_set_slave_allmulti; - } } err =team_dev_type_check_change (dev, port_dev);
@@ -1287,7 +1284,11 @@ static int team_port_add(struct team *team, struct net_device *port_dev,return 0 ; err_set_dev_type: +if (dev->flags &IFF_ALLMULTI ) +dev_set_allmulti (port_dev,-1 ); err_set_slave_allmulti: +if (dev->flags &IFF_PROMISC ) +dev_set_promiscuity (port_dev,-1 ); err_set_slave_promisc:__team_option_inst_del_port (team, port);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/990 net/mlx5: Use only loaded devices for PTP clock operations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 908561cc4b4db4510465f02f5323e98f2dc00fad ]
The PTP periodic worker and PTP operations access PCI registers through the function backing the PTP clock. The PTP clock remains registered when a PCI function is suspended, so these paths can still access the function after it has been unloaded.
To fix that, serialize clock hardware access with the clock mutex for all clocks and fail callbacks with -EAGAIN when there is no loaded function to service the clock. Additionally, tie the worker's lifetime to load/unload and use the devcom lock to synchronize with peer loads/unloads.
Since the periodic worker is stopped during unload, the free running counter may wrap without being sampled. Reinitialize the timecounter on load using the hardware real time clock in real time mode, or the saved PHC time plus elapsed CLOCK_BOOTTIME in free running mode.
This provides best effort PHC continuity across unload/load. In free running mode, elapsed time while unloaded is estimated using CLOCK_BOOTTIME rather than the PHC's adjusted frequency.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 248 +++++++++++++----- .../ethernet/mellanox/mlx5/core/lib/clock.h | 2 + 2 files changed, 185 insertions(+), 65 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +183 -65
@@ -80,6 +80,7 @@ enum { };struct mlx5_clock_dev_state { +bool loaded;struct mlx5_core_dev *mdev;struct mlx5_devcom_comp_dev *compdev;struct mlx5_nb pps_nb;
@@ -89,7 +90,7 @@ struct mlx5_clock_dev_state {struct mlx5_clock_priv {struct mlx5_clock clock;struct mlx5_core_dev *mdev; -struct mutex lock;/* protect mdev and used in PTP callbacks */ +struct mutex lock;/* protect mdev and serialize hardware callbacks */ struct mlx5_core_dev *event_mdev; };
@@ -100,9 +101,6 @@ static struct mlx5_clock_priv *clock_priv(struct mlx5_clock *clock)static void mlx5_clock_lockdep_assert (struct mlx5_clock *clock) { -if (!clock->shared) -return ; -lockdep_assert (lockdep_is_held (&clock_priv (clock)->lock)); }
@@ -115,20 +113,24 @@ static struct mlx5_core_dev *mlx5_clock_mdev_get(struct mlx5_clock *clock)static void mlx5_clock_lock (struct mlx5_clock *clock) { -if (!clock->shared) -return ; -mutex_lock (&clock_priv (clock)->lock); }static void mlx5_clock_unlock (struct mlx5_clock *clock) { -if (!clock->shared) -return ; -mutex_unlock (&clock_priv (clock)->lock); } +static struct mlx5_core_dev * +mlx5_clock_active_mdev_get (struct mlx5_clock *clock) +{ +struct mlx5_clock_priv *cpriv =clock_priv (clock); + +mlx5_clock_lockdep_assert (clock); + +return cpriv->mdev->clock_state->loaded ? cpriv->mdev :NULL ; +} +static bool mlx5_real_time_mode (struct mlx5_core_dev *mdev) {return (mlx5_is_real_time_rq (mdev) ||mlx5_is_real_time_sq (mdev));
@@ -332,7 +334,11 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp,int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (!mlx5_is_ptm_source_time_available (mdev)) { err = -EBUSY ;
@@ -358,7 +364,11 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp,int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (!mlx5_is_ptm_source_time_available (mdev)) { err = -EBUSY ;
@@ -410,6 +420,12 @@ static u64 read_internal_timer(struct cyclecounter *cc)return mlx5_read_time (mdev,NULL , false) & cc->mask; } +static void mlx5_timer_snapshot (struct mlx5_timer *timer) +{ + timer->saved_phc_ns = timer->tc.nsec; + timer->saved_boot_ns =ktime_get_boottime_ns (); +} +static void mlx5_update_clock_info_page (struct mlx5_core_dev *mdev) {struct mlx5_ib_clock_info *clock_info = mdev->clock_info;
@@ -417,6 +433,9 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev)struct mlx5_timer *timer;u32 sign; + timer = &clock->timer; +mlx5_timer_snapshot (timer); +if (!clock_info)return ;
@@ -424,7 +443,6 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev)smp_store_mb (clock_info->sign, sign |MLX5_IB_CLOCK_INFO_KERNEL_UPDATING ); - timer = &clock->timer; clock_info->cycles = timer->tc.cycle_last; clock_info->mult = timer->cycles.mult; clock_info->nsec = timer->tc.nsec;
@@ -470,10 +488,9 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info) clock = container_of(ptp_info, struct mlx5_clock, ptp_info);mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); timer = &clock->timer; - -if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) +if (!mdev || mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) goto out;write_seqlock_irqsave (&clock->lock, flags);
@@ -530,8 +547,13 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } err =mlx5_clock_settime (mdev, clock, ts); +unlock:mlx5_clock_unlock (clock);return err;
@@ -549,26 +571,40 @@ struct timespec64 mlx5_ptp_gettimex_real_time(struct mlx5_core_dev *mdev,return ts; } -static int mlx5_ptp_gettimex (struct ptp_clock_info *ptp,struct timespec64 *ts, -struct ptp_system_timestamp *sts) +static void mlx5_clock_gettimex (struct mlx5_core_dev *mdev, +struct mlx5_clock *clock,struct timespec64 *ts, +struct ptp_system_timestamp *sts) { - struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); -struct mlx5_core_dev *mdev;u64 cycles, ns; -mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock);if (mlx5_real_time_mode (mdev)) { *ts =mlx5_ptp_gettimex_real_time (mdev, sts); - goto out; +return ; } cycles =mlx5_read_time (mdev, sts, false); ns =mlx5_timecounter_cyc2time (clock, cycles); *ts =ns_to_timespec64 (ns); -out: +} + +static int mlx5_ptp_gettimex (struct ptp_clock_info *ptp,struct timespec64 *ts, +struct ptp_system_timestamp *sts) +{ +struct mlx5_clock *clock = + container_of(ptp, struct mlx5_clock, ptp_info); +struct mlx5_core_dev *mdev; +int err =0 ; + +mlx5_clock_lock (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } +mlx5_clock_gettimex (mdev, clock, ts, sts); +unlock:mlx5_clock_unlock (clock); -return 0 ; +return err; } static int mlx5_ptp_getcyclesx(struct ptp_clock_info *ptp,
@@ -579,14 +615,20 @@ static int mlx5_ptp_getcyclesx(struct ptp_clock_info *ptp, ptp_info);struct mlx5_core_dev *mdev;u64 cycles; +int err =0 ;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } cycles =mlx5_read_time (mdev, sts, false); *ts =ns_to_timespec64 (cycles); +unlock:mlx5_clock_unlock (clock); -return 0 ; +return err; }static int mlx5_ptp_adjtime_real_time (struct mlx5_core_dev *mdev,s64 delta)
@@ -619,7 +661,11 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)int err =0 ;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (mlx5_modify_mtutc_allowed (mdev)) { err =mlx5_ptp_adjtime_real_time (mdev, delta);
@@ -629,6 +675,7 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) }write_seqlock_irqsave (&clock->lock, flags); +timecounter_read (&timer->tc);timecounter_adjtime (&timer->tc, delta);mlx5_update_clock_info_page (mdev);write_sequnlock_irqrestore (&clock->lock, flags);
@@ -645,8 +692,13 @@ static int mlx5_ptp_adjphase(struct ptp_clock_info *ptp, s32 delta)int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } err =mlx5_ptp_adjtime_real_time (mdev, delta); +unlock:mlx5_clock_unlock (clock);return err;
@@ -682,7 +734,11 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)u32 mult;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (mlx5_modify_mtutc_allowed (mdev)) { err =mlx5_ptp_freq_adj_real_time (mdev, scaled_ppm);
@@ -743,7 +799,11 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, }mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (!MLX5_PPS_CAP (mdev)) { err = -EOPNOTSUPP ;
@@ -916,7 +976,11 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,return -EBUSY ;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } rt_mode =mlx5_real_time_mode (mdev);if (!MLX5_PPS_CAP (mdev)) {
@@ -1151,7 +1215,7 @@ static u64 perout_conf_next_event_timer(struct mlx5_core_dev *mdev,struct timespec64 ts;s64 target_ns; -mlx5_ptp_gettimex (&clock->ptp_info, &ts,NULL ); +mlx5_clock_gettimex (mdev, clock, &ts,NULL );ts_next_sec (&ts); target_ns =timespec64_to_ns (&ts);
@@ -1222,8 +1286,8 @@ static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) timer->nominal_c_mult = timer->cycles.mult; timer->cycles.mask =CLOCKSOURCE_MASK (41 ); -timecounter_init (&timer->tc, &timer->cycles, -ktime_to_ns (ktime_get_real ())); +timecounter_init (&timer->tc, &timer->cycles,ktime_get_real_ns ()); +mlx5_timer_snapshot (timer); }static void mlx5_init_overflow_period (struct mlx5_core_dev *mdev)
@@ -1370,9 +1434,6 @@ static void mlx5_init_clock_dev(struct mlx5_core_dev *mdev) clock->ptp); clock->ptp =NULL ; } - -if (clock->ptp) -ptp_schedule_worker (clock->ptp,0 ); }static void mlx5_destroy_clock_dev (struct mlx5_core_dev *mdev)
@@ -1517,22 +1578,53 @@ static void mlx5_clock_arm_pps_in_event(struct mlx5_clock *clock, !clock->pps_info.pin_armed[i])continue ; -if (new_mdev) { +if (new_mdev)mlx5_set_mtppse (new_mdev, i,0 ,MLX5_EVENT_MODE_REPETETIVE ); - cpriv->event_mdev = new_mdev; - }else { - cpriv->event_mdev =NULL ; - }if (old_mdev)mlx5_set_mtppse (old_mdev, i,0 ,MLX5_EVENT_MODE_DISABLE ); } + cpriv->event_mdev = new_mdev; +} + +static void mlx5_set_timecounter (struct mlx5_core_dev *mdev,u64 ns) +{ +struct mlx5_clock *clock = mdev->clock; +struct mlx5_timer *timer; +unsigned long flags; + + timer = &clock->timer; +mlx5_clock_lockdep_assert (clock); + +write_seqlock_irqsave (&clock->lock, flags); +timecounter_init (&timer->tc, &timer->cycles, ns); +mlx5_update_clock_info_page (mdev); +write_sequnlock_irqrestore (&clock->lock, flags); +} + +static void mlx5_save_timecounter (struct mlx5_core_dev *mdev) +{ +struct mlx5_clock *clock = mdev->clock; +struct mlx5_timer *timer; +unsigned long flags; + + timer = &clock->timer; +mlx5_clock_lockdep_assert (clock); + +if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) +return ; + +write_seqlock_irqsave (&clock->lock, flags); +timecounter_read (&timer->tc); +mlx5_update_clock_info_page (mdev); +write_sequnlock_irqrestore (&clock->lock, flags); }void mlx5_clock_load (struct mlx5_core_dev *mdev) {struct mlx5_clock *clock = mdev->clock;struct mlx5_clock_priv *cpriv; +bool start;if (!MLX5_CAP_GEN (mdev, device_frequency_khz))return ;
@@ -1541,18 +1633,32 @@ void mlx5_clock_load(struct mlx5_core_dev *mdev)MLX5_NB_INIT (&mdev->clock_state->pps_nb, mlx5_pps_event,PPS_EVENT );mlx5_eq_notifier_register (mdev, &mdev->clock_state->pps_nb); -if (!clock->shared) { -mlx5_clock_arm_pps_in_event (clock, mdev,NULL ); -return ; - } - cpriv =clock_priv (clock); -mlx5_devcom_comp_lock (mdev->clock_state->compdev); +if (clock->shared) +mlx5_devcom_comp_lock (mdev->clock_state->compdev);mlx5_clock_lock (clock); -if (mdev == cpriv->mdev && mdev != cpriv->event_mdev) + start = !cpriv->mdev->clock_state->loaded; + mdev->clock_state->loaded = true; +if (start) { +struct mlx5_timer *timer = &clock->timer; +u64 ns; + + cpriv->mdev = mdev; +if (mlx5_real_time_mode (mdev)) + ns =mlx5_read_time (mdev,NULL , true); +else + ns = timer->saved_phc_ns + +ktime_get_boottime_ns () - timer->saved_boot_ns; + +mlx5_set_timecounter (mdev, ns);mlx5_clock_arm_pps_in_event (clock, mdev, cpriv->event_mdev); + }mlx5_clock_unlock (clock); -mlx5_devcom_comp_unlock (mdev->clock_state->compdev); + +if (start && clock->ptp) +ptp_schedule_worker (clock->ptp,0 ); +if (clock->shared) +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); }void mlx5_clock_unload (struct mlx5_core_dev *mdev)
@@ -1560,30 +1666,42 @@ void mlx5_clock_unload(struct mlx5_core_dev *mdev)struct mlx5_core_dev *peer_dev, *next =NULL ;struct mlx5_clock *clock = mdev->clock;struct mlx5_devcom_comp_dev *pos; +struct mlx5_clock_priv *cpriv; +bool stop;if (!MLX5_CAP_GEN (mdev, device_frequency_khz))return ; -if (!clock->shared) { -mlx5_clock_arm_pps_in_event (clock,NULL , mdev); - goto out; - } - -mlx5_devcom_comp_lock (mdev->clock_state->compdev); -mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, peer_dev, pos) { -if (peer_dev->clock && peer_dev != mdev) { - next = peer_dev; -break ; +if (clock->shared) { +mlx5_devcom_comp_lock (mdev->clock_state->compdev); +mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, + peer_dev, pos) { +if (peer_dev->clock == clock && + peer_dev->clock_state->loaded) { + next = peer_dev; +break ; + } } }mlx5_clock_lock (clock); -if (mdev ==clock_priv (clock)->event_mdev) + cpriv =clock_priv (clock); + mdev->clock_state->loaded = false; +if (mdev == cpriv->mdev && next) + cpriv->mdev = next; +if (mdev == cpriv->event_mdev)mlx5_clock_arm_pps_in_event (clock, next, mdev); + stop = !cpriv->mdev->clock_state->loaded; +if (!mlx5_real_time_mode (cpriv->mdev)) +mlx5_save_timecounter (cpriv->mdev);mlx5_clock_unlock (clock); -mlx5_devcom_comp_unlock (mdev->clock_state->compdev); -out: +/* Keep devcom locked to prevent a peer from restarting the worker. */ +if (stop && clock->ptp) +ptp_cancel_worker_sync (clock->ptp); +if (clock->shared) +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); +mlx5_eq_notifier_unregister (mdev, &mdev->clock_state->pps_nb);cancel_work_sync (&mdev->clock_state->out_work); }
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +2 -0
@@ -50,6 +50,8 @@ struct mlx5_timer {struct timecounter tc;u32 nominal_c_mult;unsigned long overflow_period; +u64 saved_phc_ns; +u64 saved_boot_ns; };struct mlx5_clock {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/990 net/mlx5: Lag, free steering resources on LAG destroy failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Bloch <[email protected]>
[ Upstream commit deceb70d1303105e4368a19b251a6fd94428eb11 ]
When firmware fails to destroy LAG, driver returns before releasing the steering resources, leaking the associated software objects.
The bond is no longer eligible for offload, and the driver cannot prevent its teardown. Release the steering resources even if LAG destruction fails. Preserve the error logging and return the original error after cleanup.
--- drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +1 -2
@@ -832,7 +832,6 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev)"Failed to deactivate VF LAG; driver restart required\n" "Make sure all VFs are unbound prior to VF LAG activation or deactivation\n"); } -return err; }if (test_bit (MLX5_LAG_MODE_FLAG_HASH_BASED , &flags)) {
@@ -842,7 +841,7 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev)if (mlx5_lag_has_drop_rule (ldev))mlx5_lag_drop_rule_cleanup (ldev); -return 0 ; +return err; }bool mlx5_lag_check_prereq (struct mlx5_lag *ldev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/990 net: protect negative destination advice with RCU
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 4b77d2792c3e482afa108c08f224ea6fa396d80b ]
SO_CNX_ADVICE calls __dst_negative_advice() while holding the socket lock. Connected UDP sends can still invalidate or replace sk_dst_cache without that lock. A concurrent sk_dst_check() can drop the final destination reference and allow an RCU callback to destroy it while __dst_negative_advice() retains only a borrowed pointer. This can cause a use-after-free while accessing dst->ops or running the negative_advice callback.
The writer-side ordering fixed by commit 92f1655aa2b2 ("net: fix __dst_negative_advice() race") does not protect this reader from an independent cache replacement.
Hold an RCU read-side critical section across the lookup and callback. This follows the datagram release callbacks and covers IPv4, IPv6, and XFRM advice without changing cache-reset or reference-ownership rules.
--- include/net/sock.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/net/sock.h +4 -1
@@ -2176,10 +2176,13 @@ sk_dst_get(const struct sock *sk)static inline void __dst_negative_advice (struct sock *sk) { -struct dst_entry *dst =__sk_dst_get (sk); +struct dst_entry *dst; +rcu_read_lock (); + dst =__sk_dst_get (sk);if (dst && dst->ops->negative_advice) dst->ops->negative_advice (sk, dst); +rcu_read_unlock (); }static inline void dst_negative_advice (struct sock *sk)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/990 net: require a full socket in sock_confirm_neigh()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit c78b47704934e44442f4e48bfdcc99039e3b85a5 ]
An skb can retain dst_pending_confirm after its original output and socket owner have changed. For example, a raw MSG_CONFIRM packet can cross veth, have a TCP request socket assigned by TPROXY, and be bridged into gretap. Neighbor output for the outer packet then calls sock_confirm_neigh() with the request socket in skb->sk.
The helper unconditionally treats a non-NULL skb->sk as a full socket when accessing sk_dst_pending_confirm. TCP request and TIME_WAIT sockets do not contain that field. This produces an out-of-bounds four-byte read and, if the word is nonzero, an out-of-bounds four-byte zero write. A KASAN-enabled kernel reports:
BUG: KASAN: slab-out-of-bounds in ip_finish_output2+0xc9f/0xd60 Read of size 4 at addr ffff8880bdc3d880 by task tproxy_dst_conf/1771
Require sk_fullsock() before accessing the socket field, moving the existing helper earlier in the header to make it available here. Keep neigh_confirm() independent of the socket type so the skb's neighbor confirmation still works, including for socketless packets. This also covers the IPv6, VRF, and BPF neighbor-output callers.
--- include/net/sock.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
include/net/sock.h +10 -9
@@ -2231,6 +2231,14 @@ struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie);struct dst_entry *sk_dst_check (struct sock *sk,u32 cookie); +/* This helper checks if a socket is a full socket, +* ie _not_ a timewait or request socket. +*/ +static inline bool sk_fullsock (const struct sock *sk) +{ +return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT |TCPF_NEW_SYN_RECV ); +} +static inline void sk_dst_confirm (struct sock *sk) {if (!READ_ONCE (sk->sk_dst_pending_confirm))
@@ -2242,7 +2250,8 @@ static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n)if (skb_get_dst_pending_confirm (skb)) {struct sock *sk = skb->sk; -if (sk &&READ_ONCE (sk->sk_dst_pending_confirm)) +if (sk &&sk_fullsock (sk) && +READ_ONCE (sk->sk_dst_pending_confirm))WRITE_ONCE (sk->sk_dst_pending_confirm,0 );neigh_confirm (n); }
@@ -2966,14 +2975,6 @@ skb_sk_is_prefetched(struct sk_buff *skb)#endif /* CONFIG_INET */ } -/* This helper checks if a socket is a full socket, -* ie _not_ a timewait or request socket. -*/ -static inline bool sk_fullsock (const struct sock *sk) -{ -return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT |TCPF_NEW_SYN_RECV ); -} -static inline bool sk_is_refcounted (struct sock *sk) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/990 ipvlan: make outbound skb headers writable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit a45dbf182137275f44ad7c8bc8acd23f7af6b2cf ]
In L3 and L3S modes, ipvlan_process_v4_outbound() and ipvlan_process_v6_outbound() hand the skb to ip_local_out() and ip6_local_out(). The IP output path assumes it owns the network header:__ip_local_out() rewrites tot_len and the header checksum, and transport-mode XFRM can memmove the network header into the headroom when xfrm_skb_check_space() finds enough room, without copying.
The skb reaching ipvlan can have its header shared with another skb, for example after an AF_PACKET tap on the ipvlan device or a tc mirred mirror action. pskb_network_may_pull() only makes the header linear; it does not unshare an already linear head. The writes above then modify the other skb. If that skb is on the receive path and its IPv4 header was already validated, IPv4 option processing can use the modified header, write past the linear data, and corrupt skb_shared_info.
Use skb_cow_head() before taking header pointers and entering the local IP output path, like ip_forward() does with skb_cow() before it touches the header. Only checking skb_header_cloned() is enough here: skbs that TCP transmits are clones of the write-queue skb, whose header area has been released with __skb_header_release(). Their headers are private, so they are not copied, which avoids a reallocation for every TCP segment sent through an ipvlan slave.
If the allocation fails, the existing error accounting and drop paths are used. L2 mode is unaffected.
[edumazet: use skb_cow_head() instead of skb_unclone() to avoid
copying every TCP segment, reword changelog]
--- drivers/net/ipvlan/ipvlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ipvlan/ipvlan_core.c +4 -2
@@ -425,7 +425,8 @@ static noinline_for_stack int ipvlan_process_v4_outbound(struct sk_buff *skb) .flowi4_mark = skb->mark, }; -if (!pskb_network_may_pull (skb,sizeof (struct iphdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct iphdr )) || +skb_cow_head (skb,0 )) goto err; ip4h =ip_hdr (skb);
@@ -491,7 +492,8 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb)struct net_device *dev = skb->dev;int err, ret =NET_XMIT_DROP ; -if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr ))) { +if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )) || +skb_cow_head (skb,0 )) {DEV_STATS_INC (dev, tx_errors);kfree_skb (skb);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/990 wifi: mac80211: mesh: dont linearize SKBs unnecessarily
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 6a6db144d96352967623f38692dfc4b4fb814518 ]
If mesh fast-xmit cannot be used due to aggregation not being fully set up yet, there's no need to linearize the SKB. Avoid that, which addresses a stale pointer issue in the caller.
--- net/mac80211/rx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/mac80211/rx.c +4 -3
@@ -2818,9 +2818,6 @@ ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata,if (!sta)return false; -if (skb_linearize (skb)) -return false; - tid = skb->priority &IEEE80211_QOS_CTL_TAG1D_MASK ; tid_tx =rcu_dereference (sta->ampdu_mlme.tid_tx[tid]);if (tid_tx) {
@@ -2831,6 +2828,10 @@ ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata, tid_tx->last_tx = jiffies; } +/* this function must not fail after this */ +if (skb_linearize (skb)) +return false; +ieee80211_aggr_check (sdata, sta, skb); if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/990 wifi: mac80211: abort chanswitch when leaving an IBSS
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit 12f97c692dcbce088554a5530c79c55174ccee1a ]
ieee80211_ibss_disconnect() leaves CSA active, as ieee80211_stop_mesh() did until commit ac7472a24bd4 ("wifi: mac80211: abort chanswitch when leaving a mesh"). An IBSS left during its countdown and joined again refuses every new channel switch with -EBUSY.
Abort the channel switch the same way.
--- net/mac80211/ibss.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/ibss.c +4 -0
@@ -676,6 +676,10 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata) ifibss->state =IEEE80211_IBSS_MLME_SEARCH ;netif_carrier_off (sdata->dev); + + sdata->vif.bss_conf.csa_active = false; +ieee80211_vif_unblock_queues_csa (sdata); +if (!sta_info_flush (sdata,-1 ))synchronize_net ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/990 net: fix mac_len of skbs copied by generic XDP
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianyi Gao <[email protected]>
[ Upstream commit 71578e43b8a6723025579a08a707f4975a3cd567 ]
skb_pp_cow_data() copies the header fields of the old skb with skb_copy_header(). skb_copy_header() does not copy mac_len.
Generic XDP uses skb_pp_cow_data() for programs with frags support. After such a program, the skb can have mac_len 0. cpu_map_generic_redirect() and tc ingress then get the position of the Ethernet header wrong.
Copy mac_len in skb_pp_cow_data(), as dev_map_generic_redirect() does after skb_copy().
--- net/core/skbuff.c | 1 + 1 file changed, 1 insertion(+)
net/core/skbuff.c +1 -0
@@ -934,6 +934,7 @@ int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,skb_reserve (nskb, headroom);skb_copy_header (nskb, skb); + nskb->mac_len = skb->mac_len;skb_mark_for_recycle (nskb); err =skb_copy_bits (skb,0 , nskb->data, size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/990 ovl: allow idmapping overlay mounts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit adedb6a00a1e4c77b1de9ea1f63b5008ad0c21f5 ]
Now that every overlay inode operation honors the overlay mount idmap, allow the merged overlay mount itself to be idmapped by setting FS_ALLOW_IDMAP on ovl_fs_type. mount_setattr(MOUNT_ATTR_IDMAP) can then apply an idmapping to an overlay mount, exposing the merged tree under a different ownership view.
The composition is clean because overlayfs already normalizes every underlying id through the relevant layer idmap when it copies attributes into the overlay inode (ovl_copyattr()); the overlay inode's i_{u,g}id are thus "overlay-final" ids. The overlay mount idmap composes on top of that pivot: it is applied to (getattr) and removed from (setattr, create) those ids at the overlay-inode boundary - permission, getattr, setattr, ACL owner checks and inode_init_owner() - while the underlying layers keep being accessed with the mounter's credentials through their own, possibly idmapped, mounts. The mount idmap therefore only changes how the caller sees the overlay inode and never widens the mounter's access to the layers.
This is deliberately the final code patch of the series: only once every operation honors the mount idmap is it safe to make overlay mounts idmappable.
Stable-dep-of: cb6c084182d4 ("ovl: release the upperdir/workdir in-use locks before the umount sync")
--- fs/overlayfs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/overlayfs/super.c +1 -1
@@ -1611,7 +1611,7 @@ struct file_system_type ovl_fs_type = { .name = "overlay", .init_fs_context = ovl_init_fs_context, .parameters = ovl_parameter_spec, - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP, .kill_sb = kill_anon_super, };MODULE_ALIAS_FS ("overlay" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/990 ovl: release the upperdir/workdir in-use locks before the umount sync
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis V. Lunev <[email protected]>
[ Upstream commit cb6c084182d4c69b7eeff0bd519dd7e018749602 ]
The in-use locks on upperdir and workdir are released by ovl_free_fs() from ->put_super(). generic_shutdown_super() calls sync_filesystem() before that, and ovl_sync_fs() syncs the whole upper filesystem, so the locks stay held across a journal commit and a cache flush of the upper fs after the overlay is gone. With index=on a new overlay that uses the same upperdir, or uses it as a lowerdir, fails to mount in that window:
overlayfs: upperdir is in-use as upperdir/workdir of another mount, mount with '-o index=off' to override exclusive upperdir protection.
Userspace hits this when the last reference is not dropped by umount(2) itself. Docker with the containerd snapshotter mounts a snapshot on a thread with a private mount namespace for docker cp and for buildkit, and the superblock dies when that thread exits, after the reply to the client has gone out. The next request then gets EBUSY. The window grows with the flush latency of the upper fs and is there even if nothing was written through the overlay, as the mount itself dirties the upper.
->kill_sb() is called once s_active drops to zero, with no mount and no open file left. Release the locks there, before generic_shutdown_super() runs. What the dying superblock still does to the upper fs, the sync and dropping its references to upper dentries and inodes, does not touch the contents of upperdir or workdir. ovl_free_fs() still releases the locks for a failed mount, so clear the *_locked flags to keep it from unlocking a second time and dropping the lock of a newer mount.
This takes the sync out of the window but does not close it: the final mntput of a dying mount namespace runs from task_work, after the exiting thread may have reported completion. Userspace that needs the directories free should umount(2) before saying the job is done.
--- fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/params.c | 5 +---- fs/overlayfs/super.c | 12 +++++++++++- fs/overlayfs/util.c | 12 ++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-)
fs/overlayfs/overlayfs.h +1 -0
@@ -575,6 +575,7 @@ static inline int ovl_set_impure_dir(struct dentry *dentry)bool ovl_inuse_trylock (struct dentry *dentry);void ovl_inuse_unlock (struct dentry *dentry);bool ovl_is_inuse (struct dentry *dentry); +void ovl_inuse_unlock_all (struct ovl_fs *ofs);bool ovl_need_index (struct dentry *dentry);int ovl_nlink_start (struct dentry *dentry);void ovl_nlink_end (struct dentry *dentry);
fs/overlayfs/params.c +1 -4
@@ -842,15 +842,12 @@ void ovl_free_fs(struct ovl_fs *ofs)struct vfsmount **mounts;unsigned i; +ovl_inuse_unlock_all (ofs);iput (ofs->workbasedir_trap);iput (ofs->workdir_trap);dput (ofs->whiteout);dput (ofs->workdir); -if (ofs->workdir_locked) -ovl_inuse_unlock (ofs->workbasedir);dput (ofs->workbasedir); -if (ofs->upperdir_locked) -ovl_inuse_unlock (ovl_upper_mnt (ofs)->mnt_root);/* Reuse ofs->config.lowerdirs as a vfsmount array before freeing it */ mounts = (struct vfsmount **) ofs->config.lowerdirs;
fs/overlayfs/super.c +11 -1
@@ -1606,13 +1606,23 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)return err; } +static void ovl_kill_sb (struct super_block *sb) +{ +struct ovl_fs *ofs =OVL_FS (sb); + +/* Nothing can modify them now, do not hold them across the sync */ +if (ofs) +ovl_inuse_unlock_all (ofs); +kill_anon_super (sb); +} +struct file_system_type ovl_fs_type = { .owner =THIS_MODULE , .name ="overlay" , .init_fs_context = ovl_init_fs_context, .parameters = ovl_parameter_spec, .fs_flags =FS_USERNS_MOUNT |FS_ALLOW_IDMAP , - .kill_sb = kill_anon_super, + .kill_sb = ovl_kill_sb, };MODULE_ALIAS_FS ("overlay" );
fs/overlayfs/util.c +12 -0
@@ -1064,6 +1064,18 @@ bool ovl_is_inuse(struct dentry *dentry)return inuse; } +void ovl_inuse_unlock_all (struct ovl_fs *ofs) +{ +if (ofs->workdir_locked) { +ovl_inuse_unlock (ofs->workbasedir); + ofs->workdir_locked = false; + } +if (ofs->upperdir_locked) { +ovl_inuse_unlock (ovl_upper_mnt (ofs)->mnt_root); + ofs->upperdir_locked = false; + } +} +/* * Does this overlay dentry need to be indexed on copy up? */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/990 bonding: fix slave_cnt leak on XDP enslave failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a978095699641d4f83a32b499a981c419c94abca ]
bond_enslave() increments bond->slave_cnt before setting up XDP on the new slave. If that setup fails (slave has no XDP support, already has an XDP program, or dev_xdp_propagate() fails), the error path jumps to err_sysfs_del, which never decrements slave_cnt.
Each failed enslave therefore leaves slave_cnt one too high:
- SIOCBONDINFOQUERY reports a wrong num_slaves,
- balance-rr picks slave ids beyond the end of the slave list, so bond_get_slave_by_id() falls back to the first usable slave and transmit is skewed toward it.
Reproducer:
ip link add bond0 type bond mode balance-rr ip link set bond0 xdpdrv obj xdp_dummy.bpf.o sec xdp for i in 0 1 2; do
ip link add d$i type dummy
ip link set d$i master bond0 # fails: Slave does not support XDP
done
num_slaves read via SIOCBONDINFOQUERY is 3 before this patch, 0 after.
Add an err_dec_slave_cnt label ahead of err_sysfs_del and use it from the three XDP failure paths, which are the only failures after the increment.
--- drivers/net/bonding/bond_main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +6 -3
@@ -2307,7 +2307,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,SLAVE_NL_ERR (bond_dev, slave_dev, extack,"Slave does not support XDP" ); res = -EOPNOTSUPP ; - goto err_sysfs_del; + goto err_dec_slave_cnt; } }else if (bond->xdp_prog) { struct netdev_bpf xdp = {
@@ -2321,14 +2321,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,SLAVE_NL_ERR (bond_dev, slave_dev, extack,"Slave has XDP program loaded, please unload before enslaving" ); res = -EOPNOTSUPP ; - goto err_sysfs_del; + goto err_dec_slave_cnt; } res =dev_xdp_propagate (slave_dev, &xdp);if (res <0 ) {/* ndo_bpf() sets extack error message */ slave_dbg (bond_dev, slave_dev,"Error %d calling ndo_bpf\n" , res); - goto err_sysfs_del; + goto err_dec_slave_cnt; }if (bond->xdp_prog)bpf_prog_inc (bond->xdp_prog);
@@ -2350,6 +2350,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,return 0 ;/* Undo stages on error */ +err_dec_slave_cnt: +WRITE_ONCE (bond->slave_cnt, bond->slave_cnt -1 ); + err_sysfs_del:bond_sysfs_slave_del (new_slave);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/990 NFSv4: wake blocking lock waiters when a delegated lock is released
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olga Kornievskaia <[email protected]>
[ Upstream commit e8433473eca284bc561373d0a0fff632f76aa594 ]
When the client holds a delegation, _nfs4_proc_setlk() caches POSIX locks locally and never sends a LOCK to the server. It has to strip FL_SLEEP to do so, since that branch runs holding sp->so_delegreturn_mutex and nfsi->rwsem and F_SETLKW can block indefinitely. A contending waiter is therefore never placed on the VFS blocked-lock list, and locks_wake_up_blocks() does not reach it when the holder releases.
The waiter blocks in nfs4_retry_setlk() on clp->cl_lock_waitq instead, whose only waker is nfs4_callback_notify_lock(). The server never saw a LOCK for a cached lock, so it does not know anyone is waiting and will never send a CB_NOTIFY_LOCK; nfs4_proc_unlck() returns early without sending LOCKU for the same reason. The waiter sleeps out the full NFS4_LOCK_MAXTIMEOUT of 30s before retrying a lock that is long free.
Wake cl_lock_waitq when releasing a cached lock. The releasing thread cannot tell which waiter wants the lock, so the wakeup names only the inode; make the owner comparison in nfs4_wake_lock_waiter() conditional on cbnl_valid so that a CB_NOTIFY_LOCK still wakes exactly the owner it names. The inode restriction matters: without it every blocked locker for the server is woken, and those on non-delegated state each retry with a LOCK RPC.
--- fs/nfs/nfs4proc.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
fs/nfs/nfs4proc.c +16 -3
@@ -7323,8 +7323,15 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *if (status !=0 ) goto out;/* Is this a delegated lock? */ -if (test_bit (NFS_LOCK_INITIALIZED , &lsp->ls_flags) ==0 ) +if (test_bit (NFS_LOCK_INITIALIZED , &lsp->ls_flags) ==0 ) { +struct nfs_client *clp =NFS_SERVER (inode)->nfs_client; +struct cb_notify_lock_args cbnl = { .cbnl_valid = false }; + +/* The server never saw it, so it will not notify waiters */ +nfs_copy_fh (&cbnl.cbnl_fh,NFS_FH (inode)); +__wake_up (&clp->cl_lock_waitq,TASK_NORMAL ,0 , &cbnl); goto out; + } alloc_seqid =NFS_SERVER (inode)->nfs_client->cl_mvops->alloc_seqid; seqid =alloc_seqid (&lsp->ls_seqid,GFP_KERNEL ); status = -ENOMEM ;
@@ -7746,8 +7753,14 @@ nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, vostruct nfs_lowner *lowner = &cbnl->cbnl_owner, *wowner = &waiter->owner; -/* Only wake if the callback was for the same owner. */ -if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) +/* +* Only wake the owner a CB_NOTIFY_LOCK names. A lock cached +* under a delegation is released locally, and the releasing +* thread cannot tell which waiter wants it, so those wakeups +* (cbnl_valid false) name only the inode and wake them all. +*/ +if (cbnl->cbnl_valid && + (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev))return 0 ;/* Make sure it's for the right inode */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/990 tun: delete the flow entries of the moved queue on detach
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Umang Pokhriyal <[email protected]>
[ Upstream commit 4cc0a3f897074cea28dae38f1cd9bb230dae5d86 ]
When a queue is detached, __tun_detach() moves the last queue into the freed slot and decrements tun->numqueues. The flow entries that point at the old index of the moved queue, now tun->numqueues, are meant to be deleted, but the call passes tun->numqueues + 1, an index that never exists, so nothing is deleted.
Until those entries are refreshed by a write on their flow or age out, tun_automq_select_queue() returns an index past the last queue, and netdev_core_pick_tx() sends every such flow to queue 0 and warns:
tapq0 selects TX queue 3, but real number of TX queues is 3
Found with an LLM while testing how a VMM detaches tap queues when a guest lowers its virtio-net queue pairs. With four queues, 30 flows learned on queue 3 and queue 1 detached, all 30 went to queue 0 with the warning; with this patch they are spread by hash and no warning is printed (3 runs each, in a guest booted on net).
Pass tun->numqueues.
--- drivers/net/tun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tun.c +1 -1
@@ -607,7 +607,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean) }synchronize_net (); -tun_flow_delete_by_queue (tun, tun->numqueues +1 ); +tun_flow_delete_by_queue (tun, tun->numqueues);/* Drop read queue */ tun_queue_purge (tfile);tun_set_real_num_queues (tun);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/990 fbnic: Rename PCS IRQ to MAC IRQ as it is actually a MAC interrupt
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit f18dd1b15f7a0bea5743fcbf3a62b7d2940e2dd5 ]
Throughout several spots in the code I had called out the IRQ as being related to the PCS. However the actual IRQ is a part of the MAC and it is just exposing PCS data. To more accurately reflect the owner of the calls this change makes it so that we rename the functions and values that are taking in the interrupt value and processing it to reflect that it is a MAC call and not a PCS one.
This change is mostly motivated by the fact that we will be moving the handling of this interrupt from being PCS focused to being more PMA/PMD focused as this will drive the phydev driver that I am adding instead of driving the PCS directly.
Stable-dep-of: 05ec5504ff69 ("fbnic: Fix service task races with ndo_stop and PM suspend")
--- drivers/net/ethernet/meta/fbnic/fbnic.h | 6 ++-- drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 30 +++++++++---------- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 14 ++++----- drivers/net/ethernet/meta/fbnic/fbnic_mac.h | 8 ++--- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 4 +-- .../net/ethernet/meta/fbnic/fbnic_phylink.c | 2 +- 6 files changed, 32 insertions(+), 32 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic.h +3 -3
@@ -34,7 +34,7 @@ struct fbnic_dev {u32 __iomem *uc_addr4;const struct fbnic_mac *mac;unsigned int fw_msix_vector; -unsigned int pcs_msix_vector; +unsigned int mac_msix_vector;unsigned short num_irqs;struct {
@@ -180,8 +180,8 @@ void fbnic_fw_free_mbx(struct fbnic_dev *fbd);void fbnic_hwmon_register (struct fbnic_dev *fbd);void fbnic_hwmon_unregister (struct fbnic_dev *fbd); -int fbnic_pcs_request_irq (struct fbnic_dev *fbd); -void fbnic_pcs_free_irq (struct fbnic_dev *fbd); +int fbnic_mac_request_irq (struct fbnic_dev *fbd); +void fbnic_mac_free_irq (struct fbnic_dev *fbd);void fbnic_napi_name_irqs (struct fbnic_dev *fbd); int fbnic_napi_request_irq(struct fbnic_dev *fbd,
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +15 -15
@@ -118,12 +118,12 @@ void fbnic_fw_free_mbx(struct fbnic_dev *fbd) fbd->fw_msix_vector =0 ; } -static irqreturn_t fbnic_pcs_msix_intr (int __always_unused irq,void *data) +static irqreturn_t fbnic_mac_msix_intr (int __always_unused irq,void *data) {struct fbnic_dev *fbd = data;struct fbnic_net *fbn; -if (fbd->mac->pcs_get_link_event (fbd) ==FBNIC_LINK_EVENT_NONE ) { +if (fbd->mac->get_link_event (fbd) ==FBNIC_LINK_EVENT_NONE ) {fbnic_wr32 (fbd,FBNIC_INTR_MASK_CLEAR (0 ),1u <<FBNIC_PCS_MSIX_ENTRY );return IRQ_HANDLED ;
@@ -137,20 +137,20 @@ static irqreturn_t fbnic_pcs_msix_intr(int __always_unused irq, void *data) }/** -* fbnic_pcs_request_irq - Configure the PCS to enable it to advertise link +* fbnic_mac_request_irq - Configure the MAC to enable it to advertise link * @fbd: Pointer to device to initialize * -* This function provides basic bringup for the MAC/PCS IRQ. For now the IRQ +* This function provides basic bringup for the MAC/PHY IRQ. For now the IRQ * will remain disabled until we start the MAC/PCS/PHY logic via phylink. * * Return: non-zero on failure. **/ -int fbnic_pcs_request_irq (struct fbnic_dev *fbd) +int fbnic_mac_request_irq (struct fbnic_dev *fbd) {struct pci_dev *pdev =to_pci_dev (fbd->dev);int vector, err; -WARN_ON (fbd->pcs_msix_vector); +WARN_ON (fbd->mac_msix_vector); vector =pci_irq_vector (pdev,FBNIC_PCS_MSIX_ENTRY );if (vector <0 )
@@ -159,7 +159,7 @@ int fbnic_pcs_request_irq(struct fbnic_dev *fbd)/* Request the IRQ for PCS link vector. * Map PCS cause to it, and unmask it */ - err =request_irq (vector, &fbnic_pcs_msix_intr,0 , + err =request_irq (vector, &fbnic_mac_msix_intr,0 , fbd->netdev->name, fbd);if (err)return err;
@@ -168,22 +168,22 @@ int fbnic_pcs_request_irq(struct fbnic_dev *fbd)fbnic_wr32 (fbd,FBNIC_INTR_MSIX_CTRL (FBNIC_INTR_MSIX_CTRL_PCS_IDX ),FBNIC_PCS_MSIX_ENTRY |FBNIC_INTR_MSIX_CTRL_ENABLE ); - fbd->pcs_msix_vector = vector; + fbd->mac_msix_vector = vector;return 0 ; }/** -* fbnic_pcs_free_irq - Teardown the PCS IRQ to prepare for stopping +* fbnic_mac_free_irq - Teardown the MAC IRQ to prepare for stopping * @fbd: Pointer to device that is stopping * -* This function undoes the work done in fbnic_pcs_request_irq and prepares +* This function undoes the work done in fbnic_mac_request_irq and prepares * the device to no longer receive traffic on the host interface. **/ -void fbnic_pcs_free_irq (struct fbnic_dev *fbd) +void fbnic_mac_free_irq (struct fbnic_dev *fbd) {/* Vector has already been freed */ -if (!fbd->pcs_msix_vector) +if (!fbd->mac_msix_vector)return ;/* Disable interrupt */
@@ -192,14 +192,14 @@ void fbnic_pcs_free_irq(struct fbnic_dev *fbd)fbnic_wrfl (fbd);/* Synchronize IRQ to prevent race that would unmask vector */ -synchronize_irq (fbd->pcs_msix_vector); +synchronize_irq (fbd->mac_msix_vector);/* Mask the vector */ fbnic_wr32 (fbd,FBNIC_INTR_MASK_SET (0 ),1u <<FBNIC_PCS_MSIX_ENTRY );/* Free the vector */ -free_irq (fbd->pcs_msix_vector, fbd); - fbd->pcs_msix_vector =0 ; +free_irq (fbd->mac_msix_vector, fbd); + fbd->mac_msix_vector =0 ; }void fbnic_synchronize_irq (struct fbnic_dev *fbd,int nr)
drivers/net/ethernet/meta/fbnic/fbnic_mac.c +7 -7
@@ -434,14 +434,14 @@ static void fbnic_mac_tx_pause_config(struct fbnic_dev *fbd, bool tx_pause)wr32 (fbd,FBNIC_RXB_PAUSE_DROP_CTRL , rxb_pause_ctrl); } -static int fbnic_pcs_get_link_event_asic (struct fbnic_dev *fbd) +static int fbnic_mac_get_link_event (struct fbnic_dev *fbd) { -u32 pcs_intr_mask =rd32 (fbd,FBNIC_SIG_PCS_INTR_STS ); +u32 intr_mask =rd32 (fbd,FBNIC_SIG_PCS_INTR_STS ); -if (pcs_intr_mask &FBNIC_SIG_PCS_INTR_LINK_DOWN ) +if (intr_mask &FBNIC_SIG_PCS_INTR_LINK_DOWN )return FBNIC_LINK_EVENT_DOWN ; -return (pcs_intr_mask &FBNIC_SIG_PCS_INTR_LINK_UP ) ? +return (intr_mask &FBNIC_SIG_PCS_INTR_LINK_UP ) ?FBNIC_LINK_EVENT_UP :FBNIC_LINK_EVENT_NONE ; }
@@ -521,7 +521,7 @@ static bool fbnic_mac_get_pcs_link_status(struct fbnic_dev *fbd)return !lane_mask; } -static bool fbnic_pcs_get_link_asic (struct fbnic_dev *fbd) +static bool fbnic_mac_get_link (struct fbnic_dev *fbd) {bool link;
@@ -869,8 +869,8 @@ static const struct fbnic_mac fbnic_mac_asic = { .init_regs = fbnic_mac_init_regs, .pcs_enable = fbnic_pcs_enable_asic, .pcs_disable = fbnic_pcs_disable_asic, - .pcs_get_link = fbnic_pcs_get_link_asic, - .pcs_get_link_event = fbnic_pcs_get_link_event_asic, + .get_link = fbnic_mac_get_link, + .get_link_event = fbnic_mac_get_link_event, .get_fec_stats = fbnic_mac_get_fec_stats, .get_pcs_stats = fbnic_mac_get_pcs_stats, .get_eth_mac_stats = fbnic_mac_get_eth_mac_stats,
drivers/net/ethernet/meta/fbnic/fbnic_mac.h +4 -4
@@ -59,9 +59,9 @@ enum fbnic_sensor_id {* Configure and enable PCS to enable link if not already enabled * void (*pcs_disable)(struct fbnic_dev *fbd); * Shutdown the link if we are the only consumer of it. -* bool (*pcs_get_link)(struct fbnic_dev *fbd); +* bool (*get_link)(struct fbnic_dev *fbd); * Check PCS link status -* int (*pcs_get_link_event)(struct fbnic_dev *fbd) +* int (*get_link_event)(struct fbnic_dev *fbd) * Get the current link event status, reports true if link has * changed to either FBNIC_LINK_EVENT_DOWN or FBNIC_LINK_EVENT_UP *
@@ -76,8 +76,8 @@ struct fbnic_mac {int (*pcs_enable)(struct fbnic_dev *fbd);void (*pcs_disable)(struct fbnic_dev *fbd); -bool (*pcs_get_link)(struct fbnic_dev *fbd); -int (*pcs_get_link_event)(struct fbnic_dev *fbd); +bool (*get_link)(struct fbnic_dev *fbd); +int (*get_link_event)(struct fbnic_dev *fbd);void (*get_fec_stats)(struct fbnic_dev *fbd,bool reset,struct fbnic_fec_stats *fec_stats);
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +2 -2
@@ -44,7 +44,7 @@ int __fbnic_open(struct fbnic_net *fbn)if (err) goto time_stop; - err =fbnic_pcs_request_irq (fbd); + err =fbnic_mac_request_irq (fbd);if (err) goto time_stop;
@@ -89,7 +89,7 @@ static int fbnic_stop(struct net_device *netdev)phylink_suspend (fbn->phylink,fbnic_bmc_present (fbn->fbd));fbnic_down (fbn); -fbnic_pcs_free_irq (fbn->fbd); +fbnic_mac_free_irq (fbn->fbd);fbnic_time_stop (fbn);fbnic_fw_xmit_ownership_msg (fbn->fbd, false);
drivers/net/ethernet/meta/fbnic/fbnic_phylink.c +1 -1
@@ -132,7 +132,7 @@ fbnic_phylink_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, state->duplex =DUPLEX_FULL ; - state->link = fbd->mac->pcs_get_link (fbd); + state->link = fbd->mac->get_link (fbd); } static int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/990 fbnic: Add logic to track PMD state via MAC/PCS signals
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit 9963117a2b9b29074763ccb62fe8ee4d78ca46f2 ]
One complication with the design of our part is that the PMD doesn't provide a direct signal to the host. Instead we have visibility to signals that the PCS provides to the MAC that allow us to check the link state through that.
We will need to account for several things in the PMD and firmware when managing the link. Specifically when the link first starts to come up the PMD will cause the link to flap. This is due to the firmware starting a training cycle when the link is first detected. This will cause link flapping if we were to immediately report link up when the PCS first detects it.
To address that we are adding a pmd_state variable that is meant to be a countdown of sorts indicating the state of the PMD. If the link is down or has been reconfigured the PMD will start out in the initialize state. By default the link is assumed to be in the SEND_DATA state if it is available on initial link inspection. If link is detected while in the initialize state the PMD state will switch to training, and if after 4 seconds the link is still stable we will transition to link_ready, and finally the send_data state. With this we can avoid link flapping when a cable is first connected to the NIC.
One side effect of this is that we need to pull the link state away from the PCS. For now we use a union of the PCS link state register value and the pmd_state. The plan is to add a PMD register to report the pmd_state to the phylink interface. With that we can then look at switching over to the use of the XPCS driver for fbnic instead of having an internal one.
Stable-dep-of: 05ec5504ff69 ("fbnic: Fix service task races with ndo_stop and PM suspend")
--- drivers/net/ethernet/meta/fbnic/fbnic.h | 4 + drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 2 + drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 4 +- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 69 ++++++++---- drivers/net/ethernet/meta/fbnic/fbnic_mac.h | 36 +++++-- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 2 +- .../net/ethernet/meta/fbnic/fbnic_netdev.h | 2 +- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 6 +- .../net/ethernet/meta/fbnic/fbnic_phylink.c | 102 ++++++++++++++---- 9 files changed, 175 insertions(+), 52 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic.h +4 -0
@@ -83,6 +83,10 @@ struct fbnic_dev {/* Last @time_high refresh time in jiffies (to catch stalls) */ unsigned long last_read; +/* PMD specific data */ +unsigned long end_of_pmd_training; +u8 pmd_state; +/* Local copy of hardware statistics */ struct fbnic_hw_stats hw_stats;
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +2 -0
@@ -787,6 +787,8 @@ enum {/* MAC PCS registers */ #define FBNIC_CSR_START_PCS 0x10000/* CSR section delimiter */ +#define FBNIC_PCS_PAGE (n) (0x10000 + 0x400 * (n))/* 0x40000 + 1024*n */ +#define FBNIC_PCS (reg, n) ((reg) + FBNIC_PCS_PAGE(n))#define FBNIC_CSR_END_PCS 0x10668/* CSR section delimiter */ #define FBNIC_CSR_START_RSFEC 0x10800/* CSR section delimiter */
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +3 -1
@@ -131,7 +131,9 @@ static irqreturn_t fbnic_mac_msix_intr(int __always_unused irq, void *data) fbn =netdev_priv (fbd->netdev); -phylink_pcs_change (&fbn->phylink_pcs, false); +/* Record link down events */ +if (!fbd->mac->get_link (fbd, fbn->aui, fbn->fec)) +phylink_pcs_change (&fbn->phylink_pcs, false);return IRQ_HANDLED ; }
drivers/net/ethernet/meta/fbnic/fbnic_mac.c +51 -18
125 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_mac.h +27 -9
@@ -10,6 +10,24 @@ struct fbnic_dev;#define FBNIC_MAX_JUMBO_FRAME_SIZE 9742 +/* States loosely based on section 136.8.11.7.5 of IEEE 802.3-2022 Ethernet +* Standard. These are needed to track the state of the PHY as it has a delay +* of several seconds from the time link comes up until it has completed +* training that we need to wait to report the link. +* +* Currently we treat training as a single block as this is managed by the +* firmware. +* +* We have FBNIC_PMD_SEND_DATA set to 0 as the expected default at driver load +* and we initialize the structure containing it to zero at allocation. +*/ +enum { +FBNIC_PMD_SEND_DATA =0x0 , +FBNIC_PMD_INITIALIZE =0x1 , +FBNIC_PMD_TRAINING =0x2 , +FBNIC_PMD_LINK_READY =0x3 , +}; +enum {FBNIC_LINK_EVENT_NONE =0 ,FBNIC_LINK_EVENT_UP =1 ,
@@ -55,15 +73,15 @@ enum fbnic_sensor_id {* void (*init_regs)(struct fbnic_dev *fbd); * Initialize MAC registers to enable Tx/Rx paths and FIFOs. * -* void (*pcs_enable)(struct fbnic_dev *fbd); -* Configure and enable PCS to enable link if not already enabled -* void (*pcs_disable)(struct fbnic_dev *fbd); -* Shutdown the link if we are the only consumer of it. -* bool (*get_link)(struct fbnic_dev *fbd); -* Check PCS link status * int (*get_link_event)(struct fbnic_dev *fbd) * Get the current link event status, reports true if link has * changed to either FBNIC_LINK_EVENT_DOWN or FBNIC_LINK_EVENT_UP +* bool (*get_link)(struct fbnic_dev *fbd, u8 aui, u8 fec); +* Check link status +* +* void (*prepare)(struct fbnic_dev *fbd, u8 aui, u8 fec); +* Prepare PHY for init by fetching settings, disabling interrupts, +* and sending an updated PHY config to FW if needed. * * void (*link_down)(struct fbnic_dev *fbd); * Configure MAC for link down event
@@ -74,10 +92,10 @@ enum fbnic_sensor_id {struct fbnic_mac {void (*init_regs)(struct fbnic_dev *fbd); -int (*pcs_enable)(struct fbnic_dev *fbd); -void (*pcs_disable)(struct fbnic_dev *fbd); -bool (*get_link)(struct fbnic_dev *fbd);int (*get_link_event)(struct fbnic_dev *fbd); +bool (*get_link)(struct fbnic_dev *fbd,u8 aui,u8 fec); + +void (*prepare)(struct fbnic_dev *fbd,u8 aui,u8 fec);void (*get_fec_stats)(struct fbnic_dev *fbd,bool reset,struct fbnic_fec_stats *fec_stats);
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +1 -1
@@ -86,10 +86,10 @@ static int fbnic_stop(struct net_device *netdev) {struct fbnic_net *fbn =netdev_priv (netdev); +fbnic_mac_free_irq (fbn->fbd);phylink_suspend (fbn->phylink,fbnic_bmc_present (fbn->fbd));fbnic_down (fbn); -fbnic_mac_free_irq (fbn->fbd);fbnic_time_stop (fbn);fbnic_fw_xmit_ownership_msg (fbn->fbd, false);
drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +1 -1
@@ -111,7 +111,7 @@ int fbnic_phylink_ethtool_ksettings_get(struct net_device *netdev,int fbnic_phylink_get_fecparam (struct net_device *netdev,struct ethtool_fecparam *fecparam);int fbnic_phylink_init (struct net_device *netdev); - +void fbnic_phylink_pmd_training_complete_notify (struct net_device *netdev);bool fbnic_check_split_frames (struct bpf_prog *prog,unsigned int mtu,u32 hds_threshold);#endif /* _FBNIC_NETDEV_H_ */
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +5 -1
@@ -211,6 +211,10 @@ static void fbnic_service_task(struct work_struct *work) {struct fbnic_dev *fbd =container_of (to_delayed_work (work), struct fbnic_dev, service_task); +struct net_device *netdev = fbd->netdev; + +if (netif_running (netdev)) +fbnic_phylink_pmd_training_complete_notify (netdev);rtnl_lock ();
@@ -228,7 +232,7 @@ static void fbnic_service_task(struct work_struct *work)netdev_unlock (fbd->netdev); } -if (netif_running (fbd->netdev)) +if (netif_running (netdev))schedule_delayed_work (&fbd->service_task,HZ );rtnl_unlock ();
drivers/net/ethernet/meta/fbnic/fbnic_phylink.c +81 -21
136 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/990 fbnic: Fix service task races with ndo_stop and PM suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit 05ec5504ff69dac8867292c0e778fe79c3dde83c ]
The service task can run after the datapath has been torn down underneath it. ndo_stop stops the task with the cancel_delayed_work function, which does not wait for a pass already executing. It cannot use the cancel_delayed_work_sync function, as ndo_stop holds RTNL and the task takes RTNL itself, so a pass blocked on RTNL while ndo_stop runs carries on once ndo_stop returns.
By then the fbnic_down function has demoted the host MACDA and action entries to UPDATE and disabled the host queues, and ndo_stop has handed ownership back to firmware, which clears fw_heartbeat_enabled. The late pass's health check reports a firmware crash that did not happen, and the fbnic_fw_config_after_crash function reclaims ownership and writes the host rules back to hardware. If the BMC raised FBNIC_FW_CAP_F_BMC_TCAM_REINIT in that window, the fbnic_bmc_rpc_check function does the same through the __fbnic_set_rx_mode function. Either way host traffic is steered at queues that are no longer running until the next open and close.
The fbnic_pm_suspend function, which also serves shutdown and PCIe error recovery, has the same problem and a worse one. It calls ndo_stop directly with the device detached but __LINK_STATE_START still set, so a late pass there sees the interface running, restores the host state, and keeps re-arming itself every second after the mailbox, IRQs and MMIO are gone.
Only run the health and BMC checks, and only re-arm, while the interface is running and the device is present. The __dev_close_many function clears __LINK_STATE_START under RTNL before it calls ndo_stop, and the suspend path detaches the device under RTNL, so a late pass now leaves the host state alone and stops. The BMC flags stay raised, and the __fbnic_open function reclaims ownership, restarts the heartbeat and rebuilds the BMC rules on the next open. The fbnic_pm_suspend function also cancels the task synchronously once it has dropped RTNL, so a pass already running cannot overlap the mailbox and IRQ teardown.
On resume the __fbnic_pm_attach function called the fbnic_up function, which schedules the next pass, before attaching the device, all without RTNL. A pass that ran in between would now see the device detached and stop for good. Check for an init failure first, then hold RTNL and the instance lock across the stats reset, the fbnic_up call and the attach, as the suspend path does, so the pass blocks until the device is present. This also gives the fbnic_up function the instance lock it expects for the napi_enable_locked calls and the rx mode rewrite.
A device that detaches itself on a failed register read likewise stops re-arming the task until recovery attaches it.
The issue was found by code review. The change was tested on fbnic hardware with firmware 26.09.14-017_h7ab84d2ef68f by cycling the interface through DPC/AER recoveries for a day.
--- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 38 ++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +29 -9
@@ -222,18 +222,25 @@ static void fbnic_service_task(struct work_struct *work)fbnic_fw_check_heartbeat (fbd); -fbnic_health_check (fbd); - -fbnic_bmc_rpc_check (fbd); -if (netif_carrier_ok (fbd->netdev)) {netdev_lock (fbd->netdev);fbnic_napi_depletion_check (fbd->netdev);netdev_unlock (fbd->netdev); } -if (netif_running (netdev)) +/* fbnic_service_task_stop() does not wait for a pass that is already +* blocked on RTNL, so one can run after ndo_stop. Leave host state +* alone in that case, and do not re-arm; __fbnic_open() reclaims and +* rebuilds it. The PM path calls ndo_stop with the device detached but +* still running; fbnic_up() starts the task again on resume. +*/ +if (netif_running (netdev) &&netif_device_present (netdev)) { +fbnic_health_check (fbd); + +fbnic_bmc_rpc_check (fbd); +schedule_delayed_work (&fbd->service_task,HZ ); + }rtnl_unlock (); }
@@ -443,6 +450,12 @@ static int fbnic_pm_suspend(struct device *dev)netdev_unlock (netdev);rtnl_unlock (); +/* ndo_stop could not wait for a pass already blocked on RTNL. That +* pass no longer re-arms, but wait for it to finish before the +* mailbox, IRQs and MMIO go away. +*/ +cancel_delayed_work_sync (&fbd->service_task); + null_uc_addr:fbnic_fw_log_disable (fbd);
@@ -543,19 +556,26 @@ static void __fbnic_pm_attach(struct device *dev)struct net_device *netdev = fbd->netdev;struct fbnic_net *fbn; -rtnl_lock (); -fbnic_reset_hw_stats (fbd); -rtnl_unlock (); -if (fbnic_init_failure (fbd))return ; fbn =netdev_priv (netdev); +/* Hold RTNL until the device is attached, so the service task pass +* fbnic_up() schedules cannot run until it will see it present. +*/ +rtnl_lock (); +netdev_lock (netdev); + +fbnic_reset_hw_stats (fbd); +if (netif_running (netdev))fbnic_up (fbn);netif_device_attach (netdev); + +netdev_unlock (netdev); +rtnl_unlock (); }static int __maybe_unused fbnic_pm_resume (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/990 fbnic: Disable PTP completions during the Tx force-flush
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit 7d4568edce74ac72794cdd42767cc116bf1ca9b4 ]
When the Tx queues fail to go idle, fbnic_wait_all_queues_idle() falls back to fbnic_tx_flush(), which sets FBNIC_TMI_DROP_CTRL_EN. That bit only drops packets at the Tx MAC Interface start of packet protection FIFO.
The PTP completion path is governed by a separate bit in the same register. With only the drop enable set, a timestamped frame has its packet discarded while the matching completion is still forwarded to the host. fbnic_clean_tsq() then walks the ring with no packet left to match it against and reports "Tx timestamp without matching packet". The drop does not retire the completion either, as the completion FIFO is only drained when the completion disable is set.
Set FBNIC_TMI_DROP_CTRL_CMPL_DIS together with the drop enable so the completions are drained rather than leaked to the host, and clear both bits again when the flush is turned off.
--- drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 1 + drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +1 -0
@@ -456,6 +456,7 @@ enum {#define FBNIC_TMI_SOP_PROT_CTRL 0x04400/* 0x11000 */ #define FBNIC_TMI_DROP_CTRL 0x04401/* 0x11004 */ #define FBNIC_TMI_DROP_CTRL_EN CSR_BIT(0) +#define FBNIC_TMI_DROP_CTRL_CMPL_DIS CSR_BIT(1)#define FBNIC_TMI_DROP_PKTS 0x04402/* 0x11008 */ #define FBNIC_TMI_DROP_BYTE_L 0x04403/* 0x1100c */ #define FBNIC_TMI_ILLEGAL_PTP_REQS 0x04409/* 0x11024 */
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +7 -3
@@ -2290,15 +2290,19 @@ void fbnic_disable(struct fbnic_net *fbn)static void fbnic_tx_flush (struct fbnic_dev *fbd) { +u32 drop_ctrl =FBNIC_TMI_DROP_CTRL_EN |FBNIC_TMI_DROP_CTRL_CMPL_DIS ; +netdev_warn (fbd->netdev,"triggering Tx flush\n" ); -fbnic_rmw32 (fbd,FBNIC_TMI_DROP_CTRL ,FBNIC_TMI_DROP_CTRL_EN , -FBNIC_TMI_DROP_CTRL_EN ); +/* Drop packets and retire their PTP completions */ +fbnic_rmw32 (fbd,FBNIC_TMI_DROP_CTRL , drop_ctrl, drop_ctrl); }static void fbnic_tx_flush_off (struct fbnic_dev *fbd) { -fbnic_rmw32 (fbd,FBNIC_TMI_DROP_CTRL ,FBNIC_TMI_DROP_CTRL_EN ,0 ); +u32 drop_ctrl =FBNIC_TMI_DROP_CTRL_EN |FBNIC_TMI_DROP_CTRL_CMPL_DIS ; + +fbnic_rmw32 (fbd,FBNIC_TMI_DROP_CTRL , drop_ctrl,0 ); }struct fbnic_idle_regs {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/990 fbnic: Suspend phylink after taking the datapath down in ndo_stop
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit b45b9c6b83e7a5ac440d36b46ed9b466788b3e5c ]
The fbnic_stop function calls the phylink_suspend function before the fbnic_down function. With no BMC present that stops phylink, and the fbnic_phylink_mac_link_down function disables the MAC and holds its Tx and Rx clocks and FIFOs in reset. Only then does the fbnic_down function stop the queues and wait for the Tx path to go idle, so anything still in flight has to drain into a MAC that is no longer passing traffic, and the fbnic_wait_all_queues_idle function can be left to time out and force a flush. With a BMC present phylink leaves the link up but turns the carrier off, which the phylink_suspend function notes assumes all packets have already been sent.
It is also the reverse of how the interface comes up: the __fbnic_open function resumes phylink last, and the fbnic_up function then enables the queues and installs the host Rx filters.
Call the fbnic_down function first. The Tx path then drains with the link still up, and Rx is still stopped first, as the fbnic_clear_rx_mode and fbnic_clear_rules functions remove the host as a destination for its MAC addresses in the RPC before the queues are disabled. The MAC IRQ is still freed before phylink is suspended, so no link interrupt runs while the link is taken down. The PM suspend path goes through ndo_stop and picks up the same order.
--- drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +2 -2
@@ -86,11 +86,11 @@ static int fbnic_stop(struct net_device *netdev) {struct fbnic_net *fbn =netdev_priv (netdev); +fbnic_down (fbn); +fbnic_mac_free_irq (fbn->fbd);phylink_suspend (fbn->phylink,fbnic_bmc_present (fbn->fbd)); -fbnic_down (fbn); -fbnic_time_stop (fbn);fbnic_fw_xmit_ownership_msg (fbn->fbd, false);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/990 fbnic: Wait for the outbound flush to complete on mailbox teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit c5820a8cf59b03d59f2f5f9b3754ad27a6014a41 ]
The fbnic_mbx_reset_desc_ring function drops bus mastering and arms the outbound flush for its ring: the write flush for the Rx ring and the read flush for the Tx ring. Nothing waits for that flush to finish. The fbnic_mbx_clean_desc_ring function goes straight on to unmap and free the ring's buffers, so a device read of a Tx buffer, or a write to an Rx buffer, can still be outstanding after the buffer is gone. With an IOMMU it can also target an IOVA that has been unmapped or reused.
The PUL link reset status register reports when each direction's flush has drained. Poll the done bit for the ring's direction after arming the flush and before freeing its buffers. The flush only has to retire what the outbound path already holds; the 1ms cap keeps a wedged device from spinning.
Every caller of the fbnic_mbx_clean function runs with the datapath already down, which matters because the read flush covers all outstanding reads, not just the mailbox ones. A device that has lost its link reads back as all ones, so the done bit appears set and the poll ends on the first pass.
--- drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 4 ++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +4 -0
@@ -960,6 +960,10 @@ enum {/* PUL User Registers */ #define FBNIC_CSR_START_PUL_USER 0x31000/* CSR section delimiter */ +#define FBNIC_PUL_USER_IP_LINK_RST_STATUS \ + 0x31030/* 0xc40c0 */ +#define FBNIC_PUL_USER_IP_LINK_RST_STATUS_AW_FLUSH_DONE CSR_BIT(7) +#define FBNIC_PUL_USER_IP_LINK_RST_STATUS_AR_FLUSH_DONE CSR_BIT(8)#define FBNIC_PUL_OB_TLP_HDR_AW_CFG 0x3103d/* 0xc40f4 */ #define FBNIC_PUL_OB_TLP_HDR_AW_CFG_FLUSH_MODE CSR_BIT(20)#define FBNIC_PUL_OB_TLP_HDR_AW_CFG_FLUSH CSR_BIT(19)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +16 -0
@@ -7,6 +7,7 @@#include <linux/dev_printk.h> #include <linux/dma-mapping.h> #include <linux/gfp.h> +#include <linux/iopoll.h> #include <linux/types.h> #include "fbnic.h"
@@ -176,10 +177,25 @@ static void fbnic_mbx_unmap_and_free_msg(struct fbnic_dev *fbd, int mbx_idx,static void fbnic_mbx_clean_desc_ring (struct fbnic_dev *fbd,int mbx_idx) { +u32 flush_done, val;int i;fbnic_mbx_reset_desc_ring (fbd, mbx_idx); +/* Arming the flush only starts it. Wait for the outbound path to +* retire the requests it still holds before the buffers they may +* target are unmapped and freed. A lost link reads back as all ones, +* which ends the poll on the first pass. +*/ + flush_done = mbx_idx ==FBNIC_IPC_MBX_RX_IDX ? +FBNIC_PUL_USER_IP_LINK_RST_STATUS_AW_FLUSH_DONE : +FBNIC_PUL_USER_IP_LINK_RST_STATUS_AR_FLUSH_DONE ; +if (read_poll_timeout_atomic (fbnic_rd32, val, val & flush_done,2 , +1000 , false, fbd, +FBNIC_PUL_USER_IP_LINK_RST_STATUS )) +dev_warn (fbd->dev,"Outbound flush did not complete: %08x\n" , + val); +for (i =FBNIC_IPC_MBX_DESC_LEN ; i--;)fbnic_mbx_unmap_and_free_msg (fbd, mbx_idx, i); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/990 net: Segment CHECKSUM_UNNECESSARY GSO skbs other than fraglist
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit fdca4b030c78fa2773a94fda3a6dc3ce5558a727 ]
The netif_needs_gso function lets a GSO skb reach the device unsegmented when it is CHECKSUM_PARTIAL or CHECKSUM_UNNECESSARY. The second case was added for FCoE, whose transmit path marked CRC offload that way at the time. Commit 253aab0597d9 ("fcoe: Use CHECKSUM_PARTIAL to indicate CRC offload") moved FCoE back to CHECKSUM_PARTIAL but left the exemption in place, with nothing left that needed it. Fraglist GSO, added later, is its only user today, as its segments already carry valid checksums.
A TCP GSO skb can still arrive as CHECKSUM_UNNECESSARY without being fraglist. Hardware LRO builds its aggregates that way, for example mlx5 sets SKB_GSO_TCPV4 or SKB_GSO_TCPV6 and CHECKSUM_UNNECESSARY, without SKB_GSO_DODGY. IP forwarding and bridging turn LRO off, but a tc mirred redirect does not, so such an skb can be sent out another device. It has no csum_start and its TCP checksum field is whatever the aggregate left there. Drivers that only set up TSO for CHECKSUM_PARTIAL, such as fbnic, i40e and ice, then send the whole skb as one oversized frame with a bad checksum.
Have the validate_xmit_skb function mark any CHECKSUM_UNNECESSARY GSO skb other than fraglist as CHECKSUM_NONE, which means the same on transmit but is not exempt in the netif_needs_gso function. The __skb_gso_segment function then unshares the header and the TCP GSO code sets the skb up as CHECKSUM_PARTIAL, so a device with TSO segments it in hardware. Without TSO, and for UDP, it is segmented in software. The callers of the netif_needs_gso function that decide on segmentation for themselves, such as tap, are left as they are.
Found by code inspection. In QEMU with an emulated fbnic, TCPv4 and TCPv6 GSO skbs built this way each went out as a single 11 KB frame with a bad TCP checksum. With this change they are segmented into MSS-sized frames with valid checksums.
--- net/core/dev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/core/dev.c +12 -0
@@ -4045,6 +4045,18 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_deviceif (unlikely (!skb)) goto out_null; +/* Only fraglist GSO, whose segments already carry valid checksums, +* can be handed to a device as CHECKSUM_UNNECESSARY. Any other GSO +* skb has no csum_start for the device to segment from. NONE means +* the same on transmit, but makes netif_needs_gso() send it to the +* GSO code, which turns TCP into CHECKSUM_PARTIAL for TSO and +* segments anything the device cannot offload in software. +*/ +if (unlikely (skb->ip_summed ==CHECKSUM_UNNECESSARY && +skb_is_gso (skb) && + !(skb_shinfo (skb)->gso_type &SKB_GSO_FRAGLIST ))) + skb->ip_summed =CHECKSUM_NONE ; + features =netif_skb_features (skb); skb =validate_xmit_vlan (skb, features);if (unlikely (!skb))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/990 net/mlx5: macsec: Dont remove fs_id when adding a rule fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Changyul Lee <[email protected]>
[ Upstream commit 5175da73dd128520ad6d704d7fe54926ee5f658b ]
macsec_fs_tx_add_rule() and macsec_fs_rx_add_rule() clean up a failed rule with macsec_fs_{tx,rx}_del_rule(), which also calls macsec_fs_id_del(). The fs_id is never in the xarray at that point:macsec_fs_id_add() is the last step of adding a rule and removes its own entry when it fails.
macsec_fs_id_del() then dereferences NULL, through macsec_device for the first SA of a MACsec netdev and through fs_id_found otherwise. On RX, the SAs of one SC share an fs_id, so a failure while adding another SA drops the reference that an existing SA holds.
Split the rule teardown from the fs_id removal and do only the teardown on the error paths.
--- .../mellanox/mlx5/core/lib/macsec_fs.c | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c +24 -14
@@ -764,13 +764,9 @@ static int macsec_fs_id_add(struct list_head *macsec_devices_list, u32 fs_id,return err; } -static void macsec_fs_tx_del_rule (struct mlx5_macsec_fs *macsec_fs, -struct mlx5_macsec_tx_rule *tx_rule, -void *macdev) +static void macsec_fs_tx_free_rule (struct mlx5_macsec_fs *macsec_fs, +struct mlx5_macsec_tx_rule *tx_rule) { -macsec_fs_id_del (&macsec_fs->macsec_devices_list, tx_rule->fs_id, macdev, - &macsec_fs->sci_hash, true); -if (tx_rule->rule) {mlx5_del_flow_rules (tx_rule->rule); tx_rule->rule =NULL ;
@@ -791,6 +787,15 @@ static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs,macsec_fs_tx_ft_put (macsec_fs); } +static void macsec_fs_tx_del_rule (struct mlx5_macsec_fs *macsec_fs, +struct mlx5_macsec_tx_rule *tx_rule, +void *macdev) +{ +macsec_fs_id_del (&macsec_fs->macsec_devices_list, tx_rule->fs_id, macdev, + &macsec_fs->sci_hash, true); +macsec_fs_tx_free_rule (macsec_fs, tx_rule); +} +#define MLX5_REFORMAT_PARAM_ADD_MACSEC_OFFSET_4_BYTES 1 static union mlx5_macsec_rule *
@@ -883,7 +888,7 @@ macsec_fs_tx_add_rule(struct mlx5_macsec_fs *macsec_fs, goto out_spec; err: -macsec_fs_tx_del_rule (macsec_fs, tx_rule, macsec_ctx->secy->netdev); +macsec_fs_tx_free_rule (macsec_fs, tx_rule); macsec_rule =NULL ; out_spec:kvfree (spec);
@@ -1648,15 +1653,11 @@ static void macsec_fs_rx_ft_put(struct mlx5_macsec_fs *macsec_fs)macsec_fs_rx_destroy (macsec_fs); } -static void macsec_fs_rx_del_rule (struct mlx5_macsec_fs *macsec_fs, -struct mlx5_macsec_rx_rule *rx_rule, -void *macdev,u32 fs_id) +static void macsec_fs_rx_free_rule (struct mlx5_macsec_fs *macsec_fs, +struct mlx5_macsec_rx_rule *rx_rule) {int i; -macsec_fs_id_del (&macsec_fs->macsec_devices_list, fs_id, macdev, - &macsec_fs->fs_id_hash, false); -for (i =0 ; i <RX_NUM_OF_RULES_PER_SA ; ++i) {if (rx_rule->rule[i]) {mlx5_del_flow_rules (rx_rule->rule[i]);
@@ -1674,6 +1675,15 @@ static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs,macsec_fs_rx_ft_put (macsec_fs); } +static void macsec_fs_rx_del_rule (struct mlx5_macsec_fs *macsec_fs, +struct mlx5_macsec_rx_rule *rx_rule, +void *macdev,u32 fs_id) +{ +macsec_fs_id_del (&macsec_fs->macsec_devices_list, fs_id, macdev, + &macsec_fs->fs_id_hash, false); +macsec_fs_rx_free_rule (macsec_fs, rx_rule); +} + static void macsec_fs_rx_setup_fte(struct mlx5_flow_spec *spec, struct mlx5_flow_act *flow_act, struct mlx5_macsec_rule_attrs *attrs,
@@ -1833,7 +1843,7 @@ macsec_fs_rx_add_rule(struct mlx5_macsec_fs *macsec_fs,return macsec_rule; err: -macsec_fs_rx_del_rule (macsec_fs, rx_rule, macsec_ctx->secy->netdev, fs_id); +macsec_fs_rx_free_rule (macsec_fs, rx_rule); macsec_rule =NULL ; out_spec:kvfree (spec);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/990 dpll: notify about a reference sync pair only if it was added
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 7a3837929d049dac1f931620f30b100993ce2594 ]
dpll_pin_ref_sync_pair_add() sends a pin change notification even when xa_insert() fails and nothing has changed. zl3073x gets -EBUSY when another channel has already added the same pair and ignores it, so user space is notified about a change that did not happen.
Send the notification only after a successful insert.
Found by code review. Reproduced on a ZL30732A board with kprobes on dpll_pin_ref_sync_pair_add() and __dpll_pin_change_ntf(): loading the driver adds one pair twice and the add failing with -EBUSY sends a notification. With this patch it does not, and the successful add still does. A test module adding one pair twice shows the same on the monitor group.
--- drivers/dpll/dpll_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dpll/dpll_core.c +2 -1
@@ -999,7 +999,8 @@ int dpll_pin_ref_sync_pair_add(struct dpll_pin *pin,mutex_lock (&dpll_lock); ret =xa_insert (&pin->ref_sync_pins, ref_sync_pin->id, ref_sync_pin,GFP_KERNEL ); -__dpll_pin_change_ntf (pin); +if (!ret) +__dpll_pin_change_ntf (pin);mutex_unlock (&dpll_lock);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/990 ipv4: route: dont blackhole in-use routes when retiring fnhe routes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chase Hiltz <[email protected]>
[ Upstream commit ae89f2724db1afa96a1f1b661174fc41ae1e88fa ]
When a route cached in a nexthop exception (fnhe) is replaced or flushed, rt_bind_exception() and fnhe_flush_routes() call dst_dev_put() on it. That sets dst->dev to blackhole_netdev and dst->input/output to dst_discard*(), but other CPUs can still be using the route, e.g. as a noref dst taken from the fnhe under RCU. Packets that reach dst_input() or dst_output() after that are dropped.
If dst_dev_put() runs after a forwarded packet has entered ip_output(), ip_skb_dst_mtu() in __ip_finish_output() can return the MTU of blackhole_netdev (68), and ip_fragment() can then drop a DF packet and send ICMP_FRAG_NEEDED with mtu 68 to its source.
Commit 5018c59607a5 ("ipv4: fix race condition between route lookup and invalidation") fixed the same race in rt_cache_route() by putting the old route on the uncached list instead of calling dst_dev_put(). Do the same for routes retired from an fnhe. rt_flush_dev() still moves them to blackhole_netdev when their device is unregistered.
fnhe routes are also retired on fnhe expiry (ip_del_fnhe()) and eviction (fnhe_remove_oldest()). Those paths don't bump rt_genid, so without the obsolete marking ipv4_dst_check() could still accept the route. Keep marking retired routes DST_OBSOLETE_DEAD, as dst_dev_put() did, so that users that cached them, such as sockets, look up again.
In a netns reproducer that forwards IPv4 traffic over an ip6tnl device, with an fnhe for the destination, while the FIB keeps changing, this patch stops the mtu 68 ICMPs and the drops.
--- net/ipv4/route.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
net/ipv4/route.c +15 -8
@@ -573,6 +573,17 @@ static void ip_rt_build_flow_key(struct flowi4 *fl4, const struct sock *sk,static DEFINE_SPINLOCK (fnhe_lock); +/* Other CPUs may still be using @rt, so don't dst_dev_put() it. +* rt_flush_dev() handles it if its device is unregistered. +* Marking it dead makes ipv4_dst_check() fail for users that cached it. +*/ +static void fnhe_retire_route (struct rtable *rt) +{ +WRITE_ONCE (rt->dst.obsolete,DST_OBSOLETE_DEAD ); +rt_add_uncached_list (rt); +dst_release (&rt->dst); +} +static void fnhe_flush_routes (struct fib_nh_exception *fnhe) {struct rtable *rt;
@@ -580,14 +591,12 @@ static void fnhe_flush_routes(struct fib_nh_exception *fnhe) rt =rcu_dereference (fnhe->fnhe_rth_input);if (rt) {RCU_INIT_POINTER (fnhe->fnhe_rth_input,NULL ); -dst_dev_put (&rt->dst); -dst_release (&rt->dst); +fnhe_retire_route (rt); } rt =rcu_dereference (fnhe->fnhe_rth_output);if (rt) {RCU_INIT_POINTER (fnhe->fnhe_rth_output,NULL ); -dst_dev_put (&rt->dst); -dst_release (&rt->dst); +fnhe_retire_route (rt); } }
@@ -1502,10 +1511,8 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,if (do_cache) {dst_hold (&rt->dst);rcu_assign_pointer (*porig, rt); -if (orig) { -dst_dev_put (&orig->dst); -dst_release (&orig->dst); - } +if (orig) +fnhe_retire_route (orig); ret = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/990 ptp: kvm: x86: Leak clock_pair page if changing its encryption fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 6a01fb125ba6474cb97f14b68fe5435d3cdd08e5 ]
In a confidential guest, kvm_arch_ptp_init() shares the clock_pair page with the host using set_memory_decrypted(), and kvm_arch_ptp_exit() makes it private again with set_memory_encrypted() before freeing it.
The untrusted host can make either call fail and leave the page shared. Both paths still free the page: the init error path with __free_page(), and kvm_arch_ptp_exit() after only a WARN_ON(). The page allocator can then hand a page the host can still access to an unrelated user.
Leak the page in both cases instead, as was done for the same situation in commit b9fa16949d18 ("dma-direct: Leak pages on dma_set_decrypted() failure") and commit 03f5a999adba ("Drivers: hv: vmbus: Leak pages if set_memory_encrypted() fails").
--- drivers/ptp/ptp_kvm_x86.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ptp/ptp_kvm_x86.c +4 -3
@@ -36,7 +36,7 @@ int kvm_arch_ptp_init(void) clock_pair =page_address (p); ret =set_memory_decrypted ((unsigned long )clock_pair,1 );if (ret) { -__free_page (p); +/* The page may be left shared, so leak it. */ clock_pair =NULL ; goto nofree; }
@@ -68,8 +68,9 @@ int kvm_arch_ptp_init(void)void kvm_arch_ptp_exit (void ) {if (cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT )) { -WARN_ON (set_memory_encrypted ((unsigned long )clock_pair,1 )); -free_page ((unsigned long )clock_pair); +/* Leak the page if it cannot be made private again. */ +if (!WARN_ON (set_memory_encrypted ((unsigned long )clock_pair,1 ))) +free_page ((unsigned long )clock_pair); clock_pair =NULL ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/990 net: skbuff: uncharge trimmed zerocopy frags on error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 8b67debdfbf6b370312ebec5c9e0a1c39b5c7733 ]
__zerocopy_sg_from_iter() accounts for the frags that it adds even when it returns an error: it adds the growth of skb->truesize to sk_wmem_queued and, unless the skb is pure zerocopy, charges it to the socket.
On error, skb_zerocopy_iter_stream() cannot free the skb, as it may hold data from an earlier send. It trims the new frags, but leaves skb->truesize and their accounting in place.
Repeated failed sends to the same skb accumulate this stale accounting. This can inflate TCP memory accounting past tcp_mem, and can wrap skb->truesize, leading to a use-after-free of the socket.
Undo the accounting after the trim. If the trim fails, the frags and their accounting remain. The trim only fails if the skb is cloned, which is not expected for the unsent skb at the TCP write queue tail.
The issue was found by an LLM.
--- net/core/skbuff.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/skbuff.c +8 -1
@@ -1859,6 +1859,7 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb,struct ubuf_info *uarg, struct net_devmem_dmabuf_binding *binding) { + unsigned int orig_truesize = skb->truesize;int err, orig_len = skb->len;if (uarg->ops->link_skb) {
@@ -1879,12 +1880,18 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb, err =__zerocopy_sg_from_iter (msg, sk, skb, &msg->msg_iter, len, binding);if (err == -EFAULT || (err == -EMSGSIZE && skb->len == orig_len)) { +u32 delta_truesize = skb->truesize - orig_truesize;struct sock *save_sk = skb->sk;/* Streams do not free skb on error. Reset to prev state. */ iov_iter_revert (&msg->msg_iter, skb->len - orig_len); skb->sk = sk; -___pskb_trim (skb, orig_len); +if (!___pskb_trim (skb, orig_len)) { + skb->truesize -= delta_truesize; +sk_wmem_queued_add (sk, -delta_truesize); +if (!skb_zcopy_pure (skb)) +sk_mem_uncharge (sk, delta_truesize); + } skb->sk = save_sk;return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/990 net/mlx5e: Release IPsec root table reference on RX setup failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit e8303b58108519ff103241442c0a7602fa106af5 ]
Switchdev RX setup takes a root-chain table reference before creating its flow tables. If creation fails, rx_get() returns without incrementing the RX reference count, so rx_destroy() never releases the chain reference.
Extract the cleanup logic in a counter-partner to the function acquiring the root table ref, and call it on error to properly release everything. Also call it from the normal destroy path to reduce code duplication.
mlx5_esw_ipsec_rx_status_pass_dest_get() ignored chain table acquisition errors, returning success with an error pointer as the destination. The new unwind could then release a reference that was never taken. Propagate the error so cleanup only runs after a successful get.
Discovered by Sashiko. Not triggered as it's an unlikely error path.
--- .../mellanox/mlx5/core/en_accel/ipsec_fs.c | 20 +++++++++++-------- .../mellanox/mlx5/core/esw/ipsec_fs.c | 15 ++++++++++++-- .../mellanox/mlx5/core/esw/ipsec_fs.h | 6 ++++++ 3 files changed, 31 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +12 -8
@@ -720,6 +720,16 @@ static void ipsec_rx_sa_selector_destroy(struct mlx5_core_dev *mdev,mlx5_destroy_flow_table (rx->ft.sa_sel); } +static void +ipsec_rx_status_pass_dest_put (struct mlx5e_ipsec *ipsec, +struct mlx5e_ipsec_rx *rx, +u32 family) +{ +mlx5_ipsec_fs_roce_rx_destroy (ipsec->roce, family, ipsec->mdev); +if (rx == ipsec->rx_esw) +mlx5_esw_ipsec_rx_status_pass_dest_put (ipsec); +} +static void rx_destroy (struct mlx5_core_dev *mdev,struct mlx5e_ipsec *ipsec,struct mlx5e_ipsec_rx *rx,u32 family) {
@@ -739,13 +749,7 @@ static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,ipsec_rx_policy_destroy (rx); -mlx5_ipsec_fs_roce_rx_destroy (ipsec->roce, family, mdev); - -#ifdef CONFIG_MLX5_ESWITCH -if (rx == ipsec->rx_esw) -mlx5_chains_put_table (esw_chains (ipsec->mdev->priv.eswitch), -0 ,1 ,0 ); -#endif +ipsec_rx_status_pass_dest_put (ipsec, rx, family); } static void ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec,
@@ -1115,7 +1119,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, err_fs_ft_sa_sel:mlx5_destroy_flow_table (rx->ft.status); err_fs_ft_status: -mlx5_ipsec_fs_roce_rx_destroy (ipsec->roce, family, mdev); +ipsec_rx_status_pass_dest_put (ipsec, rx, family);return err; }
drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c +13 -2
@@ -34,12 +34,23 @@ void mlx5_esw_ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec,int mlx5_esw_ipsec_rx_status_pass_dest_get (struct mlx5e_ipsec *ipsec,struct mlx5_flow_destination *dest) { - dest->type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; - dest->ft =mlx5_chains_get_table (esw_chains (ipsec->mdev->priv.eswitch),0 ,1 ,0 ); +struct mlx5_flow_table *ft; + + ft =mlx5_chains_get_table (esw_chains (ipsec->mdev->priv.eswitch), +0 ,1 ,0 ); +if (IS_ERR (ft)) +return PTR_ERR (ft); + dest->type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; + dest->ft = ft;return 0 ; } +void mlx5_esw_ipsec_rx_status_pass_dest_put (struct mlx5e_ipsec *ipsec) +{ +mlx5_chains_put_table (esw_chains (ipsec->mdev->priv.eswitch),0 ,1 ,0 ); +} +int mlx5_esw_ipsec_rx_setup_modify_header (struct mlx5e_ipsec_sa_entry *sa_entry,struct mlx5_flow_act *flow_act) {
drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.h +6 -0
@@ -12,6 +12,7 @@ void mlx5_esw_ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_rx_create_attr *attr);int mlx5_esw_ipsec_rx_status_pass_dest_get (struct mlx5e_ipsec *ipsec,struct mlx5_flow_destination *dest); +void mlx5_esw_ipsec_rx_status_pass_dest_put (struct mlx5e_ipsec *ipsec);int mlx5_esw_ipsec_rx_setup_modify_header (struct mlx5e_ipsec_sa_entry *sa_entry,struct mlx5_flow_act *flow_act);void mlx5_esw_ipsec_rx_id_mapping_remove (struct mlx5e_ipsec_sa_entry *sa_entry);
@@ -32,6 +33,11 @@ static inline int mlx5_esw_ipsec_rx_status_pass_dest_get(struct mlx5e_ipsec *ipsreturn -EINVAL ; } +static inline +void mlx5_esw_ipsec_rx_status_pass_dest_put (struct mlx5e_ipsec *ipsec) +{ +} +static inline int mlx5_esw_ipsec_rx_setup_modify_header (struct mlx5e_ipsec_sa_entry *sa_entry,struct mlx5_flow_act *flow_act) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/990 net/mlx5e: Fix ipsec core device access during profile changes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit 5b310ae1eff7531030b123bfcb192b0176d73075 ]
Devlink E-Switch mode changes replace the netdev profile without unregistering the netdev. XFRM state and policy creation can therefore run while mlx5e_priv_cleanup() clears priv with memset() or mlx5e_priv_init() initializes it again. Accesses to priv->mdev can observe NULL or a torn pointer, and repeated loads may return different values.
Read priv->mdev once in each add callback and use the saved pointer throughout the callback, including error unwinding. The core device survives the in-place profile change, so a saved non-NULL pointer remains valid even if priv is cleared in the meantime.
A NULL priv->mdev means a profile change is in progress, which only happens during an eswitch mode change. Return -EBUSY in that case, as mlx5_eswitch_block_mode() does for the same mode change. -EOPNOTSUPP would make xfrm_dev_state_add() silently fall back to software for a crypto offload SA for its whole lifetime.
Use WRITE_ONCE() when initializing priv->mdev and when clearing it before memset(). This makes the transition to NULL atomic; the subsequent bulk clear only writes zero bytes over an already NULL pointer. Annotate the READ_ONCE() snapshots with data_race() to allow that harmless overlap with the unmarked memset() without suppressing checks for the rest of priv.
This fixes the core-device pointer accesses. Protecting the IPsec context itself during state and policy creation is handled separately.
This was found by Sashiko, during review of the next patches in the series. No attempt was made at reproducing this race, the chances seem vanishingly small.
--- .../mellanox/mlx5/core/en_accel/ipsec.c | 38 +++++++++++++------ .../net/ethernet/mellanox/mlx5/core/en_main.c | 4 +- 2 files changed, 30 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +27 -11
@@ -775,12 +775,20 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, {struct mlx5e_ipsec_sa_entry *sa_entry =NULL ;bool allow_tunnel_mode = false; +struct mlx5_core_dev *mdev;struct mlx5e_ipsec *ipsec;struct mlx5e_priv *priv;gfp_t gfp;int err; priv =netdev_priv (dev); +/* Profile cleanup can memset an already NULL mdev. */ + mdev =data_race (READ_ONCE (priv->mdev)); +/* NULL only during a profile change, which is an eswitch operation. */ +if (!mdev) { +NL_SET_ERR_MSG_MOD (extack,"Eswitch busy, can't add state" ); +return -EBUSY ; + }if (!priv->ipsec)return -EOPNOTSUPP ;
@@ -799,16 +807,16 @@ static int mlx5e_xfrm_add_state(struct net_device *dev,return 0 ; } - err =mlx5e_xfrm_validate_state (priv->mdev, x, extack); + err =mlx5e_xfrm_validate_state (mdev, x, extack);if (err) goto err_xfrm; -if (!mlx5_eswitch_block_ipsec (priv->mdev)) { +if (!mlx5_eswitch_block_ipsec (mdev)) { err = -EBUSY ; goto err_xfrm; } - err =mlx5_eswitch_block_mode (priv->mdev); + err =mlx5_eswitch_block_mode (mdev);if (err) goto unblock_ipsec;
@@ -876,9 +884,9 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, x->xso.offload_handle = (unsigned long )sa_entry;if (allow_tunnel_mode) -mlx5_eswitch_unblock_encap (priv->mdev); +mlx5_eswitch_unblock_encap (mdev); -mlx5_eswitch_unblock_mode (priv->mdev); +mlx5_eswitch_unblock_mode (mdev);return 0 ;
@@ -894,11 +902,11 @@ static int mlx5e_xfrm_add_state(struct net_device *dev,kfree (sa_entry->work); unblock_encap:if (allow_tunnel_mode) -mlx5_eswitch_unblock_encap (priv->mdev); +mlx5_eswitch_unblock_encap (mdev); unblock_mode: -mlx5_eswitch_unblock_mode (priv->mdev); +mlx5_eswitch_unblock_mode (mdev); unblock_ipsec: -mlx5_eswitch_unblock_ipsec (priv->mdev); +mlx5_eswitch_unblock_ipsec (mdev); err_xfrm:kfree (sa_entry);NL_SET_ERR_MSG_WEAK_MOD (extack,"Device failed to offload this state" );
@@ -1267,16 +1275,24 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x, {struct net_device *netdev = x->xdo.dev;struct mlx5e_ipsec_pol_entry *pol_entry; +struct mlx5_core_dev *mdev;struct mlx5e_priv *priv;int err; priv =netdev_priv (netdev); +/* Profile cleanup can memset an already NULL mdev. */ + mdev =data_race (READ_ONCE (priv->mdev)); +if (!mdev) { +NL_SET_ERR_MSG_MOD (extack,"Eswitch busy, can't add policy" ); +return -EBUSY ; + } +if (!priv->ipsec) {NL_SET_ERR_MSG_MOD (extack,"Device doesn't support IPsec packet offload" );return -EOPNOTSUPP ; } - err =mlx5e_xfrm_validate_policy (priv->mdev, x, extack); + err =mlx5e_xfrm_validate_policy (mdev, x, extack);if (err)return err;
@@ -1287,7 +1303,7 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x, pol_entry->x = x; pol_entry->ipsec = priv->ipsec; -if (!mlx5_eswitch_block_ipsec (priv->mdev)) { +if (!mlx5_eswitch_block_ipsec (mdev)) { err = -EBUSY ; goto ipsec_busy; }
@@ -1301,7 +1317,7 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x,return 0 ; err_fs: -mlx5_eswitch_unblock_ipsec (priv->mdev); +mlx5_eswitch_unblock_ipsec (mdev); ipsec_busy:kfree (pol_entry);NL_SET_ERR_MSG_MOD (extack,"Device failed to offload this policy" );
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
@@ -6205,7 +6205,7 @@ int mlx5e_priv_init(struct mlx5e_priv *priv, node =dev_to_node (mlx5_core_dma_dev (mdev));/* priv init */ - priv->mdev = mdev; +WRITE_ONCE (priv->mdev, mdev); priv->netdev = netdev; priv->max_nch = nch; priv->max_opened_tc =1 ;
@@ -6298,6 +6298,8 @@ void mlx5e_priv_cleanup(struct mlx5e_priv *priv)mlx5e_mqprio_rl_free (priv->mqprio_rl); } +/* Clear atomically before memset() for lockless XFRM readers. */ +WRITE_ONCE (priv->mdev,NULL );memset (priv,0 ,sizeof (*priv));if (destroying)/* restore destroying bit, to allow unload */ set_bit (MLX5E_STATE_DESTROYING , &priv->state);
Signature · 1 line
2.53.0