6.12.101-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 407/602 phonet: pep: fix use-after-free in pep_get_sb()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
commit 0f71f852a96af9685858ce59fda34ecbf85c283d upstream.
pep_get_sb() doesn't consider that pskb_may_pull() might have relocated the skb data, and continue to access the older pointer, causing UAF.
Reproduced under KASAN:
BUG: KASAN: slab-use-after-free in pep_get_sb+0x234/0x3b0 Read of size 1 at addr ff11000105510f50 by task repro/157 pep_get_sb+0x234/0x3b0 pipe_handler_do_rcv+0x5f7/0xa10 pep_do_rcv+0x203/0x410 __sk_receive_skb+0x471/0x4a0 phonet_rcv+0x5b3/0x6c0 __netif_receive_skb+0xcc/0x1d0
Refetch the header with skb_header_pointer() after pskb_may_pull(), so the possibly stale pointer is no longer dereferenced. There are better ways to solve this, but, this is the less instrusive one.
--- net/phonet/pep.c | 2 ++ 1 file changed, 2 insertions(+)
net/phonet/pep.c +2 -0
@@ -55,6 +55,8 @@ static unsigned char *pep_get_sb(struct ph =skb_header_pointer (skb,0 ,2 , &h);if (ph ==NULL || ph->sb_len <2 || !pskb_may_pull (skb, ph->sb_len))return NULL ; +/* pskb_may_pull() may have reallocated the head; refetch ph. */ + ph =skb_header_pointer (skb,0 ,2 , &h); ph->sb_len -=2 ; *ptype = ph->sb_type; *plen = ph->sb_len;
Greg Kroah-Hartman
maintainerPATCH 408/602 vxlan: require CAP_NET_ADMIN in the device netns for changelink
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 3a61bd9637f3d929aa846e4eb3d98b48c26fcb0e upstream.
A tunnel changelink() operates on at most two netns, dev_net(dev) and the sticky underlay netns vxlan->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in vxlan->net can rewrite a vxlan device whose underlay lives in vxlan->net.
vxlan_changelink() validates and applies the new configuration against vxlan->net (vxlan_config_validate(vxlan->net, ...)) and can reopen the underlay socket in that netns, so the same reasoning as the tunnel changelink series applies here.
Gate vxlan_changelink() with rtnl_dev_link_net_capable(), at the top of the op before any attribute is parsed, matching ipgre_changelink() and the rest of the "require CAP_NET_ADMIN in the device netns for changelink" series.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/vxlan/vxlan_core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/vxlan/vxlan_core.c +3 -0
@@ -4381,6 +4381,9 @@ static int vxlan_changelink(struct net_dstruct vxlan_rdst *dst;int err; +if (!rtnl_dev_link_net_capable (dev, vxlan->net)) +return -EPERM ; + dst = &vxlan->default_dst; err =vxlan_nl2conf (tb, data, dev, &conf, true, extack);if (err)
Greg Kroah-Hartman
maintainerPATCH 409/602 net: slip: serialize receive against buffer reallocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sungmin Kang <[email protected]>
commit ee7f9bb9320add61f7b367d7e6cd55e3a3a4d65d upstream.
sl_realloc_bufs() replaces rbuff and updates buffsize while holding sl->lock. slip_receive_buf() reads those fields and writes through rbuff without holding the lock.
An MTU change can therefore race with receive processing. An MTU shrink can expose the new smaller rbuff with the old larger bound, causing an out-of-bounds write. A receive callback which already loaded the old rbuff can instead continue writing after that buffer has been freed.
Serialize receive processing with sl_realloc_bufs() by holding sl->lock while consuming each receive batch.
--- drivers/net/slip/slip.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/slip/slip.c +4 -0
@@ -693,6 +693,8 @@ static void slip_receive_buf(struct tty_if (!sl || sl->magic !=SLIP_MAGIC || !netif_running (sl->dev))return ; +spin_lock_bh (&sl->lock); +/* Read the characters out of the buffer */ while (count--) {if (fp && *fp++) {
@@ -708,6 +710,8 @@ static void slip_receive_buf(struct tty_#endif slip_unesc (sl, *cp++); } + +spin_unlock_bh (&sl->lock); }/************************************
Greg Kroah-Hartman
maintainerPATCH 410/602 geneve: require CAP_NET_ADMIN in the device netns for changelink
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 8efb8f8bbb353b8f2fdf4f37534c6d96c9f69e01 upstream.
A tunnel changelink() operates on at most two netns, dev_net(dev) and the sticky underlay netns geneve->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in geneve->net can rewrite a geneve device whose underlay lives in geneve->net.
geneve_changelink() applies the new configuration against geneve->net:geneve_link_config() and the geneve_quiesce()/geneve_unquiesce() pair reopen the underlay sockets in that netns (geneve_sock_add() uses geneve->net), so the same reasoning as the tunnel changelink series applies here.
Gate geneve_changelink() with rtnl_dev_link_net_capable(), at the top of the op before any attribute is parsed, matching ipgre_changelink() and the rest of the "require CAP_NET_ADMIN in the device netns for changelink" series.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/geneve.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/geneve.c +3 -0
@@ -1694,6 +1694,9 @@ static int geneve_changelink(struct net_struct geneve_config cfg;int err; +if (!rtnl_dev_link_net_capable (dev, geneve->net)) +return -EPERM ; +/* If the geneve device is configured for metadata (or externally * controlled, for example, OVS), then nothing can be changed. */
Greg Kroah-Hartman
maintainerPATCH 411/602 net/af_iucv: fix NULL deref in afiucv_hs_callback_syn()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hidayath Khan <[email protected]>
commit 47a5116e56a6b6fe1e909f244e39cd0fc26ceee4 upstream.
afiucv_hs_callback_syn() allocates the child socket with GFP_ATOMIC. If the allocation fails, nsk is NULL.
The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls iucv_sock_kill(nsk) in that path.
iucv_sock_kill() does not accept a NULL socket pointer and immediately dereferences sk via sock_flag(sk, SOCK_ZAPPED). When nsk is NULL, calling iucv_sock_kill(nsk) results in a NULL pointer dereference.
Only call iucv_sock_kill() when a child socket was successfully allocated.
--- net/iucv/af_iucv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/iucv/af_iucv.c +2 -1
@@ -1871,7 +1871,8 @@ static int afiucv_hs_callback_syn(structafiucv_swap_src_dest (skb); trans_hdr->flags =AF_IUCV_FLAG_SYN |AF_IUCV_FLAG_FIN ; err =dev_queue_xmit (skb); -iucv_sock_kill (nsk); +if (nsk) +iucv_sock_kill (nsk);bh_unlock_sock (sk); goto out; }
Greg Kroah-Hartman
maintainerPATCH 412/602 net/iucv: fix use-after-free of a severed iucv_path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit be7cc4656eb1f54029610e82d1f0fdd3f9b5ec0a upstream.
af_iucv queues not-yet-received message notifications on iucv->message_q, each holding a raw pointer to the connection's iucv_path. When the peer severs the connection, iucv_sever_path() frees that path with iucv_path_free() but leaves the notifications queued. A later recvmsg() drains message_q via iucv_process_message_q() and hands the stale path to message_receive() -- a use-after-free of the freed iucv_path.
Drop the queued notifications when the path is severed; once the path is gone they can no longer be received. This also frees the notifications leaked when a socket is closed with messages still queued.
--- net/iucv/af_iucv.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/iucv/af_iucv.c +14 -0
@@ -334,6 +334,7 @@ static void iucv_sever_path(struct sockunsigned char user_data[16 ];struct iucv_sock *iucv =iucv_sk (sk);struct iucv_path *path = iucv->path; +struct sock_msg_q *p, *n;/* Whoever resets the path pointer, must sever and free it. */ if (xchg (&iucv->path,NULL )) {
@@ -345,6 +346,19 @@ static void iucv_sever_path(struct sock }else pr_iucv->path_sever (path,NULL );iucv_path_free (path); + +/* +* Message notifications queued on message_q still reference +* the now freed path; drop them, otherwise a later recvmsg() +* would pass the freed iucv_path to message_receive() via +* iucv_process_message_q(). +*/ +spin_lock_bh (&iucv->message_q.lock); +list_for_each_entry_safe (p, n, &iucv->message_q.list, list) { +list_del (&p->list); +kfree (p); + } +spin_unlock_bh (&iucv->message_q.lock); } }
Greg Kroah-Hartman
maintainerPATCH 413/602 net/mlx5e: Use sender devcom for MPV master-up
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manjunath Patil <[email protected]>
commit e32649b4bad90a6216d8e93cd7dd050af8ac9740 upstream.
After PCIe DPC recovery, mlx5 reloads the affected functions and replays multiport affiliation events. In the reported failure, the first relevant device error was:
pcieport 0000:10:01.1: DPC: containment event
pcieport 0000:10:01.1: PCIe Bus Error: severity=Uncorrected (Fatal)
pcieport 0000:10:01.1: [ 5] SDES (First)
mlx5 recovered the PCI functions and resumed 0000:11:00.1. During that resume, RDMA multiport binding replayed MLX5_DRIVER_EVENT_AFFILIATION_DONE and mlx5e sent MPV_DEVCOM_MASTER_UP. The host then panicked with:
BUG: kernel NULL pointer dereference, address: 0000000000000010 RIP: mlx5_devcom_comp_set_ready+0x5/0x40 [mlx5_core] RDI: 0000000000000000
Call trace included:
mlx5_devcom_comp_set_ready
mlx5e_devcom_event_mpv
mlx5_devcom_send_event
mlx5_ib_bind_slave_port
mlx5r_mp_probe
mlx5_pci_resume
MPV devcom registration publishes mlx5e private data to the component peer list before mlx5e_devcom_init_mpv() stores the returned component device in priv->devcom. A concurrent master-up event can therefore reach a peer whose private data is visible but whose priv->devcom backpointer is still NULL.
MPV_DEVCOM_MASTER_UP already carries the sender/master mlx5e private data as event_data. The ready bit is stored on the shared devcom component, not on an individual peer. Use the sender devcom when marking the MPV component ready.
This preserves the readiness transition while avoiding a NULL dereference of the peer devcom pointer during affiliation replay after PCI error recovery.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -2
@@ -206,11 +206,11 @@ static void mlx5e_disable_async_events(sstatic int mlx5e_devcom_event_mpv (int event,void *my_data,void *event_data) { -struct mlx5e_priv *slave_priv = my_data; +struct mlx5e_priv *master_priv = event_data;switch (event) {case MPV_DEVCOM_MASTER_UP : -mlx5_devcom_comp_set_ready (slave_priv->devcom, true); +mlx5_devcom_comp_set_ready (master_priv->devcom, true);break ;case MPV_DEVCOM_MASTER_DOWN :/* no need for comp set ready false since we unregister after
Greg Kroah-Hartman
maintainerPATCH 414/602 net/x25: fix use-after-free in x25_kill_by_neigh()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lee <[email protected]>
commit 5499e0602d2faafd42c580d25f615903c3fbe11b upstream.
x25_kill_by_neigh() walks the global X.25 socket list looking for sockets attached to a terminating neighbour. x25_list_lock protects list membership while the lookup is in progress, but it does not pin a socket's lifetime after the lock is dropped.
The function currently drops x25_list_lock before calling lock_sock(s). A concurrent close can run x25_release(), remove the same socket from x25_list, and drop the last socket reference in that window. The neighbour teardown path can then lock or inspect a freed struct sock/struct x25_sock.
Take sock_hold(s) while x25_list_lock still proves that the list entry is live, then drop the temporary reference after the socket has been locked, rechecked, and released. Recheck x25_sk(s)->neighbour after lock_sock(), because another path may have disconnected the socket before this path acquired the socket lock. Restart the list walk after each disconnect because the list lock was dropped and the previous iterator state may no longer be valid.
A QEMU/KASAN run against origin/master reproduced a slab-use-after-free in x25_kill_by_neigh().
--- net/x25/af_x25.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/x25/af_x25.c +6 -2
@@ -1772,15 +1772,19 @@ void x25_kill_by_neigh(struct x25_neigh {struct sock *s; +again:write_lock_bh (&x25_list_lock);sk_for_each (s, &x25_list) {if (x25_sk (s)->neighbour == nb) { +sock_hold (s);write_unlock_bh (&x25_list_lock);lock_sock (s); -x25_disconnect (s,ENETUNREACH ,0 ,0 ); +if (x25_sk (s)->neighbour == nb) +x25_disconnect (s,ENETUNREACH ,0 ,0 );release_sock (s); -write_lock_bh (&x25_list_lock); +sock_put (s); + goto again; } }write_unlock_bh (&x25_list_lock);
Greg Kroah-Hartman
maintainerPATCH 415/602 net: gro: fix double aggregation of flush-marked skbs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shiming Cheng <[email protected]>
commit e751256486d0ded20f5a9f9863467f1dce65142f upstream.
Commit 0ab03f353d36 ("net-gro: Fix GRO flush when receiving a GSO packet.") added a flush check to skb_gro_receive(), but skb_gro_receive_list() lacks the same validation.
As a result, packets marked with NAPI_GRO_CB(skb)->flush may still be re-aggregated.
This allows already-GRO'd packets with existing frag_list to be re-aggregated into a new GRO session, corrupting the frag_list chain structure. When skb_segment() attempts to unpack these malformed packets, it encounters invalid state and triggers a kernel panic.
Scenario (Tethering/Device forwarding):
1. Driver: Generated aggregated packet P1 via LRO with frag_list
2. Dev A: Receives aggregated fraglist packet and flush flag set
3. Dev A: Re-enters GRO, skb_gro_receive_list() is called
4. Missing flush check allows re-aggregation despite flush flag
5. Frag_list chain becomes corrupted (loops or dangling refs)
6. Dev B: TX path calls skb_segment(), crashes on corrupted frag_list
Root cause in skb_segment():
The check at line ~4891:
if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) &&
(skb_headlen(list_skb) == len || sg)) { When frag_list is corrupted by double aggregation, when list_skb is a NULL pointer from skb->next, skb_headlen(list_skb) dereference NULL/corrupted pointers occurs.
Call Trace: skb_headlen(NULL skb) skb_segment tcp_gso_segment tcp4_gso_segment inet_gso_segment skb_mac_gso_segment __skb_gso_segment skb_gso_segment validate_xmit_skb validate_xmit_skb_list sch_direct_xmit qdisc_restart __qdisc_run qdisc_run net_tx_action
Fix: Add NAPI_GRO_CB(skb)->flush validation to the early-return check in skb_gro_receive_list(), matching the defensive programming pattern of skb_gro_receive().
--- net/core/gro.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/gro.c +3 -1
@@ -230,7 +230,9 @@ done:int skb_gro_receive_list (struct sk_buff *p,struct sk_buff *skb) { -if (unlikely (p->len + skb->len >=65536 )) +/* make sure to check flush flag and to not merge */ +if (unlikely (p->len + skb->len >=65536 || +NAPI_GRO_CB (skb)->flush))return -E2BIG ;if (!pskb_may_pull (skb,skb_gro_offset (skb))) {
Greg Kroah-Hartman
maintainerPATCH 416/602 net: hip04: fix RX buffer leak on build_skb failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 14fa65d10f5696b063a7d8d26e8291ea84a2c6ed upstream.
When build_skb() fails in hip04_rx_poll(), the driver jumps to the refill path without releasing the current RX buffer and its DMA mapping. Installing a replacement buffer then overwrites the slot references and leaks both resources.
Keep the current slot intact and return budget so NAPI retries the same buffer. Also free a newly allocated RX fragment when dma_map_single() fails.
This issue was found by an in-house static analysis tool.
--- drivers/net/ethernet/hisilicon/hip04_eth.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/hisilicon/hip04_eth.c +8 -3
@@ -594,7 +594,11 @@ static int hip04_rx_poll(struct napi_str skb =build_skb (buf, priv->rx_buf_size);if (unlikely (!skb)) {net_dbg_ratelimited ("build_skb failed\n" ); - goto refill; +/* Retain the slot; return budget so NAPI retries this +* buffer. Refill would overwrite rx_buf[]/rx_phys[] +* and leak them. +*/ +return budget; } dma_unmap_single(priv->dev, priv->rx_phys[priv->rx_head],
@@ -622,14 +626,15 @@ static int hip04_rx_poll(struct napi_str rx++; } -refill: buf =netdev_alloc_frag (priv->rx_buf_size);if (!buf) goto done; phys =dma_map_single (priv->dev, buf,RX_BUF_SIZE ,DMA_FROM_DEVICE ); -if (dma_mapping_error (priv->dev, phys)) +if (dma_mapping_error (priv->dev, phys)) { +skb_free_frag (buf); goto done; + } priv->rx_buf[priv->rx_head] = buf; priv->rx_phys[priv->rx_head] = phys;hip04_set_recv_desc (priv, phys);
Greg Kroah-Hartman
maintainerPATCH 417/602 proc: Fix broken error paths for namespace links
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit 425224c2d700391729be7fe6929a88ef4e2d7a4e upstream.
Don't return the return value of down_read_killable() (0) when a ptrace access check fails, return -EACCES as intended.
--- fs/proc/namespaces.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/proc/namespaces.c +3 -1
@@ -46,7 +46,7 @@ static const char *proc_ns_get_link(struconst struct proc_ns_operations *ns_ops =PROC_I (inode)->ns_ops;struct task_struct *task;struct path ns_path; -int error = -EACCES ; +int error;if (!dentry)return ERR_PTR (-ECHILD );
@@ -59,6 +59,7 @@ static const char *proc_ns_get_link(struif (error) goto out_put_task; + error = -EACCES ;if (!ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS )) goto out;
@@ -90,6 +91,7 @@ static int proc_ns_readlink(struct dentrif (res) goto out_put_task; + res = -EACCES ;if (ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS )) { res =ns_get_name (name,sizeof (name), task, ns_ops);if (res >=0 )
Greg Kroah-Hartman
maintainerPATCH 418/602 ice: fix PTP Call Trace during PTP release
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Greenwalt <[email protected]>
commit f6a7e00b81e35ef1325234925f2fe1e53b466f92 upstream.
If a PF reset occurs when the PTP state is ICE_PTP_UNINIT, then ice_ptp_rebuild() will update the state to ICE_PTP_ERROR. This will result in the following PTP release call trace during driver unload:
kernel BUG at lib/list_debug.c:52!
ice_ptp_release+0x332/0x3c0 [ice]
ice_deinit_features.part.0+0x10e/0x120 [ice]
ice_remove+0x100/0x220 [ice]This was observed when passing PF1 through to a VM. ice_ptp_init() fails because ctrl_pf is NULL and sets the state to ICE_PTP_UNINIT.
Fix by detecting the ICE_PTP_UNINIT state in ice_ptp_rebuild() and returning without error, preventing the invalid state transition to ICE_PTP_ERROR. The only valid path to ICE_PTP_ERROR is from ICE_PTP_RESETTING after a failed rebuild.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/ice/ice_ptp.c +5 -0
@@ -2886,6 +2886,11 @@ void ice_ptp_rebuild(struct ice_pf *pf,struct ice_ptp *ptp = &pf->ptp;int err; +if (ptp->state ==ICE_PTP_UNINIT ) { +dev_dbg (ice_pf_to_dev (pf),"PTP was not initialized, skipping rebuild\n" ); +return ; + } +if (ptp->state ==ICE_PTP_READY ) {ice_ptp_prepare_for_reset (pf, reset_type); }else if (ptp->state !=ICE_PTP_RESETTING ) {
Greg Kroah-Hartman
maintainerPATCH 419/602 selftests/ftrace: Reset triggers at top level before instance loop
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit 1a087033a6bad73b4140020b40e819b0933aafc3 upstream.
When running instance tests, 'ftracetest' creates a new ftrace instance and runs the tests inside it. Before starting each test, it executes 'initialize_system()' to reset the ftrace state to initial-state.
However, since 'initialize_system()' is executed in the context of the instance directory, it only cleans up triggers and filters of that instance.
Any triggers or dynamic events left behind in the top-level instance by previous failed top-level tests, are left completely untouched. These top-level leftovers can cause subsequent instance-based tests to fail or even crash the kernel.
Fix this by executing 'initialize_system()' in the top-level tracing directory once before entering the instance loop.
--- tools/testing/selftests/ftrace/ftracetest | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/ftrace/ftracetest +1 -0
@@ -483,6 +483,7 @@ for t in $TEST_CASES; do done # Test on instance loop +(cd $TRACING_DIR; initialize_system) INSTANCE=" (instance) " for t in $TEST_CASES; do test_on_instance $t || continue
Re: [PATCH 6.12 419/602] selftests/ftrace: Reset triggers at top level before instance loop
Quoted 37 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit
1a087033a6bad73b4140020b40e819b0933aafc3upstream.When running instance tests, 'ftracetest' creates a new ftrace instance and runs the tests inside it. Before starting each test, it executes '
initialize_system()' to reset the ftrace state to initial-state.However, since '
initialize_system()' is executed in the context of the instance directory, it only cleans up triggers and filters of that instance.
Any triggers or dynamic events left behind in the top-level instance by previous failed top-level tests, are left completely untouched. These top-level leftovers can cause subsequent instance-based tests to fail or even crash the kernel.Fix this by executing '
initialize_system()' in the top-level tracing directory once before entering the instance loop.Fixes b5b77be812de ("selftests: ftrace: Allow some tests to be run in a tracing instance")Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Masami Hiramatsu (Google) <[email protected]>Signed-off-by Steven Rostedt <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- tools/testing/selftests/ftrace/ftracetest | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/ftrace/ftracetest for t in $TEST_CASES; do · line 487
Quoted 5 lines
tools/testing/selftests/ftrace/ftracetest +1
-0@@ -483,6 +483,7 @@ for t in $TEST_CASES; do done # Test on instance loop +(cd $TRACING_DIR; initialize_system) INSTANCE=" (instance) "
Hi Greg/Sasha,
I ran an AI-assisted backport review and checked this manually. The backport calls a helper that does not exist on 6.12.y.
The backport adds:
(cd $TRACING_DIR; initialize_system)
But 6.12.y defines:
initialize_ftrace()
The helper rename came from upstream commit a0aa283c53a7, which is not present on this branch. I think this is a wrong adaptation;
Lets drop it, as we anyway don't backport selftests apart from bpf to stable ?
thanks,
harshit
Quoted 5 lines
tools/testing/selftests/ftrace/ftracetest +0
-0for t in $TEST_CASES; do test_on_instance $t || continue
Greg Kroah-Hartman
maintainerPATCH 420/602 rbd: Reset positive result codes to zero in object map update path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphael Zimmer <[email protected]>
commit a6c4250b81bd30beae94e1b7a4b26fa1193ad2e4 upstream.
In a reply message to an RBD request, a positive result code indicates a data payload, which is not allowed for writes. While rbd_osd_req_callback() already resets a positive result code for writes to zero, rbd_object_map_callback() does not. This allows a corrupted reply to an object map update to trigger the rbd_assert(*result < 0) in __rbd_obj_handle_request(). This happens, because rbd_object_map_callback() calls rbd_obj_handle_request() -> __rbd_obj_handle_request() and passes this positive result code. From __rbd_obj_handle_request(), rbd_obj_advance_write() is called, which leaves the positive result code unchanged and returns true. Therefore, the if(done && *result) branch is executed in __rbd_obj_handle_request() and the assertion triggers.
This patch fixes the issue by adjusting the logic in the rbd_object_map_callback() path. A positive result code for an object map update is now reset to zero (similar to rbd_osd_req_callback()), and the message is subsequently handled the same way as if the result code was zero from the beginning. Additionally, a WARN_ON_ONCE() is added for this case.
--- drivers/block/rbd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/block/rbd.c +6 -1
@@ -1957,10 +1957,15 @@ static int rbd_object_map_update_finish(bool has_current_state;void *p; -if (osd_req->r_result) +if (osd_req->r_result <0 )return osd_req->r_result;/* +* Writes aren't allowed to return a data payload. +*/ +WARN_ON_ONCE (osd_req->r_result >0 ); + +/* * Nothing to do for a snapshot object map. */ if (osd_req->r_num_ops ==1 )
Greg Kroah-Hartman
maintainerPATCH 421/602 ksmbd: defer destroy_previous_session() until after NTLM authentication
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Montgomery <[email protected]>
commit c74801ee524f477c174a1899782b6c3b6918d407 upstream.
In ntlm_authenticate(), destroy_previous_session() is called using a user pointer resolved from the client-supplied NTLM blob username field before the NTLMv2 response is validated. An authenticated attacker can set the NTLM blob username to match a victim account and set PreviousSessionId to the victim's session ID; destroy_previous_session() destroys the victim's session while ksmbd_decode_ntlmssp_auth_blob() subsequently rejects the request with -EPERM.
Move destroy_previous_session() and the prev_id assignment to after ksmbd_decode_ntlmssp_auth_blob() returns success and use sess->user rather than the pre-authentication lookup result. This matches the ordering already used by krb5_authenticate(), where destroy_previous_session() is called only after ksmbd_krb5_authenticate() returns success.
--- fs/smb/server/smb2pdu.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/smb/server/smb2pdu.c +4 -5
@@ -1489,11 +1489,6 @@ static int ntlm_authenticate(struct ksmbreturn -EPERM ; } -/* Check for previous session */ - prev_id =le64_to_cpu (req->PreviousSessionId); -if (prev_id && prev_id != sess->id) -destroy_previous_session (conn, user, prev_id); -if (sess->state ==SMB2_SESSION_VALID ) {/* * Reuse session if anonymous try to connect
@@ -1531,6 +1526,10 @@ static int ntlm_authenticate(struct ksmb } } + prev_id =le64_to_cpu (req->PreviousSessionId); +if (prev_id && prev_id != sess->id) +destroy_previous_session (conn, sess->user, prev_id); +/* * If session state is SMB2_SESSION_VALID, We can assume * that it is reauthentication. And the user/password
Greg Kroah-Hartman
maintainerPATCH 422/602 ice: reject out-of-range ptype in ice_parser_profile_init
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Loktionov <[email protected]>
commit 59abb87159c53605c063f6e2ceb215b5eba43ee6 upstream.
set_bit(rslt->ptype, prof->ptypes) operates on a DECLARE_BITMAP of ICE_FLOW_PTYPE_MAX (1024) bits. Nothing prevents a malicious VF from providing ptype >= 1024 through VIRTCHNL, resulting in a write past the end of the bitmap and a kernel page fault.
Reproduced with a custom kernel module injecting a crafted VIRTCHNL_OP_ADD_RSS_CFG on E810-C QSFP (8086:1592), FW 4.91 0x800214af 1.3909.0, ICE COMMS DDP 1.3.53.0, kernel 7.1.0-rc1.
crash_parser: ice_parser_profile_init @ ffffffffc0d61b60crash_parser: setting ptype=0xffff (max valid=1023)crash_parser: calling ice_parser_profile_init -- expect OOB crash!
BUG: kernel NULL pointer dereference, address: 0000000000000000 Oops: Oops: 0002 [#1] SMP NOPTI CPU: 56 UID: 0 PID: 165011 Comm: insmod Kdump: loaded Tainted: G S U OE 7.1.0-rc1 #1 Hardware name: Intel Corporation S2600BPB/S2600BPB RIP: 0010:ice_parser_profile_init+0x2d/0x1d0 [ice] Call Trace: <TASK> ? __pfx_ice_parser_profile_init+0x10/0x10 [ice] crash_init+0x127/0xff0 [crash_parser] do_one_initcall+0x45/0x310 do_init_module+0x64/0x270 init_module_from_file+0xcc/0xf0 idempotent_init_module+0x17b/0x280 __x64_sys_finit_module+0x6e/0xe0
Bail out early with -EINVAL when ptype is out of range.
--- drivers/net/ethernet/intel/ice/ice_parser.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/intel/ice/ice_parser.c +3 -0
@@ -2368,6 +2368,9 @@ int ice_parser_profile_init(struct ice_pu16 proto_off =0 ;u16 off; +if (rslt->ptype >=ICE_FLOW_PTYPE_MAX ) +return -EINVAL ; +memset (prof,0 ,sizeof (*prof));set_bit (rslt->ptype, prof->ptypes);if (blk ==ICE_BLK_SW ) {
Greg Kroah-Hartman
maintainerPATCH 423/602 ice: use READ_ONCE() to access cached PHC time
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergey Temerkhanov <[email protected]>
commit 2915681b89f817677ab9f1166d95b595bc144f5f upstream.
ptp.cached_phc_time is a 64-bit value updated by a periodic work item on one CPU and read locklessly on another. On 32-bit or non-atomic architectures this can result in a torn read. Use READ_ONCE() to enforce a single atomic load.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -1
@@ -514,7 +514,7 @@ static u64 ice_ptp_extend_40b_ts(structreturn 0 ; } -return ice_ptp_extend_32b_ts (pf->ptp.cached_phc_time, +return ice_ptp_extend_32b_ts (READ_ONCE (pf->ptp.cached_phc_time), (in_tstamp >>8 ) & mask); }
Greg Kroah-Hartman
maintainerPATCH 424/602 ila: reload IPv6 header after pskb_may_pull in checksum adjust
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 92d3817649df2b0b6a008a686c8275c88d7ef594 upstream.
ila_csum_adjust_transport() caches ip6h = ipv6_hdr(skb) before calling pskb_may_pull(). On a non-linear skb whose transport header sits in a page fragment, pskb_may_pull() can call __pskb_pull_tail() / pskb_expand_head() and free the old skb head, leaving ip6h dangling; the following get_csum_diff(ip6h, p) then reads freed memory. ila_update_ipv6_locator() uses ip6h (and the iaddr derived from it) again after the csum-adjust call and additionally writes the new locator through that pointer.
Impact: a remote IPv6 packet routed through a configured ILA csum-adjust-transport route or receive-side mapping triggers a slab-use-after-free in ila_update_ipv6_locator() (KASAN). The route or mapping requires CAP_NET_ADMIN to configure, but trigger packets are unauthenticated once it exists.
Reload ip6h after each pskb_may_pull() in ila_csum_adjust_transport() before the csum-diff read. In ila_update_ipv6_locator() only the ILA_CSUM_ADJUST_TRANSPORT case pulls the skb, so reload ip6h and iaddr in that case alone before the destination-address write; the neutral-map modes never pull and keep their cached pointers.
--- net/ipv6/ila/ila_common.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/ipv6/ila/ila_common.c +12 -0
@@ -84,6 +84,7 @@ static void ila_csum_adjust_transport(ststruct tcphdr *th = (struct tcphdr *) (skb_network_header (skb) + nhoff); + ip6h =ipv6_hdr (skb); diff =get_csum_diff (ip6h, p);inet_proto_csum_replace_by_diff (&th->check, skb, diff, true, true);
@@ -95,6 +96,7 @@ static void ila_csum_adjust_transport(st (skb_network_header (skb) + nhoff);if (uh->check || skb->ip_summed ==CHECKSUM_PARTIAL ) { + ip6h =ipv6_hdr (skb); diff =get_csum_diff (ip6h, p);inet_proto_csum_replace_by_diff (&uh->check, skb, diff, true, true);
@@ -109,6 +111,7 @@ static void ila_csum_adjust_transport(ststruct icmp6hdr *ih = (struct icmp6hdr *) (skb_network_header (skb) + nhoff); + ip6h =ipv6_hdr (skb); diff =get_csum_diff (ip6h, p);inet_proto_csum_replace_by_diff (&ih->icmp6_cksum, skb, diff, true, true);
@@ -126,6 +129,15 @@ void ila_update_ipv6_locator(struct sk_bswitch (p->csum_mode) {case ILA_CSUM_ADJUST_TRANSPORT :ila_csum_adjust_transport (skb, p); +/* +* ila_csum_adjust_transport() calls pskb_may_pull(), which can +* reallocate the skb head and leave ip6h (and the iaddr derived +* from it) dangling; reload both before the write below. The +* other csum modes do not pull, so their cached pointers stay +* valid. +*/ + ip6h =ipv6_hdr (skb); + iaddr =ila_a2i (&ip6h->daddr);break ;case ILA_CSUM_NEUTRAL_MAP :if (sir2ila) {
Greg Kroah-Hartman
maintainerPATCH 425/602 mac802154: hold an interface reference across the scan worker
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
commit 234e5e898b713bc0b3a631b6f002897f43d046c8 upstream.
mac802154_scan_worker() captures the scanning sub-interface under RCU and then keeps dereferencing sdata->dev after rcu_read_unlock() and outside the rtnl -- in the failure traces, in mac802154_transmit_beacon_req() (skb->dev = sdata->dev), and in the end_scan cleanup. Nothing keeps that netdev alive across the worker iteration.
A concurrent DEL_INTERFACE or PHY removal can unregister the interface once the worker drops the rtnl between its two drv_set_channel() sections. unregister_netdevice() frees the netdev asynchronously from netdev_run_todo() with the rtnl already dropped, so neither holding the rtnl nor the per-PHY IEEE802154_IS_SCANNING flag prevents a stale worker iteration from dereferencing the freed netdev -- a KASAN slab-use-after-free, reachable by racing TRIGGER_SCAN against DEL_INTERFACE (both CAP_NET_ADMIN).
Pin the netdev with netdev_hold() while the RCU read lock is still held, and release it at every worker exit.
--- net/mac802154/scan.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/mac802154/scan.c +11 -0
@@ -179,6 +179,7 @@ void mac802154_scan_worker(struct work_senum nl802154_scan_types scan_req_type;struct ieee802154_sub_if_data *sdata;unsigned int scan_duration =0 ; +netdevice_tracker dev_tracker;struct wpan_phy *wpan_phy;u8 scan_req_duration;u8 page, channel;
@@ -209,6 +210,14 @@ void mac802154_scan_worker(struct work_sreturn ; } +/* +* sdata->dev is dereferenced below after rcu_read_unlock() and outside +* the rtnl, and a concurrent DEL_INTERFACE / PHY teardown can free it +* asynchronously from netdev_run_todo(). Pin it with a reference taken +* while the RCU read lock is still held, and drop it at every exit. +*/ +netdev_hold (sdata->dev, &dev_tracker,GFP_ATOMIC ); + wpan_phy = scan_req->wpan_phy; scan_req_type = scan_req->type; scan_req_duration = scan_req->duration;
@@ -262,12 +271,14 @@ void mac802154_scan_worker(struct work_s"Scan page %u channel %u for %ums\n" , page, channel, jiffies_to_msecs(scan_duration));queue_delayed_work (local->mac_wq, &local->scan_work, scan_duration); +netdev_put (sdata->dev, &dev_tracker);return ; end_scan:rtnl_lock ();mac802154_scan_cleanup_locked (local, sdata, false);rtnl_unlock (); +netdev_put (sdata->dev, &dev_tracker); } int mac802154_trigger_scan_locked(struct ieee802154_sub_if_data *sdata,
Greg Kroah-Hartman
maintainerPATCH 426/602 mac802154: llsec: reject frames shorter than the authentication tag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit fd3a3f28ed60c6af4b2a39933b151d6b27842c3b upstream.
llsec_do_decrypt_auth() computes the associated-data length for the AEAD request as
assoclen += datalen - authlen;
where datalen is the number of bytes after the MAC header and authlen (4, 8 or 16) is the length of the authentication tag. Nothing verifies that the frame actually carries at least authlen payload bytes. A secured frame whose payload is shorter than the tag makes datalen - authlen negative; assoclen is then passed to aead_request_set_ad() as an unsigned value close to 4 GiB, so crypto_aead_decrypt() walks far off the end of the scatterlist that only spans the real frame.
The frame is fully attacker-controlled and reaches this path from any IEEE 802.15.4 peer in radio range. Reject frames whose payload is shorter than the authentication tag before the subtraction.
Dynamically reproduced on a KASAN kernel as a general-protection-fault in the AEAD scatterwalk, and the fix confirmed.
--- net/mac802154/llsec.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mac802154/llsec.c +5 -0
@@ -891,6 +891,11 @@ llsec_do_decrypt_auth(struct sk_buff *sk data =skb_mac_header (skb) + skb->mac_len; datalen =skb_tail_pointer (skb) - data; +if (datalen < authlen) { +kfree_sensitive (req); +return -EBADMSG ; + } +sg_init_one (&sg,skb_mac_header (skb), assoclen + datalen);if (!(hdr->sec.level &IEEE802154_SCF_SECLEVEL_ENC )) {
Greg Kroah-Hartman
maintainerPATCH 427/602 mctp: serial: handle zero-length frames to prevent rx buffer overflow
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 793b9b729f1e8de57be8c8daf1a9838be96cabed upstream.
The MCTP serial receive state machine reads a frame length byte in mctp_serial_push_header() case 2 and validates it upper-bound-only:
if (c > MCTP_SERIAL_FRAME_MTU) {
dev->rxstate = STATE_ERR;
} else {
dev->rxlen = c;
dev->rxpos = 0;
dev->rxstate = STATE_DATA;
...
}A length of zero passes this check, so rxlen is set to 0 and the state machine advances to STATE_DATA. In mctp_serial_push() STATE_DATA, the incoming byte is stored and rxpos incremented before the terminator is tested:
dev->rxbuf[dev->rxpos] = c;
dev->rxpos++;
dev->rxstate = STATE_DATA;
if (dev->rxpos == dev->rxlen) {
dev->rxpos = 0;
dev->rxstate = STATE_TRAILER;
}With rxlen == 0 the "rxpos == rxlen" terminator can never fire (rxpos is already 1 on the first data byte), so subsequent bytes are written past the end of the fixed 74-byte rxbuf, which is the last member of the netdev private area. Every following data byte is an attacker-controlled 1-byte out-of-bounds heap write, and the overflow continues until a frame (0x7e) or escape byte resets the parser -- effectively unbounded.
Reaching this requires CAP_NET_ADMIN to attach the N_MCTP line discipline and bring the resulting mctpserialN netdev up, after which the bytes arrive via the tty receive path.
Route a zero-length frame straight to STATE_TRAILER instead of STATE_DATA. The trailer/framing bytes are still consumed, and the frame resolves to a zero-length skb that the MCTP core rejects; the parser never enters STATE_DATA with rxlen == 0, so the out-of-bounds write can no longer occur.
KASAN, on a frame of 0x7e 0x01 0x00 followed by data bytes (before this change):
UBSAN: array-index-out-of-bounds in drivers/net/mctp/mctp-serial.c:370 index 74 is out of range for type 'u8 [74]' BUG: KASAN: slab-out-of-bounds in mctp_serial_tty_receive_buf Write of size 1 at addr ... by task kworker/u16:0 mctp_serial_tty_receive_buf tty_ldisc_receive_buf flush_to_ldisc Allocated by task 152: alloc_netdev_mqs mctp_serial_open
v2: route zero-length frames to STATE_TRAILER instead of STATE_ERR so
the trailer/framing bytes are still consumed (Jeremy Kerr).
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/mctp/mctp-serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mctp/mctp-serial.c +1 -1
@@ -317,7 +317,7 @@ static void mctp_serial_push_header(stru }else { dev->rxlen = c; dev->rxpos =0 ; - dev->rxstate =STATE_DATA ; + dev->rxstate = c >0 ?STATE_DATA :STATE_TRAILER ; dev->rxfcs =crc_ccitt_byte (dev->rxfcs, c); }break ;
Greg Kroah-Hartman
maintainerPATCH 428/602 openvswitch: fix GSO userspace truncation underflow
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
commit 4032f8ed10fcb84d41c508dfb04be96589f78dfe upstream.
OVS_ACTION_ATTR_TRUNC currently stores a delta from the original skb length in OVS_CB(skb)->cutlen. When a later userspace action segments a GSO skb, queue_gso_packets() reuses that delta for each smaller segment. A segment can then reach queue_userspace_packet() with cutlen greater than skb->len, underflowing the length passed to skb_zerocopy().
Store the maximum preserved length instead and bound each consumer against the current skb length. Use U32_MAX as the no-truncation sentinel so the value remains valid if skb geometry changes before a consumer handles it.
--- net/openvswitch/actions.c | 19 +++++++------------ net/openvswitch/datapath.c | 25 ++++++++++++++----------- net/openvswitch/datapath.h | 2 +- net/openvswitch/vport.c | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-)
net/openvswitch/actions.c +7 -12
@@ -877,12 +877,8 @@ static void do_output(struct datapath *du16 mru =OVS_CB (skb)->mru;u32 cutlen =OVS_CB (skb)->cutlen; -if (unlikely (cutlen >0 )) { -if (skb->len - cutlen >ovs_mac_header_len (key)) -pskb_trim (skb, skb->len - cutlen); -else -pskb_trim (skb,ovs_mac_header_len (key)); - } +if (unlikely (cutlen < skb->len)) +pskb_trim (skb,max (cutlen,ovs_mac_header_len (key)));if (likely (!mru || (skb->len <= mru + vport->dev->hard_header_len))) {
@@ -1272,7 +1268,7 @@ static void execute_psample(struct datap psample_group.net =ovs_dp_get_net (dp); md.in_ifindex =OVS_CB (skb)->input_vport->dev->ifindex; - md.trunc_size = skb->len -OVS_CB (skb)->cutlen; + md.trunc_size =min (skb->len,OVS_CB (skb)->cutlen); md.rate_as_probability =1 ; rate =OVS_CB (skb)->probability ?OVS_CB (skb)->probability :U32_MAX ;
@@ -1322,22 +1318,21 @@ static int do_execute_actions(struct dat clone =skb_clone (skb,GFP_ATOMIC );if (clone)do_output (dp, clone, port, key); -OVS_CB (skb)->cutlen =0 ; +OVS_CB (skb)->cutlen =U32_MAX ;break ; }case OVS_ACTION_ATTR_TRUNC : {struct ovs_action_trunc *trunc =nla_data (a); -if (skb->len > trunc->max_len) -OVS_CB (skb)->cutlen = skb->len - trunc->max_len; +OVS_CB (skb)->cutlen = trunc->max_len;break ; }case OVS_ACTION_ATTR_USERSPACE :output_userspace (dp, skb, key, a, attr, len,OVS_CB (skb)->cutlen); -OVS_CB (skb)->cutlen =0 ; +OVS_CB (skb)->cutlen =U32_MAX ;if (nla_is_last (a, rem)) {consume_skb (skb);return 0 ;
@@ -1491,7 +1486,7 @@ static int do_execute_actions(struct datcase OVS_ACTION_ATTR_PSAMPLE :execute_psample (dp, skb, a); -OVS_CB (skb)->cutlen =0 ; +OVS_CB (skb)->cutlen =U32_MAX ;if (nla_is_last (a, rem)) {consume_skb (skb);return 0 ;
net/openvswitch/datapath.c +14 -11
@@ -272,7 +272,7 @@ void ovs_dp_process_packet(struct sk_buf upcall.portid =ovs_vport_find_upcall_portid (p, skb); upcall.mru =OVS_CB (skb)->mru; - error =ovs_dp_upcall (dp, skb, key, &upcall,0 ); + error =ovs_dp_upcall (dp, skb, key, &upcall,U32_MAX );switch (error) {case 0 :case -EAGAIN :
@@ -437,7 +437,8 @@ static int queue_userspace_packet(structstruct sk_buff *nskb =NULL ;struct sk_buff *user_skb =NULL ;/* to be queued to userspace */ struct nlattr *nla; -size_t len; +size_t msg_size; +size_t skb_len;unsigned int hlen;int err, dp_ifindex;u64 hash;
@@ -458,7 +459,8 @@ static int queue_userspace_packet(struct skb = nskb; } -if (nla_attr_size (skb->len) >USHRT_MAX ) { + skb_len =min (skb->len, cutlen); +if (nla_attr_size (skb_len) >USHRT_MAX ) { err = -EFBIG ; goto out; }
@@ -473,13 +475,13 @@ static int queue_userspace_packet(struct* padding logic. Only perform zerocopy if padding is not required. */ if (dp->user_features &OVS_DP_F_UNALIGNED ) - hlen =skb_zerocopy_headlen (skb); + hlen =min (skb_zerocopy_headlen (skb), cutlen);else - hlen = skb->len; + hlen = skb_len; - len =upcall_msg_size (upcall_info, hlen - cutlen, -OVS_CB (skb)->acts_origlen); - user_skb =genlmsg_new (len,GFP_ATOMIC ); + msg_size =upcall_msg_size (upcall_info, hlen, +OVS_CB (skb)->acts_origlen); + user_skb =genlmsg_new (msg_size,GFP_ATOMIC );if (!user_skb) { err = -ENOMEM ; goto out;
@@ -540,7 +542,7 @@ static int queue_userspace_packet(struct }/* Add OVS_PACKET_ATTR_LEN when packet is truncated */ -if (cutlen >0 && +if (skb_len < skb->len &&nla_put_u32 (user_skb,OVS_PACKET_ATTR_LEN , skb->len)) { err = -ENOBUFS ; goto out;
@@ -565,9 +567,9 @@ static int queue_userspace_packet(struct err = -ENOBUFS ; goto out; } - nla->nla_len =nla_attr_size (skb->len - cutlen); + nla->nla_len =nla_attr_size (skb_len); - err =skb_zerocopy (user_skb, skb, skb->len - cutlen, hlen); + err =skb_zerocopy (user_skb, skb, skb_len, hlen);if (err) goto out;
@@ -624,6 +626,7 @@ static int ovs_packet_cmd_execute(struct packet->ignore_df =1 ; }OVS_CB (packet)->mru = mru; +OVS_CB (packet)->cutlen =U32_MAX ;if (a[OVS_PACKET_ATTR_HASH ]) { hash =nla_get_u64 (a[OVS_PACKET_ATTR_HASH ]);
net/openvswitch/datapath.h +1 -1
@@ -114,7 +114,7 @@ struct datapath {* @mru: The maximum received fragement size; 0 if the packet is not * fragmented. * @acts_origlen: The netlink size of the flow actions applied to this skb. -* @cutlen: The number of bytes from the packet end to be removed. +* @cutlen: The number of bytes in the packet to preserve on output. * @probability: The sampling probability that was applied to this skb; 0 means * no sampling has occurred; U32_MAX means 100% probability. */
net/openvswitch/vport.c +1 -1
@@ -503,7 +503,7 @@ int ovs_vport_receive(struct vport *vporOVS_CB (skb)->input_vport = vport;OVS_CB (skb)->mru =0 ; -OVS_CB (skb)->cutlen =0 ; +OVS_CB (skb)->cutlen =U32_MAX ;OVS_CB (skb)->probability =0 ;if (unlikely (dev_net (skb->dev) !=ovs_dp_get_net (vport->dp))) {u32 mark;
Greg Kroah-Hartman
maintainerPATCH 429/602 pppoe: reload header pointer after dev_hard_header()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Asim Viladi Oglu Manizada <[email protected]>
commit e9c238f6fe42fb1b4dba3a578277de32cb487937 upstream.
pppoe_sendmsg() saves a pointer to the PPPoE header before calling dev_hard_header(). Device header callbacks are allowed to reallocate the skb head, invalidating pointers into it.
This can happen when a send is blocked in copy_from_user() while the first non-Ethernet port is added to an empty team device. The team's delegated GRE header callback then expands the skb head. PPPoE subsequently writes six bytes through the stale pointer into the freed head.
Reload the PPPoE header through the skb's network-header offset after device header creation. pskb_expand_head() updates that offset when it relocates the head.
--- drivers/net/ppp/pppoe.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ppp/pppoe.c +1 -0
@@ -900,6 +900,7 @@ static int pppoe_sendmsg(struct socket *dev_hard_header (skb, dev,ETH_P_PPP_SES , po->pppoe_pa.remote,NULL , total_len); + ph =pppoe_hdr (skb);memcpy (ph, &hdr,sizeof (struct pppoe_hdr )); ph->length =htons (total_len);
Greg Kroah-Hartman
maintainerPATCH 430/602 rtase: Workaround for TX hang caused by hardware packet parsing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Lai <[email protected]>
commit 1c50efa1faf3a1a96e100b07ec7a2f3164d90bee upstream.
The hardware performs packet parsing before packet transmission. Parsing incomplete IPv4, IPv6, TCP, or UDP headers may trigger a TX hang because the hardware parser expects additional protocol header data that is not present in the packet.
The hardware performs additional PTP parsing on UDP packets identified by destination ports 319/320 at the expected UDP destination port offset.
If such a packet has transport data smaller than RTASE_MIN_PAD_LEN, the hardware parser expects additional packet data and may trigger a TX hang.
To avoid these hardware issues, the driver applies the following workarounds.
Drop malformed packets that may trigger this hardware issue before transmission.
For IPv4 non-initial fragments, the hardware does not check the fragment offset before parsing the expected transport header location. As a result, these packets are still subject to transport header parsing even though they do not contain a transport header. If the transport data is shorter than the minimum transport header required by the hardware parser, pad the transport data to the minimum transport header length required by the hardware parser. Packets that also match the hardware PTP parsing conditions continue to follow the corresponding workaround.
For IPv6 fragmented packets, neither of the above hardware issues occurs because the hardware only continues packet parsing when the IPv6 Base Header Next Header field directly indicates UDP. Packets carrying a Fragment Header do not continue through the subsequent packet parsing stages.
For packets identified for hardware PTP parsing, pad the transport data so it reaches RTASE_MIN_PAD_LEN before transmission.
--- drivers/net/ethernet/realtek/rtase/rtase.h | 8 drivers/net/ethernet/realtek/rtase/rtase_main.c | 197 ++++++++++++++++++++++++ 2 files changed, 205 insertions(+)
drivers/net/ethernet/realtek/rtase/rtase.h +8 -0
@@ -186,6 +186,12 @@ enum rtase_sw_flag_content { RTASE_SWF_MSIX_ENABLED = BIT(2), }; +enum rtase_parse_result { +RTASE_PARSE_OK , +RTASE_PARSE_SKIP , +RTASE_PARSE_DROP , +}; +#define RSVD_MASK 0x3FFFC000struct rtase_tx_desc {
@@ -342,4 +348,6 @@ struct rtase_private {#define RTASE_MSS_MASK GENMASK(28, 18) +#define RTASE_MIN_PAD_LEN 47 +#endif /* RTASE_H */
drivers/net/ethernet/realtek/rtase/rtase_main.c +197 -0
215 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 431/602 tcp: initialize standalone TCP-AO response padding
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
commit e1a9d3cc11829c5414a75eb39c704f461936eb24 upstream.
tcp_v4_send_ack() and tcp_v6_send_response() construct standalone TCP responses with TCP-AO options. The option length carries the actual MAC length, but the TCP header length includes the option rounded up to a four-byte boundary.
tcp_ao_hash_hdr() writes the MAC only. Thus, when the MAC length is not four-byte aligned, the one to three bytes after the MAC are left uninitialized and may be transmitted. For the normal TCP-AO hashing mode, those bytes also have to be initialized before computing the MAC.
Initialize only the alignment padding in the TCP-AO branches, before hashing the header. Use TCPOPT_NOP, as in the normal TCP-AO output path. This avoids adding work to non-AO TCP responses while preserving a valid authenticated header.
--- net/ipv4/tcp_ipv4.c | 3 +++ net/ipv6/tcp_ipv6.c | 2 ++ 2 files changed, 5 insertions(+)
net/ipv4/tcp_ipv4.c +3 -0
@@ -993,6 +993,9 @@ static void tcp_v4_send_ack(const struct key->rcv_next); arg.iov[0 ].iov_len +=tcp_ao_len_aligned (key->ao_key); rep.th.doff = arg.iov[0 ].iov_len /4 ; +memset ((u8 *)&rep.opt[offset] +tcp_ao_maclen (key->ao_key), +TCPOPT_NOP ,tcp_ao_len_aligned (key->ao_key) - +tcp_ao_len (key->ao_key)); tcp_ao_hash_hdr(AF_INET, (char *)&rep.opt[offset], key->ao_key, key->traffic_key,
net/ipv6/tcp_ipv6.c +2 -0
@@ -936,6 +936,8 @@ static void tcp_v6_send_response(const s (tcp_ao_len (key->ao_key) <<16 ) | (key->ao_key->sndid <<8 ) | (key->rcv_next)); +memset ((u8 *)topt +tcp_ao_maclen (key->ao_key),TCPOPT_NOP , +tcp_ao_len_aligned (key->ao_key) -tcp_ao_len (key->ao_key)); tcp_ao_hash_hdr(AF_INET6, (char *)topt, key->ao_key, key->traffic_key,
Greg Kroah-Hartman
maintainerPATCH 432/602 tipc: clear sock->sk on the failed-insert path in tipc_sk_create()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
commit ba0533fc163f905fe817cfabdf8ed4058da44800 upstream.
When tipc_sk_create() fails to insert the new socket (tipc_sk_insert() returns non-zero), its error path frees the sk with sk_free() but leaves sock->sk pointing at the freed object:
if (tipc_sk_insert(tsk)) {
sk_free(sk);
pr_warn("Socket create failed; port number exhausted\n");
return -EINVAL;
}This is harmless for plain socket(): the syscall layer clears sock->ops before releasing, so tipc_release() is never called. It is not harmless on the accept() path. tipc_accept() creates the pre-allocated child socket with tipc_sk_create(net, new_sock, 0, kern); on failure it leaves new_sock->sk dangling and new_sock->ops non-NULL, and do_accept() then fput()s the new file, so __sock_release() -> tipc_release() runs lock_sock(new_sock->sk) on the freed sk -- a use-after-free write of the sk_lock spinlock.
tipc_release() already guards this exact "failed accept() releases a pre-allocated child" case with "if (sk == NULL) return 0;", but the guard is bypassed because tipc_sk_create() left sock->sk non-NULL (dangling) rather than NULL.
Clear sock->sk on the failed-insert path so the existing tipc_release() NULL check fires and the use-after-free is avoided.
The tipc_sk_insert() failure is reached when the per-netns socket rhashtable hits its max_size (tsk_rht_params.max_size = 1048576, ~2M elements) -- i.e. once a netns holds ~2M TIPC sockets every insert returns -E2BIG.
BUG: KASAN: slab-use-after-free in lock_sock_nested (net/core/sock.c:3839) Write of size 8 at addr ffff8880047cdc38 by task init/1 lock_sock_nested (net/core/sock.c:3839) tipc_release (net/tipc/socket.c:638) __sock_release (net/socket.c:710) sock_close (net/socket.c:1501) __fput (fs/file_table.c:512) Allocated by task 1: sk_alloc (net/core/sock.c:2308) tipc_sk_create (net/tipc/socket.c:487) tipc_accept (net/tipc/socket.c:2744) do_accept (net/socket.c:2034) Freed by task 1: __sk_destruct (net/core/sock.c:2391) tipc_sk_create (net/tipc/socket.c:504) tipc_accept (net/tipc/socket.c:2744) do_accept (net/socket.c:2034)
--- net/tipc/socket.c | 1 + 1 file changed, 1 insertion(+)
net/tipc/socket.c +1 -0
@@ -501,6 +501,7 @@ static int tipc_sk_create(struct net *netipc_set_sk_state (sk,TIPC_OPEN );if (tipc_sk_insert (tsk)) {sk_free (sk); + sock->sk =NULL ;pr_warn ("Socket create failed; port number exhausted\n" );return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 433/602 vsock/virtio: collapse receive queue under memory pressure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefano Garzarella <[email protected]>
commit 2a12c05aef213ff304ecc9e2f351de20731946b8 upstream.
When many small packets accumulate in the receive queue, the skb overhead can exceed buf_alloc even while the payload is within bounds. This causes virtio_transport_inc_rx_pkt() to reject packets, leading to connection resets during large transfers under backpressure.
The issue was reported by Brien, who has a reproducer, but it is also easily reproducible with iperf-vsock [1] using a small packet size:
iperf3 --vsock -c $CID -l 129
which fails immediately without this patch but with commit 059b7dbd20a6 ("vsock/virtio: fix potential unbounded skb queue").
Inspired by TCP's tcp_collapse() which solves a similar problem, add virtio_transport_collapse_rx_queue() that walks the receive queue and re-copies data into compact linear skbs to reduce the overhead.
The collapse is triggered proactively from when the number of skb queued is close to exceeding the overhead budget.
A pre-scan counts the eligible bytes to size each allocation precisely, avoiding waste for isolated small packets. Partially consumed skbs are kept as-is to preserve buf_used/fwd_cnt accounting, EOM-marked skbs to maintain SEQPACKET message boundaries, and skbs already larger than the collapse target because they already have a good data-to-overhead ratio.
Walking a large queue may take a significant amount of time and cache misses, causing traffic burstiness. To limit this, the collapse stops once enough room is freed for this packet and the next one, but may opportunistically free more to fill each collapsed skb to capacity.
[1] https://github.com/stefano-garzarella/iperf-vsock
--- net/vmw_vsock/virtio_transport_common.c | 165 +++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +164 -1
@@ -26,6 +26,13 @@/* Threshold for detecting small packets to copy */ #define GOOD_COPY_LEN 128 +/* Max payload that can be collapsed into a single linear skb, using the same +* allocation threshold as virtio_vsock_alloc_skb() to avoid adding pressure +* on the page allocator. +*/ +#define MAX_COLLAPSE_LEN \ + SKB_MAX_ORDER(VIRTIO_VSOCK_SKB_HEADROOM, PAGE_ALLOC_COSTLY_ORDER) +static void virtio_transport_cancel_close_work (struct vsock_sock *vsk,bool cancel_timeout);static s64 virtio_transport_has_space (struct virtio_vsock_sock *vvs);
@@ -423,6 +430,145 @@ static int virtio_transport_send_pkt_infreturn ret; } +static bool virtio_transport_can_collapse (struct sk_buff *skb) +{ +/* skbs that are partially consumed, mark a SEQPACKET message boundary, +* or are already large enough should not be collapsed: they either +* need special accounting, carry protocol state, or already have a +* good data-to-overhead ratio. +*/ +if (VIRTIO_VSOCK_SKB_CB (skb)->offset) +return false; +if (le32_to_cpu (virtio_vsock_hdr (skb)->flags) &VIRTIO_VSOCK_SEQ_EOM ) +return false; +if (skb->len >=MAX_COLLAPSE_LEN ) +return false; +return true; +} + +/* Iterate through the packets in the queue starting from the current skb to +* count the number of bytes we can collapse. +*/ +static unsigned int +virtio_transport_collapse_size (struct sk_buff *skb,struct sk_buff_head *queue) +{ +unsigned int target = skb->len -VIRTIO_VSOCK_SKB_CB (skb)->offset; + +while ((skb =skb_peek_next (skb, queue)) && +virtio_transport_can_collapse (skb)) { +unsigned int len = skb->len -VIRTIO_VSOCK_SKB_CB (skb)->offset; + +if (len >MAX_COLLAPSE_LEN - target) +return target; + + target += len; + } + +return target; +} + +/* Called under lock_sock to compact the receive queue by merging small skbs. +* @min_to_free: minimum number of skbs to eliminate from the queue. May free +* more to fill each collapsed skb to capacity. +*/ +static void +virtio_transport_collapse_rx_queue (struct virtio_vsock_sock *vvs, +u32 min_to_free) +{ +struct sk_buff *skb, *next_skb, *new_skb =NULL ; +struct sk_buff_head new_queue; +u32 saved =0 ; + +__skb_queue_head_init (&new_queue); + + skb_queue_walk_safe(&vvs->rx_queue, skb, next_skb) { +struct virtio_vsock_hdr *hdr =virtio_vsock_hdr (skb); +u32 src_off =VIRTIO_VSOCK_SKB_CB (skb)->offset; +u32 src_len = skb->len - src_off; +bool keep; + + keep = !virtio_transport_can_collapse (skb); +if (keep) { +/* Finalize pending collapsed skb to preserve packet +* ordering. +*/ +if (new_skb) { +__skb_queue_tail (&new_queue, new_skb); + new_skb =NULL ; + saved--; + } + goto next; + } + +/* Finalize if this packet won't fit in the remaining tailroom, +* so we can allocate a right-sized new_skb. +*/ +if (new_skb && src_len >skb_tailroom (new_skb)) { +__skb_queue_tail (&new_queue, new_skb); + new_skb =NULL ; + saved--; + } + +if (!new_skb) { +unsigned int alloc_size; + +/* Check after finalizing to opportunistically fill +* each collapsed skb to capacity, merging more skbs +* than strictly required. +*/ +if (saved >= min_to_free) +break ; + + alloc_size =virtio_transport_collapse_size (skb, &vvs->rx_queue); + +/* Only this skb's data is eligible, nothing to merge +* with. Keep as-is. +*/ +if (alloc_size <= src_len) { + keep = true; + goto next; + } + + new_skb =virtio_vsock_alloc_linear_skb (alloc_size + +VIRTIO_VSOCK_SKB_HEADROOM ,GFP_KERNEL ); +if (!new_skb) +break ; + +memcpy (virtio_vsock_hdr (new_skb), hdr, +sizeof (struct virtio_vsock_hdr )); +virtio_vsock_hdr (new_skb)->len =0 ; + } + +/* Cannot fail since src_off/src_len are within bounds, but if +* it does, discard new_skb to avoid queuing corrupted data. +*/ +if (WARN_ON_ONCE (skb_copy_bits (skb, src_off, +skb_put (new_skb, src_len), + src_len))) { +kfree_skb (new_skb); + new_skb =NULL ; +break ; + } + +le32_add_cpu (&virtio_vsock_hdr (new_skb)->len, src_len); +virtio_vsock_hdr (new_skb)->flags |= hdr->flags; + +next: +__skb_unlink (skb, &vvs->rx_queue); +if (keep) { +__skb_queue_tail (&new_queue, skb); + }else { +consume_skb (skb); + saved++; + } + } + +if (new_skb) +__skb_queue_tail (&new_queue, new_skb); + +skb_queue_splice (&new_queue, &vvs->rx_queue); +} +static bool virtio_transport_inc_rx_pkt (struct virtio_vsock_sock *vvs,u32 len) {
@@ -1359,12 +1505,29 @@ virtio_transport_recv_enqueue(struct vso {struct virtio_vsock_sock *vvs = vsk->trans;bool can_enqueue, free_pkt = false; +u32 len, queue_max, queue_len;struct virtio_vsock_hdr *hdr; -u32 len; hdr =virtio_vsock_hdr (skb); len =le32_to_cpu (hdr->len); +/* virtio_transport_inc_rx_pkt() rejects packets when the per-skb +* overhead (skb_queue_len * SKB_TRUESIZE(0)) exceeds buf_alloc. +* Proactively collapse the queue before that happens. +* No rx_lock needed: lock_sock is held by caller, preventing +* concurrent enqueue or dequeue. +*/ + queue_max = vvs->buf_alloc /SKB_TRUESIZE (0 ); + queue_len =skb_queue_len (&vvs->rx_queue); +if (queue_len >= queue_max) { +/* Walking a large queue may take a significant amount of time +* and cache misses, causing traffic burstiness. Limit the +* collapse to freeing room for this packet and the next one. +* It may free more to fill each collapsed skb to capacity. +*/ +virtio_transport_collapse_rx_queue (vvs, queue_len +2 - queue_max); + } +spin_lock_bh (&vvs->rx_lock); can_enqueue =virtio_transport_inc_rx_pkt (vvs, len);
Greg Kroah-Hartman
maintainerPATCH 434/602 vxlan: mdb: Fix source list corruption on a failed replace
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Raphael Tiovalen <[email protected]>
commit dcd9b465965422b9654f6026e8a2fa8984f74c3c upstream.
When replacing the source list of an MDB remote entry, all existing sources are first marked for deletion and vxlan_mdb_remote_srcs_add() is then called to add the new source list. Sources present in the new list have their deletion mark cleared, and any sources left marked afterwards are removed.
If vxlan_mdb_remote_srcs_add() fails partway through, its error path deletes all entries on the remote's source list. That rollback is only correct for its other caller, vxlan_mdb_remote_add(), where the remote was just allocated and the list contains solely entries added during the call. On the replace path the list also holds pre-existing sources, so a failed replace tears them down together with their (S, G) forwarding entries instead of leaving the entry unchanged.
This is reachable from an existing (*, G) remote. An EXCLUDE filter that loses sources starts forwarding traffic that should be blocked, while an INCLUDE filter that loses sources drops traffic that should be forwarded.
Mark entries created during the current pass with a new VXLAN_SGRP_F_NEW flag. On failure, delete only those entries and clear the deletion mark on the pre-existing ones, so a failed replace leaves the source list untouched. Retain the flag until the whole operation succeeds and then clear it. Also stop vxlan_mdb_remote_src_add() from deleting a pre-existing entry it only looked up when adding that entry's forwarding entry fails.
--- drivers/net/vxlan/vxlan_mdb.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/net/vxlan/vxlan_mdb.c +18 -12
@@ -42,6 +42,7 @@ struct vxlan_mdb_remote { };#define VXLAN_SGRP_F_DELETE BIT(0) +#define VXLAN_SGRP_F_NEW BIT(1)struct vxlan_mdb_src_entry {struct hlist_node node;
@@ -844,6 +845,7 @@ vxlan_mdb_remote_src_add(const struct vx ent =vxlan_mdb_remote_src_entry_add (remote, &src->addr);if (!ent)return -ENOMEM ; + ent->flags |=VXLAN_SGRP_F_NEW ; }else if (!(cfg->nlflags &NLM_F_REPLACE )) {NL_SET_ERR_MSG_MOD (extack,"Source entry already exists" );return -EEXIST ;
@@ -853,15 +855,16 @@ vxlan_mdb_remote_src_add(const struct vxif (err) goto err_src_del; -/* Clear flags in case source entry was marked for deletion as part of -* replace flow. +/* Clear the deletion mark so the entry survives the replace sweep. +* The new mark is retained until the whole operation succeeds. */ - ent->flags =0 ; + ent->flags &= ~VXLAN_SGRP_F_DELETE ;return 0 ; err_src_del: -vxlan_mdb_remote_src_entry_del (ent); +if (ent->flags &VXLAN_SGRP_F_NEW ) +vxlan_mdb_remote_src_entry_del (ent);return err; }
@@ -889,11 +892,19 @@ static int vxlan_mdb_remote_srcs_add(con goto err_src_del; } +hlist_for_each_entry (ent, &remote->src_list, node) + ent->flags &= ~VXLAN_SGRP_F_NEW ; +return 0 ; err_src_del: -hlist_for_each_entry_safe (ent, tmp, &remote->src_list, node) -vxlan_mdb_remote_src_del (cfg->vxlan, &cfg->group, remote, ent); +hlist_for_each_entry_safe (ent, tmp, &remote->src_list, node) { +if (ent->flags &VXLAN_SGRP_F_NEW ) +vxlan_mdb_remote_src_del (cfg->vxlan, &cfg->group, remote, + ent); +else + ent->flags &= ~VXLAN_SGRP_F_DELETE ; + }return err; }
@@ -1069,7 +1080,7 @@ vxlan_mdb_remote_srcs_replace(const stru err =vxlan_mdb_remote_srcs_add (cfg, remote, extack);if (err) - goto err_clear_delete; +return err;hlist_for_each_entry_safe (ent, tmp, &remote->src_list, node) {if (ent->flags &VXLAN_SGRP_F_DELETE )
@@ -1078,11 +1089,6 @@ vxlan_mdb_remote_srcs_replace(const stru }return 0 ; - -err_clear_delete: -hlist_for_each_entry (ent, &remote->src_list, node) - ent->flags &= ~VXLAN_SGRP_F_DELETE ; -return err; } static int vxlan_mdb_remote_replace(const struct vxlan_mdb_config *cfg,
Greg Kroah-Hartman
maintainerPATCH 435/602 drm/amd/pm: fix amdgpu_pm_info power display units
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Wang <[email protected]>
commit 238baca26a6279e688d1a156bd031390b82eb578 upstream.
amdgpu_pm_info displayed power sensor readings with the wrong fractional unit. It treated the low byte of the raw sensor value as the decimal part of watts, while that field represents milliwatts in the decoded value. As a result, debugfs could report misleading SoC power when the remainder was not already a two-digit centiwatt value.
Example with query = 0x00000354:
raw field value
---------------------
query >> 8 3 W query & 0xff 84 mW decoded power 3084 mW
output value
---------------------
before 3.84 W
after 3.08 W
--- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +12 -9
@@ -40,6 +40,8 @@#define DEVICE_ATTR_IS (_name) (attr_id == device_attr_id__##_name) +#define power_2_mwatt (power) (((power) >> 8) * 1000 + ((power) & 0xff)) +struct od_attribute {struct kobj_attribute attribute;struct list_head entry;
@@ -3200,7 +3202,6 @@ static int amdgpu_hwmon_get_power(struct enum amd_pp_sensors sensor) {struct amdgpu_device *adev =dev_get_drvdata (dev); -unsigned int uw;u32 query =0 ;int r;
@@ -3209,9 +3210,7 @@ static int amdgpu_hwmon_get_power(structreturn r;/* convert to microwatts */ - uw = (query >>8 ) *1000000 + (query &0xff ) *1000 ; - -return uw; +return power_2_mwatt (query) *1000 ; } static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
@@ -4607,7 +4606,7 @@ static int amdgpu_debugfs_pm_info_pp(str {uint32_t mp1_ver =amdgpu_ip_version (adev,MP1_HWIP ,0 );uint32_t gc_ver =amdgpu_ip_version (adev,GC_HWIP ,0 ); -uint32_t value; +uint32_t value, mwatt, centiwatt;uint64_t value64 =0 ;uint32_t query =0 ;int size;
@@ -4632,17 +4631,21 @@ static int amdgpu_debugfs_pm_info_pp(strseq_printf (m,"\t%u mV (VDDNB)\n" , value); size =sizeof (uint32_t );if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_AVG_POWER , (void *)&query, &size)) { + mwatt =power_2_mwatt (query); + centiwatt =DIV_ROUND_CLOSEST (mwatt,10 );if (adev->flags &AMD_IS_APU ) -seq_printf (m,"\t%u.%02u W (average SoC including CPU)\n" , query >>8 , query &0xff ); +seq_printf (m,"\t%u.%02u W (average SoC including CPU)\n" , centiwatt /100 , centiwatt %100 );else -seq_printf (m,"\t%u.%02u W (average SoC)\n" , query >>8 , query &0xff ); +seq_printf (m,"\t%u.%02u W (average SoC)\n" , centiwatt /100 , centiwatt %100 ); } size =sizeof (uint32_t );if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_INPUT_POWER , (void *)&query, &size)) { + mwatt =power_2_mwatt (query); + centiwatt =DIV_ROUND_CLOSEST (mwatt,10 );if (adev->flags &AMD_IS_APU ) -seq_printf (m,"\t%u.%02u W (current SoC including CPU)\n" , query >>8 , query &0xff ); +seq_printf (m,"\t%u.%02u W (current SoC including CPU)\n" , centiwatt /100 , centiwatt %100 );else -seq_printf (m,"\t%u.%02u W (current SoC)\n" , query >>8 , query &0xff ); +seq_printf (m,"\t%u.%02u W (current SoC)\n" , centiwatt /100 , centiwatt %100 ); } size =sizeof (value);seq_printf (m,"\n" );
Greg Kroah-Hartman
maintainerPATCH 436/602 drm/amd/pm: make pp_features read-only when scpm is enabled
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Wang <[email protected]>
commit 53c78ab388bfc1a4d72e756815d0db0a842c812e upstream.
SCPM owns power feature control when enabled.
Make pp_features read-only during sysfs setup by clearing its write bits and store callback.
--- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -0
@@ -2509,6 +2509,11 @@ static int default_attr_update(struct am gc_ver != IP_VERSION(9, 4, 3)) || gc_ver < IP_VERSION(9, 0, 0)) *states =ATTR_STATE_UNSUPPORTED ; + +if (adev->scpm_enabled) { + dev_attr->attr.mode &= ~S_IWUGO ; + dev_attr->store =NULL ; + } }else if (DEVICE_ATTR_IS (gpu_metrics)) {if (gc_ver <IP_VERSION (9 ,1 ,0 )) *states =ATTR_STATE_UNSUPPORTED ;
Greg Kroah-Hartman
maintainerPATCH 437/602 drm/amdgpu/gfx10: replace BUG_ON() with WARN_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit d06c4173a7c38c7a39e98859f839ce714c7af2c9 upstream.
There's no need to crash the kernel for these cases.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -8
@@ -3934,7 +3934,7 @@ static void gfx_v10_0_wait_reg_mem(struc WAIT_REG_MEM_ENGINE(eng_sel)));if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ +WARN_ON (addr0 &0x3 );/* Dword align */ amdgpu_ring_write (ring, addr0);amdgpu_ring_write (ring, addr1);amdgpu_ring_write (ring, ref);
@@ -8565,7 +8565,7 @@ static void gfx_v10_0_ring_emit_ib_gfx(s }amdgpu_ring_write (ring, header); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -8600,7 +8600,7 @@ static void gfx_v10_0_ring_emit_ib_compu }amdgpu_ring_write (ring,PACKET3 (PACKET3_INDIRECT_BUFFER ,2 )); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -8633,9 +8633,9 @@ static void gfx_v10_0_ring_emit_fence(st* aligned if only send 32bit data low (discard data high) */ if (write64bit) -BUG_ON (addr &0x7 ); +WARN_ON (addr &0x7 );else -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,lower_32_bits (seq));
@@ -8683,9 +8683,6 @@ static void gfx_v10_0_ring_emit_fence_ki {struct amdgpu_device *adev = ring->adev; -/* we only allocate 32bit for each seq wb address */ -BUG_ON (flags &AMDGPU_FENCE_FLAG_64BIT ); -/* write fence seq to the "addr" */ amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
Greg Kroah-Hartman
maintainerPATCH 438/602 drm/amdgpu/gfx11: replace BUG_ON() with WARN_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 0eebcab1ea2a77f086a04108f386f82ee3496022 upstream.
There's no need to crash the kernel for these cases.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -8
@@ -496,7 +496,7 @@ static void gfx_v11_0_wait_reg_mem(struc WAIT_REG_MEM_ENGINE(eng_sel)));if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ +WARN_ON (addr0 &0x3 );/* Dword align */ amdgpu_ring_write (ring, addr0);amdgpu_ring_write (ring, addr1);amdgpu_ring_write (ring, ref);
@@ -5673,7 +5673,7 @@ static void gfx_v11_0_ring_emit_ib_gfx(s control |=0x400000 ;amdgpu_ring_write (ring, header); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -5712,7 +5712,7 @@ static void gfx_v11_0_ring_emit_ib_compu }amdgpu_ring_write (ring,PACKET3 (PACKET3_INDIRECT_BUFFER ,2 )); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -5745,9 +5745,9 @@ static void gfx_v11_0_ring_emit_fence(st* aligned if only send 32bit data low (discard data high) */ if (write64bit) -BUG_ON (addr &0x7 ); +WARN_ON (addr &0x7 );else -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,lower_32_bits (seq));
@@ -5805,9 +5805,6 @@ static void gfx_v11_0_ring_emit_fence_ki {struct amdgpu_device *adev = ring->adev; -/* we only allocate 32bit for each seq wb address */ -BUG_ON (flags &AMDGPU_FENCE_FLAG_64BIT ); -/* write fence seq to the "addr" */ amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
Greg Kroah-Hartman
maintainerPATCH 439/602 drm/amdgpu/gfx12: replace BUG_ON() with WARN_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit cd3b3efa1ced05528d9128755338baa62a6b562d upstream.
There's no need to crash the kernel for these cases.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5 -8
@@ -409,7 +409,7 @@ static void gfx_v12_0_wait_reg_mem(struc WAIT_REG_MEM_ENGINE(eng_sel)));if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ +WARN_ON (addr0 &0x3 );/* Dword align */ amdgpu_ring_write (ring, addr0);amdgpu_ring_write (ring, addr1);amdgpu_ring_write (ring, ref);
@@ -4338,7 +4338,7 @@ static void gfx_v12_0_ring_emit_ib_gfx(s control |=0x400000 ;amdgpu_ring_write (ring, header); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -4361,7 +4361,7 @@ static void gfx_v12_0_ring_emit_ib_compu control |=0x40000000 ;amdgpu_ring_write (ring,PACKET3 (PACKET3_INDIRECT_BUFFER ,2 )); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -4392,9 +4392,9 @@ static void gfx_v12_0_ring_emit_fence(st* aligned if only send 32bit data low (discard data high) */ if (write64bit) -BUG_ON (addr &0x7 ); +WARN_ON (addr &0x7 );else -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,lower_32_bits (seq));
@@ -4446,9 +4446,6 @@ static void gfx_v12_0_ring_emit_fence_ki {struct amdgpu_device *adev = ring->adev; -/* we only allocate 32bit for each seq wb address */ -BUG_ON (flags &AMDGPU_FENCE_FLAG_64BIT ); -/* write fence seq to the "addr" */ amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
Greg Kroah-Hartman
maintainerPATCH 440/602 drm/amdgpu/gfx8: drop unecessary BUG_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 84a1a8a952ab4b8c23c5dd1f2eea4049cb4914f5 upstream.
There's no need to crash the kernel for this case.
--- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -3
@@ -6272,9 +6272,6 @@ static void gfx_v8_0_ring_emit_fence_comstatic void gfx_v8_0_ring_emit_fence_kiq (struct amdgpu_ring *ring,u64 addr,u64 seq,unsigned int flags) { -/* we only allocate 32bit for each seq wb address */ -BUG_ON (flags &AMDGPU_FENCE_FLAG_64BIT ); -/* write fence seq to the "addr" */ amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
Greg Kroah-Hartman
maintainerPATCH 441/602 drm/amdgpu/gfx9.4.3: replace BUG_ON() with WARN_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 00f4050f7c367d7bdce347ca279ce467c434cf15 upstream.
There's no need to crash the kernel for these cases.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +4 -7
@@ -409,7 +409,7 @@ static void gfx_v9_4_3_wait_reg_mem(stru WAIT_REG_MEM_ENGINE(eng_sel)));if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ +WARN_ON (addr0 &0x3 );/* Dword align */ amdgpu_ring_write (ring, addr0);amdgpu_ring_write (ring, addr1);amdgpu_ring_write (ring, ref);
@@ -2882,7 +2882,7 @@ static void gfx_v9_4_3_ring_emit_ib_comp }amdgpu_ring_write (ring,PACKET3 (PACKET3_INDIRECT_BUFFER ,2 )); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -2916,9 +2916,9 @@ static void gfx_v9_4_3_ring_emit_fence(s* aligned if only send 32bit data low (discard data high) */ if (write64bit) -BUG_ON (addr &0x7 ); +WARN_ON (addr &0x7 );else -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,lower_32_bits (seq));
@@ -2978,9 +2978,6 @@ static void gfx_v9_4_3_ring_emit_fence_k {struct amdgpu_device *adev = ring->adev; -/* we only allocate 32bit for each seq wb address */ -BUG_ON (flags &AMDGPU_FENCE_FLAG_64BIT ); -/* write fence seq to the "addr" */ amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
Greg Kroah-Hartman
maintainerPATCH 442/602 drm/amdgpu/gfx9: replace BUG_ON() with WARN_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 6302be10b521f5106ce01eb5a724b9e7945a5061 upstream.
There's no need to crash the kernel for these cases.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +5 -5
@@ -1156,7 +1156,7 @@ static void gfx_v9_0_wait_reg_mem(struct WAIT_REG_MEM_ENGINE(eng_sel)));if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ +WARN_ON (addr0 &0x3 );/* Dword align */ amdgpu_ring_write (ring, addr0);amdgpu_ring_write (ring, addr1);amdgpu_ring_write (ring, ref);
@@ -5415,7 +5415,7 @@ static void gfx_v9_0_ring_emit_ib_gfx(st }amdgpu_ring_write (ring, header); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -5527,7 +5527,7 @@ static void gfx_v9_0_ring_emit_ib_comput }amdgpu_ring_write (ring,PACKET3 (PACKET3_INDIRECT_BUFFER ,2 )); -BUG_ON (ib->gpu_addr &0x3 );/* Dword align */ +WARN_ON (ib->gpu_addr &0x3 );/* Dword align */ amdgpu_ring_write(ring, #ifdef __BIG_ENDIAN (2 << 0) |
@@ -5568,9 +5568,9 @@ static void gfx_v9_0_ring_emit_fence(str* aligned if only send 32bit data low (discard data high) */ if (write64bit) -BUG_ON (addr &0x7 ); +WARN_ON (addr &0x7 );else -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,lower_32_bits (seq));
Greg Kroah-Hartman
maintainerPATCH 443/602 drm/amdgpu/sdma4.4.2: replace BUG_ON() with WARN_ON()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 40cdbe9fa424cc6264a7aed93a04bd7d69109d9e upstream.
There's no need to crash the kernel for these cases.
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -2
@@ -450,7 +450,7 @@ static void sdma_v4_4_2_ring_emit_fence(/* write the fence */ amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_FENCE ));/* zero in first two bits */ -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,lower_32_bits (seq));
@@ -460,7 +460,7 @@ static void sdma_v4_4_2_ring_emit_fence( addr +=4 ;amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_FENCE ));/* zero in first two bits */ -BUG_ON (addr &0x3 ); +WARN_ON (addr &0x3 );amdgpu_ring_write (ring,lower_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (addr));amdgpu_ring_write (ring,upper_32_bits (seq));
Greg Kroah-Hartman
maintainerPATCH 444/602 drm/amdgpu/vce: fix integer overflow in image size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boyuan Zhang <[email protected]>
commit 186bfdc4e26d019b2e7570cb121964a1d89b2e5b upstream.
Fix a security vulnerability where malicious VCE command streams with oversized dimensions (e.g. 65536×65536) cause 32-bit integer overflow, wrapping the calculated buffer size to 0. This bypasses validation and allows GPU firmware to perform out-of-bound memory access.
The fix uses 64-bit arithmetic to detect overflow and rejects invalid dimensions before they reach the hardware.
V2: remove redundant check
V3: modify max height value
V4: remove size64
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +14 -3
@@ -852,9 +852,20 @@ int amdgpu_vce_ring_parse_cs(struct amdg goto out; } - *size =amdgpu_ib_get_value (ib, idx +8 ) * -amdgpu_ib_get_value (ib, idx +10 ) * -8 *3 /2 ; +uint32_t width, height; + width =amdgpu_ib_get_value (ib, idx +8 ); + height =amdgpu_ib_get_value (ib, idx +10 ); + +if (width ==0 || height ==0 || + width >4096 || height >2304 ) { +DRM_ERROR ("invalid VCE image size: %ux%u\n" , + width, height); + r = -EINVAL ; + goto out; + } + + *size = width * height *8 *3 /2 ; +break ;case 0x04000001 :/* config extension */
Greg Kroah-Hartman
maintainerPATCH 445/602 drm/amdgpu/vcn4: avoid rereading IB param length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boyuan Zhang <[email protected]>
commit 3b4082fabc67c9780b06eb959e59dd92fa79c0f0 upstream.
Reuse the parameter length returned by vcn_v4_0_enc_find_ib_param() instead of rereading it from the IB.
This avoids a potential TOCTOU issue if the IB contents change between reads.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +9 -6
@@ -1868,14 +1868,17 @@ out:#define RENCODE_IB_PARAM_SESSION_INIT 0x00000003/* return the offset in ib if id is found, -1 otherwise */ -static int vcn_v4_0_enc_find_ib_param (struct amdgpu_ib *ib,uint32_t id,int start) +static int vcn_v4_0_enc_find_ib_param (struct amdgpu_ib *ib,uint32_t id,int start,uint32_t *length) {int i;uint32_t len;for (i = start; (len =amdgpu_ib_get_value (ib, i)) >=8 ; i += len /4 ) { -if (amdgpu_ib_get_value (ib, i +1 ) == id) +if (amdgpu_ib_get_value (ib, i +1 ) == id) { +if (length) + *length = len;return i; + } }return -1 ; }
@@ -1885,14 +1888,14 @@ static int vcn_v4_0_ring_patch_cs_in_pla struct amdgpu_ib *ib) {struct amdgpu_ring *ring =amdgpu_job_ring (job); -uint32_t val; +uint32_t val, len;int idx =0 , sidx;/* The first instance can decode anything */ if (!ring->me)return 0 ; -while ((idx =vcn_v4_0_enc_find_ib_param (ib,RADEON_VCN_ENGINE_INFO , idx)) >=0 ) { +while ((idx =vcn_v4_0_enc_find_ib_param (ib,RADEON_VCN_ENGINE_INFO , idx, &len)) >=0 ) { val =amdgpu_ib_get_value (ib, idx +2 );/* RADEON_VCN_ENGINE_TYPE */ if (val ==RADEON_VCN_ENGINE_TYPE_DECODE ) {uint32_t valid_buf_flag =amdgpu_ib_get_value (ib, idx +6 );
@@ -1905,12 +1908,12 @@ static int vcn_v4_0_ring_patch_cs_in_plaamdgpu_ib_get_value (ib, idx +8 );return vcn_v4_0_dec_msg (p, job, msg_buffer_addr); }else if (val ==RADEON_VCN_ENGINE_TYPE_ENCODE ) { - sidx =vcn_v4_0_enc_find_ib_param (ib,RENCODE_IB_PARAM_SESSION_INIT , idx); + sidx =vcn_v4_0_enc_find_ib_param (ib,RENCODE_IB_PARAM_SESSION_INIT , idx,NULL );if (sidx >=0 &&amdgpu_ib_get_value (ib, sidx +2 ) ==RENCODE_ENCODE_STANDARD_AV1 )return vcn_v4_0_limit_sched (p, job); } - idx +=amdgpu_ib_get_value (ib, idx) /4 ; + idx += len /4 ; }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 446/602 drm/dp_mst: Handle torn-down topology gracefully in drm_dp_mst_topology_queue_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luca Coelho <[email protected]>
commit 613059875958e7b217b250ed14c3b189f9488421 upstream.
A hotplug or link-loss event can tear down the MST topology (setting mgr->mst_state = false and mgr->mst_primary = NULL) concurrently with a caller invoking drm_dp_mst_topology_queue_probe(). Since the check is already performed under mgr->lock, the condition is not a programming error but a valid race -- the topology was valid when the caller decided to call this function, but was torn down before the lock was acquired.
Replace the drm_WARN_ON() with a graceful early return. This eliminates spurious kernel warnings and the resulting compositor crashes observed when connecting/disconnecting DP MST monitors, while keeping the correct behavior of doing nothing when MST is not active. A drm_dbg_mst() trace is added so the skipped probe remains observable under MST debug logging.
The existing WARN_ON(mgr->mst_primary) in drm_dp_mst_topology_mgr_set_mst() already catches the case where the topology is initialized twice, so no diagnostic coverage is lost.
--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +3 -1
@@ -3743,8 +3743,10 @@ void drm_dp_mst_topology_queue_probe(str {mutex_lock (&mgr->lock); -if (drm_WARN_ON (mgr->dev, !mgr->mst_state || !mgr->mst_primary)) +if (!mgr->mst_state || !mgr->mst_primary) { +drm_dbg_kms (mgr->dev,"queue_probe skipped: topology torn down\n" ); goto out_unlock; + }drm_dp_mst_topology_mgr_invalidate_mstb (mgr->mst_primary);drm_dp_mst_queue_probe_work (mgr);
Greg Kroah-Hartman
maintainerPATCH 447/602 drm/amdgpu: fix division by zero with invalid uvd dimensions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boyuan Zhang <[email protected]>
commit 0c01c811be47e6b146552dd59bfedbea8f09b8f4 upstream.
When width or height is less than 16, width_in_mb or height_in_mb becomes 0, leading to fs_in_mb being 0. This causes a division by zero when calculating num_dpb_buffer in H264 and H264 Perf decode paths.
Add validation to reject frames with width < 16 or height < 16 before performing any calculations that depend on these values.
V2: Format change - move up all vaiable definitions.
V3: Use warn_once to avoid spam.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +8 -0
@@ -654,6 +654,14 @@ static int amdgpu_uvd_cs_msg_decode(struunsigned int image_size, tmp, min_dpb_size, num_dpb_buffer;unsigned int min_ctx_size = ~0 ; +/* Reject invalid dimensions to prevent division by zero */ +if (width <16 || height <16 ) { +dev_WARN_ONCE (adev->dev,1 , +"Invalid UVD decoding dimensions (%dx%d)!\n" , + width, height); +return -EINVAL ; + } + image_size = width * height; image_size += image_size /2 ; image_size =ALIGN (image_size,1024 );
Greg Kroah-Hartman
maintainerPATCH 448/602 drm/amdgpu: invoke pm_genpd_remove() before freeing genpd
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ce Sun <[email protected]>
commit 28c9b3c5dc35cc790d11e26ca3fc6e068be63998 upstream.
Call pm_genpd_remove() to unregister from global list prior to releasing acp_genpd memory, and clear the pointer after free.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +2 -0
@@ -559,7 +559,9 @@ static int acp_hw_fini(void *handle)mfd_remove_devices (adev->acp.parent);kfree (adev->acp.acp_res); +pm_genpd_remove (&adev->acp.acp_genpd->gpd);kfree (adev->acp.acp_genpd); + adev->acp.acp_genpd =NULL ;kfree (adev->acp.acp_cell);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 449/602 drm/amdgpu: fix aperture mapping leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Asad Kamal <[email protected]>
commit ea772a440d56b285f4d491affac50ecd41f6b402 upstream.
amdgpu_pci_remove() calls drm_dev_unplug() before invoking the driver fini routines. This causes drm_dev_enter() in amdgpu_ttm_fini() to always return false, so iounmap(aper_base_kaddr) never runs on normal driver unload, leaving an orphaned entry in the x86 PAT interval tree.
On connected_to_cpu hardware, the aperture is mapped write-back (WB) via ioremap_cache(). On reload, IP discovery calls memremap(..., MEMREMAP_WC) over the same range. The WC vs WB conflict causes:
ioremap error for 0x..., requested 0x1, got 0x0
amdgpu: discovery failed: -2
Fix by switching to devres-managed mappings so cleanup is guaranteed regardless of drm_dev_enter() state:
- connected_to_cpu path: devm_memremap(MEMREMAP_WB). For IORESOURCE_SYSTEM_RAM ranges this takes the try_ram_remap() shortcut, returning __va(offset) from the existing kernel direct map. No new ioremap VA or PAT entry is created, so there is nothing to orphan.
- dGPU path: devm_ioremap_wc() registers iounmap() as a devres action, guaranteeing cleanup at device_del() time.
Also remove iounmap(aper_base_kaddr) from amdgpu_device_unmap_mmio() since the mapping is now devres-owned.
v2: Remove redundant x86_64 guard (Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 36 ++++++++++++----------------- 2 files changed, 16 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -2
@@ -4635,8 +4635,6 @@ static void amdgpu_device_unmap_mmio(striounmap (adev->rmmio); adev->rmmio =NULL ; -if (adev->mman.aper_base_kaddr) -iounmap (adev->mman.aper_base_kaddr); adev->mman.aper_base_kaddr =NULL ;/* Memory manager related */
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +16 -20
@@ -1907,18 +1907,23 @@ int amdgpu_ttm_init(struct amdgpu_device/* Change the size here instead of the init above so only lpfn is affected */ amdgpu_ttm_set_buffer_funcs_status (adev, false);#ifdef CONFIG_64BIT -#ifdef CONFIG_X86 -if (adev->gmc.xgmi.connected_to_cpu) - adev->mman.aper_base_kaddr =ioremap_cache (adev->gmc.aper_base, - adev->gmc.visible_vram_size); - -else if (adev->gmc.is_app_apu) +if (adev->gmc.xgmi.connected_to_cpu) { +void *kaddr =devm_memremap (adev->dev, adev->gmc.aper_base, + adev->gmc.visible_vram_size, +MEMREMAP_WB ); +if (IS_ERR (kaddr)) +return PTR_ERR (kaddr); + adev->mman.aper_base_kaddr = (__force void __iomem *)kaddr; + }else if (adev->gmc.is_app_apu) {DRM_DEBUG_DRIVER ("No need to ioremap when real vram size is 0\n" ); - else -#endif - adev->mman.aper_base_kaddr =ioremap_wc (adev->gmc.aper_base, - adev->gmc.visible_vram_size); + }else { + adev->mman.aper_base_kaddr =devm_ioremap_wc (adev->dev, + adev->gmc.aper_base, + adev->gmc.visible_vram_size); +if (!adev->mman.aper_base_kaddr) +return -ENOMEM ; + }#endif /*
@@ -2053,8 +2058,6 @@ int amdgpu_ttm_init(struct amdgpu_device*/ void amdgpu_ttm_fini (struct amdgpu_device *adev) { -int idx; -if (!adev->mman.initialized)return ;
@@ -2077,14 +2080,7 @@ void amdgpu_ttm_fini(struct amdgpu_devicamdgpu_ttm_fw_reserve_vram_fini (adev);amdgpu_ttm_drv_reserve_vram_fini (adev); -if (drm_dev_enter (adev_to_drm (adev), &idx)) { - -if (adev->mman.aper_base_kaddr) -iounmap (adev->mman.aper_base_kaddr); - adev->mman.aper_base_kaddr =NULL ; - -drm_dev_exit (idx); - } + adev->mman.aper_base_kaddr =NULL ;amdgpu_vram_mgr_fini (adev);amdgpu_gtt_mgr_fini (adev);
Greg Kroah-Hartman
maintainerPATCH 450/602 drm/amd/pm: fix smu13 power limit range calculation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Wang <[email protected]>
commit 220f22e1d66c1cfb63387eb1c4210f92a357c2d9 upstream.
SMU13 reports SocketPowerLimitAc/Dc as the default power limit, but MsgLimits.Power may carry a different firmware bound for the same PPT throttler. Using only the socket limit for both min and max can therefore expose an incorrect power range.
Keep the socket limit as the default, but derive the range from both values:
use the lower value for the min base and the higher value for the max base before applying OD percentages. Keep the current limit query independent from the cap calculation.
--- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 11 +++++++---- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 15 ++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +7 -4
@@ -2396,11 +2396,14 @@ static int smu_v13_0_0_get_power_limit(suint32_t pp_limit = smu->adev->pm.ac_power ? skutable->SocketPowerLimitAc[PPT_THROTTLER_PPT0 ] : skutable->SocketPowerLimitDc[PPT_THROTTLER_PPT0 ]; -uint32_t power_limit =0 , od_percent_upper =0 , od_percent_lower =0 ; +uint32_t msg_limit = skutable->MsgLimits.Power[PPT_THROTTLER_PPT0 ][POWER_SOURCE_AC ]; +uint32_t min_limit =min_t (uint32_t, pp_limit, msg_limit); +uint32_t max_limit =max_t (uint32_t, pp_limit, msg_limit); +uint32_t od_percent_upper =0 , od_percent_lower =0 ;int ret;if (current_power_limit) { - ret =smu_v13_0_get_current_power_limit (smu, &power_limit); + ret =smu_v13_0_get_current_power_limit (smu, current_power_limit);if (ret) *current_power_limit = pp_limit; }
@@ -2423,12 +2426,12 @@ static int smu_v13_0_0_get_power_limit(s od_percent_upper, od_percent_lower, pp_limit);if (max_power_limit) { - *max_power_limit = pp_limit * (100 + od_percent_upper); + *max_power_limit = max_limit * (100 + od_percent_upper); *max_power_limit /=100 ; }if (min_power_limit) { - *min_power_limit = pp_limit * (100 - od_percent_lower); + *min_power_limit = min_limit * (100 - od_percent_lower); *min_power_limit /=100 ; }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +8 -7
@@ -2357,15 +2357,16 @@ static int smu_v13_0_7_get_power_limit(suint32_t pp_limit = smu->adev->pm.ac_power ? skutable->SocketPowerLimitAc[PPT_THROTTLER_PPT0 ] : skutable->SocketPowerLimitDc[PPT_THROTTLER_PPT0 ]; -uint32_t power_limit =0 , od_percent_upper =0 , od_percent_lower =0 ; +uint32_t msg_limit = skutable->MsgLimits.Power[PPT_THROTTLER_PPT0 ][POWER_SOURCE_AC ]; +uint32_t min_limit =min_t (uint32_t, pp_limit, msg_limit); +uint32_t max_limit =max_t (uint32_t, pp_limit, msg_limit); +uint32_t od_percent_upper =0 , od_percent_lower =0 ;int ret;if (current_power_limit) { - ret =smu_v13_0_get_current_power_limit (smu, &power_limit); + ret =smu_v13_0_get_current_power_limit (smu, current_power_limit);if (ret) - power_limit = pp_limit; - - *current_power_limit = power_limit; + *current_power_limit = pp_limit; }if (default_power_limit)
@@ -2386,12 +2387,12 @@ static int smu_v13_0_7_get_power_limit(s od_percent_upper, od_percent_lower, pp_limit);if (max_power_limit) { - *max_power_limit = pp_limit * (100 + od_percent_upper); + *max_power_limit = max_limit * (100 + od_percent_upper); *max_power_limit /=100 ; }if (min_power_limit) { - *min_power_limit = pp_limit * (100 - od_percent_lower); + *min_power_limit = min_limit * (100 - od_percent_lower); *min_power_limit /=100 ; }
Greg Kroah-Hartman
maintainerPATCH 451/602 bpf: Fix same-register dst/src OOB read and pointer leak in sock_ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 10f86a2a5c91fc4c4d001960f1c21abe52545ef6 ]
When a BPF sock_ops program accesses ctx fields with dst_reg == src_reg, the SOCK_OPS_GET_SK() and SOCK_OPS_GET_FIELD() macros fail to zero the destination register in the !fullsock / !locked_tcp_sock path.
Both macros borrow a temporary register to check is_fullsock / is_locked_tcp_sock when dst_reg == src_reg, because dst_reg holds the ctx pointer. When the check is false (e.g., TCP_NEW_SYN_RECV state with a request_sock), dst_reg should be zeroed but is not, leaving the stale ctx pointer:
- SOCK_OPS_GET_SK: dst_reg retains the ctx pointer, passes NULL checks as PTR_TO_SOCKET_OR_NULL, and can be used as a bogus socket pointer, leading to stack-out-of-bounds access in helpers like bpf_skc_to_tcp6_sock().
- SOCK_OPS_GET_FIELD: dst_reg retains the ctx pointer which the verifier believes is a SCALAR_VALUE, leaking a kernel pointer.
Fix both macros by:
- Changing JMP_A(1) to JMP_A(2) in the fullsock path to skip the added instruction.
- Adding BPF_MOV64_IMM(si->dst_reg, 0) after the temp register restore in the !fullsock path, placed after the restore because dst_reg == src_reg means we need src_reg intact to read ctx->temp.
--- net/core/filter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/core/filter.c +4 -2
@@ -10483,10 +10483,11 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type, si->dst_reg, si->dst_reg, \ offsetof(OBJ, OBJ_FIELD)); \if (si->dst_reg == si->src_reg) { \ - *insn++ =BPF_JMP_A (1 ); \ + *insn++ =BPF_JMP_A (2 ); \ *insn++ =BPF_LDX_MEM (BPF_DW , reg, si->src_reg, \ offsetof(struct bpf_sock_ops_kern , \ temp)); \ + *insn++ =BPF_MOV64_IMM (si->dst_reg,0 ); \ } \ }while (0 )
@@ -10520,10 +10521,11 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type, si->dst_reg, si->src_reg, \ offsetof(struct bpf_sock_ops_kern, sk));\if (si->dst_reg == si->src_reg) { \ - *insn++ =BPF_JMP_A (1 ); \ + *insn++ =BPF_JMP_A (2 ); \ *insn++ =BPF_LDX_MEM (BPF_DW , reg, si->src_reg, \ offsetof(struct bpf_sock_ops_kern , \ temp)); \ + *insn++ =BPF_MOV64_IMM (si->dst_reg,0 ); \ } \ }while (0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/602 net: qrtr: ns: Raise node count limit to 512
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youssef Samir <[email protected]>
commit ff194cffd586cbd4cc49eccb002c65f2a902a277 upstream.
The current node limit of 64 breaks the functionality for a number of AI200 deployments that have up to 384 nodes. Raise the limit to 512.
--- net/qrtr/ns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/qrtr/ns.c +2 -2
@@ -85,9 +85,9 @@ struct qrtr_node {/* Max nodes limit is chosen based on the current platform requirements. * If the requirement changes in the future, this value can be increased. */ -#define QRTR_NS_MAX_NODES 64 +#define QRTR_NS_MAX_NODES 512 -static u8 node_count; +static u16 node_count;static struct qrtr_node *node_get (unsigned int node_id) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/602 ksmbd: validate num_subauth when copying ACE in set_ntacl_dacl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haofeng Li <[email protected]>
commit 47f0b34f6bc98ed85bfdc293e8f3e432ec24958d upstream.
set_ntacl_dacl() copies each ACE from the attacker-controlled stored security descriptor verbatim into the response DACL without checking sid.num_subauth. The ACE bytes (including an unchecked num_subauth) originate from an authenticated SMB2_SET_INFO(SecInfo=DACL) that is stored raw via ksmbd_vfs_set_sd_xattr(); parse_dacl() rejects a bad ACE with break rather than an error, so parse_sec_desc() still returns success and the malformed SD reaches the xattr intact.
On a subsequent SMB2_QUERY_INFO(SecInfo=DACL) for an inode carrying a POSIX access ACL, build_sec_desc() -> set_ntacl_dacl() -> set_posix_acl_entries_dacl() walks the copied ACEs and reads
ntace->sid.sub_auth[ntace->sid.num_subauth - 1]
with num_subauth taken straight from the stored SD. Since sub_auth[] is fixed at SID_MAX_SUB_AUTHORITIES (15), a crafted num_subauth (e.g.
255) drives an out-of-bounds heap read of ~1 KB with an offset fully controlled by an authenticated client.
The sibling functions already gate this field:
parse_dacl() -- num_subauth == 0 || > SID_MAX_SUB_AUTHORITIES parse_sid() -- num_subauth > SID_MAX_SUB_AUTHORITIES smb_copy_sid() -- min_t(u8, num_subauth, SID_MAX_SUB_AUTHORITIES)
set_ntacl_dacl() is the lone inconsistent path that omits the check.
Add the same num_subauth validation in set_ntacl_dacl() before copying the ACE, matching the gate already enforced by parse_dacl().
--- fs/smb/server/smbacl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/server/smbacl.c +7 -1
@@ -745,12 +745,18 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap,if (nt_ace_size > aces_size)break ; +if (ntace->sid.num_subauth ==0 || + ntace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES ) + goto next_ace; +memcpy ((char *)pndace + size, ntace, nt_ace_size);if (check_add_overflow (size, nt_ace_size, &size))break ; + num_aces++; + +next_ace: aces_size -= nt_ace_size; ntace = (struct smb_ace *)((char *)ntace + nt_ace_size); - num_aces++; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/602 ksmbd: restore DACL size on check_add_overflow() to avoid malformed ACL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Guan <[email protected]>
commit bbf0a8e931204ecdab494a88d43b0a24a04285c5 upstream.
check_add_overflow() unconditionally writes the truncated sum into *d even on overflow, per its contract in include/linux/overflow.h. The four check_add_overflow() guards in set_posix_acl_entries_dacl() and set_ntacl_dacl() break out of the ACE-building loops on overflow, but the truncated *size is then consumed downstream at the end of set_ntacl_dacl():
pndacl->size = cpu_to_le16(le16_to_cpu(pndacl->size) + size);
This produces an on-wire NT ACL whose pndacl->size under-reports the bytes actually written by the preceding fill_ace_for_sid()/memcpy() calls, yielding a malformed ACL that can trigger out-of-bounds reads when re-parsed by clients or ksmbd itself.
Restore *size to its pre-addition value on each overflow branch (via *size -= ace_sz / size -= nt_ace_size) so that after the break, *size once again holds the cumulative size of the successfully-written ACEs. The committed ACL is then truncated-but-self-consistent rather than malformed.
The ksmbd DACL builders are the only check_add_overflow() sites found where an overflow path breaks out of a loop and the destination value is consumed afterward. The other nearby break-style cases either return -EINVAL on overflow (transport_ipc.c) or break without consuming the overflowed destination value afterward (buildid.c).
--- fs/smb/server/smbacl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/smbacl.c +6 -1
@@ -649,6 +649,7 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap, ace_sz =fill_ace_for_sid (ntace, sid,ACCESS_ALLOWED , flags, pace->e_perm,0777 );if (check_add_overflow (*size, ace_sz, size)) { + *size -= ace_sz;kfree (sid);break ; }
@@ -663,6 +664,7 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap, ace_sz =fill_ace_for_sid (ntace, sid,ACCESS_ALLOWED ,0x03 , pace->e_perm,0777 );if (check_add_overflow (*size, ace_sz, size)) { + *size -= ace_sz;kfree (sid);break ; }
@@ -708,6 +710,7 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap, ace_sz =fill_ace_for_sid (ntace, sid,ACCESS_ALLOWED ,0x0b , pace->e_perm,0777 );if (check_add_overflow (*size, ace_sz, size)) { + *size -= ace_sz;kfree (sid);break ; }
@@ -750,8 +753,10 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap, goto next_ace;memcpy ((char *)pndace + size, ntace, nt_ace_size); -if (check_add_overflow (size, nt_ace_size, &size)) +if (check_add_overflow (size, nt_ace_size, &size)) { + size -= nt_ace_size;break ; + } num_aces++; next_ace:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/602 ksmbd: bound DACL dedup walk to copied ACEs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit 58d97fcd0bf1aee694e244cc28635b9df95b543b upstream.
set_ntacl_dacl() can stop copying ACEs before consuming the full input DACL when size accounting overflows.
When that happens, num_aces reflects only the ACEs that were actually copied into the output DACL, but set_posix_acl_entries_dacl() still receives nt_num_aces and uses it to walk the existing ACE array during dedup.
That makes the dedup walk scan past the copied ACE array and inspect buffer tail that does not contain valid ACEs.
Split the two meanings currently carried by the NT ACE count. Pass the number of copied NT ACEs to bound the dedup walk, and preserve the original "input DACL had NT ACEs" state separately for the Everyone/default ACL fallback.
This keeps the dedup walk aligned with the ACEs that are actually present in the rebuilt DACL.
--- fs/smb/server/smbacl.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/smb/server/smbacl.c +10 -6
@@ -595,7 +595,8 @@ static void parse_dacl(struct mnt_idmap *idmap,static void set_posix_acl_entries_dacl (struct mnt_idmap *idmap,struct smb_ace *pndace,struct smb_fattr *fattr,u16 *num_aces, -u16 *size,u32 nt_aces_num) +u16 *size,u16 existing_nt_aces, +bool had_nt_aces) {struct posix_acl_entry *pace;struct smb_sid *sid;
@@ -627,14 +628,14 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap, gid =posix_acl_gid_translate (idmap, pace);id_to_sid (gid,SIDUNIX_GROUP , sid); - }else if (pace->e_tag ==ACL_OTHER && !nt_aces_num) { + }else if (pace->e_tag ==ACL_OTHER && !had_nt_aces) {smb_copy_sid (sid, &sid_everyone); }else {kfree (sid);continue ; } ntace = pndace; -for (j =0 ; j < nt_aces_num; j++) { +for (j =0 ; j < existing_nt_aces; j++) {if (ntace->sid.sub_auth[ntace->sid.num_subauth -1 ] == sid->sub_auth[sid->num_subauth -1 ]) goto pass_same_sid;
@@ -678,7 +679,7 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,kfree (sid); } -if (nt_aces_num) +if (had_nt_aces)return ; posix_default_acl:
@@ -732,6 +733,7 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap, {struct smb_ace *ntace, *pndace;u16 nt_num_aces =le16_to_cpu (nt_dacl->num_aces), num_aces =0 ; +u16 copied_nt_aces;unsigned short size =0 ;int i;
@@ -765,8 +767,10 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap, } } + copied_nt_aces = num_aces;set_posix_acl_entries_dacl (idmap, pndace, fattr, - &num_aces, &size, nt_num_aces); + &num_aces, &size, copied_nt_aces, + nt_num_aces !=0 ); pndacl->num_aces =cpu_to_le16 (num_aces); pndacl->size =cpu_to_le16 (le16_to_cpu (pndacl->size) + size); }
@@ -784,7 +788,7 @@ static void set_mode_dacl(struct mnt_idmap *idmap,if (fattr->cf_acls) {set_posix_acl_entries_dacl (idmap, pndace, fattr, - &num_aces, &size, num_aces); + &num_aces, &size, num_aces, false); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/602 ksmbd: validate ACE size against SID sub-authorities
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit 5152c6d49e3fd4e9f2e857c57527aead752f1f87 upstream.
set_ntacl_dacl() validates sid.num_subauth before copying an ACE, but does not verify that the declared ACE size contains all sub-authorities described by that field. An undersized ACE can therefore be copied and later make the POSIX ACL deduplication walk inspect data beyond the copied ACE boundary.
The existing initial bound check is also too small. It only ensures that the ACE size field is accessible before set_ntacl_dacl() reads sid.num_subauth farther into the input buffer.
Require enough input for the fixed SID header before accessing num_subauth, reject ACEs smaller than that header, and skip ACEs whose declared size cannot contain the complete SID. This makes the validation consistent with the other ACE walk paths.
--- fs/smb/server/smbacl.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/smb/server/smbacl.c +10 -3
@@ -743,15 +743,22 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap,for (i =0 ; i < nt_num_aces; i++) {unsigned short nt_ace_size; -if (offsetof(struct smb_ace , access_req) > aces_size) +if (aces_size < offsetof(struct smb_ace , sid) + +CIFS_SID_BASE_SIZE )break ; nt_ace_size =le16_to_cpu (ntace->size); -if (nt_ace_size > aces_size) +if (nt_ace_size > aces_size || + nt_ace_size < offsetof(struct smb_ace , sid) + +CIFS_SID_BASE_SIZE )break ;if (ntace->sid.num_subauth ==0 || - ntace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES ) + ntace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES || + nt_ace_size < offsetof(struct smb_ace , sid) + +CIFS_SID_BASE_SIZE + +sizeof (__le32) * + ntace->sid.num_subauth) goto next_ace;memcpy ((char *)pndace + size, ntace, nt_ace_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/602 fscrypt: Avoid dynamic allocation in fscrypt_get_devices()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 6fe4e4b8259e1330945b5f3c9476e08473b8e0e8 upstream.
When a blk_crypto_key starts being used or is evicted, fs/crypto/ calls fscrypt_get_devices() to get the filesystem's list of block devices, then iterates over them and calls blk_crypto_config_supported(), blk_crypto_start_using_key(), or blk_crypto_evict_key() on each one.
Currently, the block device pointers are placed in a dynamically allocated array. This dynamic allocation is problematic because:
- It can fail, especially at the fscrypt_destroy_inline_crypt_key() call site when it's invoked for inode eviction under direct reclaim.
- fscrypt_destroy_inline_crypt_key() doesn't handle the failure. It just zeroizes and frees the blk_crypto_key without calling blk_crypto_evict_key(). That causes a use-after-free.
For now, let's fix this in the straightforward and easily-backportable way by switching to an on-stack array. Currently the fscrypt multi-device functionality is used only by f2fs, which has a hardcoded limit of 8 block devices. An on-stack array works fine for that.
(Of course, this solution won't scale up to large number of block devices. For that we'd need a different solution, like moving the block device iteration into the filesystem. Or in the case of btrfs, which will only support blk-crypto-fallback, we should make it just call blk-crypto-fallback directly, so the block devices won't be needed.)
--- fs/crypto/inline_crypt.c | 57 ++++++++++++++-------------------------- fs/f2fs/super.c | 25 ++++++++++-------- include/linux/fscrypt.h | 18 +++++++------ 3 files changed, 44 insertions(+), 56 deletions(-)
fs/crypto/inline_crypt.c +20 -37
@@ -21,22 +21,14 @@#include "fscrypt_private.h" -static struct block_device **fscrypt_get_devices (struct super_block *sb, -unsigned int *num_devs) +static unsigned int +fscrypt_get_devices (struct super_block *sb, +struct block_device *devs[FSCRYPT_MAX_DEVICES ]) { -struct block_device **devs; - -if (sb->s_cop->get_devices) { - devs = sb->s_cop->get_devices (sb, num_devs); -if (devs) -return devs; - } - devs =kmalloc (sizeof (*devs),GFP_KERNEL ); -if (!devs) -return ERR_PTR (-ENOMEM ); +if (sb->s_cop->get_devices) +return sb->s_cop->get_devices (sb, devs); devs[0 ] = sb->s_bdev; - *num_devs =1 ; -return devs; +return 1 ; }static unsigned int fscrypt_get_dun_bytes (const struct fscrypt_inode_info *ci)
@@ -94,7 +86,7 @@ int fscrypt_select_encryption_impl(struct fscrypt_inode_info *ci)const struct inode *inode = ci->ci_inode;struct super_block *sb = inode->i_sb;struct blk_crypto_config crypto_cfg; -struct block_device **devs; +struct block_device *devs[FSCRYPT_MAX_DEVICES ];unsigned int num_devs;unsigned int i;
@@ -131,20 +123,15 @@ int fscrypt_select_encryption_impl(struct fscrypt_inode_info *ci) crypto_cfg.data_unit_size =1U << ci->ci_data_unit_bits; crypto_cfg.dun_bytes =fscrypt_get_dun_bytes (ci); - devs =fscrypt_get_devices (sb, &num_devs); -if (IS_ERR (devs)) -return PTR_ERR (devs); - + num_devs =fscrypt_get_devices (sb, devs);for (i =0 ; i < num_devs; i++) {if (!blk_crypto_config_supported (devs[i], &crypto_cfg)) - goto out_free_devs; +return 0 ; }fscrypt_log_blk_crypto_impl (ci->ci_mode, devs, num_devs, &crypto_cfg); ci->ci_inlinecrypt = true; -out_free_devs: -kfree (devs);return 0 ; }
@@ -157,7 +144,7 @@ int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,struct super_block *sb = inode->i_sb;enum blk_crypto_mode_num crypto_mode = ci->ci_mode->blk_crypto_mode;struct blk_crypto_key *blk_key; -struct block_device **devs; +struct block_device *devs[FSCRYPT_MAX_DEVICES ];unsigned int num_devs;unsigned int i;int err;
@@ -175,17 +162,12 @@ int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key, }/* Start using blk-crypto on all the filesystem's block devices. */ - devs =fscrypt_get_devices (sb, &num_devs); -if (IS_ERR (devs)) { - err =PTR_ERR (devs); - goto fail; - } + num_devs =fscrypt_get_devices (sb, devs);for (i =0 ; i < num_devs; i++) { err =blk_crypto_start_using_key (devs[i], blk_key);if (err)break ; } -kfree (devs);if (err) {fscrypt_err (inode,"error %d starting to use blk-crypto" , err); goto fail;
@@ -203,20 +185,21 @@ void fscrypt_destroy_inline_crypt_key(struct super_block *sb, struct fscrypt_prepared_key *prep_key) {struct blk_crypto_key *blk_key = prep_key->blk_key; -struct block_device **devs; +struct block_device *devs[FSCRYPT_MAX_DEVICES ];unsigned int num_devs;unsigned int i;if (!blk_key)return ; -/* Evict the key from all the filesystem's block devices. */ - devs =fscrypt_get_devices (sb, &num_devs); -if (!IS_ERR (devs)) { -for (i =0 ; i < num_devs; i++) -blk_crypto_evict_key (devs[i], blk_key); -kfree (devs); - } +/* +* Evict the key from all the filesystem's block devices. +* This *must* be done before the key is freed. +*/ + num_devs =fscrypt_get_devices (sb, devs); +for (i =0 ; i < num_devs; i++) +blk_crypto_evict_key (devs[i], blk_key); +kfree_sensitive (blk_key); }
fs/f2fs/super.c +14 -11
@@ -3282,24 +3282,27 @@ static bool f2fs_has_stable_inodes(struct super_block *sb)return true; } -static struct block_device **f2fs_get_devices (struct super_block *sb, -unsigned int *num_devs) +static unsigned int +f2fs_get_devices (struct super_block *sb, +struct block_device *devs[FSCRYPT_MAX_DEVICES ]) {struct f2fs_sb_info *sbi =F2FS_SB (sb); -struct block_device **devs; +int ndevs;int i; -if (!f2fs_is_multi_device (sbi)) -return NULL ; +static_assert (MAX_DEVICES <=FSCRYPT_MAX_DEVICES ); - devs =kmalloc_array (sbi->s_ndevs,sizeof (*devs),GFP_KERNEL ); -if (!devs) -return ERR_PTR (-ENOMEM ); +if (!f2fs_is_multi_device (sbi)) { + devs[0 ] = sb->s_bdev; +return 1 ; + } + ndevs = sbi->s_ndevs; +if (WARN_ON_ONCE (ndevs >FSCRYPT_MAX_DEVICES )) + ndevs =FSCRYPT_MAX_DEVICES ; -for (i =0 ; i < sbi->s_ndevs; i++) +for (i =0 ; i < ndevs; i++) devs[i] =FDEV (i).bdev; - *num_devs = sbi->s_ndevs; -return devs; +return ndevs; }static const struct fscrypt_operations f2fs_cryptops = {
include/linux/fscrypt.h +10 -8
@@ -57,6 +57,9 @@ struct fscrypt_name {/* Maximum value for the third parameter of fscrypt_operations.set_context(). */ #define FSCRYPT_SET_CONTEXT_MAX_SIZE 40 +/* Maximum supported number of block devices per filesystem */ +#define FSCRYPT_MAX_DEVICES 8 +#ifdef CONFIG_FS_ENCRYPTION /* Crypto operations for filesystems */
@@ -175,21 +178,20 @@ struct fscrypt_operations {bool (*has_stable_inodes)(struct super_block *sb);/* -* Return an array of pointers to the block devices to which the -* filesystem may write encrypted file contents, NULL if the filesystem -* only has a single such block device, or an ERR_PTR() on error. +* Retrieve the list of block devices to which the filesystem may write +* encrypted file contents. * -* On successful non-NULL return, *num_devs is set to the number of -* devices in the returned array. The caller must free the returned -* array using kfree(). +* This writes the block_device pointers to @devs and returns the count +* (between 1 and FSCRYPT_MAX_DEVICES inclusively). * * If the filesystem can use multiple block devices (other than block * devices that aren't used for encrypted file contents, such as * external journal devices), and wants to support inline encryption, * then it must implement this function. Otherwise it's not needed. */ -struct block_device **(*get_devices)(struct super_block *sb, -unsigned int *num_devs); +unsigned int (*get_devices)( +struct super_block *sb, +struct block_device *devs[FSCRYPT_MAX_DEVICES ]); };int fscrypt_d_revalidate (struct dentry *dentry,unsigned int flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/602 drm/amd/display: Fix DTB DTO updates breaking live pixel rate sources
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Wentland <[email protected]>
commit 76a2db58e95e328007043f54ac3c7336ccbee440 upstream.
dcn32_update_clocks_update_dtb_dto() and its dcn35 counterpart reprogram the DTB DTO of every timing generator in the context whenever the DTBCLK reference changes, passing a zeroed pixel rate and never setting is_hdmi. Both dccg set_dtbclk_dto() implementations treat a zero pixel rate as a disable request. On dcn32 that branch drives PIPE_DTO_SRC_SEL to the DP DTO source, so a timing generator actively scanning out an HDMI stream has its pixel rate source re-muxed out from under the live raster and the OTG stops on the spot. On dcn35 it clears DTBCLK_DTO_ENABLE and restores DTBCLK_Pn clock gating, which does the same to a live 128b/132b stream.
Two displays where only one runs a 128b/132b link hit this reliably. is_dtbclk_required() holds the DTBCLK reference high while both are active, and the moment the 128b/132b stream is torn down (compositor switch, display disable, hot-unplug) the next safe_to_lower pass drops the reference to the lowest DPM level and the DTO walk freezes the surviving screen. On Navi31 the DAL mailbox then goes deaf on the DISPCLK hard-min that follows the walk in dcn32_update_clocks(), stranding both SMU mailboxes until reboot.
Set is_hdmi for HDMI and DVI signals so the disable path leaves the pixel rate source selection on the HDMI path, and pass the real pixel rate for 128b/132b streams so a reference change rescales their DTO instead of disabling it.
[ mschwartz: dcn32 and dcn35 clk_mgr hunks only. The rest is HDMI FRL
enablement, absent before 7.2, so the FRL conditions and the req_audio_dtbclk_khz assignment they guard are dropped and the FRL-centric changelog is rewritten. Added the pipe_ctx->stream check the new dereferences need. ]
--- .../gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c | 9 ++++++++- .../gpu/drm/amd/display/dc/clk_mgr/dcn35/dcn35_clk_mgr.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c +8 -1
@@ -276,13 +276,20 @@ static void dcn32_update_clocks_update_dtb_dto(struct clk_mgr_internal *clk_mgr,struct dtbclk_dto_params dto_params = {0 };/* use mask to program DTO once per tg */ -if (pipe_ctx->stream_res.tg && +if (pipe_ctx->stream && pipe_ctx->stream_res.tg && !(tg_mask & (1 << pipe_ctx->stream_res.tg->inst))) { tg_mask |= (1 << pipe_ctx->stream_res.tg->inst); dto_params.otg_inst = pipe_ctx->stream_res.tg->inst; dto_params.ref_dtbclk_khz = ref_dtbclk_khz; +if (dccg->ctx->dc->link_srv->dp_is_128b_132b_signal (pipe_ctx)) + dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz /10 ; + +if (dc_is_hdmi_signal (pipe_ctx->stream->signal) || +dc_is_dvi_signal (pipe_ctx->stream->signal)) + dto_params.is_hdmi = true; + dccg->funcs->set_dtbclk_dto (clk_mgr->dccg, &dto_params);//dccg->funcs->set_audio_dtbclk_dto(clk_mgr->dccg, &dto_params); }
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn35/dcn35_clk_mgr.c +8 -1
@@ -247,13 +247,20 @@ static void dcn35_update_clocks_update_dtb_dto(struct clk_mgr_internal *clk_mgr,struct dtbclk_dto_params dto_params = {0 };/* use mask to program DTO once per tg */ -if (pipe_ctx->stream_res.tg && +if (pipe_ctx->stream && pipe_ctx->stream_res.tg && !(tg_mask & (1 << pipe_ctx->stream_res.tg->inst))) { tg_mask |= (1 << pipe_ctx->stream_res.tg->inst); dto_params.otg_inst = pipe_ctx->stream_res.tg->inst; dto_params.ref_dtbclk_khz = ref_dtbclk_khz; +if (dccg->ctx->dc->link_srv->dp_is_128b_132b_signal (pipe_ctx)) + dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz /10 ; + +if (dc_is_hdmi_signal (pipe_ctx->stream->signal) || +dc_is_dvi_signal (pipe_ctx->stream->signal)) + dto_params.is_hdmi = true; + dccg->funcs->set_dtbclk_dto (clk_mgr->dccg, &dto_params);//dccg->funcs->set_audio_dtbclk_dto(clk_mgr->dccg, &dto_params); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/602 io_uring/rw: fix missing ERESTARTSYS conversion in read paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yitang Yang <[email protected]>
commit ab05caca123c6d0b41850b7c05b246e4dca4a770 upstream.
Both read and write may receive internal restart error codes from the filesystem layer and should be converted to -EINTR. However, when multishot read support was added, the error code normalization was lost for both io_read() and io_read_mshot().
Extract the conversion into io_fixup_restart_res() and apply it in all three locations: io_rw_done(), io_read(), and io_read_mshot().
--- io_uring/rw.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
io_uring/rw.c +25 -17
@@ -560,6 +560,24 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res)smp_store_release (&req->iopoll_completed,1 ); } +static inline ssize_t io_fixup_restart_res (ssize_t ret) +{ +switch (ret) { +case -ERESTARTSYS : +case -ERESTARTNOINTR : +case -ERESTARTNOHAND : +case -ERESTART_RESTARTBLOCK : +/* +* We can't just restart the syscall, since previously +* submitted sqes may already be in progress. Just fail +* this IO with EINTR. +*/ +return -EINTR ; +default : +return ret; + } +} +static inline void io_rw_done (struct kiocb *kiocb,ssize_t ret) {/* IO was queued async, completion will happen later */
@@ -567,21 +585,8 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)return ;/* transform internal restart error codes */ -if (unlikely (ret <0 )) { -switch (ret) { -case -ERESTARTSYS : -case -ERESTARTNOINTR : -case -ERESTARTNOHAND : -case -ERESTART_RESTARTBLOCK : -/* -* We can't just restart the syscall, since previously -* submitted sqes may already be in progress. Just fail -* this IO with EINTR. -*/ - ret = -EINTR ; -break ; - } - } +if (unlikely (ret <0 )) + ret =io_fixup_restart_res (ret);INDIRECT_CALL_2 (kiocb->ki_complete, io_complete_rw_iopoll, io_complete_rw, kiocb, ret);
@@ -961,7 +966,8 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags)if (req->flags &REQ_F_BUFFERS_COMMIT )io_kbuf_recycle (req, sel.buf_list, issue_flags); -return ret; + +return io_fixup_restart_res (ret); }int io_read_mshot (struct io_kiocb *req,unsigned int issue_flags)
@@ -995,8 +1001,10 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)return -EAGAIN ; }else if (ret <=0 ) {io_kbuf_recycle (req, sel.buf_list, issue_flags); -if (ret <0 ) +if (ret <0 ) { + ret =io_fixup_restart_res (ret);req_set_fail (req); + } }else if (!(req->flags &REQ_F_APOLL_MULTISHOT )) { cflags =io_put_kbuf (req, ret, sel.buf_list); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/602 net: pcs: xpcs: fix SGMII state reading
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Coia Prant <[email protected]>
commit def9a4745e105145133e442dd8a1c126caf0f553 upstream.
Commit 2a22b7ae2fa3 ("net: pcs: xpcs: adapt Wangxun NICs for SGMII mode") added a path in xpcs_get_state_c37_sgmii() that reads speed/duplex from BMCR after AN completes. However, BMCR does not reflect the negotiated result on the hardware where this has been tested:
- On RK3568 (MAC side SGMII), BMCR returns a fixed hardware reset value
- Wangxun engineer Jiawen Wu confirmed that on their side, "BMCR looks like it only wants to be return as 0" [0]
The correct information is available in CL37_ANSGM_STS, which contains the actual link status and negotiated speed/duplex.
This bug was previously masked by phylink core, which overrides the PCS link state with the PHY state when a PHY is present:
/* If we have a phy, the "up" state is the union of both the
* PHY and the MAC
*/
if (phy)
link_state.link &= pl->phy_state.link;Thus, when the link is down, the PHY's link_down state is applied on top of whatever the PCS reports, hiding the broken PCS state reading path.
Modify xpcs_get_state_c37_sgmii() to:
1. Read link state from CL37_ANSGM_STS
2. If link is up, report speed/duplex from CL37_ANSGM_STS
3. Remove the broken BMCR reading path entirely
Also properly set state->an_complete to reflect the AN completion status, and clear CL37_ANCMPLT_INTR when link is down to avoid stale state.
[0] https://lore.kernel.org/all/[email protected]/
--- drivers/net/pcs/pcs-xpcs.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-)
drivers/net/pcs/pcs-xpcs.c +7 -25
@@ -973,6 +973,7 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,/* Reset link_state */ state->link = false; + state->an_complete = false; state->speed =SPEED_UNKNOWN ; state->duplex =DUPLEX_UNKNOWN ; state->pause =0 ;
@@ -984,6 +985,8 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,if (ret <0 )return ret; + state->an_complete = ret &DW_VR_MII_AN_STS_C37_ANCMPLT_INTR ; +if (ret &DW_VR_MII_C37_ANSGM_SP_LNKSTS ) {int speed_value;
@@ -1002,34 +1005,13 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, state->duplex =DUPLEX_FULL ; else state->duplex = DUPLEX_HALF; - }else if (ret ==DW_VR_MII_AN_STS_C37_ANCMPLT_INTR ) { -int speed, duplex; - - state->link = true; - - speed =xpcs_read (xpcs,MDIO_MMD_VEND2 ,MDIO_CTRL1 ); -if (speed <0 ) -return speed; - - speed &=SGMII_SPEED_SS13 |SGMII_SPEED_SS6 ; -if (speed ==SGMII_SPEED_SS6 ) - state->speed =SPEED_1000 ; -else if (speed ==SGMII_SPEED_SS13 ) - state->speed =SPEED_100 ; -else if (speed ==0 ) - state->speed =SPEED_10 ; - - duplex =xpcs_read (xpcs,MDIO_MMD_VEND2 ,MII_ADVERTISE ); -if (duplex <0 ) -return duplex; -if (duplex &DW_FULL_DUPLEX ) - state->duplex =DUPLEX_FULL ; -else if (duplex &DW_HALF_DUPLEX ) - state->duplex =DUPLEX_HALF ; +return 0 ; + } +/* Clear AN complete status or interrupt */ +if (state->an_complete)xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); - }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/602 gve: fix Rx queue stall on alloc failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eddie Phillips <[email protected]>
commit b65352a1bac64442ad95e64f385b40ccb9f1b0db upstream.
When the system is under extreme memory pressure, page allocations can fail during the Rx buffer refill loop. If the number of buffers posted to hardware falls below a critical low threshold and the refill loop exits due to allocation failures, the queue can stall:
1. The device drops incoming packets because there are no descriptors.
2. Since no packets are processed, no Rx completions are generated.
3. Because no completions occur, NAPI is never scheduled, preventing the refill loop from running again even after memory is freed.
This results in a permanent queue stall.
Resolve this by introducing a starvation recovery timer for each Rx queue. If the number of buffers posted to hardware falls below a critical low threshold, start a timer to periodically reschedule NAPI. Once NAPI runs and successfully refills the queue above the threshold, the timer is not rescheduled.
The threshold is set to 32 because a single maximum-sized Receive Segment Coalescing (RSC) packet can consume up to 19 descriptors in the Rx path. Lower thresholds (such as 8 or 16) would be insufficient to process a complete maximum-sized RSC packet, risking packet drops or unexpected hardware behavior under memory pressure. Setting the threshold to 32 guarantees a safe margin to handle at least one full RSC packet.
--- drivers/net/ethernet/google/gve/gve.h | 3 ++ drivers/net/ethernet/google/gve/gve_rx_dqo.c | 36 ++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/net/ethernet/google/gve/gve.h +3 -0
@@ -12,6 +12,7 @@#include <linux/ethtool_netlink.h> #include <linux/netdevice.h> #include <linux/pci.h> +#include <linux/timer.h> #include <linux/u64_stats_sync.h> #include <net/xdp.h>
@@ -38,6 +39,7 @@/* Interval to schedule a stats report update, 20000ms. */ #define GVE_STATS_REPORT_TIMER_PERIOD 20000 +#define GVE_RX_NAPI_RESCHED_MS 20/* msecs */ /* Numbers of NIC tx/rx stats in stats report. */ #define NIC_TX_STATS_REPORT_NUM 0
@@ -311,6 +313,7 @@ struct gve_rx_ring {struct xdp_rxq_info xsk_rxq;struct xsk_buff_pool *xsk_pool;struct page_frag_cache page_cache;/* Page cache to allocate XDP frames */ +struct timer_list starvation_timer;/* for queue starvation recovery */ };/* A TX desc ring entry */
drivers/net/ethernet/google/gve/gve_rx_dqo.c +36 -0
@@ -199,6 +199,16 @@ static int gve_alloc_page_dqo(struct gve_rx_ring *rx,return 0 ; } +static void gve_rx_starvation_timer (struct timer_list *t) +{ +struct gve_rx_ring *rx =from_timer (rx, t, starvation_timer); +struct gve_priv *priv = rx->gve; +struct gve_notify_block *block; + + block = &priv->ntfy_blocks[rx->ntfy_id]; +napi_schedule (&block->napi); +} +static void gve_rx_free_hdr_bufs (struct gve_priv *priv,struct gve_rx_ring *rx) {struct device *hdev = &priv->pdev->dev;
@@ -290,10 +300,13 @@ static void gve_rx_reset_ring_dqo(struct gve_priv *priv, int idx)void gve_rx_stop_ring_dqo (struct gve_priv *priv,int idx) {int ntfy_idx =gve_rx_idx_to_ntfy (priv, idx); +struct gve_rx_ring *rx = &priv->rx[idx];if (!gve_rx_was_added_to_block (priv, idx))return ; +timer_shutdown_sync (&rx->starvation_timer); +gve_remove_napi (priv, ntfy_idx);gve_rx_remove_from_block (priv, idx);gve_rx_reset_ring_dqo (priv, idx);
@@ -371,8 +384,10 @@ static int gve_rx_alloc_hdr_bufs(struct gve_priv *priv, struct gve_rx_ring *rx,void gve_rx_start_ring_dqo (struct gve_priv *priv,int idx) {int ntfy_idx =gve_rx_idx_to_ntfy (priv, idx); +struct gve_rx_ring *rx = &priv->rx[idx];gve_rx_add_to_block (priv, idx); +timer_setup (&rx->starvation_timer, gve_rx_starvation_timer,0 );gve_add_napi (priv, ntfy_idx, gve_napi_poll_dqo); }
@@ -511,6 +526,7 @@ void gve_rx_post_buffers_dqo(struct gve_rx_ring *rx)struct gve_rx_compl_queue_dqo *complq = &rx->dqo.complq;struct gve_rx_buf_queue_dqo *bufq = &rx->dqo.bufq;struct gve_priv *priv = rx->gve; +u32 num_bufs_avail_to_hw;u32 num_avail_slots;u32 num_full_slots;u32 num_posted =0 ;
@@ -555,6 +571,26 @@ void gve_rx_post_buffers_dqo(struct gve_rx_ring *rx) } rx->fill_cnt += num_posted; + +/* If the queue has fewer than GVE_RX_BUF_THRESH_DQO descriptors +* visible to the hardware, the hardware is in danger of starving +* and cannot trigger interrupts. +* +* We use a threshold of 32 because a single maximum-sized RSC +* packet can consume up to 19 descriptors in the Rx path. Lower +* thresholds (e.g., 8 or 16) would be unsafe as they could cause +* the device to drop/stall on a maximum-sized RSC packet. +* +* Start the timer to periodically reschedule NAPI and recover. +*/ + num_bufs_avail_to_hw = + ((bufq->tail & ~(GVE_RX_BUF_THRESH_DQO -1 )) - + bufq->head) & bufq->mask; + +if (num_bufs_avail_to_hw <GVE_RX_BUF_THRESH_DQO ) { +mod_timer (&rx->starvation_timer, + jiffies +msecs_to_jiffies (GVE_RX_NAPI_RESCHED_MS )); + } } static void gve_try_recycle_buf(struct gve_priv *priv, struct gve_rx_ring *rx,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/602 rust: allow `suspicious_runtime_symbol_definitions` lint for Rust >= 1.98
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miguel Ojeda <[email protected]>
commit 608045a91d9176d66b2114d0006bc8b57dff2ca9 upstream.
Starting with Rust 1.98.0 (expected 2026-08-20), Rust is introducing a couple new lints, invalid_runtime_symbol_definitions (deny-by-default) and suspicious_runtime_symbol_definitions (warn-by-default), which check the signature of items whose symbol name is a runtime symbol expected by core.
Our build hits the second one, i.e. the warning:
error: suspicious definition of the runtime `strlen` symbol used by the standard library
--> rust/bindings/bindings_generated.rs:20018:5
|
20018 | pub fn strlen(s: *const ffi::c_char) -> usize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const i8) -> usize`
found `unsafe extern "C" fn(*const u8) -> usize`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "strlen")]`, or `#[link_name = "strlen"]`
= help: allow this lint if the signature is compatible
= note: `-D suspicious-runtime-symbol-definitions` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(suspicious_runtime_symbol_definitions)]`
error: suspicious definition of the runtime `strlen` symbol used by the standard library
--> rust/uapi/uapi_generated.rs:14236:5
|
14236 | pub fn strlen(s: *const ffi::c_char) -> usize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const i8) -> usize`
found `unsafe extern "C" fn(*const u8) -> usize`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "strlen")]`, or `#[link_name = "strlen"]`
= help: allow this lint if the signature is compatible
= note: `-D suspicious-runtime-symbol-definitions` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(suspicious_runtime_symbol_definitions)]`Thus allow the lint in bindings and uapi.
A more targeted alternative to avoid allowing it would be to pass --blocklist-function strlen to bindgen, but we would perhaps need to adjust if other C headers end up adding more (or Rust checking more). Since it is just the less critical one that we hit, and since eventually this should be properly fixed by getting upstream Rust to provide a flag like GCC/Clang's -funsigned-char [2][3], just allow it for now.
--- init/Kconfig | 3 +++ rust/bindings/lib.rs | 4 ++++ rust/uapi/lib.rs | 4 ++++ 3 files changed, 11 insertions(+)
init/Kconfig +3 -0
@@ -140,6 +140,9 @@ config LD_CAN_USE_KEEP_IN_OVERLAY config RUSTC_HAS_UNNECESSARY_TRANSMUTES def_bool RUSTC_VERSION >= 108800 +config RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS + def_bool RUSTC_VERSION >= 109800 + config PAHOLE_VERSION int default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE))
rust/bindings/lib.rs +4 -0
@@ -27,6 +27,10 @@#[allow(dead_code)] #[allow(clippy::undocumented_unsafe_blocks)] #[cfg_attr( CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES , allow(unnecessary_transmutes))] +#[cfg_attr( +CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS , +allow(suspicious_runtime_symbol_definitions) +)] mod bindings_raw {// Manual definition for blocklisted types. type __kernel_size_t =usize ;
rust/uapi/lib.rs +4 -0
@@ -25,6 +25,10 @@ unsafe_op_in_unsafe_fn )]#![cfg_attr( CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES , allow(unnecessary_transmutes))] +#![cfg_attr( +CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS , +allow(suspicious_runtime_symbol_definitions) +)] // Manual definition of blocklisted types. type __kernel_size_t =usize ;
Greg Kroah-Hartman
maintainerPATCH 463/602 mm/damon/core: validate ranges in damon_set_regions()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 1292c0ecb1caefb8ca064a3639d5673991e8810c upstream.
DAMON core logic assumes zero length regions don't exist. However, a few DAMON API callers including DAMON_SYSFS, DAMON_RECLAIM and DAMON_LRU_SORT allow users to set empty monitoring target regions. This could result in WARN_ONCE() on CONFIG_DAMON_DEBUG_SANITY enabled kernel, and divide-by-zero from damon_merge_two_regions().
For example, the WANR_ONCE() can be triggered like below.
# grep DAMON_DEBUG_SANITY /boot/config-$(uname -r)
# CONFIG_DAMON_DEBUG_SANITY=y
# damo start
# cd /sys/kernel/mm/damon/admin/kdamonds/0
# echo 0 > contexts/0/targets/0/regions/0/start
# echo 0 > contexts/0/targets/0/regions/0/end
# echo commit > state
# dmesg
[....]
[ 73.705780] ------------[ cut here ]------------
[ 73.707552] start 0 >= end 0
[ 73.708452] WARNING: mm/damon/core.c:359 at damon_new_region+0x6e/0x80, CPU#1: kdamond.0/758
[...]All DAMON API callers eventually use damon_set_regions() to setup the regions. Add the validation logic in the function.
--- mm/damon/core.c | 6 ++++++ 1 file changed, 6 insertions(+)
mm/damon/core.c +6 -0
@@ -214,6 +214,12 @@ int damon_set_regions(struct damon_targeunsigned int i;int err; +for (i =0 ; i < nr_ranges; i++) { +if (ALIGN_DOWN (ranges[i].start,DAMON_MIN_REGION ) >= +ALIGN (ranges[i].end,DAMON_MIN_REGION )) +return -EINVAL ; + } +/* Remove regions which are not in the new ranges */ damon_for_each_region_safe (r, next, t) {for (i =0 ; i < nr_ranges; i++) {
Greg Kroah-Hartman
maintainerPATCH 464/602 mm/damon/core: disallow overlapping input ranges for damon_set_regions()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 954157679ec34661c2e87e7eb796104a797c32db upstream.
damon_set_regions() assumes the input ranges are sorted by the address and don't overlap each other. Hence the assumption was initially to be explicitly validated. But commit 97d482f4592f ("mm/damon/sysfs: reuse damon_set_regions() for regions setting") has mistakenly removed the validation.
This can make DAMON behave in unexpected ways. At the best, the monitoring results snapshot will just look weird since there will be overlapping regions. DAMOS will also work weirdly, applying the same action multiple times for overlapping regions, and make DAMOS quota weird. More seriously, depending on the setup and regions updates sequence, negative size regions can be made. It will trigger WARN_ONCE() if the kernel is built with CONFIG_DAMON_DEBUG_SANITY=y. Depending on the monitoring results, the negative size region can further trigger division by zero in damon_merge_two_regions().
Note that some of the consequences including the WARN_ONCE() and the divide by zero depend on commits that were introduced after the root cause commit 97d482f4592f ("mm/damon/sysfs: reuse damon_set_regions() for regions setting").
Fix the problems by checking the assumption and returning an error if the input ranges don't meet the assumption.
The issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/damon/core.c +9 -2
@@ -212,12 +212,19 @@ int damon_set_regions(struct damon_targe {struct damon_region *r, *next;unsigned int i; +unsigned long last_end;int err;for (i =0 ; i < nr_ranges; i++) { -if (ALIGN_DOWN (ranges[i].start,DAMON_MIN_REGION ) >= -ALIGN (ranges[i].end,DAMON_MIN_REGION )) +unsigned long start, end; + + start =ALIGN_DOWN (ranges[i].start,DAMON_MIN_REGION ); + end =ALIGN (ranges[i].end,DAMON_MIN_REGION ); +if (start >= end) +return -EINVAL ; +if (i >0 && last_end > start)return -EINVAL ; + last_end = end; }/* Remove regions which are not in the new ranges */
Greg Kroah-Hartman
maintainerPATCH 465/602 iommufd: Reject invalid read count in iommufd_fault_fops_read()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
[ Upstream commit 47916a54eeb2a9e654512ee609f71bd5b29db702 ]
The read count must be large enough to hold one fault or a group's faults.
iommufd_fault_fops_read() does not validate the count, but returns 0 as if the read had succeeded while leaving the pending fault in the queue.
Return -EINVAL in the undersize cases.
--- drivers/iommu/iommufd/fault.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iommu/iommufd/fault.c +3 -0
@@ -273,6 +273,9 @@ static ssize_t iommufd_fault_fops_read(sif (done >= count || group->fault_count * fault_size > count - done) {iommufd_fault_deliver_restore (fault, group); +/* Read count doesn't fit the first fault group */ +if (done ==0 ) + rc = -EINVAL ;break ; }
Greg Kroah-Hartman
maintainerPATCH 466/602 iommufd: Break the loop on failure in iommufd_fault_fops_read()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
[ Upstream commit 172fc8b19825a0f5884c38f2289188284e2d45ee ]
On a copy_to_user() failure inside the inner list_for_each_entry, only the inner loop breaks; the outer while re-fetches the just-restored fault group and retries the failing copy_to_user() forever, spinning the reader at 100% CPU with fault->mutex held.
Check rc after the inner loop and break the outer while as well.
--- drivers/iommu/iommufd/fault.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iommu/iommufd/fault.c +2 -0
@@ -299,6 +299,8 @@ static ssize_t iommufd_fault_fops_read(s } done += fault_size; } +if (rc) +break ; }mutex_unlock (&fault->mutex);
Greg Kroah-Hartman
maintainerPATCH 467/602 iommufd: Avoid partial fault group delivery in iommufd_fault_fops_read()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
[ Upstream commit 091ab6d70dc444f56ed14faedbcacfc979f4c613 ]
The cookie returned by xa_alloc() in iommufd_fault_fops_read() is per fault group, but the inner copy_to_user() runs per fault inside the group. If a copy fails mid-group, xa_erase clears the cookie and the group is restored to the deliver list, yet done is not rolled back. The function returns the partial byte count, with the successfully copied faults sitting at offsets below done carrying the now-erased cookie. The next read() then re-fetches the group, allocates a fresh cookie, and re-delivers every fault including the ones already copied; userspace sees duplicates carrying the new cookie, and a stale cookie that can never be responded to.
Use a local group_done variable that tracks the per-group progress inside the inner loop, and only commit done = group_done after the inner loop has finished successfully. On a copy_to_user failure the outer break skips the commit, so done remains at its prior start-of-group baseline; the partial bytes already written past done are undefined to userspace per the read(2) contract, and the next read re-delivers the whole group atomically.
--- drivers/iommu/iommufd/fault.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/iommufd/fault.c +5 -2
@@ -270,6 +270,8 @@ static ssize_t iommufd_fault_fops_read(smutex_lock (&fault->mutex);while ((group =iommufd_fault_deliver_fetch (fault))) { +size_t group_done = done; +if (done >= count || group->fault_count * fault_size > count - done) {iommufd_fault_deliver_restore (fault, group);
@@ -291,16 +293,17 @@ static ssize_t iommufd_fault_fops_read(siommufd_compose_fault_message (&iopf->fault, &data, idev, group->cookie); -if (copy_to_user (buf + done, &data, fault_size)) { +if (copy_to_user (buf + group_done, &data, fault_size)) {xa_erase (&fault->response, group->cookie);iommufd_fault_deliver_restore (fault, group); rc = -EFAULT ;break ; } - done += fault_size; + group_done += fault_size; }if (rc)break ; + done = group_done; }mutex_unlock (&fault->mutex);
Greg Kroah-Hartman
maintainerPATCH 468/602 fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
[ Upstream commit fc3b071a7c8dc0f5d56defddf6e6fd5aaa3e1e27 ]
afu_ioctl_dma_map() accepts a 64-bit length from userspace via DFL_FPGA_PORT_DMA_MAP ioctl without an upper bound check. The value is passed to afu_dma_pin_pages() where npages is derived as length >> PAGE_SHIFT and passed to pin_user_pages_fast() which takes int nr_pages, causing implicit truncation if length is very large.
Validate map.length at the ioctl entry point before calling afu_dma_map_region(), rejecting values whose page count exceeds INT_MAX.
--- drivers/fpga/dfl-afu-main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/fpga/dfl-afu-main.c +3 -0
@@ -720,6 +720,9 @@ afu_ioctl_dma_map(struct dfl_feature_plaif (map.argsz < minsz || map.flags)return -EINVAL ; +if (map.length >>PAGE_SHIFT > (u64 )INT_MAX ) +return -EINVAL ; + ret =afu_dma_map_region (pdata, map.user_addr, map.length, &map.iova);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 469/602 i2c: davinci: Unregister cpufreq notifier on probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
[ Upstream commit e43f32816a1b1fe5a86279411626fe3a9be56d45 ]
davinci_i2c_probe() registers a cpufreq transition notifier before adding the I2C adapter. If i2c_add_numbered_adapter() fails, the probe error path releases the device resources without unregistering the notifier.
Add a dedicated error path to unregister the cpufreq notifier after i2c_add_numbered_adapter() fails.
--- drivers/i2c/busses/i2c-davinci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-davinci.c +3 -1
@@ -864,13 +864,15 @@ static int davinci_i2c_probe(struct plat adap->nr = pdev->id; r =i2c_add_numbered_adapter (adap);if (r) - goto err_unuse_clocks; + goto err_cpufreq;pm_runtime_mark_last_busy (dev->dev);pm_runtime_put_autosuspend (dev->dev);return 0 ; +err_cpufreq: +i2c_davinci_cpufreq_deregister (dev); err_unuse_clocks:pm_runtime_dont_use_autosuspend (dev->dev);pm_runtime_put_sync (dev->dev);
Re: [PATCH 6.12 469/602] i2c: davinci: Unregister cpufreq notifier on probe failure
Quoted 36 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
[ Upstream commit
e43f32816a1b1fe5a86279411626fe3a9be56d45]
davinci_i2c_probe()registers a cpufreq transition notifier before adding the I2C adapter. Ifi2c_add_numbered_adapter()fails, the probe error path releases the device resources without unregistering the notifier.Add a dedicated error path to unregister the cpufreq notifier after
i2c_add_numbered_adapter()fails.Fixes 82c0de11b734 ("i2c: davinci: Add cpufreq support")Signed-off-by Haoxiang Li <[email protected]>Cc <[email protected]> # v2.6.36+Reviewed-by Bartosz Golaszewski <[email protected]>Signed-off-by Andi Shyti <[email protected]>Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/i2c/busses/i2c-davinci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i2c/busses/i2c-davinci.c +1
-1@@ -864,13 +864,15 @@ static int davinci_i2c_probe(struct plat adap->nr = pdev->id; r =i2c_add_numbered_adapter (adap);if (r) - goto err_unuse_clocks; + goto err_cpufreq;
drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct plat · line 878
Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +2
-0pm_runtime_mark_last_busy (dev->dev);pm_runtime_put_autosuspend (dev->dev);return 0 ; +err_cpufreq: +i2c_davinci_cpufreq_deregister (dev); err_unuse_clocks:pm_runtime_dont_use_autosuspend (dev->dev);pm_runtime_put_sync (dev->dev);
Hi Greg/Sasha,
I ran an AI-assisted backport review and checked this manually. The backport handles the i2c_add_numbered_adapter() failure, but 6.12.y has two additional failure paths after the cpufreq notifier is registered:
if (IS_ERR(rinfo->scl_gpiod)) {
r = PTR_ERR(rinfo->scl_gpiod);
goto err_unuse_clocks;
} if (IS_ERR(rinfo->sda_gpiod)) {
r = PTR_ERR(rinfo->sda_gpiod);
goto err_unuse_clocks;
}
Both bypass:
err_cpufreq:
i2c_davinci_cpufreq_deregister(dev);
The GPIO recovery code is absent upstream becauseb04ce6385979 ("i2c: davinci: kill platform data") removed it, but it still exists in 6.12.y. If either lookup fails, probe cleanup frees the device containing the registered notifier while the cpufreq chain retains its address.
I think this backport is incomplete; I think route both GPIO failure branches through err_cpufreq:
Thanks,
harshit
Quoted 3 lines
Sasha Levin
maintainerRe: [PATCH 6.12 469/602] i2c: davinci: Unregister cpufreq notifier on probe failure
Quoted 2 lines · Harshit Mogalapalli
I think this backport is incomplete; I think route both GPIO failure branches through
err_cpufreq:
Both IS_ERR() checks are inside "else if (dev->pdata->gpio_recovery)", and nothing sets gpio_recovery in either tree - dead code.
They also used "goto err_unuse_clocks" before this patch, so it's a pre-existing gap, not a regression. The patch fixes the i2c_add_numbered_adapter() leak; dropping it is strictly worse.
And since b04ce6385979 deleted the block in v6.14, there's no upstream commit to backport for the rest.
Thanks for the review.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 6.12 469/602] i2c: davinci: Unregister cpufreq notifier on probe failure
Hi Sasha,
Quoted 11 lines · Sasha Levin
Quoted 2 lines · Harshit Mogalapalli
I think this backport is incomplete; I think route both GPIO failure branches through
err_cpufreq:Both
IS_ERR()checks are inside "else if (dev->pdata->gpio_recovery)", and nothing setsgpio_recoveryin either tree - dead code.They also used "goto
err_unuse_clocks" before this patch, so it's a pre-existing gap, not a regression. The patch fixes thei2c_add_numbered_adapter()leak; dropping it is strictly worse.
Yep agreed, thanks fore checking sasha, just that it is unusual to do that. Nothing to fix, thanks!
Regards,
harshit
Quoted 5 lines
And since
b04ce6385979deleted the block in v6.14, there's no upstream commit to backport for the rest.Thanks for the review.
Greg Kroah-Hartman
maintainerPATCH 470/602 VFS/audit: introduce kern_path_parent() for audit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 76a53de6f7ff0641570364234fb4489f4d4fc8e9 ]
audit_alloc_mark() and audit_get_nd() both need to perform a path lookup getting the parent dentry (which must exist) and the final target (following a LAST_NORM name) which sometimes doesn't need to exist.
They don't need the parent to be locked, but use kern_path_locked() or kern_path_locked_negative() anyway. This is somewhat misleading to the casual reader.
This patch introduces a more targeted function, kern_path_parent(), which returns not holding locks. On success the "path" will be set to the parent, which must be found, and the return value is the dentry of the target, which might be negative.
This will clear the way to rename kern_path_locked() which is otherwise only used to prepare for removing something.
It also allows us to remove kern_path_locked_negative(), which is transformed into the new kern_path_parent().
Stable-dep-of: 81905b5acbe7 ("audit: fix recursive locking deadlock in audit_dupe_exe()")
--- fs/namei.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/namei.h | 1 + kernel/audit.h | 4 ++-- kernel/audit_fsnotify.c | 9 +++------ kernel/audit_watch.c | 9 ++++++--- 5 files changed, 55 insertions(+), 11 deletions(-)
fs/namei.c +43 -0
@@ -2705,6 +2705,49 @@ static struct dentry *__kern_path_lockedreturn d; } +/** +* kern_path_parent: lookup path returning parent and target +* @name: path name +* @path: path to store parent in +* +* The path @name should end with a normal component, not "." or ".." or "/". +* A lookup is performed and if successful the parent information +* is store in @parent and the dentry is returned. +* +* The dentry maybe negative, the parent will be positive. +* +* Returns: dentry or error. +*/ +struct dentry *kern_path_parent (const char *name,struct path *path) +{ +struct filename *filename =getname_kernel (name); +struct path parent_path; +struct dentry *d; +struct qstr last; +int type, error; + + error =filename_parentat (AT_FDCWD , filename,0 , &parent_path, &last, &type); +if (error) { + d =ERR_PTR (error); + goto out; + } +if (unlikely (type !=LAST_NORM )) { +path_put (&parent_path); + d =ERR_PTR (-EINVAL ); + goto out; + } + + d =lookup_one_len_unlocked (last.name, parent_path.dentry, last.len); +if (IS_ERR (d)) { +path_put (&parent_path); + goto out; + } + *path = parent_path; +out: +putname (filename); +return d; +} +struct dentry *kern_path_locked (const char *name,struct path *path) {struct filename *filename =getname_kernel (name);
include/linux/namei.h +1 -0
@@ -51,6 +51,7 @@ struct dentry *lookup_one_qstr_excl(consstruct dentry *base, unsigned int flags);extern int kern_path (const char *,unsigned ,struct path *); +struct dentry *kern_path_parent (const char *name,struct path *parent);extern struct dentry *kern_path_create (int ,const char *,struct path *,unsigned int );extern struct dentry *user_path_create (int ,const char __user *,struct path *,unsigned int );
kernel/audit.h +2 -2
@@ -279,8 +279,8 @@ extern struct audit_fsnotify_mark *auditextern char *audit_mark_path (struct audit_fsnotify_mark *mark);extern void audit_remove_mark (struct audit_fsnotify_mark *audit_mark);extern void audit_remove_mark_rule (struct audit_krule *krule); -extern int audit_mark_compare (struct audit_fsnotify_mark *mark, -unsigned long ino,dev_t dev); +extern int audit_mark_compare (struct audit_fsnotify_mark *mark,u64 ino, +dev_t dev);extern int audit_dupe_exe (struct audit_krule *new,struct audit_krule *old);extern int audit_exe_compare (struct task_struct *tsk,struct audit_fsnotify_mark *mark);
kernel/audit_fsnotify.c +3 -6
@@ -57,7 +57,7 @@ char *audit_mark_path(struct audit_fsnotreturn mark->path; } -int audit_mark_compare (struct audit_fsnotify_mark *mark,unsigned long ino,dev_t dev) +int audit_mark_compare (struct audit_fsnotify_mark *mark,u64 ino,dev_t dev) {if (mark->ino ==AUDIT_INO_UNSET )return 0 ;
@@ -76,17 +76,14 @@ struct audit_fsnotify_mark *audit_alloc_struct audit_fsnotify_mark *audit_mark;struct path path;struct dentry *dentry; -struct inode *inode;int ret;if (pathname[0 ] !='/' || pathname[len-1 ] =='/' )return ERR_PTR (-EINVAL ); - dentry =kern_path_locked (pathname, &path); + dentry =kern_path_parent (pathname, &path);if (IS_ERR (dentry))return ERR_CAST (dentry);/* returning an error */ - inode = path.dentry->d_inode; -inode_unlock (inode); audit_mark =kzalloc (sizeof (*audit_mark),GFP_KERNEL );if (unlikely (!audit_mark)) {
@@ -100,7 +97,7 @@ struct audit_fsnotify_mark *audit_alloc_audit_update_mark (audit_mark, dentry->d_inode); audit_mark->rule = krule; - ret =fsnotify_add_inode_mark (&audit_mark->mark, inode,0 ); + ret =fsnotify_add_inode_mark (&audit_mark->mark, path.dentry->d_inode,0 );if (ret <0 ) { audit_mark->path =NULL ;fsnotify_put_mark (&audit_mark->mark);
kernel/audit_watch.c +6 -3
@@ -244,7 +244,7 @@ static void audit_watch_log_rule_change(/* Update inode info in audit rules based on filesystem event. */ static void audit_update_watch (struct audit_parent *parent,const struct qstr *dname,dev_t dev, -unsigned long ino,unsigned invalidating) +u64 ino,unsigned int invalidating) {struct audit_watch *owatch, *nwatch, *nextw;struct audit_krule *r, *nextr;
@@ -347,15 +347,18 @@ static void audit_remove_parent_watches(/* Get path information necessary for adding watches. */ static int audit_get_nd (struct audit_watch *watch,struct path *parent) { -struct dentry *d =kern_path_locked (watch->path, parent); +struct dentry *d; + + d =kern_path_parent (watch->path, parent);if (IS_ERR (d))return PTR_ERR (d); +if (d_is_positive (d)) {/* update watch filter fields */ watch->dev = d->d_sb->s_dev; watch->ino =d_backing_inode (d)->i_ino; } -inode_unlock (d_backing_inode (parent->dentry)); +dput (d);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 471/602 audit: widen ino fields to u64
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 125dfa218134df7cc112667e92984de9d8cd0bf6 ]
inode->i_ino is being widened from unsigned long to u64. The audit subsystem uses unsigned long ino in struct fields, function parameters, and local variables that store inode numbers from arbitrary filesystems. On 32-bit platforms this truncates inode numbers that exceed 32 bits, which will cause incorrect audit log entries and broken watch/mark comparisons.
Widen all audit ino fields, parameters, and locals to u64, and update the inode format string from %lu to %llu to match.
Stable-dep-of: 81905b5acbe7 ("audit: fix recursive locking deadlock in audit_dupe_exe()")
--- include/linux/audit.h | 2 +- kernel/audit.h | 9 ++++----- kernel/audit_fsnotify.c | 2 +- kernel/audit_watch.c | 10 +++++----- kernel/auditsc.c | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-)
include/linux/audit.h +1 -1
@@ -16,7 +16,7 @@#include <uapi/linux/netfilter/nf_tables.h> #include <uapi/linux/fanotify.h> -#define AUDIT_INO_UNSET ((unsigned long)-1) +#define AUDIT_INO_UNSET ((u64)-1)#define AUDIT_DEV_UNSET ((dev_t)-1)struct audit_sig_info {
kernel/audit.h +4 -5
@@ -75,7 +75,7 @@ struct audit_names {int name_len;/* number of chars to log */ bool hidden;/* don't log this record */ -unsigned long ino; +u64 ino;dev_t dev;umode_t mode;kuid_t uid;
@@ -219,9 +219,9 @@ extern int auditd_test_task(struct task_#define AUDIT_INODE_BUCKETS 32extern struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS ]; -static inline int audit_hash_ino (u32 ino) +static inline int audit_hash_ino (u64 ino) { -return (ino & (AUDIT_INODE_BUCKETS -1 )); +return ((u32 )ino & (AUDIT_INODE_BUCKETS -1 )); }/* Indicates that audit should log the full pathname. */
@@ -271,8 +271,7 @@ extern int audit_to_watch(struct audit_kextern int audit_add_watch (struct audit_krule *krule,struct list_head **list);extern void audit_remove_watch_rule (struct audit_krule *krule);extern char *audit_watch_path (struct audit_watch *watch); -extern int audit_watch_compare (struct audit_watch *watch,unsigned long ino, -dev_t dev); +extern int audit_watch_compare (struct audit_watch *watch,u64 ino,dev_t dev);extern struct audit_fsnotify_mark *audit_alloc_mark (struct audit_krule *krule,char *pathname,int len);
kernel/audit_fsnotify.c +1 -1
@@ -25,7 +25,7 @@*/ struct audit_fsnotify_mark {dev_t dev;/* associated superblock device */ -unsigned long ino;/* associated inode number */ +u64 ino;/* associated inode number */ char *path;/* insertion path */ struct fsnotify_mark mark;/* fsnotify mark on the inode */ struct audit_krule *rule;
kernel/audit_watch.c +5 -5
@@ -37,7 +37,7 @@ struct audit_watch {refcount_t count;/* reference count */ dev_t dev;/* associated superblock device */ char *path;/* insertion path */ -unsigned long ino;/* associated inode number */ +u64 ino;/* associated inode number */ struct audit_parent *parent;/* associated parent */ struct list_head wlist;/* entry in parent->watches list */ struct list_head rules;/* anchor for krule->rlist */
@@ -125,7 +125,7 @@ char *audit_watch_path(struct audit_watcreturn watch->path; } -int audit_watch_compare (struct audit_watch *watch,unsigned long ino,dev_t dev) +int audit_watch_compare (struct audit_watch *watch,u64 ino,dev_t dev) {return (watch->ino !=AUDIT_INO_UNSET ) && (watch->ino == ino) &&
@@ -285,7 +285,7 @@ static void audit_update_watch(struct aulist_del (&oentry->rule.list);audit_panic ("error updating watch, removing" ); }else { -int h =audit_hash_ino ((u32 )ino); +int h =audit_hash_ino (ino);/* * nentry->rule.watch == oentry->rule.watch so
@@ -439,7 +439,7 @@ int audit_add_watch(struct audit_krule *audit_add_to_parent (krule, parent); - h =audit_hash_ino ((u32 )watch->ino); + h =audit_hash_ino (watch->ino); *list = &audit_inode_hash[h]; error:path_put (&parent_path);
@@ -527,7 +527,7 @@ int audit_dupe_exe(struct audit_krule *nint audit_exe_compare (struct task_struct *tsk,struct audit_fsnotify_mark *mark) {struct file *exe_file; -unsigned long ino; +u64 ino;dev_t dev;/* only do exe filtering if we are recording @current events/records */
kernel/auditsc.c +2 -2
@@ -884,7 +884,7 @@ static int audit_filter_inode_name(strucstruct audit_names *n, struct audit_context *ctx) { - int h = audit_hash_ino((u32)n->ino); + int h = audit_hash_ino(n->ino);struct list_head *list = &audit_inode_hash[h];return __audit_filter_op (tsk, ctx, list, n, ctx->major);
@@ -1549,7 +1549,7 @@ static void audit_log_name(struct audit_audit_log_format (ab," name=(null)" );if (n->ino !=AUDIT_INO_UNSET ) - audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#ho ouid=%u ogid=%u rdev=%02x:%02x", + audit_log_format(ab, " inode=%llu dev=%02x:%02x mode=%#ho ouid=%u ogid=%u rdev=%02x:%02x", n->ino, MAJOR(n->dev), MINOR(n->dev),
Greg Kroah-Hartman
maintainerPATCH 472/602 audit: use unsigned int instead of unsigned
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Robaina <[email protected]>
[ Upstream commit 8b226771014beab1292081151a99530886ce54b4 ]
Address checkpatch.pl warning below, across the audit subsystem:
WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
Minor cleanup, no functional changes.
Stable-dep-of: 81905b5acbe7 ("audit: fix recursive locking deadlock in audit_dupe_exe()")
--- include/linux/audit.h | 4 ++-- include/linux/audit_arch.h | 12 ++++++------ kernel/audit.c | 2 +- kernel/audit.h | 2 +- kernel/audit_tree.c | 2 +- kernel/auditfilter.c | 8 ++++---- kernel/auditsc.c | 2 +- lib/compat_audit.c | 12 ++++++------ 8 files changed, 22 insertions(+), 22 deletions(-)
include/linux/audit.h +2 -2
@@ -123,8 +123,8 @@ enum audit_nfcfgop { AUDIT_NFT_OP_INVALID, }; -extern int __init audit_register_class (int class,unsigned *list); -extern int audit_classify_syscall (int abi,unsigned syscall); +extern int __init audit_register_class (int class,unsigned int *list); +extern int audit_classify_syscall (int abi,unsigned int syscall);extern int audit_classify_arch (int arch);/* audit_names->type values */
include/linux/audit_arch.h +6 -6
@@ -21,13 +21,13 @@ enum auditsc_class_t {AUDITSC_NVALS /* count */ }; -extern int audit_classify_compat_syscall (int abi,unsigned syscall); +extern int audit_classify_compat_syscall (int abi,unsigned int syscall);/* only for compat system calls */ -extern unsigned compat_write_class[]; -extern unsigned compat_read_class[]; -extern unsigned compat_dir_class[]; -extern unsigned compat_chattr_class[]; -extern unsigned compat_signal_class[]; +extern unsigned int compat_write_class[]; +extern unsigned int compat_read_class[]; +extern unsigned int compat_dir_class[]; +extern unsigned int compat_chattr_class[]; +extern unsigned int compat_signal_class[];#endif
kernel/audit.c +1 -1
@@ -1985,7 +1985,7 @@ static void audit_log_vformat(struct aud* here and AUDIT_BUFSIZ is at least 1024, then we can * log everything that printk could have logged. */ avail =audit_expand (ab, -max_t (unsigned,AUDIT_BUFSIZ ,1 +len-avail)); + max_t(unsigned int, AUDIT_BUFSIZ, 1+len-avail));if (!avail) goto out_va_end; len =vsnprintf (skb_tail_pointer (skb), avail, fmt, args2);
kernel/audit.h +1 -1
@@ -227,7 +227,7 @@ static inline int audit_hash_ino(u64 ino/* Indicates that audit should log the full pathname. */ #define AUDIT_NAME_FULL -1 -extern int audit_match_class (int class,unsigned syscall); +extern int audit_match_class (int class,unsigned int syscall);extern int audit_comparator (const u32 left,const u32 op,const u32 right);extern int audit_uid_comparator (kuid_t left,u32 op,kuid_t right);extern int audit_gid_comparator (kgid_t left,u32 op,kgid_t right);
kernel/audit_tree.c +1 -1
@@ -33,7 +33,7 @@ struct audit_chunk {struct audit_node {struct list_head list;struct audit_tree *owner; -unsigned index;/* index; upper bit indicates 'will prune' */ +unsigned int index;/* index; upper bit indicates 'will prune' */ } owners[] __counted_by(count); };
kernel/auditfilter.c +4 -4
@@ -165,13 +165,13 @@ static inline int audit_to_inode(structstatic __u32 *classes[AUDIT_SYSCALL_CLASSES ]; -int __init audit_register_class (int class,unsigned *list) +int __init audit_register_class (int class,unsigned int *list) {__u32 *p =kcalloc (AUDIT_BITMASK_SIZE ,sizeof (__u32),GFP_KERNEL );if (!p)return -ENOMEM ;while (*list != ~0U ) { -unsigned n = *list++; +unsigned int n = *list++;if (n >=AUDIT_BITMASK_SIZE *32 -AUDIT_SYSCALL_CLASSES ) {kfree (p);return -EINVAL ;
@@ -186,7 +186,7 @@ int __init audit_register_class(int clasreturn 0 ; } -int audit_match_class (int class,unsigned syscall) +int audit_match_class (int class,unsigned int syscall) {if (unlikely (syscall >=AUDIT_BITMASK_SIZE *32 ))return 0 ;
@@ -237,7 +237,7 @@ static int audit_match_signal(struct aud/* Common user-space to kernel rule translation. */ static inline struct audit_entry *audit_to_entry_common (struct audit_rule_data *rule) { -unsigned listnr; +unsigned int listnr;struct audit_entry *entry;int i, err;
kernel/auditsc.c +1 -1
@@ -150,7 +150,7 @@ static const struct audit_nfcfgop_tab austatic int audit_match_perm (struct audit_context *ctx,int mask) { -unsigned n; +unsigned int n;if (unlikely (!ctx))return 0 ;
lib/compat_audit.c +6 -6
@@ -4,32 +4,32 @@#include <linux/audit_arch.h> #include <asm/unistd32.h> -unsigned compat_dir_class[] = { +unsigned int compat_dir_class[] = { #include <asm-generic/audit_dir_write.h> ~0U }; -unsigned compat_read_class[] = { +unsigned int compat_read_class[] = { #include <asm-generic/audit_read.h> ~0U }; -unsigned compat_write_class[] = { +unsigned int compat_write_class[] = { #include <asm-generic/audit_write.h> ~0U }; -unsigned compat_chattr_class[] = { +unsigned int compat_chattr_class[] = { #include <asm-generic/audit_change_attr.h> ~0U }; -unsigned compat_signal_class[] = { +unsigned int compat_signal_class[] = { #include <asm-generic/audit_signal.h> ~0U }; -int audit_classify_compat_syscall (int abi,unsigned syscall) +int audit_classify_compat_syscall (int abi,unsigned int syscall) {switch (syscall) {#ifdef __NR_open
Greg Kroah-Hartman
maintainerPATCH 473/602 audit: fix recursive locking deadlock in audit_dupe_exe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Robaina <[email protected]>
[ Upstream commit 81905b5acbe77284734438df3fbec1158e6429a3 ]
A deadlock occurs in the audit subsystem when duplicating executable-related rules.
When a file is moved (e.g., via do_renameat2()), the VFS layer locks the parent directory (I_MUTEX_PARENT), which synchronously triggers an fsnotify_move event. If an existing executable audit rule matches the file being moved, the audit subsystem catches this event and calls audit_dupe_exe() to duplicate the watch and update the rule. Then, audit_alloc_mark() would call kern_path_parent() to resolve the path, leading to a blind attempt to acquire the exact same I_MUTEX_PARENT lock already held by the task, resulting in the following recursive locking deadlock:
============================================
WARNING: possible recursive locking detected 6.12.0-55.27.1.el10_0.x86_64+debug #1 Not tainted
--------------------------------------------
mv/5099 is trying to acquire lock:
ffff888132845358 (&inode->i_sb->s_type->i_mutex_dir_key/1){+.+.}-{3:3},
at: __kern_path_locked+0x10a/0x2f0
but task is already holding lock:
ffff888132846b58 (&inode->i_sb->s_type->i_mutex_dir_key/1){+.+.}-{3:3},
at: lock_two_directories+0x13f/0x2b0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(&inode->i_sb->s_type->i_mutex_dir_key/1);
lock(&inode->i_sb->s_type->i_mutex_dir_key/1);
*** DEADLOCK ***
May be due to missing lock nesting notation
6 locks held by mv/5099:
#0: ffff888112a9c440 (sb_writers#13)
at: do_renameat2+0x34c/0xbc0
#1: ffff888112a9c790 (&type->s_vfs_rename_key#3)
at: do_renameat2+0x415/0xbc0
#2: ffff888132846b58 (&inode->i_sb->s_type->i_mutex_dir_key/1)
at: lock_two_directories+0x13f/0x2b0
#3: ffff888132845358 (&inode->i_sb->s_type->i_mutex_dir_key/5)
at: lock_two_directories+0x175/0x2b0
#4: ffffffffb3a1fb10 (&fsnotify_mark_srcu)
at: fsnotify+0x454/0x28a0
#5: ffffffffaf886230 (audit_filter_mutex)
at: audit_update_watch+0x36/0x11e0
stack backtrace: Call Trace: <TASK> dump_stack_lvl+0x6f/0xb0 print_deadlock_bug.cold+0xbd/0xca validate_chain+0x83a/0xf00 __lock_acquire+0xcac/0x1d20 lock_acquire.part.0+0x11b/0x360 down_write_nested+0x9f/0x230 __kern_path_locked+0x10a/0x2f0 kern_path_locked+0x26/0x40 audit_alloc_mark+0xfb/0x4f0 audit_dupe_exe+0x6c/0xe0 audit_dupe_rule+0x6c2/0xc00 audit_update_watch+0x4cc/0x11e0 audit_watch_handle_event+0x12c/0x1b0 send_to_group+0x5d0/0x8b0 fsnotify+0x615/0x28a0 fsnotify_move+0x1d8/0x630 vfs_rename+0xdcd/0x1df0 do_renameat2+0x9d4/0xbc0 __x64_sys_renameat+0x192/0x260 do_syscall_64+0x92/0x180 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f0491fe8c4e Code: 0f 1f 40 00 48 8b 15 c1 e1 16 00 f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 49 89 ca b8 08 01 00 00 0f 05 <48> 3d 00 f0 ff ff 77 0a c3 66 0f 1f 84 00 00 00 00 00 48 8b 15 89 RSP: 002b:00007ffc7210bf38 EFLAGS: 00000246 ORIG_RAX: 0000000000000108 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f0491fe8c4e RDX: 0000000000000003 RSI: 00007ffc7210e6c8 RDI: 00000000ffffff9c RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000001 R10: 00005575eb2dae2a R11: 0000000000000246 R12: 00005575eb2dae2a R13: 00007ffc7210e6c8 R14: 0000000000000003 R15: 00000000ffffff9c </TASK>
The aforementioned deadlock can be consistently reproduced by running the script below:
audit-dupe-exe-deadlock.sh
--------------------------
#!/bin/bash
auditctl -D
mkdir -p /tmp/foo
touch /tmp/file
auditctl -a always,exit -F exe=/tmp/file -F path=/tmp/file -S all -k dr mv /tmp/file /tmp/foo/file
rm -Rf /tmp/foo
This patch fixes the issue by introducing struct audit_watch_ctx to pass the fsnotify event context down to audit_alloc_mark(). By utilizing the already-resolved directory inode provided by the event, we bypass the kern_path_parent() path resolution entirely, safely avoiding the recursive lock. Furthermore, it explicitly allows duplicate fsnotify marks (allow_dups = 1) during the rename update, allowing the new rule's mark to safely coexist with the old rule's mark until the old rule is freed.
P.S.: This issue was identified and reproduced during a comprehensive code coverage analysis of the audit subsystem. The full report is available at the link below:
https://people.redhat.com/rrobaina/audit-code-coverage-analysis.pdf
P.P.S: With the permission of both Ricardo and Nathan, I've squashed a fixup patch from Nathan that addresses a compile time error when CONFIG_AUDITSYSCALL=n.
--- kernel/audit.h | 17 ++++++++++++----- kernel/audit_fsnotify.c | 32 +++++++++++++++++++++++--------- kernel/audit_watch.c | 25 +++++++++++++++++-------- kernel/auditfilter.c | 9 +++++---- 4 files changed, 57 insertions(+), 26 deletions(-)
kernel/audit.h +12 -5
@@ -250,8 +250,13 @@ extern int audit_del_rule(struct audit_eextern void audit_free_rule_rcu (struct rcu_head *head);extern struct list_head audit_filter_list[]; -extern struct audit_entry *audit_dupe_rule (struct audit_krule *old); +struct audit_watch_ctx { +struct inode *dir; +struct inode *child; +}; +extern struct audit_entry *audit_dupe_rule (struct audit_krule *old, +struct audit_watch_ctx *ctx);extern void audit_log_d_path_exe (struct audit_buffer *ab,struct mm_struct *mm);
@@ -274,13 +279,15 @@ extern char *audit_watch_path(struct audextern int audit_watch_compare (struct audit_watch *watch,u64 ino,dev_t dev);extern struct audit_fsnotify_mark *audit_alloc_mark (struct audit_krule *krule, -char *pathname,int len); +char *pathname,int len, +struct audit_watch_ctx *ctx);extern char *audit_mark_path (struct audit_fsnotify_mark *mark);extern void audit_remove_mark (struct audit_fsnotify_mark *audit_mark);extern void audit_remove_mark_rule (struct audit_krule *krule);extern int audit_mark_compare (struct audit_fsnotify_mark *mark,u64 ino,dev_t dev); -extern int audit_dupe_exe (struct audit_krule *new,struct audit_krule *old); +extern int audit_dupe_exe (struct audit_krule *new,struct audit_krule *old, +struct audit_watch_ctx *ctx);extern int audit_exe_compare (struct task_struct *tsk,struct audit_fsnotify_mark *mark);
@@ -311,13 +318,13 @@ extern struct list_head *audit_killed_tr#define audit_watch_path (w) ""#define audit_watch_compare (w, i, d) 0 -#define audit_alloc_mark (k, p, l) (ERR_PTR(-EINVAL)) +#define audit_alloc_mark (k, p, l, c) (ERR_PTR(-EINVAL))#define audit_mark_path (m) ""#define audit_remove_mark (m) do { } while (0)#define audit_remove_mark_rule (k) do { } while (0)#define audit_mark_compare (m, i, d) 0#define audit_exe_compare (t, m) (-EINVAL) -#define audit_dupe_exe (n, o) (-EINVAL) +#define audit_dupe_exe (n, o, c) (-EINVAL)#define audit_remove_tree_rule (rule) BUG()#define audit_add_tree_rule (rule) -EINVAL
kernel/audit_fsnotify.c +23 -9
@@ -71,19 +71,30 @@ static void audit_update_mark(struct aud audit_mark->ino = inode ? inode->i_ino :AUDIT_INO_UNSET ; } -struct audit_fsnotify_mark *audit_alloc_mark (struct audit_krule *krule,char *pathname,int len) +struct audit_fsnotify_mark *audit_alloc_mark (struct audit_krule *krule,char *pathname, +int len,struct audit_watch_ctx *ctx) {struct audit_fsnotify_mark *audit_mark;struct path path;struct dentry *dentry; -int ret; +struct inode *dir, *child; +int ret, allow_dups;if (pathname[0 ] !='/' || pathname[len-1 ] =='/' )return ERR_PTR (-EINVAL ); - dentry =kern_path_parent (pathname, &path); -if (IS_ERR (dentry)) -return ERR_CAST (dentry);/* returning an error */ +if (!ctx) { + dentry =kern_path_parent (pathname, &path); +if (IS_ERR (dentry)) +return ERR_CAST (dentry);/* returning an error */ + dir =d_inode (path.dentry); + child =d_inode (dentry); + allow_dups =0 ; + }else { + dir = ctx->dir; + child = ctx->child; + allow_dups =1 ; + } audit_mark =kzalloc (sizeof (*audit_mark),GFP_KERNEL );if (unlikely (!audit_mark)) {
@@ -94,18 +105,21 @@ struct audit_fsnotify_mark *audit_alloc_fsnotify_init_mark (&audit_mark->mark, audit_fsnotify_group); audit_mark->mark.mask =AUDIT_FS_EVENTS ; audit_mark->path = pathname; -audit_update_mark (audit_mark, dentry->d_inode); audit_mark->rule = krule; - ret =fsnotify_add_inode_mark (&audit_mark->mark, path.dentry->d_inode,0 ); +audit_update_mark (audit_mark, child); + ret =fsnotify_add_inode_mark (&audit_mark->mark, dir, allow_dups); +if (ret <0 ) { audit_mark->path =NULL ;fsnotify_put_mark (&audit_mark->mark); audit_mark =ERR_PTR (ret); } out: -dput (dentry); -path_put (&path); +if (!ctx) { +dput (dentry); +path_put (&path); + }return audit_mark; }
kernel/audit_watch.c +17 -8
@@ -244,7 +244,8 @@ static void audit_watch_log_rule_change(/* Update inode info in audit rules based on filesystem event. */ static void audit_update_watch (struct audit_parent *parent,const struct qstr *dname,dev_t dev, -u64 ino,unsigned int invalidating) +u64 ino,unsigned int invalidating, +struct audit_watch_ctx *ctx) {struct audit_watch *owatch, *nwatch, *nextw;struct audit_krule *r, *nextr;
@@ -280,7 +281,7 @@ static void audit_update_watch(struct aulist_del (&oentry->rule.rlist);list_del_rcu (&oentry->list); - nentry =audit_dupe_rule (&oentry->rule); + nentry =audit_dupe_rule (&oentry->rule, ctx);if (IS_ERR (nentry)) {list_del (&oentry->rule.list);audit_panic ("error updating watch, removing" );
@@ -479,10 +480,17 @@ static int audit_watch_handle_event(struif (WARN_ON_ONCE (inode_mark->group != audit_watch_group))return 0 ; -if (mask & (FS_CREATE |FS_MOVED_TO ) && inode) -audit_update_watch (parent, dname, inode->i_sb->s_dev, inode->i_ino,0 ); -else if (mask & (FS_DELETE |FS_MOVED_FROM )) -audit_update_watch (parent, dname,AUDIT_DEV_UNSET ,AUDIT_INO_UNSET ,1 ); +if (mask & (FS_CREATE |FS_MOVED_TO ) && inode) { +struct audit_watch_ctx ctx = { .dir = dir, .child = inode }; + +audit_update_watch (parent, dname, inode->i_sb->s_dev, inode->i_ino,0 , + &ctx); + }else if (mask & (FS_DELETE |FS_MOVED_FROM )) { +struct audit_watch_ctx ctx = { .dir = dir, .child =NULL }; + +audit_update_watch (parent, dname,AUDIT_DEV_UNSET ,AUDIT_INO_UNSET ,1 , + &ctx); + }else if (mask & (FS_DELETE_SELF |FS_UNMOUNT |FS_MOVE_SELF ))audit_remove_parent_watches (parent);
@@ -505,7 +513,8 @@ static int __init audit_watch_init(void) }device_initcall (audit_watch_init); -int audit_dupe_exe (struct audit_krule *new,struct audit_krule *old) +int audit_dupe_exe (struct audit_krule *new,struct audit_krule *old, +struct audit_watch_ctx *ctx) {struct audit_fsnotify_mark *audit_mark;char *pathname;
@@ -514,7 +523,7 @@ int audit_dupe_exe(struct audit_krule *nif (!pathname)return -ENOMEM ; - audit_mark =audit_alloc_mark (new, pathname,strlen (pathname)); + audit_mark =audit_alloc_mark (new, pathname,strlen (pathname), ctx);if (IS_ERR (audit_mark)) {kfree (pathname);return PTR_ERR (audit_mark);
kernel/auditfilter.c +5 -4
@@ -590,7 +590,7 @@ static struct audit_entry *audit_data_to err =PTR_ERR (str); goto exit_free; } - audit_mark =audit_alloc_mark (&entry->rule, str, f_val); + audit_mark =audit_alloc_mark (&entry->rule, str, f_val,NULL );if (IS_ERR (audit_mark)) {kfree (str); err =PTR_ERR (audit_mark);
@@ -818,7 +818,8 @@ static inline int audit_dupe_lsm_field(s* rule with the new rule in the filterlist, then free the old rule. * The rlist element is undefined; list manipulations are handled apart from * the initial copy. */ -struct audit_entry *audit_dupe_rule (struct audit_krule *old) +struct audit_entry *audit_dupe_rule (struct audit_krule *old, +struct audit_watch_ctx *ctx) {u32 fcount = old->field_count;struct audit_entry *entry;
@@ -877,7 +878,7 @@ struct audit_entry *audit_dupe_rule(stru new->filterkey = fk;break ;case AUDIT_EXE : - err =audit_dupe_exe (new, old); + err =audit_dupe_exe (new, old, ctx);break ; }if (err) {
@@ -1408,7 +1409,7 @@ static int update_lsm_rule(struct audit_if (!security_audit_rule_known (r))return 0 ; - nentry =audit_dupe_rule (r); + nentry =audit_dupe_rule (r,NULL );if (entry->rule.exe)audit_remove_mark (entry->rule.exe);if (IS_ERR (nentry)) {
Greg Kroah-Hartman
maintainerPATCH 474/602 i2c: i801: fix hardware state machine corruption in error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingyu Wang <[email protected]>
[ Upstream commit 10dd1a736d557e310a77117832874729a0175d57 ]
A severe livelock and subsequent Hung Task panic were observed in the i2c-i801 driver during concurrent Fuzzing. The crash is caused by an unconditional hardware register cleanup in the error handling path of i801_access().
When i801_check_pre() fails (e.g., returning -EBUSY because the SMBus controller is actively used by BIOS/ACPI), the kernel does not actually acquire the hardware ownership. However, the code jumps to the 'out' label and executes:
iowrite8(SMBHSTSTS_INUSE_STS | STATUS_FLAGS, SMBHSTSTS(priv));
This forcefully clears the INUSE_STS lock and resets the hardware status flags without owning the controller. Doing so interrupts ongoing BIOS/ACPI transactions and totally corrupts the SMBus hardware state machine.
Consequently, all subsequent i801_access() calls fail at the pre-check stage, triggering an endless stream of "SMBus is busy, can't use it!" error logs. Over a slow serial console, this printk flood monopolizes the CPU (Console Livelock), starving other processes trying to acquire the mmap_lock down_read semaphore, ultimately triggering the hung task watchdog.
Fix this by moving the 'out' label below the hardware register cleanup. If i801_check_pre() fails, we safely bypass the iowrite8() and only release the software locks (pm_runtime and mutex), strictly adhering to the rule of not releasing resources that were never acquired.
--- drivers/i2c/busses/i2c-i801.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +1 -1
@@ -930,13 +930,13 @@ static s32 i801_access(struct i2c_adapte*/ if (hwpec)outb_p (inb_p (SMBAUXCTL (priv)) & ~SMBAUXCTL_CRC ,SMBAUXCTL (priv)); -out:/* * Unlock the SMBus device for use by BIOS/ACPI, * and clear status flags if not done already. */ outb_p (SMBHSTSTS_INUSE_STS |STATUS_FLAGS ,SMBHSTSTS (priv)); +out:pm_runtime_mark_last_busy (&priv->pci_dev->dev);pm_runtime_put_autosuspend (&priv->pci_dev->dev);mutex_unlock (&priv->acpi_lock);
Greg Kroah-Hartman
maintainerPATCH 475/602 ALSA: hda: conexant: Remove mic bias threshold override
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Heng <[email protected]>
[ Upstream commit f52524da7084c1a54683ae9fbc73e93fff19dd64 ]
Remove the mic bias current comparator threshold override (NID 0x1c, verb 0x320, value 0x010) from Conexant codec driver.
This override was originally intended to support volume up/down controls on headsets with inline remote controls, but it causes microphone detection failures on some headsets with impedance less than 1k ohm.
After consulting with the vendor's engineers, it was confirmed that this setting is board-specific and should be handled by BIOS/firmware rather than the generic codec driver, especially since inline remote support is not currently implemented.
--- sound/pci/hda/patch_conexant.c | 3 --- 1 file changed, 3 deletions(-)
sound/pci/hda/patch_conexant.c +0 -3
@@ -168,9 +168,6 @@ static void cx_fixup_headset_recog(struc {unsigned int mic_present; -/* fix some headset type recognize fail issue, such as EDIFIER headset */ -/* set micbias output current comparator threshold from 66% to 55%. */ -snd_hda_codec_write (codec,0x1c ,0 ,0x320 ,0x010 );/* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias register * value adjustment trim from 2.2K ohms to 2.0K ohms. */
Greg Kroah-Hartman
maintainerPATCH 476/602 ALSA: hda: Fix cached processing coefficient verbs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit f67be28fdf8b5d31ac1cc1152bb17250f9f8f513 ]
Intel HD Audio defines Coefficient Index and Processing Coefficient as separate audio widget controls in the Audio Widget Verb Definitions:
Coefficient Index selects the coefficient slot, while Processing Coefficient accesses the value at the selected slot.
hda_reg_read_coef() selects the slot with AC_VERB_SET_COEF_INDEX, but then uses AC_VERB_GET_COEF_INDEX for the value read. That reads back the selected index instead of the coefficient value. hda_reg_write_coef() has the same issue and builds the value write from AC_VERB_GET_COEF_INDEX instead of AC_VERB_SET_PROC_COEF.
This only affects the regmap coefficient cache path used by codecs that set codec->cache_coef. Direct coefficient helpers already use the normal SET_COEF_INDEX followed by GET_PROC_COEF or SET_PROC_COEF sequence, which is likely why this has not been noticed widely.
Use AC_VERB_GET_PROC_COEF for cached coefficient reads and AC_VERB_SET_PROC_COEF for cached coefficient writes.
--- sound/hda/hdac_regmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/hda/hdac_regmap.c +2 -2
@@ -214,7 +214,7 @@ static int hda_reg_read_coef(struct hdac err =snd_hdac_exec_verb (codec, verb,0 ,NULL );if (err <0 )return err; - verb = (reg & ~0xfffff ) | (AC_VERB_GET_COEF_INDEX <<8 ); + verb = (reg & ~0xfffff ) | (AC_VERB_GET_PROC_COEF <<8 );return snd_hdac_exec_verb (codec, verb,0 , val); }
@@ -232,7 +232,7 @@ static int hda_reg_write_coef(struct hda err =snd_hdac_exec_verb (codec, verb,0 ,NULL );if (err <0 )return err; - verb = (reg & ~0xfffff ) | (AC_VERB_GET_COEF_INDEX <<8 ) | + verb = (reg & ~0xfffff ) | (AC_VERB_SET_PROC_COEF <<8 ) | (val &0xffff );return snd_hdac_exec_verb (codec, verb,0 ,NULL ); }
Greg Kroah-Hartman
maintainerPATCH 477/602 rxrpc: Pull out certain app callback funcs into an ops table
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 23738cc8048322cf324f330cd697380fb3455da5 ]
A number of functions separately furnish an AF_RXRPC socket with callback function pointers into a kernel app (such as the AFS filesystem) that is using it. Replace most of these with an ops table for the entire socket. This makes it easier to add more callback functions.
Note that the call incoming data processing callback is retaind as that gets set to different things, depending on the type of op.
Stable-dep-of: dc175389b18c ("rxrpc: serialize kernel accept preallocation with socket teardown")
--- fs/afs/rxrpc.c | 11 ++++++++--- include/net/af_rxrpc.h | 25 +++++++++++++++---------- net/rxrpc/af_rxrpc.c | 20 ++++++++------------ net/rxrpc/ar-internal.h | 3 +-- net/rxrpc/call_accept.c | 34 ++++++++++++++++------------------ net/rxrpc/rxperf.c | 10 +++++++--- 6 files changed, 55 insertions(+), 48 deletions(-)
fs/afs/rxrpc.c +8 -3
@@ -24,8 +24,15 @@ static void afs_wake_up_async_call(strucstatic void afs_process_async_call (struct work_struct *);static void afs_rx_new_call (struct sock *,struct rxrpc_call *,unsigned long );static void afs_rx_discard_new_call (struct rxrpc_call *,unsigned long ); +static void afs_rx_attach (struct rxrpc_call *rxcall,unsigned long user_call_ID);static int afs_deliver_cm_op_id (struct afs_call *); +static const struct rxrpc_kernel_ops afs_rxrpc_callback_ops = { + .notify_new_call = afs_rx_new_call, + .discard_new_call = afs_rx_discard_new_call, + .user_attach_call = afs_rx_attach, +}; +/* asynchronous incoming call initial processing */ static const struct afs_call_type afs_RXCMxxxx = { .name ="CB.xxxx" ,
@@ -84,8 +91,7 @@ int afs_open_socket(struct afs_net *net)* it sends back to us. */ -rxrpc_kernel_new_call_notification (socket, afs_rx_new_call, - afs_rx_discard_new_call); +rxrpc_kernel_set_notifications (socket, &afs_rxrpc_callback_ops); ret =kernel_listen (socket,INT_MAX );if (ret <0 )
@@ -758,7 +764,6 @@ void afs_charge_preallocation(struct worif (rxrpc_kernel_charge_accept (net->socket, afs_wake_up_async_call, - afs_rx_attach, (unsigned long )call,GFP_KERNEL , call->debug_id) <0 )
include/net/af_rxrpc.h +15 -10
@@ -29,18 +29,23 @@ enum rxrpc_interruptibility {*/ extern atomic_t rxrpc_debug_id; +/* +* Operations table for rxrpc to call out to a kernel application (e.g. kAFS). +*/ +struct rxrpc_kernel_ops { +void (*notify_new_call)(struct sock *sk,struct rxrpc_call *call, +unsigned long user_call_ID); +void (*discard_new_call)(struct rxrpc_call *call,unsigned long user_call_ID); +void (*user_attach_call)(struct rxrpc_call *call,unsigned long user_call_ID); +}; +typedef void (*rxrpc_notify_rx_t )(struct sock *,struct rxrpc_call *,unsigned long );typedef void (*rxrpc_notify_end_tx_t )(struct sock *,struct rxrpc_call *,unsigned long ); -typedef void (*rxrpc_notify_new_call_t )(struct sock *,struct rxrpc_call *, -unsigned long ); -typedef void (*rxrpc_discard_new_call_t )(struct rxrpc_call *,unsigned long ); -typedef void (*rxrpc_user_attach_call_t )(struct rxrpc_call *,unsigned long ); -void rxrpc_kernel_new_call_notification (struct socket *, -rxrpc_notify_new_call_t , -rxrpc_discard_new_call_t ); +void rxrpc_kernel_set_notifications (struct socket *sock, +const struct rxrpc_kernel_ops *app_ops); struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, struct rxrpc_peer *peer, struct key *key,
@@ -70,9 +75,9 @@ struct rxrpc_peer *rxrpc_kernel_get_callconst struct sockaddr_rxrpc *rxrpc_kernel_remote_srx (const struct rxrpc_peer *peer);const struct sockaddr *rxrpc_kernel_remote_addr (const struct rxrpc_peer *peer);unsigned int rxrpc_kernel_get_srtt (const struct rxrpc_peer *); -int rxrpc_kernel_charge_accept (struct socket *,rxrpc_notify_rx_t , -rxrpc_user_attach_call_t ,unsigned long ,gfp_t , -unsigned int ); +int rxrpc_kernel_charge_accept (struct socket *sock,rxrpc_notify_rx_t notify_rx, +unsigned long user_call_ID,gfp_t gfp, +unsigned int debug_id);void rxrpc_kernel_set_tx_length (struct socket *,struct rxrpc_call *,s64 );bool rxrpc_kernel_check_life (const struct socket *,const struct rxrpc_call *);u32 rxrpc_kernel_get_epoch (struct socket *,struct rxrpc_call *);
net/rxrpc/af_rxrpc.c +8 -12
@@ -464,24 +464,20 @@ u32 rxrpc_kernel_get_epoch(struct socketEXPORT_SYMBOL (rxrpc_kernel_get_epoch);/** -* rxrpc_kernel_new_call_notification - Get notifications of new calls -* @sock: The socket to intercept received messages on -* @notify_new_call: Function to be called when new calls appear -* @discard_new_call: Function to discard preallocated calls +* rxrpc_kernel_set_notifications - Set table of callback operations +* @sock: The socket to install table upon +* @app_ops: Callback operation table to set * -* Allow a kernel service to be given notifications about new calls. +* Allow a kernel service to set a table of event notifications on a socket. */ -void rxrpc_kernel_new_call_notification ( -struct socket *sock, -rxrpc_notify_new_call_t notify_new_call, -rxrpc_discard_new_call_t discard_new_call) +void rxrpc_kernel_set_notifications (struct socket *sock, +const struct rxrpc_kernel_ops *app_ops) {struct rxrpc_sock *rx =rxrpc_sk (sock->sk); - rx->notify_new_call = notify_new_call; - rx->discard_new_call = discard_new_call; + rx->app_ops = app_ops; } -EXPORT_SYMBOL (rxrpc_kernel_new_call_notification); +EXPORT_SYMBOL (rxrpc_kernel_set_notifications);/** * rxrpc_kernel_set_max_life - Set maximum lifespan on a call
net/rxrpc/ar-internal.h +1 -2
@@ -142,8 +142,7 @@ struct rxrpc_backlog {struct rxrpc_sock {/* WARNING: sk has to be the first member */ struct sock sk; -rxrpc_notify_new_call_t notify_new_call;/* Func to notify of new call */ -rxrpc_discard_new_call_t discard_new_call;/* Func to discard a new call */ +const struct rxrpc_kernel_ops *app_ops;/* Table of kernel app notification funcs */ struct rxrpc_local *local;/* local endpoint */ struct rxrpc_backlog *backlog;/* Preallocation for services */ spinlock_t incoming_lock;/* Incoming call vs service shutdown lock */
net/rxrpc/call_accept.c +16 -18
@@ -34,7 +34,6 @@ static void rxrpc_dummy_notify(struct sostatic int rxrpc_service_prealloc_one (struct rxrpc_sock *rx,struct rxrpc_backlog *b,rxrpc_notify_rx_t notify_rx, -rxrpc_user_attach_call_t user_attach_call,unsigned long user_call_ID,gfp_t gfp,unsigned int debug_id) {
@@ -123,9 +122,10 @@ static int rxrpc_service_prealloc_one(st call->user_call_ID = user_call_ID; call->notify_rx = notify_rx; -if (user_attach_call) { +if (rx->app_ops && + rx->app_ops->user_attach_call) {rxrpc_get_call (call, rxrpc_call_get_kernel_service); -user_attach_call (call, user_call_ID); + rx->app_ops->user_attach_call (call, user_call_ID); }rxrpc_get_call (call, rxrpc_call_get_userid);
@@ -221,9 +221,10 @@ void rxrpc_discard_prealloc(struct rxrpcstruct rxrpc_call *call = b->call_backlog[tail];rxrpc_see_call (call, rxrpc_call_see_discard);rcu_assign_pointer (call->socket, rx); -if (rx->discard_new_call) { +if (rx->app_ops && + rx->app_ops->discard_new_call) {_debug ("discard %lx" , call->user_call_ID); - rx->discard_new_call (call, call->user_call_ID); + rx->app_ops->discard_new_call (call, call->user_call_ID);if (call->notify_rx) call->notify_rx = rxrpc_dummy_notify;rxrpc_put_call (call, rxrpc_call_put_kernel);
@@ -392,8 +393,9 @@ bool rxrpc_new_incoming_call(struct rxrprxrpc_incoming_call (rx, call, skb); conn = call->conn; -if (rx->notify_new_call) - rx->notify_new_call (&rx->sk, call, call->user_call_ID); +if (rx->app_ops && + rx->app_ops->notify_new_call) + rx->app_ops->notify_new_call (&rx->sk, call, call->user_call_ID);spin_lock (&conn->state_lock);if (conn->state ==RXRPC_CONN_SERVICE_UNSECURED ) {
@@ -445,8 +447,7 @@ int rxrpc_user_charge_accept(struct rxrpif (rx->sk.sk_state ==RXRPC_CLOSE )return -ESHUTDOWN ; -return rxrpc_service_prealloc_one (rx, b,NULL ,NULL , user_call_ID, -GFP_KERNEL , +return rxrpc_service_prealloc_one (rx, b,NULL , user_call_ID,GFP_KERNEL ,atomic_inc_return (&rxrpc_debug_id)); }
@@ -454,20 +455,18 @@ int rxrpc_user_charge_accept(struct rxrp* rxrpc_kernel_charge_accept - Charge up socket with preallocated calls * @sock: The socket on which to preallocate * @notify_rx: Event notification function for the call -* @user_attach_call: Func to attach call to user_call_ID * @user_call_ID: The tag to attach to the preallocated call * @gfp: The allocation conditions. * @debug_id: The tracing debug ID. * -* Charge up the socket with preallocated calls, each with a user ID. A -* function should be provided to effect the attachment from the user's side. -* The user is given a ref to hold on the call. +* Charge up the socket with preallocated calls, each with a user ID. The +* ->user_attach_call() callback function should be provided to effect the +* attachment from the user's side. The user is given a ref to hold on the +* call. * * Note that the call may be come connected before this function returns. */ -int rxrpc_kernel_charge_accept (struct socket *sock, -rxrpc_notify_rx_t notify_rx, -rxrpc_user_attach_call_t user_attach_call, +int rxrpc_kernel_charge_accept (struct socket *sock,rxrpc_notify_rx_t notify_rx,unsigned long user_call_ID,gfp_t gfp,unsigned int debug_id) {
@@ -477,8 +476,7 @@ int rxrpc_kernel_charge_accept(struct soif (sock->sk->sk_state ==RXRPC_CLOSE )return -ESHUTDOWN ; -return rxrpc_service_prealloc_one (rx, b, notify_rx, - user_attach_call, user_call_ID, +return rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, gfp, debug_id); }EXPORT_SYMBOL (rxrpc_kernel_charge_accept);
net/rxrpc/rxperf.c +7 -3
@@ -136,6 +136,12 @@ static void rxperf_notify_end_reply_tx(s RXPERF_CALL_SV_AWAIT_ACK); } +static const struct rxrpc_kernel_ops rxperf_rxrpc_callback_ops = { + .notify_new_call = rxperf_rx_new_call, + .discard_new_call = rxperf_rx_discard_new_call, + .user_attach_call = rxperf_rx_attach, +}; +/* * Charge the incoming call preallocation. */
@@ -161,7 +167,6 @@ static void rxperf_charge_preallocation(if (rxrpc_kernel_charge_accept (rxperf_socket, rxperf_notify_rx, - rxperf_rx_attach, (unsigned long )call,GFP_KERNEL , call->debug_id) <0 )
@@ -209,8 +214,7 @@ static int rxperf_open_socket(void)if (ret <0 ) goto error_2; -rxrpc_kernel_new_call_notification (socket, rxperf_rx_new_call, - rxperf_rx_discard_new_call); +rxrpc_kernel_set_notifications (socket, &rxperf_rxrpc_callback_ops); ret =kernel_listen (socket,INT_MAX );if (ret <0 )
Greg Kroah-Hartman
maintainerPATCH 478/602 rxrpc: serialize kernel accept preallocation with socket teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Daming <[email protected]>
[ Upstream commit dc175389b18c29a5303ee83169ec653adfae3e17 ]
rxrpc_kernel_charge_accept() reads rx->backlog without any socket/backlog synchronization and passes that raw pointer into rxrpc_service_prealloc_one(). A concurrent rxrpc_discard_prealloc() sets rx->backlog = NULL and frees the backlog rings, so a kernel preallocation worker can keep using a freed struct rxrpc_backlog while updating *_backlog_head/tail and array slots.
Serialize the state check and backlog lookup with the socket lock, and reject kernel preallocation once teardown has disabled listening or discarded the service backlog.
--- net/rxrpc/call_accept.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
net/rxrpc/call_accept.c +19 -6
@@ -470,13 +470,26 @@ int rxrpc_kernel_charge_accept(struct so unsigned long user_call_ID, gfp_t gfp, unsigned int debug_id) { - struct rxrpc_sock *rx = rxrpc_sk(sock->sk); -struct rxrpc_backlog *b = rx->backlog; + struct rxrpc_backlog *b; +struct rxrpc_sock *rx; +struct sock *sk; +int ret; -if (sock->sk->sk_state ==RXRPC_CLOSE ) -return -ESHUTDOWN ; + sk = sock->sk; + rx =rxrpc_sk (sk); -return rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, - gfp, debug_id); +lock_sock (sk); +if (sk->sk_state !=RXRPC_SERVER_LISTENING || !rx->backlog) { + ret = -ESHUTDOWN ; + goto out; + } + + b = rx->backlog; + ret =rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, + gfp, debug_id); + +out: +release_sock (sk); +return ret; }EXPORT_SYMBOL (rxrpc_kernel_charge_accept);
Greg Kroah-Hartman
maintainerPATCH 479/602 xfs: factor out xfs_attr3_leaf_init
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Long Li <[email protected]>
[ Upstream commit e65bb55d7f8c2041c8fdb73cd29b0b4cad4ed847 ]
Factor out wrapper xfs_attr3_leaf_init function, which exported for external use.
Stable-dep-of: a1caeeadbf57 ("xfs: don't replace the wrong part of the cow fork")
--- fs/xfs/libxfs/xfs_attr_leaf.c | 22 ++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++ 2 files changed, 25 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +22 -0
@@ -1330,6 +1330,28 @@ xfs_attr3_leaf_create( }/* +* Reinitialize an existing attr fork block as an empty leaf, and attach +* the buffer to tp. +*/ +int +xfs_attr3_leaf_init ( +struct xfs_trans *tp, +struct xfs_inode *dp, +xfs_dablk_t blkno) +{ +struct xfs_buf *bp =NULL ; +struct xfs_da_args args = { + .trans = tp, + .dp = dp, + .owner = dp->i_ino, + .geo = dp->i_mount->m_attr_geo, + }; + +ASSERT (tp !=NULL ); + +return xfs_attr3_leaf_create (&args, blkno, &bp); +} +/* * Split the leaf node, rebalance, then add the new entry. * * Returns 0 if the entry was added, 1 if a further split is needed or a
fs/xfs/libxfs/xfs_attr_leaf.h +3 -0
@@ -86,6 +86,9 @@ int xfs_attr3_leaf_list_int(struct xfs_b/* * Routines used for shrinking the Btree. */ + +int xfs_attr3_leaf_init (struct xfs_trans *tp,struct xfs_inode *dp, +xfs_dablk_t blkno);int xfs_attr3_leaf_toosmall (struct xfs_da_state *state,int *retval); void xfs_attr3_leaf_unbalance(struct xfs_da_state *state, struct xfs_da_state_blk *drop_blk,
Greg Kroah-Hartman
maintainerPATCH 480/602 xfs: dont replace the wrong part of the cow fork
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Darrick J. Wong" <[email protected]>
[ Upstream commit a1caeeadbf57ff86dfc3454398c46de86056a74e ]
LOLLM points out that xfs_iext_lookup_extent can return a @got where got->br_startoff < startoff. In this case, xrep_cow_replace_range replaces the entire mapping instead of just the part that had been marked bad in the bitmap, but advances the bitmap cursor in xrep_cow_replace by the amount replaced. As a result, we fail to replace the end of the bad range, and replace part of the good range.
Fix this by rewriting the replace method to handle replacing the middle of a cow fork mapping. This we do by returning both the current mapping as @got, and the subset of the mapping that we want to replace as @rep, using @rep to store the results of the new allocation, and comparing @rep to @got to figure out the exact transformations needed.
--- fs/xfs/scrub/cow_repair.c | 182 +++++++++++++++++++++++++++++----------------- fs/xfs/scrub/trace.h | 28 ++++--- 2 files changed, 135 insertions(+), 75 deletions(-)
fs/xfs/scrub/cow_repair.c +118 -64
@@ -73,12 +73,6 @@ struct xrep_cow {unsigned int next_bno; }; -/* CoW staging extent. */ -struct xrep_cow_extent { -xfs_fsblock_t fsbno; -xfs_extlen_t len; -}; -/* * Mark the part of the file range that corresponds to the given physical * space. Caller must ensure that the physical range is within xc->irec.
@@ -315,22 +309,21 @@ out_pag: STATIC intxrep_cow_alloc (struct xfs_scrub *sc, -xfs_extlen_t maxlen, -struct xrep_cow_extent *repl) +struct xfs_bmbt_irec *del) {struct xfs_alloc_arg args = { .tp = sc->tp, .mp = sc->mp, .oinfo =XFS_RMAP_OINFO_SKIP_UPDATE , .minlen =1 , - .maxlen = maxlen, + .maxlen = del->br_blockcount, .prod =1 , .resv =XFS_AG_RESV_NONE , .datatype =XFS_ALLOC_USERDATA , };int error; - error =xfs_trans_reserve_more (sc->tp, maxlen,0 ); + error =xfs_trans_reserve_more (sc->tp, del->br_blockcount,0 );if (error)return error;
@@ -343,8 +336,8 @@ xrep_cow_alloc(xfs_refcount_alloc_cow_extent (sc->tp, args.fsbno, args.len); - repl->fsbno = args.fsbno; - repl->len = args.len; + del->br_startblock = args.fsbno; + del->br_blockcount = args.len;return 0 ; }
@@ -358,19 +351,19 @@ static inline intxrep_cow_find_mapping ( struct xrep_cow *xc, struct xfs_iext_cursor *icur, - xfs_fileoff_t startoff, - struct xfs_bmbt_irec *got) + xfs_fileoff_t badoff, + xfs_extlen_t badlen, + struct xfs_bmbt_irec *got, + struct xfs_bmbt_irec *rep) { struct xfs_inode *ip = xc->sc->ip;struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_COW_FORK ); -if (!xfs_iext_lookup_extent (ip, ifp, startoff, icur, got)) - goto bad; - -if (got->br_startoff > startoff) +if (!xfs_iext_lookup_extent (ip, ifp, badoff, icur, got)) goto bad; +memcpy (rep, got,sizeof (*rep)); -if (got->br_blockcount ==0 ) +if (got->br_startoff > badoff) goto bad;if (isnullstartblock (got->br_startblock))
@@ -379,6 +372,24 @@ xrep_cow_find_mapping(if (xfs_bmap_is_written_extent (got)) goto bad; +if (got->br_startoff < badoff) { +const int64_t delta = badoff - got->br_startoff; + + rep->br_blockcount -= delta; + rep->br_startoff += delta; + rep->br_startblock += delta; + } + +if (got->br_startoff + got->br_blockcount > badoff + badlen) { +const int64_t delta = (got->br_startoff + got->br_blockcount) - + (badoff + badlen); + + rep->br_blockcount -= delta; + } + +if (got->br_blockcount ==0 ) + goto bad; +return 0 ; bad:ASSERT (0 );
@@ -389,46 +400,92 @@ bad:#define REPLACE_RIGHT_SIDE (1U << 1)/* -* Given a CoW fork mapping @got and a replacement mapping @repl, remap the -* beginning of @got with the space described by @rep. +* Given a CoW fork mapping @got and a replacement mapping @rep, map the space +* described by @rep into the cow fork, pushing aside @got as necessary. @icur +* must point to iext tree leaf containing @got. */ static inline void xrep_cow_replace_mapping ( -struct xfs_inode *ip, -struct xfs_iext_cursor *icur, -const struct xfs_bmbt_irec *got, -const struct xrep_cow_extent *repl) +struct xfs_inode *ip, +struct xfs_iext_cursor *icur, +struct xfs_bmbt_irec *got, +struct xfs_bmbt_irec *rep) { -struct xfs_bmbt_irec new = *got;/* struct copy */ +struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_COW_FORK ); +xfs_fileoff_t rep_endoff = + rep->br_startoff + rep->br_blockcount; +xfs_fileoff_t got_endoff = + got->br_startoff + got->br_blockcount; +uint32_t state =BMAP_COWFORK ; -ASSERT (repl->len >0 ); +ASSERT (rep->br_blockcount >0 );ASSERT (!isnullstartblock (got->br_startblock)); +ASSERT (got->br_startoff <= rep->br_startoff); +ASSERT (got_endoff >= rep_endoff); -trace_xrep_cow_replace_mapping (ip, got, repl->fsbno, repl->len); +trace_xrep_cow_replace_mapping (ip, got, rep); -if (got->br_blockcount == repl->len) { +if (got->br_startoff == rep->br_startoff) + state |=BMAP_LEFT_FILLING ; +if (got_endoff == rep_endoff) + state |=BMAP_RIGHT_FILLING ; + +switch (state & (BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING )) { +case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING :/* -* The new extent is a complete replacement for the existing -* extent. Update the COW fork record. +* Replacement matches the whole mapping, update the record. */ - new.br_startblock = repl->fsbno; -xfs_iext_update_extent (ip,BMAP_COWFORK , icur, &new); -return ; - } +xfs_iext_update_extent (ip, state, icur, rep); +break ; +case BMAP_LEFT_FILLING : +/* +* Replace the first part of the mapping: Update the cursor +* position with the new mapping, then add a record with the +* tail of the old mapping. +*/ + got->br_startoff = rep_endoff; + got->br_blockcount -= rep->br_blockcount; + got->br_startblock += rep->br_blockcount; + +xfs_iext_update_extent (ip, state, icur, rep); +xfs_iext_next (ifp, icur); +xfs_iext_insert (ip, icur, got, state); +break ; +case BMAP_RIGHT_FILLING : +/* +* Replacing the last part of the mapping. Shorten the current +* mapping then add a record with the new mapping. +*/ + got->br_blockcount -= rep->br_blockcount; -/* -* The new extent can replace the beginning of the COW fork record. -* Move the left side of @got upwards, then insert the new record. -*/ - new.br_startoff += repl->len; - new.br_startblock += repl->len; - new.br_blockcount -= repl->len; -xfs_iext_update_extent (ip,BMAP_COWFORK , icur, &new); - - new.br_startoff = got->br_startoff; - new.br_startblock = repl->fsbno; - new.br_blockcount = repl->len; -xfs_iext_insert (ip, icur, &new,BMAP_COWFORK ); +xfs_iext_update_extent (ip, state, icur, got); +xfs_iext_next (ifp, icur); +xfs_iext_insert (ip, icur, rep, state); +break ; +case 0 : +/* +* Replacing the middle of the extent. Shorten the current +* mapping, add a new record with the new mapping, and add a +* second new record with the tail of the old mapping. +*/ + got->br_blockcount = rep->br_startoff - got->br_startoff; + +struct xfs_bmbt_irec new = { + .br_startoff = rep_endoff, + .br_blockcount = got_endoff - rep_endoff, + .br_state = got->br_state, + .br_startblock = got->br_startblock + + rep->br_blockcount + + got->br_blockcount, + }; + +xfs_iext_update_extent (ip, state, icur, got); +xfs_iext_next (ifp, icur); +xfs_iext_insert (ip, icur, rep, state); +xfs_iext_next (ifp, icur); +xfs_iext_insert (ip, icur, &new, state); +break ; + } }/*
@@ -442,30 +499,27 @@ xrep_cow_replace_range( xfs_extlen_t *blockcount) {struct xfs_iext_cursor icur; -struct xrep_cow_extent repl; -struct xfs_bmbt_irec got; +struct xfs_bmbt_irec got, rep;struct xfs_scrub *sc = xc->sc; -xfs_fileoff_t nextoff; -xfs_extlen_t alloc_len; +xfs_fsblock_t old_fsbno;int error;/* -* Put the existing CoW fork mapping in @got. If @got ends before -* @rep, truncate @rep so we only replace one extent mapping at a time. +* Put the existing CoW fork mapping in @got, and put in @rep the +* contents of @got trimmed to @startoff/@blockcount. We only want +* to replace the bad region, and only one mapping at a time. */ - error =xrep_cow_find_mapping (xc, &icur, startoff, &got); + error =xrep_cow_find_mapping (xc, &icur, startoff, *blockcount, &got, + &rep);if (error)return error; - nextoff =min (startoff + *blockcount, - got.br_startoff + got.br_blockcount); + old_fsbno = rep.br_startblock;/* * Allocate a replacement extent. If we don't fill all the blocks, * shorten the quantity that will be deleted in this step. */ - alloc_len =min_t (xfs_fileoff_t,XFS_MAX_BMBT_EXTLEN , - nextoff - startoff); - error =xrep_cow_alloc (sc, alloc_len, &repl); + error =xrep_cow_alloc (sc, &rep);if (error)return error;
@@ -473,7 +527,7 @@ xrep_cow_replace_range(* Replace the old mapping with the new one, and commit the metadata * changes made so far. */ -xrep_cow_replace_mapping (sc->ip, &icur, &got, &repl); +xrep_cow_replace_mapping (sc->ip, &icur, &got, &rep);xfs_inode_set_cowblocks_tag (sc->ip); error =xfs_defer_finish (&sc->tp);
@@ -481,12 +535,12 @@ xrep_cow_replace_range(return error;/* Note the old CoW staging extents; we'll reap them all later. */ - error =xfsb_bitmap_set (&xc->old_cowfork_fsblocks, got.br_startblock, - repl.len); + error =xfsb_bitmap_set (&xc->old_cowfork_fsblocks, old_fsbno, + rep.br_blockcount);if (error)return error; - *blockcount = repl.len; + *blockcount = rep.br_blockcount;return 0 ; }
fs/xfs/scrub/trace.h +17 -11
@@ -2553,9 +2553,9 @@ TRACE_EVENT(xrep_cow_mark_file_range, ); TRACE_EVENT(xrep_cow_replace_mapping, - TP_PROTO(struct xfs_inode *ip, const struct xfs_bmbt_irec *irec, - xfs_fsblock_t new_startblock, xfs_extlen_t new_blockcount), - TP_ARGS(ip, irec, new_startblock, new_blockcount), + TP_PROTO(struct xfs_inode *ip, const struct xfs_bmbt_irec *got, + const struct xfs_bmbt_irec *rep), + TP_ARGS(ip, got, rep), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_ino_t, ino)
@@ -2563,28 +2563,34 @@ TRACE_EVENT(xrep_cow_replace_mapping, __field(xfs_fileoff_t, startoff) __field(xfs_filblks_t, blockcount) __field(xfs_exntst_t, state) + __field(xfs_fileoff_t, new_startoff) __field(xfs_fsblock_t, new_startblock) __field(xfs_extlen_t, new_blockcount) +__field (xfs_exntst_t, new_state) ),TP_fast_assign ( __entry->dev = ip->i_mount->m_super->s_dev; __entry->ino = ip->i_ino; - __entry->startoff = irec->br_startoff; - __entry->startblock = irec->br_startblock; - __entry->blockcount = irec->br_blockcount; - __entry->state = irec->br_state; - __entry->new_startblock = new_startblock; - __entry->new_blockcount = new_blockcount; + __entry->startoff = got->br_startoff; + __entry->startblock = got->br_startblock; + __entry->blockcount = got->br_blockcount; + __entry->state = got->br_state; + __entry->new_startoff = rep->br_startoff; + __entry->new_startblock = rep->br_startblock; + __entry->new_blockcount = rep->br_blockcount; + __entry->new_state = rep->br_state; ), -TP_printk ("dev %d:%d ino 0x%llx startoff 0x%llx startblock 0x%llx fsbcount 0x%llx state 0x%x new_startblock 0x%llx new_fsbcount 0x%x" , +TP_printk ("dev %d:%d ino 0x%llx startoff 0x%llx startblock 0x%llx fsbcount 0x%llx state 0x%x new_startoff 0x%llx new_startblock 0x%llx new_fsbcount 0x%x new_state 0x%x" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->ino, __entry->startoff, __entry->startblock, __entry->blockcount, __entry->state, + __entry->new_startoff, __entry->new_startblock, - __entry->new_blockcount) + __entry->new_blockcount, + __entry->new_state) ); TRACE_EVENT(xrep_cow_free_staging,
Greg Kroah-Hartman
maintainerPATCH 481/602 fbcon: Rename struct fbcon_ops to struct fbcon_par
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit a6adbbc4c32a016146e117b1e9e5242724a75e10 ]
The type struct fbcon_ops contains fbcon state and callbacks. As the callbacks will be removed from struct fbcon_ops, rename the data type to struct fbcon_par. Also rename the variables from ops to par.
The _par postfix ("private access registers") is used throughout the fbdev subsystem for per-driver state. The fbcon pointer within struct fb_info is also named fbcon_par. Hence, the new naming fits existing practice.
v2:
- rename struct fbcon_ops to struct fbcon_par
- fix build for CONFIG_FB_TILEBITTING=n (kernel test robot)
- fix indention
Stable-dep-of: 84202754fb17 ("fbcon: Use correct type for vc_resize() return value")
--- drivers/video/fbdev/core/bitblit.c | 120 ++++----- drivers/video/fbdev/core/fbcon.c | 417 +++++++++++++++----------------- drivers/video/fbdev/core/fbcon.h | 6 drivers/video/fbdev/core/fbcon_ccw.c | 146 +++++------ drivers/video/fbdev/core/fbcon_cw.c | 146 +++++------ drivers/video/fbdev/core/fbcon_rotate.c | 44 +-- drivers/video/fbdev/core/fbcon_rotate.h | 6 drivers/video/fbdev/core/fbcon_ud.c | 162 ++++++------ drivers/video/fbdev/core/softcursor.c | 20 - drivers/video/fbdev/core/tileblit.c | 28 +- 10 files changed, 543 insertions(+), 552 deletions(-)
drivers/video/fbdev/core/bitblit.c +60 -60
@@ -261,10 +261,10 @@ static void bit_cursor(struct vc_data *v int fg, int bg) {struct fb_cursor cursor; -struct fbcon_ops *ops = info->fbcon_par; +struct fbcon_par *par = info->fbcon_par;unsigned short charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;int w =DIV_ROUND_UP (vc->vc_font.width,8 ), c; -int y =real_y (ops->p, vc->state.y); +int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;int err =1 ;char *src;
@@ -278,10 +278,10 @@ static void bit_cursor(struct vc_data *v attribute =get_attribute (info, c); src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height)); -if (ops->cursor_state.image.data != src || - ops->cursor_reset) { - ops->cursor_state.image.data = src; - cursor.set |=FB_CUR_SETIMAGE ; +if (par->cursor_state.image.data != src || + par->cursor_reset) { + par->cursor_state.image.data = src; + cursor.set |=FB_CUR_SETIMAGE ; }if (attribute) {
@@ -290,46 +290,46 @@ static void bit_cursor(struct vc_data *v dst =kmalloc_array (w, vc->vc_font.height,GFP_ATOMIC );if (!dst)return ; -kfree (ops->cursor_data); - ops->cursor_data = dst; +kfree (par->cursor_data); + par->cursor_data = dst;update_attr (dst, src, attribute, vc); src = dst; } -if (ops->cursor_state.image.fg_color != fg || - ops->cursor_state.image.bg_color != bg || - ops->cursor_reset) { - ops->cursor_state.image.fg_color = fg; - ops->cursor_state.image.bg_color = bg; +if (par->cursor_state.image.fg_color != fg || + par->cursor_state.image.bg_color != bg || + par->cursor_reset) { + par->cursor_state.image.fg_color = fg; + par->cursor_state.image.bg_color = bg; cursor.set |=FB_CUR_SETCMAP ; } -if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->state.x)) || - (ops->cursor_state.image.dy != (vc->vc_font.height * y)) || - ops->cursor_reset) { - ops->cursor_state.image.dx = vc->vc_font.width * vc->state.x; - ops->cursor_state.image.dy = vc->vc_font.height * y; +if ((par->cursor_state.image.dx != (vc->vc_font.width * vc->state.x)) || + (par->cursor_state.image.dy != (vc->vc_font.height * y)) || + par->cursor_reset) { + par->cursor_state.image.dx = vc->vc_font.width * vc->state.x; + par->cursor_state.image.dy = vc->vc_font.height * y; cursor.set |=FB_CUR_SETPOS ; } -if (ops->cursor_state.image.height != vc->vc_font.height || - ops->cursor_state.image.width != vc->vc_font.width || - ops->cursor_reset) { - ops->cursor_state.image.height = vc->vc_font.height; - ops->cursor_state.image.width = vc->vc_font.width; +if (par->cursor_state.image.height != vc->vc_font.height || + par->cursor_state.image.width != vc->vc_font.width || + par->cursor_reset) { + par->cursor_state.image.height = vc->vc_font.height; + par->cursor_state.image.width = vc->vc_font.width; cursor.set |=FB_CUR_SETSIZE ; } -if (ops->cursor_state.hot.x || ops->cursor_state.hot.y || - ops->cursor_reset) { - ops->cursor_state.hot.x = cursor.hot.y =0 ; +if (par->cursor_state.hot.x || par->cursor_state.hot.y || + par->cursor_reset) { + par->cursor_state.hot.x = cursor.hot.y =0 ; cursor.set |=FB_CUR_SETHOT ; }if (cursor.set &FB_CUR_SETSIZE || - vc->vc_cursor_type != ops->p->cursor_shape || - ops->cursor_state.mask ==NULL || - ops->cursor_reset) { + vc->vc_cursor_type != par->p->cursor_shape || + par->cursor_state.mask ==NULL || + par->cursor_reset) {char *mask =kmalloc_array (w, vc->vc_font.height,GFP_ATOMIC );int cur_height, size, i =0 ;u8 msk =0xff ;
@@ -337,13 +337,13 @@ static void bit_cursor(struct vc_data *vif (!mask)return ; -kfree (ops->cursor_state.mask); - ops->cursor_state.mask = mask; +kfree (par->cursor_state.mask); + par->cursor_state.mask = mask; - ops->p->cursor_shape = vc->vc_cursor_type; + par->p->cursor_shape = vc->vc_cursor_type; cursor.set |=FB_CUR_SETSHAPE ; -switch (CUR_SIZE (ops->p->cursor_shape)) { +switch (CUR_SIZE (par->p->cursor_shape)) {case CUR_NONE : cur_height =0 ;break ;
@@ -372,19 +372,19 @@ static void bit_cursor(struct vc_data *v mask[i++] = msk; } - ops->cursor_state.enable = enable && !use_sw; + par->cursor_state.enable = enable && !use_sw; cursor.image.data = src; - cursor.image.fg_color = ops->cursor_state.image.fg_color; - cursor.image.bg_color = ops->cursor_state.image.bg_color; - cursor.image.dx = ops->cursor_state.image.dx; - cursor.image.dy = ops->cursor_state.image.dy; - cursor.image.height = ops->cursor_state.image.height; - cursor.image.width = ops->cursor_state.image.width; - cursor.hot.x = ops->cursor_state.hot.x; - cursor.hot.y = ops->cursor_state.hot.y; - cursor.mask = ops->cursor_state.mask; - cursor.enable = ops->cursor_state.enable; + cursor.image.fg_color = par->cursor_state.image.fg_color; + cursor.image.bg_color = par->cursor_state.image.bg_color; + cursor.image.dx = par->cursor_state.image.dx; + cursor.image.dy = par->cursor_state.image.dy; + cursor.image.height = par->cursor_state.image.height; + cursor.image.width = par->cursor_state.image.width; + cursor.hot.x = par->cursor_state.hot.x; + cursor.hot.y = par->cursor_state.hot.y; + cursor.mask = par->cursor_state.mask; + cursor.enable = par->cursor_state.enable; cursor.image.depth =1 ; cursor.rop =ROP_XOR ;
@@ -394,31 +394,31 @@ static void bit_cursor(struct vc_data *vif (err)soft_cursor (info, &cursor); - ops->cursor_reset =0 ; + par->cursor_reset =0 ; }static int bit_update_start (struct fb_info *info) { -struct fbcon_ops *ops = info->fbcon_par; +struct fbcon_par *par = info->fbcon_par;int err; - err =fb_pan_display (info, &ops->var); - ops->var.xoffset = info->var.xoffset; - ops->var.yoffset = info->var.yoffset; - ops->var.vmode = info->var.vmode; + err =fb_pan_display (info, &par->var); + par->var.xoffset = info->var.xoffset; + par->var.yoffset = info->var.yoffset; + par->var.vmode = info->var.vmode;return err; } -void fbcon_set_bitops (struct fbcon_ops *ops) +void fbcon_set_bitops (struct fbcon_par *par) { - ops->bmove = bit_bmove; - ops->clear = bit_clear; - ops->putcs = bit_putcs; - ops->clear_margins = bit_clear_margins; - ops->cursor = bit_cursor; - ops->update_start = bit_update_start; - ops->rotate_font =NULL ; + par->bmove = bit_bmove; + par->clear = bit_clear; + par->putcs = bit_putcs; + par->clear_margins = bit_clear_margins; + par->cursor = bit_cursor; + par->update_start = bit_update_start; + par->rotate_font =NULL ; -if (ops->rotate) -fbcon_set_rotate (ops); +if (par->rotate) +fbcon_set_rotate (par); }
drivers/video/fbdev/core/fbcon.c +204 -213
1,058 lines not on this page · raw message
drivers/video/fbdev/core/fbcon.h +3 -3
@@ -50,7 +50,7 @@ struct fbcon_display {const struct fb_videomode *mode; }; -struct fbcon_ops { +struct fbcon_par {void (*bmove)(struct vc_data *vc,struct fb_info *info,int sy,int sx,int dy,int dx,int height,int width); void (*clear)(struct vc_data *vc, struct fb_info *info, int sy,
@@ -185,7 +185,7 @@ static inline u_short fb_scrollmode(stru#ifdef CONFIG_FB_TILEBLITTING extern void fbcon_set_tileops (struct vc_data *vc,struct fb_info *info);#endif -extern void fbcon_set_bitops (struct fbcon_ops *ops); +extern void fbcon_set_bitops (struct fbcon_par *par);extern int soft_cursor (struct fb_info *info,struct fb_cursor *cursor);#define FBCON_ATTRIBUTE_UNDERLINE 1
@@ -224,7 +224,7 @@ static inline int get_attribute(struct f (i == FB_ROTATE_UR || i == FB_ROTATE_UD) ? _r : _v; })#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION -extern void fbcon_set_rotate (struct fbcon_ops *ops); +extern void fbcon_set_rotate (struct fbcon_par *par);#else #define fbcon_set_rotate (x) do {} while(0)#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
drivers/video/fbdev/core/fbcon_ccw.c +73 -73
261 lines not on this page · raw message
drivers/video/fbdev/core/fbcon_cw.c +73 -73
261 lines not on this page · raw message
drivers/video/fbdev/core/fbcon_rotate.c +22 -22
90 lines not on this page · raw message
drivers/video/fbdev/core/fbcon_rotate.h +3 -3
@@ -90,7 +90,7 @@ static inline void rotate_ccw(const char } } -extern void fbcon_rotate_cw (struct fbcon_ops *ops); -extern void fbcon_rotate_ud (struct fbcon_ops *ops); -extern void fbcon_rotate_ccw (struct fbcon_ops *ops); +extern void fbcon_rotate_cw (struct fbcon_par *par); +extern void fbcon_rotate_ud (struct fbcon_par *par); +extern void fbcon_rotate_ccw (struct fbcon_par *par);#endif
drivers/video/fbdev/core/fbcon_ud.c +81 -81
291 lines not on this page · raw message
drivers/video/fbdev/core/softcursor.c +10 -10
@@ -21,7 +21,7 @@int soft_cursor (struct fb_info *info,struct fb_cursor *cursor) { -struct fbcon_ops *ops = info->fbcon_par; +struct fbcon_par *par = info->fbcon_par;unsigned int scan_align = info->pixmap.scan_align -1 ;unsigned int buf_align = info->pixmap.buf_align -1 ;unsigned int i, size, dsize, s_pitch, d_pitch;
@@ -34,19 +34,19 @@ int soft_cursor(struct fb_info *info, st s_pitch = (cursor->image.width +7 ) >>3 ; dsize = s_pitch * cursor->image.height; -if (dsize +sizeof (struct fb_image ) != ops->cursor_size) { -kfree (ops->cursor_src); - ops->cursor_size = dsize +sizeof (struct fb_image ); - - ops->cursor_src =kmalloc (ops->cursor_size,GFP_ATOMIC ); -if (!ops->cursor_src) { - ops->cursor_size =0 ; +if (dsize +sizeof (struct fb_image ) != par->cursor_size) { +kfree (par->cursor_src); + par->cursor_size = dsize +sizeof (struct fb_image ); + + par->cursor_src =kmalloc (par->cursor_size,GFP_ATOMIC ); +if (!par->cursor_src) { + par->cursor_size =0 ;return -ENOMEM ; } } - src = ops->cursor_src +sizeof (struct fb_image ); - image = (struct fb_image *)ops->cursor_src; + src = par->cursor_src +sizeof (struct fb_image ); + image = (struct fb_image *)par->cursor_src; *image = cursor->image; d_pitch = (s_pitch + scan_align) & ~scan_align;
drivers/video/fbdev/core/tileblit.c +14 -14
@@ -151,34 +151,34 @@ static void tile_cursor(struct vc_data *static int tile_update_start (struct fb_info *info) { -struct fbcon_ops *ops = info->fbcon_par; +struct fbcon_par *par = info->fbcon_par;int err; - err =fb_pan_display (info, &ops->var); - ops->var.xoffset = info->var.xoffset; - ops->var.yoffset = info->var.yoffset; - ops->var.vmode = info->var.vmode; + err =fb_pan_display (info, &par->var); + par->var.xoffset = info->var.xoffset; + par->var.yoffset = info->var.yoffset; + par->var.vmode = info->var.vmode;return err; }void fbcon_set_tileops (struct vc_data *vc,struct fb_info *info) {struct fb_tilemap map; -struct fbcon_ops *ops = info->fbcon_par; +struct fbcon_par *par = info->fbcon_par; - ops->bmove = tile_bmove; - ops->clear = tile_clear; - ops->putcs = tile_putcs; - ops->clear_margins = tile_clear_margins; - ops->cursor = tile_cursor; - ops->update_start = tile_update_start; + par->bmove = tile_bmove; + par->clear = tile_clear; + par->putcs = tile_putcs; + par->clear_margins = tile_clear_margins; + par->cursor = tile_cursor; + par->update_start = tile_update_start; -if (ops->p) { +if (par->p) { map.width = vc->vc_font.width; map.height = vc->vc_font.height; map.depth =1 ; map.length = vc->vc_font.charcount; - map.data = ops->p->fontdata; + map.data = par->p->fontdata; info->tileops->fb_settile (info, &map); } }
Greg Kroah-Hartman
maintainerPATCH 482/602 fbcon: Use correct type for vc_resize() return value
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiacheng Yu <[email protected]>
[ Upstream commit 84202754fb1727dc3ee87f47104e4162ecc8ba3a ]
The return value of vc_resize() is int, but fbcon_set_disp() stores it in an unsigned long variable. While the !ret check happens to work correctly by coincidence (negative values become large positive values), the types should match. Use int instead.
Eliminates the following W=3 warning:
drivers/video/fbdev/core/fbcon.c: In function 'fbcon_set_disp':
drivers/video/fbdev/core/fbcon.c:1494:14: warning: implicit conversion from 'int' to 'unsigned long' [-Wconversion]
--- drivers/video/fbdev/core/fbcon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/core/fbcon.c +1 -2
@@ -1366,8 +1366,7 @@ static void fbcon_set_disp(struct fb_infstruct vc_data **default_mode, *vc;struct vc_data *svc;struct fbcon_par *par = info->fbcon_par; -int rows, cols; -unsigned long ret =0 ; +int rows, cols, ret; p = &fb_display[unit];
Greg Kroah-Hartman
maintainerPATCH 483/602 rxrpc: Fix CPU time starvation in I/O thread
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 9e3cccd176b5ec6ff78693287fb03097e453e69c ]
Starvation can happen in the rxrpc I/O thread because it goes back to the top of the I/O loop after it does any one thing without trying to give any other connection or call CPU time. Also, because it processes one call packet at a time, it tries to do the retransmission loop after each ACK without checking to see if there are other ACKs already in the queue that can update the SACK state.
Fix this by:
(1) Add a received-packet queue on each call.
(2) Distribute packets from the master Rx queue to the individual call, conn and error queues and 'poking' calls to add them to the attend queue first thing in the I/O thread.
(3) Go through all the attention-seeking connections and calls before going back to the top of the I/O thread. Each queue is extracted as a whole and then gone through so that new additions to insert themselves into the queue.
(4) Make the call event handler go through all the packets currently on the call's rx_queue before transmitting and retransmitting DATA packets.
(5) Drop the skb argument from the call event handler as this is now replaced with the rx_queue. Instead, keep track of whether we received a packet or an ACK for the tests that used to rely on that.
Stable-dep-of: e66f8f32f501 ("rxrpc: Fix socket notification race")
--- include/trace/events/rxrpc.h | 2 net/rxrpc/ar-internal.h | 10 +++- net/rxrpc/call_accept.c | 2 net/rxrpc/call_event.c | 31 +++++++----- net/rxrpc/call_object.c | 2 net/rxrpc/conn_client.c | 12 ++-- net/rxrpc/input.c | 2 net/rxrpc/io_thread.c | 104 +++++++++++++++++++++---------------------- net/rxrpc/peer_event.c | 2 9 files changed, 93 insertions(+), 74 deletions(-)
include/trace/events/rxrpc.h +2 -0
@@ -121,6 +121,7 @@ EM(rxrpc_call_poke_conn_abort, "Conn-abort") \ EM(rxrpc_call_poke_error, "Error") \ EM(rxrpc_call_poke_idle, "Idle") \ + EM(rxrpc_call_poke_rx_packet, "Rx-packet") \ EM(rxrpc_call_poke_set_timeout, "Set-timo") \ EM(rxrpc_call_poke_start, "Start") \EM (rxrpc_call_poke_timer,"Timer" ) \
@@ -139,6 +140,7 @@ EM(rxrpc_skb_new_error_report, "NEW error-rpt") \ EM(rxrpc_skb_new_jumbo_subpacket, "NEW jumbo-sub") \ EM(rxrpc_skb_new_unshared, "NEW unshared ") \ + EM(rxrpc_skb_put_call_rx, "PUT call-rx ") \ EM(rxrpc_skb_put_conn_secured, "PUT conn-secd") \ EM(rxrpc_skb_put_conn_work, "PUT conn-work") \EM (rxrpc_skb_put_error_report,"PUT error-rep" ) \
net/rxrpc/ar-internal.h +9 -1
@@ -683,6 +683,7 @@ struct rxrpc_call {/* Received data tracking */ struct sk_buff_head recvmsg_queue;/* Queue of packets ready for recvmsg() */ +struct sk_buff_head rx_queue;/* Queue of packets for this call to receive */ struct sk_buff_head rx_oos_queue;/* Queue of out of sequence packets */ void *rx_dec_buffer;/* Decryption buffer */ unsigned short rx_dec_bsize;/* rx_dec_buffer size */
@@ -871,7 +872,7 @@ void rxrpc_propose_delay_ACK(struct rxrpvoid rxrpc_shrink_call_tx_buffer (struct rxrpc_call *);void rxrpc_resend (struct rxrpc_call *call,struct sk_buff *ack_skb); -bool rxrpc_input_call_event (struct rxrpc_call *call,struct sk_buff *skb); +bool rxrpc_input_call_event (struct rxrpc_call *call);/* * call_object.c
@@ -1320,6 +1321,13 @@ static inline bool after_eq(u32 seq1, u3return (s32)(seq1 - seq2) >=0 ; } +static inline void rxrpc_queue_rx_call_packet (struct rxrpc_call *call,struct sk_buff *skb) +{ +rxrpc_get_skb (skb, rxrpc_skb_get_call_rx); +__skb_queue_tail (&call->rx_queue, skb); +rxrpc_poke_call (call, rxrpc_call_poke_rx_packet); +} +/* * debug tracing */
net/rxrpc/call_accept.c +1 -1
@@ -415,7 +415,7 @@ bool rxrpc_new_incoming_call(struct rxrp }_leave (" = %p{%d}" , call, call->debug_id); -rxrpc_input_call_event (call, skb); +rxrpc_queue_rx_call_packet (call, skb);rxrpc_put_call (call, rxrpc_call_put_input);return true;
net/rxrpc/call_event.c +17 -14
@@ -315,10 +315,11 @@ static void rxrpc_send_initial_ping(stru/* * Handle retransmission and deferred ACK/abort generation. */ -bool rxrpc_input_call_event (struct rxrpc_call *call,struct sk_buff *skb) +bool rxrpc_input_call_event (struct rxrpc_call *call) { +struct sk_buff *skb;ktime_t now, t; -bool resend = false; +bool resend = false, saw_ack = false;s32 abort_code;rxrpc_see_call (call, rxrpc_call_see_input);
@@ -328,9 +329,6 @@ bool rxrpc_input_call_event(struct rxrpc call->debug_id, rxrpc_call_states[__rxrpc_call_state (call)], call->events); -if (__rxrpc_call_is_complete (call)) - goto out; -/* Handle abort request locklessly, vs rxrpc_propose_abort(). */ abort_code =smp_load_acquire (&call->send_abort);if (abort_code) {
@@ -339,11 +337,20 @@ bool rxrpc_input_call_event(struct rxrpc goto out; } -if (skb && skb->mark ==RXRPC_SKB_MARK_ERROR ) - goto out; +while ((skb =__skb_dequeue (&call->rx_queue))) { +struct rxrpc_skb_priv *sp =rxrpc_skb (skb); + +if (__rxrpc_call_is_complete (call) || + skb->mark ==RXRPC_SKB_MARK_ERROR ) { +rxrpc_free_skb (skb, rxrpc_skb_put_call_rx); + goto out; + } + + saw_ack |= sp->hdr.type ==RXRPC_PACKET_TYPE_ACK ; -if (skb)rxrpc_input_call_packet (call, skb); +rxrpc_free_skb (skb, rxrpc_skb_put_call_rx); + }/* If we see our async-event poke, check for timeout trippage. */ now =ktime_get_real ();
@@ -409,12 +416,8 @@ bool rxrpc_input_call_event(struct rxrpc rxrpc_propose_ack_ping_for_keepalive); } -if (skb) { -struct rxrpc_skb_priv *sp =rxrpc_skb (skb); - -if (sp->hdr.type ==RXRPC_PACKET_TYPE_ACK ) -rxrpc_congestion_degrade (call); - } +if (saw_ack) +rxrpc_congestion_degrade (call);if (test_and_clear_bit (RXRPC_CALL_EV_INITIAL_PING , &call->events))rxrpc_send_initial_ping (call);
net/rxrpc/call_object.c +2 -0
@@ -147,6 +147,7 @@ struct rxrpc_call *rxrpc_alloc_call(struINIT_LIST_HEAD (&call->attend_link);INIT_LIST_HEAD (&call->tx_sendmsg);INIT_LIST_HEAD (&call->tx_buffer); +skb_queue_head_init (&call->rx_queue);skb_queue_head_init (&call->recvmsg_queue);skb_queue_head_init (&call->rx_oos_queue);init_waitqueue_head (&call->waitq);
@@ -535,6 +536,7 @@ void rxrpc_get_call(struct rxrpc_call *cstatic void rxrpc_cleanup_ring (struct rxrpc_call *call) {rxrpc_purge_queue (&call->recvmsg_queue); +rxrpc_purge_queue (&call->rx_queue);rxrpc_purge_queue (&call->rx_oos_queue);kfree (call->rx_dec_buffer); }
net/rxrpc/conn_client.c +7 -5
@@ -508,16 +508,18 @@ static void rxrpc_activate_channels(struvoid rxrpc_connect_client_calls (struct rxrpc_local *local) {struct rxrpc_call *call; +LIST_HEAD (new_client_calls); -while ((call =list_first_entry_or_null (&local->new_client_calls, - struct rxrpc_call, wait_link)) - ) { +spin_lock (&local->client_call_lock); +list_splice_tail_init (&local->new_client_calls, &new_client_calls); +spin_unlock (&local->client_call_lock); + +while ((call =list_first_entry_or_null (&new_client_calls, + struct rxrpc_call, wait_link))) {struct rxrpc_bundle *bundle = call->bundle; -spin_lock (&local->client_call_lock);list_move_tail (&call->wait_link, &bundle->waiting_calls);rxrpc_see_call (call, rxrpc_call_see_waiting_call); -spin_unlock (&local->client_call_lock);if (rxrpc_bundle_has_space (bundle))rxrpc_activate_channels (bundle);
net/rxrpc/input.c +1 -1
@@ -1122,5 +1122,5 @@ void rxrpc_implicit_end_call(struct rxrpbreak ; } -rxrpc_input_call_event (call, skb); +rxrpc_input_call_event (call); }
net/rxrpc/io_thread.c +53 -51
145 lines not on this page · raw message
net/rxrpc/peer_event.c +1 -1
@@ -216,7 +216,7 @@ static void rxrpc_distribute_error(strucrxrpc_see_call (call, rxrpc_call_see_distribute_error);rxrpc_set_call_completion (call, compl,0 , -err); -rxrpc_input_call_event (call, skb); +rxrpc_input_call_event (call);spin_lock (&peer->lock); }
Greg Kroah-Hartman
maintainerPATCH 484/602 rxrpc: Dont need barrier for ->tx_bottom and ->acks_hard_ack
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 6396b48ac0a77165f9c2c40ab03d6c8188c89739 ]
We don't need a barrier for the ->tx_bottom value (which indicates the lowest sequence still in the transmission queue) and the ->acks_hard_ack value (which tracks the DATA packets hard-ack'd by the latest ACK packet received and thus indicates which DATA packets can now be discarded) as the app thread doesn't use either value as a reference to memory to access. Rather, the app thread merely uses these as a guide to how much space is available in the transmission queue
Change the code to use READ/WRITE_ONCE() instead.
Also, change rxrpc_check_tx_space() to use the same value for tx_bottom throughout.
Stable-dep-of: e66f8f32f501 ("rxrpc: Fix socket notification race")
--- net/rxrpc/sendmsg.c | 8 +++++--- net/rxrpc/txbuf.c | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-)
net/rxrpc/sendmsg.c +5 -3
@@ -93,9 +93,11 @@ no_wait:*/ static bool rxrpc_check_tx_space (struct rxrpc_call *call,rxrpc_seq_t *_tx_win) { +rxrpc_seq_t tx_bottom =READ_ONCE (call->tx_bottom); +if (_tx_win) - *_tx_win = call->tx_bottom; -return call->tx_prepared - call->tx_bottom <256 ; + *_tx_win = tx_bottom; +return call->tx_prepared - tx_bottom <256 ; }/*
@@ -137,7 +139,7 @@ static int rxrpc_wait_for_tx_window_wait rtt =2 ; timeout = rtt; - tx_start =smp_load_acquire (&call->acks_hard_ack); + tx_start =READ_ONCE (call->acks_hard_ack);for (;;) {set_current_state (TASK_UNINTERRUPTIBLE );
net/rxrpc/txbuf.c +2 -2
@@ -216,14 +216,14 @@ void rxrpc_shrink_call_tx_buffer(structwhile ((txb =list_first_entry_or_null (&call->tx_buffer, struct rxrpc_txbuf, call_link))) { - hard_ack =smp_load_acquire (&call->acks_hard_ack); + hard_ack = call->acks_hard_ack;if (before (hard_ack, txb->seq))break ;if (txb->seq != call->tx_bottom +1 )rxrpc_see_txbuf (txb, rxrpc_txbuf_see_out_of_step); ASSERTCMP(txb->seq, ==, call->tx_bottom + 1); -smp_store_release (&call->tx_bottom, call->tx_bottom +1 ); +WRITE_ONCE (call->tx_bottom, call->tx_bottom +1 );list_del_rcu (&txb->call_link);trace_rxrpc_txqueue (call, rxrpc_txqueue_dequeue);
Greg Kroah-Hartman
maintainerPATCH 485/602 rxrpc: Use irq-disabling spinlocks between app and I/O thread
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit a2ea9a9072607c2fd6442bd1ffb4dbdbf882aed7 ]
Where a spinlock is used by both the application thread and the I/O thread, use irq-disabling locking so that an interrupt taken on the app thread doesn't also slow down the I/O thread.
Stable-dep-of: e66f8f32f501 ("rxrpc: Fix socket notification race")
--- net/rxrpc/af_rxrpc.c | 4 ++-- net/rxrpc/call_accept.c | 20 ++++++++++---------- net/rxrpc/call_object.c | 14 +++++++------- net/rxrpc/conn_client.c | 12 ++++++------ net/rxrpc/conn_event.c | 14 +++++++------- net/rxrpc/conn_object.c | 8 ++++---- net/rxrpc/input.c | 5 +---- net/rxrpc/io_thread.c | 8 ++++---- net/rxrpc/peer_event.c | 8 ++++---- net/rxrpc/peer_object.c | 1 + net/rxrpc/recvmsg.c | 22 +++++++++++----------- net/rxrpc/security.c | 4 ++-- 12 files changed, 59 insertions(+), 61 deletions(-)
net/rxrpc/af_rxrpc.c +2 -2
@@ -408,9 +408,9 @@ void rxrpc_kernel_shutdown_call(struct s/* Make sure we're not going to call back into a kernel service */ if (call->notify_rx) { -spin_lock (&call->notify_lock); +spin_lock_irq (&call->notify_lock); call->notify_rx = rxrpc_dummy_notify_rx; -spin_unlock (&call->notify_lock); +spin_unlock_irq (&call->notify_lock); } }mutex_unlock (&call->user_mutex);
net/rxrpc/call_accept.c +10 -10
@@ -189,8 +189,8 @@ void rxrpc_discard_prealloc(struct rxrpc/* Make sure that there aren't any incoming calls in progress before we * clear the preallocation buffers. */ -spin_lock (&rx->incoming_lock); -spin_unlock (&rx->incoming_lock); +spin_lock_irq (&rx->incoming_lock); +spin_unlock_irq (&rx->incoming_lock); head = b->peer_backlog_head; tail = b->peer_backlog_tail;
@@ -349,7 +349,7 @@ bool rxrpc_new_incoming_call(struct rxrpif (sp->hdr.type !=RXRPC_PACKET_TYPE_DATA )return rxrpc_protocol_error (skb, rxrpc_eproto_no_service_call); -read_lock (&local->services_lock); +read_lock_irq (&local->services_lock);/* Weed out packets to services we're not offering. Packets that would * begin a call are explicitly rejected and the rest are just
@@ -406,12 +406,12 @@ bool rxrpc_new_incoming_call(struct rxrpspin_unlock (&conn->state_lock);spin_unlock (&rx->incoming_lock); -read_unlock (&local->services_lock); +read_unlock_irq (&local->services_lock);if (hlist_unhashed (&call->error_link)) { -spin_lock (&call->peer->lock); +spin_lock_irq (&call->peer->lock);hlist_add_head (&call->error_link, &call->peer->error_targets); -spin_unlock (&call->peer->lock); +spin_unlock_irq (&call->peer->lock); }_leave (" = %p{%d}" , call, call->debug_id);
@@ -420,20 +420,20 @@ bool rxrpc_new_incoming_call(struct rxrpreturn true; unsupported_service: -read_unlock (&local->services_lock); +read_unlock_irq (&local->services_lock);return rxrpc_direct_abort (skb, rxrpc_abort_service_not_offered,RX_INVALID_OPERATION , -EOPNOTSUPP ); unsupported_security: -read_unlock (&local->services_lock); +read_unlock_irq (&local->services_lock);return rxrpc_direct_abort (skb, rxrpc_abort_service_not_offered,RX_INVALID_OPERATION , -EKEYREJECTED ); no_call:spin_unlock (&rx->incoming_lock); -read_unlock (&local->services_lock); +read_unlock_irq (&local->services_lock);_leave (" = f [%u]" , skb->mark);return false; discard: -read_unlock (&local->services_lock); +read_unlock_irq (&local->services_lock);return true; }
net/rxrpc/call_object.c +7 -7
@@ -48,7 +48,7 @@ void rxrpc_poke_call(struct rxrpc_call *bool busy;if (!test_bit (RXRPC_CALL_DISCONNECTED , &call->flags)) { -spin_lock_bh (&local->lock); +spin_lock_irq (&local->lock); busy = !list_empty (&call->attend_link);trace_rxrpc_poke_call (call, busy, what);if (!busy && !rxrpc_try_get_call (call, rxrpc_call_get_poke))
@@ -56,7 +56,7 @@ void rxrpc_poke_call(struct rxrpc_call *if (!busy) {list_add_tail (&call->attend_link, &local->call_attend_q); } -spin_unlock_bh (&local->lock); +spin_unlock_irq (&local->lock);if (!busy)rxrpc_wake_up_io_thread (local); }
@@ -303,9 +303,9 @@ static int rxrpc_connect_call(struct rxrtrace_rxrpc_client (NULL ,-1 , rxrpc_client_queue_new_call);rxrpc_get_call (call, rxrpc_call_get_io_thread); -spin_lock (&local->client_call_lock); +spin_lock_irq (&local->client_call_lock);list_add_tail (&call->wait_link, &local->new_client_calls); -spin_unlock (&local->client_call_lock); +spin_unlock_irq (&local->client_call_lock);rxrpc_wake_up_io_thread (local);return 0 ;
@@ -435,7 +435,7 @@ error_attached_to_socket:/* * Set up an incoming call. call->conn points to the connection. -* This is called in BH context and isn't allowed to fail. +* This is called with interrupts disabled and isn't allowed to fail. */ void rxrpc_incoming_call(struct rxrpc_sock *rx, struct rxrpc_call *call,
@@ -560,7 +560,7 @@ void rxrpc_release_call(struct rxrpc_socrxrpc_put_call_slot (call);/* Make sure we don't get any more notifications */ -spin_lock (&rx->recvmsg_lock); +spin_lock_irq (&rx->recvmsg_lock);if (!list_empty (&call->recvmsg_link)) { _debug("unlinking once-pending call %p { e=%lx f=%lx }",
@@ -573,7 +573,7 @@ void rxrpc_release_call(struct rxrpc_soc call->recvmsg_link.next =NULL ; call->recvmsg_link.prev =NULL ; -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock);if (put)rxrpc_put_call (call, rxrpc_call_put_unnotify);
net/rxrpc/conn_client.c +6 -6
@@ -510,9 +510,9 @@ void rxrpc_connect_client_calls(struct rstruct rxrpc_call *call;LIST_HEAD (new_client_calls); -spin_lock (&local->client_call_lock); +spin_lock_irq (&local->client_call_lock);list_splice_tail_init (&local->new_client_calls, &new_client_calls); -spin_unlock (&local->client_call_lock); +spin_unlock_irq (&local->client_call_lock);while ((call =list_first_entry_or_null (&new_client_calls, struct rxrpc_call, wait_link))) {
@@ -547,9 +547,9 @@ void rxrpc_expose_client_call(struct rxrset_bit (RXRPC_CONN_DONT_REUSE , &conn->flags);trace_rxrpc_client (conn, channel, rxrpc_client_exposed); -spin_lock (&call->peer->lock); +spin_lock_irq (&call->peer->lock);hlist_add_head (&call->error_link, &call->peer->error_targets); -spin_unlock (&call->peer->lock); +spin_unlock_irq (&call->peer->lock); } }
@@ -590,9 +590,9 @@ void rxrpc_disconnect_client_call(struct ASSERTCMP(call->call_id, ==, 0);ASSERT (!test_bit (RXRPC_CALL_EXPOSED , &call->flags));/* May still be on ->new_client_calls. */ -spin_lock (&local->client_call_lock); +spin_lock_irq (&local->client_call_lock);list_del_init (&call->wait_link); -spin_unlock (&local->client_call_lock); +spin_unlock_irq (&local->client_call_lock);return ; }
net/rxrpc/conn_event.c +7 -7
@@ -26,7 +26,7 @@ static bool rxrpc_set_conn_aborted(strucbool aborted = false;if (conn->state !=RXRPC_CONN_ABORTED ) { -spin_lock (&conn->state_lock); +spin_lock_irq (&conn->state_lock);if (conn->state !=RXRPC_CONN_ABORTED ) { conn->abort_code = abort_code; conn->error = err;
@@ -37,7 +37,7 @@ static bool rxrpc_set_conn_aborted(strucset_bit (RXRPC_CONN_EV_ABORT_CALLS , &conn->events); aborted = true; } -spin_unlock (&conn->state_lock); +spin_unlock_irq (&conn->state_lock); }return aborted;
@@ -268,12 +268,12 @@ static int rxrpc_process_event(struct rxreturn conn->security->respond_to_challenge (conn, skb);case RXRPC_PACKET_TYPE_RESPONSE : -spin_lock (&conn->state_lock); +spin_lock_irq (&conn->state_lock);if (conn->state !=RXRPC_CONN_SERVICE_CHALLENGING ) { -spin_unlock (&conn->state_lock); +spin_unlock_irq (&conn->state_lock);return 0 ; } -spin_unlock (&conn->state_lock); +spin_unlock_irq (&conn->state_lock); ret =rxrpc_verify_response (conn, skb);if (ret <0 )
@@ -284,12 +284,12 @@ static int rxrpc_process_event(struct rxif (ret <0 )return ret; -spin_lock (&conn->state_lock); +spin_lock_irq (&conn->state_lock);if (conn->state ==RXRPC_CONN_SERVICE_CHALLENGING ) { conn->state =RXRPC_CONN_SERVICE ; secured = true; } -spin_unlock (&conn->state_lock); +spin_unlock_irq (&conn->state_lock);if (secured) {/* Offload call state flipping to the I/O thread. As
net/rxrpc/conn_object.c +4 -4
@@ -31,13 +31,13 @@ void rxrpc_poke_conn(struct rxrpc_connecif (WARN_ON_ONCE (!local))return ; -spin_lock_bh (&local->lock); +spin_lock_irq (&local->lock); busy = !list_empty (&conn->attend_link);if (!busy) {rxrpc_get_connection (conn, why);list_add_tail (&conn->attend_link, &local->conn_attend_q); } -spin_unlock_bh (&local->lock); +spin_unlock_irq (&local->lock);rxrpc_wake_up_io_thread (local); }
@@ -197,9 +197,9 @@ void rxrpc_disconnect_call(struct rxrpc_ call->peer->cong_ssthresh = call->cong_ssthresh;if (!hlist_unhashed (&call->error_link)) { -spin_lock (&call->peer->lock); +spin_lock_irq (&call->peer->lock);hlist_del_init (&call->error_link); -spin_unlock (&call->peer->lock); +spin_unlock_irq (&call->peer->lock); }if (rxrpc_is_client_call (call)) {
net/rxrpc/input.c +1 -4
@@ -365,7 +365,7 @@ static void rxrpc_input_queue_data(strucstruct rxrpc_skb_priv *sp =rxrpc_skb (skb);bool last = sp->hdr.flags &RXRPC_LAST_PACKET ; -__skb_queue_tail (&call->recvmsg_queue, skb); +skb_queue_tail (&call->recvmsg_queue, skb);rxrpc_input_update_ack_window (call, window, wtop);trace_rxrpc_receive (call, last ? why +1 : why, sp->hdr.serial, sp->hdr.seq);if (last)
@@ -442,7 +442,6 @@ static void rxrpc_input_data_one(structrxrpc_get_skb (skb, rxrpc_skb_get_to_recvmsg); -spin_lock (&call->recvmsg_queue.lock);rxrpc_input_queue_data (call, skb, window, wtop, rxrpc_receive_queue); *_notify = true;
@@ -464,8 +463,6 @@ static void rxrpc_input_data_one(struct rxrpc_receive_queue_oos); } -spin_unlock (&call->recvmsg_queue.lock); - call->ackr_sack_base = sack; }else {unsigned int slot;
net/rxrpc/io_thread.c +4 -4
@@ -475,9 +475,9 @@ int rxrpc_io_thread(void *data) }/* Deal with connections that want immediate attention. */ -spin_lock_bh (&local->lock); +spin_lock_irq (&local->lock);list_splice_tail_init (&local->conn_attend_q, &conn_attend_q); -spin_unlock_bh (&local->lock); +spin_unlock_irq (&local->lock); while ((conn = list_first_entry_or_null(&conn_attend_q, struct rxrpc_connection,
@@ -494,9 +494,9 @@ int rxrpc_io_thread(void *data)rxrpc_discard_expired_client_conns (local);/* Deal with calls that want immediate attention. */ -spin_lock_bh (&local->lock); +spin_lock_irq (&local->lock);list_splice_tail_init (&local->call_attend_q, &call_attend_q); -spin_unlock_bh (&local->lock); +spin_unlock_irq (&local->lock); while ((call = list_first_entry_or_null(&call_attend_q, struct rxrpc_call,
net/rxrpc/peer_event.c +4 -4
@@ -205,23 +205,23 @@ static void rxrpc_distribute_error(strucstruct rxrpc_call *call;HLIST_HEAD (error_targets); -spin_lock (&peer->lock); +spin_lock_irq (&peer->lock);hlist_move_list (&peer->error_targets, &error_targets);while (!hlist_empty (&error_targets)) { call =hlist_entry (error_targets.first, struct rxrpc_call, error_link);hlist_del_init (&call->error_link); -spin_unlock (&peer->lock); +spin_unlock_irq (&peer->lock);rxrpc_see_call (call, rxrpc_call_see_distribute_error);rxrpc_set_call_completion (call, compl,0 , -err);rxrpc_input_call_event (call); -spin_lock (&peer->lock); +spin_lock_irq (&peer->lock); } -spin_unlock (&peer->lock); +spin_unlock_irq (&peer->lock); }/*
net/rxrpc/peer_object.c +1 -0
@@ -304,6 +304,7 @@ static void rxrpc_free_peer(struct rxrpc* Set up a new incoming peer. There shouldn't be any other matching peers * since we've already done a search in the list from the non-reentrant context * (the data_ready handler) that is the only place we can add new peers. +* Called with interrupts disabled. */ void rxrpc_new_incoming_peer (struct rxrpc_local *local,struct rxrpc_peer *peer) {
net/rxrpc/recvmsg.c +11 -11
@@ -36,16 +36,16 @@ void rxrpc_notify_socket(struct rxrpc_ca sk = &rx->sk;if (rx && sk->sk_state <RXRPC_CLOSE ) {if (call->notify_rx) { -spin_lock (&call->notify_lock); +spin_lock_irq (&call->notify_lock); call->notify_rx (sk, call, call->user_call_ID); -spin_unlock (&call->notify_lock); +spin_unlock_irq (&call->notify_lock); }else { -spin_lock (&rx->recvmsg_lock); +spin_lock_irq (&rx->recvmsg_lock);if (list_empty (&call->recvmsg_link)) {rxrpc_get_call (call, rxrpc_call_get_notify_socket);list_add_tail (&call->recvmsg_link, &rx->recvmsg_q); } -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock);if (!sock_flag (sk,SOCK_DEAD )) {_debug ("call %ps" , sk->sk_data_ready);
@@ -379,14 +379,14 @@ try_again:* We also want to weed out calls that got requeued whilst we were * shovelling data out. */ -spin_lock (&rx->recvmsg_lock); +spin_lock_irq (&rx->recvmsg_lock); l = rx->recvmsg_q.next; call = list_entry(l, struct rxrpc_call, recvmsg_link);if (!rxrpc_call_is_complete (call) &&skb_queue_empty (&call->recvmsg_queue)) {list_del_init (&call->recvmsg_link); -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock);release_sock (&rx->sk);trace_rxrpc_recvmsg (call->debug_id, rxrpc_recvmsg_unqueue,0 );rxrpc_put_call (call, rxrpc_call_put_recvmsg);
@@ -407,7 +407,7 @@ try_again:list_del_init (&call->recvmsg_link); elserxrpc_get_call (call ,rxrpc_call_get_recvmsg ); -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock); call_debug_id = call->debug_id;trace_rxrpc_recvmsg (call_debug_id, rxrpc_recvmsg_dequeue,0 );
@@ -502,17 +502,17 @@ error_unlock_call: error_requeue_call:if (!(flags &MSG_PEEK )) { -spin_lock (&rx->recvmsg_lock); +spin_lock_irq (&rx->recvmsg_lock);if (list_empty (&call->recvmsg_link)) {list_add (&call->recvmsg_link, &rx->recvmsg_q);rxrpc_see_call (call, rxrpc_call_see_recvmsg_requeue); -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock); }else if (list_is_first (&call->recvmsg_link, &rx->recvmsg_q)) { -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock);rxrpc_put_call (call, rxrpc_call_see_recvmsg_requeue_first); }else {list_move (&call->recvmsg_link, &rx->recvmsg_q); -spin_unlock (&rx->recvmsg_lock); +spin_unlock_irq (&rx->recvmsg_lock);rxrpc_put_call (call, rxrpc_call_see_recvmsg_requeue_move); }trace_rxrpc_recvmsg (call_debug_id, rxrpc_recvmsg_requeue,0 );
net/rxrpc/security.c +2 -2
@@ -114,10 +114,10 @@ found:if (conn->state ==RXRPC_CONN_CLIENT_UNSECURED ) { ret = conn->security->init_connection_security (conn, token);if (ret ==0 ) { -spin_lock (&conn->state_lock); +spin_lock_irq (&conn->state_lock);if (conn->state ==RXRPC_CONN_CLIENT_UNSECURED ) conn->state =RXRPC_CONN_CLIENT ; -spin_unlock (&conn->state_lock); +spin_unlock_irq (&conn->state_lock); } }mutex_unlock (&conn->security_lock);
Greg Kroah-Hartman
maintainerPATCH 486/602 rxrpc: Fix notification vs call-release vs recvmsg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 2fd895842d49c23137ae48252dd211e5d6d8a3ed ]
When a call is released, rxrpc takes the spinlock and removes it from ->recvmsg_q in an effort to prevent racing recvmsg() invocations from seeing the same call. Now, rxrpc_recvmsg() only takes the spinlock when actually removing a call from the queue; it doesn't, however, take it in the lead up to that when it checks to see if the queue is empty. It *does* hold the socket lock, which prevents a recvmsg/recvmsg race - but this doesn't prevent sendmsg from ending the call because sendmsg() drops the socket lock and relies on the call->user_mutex.
Fix this by firstly removing the bit in rxrpc_release_call() that dequeues the released call and, instead, rely on recvmsg() to simply discard released calls (done in a preceding fix).
Secondly, rxrpc_notify_socket() is abandoned if the call is already marked as released rather than trying to be clever by setting both pointers in call->recvmsg_link to NULL to trick list_empty(). This isn't perfect and can still race, resulting in a released call on the queue, but recvmsg() will now clean that up.
Stable-dep-of: e66f8f32f501 ("rxrpc: Fix socket notification race")
--- include/trace/events/rxrpc.h | 3 ++- net/rxrpc/call_object.c | 28 ++++++++++++---------------- net/rxrpc/recvmsg.c | 4 ++++ 3 files changed, 18 insertions(+), 17 deletions(-)
include/trace/events/rxrpc.h +2 -1
@@ -278,10 +278,10 @@ EM(rxrpc_call_put_poke, "PUT poke ") \ EM(rxrpc_call_put_recvmsg, "PUT recvmsg ") \ EM(rxrpc_call_put_recvmsg_peek_nowait, "PUT peek-nwt") \ + EM(rxrpc_call_put_release_recvmsg_q, "PUT rls-rcmq") \ EM(rxrpc_call_put_release_sock, "PUT rls-sock") \ EM(rxrpc_call_put_release_sock_tba, "PUT rls-sk-a") \ EM(rxrpc_call_put_sendmsg, "PUT sendmsg ") \ - EM(rxrpc_call_put_unnotify, "PUT unnotify") \ EM(rxrpc_call_put_userid_exists, "PUT u-exists") \ EM(rxrpc_call_put_userid, "PUT user-id ") \EM (rxrpc_call_see_accept,"SEE accept " ) \
@@ -294,6 +294,7 @@ EM(rxrpc_call_see_disconnected, "SEE disconn ") \ EM(rxrpc_call_see_distribute_error, "SEE dist-err") \ EM(rxrpc_call_see_input, "SEE input ") \ + EM(rxrpc_call_see_notify_released, "SEE nfy-rlsd") \ EM(rxrpc_call_see_recvmsg, "SEE recvmsg ") \ EM(rxrpc_call_see_recvmsg_requeue, "SEE recv-rqu") \EM (rxrpc_call_see_recvmsg_requeue_first,"SEE recv-rqF" ) \
net/rxrpc/call_object.c +12 -16
@@ -547,7 +547,7 @@ static void rxrpc_cleanup_ring(struct rxvoid rxrpc_release_call (struct rxrpc_sock *rx,struct rxrpc_call *call) {struct rxrpc_connection *conn = call->conn; -bool put = false, putu = false; +bool putu = false;_enter ("{%d,%d}" , call->debug_id,refcount_read (&call->ref));
@@ -559,23 +559,13 @@ void rxrpc_release_call(struct rxrpc_socrxrpc_put_call_slot (call); -/* Make sure we don't get any more notifications */ +/* Note that at this point, the call may still be on or may have been +* added back on to the socket receive queue. recvmsg() must discard +* released calls. The CALL_RELEASED flag should prevent further +* notifications. +*/ spin_lock_irq (&rx->recvmsg_lock); - -if (!list_empty (&call->recvmsg_link)) { -_debug ("unlinking once-pending call %p { e=%lx f=%lx }" , - call, call->events, call->flags); -list_del (&call->recvmsg_link); - put = true; - } - -/* list_empty() must return false in rxrpc_notify_socket() */ - call->recvmsg_link.next =NULL ; - call->recvmsg_link.prev =NULL ; -spin_unlock_irq (&rx->recvmsg_lock); -if (put) -rxrpc_put_call (call, rxrpc_call_put_unnotify);write_lock (&rx->call_lock);
@@ -624,6 +614,12 @@ void rxrpc_release_calls_on_socket(strucrxrpc_put_call (call, rxrpc_call_put_release_sock); } +while ((call =list_first_entry_or_null (&rx->recvmsg_q, + struct rxrpc_call, recvmsg_link))) { +list_del_init (&call->recvmsg_link); +rxrpc_put_call (call, rxrpc_call_put_release_recvmsg_q); + } +_leave ("" ); }
net/rxrpc/recvmsg.c +4 -0
@@ -29,6 +29,10 @@ void rxrpc_notify_socket(struct rxrpc_caif (!list_empty (&call->recvmsg_link))return ; +if (test_bit (RXRPC_CALL_RELEASED , &call->flags)) { +rxrpc_see_call (call, rxrpc_call_see_notify_released); +return ; + }rcu_read_lock ();
Greg Kroah-Hartman
maintainerPATCH 487/602 rxrpc: Fix socket notification race
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit e66f8f32f50116670dbbee5bc9e692cd2cd0c8f8 ]
There's a race between rxrpc_recvmsg() and rxrpc_notify_socket(), whereby the latter's attempt to avoid disabling interrupts and taking the socket's recvmsg_lock if the call is already queued may happen simultaneously with the former's discarding of a call that has nothing queued.
Fix this by removing the shortcut. Note that this only affects userspace's use of AF_RXRPC; the AFS filesystem driver doesn't use the socket queue.
--- net/rxrpc/recvmsg.c | 2 -- 1 file changed, 2 deletions(-)
net/rxrpc/recvmsg.c +0 -2
@@ -27,8 +27,6 @@ void rxrpc_notify_socket(struct rxrpc_ca_enter ("%d" , call->debug_id); -if (!list_empty (&call->recvmsg_link)) -return ;if (test_bit (RXRPC_CALL_RELEASED , &call->flags)) {rxrpc_see_call (call, rxrpc_call_see_notify_released);return ;
Greg Kroah-Hartman
maintainerPATCH 488/602 tipc: restrict socket queue dumps in enqueue tracepoints
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Xiasong <[email protected]>
[ Upstream commit acd7df8d955480a6f6e5bb809da67b1500cc3cf4 ]
tipc_sk_enqueue() runs with sk->sk_lock.slock held while the socket is owned by user context. The spinlock protects the backlog queue in this path, but it does not serialize against the socket owner consuming or purging sk_receive_queue.
KASAN reported:
CPU: 14 UID: 0 PID: 1050 Comm: tipc3 Not tainted 7.1.0-rc6+ #126 PREEMPT(lazy)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x76/0xa0 lib/dump_stack.c:123
print_report+0xce/0x5b0 mm/kasan/report.c:482
kasan_report+0xc6/0x100 mm/kasan/report.c:597
__asan_report_load4_noabort+0x14/0x30 mm/kasan/report_generic.c:380
tipc_skb_dump+0x1327/0x16f0 net/tipc/trace.c:73
tipc_list_dump+0x208/0x2e0 net/tipc/trace.c:187
tipc_sk_dump+0xaf6/0xd60 net/tipc/socket.c:3996
trace_event_raw_event_tipc_sk_class+0x312/0x5a0 net/tipc/trace.h:188
tipc_sk_rcv+0xb1d/0x1d50 net/tipc/socket.c:2497
tipc_node_xmit+0x1c3/0x1440 net/tipc/node.c:1689
__tipc_sendmsg+0x97a/0x1440 net/tipc/socket.c:1512
tipc_sendmsg+0x52/0x80 net/tipc/socket.c:1400
sock_sendmsg+0x2f6/0x3e0 net/socket.c:825
splice_to_socket+0x7f9/0x1010 fs/splice.c:884
do_splice+0xe21/0x2330 fs/splice.c:936
__do_splice+0x153/0x260 fs/splice.c:1431
__x64_sys_splice+0x150/0x230 fs/splice.c:1616
x64_sys_call+0xeb5/0x2790 arch/x86/entry/syscall_64.c:41
do_syscall_64+0xf3/0x620 arch/x86/entry/syscall_64.c:63
entry_SYSCALL_64_after_hwframe+0x76/0x7e arch/x86/entry/entry_64.S:130
RIP: 0033:0x71624e8aafe2
Code: 08 0f 85 71 3a ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 66 2e 0f 1f 84 00 00 00 00 00 66
RSP: 002b:0000716157ffed68 EFLAGS: 00000246 ORIG_RAX: 0000000000000113
RAX: ffffffffffffffda RBX: 0000716157fff6c0 RCX: 000071624e8aafe2
RDX: 000000000000005f RSI: 0000000000000000 RDI: 0000000000000066
RBP: 0000716157ffed90 R08: 0000000000008000 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000246 R12: ffffffffffffff00
R13: 0000000000000021 R14: 0000000000000000 R15: 00007fff89799c40
</TASK>The TIPC_DUMP_ALL tracepoints in tipc_sk_enqueue() also dump sk_receive_queue and can therefore dereference skbs that the socket owner has already dequeued or freed. Restrict these dumps to TIPC_DUMP_SK_BKLGQ, which matches the queue protected by the held spinlock.
Keep the change limited to the enqueue path, where the unsafe queue dump is reachable while the socket is owned by user context.
--- net/tipc/socket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/tipc/socket.c +3 -3
@@ -2456,17 +2456,17 @@ static void tipc_sk_enqueue(struct sk_buatomic_set (dcnt,0 ); lim =rcvbuf_limit (sk, skb) +atomic_read (dcnt);if (likely (!sk_add_backlog (sk, skb, lim))) { -trace_tipc_sk_overlimit1 (sk, skb,TIPC_DUMP_ALL , +trace_tipc_sk_overlimit1 (sk, skb,TIPC_DUMP_SK_BKLGQ ,"bklg & rcvq >90% allocated!" );continue ; } -trace_tipc_sk_dump (sk, skb,TIPC_DUMP_ALL ,"err_overload!" ); +trace_tipc_sk_dump (sk, skb,TIPC_DUMP_SK_BKLGQ ,"err_overload!" );/* Overload => reject message back to sender */ onode =tipc_own_addr (sock_net (sk));atomic_inc (&sk->sk_drops);if (tipc_msg_reverse (onode, &skb,TIPC_ERR_OVERLOAD )) { -trace_tipc_sk_rej_msg (sk, skb,TIPC_DUMP_ALL , +trace_tipc_sk_rej_msg (sk, skb,TIPC_DUMP_SK_BKLGQ ,"@sk_enqueue!" );__skb_queue_tail (xmitq, skb); }
Greg Kroah-Hartman
maintainerPATCH 489/602 vduse: Use fixed 4KB bounce pages for non-4KB page size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sheng Zhao <[email protected]>
[ Upstream commit 3fc3068e7247c94dec08e93fea422a1bb649bfe5 ]
The allocation granularity of bounce pages is PAGE_SIZE. This may cause even small IO requests to occupy an entire bounce page exclusively. The kind of memory waste will be more significant when PAGE_SIZE is larger than 4KB (e.g. arm64 with 64KB pages).
So, optimize it by using fixed 4KB bounce maps and iova allocation granularity. A single IO request occupies at least a 4KB bounce page instead of the entire memory page of PAGE_SIZE.
Message-Id: <[email protected]>
Stable-dep-of: 9c1523803445 ("VDUSE: avoid leaking information to userspace")
--- drivers/vdpa/vdpa_user/iova_domain.c | 130 +++++++++++++++++++++++------------ drivers/vdpa/vdpa_user/iova_domain.h | 5 + 2 files changed, 94 insertions(+), 41 deletions(-)
drivers/vdpa/vdpa_user/iova_domain.c +89 -41
@@ -103,19 +103,38 @@ void vduse_domain_clear_map(struct vdusestatic int vduse_domain_map_bounce_page (struct vduse_iova_domain *domain,u64 iova,u64 size,u64 paddr) { -struct vduse_bounce_map *map; +struct vduse_bounce_map *map, *head_map; +struct page *tmp_page;u64 last = iova + size -1 ;while (iova <= last) { - map = &domain->bounce_maps[iova >>PAGE_SHIFT ]; +/* +* When PAGE_SIZE is larger than 4KB, multiple adjacent bounce_maps will +* point to the same memory page of PAGE_SIZE. Since bounce_maps originate +* from IO requests, we may not be able to guarantee that the orig_phys +* values of all IO requests within the same 64KB memory page are contiguous. +* Therefore, we need to store them separately. +* +* Bounce pages are allocated on demand. As a result, it may occur that +* multiple bounce pages corresponding to the same 64KB memory page attempt +* to allocate memory simultaneously, so we use cmpxchg to handle this +* concurrency. +*/ + map = &domain->bounce_maps[iova >>BOUNCE_MAP_SHIFT ];if (!map->bounce_page) { - map->bounce_page =alloc_page (GFP_ATOMIC ); -if (!map->bounce_page) -return -ENOMEM ; + head_map = &domain->bounce_maps[(iova &PAGE_MASK ) >>BOUNCE_MAP_SHIFT ]; +if (!head_map->bounce_page) { + tmp_page =alloc_page (GFP_ATOMIC ); +if (!tmp_page) +return -ENOMEM ; +if (cmpxchg (&head_map->bounce_page,NULL , tmp_page)) +__free_page (tmp_page); + } + map->bounce_page = head_map->bounce_page; } map->orig_phys = paddr; - paddr +=PAGE_SIZE ; - iova +=PAGE_SIZE ; + paddr +=BOUNCE_MAP_SIZE ; + iova +=BOUNCE_MAP_SIZE ; }return 0 ; }
@@ -127,12 +146,17 @@ static void vduse_domain_unmap_bounce_pau64 last = iova + size -1 ;while (iova <= last) { - map = &domain->bounce_maps[iova >>PAGE_SHIFT ]; + map = &domain->bounce_maps[iova >>BOUNCE_MAP_SHIFT ]; map->orig_phys =INVALID_PHYS_ADDR ; - iova +=PAGE_SIZE ; + iova +=BOUNCE_MAP_SIZE ; } } +static unsigned int offset_in_bounce_page (dma_addr_t addr) +{ +return (addr & ~BOUNCE_MAP_MASK ); +} +static void do_bounce (phys_addr_t orig,void *addr,size_t size,enum dma_data_direction dir) {
@@ -163,7 +187,7 @@ static void vduse_domain_bounce(struct v {struct vduse_bounce_map *map;struct page *page; -unsigned int offset; +unsigned int offset, head_offset;void *addr;size_t sz;
@@ -171,9 +195,10 @@ static void vduse_domain_bounce(struct vreturn ;while (size) { - map = &domain->bounce_maps[iova >>PAGE_SHIFT ]; - offset =offset_in_page (iova); - sz =min_t (size_t,PAGE_SIZE - offset, size); + map = &domain->bounce_maps[iova >>BOUNCE_MAP_SHIFT ]; + head_offset =offset_in_page (iova); + offset =offset_in_bounce_page (iova); + sz =min_t (size_t,BOUNCE_MAP_SIZE - offset, size);if (WARN_ON (!map->bounce_page || map->orig_phys ==INVALID_PHYS_ADDR ))
@@ -183,7 +208,7 @@ static void vduse_domain_bounce(struct v map->user_bounce_page : map->bounce_page; addr =kmap_local_page (page); -do_bounce (map->orig_phys + offset, addr + offset, sz, dir); +do_bounce (map->orig_phys + offset, addr + head_offset, sz, dir);kunmap_local (addr); size -= sz; iova += sz;
@@ -218,7 +243,7 @@ vduse_domain_get_bounce_page(struct vdusstruct page *page =NULL ;read_lock (&domain->bounce_lock); - map = &domain->bounce_maps[iova >>PAGE_SHIFT ]; + map = &domain->bounce_maps[iova >>BOUNCE_MAP_SHIFT ];if (domain->user_bounce_pages || !map->bounce_page) goto out;
@@ -236,7 +261,7 @@ vduse_domain_free_kernel_bounce_pages(ststruct vduse_bounce_map *map;unsigned long pfn, bounce_pfns; - bounce_pfns = domain->bounce_size >>PAGE_SHIFT ; + bounce_pfns = domain->bounce_size >>BOUNCE_MAP_SHIFT ;for (pfn =0 ; pfn < bounce_pfns; pfn++) { map = &domain->bounce_maps[pfn];
@@ -246,7 +271,8 @@ vduse_domain_free_kernel_bounce_pages(stif (!map->bounce_page)continue ; -__free_page (map->bounce_page); +if (!((pfn <<BOUNCE_MAP_SHIFT ) & ~PAGE_MASK )) +__free_page (map->bounce_page); map->bounce_page =NULL ; } }
@@ -254,8 +280,12 @@ vduse_domain_free_kernel_bounce_pages(stint vduse_domain_add_user_bounce_pages (struct vduse_iova_domain *domain,struct page **pages,int count) { -struct vduse_bounce_map *map; -int i, ret; +struct vduse_bounce_map *map, *head_map; +int i, j, ret; +int inner_pages =PAGE_SIZE /BOUNCE_MAP_SIZE ; +int bounce_pfns = domain->bounce_size >>BOUNCE_MAP_SHIFT ; +struct page *head_page =NULL ; +bool need_copy;/* Now we don't support partial mapping */ if (count != (domain->bounce_size >>PAGE_SHIFT ))
@@ -267,16 +297,23 @@ int vduse_domain_add_user_bounce_pages(s goto out;for (i =0 ; i < count; i++) { - map = &domain->bounce_maps[i]; -if (map->bounce_page) { + need_copy = false; + head_map = &domain->bounce_maps[(i * inner_pages)]; + head_page = head_map->bounce_page; +for (j =0 ; j < inner_pages; j++) { +if ((i * inner_pages + j) >= bounce_pfns) +break ; + map = &domain->bounce_maps[(i * inner_pages + j)];/* Copy kernel page to user page if it's in use */ -if (map->orig_phys !=INVALID_PHYS_ADDR ) -memcpy_to_page (pages[i],0 , -page_address (map->bounce_page), -PAGE_SIZE ); +if ((head_page) && (map->orig_phys !=INVALID_PHYS_ADDR )) + need_copy = true; + map->user_bounce_page = pages[i]; } - map->user_bounce_page = pages[i];get_page (pages[i]); +if ((head_page) && (need_copy)) +memcpy_to_page (pages[i],0 , +page_address (head_page), +PAGE_SIZE ); } domain->user_bounce_pages = true; ret =0 ;
@@ -288,8 +325,12 @@ out:void vduse_domain_remove_user_bounce_pages (struct vduse_iova_domain *domain) { -struct vduse_bounce_map *map; -unsigned long i, count; +struct vduse_bounce_map *map, *head_map; +unsigned long i, j, count; +int inner_pages =PAGE_SIZE /BOUNCE_MAP_SIZE ; +int bounce_pfns = domain->bounce_size >>BOUNCE_MAP_SHIFT ; +struct page *head_page =NULL ; +bool need_copy;write_lock (&domain->bounce_lock);if (!domain->user_bounce_pages)
@@ -297,20 +338,27 @@ void vduse_domain_remove_user_bounce_pag count = domain->bounce_size >>PAGE_SHIFT ;for (i =0 ; i < count; i++) { -struct page *page =NULL ; - - map = &domain->bounce_maps[i]; -if (WARN_ON (!map->user_bounce_page)) + need_copy = false; + head_map = &domain->bounce_maps[(i * inner_pages)]; +if (WARN_ON (!head_map->user_bounce_page))continue ; + head_page = head_map->user_bounce_page; -/* Copy user page to kernel page if it's in use */ -if (map->orig_phys !=INVALID_PHYS_ADDR ) { - page = map->bounce_page; -memcpy_from_page (page_address (page), - map->user_bounce_page,0 ,PAGE_SIZE ); +for (j =0 ; j < inner_pages; j++) { +if ((i * inner_pages + j) >= bounce_pfns) +break ; + map = &domain->bounce_maps[(i * inner_pages + j)]; +if (WARN_ON (!map->user_bounce_page)) +continue ; +/* Copy user page to kernel page if it's in use */ +if ((map->orig_phys !=INVALID_PHYS_ADDR ) && (head_map->bounce_page)) + need_copy = true; + map->user_bounce_page =NULL ; } -put_page (map->user_bounce_page); - map->user_bounce_page =NULL ; +if (need_copy) +memcpy_from_page (page_address (head_map->bounce_page), + head_page,0 ,PAGE_SIZE ); +put_page (head_page); } domain->user_bounce_pages = false; out:
@@ -581,7 +629,7 @@ vduse_domain_create(unsigned long iova_lunsigned long pfn, bounce_pfns;int ret; - bounce_pfns =PAGE_ALIGN (bounce_size) >>PAGE_SHIFT ; + bounce_pfns =PAGE_ALIGN (bounce_size) >>BOUNCE_MAP_SHIFT ;if (iova_limit <= bounce_size)return NULL ;
@@ -613,7 +661,7 @@ vduse_domain_create(unsigned long iova_lrwlock_init (&domain->bounce_lock);spin_lock_init (&domain->iotlb_lock);init_iova_domain (&domain->stream_iovad, -PAGE_SIZE ,IOVA_START_PFN ); +BOUNCE_MAP_SIZE ,IOVA_START_PFN ); ret =iova_domain_init_rcaches (&domain->stream_iovad);if (ret) goto err_iovad_stream;
drivers/vdpa/vdpa_user/iova_domain.h +5 -0
@@ -19,6 +19,11 @@#define INVALID_PHYS_ADDR (~(phys_addr_t)0) +#define BOUNCE_MAP_SHIFT 12 +#define BOUNCE_MAP_SIZE (1 << BOUNCE_MAP_SHIFT) +#define BOUNCE_MAP_MASK (~(BOUNCE_MAP_SIZE - 1)) +#define BOUNCE_MAP_ALIGN (addr) (((addr) + BOUNCE_MAP_SIZE - 1) & ~(BOUNCE_MAP_SIZE - 1)) +struct vduse_bounce_map {struct page *bounce_page;struct page *user_bounce_page;
Greg Kroah-Hartman
maintainerPATCH 490/602 vduse: remove unused vaddr parameter of vduse_domain_free_coherent
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eugenio Pérez <[email protected]>
[ Upstream commit 766e1749c0ef6a09651be9b8a8283d508c322b58 ]
We will modify the function in next patches so let's clean it first.
Message-Id: <[email protected]>
Stable-dep-of: 9c1523803445 ("VDUSE: avoid leaking information to userspace")
--- drivers/vdpa/vdpa_user/iova_domain.c | 3 +-- drivers/vdpa/vdpa_user/iova_domain.h | 3 +-- drivers/vdpa/vdpa_user/vduse_dev.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-)
drivers/vdpa/vdpa_user/iova_domain.c +1 -2
@@ -528,8 +528,7 @@ err: }void vduse_domain_free_coherent (struct vduse_iova_domain *domain,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs) +dma_addr_t dma_addr,unsigned long attrs) {struct iova_domain *iovad = &domain->consistent_iovad;struct vhost_iotlb_map *map;
drivers/vdpa/vdpa_user/iova_domain.h +1 -2
@@ -72,8 +72,7 @@ void *vduse_domain_alloc_coherent(struct gfp_t flag, unsigned long attrs);void vduse_domain_free_coherent (struct vduse_iova_domain *domain,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs); +dma_addr_t dma_addr,unsigned long attrs);void vduse_domain_reset_bounce_map (struct vduse_iova_domain *domain);
drivers/vdpa/vdpa_user/vduse_dev.c +1 -1
@@ -904,7 +904,7 @@ static void vduse_dev_free_coherent(strustruct vduse_dev *vdev =dev_to_vduse (dev);struct vduse_iova_domain *domain = vdev->domain; -vduse_domain_free_coherent (domain, size, vaddr, dma_addr, attrs); +vduse_domain_free_coherent (domain, size, dma_addr, attrs); }static size_t vduse_dev_max_mapping_size (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 491/602 vduse: take out allocations from vduse_dev_alloc_coherent
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eugenio Pérez <[email protected]>
[ Upstream commit 489d76520612abf9a4ede4344349105406c91a73 ]
The function vduse_dev_alloc_coherent will be called under rwlock in next patches. Make it out of the lock to avoid increasing its fail rate.
Message-Id: <[email protected]>
Stable-dep-of: 9c1523803445 ("VDUSE: avoid leaking information to userspace")
--- drivers/vdpa/vdpa_user/iova_domain.c | 24 +++++++----------------- drivers/vdpa/vdpa_user/iova_domain.h | 5 ++--- drivers/vdpa/vdpa_user/vduse_dev.c | 14 ++++++++++---- 3 files changed, 19 insertions(+), 24 deletions(-)
drivers/vdpa/vdpa_user/iova_domain.c +7 -17
@@ -493,17 +493,15 @@ void vduse_domain_unmap_page(struct vdusvduse_domain_free_iova (iovad, dma_addr, size); } -void *vduse_domain_alloc_coherent (struct vduse_iova_domain *domain, -size_t size,dma_addr_t *dma_addr, -gfp_t flag,unsigned long attrs) +dma_addr_t vduse_domain_alloc_coherent (struct vduse_iova_domain *domain, +size_t size,void *orig) {struct iova_domain *iovad = &domain->consistent_iovad;unsigned long limit = domain->iova_limit;dma_addr_t iova =vduse_domain_alloc_iova (iovad, size, limit); -void *orig =alloc_pages_exact (size, flag); -if (!iova || !orig) - goto err; +if (!iova) +return DMA_MAPPING_ERROR ;spin_lock (&domain->iotlb_lock); if (vduse_iotlb_add_range(domain, (u64)iova, (u64)iova + size - 1,
@@ -514,17 +512,12 @@ void *vduse_domain_alloc_coherent(struct }spin_unlock (&domain->iotlb_lock); - *dma_addr = iova; +return iova; -return orig; err: - *dma_addr =DMA_MAPPING_ERROR ; -if (orig) -free_pages_exact (orig, size); -if (iova) -vduse_domain_free_iova (iovad, iova, size); +vduse_domain_free_iova (iovad, iova, size); -return NULL ; +return DMA_MAPPING_ERROR ; } void vduse_domain_free_coherent(struct vduse_iova_domain *domain, size_t size,
@@ -533,7 +526,6 @@ void vduse_domain_free_coherent(struct vstruct iova_domain *iovad = &domain->consistent_iovad;struct vhost_iotlb_map *map;struct vdpa_map_file *map_file; -phys_addr_t pa;spin_lock (&domain->iotlb_lock); map = vhost_iotlb_itree_first(domain->iotlb, (u64)dma_addr,
@@ -545,12 +537,10 @@ void vduse_domain_free_coherent(struct v map_file = (struct vdpa_map_file *)map->opaque;fput (map_file->file);kfree (map_file); - pa = map->addr;vhost_iotlb_map_free (domain->iotlb, map);spin_unlock (&domain->iotlb_lock);vduse_domain_free_iova (iovad, dma_addr, size); -free_pages_exact (phys_to_virt (pa), size); }static vm_fault_t vduse_domain_mmap_fault (struct vm_fault *vmf)
drivers/vdpa/vdpa_user/iova_domain.h +2 -3
@@ -67,9 +67,8 @@ void vduse_domain_unmap_page(struct vdus dma_addr_t dma_addr, size_t size, enum dma_data_direction dir, unsigned long attrs); -void *vduse_domain_alloc_coherent (struct vduse_iova_domain *domain, -size_t size,dma_addr_t *dma_addr, -gfp_t flag,unsigned long attrs); +dma_addr_t vduse_domain_alloc_coherent (struct vduse_iova_domain *domain, +size_t size,void *orig);void vduse_domain_free_coherent (struct vduse_iova_domain *domain,size_t size,dma_addr_t dma_addr,unsigned long attrs);
drivers/vdpa/vdpa_user/vduse_dev.c +10 -4
@@ -883,18 +883,23 @@ static void *vduse_dev_alloc_coherent(st {struct vduse_dev *vdev =dev_to_vduse (dev);struct vduse_iova_domain *domain = vdev->domain; -unsigned long iova;void *addr; *dma_addr =DMA_MAPPING_ERROR ; - addr =vduse_domain_alloc_coherent (domain, size, - (dma_addr_t *)&iova, flag, attrs); + + addr =alloc_pages_exact (size, flag);if (!addr)return NULL ; - *dma_addr = (dma_addr_t )iova; + *dma_addr =vduse_domain_alloc_coherent (domain, size, addr); +if (*dma_addr ==DMA_MAPPING_ERROR ) + goto err;return addr; + +err: +free_pages_exact (addr, size); +return NULL ; } static void vduse_dev_free_coherent(struct device *dev, size_t size,
@@ -905,6 +910,7 @@ static void vduse_dev_free_coherent(strustruct vduse_iova_domain *domain = vdev->domain;vduse_domain_free_coherent (domain, size, dma_addr, attrs); +free_pages_exact (vaddr, size); }static size_t vduse_dev_max_mapping_size (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 492/602 VDUSE: avoid leaking information to userspace
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Wang <[email protected]>
[ Upstream commit 9c1523803445ee0348f62b77793266dd981596e0 ]
The bounceing is not necessarily page aligned, so current VDUSE can leak kernel information through mapping bounce pages to userspace. Allocate bounce pages with __GFP_ZERO to avoid leaking information to userspace.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_user/iova_domain.c | 2 +- drivers/vdpa/vdpa_user/vduse_dev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/vdpa/vdpa_user/iova_domain.c +1 -1
@@ -124,7 +124,7 @@ static int vduse_domain_map_bounce_page(if (!map->bounce_page) { head_map = &domain->bounce_maps[(iova &PAGE_MASK ) >>BOUNCE_MAP_SHIFT ];if (!head_map->bounce_page) { - tmp_page =alloc_page (GFP_ATOMIC ); + tmp_page =alloc_page (GFP_ATOMIC | __GFP_ZERO);if (!tmp_page)return -ENOMEM ;if (cmpxchg (&head_map->bounce_page,NULL , tmp_page))
drivers/vdpa/vdpa_user/vduse_dev.c +1 -1
@@ -887,7 +887,7 @@ static void *vduse_dev_alloc_coherent(st *dma_addr =DMA_MAPPING_ERROR ; - addr =alloc_pages_exact (size, flag); + addr =alloc_pages_exact (size, flag | __GFP_ZERO);if (!addr)return NULL ;
Greg Kroah-Hartman
maintainerPATCH 493/602 octeontx2: Annotate mmio regions as __iomem
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Subbaraya Sundeep <[email protected]>
[ Upstream commit d0976b43956ee8c8bd093223df9115bfcf63dfe5 ]
This patch removes unnecessary typecasts by marking the mbox_regions array as __iomem since it is used to store pointers to memory-mapped I/O (MMIO) regions. Also simplified the call to readq() in PF driver by removing redundant type casts.
Stable-dep-of: 0b352f04b9be ("octeontx2-vf: clear stale mailbox IRQ state before request_irq()")
--- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 12 ++++++------ drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +6 -6
@@ -2401,7 +2401,7 @@ static inline void rvu_afvf_mbox_up_hand__rvu_mbox_up_handler (mwork,TYPE_AFVF ); } -static int rvu_get_mbox_regions (struct rvu *rvu,void **mbox_addr, +static int rvu_get_mbox_regions (struct rvu *rvu,void __iomem **mbox_addr,int num,int type,unsigned long *pf_bmap) {struct rvu_hwinfo *hw = rvu->hw;
@@ -2426,7 +2426,7 @@ static int rvu_get_mbox_regions(struct r bar4 =rvupf_read64 (rvu,RVU_PF_VF_BAR4_ADDR ); bar4 += region *MBOX_SIZE ; } - mbox_addr[region] = (void *)ioremap_wc (bar4,MBOX_SIZE ); + mbox_addr[region] =ioremap_wc (bar4,MBOX_SIZE );if (!mbox_addr[region]) goto error; }
@@ -2449,7 +2449,7 @@ static int rvu_get_mbox_regions(struct r RVU_AF_PF_BAR4_ADDR); bar4 += region *MBOX_SIZE ; } - mbox_addr[region] = (void *)ioremap_wc (bar4,MBOX_SIZE ); + mbox_addr[region] =ioremap_wc (bar4,MBOX_SIZE );if (!mbox_addr[region]) goto error; }
@@ -2457,7 +2457,7 @@ static int rvu_get_mbox_regions(struct r error:while (region--) -iounmap ((void __iomem *)mbox_addr[region]); +iounmap (mbox_addr[region]);return -ENOMEM ; }
@@ -2467,10 +2467,10 @@ static int rvu_mbox_init(struct rvu *rvu void (mbox_up_handler)(struct work_struct *)) {int err = -EINVAL , i, dir, dir_up; +void __iomem **mbox_regions;void __iomem *reg_base;struct rvu_work *mwork;unsigned long *pf_bmap; -void **mbox_regions;const char *name;u64 cfg;
@@ -2493,7 +2493,7 @@ static int rvu_mbox_init(struct rvu *rvumutex_init (&rvu->mbox_lock); - mbox_regions =kcalloc (num,sizeof (void *),GFP_KERNEL ); + mbox_regions =kcalloc (num,sizeof (void __iomem *),GFP_KERNEL );if (!mbox_regions) { err = -ENOMEM ; goto free_bitmap;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -2
@@ -593,8 +593,7 @@ static int otx2_pfvf_mbox_init(struct ot base =pci_resource_start (pf->pdev,PCI_MBOX_BAR_NUM ) +MBOX_SIZE ; else - base =readq ((void __iomem *)((u64 )pf->reg_base + -RVU_PF_VF_BAR4_ADDR )); + base =readq (pf->reg_base +RVU_PF_VF_BAR4_ADDR ); hwbase =ioremap_wc (base,MBOX_SIZE * pf->total_vfs);if (!hwbase) {
Greg Kroah-Hartman
maintainerPATCH 494/602 octeontx2-vf: clear stale mailbox IRQ state before request_irq()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 0b352f04b9be2c83c0240aa6dae7257fefa90464 ]
otx2vf_register_mbox_intr() currently installs the VF mailbox IRQ handler before clearing stale mailbox interrupt state. The code then says that local interrupt bits should be cleared first to avoid spurious interrupts, but that clear still happens only after request_irq() has already made the handler reachable.
A running system can reach this during VF mailbox interrupt registration while stale or latched RVU_VF_INT state is still present. If delivery happens in the request_irq()-to-clear window, otx2vf_vfaf_mbox_intr_handler() can run before local quiesce and touch the same vf->mbox and vf->mbox_wq carrier that probe and teardown later reuse or destroy.
Move the stale mailbox interrupt clear ahead of request_irq(), but keep interrupt enabling after the handler is installed. This closes the pre-clear early-IRQ window without creating a new enable-before-handler window.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +8 -5
@@ -245,9 +245,15 @@ static int otx2vf_register_mbox_intr(str {struct otx2_hw *hw = &vf->hw;struct msg_req *req; +u64 mbox_int_mask;char *irq_name;int err; + mbox_int_mask =BIT_ULL (0 ); + +/* Clear stale mailbox interrupt state before installing the handler. */ +otx2_write64 (vf,RVU_VF_INT , mbox_int_mask); +/* Register mailbox interrupt handler */ irq_name = &hw->irq_name[RVU_VF_INT_VEC_MBOX *NAME_SIZE ];snprintf (irq_name,NAME_SIZE ,"RVUVFAF Mbox" );
@@ -259,11 +265,8 @@ static int otx2vf_register_mbox_intr(strreturn err; } -/* Enable mailbox interrupt for msgs coming from PF. -* First clear to avoid spurious interrupts, if any. -*/ -otx2_write64 (vf,RVU_VF_INT ,BIT_ULL (0 )); -otx2_write64 (vf,RVU_VF_INT_ENA_W1S ,BIT_ULL (0 )); +/* Enable mailbox interrupt for msgs coming from PF. */ +otx2_write64 (vf,RVU_VF_INT_ENA_W1S , mbox_int_mask);if (!probe_pf)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 495/602 octeontx2-pf: clear stale mailbox IRQ state before request_irq()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit f918554fb7246e89b98ef90abe80801f038258b3 ]
otx2_register_mbox_intr() currently installs the PF mailbox IRQ handler before clearing stale mailbox interrupt state. The function itself then comments that the local interrupt bits must be cleared first to avoid spurious interrupts, but that clear happens only after request_irq() has already exposed the handler to irq delivery.
A running system can reach this during PF mailbox interrupt registration while stale or latched RVU_PF_INT state is still present. If delivery happens in the request_irq()-to-clear window, otx2_pfaf_mbox_intr_handler() can run before local quiesce and touch the same pf->mbox and pf->mbox_wq carrier that probe and teardown later reuse or destroy.
Move the stale mailbox interrupt clear ahead of request_irq(), but keep interrupt enabling after the handler is installed. This closes the pre-clear early-IRQ window without creating a new enable-before-handler window.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -4
@@ -1023,6 +1023,9 @@ static int otx2_register_mbox_intr(strucchar *irq_name;int err; +/* Clear stale mailbox interrupt state before installing the handler. */ +otx2_write64 (pf,RVU_PF_INT ,BIT_ULL (0 )); +/* Register mailbox interrupt handler */ irq_name = &hw->irq_name[RVU_PF_INT_VEC_AFPF_MBOX *NAME_SIZE ];snprintf (irq_name,NAME_SIZE ,"RVUPFAF Mbox" );
@@ -1034,10 +1037,7 @@ static int otx2_register_mbox_intr(strucreturn err; } -/* Enable mailbox interrupt for msgs coming from AF. -* First clear to avoid spurious interrupts, if any. -*/ -otx2_write64 (pf,RVU_PF_INT ,BIT_ULL (0 )); +/* Enable mailbox interrupt for msgs coming from AF. */ otx2_write64 (pf,RVU_PF_INT_ENA_W1S ,BIT_ULL (0 ));if (!probe_af)
Greg Kroah-Hartman
maintainerPATCH 496/602 arm64: dts: qcom: correct RBR opp entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Baryshkov <[email protected]>
[ Upstream commit a5c21b9bd5f531e50141b0484faabb707b92f1e2 ]
DisplayPort Reduced Bit Rate uses link rate of 1.62 Gbps, the main link clock should be 162 MHz. Having the incorrect frequency (160 MHz) in the OPP table will result in selecting wrong link frequency. Correct the entry in the OPP table.
Stable-dep-of: c17e22094667 ("arm64: dts: qcom: hamoa: Fix OPP tables for all DisplayPort controllers")
--- arch/arm64/boot/dts/qcom/sc7180.dtsi | 4 ++-- arch/arm64/boot/dts/qcom/sc7280.dtsi | 8 ++++---- arch/arm64/boot/dts/qcom/sc8180x.dtsi | 12 ++++++------ arch/arm64/boot/dts/qcom/sc8280xp.dtsi | 32 ++++++++++++++++---------------- arch/arm64/boot/dts/qcom/sm6350.dtsi | 4 ++-- arch/arm64/boot/dts/qcom/sm8150.dtsi | 4 ++-- arch/arm64/boot/dts/qcom/sm8250.dtsi | 4 ++-- arch/arm64/boot/dts/qcom/sm8350.dtsi | 4 ++-- arch/arm64/boot/dts/qcom/sm8450.dtsi | 4 ++-- arch/arm64/boot/dts/qcom/x1e80100.dtsi | 16 ++++++++-------- 10 files changed, 46 insertions(+), 46 deletions(-)
arch/arm64/boot/dts/qcom/sc7180.dtsi +2 -2
@@ -3410,8 +3410,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sc7280.dtsi +4 -4
@@ -4723,8 +4723,8 @@ edp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -4820,8 +4820,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sc8180x.dtsi +6 -6
@@ -3269,8 +3269,8 @@ dp0_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -3347,8 +3347,8 @@ dp1_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -3415,8 +3415,8 @@ edp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sc8280xp.dtsi +16 -16
@@ -4259,8 +4259,8 @@ mdss0_dp0_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -4337,8 +4337,8 @@ mdss0_dp1_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -4409,8 +4409,8 @@ mdss0_dp2_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -4481,8 +4481,8 @@ mdss0_dp3_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -5547,8 +5547,8 @@ mdss1_dp0_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -5619,8 +5619,8 @@ mdss1_dp1_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -5691,8 +5691,8 @@ mdss1_dp2_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -5763,8 +5763,8 @@ mdss1_dp3_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sm6350.dtsi +2 -2
@@ -2222,8 +2222,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sm8150.dtsi +2 -2
@@ -3932,8 +3932,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sm8250.dtsi +2 -2
@@ -4818,8 +4818,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sm8350.dtsi +2 -2
@@ -2909,8 +2909,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/sm8450.dtsi +2 -2
@@ -3223,8 +3223,8 @@ dp_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
arch/arm64/boot/dts/qcom/x1e80100.dtsi +8 -8
@@ -4758,8 +4758,8 @@ mdss_dp0_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -4841,8 +4841,8 @@ mdss_dp1_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -4923,8 +4923,8 @@ mdss_dp2_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
@@ -5002,8 +5002,8 @@ mdss_dp3_opp_table: opp-table { compatible = "operating-points-v2"; - opp-160000000 { - opp-hz = /bits/ 64 <160000000>; + opp-162000000 { + opp-hz = /bits/ 64 <162000000>; required-opps = <&rpmhpd_opp_low_svs>; };
Greg Kroah-Hartman
maintainerPATCH 497/602 arm64: dts: qcom: hamoa: Fix OPP tables for all DisplayPort controllers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit c17e220946675232d383620ed9cff6685735ec48 ]
According to internal documentation, the corners specific for each rate from the DP link clock are:
- LOWSVS_D1 -> 19.2 MHz
- LOWSVS -> 270 MHz - SVS -> 540 MHz (594 MHz in case of DP3) - SVS_L1 -> 594 MHz - NOM -> 810 MHz - NOM_L1 -> 810 MHz - TURBO -> 810 MHz
So fix all tables for each of the four controllers according to the documentation, but since DP0 through DP2 have the same entries in their tables, lets drop the DP1 and DP2 and have all of them share the DP0 table instead. However keep a separate table for the DP3 as it is different for the SVS, compared to the rest of the controllers.
The 19.2 MHz @ LOWSVS_D1 isn't needed as it's not an actual working frequency and the controller will never select it. So remove it.
--- arch/arm64/boot/dts/qcom/x1e80100.dtsi | 77 +++++---------------------------- 1 file changed, 12 insertions(+), 65 deletions(-)
arch/arm64/boot/dts/qcom/x1e80100.dtsi +12 -65
@@ -4758,18 +4758,18 @@ mdss_dp0_opp_table: opp-table { compatible = "operating-points-v2"; - opp-162000000 { - opp-hz = /bits/ 64 <162000000>; - required-opps = <&rpmhpd_opp_low_svs>; - }; - opp-270000000 { opp-hz = /bits/ 64 <270000000>; - required-opps = <&rpmhpd_opp_svs>; + required-opps = <&rpmhpd_opp_low_svs>; }; opp-540000000 { opp-hz = /bits/ 64 <540000000>; + required-opps = <&rpmhpd_opp_svs>; + }; + + opp-594000000 { + opp-hz = /bits/ 64 <594000000>; required-opps = <&rpmhpd_opp_svs_l1>; };
@@ -4806,7 +4806,7 @@ assigned-clock-parents = <&usb_1_ss1_qmpphy QMP_USB43DP_DP_LINK_CLK>, <&usb_1_ss1_qmpphy QMP_USB43DP_DP_VCO_DIV_CLK>; - operating-points-v2 = <&mdss_dp1_opp_table>; + operating-points-v2 = <&mdss_dp0_opp_table>; power-domains = <&rpmhpd RPMHPD_MMCX>;
@@ -4837,30 +4837,6 @@ }; }; }; - - mdss_dp1_opp_table: opp-table { - compatible = "operating-points-v2"; - - opp-162000000 { - opp-hz = /bits/ 64 <162000000>; - required-opps = <&rpmhpd_opp_low_svs>; - }; - - opp-270000000 { - opp-hz = /bits/ 64 <270000000>; - required-opps = <&rpmhpd_opp_svs>; - }; - - opp-540000000 { - opp-hz = /bits/ 64 <540000000>; - required-opps = <&rpmhpd_opp_svs_l1>; - }; - - opp-810000000 { - opp-hz = /bits/ 64 <810000000>; - required-opps = <&rpmhpd_opp_nom>; - }; - }; }; mdss_dp2: displayport-controller@ae9a000 {
@@ -4889,7 +4865,7 @@ assigned-clock-parents = <&usb_1_ss2_qmpphy QMP_USB43DP_DP_LINK_CLK>, <&usb_1_ss2_qmpphy QMP_USB43DP_DP_VCO_DIV_CLK>; - operating-points-v2 = <&mdss_dp2_opp_table>; + operating-points-v2 = <&mdss_dp0_opp_table>; power-domains = <&rpmhpd RPMHPD_MMCX>;
@@ -4919,30 +4895,6 @@ }; }; }; - - mdss_dp2_opp_table: opp-table { - compatible = "operating-points-v2"; - - opp-162000000 { - opp-hz = /bits/ 64 <162000000>; - required-opps = <&rpmhpd_opp_low_svs>; - }; - - opp-270000000 { - opp-hz = /bits/ 64 <270000000>; - required-opps = <&rpmhpd_opp_svs>; - }; - - opp-540000000 { - opp-hz = /bits/ 64 <540000000>; - required-opps = <&rpmhpd_opp_svs_l1>; - }; - - opp-810000000 { - opp-hz = /bits/ 64 <810000000>; - required-opps = <&rpmhpd_opp_nom>; - }; - }; }; mdss_dp3: displayport-controller@aea0000 {
@@ -5002,19 +4954,14 @@ mdss_dp3_opp_table: opp-table { compatible = "operating-points-v2"; - opp-162000000 { - opp-hz = /bits/ 64 <162000000>; - required-opps = <&rpmhpd_opp_low_svs>; - }; - opp-270000000 { opp-hz = /bits/ 64 <270000000>; - required-opps = <&rpmhpd_opp_svs>; + required-opps = <&rpmhpd_opp_low_svs>; }; - opp-540000000 { - opp-hz = /bits/ 64 <540000000>; - required-opps = <&rpmhpd_opp_svs_l1>; + opp-594000000 { + opp-hz = /bits/ 64 <594000000>; + required-opps = <&rpmhpd_opp_svs>; }; opp-810000000 {
Greg Kroah-Hartman
maintainerPATCH 498/602 ASoC: mediatek: mt8192-afe-pcm: Simplify probe() with local dev variable
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tang Bin <[email protected]>
[ Upstream commit 01981565c764c554cc96e2d30a71c42975171416 ]
Simplify the function mt8192_afe_pcm_dev_probe() by using local 'dev' instead of '&pdev->dev'.
Stable-dep-of: e24d5dde56a5 ("ASoC: mediatek: mt8192: Check runtime resume during probe")
--- sound/soc/mediatek/mt8192/mt8192-afe-pcm.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
sound/soc/mediatek/mt8192/mt8192-afe-pcm.c +9 -10
@@ -2164,27 +2164,26 @@ static int mt8192_afe_pcm_dev_probe(stru {struct mtk_base_afe *afe;struct mt8192_afe_private *afe_priv; -struct device *dev; +struct device *dev = &pdev->dev;struct reset_control *rstc;int i, ret, irq_id; - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (34 )); + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (34 ));if (ret)return ret; - afe =devm_kzalloc (&pdev->dev,sizeof (*afe),GFP_KERNEL ); + afe =devm_kzalloc (dev,sizeof (*afe),GFP_KERNEL );if (!afe)return -ENOMEM ;platform_set_drvdata (pdev, afe); - afe->platform_priv =devm_kzalloc (&pdev->dev,sizeof (*afe_priv), + afe->platform_priv =devm_kzalloc (dev,sizeof (*afe_priv),GFP_KERNEL );if (!afe->platform_priv)return -ENOMEM ; afe_priv = afe->platform_priv; - afe->dev = &pdev->dev; - dev = afe->dev; + afe->dev = dev; ret =of_reserved_mem_device_init (dev);if (ret) {
@@ -2212,7 +2211,7 @@ static int mt8192_afe_pcm_dev_probe(struif (ret)return dev_err_probe (dev, ret,"failed to trigger audio reset\n" ); - ret =devm_pm_runtime_enable (&pdev->dev); + ret =devm_pm_runtime_enable (dev);if (ret)return ret;
@@ -2228,13 +2227,13 @@ static int mt8192_afe_pcm_dev_probe(stru/* enable clock for regcache get default value from hw */ afe_priv->pm_runtime_bypass_reg_ctl = true; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_get_sync (dev); ret =regmap_reinit_cache (afe->regmap, &mt8192_afe_regmap_config);if (ret)return dev_err_probe (dev, ret,"regmap_reinit_cache fail\n" ); -pm_runtime_put_sync (&pdev->dev); +pm_runtime_put_sync (dev); afe_priv->pm_runtime_bypass_reg_ctl = false;regcache_cache_only (afe->regmap, true);
@@ -2301,7 +2300,7 @@ static int mt8192_afe_pcm_dev_probe(stru afe->runtime_suspend = mt8192_afe_runtime_suspend;/* register platform */ - ret =devm_snd_soc_register_component (&pdev->dev, + ret =devm_snd_soc_register_component (dev, &mtk_afe_pcm_platform, afe->dai_drivers, afe->num_dai_drivers);
Greg Kroah-Hartman
maintainerPATCH 499/602 ASoC: mediatek: mt8192: Check runtime resume during probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
[ Upstream commit e24d5dde56a50946020b134fa8448869093db76a ]
The MT8192 AFE probe enables runtime PM temporarily while reinitializing the regmap cache from hardware, but it uses pm_runtime_get_sync() without checking the return value. If runtime resume fails, probe keeps going without the device necessarily being accessible, and pm_runtime_get_sync() may leave the PM usage count incremented.
The regmap_reinit_cache() failure path also returns before dropping the temporary PM reference and before clearing pm_runtime_bypass_reg_ctl.
Use pm_runtime_resume_and_get() so resume failures do not leak a usage count, and clear the temporary bypass flag after dropping the probe PM reference on all regmap_reinit_cache() outcomes.
--- sound/soc/mediatek/mt8192/mt8192-afe-pcm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
sound/soc/mediatek/mt8192/mt8192-afe-pcm.c +8 -4
@@ -2227,15 +2227,19 @@ static int mt8192_afe_pcm_dev_probe(stru/* enable clock for regcache get default value from hw */ afe_priv->pm_runtime_bypass_reg_ctl = true; -pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev); +if (ret) { + afe_priv->pm_runtime_bypass_reg_ctl = false; +return dev_err_probe (dev, ret,"failed to resume device\n" ); + } ret =regmap_reinit_cache (afe->regmap, &mt8192_afe_regmap_config); -if (ret) -return dev_err_probe (dev, ret,"regmap_reinit_cache fail\n" ); -pm_runtime_put_sync (dev); afe_priv->pm_runtime_bypass_reg_ctl = false; +if (ret) +return dev_err_probe (dev, ret,"regmap_reinit_cache fail\n" ); +regcache_cache_only (afe->regmap, true);regcache_mark_dirty (afe->regmap);
Greg Kroah-Hartman
maintainerPATCH 500/602 ASoC: mediatek: mt8183-afe-pcm: Shorten memif_data table using macros
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit 91c2685430f217ae8f2866e4372948eaf123b5c4 ]
The memif_data table describes all the supported PCM channels for the audio frontend. Most of the fields are either the same or can be derived from the interface's name. This results in a very long table (in source code) that can be shortened with macros.
Do just that. Some "convenience" macros were added to cover non-existent register fields that would otherwise require multiple layers of macros to handle.
Stable-dep-of: f0334fbfd107 ("ASoC: mediatek: mt8183: Check runtime resume during probe")
--- sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 243 ++++++----------------------- 1 file changed, 54 insertions(+), 189 deletions(-)
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +54 -189
@@ -425,196 +425,61 @@ static const struct snd_soc_component_dr .name = "mt8183-afe-pcm-dai", }; +#define MT8183_MEMIF_BASE (_id, _en_reg, _fs_reg, _mono_reg) \ + [MT8183_MEMIF_##_id] = { \ + .name = #_id, \ + .id = MT8183_MEMIF_##_id, \ + .reg_ofs_base = AFE_##_id##_BASE, \ + .reg_ofs_cur = AFE_##_id##_CUR, \ + .reg_ofs_end = AFE_##_id##_END, \ + .fs_reg = (_fs_reg), \ + .fs_shift = _id##_MODE_SFT, \ + .fs_maskbit = _id##_MODE_MASK, \ + .mono_reg = (_mono_reg), \ + .mono_shift = _id##_DATA_SFT, \ + .enable_reg = (_en_reg), \ + .enable_shift = _id##_ON_SFT, \ + .hd_reg = AFE_MEMIF_HD_MODE, \ + .hd_align_reg = AFE_MEMIF_HDALIGN, \ + .hd_shift = _id##_HD_SFT, \ + .hd_align_mshift = _id##_HD_ALIGN_SFT, \ + .agent_disable_reg = -1, \ + .agent_disable_shift = -1, \ + .msb_reg = -1, \ + .msb_shift = -1, \ + } + +#define MT8183_MEMIF (_id, _fs_reg, _mono_reg) \ + MT8183_MEMIF_BASE(_id, AFE_DAC_CON0, _fs_reg, _mono_reg) + +/* For convenience with macros: missing register fields */ +#define MOD_DAI_DATA_SFT -1 +#define HDMI_MODE_SFT -1 +#define HDMI_MODE_MASK -1 +#define HDMI_DATA_SFT -1 +#define HDMI_ON_SFT -1 + +/* For convenience with macros: register name differences */ +#define AFE_VUL12_BASE AFE_VUL_D2_BASE +#define AFE_VUL12_CUR AFE_VUL_D2_CUR +#define AFE_VUL12_END AFE_VUL_D2_END +#define AWB2_HD_ALIGN_SFT AWB2_ALIGN_SFT +#define VUL12_DATA_SFT VUL12_MONO_SFT +#define AFE_HDMI_BASE AFE_HDMI_OUT_BASE +#define AFE_HDMI_CUR AFE_HDMI_OUT_CUR +#define AFE_HDMI_END AFE_HDMI_OUT_END +static const struct mtk_base_memif_data memif_data[MT8183_MEMIF_NUM ] = { - [MT8183_MEMIF_DL1 ] = { - .name ="DL1" , - .id =MT8183_MEMIF_DL1 , - .reg_ofs_base =AFE_DL1_BASE , - .reg_ofs_cur =AFE_DL1_CUR , - .fs_reg =AFE_DAC_CON1 , - .fs_shift =DL1_MODE_SFT , - .fs_maskbit =DL1_MODE_MASK , - .mono_reg =AFE_DAC_CON1 , - .mono_shift =DL1_DATA_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =DL1_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =DL1_HD_SFT , - .hd_align_mshift =DL1_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_DL2 ] = { - .name ="DL2" , - .id =MT8183_MEMIF_DL2 , - .reg_ofs_base =AFE_DL2_BASE , - .reg_ofs_cur =AFE_DL2_CUR , - .fs_reg =AFE_DAC_CON1 , - .fs_shift =DL2_MODE_SFT , - .fs_maskbit =DL2_MODE_MASK , - .mono_reg =AFE_DAC_CON1 , - .mono_shift =DL2_DATA_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =DL2_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =DL2_HD_SFT , - .hd_align_mshift =DL2_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_DL3 ] = { - .name ="DL3" , - .id =MT8183_MEMIF_DL3 , - .reg_ofs_base =AFE_DL3_BASE , - .reg_ofs_cur =AFE_DL3_CUR , - .fs_reg =AFE_DAC_CON2 , - .fs_shift =DL3_MODE_SFT , - .fs_maskbit =DL3_MODE_MASK , - .mono_reg =AFE_DAC_CON1 , - .mono_shift =DL3_DATA_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =DL3_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =DL3_HD_SFT , - .hd_align_mshift =DL3_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_VUL2 ] = { - .name ="VUL2" , - .id =MT8183_MEMIF_VUL2 , - .reg_ofs_base =AFE_VUL2_BASE , - .reg_ofs_cur =AFE_VUL2_CUR , - .fs_reg =AFE_DAC_CON2 , - .fs_shift =VUL2_MODE_SFT , - .fs_maskbit =VUL2_MODE_MASK , - .mono_reg =AFE_DAC_CON2 , - .mono_shift =VUL2_DATA_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =VUL2_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =VUL2_HD_SFT , - .hd_align_mshift =VUL2_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_AWB ] = { - .name ="AWB" , - .id =MT8183_MEMIF_AWB , - .reg_ofs_base =AFE_AWB_BASE , - .reg_ofs_cur =AFE_AWB_CUR , - .fs_reg =AFE_DAC_CON1 , - .fs_shift =AWB_MODE_SFT , - .fs_maskbit =AWB_MODE_MASK , - .mono_reg =AFE_DAC_CON1 , - .mono_shift =AWB_DATA_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =AWB_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =AWB_HD_SFT , - .hd_align_mshift =AWB_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_AWB2 ] = { - .name ="AWB2" , - .id =MT8183_MEMIF_AWB2 , - .reg_ofs_base =AFE_AWB2_BASE , - .reg_ofs_cur =AFE_AWB2_CUR , - .fs_reg =AFE_DAC_CON2 , - .fs_shift =AWB2_MODE_SFT , - .fs_maskbit =AWB2_MODE_MASK , - .mono_reg =AFE_DAC_CON2 , - .mono_shift =AWB2_DATA_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =AWB2_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =AWB2_HD_SFT , - .hd_align_mshift =AWB2_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_VUL12 ] = { - .name ="VUL12" , - .id =MT8183_MEMIF_VUL12 , - .reg_ofs_base =AFE_VUL_D2_BASE , - .reg_ofs_cur =AFE_VUL_D2_CUR , - .fs_reg =AFE_DAC_CON0 , - .fs_shift =VUL12_MODE_SFT , - .fs_maskbit =VUL12_MODE_MASK , - .mono_reg =AFE_DAC_CON0 , - .mono_shift =VUL12_MONO_SFT , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =VUL12_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =VUL12_HD_SFT , - .hd_align_mshift =VUL12_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_MOD_DAI ] = { - .name ="MOD_DAI" , - .id =MT8183_MEMIF_MOD_DAI , - .reg_ofs_base =AFE_MOD_DAI_BASE , - .reg_ofs_cur =AFE_MOD_DAI_CUR , - .fs_reg =AFE_DAC_CON1 , - .fs_shift =MOD_DAI_MODE_SFT , - .fs_maskbit =MOD_DAI_MODE_MASK , - .mono_reg =-1 , - .mono_shift =0 , - .enable_reg =AFE_DAC_CON0 , - .enable_shift =MOD_DAI_ON_SFT , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =MOD_DAI_HD_SFT , - .hd_align_mshift =MOD_DAI_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, - [MT8183_MEMIF_HDMI ] = { - .name ="HDMI" , - .id =MT8183_MEMIF_HDMI , - .reg_ofs_base =AFE_HDMI_OUT_BASE , - .reg_ofs_cur =AFE_HDMI_OUT_CUR , - .fs_reg =-1 , - .fs_shift =-1 , - .fs_maskbit =-1 , - .mono_reg =-1 , - .mono_shift =-1 , - .enable_reg =-1 ,/* control in tdm for sync start */ - .enable_shift =-1 , - .hd_reg =AFE_MEMIF_HD_MODE , - .hd_align_reg =AFE_MEMIF_HDALIGN , - .hd_shift =HDMI_HD_SFT , - .hd_align_mshift =HDMI_HD_ALIGN_SFT , - .agent_disable_reg =-1 , - .agent_disable_shift =-1 , - .msb_reg =-1 , - .msb_shift =-1 , - }, +MT8183_MEMIF (DL1 ,AFE_DAC_CON1 ,AFE_DAC_CON1 ), +MT8183_MEMIF (DL2 ,AFE_DAC_CON1 ,AFE_DAC_CON1 ), +MT8183_MEMIF (DL3 ,AFE_DAC_CON2 ,AFE_DAC_CON1 ), +MT8183_MEMIF (VUL2 ,AFE_DAC_CON2 ,AFE_DAC_CON2 ), +MT8183_MEMIF (AWB ,AFE_DAC_CON1 ,AFE_DAC_CON1 ), +MT8183_MEMIF (AWB2 ,AFE_DAC_CON2 ,AFE_DAC_CON2 ), +MT8183_MEMIF (VUL12 ,AFE_DAC_CON0 ,AFE_DAC_CON0 ), +MT8183_MEMIF (MOD_DAI ,AFE_DAC_CON1 ,-1 ), +/* enable control in tdm for sync start */ +MT8183_MEMIF_BASE (HDMI ,-1 ,-1 ,-1 ), };static const struct mtk_base_irq_data irq_data[MT8183_IRQ_NUM ] = {
Greg Kroah-Hartman
maintainerPATCH 501/602 ASoC: mediatek: mt8183-afe-pcm: Support >32 bit DMA addresses
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit 9e7bc5cb8d089d9799e17a9ac99c5da9b13b02e3 ]
The AFE DMA hardware supports up to 34 bits for DMA addresses. This is missing from the driver and prevents reserved memory regions from working properly when the allocated region is above the 4GB line.
Fill in the related register offsets for each DAI, and also set the DMA mask. Also fill in the LSB end register offsets for completeness.
Stable-dep-of: f0334fbfd107 ("ASoC: mediatek: mt8183: Check runtime resume during probe")
--- sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +14 -0
@@ -6,6 +6,7 @@// Author: KaiChieh Chuang <[email protected]> #include <linux/delay.h> +#include <linux/dma-mapping.h> #include <linux/module.h> #include <linux/mfd/syscon.h> #include <linux/of.h>
@@ -432,6 +433,9 @@ static const struct snd_soc_component_dr .reg_ofs_base = AFE_##_id##_BASE, \ .reg_ofs_cur = AFE_##_id##_CUR, \ .reg_ofs_end = AFE_##_id##_END, \ + .reg_ofs_base_msb = AFE_##_id##_BASE_MSB, \ + .reg_ofs_cur_msb = AFE_##_id##_CUR_MSB, \ + .reg_ofs_end_msb = AFE_##_id##_END_MSB, \ .fs_reg = (_fs_reg), \ .fs_shift = _id##_MODE_SFT, \ .fs_maskbit = _id##_MODE_MASK, \
@@ -463,11 +467,17 @@ static const struct snd_soc_component_dr#define AFE_VUL12_BASE AFE_VUL_D2_BASE#define AFE_VUL12_CUR AFE_VUL_D2_CUR#define AFE_VUL12_END AFE_VUL_D2_END +#define AFE_VUL12_BASE_MSB AFE_VUL_D2_BASE_MSB +#define AFE_VUL12_CUR_MSB AFE_VUL_D2_CUR_MSB +#define AFE_VUL12_END_MSB AFE_VUL_D2_END_MSB#define AWB2_HD_ALIGN_SFT AWB2_ALIGN_SFT#define VUL12_DATA_SFT VUL12_MONO_SFT#define AFE_HDMI_BASE AFE_HDMI_OUT_BASE#define AFE_HDMI_CUR AFE_HDMI_OUT_CUR#define AFE_HDMI_END AFE_HDMI_OUT_END +#define AFE_HDMI_BASE_MSB AFE_HDMI_OUT_BASE_MSB +#define AFE_HDMI_CUR_MSB AFE_HDMI_OUT_CUR_MSB +#define AFE_HDMI_END_MSB AFE_HDMI_OUT_END_MSBstatic const struct mtk_base_memif_data memif_data[MT8183_MEMIF_NUM ] = {MT8183_MEMIF (DL1 ,AFE_DAC_CON1 ,AFE_DAC_CON1 ),
@@ -951,6 +961,10 @@ static int mt8183_afe_pcm_dev_probe(strustruct reset_control *rstc;int i, irq_id, ret; + ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (34 )); +if (ret) +return ret; + afe =devm_kzalloc (&pdev->dev,sizeof (*afe),GFP_KERNEL );if (!afe)return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 502/602 ASoC: mediatek: mt8183-afe-pcm: use local `dev` pointer in driver callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit bb8d8ba4715cb8f997d63d90ba935f6073595df5 ]
The probe and remove functions in the mt8183-afe-pcm driver repeatedly uses &pdev->dev for |struct device *|, but then assigns this value to afe->dev and uses that in other places in the same function.
Store &pdev->dev in a local pointer and use that exclusively to avoid the numerous dereferences and to make the code more consistent. Lines are reflowed where it makes sense.
Stable-dep-of: f0334fbfd107 ("ASoC: mediatek: mt8183: Check runtime resume during probe")
--- sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 37 +++++++++++++---------------- 1 file changed, 17 insertions(+), 20 deletions(-)
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +17 -20
@@ -957,27 +957,25 @@ static int mt8183_afe_pcm_dev_probe(stru {struct mtk_base_afe *afe;struct mt8183_afe_private *afe_priv; -struct device *dev; +struct device *dev = &pdev->dev;struct reset_control *rstc;int i, irq_id, ret; - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (34 )); + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (34 ));if (ret)return ret; - afe =devm_kzalloc (&pdev->dev,sizeof (*afe),GFP_KERNEL ); + afe =devm_kzalloc (dev,sizeof (*afe),GFP_KERNEL );if (!afe)return -ENOMEM ;platform_set_drvdata (pdev, afe); - afe->platform_priv =devm_kzalloc (&pdev->dev,sizeof (*afe_priv), -GFP_KERNEL ); + afe->platform_priv =devm_kzalloc (dev,sizeof (*afe_priv),GFP_KERNEL );if (!afe->platform_priv)return -ENOMEM ; afe_priv = afe->platform_priv; - afe->dev = &pdev->dev; - dev = afe->dev; + afe->dev = dev; ret =of_reserved_mem_device_init (dev);if (ret) {
@@ -1028,7 +1026,7 @@ static int mt8183_afe_pcm_dev_probe(stru/* enable clock for regcache get default value from hw */ afe_priv->pm_runtime_bypass_reg_ctl = true; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_get_sync (dev); ret =regmap_reinit_cache (afe->regmap, &mt8183_afe_regmap_config);if (ret) {
@@ -1036,7 +1034,7 @@ static int mt8183_afe_pcm_dev_probe(stru goto err_pm_disable; } -pm_runtime_put_sync (&pdev->dev); +pm_runtime_put_sync (dev); afe_priv->pm_runtime_bypass_reg_ctl = false;regcache_cache_only (afe->regmap, true);
@@ -1094,7 +1092,7 @@ static int mt8183_afe_pcm_dev_probe(strufor (i =0 ; i <ARRAY_SIZE (dai_register_cbs); i++) { ret = dai_register_cbs[i](afe);if (ret) { -dev_warn (afe->dev,"dai register i %d fail, ret %d\n" , +dev_warn (dev,"dai register i %d fail, ret %d\n" , i, ret); goto err_pm_disable; }
@@ -1103,8 +1101,7 @@ static int mt8183_afe_pcm_dev_probe(stru/* init dai_driver and component_driver */ ret =mtk_afe_combine_sub_dai (afe);if (ret) { -dev_warn (afe->dev,"mtk_afe_combine_sub_dai fail, ret %d\n" , - ret); +dev_warn (dev,"mtk_afe_combine_sub_dai fail, ret %d\n" , ret); goto err_pm_disable; }
@@ -1116,16 +1113,14 @@ static int mt8183_afe_pcm_dev_probe(stru afe->runtime_suspend = mt8183_afe_runtime_suspend;/* register component */ - ret =devm_snd_soc_register_component (&pdev->dev, - &mtk_afe_pcm_platform, + ret =devm_snd_soc_register_component (dev, &mtk_afe_pcm_platform,NULL ,0 );if (ret) {dev_warn (dev,"err_platform\n" ); goto err_pm_disable; } - ret =devm_snd_soc_register_component (afe->dev, - &mt8183_afe_pcm_dai_component, + ret =devm_snd_soc_register_component (dev, &mt8183_afe_pcm_dai_component, afe->dai_drivers, afe->num_dai_drivers);if (ret) {
@@ -1136,15 +1131,17 @@ static int mt8183_afe_pcm_dev_probe(strureturn ret; err_pm_disable: -pm_runtime_disable (&pdev->dev); +pm_runtime_disable (dev);return ret; }static void mt8183_afe_pcm_dev_remove (struct platform_device *pdev) { -pm_runtime_disable (&pdev->dev); -if (!pm_runtime_status_suspended (&pdev->dev)) -mt8183_afe_runtime_suspend (&pdev->dev); +struct device *dev = &pdev->dev; + +pm_runtime_disable (dev); +if (!pm_runtime_status_suspended (dev)) +mt8183_afe_runtime_suspend (dev); }static const struct of_device_id mt8183_afe_pcm_dt_match[] = {
Greg Kroah-Hartman
maintainerPATCH 503/602 ASoC: mediatek: mt8183: Check runtime resume during probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
[ Upstream commit f0334fbfd107682d0c95f3f71e25f6127038e2b9 ]
The MT8183 AFE probe uses pm_runtime_get_sync() before reading hardware defaults into the regmap cache, but does not check whether runtime resume failed. If regmap_reinit_cache() then fails, the temporary runtime PM usage count is also not released.
Use pm_runtime_resume_and_get() so resume failures abort probe without leaking a usage count, and release the temporary reference before handling the regmap cache result.
--- sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +8 -4
@@ -1026,17 +1026,21 @@ static int mt8183_afe_pcm_dev_probe(stru/* enable clock for regcache get default value from hw */ afe_priv->pm_runtime_bypass_reg_ctl = true; -pm_runtime_get_sync (dev); - - ret =regmap_reinit_cache (afe->regmap, &mt8183_afe_regmap_config); + ret =pm_runtime_resume_and_get (dev);if (ret) { -dev_err (dev,"regmap_reinit_cache fail, ret %d\n" , ret); + afe_priv->pm_runtime_bypass_reg_ctl = false; goto err_pm_disable; } + ret =regmap_reinit_cache (afe->regmap, &mt8183_afe_regmap_config);pm_runtime_put_sync (dev); afe_priv->pm_runtime_bypass_reg_ctl = false; +if (ret) { +dev_err (dev,"regmap_reinit_cache fail, ret %d\n" , ret); + goto err_pm_disable; + } +regcache_cache_only (afe->regmap, true);regcache_mark_dirty (afe->regmap);
Greg Kroah-Hartman
maintainerPATCH 504/602 netfilter: nf_conntrack_sip: remove net variable shadowing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 7970d6aaf710db166de98c5356a260089896fae5 ]
net is already set, derived from nf_conn.
I don't see how the device could be living in a different netns than the conntrack entry.
Remove the extra variable and re-use existing one.
Stable-dep-of: e5e24a365a5e ("netfilter: nf_conntrack_sip: validate skb_dst() before accessing it")
--- net/netfilter/nf_conntrack_sip.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netfilter/nf_conntrack_sip.c +1 -2
@@ -948,9 +948,8 @@ static int set_expected_rtp_rtcp(struct saddr = &ct->tuplehash[!dir].tuple.src.u3; }else if (sip_external_media) {struct net_device *dev =skb_dst (skb)->dev; -struct net *net =dev_net (dev); -struct flowi fl;struct dst_entry *dst =NULL ; +struct flowi fl;memset (&fl,0 ,sizeof (fl));
Greg Kroah-Hartman
maintainerPATCH 505/602 netfilter: nf_conntrack_sip: validate skb_dst() before accessing it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit e5e24a365a5e024efef63cc49abb345fbd4852c5 ]
tc ingress and openvswitch do not guarantee routing information to be available. These subsystems use the conntrack helper infrastructure, and the SIP helper relies on the skb_dst() to be present if sip_external_media is set to 1 (which is disabled by default as a module parameter).
This effectively disables the sip_external_media toggle for these subsystems without resulting in a crash.
--- net/netfilter/nf_conntrack_sip.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_sip.c +5 -2
@@ -947,7 +947,6 @@ static int set_expected_rtp_rtcp(structreturn NF_ACCEPT ; saddr = &ct->tuplehash[!dir].tuple.src.u3; }else if (sip_external_media) { -struct net_device *dev =skb_dst (skb)->dev;struct dst_entry *dst =NULL ;struct flowi fl;
@@ -969,7 +968,11 @@ static int set_expected_rtp_rtcp(struct* through the same interface as the signalling peer. */ if (dst) { -bool external_media = (dst->dev == dev); +const struct dst_entry *this_dst =skb_dst (skb); +bool external_media = false; + +if (this_dst && dst->dev == this_dst->dev) + external_media = true;dst_release (dst);if (external_media)
Greg Kroah-Hartman
maintainerPATCH 506/602 netfilter: bitwise: rename some boolean operation functions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeremy Sowden <[email protected]>
[ Upstream commit a12143e6084c502fc3cfaa8b717bffc8c14cf806 ]
In the next patch we add support for doing AND, OR and XOR operations directly in the kernel, so rename some functions and an enum constant related to mask-and-xor boolean operations.
Stable-dep-of: d07955dd34ec ("netfilter: nft_fib: reject fib expression on the netdev egress hook")
--- include/uapi/linux/netfilter/nf_tables.h | 10 ++++++--- net/netfilter/nft_bitwise.c | 34 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 20 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +7 -3
@@ -564,16 +564,20 @@ enum nft_immediate_attributes {/** * enum nft_bitwise_ops - nf_tables bitwise operations * -* @NFT_BITWISE_BOOL: mask-and-xor operation used to implement NOT, AND, OR and -* XOR boolean operations +* @NFT_BITWISE_MASK_XOR: mask-and-xor operation used to implement NOT, AND, OR +* and XOR boolean operations * @NFT_BITWISE_LSHIFT: left-shift operation * @NFT_BITWISE_RSHIFT: right-shift operation */ enum nft_bitwise_ops { -NFT_BITWISE_BOOL , +NFT_BITWISE_MASK_XOR ,NFT_BITWISE_LSHIFT ,NFT_BITWISE_RSHIFT , }; +/* +* Old name for NFT_BITWISE_MASK_XOR. Retained for backwards-compatibility. +*/ +#define NFT_BITWISE_BOOL NFT_BITWISE_MASK_XOR/** * enum nft_bitwise_attributes - nf_tables bitwise expression netlink attributes
net/netfilter/nft_bitwise.c +17 -17
@@ -25,8 +25,8 @@ struct nft_bitwise {struct nft_data data; }; -static void nft_bitwise_eval_bool (u32 *dst,const u32 *src, -const struct nft_bitwise *priv) +static void nft_bitwise_eval_mask_xor (u32 *dst,const u32 *src, +const struct nft_bitwise *priv) {unsigned int i;
@@ -68,8 +68,8 @@ void nft_bitwise_eval(const struct nft_eu32 *dst = ®s->data[priv->dreg];switch (priv->op) { -case NFT_BITWISE_BOOL : -nft_bitwise_eval_bool (dst, src, priv); +case NFT_BITWISE_MASK_XOR : +nft_bitwise_eval_mask_xor (dst, src, priv);break ;case NFT_BITWISE_LSHIFT :nft_bitwise_eval_lshift (dst, src, priv);
@@ -90,8 +90,8 @@ static const struct nla_policy nft_bitwi [NFTA_BITWISE_DATA] = { .type = NLA_NESTED }, }; -static int nft_bitwise_init_bool (struct nft_bitwise *priv, -const struct nlattr *const tb[]) +static int nft_bitwise_init_mask_xor (struct nft_bitwise *priv, +const struct nlattr *const tb[]) {struct nft_data_desc mask = { .type =NFT_DATA_VALUE ,
@@ -186,7 +186,7 @@ static int nft_bitwise_init(const structif (tb[NFTA_BITWISE_OP ]) { priv->op =ntohl (nla_get_be32 (tb[NFTA_BITWISE_OP ]));switch (priv->op) { -case NFT_BITWISE_BOOL : +case NFT_BITWISE_MASK_XOR :case NFT_BITWISE_LSHIFT :case NFT_BITWISE_RSHIFT :break ;
@@ -194,12 +194,12 @@ static int nft_bitwise_init(const structreturn -EOPNOTSUPP ; } }else { - priv->op =NFT_BITWISE_BOOL ; + priv->op =NFT_BITWISE_MASK_XOR ; }switch (priv->op) { -case NFT_BITWISE_BOOL : - err =nft_bitwise_init_bool (priv, tb); +case NFT_BITWISE_MASK_XOR : + err =nft_bitwise_init_mask_xor (priv, tb);break ;case NFT_BITWISE_LSHIFT :case NFT_BITWISE_RSHIFT :
@@ -210,8 +210,8 @@ static int nft_bitwise_init(const structreturn err; } -static int nft_bitwise_dump_bool (struct sk_buff *skb, -const struct nft_bitwise *priv) +static int nft_bitwise_dump_mask_xor (struct sk_buff *skb, +const struct nft_bitwise *priv) {if (nft_data_dump (skb,NFTA_BITWISE_MASK , &priv->mask,NFT_DATA_VALUE , priv->len) <0 )
@@ -249,8 +249,8 @@ static int nft_bitwise_dump(struct sk_bureturn -1 ;switch (priv->op) { -case NFT_BITWISE_BOOL : - err =nft_bitwise_dump_bool (skb, priv); +case NFT_BITWISE_MASK_XOR : + err =nft_bitwise_dump_mask_xor (skb, priv);break ;case NFT_BITWISE_LSHIFT :case NFT_BITWISE_RSHIFT :
@@ -270,7 +270,7 @@ static int nft_bitwise_offload(struct nfconst struct nft_bitwise *priv =nft_expr_priv (expr);struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; -if (priv->op !=NFT_BITWISE_BOOL ) +if (priv->op !=NFT_BITWISE_MASK_XOR )return -EOPNOTSUPP ; if (memcmp(&priv->xor, &zero, sizeof(priv->xor)) ||
@@ -407,7 +407,7 @@ nft_bitwise_fast_dump(struct sk_buff *skreturn -1 ;if (nla_put_be32 (skb,NFTA_BITWISE_LEN ,htonl (sizeof (u32))))return -1 ; -if (nla_put_be32 (skb,NFTA_BITWISE_OP ,htonl (NFT_BITWISE_BOOL ))) +if (nla_put_be32 (skb,NFTA_BITWISE_OP ,htonl (NFT_BITWISE_MASK_XOR )))return -1 ; data.data[0 ] = priv->mask;
@@ -502,7 +502,7 @@ nft_bitwise_select_ops(const struct nft_return &nft_bitwise_ops;if (tb[NFTA_BITWISE_OP ] && -ntohl (nla_get_be32 (tb[NFTA_BITWISE_OP ])) !=NFT_BITWISE_BOOL ) +ntohl (nla_get_be32 (tb[NFTA_BITWISE_OP ])) !=NFT_BITWISE_MASK_XOR )return &nft_bitwise_ops;return &nft_bitwise_fast_ops;
Greg Kroah-Hartman
maintainerPATCH 507/602 netfilter: nf_tables: Remove unused nft_reduce_is_readonly()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yue Haibing <[email protected]>
[ Upstream commit bf6788742b8d6c73de441e088a71de7154f0d4aa ]
Since commit 9e539c5b6d9c ("netfilter: nf_tables: disable expression reduction infra") this is unused.
Stable-dep-of: d07955dd34ec ("netfilter: nft_fib: reject fib expression on the netdev egress hook")
--- include/net/netfilter/nf_tables.h | 5 ----- 1 file changed, 5 deletions(-)
include/net/netfilter/nf_tables.h +0 -5
@@ -1954,11 +1954,6 @@ static inline u64 nft_net_tstamp(const s#define __NFT_REDUCE_READONLY 1UL#define NFT_REDUCE_READONLY (void *)__NFT_REDUCE_READONLY -static inline bool nft_reduce_is_readonly (const struct nft_expr *expr) -{ -return expr->ops->reduce ==NFT_REDUCE_READONLY ; -} -void nft_reg_track_update (struct nft_regs_track *track,const struct nft_expr *expr,u8 dreg,u8 len);void nft_reg_track_cancel (struct nft_regs_track *track,u8 dreg,u8 len);