6.1.193-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 365/2857 drm/amdgpu: force complete the MES ring fences on reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 48dc279c3010ac8f91b1845b2abb3a1e9943a0f5 ]
The MES scheduler ring has no drm scheduler (no_scheduler = true), so it is skipped by the force-completion loop in amdgpu_device_pre_asic_reset(). It uses a polling fence whose hw value lives in wb (GTT) memory and survives a MODE1 reset, while fence_drv.sync_seq keeps advancing for every packet.
When the reset is triggered because MES itself stopped responding, the timed-out packets advance sync_seq past the last hw fence value MES wrote. After resume the first MES submission polls forever on a seq that is never written back, failing the resume and wedging the box on a second reset:
amdgpu: MES ring buffer is full.
amdgpu: *ERROR* ring gfx_0.0.0 test failed (-110)
amdgpu: resume of IP block <gfx_v11_0> failed -110
amdgpu: GPU reset end with ret = -110
Force complete the MES scheduler ring fences together with the scheduler rings so their hw fence is realigned to sync_seq.
v2: cover all XCCs (one scheduler ring each), not just mes.ring[0].
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
@@ -4979,6 +4979,15 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,if (adev->gfx.kiq.ring.fence_drv.initialized && adev->gfx.kiq.ring.sched.ready)amdgpu_fence_driver_force_completion (&adev->gfx.kiq.ring); +/* +* MES scheduler rings have no drm scheduler, so they are missed by the +* loop above. Realign their polling fence too (one per XCC), otherwise the +* first post-reset submission polls forever on a stale seq. sched.ready is +* only set while the driver owns the ring. +*/ +if (adev->mes.ring.fence_drv.initialized && adev->mes.ring.sched.ready) +amdgpu_fence_driver_force_completion (&adev->mes.ring); +amdgpu_fence_driver_isr_toggle (adev, false);if (job && job->vm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/2857 reboot: fix cad_pid use-after-free race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit 5a88f78df753993469dab4d1831f8fb4256a9468 ]
cad_pid is a single kernel-wide struct pid pointer. proc_do_cad_pid() reads it and passes it to pid_vnr() without protecting the lifetime of the referenced struct pid. A concurrent writer can replace cad_pid and drop the final reference to the old struct pid after the reader has loaded the pointer but before pid_vnr() has finished dereferencing it, causing a use-after-free.
kill_cad_pid() has the same lifetime race when it passes cad_pid to kill_pid().
At the time this issue was reported, an unprivileged user could reach the sysctl through user and PID namespaces because cad_pid was registered in pid_table[]. Moving cad_pid back to the global reboot sysctl table corrected that namespace and permission mismatch, but did not fix the underlying lifetime race.
Fix this by treating cad_pid as an RCU-protected pointer at both read sites and by waiting for a grace period before dropping the old reference on the write side.
call_rcu(&old_pid->rcu, ...) cannot be used here because free_pid() also queues pid->rcu; queueing the same rcu_head twice can corrupt the RCU callback list.
Original KASAN crash stack:
kernel/pid.c:545 pid_nr_ns() # reads freed pid->level kernel/pid.c:556 pid_vnr() # calls pid_nr_ns() kernel/pid.c:775 proc_do_cad_pid() # calls pid_vnr(cad_pid)
--- include/linux/sched.h | 2 +- include/linux/sched/signal.h | 5 +---- init/main.c | 2 +- kernel/reboot.c | 5 +++-- kernel/signal.c | 12 ++++++++++++ kernel/sysctl.c | 13 +++++++++++-- 6 files changed, 29 insertions(+), 10 deletions(-)
include/linux/sched.h +1 -1
@@ -1724,7 +1724,7 @@ static inline int is_global_init(struct task_struct *tsk)return task_tgid_nr (tsk) ==1 ; } -extern struct pid *cad_pid; +extern struct pid __rcu *cad_pid;/* * Per process flags
include/linux/sched/signal.h +1 -4
@@ -591,10 +591,7 @@ static inline sigset_t *sigmask_to_save(void)return res; } -static inline int kill_cad_pid (int sig,int priv) -{ -return kill_pid (cad_pid, sig, priv); -} +int kill_cad_pid (int sig,int priv);/* These can be the second arg to send_sig_info/send_group_sig_info. */ #define SEND_SIG_NOINFO ((struct kernel_siginfo *) 0)
init/main.c +1 -1
@@ -1575,7 +1575,7 @@ static noinline void __init kernel_init_freeable(void)*/ set_mems_allowed (node_states[N_MEMORY ]); - cad_pid =get_pid (task_pid (current)); +rcu_assign_pointer (cad_pid,get_pid (task_pid (current)));smp_prepare_cpus (setup_max_cpus);
kernel/reboot.c +3 -2
@@ -13,7 +13,9 @@#include <linux/kexec.h> #include <linux/kmod.h> #include <linux/kmsg_dump.h> +#include <linux/rcupdate.h> #include <linux/reboot.h> +#include <linux/sched/signal.h> #include <linux/suspend.h> #include <linux/syscalls.h> #include <linux/syscore_ops.h>
@@ -24,8 +26,7 @@*/ static int C_A_D =1 ; -struct pid *cad_pid; -EXPORT_SYMBOL (cad_pid); +struct pid __rcu *cad_pid;#if defined(CONFIG_ARM )#define DEFAULT_REBOOT_MODE = REBOOT_HARD
kernel/signal.c +12 -0
@@ -1937,6 +1937,18 @@ int kill_pid(struct pid *pid, int sig, int priv) }EXPORT_SYMBOL (kill_pid); +int kill_cad_pid (int sig,int priv) +{ +int ret; + +rcu_read_lock (); + ret =kill_pid (rcu_dereference (cad_pid), sig, priv); +rcu_read_unlock (); + +return ret; +} +EXPORT_SYMBOL (kill_cad_pid); +/* * These functions support sending signals using preallocated sigqueue * structures. This is needed "because realtime applications cannot
kernel/sysctl.c +11 -2
@@ -1348,10 +1348,13 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { struct pid *new_pid; +struct pid *old_pid;pid_t tmp;int r; - tmp =pid_vnr (cad_pid); +rcu_read_lock (); + tmp =pid_vnr (rcu_dereference (cad_pid)); +rcu_read_unlock (); r =__do_proc_dointvec (&tmp, table, write, buffer, lenp, ppos,NULL ,NULL );
@@ -1362,7 +1365,13 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,if (!new_pid)return -ESRCH ; -put_pid (xchg (&cad_pid, new_pid)); + old_pid =unrcu_pointer (xchg (&cad_pid,RCU_INITIALIZER (new_pid))); +/* +* Wait for cad_pid readers before put_pid(). We cannot use +* call_rcu() here because free_pid() already owns pid->rcu. +*/ +synchronize_rcu (); +put_pid (old_pid);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/2857 smb: client: reject SetEA requests that do not fit the request buffer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunpeng Tian <[email protected]>
[ Upstream commit 4aa2c106aef4bf3dfd97c30842db0767b26e8428 ]
CIFSSMBSetEA() copies the caller's extended attribute value into the SMB request buffer without checking that it fits. The requirement is stated in the source but was never implemented:
/*BB add length check to see if it would fit in negotiated SMB buffer size BB */ /* if (ea_value_len > buffer_size - 512 (enough for header)) */ if (ea_value_len) memcpy(parm_data->list.name + name_len + 1, ea_value, ea_value_len);
The only bound applied on the way in is in cifs_xattr_set():
#define MAX_EA_VALUE_SIZE CIFSMaxBufSize ... if (size > MAX_EA_VALUE_SIZE)
CIFSMaxBufSize is the full payload capacity of the buffer, so a value of exactly that size leaves no room for the SMB header, the TRANS2 parameter block, the fealist header and the EA name that are written ahead of it in the same object.
SendReceive() already enforces the correct limit on this very length:
if (in_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE)
but it is called after the copy has taken place. An unprivileged setxattr(2) on an SMB1 mount with a 250-byte name and a 16384-byte value writes 16384 bytes starting 345 bytes into a 16588-byte cifs_request object, ending 141 bytes past it:
BUG: KASAN: slab-out-of-bounds in CIFSSMBSetEA+0xabc/0xde0 Write of size 16384 at addr ffff888003aa0159 by task init/68 __asan_memcpy+0x3c/0x60 CIFSSMBSetEA+0xabc/0xde0 cifs_xattr_set+0xd3a/0xff0 __vfs_setxattr+0x13e/0x1a0 The buggy address is located 345 bytes inside of allocated 16588-byte region
Apply SendReceive()'s limit to the assembled request before the copy rather than after it, and widen the byte counters so the sum cannot wrap before it is tested.
byte_count is also tested against U16_MAX, because it is stored in the 16-bit pSMB->ByteCount. That becomes reachable when CIFSMaxBufSize is raised at module load, where it may be set as high as 1024*127: with a 5-byte EA name and a 65521-byte value, count is exactly U16_MAX while byte_count is 65556, and cpu_to_le16() would truncate it to 20 and transmit a frame whose ByteCount does not match its length. Testing byte_count covers count as well, since byte_count is the larger of the two and count's only 16-bit consumer is written after this point.
check_add_overflow() is evaluated first so that total_len is assigned before it is reported.
--- fs/smb/client/cifssmb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/smb/client/cifssmb.c +12 -1
@@ -5799,8 +5799,11 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,int name_len;int rc =0 ;int bytes_returned =0 ; -__u16 params, param_offset, byte_count, offset, count; +__u16 params, param_offset; +unsigned int byte_count, offset, count;int remap =cifs_remap (cifs_sb); +unsigned int total_len; +unsigned int in_len;cifs_dbg (FYI ,"In SetEA\n" ); SetEARetry:
@@ -5808,6 +5811,7 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, (void **) &pSMBr);if (rc)return rc; + in_len =get_rfc1002_length (pSMB);if (pSMB->hdr.Flags2 &SMBFLG2_UNICODE ) { name_len =
@@ -5851,6 +5855,13 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, pSMB->Reserved3 =0 ; pSMB->SubCommand =cpu_to_le16 (TRANS2_SET_PATH_INFORMATION ); byte_count =3 /* pad */ + params + count; +if (check_add_overflow (in_len, byte_count, &total_len) || + byte_count >U16_MAX || + total_len > CIFSMaxBufSize +MAX_CIFS_HDR_SIZE -4 ) { +cifs_dbg (VFS ,"EA request too large: %u bytes\n" , total_len); +cifs_buf_release (pSMB); +return -E2BIG ; + } pSMB->DataCount =cpu_to_le16 (count); parm_data->list_len =cpu_to_le32 (count); parm_data->list[0 ].EA_flags =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/2857 vsock/vmci: validate packet source for connected sockets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit ad9a7da3fa39c2d616ec0dd3cf6e30531d032fe7 ]
vmci_transport_recv_stream_cb() looks up sockets first by the full source and destination tuple, then by destination only in the bound table. The fallback can select a non-listening socket without checking whether the packet came from its stored peer.
This was reproduced with two VMCI contexts. A RST from the context not stored in a TCP_SYN_SENT socket reset that socket after it was selected by the destination-only lookup.
VMCI can process notification packets in bottom-half context when the socket is not owned by user context, or defer packets to a workqueue. Use vsock_check_source() after taking the socket lock in the bottom-half path, and recheck after lock_sock() in the workqueue path. Listening sockets continue to accept packets from any source.
Reply with a RST addressed from the received packet before dropping a source that fails validation. This preserves the existing reset behavior for bound non-listening and concurrently closed sockets without directing the reset to a connected socket's stored peer.
--- net/vmw_vsock/vmci_transport.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
net/vmw_vsock/vmci_transport.c +28 -6
@@ -676,11 +676,13 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)struct vmci_transport_packet *pkt;struct vsock_sock *vsk;bool bh_process_pkt; +bool drop_pkt;int err; sk =NULL ; err =VMCI_SUCCESS ; bh_process_pkt = false; + drop_pkt = false;/* Ignore incoming packets from contexts without sockets, or resources * that aren't vsock implementations.
@@ -757,17 +759,29 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)bh_lock_sock (sk);if (!sock_owned_by_user (sk)) { -/* The local context ID may be out of date, update it. */ - vsk->local_addr.svm_cid = dst.svm_cid; +if (sk->sk_state !=TCP_LISTEN && + !vsock_check_source (vsk, &vmci_transport, &src)) { + drop_pkt = true; + err =VMCI_ERROR_NO_ACCESS ; + }else { +/* The local context ID may be out of date, update it. */ + vsk->local_addr.svm_cid = dst.svm_cid; -if (sk->sk_state ==TCP_ESTABLISHED ) -vmci_trans (vsk)->notify_ops->handle_notify_pkt ( - sk, pkt, true, &dst, &src, - &bh_process_pkt); +if (sk->sk_state ==TCP_ESTABLISHED ) +vmci_trans (vsk)->notify_ops->handle_notify_pkt (sk, pkt, true, + &dst, &src, + &bh_process_pkt); + } }bh_unlock_sock (sk); +if (drop_pkt) { +if (vmci_transport_send_reset_bh (&dst, &src, pkt) <0 ) +pr_err ("unable to send reset\n" ); + goto out; + } +if (!bh_process_pkt) {struct vmci_transport_recv_pkt_info *recv_pkt_info;
@@ -892,6 +906,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) {struct vmci_transport_recv_pkt_info *recv_pkt_info;struct vmci_transport_packet *pkt; +struct sockaddr_vm src;struct sock *sk; recv_pkt_info =
@@ -900,6 +915,12 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) pkt = &recv_pkt_info->pkt;lock_sock (sk); +vsock_addr_init (&src, pkt->dg.src.context, pkt->src_port); +if (sk->sk_state !=TCP_LISTEN && + !vsock_check_source (vsock_sk (sk), &vmci_transport, &src)) { +vmci_transport_reply_reset (pkt); + goto out; + }/* The local context ID may be out of date. */ vsock_sk (sk)->local_addr.svm_cid = pkt->dg.dst.context;
@@ -929,6 +950,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)break ; } +out:release_sock (sk);kfree (recv_pkt_info);/* Release reference obtained in the stream callback when we fetched
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/2857 ipv6: Fix redirect exception creation for UDP/RAW sockets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit cd51b74bdd0b75aedf255dc67306a16dd057f7ee ]
When an ICMP Redirect Message is matched to a socket, both IPv4 and IPv6 verify that the source IP of the ICMP packet is the current gateway for the quoted packet. Both also pass the socket's bound device as the expected nexthop device.
The difference is that IPv4 treats "oif=0" as "any", whereas IPv6 always requires an exact match (see ip6_redirect_nh_match()), since the gateway address is usually a link-local address.
Therefore, when an IPv6 UDP/RAW socket is not bound to a device, the above verification fails and an exception is not created. This also happens when the socket is bound to a VRF, as l3mdev_update_flow() resets the oif to 0.
Fix this by passing the ifindex of the ingress device as the expected nexthop device. This is consistent with the existing callers of ip6_redirect(). Note that for ICMPv6 Redirect Message packets the VRF driver does not reset skb->dev to the VRF device, so skb->dev is correct, even when it is a VRF port.
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -3223,7 +3223,7 @@ void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif)void ip6_sk_redirect (struct sk_buff *skb,struct sock *sk) { -ip6_redirect (skb,sock_net (sk), sk->sk_bound_dev_if, +ip6_redirect (skb,sock_net (sk), skb->dev->ifindex,READ_ONCE (sk->sk_mark), sk->sk_uid); }EXPORT_SYMBOL_GPL (ip6_sk_redirect);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/2857 ipv6: udp: Create exceptions before socket matching
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit ac76cab50e899a7346408b8d3c3a4192c2eefb9f ]
Currently, when ICMPv6 Packet Too Big and Redirect Message packets are locally delivered and quote a UDP packet, an exception is only created in the IPv6 exception cache if the kernel can match the UDP packet to an existing socket.
This behavior allows off-path attackers to conduct a side-channel attack on the exception cache in order to discover the ephemeral port used by a connected UDP socket.
Commit 4785305c05b2 ("ipv6: use siphash in rt6_exception_hash()") and commit a00df2caffed ("ipv6: make exception cache less predictible") tried to mitigate such attacks by making it harder for attackers to discover hash collisions in the exception cache and by randomizing the number of exceptions a hash bucket can hold, respectively. Unfortunately, both of the mitigations can be bypassed.
Instead, mitigate such attacks by always creating an exception, even before trying to find a matching socket. Do that by calling ip6_update_pmtu() and ip6_redirect(), the helpers used when the quoted packet did not originate from a socket.
This means that guesses (right or wrong) from an off-path attacker will always result in an exception being created or updated in the cache that the attacker can observe.
Pass the ifindex of the ingress device and the default uid, in a similar fashion to icmpv6_err(). Unlike IPv4, an oif of 0 would not match any nexthop in ip6_redirect_nh_match() and no exception would be created in response to a Redirect Message.
Note that this does not allow attackers to create exceptions that they could not create before, as both helpers can already be reached with little to no validation. For example, by sending an ICMPv6 error that quotes an ICMPv6 Echo Reply or one that quotes a UDP source port that matches a wildcard socket.
Also note that in the good case (matched socket) the above scheme comes at the cost of an extra route lookup, as the no socket helpers perform their own lookup before the one performed by ip6_sk_update_pmtu() / ip6_sk_redirect(). When the two resolve to different nexthops, it also results in two exceptions being created for the same destination IP. One in the exception cache of the nexthop resolved by the no socket helpers and another in the exception cache of the nexthop used by the socket.
--- net/ipv6/udp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
net/ipv6/udp.c +13 -0
@@ -633,6 +633,17 @@ static struct sock *__udp6_lib_err_encap(struct net *net,return sk; } +static void udpv6_err_update_exception (struct net *net,struct sk_buff *skb, +u8 type,__be32 info) +{ +if (type ==ICMPV6_PKT_TOOBIG ) +ip6_update_pmtu (skb, net, info, skb->dev->ifindex,0 , +sock_net_uid (net,NULL )); +else if (type ==NDISC_REDIRECT ) +ip6_redirect (skb, net, skb->dev->ifindex,0 , +sock_net_uid (net,NULL )); +} +int __udp6_lib_err (struct sk_buff *skb,struct inet6_skb_parm *opt,u8 type,u8 code,int offset,__be32 info,struct udp_table *udptable)
@@ -648,6 +659,8 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,int err;struct net *net =dev_net (skb->dev); +udpv6_err_update_exception (net, skb, type, info); + sk =__udp6_lib_lookup (net, daddr, uh->dest, saddr, uh->source,inet6_iif (skb),inet6_sdif (skb), udptable,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/2857 xfrm: save input state data before secpath resets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 3cf5cdecd99c9c186a5ea518d93bbf3045b6e3aa ]
xfrm_input() stores the current xfrm_state in the skb secpath while it continues receive-side processing. Some input paths can reset that secpath before xfrm_input() has finished dereferencing the state.
Receive callback users such as VTI and XFRM interfaces can reset the secpath. The VTI receive path does so before checking whether the packet crosses network namespaces, while the XFRM interface path does so only for cross-network-namespace packets. The XFRM_MAX_DEPTH error path can also reset the secpath before the final drop callback reports the current state's protocol.
If secpath_reset() drops the last state reference while the state is concurrently deleted, xfrm_input() can still dereference the freed state when selecting transport_finish() or reporting the drop callback protocol.
Save the state protocol on the stack while the state is still valid, and use the already saved address family for transport_finish(). A larval XFRM_STATE_ACQ state has no type, so retain nexthdr as its protocol. This preserves the existing drop-path fallback while avoiding the post-reset state dereferences without adding an extra state reference to every received packet.
--- net/xfrm/xfrm_input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/xfrm/xfrm_input.c +7 -3
@@ -462,6 +462,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)struct xfrm_state *x =NULL ;xfrm_address_t *daddr;u32 mark = skb->mark; +u8 xfrm_proto = nexthdr;unsigned int family =AF_UNSPEC ;int decaps =0 ;int async =0 ;
@@ -472,6 +473,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type <0 || (xo && (xo->flags &XFRM_GRO || encap_type ==0 ))) { x =xfrm_input_state (skb); + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->km.state !=XFRM_STATE_VALID )) {if (x->km.state ==XFRM_STATE_ACQ )
@@ -572,11 +574,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) x =xfrm_state_lookup (net, mark, daddr, spi, nexthdr, family);if (x ==NULL ) { + xfrm_proto = nexthdr;secpath_reset (skb);XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOSTATES );xfrm_audit_state_notfound (skb, family, spi, seq); goto drop; } + xfrm_proto = x->type ? x->type->proto : nexthdr; skb->mark =xfrm_smark_get (skb->mark, x);
@@ -695,7 +699,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) crypto_done = false; }while (!err); - err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); + err =xfrm_rcv_cb (skb, family, xfrm_proto,0 );if (err) goto drop;
@@ -718,7 +722,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) err = -EAFNOSUPPORT ;rcu_read_lock (); - afinfo =xfrm_state_afinfo_get_rcu (x->props.family); + afinfo =xfrm_state_afinfo_get_rcu (family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async);rcu_read_unlock ();
@@ -742,7 +746,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) drop:if (async)dev_put (skb->dev); -xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 ); +xfrm_rcv_cb (skb, family, xfrm_proto,-1 );kfree_skb (skb);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/2857 IB/hfi1: Use dma_mmap_coherent for matching buffers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dean Luick <[email protected]>
[ Upstream commit 1ec82317a1daac78c04b0c15af89018ccf9fa2b7 ]
For memory allocated with dma_alloc_coherent(), use dma_mmap_coherent() to mmap it into user space.
Stable-dep-of: 975396b9e5a4 ("IB/hfi1: Resolve the credit-return buffer through the send context's node")
--- drivers/infiniband/hw/hfi1/file_ops.c | 81 +++++++++++++++++++-------- 1 file changed, 57 insertions(+), 24 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +57 -24
@@ -306,6 +306,17 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from)return reqs; } +static inline void mmap_cdbg (u16 ctxt,u8 subctxt,u8 type,u8 mapio,u8 vmf, +u64 memaddr,void *memvirt,dma_addr_t memdma, +ssize_t memlen,struct vm_area_struct *vma) +{ +hfi1_cdbg (PROC , +"%u:%u type:%u io/vf/dma:%d/%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx" , + ctxt, subctxt, type, mapio, vmf, !!memdma, + memaddr ?: (u64 )memvirt, memlen, + vma->vm_end - vma->vm_start, vma->vm_flags); +} +static int hfi1_file_mmap (struct file *fp,struct vm_area_struct *vma) {struct hfi1_filedata *fd = fp->private_data;
@@ -315,6 +326,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)u64 token = vma->vm_pgoff <<PAGE_SHIFT , memaddr =0 ;void *memvirt =NULL ; +dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type;ssize_t memlen =0 ;int ret =0 ;
@@ -334,6 +346,11 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) goto done; } +/* +* vm_pgoff is used as a buffer selector cookie. Always mmap from +* the beginning. +*/ + vma->vm_pgoff =0 ; flags = vma->vm_flags;switch (type) {
@@ -355,7 +372,8 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); mapio =1 ;break ; -case PIO_CRED : +case PIO_CRED : { +u64 cr_page_offset;if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -365,10 +383,11 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - memvirt = dd->cr_base[uctxt->numa_id].va; - memaddr =virt_to_phys (memvirt) + - (((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) &PAGE_MASK ); + cr_page_offset = ((u64 )uctxt->sc->hw_free - + (u64 )dd->cr_base[uctxt->numa_id].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; + memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -378,14 +397,16 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* memory been flagged as non-cached? */ /* vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); */ - mapio =1 ;break ; + }case RCV_HDRQ : memlen =rcvhdrq_size (uctxt); memvirt = uctxt->rcvhdrq; + memdma = uctxt->rcvhdrq_dma;break ;case RCV_EGRBUF : { -unsigned long addr; +unsigned long vm_start_save; +unsigned long vm_end_save;int i;/* * The RcvEgr buffer need to be handled differently
@@ -404,24 +425,34 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) goto done; } vma->vm_flags &= ~VM_MAYWRITE ; - addr = vma->vm_start; +/* +* Mmap multiple separate allocations into a single vma. From +* here, dma_mmap_coherent() calls dma_direct_mmap(), which +* requires the mmap to exactly fill the vma starting at +* vma_start. Adjust the vma start and end for each eager +* buffer segment mapped. Restore the originals when done. +*/ + vm_start_save = vma->vm_start; + vm_end_save = vma->vm_end; + vma->vm_end = vma->vm_start;for (i =0 ; i < uctxt->egrbufs.numbufs; i++) { memlen = uctxt->egrbufs.buffers[i].len; memvirt = uctxt->egrbufs.buffers[i].addr; - ret =remap_pfn_range ( - vma, addr, -/* -* virt_to_pfn() does the same, but -* it's not available on x86_64 -* when CONFIG_MMU is enabled. -*/ -PFN_DOWN (__pa (memvirt)), - memlen, - vma->vm_page_prot); -if (ret <0 ) + memdma = uctxt->egrbufs.buffers[i].dma; + vma->vm_end += memlen; +mmap_cdbg (ctxt, subctxt, type, mapio, vmf, memaddr, + memvirt, memdma, memlen, vma); + ret =dma_mmap_coherent (&dd->pcidev->dev, vma, + memvirt, memdma, memlen); +if (ret <0 ) { + vma->vm_start = vm_start_save; + vma->vm_end = vm_end_save; goto done; - addr += memlen; + } + vma->vm_start += memlen; } + vma->vm_start = vm_start_save; + vma->vm_end = vm_end_save; ret =0 ; goto done; }
@@ -481,6 +512,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) } memlen =PAGE_SIZE ; memvirt = (void *)hfi1_rcvhdrtail_kvaddr (uctxt); + memdma = uctxt->rcvhdrqtailaddr_dma; flags &= ~VM_MAYWRITE ;break ;case SUBCTXT_UREGS :
@@ -529,14 +561,15 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) } vma->vm_flags = flags; -hfi1_cdbg (PROC , -"%u:%u type:%u io/vf:%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx\n" , - ctxt, subctxt, type, mapio, vmf, memaddr, memlen, - vma->vm_end - vma->vm_start, vma->vm_flags); +mmap_cdbg (ctxt, subctxt, type, mapio, vmf, memaddr, memvirt, memdma, + memlen, vma);if (vmf) { vma->vm_pgoff =PFN_DOWN (memaddr); vma->vm_ops = &vm_ops; ret =0 ; + }else if (memdma) { + ret =dma_mmap_coherent (&dd->pcidev->dev, vma, + memvirt, memdma, memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/2857 IB/hfi1: Resolve the credit-return buffer through the send contexts node
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
[ Upstream commit 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b ]
hfi1_file_mmap()'s PIO_CRED case derives this context's credit-return page offset, and the DMA handle for it, from dd->cr_base[uctxt->numa_id]. uctxt->numa_id is the node of whichever CPU the process happened to be running on, but the entry itself lives in the credit-return allocation of the send context's own node:
sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index];
and user send contexts are allocated with sc_alloc(dd, SC_USER, ..., dd->node), the HFI-local node. On a multi-socket host with the process running off that node the two allocations differ, so the subtraction produces an offset into an unrelated buffer and the DMA handle belongs to the wrong allocation.
Use the send context's own node for all three references. The continuation lines are reindented at the same time; they mixed spaces and tabs.
--- drivers/infiniband/hw/hfi1/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +4 -4
@@ -384,10 +384,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* of enabled contexts > 64 and 128 respectively). */ cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) & -PAGE_MASK ; - memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; - memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; + (u64 )dd->cr_base[uctxt->sc->node].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; + memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/2857 IB/hfi1: Fix the PIO_CRED credit-return mmap
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
[ Upstream commit 62f0f34fbd2b2d5653d33d3b9d42fdcabb1c0101 ]
hfi1_file_mmap()'s PIO_CRED case must hand user space the single credit-return page that holds this context's entry. That page is the second or third page of the per-node credit-return allocation once the hardware send context index reaches 64 or 128, so the failure below is
intermittent: when the entry lands on the first page the offset is zero and everything works.
Two things are wrong.
First, cr_page_offset is a byte offset but .va is a struct credit_return *, so adding it is pointer arithmetic and scales the offset by sizeof(struct credit_return) == 64. memvirt then lands 256 KiB or 512 KiB past a 10240-byte allocation. With an IOMMU translating, that address is inside the vmalloc range but in no vm_area, so dma_mmap_coherent() -> iommu_dma_mmap() finds no pages, vmalloc_to_pfn() returns page_to_pfn(NULL), and remap_pfn_range() installs a frame above MAXPHYADDR. The first user read then takes:
psm2_ep_open_pr: Corrupted page table at address 7a14d007e000 PGD 800000013886a067 P4D 800000013886a067 PUD 13886b067 PMD 13886c067
PTE 800049168e911235 Oops: Bad pagetable: 000d [#1] SMP PTI
Second, and still wrong once the arithmetic is corrected, dma_mmap_coherent() describes a whole coherent buffer and selects the page within it with vma->vm_pgoff. Offsetting cpu_addr has no effect:
for a vmap'd allocation iommu_dma_mmap() uses cpu_addr only to locate the vm_area and then maps pages[vm_pgoff], which hfi1_file_mmap() has just set to 0. User space therefore always receives the first credit-return page, every credit read is for the wrong context, and send PIO stalls forever.
Use the DMA API as intended: pass the base of the allocation with its full length and select the page with vm_pgoff. A separate length is needed because memlen must keep describing the VMA for the existing size check. The dma-direct path stays correct as well, since dma_direct_mmap() adds the same vm_pgoff to the base pfn.
Tested on a Dell T7610 (Xeon E5-2650 v2, Intel IOMMU in DMA-FQ mode) against a Threadripper PRO 3995WX peer, both Omni-Path 100. Before this change psm2_ep_open() Oopses the kernel; with only the arithmetic corrected psm2_ep_open() succeeds but any transfer that uses send PIO hangs, PSM2_SDMA=2 (send PIO disabled) completing normally while PSM2_SDMA=0 (send PIO only) hangs every time. With this change send PIO, send DMA and the default mixed mode all work.
--- drivers/infiniband/hw/hfi1/file_ops.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +16 -5
@@ -328,6 +328,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)void *memvirt =NULL ;dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type; +size_t memdmalen =0 ;ssize_t memlen =0 ;int ret =0 ;u16 ctxt;
@@ -373,7 +374,9 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) mapio =1 ;break ;case PIO_CRED : { +struct credit_return_base *cr = &dd->cr_base[uctxt->sc->node];u64 cr_page_offset; +if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -383,11 +386,18 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->sc->node].va) & + cr_page_offset = ((u64 )uctxt->sc->hw_free - (u64 )cr->va) &PAGE_MASK ; - memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; - memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; +/* +* dma_mmap_coherent() describes the whole coherent buffer and +* selects the page within it with vma->vm_pgoff, so pass the +* base of the allocation and its length and let vm_pgoff pick +* the page. +*/ + vma->vm_pgoff = cr_page_offset >>PAGE_SHIFT ; + memvirt = cr->va; + memdma = cr->dma; + memdmalen =TXE_NUM_CONTEXTS *sizeof (struct credit_return ); memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -569,7 +579,8 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) ret =0 ; }else if (memdma) { ret =dma_mmap_coherent (&dd->pcidev->dev, vma, - memvirt, memdma, memlen); + memvirt, memdma, + memdmalen ? memdmalen : memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/2857 usb: cdnsp: fix wakeup from S3 after controller context loss
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pawel Laszczak <[email protected]>
[ Upstream commit eae6460f617382044c5afe5ef202f4d8b2c099b5 ]
CDNSP controller may lose its runtime register programming across S3 suspend/resume, depending on SoC power domain configuration. After resume the operational and interrupter registers may contain reset values, which prevents the gadget side from recovering correctly and breaks wakeup from S3.
Fix this by detecting whether the controller lost its register context after resume and handling both cases:
- If context was lost (CFG_3XPORT_U1_PIPE_CLK_GATE_EN set or power lost): reset the controller and reprogram the state required for normal operation, including the command ring, DCBAA pointer, doorbell base, event ring, ERST base/size and event ring dequeue pointer.
- If context was retained: restart the controller directly without reprogramming registers. Issue a wakeup if the link was in U3 before suspend.
Move the basic controller register programming out of the one-time memory initialization path and make it reusable from the resume path. Also separate ring allocation from ring initialization so that rings can be reinitialized without reallocating DMA memory.
Always perform the full suspend sequence regardless of the current link state. Previously, if the device was already in U3, the suspend callback returned early without stopping the controller, which could lead to commands being issued on a disabled slot during resume.
--- drivers/usb/cdns3/cdnsp-gadget.c | 111 +++++++++++++++++++++++++++++-- drivers/usb/cdns3/cdnsp-gadget.h | 1 + drivers/usb/cdns3/cdnsp-mem.c | 98 ++++++++++----------------- 3 files changed, 143 insertions(+), 67 deletions(-)
drivers/usb/cdns3/cdnsp-gadget.c +107 -4
@@ -1819,6 +1819,82 @@ static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) readl(&pdev->rev_cap->tx_buff_size)); } +static void cdnsp_set_event_deq (struct cdnsp_device *pdev) +{ +dma_addr_t deq; +u64 temp; + + deq =cdnsp_trb_virt_to_dma (pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + +/* Update controller event ring dequeue pointer */ + temp =cdnsp_read_64 (&pdev->ir_set->erst_dequeue); + temp &=ERST_PTR_MASK ; + +/* +* Don't clear the EHB bit (which is RW1C) because +* there might be more events to service. +*/ + temp &= ~ERST_EHB ; + +cdnsp_write_64 (((u64 )deq & (u64 )~ERST_PTR_MASK ) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_interrupter (struct cdnsp_device *pdev) +{ +u64 erst_base; +u32 erst_size; + +/* Set ERST count with the number of entries in the segment table. */ + erst_size =readl (&pdev->ir_set->erst_size); + erst_size &=ERST_SIZE_MASK ; + erst_size |=ERST_NUM_SEGS ; +writel (erst_size, &pdev->ir_set->erst_size); + +/* Set the segment table base address. */ + erst_base =cdnsp_read_64 (&pdev->ir_set->erst_base); + erst_base &=ERST_PTR_MASK ; + erst_base |= (pdev->erst.erst_dma_addr & (u64 )~ERST_PTR_MASK ); +cdnsp_write_64 (erst_base, &pdev->ir_set->erst_base); + +/* Set the event ring dequeue address. */ +cdnsp_set_event_deq (pdev); +} + +/* Set up basic CDNSP registers */ +static void cdnsp_init (struct cdnsp_device *pdev) +{ +unsigned int val; +u64 val_64; + + val =readl (&pdev->op_regs->config_reg); + val |= ((val & ~MAX_DEVS ) |CDNSP_DEV_MAX_SLOTS ) |CONFIG_U3E ; +writel (val, &pdev->op_regs->config_reg); + +/* Initialize the Command ring */ +cdnsp_ring_init (pdev, pdev->cmd_ring); + +/* Set the address in the Command Ring Control register */ + val_64 =cdnsp_read_64 (&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64 )CMD_RING_RSVD_BITS ) | + (pdev->cmd_ring->first_seg->dma & (u64 )~CMD_RING_RSVD_BITS ) | + pdev->cmd_ring->cycle_state; +cdnsp_write_64 (val_64, &pdev->op_regs->cmd_ring); + +/* Set Device Context Base Address Array pointer */ +cdnsp_write_64 (pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr); + +/* Set Doorbell array pointer */ + val =readl (&pdev->cap_regs->db_off); + val &=DBOFF_MASK ; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + +/* Initialize the Primary interrupter */ +cdnsp_ring_init (pdev, pdev->event_ring); +cdnsp_add_interrupter (pdev); +} +static int cdnsp_gen_setup (struct cdnsp_device *pdev) {int ret;
@@ -1884,6 +1960,8 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)if (ret)return ret; +cdnsp_init (pdev); +/* * Software workaround for U1: after transition * to U1 the controller starts gating clock, and in some cases,
@@ -2014,9 +2092,6 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)struct cdnsp_device *pdev = cdns->gadget_dev;unsigned long flags; -if (pdev->link_state ==XDEV_U3 ) -return 0 ; -spin_lock_irqsave (&pdev->lock, flags);cdnsp_disconnect_gadget (pdev);cdnsp_stop (pdev);
@@ -2030,12 +2105,38 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated)struct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;unsigned long flags; +bool context_lost; +u32 val;int ret;if (!pdev->gadget_driver)return 0 ;spin_lock_irqsave (&pdev->lock, flags); + val =readl (&pdev->port3x_regs->mode_2); + context_lost = !!(val &CFG_3XPORT_U1_PIPE_CLK_GATE_EN ) || hibernated; + +if (context_lost) { +cdnsp_halt (pdev); +cdnsp_set_apb_timeout_value (pdev); + +/* Reset the internal controller memory state and registers. */ + ret =cdnsp_reset (pdev); +if (ret) + goto unlock; + + val =readl (&pdev->port3x_regs->mode_2); + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN ; +writel (val, &pdev->port3x_regs->mode_2); + +cdnsp_clear_cmd_ring (pdev); + +memset (pdev->event_ring->first_seg->trbs,0 , +sizeof (union cdnsp_trb ) * (TRBS_PER_SEGMENT )); + +cdnsp_init (pdev); + } + max_speed = pdev->gadget_driver->max_speed;/* Limit speed if necessary. */
@@ -2043,9 +2144,11 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated) ret =cdnsp_run (pdev, max_speed); -if (pdev->link_state ==XDEV_U3 ) +if (!context_lost && pdev->active_port && + pdev->link_state ==XDEV_U3 )__cdnsp_gadget_wakeup (pdev); +unlock:spin_unlock_irqrestore (&pdev->lock, flags);return ret;
drivers/usb/cdns3/cdnsp-gadget.h +1 -0
@@ -1509,6 +1509,7 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,int cdnsp_ring_expansion (struct cdnsp_device *pdev,struct cdnsp_ring *ring,unsigned int num_trbs,gfp_t flags); +void cdnsp_ring_init (struct cdnsp_device *pdev,struct cdnsp_ring *ring);struct cdnsp_ring *cdnsp_dma_to_transfer_ring (struct cdnsp_ep *ep,u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep,
drivers/usb/cdns3/cdnsp-mem.c +35 -63
166 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/2857 ALSA: hda/realtek: Add quirk for TongFang X6xx45xU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eckhart Mohr <[email protected]>
[ Upstream commit d595255241e5fec0c94adeebf2565524398e37c5 ]
Fix microphone detection on built in headphone jack for some devices.
Stable-dep-of: e72d5659a260 ("ALSA: hda/realtek: Add quirk for TongFang XxAF5xxx")
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10495,6 +10495,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1d05 ,0x300f ,"TongFang X6AR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3019 ,"TongFang X6FR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3031 ,"TongFang X6AR55xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6xx45xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d17 ,0x3288 ,"Haier Boyue G42" ,ALC269VC_FIXUP_ACER_VCOPPERBOX_PINS ),SND_PCI_QUIRK (0x1d72 ,0x1602 ,"RedmiBook" ,ALC255_FIXUP_XIAOMI_HEADSET_MIC ), SND_PCI_QUIRK(0x1d72, 0x1701, "XiaomiNotebook Pro", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/2857 ublk: clear VM_MAYWRITE on read-only ublk char device mmap
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kanishka De Silva <[email protected]>
[ Upstream commit 6e2b571b0a54755b06e092501913e1dfefe75d6c ]
ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.
The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.
Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).
Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.
--- drivers/block/ublk_drv.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/block/ublk_drv.c +6 -0
@@ -980,6 +980,12 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)if (vma->vm_flags &VM_WRITE )return -EPERM ; +/* +* The per-queue command buffer is kernel-written ABI; prevent +* the daemon from upgrading to writable via mprotect(). +*/ + vma->vm_flags &= ~VM_MAYWRITE ; + end =UBLKSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;if (phys_off <UBLKSRV_CMD_BUF_OFFSET || phys_off >= end)return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/2857 memcg: make the v1 soft limit knob inert
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
[ Upstream commit a3417097fb107cea3358b19bcbb4eb655fd67f8c ]
The v1 soft limit has been deprecated since v6.12 and nobody has reported depending on it. Start the removal by decoupling the interface from the
implementation: keep memory.soft_limit_in_bytes, but ignore writes to it and always report the maximum value on read similar to what memory.kmem.limit_in_bytes already does.
Writes are still parsed, so malformed input keeps returning -EINVAL. The knob now also behaves the same everywhere: it used to return -EOPNOTSUPP on PREEMPT_RT, where soft limit reclaim has always been disabled.
This also fixes the syzbot report linked below. Soft limit reclaim is the only caller that runs shrink_lruvec() from kswapd against a specific memcg, so it is the only way to reach lru_gen_shrink_lruvec() and in turn set_mm_walk(), which warns when called from kswapd.
--- .../admin-guide/cgroup-v1/memory.rst | 46 +++---------------- mm/memcontrol.c | 40 ++++++++++------ 2 files changed, 32 insertions(+), 54 deletions(-)
Documentation/admin-guide/cgroup-v1/memory.rst +6 -40
@@ -47,7 +47,6 @@ Features: - pages are linked to per-memcg LRU exclusively, and there is no global LRU. - optionally, memory+swap usage can be accounted and limited. - hierarchical accounting - - soft limit - moving (recharging) account at moving a task is selectable. - usage threshold notifier - memory pressure notifier
@@ -75,8 +74,9 @@ Brief summary of control files. memory.memsw.failcnt show the number of memory+Swap hits limits memory.max_usage_in_bytes show max memory usage recorded memory.memsw.max_usage_in_bytes show max memory+Swap usage recorded - memory.soft_limit_in_bytes set/show soft limit of memory usage - This knob is not available on CONFIG_PREEMPT_RT systems. + memory.soft_limit_in_bytes This knob is deprecated and has no effect. + Writes are ignored and reads always + return the maximum value. memory.stat show various statistics memory.use_hierarchy set/show hierarchical account enabled This knob is deprecated and shouldn't be
@@ -326,9 +326,6 @@ memory.kmem.usage_in_bytes, or in a separate counter when it makes sense. The main "kmem" counter is fed into the main counter, so kmem charges will also be visible from the user counter. -Currently no soft limit is implemented for kernel memory. It is future work -to trigger slab reclaim when those limits are reached. - 2.7.1 Current Kernel Memory resources accounted -----------------------------------------------
@@ -687,41 +684,10 @@ For compatibility reasons writing 1 to memory.use_hierarchy will always pass:: 7. Soft limits ============== -Soft limits allow for greater sharing of memory. The idea behind soft limits -is to allow control groups to use as much of the memory as needed, provided - -a. There is no memory contention -b. They do not exceed their hard limit - -When the system detects memory contention or low memory, control groups -are pushed back to their soft limits. If the soft limit of each control -group is very high, they are pushed back as much as possible to make -sure that one control group does not starve the others of memory. - -Please note that soft limits is a best-effort feature; it comes with -no guarantees, but it does its best to make sure that when memory is -heavily contended for, memory is allocated based on the soft limit -hints/setup. Currently soft limit based reclaim is set up such that -it gets invoked from balance_pgdat (kswapd). - -7.1 Interface -------------- - -Soft limits can be setup by using the following commands (in this example we -assume a soft limit of 256 MiB):: - - # echo 256M > memory.soft_limit_in_bytes - -If we want to change this to 1G, we can at any time use:: - - # echo 1G > memory.soft_limit_in_bytes +Writing to memory.soft_limit_in_bytes has no effect and reading it will +always return the maximum value. -NOTE1: - Soft limits take effect over a long period of time, since they involve - reclaiming memory for balancing between memory cgroups -NOTE2: - It is recommended to set the soft limit always below the hard limit, - otherwise the hard limit will take precedence. +Use memory.low and memory.min in cgroup v2 instead. 8. Move charges at task migration (DEPRECATED!) ===============================================
mm/memcontrol.c +26 -14
@@ -3689,9 +3689,32 @@ enum {RES_LIMIT ,RES_MAX_USAGE , RES_FAILCNT, - RES_SOFT_LIMIT, }; +static u64 mem_cgroup_soft_limit_read (struct cgroup_subsys_state *css, +struct cftype *cft) +{ +return (u64 )PAGE_COUNTER_MAX *PAGE_SIZE ; +} + +static ssize_t mem_cgroup_soft_limit_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +unsigned long nr_pages; +int ret; + + ret =page_counter_memparse (strstrip (buf),"-1" , &nr_pages); +if (ret) +return ret; + +pr_warn_once ("soft_limit_in_bytes is deprecated and will be removed. " +"Writing any value to this file has no effect. " +"Please report your usecase to [email protected] if you " +"depend on this functionality.\n" ); + +return nbytes; +} +static u64 mem_cgroup_read_u64 (struct cgroup_subsys_state *css,struct cftype *cft) {
@@ -3728,8 +3751,6 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,return (u64 )counter->watermark *PAGE_SIZE ;case RES_FAILCNT :return counter->failcnt; -case RES_SOFT_LIMIT : -return (u64 )memcg->soft_limit *PAGE_SIZE ;default :BUG (); }
@@ -3870,14 +3891,6 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,break ; }break ; -case RES_SOFT_LIMIT : -if (IS_ENABLED (CONFIG_PREEMPT_RT )) { - ret = -EOPNOTSUPP ; - }else { - memcg->soft_limit = nr_pages; - ret =0 ; - } -break ; }return ret ?: nbytes; }
@@ -5026,9 +5039,8 @@ static struct cftype mem_cgroup_legacy_files[] = { }, { .name = "soft_limit_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT), - .write = mem_cgroup_write, - .read_u64 = mem_cgroup_read_u64, + .write = mem_cgroup_soft_limit_write, + .read_u64 = mem_cgroup_soft_limit_read, }, { .name = "failcnt",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/2857 ALSA: rawmidi: Return the error from snd_rawmidi_input_params()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit f4a23e17d84fd2a152d9e12369761934e1af0ee8 ]
The snd_rawmidi_input_params() computes err for the three invalid mode combinations and for resize_runtime_buffer(), applies the new framing and clock type only when err is zero, and then returns 0 anyway. A caller that asked for parameters the kernel rejected is told the change succeeded, and the substream keeps its old buffer.
The open_mutex conversion turned the early returns into assignments. It handled the output sibling correctly, which still returns err, and left this one behind.
--- sound/core/rawmidi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/rawmidi.c +1 -1
@@ -793,7 +793,7 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, substream->clock_type = clock_type; }mutex_unlock (&substream->rmidi->open_mutex); -return 0 ; +return err; }EXPORT_SYMBOL (snd_rawmidi_input_params);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/2857 dm-integrity: fix NULL pointer dereference when the R flag is used
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit 7d4d4f3b668d708d94f62ecdd33ac330a6fd8a84 ]
If the dm-integrity device has the SB_FLAG_DIRTY_BITMAP flag set and the user activates the device in the 'R' mode, a crash in dm_integrity_resume happens because the function attempts to read the journal containing the bitmap.
This patch makes dm-integrity skip any writes to the device in dm_integrity_resume if the device is activated in the 'R' mode.
--- drivers/md/dm-integrity.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/md/dm-integrity.c +5 -0
@@ -3253,6 +3253,10 @@ static void dm_integrity_resume(struct dm_target *ti) r =sync_rw_sb (ic,REQ_OP_READ );if (r)dm_integrity_io_error (ic,"reading superblock" , r); + +if (ic->mode =='R' ) + goto skip_writes; +if ((ic->sb->flags & flags) != flags) { ic->sb->flags |= flags; r =sync_rw_sb (ic,REQ_OP_WRITE |REQ_FUA );
@@ -3362,6 +3366,7 @@ static void dm_integrity_resume(struct dm_target *ti) } } +skip_writes: ic->reboot_notifier.notifier_call = dm_integrity_reboot; ic->reboot_notifier.next =NULL ; ic->reboot_notifier.priority =INT_MAX -1 ;/* be notified after md and before hardware drivers */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/2857 drm/amdgpu: Skip accessing psp rum time db for APUs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kanala Ramalingeswara Reddy <[email protected]>
[ Upstream commit a26301203a196a991527f7b1ab884d4dd0e7c95e ]
Psp runtime DB is for dGPUs only.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +6 -0
@@ -266,6 +266,12 @@ static bool psp_get_runtime_db_entry(struct amdgpu_device *adev,bool ret = false;int i; +/* +* Runtime DB is for dGPUs only. +*/ +if (adev->flags &AMD_IS_APU ) +return false; + db_header_pos = adev->gmc.mc_vram_size -PSP_RUNTIME_DB_OFFSET ; db_dir_pos = db_header_pos +sizeof (struct psp_runtime_data_header );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/2857 smb: client: pin DFS superblock in iterator callback
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit d806d5a85dcbe2a0f181b2f0f9f61ddfbefa1818 ]
tcon_super_cb() stores a raw superblock pointer, but __cifs_get_super() takes its active reference only after iterate_supers_type() has dropped s_umount and its passive reference. Concurrent DFS automount expiry can therefore free the superblock before cifs_sb_active() uses it.
A deterministic KASAN test reproduces the race as:
BUG: KASAN: slab-use-after-free in cifs_sb_active+0x77/0x80
The same test passes with this change applied.
Take the active reference in the callback while iterate_supers_type() still holds s_umount shared. cifs_put_tcp_super() remains the matching release.
--- fs/smb/client/misc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
fs/smb/client/misc.c +8 -9
@@ -1379,8 +1379,14 @@ static void tcp_super_cb(struct super_block *sb, void *arg) cifs_sb =CIFS_SB (sb); tcon =cifs_sb_master_tcon (cifs_sb); -if (tcon->ses->server == server) +if (tcon->ses->server == server) { +/* +* Take the active reference while iterate_supers_type() still +* holds s_umount shared. +*/ +cifs_sb_active (sb); sd->sb = sb; + } } static struct super_block *__cifs_get_super(void (*f)(struct super_block *, void *),
@@ -1396,15 +1402,8 @@ static struct super_block *__cifs_get_super(void (*f)(struct super_block *, voidfor (; *fs_type; fs_type++) {iterate_supers_type (*fs_type, f, &sd); -if (sd.sb) { -/* -* Grab an active reference in order to prevent automounts (DFS links) -* of expiring and then freeing up our cifs superblock pointer while -* we're doing failover. -*/ -cifs_sb_active (sd.sb); +if (sd.sb)return sd.sb; - } }return ERR_PTR (-EINVAL ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/2857 mmc: mmc-hsq: Use fifo to dispatch mmc_request
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Wu <[email protected]>
[ Upstream commit e026a3f9172f5c9aacff270b929a166c3ea1b6f7 ]
Current next_tag selection will cause a large delay in some requests and destroy the scheduling results of the block scheduling layer. Because the issued mrq tags cannot ensure that each time is sequential, especially when the IO load is heavy. In the fio performance test, we found that 4k random read data was sent to mmc_hsq to start calling request_atomic It takes nearly 200ms to process the request, while mmc_hsq has processed thousands of other requests. So we use fifo here to ensure the first in, first out feature of the request and avoid adding additional delay to the request.
Stable-dep-of: 5d132990475f ("mmc: hsq: Fix use-after-free in retry work")
--- drivers/mmc/host/mmc_hsq.c | 40 ++++++++++++++------------------------ drivers/mmc/host/mmc_hsq.h | 5 +++++ 2 files changed, 20 insertions(+), 25 deletions(-)
drivers/mmc/host/mmc_hsq.c +15 -25
@@ -13,9 +13,6 @@#include "mmc_hsq.h" -#define HSQ_NUM_SLOTS 64 -#define HSQ_INVALID_TAG HSQ_NUM_SLOTS -static void mmc_hsq_retry_handler (struct work_struct *work) { struct mmc_hsq *hsq = container_of(work, struct mmc_hsq, retry_work);
@@ -73,7 +70,6 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq)static void mmc_hsq_update_next_tag (struct mmc_hsq *hsq,int remains) { -struct hsq_slot *slot;int tag;/*
@@ -82,29 +78,12 @@ static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains)*/ if (!remains) { hsq->next_tag =HSQ_INVALID_TAG ; + hsq->tail_tag =HSQ_INVALID_TAG ;return ; } -/* -* Increasing the next tag and check if the corresponding request is -* available, if yes, then we found a candidate request. -*/ -if (++hsq->next_tag !=HSQ_INVALID_TAG ) { - slot = &hsq->slot[hsq->next_tag]; -if (slot->mrq) -return ; - } - -/* Othersie we should iterate all slots to find a available tag. */ -for (tag =0 ; tag <HSQ_NUM_SLOTS ; tag++) { - slot = &hsq->slot[tag]; -if (slot->mrq) -break ; - } - -if (tag ==HSQ_NUM_SLOTS ) - tag =HSQ_INVALID_TAG ; - + tag = hsq->tag_slot[hsq->next_tag]; + hsq->tag_slot[hsq->next_tag] =HSQ_INVALID_TAG ; hsq->next_tag = tag; }
@@ -233,8 +212,14 @@ static int mmc_hsq_request(struct mmc_host *mmc, struct mmc_request *mrq)* Set the next tag as current request tag if no available * next tag. */ -if (hsq->next_tag ==HSQ_INVALID_TAG ) +if (hsq->next_tag ==HSQ_INVALID_TAG ) { hsq->next_tag = tag; + hsq->tail_tag = tag; + hsq->tag_slot[hsq->tail_tag] =HSQ_INVALID_TAG ; + }else { + hsq->tag_slot[hsq->tail_tag] = tag; + hsq->tail_tag = tag; + } hsq->qcnt++;
@@ -339,8 +324,10 @@ static const struct mmc_cqe_ops mmc_hsq_ops = {int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ; + hsq->tail_tag =HSQ_INVALID_TAG ; hsq->slot =devm_kcalloc (mmc_dev (mmc), hsq->num_slots,sizeof (struct hsq_slot ),GFP_KERNEL );
@@ -351,6 +338,9 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) hsq->mmc->cqe_private = hsq; mmc->cqe_ops = &mmc_hsq_ops; +for (i =0 ; i <HSQ_NUM_SLOTS ; i++) + hsq->tag_slot[i] =HSQ_INVALID_TAG ; +INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler);spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
drivers/mmc/host/mmc_hsq.h +5 -0
@@ -2,6 +2,9 @@#ifndef LINUX_MMC_HSQ_H #define LINUX_MMC_HSQ_H +#define HSQ_NUM_SLOTS 64 +#define HSQ_INVALID_TAG HSQ_NUM_SLOTS +struct hsq_slot {struct mmc_request *mrq; };
@@ -17,6 +20,8 @@ struct mmc_hsq {int next_tag;int num_slots;int qcnt; +int tail_tag; +int tag_slot[HSQ_NUM_SLOTS ];bool enabled;bool waiting_for_idle;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/2857 mmc: hsq: Fix use-after-free in retry work
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 5d132990475f02cfa1debe03d50b479432864ebd ]
mmc_hsq_pump_requests() queues retry_work when request_atomic() returns -EBUSY; today sdhci-sprd is the only consumer that implements request_atomic(). The work is embedded in a devm-allocated mmc_hsq, but is never cancelled during driver removal. Work still pending at unbind can therefore run after the devm allocation has been released and dereference hsq->mmc and hsq->mrq.
Use devm_work_autocancel() to cancel and drain retry_work before the devm allocation is released. By the time devres cleanup begins, mmc_remove_host() has already stopped the host, so no new requests can arm the work.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmc_hsq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/host/mmc_hsq.c +7 -1
@@ -7,6 +7,7 @@* Author: Baolin Wang <[email protected]> */ +#include <linux/devm-helpers.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/module.h>
@@ -324,6 +325,7 @@ static const struct mmc_cqe_ops mmc_hsq_ops = {int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int ret;int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ;
@@ -341,7 +343,11 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)for (i =0 ; i <HSQ_NUM_SLOTS ; i++) hsq->tag_slot[i] =HSQ_INVALID_TAG ; -INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler); + ret =devm_work_autocancel (mmc_dev (mmc), &hsq->retry_work, + mmc_hsq_retry_handler); +if (ret) +return ret; +spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/2857 irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ju Nan <[email protected]>
[ Upstream commit d31fbbade43f880b7e59e2b3a72722fe2725d93f ]
HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:
atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
if (atomic_delay > to * 1000)
return -ETIMEDOUT;So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.
The hwspinlock core documents this explicitly:
If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.
--- drivers/irqchip/irq-stm32-exti.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/irqchip/irq-stm32-exti.c +3 -3
@@ -24,7 +24,7 @@#define IRQS_PER_BANK 32 -#define HWSPNLCK_TIMEOUT 1000/* usec */ +#define HWSPNLCK_TIMEOUT_MS 1struct stm32_exti_bank {u32 imr_ofst;
@@ -363,7 +363,7 @@ static int stm32_irq_set_type(struct irq_data *d, unsigned int type)irq_gc_lock (gc);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
@@ -567,7 +567,7 @@ static int stm32_exti_h_set_type(struct irq_data *d, unsigned int type)raw_spin_lock (&chip_data->rlock);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/2857 ALSA: usbusx2y: validate URB actual_length in interrupt callback
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
[ Upstream commit 8f5ef203abda9dd36b2af473c7b737d544f807bd ]
i_usx2y_in04_int() processes the interrupt URB data without checking urb->actual_length. A short transfer from a malfunctioning device would cause the handler to process uninitialized heap data from the kmalloc-allocated in04_buf, which is then copied to the mmap-accessible ctl_snapshot[] array.
Fix by using kzalloc() for in04_buf to zero-initialize the buffer, and adding an actual_length check to skip processing on short transfers while still resubmitting the URB.
--- sound/usb/usx2y/usbusx2y.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
sound/usb/usx2y/usbusx2y.c +6 -1
@@ -190,6 +190,10 @@ static void i_usx2y_in04_int(struct urb *urb) }// printk("%i:0x%02X ", 8, (int)((unsigned char*)usx2y->in04_buf)[8]); Master volume shows 0 here if fader is at max during boot ?!? + +if (urb->actual_length <USX2Y_IN04_SIZE ) + goto resubmit; +if (us428ctls) { diff =-1 ;if (us428ctls->ctl_snapshot_last ==-2 ) {
@@ -254,6 +258,7 @@ static void i_usx2y_in04_int(struct urb *urb)if (err)snd_printk (KERN_ERR "in04_int() usb_submit_urb err=%i\n" , err); +resubmit: urb->dev = usx2y->dev;usb_submit_urb (urb,GFP_ATOMIC ); }
@@ -306,7 +311,7 @@ int usx2y_in04_init(struct usx2ydev *usx2y) goto error; } - usx2y->in04_buf =kmalloc (USX2Y_IN04_SIZE ,GFP_KERNEL ); + usx2y->in04_buf =kzalloc (USX2Y_IN04_SIZE ,GFP_KERNEL );if (!usx2y->in04_buf) { err = -ENOMEM ; goto error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/2857 ALSA: hda/realtek: Add quirk for TongFang X6SP45xU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eckhart Mohr <[email protected]>
[ Upstream commit 26a94400ffa4fcbeff32e23abebb83a1a20eb401 ]
TongFang X6KK45xU and X6SP45xU have actually different PCI IDs. This patch Adds the missing PCI ID to fix headphone detection and clarifies the naming.
Stable-dep-of: e72d5659a260 ("ALSA: hda/realtek: Add quirk for TongFang XxAF5xxx")
--- sound/pci/hda/patch_realtek.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/pci/hda/patch_realtek.c +2 -1
@@ -10495,7 +10495,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1d05 ,0x300f ,"TongFang X6AR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3019 ,"TongFang X6FR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3031 ,"TongFang X6AR55xU" ,ALC2XX_FIXUP_HEADSET_MIC ), -SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6xx45xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x3033 ,"TongFang X6SP45xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6KK45xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d17 ,0x3288 ,"Haier Boyue G42" ,ALC269VC_FIXUP_ACER_VCOPPERBOX_PINS ),SND_PCI_QUIRK (0x1d72 ,0x1602 ,"RedmiBook" ,ALC255_FIXUP_XIAOMI_HEADSET_MIC ), SND_PCI_QUIRK(0x1d72, 0x1701, "XiaomiNotebook Pro", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/2857 xfs: strengthen the "is cow staging" helpers in scrub
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 0d43368844a75ad13561a1198a3b027940730756 ]
LOLLM pointed out a bug in both of the refcount scrub predicates that determine if a range of blocks is marked as CoW staging in the btree. While it compares blockcount < len, this isn't enough to determine that the CoW staging record is at least as large as the range passed into the helper. Fix both of them.
--- fs/xfs/scrub/refcount.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/refcount.c +5 -1
@@ -443,8 +443,12 @@ xchk_xref_is_cow_staging(if (rc.rc_domain !=XFS_REFC_DOMAIN_COW )xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Can't start after bno */ +if (rc.rc_startblock > agbno) +xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Must be at least as long as what was passed in */ -if (rc.rc_blockcount < len) +if (rc.rc_startblock + rc.rc_blockcount < agbno + len)xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/2857 path: add cleanup helper
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit ff2c570ef7eaa9ded58e7a02dd7a68874a897508 ]
Add a simple cleanup helper so we can cleanup struct path easily. No need for any extra machinery. Avoid DEFINE_FREE() as it causes a local copy of struct path to be used. Just rely on path_put() directly called from a cleanup helper.
Stable-dep-of: a7c1290eef60 ("configfs: pin the symlink target's dirent instead of chasing ->ci_dentry")
--- include/linux/path.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/path.h +9 -0
@@ -24,4 +24,13 @@ static inline void path_put_init(struct path *path) *path = (struct path) { }; } +/* +* Cleanup macro for use with __free(path_put). Avoids dereference and +* copying @path unlike DEFINE_FREE(). path_put() will handle the empty +* path correctly just ensure @path is initialized: +* +* struct path path __free(path_put) = {}; +*/ +#define __free_path_put path_put +#endif /* _LINUX_PATH_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/2857 configfs:get_target() - release path as soon as we grab configfs_item reference
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 1b25dea3867abc9bad6f0337d395c6f0ce4e4f6f ]
... and get rid of path argument - it turns into a local variable in get_target()
Stable-dep-of: a7c1290eef60 ("configfs: pin the symlink target's dirent instead of chasing ->ci_dentry")
--- fs/configfs/symlink.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
fs/configfs/symlink.c +13 -20
@@ -114,26 +114,21 @@ static int create_link(struct config_item *parent_item, } -static int get_target (const char *symname,struct path *path, -struct config_item **target,struct super_block *sb) +static int get_target (const char *symname,struct config_item **target, +struct super_block *sb) { + struct path path __free(path_put) = {};int ret; - ret =kern_path (symname,LOOKUP_FOLLOW |LOOKUP_DIRECTORY , path); -if (!ret) { -if (path->dentry->d_sb == sb) { - *target =configfs_get_config_item (path->dentry); -if (!*target) { - ret = -ENOENT ; -path_put (path); - } - }else { - ret = -EPERM ; -path_put (path); - } - } - -return ret; + ret =kern_path (symname,LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &path); +if (ret) +return ret; +if (path.dentry->d_sb != sb) +return -EPERM ; + *target =configfs_get_config_item (path.dentry); +if (!*target) +return -ENOENT ; +return 0 ; }
@@ -141,7 +136,6 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, const char *symname) { int ret; -struct path path;struct configfs_dirent *sd;struct config_item *parent_item;struct config_item *target_item =NULL ;
@@ -188,7 +182,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,* AV, a thoroughly annoyed bastard. */ inode_unlock (dir); - ret =get_target (symname, &path, &target_item, dentry->d_sb); + ret =get_target (symname, &target_item, dentry->d_sb);inode_lock (dir);if (ret) goto out_put;
@@ -210,7 +204,6 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, }config_item_put (target_item); -path_put (&path); out_put:config_item_put (parent_item);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/2857 configfs: pin the symlink targets dirent instead of chasing ->ci_dentry
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasileios Almpanis <[email protected]>
[ Upstream commit a7c1290eef60711c10289c056ad32ed1f2b47b12 ]
create_link() reads the target's configfs_dirent from item->ci_dentry->d_fsdata, relying on the item reference taken by get_target(). That reference pins the item, not its dentry: the dentry is pinned by DCACHE_PERSISTENT, which configfs_remove_dir() releases via simple_rmdir() while the item is still alive. A symlink racing with rmdir of its target can therefore find ->ci_dentry freed and its dirent released, triggering WARN_ON(!atomic_read(&sd->s_count)) in configfs_get().
Take the dirent in get_target() as well, under ->d_lock and atomically with the item reference, and pass it down to create_link(). A hashed dentry has not been killed yet, so its ->d_fsdata reference keeps the dirent alive there.
--- fs/configfs/symlink.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
fs/configfs/symlink.c +20 -4
@@ -76,9 +76,9 @@ static int configfs_get_target_path(struct config_item *item,static int create_link (struct config_item *parent_item,struct config_item *item, +struct configfs_dirent *target_sd,struct dentry *dentry) { -struct configfs_dirent *target_sd = item->ci_dentry->d_fsdata;char *body;int ret;
@@ -115,6 +115,7 @@ static int create_link(struct config_item *parent_item,static int get_target (const char *symname,struct config_item **target, +struct configfs_dirent **target_sd,struct super_block *sb) { struct path path __free(path_put) = {};
@@ -125,7 +126,20 @@ static int get_target(const char *symname, struct config_item **target,return ret;if (path.dentry->d_sb != sb)return -EPERM ; - *target =configfs_get_config_item (path.dentry); +/* +* A hashed dentry guarantees that neither the item nor the dirent +* have been released yet, as removals unhash before dropping. +* Grab both references here. An item reference alone would not keep +* ->ci_dentry alive. +*/ +spin_lock (&path.dentry->d_lock); +if (!d_unhashed (path.dentry)) { +struct configfs_dirent *sd = path.dentry->d_fsdata; + + *target =config_item_get (sd->s_element); + *target_sd =configfs_get (sd); + } +spin_unlock (&path.dentry->d_lock);if (!*target)return -ENOENT ;return 0 ;
@@ -139,6 +153,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,struct configfs_dirent *sd;struct config_item *parent_item;struct config_item *target_item =NULL ; +struct configfs_dirent *target_sd =NULL ;const struct config_item_type *type; sd = dentry->d_parent->d_fsdata;
@@ -182,7 +197,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,* AV, a thoroughly annoyed bastard. */ inode_unlock (dir); - ret =get_target (symname, &target_item, dentry->d_sb); + ret =get_target (symname, &target_item, &target_sd, dentry->d_sb);inode_lock (dir);if (ret) goto out_put;
@@ -196,13 +211,14 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, ret = type->ct_item_ops->allow_link (parent_item, target_item);if (!ret) {mutex_lock (&configfs_symlink_mutex); - ret =create_link (parent_item, target_item, dentry); + ret =create_link (parent_item, target_item, target_sd, dentry);mutex_unlock (&configfs_symlink_mutex);if (ret && type->ct_item_ops->drop_link) type->ct_item_ops->drop_link (parent_item, target_item); } +configfs_put (target_sd);config_item_put (target_item); out_put:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/2857 configfs: unhash the dentry before dropping the item in rmdir
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasileios Almpanis <[email protected]>
[ Upstream commit f06c2d26d1999d37e93299db0ecead04ca7d0b9f ]
configfs_get_config_item() treats a hashed dentry as proof that sd->s_element is a live config_item. configfs_rmdir() breaks that:simple_rmdir() leaves the dentry hashed, the last reference to the item is dropped right after, and the dentry is only unhashed by d_delete() once ->rmdir() has returned. configfs_symlink() resolves its target holding no lock on it, so get_target() can land in that window:
BUG: KASAN: slab-use-after-free in config_item_get+0x26/0x90 get_target fs/configfs/symlink.c:128 [inline] configfs_symlink+0x4ab/0x1030 fs/configfs/symlink.c:185
Unhash in configfs_remove_dir(), while the item is still guaranteed to be there. A reference obtained just before that stays harmless, as create_link() rechecks CONFIGFS_USET_DROPPING, already set by configfs_detach_prep(). Both configfs_unregister_subsystem() paths d_drop() after detaching, so this only makes rmdir match them.
--- fs/configfs/dir.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/configfs/dir.c +11 -2
@@ -395,8 +395,17 @@ static void remove_dir(struct dentry * d)configfs_remove_dirent (d); -if (d_really_is_positive (d)) -simple_rmdir (d_inode (parent),d); +if (d_really_is_positive (d)) { +if (!simple_rmdir (d_inode (parent), d)) +/* +* configfs_get_config_item() takes a hashed dentry as +* proof that ->s_element is still alive. Our caller +* is about to drop the last reference to the item and +* the VFS will not unhash until after we return, so +* unhash it here. +*/ +d_drop (d); + }pr_debug (" o %pd removing done (%d)\n" , d,d_count (d));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/2857 EDAC/altera: Use ECC manager compatible to select A10/S10 IRQ layout
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rounak Das <[email protected]>
[ Upstream commit d4486fc3098e176cb4a29fee037216484761f9ca ]
The SDMMC ECC IRQ layout selection uses CONFIG_64BIT to distinguish between Arria10 and Stratix10 paths.
Detect the SoC once at probe via the device match table (.data) store it in struct altr_arria10_edac, and use it instead of CONFIG_64BIT.
This keeps the decision correct for every ECC child device (OCRAM, SD/MMC, etc.) and avoids any runtime compatible lookup.
Stable-dep-of: 9868f5c077df ("EDAC/altera: Use parent device for devres in altr_portb_setup()")
--- drivers/edac/altera_edac.c | 107 +++++++++++++++++++------------------ drivers/edac/altera_edac.h | 1 + 2 files changed, 55 insertions(+), 53 deletions(-)
drivers/edac/altera_edac.c +54 -53
@@ -1517,6 +1517,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)int edac_idx, rc;struct device_node *np;const struct edac_device_prv_data *prv = &a10_sdmmceccb_data; +bool is_s10 = device->edac->is_s10; rc =altr_check_ecc_deps (device);if (rc)
@@ -1558,15 +1559,14 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)/* * Update the PortB IRQs - A10 has 4, S10 has 2, Index accordingly -* -* FIXME: Instead of ifdefs with different architectures the driver -* should properly use compatibles. */ -#ifdef CONFIG_64BIT - altdev->sb_irq =irq_of_parse_and_map (np,1 ); -#else - altdev->sb_irq =irq_of_parse_and_map (np,2 ); -#endif + +/* Using compatibles to determine the IRQ Index */ +if (is_s10) + altdev->sb_irq =irq_of_parse_and_map (np,1 ); +else + altdev->sb_irq =irq_of_parse_and_map (np,2 ); +if (!altdev->sb_irq) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB SBIRQ alloc\n" ); rc = -ENODEV ;
@@ -1580,29 +1580,28 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) goto err_release_group_1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Error PortB DBIRQ alloc\n" ); - goto err_release_group_1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,3 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); - rc = -ENODEV ; - goto err_release_group_1; - } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, - prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); - goto err_release_group_1; +if (is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + goto err_release_group_1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,3 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + rc = -ENODEV ; + goto err_release_group_1; + } + rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); + goto err_release_group_1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -1985,29 +1984,29 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac, goto err_release_group1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Unable to parse DB IRQ index\n" ); - goto err_release_group1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,1 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); - rc = -ENODEV ; - goto err_release_group1; - } - rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, -IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); - goto err_release_group1; +if (edac->is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE , +"Unable to parse DB IRQ index\n" ); + goto err_release_group1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,1 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); + rc = -ENODEV ; + goto err_release_group1; + } + rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, +IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); + goto err_release_group1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -2133,6 +2132,8 @@ static int altr_edac_a10_probe(struct platform_device *pdev)platform_set_drvdata (pdev, edac);INIT_LIST_HEAD (&edac->a10_ecc_devices); + edac->is_s10 = !!device_get_match_data (&pdev->dev); + edac->ecc_mgr_map =altr_sysmgr_regmap_lookup_by_phandle (pdev->dev.of_node,"altr,sysmgr-syscon" );
@@ -2221,7 +2222,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev)static const struct of_device_id altr_edac_a10_of_match[] = { { .compatible ="altr,socfpga-a10-ecc-manager" }, - { .compatible ="altr,socfpga-s10-ecc-manager" }, + { .compatible ="altr,socfpga-s10-ecc-manager" , .data = (void *)1 }, {}, };MODULE_DEVICE_TABLE (of, altr_edac_a10_of_match);
drivers/edac/altera_edac.h +1 -0
@@ -395,6 +395,7 @@ struct altr_arria10_edac {struct irq_chip irq_chip;struct list_head a10_ecc_devices;struct notifier_block panic_notifier; + bool is_s10; };#endif /* #ifndef _ALTERA_EDAC_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/2857 EDAC/altera: Use parent device for devres in altr_portb_setup()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dinh Nguyen <[email protected]>
[ Upstream commit 9868f5c077dfe0b606331f2e782484f91a5789a5 ]
Anchor the devres group and the devm-managed IRQ requests in altr_portb_setup() to the actual parent device (device->edac->dev) instead of the embedded struct device inside the copied per-port altr_edac_device_dev.
This keeps devres_open_group(), devm_request_irq(), devres_remove_group() and devres_release_group() all referring to the same long-lived device so the group and the resources allocated inside it are torn down together.
--- drivers/edac/altera_edac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/edac/altera_edac.c +5 -5
@@ -1544,7 +1544,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) altdev = dci->pvt_info; *altdev = *device; -if (!devres_open_group (&altdev->ddev, altr_portb_setup,GFP_KERNEL )) +if (!devres_open_group (device->edac->dev, altr_portb_setup,GFP_KERNEL ))return -ENOMEM ;/* Update PortB specific values */
@@ -1572,7 +1572,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->sb_irq, + rc =devm_request_irq (device->edac->dev, altdev->sb_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1594,7 +1594,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + rc =devm_request_irq (device->edac->dev, altdev->db_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1614,13 +1614,13 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)list_add (&altdev->next, &altdev->edac->a10_ecc_devices); -devres_remove_group (&altdev->ddev, altr_portb_setup); +devres_remove_group (device->edac->dev, altr_portb_setup);return 0 ; err_release_group_1:edac_device_free_ctl_info (dci); -devres_release_group (&altdev->ddev, altr_portb_setup); +devres_release_group (device->edac->dev, altr_portb_setup);edac_printk (KERN_ERR ,EDAC_DEVICE ,"%s:Error setting up EDAC device: %d\n" , ecc_name, rc);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/2857 s390/crypto: Fix skcipher_walk return code handling in aes_s390
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit 15fa028589c3a2545f0bff355eff06d5844196bf ]
The return codes from skcipher_walk_virt() were not properly checked before entering the processing loops in ecb_aes_crypt() and ctr_aes_crypt(). If skcipher_walk_virt() fails, the walk structure may be in an undefined state, and attempting to process data could lead to incorrect behavior or accessing uninitialized memory.
Add proper return code checking to ensure correct handling of the walk initialization and walk advance and eventually return to the caller with that return code.
--- arch/s390/crypto/aes_s390.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/s390/crypto/aes_s390.c +5 -5
@@ -231,7 +231,7 @@ static int ecb_aes_crypt(struct skcipher_request *req, unsigned long modifier)return fallback_skcipher_crypt (sctx, req, modifier); ret =skcipher_walk_virt (&walk, req, false); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_km(sctx->fc | modifier, sctx->key,
@@ -335,7 +335,7 @@ static int cbc_aes_crypt(struct skcipher_request *req, unsigned long modifier)return ret;memcpy (param.iv, walk.iv,AES_BLOCK_SIZE );memcpy (param.key, sctx->key, sctx->key_len); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_kmc(sctx->fc | modifier, ¶m,
@@ -465,7 +465,7 @@ static int xts_aes_crypt(struct skcipher_request *req, unsigned long modifier)memcpy (xts_param.key + offset, xts_ctx->key, xts_ctx->key_len);memcpy (xts_param.init, pcc_param.xts,16 ); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_km(xts_ctx->fc | modifier, xts_param.key + offset,
@@ -581,7 +581,7 @@ static int ctr_aes_crypt(struct skcipher_request *req) locked =mutex_trylock (&ctrblk_lock); ret =skcipher_walk_virt (&walk, req, false); -while ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE ) { +while (!ret && ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE )) { n =AES_BLOCK_SIZE ;if (nbytes >=2 *AES_BLOCK_SIZE && locked)
@@ -600,7 +600,7 @@ static int ctr_aes_crypt(struct skcipher_request *req)/* * final block may be < AES_BLOCK_SIZE, copy only nbytes */ -if (nbytes) { +if (!ret && nbytes) {memset (buf,0 ,AES_BLOCK_SIZE );memcpy (buf, walk.src.virt.addr, nbytes); cpacf_kmctr(sctx->fc, sctx->key, buf, buf,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/2857 ALSA: hda/realtek: Add quirk for TongFang XxAF5xxx
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eckhart Mohr <[email protected]>
[ Upstream commit e72d5659a2606056a0c34af212b46a3275a55bbf ]
Fix microphone detection on built in headphone jack for some devices
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10497,6 +10497,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1d05 ,0x3031 ,"TongFang X6AR55xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3033 ,"TongFang X6SP45xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6KK45xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x30ba ,"TongFang XxAF5xxx" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d17 ,0x3288 ,"Haier Boyue G42" ,ALC269VC_FIXUP_ACER_VCOPPERBOX_PINS ),SND_PCI_QUIRK (0x1d72 ,0x1602 ,"RedmiBook" ,ALC255_FIXUP_XIAOMI_HEADSET_MIC ), SND_PCI_QUIRK(0x1d72, 0x1701, "XiaomiNotebook Pro", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/2857 mm: mempolicy: fix automatic numa balancing for shmem
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Weiner <[email protected]>
[ Upstream commit d230991493b521eeff39f32434fddcbcdb109eb0 ]
Neha reports that mapped shmem aren't considered for NUMA balancing, noting convergence problems and bandwidth bottlenecking for cachelib based workloads on tiered memory systems.
Looking at the code and going through the git history, this doesn't actually seem intentional:
Commit fc3147245d19 ("mm: numa: Limit NUMA scanning to migrate-on-fault VMAs") added a vma_policy_mof() gate to task_numa_work() so VMAs whose policy lacks MPOL_F_MOF are skipped from NUMA balancing scans. The motivation was a real usecase: Oracle was pinning shared segments with mbind(MPOL_BIND) so trapping faults was both expensive and pointless.
The handling of NULL from vm_ops->get_policy, however, treated "user explicitly opted out" the same as "user never specified anything." For VMAs whose shared policy is absent - the common case for shmem - the scan was disabled too.
This issue is old. It probably hurts less in conventional NUMA. But it's very noticeable on tiered systems, where entire tmpfs workingsets can get stuck on lower-bandwidth memory.
Fix this by having vma_policy_mof() use __get_vma_policy() directly, and thereby handle the fallback to task policy (-> preferred_node_policy() has MPOL_F_MOF per default). Every other consumer of vm_ops->get_policy already handles it this way, the scan-eligibility check was the outlier.
This preserves Mel's intended fix: don't scan stuff the user explicitly pinned. But allow default policy vmas to participate in balancing.
--- mm/mempolicy.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
mm/mempolicy.c +5 -14
@@ -1798,23 +1798,14 @@ static struct mempolicy *get_vma_policy(struct vm_area_struct *vma,bool vma_policy_mof (struct vm_area_struct *vma) {struct mempolicy *pol; +bool mof; -if (vma->vm_ops && vma->vm_ops->get_policy) { -bool ret = false; - - pol = vma->vm_ops->get_policy (vma, vma->vm_start); -if (pol && (pol->flags &MPOL_F_MOF )) - ret = true; -mpol_cond_put (pol); - -return ret; - } - - pol = vma->vm_policy; + pol =__get_vma_policy (vma, vma->vm_start);if (!pol) pol =get_task_policy (current); - -return pol->flags &MPOL_F_MOF ; + mof = pol->flags &MPOL_F_MOF ; +mpol_cond_put (pol); +return mof; }bool apply_policy_zone (struct mempolicy *policy,enum zone_type zone)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/2857 mm/kmemleak: report RCU-tasks quiescent states during the scan
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 3541a2b06ecd78ba333188df04368dcf97273d6a ]
kmemleak_scan() can run for ages on large debug kernels. It was causing some soft-lockups which I got fixed with commit 3175fcfec8b16baeb ("mm/kmemleak: avoid soft lockup when scanning task stacks") with our beloved cond_resched().
I've got the fix above deployed in the Meta fleet, and now I am seeing:
INFO: rcu_tasks detected stalls on tasks:
task:kmemleak state:R ... nvcsw: 274/274 holdout: 1 idle_cpu: -1/3
scan_block
scan_gray_list
kmemleak_scanand, worse, blocks the callers waiting on that grace period. Here a BPF struct_ops map free, which waits via synchronize_rcu_mult(call_rcu, call_rcu_tasks), is stuck long enough to also trip the hung task check:
INFO: task kworker/...:bpf_map_free_deferred blocked for 122 seconds
__wait_rcu_gp
bpf_struct_ops_map_freeThen I've learned that cond_resched() is not an RCU-tasks quiescent state, so, we need to use stronger primitives.
Use cond_resched_tasks_rcu_qs() at the scan reschedule points so the scan reports an RCU-tasks quiescent state as it proceeds.
Inspired by commit b96285e10aad ("tracing: Have osnoise_main() add a quiescent state for task rcu").
--- mm/kmemleak.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mm/kmemleak.c +6 -6
@@ -1395,7 +1395,7 @@ static void scan_large_block(void *start, void *end) next =min (start +MAX_SCAN_SIZE , end);scan_block (start, next,NULL ); start = next; - cond_resched(); + cond_resched_tasks_rcu_qs(); } }#endif
@@ -1440,7 +1440,7 @@ static void scan_object(struct kmemleak_object *object)break ;raw_spin_unlock_irqrestore (&object->lock, flags); -cond_resched (); +cond_resched_tasks_rcu_qs ();raw_spin_lock_irqsave (&object->lock, flags); }while (object->flags &OBJECT_ALLOCATED ); }else
@@ -1467,7 +1467,7 @@ static void scan_gray_list(void)*/ object =list_entry (gray_list.next,typeof (*object), gray_list);while (&object->gray_list != &gray_list) { -cond_resched (); +cond_resched_tasks_rcu_qs ();/* may add new objects to the list */ if (!scan_should_stop ())
@@ -1502,7 +1502,7 @@ static void kmemleak_cond_resched(struct kmemleak_object *object)raw_spin_unlock_irq (&kmemleak_lock);rcu_read_unlock (); -cond_resched (); +cond_resched_tasks_rcu_qs ();rcu_read_lock ();raw_spin_lock_irq (&kmemleak_lock);
@@ -1546,7 +1546,7 @@ static void kmemleak_scan_task_stacks(void) }put_task_struct (p); } -cond_resched (); +cond_resched_tasks_rcu_qs (); }while (pid && !scan_should_stop ()); }
@@ -1632,7 +1632,7 @@ static void kmemleak_scan(void)continue ;scan_block (page, page +1 ,NULL );if (!(pfn &63 )) -cond_resched (); +cond_resched_tasks_rcu_qs (); } }put_online_mems ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/2857 memcg: bypass the reclaim and oom killer for dying tasks once oom_reaper is done
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
[ Upstream commit 6b0d1083364fc8e7cc2f7d1f93ee3ee78f4d52f7 ]
At Meta, we are seeing instances where an OOM killed job is stuck in the exit path for several hours. In one particular case, the job was stuck for more than 8 hours and I had to manually remove the memory.max limits to allow the process to exit.
The job was a single process job and had ~55 GiB memory.max and zswap enabled. It had almost 0 anon in memory and ~111 GiB in zswap compressed to ~51 GiB zswap pool (i.e. almost all of memory.current was zswap). Nothing was left on the LRUs to reclaim.
On further inspection, I observed ~20k threads of that process stuck with the following stack:
[<0>] mem_cgroup_out_of_memory+0x4e/0xa0 [<0>] charge_memcg+0x8bf/0x990 [<0>] mem_cgroup_swapin_charge_folio+0x4e/0x80 [<0>] __read_swap_cache_async+0x10c/0x260 [<0>] swapin_readahead+0x116/0x3f0 [<0>] do_swap_page+0x13c/0x1ce0 [<0>] handle_mm_fault+0x61d/0x11f0 [<0>] do_user_addr_fault+0x3e7/0x6d0 [<0>] exc_page_fault+0x8f/0x110 [<0>] asm_exc_page_fault+0x22/0x30 [<0>] __get_user_8+0x14/0x20 [<0>] futex_cleanup+0x27/0x1c0 [<0>] futex_exit_release+0x47/0x60 [<0>] do_exit+0x107/0x940 [<0>] do_group_exit+0x81/0xa0 [<0>] get_signal+0x2b1/0x6e0 [<0>] arch_do_signal_or_restart+0x1a/0x1c0 [<0>] exit_to_user_mode_loop+0xa8/0x1c0 [<0>] do_syscall_64+0x152/0x250 [<0>] entry_SYSCALL_64_after_hwframe+0x4b/0x53
In addition the dmesg was filled with "Out of memory and no killable processes..." messages.
I have no idea why oom reaper was not able to reap/unmap the process. My guess is that since oom reaper tries to acquire mmap_lock in read mode limited number of times and then gives up, there might be a thread of that process which had mmap_lock in write mode at that time.
My initial suspicion was the futex_cleanup and kernel page fault causing infinite fault and charge retries but that was put to rest in previous discussions happened on similar problem [1].
My current theory is that it is just a simple slow serialization behind the oom_lock. Unlike page allocator, memcg charge code takes the oom_lock without the "try". Though memcg oom code uses mutex_lock_killable(), note that in the call stack get_signal() consumes SIGKILL (or sigdelset(SIGKILL)) before calling do_group_exit(). So this mutex_lock_killable() is just a mutex_lock() here. Therefore 10s of thousands of threads are waiting on oom_lock and one by one they get -EFAULT from get_user() in the futex cleanup code and bails out.
Discussion from [1] led to commit a75ffa26122b ("memcg, oom: do not bypass oom killer for dying tasks") which routes dying tasks into the OOM path precisely so the oom_reaper can reap their mm and free the memory asynchronously. But the reaper is best-effort and one-shot: if it cannot take mmap_lock for read (e.g. a sibling thread holds it for write) it sets MMF_OOM_SKIP and never retries, leaving only the glacial oom_lock-serialized synchronous drain.
Once MMF_OOM_SKIP is set there is no more asynchronous reclaim coming for the mm, so a dying task charging against it has nothing left to wait for:
it frees its memory only once it finishes exiting. Running reclaim and the (no-victim) OOM killer for it is then pointless, and doing it for 10s of thousands of exiting threads is what serializes them behind oom_lock. So before reclaim, if current is an OOM victim whose reaper is done, fail the charge.
Reproduced with 20k threads, each parking a robust futex head on its own zswapped page, OOM-group-killed while a sibling holds mmap_lock for write so the reaper gives up and sets MMF_OOM_SKIP. Tested on next-20260728 and baseline show ~90 seconds exit time while with the patch the exit time reduced to ~3 seconds.
to ~51 GiB zswap pool (i.e. almost all of memory.current was zswap). Nothing was left on the LRUs to reclaim.
On further inspection, I observed ~20k threads of that process stuck with the following stack:
[<0>] mem_cgroup_out_of_memory+0x4e/0xa0 [<0>] charge_memcg+0x8bf/0x990 [<0>] mem_cgroup_swapin_charge_folio+0x4e/0x80 [<0>] __read_swap_cache_async+0x10c/0x260 [<0>] swapin_readahead+0x116/0x3f0 [<0>] do_swap_page+0x13c/0x1ce0 [<0>] handle_mm_fault+0x61d/0x11f0 [<0>] do_user_addr_fault+0x3e7/0x6d0 [<0>] exc_page_fault+0x8f/0x110 [<0>] asm_exc_page_fault+0x22/0x30 [<0>] __get_user_8+0x14/0x20 [<0>] futex_cleanup+0x27/0x1c0 [<0>] futex_exit_release+0x47/0x60 [<0>] do_exit+0x107/0x940 [<0>] do_group_exit+0x81/0xa0 [<0>] get_signal+0x2b1/0x6e0 [<0>] arch_do_signal_or_restart+0x1a/0x1c0 [<0>] exit_to_user_mode_loop+0xa8/0x1c0 [<0>] do_syscall_64+0x152/0x250 [<0>] entry_SYSCALL_64_after_hwframe+0x4b/0x53
In addition the dmesg was filled with "Out of memory and no killable processes..." messages.
I have no idea why oom reaper was not able to reap/unmap the process. My guess is that since oom reaper tries to acquire mmap_lock in read mode limited number of times and then gives up, there might be a thread of that process which had mmap_lock in write mode at that time.
My initial suspicion was the futex_cleanup and kernel page fault causing infinite fault and charge retries but that was put to rest in previous discussions happened on similar problem [1].
My current theory is that it is just a simple slow serialization behind the oom_lock. Unlike page allocator, memcg charge code takes the oom_lock without the "try". Though memcg oom code uses mutex_lock_killable(), note that in the call stack get_signal() consumes SIGKILL (or sigdelset(SIGKILL)) before calling do_group_exit(). So this mutex_lock_killable() is just a mutex_lock() here. Therefore 10s of thousands of threads are waiting on oom_lock and one by one they get -EFAULT from get_user() in the futex cleanup code and bails out.
Discussion from [1] led to commit a75ffa26122b ("memcg, oom: do not bypass oom killer for dying tasks") which routes dying tasks into the OOM path precisely so the oom_reaper can reap their mm and free the memory asynchronously. But the reaper is best-effort and one-shot: if it cannot take mmap_lock for read (e.g. a sibling thread holds it for write) it sets MMF_OOM_SKIP and never retries, leaving only the glacial oom_lock-serialized synchronous drain.
Once MMF_OOM_SKIP is set there is no more asynchronous reclaim coming for the mm, so a dying task charging against it has nothing left to wait for:
it frees its memory only once it finishes exiting. Running reclaim and the (no-victim) OOM killer for it is then pointless, and doing it for 10s of thousands of exiting threads is what serializes them behind oom_lock.
--- mm/memcontrol.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
mm/memcontrol.c +13 -0
@@ -2677,6 +2677,19 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,if (!gfpflags_allow_blocking (gfp_mask)) goto nomem; +/* +* OOM victim still needs to charge memory to exit. OOM reaper should +* help but it might fail on mmap_lock contention. If the victim is a +* large thread group then all exiting threads might compete on oom_lock +* just to learn that there is nothing really killable anymore. Bail +* out early and fail the charge to expedite their exit. They are +* considered fully reclaimed by the oom reaper and they shouldn't +* contribute further charges. +*/ +if (tsk_is_oom_victim (current) && +test_bit (MMF_OOM_SKIP , ¤t->signal->oom_mm->flags)) + goto nomem; +memcg_memory_event (mem_over_limit,MEMCG_MAX ); raised_max_event = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/2857 mm/gup: fix always draining LRU caches in collect_longterm_unpinnable_folios()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 078e1a0fc41a42baaf113383b52dab8874c0b967 ]
folio_may_be_lru_cached() is currently only true for small folios, and for small folios FOLL_PIN adds GUP_PIN_COUNTING_BIAS references instead of 1 in try_grab_folio()/try_grab_folio_fast().
Consequently, our
folio_ref_count(folio) != folio_expected_ref_count(folio) + 1
check in collect_longterm_unpinnable_folios() will currently always identify "reference mismatch" and first drain the local LRU cache to then drain the LRU cache on all CPUs, as collect_longterm_unpinnable_folios() is really called after pinning the folios with FOLL_PIN.
Add a comment because the current code is not quite intuitive: we used to drain only to make sure the folio_isolate_lru() would succeed. But then we also started draining to make later migration more reliable.
We'll refactor that code soon a bit, to also make it usable in other context where we really want to remove any references from LRU caches.
Let's add CC stable, because having an easy way for excessive LRU cache draining on all CPUs does not sound right. In common scenarios we don't expect to ever have to drain.
--- mm/gup.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/gup.c +8 -2
@@ -1972,6 +1972,7 @@ static unsigned long collect_longterm_unpinnable_pages(for (i =0 ; i < nr_pages; i++) {struct folio *folio =page_folio (pages[i]); +const int pin_refs =folio_test_large (folio) ?1 :GUP_PIN_COUNTING_BIAS ;if (folio == prev_folio)continue ;
@@ -1990,15 +1991,20 @@ static unsigned long collect_longterm_unpinnable_pages(continue ; } +/* +* We drain not only to make the folio_isolate_lru() succeed, +* but also to remove any other folio references from LRU +* caches. +*/ if (drained ==0 &&folio_may_be_lru_cached (folio) &&folio_ref_count (folio) != -folio_expected_ref_count (folio) +1 ) { +folio_expected_ref_count (folio) + pin_refs) {lru_add_drain (); drained =1 ; }if (drained ==1 &&folio_may_be_lru_cached (folio) &&folio_ref_count (folio) != -folio_expected_ref_count (folio) +1 ) { +folio_expected_ref_count (folio) + pin_refs) {lru_add_drain_all (); drained =2 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 363/2857 platform/x86: think-lmi: Fix current password length check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 54745d563114b74f6fecebce68cd020d06c1772b ]
current_password_store() checks the password length before removing the trailing newline, which can reject valid passwords that are exactly ->maxlen bytes long.
It also passes ->maxlen to strscpy(), which truncates passwords without a newline.
Use strchrnul() to measure the password length up to the newline, then copy that many bytes and add a trailing NUL terminator using strscpy().
--- drivers/platform/x86/think-lmi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/platform/x86/think-lmi.c +3 -4
@@ -396,14 +396,13 @@ static ssize_t current_password_store(struct kobject *kobj,struct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj);size_t pwdlen; - pwdlen =strlen (buf); +/* Strip newline; setting password won't work if one is present. */ + pwdlen =strchrnul (buf,'\n' ) - buf;/* pwdlen == 0 is allowed to clear the password */ if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))return -EINVAL ; -strscpy (setting->password, buf, setting->maxlen); -/* Strip out CR if one is present, setting password won't work if it is present */ -strreplace (setting->password,'\n' ,'\0' ); +strscpy (setting->password, buf, pwdlen +1 );return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/2857 swiotlb: use the adjusted address for the highmem page lookup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit b7d7914a9ae3097e63d113007e4fb44d33d515b1 ]
swiotlb_bounce() reads the page frame number from the slot's recorded orig_addr, then advances orig_addr by tlb_offset to reach the address the caller asked about. The highmem branch mixes the two: the offset within the page comes from the adjusted address, the page from the value before it.
Once the adjustment crosses a page boundary the pair no longer describes one location, and the whole copy lands one page below the intended one for a positive tlb_offset, one above for a negative one. DMA_FROM_DEVICE writes the device data over the wrong page and leaves the intended one stale, DMA_TO_DEVICE feeds the device from a page the mapping may not cover. Partial syncs through dma_sync_single_range_for_*() are what make tlb_offset non-zero.
The branch test is picked the same way, so a slot recorded in lowmem can be adjusted into highmem and the lowmem path then hands a highmem address to phys_to_virt().
Take both from orig_addr once it is final and keep pfn in the branch that uses it. PhysHighMem() asks the question straight from the address, as dma-debug already does.
--- kernel/dma/swiotlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/dma/swiotlb.c +2 -2
@@ -556,7 +556,6 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t sizeint index = (tlb_addr - mem->start) >>IO_TLB_SHIFT ;phys_addr_t orig_addr = mem->slots[index].orig_addr;size_t alloc_size = mem->slots[index].alloc_size; -unsigned long pfn =PFN_DOWN (orig_addr);unsigned char *vaddr = mem->vaddr + tlb_addr - mem->start;unsigned int tlb_offset, orig_addr_offset;
@@ -590,7 +589,8 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size size = alloc_size; } -if (PageHighMem (pfn_to_page (pfn))) { +if (PageHighMem (pfn_to_page (PFN_DOWN (orig_addr)))) { +unsigned long pfn =PFN_DOWN (orig_addr);unsigned int offset = orig_addr & ~PAGE_MASK ;struct page *page;unsigned int sz =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/2857 tools/bootconfig: Fix integer overflow and truncation in size checks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 462d0b066b613103f579793031429db2ca23abc0 ]
Sashiko reported that on 32-bit systems, if an attacker crafts size in the bootconfig footer such that adding BOOTCONFIG_FOOTER_SIZE wraps around (for instance, if size is 0xFFFFFFFF), the size check in load_xbc_from_initrd() can be bypassed:
if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
pr_err("bootconfig size is too big\n");
return -E2BIG;
}Furthermore, on 64-bit systems with an initrd > 4.29 GB, comparing a corrupted 32-bit size (e.g. 0xFFFFFFFF) against
stat.st_size - BOOTCONFIG_FOOTER_SIZE can also bypass the check if size is not bounded. Similarly, load_xbc_file() passes 64-bit stat.st_size directly into the 32-bit int size parameter of load_xbc_fd(), truncating large standalone files (>= 2GB).
In both cases, passing 0xFFFFFFFF to load_xbc_fd() truncates to -1, resulting in malloc(0), an integer overflow in read(), and an out-of-bounds null-byte write.
Fix this by:
1. Rejecting size > XBC_DATA_MAX or
size > stat.st_size - BOOTCONFIG_FOOTER_SIZE in load_xbc_from_initrd().
2. Rejecting stat.st_size > XBC_DATA_MAX in load_xbc_file() before passing it to load_xbc_fd().
3. Checking size < 0 || size > XBC_DATA_MAX defensively in load_xbc_fd().
--- tools/bootconfig/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/bootconfig/main.c +12 -1
@@ -139,6 +139,9 @@ static int load_xbc_fd(int fd, char **buf, int size) {int ret; +if (size <0 || size >XBC_DATA_MAX ) +return -EINVAL ; + *buf =malloc (size +1 );if (!*buf)return -ENOMEM ;
@@ -167,6 +170,13 @@ static int load_xbc_file(const char *path, char **buf)return ret; } +if (stat.st_size >XBC_DATA_MAX ) { +pr_err ("%s size is too big\n" , path); + ret = -E2BIG ; +close (fd); +return ret; + } + ret =load_xbc_fd (fd, buf, stat.st_size);close (fd);
@@ -217,7 +227,8 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) { +if (size >XBC_DATA_MAX || + size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/2857 bootconfig: Fix integer overflow in initrd size check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 7812d6dab0698001e50e8c2f901e17da3eb6f429 ]
Sashiko reported that in get_boot_config_from_initrd(), a crafted initrd with a huge bootconfig size (such as 0xFFFFFFFF) can cause the pointer arithmetic:
data = ((void *)hdr) - size;
to wrap around on 32-bit systems (or when pointer subtraction overflows). Because data wraps around, the subsequent bounds check:
if ((unsigned long)data < initrd_start)
evaluates to false, bypassing the check. The kernel then calls xbc_calc_checksum(data, size), which attempts to read 4GB of memory, hitting unmapped pages and triggering a fatal kernel page fault during early boot. Furthermore, on 64-bit systems with an initrd > 4.29 GB, an unbounded 32-bit size can similarly bypass the initrd_start check.
Fix this by:
1. Ensuring the initrd is at least large enough to contain the bootconfig footer and verifying hdr is within the initrd bounds.
2. Checking that size does not exceed XBC_DATA_MAX and does not exceed the available space between initrd_start and hdr before performing pointer subtraction.
--- init/main.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
init/main.c +15 -10
@@ -275,7 +275,8 @@ static void * __init get_boot_config_from_initrd(size_t *_size)u32 *hdr;int i; -if (!initrd_end) +if (!initrd_end || initrd_end < initrd_start || + initrd_end - initrd_start <BOOTCONFIG_MAGIC_LEN +8 )return NULL ; data = (char *)initrd_end -BOOTCONFIG_MAGIC_LEN ;
@@ -292,16 +293,26 @@ static void * __init get_boot_config_from_initrd(size_t *_size) found: hdr = (u32 *)(data -8 ); +if ((unsigned long )hdr < initrd_start) +return NULL ; + size =le32_to_cpu (hdr[0 ]); csum =le32_to_cpu (hdr[1 ]); - data = ((void *)hdr) - size; -if ((unsigned long )data < initrd_start) { -pr_err ("bootconfig size %d is greater than initrd size %ld\n" , +if (size >XBC_DATA_MAX ) { +pr_err ("bootconfig size %u is greater than max size %d\n" , + size,XBC_DATA_MAX ); +return NULL ; + } + +if (size > ((unsigned long )hdr - initrd_start)) { +pr_err ("bootconfig size %u is greater than initrd size %lu\n" , size, initrd_end - initrd_start);return NULL ; } + data = ((void *)hdr) - size; +if (xbc_calc_checksum (data, size) != csum) {pr_err ("bootconfig checksum failed\n" );return NULL ;
@@ -400,12 +411,6 @@ static void __init setup_boot_config(void)return ; } -if (size >=XBC_DATA_MAX ) { -pr_err ("bootconfig size %ld greater than max size %d\n" , - (long )size,XBC_DATA_MAX ); -return ; - } - ret =xbc_init (data, size, &msg, &pos);if (ret <0 ) {if (pos <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/2857 tracing: Undo the registration when enabling the histogram trigger fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 92383cef66791a0c63a2f27755cadbdb2fbf270b ]
Commit 6f86bdeab633 ("tracing: Fix bad hist from corrupting named_triggers list") described how a trigger that is registered but not on file->triggers ends up freed while still on the global named_triggers list, and moved the registration down so that hist_trigger_enable() follows it immediately. One path still gets there. hist_trigger_enable() adds the trigger and takes it straight back out when the event cannot be enabled:
list_add_tail_rcu(&data->list, &file->triggers);
update_cond_flag(file);
if (trace_event_trigger_enable_disable(file, 1) < 0) {
list_del_rcu(&data->list);
update_cond_flag(file);
ret--;
}so the list walk in hist_unregister_trigger() matches nothing, test stays NULL, and the ->free() that would call del_named_trigger() is skipped. out_unreg falls through to out_free, which frees the trigger anyway:
BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff8880091d3160 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0xa00 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 69: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160
Leave the trigger where hist_unregister_trigger() can find it and let that undo the registration, which is the only code that knows all of what cmd_ops->init() took: the named list entry, the hist_pad reference, the reference on the trigger a named histogram is shared with, and the copied cmd_ops. It also pairs the failed trace_event_trigger_enable_disable(), whose sm_ref and buffered event reference are otherwise left behind.
Since ->free() releases trigger_data and, for a trigger that does not share its histogram, hist_data with it, out_unreg can no longer fall through to out_free. For a trigger that does share, hist_register_trigger() has already destroyed the caller's hist_data, so the fall-through was reading freed memory there as well.
Move the enable_timestamps check in hist_unregister_trigger() above the ->free() call for the same reason: hist_data does not outlive it once the trigger being removed is the one that owns it.
--- kernel/trace/trace_events_hist.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
kernel/trace/trace_events_hist.c +10 -7
@@ -6302,11 +6302,12 @@ static int hist_trigger_enable(struct event_trigger_data *data,update_cond_flag (file); -if (trace_event_trigger_enable_disable (file,1 ) <0 ) { -list_del_rcu (&data->list); -update_cond_flag (file); +/* +* On failure the caller undoes the registration, and +* hist_unregister_trigger() can only find the trigger here. +*/ +if (trace_event_trigger_enable_disable (file,1 ) <0 ) ret--; - }return ret; }
@@ -6384,13 +6385,13 @@ static void hist_unregister_trigger(char *glob, } } -if (test && test->ops->free) - test->ops->free (test); -if (hist_data->enable_timestamps) {if (!hist_data->remove || test)tracing_set_filter_buffering (file->tr, false); } + +if (test && test->ops->free) + test->ops->free (test); }static bool hist_file_check_refs (struct trace_event_file *file)
@@ -6590,6 +6591,8 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,return ret; out_unreg:event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data); +/* The unregister frees trigger_data, skip out_free */ + goto out; out_free:event_trigger_reset_filter (cmd_ops, trigger_data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/2857 tracing: Take trace_array reference when opening a tracer options file
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit ed0aff60f83a9bdc2f6556376ac79c96b3ce7e80 ]
When a tracer option file is opened, it is passed a descriptor that points to an element on the trace_array's topts array. This element has information to find the trace array and other information. It uses this element to take a reference of the trace_array so that the trace_array does not get removed while this file is opened.
Unfortunately, there's a race condition where the element itself could be freed by the removal of the instance the trace_array represents causing a use-after-free as this element that is used to find the trace_array to increment its reference counter is also freed when the instance is removed.
To solve this, add a trace_array_tracer_options_get() helper function that will take the address of the element that is passed to the open function by the inode->i_private pointer and search all the trace_arrays under a lock to find the one that the element's address is in the range of the trace_arrays topts array elements. When a match happens, that trace_array's reference would be increased.
Note, there's a race where if an admin was deleting and creating trace instances at the same time and the memory of the old trace_array's array matched the memory of the new trace_array that it could in theory open the option from the wrong trace array. But we do not care because it would be stupid to perform that kind of action. As long as the only thing that can happen is that the option from the wrong trace array is used and doesn't crash the kernel it will only make the user confused. But if they are doing something stupid like this, they are already confused, so no harm done.
--- kernel/trace/trace.c | 48 +++++++++++++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-)
kernel/trace/trace.c +47 -1
@@ -8919,12 +8919,57 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,return cnt; } +static bool tr_option_match (struct trace_array *tr,void *topt) +{ +for (int i =0 ; i < tr->nr_topts; i++) { +struct trace_options *tr_topts = &tr->topts[i]; + +if (topt >= (void *)&tr_topts->topts[0 ] && + topt < (void *)&tr_topts->topts[tr_topts->nr_topts]) +return true; + } +return false; +} + +/* +* The topt is the address of a trace_array->topts[] element that holds the +* the tracer options descriptor. But since the trace_array reference has not +* been taken yet, it cannot be dereferenced as it could have been freed by +* a rmdir of the instance the trace_array represents. +* +* Search the list of trace_arrays and compare the topt to the address of +* the entire trace_array topts array for each trace_array in the list. +* If one is matched, then take the reference and return it. If not, the +* trace_array no longer exits. +*/ +static int trace_array_tracer_options_get (void *topt) +{ +struct trace_array *tr; +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + +if (tracing_disabled) +return -ENODEV ; + +guard (mutex)(&trace_types_lock); +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (tr_option_match (tr, topt)) { + tr->ref++; +return 0 ; + } + } +return -ENODEV ; +} +static int tracing_open_options (struct inode *inode,struct file *filp) {struct trace_option_dentry *topt = inode->i_private;int ret; - ret =tracing_check_open_get_tr (topt->tr); + ret =trace_array_tracer_options_get (topt);if (ret)return ret;
@@ -9208,6 +9253,7 @@ create_trace_option_files(struct trace_array *tr, struct tracer *tracer) tr->topts = tr_topts; tr->topts[tr->nr_topts].tracer = tracer; tr->topts[tr->nr_topts].topts = topts; + tr->topts[tr->nr_topts].nr_topts = cnt; tr->nr_topts++;for (cnt =0 ; opts[cnt].name; cnt++) {
kernel/trace/trace.h +1 -0
@@ -202,6 +202,7 @@ struct array_buffer {struct trace_options {struct tracer *tracer;struct trace_option_dentry *topts; +int nr_topts; };struct trace_pid_list *trace_pid_list_alloc (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/2857 KEYS: encrypted: fix integer overflow of datablob_len
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8697c431e297eb0d0ab13dda6bc172b48a34f05c ]
encrypted_key_alloc() stores datablob_len in a u16. It is computed from multiple string and payload lengths. If the result exceeds U16_MAX, the assignment truncates the allocation size. KASAN reports a 32760-byte slab-out-of-bounds write when __ekey_init() copies the master key description into the undersized buffer.
The total payload length stored in key->datalen is also a u16. Use check_add_overflow() to reject values that do not fit either destination, and use kzalloc_flex() for the flexible-array allocation.
--- security/keys/encrypted-keys/encrypted.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
security/keys/encrypted-keys/encrypted.c +14 -6
@@ -18,6 +18,7 @@#include <linux/parser.h> #include <linux/string.h> #include <linux/err.h> +#include <linux/overflow.h> #include <keys/user-type.h> #include <keys/trusted-type.h> #include <keys/encrypted-type.h>
@@ -606,6 +607,7 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, {struct encrypted_key_payload *epayload =NULL ;unsigned short datablob_len; +unsigned short payload_totallen;unsigned short decrypted_datalen;unsigned short payload_datalen;unsigned int encrypted_datalen;
@@ -659,16 +661,22 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, encrypted_datalen =roundup (decrypted_datalen, blksize); - datablob_len = format_len +1 +strlen (master_desc) +1 - +strlen (datalen) +1 + ivsize +1 + encrypted_datalen; +if (check_add_overflow (format_len +1 +strlen (master_desc) +1 + +strlen (datalen) +1 + ivsize +1 , + encrypted_datalen, &datablob_len)) +return ERR_PTR (-EINVAL ); + +if (check_add_overflow (datablob_len, + payload_datalen +HASH_SIZE +1 , + &payload_totallen)) +return ERR_PTR (-EINVAL ); - ret =key_payload_reserve (key, payload_datalen + datablob_len - +HASH_SIZE +1 ); + ret =key_payload_reserve (key, payload_totallen);if (ret <0 )return ERR_PTR (ret); - epayload =kzalloc (sizeof (*epayload) + payload_datalen + - datablob_len +HASH_SIZE +1 ,GFP_KERNEL ); + epayload =kzalloc (struct_size (epayload, payload_data, payload_totallen), +GFP_KERNEL );if (!epayload)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/2857 ALSA: core: Make snd_card_disconnect() return void
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 663f922fd7a9e9342dca512db339c7fb2b59b8e6 ]
All callers from other files ignore the return value of this function. And it can only ever return a non-zero value if the parameter card is NULL.
Move the check for card being NULL into snd_card_free_when_closed() to keep the previous behaviour. Note this isn't necessary for snd_card_disconnect_sync() because if card was NULL in there the dereference of card for dev_err() would oops the kernel. Replace this by an oops triggered by the dereference of card for spin_lock_irq().
Stable-dep-of: fd95e68df6fe ("ALSA: core: Fix potential UAF after asynchronous card release")
--- include/sound/core.h | 2 +- sound/core/init.c | 24 ++++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-)
include/sound/core.h +1 -1
@@ -286,7 +286,7 @@ int snd_devm_card_new(struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size, struct snd_card **card_ret); -int snd_card_disconnect (struct snd_card *card); +void snd_card_disconnect (struct snd_card *card);void snd_card_disconnect_sync (struct snd_card *card);int snd_card_free (struct snd_card *card);int snd_card_free_when_closed (struct snd_card *card);
sound/core/init.c +8 -16
@@ -489,17 +489,17 @@ static const struct file_operations snd_shutdown_f_ops =* Note: The current implementation replaces all active file->f_op with special * dummy file operations (they do nothing except release). */ -int snd_card_disconnect (struct snd_card *card) +void snd_card_disconnect (struct snd_card *card) {struct snd_monitor_file *mfile;if (!card) -return -EINVAL ; +return ;spin_lock (&card->files_lock);if (card->shutdown) {spin_unlock (&card->files_lock); -return 0 ; +return ; } card->shutdown =1 ;
@@ -560,7 +560,6 @@ int snd_card_disconnect(struct snd_card *card)#ifdef CONFIG_PM snd_power_sync_ref (card);#endif -return 0 ; }EXPORT_SYMBOL (snd_card_disconnect);
@@ -575,15 +574,7 @@ EXPORT_SYMBOL(snd_card_disconnect);*/ void snd_card_disconnect_sync (struct snd_card *card) { -int err; - - err =snd_card_disconnect (card); -if (err <0 ) { -dev_err (card->dev, -"snd_card_disconnect error (%d), skipping sync\n" , - err); -return ; - } +snd_card_disconnect (card);spin_lock_irq (&card->files_lock); wait_event_lock_irq(card->remove_sleep,
@@ -629,9 +620,10 @@ static int snd_card_do_free(struct snd_card *card)*/ int snd_card_free_when_closed (struct snd_card *card) { -int ret =snd_card_disconnect (card); -if (ret) -return ret; +if (!card) +return -EINVAL ; + +snd_card_disconnect (card);put_device (&card->card_dev);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/2857 ALSA: core: Use guard() for locking
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 742ecf3ce1acdbcd0bc936178e1eaf346a0fd376 ]
We can simplify the code gracefully with new guard() macro and co for automatic cleanup of locks.
Only the code refactoring, and no functional changes.
Stable-dep-of: fd95e68df6fe ("ALSA: core: Fix potential UAF after asynchronous card release")
--- sound/core/init.c | 193 +++++++++++++++++++---------------------- sound/core/sound.c | 28 +++--- sound/core/sound_oss.c | 17 ++-- 3 files changed, 104 insertions(+), 134 deletions(-)
sound/core/init.c +88 -105
@@ -279,30 +279,31 @@ static int snd_card_init(struct snd_card *card, struct device *parent,if (xid)strscpy (card->id, xid,sizeof (card->id)); err =0 ; -mutex_lock (&snd_card_mutex); -if (idx <0 )/* first check the matching module-name slot */ - idx =get_slot_from_bitmask (idx, module_slot_match, module); -if (idx <0 )/* if not matched, assign an empty slot */ - idx =get_slot_from_bitmask (idx, check_empty_slot, module); -if (idx <0 ) - err = -ENODEV ; -else if (idx < snd_ecards_limit) { -if (test_bit (idx, snd_cards_lock)) - err = -EBUSY ;/* invalid */ - }else if (idx >=SNDRV_CARDS ) - err = -ENODEV ; + scoped_guard(mutex, &snd_card_mutex) { +if (idx <0 )/* first check the matching module-name slot */ + idx =get_slot_from_bitmask (idx, module_slot_match, module); +if (idx <0 )/* if not matched, assign an empty slot */ + idx =get_slot_from_bitmask (idx, check_empty_slot, module); +if (idx <0 ) + err = -ENODEV ; +else if (idx < snd_ecards_limit) { +if (test_bit (idx, snd_cards_lock)) + err = -EBUSY ;/* invalid */ + }else if (idx >=SNDRV_CARDS ) + err = -ENODEV ; +if (!err) { +set_bit (idx, snd_cards_lock);/* lock it */ +if (idx >= snd_ecards_limit) + snd_ecards_limit = idx +1 ;/* increase the limit */ + } + }if (err <0 ) { -mutex_unlock (&snd_card_mutex);dev_err (parent,"cannot find the slot for index %d (range 0-%i), error: %d\n" , - idx, snd_ecards_limit -1 , err); + idx, snd_ecards_limit -1 , err);if (!card->managed)kfree (card);/* manually free here, as no destructor called */ return err; } -set_bit (idx, snd_cards_lock);/* lock it */ -if (idx >= snd_ecards_limit) - snd_ecards_limit = idx +1 ;/* increase the limit */ -mutex_unlock (&snd_card_mutex); card->dev = parent; card->number = idx;#ifdef MODULE
@@ -381,11 +382,10 @@ struct snd_card *snd_card_ref(int idx) {struct snd_card *card; -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card)get_device (&card->card_dev); -mutex_unlock (&snd_card_mutex);return card; }EXPORT_SYMBOL_GPL (snd_card_ref);
@@ -393,12 +393,8 @@ EXPORT_SYMBOL_GPL(snd_card_ref);/* return non-zero if a card is already locked */ int snd_card_locked (int card) { -int locked; - -mutex_lock (&snd_card_mutex); - locked =test_bit (card, snd_cards_lock); -mutex_unlock (&snd_card_mutex); -return locked; +guard (mutex)(&snd_card_mutex); +return test_bit (card, snd_cards_lock); }static loff_t snd_disconnect_llseek (struct file *file,loff_t offset,int orig)
@@ -422,15 +418,15 @@ static int snd_disconnect_release(struct inode *inode, struct file *file) {struct snd_monitor_file *df =NULL , *_df; -spin_lock (&shutdown_lock); -list_for_each_entry (_df, &shutdown_files, shutdown_list) { -if (_df->file == file) { - df = _df; -list_del_init (&df->shutdown_list); -break ; + scoped_guard(spinlock, &shutdown_lock) { +list_for_each_entry (_df, &shutdown_files, shutdown_list) { +if (_df->file == file) { + df = _df; +list_del_init (&df->shutdown_list); +break ; + } } } -spin_unlock (&shutdown_lock);if (likely (df)) {if ((file->f_flags &FASYNC ) && df->disconnected_f_op->fasync)
@@ -496,27 +492,24 @@ void snd_card_disconnect(struct snd_card *card)if (!card)return ; -spin_lock (&card->files_lock); -if (card->shutdown) { -spin_unlock (&card->files_lock); -return ; - } - card->shutdown =1 ; + scoped_guard(spinlock, &card->files_lock) { +if (card->shutdown) +return ; + card->shutdown =1 ; -/* replace file->f_op with special dummy operations */ -list_for_each_entry (mfile, &card->files_list, list) { -/* it's critical part, use endless loop */ -/* we have no room to fail */ - mfile->disconnected_f_op = mfile->file->f_op; +/* replace file->f_op with special dummy operations */ +list_for_each_entry (mfile, &card->files_list, list) { +/* it's critical part, use endless loop */ +/* we have no room to fail */ + mfile->disconnected_f_op = mfile->file->f_op; -spin_lock (&shutdown_lock); -list_add (&mfile->shutdown_list, &shutdown_files); -spin_unlock (&shutdown_lock); + scoped_guard(spinlock, &shutdown_lock) +list_add (&mfile->shutdown_list, &shutdown_files); - mfile->file->f_op = &snd_shutdown_f_ops; -fops_get (mfile->file->f_op); + mfile->file->f_op = &snd_shutdown_f_ops; +fops_get (mfile->file->f_op); + } } -spin_unlock (&card->files_lock);#ifdef CONFIG_PM /* wake up sleepers here before other callbacks for avoiding potential
@@ -552,10 +545,10 @@ void snd_card_disconnect(struct snd_card *card) }/* disable fops (user space) operations for ALSA API */ -mutex_lock (&snd_card_mutex); - snd_cards[card->number] =NULL ; -clear_bit (card->number, snd_cards_lock); -mutex_unlock (&snd_card_mutex); + scoped_guard(mutex, &snd_card_mutex) { + snd_cards[card->number] =NULL ; +clear_bit (card->number, snd_cards_lock); + }#ifdef CONFIG_PM snd_power_sync_ref (card);
@@ -576,11 +569,10 @@ void snd_card_disconnect_sync(struct snd_card *card) {snd_card_disconnect (card); -spin_lock_irq (&card->files_lock); +guard (spinlock_irq)(&card->files_lock);wait_event_lock_irq (card->remove_sleep,list_empty (&card->files_list), card->files_lock); -spin_unlock_irq (&card->files_lock); }EXPORT_SYMBOL_GPL (snd_card_disconnect_sync);
@@ -782,9 +774,8 @@ void snd_card_set_id(struct snd_card *card, const char *nid)/* check if user specified own card->id */ if (card->id[0 ] !='\0' )return ; -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex);snd_card_set_id_no_lock (card, nid, nid); -mutex_unlock (&snd_card_mutex); }EXPORT_SYMBOL (snd_card_set_id);
@@ -812,14 +803,11 @@ static ssize_t id_store(struct device *dev, struct device_attribute *attr, }memcpy (buf1, buf, copy); buf1[copy] ='\0' ; -mutex_lock (&snd_card_mutex); -if (!card_id_ok (NULL , buf1)) { -mutex_unlock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); +if (!card_id_ok (NULL , buf1))return -EEXIST ; - }strcpy (card->id, buf1);snd_info_card_id_change (card); -mutex_unlock (&snd_card_mutex);return count; }
@@ -912,26 +900,27 @@ int snd_card_register(struct snd_card *card) err =snd_device_register_all (card);if (err <0 )return err; -mutex_lock (&snd_card_mutex); -if (snd_cards[card->number]) { -/* already registered */ -mutex_unlock (&snd_card_mutex); -return snd_info_card_register (card);/* register pending info */ - } -if (*card->id) { -/* make a unique id name from the given string */ -char tmpid[sizeof (card->id)]; -memcpy (tmpid, card->id,sizeof (card->id)); -snd_card_set_id_no_lock (card, tmpid, tmpid); - }else { -/* create an id from either shortname or longname */ -const char *src; - src = *card->shortname ? card->shortname : card->longname; -snd_card_set_id_no_lock (card, src, -retrieve_id_from_card_name (src)); + scoped_guard(mutex, &snd_card_mutex) { +if (snd_cards[card->number]) { +/* already registered */ +return snd_info_card_register (card);/* register pending info */ + } +if (*card->id) { +/* make a unique id name from the given string */ +char tmpid[sizeof (card->id)]; + +memcpy (tmpid, card->id,sizeof (card->id)); +snd_card_set_id_no_lock (card, tmpid, tmpid); + }else { +/* create an id from either shortname or longname */ +const char *src; + + src = *card->shortname ? card->shortname : card->longname; +snd_card_set_id_no_lock (card, src, +retrieve_id_from_card_name (src)); + } + snd_cards[card->number] = card; } - snd_cards[card->number] = card; -mutex_unlock (&snd_card_mutex); err =snd_info_card_register (card);if (err <0 )return err;
@@ -952,7 +941,7 @@ static void snd_card_info_read(struct snd_info_entry *entry,struct snd_card *card;for (idx = count =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card) { count++;
@@ -964,7 +953,6 @@ static void snd_card_info_read(struct snd_info_entry *entry,snd_iprintf (buffer," %s\n" , card->longname); } -mutex_unlock (&snd_card_mutex); }if (!count)snd_iprintf (buffer,"--- no soundcards ---\n" );
@@ -977,13 +965,12 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer)struct snd_card *card;for (idx = count =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card) { count++;snd_iprintf (buffer,"%s\n" , card->longname); } -mutex_unlock (&snd_card_mutex); }if (!count) {snd_iprintf (buffer,"--- no soundcards ---\n" );
@@ -1000,12 +987,11 @@ static void snd_card_module_info_read(struct snd_info_entry *entry,struct snd_card *card;for (idx =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card)snd_iprintf (buffer,"%2i %s\n" , idx, card->module->name); -mutex_unlock (&snd_card_mutex); } }#endif
@@ -1087,15 +1073,13 @@ int snd_card_file_add(struct snd_card *card, struct file *file) mfile->file = file; mfile->disconnected_f_op =NULL ;INIT_LIST_HEAD (&mfile->shutdown_list); -spin_lock (&card->files_lock); +guard (spinlock)(&card->files_lock);if (card->shutdown) { -spin_unlock (&card->files_lock);kfree (mfile);return -ENODEV ; }list_add (&mfile->list, &card->files_list);get_device (&card->card_dev); -spin_unlock (&card->files_lock);return 0 ; }EXPORT_SYMBOL (snd_card_file_add);
@@ -1117,22 +1101,21 @@ int snd_card_file_remove(struct snd_card *card, struct file *file) {struct snd_monitor_file *mfile, *found =NULL ; -spin_lock (&card->files_lock); -list_for_each_entry (mfile, &card->files_list, list) { -if (mfile->file == file) { -list_del (&mfile->list); -spin_lock (&shutdown_lock); -list_del (&mfile->shutdown_list); -spin_unlock (&shutdown_lock); -if (mfile->disconnected_f_op) -fops_put (mfile->disconnected_f_op); - found = mfile; -break ; + scoped_guard(spinlock, &card->files_lock) { +list_for_each_entry (mfile, &card->files_list, list) { +if (mfile->file == file) { +list_del (&mfile->list); + scoped_guard(spinlock, &shutdown_lock) +list_del (&mfile->shutdown_list); +if (mfile->disconnected_f_op) +fops_put (mfile->disconnected_f_op); + found = mfile; +break ; + } } +if (list_empty (&card->files_list)) +wake_up_all (&card->remove_sleep); } -if (list_empty (&card->files_list)) -wake_up_all (&card->remove_sleep); -spin_unlock (&card->files_lock);if (!found) {dev_err (card->dev,"card file remove problem (%p)\n" , file);return -ENOENT ;
sound/core/sound.c +11 -17
@@ -103,7 +103,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)if (minor >=ARRAY_SIZE (snd_minors))return NULL ; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex); mreg = snd_minors[minor];if (mreg && mreg->type == type) { private_data = mreg->private_data;
@@ -111,7 +111,6 @@ void *snd_lookup_minor_data(unsigned int minor, int type)get_device (&mreg->card_ptr->card_dev); }else private_data =NULL ; -mutex_unlock (&sound_mutex);return private_data; }EXPORT_SYMBOL (snd_lookup_minor_data);
@@ -150,17 +149,15 @@ static int snd_open(struct inode *inode, struct file *file)if (minor >=ARRAY_SIZE (snd_minors))return -ENODEV ; -mutex_lock (&sound_mutex); - mptr = snd_minors[minor]; -if (mptr ==NULL ) { - mptr =autoload_device (minor); -if (!mptr) { -mutex_unlock (&sound_mutex); -return -ENODEV ; + scoped_guard(mutex, &sound_mutex) { + mptr = snd_minors[minor]; +if (mptr ==NULL ) { + mptr =autoload_device (minor); +if (!mptr) +return -ENODEV ; } + new_fops =fops_get (mptr->f_ops); } - new_fops =fops_get (mptr->f_ops); -mutex_unlock (&sound_mutex);if (!new_fops)return -ENODEV ;replace_fops (file, new_fops);
@@ -276,7 +273,7 @@ int snd_register_device(int type, struct snd_card *card, int dev, preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex); minor =snd_find_free_minor (type, card, dev);if (minor <0 ) { err = minor;
@@ -291,7 +288,6 @@ int snd_register_device(int type, struct snd_card *card, int dev, snd_minors[minor] = preg; error: -mutex_unlock (&sound_mutex);if (err <0 )kfree (preg);return err;
@@ -312,7 +308,7 @@ int snd_unregister_device(struct device *dev)int minor;struct snd_minor *preg; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex);for (minor =0 ; minor <ARRAY_SIZE (snd_minors); ++minor) { preg = snd_minors[minor];if (preg && preg->dev == dev) {
@@ -322,7 +318,6 @@ int snd_unregister_device(struct device *dev)break ; } } -mutex_unlock (&sound_mutex);if (minor >=ARRAY_SIZE (snd_minors))return -ENOENT ;return 0 ;
@@ -362,7 +357,7 @@ static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buint minor;struct snd_minor *mptr; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex);for (minor =0 ; minor <SNDRV_OS_MINORS ; ++minor) { mptr = snd_minors[minor];if (!mptr)
@@ -380,7 +375,6 @@ static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_busnd_iprintf (buffer,"%3i: : %s\n" , minor,snd_device_type_name (mptr->type)); } -mutex_unlock (&sound_mutex); }int __init snd_minor_info_init (void )
sound/core/sound_oss.c +5 -12
@@ -29,7 +29,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)if (minor >=ARRAY_SIZE (snd_oss_minors))return NULL ; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); mreg = snd_oss_minors[minor];if (mreg && mreg->type == type) { private_data = mreg->private_data;
@@ -37,7 +37,6 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)get_device (&mreg->card_ptr->card_dev); }else private_data =NULL ; -mutex_unlock (&sound_oss_mutex);return private_data; }EXPORT_SYMBOL (snd_lookup_oss_minor_data);
@@ -106,7 +105,7 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); snd_oss_minors[minor] = preg; minor_unit =SNDRV_MINOR_OSS_DEVICE (minor);switch (minor_unit) {
@@ -130,7 +129,6 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, goto __end; snd_oss_minors[track2] = preg; } -mutex_unlock (&sound_oss_mutex);return 0 ; __end:
@@ -139,7 +137,6 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,if (register1 >=0 )unregister_sound_special (register1); snd_oss_minors[minor] =NULL ; -mutex_unlock (&sound_oss_mutex);kfree (preg);return -EBUSY ; }
@@ -156,12 +153,10 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)return 0 ;if (minor <0 )return minor; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); mptr = snd_oss_minors[minor]; -if (mptr ==NULL ) { -mutex_unlock (&sound_oss_mutex); +if (mptr ==NULL )return -ENOENT ; - }switch (SNDRV_MINOR_OSS_DEVICE (minor)) {case SNDRV_MINOR_OSS_PCM : track2 =SNDRV_MINOR_OSS (cidx,SNDRV_MINOR_OSS_AUDIO );
@@ -176,7 +171,6 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)if (track2 >=0 ) snd_oss_minors[track2] =NULL ; snd_oss_minors[minor] =NULL ; -mutex_unlock (&sound_oss_mutex);/* call unregister_sound_special() outside sound_oss_mutex; * otherwise may deadlock, as it can trigger the release of a card
@@ -220,7 +214,7 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,int minor;struct snd_minor *mptr; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex);for (minor =0 ; minor <SNDRV_OSS_MINORS ; ++minor) { mptr = snd_oss_minors[minor];if (!mptr)
@@ -233,7 +227,6 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,snd_iprintf (buffer,"%3i: : %s\n" , minor,snd_oss_device_type_name (mptr->type)); } -mutex_unlock (&sound_oss_mutex); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/2857 ALSA: core: Fix potential UAF after asynchronous card release
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit fd95e68df6fe66344161a1329cbe5e5805e7b704 ]
Usually a sound driver releases the resources assigned to the card via snd_card_free(), and it synchronizes with the whole release procedure. However, when the card is released asynchronously via snd_card_free_when_closed() like USB-audio driver, the situation is slightly different; although the snd_card_disconnect() call at the disconnection guarantees that any newer accesses will be gated, the in-flight tasks might be still accessing to the underlying card->dev device even after the disconnection, which would cause a use-after-free in the end, as reported by fuzzers.
For addressing the bug above, this patch takes the refcount of card->dev at initialization of the card object, and releases at its
destructor. This assures the availability of the card->dev in its
whole lifecycle.
--- sound/core/init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/core/init.c +2 -1
@@ -304,7 +304,7 @@ static int snd_card_init(struct snd_card *card, struct device *parent,kfree (card);/* manually free here, as no destructor called */ return err; } - card->dev = parent; + card->dev =get_device (parent); card->number = idx;#ifdef MODULE WARN_ON (!module);
@@ -592,6 +592,7 @@ static int snd_card_do_free(struct snd_card *card)dev_warn (card->dev,"unable to free card info\n" );/* Not fatal error */ } +put_device (card->dev);if (card->release_completion)complete (card->release_completion);if (!managed)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/2857 phy: renesas: rcar-gen3-usb2: Avoid long delay in atomic context
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
[ Upstream commit 48e97c59a49c9e90270f5e3d221db253b76de5da ]
The OTG PHY initialization sequence needs to wait for 20 ms at a specific step, as described in commit 72c0339c115b ("phy: renesas:
rcar-gen3-usb2: follow the hardware manual procedure").
Commit 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data") tried to address various problems in the rcar-gen3-usb2 driver and converted the mutex protecting HW register accesses to a spin lock, leaving, however, a long delay in the critical section protected by the spin lock. This may become a problem, especially on RT kernels.
To address this, release the spin lock before sleeping for 20 ms as required by the HW manual and reacquire it afterwards. To avoid other threads entering the critical section and configuring the HW while the software is waiting for the OTG initialization to complete, introduce the otg_initializing variable alongside the otg_init_done wait queue. Any other thread trying to configure the HW while the OTG PHY initialization is in progress waits for the wait queue instead of immediately returning errors to PHY users. The IRQs were also disabled while waiting for the OTG PHY initialization to complete, as the interrupt handler may also apply HW settings.
The OTG can only be initialized once. It is initialized by the first PHY that calls struct phy_ops::rcar_gen3_phy_usb2_init().
To avoid failures when multiple PHYs call struct phy_ops::rcar_gen3_phy_usb2_init() simultaneously, and the PHY responsible for initializing the OTG either fails or deinit quiqly and another PHY takes over the PHY init role), the code waiting for the channel->otg_init_done wait queue retries up to NUM_OF_PHYS times.
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 302 ++++++++++++++++++++--- 1 file changed, 261 insertions(+), 41 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +261 -41
@@ -25,6 +25,7 @@#include <linux/reset.h> #include <linux/string.h> #include <linux/usb/of.h> +#include <linux/wait.h> #include <linux/workqueue.h> /******* USB2.0 Host registers (original offset is +0x200) *******/
@@ -90,6 +91,13 @@#define USB2_OBINT_IDCHG_EN BIT(0)#define USB2_LINECTRL1_USB2_IDMON BIT(0) +/* +* The OTG initialization is expected to finish in 20ms. Choose a large enough +* timeout to avoid waiters exit prematurely the waiting section under heavy +* CPU load. +*/ +#define USB2_OTG_INIT_TIMEOUT msecs_to_jiffies(120) +#define NUM_OF_PHYS 4enum rcar_gen3_phy_index {PHY_INDEX_BOTH_HC ,
@@ -120,6 +128,7 @@ struct rcar_gen3_chan {struct rcar_gen3_phy rphys[NUM_OF_PHYS ];struct regulator *vbus;struct work_struct work; +wait_queue_head_t otg_init_done;spinlock_t lock;/* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode;u32 obint_enable_bits;
@@ -127,6 +136,13 @@ struct rcar_gen3_chan {bool is_otg_channel;bool uses_otg_pins;bool soc_no_adp_ctrl; +/* +* The OTG can be initialized only once and needs to release the spinlock +* and wait for 20 ms due to hardware constraints. If a thread executes +* PHY configuration code while the OTG PHY is waiting for the 20 ms, the +* thread will have to wait for the OTG PHY initialization to complete. +*/ +bool otg_initializing; };struct rcar_gen3_phy_drv_data {
@@ -346,26 +362,58 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,struct rcar_gen3_chan *ch =dev_get_drvdata (dev);bool is_b_device;enum phy_mode cur_mode, new_mode; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret = -EIO ; -guard (spinlock_irqsave)(&ch->lock); +spin_lock_irqsave (&ch->lock, flags); -if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch)) -return -EIO ; +if (!ch->is_otg_channel) + goto unlock; + +while (retries-- && ch->otg_initializing) { +spin_unlock_irqrestore (&ch->lock, flags); + + ret =wait_event_timeout (ch->otg_init_done, !ch->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto exit; + +spin_lock_irqsave (&ch->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (ch->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + +if (!rcar_gen3_is_any_otg_rphy_initialized (ch)) { + ret = -EIO ; + goto unlock; + } -if (sysfs_streq (buf,"host" )) +if (sysfs_streq (buf,"host" )) { new_mode =PHY_MODE_USB_HOST ; -else if (sysfs_streq (buf,"peripheral" )) + }else if (sysfs_streq (buf,"peripheral" )) { new_mode =PHY_MODE_USB_DEVICE ; -else -return -EINVAL ; + }else { + ret = -EINVAL ; + goto unlock; + }/* is_b_device: true is B-Device. false is A-Device. */ is_b_device =rcar_gen3_check_id (ch); cur_mode =rcar_gen3_get_phy_mode (ch);/* If current and new mode is the same, this returns the error */ -if (cur_mode == new_mode) -return -EINVAL ; +if (cur_mode == new_mode) { + ret = -EINVAL ; + goto unlock; + }if (new_mode ==PHY_MODE_USB_HOST ) {/* And is_host must be false */ if (!is_b_device)/* A-Peripheral */
@@ -379,7 +427,10 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,rcar_gen3_init_for_peri (ch); } -return count; +unlock: +spin_unlock_irqrestore (&ch->lock, flags); +exit: +return ret ?: count; } static ssize_t role_show(struct device *dev, struct device_attribute *attr,
@@ -395,14 +446,11 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RW (role); -static void rcar_gen3_init_otg (struct rcar_gen3_chan *ch) +static void rcar_gen3_init_otg_phase0 (struct rcar_gen3_chan *ch) {void __iomem *usb2_base = ch->base;u32 val; -if (!ch->is_otg_channel ||rcar_gen3_is_any_otg_rphy_initialized (ch)) -return ; -/* Should not use functions of read-modify-write a register */ val =readl (usb2_base +USB2_LINECTRL1 ); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -416,7 +464,11 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val =readl (usb2_base +USB2_ADPCTRL );writel (val |USB2_ADPCTRL_IDPULLUP , usb2_base +USB2_ADPCTRL ); } -mdelay (20 ); +} + +static void rcar_gen3_init_otg_phase1 (struct rcar_gen3_chan *ch) +{ +void __iomem *usb2_base = ch->base;writel (0xffffffff , usb2_base +USB2_OBINTSTA );writel (ch->obint_enable_bits, usb2_base +USB2_OBINTEN );
@@ -430,6 +482,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)void __iomem *usb2_base = ch->base;struct device *dev = ch->dev;irqreturn_t ret =IRQ_NONE ; +unsigned long flags;u32 status;pm_runtime_get_noresume (dev);
@@ -437,29 +490,98 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)if (pm_runtime_suspended (dev)) goto rpm_put; - scoped_guard(spinlock, &ch->lock) { - status =readl (usb2_base +USB2_OBINTSTA ); -if (status & ch->obint_enable_bits) { -dev_vdbg (dev,"%s: %08x\n" , __func__, status); -writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); -rcar_gen3_device_recognition (ch); - ret =IRQ_HANDLED ; - } +spin_lock_irqsave (&ch->lock, flags); + + status =readl (usb2_base +USB2_OBINTSTA ); +if (status & ch->obint_enable_bits) { +dev_vdbg (dev,"%s: %08x\n" , __func__, status); +writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); + + ret =IRQ_HANDLED ; + +/* This should not happen! */ +if (ch->otg_initializing) + goto unlock; + +rcar_gen3_device_recognition (ch); } +unlock: +spin_unlock_irqrestore (&ch->lock, flags); rpm_put:pm_runtime_put_noidle (dev);return ret; } +static void rcar_gen3_phy_usb2_irqs_mask_all (struct rcar_gen3_chan *channel, +u32 *masked_irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + *masked_irqs_bits = val & bitmask; + val &= ~bitmask; +writel (val, usb2_base +USB2_INT_ENABLE ); + +/* +* Don't report channel->obint_enable_bits IRQs. These are +* unmasked anyway in rcar_gen3_init_otg_phase1(). +*/ + val =readl (usb2_base +USB2_OBINTEN ); + val &= ~channel->obint_enable_bits; +writel (val, usb2_base +USB2_OBINTEN ); +} + +static void rcar_gen3_phy_usb2_irqs_unmask (struct rcar_gen3_chan *channel, +u32 irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + val &= ~bitmask; + val |= irqs_bits; +writel (val, usb2_base +USB2_INT_ENABLE ); +} +static int rcar_gen3_phy_usb2_init (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }/* Initialize USB2 part */ val =readl (usb2_base +USB2_INT_ENABLE );
@@ -472,12 +594,30 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) }/* Initialize otg part (only if we initialize a PHY with IRQs). */ -if (rphy->int_enable_bits) -rcar_gen3_init_otg (channel); +if (rphy->int_enable_bits && channel->is_otg_channel && + !rcar_gen3_is_any_otg_rphy_initialized (channel)) { +u32 masked_irq_bits =0 ; + +rcar_gen3_init_otg_phase0 (channel); +rcar_gen3_phy_usb2_irqs_mask_all (channel, &masked_irq_bits); + channel->otg_initializing = true; +spin_unlock_irqrestore (&channel->lock, flags); + +fsleep (20000 ); + +spin_lock_irqsave (&channel->lock, flags); +rcar_gen3_phy_usb2_irqs_unmask (channel, masked_irq_bits); +rcar_gen3_init_otg_phase1 (channel); + channel->otg_initializing = false; +wake_up_all (&channel->otg_init_done); + } rphy->initialized = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +return ret; }static int rcar_gen3_phy_usb2_exit (struct phy *p)
@@ -485,9 +625,32 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } rphy->initialized = false;
@@ -497,7 +660,9 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &= ~USB2_INT_ENABLE_UCOM_INTEN ;writel (val, usb2_base +USB2_INT_ENABLE ); -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); +return ret; }static int rcar_gen3_phy_usb2_power_on (struct phy *p)
@@ -505,8 +670,10 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; -int ret =0 ; +int ret;if (channel->vbus) { ret =regulator_enable (channel->vbus);
@@ -514,7 +681,27 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)return ret; } -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto disable_regulator; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }if (!rcar_gen3_are_all_rphys_power_off (channel)) goto out;
@@ -529,27 +716,59 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)/* The powered flag should be set for any other phys anyway */ rphy->powered = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +disable_regulator: +if (ret && channel->vbus) +regulator_disable (channel->vbus); + +return ret; }static int rcar_gen3_phy_usb2_power_off (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch; -int ret =0 ; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret; - scoped_guard(spinlock_irqsave, &channel->lock) { - rphy->powered = false; +spin_lock_irqsave (&channel->lock, flags); -if (rcar_gen3_are_all_rphys_power_off (channel)) { -u32 val =readl (channel->base +USB2_USBCTR ); +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); - val |=USB2_USBCTR_PLL_RST ; -writel (val, channel->base +USB2_USBCTR ); - } + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + + rphy->powered = false; + +if (rcar_gen3_are_all_rphys_power_off (channel)) { +u32 val =readl (channel->base +USB2_USBCTR ); + + val |=USB2_USBCTR_PLL_RST ; +writel (val, channel->base +USB2_USBCTR ); } -if (channel->vbus) +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +if (!ret && channel->vbus) ret =regulator_disable (channel->vbus);return ret;
@@ -763,6 +982,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) channel->obint_enable_bits =USB2_OBINT_IDCHG_EN ;spin_lock_init (&channel->lock); +init_waitqueue_head (&channel->otg_init_done);for (i =0 ; i <NUM_OF_PHYS ; i++) { channel->rphys[i].phy =devm_phy_create (dev,NULL , phy_data->phy_usb2_ops);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/2857 smb: client: cancel reconnect work in clean_demultiplex_info()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit c65eae6f61d1778ff7a82e4aae4080e26f486af1 ]
clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:
cifs_demultiplex_thread()
cifs_readv_from_socket()
cifs_reconnect()
__cifs_reconnect()
cifs_queue_server_reconn()
mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
clean_demultiplex_info()
cancel_delayed_work_sync(&server->echo) // echo canceled
// reconnect NOT canceled
kfree_sensitive(server) // server freed ...later, on cifsiod_wq:
smb2_reconnect_server()
server->srv_count // UAF read of freed server
Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -989,6 +989,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)spin_unlock (&server->srv_lock);cancel_delayed_work_sync (&server->echo); +cancel_delayed_work_sync (&server->reconnect);spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/2857 drm/bridge: tc358768: Enforce input bus flags via atomic_check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leonardo Costa <[email protected]>
[ Upstream commit ed761e0693950fcb4f6b0f60387a3961b972adf3 ]
The tc358768 declares static bridge timings requiring pixel data to be sampled on the positive clock edge.
However, the DRM core default propagation simply copies the output-side bus flags, coming from the next bridge, connector or panel, to the input side. If the propagated flags are incompatible with the bridge ones, the data is wrongly sampled, typically resulting in visual artifacts on the panel.
Implement the atomic_check hook, replacing the mutually exclusive mode_fixup, and set the bridge state input bus flags to the ones required by the tc358768. The sync polarity defaulting previously done in mode_fixup is carried over into atomic_check unchanged.
--- drivers/gpu/drm/bridge/tc358768.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/bridge/tc358768.c +11 -0
@@ -1146,9 +1146,20 @@ tc358768_atomic_get_input_bus_fmts(struct drm_bridge *bridge,return input_fmts; } +static int tc358768_bridge_atomic_check (struct drm_bridge *bridge, +struct drm_bridge_state *bridge_state, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ + bridge_state->input_bus_cfg.flags = bridge->timings->input_bus_flags; + +return 0 ; +} +static const struct drm_bridge_funcs tc358768_bridge_funcs = { .attach = tc358768_bridge_attach, .mode_valid = tc358768_bridge_mode_valid, + .atomic_check = tc358768_bridge_atomic_check, .pre_enable = tc358768_bridge_pre_enable, .enable = tc358768_bridge_enable, .disable = tc358768_bridge_disable,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/2857 smb: client: fix rlist race and missing initialization
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 5f270f091256da1338c3631083e15d7f83cc05e1 ]
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making list_empty() always return false and list_add() dereference a NULL ->prev pointer.
Also, cifs_signal_cifsd_for_reconnect() can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
--- fs/smb/client/connect.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/connect.c +7 -0
@@ -195,6 +195,8 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, nserver = ses->chans[i].server;if (!nserver)continue ; +if (!list_empty (&nserver->rlist)) +continue ; nserver->srv_count++;list_add (&nserver->rlist, &reco); }
@@ -203,11 +205,15 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, } } +spin_lock (&cifs_tcp_ses_lock);list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);set_need_reco (server); +spin_unlock (&cifs_tcp_ses_lock);cifs_put_tcp_session (server,0 ); +spin_lock (&cifs_tcp_ses_lock); } +spin_unlock (&cifs_tcp_ses_lock); }/*
@@ -1762,6 +1768,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,spin_lock_init (&tcp_ses->mid_lock);INIT_LIST_HEAD (&tcp_ses->tcp_ses_list);INIT_LIST_HEAD (&tcp_ses->smb_ses_list); +INIT_LIST_HEAD (&tcp_ses->rlist);INIT_DELAYED_WORK (&tcp_ses->echo, cifs_echo_request);INIT_DELAYED_WORK (&tcp_ses->reconnect, smb2_reconnect_server);mutex_init (&tcp_ses->reconnect_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/2857 Input: hp_sdc - shut down kicker timer on module exit
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 309731e95917125bbd13626a7a5600490a5bf44f ]
hp_sdc_kicker() rearms hp_sdc.kicker with mod_timer() after scheduling the tasklet. The module exit path uses timer_delete_sync(). That waits for a callback already running but can still leave the timer rearmed.
A callback can therefore leave the timer pending while hp_sdc_exit() tears down the driver, allowing timer activity to access dismantled driver state.
Use timer_shutdown_sync() for final teardown. It waits for a running callback and prevents rearming after module exit begins.
--- drivers/input/serio/hp_sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/serio/hp_sdc.c +1 -1
@@ -980,7 +980,7 @@ static void hp_sdc_exit(void)free_irq (hp_sdc.irq, &hp_sdc);write_unlock_irq (&hp_sdc.lock); -del_timer_sync (&hp_sdc.kicker); +timer_shutdown_sync (&hp_sdc.kicker);tasklet_kill (&hp_sdc.task);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/2857 wifi: mac80211: refuse to make a monitor active when it has no queue
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 2b04d6556964ae9f89819b86a0a7801e39c3aae5 ]
A monitor interface only gets a TXQ if it's created active, and one can't be added later. Setting the flag on a down interface is still allowed, so the driver is handed a monitor with no queue. ath9k dereferences it:
BUG: kernel NULL pointer dereference, address: 0000000000000066 RIP: 0010:ath_tx_node_init+0x49/0x170 [ath9k] ath9k_add_interface+0x10c/0x140 [ath9k] drv_add_interface+0x54/0x250 [mac80211] ieee80211_do_open+0x32f/0x800 [mac80211]
Reached with CAP_NET_ADMIN by "iw dev X set monitor active" followed by "ip link set X up". RTNL is held, so netlink operations block behind it.
Refuse the flag when there is no queue to give.
--- net/mac80211/cfg.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mac80211/cfg.c +5 -0
@@ -104,6 +104,11 @@ static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,return -EBUSY ; } +/* TXQs are reserved in ieee80211_if_add() and cannot be added later */ +if ((params->flags &MONITOR_FLAG_ACTIVE ) && + local->ops->wake_tx_queue && !sdata->vif.txq) +return -EOPNOTSUPP ; +/* also validate MU-MIMO change */ monitor_sdata =wiphy_dereference (local->hw.wiphy, local->monitor_sdata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/2857 i2c: imx: disable autosuspend on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit e0c3e9d76adbe522dd420a766ce42d03ce887c29 ]
i2c_imx_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-imx.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/busses/i2c-imx.c +1 -0
@@ -1660,6 +1660,7 @@ static int i2c_imx_remove(struct platform_device *pdev)pm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev); +pm_runtime_dont_use_autosuspend (&pdev->dev);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/2857 ata: libahci_platform: Simplify code with for_each_child_of_node_scoped()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Zekun <[email protected]>
[ Upstream commit aa3ca1faf3222af7aaa194a910995820135fc54e ]
for_each_child_of_node_scoped() can put the device_node automatically. So let's use it to make the code simpler by avoiding the need to explicitly call of_node_put().
Stable-dep-of: 0d1cb83337f1 ("ata: libahci_platform: Fix device reference leak in ahci_platform_get_resources()")
--- drivers/ata/libahci_platform.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
drivers/ata/libahci_platform.c +5 -14
@@ -418,7 +418,6 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,static int ahci_platform_get_firmware (struct ahci_host_priv *hpriv,struct device *dev) { -struct device_node *child;u32 port;if (!of_property_read_u32 (dev->of_node,"hba-cap" , &hpriv->saved_cap))
@@ -427,14 +426,12 @@ static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv,of_property_read_u32 (dev->of_node,"ports-implemented" , &hpriv->saved_port_map); -for_each_child_of_node (dev->of_node, child) { +for_each_child_of_node_scoped (dev->of_node, child) {if (!of_device_is_available (child))continue ; -if (of_property_read_u32 (child,"reg" , &port)) { -of_node_put (child); +if (of_property_read_u32 (child,"reg" , &port))return -EINVAL ; - }if (!of_property_read_u32 (child,"hba-port-cap" , &hpriv->saved_port_cap[port])) hpriv->saved_port_cap[port] &=PORT_CMD_CAP ;
@@ -482,7 +479,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,int child_nodes, rc = -ENOMEM , enabled_ports =0 ;struct device *dev = &pdev->dev;struct ahci_host_priv *hpriv; -struct device_node *child;u32 mask_port_map =0 ;u32 max_port;
@@ -604,7 +600,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, }if (child_nodes) { -for_each_child_of_node (dev->of_node, child) { +for_each_child_of_node_scoped (dev->of_node, child) {u32 port;struct platform_device *port_dev__maybe_unused ;
@@ -613,7 +609,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,if (of_property_read_u32 (child,"reg" , &port)) { rc = -EINVAL ; -of_node_put (child); goto err_out; }
@@ -631,18 +626,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,if (port_dev) { rc =ahci_platform_get_regulator (hpriv, port, &port_dev->dev); -if (rc == -EPROBE_DEFER ) { -of_node_put (child); +if (rc == -EPROBE_DEFER ) goto err_out; - } }#endif rc =ahci_platform_get_phy (hpriv, port, dev, child); -if (rc) { -of_node_put (child); +if (rc) goto err_out; - } enabled_ports++; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/2857 ata: libahci_platform: Fix device reference leak in ahci_platform_get_resources()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 0d1cb83337f13af082afb68b28d3fdfe29cde7fb ]
of_find_device_by_node() takes a reference on the port platform device, which is only used to look up its port regulator and is never released, neither on success nor on the error paths. Drop the reference with put_device() once the regulator has been obtained, which covers both the success and error paths.
--- drivers/ata/libahci_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libahci_platform.c +1 -1
@@ -622,10 +622,10 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,of_platform_device_create (child,NULL ,NULL ); port_dev =of_find_device_by_node (child); -if (port_dev) { rc =ahci_platform_get_regulator (hpriv, port, &port_dev->dev); +put_device (&port_dev->dev);if (rc == -EPROBE_DEFER ) goto err_out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/2857 drm/amdkfd: Avoid integer underflow with ffs in EOP ring size calc
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Francis <[email protected]>
[ Upstream commit c883d0a132d430ef7ebb23fd94323be94d0fbdb8 ]
The low 6 bits of cp_hqd_eop_control store the base-2 logarithm of the EOP ring size. This was calculated as
ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1
But ffs can in theory return 1 or 0, so this could underflow (although in practice the ring buffer size cannot be less than 4096).
Change this to
ffs(q->eop_ring_buffer_size / sizeof(unsigned int) / 4)
using properties of logarithms.
--- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +1 -1
@@ -192,7 +192,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control =min (0xA , -ffs (q->eop_ring_buffer_size /sizeof (unsigned int )) -1 -1 ); +ffs (q->eop_ring_buffer_size /sizeof (unsigned int ) /4 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +1 -1
@@ -218,7 +218,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control =min (0xA , -ffs (q->eop_ring_buffer_size /sizeof (unsigned int )) -1 -1 ); +ffs (q->eop_ring_buffer_size /sizeof (unsigned int ) /4 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/2857 drm/amdkfd: Avoid integer underflow in EOP ring size calculation.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Francis <[email protected]>
[ Upstream commit 8ee521b8b189799e361d4233c5180ba56656d4d4 ]
The low 6 bits of cp_hqd_eop_control store the base-2 logarithm of the EOP ring size. This was calculated as
order_base_2(q->eop_ring_buffer_size / 4) - 1
But order_base_2 can in theory return 0, so this could underflow (although in practice the ring buffer size cannot be less than 4096).
Change this to
order_base_2(q->eop_ring_buffer_size / 8)
using properties of logarithms.
Also add to the above comment to make the mathematics more clear.
--- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +5 -1
@@ -237,6 +237,10 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,1 <<CP_HQD_IB_CONTROL__IB_EXE_DISABLE__SHIFT ;/* +* The lowest 6 bits of eop_control store the EOP ring size. If +* their value is X, the ring size is 2^(X + 1) dwords, or +* 2^(X + 3) bytes. +* * HW does not clamp this field correctly. Maximum EOP queue size * is constrained by per-SE EOP done signal count, which is 8-bit. * Limit is 0xFF EOP entries (= 0x7F8 dwords). CP will not submit
@@ -244,7 +248,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control =min (0xA , -order_base_2 (q->eop_ring_buffer_size /4 ) -1 ); +order_base_2 (q->eop_ring_buffer_size /8 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +4 -1
@@ -204,6 +204,9 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd, mtype <<CP_HQD_IB_CONTROL__MTYPE__SHIFT ;/* +* The lowest 6 bits of eop_control store the EOP ring size. If +* their value is X, the ring size is 2^(X + 1) dwords, or +* 2^(X + 3) bytes. * HW does not clamp this field correctly. Maximum EOP queue size * is constrained by per-SE EOP done signal count, which is 8-bit. * Limit is 0xFF EOP entries (= 0x7F8 dwords). CP will not submit
@@ -211,7 +214,7 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control |=min (0xA , -order_base_2 (q->eop_ring_buffer_size /4 ) -1 ); +order_base_2 (q->eop_ring_buffer_size /8 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/2857 drm/amdgpu: fix rmmio iounmap skipped on device removal
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengjun Yao <[email protected]>
[ Upstream commit 5155002b03b24ba3ef91c5c313b8cf0171b24904 ]
amdgpu_pci_remove() calls drm_dev_unplug() before fini_sw(), so drm_dev_enter() is already false there and the iounmap() guarded by it is skipped. This .remove path runs on both hot-unplug and plain rmmod, so the register BAR ioremap mapping leaks one instance per unload.
Unmap rmmio unconditionally (guard only on non-NULL) and drop the now unused idx.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -4
@@ -4189,7 +4189,6 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)void amdgpu_device_fini_sw (struct amdgpu_device *adev) { -int idx;bool px;amdgpu_device_ip_fini (adev);
@@ -4221,12 +4220,10 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)if ((adev->pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )vga_client_unregister (adev->pdev); -if (drm_dev_enter (adev_to_drm (adev), &idx)) { - +if (adev->rmmio) {iounmap (adev->rmmio); adev->rmmio =NULL ;amdgpu_device_doorbell_fini (adev); -drm_dev_exit (idx); }if (IS_ENABLED (CONFIG_PERF_EVENTS ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/2857 x86/microcode/intel: Reject problematic loading on Granite Rapids systems
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chang S. Bae <[email protected]>
[ Upstream commit e7d3e2f46dd5a69046e6d95a0f189155a5516b93 ]
Microcode updates can usually jump revisions. However, there is an erratum on Granite Rapids systems. If they "jump over" revision 0x1000405, they result in an #MC. Avoid it.
--- arch/x86/kernel/cpu/microcode/intel.c | 55 ++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/intel.c +54 -1
@@ -261,6 +261,23 @@ static int microcode_sanity_check(void *mc, int print_err)return 0 ; } +static bool revision_is_safe (struct cpu_signature *sig,u32 rev) +{ +/* +* Erratum GNR98 can cause #MCs if "jumping over" revision 0x1000405. +* Avoid the jumps. +*/ +if (x86_family (sig->sig) ==6 && +x86_model (sig->sig) ==INTEL_FAM6_GRANITERAPIDS_X && +x86_stepping (sig->sig) ==1 && + sig->pf &0x95 && + sig->rev <0x1000405 && + rev >0x1000405 ) +return false; + +return true; +} +/* * Get microcode matching with BSP's model. Only CPUs with the same model as * BSP can stay in the platform.
@@ -292,8 +309,19 @@ scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save)continue ; } +if (!revision_is_safe (&uci->cpu_sig, mc_header->rev)) { + data += mc_size; +continue ; + } +if (save) { -save_microcode_patch (uci, data, mc_size); +/* +* Only cache what the BSP could have loaded: a newer +* revision was rejected as unsafe and must not be +* applied on resume or hotplug. +*/ +if (mc_header->rev <= uci->cpu_sig.rev) +save_microcode_patch (uci, data, mc_size); goto next; }
@@ -629,6 +657,11 @@ void load_ucode_intel_ap(void) *iup = patch; } +intel_cpu_collect_info (&uci); + +if (!revision_is_safe (&uci.cpu_sig, (*iup)->hdr.rev)) +return ; + uci.mc = *iup;apply_microcode_early (&uci, true);
@@ -646,6 +679,9 @@ static struct microcode_intel *find_patch(struct ucode_cpu_info *uci)if (phdr->rev <= uci->cpu_sig.rev)continue ; +if (!revision_is_safe (&uci->cpu_sig, phdr->rev)) +continue ; +if (!find_matching_signature (phdr, uci->cpu_sig.sig, uci->cpu_sig.pf))
@@ -706,6 +742,7 @@ static enum ucode_state apply_microcode_intel(int cpu)struct cpuinfo_x86 *c = &cpu_data (cpu);bool bsp = c->cpu_index == boot_cpu_data.cpu_index;struct microcode_intel *mc; +struct cpu_signature sig;enum ucode_state ret;static int prev_rev;u32 rev;
@@ -733,6 +770,17 @@ static enum ucode_state apply_microcode_intel(int cpu) goto out; } +/* +* uci->cpu_sig.rev can be stale, e.g. on resume. Check against the +* revision the CPU is really running. +*/ + sig = uci->cpu_sig; + sig.rev = rev; +if (!revision_is_safe (&sig, mc->hdr.rev)) { + ret =UCODE_NFOUND ; + goto out; + } +/* * Writeback and invalidate caches before updating microcode to avoid * internal issues depending on what the microcode is updating.
@@ -818,6 +866,11 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)break ; } +if (!revision_is_safe (&uci->cpu_sig, mc_header.rev)) { +pr_err_once ("Erratum GNR98: skipping revision 0x%x.\n" , mc_header.rev); +continue ; + } + csig = uci->cpu_sig.sig; cpf = uci->cpu_sig.pf;if (has_newer_microcode (mc, csig, cpf, new_rev)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/2857 fs/ntfs3: use d_instantiate_new() in ntfs_create_inode() and murder syzbots "WARNING in do_new_mount" saga
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 1abd643f3783ea8f8e273c18697ff0413aa92dc7 ]
ntfs_create_inode() creates a new inode via ntfs_new_inode(). It hashes it with insert_inode_locked() and so it's marked as I_NEW until unlock_new_inode().
ntfs 3 calls d_instantiate() in between though... Since the dentry was already hashed by the lookup before the create any path walk finds it without touching the parent's i_rwsem and so can lock the inode.
If the inode is a directory unlock_new_inode() calls lockdep_annotate_inode_mutex_key() and marks i_rwsem with the i_mutex_dir_key class.
That resets the count and the owner of a lock somebody else may already hold by now...
syzbot has been spamming us with the same godforsaken bug
"WARNING in do_new_mount"
since 2023. I can't take it anymore so I went looking. Afaict, syzbot's executor chdirs into a freshly mounted ntfs3 image, creates a directory and then mounts some pseudofs on it. Everytime the mkdir() takes longer than syzbot waits mount() runs concurrently:
mkdir("./sys") mount(NULL, "./sys", "sysfs")
ntfs_create_inode()
d_instantiate()
user_path_at() finds the dentry
do_lock_mount()
inode_lock(inode)
namespace_lock()
unlock_new_inode()
lockdep_annotate_inode_mutex_key()
init_rwsem(&inode->i_rwsem)
unlock_mount()
inode_unlock(inode)The mount side then releases a lock that according to the rwsem nobody holds:
DEBUG_RWSEMS_WARN_ON((rwsem_owner(sem) != current) && ...):
count = 0x0, magic = 0xffff888043a854e8, owner = 0x0, curr 0xffff888000244880, list empty
WARNING: CPU: 0 PID: 5346 at kernel/locking/rwsem.c:1368 __up_write Call Trace: inode_unlock include/linux/fs.h:877 [inline] unlock_mount fs/namespace.c:2892 [inline] do_new_mount_fc fs/namespace.c:3828 [inline] do_new_mount+0x777/0xa40 fs/namespace.c:3887
On PREEMPT_RT the same thing shows up as
DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current)
WARNING: kernel/locking/rtmutex_common.h:193 at rt_mutex_slowunlock
The up_write() underflows the reset count. A following inode_lock() on that directory then never returns. A path walk into the new directory racing with the mkdir() corrupts the lock the same way via inode_lock_shared() in lookup_slow().
Switch to d_instantiate_new() and drop the trailing unlock_new_inode(). All error paths bail out before that point with I_NEW still set and keep using discard_new_inode().
May we never see this fscking bug report again.
--- fs/ntfs3/inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ntfs3/inode.c +2 -4
@@ -1642,10 +1642,10 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, }/* -* Call 'd_instantiate' after inode->i_op is set +* Call 'd_instantiate_new' after inode->i_op is set * but before finish_open. */ -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);ntfs_save_wsl_perm (inode);mark_inode_dirty (dir);
@@ -1696,8 +1696,6 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,return ERR_PTR (err); } -unlock_new_inode (inode); -return inode; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/2857 mm/hugetlb: do not dissolve gigantic pages without runtime support
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longlong Xia <[email protected]>
[ Upstream commit a363c62a653cc8b3e21da9545fa4e028ef50f9c3 ]
dissolve_free_hugetlb_folio() doesn't check hstate_is_gigantic_no_runtime(h) though remove_hugetlb_folio()/ update_and_free_hugetlb_folio() silently bail for such folios, so it frees a still-listed folio and, on vmemmap restore failure, the add_hugetlb_folio() rollback corrupts the free list.
--- mm/hugetlb.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
mm/hugetlb.c +10 -0
@@ -2352,6 +2352,16 @@ int dissolve_free_huge_page(struct page *page)if (!page_count (page)) {struct page *head =compound_head (page);struct hstate *h =page_hstate (head); + +/* +* remove_hugetlb_page()/update_and_free_page() bail +* for gigantic hstates without runtime support, so dissolving one +* here would leave it on the free list and, on vmemmap restore +* failure, the add_hugetlb_page() rollback corrupts that list. +*/ +if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) + goto out; +if (!available_huge_pages (h)) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/2857 mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
[ Upstream commit 39c0ceedd54557bdc1542de08d22b2ed33e534e4 ]
damon_hugetlb_mkold() reads the page table entry into a local variable, unsets the accessed bit in the variable, and updates the page table entry with the updated variable value. If hardware updates the same page table entry in parallel, the hw updates could be lost. For example, hardware-updated dirty bits might be lost.
Avoid the parallel updates by clearing the page table entry when reading it together, using huge_ptep_get_and_clear(). If a parallel write to the memory is made after the clearing, the hw will see the page table entry is cleared, trigger page fault and wait until it is handled. The page fault handling will wait for damon_hugetlb_mkold() due to the page table lock.
Because hugetlbfs is an in-memory file system and hugetlb pages cannot be reclaimed, no critical issue is expected to my best knowledge. But definitely this is a nasty bug that should be fixed sooner rather than later.
The issue was discovered [1] by Sashiko.
--- mm/damon/vaddr.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
mm/damon/vaddr.c +12 -5
@@ -332,6 +332,17 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr, }#ifdef CONFIG_HUGETLB_PAGE +static bool damon_hugetlb_ptep_mkold (pte_t *pte,struct mm_struct *mm, +struct vm_area_struct *vma,unsigned long addr,pte_t *entry) +{ +if (!pte_young (*entry)) +return false; + *entry =huge_ptep_get_and_clear (mm, addr, pte); + *entry =pte_mkold (*entry); +set_huge_pte_at (mm, addr, pte, *entry); +return true; +} +static void damon_hugetlb_mkold (pte_t *pte,struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr) {
@@ -341,11 +352,7 @@ static void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,get_page (page); -if (pte_young (entry)) { - referenced = true; - entry =pte_mkold (entry); -set_huge_pte_at (mm, addr, pte, entry); - } + referenced =damon_hugetlb_ptep_mkold (pte, mm, vma, addr, &entry);#ifdef CONFIG_MMU_NOTIFIER if (mmu_notifier_clear_young(mm, addr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/2857 smb: client: delete compound mids on send failure before unlock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adarsh Das <[email protected]>
[ Upstream commit 8f6f8a48399f82f4a83f7b9f25b9707e0062a4f9 ]
When sending a compound request fails, smb_send_rqst() kicks off a reconnect. compound_send_recv() still has those mids on pending_mid_q, but it unlocks the server without removing them first.
During reconnect, cifs_abort_connection() walks pending_mid_q and runs each mid callback. With no response yet, those callbacks return credits and drop in_flight. Then compound_send_recv()'s send-error path returns the same credits again. in_flight ends up decremented twice and smb2_add_credits() WARNs.
syzbot hits this during SMB2_negotiate when the socket send fails.
cifs_call_async() already calls delete_mid() before unlock on send failure. Do the same for compound chains and set cancelled_mid[] so the
out: path does not delete them again.
--- fs/smb/client/transport.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/smb/client/transport.c +4 -0
@@ -1200,6 +1200,10 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,if (rc <0 ) {revert_current_mid (server, num_rqst); server->sequence_number -=2 ; +for (i =0 ; i < num_rqst; i++) { +delete_mid (midQ[i]); + cancelled_mid[i] = true; + } }cifs_server_unlock (server);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/2857 i2c: qcom-cci: Stop complaining about DT set clock rate
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan O'Donoghue <[email protected]>
[ Upstream commit 8284750a182937bf805f703311501730f02eb40e ]
It is common practice in the downstream and upstream CCI dt to set CCI clock rates to 19.2 MHz. It appears to be fairly common for initial code to set the CCI clock rate to 37.5 MHz.
Applying the widely used CCI clock rates from downstream ought not to cause warning messages in the upstream kernel where our general policy is to usually copy downstream hardware clock rates across the range of Qualcomm drivers.
Drop the warning it is pervasive across CAMSS users but doesn't add any information or warrant any changes to the DT to align the DT clock rate to the bootloader clock rate.
Stable-dep-of: 7362a1553eb0 ("i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()")
--- drivers/i2c/busses/i2c-qcom-cci.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +0 -8
@@ -603,14 +603,6 @@ static int cci_probe(struct platform_device *pdev) } } -if (cci_clk_rate != cci->data->cci_clk_rate) { -/* cci clock set by the bootloader or via assigned clock rate -* in DT. -*/ -dev_warn (dev,"Found %lu cci clk rate while %lu was expected\n" , - cci_clk_rate, cci->data->cci_clk_rate); - } - ret =cci_enable_clocks (cci);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/2857 i2c: qcom-cci: Remove the unused variable cci_clk_rate
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiapeng Chong <[email protected]>
[ Upstream commit b88c79699d72caa947ecaae85839b3563662ccce ]
Variable cci_clk_rate is not effectively used, so delete it.
drivers/i2c/busses/i2c-qcom-cci.c:526:16: warning: variable ‘cci_clk_rate’ set but not used.
Stable-dep-of: 7362a1553eb0 ("i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()")
--- drivers/i2c/busses/i2c-qcom-cci.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +0 -9
@@ -523,7 +523,6 @@ static const struct dev_pm_ops qcom_cci_pm = {static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -unsigned long cci_clk_rate =0 ;struct device_node *child;struct resource *r;struct cci *cci;
@@ -595,14 +594,6 @@ static int cci_probe(struct platform_device *pdev) } cci->nclocks = ret; -/* Retrieve CCI clock rate */ -for (i =0 ; i < cci->nclocks; i++) { -if (!strcmp (cci->clocks[i].id,"cci" )) { - cci_clk_rate =clk_get_rate (cci->clocks[i].clk); -break ; - } - } - ret =cci_enable_clocks (cci);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/2857 i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Zhenlong <[email protected]>
[ Upstream commit 7362a1553eb09a8cdf8be7e509bd5309a8342486 ]
The of_node_put() matching of_node_get() runs after i2c_del_adapter(), whose trailing memset() zeroes adap->dev and thus adap->dev.of_node, making the put a no-op and leaking the node on every adapter removal and error cleanup.
Use a devm action: the pointer is captured at registration, out of reach of that memset(), and devres runs the put once on probe failure and detach, replacing the three manual of_node_put() calls. The setup loop uses the scoped iterator form so the child node is released automatically if devm_add_action_or_reset() fails mid-loop.
--- drivers/i2c/busses/i2c-qcom-cci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +11 -9
@@ -520,10 +520,14 @@ static const struct dev_pm_ops qcom_cci_pm = { SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL) }; +static void cci_put_of_node (void *data) +{ +of_node_put (data); +} +static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct device_node *child;struct resource *r;struct cci *cci;int ret, i;
@@ -539,7 +543,7 @@ static int cci_probe(struct platform_device *pdev)if (!cci->data)return -ENOENT ; -for_each_available_child_of_node (dev->of_node, child) { +for_each_available_child_of_node_scoped (dev->of_node, child) {struct cci_master *master;u32 idx;
@@ -560,6 +564,9 @@ static int cci_probe(struct platform_device *pdev) master->adap.algo = &cci_algo; master->adap.dev.parent = dev; master->adap.dev.of_node =of_node_get (child); + ret =devm_add_action_or_reset (dev, cci_put_of_node, child); +if (ret) +return ret; master->master = idx; master->cci = cci;
@@ -634,10 +641,8 @@ static int cci_probe(struct platform_device *pdev)continue ; ret =i2c_add_adapter (&cci->master[i].adap); -if (ret <0 ) { -of_node_put (cci->master[i].adap.dev.of_node); +if (ret <0 ) goto error_i2c; - } }return 0 ;
@@ -645,10 +650,8 @@ static int cci_probe(struct platform_device *pdev) error_i2c:for (--i ; i >=0 ; i--) { -if (cci->master[i].cci) { +if (cci->master[i].cci)i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node); - } }disable_irq (cci->irq);
@@ -673,7 +676,6 @@ static int cci_remove(struct platform_device *pdev)for (i =0 ; i < cci->data->num_masters; i++) {if (cci->master[i].cci) {i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node);cci_halt (cci, i); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/2857 smb: client: clean up failed cached directory opens
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
[ Upstream commit d2ff5fb93ea83034025850266b5eed391f96b825 ]
open_cached_dir() sends CREATE and QUERY_INFO as a compound request. If the CREATE succeeds but a later command returns an error, the function must retain the CREATE FID so common cleanup can issue SMB2_close(). It also must not treat a response error as a valid CREATE.
Validate the CREATE response before using its fields, record the FIDs, and mark the handle open before handling errors from later compound commands. Move the -EREMCHG reconnect handling before response validation so a missing response does not hide the reconnect request. Count the handle when it is marked open; confirmed close responses decrement the counter, while existing close retry behavior remains best effort on transport failures.
--- fs/smb/client/cached_dir.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
fs/smb/client/cached_dir.c +23 -10
@@ -8,6 +8,7 @@#include <linux/namei.h> #include "cifsglob.h" #include "cifsproto.h" +#include "smb2status.h" #include "cifs_debug.h" #include "smb2proto.h" #include "cached_dir.h"
@@ -277,24 +278,37 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, rc =compound_send_recv (xid, ses, server, flags,2 , rqst, resp_buftype, rsp_iov); -if (rc) { -if (rc == -EREMCHG ) { - tcon->need_reconnect = true; -pr_warn_once ("server share %s deleted\n" , - tcon->tree_name); - } - goto oshr_free; +if (rc == -EREMCHG ) { + tcon->need_reconnect = true; +pr_warn_once ("server share %s deleted\n" , + tcon->tree_name); } - cfid->is_open = true; -spin_lock (&cfids->cfid_list_lock); +if (!rsp_iov[0 ].iov_base || rsp_iov[0 ].iov_len <sizeof (*o_rsp)) { +if (!rc) + rc = -EIO ; + goto oshr_free; + } o_rsp = (struct smb2_create_rsp *)rsp_iov[0 ].iov_base; +if (o_rsp->hdr.Status !=STATUS_SUCCESS ) { +if (!rc) + rc = -EIO ; + goto oshr_free; + } + oparms.fid->persistent_fid = o_rsp->PersistentFileId; oparms.fid->volatile_fid = o_rsp->VolatileFileId;#ifdef CONFIG_CIFS_DEBUG2 oparms.fid->mid =le64_to_cpu (o_rsp->hdr.MessageId);#endif /* CIFS_DEBUG2 */ + cfid->is_open = true; +atomic_inc (&tcon->num_remote_opens); + +if (rc) + goto oshr_free; + +spin_lock (&cfids->cfid_list_lock); rc = -EINVAL ;if (o_rsp->OplockLevel !=SMB2_OPLOCK_LEVEL_LEASE ) {
@@ -367,7 +381,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,free_cached_dir (cfid); }else { *ret_cfid = cfid; -atomic_inc (&tcon->num_remote_opens); }kfree (utf16_path);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 448/2857 KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 10180a277549339020b08000206092c07e0bff5a ]
Re-pend GET_NESTED_STATE_PAGES before exiting to userspace if getting the nested pages fails in the KVM_RUN path. If userspace re-runs the vCPU, and vmcs02 holds valid PFNs from the *previous* run of L2, then KVM could re-enter L2 with stale, unpinned PFNs mapped into e.g. the vAPIC page.
Note, both SVM and VMX (as of commit 11722439fb20 ("KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit") ensure the request is cleared on VM-Exit (including the "forced" case), i.e. there is no risk of double-mapping due to emulated VMLAUNCH/VMRESUME/VMRUN *and* the request trying to map the nested pages.
--- arch/x86/kvm/x86.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/x86.c +1 -0
@@ -10655,6 +10655,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) }if (kvm_check_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu)) {if (unlikely (!kvm_x86_ops.nested_ops->get_nested_state_pages (vcpu))) { +kvm_make_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu); r =0 ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/2857 KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit c1214f293d77c6e425a379f90d09bdb4815993a8 ]
Fill kvm_run with "internal error, emulation" in the common error handling paths for getting nested state pages, as requiring each check to manually fill kvm_run is error prone and requires a non-trivial amount of copy+paste.
Specifically, both SVM and VMX fail to fill kvm_run if load_pdptrs() fails, and SVM fails to fill kvm_run if kvm_hv_verify_vp_assist() fails. If those flows fail, the *best* case scenario is that KVM will exit to userspace with KVM_EXIT_UNKNOWN. The worst case scenario is that KVM exits with a stale exit_reason and confuses userspace.
Note, SVM never exits to userspace if something goes sideways when dealing with vmcb12 assets while emulating VMRUN, i.e. lack of SVM-specific code is not a bug.
--- arch/x86/kvm/svm/nested.c | 7 +------ arch/x86/kvm/vmx/nested.c | 15 +++++---------- arch/x86/kvm/x86.c | 3 +++ 3 files changed, 9 insertions(+), 16 deletions(-)
arch/x86/kvm/svm/nested.c +1 -6
@@ -1729,13 +1729,8 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)if (CC (!load_pdptrs (vcpu, vcpu->arch.cr3)))return false; -if (!nested_svm_vmrun_msrpm (svm)) { - vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; - vcpu->run->internal.suberror = -KVM_INTERNAL_ERROR_EMULATION ; - vcpu->run->internal.ndata =0 ; +if (!nested_svm_vmrun_msrpm (svm))return false; - }return true; }
arch/x86/kvm/vmx/nested.c +5 -10
@@ -3220,10 +3220,6 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu) }else {pr_debug_ratelimited ("%s: no backing for APIC-access address in vmcs12\n" , __func__); - vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; - vcpu->run->internal.suberror = -KVM_INTERNAL_ERROR_EMULATION ; - vcpu->run->internal.ndata =0 ;return false; } }
@@ -3287,11 +3283,6 @@ static bool vmx_get_nested_state_pages(struct kvm_vcpu *vcpu)if (!nested_get_evmcs_page (vcpu)) {pr_debug_ratelimited ("%s: enlightened vmptrld failed\n" , __func__); - vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; - vcpu->run->internal.suberror = -KVM_INTERNAL_ERROR_EMULATION ; - vcpu->run->internal.ndata =0 ; -return false; }
@@ -3693,8 +3684,12 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) vmentry_failed: vmx->nested.nested_run_pending =0 ; -if (status ==NVMX_VMENTRY_KVM_INTERNAL_ERROR ) +if (status ==NVMX_VMENTRY_KVM_INTERNAL_ERROR ) { + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ; + vcpu->run->internal.ndata =0 ;return 0 ; + }if (status ==NVMX_VMENTRY_VMEXIT )return 1 ;WARN_ON_ONCE (status !=NVMX_VMENTRY_VMFAIL );
arch/x86/kvm/x86.c +3 -0
@@ -10655,6 +10655,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) }if (kvm_check_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu)) {if (unlikely (!kvm_x86_ops.nested_ops->get_nested_state_pages (vcpu))) { + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ; + vcpu->run->internal.ndata =0 ;kvm_make_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu); r =0 ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 450/2857 virtio_net: copy zerocopy frags in start_xmit without NAPI
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 07e1a9408b6c2f9d0cfb757b67dabb52da7a32b2 ]
Virtio-net without NAPI frees completed skbs lazily on the next start_xmit. Senders waiting for in-flight zerocopy buffers can deadlock if they cannot transmit more packets, as then no completed packets will be freed.
When !use_napi, virtio-net already calls skb_orphan to avoid waiting up for transmitted skbs to be freed. For zerocopy packets that require deep copying on orphan (i.e. those that do not set SKBFL_DONT_ORPHAN, such as PACKET_TX_RING), call skb_orphan_frags before orphaning to release the buffers.
This fixes the tpacket_snd slot reuse bug on skb_orphan for virtio-net, and prevents PACKET_TX_RING from running out of slots.
This fix also touches vhost_net zerocopy packets, which also do not set SKBFL_DONT_ORPHAN. This is fine: vhost_net packets only encounter virtio-net in nested virtualization, and only if napi_tx is explicitly disabled (it has been default-enabled since Linux 4.12). In that rare case, copying the frags is desirable anyway to prevent holding guest descriptors pinned across unbounded intervals.
This is a prerequisite for the next patch, which converts PACKET_TX_RING to standard zerocopy completion. Without this patch first, a bounded ring sender can stall indefinitely behind a virtio-net virtqueue that cannot reclaim.
--- drivers/net/virtio_net.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/virtio_net.c +8 -0
@@ -1910,6 +1910,13 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) }while (use_napi && kick &&unlikely (!virtqueue_enable_cb_delayed (sq->vq))); +if (!use_napi && +unlikely (skb_orphan_frags (skb,GFP_ATOMIC ))) { + dev->stats.tx_dropped++; +dev_kfree_skb_any (skb); + goto kick_vq; + } +/* timestamp packet in software */ skb_tx_timestamp (skb);
@@ -1960,6 +1967,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) } } +kick_vq:if (kick ||netif_xmit_stopped (txq)) {if (virtqueue_kick_prepare (sq->vq) &&virtqueue_notify (sq->vq)) {u64_stats_update_begin (&sq->stats.syncp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/2857 net: macb: initialize PTP state before registering clock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit e1406330d70e56dd44fa6fbafc86e77e5c80c122 ]
gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready.
In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it.
This race is theoretical and has not been observed in practice.
Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock.
--- drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5104,6 +5104,7 @@ static int macb_probe(struct platform_device *pdev)spin_lock_init (&bp->lock);spin_lock_init (&bp->stats_lock); +spin_lock_init (&bp->tsu_clk_lock);/* setup capabilities */ macb_configure_caps (bp, macb_config);
drivers/net/ethernet/cadence/macb_ptp.c +1 -3
@@ -381,6 +381,7 @@ void gem_ptp_init(struct net_device *dev) bp->tsu_rate = bp->ptp_info->get_tsu_rate (bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj ();gem_ptp_init_timer (bp); +gem_ptp_init_tsu (bp); bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &dev->dev);if (IS_ERR (bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n",
@@ -392,15 +393,12 @@ void gem_ptp_init(struct net_device *dev)return ; } -spin_lock_init (&bp->tsu_clk_lock);for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { queue->tx_ts_head =0 ; queue->tx_ts_tail =0 ;INIT_WORK (&queue->tx_ts_task, gem_tx_timestamp_flush); } -gem_ptp_init_tsu (bp); -dev_info (&bp->pdev->dev,"%s ptp clock registered.\n" ,GEM_PTP_TIMER_NAME ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/2857 packet: use ubuf_info completion for TX_RING packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 9518405613863d0bf0700927a21367f5942cf058 ]
tpacket_snd sends skbs with frags pointing into its ring slots. Slots are released when skb->destructor is called.
A call to skb_orphan calls skb->destructor before the skb is freed. This can cause the slot to be reused while still linked into the skb.
Switch to standard zerocopy completion (ubuf_info) so the slot is only released once all references to the payload are freed or copied. Restore skb->destructor to standard sock_wfree.
The ubuf_info completion callback can be called with a NULL skb, but only from net_zcopy_put and related API, used by zerocopy implementations that hold their own reference on the uarg, such as MSG_ZEROCOPY. This uarg is only ever completed from skb_zcopy_clear, so skb is always set.
To prevent userspace from aliasing in-flight state on shared ring slots, allocate tpacket_uarg per packet, rather than per slot. This adds a small allocation to the transmit path. Use standard kmalloc to allow backporting to stable kernels.
The uarg holds an sk_wmem_alloc reference, rather than an sk_refcnt reference. packet_free_tx_ring waits on sk_wmem_alloc before freeing the ring pages. Always allocate vec->deferred for tx_ring so page-backed rings also wait on sk_wmem_alloc when skb_copy_ubufs drops page refs before calling tpacket_ubuf_complete.
Drop the tx_ring.pg_vec test that tpacket_destruct_skb performed before accessing the slot. The sk_wmem_alloc reference now guarantees that the slot is valid. The test is also not sufficient by itself, as it reads pg_vec without pg_vec_lock, so it can race with packet_set_ring.
As a result a slot is released when its payload is copied, which can be before transmission (e.g., in skb_orphan_frags_rx). If copied before skb_tx_timestamp() is called, no slot timestamp is recorded, similar to when skb_orphan() was called early in the datapath before this patch.
Revert the now unused previous skb_zcopy_.._nouarg infra.
Depends on commit 992cc9f94ca9 ("net/packet: defer vmalloc TX_RING free until skbs finish").
--- include/linux/skbuff.h | 19 +------- net/packet/af_packet.c | 98 ++++++++++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 56 deletions(-)
include/linux/skbuff.h +1 -18
@@ -1736,22 +1736,6 @@ static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg, } } -static inline void skb_zcopy_set_nouarg (struct sk_buff *skb,void *val) -{ -skb_shinfo (skb)->destructor_arg = (void *)((uintptr_t ) val |0x1UL ); -skb_shinfo (skb)->flags |=SKBFL_ZEROCOPY_FRAG ; -} - -static inline bool skb_zcopy_is_nouarg (struct sk_buff *skb) -{ -return (uintptr_t )skb_shinfo (skb)->destructor_arg &0x1UL ; -} - -static inline void *skb_zcopy_get_nouarg (struct sk_buff *skb) -{ -return (void *)((uintptr_t )skb_shinfo (skb)->destructor_arg & ~0x1UL ); -} -static inline void net_zcopy_put (struct ubuf_info *uarg) {if (uarg)
@@ -1774,8 +1758,7 @@ static inline void skb_zcopy_clear(struct sk_buff *skb, bool zerocopy_success)struct ubuf_info *uarg =skb_zcopy (skb);if (uarg) { -if (!skb_zcopy_is_nouarg (skb)) - uarg->callback (skb, uarg, zerocopy_success); + uarg->callback (skb, uarg, zerocopy_success);skb_shinfo (skb)->flags &= ~SKBFL_ALL_ZEROCOPY ; }
net/packet/af_packet.c +60 -38
154 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/2857 tty: n_gsm: fix missing modem controls after DLCI open in convergence layer type 2
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Starke <[email protected]>
[ Upstream commit 11ea5a63d30ad6d305b1c22301cd99ff45a98c8d ]
The current implementation only updates the virtual V.24 control signals after DLCI open in basic option mode. In advanced option mode with convergence layer type 2 an empty data frame needs to be transmitted to inform the peer about the initial virtual V.24 control signals. Not doing so has two unwanted side effects:
1. hardware flow control status is unclear (initial CTS line is unknown)
2. DLCI user presence is not transmitted (initial DTR line is unknown)
Applications waiting on these lines can not start after a DLCI has been opened until the first data frame has been transmitted.
Fix this by using gsm_modem_update() thoroughly which handles basic and advanced option mode correctly. Add a flag in gsm_modem_update() and the delegated gsm_modem_upd_via_msc() to control whether waiting for the MSC command response is possible. Remove obsolete gsm_modem_send_initial_msc().
--- drivers/tty/n_gsm.c | 47 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-)
drivers/tty/n_gsm.c +14 -33
@@ -414,13 +414,12 @@ static const u8 gsm_fcs8[256] = {#define GOOD_FCS 0xCFstatic int gsmld_output (struct gsm_mux *gsm,u8 *data,int len); -static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk); +static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk,bool wait);static struct gsm_msg *gsm_data_alloc (struct gsm_mux *gsm,u8 addr,int len,u8 ctrl);static int gsm_send_packet (struct gsm_mux *gsm,struct gsm_msg *msg);static void gsmld_write_trigger (struct gsm_mux *gsm);static void gsmld_write_task (struct work_struct *work); -static int gsm_modem_send_initial_msc (struct gsm_dlci *dlci);/** * gsm_fcs_add - update FCS
@@ -1835,7 +1834,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci)pr_debug ("DLCI %d goes open.\n" , dlci->addr);/* Send current modem state */ if (dlci->addr) -gsm_modem_send_initial_msc (dlci); +gsm_modem_update (dlci,0 , false);gsm_dlci_data_kick (dlci);wake_up (&dlci->gsm->event); }
@@ -3466,9 +3465,10 @@ static void gsm_modem_upd_via_data(struct gsm_dlci *dlci, u8 brk)* gsm_modem_upd_via_msc - send modem bits via control frame * @dlci: channel * @brk: break signal +* @wait: wait for the MSC command */ -static int gsm_modem_upd_via_msc (struct gsm_dlci *dlci,u8 brk) +static int gsm_modem_upd_via_msc (struct gsm_dlci *dlci,u8 brk,bool wait) {u8 modembits[3 ];struct gsm_control *ctrl;
@@ -3485,41 +3485,22 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk) modembits[2 ] = (brk <<4 ) |2 |EA ;/* Length, Break, EA */ len++; } +if (!wait) +return gsm_control_command (dlci->gsm,CMD_MSC , modembits, len); ctrl =gsm_control_send (dlci->gsm,CMD_MSC , modembits, len);if (ctrl ==NULL )return -ENOMEM ;return gsm_control_wait (dlci->gsm, ctrl); } -/** -* gsm_modem_send_initial_msc - Send initial modem status message -* -* @dlci channel -* -* Send an initial MSC message after DLCI open to set the initial -* modem status lines. This is only done for basic mode. -* Does not wait for a response as we cannot block the input queue -* processing. -*/ -static int gsm_modem_send_initial_msc (struct gsm_dlci *dlci) -{ -u8 modembits[2 ]; - -if (dlci->adaption !=1 || dlci->gsm->encoding !=GSM_BASIC_OPT ) -return 0 ; - - modembits[0 ] = (dlci->addr <<2 ) |2 |EA ;/* DLCI, Valid, EA */ - modembits[1 ] = (gsm_encode_modem (dlci) <<1 ) |EA ; -return gsm_control_command (dlci->gsm,CMD_MSC , (const u8 *)&modembits,2 ); -} -/** * gsm_modem_update - send modem status line state * @dlci: channel * @brk: break signal +* @wait: wait for the MSC command */ -static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk) +static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk,bool wait) {if (dlci->gsm->dead)return -EL2HLT ;
@@ -3529,7 +3510,7 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)return 0 ; }else if (dlci->gsm->encoding ==GSM_BASIC_OPT ) {/* Send as MSC control message. */ -return gsm_modem_upd_via_msc (dlci, brk); +return gsm_modem_upd_via_msc (dlci, brk, wait); }/* Modem status lines are not supported. */
@@ -3568,7 +3549,7 @@ static void gsm_dtr_rts(struct tty_port *port, int onoff) modem_tx &= ~(TIOCM_DTR |TIOCM_RTS );if (modem_tx != dlci->modem_tx) { dlci->modem_tx = modem_tx; -gsm_modem_update (dlci,0 ); +gsm_modem_update (dlci,0 , true); } }
@@ -3760,7 +3741,7 @@ static int gsmtty_tiocmset(struct tty_struct *tty,if (modem_tx != dlci->modem_tx) { dlci->modem_tx = modem_tx; -return gsm_modem_update (dlci,0 ); +return gsm_modem_update (dlci,0 , true); }return 0 ; }
@@ -3822,7 +3803,7 @@ static void gsmtty_throttle(struct tty_struct *tty) dlci->modem_tx &= ~TIOCM_RTS ; dlci->throttled = true;/* Send an MSC with RTS cleared */ -gsm_modem_update (dlci,0 ); +gsm_modem_update (dlci,0 , true); }static void gsmtty_unthrottle (struct tty_struct *tty)
@@ -3834,7 +3815,7 @@ static void gsmtty_unthrottle(struct tty_struct *tty) dlci->modem_tx |=TIOCM_RTS ; dlci->throttled = false;/* Send an MSC with RTS set */ -gsm_modem_update (dlci,0 ); +gsm_modem_update (dlci,0 , true); }static int gsmtty_break_ctl (struct tty_struct *tty,int state)
@@ -3852,7 +3833,7 @@ static int gsmtty_break_ctl(struct tty_struct *tty, int state)if (encode >0x0F ) encode =0x0F ;/* Best effort */ } -return gsm_modem_update (dlci, encode); +return gsm_modem_update (dlci, encode, true); }static void gsmtty_cleanup (struct tty_struct *tty)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/2857 serial: fix ioctl hangup race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 8ca59f7baee7c72cf7729950b4ab2e7f910c9549 ]
The tty ioctls can race with hangup and end up calling into a tty driver for a device that is already gone or powered down.
Add the missing checks to make sure the port has not been hung up before accessing the hardware to avoid issues like kernel panic due to unclocked accesses.
Note that TIOCGSERIAL, TIOCGICOUNT do not access hardware and are therefore not affected by the race.
Also note that the initialised check in uart_set_ldisc() added by commit 2f70e49ed860 ("serial_core: Check for port state when tty is in error state") should have been done under the port lock to avoid racing with uart_do_autoconfig().
--- drivers/tty/serial/serial_core.c | 52 +++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-)
drivers/tty/serial/serial_core.c +38 -14
@@ -816,7 +816,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,upf_t old_flags, new_flags;int retval =0 ; -if (!uport) +if (!uport ||tty_io_error (tty))return -EIO ; new_port = new_info->port;
@@ -1120,7 +1120,7 @@ static int uart_break_ctl(struct tty_struct *tty, int break_state)mutex_lock (&port->mutex); uport =uart_port_check (state); -if (!uport) +if (!uport ||tty_io_error (tty)) goto out;if (uport->type !=PORT_UNKNOWN && uport->ops->break_ctl)
@@ -1149,7 +1149,7 @@ static int uart_do_autoconfig(struct tty_struct *tty, struct uart_state *state)return -ERESTARTSYS ; uport =uart_port_check (state); -if (!uport) { +if (!uport ||tty_io_error (tty)) { ret = -EIO ; goto out; }
@@ -1204,7 +1204,7 @@ static void uart_enable_ms(struct uart_port *uport)* FIXME: This wants extracting into a common all driver implementation * of TIOCMWAIT using tty_port. */ -static int uart_wait_modem_status (struct uart_state *state,unsigned long arg) +static int uart_wait_modem_status (struct tty_struct *tty,struct uart_state *state,unsigned long arg) {struct uart_port *uport;struct tty_port *port = &state->port;
@@ -1215,14 +1215,26 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)/* * note the counters on entry */ +mutex_lock (&port->mutex); uport =uart_port_ref (state); -if (!uport) +if (!uport) { +mutex_unlock (&port->mutex);return -EIO ; + } + +if (tty_io_error (tty)) { +mutex_unlock (&port->mutex); + ret = -EIO ; + goto out_deref; + } +spin_lock_irq (&uport->lock);memcpy (&cprev, &uport->icount,sizeof (struct uart_icount ));uart_enable_ms (uport);spin_unlock_irq (&uport->lock); +mutex_unlock (&port->mutex); +add_wait_queue (&port->delta_msr_wait, &wait);for (;;) {set_current_state (TASK_INTERRUPTIBLE );
@@ -1251,6 +1263,7 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg) }__set_current_state (TASK_RUNNING );remove_wait_queue (&port->delta_msr_wait, &wait); +out_deref:uart_port_deref (uport);return ret;
@@ -1568,7 +1581,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)*/ switch (cmd) {case TIOCMIWAIT : - ret =uart_wait_modem_status (state, arg); + ret =uart_wait_modem_status (tty, state, arg);break ; }
@@ -1629,15 +1642,15 @@ static void uart_set_ldisc(struct tty_struct *tty) {struct uart_state *state = tty->driver_data;struct uart_port *uport; -struct tty_port *port = &state->port; - -if (!tty_port_initialized (port)) -return ;mutex_lock (&state->port.mutex); uport =uart_port_check (state); -if (uport && uport->ops->set_ldisc) +if (!uport ||tty_io_error (tty)) + goto out; + +if (uport->ops->set_ldisc) uport->ops->set_ldisc (uport, &tty->termios); +out:mutex_unlock (&state->port.mutex); }
@@ -1652,7 +1665,7 @@ static void uart_set_termios(struct tty_struct *tty,mutex_lock (&state->port.mutex); uport =uart_port_check (state); -if (!uport) +if (!uport ||tty_io_error (tty)) goto out;/*
@@ -1817,14 +1830,25 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)* 'timeout' / 'expire' give us the maximum amount of time * we wait. */ -while (!port->ops->tx_empty (port)) { +for (;;) { +bool done; + +uart_port_deref (port); +mutex_lock (&state->port.mutex); + port =uart_port_ref (state); + done = !port ||tty_io_error (tty) || port->ops->tx_empty (port); +mutex_unlock (&state->port.mutex); +if (done) +break ; +msleep_interruptible (jiffies_to_msecs (char_time));if (signal_pending (current))break ;if (timeout &&time_after (jiffies, expire))break ; } -uart_port_deref (port); +if (port) +uart_port_deref (port); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/2857 serial: abort TIOCMIWAIT on hangup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit eb35b73e133686e5b999eb7130c4e3d22fe03089 ]
Add the missing hangup check to the TIOCMIWAIT wait loop to avoid going back to sleep (indefinitely) after being woken on hangup.
--- drivers/tty/serial/serial_core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/tty/serial/serial_core.c +5 -0
@@ -1251,6 +1251,11 @@ static int uart_wait_modem_status(struct tty_struct *tty, struct uart_state *stabreak ; } +if (tty_io_error (tty)) { + ret = -EIO ; +break ; + } +schedule ();/* see if a signal did it */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/2857 serial: 8250_omap: fix wake irq cleared during suspend
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kendall Willis <[email protected]>
[ Upstream commit 73f3e6ca7a6a7c952977c7c94f1c6dddebcafa34 ]
The wake irq was cleared in shutdown(), which runs during the suspend sequence, making it impossible to wake the system via UART. Move wake irq setup to probe() and teardown to remove() so the irq remains armed during suspend when the UART is a wakeup source.
--- drivers/tty/serial/8250/8250_omap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/tty/serial/8250/8250_omap.c +9 -8
@@ -685,12 +685,6 @@ static int omap_8250_startup(struct uart_port *port)struct omap8250_priv *priv = port->private_data;int ret; -if (priv->wakeirq) { - ret =dev_pm_set_dedicated_wake_irq (port->dev, priv->wakeirq); -if (ret) -return ret; - } -pm_runtime_get_sync (port->dev);serial_out (up,UART_FCR ,UART_FCR_CLEAR_RCVR |UART_FCR_CLEAR_XMIT );
@@ -740,7 +734,6 @@ static int omap_8250_startup(struct uart_port *port) err:pm_runtime_mark_last_busy (port->dev);pm_runtime_put_autosuspend (port->dev); -dev_pm_clear_wake_irq (port->dev);return ret; }
@@ -775,7 +768,6 @@ static void omap_8250_shutdown(struct uart_port *port)pm_runtime_mark_last_busy (port->dev);pm_runtime_put_autosuspend (port->dev);free_irq (port->irq, port); -dev_pm_clear_wake_irq (port->dev); }static void omap_8250_throttle (struct uart_port *port)
@@ -1468,6 +1460,13 @@ static int omap8250_probe(struct platform_device *pdev) } }#endif + +if (priv->wakeirq) { + ret =dev_pm_set_dedicated_wake_irq (&pdev->dev, priv->wakeirq); +if (ret) + goto err; + } + ret =serial8250_register_8250_port (&up);if (ret <0 ) {dev_err (&pdev->dev,"unable to register 8250 port\n" );
@@ -1478,6 +1477,7 @@ static int omap8250_probe(struct platform_device *pdev)pm_runtime_put_autosuspend (&pdev->dev);return 0 ; err: +dev_pm_clear_wake_irq (&pdev->dev);pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_put_sync (&pdev->dev);flush_work (&priv->qos_work);
@@ -1497,6 +1497,7 @@ static int omap8250_remove(struct platform_device *pdev)serial8250_unregister_port (priv->line); priv->line = -ENODEV ; +dev_pm_clear_wake_irq (&pdev->dev);pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_put_sync (&pdev->dev);flush_work (&priv->qos_work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/2857 HID: multitouch: stop the release timer from being rearmed on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
[ Upstream commit 5acb2dace582f061aab5e14c399ac9480315f44b ]
mt_remove() quiesces the sticky-finger timer before stopping the hardware:
timer_delete_sync(&td->release_timer);
sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
hid_hw_stop(hdev);timer_delete_sync() waits for a running callback and dequeues the timer, but it does not stop the timer from being armed again. The transport is still delivering reports at that point, and the report path rearms it:
if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
if (td->mt_io_flags & MT_IO_SLOTS_MASK)
mod_timer(&td->release_timer,
jiffies + msecs_to_jiffies(100));A report that arrives after timer_delete_sync() has returned therefore leaves the timer queued. td is allocated with devm_kzalloc() against hdev->dev, so it is freed when the driver is unbound, after mt_remove() returns. When the timer fires afterwards, mt_expired_timeout() dereferences the freed td:
struct mt_device *td = timer_container_of(td, t, release_timer);
struct hid_device *hdev = td->hdev;
if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))Simply moving the teardown after hid_hw_stop() does not fix this on its own, because mt_expired_timeout() calls mt_release_contacts(), which walks hdev->inputs; the timer still has to be quiesced before hid_hw_stop() tears the input devices down.
Use timer_shutdown_sync() instead, which additionally makes any later mod_timer() a no-op, so neither ordering constraint has to be traded off against the other. This is the final-teardown pattern the function was introduced for, and hid-wiimote already uses it for the same reason.
--- drivers/hid/hid-multitouch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-multitouch.c +1 -1
@@ -1892,7 +1892,7 @@ static void mt_remove(struct hid_device *hdev) {struct mt_device *td =hid_get_drvdata (hdev); -del_timer_sync (&td->release_timer); +timer_shutdown_sync (&td->release_timer);sysfs_remove_group (&hdev->dev.kobj, &mt_attribute_group);hid_hw_stop (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/2857 x86/mce: Fix hardware debug register corruption on task migration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit b8d1d5b63a8ef532038eebd9d97d406860385668 ]
In exc_machine_check_user(), local_db_save() and local_db_restore() are invoked in the outer entry stubs (DEFINE_IDTENTRY_MCE_USER, DEFINE_FREDENTRY_MCE, and DEFINE_IDTENTRY_RAW), surrounding exc_machine_check_user().
However, exc_machine_check_user() calls irqentry_exit_to_user_mode(), which handles pending thread work and may schedule() if TIF_NEED_RESCHED is set. If the task migrates to another CPU during schedule(), local_db_restore() runs on the new CPU with the dr7 state saved from the old CPU. This corrupts the new CPU's DR7 hardware debug register and leaves the old CPU's DR7 disabled. In short, local_db_save() and local_db_restore() pair must be run on the same CPU.
To fix this, move local_db_save() and local_db_restore() inside exc_machine_check_user() and exc_machine_check_kernel(). In exc_machine_check_user(), DR7 is saved and restored strictly around do_machine_check() to avoid schedule() during migration. In exc_machine_check_kernel(), local_db_save() is called at the entry point to prevent early memory accesses from triggering nested #DB exceptions, and restored on all exits.
--- arch/x86/kernel/cpu/mce/core.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/mce/core.c +10 -13
@@ -2117,6 +2117,9 @@ bool filter_mce(struct mce *m) static __always_inline void exc_machine_check_kernel(struct pt_regs *regs) {irqentry_state_t irq_state; +unsigned long dr7; + + dr7 =local_db_save ();WARN_ON_ONCE (user_mode (regs));
@@ -2125,20 +2128,26 @@ static __always_inline void exc_machine_check_kernel(struct pt_regs *regs)* mce_check_crashing_cpu() for details. */ if (mca_cfg.initialized &&mce_check_crashing_cpu ()) -return ; + goto out; irq_state =irqentry_nmi_enter (regs);do_machine_check (regs);irqentry_nmi_exit (regs, irq_state); +out: +local_db_restore (dr7); } static __always_inline void exc_machine_check_user(struct pt_regs *regs) { +unsigned long dr7; +irqentry_enter_from_user_mode (regs); + dr7 =local_db_save ();do_machine_check (regs); +local_db_restore (dr7);irqentry_exit_to_user_mode (regs); }
@@ -2147,34 +2156,22 @@ static __always_inline void exc_machine_check_user(struct pt_regs *regs)/* MCE hit kernel mode */ DEFINE_IDTENTRY_MCE (exc_machine_check) { -unsigned long dr7; - - dr7 =local_db_save ();exc_machine_check_kernel (regs); -local_db_restore (dr7); }/* The user mode variant. */ DEFINE_IDTENTRY_MCE_USER (exc_machine_check) { -unsigned long dr7; - - dr7 =local_db_save ();exc_machine_check_user (regs); -local_db_restore (dr7); }#else /* 32bit unified entry point */ DEFINE_IDTENTRY_RAW (exc_machine_check) { -unsigned long dr7; - - dr7 =local_db_save ();if (user_mode (regs))exc_machine_check_user (regs);else exc_machine_check_kernel (regs); -local_db_restore (dr7); }#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/2857 drm/amd/display: Whitespace cleanup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 3335a13535312c9fad4d8d1307a621e6617d6ed8 ]
Commit 075e2099c32c ("drm/amd/display: Fix race condition in DPIA AUX transfer") was backported to stable, which I noticed because of git saying
linux-6.1/.git/rebase-apply/patch:37154: space before tab in indent.
while applying patch-6.1.21. While fixing the code location that issued that warning, improve in few more places.
Stable-dep-of: c5fd4eaad50d ("drm/amd/display: Fix dc stream excess put in dm_update_crtc_state()")
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +13 -13
@@ -2336,9 +2336,9 @@ static int dm_late_init(void *handle)*/ params.min_abm_backlight =0x28F ;/* In the case where abm is implemented on dmcub, -* dmcu object will be null. -* ABM 2.4 and up are implemented on dmcub. -*/ +* dmcu object will be null. +* ABM 2.4 and up are implemented on dmcub. +*/ if (dmcu) {if (!dmcu_load_iram (dmcu, params))return -EINVAL ;
@@ -7087,13 +7087,13 @@ static uint add_fs_modes(struct amdgpu_dm_connector *aconnector)/* Standard FPS values * * 23.976 - TV/NTSC -* 24 - Cinema -* 25 - TV/PAL +* 24 - Cinema +* 25 - TV/PAL * 29.97 - TV/NTSC -* 30 - TV/NTSC -* 48 - Cinema HFR -* 50 - TV/PAL -* 60 - Commonly used +* 30 - TV/NTSC +* 48 - Cinema HFR +* 50 - TV/PAL +* 60 - Commonly used * 48,72,96,120 - Multiples of 24 */ static const u32 common_rates[] = {
@@ -7719,7 +7719,7 @@ static void update_freesync_state_on_stream(return ;spin_lock_irqsave (&adev_to_drm (adev)->event_lock, flags); - vrr_params = acrtc->dm_irq_params.vrr_params; + vrr_params = acrtc->dm_irq_params.vrr_params;if (surface) { mod_freesync_handle_preflip(
@@ -8274,7 +8274,7 @@ static void amdgpu_dm_commit_audio(struct drm_device *dev,if (!drm_atomic_crtc_needs_modeset (new_crtc_state))continue ; - notify: +notify:if (connector->connector_type ==DRM_MODE_CONNECTOR_WRITEBACK )continue ;
@@ -9303,7 +9303,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm, skip_modeset:/* Release extra reference */ if (new_stream) -dc_stream_release (new_stream); +dc_stream_release (new_stream); new_stream =NULL ;/*
@@ -10699,7 +10699,7 @@ int amdgpu_dm_process_dmub_aux_transfer_sync(if (!dc_process_dmub_aux_transfer_async (ctx->dc, link_index, payload)) { *operation_result =AUX_RET_ERROR_ENGINE_ACQUIRE ; goto out; - } + }if (!wait_for_completion_timeout (&adev->dm.dmub_aux_transfer_done,10 *HZ )) {DRM_ERROR ("wait_for_completion_timeout timeout!" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/2857 drm/amd/display: Fix dc stream excess put in dm_update_crtc_state()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit c5fd4eaad50d620c7e09ac2082b2fb55ee54170e ]
In dm_update_crtc_state(), when a modeset is required the newly created stream is stored in dm_new_crtc_state->stream and an extra reference is taken with dc_stream_retain(). The reference returned by create_validate_stream_for_sink() is released as an extra reference at the skip_modeset label, leaving the stream owned by the new CRTC state.
If amdgpu_dm_check_crtc_color_mgmt() fails afterwards, the code jumps to the fail label which releases new_stream again. Since the extra reference was already released at skip_modeset, this drops the reference owned by dm_new_crtc_state->stream and the stream is released while the atomic state still points to it, leading to a premature free of the dc stream.
Set new_stream to NULL after releasing the extra reference at the skip_modeset label so that a later goto fail cannot release the reference owned by the new CRTC state.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -1
@@ -9302,8 +9302,10 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm, skip_modeset:/* Release extra reference */ -if (new_stream) +if (new_stream) {dc_stream_release (new_stream); + new_stream =NULL ; + } new_stream =NULL ;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/2857 drm/amd/display: Bump frame warning limit for clang builds of dml
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Lipski <[email protected]>
[ Upstream commit 18779dd84515db093fedb4ebaf0998c9b165a5fb ]
[Why&How]
When building the DML files with clang without any sanitizer or LTO, the following -Wframe-larger-than errors break the build under CONFIG_WERROR:
display_mode_vba_30.c: error: stack frame size (2512) exceeds limit
(2048) in 'dml30_ModeSupportAndSystemConfigurationFull'
display_mode_vba_31.c: error: stack frame size (2416) exceeds limit
(2048) in 'dml31_ModeSupportAndSystemConfigurationFull'
display_mode_vba_314.c: error: stack frame size (2392) exceeds limit
(2048) in 'dml314_ModeSupportAndSystemConfigurationFull'
Clang consistently spills more than gcc, pushing the frame past the 2048 byte limit.
Apply an existing approach of increasing the warn stack size to the non-sanitizer path so plain clang builds use a 3072 byte limit.
--- drivers/gpu/drm/amd/display/dc/dml/Makefile | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/dc/dml/Makefile +4 -0
@@ -55,9 +55,13 @@ ifneq ($(CONFIG_FRAME_WARN),0) ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) frame_warn_flag := -Wframe-larger-than=3072 else +ifeq ($(CONFIG_CC_IS_CLANG),y) +frame_warn_flag := -Wframe-larger-than=3072 +else frame_warn_flag := -Wframe-larger-than=2048 endif endif +endif CFLAGS_$(AMDDALPATH)/dc/dml/display_mode_lib.o := $(dml_ccflags)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/2857 drm/amdgpu/pm: add workload profile pause helper
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit 7f991dd3641ef52e0a25b43f27cc61440c4bdcb4 ]
To be used for display idle optimizations when
we want to pause non-default profiles.
Stable-dep-of: 1f1d43418d61 ("drm/amdgpu: skip gfx switch_power_profile during GPU reset")
--- .../gpu/drm/amd/include/kgd_pp_interface.h | 1 + drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 19 +++++++++++++++++++ drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 ++ 3 files changed, 22 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -340,6 +340,7 @@ struct amd_pm_funcs {int (*set_pp_table)(void *handle,const char *buf,size_t size);void (*debugfs_print_current_performance_level)(void *handle,struct seq_file *m);int (*switch_power_profile)(void *handle,enum PP_SMC_POWER_PROFILE type,bool en); +int (*pause_power_profile)(void *handle,bool pause);/* export to amdgpu */ struct amd_vce_state *(*get_vce_clock_state)(void *handle,u32 idx); int (*dispatch_tasks)(void *handle, enum amd_pp_task task_id,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +19 -0
@@ -301,6 +301,25 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,return ret; } +int amdgpu_dpm_pause_power_profile (struct amdgpu_device *adev, +bool pause) +{ +const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; +int ret =0 ; + +if (amdgpu_sriov_vf (adev)) +return 0 ; + +if (pp_funcs && pp_funcs->pause_power_profile) { +mutex_lock (&adev->pm.mutex); + ret = pp_funcs->pause_power_profile ( + adev->powerplay.pp_handle, pause); +mutex_unlock (&adev->pm.mutex); + } + +return ret; +} +int amdgpu_dpm_set_xgmi_pstate (struct amdgpu_device *adev,uint32_t pstate) {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
@@ -384,6 +384,8 @@ int amdgpu_dpm_set_xgmi_pstate(struct amdgpu_device *adev,int amdgpu_dpm_switch_power_profile (struct amdgpu_device *adev,enum PP_SMC_POWER_PROFILE type,bool en); +int amdgpu_dpm_pause_power_profile (struct amdgpu_device *adev, +bool pause);int amdgpu_dpm_baco_reset (struct amdgpu_device *adev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/2857 net: mctp: avoid confusion over local/peer dest/source addresses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeremy Kerr <[email protected]>
[ Upstream commit ee076b73e576b0a052d5686d873346b285ae50ea ]
We have a double-swap of local and peer addresses in mctp_alloc_local_tag; the arguments in both call sites are swapped, but there is also a swap in the implementation of alloc_local_tag. This is opaque because we're using source/dest address references, which don't match the local/peer semantics.
Avoid this confusion by naming the arguments as 'local' and 'peer', and remove the double swap. The calling order now matches mctp_key_alloc.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- include/net/mctp.h | 4 ++-- net/mctp/af_mctp.c | 2 +- net/mctp/route.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-)
include/net/mctp.h +2 -2
@@ -90,7 +90,7 @@ struct mctp_sock { };/* Key for matching incoming packets to sockets or reassembly contexts. -* Packets are matched on (src,dest,tag). +* Packets are matched on (peer EID, local EID, tag). * * Lifetime / locking requirements: *
@@ -258,7 +258,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,void mctp_key_unref (struct mctp_sk_key *key);struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, -mctp_eid_t daddr,mctp_eid_t saddr, +mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp);/* routing <--> device interface */
net/mctp/af_mctp.c +1 -1
@@ -366,7 +366,7 @@ static int mctp_ioctl_alloctag(struct mctp_sock *msk, unsigned long arg)if (ctl.flags)return -EINVAL ; - key =mctp_alloc_local_tag (msk, ctl.peer_addr,MCTP_ADDR_ANY , + key =mctp_alloc_local_tag (msk,MCTP_ADDR_ANY , ctl.peer_addr, true, &tag);if (IS_ERR (key))return PTR_ERR (key);
net/mctp/route.c +8 -8
@@ -634,11 +634,11 @@ static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,refcount_inc (&key->refs); } -/* Allocate a locally-owned tag value for (saddr, daddr), and reserve +/* Allocate a locally-owned tag value for (local, peer), and reserve * it for the socket msk */ struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, -mctp_eid_t daddr,mctp_eid_t saddr, +mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp) {struct net *net =sock_net (&msk->sk);
@@ -648,11 +648,11 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,u8 tagbits;/* for NULL destination EIDs, we may get a response from any peer */ -if (daddr ==MCTP_ADDR_NULL ) - daddr =MCTP_ADDR_ANY ; +if (peer ==MCTP_ADDR_NULL ) + peer =MCTP_ADDR_ANY ;/* be optimistic, alloc now */ - key =mctp_key_alloc (msk, saddr, daddr,0 ,GFP_KERNEL ); + key =mctp_key_alloc (msk, local, peer,0 ,GFP_KERNEL );if (!key)return ERR_PTR (-ENOMEM );
@@ -673,8 +673,8 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,if (tmp->tag &MCTP_HDR_FLAG_TO )continue ; -if (!(mctp_address_matches (tmp->peer_addr, daddr) && -mctp_address_matches (tmp->local_addr, saddr))) +if (!(mctp_address_matches (tmp->peer_addr, peer) && +mctp_address_matches (tmp->local_addr, local)))continue ;spin_lock (&tmp->lock);
@@ -966,7 +966,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, key =mctp_lookup_prealloc_tag (msk, daddr, req_tag, &tag); else - key =mctp_alloc_local_tag (msk, daddr, saddr, + key =mctp_alloc_local_tag (msk, saddr, daddr, false, &tag);if (IS_ERR (key)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/2857 net: mctp: Add some detail on the key allocation implementation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeremy Kerr <[email protected]>
[ Upstream commit aee6479a458e2c5027e558cfe26c60c37f8efc80 ]
We could do with a little more comment on where MCTP_ADDR_ANY will match in the key allocations.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- net/mctp/route.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
net/mctp/route.c +37 -0
@@ -73,6 +73,40 @@ static struct mctp_sock *mctp_lookup_bind(struct net *net, struct sk_buff *skb)return NULL ; } +/* A note on the key allocations. +* +* struct net->mctp.keys contains our set of currently-allocated keys for +* MCTP tag management. The lookup tuple for these is the peer EID, +* local EID and MCTP tag. +* +* In some cases, the peer EID may be MCTP_EID_ANY: for example, when a +* broadcast message is sent, we may receive responses from any peer EID. +* Because the broadcast dest address is equivalent to ANY, we create +* a key with (local = local-eid, peer = ANY). This allows a match on the +* incoming broadcast responses from any peer. +* +* We perform lookups when packets are received, and when tags are allocated +* in two scenarios: +* +* - when a packet is sent, with a locally-owned tag: we need to find an +* unused tag value for the (local, peer) EID pair. +* +* - when a tag is manually allocated: we need to find an unused tag value +* for the peer EID, but don't have a specific local EID at that stage. +* +* in the latter case, on successful allocation, we end up with a tag with +* (local = ANY, peer = peer-eid). +* +* So, the key set allows both a local EID of ANY, as well as a peer EID of +* ANY in the lookup tuple. Both may be ANY if we prealloc for a broadcast. +* The matching (in mctp_key_match()) during lookup allows the match value to +* be ANY in either the dest or source addresses. +* +* When allocating (+ inserting) a tag, we need to check for conflicts amongst +* the existing tag set. This requires macthing either exactly on the local +* and peer addresses, or either being ANY. +*/ +static bool mctp_key_match (struct mctp_sk_key *key,mctp_eid_t local,mctp_eid_t peer,u8 tag) {
@@ -386,6 +420,9 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)* key lookup to find the socket, but don't use this * key for reassembly - we'll create a more specific * one for future packets if required (ie, !EOM). +* +* this lookup requires key->peer to be MCTP_ADDR_ANY, +* it doesn't match just any key->peer. */ any_key =mctp_lookup_key (net, skb,MCTP_ADDR_ANY , &f);if (any_key) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/2857 drm/amdgpu: skip gfx switch_power_profile during GPU reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prike Liang <[email protected]>
[ Upstream commit 1f1d43418d61c8511779e0f63a954a78b9433b43 ]
During resume from GPU reset, the gfx idle work may invoke switch_power_profile before the reset completes. This causes the following assert error because the register access occurs without first releasing the GPU reset semaphore:
[ 1576.768935] CR2: 0000559ea133ead0 CR3: 00000002e6c42000 CR4: 0000000000350ef0 [ 1576.768940] Call Trace: [ 1576.768944] <TASK> [ 1576.768953] amdgpu_device_rreg+0x21/0x50 [amdgpu] [ 1576.769158] smu_msg_v1_send_msg+0x1a4/0x6e0 [amdgpu] [ 1576.769437] smu_cmn_send_smc_msg_with_params_ext+0xba/0x120 [amdgpu] [ 1576.769721] smu_cmn_send_smc_msg_with_param+0x33/0x40 [amdgpu] [ 1576.769993] smu_v13_0_0_set_power_profile_mode+0x192/0x2b0 [amdgpu] [ 1576.770267] smu_bump_power_profile_mode+0x5d/0x80 [amdgpu] [ 1576.770538] smu_switch_power_profile+0xa4/0xf0 [amdgpu] [ 1576.770839] amdgpu_dpm_switch_power_profile+0x6f/0x90 [amdgpu] [ 1576.771210] amdgpu_gfx_profile_idle_work_handler+0xe9/0x130 [amdgpu] [ 1576.771460] process_one_work+0x23e/0x6f0 [ 1576.771491] worker_thread+0x1c4/0x380 [ 1576.771506] kthread+0x10c/0x150 [ 1576.771512] ? __pfx_worker_thread+0x10/0x10 [ 1576.771518] ? __pfx_kthread+0x10/0x10 [ 1576.771530] ret_from_fork+0x314/0x390 [ 1576.771537] ? __pfx_kthread+0x10/0x10 [ 1576.771546] ret_from_fork_asm+0x1a/0x30
--- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -2
@@ -288,7 +288,8 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;int ret =0 ; -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) || +amdgpu_in_reset (adev))return 0 ;if (pp_funcs && pp_funcs->switch_power_profile) {
@@ -307,7 +308,8 @@ int amdgpu_dpm_pause_power_profile(struct amdgpu_device *adev,const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;int ret =0 ; -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) || +amdgpu_in_reset (adev))return 0 ;if (pp_funcs && pp_funcs->pause_power_profile) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/2857 drm/msm: RCU-free the scheduler-containing ring and VM objects
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonghyuk Kim(MalHyuk) <[email protected]>
[ Upstream commit 01c8d1f385f788f1bbbbb7687c4386d614281218 ]
Both struct msm_ringbuffer and struct msm_gem_vm embed a struct drm_gpu_scheduler. msm_ringbuffer_destroy() and the VM free callback msm_gem_vm_free() call drm_sched_fini() on the embedded scheduler and then free the containing object with plain kfree().
drm_sched_fence_get_timeline_name() returns fence->sched->name, and the scheduler fence keeps a .release callback so it is not ops-detached on signalling. A finished fence exported to userspace (the submit out-fence, or a VM_BIND fence, via sync_file / drm_syncobj) keeps pointing at the embedded scheduler after the ring/VM is freed, so a later get_timeline_name() -- reachable unprivileged through SYNC_IOC_FILE_INFO -- dereferences freed slab memory (KASAN slab-use-after-free read).
Per the dma-fence lifetime contract the exporter must keep the data backing a signalled fence alive for an RCU grace period. Free the scheduler-containing objects with kfree_rcu() instead of kfree().
Patchwork: https://patchwork.freedesktop.org/patch/750234/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_ringbuffer.c +1 -1
@@ -130,5 +130,5 @@ void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)msm_gem_kernel_put (ring->bo, ring->gpu->aspace); -kfree (ring); +kfree_rcu (ring, rcu); }
drivers/gpu/drm/msm/msm_ringbuffer.h +1 -0
@@ -49,6 +49,7 @@ struct msm_ringbuffer {/* * The job scheduler for this ring. */ +struct rcu_head rcu;struct drm_gpu_scheduler sched;bool sched_initialized;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/2857 arm64: Use load LSE atomics for the non-return per-CPU atomic operations
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
[ Upstream commit 535fdfc5a228524552ee8810c9175e877e127c27 ]
The non-return per-CPU this_cpu_*() atomic operations are implemented as STADD/STCLR/STSET when FEAT_LSE is available. On many microarchitecture implementations, these instructions tend to be executed "far" in the interconnect or memory subsystem (unless the data is already in the L1 cache). This is in general more efficient when there is contention as it avoids bouncing cache lines between CPUs. The load atomics (e.g. LDADD without XZR as destination), OTOH, tend to be executed "near" with the data loaded into the L1 cache.
STADD executed back to back as in srcu_read_{lock,unlock}*() incur an additional overhead due to the default posting behaviour on several CPU implementations. Since the per-CPU atomics are unlikely to be used concurrently on the same memory location, encourage the hardware to to execute them "near" by issuing load atomics - LDADD/LDCLR/LDSET - with the destination register unused (but not XZR).
Stable-dep-of: 8cf2093f5372 ("arm64: percpu: Fix LSE operations on {8,16}-bit types")
--- arch/arm64/include/asm/percpu.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
arch/arm64/include/asm/percpu.h +11 -4
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %[ptr]\n" \ +#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -124,9 +124,16 @@ PERCPU_RW_OPS(8) PERCPU_RW_OPS(16) PERCPU_RW_OPS(32)PERCPU_RW_OPS (64 ) -PERCPU_OP(add, add, stadd) -PERCPU_OP(andnot, bic, stclr) -PERCPU_OP(or, orr, stset) + +/* +* Use value-returning atomics for CPU-local ops as they are more likely +* to execute "near" to the CPU (e.g. in L1$). +* +* https://lore.kernel.org/r/e7d539ed-ced0-4b96-8ecd-048a5b803b85@paulmck-laptop + */ +PERCPU_OP(add, add, ldadd) +PERCPU_OP(andnot, bic, ldclr) +PERCPU_OP(or, orr, ldset) PERCPU_RET_OP(add, add, ldadd)#undef PERCPU_RW_OPS
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/2857 arm64: percpu: Fix LSE operations on {8,16}-bit types
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
[ Upstream commit 8cf2093f5372952a9ebc805c418d45df7112cd14 ]
The assembly for __percpu_##name##_case_##sz() and __percpu_##name##_return_case_##sz() doesn't use the 'sfx' macro argument to form the LSE instruction. Without 'sfx', a W register argument will imply a 32-bit memory location, and consequently {8,16}-bit ops will erroneously read and write 32 bits of memory when the LSE instruction is used.
Fix this by appending 'sfx' to 'op_lse' to LSE instruction. It is not necessary (and not valid) to append 'sfx' to 'op_llsc', as 'op_llsc' is a register-register operation which does not access memory (and does not take a size suffix).
--- arch/arm64/include/asm/percpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/percpu.h +2 -2
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -98,7 +98,7 @@ __percpu_##name##_return_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[ret], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ #op_llsc "\t%" #w "[ret], %" #w "[ret], %" #w "[val]\n" \ __nops(2)) \ : [loop] "=&r" (loop), [ret] "=&r" (ret), \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/2857 io_uring/rw: end write accounting from ->ki_complete
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit 796aa0547557e63338657ed1c487906f9fac4c73 ]
Commit b000145e9907 moved both the fsnotify calls and the write accounting out of the kiocb completion handler and into the io_req_rw_complete() task_work. However, only the fsnotify part actually needed to move as it may sleep. Ending the write accounting is just a percpu_up_read() on the superblock writers sem.
Deferring it is a problem, because it makes dropping SB_FREEZE_WRITE protection depend on the ring owner getting to running task_work. But the task may be blocked in freeze_super(), causing it to never get to that:
task io-wq worker
--------------------------------------------------------------
io_write()
io_kiocb_start_write() (takes sb_writers, hidden from
lockdep by __sb_writers_release)
write_iter() -> -EIOCBQUEUED
ioctl(FS_IOC_SHUTDOWN)
bdev_freeze()
freeze_super()
percpu_down_write() <- waits for the reader above
io_write()
kiocb_start_write()
percpu_down_read() <- queued
behind the writer
<bio completes>
io_complete_rw()
queues io_req_rw_complete() <- never runs, task is in D state
End the write from io_complete_rw() instead, and leave only the fsnotify calls in task_work.
--- io_uring/rw.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
io_uring/rw.c +20 -10
@@ -215,20 +215,25 @@ static void io_req_end_write(struct io_kiocb *req) } } -/* -* Trigger the notifications after having done some IO, and finish the write -* accounting, if any. -*/ -static void io_req_io_end (struct io_kiocb *req) +/* Trigger the notifications after having done some IO. */ +static void io_req_io_notify (struct io_kiocb *req) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); -if (rw->kiocb.ki_flags &IOCB_WRITE ) { -io_req_end_write (req); +if (rw->kiocb.ki_flags &IOCB_WRITE )fsnotify_modify (req->file); - }else { +else fsnotify_access (req->file); - } +} + +/* Finish write accounting and notify, for inline completions only. */ +static void io_req_io_end (struct io_kiocb *req) +{ + struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); + +if (rw->kiocb.ki_flags &IOCB_WRITE ) +io_req_end_write (req); +io_req_io_notify (req); }static bool __io_complete_rw_common (struct io_kiocb *req,long res)
@@ -266,7 +271,7 @@ static inline int io_fixup_rw_res(struct io_kiocb *req, long res)static void io_req_rw_complete (struct io_kiocb *req,bool *locked) { -io_req_io_end (req); +io_req_io_notify (req);io_req_task_complete (req, locked); }
@@ -277,6 +282,11 @@ static void io_complete_rw(struct kiocb *kiocb, long res)if (__io_complete_rw_common (req, res))return ; + +/* ring owner may block in freeze_super() before task_work runs */ +if (kiocb->ki_flags &IOCB_WRITE ) +io_req_end_write (req); +io_req_set_res (req,io_fixup_rw_res (req, res),0 ); req->io_task_work.func = io_req_rw_complete;io_req_task_work_add (req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 464/2857 mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit 26cc0e69cce062cd3aa6fae33074684669c35a71 ]
When a socket transmits a packet with MCTP_TAG_PREALLOC set, mctp_lookup_prealloc_tag() iterates over the per-netns &mns->keys list and matches netid, req_tag, peer_addr, and manual_alloc, without checking whether tmp->sk == &msk->sk. This allows any MCTP socket in the same network namespace to use and consume another socket's preallocated tag.
Iterate the socket's own tag list (&msk->keys via sklist) instead of the namespace-wide &mns->keys list in mctp_lookup_prealloc_tag(), ensuring that only tags allocated by msk are matched.
Tested in QEMU against Linux 7.3.0-rc3 by allocating a manual tag (0x18) on socket A via SIOCMCTPALLOCTAG for peer EID 9 and sending a 4-byte message with MCTP_TAG_PREALLOC from socket B in the same network namespace. On the unfixed kernel, sendto(sock_b) using socket A's preallocated tag succeeds (ret = 4); with this patch applied, sendto(sock_b) fails with -ENOENT (errno = 2) while sendto(sock_a) succeeds (ret = 4).
--- net/mctp/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mctp/route.c +1 -1
@@ -773,7 +773,7 @@ static struct mctp_sk_key *mctp_lookup_prealloc_tag(struct mctp_sock *msk,spin_lock_irqsave (&mns->keys_lock, flags); -hlist_for_each_entry (tmp, &mns->keys, hlist) { +hlist_for_each_entry (tmp, &msk->keys, sklist) {if (tmp->net != netid)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 473/2857 smb: client: flush and commit data before querying allocated ranges
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit aa994489bd835547c191827acc460192e147032d ]
The mode 0 / FALLOC_FL_KEEP_SIZE fallocate emulation for small interior ranges in smb3_simple_fallocate_range() issues FSCTL_QUERY_ALLOCATED_RANGES and zero-fills any sub-range the server reports as an unallocated hole, to force block allocation without changing file contents.
This is unsafe against Windows servers. Per the Win32 documentation, FSCTL_QUERY_ALLOCATED_RANGES only reports ranges that *may* contain nonzero data and is explicitly not coherent with recently written data:
"a call to FSCTL_QUERY_ALLOCATED_RANGES [after writing to a network
file] would not necessarily return a correct list of allocated regions. To ensure coherency [...] flush the data to the file"
fsx (generic/363) reproduces the resulting corruption against Windows Server 2022: a range is written, an uncached read returns the data, yet the next FSCTL_QUERY_ALLOCATED_RANGES on that range reports it as a whole hole, so the emulation overwrites live data with zeroes. A network trace confirmed the WRITE, the READ returning data and the query returning an empty range list within microseconds. Samba does not exhibit this; its query is coherent with the written data.
Write back the dirty pages, drain any outstanding I/O and issue an SMB2 FLUSH to force the server to commit the data before querying the allocated ranges, so the query reflects the data actually present.
With this, generic/363 passes against both Windows Server 2022 and Samba over 100000 fsx operations.
--- fs/smb/client/smb2ops.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
fs/smb/client/smb2ops.c +27 -8
@@ -3683,9 +3683,27 @@ static int smb3_simple_fallocate_range(unsigned int xid,u32 out_data_len;char *buf =NULL ;u64 range_start, range_len, range_end; +struct inode *inode =d_inode (cfile->dentry);loff_t l;int rc; +filemap_invalidate_lock (inode->i_mapping); + +/* +* Flush and commit the data to the server, otherwise +* FSCTL_QUERY_ALLOCATED_RANGES might report recently written data as +* unallocated holes on Windows Servers, and the loop below would +* then zero-fill them and corrupt the file. +*/ + rc =filemap_write_and_wait_range (inode->i_mapping, off, + off + len -1 ); +if (rc) + goto out_unlock; + rc =SMB2_flush (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid); +if (rc) + goto out_unlock; + in_data.file_offset =cpu_to_le64 (off); in_data.length =cpu_to_le64 (len); rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
@@ -3695,12 +3713,12 @@ static int smb3_simple_fallocate_range(unsigned int xid,1024 *sizeof (struct file_allocated_range_buffer ), (char **)&out_data, &out_data_len);if (rc) - goto out; + goto out_unlock; buf =kzalloc (1024 *1024 ,GFP_KERNEL );if (buf ==NULL ) { rc = -ENOMEM ; - goto out; + goto out_unlock; } tmp_data = out_data;
@@ -3711,12 +3729,12 @@ static int smb3_simple_fallocate_range(unsigned int xid,if (out_data_len ==0 ) { rc =smb3_simple_fallocate_write_range (xid, tcon, cfile, off, len, buf); - goto out; + goto out_unlock; }if (out_data_len <sizeof (struct file_allocated_range_buffer )) { rc = -EINVAL ; - goto out; + goto out_unlock; } range_start =le64_to_cpu (tmp_data->file_offset);
@@ -3724,7 +3742,7 @@ static int smb3_simple_fallocate_range(unsigned int xid,if (check_add_overflow (range_start, range_len, &range_end) || range_end >S64_MAX ) { rc = -EINVAL ; - goto out; + goto out_unlock; }if (off < range_start) {
@@ -3739,11 +3757,11 @@ static int smb3_simple_fallocate_range(unsigned int xid, rc =smb3_simple_fallocate_write_range (xid, tcon, cfile, off, l, buf);if (rc) - goto out; + goto out_unlock; off = off + l; len = len - l;if (len ==0 ) - goto out; + goto out_unlock; }/* * We are at a section of allocated data, just skip forward
@@ -3762,7 +3780,8 @@ static int smb3_simple_fallocate_range(unsigned int xid, out_data_len -=sizeof (struct file_allocated_range_buffer ); } - out: + out_unlock: +filemap_invalidate_unlock (inode->i_mapping);kfree (out_data);kfree (buf);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 474/2857 smb: client: flush dirty data before zeroing a range
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 8f8d32c1044f70e46e87550e039a15ff20a4b21c ]
smb3_zero_range() emulates FALLOC_FL_ZERO_RANGE by invalidating the page cache over the target range with truncate_pagecache_range() and then issuing FSCTL_SET_ZERO_DATA to the server.
Dirty data was only flushed conditionally, when the range reached or extended EOF. For a purely interior zero range that does not reach EOF, no flush happened, so a dirty folio overlapping the range could be written back to the server after the FSCTL and refill the range that was just zeroed with stale data.
Fix this by unconditionally flushing and waiting for dirty data in the range before invalidating the page cache and issuing FSCTL_SET_ZERO_DATA, exactly as was done for smb3_punch_hole() in commit d7d2adcd022b ("smb/client: flush dirty data before punching a hole"); the two paths are structurally identical here.
This is observed as generic/363 randomly reading stale data where a zeroed range is expected against Windows Server.
--- fs/smb/client/smb2ops.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
fs/smb/client/smb2ops.c +5 -9
@@ -3515,8 +3515,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,struct inode *inode =file_inode (file);struct cifsInodeInfo *cifsi =CIFS_I (inode);struct cifsFileInfo *cfile = file->private_data; -struct netfs_inode *ictx =netfs_inode (inode); -unsigned long long i_size, new_size, remote_size; +unsigned long long i_size, new_size;long rc;unsigned int xid;__le64 eof;
@@ -3530,14 +3529,11 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,filemap_invalidate_lock (inode->i_mapping); i_size =i_size_read (inode); - remote_size = ictx->remote_i_size; -if (offset + len >= remote_size && offset < i_size) { -unsigned long long top =umin (offset + len, i_size); - rc =filemap_write_and_wait_range (inode->i_mapping, offset, top -1 ); -if (rc <0 ) - goto zero_range_exit; - } + rc =filemap_write_and_wait_range (inode->i_mapping, offset, + offset + len -1 ); +if (rc <0 ) + goto zero_range_exit;/* * We zero the range through ioctl, so we need remove the page caches
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 475/2857 smb: client: drain and invalidate before server-side copy/clone
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit c9b1194e8ec99d95db25db45edd2fbf690f043ab ]
cifs_file_copychunk_range() and the clone (FICLONE) path of cifs_remap_file_range() do not serialise the destination page cache against the server-side copy the way the other server-side range operations (smb3_zero_range(), smb3_punch_hole(), smb3_collapse_range() and smb3_insert_range()) do.
cifs_file_copychunk_range() invalidates the destination range with filemap_invalidate_inode(), which takes and drops the mapping's invalidate_lock internally, so the lock is no longer held when the copychunk ioctl is issued. It also never drains in-flight netfs I/O on the target. The clone path never takes the invalidate_lock at all (only i_rwsem), uses a bare truncate_inode_pages_range() and likewise does not drain outstanding I/O.
As a result an asynchronous destination writeback can complete after the server-side copy/clone has run and reinstate stale data over the region just written by the server, corrupting the file. This is the same class of corruption as commit d7d2adcd022b ("smb/client: flush dirty data before punching a hole") and has been seen randomly in generic/363 against Windows Server.
Fix both paths to follow the established ordering: hold the target mapping's invalidate_lock across the flush and invalidation of the destination and the server ioctl, and call netfs_wait_for_outstanding_io() on the target to drain in-flight writes before the ioctl is issued. Only the target inode's invalidate_lock is required, as the source is merely flushed and not invalidated; i_rwsem (already held via lock_two_nondirectories()) is acquired before the invalidate_lock, matching the VFS lock ordering. Since filemap_invalidate_inode() takes that same lock internally, replace it with its own unmap/flush/invalidate steps instead of calling it, and return early on a zero-length copy to avoid a range underflow.
--- fs/smb/client/cifsfs.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/cifsfs.c +7 -0
@@ -1317,6 +1317,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,* server could even support copy of range where source = target */ lock_two_nondirectories (target_inode, src_inode); +filemap_invalidate_lock (target_inode->i_mapping);if (len ==0 ) {loff_t src_size =i_size_read (src_inode);
@@ -1409,6 +1410,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,that target is updated on the server */ CIFS_I (target_inode)->time =0 ; unlock: +filemap_invalidate_unlock (target_inode->i_mapping);/* although unlocking in the reverse order from locking is not strictly necessary here it is a little cleaner to be consistent */ unlock_two_nondirectories (src_inode, target_inode);
@@ -1432,6 +1434,9 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,unsigned long long destend, fstart, fend;ssize_t rc; +if (len ==0 ) +return 0 ; +cifs_dbg (FYI ,"copychunk range\n" );if (!src_file->private_data || !dst_file->private_data) {
@@ -1461,6 +1466,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,* server could even support copy of range where source = target */ lock_two_nondirectories (target_inode, src_inode); +filemap_invalidate_lock (target_inode->i_mapping);cifs_dbg (FYI ,"about to flush pages\n" );
@@ -1513,6 +1519,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,CIFS_I (target_inode)->time =0 ; unlock: +filemap_invalidate_unlock (target_inode->i_mapping);/* although unlocking in the reverse order from locking is not * strictly necessary here it is a little cleaner to be consistent */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 476/2857 smb: client: only require read lease for size-extending zero range
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit fafc68cccf8a00ed0a1f47c1413a3f16ce4dcdfa ]
smb3_zero_range() refuses any FALLOC_FL_ZERO_RANGE that clears FALLOC_FL_KEEP_SIZE with -EOPNOTSUPP whenever the inode is not read caching:
/* if file not oplocked can't be sure whether asking to extend size */ rc = -EOPNOTSUPP; if (keep_size == false && !CIFS_CACHE_READ(cifsi)) goto zero_range_exit;
The read lease is only needed to trust the cached i_size when deciding whether the range extends the file. When it is not held, the size can instead be fetched from the server, which is authoritative, rather than refusing the request outright: query the server's end of file and take the larger of it and the cached size for the interior-vs-extend decision. The larger of the two is used because the server's end of file reflects another client's growth while the cached size reflects this client's own writes that may not have reached the server yet; using the server size alone would wrongly shrink the file when the range flush above left an extending write unwritten.
The query isn't lease-protected either, so its result is only trusted to confirm the range is interior, never to justify extending: if it still shows the range going past EOF, refuse with -EOPNOTSUPP instead of calling SMB2_set_eof(), which could otherwise shrink the file if another client extended it further between the query and the call. For the same reason, take the larger of the already-computed i_size and a fresh i_size_read(inode) right before that call, instead of relying on either
alone: the local variable carries the query's result, which is never written back to the inode, while a concurrent write on this client can still extend the cached i_size during the flush, the query, or the zero-data round trip that happen in between.
Rejecting interior ranges is observed as generic/363 randomly failing against Windows Server with
do_zero_range: fallocate: Operation not supported
fsx issues an interior, non-KEEP_SIZE zero range while the inode is transiently not read caching: the server had just downgraded the file's lease from RWH to RH after breaking the write caching, and the ensuing handle reopen/revalidation left CIFS_CACHE_READ momentarily clear. The range sat well within the server's end of file, so no extend was needed, yet the range was refused and fsx aborted. This keeps the emulation correct even when a genuine lease break from another client leaves the inode without read caching -- the case the -EOPNOTSUPP guard turned into a hard failure. The extra round trip only happens on the no-lease path; the common cached case is unchanged.
--- fs/smb/client/smb2ops.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
fs/smb/client/smb2ops.c +28 -7
@@ -3507,6 +3507,21 @@ static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon, 0, NULL, NULL); } +static long query_server_eof (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifsFileInfo *cfile, +unsigned long long *eof) +{ +struct smb2_file_all_info file_inf = {}; +long rc; + + rc =SMB2_query_info (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, &file_inf); +if (!rc) + *eof =le64_to_cpu (file_inf.EndOfFile); +return rc; +} +static long smb3_zero_range (struct file *file,struct cifs_tcon *tcon,unsigned long long offset,unsigned long long len,bool keep_size)
@@ -3515,7 +3530,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,struct inode *inode =file_inode (file);struct cifsInodeInfo *cifsi =CIFS_I (inode);struct cifsFileInfo *cfile = file->private_data; -unsigned long long i_size, new_size; +unsigned long long i_size, remote_i_size, new_size;long rc;unsigned int xid;__le64 eof;
@@ -3544,10 +3559,17 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,*/ truncate_pagecache_range (inode,min (offset, i_size), offset + len -1 ); -/* if file not oplocked can't be sure whether asking to extend size */ - rc = -EOPNOTSUPP ; -if (keep_size == false && !CIFS_CACHE_READ (cifsi)) - goto zero_range_exit; + new_size = offset + len; +if (!keep_size && !CIFS_CACHE_READ (cifsi)) { + rc =query_server_eof (xid, tcon, cfile, &remote_i_size); +if (rc) + goto zero_range_exit; + i_size =max (i_size, remote_i_size); +if (i_size < new_size) { + rc = -EOPNOTSUPP ; + goto zero_range_exit; + } + } rc =smb3_zero_data (file, tcon, offset, len, xid);if (rc <0 )
@@ -3556,8 +3578,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,/* * do we also need to change the size of the file? */ - new_size = offset + len; -if (keep_size == false && (unsigned long long )i_size_read (inode) < new_size) { +if (!keep_size &&umax (i_size,i_size_read (inode)) < new_size) { eof =cpu_to_le64 (new_size); rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, &eof);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 477/2857 dm-integrity: validate the superblock on resume
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit fc79aeb86a2c244c1f1894e2d8f2966fe2b60fa2 ]
dm_integrity_resume() re-reads the superblock from the device so that it picks up the flags and the recalculate position. It performs no validation on the result, while the constructor validates the superblock it reads and sizes all the in-memory structures according to it. The user may modify the superblock on the underlying device while the dm-integrity device is suspended, so that the two no longer agree.
In particular, access_journal_data() shifts the journal entry index by ic->sb->log2_sectors_per_block, while ic->journal_section_sectors and the journal page list were computed with the value that was present at constructor time. Increasing log2_sectors_per_block makes the index run past the end of the journal, and dm-integrity then writes 512 bytes through lowmem_page_address(NULL).
Snapshot the validated superblock in the constructor and refuse to resume if any of the fields that describe the on-disk geometry changed.
--- drivers/md/dm-integrity.c | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/md/dm-integrity.c +49 -0
@@ -171,6 +171,7 @@ struct dm_integrity_c {struct dm_bufio_client *bufio;struct workqueue_struct *metadata_wq;struct superblock *sb; +struct superblock *sb_copy;unsigned int journal_pages;unsigned int n_bitmap_blocks;
@@ -3238,6 +3239,34 @@ static void dm_integrity_postsuspend(struct dm_target *ti) ic->journal_uptodate = true; } +/* +* The superblock is re-read from the device on every resume, so that we pick +* up the flags and the recalculate position. The geometry described by the +* superblock must not change though - the in-memory structures (and the +* journal in particular) were sized according to the superblock that was +* validated in the constructor. Reject a superblock that was modified behind +* our back. +* +* Only the fields that the driver never rewrites may be tested here. In +* particular, "version" is recalculated by sb_set_version on every superblock +* write and it depends on SB_FLAG_RECALCULATING and SB_FLAG_DIRTY_BITMAP, and +* SB_FLAG_DISCARD_KEYED may be set by dm_integrity_resume itself. +*/ +static bool superblock_changed (struct dm_integrity_c *ic) +{ +const __le32 immutable_flags =cpu_to_le32 (SB_FLAG_HAVE_JOURNAL_MAC | +SB_FLAG_FIXED_PADDING | +SB_FLAG_FIXED_HMAC ); + +return memcmp (ic->sb->magic, ic->sb_copy->magic,sizeof (ic->sb->magic)) !=0 || + ic->sb->log2_interleave_sectors != ic->sb_copy->log2_interleave_sectors || + ic->sb->integrity_tag_size != ic->sb_copy->integrity_tag_size || + ic->sb->journal_sections != ic->sb_copy->journal_sections || + ic->sb->log2_sectors_per_block != ic->sb_copy->log2_sectors_per_block || + ((ic->sb->flags ^ ic->sb_copy->flags) & immutable_flags) !=0 || +memcmp (ic->sb->salt, ic->sb_copy->salt,SALT_SIZE ) !=0 ; +} +static void dm_integrity_resume (struct dm_target *ti) {struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private;
@@ -3254,6 +3283,18 @@ static void dm_integrity_resume(struct dm_target *ti)if (r)dm_integrity_io_error (ic,"reading superblock" , r); +if (unlikely (superblock_changed (ic))) { +/* +* Restore the superblock that we validated in the constructor, +* so that the rest of the driver doesn't operate on values +* that don't match the in-memory structures. +*/ +memcpy (ic->sb, ic->sb_copy,sizeof (struct superblock )); +DMERR ("The superblock was changed while the device was suspended" ); +dm_integrity_io_error (ic,"superblock check" , -EINVAL ); + goto skip_writes; + } +if (ic->mode =='R' ) goto skip_writes;
@@ -4667,6 +4708,13 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv ic->just_formatted = true; } + ic->sb_copy =kmemdup (ic->sb,sizeof (struct superblock ),GFP_KERNEL ); +if (!ic->sb_copy) { + ti->error ="Cannot allocate superblock copy" ; + r = -ENOMEM ; + goto bad; + } +if (!ic->meta_dev) { r =dm_set_target_max_io_len (ti,1U << ic->sb->log2_interleave_sectors);if (r)
@@ -4763,6 +4811,7 @@ static void dm_integrity_dtr(struct dm_target *ti)kvfree (ic->journal_tree);if (ic->sb)free_pages_exact (ic->sb,SB_SECTORS <<SECTOR_SHIFT ); +kfree (ic->sb_copy);if (ic->internal_hash)crypto_free_shash (ic->internal_hash);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 478/2857 perf: Replace perf_event_header__init_id with full header init
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit b9d1fdc6f4ac1b6e49f9deafaf137da1407d9af1 ]
perf_iterate_sb() invokes its callback for each matching perf_event on the CPU and task context, passing a shared caller-allocated event structure.
perf_event_header__init_id() mutated header->size in place by adding event->id_header_size, requiring sideband output callbacks to save and restore header fields across iterations. Three sideband callbacks failed to save and restore header.size around perf_event_header__init_id():
- perf_event_ksymbol_output()
- perf_event_bpf_output()
- perf_event_text_poke_output()
When multiple events with attr.ksymbol, attr.bpf_event, or attr.text_poke and sample_id_all are active on the same CPU, each subsequent event receives a record whose header.size is inflated by all preceding events' id_header_size values while only a single id_sample is written, leaving uninitialized ring-buffer bytes at the end of the record and causing userspace perf to fail with -EFAULT ("Bad address") when parsing the sample_id trailer.
Similarly, perf_event_mmap_output() set PERF_RECORD_MISC_MMAP_BUILD_ID in mmap_event->event_id.header.misc when event->attr.build_id was enabled, but only saved and restored header.size and header.type. If an event with attr.build_id was followed by an event with attr.mmap2 and !attr.build_id, the second event received PERF_RECORD_MISC_MMAP_BUILD_ID in header.misc while its payload contained maj/min/ino/ino_generation instead of a build ID.
Rather than splitting header initialization between callers and output callbacks and saving/restoring mutated header fields, replace perf_event_header__init_id() with perf_event_header__init(), which initializes header->type, header->misc, and header->size alongside the sample_id fields on each invocation.
--- arch/powerpc/perf/imc-pmu.c | 23 +-- include/linux/perf_event.h | 7 +- kernel/events/core.c | 288 +++++++++++++++--------------------- kernel/events/ring_buffer.c | 7 +- 4 files changed, 140 insertions(+), 185 deletions(-)
arch/powerpc/perf/imc-pmu.c +12 -11
@@ -1279,6 +1279,8 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem,struct perf_event_header *header, struct perf_event *event) { + u16 misc = 0; +/* Sanity checks for a valid record */ if (be64_to_cpu (READ_ONCE (mem->tb1)) > *prev_tb) *prev_tb =be64_to_cpu (READ_ONCE (mem->tb1));
@@ -1293,23 +1295,19 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem, data->ip =be64_to_cpu (READ_ONCE (mem->ip)); data->period = event->hw.last_period; - header->type =PERF_RECORD_SAMPLE ; - header->size =sizeof (*header) + event->header_size; - header->misc =0 ; -if (cpu_has_feature (CPU_FTR_ARCH_31 )) {switch (IMC_TRACE_RECORD_VAL_HVPR (be64_to_cpu (READ_ONCE (mem->val)))) {case 0 :/* when MSR HV and PR not set in the trace-record */ - header->misc |=PERF_RECORD_MISC_GUEST_KERNEL ; + misc |=PERF_RECORD_MISC_GUEST_KERNEL ;break ;case 1 :/* MSR HV is 0 and PR is 1 */ - header->misc |=PERF_RECORD_MISC_GUEST_USER ; + misc |=PERF_RECORD_MISC_GUEST_USER ;break ;case 2 :/* MSR HV is 1 and PR is 0 */ - header->misc |=PERF_RECORD_MISC_KERNEL ; + misc |=PERF_RECORD_MISC_KERNEL ;break ;case 3 :/* MSR HV is 1 and PR is 1 */ - header->misc |=PERF_RECORD_MISC_USER ; + misc |=PERF_RECORD_MISC_USER ;break ;default :pr_info ("IMC: Unable to set the flag based on MSR bits\n" );
@@ -1317,11 +1315,14 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem, } }else {if (is_kernel_addr (data->ip)) - header->misc |=PERF_RECORD_MISC_KERNEL ; + misc |=PERF_RECORD_MISC_KERNEL ;else - header->misc |=PERF_RECORD_MISC_USER ; + misc |=PERF_RECORD_MISC_USER ; } -perf_event_header__init_id (header, data, event); +perf_event_header__init (header, data, +PERF_RECORD_SAMPLE , misc, +sizeof (*header) + event->header_size, + event);return 0 ; }
include/linux/perf_event.h +4 -3
@@ -1172,9 +1172,10 @@ static inline bool uses_default_overflow_handler(struct perf_event *event)#endif extern void -perf_event_header__init_id (struct perf_event_header *header, -struct perf_sample_data *data, -struct perf_event *event); +perf_event_header__init (struct perf_event_header *header, +struct perf_sample_data *data, +u32 type,u16 misc,u16 size, +struct perf_event *event); extern void perf_event__output_id_sample(struct perf_event *event, struct perf_output_handle *handle,
kernel/events/core.c +121 -167
608 lines not on this page · raw message
kernel/events/ring_buffer.c +3 -4
@@ -241,14 +241,13 @@ __perf_output_begin(struct perf_output_handle *handle, handle->size = (1UL << page_shift) - offset;if (unlikely (have_lost)) { - lost_event.header.size =sizeof (lost_event); - lost_event.header.type =PERF_RECORD_LOST ; - lost_event.header.misc =0 ; lost_event.id = event->id; lost_event.lost =local_xchg (&rb->lost,0 );/* XXX mostly redundant; @data is already fully initializes */ -perf_event_header__init_id (&lost_event.header, data, event); +perf_event_header__init (&lost_event.header, data, +PERF_RECORD_LOST ,/* misc= */ 0 , +sizeof (lost_event), event);perf_output_put (handle, lost_event);perf_event__output_id_sample (event, handle, data); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 479/2857 namespace: check a recursive bind mount for mount namespace loops
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit c640a01a78e42302879006ed7b7d5a9a943ba815 ]
do_loopback() refuses to bind mount the file of a mount namespace that is as old as the caller's or older because a mount namespace that holds a mount of its own file, or of an ancestor's, would cause a cycle. But it only checks the dentry the bind mount starts from. With MS_REC everything below it is copied and do_loopback() passes CL_COPY_MNT_NS_FILE so mount namespace files below the source are copied.
That's fine for a source in the caller's own mount namespace. Every mount namespace file in there passed the same check when it was bind-mounted. It isn't fine for a source in another mount namespace. may_copy_tree() accepts a bind mount of any nsfs or pidfs file no matter what mount namespace it lives in so that /proc/<pid>/ns/<ns> and pidfds can be bind mounted. If we create a bind-mount stack of mount namespaces file descriptors the kernel will copy them irrespective of their ancestoral relationship to the mount namespace in question:
151 146 0:7 net:[4026531833] /tmp/nrc/y rw - nsfs nsfs rw 152 151 0:7 mnt:[4026532293] /tmp/nrc/y rw - nsfs nsfs rw
Mount 152 is a mount of the mount namespace file of mount namespace 4026532293 inside mount namespace 4026532293. That namespace and every mount in it are leaked... All it takes is a process in an older mount namespace that stacks the file and repeating it leaks without limit:
after control: Shmem: 380 kB
child: mount(/proc/self/fd/6, MS_BIND|MS_REC): ok
after cycle: Shmem: 65916 kB
do_move_mount() runs check_for_nsfs_mounts() over a detached tree for exactly that reason. Do the same for the copy before it is grafted.
--- fs/namespace.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-)
fs/namespace.c +27 -23
@@ -2468,6 +2468,28 @@ static struct mount *__do_loopback(struct path *old_path, int recurse)return mnt; } +/* +* Check that there aren't references to earlier/same mount namespaces in the +* specified subtree. Such references can act as pins for mount namespaces +* that aren't checked by the mount-cycle checking code, thereby allowing +* cycles to be made. +*/ +static bool check_for_nsfs_mounts (struct mount *subtree) +{ +struct mount *p; +bool ret = false; + +lock_mount_hash (); +for (p = subtree; p; p =next_mnt (p, subtree)) +if (mnt_ns_loop (p->mnt.mnt_root)) + goto out; + + ret = true; +out: +unlock_mount_hash (); +return ret; +} +/* * do loopback mount. */
@@ -2504,7 +2526,11 @@ static int do_loopback(struct path *path, const char *old_name, goto out2; } - err =graft_tree (mnt, parent, mp); +/* the copy may carry mount namespace files from below the source */ +if (recurse && !check_for_nsfs_mounts (mnt)) + err = -EINVAL ; +else + err =graft_tree (mnt, parent, mp);if (err) {lock_mount_hash ();umount_tree (mnt,UMOUNT_SYNC );
@@ -2790,28 +2816,6 @@ static inline int tree_contains_unbindable(struct mount *mnt)return 0 ; } -/* -* Check that there aren't references to earlier/same mount namespaces in the -* specified subtree. Such references can act as pins for mount namespaces -* that aren't checked by the mount-cycle checking code, thereby allowing -* cycles to be made. -*/ -static bool check_for_nsfs_mounts (struct mount *subtree) -{ -struct mount *p; -bool ret = false; - -lock_mount_hash (); -for (p = subtree; p; p =next_mnt (p, subtree)) -if (mnt_ns_loop (p->mnt.mnt_root)) - goto out; - - ret = true; -out: -unlock_mount_hash (); -return ret; -} -static int do_set_group (struct path *from_path,struct path *to_path) {struct mount *from, *to;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 480/2857 drm/amdgpu: skip the noirq suspend reset for a switcheroo-parked GPU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Theo Andersen Carton <[email protected]>
[ Upstream commit eadb85cca111152bd334b861fb53747ab851d13a ]
amdgpu_pmops_suspend_noirq() resets the ASIC unconditionally. When the GPU has been parked by vga_switcheroo it has neither power nor a PCIe link, so the reset cannot reach it: pci_set_power_state() reports the device as inaccessible and amdgpu_asic_reset() returns -EINVAL. A failure there aborts the entire noirq suspend phase, and with it the system suspend, so the machine cannot sleep at all while the GPU is switched off.
amdgpu_device_prepare(), amdgpu_device_suspend() and amdgpu_device_resume() all bail out early on DRM_SWITCH_POWER_OFF. This callback was added later, for an unrelated reason, and did not inherit the check. nouveau guards every one of its PM callbacks the same way.
Bail out the same way here. On a single-GPU system switch_power_state is never DRM_SWITCH_POWER_OFF, so this is a no-op there.
Found on a MacBookPro11,5, where the Radeon is powered down through apple-gmux so that the internal panel can be driven by the iGPU instead. Every suspend failed in amdgpu_pmops_suspend_noirq() while the card was off; with this check a full S3 cycle completes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +8 -0
@@ -2441,6 +2441,14 @@ static int amdgpu_pmops_suspend_noirq(struct device *dev)struct drm_device *drm_dev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (drm_dev); +/* +* A GPU parked by vga_switcheroo has no power and no PCIe link, so the +* ASIC reset below would fail and abort the whole noirq suspend phase. +* Bail out like amdgpu_device_prepare/suspend/resume() already do. +*/ +if (drm_dev->switch_power_state ==DRM_SWITCH_POWER_OFF ) +return 0 ; + adev->suspend_complete = true;if (amdgpu_acpi_should_gpu_reset (adev))return amdgpu_asic_reset (adev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 481/2857 drm/amd/display: guard dc_sink dereferences in MST mode validation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hari Mishal <[email protected]>
[ Upstream commit 217f64f348c90cba62164e7ff38e0ccf78a5ca09 ]
dm_dp_mst_is_port_support_mode() reads aconnector->dc_sink->dsc_caps... for the DSC branch-throughput check, and get_conv_frl_bw()'s HDMI-PCON FRL-bandwidth path reads aconnector->dc_sink->edid_caps.max_frl_rate, both without a NULL check. dc_sink is cleared asynchronously on MST unplug, and both functions run from paths that the driver's own comments document as racing that teardown: the connector probe worker's ->mode_valid callback and a compositor's atomic check, neither of which holds the MST manager lock that the teardown path uses. The former does have an existing dsc_aux NULL check, but dsc_aux isn't reliably cleared in every path that clears dc_sink, so it doesn't cover this.
Fail the port-support check and skip the FRL conversion path when the sink is already gone.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -0
@@ -1671,6 +1671,9 @@ enum dc_status dm_dp_mst_is_port_support_mode( }#endif +if (!aconnector->dc_sink) +return DC_FAIL_BANDWIDTH_VALIDATE ; +/* check is mst dsc output bandwidth branch_overall_throughput_0_mps */ switch (stream->timing.pixel_encoding) {case PIXEL_ENCODING_RGB :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 482/2857 namespace: never expire a locked mount
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit f78ddcc872248c7aa1d7e904928441a0be4c6d5d ]
Locked mounts are special. They protect the underlying files and directories from being revealed. do_umount() refuses to unmount locked mounts but shrink_submounts() doesn't.
A shrinkable mount can become locked once the owner of a user namespace puts it beneath a locked mount with MOVE_MOUNT_BENEATH. The locked property now moves to the mount at the bottom making it possible to unmount the top mount.
So umount() of an unlocked ancestor now expires the bottom mount first and the covered directory is revealed:
move_mount(c -> x/hidden, MOVE_MOUNT_BENEATH) = 0
the cover after the lock moved: umount2(x/hidden) = 0 the holder of the lock: umount2(x/hidden) = EINVAL the root of the copy, busy: umount2(x) = EBUSY
reads x/hidden/secret: "covered-by-root"
So leave a locked mount alone as it dies together with its parent. A plain umount() of an unlocked mount with a locked one below it is EBUSY from now on. It's the same for any other locked child. A lazy umount still takes the whole tree.
mark_mounts_for_expiry() never sees a locked mount. lock_mnt_tree() leaves a mount on an expiry list alone and nothing else puts a locked one on such a list. Add an assert for this.
--- fs/namespace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/namespace.c +4 -1
@@ -3221,6 +3221,8 @@ void mark_mounts_for_expiry(struct list_head *mounts)* cleared by mntput()) */ list_for_each_entry_safe (mnt, next, mounts, mnt_expire) { +/* lock_mnt_tree() leaves expirable mounts alone */ +WARN_ON_ONCE (IS_MNT_LOCKED (mnt));if (!xchg (&mnt->mnt_expiry_mark,1 ) ||propagate_mount_busy (mnt,1 ))continue ;
@@ -3249,7 +3251,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);*/ static bool shrink_submount (struct mount *mnt) { -if (propagate_mount_busy (mnt,1 )) +/* not the kernel's to remove either */ +if (IS_MNT_LOCKED (mnt) ||propagate_mount_busy (mnt,1 ))return false;touch_mnt_namespace (mnt->mnt_ns);umount_tree (mnt,UMOUNT_PROPAGATE |UMOUNT_SYNC );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 465/2857 KVM: SVM: Preserve TLB control (i.e. pending TLB flush) on failed VMRUN
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 60d93c27859fb3ec5b5a689e24de303f166477d0 ]
Don't reset the VMCB's TLB control back to "do nothing" on a failed VMRUN, as empirical testing shows that the CPU performs the requested TLB flush if and only if VMRUN is successful, i.e. clearing TLB control on a failed VMRUN effectively drops a TLB flush.
Explicitly track the need to flush all ASIDs on a per-CPU basis, as the ASID reuse condition is tied to the pCPU, not to the vCPU. As a bonus, this also obviates the need to avoid clobbering FLUSH_ALL_ASID with TLB_CONTROL_FLUSH_ASID, e.g. in svm_flush_tlb_asid().
Deliberately don't bother saving/restoring the "old" tlb_ctl on failure, in quotes because it's not exactly the old tlb_ctl, it's the tlb_ctl from after pre_svm_run(), but before updating tlb_ctl for flush_all_asids. If VMRUN fails and TLB_CONTROL_FLUSH_ALL_ASID is forced, then the next successful run of the VMCB *may* unnecessarily flush all ASIDs, which strictly speaking could result in noisy neighbor issues. However, the fact that new_asid() is already guest-triggerable, because of KVM's flawed behavior of clearing the ASID on emulated INIT, means that a guest can already trigger a flush of all ASIDs at roughly the same rate. And once KVM stops clobbering the ASID on emulated INIT, *or* assigns a static ASID to each vCPU, this flaw goes away.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/svm.c | 14 +++++++++++--- arch/x86/kvm/svm/svm.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-)
arch/x86/kvm/svm/svm.c +11 -3
@@ -1911,8 +1911,7 @@ static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)if (sd->next_asid > sd->max_asid) { ++sd->asid_generation; sd->next_asid = sd->min_asid; - svm->vmcb->control.tlb_ctl =TLB_CONTROL_FLUSH_ALL_ASID ; -vmcb_mark_dirty (svm->vmcb,VMCB_ASID ); + sd->flush_all_asids = true; } svm->current_vmcb->asid_generation = sd->asid_generation;
@@ -4059,6 +4058,11 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags) svm->vmcb->control.asid = svm->asid;vmcb_mark_dirty (svm->vmcb,VMCB_ASID ); } +if (this_cpu_ptr (&svm_data)->flush_all_asids) { + svm->vmcb->control.tlb_ctl =TLB_CONTROL_FLUSH_ALL_ASID ; +vmcb_mark_dirty (svm->vmcb,VMCB_ASID ); + } + svm->vmcb->save.cr2 = vcpu->arch.cr2;svm_hv_update_vp_id (svm->vmcb, vcpu);
@@ -4128,7 +4132,11 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags) svm->nested.nested_run_pending =0 ; } - svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ; +if (svm->vmcb->control.exit_code !=SVM_EXIT_ERR ) { +this_cpu_ptr (&svm_data)->flush_all_asids = false; + svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ; + } +vmcb_mark_all_clean (svm->vmcb);/* if exit due to PF check for async PF */
arch/x86/kvm/svm/svm.h +1 -0
@@ -293,6 +293,7 @@ struct svm_cpu_data {u32 min_asid;struct kvm_ldttss_desc *tss_desc; +bool flush_all_asids;struct page *save_area;unsigned long save_area_pa;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 483/2857 regulator: of: fill in supply names in of_regulator_bulk_get_all()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
[ Upstream commit e2151c29cec73f6cc70abf1c7cbc7b9b202489f5 ]
of_regulator_bulk_get_all() returns an array it allocated itself, and fills in only the consumer of each entry. Every other way of getting a bulk array has the supply name set, because the caller provides it, and the core expects it to be there: regulator_bulk_enable() prints it when a supply fails to enable, so a caller that hands such an array to it dereferences uninitialised memory on that path.
Copy each name into the array's own allocation, right behind the entries, so that it shares the array's lifetime and callers still have nothing extra to free. That also retires the fixed 64 byte stack buffer the names were assembled in, which is_supply_name() never bounded the copy against.
--- drivers/regulator/of_regulator.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/regulator/of_regulator.c +18 -9
@@ -755,16 +755,16 @@ static int is_supply_name(const char *name)int of_regulator_bulk_get_all (struct device *dev,struct device_node *np,struct regulator_bulk_data **consumers) { -int num_consumers =0 ; +int num_consumers =0 , names_len =0 ;struct regulator *tmp;struct property *prop; +char *names;int i, n =0 , ret; -char name[64 ]; *consumers =NULL ;/* -* first pass: get numbers of xxx-supply +* first pass: get numbers of xxx-supply and the room their names take * second pass: fill consumers */ restart:
@@ -774,16 +774,19 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,continue ;if (!*consumers) { num_consumers++; + names_len += i +1 ;continue ; }else { -memcpy (name, prop->name, i); - name[i] ='\0' ; - tmp =regulator_get (dev, name); +memcpy (names, prop->name, i); + names[i] ='\0' ; + tmp =regulator_get (dev, names);if (IS_ERR (tmp)) { ret =PTR_ERR (tmp); goto error; } + (*consumers)[n].supply = names; (*consumers)[n].consumer = tmp; + names += i +1 ; n++;continue ; }
@@ -792,11 +795,17 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,return num_consumers;if (num_consumers ==0 )return 0 ; - *consumers =kmalloc_array (num_consumers, -sizeof (struct regulator_bulk_data ), -GFP_KERNEL ); +/* +* The supply names are kept in the same allocation as the array, so +* that they share its lifetime and the caller has nothing extra to +* free. +*/ + *consumers =kzalloc (size_add (size_mul (num_consumers, +sizeof (struct regulator_bulk_data )), + names_len),GFP_KERNEL );if (!*consumers)return -ENOMEM ; + names = (char *)(*consumers + num_consumers); goto restart; error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 484/2857 net: team: free skb when broadcast has no txable port
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 489114c9ecae44e523361a4b3e610ee5ebd9189c ]
bc_transmit() sends the original skb through the last txable port. When no port is txable, it returns false without consuming the skb, but team_xmit() still returns NETDEV_TX_OK. AF_PACKET sends then retain the skb and its socket write-memory charge.
A TX-enabled, link-down port keeps the broadcast transmit op installed. Carrier can stay up through a second link-up, TX-disabled port or be forced on by userspace. Free the original skb on the no-port path while leaving the existing drop accounting intact.
Discovered by Sashiko during review of previous commit.
--- drivers/net/team/team_mode_broadcast.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/team/team_mode_broadcast.c +2 -0
@@ -38,6 +38,8 @@ static bool bc_transmit(struct team *team, struct sk_buff *skb) ret = !team_dev_queue_xmit (team, last, skb);if (!sum_ret) sum_ret = ret; + }else { +dev_kfree_skb_any (skb); }return sum_ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 485/2857 drm/amd/display: Fix direct scanout alpha on some DRM_FORMATs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Li <[email protected]>
[ Upstream commit 7744262f5d63f9faa4d59dec127ae1c8b2d56495 ]
[Why]
DM was declaring it's own list of has_alpha DRM formats to check against for enabling alpha blending, when the format->has_alpha already does that for us.
The self-declared list missed some has_alpha formats, causing direct-scanout planes with such formats to appear opaque.
[How]
Drop the self-declared list, instead use the format->has_alpha field directly.
--- .../drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +1 -14
@@ -101,20 +101,7 @@ void fill_blending_from_plane_state(const struct drm_plane_state *plane_state,if (plane_state->pixel_blend_mode ==DRM_MODE_BLEND_PREMULTI || plane_state->pixel_blend_mode ==DRM_MODE_BLEND_COVERAGE ) { -static const uint32_t alpha_formats[] = { -DRM_FORMAT_ARGB8888 , -DRM_FORMAT_RGBA8888 , -DRM_FORMAT_ABGR8888 , - }; -uint32_t format = plane_state->fb->format->format; -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (alpha_formats); ++i) { -if (format == alpha_formats[i]) { - *per_pixel_alpha = true; -break ; - } - } + *per_pixel_alpha = plane_state->fb->format->has_alpha;if (*per_pixel_alpha && plane_state->pixel_blend_mode ==DRM_MODE_BLEND_COVERAGE ) *pre_multiplied_alpha = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 486/2857 drm/amdgpu: serialize vblank counter reads against GPU reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vitaly Prosyak <[email protected]>
[ Upstream commit 1a6023edfbb5673f55fab6348f135fb3b1428ea5 ]
The vblank counter callback reads display registers and scanout position without holding reset_domain->sem. During GPU recovery, display commit work can call the callback while reset owns the semaphore for writing. The hardware access then triggers the lockdep_assert_held() in amdgpu_device_skip_hw_access() and sets TAINT_WARN when lockdep is enabled.
Try to acquire the reset semaphore for reading before accessing the hardware, and hold it across the counter and scanout-position reads. If reset is already in progress, return DRM's cached software vblank count instead. This avoids blocking behind reset and avoids accessing display hardware while it is being reset.
The cached count is less accurate than the hardware count, but is used only when reset prevents a safe hardware read. This addresses the reset-time warning from this vblank path; it does not suppress or fix unrelated lockdep warnings.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
@@ -29,6 +29,7 @@#include "amdgpu.h" #include <drm/amdgpu_drm.h> #include <drm/drm_drv.h> +#include <drm/drm_vblank.h> #include "amdgpu_uvd.h" #include "amdgpu_vce.h" #include "atom.h"
@@ -42,6 +43,7 @@#include "amdgpu_gem.h" #include "amdgpu_display.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" void amdgpu_unregister_gpu_instance (struct amdgpu_device *adev) {
@@ -1315,6 +1317,9 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)DRM_ERROR ("Invalid crtc %u\n" , pipe);return -EINVAL ; } +if (!down_read_trylock (&adev->reset_domain->sem)) +return drm_crtc_vblank_count (crtc); +/* The hw increments its frame counter at start of vsync, not at start * of vblank, as is required by DRM core vblank counter handling.
@@ -1360,6 +1365,7 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)DRM_DEBUG_VBL ("NULL mode info! Returned count may be wrong.\n" ); } +up_read (&adev->reset_domain->sem);return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 487/2857 Input: xpad - add support for Corsair Novablade Pro
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Furman <[email protected]>
[ Upstream commit f9282b8aa85a8c97c50d656db75feb6d76fc7cbe ]
Add device IDs for the Corsair Novablade Pro leverless fight controller in both wired (0x2b1f) and 2.4 GHz receiver (0x2b2b) modes, and add Corsair's vendor ID to the Xbox 360 vendor match list.
Outside of its PS4/PS5 modes the controller uses the Xbox 360 protocol (vendor-specific class, subclass 93, protocol 1) on interface 0, which xpad does not currently bind, so no gamepad device is created. The PS4/PS5 modes present a standard HID gamepad and already work with hid-generic.
Tested on 7.2.5 with the 2.4 GHz receiver and wired.
--- drivers/input/joystick/xpad.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/input/joystick/xpad.c +3 -0
@@ -307,6 +307,8 @@ static const struct xpad_device { { 0x16d0, 0x13ea, "Azeron Keyzen", 0, XTYPE_XBOX360 }, { 0x17ef, 0x6182, "Lenovo Legion Controller for Windows", 0, XTYPE_XBOX360 }, { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 }, + { 0x1b1c, 0x2b1f, "Corsair Novablade Pro (Wired)", 0, XTYPE_XBOX360 }, + { 0x1b1c, 0x2b2b, "Corsair Novablade Pro (2.4 GHz Receiver)", 0, XTYPE_XBOX360 }, { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 }, { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, { 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
@@ -506,6 +508,7 @@ static const struct usb_device_id xpad_table[] = {XPAD_XBOX360_VENDOR (0x16d0 ),/* Azeron controllers */ XPAD_XBOX360_VENDOR (0x17ef ),/* Lenovo */ XPAD_XBOX360_VENDOR (0x1949 ),/* Amazon controllers */ +XPAD_XBOX360_VENDOR (0x1b1c ),/* Corsair controllers */ XPAD_XBOX360_VENDOR (0x1bad ),/* Harminix Rock Band Guitar and Drums */ XPAD_XBOX360_VENDOR (0x20d6 ),/* PowerA Controllers */ XPAD_XBOXONE_VENDOR(0x20d6), /* PowerA Controllers */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 488/2857 x86/kvm: Use separate percpu variable to track the enabling of asyncpf
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiaoyao Li <[email protected]>
[ Upstream commit ccb2280ec2f9e805d70f57a3a1c5deff0d532cb3 ]
Refer to commit fd10cde9294f ("KVM paravirt: Add async PF initialization to PV guest") and commit 344d9588a9df ("KVM: Add PV MSR to enable asynchronous page faults delivery"). It turns out that at the time when asyncpf was introduced, the purpose was defining the shared PV data 'struct kvm_vcpu_pv_apf_data' with the size of 64 bytes. However, it made a mistake and defined the size to 68 bytes, which failed to make fit in a cache line and made the code inconsistent with the documentation.
Below justification quoted from Sean[*]
KVM (the host side) has *never* read kvm_vcpu_pv_apf_data.enabled, and the documentation clearly states that enabling is based solely on the bit in the synthetic MSR.
So rather than update the documentation, fix the goof by removing the enabled filed and use the separate percpu variable instread. KVM-as-a-host obviously doesn't enforce anything or consume the size, and changing the header will only affect guests that are rebuilt against the new header, so there's no chance of ABI breakage between KVM and its guests. The only possible breakage is if some other hypervisor is emulating KVM's async #PF (LOL) and relies on the guest to set kvm_vcpu_pv_apf_data.enabled. But (a) I highly doubt such a hypervisor exists, (b) that would arguably be a violation of KVM's "spec", and
(c) the worst case scenario is that the guest would simply lose async #PF functionality.
[*] https://lore.kernel.org/all/[email protected]/T/#u
Stable-dep-of: 81d99abe2bd8 ("x86/kvm: Don't consume async #PF flags on a kernel #PF in NMI context")
--- Documentation/virt/kvm/x86/msr.rst | 1 - arch/x86/include/uapi/asm/kvm_para.h | 1 - arch/x86/kernel/kvm.c | 11 ++++++----- 3 files changed, 6 insertions(+), 7 deletions(-)
Documentation/virt/kvm/x86/msr.rst +0 -1
@@ -204,7 +204,6 @@ data: __u32 token; __u8 pad[56]; - __u32 enabled; }; Bits 5-4 of the MSR are reserved and should be zero. Bit 0 is set to 1
arch/x86/include/uapi/asm/kvm_para.h +0 -1
@@ -142,7 +142,6 @@ struct kvm_vcpu_pv_apf_data {__u32 token;__u8 pad[56 ]; -__u32 enabled; };#define KVM_PV_EOI_BIT 0
arch/x86/kernel/kvm.c +6 -5
@@ -65,6 +65,7 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +static DEFINE_PER_CPU_READ_MOSTLY(bool, async_pf_enabled); static DEFINE_PER_CPU_DECRYPTED(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64); DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64) __visible; static int has_steal_clock = 0;
@@ -244,7 +245,7 @@ noinstr u32 kvm_read_and_reset_apf_flags(void) {u32 flags =0 ; -if (__this_cpu_read (apf_reason.enabled)) { +if (__this_cpu_read (async_pf_enabled)) { flags =__this_cpu_read (apf_reason.flags);__this_cpu_write (apf_reason.flags,0 ); }
@@ -295,7 +296,7 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_kvm_asyncpf_interrupt)inc_irq_stat (irq_hv_callback_count); -if (__this_cpu_read (apf_reason.enabled)) { +if (__this_cpu_read (async_pf_enabled)) { token =__this_cpu_read (apf_reason.token);kvm_async_pf_task_wake (token);__this_cpu_write (apf_reason.token,0 );
@@ -362,7 +363,7 @@ static void kvm_guest_cpu_init(void)wrmsrl (MSR_KVM_ASYNC_PF_INT ,HYPERVISOR_CALLBACK_VECTOR );wrmsrl (MSR_KVM_ASYNC_PF_EN , pa); -__this_cpu_write (apf_reason.enabled,1 ); +__this_cpu_write (async_pf_enabled, true);pr_debug ("setup async PF for cpu %d\n" ,smp_processor_id ()); }
@@ -383,11 +384,11 @@ static void kvm_guest_cpu_init(void)static void kvm_pv_disable_apf (void ) { -if (!__this_cpu_read (apf_reason.enabled)) +if (!__this_cpu_read (async_pf_enabled))return ;wrmsrl (MSR_KVM_ASYNC_PF_EN ,0 ); -__this_cpu_write (apf_reason.enabled,0 ); +__this_cpu_write (async_pf_enabled, false);pr_debug ("disable async PF for cpu %d\n" ,smp_processor_id ()); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 489/2857 x86/kvm: Dont consume async #PF flags on a kernel #PF in NMI context
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: EJ Campbell <[email protected]>
[ Upstream commit 81d99abe2bd81379abfb595e403bbbee6fbfc624 ]
An async #PF "page not present" event arrives through the #PF vector, and its reason sits in the per-CPU apf_reason.flags until __kvm_handle_async_pf() reads and clears it. If an NMI arrives after the event is injected and before the #PF handler reads the flags, and the NMI handler itself takes a #PF, that fault reads and clears the flags belonging to the #PF it interrupted. It then finds interrupts disabled in the NMI context it interrupted, and panics:
Kernel panic - not syncing: Host injected async #PF in interrupt disabled region Call Trace: <NMI> panic+0x52/0x60 __kvm_handle_async_pf+0xb0/0xb0 exc_page_fault+0x71/0xb0 asm_exc_page_fault+0x27/0x30 RIP: 0010:__get_user_nocheck_8+0x6/0x20 perf_callchain_user+0x147/0x1a0 get_perf_callchain+0x12d/0x1c0 ... perf_event_nmi_handler+0x26/0x50 exc_nmi+0xe8/0x110 RIP: 0010:asm_exc_page_fault+0x0/0x30 </NMI>
The last RIP line shows the NMI landing on the first instruction of the #PF entry. perf with user call chains takes such a fault: the sampling NMI walks the user stack with __get_user(), which faults when a saved frame pointer is not a valid user address or the walk runs off the top of the stack. The same window exists when KVM, running as an L1 hypervisor with DELIVERY_AS_PF_VMEXIT, reads the flags itself after a #PF VM-exit.
The NMI entry code saves and restores CR2 for this nesting, but not the async #PF reason. Andy Lutomirski described the race, with perf as the example, when async #PF delivery was reworked in 2020 [1]. Saving and clearing the flags across the NMI, next to CR2, was discussed there but not merged.
Since that rework, Linux has stopped setting KVM_ASYNC_PF_SEND_ALWAYS, so the host delivers "page not present" only for user mode faults and a kernel-mode fault in NMI context (including kernel-mode #MC and #DB) cannot be an async page fault. In that case, return without touching the flags so that the interrupted handler finds them intact.
Tested on v7.3-rc5 in a 4-vCPU, 2 GiB guest restored from a snapshot whose memory is served on demand through userfaultfd, so that reading it back takes async #PFs, while every thread samples hardware cycles with user call chains and points its frame pointer at an unmapped page. Without this patch the guest panicked as above in 3 of 3 runs. With it, the guest survived 3 of 3 runs of 60 seconds, and the host counted 148,441 to 153,334 kvm_async_pf_not_present events in the first 20 seconds of each. On 6.18.50 the results were the same: the guest panicked without the patch and survived with it.
--- arch/x86/kernel/kvm.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)
arch/x86/kernel/kvm.c +29 -3
@@ -254,11 +254,39 @@ noinstr u32 kvm_read_and_reset_apf_flags(void) }EXPORT_SYMBOL_GPL (kvm_read_and_reset_apf_flags); +static __always_inline bool kvm_apf_reason_pending(void) +{ +return __this_cpu_read (async_pf_enabled) && +__this_cpu_read (apf_reason.flags); +} + noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token) { -u32 flags =kvm_read_and_reset_apf_flags ();irqentry_state_t state; +u32 flags; + +if (!kvm_apf_reason_pending ()) +return false; + +/* +* The guest does not enable KVM_ASYNC_PF_SEND_ALWAYS, so the host +* delivers async #PF only to user mode (or as a #PF VM-exit, which KVM +* reads itself). A #PF from kernel mode can still arrive between that +* delivery and the read of the reason flags, inside an NMI that +* interrupted it, for instance perf reading user memory for a call +* chain. Such a fault is not async, so leave the async PF flags +* untouched for the outer handler. Outside NMI context, on the other +* hand, async PF flags on a kernel-mode fault mean the host is broken. +*/ +if (!user_mode (regs)) { +if (likely (in_nmi ())) +return false; + state =irqentry_enter (regs); +instrumentation_begin (); +panic ("Host injected async #PF in kernel mode\n" ); + } + flags =kvm_read_and_reset_apf_flags ();if (!flags)return false;
@@ -274,8 +302,6 @@ noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token)panic ("Host injected async #PF in interrupt disabled region\n" );if (flags &KVM_PV_REASON_PAGE_NOT_PRESENT ) { -if (unlikely (!(user_mode (regs)))) -panic ("Host injected async #PF in kernel mode\n" );/* Page is swapped out by the host. */ kvm_async_pf_task_wait_schedule (token); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 490/2857 drm/i915/dmc: Add sanity check for DMC load address
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dibin Moolakadan Subrahmanian <[email protected]>
[ Upstream commit 7dedc5bb11f95e96fe80757c924d8d9aa7327759 ]
For DMC firmware header version 3, the firmware load address is stored in dmc_info->start_mmioaddr and later used by dmc_load_program().
Unlike the MMIO address table, the firmware load address is not validated. Add a sanity check to ensure it is within the valid range.
BSpec: 69671, 68378
--- drivers/gpu/drm/i915/display/intel_dmc.c | 55 +++++++++++++++++++ drivers/gpu/drm/i915/display/intel_dmc_regs.h | 12 ++++ 2 files changed, 67 insertions(+)
drivers/gpu/drm/i915/display/intel_dmc.c +55 -0
@@ -543,6 +543,55 @@ static void dmc_set_fw_offset(struct intel_dmc *dmc, } } +/* +* Check if the load address is within the valid range for the given DMC ID. +*/ +static bool dmc_load_addr_sanity_check (struct intel_dmc *dmc, +u32 start_addr,u32 payload_size, +int header_ver,u8 dmc_id) +{ +u32 start_range, end_range, end_addr; + +if (header_ver !=3 ) +return true; + +switch (dmc_id) { +case DMC_FW_MAIN : + start_range =DMC_MAIN_PROGRAM_BASE_START ; + end_range =DMC_MAIN_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPEA : + start_range =DMC_PIPEA_PROGRAM_BASE_START ; + end_range =DMC_PIPEA_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPEB : + start_range =DMC_PIPEB_PROGRAM_BASE_START ; + end_range =DMC_PIPEB_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPEC : + start_range =DMC_PIPEC_PROGRAM_BASE_START ; + end_range =DMC_PIPEC_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPED : + start_range =DMC_PIPED_PROGRAM_BASE_START ; + end_range =DMC_PIPED_PROGRAM_BASE_END ; +break ; +default : +MISSING_CASE (dmc_id); +return false; + } + +if (payload_size ==0 ) + end_addr = start_addr; +else if (check_add_overflow (start_addr, payload_size -1 , &end_addr)) +return false; + +if (start_addr < start_range || end_addr > end_range) +return false; + +return true; +} +static bool dmc_mmio_addr_sanity_check (struct intel_dmc *dmc,const u32 *mmioaddr,u32 mmio_count,int header_ver,u8 dmc_id)
@@ -683,6 +732,12 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc,return 0 ; } +if (!dmc_load_addr_sanity_check (dmc, start_mmioaddr, payload_size, + dmc_header->header_ver, dmc_id)) { +drm_err (&i915->drm,"DMC %d: firmware has wrong load address\n" , dmc_id); +return 0 ; + } + dmc_info->payload =kmalloc (payload_size,GFP_KERNEL );if (!dmc_info->payload)return 0 ;
drivers/gpu/drm/i915/display/intel_dmc_regs.h +12 -0
@@ -76,6 +76,18 @@#define TGL_PIPE_MMIO_END (dmc_id) _PICK_EVEN(((dmc_id) - 1), _TGL_PIPEA_MMIO_END,\ _TGL_PIPEB_MMIO_END) +/* For DMC header version v3*/ +#define DMC_MAIN_PROGRAM_BASE_START 0x80000 +#define DMC_MAIN_PROGRAM_BASE_END 0x86fff +#define DMC_PIPEA_PROGRAM_BASE_START 0x90000 +#define DMC_PIPEA_PROGRAM_BASE_END 0x96fff +#define DMC_PIPEB_PROGRAM_BASE_START 0x98000 +#define DMC_PIPEB_PROGRAM_BASE_END 0x9efff +#define DMC_PIPEC_PROGRAM_BASE_START 0x52000 +#define DMC_PIPEC_PROGRAM_BASE_END 0x53fff +#define DMC_PIPED_PROGRAM_BASE_START 0x59000 +#define DMC_PIPED_PROGRAM_BASE_END 0x5afff +#define SKL_DMC_DC3_DC5_COUNT _MMIO(0x80030)#define SKL_DMC_DC5_DC6_COUNT _MMIO(0x8002C)#define BXT_DMC_DC3_DC5_COUNT _MMIO(0x80038)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 491/2857 ipc: create_ipc_ns: drop mqueue mount on sysctl setup failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Kulikov <[email protected]>
[ Upstream commit 7229d74e5e8c1f140529d405c88d4493e37ce4e3 ]
If setup_mq_sysctls(ns) fails after mq_init_ns(ns) succeeds, the error path skipped releasing the internal kernel mqueue mount kept in ns->mq_mnt. That leaves the vfsmount/superblock referenced until final namespace teardown, i.e. a resource leak on this rare failure edge.
Unwind it by calling mntput(ns->mq_mnt) before dropping user_ns and freeing the IPC namespace. This mirrors the normal ordering used in free_ipc_ns().
Stable-dep-of: f0e48172a59e ("ipc: drop the mqueue mount with kern_unmount() on setup failure")
--- ipc/namespace.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
ipc/namespace.c +5 -4
@@ -61,10 +61,10 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, err = -ENOMEM ;if (!setup_mq_sysctls (ns)) - goto fail_put; + goto fail_mq_mount;if (!setup_ipc_sysctls (ns)) - goto fail_mq; + goto fail_mq_sysctls; err =msg_init_ns (ns);if (err)
@@ -77,9 +77,10 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, fail_ipc:retire_ipc_sysctls (ns); -fail_mq: +fail_mq_sysctls:retire_mq_sysctls (ns); - +fail_mq_mount: +mntput (ns->mq_mnt); fail_put:put_user_ns (ns->user_ns);ns_free_inum (&ns->ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 492/2857 ipc: drop the mqueue mount with kern_unmount() on setup failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit f0e48172a59e517e613b73f73cc35f24fd123aeb ]
mq_init_ns() creates the mqueue mount with fc_mount_longterm(), so its ->mnt_ns is MNT_NS_INTERNAL. When setting up the mqueue or ipc sysctls or msg_init_ns() fails afterwards, create_ipc_ns() drops it with a plain mntput(). With ->mnt_ns set that takes the fast path of mntput_no_expire(). The count drops to zero and nothing ever kills the mount, so the mount and the mqueue superblock are leaked.
Commit dc55e35f9e81 ("ipc: Store mqueue sysctls in the ipc namespace") added the first failure path after mq_init_ns() and never dropped the mount. Commit 7229d74e5e8c ("ipc: create_ipc_ns: drop mqueue mount on sysctl setup failure") tried to fix that with a mntput() but that doesn't help for a long-term mount.
Use kern_unmount(). free_ipc() open-codes the same thing for a namespace that made it.
--- ipc/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ipc/namespace.c +1 -1
@@ -80,7 +80,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, fail_mq_sysctls:retire_mq_sysctls (ns); fail_mq_mount: -mntput (ns->mq_mnt); +kern_unmount (ns->mq_mnt); fail_put:put_user_ns (ns->user_ns);ns_free_inum (&ns->ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 466/2857 KVM: SVM: Update control fields on #VMEXIT if and only if VMRUN succeeded
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit e27fc915c8f575ab5630e27d97465c2077d4b9d1 ]
Leave control.erap_ctl and control.clean as-is in the VMCS if VMRUN fails, because as per AMD:
there's no explicit architectural guarantee about the behavior in the presence of VMRUN failures. So the best thing to do would be to assume that if VMRUN fails, the actions requested in the control fields may not have been performed.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +2 -2
@@ -4135,9 +4135,9 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)if (svm->vmcb->control.exit_code !=SVM_EXIT_ERR ) {this_cpu_ptr (&svm_data)->flush_all_asids = false; svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ; - } -vmcb_mark_all_clean (svm->vmcb); +vmcb_mark_all_clean (svm->vmcb); + }/* if exit due to PF check for async PF */ if (svm->vmcb->control.exit_code ==SVM_EXIT_EXCP_BASE +PF_VECTOR )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 493/2857 tracing: Fix fully-qualified variable reference printing in histograms
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Zanussi <[email protected]>
[ Upstream commit 9236eebd138aa2753f7b30fc6cee7b7202841247 ]
The syntax for fully-qualified variable references in histograms is subsys.event.$var, which is parsed correctly, but not displayed correctly when printing a histogram spec. The current code puts the $ reference at the beginning of the fully-qualified variable name i.e. $subsys.event.var, which is incorrect.
Before:
trigger info: hist:keys=next_comm:vals=hitcount:wakeup_lat=common_timestamp.usecs-$sched.sched_wakeup.ts0: ...
After:
trigger info: hist:keys=next_comm:vals=hitcount:wakeup_lat=common_timestamp.usecs-sched.sched_wakeup.$ts0: ...
Stable-dep-of: a0777b9e5315 ("tracing: Fix NULL dereference when copying keys for a field variable")
--- kernel/trace/trace_events_hist.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
kernel/trace/trace_events_hist.c +10 -5
@@ -1339,9 +1339,12 @@ static const char *hist_field_name(struct hist_field *field, field->flags & HIST_FIELD_FL_VAR_REF) {if (field->system) {static char full_name[MAX_FILTER_STR_VAL ]; +static char *fmt;int len; - len =snprintf (full_name,sizeof (full_name),"%s.%s.%s" , + fmt = field->flags &HIST_FIELD_FL_VAR_REF ?"%s.%s.$%s" :"%s.%s.%s" ; + + len =snprintf (full_name,sizeof (full_name), fmt, field->system, field->event_name, field->name);if (len <sizeof (full_name))
@@ -1709,9 +1712,10 @@ static const char *get_hist_field_flags(struct hist_field *hist_field)static void expr_field_str (struct hist_field *field,char *expr) { -if (field->flags &HIST_FIELD_FL_VAR_REF ) -strcat (expr,"$" ); -else if (field->flags &HIST_FIELD_FL_CONST ) { +if (field->flags &HIST_FIELD_FL_VAR_REF ) { +if (!field->system) +strcat (expr,"$" ); + }else if (field->flags &HIST_FIELD_FL_CONST ) {char str[HIST_CONST_DIGITS_MAX ];snprintf (str,HIST_CONST_DIGITS_MAX ,"%llu" , field->constant);
@@ -5845,7 +5849,8 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)else if (field_name) {if (hist_field->flags &HIST_FIELD_FL_VAR_REF || hist_field->flags &HIST_FIELD_FL_ALIAS ) -seq_putc (m,'$' ); +if (!hist_field->system) +seq_putc (m,'$' );seq_printf (m,"%s" , field_name); }else if (hist_field->flags &HIST_FIELD_FL_TIMESTAMP )seq_puts (m,"common_timestamp" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 494/2857 tracing: Use __free() for expr_str() buffer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 988995c0552b6213b6bf16cea57258d4842c1488 ]
expr_str() allocates a temporary expression buffer and manually frees it on some error paths.
Convert the buffer to __free(kfree) and return it with return_ptr() on success. This keeps ownership handling separate from the later ERR_PTR() conversion and string-bound change.
Stable-dep-of: a0777b9e5315 ("tracing: Fix NULL dereference when copying keys for a field variable")
--- kernel/trace/trace_events_hist.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
kernel/trace/trace_events_hist.c +6 -8
@@ -1736,7 +1736,7 @@ static void expr_field_str(struct hist_field *field, char *expr)static char *expr_str (struct hist_field *field,unsigned int level) { -char *expr; + char *expr __free(kfree) = NULL;if (level >1 )return NULL ;
@@ -1747,7 +1747,7 @@ static char *expr_str(struct hist_field *field, unsigned int level)if (!field->operands[0 ]) {expr_field_str (field, expr); -return expr; +return_ptr (expr); }if (field->operator ==FIELD_OP_UNARY_MINUS ) {
@@ -1755,16 +1755,15 @@ static char *expr_str(struct hist_field *field, unsigned int level)strcat (expr,"-(" ); subexpr =expr_str (field->operands[0 ], ++level); -if (!subexpr) { -kfree (expr); +if (!subexpr)return NULL ; - } +strcat (expr, subexpr);strcat (expr,")" );kfree (subexpr); -return expr; +return_ptr (expr); }expr_field_str (field->operands[0 ], expr);
@@ -1783,13 +1782,12 @@ static char *expr_str(struct hist_field *field, unsigned int level)strcat (expr,"*" );break ;default : -kfree (expr);return NULL ; }expr_field_str (field->operands[1 ], expr); -return expr; +return_ptr (expr); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 495/2857 tracing: Return ERR_PTR() from expr_str()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit a5ca27e8ff1c10e949af7cfe474d6d1a08fb5601 ]
expr_str() currently reports all failure cases as NULL, so callers cannot distinguish invalid recursion depth from allocation failure or later string construction errors.
Return ERR_PTR()-encoded errors from expr_str() and make parse_unary() and parse_expr() propagate them. Clear expr->name before destroying the hist field so the error pointer is not freed as a string.
Stable-dep-of: 935601a4276f ("tracing: Bound histogram expression strings with seq_buf")
--- kernel/trace/trace_events_hist.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
kernel/trace/trace_events_hist.c +20 -5
@@ -1739,11 +1739,11 @@ static char *expr_str(struct hist_field *field, unsigned int level) char *expr __free(kfree) = NULL;if (level >1 ) -return NULL ; +return ERR_PTR (-EINVAL ); expr =kzalloc (MAX_FILTER_STR_VAL ,GFP_KERNEL );if (!expr) -return NULL ; +return ERR_PTR (-ENOMEM );if (!field->operands[0 ]) {expr_field_str (field, expr);
@@ -1755,8 +1755,8 @@ static char *expr_str(struct hist_field *field, unsigned int level)strcat (expr,"-(" ); subexpr =expr_str (field->operands[0 ], ++level); -if (!subexpr) -return NULL ; +if (IS_ERR (subexpr)) +return subexpr;strcat (expr, subexpr);strcat (expr,")" );
@@ -1782,7 +1782,7 @@ static char *expr_str(struct hist_field *field, unsigned int level)strcat (expr,"*" );break ;default : -return NULL ; +return ERR_PTR (-EINVAL ); }expr_field_str (field->operands[1 ], expr);
@@ -2553,6 +2553,11 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data, expr->is_signed = operand1->is_signed; expr->operator =FIELD_OP_UNARY_MINUS ; expr->name =expr_str (expr,0 ); +if (IS_ERR (expr->name)) { + ret =PTR_ERR (expr->name); + expr->name =NULL ; + goto free; + } expr->type =kstrdup_const (operand1->type,GFP_KERNEL );if (!expr->type) { ret = -ENOMEM ;
@@ -2765,6 +2770,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,destroy_hist_field (operand1,0 ); expr->name =expr_str (expr,0 ); +if (IS_ERR (expr->name)) { + ret =PTR_ERR (expr->name); + expr->name =NULL ; + goto free_expr; + } }else {/* The operand sizes should be the same, so just pick one */ expr->size = operand1->size;
@@ -2778,6 +2788,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data, } expr->name =expr_str (expr,0 ); +if (IS_ERR (expr->name)) { + ret =PTR_ERR (expr->name); + expr->name =NULL ; + goto free_expr; + } }return expr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 496/2857 tracing: Bound histogram expression strings with seq_buf
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 935601a4276f28105498609f7f98aa66e86e9c96 ]
expr_str() allocates a fixed MAX_FILTER_STR_VAL buffer and then builds expression names with a series of raw strcat() appends. Nested operands, constants, field flags, and generated field names can push the rendered string past that fixed limit before the name is attached to the hist field.
Build expression strings with seq_buf and return -E2BIG when the rendered name would exceed MAX_FILTER_STR_VAL. This keeps the existing tracing-side limit while replacing the raw append logic with bounded construction.
Stable-dep-of: a0777b9e5315 ("tracing: Fix NULL dereference when copying keys for a field variable")
--- kernel/trace/trace_events_hist.c | 57 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 24 deletions(-)
kernel/trace/trace_events_hist.c +33 -24
@@ -93,7 +93,6 @@ typedef u64 (*hist_field_fn_t) (struct hist_field *field,#define HIST_FIELD_OPERANDS_MAX 2#define HIST_FIELDS_MAX (TRACING_MAP_FIELDS_MAX + TRACING_MAP_VARS_MAX)#define HIST_ACTIONS_MAX 8 -#define HIST_CONST_DIGITS_MAX 21#define HIST_DIV_SHIFT 20/* For optimizing division by constants */ enum field_op_id {
@@ -1710,33 +1709,36 @@ static const char *get_hist_field_flags(struct hist_field *hist_field)return flags_str; } -static void expr_field_str (struct hist_field *field,char *expr) +static bool expr_field_str (struct hist_field *field,struct seq_buf *s) { +const char *field_name; +if (field->flags &HIST_FIELD_FL_VAR_REF ) {if (!field->system) -strcat (expr,"$" ); - }else if (field->flags &HIST_FIELD_FL_CONST ) { -char str[HIST_CONST_DIGITS_MAX ]; +seq_buf_putc (s,'$' ); + }else if (field->flags &HIST_FIELD_FL_CONST ) +seq_buf_printf (s,"%llu" , field->constant); -snprintf (str,HIST_CONST_DIGITS_MAX ,"%llu" , field->constant); -strcat (expr, str); - } + field_name =hist_field_name (field,0 ); +if (!field_name) +return false; -strcat (expr,hist_field_name (field,0 )); +seq_buf_puts (s, field_name);if (field->flags && !(field->flags &HIST_FIELD_FL_VAR_REF )) {const char *flags_str =get_hist_field_flags (field); -if (flags_str) { -strcat (expr,"." ); -strcat (expr, flags_str); - } +if (flags_str) +seq_buf_printf (s,".%s" , flags_str); } + +return !seq_buf_has_overflowed (s); }static char *expr_str (struct hist_field *field,unsigned int level) { char *expr __free(kfree) = NULL; +struct seq_buf s;if (level >1 )return ERR_PTR (-EINVAL );
@@ -1745,47 +1747,54 @@ static char *expr_str(struct hist_field *field, unsigned int level)if (!expr)return ERR_PTR (-ENOMEM ); +seq_buf_init (&s, expr,MAX_FILTER_STR_VAL ); +if (!field->operands[0 ]) { -expr_field_str (field, expr); +if (!expr_field_str (field, &s)) +return ERR_PTR (-E2BIG ); +return_ptr (expr); }if (field->operator ==FIELD_OP_UNARY_MINUS ) {char *subexpr; -strcat (expr,"-(" ); subexpr =expr_str (field->operands[0 ], ++level);if (IS_ERR (subexpr))return subexpr; -strcat (expr, subexpr); -strcat (expr,")" ); - +seq_buf_printf (&s,"-(%s)" , subexpr);kfree (subexpr); +if (seq_buf_has_overflowed (&s)) +return ERR_PTR (-E2BIG ); +return_ptr (expr); } -expr_field_str (field->operands[0 ], expr); +if (!expr_field_str (field->operands[0 ], &s)) +return ERR_PTR (-E2BIG );switch (field->operator) {case FIELD_OP_MINUS : -strcat (expr,"-" ); +seq_buf_putc (&s,'-' );break ;case FIELD_OP_PLUS : -strcat (expr,"+" ); +seq_buf_putc (&s,'+' );break ;case FIELD_OP_DIV : -strcat (expr,"/" ); +seq_buf_putc (&s,'/' );break ;case FIELD_OP_MULT : -strcat (expr,"*" ); +seq_buf_putc (&s,'*' );break ;default :return ERR_PTR (-EINVAL ); } -expr_field_str (field->operands[1 ], expr); +if (seq_buf_has_overflowed (&s) || + !expr_field_str (field->operands[1 ], &s)) +return ERR_PTR (-E2BIG );return_ptr (expr); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 497/2857 tracing: Fix NULL dereference when copying keys for a field variable
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit a0777b9e53157f1f6848a0fd0650f5465391ea81 ]
In event_hist_trigger_parse() where it needs to create actions like "onmatch", it calls:
event_hist_trigger_parse() {
create_actions() {
action_create() {
trace_action_create() {
trace_action_create_field_var() {
create_field_var_hist()Where create_field_var_hist() does a loop on the hist_data representing the keys. The issue is, if the keys uses one of the pseudo field types (like common_cpu), the hist_data field element will have NULL for its field member causing a NULL pointer dereference when accessing the key_field->field->name.
# echo 'hist:keys=common_cpu:ts0=common_timestamp.usecs' > \
events/sched/sched_waking/trigger
# echo 'my_synth u64 lat; int prio' > synthetic_events
# echo 'hist:keys=common_cpu:wakeup_lat=common_timestamp.usecs-$ts0:\
onmatch(sched.sched_waking).my_synth($wakeup_lat,prio)' > \
events/sched/sched_switch/triggerKASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:create_field_var_hist+0x771/0x1380 Call Trace: trace_action_create_field_var+0x360/0x600 trace_action_create+0x393/0xe80 event_hist_trigger_parse+0x3e47/0x69e0 trigger_process_regex+0x1a6/0x250 event_trigger_write+0xce/0x160
Instead of accessing it directly, use the proper handler expr_field_str() to get the name.
The three previous patches are prerequisites: without them a .buckets key and a common_stacktrace key each render into a command that cannot be parsed back.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -3025,7 +3025,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data, key_field = hist_data->fields[i];if (!first)seq_buf_putc (&s,',' ); -seq_buf_puts (&s, key_field->field->name); +expr_field_str (key_field, &s); first = false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 498/2857 drm/amdgpu/uvd3.1: Fix checking whether UVD firmware keyselect was already set
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 800ea86e83e137395eba54103e5c459c2bc9965f ]
The PASS_MASK is for a different register not for UVD_FW_START. It was a mistake to check this flag. It should be enough to check that the register is non-zero.
--- drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c +1 -1
@@ -288,7 +288,7 @@ static int uvd_v3_1_fw_validate(struct amdgpu_device *adev)int i;uint32_t keysel = adev->uvd.keyselect; -if (RREG32 (mmUVD_FW_START) &UVD_FW_STATUS__PASS_MASK ) { +if (RREG32 (mmUVD_FW_START)) {dev_dbg (adev->dev,"UVD keyselect already set: 0x%x (on CPU: 0x%x)\n" ,RREG32 (mmUVD_FW_START), adev->uvd.keyselect);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 499/2857 serial: core: fix TIOCSSERIAL and TIOCSERCONFIG on uninitialised ports
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hengyu Liang <[email protected]>
[ Upstream commit e1f46a09df93650288babb23de6e34bff73e80e6 ]
Commit 8ca59f7baee7 ("serial: fix ioctl hangup race") made uart_set_info() and uart_do_autoconfig() return -EIO when TTY_IO_ERROR is set, so that they do not run on a port that has been hung up.
However, TTY_IO_ERROR is also set on a port that could not be started, for example because its type is unknown, and by uart_shutdown(), which both functions call. As of now, setserial cannot configure a port that the kernel did not detect, and an autoconfig that follows a port, irq or type change in the same setserial call fails on any port.
The issue can be reproduced with setserial (busybox) on a port without a detected UART, for example ttyS3 of a QEMU guest:
setserial /dev/ttyS3 uart 16550A
setserial -g /dev/ttyS3
Before commit 8ca59f7baee7 ("serial: fix ioctl hangup race"), the result is:
/dev/ttyS3, UART: 16550A, Port: 0x02e8, IRQ: 3
After that commit, the result is:
setserial: can't set serial info: Input/output error /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3
This patch will check tty_port_active() in these two functions instead. uart_hangup() clears it under the port mutex, and it stays set on an open port that could not be started.
--- drivers/tty/serial/serial_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/tty/serial/serial_core.c +7 -2
@@ -816,7 +816,11 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,upf_t old_flags, new_flags;int retval =0 ; -if (!uport ||tty_io_error (tty)) +/* +* TTY_IO_ERROR is also set on a port that could not be started, and +* this is how such a port is configured. Only refuse a hung up port. +*/ +if (!uport || !tty_port_active (port))return -EIO ; new_port = new_info->port;
@@ -1149,7 +1153,8 @@ static int uart_do_autoconfig(struct tty_struct *tty, struct uart_state *state)return -ERESTARTSYS ; uport =uart_port_check (state); -if (!uport ||tty_io_error (tty)) { +/* As in uart_set_info(), only refuse a hung up port. */ +if (!uport || !tty_port_active (port)) { ret = -EIO ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 500/2857 net/sched: sch_teql: fix slaves_lock IRQ deadlock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
commit 8b2043279dae25483fe1f2d926e76d41ab95c398 upstream.
This is a followup of commit e5b811fe7931 ("net/sched: sch_teql:
Introduce slaves_lock to avoid race condition and UAF") as reported by Sashiko.
The issue: master->slaves_lock serializes the master's ring of slave qdiscs. The control paths -- teql_dequeue(), teql_destroy() and teql_qdisc_init() -- take it with spin_lock_bh(), while teql_master_xmit() (the master's ndo_start_xmit) takes it with plain spin_lock().
netpoll_send_skb() wraps the transmit in local_irq_save(), and __netpoll_send_skb() asserts lockdep_assert_irqs_disabled(), so teql_master_xmit() reached from netconsole always acquires slaves_lock with hard IRQs disabled. On PREEMPT_RT spinlock_t is an rtmutex, and Documentation/locking/locktypes.rst names
local_irq_disable(); spin_lock(&lock);
as a sequence that breaks there because the rtmutex requires a fully preemptible context. This is reachable without any panic: the nbcon printer thread calls netconsole's write_thread() callback on every message. The usual remedy -- folding the IRQ disable into the lock with spin_lock_irqsave() -- is unavailable because the local_irq_save() is netpoll's, not ours.
On non-RT the same asymmetry leaves slaves_lock acquirable with hard IRQs disabled on one path and held with hard IRQs enabled on another. That is only exploitable during the panic console flush (netconsole is CON_NBCON_ATOMIC_UNSAFE, so console_is_usable() admits its write_atomic() only from nbcon_atomic_flush_unsafe(), which panic() alone calls), and even then an IRQ-saving lock does not help if the holder oopsed inside the section or was stopped by panic_other_cpus_shutdown(). So the non-RT half is hardening; the PREEMPT_RT half is the bug.
The Fix: take slaves_lock as a raw spinlock with IRQs saved at every site. Since skb_queue_purge() takes the queue's spinlock_t and may not nest inside a raw lock on PREEMPT_RT, move its call in teql_destroy() outside the raw section; dat->q is the dying qdisc's own queue and was never serialized by slaves_lock, so the move is behaviour-neutral.
The new critical sections contain only RCU pointer assignments and netdev_get_tx_queue(); skb_queue_purge(), netif_wake_queue() and dev_reset_queue() are all outside them. teql_destroy()'s ring walk is O(slaves), two pointer loads and a compare per iteration, so even a large ring is microseconds with IRQs off. Keeping the purge conditional rather than dropping it outright is the conservative call for a backport.
Some context: commit 6301f6a34ed8 ("net/sched: sch_teql: move rcu_read_lock()/spin_lock() from _bh variants") hardened the parent fix; together they addressed the master->slaves resurrection use-after-free and the xmit-side BH warning but left the reverse direction -- a hard IRQ re-entering xmit while a control path holds the lock -- unaddressed.
Conditions to recreate the bug:
- CONFIG_PREEMPT_RT, CONFIG_NET_SCH_TEQL, CONFIG_DUMMY and CONFIG_NETCONSOLE.
- Run ip link add dev teqlslave0 type dummy, bring teqlslave0 up, attach it with tc qdisc add dev teqlslave0 root teql0, and bring teql0 up.
- Configure a netconsole target on teql0 with explicit local and remote IP addresses and a remote MAC address, then emit a console message. The nbcon printer thread reaches teql_master_xmit() with hard IRQs disabled by netpoll; taking slaves_lock as a spinlock_t is invalid on PREEMPT_RT. No panic or concurrent qdisc change is required.
- Reachable by an admin with CAP_NET_ADMIN; teql devices exist only in the initial netns (no per-netns ops), so a user namespace does not suffice.
--- net/sched/sch_teql.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-)
net/sched/sch_teql.c +28 -17
@@ -53,7 +53,7 @@ struct teql_master {struct Qdisc_ops qops;struct net_device *dev;struct Qdisc __rcu *slaves; -spinlock_t slaves_lock;/* serializes writes to ->slaves */ +raw_spinlock_t slaves_lock;/* serializes writes to ->slaves */ struct list_head master_list;unsigned long tx_bytes;unsigned long tx_packets;
@@ -92,6 +92,7 @@ teql_dequeue(struct Qdisc *sch) {struct teql_sched_data *dat =qdisc_priv (sch);struct netdev_queue *dat_queue; +unsigned long flags;struct sk_buff *skb;struct Qdisc *q;
@@ -102,9 +103,9 @@ teql_dequeue(struct Qdisc *sch)if (skb ==NULL ) {struct net_device *m =qdisc_dev (q);if (m) { -spin_lock_bh (&dat->m->slaves_lock); +raw_spin_lock_irqsave (&dat->m->slaves_lock, flags);rcu_assign_pointer (dat->m->slaves, sch); -spin_unlock_bh (&dat->m->slaves_lock); +raw_spin_unlock_irqrestore (&dat->m->slaves_lock, flags);netif_wake_queue (m); } }else {
@@ -137,11 +138,13 @@ teql_destroy(struct Qdisc *sch)struct teql_master *master = dat->m;struct netdev_queue *txq =NULL ;bool reset_master_queue = false; +unsigned long flags; +bool purge = false;if (!master)return ; -spin_lock_bh (&master->slaves_lock); +raw_spin_lock_irqsave (&master->slaves_lock, flags); prev =rcu_dereference_protected (master->slaves,lockdep_is_held (&master->slaves_lock));if (prev) {
@@ -169,12 +172,18 @@ teql_destroy(struct Qdisc *sch) reset_master_queue = true; } } -skb_queue_purge (&dat->q); + purge = true;break ; }while (prev !=rcu_dereference_protected (master->slaves,lockdep_is_held (&master->slaves_lock))); } -spin_unlock_bh (&master->slaves_lock); +raw_spin_unlock_irqrestore (&master->slaves_lock, flags); + +/* skb_queue_purge() takes the queue's spinlock_t, which cannot nest +* inside a raw lock on PREEMPT_RT; purge after the raw section. +*/ +if (purge) +skb_queue_purge (&dat->q);if (reset_master_queue)dev_reset_queue (master->dev, txq,NULL );
@@ -187,6 +196,7 @@ static int teql_qdisc_init(struct Qdiscstruct teql_master *m = (struct teql_master *)sch->ops;struct teql_sched_data *q =qdisc_priv (sch);struct Qdisc *first; +unsigned long flags;if (dev->hard_header_len > m->dev->hard_header_len)return -EINVAL ;
@@ -203,7 +213,7 @@ static int teql_qdisc_init(struct Qdiscskb_queue_head_init (&q->q); -spin_lock_bh (&m->slaves_lock); +raw_spin_lock_irqsave (&m->slaves_lock, flags); first =rcu_dereference_protected (m->slaves,lockdep_is_held (&m->slaves_lock));if (first) {if (m->dev->flags &IFF_UP ) {
@@ -214,7 +224,7 @@ static int teql_qdisc_init(struct Qdisc (m->dev->flags & IFF_MULTICAST && !(dev->flags & IFF_MULTICAST)) || dev->mtu < m->dev->mtu) { -spin_unlock_bh (&m->slaves_lock); +raw_spin_unlock_irqrestore (&m->slaves_lock, flags);return -EINVAL ; } }else {
@@ -237,7 +247,7 @@ static int teql_qdisc_init(struct Qdisc m->dev->mtu = dev->mtu; m->dev->flags = (m->dev->flags&~FMASK )|(dev->flags&FMASK ); } -spin_unlock_bh (&m->slaves_lock); +raw_spin_unlock_irqrestore (&m->slaves_lock, flags);return 0 ; }
@@ -302,11 +312,12 @@ static inline int teql_resolve(struct skstatic netdev_tx_t teql_master_xmit (struct sk_buff *skb,struct net_device *dev) {struct teql_master *master =netdev_priv (dev); -struct Qdisc *start, *q; -int busy; -int nores;int subq =skb_get_queue_mapping (skb);struct sk_buff *skb_res =NULL ; +struct Qdisc *start, *q; +unsigned long flags; +int nores; +int busy; restart: nores =0 ;
@@ -342,13 +353,13 @@ restart: netdev_start_xmit(skb, slave, slave_txq, false) == NETDEV_TX_OK) {__netif_tx_unlock (slave_txq); -spin_lock (&master->slaves_lock); +raw_spin_lock_irqsave (&master->slaves_lock, flags);if (rcu_dereference_protected (master->slaves,lockdep_is_held (&master->slaves_lock)) == q)rcu_assign_pointer (master->slaves,rcu_dereference_protected (NEXT_SLAVE (q),lockdep_is_held (&master->slaves_lock))); -spin_unlock (&master->slaves_lock); +raw_spin_unlock_irqrestore (&master->slaves_lock, flags);netif_wake_queue (dev); master->tx_packets++; master->tx_bytes += length;
@@ -361,13 +372,13 @@ restart: busy =1 ;break ;case 1 : -spin_lock (&master->slaves_lock); +raw_spin_lock_irqsave (&master->slaves_lock, flags);if (rcu_dereference_protected (master->slaves,lockdep_is_held (&master->slaves_lock)) == q)rcu_assign_pointer (master->slaves,rcu_dereference_protected (NEXT_SLAVE (q),lockdep_is_held (&master->slaves_lock))); -spin_unlock (&master->slaves_lock); +raw_spin_unlock_irqrestore (&master->slaves_lock, flags);rcu_read_unlock ();return NETDEV_TX_OK ;default :
@@ -489,7 +500,7 @@ static __init void teql_master_setup(strstruct teql_master *master =netdev_priv (dev);struct Qdisc_ops *ops = &master->qops; -spin_lock_init (&master->slaves_lock); +raw_spin_lock_init (&master->slaves_lock); master->dev = dev; ops->priv_size =sizeof (struct teql_sched_data );