6.18.65-rc1 review
Greg Kroah-Hartman
maintainerPATCH 78/2151 l2tp: snapshot sequencing state when building transmit headers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit d06ae66516e1aaf023808912af6292aef09d46c3 ]
Updates to send_seq from netlink, PPP setsockopt and receive-side negotiation race with packet transmission. The header length is updated separately, while transmit reads both fields repeatedly without synchronization.
For example, transmit can push a ten-byte L2TPv2 header, then a concurrent writer clears send_seq before the header builder reads it. The builder writes only six bytes, leaving four bytes of uninitialized skb headroom in the outgoing packet. The reverse mismatch overwrites the beginning of the payload. A later hdr_len read can also make the UDP length disagree with the skb length.
KCSAN reported:
BUG: KCSAN: data-race in l2tp_session_set_header_len / l2tp_xmit_skb
write to 0xffff888100d0944a of 2 bytes by task 116 on cpu 1:
l2tp_session_set_header_len+0x81/0xc0 l2tp_nl_cmd_session_modify+0x122/0x2c0 genl_family_rcv_msg_doit+0x170/0x1d0
read to 0xffff888100d0944a of 2 bytes by task 115 on cpu 0:
l2tp_xmit_skb+0x9c/0xc80 pppol2tp_sendmsg+0x21c/0x2a0 __sys_sendto+0x28c/0x2a0
The bug can lead to leak kernel base address for KASLR bypass, the corresponding reproducer can be provided per request.
Initialize hdr_len to the maximum header size and leave it unchanged when sequencing is toggled. Snapshot send_seq once per packet and use that snapshot for the actual header length and header construction, including the sequence flag. Use the same length for headroom, the header push and the UDP length. PPP callers can safely reserve the maximum size; L2TPv3 header sizes do not depend on sequencing.
Make send_seq a separate bool so READ_ONCE() and WRITE_ONCE() can be used without sharing a bitfield storage unit with other configuration flags. Preserve the netlink attribute's existing low-bit truncation.
--- net/l2tp/l2tp_core.c | 51 +++++++++++++++++++---------------------- net/l2tp/l2tp_core.h | 6 ++--- net/l2tp/l2tp_debugfs.c | 4 ++-- net/l2tp/l2tp_netlink.c | 11 ++++----- net/l2tp/l2tp_ppp.c | 8 +++---- 5 files changed, 35 insertions(+), 45 deletions(-)
net/l2tp/l2tp_core.c +24 -27
@@ -924,11 +924,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,* check if we sre sending sequence numbers and if not, * configure it so. */ -if (!session->lns_mode && !session->send_seq) { +if (!session->lns_mode && !READ_ONCE (session->send_seq)) {trace_session_seqnum_lns_enable (session); - session->send_seq =1 ; -l2tp_session_set_header_len (session, tunnel->version, - tunnel->encap); +WRITE_ONCE (session->send_seq, true); } }else {/* No sequence numbers.
@@ -946,12 +944,10 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,* If we're the LNS and we're sending sequence numbers, the * LAC is broken. Discard the frame. */ -if (!session->lns_mode && session->send_seq) { +if (!session->lns_mode &&READ_ONCE (session->send_seq)) {trace_session_seqnum_lns_disable (session); - session->send_seq =0 ; -l2tp_session_set_header_len (session, tunnel->version, - tunnel->encap); - }else if (session->send_seq) { +WRITE_ONCE (session->send_seq, false); + }else if (READ_ONCE (session->send_seq)) {pr_debug_ratelimited ("%s: recv data has no seq numbers when required. Discarding.\n" , session->name);atomic_long_inc (&session->stats.rx_seq_discards);
@@ -1147,7 +1143,8 @@ static void l2tp_udp_encap_err_recv(struct sock *sk, struct sk_buff *skb, int er/* Build an L2TP header for the session into the buffer provided. */ -static int l2tp_build_l2tpv2_header (struct l2tp_session *session,void *buf) +static int l2tp_build_l2tpv2_header (struct l2tp_session *session,void *buf, +bool send_seq) {struct l2tp_tunnel *tunnel = session->tunnel;__be16 *bufp = buf;
@@ -1156,14 +1153,14 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)u32 tunnel_id = tunnel->peer_tunnel_id;u32 session_id = session->peer_session_id; -if (session->send_seq) +if (send_seq) flags |=L2TP_HDRFLAG_S ;/* Setup L2TP header. */ *bufp++ =htons (flags); *bufp++ =htons (tunnel_id); *bufp++ =htons (session_id); -if (session->send_seq) { +if (send_seq) { *bufp++ =htons (session->ns); *bufp++ =0 ; session->ns++;
@@ -1174,7 +1171,8 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)return bufp - optr; } -static int l2tp_build_l2tpv3_header (struct l2tp_session *session,void *buf) +static int l2tp_build_l2tpv3_header (struct l2tp_session *session,void *buf, +bool send_seq) {struct l2tp_tunnel *tunnel = session->tunnel;char *bufp = buf;
@@ -1200,7 +1198,7 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)if (session->l2specific_type ==L2TP_L2SPECTYPE_DEFAULT ) {u32 l2h =0 ; -if (session->send_seq) { +if (send_seq) { l2h =0x40000000 | session->ns; session->ns++; session->ns &=0xffffff ;
@@ -1234,19 +1232,24 @@ static int l2tp_xmit_queue(struct l2tp_tunnel *tunnel, struct sk_buff *skb, strustatic int l2tp_xmit_core (struct l2tp_session *session,struct sk_buff *skb,unsigned int *len) {struct l2tp_tunnel *tunnel = session->tunnel; +bool send_seq =READ_ONCE (session->send_seq);unsigned int data_len = skb->len;struct sock *sk = tunnel->sock; +u16 hdr_len = session->hdr_len;int headroom, uhlen, udp_len;int ret =NET_XMIT_SUCCESS ;struct inet_sock *inet;struct udphdr *uh; +if (tunnel->version ==L2TP_HDR_VER_2 && !send_seq) + hdr_len -=4 ; +/* Check that there's enough headroom in the skb to insert IP, * UDP and L2TP headers. If not enough, expand it to * make room. Adjust truesize. */ uhlen = (tunnel->encap ==L2TP_ENCAPTYPE_UDP ) ?sizeof (*uh) :0 ; - headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + session->hdr_len; + headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + hdr_len;if (skb_cow_head (skb, headroom)) {kfree_skb (skb);return NET_XMIT_DROP ;
@@ -1254,9 +1257,9 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns/* Setup L2TP header */ if (tunnel->version ==L2TP_HDR_VER_2 ) -l2tp_build_l2tpv2_header (session,__skb_push (skb, session->hdr_len)); +l2tp_build_l2tpv2_header (session,__skb_push (skb, hdr_len), send_seq);else -l2tp_build_l2tpv3_header (session,__skb_push (skb, session->hdr_len)); +l2tp_build_l2tpv3_header (session,__skb_push (skb, hdr_len), send_seq);/* Reset control buffer */ memset (skb->cb,0 ,sizeof (skb->cb));
@@ -1299,7 +1302,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns uh =udp_hdr (skb); uh->source = inet->inet_sport; uh->dest = inet->inet_dport; - udp_len = uhlen + session->hdr_len + data_len; + udp_len = uhlen + hdr_len + data_len;if (udp_len >U16_MAX ) {kfree_skb (skb); ret =NET_XMIT_DROP ;
@@ -1768,16 +1771,11 @@ static void l2tp_session_del_work(struct work_struct *work)l2tp_session_put (session); } -/* We come here whenever a session's send_seq, cookie_len or -* l2specific_type parameters are set. -*/ -void l2tp_session_set_header_len (struct l2tp_session *session,int version, -enum l2tp_encap_type encap) +static void l2tp_session_set_header_len (struct l2tp_session *session,int version, +enum l2tp_encap_type encap) {if (version ==L2TP_HDR_VER_2 ) { - session->hdr_len =6 ; -if (session->send_seq) - session->hdr_len +=4 ; + session->hdr_len =10 ; }else { session->hdr_len =4 + session->cookie_len; session->hdr_len +=l2tp_get_l2specific_len (session);
@@ -1785,7 +1783,6 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version, session->hdr_len +=4 ; } } -EXPORT_SYMBOL_GPL (l2tp_session_set_header_len);struct l2tp_session *l2tp_session_create (int priv_size,struct l2tp_tunnel *tunnel,u32 session_id,u32 peer_session_id,struct l2tp_session_cfg *cfg)
net/l2tp/l2tp_core.h +2 -4
@@ -76,7 +76,7 @@ struct l2tp_session {u8 peer_cookie[8 ];int peer_cookie_len;u16 l2specific_type; -u16 hdr_len; +u16 hdr_len;/* maximum L2TP header length */ u32 nr;/* session NR state (receive) */ u32 ns;/* session NR state (send) */ struct sk_buff_head reorder_q;/* receive reorder queue */
@@ -94,8 +94,8 @@ struct l2tp_session {char name[L2TP_SESSION_NAME_MAX ];/* for logging */ char ifname[IFNAMSIZ ]; +bool send_seq;/* send packets with sequence numbers? */ unsigned int recv_seq:1; /* expect receive packets with sequence numbers? */ - unsigned int send_seq:1; /* send packets with sequence numbers? */ unsigned int lns_mode:1; /* behave as LNS?* LAC enables sequence numbers under LNS control. */
@@ -257,8 +257,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,int l2tp_udp_encap_recv (struct sock *sk,struct sk_buff *skb);/* Transmit path helpers for sending packets over the tunnel socket. */ -void l2tp_session_set_header_len (struct l2tp_session *session,int version, -enum l2tp_encap_type encap);int l2tp_xmit_skb (struct l2tp_session *session,struct sk_buff *skb);/* Pseudowire management.
net/l2tp/l2tp_debugfs.c +2 -2
@@ -182,12 +182,12 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) session->pwtype ==L2TP_PWTYPE_ETH ?"ETH" : session->pwtype ==L2TP_PWTYPE_PPP ?"PPP" : ""); -if (session->send_seq || session->recv_seq) +if (READ_ONCE (session->send_seq) || session->recv_seq)seq_printf (m," nr %u, ns %u\n" , session->nr, session->ns);seq_printf (m," refcnt %d\n" ,refcount_read (&session->ref_count));seq_printf (m," config 0/0/%c/%c/-/%s %08x %u\n" , session->recv_seq ?'R' :'-' , - session->send_seq ?'S' :'-' , +READ_ONCE (session->send_seq) ?'S' :'-' , session->lns_mode ?"LNS" :"LAC" ,0 ,jiffies_to_msecs (session->reorder_timeout));
net/l2tp/l2tp_netlink.c +4 -7
@@ -697,12 +697,9 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *infif (info->attrs[L2TP_ATTR_RECV_SEQ ]) session->recv_seq =nla_get_u8 (info->attrs[L2TP_ATTR_RECV_SEQ ]); -if (info->attrs[L2TP_ATTR_SEND_SEQ ]) { -struct l2tp_tunnel *tunnel = session->tunnel; - - session->send_seq =nla_get_u8 (info->attrs[L2TP_ATTR_SEND_SEQ ]); -l2tp_session_set_header_len (session, tunnel->version, tunnel->encap); - } +if (info->attrs[L2TP_ATTR_SEND_SEQ ]) +WRITE_ONCE (session->send_seq, +nla_get_u8 (info->attrs[L2TP_ATTR_SEND_SEQ ]) &1 );if (info->attrs[L2TP_ATTR_LNS_MODE ]) session->lns_mode =nla_get_u8 (info->attrs[L2TP_ATTR_LNS_MODE ]);
@@ -745,7 +742,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl (session->peer_cookie_len &&nla_put (skb,L2TP_ATTR_PEER_COOKIE , session->peer_cookie_len, session->peer_cookie)) ||nla_put_u8 (skb,L2TP_ATTR_RECV_SEQ , session->recv_seq) || -nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ , session->send_seq) || +nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ ,READ_ONCE (session->send_seq)) ||nla_put_u8 (skb,L2TP_ATTR_LNS_MODE , session->lns_mode) || (l2tp_tunnel_uses_xfrm (tunnel) && nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) ||
net/l2tp/l2tp_ppp.c +3 -5
@@ -1193,15 +1193,13 @@ static int pppol2tp_session_setsockopt(struct sock *sk, err = -EINVAL ;break ; } - session->send_seq = !!val; +WRITE_ONCE (session->send_seq, !!val); {struct pppox_sock *po =pppox_sk (sk); po->chan.hdrlen = val ?PPPOL2TP_L2TP_HDR_SIZE_SEQ :PPPOL2TP_L2TP_HDR_SIZE_NOSEQ ; } -l2tp_session_set_header_len (session, session->tunnel->version, - session->tunnel->encap);break ;case PPPOL2TP_SO_LNSMODE :
@@ -1311,7 +1309,7 @@ static int pppol2tp_session_getsockopt(struct sock *sk,break ;case PPPOL2TP_SO_SENDSEQ : - *val = session->send_seq; + *val =READ_ONCE (session->send_seq);break ;case PPPOL2TP_SO_LNSMODE :
@@ -1557,7 +1555,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) state, user_data_ok);seq_printf (m," 0/0/%c/%c/%s %08x %u\n" , session->recv_seq ?'R' :'-' , - session->send_seq ?'S' :'-' , +READ_ONCE (session->send_seq) ?'S' :'-' , session->lns_mode ?"LNS" :"LAC" ,0 ,jiffies_to_msecs (session->reorder_timeout));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 79/2151 mm/memory: update stale locking comments for fault handlers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aditya Sharma <[email protected]>
[ Upstream commit 214f9ab72ce6e16120c20ad670389656f059e685 ]
Update the comments for wp_page_copy(), do_wp_page(), do_swap_page(), do_anonymous_page(), __do_fault(), do_fault(), handle_pte_fault(), __handle_mm_fault(), and handle_mm_fault() to concisely clarify that they can be entered holding either the mmap_lock or the VMA lock, and that the lock may be released upon returning VM_FAULT_RETRY.
Additionally, make the following corrections:
- In do_anonymous_page(), correct the outdated claim that the function is entered with the PTE "mapped but not yet locked". Since handle_pte_fault() unmaps the empty PTE before routing to do_pte_missing(), the comment now correctly states it is entered with the PTE unmapped and unlocked.
- In __do_fault(), update the stale reference from __lock_page_retry() to __folio_lock_or_retry().
Stable-dep-of: f681d4580d5c ("mm: fix address wraparound when scanning large folio PTEs")
--- mm/memory.c | 55 ++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 26 deletions(-)
mm/memory.c +29 -26
@@ -3673,8 +3673,8 @@ vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf)* Handle the case of a page which we actually need to copy to a new page, * either due to COW or unsharing. * -* Called with mmap_lock locked and the old page referenced, but -* without the ptl held. +* Called with either the VMA lock or the mmap_lock held (see FAULT_FLAG_VMA_LOCK) +* and the old page referenced, but without the ptl held. * * High level logic flow: *
@@ -4075,9 +4075,9 @@ static bool wp_can_reuse_anon_folio(struct folio *folio,* though the page will change only once the write actually happens. This * avoids a few races, and potentially makes it more efficient. * -* We enter with non-exclusive mmap_lock (to exclude vma changes, -* but allow concurrent faults), with pte both mapped and locked. -* We return with mmap_lock still held, but pte unmapped and unlocked. +* We enter with either the VMA lock or the mmap_lock held (see +* FAULT_FLAG_VMA_LOCK) and pte both mapped and locked. We return with +* the same lock still held, but pte unmapped and unlocked. */ static vm_fault_t do_wp_page(struct vm_fault *vmf) __releases(vmf->ptl)
@@ -4605,12 +4605,12 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)static DECLARE_WAIT_QUEUE_HEAD (swapcache_wq);/* -* We enter with non-exclusive mmap_lock (to exclude vma changes, -* but allow concurrent faults), and pte mapped but not yet locked. +* We enter with either the VMA lock or the mmap_lock held (see +* FAULT_FLAG_VMA_LOCK), and pte mapped but not yet locked. * We return with pte unmapped and unlocked. * -* We return with the mmap_lock locked or unlocked in the same cases -* as does filemap_fault(). +* When returning, the lock may have been released in the same cases +* as done by filemap_fault(). */ vm_fault_t do_swap_page (struct vm_fault *vmf) {
@@ -5161,9 +5161,10 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf) }/* -* We enter with non-exclusive mmap_lock (to exclude vma changes, -* but allow concurrent faults), and pte mapped but not yet locked. -* We return with mmap_lock still held, but pte unmapped and unlocked. +* We enter with either the VMA lock or the mmap_lock held (see +* FAULT_FLAG_VMA_LOCK), and pte unmapped and unlocked. +* We return with the lock still held, but pte unmapped and unlocked. +* If VM_FAULT_RETRY is returned, the lock may have been released. */ static vm_fault_t do_anonymous_page (struct vm_fault *vmf) {
@@ -5281,9 +5282,10 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) }/* -* The mmap_lock must have been held on entry, and may have been -* released depending on flags and vma->vm_ops->fault() return value. -* See filemap_fault() and __lock_page_retry(). +* Either the VMA lock or the mmap_lock must have been held on entry +* (see FAULT_FLAG_VMA_LOCK) and may have been released depending on +* flags and vma->vm_ops->fault() return value. +* See filemap_fault() and __folio_lock_or_retry(). */ static vm_fault_t __do_fault (struct vm_fault *vmf) {
@@ -5844,11 +5846,11 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf) }/* -* We enter with non-exclusive mmap_lock (to exclude vma changes, -* but allow concurrent faults). -* The mmap_lock may have been released depending on flags and our +* We enter with either the VMA lock or the mmap_lock held (see +* FAULT_FLAG_VMA_LOCK). +* The lock may have been released depending on flags and our * return value. See filemap_fault() and __folio_lock_or_retry(). -* If mmap_lock is released, vma may become invalid (for example +* If the lock is released, vma may become invalid (for example * by other thread calling munmap()). */ static vm_fault_t do_fault (struct vm_fault *vmf)
@@ -6176,10 +6178,11 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud)* with external mmu caches can use to update those (ie the Sparc or * PowerPC hashed page tables that act as extended TLBs). * -* We enter with non-exclusive mmap_lock (to exclude vma changes, but allow -* concurrent faults). +* On entry, we hold either the VMA lock or the mmap_lock +* (see FAULT_FLAG_VMA_LOCK). * -* The mmap_lock may have been released depending on flags and our return value. +* The mmap_lock or VMA lock may have been released depending on flags +* and our return value. * See filemap_fault() and __folio_lock_or_retry(). */ static vm_fault_t handle_pte_fault (struct vm_fault *vmf)
@@ -6272,8 +6275,8 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)/* * On entry, we hold either the VMA lock or the mmap_lock -* (FAULT_FLAG_VMA_LOCK tells you which). If VM_FAULT_RETRY is set in -* the result, the mmap_lock is not held on exit. See filemap_fault() +* (see FAULT_FLAG_VMA_LOCK). If VM_FAULT_RETRY is set in +* the result, the lock is not held on exit. See filemap_fault() * and __folio_lock_or_retry(). */ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
@@ -6501,9 +6504,9 @@ static vm_fault_t sanitize_fault_flags(struct vm_area_struct *vma,/* * By the time we get here, we already hold either the VMA lock or the -* mmap_lock (FAULT_FLAG_VMA_LOCK tells you which). +* mmap_lock (see FAULT_FLAG_VMA_LOCK). * -* The mmap_lock may have been released depending on flags and our +* The lock may have been released depending on flags and our * return value. See filemap_fault() and __folio_lock_or_retry(). */ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 80/2151 mm: fix address wraparound when scanning large folio PTEs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit f681d4580d5c3c749f623cda722a21aefd3147b3 ]
numa_rebuild_large_mapping() and do_swap_page() can be tricked into generating an address wraparound, crashing the kernel. All that's required is to map a tail page of a large folio close enough to the start/end of the address space to e.g., make
unsigned long addr_start = addr - (nr << PAGE_SHIFT);
to wrap around.
Let's fix it by providing a better helper, folio_scan_range(), that takes care of staying within VMA and page table boundaries while handling possible wraparounds.
There are some nasty details, like not being able to use pmd_addr_end() in this context. Add some helpful comments for these cases.
--- mm/memory.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-)
mm/memory.c +36 -14
@@ -4604,6 +4604,34 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)static DECLARE_WAIT_QUEUE_HEAD (swapcache_wq); +/* +* Get the address range in which a folio might be mapped, assuming its pages +* are mapped consecutively and the folio page at the given idx is mapped at +* the given address. +*/ +static void folio_pte_range (const struct folio *folio, +const struct vm_area_struct *vma,unsigned long addr, +unsigned long idx,unsigned long *start,unsigned long *end) +{ +/* Stay within the page table and VMA boundaries. */ +const unsigned long pmd_start = addr &PMD_MASK ; +const unsigned long pmd_end = pmd_start +PMD_SIZE ; +const unsigned long lower =max (pmd_start, vma->vm_start); +/* +* We cannot use pmd_addr_end(), as it does not clamp reliably. To +* avoid wraparounds, compute using the inclusive end. +*/ +const unsigned long upper =min (pmd_end -1 , vma->vm_end -1 ) +1 ; +const unsigned long offset = idx <<PAGE_SHIFT ; + +/* +* Avoid start/end addresses wrapping by not adding/subtracting more +* than the lower/upper limits would allow. +*/ + *start = addr -min (addr - lower, offset); + *end = addr +min (upper - addr,folio_size (folio) - offset); +} +/* * We enter with either the VMA lock or the mmap_lock held (see * FAULT_FLAG_VMA_LOCK), and pte mapped but not yet locked.
@@ -4861,16 +4889,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) address = vmf->address; ptep = vmf->pte;if (folio_test_large (folio) &&folio_test_swapcache (folio)) { -int nr =folio_nr_pages (folio); -unsigned long idx =folio_page_idx (folio, page); -unsigned long folio_start = address - idx *PAGE_SIZE ; -unsigned long folio_end = folio_start + nr *PAGE_SIZE ; +const int nr =folio_nr_pages (folio); +const unsigned long idx =folio_page_idx (folio, page); +unsigned long folio_start, folio_end;pte_t *folio_ptep;pte_t folio_pte; -if (unlikely (folio_start <max (address &PMD_MASK , vma->vm_start))) - goto check_folio; -if (unlikely (folio_end >pmd_addr_end (address, vma->vm_end))) +folio_pte_range (folio, vma, address, idx, &folio_start, + &folio_end); +if (unlikely ((folio_end - folio_start) >>PAGE_SHIFT != nr)) goto check_folio; folio_ptep = vmf->pte - idx;
@@ -5963,16 +5990,11 @@ static void numa_rebuild_large_mapping(struct vm_fault *vmf, struct vm_area_stru struct folio *folio, pte_t fault_pte, bool ignore_writable, bool pte_write_upgrade) { - int nr = pte_pfn(fault_pte) - folio_pfn(folio); + const unsigned long idx = pte_pfn(fault_pte) - folio_pfn(folio);unsigned long start, end, addr = vmf->address; -unsigned long addr_start = addr - (nr <<PAGE_SHIFT ); -unsigned long pt_start =ALIGN_DOWN (addr,PMD_SIZE );pte_t *start_ptep; -/* Stay within the VMA and within the page table. */ - start =max3 (addr_start, pt_start, vma->vm_start); - end =min3 (addr_start +folio_size (folio), pt_start +PMD_SIZE , - vma->vm_end); +folio_pte_range (folio, vma, addr, idx, &start, &end); start_ptep = vmf->pte - ((addr - start) >>PAGE_SHIFT );/* Restore all PTEs' mapping of the large folio */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 81/2151 mm/huge_memory: fix truncate racing with PMD zapping
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit e6a07d29b0a60f3a4cfe77fe34eeb4b3fb38d6c4 ]
zap_huge_pmd_folio() removes the rmap before calling folio_mark_dirty(). If this was the last mapping, truncation can skip unmapping the folio and proceed without waiting for the PMD lock, racing with dirtying.
ifs_set_range_dirty() can oops if MADV_DONTNEED races with ftruncate() on XFS, when we get the folio set dirty after it was found to not be mapped anymore.
Move folio_mark_dirty() and folio_mark_accessed() before rmap removal, matching the PTE zap path. This keeps the folio mapped while updating its state, so truncation must wait for the page table lock.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/huge_memory.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/huge_memory.c +9 -2
@@ -2327,8 +2327,6 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page =pmd_page (orig_pmd); folio =page_folio (page); -folio_remove_rmap_pmd (folio, page, vma); -WARN_ON_ONCE (folio_mapcount (folio) <0 );VM_BUG_ON_PAGE (!PageHead (page), page); }else if (thp_migration_supported ()) {swp_entry_t entry;
@@ -2360,6 +2358,15 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,folio_mark_accessed (folio); } +/* +* Only present folios are rmappable. Remove the rmap after +* transferring young+dirty to the folio. +*/ +if (flush_needed) { +folio_remove_rmap_pmd (folio, &folio->page, vma); +WARN_ON_ONCE (folio_mapcount (folio) <0 ); + } +spin_unlock (ptl);if (flush_needed)tlb_remove_page_size (tlb, &folio->page,HPAGE_PMD_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 82/2151 hwmon: (coretemp) Read TjMax only when refreshing the temperature
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Neri <[email protected]>
[ Upstream commit 5407d2b7d5279b7100621d92f2181184c8f00d62 ]
show_temp() reads TjMax before checking whether the cached temperature is still fresh, but consumes it only when recomputing that temperature. On a cache hit the value is discarded.
Discarding it is not free. On CPUs that report TjMax in MSR_IA32_TEMPERATURE_TARGET, get_tjmax() returns the value it just read without storing it in tdata->tjmax, so every call reads the MSR again. That is a cross-CPU call whenever the CPU owning the sensor is not the current one, and it is made while holding tdata->update_lock.
Read TjMax where it is used. The value cannot go stale in the meantime:
bits 23:16 of MSR_IA32_TEMPERATURE_TARGET are read-only, and the register is package-scoped, so every CPU of the package reads the same value.
The temperature reported to userspace does not change.
Use the existing rdmsrq_on_cpu() interface and struct msr in show_temp() so the subsequent timestamp fix applies without changes. Read the validity bit and temperature from the same low word as before.
Stable-dep-of: 9a6aa085c94c ("hwmon: (coretemp) Fix 32-bit jiffies wraparound in show_temp()")
--- drivers/hwmon/coretemp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/hwmon/coretemp.c +5 -5
@@ -392,24 +392,24 @@ static ssize_t show_ttarget(struct device *dev,static ssize_t show_temp (struct device *dev,struct device_attribute *devattr,char *buf) { -u32 eax, edx; +struct msr val; struct temp_data *tdata = container_of(devattr, struct temp_data, sd_attrs[ATTR_TEMP]);int tjmax, temp;bool valid;mutex_lock (&tdata->update_lock); - tjmax =get_tjmax (tdata, dev);/* Check whether the time interval has elapsed */ if (time_after (jiffies, tdata->last_updated +HZ )) { -rdmsr_on_cpu (tdata->cpu, tdata->status_reg, &eax, &edx); + tjmax =get_tjmax (tdata, dev); +rdmsrq_on_cpu (tdata->cpu, tdata->status_reg, &val.q);/* * Bit 31 indicates whether the reading is valid. Some CPUs * clear it while the temperature is too low to be measured. * Such a reading is not a temperature. Do not report it. */ - tdata->temp_valid = (eax >>31 ) &1 ; - tdata->temp = tjmax - ((eax >>16 ) &0xff ) *1000 ; + tdata->temp_valid = (val.l >>31 ) &1 ; + tdata->temp = tjmax - ((val.l >>16 ) &0xff ) *1000 ; tdata->last_updated = jiffies; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 83/2151 hwmon: (coretemp) Fix 32-bit jiffies wraparound in show_temp()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 9a6aa085c94c7f2817c4d50a7264e6fb51286f40 ]
show_temp() rate-limits MSR reads by storing tdata->last_updated as an unsigned long and comparing it against jiffies using time_after(jiffies, tdata->last_updated + HZ).
time_after() relies on signed long subtraction, which only produces the expected result while the two timestamps are within LONG_MAX jiffies of each other. On 32-bit kernels, if tempX_input is not read for more than LONG_MAX jiffies (~24.85 days at HZ=1000), the signed difference flips sign and time_after() evaluates to false. Because tdata->last_updated is only refreshed when time_after() succeeds, subsequent reads remain blocked from refreshing for another ~24.85 days until jiffies wraps past tdata->last_updated + HZ again, returning either a stale cached temperature or -ENODATA if the sensor had never been read since initialization.
Store tdata->last_updated as a u64 and use get_jiffies_64() with time_after64(), which does not wrap in any practical uptime.
--- drivers/hwmon/coretemp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/hwmon/coretemp.c +5 -8
@@ -77,7 +77,7 @@ struct temp_data {int temp;bool temp_valid;int tjmax; -unsigned long last_updated; +u64 last_updated;unsigned int cpu;int index;u32 cpu_core_id;
@@ -400,7 +400,7 @@ static ssize_t show_temp(struct device *dev,mutex_lock (&tdata->update_lock);/* Check whether the time interval has elapsed */ -if (time_after (jiffies, tdata->last_updated +HZ )) { +if (time_after64 (get_jiffies_64 (), tdata->last_updated +HZ )) { tjmax =get_tjmax (tdata, dev);rdmsrq_on_cpu (tdata->cpu, tdata->status_reg, &val.q);/*
@@ -410,7 +410,7 @@ static ssize_t show_temp(struct device *dev,*/ tdata->temp_valid = (val.l >>31 ) &1 ; tdata->temp = tjmax - ((val.l >>16 ) &0xff ) *1000 ; - tdata->last_updated = jiffies; + tdata->last_updated =get_jiffies_64 (); } valid = tdata->temp_valid;
@@ -522,11 +522,8 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) tdata->cpu = cpu; tdata->cpu_core_id =topology_core_id (cpu); tdata->attr_size =MAX_CORE_ATTRS ; -/* -* A zero timestamp does not look stale on 32-bit, where jiffies -* starts just short of wrapping. Backdate it instead. -*/ - tdata->last_updated = jiffies -HZ -1 ; +/* Backdate to force a refresh on the first read */ + tdata->last_updated =get_jiffies_64 () -HZ -1 ;mutex_init (&tdata->update_lock);return tdata; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 84/2151 hwmon: (tmp108) Fix initial conversion delay and wait until ready
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 7cd60538073e465310c94b2a2f0ea8d2f03768ef ]
In tmp108_common_probe(), the driver only adds the 30 ms conversion delay (TMP108_CONVERSION_TIME_MS) to ready_time if the sensor was previously in TMP108_MODE_SHUTDOWN. However, the TMP108 hardware defaults to continuous conversion mode (TMP108_MODE_CONTINUOUS) upon power-on reset, including immediately after enabling the vcc supply regulator during probe, while the temperature register retains its power-on reset value of 0x0000 (0°C) until the first conversion completes. Because the initial mode is not shutdown, the delay is bypassed and early reads via thermal zone registration or sysfs before the first conversion finishes return an uninitialized 0°C reading.
In addition, returning -EAGAIN from tmp108_read() while waiting for a conversion to complete after probe or resume can trigger an unnecessary tight retry loop in callers or fail initial reads.
Unconditionally set ready_time to TMP108_CONVERSION_TIME_MS ahead in tmp108_common_probe(), track ready_time as ktime_t, and wait for the remaining conversion time in tmp108_read() using usleep_range() instead of returning -EAGAIN.
--- drivers/hwmon/tmp108.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/hwmon/tmp108.c +11 -15
@@ -14,7 +14,7 @@#include <linux/i2c.h> #include <linux/i3c/device.h> #include <linux/init.h> -#include <linux/jiffies.h> +#include <linux/ktime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/slab.h>
@@ -74,7 +74,7 @@struct tmp108 {struct regmap *regmap;u16 orig_config; -u64 ready_time; +ktime_t ready_time; };/* convert 12-bit TMP108 register value to milliCelsius */
@@ -95,6 +95,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,struct tmp108 *tmp108 =dev_get_drvdata (dev);unsigned int regval;int err, hyst; +s64 delay;if (type == hwmon_chip) {if (attr == hwmon_chip_update_interval) {
@@ -124,12 +125,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input: -/* Is it too early to return a conversion ? */ -if (time_before64 (get_jiffies_64 (), tmp108->ready_time)) { -dev_dbg (dev,"%s: Conversion not ready yet..\n" , - __func__); -return -EAGAIN ; - } +/* Wait if it is too early to return a conversion */ + delay =ktime_us_delta (tmp108->ready_time,ktime_get ()); +if (delay >0 ) +usleep_range (delay, delay +1000 ); err =regmap_read (tmp108->regmap,TMP108_REG_TEMP , ®val);if (err <0 )return err;
@@ -362,11 +361,8 @@ static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char *return err; } - tmp108->ready_time =get_jiffies_64 (); -if ((tmp108->orig_config &TMP108_CONF_MODE_MASK ) == -TMP108_MODE_SHUTDOWN ) - tmp108->ready_time += -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS ); err =devm_add_action_or_reset (dev, tmp108_restore_config, tmp108);if (err) {
@@ -413,8 +409,8 @@ static int tmp108_resume(struct device *dev) err =regmap_update_bits (tmp108->regmap,TMP108_REG_CONF ,TMP108_CONF_MODE_MASK ,TMP108_MODE_CONTINUOUS ); - tmp108->ready_time =get_jiffies_64 () + -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 85/2151 drm/amdgpu: dont walk the CS chunks when allocating them failed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit ade92d50aad6799a5a9d7e73cd1604fd0576e656 ]
amdgpu_cs_pass1() sets p->nchunks before allocating p->chunks, and the allocation failure path skips resetting it. amdgpu_cs_parser_fini() then frees the kdata of nchunks chunks from a NULL array. On navi48 with the chunk array allocation failed through failslab:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:amdgpu_cs_parser_fini+0x35d/0x710 [amdgpu] amdgpu_cs_ioctl+0xcae/0x7a20 [amdgpu] drm_ioctl_kernel+0x180/0x320 [drm]
Set nchunks once the array exists.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -2
@@ -219,13 +219,14 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,if (IS_ERR (chunk_array))return PTR_ERR (chunk_array); - p->nchunks = cs->in.num_chunks; - p->chunks =kvmalloc_array (p->nchunks,sizeof (struct amdgpu_cs_chunk ), +/* parser_fini() walks nchunks chunks, set it once they exist */ + p->chunks =kvmalloc_array (cs->in.num_chunks,sizeof (struct amdgpu_cs_chunk ),GFP_KERNEL );if (!p->chunks) { ret = -ENOMEM ; goto free_chunk; } + p->nchunks = cs->in.num_chunks;for (i =0 ; i < p->nchunks; i++) {struct drm_amdgpu_cs_chunk __user *chunk_ptr =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 86/2151 mm/vma: avoid losing atomic VMA flags when setting sticky VMA flags
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit c386d799f423685952138cab8d89f0331825bdee ]
vma_merge_existing_range() merges an existing VMA (middle) when its attributes have changed to match those of one or both adjacent VMAs.
Sticky flags are propagated if they are set in any of the merged VMAs. They are initialised from vmg->vma_flags, which is assumed to contain middle's sticky flags when the function is invoked.
However, the VMA write lock is not held for middle when they are first populated, so concurrent updates to atomic VMA flags may occur, which will be lost upon merge.
This can result in fork failing to propagate guard region markers and (if file-backed) THP collapse discarding them.
Resolve this by propagating the sticky flags after middle is locked.
Make life easier by factoring this into propagate_sticky_flags(), which treats vmg->vma_flags as its base (in case any sticky flags are set there), updating it as sticky flags are accumulated from merged VMAs.
Also update vma_expand() to use propagate_sticky_flags() so all merge paths utilise it.
propagate_sticky_flags() also asserts that the VMA write lock is held for the VMA whose sticky flags are being read, with a comment explaining why.
Another means by which atomic VMA flags can fail to be observed is when the merge is finalised in commit_merge().
rmap locks are dropped in vma_complete() before the sticky flags are written, meaning an rmap walker can observe the VMA without sticky flags set, which can also result in retract_page_tables() discarding guard markers.
Resolve this by assigning the sticky flags before dropping rmap locks, factored into commit_sticky_flags() with a write assert on the VMA being written to.
Also remove the vma_set_flags_mask() invocation at the end of vma_merge_existing_range() as this was introduced by commit 64212ba02e66 ("mm: implement sticky VMA flags") to propagate sticky flags, which is now redundant with the introduction of commit_sticky_flags().
The vma_set_flags_mask() invocation at the end of vma_expand() setting sticky flags only is also removed for the same reason.
Also update vma_merge_existing_range()'s comment to reflect the fact that vmg->vma_flags gets updated.
Finally, update the userland VMA tests to reflect a previously missed const-ification in vma_assert_write_locked() which would otherwise cause a warning when building them.
--- mm/vma.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
mm/vma.c +19 -14
@@ -756,6 +756,9 @@ static int commit_merge(struct vma_merge_struct *vmg)return -ENOMEM ;vma_prepare (&vp); +/* Must be made visible before vma_complete() for rmap walkers. */ +vma_assert_write_locked (vmg->target); +vm_flags_set (vmg->target, vmg->vm_flags &VM_STICKY );/* * THP pages may need to do additional splits if we increase * middle->vm_start.
@@ -794,8 +797,8 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma)* merge. * * As part of this operation, if a merge occurs, the @vmg object will have its -* vma, start, end, and pgoff fields modified to execute the merge. Subsequent -* calls to this function should reset these fields. +* vma, start, end, pgoff and vm_flags fields modified to execute the merge. +* Subsequent calls to this function should reset these fields. * * Returns: The merged VMA if merge succeeds, or NULL otherwise. *
@@ -809,7 +812,6 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma)static __must_check struct vm_area_struct *vma_merge_existing_range (struct vma_merge_struct *vmg) { -vm_flags_t sticky_flags = vmg->vm_flags &VM_STICKY ;struct vm_area_struct *middle = vmg->middle;struct vm_area_struct *prev = vmg->prev;struct vm_area_struct *next;
@@ -904,17 +906,22 @@ static __must_check struct vm_area_struct *vma_merge_existing_range(/* No matter what happens, we will be adjusting middle. */ vma_start_write (middle); +/* Write lock prevents concurrent atomic VMA flag updates. */ +vma_assert_write_locked (middle); + vmg->vm_flags |= middle->vm_flags &VM_STICKY ;if (merge_right) {vma_start_write (next); vmg->target = next; - sticky_flags |= (next->vm_flags &VM_STICKY ); +vma_assert_write_locked (next); + vmg->vm_flags |= next->vm_flags &VM_STICKY ; }if (merge_left) {vma_start_write (prev); vmg->target = prev; - sticky_flags |= (prev->vm_flags &VM_STICKY ); +vma_assert_write_locked (prev); + vmg->vm_flags |= prev->vm_flags &VM_STICKY ; }if (merge_both) {
@@ -984,7 +991,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range(if (err ||commit_merge (vmg)) goto abort; -vm_flags_set (vmg->target, sticky_flags);khugepaged_enter_vma (vmg->target, vmg->vm_flags); vmg->state =VMA_MERGE_SUCCESS ;return vmg->target;
@@ -1176,20 +1182,14 @@ int vma_expand(struct vma_merge_struct *vmg)struct vm_area_struct *target = vmg->target;struct vm_area_struct *next = vmg->next;int ret =0 ; -vm_flags_t sticky_flags; - - sticky_flags = vmg->vm_flags &VM_STICKY ; - sticky_flags |= target->vm_flags &VM_STICKY ;VM_WARN_ON_VMG (!target, vmg);mmap_assert_write_locked (vmg->mm);vma_start_write (target); -if (next && target != next && vmg->end == next->vm_end) { - sticky_flags |= next->vm_flags &VM_STICKY ; +if (next && target != next && vmg->end == next->vm_end) remove_next = true; - }/* We must have a target. */ VM_WARN_ON_VMG (!target, vmg);
@@ -1202,6 +1202,9 @@ int vma_expand(struct vma_merge_struct *vmg)VM_WARN_ON_VMG (target->vm_start < vmg->start || target->vm_end > vmg->end, vmg); +vma_assert_write_locked (target); + vmg->vm_flags |= target->vm_flags &VM_STICKY ; +/* * If we are removing the next VMA or copying from a VMA * (e.g. mremap()'ing), we must propagate anon_vma state.
@@ -1219,11 +1222,13 @@ int vma_expand(struct vma_merge_struct *vmg)if (remove_next) {vma_start_write (next); vmg->__remove_next = true; + +vma_assert_write_locked (next); + vmg->vm_flags |= next->vm_flags &VM_STICKY ; }if (commit_merge (vmg)) goto nomem; -vm_flags_set (target, sticky_flags);return 0 ; nomem:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 87/2151 mm/vma: dont leak the charge for stack growth
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit b1ee87802111156e27557e82acc31fa7dfc76e2a ]
acct_stack_growth() charges stack expansion even without VM_ACCOUNT. This can happen for read-only or MAP_NORESERVE mappings created with MAP_GROWSDOWN. Unmapping these VMAs does not release the charge, leaking Committed_AS.
Only check and charge growth for VM_ACCOUNT VMAs, matching mremap(). Unaccounted growth skips the overcommit check while remaining subject to the other stack-growth limits.
--- mm/vma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/vma.c +2 -1
@@ -3089,7 +3089,8 @@ static int acct_stack_growth(struct vm_area_struct *vma,* Overcommit.. This must be the final test, as it will * update security statistics. */ -if (security_vm_enough_memory_mm (mm, grow)) +if ((vma->vm_flags &VM_ACCOUNT ) && +security_vm_enough_memory_mm (mm, grow))return -ENOMEM ;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 88/2151 sched: Re-arrange the {EN,DE}QUEUE flags
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
[ Upstream commit 376f8963bbda5fee838eb1823b07562368104024 ]
Ensure the matched flags are in the low word while the unmatched flags go into the second word.
Stable-dep-of: c282051fc2ca ("sched/fair: Clear throttle state when leaving the fair class")
--- kernel/sched/sched.h | 45 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
kernel/sched/sched.h +24 -21
@@ -2377,27 +2377,30 @@ extern const u32 sched_prio_to_wmult[40];* */ -#define DEQUEUE_SLEEP 0x01/* Matches ENQUEUE_WAKEUP */ -#define DEQUEUE_SAVE 0x02/* Matches ENQUEUE_RESTORE */ -#define DEQUEUE_MOVE 0x04/* Matches ENQUEUE_MOVE */ -#define DEQUEUE_NOCLOCK 0x08/* Matches ENQUEUE_NOCLOCK */ -#define DEQUEUE_SPECIAL 0x10 -#define DEQUEUE_MIGRATING 0x100/* Matches ENQUEUE_MIGRATING */ -#define DEQUEUE_DELAYED 0x200/* Matches ENQUEUE_DELAYED */ -#define DEQUEUE_THROTTLE 0x800 - -#define ENQUEUE_WAKEUP 0x01 -#define ENQUEUE_RESTORE 0x02 -#define ENQUEUE_MOVE 0x04 -#define ENQUEUE_NOCLOCK 0x08 - -#define ENQUEUE_HEAD 0x10 -#define ENQUEUE_REPLENISH 0x20 -#define ENQUEUE_MIGRATED 0x40 -#define ENQUEUE_INITIAL 0x80 -#define ENQUEUE_MIGRATING 0x100 -#define ENQUEUE_DELAYED 0x200 -#define ENQUEUE_RQ_SELECTED 0x400 +#define DEQUEUE_SLEEP 0x0001/* Matches ENQUEUE_WAKEUP */ +#define DEQUEUE_SAVE 0x0002/* Matches ENQUEUE_RESTORE */ +#define DEQUEUE_MOVE 0x0004/* Matches ENQUEUE_MOVE */ +#define DEQUEUE_NOCLOCK 0x0008/* Matches ENQUEUE_NOCLOCK */ + +#define DEQUEUE_MIGRATING 0x0010/* Matches ENQUEUE_MIGRATING */ +#define DEQUEUE_DELAYED 0x0020/* Matches ENQUEUE_DELAYED */ + +#define DEQUEUE_SPECIAL 0x00010000 +#define DEQUEUE_THROTTLE 0x00020000 + +#define ENQUEUE_WAKEUP 0x0001 +#define ENQUEUE_RESTORE 0x0002 +#define ENQUEUE_MOVE 0x0004 +#define ENQUEUE_NOCLOCK 0x0008 + +#define ENQUEUE_MIGRATING 0x0010 +#define ENQUEUE_DELAYED 0x0020 + +#define ENQUEUE_HEAD 0x00010000 +#define ENQUEUE_REPLENISH 0x00020000 +#define ENQUEUE_MIGRATED 0x00040000 +#define ENQUEUE_INITIAL 0x00080000 +#define ENQUEUE_RQ_SELECTED 0x00100000#define RETRY_TASK ((void *)-1UL)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 89/2151 sched: Fold sched_class::switch{ing,ed}_{to,from}() into the change pattern
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
[ Upstream commit 637b0682821b144d5993211cf0a768b322138a69 ]
Add {DE,EN}QUEUE_CLASS and fold the sched_class::switch* methods into the change pattern. This completes and makes the pattern more symmetric.
This changes the order of callbacks slightly:
OLD NEW
| | switching_from() dequeue_task(); | dequeue_task() put_prev_task(); | put_prev_task() | switched_from() | ... change task ... | ... change task ... | switching_to(); | switching_to() enqueue_task(); | enqueue_task() set_next_task(); | set_next_task() prev_class->switched_from() | switched_to() | switched_to() |
Notably, it moves the switched_from() callback right after the dequeue/put. Existing implementations don't appear to be affected by this change in location -- specifically the task isn't enqueued on the class in question in either location.
Make (CLASS)^(SAVE|MOVE), because there is nothing to save-restore when changing scheduling classes.
Stable-dep-of: c282051fc2ca ("sched/fair: Clear throttle state when leaving the fair class")
--- kernel/sched/core.c | 51 +++++++++++++++++----------------------- kernel/sched/ext.c | 22 ++++++++++++----- kernel/sched/idle.c | 4 ++-- kernel/sched/rt.c | 2 +- kernel/sched/sched.h | 22 +++++++---------- kernel/sched/stop_task.c | 4 ++-- kernel/sched/syscalls.c | 7 ++++-- 7 files changed, 55 insertions(+), 57 deletions(-)
kernel/sched/core.c +21 -30
@@ -2185,34 +2185,9 @@ inline int task_curr(const struct task_struct *p)return cpu_curr (task_cpu (p)) == p; } -/* -* ->switching_to() is called with the pi_lock and rq_lock held and must not -* mess with locking. -*/ -void check_class_changing (struct rq *rq,struct task_struct *p, -const struct sched_class *prev_class) -{ -if (prev_class != p->sched_class && p->sched_class->switching_to) - p->sched_class->switching_to (rq, p); -} - -/* -* switched_from, switched_to and prio_changed must _NOT_ drop rq->lock, -* use the balance_callback list if you want balancing. -* -* this means any call to check_class_changed() must be followed by a call to -* balance_callback(). -*/ -void check_class_changed (struct rq *rq,struct task_struct *p, -const struct sched_class *prev_class, -int oldprio) +void check_prio_changed (struct rq *rq,struct task_struct *p,int oldprio) { -if (prev_class != p->sched_class) { -if (prev_class->switched_from) - prev_class->switched_from (rq, p); - - p->sched_class->switched_to (rq, p); - }else if (oldprio != p->prio ||dl_task (p)) +if (oldprio != p->prio ||dl_task (p)) p->sched_class->prio_changed (rq, p, oldprio); }
@@ -7413,6 +7388,9 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) prev_class = p->sched_class; next_class =__setscheduler_class (p->policy, prio); +if (prev_class != next_class) + queue_flag |=DEQUEUE_CLASS ; +if (prev_class != next_class && p->se.sched_delayed)dequeue_task (rq, p,DEQUEUE_SLEEP |DEQUEUE_DELAYED |DEQUEUE_NOCLOCK );
@@ -7449,11 +7427,10 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) p->sched_class = next_class; p->prio = prio; - -check_class_changing (rq, p, prev_class); } -check_class_changed (rq, p, prev_class, oldprio); +if (!(queue_flag &DEQUEUE_CLASS )) +check_prio_changed (rq, p, oldprio); out_unlock:/* Avoid rq from going away on us: */ preempt_disable ();
@@ -10892,6 +10869,11 @@ struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned intlockdep_assert_rq_held (rq); +if (flags &DEQUEUE_CLASS ) { +if (p->sched_class->switching_from) + p->sched_class->switching_from (rq, p); + } + *ctx = (struct sched_change_ctx ){ .p = p, .flags = flags,
@@ -10904,6 +10886,9 @@ struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned intif (ctx->running)put_prev_task (rq, p); +if ((flags &DEQUEUE_CLASS ) && p->sched_class->switched_from) + p->sched_class->switched_from (rq, p); +return ctx; }
@@ -10914,8 +10899,14 @@ void sched_change_end(struct sched_change_ctx *ctx)lockdep_assert_rq_held (rq); +if ((ctx->flags &ENQUEUE_CLASS ) && p->sched_class->switching_to) + p->sched_class->switching_to (rq, p); +if (ctx->queued)enqueue_task (rq, p, ctx->flags |ENQUEUE_NOCLOCK );if (ctx->running)set_next_task (rq, p); + +if ((ctx->flags &ENQUEUE_CLASS ) && p->sched_class->switched_to) + p->sched_class->switched_to (rq, p); }
kernel/sched/ext.c +16 -6
@@ -4079,20 +4079,25 @@ static void scx_root_disable(struct scx_sched *sch)scx_task_iter_start (&sti);while ((p =scx_task_iter_next_locked (&sti))) { +unsigned int queue_flags =DEQUEUE_SAVE |DEQUEUE_MOVE |DEQUEUE_NOCLOCK ;const struct sched_class *old_class = p->sched_class;const struct sched_class *new_class =scx_setscheduler_class (p);update_rq_clock (task_rq (p)); +if (old_class != new_class) + queue_flags |=DEQUEUE_CLASS ; +if (old_class != new_class && p->se.sched_delayed)dequeue_task (task_rq (p), p,DEQUEUE_SLEEP |DEQUEUE_DELAYED |DEQUEUE_NOCLOCK ); - scoped_guard (sched_change, p, DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK) { + scoped_guard (sched_change, p, queue_flags) { p->sched_class = new_class; -check_class_changing (task_rq (p), p, old_class); } -check_class_changed (task_rq (p), p, old_class, p->prio); +if (!(queue_flags &DEQUEUE_CLASS )) +check_prio_changed (task_rq (p), p, p->prio); +scx_exit_task (p); }scx_task_iter_stop (&sti);
@@ -4932,6 +4937,7 @@ static void scx_root_enable_workfn(struct kthread_work *work)percpu_down_write (&scx_fork_rwsem);scx_task_iter_start (&sti);while ((p =scx_task_iter_next_locked (&sti))) { +unsigned int queue_flags =DEQUEUE_SAVE |DEQUEUE_MOVE |DEQUEUE_NOCLOCK ;const struct sched_class *old_class = p->sched_class;const struct sched_class *new_class =scx_setscheduler_class (p);
@@ -4940,16 +4946,20 @@ static void scx_root_enable_workfn(struct kthread_work *work)update_rq_clock (task_rq (p)); +if (old_class != new_class) + queue_flags |=DEQUEUE_CLASS ; +if (old_class != new_class && p->se.sched_delayed)dequeue_task (task_rq (p), p,DEQUEUE_SLEEP |DEQUEUE_DELAYED |DEQUEUE_NOCLOCK ); - scoped_guard (sched_change, p, DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK) { + scoped_guard (sched_change, p, queue_flags) { p->scx.slice =SCX_SLICE_DFL ; p->sched_class = new_class; -check_class_changing (task_rq (p), p, old_class); } -check_class_changed (task_rq (p), p, old_class, p->prio); +if (!(queue_flags &DEQUEUE_CLASS )) +check_prio_changed (task_rq (p), p, p->prio); +put_task_struct (p); }scx_task_iter_stop (&sti);
kernel/sched/idle.c +2 -2
@@ -525,7 +525,7 @@ static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued) { } -static void switched_to_idle (struct rq *rq,struct task_struct *p) +static void switching_to_idle (struct rq *rq,struct task_struct *p) {BUG (); }
@@ -563,6 +563,6 @@ DEFINE_SCHED_CLASS(idle) = { .task_tick = task_tick_idle, .prio_changed = prio_changed_idle, - .switched_to = switched_to_idle, + .switching_to = switching_to_idle, .update_curr = update_curr_idle, };
kernel/sched/rt.c +1 -1
@@ -2609,8 +2609,8 @@ DEFINE_SCHED_CLASS(rt) = { .get_rr_interval = get_rr_interval_rt, - .prio_changed = prio_changed_rt, .switched_to = switched_to_rt, + .prio_changed = prio_changed_rt, .update_curr = update_curr_rt,
kernel/sched/sched.h +8 -14
@@ -21,7 +21,6 @@#include <linux/sched/task_flags.h> #include <linux/sched/task.h> #include <linux/sched/topology.h> -#include <linux/atomic.h> #include <linux/bitmap.h> #include <linux/bug.h>
@@ -2384,6 +2383,7 @@ extern const u32 sched_prio_to_wmult[40];#define DEQUEUE_MIGRATING 0x0010/* Matches ENQUEUE_MIGRATING */ #define DEQUEUE_DELAYED 0x0020/* Matches ENQUEUE_DELAYED */ +#define DEQUEUE_CLASS 0x0040/* Matches ENQUEUE_CLASS */ #define DEQUEUE_SPECIAL 0x00010000#define DEQUEUE_THROTTLE 0x00020000
@@ -2395,6 +2395,7 @@ extern const u32 sched_prio_to_wmult[40];#define ENQUEUE_MIGRATING 0x0010#define ENQUEUE_DELAYED 0x0020 +#define ENQUEUE_CLASS 0x0040#define ENQUEUE_HEAD 0x00010000#define ENQUEUE_REPLENISH 0x00020000
@@ -2458,14 +2459,11 @@ struct sched_class {void (*task_fork)(struct task_struct *p);void (*task_dead)(struct task_struct *p); -/* -* The switched_from() call is allowed to drop rq->lock, therefore we -* cannot assume the switched_from/switched_to pair is serialized by -* rq->lock. They are however serialized by p->pi_lock. -*/ -void (*switching_to) (struct rq *this_rq,struct task_struct *task); -void (*switched_from)(struct rq *this_rq,struct task_struct *task); -void (*switched_to) (struct rq *this_rq,struct task_struct *task); +void (*switching_from)(struct rq *this_rq,struct task_struct *task); +void (*switched_from) (struct rq *this_rq,struct task_struct *task); +void (*switching_to) (struct rq *this_rq,struct task_struct *task); +void (*switched_to) (struct rq *this_rq,struct task_struct *task); +void (*reweight_task)(struct rq *this_rq,struct task_struct *task,const struct load_weight *lw); void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
@@ -3892,11 +3890,7 @@ extern void set_load_weight(struct task_struct *p, bool update_load);extern void enqueue_task (struct rq *rq,struct task_struct *p,int flags);extern bool dequeue_task (struct rq *rq,struct task_struct *p,int flags); -extern void check_class_changing (struct rq *rq,struct task_struct *p, -const struct sched_class *prev_class); -extern void check_class_changed (struct rq *rq,struct task_struct *p, -const struct sched_class *prev_class, -int oldprio); +extern void check_prio_changed (struct rq *rq,struct task_struct *p,int oldprio);extern struct balance_callback *splice_balance_callbacks (struct rq *rq);extern void balance_callbacks (struct rq *rq,struct balance_callback *head);
kernel/sched/stop_task.c +2 -2
@@ -75,7 +75,7 @@ static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued) { } -static void switched_to_stop (struct rq *rq,struct task_struct *p) +static void switching_to_stop (struct rq *rq,struct task_struct *p) {BUG ();/* its impossible to change to this class */ }
@@ -112,6 +112,6 @@ DEFINE_SCHED_CLASS(stop) = { .task_tick = task_tick_stop, .prio_changed = prio_changed_stop, - .switched_to = switched_to_stop, + .switching_to = switching_to_stop, .update_curr = update_curr_stop, };
kernel/sched/syscalls.c +5 -2
@@ -713,6 +713,9 @@ int __sched_setscheduler(struct task_struct *p, prev_class = p->sched_class; next_class =__setscheduler_class (policy, newprio); +if (prev_class != next_class) + queue_flags |=DEQUEUE_CLASS ; +if (prev_class != next_class && p->se.sched_delayed)dequeue_task (rq, p,DEQUEUE_SLEEP |DEQUEUE_DELAYED |DEQUEUE_NOCLOCK );
@@ -725,7 +728,6 @@ int __sched_setscheduler(struct task_struct *p,__setscheduler_dl_pi (newprio, policy, p, scope); }__setscheduler_uclamp (p, attr); -check_class_changing (rq, p, prev_class);if (scope->queued) {/*
@@ -737,7 +739,8 @@ int __sched_setscheduler(struct task_struct *p, } } -check_class_changed (rq, p, prev_class, oldprio); +if (!(queue_flags &DEQUEUE_CLASS )) +check_prio_changed (rq, p, oldprio);/* Avoid rq from going away on us: */ preempt_disable ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 90/2151 sched/fair: Clear throttle state when leaving the fair class
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit c282051fc2cae2ea54770ebe435dbea090272c25 ]
Task-based CFS bandwidth throttling removes a task's fair sched_entity while the scheduler core still considers the task queued. p->throttled carries the fair-specific state across dequeue/enqueue operations.
DEQUEUE_CLASS removes the task from cfs_rq->throttled_limbo_list but retains the bit. If the last finite CFS quota is disabled while the task runs in another class, it is absent from the unthrottle walk and the bit survives.
Returning to fair while cfs_bandwidth_used() is false then performs a real fair enqueue with p->throttled still set.
After bandwidth is re-enabled, a class-change dequeue treats the stale bit as limbo state and skips __dequeue_task(). p->se.on_rq therefore remains set, and put_prev_task_fair() places the entity in the EEVDF tree while the task moves to RT. On exit, the fair picker can select the TASK_DEAD task. __schedule() then returns to do_task_dead(), which hits BUG().
Keep p->throttled across migrations and group moves, but clear it on DEQUEUE_CLASS because fair-specific state must not outlive fair-class membership. A later return to fair uses the normal enqueue path. That path still respects a throttled cfs_rq.
A KASAN, LOCKDEP and DEBUG_LIST v7.3 kernel reproduced the do_task_dead() BUG in 3/3 root and 3/3 delegated uid-1000 runs with CapPrm=CapEff=0 and RLIMIT_RTPRIO=1. The fix passed both matrices plus a 3/3 class-switch control with bandwidth continuously enabled, without a scheduler warning, KASAN report, lockdep splat or crash.
An AI coding assistant analyzed the state mismatch and drafted the initial reproducer, fix candidate and this changelog. The source paths, trigger, controls and results were rechecked against the cited revisions.
--- kernel/sched/fair.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
@@ -5988,8 +5988,8 @@ static void dequeue_throttled_task(struct task_struct *p, int flags)WARN_ON_ONCE (p->se.on_rq);list_del_init (&p->throttle_node); -/* task blocked after throttled */ -if (flags &DEQUEUE_SLEEP ) { +/* Task blocked after throttling or is leaving the fair class: */ +if (flags & (DEQUEUE_SLEEP |DEQUEUE_CLASS )) { p->throttled = false;return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 91/2151 sched_ext: Skip ops.set_weight() for disabled tasks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuba Piecuch <[email protected]>
[ Upstream commit 0e2f4ab68a89fad42e0f5a9ff4b740738e7aa1d6 ]
When switching a task's sched_class away from sched_ext, we get the following sequence of events in __sched_setscheduler():
sched_change_begin()
switched_from_scx()
scx_disable_task(p)
ops.disable(p)__setscheduler_params()
set_load_weight()
reweight_task_scx(p)
ops.set_weight(p)p->sched_class = next_class;sched_change_end()
...
Notably, ops.set_weight() is called _after_ ops.disable(). This violates the expected semantics of the callbacks, the expectation being that ops.disable() can only be followed by ops.exit_task() or ops.enable().
Skipping the weight adjustment for disabled tasks should be harmless since the weight will be recalculated in scx_enable_task() if the task ever rejoins SCX.
--- kernel/sched/ext.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
kernel/sched/ext.c +11 -0
@@ -3109,6 +3109,17 @@ static void reweight_task_scx(struct rq *rq, struct task_struct *p,lockdep_assert_rq_held (task_rq (p)); +/* +* When switching sched_class away from SCX, reweight_task_scx() +* is called _after_ scx_disable_task(). Skip calling ops.set_weight() +* since the BPF scheduler may have already forgotten the task in +* ops.disable(). +* p->scx.weight will be recalculated in scx_enable_task() if the task +* ever returns to SCX class. +*/ +if (scx_get_task_state (p) !=SCX_TASK_ENABLED ) +return ; + p->scx.weight =sched_weight_to_cgroup (scale_load_down (lw->weight));if (SCX_HAS_OP (sch, set_weight)) SCX_CALL_OP_TASK(sch, SCX_KF_REST, set_weight, rq,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 92/2151 mm/madvise: preserve VMA_SOFTDIRTY_BIT when changing anonymous names
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 652f15be3c11415725694ccea317c51e35c0b582 ]
When changing the anonymous VMA name, madvise_update_vma() calls vma_modify_name() to possibly merge with adjacent VMAs. We don't call vma_modify_flags() and consequently don't obtain the new VMA flags.
Later in the function we update the VMA flags to the stale new_vma_flags we obtained before. This can result in us losing the VMA_SOFTDIRTY_BIT flag set on a VMA we just merged with.
There is no need to update the VMA flags at all, so just exit early. This skips calling khugepaged_enter_vma(), but since the flags didn't change this is fine.
--- mm/madvise.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/madvise.c +3 -3
@@ -176,6 +176,9 @@ static int madvise_update_vma(vm_flags_t new_flags,/* vm_flags is protected by the mmap_lock held in write mode. */ vma_start_write (vma); +if (set_new_anon_name) +return replace_anon_vma_name (vma, anon_name); +vm_flags_reset (vma, new_flags);/* * If the vma become good for khugepaged to scan,
@@ -185,9 +188,6 @@ static int madvise_update_vma(vm_flags_t new_flags,if (new_flags &VM_HUGEPAGE )khugepaged_enter_vma (vma, new_flags); -if (set_new_anon_name) -return replace_anon_vma_name (vma, anon_name); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 93/2151 quota: initialize dquot cache before mounting rootfs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: YouYou Yu <[email protected]>
[ Upstream commit e21a6f39aa6d0336ffbf5f34e5fa20ff8de36773 ]
On some systems, a tmpfs backed rootfs is extensively used throughout system's lifecycle. tmpfs quotas are needed to limit per user rootfs usage. However, booting with CONFIG_TMPFS_QUOTA=y, an initramfs, no root= and "initramfs_options=usrquota" panics at boot:
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:dqget+0x1ac/0x490 Call Trace: __dquot_initialize dquot_initialize shmem_get_inode shmem_fill_super ... mnt_init vfs_caches_init start_kernel
The rootfs is mounted from mnt_init(), but the dquot hash table and cache are only set up later by dquot_init(), an fs_initcall. Creating the root inode of a quota enabled rootfs thus dereferences the NULL dquot_hash in dqget().
Rename dquot_init() to dquot_cache_init() and call it from vfs_caches_init() before mnt_init(). The slab, percpu and early workqueue code it relies on is available there, and the workqueue rescuer and shrinker debugfs entries are set up later by their own subsystems. Keep the sysctl registration in an fs_initcall, as done for the dcache, inode and mount sysctls. This only moves existing allocations earlier in boot.
--- fs/dcache.c | 2 ++ fs/quota/dquot.c | 10 ++++++---- include/linux/quotaops.h | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-)
fs/dcache.c +2 -0
@@ -32,6 +32,7 @@#include <linux/bit_spinlock.h> #include <linux/rculist_bl.h> #include <linux/list_lru.h> +#include <linux/quotaops.h> #include "internal.h" #include "mount.h"
@@ -3288,6 +3289,7 @@ void __init vfs_caches_init(void)inode_init ();files_init ();files_maxfiles_init (); +dquot_cache_init ();mnt_init ();bdev_cache_init ();chrdev_init ();
fs/quota/dquot.c +6 -4
@@ -3019,7 +3019,7 @@ static const struct ctl_table fs_dqstats_table[] = {#endif }; -static int __init dquot_init (void ) +void __init dquot_cache_init (void ) {int i, ret;unsigned long nr_hash, order;
@@ -3027,8 +3027,6 @@ static int __init dquot_init(void)printk (KERN_NOTICE "VFS: Disk quotas %s\n" , __DQUOT_VERSION__); -register_sysctl_init ("fs/quota" , fs_dqstats_table); - dquot_cachep = kmem_cache_create("dquot", sizeof(struct dquot), sizeof(unsigned long) * 4, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
@@ -3070,7 +3068,11 @@ static int __init dquot_init(void) WQ_UNBOUND | WQ_MEM_RECLAIM, WQ_MAX_ACTIVE);if (!quota_unbound_wq)panic ("Cannot create quota_unbound_wq\n" ); +} +static int __init init_fs_dquot_sysctls (void ) +{ +register_sysctl_init ("fs/quota" , fs_dqstats_table);return 0 ; } -fs_initcall (dquot_init); +fs_initcall (init_fs_dquot_sysctls);
include/linux/quotaops.h +5 -0
@@ -40,6 +40,7 @@ void __quota_error(struct super_block *sb, const char *func,/* * declaration of quota_function calls in kernel. */ +void dquot_cache_init (void );int dquot_initialize (struct inode *inode);bool dquot_initialize_needed (struct inode *inode);void dquot_drop (struct inode *inode);
@@ -206,6 +207,10 @@ static inline int sb_has_quota_active(struct super_block *sb, int type)return 0 ; } +static inline void dquot_cache_init (void ) +{ +} +static inline int dquot_initialize (struct inode *inode) {return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 94/2151 ksmbd: let the owner read and change the DACL when no ACE names it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit ffc855fe16afe02b22305111aa68cd8d07360941 ]
smb_check_perm_dacl() refuses the owner when neither its DACL lookup nor the POSIX ACL fallback matches. The owner then cannot read or replace the DACL over SMB. MS-DTYP 2.5.3.2 grants the owner READ_CONTROL and WRITE_DAC unless an OWNER RIGHTS ACE applies.
An empty DACL allows the owner's explicit requests for these rights but refuses MAXIMUM_ALLOWED. smb2_open() uses that check for the maximal access reply (MS-SMB2 3.3.5.9.5), so even a READ_CONTROL open fails when it asks for that reply.
Grant the owner's implicit rights on both paths, for explicit requests and MAXIMUM_ALLOWED, unless an OWNER RIGHTS ACE applies.
--- fs/smb/server/smbacl.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
fs/smb/server/smbacl.c +33 -4
@@ -27,6 +27,9 @@ static const struct smb_sid creator_owner = {/* security id for everyone/world system group */ static const struct smb_sid creator_group = {1 ,1 , {0 ,0 ,0 ,0 ,0 ,3 }, {cpu_to_le32 (1 )} }; +/* security id for owner rights */ +static const struct smb_sid sid_owner_rights = { +1 ,1 , {0 ,0 ,0 ,0 ,0 ,3 }, {cpu_to_le32 (4 )} };/* security id for everyone/world system group */ static const struct smb_sid sid_everyone = {
@@ -1466,6 +1469,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,int i, found =0 ;unsigned int access_bits =0 , denied =0 ;struct smb_ace *others_ace =NULL ; +bool or_ace = false;struct posix_acl_entry *pa_entry;unsigned int sid_type =SIDOWNER ;unsigned short ace_size;
@@ -1498,6 +1502,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, is_owner = uid ==from_kuid (&init_user_ns,vfsuid_into_kuid (vfsuid));if (!pdacl->num_aces) { +unsigned int allowed =0 ; +/* * An empty (present, zero-ACE) DACL grants no access to * anyone except the object owner's implicit READ_CONTROL
@@ -1506,9 +1512,14 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,* not let trailing bytes after a zero-ACE DACL become an * implicit grant. */ -if (!is_owner || - (*pdaccess & ~(FILE_READ_CONTROL_LE |FILE_WRITE_DAC_LE ))) +if (is_owner) + allowed =READ_CONTROL |WRITE_DAC ; +if (*pdaccess &FILE_MAXIMAL_ACCESS_LE ) + requested |= allowed; +if (!allowed || requested & ~allowed) rc = -EACCES ; +else + *pdaccess =cpu_to_le32 (requested); goto err_out; }
@@ -1585,6 +1596,9 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, found =1 ;break ; } +if (!compare_sids (&sid_owner_rights, &ace->sid) && + !(ace->flags &INHERIT_ONLY_ACE )) + or_ace = true;if (!compare_sids (&sid_everyone, &ace->sid) || !compare_sids (&sid_authusers, &ace->sid)) others_ace = ace;
@@ -1629,8 +1643,23 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,if (others_ace) { ace = others_ace; }else { -ksmbd_debug (SMB ,"Can't find corresponding sid\n" ); - rc = -EACCES ; +unsigned int allowed =0 ; + +/* +* No ACE names the owner, who may still read and +* change the DACL unless OWNER RIGHTS applies +* (MS-DTYP 2.5.3.2). +*/ +if (is_owner && !or_ace) + allowed =READ_CONTROL |WRITE_DAC ; +if (*pdaccess &FILE_MAXIMAL_ACCESS_LE ) + requested |= allowed; +if (!allowed || requested & ~allowed) { +ksmbd_debug (SMB ,"Can't find corresponding sid\n" ); + rc = -EACCES ; + goto err_out; + } + *pdaccess =cpu_to_le32 (requested); goto err_out; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 95/2151 mm/userfaultfd: compare exact registration modes before skipping
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 05f64f211a25f7d9771d4fde109aad97174a1cf3 ]
Changing registration from MISSING|WP to WP returns success but leaves MISSING enabled. The no-op check sees that WP is already set and skips the update, so later accesses to missing pages still wait for userspace.
Skip the update only when the current and requested UFFD modes match exactly.
--- mm/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/userfaultfd.c +1 -1
@@ -2077,7 +2077,7 @@ int userfaultfd_register_range(struct userfaultfd_ctx *ctx,* userfaultfd and with the right tracking mode too. */ if (vma->vm_userfaultfd_ctx.ctx == ctx && - (vma->vm_flags & vm_flags) == vm_flags) + (vma->vm_flags & __VM_UFFD_FLAGS) == vm_flags) goto skip;if (vma->vm_start > start)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 96/2151 apparmor: optimize current_label_crit_section() with needput
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
[ Upstream commit 1555a0e2a149cba4578f5270e7fb9efb420b985f ]
The {begin,end}_current_label_crit_section() has the same issue as the {__begin,__end} version. That is the check to see if the label has been updated in the end check forces an unnecessary memory barrier. We can optimize this the same way we do with the {__begin,__end} variant by passing in a local variable that carries the state information from the begin check into the end check.
No functional change.
Stable-dep-of: d30844001360 ("apparmor: fix query_data() output overlapping the lookup key")
--- security/apparmor/af_unix.c | 25 +++++++++------- security/apparmor/apparmorfs.c | 51 +++++++++++++++++++------------- security/apparmor/include/cred.h | 16 +++++----- security/apparmor/lsm.c | 45 +++++++++++++++++----------- security/apparmor/net.c | 5 ++-- 5 files changed, 84 insertions(+), 58 deletions(-)
security/apparmor/af_unix.c +15 -10
@@ -462,13 +462,14 @@ static int aa_unix_label_sk_perm(const struct cred *subj_cred,int aa_unix_sock_perm (const char *op,u32 request,struct socket *sock) {struct aa_label *label; +bool needput;int error; - label =begin_current_label_crit_section (); + label =begin_current_label_crit_section (&needput); error =aa_unix_label_sk_perm (current_cred (), label, op, request, sock->sk,is_unix_fs (sock->sk) ? &unix_sk (sock->sk)->path :NULL ); -end_current_label_crit_section (label); +end_current_label_crit_section (label, needput);return error; }
@@ -489,13 +490,14 @@ int aa_unix_bind_perm(struct socket *sock, struct sockaddr *addr, {struct aa_profile *profile;struct aa_label *label; +bool needput;int error =0 ; error =valid_addr (addr, addrlen);if (error)return error; - label =begin_current_label_crit_section (); + label =begin_current_label_crit_section (&needput);/* fs bind is handled by mknod */ if (!unconfined (label)) {DEFINE_AUDIT_SK (ad,OP_BIND ,current_cred (), sock->sk);
@@ -506,7 +508,7 @@ int aa_unix_bind_perm(struct socket *sock, struct sockaddr *addr, error =fn_for_each_confined (label, profile,profile_bind_perm (profile, sock->sk, &ad)); } -end_current_label_crit_section (label); +end_current_label_crit_section (label, needput);return error; }
@@ -528,9 +530,10 @@ int aa_unix_listen_perm(struct socket *sock, int backlog) {struct aa_profile *profile;struct aa_label *label; +bool needput;int error =0 ; - label =begin_current_label_crit_section (); + label =begin_current_label_crit_section (&needput);if (!unconfined (label)) {DEFINE_AUDIT_SK (ad,OP_LISTEN ,current_cred (), sock->sk);
@@ -538,7 +541,7 @@ int aa_unix_listen_perm(struct socket *sock, int backlog)profile_listen_perm (profile, sock->sk, backlog, &ad)); } -end_current_label_crit_section (label); +end_current_label_crit_section (label, needput);return error; }
@@ -549,16 +552,17 @@ int aa_unix_accept_perm(struct socket *sock, struct socket *newsock) {struct aa_profile *profile;struct aa_label *label; +bool needput;int error =0 ; - label =begin_current_label_crit_section (); + label =begin_current_label_crit_section (&needput);if (!unconfined (label)) {DEFINE_AUDIT_SK (ad,OP_ACCEPT ,current_cred (), sock->sk); error =fn_for_each_confined (label, profile,profile_accept_perm (profile, sock->sk, &ad)); } -end_current_label_crit_section (label); +end_current_label_crit_section (label, needput);return error; }
@@ -582,9 +586,10 @@ int aa_unix_opt_perm(const char *op, u32 request, struct socket *sock, {struct aa_profile *profile;struct aa_label *label; +bool needput;int error =0 ; - label =begin_current_label_crit_section (); + label =begin_current_label_crit_section (&needput);if (!unconfined (label)) {DEFINE_AUDIT_SK (ad, op,current_cred (), sock->sk);
@@ -592,7 +597,7 @@ int aa_unix_opt_perm(const char *op, u32 request, struct socket *sock,profile_opt_perm (profile, request, sock->sk, optname, &ad)); } -end_current_label_crit_section (label); +end_current_label_crit_section (label, needput);return error; }
security/apparmor/apparmorfs.c +31 -20
158 lines not on this page · raw message
security/apparmor/include/cred.h +8 -8
@@ -131,12 +131,14 @@ static inline void __end_current_label_crit_section(struct aa_label *label,/** * end_current_label_crit_section - put a reference found with begin_current_label.. * @label: label reference to put +* @needput: output: bool set by __begin_current_label_crit_section * * Should only be used with a reference obtained with * begin_current_label_crit_section and never used in situations where the * task cred may be updated */ -static inline void end_current_label_crit_section (struct aa_label *label) +static inline void end_current_label_crit_section (struct aa_label *label, +bool needput) {if (label !=aa_current_raw_label ())aa_put_label (label);
@@ -170,24 +172,22 @@ static inline struct aa_label *__begin_current_label_crit_section(bool *needput)/** * begin_current_label_crit_section - current's confining label and update it +* @needput: store whether the label needs to be put when ending crit section * * Returns: up to date confining label or the ns unconfined label (NOT NULL) * -* Not safe to call inside locks -* * The returned reference must be put with end_current_label_crit_section() -* This must NOT be used if the task cred could be updated within the +* This should NOT be used if the task cred could be updated within the * critical section between begin_current_label_crit_section() .. * end_current_label_crit_section() */ -static inline struct aa_label *begin_current_label_crit_section (void ) +static inline struct aa_label *begin_current_label_crit_section (bool *needput) {struct aa_label *label =aa_current_raw_label (); -if (label_is_stale (label)) { - label =aa_get_newest_label (label); + label =__begin_current_label_crit_section (needput); +if (*needput)aa_schedule_stale_label_replacement (); - }return label; }
security/apparmor/lsm.c +27 -18
178 lines not on this page · raw message
security/apparmor/net.c +3 -2
@@ -308,15 +308,16 @@ static int aa_label_sk_perm(const struct cred *subj_cred,int aa_sk_perm (const char *op,u32 request,struct sock *sk) {struct aa_label *label; +bool needput;int error;AA_BUG (!sk);AA_BUG (in_interrupt ());/* TODO: switch to begin_current_label ???? */ - label =begin_current_label_crit_section (); + label =begin_current_label_crit_section (&needput); error =aa_label_sk_perm (current_cred (), label, op, request, sk); -end_current_label_crit_section (label); +end_current_label_crit_section (label, needput);return error; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 97/2151 apparmor: fix query_data() output overlapping the lookup key
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit d30844001360a403a511cf24fc75ecaa6a7a7544 ]
In query_data(), buf and query point into the same multi_transaction
buffer: buf at the start, query a few bytes in, and the lookup key right after the label string that query points to. Reusing the buffer is by design and is safe as long as the query is fully parsed before buf is written to, but the key is not: it is dereferenced on every iteration of label_for_each_confined(), after output has already been written. So when the label has more than one profile with a data table, the data of the first matching profile is written to buf while the key is still needed, and overwrites it if the data is large enough. The later lookups then run on a corrupted key. Besides, if the data has no NUL byte from the key's position to the end of the allocation, strhash() -> strlen() -> jhash() reads past the 4096-byte slab object, triggering an out-of-bound read:
BUG: KASAN: slab-out-of-bounds in jhash+0x595/0x5e0 Read of size 1 at addr ff1100001159d000 by task exploit/155 CPU: 0 UID: 1000 PID: 155 Comm: exploit Not tainted 7.3.0-rc7 #1 Call Trace: jhash+0x595/0x5e0 aa_write_access+0x880/0x1400 vfs_write+0x26f/0xd20 ksys_write+0x115/0x210
Writing to the .access file is unprivileged (0666), but triggering this requires loaded profiles that carry a data table, which needs CAP_MAC_ADMIN and is not the case on default distribution policies.
Fix by copying the key with kstrdup() before writing any output to buf, so the key stays valid across all loop iterations regardless of what gets written to the overlapping buffer.
--- security/apparmor/apparmorfs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
security/apparmor/apparmorfs.c +12 -3
@@ -755,7 +755,7 @@ static void profile_query_cb(const struct aa_profile *profile,static ssize_t query_data (char *buf,size_t buf_len,char *query,size_t query_len) { -char *out; +char *out, *keydup;const char *key;struct label_it i;struct aa_label *label, *curr;
@@ -777,11 +777,18 @@ static ssize_t query_data(char *buf, size_t buf_len,if (buf_len <sizeof (bytes) +sizeof (blocks))return -EINVAL ;/* not enough space */ +/* buf overlaps query, keep a copy of the key for the later lookups */ + keydup =kstrdup (key,GFP_KERNEL ); +if (!keydup) +return -ENOMEM ; + curr =begin_current_label_crit_section (&needput); label =aa_label_parse (curr, query,GFP_KERNEL , false, false);end_current_label_crit_section (curr, needput); -if (IS_ERR (label)) +if (IS_ERR (label)) { +kfree (keydup);return PTR_ERR (label); + }/* We are going to leave space for two numbers. The first is the total * number of bytes we are writing after the first number. This is so
@@ -799,13 +806,14 @@ static ssize_t query_data(char *buf, size_t buf_len,if (!profile->data)continue ; - data =rhashtable_lookup_fast (profile->data, &key, + data =rhashtable_lookup_fast (profile->data, &keydup, profile->data->p);if (data) {if (out +sizeof (outle32) + data->size > buf + buf_len) {aa_put_label (label); +kfree (keydup);return -EINVAL ;/* not enough space */ } outle32 =__cpu_to_le32 (data->size);
@@ -817,6 +825,7 @@ static ssize_t query_data(char *buf, size_t buf_len, } }aa_put_label (label); +kfree (keydup); outle32 =__cpu_to_le32 (out - buf -sizeof (bytes));memcpy (buf, &outle32,sizeof (outle32));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 98/2151 mm/shmem: preserve allocation errors when swapping in large entries
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit f4ce23b1feef16d435aa1188b6c2a637a5373ed5 ]
shmem_swapin_folio() adjusts swap to the requested slot within a large swap entry before allocating a folio. If allocation or charging fails, the error path compares this adjusted value with the original entry still stored in the XArray in shmem_confirm_swap().
Unless the index is at the start of the entry, this turns -ENOMEM into -EEXIST even though nothing changed.
The caller retries -EEXIST, so persistent allocation failures can leave the task spinning instead of returning the error.
Restore swap to index_entry on allocation failure so the existing error path checks the original entry. This preserves the allocation error if the entry is unchanged and still retries if it changed concurrently.
--- mm/shmem.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/shmem.c +4 -0
@@ -2376,6 +2376,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,if (IS_ERR (folio)) { error =PTR_ERR (folio); folio =NULL ; +/* Make sure to validate the original value. */ + swap = index_entry; goto failed; } skip_swapcache = true;
@@ -2384,6 +2386,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, folio =shmem_swapin_cluster (swap, gfp, info, index);if (!folio) { error = -ENOMEM ; +/* Make sure to validate the original value. */ + swap = index_entry; goto failed; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 99/2151 mm/filemap: read mapping->a_ops->free_folio under i_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit dc24e273244e9d712257d5a6c20a32c7f5ca84e6 ]
memory_failure() -> ... -> filemap_remove_folio() can read mapping->a_ops after the inode has been freed. Once the folio is deleted from the pagecache it no longer pins the mapping, so after i_lock is dropped e.g., a concurrent final iput() can evict and free the inode before filemap_free_folio() looks up mapping->a_ops->free_folio.
Most callers hold a reference on the inode, but not all.
Documentation/filesystems/vfs.rst explicitly states that ->free_folio() must not assume the original address_space mapping still exists.
Fix it by loading ->free_folio while i_lock is still held, similar to what folio_unmap_invalidate() does.
Inline filemap_free_folio() into its remaining caller such that delete_from_page_cache_batch() also just loads the callback before dropping the i_lock.
The bug was found by code inspection and has not been reproduced.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
mm/filemap.c +14 -15
@@ -227,18 +227,6 @@ void __filemap_remove_folio(struct folio *folio, void *shadow)page_cache_delete (mapping, folio, shadow); } -static void filemap_free_folio (const struct address_space *mapping, -struct folio *folio) -{ -void (*free_folio)(struct folio *); - - free_folio = mapping->a_ops->free_folio; -if (free_folio) -free_folio (folio); - -folio_put_refs (folio,folio_nr_pages (folio)); -} -/** * filemap_remove_folio - Remove folio from page cache. * @folio: The folio.
@@ -250,6 +238,7 @@ static void filemap_free_folio(const struct address_space *mapping,void filemap_remove_folio (struct folio *folio) {struct address_space *mapping = folio->mapping; +void (*free_folio)(struct folio *folio);BUG_ON (!folio_test_locked (folio));spin_lock (&mapping->host->i_lock);
@@ -258,9 +247,12 @@ void filemap_remove_folio(struct folio *folio)xa_unlock_irq (&mapping->i_pages);if (mapping_shrinkable (mapping))inode_add_lru (mapping->host); + free_folio = mapping->a_ops->free_folio;spin_unlock (&mapping->host->i_lock); -filemap_free_folio (mapping, folio); +if (free_folio) +free_folio (folio); +folio_put_refs (folio,folio_nr_pages (folio)); }/*
@@ -320,6 +312,7 @@ static void page_cache_delete_batch(struct address_space *mapping,void delete_from_page_cache_batch (struct address_space *mapping,struct folio_batch *fbatch) { +void (*free_folio)(struct folio *folio);int i;if (!folio_batch_count (fbatch))
@@ -337,10 +330,16 @@ void delete_from_page_cache_batch(struct address_space *mapping,xa_unlock_irq (&mapping->i_pages);if (mapping_shrinkable (mapping))inode_add_lru (mapping->host); + free_folio = mapping->a_ops->free_folio;spin_unlock (&mapping->host->i_lock); -for (i =0 ; i <folio_batch_count (fbatch); i++) -filemap_free_folio (mapping, fbatch->folios[i]); +for (i =0 ; i <folio_batch_count (fbatch); i++) { +struct folio *folio = fbatch->folios[i]; + +if (free_folio) +free_folio (folio); +folio_put_refs (folio,folio_nr_pages (folio)); + } }int filemap_check_errors (struct address_space *mapping)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 100/2151 mm/rmap: handle device-exclusive entries in folio_referenced_one()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit f3c493d2f42b5f44a5c134d8d7ea7f960caf5e2c ]
page_vma_mapped_walk() can return non-present device-exclusive entries, but folio_referenced_one() passes them to PTE young-bit accessors that require present PTEs.
We must neither call clear_flush_young_ptes_notify() nor folio_pte_batch() with non-present entries. For example, clearing the young bit on non-present PTEs can corrupt the entry: on arm64 PTE_AF overlaps the swap type, so clearing it turns a device-exclusive entry into an ordinary swap entry.
folio_pte_batch() will VM_WARN_ON_FOLIO.
Apply the same approach as the previous fixes to e.g., damon_ptep_mkold():
treat these entries as old from the CPU's perspective and obtain their young state through the MMU notifier.
Skip PTE batching and MGLRU look-around for non-present entries, and don't modify non-present PTEs.
--- mm/rmap.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
mm/rmap.c +17 -3
@@ -858,6 +858,7 @@ static bool folio_referenced_one(struct folio *folio,struct folio_referenced_arg *pra = arg;DEFINE_FOLIO_VMA_WALK (pvmw, folio, vma, address,0 );int ptes =0 , referenced =0 ; +pte_t pteval;while (page_vma_mapped_walk (&pvmw)) { address = pvmw.address;
@@ -901,12 +902,25 @@ static bool folio_referenced_one(struct folio *folio,return false; } -if (lru_gen_enabled () && pvmw.pte) { +if (pvmw.pte) + pteval =ptep_get (pvmw.pte); + +if (lru_gen_enabled () && pvmw.pte &&pte_present (pteval)) {if (lru_gen_look_around (&pvmw)) referenced++; }else if (pvmw.pte) { -if (ptep_clear_flush_young_notify (vma, address, - pvmw.pte)) +bool young = false; + +/* +* PFN swap PTEs, such as device-exclusive ones, that +* actually map pages are "old" from a CPU perspective. +* The MMU notifier takes care of any device aspects. +*/ +if (pte_present (pteval)) + young =ptep_clear_flush_young (vma, address, pvmw.pte); + young |=mmu_notifier_clear_flush_young (vma->vm_mm, address, + address +PAGE_SIZE ); +if (young) referenced++; }else if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE )) { if (pmdp_clear_flush_young_notify(vma, address,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 101/2151 fs/proc/task_mmu: fix missed VMAs when reading /proc/PID/maps and friends
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit ee1afc5539b6fe03569a5855b6041b13343b0993 ]
Reading /proc/PID/maps under per-VMA locks can skip continuously mapped address ranges during concurrent VMA splits or merges. This violates the guarantee in Documentation/filesystems/proc.rst:
"If there is something at a given vaddr during the entirety of the life of the smaps/maps walk, there will be some output for it."
lock_next_vma() reuses a tree iterator across calls under RCU. The iterator remembers the range of its last entry. When its node is replaced, mas_next_slot() walks the tree again at the last index of that range, then advances past the entry containing that index. If VMA boundaries changed, this can skip a range that has not been reported:
- A lookup finds [A, C), then mprotect() splits it into [A, B) and [B, C) before vma_start_read() locks the first VMA. The reader reports [A, B), but the iterator still covers [A, C). The next call starts from B yet advances past C, omitting [B, C).
- The reader reports [A, B) and unlocks it. A concurrent mprotect() then merges it with [B, C). On the next call, the iterator resumes at B - 1, which now belongs to [A, C), and advances past C. Again, [B, C) is lost.
Checking the mmap_lock sequence only within the next call misses writers that completed before that call began. Also, a NULL result is currently accepted without validation, so a race can terminate the walk early.
Even a fresh lookup can skip a mapping. Suppose it finds a gap before [B, C). A writer inserts an adjacent VMA at the end of that gap, then merges it into [B, C), replacing the node. The lookup resumes at the old gap's last index, now inside the merged VMA, and steps past it. The original [B, C) remains mapped throughout. Repeating the forward lookup is insufficient: another merge can make it skip the same mapping again, returning the same later VMA or NULL.
The fresh-lookup race also affects /proc/PID/smaps, numa_maps and smaps_rollup. Resetting the iterator after gathering each VMA's statistics does not prevent a merge during the next lookup. Fixing lock_next_vma() also prevents omitted entries and incomplete rollup statistics.
Tie VMA iterator state with the current mm and the write generation at the point of last mm speculation in vma_rcu_iter, whose values we call 'rvmi'.
This allows us to neatly abstract the existing priv->iter logic alongside query_vma_find_by_addr() which uses its own VMA iterator.
Then, provide helpers that act on the rvmi - vma_rcu_iter_[maybe_changed, may_have_skipped]() to determine whether any VMAs may have been altered since last mm speculation.
Additionally introduce vma_range_is_empty(), used by vma_rcu_iter_may_have_skipped(), to determine conclusively whether VMAs exist in a set range, needing to be traversed.
Original fix generated by an LLM and sent by Josef Bacik in private, then amended by David Hildenbrand, and Lorenzo Stoakes added additional abstraction.
--- fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 9 +++--- include/linux/mmap_lock.h | 22 ++++++++++++-- mm/mmap_lock.c | 61 +++++++++++++++++++++++++++++---------- 4 files changed, 70 insertions(+), 23 deletions(-)
fs/proc/internal.h +1 -0
@@ -391,6 +391,7 @@ struct proc_maps_private {struct inode *inode;struct task_struct *task;struct vma_iterator iter; +struct vma_rcu_iter rvmi;loff_t last_pos;struct proc_maps_locking_ctx lock_ctx;#ifdef CONFIG_NUMA
fs/proc/task_mmu.c +5 -4
@@ -189,7 +189,7 @@ static struct vm_area_struct *get_next_vma(struct proc_maps_private *priv,return vma_next (&priv->iter);unlock_ctx_vma (lock_ctx); - vma =lock_next_vma (lock_ctx->mm, &priv->iter, last_pos); + vma =lock_next_vma (&priv->rvmi, last_pos);if (!IS_ERR_OR_NULL (vma)) lock_ctx->locked_vma = vma;
@@ -308,7 +308,7 @@ static void *m_start(struct seq_file *m, loff_t *ppos)*/ if (last_addr >0 ) *ppos = last_addr = priv->last_pos; -vma_iter_init (&priv->iter, mm, (unsigned long )last_addr); +vma_rcu_iter_init (&priv->rvmi, mm, &priv->iter, (unsigned long )last_addr);hold_task_mempolicy (priv);if (last_addr ==SENTINEL_VMA_GATE )return get_gate_vma (mm);
@@ -552,6 +552,7 @@ static struct vm_area_struct *query_vma_find_by_addr(struct proc_maps_locking_ctstruct mm_struct *mm = lock_ctx->mm;struct vm_area_struct *vma;struct vma_iterator vmi; +struct vma_rcu_iter rvmi;if (lock_ctx->mmap_locked)return find_vma (mm, addr);
@@ -559,8 +560,8 @@ static struct vm_area_struct *query_vma_find_by_addr(struct proc_maps_locking_ct/* Unlock previously locked VMA and find the next one under RCU */ unlock_ctx_vma (lock_ctx);rcu_read_lock (); -vma_iter_init (&vmi, mm, addr); - vma =lock_next_vma (mm, &vmi, addr); +vma_rcu_iter_init (&rvmi, mm, &vmi, addr); + vma =lock_next_vma (&rvmi, addr);rcu_read_unlock ();if (!vma)
include/linux/mmap_lock.h +19 -3
@@ -17,6 +17,13 @@ extern int rcuwait_wake_up(struct rcuwait *w);#define MMAP_LOCK_INITIALIZER (name) \ .mmap_lock = __RWSEM_INITIALIZER((name).mmap_lock), +/* Tie a VMA iterator to mm write lock state at iterator initialisation. */ +struct vma_rcu_iter { +struct mm_struct *mm; +struct vma_iterator *vmi; +unsigned int mm_wr_seq; +}; +DECLARE_TRACEPOINT (mmap_lock_start_locking);DECLARE_TRACEPOINT (mmap_lock_acquire_returned);DECLARE_TRACEPOINT (mmap_lock_released);
@@ -263,9 +270,8 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,* Returns either a valid locked VMA, NULL if no more VMAs or -EINTR if the * process was interrupted. */ -struct vm_area_struct *lock_next_vma (struct mm_struct *mm, -struct vma_iterator *iter, -unsigned long address); +struct vm_area_struct *lock_next_vma (struct vma_rcu_iter *rvmi, +unsigned long from_addr);#else /* CONFIG_PER_VMA_LOCK */
@@ -308,6 +314,16 @@ static inline void vma_assert_locked(struct vm_area_struct *vma)#endif /* CONFIG_PER_VMA_LOCK */ +static inline void vma_rcu_iter_init (struct vma_rcu_iter *rvmi, +struct mm_struct *mm,struct vma_iterator *vmi, +unsigned long addr) +{ +vma_iter_init (vmi, mm, addr); + rvmi->mm = mm; + rvmi->vmi = vmi; + rvmi->mm_wr_seq =UINT_MAX ;/* Start odd so changed by default. */ +} +static inline void mmap_write_lock (struct mm_struct *mm) {__mmap_lock_trace_start_locking (mm, true);
mm/mmap_lock.c +45 -16
86 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 102/2151 mm/huge_memory: properly handle refcounted PUD mappings on fork
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit d90bdc02e36ec08d8248ebc6cdc52e12043eb28c ]
copy_huge_pud() copies device-DAX entries without taking a folio reference or updating mapcounts and the child's RSS.
For example, MADV_GUARD_INSTALL sets VM_MAYBE_GUARD on a device-DAX VMA, forcing copy_page_range() to traverse the whole VMA on fork. Any remaining huge PUDs are then copied without accounting for the new mappings. Unmapping them in the child decrements accounting that was never added.
Use vm_normal_page_pud() to identify refcounted mappings. Take a folio reference and add the child's PUD rmap and RSS accounting before installing the copied entry. Pass src and dst VMAs consistently instead of src and dst MM. Move the TODO.
--- include/linux/huge_mm.h | 5 ++--- mm/huge_memory.c | 27 +++++++++++++++++++-------- mm/memory.c | 4 +--- 3 files changed, 22 insertions(+), 14 deletions(-)
include/linux/huge_mm.h +2 -3
@@ -12,9 +12,8 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr, struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma);void huge_pmd_set_accessed (struct vm_fault *vmf); -int copy_huge_pud (struct mm_struct *dst_mm,struct mm_struct *src_mm, -pud_t *dst_pud,pud_t *src_pud,unsigned long addr, -struct vm_area_struct *vma); +int copy_huge_pud (struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma, +pud_t *dst_pud,pud_t *src_pud,unsigned long addr);#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD void huge_pud_set_accessed (struct vm_fault *vmf,pud_t orig_pud);
mm/huge_memory.c +19 -8
@@ -1911,11 +1911,13 @@ void touch_pud(struct vm_area_struct *vma, unsigned long addr,update_mmu_cache_pud (vma, addr, pud); } -int copy_huge_pud (struct mm_struct *dst_mm,struct mm_struct *src_mm, -pud_t *dst_pud,pud_t *src_pud,unsigned long addr, -struct vm_area_struct *vma) +int copy_huge_pud (struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma, +pud_t *dst_pud,pud_t *src_pud,unsigned long addr) { +struct mm_struct *dst_mm = dst_vma->vm_mm; +struct mm_struct *src_mm = src_vma->vm_mm;spinlock_t *dst_ptl, *src_ptl; +struct page *page;pud_t pud;int ret;
@@ -1928,11 +1930,20 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm,if (unlikely (!pud_trans_huge (pud))) goto out_unlock; -/* -* TODO: once we support anonymous pages, use -* folio_try_dup_anon_rmap_*() and split if duplicating fails. -*/ -if (is_cow_mapping (vma->vm_flags) &&pud_write (pud)) { + page =vm_normal_page_pud (src_vma, addr, pud); +if (page) { +struct folio *folio =page_folio (page); + +folio_get (folio); +/* +* TODO: once we support anonymous pages, use +* folio_try_dup_anon_rmap_*() and split if duplicating fails. +*/ +folio_add_file_rmap_pud (folio, page, dst_vma); +add_mm_counter (dst_mm,mm_counter_file (folio),HPAGE_PUD_NR ); + } + +if (is_cow_mapping (src_vma->vm_flags) &&pud_write (pud)) {pudp_set_wrprotect (src_mm, addr, src_pud); pud =pud_wrprotect (pud); }
mm/memory.c +1 -3
@@ -1416,7 +1416,6 @@ copy_pud_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, unsigned long end) {struct mm_struct *dst_mm = dst_vma->vm_mm; -struct mm_struct *src_mm = src_vma->vm_mm;pud_t *src_pud, *dst_pud;unsigned long next;
@@ -1430,8 +1429,7 @@ copy_pud_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,int err;VM_BUG_ON_VMA (next-addr !=HPAGE_PUD_SIZE , src_vma); - err =copy_huge_pud (dst_mm, src_mm, - dst_pud, src_pud, addr, src_vma); + err =copy_huge_pud (dst_vma, src_vma, dst_pud, src_pud, addr);if (err == -ENOMEM )return -ENOMEM ;if (!err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 103/2151 fork: take mmap_lock before copying mm_struct
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit ef694e2d210111cc08c52fd25da9ab130170bfa3 ]
dup_mm() copies the parent's mm_struct before dup_mmap() takes the mmap_lock. A concurrent brk() can leave the child with a stale mm->brk and newer heap mappings, causing later brk() requests to fail.
Other operations (e.g., PR_SET_MM) on the parent's mm_struct can similarly cause inconsistencies.
As a simple and robust fix, grab the parent's mmap_lock earlier. This way we don't need to update individual mm fields in dup_mmap() and keep missing ones. Stop updating the 4 existing members (total_vm, data_vm, exec_vm, stack_vm), as that is now no longer required.
Keep releasing the parent's mmap_lock in dup_mmap(), before userfaultfd completion, to avoid moving the userfaultfd handling into the caller. This should get cleaned up later.
Move uprobe_start_dup_mmap() to preserve the lock ordering.
--- kernel/fork.c | 20 ++++++++++++++------ mm/mmap.c | 8 +------- mm/nommu.c | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-)
kernel/fork.c +14 -6
@@ -1487,12 +1487,19 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,if (!mm) goto fail_nomem; +uprobe_start_dup_mmap (); +if (mmap_write_lock_killable (oldmm)) { +free_mm (mm); + goto fail_uprobe; + } +memcpy (mm, oldmm,sizeof (*mm)); -if (!mm_init (mm, tsk, mm->user_ns)) - goto fail_nomem; +if (!mm_init (mm, tsk, mm->user_ns)) { +mmap_write_unlock (oldmm); + goto fail_uprobe; + } -uprobe_start_dup_mmap (); err =dup_mmap (mm, oldmm);if (err) goto free_pt;
@@ -1511,9 +1518,10 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, mm->binfmt =NULL ;mm_init_owner (mm,NULL );mmput (mm); -if (err) -uprobe_end_dup_mmap (); - +if (!err) +return NULL ; +fail_uprobe: +uprobe_end_dup_mmap (); fail_nomem:return NULL ; }
mm/mmap.c +1 -7
@@ -1724,8 +1724,7 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)LIST_HEAD (uf);VMA_ITERATOR (vmi, mm,0 ); -if (mmap_write_lock_killable (oldmm)) -return -EINTR ; +mmap_assert_write_locked (oldmm);flush_cache_dup_mm (oldmm);uprobe_dup_mmap (oldmm, mm);/*
@@ -1736,11 +1735,6 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)/* No ordering required: file already has been exposed. */ dup_mm_exe_file (mm, oldmm); - mm->total_vm = oldmm->total_vm; - mm->data_vm = oldmm->data_vm; - mm->exec_vm = oldmm->exec_vm; - mm->stack_vm = oldmm->stack_vm; -/* Use __mt_dup() to efficiently build an identical maple tree. */ retval =__mt_dup (&oldmm->mm_mt, &mm->mm_mt,GFP_KERNEL );if (unlikely (retval))
mm/nommu.c +1 -1
@@ -1896,7 +1896,7 @@ subsys_initcall(init_admin_reserve);int dup_mmap (struct mm_struct *mm,struct mm_struct *oldmm) { -mmap_write_lock (oldmm); +mmap_assert_write_locked (oldmm);dup_mm_exe_file (mm, oldmm);mmap_write_unlock (oldmm);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 104/2151 hwmon: (gpd-fan) Reset both fans to automatic on duo boards
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Solcanu <[email protected]>
[ Upstream commit d1f60971fbf85c243ab6c78f6535fbc88fa640ce ]
On boards using gpd_duo_drvdata (GPD Duo, GPD Win 5), writing pwm1_enable=2 only returns the first fan to EC control. The second fan keeps its last manual duty cycle, e.g. full speed after pwm1=255, so a fan control tool that exits leaves it running at that speed.
gpd_duo_write_pwm() writes both fan registers (pwm_write and pwm_write + 1), but switching to automatic only clears pwm_write. Also clear pwm_write + 1, so both fans return to EC control.
Tested on a GPD Win 5 (G1618-05). Not tested on the GPD Duo.
--- drivers/hwmon/gpd-fan.c | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/gpd-fan.c +1 -0
@@ -412,6 +412,7 @@ static void gpd_duo_set_pwm_enable(enum FAN_PWM_ENABLE pwm_enable)break ;case AUTOMATIC :gpd_ecram_write (gpd_driver_priv.drvdata->pwm_write,0 ); +gpd_ecram_write (gpd_driver_priv.drvdata->pwm_write +1 ,0 );break ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 105/2151 ASoC: qcom: q6apm: clear g_apm on driver removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ajay Kumar Nandam <[email protected]>
[ Upstream commit be2172758f2b7c801ae80b9c8d1510b31eeffdaa ]
The global g_apm pointer is set during apm_probe() but never cleared in apm_remove(). After the driver is removed the devm-managed struct q6apm is freed, leaving g_apm dangling. A subsequent call to q6apm_is_adsp_ready() dereferences the freed pointer.
Clear g_apm in apm_remove() before the component is unregistered so that q6apm_is_adsp_ready() returns false instead of triggering a use-after-free.
--- sound/soc/qcom/qdsp6/q6apm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/qcom/qdsp6/q6apm.c +1 -0
@@ -798,6 +798,7 @@ static int apm_probe(gpr_device_t *gdev)static void apm_remove (gpr_device_t *gdev) { + g_apm =NULL ;of_platform_depopulate (&gdev->dev);snd_soc_unregister_component (&gdev->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 106/2151 mm: fix deadlock of mremap() against UFFDIO_MOVE
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit d03df42ddae196f20e9cfb775704e60269eb6b44 ]
With per-VMA locks, UFFDIO_MOVE can run concurrently with mremap() on different VMAs in the same mm. Those VMAs can share page tables, so both operations can acquire the same pair of page-table locks.
UFFDIO_MOVE orders the locks by address, while mremap() takes the source lock first. These conflicting orders can deadlock; mremap() holding mmap_lock for writing no longer helps.
Move double_pt_lock() and double_pt_unlock() to mm/internal.h and use them for all page-table moves in mremap(). Preserve the source entry checks after acquiring both locks. Remove the comments claiming that exclusive mmap_lock makes lock ordering irrelevant.
In move_ptes(), make sure to just recheck source and destination PMD after taking the locks and drop the overly-long comment.
Fix generated by an LLM and sent by Chris Mason in private.
[ david: use new helpers consistently; simplify description and comments;
move_ptes() fixup ]
--- include/linux/userfaultfd_k.h | 2 - mm/huge_memory.c | 19 +++----- mm/hugetlb.c | 14 ++---- mm/internal.h | 28 +++++++++++ mm/mremap.c | 87 ++++++++++++++--------------------- mm/userfaultfd.c | 27 ----------- 6 files changed, 72 insertions(+), 105 deletions(-)
include/linux/userfaultfd_k.h +0 -2
@@ -140,8 +140,6 @@ extern long uffd_wp_range(struct vm_area_struct *vma, unsigned long start, unsigned long len, bool enable_wp);/* move_pages */ -void double_pt_lock (spinlock_t *ptl1,spinlock_t *ptl2); -void double_pt_unlock (spinlock_t *ptl1,spinlock_t *ptl2);ssize_t move_pages (struct userfaultfd_ctx *ctx,unsigned long dst_start,unsigned long src_start,unsigned long len,__u64 flags); int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pmd_t dst_pmdval,
mm/huge_memory.c +7 -12
@@ -2441,15 +2441,11 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,return false; } -/* -* We don't have to worry about the ordering of src and dst -* ptlocks because exclusive mmap_lock prevents deadlock. -*/ - old_ptl =__pmd_trans_huge_lock (old_pmd, vma); -if (old_ptl) { - new_ptl =pmd_lockptr (mm, new_pmd); -if (new_ptl != old_ptl) -spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING ); + old_ptl =pmd_lockptr (mm, old_pmd); + new_ptl =pmd_lockptr (mm, new_pmd); + +double_pt_lock (old_ptl, new_ptl); +if (likely (is_swap_pmd (*old_pmd) ||pmd_trans_huge (*old_pmd))) { pmd =pmdp_huge_get_and_clear (mm, old_addr, old_pmd);if (pmd_present (pmd)) force_flush = true;
@@ -2466,11 +2462,10 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,set_pmd_at (mm, new_addr, new_pmd, pmd);if (force_flush)flush_pmd_tlb_range (vma, old_addr, old_addr +PMD_SIZE ); -if (new_ptl != old_ptl) -spin_unlock (new_ptl); -spin_unlock (old_ptl); +double_pt_unlock (old_ptl, new_ptl);return true; } +double_pt_unlock (old_ptl, new_ptl);return false; }
mm/hugetlb.c +3 -11
@@ -5808,15 +5808,9 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,spinlock_t *src_ptl, *dst_ptl;pte_t pte; - dst_ptl =huge_pte_lock (h, mm, dst_pte); + dst_ptl =huge_pte_lockptr (h, mm, dst_pte); src_ptl =huge_pte_lockptr (h, mm, src_pte); - -/* -* We don't have to worry about the ordering of src and dst ptlocks -* because exclusive mmap_lock (or the i_mmap_lock) prevents deadlock. -*/ -if (src_ptl != dst_ptl) -spin_lock_nested (src_ptl,SINGLE_DEPTH_NESTING ); +double_pt_lock (dst_ptl, src_ptl); pte =huge_ptep_get_and_clear (mm, old_addr, src_pte, sz);
@@ -5832,9 +5826,7 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,set_huge_pte_at (mm, new_addr, dst_pte, pte, sz); } -if (src_ptl != dst_ptl) -spin_unlock (src_ptl); -spin_unlock (dst_ptl); +double_pt_unlock (dst_ptl, src_ptl); } unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma,
mm/internal.h +28 -0
@@ -467,6 +467,34 @@ static inline void force_page_cache_readahead(struct address_space *mapping,force_page_cache_ra (&ractl, nr_to_read); } +/* +* Take two page table locks at the same level in address order such that +* we cannot deadlock. +*/ +static inline void double_pt_lock (spinlock_t *ptl1,spinlock_t *ptl2) +__acquires (ptl1) +__acquires (ptl2) +{ +if (ptl1 > ptl2) +swap (ptl1, ptl2); +spin_lock (ptl1); +if (ptl1 != ptl2) +spin_lock_nested (ptl2,SINGLE_DEPTH_NESTING ); +else +__acquire (ptl2); +} + +static inline void double_pt_unlock (spinlock_t *ptl1,spinlock_t *ptl2) +__releases (ptl1) +__releases (ptl2) +{ +spin_unlock (ptl1); +if (ptl1 != ptl2) +spin_unlock (ptl2); +else +__release (ptl2); +} +unsigned find_lock_entries (struct address_space *mapping,pgoff_t *start,pgoff_t end,struct folio_batch *fbatch,pgoff_t *indices); unsigned find_get_entries(struct address_space *mapping, pgoff_t *start,
mm/mremap.c +34 -53
153 lines not on this page · raw message
mm/userfaultfd.c +0 -27
@@ -989,33 +989,6 @@ int mwriteprotect_range(struct userfaultfd_ctx *ctx, unsigned long start, } -void double_pt_lock (spinlock_t *ptl1, -spinlock_t *ptl2) -__acquires (ptl1) -__acquires (ptl2) -{ -if (ptl1 > ptl2) -swap (ptl1, ptl2); -/* lock in virtual address order to avoid lock inversion */ -spin_lock (ptl1); -if (ptl1 != ptl2) -spin_lock_nested (ptl2,SINGLE_DEPTH_NESTING ); -else -__acquire (ptl2); -} - -void double_pt_unlock (spinlock_t *ptl1, -spinlock_t *ptl2) -__releases (ptl1) -__releases (ptl2) -{ -spin_unlock (ptl1); -if (ptl1 != ptl2) -spin_unlock (ptl2); -else -__release (ptl2); -} -static inline bool is_pte_pages_stable (pte_t *dst_pte,pte_t *src_pte,pte_t orig_dst_pte,pte_t orig_src_pte,pmd_t *dst_pmd,pmd_t dst_pmdval)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 107/2151 rose: walk the neighbour list under its lock when a device goes down
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_link_device_down() walks rose_neigh_list without rose_neigh_list_lock. The list can change under it: rose_add_node() and rose_del_node() from the SIOCADDRT/SIOCDELRT ioctls, and rose_rt_device_down(), which the same NETDEV_DOWN event calls right after, all add or free neighbours under that lock. The walk can then follow a neighbour that has just been freed.
Take the lock around the walk, as rose_link_failed() does around the very same calls to rose_del_route_by_neigh() and rose_kill_by_neigh().
--- net/rose/rose_route.c | 2 ++ 1 file changed, 2 insertions(+)
net/rose/rose_route.c +2 -0
@@ -958,12 +958,14 @@ void rose_link_device_down(struct net_device *dev) {struct rose_neigh *rose_neigh; +spin_lock_bh (&rose_neigh_list_lock);for (rose_neigh = rose_neigh_list; rose_neigh !=NULL ; rose_neigh = rose_neigh->next) {if (rose_neigh->dev == dev) {rose_del_route_by_neigh (rose_neigh);rose_kill_by_neigh (rose_neigh); } } +spin_unlock_bh (&rose_neigh_list_lock); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 108/2151 rose: hold RTNL while a route is added or deleted
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_ax25_dev_find() says it is called with RTNL, but rose_rt_ioctl() does not take it for SIOCADDRT and SIOCDELRT. __dev_get_by_name() is then used without RTNL or RCU, and the device can go down between the IFF_UP check and rose_add_node(): the NETDEV_DOWN notifier runs rose_rt_device_down(), finds no neighbour on the device yet, and the neighbour added right after keeps a pointer to a device that may be unregistered and freed, since rose_neigh->dev holds no reference.
Commit b4ec82402149 ("rose: device refcount leak") stopped taking a reference on the device because RTNL would be held, which the ioctl never did.
Take RTNL around the lookup of the device and the change of the tables. The notifier runs under RTNL too, so a neighbour is either on the list before the device goes down, where rose_rt_device_down() removes it, or not added at all.
--- net/rose/rose_route.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
net/rose/rose_route.c +13 -6
@@ -17,6 +17,7 @@#include <net/ax25.h> #include <linux/inet.h> #include <linux/netdevice.h> +#include <linux/rtnetlink.h> #include <net/arp.h> #include <linux/if_arp.h> #include <linux/skbuff.h>
@@ -829,23 +830,29 @@ int rose_rt_ioctl(unsigned int cmd, void __user *arg)case SIOCADDRT :if (copy_from_user (&rose_route, arg,sizeof (struct rose_route_struct )))return -EFAULT ; -if ((dev =rose_ax25_dev_find (rose_route.device)) ==NULL ) -return -EINVAL ;if (rose_dev_exists (&rose_route.address))/* Can't add routes to ourself */ return -EINVAL ;if (rose_route.mask >10 )/* Mask can't be more than 10 digits */ return -EINVAL ;if (rose_route.ndigis >AX25_MAX_DIGIS )return -EINVAL ; - err =rose_add_node (&rose_route, dev); +/* +* RTNL keeps the device up until the neighbour that uses it +* is on the list, where rose_rt_device_down() finds it. +*/ +rtnl_lock (); + dev =rose_ax25_dev_find (rose_route.device); + err = dev ?rose_add_node (&rose_route, dev) : -EINVAL ; +rtnl_unlock ();return err;case SIOCDELRT :if (copy_from_user (&rose_route, arg,sizeof (struct rose_route_struct )))return -EFAULT ; -if ((dev =rose_ax25_dev_find (rose_route.device)) ==NULL ) -return -EINVAL ; - err =rose_del_node (&rose_route, dev); +rtnl_lock (); + dev =rose_ax25_dev_find (rose_route.device); + err = dev ?rose_del_node (&rose_route, dev) : -EINVAL ; +rtnl_unlock ();return err;case SIOCRSCLRRT :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 109/2151 rose: change the loopback nodes under the neighbour list lock too
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
Since commit fe2c802ab62a ("rose: improving AX25 routing frames via ROSE network"), rose_route_frame() looks up the node list through rose_get_neigh() with route_frame set, under rose_neigh_list_lock only:
it cannot take rose_node_list_lock there. Every other writer of rose_node_list holds both locks for that reason, but rose_add_loopback_node() and rose_del_loopback_node(), run when a rose device is opened, closed or given a new address, take rose_node_list_lock alone. A frame routed at that moment can walk a node that is being freed.
Take rose_neigh_list_lock inside rose_node_list_lock in both, in the same order as rose_add_node() and rose_del_node().
--- net/rose/rose_route.c | 4 ++++ 1 file changed, 4 insertions(+)
net/rose/rose_route.c +4 -0
@@ -463,6 +463,7 @@ int rose_add_loopback_node(const rose_address *address)int err =0 ;spin_lock_bh (&rose_node_list_lock); +spin_lock_bh (&rose_neigh_list_lock); rose_node = rose_node_list;while (rose_node !=NULL ) {
@@ -495,6 +496,7 @@ int rose_add_loopback_node(const rose_address *address)rose_neigh_hold (rose_loopback_neigh); out: +spin_unlock_bh (&rose_neigh_list_lock);spin_unlock_bh (&rose_node_list_lock);return err;
@@ -508,6 +510,7 @@ void rose_del_loopback_node(const rose_address *address)struct rose_node *rose_node;spin_lock_bh (&rose_node_list_lock); +spin_lock_bh (&rose_neigh_list_lock); rose_node = rose_node_list;while (rose_node !=NULL ) {
@@ -527,6 +530,7 @@ void rose_del_loopback_node(const rose_address *address)rose_neigh_put (rose_loopback_neigh); out: +spin_unlock_bh (&rose_neigh_list_lock);spin_unlock_bh (&rose_node_list_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 110/2151 rose: check the length of Restart Request and Diagnostic frames
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_route_frame() only makes sure that a frame holds the three bytes of the ROSE header before it hands the frames with LCI 0 to rose_link_rx_restart(). There, a Restart Request has its cause read from byte 3 to set dce_mode, and a Diagnostic has bytes 3 to 6 printed. A peer that sends them shorter makes the kernel read past the end of the frame, and set dce_mode, which decides from which end LCIs are given out, from whatever lies there.
Only read the restarting cause when the frame has one, and leave dce_mode as it was otherwise. Ignore a Diagnostic too short to hold its diagnostic code and the three bytes it reports, as x25 does with pskb_may_pull().
--- net/rose/rose_link.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/rose/rose_link.c +6 -1
@@ -185,7 +185,9 @@ void rose_link_rx_restart(struct sk_buff *skb, struct rose_neigh *neigh, unsignerose_link_restarted (neigh);rose_stop_t0timer (neigh); neigh->restarted =1 ; - neigh->dce_mode = (skb->data[3 ] ==ROSE_DTE_ORIGINATED ); +/* The restarting cause, when present, tells if the peer is a DTE */ +if (skb->len >ROSE_MIN_LEN ) + neigh->dce_mode = (skb->data[3 ] ==ROSE_DTE_ORIGINATED );rose_transmit_restart_confirmation (neigh);break ;
@@ -195,6 +197,9 @@ void rose_link_rx_restart(struct sk_buff *skb, struct rose_neigh *neigh, unsignebreak ;case ROSE_DIAGNOSTIC : +/* Diagnostic code and the first three bytes of the bad packet */ +if (skb->len <ROSE_MIN_LEN +4 ) +break ;pr_warn ("ROSE: received diagnostic #%d - %3ph\n" , skb->data[3 ], skb->data +4 );break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 111/2151 rose: keep a socket unbound when connect() fails to autobind it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When connect() is called on a socket that was never bound, it clears SOCK_ZAPPED first and then looks for a rose device and for the callsign of the user. If there is no rose device, or no callsign for the user, connect() fails, but the socket is left marked as bound although it has no device, no source address and is not on rose_list.
A second connect() on that socket then skips the autobind and places the call with an all-zero source address and callsign. The socket is not on rose_list, so rose_new_lci() does not see the LCI it holds and rose_find_socket() never finds it: the Call Accepted is not delivered to it and the call can only time out.
Clear SOCK_ZAPPED only once the autobind has succeeded, right before the socket goes on rose_list, as rose_bind() does.
--- net/rose/af_rose.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/rose/af_rose.c +2 -2
@@ -894,8 +894,6 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_leif (sock_flag (sk,SOCK_ZAPPED )) {/* Must bind first - autobinding in this may or may not work */ struct net_device *dev; -sock_reset_flag (sk,SOCK_ZAPPED ); - dev =rose_dev_first ();if (!dev) { err = -ENETUNREACH ;
@@ -916,6 +914,8 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le GFP_KERNEL);ax25_uid_put (user); +/* Only now is the socket bound: a failed autobind leaves it as it was */ +sock_reset_flag (sk,SOCK_ZAPPED );rose_insert_socket (sk);/* Finish the bind */ }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 112/2151 rose: refuse an empty message when the Q bit is included
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
With the ROSE_QBITINCL socket option set, rose_sendmsg() takes the Q bit from the first byte of the message and pulls that byte off. Nothing checks that there is a first byte: a send() of zero bytes reads the Q bit from beyond the data copied from the user, skb_pull() fails without a word, and an empty data frame goes out with a Q bit taken from uninitialised memory.
Refuse such a message with EINVAL before anything is allocated. x25_sendmsg() checks for that byte too, with pskb_may_pull().
--- net/rose/af_rose.c | 4 ++++ 1 file changed, 4 insertions(+)
net/rose/af_rose.c +4 -0
@@ -1286,6 +1286,10 @@ static int rose_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)if (len >65535 )return -EMSGSIZE ; +/* With the Q bit included, the first byte of the data holds it */ +if (rose->qbitincl && len <1 ) +return -EINVAL ; + size = len +AX25_BPQ_HEADER_LEN +AX25_MAX_HEADER_LEN +ROSE_MIN_LEN ;if ((skb =sock_alloc_send_skb (sk, size, msg->msg_flags &MSG_DONTWAIT , &err)) ==NULL )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 113/2151 rose: give loopback answers LCIs that calls cannot be given
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
A call to an address of the node itself goes through the loopback neighbour, and both ends of it use that neighbour. rose_loopback_timer() gives the answering end LCI 51 - i for a call on LCI i, so that each end finds the other. The 51 comes from ROSE_DEFAULT_MAXVC, but the number of circuits is the maximum_virtual_circuits sysctl, which goes up to 254, and rose_new_lci() hands out LCIs from 1 up to that value on the loopback neighbour as on any other.
With more than 50 circuits allowed, the call on LCI 51 is answered on LCI 0 and the next ones on LCIs that wrap around to huge values: the answer is never matched to its call. Below that, LCI 51 - i is never checked to be free, and only the way rose_new_lci() walks the LCIs keeps it from being one that a call already uses.
Answer on LCI 4096 - i instead, at the top of the 12-bit LCI range, as was nearly done before commit 1f731b63752d ("rose_loopback_timer sets VC number <= ROSE_DEFAULT_MAXVC"): 0xFFF - i. That commit moved the answers below 51 so that /proc/net/rose would not show an LCI above the number of circuits; it prints the LCI on three hex digits, which any LCI up to 0xFFF fits. 4096 - i is still its own inverse, so each end finds the other as before, and rose_new_lci() never gives out an LCI above 254.
--- net/rose/rose_loopback.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/rose/rose_loopback.c +6 -1
@@ -101,7 +101,12 @@ static void rose_loopback_timer(struct timer_list *unused)continue ; } dest = (rose_address *)(skb->data +ROSE_CALL_REQ_DEST_ADDR_OFF ); - lci_o =ROSE_DEFAULT_MAXVC +1 - lci_i; +/* +* The call and its answer use the same neighbour: give the +* answer the LCI at the other end of the 12-bit range, which +* rose_new_lci() never hands out, and get back from it. +*/ + lci_o =0xFFF +1 - lci_i;skb_reset_transport_header (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 114/2151 rose: clear the other half of a through route a new call takes over
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When a Call Request comes in on the LCI of an existing through route, for a call other than the one the route was built for, the neighbour has evidently lost that call: it gives the LCI out again. rose_route_frame() then removes the route and goes on with the new call, but says nothing to the neighbour on the other half. That end keeps its virtual circuit up with nothing behind it, and its LCI on our side is freed while it may still send on it.
Do as rose_clear_routes_by_neigh() does when a neighbour goes away:
detach the half that the new call takes over and send a Clear Request on the other half. The route stays for that half until its Clear Confirmation, which removes it, and its LCI is not given to another call meanwhile. The cause is the one given to a socket in the same case, network congestion. A route that has no other half left is removed as before.
--- net/rose/rose_route.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)
net/rose/rose_route.c +36 -4
@@ -1145,8 +1145,24 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) 120); goto out; } -/* Remove an existing unused route */ -rose_remove_route (rose_route); +/* +* Another call on the LCI of a through +* route: the neighbour no longer has the +* call it was built for. Clear the other +* half, which keeps the route until its +* Clear Confirmation, and leave the LCI +* to the new call. +*/ +if (rose_route->neigh2 !=NULL ) { +rose_neigh_put (rose_route->neigh1); + rose_route->neigh1 =NULL ; +rose_transmit_clear_request (rose_route->neigh2, + rose_route->lci2, +ROSE_NETWORK_CONGESTION , +0 ); + }else { +rose_remove_route (rose_route); + }break ; }else if (rose_route->neigh2 !=NULL ) { skb->data[0 ] &=0xF0 ;
@@ -1180,8 +1196,24 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) 120); goto out; } -/* Remove an existing unused route */ -rose_remove_route (rose_route); +/* +* Another call on the LCI of a through +* route: the neighbour no longer has the +* call it was built for. Clear the other +* half, which keeps the route until its +* Clear Confirmation, and leave the LCI +* to the new call. +*/ +if (rose_route->neigh1 !=NULL ) { +rose_neigh_put (rose_route->neigh2); + rose_route->neigh2 =NULL ; +rose_transmit_clear_request (rose_route->neigh1, + rose_route->lci1, +ROSE_NETWORK_CONGESTION , +0 ); + }else { +rose_remove_route (rose_route); + }break ; }else if (rose_route->neigh1 !=NULL ) { skb->data[0 ] &=0xF0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 115/2151 rose: disconnect sockets under their lock when a neighbour goes away
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_kill_by_neigh() disconnects every socket that uses a neighbour whose link has failed, restarted or gone down, holding only rose_list_lock. rose_disconnect() stops the timers, purges the queues and changes the state of the socket, but its timers and the frames received for it work on the same socket under bh_lock_sock() only, on other CPUs, and are not kept out by rose_list_lock.
Disconnect each socket under its lock. rose_rx_call_request() and rose_kill_by_device() take the socket lock before rose_list_lock, so do as rose_kill_by_device() does: take a reference on the sockets that use the neighbour under rose_list_lock, drop it, and lock each socket in turn, checking that it still uses the neighbour. The neighbour is still taken under rose_list_lock as well: rose_release() takes it under that lock while it owns the socket, which bh_lock_sock() does not keep out.
--- net/rose/af_rose.c | 48 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-)
net/rose/af_rose.c +41 -7
@@ -162,19 +162,52 @@ static void rose_remove_socket(struct sock *sk)*/ void rose_kill_by_neigh (struct rose_neigh *neigh) { -struct sock *s; +struct sock *s, *array[16 ]; +bool rescan; +int i, cnt; +/* +* Each socket is disconnected under its lock, which its timers and +* the frames received for it hold while they work on it. That lock +* is taken before rose_list_lock elsewhere, so collect the sockets +* first, as rose_kill_by_device() does. rose_list_lock is still +* held around the change of the neighbour, which rose_release() +* takes under it while it owns the socket. A socket done with has +* no neighbour left and is not collected again. +*/ +again: + rescan = false; + cnt =0 ;spin_lock_bh (&rose_list_lock);sk_for_each (s, &rose_list) { -struct rose_sock *rose =rose_sk (s); +if (rose_sk (s)->neighbour != neigh) +continue ; +if (cnt ==ARRAY_SIZE (array)) { + rescan = true; +break ; + } +sock_hold (s); + array[cnt++] = s; + } +spin_unlock_bh (&rose_list_lock); + +for (i =0 ; i < cnt; i++) { +struct rose_sock *rose =rose_sk (array[i]); +bh_lock_sock (array[i]); +/* rose_release() takes the neighbour under rose_list_lock */ +spin_lock_bh (&rose_list_lock);if (rose->neighbour == neigh) { -rose_disconnect (s,ENETUNREACH ,ROSE_OUT_OF_ORDER ,0 ); +rose_disconnect (array[i],ENETUNREACH ,ROSE_OUT_OF_ORDER ,0 );rose_neigh_put (rose->neighbour); rose->neighbour =NULL ; } +spin_unlock_bh (&rose_list_lock); +bh_unlock_sock (array[i]); +sock_put (array[i]); } -spin_unlock_bh (&rose_list_lock); +if (rescan) + goto again; }/*
@@ -721,9 +754,10 @@ static int rose_release(struct socket *sock)* Disconnect before the socket lock is dropped: frames put on * the backlog meanwhile, a Clear Confirmation for one, then * find it in state 0 instead of dropping the neighbour -* reference a second time. rose_kill_by_neigh() does not take -* the socket lock: take the neighbour under rose_list_lock, as -* it does, so that only one of them drops the reference. +* reference a second time. rose_kill_by_neigh() can run while +* the socket is owned here: take the neighbour under +* rose_list_lock, as it does, so that only one of them drops +* the reference. */ rose_disconnect (sk,0 ,-1 ,-1 );spin_lock_bh (&rose_list_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 116/2151 hdlcdrv: close the hardware driver once, and only if it was opened
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
hdlcdrv_unregister() calls the hardware driver's close() when s->opened is set and then calls unregister_netdev(). Two things go wrong:
- if the interface is still up, unregister_netdev() closes it through ndo_stop, so hdlcdrv_close() calls the hardware driver's close() a second time;
- hdlcdrv_open() sets s->opened before it calls the hardware driver's open() and leaves it set when that fails, so close() is also called for a port that was never opened.
The close() methods of the baycom drivers are not written for either case. baycom_ser_fdx and baycom_ser_hdx call free_irq() and release_region() for resources they do not hold. baycom_par dereferences bc->pdev, which is NULL if the port was never opened and points to an unregistered parport device after a first close.
Set s->opened only once the hardware driver's open() has succeeded, and let unregister_netdev() do the closing.
Tested in a QEMU guest (6.12.94, KASAN and lockdep) with baycom_ser_fdx and two ports: bcsf0 at an address without a UART, whose open fails, and bcsf1 on a UART, left up. Unloading baycom_ser_fdx gave before the change:
Trying to free already-free IRQ 5
ser12_close+0xa1/0x190 [baycom_ser_fdx] cleanup_baycomserfdx+0x38/0x50 [baycom_ser_fdx] resource: Trying to free nonexistent resource <0x300-0x307> baycom_ser_fdx: close ser_fdx at iobase 0x250 irq 9 Trying to free already-free IRQ 9 resource: Trying to free nonexistent resource <0x250-0x257>
and after the change a single close of bcsf1 and no warning. The baycom_par case was not reproduced, the test kernel has no parport support.
--- drivers/net/hamradio/hdlcdrv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/hamradio/hdlcdrv.c +2 -3
@@ -441,7 +441,6 @@ static int hdlcdrv_open(struct net_device *dev)/* * initialise some variables */ - s->opened =1 ; s->hdlcrx.hbuf.rd = s->hdlcrx.hbuf.wr =0 ; s->hdlcrx.in_hdlc_rx =0 ; s->hdlcrx.rx_state =0 ;
@@ -458,6 +457,7 @@ static int hdlcdrv_open(struct net_device *dev) i = s->ops->open (dev);if (i)return i; + s->opened =1 ;netif_start_queue (dev);return 0 ; }
@@ -725,8 +725,7 @@ void hdlcdrv_unregister(struct net_device *dev)BUG_ON (s->magic !=HDLCDRV_MAGIC ); -if (s->opened && s->ops->close) - s->ops->close (dev); +/* unregister_netdev() closes the device if it is still up */ unregister_netdev (dev);free_netdev (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 117/2151 mm/shmem: make shmem_file() check the files inode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit d3710111839d11339e414b1bb3fea3d05ab83f6e ]
shmem_file() only checks if file->f_mapping is a shmem mapping. This mapping can belong to another file, however, as with a Coda file backed by a tmpfs container after mmap().
So it does not guarantee that the file inode is an actual shmem inode.
Seal handling and memfd preservation use this check before accessing shmem inode state, so they can access an inode of the wrong type.
Let's make shmem_file() check the inode's file operations instead, to identify shmem inodes reliably. This will identify regular shmem inodes, including memfds and ordinary tmpfs files, independently of wrapper file operations.
Use shmem_mapping() in collapse_file() instead to not change the behavior of collapse_file(): it operates on the page cache and uses mapping->host for shmem inode operations. Focusing on the file does not seem relevant.
--- include/linux/shmem_fs.h | 15 ++++++--------- mm/khugepaged.c | 2 +- mm/shmem.c | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-)
include/linux/shmem_fs.h +6 -9
@@ -99,8 +99,14 @@ extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags);extern int shmem_lock (struct file *file,int lock,struct ucounts *ucounts);#ifdef CONFIG_SHMEM +bool shmem_file (struct file *file);bool shmem_mapping (const struct address_space *mapping);#else +static inline bool shmem_file (struct file *file) +{ +return false; +} +static inline bool shmem_mapping (const struct address_space *mapping) {return false;
@@ -171,15 +177,6 @@ static inline struct page *shmem_read_mapping_page( mapping_gfp_mask(mapping)); } -static inline bool shmem_file (struct file *file) -{ -if (!IS_ENABLED (CONFIG_SHMEM )) -return false; -if (!file || !file->f_mapping) -return false; -return shmem_mapping (file->f_mapping); -} -/* * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages * beyond i_size's notion of EOF, which fallocate has committed to reserving:
mm/khugepaged.c +1 -1
@@ -1860,6 +1860,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, struct collapse_control *cc) {struct address_space *mapping = file->f_mapping; +const bool is_shmem =shmem_mapping (mapping);struct page *dst;struct folio *folio, *tmp, *new_folio;unsigned long new_pfn =-1 ;
@@ -1867,7 +1868,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,LIST_HEAD (pagelist);XA_STATE_ORDER (xas, &mapping->i_pages, start,HPAGE_PMD_ORDER );int nr_none =0 , result =SCAN_SUCCEED ; -bool is_shmem =shmem_file (file);bool do_readahead = false;bool readahead_done = false;
mm/shmem.c +5 -0
@@ -275,6 +275,11 @@ static const struct vm_operations_struct shmem_vm_ops;static const struct vm_operations_struct shmem_anon_vm_ops;static struct file_system_type shmem_fs_type; +bool shmem_file (struct file *file) +{ +return file &&file_inode (file)->i_fop == &shmem_file_operations; +} +bool shmem_mapping (const struct address_space *mapping) {return mapping->a_ops == &shmem_aops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 118/2151 drm/amd/display: Reset DET of HUBPs without a plane before outstanding updates
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roman Li <[email protected]>
[ Upstream commit f3afbf7d832ab138655afc96bd42226775d03ce7 ]
[WHY]
DC asserts with:
WARNING: dc/hubbub/dcn401/dcn401_hubbub.c at dcn401_program_compbuf_segments
Call Trace: <TASK> dcn401_program_outstanding_updates+0x36/0x60 [amdgpu] hwss_process_outstanding_hw_updates+0x33/0x40 [amdgpu] commit_planes_for_stream+0x171f/0x1ff0 [amdgpu] dc_update_state_execute+0xaa/0x170 [amdgpu] dc_update_planes_and_stream+0x42/0x70 [amdgpu] amdgpu_dm_atomic_commit_tail+0x16a9/0x4020 [amdgpu] commit_tail+0xc3/0x1b0 [drm_kms_helper]
The DET left by the VBIOS on a HUBP without a plane can be larger than the DET planned for the new state. The compbuf is sized for the planned DET, so DET + compbuf can exceed the CRB size. Programming the compbuf then triggers the ASSERT and sets CONFIG_ERROR in hardware.
[HOW]
Release the DET of HUBPs without a plane before the compbuf is programmed.
Add hwss_reset_unused_det() and call it in the commit and flip paths, to cover both seamless and non-seamless boots.
--- drivers/gpu/drm/amd/display/dc/core/dc.c | 6 +++- .../drm/amd/display/dc/core/dc_hw_sequencer.c | 32 +++++++++++++++++++ .../drm/amd/display/dc/hwss/hw_sequencer.h | 3 ++ 3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +5 -1
@@ -2282,6 +2282,8 @@ static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *c* update pending complete before optimizing bandwidth. */ hwss_wait_for_odm_update_pending_complete (dc, context); +/* No DET may stay allocated to a HUBP without a plane (e.g. left over from VBIOS) */ +hwss_reset_unused_det (dc, context);/* pplib is notified if disp_num changed */ dc->hwss.optimize_bandwidth (dc, context);/* Need to do otg sync again as otg could be out of sync due to otg
@@ -4089,8 +4091,10 @@ static void commit_planes_for_stream(struct dc *dc,dc_exit_ips_for_hw_access (dc);dc_z10_restore (dc); -if (update_type ==UPDATE_TYPE_FULL && dc->optimized_required) +if (update_type ==UPDATE_TYPE_FULL && dc->optimized_required) { +hwss_reset_unused_det (dc, dc->current_state);hwss_process_outstanding_hw_updates (dc, dc->current_state); + }if (update_type !=UPDATE_TYPE_FAST && dc->res_pool->funcs->prepare_mcache_programming) dc->res_pool->funcs->prepare_mcache_programming (dc, context);
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +32 -0
@@ -32,6 +32,7 @@#include "resource.h" #include "dc_dmub_srv.h" #include "dc_state_priv.h" +#include "dchubbub.h" #define NUM_ELEMENTS (a) (sizeof(a) / sizeof((a)[0]))#define MAX_NUM_MCACHE 8
@@ -1194,6 +1195,37 @@ void hwss_wait_for_odm_update_pending_complete(struct dc *dc, struct dc_state *chwss_wait_for_all_blank_complete (dc, context); } +void hwss_reset_unused_det (struct dc *dc,struct dc_state *context) +{ +struct hubbub *hubbub = dc->res_pool->hubbub; +unsigned int i, j; + +if (!hubbub || !hubbub->funcs->program_det_segments) +return ; + +for (i =0 ; i < dc->res_pool->pipe_count; i++) { +struct hubp *hubp = dc->res_pool->hubps[i]; +bool hubp_in_use = false; + +if (!hubp) +continue ; + +for (j =0 ; j < dc->res_pool->pipe_count; j++) { +const struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[j]; + +/* A plane-less pipe renders from the DPG, its HUBP (assigned with the stream) needs no DET */ +if (pipe->plane_state && pipe->plane_res.hubp && + pipe->plane_res.hubp->inst == hubp->inst) { + hubp_in_use = true; +break ; + } + } + +if (!hubp_in_use) + hubbub->funcs->program_det_segments (hubbub, hubp->inst,0 ); + } +} +void hwss_wait_for_no_pipes_pending (struct dc *dc,struct dc_state *context) {int i;
drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h +3 -0
@@ -566,6 +566,9 @@ void hwss_wait_for_odm_update_pending_complete(struct dc *dc,void hwss_wait_for_no_pipes_pending (struct dc *dc,struct dc_state *context); +void hwss_reset_unused_det (struct dc *dc, +struct dc_state *context); +void hwss_wait_for_outstanding_hw_updates (struct dc *dc,struct dc_state *dc_context);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 119/2151 mm/shmem: fix accounting of swapin-error markers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 66ce68a249f4ac56cd6968aa6d8ded20fb4b7d09 ]
A failed swap read replaces the swap entry with a swapin-error marker in the page-cache and subtracts its pages from "alloced" and "swapped"; however, it leaves their block charge in place.
Removing the marker during truncate then subtracts from "swapped" again. This can underflow the counters or make swapped reach zero while other pages remain swapped out, causing swapoff to loop without finding them.
When installing the marker, subtract only from "swapped" and let shmem_recalc_inode() reduce "alloced" and release the block charge.
Make shmem_free_swap() report successful removal separately from the number of swap pages freed, so removing a swapin-error marker does not subtract from "swapped" again.
It's a bit confusing, but replacing a swapped out page by a swapin-error marker in shmem_set_folio_swapin_error() behaves as follows:
Initially:
alloced=1, swapped=1, nrpages=0 Calling shmem_recalc_inode(inode, 0, -1) -> swapped = 0 -> freed = 1 - 0 - 0 = 1 -> alloced -= freed -> alloced=0, swapped=0, block charge released
--- mm/shmem.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
mm/shmem.c +14 -17
@@ -945,12 +945,11 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) }/* -* Remove swap entry from page cache, free the swap and its page cache. Returns -* the number of pages being freed. 0 means entry not found in XArray (0 pages -* being freed). +* Remove a swap entry or swapin-error marker wholly within [index, end]. +* Return whether it was removed, counting freed swap pages in nr_swaps_freed. */ -static long shmem_free_swap (struct address_space *mapping, -pgoff_t index,pgoff_t end,void *radswap) +static bool shmem_free_swap (struct address_space *mapping, +pgoff_t index,pgoff_t end,void *radswap,long *nr_swaps_freed) {XA_STATE (xas, &mapping->i_pages, index);const swp_entry_t swp =radix_to_swp_entry (radswap);
@@ -971,8 +970,10 @@ static long shmem_free_swap(struct address_space *mapping,xas_unlock_irq (&xas);/* A swapin-error marker holds no swap slot, so just drop it. */ -if (nr_pages && !non_swap_entry (swp)) +if (nr_pages && !non_swap_entry (swp)) {free_swap_and_cache_nr (swp, nr_pages); + *nr_swaps_freed += nr_pages; + }return nr_pages; }
@@ -1125,8 +1126,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,if (xa_is_value (folio)) {if (unfalloc)continue ; - nr_swaps_freed +=shmem_free_swap (mapping, indices[i], - end -1 , folio); +shmem_free_swap (mapping, indices[i], end -1 , + folio, &nr_swaps_freed);continue ; }
@@ -1193,13 +1194,11 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,if (xa_is_value (folio)) {int order; -long swaps_freed;if (unfalloc)continue ; - swaps_freed =shmem_free_swap (mapping, indices[i], - end -1 , folio); -if (!swaps_freed) { +if (!shmem_free_swap (mapping, indices[i], end -1 , + folio, &nr_swaps_freed)) {pgoff_t base = indices[i]; order = shmem_confirm_swap(mapping, indices[i],
@@ -1220,7 +1219,6 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, index = base;break ; } - nr_swaps_freed += swaps_freed;continue ; }
@@ -2243,11 +2241,10 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,if (!skip_swapcache)swap_cache_del_folio (folio);/* -* Don't treat swapin error folio as alloced. Otherwise inode->i_blocks -* won't be 0 when inode is released and thus trigger WARN_ON(i_blocks) -* in shmem_evict_inode(). +* Let shmem_recalc_inode() reduce alloced and release the block charge +* for the freed swap pages. */ -shmem_recalc_inode (inode, -nr_pages, -nr_pages); +shmem_recalc_inode (inode,0 , -nr_pages);swap_free_nr (swap, nr_pages); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 120/2151 ovl: inherit FMODE_NONOTIFY when reading directory layers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 9ff338af0e002fe217cfa16b1289b76f6b21fc72 ]
Listing a merged or impure overlay directory opens the real layer directories from ovl_dir_read(), when the readdir cache is filled. Those opens use plain ovl_path_open(), so when the directory fd is one that fanotify created for a permission event, they can still raise FS_OPEN_PERM. A listener that also marks the backing filesystem and calls getdents() on the event fd before answering then deadlocks the same way as with the directory open fixed by the previous commit.
Store the overlay user file in struct ovl_readdir_data and pass it to ovl_path_open_realfile() from ovl_dir_read(), for both the merged and the impure cache. Internal readers such as ovl_check_empty_dir() and the mount-time workdir cleanup still pass no user file.
A note about severity and real world impact: The FAN_OPEN_PERM event is traditionally used by anti-malware protection agents and security/audit agents. The scope that is often used in those use cases is FAN_MARK_MOUNT and agents typically monitor multiple mounts in a mount namespace. FAN_OPEN_PERM from directory open requires user opt-in with FAN_ONDIR. It is often not the case that anti-malware agents monitor open of directories. Security/audit engines are more likely to opt-into FAN_OPEN_PERM on directories, but are less likely to list the content of a directory within the scope of FAN_OPEN_PERM event, so the real world impact of this bug is likely not significant.
--- fs/overlayfs/readdir.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
fs/overlayfs/readdir.c +17 -11
@@ -41,6 +41,7 @@ struct ovl_dir_cache {struct ovl_readdir_data {struct dir_context ctx; +const struct file *user_file;struct dentry *dentry;bool is_lowest;struct rb_root *root;
@@ -380,7 +381,8 @@ static inline int ovl_dir_read(const struct path *realpath,struct file *realfile;int err; - realfile =ovl_path_open (realpath,O_RDONLY |O_LARGEFILE ); + realfile =ovl_path_open_realfile (rdd->user_file, realpath, +O_RDONLY |O_LARGEFILE );if (IS_ERR (realfile))return PTR_ERR (realfile);
@@ -424,13 +426,14 @@ static void ovl_dir_reset(struct file *file) }static int ovl_dir_read_merged (struct dentry *dentry,struct list_head *list, -struct rb_root *root) +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_merge, .ctx.count =INT_MAX , + .user_file = user_file, .dentry = dentry, .list = list, .root = root,
@@ -483,9 +486,10 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos) od->cursor = p; } -static struct ovl_dir_cache *ovl_cache_get (struct dentry *dentry) +static struct ovl_dir_cache *ovl_dir_cache_get (struct file *file) {int res; +struct dentry *dentry = file->f_path.dentry;struct ovl_dir_cache *cache;struct inode *inode =d_inode (dentry);
@@ -505,7 +509,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)INIT_LIST_HEAD (&cache->entries); cache->root =RB_ROOT ; - res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root); + res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -649,8 +653,8 @@ static bool ovl_fill_plain(struct dir_context *ctx, const char *name,return true; } -static int ovl_dir_read_impure (const struct path *path,struct list_head *list, -struct rb_root *root) +static int ovl_dir_read_impure (const struct path *path,struct list_head *list, +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;
@@ -658,6 +662,7 @@ static int ovl_dir_read_impure(const struct path *path, struct list_head *list,struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_plain, .ctx.count =INT_MAX , + .user_file = user_file, .list = list, .root = root, };
@@ -695,9 +700,10 @@ static int ovl_dir_read_impure(const struct path *path, struct list_head *list,return 0 ; } -static struct ovl_dir_cache *ovl_cache_get_impure (const struct path *path) +static struct ovl_dir_cache *ovl_cache_get_impure (struct file *file) {int res; +const struct path *path = &file->f_path;struct dentry *dentry = path->dentry;struct inode *inode =d_inode (dentry);struct ovl_fs *ofs =OVL_FS (dentry->d_sb);
@@ -715,7 +721,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path)if (!cache)return ERR_PTR (-ENOMEM ); - res =ovl_dir_read_impure (path, &cache->entries, &cache->root); + res =ovl_dir_read_impure (path, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -836,7 +842,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)dput (parent);if (ovl_is_impure_dir (file)) { - rdt.cache =ovl_cache_get_impure (&file->f_path); + rdt.cache =ovl_cache_get_impure (file);if (IS_ERR (rdt.cache))return PTR_ERR (rdt.cache); }
@@ -884,7 +890,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)if (!od->cache) {struct ovl_dir_cache *cache; - cache =ovl_cache_get (dentry); + cache =ovl_dir_cache_get (file); err =PTR_ERR (cache);if (IS_ERR (cache)) goto out;
@@ -1086,7 +1092,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)const struct cred *old_cred; old_cred =ovl_override_creds (dentry->d_sb); - err =ovl_dir_read_merged (dentry, list, &root); + err =ovl_dir_read_merged (dentry, list, &root,NULL );ovl_revert_creds (old_cred);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 121/2151 comedi: addi_apci_3xxx: fix subdevice count underallocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Zi <[email protected]>
[ Upstream commit 3de5aa458dede472a253266d02902bd95af8e849 ]
In apci3xxx_auto_attach(), the number of subdevices is computed with
n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao + ...
The ternary is inverted: when the board has analog input channels (ai_n_chan != 0), it counts 0 instead of 1, so the AI subdevice that is actually created is not accounted for. As a result comedi_alloc_subdevices() allocates one entry too few, and the later subdevice initialization (notably the TTL Digital I/O subdevice, which is populated last) writes past the end of the allocated array, causing a slab out-of-bounds write.
Flip the ternary to count 1 when ai_n_chan is non-zero and 0 otherwise, matching the subdevice creation order in the function.
--- drivers/comedi/drivers/addi_apci_3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/addi_apci_3xxx.c +1 -1
@@ -787,7 +787,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - n_subdevices = (board->ai_n_chan ?0 :1 ) + board->has_ao + + n_subdevices = (board->ai_n_chan ?1 :0 ) + board->has_ao + board->has_dig_in + board->has_dig_out + board->has_ttl_io; ret =comedi_alloc_subdevices (dev, n_subdevices);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 122/2151 comedi: dt2811: fix shift-out-of-bounds in IRQ check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 471ce96a9c415b8a67bd5081ac2089a458cacc2f ]
The IRQ number passed via comedi_devconfig->options[1] is a signed int that comes from userspace. The check it->options[1] <= 7 does not reject negative values, so a negative IRQ number reaches BIT(it->options[1]), which is undefined behavior and triggers a UBSAN shift-out-of-bounds warning:
UBSAN: shift-out-of-bounds in drivers/comedi/drivers/dt2811.c:570:31 shift exponent -251 is negative
Add an explicit lower bound check (it->options[1] >= 0) so that only valid IRQ numbers 0..7 are accepted before the shift.
--- drivers/comedi/drivers/dt2811.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/dt2811.c +1 -1
@@ -566,7 +566,7 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)dt2811_reset (dev);/* IRQ's 2,3,5,7 are valid for async command support */ -if (it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { +if (it->options[1 ] >=0 && it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { ret =request_irq (it->options[1 ], dt2811_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 123/2151 ACPI: button: Enable wakeup GPEs for ACPI buttons at probe time
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit a004b8f0d3bc5d82d3f2c91ff93f4b4b7ccb8f76 ]
Prior to commit 57c31e6d620f ("ACPI: scan: Use acpi_setup_gpe_for_wake() for buttons"), ACPI button wakeup GPEs having handler methods remained enabled after acpi_wakeup_gpe_init(), but currently they are not enabled because acpi_setup_gpe_for_wake() disables them.
That causes function keys to stop working on some systems [1] and there may be other related issues elsewhere.
To address that, make the ACPI button driver enable wakeup GPEs for ACPI buttons so long as they have handler methods. While this does not restore the old behavior exactly (the ACPI button driver needs to be bound to the button devices for the GPEs to be enabled), it should be sufficient to restore the missing functionality.
For this purpose, introduce acpi_enable_gpe_cond() that enables a GPE if its dispatch type matches the supplied one and modify acpi_button_probe() to use that function for enabling the GPEs in question.
[ Adjusted for 6.18.y: struct acpi_button has no dev member in this
tree, so use &button->pdev->dev in the two dev_dbg() calls. ]
--- drivers/acpi/acpica/evxfgpe.c | 50 ++++++++++++++++++++++++++++------- drivers/acpi/button.c | 22 +++++++++++++++ include/acpi/acpixf.h | 5 ++++ 3 files changed, 68 insertions(+), 9 deletions(-)
drivers/acpi/acpica/evxfgpe.c +41 -9
@@ -78,18 +78,22 @@ ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)/******************************************************************************* * -* FUNCTION: acpi_enable_gpe +* FUNCTION: acpi_enable_gpe_cond * * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 * gpe_number - GPE level within the GPE block +* dispatch_type - GPE dispatch type to match * * RETURN: Status * -* DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is -* hardware-enabled. +* DESCRIPTION: Add a reference to a GPE so long as its dispatch type matches +* the supplied one, or it is different from ACPI_GPE_DISPATCH_NONE +* if the supplied one is ACPI_GPE_DISPATCH_MASK. On the first +* reference, the GPE is hardware-enabled. * ******************************************************************************/ -acpi_status acpi_enable_gpe (acpi_handle gpe_device,u32 gpe_number) +acpi_status acpi_enable_gpe_cond (acpi_handle gpe_device,u32 gpe_number, +u8 dispatch_type) {acpi_status status =AE_BAD_PARAMETER ;struct acpi_gpe_event_info *gpe_event_info;
@@ -100,14 +104,18 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number) flags =acpi_os_acquire_lock (acpi_gbl_gpe_lock);/* -* Ensure that we have a valid GPE number and that there is some way -* of handling the GPE (handler or a GPE method). In other words, we -* won't allow a valid GPE to be enabled if there is no way to handle it. +* Ensure that we have a valid GPE number and that the dispatch type of +* the GPE matches the supplied one (or it is not ACPI_GPE_DISPATCH_NONE +* if the supplied one is ACPI_GPE_DISPATCH_MASK). */ gpe_event_info =acpi_ev_get_gpe_event_info (gpe_device, gpe_number);if (gpe_event_info) { -if (ACPI_GPE_DISPATCH_TYPE (gpe_event_info->flags) != -ACPI_GPE_DISPATCH_NONE ) { +if (dispatch_type ==ACPI_GPE_DISPATCH_MASK ) + dispatch_type =ACPI_GPE_DISPATCH_TYPE (gpe_event_info->flags); +else if (dispatch_type !=ACPI_GPE_DISPATCH_TYPE (gpe_event_info->flags)) + dispatch_type =ACPI_GPE_DISPATCH_NONE ; + +if (dispatch_type !=ACPI_GPE_DISPATCH_NONE ) { status =acpi_ev_add_gpe_reference (gpe_event_info, TRUE);if (ACPI_SUCCESS (status) &&ACPI_GPE_IS_POLLING_NEEDED (gpe_event_info)) {
@@ -128,6 +136,30 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)acpi_os_release_lock (acpi_gbl_gpe_lock, flags);return_ACPI_STATUS (status); } +ACPI_EXPORT_SYMBOL (acpi_enable_gpe_cond) + +/******************************************************************************* +* +* FUNCTION: acpi_enable_gpe +* +* PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 +* gpe_number - GPE level within the GPE block +* +* RETURN: Status +* +* DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is +* hardware-enabled. +* +******************************************************************************/ +acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number) +{ +/* +* Ensure that there is some way of handling the GPE (handler or a GPE +* method). In other words, we won't allow a valid GPE to be enabled if +* there is no way to handle it. +*/ +return acpi_enable_gpe_cond (gpe_device, gpe_number,ACPI_GPE_DISPATCH_MASK ); +}ACPI_EXPORT_SYMBOL (acpi_enable_gpe)/*******************************************************************************
drivers/acpi/button.c +22 -0
@@ -190,6 +190,7 @@ struct acpi_button {ktime_t last_time;bool suspended;bool lid_state_initialized; +bool gpe_enabled; };static struct acpi_device *lid_device;
@@ -651,6 +652,21 @@ static int acpi_button_probe(struct platform_device *pdev) status =acpi_install_notify_handler (device->handle,ACPI_ALL_NOTIFY , handler, button); +if (ACPI_SUCCESS (status) && device->wakeup.flags.valid) { +acpi_status st; + +/* +* If the wakeup GPE has a handler method, enable it in +* case it is also used for signaling runtime events. +*/ + st =acpi_enable_gpe_cond (device->wakeup.gpe_device, + device->wakeup.gpe_number, +ACPI_GPE_DISPATCH_METHOD ); + button->gpe_enabled =ACPI_SUCCESS (st); +if (button->gpe_enabled) +dev_dbg (&button->pdev->dev,"Enabled ACPI GPE%02llx\n" , + device->wakeup.gpe_number); + }break ; }if (ACPI_FAILURE (status)) {
@@ -694,6 +710,12 @@ static void acpi_button_remove(struct platform_device *pdev) acpi_button_event);break ;default : +if (button->gpe_enabled) { +dev_dbg (&button->pdev->dev,"Disabling ACPI GPE%02llx\n" , + adev->wakeup.gpe_number); +acpi_disable_gpe (adev->wakeup.gpe_device, + adev->wakeup.gpe_number); + } acpi_remove_notify_handler(adev->handle, ACPI_ALL_NOTIFY, button->type == ACPI_BUTTON_TYPE_LID ? acpi_lid_notify :
include/acpi/acpixf.h +5 -0
@@ -725,6 +725,11 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status*/ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_update_all_gpes(void)) +ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status + acpi_enable_gpe_cond(acpi_handle gpe_device, + u32 gpe_number, + u8 dispatch_type)) + ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 124/2151 ALSA: hda/realtek: Enable mute and mic-mute LEDs on HP ENVY 17-cr0xxx
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandr <[email protected]>
commit cf79cc4996bf936fe159af2a600519b3ebd4ccb7 upstream.
The HP ENVY Laptop 17-cr0xxx (subsystem ID 103c:8a2e) has mute and mic-mute LEDs on the F8 and F5 keys that never light up on Linux: the existing quirk entry only sets up the CS35L41 amplifiers.
The board uses the same LED wiring as the HP ENVY x360 15-ey0xxx (103c:8a31): the mute LED is driven by COEF 0x0b bits 3:2 and the mic-mute LED by GPIO2 with inverted polarity. Both were verified with hda-verb on the actual hardware. Switch the entry to ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS, which chains the amplifier setup with ALC245_FIXUP_HP_X360_MUTE_LEDS, and use the DMI product name of the board.
--- sound/hda/codecs/realtek/alc269.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +1 -1
@@ -6991,7 +6991,7 @@ static const struct hda_quirk alc269_fixSND_PCI_QUIRK (0x103c ,0x8a2b ,"HP Envy 15" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8a2c ,"HP Envy 16" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8a2d ,"HP Envy 16" ,ALC287_FIXUP_CS35L41_I2C_2 ), -SND_PCI_QUIRK (0x103c ,0x8a2e ,"HP Envy 16" ,ALC287_FIXUP_CS35L41_I2C_2 ), +SND_PCI_QUIRK (0x103c ,0x8a2e ,"HP ENVY Laptop 17-cr0xxx" ,ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS ),SND_PCI_QUIRK (0x103c ,0x8a30 ,"HP Envy 17" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8a31 ,"HP Envy 15" ,ALC287_FIXUP_CS35L41_I2C_2 ), SND_PCI_QUIRK(0x103c, 0x8a34, "HP Pavilion x360 2-in-1 Laptop 14-ek0xxx", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
Greg Kroah-Hartman
maintainerPATCH 125/2151 serial: max310x: schedule tx_work directly from the IRQ handler
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
commit c06fcc258db0c0c7f607e64a7ce6a157bb2414b1 upstream.
The TXEMPTY interrupt asks for a FIFO refill, and start_tx() does nothing beyond scheduling tx_work, so going through it makes no functional difference. It does conflate two distinct events, though:start_tx() is the serial core starting a new transmission, while TXEMPTY can only fire for a transmission that is already running - the bit latches on the FIFO's non-empty to empty transition, and the IRQ handler's read of IRQSTS consumes the latch, so a stale TXEMPTY cannot exist on an idle port (if the bit were level-triggered, the handler's read-until-clear loop would never terminate).
Schedule tx_work directly, keeping the interrupt path a pure FIFO refill. This is preparation for a following patch that adds software-timed RS485 RTS control, where start_tx() also starts the RTS envelope and a refill must not restart it.
No functional change.
--- drivers/tty/serial/max310x.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/max310x.c +5 -1
@@ -810,8 +810,12 @@ static irqreturn_t max310x_port_irq(stru }if (rxlen)max310x_handle_rx (port, rxlen); +/* +* TXEMPTY latches on the FIFO becoming empty, so a stale +* interrupt cannot pump data during an RTS setup delay. +*/ if (ists &MAX310X_IRQ_TXEMPTY_BIT ) -max310x_start_tx (port); +schedule_work (&s->p[portno].tx_work); }while (1 );return res;
Greg Kroah-Hartman
maintainerPATCH 126/2151 x86/cpufeatures: Make X86_FEATURE leaf 17 Linux-specific
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Borislav Petkov (AMD) <[email protected]>
commit ddde4abaa0ecc8395e0fcfa3e92f65d481890cc8 upstream.
That cpuinfo_x86.x86_capability[] element was supposed to mirror CPUID flags from CPUID_0x80000007_EBX but that leaf has still to this day only three bits defined in it. So move those bits to scattered.c and free the capability element for synthetic flags.
No functional changes.
--- arch/x86/include/asm/cpufeature.h | 2 +- arch/x86/include/asm/cpufeatures.h | 5 ++++- arch/x86/kernel/cpu/common.c | 8 ++------ arch/x86/kernel/cpu/scattered.c | 3 +++ arch/x86/kvm/reverse_cpuid.h | 1 - tools/arch/x86/include/asm/cpufeatures.h | 5 ++++- 6 files changed, 14 insertions(+), 10 deletions(-)
arch/x86/include/asm/cpufeature.h +1 -1
@@ -30,7 +30,7 @@ enum cpuid_leafsCPUID_6_EAX ,CPUID_8000_000A_EDX ,CPUID_7_ECX , -CPUID_8000_0007_EBX , +CPUID_LNX_6 ,CPUID_7_EDX ,CPUID_8000_001F_EAX , CPUID_8000_0021_EAX,
arch/x86/include/asm/cpufeatures.h +4 -1
@@ -407,9 +407,12 @@#define X86_FEATURE_ENQCMD (16*32+29)/* "enqcmd" ENQCMD and ENQCMDS instructions */ #define X86_FEATURE_SGX_LC (16*32+30)/* "sgx_lc" Software Guard Extensions Launch Control */ -/* AMD-defined CPU features, CPUID level 0x80000007 (EBX), word 17 */ +/* +* Linux-defined word for use with scattered/synthetic bits. +*/ #define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0)/* "overflow_recov" MCA overflow recovery support */ #define X86_FEATURE_SUCCOR (17*32+ 1)/* "succor" Uncorrectable error containment and recovery */ +#define X86_FEATURE_SMCA (17*32+ 3)/* "smca" Scalable MCA */ #define X86_FEATURE_BTB_CTX_ISOLATION (17*32+ 4)/* AMD: Branch predictions contexts isolated */
arch/x86/kernel/cpu/common.c +2 -6
@@ -1025,12 +1025,8 @@ void get_cpu_cap(struct cpuinfo_x86 *c) c->x86_capability[CPUID_8000_0001_EDX ] = edx; } -if (c->extended_cpuid_level >=0x80000007 ) { -cpuid (0x80000007 , &eax, &ebx, &ecx, &edx); - - c->x86_capability[CPUID_8000_0007_EBX ] = ebx; - c->x86_power = edx; - } +if (c->extended_cpuid_level >=0x80000007 ) + c->x86_power =cpuid_edx (0x80000007 );if (c->extended_cpuid_level >=0x80000008 ) {cpuid (0x80000008 , &eax, &ebx, &ecx, &edx);
arch/x86/kernel/cpu/scattered.c +3 -0
@@ -44,6 +44,9 @@ static const struct cpuid_bit cpuid_bits { X86_FEATURE_SGX1, CPUID_EAX, 0, 0x00000012, 0 }, { X86_FEATURE_SGX2, CPUID_EAX, 1, 0x00000012, 0 }, { X86_FEATURE_SGX_EDECCSSA, CPUID_EAX, 11, 0x00000012, 0 }, + { X86_FEATURE_OVERFLOW_RECOV, CPUID_EBX, 0, 0x80000007, 0 }, + { X86_FEATURE_SUCCOR, CPUID_EBX, 1, 0x80000007, 0 }, + { X86_FEATURE_SMCA, CPUID_EBX, 3, 0x80000007, 0 }, { X86_FEATURE_HW_PSTATE, CPUID_EDX, 7, 0x80000007, 0 }, { X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 },
arch/x86/kvm/reverse_cpuid.h +0 -1
@@ -79,7 +79,6 @@ static const struct cpuid_reg reverse_cp [CPUID_6_EAX] = { 6, 0, CPUID_EAX}, [CPUID_8000_000A_EDX] = {0x8000000a, 0, CPUID_EDX}, [CPUID_7_ECX] = { 7, 0, CPUID_ECX}, - [CPUID_8000_0007_EBX] = {0x80000007, 0, CPUID_EBX}, [CPUID_7_EDX] = { 7, 0, CPUID_EDX}, [CPUID_7_1_EAX] = { 7, 1, CPUID_EAX}, [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX},
tools/arch/x86/include/asm/cpufeatures.h +4 -1
@@ -407,9 +407,12 @@#define X86_FEATURE_ENQCMD (16*32+29)/* "enqcmd" ENQCMD and ENQCMDS instructions */ #define X86_FEATURE_SGX_LC (16*32+30)/* "sgx_lc" Software Guard Extensions Launch Control */ -/* AMD-defined CPU features, CPUID level 0x80000007 (EBX), word 17 */ +/* +* Linux-defined word for use with scattered/synthetic bits. +*/ #define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0)/* "overflow_recov" MCA overflow recovery support */ #define X86_FEATURE_SUCCOR (17*32+ 1)/* "succor" Uncorrectable error containment and recovery */ +#define X86_FEATURE_SMCA (17*32+ 3)/* "smca" Scalable MCA */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
Greg Kroah-Hartman
maintainerPATCH 127/2151 drm/komeda: Fix bits parsing of GLB_CORE_ID
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raveendra Talabattula <[email protected]>
[ Upstream commit ec902de0221747094f9ccbb61454e9633fbf282f ]
GLB_CORE_ID contains the product and version information returned by the hardware. The current macros parses VERSION_MINOR as a 4-bit field and VERSION_STATUS as an 8-bit field, which does not match the register layout. As a result, the driver reports an incorrect version number.
Fix the parsing macros to match the hardware specification:
- VERSION_MINOR is 8 bits at [11:4]
- VERSION_STATUS is 4 bits at [3:0]
--- drivers/gpu/drm/arm/display/include/malidp_product.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/display/include/malidp_product.h +7 -3
@@ -8,14 +8,18 @@#define _MALIDP_PRODUCT_H_/* Product identification */ +/* GLB_CORE_ID fields as per HW specification: +* MINOR is 8 bits ([11:4]) and STATUS is 4 bits ([3:0]). +* Update masks/shifts accordingly. +*/ #define MALIDP_CORE_ID (__product, __major, __minor, __status) \ ((((__product) & 0xFFFF) << 16) | (((__major) & 0xF) << 12) | \ - (((__minor) & 0xF) << 8) | ((__status) & 0xFF)) + (((__minor) & 0xFF) << 4) | ((__status) & 0xF))#define MALIDP_CORE_ID_PRODUCT_ID (__core_id) ((__u32)(__core_id) >> 16)#define MALIDP_CORE_ID_MAJOR (__core_id) (((__u32)(__core_id) >> 12) & 0xF) -#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 8) & 0xF) -#define MALIDP_CORE_ID_STATUS (__core_id) (((__u32)(__core_id)) & 0xFF) +#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 4) & 0xFF) +#define MALIDP_CORE_ID_STATUS (__core_id) ((__u32)(__core_id) & 0xF)/* Mali-display product IDs */ #define MALIDP_D71_PRODUCT_ID 0x0071
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 128/2151 accel/qaic: reject BO sizes that overflow page count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao-Qun Huang <[email protected]>
[ Upstream commit 568d4cb5dcc5ec4e22975699b6ea67a30806884c ]
create_sgt() receives the BO size as a u64 but stores the number of pages in an int. qaic_create_bo_ioctl() page-aligns the user-supplied size without an upper bound, so DIV_ROUND_UP(size, PAGE_SIZE) can exceed INT_MAX and truncate when assigned to nr_pages.
When the page count wraps to a small positive value (for example a BO larger than 16 TiB on a 4 KiB page kernel), create_sgt() succeeds after allocating only a handful of pages while the GEM object still records the full size, so the request never fails with -ENOMEM. The temporary pages array and the allocation loop both use the truncated count, so the backing SG table ends up smaller than obj->size. Later slice operations validate against obj->size and then clone ranges from this short sgt.
Compute the page count as a u64 and reject sizes that do not fit in nr_pages before the narrowing conversion.
--- drivers/accel/qaic/qaic_data.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/accel/qaic/qaic_data.c +7 -1
@@ -15,6 +15,7 @@#include <linux/math64.h> #include <linux/mm.h> #include <linux/moduleparam.h> +#include <linux/overflow.h> #include <linux/scatterlist.h> #include <linux/spinlock.h> #include <linux/srcu.h>
@@ -454,7 +455,12 @@ static int create_sgt(struct qaic_device *qdev, struct sg_table **sgt_out, u64 sint order;if (size) { - nr_pages =DIV_ROUND_UP (size,PAGE_SIZE ); +u64 nr_pages_u64 =DIV_ROUND_UP_ULL (size,PAGE_SIZE ); + +if (overflows_type (nr_pages_u64, int)) +return -E2BIG ; + + nr_pages = nr_pages_u64;/* * calculate how much extra we are going to allocate, to remove * later
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 129/2151 drm/panfrost: Prevent division by 0
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit fd4227f03546c323b5b21568f727233e9792d298 ]
When updating and debug-printing devfreq stats, in the very unlikely off-chance that total device time is less than 100 ns, division by 0 would happen. Fix the divisor when relevant and rearrange operands.
--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_devfreq.c +1 -1
@@ -76,7 +76,7 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,dev_dbg (pfdev->dev,"busy %lu total %lu %lu %% freq %lu MHz\n" , status->busy_time, status->total_time, - status->busy_time / (status->total_time /100 ), + status->busy_time *100 /MAX (status->total_time,1 ), status->current_frequency /1000 /1000 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 130/2151 bpf: sched_ext: Mark ops argument container pointer fields as trusted
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit aed1bf1a352acd4f5ffd2a81e23d2bb6e8e9b636 ]
Walking an unannotated pointer field of a trusted struct yields a bare PTR_TO_BTF_ID in non-sleepable programs, which kfuncs and helpers accept, but PTR_UNTRUSTED in sleepable programs, which they reject. This gets in the way of making ops.init_task() sleepable, which schedulers want for allocations. For example, passing args->cgroup into bpf_cgrp_storage_get() then fails verification and the only recourse is round-tripping through the cgroup ID with bpf_cgroup_from_id().
The pointer fields in the sched_ext ops argument containers are all pinned by the callers for the duration of the ops calls and are never NULL. Add them to the verifier's trusted-fields whitelist so that they are PTR_TRUSTED in both sleepable and non-sleepable programs.
--- kernel/bpf/verifier.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
kernel/bpf/verifier.c +26 -0
@@ -7304,6 +7304,28 @@ BTF_TYPE_SAFE_TRUSTED(struct file) {struct inode *f_inode; }; +/* +* The pointer fields in the sched_ext ops argument containers are pinned by the +* callers for the duration of the ops calls and are never NULL. +*/ +BTF_TYPE_SAFE_TRUSTED(struct scx_init_task_args) { +#ifdef CONFIG_EXT_GROUP_SCHED +struct cgroup *cgroup; +#endif +}; + +BTF_TYPE_SAFE_TRUSTED(struct scx_cpu_release_args) { +struct task_struct *task; +}; + +BTF_TYPE_SAFE_TRUSTED(struct scx_sub_attach_args) { +struct sched_ext_ops *ops; +}; + +BTF_TYPE_SAFE_TRUSTED(struct scx_sub_detach_args) { +struct sched_ext_ops *ops; +}; + BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct dentry) {struct inode *d_inode; };
@@ -7343,6 +7365,10 @@ static bool type_is_trusted(struct bpf_verifier_env *env,BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct bpf_iter__task ));BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct linux_binprm ));BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct file )); +BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct scx_init_task_args )); +BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct scx_cpu_release_args )); +BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct scx_sub_attach_args )); +BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED(struct scx_sub_detach_args ));return btf_nested_type_is_trusted (&env->log, reg, field_name, btf_id,"__safe_trusted" ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 131/2151 drm/omap: dsi: avoid sending bta sync all the time in writes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andreas Kemnade <[email protected]>
[ Upstream commit 20207f78382ff339f3a7f7c5db2c0219b157d32a ]
Some chips need configuration commands to be sent first, before they can send data. TC358762 for example needs PPI_LPTXTIMECNT configured and PPI_STARTPPI set to 1 to be able to transmit anything. To be able to configure such chips, do not send bta sync during writes if no acks are requested. Instead just wait for the packet to be sent to avoid FIFO overflows. There might be more to do about acks, but there seem to be virtually no users of that flag.
This came to light when fiddling with the Epson Moverio BT-200 display which consists of 2 TC358762 bridges with SPI funneled through to the unknown display chip. With that patch the bridge can be accessed, Reading back registers works, when the above-mentioned registers are set.
In Command-Mode update, there was a nop sent, apparently the most relevant part was the bta sync to actually force low power mode.
Video mode panel at OMAP4 (BT-200) and video mode at OMAP5 was tested.
--- drivers/gpu/drm/omapdrm/dss/dsi.c | 63 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/gpu/drm/omapdrm/dss/dsi.c +31 -32
@@ -58,9 +58,6 @@ static void dsi_uninit_dispc(struct dsi_data *dsi);static int dsi_vc_send_null (struct dsi_data *dsi,int vc,int channel); -static ssize_t _omap_dsi_host_transfer (struct dsi_data *dsi,int vc, -const struct mipi_dsi_msg *msg); -#ifdef DSI_PERF_MEASURE static bool dsi_perf;module_param (dsi_perf, bool,0644 );
@@ -2189,28 +2186,45 @@ static int dsi_vc_send_null(struct dsi_data *dsi, int vc, int channel)static int dsi_vc_write_common (struct omap_dss_device *dssdev,int vc,const struct mipi_dsi_msg *msg) { +DECLARE_COMPLETION_ONSTACK (completion);struct dsi_data *dsi =to_dsi_data (dssdev); +u32 err;int r; +/* wait for IRQ for packet transmission confirmation */ + r =dsi_register_isr_vc (dsi, vc, dsi_completion_handler, + &completion,DSI_VC_IRQ_PACKET_SENT ); +if (r) +return r; +if (mipi_dsi_packet_format_is_short (msg->type)) r =dsi_vc_send_short (dsi, vc, msg);else r =dsi_vc_send_long (dsi, vc, msg); -if (r <0 ) +if ((!r) &&wait_for_completion_timeout (&completion, +msecs_to_jiffies (500 )) ==0 ) + r = -EIO ; + +dsi_unregister_isr_vc (dsi, vc, dsi_completion_handler, + &completion,DSI_VC_IRQ_PACKET_SENT ); +if (r)return r; -/* -* TODO: we do not always have to do the BTA sync, for example -* we can improve performance by setting the update window -* information without sending BTA sync between the commands. -* In that case we can return early. -*/ +/* TODO: find out if more needs to be done for MIPI_DSI_MSG_REQ_ACK */ - r =dsi_vc_send_bta_sync (dssdev, vc); -if (r) { -DSSERR ("bta sync failed\n" ); -return r; +if (msg->flags &MIPI_DSI_MSG_REQ_ACK ) { + r =dsi_vc_send_bta_sync (dssdev, vc); +if (r) { +DSSERR ("bta sync failed\n" ); +return r; + } + }else { + err =dsi_get_errors (dsi); +if (err) { +DSSERR ("Error while sending: %x\n" , err); +return -EIO ; + } }/* RX_FIFO_NOT_EMPTY */
@@ -3228,21 +3242,6 @@ static int _dsi_update(struct dsi_data *dsi)return 0 ; } -static int _dsi_send_nop (struct dsi_data *dsi,int vc,int channel) -{ -const u8 payload[] = {MIPI_DCS_NOP }; -const struct mipi_dsi_msg msg = { - .channel = channel, - .type =MIPI_DSI_DCS_SHORT_WRITE , - .tx_len =1 , - .tx_buf = payload, - }; - -WARN_ON (!dsi_bus_is_locked (dsi)); - -return _omap_dsi_host_transfer (dsi, vc, &msg); -} -static int dsi_update_channel (struct omap_dss_device *dssdev,int vc) {struct dsi_data *dsi =to_dsi_data (dssdev);
@@ -3263,13 +3262,13 @@ static int dsi_update_channel(struct omap_dss_device *dssdev, int vc)DSSDBG ("dsi_update_channel: %d" , vc);/* -* Send NOP between the frames. If we don't send something here, the +* Transition to LP here. If we don't send something here, the * updates stop working. This is probably related to DSI spec stating * that the DSI host should transition to LP at least once per frame. */ - r =_dsi_send_nop (dsi,VC_CMD , dsi->dsidev->channel); + r =dsi_vc_send_bta_sync (dssdev,VC_CMD );if (r <0 ) { -DSSWARN ("failed to send nop between frames: %d\n" , r); +DSSWARN ("failed to send bta sync between frames: %d\n" , r); goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 132/2151 drm: of: Fix drm_of_get_data_lanes_count_ep() return value documentation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
[ Upstream commit e3eca845ef7d6cd8c407f9b42beb45af94ff096b ]
Update drm_of_get_data_lanes_count_ep() return value documentation to match the drm_of_get_data_lanes_count() return value documentation. The drm_of_get_data_lanes_count_ep() is only a wrapper around the drm_of_get_data_lanes_count() and therefore returns the same error codes.
Simplify the return code description of drm_of_get_data_lanes_count() and drm_of_get_data_lanes_count_ep() to -ENODATA and -EINVAL.
--- drivers/gpu/drm/drm_of.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_of.c +4 -4
@@ -507,8 +507,8 @@ EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping);* * Return: * * min..max - positive integer count of "data-lanes" elements -* * -ve - the "data-lanes" property is missing or invalid -* * -EINVAL - the "data-lanes" property is unsupported +* * -ENODATA - the property does not have a value. +* * -EINVAL - the "data-lanes" property is missing or invalid */ int drm_of_get_data_lanes_count (const struct device_node *endpoint,const unsigned int min,const unsigned int max)
@@ -539,8 +539,8 @@ EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_count);* * Return: * * min..max - positive integer count of "data-lanes" elements -* * -EINVAL - the "data-mapping" property is unsupported -* * -ENODEV - the "data-mapping" property is missing +* * -ENODATA - the property does not have a value. +* * -EINVAL - the "data-lanes" property is missing or invalid */ int drm_of_get_data_lanes_count_ep(const struct device_node *port, int port_reg, int reg,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 133/2151 libbpf: Avoid overflow in BTF.ext bounds check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darren Carreras <[email protected]>
[ Upstream commit e40f61a31688898e7cf81e91074a42f805883e4d ]
A malformed BTF.ext subsection length in an ELF input can wrap the pointer addition used by btf_ext_parse_sec_info() on 32-bit builds. The wrapped pointer passes the bounds check and parsing then reads beyond the copied BTF.ext data.
Ensure the header fits in the copied data, then validate the subsection offset and length with subtraction before forming its pointer.
--- tools/lib/bpf/btf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tools/lib/bpf/btf.c +9 -5
@@ -3013,7 +3013,7 @@ static int btf_ext_parse_sec_info(struct btf_ext *btf_ext, {const struct btf_ext_info_sec *sinfo;struct btf_ext_info *ext_info; -__u32 info_left, record_size; +__u32 data_left, info_left, record_size;size_t sec_cnt =0 ;void *info;
@@ -3026,16 +3026,20 @@ static int btf_ext_parse_sec_info(struct btf_ext *btf_ext,return -EINVAL ; } -/* The start of the info sec (including the __u32 record_size). */ - info = btf_ext->data + btf_ext->hdr->hdr_len + ext_sec->off; - info_left = ext_sec->len; +if (btf_ext->hdr->hdr_len > btf_ext->data_size) +return -EINVAL ; -if (btf_ext->data + btf_ext->data_size < info + ext_sec->len) { + data_left = btf_ext->data_size - btf_ext->hdr->hdr_len; +if (ext_sec->off > data_left || ext_sec->len > data_left - ext_sec->off) {pr_debug ("%s section (off:%u len:%u) is beyond the end of the ELF section .BTF.ext\n" , ext_sec->desc, ext_sec->off, ext_sec->len);return -EINVAL ; } +/* The start of the info sec (including the __u32 record_size). */ + info = btf_ext->data + btf_ext->hdr->hdr_len + ext_sec->off; + info_left = ext_sec->len; +/* At least a record size */ if (info_left <sizeof (__u32)) {pr_debug (".BTF.ext %s record size not found\n" , ext_sec->desc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 134/2151 selftests/bpf: Allocate a larger timeout for connection
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexis Lothoré (eBPF Foundation) <[email protected]>
[ Upstream commit 669e4fa766000ae4137bb02eb22ce75ba78ad32d ]
Some tests, like tc_tunnel or tc_edt, sporadically fail in CI with the following logs:
(network_helpers.c:309: errno: Operation now in progress) \
Failed to connect to server
send_and_test_data:FAIL:connect to server unexpected error: -115
This is due to SO_RCVTIMEO and SO_SNDTIMEO being set on the client socket (see settimeo() in client_socket()), allowing connect() to return an error and to set errno to EINPROGRESS instead of ETIMEDOUT. Increasing the timeout value for those tests is likely not a good solution (and it has already been done by commit 2790db208b44 ("selftests/bpf: Improve tc_tunnel test reliability")): some tests expect some data transfer to fail, and so the timeout value would increase overall test execution duration again (not only the connection, but any socket operation).
Another solution is to allocate a timeout budget specific to the
connection: we can apply a larger timeout only for connections, and once the connection is established, set back the timeout configured through opts->timeout_ms; this would allow connection to succeed under heavy CI load, while keeping timeout reasonable for the rest of the test traffic.
Create a dedicated connect helper that sets a large timeout for the connect step, tries to connect, and if successful, finally sets the timeout value to the one configured by the test.
--- tools/testing/selftests/bpf/network_helpers.c | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +35 -11
@@ -49,6 +49,8 @@ errno = __save; \ }) +#define CONNECT_MIN_TIMEOUT_MS 5000 +struct ipv4_packet pkt_v4 = { .eth.h_proto =__bpf_constant_htons (ETH_P_IP ), .iph.ihl =5 ,
@@ -291,6 +293,37 @@ int client_socket(int family, int type,return -1 ; } +static int connect_with_timeout (int fd,const struct sockaddr_storage *addr, +socklen_t addrlen,int timeout_ms) +{ +int connect_timeout_ms =MAX (timeout_ms,CONNECT_MIN_TIMEOUT_MS ); + +/* +* Override timeout configuration with a larger value for the +* connection +*/ +if (settimeo (fd, connect_timeout_ms)) { +log_err ("Failed to set connect timeout" ); +return -1 ; + } + +if (connect (fd, (const struct sockaddr *)addr, addrlen)) { +log_err ("Failed to connect" ); +return -1 ; + } + +/* +* If the timeout configured by the test is different from the +* connect timeout, restore it +*/ +if (timeout_ms != connect_timeout_ms &&settimeo (fd, timeout_ms)) { +log_err ("Failed to set timeout for connected socket" ); +return -1 ; + } + +return 0 ; +} +int connect_to_addr (int type,const struct sockaddr_storage *addr,socklen_t addrlen,const struct network_helper_opts *opts) {
@@ -305,8 +338,7 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addreturn -1 ; } -if (connect (fd, (const struct sockaddr *)addr, addrlen)) { -log_err ("Failed to connect to server" ); +if (connect_with_timeout (fd, addr, addrlen, opts->timeout_ms)) {save_errno_close (fd);return -1 ; }
@@ -376,20 +408,12 @@ int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms)struct sockaddr_storage addr;socklen_t len =sizeof (addr); -if (settimeo (client_fd, timeout_ms)) -return -1 ; -if (getsockname (server_fd, (struct sockaddr *)&addr, &len)) {log_err ("Failed to get server addr" );return -1 ; } -if (connect (client_fd, (const struct sockaddr *)&addr, len)) { -log_err ("Failed to connect to server" ); -return -1 ; - } - -return 0 ; +return connect_with_timeout (client_fd, &addr, len, timeout_ms); } int make_sockaddr(int family, const char *addr_str, __u16 port,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 135/2151 bpf: Roll back stream capacity when allocation fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianlin Shi <[email protected]>
[ Upstream commit bd2466ed8fc2ee54408bfe433e75f9f46bfa04f7 ]
bpf_stream_push_str() accounts the string length before allocating a stream element. If the allocation fails, the length remains charged even though no element is queued and therefore cannot be released by a reader. Repeated failures can exhaust the stream capacity permanently until the BPF program is freed.
Refactor bpf_stream_release_capacity() to take a length so the consume and release sides are symmetric, and use it to roll back the charge when creating the stream element fails.
--- kernel/bpf/stream.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
kernel/bpf/stream.c +10 -5
@@ -208,10 +208,8 @@ static int bpf_stream_consume_capacity(struct bpf_stream *stream, int len)return 0 ; } -static void bpf_stream_release_capacity (struct bpf_stream *stream,struct bpf_stream_elem *elem) +static void bpf_stream_release_capacity (struct bpf_stream *stream,int len) { -int len = elem->total_len; -atomic_sub (len, &stream->capacity); }
@@ -219,7 +217,14 @@ static int bpf_stream_push_str(struct bpf_stream *stream, const char *str, int l {int ret =bpf_stream_consume_capacity (stream, len); -return ret ?:__bpf_stream_push_str (&stream->log, str, len); +if (ret) +return ret; + + ret =__bpf_stream_push_str (&stream->log, str, len); +if (ret) +bpf_stream_release_capacity (stream, len); + +return ret; }static struct bpf_stream *bpf_stream_get (enum bpf_stream_id stream_id,struct bpf_prog_aux *aux)
@@ -331,7 +336,7 @@ static int bpf_stream_read(struct bpf_stream *stream, void __user *buf, int len)if (cont)continue ;bpf_stream_backlog_pop (stream); -bpf_stream_release_capacity (stream, elem); +bpf_stream_release_capacity (stream, elem->total_len);bpf_stream_free_elem (elem); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 136/2151 bpf: Fix stream capacity leak in staging path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianlin Shi <[email protected]>
[ Upstream commit effa6370ba89e7839c9bfeb802d8f05d6843ddf1 ]
bpf_stream_stage_printk() increments ss->len before pushing the formatted string to the staging log. If element allocation fails, ss->len remains inflated and bpf_stream_stage_commit() permanently charges the stream capacity for data that was never queued.
Only account the string length after a successful push, and use vscnprintf() so the staged length is the truncated payload without the trailing NUL.
--- kernel/bpf/stream.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/bpf/stream.c +5 -4
@@ -441,17 +441,18 @@ int bpf_stream_stage_printk(struct bpf_stream_stage *ss, const char *fmt, ...) {struct bpf_bprintf_buffers *buf;va_list args; -int ret; +int len, ret;if (bpf_try_get_buffers (&buf))return -EBUSY ;va_start (args, fmt); - ret =vsnprintf (buf->buf,ARRAY_SIZE (buf->buf), fmt, args); + len =vscnprintf (buf->buf,ARRAY_SIZE (buf->buf), fmt, args);va_end (args); - ss->len += ret;/* Exclude NULL byte during push. */ - ret =__bpf_stream_push_str (&ss->log, buf->buf, ret); + ret =__bpf_stream_push_str (&ss->log, buf->buf, len); +if (!ret) + ss->len += len;bpf_put_buffers ();return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 137/2151 bpf: Return partial progress from bpf_stream_read on fault
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianlin Shi <[email protected]>
[ Upstream commit 16790357a50baae10de1f619b608a85145d54bc2 ]
bpf_stream_read() pops and frees stream elements after a successful copy_to_user(). If a later copy_to_user() fails, it currently restores only the current element's consumed_len and returns -EFAULT, hiding bytes already delivered to userspace and making the consumed data unrecoverable on retry.
On a short copy, keep the successfully copied prefix of the current element and return the number of bytes copied. Return -EFAULT only when no bytes were copied for the call.
--- kernel/bpf/stream.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
kernel/bpf/stream.c +9 -7
@@ -310,6 +310,7 @@ static int bpf_stream_read(struct bpf_stream *stream, void __user *buf, int len)while (rem_len) {int pos = len - rem_len; +int chunk, n;bool cont; node =bpf_stream_backlog_peek (stream);
@@ -323,13 +324,14 @@ static int bpf_stream_read(struct bpf_stream *stream, void __user *buf, int len) cons_len = elem->consumed_len; cont =bpf_stream_consume_elem (elem, &rem_len) == false; - - ret =copy_to_user (buf + pos, elem->str + cons_len, - elem->consumed_len - cons_len); -/* Restore in case of error. */ -if (ret) { - ret = -EFAULT ; - elem->consumed_len = cons_len; + chunk = elem->consumed_len - cons_len; + + n =copy_to_user (buf + pos, elem->str + cons_len, chunk); +if (n) { +/* Keep any successfully copied bytes; -EFAULT only if none. */ + elem->consumed_len -= n; + rem_len += n; + ret = (len == rem_len) ? -EFAULT :0 ;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 138/2151 bpf: Reject oversized bpf_stream_vprintk output with -E2BIG
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianlin Shi <[email protected]>
[ Upstream commit 41c0348f6e65c26df4866d5dc96c57b1995fe36c ]
bstr_printf() returns the would-be length excluding the trailing NUL. When that value is >= MAX_BPRINTF_BUF the message was truncated, but bpf_stream_push_str() still tried to allocate with the inflated length and failed with -ENOMEM. The boundary case of exactly MAX_BPRINTF_BUF could also copy the trailing NUL into the stream element.
Reject such lengths with -E2BIG before charging stream capacity, and tighten bpf_stream_elem_alloc() to accept only payloads strictly shorter than the bprintf buffer.
--- kernel/bpf/stream.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
kernel/bpf/stream.c +9 -4
@@ -165,11 +165,11 @@ static struct bpf_stream_elem *bpf_stream_elem_alloc(int len)BUILD_BUG_ON (max_len >BPF_STREAM_PAGE_SZ );/* -* Length denotes the amount of data to be written as part of stream element, -* thus includes '\0' byte. We're capped by how much bpf_bprintf_buffers can -* accomodate, therefore deny allocations that won't fit into them. +* Length is the payload pushed into the stream, excluding the +* trailing NUL of the bprintf buffer. Reject anything that cannot +* fit without copying that NUL into the stream element. */ -if (len <0 || len > max_len) +if (len <0 || len >= max_len)return NULL ;if (!bpf_stream_page_local_lock (&flags))
@@ -389,6 +389,11 @@ __bpf_kfunc int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, conreturn ret; ret =bstr_printf (data.buf,MAX_BPRINTF_BUF , fmt__str, data.bin_args); +/* Truncation: reject before capacity charge (not -ENOMEM). */ +if (ret >=MAX_BPRINTF_BUF ) { +bpf_bprintf_cleanup (&data); +return -E2BIG ; + }/* Exclude NULL byte during push. */ ret =bpf_stream_push_str (stream, data.buf, ret);bpf_bprintf_cleanup (&data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 139/2151 drm/panthor: Take reqs_lock in soft_reset for clearing pending_reqs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Frattaroli <[email protected]>
[ Upstream commit 2d354adc5bbabe2e818be09bbe13f6bfde4a30c7 ]
panthor_gpu_soft_reset() sets pending_reqs to 0 without taking the requisite reqs_lock.
Fix this by taking the lock for the duration of the modification.
--- drivers/gpu/drm/panthor/panthor_gpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_gpu.c +4 -1
@@ -334,7 +334,10 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)return -ETIMEDOUT ; } - ptdev->gpu->pending_reqs =0 ; + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { + ptdev->gpu->pending_reqs =0 ; + } +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 140/2151 bpf: Reject oversized stream read buffers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit ea0b60fae724aa1147d4a07eda5131d3a9a9977e ]
BPF_PROG_STREAM_READ_BY_FD exposes stream_buf_len as a u32, but the internal stream reader accepts an int. Values above INT_MAX therefore become negative before bpf_stream_read(), producing negative consumption lengths. The generic usercopy size check prevents the oversized copy, but emits a warning and reports EFAULT for an unchecked argument.
Change bpf_prog_stream_read() to accept u32 and reject values that the signed reader cannot represent.
--- include/linux/bpf.h | 2 +- kernel/bpf/stream.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/bpf.h +1 -1
@@ -3712,7 +3712,7 @@ void bpf_put_buffers(void);void bpf_prog_stream_init (struct bpf_prog *prog);void bpf_prog_stream_free (struct bpf_prog *prog); -int bpf_prog_stream_read (struct bpf_prog *prog,enum bpf_stream_id stream_id,void __user *buf,int len); +int bpf_prog_stream_read (struct bpf_prog *prog,enum bpf_stream_id stream_id,void __user *buf,u32 len);void bpf_stream_stage_init (struct bpf_stream_stage *ss);void bpf_stream_stage_free (struct bpf_stream_stage *ss);__printf (2 ,3 )
kernel/bpf/stream.c +3 -1
@@ -346,13 +346,15 @@ static int bpf_stream_read(struct bpf_stream *stream, void __user *buf, int len)return ret ? ret : len - rem_len; } -int bpf_prog_stream_read (struct bpf_prog *prog,enum bpf_stream_id stream_id,void __user *buf,int len) +int bpf_prog_stream_read (struct bpf_prog *prog,enum bpf_stream_id stream_id,void __user *buf,u32 len) {struct bpf_stream *stream; stream =bpf_stream_get (stream_id, prog->aux);if (!stream)return -ENOENT ; +if (len >INT_MAX ) +return -EINVAL ;return bpf_stream_read (stream, buf, len); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 141/2151 gpio: pcf857x: implement get_direction()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit ed14364ae8c310cc3f3f649ffcbc7f82befe1579 ]
The GPIO core warns (and taints the kernel) when a gpiochip lacks .get_direction() and a consumer queries a line's direction, for example via /sys/kernel/debug/gpio. pcf857x provided direction_input/output but no get_direction.
These quasi-bidirectional expanders cannot report direction in hardware, and the 'out' software latch alone is ambiguous - a released (input) line and an output driven high both read back as a set bit. Track the direction explicitly in a 'dir' latch updated by the direction_input(), direction_output() and set_multiple() paths, and return it from get_direction(). Initialise it from the same reset state as 'out':
released lines are inputs, lines flagged in the power-on latch are driven-low outputs.
--- drivers/gpio/gpio-pcf857x.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpio/gpio-pcf857x.c +15 -1
@@ -70,8 +70,9 @@ MODULE_DEVICE_TABLE(of, pcf857x_of_table);struct pcf857x {struct gpio_chip chip;struct i2c_client *client; -struct mutex lock;/* protect 'out' */ +struct mutex lock;/* protect 'out' and 'dir' */ unsigned int out;/* software latch */ +unsigned int dir;/* direction latch (1 = input) */ unsigned int status;/* current status */ unsigned int irq_enabled;/* enabled irqs */
@@ -124,12 +125,21 @@ static int pcf857x_input(struct gpio_chip *chip, unsigned int offset)mutex_lock (&gpio->lock); gpio->out |= (1 << offset); + gpio->dir |= (1 << offset); status = gpio->write (gpio->client, gpio->out);mutex_unlock (&gpio->lock);return status; } +static int pcf857x_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct pcf857x *gpio =gpiochip_get_data (chip); + +return (gpio->dir & (1 << offset)) ?GPIO_LINE_DIRECTION_IN + :GPIO_LINE_DIRECTION_OUT ; +} +static int pcf857x_get (struct gpio_chip *chip,unsigned int offset) {struct pcf857x *gpio =gpiochip_get_data (chip);
@@ -165,6 +175,7 @@ static int pcf857x_output(struct gpio_chip *chip, unsigned int offset, int value gpio->out |= bit; else gpio->out &= ~bit; + gpio->dir &= ~bit; status = gpio->write (gpio->client, gpio->out);mutex_unlock (&gpio->lock);
@@ -185,6 +196,7 @@ static int pcf857x_set_multiple(struct gpio_chip *chip, unsigned long *mask,mutex_lock (&gpio->lock); gpio->out &= ~*mask; gpio->out |= *bits & *mask; + gpio->dir &= ~*mask; status = gpio->write (gpio->client, gpio->out);mutex_unlock (&gpio->lock);
@@ -299,6 +311,7 @@ static int pcf857x_probe(struct i2c_client *client) gpio->chip.set_multiple = pcf857x_set_multiple; gpio->chip.direction_input = pcf857x_input; gpio->chip.direction_output = pcf857x_output; + gpio->chip.get_direction = pcf857x_get_direction; gpio->chip.ngpio = (uintptr_t )i2c_get_match_data (client); reset_gpio =devm_gpiod_get_optional (&client->dev,"reset" ,GPIOD_OUT_HIGH );
@@ -394,6 +407,7 @@ static int pcf857x_probe(struct i2c_client *client)* reset state. Otherwise it flags pins to be driven low. */ gpio->out = ~n_latch; + gpio->dir = ~n_latch; gpio->status = gpio->read (gpio->client);/* Enable irqchip if we have an interrupt */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 142/2151 drm/vkms: Fix limited-range YCbCr to RGB conversion scaling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Wentland <[email protected]>
[ Upstream commit 8af5fccd9e8af443efd6f0fec5ba56366f57309a ]
The limited-/studio-range YCbCr to RGB conversion matrices were generated with colour.matrix_YCbCr(is_legal=True, bits=8), which normalises the narrow range by 2^bits (256 for 8-bit) rather than by the full-range maximum 2^bits - 1 (255). As a result the luma scale was 256/219 and the chroma scale 256/224 instead of the correct 255/219 and 255/224.
This over-scales every limited-range conversion by a factor of 256/255, producing an error of up to ~3/255 (8-bit) and causing IGT tests that compare software-computed surfaces against VKMS-processed ones to fail.
Recompute the three limited-range matrices from first principles rather than relying on colour's is_legal scaling:
1. Start from the standard ITU-R YCbCr -> RGB relations for the luma weights Kr, Kb (Kg = 1 - Kr - Kb) of each encoding (BT.601, BT.709 and BT.2020 non-constant luminance). These are the same relations that produce the existing full-range matrices.
2. Expand the studio input range to full range relative to a full-range maximum of 2^n - 1: the luma coefficient by 255/(235 - 16) and the chroma coefficients by 255/(240 - 16). This matches the DRM UAPI definition and IGT's igt_ycbcr_to_rgb_matrix().
3. Convert each coefficient to S31.32 fixed point (round(coeff * 2^32)).
Update the limited-range reference values in the vkms-format KUnit test accordingly. Provide a python script to show how the kunit test value are calculated.
--- .../gpu/drm/vkms/tests/gen_yuv_conversion.py | 87 +++++++++++++++++++ drivers/gpu/drm/vkms/tests/vkms_format_test.c | 38 ++++---- drivers/gpu/drm/vkms/vkms_formats.c | 55 ++++++++---- 3 files changed, 144 insertions(+), 36 deletions(-) create mode 100755 drivers/gpu/drm/vkms/tests/gen_yuv_conversion.py
drivers/gpu/drm/vkms/tests/gen_yuv_conversion.py new file +87 -0
@@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0+ +""" +Derive the VKMS YCbCr -> RGB conversion constants and the vkms-format KUnit +reference values. + +It produces: + 1. The S31.32 fixed-point conversion matrices used in + drivers/gpu/drm/vkms/vkms_formats.c and asserted by + vkms_format_test_conversion_matrix. + 2. The 16-bit reference YCbCr inputs for the limited-range + yuv_u16_to_argb_u16 round-trip cases (the values changed by the fix). + +Requires numpy. +""" + +import numpy as np + +FP = 1 << 32 # S31.32 scale: fixed = round(coeff * 2^32) + +# ITU-R luma weights (Kr, Kb); Kg = 1 - Kr - Kb. +ENCODINGS = { + "BT601": (0.299, 0.114), + "BT709": (0.2126, 0.0722), + "BT2020": (0.2627, 0.0593), # non-constant luminance +} + +# 8-bit studio-range levels: luma 16..235 (range 219), chroma 16..240 +# (range 224, neutral 128); full-range maximum is 2^n - 1 = 255. +FULL_MAX = 255 +Y_RANGE = 235 - 16 # 219 +C_RANGE = 240 - 16 # 224 + +# 16-bit RGB test colors. +COLORS = { + "white": (0xffff, 0xffff, 0xffff), + "gray": (0x8080, 0x8080, 0x8080), + "black": (0x0000, 0x0000, 0x0000), + "red": (0xffff, 0x0000, 0x0000), + "green": (0x0000, 0xffff, 0x0000), + "blue": (0x0000, 0x0000, 0xffff), +} + + +def rgb_matrix(kr, kb, limited): + """Normalized YCbCr -> RGB (Y in [0,1], Cb/Cr in [-0.5, 0.5]).""" + kg = 1.0 - kr - kb + # Standard full-range relations. + m = [[1.0, 0.0, 2 * (1 - kr)], + [1.0, -2 * (1 - kb) * kb / kg, -2 * (1 - kr) * kr / kg], + [1.0, 2 * (1 - kb), 0.0]] + if limited: + # Expand studio input range to full range: luma by 255/219, + # chroma by 255/224 (relative to full-range maximum 2^n - 1). + ys, cs = FULL_MAX / Y_RANGE, FULL_MAX / C_RANGE + m = [[r[0] * ys, r[1] * cs, r[2] * cs] for r in m] + return m + + +def ref_yuv(m, y_offset): + """16-bit YCbCr that VKMS decodes back to each RGB color. + + VKMS decode: [R,G,B] = M . [Y - y_offset*257, Cb - 128*257, Cr - 128*257] + (8-bit offsets lifted to 16-bit by *257 = 65535/255), so invert and + re-add the offsets. + """ + inv = np.linalg.inv(np.array(m, float)) + off = np.array([y_offset * 257, 128 * 257, 128 * 257]) + return {name: tuple(int(min(max(round(v), 0), 0xffff)) + for v in inv @ np.array(rgb, float) + off) + for name, rgb in COLORS.items()} + +print(f"== RGB REFERENCE VALUES ==") +for name, rgb in COLORS.items(): + print(f" {name:6} {{ {rgb[0]:#06x}, {rgb[1]:#06x}, {rgb[2]:#06x} }}") +print() + +for enc, (kr, kb) in ENCODINGS.items(): + for limited in (False, True): + m = rgb_matrix(kr, kb, limited) + y_offset = 16 if limited else 0 + print(f"== {enc} {'LIMITED' if limited else 'FULL'} (y_offset={y_offset}) ==") + for row in m: + print(" { " + ", ".join(str(round(v * FP)) for v in row) + " },") + for name, yuv in ref_yuv(m, y_offset).items(): + print(f" {name:6} {{ {yuv[0]:#06x}, {yuv[1]:#06x}, {yuv[2]:#06x} }}") + print()
drivers/gpu/drm/vkms/tests/vkms_format_test.c +20 -18
@@ -54,6 +54,8 @@ struct yuv_u16_to_argb_u16_case {* The YUV color representation were acquired via the colour python framework. * Below are the function calls used for generating each case. * +* The limited-range cases are generated by gen_yuv_conversion.py. +* * For more information got to the docs: * https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.html */
@@ -101,12 +103,12 @@ static struct yuv_u16_to_argb_u16_case yuv_u16_to_argb_u16_cases[] = { .range = DRM_COLOR_YCBCR_LIMITED_RANGE, .n_colors = 6, .colors = { - { "white", { 0xeb00, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, - { "gray", { 0x7dee, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, - { "black", { 0x1000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, - { "red", { 0x517b, 0x5a34, 0xf000 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, - { "green", { 0x908e, 0x35cc, 0x2237 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, - { "blue", { 0x28f7, 0xf000, 0x6dc9 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + { "white", { 0xebeb, 0x8080, 0x8080 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e6c, 0x8080, 0x8080 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x1010, 0x8080, 0x8080 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x51cd, 0x5a8e, 0xf0f0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x911e, 0x3602, 0x2259 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x2920, 0xf0f0, 0x6e37 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, } },/*
@@ -151,12 +153,12 @@ static struct yuv_u16_to_argb_u16_case yuv_u16_to_argb_u16_cases[] = { .range = DRM_COLOR_YCBCR_LIMITED_RANGE, .n_colors = 6, .colors = { - { "white", { 0xeb00, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, - { "gray", { 0x7dee, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, - { "black", { 0x1000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, - { "red", { 0x3e8f, 0x6656, 0xf000 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, - { "green", { 0xaca1, 0x29aa, 0x1a45 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, - { "blue", { 0x1fd0, 0xf000, 0x75bb }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + { "white", { 0xebeb, 0x8080, 0x8080 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e6c, 0x8080, 0x8080 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x1010, 0x8080, 0x8080 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x3ece, 0x66bc, 0xf0f0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad4e, 0x29d4, 0x1a5f }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1ff0, 0xf0f0, 0x7631 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, } },/*
@@ -201,12 +203,12 @@ static struct yuv_u16_to_argb_u16_case yuv_u16_to_argb_u16_cases[] = { .range = DRM_COLOR_YCBCR_LIMITED_RANGE, .n_colors = 6, .colors = { - { "white", { 0xeb00, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, - { "gray", { 0x7dee, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, - { "black", { 0x1000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, - { "red", { 0x4988, 0x60b9, 0xf000 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, - { "green", { 0xa47b, 0x2f47, 0x1902 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, - { "blue", { 0x1cfd, 0xf000, 0x76fe }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + { "white", { 0xebeb, 0x8080, 0x8080 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e6c, 0x8080, 0x8080 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x1010, 0x8080, 0x8080 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x49d2, 0x611a, 0xf0f0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xa520, 0x2f76, 0x191b }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d1a, 0xf0f0, 0x7775 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, } }, };
drivers/gpu/drm/vkms/vkms_formats.c +37 -18
82 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 143/2151 bpftool: Fix spurious batch file read error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 713c02b59e21840f623a3e31c43d967026c75181 ]
do_batch() checks errno after the read loop to detect read failures, but fgets() does not clear errno on success, so a stale errno left by a previously executed command (e.g. map dump's EBADF from a double close) makes bpftool report a batch file read failure and exit with an error even though every command succeeded.
Clear errno before each fgets() call, so the post-loop check only sees the outcome of the last read: zero on success or EOF, E2BIG for an overlong line, and a genuine errno when fgets() fails.
Since errno is now reset before every read in batch mode, drop the USE_LIBCAP errno reset in main() that existed only to keep errno clean for the batch mode.
--- tools/bpf/bpftool/main.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
tools/bpf/bpftool/main.c +5 -11
@@ -358,7 +358,11 @@ static int do_batch(int argc, char **argv)if (json_output)jsonw_start_array (json_wtr); -while (fgets (buf,sizeof (buf), fp)) { +for (;;) { + errno =0 ; +if (!fgets (buf,sizeof (buf), fp)) +break ; + cp =strchr (buf,'#' );if (cp) *cp ='\0' ;
@@ -460,16 +464,6 @@ int main(int argc, char **argv)setlinebuf (stdout); -#ifdef USE_LIBCAP -/* Libcap < 2.63 hooks before main() to compute the number of -* capabilities of the running kernel, and doing so it calls prctl() -* which may fail and set errno to non-zero. -* Let's reset errno to make sure this does not interfere with the -* batch mode. -*/ - errno =0 ; -#endif - last_do_help = do_help; pretty_output = false; json_output = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 144/2151 regulator: fixed: reject incompatible platform devices
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chandradhar Kumar <[email protected]>
[ Upstream commit f7396c2dbbc1bed6c2c554d1ddf80d16e4780a7d ]
The fixed regulator driver expects non-DT platform devices to provide their configuration through platform_data as a struct fixed_voltage_config.
An explicitly bound driver can bypass the normal platform device/driver matching and attach the fixed regulator driver to an unrelated platform device. This causes the driver's platform_data to be interpreted as a struct fixed_voltage_config even though it contains data for a different device.
Reject non-DT platform devices whose name does not match the fixed regulator driver before accessing their platform data.
--- drivers/regulator/fixed.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/regulator/fixed.c +4 -0
@@ -29,6 +29,7 @@#include <linux/regulator/of_regulator.h> #include <linux/regulator/machine.h> #include <linux/clk.h> +#include <linux/string.h> /* Default time in millisecond to wait for emergency shutdown */ #define FV_DEF_EMERG_SHUTDWN_TMO 10
@@ -229,6 +230,9 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)enum gpiod_flags gflags;int ret; +if (!pdev->dev.of_node &&strcmp (pdev->name,"reg-fixed-voltage" )) +return -ENODEV ; + drvdata =devm_kzalloc (&pdev->dev,sizeof (struct fixed_voltage_data ),GFP_KERNEL );if (!drvdata)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 145/2151 spi: sh-msiof: propagate setup runtime-PM errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 152867998da9f331d6235d76aae1c7e1650708a9 ]
sh_msiof_spi_setup() ignores pm_runtime_get_sync() before programming native chip-select registers and marking the configuration initialized.
Use the checked runtime-PM helper and return failure before register access.
--- drivers/spi/spi-sh-msiof.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/spi/spi-sh-msiof.c +4 -1
@@ -453,6 +453,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi)struct sh_msiof_spi_priv *p =spi_controller_get_devdata (spi->controller);u32 clr, set, tmp; +int ret;if (spi_get_csgpiod (spi,0 ) ||spi_controller_is_target (p->ctlr))return 0 ;
@@ -468,7 +469,9 @@ static int sh_msiof_spi_setup(struct spi_device *spi) clr |=SIMDR1_SYNCAC ; else set |= SIMDR1_SYNCAC; -pm_runtime_get_sync (&p->pdev->dev); + ret =pm_runtime_resume_and_get (&p->pdev->dev); +if (ret <0 ) +return ret; tmp =sh_msiof_read (p,SITMDR1 ) & ~clr;sh_msiof_write (p,SITMDR1 , tmp | set |SIMDR1_TRMD |SITMDR1_PCON ); tmp =sh_msiof_read (p,SIRMDR1 ) & ~clr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 146/2151 iio: humidity: hts221: report available values via read_avail()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adi Nata <[email protected]>
[ Upstream commit 003e99cf33e344a380ba10b3e04ccb862f3d9dc3 ]
Replace the custom oversampling_ratio_available sysfs attributes with the standard IIO read_avail() callback. This lets the IIO core create and format *_available attributes and exposes the lists to in-kernel consumers.
As a consequence, the incorrectly named in_humidity_oversampling_ratio_available attribute is replaced by the standard in_humidityrelative_oversampling_ratio_available name for the IIO_HUMIDITYRELATIVE channel. The temperature oversampling and sampling frequency available attribute names are unchanged.
--- drivers/iio/humidity/hts221_core.c | 106 +++++++++++------------------ 1 file changed, 40 insertions(+), 66 deletions(-)
drivers/iio/humidity/hts221_core.c +40 -66
@@ -10,7 +10,6 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h> -#include <linux/iio/sysfs.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/regmap.h>
@@ -49,7 +48,7 @@ struct hts221_odr {struct hts221_avg {u8 addr;u8 mask; -u16 avg_avl[HTS221_AVG_DEPTH ]; +int avg_avl[HTS221_AVG_DEPTH ]; };static const struct hts221_odr hts221_odr_table[] = {
@@ -58,6 +57,8 @@ static const struct hts221_odr hts221_odr_table[] = { { 13, 0x03 }, /* 12.5Hz */ }; +static const int hts221_odr_avail[] = { 1, 7, 13 }; + static const struct hts221_avg hts221_avg_list[] = { { .addr = 0x10,
@@ -97,7 +98,11 @@ static const struct iio_chan_spec hts221_channels[] = {BIT (IIO_CHAN_INFO_OFFSET ) |BIT (IIO_CHAN_INFO_SCALE ) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 0, .scan_type = { .sign = 's',
@@ -113,7 +118,11 @@ static const struct iio_chan_spec hts221_channels[] = {BIT (IIO_CHAN_INFO_OFFSET ) |BIT (IIO_CHAN_INFO_SCALE ) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 1, .scan_type = { .sign = 's',
@@ -192,53 +201,35 @@ static int hts221_update_avg(struct hts221_hw *hw,return 0 ; } -static ssize_t hts221_sysfs_sampling_freq (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -int i; -ssize_t len =0 ; - -for (i =0 ; i <ARRAY_SIZE (hts221_odr_table); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - hts221_odr_table[i].hz); - buf[len -1 ] ='\n' ; - -return len; -} - -static ssize_t -hts221_sysfs_rh_oversampling_avail (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -const struct hts221_avg *avg = &hts221_avg_list[HTS221_SENSOR_H ]; -ssize_t len =0 ; -int i; - -for (i =0 ; i <ARRAY_SIZE (avg->avg_avl); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - avg->avg_avl[i]); - buf[len -1 ] ='\n' ; - -return len; -} - -static ssize_t -hts221_sysfs_temp_oversampling_avail (struct device *dev, -struct device_attribute *attr, -char *buf) +static int hts221_read_avail (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length, +long mask) { -const struct hts221_avg *avg = &hts221_avg_list[HTS221_SENSOR_T ]; -ssize_t len =0 ; -int i; - -for (i =0 ; i <ARRAY_SIZE (avg->avg_avl); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - avg->avg_avl[i]); - buf[len -1 ] ='\n' ; - -return len; +switch (mask) { +case IIO_CHAN_INFO_OVERSAMPLING_RATIO : +switch (chan->type) { +case IIO_HUMIDITYRELATIVE : + *vals = hts221_avg_list[HTS221_SENSOR_H ].avg_avl; + *length =ARRAY_SIZE (hts221_avg_list[HTS221_SENSOR_H ].avg_avl); +break ; +case IIO_TEMP : + *vals = hts221_avg_list[HTS221_SENSOR_T ].avg_avl; + *length =ARRAY_SIZE (hts221_avg_list[HTS221_SENSOR_T ].avg_avl); +break ; +default : +return -EINVAL ; + } + *type =IIO_VAL_INT ; +return IIO_AVAIL_LIST ; +case IIO_CHAN_INFO_SAMP_FREQ : + *vals = hts221_odr_avail; + *type =IIO_VAL_INT ; + *length =ARRAY_SIZE (hts221_odr_avail); +return IIO_AVAIL_LIST ; +default : +return -EINVAL ; + } }int hts221_set_enable (struct hts221_hw *hw,bool enable)
@@ -521,27 +512,10 @@ static int hts221_validate_trigger(struct iio_dev *iio_dev,return hw->trig == trig ?0 : -EINVAL ; } -static IIO_DEVICE_ATTR(in_humidity_oversampling_ratio_available, S_IRUGO, - hts221_sysfs_rh_oversampling_avail, NULL, 0); -static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available, S_IRUGO, - hts221_sysfs_temp_oversampling_avail, NULL, 0); -static IIO_DEV_ATTR_SAMP_FREQ_AVAIL (hts221_sysfs_sampling_freq); - -static struct attribute *hts221_attributes[] = { - &iio_dev_attr_sampling_frequency_available.dev_attr.attr, - &iio_dev_attr_in_humidity_oversampling_ratio_available.dev_attr.attr, - &iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group hts221_attribute_group = { - .attrs = hts221_attributes, -}; -static const struct iio_info hts221_info = { - .attrs = &hts221_attribute_group, .read_raw = hts221_read_raw, .write_raw = hts221_write_raw, + .read_avail = hts221_read_avail, .validate_trigger = hts221_validate_trigger, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 147/2151 dt-bindings: iio: light: ltr501: Sort compatible enum array
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 6c430006fbcb63dc8baee3c3bf356b264ba7f61e ]
Restore alphabetical sorting of the properties.compatible.enum array.
Stable-dep-of: 198ed7962e42 ("dt-bindings: iio: light: ltr501: Add missing ltr303 compatible")
--- Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml +1 -1
@@ -15,9 +15,9 @@ allOf: properties: compatible: enum: + - liteon,ltr301 - liteon,ltr501 - liteon,ltr559 - - liteon,ltr301 reg: maxItems: 1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 148/2151 dt-bindings: iio: light: ltr501: Add missing ltr303 compatible
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 198ed7962e42f1e45b7f48b9abc70aad9e3185f8 ]
When support for ltr303 was back in 2021, the bindings documentation was not updated accordingly.
--- Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml +1 -0
@@ -16,6 +16,7 @@ properties: compatible: enum: - liteon,ltr301 + - liteon,ltr303 - liteon,ltr501 - liteon,ltr559
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 149/2151 iio: temperature: tmp117: fix calibbias cache update on I2C write failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
[ Upstream commit 61fff9cebbfdf39bbd04d366882476d1def14047 ]
The calibbias cache (data->calibbias) was updated before the I2C write to TMP117_REG_TEMP_OFFSET was known to succeed. If the write failed, the function correctly returned an error, but the driver's internal cache had already been updated to the new value.
This causes the cache and the actual hardware register to go out of
sync: a subsequent write of the same value would be silently skipped by the early "if (off == data->calibbias) return 0;" check, since the cache matches even though the register was never successfully updated.
Update data->calibbias only after confirming the I2C write succeeded, so the cache always reflects the actual state of the device.
Found by code inspection.
--- drivers/iio/temperature/tmp117.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iio/temperature/tmp117.c +7 -2
@@ -95,15 +95,20 @@ static int tmp117_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec {struct tmp117_data *data =iio_priv (indio_dev);s16 off; +int ret;switch (mask) {case IIO_CHAN_INFO_CALIBBIAS : off =clamp_t (int, val,S16_MIN ,S16_MAX );if (off == data->calibbias)return 0 ; + + ret =i2c_smbus_write_word_swapped (data->client,TMP117_REG_TEMP_OFFSET , off); +if (ret) +return ret; + data->calibbias = off; -return i2c_smbus_write_word_swapped (data->client, -TMP117_REG_TEMP_OFFSET , off); +return 0 ;default :return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 150/2151 iio: pressure: rohm-bm1390: Fix AVE_NUM initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matti Vaittinen <[email protected]>
[ Upstream commit 64f4173ad1a7f1b247296c84e624f5095be170c7 ]
The BM1390 tries to initialize the AVE_NUM to 110b at the start-up. The field location is not taken into account, and value is written unsifted. This causes the AVE_NUM to be initialized to zero.
Use FIELD_PREP() to shift the intended AVE_NUM value to correct field.
--- drivers/iio/pressure/rohm-bm1390.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/pressure/rohm-bm1390.c +3 -1
@@ -479,6 +479,7 @@ static const struct iio_info bm1390_info = {static int bm1390_chip_init (struct bm1390_data *data) { +u8 regval;int ret; ret = regmap_write_bits(data->regmap, BM1390_REG_POWER,
@@ -512,8 +513,9 @@ static int bm1390_chip_init(struct bm1390_data *data)* Default to use IIR filter in "middle" mode. Also the AVE_NUM must * be fixed when IIR is in use. */ + regval =FIELD_PREP (BM1390_MASK_AVE_NUM ,BM1390_IIR_AVE_NUM ); ret =regmap_update_bits (data->regmap,BM1390_REG_MODE_CTRL , -BM1390_MASK_AVE_NUM ,BM1390_IIR_AVE_NUM ); +BM1390_MASK_AVE_NUM , regval);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 151/2151 ata: pata_parport: Fix use-after-free in new_device_store
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit bd46a0b22933fb45f4ff009fa4a3836124df34b3 ]
The function new_device_store() calls driver_find() without any protection against concurrent driver unregistration. This can lead to a use-after-free (UAF) when a driver is unloaded (via rmmod) in parallel with a new device addition via sysfs.
The race window exists because driver_find() returns a pointer to the driver's private data, but does not increase its reference count. The caller is responsible for ensuring the driver remains valid, but new_device_store() did not hold any lock or reference during the lookup and subsequent use.
Concurrently, pata_parport_unregister_driver() releases the pi_mutex before calling driver_unregister(), allowing new_device_store to proceed with a stale pointer after the driver has been freed.
Fix this by expanding the critical section protected by pi_mutex in both functions:
- In new_device_store(): acquire pi_mutex before calling driver_find(), and keep it held until all uses of the found driver pointer are completed.
- In pata_parport_unregister_driver(): hold pi_mutex throughout the entire unregistration process, including the driver_unregister() call, so that no concurrent lookup can see a partially removed driver.
Thread A (new_device_store) | Thread B (pata_parport_unregister_driver)
driver_find("ate") |
| mutex_lock(&pi_mutex)
| idr_remove(&protocols, id)
| mutex_unlock(&pi_mutex)
| driver_unregister(&pr->driver)
| (frees driver_private)
/* continues using stale driv */|
-> UAF! |Logs:
BUG: KASAN: slab-use-after-free in driver_find+0xd0/0xd4 Read of size 8 at addr ffffff9f970dc690 by task sh/4737 Call trace: show_stack+0x14/0x1c (C) dump_stack_lvl+0x70/0x84 print_report+0xf4/0x5a4 kasan_report+0xa0/0xe4 __asan_report_load8_noabort+0x18/0x20 driver_find+0xd0/0xd4 new_device_store+0x140/0x30c [pata_parport] bus_attr_store+0x5c/0x94 sysfs_kf_write+0x1c4/0x25c ... Allocated by task 4734: kasan_save_stack+0x28/0x4c kasan_save_track+0x1c/0x34 kasan_save_alloc_info+0x3c/0x4c __kasan_kmalloc+0x98/0xac __kmalloc_cache_noprof+0x158/0x3cc bus_add_driver+0x70/0x4d8 driver_register+0xf0/0x3b0 pata_parport_register_driver+0xb8/0x1c4 [pata_parport] 0xffffffc07f5ce014 do_one_initcall+0xb8/0x36c do_init_module+0x230/0x6d4 ... Freed by task 4737: kasan_save_stack+0x28/0x4c kasan_save_track+0x1c/0x34 kasan_save_free_info+0x48/0x8c __kasan_slab_free+0x5c/0x84 kfree+0x174/0x3e0 driver_release+0x1c/0x7c kobject_put+0x178/0x47c driver_find+0x78/0xd4 new_device_store+0x140/0x30c [pata_parport] bus_attr_store+0x5c/0x94 sysfs_kf_write+0x1c4/0x25c ...
--- drivers/ata/pata_parport/pata_parport.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ata/pata_parport/pata_parport.c +4 -3
@@ -626,8 +626,9 @@ void pata_parport_unregister_driver(struct pi_protocol *pr)break ; }idr_remove (&protocols, id); -mutex_unlock (&pi_mutex);driver_unregister (&pr->driver); +mutex_unlock (&pi_mutex); + }EXPORT_SYMBOL_GPL (pata_parport_unregister_driver);
@@ -654,18 +655,18 @@ static ssize_t new_device_store(const struct bus_type *bus, const char *buf, siz port_wanted =-1 ; } +mutex_lock (&pi_mutex); drv =driver_find (protocol, &pata_parport_bus_type);if (!drv) {if (strcmp (protocol,"auto" )) {pr_err ("protocol %s not found\n" , protocol); +mutex_unlock (&pi_mutex);return -EINVAL ; } pr_wanted =NULL ; }else { pr_wanted = container_of(drv, struct pi_protocol, driver); } - -mutex_lock (&pi_mutex);/* walk all parports */ idr_for_each_entry (&parport_list, parport, port_num) {if (port_num == port_wanted || port_wanted ==-1 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 152/2151 ARM: dts: helios4: fix lm75 supply name
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit ef473a83c63e3173ac472e42727e990b923b99db ]
The lm75 driver requests a regulator named "vs" (the +VS power pin of the chip). The Helios4 DTS incorrectly used vcc-supply instead of vs-supply, causing the regulator core to emit:
lm75 0-004c: supply vs not found, using dummy regulator
Fix the property name to match the binding and the driver.
--- arch/arm/boot/dts/marvell/armada-388-helios4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/marvell/armada-388-helios4.dts +1 -1
@@ -200,7 +200,7 @@ usb3-ilimit-hog { temp_sensor: temp@4c { compatible = "ti,lm75"; reg = <0x4c>; - vcc-supply = <®_3p3v>; + vs-supply = <®_3p3v>; }; eeprom@53 {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 153/2151 ARM: dts: armada-385-clearfog-gtr: fix vmmc property name
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 337d10963f601d5a3dfb4b7aa273ca8c0b4d5172 ]
The SDHCI node references the 3.3V regulator through a bare "vmmc" property, which is not part of the mmc controller DT binding; the correct property is "vmmc-supply".
--- arch/arm/boot/dts/marvell/armada-385-clearfog-gtr.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/marvell/armada-385-clearfog-gtr.dtsi +1 -1
@@ -235,7 +235,7 @@ sdhci@d8000 { pinctrl-0 = <&cf_gtr_sdhci_pins>; pinctrl-names = "default"; status = "okay"; - vmmc = <®_3p3v>; + vmmc-supply = <®_3p3v>; wp-inverted; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 154/2151 ARM: dts: armada-395-gp: drop unsupported SDHCI clock-frequency
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit a56183c7f15215d804290808a2b5a1fa997aa9cd ]
The SDHCI node carries a "clock-frequency" property, but the marvell,armada-380-sdhci binding does not define it and dtbs_check rejects the node as a result. No driver consumes it either: only a few other sdhci-pltfm based drivers (imx, mcf, iproc, arasan, dwcmshc, xenon) read that property, while sdhci-pxav3 derives the maximum clock from the io clock rate.
Remove the property.
--- arch/arm/boot/dts/marvell/armada-395-gp.dts | 1 - 1 file changed, 1 deletion(-)
arch/arm/boot/dts/marvell/armada-395-gp.dts +0 -1
@@ -59,7 +59,6 @@ sata@a8000 { /* CON18 */ sdhci@d8000 { - clock-frequency = <200000000>; broken-cd; wp-inverted; bus-width = <8>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 155/2151 ARM: dts: armada-388-helios4: fix vmmc property name
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 008e9faadef8c0aaa9b8a3ff05a2126e3c5b08b7 ]
The sdhci@d8000 node references the 3.3V regulator through a bare "vmmc" property, which is not part of the mmc controller DT binding. The binding requires supply properties in the form "vmmc-supply", so the current entry is ignored by the driver.
Rename the property to "vmmc-supply" so the fixed regulator is correctly wired up as the card power supply.
--- arch/arm/boot/dts/marvell/armada-388-helios4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/marvell/armada-388-helios4.dts +1 -1
@@ -269,7 +269,7 @@ sdhci@d8000 { &helios_sdhci_cd_pins>; pinctrl-names = "default"; status = "okay"; - vmmc = <®_3p3v>; + vmmc-supply = <®_3p3v>; wp-inverted; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 156/2151 ARM: dts: helios4: fix vbus-supply for USB2 PHY
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit a132798a133e76a7bb575ba95b2b64eadd245438 ]
The usb-nop-xceiv binding and driver use "vbus-supply"; the driver acquires the VBUS regulator via devm_regulator_get_exclusive("vbus") (phy-generic.c). The stale "vbus-regulator" name is never read by the driver and dtbs_check rejects it as an unknown property. Rename the property so reg_5p0v_usb is honored.
--- arch/arm/boot/dts/marvell/armada-388-helios4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/marvell/armada-388-helios4.dts +1 -1
@@ -140,7 +140,7 @@ fan2: j17-pwm { usb2_phy: usb2-phy { compatible = "usb-nop-xceiv"; - vbus-regulator = <®_5p0v_usb>; + vbus-supply = <®_5p0v_usb>; }; usb3_phy: usb3-phy {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 157/2151 ARM: dts: helios4: fix spi1 location
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 5df4320a30a87f9bb918ace7b389026917c8d896 ]
This spi node is specified in armada-38x.dtsi with proper compatible strings whereas they are not present here. Instead of copy and pasting various lines, just reference the node in the dtsi.
This dts seems to predate the move of spi from internal-regs to the soc node so this moves it in line there.
Allows proper probing of SPI at runtime.
Remove the microsom_spi1_cs_pins pinctrl group and its reference in &spi1. The group only muxed mpp59 to the "spi1" function, but that pin (SPI1 cs0) is already covered by spi1_pins, which selects the same function for mpp56-59 in armada-38x.dtsi.
--- .../arm/boot/dts/marvell/armada-388-helios4.dts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
arch/arm/boot/dts/marvell/armada-388-helios4.dts +6 -11
@@ -254,13 +254,6 @@ sata3: sata-port@1 { }; }; - spi@10680 { - pinctrl-0 = <&spi1_pins - µsom_spi1_cs_pins>; - pinctrl-names = "default"; - status = "okay"; - }; - sdhci@d8000 { bus-width = <4>; cd-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
@@ -327,11 +320,13 @@ helios_fan2_pins: helios_fan2_pins { marvell,pins = "mpp48", "mpp55"; marvell,function = "gpio"; }; - microsom_spi1_cs_pins: spi1-cs-pins { - marvell,pins = "mpp59"; - marvell,function = "spi1"; - }; }; }; }; }; + +&spi1 { + pinctrl-0 = <&spi1_pins>; + pinctrl-names = "default"; + status = "okay"; +};
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 158/2151 kexec_file: stop the top-down search before it underflows
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit c711461303af9f796b293b5ac06f49a885e46e71 ]
locate_mem_hole_top_down() walks candidates downwards by subtracting PAGE_SIZE whenever the window conflicts with an existing segment or with an architecture exclude range.
Nothing stops that subtraction at zero, so a search that reaches the bottom of the address space wraps temp_start around and continues.
The walk starts inside the range being scanned and only moves down, so bail out once a candidate ends up above end. That covers every step in the loop rather than the subtractions alone, and it matches locate_mem_hole_bottom_up(), which already bounds its candidate on both sides.
This is a better check than subtracting with check_sub_overflow(), given that we would have 3 subtractions in this block, and this single fix would take care of them all (instead of three check_sub_overflow()).
--- kernel/kexec_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/kexec_file.c +3 -1
@@ -483,7 +483,9 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end,/* align down start */ temp_start =ALIGN_DOWN (temp_start, kbuf->buf_align); -if (temp_start < start || temp_start < kbuf->buf_min) +/* A candidate above the range means the walk wrapped around */ +if (temp_start < start || temp_start < kbuf->buf_min || + temp_start > end)return 0 ; temp_end = temp_start + kbuf->memsz -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 159/2151 perf jitdump: Fix extended header read that always fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 598e905931380f0714d5fd50cecfac615a1ec742 ]
jit_open() sets bsz = bs before the fread() that uses bs - bsz as the read size, making the expression always evaluate to zero. fread() with size 0 returns 0, which triggers the ret != 1 error path — so extended jitdump headers (total_size > sizeof(header)) have been silently broken since the original implementation.
Additionally, when 0 < bs <= bsz the if (bs > bsz) block is skipped entirely, leaving extended header bytes unread in the stream. Subsequent jit_get_next_entry() calls then parse those leftover bytes as a jr_prefix, corrupting the record stream.
Fix by separating the buffer growth from the read: realloc only when bs > bsz, then unconditionally fread bs bytes when bs > 0.
--- tools/perf/util/jitdump.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/jitdump.c +5 -3
@@ -224,10 +224,12 @@ jit_open(struct jit_buf_desc *jd, const char *name) n =realloc (buf, bs);if (!n) goto error; - bsz = bs; buf = n; -/* read extra we do not know about */ - ret =fread (buf, bs - bsz,1 , jd->in); + bsz = bs; + } +if (bs >0 ) { +/* consume extended header bytes from the stream */ + ret =fread (buf, bs,1 , jd->in);if (ret !=1 ) goto error; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 160/2151 perf jitdump: Fix debug_data and unwinding_data leaks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 2bd967f3adcba1d3e54f10b0d8b25f950e4f03fd ]
jit_repipe_debug_info() overwrites jd->debug_data without freeing the previous allocation. If two consecutive JIT_CODE_DEBUG_INFO records appear without an intervening LOAD record consuming the data, the first allocation leaks.
The sibling jit_repipe_unwinding_info() already frees the old jd->unwinding_data before reassignment — add the same pattern to jit_repipe_debug_info() using zfree().
Also add cleanup of both buffers in jit_close() so they are freed when the jitdump session ends, even if no LOAD record consumed them.
--- tools/perf/util/jitdump.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/jitdump.c +3 -0
@@ -117,6 +117,8 @@ jit_close(struct jit_buf_desc *jd)funlockfile (jd->in);fclose (jd->in); jd->in =NULL ; +zfree (&jd->debug_data); +zfree (&jd->unwinding_data); } static int
@@ -662,6 +664,7 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)memcpy (data, &jr->info.entries, sz); +zfree (&jd->debug_data); jd->debug_data = data;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 161/2151 perf jitdump: Validate code_size against total_size in code load
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 06c7cf7a072fcd52e68471628c56630d2bdcc650 ]
jit_repipe_code_load() reads code_size from the jitdump record and uses it to compute a pointer to the code blob:
code = (unsigned long)jr + jr->load.p.total_size - csize;
An oversized code_size underflows the pointer arithmetic, causing OOB reads into earlier heap memory. Validate that code_size fits within the record (total_size - sizeof(jr->load)) before the pointer computation.
code_size is uint64_t but csize is int; values above INT_MAX wrap negative when narrowed into csize, which defeats the bounds check and sends the code pointer past the end of the record. Reject those too.
--- tools/perf/util/jitdump.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/perf/util/jitdump.c +11 -0
@@ -9,6 +9,7 @@#include <fcntl.h> #include <unistd.h> #include <inttypes.h> +#include <limits.h> #include <byteswap.h> #include <sys/stat.h> #include <sys/mman.h>
@@ -451,6 +452,16 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) csize = jr->load.code_size; usize = jd->unwinding_mapped_size; addr = jr->load.code_addr; + +/* code blob lives at the end of the record, validate it fits */ +if (jr->load.p.total_size <sizeof (jr->load) || + jr->load.code_size > jr->load.p.total_size -sizeof (jr->load) || + jr->load.code_size >INT_MAX ) { +pr_warning ("jitdump: invalid code_size %" PRIu64" (total_size=%u) in code_load record\n" , + (uint64_t )jr->load.code_size, jr->load.p.total_size); +return -1 ; + } + sym = (void *)((unsigned long )jr +sizeof (jr->load)); code = (unsigned long )jr + jr->load.p.total_size - csize; count = jr->load.code_index;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 162/2151 perf jitdump: Prevent integer underflow in debug info size calculation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit dfe8fe96efca3c32979dc0859f88e15b677d25f1 ]
jit_repipe_debug_info() and jit_repipe_unwinding_info() compute payload sizes by subtracting the fixed header size from total_size:
sz = jr->prefix.total_size - sizeof(jr->info);
When total_size is smaller than the header struct (from a truncated or corrupted jitdump record), the subtraction underflows to a massive value, causing an oversized allocation followed by an OOB memcpy.
Validate that total_size covers at least the fixed header before the subtraction in both functions.
--- tools/perf/util/jitdump.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/jitdump.c +8 -0
@@ -668,6 +668,10 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)if (!(jd && jr))return -1 ; +/* total_size must cover at least the fixed header */ +if (jr->prefix.total_size <sizeof (jr->info)) +return -1 ; + sz = jr->prefix.total_size -sizeof (jr->info); data =malloc (sz);if (!data)
@@ -696,6 +700,10 @@ jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)if (!(jd && jr))return -1 ; +/* total_size must cover at least the fixed header */ +if (jr->prefix.total_size <sizeof (jr->unwinding)) +return -1 ; + unwinding_data_size = jr->prefix.total_size -sizeof (jr->unwinding); unwinding_data =malloc (unwinding_data_size);if (!unwinding_data)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 163/2151 perf jitdump: Bounds-check debug entry byte-swap loop
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit ede3cd8151675c2983cd49104b1e9b25a3712ed8 ]
The byte-swap loop for JIT_CODE_DEBUG_INFO uses array indexing (jr->info.entries[n]) to iterate debug entries. struct debug_entry has a flexible array member name[], so each entry has a different size. Array indexing computes offsets assuming fixed-size elements, landing inside variable-length name strings after the first entry and byte-swapping garbage.
Additionally, nr_entry is read from untrusted jitdump input without validation against total_size, so a crafted value causes OOB reads.
Replace the array indexing with debug_entry_next() pointer arithmetic (which correctly accounts for the variable-length name) and bounds-check each entry against the record's total_size before byte-swapping.
--- tools/perf/util/jitdump.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
tools/perf/util/jitdump.c +22 -4
@@ -319,14 +319,32 @@ jit_get_next_entry(struct jit_buf_desc *jd)switch (id) {case JIT_CODE_DEBUG_INFO :if (jd->needs_bswap) { +void *end = (void *)jr + jr->prefix.total_size; +struct debug_entry *ent;uint64_t n; + jr->info.code_addr =bswap_64 (jr->info.code_addr); jr->info.nr_entry =bswap_64 (jr->info.nr_entry); -for (n =0 ; n < jr->info.nr_entry; n++) { - jr->info.entries[n].addr =bswap_64 (jr->info.entries[n].addr); - jr->info.entries[n].lineno =bswap_32 (jr->info.entries[n].lineno); - jr->info.entries[n].discrim =bswap_32 (jr->info.entries[n].discrim); + +/* +* debug_entry has a variable-length name[], so array +* indexing would compute wrong offsets — use +* debug_entry_next() and bounds-check each entry. +*/ + ent = &jr->info.entries[0 ]; +for (n =0 ; n < jr->info.nr_entry; n++) { +if ((void *)ent +sizeof (*ent) > end) +break ; +/* name must be NUL-terminated within the record */ +if (!memchr (ent->name,'\0' , (char *)end - ent->name)) +break ; + ent->addr =bswap_64 (ent->addr); + ent->lineno =bswap_32 (ent->lineno); + ent->discrim =bswap_32 (ent->discrim); + ent =debug_entry_next (ent); } +/* clamp so downstream consumers don't overrun */ + jr->info.nr_entry = n; }break ;case JIT_CODE_UNWINDING_INFO :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 164/2151 perf jitdump: Check snprintf return before computing header size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 0155f05ea6e133c18a04b8b5945cac59870da156 ]
snprintf() returns the would-have-been length on truncation. When the jitted filename exceeds PATH_MAX, the unclamped 'size' value inflates sizeof(event->mmap2.filename) - size into a massive underflow, causing the header.size computation to write an oversized header. The subsequent write to 'id = event + header.size - idr_size' then corrupts the heap.
Clamp size to PATH_MAX - 1 after snprintf in both jit_repipe_code_load() and jit_repipe_code_move().
--- tools/perf/util/jitdump.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/jitdump.c +6 -0
@@ -494,6 +494,9 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) jd->dir, nspid, count); +/* snprintf returns would-be length on truncation, clamp to buffer */ +if (size >=sizeof (event->mmap2.filename)) + size =sizeof (event->mmap2.filename) -1 ; size++;/* for \0 */
@@ -622,6 +625,9 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) jd->dir, nspid, jr->move.code_index); +/* snprintf returns would-be length on truncation, clamp to buffer */ +if (size >=sizeof (event->mmap2.filename)) + size =sizeof (event->mmap2.filename) -1 ; size++;/* for \0 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 165/2151 perf jitdump: Fix funlockfile on unlocked stream in jit_open() error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit bfde6848c1e24fd979d0138c57c1cc28c35093c3 ]
If the malloc() for the initial read buffer fails, jit_open() jumps to the error label which calls funlockfile(jd->in). However, flockfile() is called later in the function, so at this point the stream was never locked. Calling funlockfile() on an unlocked stream is undefined behavior per POSIX.
Split the error path into two labels: 'error' (after flockfile) calls funlockfile before cleanup, 'error_noflock' (before flockfile) skips the unlock.
--- tools/perf/util/jitdump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/jitdump.c +3 -2
@@ -157,7 +157,7 @@ jit_open(struct jit_buf_desc *jd, const char *name) buf =malloc (bsz);if (!buf) - goto error; + goto error_noflock;/* * protect from writer modifying the file while we are reading it
@@ -245,8 +245,9 @@ jit_open(struct jit_buf_desc *jd, const char *name)return 0 ; error: -free (buf);funlockfile (jd->in); +error_noflock: +free (buf);fclose (jd->in);return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 166/2151 perf jitdump: Free event in jit_repipe_code_move()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 7fc5851aac606b9e4143f6857710cc5f346770c5 ]
jit_repipe_code_move() allocates a perf_event with calloc but never frees it — the 'out' label exits with only perf_sample__exit().
The sibling function jit_repipe_code_load() correctly calls free(event) at its out label. Add the same free(event) to jit_repipe_code_move().
--- tools/perf/util/jitdump.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/jitdump.c +1 -0
@@ -682,6 +682,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)build_id__mark_dso_hit (tool, event, &sample,NULL , jd->machine); out:perf_sample__exit (&sample); +free (event);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 167/2151 perf: replace strcpy() with strncpy() in util/jitdump.c
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hrishikesh Suresh <[email protected]>
[ Upstream commit 9bef5cead63d5d8fad3ba7ebaf26f3f4ee172c82 ]
Usage of strcpy() can lead to buffer overflows. Therefore, it has been replaced with strncpy(). The output file path is provided as a parameter and might be restricted by command-line by default. But this defensive patch will prevent any potential overflow, making the code more robust against future changes in input handling.
Testing:
- ran perf test from tools/perf and did not observe any regression with the earlier code
Stable-dep-of: 4eddf7d9e341 ("perf jitdump: Use dirname() return value in jit_open()")
--- tools/perf/util/jitdump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/jitdump.c +2 -1
@@ -239,7 +239,8 @@ jit_open(struct jit_buf_desc *jd, const char *name)/* * keep dirname for generating files and mmap records */ -strcpy (jd->dir, name); +strncpy (jd->dir, name,PATH_MAX ); + jd->dir[PATH_MAX -1 ] ='\0' ;dirname (jd->dir);free (buf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 168/2151 perf jitdump: Use dirname() return value in jit_open()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 4eddf7d9e341eb8c41704b8aa27b4a91f4e2c7c9 ]
jit_open() calls dirname(jd->dir) but ignores the return value. POSIX says dirname() may return a pointer to internal static storage — glibc does this when the path has no '/', returning "." from a static buffer and leaving jd->dir unchanged with the original filename.
Capture the return value and copy it back to jd->dir when dirname() returns a different pointer.
--- tools/perf/util/jitdump.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/jitdump.c +4 -1
@@ -146,6 +146,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)ssize_t bs, bsz =0 ;void *n, *buf =NULL ;int ret, retval =-1 ; +char *dname;nsinfo__mountns_enter (jd->nsi, &nsc); jd->in =fopen (name,"r" );
@@ -241,7 +242,9 @@ jit_open(struct jit_buf_desc *jd, const char *name)*/ strncpy (jd->dir, name,PATH_MAX ); jd->dir[PATH_MAX -1 ] ='\0' ; -dirname (jd->dir); + dname =dirname (jd->dir); +if (dname != jd->dir) +strlcpy (jd->dir, dname,sizeof (jd->dir));free (buf);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 169/2151 perf jitdump: Validate debug entries on native (non-swap) path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 51e14e495f0cea061bbad33e7635f7fd857113ad ]
The bounds-checking and nr_entry clamping added for the byte-swap path only runs when jd->needs_bswap is true. On native-endian files, nr_entry passes through unvalidated to jit_repipe_debug_info(), which stores it as jd->nr_debug_entries. Downstream, jit_process_debug_info() in genelf_debug.c iterates nr_debug_entries times via debug_entry_next(), which calls strlen() on each entry's name field — a crafted nr_entry causes OOB reads and writes.
Add bounds-checked iteration in jit_repipe_debug_info() that validates each debug_entry fits in the payload and its name is NUL-terminated before calling debug_entry_next(). Clamp nr_debug_entries to the count of valid entries.
--- tools/perf/util/jitdump.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
tools/perf/util/jitdump.c +22 -5
@@ -692,8 +692,10 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)static int jit_repipe_debug_info (struct jit_buf_desc *jd,union jr_entry *jr) { -void *data; -size_t sz; +struct debug_entry *ent; +void *data, *end; +size_t sz, valid; +uint64_t i;if (!(jd && jr))return -1 ;
@@ -713,10 +715,25 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr) jd->debug_data = data;/* -* we must use nr_entry instead of size here because -* we cannot distinguish actual entry from padding otherwise +* Clamp nr_debug_entries to entries that actually fit in the +* payload. The byte-swap path already does this for cross-endian +* files; validate on the native path too, since downstream +* jit_process_debug_info() iterates via debug_entry_next() which +* calls strlen() on each entry's name field. */ - jd->nr_debug_entries = jr->info.nr_entry; + end = data + sz; + ent = data; + valid =0 ; +for (i =0 ; i < jr->info.nr_entry; i++) { +if ((void *)ent +sizeof (*ent) > end) +break ; +/* name must be NUL-terminated within the payload */ +if (!memchr (ent->name,'\0' , (char *)end - ent->name)) +break ; + ent =debug_entry_next (ent); + valid++; + } + jd->nr_debug_entries = valid;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 170/2151 perf jitdump: Validate sym string NUL-termination in code load
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 98bfe1142ccbaa5ffdca5dcdddd26f238ad33585 ]
jit_repipe_code_load() computes sym = (void *)jr + sizeof(jr->load) and passes it to jit_emit_elf() which calls strlen(sym) via jit_write_elf(). If code_size equals total_size - sizeof(jr->load), the sym pointer aliases the code blob with no NUL terminator, and strlen() scans past the buffer into adjacent heap memory.
Add a memchr() check to verify the symbol name is NUL-terminated within the region between the load header and the code blob before use.
--- tools/perf/util/jitdump.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/util/jitdump.c +7 -0
@@ -487,6 +487,13 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) sym = (void *)((unsigned long )jr +sizeof (jr->load)); code = (unsigned long )jr + jr->load.p.total_size - csize; + +/* sym string lives between the load header and the code blob */ +if (!memchr (sym,'\0' , code - (unsigned long )sym)) { +pr_warning ("jitdump: unterminated symbol name in code_load record\n" ); +return -1 ; + } + count = jr->load.code_index; idr_size = jd->machine->id_hdr_size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 171/2151 perf jitdump: Validate unwinding sizes against record payload
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 92d50319b4f0c0bbee8a236a09063272cd22faab ]
jit_repipe_unwinding_info() copies unwinding_size and eh_frame_hdr_size from the jitdump record into jd-> fields without checking them against the actual payload size. Downstream, jit_add_eh_frame_info() in genelf.c computes unwinding_table_size = unwinding_size - eh_frame_hdr_size, which underflows when eh_frame_hdr_size > unwinding_size. The result is passed as d->d_size to libelf, causing an OOB heap read into the output ELF file.
Validate that unwinding_size fits within the record payload and that eh_frame_hdr_size does not exceed unwinding_size before allocating or storing the values, so a bogus record cannot force a large allocation that is then discarded.
mapped_size is likewise taken from the record and was narrowed into an int for the mmap2 len computation in jit_repipe_code_load() and jit_repipe_code_move(); values above INT_MAX would turn negative, producing a wrong mmap2 length. Use uint64_t for usize so the value cannot truncate.
--- tools/perf/util/jitdump.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
tools/perf/util/jitdump.c +16 -3
@@ -462,7 +462,8 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)u16 idr_size;const char *sym;uint64_t count; -int ret, csize, usize; +int ret, csize; +uint64_t usize;pid_t nspid, pid, tid;struct {u32 pid, tid;
@@ -543,7 +544,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) event->mmap2.pgoff =GEN_ELF_TEXT_OFFSET ; event->mmap2.start = addr; - event->mmap2.len = usize ?ALIGN_8 (csize) + usize : csize; + event->mmap2.len = usize ?ALIGN_8 ((uint64_t )csize) + usize : (uint64_t )csize; event->mmap2.pid = pid; event->mmap2.tid = tid; event->mmap2.ino = st.st_ino;
@@ -610,7 +611,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)char *filename;size_t size;struct stat st; -int usize; +uint64_t usize;u16 idr_size;int ret;pid_t nspid, pid, tid;
@@ -759,6 +760,18 @@ jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)return -1 ; unwinding_data_size = jr->prefix.total_size -sizeof (jr->unwinding); + +/* +* Validate sizes before allocating — jit_add_eh_frame_info() +* computes unwinding_size - eh_frame_hdr_size and uses the +* result as a buffer length for libelf. +*/ +if (jr->unwinding.unwinding_size > unwinding_data_size || + jr->unwinding.eh_frame_hdr_size > jr->unwinding.unwinding_size) { +pr_warning ("jitdump: invalid unwinding sizes in unwinding_info record\n" ); +return -1 ; + } + unwinding_data =malloc (unwinding_data_size);if (!unwinding_data)return -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 172/2151 dt-bindings: display: panel: samsung,s6e8aa5x01: Allow common properties
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konrad Dybcio <[email protected]>
[ Upstream commit c3fd78f0f3624fff3dcf55d89326f90000367596 ]
Change additionalProperties to unevaluatedProperties to allow inheriting properties from panel-common.yaml, preventing this warning:
qcom/sm6125-xiaomi-laurel-sprout.dtb: panel@0 (samsung,s6e8fc0-m1906f9): 'port' does not match any of the regexes: '^pinctrl-[0-9]+$'
from schema $id: http://devicetree.org/schemas/display/panel/samsung,s6e8aa5x01-ams561ra01.yaml
--- .../bindings/display/panel/samsung,s6e8aa5x01-ams561ra01.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/display/panel/samsung,s6e8aa5x01-ams561ra01.yaml +1 -1
@@ -31,7 +31,7 @@ required: - compatible - reg -additionalProperties: false +unevaluatedProperties: false examples: - |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 173/2151 remoteproc: qcom_q6v5_adsp: Fix double jiffies conversion in adsp_start()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anup Vishwakarma <[email protected]>
[ Upstream commit f559ef6316971fe39dc5f5edd6a483429ba03768 ]
adsp_start() computes 5 * HZ, an already-converted jiffies count, and passes it into msecs_to_jiffies(), which expects milliseconds -- reinterpreting the value and shrinking the intended timeout. Every other caller (q6v5_start() in qcom_q6v5_mss.c, qcom_pas_start() in qcom_q6v5_pas.c) passes msecs_to_jiffies(5000) directly, matching qcom_q6v5_wait_for_start()'s kerneldoc, which documents @timeout as already being in jiffies.
On CONFIG_HZ=250 this shrinks the intended 5 second timeout to ~1.25 seconds, causing a DSP that legitimately takes 2-3 seconds to signal ready to be spuriously torn down as a boot failure.
Fix by passing msecs_to_jiffies(5000) directly, matching every other caller.
--- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_adsp.c +1 -1
@@ -430,7 +430,7 @@ static int adsp_start(struct rproc *rproc) goto disable_adsp_clks; } - ret =qcom_q6v5_wait_for_start (&adsp->q6v5,msecs_to_jiffies (5 *HZ )); + ret =qcom_q6v5_wait_for_start (&adsp->q6v5,msecs_to_jiffies (5000 ));if (ret == -ETIMEDOUT ) {dev_err (adsp->dev,"start timed out\n" ); goto disable_adsp_clks;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 174/2151 arm64: dts: qcom: sdm845-sony-xperia-tama: Fix Bluetooth UART pinctrl
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shujath Mohd <[email protected]>
[ Upstream commit cd0f33393882e2554d46e8e068ab95d00593f385 ]
Use the 4-pin UART6 pinctrl configuration for the WCN3990 Bluetooth controller on Sony Xperia Tama devices.
This enables the UART hardware flow control required for reliable Bluetooth communication at higher baud rates.
--- arch/arm64/boot/dts/qcom/sdm845-sony-xperia-tama.dtsi | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/qcom/sdm845-sony-xperia-tama.dtsi +2 -0
@@ -755,6 +755,8 @@ int-pins { }; &uart6 { + pinctrl-0 = <&qup_uart6_4pin>; + status = "okay"; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 175/2151 cxl/mce: Avoid alias page retirement for corrected errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shaikh Kamaluddin <[email protected]>
[ Upstream commit 04a7b330c8b60dfff200d9a32dd6615f97b59d07 ]
cxl_handle_mce() offlines the aliased page of an Extended Linear Cache (ELC) region for any MCE with a usable address in the region. This includes corrected errors, needlessly reducing usable memory.
Skip ELC alias retirement when mce_is_correctable() identifies the reported error as corrected. Uncorrected errors with a usable address in the ELC region continue to retire the aliased page as before.
mce_usable_address() already implements the per-vendor checks that determine whether the reported address is usable, so no separate memory-error classification is needed.
On AMD, a corrected legacy bank 4 DRAM ECC error (XEC 8) reports a usable address and retired the aliased page before this change. Tested under QEMU with Intel Skylake-Server and AMD EPYC-Milan models.
--- drivers/cxl/core/mce.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/cxl/core/mce.c +7 -1
@@ -18,7 +18,13 @@ static int cxl_handle_mce(struct notifier_block *nb, unsigned long val,u64 spa, spa_alias;unsigned long pfn; -if (!mce || !mce_usable_address (mce)) +if (!mce) +return NOTIFY_DONE ; + +if (mce_is_correctable (mce)) +return NOTIFY_DONE ; + +if (!mce_usable_address (mce))return NOTIFY_DONE ; spa = mce->addr &MCI_ADDR_PHYSADDR ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 176/2151 remoteproc: xlnx: Initialize mailbox work before requesting channels
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 5ca7dea7cb2e47f42c15ac7206c5e0cba23d292d ]
zynqmp_r5_setup_mbox() installs zynqmp_r5_mb_rx_cb() as the mailbox RX callback before requesting the mailbox channels, but initializes ipi->mbox_work only after both channels have been requested. Once the RX channel is active, a notification delivered before the late INIT_WORK() would make the callback queue an uninitialized work item.
Initialize the work item before requesting channels. Also drain the work before freeing the mailbox state, after the channels have been released so no new callbacks can queue it. Use the same drain before freeing ipi from the channel request error paths, since the callback is already published there as well.
This issue was found by our static analysis tool and then confirmed by manual review of the mailbox setup sequence. The callback is published before the channel requests complete, so the work item should be ready before the mailbox provider can invoke it.
A QEMU PoC modeled a mailbox notification delivered after the RX callback became reachable but before the delayed INIT_WORK(). DEBUG_OBJECTS reported queueing an uninitialized work item from the zynqmp_r5_setup_mbox() path.
This is sent as an RFC because the practical trigger depends on the ZynqMP IPI mailbox provider and firmware delivery timing. If the provider cannot invoke the RX callback until after setup returns, this is a defensive lifecycle cleanup rather than a reachable race on current systems.
--- drivers/remoteproc/xlnx_r5_remoteproc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +6 -2
@@ -271,6 +271,8 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev)if (!ipi)return NULL ; +INIT_WORK (&ipi->mbox_work, handle_event_notified); + mbox_cl = &ipi->mbox_cl; mbox_cl->rx_callback = zynqmp_r5_mb_rx_cb; mbox_cl->tx_block = false;
@@ -282,6 +284,7 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev) ipi->tx_chan =mbox_request_channel_byname (mbox_cl,"tx" );if (IS_ERR (ipi->tx_chan)) { ipi->tx_chan =NULL ; +cancel_work_sync (&ipi->mbox_work);kfree (ipi);dev_warn (cdev,"mbox tx channel request failed\n" );return NULL ;
@@ -292,13 +295,12 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev)mbox_free_channel (ipi->tx_chan); ipi->rx_chan =NULL ; ipi->tx_chan =NULL ; +cancel_work_sync (&ipi->mbox_work);kfree (ipi);dev_warn (cdev,"mbox rx channel request failed\n" );return NULL ; } -INIT_WORK (&ipi->mbox_work, handle_event_notified); -return ipi; }
@@ -317,6 +319,8 @@ static void zynqmp_r5_free_mbox(struct mbox_info *ipi) ipi->rx_chan =NULL ; } +cancel_work_sync (&ipi->mbox_work); +kfree (ipi); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 177/2151 dt-bindings: clock: qcom,milos-camcc: Document interconnect path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luca Weiss <[email protected]>
[ Upstream commit 7e622e74d2700da4d6ed3aa2a4d7e1b7d7293768 ]
Document an interconnect path for camcc which needs to be enabled so that the CAMSS_TOP_GDSC power domain can turn on successfully.
Stable-dep-of: e0f335a4e17f ("dt-bindings: clock: qcom,milos-camcc: Add missing power-domains support")
--- .../devicetree/bindings/clock/qcom,milos-camcc.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/clock/qcom,milos-camcc.yaml +8 -0
@@ -25,6 +25,10 @@ properties: - description: Sleep clock source - description: Camera AHB clock from GCC + interconnects: + items: + - description: Interconnect path to enable the MultiMedia NoC + required: - compatible - clocks
@@ -37,12 +41,16 @@ unevaluatedProperties: false examples: - | #include <dt-bindings/clock/qcom,milos-gcc.h> + #include <dt-bindings/interconnect/qcom,icc.h> + #include <dt-bindings/interconnect/qcom,milos-rpmh.h> clock-controller@adb0000 { compatible = "qcom,milos-camcc"; reg = <0x0adb0000 0x40000>; clocks = <&bi_tcxo_div2>, <&sleep_clk>, <&gcc GCC_CAMERA_AHB_CLK>; + interconnects = <&mmss_noc MASTER_CAMNOC_HF QCOM_ICC_TAG_ALWAYS + &mmss_noc SLAVE_MNOC_HF_MEM_NOC QCOM_ICC_TAG_ALWAYS>; #clock-cells = <1>; #reset-cells = <1>; #power-domain-cells = <1>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 178/2151 dt-bindings: clock: qcom,milos-camcc: Add missing power-domains support
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Taniya Das <[email protected]>
[ Upstream commit e0f335a4e17f5c80b24b8bd2060802bac072775c ]
The Milos camera clock controller requires the CX and MX power domains, along with their performance state votes, to be enabled before the clock controller can be accessed.
Document the 'power-domains' and 'required-opps' properties and add them to the required properties list and example. Since these properties become required for the already-documented qcom,milos-camcc compatible, this is an ABI break for any devicetree using this binding without specifying them.
--- .../bindings/clock/qcom,milos-camcc.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
Documentation/devicetree/bindings/clock/qcom,milos-camcc.yaml +19 -0
@@ -29,9 +29,21 @@ properties: items: - description: Interconnect path to enable the MultiMedia NoC + power-domains: + items: + - description: CX power domain + - description: MX power domain + + required-opps: + items: + - description: CX performance point + - description: MX performance point + required: - compatible - clocks + - power-domains + - required-opps allOf: - $ref: qcom,gcc.yaml#
@@ -43,6 +55,7 @@ examples: #include <dt-bindings/clock/qcom,milos-gcc.h> #include <dt-bindings/interconnect/qcom,icc.h> #include <dt-bindings/interconnect/qcom,milos-rpmh.h> + #include <dt-bindings/power/qcom,rpmhpd.h> clock-controller@adb0000 { compatible = "qcom,milos-camcc"; reg = <0x0adb0000 0x40000>;
@@ -51,6 +64,12 @@ examples: <&gcc GCC_CAMERA_AHB_CLK>; interconnects = <&mmss_noc MASTER_CAMNOC_HF QCOM_ICC_TAG_ALWAYS &mmss_noc SLAVE_MNOC_HF_MEM_NOC QCOM_ICC_TAG_ALWAYS>; + + power-domains = <&rpmhpd RPMHPD_CX>, + <&rpmhpd RPMHPD_MX>; + required-opps = <&rpmhpd_opp_low_svs>, + <&rpmhpd_opp_low_svs>; + #clock-cells = <1>; #reset-cells = <1>; #power-domain-cells = <1>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 179/2151 dt-bindings: clock: qcom,milos-videocc: Add missing power-domains support
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Taniya Das <[email protected]>
[ Upstream commit 3da90acddd2f211549032e9fdad40a5879803442 ]
The Milos video clock controller requires the CX and MX power domains, along with their performance state votes, to be enabled before the clock controller can be accessed.
Document the 'power-domains' and 'required-opps' properties and add them to the required properties list and example. Since these properties become required for the already-documented qcom,milos-videocc compatible, this is an ABI break for any devicetree using this binding without specifying them.
--- .../bindings/clock/qcom,milos-videocc.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
Documentation/devicetree/bindings/clock/qcom,milos-videocc.yaml +19 -0
@@ -26,9 +26,21 @@ properties: - description: Sleep clock source - description: Video AHB clock from GCC + power-domains: + items: + - description: CX power domain + - description: MX power domain + + required-opps: + items: + - description: CX performance point + - description: MX performance point + required: - compatible - clocks + - power-domains + - required-opps allOf: - $ref: qcom,gcc.yaml#
@@ -38,6 +50,7 @@ unevaluatedProperties: false examples: - | #include <dt-bindings/clock/qcom,milos-gcc.h> + #include <dt-bindings/power/qcom,rpmhpd.h> clock-controller@aaf0000 { compatible = "qcom,milos-videocc"; reg = <0x0aaf0000 0x10000>;
@@ -45,6 +58,12 @@ examples: <&bi_tcxo_ao_div2>, <&sleep_clk>, <&gcc GCC_VIDEO_AHB_CLK>; + + power-domains = <&rpmhpd RPMHPD_CX>, + <&rpmhpd RPMHPD_MX>; + required-opps = <&rpmhpd_opp_low_svs>, + <&rpmhpd_opp_low_svs>; + #clock-cells = <1>; #reset-cells = <1>; #power-domain-cells = <1>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 180/2151 lsm: dont call security_backing_file_free() multiple times
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cai Xinchen <[email protected]>
[ Upstream commit 3a84fc1a21577dbc8da7e4b6a49c9d8b07c07000 ]
I found the following path:
alloc_empty_backing-file
init_file(&ff->file, xxx)
-> file_ref_init(&f->f_ref, 1); // only 1
error = init_backing_file
-> security_backing_file_alloc
-> rc = call_int_hook(backing_file_alloc, ...)
if (unlikely(rc))
security_backing_file_free(backing_file); // first call
if (unlikely(error)) {
fput(&ff->file);
-> if (unlikely(file_ref_put(&file->f_ref))) // zero
__fput_deferred(file);
-> ____fput -> __fput -> file_free(file);
-> backing_file_free(backing_file(f));
-> security_backing_file_free(&ff->file); // second callCurrently, only SELinux has the lsm backing_file_alloc hook, and it always return 0. When security_backing_file_free is called for the first time, the blobs pointer is set to NULL. Therefore, double free will not occur in the code.
--- security/security.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
security/security.c +1 -2
@@ -3040,9 +3040,8 @@ void security_backing_file_free(struct file *backing_file) {void *blob =backing_file_security (backing_file); -call_void_hook (backing_file_free, backing_file); -if (blob) { +call_void_hook (backing_file_free, backing_file);backing_file_set_security (backing_file,NULL );kmem_cache_free (lsm_backing_file_cache, blob); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 181/2151 ASoC: wcd-mbhc-v2: Fix incorrect properties names and typos
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Heidelberg <[email protected]>
[ Upstream commit 17bca5d55446c1e21944d47354ee2f0b80db36d6 ]
Improves debugging experience.
--- sound/soc/codecs/wcd-mbhc-v2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/wcd-mbhc-v2.c +4 -4
@@ -864,7 +864,7 @@ static int wcd_measure_adc_continuous(struct wcd_mbhc *mbhc)u8 adc_en;/* Pre-requisites for ADC continuous measurement */ -/* Read legacy electircal detection and disable */ +/* Read legacy electrical detection and disable */ wcd_mbhc_write_field (mbhc,WCD_MBHC_ELECT_SCHMT_ISRC ,0x00 );/* Set ADC to continuous measurement */ wcd_mbhc_write_field (mbhc,WCD_MBHC_ADC_MODE ,1 );
@@ -965,7 +965,7 @@ static int wcd_check_cross_conn(struct wcd_mbhc *mbhc)if (wcd_mbhc_read_field (mbhc,WCD_MBHC_HPH_PA_EN ))return -EINVAL ; -/* Read legacy electircal detection and disable */ +/* Read legacy electrical detection and disable */ elect_ctl =wcd_mbhc_read_field (mbhc,WCD_MBHC_ELECT_SCHMT_ISRC );wcd_mbhc_write_field (mbhc,WCD_MBHC_ELECT_SCHMT_ISRC ,0 );
@@ -1470,14 +1470,14 @@ int wcd_dt_parse_mbhc_data(struct device *dev, struct wcd_mbhc_config *cfg) ret =of_property_read_u32 (np,"qcom,mbhc-headset-vthreshold-microvolt" , µvolt);if (ret) -dev_dbg (dev,"missing qcom,mbhc-hs-mic-max-vthreshold--microvolt in dt node\n" ); +dev_dbg (dev,"missing qcom,mbhc-headset-vthreshold-microvolt in dt node\n" );else cfg->hs_thr = microvolt/1000 ; ret =of_property_read_u32 (np,"qcom,mbhc-headphone-vthreshold-microvolt" , µvolt);if (ret) -dev_dbg (dev,"missing qcom,mbhc-hs-mic-min-vthreshold-microvolt entry\n" ); +dev_dbg (dev,"missing qcom,mbhc-headphone-vthreshold-microvolt entry\n" );else cfg->hph_thr = microvolt/1000 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 182/2151 pwm: renesas-tpu: Fix runtime PM reference leak
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 62cff15fbf2b12ebbb0b01ca720030c2bc12aed1 ]
tpu_pwm_timer_start() used pm_runtime_get_sync() without checking its return value before touching the TPU clock. A failed runtime resume was therefore ignored, and the callback continued into register access.
Use pm_runtime_resume_and_get() and propagate a failed resume. Keep the matching put when clock preparation fails after a successful resume.
tpu_pwm_disable() also needs to propagate a failed start so that the PWM apply callback does not access registers while runtime PM is inactive.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/pwm/pwm-renesas-tpu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/pwm/pwm-renesas-tpu.c +18 -5
@@ -149,10 +149,14 @@ static int tpu_pwm_timer_start(struct tpu_pwm_device *tpd)if (!tpd->timer_on) {/* Wake up device and enable clock. */ -pm_runtime_get_sync (&tpd->tpu->pdev->dev); + ret =pm_runtime_resume_and_get (&tpd->tpu->pdev->dev); +if (ret <0 ) +return ret; + ret =clk_prepare_enable (tpd->tpu->clk);if (ret) {dev_err (&tpd->tpu->pdev->dev,"cannot enable clock\n" ); +pm_runtime_put (&tpd->tpu->pdev->dev);return ret; } tpd->timer_on = true;
@@ -382,15 +386,21 @@ static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)return 0 ; } -static void tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) +static int tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) {struct tpu_device *tpu =to_tpu_device (chip);struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; +int ret;/* The timer must be running to modify the pin output configuration. */ -tpu_pwm_timer_start (tpd); + ret =tpu_pwm_timer_start (tpd); +if (ret <0 ) +return ret; +tpu_pwm_set_pin (tpd,TPU_PIN_INACTIVE );tpu_pwm_timer_stop (tpd); + +return 0 ; } static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -401,7 +411,10 @@ static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,if (state->polarity != pwm->state.polarity) {if (enabled) { -tpu_pwm_disable (chip, pwm); + err =tpu_pwm_disable (chip, pwm); +if (err) +return err; + enabled = false; }
@@ -412,7 +425,7 @@ static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,if (!state->enabled) {if (enabled) -tpu_pwm_disable (chip, pwm); +return tpu_pwm_disable (chip, pwm);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 183/2151 spi: omap2-mcspi: Remove unbalanced pm_runtime_put_sync() calls
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit 5f01cb141169fe422c42279f7d502479b1ff9fd2 ]
pm_runtime_put_sync() is called in the probe error path and in remove when nothing holds a runtime PM reference anymore, so it underflows the usage count.
--- drivers/spi/spi-omap2-mcspi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/spi/spi-omap2-mcspi.c +0 -2
@@ -1593,7 +1593,6 @@ static int omap2_mcspi_probe(struct platform_device *pdev) disable_pm:pm_runtime_dont_use_autosuspend (&pdev->dev); -pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev); free_ctlr:omap2_mcspi_release_dma (ctlr);
@@ -1613,7 +1612,6 @@ static void omap2_mcspi_remove(struct platform_device *pdev)omap2_mcspi_release_dma (ctlr);pm_runtime_dont_use_autosuspend (mcspi->dev); -pm_runtime_put_sync (mcspi->dev);pm_runtime_disable (&pdev->dev);spi_controller_put (ctlr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 184/2151 soc: qcom: apr: clean up failed service registrations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongyan Xu <[email protected]>
[ Upstream commit 7dc14f37ca4ee35040c67c4b0180dd7b32079caf ]
apr_add_device() publishes a service in svcs_idr before parsing the optional protection domain and registering the device. If device registration fails, put_device() frees the apr_device while its service remains in the IDR. A received packet can then dereference that stale entry. The property error path also leaves the service and allocation behind.
Split device_register() into device_initialize() and device_add() so every pre-registration error can safely drop the device reference. Remove the service from the IDR on all failures after publication, then drain the RX workqueue before dropping the device reference. This prevents an in-flight lookup from outliving the device.
--- drivers/soc/qcom/apr.c | 44 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-)
drivers/soc/qcom/apr.c +28 -16
@@ -434,31 +434,35 @@ static int apr_add_device(struct device *dev, struct device_node *np,if (np)snprintf (adev->name,APR_NAME_SIZE ,"%pOFn" , np); + adev->dev.bus = &aprbus; + adev->dev.parent = dev; + adev->dev.of_node = np; + adev->dev.release = apr_dev_release; + adev->dev.driver =NULL ; +device_initialize (&adev->dev); +switch (apr->type) {case PR_TYPE_APR : -dev_set_name (&adev->dev,"aprsvc:%s:%x:%x" , adev->name, - domain_id, svc_id); + ret =dev_set_name (&adev->dev,"aprsvc:%s:%x:%x" , adev->name, + domain_id, svc_id);break ;case PR_TYPE_GPR : -dev_set_name (&adev->dev,"gprsvc:%s:%x:%x" , adev->name, - domain_id, svc_id); + ret =dev_set_name (&adev->dev,"gprsvc:%s:%x:%x" , adev->name, + domain_id, svc_id);break ;default : + ret = -EINVAL ;break ; } - - adev->dev.bus = &aprbus; - adev->dev.parent = dev; - adev->dev.of_node = np; - adev->dev.release = apr_dev_release; - adev->dev.driver =NULL ; +if (ret) + goto out_put_device;spin_lock (&apr->svcs_lock); ret =idr_alloc (&apr->svcs_idr, svc, svc_id, svc_id +1 ,GFP_ATOMIC );spin_unlock (&apr->svcs_lock);if (ret <0 ) {dev_err (dev,"idr_alloc failed: %d\n" , ret); - goto out; + goto out_put_device; }/* Protection domain is optional, it does not exist on older platforms */
@@ -466,18 +470,26 @@ static int apr_add_device(struct device *dev, struct device_node *np, 1, &adev->service_path);if (ret <0 && ret != -EINVAL ) {dev_err (dev,"Failed to read second value of qcom,protection-domain\n" ); - goto out; + goto out_remove_idr; }dev_info (dev,"Adding APR/GPR dev: %s\n" ,dev_name (&adev->dev)); - ret =device_register (&adev->dev); + ret =device_add (&adev->dev);if (ret) { -dev_err (dev,"device_register failed: %d\n" , ret); -put_device (&adev->dev); +dev_err (dev,"device_add failed: %d\n" , ret); + goto out_remove_idr; } -out: +return 0 ; + +out_remove_idr: +spin_lock (&apr->svcs_lock); +idr_remove (&apr->svcs_idr, svc_id); +spin_unlock (&apr->svcs_lock); +flush_workqueue (apr->rxwq); +out_put_device: +put_device (&adev->dev);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 185/2151 platform/chrome: cros_ec_proto: Fix deferred response
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rob Barnes <[email protected]>
[ Upstream commit c55749415623a58eba3eb527da023d29b43fbf5d ]
When cros_ec_wait_until_complete() succeeds after an EC_RES_IN_PROGRESS status, it previously returned the 4-byte transfer size of EC_CMD_GET_COMMS_STATUS. For 0-byte payload commands (such as EC_CMD_FLASH_ERASE), userspace received 4 bytes instead of 0, causing response size validation errors. For commands expecting non-zero response payloads, the kernel exited without issuing EC_CMD_RESEND_RESPONSE, leaving response buffers uninitialized.
Refactor cros_ec_wait_until_complete() to pass orig_msg, issue EC_CMD_RESEND_RESPONSE into orig_msg->data when insize > 0, and return 0 for 0-byte response commands.
--- drivers/platform/chrome/cros_ec_proto.c | 32 +++- drivers/platform/chrome/cros_ec_proto_test.c | 158 ++++++++++++++++++- 2 files changed, 183 insertions(+), 7 deletions(-)
drivers/platform/chrome/cros_ec_proto.c +28 -4
@@ -138,7 +138,8 @@ static int cros_ec_xfer_command(struct cros_ec_device *ec_dev, struct cros_ec_coreturn ret; } -static int cros_ec_wait_until_complete (struct cros_ec_device *ec_dev,uint32_t *result) +static int cros_ec_wait_until_complete (struct cros_ec_device *ec_dev, +struct cros_ec_command *orig_msg) { DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, sizeof(struct ec_response_get_comms_status));
@@ -161,7 +162,7 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *if (ret <0 )return ret; - *result = msg->result; + orig_msg->result = msg->result;if (msg->result !=EC_RES_SUCCESS )return ret;
@@ -170,8 +171,31 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *break ; } -if (!(status->flags &EC_COMMS_STATUS_PROCESSING )) +if (!(status->flags &EC_COMMS_STATUS_PROCESSING )) { +u32 orig_cmd, orig_outsize, orig_version; + +/* If no response payload is expected, return 0. */ +if (orig_msg->insize ==0 ) +return 0 ; + +/* +* Request the response using EC_CMD_RESEND_RESPONSE. +* Restore the original message fields so it appears +* to be a direct response to the original command. +*/ + orig_cmd = orig_msg->command; + orig_outsize = orig_msg->outsize; + orig_version = orig_msg->version; + + orig_msg->command =EC_CMD_RESEND_RESPONSE ; + orig_msg->outsize =0 ; + orig_msg->version =0 ; + ret =cros_ec_xfer_command (ec_dev, orig_msg); + orig_msg->command = orig_cmd; + orig_msg->outsize = orig_outsize; + orig_msg->version = orig_version;return ret; + } }if (i >=EC_COMMAND_RETRIES )
@@ -185,7 +209,7 @@ static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_coint ret =cros_ec_xfer_command (ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) - ret =cros_ec_wait_until_complete (ec_dev, &msg->result); + ret =cros_ec_wait_until_complete (ec_dev, msg);return ret; }
drivers/platform/chrome/cros_ec_proto_test.c +155 -3
182 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 186/2151 staging: rtl8723bs: remove unused private debug counters
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Tidmore <[email protected]>
[ Upstream commit 7de30d5d76aa614777a02a9807d29ed65b0704a0 ]
The driver maintains a private struct debug_priv embedded within struct dvobj_priv to track various error counters (e.g., suspend errors, alloc failures, RX drops).
These counters are incremented in various files but the data is never read or exposed to userspace.
Remove the unused debug_priv structure definition, the instance in dvobj_priv, and all associated increment operations across the driver to clean up the code.
This also removes the following helper functions which were used solely to update these counters:
- rtw_reset_rx_info()
- recv_indicatepkts_pkt_loss_cnt()
Stable-dep-of: baa84b1bb164 ("staging: rtl8723bs: disable SDIO function on block size failure")
--- drivers/staging/rtl8723bs/core/rtw_mlme.c | 13 ------ drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 3 -- drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 6 +-- drivers/staging/rtl8723bs/core/rtw_recv.c | 24 +--------- drivers/staging/rtl8723bs/hal/hal_com.c | 13 ------ .../staging/rtl8723bs/hal/rtl8723b_hal_init.c | 4 -- drivers/staging/rtl8723bs/hal/sdio_halinit.c | 8 +--- drivers/staging/rtl8723bs/include/drv_types.h | 41 ----------------- drivers/staging/rtl8723bs/os_dep/os_intfs.c | 15 +------ drivers/staging/rtl8723bs/os_dep/sdio_intf.c | 45 +++++-------------- 10 files changed, 15 insertions(+), 157 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme.c +0 -13
@@ -828,15 +828,6 @@ static void free_scanqueue(struct mlme_priv *pmlmepriv)spin_unlock_bh (&scan_queue->lock); } -static void rtw_reset_rx_info (struct debug_priv *pdbgpriv) -{ - pdbgpriv->dbg_rx_ampdu_drop_count =0 ; - pdbgpriv->dbg_rx_ampdu_forced_indicate_count =0 ; - pdbgpriv->dbg_rx_ampdu_loss_count =0 ; - pdbgpriv->dbg_rx_dup_mgt_frame_drop_count =0 ; - pdbgpriv->dbg_rx_ampdu_window_shift_cnt =0 ; -} -static void find_network (struct adapter *adapter) {struct wlan_network *pwlan =NULL ;
@@ -861,8 +852,6 @@ void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue) {struct mlme_priv *pmlmepriv = &adapter->mlmepriv;struct wlan_network *tgt_network = &pmlmepriv->cur_network; -struct dvobj_priv *psdpriv = adapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;if (check_fwstate (pmlmepriv,WIFI_STATION_STATE |WIFI_AP_STATE )) {struct sta_info *psta;
@@ -886,8 +875,6 @@ void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue)if (lock_scanned_queue) adapter->securitypriv.key_mask =0 ; - -rtw_reset_rx_info (pdbgpriv); }/*
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0 -3
@@ -448,8 +448,6 @@ void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame)struct mlme_priv *pmlmepriv = &padapter->mlmepriv;u8 *pframe = precv_frame->u.hdr.rx_data;struct sta_info *psta =rtw_get_stainfo (&padapter->stapriv,GetAddr2Ptr (pframe)); -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;if (GetFrameType (pframe) !=WIFI_MGT_TYPE )return ;
@@ -473,7 +471,6 @@ void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame)if (GetRetry (pframe)) {if (precv_frame->u.hdr.attrib.seq_num == psta->RxMgmtFrameSeqNum) {/* drop the duplicate management frame */ - pdbgpriv->dbg_rx_dup_mgt_frame_drop_count++;return ; } }
drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +1 -5
@@ -139,8 +139,6 @@ static bool rtw_pwr_unassociated_idle(struct adapter *adapter)void rtw_ps_processor (struct adapter *padapter) {struct pwrctrl_priv *pwrpriv =adapter_to_pwrctl (padapter); -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;u32 ps_deny =0 ;mutex_lock (&adapter_to_pwrctl (padapter)->lock);
@@ -149,10 +147,8 @@ void rtw_ps_processor(struct adapter *padapter)if (ps_deny !=0 ) goto exit; -if (pwrpriv->bInSuspend) {/* system suspend or autosuspend */ - pdbgpriv->dbg_ps_insuspend_cnt++; +if (pwrpriv->bInSuspend)/* system suspend or autosuspend */ return ; - } pwrpriv->ps_processing = true;
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -23
@@ -1779,9 +1779,6 @@ static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe)static int check_indicate_seq (struct recv_reorder_ctrl *preorder_ctrl,u16 seq_num) { -struct adapter *padapter = preorder_ctrl->padapter; -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;u8 wsize = preorder_ctrl->wsize_b;u16 wend = (preorder_ctrl->indicate_seq + wsize -1 ) %4096u ;
@@ -1807,7 +1804,6 @@ static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_n preorder_ctrl->indicate_seq = seq_num +1 - wsize; else preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1; - pdbgpriv->dbg_rx_ampdu_window_shift_cnt++; }return true;
@@ -1856,15 +1852,6 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, un } -static void recv_indicatepkts_pkt_loss_cnt (struct debug_priv *pdbgpriv,u64 prev_seq,u64 current_seq) -{ -if (current_seq < prev_seq) - pdbgpriv->dbg_rx_ampdu_loss_count += (4096 + current_seq - prev_seq); -else - pdbgpriv->dbg_rx_ampdu_loss_count += (current_seq - prev_seq); - -} -static int rtw_recv_indicatepkt (struct adapter *padapter,union recv_frame *precv_frame) {struct recv_priv *precvpriv;
@@ -1911,8 +1898,6 @@ static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorint bPktInBuf = false;struct recv_priv *precvpriv = &padapter->recvpriv;struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;/* spin_lock_irqsave(&ppending_recvframe_queue->lock, irql); */ /* spin_lock(&ppending_recvframe_queue->lock); */
@@ -1922,7 +1907,6 @@ static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reor/* Handling some condition for forced indicate case. */ if (bforced == true) { - pdbgpriv->dbg_rx_ampdu_forced_indicate_count++;if (list_empty (phead)) {/* spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); */ /* spin_unlock(&ppending_recvframe_queue->lock); */
@@ -1932,7 +1916,6 @@ static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reor prframe = (union recv_frame *)plist; pattrib = &prframe->u.hdr.attrib; -recv_indicatepkts_pkt_loss_cnt (pdbgpriv, preorder_ctrl->indicate_seq, pattrib->seq_num); preorder_ctrl->indicate_seq = pattrib->seq_num; }
@@ -1992,8 +1975,6 @@ static int recv_indicatepkt_reorder(struct adapter *padapter, union recv_frame *struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;struct recv_reorder_ctrl *preorder_ctrl = prframe->u.hdr.preorder_ctrl;struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;if (!pattrib->amsdu) {/* s1. */
@@ -2039,11 +2020,8 @@ static int recv_indicatepkt_reorder(struct adapter *padapter, union recv_frame *spin_lock_bh (&ppending_recvframe_queue->lock);/* s2. check if winstart_b(indicate_seq) needs to been updated */ -if (!check_indicate_seq (preorder_ctrl, pattrib->seq_num)) { - pdbgpriv->dbg_rx_ampdu_drop_count++; +if (!check_indicate_seq (preorder_ctrl, pattrib->seq_num)) goto _err_exit; - } -/* s3. Insert all packet into Reorder Queue to maintain its ordering. */ if (!enqueue_reorder_recvframe (preorder_ctrl, prframe)) {
drivers/staging/rtl8723bs/hal/hal_com.c +0 -13
@@ -847,21 +847,8 @@ bool GetU1ByteIntegerFromStringInDecimal(char *Str, u8 *pInt)void rtw_hal_check_rxfifo_full (struct adapter *adapter) { -struct dvobj_priv *psdpriv = adapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg; -int save_cnt = false; -/* switch counter to RX fifo */ rtw_write8 (adapter,REG_RXERR_RPT +3 ,rtw_read8 (adapter,REG_RXERR_RPT +3 )|0xf0 ); - save_cnt = true; -/* todo: other chips */ - -if (save_cnt) { -/* rtw_write8(adapter, REG_RXERR_RPT+3, rtw_read8(adapter, REG_RXERR_RPT+3)|0xa0); */ - pdbgpriv->dbg_rx_fifo_last_overflow = pdbgpriv->dbg_rx_fifo_curr_overflow; - pdbgpriv->dbg_rx_fifo_curr_overflow =rtw_read16 (adapter,REG_RXERR_RPT ); - pdbgpriv->dbg_rx_fifo_diff_overflow = pdbgpriv->dbg_rx_fifo_curr_overflow-pdbgpriv->dbg_rx_fifo_last_overflow; - } }static u32 Array_kfreemap[] = {
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c +0 -4
@@ -304,8 +304,6 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)const struct firmware *fw;struct device *device =dvobj_to_dev (padapter->dvobj);u8 *fwfilepath; -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;u8 tmp_ps; pFirmware =kzalloc (sizeof (struct rt_firmware ),GFP_KERNEL );
@@ -324,8 +322,6 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)/* 2. read power_state = 0xA0[1:0] */ tmp_ps =rtw_read8 (padapter,0xa0 ); tmp_ps &=0x03 ; -if (tmp_ps !=0x01 ) - pdbgpriv->dbg_downloadfw_pwr_state_cnt++; fwfilepath ="rtlwifi/rtl8723bs_nic.bin" ;
drivers/staging/rtl8723bs/hal/sdio_halinit.c +1 -7
@@ -886,9 +886,6 @@ static void CardDisableRTL8723BSdio(struct adapter *padapter)u32 rtl8723bs_hal_deinit (struct adapter *padapter) { -struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg; -if (padapter->hw_init_completed) {if (adapter_to_pwrctl (padapter)->bips_processing) {if (padapter->netif_up) {
@@ -921,18 +918,15 @@ u32 rtl8723bs_hal_deinit(struct adapter *padapter)adapter_to_pwrctl (padapter)->pre_ips_type =0 ; }else { - pdbgpriv->dbg_carddisable_cnt++;CardDisableRTL8723BSdio (padapter);adapter_to_pwrctl (padapter)->pre_ips_type =1 ; } }else { - pdbgpriv->dbg_carddisable_cnt++;CardDisableRTL8723BSdio (padapter); } - }else - pdbgpriv->dbg_deinit_fail_cnt++; + }return _SUCCESS; }
drivers/staging/rtl8723bs/include/drv_types.h +0 -41
53 lines not on this page · raw message
drivers/staging/rtl8723bs/os_dep/os_intfs.c +2 -13
@@ -974,8 +974,6 @@ void rtw_ndev_destructor(struct net_device *ndev)void rtw_dev_unload (struct adapter *padapter) {struct pwrctrl_priv *pwrctl =adapter_to_pwrctl (padapter); -struct dvobj_priv *pobjpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &pobjpriv->drv_dbg;struct cmd_priv *pcmdpriv = &padapter->cmdpriv;u8 cnt =0 ;
@@ -1005,7 +1003,6 @@ void rtw_dev_unload(struct adapter *padapter)/* check HW status and SW state */ netdev_dbg (padapter->pnetdev,"%s: driver in IPS-FWLPS\n" , __func__); - pdbgpriv->dbg_dev_unload_inIPS_cnt++;LeaveAllPowerSaveMode (padapter); }else { netdev_dbg(padapter->pnetdev,
@@ -1089,24 +1086,21 @@ static void rtw_suspend_normal(struct adapter *padapter)void rtw_suspend_common (struct adapter *padapter) {struct dvobj_priv *psdpriv = padapter->dvobj; -struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;struct pwrctrl_priv *pwrpriv =dvobj_to_pwrctl (psdpriv);struct mlme_priv *pmlmepriv = &padapter->mlmepriv;unsigned long start_time = jiffies;netdev_dbg (padapter->pnetdev," suspend start\n" ); - pdbgpriv->dbg_suspend_cnt++; pwrpriv->bInSuspend = true;while (pwrpriv->bips_processing)msleep (1 ); -if ((!padapter->bup) || (padapter->bDriverStopped) || (padapter->bSurpriseRemoved)) { - pdbgpriv->dbg_suspend_error_cnt++; +if ((!padapter->bup) || (padapter->bDriverStopped) || (padapter->bSurpriseRemoved))return ; - } +rtw_ps_deny (padapter,PS_DENY_SUSPEND );rtw_cancel_all_timer (padapter);
@@ -1134,8 +1128,6 @@ static int rtw_resume_process_normal(struct adapter *padapter)struct net_device *pnetdev;struct pwrctrl_priv *pwrpriv;struct mlme_priv *pmlmepriv; -struct dvobj_priv *psdpriv; -struct debug_priv *pdbgpriv;int ret = _SUCCESS;
@@ -1147,8 +1139,6 @@ static int rtw_resume_process_normal(struct adapter *padapter) pnetdev = padapter->pnetdev; pwrpriv =adapter_to_pwrctl (padapter); pmlmepriv = &padapter->mlmepriv; - psdpriv = padapter->dvobj; - pdbgpriv = &psdpriv->drv_dbg;/* interface init */ /* if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) */ if ((padapter->intf_init) && (padapter->intf_init (adapter_to_dvobj (padapter)) != _SUCCESS)) {
@@ -1167,7 +1157,6 @@ static int rtw_resume_process_normal(struct adapter *padapter)if (pm_netdev_open (pnetdev, true) !=0 ) { ret =-1 ; - pdbgpriv->dbg_resume_error_cnt++; goto exit; }
drivers/staging/rtl8723bs/os_dep/sdio_intf.c +10 -35
110 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 187/2151 staging: rtl8723bs: disable SDIO function on block size failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit baa84b1bb1648506333fde3e66b6540f9d7d73cc ]
sdio_init() enables the SDIO function before configuring the block size. If sdio_set_block_size() fails, the function jumps to the release path and returns the error without disabling the SDIO function. The caller then frees the dvobj directly, so the enabled SDIO function is left active on that probe failure path.
Disable the SDIO function before releasing the host when block size configuration fails.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/staging/rtl8723bs/os_dep/sdio_intf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/os_dep/sdio_intf.c +3 -1
@@ -121,8 +121,10 @@ static u32 sdio_init(struct dvobj_priv *dvobj) goto release; err =sdio_set_block_size (func,512 ); -if (err) +if (err) { +sdio_disable_func (func); goto release; + } psdio_data->block_transfer_len =512 ; psdio_data->tx_block_mode =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 188/2151 staging: octeon: schedule the TX cleanup tasklet every 1024th packet
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Orgad Shaneh <[email protected]>
[ Upstream commit db57f6517bf65523968ae29cd34a790bfa7d32af ]
cvm_oct_xmit() means to schedule the cleanup tasklet once every 1024 packets, as its comment says, to cover the pathological case of heavy traffic on one port delaying the cleanup of another port blocked waiting for it.
The test is inverted: total_to_clean & 0x3ff is true for 1023 of every 1024 values, and false only on the multiples of 1024. So the tasklet is scheduled on nearly every packet, and skipped on exactly the packet the comment wants. That costs one TASKLET softirq per transmitted packet, each walking every port and doing an FAU fetch-and-add per non-empty queue, and it buys nothing for this port, which already frees its completed skbs inline from the skb_to_free value it reads out of the FAU.
Test the mask against zero. On a CN50XX board (2 cores at 300MHz) carrying ~6.9k transmitted packets/s, TASKLET softirqs drop from 7133/s to 597/s with no throughput change; the freeing work is conserved, so this removes softirq entries, not work.
--- drivers/staging/octeon/ethernet-tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/octeon/ethernet-tx.c +1 -1
@@ -482,7 +482,7 @@ netdev_tx_t cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)cvmx_fau_fetch_and_add32 (FAU_TOTAL_TX_TO_CLEAN ,1 ); } -if (total_to_clean &0x3ff ) { +if ((total_to_clean &0x3ff ) ==0 ) {/* * Schedule the cleanup tasklet every 1024 packets for * the pathological case of high traffic on one port
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 189/2151 clk: fix self-consuming provider module pinning
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jerome Brunet <[email protected]>
[ Upstream commit a1c8d531c694e193dc48ef2428877d5ea2e35134 ]
clk_hw_get_clk() lets a provider get a struct clk for one of its own struct clk_hw.
When a struct clk is created, the module usage count of the provider is unconditionally increased. For a self-consuming provider, this means it pins itself and the module can never be unloaded.
Increasing the module usage count should only be done when the consumer lives in a different module from the provider. Use THIS_MODULE to capture caller's module and increase the module usage count accordingly.
It is OK for consumer-only APIs such as clk_get() or of_clk_get() to pass a NULL owner. As a result, any provider module will get pinned, same as before.
--- drivers/clk/clk.c | 46 ++++++++++++++++++++---------------- drivers/clk/clk.h | 5 ++-- drivers/clk/clkdev.c | 4 ++-- include/linux/clk-provider.h | 22 ++++++++++++++--- 4 files changed, 50 insertions(+), 27 deletions(-)
drivers/clk/clk.c +26 -20
@@ -115,6 +115,7 @@ struct clk {unsigned long max_rate;unsigned int exclusive_count;struct hlist_node clks_node; +bool pinning; };/*** runtime pm ***/
@@ -4153,13 +4154,15 @@ static void free_clk(struct clk *clk)* @hw: clk_hw associated with the clk being consumed * @dev_id: string describing device name * @con_id: connection ID string on device +* @owner: reference to the module creating the clock * * This is the main function used to create a clk pointer for use by clk * consumers. It connects a consumer to the clk_core and clk_hw structures * used by the framework and clk provider respectively. */ struct clk *clk_hw_create_clk (struct device *dev,struct clk_hw *hw, -const char *dev_id,const char *con_id) +const char *dev_id,const char *con_id, +struct module *owner) {struct clk *clk;struct clk_core *core;
@@ -4174,7 +4177,13 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,return clk; clk->dev = dev; -if (!try_module_get (core->owner)) { +/* +* Pin the provider module only when the consumer lives in a different +* module. A provider getting a clk from its own clk_hw would otherwise +* pin itself and could never be unloaded. +*/ + clk->pinning = owner != core->owner; +if (clk->pinning && !try_module_get (core->owner)) {free_clk (clk);return ERR_PTR (-ENOENT ); }
@@ -4185,24 +4194,19 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,return clk; } -/** -* clk_hw_get_clk - get clk consumer given an clk_hw -* @hw: clk_hw associated with the clk being consumed -* @con_id: connection ID string on device -* -* Returns: new clk consumer -* This is the function to be used by providers which need -* to get a consumer clk and act on the clock element -* Calls to this function must be balanced with calls clk_put() +/* +* Internal helper backing the clk_hw_get_clk() macro, which passes the caller's +* module via THIS_MODULE. */ -struct clk *clk_hw_get_clk (struct clk_hw *hw,const char *con_id) +struct clk *__clk_hw_get_clk (struct clk_hw *hw,const char *con_id, +struct module *owner) {struct device *dev = hw->core->dev;const char *name = dev ?dev_name (dev) :NULL ; -return clk_hw_create_clk (dev, hw, name, con_id); +return clk_hw_create_clk (dev, hw, name, con_id, owner); } -EXPORT_SYMBOL (clk_hw_get_clk); +EXPORT_SYMBOL (__clk_hw_get_clk);static int clk_cpy_name (const char **dst_p,const char *src,bool must_exist) {
@@ -4366,8 +4370,9 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw)INIT_HLIST_HEAD (&core->clks);/* -* Don't call clk_hw_create_clk() here because that would pin the -* provider module to itself and prevent it from ever being removed. +* Don't call clk_hw_create_clk() here because it would systematically +* add a consumer to the hw clock and all clocks would appear to have +* consumer in the clock summary. */ hw->clk =alloc_clk (core,NULL ,NULL );if (IS_ERR (hw->clk)) {
@@ -4724,7 +4729,7 @@ struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,if (!clkp)return ERR_PTR (-ENOMEM ); - clk =clk_hw_get_clk (hw, con_id); + clk =__clk_hw_get_clk (hw, con_id, dev->driver->owner);if (!IS_ERR (clk)) { *clkp = clk;devres_add (dev, clkp);
@@ -4771,7 +4776,8 @@ void __clk_put(struct clk *clk) owner = clk->core->owner;kref_put (&clk->core->ref, __clk_release); -module_put (owner); +if (clk->pinning) +module_put (owner);free_clk (clk); }
@@ -5292,7 +5298,7 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) {struct clk_hw *hw =of_clk_get_hw_from_clkspec (clkspec); -return clk_hw_create_clk (NULL , hw,NULL , __func__); +return clk_hw_create_clk (NULL , hw,NULL , __func__,NULL ); }EXPORT_SYMBOL_GPL (of_clk_get_from_provider);
@@ -5319,7 +5325,7 @@ static struct clk *__of_clk_get(struct device_node *np, {struct clk_hw *hw =of_clk_get_hw (np, index, con_id); -return clk_hw_create_clk (NULL , hw, dev_id, con_id); +return clk_hw_create_clk (NULL , hw, dev_id, con_id,NULL ); }struct clk *of_clk_get (struct device_node *np,int index)
drivers/clk/clk.h +3 -2
@@ -23,13 +23,14 @@ struct clk_hw *clk_find_hw(const char *dev_id, const char *con_id);#ifdef CONFIG_COMMON_CLK struct clk *clk_hw_create_clk (struct device *dev,struct clk_hw *hw, -const char *dev_id,const char *con_id); +const char *dev_id,const char *con_id, +struct module *owner);void __clk_put (struct clk *clk);#else /* All these casts to avoid ifdefs in clkdev... */ static inline struct clk *clk_hw_create_clk (struct device *dev,struct clk_hw *hw,const char *dev_id, -const char *con_id) +const char *con_id,struct module *owner) {return (struct clk *)hw; }
drivers/clk/clkdev.c +2 -2
@@ -88,7 +88,7 @@ static struct clk *__clk_get_sys(struct device *dev, const char *dev_id, {struct clk_hw *hw =clk_find_hw (dev_id, con_id); -return clk_hw_create_clk (dev, hw, dev_id, con_id); +return clk_hw_create_clk (dev, hw, dev_id, con_id,NULL ); }struct clk *clk_get_sys (const char *dev_id,const char *con_id)
@@ -105,7 +105,7 @@ struct clk *clk_get(struct device *dev, const char *con_id)if (dev && dev->of_node) { hw =of_clk_get_hw (dev->of_node,0 , con_id);if (!IS_ERR (hw) ||PTR_ERR (hw) == -EPROBE_DEFER ) -return clk_hw_create_clk (dev, hw, dev_id, con_id); +return clk_hw_create_clk (dev, hw, dev_id, con_id,NULL ); }return __clk_get_sys (dev, dev_id, con_id);
include/linux/clk-provider.h +19 -3
@@ -37,6 +37,7 @@ struct clk;struct clk_hw ;struct clk_core ;struct dentry ; +struct module ;/** * struct clk_rate_request - Structure encoding the clk constraints that
@@ -316,8 +317,9 @@ struct clk_init_data {* @core: pointer to the struct clk_core instance that points back to this * struct clk_hw instance * -* @clk: pointer to the per-user struct clk instance that can be used to call -* into the clk API +* @clk: pointer to the per-user struct clk instance. This will be removed at +* some point in the future, Please consider the field obsolete and do not use +* it. Use clk_hw_get_clk() to get a per-user struct clk from a struct clk_hw. * * @init: pointer to struct clk_init_data that contains the init data shared * with the common clock framework. This pointer will be set to NULL once
@@ -1395,10 +1397,24 @@ static inline struct clk_hw *__clk_get_hw(struct clk *clk) }#endif -struct clk *clk_hw_get_clk (struct clk_hw *hw,const char *con_id); +struct clk *__clk_hw_get_clk (struct clk_hw *hw,const char *con_id, +struct module *owner);struct clk *devm_clk_hw_get_clk (struct device *dev,struct clk_hw *hw,const char *con_id); +/** +* clk_hw_get_clk - get clk consumer given a clk_hw +* @hw: clk_hw associated with the clk being consumed +* @con_id: connection ID string on device +* +* Return: new clk consumer +* This is the function to be used by providers which need +* to get a consumer clk and act on the clock element +* Calls to this function must be balanced with calls to clk_put() +*/ +#define clk_hw_get_clk (hw, con_id) \ + __clk_hw_get_clk((hw), (con_id), THIS_MODULE) +unsigned int clk_hw_get_num_parents (const struct clk_hw *hw);struct clk_hw *clk_hw_get_parent (const struct clk_hw *hw); struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 190/2151 microblaze: CCF: fix refcount leak
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander A. Klimov <[email protected]>
[ Upstream commit aeedf85beac51c7cd8f7bf4c918a0104dfdb8b78 ]
Every value returned from of_clk_get() is supposed to be cleaned up via clk_put() once not needed anymore.
--- arch/microblaze/kernel/cpu/cpuinfo.c | 1 + 1 file changed, 1 insertion(+)
arch/microblaze/kernel/cpu/cpuinfo.c +1 -0
@@ -133,6 +133,7 @@ void __init setup_cpuinfo_clk(void) cpuinfo.cpu_clock_freq =fcpu (cpu,"timebase-frequency" ); }else { cpuinfo.cpu_clock_freq =clk_get_rate (clk); +clk_put (clk); }if (!cpuinfo.cpu_clock_freq) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 191/2151 microblaze: prevent ptrace writes to MSR and pt_mode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 8518fd17ccef4a7d77877ccb0403b722106ad1a4 ]
arch_ptrace() accepts PTRACE_POKEUSR for every aligned offset below PT_SIZE. This includes the saved machine status register and pt_mode, which are kernel-owned execution state rather than general registers.
On return from an exception, rtbd copies MSR_UMS to the live MSR_UM bit. An unprivileged same-UID tracer can therefore clear MSR_UMS in its tracee's saved register frame and make the tracee resume in supervisor mode. pt_mode also controls whether later entry paths classify the frame as kernel or user state.
Reject PTRACE_POKEUSR writes to both fields while retaining read access.
--- arch/microblaze/kernel/ptrace.c | 3 +++ 1 file changed, 3 insertions(+)
arch/microblaze/kernel/ptrace.c +3 -0
@@ -101,6 +101,9 @@ long arch_ptrace(struct task_struct *child, long request, }else { rval = -EIO ; } + }else if (request ==PTRACE_POKEUSR && + (addr ==PT_MSR || addr ==PT_MODE )) { + rval = -EIO ; }else if (addr <PT_SIZE && (addr &0x3 ) ==0 ) {microblaze_reg_t *reg_addr =reg_save_addr (addr, child);if (request ==PTRACE_PEEKUSR )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 192/2151 soundwire: intel: initialise quirk_mask before reading it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boris Faure <[email protected]>
[ Upstream commit ee8a8cfe4e8d3c67456e554c988017c252710a25 ]
sdw_master_read_intel_prop() declares quirk_mask without an initialiser and ignores the return value of fwnode_property_read_u32(). When a BIOS does not describe "intel-quirk-mask" for a link, the property read leaves the variable untouched and stack garbage decides whether SDW_INTEL_QUIRK_MASK_BUS_DISABLE is honoured, so the link may be marked hw_disabled at random.
Initialise it to 0, matching is_link_enabled() in sound/hda/core/intel-sdw-acpi.c.
Found by code inspection, not observed at run time.
--- drivers/soundwire/intel_auxdevice.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/intel_auxdevice.c +1 -1
@@ -156,7 +156,7 @@ static int sdw_master_read_intel_prop(struct sdw_bus *bus)struct sdw_intel_prop *intel_prop;struct fwnode_handle *link;char name[32 ]; -u32 quirk_mask; +u32 quirk_mask =0 ;/* Find master handle */ snprintf(name, sizeof(name),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 193/2151 arm64: dts: rockchip: Correct Device Orientation on Gameforce Ace
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Morgan <[email protected]>
[ Upstream commit 0d170ee38e7a943248082cdb4b3e40b45a96e2f6 ]
The display, touchscreen, and IMU are currently not oriented consistently. The touchscreen is 90 degrees offset and the IMU is using the default mount matrix which is 180 degrees offset.
Fix the touchscreen alignment and add a mount matrix for the IMU. When the device is held vertically relative to the display hardware, the touchscreen 0,0 position is in the top left corner of the display (next to the home button), and the IMU reads the correct orientation.
--- arch/arm64/boot/dts/rockchip/rk3588s-gameforce-ace.dts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/rockchip/rk3588s-gameforce-ace.dts +5 -2
@@ -556,6 +556,7 @@ regulator-state-mem { &i2c3 { status = "okay"; + /* Touchscreen is rotated 90 degrees with 0,0 position near home button. */ touchscreen@14 { compatible = "goodix,gt911"; reg = <0x14>;
@@ -565,10 +566,8 @@ touchscreen@14 { pinctrl-0 = <&touch_int>, <&touch_rst>; pinctrl-names = "default"; reset-gpios = <&gpio1 RK_PA7 GPIO_ACTIVE_HIGH>; - touchscreen-inverted-x; touchscreen-size-x = <1080>; touchscreen-size-y = <1920>; - touchscreen-swapped-x-y; }; };
@@ -600,11 +599,15 @@ channel@7 { }; }; + /* IMU oriented relative to panel, which is rotated 90 degrees. */ imu@68 { compatible = "invensense,mpu6880"; reg = <0x68>; interrupt-parent = <&gpio0>; interrupts = <RK_PD3 IRQ_TYPE_EDGE_RISING>; + mount-matrix = "-1", "0", "0", + "0", "-1", "0", + "0", "0", "1"; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 194/2151 cxl/ras: Pass the PCI devices struct device to match_memdev_by_parent()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 977eaad352bad4c4aac7cd15683800196c2ead57 ]
cxl_cper_handle_prot_err() hands bus_find_device() the 'struct pci_dev' where match_memdev_by_parent() expects the embedded 'struct device'. The comparison never matches. The lookup always fails and CXL endpoint protocol errors reported via CPER are dropped without a trace event, leaving only the root port, downstream and upstream cases reporting.
Pass &pdev->dev, and rename the callback parameter to match what it is.
--- drivers/cxl/core/ras.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/ras.c +3 -3
@@ -70,9 +70,9 @@ cxl_cper_trace_uncorr_prot_err(struct cxl_memdev *cxlmd,trace_cxl_aer_uncorrectable_error (cxlmd, status, fe, hl); } -static int match_memdev_by_parent (struct device *dev,const void *uport) +static int match_memdev_by_parent (struct device *dev,const void *parent) { -if (is_cxl_memdev (dev) && dev->parent == uport) +if (is_cxl_memdev (dev) && dev->parent == parent)return 1 ;return 0 ; }
@@ -108,7 +108,7 @@ static void cxl_cper_handle_prot_err(struct cxl_cper_prot_err_work_data *data)return ; struct device *mem_dev __free(put_device) = bus_find_device( - &cxl_bus_type,NULL , pdev, match_memdev_by_parent); + &cxl_bus_type,NULL , &pdev->dev, match_memdev_by_parent);if (!mem_dev)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 195/2151 wifi: rtw88: debugfs: dont vzalloc(0) when rsvd_page is read unconfigured
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdurrahman Karadag <[email protected]>
[ Upstream commit 81510c3d6f2199889a4a936d8cf8b9e05911b10e ]
Reading the rsvd_page debugfs entry before writing a page offset and count to it calls vzalloc() with a size of zero, because rsvd_page.page_num defaults to 0. vmalloc warns about this:
WARNING: mm/vmalloc.c:4019 at __vmalloc_node_range_noprof+0x9ac/0xa30 ... Call Trace: __vmalloc_node_noprof+0x4c/0x70 rtw_debugfs_get_rsvd_page+0x4c/0x110 [rtw88_core] seq_read_iter+0x132/0x4b0 seq_read+0x12e/0x1c0 full_proxy_read+0x6f/0xc0 vfs_read+0xdd/0x490
rtw_fw_dump_fifo() would reject the zero size anyway, but only after the allocation. Check for a zero buffer size first and print a short usage hint instead of allocating.
--- drivers/net/wireless/realtek/rtw88/debug.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/debug.c +5 -0
@@ -315,6 +315,11 @@ static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v)int i;int ret; +if (!buf_size) { +seq_puts (m,"usage: echo <page_offset> <page_num> > rsvd_page\n" ); +return 0 ; + } + buf =vzalloc (buf_size);if (!buf)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 196/2151 sched_ext/scx_flatcg: Make cgv_node_less() wraparound-safe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit bf2f23dc5a36237c0d4738966829e5cbde973c8a ]
cgv_node_less() compares cvtimes with a plain <, which misorders once cvtime wraps: the wrapped node lands at the front of the tree while the unwrapped ones get stuck behind it. Each CPU picking a cgroup charges it a full slice, making wrap occur earlier than a naive estimate might suggest.
Use time_before() instead. cgrp_cap_budget() bounds the lag behind cvtime_now, while the lead is bounded by the slice charge plus pending cvtime_delta on re-insertion, so the cyclic ordering assumptions of time_before() hold.
--- tools/sched_ext/scx_flatcg.bpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/sched_ext/scx_flatcg.bpf.c +1 -1
@@ -144,7 +144,7 @@ static bool cgv_node_less(struct bpf_rb_node *a, const struct bpf_rb_node *b) cgc_a = container_of(a, struct cgv_node, rb_node); cgc_b = container_of(b, struct cgv_node, rb_node); -return cgc_a->cvtime < cgc_b->cvtime; +return time_before (cgc_a->cvtime, cgc_b->cvtime); }static struct fcg_cpu_ctx *find_cpu_ctx (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 197/2151 fuse: fall back to copy_splice_read() on FOPEN_DIRECT_IO
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miklos Szeredi <[email protected]>
[ Upstream commit 10bd6b32965265688fa277d166ab224de8e86eb2 ]
Yafang Shao reports:
"After upgrading the kernel from 6.1.y to 6.18.y on production servers, some containers failed to read lxcfs data. The root cause is that our lxcfs is still at the old v3.0.4, which does not include commit 25982f5 ("Set the file size to 4k") [0].
Between 6.1.y and 6.18.y, the FUSE splice_read path was converted from generic_file_splice_read() to filemap_splice_read() by commit 2cb1e08985e3 ("splice: Use filemap_splice_read() instead of generic_file_splice_read()"). Unlike generic_file_splice_read(), filemap_splice_read() strictly checks i_size and refuses to read from zero-size files, which breaks virtual FUSE filesystems like the old lxcfs."
Fix by using copy_splice_read() for the FOPEN_DIRECT_IO case, just like the VFS does for DAX and O_DIRECT files.
--- fs/fuse/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/fuse/file.c +4 -1
@@ -1828,7 +1828,10 @@ static ssize_t fuse_splice_read(struct file *in, loff_t *ppos,struct fuse_file *ff = in->private_data;/* FOPEN_DIRECT_IO overrides FOPEN_PASSTHROUGH */ -if (fuse_file_passthrough (ff) && !(ff->open_flags &FOPEN_DIRECT_IO )) + +if (ff->open_flags &FOPEN_DIRECT_IO ) +return copy_splice_read (in, ppos, pipe, len, flags); +else if (fuse_file_passthrough (ff))return fuse_passthrough_splice_read (in, ppos, pipe, len, flags);else return filemap_splice_read (in, ppos, pipe, len, flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 198/2151 sched/core: Dont steal a proxy-exec donor
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasily Gorbik <[email protected]>
[ Upstream commit 3dd95f077371f5def65a91c4bb13bd574a62bc3a ]
try_steal_cookie() avoids stealing src->core_pick and src->curr before moving a task with the same cookie via move_queued_task_locked().
With proxy-exec, src->donor is the current scheduling context and may differ from src->curr. Stealing it migrates a task that the source rq still treats as current, leaving src's scheduler state for that task stale. For CFS this means cfs_rq->curr points at the stolen entity, and the next pick on the source rq hits the WARN_ON_ONCE in put_prev_entity().
Commit 7de9d4f94638 ("sched: Start blocked_on chain processing in find_proxy_task()") tweaked the fair class logic so that the donor task isn't migrated away while we're running the proxy. Do it similarly for try_steal_cookie() and skip src->donor as well.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -6292,7 +6292,7 @@ static bool try_steal_cookie(int this, int that)return false; do { - if (p == src->core_pick || p == src->curr) + if (p == src->core_pick || p == src->curr || p == src->donor) goto next; if (!is_cpu_allowed(p, this))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 199/2151 dlm: validate lock modes in recovery messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danila Chernetsov <[email protected]>
[ Upstream commit 7bf1aca6d626944091a5cb218b4e487547edff0a ]
The DLM recovery path restores lock state from rcom_lock messages received from remote nodes. The lock modes in these messages are copied directly into the local lkb state without validating that they are within the valid DLM lock mode range.
The rest of the DLM code assumes that lkb_rqmode and lkb_grmode contain valid lock modes. In particular, LVB callback handling in dlm_may_skip_callback() uses lock modes as indexes into the dlm_lvb_operations array:
dlm_lvb_operations[prev_mode + 1][mode + 1]
An invalid lock mode received during recovery could therefore result in an out-of-bounds read during subsequent LVB callback processing.
Validate rl_rqmode and rl_grmode before storing them into the local LKB state. This preserves the lock mode invariant required by the rest of the DLM code.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- fs/dlm/lock.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/dlm/lock.c +4 -0
@@ -5529,6 +5529,10 @@ static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, {struct rcom_lock *rl = (struct rcom_lock *) rc->rc_buf; +if (rl->rl_rqmode <DLM_LOCK_IV || rl->rl_rqmode >DLM_LOCK_EX || + rl->rl_grmode <DLM_LOCK_IV || rl->rl_grmode >DLM_LOCK_EX ) +return -EINVAL ; + lkb->lkb_nodeid =le32_to_cpu (rc->rc_header.h_nodeid); lkb->lkb_ownpid =le32_to_cpu (rl->rl_ownpid); lkb->lkb_remid =le32_to_cpu (rl->rl_lkid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 200/2151 dlm: fix NULL pointer dereference in dlm_dump_rsb_name()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danila Chernetsov <[email protected]>
[ Upstream commit 19982c99a302ab544c69f95d37ca3070c89762d3 ]
The function dlm_dump_rsb_name() is called from receive_rcom_lookup() when a debug dump is requested via a special RCOM_LOOKUP message with rc_id == 0xFFFFFFFF.
The resource name passed to dlm_dump_rsb_name() comes from the received message. There is no guarantee that an RSB with this name exists in the local hash table.
dlm_search_rsb_tree() returns 0 when the RSB is found and stores a valid pointer in r. When the lookup fails, it returns -EBADR and leaves r NULL.
The current error handling is inverted:
if (!error)
goto out;As a result, dlm_dump_rsb() is called only when the lookup fails and r is NULL, resulting in a NULL pointer dereference.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- fs/dlm/lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/lock.c +1 -1
@@ -1421,7 +1421,7 @@ void dlm_dump_rsb_name(struct dlm_ls *ls, const char *name, int len)rcu_read_lock (); error =dlm_search_rsb_tree (&ls->ls_rsbtbl, name, len, &r); -if (!error) +if (error) goto out;dlm_dump_rsb (r);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 201/2151 dlm: fix buffer overflow from negative len in dlm_search_rsb_tree
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit d785f7d92f197b72d496bbcf54a160cd54f00263 ]
commit 080e5563f878c ("dlm: validate length in dlm_search_rsb_tree") only checks for len > DLM_RESNAME_MAXLEN, which does not catch negative values. While the input 'len' can be negative and a negative int passed to memcpy() is implicitly converted to a large size_t, causing a stack buffer overflow on the key[] array.
Fix this by changing the 'len' parameter type from int to unsigned int. This ensures negative values from callers are implicitly converted to large unsigned values that are caught by the existing
len > DLM_RESNAME_MAXLEN check.
Stable-dep-of: b4e6ae7ba711 ("dlm: fix variable key length lookup")
--- fs/dlm/lock.c | 6 ++++-- fs/dlm/lock.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-)
fs/dlm/lock.c +4 -2
@@ -622,12 +622,14 @@ static int get_rsb_struct(struct dlm_ls *ls, const void *name, int len,return 0 ; } -int dlm_search_rsb_tree (struct rhashtable *rhash,const void *name,int len, -struct dlm_rsb **r_ret) +int dlm_search_rsb_tree (struct rhashtable *rhash,const void *name, +unsigned int len,struct dlm_rsb **r_ret) {char key[DLM_RESNAME_MAXLEN ] = {}; +if (len >DLM_RESNAME_MAXLEN )return -EINVAL ; +memcpy (key, name, len); *r_ret =rhashtable_lookup_fast (rhash, &key, dlm_rhash_rsb_params);if (*r_ret)
fs/dlm/lock.h +2 -2
@@ -31,8 +31,8 @@ void resume_scan_timer(struct dlm_ls *ls);int dlm_master_lookup (struct dlm_ls *ls,int from_nodeid,const char *name,int len,unsigned int flags,int *r_nodeid,int *result); -int dlm_search_rsb_tree (struct rhashtable *rhash,const void *name,int len, -struct dlm_rsb **r_ret); +int dlm_search_rsb_tree (struct rhashtable *rhash,const void *name, +unsigned int len,struct dlm_rsb **r_ret);void dlm_recover_purge (struct dlm_ls *ls,const struct list_head *root_list);void dlm_purge_mstcpy_locks (struct dlm_rsb *r);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 202/2151 dlm: fix variable key length lookup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Aring <[email protected]>
[ Upstream commit b4e6ae7ba711758c38d5eb7d5a7a0712273bdf6f ]
Before commit 6c648035cbe7 ("dlm: switch to use rhashtable for rsbs") the rsb hashtable was dynamic key length. Accidentally it was changed to switch to static key length which can end in different results. We fixing this back to the original behaviour by adding the necessary functionality to rhashtable to handle the objects and lookups as dynamic key lengths.
--- fs/dlm/config.c | 30 ++++++++++++++++++++++++++++-- fs/dlm/dlm_internal.h | 5 +++++ fs/dlm/lock.c | 6 ++++-- 3 files changed, 37 insertions(+), 4 deletions(-)
fs/dlm/config.c +28 -2
@@ -64,11 +64,37 @@ static void release_node(struct config_item *);static struct configfs_attribute *comm_attrs[];static struct configfs_attribute *node_attrs[]; +static u32 rsb_hashfn (const void *data,u32 len,u32 seed) +{ +const struct dlm_rsb_key *key = data; + +return jhash (key->name, key->len,0 ); +} + +static u32 rsb_obj_hashfn (const void *data,u32 len,u32 seed) +{ +const struct dlm_rsb *r = data; + +return r->res_hash; +} + +static int rsb_obj_cmpfn (struct rhashtable_compare_arg *arg,const void *obj) +{ +const struct dlm_rsb_key *key = arg->key; +const struct dlm_rsb *r = obj; + +if (key->len != r->res_length) +return -1 ; + +return memcmp (&r->res_name, key->name, key->len); +} +const struct rhashtable_params dlm_rhash_rsb_params = { .nelem_hint =3 ,/* start small */ - .key_len =DLM_RESNAME_MAXLEN , - .key_offset = offsetof(struct dlm_rsb , res_name), .head_offset = offsetof(struct dlm_rsb , res_node), + .hashfn = rsb_hashfn, + .obj_hashfn = rsb_obj_hashfn, + .obj_cmpfn = rsb_obj_cmpfn, .automatic_shrinking = true, };
fs/dlm/dlm_internal.h +5 -0
@@ -340,6 +340,11 @@ struct dlm_rsb {char res_name[DLM_RESNAME_MAXLEN +1 ]; }; +struct dlm_rsb_key { +char name[DLM_RESNAME_MAXLEN ]; +size_t len; +}; +/* dlm_master_lookup() flags */ #define DLM_LU_RECOVER_DIR 1
fs/dlm/lock.c +4 -2
@@ -625,12 +625,14 @@ static int get_rsb_struct(struct dlm_ls *ls, const void *name, int len,int dlm_search_rsb_tree (struct rhashtable *rhash,const void *name,unsigned int len,struct dlm_rsb **r_ret) { -char key[DLM_RESNAME_MAXLEN ] = {}; +struct dlm_rsb_key key = { + .len = len, + };if (len >DLM_RESNAME_MAXLEN )return -EINVAL ; -memcpy (key, name, len); +memcpy (key.name, name, len); *r_ret =rhashtable_lookup_fast (rhash, &key, dlm_rhash_rsb_params);if (*r_ret)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 203/2151 remoteproc: imx_dsp_rproc: Drop extra space
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peng Fan <[email protected]>
[ Upstream commit 8049dc7b631e33a42d8413fe48b043113afa914c ]
Drop extra space between return and zero.
Stable-dep-of: 13df1fa4f1a3 ("remoteproc: imx_dsp: Acquire runtime PM before adding carveouts")
--- drivers/remoteproc/imx_dsp_rproc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_dsp_rproc.c +2 -2
@@ -784,7 +784,7 @@ static int imx_dsp_rproc_prepare(struct rproc *rproc)pm_runtime_get_sync (dev); -return 0 ; +return 0 ; }/* Unprepare function for rproc_ops */
@@ -792,7 +792,7 @@ static int imx_dsp_rproc_unprepare(struct rproc *rproc) {pm_runtime_put_sync (rproc->dev.parent); -return 0 ; +return 0 ; }/* Kick function for rproc_ops */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 204/2151 remoteproc: imx_dsp: Acquire runtime PM before adding carveouts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 13df1fa4f1a30571442eda64c73d6cac7b9b5c95 ]
The prepare callback publishes DSP carveouts before acquiring the runtime-PM reference that establishes required clocks and mailbox state. A PM failure therefore leaves the prepare transaction partially published.
Acquire runtime PM first and drop that reference if carveout construction fails, so a failed prepare does not add resources before its hardware prerequisite.
--- drivers/remoteproc/imx_dsp_rproc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_dsp_rproc.c +5 -2
@@ -776,14 +776,17 @@ static int imx_dsp_rproc_prepare(struct rproc *rproc)struct device *dev = rproc->dev.parent;int ret; + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) +return ret; + ret =imx_dsp_rproc_add_carveout (priv);if (ret) {dev_err (dev,"failed on imx_dsp_rproc_add_carveout\n" ); +pm_runtime_put_sync (dev);return ret; } -pm_runtime_get_sync (dev); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 205/2151 arm64: dts: imx95: Avoid 32-bit PCIe window System RAM overlap
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Richard Zhu <[email protected]>
[ Upstream commit 9094eb07b3e236233dbaac61ed30cc65be9e9c6c ]
Move the PCIe non-prefetchable memory PCI bus address from 0xe0000000 to 0x10000000 to avoid overlap with DRAM. Avoid hit this as a P2P transfer[1]. The 0x10000000 range is reserved and safe to use.
--- arch/arm64/boot/dts/freescale/imx95.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/imx95.dtsi +2 -2
@@ -1824,7 +1824,7 @@ pcie0: pcie@4c300000 { <0 0x4c340000 0 0x4000>; reg-names = "dbi", "config", "atu", "app"; ranges = <0x43000000 0x9 0x00000000 0x9 0x00000000 0x0 0xe0000000>, - <0x82000000 0x0 0xe0000000 0x9 0xe0000000 0x0 0x10000000>, + <0x82000000 0x0 0x10000000 0x9 0xe0000000 0x0 0x10000000>, <0x81000000 0x0 0x00000000 0x9 0xf0000000 0x0 0x00100000>; #address-cells = <3>; #size-cells = <2>;
@@ -1900,7 +1900,7 @@ pcie1: pcie@4c380000 { <0 0x4c3c0000 0 0x4000>; reg-names = "dbi", "config", "atu", "app"; ranges = <0x43000000 0xa 0x00000000 0xa 0x00000000 0x0 0xe0000000>, - <0x82000000 0x0 0xe0000000 0xa 0xe0000000 0x0 0x10000000>, + <0x82000000 0x0 0x10000000 0xa 0xe0000000 0x0 0x10000000>, <0x81000000 0x0 0x00000000 0xa 0xf0000000 0x0 0x00100000>; #address-cells = <3>; #size-cells = <2>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 206/2151 x86/crash: Reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ionut Nechita <[email protected]>
[ Upstream commit 6664ad1026b558563702f9a1ce637df33e7c001e ]
NR_CPUS_DEFAULT is purely a Kconfig thing. Its entire purpose in life is to start NR_CPUS at a sane value. There is precisely one (buggy) reference to it outside of Kconfig in the whole kernel: the x86 crash code.
That code undersizes the elfcorehdr reservation whenever NR_CPUS exceeds NR_CPUS_DEFAULT, because the header carries one phdr per possible CPU and num_possible_cpus() is bounded by NR_CPUS. kexec_file_load(2) then fails with -EINVAL from sanity_check_segment_list(), and kexec_load(2) silently truncates the elfcorehdr, which surfaces later as a bad or unusable dump.
Size the elfcorehdr reservation with NR_CPUS instead.
--- arch/x86/kernel/crash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +3 -3
@@ -432,9 +432,9 @@ int crash_load_segments(struct kimage *image)* maximum CPUs and maximum memory ranges. */ if (IS_ENABLED (CONFIG_MEMORY_HOTPLUG )) - pnum =2 +CONFIG_NR_CPUS_DEFAULT +CONFIG_CRASH_MAX_MEMORY_RANGES ; + pnum =2 +CONFIG_NR_CPUS +CONFIG_CRASH_MAX_MEMORY_RANGES ;else - pnum +=2 +CONFIG_NR_CPUS_DEFAULT ; + pnum +=2 +CONFIG_NR_CPUS ;if (pnum < (unsigned long )PN_XNUM ) { kbuf.memsz = pnum *sizeof (Elf64_Phdr);
@@ -493,7 +493,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)unsigned int sz;/* kernel_map, VMCOREINFO and maximum CPUs */ - sz =2 +CONFIG_NR_CPUS_DEFAULT ; + sz =2 +CONFIG_NR_CPUS ;if (IS_ENABLED (CONFIG_MEMORY_HOTPLUG )) sz +=CONFIG_CRASH_MAX_MEMORY_RANGES ; sz *=sizeof (Elf64_Phdr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 207/2151 bpftool: Set BPF_F_XDP_DEV_BOUND_ONLY flag non-destructively
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Toke Høiland-Jørgensen <[email protected]>
[ Upstream commit 06d6f845c4bda857a6ae864690f35321b878e827 ]
When setting the XDP hints ifname, bpftool would set the BPF_F_XDP_DEV_BOUND_ONLY without looking at the existing program flags, overriding any other flag values. This was always a destructive action, but after we change libbpf to carry the frags section flag in prog_flags, this can impact bpftool loading of XDP frags programs.
Change the flag setting to be non-destructive by OR'ing it with the existing flags.
--- tools/bpf/bpftool/prog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/prog.c +1 -1
@@ -1769,7 +1769,7 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) }if (prog_type ==BPF_PROG_TYPE_XDP && xdpmeta_ifindex) { -bpf_program__set_flags (pos,BPF_F_XDP_DEV_BOUND_ONLY ); +bpf_program__set_flags (pos,bpf_program__flags (pos) |BPF_F_XDP_DEV_BOUND_ONLY );bpf_program__set_ifindex (pos, xdpmeta_ifindex); }else {bpf_program__set_ifindex (pos, offload_ifindex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 208/2151 PCI: endpoint: pci-epf-vntb: Pass PF/VF number when BAR programming
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit afe2aa9dc93d904730bab63f5ccb514a318e6464 ]
vntb_epf_mw_set_trans() programs the memory-window BAR through pci_epc_set_bar() with hardcoded function numbers (0, 0), so the BAR lands on the wrong function whenever the vNTB EPF is bound to anything but PF0. The other BAR programming sites in the vNTB driver already pass the EPF's own numbers.
Pass the EPF's own func_no/vfunc_no here as well.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +2 -1
@@ -1156,7 +1156,8 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx, epf_bar->barno = barno; epf_bar->size = size; - ret =pci_epc_set_bar (ntb->epf->epc,0 ,0 , epf_bar); + ret =pci_epc_set_bar (ntb->epf->epc, ntb->epf->func_no, + ntb->epf->vfunc_no, epf_bar);if (ret) {dev_err (dev,"failure set mw trans\n" );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 209/2151 dmaengine: fsl_raid: dont invoke client callback under desc_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 62c267ce97444f8a381f2bb3cd5d534eb362c540 ]
fsl_re_dequeue() holds re_chan->desc_lock while calling fsl_re_desc_done(), which synchronously invokes the DMA client completion callback via dmaengine_desc_get_callback_invoke(). If that callback submits new work (e.g. fsl_re_tx_submit()), it tries to reacquire the same desc_lock and deadlocks on the spinlock.
Collect completed descriptors into a local list under the lock, then release the lock and invoke the callbacks before moving the descriptors to the ack queue.
--- drivers/dma/fsl_raid.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/dma/fsl_raid.c +13 -2
@@ -162,6 +162,7 @@ static void fsl_re_dequeue(struct tasklet_struct *t)struct fsl_re_hw_desc *hwdesc;unsigned long flags;unsigned int count, oub_count; +LIST_HEAD (completed);int found;fsl_re_cleanup_descs (re_chan);
@@ -182,8 +183,7 @@ static void fsl_re_dequeue(struct tasklet_struct *t) }if (found) { -fsl_re_desc_done (desc); -list_move_tail (&desc->node, &re_chan->ack_q); +list_move_tail (&desc->node, &completed); }else {dev_err (re_chan->dev,"found hwdesc not in sw queue, discard it\n" );
@@ -196,6 +196,17 @@ static void fsl_re_dequeue(struct tasklet_struct *t) FSL_RE_RMVD_JOB(1)); }spin_unlock_irqrestore (&re_chan->desc_lock, flags); + +/* Invoke the client callbacks outside the channel lock. The callback +* may submit new work which re-acquires desc_lock, so holding it here +* would deadlock. +*/ +list_for_each_entry_safe (desc, _desc, &completed, node) { +fsl_re_desc_done (desc); +spin_lock_irqsave (&re_chan->desc_lock, flags); +list_move_tail (&desc->node, &re_chan->ack_q); +spin_unlock_irqrestore (&re_chan->desc_lock, flags); + } }/* Per Job Ring interrupt handler */
Signature · 1 line
2.53.0