7.3.7-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 464/1005 wifi: mac80211_hwsim: use CLOCK_BOOTTIME for the beacon timer
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Loïc Kassel <[email protected]>
[ Upstream commit 0da2be70425b21acf6e11bcf02f8a10fd55e85b0 ]
The simulated TSF is based on boottime, and the beacon timer is re-armed with an absolute expiry derived from the TSF through mac80211_hwsim_tsf_to_boottime(). The timer itself is however still set up with CLOCK_MONOTONIC.
Boottime keeps running while the system is suspended, monotonic does not. After the host has been suspended once, every beacon is therefore scheduled too late by the total time spent in suspend, and APs practically stop sending beacons.
Set the beacon timer up with CLOCK_BOOTTIME so that it is consistent with the TSF.
--- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/virtual/mac80211_hwsim_main.c +1 -1
@@ -6136,7 +6136,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,for (i =0 ; i <ARRAY_SIZE (data->link_data); i++) {hrtimer_setup (&data->link_data[i].beacon_timer, mac80211_hwsim_beacon, -CLOCK_MONOTONIC ,HRTIMER_MODE_ABS_SOFT ); +CLOCK_BOOTTIME ,HRTIMER_MODE_ABS_SOFT ); data->link_data[i].link_id = i; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 465/1005 wifi: mac80211: mesh: dont linearize SKBs unnecessarily
In reply to Greg Kroah-Hartman7.3-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
@@ -2930,9 +2930,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) {
@@ -2943,6 +2940,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 466/1005 wifi: mac80211: abort chanswitch when leaving an IBSS
In reply to Greg Kroah-Hartman7.3-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
@@ -669,6 +669,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 467/1005 net: fix mac_len of skbs copied by generic XDP
In reply to Greg Kroah-Hartman7.3-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
@@ -966,6 +966,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 468/1005 ovl: release the upperdir/workdir in-use locks before the umount sync
In reply to Greg Kroah-Hartman7.3-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
@@ -580,6 +580,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
@@ -845,15 +845,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
@@ -1598,13 +1598,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
@@ -1059,6 +1059,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 469/1005 net: mana: fix XDP_REDIRECT of pre-allocated RX buffers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Orgad Shaneh <[email protected]>
[ Upstream commit 67869597fab06abaa5b977cb7004532269fc960b ]
mana_pre_alloc_rxbufs() fills the RX rings with plain pages from dev_alloc_pages() (from_pool == false), but the rxq is registered with MEM_TYPE_PAGE_POOL and mana_run_xdp() builds every xdp_buff with that rxq info. mana_rx_skb() frees a !from_pool buffer correctly on XDP_PASS, XDP_TX and XDP_DROP, but a redirected buffer is freed through its memory model: __xdp_return() hands the plain page to page_pool_put_full_netmem(). This triggers the WARN in include/net/page_pool/helpers.h, breaks the page refcount, RX refills fail and the queue stops receiving.
The pre-allocated buffers fill the whole ring of every rxq created by an MTU change, by ethtool -L / -G and, since
commit 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency."), by every XDP attach and detach. So on current kernels the first ring of redirected packets after attaching an XDP program always hits this.
Reproduced on 7.2.11, and on 6.12.113 after ethtool -L, on an Azure MANA VF: an XDP program that redirects UDP to an XSKMAP with an AF_XDP socket in copy mode gives WARNINGs at __xdp_return+0x249 (stack __xsk_map_redirect, xdp_do_redirect, mana_run_xdp, mana_poll), then the queue stops.
Give each rxq a second xdp_rxq_info registered with MEM_TYPE_PAGE_SHARED, the model these buffers had before the page pool was added, and use it for buffers that are not from the pool. Those buffers are already DMA-unmapped by mana_refill_rx_oob() before XDP runs, and page_frag_free() frees them whatever their order. Allocating the pre-allocated buffers from the page pool instead would need the pools to exist before the rxqs and to outlive them, a much larger change.
Found, fixed and tested with an AI coding assistant (Claude Code).
--- drivers/net/ethernet/microsoft/mana/mana_bpf.c | 9 +++++++-- drivers/net/ethernet/microsoft/mana/mana_en.c | 11 ++++++++++- include/net/mana/mana.h | 5 ++++- 3 files changed, 21 insertions(+), 4 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +7 -2
@@ -78,7 +78,8 @@ int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames, }u32 mana_run_xdp (struct net_device *ndev,struct mana_rxq *rxq, -struct xdp_buff *xdp,void *buf_va,uint pkt_len) +struct xdp_buff *xdp,void *buf_va,bool from_pool, +uint pkt_len) {struct mana_stats_rx *rx_stats;struct bpf_prog *prog;
@@ -90,7 +91,11 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq,if (!prog) goto out; -xdp_init_buff (xdp,PAGE_SIZE , &rxq->xdp_rxq); +/* A redirected buffer is freed by its memory model, so a buffer not +* from the page pool must not claim MEM_TYPE_PAGE_POOL. +*/ +xdp_init_buff (xdp,PAGE_SIZE , + from_pool ? &rxq->xdp_rxq : &rxq->xdp_rxq_shared);xdp_prepare_buff (xdp, buf_va, rxq->headroom, pkt_len, true); act =bpf_prog_run_xdp (prog, xdp);
drivers/net/ethernet/microsoft/mana/mana_en.c +10 -1
@@ -2126,7 +2126,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool,return ; } - act =mana_run_xdp (ndev, rxq, &xdp, buf_va, pkt_len); + act =mana_run_xdp (ndev, rxq, &xdp, buf_va, from_pool, pkt_len);if (act ==XDP_REDIRECT && !rxq->xdp_rc)return ;
@@ -2919,6 +2919,9 @@ static void mana_destroy_rxq(struct mana_port_context *apc,if (xdp_rxq_info_is_reg (&rxq->xdp_rxq))xdp_rxq_info_unreg (&rxq->xdp_rxq); +if (xdp_rxq_info_is_reg (&rxq->xdp_rxq_shared)) +xdp_rxq_info_unreg (&rxq->xdp_rxq_shared); +if (rxq->rxobj !=INVALID_MANA_HANDLE )mana_destroy_wq_obj (apc,GDMA_RQ , rxq->rxobj);
@@ -3203,6 +3206,12 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,WARN_ON (xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , rxq->page_pool)); +/* The pre-allocated buffers (mana_pre_alloc_rxbufs) are plain pages */ +WARN_ON (xdp_rxq_info_reg (&rxq->xdp_rxq_shared, ndev, rxq_idx, + cq->napi.napi_id)); +WARN_ON (xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq_shared, +MEM_TYPE_PAGE_SHARED ,NULL )); +/* Initialize the DIM work before enabling NAPI, so that a poll * cannot reach net_dim() with an uninitialized cq->dim.work. */
include/net/mana/mana.h +4 -1
@@ -421,6 +421,8 @@ struct mana_rxq {struct bpf_prog __rcu *bpf_prog;struct xdp_rxq_info xdp_rxq; +/* For buffers not from the page pool (from_pool == false) */ +struct xdp_rxq_info xdp_rxq_shared;void *xdp_save_va;/* for reusing */ bool xdp_flush;int xdp_rc;/* XDP redirect return code */
@@ -694,7 +696,8 @@ void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev);int mana_xdp_xmit (struct net_device *ndev,int n,struct xdp_frame **frames,u32 flags);u32 mana_run_xdp (struct net_device *ndev,struct mana_rxq *rxq, -struct xdp_buff *xdp,void *buf_va,uint pkt_len); +struct xdp_buff *xdp,void *buf_va,bool from_pool, +uint pkt_len);struct bpf_prog *mana_xdp_get (struct mana_port_context *apc);void mana_chn_setxdp (struct mana_port_context *apc,struct bpf_prog *prog);int mana_bpf (struct net_device *ndev,struct netdev_bpf *bpf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 470/1005 bonding: fix slave_cnt leak on XDP enslave failure
In reply to Greg Kroah-Hartman7.3-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
@@ -2305,7 +2305,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 = {
@@ -2319,14 +2319,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);
@@ -2348,6 +2348,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 471/1005 sched_ext: Fix partial-SMT core counting in calc_shard_layout()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Qiao <[email protected]>
[ Upstream commit 3b1ce3e0ccba4aadbf6330a5ed8bda78f0c9353a ]
calc_shard_layout() counts the cores of an LLC to spread them evenly across shards. A core is counted when its cpu is the first cpu of topology_sibling_cpumask(), but the cores scx_cid_init() builds are the siblings intersected with @llc_cpus.
The sibling mask may contain cpus outside @llc_cpus - siblings which landed in another node or LLC unit, or offlined siblings on archs that keep them in the mask (mips, sparc64). A core whose first sibling is such a cpu is never counted, so cores_per_shard and nr_large come out too small and the shards end up uneven.
Count a core at its first sibling in @llc_cpus, matching the cores the build loop constructs.
--- kernel/sched/ext/cid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/sched/ext/cid.c +7 -1
@@ -63,7 +63,13 @@ static void calc_shard_layout(const struct cpumask *llc_cpus, u32 shard_size,for_each_cpu (cpu, llc_cpus) { nr_cpus++; -if (cpumask_first (topology_sibling_cpumask (cpu)) == cpu) +/* +* scx_cid_init() forms each core from the siblings in +* @llc_cpus. The sibling mask may include cpus outside +* @llc_cpus, so count a core at its first sibling in @llc_cpus. +*/ +if (cpumask_first_and (topology_sibling_cpumask (cpu), + llc_cpus) == cpu) nr_cores++; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 472/1005 cgroup/cpuset: Protect current->mems_allowed read in cpuset_fork()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Waiman Long <[email protected]>
[ Upstream commit a25cc4c75fdd8921f160bc3950665889eba7374b ]
Reading mems_allowed of the current task outside of cpuset_mutex critical section should be protected by using mems_allowed_seq seqlock as the nodemask can be updated concurrently leading to a torn read. Such protection is currently not implemented in cpuset_fork() for the !CLONE_INTO_CGROUP case. As a result, the child task may inherit an empty or corrupted mems_allowed nodemask. This violates NUMA memory policy constraints and causes subsequent page allocations to unconditionally fail, potentially leading to crashes or spurious OOM killer invocations for the child task.
Fix that by using a read_mems_allowed_begin/read_mems_allowed_retry() loop to protect the mems_allowed read.
--- kernel/cgroup/cpuset.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +10 -1
@@ -3980,11 +3980,20 @@ static void cpuset_fork(struct task_struct *task)rcu_read_unlock ();if (cs == oldcs) { +unsigned int seq; +if (cs == &top_cpuset)return ;set_cpus_allowed_ptr (task, current->cpus_ptr); - task->mems_allowed = current->mems_allowed; +/* +* A cpuset.mems update can update current->mems_allowed +* concurrently, so retry it again if it really happens. +*/ +do { + seq =read_mems_allowed_begin (); + task->mems_allowed = current->mems_allowed; + }while (read_mems_allowed_retry (seq));return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 473/1005 NFS: dont let delegated c/mtime stamps go backward
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 427d4cd8048c8e18e7d0c7d0637e7fbec9fba078 ]
With a timestamp delegation the client stamps c/mtime from its own coarse clock. That can land before the server's fine-grained ctime the client cached from the OPEN or SETATTR reply, e.g. on a WRITE right after an exclusive create. The server then either rejects the times (they don't pass dl_ctime) or can't apply the ctime, since inode_set_ctime_deleg() never moves ctime backward. Either way the c/mtime the client reported while holding the delegation changes after DELEGRETURN; git t1092 over NFSv4.2 sees a stat-dirty file.
When a delegated stamp isn't after the cached ctime, use the cached ctime + 1ns instead. Compute the stamp before storing it, so lockless readers (getattr, CB_GETATTR) never see the trailing coarse time.
--- fs/nfs/inode.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-)
fs/nfs/inode.c +26 -14
@@ -623,25 +623,33 @@ nfs_fattr_fixup_delegated(struct inode *inode, struct nfs_fattr *fattr) } } +/* +* With delegated timestamps, the client's coarse clock can trail the +* server's fine-grained ctime cached from an OPEN or SETATTR reply. The +* server won't move ctime backward when the times are returned, so a +* new stamp must land after the cached ctime. +*/ +static struct timespec64 nfs_delegated_stamp (struct inode *inode) +{ +struct timespec64 ctime =inode_get_ctime (inode); +struct timespec64 now =current_time (inode); + +if (timespec64_compare (&now, &ctime) <=0 ) { + now = ctime; +timespec64_add_ns (&now,1 ); + } +return now; +} +static void nfs_set_timestamps_to_ts (struct inode *inode,struct iattr *attr) {unsigned int cache_flags =0 ;if (attr->ia_valid &ATTR_MTIME_SET ) { -struct timespec64 ctime =inode_get_ctime (inode); -struct timespec64 mtime =inode_get_mtime (inode); -struct timespec64 now; -bool updated = false; - - now =inode_set_ctime_current (inode); -if (!timespec64_equal (&now, &ctime)) - updated = true; - +/* The stamp is always after the old ctime */ +inode_set_ctime_to_ts (inode,nfs_delegated_stamp (inode));inode_set_mtime_to_ts (inode, attr->ia_mtime); -if (!timespec64_equal (&now, &mtime)) - updated = true; - -inode_maybe_inc_iversion (inode, updated); +inode_maybe_inc_iversion (inode, true); cache_flags |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ; }if (attr->ia_valid &ATTR_ATIME ) {
@@ -659,7 +667,11 @@ static void nfs_update_atime(struct inode *inode)static void nfs_update_mtime (struct inode *inode) { -inode_update_time (inode,FS_UPD_CMTIME ,0 ); +struct timespec64 now =nfs_delegated_stamp (inode); + +/* Not inode_update_time(): lockless readers would see its stamp */ +inode_set_ctime_to_ts (inode, now); +inode_set_mtime_to_ts (inode, now);NFS_I (inode)->cache_validity &= ~(NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 474/1005 NFS: stamp after the servers ctime when truncating under delegated times
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit f13110f9cfb95a09d286eee561adc96c6a02664f ]
A size-changing SETATTR always has the server stamp c/mtime (__nfsd_setattr(), per RFC 5661 section 18.30.4). With delegated timestamps the client discards the reply's ctime and stamps its own in nfs_vmtruncate(), clamped only against its cached ctime. A coarse client stamp can still land before the server's, which then won't move ctime back when the holder returns its times, so ctime changes after DELEGRETURN.
- Raise the cached ctime to the reply's before nfs_vmtruncate() stamps, so the delegated stamp lands after the server's.
- Stamp before nfs_vmtruncate() drops i_lock for truncate_pagecache(), not after. A delegation return starting in that window made the stamp a no-op, and DELEGRETURN sent the pre-truncate mtime, which the server could apply over its own truncate stamp.
--- fs/nfs/inode.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
fs/nfs/inode.c +22 -1
@@ -641,6 +641,21 @@ static struct timespec64 nfs_delegated_stamp(struct inode *inode)return now; } +/* +* The server stamped c/mtime itself (e.g. for a size change). Raise the +* cached ctime to the server's so that the next delegated stamp lands +* after it. +*/ +static void nfs_delegated_ctime_raise (struct inode *inode, +const struct nfs_fattr *fattr) +{ +struct timespec64 ctime =inode_get_ctime (inode); + +if ((fattr->valid &NFS_ATTR_FATTR_CTIME ) && +timespec64_compare (&fattr->ctime, &ctime) >0 ) +inode_set_ctime_to_ts (inode, fattr->ctime); +} +static void nfs_set_timestamps_to_ts (struct inode *inode,struct iattr *attr) {unsigned int cache_flags =0 ;
@@ -814,10 +829,14 @@ static int nfs_vmtruncate(struct inode * inode, loff_t offset)nfs_ooo_clear (NFS_I (inode)); }NFS_I (inode)->cache_validity &= ~NFS_INO_INVALID_SIZE ; +/* +* Stamp in the same i_lock section that checked the delegation and +* raised ctime, before a delegation return can start. +*/ +nfs_update_delegated_mtime_locked (inode);spin_unlock (&inode->i_lock);truncate_pagecache (inode, offset); -nfs_update_delegated_mtime_locked (inode);spin_lock (&inode->i_lock); out:return err;
@@ -843,6 +862,8 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,if ((attr->ia_valid &ATTR_SIZE ) !=0 ) {if (!nfs_have_delegated_mtime (inode))nfs_set_cache_invalid (inode,NFS_INO_INVALID_MTIME ); +else +nfs_delegated_ctime_raise (inode, fattr);nfs_set_cache_invalid (inode,NFS_INO_INVALID_BLOCKS );nfs_inc_stats (inode,NFSIOS_SETATTRTRUNC );nfs_vmtruncate (inode, attr->ia_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 475/1005 NFS: stamp after the servers ctime following a CLONE
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 23b9cf773211d536147aa53ade68a88d457838ac ]
nfs42_copy_dest_done() stamps the client's own c/mtime when it holds delegated timestamps. A server that stamps c/mtime on CLONE (as nfsd did before "nfsd: mark the delegation written on COPY/CLONE instead of stamping c/mtime", and as btrfs did before "btrfs: honor FMODE_NOCMTIME when cloning") can end up with a ctime newer than the client's coarse stamp, which it won't move back when the holder returns its times.
The stamp didn't survive anyway: nfs_post_op_update_inode() then marks ctime invalid, so nfs_fattr_fixup_delegated() keeps the reply's ctime and nfs_update_inode() writes it over the stamp. Against a server that no longer stamps on CLONE, the client's ctime goes back to its old value until DELEGRETURN.
- Pass the CLONE reply's attributes to nfs42_copy_dest_done() and raise the cached ctime to the server's before stamping. COPY returns no attributes, so it passes NULL.
- Stamp before dropping i_lock, so a concurrent refresh can't take the server's times while ctime and mtime are marked invalid.
- Under delegated timestamps, apply the reply with nfs_refresh_inode(), which doesn't mark ctime invalid.
--- fs/nfs/delegation.h | 2 ++ fs/nfs/inode.c | 6 ++++-- fs/nfs/nfs42proc.c | 25 ++++++++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-)
fs/nfs/delegation.h +2 -0
@@ -95,6 +95,8 @@ void nfs4_inode_make_writeable(struct inode *inode);void nfs_update_delegated_atime (struct inode *inode);void nfs_update_delegated_mtime (struct inode *inode);void nfs_update_delegated_mtime_locked (struct inode *inode); +void nfs_delegated_ctime_raise (struct inode *inode, +const struct nfs_fattr *fattr);static inline int nfs_have_read_or_write_delegation (struct inode *inode) {
fs/nfs/inode.c +4 -2
@@ -646,8 +646,8 @@ static struct timespec64 nfs_delegated_stamp(struct inode *inode)* cached ctime to the server's so that the next delegated stamp lands * after it. */ -static void nfs_delegated_ctime_raise (struct inode *inode, -const struct nfs_fattr *fattr) +void nfs_delegated_ctime_raise (struct inode *inode, +const struct nfs_fattr *fattr) {struct timespec64 ctime =inode_get_ctime (inode);
@@ -655,6 +655,7 @@ static void nfs_delegated_ctime_raise(struct inode *inode, timespec64_compare(&fattr->ctime, &ctime) > 0)inode_set_ctime_to_ts (inode, fattr->ctime); } +EXPORT_SYMBOL_GPL (nfs_delegated_ctime_raise);static void nfs_set_timestamps_to_ts (struct inode *inode,struct iattr *attr) {
@@ -705,6 +706,7 @@ void nfs_update_delegated_mtime_locked(struct inode *inode) nfs_have_directory_delegation(inode))nfs_update_mtime (inode); } +EXPORT_SYMBOL_GPL (nfs_update_delegated_mtime_locked);void nfs_update_delegated_mtime (struct inode *inode) {
fs/nfs/nfs42proc.c +20 -5
@@ -380,6 +380,7 @@ static int process_copy_commit(struct file *dst, loff_t pos_dst,* @pos: destination offset * @len: copy length * @oldsize: length of the file prior to clone/copy +* @fattr: destination attributes from the reply, or NULL * * Punch a hole in the inode page cache, so that the NFS client will * know to retrieve new data.
@@ -387,7 +388,7 @@ static int process_copy_commit(struct file *dst, loff_t pos_dst,* invalid cached values for change attribute, ctime, mtime and space used. */ static void nfs42_copy_dest_done (struct file *file,loff_t pos,loff_t len, -loff_t oldsize) +loff_t oldsize,const struct nfs_fattr *fattr) {struct inode *inode =file_inode (file);struct address_space *mapping = file->f_mapping;
@@ -405,8 +406,12 @@ static void nfs42_copy_dest_done(struct file *file, loff_t pos, loff_t len,NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME | NFS_INO_INVALID_BLOCKS); +/* The server may have stamped c/mtime; stamp after it */ +if (fattr &&nfs_have_delegated_mtime (inode)) +nfs_delegated_ctime_raise (inode, fattr); +/* Before a refresh can see the times invalid and take the server's */ +nfs_update_delegated_mtime_locked (inode);spin_unlock (&inode->i_lock); -nfs_update_delegated_mtime (inode); } static ssize_t _nfs42_proc_copy(struct file *src,
@@ -506,7 +511,8 @@ static ssize_t _nfs42_proc_copy(struct file *src, goto out; } -nfs42_copy_dest_done (dst, pos_dst, res->write_res.count, oldsize_dst); +nfs42_copy_dest_done (dst, pos_dst, res->write_res.count, oldsize_dst, +NULL );nfs_invalidate_atime (src_inode); status = res->write_res.count; out:
@@ -1311,8 +1317,17 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f,/* a zero-length count means clone to EOF in src */ if (count ==0 && res.dst_fattr->valid &NFS_ATTR_FATTR_SIZE ) count =nfs_size_to_loff_t (res.dst_fattr->size) - dst_offset; -nfs42_copy_dest_done (dst_f, dst_offset, count, oldsize_dst); - status =nfs_post_op_update_inode (dst_inode, res.dst_fattr); +nfs42_copy_dest_done (dst_f, dst_offset, count, oldsize_dst, + res.dst_fattr); +/* +* nfs_post_op_update_inode() would mark ctime invalid, so the +* reply's ctime would overwrite the delegated stamp. +*/ +if (nfs_have_delegated_mtime (dst_inode)) + status =nfs_refresh_inode (dst_inode, res.dst_fattr); +else + status =nfs_post_op_update_inode (dst_inode, + res.dst_fattr); }kfree (res.dst_fattr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 476/1005 NFSv4: wake blocking lock waiters when a delegated lock is released
In reply to Greg Kroah-Hartman7.3-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
@@ -7287,8 +7287,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 ;
@@ -7708,8 +7715,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 477/1005 NFSv4: remember that the server may send CB_NOTIFY_LOCK
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olga Kornievskaia <[email protected]>
[ Upstream commit 4fdc29eb6730207b4a6f63f81575c7aa5c2a4ff1 ]
Two processes contending for a POSIX lock on one file see occasional acquisitions of almost exactly 1, 3 or 7 seconds when the client holds a delegation, although the holder releases within microseconds.
nfs4_retry_setlk() only parks a waiter on clp->cl_lock_waitq when NFS_STATE_MAY_NOTIFY_LOCK is set. Otherwise it uses nfs4_retry_setlk_simple(), which has no waitqueue at all and sleeps on a bare timeout starting at NFS4_LOCK_MINTIMEOUT and doubling, so a waiter that loses one poll waits a second, then two, then four.
NFS_STATE_MAY_NOTIFY_LOCK is set in _nfs4_open_and_get_state() from the OPEN reply rflags. It describes the server, but is recorded per nfs4_state and can only be learned from a reply. Once a delegation is held, further opens are satisfied from it with no OPEN on the wire, so o_res.rflags is zero and the new state starts out believing no callback can arrive, even though the open that obtained the delegation was told otherwise.
Record the capability on the nfs_client the first time an OPEN reply carries it, and apply it to every state built for that client. nfs_client is the right scope: the flag describes one server, CB_NOTIFY_LOCK arrives on that client's backchannel, and cl_lock_waitq is per nfs_client.
This also covers a case the per-state flag misses. After the delegation is recalled the state has neither NFS_DELEGATED_STATE nor NFS_STATE_MAY_NOTIFY_LOCK, so locks go to the server and the server does send CB_NOTIFY_LOCK, but the client is in the backoff loop and ignores it.
--- fs/nfs/nfs4proc.c | 2 ++ include/linux/nfs_fs_sb.h | 1 + 2 files changed, 3 insertions(+)
fs/nfs/nfs4proc.c +2 -0
@@ -3093,6 +3093,8 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,if (server->caps &NFS_CAP_POSIX_LOCK )set_bit (NFS_STATE_POSIX_LOCKS , &state->flags);if (opendata->o_res.rflags &NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK ) + server->nfs_client->cl_may_notify_lock = true; +if (server->nfs_client->cl_may_notify_lock)set_bit (NFS_STATE_MAY_NOTIFY_LOCK , &state->flags);if (opendata->o_res.rflags &NFS4_OPEN_RESULT_PRESERVE_UNLINKED )set_bit (NFS_INO_PRESERVE_UNLINKED , &NFS_I (state->inode)->flags);
include/linux/nfs_fs_sb.h +1 -0
@@ -116,6 +116,7 @@ struct nfs_client {#define NFS_SP4_MACH_CRED_COMMIT 6/* COMMIT */ #define NFS_SP4_MACH_CRED_PNFS_CLEANUP 7/* LAYOUTRETURN */ wait_queue_head_t cl_lock_waitq; +bool cl_may_notify_lock;#endif /* CONFIG_NFS_V4 */ /* Our own IP address, as a null-terminated string.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 478/1005 sched_ext: Add scx_bpf_dsq_reenq_task() to re-enqueue single tasks from a DSQ iteration
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit b3768d058c98d4e8114a246d3267d7dae1c123fb ]
scx_bpf_dsq_reenq() re-enqueues a whole DSQ, but a scheduler that loses the cpus serving a DSQ, such as a sub-scheduler after a cap revoke, needs only the stranded tasks placed again.
Add scx_bpf_dsq_reenq_task(), which marks a task from a DSQ iteration. When the iteration ends, the DSQ's deferred re-enqueue walk is scheduled once and re-enqueues only the marked tasks. The kfunc locks the task's rq and the DSQ like scx_bpf_dsq_move() and is callable from the same contexts. The mark is cleared when the task leaves the DSQ, so a task consumed before the walk is not re-enqueued.
An iteration's DSQ can be destroyed before the iteration ends, so schedule_dsq_reenq() now skips a destroyed DSQ instead of aborting the scheduler. scx_bpf_dsq_reenq() racing scx_bpf_destroy_dsq() takes the same path.
Declare the kfunc for the tools and add a compat probe.
v2: Note in the kerneldoc that another iteration's re-enqueue may take a marked task early, and that a task on another scheduler returns false (Andrea).
Stable-dep-of: fcbff7b56a88 ("sched_ext: make DSQ iterator stay drained after NULL")
--- include/linux/sched/ext.h | 1 + kernel/sched/ext/ext.c | 82 +++++++++++++++++++++++- kernel/sched/ext/internal.h | 2 + tools/sched_ext/include/scx/common.bpf.h | 1 + tools/sched_ext/include/scx/compat.bpf.h | 6 ++ 5 files changed, 89 insertions(+), 3 deletions(-)
include/linux/sched/ext.h +1 -0
@@ -155,6 +155,7 @@ enum scx_ent_flags {/* scx_entity.dsq_flags */ enum scx_ent_dsq_flags {SCX_TASK_DSQ_ON_PRIQ =1 <<0 ,/* task is queued on the priority queue of a dsq */ +SCX_TASK_DSQ_REENQ =1 <<1 ,/* marked by scx_bpf_dsq_reenq_task() */ };enum scx_dsq_lnode_flags {
kernel/sched/ext/ext.c +79 -3
141 lines not on this page · raw message
kernel/sched/ext/internal.h +2 -0
@@ -1888,6 +1888,8 @@ enum scx_reenq_flags {/* internal: kernel-issued on cap revoke, not accepted from BPF */ SCX_REENQ_CAP_REVOKE =1LLU <<1 , +/* internal: tasks marked by scx_bpf_dsq_reenq_task() */ +SCX_REENQ_MARKED =1LLU <<2 , __SCX_REENQ_FILTER_MASK = 0xffffLLU,
tools/sched_ext/include/scx/common.bpf.h +1 -0
@@ -74,6 +74,7 @@ struct task_struct *scx_bpf_dsq_peek(u64 dsq_id) __ksym __weak; int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id, u64 flags) __ksym __weak;struct task_struct *bpf_iter_scx_dsq_next (struct bpf_iter_scx_dsq *it) __ksym__weak ; void bpf_iter_scx_dsq_destroy(struct bpf_iter_scx_dsq *it) __ksym __weak; +bool scx_bpf_dsq_reenq_task(struct bpf_iter_scx_dsq *it, struct task_struct *p) __ksym __weak; void scx_bpf_exit_bstr(s64 exit_code, char *fmt, unsigned long long *data, u32 data__sz) __ksym __weak; void scx_bpf_error_bstr(char *fmt, unsigned long long *data, u32 data_len) __ksym; void scx_bpf_dump_bstr(char *fmt, unsigned long long *data, u32 data_len) __ksym __weak;
tools/sched_ext/include/scx/compat.bpf.h +6 -0
@@ -414,6 +414,12 @@ static inline bool __COMPAT_has_generic_reenq(void)return bpf_ksym_exists (scx_bpf_dsq_reenq___compat); } +/* v7.4: Add scx_bpf_dsq_reenq_task(). */ +static inline bool __COMPAT_has_dsq_reenq_task (void ) +{ +return bpf_ksym_exists (scx_bpf_dsq_reenq_task); +} +/* * v6.19: The new void variant can be called from anywhere while the older v1 * variant can only be called from ops.cpu_release(). The double ___ prefixes on
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 479/1005 sched_ext: make DSQ iterator stay drained after NULL
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kang Chen <[email protected]>
[ Upstream commit fcbff7b56a881bbe041b6c5ba12831a3c1ac1bb4 ]
nldsq_cursor_next_task() unlinks the iteration cursor when it reaches the end of the DSQ. A later call sees list_empty(&cursor->node), starts from the DSQ head again, and returns the first task of the same iteration.
The verifier relies on the iterator contract that once next() returns NULL it keeps returning NULL: process_iter_next_call() marks the iterator DRAINED and treats the result of later next() calls as the constant zero. A restarted DSQ iteration therefore hands the BPF program a task pointer while the verifier believes R0 == 0.
Remember the drained state in the cursor flags and return NULL on every later next() call. The cursor has spare flag bits and the BPF-visible iterator layout is unchanged.
--- kernel/sched/ext/ext.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
kernel/sched/ext/ext.c +15 -2
@@ -492,12 +492,14 @@ enum scx_dsq_iter_flags {/* iterate in the reverse dispatch order */ SCX_DSQ_ITER_REV =1U <<16 , + __SCX_DSQ_ITER_DRAINED =1U <<28 , __SCX_DSQ_ITER_HAS_REENQ =1U <<29 , __SCX_DSQ_ITER_HAS_SLICE =1U <<30 , __SCX_DSQ_ITER_HAS_VTIME =1U <<31 , __SCX_DSQ_ITER_USER_FLAGS =SCX_DSQ_ITER_REV , __SCX_DSQ_ITER_ALL_FLAGS = __SCX_DSQ_ITER_USER_FLAGS | + __SCX_DSQ_ITER_DRAINED | __SCX_DSQ_ITER_HAS_REENQ | __SCX_DSQ_ITER_HAS_SLICE | __SCX_DSQ_ITER_HAS_VTIME,
@@ -10236,13 +10238,24 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id, __bpf_kfunc struct task_struct *bpf_iter_scx_dsq_next(struct bpf_iter_scx_dsq *it) {struct bpf_iter_scx_dsq_kern *kit = (void *)it; +struct task_struct *p; -if (!kit->dsq) +if (!kit->dsq || (kit->cursor.flags & __SCX_DSQ_ITER_DRAINED))return NULL ;guard (raw_spinlock_irqsave)(&kit->dsq->lock); -return nldsq_cursor_next_task (&kit->cursor, kit->dsq); + p =nldsq_cursor_next_task (&kit->cursor, kit->dsq); +/* +* nldsq_cursor_next_task() unlinks the cursor and starts from the DSQ +* head when it is called again. The verifier relies on an iterator +* which returned NULL to keep returning NULL (see +* process_iter_next_call()), so remember the drained state. +*/ +if (!p) + kit->cursor.flags |= __SCX_DSQ_ITER_DRAINED; + +return p; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 480/1005 tun: delete the flow entries of the moved queue on detach
In reply to Greg Kroah-Hartman7.3-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
@@ -615,7 +615,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);spin_lock_bh (&ntfile->tx_ring.consumer_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 481/1005 fbnic: Fix service task races with ndo_stop and PM suspend
In reply to Greg Kroah-Hartman7.3-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
@@ -229,18 +229,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 (); }
@@ -455,6 +462,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);
@@ -555,19 +568,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 482/1005 fbnic: Disable PTP completions during the Tx force-flush
In reply to Greg Kroah-Hartman7.3-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
@@ -459,6 +459,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
@@ -2309,15 +2309,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 483/1005 fbnic: Suspend phylink after taking the datapath down in ndo_stop
In reply to Greg Kroah-Hartman7.3-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 484/1005 fbnic: Wait for the outbound flush to complete on mailbox teardown
In reply to Greg Kroah-Hartman7.3-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
@@ -974,6 +974,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 485/1005 net: Segment CHECKSUM_UNNECESSARY GSO skbs other than fraglist
In reply to Greg Kroah-Hartman7.3-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
@@ -4105,6 +4105,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 486/1005 NFSv4/flexfiles: Reference the device node across DS setup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
[ Upstream commit e85acae4cda89c075bc94520fdcf5901595fffae ]
The flexfiles I/O setup paths read the mirror's pinned per-stripe device node (mirror->dss[dss_id].mirror_ds) repeatedly and locklessly, relying on the mirror's lifetime pin. To prepare for re-resolving that pointer in place on CB_NOTIFY_DEVICEID CHANGE, readers must hold their own reference on the node they are using rather than trusting the pin.
Replace ff_layout_init_mirror_ds() with ff_layout_get_mirror_ds(), which resolves on first use as before but returns the node with its own reference held. Thread the referenced node through nfs4_ff_layout_prepare_ds() and the DS selection helpers so each setup path snapshots the node once, and drop the reference when setup is done.
No functional change: the pointer is still resolved once and pinned for the life of the mirror. Each reference this adds is released on every exit from the path that took it, error paths included.
Stable-dep-of: 788c4f628565 ("NFSv4/flexfiles: limit transport disconnects when cancelling I/O")
--- fs/nfs/flexfilelayout/flexfilelayout.c | 140 ++++++++++++++-------- fs/nfs/flexfilelayout/flexfilelayout.h | 16 ++- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 74 +++++++----- 3 files changed, 141 insertions(+), 89 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +87 -53
@@ -878,7 +878,7 @@ ff_layout_mark_ds_reachable(struct pnfs_layout_segment *lseg, u32 idx, u32 dss_infs4_mark_deviceid_available (devid); } -static struct nfs4_pnfs_ds * +static struct nfs4_ff_layout_ds * ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg, u32 start_idx, u32 *best_idx, u64 offset, u32 *dss_id,
@@ -886,7 +886,9 @@ ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg, {struct nfs4_ff_layout_segment *fls =FF_LAYOUT_LSEG (lseg);struct nfs4_ff_layout_mirror *mirror; -struct nfs4_pnfs_ds *ds =ERR_PTR (-EAGAIN ); +struct nfs4_ff_layout_ds *mirror_ds; +struct nfs4_ff_layout_ds *ret =ERR_PTR (-EAGAIN ); +struct nfs4_pnfs_ds *ds;u32 idx;/* mirrors are initially sorted by efficiency */
@@ -896,25 +898,32 @@ ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg, fls->stripe_unit, fls->mirror_array[idx]->dss_count, offset); - ds =nfs4_ff_layout_prepare_ds (lseg, mirror, *dss_id, false); -if (IS_ERR (ds)) + mirror_ds =ff_layout_get_mirror_ds (lseg->pls_layout, mirror, + *dss_id); + ds =nfs4_ff_layout_prepare_ds (lseg, mirror, mirror_ds, + *dss_id, false); +if (IS_ERR (ds)) { +nfs4_ff_layout_put_deviceid (mirror_ds); + ret =ERR_CAST (ds);continue ; + }if (check_device && -nfs4_test_deviceid_unavailable (&mirror->dss[*dss_id].mirror_ds->id_node)) { +nfs4_test_deviceid_unavailable (&mirror_ds->id_node)) { +nfs4_ff_layout_put_deviceid (mirror_ds);// reinitialize the error state in case if this is the last iteration - ds =ERR_PTR (-EINVAL ); + ret =ERR_PTR (-EINVAL );continue ; } *best_idx = idx; -break ; +return mirror_ds; } -return ds; +return ret; } -static struct nfs4_pnfs_ds * +static struct nfs4_ff_layout_ds *ff_layout_choose_any_ds_for_read (struct pnfs_layout_segment *lseg,u32 start_idx,u32 *best_idx,u64 offset,u32 *dss_id)
@@ -923,7 +932,7 @@ ff_layout_choose_any_ds_for_read(struct pnfs_layout_segment *lseg, offset, dss_id, false); } -static struct nfs4_pnfs_ds * +static struct nfs4_ff_layout_ds *ff_layout_choose_valid_ds_for_read (struct pnfs_layout_segment *lseg,u32 start_idx,u32 *best_idx,u64 offset,u32 *dss_id)
@@ -932,34 +941,36 @@ ff_layout_choose_valid_ds_for_read(struct pnfs_layout_segment *lseg, offset, dss_id, true); } -static struct nfs4_pnfs_ds * +static struct nfs4_ff_layout_ds *ff_layout_choose_best_ds_for_read (struct pnfs_layout_segment *lseg,u32 start_idx,u32 *best_idx,u64 offset,u32 *dss_id) { -struct nfs4_pnfs_ds *ds; +struct nfs4_ff_layout_ds *mirror_ds; - ds =ff_layout_choose_valid_ds_for_read (lseg, start_idx, best_idx, - offset, dss_id); -if (!IS_ERR (ds)) -return ds; + mirror_ds =ff_layout_choose_valid_ds_for_read (lseg, start_idx, + best_idx, offset, + dss_id); +if (!IS_ERR (mirror_ds)) +return mirror_ds;return ff_layout_choose_any_ds_for_read (lseg, start_idx, best_idx, offset, dss_id); } -static struct nfs4_pnfs_ds * +static struct nfs4_ff_layout_ds *ff_layout_get_ds_for_read (struct nfs_pageio_descriptor *pgio,u32 *best_idx,u64 offset,u32 *dss_id) {struct pnfs_layout_segment *lseg = pgio->pg_lseg; -struct nfs4_pnfs_ds *ds; +struct nfs4_ff_layout_ds *mirror_ds; - ds =ff_layout_choose_best_ds_for_read (lseg, pgio->pg_mirror_idx, - best_idx, offset, dss_id); -if (!IS_ERR (ds) || !pgio->pg_mirror_idx) -return ds; + mirror_ds =ff_layout_choose_best_ds_for_read (lseg, + pgio->pg_mirror_idx, + best_idx, offset, dss_id); +if (!IS_ERR (mirror_ds) || !pgio->pg_mirror_idx) +return mirror_ds;return ff_layout_choose_best_ds_for_read (lseg,0 , best_idx, offset, dss_id); }
@@ -1048,8 +1059,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) {struct nfs_pgio_mirror *pgm; -struct nfs4_ff_layout_mirror *mirror; -struct nfs4_pnfs_ds *ds; +struct nfs4_ff_layout_ds *mirror_ds;u32 ds_idx, dss_id; if (NFS_SERVER(pgio->pg_inode)->flags &
@@ -1071,9 +1081,9 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,/* Reset wb_nio, since getting layout segment was successful */ req->wb_nio =0 ; - ds =ff_layout_get_ds_for_read (pgio, &ds_idx, -req_offset (req), &dss_id); -if (IS_ERR (ds)) { + mirror_ds =ff_layout_get_ds_for_read (pgio, &ds_idx, +req_offset (req), &dss_id); +if (IS_ERR (mirror_ds)) {if (!ff_layout_no_fallback_to_mds (pgio->pg_lseg)) goto out_mds;pnfs_generic_pg_cleanup (pgio);
@@ -1083,9 +1093,9 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, goto retry; } - mirror =FF_LAYOUT_COMP (pgio->pg_lseg, ds_idx); pgm = &pgio->pg_mirrors[0 ]; - pgm->pg_bsize = mirror->dss[dss_id].mirror_ds->ds_versions[0 ].rsize; + pgm->pg_bsize = mirror_ds->ds_versions[0 ].rsize; +nfs4_ff_layout_put_deviceid (mirror_ds); pgio->pg_mirror_idx = ds_idx;return ;
@@ -1135,6 +1145,7 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) {struct nfs4_ff_layout_mirror *mirror; +struct nfs4_ff_layout_ds *mirror_ds;struct nfs_pgio_mirror *pgm;struct nfs4_pnfs_ds *ds;u32 i, dss_id;
@@ -1166,9 +1177,12 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,FF_LAYOUT_LSEG (pgio->pg_lseg)->stripe_unit, mirror->dss_count, req_offset(req)); + mirror_ds =ff_layout_get_mirror_ds (pgio->pg_lseg->pls_layout, + mirror, dss_id); ds =nfs4_ff_layout_prepare_ds (pgio->pg_lseg, mirror, - dss_id, true); + mirror_ds, dss_id, true);if (IS_ERR (ds)) { +nfs4_ff_layout_put_deviceid (mirror_ds);if (!ff_layout_no_fallback_to_mds (pgio->pg_lseg)) goto out_mds;pnfs_generic_pg_cleanup (pgio);
@@ -1178,7 +1192,8 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, goto retry; } pgm = &pgio->pg_mirrors[i]; - pgm->pg_bsize = mirror->dss[dss_id].mirror_ds->ds_versions[0 ].wsize; + pgm->pg_bsize = mirror_ds->ds_versions[0 ].wsize; +nfs4_ff_layout_put_deviceid (mirror_ds); } if (NFS_SERVER(pgio->pg_inode)->flags &
@@ -1310,14 +1325,16 @@ static void ff_layout_resend_pnfs_read(struct nfs_pgio_header *hdr)u32 idx = hdr->pgio_mirror_idx +1 ;u32 new_idx =0 ;u32 dss_id =0 ; -struct nfs4_pnfs_ds *ds; +struct nfs4_ff_layout_ds *mirror_ds; - ds =ff_layout_choose_any_ds_for_read (hdr->lseg, idx, &new_idx, - hdr->args.offset, &dss_id); -if (IS_ERR (ds)) + mirror_ds =ff_layout_choose_any_ds_for_read (hdr->lseg, idx, &new_idx, + hdr->args.offset, &dss_id); +if (IS_ERR (mirror_ds)) {pnfs_error_mark_layout_for_return (hdr->inode, hdr->lseg); -else + }else { +nfs4_ff_layout_put_deviceid (mirror_ds);ff_layout_send_layouterror (hdr->lseg); + }pnfs_read_resend_pnfs (hdr, new_idx); }
@@ -2238,6 +2255,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)struct rpc_clnt *ds_clnt;struct nfsd_file *localio;struct nfs4_ff_layout_mirror *mirror; +struct nfs4_ff_layout_ds *mirror_ds;const struct cred *ds_cred;loff_t offset = hdr->args.offset;u32 idx = hdr->pgio_mirror_idx;
@@ -2255,22 +2273,24 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)FF_LAYOUT_LSEG (lseg)->stripe_unit, mirror->dss_count, offset); - ds =nfs4_ff_layout_prepare_ds (lseg, mirror, dss_id, false); + mirror_ds =ff_layout_get_mirror_ds (lseg->pls_layout, mirror, dss_id); + ds =nfs4_ff_layout_prepare_ds (lseg, mirror, mirror_ds, dss_id, false);if (IS_ERR (ds)) { ds_fatal_error =nfs_error_is_fatal (PTR_ERR (ds)); goto out_failed; } - ds_clnt =nfs4_ff_find_or_create_ds_client (mirror, ds->ds_clp, - hdr->inode, dss_id); + ds_clnt =nfs4_ff_find_or_create_ds_client (mirror_ds, ds->ds_clp, + hdr->inode);if (IS_ERR (ds_clnt)) goto out_failed; - ds_cred =ff_layout_get_ds_cred (mirror, &lseg->pls_range, hdr->cred, dss_id); + ds_cred =ff_layout_get_ds_cred (mirror, &lseg->pls_range, hdr->cred, + mirror_ds, dss_id);if (!ds_cred) goto out_failed; - vers =nfs4_ff_layout_ds_version (mirror, dss_id); + vers =nfs4_ff_layout_ds_version (mirror_ds);dprintk ("%s USE DS: %s cl_count %d vers %d\n" , __func__, ds->ds_remotestr,refcount_read (&ds->ds_clp->cl_count), vers);
@@ -2282,7 +2302,8 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)if (fh) hdr->args.fh = fh; -nfs4_ff_layout_select_ds_stateid (mirror, dss_id, &hdr->args.stateid); +nfs4_ff_layout_select_ds_stateid (mirror, mirror_ds, dss_id, + &hdr->args.stateid);/* * Note that if we ever decide to split across DSes,
@@ -2305,9 +2326,11 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr) &ff_layout_read_call_ops_v4, 0, RPC_TASK_SOFTCONN, localio);put_cred (ds_cred); +nfs4_ff_layout_put_deviceid (mirror_ds);return PNFS_ATTEMPTED ; out_failed: +nfs4_ff_layout_put_deviceid (mirror_ds);if (ff_layout_avoid_mds_available_ds (lseg) && !ds_fatal_error)return PNFS_TRY_AGAIN ;if (ff_layout_no_fallback_to_mds (lseg)) {
@@ -2333,6 +2356,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)struct rpc_clnt *ds_clnt;struct nfsd_file *localio;struct nfs4_ff_layout_mirror *mirror; +struct nfs4_ff_layout_ds *mirror_ds;const struct cred *ds_cred;loff_t offset = hdr->args.offset;int vers;
@@ -2346,22 +2370,24 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)FF_LAYOUT_LSEG (lseg)->stripe_unit, mirror->dss_count, offset); - ds =nfs4_ff_layout_prepare_ds (lseg, mirror, dss_id, true); + mirror_ds =ff_layout_get_mirror_ds (lseg->pls_layout, mirror, dss_id); + ds =nfs4_ff_layout_prepare_ds (lseg, mirror, mirror_ds, dss_id, true);if (IS_ERR (ds)) { ds_fatal_error =nfs_error_is_fatal (PTR_ERR (ds)); goto out_failed; } - ds_clnt =nfs4_ff_find_or_create_ds_client (mirror, ds->ds_clp, - hdr->inode, dss_id); + ds_clnt =nfs4_ff_find_or_create_ds_client (mirror_ds, ds->ds_clp, + hdr->inode);if (IS_ERR (ds_clnt)) goto out_failed; - ds_cred =ff_layout_get_ds_cred (mirror, &lseg->pls_range, hdr->cred, dss_id); + ds_cred =ff_layout_get_ds_cred (mirror, &lseg->pls_range, hdr->cred, + mirror_ds, dss_id);if (!ds_cred) goto out_failed; - vers =nfs4_ff_layout_ds_version (mirror, dss_id); + vers =nfs4_ff_layout_ds_version (mirror_ds); dprintk("%s ino %llu sync %d req %zu@%llu DS: %s cl_count %d vers %d\n", __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
@@ -2376,7 +2402,8 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)if (fh) hdr->args.fh = fh; -nfs4_ff_layout_select_ds_stateid (mirror, dss_id, &hdr->args.stateid); +nfs4_ff_layout_select_ds_stateid (mirror, mirror_ds, dss_id, + &hdr->args.stateid);/* * Note that if we ever decide to split across DSes,
@@ -2398,9 +2425,11 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) &ff_layout_write_call_ops_v4, sync, RPC_TASK_SOFTCONN, localio);put_cred (ds_cred); +nfs4_ff_layout_put_deviceid (mirror_ds);return PNFS_ATTEMPTED ; out_failed: +nfs4_ff_layout_put_deviceid (mirror_ds);if (ff_layout_avoid_mds_available_ds (lseg) && !ds_fatal_error)return PNFS_TRY_AGAIN ;if (ff_layout_no_fallback_to_mds (lseg)) {
@@ -2435,6 +2464,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)struct rpc_clnt *ds_clnt;struct nfsd_file *localio;struct nfs4_ff_layout_mirror *mirror; +struct nfs4_ff_layout_ds *mirror_ds =NULL ;const struct cred *ds_cred;u32 idx, dss_id;int vers, ret;
@@ -2447,20 +2477,22 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how) idx =calc_mirror_idx_from_commit (lseg, data->ds_commit_index); mirror =FF_LAYOUT_COMP (lseg, idx); dss_id =calc_dss_id_from_commit (lseg, data->ds_commit_index); - ds =nfs4_ff_layout_prepare_ds (lseg, mirror, dss_id, true); + mirror_ds =ff_layout_get_mirror_ds (lseg->pls_layout, mirror, dss_id); + ds =nfs4_ff_layout_prepare_ds (lseg, mirror, mirror_ds, dss_id, true);if (IS_ERR (ds)) goto out_err; - ds_clnt =nfs4_ff_find_or_create_ds_client (mirror, ds->ds_clp, - data->inode, dss_id); + ds_clnt =nfs4_ff_find_or_create_ds_client (mirror_ds, ds->ds_clp, + data->inode);if (IS_ERR (ds_clnt)) goto out_err; - ds_cred =ff_layout_get_ds_cred (mirror, &lseg->pls_range, data->cred, dss_id); + ds_cred =ff_layout_get_ds_cred (mirror, &lseg->pls_range, data->cred, + mirror_ds, dss_id);if (!ds_cred) goto out_err; - vers =nfs4_ff_layout_ds_version (mirror, dss_id); + vers =nfs4_ff_layout_ds_version (mirror_ds); dprintk("%s ino %llu, how %d cl_count %d vers %d\n", __func__, data->inode->i_ino, how, refcount_read(&ds->ds_clp->cl_count),
@@ -2486,8 +2518,10 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how) &ff_layout_commit_call_ops_v4, how, RPC_TASK_SOFTCONN, localio);put_cred (ds_cred); +nfs4_ff_layout_put_deviceid (mirror_ds);return ret; out_err: +nfs4_ff_layout_put_deviceid (mirror_ds);pnfs_generic_prepare_to_resend_writes (data);pnfs_generic_commit_release (data);return -EAGAIN ;
fs/nfs/flexfilelayout/flexfilelayout.h +11 -5
@@ -207,9 +207,9 @@ ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg) }static inline int -nfs4_ff_layout_ds_version (const struct nfs4_ff_layout_mirror *mirror,u32 dss_id) +nfs4_ff_layout_ds_version (const struct nfs4_ff_layout_ds *mirror_ds) { -return mirror->dss[dss_id].mirror_ds->ds_versions[0 ].version; +return mirror_ds->ds_versions[0 ].version; } static inline u32
@@ -245,23 +245,29 @@ struct nfs_fh * nfs4_ff_layout_select_ds_fh(struct nfs4_ff_layout_mirror *mirror, u32 dss_id);void nfs4_ff_layout_select_ds_stateid (const struct nfs4_ff_layout_mirror *mirror, +const struct nfs4_ff_layout_ds *mirror_ds,u32 dss_id,nfs4_stateid *stateid); +struct nfs4_ff_layout_ds * +ff_layout_get_mirror_ds (struct pnfs_layout_hdr *lo, +struct nfs4_ff_layout_mirror *mirror, +u32 dss_id);struct nfs4_pnfs_ds *nfs4_ff_layout_prepare_ds (struct pnfs_layout_segment *lseg,struct nfs4_ff_layout_mirror *mirror, +struct nfs4_ff_layout_ds *mirror_ds,u32 dss_id,bool fail_return);struct rpc_clnt * -nfs4_ff_find_or_create_ds_client (struct nfs4_ff_layout_mirror *mirror, +nfs4_ff_find_or_create_ds_client (const struct nfs4_ff_layout_ds *mirror_ds,struct nfs_client *ds_clp, -struct inode *inode, -u32 dss_id); +struct inode *inode);const struct cred *ff_layout_get_ds_cred (struct nfs4_ff_layout_mirror *mirror,const struct pnfs_layout_range *range,const struct cred *mdscred, +const struct nfs4_ff_layout_ds *mirror_ds,u32 dss_id);bool ff_layout_avoid_mds_available_ds (struct pnfs_layout_segment *lseg);bool ff_layout_avoid_read_on_rw (struct pnfs_layout_segment *lseg);
fs/nfs/flexfilelayout/flexfilelayoutdev.c +43 -31
155 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 487/1005 NFSv4/flexfiles: Hold a device node reference for layoutstats encoding
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
[ Upstream commit dbde656f2f7a8dced33413c83a0cb6b634bfb26e ]
ff_layout_mirror_prepare_stats() records a stripe's device under i_lock, but the layoutstats/layoutreturn XDR encode runs later and dereferences the mirror's pinned device node (for the DS netaddr) with no reference of its own. Once a CHANGE notification can re-point the pinned node, that read becomes use-after-free.
Take a node reference at prepare time and carry it with the stripe in a per-devinfo nfs4_ff_layoutstat_priv, released in ff_layout_free_layoutstats(). The priv entries live alongside the devinfo array: co-allocated for LAYOUTSTATS, an additional member of nfs4_flexfile_layoutreturn_args for LAYOUTRETURN.
Stable-dep-of: 788c4f628565 ("NFSv4/flexfiles: limit transport disconnects when cancelling I/O")
--- fs/nfs/flexfilelayout/flexfilelayout.c | 53 +++++++++++++++++--------- fs/nfs/flexfilelayout/flexfilelayout.h | 11 ++++++ 2 files changed, 47 insertions(+), 17 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +36 -17
@@ -44,10 +44,11 @@ static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,static int ff_layout_mirror_prepare_stats (struct pnfs_layout_hdr *lo,struct nfs42_layoutstat_devinfo *devinfo, +struct nfs4_ff_layoutstat_priv *priv,int dev_limit,enum nfs4_ff_op_type type);static void ff_layout_encode_ff_layoutupdate (struct xdr_stream *xdr,const struct nfs42_layoutstat_devinfo *devinfo, -struct nfs4_ff_layout_ds_stripe *dss_info); +struct nfs4_ff_layoutstat_priv *priv);static struct pnfs_layout_hdr *ff_layout_alloc_layout_hdr (struct inode *inode,gfp_t gfp_flags)
@@ -2805,7 +2806,7 @@ ff_layout_prepare_layoutreturn(struct nfs4_layoutreturn_args *args)spin_lock (&args->inode->i_lock); ff_args->num_dev =ff_layout_mirror_prepare_stats ( - &ff_layout->generic_hdr, &ff_args->devinfo[0 ], + &ff_layout->generic_hdr, &ff_args->devinfo[0 ], &ff_args->priv[0 ],ARRAY_SIZE (ff_args->devinfo),NFS4_FF_OP_LAYOUTRETURN );spin_unlock (&args->inode->i_lock);
@@ -2980,10 +2981,11 @@ ff_layout_encode_io_latency(struct xdr_stream *xdr,static void ff_layout_encode_ff_layoutupdate (struct xdr_stream *xdr,const struct nfs42_layoutstat_devinfo *devinfo, -struct nfs4_ff_layout_ds_stripe *dss_info) +struct nfs4_ff_layoutstat_priv *priv) { +struct nfs4_ff_layout_ds_stripe *dss_info = priv->dss_info;struct nfs4_pnfs_ds_addr *da; -struct nfs4_pnfs_ds *ds = dss_info->mirror_ds->ds; +struct nfs4_pnfs_ds *ds = priv->mirror_ds->ds;struct nfs_fh *fh = &dss_info->fh_versions[0 ];__be32 *p;
@@ -3030,10 +3032,10 @@ ff_layout_encode_layoutstats(struct xdr_stream *xdr, const void *args,static void ff_layout_free_layoutstats (struct nfs4_xdr_opaque_data *opaque) { -struct nfs4_ff_layout_ds_stripe *dss_info = opaque->data; -struct nfs4_ff_layout_mirror *mirror = dss_info->mirror; +struct nfs4_ff_layoutstat_priv *priv = opaque->data; -ff_layout_put_mirror (mirror); +nfs4_ff_layout_put_deviceid (priv->mirror_ds); +ff_layout_put_mirror (priv->dss_info->mirror); }static const struct nfs4_xdr_opaque_ops layoutstat_ops = {
@@ -3044,12 +3046,13 @@ static const struct nfs4_xdr_opaque_ops layoutstat_ops = {static int ff_layout_mirror_prepare_stats (struct pnfs_layout_hdr *lo,struct nfs42_layoutstat_devinfo *devinfo, +struct nfs4_ff_layoutstat_priv *priv,int dev_limit,enum nfs4_ff_op_type type) {struct nfs4_flexfile_layout *ff_layout =FF_LAYOUT_FROM_HDR (lo);struct nfs4_ff_layout_mirror *mirror;struct nfs4_ff_layout_ds_stripe *dss_info; -struct nfs4_deviceid_node *dev; +struct nfs4_ff_layout_ds *mirror_ds;int i =0 , dss_id;list_for_each_entry (mirror, &ff_layout->mirrors, mirrors) {
@@ -3057,7 +3060,8 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo, dss_info = &mirror->dss[dss_id];if (i >= dev_limit)break ; -if (IS_ERR_OR_NULL (dss_info->mirror_ds)) + mirror_ds = dss_info->mirror_ds; +if (IS_ERR_OR_NULL (mirror_ds))continue ; if (!test_and_clear_bit(NFS4_FF_MIRROR_STAT_AVAIL, &mirror->flags) &&
@@ -3066,9 +3070,14 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,/* mirror refcount put in cleanup_layoutstats */ if (!refcount_inc_not_zero (&mirror->ref))continue ; - dev = &dss_info->mirror_ds->id_node; +/* +* The mirror's pin holds the node while we're under +* i_lock; take a reference for the encode, put in +* ff_layout_free_layoutstats(). +*/ +atomic_inc (&mirror_ds->id_node.ref);memcpy (&devinfo->dev_id, - &dev->deviceid, + &mirror_ds->id_node.deviceid,NFS4_DEVICEID4_SIZE ); devinfo->offset =0 ; devinfo->length =NFS4_MAX_UINT64 ;
@@ -3084,9 +3093,12 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,spin_unlock (&mirror->lock); devinfo->layout_type =LAYOUT_FLEX_FILES ; devinfo->ld_private.ops = &layoutstat_ops; - devinfo->ld_private.data = &mirror->dss[dss_id]; + priv->dss_info = dss_info; + priv->mirror_ds = mirror_ds; + devinfo->ld_private.data = priv; devinfo++; + priv++; i++; } }
@@ -3097,21 +3109,28 @@ static int ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args) {struct pnfs_layout_hdr *lo;struct nfs4_flexfile_layout *ff_layout; +struct nfs4_ff_layoutstat_priv *priv;const int dev_count =PNFS_LAYOUTSTATS_MAXDEV ; -/* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics */ - args->devinfo =kmalloc_objs (*args->devinfo, dev_count, -nfs_io_gfp_mask ()); +/* +* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics. +* The per-devinfo private entries are co-allocated after the +* devinfo array and freed along with it. +*/ + args->devinfo =kmalloc (dev_count * (sizeof (*args->devinfo) + +sizeof (*priv)), +nfs_io_gfp_mask ());if (!args->devinfo)return -ENOMEM ; + priv = (struct nfs4_ff_layoutstat_priv *)&args->devinfo[dev_count];spin_lock (&args->inode->i_lock); lo =NFS_I (args->inode)->layout;if (lo &&pnfs_layout_is_valid (lo)) { ff_layout =FF_LAYOUT_FROM_HDR (lo); args->num_dev =ff_layout_mirror_prepare_stats ( - &ff_layout->generic_hdr, &args->devinfo[0 ], dev_count, -NFS4_FF_OP_LAYOUTSTATS ); + &ff_layout->generic_hdr, &args->devinfo[0 ], priv, + dev_count,NFS4_FF_OP_LAYOUTSTATS ); }else args->num_dev =0 ;spin_unlock (&args->inode->i_lock);
fs/nfs/flexfilelayout/flexfilelayout.h +11 -0
@@ -124,9 +124,20 @@ struct nfs4_flexfile_layout {unsigned long flags; }; +/* +* Per-devinfo private data for a layoutstats/layoutreturn encode: the +* stripe the stats describe plus a reference on its device node so the +* node (and its DS addresses) stay valid until the XDR encode runs. +*/ +struct nfs4_ff_layoutstat_priv { +struct nfs4_ff_layout_ds_stripe *dss_info; +struct nfs4_ff_layout_ds *mirror_ds; +}; +struct nfs4_flexfile_layoutreturn_args {struct list_head errors;struct nfs42_layoutstat_devinfo devinfo[FF_LAYOUTSTATS_MAXDEV ]; +struct nfs4_ff_layoutstat_priv priv[FF_LAYOUTSTATS_MAXDEV ];unsigned int num_errors;unsigned int num_dev;struct page *pages[1 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 488/1005 NFSv4/flexfiles: Make the pinned device node pointer RCU-managed
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
[ Upstream commit b14c22e01c5c4f8dfe9c7165c801796e1ec6ebae ]
Annotate mirror->dss[dss_id].mirror_ds as __rcu and convert the remaining readers, completing the preparation for re-pointing the pinned node while I/O is in flight:
- ff_layout_get_mirror_ds() takes its reference under rcu_read_lock() with atomic_inc_not_zero(), retrying if it races a reset. The resolve path takes the caller's reference before publishing the node with cmpxchg(), so a concurrent reset cannot drop the last reference under the caller: one reference is held for the installed pointer and one for the caller, and the pointer's reference is released elsewhere by xchg + put.
- The availability scans hold rcu_read_lock() across the walk; they only test flags on the RCU-freed node.
- ff_layout_cancel_io() holds a reference across the cancel and disconnect calls. Both of its callers hold i_lock and nothing on that path sleeps, so the reference is not about blocking: it is what keeps the node alive between the RCU-protected read and the use of mirror_ds->ds. The final put is never reached here, because the mirror's own pin outlives the loop -- which matters, since that put ends in nfs_put_client() and cannot run under a spinlock.
- ff_layout_mirror_prepare_stats() reads the pointer with rcu_dereference() under rcu_read_lock(). i_lock, which both callers hold, is what excludes the re-pointing walk added later in this series; it does not exclude the resolve path's cmpxchg(), which runs from I/O submission, so the read cannot claim i_lock as its update- side lock. A non-NULL pointer read there is stable regardless: the resolve path only ever installs over NULL.
- ff_layout_free_mirror() tears down the last reference; no concurrency.
The pointer is still only ever set once per mirror lifetime, so there is no behavior change; this commit makes the subsequent in-place re-resolve on CB_NOTIFY_DEVICEID CHANGE safe to introduce.
Stable-dep-of: 788c4f628565 ("NFSv4/flexfiles: limit transport disconnects when cancelling I/O")
--- fs/nfs/flexfilelayout/flexfilelayout.c | 35 ++++--- fs/nfs/flexfilelayout/flexfilelayout.h | 2 +- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 110 ++++++++++++++-------- 3 files changed, 93 insertions(+), 54 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +22 -13
@@ -313,7 +313,9 @@ static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror) cred =rcu_access_pointer (mirror->dss[dss_id].rw_cred);put_cred (cred);nfs_close_local_fh (&mirror->dss[dss_id].nfl); -nfs4_ff_layout_put_deviceid (mirror->dss[dss_id].mirror_ds); +/* the last reference to the mirror is gone; no concurrency */ +nfs4_ff_layout_put_deviceid (rcu_dereference_protected ( + mirror->dss[dss_id].mirror_ds,1 )); }kfree (mirror->dss);
@@ -2578,22 +2580,29 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg)for (idx =0 ; idx < flseg->mirror_array_cnt; idx++) { mirror = flseg->mirror_array[idx];for (dss_id =0 ; dss_id < mirror->dss_count; dss_id++) { - mirror_ds = mirror->dss[dss_id].mirror_ds; -if (IS_ERR_OR_NULL (mirror_ds)) +rcu_read_lock (); + mirror_ds =rcu_dereference (mirror->dss[dss_id].mirror_ds); +if (IS_ERR_OR_NULL (mirror_ds) || + !atomic_inc_not_zero (&mirror_ds->id_node.ref)) { +rcu_read_unlock ();continue ; - ds = mirror->dss[dss_id].mirror_ds->ds; + } +rcu_read_unlock (); + ds = mirror_ds->ds;if (!ds) -continue ; + goto next; ds_clp = ds->ds_clp;if (!ds_clp) -continue ; + goto next; clnt = ds_clp->cl_rpcclient;if (!clnt) -continue ; + goto next;if (!rpc_cancel_tasks (clnt, -ECANCELED , ff_layout_match_io, lseg)) -continue ; + goto next;rpc_clnt_disconnect (clnt); +next: +nfs4_ff_layout_put_deviceid (mirror_ds); } } }
@@ -3055,12 +3064,13 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo, struct nfs4_ff_layout_ds *mirror_ds; int i = 0, dss_id; + rcu_read_lock(); list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) { for (dss_id = 0; dss_id < mirror->dss_count; ++dss_id) { dss_info = &mirror->dss[dss_id]; if (i >= dev_limit) break; - mirror_ds = dss_info->mirror_ds; + mirror_ds = rcu_dereference(dss_info->mirror_ds); if (IS_ERR_OR_NULL(mirror_ds)) continue; if (!test_and_clear_bit(NFS4_FF_MIRROR_STAT_AVAIL,
@@ -3070,10 +3080,8 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,/* mirror refcount put in cleanup_layoutstats */ if (!refcount_inc_not_zero (&mirror->ref))continue ; -/* -* The mirror's pin holds the node while we're under -* i_lock; take a reference for the encode, put in -* ff_layout_free_layoutstats(). +/* The pin holds a reference; it is exchanged out only +* under i_lock. Put in ff_layout_free_layoutstats(). */ atomic_inc (&mirror_ds->id_node.ref); memcpy(&devinfo->dev_id,
@@ -3102,6 +3110,7 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo, i++; } } +rcu_read_unlock ();return i; }
fs/nfs/flexfilelayout/flexfilelayout.h +1 -1
@@ -79,7 +79,7 @@ struct nfs4_ff_layout_ds_stripe {struct nfs4_ff_layout_mirror *mirror;struct nfs4_deviceid devid;u32 efficiency; -struct nfs4_ff_layout_ds *mirror_ds; +struct nfs4_ff_layout_ds __rcu *mirror_ds;u32 fh_versions_cnt;struct nfs_fh *fh_versions;nfs4_stateid stateid;
fs/nfs/flexfilelayout/flexfilelayoutdev.c +70 -40
154 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 489/1005 SUNRPC: add request-scoped disconnects when cancelling tasks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Menninger <[email protected]>
[ Upstream commit 9d84719d34cb98a2f584e38679f95216c1a15d0e ]
rpc_cancel_tasks() allows callers to cancel a selected set of RPC tasks, but callers that also need to tear down the connection currently have to disconnect at the rpc_clnt level.
That is broader than necessary for clients with multiple transports. A cancelled request is associated with a specific rpc_xprt and records the connection generation on which it was transmitted in rq_connect_cookie.
Add rpc_cancel_tasks_and_disconnect() to cancel matching tasks and mark matching requests that remain on the transport transmit or receive queues for conditional transport disconnect when the request is released.
Store the disconnect indication in struct rpc_rqst rather than struct rpc_task. An RPC task can release one request and later acquire another, so task-scoped state could otherwise be consumed by a successor request and disconnect the wrong transport generation.
After cancelling matching tasks, walk the client's transports and mark matching requests belonging to that client that remain on the transmit or receive queues. An rpc_xprt may be shared by multiple rpc_clnt instances, so requests belonging to other clients are not marked.
When a marked request is released, consume the marker under the existing transport_lock critical section. If the request was transmitted, call xprt_conditional_disconnect_locked() with its rq_connect_cookie. The disconnect is skipped if that cookie no longer matches the transport's current connection generation.
This adds no lock acquisition to the normal request-release path. Requests that were never transmitted do not trigger this additional disconnect.
Stable-dep-of: 788c4f628565 ("NFSv4/flexfiles: limit transport disconnects when cancelling I/O")
--- include/linux/sunrpc/sched.h | 4 ++ include/linux/sunrpc/xprt.h | 5 ++ net/sunrpc/clnt.c | 94 ++++++++++++++++++++++++------ net/sunrpc/sunrpc.h | 8 +++ net/sunrpc/xprt.c | 107 +++++++++++++++++++++++++++++++++-- 5 files changed, 195 insertions(+), 23 deletions(-)
include/linux/sunrpc/sched.h +4 -0
@@ -230,6 +230,10 @@ unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error,bool (*fnmatch)(const struct rpc_task *,const void *), const void *data); +unsigned long rpc_cancel_tasks_and_disconnect (struct rpc_clnt *clnt,int error, +bool (*fnmatch)(const struct rpc_task *, +const void *), +const void *data);void rpc_execute (struct rpc_task *);void rpc_init_priority_wait_queue (struct rpc_wait_queue *,const char *);void rpc_init_wait_queue (struct rpc_wait_queue *,const char *);
include/linux/sunrpc/xprt.h +5 -0
@@ -112,6 +112,11 @@ struct rpc_rqst {ktime_t rq_xtime;/* transmit time stamp */ int rq_ntrans; +bool rq_disconnect_on_release; +/* +* protected by rq_xprt->transport_lock +* while the request is active +*/ #if defined(CONFIG_SUNRPC_BACKCHANNEL )struct lwq_node rq_bc_list;/* Callback service list */
net/sunrpc/clnt.c +77 -17
116 lines not on this page · raw message
net/sunrpc/sunrpc.h +8 -0
@@ -38,9 +38,17 @@ static inline int sock_is_loopback(struct sock *sk)struct svc_serv ;struct svc_rqst ; +struct rpc_clnt ; +struct rpc_task ; +struct rpc_xprt ;int rpc_clients_notifier_register (void );void rpc_clients_notifier_unregister (void );void auth_domain_cleanup (void );void svc_sock_update_bufs (struct svc_serv *serv);enum svc_auth_status svc_authenticate (struct svc_rqst *rqstp); +void xprt_mark_matching_reqs_disconnect_on_release (struct rpc_xprt *xprt, +const struct rpc_clnt *clnt, +bool (*fnmatch)(const struct rpc_task *, +const void *), +const void *data);#endif /* _NET_SUNRPC_SUNRPC_H */
net/sunrpc/xprt.c +101 -6
143 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 490/1005 NFSv4/flexfiles: limit transport disconnects when cancelling I/O
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Menninger <[email protected]>
[ Upstream commit 788c4f628565897e7090cdf5bb2e049e74aeca96 ]
ff_layout_cancel_io() cancels RPC tasks associated with a recalled or revoked layout segment. If any matching tasks are found, it then calls rpc_clnt_disconnect().
rpc_clnt_disconnect() disconnects every transport attached to the RPC client. A data server client can have multiple transports, while the cancelled requests may have used only a subset of them. Cancelling I/O for one layout segment can therefore disrupt unrelated I/O using other transports belonging to the same data server client.
This is particularly disruptive with RPC/RDMA during data server recovery, where unnecessary transport disconnects can result in repeated reconnect activity on otherwise unaffected connections.
Use rpc_cancel_tasks_and_disconnect() instead. Matching tasks are still cancelled, but only matching requests belonging to that client that remain on the transport transmit or receive queues are marked for disconnect. When such a request is released, SUNRPC conditionally disconnects the connection generation on which that request was sent.
This preserves cancellation and draining of I/O associated with the layout segment without disconnecting unrelated transports attached to the same RPC client.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +3 -4
@@ -2597,10 +2597,9 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg) clnt = ds_clp->cl_rpcclient;if (!clnt) goto next; -if (!rpc_cancel_tasks (clnt, -ECANCELED , - ff_layout_match_io, lseg)) - goto next; -rpc_clnt_disconnect (clnt); +rpc_cancel_tasks_and_disconnect (clnt, -ECANCELED , + ff_layout_match_io, + lseg); next:nfs4_ff_layout_put_deviceid (mirror_ds); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 491/1005 net/mlx5: E-switch, Restore host PF enable for ECPF that isnt E-switch manager
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit 4777203cc9af51db5ae647920c14ee9451e783d7 ]
The cited commit breaks host PF enable_hca when the ECPF isn't E-switch manager. For example, when the link layer is infiniband, the ECPF isn't E-switch manager, so after the cited commit enable_hca is never issued for the host PF, it stays in initializing state and fails to probe.
Fix it by checking esw_allowed() only for vport bookkeeping
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +12 -12
@@ -1509,13 +1509,9 @@ int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)struct mlx5_vport *vport;int err; -if (!mlx5_core_is_ecpf (dev) || !mlx5_esw_allowed (esw)) +if (!mlx5_core_is_ecpf (dev))return 0 ; - vport =mlx5_eswitch_get_vport (esw, vport_num); -if (IS_ERR (vport)) -return PTR_ERR (vport); -/* Once vport and representor are ready, take the PF out of * initializing state. Enabling HCA clears the iser->initializing * bit and PF driver loading can progress.
@@ -1524,7 +1520,11 @@ int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)if (err)return err; - vport->pf_activated = true; +if (mlx5_esw_allowed (esw)) { + vport =mlx5_eswitch_get_vport (esw, vport_num); +if (!IS_ERR (vport)) + vport->pf_activated = true; + }return 0 ; }
@@ -1535,18 +1535,18 @@ int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)struct mlx5_vport *vport;int err; -if (!mlx5_core_is_ecpf (dev) || !mlx5_esw_allowed (esw)) +if (!mlx5_core_is_ecpf (dev))return 0 ; - vport =mlx5_eswitch_get_vport (esw, vport_num); -if (IS_ERR (vport)) -return PTR_ERR (vport); - err =mlx5_cmd_pf_disable_hca (dev, vport_num);if (err)return err; - vport->pf_activated = false; +if (mlx5_esw_allowed (esw)) { + vport =mlx5_eswitch_get_vport (esw, vport_num); +if (!IS_ERR (vport)) + vport->pf_activated = false; + }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 492/1005 net/mlx5: macsec: Dont remove fs_id when adding a rule fails
In reply to Greg Kroah-Hartman7.3-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 493/1005 dpll: notify about a reference sync pair only if it was added
In reply to Greg Kroah-Hartman7.3-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
@@ -1081,7 +1081,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 494/1005 ipv4: route: dont blackhole in-use routes when retiring fnhe routes
In reply to Greg Kroah-Hartman7.3-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); } }
@@ -1505,10 +1514,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 495/1005 ptp: kvm: x86: Leak clock_pair page if changing its encryption fails
In reply to Greg Kroah-Hartman7.3-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 496/1005 net: skbuff: uncharge trimmed zerocopy frags on error
In reply to Greg Kroah-Hartman7.3-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
@@ -1922,6 +1922,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) {
@@ -1942,12 +1943,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 497/1005 net/mlx5e: Release IPsec root table reference on RX setup failure
In reply to Greg Kroah-Hartman7.3-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 498/1005 net/mlx5e: Serialize ipsec encap reservations with eswitch operations
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit b102f927c69e2d7cf849bcfb7f7b0cd6e52fc1b0 ]
mlx5_eswitch_block_encap() takes mode_lock but ignores eswitch_operation_in_progress. mlx5_devlink_eswitch_encap_mode_set() claims the operation and drops mode_lock while rebuilding the FDB and updating offloads.encap, so a reservation can read a stale or rolled-back encap value. In diagram form:
T1: first IPsec SA (NIC table) T2: encap none -> basic
mlx5_devlink_eswitch_encap_mode_set()
down_write(&esw->mode_lock)
sees num_block_encap == 0
eswitch_operation_in_progress = true
up_write(&esw->mode_lock)
esw_destroy_offloads_fdb_tables()
mlx5e_xfrm_add_state()
mlx5e_ipsec_fs_tunnel_allowed()
mlx5_eswitch_block_encap()
down_write(&esw->mode_lock)
reads encap == NONE
num_block_encap++
up_write(&esw->mode_lock)
esw->offloads.encap = BASIC
esw_create_offloads_fdb_tables()The race happens therefore because offloads.encap is not consistently accessed under mode_lock. There are other variations of the above race (e.g. in rollback, or in tx_create()).
Use mlx5_esw_lock() to reject a reservation while an operation is in progress. This implies changing mlx5e_ipsec_fs_tunnel_allowed() to propagate the error. Note that these are not new failure modes as it seems on first glance, because if the eswitch_operation_in_progress flag is set, rx_get()/tx_get()->mlx5_eswitch_block_mode() already fails with -EBUSY. The new code simply protects against an operation initiated in the short window after mlx5_eswitch_block_mode().
This race was found by Sashiko during inspection of another patch of this series. No attempt has been made to trigger it, as it requires very precise timing.
--- .../mellanox/mlx5/core/en_accel/ipsec.c | 5 ++++- .../mellanox/mlx5/core/en_accel/ipsec.h | 2 +- .../mellanox/mlx5/core/en_accel/ipsec_fs.c | 21 ++++++++++++------- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 6 +++--- .../mellanox/mlx5/core/eswitch_offloads.c | 20 +++++++++++------- 5 files changed, 35 insertions(+), 19 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +4 -1
@@ -812,7 +812,10 @@ static int mlx5e_xfrm_add_state(struct net_device *dev,if (x->props.mode ==XFRM_MODE_TUNNEL && x->xso.type ==XFRM_DEV_OFFLOAD_PACKET ) { - allow_tunnel_mode =mlx5e_ipsec_fs_tunnel_allowed (sa_entry); + err =mlx5e_ipsec_fs_tunnel_allowed (sa_entry); +if (err <0 ) + goto unblock_mode; + allow_tunnel_mode = err;if (!allow_tunnel_mode) {NL_SET_ERR_MSG_MOD (extack,"Packet offload tunnel mode is disabled due to encap settings" );
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h +1 -1
@@ -320,7 +320,7 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry);int mlx5e_accel_ipsec_fs_add_pol (struct mlx5e_ipsec_pol_entry *pol_entry);void mlx5e_accel_ipsec_fs_del_pol (struct mlx5e_ipsec_pol_entry *pol_entry);void mlx5e_accel_ipsec_fs_modify (struct mlx5e_ipsec_sa_entry *sa_entry); -bool mlx5e_ipsec_fs_tunnel_allowed (struct mlx5e_ipsec_sa_entry *sa_entry); +int mlx5e_ipsec_fs_tunnel_allowed (struct mlx5e_ipsec_sa_entry *sa_entry);int mlx5_ipsec_create_sa_ctx (struct mlx5e_ipsec_sa_entry *sa_entry);void mlx5_ipsec_free_sa_ctx (struct mlx5e_ipsec_sa_entry *sa_entry);
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +14 -7
@@ -1072,9 +1072,12 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, goto err_fs_ft_sa_sel;/* Create FT */ -if (mlx5_ipsec_device_caps (mdev) &MLX5_IPSEC_CAP_TUNNEL ) - rx->allow_tunnel_mode = -mlx5_eswitch_block_encap (mdev, rx == ipsec->rx_esw); +if (mlx5_ipsec_device_caps (mdev) &MLX5_IPSEC_CAP_TUNNEL ) { + err =mlx5_eswitch_block_encap (mdev, rx == ipsec->rx_esw); +if (err <0 ) + goto err_fs_ft; + rx->allow_tunnel_mode = err; + }if (rx->allow_tunnel_mode) flags =MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT ;
@@ -1315,9 +1318,12 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,if (err) goto err_status_rule; -if (mlx5_ipsec_device_caps (mdev) &MLX5_IPSEC_CAP_TUNNEL ) - tx->allow_tunnel_mode = -mlx5_eswitch_block_encap (mdev, tx == ipsec->tx_esw); +if (mlx5_ipsec_device_caps (mdev) &MLX5_IPSEC_CAP_TUNNEL ) { + err =mlx5_eswitch_block_encap (mdev, tx == ipsec->tx_esw); +if (err <0 ) + goto err_encap; + tx->allow_tunnel_mode = err; + }if (tx->allow_tunnel_mode) flags =MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT ;
@@ -1387,6 +1393,7 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx, err_sa_ft:if (tx->allow_tunnel_mode)mlx5_eswitch_unblock_encap (mdev); +err_encap:mlx5_del_flow_rules (tx->status.rule); err_status_rule:mlx5_destroy_flow_table (tx->ft.status);
@@ -2854,7 +2861,7 @@ void mlx5e_accel_ipsec_fs_modify(struct mlx5e_ipsec_sa_entry *sa_entry)memcpy (sa_entry, &sa_entry_shadow,sizeof (*sa_entry)); } -bool mlx5e_ipsec_fs_tunnel_allowed (struct mlx5e_ipsec_sa_entry *sa_entry) +int mlx5e_ipsec_fs_tunnel_allowed (struct mlx5e_ipsec_sa_entry *sa_entry) {struct mlx5e_ipsec *ipsec = sa_entry->ipsec;struct xfrm_state *x = sa_entry->x;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +3 -3
@@ -967,7 +967,7 @@ void mlx5_eswitch_unload_reps(struct mlx5_eswitch *esw);bool mlx5_eswitch_is_peer (struct mlx5_eswitch *esw,struct mlx5_eswitch *peer_esw); -bool mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb); +int mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb);void mlx5_eswitch_unblock_encap (struct mlx5_core_dev *dev);int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev);
@@ -1071,10 +1071,10 @@ mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw)static inline void mlx5_eswitch_unload_reps (struct mlx5_eswitch *esw) {} -static inline bool +static inline int mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb) { -return true; +return 1 ; }static inline void mlx5_eswitch_unblock_encap (struct mlx5_core_dev *dev)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +13 -7
@@ -4689,25 +4689,31 @@ int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)return esw_inline_mode_to_devlink (esw->offloads.inline_mode, mode); } -bool mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb) +/* Return 1 if allowed, 0 if disallowed by the configuration, or -EBUSY +* if an eswitch operation is in progress. +*/ +int mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb) {struct mlx5_eswitch *esw = dev->priv.eswitch;enum devlink_eswitch_encap_mode encap; -bool allow_tunnel = false; +int ret;if (!mlx5_esw_allowed (esw)) -return true; +return 1 ; + + ret =mlx5_esw_lock (esw); +if (ret) +return ret; -down_write (&esw->mode_lock); encap = esw->offloads.encap;if (esw->mode ==MLX5_ESWITCH_LEGACY || (encap ==DEVLINK_ESWITCH_ENCAP_MODE_NONE && !from_fdb)) { - allow_tunnel = true; + ret =1 ; esw->offloads.num_block_encap++; } -up_write (&esw->mode_lock); +mlx5_esw_unlock (esw); -return allow_tunnel; +return ret; }void mlx5_eswitch_unblock_encap (struct mlx5_core_dev *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 499/1005 net/mlx5e: Take HCA devcom lock before esw->mode_lock
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit b7e98883eeb72b736dbdeb443e1f43e45f8e5dc1 ]
Uplink ETH driver removal waits for any eswitch operation in progress before removing REPs. Removal through mlx5_unregister_device() or mlx5_detach_device() does this while holding the HCA devcom lock, which is used by peer devices in the same group.
An E-Switch mode change can therefore race with a Socket Direct secondary device removal:
T1: primary mode set T2: SD secondary dev removalmlx5_devlink_eswitch_mode_set()
sets operation in progress
mlx5_unregister_device()
mlx5_devcom_comp_lock(hca)
...
mlx5e_remove()
mlx5_sd_get_adev() -> T1 dev
mlx5_eswitch_safe_aux_devs_remove()
waits for T1's operation esw_offloads_start()
esw_mode_change()
mlx5_devcom_comp_lock(hca)
waits for T2's lock
The timeout in mlx5_eswitch_safe_aux_devs_remove() makes this not a deadlock, but representor removal is skipped in that case which is incorrect.
This bug was found by Sashiko inspecting the next patch in the series, which removes the timeout. It wasn't reproduced but the scenario seems plausible, albeit unlikely. This was undetectable by lockdep because the down_read_trylock() in mlx5_esw_hold() doesn't register as a lock edge, and also because it can't see the wait on the flag as a lock edge.
Fix the lock order so the HCA devcom lock is taken in mlx5_devlink_eswitch_mode_set() before esw->mode_lock and held for the duration of the mode change.
Expanding the HCA devcom lock critical section implies new lock edges being added, but this is safe:
- mlx5_devlink_netdev_netns_immutable_set() adds HCA devcom -> RTNL, but there's already a HCA devcom -> RTNL dependency in mlx5_register_device() -..-> register_netdev()
- esw_offloads_disable/enable() -> esw devcom cleanup/init: adds HCA devcom -> esw devcom. Nothing takes the HCA devcom lock while holding the esw devcom lock.
--- .../net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +5 -4
@@ -2457,8 +2457,8 @@ void mlx5_esw_reps_unblock(struct mlx5_eswitch *esw)static void esw_mode_change (struct mlx5_eswitch *esw,u16 mode) { +mlx5_devcom_comp_assert_locked (esw->dev->priv.hca_devcom_comp);mlx5_esw_reps_unblock (esw); -mlx5_devcom_comp_lock (esw->dev->priv.hca_devcom_comp);if (esw->dev->priv.flags &MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ||mlx5_core_mp_enabled (esw->dev)) { esw->mode = mode;
@@ -2471,7 +2471,6 @@ static void esw_mode_change(struct mlx5_eswitch *esw, u16 mode) esw->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; out:mlx5_rescan_drivers_locked (esw->dev); -mlx5_devcom_comp_unlock (esw->dev->priv.hca_devcom_comp);mlx5_esw_reps_block (esw); }
@@ -4485,10 +4484,11 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,return 0 ;mlx5_lag_disable_change (esw->dev); +mlx5_devcom_comp_lock (esw->dev->priv.hca_devcom_comp); err =mlx5_esw_try_lock (esw);if (err <0 ) {NL_SET_ERR_MSG_MOD (extack,"Can't change mode, E-Switch is busy" ); - goto enable_lag; + goto unlock_hca; } cur_mlx5_mode = err; err =0 ;
@@ -4551,7 +4551,8 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, esw->eswitch_operation_in_progress = false; unlock:mlx5_esw_unlock (esw); -enable_lag: +unlock_hca: +mlx5_devcom_comp_unlock (esw->dev->priv.hca_devcom_comp);mlx5_lag_enable_change (esw->dev);/* Shared FDB activation is creating LAG which is changing reps. */ if (!err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 500/1005 net/mlx5e: Fix E-Switch races in uplink unbind
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit 5eaf9931c8af41b1f0de6dc0589efa698784157c ]
Unbinding the uplink Ethernet auxiliary driver in switchdev mode with offloaded IPsec policies deadlocks on the esw->mode_lock semaphore:mlx5_eswitch_safe_aux_devs_remove()
mlx5_esw_hold()
down_read_trylock(&esw->mode_lock) (*)
mlx5_core_reps_aux_devs_remove()
...
mlx5e_vport_uplink_rep_unload()
unregister_netdev()
xfrm_dev_unregister()
xfrm_dev_policy_flush()
xfrm_policy_kill()
xfrm_dev_policy_delete()
mlx5e_xfrm_del_policy()
mlx5e_accel_ipsec_fs_del_pol()
rx_ft_put_policy()
rx_put()
mlx5_eswitch_unblock_mode()
down_write(&esw->mode_lock) (BOOM)Another deadlock with IPsec states:mlx5_eswitch_safe_aux_devs_remove()
mlx5_esw_hold()
down_read_trylock(&esw->mode_lock) (*)
mlx5_core_reps_aux_devs_remove()
...
mlx5e_vport_uplink_rep_unload()
unregister_netdev()
xfrm_dev_unregister()
xfrm_dev_state_flush()
xfrm_dev_state_free()
mlx5e_xfrm_free_state()
mlx5e_accel_ipsec_fs_del_rule()
rx_ft_put()
rx_put()
rx_destroy()
mlx5_eswitch_unblock_encap()
down_write(&esw->mode_lock) (BOOM)To fix these, first refactor initiators of eswitch operations so they no longer step on each other's toes.
The active/inactive toggle and setting the inline/encap mode now use the new mlx5_esw_lock_wait(), which waits for an operation in progress to finish. They all hold devl_lock, so the only operation they can find in progress is an uplink unbind, which doesn't need devl_lock. Setting the esw mode keeps using mlx5_esw_try_lock(), which also rejects the change while eswitch users exist and bails out with -EBUSY.
mlx5_eswitch_safe_aux_devs_remove() now also waits for an operation in progress with the same mlx5_esw_lock_wait() before initiating one, dropping mode_lock and then removing representors.
The deadlocks are avoided.
Finishing an operation in progress now requires mlx5_esw_unlock() to wake up any waiters instead of plain up_write(&mode_lock).
As a side effect, the timeout in mlx5_eswitch_safe_aux_devs_remove() is gone, which fixes another scary corner case, of representor devs not being removed on timeout but leaked instead. The timeout hid the SD deadlock fixed in the previous patch. Now that that's gone, no reason for the timeout to stay.
This was found by internal testing and reproduced on HW.
It was independently found by Sashiko during analysis of another patch in this series.
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 24 +++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + .../mellanox/mlx5/core/eswitch_offloads.c | 50 +++++++++---------- 3 files changed, 48 insertions(+), 27 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +24 -0
@@ -3039,12 +3039,36 @@ int mlx5_esw_lock(struct mlx5_eswitch *esw)return 0 ; } +static void esw_mode_lock (struct mlx5_eswitch *esw) +{ +down_write (&esw->mode_lock); +} + +static void esw_mode_unlock (struct mlx5_eswitch *esw) +{ +up_write (&esw->mode_lock); +} + +/* Lock the eswitch and wait for an operation in progress to finish. */ +void mlx5_esw_lock_wait (struct mlx5_eswitch *esw) +{ +down_write (&esw->mode_lock); +wait_var_event_any_lock (&esw->eswitch_operation_in_progress, + !esw->eswitch_operation_in_progress, + esw, esw_mode,TASK_UNINTERRUPTIBLE ); +} +/** * mlx5_esw_unlock() - Release write lock on esw mode lock * @esw: eswitch device. +* +* Also wakes up mlx5_esw_lock_wait() waiters, so it must be used to release +* mode_lock after clearing eswitch_operation_in_progress. */ void mlx5_esw_unlock (struct mlx5_eswitch *esw) { +wake_up_var_locked (&esw->eswitch_operation_in_progress, + &esw->mode_lock);up_write (&esw->mode_lock); }
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -948,6 +948,7 @@ void mlx5_esw_get(struct mlx5_core_dev *dev);void mlx5_esw_put (struct mlx5_core_dev *dev);int mlx5_esw_try_lock (struct mlx5_eswitch *esw);int mlx5_esw_lock (struct mlx5_eswitch *esw); +void mlx5_esw_lock_wait (struct mlx5_eswitch *esw);void mlx5_esw_unlock (struct mlx5_eswitch *esw);void esw_vport_change_handle_locked (struct mlx5_vport *vport);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +23 -27
92 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 501/1005 net/mlx5e: Fix ipsec core device access during profile changes
In reply to Greg Kroah-Hartman7.3-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
@@ -773,12 +773,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 ;
@@ -797,16 +805,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;
@@ -877,9 +885,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 ;
@@ -895,11 +903,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" );
@@ -1268,16 +1276,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;
@@ -1288,7 +1304,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; }
@@ -1302,7 +1318,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
@@ -6383,7 +6383,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 ;
@@ -6468,6 +6468,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
Greg Kroah-Hartman
maintainerPATCH 502/1005 net/mlx5e: Block E-Switch mode changes during IPsec policy creation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit d9e4ac08ea892da54c5aa7ae4a368f2d09db589c ]
Eswitch mode changes can tear down the IPsec context while policy creation is accessing it. The mode-blocking reference acquired when creating a flow table comes too late: the table lookup already accesses the IPsec context before taking that reference.
Take a temporary mode-blocking reference before checking the IPsec context and validating the policy. This gets dropped after successful setup, when the flow table holds its own reference.
The temporary reservation must allow reuse of existing IPsec tables. For example:
1. An offloaded inbound IPsec policy is added on the uplink.
2. A TC flower rule is added on a VF representor.
3. Another uplink policy is added using the same RX tables.
The third policy reuses the first policy's tables, so it must not be rejected merely because esw->user_count is nonzero. Add a check_users argument to mlx5_eswitch_block_mode(). Pass false for temporary policy reservations and true when creating the first table (rx_get()/tx_get()).
Temporary reservations take mode_lock and check operation ownership without requiring eswitch user_count to be zero.
mlx5e_xfrm_add_state() needs the same early mode reservation and is handled in the next patch.
This was found by Sashiko, during review of the last patch in the series. No reproduction attempted, as it seems quite a tricky race to successfully trigger.
--- .../mellanox/mlx5/core/en_accel/ipsec.c | 23 +++++++++++++++---- .../mellanox/mlx5/core/en_accel/ipsec_fs.c | 4 ++-- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 8 +++++-- .../mellanox/mlx5/core/eswitch_offloads.c | 9 +++++--- 4 files changed, 32 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +18 -5
@@ -814,7 +814,7 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, goto err_xfrm; } - err =mlx5_eswitch_block_mode (mdev); + err =mlx5_eswitch_block_mode (mdev, true);if (err) goto unblock_ipsec;
@@ -1288,18 +1288,28 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x,return -EBUSY ; } +/* Block esw mode changes until the policy holds its own block. */ + err =mlx5_eswitch_block_mode (mdev, false); +if (err) { +NL_SET_ERR_MSG_MOD (extack,"Eswitch busy, can't add policy" ); +return err; + } +if (!priv->ipsec) {NL_SET_ERR_MSG_MOD (extack,"Device doesn't support IPsec packet offload" ); -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + goto unblock_mode; } err =mlx5e_xfrm_validate_policy (mdev, x, extack);if (err) -return err; + goto unblock_mode; pol_entry =kzalloc_obj (*pol_entry); -if (!pol_entry) -return -ENOMEM ; +if (!pol_entry) { + err = -ENOMEM ; + goto unblock_mode; + } pol_entry->x = x; pol_entry->ipsec = priv->ipsec;
@@ -1315,6 +1325,7 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x, goto err_fs; x->xdo.offload_handle = (unsigned long )pol_entry; +mlx5_eswitch_unblock_mode (mdev);return 0 ; err_fs:
@@ -1322,6 +1333,8 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x, ipsec_busy:kfree (pol_entry);NL_SET_ERR_MSG_MOD (extack,"Device failed to offload this policy" ); +unblock_mode: +mlx5_eswitch_unblock_mode (mdev);return err; }
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +2 -2
@@ -1134,7 +1134,7 @@ static int rx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,if (rx->ft.refcnt) goto skip; - err =mlx5_eswitch_block_mode (mdev); + err =mlx5_eswitch_block_mode (mdev, true);if (err)return err;
@@ -1427,7 +1427,7 @@ static int tx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,if (tx->ft.refcnt) goto skip; - err =mlx5_eswitch_block_mode (mdev); + err =mlx5_eswitch_block_mode (mdev, true);if (err)return err;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +6 -2
@@ -971,7 +971,7 @@ bool mlx5_eswitch_is_peer(struct mlx5_eswitch *esw,int mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb);void mlx5_eswitch_unblock_encap (struct mlx5_core_dev *dev); -int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev); +int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev,bool check_users);void mlx5_eswitch_unblock_mode (struct mlx5_core_dev *dev);static inline int mlx5_eswitch_num_vfs (struct mlx5_eswitch *esw)
@@ -1082,7 +1082,11 @@ static inline void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev) { } -static inline int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev) {return 0 ; } +static inline int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev, +bool check_users) +{ +return 0 ; +}static inline void mlx5_eswitch_unblock_mode (struct mlx5_core_dev *dev) {}static inline bool mlx5_eswitch_block_ipsec (struct mlx5_core_dev *dev) {
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +6 -3
@@ -4342,7 +4342,7 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)return 0 ; } -int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev) +int mlx5_eswitch_block_mode (struct mlx5_core_dev *dev,bool check_users) {struct mlx5_eswitch *esw = dev->priv.eswitch;int err;
@@ -4350,8 +4350,11 @@ int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev)if (!mlx5_esw_allowed (esw))return 0 ; -/* Take TC into account */ - err =mlx5_esw_try_lock (esw); +/* Temporary reservations may reuse tables while TC users exist. */ +if (check_users) + err =mlx5_esw_try_lock (esw); +else + err =mlx5_esw_lock (esw);if (err <0 )return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 503/1005 net/mlx5e: Block E-Switch mode changes during IPsec state creation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit 0d09de8e4f11391e8468219dbbc7af027e39e9b8 ]
mlx5e_xfrm_add_state() reads priv->ipsec before blocking eswitch mode changes. A concurrent profile change can free the saved IPsec context and cause use-after-free.
The temporary mode reservation was added in commit 22239eb258bc ("net/mlx5e: Prevent tunnel reformat when tunnel mode not allowed") after saving priv->ipsec but the race was actually enabled by the "Fixes" commit.
Extend the reservation to cover obtaining the context as well.
Use mlx5_eswitch_block_mode(mdev, false) for the temporary reservation, as policy creation does, to check operation ownership under mode_lock without rejecting existing eswitch users. This allows reusing existing IPsec tables while TC rules exist on VF representors.
Check the context only after taking the mode reservation, so a concurrent mode change consistently returns -EBUSY and a missing context returns -EOPNOTSUPP, preserving software fallback for crypto offload. Keep the atomic acquire-placeholder path exempt, since it creates no hardware state and cannot take sleeping locks.
This was found by Sashiko, during review of the last patch in the series. No reproduction attempted, as it seems quite a tricky race to successfully trigger.
--- .../mellanox/mlx5/core/en_accel/ipsec.c | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +23 -14
@@ -771,6 +771,7 @@ static int mlx5e_xfrm_add_state(struct net_device *dev,struct xfrm_state *x, struct netlink_ext_ack *extack) { + bool is_acq = x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ;struct mlx5e_ipsec_sa_entry *sa_entry =NULL ;bool allow_tunnel_mode = false;struct mlx5_core_dev *mdev;
@@ -787,20 +788,31 @@ static int mlx5e_xfrm_add_state(struct net_device *dev,NL_SET_ERR_MSG_MOD (extack,"Eswitch busy, can't add state" );return -EBUSY ; } -if (!priv->ipsec) -return -EOPNOTSUPP ; + +if (!is_acq) { + err =mlx5_eswitch_block_mode (mdev, false); +if (err) +return err; + } ipsec = priv->ipsec; - gfp = (x->xso.flags &XFRM_DEV_OFFLOAD_FLAG_ACQ ) ?GFP_ATOMIC :GFP_KERNEL ; +if (!ipsec) { + err = -EOPNOTSUPP ; + goto unblock_mode; + } + + gfp = is_acq ?GFP_ATOMIC :GFP_KERNEL ; sa_entry =kzalloc_obj (*sa_entry, gfp); -if (!sa_entry) -return -ENOMEM ; +if (!sa_entry) { + err = -ENOMEM ; + goto unblock_mode; + } sa_entry->x = x; sa_entry->dev = dev; sa_entry->ipsec = ipsec;/* Check if this SA is originated from acquire flow temporary SA */ -if (x->xso.flags &XFRM_DEV_OFFLOAD_FLAG_ACQ ) { +if (is_acq) { x->xso.offload_handle = (unsigned long )sa_entry;return 0 ; }
@@ -814,21 +826,17 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, goto err_xfrm; } - err =mlx5_eswitch_block_mode (mdev, true); -if (err) - goto unblock_ipsec; -if (x->props.mode ==XFRM_MODE_TUNNEL && x->xso.type ==XFRM_DEV_OFFLOAD_PACKET ) { err =mlx5e_ipsec_fs_tunnel_allowed (sa_entry);if (err <0 ) - goto unblock_mode; + goto unblock_ipsec; allow_tunnel_mode = err;if (!allow_tunnel_mode) {NL_SET_ERR_MSG_MOD (extack,"Packet offload tunnel mode is disabled due to encap settings" ); err = -EINVAL ; - goto unblock_mode; + goto unblock_ipsec; } }
@@ -904,13 +912,14 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, unblock_encap:if (allow_tunnel_mode)mlx5_eswitch_unblock_encap (mdev); -unblock_mode: -mlx5_eswitch_unblock_mode (mdev); unblock_ipsec:mlx5_eswitch_unblock_ipsec (mdev); err_xfrm:kfree (sa_entry);NL_SET_ERR_MSG_WEAK_MOD (extack,"Device failed to offload this state" ); +unblock_mode: +if (!is_acq) +mlx5_eswitch_unblock_mode (mdev);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 504/1005 net/mlx5e: Serialize TC and IPsec offload exclusion counters
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit 717dec565a5e7feab544da5aa77db9da71bc93fe ]
The counters enforcing TC and IPsec packet offload mutual exclusion are not consistently serialized. IPsec admission conditionally takes mode_lock for writing, while TC admission holds it only for read. Neither release path takes the lock, and devices without an eswitch cannot rely on it at all.
These are per-core-device counters, separate from the eswitch mode and encapsulation reservations protected by mode_lock. Move them into mdev->offload_block and protect their checks, increments and decrements with a dedicated spinlock that is available even without an eswitch. A spinlock is used because some of these functions are called from atomic context and is a good fit because the critical sections are and will stay really short.
IPsec admission then no longer needs mode_lock to update these counters. Add warnings for unbalanced releases. Keep mlx5_esw_lock() for eswitch operation admission and temporary mode/encapsulation reservations.
This was found by upstream Sashiko during review of [1], and spun-off into a fix from the larger patch.
[1]
https://lore.kernel.org/netdev/[email protected]/
--- .../mellanox/mlx5/core/en_accel/ipsec_fs.c | 43 ++++++------------- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 18 +++++--- .../net/ethernet/mellanox/mlx5/core/main.c | 1 + include/linux/mlx5/driver.h | 8 +++- 4 files changed, 31 insertions(+), 39 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +12 -31
@@ -2585,45 +2585,26 @@ void mlx5e_accel_ipsec_fs_read_stats(struct mlx5e_priv *priv, void *ipsec_stats) } } -#ifdef CONFIG_MLX5_ESWITCH static int mlx5e_ipsec_block_tc_offload (struct mlx5_core_dev *mdev) { -struct mlx5_eswitch *esw = mdev->priv.eswitch; -int err =0 ; - -if (esw) { - err =mlx5_esw_lock (esw); -if (err) -return err; - } - -if (mdev->num_block_ipsec) { - err = -EBUSY ; - goto unlock; - } +int ret =0 ; - mdev->num_block_tc++; - -unlock: -if (esw) -mlx5_esw_unlock (esw); - -return err; -} -#else -static int mlx5e_ipsec_block_tc_offload (struct mlx5_core_dev *mdev) -{ -if (mdev->num_block_ipsec) -return -EBUSY ; +spin_lock_bh (&mdev->offload_block.lock); +if (mdev->offload_block.num_block_ipsec) + ret = -EBUSY ; +else + mdev->offload_block.num_block_tc++; +spin_unlock_bh (&mdev->offload_block.lock); - mdev->num_block_tc++; -return 0 ; +return ret; } -#endif static void mlx5e_ipsec_unblock_tc_offload (struct mlx5_core_dev *mdev) { - mdev->num_block_tc--; +spin_lock_bh (&mdev->offload_block.lock); +if (!WARN_ON_ONCE (!mdev->offload_block.num_block_tc)) + mdev->offload_block.num_block_tc--; +spin_unlock_bh (&mdev->offload_block.lock); }int mlx5e_accel_ipsec_fs_add_rule (struct mlx5e_ipsec_sa_entry *sa_entry)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +12 -6
@@ -4834,16 +4834,19 @@ static bool is_tc_ipsec_order_check_needed(struct net_device *filter, struct mlxstatic int mlx5e_tc_block_ipsec_offload (struct net_device *filter,struct mlx5e_priv *priv) {struct mlx5_core_dev *mdev = priv->mdev; +int ret =0 ;if (!is_tc_ipsec_order_check_needed (filter, priv))return 0 ; -if (mdev->num_block_tc) -return -EBUSY ; - - mdev->num_block_ipsec++; +spin_lock_bh (&mdev->offload_block.lock); +if (mdev->offload_block.num_block_tc) + ret = -EBUSY ; +else + mdev->offload_block.num_block_ipsec++; +spin_unlock_bh (&mdev->offload_block.lock); -return 0 ; +return ret; }static void mlx5e_tc_unblock_ipsec_offload (struct net_device *filter,struct mlx5e_priv *priv)
@@ -4851,7 +4854,10 @@ static void mlx5e_tc_unblock_ipsec_offload(struct net_device *filter, struct mlxif (!is_tc_ipsec_order_check_needed (filter, priv))return ; - priv->mdev->num_block_ipsec--; +spin_lock_bh (&priv->mdev->offload_block.lock); +if (!WARN_ON_ONCE (!priv->mdev->offload_block.num_block_ipsec)) + priv->mdev->offload_block.num_block_ipsec--; +spin_unlock_bh (&priv->mdev->offload_block.lock); } int mlx5e_configure_flower(struct net_device *dev, struct mlx5e_priv *priv,
drivers/net/ethernet/mellanox/mlx5/core/main.c +1 -0
@@ -1810,6 +1810,7 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)lockdep_register_key (&dev->lock_key);mutex_init (&dev->intf_state_mutex);lockdep_set_class (&dev->intf_state_mutex, &dev->lock_key); +spin_lock_init (&dev->offload_block.lock);mutex_init (&dev->mlx5e_res.uplink_netdev_lock);mutex_init (&dev->wc_state_lock);
include/linux/mlx5/driver.h +6 -2
@@ -788,8 +788,12 @@ struct mlx5_core_dev {u32 vsc_addr;struct mlx5_hv_vhca *hv_vhca;struct mlx5_hwmon *hwmon; -u64 num_block_tc; -u64 num_block_ipsec; +struct { +/* Protects the fields below. */ +spinlock_t lock; +u64 num_block_tc; +u64 num_block_ipsec; + } offload_block;#ifdef CONFIG_MLX5_MACSEC struct mlx5_macsec_fs *macsec_fs;/* MACsec notifier chain to sync MACsec core and IB database */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 505/1005 net: Fix memory_allocated leak in __sk_mem_raise_allocated().
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 8012eec76b7e6c0d9fb338fe8e3db6ca1b419da4 ]
__sk_mem_raise_allocated() calls sk_memory_allocated_add() and reuses the return value to check if it was called.
However, sk_memory_allocated_{add,sub}() cache a value in per-cpu counter, sk->sk_prot->per_cpu_fw_alloc, up to sysctl_mem_pcpu_rsv before reflecting it to sk->sk_prot->memory_allocated.
Thus, sk->sk_prot->memory_allocated could have a negative value, and proto_memory_allocated() returns 0 in such a case.
Then, if mem_cgroup_sk_charge() succeeds, sk_prot_mem_limits() checks are bypassed, and if mem_cgroup_sk_charge() fails, sk_memory_allocated_sub() is not called, leaking counters.
Let's use sk->sk_bypass_prot_mem instead of allocated.
--- net/core/sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/sock.c +2 -2
@@ -3357,7 +3357,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) goto suppress_allocation; } -if (!allocated) +if (sk->sk_bypass_prot_mem)return 1 ;/* Under limit. */
@@ -3438,7 +3438,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)trace_sock_exceed_buf_limit (sk, prot, allocated, kind); -if (allocated) +if (!sk->sk_bypass_prot_mem)sk_memory_allocated_sub (sk, amt);if (charged)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 506/1005 fou: gue: check IP version of held packets for direct IP encapsulation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c59f004734a2a7c0e427011db13aca524e781498 ]
For GUE version 0, gue_gro_receive() compares the base GUE header and its optional fields with every held packet. For GUE version 1 (direct IP encapsulation), it skips this comparison and selects the next GRO handler only from the IP version of the incoming packet.
A held version 0 GUE packet from the same outer flow therefore stays eligible. For example, a GUE/IPv4/UDP packet can be aggregated with a direct IPv4/TCP packet, and inet_gro_receive() then parses the held packet's GUE header as an IPv4 header.
Clear same_flow for held packets whose first nibble does not match the incoming IP version. A valid version 0 GUE header always has a first nibble between 0 and 3, so this also separates the two GUE formats. The reverse case is already handled: the version 0 path compares the whole base GUE header, including the version bits.
--- net/ipv4/fou_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/ipv4/fou_core.c +12 -0
@@ -364,6 +364,18 @@ static struct sk_buff *gue_gro_receive(struct sock *sk,default : goto out; } + +/* Match the encapsulation format and IP version. */ +list_for_each_entry (p, head, list) { +const struct iphdr *iph2; + +if (!NAPI_GRO_CB (p)->same_flow) +continue ; + + iph2 = (const struct iphdr *)(p->data + off); +if (iph2->version != ((struct iphdr *)guehdr)->version) +NAPI_GRO_CB (p)->same_flow =0 ; + } goto next_proto;default : goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 507/1005 tcp: Do not allow buggy transitions between ehash and lhash2.
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 8cc3aef0cb198049805ecc061a2cc7b79b0ae43e ]
The following state transitions have long been a playground for syzbot, and recently AI joined in, reporting a lot more bugs.
* listen() + shutdown() + connect()
* connect() + connect(AF_UNSPEC) + listen()
All the fix attempts would add more code to the fast path, which is not worth it.
Instead of playing whack-a-mole with these edge-case bugs, let's disallow these transitions.
Note that unhashed_state is placed in the 4-byte hole after icsk_pmtu_cookie.
$ pahole -C inet_connection_sock vmlinux
struct inet_connection_sock {
...
__u32 icsk_pmtu_cookie; /* 1208 4 */
unsigned char unhashed_state; /* 1212 1 *//* XXX 3 bytes hole, try to pack */
Stable-dep-of: 8c011697f76a ("tcp: do not resurrect a former listener with SO_ATTACH_REUSEPORT_[CE]BPF")
--- include/net/inet_connection_sock.h | 1 + net/ipv4/inet_connection_sock.c | 1 + net/ipv4/inet_hashtables.c | 11 +++++++++++ 3 files changed, 13 insertions(+)
include/net/inet_connection_sock.h +1 -0
@@ -94,6 +94,7 @@ struct inet_connection_sock {u32 icsk_rto_max;__u32 icsk_delack_max;__u32 icsk_pmtu_cookie; +unsigned char unhashed_state;const struct tcp_congestion_ops *icsk_ca_ops;const struct inet_connection_sock_af_ops *icsk_af_ops;const struct tcp_ulp_ops *icsk_ulp_ops;
net/ipv4/inet_connection_sock.c +1 -0
@@ -1262,6 +1262,7 @@ struct sock *inet_csk_clone_lock(const struct sock *sk,memset (&newicsk->icsk_accept_queue,0 ,sizeof (newicsk->icsk_accept_queue)); + newicsk->unhashed_state =0 ;inet_sk_set_state (newsk,TCP_SYN_RECV );inet_clone_ulp (req, newsk, priority);
net/ipv4/inet_hashtables.c +11 -0
@@ -804,6 +804,11 @@ int inet_hash(struct sock *sk)inet_init_ehash_secret ();WARN_ON (!sk_unhashed (sk)); + +if (unlikely (inet_csk (sk)->unhashed_state && +inet_csk (sk)->unhashed_state !=TCP_LISTEN )) +return -EINVAL ; + ilb2 =inet_lhash2_bucket_sk (hashinfo, sk);spin_lock (&ilb2->lock);
@@ -833,6 +838,9 @@ void inet_unhash(struct sock *sk)return ;sock_rps_delete_flow (sk); + +inet_csk (sk)->unhashed_state = sk->sk_state; +if (sk->sk_state ==TCP_LISTEN ) {struct inet_listen_hashbucket *ilb2;
@@ -1059,6 +1067,9 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,int ret, i, low, high;bool local_ports; +if (unlikely (inet_csk (sk)->unhashed_state ==TCP_LISTEN )) +return -EINVAL ; +if (port) {local_bh_disable (); ret = check_established(death_row, sk, port, NULL, false,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 508/1005 tcp: do not resurrect a former listener with SO_ATTACH_REUSEPORT_[CE]BPF
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 8c011697f76abf3b2302718a7a1c50e36d849f28 ]
After listen() + shutdown(), a TCP socket is moved to the closed section of its reuseport group, while TCP_NEW_SYN_RECV requests can still reference it as rsk_listener.
If SO_ATTACH_REUSEPORT_[CE]BPF is then used on this socket, reuseport_attach_prog() calls reuseport_alloc(), which resurrects it into the listening section of a new group, even though the socket is still in TCP_CLOSE.
After close(), the socket stays in that group and the pending requests keep it allocated. When the final ACK arrives, reuseport_migrate_sock() can select this dead socket and inet_csk_clone_lock() clones it. With a ULP like espintcp installed while in TCP_CLOSE, the child inherits icsk_ulp_data and sk_destruct after tcp_cleanup_ulp() cleared icsk_ulp_ops, leading to a use-after-free in espintcp_destruct().
As done in commit 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between ehash and lhash2."), deny this transition instead of adding checks to the fast path.
Only an unhashed former listener is affected. Applications can still attach a reuseport prog to a socket that never listened, or to a listener (including one that called listen() again after shutdown()).
--- net/core/sock_reuseport.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/core/sock_reuseport.c +9 -0
@@ -6,6 +6,7 @@* selecting the socket index from the array of available sockets. */ +#include <net/inet_connection_sock.h> #include <net/ip.h> #include <net/sock_reuseport.h> #include <linux/bpf.h>
@@ -692,6 +693,14 @@ int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog)if (!sk->sk_reuseport)return -EINVAL ; +/* Do not put a shutdown()ed TCP listener back into the +* listening section of a reuseport group while it is in +* TCP_CLOSE: requests can still migrate to it. +*/ +if (sk_is_tcp (sk) && +inet_csk (sk)->unhashed_state ==TCP_LISTEN ) +return -EINVAL ; + err =reuseport_alloc (sk, false);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 509/1005 udp: do not use a cross-family sk_rx_dst in early demux
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 5636e67320563be743d47706ef4914078c27edb2 ]
A dual-stack UDP socket connected to a v4-mapped address can receive both IPv4 packets and IPv6 packets using v4-mapped addresses:ip6_rcv_core() no longer rejects a v4-mapped source since commit dcc32f4f183a ("ipv6: weaken the v4mapped source check"), which kept that check only in tcp_v6_conn_request(). ipv6_portaddr_hash() hashes v4-mapped addresses like IPv4 ones, so both early demux handlers find the socket, and both __udp4_lib_rcv() and __udp6_lib_rcv() store their input dst in the same sk->sk_rx_dst.
udp_v6_early_demux() validates the cached dst with dst_check(), but ipv4_dst_check() ignores the cookie, so an IPv4 dst gets attached to an IPv6 skb. ip6_rcv_finish_core() then skips the route lookup and ip_local_deliver() parses the IPv6 header as an IPv4 one: the IPv6 next header and hop limit are read as a fragment offset, and the IPv4 protocol is taken from a source address byte.
The reverse direction looks possible too: per-cpu dsts of IPv6 routes using nexthop objects have rt->sernum set, and ip6_dst_check() then ignores the cookie, so udp_v4_early_demux() can attach an IPv6 dst to an IPv4 skb.
Kyle Zeng reported that such a packet can reach XFRM input still holding the prefetched, non refcounted, socket set by early demux, which can then outlive its RCU grace period.
Only use the cached dst if its family matches the packet. Otherwise fall back to a regular route lookup.
TCP does not have the same problem: sk_ehashfn() hashes a v4-mapped socket with inet_ehashfn(), while IPv6 lookups use inet6_ehashfn(), so IPv6 packets do not normally find a v4-mapped TCP socket.
--- net/ipv4/udp.c | 5 ++++- net/ipv6/udp.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
net/ipv4/udp.c +4 -1
@@ -2849,8 +2849,11 @@ enum skb_drop_reason udp_v4_early_demux(struct sk_buff *skb) skb->destructor = sock_pfree; dst =rcu_dereference (sk->sk_rx_dst); -if (dst) +/* A dual-stack socket can cache an IPv6 dst. */ +if (dst && dst->ops->family ==AF_INET ) dst =dst_check (dst,0 ); +else + dst =NULL ;if (dst) {u32 itag =0 ;
net/ipv6/udp.c +4 -1
@@ -1255,8 +1255,11 @@ void udp_v6_early_demux(struct sk_buff *skb) skb->destructor = sock_pfree; dst =rcu_dereference (sk->sk_rx_dst); -if (dst) +/* A dual-stack socket can cache an IPv4 dst. */ +if (dst && dst->ops->family ==AF_INET6 ) dst =dst_check (dst, sk->sk_rx_dst_cookie); +else + dst =NULL ;if (dst) {/* set noref for now. * any place which wants to hold dst has to call
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 510/1005 net: gro: compare skb->protocol in gro_list_prepare()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 511582022bfd07475d0daa209e6e6aa5a940740d ]
gro_list_prepare() checks whether a held packet may belong to the same flow as the incoming one by comparing the device, VLAN tag, metadata and the link-layer header, using dev->hard_header_len as its length.
On devices without a link-layer header (hard_header_len == 0), such as L3 GRE tunnels, no compared byte carries the outer protocol:skb->protocol comes from the tunnel header. Packets of different protocols can then stay eligible, and the GRO handler selected from the incoming skb->protocol parses the held packet with the wrong layout.
For example, take an IPv4/UDP packet held by UDP GRO and a VLAN/IPv4/TCP packet received on the same ipgre device. vlan_gro_receive() reads the first four bytes of the held IPv4 header as a VLAN header. With crafted values, the held packet survives up to tcp_gro_receive(), which uses its UDP header as a TCP header. With a short linear part, the FIN/PSH update of the held packet's TCP flags can then write into skb_shared_info.
The VLAN, GRE, IPv4 and IPv6 GRO handlers compare the next-protocol field of their own header, so once the outer protocol matches, the inner layers are checked too. Only the outermost protocol was not compared.
Compare skb->protocol too. On Ethernet devices this is redundant with compare_ether_header(), but it is cheap.
GUE direct IP encapsulation has a similar issue, but there both packets have the same outer protocol, so it is fixed separately in gue_gro_receive().
--- net/core/gro.c | 1 + 1 file changed, 1 insertion(+)
net/core/gro.c +1 -0
@@ -374,6 +374,7 @@ static void gro_list_prepare(const struct list_head *head, } diffs = (unsigned long )p->dev ^ (unsigned long )skb->dev; + diffs |= p->protocol != skb->protocol; diffs |= p->vlan_all ^ skb->vlan_all; diffs |=skb_metadata_differs (p, skb);if (maclen ==ETH_HLEN )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 511/1005 net: stmmac: count XDP_PASS frames in rx_packets on the XSK zero-copy path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anandu Padinhare <[email protected]>
[ Upstream commit 070411c1590c8172eb4d86f045d99c372f22fe23 ]
In the AF_XDP zero-copy RX path, frames that the XDP program passes to the stack are handed over by stmmac_dispatch_skb_zc(). That function increments rx_pkt_n instead of rx_packets since
commit 133466c3bbe1 ("net: stmmac: use per-queue 64 bit statistics where necessary").
stmmac_rx_zc() already adds every processed frame to rx_pkt_n, so each XDP_PASS frame is counted twice there, and rx_packets, which ndo_get_stats64() reports, never counts them: on a zero-copy queue rx_bytes grows with the passed frames while rx_packets stays still.
Count the frame in rx_packets, as the regular RX path and the code before that commit did.
Found while testing AF_XDP zero-copy on an ADSP-SC598 (adi-dwmac, 100 Mbit/s link): rx_pkt_n grew almost twice as fast as the frames the MAC delivered, while "ip -s link" counted almost none.
Tested on that board with a 6.18-based kernel, whose zero-copy RX accounting matches net. An AF_XDP zero-copy socket on queue 0 received frames of one EtherType while UDP traffic was passed to the stack. In a run with 60 s of traffic before the change, rx_pkt_n was 1.88 times the frames that reached the driver (MAC frames minus RX FIFO overflows) and "ip -s link" counted 55 RX packets. In the same test with the change, rx_pkt_n equals the frames that reached the driver and rx_packets equals the frames passed to the stack.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -5522,7 +5522,7 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue,napi_gro_receive (&ch->rxtx_napi, skb);u64_stats_update_begin (&rxq_stats->napi_syncp); -u64_stats_inc (&rxq_stats->napi.rx_pkt_n); +u64_stats_inc (&rxq_stats->napi.rx_packets);u64_stats_add (&rxq_stats->napi.rx_bytes, len);u64_stats_update_end (&rxq_stats->napi_syncp); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 512/1005 ASoC: apple: mca: Fix clock selection for clock consumer FEs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Janne Grunau <[email protected]>
[ Upstream commit d9bcb20e403908415809c37b96db4c9d651298cc ]
In commit 00309bfb1f54 ("ASoC: apple: mca: Support FEs being clock consumers") the syncgen clock selection was misunderstood resulting in selecting a random clock. In the capture on multiple BEs for IV sense data use case the configuration worked partially by sheer luck. On Macbook Pro's with 6 speakers it could result in desync IV sense data triggered likely by sample rate changes.
When the FE is a clock consumer select the clock of first used BE as SYNCGEN_MCLK.
Add function like macros to determine the clock index based on the FE or BE number.
This is functionally equivalent to the state sent in v2 of "ASoC: apple:
mca: support simultaneous I2S capture on the frontend" in [1].
--- sound/soc/apple/mca.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
sound/soc/apple/mca.c +7 -3
@@ -53,6 +53,8 @@#define SYNCGEN_STATUS_EN BIT(0)#define REG_SYNCGEN_MCLK_SEL 0x104#define SYNCGEN_MCLK_SEL GENMASK(3, 0) +#define SYNCGEN_MCLK_FE_CLK (n) ((n) + 1) +#define SYNCGEN_MCLK_BE_CLK (n) ((n) + 7)#define REG_SYNCGEN_HI_PERIOD 0x108#define REG_SYNCGEN_LO_PERIOD 0x10c
@@ -313,7 +315,8 @@ static int mca_fe_enable_clocks(struct mca_cluster *cl)return -EINVAL ; } -writel_relaxed (cl->no +1 , cl->base +REG_SYNCGEN_MCLK_SEL ); +writel_relaxed (SYNCGEN_MCLK_FE_CLK (cl->no), + cl->base +REG_SYNCGEN_MCLK_SEL );mca_modify (cl,REG_SYNCGEN_STATUS ,SYNCGEN_STATUS_EN ,SYNCGEN_STATUS_EN );mca_modify (cl,REG_STATUS ,STATUS_MCLK_EN ,STATUS_MCLK_EN );
@@ -390,7 +393,7 @@ static int mca_fe_prepare(struct snd_pcm_substream *substream,/* Turn on the cluster power domain if not already in use */ if (!cl->syncgen_in_use) { -int port =ffs (mca_fe_get_portmask (substream)); +int port =ffs (mca_fe_get_portmask (substream)) -1 ; cl->pd_link = device_link_add(mca->dev, cl->pd_dev, DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
@@ -401,7 +404,8 @@ static int mca_fe_prepare(struct snd_pcm_substream *substream,return -EINVAL ; } -mca_modify (cl,REG_SYNCGEN_MCLK_SEL ,SYNCGEN_MCLK_SEL ,BIT (port)); +mca_modify (cl,REG_SYNCGEN_MCLK_SEL ,SYNCGEN_MCLK_SEL , +SYNCGEN_MCLK_BE_CLK (port));mca_modify (cl,REG_SYNCGEN_STATUS ,SYNCGEN_STATUS_EN ,SYNCGEN_STATUS_EN ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 513/1005 drm/i915/psr: Flush on cursor update also when not using Selective Fetch
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Högander <[email protected]>
[ Upstream commit 6b3ea5a07eac0514623da3d0709b34c8c70f2827 ]
Currently we are not doing flush on cursor update if Selective Fetch is not in use. This does not cause problems in PSR cases as enabling VBI is triggering PSR exit which triggers sending update to panel. In case of Panel Replay this does not happen. This causes legacy cursor update not working if using Panel Replay without Selective Updates.
Dc3co is currently not enabled. Anyways there is no reason to differentiate calling psr2_dc3co_flush_locked on cursor update depending on selective fetch being enabled. So remove this dependency.
v2:
- Keep DC3CO handling for cursor updates.
--- drivers/gpu/drm/i915/display/intel_psr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/display/intel_psr.c +3 -4
@@ -3717,12 +3717,11 @@ void intel_psr_flush(struct intel_display *display,if (intel_dp->psr.pause_counter) goto unlock; -if (origin ==ORIGIN_FLIP || - (origin ==ORIGIN_CURSOR_UPDATE && - !intel_dp->psr.psr2_sel_fetch_enabled)) { +if (origin ==ORIGIN_FLIP || origin ==ORIGIN_CURSOR_UPDATE )psr2_dc3co_flush_locked (intel_dp, frontbuffer_bits); + +if (origin ==ORIGIN_FLIP ) goto unlock; - }if (pipe_frontbuffer_bits ==0 ) goto unlock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 514/1005 udp: check frag_list IP family before using skb_segment_list()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 22b7cb932c6a0f7566d41072be6956cb6c8af4e1 ]
UDP fraglist GRO uses SKB_GSO_UDP_L4 for both IPv4 and IPv6.
__udp_gso_segment() reuses the frag_list skbs when the geometry of the head skb was not modified. skb_segment_list() keeps the network header of each frag_list skb as it was at GRO time and only adjusts the transport header offset.
Nothing guarantees that the head skb still has the IP family of the frag_list skbs: helpers like skb_mpls_pop() let the caller choose the new protocol. In that case __udpv6_gso_segment_list_csum() handles the 20 byte IPv4 header of each frag_list skb as a struct ipv6hdr, and can write IPv6 addresses beyond its linear part.
Check the IP version of the first frag_list skb. All skbs in the list belong to the same flow, so they share the same IP family. Use the skb_segment() fallback on a mismatch. Regular fraglist GRO traffic keeps the fast path.
--- net/ipv4/udp_offload.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/ipv4/udp_offload.c +7 -2
@@ -514,9 +514,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, }if (skb_shinfo (gso_skb)->gso_type &SKB_GSO_FRAGLIST ) { -/* Detect modified geometry and pass those to skb_segment. */ +/* Detect modified geometry and pass those to skb_segment. +* SKB_GSO_UDP_L4 is used by both IPv4 and IPv6: also make sure +* the frag_list skbs still have the IP family we segment for, +* as their network headers are not rebuilt. +*/ if ((skb_pagelen (gso_skb) -sizeof (*uh) ==skb_shinfo (gso_skb)->gso_size) && - !(skb_shinfo (gso_skb)->gso_type &SKB_GSO_DODGY )) + !(skb_shinfo (gso_skb)->gso_type &SKB_GSO_DODGY ) && +ip_hdr (skb_shinfo (gso_skb)->frag_list)->version == (is_ipv6 ?6 :4 ))return __udp_gso_segment_list (gso_skb, features, is_ipv6); ret =__skb_linearize (gso_skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/1005 drm/bridge: sii902x: validate I2S data lane values
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 444b7116e7ef1fdb5f7db3bc1f74b20098d062d4 ]
The sil,i2s-data-lanes property reader bounds the number of entries, but does not bound each entry's value. Those values index the four-entry i2s_lane_id table when the audio FIFO sequence is built.
Reject unsupported lane values before indexing that table. Report the property name and invalid value with dev_err_probe() so the diagnostic identifies the faulty configuration.
The issue was found by our static-analysis tool.
--- drivers/gpu/drm/bridge/sii902x.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/sii902x.c +7 -1
@@ -890,9 +890,15 @@ static int sii902x_audio_codec_init(struct sii902x *sii902x, } codec_data.max_i2s_channels =2 * num_lanes; -for (i =0 ; i < num_lanes; i++) +for (i =0 ; i < num_lanes; i++) { +if (lanes[i] >=ARRAY_SIZE (i2s_lane_id)) +return dev_err_probe (dev, -EINVAL , +"invalid sil,i2s-data-lanes value %u\n" , + lanes[i]); + sii902x->audio.i2s_fifo_sequence[i] |= audio_fifo_id[i] | i2s_lane_id[lanes[i]] |SII902X_TPI_I2S_FIFO_ENABLE ; + } sii902x->audio.mclk =devm_clk_get_optional (dev,"mclk" );if (IS_ERR (sii902x->audio.mclk)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 516/1005 xen/grant-table: annotate on-stack work in gnttab_unmap_refs_sync()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kavitha Daula <[email protected]>
[ Upstream commit 704f812cdab8bbf30987653c1c76c0d2c1e135e7 ]
Both callers of gnttab_unmap_refs_sync(), free_persistent_gnts() and xen_blkbk_unmap_purged_grants() in blkback, keep their struct gntab_unmap_queue_data on the stack. gnttab_unmap_refs_async() sets up the delayed work inside it with INIT_DELAYED_WORK(), so with CONFIG_DEBUG_OBJECTS_WORK and CONFIG_DEBUG_OBJECTS_TIMERS every persistent grant teardown warns twice, once for the work and once for its timer:
[ 104.366085] ODEBUG: object ffffc9004020fad8 is on stack ffffc9004020c000, but NOT annotated. [ 104.371551] WARNING: CPU: 1 PID: 48 at lib/debugobjects.c:672 lookup_object_or_alloc.part.0+0x12b/0x1f0 Call Trace: <TASK> __debug_object_init+0xfe/0x1a0 debug_object_init+0x38/0x50 __init_work+0x28/0x30 gnttab_unmap_refs_async+0x18/0xa0 gnttab_unmap_refs_sync+0x61/0x90 free_persistent_gnts+0x179/0x280 xen_blkbk_free_caches+0x16/0x30 xen_blkif_disconnect+0xfa/0x2d0 frontend_changed+0x90/0x680 xenbus_otherend_changed+0x80/0xb0 frontend_changed+0x14/0x20 xenwatch_thread+0x96/0x1a0 kthread+0x11d/0x250 ret_from_fork+0x29f/0x2d0 ret_from_fork_asm+0x1a/0x30 </TASK>
gnttab_unmap_refs_sync() waits for the unmap to complete before it returns, so the work never outlives the caller's frame. Initialise it with INIT_DELAYED_WORK_ONSTACK() when the item is on the stack and destroy it before returning. The function is exported, so an item that is not on the stack keeps INIT_DELAYED_WORK().
Message-ID: <[email protected]>
--- drivers/xen/grant-table.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/xen/grant-table.c +11 -1
@@ -38,6 +38,7 @@#include <linux/sched.h> #include <linux/mm.h> #include <linux/slab.h> +#include <linux/sched/task_stack.h> #include <linux/vmalloc.h> #include <linux/uaccess.h> #include <linux/io.h>
@@ -1361,12 +1362,21 @@ static void unmap_refs_callback(int result,int gnttab_unmap_refs_sync (struct gntab_unmap_queue_data *item) {struct unmap_refs_callback_data data; +bool on_stack =object_is_on_stack (item);init_completion (&data.completion); item->data = &data; item->done = &unmap_refs_callback; -gnttab_unmap_refs_async (item); +/* blkback keeps @item, and so its retry work, on the stack. */ +if (on_stack) +INIT_DELAYED_WORK_ONSTACK (&item->gnttab_work, gnttab_unmap_work); +else +INIT_DELAYED_WORK (&item->gnttab_work, gnttab_unmap_work); + item->age =0 ; +__gnttab_unmap_refs_async (item);wait_for_completion (&data.completion); +if (on_stack) +destroy_delayed_work_on_stack (&item->gnttab_work);return data.result; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 517/1005 ASoC: max98090: keep the MIC boost across mic input power-up
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: LiangCheng Wang <[email protected]>
[ Upstream commit 58d51fa6ff1d21e79c3c340bfb3155dfa3025ca3 ]
PA1EN/PA2EN select both the MIC1/MIC2 preamp enable and its gain (0 = off, 1 = 0 dB, 2 = +20 dB, 3 = +30 dB). "MICn Boost Volume" keeps the selected gain in max98090->pa1en/pa2en while the input is off, and max98090_micinput_event() writes it to the field when the "MICn Input" widget powers up.
The event handler also reads the field back to keep the stored gain in sync ("Update for volatile"), but it does so on POST_PMU and POST_PMD. The widget drives PA1EN/PA2EN as a single enable bit, the low bit of the field, so at both points DAPM has just rewritten it:
- POST_PMU: DAPM has set the field to 1, so the read-back stores 0 dB and the handler then restores 0 dB.
- POST_PMD: DAPM has cleared the low bit, so a +30 dB (3) gain reads
back as +20 dB (2).
As a result every capture starts at 0 dB: a boost set while the input is powered down, e.g. restored by alsactl or an audio HAL at boot, never takes effect, and one changed during capture is lost at the next power-up.
Read the field back on PRE_PMD instead, while it still holds the active gain, and only restore the stored gain on POST_PMU.
Tested on i.MX95 with a MAX98090 headset mic on MIC1, running NXP's 6.18.38 vendor kernel (max98090_micinput_event() is the same as in mainline): with MIC1 Boost Volume set to 2 (+30 dB) before capture, register 0x10 reads 0x20 (0 dB) during capture without this change and 0x60 (+30 dB) with it, and a boost changed during capture is kept for the next capture.
--- sound/soc/codecs/max98090.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
sound/soc/codecs/max98090.c +12 -10
@@ -743,14 +743,6 @@ static int max98090_micinput_event(struct snd_soc_dapm_widget *w,else val = (val &M98090_MIC_PA2EN_MASK ) >>M98090_MIC_PA2EN_SHIFT ; -if (val >=1 ) { -if (w->reg ==M98090_REG_MIC1_INPUT_LEVEL ) { - max98090->pa1en = val -1 ;/* Update for volatile */ - }else { - max98090->pa2en = val -1 ;/* Update for volatile */ - } - } -switch (event) {case SND_SOC_DAPM_POST_PMU :/* If turning on, set to most recently selected volume */
@@ -759,6 +751,14 @@ static int max98090_micinput_event(struct snd_soc_dapm_widget *w,else val = max98090->pa2en +1 ;break ; +case SND_SOC_DAPM_PRE_PMD : +if (val >=1 ) { +if (w->reg ==M98090_REG_MIC1_INPUT_LEVEL ) + max98090->pa1en = val -1 ; +else + max98090->pa2en = val -1 ; + } +return 0 ;case SND_SOC_DAPM_POST_PMD :/* If turning off, turn off */ val =0 ;
@@ -1121,11 +1121,13 @@ static const struct snd_soc_dapm_widget max98090_dapm_widgets[] = {SND_SOC_DAPM_PGA_E ("MIC1 Input" ,M98090_REG_MIC1_INPUT_LEVEL ,M98090_MIC_PA1EN_SHIFT ,0 ,NULL ,0 , max98090_micinput_event, -SND_SOC_DAPM_POST_PMU |SND_SOC_DAPM_POST_PMD ), +SND_SOC_DAPM_POST_PMU |SND_SOC_DAPM_PRE_PMD | +SND_SOC_DAPM_POST_PMD ),SND_SOC_DAPM_PGA_E ("MIC2 Input" ,M98090_REG_MIC2_INPUT_LEVEL ,M98090_MIC_PA2EN_SHIFT ,0 ,NULL ,0 , max98090_micinput_event, -SND_SOC_DAPM_POST_PMU |SND_SOC_DAPM_POST_PMD ), +SND_SOC_DAPM_POST_PMU |SND_SOC_DAPM_PRE_PMD | +SND_SOC_DAPM_POST_PMD ), SND_SOC_DAPM_MIXER("LINEA Mixer", SND_SOC_NOPM, 0, 0, &max98090_linea_mixer_controls[0],
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 518/1005 erofs: reset buf->off in erofs_init_metabuf()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 8b4ddd28ec5bdec14cefc57f8bf792cb4764d724 ]
erofs_init_metabuf() sets buf->off only for the block device and keeps the old value when it switches to the metabox or the managed cache. erofs_bread() adds buf->off to every offset, so the result depends on how the buffer was last initialized.
getxattr and listxattr init the same buffer twice, for the inline and the shared xattrs, with in_metabox taken from different places. On a block device mount with fsoffset=, if the inode is outside the metabox and COMPAT_SHARED_EA_IN_METABOX is set, the shared xattrs are read at their metabox offset plus fsoffset. The same image mounted file-backed returns the right values.
Reset buf->off on every init.
--- fs/erofs/data.c | 1 + 1 file changed, 1 insertion(+)
fs/erofs/data.c +1 -0
@@ -60,6 +60,7 @@ int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb,struct erofs_sb_info *sbi =EROFS_SB (sb); buf->mc = false; + buf->off =0 ;if (in_metabox) {if (unlikely (!sbi->metabox_inode))return -EFSCORRUPTED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 519/1005 tcp: Clear DEFER_CONNECT before tcp_connect() and in tcp_abort().
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 93723db43e5185404e7d637357d07ffbb38e8b65 ]
When TFO is enabled, tcp_v[46]_connect() sets sk->sk_state to TCP_SYN_SENT and puts the socket into ehash without calling tcp_connect().
Then, tcp_fastopen_defer_connect() sets DEFER_CONNECT, and the first write()/sendmsg() will call tcp_connect() and send SYN with data if possible.
If tcp_abort() kills a socket before the first write()/sendmsg(), the unhashed socket can still call it and send SYN in TCP_CLOSE.
Also, DEFER_CONNECT is cleared after __inet_stream_connect().
So, blocking write()/sendmsg() can release lock_sock() in inet_wait_for_connect() while DEFER_CONNECT is set, and tcp_poll() could set EPOLLOUT even after SYN is sent.
Let's clear DEFER_CONNECT in tcp_abort() and right before tcp_connect() in tcp_sendmsg_fastopen().
Note that the last argument of __inet_stream_connect() is changed from is_sendmsg to defer_connect as DEFER_CONNECT is already cleared when __inet_stream_connect() is called.
This change is also needed for the next patch.
--- include/net/inet_common.h | 2 +- net/ipv4/af_inet.c | 10 ++++++---- net/ipv4/tcp.c | 9 +++++++-- net/mptcp/protocol.c | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-)
include/net/inet_common.h +1 -1
@@ -25,7 +25,7 @@ int inet_release(struct socket *sock);int inet_stream_connect (struct socket *sock,struct sockaddr_unsized *uaddr,int addr_len,int flags);int __inet_stream_connect (struct socket *sock,struct sockaddr_unsized *uaddr, -int addr_len,int flags,int is_sendmsg); +int addr_len,int flags,bool defer_connect);int inet_dgram_connect (struct socket *sock,struct sockaddr_unsized *uaddr,int addr_len,int flags); int inet_accept(struct socket *sock, struct socket *newsock,
net/ipv4/af_inet.c +6 -4
@@ -629,7 +629,7 @@ static long inet_wait_for_connect(struct sock *sk, long timeo, int writebias)* TCP 'magic' in here. */ int __inet_stream_connect (struct socket *sock,struct sockaddr_unsized *uaddr, -int addr_len,int flags,int is_sendmsg) +int addr_len,int flags,bool defer_connect) {struct sock *sk = sock->sk;int err;
@@ -664,8 +664,10 @@ int __inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr, err = -EISCONN ; goto out;case SS_CONNECTING : -if (inet_test_bit (DEFER_CONNECT , sk)) - err = is_sendmsg ? -EINPROGRESS : -EISCONN ; +if (defer_connect) + err = -EINPROGRESS ; +else if (inet_test_bit (DEFER_CONNECT , sk)) + err = -EISCONN ;else err = -EALREADY ;/* Fall out of switch with err, set for this state */
@@ -752,7 +754,7 @@ int inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr,int err;lock_sock (sock->sk); - err =__inet_stream_connect (sock, uaddr, addr_len, flags,0 ); + err =__inet_stream_connect (sock, uaddr, addr_len, flags, false);release_sock (sock->sk);return err; }
net/ipv4/tcp.c +7 -2
@@ -1054,6 +1054,7 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied,struct tcp_sock *tp =tcp_sk (sk);struct inet_sock *inet =inet_sk (sk);struct sockaddr *uaddr = msg->msg_name; +bool defer_connect = false;int err, flags; if (!(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) &
@@ -1073,6 +1074,9 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, tp->fastopen_req->uarg = uarg;if (inet_test_bit (DEFER_CONNECT , sk)) { +inet_clear_bit (DEFER_CONNECT , sk); + defer_connect = true; + err =tcp_connect (sk);/* Same failure procedure as in tcp_v4/6_connect */ if (err) {
@@ -1083,14 +1087,13 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, } flags = (msg->msg_flags &MSG_DONTWAIT ) ?O_NONBLOCK :0 ; err =__inet_stream_connect (sk->sk_socket, (struct sockaddr_unsized *)uaddr, - msg->msg_namelen, flags,1 ); + msg->msg_namelen, flags, defer_connect);/* fastopen_req could already be freed in __inet_stream_connect * if the connection times out or gets rst */ if (tp->fastopen_req) { *copied = tp->fastopen_req->copied;tcp_free_fastopen_req (tp); -inet_clear_bit (DEFER_CONNECT , sk); }return err; }
@@ -5151,6 +5154,8 @@ int tcp_abort(struct sock *sk, int err)/* Don't race with userspace socket closes such as tcp_close. */ lock_sock (sk); +inet_clear_bit (DEFER_CONNECT , sk); +/* Avoid closing the same socket twice. */ if (sk->sk_state ==TCP_CLOSE ) {if (!has_current_bpf_ctx ())
net/mptcp/protocol.c +3 -2
@@ -1920,10 +1920,12 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, msg->msg_flags = saved_flags;release_sock (ssk); +inet_clear_bit (DEFER_CONNECT , sk); +/* do the blocking bits of inet_stream_connect outside the ssk socket lock */ if (ret == -EINPROGRESS && !(msg->msg_flags &MSG_DONTWAIT )) { ret =__inet_stream_connect (sk->sk_socket, msg->msg_name, - msg->msg_namelen, msg->msg_flags,1 ); + msg->msg_namelen, msg->msg_flags, true);/* Keep the same behaviour of plain TCP: zero the copied bytes in * case of any error, except timeout or signal
@@ -1941,7 +1943,6 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, sk->sk_socket->state =SS_UNCONNECTED ; } } -inet_clear_bit (DEFER_CONNECT , sk);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 520/1005 tcp: Drop any segments if DEFER_CONNECT is set.
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 44809e49177992b15708a150437d9aebc5beea9c ]
TCP Fast Open lets a client send data in its SYN. With TCP_FASTOPEN_CONNECT and a cached Fast Open cookie, which the server sent in the SYN-ACK of an earlier connection, the connection is set up in two steps:
- connect() sends nothing, so that the SYN can carry the data of the first write(). It only sets DEFER_CONNECT and inserts the socket into the hash table in SYN_SENT.
- The first write() calls tcp_connect(), which runs tcp_connect_init() and sends the SYN.
A socket must not accept any segment before it has sent its SYN. But nothing on the receive path checks DEFER_CONNECT. So until the write(), the half-initialised socket processes segments like any socket in SYN_SENT, and a forged SYN is accepted.
Similarly, ICMP with seq matching ISN is accepted in the state. Before commit 57889a8f6d49 ("tcp: initialize send sequence numbers before deferring TFO"), even seq 0 message was accepted.
Drop any segments if DEFER_CONNECT is set.
--- net/ipv4/tcp_input.c | 9 +++++++++ net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +9 -0
@@ -7236,6 +7236,15 @@ tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) goto discard;case TCP_SYN_SENT : +/* We sent nothing yet, so no segment belongs to this connection. +* Send no RST: it would be built from this socket, whose TCP-AO +* keys are not set up either. +*/ +if (unlikely (inet_test_bit (DEFER_CONNECT , sk))) { +SKB_DR_SET (reason,NOT_SPECIFIED ); + goto discard; + } + tp->rx_opt.saw_tstamp =0 ;tcp_mstamp_refresh (tp); queued =tcp_rcv_synsent_state_process (sk, skb, th);
net/ipv4/tcp_ipv4.c +1 -1
@@ -541,7 +541,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)if (!(type ==ICMP_DEST_UNREACH && code ==ICMP_FRAG_NEEDED ))__NET_INC_STATS (net,LINUX_MIB_LOCKDROPPEDICMPS ); } -if (sk->sk_state ==TCP_CLOSE ) +if (sk->sk_state ==TCP_CLOSE ||inet_test_bit (DEFER_CONNECT , sk)) goto out;if (static_branch_unlikely (&ip4_min_ttl)) {
net/ipv6/tcp_ipv6.c +1 -1
@@ -449,7 +449,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,if (sock_owned_by_user (sk) && type !=ICMPV6_PKT_TOOBIG )__NET_INC_STATS (net,LINUX_MIB_LOCKDROPPEDICMPS ); -if (sk->sk_state ==TCP_CLOSE ) +if (sk->sk_state ==TCP_CLOSE ||inet_test_bit (DEFER_CONNECT , sk)) goto out;if (static_branch_unlikely (&ip6_min_hopcount)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 521/1005 amt: tear down every amt device on an unregistering lower
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Omar Ramadan <[email protected]>
[ Upstream commit 7262e999ebec0a10ecc97ba4739f12255b7c6da8 ]
amt_device_event() acts only on the amt device that amt_lookup_upper_dev() returns, which is the first amt device bound to the event's lower. Several amt devices can share one lower, for example two gateways.
On NETDEV_UNREGISTER, only the first device is unlinked and unregistered. The others stay upper-linked to the lower, and unregister_netdevice_many_notify() warns, because the notifier chain must detach every upper device. They also still hold a reference on the lower, so each is torn down only when netdev_wait_allrefs_any(), called from netdev_run_todo(), rebroadcasts NETDEV_UNREGISTER. By then the lower's sysfs directory is gone, so unlinking it trips a kernfs WARN, and unregistering it from inside the rebroadcast trips the WARN in __rtnl_unlock(). On NETDEV_CHANGEMTU, only the first device is resized.
Walk every amt device in the lower's netns and act on each one bound to the lower. On NETDEV_UNREGISTER, queue them all and unregister them in one batch. amt_dellink() unlinks each device but leaves it on the netns device list until unregister_netdevice_many(), so the walk stays valid under RTNL.
To reproduce:
ip link add lower0 type dummy
ip link add amtg1 type amt mode gateway local 192.0.2.1 \
discovery 192.0.2.2 dev lower0
ip link add amtg2 type amt mode gateway local 192.0.2.1 \
discovery 192.0.2.2 dev lower0
ip link del lower0Without this patch, the last command logs:
WARNING: net/core/dev.c:12773 at unregister_netdevice_many_notify+0x13e5/0x1940, CPU#3: ip/216 kernfs: can not remove 'upper_amtg2', no directory WARNING: fs/kernfs/dir.c:1784 at kernfs_remove_by_name_ns+0xc9/0xd0, CPU#0: ip/216 WARNING: net/core/rtnetlink.c:141 at __rtnl_unlock+0xb2/0xf0, CPU#0: ip/216 WARNING: net/core/rtnetlink.c:141 at __rtnl_unlock+0xb2/0xf0, CPU#0: ip/216
With it, the commands log nothing and remove both amt devices, and tools/testing/selftests/net/amt.sh passes on a KASAN and lockdep kernel.
Found by a selftest for our upcoming AMT offload RFC, which deletes a lower carrying two amt gateways, on our 6.18-based driver. The commands above reproduce it on net.
--- drivers/net/amt.c | 56 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 32 deletions(-)
drivers/net/amt.c +24 -32
@@ -3394,22 +3394,6 @@ static struct rtnl_link_ops amt_link_ops __read_mostly = { .fill_info = amt_fill_info, }; -static struct net_device *amt_lookup_upper_dev (struct net_device *dev) -{ -struct net_device *upper_dev; -struct amt_dev *amt; - -for_each_netdev (dev_net (dev), upper_dev) { -if (netif_is_amt (upper_dev)) { - amt =netdev_priv (upper_dev); -if (amt->stream_dev == dev) -return upper_dev; - } - } - -return NULL ; -} -static int amt_device_event (struct notifier_block *unused,unsigned long event,void *ptr) {
@@ -3419,26 +3403,34 @@ static int amt_device_event(struct notifier_block *unused,LIST_HEAD (list);int new_mtu; - upper_dev =amt_lookup_upper_dev (dev); -if (!upper_dev) -return NOTIFY_DONE ; - amt =netdev_priv (upper_dev); +/* amt_dellink() leaves each device on the netns device list until +* unregister_netdevice_many(), so the walk stays valid. +*/ +for_each_netdev (dev_net (dev), upper_dev) { +if (!netif_is_amt (upper_dev)) +continue ; + amt =netdev_priv (upper_dev); +if (amt->stream_dev != dev) +continue ; -switch (event) { -case NETDEV_UNREGISTER : -amt_dellink (amt->dev, &list); -unregister_netdevice_many (&list); -break ; -case NETDEV_CHANGEMTU : -if (amt->mode ==AMT_MODE_RELAY ) - new_mtu = dev->mtu -AMT_RELAY_HLEN ; -else - new_mtu = dev->mtu -AMT_GW_HLEN ; +switch (event) { +case NETDEV_UNREGISTER : +amt_dellink (amt->dev, &list); +break ; +case NETDEV_CHANGEMTU : +if (amt->mode ==AMT_MODE_RELAY ) + new_mtu = dev->mtu -AMT_RELAY_HLEN ; +else + new_mtu = dev->mtu -AMT_GW_HLEN ; -dev_set_mtu (amt->dev, new_mtu); -break ; +dev_set_mtu (amt->dev, new_mtu); +break ; + } } +if (event ==NETDEV_UNREGISTER ) +unregister_netdevice_many (&list); +return NOTIFY_DONE ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 522/1005 net: ena: Keep the RX buffer mapped if skb allocation fails
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 3e8e22a1007a6337ba2400b3ea87077947005c20 ]
We are seeing the following issue in production on arm64 EC2 hosts (m8g.metal-24xl, 64K pages, SMMUv3 in strict mode, 6.18 based kernel). Right after a global OOM, the SMMU reports F_TRANSLATION write faults from the ENA device, followed by a burst of:
WARNING: CPU: 48 PID: 1656834 at drivers/iommu/dma-iommu.c:1242 iommu_dma_unmap_phys+0xf4/0x108 Call trace: iommu_dma_unmap_phys+0xf4/0x108 (P) dma_unmap_phys+0x194/0x2a8 dma_unmap_page_attrs+0x1c/0x38 ena_io_poll+0x7bc/0x1790 [ena] __napi_poll+0x54/0x220 net_rx_action+0x250/0x520
ena_rx_skb() unmaps the RX buffer, or takes an extra page reference to reuse it, before napi_build_skb() allocates the skb. If the allocation fails, it returns NULL with rx_info->page still set. ena_clean_rx_irq() then puts the req_id back on the free list, and ena_alloc_rx_buffer() treats the buffer as still mapped and posts its old DMA address to the device again.
With the IOMMU in strict mode, the device then writes to an unmapped IOVA, and the next completion of that buffer unmaps it a second time. If the IOVA was handed to a new mapping in between, the device can write into that buffer instead. On the reuse path, the extra page reference is never dropped.
Allocate the skb before touching rx_info, so that a failed allocation leaves the buffer mapped and unchanged for the refill.
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +4 -4
@@ -1009,6 +1009,10 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, buf_len =SKB_DATA_ALIGN (len + buf_offset + tailroom); + skb =ena_alloc_skb (rx_ring, buf_addr, buf_len); +if (unlikely (!skb)) +return NULL ; +/* If XDP isn't loaded try to reuse part of the RX buffer */ reuse_rx_buf_page = !is_xdp_loaded &&ena_try_rx_buf_page_reuse (rx_info, buf_len, len, pkt_offset);
@@ -1016,10 +1020,6 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,if (!reuse_rx_buf_page)ena_unmap_rx_buff_attrs (rx_ring, rx_info,DMA_ATTR_SKIP_CPU_SYNC ); - skb =ena_alloc_skb (rx_ring, buf_addr, buf_len); -if (unlikely (!skb)) -return NULL ; -/* Populate skb's linear part */ skb_reserve (skb, buf_offset);skb_put (skb, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 523/1005 net: ena: avoid RX copybreak for multi-descriptor packets
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit f3c790c34d228d46c4a05fe5d001d1bbea444e2b ]
ena_rx_skb() selects the copybreak path based on the first RX descriptor's length without checking the number of descriptors. When a packet spans multiple descriptors, this copies only the first buffer into the skb and fails to recycle the remaining request IDs, while RX cleanup advances by the full descriptor count.
Restrict copybreak to single-descriptor packets and apply the same restriction to the rx_copybreak_pkt statistic. Multi-descriptor packets then use the existing fragment-processing path.
Discovered by comparing the in-tree ENA driver with Amazon's standalone ENA driver.
Compiled with W=1 under x86_64 defconfig.
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +3 -2
@@ -986,7 +986,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, page_offset = rx_info->page_offset; buf_addr =page_address (rx_info->page) + page_offset; -if (len <= rx_ring->rx_copybreak) { +if (len <= rx_ring->rx_copybreak &&likely (descs ==1 )) { skb =ena_alloc_skb (rx_ring,NULL , len);if (unlikely (!skb))return NULL ;
@@ -1293,7 +1293,8 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,skb_record_rx_queue (skb, rx_ring->qid); -if (rx_ring->ena_bufs[0 ].len <= rx_ring->rx_copybreak) +if (rx_ring->ena_bufs[0 ].len <= rx_ring->rx_copybreak && + ena_rx_ctx.descs ==1 ) rx_copybreak_pkt++; total_len += skb->len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 524/1005 tun: disallow setting IEEE 802.15.4 and 6LoWPAN link types via TUNSETLINK
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kalpesh Solanki <[email protected]>
[ Upstream commit 968f2b94a5964b75d9c0da84523e42530c1891f0 ]
A userspace application can set the link type of a TUN/TAP interface to ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR, or ARPHRD_6LOWPAN via ioctl(fd, TUNSETLINK, arg) because tun_get_addr_len() explicitly recognized these types.
However, TUN devices cannot function as genuine IEEE 802.15.4 or 6LoWPAN interfaces:
1. They lack wpan_phy, channels, PAN IDs, and MLME operations, and tun never initializes dev->ieee802154_ptr or dev->ml_priv. When an unprivileged user creates a TUN interface in a user+net namespace, changes its link type to ARPHRD_IEEE802154, and issues a netlink dump request (such as IEEE802154_LLSEC_LIST_KEY), ieee802154_llsec_dump_table() unconditionally dereferences dev->ieee802154_ptr / ieee802154_mlme_ops(dev), triggering a supervisor null-pointer dereference / general protection fault. Similar dereferences occur across net/ieee802154/nl-phy.c (ieee802154_del_iface) and net/ieee802154/socket.c.
2. Similarly, the 6LoWPAN subsystem assumes via lowpan_dev(dev) that netdev_priv(dev) is struct lowpan_dev. On a TUN device, netdev_priv(dev) is struct tun_struct. On netdev events (such as NETDEV_DOWN in net/6lowpan/core.c:lowpan_device_event), it clears bits in lowpan_dev(dev)->ctx.table flags, which corrupts private memory inside tun_struct.
Rather than scattering checks across subsystems, fix the issue at the
source: disallow setting ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR, and ARPHRD_6LOWPAN via TUNSETLINK by returning -EINVAL. Cast arg to unsigned short in the comparison to prevent upper-bit truncation bypasses (e.g. arg = ARPHRD_IEEE802154 | 0x10000).
--- drivers/net/tun.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/tun.c +4 -0
@@ -3371,6 +3371,10 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,netif_info (tun, drv, tun->dev,"Linktype set failed because interface is up\n" ); ret = -EBUSY ; + }else if ((unsigned short )arg ==ARPHRD_IEEE802154 || + (unsigned short )arg ==ARPHRD_IEEE802154_MONITOR || + (unsigned short )arg ==ARPHRD_6LOWPAN ) { + ret = -EINVAL ; }else { ret =call_netdevice_notifiers (NETDEV_PRE_TYPE_CHANGE , tun->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 525/1005 tls: fix async encryption race on weakly ordered architectures
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ofri Zangi <[email protected]>
[ Upstream commit a2fd526d644233d6a892c28173f07c61e21e4c93 ]
With async encryption, a record can be transmitted without its TLS header on weakly ordered architectures such as arm64, because the consumer may observe rec->tx_ready set while still seeing the old scatterlist entry.
tls_encrypt_done() restores the TLS header in the scatterlist entry (sge->offset -= prot->prepend_size, sge->length += prot->prepend_size) and then publishes the record with smp_store_mb(rec->tx_ready, true). On another CPU, tls_tx_records() checks rec->tx_ready with READ_ONCE() and then reads the entry in tls_push_sg().
Nothing orders these accesses. The barrier in smp_store_mb() comes after the tx_ready store, so it does not order the earlier scatterlist update before it. On the reader side, READ_ONCE() does not order the later loads of sge->offset and sge->length. The reader can therefore see tx_ready set together with the old offset and length, and pushes the record without its header.
Publish tx_ready with smp_store_release() in tls_encrypt_done() and read it with smp_load_acquire() in tls_tx_records(), so that observing tx_ready guarantees the restored scatterlist entry is visible. Keep the full barrier that smp_store_mb() provided as an explicit smp_mb(), as it is still needed to order the tx_ready store before the tx_list head check.
The issue was discovered during development on an arm64 system. A curl download test over kTLS failed with:
curl: (56) OpenSSL SSL_read: error:0A00010B:SSL routines::wrong version number, errno 0
--- net/tls/tls_sw.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
net/tls/tls_sw.c +10 -3
@@ -436,7 +436,8 @@ int tls_tx_records(struct sock *sk, int flags)/* Tx all ready records */ list_for_each_entry_safe (rec, tmp, &ctx->tx_list, list) { -if (READ_ONCE (rec->tx_ready)) { +/* Pairs with smp_store_release() in tls_encrypt_done() */ +if (smp_load_acquire (&rec->tx_ready)) {if (flags ==-1 ) tx_flags = rec->tx_flags;else
@@ -504,8 +505,14 @@ static void tls_encrypt_done(void *data, int err)if (rec) {struct tls_rec *first_rec; -/* Mark the record as ready for transmission */ -smp_store_mb (rec->tx_ready, true); +/* Mark the record as ready for transmission. Pairs with +* smp_load_acquire() in tls_tx_records(): the sge +* offset/length update above must be visible before tx_ready. +*/ +smp_store_release (&rec->tx_ready, true); + +/* Order the tx_ready store before the tx_list head check */ +smp_mb ();/* If received record is at head of tx_list, schedule tx */ first_rec = list_first_entry(&ctx->tx_list,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 526/1005 net/mlx5: HWS, fix flow meter release on FTE update
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandre Cassen <[email protected]>
[ Upstream commit 145480b28ca82e9fae789427cc4569e596515a32 ]
HWS has no duplicate match. When a flower filter is replaced in place, its new rule waits as the pending duplicate of the old FTE. Once the old rule goes, switch_to_pending_act_dests() copies the pending actions over the FTE before update_fte() releases the actions of the old rule. An HWS rule reads the base id of its meter action through a pointer to the exe_aso of the FTE. That release takes the meter action of the new rule instead.
When the two meters sit in different ASO objects, the old meter action leaks. It keeps its ASO object referenced. The firmware then fails to destroy that object and to free the PD of the meters, and its STC is still in the pool when the context closes. The new meter action is destroyed one release early, while a rule still points to it, and the last release underflows its refcount:
mlx5_core 0000:b1:00.1: mlx5_cmd_out_err:822:(pid 2641): DESTROY_GENERAL_OBJECT(0xa03) op_mod(0x24) failed, status bad resource(0x5), syndrome (0xeeda5c), err(-22)
refcount_t: underflow; use-after-free.
WARNING: lib/refcount.c:96 at refcount_dec_not_one+0x3f/0x60, CPU#43: tc/2641 Call Trace: <TASK> mlx5_fs_put_hws_action.part.0+0x1a/0xa0 [mlx5_core] mlx5_fs_destroy_fs_actions+0xa8/0x110 [mlx5_core] mlx5_cmd_hws_delete_fte+0x49/0x90 [mlx5_core] del_hw_fte+0x209/0x320 [mlx5_core] mlx5_del_flow_rules+0x10b/0x260 [mlx5_core] __mlx5_eswitch_del_rule+0x5c/0x1b0 [mlx5_core] mlx5_eswitch_del_offloaded_rule+0x10/0x20 [mlx5_core] mlx5e_tc_rule_unoffload+0x4b/0x100 [mlx5_core] mlx5e_tc_unoffload_fdb_rules+0x35/0x80 [mlx5_core] mlx5e_tc_del_fdb_flow+0x2ca/0x310 [mlx5_core] mlx5e_tc_del_flow+0x5d/0x2d0 [mlx5_core] mlx5e_flow_put+0x3a/0x80 [mlx5_core] mlx5e_delete_flower+0x291/0x460 [mlx5_core] mlx5e_setup_tc_block_cb+0xc4/0x110 [mlx5_core] tc_setup_cb_destroy+0xcc/0x1b0 fl_hw_destroy_filter+0xa1/0xe0 [cls_flower] __fl_delete+0x2d0/0x3d0 [cls_flower] fl_destroy+0xbd/0x160 [cls_flower] tcf_proto_destroy+0x3b/0x110 tcf_proto_put+0x3d/0x70 tc_del_tfilter+0x362/0x8f0 rtnetlink_rcv_msg+0x384/0x460 netlink_rcv_skb+0x61/0x120 rtnetlink_rcv+0x15/0x30 netlink_unicast+0x2a1/0x3d0 netlink_sendmsg+0x237/0x490 ____sys_sendmsg+0x33b/0x360 ___sys_sendmsg+0x99/0xf0 __sys_sendmsg+0x93/0x100 __x64_sys_sendmsg+0x1d/0x30 x64_sys_call+0x821/0x23d0 do_syscall_64+0xba/0x550 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK> mlx5_core 0000:b1:00.1: mlx5_cmd_out_err:822:(pid 2642): DEALLOC_PD(0x801) op_mod(0x0) failed, status bad resource state(0x9), syndrome (0xef0c8a), err(-22) mlx5_core 0000:b1:00.1: mlx5hws_pool_destroy:386:(pid 2642): Attempting to destroy non-empty pool
Keep the base id in the rule action, as the sampler id is.
Discovered while stress testing a 5G UPF kernel code. Without this fix, the reproduction below gives the trace above on a ConnectX-7 with firmware 28.48.1000. It only uses tc and devlink, with no kernel change. 129 meters cannot fit in one ASO object. DEV is the uplink representor and PCI its devlink handle:
r() { echo "filter $1 dev $DEV ingress prio 1 handle $2 protocol ip flower skip_sw dst_ip 10.0.0.$2 action police index $3 rate 1mbit burst 32k conform-exceed drop/pipe action drop"; } devlink dev param set $PCI name flow_steering_mode value hmfs cmode runtime
devlink dev eswitch set $PCI mode switchdev
tc qdisc add dev $DEV ingress
for i in $(seq 129); do r add $i $i; done | tc -b -
r replace 1 1000 | tc -b -
tc filter del dev $DEV ingress prio 1
devlink dev eswitch set $PCI mode legacy
With this fix, the reproduction runs clean on the same ConnectX-7. It was not tested against kernel selftests.
--- .../net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c | 8 ++++---- .../net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +4 -4
@@ -523,13 +523,13 @@ mlx5_fs_get_action_aso_meter(struct mlx5_fs_hws_context *fs_ctx, }static void mlx5_fs_put_action_aso_meter (struct mlx5_fs_hws_context *fs_ctx, -struct mlx5_exe_aso *exe_aso) +u32 base_id) {struct mlx5_fs_hws_data *meter_hws_data;struct xarray *meters_xa; meters_xa = &fs_ctx->hws_pool.aso_meters; - meter_hws_data =xa_load (meters_xa, exe_aso->base_id); + meter_hws_data =xa_load (meters_xa, base_id);if (!meter_hws_data)return ;return mlx5_fs_put_hws_action (meter_hws_data);
@@ -704,7 +704,7 @@ static void mlx5_fs_destroy_fs_action(struct mlx5_flow_root_namespace *ns,mlx5_fc_put_hws_action (fs_action->counter);break ;case MLX5HWS_ACTION_TYP_ASO_METER : -mlx5_fs_put_action_aso_meter (fs_ctx, fs_action->exe_aso); +mlx5_fs_put_action_aso_meter (fs_ctx, fs_action->aso_base_id);break ;case MLX5HWS_ACTION_TYP_SAMPLER :mlx5_fs_put_dest_action_sampler (fs_ctx, fs_action->sampler_id);
@@ -936,7 +936,7 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns, fte_action->exe_aso.flow_meter.init_color; (*ractions)[num_actions++].action = tmp_action; fs_actions[num_fs_actions].action = tmp_action; - fs_actions[num_fs_actions++].exe_aso = &fte_action->exe_aso; + fs_actions[num_fs_actions++].aso_base_id = fte_action->exe_aso.base_id; }if (fte_action->action &MLX5_FLOW_CONTEXT_ACTION_DROP ) {
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +1 -1
@@ -57,7 +57,7 @@ struct mlx5_fs_hws_rule_action {struct mlx5hws_action *action;union {struct mlx5_fc *counter; -struct mlx5_exe_aso *exe_aso; +u32 aso_base_id;u32 sampler_id; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 527/1005 drm/xe/pm: Apply tile workarounds after PCODE initialization
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Charles <[email protected]>
[ Upstream commit a17c5ed0dc715d2e39d00e33372cb094209ac8ef ]
Tile workarounds program SoC registers through MMIO. Wait for PCODE initialization to complete before applying them during system resume, since MMIO access may be blocked until SoC initialization completes.
Also apply tile workarounds after PCODE initialization on D3cold runtime resume, so their register settings are restored after power loss. Keep both paths ordered before early GT resume.
--- drivers/gpu/drm/xe/xe_pm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_pm.c +7 -3
@@ -239,13 +239,13 @@ int xe_pm_resume(struct xe_device *xe)drm_dbg (&xe->drm,"Resuming device\n" );trace_xe_pm_resume (xe,__builtin_return_address (0 )); -for_each_tile (tile, xe, id) -xe_wa_apply_tile_workarounds (tile); - err =xe_pcode_ready (xe, true);if (err)return err; +for_each_tile (tile, xe, id) +xe_wa_apply_tile_workarounds (tile); +for_each_gt (gt, xe, id)xe_gt_idle_disable_c6 (gt);
@@ -666,6 +666,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe)*/ int xe_pm_runtime_resume (struct xe_device *xe) { +struct xe_tile *tile;struct xe_gt *gt;u8 id;int err =0 ;
@@ -681,6 +682,9 @@ int xe_pm_runtime_resume(struct xe_device *xe)if (err) goto out; +for_each_tile (tile, xe, id) +xe_wa_apply_tile_workarounds (tile); +for_each_gt (gt, xe, id)xe_gt_idle_disable_c6 (gt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 528/1005 drm/xe/guc: Demote uncorrectable local error log on CRI
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Varun Gupta <[email protected]>
[ Upstream commit f831b84713b57cbd67f228a7f10147791e5ab13d ]
The UNCORRECTABLE_LOCAL_ERROR notification sent by the GuC indicates a local, queue-level context termination rather than a global device or driver failure. On CRI, due to a hardware limitation, the platform cannot distinguish GT translation faults from true RAS conditions, meaning standard workloads routinely trigger this error.
Printing this at ERROR level is too noisy and causes false-positive dmesg-warn failures in CI. Demote the log level to debug for CRI.
v5:
- Correct commmit message and comment (Tejas)
v4:
- Change to _dbg instead of _info. (Matt)
v3:
- Limit the demotion to CRI and add comment explaining the HW limitation (Rodrigo)
v2:
- Also ratelimit the GUC_ID_UNKNOWN to match the CAT error handler.
(Himal)
--- drivers/gpu/drm/xe/xe_guc_submit.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_guc_submit.c +14 -4
@@ -3368,7 +3368,7 @@ int xe_guc_uncorrectable_error_handler(struct xe_guc *guc, u32 *msg, u32 len) guc_id = msg[0 ];if (guc_id ==GUC_ID_UNKNOWN ) { -xe_gt_err (gt,"GuC: Uncorrectable local error with unknown GuC id\n" ); +xe_gt_err_ratelimited (gt,"GuC: Uncorrectable local error with unknown GuC id\n" );return 0 ; }
@@ -3376,9 +3376,19 @@ int xe_guc_uncorrectable_error_handler(struct xe_guc *guc, u32 *msg, u32 len)if (unlikely (!q))return -EPROTO ; -xe_gt_err (gt, -"GuC: Uncorrectable local error! guc_id=%d class=%s, logical_mask=0x%x" , - guc_id,xe_hw_engine_class_to_str (q->class), q->logical_mask); +/* +* On CRI, the hardware cannot distinguish GT translation faults +* from true RAS conditions. Demote to debug to avoid false +* positive hardware error logs. +*/ +if (gt_to_xe (gt)->info.platform ==XE_CRESCENTISLAND ) +xe_gt_dbg (gt, +"GuC: Uncorrectable local error! guc_id=%d class=%s, logical_mask=0x%x" , + guc_id,xe_hw_engine_class_to_str (q->class), q->logical_mask); +else +xe_gt_err (gt, +"GuC: Uncorrectable local error! guc_id=%d class=%s, logical_mask=0x%x" , + guc_id,xe_hw_engine_class_to_str (q->class), q->logical_mask);trace_xe_guc_uncorrectable_error (q);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 529/1005 drm/xe/pf: Program LMTT directory pointer from each GTs init path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Satyanarayana K V P <[email protected]>
[ Upstream commit 3654a4d734df960d303d2494037606c72525c0a3 ]
The LMTT directory pointer is configured on every GT of the tile only from the primary GT's init/reset flow. On new platforms, both primary and media GTs have their own forcewake. Primary GT's init holds only its own forcewake, so the media GT write can be lost.
Program the LMTT directory pointer from each GT's own init and restart path, while that GT's forcewake is held.
Also use MCR registers for primary GT and unicast registers for media GT.
--- drivers/gpu/drm/xe/regs/xe_gt_regs.h | 1 + drivers/gpu/drm/xe/xe_gt.c | 14 +++---- drivers/gpu/drm/xe/xe_lmtt.c | 58 +++++++++++++++++++++------- drivers/gpu/drm/xe/xe_lmtt.h | 5 ++- 4 files changed, 55 insertions(+), 23 deletions(-)
drivers/gpu/drm/xe/regs/xe_gt_regs.h +1 -0
@@ -107,6 +107,7 @@#define GAMSTLB_CTRL2 XE_REG_MCR(0x4788)#define STLB_SINGLE_BANK_MODE REG_BIT(11) +#define XE2_LMEM_CFG_MCR XE_REG_MCR(0x48b0)#define XE2_LMEM_CFG XE_REG(0x48b0)#define XE2_GAMWALK_CTRL 0x47e4
drivers/gpu/drm/xe/xe_gt.c +6 -8
@@ -704,11 +704,10 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)xe_gt_apply_ccs_mode (gt); } -if (IS_SRIOV_PF (gt_to_xe (gt)) &&xe_gt_is_main_type (gt)) -xe_lmtt_init_hw (>_to_tile (gt)->sriov.pf.lmtt); - -if (IS_SRIOV_PF (gt_to_xe (gt))) +if (IS_SRIOV_PF (gt_to_xe (gt))) { +xe_lmtt_init_hw (gt);xe_gt_sriov_pf_init_hw (gt); + }/* Last action registered here so devres drains resets before teardown */ err =devm_add_action_or_reset (xe->drm.dev, gt_worker_disable, gt);
@@ -905,11 +904,10 @@ static int do_gt_restart(struct xe_gt *gt)if (err)return err; -if (IS_SRIOV_PF (gt_to_xe (gt)) &&xe_gt_is_main_type (gt)) -xe_lmtt_init_hw (>_to_tile (gt)->sriov.pf.lmtt); - -if (IS_SRIOV_PF (gt_to_xe (gt))) +if (IS_SRIOV_PF (gt_to_xe (gt))) { +xe_lmtt_init_hw (gt);xe_gt_sriov_pf_init_hw (gt); + }xe_mocs_init (gt);
drivers/gpu/drm/xe/xe_lmtt.c +45 -13
103 lines not on this page · raw message
drivers/gpu/drm/xe/xe_lmtt.h +3 -2
@@ -9,12 +9,13 @@#include <linux/types.h> struct xe_bo ; +struct xe_gt ;struct xe_lmtt ;struct xe_lmtt_ops ;#ifdef CONFIG_PCI_IOV int xe_lmtt_init (struct xe_lmtt *lmtt); -void xe_lmtt_init_hw (struct xe_lmtt *lmtt); +void xe_lmtt_init_hw (struct xe_gt *gt);void xe_lmtt_invalidate_hw (struct xe_lmtt *lmtt);int xe_lmtt_prepare_pages (struct xe_lmtt *lmtt,unsigned int vfid,u64 range);int xe_lmtt_populate_pages (struct xe_lmtt *lmtt,unsigned int vfid,struct xe_bo *bo,u64 offset);
@@ -23,7 +24,7 @@ u64 xe_lmtt_estimate_pt_size(struct xe_lmtt *lmtt, u64 size);u64 xe_lmtt_page_size (struct xe_lmtt *lmtt);#else static inline int xe_lmtt_init (struct xe_lmtt *lmtt) {return 0 ; } -static inline void xe_lmtt_init_hw (struct xe_lmtt *lmtt) { } +static inline void xe_lmtt_init_hw (struct xe_gt *gt) { }#endif #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 530/1005 drm/xe: Sync Wa_16023105232 in xe_was to match OOB rule
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gustavo Sousa <[email protected]>
[ Upstream commit 557c7b4343781cae9725bf26122d29c26ea12f5d ]
Wa_16023105232 was extended in xe_wa_oob.rules to match extra IP releases while the respective entry in xe_was[] was overlooked. Update the latter to be in sync with the former.
Also add comments in the code so that we don't forget to update both places if new IP versions are added.
--- drivers/gpu/drm/xe/xe_wa.c | 5 +++-- drivers/gpu/drm/xe/xe_wa_oob.rules | 1 + 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_wa.c +3 -2
@@ -579,8 +579,9 @@ static const struct xe_rtp_table_sr engine_was = XE_RTP_TABLE_SR(XE_RTP_ACTIONS (SET (TDL_CHICKEN ,QID_WAIT_FOR_THREAD_NOT_RUN_DISABLE )) }, { XE_RTP_NAME("16023105232"), -XE_RTP_RULES (MEDIA_VERSION_RANGE (1301 ,3000 ),OR , -GRAPHICS_VERSION_RANGE (2001 ,3001 )), +/* IP versions need to be in sync with the respective entry in xe_wa_oob.rules. */ +XE_RTP_RULES (MEDIA_VERSION_RANGE (1301 ,3002 ),OR , +GRAPHICS_VERSION_RANGE (2001 ,3005 )),XE_RTP_ACTIONS (SET (RING_PSMI_CTL (0 ),RC_SEMA_IDLE_MSG_DISABLE ,XE_RTP_ACTION_FLAG (ENGINE_BASE ))) },
drivers/gpu/drm/xe/xe_wa_oob.rules +1 -0
@@ -44,6 +44,7 @@ 18013179988 GRAPHICS_VERSION(1255) GRAPHICS_VERSION_RANGE(1270, 1274) 1508761755 GRAPHICS_VERSION(1255) +# IP versions need to be in sync with the respective entry in xe_wa.c. 16023105232 GRAPHICS_VERSION_RANGE(2001, 3005) MEDIA_VERSION_RANGE(1301, 3002) 16026508708 GRAPHICS_VERSION_RANGE(1200, 3005)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 531/1005 ALSA: hda/realtek - remove headphone MIC support for Dell Pro QC1255
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kailang Yang <[email protected]>
[ Upstream commit 1da5e525f0526a0b8e3b6c8c3208e6fad920f126 ]
This unit don't support headphone MIC.
The popping sound will disappear when you remove it.
--- sound/hda/codecs/realtek/alc269.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
sound/hda/codecs/realtek/alc269.c +6 -13
@@ -4436,7 +4436,6 @@ enum {ALC256_FIXUP_HONOR_MRB_XXX_M1020_AUDIO ,ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX ,ALC287_FIXUP_ACER_MICMUTE_LED , -ALC236_FIXUP_DELL_HP_POP_NOISE ,ALC274_FIXUP_HP_89E9_GPIO ,ALC274_FIXUP_HP_VERBS , ALC287_FIXUP_AW88399_I2C_2,
@@ -7226,12 +7225,6 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC2XX_FIXUP_HEADSET_MIC, }, - [ALC236_FIXUP_DELL_HP_POP_NOISE] = { - .type = HDA_FIXUP_FUNC, - .v.func = alc285_fixup_invalidate_dacs, - .chained = true, - .chain_id =ALC255_FIXUP_DELL1_MIC_NO_PRESENCE - }, [ALC274_FIXUP_HP_89E9_GPIO] = { .type = HDA_FIXUP_FUNC, .v.func = alc274_fixup_hp_89e9_amp,
@@ -7469,12 +7462,12 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1028 ,0x0cc3 ,"Dell Oasis 14 Low Weight MTL-U" ,ALC289_FIXUP_DELL_CS35L41_SPI_2 ),SND_PCI_QUIRK (0x1028 ,0x0cc4 ,"Dell Oasis 16 MTL-H/U" ,ALC289_FIXUP_DELL_CS35L41_SPI_2 ),SND_PCI_QUIRK (0x1028 ,0x0cc5 ,"Dell Oasis 14" ,ALC289_FIXUP_RTK_AMP_DUAL_SPK ), -SND_PCI_QUIRK (0x1028 ,0x0d56 ,"Dell Pro Tower QCT1255" ,ALC236_FIXUP_DELL_HP_POP_NOISE ), -SND_PCI_QUIRK (0x1028 ,0x0d58 ,"Dell Pro Micro QCM1255" ,ALC236_FIXUP_DELL_HP_POP_NOISE ), -SND_PCI_QUIRK (0x1028 ,0x0d5a ,"Dell Pro Slim QCS1255" ,ALC236_FIXUP_DELL_HP_POP_NOISE ), -SND_PCI_QUIRK (0x1028 ,0x0e6b ,"Dell Pro Tower QCT1255" ,ALC236_FIXUP_DELL_HP_POP_NOISE ), -SND_PCI_QUIRK (0x1028 ,0x0e6c ,"Dell Pro Slim QCS1255" ,ALC236_FIXUP_DELL_HP_POP_NOISE ), -SND_PCI_QUIRK (0x1028 ,0x0e6d ,"Dell Pro Micro QCM1255" ,ALC236_FIXUP_DELL_HP_POP_NOISE ), +SND_PCI_QUIRK (0x1028 ,0x0d56 ,"Dell Pro Tower QCT1255" ,ALC255_FIXUP_DELL2_MIC_NO_PRESENCE ), +SND_PCI_QUIRK (0x1028 ,0x0d58 ,"Dell Pro Micro QCM1255" ,ALC255_FIXUP_DELL2_MIC_NO_PRESENCE ), +SND_PCI_QUIRK (0x1028 ,0x0d5a ,"Dell Pro Slim QCS1255" ,ALC255_FIXUP_DELL2_MIC_NO_PRESENCE ), +SND_PCI_QUIRK (0x1028 ,0x0e6b ,"Dell Pro Tower QCT1255" ,ALC255_FIXUP_DELL2_MIC_NO_PRESENCE ), +SND_PCI_QUIRK (0x1028 ,0x0e6c ,"Dell Pro Slim QCS1255" ,ALC255_FIXUP_DELL2_MIC_NO_PRESENCE ), +SND_PCI_QUIRK (0x1028 ,0x0e6d ,"Dell Pro Micro QCM1255" ,ALC255_FIXUP_DELL2_MIC_NO_PRESENCE ),SND_PCI_QUIRK (0x1028 ,0x164a ,"Dell" ,ALC293_FIXUP_DELL1_MIC_NO_PRESENCE ),SND_PCI_QUIRK (0x1028 ,0x164b ,"Dell" ,ALC293_FIXUP_DELL1_MIC_NO_PRESENCE ), SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 532/1005 ALSA: hda/realtek: Update quirk for Acer Predator PHN16-72
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fa-Iz Faadhillah Ibrahim <[email protected]>
[ Upstream commit a2dac609bfcc395a8c2e87d3ba1fc26ac50811d0 ]
The Acer Predator PHN16-72 (1025:1731) uses the ALC245 codec, but its mic-mute LED is not enabled by default. Replace the existing quirk with ALC245_FIXUP_ACER_MICMUTE_LED quirk to enable the mic-mute LED chain the existing ALC2XX_FIXUP_HEADSET_MIC quirk.
--- sound/hda/codecs/realtek/alc269.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +1 -1
@@ -7363,7 +7363,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1025 ,0x169a ,"Acer Swift SFG16" ,ALC256_FIXUP_ACER_SFG16_MICMUTE_LED ),SND_PCI_QUIRK (0x1025 ,0x171e ,"Acer Nitro ANV15-51" ,ALC245_FIXUP_ACER_MICMUTE_LED ),SND_PCI_QUIRK (0x1025 ,0x172c ,"Acer Nitro ANV16-41" ,ALC2XX_FIXUP_HEADSET_MIC ), -SND_PCI_QUIRK (0x1025 ,0x1731 ,"Acer Predator PHN16-72" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1025 ,0x1731 ,"Acer Predator PHN16-72" ,ALC245_FIXUP_ACER_MICMUTE_LED ),SND_PCI_QUIRK (0x1025 ,0x173a ,"Acer Swift SFG14-73" ,ALC245_FIXUP_ACER_MICMUTE_LED ),SND_PCI_QUIRK (0x1025 ,0x173b ,"Acer Swift SFG16-72" ,ALC245_FIXUP_ACER_MICMUTE_LED ), SND_PCI_QUIRK(0x1025, 0x1758, "Acer Nitro ANV15-41", ALC245_FIXUP_ACER_MICMUTE_LED),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 533/1005 igmp: use the joined device when leaving a multicast group
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junyoung Jang <[email protected]>
[ Upstream commit 19ec8416a76c08326fe5f814410a1b43046e63be ]
When a socket joins a multicast group, the ifindex of the device is stored in the socket's membership entry. When leaving, ip_mc_leave_group() resolves the device again from the request. If the request only specifies an interface address and that address is not assigned to any device, no device is found. The membership is still matched by address and removed from the socket, but the group is not released on the device it was joined on.
The group is then leaked on the device until the device is unregistered. An unprivileged user can trigger this by joining with an ifindex and a non-local address and leaving with the address only. It can also happen when a socket joins and leaves with the address only and the address is removed in between.
Fix by resolving the device from the ifindex stored in the membership, like ip_mc_drop_socket() does.
--- net/ipv4/igmp.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/igmp.c +2 -0
@@ -2463,6 +2463,8 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) iml->multi.imr_address.s_addr)continue ; +/* The drop request may not resolve to the joined device. */ + in_dev =inetdev_by_index (net, iml->multi.imr_ifindex); (void )ip_mc_leave_src (sk, iml, in_dev); *imlp = iml->next_rcu;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 534/1005 net: Make PSP skb extension survive packet scrubbing
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Wang <[email protected]>
[ Upstream commit b22268fc3ddc1e634daf177e53b04e96fa58c330 ]
skb_scrub_packet() drops all skb extensions unconditionally via skb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv, vxlan_rcv, etc.) and virtual device forwarding/redirection (dev_forward_skb, netkit_xmit, skb_do_redirect).
When a virtual device such as netkit is associated with a PSP device in another network namespace via PSP_CMD_DEV_ASSOC, incoming PSP packets decapsulated by psp_dev_rcv() lose their SKB_EXT_PSP extension when scrubbed during redirection into the peer netns. Without SKB_EXT_PSP, __psp_sk_rx_policy_check() rejects incoming TCP data segments at the socket layer with SKB_DROP_REASON_PSP_INPUT.
Introduce a static skb_ext_scrub() helper in net/core/skbuff.c to preserve SKB_EXT_PSP across skb_scrub_packet() while dropping all other extensions. If SKB_EXT_PSP is not active, skb_ext_scrub() simply calls skb_ext_reset(). If SKB_EXT_PSP is the only extension in the skb_ext buffer, nothing needs to be scrubbed. Otherwise, save the PSP metadata, reset the extension block, and re-add a fresh SKB_EXT_PSP extension.
--- net/core/skbuff.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
net/core/skbuff.c +28 -2
@@ -6311,6 +6311,31 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, }EXPORT_SYMBOL (skb_try_coalesce); +static void skb_ext_scrub (struct sk_buff *skb) +{ +#if IS_ENABLED (CONFIG_INET_PSP ) +struct psp_skb_ext *pse =skb_ext_find (skb,SKB_EXT_PSP ); + +if (pse) { +struct skb_ext *ext = skb->extensions; +struct psp_skb_ext tmp; + +/* Nothing else to scrub if PSP is the only extension in ext. */ +if (ext->chunks ==SKB_EXT_CHUNKSIZEOF (*ext) + + skb_ext_type_len[SKB_EXT_PSP ]) +return ; + + tmp = *pse; +skb_ext_reset (skb); + pse =skb_ext_add (skb,SKB_EXT_PSP ); +if (pse) +memcpy (pse, &tmp,sizeof (*pse)); +return ; + } +#endif +skb_ext_reset (skb); +} +/** * skb_scrub_packet - scrub an skb *
@@ -6322,7 +6347,8 @@ EXPORT_SYMBOL(skb_try_coalesce);* operations. * skb_scrub_packet can also be used to clean a skb before injecting it in * another namespace (@xnet == true). We have to clear all information in the -* skb that could impact namespace isolation. +* skb that could impact namespace isolation. Note that PSP skb extension is +* preserved across packet scrubbing by design. */ void skb_scrub_packet (struct sk_buff *skb,bool xnet) {
@@ -6330,7 +6356,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet) skb->skb_iif =0 ; skb->ignore_df =0 ;skb_dst_drop (skb); -skb_ext_reset (skb); +skb_ext_scrub (skb);nf_reset_ct (skb);nf_reset_trace (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 535/1005 sched_ext: Reject DSQ iterator kfuncs in tracing programs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit 700a332c3fe33014bbd5ae852d71ba679fc29e0a ]
bpf_iter_scx_dsq_next() and bpf_iter_scx_dsq_destroy() take the target user DSQ's raw spinlock, but they are in scx_kfunc_ids_any, which is also registered for BPF_PROG_TYPE_TRACING.
For an active root scheduler without ops.sub_attach, the compatibility path in scx_prog_sched() lets an unassociated tracing program resolve to that scheduler. The tracing program can then call the iterator kfuncs while the target DSQ lock is already held.
For example, a scheduler which mixes FIFO and priority-queue insertions into a user DSQ triggers scx_error() from scx_dispatch_enqueue() while holding that DSQ's lock. scx_claim_exit() emits sched_ext_exit before the lock is released:
scx_dispatch_enqueue()
raw_spin_lock(&dsq->lock)
scx_error()
scx_claim_exit()
trace_sched_ext_exit()
tracing BPF program
bpf_iter_scx_dsq_new(dsq_id)
bpf_for_each(scx_dsq, p, dsq_id, 0)
bpf_iter_scx_dsq_next(it)
raw_spin_lock_irqsave(&dsq->lock)The tracing program recursively acquires the same raw spinlock and locks up the CPU. Because the tracepoint runs before scx_finish_exit(), disable_irq_work is not queued and the scheduler cannot enter its normal disable path.
Reject the two iterator kfuncs from tracing programs at verification time. The kfuncs remain available to SCX struct_ops and syscall programs. bpf_iter_scx_dsq_destroy() has no independent live
reproduction: its cursor only links into the DSQ after at least one successful next(), which deadlocks in the same window first. It is included for symmetry.
This extends the coverage of commit b07a7450f6ef ("sched_ext: Reject rq-lock-taking kfuncs in tracing programs") and commit 4c2e0751d5e6 ("sched_ext: Reject scx_bpf_destroy_dsq() in tracing programs").
--- kernel/sched/ext/ext.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/sched/ext/ext.c +6 -2
@@ -11316,8 +11316,10 @@ static const struct btf_kfunc_id_set scx_kfunc_set_any = {* when scx_locked_rq() returns NULL. Taking it while the context already holds * an rq lock, the same one or another cpu's, can deadlock. * -* scx_bpf_destroy_dsq() takes a user DSQ lock. A tracing program can run while -* that lock is already held and recursively acquire it. +* scx_bpf_destroy_dsq() takes a user DSQ lock. So do +* bpf_iter_scx_dsq_next() and bpf_iter_scx_dsq_destroy(), the latter only +* after a successful next() has linked the cursor. A tracing program can +* run while that lock is already held and recursively acquire it. * * Before returning, scx_bpf_sub_grant() and scx_bpf_sub_revoke() invoke * ops.sub_caps_updated() of the sub-schedulers whose caps changed, so those ops
@@ -11334,6 +11336,8 @@ BTF_ID_FLAGS(func, scx_bpf_cidperf_set, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, scx_bpf_sub_grant, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, scx_bpf_sub_revoke, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, scx_bpf_destroy_dsq, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, bpf_iter_scx_dsq_next, KF_ITER_NEXT | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_iter_scx_dsq_destroy, KF_ITER_DESTROY)BTF_KFUNCS_END (scx_kfunc_ids_no_tracing)/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 536/1005 ice: dpll: serialize changes of the SyncE CGU registers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 0afbc079d87eb2ba86b396bb1be145ad679ec300 ]
All E825C PFs share the CGU registers R10 and R11. On dual complex E825 the second complex reaches the CGU of complex 0 through cgu_peer. RCLK pin callbacks read, modify and write these registers under dpll_lock and the pf->dplls.lock of their PF. ice_ptp_link_change() rewrites R10 under the pf->dplls.lock of its PF only, so a link change on one PF can write back a stale R10 and undo an RCLK pin change made by another PF.
Add a mutex to struct ice_adapter, which all E825C PFs share, and hold it around these sequences.
Tested on GNR-D with dual complex E825, with a 2 to 4 ms delay after the read of R10 in the link change path to widen the window. Toggling the RCLK pin of one port while another port of the same complex went down and up 143 times lost 120 of 86814 updates of the mux in R10 without this patch, and none of 76992 with it.
--- drivers/net/ethernet/intel/ice/ice_adapter.c | 2 ++ drivers/net/ethernet/intel/ice/ice_adapter.h | 4 ++++ drivers/net/ethernet/intel/ice/ice_dpll.c | 11 ++++++----- drivers/net/ethernet/intel/ice/ice_dpll.h | 4 ++++ drivers/net/ethernet/intel/ice/ice_ptp.c | 2 ++ drivers/net/ethernet/intel/ice/ice_tspll.c | 4 ++-- 6 files changed, 20 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_adapter.c +2 -0
@@ -72,6 +72,7 @@ static struct ice_adapter *ice_adapter_new(struct pci_dev *pdev)spin_lock_init (&adapter->txq_ctx_lock);for (int i =0 ; i <ARRAY_SIZE (adapter->cpi_phy_lock); i++)mutex_init (&adapter->cpi_phy_lock[i]); +mutex_init (&adapter->cgu_synce_lock);refcount_set (&adapter->refcount,1 );spin_lock_init (&adapter->ports.lock);
@@ -85,6 +86,7 @@ static void ice_adapter_free(struct ice_adapter *adapter)WARN_ON (!list_empty (&adapter->ports.list));for (int i =0 ; i <ARRAY_SIZE (adapter->cpi_phy_lock); i++)mutex_destroy (&adapter->cpi_phy_lock[i]); +mutex_destroy (&adapter->cgu_synce_lock);cleanup_srcu_struct (&adapter->ports.srcu);
drivers/net/ethernet/intel/ice/ice_adapter.h +4 -0
@@ -41,6 +41,8 @@ struct ice_port_list {* @txq_ctx_lock: Spinlock protecting access to the GLCOMM_QTX_CNTX_CTL register * @cpi_phy_lock: Per-PHY mutex serializing CPI REQ/ACK transactions. * Index 0 = PHY0, index 1 = PHY1. Used on E825C devices. +* @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11, +* which all PFs reach. Used on E825C devices. * @ctrl_pf: Control PF of the adapter * @ports: Ports list * @index: 64-bit index cached for collision detection on 32bit systems
@@ -53,6 +55,8 @@ struct ice_adapter {spinlock_t txq_ctx_lock;/* Serialize CPI REQ/ACK transactions per PHY (E825C only) */ struct mutex cpi_phy_lock[ICE_E825_MAX_PHYS ]; +/* Serialize changes of the SyncE CGU registers (E825C only) */ +struct mutex cgu_synce_lock;struct ice_pf *ctrl_pf;struct ice_port_list ports;
drivers/net/ethernet/intel/ice/ice_dpll.c +6 -5
@@ -2024,7 +2024,7 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,* * DPLL subsystem callback. Set proper signals to recover clock from port. * -* Context: Called under pf->dplls.lock +* Context: Called under pf->dplls.lock, acquires adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error
@@ -2032,14 +2032,15 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,static int ice_dpll_synce_update_e825c (struct ice_hw *hw,bool ena,u32 port_num,enum ice_synce_clk output) { +struct ice_pf *pf = hw->back;int err; +mutex_lock (&pf->adapter->cgu_synce_lock);/* configure the mux to deliver proper signal to DPLL from the MUX */ err =ice_tspll_cfg_bypass_mux_e825c (hw, ena, port_num, output); -if (err) -return err; - - err =ice_tspll_cfg_synce_ethdiv_e825c (hw, output); +if (!err) + err =ice_tspll_cfg_synce_ethdiv_e825c (hw, output); +mutex_unlock (&pf->adapter->cgu_synce_lock);if (err)return err;
drivers/net/ethernet/intel/ice/ice_dpll.h +4 -0
@@ -156,6 +156,7 @@ struct ice_dpll {* txclk_notify_rwsem (read) * -> pf->dplls.lock * -> ctrl_pf->dplls.lock +* -> adapter->cgu_synce_lock * * - @lock serializes all DPLL state mutations on this PF. When the * controlling PF's lock must also be taken (e.g. updating the shared
@@ -167,6 +168,9 @@ struct ice_dpll {* dpll_*_change_ntf() calls. ice_dpll_deinit() takes the write side * standalone (not nested under any other lock) to drain in-flight * readers before pins and the TXC DPLL device are freed. +* - adapter->cgu_synce_lock serializes changes of the CGU registers R10 and +* R11. All E825C PFs reach one CGU, so @lock, which is per PF, does not +* cover them. */ struct ice_dplls {struct kthread_worker *kworker;
drivers/net/ethernet/intel/ice/ice_ptp.c +2 -0
@@ -1365,7 +1365,9 @@ void ice_ptp_link_change(struct ice_pf *pf, bool linkup)break ; } +mutex_lock (&pf->adapter->cgu_synce_lock); err =ice_tspll_cfg_synce_ethdiv_e825c (hw, clk_pin); +mutex_unlock (&pf->adapter->cgu_synce_lock);if (active && err) { dev_err_once(ice_pf_to_dev(pf), "Failed to configure SyncE ETH divider for pin %d, err %d\n",
drivers/net/ethernet/intel/ice/ice_tspll.c +2 -2
@@ -680,7 +680,7 @@ int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active,* * Set reference clock source and output clock selection. * -* Context: Called under pf->dplls.lock +* Context: Called under pf->dplls.lock and adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error
@@ -786,7 +786,7 @@ static int ice_tspll_get_div_e825c(u16 link_speed, unsigned int *divider)* * Set the correct CGU divider for RCLKA or RCLKB. * -* Context: Called under pf->dplls.lock +* Context: Called under pf->dplls.lock and adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 537/1005 ice: dpll: set the SyncE divider only for the port driving the output
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 164721e16b822c3b2f19526ff00deaa7b47fbf46 ]
R10 holds one divider for each recovered clock output, shared by all ports. ice_ptp_link_change() sets it from the link speed of its own port even when another port drives the output, and checks the mux only to decide whether an error is worth reporting. With ports running at different speeds, a link change on one port leaves the output of another port with a wrong divider.
Skip the outputs that the port does not drive, and check the mux under cgu_synce_lock, so that another PF cannot select its port in between.
The check computes the mux value as port % ports_per_phy + 3, while ice_tspll_cfg_bypass_mux_e825c() and ice_dpll_rclk_update_e825c() use port + 3. With the skip, a port from ports_per_phy up would never update the divider, so use port + 3 as they do.
Tested on GNR-D with dual complex E825. With the RCLK pin of one port connected, five down and up cycles of another port of the same complex called ice_tspll_cfg_synce_ethdiv_e825c() 20 times without this patch and never with it. Five cycles of the port driving the output still called it 10 times. Both ports ran at 25 Gb/s, so the divider value did not change on this setup.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 10 +++++++--- drivers/net/ethernet/intel/ice/ice_tspll.c | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +7 -3
@@ -1347,6 +1347,7 @@ void ice_ptp_link_change(struct ice_pf *pf, bool linkup)int pin, err;mutex_lock (&pf->dplls.lock); +mutex_lock (&pf->adapter->cgu_synce_lock);for (pin =0 ; pin <ICE_SYNCE_CLK_NUM ; pin++) {enum ice_synce_clk clk_pin;bool active;
@@ -1365,16 +1366,19 @@ void ice_ptp_link_change(struct ice_pf *pf, bool linkup)break ; } -mutex_lock (&pf->adapter->cgu_synce_lock); +/* The divider is shared, set it only for our port */ +if (!active) +continue ; + err =ice_tspll_cfg_synce_ethdiv_e825c (hw, clk_pin); -mutex_unlock (&pf->adapter->cgu_synce_lock); -if (active && err) { +if (err) {dev_err_once (ice_pf_to_dev (pf),"Failed to configure SyncE ETH divider for pin %d, err %d\n" , pin, err);break ; } } +mutex_unlock (&pf->adapter->cgu_synce_lock);mutex_unlock (&pf->dplls.lock);if (linkup)
drivers/net/ethernet/intel/ice/ice_tspll.c +2 -2
@@ -634,6 +634,7 @@ int ice_tspll_init(struct ice_hw *hw)* * Check if given port is selected as recovered clock source for given output. * +* Context: Called under pf->dplls.lock and adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error
@@ -662,8 +663,7 @@ int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active,return -EINVAL ; } -if (active_clk == port % hw->ptp.ports_per_phy + -ICE_CGU_BYPASS_MUX_OFFSET_E825C ) +if (active_clk == port +ICE_CGU_BYPASS_MUX_OFFSET_E825C ) *active = true;else *active = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 538/1005 net/mlx5e: kTLS, Fix missing error unwind when enabling RX offload
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xuanqiang Luo <[email protected]>
[ Upstream commit 343672bad64153e895d201ff6d3dfaf15c22682e ]
Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().
If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.
Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.
--- drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +5 -1
@@ -139,7 +139,11 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable) err =mlx5e_accel_fs_tcp_create (priv->fs);if (!err && !priv->ktls_rx_was_enabled) { priv->ktls_rx_was_enabled = true; -mlx5e_safe_reopen_channels (priv); + err =mlx5e_safe_reopen_channels (priv); +if (err) { + priv->ktls_rx_was_enabled = false; +mlx5e_accel_fs_tcp_destroy (priv->fs); + } } }else {mlx5e_accel_fs_tcp_destroy (priv->fs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 539/1005 udp_tunnel: dont treat IPv4 sockets bound to an address as wildcard
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antonio Quartulli <[email protected]>
[ Upstream commit 612b8376e8112a6f9caaedc25fa48ac42e02826d ]
With IPv6 enabled, sk_saddr_any() checks sk_v6_rcv_saddr also for AF_INET sockets, where it is always zero. An IPv4 tunnel socket bound to a specific address (e.g. fou or geneve with "local") ends up in the GRO lookup fast path, although another socket may bind the same port on a different address: GRO then hands that socket's packets to the tunnel's gro_receive.
Check the IPv6 address only for AF_INET6 sockets.
--- net/ipv4/udp_tunnel_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv4/udp_tunnel_core.c +3 -3
@@ -62,10 +62,10 @@ EXPORT_SYMBOL(udp_sock_create4);static bool sk_saddr_any (struct sock *sk) {#if IS_ENABLED (CONFIG_IPV6 ) -return ipv6_addr_any (&sk->sk_v6_rcv_saddr); -#else -return !sk->sk_rcv_saddr; +if (sk->sk_family ==AF_INET6 ) +return ipv6_addr_any (&sk->sk_v6_rcv_saddr);#endif +return !sk->sk_rcv_saddr; } void setup_udp_tunnel_sock(struct net *net, struct sock *sk,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 540/1005 net/mlx5: Lag, Return error when enabling MPESW without LAG support
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uri Dar <[email protected]>
[ Upstream commit a532a7049ba23edeb2e16f7bb5929314f2e47ca0 ]
When firmware reports a function as not LAG capable (lag_master=0 or num_lag_ports < 2), mlx5_lag_add_mdev() creates no LAG object for it. Enabling multiport E-Switch on such a device returns 0 from mlx5_lag_mpesw_queue_work(), so
"devlink dev param set ... esw_multiport value true" reports success although nothing was enabled, and a following "devlink dev param show" still reports false.
Return -EOPNOTSUPP instead. mlx5_lag_mpesw_disable() ignores the return value, so disabling keeps its current behavior.
--- drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +1 -1
@@ -227,7 +227,7 @@ static int mlx5_lag_mpesw_queue_work(struct mlx5_core_dev *dev,int err =0 ;if (!ldev) -return 0 ; +return -EOPNOTSUPP ; work =kzalloc_obj (*work);if (!work)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 541/1005 net: virtio: fix UDP tunnel GSO header of VLAN tagged packets
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 9e244f94128a4b89004f0564b66e039e58318a34 ]
virtio_net_hdr_tnl_from_skb() builds a wrong header for VLAN tagged UDP tunnel GSO packets.
1) When the skb carries a hwaccel VLAN tag, tun_put_user() inserts the 802.1Q header in the frame it copies to user space or vhost-net, and passes vlan_hlen = VLAN_HLEN. virtio_net_hdr_from_skb() adds vlan_hlen to csum_start, but inner_nh_offset and outer_th_offset do not account for it, and are 4 bytes short of the real inner L3 and outer UDP headers in the emitted frame.
tun advertises NETIF_F_HW_VLAN_CTAG_TX and NETIF_F_HW_VLAN_STAG_TX in hw_enc_features, and its vlan_features keep the UDP tunnel GSO features, so this happens for example with a VLAN filtering bridge with a tagged port, or with a vlan device on top of a tap.
2) The outer family comes from skb->protocol, which is ETH_P_8021Q or ETH_P_8021AD when the VLAN tag is in the packet data, so a packet with an outer IPv6 header is reported as VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4. This happens when __vlan_hwaccel_push_inside() inserted the tag because the device does not offload it: virtio_net never offloads VLAN insertion but keeps UDP tunnel GSO in its vlan_features, and tun does the same with VLAN TX offload disabled, or with QinQ (outer tag offloaded, inner tag in the data).
The receiver sets inner_network_header and transport_header from these offsets, and checks them with the wrong outer family. A forwarded packet that gets segmented again uses the wrong inner headers, and a receiver checking the outer headers against the virtio header drops the packet.
Add vlan_hlen to both offsets like csum_start, and take the outer family from vlan_get_protocol(), which skips VLAN tags in the data.
--- include/linux/virtio_net.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
include/linux/virtio_net.h +9 -3
@@ -622,7 +622,10 @@ virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb,if (feature_hdrlen && hdr->hdr_len)__virtio_net_set_tnl_hdrlen (skb, hdr); -if (skb->protocol ==htons (ETH_P_IPV6 )) +/* skb->protocol is the VLAN protocol when the tag is in the +* packet data. +*/ +if (vlan_get_protocol (skb) ==htons (ETH_P_IPV6 )) hdr->gso_type |=VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6 ;else hdr->gso_type |=VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4 ;
@@ -630,8 +633,11 @@ virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb,if (skb_shinfo (skb)->gso_type &SKB_GSO_UDP_TUNNEL_CSUM ) hdr->flags |=VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ; - inner_nh = skb->inner_network_header -skb_headroom (skb); - outer_th = skb->transport_header -skb_headroom (skb); +/* Like csum_start, the offsets must account for a VLAN tag +* the caller inserts in the frame. +*/ + inner_nh = skb->inner_network_header -skb_headroom (skb) + vlan_hlen; + outer_th = skb->transport_header -skb_headroom (skb) + vlan_hlen; vhdr->inner_nh_offset =cpu_to_le16 (inner_nh); vhdr->outer_th_offset =cpu_to_le16 (outer_th);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 542/1005 tcp: Pass req->rsk_listener to inet_csk_reqsk_queue_drop() in tcp_check_req().
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit a9782a6f2bbd0c444689725a710d8b21eab61bc5 ]
When connection migration happens in tcp_v[46]_rcv(), a new listener is passed to tcp_check_req().
When either of the following is true,
* the new listener queue is full and
net.ipv4.tcp_abort_on_overflow is set
* the packet has RST or (not stripped) SYN
tcp_check_req() sends RST and calls inet_csk_reqsk_queue_drop().
Here, the new listener is passed, and its qlen is decremented wrongly while reqsk is tied to the old listener.
Once qlen underflows, inet_csk_reqsk_queue_is_full() always return true, and the new listener stops serving.
Without the patch, this script times out while waiting for SYN+ACK since the new listener drops SYN, but with the patch, 3WHS completes.
0 `sysctl -q net.ipv4.tcp_migrate_req=1`
+0 sysctl -q net.ipv4.tcp_syncookies=0
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_SOCKET, SO_REUSEPORT, [1], 4) = 0 +0 bind(3, ..., ...) = 0
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 4 +0 setsockopt(4, SOL_SOCKET, SO_REUSEPORT, [1], 4) = 0 +0 bind(4, ..., ...) = 0
+0 listen(4, 128) = 0
+0 < S 0:0(0) win 32792 <mss 1000>
+0 > S. 0:0(0) ack 1 <...>
+0 listen(3, 128) = 0
+0 close(4) = 0
+.01 < R 1:1(0) win 0
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 5 +0 listen(5, 1) = 0
+.01 < S 0:0(0) win 32792 <mss 1000>
+0 > S. 0:0(0) ack 1 <...>
+0 < . 1:1(0) ack 1 win 32792
+0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0 accept(3, ..., ...) = 6
Let's pass req->rsk_listener instead.
--- net/ipv4/tcp_minisocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_minisocks.c +1 -1
@@ -974,7 +974,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,tcp_reset (sk, skb); }if (!fastopen) { -bool unlinked =inet_csk_reqsk_queue_drop (sk, req); +bool unlinked =inet_csk_reqsk_queue_drop (req->rsk_listener, req);if (unlinked)__NET_INC_STATS (sock_net (sk),LINUX_MIB_EMBRYONICRSTS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 543/1005 af_unix: Inherit SO_INQ in unix_stream_connect()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenbo Sun <[email protected]>
[ Upstream commit 0359338fd8cf1a2dc001d0cd69c331c17decee88 ]
When SO_INQ is enabled on a listening AF_UNIX SOCK_STREAM socket, accepted sockets created by unix_stream_connect() do not inherit u->recvmsg_inq from the listener, unlike TCP_INQ, AF_VSOCK SO_INQ, and AF_UNIX SO_RIGHTS_NOTRUNC. As a result, recvmsg() on the accepted socket never puts an SCM_INQ control message unless SO_INQ is set again after accept().
Copy otheru->recvmsg_inq to newu->recvmsg_inq in unix_stream_connect() using READ_ONCE() to pair with the lockless WRITE_ONCE() in unix_setsockopt().
Found during LLM-assisted code review of unix_stream_connect() while comparing option inheritance between SO_INQ and SO_RIGHTS_NOTRUNC.
Confirmed on UML (x86_64) by enabling SO_INQ on a listening AF_UNIX SOCK_STREAM socket before listen() and accept(), sending data from a connected client, and observing that recvmsg() on the accepted socket returned no SCM_INQ control message.
Tested on UML (x86_64) against the reproducer, verifying that recvmsg() on the accepted socket now returns the expected SCM_INQ control message, and ran the tools/testing/selftests/net/af_unix/scm_inq selftest (all 6 test cases passed).
--- net/unix/af_unix.c | 1 + 1 file changed, 1 insertion(+)
net/unix/af_unix.c +1 -0
@@ -1752,6 +1752,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr_unsized *uad newu =unix_sk (newsk); otheru =unix_sk (other); newu->listener = other; + newu->recvmsg_inq =READ_ONCE (otheru->recvmsg_inq); newu->scm_rights_notrunc =READ_ONCE (otheru->scm_rights_notrunc);RCU_INIT_POINTER (newsk->sk_wq, &newu->peer_wq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 544/1005 amt: use ipv6_hdr() in amt_mldv1_leave_handler()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenbo Sun <[email protected]>
[ Upstream commit 6730fe495c35f174a424ab58cf5fdf99ce4746e9 ]
In amt_mldv1_leave_handler(), which handles IPv6 MLDv1 Done (ICMPV6_MGM_REDUCTION) messages, the source address is mistakenly extracted via ip_hdr(skb)->saddr into host.ip4 instead of copying the IPv6 source address from ipv6_hdr(skb)->saddr into host.ip6 as amt_mldv1_report_handler() does.
Because amt_lookup_group() compares the full union amt_addr for v6 groups, looking up the group with a 32-bit IPv4 header slice fails to match the group entry created by amt_mldv1_report_handler(). As a result, amt_del_group() is not called when an MLDv1 listener leaves, and the AMT relay continues forwarding multicast traffic until the group timer expires.
Use ipv6_hdr(skb) and copy ip6h->saddr into host.ip6 so that MLDv1 Done messages properly match and delete the corresponding IPv6 group.
This issue was found via LLM-assisted code review, confirmed by reproducing the stale group forwarding in a User-Mode Linux (ARCH=um) environment, and verified in UML by testing that AMT relay multicast forwarding stops immediately after receiving an MLDv1 Done message.
--- drivers/net/amt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/amt.c +2 -3
@@ -2137,13 +2137,12 @@ static void amt_mldv1_leave_handler(struct amt_dev *amt, struct sk_buff *skb, struct amt_tunnel_list *tunnel) {struct mld_msg *mld = (struct mld_msg *)icmp6_hdr (skb); -struct iphdr *iph =ip_hdr (skb); +struct ipv6hdr *ip6h =ipv6_hdr (skb);struct amt_group_node *gnode;union amt_addr group, host;memcpy (&group.ip6, &mld->mld_mca,sizeof (struct in6_addr )); -memset (&host,0 ,sizeof (union amt_addr )); - host.ip4 = iph->saddr; +memcpy (&host.ip6, &ip6h->saddr,sizeof (struct in6_addr )); gnode =amt_lookup_group (tunnel, &group, &host, true);if (gnode) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 545/1005 net: usb: cdc_ncm: dont underflow the NDP room check
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiahao Xu <[email protected]>
[ Upstream commit b507828c7b6135ff7a4b69eba6e33502b4839fb9 ]
cdc_ncm_ndp16() and cdc_ncm_ndp32() verify that the new NDP and the datagram fit into the NTB with an unsigned subtraction:
if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) return NULL;
Nothing guarantees that skb->len plus the reserve stays below tx_curr_size, and when it does not the subtraction wraps around to a huge value, the check passes, and the skb_put_zero() of max_ndp_size bytes that follows overruns the NTB:
skbuff: skb_over_panic: text:ffff80000db33558 len:428 put:172 head:ffff0000c2c66100 tail:0x1ac end:0x140
kernel BUG at net/core/skbuff.c:200
skb_put_zero include/linux/skbuff.h:2595 [inline] cdc_ncm_ndp16 drivers/net/usb/cdc_ncm.c:1132 [inline] cdc_ncm_fill_tx_frame+0xdf0/0x30e0 drivers/net/usb/cdc_ncm.c:1309
Here tx_curr_size is 0x140 = 320, skb->len is already 256 and the skb_put_zero() wants another 172 bytes.
Two device controlled settings make this reachable:
- dwNtbOutMaxSize = 320 caps tx_max at 320. The lower bound computed in cdc_ncm_check_tx_max() is max_datagram_size + max_ndp_size + the NTH header, but cdc_ncm_setup() clamps tx_max before cdc_ncm_set_dgram_size() runs, so max_datagram_size is still 0 and the bound is only max_ndp_size + the NTH header. It does not reserve room for one datagram plus one NDP.
- wNdpOutAlignment = 256 is accepted by cdc_ncm_fix_modulus() as long as it is smaller than tx_max, and cdc_ncm_align_tail() then pads the 12 byte NTH header up to 256 bytes right before this check.
An NDP can also be added to an NTB that already holds datagrams through cdc_mbim_tx_fixup(), which uses a different signature per MBIM session. On plain cdc_ncm the chain lookup in cdc_ncm_ndp16() returns the existing NDP for the single signature, so there the create path is normally reached for the first datagram of each NTB.
Rewrite the test as an addition, which cannot underflow and gives the same answer whenever the original subtraction did not wrap.
--- drivers/net/usb/cdc_ncm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/usb/cdc_ncm.c +2 -2
@@ -1125,7 +1125,7 @@ static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp16(struct cdc_ncm_ctx *ctx, struct scdc_ncm_align_tail (skb, ctx->tx_ndp_modulus,0 , ctx->tx_curr_size);/* verify that there is room for the NDP and the datagram (reserve) */ -if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) +if (skb->len + reserve + ctx->max_ndp_size > ctx->tx_curr_size)return NULL ;/* link to it */
@@ -1180,7 +1180,7 @@ static struct usb_cdc_ncm_ndp32 *cdc_ncm_ndp32(struct cdc_ncm_ctx *ctx, struct scdc_ncm_align_tail (skb, ctx->tx_ndp_modulus,0 , ctx->tx_curr_size);/* verify that there is room for the NDP and the datagram (reserve) */ -if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) +if (skb->len + reserve + ctx->max_ndp_size > ctx->tx_curr_size)return NULL ;/* link to it */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 546/1005 net/mlx5e: IPsec, dont match upper proto selectors in crypto offload TX
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit 5ed47bd79cebee8429d06c6640aac7ac7c4805ca ]
The mentioned commit introduced support for upper protocol selectors (protocol & ports) to mlx5 IPsec offload. In crypto offload mode this causes offloaded TX SAs to stop matching traffic.
In tx_add_rule(), setup_fte_upper_proto_match() is called for all offload types and programs a match on the upper protocol (TCP/UDP) and ports. For crypto offload, setup_fte_esp() is then called and sets ip_protocol to ESP. The resulting rule requires both ESP as the IP protocol and TCP/UDP ports, which no packet can satisfy, so TX crypto offload silently stops working for such SAs.
In crypto offload mode the stack builds the ESP packet and the HW only encrypts it, so the SA rule should only match on the SPI. Move the setup_fte_upper_proto_match() call under the XFRM_DEV_OFFLOAD_PACKET case, where the rule matches the plaintext packet and upper protocol selectors apply.
The other three callers are unaffected: rx_add_rule_sa_selector() is already only invoked for packet offload, and tx_add_policy() / rx_add_policy() are only reachable in packet offload mode, since xfrm policy offload is exclusively of type XFRM_DEV_OFFLOAD_PACKET.
--- drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +1 -1
@@ -2194,7 +2194,6 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry) }setup_fte_no_frags (spec); -setup_fte_upper_proto_match (spec, &attrs->upspec);switch (attrs->type) {case XFRM_DEV_OFFLOAD_CRYPTO :
@@ -2207,6 +2206,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)setup_fte_reg_a (spec);break ;case XFRM_DEV_OFFLOAD_PACKET : +setup_fte_upper_proto_match (spec, &attrs->upspec);setup_fte_reg_c4 (spec, attrs->reqid); err =setup_pkt_reformat (ipsec, attrs, &flow_act);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 547/1005 net/mlx5e: Rename state_destroy to rx_mode_active in flow steering
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Lazar <[email protected]>
[ Upstream commit cdcb648a97ebc247eea3a9a7d15916613f640527 ]
This flag controls the enablement of RX mode handling (promisc, allmulti, broadcast, netdev addr sync). It acts as a safeguard that prevents new FS (flow steering) operations during device teardown. When the device is in destroying state it is set to false to indicate RX mode operations are not allowed. Its name is misleading, as it suggests a destroy-state flag rather than RX mode activity. Rename it for clarity.
No functional change.
Stable-dep-of: 3962ded998c1 ("net/mlx5e: Fix false WARN_ON_ONCE in flow steering cleanup on RX init failure")
--- drivers/net/ethernet/mellanox/mlx5/core/en/fs.h | 5 +++-- drivers/net/ethernet/mellanox/mlx5/core/en_fs.c | 17 +++++++++-------- .../net/ethernet/mellanox/mlx5/core/en_main.c | 15 +++++++++------ 3 files changed, 21 insertions(+), 16 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +3 -2
@@ -158,7 +158,7 @@ void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,struct mlx5e_flow_steering *mlx5e_fs_init (const struct mlx5e_profile *profile,struct mlx5_core_dev *mdev, -bool state_destroy, +bool rx_mode_active,struct dentry *dfs_root);void mlx5e_fs_cleanup (struct mlx5e_flow_steering *fs);struct mlx5e_vlan_table *mlx5e_fs_get_vlan (struct mlx5e_flow_steering *fs);
@@ -198,7 +198,8 @@ void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp);struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp (struct mlx5e_flow_steering *fs);void mlx5e_fs_set_accel_tcp (struct mlx5e_flow_steering *fs,struct mlx5e_accel_fs_tcp *accel_tcp);#endif -void mlx5e_fs_set_state_destroy (struct mlx5e_flow_steering *fs,bool state_destroy); +void mlx5e_fs_set_rx_mode_active (struct mlx5e_flow_steering *fs, +bool rx_mode_active);void mlx5e_fs_set_vlan_strip_disable (struct mlx5e_flow_steering *fs,bool vlan_strip_disable);struct mlx5_core_dev *mlx5e_fs_get_mdev (struct mlx5e_flow_steering *fs);
drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +9 -8
@@ -44,7 +44,7 @@struct mlx5e_flow_steering {struct work_struct set_rx_mode_work; -bool state_destroy; +bool rx_mode_active;bool vlan_strip_disable;struct mlx5_core_dev *mdev;struct mlx5_flow_namespace *ns;
@@ -560,7 +560,7 @@ static void mlx5e_del_vlan_rules(struct mlx5e_flow_steering *fs)for_each_set_bit (i, fs->vlan->active_svlans,VLAN_N_VID )mlx5e_fs_del_vlan_rule (fs,MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID , i); -WARN_ON_ONCE (fs->state_destroy); +WARN_ON_ONCE (fs->rx_mode_active);mlx5e_remove_vlan_trap (fs);
@@ -743,7 +743,7 @@ static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,mlx5e_for_each_hash_node (hn, tmp, fs->l2.netdev_mc, i) hn->action =MLX5E_ACTION_DEL ; -if (fs->state_destroy) +if (fs->rx_mode_active)mlx5e_sync_netdev_addr (fs, netdev, uc, mc);mlx5e_apply_netdev_addr (fs);
@@ -840,7 +840,7 @@ void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, goto update_vport_context; } -bool rx_mode_enable = fs->state_destroy; +bool rx_mode_enable = fs->rx_mode_active;bool promisc_enabled = rx_mode_enable && (netdev->flags &IFF_PROMISC );bool allmulti_enabled = rx_mode_enable && (netdev->flags &IFF_ALLMULTI );bool broadcast_enabled = rx_mode_enable;
@@ -1479,7 +1479,7 @@ static void mlx5e_fs_debugfs_init(struct mlx5e_flow_steering *fs,struct mlx5e_flow_steering *mlx5e_fs_init (const struct mlx5e_profile *profile,struct mlx5_core_dev *mdev, -bool state_destroy, +bool rx_mode_active,struct dentry *dfs_root) {struct mlx5e_flow_steering *fs;
@@ -1490,7 +1490,7 @@ struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile, goto err; fs->mdev = mdev; - fs->state_destroy = state_destroy; + fs->rx_mode_active = rx_mode_active;if (mlx5e_profile_feature_cap (profile,FS_VLAN )) { err =mlx5e_fs_vlan_alloc (fs);if (err)
@@ -1606,9 +1606,10 @@ void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_f }#endif -void mlx5e_fs_set_state_destroy (struct mlx5e_flow_steering *fs,bool state_destroy) +void mlx5e_fs_set_rx_mode_active (struct mlx5e_flow_steering *fs, +bool rx_mode_active) { - fs->state_destroy = state_destroy; + fs->rx_mode_active = rx_mode_active; } void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs,
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +9 -6
@@ -6559,8 +6559,9 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)clear_bit (MLX5E_STATE_DESTROYING , &priv->state);if (priv->fs) -mlx5e_fs_set_state_destroy (priv->fs, - !test_bit (MLX5E_STATE_DESTROYING , &priv->state)); +mlx5e_fs_set_rx_mode_active (priv->fs, + !test_bit (MLX5E_STATE_DESTROYING , + &priv->state));/* Validate the max_wqe_size_sq capability. */ if (WARN_ON_ONCE (mlx5e_get_max_sq_wqebbs (priv->mdev) <MLX5E_MAX_TX_WQEBBS )) {
@@ -6640,8 +6641,9 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)mlx5e_reset_channels (priv->netdev);set_bit (MLX5E_STATE_DESTROYING , &priv->state);if (priv->fs) -mlx5e_fs_set_state_destroy (priv->fs, - !test_bit (MLX5E_STATE_DESTROYING , &priv->state)); +mlx5e_fs_set_rx_mode_active (priv->fs, + !test_bit (MLX5E_STATE_DESTROYING , + &priv->state));cancel_work_sync (&priv->update_stats_work);return err; }
@@ -6652,8 +6654,9 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv)set_bit (MLX5E_STATE_DESTROYING , &priv->state);if (priv->fs) -mlx5e_fs_set_state_destroy (priv->fs, - !test_bit (MLX5E_STATE_DESTROYING , &priv->state)); +mlx5e_fs_set_rx_mode_active (priv->fs, + !test_bit (MLX5E_STATE_DESTROYING , + &priv->state));if (profile->disable) profile->disable (priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 548/1005 net/mlx5e: Fix false WARN_ON_ONCE in flow steering cleanup on RX init failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Lazar <[email protected]>
[ Upstream commit 3962ded998c1df8a449fdf986f44f478e9c09675 ]
mlx5e_attach_netdev() sets rx_mode_active before calling init_rx(), so any init_rx() failure after mlx5e_create_flow_steering() has succeeded makes mlx5e_destroy_flow_steering() trip WARN_ON_ONCE(fs->rx_mode_active) in mlx5e_del_vlan_rules().
Hit in internal regression testing, so kthread creation failed with -EINTR:
WARNING: CPU: 3 PID: 170 at drivers/net/ethernet/mellanox/mlx5/core/en_fs.c:564 mlx5e_del_vlan_rules+0x295/0x2b0 [mlx5_core] mlx5e_destroy_flow_steering+0x34/0xc0 [mlx5_core] mlx5e_init_nic_rx+0x137/0x200 [mlx5_core] mlx5e_attach_netdev+0x105/0x360 [mlx5_core]
Fix it by creating NIC flow steering with rx_mode_active cleared and setting it only after profile->init_rx() succeeds. This also lets the internal error paths of mlx5e_create_flow_steering() destroy partially created steering without warning. The flag is set in mlx5e_attach_netdev() rather than mlx5e_init_nic_rx() so that non-NIC profiles, such as representors, also get it set after a detach/attach cycle.
--- .../net/ethernet/mellanox/mlx5/core/en_main.c | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +9 -14
@@ -6039,9 +6039,7 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev, priv->dfs_root =debugfs_create_dir ("nic" ,mlx5_debugfs_get_dev_root (mdev)); - fs =mlx5e_fs_init (priv->profile, mdev, - !test_bit (MLX5E_STATE_DESTROYING , &priv->state), - priv->dfs_root); + fs =mlx5e_fs_init (priv->profile, mdev, false, priv->dfs_root);if (!fs) { err = -ENOMEM ;mlx5_core_err (mdev,"FS initialization failed, %d\n" , err);
@@ -6558,10 +6556,6 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)int err;clear_bit (MLX5E_STATE_DESTROYING , &priv->state); -if (priv->fs) -mlx5e_fs_set_rx_mode_active (priv->fs, - !test_bit (MLX5E_STATE_DESTROYING , - &priv->state));/* Validate the max_wqe_size_sq capability. */ if (WARN_ON_ONCE (mlx5e_get_max_sq_wqebbs (priv->mdev) <MLX5E_MAX_TX_WQEBBS )) {
@@ -6622,6 +6616,9 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)if (err) goto err_cleanup_tx; +if (priv->fs) +mlx5e_fs_set_rx_mode_active (priv->fs, true); +if (profile->enable) { err = profile->enable (priv);if (err)
@@ -6633,6 +6630,10 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)return 0 ; err_cleanup_rx: +if (priv->fs) { +mlx5e_fs_set_rx_mode_active (priv->fs, false); +cancel_work_sync (&priv->set_rx_mode_work); + } profile->cleanup_rx (priv); err_cleanup_tx: profile->cleanup_tx (priv);
@@ -6640,10 +6641,6 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) out:mlx5e_reset_channels (priv->netdev);set_bit (MLX5E_STATE_DESTROYING , &priv->state); -if (priv->fs) -mlx5e_fs_set_rx_mode_active (priv->fs, - !test_bit (MLX5E_STATE_DESTROYING , - &priv->state));cancel_work_sync (&priv->update_stats_work);return err; }
@@ -6654,9 +6651,7 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv)set_bit (MLX5E_STATE_DESTROYING , &priv->state);if (priv->fs) -mlx5e_fs_set_rx_mode_active (priv->fs, - !test_bit (MLX5E_STATE_DESTROYING , - &priv->state)); +mlx5e_fs_set_rx_mode_active (priv->fs, false);if (profile->disable) profile->disable (priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/1005 net: phy: c45: select BASE-T1 type for the forced speed
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iustin Stolniceanu <[email protected]>
[ Upstream commit df501db9b18fae4d3edd534b992675f4673a938e ]
Commit 25108a834e14 ("net: phy: c45: add support for 1000BASE-T1 forced setup") made genphy_c45_pma_setup_forced() write the type selection field (bits 3:0) of the BASE-T1 PMA/PMD control register (1.2100) on every forced setup: 1000BASE-T1 for SPEED_1000, and 0 for everything else. 0 selects 100BASE-T1, so forcing a 10BASE-T1L PHY to 10 Mbit/s now also switches its PMA to 100BASE-T1, a mode it does not implement.
Seen on an ADIN1110 (internal ADIN1100 PHY): after
ethtool -s ethX autoneg off speed 10 master-slave forced-master
1.2100 reads 0xc000 instead of the 0xc002. Since the field is not restored by re-enabling autoneg, the PHY keeps the wrong type until the next forced setup or reset.
Add a helper that returns the type selection value for the forced speed and the supported link modes: 100BASE-T1, 1000BASE-T1, and 10BASE-T1L or 10BASE-T1S for SPEED_10 depending on the supported 10 Mbit/s modes. Fail with -EINVAL when no type matches instead of writing 100BASE-T1. This also applies to forced 2.5G, 5G and 10G on BASE-T1 capable PHYs, for which there are no link modes yet.
The field is called "type selection" in IEEE 802.3-2022 (45.2.1.214, Table 45-178). Keep the old STRAP names as aliases.
Tested on EVAL-ADIN1110EBZ: with this change, forcing 10 Mbit/s writes 1.2100 = 0xc002 (10BASE-T1L) instead of the invalid 0xc000.
--- drivers/net/phy/phy-c45.c | 46 ++++++++++++++++++++++++++++++++++----- include/uapi/linux/mdio.h | 13 +++++++++-- 2 files changed, 52 insertions(+), 7 deletions(-)
drivers/net/phy/phy-c45.c +41 -5
@@ -104,6 +104,36 @@ int genphy_c45_pma_baset1_setup_master_slave(struct phy_device *phydev) }EXPORT_SYMBOL_GPL (genphy_c45_pma_baset1_setup_master_slave); +/* Type selection value for the BASE-T1 PMA/PMD control register (1.2100, +* 802.3-2022 Table 45-178) matching the forced speed. 10 Mbit/s is ambiguous +* between 10BASE-T1L and 10BASE-T1S, so the supported link modes decide. +* 2.5G, 5G and 10GBASE-T1 are not handled as there are no link modes for them +* yet. +*/ +static int genphy_c45_baset1_type_sel (struct phy_device *phydev) +{ +switch (phydev->speed) { +case SPEED_10 : +if (linkmode_test_bit (ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, + phydev->supported)) +return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1L ; +if (linkmode_test_bit (ETHTOOL_LINK_MODE_10baseT1S_Full_BIT, + phydev->supported) || +linkmode_test_bit (ETHTOOL_LINK_MODE_10baseT1S_Half_BIT, + phydev->supported) || +linkmode_test_bit (ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT, + phydev->supported)) +return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1S ; +return -EINVAL ; +case SPEED_100 : +return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_100BT1 ; +case SPEED_1000 : +return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_1000BT1 ; +default : +return -EINVAL ; + } +} +/** * genphy_c45_pma_setup_forced - configures a forced speed * @phydev: target phy_device struct
@@ -166,6 +196,16 @@ int genphy_c45_pma_setup_forced(struct phy_device *phydev)return -EINVAL ; } +/* Resolve the type before the first write, so a speed without a +* matching type leaves the PHY untouched. +*/ + bt1_ctrl =0 ; +if (genphy_c45_baset1_able (phydev)) { + bt1_ctrl =genphy_c45_baset1_type_sel (phydev); +if (bt1_ctrl <0 ) +return bt1_ctrl; + } + ret =phy_write_mmd (phydev,MDIO_MMD_PMAPMD ,MDIO_CTRL1 , ctrl1);if (ret <0 )return ret;
@@ -179,12 +219,8 @@ int genphy_c45_pma_setup_forced(struct phy_device *phydev)if (ret <0 )return ret; - bt1_ctrl =0 ; -if (phydev->speed ==SPEED_1000 ) - bt1_ctrl =MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000 ; - ret =phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,MDIO_PMA_PMD_BT1_CTRL , -MDIO_PMA_PMD_BT1_CTRL_STRAP , bt1_ctrl); +MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL , bt1_ctrl);if (ret <0 )return ret; }
include/uapi/linux/mdio.h +11 -2
@@ -417,8 +417,17 @@#define MDIO_AN_10BT1_AN_STAT_LPA_EEE_T1L 0x4000/* 10BASE-T1L LP EEE ability advertisement */ /* BASE-T1 PMA/PMD control register */ -#define MDIO_PMA_PMD_BT1_CTRL_STRAP 0x000F/* Type selection (Strap) */ -#define MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000 0x0001/* Select 1000BASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL 0x000F/* Type selection */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_100BT1 0x0000/* Select 100BASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_1000BT1 0x0001/* Select 1000BASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1L 0x0002/* Select 10BASE-T1L */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1S 0x0003/* Select 10BASE-T1S */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_2P5GBT1 0x0004/* Select 2.5GBASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_5GBT1 0x0005/* Select 5GBASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10GBT1 0x0006/* Select 10GBASE-T1 */ +/* Legacy names, kept for userspace */ +#define MDIO_PMA_PMD_BT1_CTRL_STRAP MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL +#define MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000 MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_1000BT1#define MDIO_PMA_PMD_BT1_CTRL_CFG_MST 0x4000/* MASTER-SLAVE config value */ /* 1000BASE-T1 PCS control register */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 550/1005 tls: Break the connection after a burst of empty data records
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 201f0531e413d6cdd9673a77bea340839e1713ae ]
TLS permits zero-length application_data records, and RFC 8446 suggests them for generating cover traffic. Nothing bounds how many of them a reader processes back to back, though. They advance neither loop bound in tls_sw_recvmsg() and tls_sw_read_sock(), so a peer streaming them faster than the reader decrypts them keeps it in the kernel for as long as they arrive. recvmsg() does not check for signals while records are ready, and its peek and async paths queue every empty record on rx_list. read_sock consumers like nvme-tcp hold the socket lock throughout and never get control back.
Break the connection once a reader decrypts more than 128 consecutive empty data records without sleeping or returning to its caller in between, treating the burst as a protocol violation like a malformed record header. A stream of empty records which the reader keeps up with costs no more than any other traffic, so the count starts over on every read and whenever the reader waits for the next record. The strparser is stopped before it parses the next record, so the reader gets the error from tls_rx_rec_wait() and no later record is delivered. Returning to the caller and keeping the connection alive would need a way to wake read_sock consumers which installed their own sk_data_ready after the handshake, a lot of code for a peer that is either broken or malicious.
Consume empty records in recvmsg() rather than queuing them on rx_list, so that repeated MSG_PEEK cannot pile them up past the per-read count. Decrypt them synchronously, too. Once a recvmsg() call has decrypted a record asynchronously, recv_end replaces the error with the result of process_rx_list(), so a call that saw only empty records returns 0, a false EOF, instead of the error or -EAGAIN.
--- include/net/tls.h | 1 + net/tls/tls_sw.c | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-)
include/net/tls.h +1 -0
@@ -139,6 +139,7 @@ struct tls_sw_context_rx { u8 zc_capable:1; u8 reader_contended:1;bool key_update_pending; +u8 empty_run;struct tls_strparser strp;
net/tls/tls_sw.c +25 -4
@@ -1153,6 +1153,7 @@ tls_rx_rec_wait(struct sock *sk, bool nonblock, bool released, bool has_copied)if (!timeo)return -EAGAIN ; + ctx->empty_run =0 ; released = true;add_wait_queue (sk_sleep (sk), &wait);sk_set_bit (SOCKWQ_ASYNC_WAITDATA , sk);
@@ -1572,6 +1573,7 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg, struct tls_decrypt_arg *darg) {struct tls_context *tls_ctx =tls_get_ctx (sk); +struct tls_sw_context_rx *ctx =tls_sw_ctx_rx (tls_ctx);struct tls_prot_info *prot = &tls_ctx->prot_info;struct strp_msg *rxm;int err;
@@ -1589,6 +1591,19 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg, rxm->full_len -= prot->overhead_size;tls_advance_record_sn (sk, prot, &tls_ctx->rx); +/* A peer may send empty data records, e.g. as cover traffic, but +* a burst of them traps the reader in the kernel. Treat more than +* 128 in a row, without the reader sleeping or returning to the +* caller in between, as a protocol violation. Stop the strparser +* before the next record gets parsed, so the reader finds the +* error in tls_rx_rec_wait(). +*/ +if (rxm->full_len || +tls_msg (darg->skb)->control !=TLS_RECORD_TYPE_DATA ) + ctx->empty_run =0 ; +else if (unlikely (++ctx->empty_run >128 )) +tls_strp_abort_strp (&ctx->strp, -EBADMSG ); +return tls_check_pending_rekey (sk, tls_ctx, darg->skb); }
@@ -1768,6 +1783,7 @@ static int tls_rx_reader_acquire(struct sock *sk, struct tls_sw_context_rx *ctx, }WRITE_ONCE (ctx->reader_present,1 ); + ctx->empty_run =0 ;return 0 ; }
@@ -1881,9 +1897,11 @@ int tls_sw_recvmsg(struct sock *sk, tlm->control == TLS_RECORD_TYPE_DATA) darg.zc = true; -/* Do not use async mode if record is non-data */ +/* Do not use async mode if record is non-data or empty, +* recv_end would report an error after empty records as EOF. +*/ if (tlm->control ==TLS_RECORD_TYPE_DATA ) - darg.async = ctx->async_capable; + darg.async = ctx->async_capable && to_decrypt;else darg.async = false;
@@ -1925,7 +1943,10 @@ int tls_sw_recvmsg(struct sock *sk,DEBUG_NET_WARN_ON_ONCE (darg.skb == ctx->strp.anchor); -if (async) { +/* Consume empty records, even when peeking, so that +* they cannot pile up on rx_list. +*/ +if (async && chunk) {/* TLS 1.2-only, to_decrypt must be text len */ chunk =min_t (int, to_decrypt, len); async_copy_bytes += chunk;
@@ -1946,7 +1967,7 @@ int tls_sw_recvmsg(struct sock *sk,if (err <0 ) goto put_on_rx_list_err; -if (is_peek) { +if (is_peek && chunk) { peeked += chunk; goto put_on_rx_list; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 551/1005 tls: Consume empty data records in tls_sw_splice_read()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit db6a6c6863bd22b2543e313cb8e4807fdd33778b ]
A zero-length application_data record decrypts to full_len == 0, so tls_sw_splice_read() splices zero bytes and returns zero. A zero return from a splice read means EOF, and the caller tears down a connection that is still live.
Consume the record and fetch the next one, as tls_sw_read_sock() does. The cap on consecutive empty records bounds the loop.
When an empty record precedes a close_notify, splice(2) now returns -EINVAL from the control-record test instead of a false EOF. A splice that reaches an alert record already reports -EINVAL.
--- net/tls/tls_sw.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-)
net/tls/tls_sw.c +28 -20
@@ -2051,32 +2051,40 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,if (err) goto splice_read_end; -if (!skb_queue_empty (&ctx->rx_list)) { - skb =__skb_dequeue (&ctx->rx_list); - }else { -struct tls_decrypt_arg darg; +for (;;) { +if (!skb_queue_empty (&ctx->rx_list)) { + skb =__skb_dequeue (&ctx->rx_list); + }else { +struct tls_decrypt_arg darg; - err =tls_rx_rec_wait (sk, nonblock, true, false); -if (err <=0 ) - goto splice_read_end; + err =tls_rx_rec_wait (sk, nonblock, true, false); +if (err <=0 ) + goto splice_read_end; -memset (&darg.inargs,0 ,sizeof (darg.inargs)); +memset (&darg.inargs,0 ,sizeof (darg.inargs)); - err =tls_rx_one_record (sk,NULL , &darg); -if (err <0 ) - goto splice_read_end; + err =tls_rx_one_record (sk,NULL , &darg); +if (err <0 ) + goto splice_read_end; -tls_rx_rec_done (ctx); - skb = darg.skb; - } +tls_rx_rec_done (ctx); + skb = darg.skb; + } - rxm =strp_msg (skb); - tlm =tls_msg (skb); + rxm =strp_msg (skb); + tlm =tls_msg (skb); -/* splice does not support reading control messages */ -if (tlm->control !=TLS_RECORD_TYPE_DATA ) { - err = -EINVAL ; - goto splice_requeue; +/* splice does not support reading control messages */ +if (tlm->control !=TLS_RECORD_TYPE_DATA ) { + err = -EINVAL ; + goto splice_requeue; + } + +/* Splicing zero bytes would read as EOF */ +if (rxm->full_len) +break ; + +consume_skb (skb); } chunk = min_t(unsigned int, rxm->full_len, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 552/1005 selftests: tls: Skip the zero_len tests when TLS is unavailable
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 77389a6d30a262fa94d427c03a393c05c013665c ]
FIXTURE_SETUP(zero_len) returns early when ulp_sock_pair() reports that the TCP_ULP setsockopt failed, so on a kernel built without CONFIG_TLS the TLS_RX setsockopt never runs. TEST_F(zero_len, test) then sends its raw records over a plain TCP socket, which returns the ciphertext verbatim. All eight variants FAIL on a machine that lacks TLS, and those failures mask any real regression in the same run.
Skip the test when the fixture recorded notls, as the other fixtures in this file do.
--- tools/testing/selftests/net/tls.c | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/net/tls.c +3 -0
@@ -2639,6 +2639,9 @@ TEST_F(zero_len, test)int rec_off;int i; +if (self->notls) +SKIP (return,"no TLS support" ); +for (i =0 ; i <4 && variant->recs[i]; i++) EXPECT_EQ(send(self->fd, variant->recs[i]->cipher_data, variant->recs[i]->cipher_len, 0),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 553/1005 nsh: limit recursion in nsh_gso_segment()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 3921fb102d78a6d7aa61b8d273e097a1a8026b90 ]
nsh_gso_segment() calls skb_mac_gso_segment() for the inner packet, which calls nsh_gso_segment() again when the next protocol is NSH, either directly or behind an inner Ethernet header (ETH_P_TEB).
Nothing limits the depth: a GSO packet made of stacked 8-byte NSH headers recurses once per header, and a 64KB packet can hold about 8000 of them, overflowing the kernel stack.
Such a packet can be injected with a packet socket using PACKET_VNET_HDR, or with tun/tap or virtio_net, as nothing checks that a GSO packet with VIRTIO_NET_HDR_F_NEEDS_CSUM carries the protocol it claims. It is then segmented in software if the output device does not support the GSO type:
BUG: TASK stack guard page was hit at ffffcad5c0ab3ff8 (stack is ffffcad5c0ab4000..ffffcad5c0ab8000) Oops: stack guard page: 0000 [#1] SMP NOPTI CPU: 3 UID: 0 PID: 337 Comm: nsh_gso Tainted: G E 7.4.0-rc1+ #118 PREEMPT(lazy) RIP: 0010:lock_acquire (kernel/locking/lockdep.c:5902) Call Trace: <TASK> skb_mac_gso_segment (include/linux/rcupdate.h:309 include/linux/rcupdate.h:849 net/core/gso.c:50) nsh_gso_segment (net/nsh/nsh.c:110) nsh skb_mac_gso_segment (net/core/gso.c:53) nsh_gso_segment (net/nsh/nsh.c:110) nsh [...] skb_mac_gso_segment (net/core/gso.c:53) __skb_gso_segment (net/core/gso.c:129) validate_xmit_skb (net/core/dev.c:4238) __dev_queue_xmit (net/core/dev.c:5087) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189) __sys_sendto (net/socket.c:800 net/socket.c:818 net/socket.c:2283) __x64_sys_sendto (net/socket.c:2290 net/socket.c:2286 net/socket.c:2286) do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:84) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Use gso_recursion_inc_test(), added in commit 006c8b834aed ("net: gso:
limit recursive IP-in-IP segmentation"), with the same limit as IPv4 and IPv6. The counter is shared with them: a packet with four NSH headers in front of an IPv4 header is still segmented, one more NSH header and it is dropped.
The NSH -> ETH_P_TEB -> NSH route is covered as well, as each round goes through nsh_gso_segment().
--- include/net/gso.h | 2 +- net/nsh/nsh.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
include/net/gso.h +1 -1
@@ -19,7 +19,7 @@ struct skb_gso_cb {int encap_level;__wsum csum;__u16 csum_start; -/* Number of IPv4/IPv6 GSO handler entries for this packet. */ +/* Number of IPv4/IPv6/NSH GSO handler entries for this packet. */ u8 recursion_counter; };#define SKB_GSO_CB_OFFSET 32
net/nsh/nsh.c +7 -0
@@ -9,6 +9,7 @@#include <linux/netdevice.h> #include <linux/skbuff.h> #include <net/gso.h> +#include <net/ip_tunnels.h> #include <net/nsh.h> #include <net/tun_proto.h>
@@ -84,6 +85,12 @@ static struct sk_buff *nsh_gso_segment(struct sk_buff *skb,skb_reset_network_header (skb); +/* NSH can carry NSH (directly, or in an inner Ethernet frame): +* limit the recursion, as IPv4 and IPv6 do. +*/ +if (unlikely (gso_recursion_inc_test (skb,IP_TUNNEL_RECURSION_LIMIT ))) + goto out; + outer_proto = skb->protocol; outer_hlen =skb_mac_header_len (skb); mac_len = skb->mac_len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 554/1005 tracing: skip boot kprobe setup when no events were requested
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenwen Fu <[email protected]>
[ Upstream commit 2388a673e9276de30c7e917fce50830e497d46cc ]
setup_boot_kprobe_events() calls enable_boot_kprobe_events() even when the kprobe_event= boot parameter was not supplied. That call takes event_mutex without any command-line probes to enable.
Asynchronous eval-map updates also hold event_mutex. A normal boot can therefore wait in init_kprobe_trace() for this background work despite having no boot probes to set up.
Return early when the boot-event buffer is empty. Keep the mutex protection in trace_event_update_all() and retain setup for explicit kprobe_event= parameters. Bootconfig handles its own probe enablement, and the existing trace_eval_sync() still waits for background work before init memory is freed.
--- kernel/trace/trace_kprobe.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_kprobe.c +3 -0
@@ -2017,6 +2017,9 @@ static __init void setup_boot_kprobe_events(void)char *p, *cmd = kprobe_boot_events_buf;int ret; +if (!kprobe_boot_events_buf[0 ]) +return ; +strreplace (kprobe_boot_events_buf,',' ,' ' );while (cmd && *cmd !='\0' ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 555/1005 docs, kprobes: Fix bracket
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manuel Ebner <[email protected]>
[ Upstream commit b91a5c16996d089cd07ceaf33b5a621cb94c2c2f ]
Remove needless ')'
--- Documentation/trace/kprobes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/trace/kprobes.rst +1 -1
@@ -31,7 +31,7 @@ can trap at almost any kernel code address [1]_, specifying a handler routine to be invoked when the breakpoint is hit. .. [1] some parts of the kernel code can not be trapped, see - :ref:`kprobes_blacklist`) + :ref:`kprobes_blacklist` There are currently two types of probes: kprobes, and kretprobes (also called return probes). A kprobe can be inserted on virtually
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/1005 KEYS: do not let an unmatched key decide the search result
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixiong Wei <[email protected]>
[ Upstream commit 143fe160178c73e43575bff4890d23f84e37146d ]
With the dns_resolver key type available, put a key named "foo" in a fresh session keyring, revoke it, and search for "bar":
keyctl new_session >/dev/null A=$(printf '127.0.0.1\0' | keyctl padd dns_resolver foo @s) keyctl revoke "$A" keyctl search @s dns_resolver bar
Results:
keyctl_search: Key has been revoked
The search returns -EKEYREVOKED even though there is no key named "bar". It should return -ENOKEY.
A dns_resolver search walks the keys in the keyring and uses dns_resolver_cmp() to compare their descriptions with the requested name. When keyring_search_iterator() sees the revoked "foo" key, it records -EKEYREVOKED in ctx->result and skips the key before comparing its description. The search continues, but without a match it returns the error recorded for "foo".
Call the match callback before checking for invalidated, revoked or expired keys. A nonmatching key then leaves ctx->result alone.
--- security/keys/keyring.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
security/keys/keyring.c +6 -6
@@ -598,6 +598,12 @@ static int keyring_search_iterator(const void *object, void *iterator_data)return 0 ; } +/* A key the caller did not ask for must not decide the result. */ +if (!ctx->match_data.cmp (key, &ctx->match_data)) { +kleave (" = 0 [!match]" ); +return 0 ; + } +/* skip invalidated, revoked and expired keys */ if (ctx->flags &KEYRING_SEARCH_DO_STATE_CHECK ) {time64_t expiry =READ_ONCE (key->expiry);
@@ -617,12 +623,6 @@ static int keyring_search_iterator(const void *object, void *iterator_data) } } -/* keys that don't match */ -if (!ctx->match_data.cmp (key, &ctx->match_data)) { -kleave (" = 0 [!match]" ); -return 0 ; - } -/* key must have search permissions */ if (!(ctx->flags &KEYRING_SEARCH_NO_CHECK_PERM ) && key_task_permission(make_key_ref(key, ctx->possessed),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/1005 ALSA: aw2-alsa: select SND_PCM
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jude Gyimah <[email protected]>
[ Upstream commit bca568589ad118a9b0bac086760baee2a41976a5 ]
Several stanzas in sound/pci/Kconfig select SND_PCM. SND_AW2 selects nothing at all.
aw2-alsa calls snd_pcm_new, which sound/core/pcm.c provides under SND_PCM.
aw2-alsa.c:(.text+0x554): undefined reference to `snd_pcm_new'
4 symbols are undefined in all.
The driver can be built into vmlinux while SND_PCM is a module, in which case the symbols are not there at link time.
Select rather than depend on: SND_PCM has no prompt of its own and is only ever enabled by a select, so a depends on would leave SND_AW2 unselectable.
Reproduced on v7.3, arm64, with CONFIG_SND_AW2=y and CONFIG_SND_PCM=m.
Found with kreach, a static check that compares what Kconfig allows against the symbols the compiled objects actually reference.
--- sound/pci/Kconfig | 1 + 1 file changed, 1 insertion(+)
sound/pci/Kconfig +1 -0
@@ -141,6 +141,7 @@ config SND_AU8830 config SND_AW2 tristate "Emagic Audiowerk 2" + select SND_PCM help Say Y here to include support for Emagic Audiowerk 2 soundcards.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 558/1005 Xen/gnttab: improve error handling in gnttab_dma_{alloc,free}_pages()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Beulich <[email protected]>
[ Upstream commit 2b66f2cc753243a6adb3e9a5c038b0fc59ba7ec9 ]
Both decrease-reservation and populate-physmap can succeed partially. For the former this may be pretty unlikely, but clearly the latter can hit both out-of-memory conditions in the hypervisor or denial because of the allocation exceeding the domain's allowance (there's no interaction with the balloon driver here either).
In gnttab_dma_free_pages() we simply can't give back to the system what hasn't been re-filled with backing memory. For gnttab_dma_alloc_pages() both parts of the overall region need dealing with differently.
While no present caller of gnttab_dma_free_pages() checks its return value, also don't use -EFAULT there: It really is an out-of-memory condition. (In gnttab_dma_alloc_pages() -EFAULT doesn't look quite right either, but I couldn't think of a clearly better error code there.)
Message-ID: <[email protected]>
--- drivers/xen/grant-table.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/xen/grant-table.c +24 -1
@@ -1097,6 +1097,24 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) ret =xenmem_reservation_decrease (args->nr_pages, args->frames);if (ret != args->nr_pages) {pr_debug ("Failed to decrease reservation for DMA buffer\n" ); +if (ret >=0 ) { +/* Free the part where decrease didn't work. */ +size_t done = ret <<PAGE_SHIFT ; + +if (args->coherent) +dma_free_coherent (args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); +else +dma_free_wc (args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); + +if (!ret)/* Nothing else to do? */ +return -EFAULT ; + + args->nr_pages = ret; + } ret = -EFAULT ; goto fail; }
@@ -1130,7 +1148,12 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) ret =xenmem_reservation_increase (args->nr_pages, args->frames);if (ret != args->nr_pages) {pr_debug ("Failed to increase reservation for DMA buffer\n" ); - ret = -EFAULT ; +/* Can only free what has been re-filled. */ +if (!ret) +return -ENOMEM ; +if (ret >0 ) + args->nr_pages = ret; + ret = -ENOMEM ; }else { ret =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 559/1005 cpuset: generalize the validate_partition() interface
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridong Chen <[email protected]>
[ Upstream commit e234ed1bb82c96a5643fd70784f16cf3d72eeed3 ]
Refactor validate_partition() to take the parent partition, the new partition root state, the new effective exclusive CPUs and the CPUs to be deleted, instead of a trial cpuset. A NULL parent stands for a remote partition, whose CPUs come from top_cpuset. This makes the interface flexible enough to handle both local and remote partition validation.
This also fixes a false PERR_NOCPUS error when expanding a remote partition. The no CPU left for tasks check in partition_cpus_change() is done against the cgroup parent, but the CPUs of a remote partition come from top_cpuset, not from its parent. For example, on a 4-CPU system:
echo 2-3 > P/cpuset.cpus
echo 2-3 > P/cpuset.cpus.exclusive
echo 2-3 > P/C/cpuset.cpus
echo 2 > P/C/cpuset.cpus.exclusive
echo root > P/C/cpuset.cpus.partition
(a task in P)
echo 2-3 > P/C/cpuset.cpus.exclusive
cat P/C/cpuset.cpus.partition
root invalid (Parent is not a partition root)
The effective_cpus of P is 3, a subset of the new exclusive CPUs 2-3 of C, and P has a task, so the expansion is rejected. However, P is not a partition root and does not give any CPU to C, and top_cpuset still has CPUs 0-1 for the task. Enabling C directly with exclusive CPUs 2-3 succeeds, as remote_partition_enable() checks top_cpuset instead.
The no CPU left for tasks check now uses the given parent instead of parent_cs(cs), and top_cpuset for a remote partition, as that is where its CPUs are taken from.
The housekeeping conflict check is folded into validate_partition(). It is skipped when the parent is not a valid partition root, as @cs can't be a valid local partition in that case.
Use the new interface for local partition enablement in update_parent_effective_cpumask() and in partition_cpus_change(), replacing the open-coded checks there. The order of the checks is now the same for both paths: empty CPUs, housekeeping conflict, then no CPU left for tasks.
Add a test case to test_cpuset_prs.sh for the remote partition expansion above.
--- kernel/cgroup/cpuset.c | 119 +++++++++--------- .../selftests/cgroup/test_cpuset_prs.sh | 5 + 2 files changed, 64 insertions(+), 60 deletions(-)
kernel/cgroup/cpuset.c +59 -60
@@ -1511,6 +1511,48 @@ static bool prstate_housekeeping_conflict(int new_prs, int parent_prs,return res; } +/** +* validate_partition - Validate a cpuset partition configuration +* @cs: The cpuset to validate +* @parent: Parent partition of @cs, NULL for remote partition +* @new_prs: The proposed new partition root state +* @new_excpus: The new effective exclusive CPUs mask to validate +* @del: exclusive CPUs to be deleted from @cs, can be NULL +* +* A remote partition gets its CPUs from top_cpuset, so top_cpuset is used +* as the parent when @parent is NULL. +* +* The housekeeping check is skipped if @parent is not a valid partition +* root as @cs can't be a valid local partition in that case. +* +* Return: PRS error code (0 if valid, non-zero error code if invalid) +*/ +static enum prs_errcode validate_partition (struct cpuset *cs, +struct cpuset *parent,int new_prs, +struct cpumask *new_excpus, +struct cpumask *del) +{ +int parent_prs; + +if (new_prs ==PRS_MEMBER ) +return PERR_NONE ; + +if (cpumask_empty (new_excpus)) +return PERR_INVCPUS ; + +if (!parent) + parent = &top_cpuset; + parent_prs = parent->partition_root_state; +if (parent_prs >0 && +prstate_housekeeping_conflict (new_prs, parent_prs, new_excpus, del)) +return PERR_HKEEPING ; + +if (tasks_nocpu_error (parent, cs, new_excpus)) +return PERR_NOCPUS ; + +return PERR_NONE ; +} +/* * cpuset_update_sd_hk_unlock - Rebuild sched domains, update HK & unlock *
@@ -1921,18 +1963,10 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,if ((cmd == partcmd_enable) || (cmd == partcmd_enablei)) { new_prs = (cmd == partcmd_enable) ?PRS_ROOT :PRS_ISOLATED ; -/* -* Enabling partition root is not allowed if its -* effective_xcpus is empty. -*/ -if (cpumask_empty (tmp->delmask)) -return PERR_INVCPUS ; - -if (prstate_housekeeping_conflict (new_prs, parent_prs, tmp->delmask,NULL )) -return PERR_HKEEPING ; - -if (nocpu) -return PERR_NOCPUS ; + part_error =validate_partition (cs, parent, new_prs, + tmp->delmask,NULL ); +if (part_error) +return part_error;/* * This function will only be called when all the preliminary
@@ -2510,32 +2544,6 @@ static int parse_cpuset_cpulist(const char *buf, struct cpumask *out_mask)return 0 ; } -/** -* validate_partition - Validate a cpuset partition configuration -* @cs: The cpuset to validate -* @trialcs: The trial cpuset containing proposed configuration changes -* -* If any validation check fails, the appropriate error code is set in the -* cpuset's prs_err field. -* -* Return: PRS error code (0 if valid, non-zero error code if invalid) -*/ -static enum prs_errcode validate_partition (struct cpuset *cs,struct cpuset *trialcs) -{ -struct cpuset *parent =parent_cs (cs); - -if (cs_is_member (trialcs)) -return PERR_NONE ; - -if (cpumask_empty (trialcs->effective_xcpus)) -return PERR_INVCPUS ; - -if (tasks_nocpu_error (parent, cs, trialcs->effective_xcpus)) -return PERR_NOCPUS ; - -return PERR_NONE ; -} -/** * partition_cpus_change - Handle partition state changes due to CPU mask updates * @cs: The target cpuset being modified
@@ -2549,33 +2557,24 @@ static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialcs, struct tmpmasks *tmp) {enum prs_errcode prs_err; -int parent_prs =is_remote_partition (cs) - ?PRS_ROOT :parent_cs (cs)->partition_root_state; +struct cpuset *parent =is_remote_partition (cs) ?NULL :parent_cs (cs);if (cs_is_member (cs))return ; - prs_err =validate_partition (cs, trialcs); -if (!prs_err && (parent_prs >0 ) && - !cpumask_empty (trialcs->effective_xcpus)) { -int prs = cs->partition_root_state; - -/* -* Check for housekeeping conflict by passing the whole -* effective_xcpus as well as those CPUs that are to be -* removed from cs as delmask. -*/ -if (prs >0 ) -cpumask_andnot (tmp->delmask, cs->effective_xcpus, - trialcs->effective_xcpus); -else -cpumask_clear (tmp->delmask); - -if (prstate_housekeeping_conflict (prs, parent_prs, - trialcs->effective_xcpus, tmp->delmask)) - prs_err =PERR_HKEEPING ; - } +/* +* Check for housekeeping conflict by passing the whole +* effective_xcpus as well as those CPUs that are to be +* removed from cs as delmask. +*/ +if (is_partition_valid (cs)) +cpumask_andnot (tmp->delmask, cs->effective_xcpus, + trialcs->effective_xcpus); +else +cpumask_clear (tmp->delmask); + prs_err =validate_partition (cs, parent, trialcs->partition_root_state, + trialcs->effective_xcpus, tmp->delmask);if (prs_err) {WRITE_ONCE (cs->prs_err, prs_err); trialcs->prs_err = prs_err;
tools/testing/selftests/cgroup/test_cpuset_prs.sh +5 -0
@@ -556,6 +556,11 @@ REMOTE_TEST_MATRIX=( " C1-4:P1 C5-6 C1-2 . C5 . \ . P1 P1 . O5=0 . p1:3-4|p2:6|c11:1-2|c12:3-4|c21:6|c22:6 \ p1:P1|p2:P1|c11:P1" + # Expanding a remote partition should check top cpuset, not its member + # parent, for the no CPU left for tasks error. + " CX2-3:T . C2-3:X2:P1 . . . \ + . . X2-3 . . . p1:1,4-7|c11:2-3 \ + p1:P0|c11:P1" ) #
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 560/1005 tracing/eprobe: Install the trigger for every instance that enables the eprobe
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit be94710b1f6ba1bea33e73129c110af80e999b2d upstream.
The eprobe trigger lives in the instance of the enabling file, but it is only added when the eprobe is first enabled and only removed when the last file goes away. A second instance then records nothing, and the first instance's trigger is left behind once the eprobe is disabled there, so the eprobe can be deleted while that trigger still uses it.
Add and remove the trigger for each file. The file is never NULL here, so warn if it is and drop the dead perf paths.
--- kernel/trace/trace_eprobe.c | 58 ++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 39 deletions(-)
kernel/trace/trace_eprobe.c +19 -39
@@ -644,37 +644,32 @@ static int enable_trace_eprobe(struct tr {struct trace_probe *tp;struct trace_eprobe *ep; -bool enabled;int ret =0 ;int cnt =0 ; +if (WARN_ON_ONCE (!file)) +return -EINVAL ; + tp =trace_probe_primary_from_call (call);if (WARN_ON_ONCE (!tp))return -ENODEV ; - enabled =trace_probe_is_enabled (tp);/* This also changes "enabled" state */ -if (file) { - ret =trace_probe_add_file (tp, file); -if (ret) -return ret; - }else -trace_probe_set_flag (tp,TP_FLAG_PROFILE ); - -if (enabled) -return 0 ; + ret =trace_probe_add_file (tp, file); +if (ret) +return ret; +/* The trigger lives in the instance of the file, add it for each file */ for_each_trace_eprobe_tp (ep, tp) { ret =enable_eprobe (ep, file);if (ret)break ; - enabled = true; cnt++; }if (ret) {/* Failed to enable one of them. Roll back all */ -if (enabled) { +if (cnt) {/* * It's a bug if one failed for something other than memory * not being available but another eprobe succeeded.
@@ -687,10 +682,7 @@ static int enable_trace_eprobe(struct trbreak ; } } -if (file) -trace_probe_remove_file (tp, file); -else -trace_probe_clear_flag (tp,TP_FLAG_PROFILE ); +trace_probe_remove_file (tp, file); }return ret;
@@ -702,33 +694,21 @@ static int disable_trace_eprobe(struct tstruct trace_probe *tp;struct trace_eprobe *ep; +if (WARN_ON_ONCE (!file)) +return -EINVAL ; + tp =trace_probe_primary_from_call (call);if (WARN_ON_ONCE (!tp))return -ENODEV ; -if (file) { -if (!trace_probe_get_file_link (tp, file)) -return -ENOENT ; -if (!trace_probe_has_single_file (tp)) - goto out; -trace_probe_clear_flag (tp,TP_FLAG_TRACE ); - }else -trace_probe_clear_flag (tp,TP_FLAG_PROFILE ); - -if (!trace_probe_is_enabled (tp)) { -for_each_trace_eprobe_tp (ep, tp) -disable_eprobe (ep, file->tr); - } +if (!trace_probe_get_file_link (tp, file)) +return -ENOENT ; - out: -if (file) -/* -* Synchronization is done in below function. For perf event, -* file == NULL and perf_trace_event_unreg() calls -* tracepoint_synchronize_unregister() to ensure synchronize -* event. We don't need to care about it. -*/ -trace_probe_remove_file (tp, file); +for_each_trace_eprobe_tp (ep, tp) +disable_eprobe (ep, file->tr); + +/* Synchronization is done in below function. */ +trace_probe_remove_file (tp, file);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 561/1005 KEYS: Expand key->{datalen,quotalen} to unsigned int
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit 4a65eaf146f0d10ebaa88cfaef9c3b24f93766d9 upstream.
In key_alloc() and key_payload_reserve(), key->quotalen and key->datalen can receive values larger than USHRT_MAX.
Example:
keyctl new_session >/dev/null
owner=$(keyctl newring owner @s)
keeper=$(keyctl newring keeper @s)
for ((i=0; i<16384; i++)); do
key=$(keyctl add user "k$i" x "$keeper")
keyctl link "$key" "$owner"
done
awk -v uid="$(id -u):" '$1 == uid {print $NF}' /proc/key-users
keyctl clear "$owner"
awk -v uid="$(id -u):" '$1 == uid {print $NF}' /proc/key-usersBecause key->datalen wraps around 65535, the quota refunded upon clearing is truncated, causing quota bytes to leak in /proc/key-users.
Change the types of key->datalen and key->quotalen from unsigned short to unsigned int so that they can carry the full payload length without truncation.
--- fs/smb/client/cifsacl.c | 6 +++--- include/linux/key.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
fs/smb/client/cifsacl.c +3 -3
@@ -385,7 +385,7 @@ id_to_sid(unsigned int cid, uint sidtype goto out_revert_creds; }else if (sidkey->datalen <CIFS_SID_BASE_SIZE ) { rc =smb_EIO1 (smb_eio_trace_malformed_sid_key, sidkey->datalen); -cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%hu)\n" , +cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%u)\n" , __func__, sidkey->datalen); goto invalidate_key; }
@@ -403,7 +403,7 @@ id_to_sid(unsigned int cid, uint sidtypeif (ksid_size > sidkey->datalen) { rc =smb_EIO2 (smb_eio_trace_malformed_ksid_key, ksid_size, sidkey->datalen); -cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%hu, ksid_size=%u)\n" , +cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%u, ksid_size=%u)\n" , __func__, sidkey->datalen, ksid_size); goto invalidate_key; }
@@ -498,7 +498,7 @@ try_upcall_to_get_id:*/ BUILD_BUG_ON (sizeof (uid_t) !=sizeof (gid_t));if (sidkey->datalen !=sizeof (uid_t)) { -cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%hu)\n" , +cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%u)\n" , __func__, sidkey->datalen);key_invalidate (sidkey); goto out_key_put;
include/linux/key.h +2 -2
@@ -216,8 +216,8 @@ struct key {kuid_t uid;kgid_t gid;key_perm_t perm;/* access permissions */ -unsigned short quotalen;/* length added to quota */ -unsigned short datalen;/* payload data length +unsigned int quotalen;/* length added to quota */ +unsigned int datalen;/* payload data length * - may not match RCU dereferenced payload * - payload should contain own length */
Greg Kroah-Hartman
maintainerPATCH 562/1005 KEYS: Reject descriptions larger than KEY_MAX_DESC_SIZE
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit 094c53d2994975e36d4cab7cf5d9f34c1b0f1916 upstream.
KEY_MAX_DESC_SIZE includes the trailing NULL character. Descriptions generated from payloads and in-kernel paths bypass the userspace limit.
Reject descriptions at or above KEY_MAX_DESC_SIZE with -EINVAL at the following sites:
- key_alloc(): before quota calculation
- __key_create_or_update(): before key_set_index_key()
- keyring_search(): before match_preparse
- request_key_and_link(): before match_preparse
- request_key_rcu(): before check_cached_key()
--- include/linux/key.h | 3 +++ security/keys/key.c | 10 +++++++++- security/keys/keyctl.c | 2 -- security/keys/keyring.c | 7 ++++++- security/keys/request_key.c | 14 ++++++++++++-- 5 files changed, 30 insertions(+), 6 deletions(-)
include/linux/key.h +3 -0
@@ -37,6 +37,9 @@ struct net;#undef KEY_DEBUGGING +/* Maximum length of a key description, including the trailing NUL */ +#define KEY_MAX_DESC_SIZE 4096 +#define KEY_POS_VIEW 0x01000000/* possessor can view a key's attributes */ #define KEY_POS_READ 0x02000000/* possessor can read key payload / view keyring */ #define KEY_POS_WRITE 0x04000000/* possessor can update key payload / add link to keyring */
security/keys/key.c +9 -1
@@ -245,6 +245,8 @@ struct key *key_alloc(struct key_type *t } desclen =strlen (desc); +if (desclen >=KEY_MAX_DESC_SIZE ) + goto error; quotalen = desclen +1 + type->def_datalen;/* get hold of the key tracking for this user */
@@ -829,6 +831,7 @@ static key_ref_t __key_create_or_update(key_ref_t key_ref;int ret;struct key_restriction *restrict_link =NULL ; +size_t desclen;/* look up the key type to see if it's one of the registered kernel * types */
@@ -869,7 +872,12 @@ static key_ref_t __key_create_or_update(if (!index_key.description) goto error_free_prep; } - index_key.desc_len =strlen (index_key.description); + desclen =strlen (index_key.description); +if (desclen >=KEY_MAX_DESC_SIZE ) { + key_ref =ERR_PTR (-EINVAL ); + goto error_free_prep; + } + index_key.desc_len = desclen;key_set_index_key (&index_key); ret =__key_link_lock (keyring, &index_key);
security/keys/keyctl.c +0 -2
@@ -24,8 +24,6 @@#include <keys/request_key_auth-type.h> #include "internal.h" -#define KEY_MAX_DESC_SIZE 4096 -static const unsigned char keyrings_capabilities[2 ] = { [0] = (KEYCTL_CAPS0_CAPABILITIES | (IS_ENABLED(CONFIG_PERSISTENT_KEYRINGS) ? KEYCTL_CAPS0_PERSISTENT_KEYRINGS : 0) |
security/keys/keyring.c +6 -1
@@ -957,7 +957,6 @@ key_ref_t keyring_search(key_ref_t keyristruct keyring_search_context ctx = { .index_key.type = type, .index_key.description = description, - .index_key.desc_len =strlen (description), .cred =current_cred (), .match_data.cmp = key_default_cmp, .match_data.raw_data = description,
@@ -965,8 +964,14 @@ key_ref_t keyring_search(key_ref_t keyri .flags = KEYRING_SEARCH_DO_STATE_CHECK, };key_ref_t key; +size_t desclen;int ret; + desclen =strlen (description); +if (desclen >=KEY_MAX_DESC_SIZE ) +return ERR_PTR (-EINVAL ); + ctx.index_key.desc_len = desclen; +if (recurse) ctx.flags |=KEYRING_SEARCH_RECURSE ;if (type->match_preparse) {
security/keys/request_key.c +12 -2
@@ -584,7 +584,6 @@ struct key *request_key_and_link(struct .index_key.type = type, .index_key.domain_tag = domain_tag, .index_key.description = description, - .index_key.desc_len = strlen(description), .cred = current_cred(), .match_data.cmp = key_default_cmp, .match_data.raw_data = description,
@@ -595,8 +594,14 @@ struct key *request_key_and_link(struct };struct key *key;key_ref_t key_ref; +size_t desclen;int ret; + desclen =strlen (description); +if (desclen >=KEY_MAX_DESC_SIZE ) +return ERR_PTR (-EINVAL ); + ctx.index_key.desc_len = desclen; +kenter ("%s,%s,%p,%zu,%p,%p,%lx" , ctx.index_key.type->name, ctx.index_key.description, callout_info, callout_len, aux, dest_keyring, flags);
@@ -787,7 +792,6 @@ struct key *request_key_rcu(struct key_t .index_key.type = type, .index_key.domain_tag = domain_tag, .index_key.description = description, - .index_key.desc_len = strlen(description), .cred = current_cred(), .match_data.cmp = key_default_cmp, .match_data.raw_data = description,
@@ -797,6 +801,12 @@ struct key *request_key_rcu(struct key_t };struct key *key;key_ref_t key_ref; +size_t desclen; + + desclen =strlen (description); +if (desclen >=KEY_MAX_DESC_SIZE ) +return ERR_PTR (-EINVAL ); + ctx.index_key.desc_len = desclen;kenter ("%s,%s" , type->name, description);
Greg Kroah-Hartman
maintainerPATCH 563/1005 KEYS: Verify the key identity in __key_unlink_begin
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit 7a7f70ff7b26519c98b339a3e0cd9ee3c8d17f77 upstream.
When two keys have identical type and description, linking the second key replaces the first in a keyring. However, attempting to unlink the first key (no longer in the keyring) unlinks the second key.
This happens because __key_unlink_begin() calls assoc_array_delete() with &key->index_key, matching only on type and description rather than the key's identity.
Example:
keyctl new_session >/dev/null keyctl newring ring_a @s keyctl newring ring_b @s A=$(keyctl add user A ss %:ring_a) B=$(keyctl add user A qq %:ring_b) keyctl newring R @s keyctl link $A %:R keyctl link $B %:R keyctl unlink $A %:R keyctl show
Verify the key identity before unlinking, and return -ENOENT on mismatch, instead of unlinking the key with the wrong identity.
--- security/keys/keyring.c | 6 ++++++ 1 file changed, 6 insertions(+)
security/keys/keyring.c +6 -0
@@ -1506,9 +1506,15 @@ static int __key_unlink_begin(struct key struct assoc_array_edit **_edit) {struct assoc_array_edit *edit; +const void *object;BUG_ON (*_edit !=NULL ); + object =assoc_array_find (&keyring->keys, &keyring_assoc_array_ops, + &key->index_key); +if (!object ||keyring_ptr_to_key (object) != key) +return -ENOENT ; + edit =assoc_array_delete (&keyring->keys, &keyring_assoc_array_ops, &key->index_key);if (IS_ERR (edit))
Greg Kroah-Hartman
maintainerPATCH 564/1005 KEYS: Protect pkey method checks against type removal
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuansheng Yang <[email protected]>
commit bab48a1044475f62d6e910c6d7267ce4bae847f9 upstream.
keyctl_pkey_query(), keyctl_pkey_e_d_s() and keyctl_pkey_verify() check that key->type has the ->asym_*() method they need and call it later, without holding key->sem. A reference keeps the key alive, but does not pin the module that provides its type.
When that module is unloaded, unregister_key_type() waits for the key GC to process every remaining key of the type. For each such key, the GC takes key->sem for writing, switches key->type to key_type_dead, whose ->asym_*() methods are NULL, and destroys the payload. If that happens between the check and the call, the keyctl calls a NULL method; if it happens while the method runs, the method returns into freed module text. In-tree, turris-signing-key provides ->asym_query() and ->asym_eds_op() and can be built as a module.
Take key->sem for reading around each method call, and check the method again under it, right before the call. While the lock is held the GC cannot switch the key to key_type_dead, so unregister_key_type() and the module unload cannot complete until the method returns. If the type is already gone, the check finds key_type_dead and the keyctl fails with -EOPNOTSUPP, as it does for any key type without the method.
memdup_user() and copy_to_user() stay outside key->sem, as in keyctl_read_key(), so no page fault is taken with key->sem held. The in-tree ->asym_*() methods do not take key->sem themselves. Nothing else in the kernel calls these methods, so these four call sites are the full coverage:
- keyctl_pkey_query(): ->asym_query() for KEYCTL_PKEY_QUERY
- keyctl_pkey_params_get_2(): ->asym_query(), and the op-specific check for KEYCTL_PKEY_ENCRYPT, _DECRYPT, _SIGN and _VERIFY
- keyctl_pkey_e_d_s(): ->asym_eds_op() for _ENCRYPT, _DECRYPT and _SIGN
- keyctl_pkey_verify(): ->asym_verify_signature() for _VERIFY
This problem was recently fixed for keyctl_read_key() by 925c84e3cc21 ("keys: Protect the read method check against type removal") and for key_update() by aef3a8a4f988 ("KEYS: Protect the update method check against type removal").
--- security/keys/keyctl_pkey.c | 100 +++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 24 deletions(-)
security/keys/keyctl_pkey.c +76 -24
@@ -129,45 +129,77 @@ static int keyctl_pkey_params_get_2(consif (ret <0 )return ret; +down_read (¶ms->key->sem); + +if (!params->key->type->asym_query) { + ret = -EOPNOTSUPP ; + goto out_up_key_sem; + } + ret = params->key->type->asym_query (params, &info);if (ret <0 ) -return ret; + goto out_up_key_sem;switch (op) {case KEYCTL_PKEY_ENCRYPT :if (uparams.in_len > info.max_dec_size || - uparams.out_len > info.max_enc_size) -return -EINVAL ; + uparams.out_len > info.max_enc_size) { + ret = -EINVAL ; + goto out_up_key_sem; + } params->out_len = info.max_enc_size;break ;case KEYCTL_PKEY_DECRYPT :if (uparams.in_len > info.max_enc_size || - uparams.out_len > info.max_dec_size) -return -EINVAL ; + uparams.out_len > info.max_dec_size) { + ret = -EINVAL ; + goto out_up_key_sem; + } params->out_len = info.max_dec_size;break ;case KEYCTL_PKEY_SIGN :if (uparams.in_len > info.max_data_size || - uparams.out_len > info.max_sig_size) -return -EINVAL ; + uparams.out_len > info.max_sig_size) { + ret = -EINVAL ; + goto out_up_key_sem; + } params->out_len = info.max_sig_size;break ;case KEYCTL_PKEY_VERIFY :if (uparams.in_len > info.max_data_size || - uparams.in2_len > info.max_sig_size) -return -EINVAL ; + uparams.in2_len > info.max_sig_size) { + ret = -EINVAL ; + goto out_up_key_sem; + } params->out_len = info.max_sig_size;break ;default : -return -EOPNOTSUPP ; + ret = -EOPNOTSUPP ; + goto out_up_key_sem; } params->in_len = uparams.in_len; -return 0 ; + +switch (op) { +case KEYCTL_PKEY_VERIFY : +if (!params->key->type->asym_verify_signature) + ret = -EOPNOTSUPP ; +break ; +case KEYCTL_PKEY_ENCRYPT : +case KEYCTL_PKEY_DECRYPT : +case KEYCTL_PKEY_SIGN : +if (!params->key->type->asym_eds_op) + ret = -EOPNOTSUPP ; +break ; + } + +out_up_key_sem: +up_read (¶ms->key->sem); +return ret; }/*
@@ -185,7 +217,16 @@ long keyctl_pkey_query(key_serial_t id,if (ret <0 ) goto error; +down_read (¶ms.key->sem); +if (!params.key->type->asym_query) { + ret = -EOPNOTSUPP ; + goto out_up_key_sem; + } + ret = params.key->type->asym_query (¶ms, &res); + +out_up_key_sem: +up_read (¶ms.key->sem);if (ret <0 ) goto error;
@@ -230,10 +271,6 @@ long keyctl_pkey_e_d_s(int op,if (ret <0 ) goto error_params; - ret = -EOPNOTSUPP ; -if (!params.key->type->asym_eds_op) - goto error_params; -switch (op) {case KEYCTL_PKEY_ENCRYPT : params.op = kernel_pkey_encrypt;
@@ -260,7 +297,16 @@ long keyctl_pkey_e_d_s(int op,if (!out) goto error_in; +down_read (¶ms.key->sem); +if (!params.key->type->asym_eds_op) { + ret = -EOPNOTSUPP ; + goto out_up_key_sem; + } + ret = params.key->type->asym_eds_op (¶ms, in, out); + +out_up_key_sem: +up_read (¶ms.key->sem);if (ret <0 ) goto error_out;
@@ -305,31 +351,37 @@ long keyctl_pkey_verify(const struct key ret =keyctl_pkey_params_get_2 (_params, _info,KEYCTL_PKEY_VERIFY , ¶ms);if (ret <0 ) - goto error_params; - - ret = -EOPNOTSUPP ; -if (!params.key->type->asym_verify_signature) - goto error_params; + goto out_free_params; in =memdup_user (_in, params.in_len);if (IS_ERR (in)) { ret =PTR_ERR (in); - goto error_params; + goto out_free_params; } in2 =memdup_user (_in2, params.in2_len);if (IS_ERR (in2)) { ret =PTR_ERR (in2); - goto error_in; + goto out_free_in; } params.op = kernel_pkey_verify; +down_read (¶ms.key->sem); +if (!params.key->type->asym_verify_signature) { + ret = -EOPNOTSUPP ; + goto out_up_key_sem; + } + ret = params.key->type->asym_verify_signature (¶ms, in, in2); +out_up_key_sem: +up_read (¶ms.key->sem);kfree (in2); -error_in: + +out_free_in:kfree (in); -error_params: + +out_free_params:keyctl_pkey_params_free (¶ms);return ret; }
Greg Kroah-Hartman
maintainerPATCH 565/1005 bootconfig: Allow keys with the maximum supported depth
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiqi Zhang <[email protected]>
commit cab697164b47eecfa2f146024f5d661f99a1a1e7 upstream.
xbc_verify_tree() accepts keys with XBC_DEPTH_MAX (16) components, but xbc_node_compose_key_after() returns -ERANGE immediately after storing the sixteenth component. It rejects the key before discovering that there are no more ancestors to collect.
For example, a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p = value can be attached to an initrd successfully. However, bootconfig -l stops listing and prints "Failed to compose key -34". In the kernel, the same error propagates through copy_xbc_key_value_list() during its length probe, so proc_boot_config_init() returns before creating /proc/bootconfig.
Check the array capacity before storing the next component. This lets exactly XBC_DEPTH_MAX components be composed while retaining the check before any out-of-bounds store.
I found this issue while reviewing bootconfig's depth handling and used OpenAI Codex to verify the failure and develop the fix. I reviewed the change and wrote and ran the regression tests.
--- lib/bootconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bootconfig.c +1 -1
@@ -431,9 +431,9 @@ int __init xbc_node_compose_key_after(st node =xbc_node_get_parent (node);while (node && node != root) { - keys[depth++] =xbc_node_index (node);if (depth ==XBC_DEPTH_MAX )return -ERANGE ; + keys[depth++] =xbc_node_index (node); node =xbc_node_get_parent (node); }if (!node && root)
Greg Kroah-Hartman
maintainerPATCH 566/1005 ALSA: caiaq: Kill EP1 URB before unregistering the input device
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergei Nizovtsev <[email protected]>
commit 5d325345185015024a86abca4cc5fa6a3f75294e upstream.
snd_disconnect() unregisters the input device via snd_usb_caiaq_input_disconnect() and only afterwards kills the EP1 command URB (cdev->ep1_in_urb). The EP1 completion handler usb_ep1_command_reply_dispatch() feeds snd_usb_caiaq_input_dispatch() for EP1_CMD_READ_{ERP,ANALOG,IO} replies, which report into cdev->input_dev. Since commit b04dcbb7f7b1 ("ALSA: caiaq: Use snd_card_free_when_closed() at disconnection") the input device is unregistered from snd_usb_caiaq_input_disconnect() but cdev->input_dev is cleared only later, in snd_usb_caiaq_input_free() from the card destructor. As the dispatch guard only tests cdev->input_dev for NULL, an EP1 reply that completes after input_unregister_device() but before cdev->ep1_in_urb is killed reports into an input device that has already been unregistered and, with no evdev client holding it open, freed.
Normally the window is closed by the USB core: usb_unbind_interface() calls usb_disable_interface() before ->disconnect(), which flushes the EP1 URB as long as endpoint 0x81 belongs to the interface being unbound. But caiaq addresses EP1 through the device-wide pipe usb_rcvbulkpipe(usb_dev, 0x1) without checking which interface owns the endpoint. If a device declares it in another interface, the URB stays live across snd_disconnect() of the interface that owns the card.
This needs a crafted device descriptor; a device that has EP1 in the interface caiaq is bound to is not affected.
Kill cdev->ep1_in_urb (and the paired midi_out_urb) before the input and audio disconnect helpers, so no EP1 completion can run once the input device has been unregistered.
Reproduced under KASAN with raw-gadget + dummy_hcd emulating an Audio Kontrol 1 (17cc:0815) with the EP1 bulk pair in interface 1: only interface 0 was bound to snd-usb-caiaq and then unbound through sysfs while the gadget flooded EP1 with EP1_CMD_READ_ERP replies. With no PCM stream running the window is very short and was only hit by stalling the unbinding CPU with a kgdb breakpoint at snd_usb_caiaq_audio_disconnect(). With the fix applied, the same test runs clean.
BUG: KASAN: slab-use-after-free in input_event+0x3a/0xc0 Read of size 8 at addr ffff8880151a4028 by task sh/118 Call Trace: <IRQ> input_event+0x3a/0xc0 snd_usb_caiaq_input_dispatch+0xab2/0xf00 usb_ep1_command_reply_dispatch+0x1f3/0x580 __usb_hcd_giveback_urb+0x246/0x400 dummy_timer+0x1415/0x3380 __hrtimer_run_queues+0x39d/0x800 hrtimer_run_softirq+0x187/0x2d0 handle_softirqs+0x1ff/0x930 __irq_exit_rcu+0x15b/0x210 irq_exit_rcu+0xe/0x20 sysvec_apic_timer_interrupt+0x81/0xb0 </IRQ> <TASK> asm_sysvec_apic_timer_interrupt+0x1a/0x20 RIP: 0010:snd_usb_caiaq_audio_disconnect+0x0/0x70 snd_disconnect+0x81/0x110 usb_unbind_interface+0x1a0/0x860 device_release_driver_internal+0x2c5/0x470 unbind_store+0xde/0x100 </TASK> Allocated by task 80: input_allocate_device+0x47/0x340 snd_usb_caiaq_input_init+0x4c/0x1ac0 snd_probe+0xab3/0x1160 usb_probe_interface+0x2ea/0x810 Freed by task 118: kfree+0x1ea/0x5c0 input_dev_release+0xab/0xd0 device_release+0xcf/0x250 kobject_put+0x169/0x320 snd_disconnect+0x79/0x110 usb_unbind_interface+0x1a0/0x860
--- sound/usb/caiaq/device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/usb/caiaq/device.c +8 -3
@@ -593,14 +593,19 @@ static void snd_disconnect(struct usb_insnd_card_disconnect (card); +/* +* Kill the EP1 URB before disconnecting the input device: its +* completion reports into cdev->input_dev, which input_disconnect() +* frees without clearing the pointer. +*/ +usb_kill_urb (cdev->ep1_in_urb); +usb_kill_urb (cdev->midi_out_urb); +#ifdef CONFIG_SND_USB_CAIAQ_INPUT snd_usb_caiaq_input_disconnect (cdev);#endif snd_usb_caiaq_audio_disconnect (cdev); -usb_kill_urb (cdev->ep1_in_urb); -usb_kill_urb (cdev->midi_out_urb); -snd_card_free_when_closed (card); }
Greg Kroah-Hartman
maintainerPATCH 567/1005 Revert "ALSA: hda/cs420x: Add CS4208 fixup for MacBookAir 7,2"
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit d1a1f361e08311f6d9a4aea2da2d1bcb3891f4ef upstream.
This reverts commit 82cfab6a52621febf36752bd5ed5184f82c96e07.
The quirk entry seems matching with other multiple irrelevant models that lead to a regression on those.
Maybe we should use HDA_CODEC_QUIRK() entry for the corresponding codec SSID, instead. But let's revert for addressing the regression at first.
--- sound/hda/codecs/cirrus/cs420x.c | 2 -- 1 file changed, 2 deletions(-)
sound/hda/codecs/cirrus/cs420x.c +0 -2
@@ -571,7 +571,6 @@ static const struct hda_model_fixup cs42static const struct hda_quirk cs4208_fixup_tbl[] = {SND_PCI_QUIRK_VENDOR (0x106b ,"Apple" ,CS4208_MAC_AUTO ), -SND_PCI_QUIRK (0x8086 ,0x7270 ,"MacBookAir 7,2" ,CS4208_MAC_AUTO ), {}/* terminator */ };
@@ -584,7 +583,6 @@ static const struct hda_quirk cs4208_macSND_PCI_QUIRK (0x106b ,0x7800 ,"MacPro 6,1" ,CS4208_MACMINI ),SND_PCI_QUIRK (0x106b ,0x7b00 ,"MacBookPro 12,1" ,CS4208_MBP11 ), SND_PCI_QUIRK(0x106b, 0x7f00, "iMac 16,1", CS4208_MBP11), - SND_PCI_QUIRK(0x8086, 0x7270, "MacBookAir 7,2", CS4208_MBA6), {} /* terminator */ };
Greg Kroah-Hartman
maintainerPATCH 568/1005 ALSA: hda/realtek: Fix the Dell XPS 8940 headset microphone
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Angel J <[email protected]>
commit ae28ba98f55a2f30fed57371899b8cecd7cbde64 upstream.
The Dell XPS 8940 (1028:09c5) has an ALC3861 codec (0x10ec0899). Its BIOS marks the headset microphone pin at NID 0x19 as disconnected (0x411111f0). With no external microphone input in the pin configuration, the generic parser creates a shared headphone/mic input on NID 0x1b instead. Headphone playback works, but the headset microphone is silent.
Override NID 0x19 as a front microphone without independent presence detection. This gives the generic parser the dedicated microphone input and preserves NID 0x1b for simultaneous headphone playback.
I encountered this issue on my XPS 8940. Similar symptoms were also reported by a user on Ubuntu:
https://bugs.launchpad.net/bugs/1971232
--- sound/hda/codecs/realtek/alc882.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/hda/codecs/realtek/alc882.c +10 -0
@@ -50,6 +50,7 @@ enum {ALC889_FIXUP_MP41_VREF ,ALC882_FIXUP_INV_DMIC ,ALC882_FIXUP_NO_PRIMARY_HP , +ALC898_FIXUP_DELL_XPS8940_MIC ,ALC887_FIXUP_ASUS_BASS ,ALC887_FIXUP_BASS_CHMAP , ALC1220_FIXUP_GB_DUAL_CODECS,
@@ -507,6 +508,13 @@ static const struct hda_fixup alc882_fix .type = HDA_FIXUP_FUNC, .v.func = alc882_fixup_no_primary_hp, }, + [ALC898_FIXUP_DELL_XPS8940_MIC] = { + .type = HDA_FIXUP_PINS, + .v.pins = (const struct hda_pintbl []) { + {0x19 ,0x02a19130 },/* headset mic, no separate jack detect */ + {} + }, + }, [ALC887_FIXUP_ASUS_BASS] = { .type = HDA_FIXUP_PINS, .v.pins = (const struct hda_pintbl []) {
@@ -610,6 +618,8 @@ static const struct hda_quirk alc882_fixSND_PCI_QUIRK (0x1025 ,0x0259 ,"Acer Aspire 5935" ,ALC889_FIXUP_DAC_ROUTE ),SND_PCI_QUIRK (0x1025 ,0x026b ,"Acer Aspire 8940G" ,ALC882_FIXUP_ACER_ASPIRE_8930G ),SND_PCI_QUIRK (0x1025 ,0x0296 ,"Acer Aspire 7736z" ,ALC882_FIXUP_ACER_ASPIRE_7736 ), +SND_PCI_QUIRK (0x1028 ,0x09c5 ,"Dell XPS 8940" , +ALC898_FIXUP_DELL_XPS8940_MIC ),SND_PCI_QUIRK (0x1043 ,0x13c2 ,"Asus A7M" ,ALC882_FIXUP_EAPD ),SND_PCI_QUIRK (0x1043 ,0x1873 ,"ASUS W90V" ,ALC882_FIXUP_ASUS_W90V ), SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Greg Kroah-Hartman
maintainerPATCH 569/1005 ALSA: usb-audio: Drop capture packets with bogus actual_length
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gichoon Han <[email protected]>
commit eed0e9583a290e6adbe3a8480bdae911f31e1ed9 upstream.
retire_capture_urb() copies urb->iso_frame_desc[i].actual_length bytes out of urb->transfer_buffer at the packet's offset, but never checks that value against the requested packet length. A host controller reporting more data than requested makes memcpy() read past the end of the URB transfer buffer.
Commit 06be918062ad ("ALSA: usb-audio: Bound packet copies by the PCM buffer size") clamps the count to the PCM ring buffer size, which protects the destination. The source slot is only ep->curpacksize bytes per packet, though, so the over-read remains.
This was hit on an ARM32 system (vendor 5.4 kernel; the code path is unchanged in mainline) with a full-speed UAC1 microphone behind a high-speed hub, i.e. the EHCI siTD path. sitd_complete() computes actual_length as desc->length - SITD_LENGTH(t); the controller reported a remaining length larger than the programmed one, the value wrapped to ~4G, and the capture copy faulted on the first unmapped page after the URB buffer:
Unable to handle kernel paging request at virtual address e8756000 Internal error: Oops: 7 [#1] PREEMPT SMP ARM r3 : 00000000 r2 : 0001e700 r1 : e8756000 r0 : e878fc80 Code: ba000002 f5d1f03c f5d1f05c f5d1f07c (e8b151f8)
A packet can never legitimately carry more than its requested length, so warn and skip it instead of copying.
--- sound/usb/pcm.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/usb/pcm.c +6 -0
@@ -1337,6 +1337,12 @@ static void retire_capture_urb(struct sn"frame %d active: %d\n" , i, urb->iso_frame_desc[i].status); bytes = urb->iso_frame_desc[i].actual_length; +if (unlikely (bytes > urb->iso_frame_desc[i].length)) { +dev_warn_ratelimited (&subs->dev->dev, +"packet %d: actual_length %u exceeds length %u, dropping\n" , + i, bytes, urb->iso_frame_desc[i].length); +continue ; + }if (subs->stream_offset_adj >0 ) {unsigned int adj =min (subs->stream_offset_adj, bytes); cp += adj;
Greg Kroah-Hartman
maintainerPATCH 570/1005 ALSA: hda: Fix [codec] ID matching in patch files for IDs with bit 31 set
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Davison <[email protected]>
commit fda103c1432f344e1cd548f346d157b1e67ee7c5 upstream.
parse_codec_mode() reads the vendor and subsystem IDs of a patch file's [codec] line into an int, and skips the check when the value is zero or negative, as documented. An ID with bit 31 set, such as SigmaTel's 0x8384xxxx or Intel's 0x8086xxxx, comes out negative, so it is taken as a wildcard and the section is applied to every codec instead of the one it names.
This was seen on an OpenPeak OpenFrame 2 with an IDT 92HD75B2X5 (0x111d7608). A patch file written for the STAC9202 (0x83847632) in the related OpenFrame 1 was applied to it, swapping the headphone and speaker pin configurations, so auto-mute never muted the speaker.
Read the IDs as long long, so real IDs are compared exactly. Values written as negative numbers (e.g. -1) still act as wildcards, as documented; a hex value such as 0xffffffff is now compared as written.
Tested on 6.18.60 on an OpenFrame 2, with a rebuilt snd-hda-codec and the STAC9202 patch file: user_pin_configs stays empty for the IDT codec, and the headphone and line-out pins are assigned as the BIOS sets them. Not tested on a STAC9202 itself.
The bug was tracked down and this fix written with an AI coding assistant (Claude Code, Claude Opus 5.5), which also ran the tests above. I have reviewed the change and the tests.
--- sound/hda/common/sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/hda/common/sysfs.c +3 -2
@@ -512,11 +512,12 @@ static inline int strmatch(const char *astatic void parse_codec_mode (char *buf,struct hda_bus *bus,struct hda_codec **codecp) { -int vendorid, subid, caddr; +long long vendorid, subid; +int caddr;struct hda_codec *codec; *codecp =NULL ; -if (sscanf (buf,"%i %i %i" , &vendorid, &subid, &caddr) ==3 ) { +if (sscanf (buf,"%lli %lli %i" , &vendorid, &subid, &caddr) ==3 ) {list_for_each_codec (codec, bus) { if ((vendorid <= 0 || codec->core.vendor_id == vendorid) && (subid <= 0 || codec->core.subsystem_id == subid) &&
Greg Kroah-Hartman
maintainerPATCH 571/1005 selftests/ftrace: Add missing spaces after ! in probe syntax tests
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaewon Jung <[email protected]>
commit 36990c8fda77d918b1e52d5d6df3a144b552d86e upstream.
Add the missing space between ! and grep. Otherwise, the shell tries to run !grep and reports "!grep: not found". This always skips the conditional checks without checking for kernel return probe argument support.
--- tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc | 4 ++-- tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc +2 -2
@@ -33,7 +33,7 @@ check_error 'f vfs_read ^$stack10000' # check_error 'f vfs_read ^$arg10000' # BAD_ARG_NUM -if !grep -q 'kernel return probes support:' README; then +if ! grep -q 'kernel return probes support:' README; then check_error 'f vfs_read $retval ^$arg1' # BAD_VAR fi check_error 'f vfs_read ^$none_var' # BAD_VAR
@@ -100,7 +100,7 @@ if grep -q "<argname>" README; then check_error 'f vfs_read args=^$arg*' # BAD_VAR_ARGS check_error 'f vfs_read +0(^$arg*)' # BAD_VAR_ARGS check_error 'f vfs_read $arg* ^$arg*' # DOUBLE_ARGS -if !grep -q 'kernel return probes support:' README; then +if ! grep -q 'kernel return probes support:' README; then check_error 'f vfs_read%return ^$arg*' # NOFENTRY_ARGS fi check_error 'f vfs_read ^hoge' # NO_BTFARG
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +1 -1
@@ -108,7 +108,7 @@ if grep -q "<argname>" README; then check_error 'p vfs_read args=^$arg*' # BAD_VAR_ARGS check_error 'p vfs_read +0(^$arg*)' # BAD_VAR_ARGS check_error 'p vfs_read $arg* ^$arg*' # DOUBLE_ARGS -if !grep -q 'kernel return probes support:' README; then +if ! grep -q 'kernel return probes support:' README; then check_error 'r vfs_read ^$arg*' # NOFENTRY_ARGS fi check_error 'p vfs_read+20 ^$arg*' # NOFENTRY_ARGS
Greg Kroah-Hartman
maintainerPATCH 572/1005 tracing/selftests: Fix false bashism in kprobe_non_uniq_symbol.tc
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit 88d5f8cb8a6276194ac8c1de44f3ed77d7e938ce upstream.
The checkbashism is giving a false positive to the kprobe test of:
($"foo" should be eval_gettext "foo"):
if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}$" /proc/kallsyms)" -le '1' ]; then
This is because it sees the $" at the end of the grep as a bash symbol. Instead, escape the '$' with a backslash as it is within quotes and that '$' is for grep to process an end of line character and not a bash variable.
--- tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +1 -1
@@ -6,7 +6,7 @@ SYMBOL='name_show' # We skip this test on kernel where SYMBOL is unique or does not exist. -if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}$" /proc/kallsyms)" -le '1' ]; then +if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}\$" /proc/kallsyms)" -le '1' ]; then exit_unsupported fi
Greg Kroah-Hartman
maintainerPATCH 573/1005 kprobes: Fix error return and slot leak in __register_kprobe()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit 6a658cc2d605e5acf35e638c62f480460d5939cd upstream.
When arm_kprobe() fails in __register_kprobe(), the probe is removed from kprobe_table and synchronize_rcu() is executed, but the error code ret was ignored and try_to_optimize_kprobe(p) was executed, returning 0. Additionally, the instruction slot allocated by prepare_kprobe() was leaked.
Fix this by releasing the instruction slot via arch_remove_kprobe(p) and returning ret when arm_kprobe() fails.
--- kernel/kprobes.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/kprobes.c +2 -0
@@ -1711,6 +1711,8 @@ static int __register_kprobe(struct kproif (ret) {hlist_del_rcu (&p->hlist);synchronize_rcu (); +arch_remove_kprobe (p); +return ret; } }