6.18.40-rc1 review
Subsystems (13)
Greg Kroah-Hartman
maintainerPATCH 669/1611 xprtrdma: Decouple req recycling from RPC completion
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit e786233d2e0bbff9a82e43f02ae3a46ab4b08ec3 ]
rl_kref formerly served two distinct lifetimes through a single
refcount: it gated when a Reply could wake its RPC task, and it gated when an rpcrdma_req could return to its free pool. The marshal path took the Send-side reference only when SGEs needed DMA-unmap (sc_unmap_count > 0), which made a Send carrying only pre-registered buffers an exception: the Reply handler dropped rl_kref from 1 to 0 and freed the req while the HCA might still be DMA-reading from its send buffer.
Give rl_kref a narrower job. The RPC layer takes one reference when slot allocation hands a req out. rpcrdma_prepare_send_sges() takes a Send-side reference unconditionally after WR preparation succeeds. xprt_rdma_free_slot() and xprt_rdma_bc_free_rqst() drop the RPC-layer reference; rpcrdma_sendctx_unmap() drops the Send-side reference. The req returns to its free pool only after both owners have signed off.
The existing kref_init(&req->rl_kref) call in rpcrdma_prepare_send_sges() is removed. Initialization moves to the slot-allocation paths (xprt_rdma_alloc_slot and rpcrdma_bc_rqst_get), and the release callback re-arms rl_kref before the req returns to a free pool. A re-init in the marshal path would discard the RPC-layer reference that already exists on entry.
Three invariants follow:
- Any rpcrdma_req held by an rpc_rqst has rl_kref >= 1. xprt_rdma_alloc_slot(), rpcrdma_bc_rqst_get(), and the backlog-wake branch in xprt_rdma_alloc_slot() each kref_init rl_kref before publishing the req. Without this invariant, an RPC task that aborts between slot allocation and marshal (gss_refresh failure or signal during call_connect, for example) would drive xprt_release() -> xprt_rdma_free_slot() -> kref_put against a refcount of zero, saturating refcount_t and stranding the slot.
- The Send-side reference is taken only after WR prep succeeds. A mapping failure in rpcrdma_prepare_send_sges() runs rpcrdma_sendctx_cancel(), which DMA-unmaps the sendctx and clears sc_req without touching rl_kref. The sendctx ring walks in rpcrdma_sendctx_put_locked() and rpcrdma_sendctxs_destroy() skip entries with sc_req == NULL, so a burst of -EIO marshal failures cannot hold reqs off rb_send_bufs.
- The release callback re-arms rl_kref so the next consumer enters with the invariant satisfied.
Replies now complete the RPC directly. rpcrdma_reply_handler() calls rpcrdma_complete_rqst() in place of kref_put on the non-LocalInv branch. The LocalInv branch already completes the RPC from frwr_unmap_async() and is unaffected.
Because Send-side references can now outlive RPC completion, connection teardown drains sendctx entries whose unsignaled Sends never had a later signaled completion to walk the ring. rpcrdma_sendctxs_destroy() walks the active range and runs rpcrdma_sendctx_unmap() on each entry with a non-NULL sc_req before the request buffers are reset, and is moved ahead of rpcrdma_reqs_reset() in rpcrdma_xprt_disconnect() so the reqs are still in their pre-reset state when the Send-side refs are released.
The drain creates a teardown-ordering hazard on the backchannel path. With the new lifetime, releasing a bc_prealloc req from rpcrdma_req_release() re-adds it to bc_pa_list. The disconnect in xprt_rdma_destroy() runs after xprt_destroy_backchannel() has already emptied bc_pa_list, so the drained reqs would otherwise leak. xprt_rdma_destroy() now runs xprt_rdma_bc_destroy(xprt, 0) a second time after the disconnect to reclaim them.
--- net/sunrpc/xprtrdma/backchannel.c | 5 ++- net/sunrpc/xprtrdma/rpc_rdma.c | 47 +++++++++++--------------- net/sunrpc/xprtrdma/transport.c | 55 ++++++++++++++++++++++++++++--- net/sunrpc/xprtrdma/verbs.c | 29 +++++++++++++--- net/sunrpc/xprtrdma/xprt_rdma.h | 2 +- 5 files changed, 97 insertions(+), 41 deletions(-)
net/sunrpc/xprtrdma/backchannel.c +2 -3
@@ -158,9 +158,7 @@ void xprt_rdma_bc_free_rqst(struct rpc_rqst *rqst)rpcrdma_rep_put (&r_xprt->rx_buf, rep); req->rl_reply =NULL ; -spin_lock (&xprt->bc_pa_lock); -list_add_tail (&rqst->rq_bc_pa_list, &xprt->bc_pa_list); -spin_unlock (&xprt->bc_pa_lock); +rpcrdma_req_put (req);xprt_put (xprt); }
@@ -202,6 +200,7 @@ static struct rpc_rqst *rpcrdma_bc_rqst_get(struct rpcrdma_xprt *r_xprt) rqst->rq_xprt = xprt;__set_bit (RPC_BC_PA_IN_USE , &rqst->rq_bc_pa_state);xdr_buf_init (&rqst->rq_snd_buf,rdmab_data (req->rl_sendbuf), size); +kref_init (&req->rl_kref);return rqst; }
net/sunrpc/xprtrdma/rpc_rdma.c +19 -28
105 lines not on this page · raw message
net/sunrpc/xprtrdma/transport.c +50 -5
91 lines not on this page · raw message
net/sunrpc/xprtrdma/verbs.c +25 -4
@@ -65,6 +65,8 @@static int rpcrdma_sendctxs_create (struct rpcrdma_xprt *r_xprt);static void rpcrdma_sendctxs_destroy (struct rpcrdma_xprt *r_xprt); +static unsigned long rpcrdma_sendctx_next (struct rpcrdma_buffer *buf, +unsigned long item);static void rpcrdma_sendctx_put_locked (struct rpcrdma_xprt *r_xprt,struct rpcrdma_sendctx *sc);static int rpcrdma_reqs_setup (struct rpcrdma_xprt *r_xprt);
@@ -571,9 +573,9 @@ void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt)rpcrdma_xprt_drain (r_xprt);rpcrdma_reps_unmap (r_xprt); +rpcrdma_sendctxs_destroy (r_xprt);rpcrdma_reqs_reset (r_xprt);rpcrdma_mrs_destroy (r_xprt); -rpcrdma_sendctxs_destroy (r_xprt);if (rpcrdma_ep_put (ep))rdma_destroy_id (id);
@@ -605,6 +607,20 @@ static void rpcrdma_sendctxs_destroy(struct rpcrdma_xprt *r_xprt)if (!buf->rb_sc_ctxs)return ; + +/* The QP is drained, but the final unsignaled Sends might not +* have been walked by a signaled Send completion. Release those +* Send owners before request buffers are reset. +*/ +for (i =rpcrdma_sendctx_next (buf, buf->rb_sc_tail); + i !=rpcrdma_sendctx_next (buf, buf->rb_sc_head); + i =rpcrdma_sendctx_next (buf, i)) { +struct rpcrdma_sendctx *sc = buf->rb_sc_ctxs[i]; + +if (sc && sc->sc_req) +rpcrdma_sendctx_unmap (sc); + } +for (i =0 ; i <= buf->rb_sc_last; i++)kfree (buf->rb_sc_ctxs[i]);kfree (buf->rb_sc_ctxs);
@@ -727,15 +743,20 @@ static void rpcrdma_sendctx_put_locked(struct rpcrdma_xprt *r_xprt,struct rpcrdma_buffer *buf = &r_xprt->rx_buf;unsigned long next_tail; -/* Unmap SGEs of previously completed but unsignaled -* Sends by walking up the queue until @sc is found. +/* Release previously completed but unsignaled Sends by walking +* up the queue until @sc is found. Entries left behind by a +* failed rpcrdma_prepare_send_sges() have sc_req cleared. */ next_tail = buf->rb_sc_tail;do { +struct rpcrdma_sendctx *cur; + next_tail =rpcrdma_sendctx_next (buf, next_tail);/* ORDER: item must be accessed _before_ tail is updated */ -rpcrdma_sendctx_unmap (buf->rb_sc_ctxs[next_tail]); + cur = buf->rb_sc_ctxs[next_tail]; +if (cur->sc_req) +rpcrdma_sendctx_unmap (cur); }while (buf->rb_sc_ctxs[next_tail] != sc);
net/sunrpc/xprtrdma/xprt_rdma.h +1 -1
@@ -410,7 +410,6 @@ struct rpcrdma_stats {/* accessed when receiving a reply */ unsigned long long total_rdma_reply;unsigned long long fixup_copy_count; -unsigned long reply_waits_for_send;unsigned long local_inv_needed;unsigned long nomsg_call_count;unsigned long bcall_count;
@@ -488,6 +487,7 @@ void rpcrdma_buffer_put(struct rpcrdma_buffer *buffers, struct rpcrdma_req *req);void rpcrdma_rep_put (struct rpcrdma_buffer *buf,struct rpcrdma_rep *rep);void rpcrdma_reply_put (struct rpcrdma_buffer *buffers,struct rpcrdma_req *req); +void rpcrdma_req_put (struct rpcrdma_req *req);bool rpcrdma_regbuf_realloc (struct rpcrdma_regbuf *rb,size_t size,gfp_t flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 670/1611 NFSv4/pnfs: defer return_range callbacks until after inode unlock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 77b160b2d863d37f36b6c38e80a7d259ce939e69 ]
Sometimes unmounting an NFS filesystem mounted with pNFS SCSI layouts triggers the following warning:
BUG: scheduling while atomic: umount.nfs4/...
__schedule_bug+0xbd/0x100
schedule_debug.constprop.0+0x19f/0x220
__schedule+0x10d/0x10a0
schedule+0x74/0x190
schedule_timeout+0xf5/0x220
io_schedule_timeout+0xd5/0x160
__wait_for_common+0x186/0x4b0
blk_execute_rq+0x2ef/0x3a0
scsi_execute_cmd+0x1ff/0x700
sd_pr_out_command.isra.0+0x242/0x380 [sd_mod]
bl_unregister_scsi.constprop.0+0x109/0x3c0 [blocklayoutdriver]
bl_unregister_dev+0x175/0x1c0 [blocklayoutdriver]
bl_free_device+0x1f/0x1b0 [blocklayoutdriver]
bl_free_deviceid_node+0x12/0x30 [blocklayoutdriver]
nfs4_put_deviceid_node+0x171/0x360 [nfsv4]
ext_tree_remove+0x11c/0x1d0 [blocklayoutdriver]
_pnfs_return_layout+0x416/0x900 [nfsv4]
nfs4_evict_inode+0x108/0x130 [nfsv4]
evict+0x316/0x750
dispose_list+0xf1/0x1a0
evict_inodes+0x33f/0x440
generic_shutdown_super+0xc9/0x4e0
kill_anon_super+0x3a/0x90
nfs_kill_super+0x44/0x60 [nfs]
deactivate_locked_super+0xb8/0x1b0
cleanup_mnt+0x25a/0x380
task_work_run+0x13e/0x210
exit_to_user_mode_loop+0x169/0x400
do_syscall_64+0x467/0x1550
entry_SYSCALL_64_after_hwframe+0x76/0x7eThe warning occurs because the block layout driver unregisters the SCSI device while the inode lock is still held. Device unregistration issues a SCSI PR command, which may sleep, resulting in a "scheduling while atomic" warning.
During layout return, ext_tree_remove() invokes the layout driver's return_range callback while holding the inode lock. For block layouts, this callback eventually calls bl_unregister_scsi(), which may block in scsi_execute_cmd() while issuing PR commands to the device.
Fix this by deferring the return_range callbacks until after the inode lock has been released. The layout header reference count is incremented before invoking return_range(), ensuring that the layout header remains valid while the layout driver removes extents from the extent tree.
--- fs/nfs/callback_proc.c | 9 +++++---- fs/nfs/pnfs.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-)
fs/nfs/callback_proc.c +5 -4
@@ -254,6 +254,7 @@ static u32 initiate_file_draining(struct nfs_client *clp,struct pnfs_layout_hdr *lo;u32 rv =NFS4ERR_NOMATCHING_LAYOUT ;LIST_HEAD (free_me_list); +bool return_range = false; ino =nfs_layout_find_inode (clp, &args->cbl_fh, &args->cbl_stateid);if (IS_ERR (ino)) {
@@ -298,13 +299,13 @@ static u32 initiate_file_draining(struct nfs_client *clp,/* Embrace your forgetfulness! */ rv =NFS4ERR_NOMATCHING_LAYOUT ; -if (NFS_SERVER (ino)->pnfs_curr_ld->return_range) { -NFS_SERVER (ino)->pnfs_curr_ld->return_range (lo, - &args->cbl_range); - } + return_range = true; } unlock:spin_unlock (&ino->i_lock); +if (return_range &&NFS_SERVER (ino)->pnfs_curr_ld->return_range) +NFS_SERVER (ino)->pnfs_curr_ld->return_range (lo, + &args->cbl_range);pnfs_free_lseg_list (&free_me_list);/* Free all lsegs that are attached to commit buckets */ nfs_commit_inode (ino,0 );
fs/nfs/pnfs.c +2 -2
@@ -1463,8 +1463,6 @@ _pnfs_return_layout(struct inode *ino)pnfs_clear_layoutcommit (ino, &tmp_list);pnfs_mark_matching_lsegs_return (lo, &tmp_list, &range,0 ); -if (NFS_SERVER (ino)->pnfs_curr_ld->return_range) -NFS_SERVER (ino)->pnfs_curr_ld->return_range (lo, &range);/* Don't send a LAYOUTRETURN if list was initially empty */ if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags) ||
@@ -1476,6 +1474,8 @@ _pnfs_return_layout(struct inode *ino) send =pnfs_prepare_layoutreturn (lo, &stateid, &cred,NULL );spin_unlock (&ino->i_lock); +if (NFS_SERVER (ino)->pnfs_curr_ld->return_range) +NFS_SERVER (ino)->pnfs_curr_ld->return_range (lo, &range);if (send) status =pnfs_send_layoutreturn (lo, &stateid, &cred,IOMODE_ANY ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 671/1611 nfs: keep PG_UPTODATE clear after read errors in page groups
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Clark Wang <[email protected]>
[ Upstream commit 3ff72e1cdf5c337b6acfcf3fcef748c5b9a5316b ]
When a read request is split into multiple subrequests, earlier completions may advance PG_UPTODATE state for the page group once their bytes fall within hdr->good_bytes. If a later subrequest in the same group then completes with NFS_IOHDR_ERROR, the read path needs to clear any accumulated PG_UPTODATE state and keep later completions from rebuilding it.
Otherwise, a subsequent successful subrequest can re-enter nfs_page_group_set_uptodate(), restore the page-group sync state, and leave stale PG_UPTODATE behind for nfs_page_group_destroy() to trip over in nfs_free_request().
Add a sticky page-group read-failed flag. Once any subrequest in the group is known to be bad, mark the group failed, clear any accumulated PG_UPTODATE state, and refuse further PG_UPTODATE synchronization for the rest of the completion walk.
--- fs/nfs/read.c | 25 ++++++++++++++++++++++++- include/linux/nfs_page.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-)
fs/nfs/read.c +24 -1
@@ -132,10 +132,32 @@ static void nfs_readpage_release(struct nfs_page *req, int error)static void nfs_page_group_set_uptodate (struct nfs_page *req) { -if (nfs_page_group_sync_on_bit (req,PG_UPTODATE )) +bool uptodate = false; + +nfs_page_group_lock (req); +if (!test_bit (PG_READ_FAILED , &req->wb_head->wb_flags) && +nfs_page_group_sync_on_bit_locked (req,PG_UPTODATE )) + uptodate = true; +nfs_page_group_unlock (req); + +if (uptodate)folio_mark_uptodate (nfs_page_to_folio (req)); } +static void nfs_page_group_mark_read_failed (struct nfs_page *req) +{ +struct nfs_page *tmp; + +nfs_page_group_lock (req); +set_bit (PG_READ_FAILED , &req->wb_head->wb_flags); + tmp = req; +do { +clear_bit (PG_UPTODATE , &tmp->wb_flags); + tmp = tmp->wb_this_page; + }while (tmp != req); +nfs_page_group_unlock (req); +} +static void nfs_read_completion (struct nfs_pgio_header *hdr) {unsigned long bytes =0 ;
@@ -172,6 +194,7 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)if (bytes <= hdr->good_bytes)nfs_page_group_set_uptodate (req);else { +nfs_page_group_mark_read_failed (req); error = hdr->error;xchg (&nfs_req_openctx (req)->error, error); }
include/linux/nfs_page.h +1 -0
@@ -33,6 +33,7 @@ enum {PG_TEARDOWN ,/* page group sync for destroy */ PG_UNLOCKPAGE ,/* page group sync bit in read path */ PG_UPTODATE ,/* page group sync bit in read path */ +PG_READ_FAILED ,/* page group saw a read error */ PG_WB_END ,/* page group sync bit in write path */ PG_REMOVE ,/* page group sync bit in write path */ PG_CONTENDED1, /* Is someone waiting for a lock? */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 672/1611 NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS on fatal DS connect errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit 7a375cafc14ed151508f908ea5681caf0a9cc1d6 ]
Commit f06bedfa62d5 ("pNFS/flexfiles: don't attempt pnfs on fatal DS errors") teaches ff_layout_{read,write}_pagelist() to return PNFS_NOT_ATTEMPTED when nfs4_ff_layout_prepare_ds() fails with a nfs_error_is_fatal() errno (e.g. -ETIMEDOUT from a SOFTCONN connect deadline, -ENOMEM, -ERESTARTSYS), so that the client gives up instead of spinning. pnfs_do_{read,write}() then dispatches the I/O through pnfs_{read,write}_through_mds() → nfs_pageio_reset_{read,write}_mds().
That fallback is unconditional and silently violates FF_FLAGS_NO_IO_THRU_MDS:
when the layout segment carries the flag (typically single-mirror appliance layouts where MDS I/O is explicitly forbidden), theout_failed: path's \&& !ds_fatal_error\ clause overrides the flag's short-circuit through ff_layout_avoid_mds_available_ds() and routes the I/O to the MDS file handle anyway.
This is reachable in practice during a data-server restart: SOFTCONN exhaustion produces -ETIMEDOUT, which is fatal per nfs_error_is_fatal(), which triggers PNFS_NOT_ATTEMPTED, which silently goes to MDS.
Preserve the upstream "don't spin on fatal errors" intent for layouts that permit MDS fallback. For layouts with FF_FLAGS_NO_IO_THRU_MDS set, mark the layout for return and request PNFS_TRY_AGAIN instead; if the server cannot supply a usable layout the failure now surfaces cleanly via pnfs_update_layout(), rather than via silent MDS I/O that contradicts the flag.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/nfs/flexfilelayout/flexfilelayout.c +16 -0
@@ -2206,6 +2206,14 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr) out_failed:if (ff_layout_avoid_mds_available_ds (lseg) && !ds_fatal_error)return PNFS_TRY_AGAIN ; +if (ff_layout_no_fallback_to_mds (lseg)) { +/* +* FF_FLAGS_NO_IO_THRU_MDS: force fresh LAYOUTGET, +* never fall through to MDS I/O. +*/ +pnfs_error_mark_layout_for_return (hdr->inode, lseg); +return PNFS_TRY_AGAIN ; + }trace_pnfs_mds_fallback_read_pagelist (hdr->inode, hdr->args.offset, hdr->args.count,IOMODE_READ ,NFS_I (hdr->inode)->layout, lseg);
@@ -2291,6 +2299,14 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) out_failed:if (ff_layout_avoid_mds_available_ds (lseg) && !ds_fatal_error)return PNFS_TRY_AGAIN ; +if (ff_layout_no_fallback_to_mds (lseg)) { +/* +* FF_FLAGS_NO_IO_THRU_MDS: force fresh LAYOUTGET, +* never fall through to MDS I/O. +*/ +pnfs_error_mark_layout_for_return (hdr->inode, lseg); +return PNFS_TRY_AGAIN ; + }trace_pnfs_mds_fallback_write_pagelist (hdr->inode, hdr->args.offset, hdr->args.count,IOMODE_RW ,NFS_I (hdr->inode)->layout, lseg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 673/1611 NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS in pg_get_mirror_count_write
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit 1d62e659c0bf11649cf48e002c2a55d148f2610a ]
The FF_FLAGS_NO_IO_THRU_MDS flag lives on each lseg, so any fallback decision made when there is no current lseg (e.g. between LAYOUTRETURN and the next LAYOUTGET) cannot run the per-lseg check.
Introduce a sticky hdr-level ditto for FF_FLAGS_NO_IO_THRU_MDS in struct nfs4_flexfile_layout::flags (NFS4_FF_HDR_NO_IO_THRU_MDS bit), set whenever ff_layout_alloc_lseg() parses an lseg with the flag. The bit is never cleared for the lifetime of the layout hdr; the server is assumed to be consistent in its no-fallback policy per file. kzalloc() in ff_layout_alloc_layout_hdr() zero-initializes the field.
Use the new ff_layout_hdr_no_fallback_to_mds() helper to gate ff_layout_pg_get_mirror_count_write(): when pnfs_update_layout() returns NULL (e.g. NFS_LAYOUT_BULK_RECALL, pnfs_layout_io_test_failed, pnfs_layoutgets_blocked) the existing code unconditionally calls nfs_pageio_reset_write_mds(). This is a source of unwanted WRITE to MDS. Fix it by checking NFS4_FF_HDR_NO_IO_THRU_MDS bit, and if set surface -EAGAIN instead; the writepage-side caller (nfs_do_writepage() for buffered, nfs_direct_write_reschedule() for O_DIRECT) then redirties the request so writeback retries via pNFS.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 13 +++++++++++++ fs/nfs/flexfilelayout/flexfilelayout.h | 16 ++++++++++++++++ 2 files changed, 29 insertions(+)
fs/nfs/flexfilelayout/flexfilelayout.c +13 -0
@@ -638,6 +638,9 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,if (!p) goto out_sort_mirrors; fls->flags =be32_to_cpup (p); +if (fls->flags &FF_FLAGS_NO_IO_THRU_MDS ) +set_bit (NFS4_FF_HDR_NO_IO_THRU_MDS , + &FF_LAYOUT_FROM_HDR (lh)->flags); p =xdr_inline_decode (&stream,4 );if (!p)
@@ -1187,6 +1190,16 @@ ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,0 ,NFS4_MAX_UINT64 ,IOMODE_RW ,NFS_I (pgio->pg_inode)->layout, pgio->pg_lseg); +if (NFS_I (pgio->pg_inode)->layout && +ff_layout_hdr_no_fallback_to_mds (NFS_I (pgio->pg_inode)->layout)) { +/* +* FF_FLAGS_NO_IO_THRU_MDS: no current lseg but the server's +* policy forbids MDS fallback. Surface -EAGAIN so writeback +* retries rather than silently issuing the WRITE via MDS. +*/ + pgio->pg_error = -EAGAIN ; + goto out; + }/* no lseg means that pnfs is not in use, so no mirroring here */ nfs_pageio_reset_write_mds (pgio); out:
fs/nfs/flexfilelayout/flexfilelayout.h +16 -0
@@ -112,12 +112,16 @@ struct nfs4_ff_layout_segment { struct nfs4_ff_layout_mirror *mirror_array[] __counted_by(mirror_array_cnt); }; +/* nfs4_flexfile_layout::flags bit indices */ +#define NFS4_FF_HDR_NO_IO_THRU_MDS 0/* any lseg has had FF_FLAGS_NO_IO_THRU_MDS */ +struct nfs4_flexfile_layout {struct pnfs_layout_hdr generic_hdr;struct pnfs_ds_commit_info commit_info;struct list_head mirrors;struct list_head error_list;/* nfs4_ff_layout_ds_err */ ktime_t last_report_time;/* Layoutstat report times */ +unsigned long flags; };struct nfs4_flexfile_layoutreturn_args {
@@ -184,6 +188,18 @@ ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg)return FF_LAYOUT_LSEG (lseg)->flags &FF_FLAGS_NO_IO_THRU_MDS ; } +/* +* Sticky hdr-level mirror of FF_FLAGS_NO_IO_THRU_MDS so callers that have +* no current lseg (e.g. between LAYOUTRETURN and the next LAYOUTGET) can +* still honor the no-MDS-fallback policy. +*/ +static inline bool +ff_layout_hdr_no_fallback_to_mds (struct pnfs_layout_hdr *lo) +{ +return test_bit (NFS4_FF_HDR_NO_IO_THRU_MDS , + &FF_LAYOUT_FROM_HDR (lo)->flags); +} +static inline bool ff_layout_no_read_on_rw (struct pnfs_layout_segment *lseg) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 674/1611 nfs: use nfsi->rwsem to protect traversal of the file lock list
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Erkun <[email protected]>
[ Upstream commit 4837fb36219e6c08b666bc31a86841bad8526358 ]
Lingfeng identified a bug and suggested two solutions, but both appear to have issues.
Generally, we cannot release flc_lock while iterating over the file lock list to avoid use-after-free (UAF) problems with file locks. However, functions like nfs_delegation_claim_locks and nfs4_reclaim_locks cannot adhere to this rule because recover_lock or nfs4_lock_delegation_recall may take a long time. To resolve this, NFS switches to using nfsi->rwsem for the same protection, and nfs_reclaim_locks follows this approach. Although nfs_delegation_claim_locks uses so_delegreturn_mutex instead, this is inadequate since a single inode can have multiple nfs4_state instances. Therefore, the fix is to also use nfsi->rwsem in this case.
Furthermore, after commit c69899a17ca4 ("NFSv4: Update of VFS byte range lock must be atomic with the stateid update"), the functions nfs4_locku_done and nfs4_lock_done also break this rule because they call locks_lock_inode_wait without holding nfsi->rwsem. Simply adding this protection could cause many deadlocks, so instead, the call to locks_lock_inode_wait is moved into _nfs4_proc_setlk. Regarding the bug fixed by commit c69899a17ca4 ("NFSv4: Update of VFS byte range lock must be atomic with the stateid update"), it has been resolved after commit 0460253913e5 ("NFSv4: nfs4_do_open() is incorrectly triggering state recovery") because all slots are drained before calling nfs4_do_reclaim, which prevents concurrent stateid changes along this path. Also, nfs_delegation_claim_locks does not cause this concurrency either since when _nfs4_proc_setlk is called with NFS_DELEGATED_STATE, no RPC is sent, so nfs4_lock_done is not called. Therefore, nfs4_lock_delegation_recall from nfs_delegation_claim_locks is the first time the stateid is set.
--- fs/nfs/delegation.c | 9 ++++++++- fs/nfs/nfs4proc.c | 22 +++++++++++----------- include/linux/nfs_xdr.h | 1 - 3 files changed, 19 insertions(+), 13 deletions(-)
fs/nfs/delegation.c +8 -1
@@ -158,6 +158,7 @@ int nfs4_check_delegation(struct inode *inode, fmode_t type)static int nfs_delegation_claim_locks (struct nfs4_state *state,const nfs4_stateid *stateid) {struct inode *inode = state->inode; +struct nfs_inode *nfsi =NFS_I (inode);struct file_lock *fl;struct file_lock_context *flctx =locks_inode_context (inode);struct list_head *list;
@@ -167,6 +168,9 @@ static int nfs_delegation_claim_locks(struct nfs4_state *state, const nfs4_state goto out; list = &flctx->flc_posix; + +/* Guard against reclaim and new lock/unlock calls */ +down_write (&nfsi->rwsem);spin_lock (&flctx->flc_lock); restart:for_each_file_lock (fl, list) {
@@ -174,8 +178,10 @@ static int nfs_delegation_claim_locks(struct nfs4_state *state, const nfs4_statecontinue ;spin_unlock (&flctx->flc_lock); status =nfs4_lock_delegation_recall (fl, state, stateid); -if (status <0 ) +if (status <0 ) { +up_write (&nfsi->rwsem); goto out; + }spin_lock (&flctx->flc_lock); }if (list == &flctx->flc_posix) {
@@ -183,6 +189,7 @@ static int nfs_delegation_claim_locks(struct nfs4_state *state, const nfs4_state goto restart; }spin_unlock (&flctx->flc_lock); +up_write (&nfsi->rwsem); out:return status; }
fs/nfs/nfs4proc.c +11 -11
@@ -7178,7 +7178,6 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)switch (task->tk_status) {case 0 :renew_lease (calldata->server, calldata->timestamp); -locks_lock_inode_wait (calldata->lsp->ls_state->inode, &calldata->fl);if (nfs4_update_lock_stateid (calldata->lsp, &calldata->res.stateid))break ;
@@ -7445,11 +7444,6 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)case 0 :renew_lease (NFS_SERVER (d_inode (data->ctx->dentry)), data->timestamp); -if (data->arg.new_lock && !data->cancelled) { - data->fl.c.flc_flags &= ~(FL_SLEEP |FL_ACCESS ); -if (locks_lock_inode_wait (lsp->ls_state->inode, &data->fl) <0 ) - goto out_restart; - }if (data->arg.new_lock_owner !=0 ) {nfs_confirm_seqid (&lsp->ls_seqid,0 );nfs4_stateid_copy (&lsp->ls_stateid, &data->res.stateid);
@@ -7559,11 +7553,10 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f msg.rpc_argp = &data->arg; msg.rpc_resp = &data->res; task_setup_data.callback_data = data; -if (recovery_type >NFS_LOCK_NEW ) { -if (recovery_type ==NFS_LOCK_RECLAIM ) - data->arg.reclaim =NFS_LOCK_RECLAIM ; - }else - data->arg.new_lock =1 ; + +if (recovery_type ==NFS_LOCK_RECLAIM ) + data->arg.reclaim =NFS_LOCK_RECLAIM ; + task =rpc_run_task (&task_setup_data);if (IS_ERR (task))return PTR_ERR (task);
@@ -7675,6 +7668,13 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lockup_read (&nfsi->rwsem);mutex_unlock (&sp->so_delegreturn_mutex); status =_nfs4_do_setlk (state, cmd, request,NFS_LOCK_NEW ); +if (status) + goto out; + +down_read (&nfsi->rwsem); + request->c.flc_flags &= ~(FL_SLEEP |FL_ACCESS ); + status =locks_lock_inode_wait (state->inode, request); +up_read (&nfsi->rwsem); out: request->c.flc_flags = flags;return status;
include/linux/nfs_xdr.h +0 -1
@@ -579,7 +579,6 @@ struct nfs_lock_args {struct nfs_lowner lock_owner; unsigned char block : 1; unsigned char reclaim : 1; - unsigned char new_lock : 1; unsigned char new_lock_owner : 1; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 675/1611 PCI: mediatek: Fix operator precedence in PCIE_FTS_NUM_L0 macro
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 282305d7e9c0e27fd8b4df34b7cd5506a1eccdd6 ]
The original PCIE_FTS_NUM_L0(x) macro was buggy due to improper operator precedence, where ((x) & 0xff << 8) was evaluated as ((x) & 0xff00).
Instead of just fixing the parentheses, use the standard FIELD_PREP() macro. This makes the code more robust by automatically handling masks and shifts, while also adding compile-time type and range checking to ensure the value fits within PCIE_FTS_NUM_MASK.
--- drivers/pci/controller/pcie-mediatek.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-mediatek.c +2 -1
@@ -7,6 +7,7 @@* Honghui Zhang <[email protected]> */ +#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/iopoll.h>
@@ -61,7 +62,7 @@/* MediaTek specific configuration registers */ #define PCIE_FTS_NUM 0x70c#define PCIE_FTS_NUM_MASK GENMASK(15, 8) -#define PCIE_FTS_NUM_L0 (x) ((x) & 0xff << 8) +#define PCIE_FTS_NUM_L0 (x) FIELD_PREP(PCIE_FTS_NUM_MASK, x)#define PCIE_FC_CREDIT 0x73c#define PCIE_FC_CREDIT_MASK (GENMASK(31, 31) | GENMASK(28, 16))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 676/1611 pwm: rzg2l-gpt: Add missing newlines to dev_err_probe() messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Biju Das <[email protected]>
[ Upstream commit 898ab0f30e008e411ce93ddf81c4099abd9d4e46 ]
dev_err_probe() internally calls dev_err() which uses pr_fmt() and printk(). Kernel log messages should end with a newline character to ensure proper log formatting. Add missing '\n' at the end of the error strings in rzg2l_gpt_probe().
--- drivers/pwm/pwm-rzg2l-gpt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pwm/pwm-rzg2l-gpt.c +3 -3
@@ -408,14 +408,14 @@ static int rzg2l_gpt_probe(struct platform_device *pdev) rate =clk_get_rate (clk);if (!rate) -return dev_err_probe (dev, -EINVAL ,"The gpt clk rate is 0" ); +return dev_err_probe (dev, -EINVAL ,"The gpt clk rate is 0\n" );/* * Refuse clk rates > 1 GHz to prevent overflow later for computing * period and duty cycle. */ if (rate >NSEC_PER_SEC ) -return dev_err_probe (dev, -EINVAL ,"The gpt clk rate is > 1GHz" ); +return dev_err_probe (dev, -EINVAL ,"The gpt clk rate is > 1GHz\n" );/* * Rate is in MHz and is always integer for peripheral clk
@@ -424,7 +424,7 @@ static int rzg2l_gpt_probe(struct platform_device *pdev)*/ rzg2l_gpt->rate_khz = rate /KILO ;if (rzg2l_gpt->rate_khz *KILO != rate) -return dev_err_probe (dev, -EINVAL ,"Rate is not multiple of 1000" ); +return dev_err_probe (dev, -EINVAL ,"Rate is not multiple of 1000\n" );mutex_init (&rzg2l_gpt->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 677/1611 PCI: meson: Propagate devm_add_action_or_reset() failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuvam Pandey <[email protected]>
[ Upstream commit b12341b98d5ac52f48ca1390e1e371aed81346c8 ]
meson_pcie_probe_clock() enables a clock and then registers a devres action to disable it during teardown. If devm_add_action_or_reset() fails, it runs the action immediately, disabling the clock.
The return value is currently ignored, so on that failure path, meson_pcie_probe_clock() returns the disabled clock and probe continues. Return the error so the existing probe error path unwinds normally.
--- drivers/pci/controller/dwc/pci-meson.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-meson.c +3 -1
@@ -204,7 +204,9 @@ static inline struct clk *meson_pcie_probe_clock(struct device *dev,return ERR_PTR (ret); } -devm_add_action_or_reset (dev, meson_pcie_disable_clock, clk); + ret =devm_add_action_or_reset (dev, meson_pcie_disable_clock, clk); +if (ret) +return ERR_PTR (ret);return clk; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 678/1611 PCI: meson: Add missing remove callback
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuvam Pandey <[email protected]>
[ Upstream commit 4b0dc84b293984f75598881809fb2d3daf54a2a8 ]
meson_pcie_probe() powers on the PHY and registers the DesignWare host bridge with dw_pcie_host_init(), but the driver has no remove callback. On driver unbind or module unload, the driver core therefore proceeds to devres cleanup without first unregistering the host bridge or powering off the PHY.
Add a remove callback that deinitializes the DesignWare host bridge and powers off the PHY while device-managed resources are still valid.
--- drivers/pci/controller/dwc/pci-meson.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/pci/controller/dwc/pci-meson.c +9 -0
@@ -453,6 +453,14 @@ static int meson_pcie_probe(struct platform_device *pdev)return ret; } +static void meson_pcie_remove (struct platform_device *pdev) +{ +struct meson_pcie *mp =platform_get_drvdata (pdev); + +dw_pcie_host_deinit (&mp->pci.pp); +meson_pcie_power_off (mp); +} +static const struct of_device_id meson_pcie_of_match[] = { { .compatible ="amlogic,axg-pcie" ,
@@ -466,6 +474,7 @@ MODULE_DEVICE_TABLE(of, meson_pcie_of_match);static struct platform_driver meson_pcie_driver = { .probe = meson_pcie_probe, + .remove = meson_pcie_remove, .driver = { .name ="meson-pcie" , .of_match_table = meson_pcie_of_match,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 679/1611 fs/ntfs3: resize log->one_page_buf when adopting on-disk page size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamie Nguyen <[email protected]>
[ Upstream commit 5a35454179fe1041d9cd286f5d320ce0d448c12a ]
log_replay() allocates log->one_page_buf using the page size that was chosen from the host PAGE_SIZE:
log->one_page_buf = kmalloc(log->page_size, GFP_NOFS);
Later, when a restart area is found, the log page size recorded on disk is adopted:
t32 = le32_to_cpu(log->rst_info.r_page->sys_page_size);
if (log->page_size != t32) {
log->l_size = log->orig_file_size;
log->page_size = norm_file_page(t32, &log->l_size,
t32 == DefaultLogPageSize);
}If the on-disk page size is larger than the size used for the initial allocation, log->page_size grows but one_page_buf is left at its original, smaller size. A subsequent unaligned read_log_page() then reads log->page_size bytes into the undersized scratch buffer:
page_buf = page_off ? log->one_page_buf : *buffer; err = ntfs_read_run_nb_ra(ni->mi.sbi, &ni->file.run, page_vbo, page_buf, log->page_size, NULL, &log->read_ahead);
overflowing the allocation. This is reachable when mounting a dirty NTFS volume whose log was formatted with a page size larger than the buffer initially allocated on the mounting host (for example a 64K-log volume mounted on a host that allocated a 4K scratch buffer).
Grow one_page_buf when the adopted on-disk page size exceeds the size used for the initial allocation. On krealloc() failure the original buffer is left intact and freed by the existing error path.
--- fs/ntfs3/fslog.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
fs/ntfs3/fslog.c +19 -0
@@ -3936,9 +3936,28 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)*/ t32 =le32_to_cpu (log->rst_info.r_page->sys_page_size);if (log->page_size != t32) { +u32 old_page_size = log->page_size; + log->l_size = log->orig_file_size; log->page_size =norm_file_page (t32, &log->l_size, t32 == DefaultLogPageSize); + +/* +* If the adopted on-disk page size is larger than the size used +* to allocate one_page_buf above, grow the scratch buffer so a +* later read_log_page() cannot overflow it. +*/ +if (log->page_size > old_page_size) { +void *buf; + + buf =krealloc (log->one_page_buf, log->page_size, +GFP_NOFS ); +if (!buf) { + err = -ENOMEM ; + goto out; + } + log->one_page_buf = buf; + } } if (log->page_size != t32 ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 680/1611 platform/x86:intel/pmc: Add support for multiple DMU GUIDs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xi Pardee <[email protected]>
[ Upstream commit 3b603955f2423cf668ebd5ba670019a5b4960cc5 ]
Enable support for multiple DMU GUIDs to accommodate Arrow Lake H/U platforms. Arrow Lake U/H may have several GUIDs pointing to a single telemetry region providing die C6 value Add support to search for available GUIDs.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- drivers/platform/x86/intel/pmc/arl.c | 6 ++++-- drivers/platform/x86/intel/pmc/core.c | 22 ++++++++++++++++++---- drivers/platform/x86/intel/pmc/core.h | 6 +++--- drivers/platform/x86/intel/pmc/mtl.c | 3 ++- 4 files changed, 27 insertions(+), 10 deletions(-)
drivers/platform/x86/intel/pmc/arl.c +4 -2
@@ -720,9 +720,10 @@ static int arl_h_core_init(struct pmc_dev *pmcdev, struct pmc_dev_info *pmc_dev_return generic_core_init (pmcdev, pmc_dev_info); } +static u32 ARL_PMT_DMU_GUIDS [] = {ARL_PMT_DMU_GUID ,0x0 };struct pmc_dev_info arl_pmc_dev = { .pci_func =0 , - .dmu_guid =ARL_PMT_DMU_GUID , + .dmu_guids =ARL_PMT_DMU_GUIDS , .regmap_list = arl_pmc_info_list, .map = &arl_socs_reg_map, .sub_req_show = &pmc_core_substate_req_regs_fops,
@@ -732,9 +733,10 @@ struct pmc_dev_info arl_pmc_dev = { .sub_req = pmc_core_pmt_get_lpm_req, }; +static u32 ARL_H_PMT_DMU_GUIDS [] = {ARL_PMT_DMU_GUID ,0x0 };struct pmc_dev_info arl_h_pmc_dev = { .pci_func =2 , - .dmu_guid =ARL_PMT_DMU_GUID , + .dmu_guids =ARL_H_PMT_DMU_GUIDS , .regmap_list = arl_pmc_info_list, .map = &mtl_socm_reg_map, .sub_req_show = &pmc_core_substate_req_regs_fops,
drivers/platform/x86/intel/pmc/core.c +18 -4
@@ -20,6 +20,7 @@ enum header_type {#include <linux/debugfs.h> #include <linux/delay.h> #include <linux/dmi.h> +#include <linux/err.h> #include <linux/io.h> #include <linux/module.h> #include <linux/pci.h>
@@ -1281,7 +1282,20 @@ int get_primary_reg_base(struct pmc *pmc)return 0 ; } -void pmc_core_punit_pmt_init (struct pmc_dev *pmcdev,u32 guid) +static struct telem_endpoint *pmc_core_register_endpoint (struct pci_dev *pcidev,u32 *guids) +{ +struct telem_endpoint *ep; +unsigned int i; + +for (i =0 ; guids[i]; i++) { + ep =pmt_telem_find_and_register_endpoint (pcidev, guids[i],0 ); +if (!IS_ERR (ep)) +return ep; + } +return ERR_PTR (-ENODEV ); +} + +void pmc_core_punit_pmt_init (struct pmc_dev *pmcdev,u32 *guids) {struct telem_endpoint *ep;struct pci_dev *pcidev;
@@ -1292,7 +1306,7 @@ void pmc_core_punit_pmt_init(struct pmc_dev *pmcdev, u32 guid)return ; } - ep =pmt_telem_find_and_register_endpoint (pcidev, guid,0 ); + ep =pmc_core_register_endpoint (pcidev, guids);pci_dev_put (pcidev);if (IS_ERR (ep)) { dev_err(&pmcdev->pdev->dev,
@@ -1689,8 +1703,8 @@ int generic_core_init(struct pmc_dev *pmcdev, struct pmc_dev_info *pmc_dev_info) }pmc_core_get_low_power_modes (pmcdev); -if (pmc_dev_info->dmu_guid) -pmc_core_punit_pmt_init (pmcdev, pmc_dev_info->dmu_guid); +if (pmc_dev_info->dmu_guids) +pmc_core_punit_pmt_init (pmcdev, pmc_dev_info->dmu_guids);if (ssram) { ret =pmc_core_get_telem_info (pmcdev, pmc_dev_info);
drivers/platform/x86/intel/pmc/core.h +3 -3
@@ -481,7 +481,7 @@ enum pmc_index {/** * struct pmc_dev_info - Structure to keep PMC device info * @pci_func: Function number of the primary PMC -* @dmu_guid: Die Management Unit GUID +* @dmu_guids: List of Die Management Unit GUID * @regmap_list: Pointer to a list of pmc_info structure that could be * available for the platform. When set, this field implies * SSRAM support.
@@ -495,7 +495,7 @@ enum pmc_index {*/ struct pmc_dev_info {u8 pci_func; -u32 dmu_guid; +u32 *dmu_guids;struct pmc_info *regmap_list;const struct pmc_reg_map *map;const struct file_operations *sub_req_show;
@@ -532,7 +532,7 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore);int pmc_core_resume_common (struct pmc_dev *pmcdev);int get_primary_reg_base (struct pmc *pmc);void pmc_core_get_low_power_modes (struct pmc_dev *pmcdev); -void pmc_core_punit_pmt_init (struct pmc_dev *pmcdev,u32 guid); +void pmc_core_punit_pmt_init (struct pmc_dev *pmcdev,u32 *guids);void pmc_core_set_device_d3 (unsigned int device);int generic_core_init (struct pmc_dev *pmcdev,struct pmc_dev_info *pmc_dev_info);
drivers/platform/x86/intel/pmc/mtl.c +2 -1
@@ -992,9 +992,10 @@ static int mtl_core_init(struct pmc_dev *pmcdev, struct pmc_dev_info *pmc_dev_inreturn generic_core_init (pmcdev, pmc_dev_info); } +static u32 MTL_PMT_DMU_GUIDS [] = {MTL_PMT_DMU_GUID ,0x0 };struct pmc_dev_info mtl_pmc_dev = { .pci_func =2 , - .dmu_guid =MTL_PMT_DMU_GUID , + .dmu_guids =MTL_PMT_DMU_GUIDS , .regmap_list = mtl_pmc_info_list, .map = &mtl_socm_reg_map, .sub_req_show = &pmc_core_substate_req_regs_fops,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 681/1611 platform/x86:intel/pmc: Rename PMC index variable to pmc_idx
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xi Pardee <[email protected]>
[ Upstream commit 7848154c3a11fb3ffbffd150f2185f97b5a6595a ]
Rename all PMC index variables to pmc_idx in core.c. This improves code readability and consistency.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- drivers/platform/x86/intel/pmc/core.c | 108 +++++++++++++------------- 1 file changed, 54 insertions(+), 54 deletions(-)
drivers/platform/x86/intel/pmc/core.c +54 -54
@@ -312,20 +312,20 @@ static inline u8 pmc_core_reg_read_byte(struct pmc *pmc, int offset) }static void pmc_core_display_map (struct seq_file *s,int index,int idx,int ip, -int pmc_index,u8 pf_reg,const struct pmc_bit_map **pf_map) +int pmc_idx,u8 pf_reg,const struct pmc_bit_map **pf_map) {seq_printf (s,"PMC%d:PCH IP: %-2d - %-32s\tState: %s\n" , - pmc_index, ip, pf_map[idx][index].name, + pmc_idx, ip, pf_map[idx][index].name, pf_map[idx][index].bit_mask & pf_reg ?"Off" :"On" ); }static int pmc_core_ppfear_show (struct seq_file *s,void *unused) {struct pmc_dev *pmcdev = s->private; -unsigned int i; +unsigned int pmc_idx; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { -struct pmc *pmc = pmcdev->pmcs[i]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];const struct pmc_bit_map **maps;u8 pf_regs[PPFEAR_MAX_NUM_ENTRIES ];unsigned int index, iter, idx, ip =0 ;
@@ -343,7 +343,7 @@ static int pmc_core_ppfear_show(struct seq_file *s, void *unused)for (idx =0 ; maps[idx]; idx++) {for (index =0 ; maps[idx][index].name && index < pmc->map->ppfear_buckets *8 ; ip++, index++) -pmc_core_display_map (s, index, idx, ip, i, +pmc_core_display_map (s, index, idx, ip, pmc_idx, pf_regs[index /8 ], maps); } }
@@ -472,7 +472,7 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore)struct pmc *pmc;const struct pmc_reg_map *map;u32 reg; -unsigned int pmc_index; +unsigned int pmc_idx;int ltr_index; ltr_index = value;
@@ -480,8 +480,8 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore)* is based on the contiguous indexes from ltr_show output. * pmc index and ltr index needs to be calculated from it. */ -for (pmc_index =0 ; pmc_index <ARRAY_SIZE (pmcdev->pmcs) && ltr_index >=0 ; pmc_index++) { - pmc = pmcdev->pmcs[pmc_index]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs) && ltr_index >=0 ; pmc_idx++) { + pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ;
@@ -498,10 +498,10 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore) ltr_index = ltr_index - (map->ltr_ignore_max +2 ) -1 ; } -if (pmc_index >=ARRAY_SIZE (pmcdev->pmcs) || ltr_index <0 ) +if (pmc_idx >=ARRAY_SIZE (pmcdev->pmcs) || ltr_index <0 )return -EINVAL ; -pr_debug ("ltr_ignore for pmc%d: ltr_index:%d\n" , pmc_index, ltr_index); +pr_debug ("ltr_ignore for pmc%d: ltr_index:%d\n" , pmc_idx, ltr_index);guard (mutex)(&pmcdev->lock);
@@ -636,14 +636,14 @@ static int pmc_core_ltr_show(struct seq_file *s, void *unused)u64 decoded_snoop_ltr, decoded_non_snoop_ltr, val;u32 ltr_raw_data, scale;u16 snoop_ltr, nonsnoop_ltr; -unsigned int i, index, ltr_index =0 ; +unsigned int pmc_idx, index, ltr_index =0 ; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) {struct pmc *pmc;const struct pmc_bit_map *map;u32 ltr_ign_reg; - pmc = pmcdev->pmcs[i]; + pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ;
@@ -677,7 +677,7 @@ static int pmc_core_ltr_show(struct seq_file *s, void *unused) }seq_printf (s,"%d\tPMC%d:%-32s\tLTR: RAW: 0x%-16x\tNon-Snoop(ns): %-16llu\tSnoop(ns): %-16llu\tLTR_IGNORE: %d\n" , - ltr_index, i, map[index].name, ltr_raw_data, + ltr_index, pmc_idx, map[index].name, ltr_raw_data, decoded_non_snoop_ltr, decoded_snoop_ltr, ltr_ign_data); ltr_index++;
@@ -690,15 +690,15 @@ DEFINE_SHOW_ATTRIBUTE(pmc_core_ltr);static int pmc_core_s0ix_blocker_show (struct seq_file *s,void *unused) {struct pmc_dev *pmcdev = s->private; -unsigned int pmcidx; +unsigned int pmc_idx; -for (pmcidx =0 ; pmcidx <ARRAY_SIZE (pmcdev->pmcs); pmcidx++) { +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); pmc_idx++) {const struct pmc_bit_map **maps;unsigned int arr_size, r_idx;u32 offset, counter;struct pmc *pmc; - pmc = pmcdev->pmcs[pmcidx]; + pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ; maps = pmc->map->s0ix_blocker_maps;
@@ -712,7 +712,7 @@ static int pmc_core_s0ix_blocker_show(struct seq_file *s, void *unused)if (!map->blk)continue ; counter =pmc_core_reg_read (pmc, offset); -seq_printf (s,"PMC%d:%-30s %-30d\n" , pmcidx, +seq_printf (s,"PMC%d:%-30s %-30d\n" , pmc_idx, map->name, counter); offset += map->blk *S0IX_BLK_SIZE ; }
@@ -724,13 +724,13 @@ DEFINE_SHOW_ATTRIBUTE(pmc_core_s0ix_blocker);static void pmc_core_ltr_ignore_all (struct pmc_dev *pmcdev) { -unsigned int i; +unsigned int pmc_idx; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); i++) { +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); pmc_idx++) {struct pmc *pmc;u32 ltr_ign; - pmc = pmcdev->pmcs[i]; + pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ;
@@ -751,12 +751,12 @@ static void pmc_core_ltr_ignore_all(struct pmc_dev *pmcdev)static void pmc_core_ltr_restore_all (struct pmc_dev *pmcdev) { -unsigned int i; +unsigned int pmc_idx; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); i++) { +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); pmc_idx++) {struct pmc *pmc; - pmc = pmcdev->pmcs[i]; + pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ;
@@ -795,10 +795,10 @@ DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_res);static int pmc_core_substate_sts_regs_show (struct seq_file *s,void *unused) {struct pmc_dev *pmcdev = s->private; -unsigned int i; +unsigned int pmc_idx; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { -struct pmc *pmc = pmcdev->pmcs[i]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];const struct pmc_bit_map **maps;u32 offset;
@@ -806,7 +806,7 @@ static int pmc_core_substate_sts_regs_show(struct seq_file *s, void *unused)continue ; maps = pmc->map->lpm_sts; offset = pmc->map->lpm_status_offset; -pmc_core_lpm_display (pmc,NULL , s, offset, i,"STATUS" , maps); +pmc_core_lpm_display (pmc,NULL , s, offset, pmc_idx,"STATUS" , maps); }return 0 ;
@@ -816,10 +816,10 @@ DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_sts_regs);static int pmc_core_substate_l_sts_regs_show (struct seq_file *s,void *unused) {struct pmc_dev *pmcdev = s->private; -unsigned int i; +unsigned int pmc_idx; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { -struct pmc *pmc = pmcdev->pmcs[i]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];const struct pmc_bit_map **maps;u32 offset;
@@ -827,7 +827,7 @@ static int pmc_core_substate_l_sts_regs_show(struct seq_file *s, void *unused)continue ; maps = pmc->map->lpm_sts; offset = pmc->map->lpm_live_status_offset; -pmc_core_lpm_display (pmc,NULL , s, offset, i,"LIVE_STATUS" , maps); +pmc_core_lpm_display (pmc,NULL , s, offset, pmc_idx,"LIVE_STATUS" , maps); }return 0 ;
@@ -920,11 +920,11 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused)u32 sts_offset;u32 sts_offset_live;u32 *lpm_req_regs; -unsigned int mp, pmc_index; +unsigned int mp, pmc_idx;int num_maps; -for (pmc_index =0 ; pmc_index <ARRAY_SIZE (pmcdev->pmcs); ++pmc_index) { -struct pmc *pmc = pmcdev->pmcs[pmc_index]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];const struct pmc_bit_map **maps;if (!pmc)
@@ -945,7 +945,7 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused)continue ;/* Display the header */ -pmc_core_substate_req_header_show (s, pmc_index,HEADER_STATUS ); +pmc_core_substate_req_header_show (s, pmc_idx,HEADER_STATUS );/* Loop over maps */ for (mp =0 ; mp < num_maps; mp++) {
@@ -983,7 +983,7 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused) }/* Display the element name in the first column */ -seq_printf (s,"pmc%d: %34s |" , pmc_index, map[i].name); +seq_printf (s,"pmc%d: %34s |" , pmc_idx, map[i].name);/* Loop over the enabled states and display if required */ pmc_for_each_mode (mode, pmcdev) {
@@ -1567,7 +1567,7 @@ static int pmc_core_get_telem_info(struct pmc_dev *pmcdev, struct pmc_dev_info * { struct pci_dev *pcidev __free(pci_dev_put) = NULL;struct telem_endpoint *ep; -unsigned int i; +unsigned int pmc_idx;u32 guid;int ret;
@@ -1575,10 +1575,10 @@ static int pmc_core_get_telem_info(struct pmc_dev *pmcdev, struct pmc_dev_info *if (!pcidev)return -ENODEV ; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) {struct pmc *pmc; - pmc = pmcdev->pmcs[i]; + pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ;
@@ -1610,7 +1610,7 @@ static const struct pmc_reg_map *pmc_core_find_regmap(struct pmc_info *list, u16return NULL ; } -static int pmc_core_pmc_add (struct pmc_dev *pmcdev,unsigned int pmc_index) +static int pmc_core_pmc_add (struct pmc_dev *pmcdev,unsigned int pmc_idx) {struct pmc_ssram_telemetry pmc_ssram_telemetry;
@@ -1618,7 +1618,7 @@ static int pmc_core_pmc_add(struct pmc_dev *pmcdev, unsigned int pmc_index)struct pmc *pmc;int ret; - ret =pmc_ssram_telemetry_get_pmc_info (pmc_index, &pmc_ssram_telemetry); + ret =pmc_ssram_telemetry_get_pmc_info (pmc_idx, &pmc_ssram_telemetry);if (ret)return ret;
@@ -1626,7 +1626,7 @@ static int pmc_core_pmc_add(struct pmc_dev *pmcdev, unsigned int pmc_index)if (!map)return -ENODEV ; - pmc = pmcdev->pmcs[pmc_index]; + pmc = pmcdev->pmcs[pmc_idx];/* Memory for primary PMC has been allocated */ if (!pmc) { pmc =devm_kzalloc (&pmcdev->pdev->dev,sizeof (*pmc),GFP_KERNEL );
@@ -1643,7 +1643,7 @@ static int pmc_core_pmc_add(struct pmc_dev *pmcdev, unsigned int pmc_index)return -ENOMEM ; } - pmcdev->pmcs[pmc_index] = pmc; + pmcdev->pmcs[pmc_idx] = pmc;return 0 ; }
@@ -1715,8 +1715,8 @@ int generic_core_init(struct pmc_dev *pmcdev, struct pmc_dev_info *pmc_dev_info)return 0 ; unmap_regbase: -for (unsigned int i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { -struct pmc *pmc = pmcdev->pmcs[i]; +for (unsigned int pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];if (pmc && pmc->regbase)iounmap (pmc->regbase);
@@ -1809,10 +1809,10 @@ static void pmc_core_do_dmi_quirks(struct pmc *pmc)static void pmc_core_clean_structure (struct platform_device *pdev) {struct pmc_dev *pmcdev =platform_get_drvdata (pdev); -unsigned int i; +unsigned int pmc_idx; -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { -struct pmc *pmc = pmcdev->pmcs[i]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];if (pmc && pmc->regbase)iounmap (pmc->regbase);
@@ -1972,7 +1972,7 @@ int pmc_core_resume_common(struct pmc_dev *pmcdev)struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN ];const struct pmc_bit_map **maps = pmc->map->lpm_sts;int offset = pmc->map->lpm_status_offset; -unsigned int i; +unsigned int pmc_idx, i;/* Check if the syspend used S0ix */ if (pm_suspend_via_firmware ())
@@ -2010,13 +2010,13 @@ int pmc_core_resume_common(struct pmc_dev *pmcdev)if (pmc->map->slps0_dbg_maps)pmc_core_slps0_display (pmc, dev,NULL ); -for (i =0 ; i <ARRAY_SIZE (pmcdev->pmcs); ++i) { -struct pmc *pmc = pmcdev->pmcs[i]; +for (pmc_idx =0 ; pmc_idx <ARRAY_SIZE (pmcdev->pmcs); ++pmc_idx) { +struct pmc *pmc = pmcdev->pmcs[pmc_idx];if (!pmc)continue ;if (pmc->map->lpm_sts) -pmc_core_lpm_display (pmc, dev,NULL , offset, i,"STATUS" , maps); +pmc_core_lpm_display (pmc, dev,NULL , offset, pmc_idx,"STATUS" , maps); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 682/1611 platform/x86:intel/pmc: Relocate lpm_req_guid to pmc_reg_map
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xi Pardee <[email protected]>
[ Upstream commit c2bc11f1f204ef916ec96e45cf329e42873b37d6 ]
Relocate the lpm_req_guid field from pmc_info to pmc_reg_map. The previous implementation stored lpm_req_guid in pmc_info and relied on pmc_core_find_guid() to retrieve the correct GUID, which was unnecessary. Since lpm_req_guid is specific to PMC, pmc_reg_map is a more appropriate location for this information.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- drivers/platform/x86/intel/pmc/arl.c | 6 ++---- drivers/platform/x86/intel/pmc/core.c | 15 ++------------- drivers/platform/x86/intel/pmc/core.h | 4 +++- drivers/platform/x86/intel/pmc/lnl.c | 2 +- drivers/platform/x86/intel/pmc/mtl.c | 6 +++--- drivers/platform/x86/intel/pmc/ptl.c | 3 +-- 6 files changed, 12 insertions(+), 24 deletions(-)
drivers/platform/x86/intel/pmc/arl.c +2 -4
@@ -281,6 +281,7 @@ static const struct pmc_reg_map arl_socs_reg_map = { .etr3_offset = ETR3_OFFSET, .pson_residency_offset = TGL_PSON_RESIDENCY_OFFSET, .pson_residency_counter_step = TGL_PSON_RES_COUNTER_STEP, + .lpm_req_guid = SOCS_LPM_REQ_GUID, };static const struct pmc_bit_map arl_pchs_ltr_show_map[] = {
@@ -648,26 +649,23 @@ static const struct pmc_reg_map arl_pchs_reg_map = { .lpm_num_maps = ADL_LPM_NUM_MAPS, .lpm_reg_index = ARL_LPM_REG_INDEX, .etr3_offset = ETR3_OFFSET, + .lpm_req_guid = PCHS_LPM_REQ_GUID, };static struct pmc_info arl_pmc_info_list[] = { { - .guid =IOEP_LPM_REQ_GUID , .devid =PMC_DEVID_ARL_IOEP , .map = &mtl_ioep_reg_map, }, { - .guid =SOCS_LPM_REQ_GUID , .devid =PMC_DEVID_ARL_SOCS , .map = &arl_socs_reg_map, }, { - .guid =PCHS_LPM_REQ_GUID , .devid =PMC_DEVID_ARL_PCHS , .map = &arl_pchs_reg_map, }, { - .guid =SOCM_LPM_REQ_GUID , .devid =PMC_DEVID_ARL_SOCM , .map = &mtl_socm_reg_map, },
drivers/platform/x86/intel/pmc/core.c +2 -13
@@ -1444,15 +1444,6 @@ static void pmc_core_dbgfs_register(struct pmc_dev *pmcdev, struct pmc_dev_info } } -static u32 pmc_core_find_guid (struct pmc_info *list,const struct pmc_reg_map *map) -{ -for (; list->map; ++list) -if (list->map == map) -return list->guid; - -return 0 ; -} -/* * This function retrieves low power mode requirement data from PMC Low * Power Mode (LPM) table.
@@ -1568,7 +1559,6 @@ static int pmc_core_get_telem_info(struct pmc_dev *pmcdev, struct pmc_dev_info * struct pci_dev *pcidev __free(pci_dev_put) = NULL;struct telem_endpoint *ep;unsigned int pmc_idx; -u32 guid;int ret; pcidev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (20 , pmc_dev_info->pci_func));
@@ -1582,11 +1572,10 @@ static int pmc_core_get_telem_info(struct pmc_dev *pmcdev, struct pmc_dev_info *if (!pmc)continue ; - guid =pmc_core_find_guid (pmcdev->regmap_list, pmc->map); -if (!guid) +if (!pmc->map->lpm_req_guid)return -ENXIO ; - ep =pmt_telem_find_and_register_endpoint (pcidev, guid,0 ); + ep =pmt_telem_find_and_register_endpoint (pcidev, pmc->map->lpm_req_guid,0 );if (IS_ERR (ep)) {dev_dbg (&pmcdev->pdev->dev,"couldn't get telem endpoint %pe" , ep);return -EPROBE_DEFER ;
drivers/platform/x86/intel/pmc/core.h +3 -1
@@ -355,6 +355,7 @@ struct pmc_bit_map {* @s0ix_blocker_offset PWRMBASE offset to S0ix blocker counter * @num_s0ix_blocker: Number of S0ix blockers * @blocker_req_offset: Telemetry offset to S0ix blocker low power mode substate requirement table +* @lpm_req_guid: Telemetry GUID to read low power mode substate requirement table * * Each PCH has unique set of register offsets and bit indexes. This structure * captures them to have a common implementation.
@@ -396,6 +397,8 @@ struct pmc_reg_map {const u8 *lpm_reg_index;const u32 pson_residency_offset;const u32 pson_residency_counter_step; +/* GUID for telemetry regions */ +const u32 lpm_req_guid; };/**
@@ -405,7 +408,6 @@ struct pmc_reg_map {* specific attributes */ struct pmc_info { -u32 guid;u16 devid;const struct pmc_reg_map *map; };
drivers/platform/x86/intel/pmc/lnl.c +1 -1
@@ -533,11 +533,11 @@ static const struct pmc_reg_map lnl_socm_reg_map = { .s0ix_blocker_maps = lnl_blk_maps, .s0ix_blocker_offset = LNL_S0IX_BLOCKER_OFFSET, .lpm_reg_index = LNL_LPM_REG_INDEX, + .lpm_req_guid = SOCM_LPM_REQ_GUID, };static struct pmc_info lnl_pmc_info_list[] = { { - .guid =SOCM_LPM_REQ_GUID , .devid =PMC_DEVID_LNL_SOCM , .map = &lnl_socm_reg_map, },
drivers/platform/x86/intel/pmc/mtl.c +3 -3
@@ -473,6 +473,7 @@ const struct pmc_reg_map mtl_socm_reg_map = { .lpm_status_offset = MTL_LPM_STATUS_OFFSET, .lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET, .lpm_reg_index = MTL_LPM_REG_INDEX, + .lpm_req_guid = SOCP_LPM_REQ_GUID, };static const struct pmc_bit_map mtl_ioep_pfear_map[] = {
@@ -797,6 +798,7 @@ const struct pmc_reg_map mtl_ioep_reg_map = { .lpm_en_offset = MTL_LPM_EN_OFFSET, .lpm_sts_latch_en_offset = MTL_LPM_STATUS_LATCH_EN_OFFSET, .lpm_reg_index = MTL_LPM_REG_INDEX, + .lpm_req_guid = IOEP_LPM_REQ_GUID, };static const struct pmc_bit_map mtl_ioem_pfear_map[] = {
@@ -944,21 +946,19 @@ static const struct pmc_reg_map mtl_ioem_reg_map = { .lpm_res_counter_step_x2 = TGL_PMC_LPM_RES_COUNTER_STEP_X2, .lpm_residency_offset = MTL_LPM_RESIDENCY_OFFSET, .lpm_reg_index = MTL_LPM_REG_INDEX, + .lpm_req_guid = IOEM_LPM_REQ_GUID, };static struct pmc_info mtl_pmc_info_list[] = { { - .guid =SOCP_LPM_REQ_GUID , .devid =PMC_DEVID_MTL_SOCM , .map = &mtl_socm_reg_map, }, { - .guid =IOEP_LPM_REQ_GUID , .devid =PMC_DEVID_MTL_IOEP , .map = &mtl_ioep_reg_map, }, { - .guid =IOEM_LPM_REQ_GUID , .devid =PMC_DEVID_MTL_IOEM , .map = &mtl_ioem_reg_map },
drivers/platform/x86/intel/pmc/ptl.c +1 -2
@@ -528,16 +528,15 @@ static const struct pmc_reg_map ptl_pcdp_reg_map = { .s0ix_blocker_offset = LNL_S0IX_BLOCKER_OFFSET, .num_s0ix_blocker = PTL_NUM_S0IX_BLOCKER, .blocker_req_offset = PTL_BLK_REQ_OFFSET, + .lpm_req_guid = PCDP_LPM_REQ_GUID, };static struct pmc_info ptl_pmc_info_list[] = { { - .guid =PCDP_LPM_REQ_GUID , .devid =PMC_DEVID_PTL_PCDH , .map = &ptl_pcdp_reg_map, }, { - .guid =PCDP_LPM_REQ_GUID , .devid =PMC_DEVID_PTL_PCDP , .map = &ptl_pcdp_reg_map, },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 683/1611 platform/x86/intel/vsec: correct kernel-doc comments
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
[ Upstream commit 20e20b147cf7cb6780a5b95da2a0e37c52cd1015 ]
Fix kernel-doc warnings in intel_vsec.h to eliminate all kernel-doc warnings:
Warning: include/linux/intel_vsec.h:92 struct member 'read_telem' not
described in 'pmt_callbacks'
Warning: include/linux/intel_vsec.h:146 expecting prototype for struct
intel_sec_device. Prototype was for struct intel_vsec_device instead
Warning: include/linux/intel_vsec.h:146 struct member 'priv_data_size'
not described in 'intel_vsec_device'
In struct pmt_callbacks, correct the kernel-doc for @read_telem. kernel-doc doesn't support documenting callback function parameters, so drop the '@' signs on those and use "* *" to make them somewhat readable in the produced documentation output.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- include/linux/intel_vsec.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
include/linux/intel_vsec.h +9 -8
@@ -80,13 +80,13 @@ enum intel_vsec_quirks {/** * struct pmt_callbacks - Callback infrastructure for PMT devices -* ->read_telem() when specified, called by client driver to access PMT data (instead -* of direct copy). -* @pdev: PCI device reference for the callback's use -* @guid: ID of data to acccss -* @data: buffer for the data to be copied -* @off: offset into the requested buffer -* @count: size of buffer +* @read_telem: when specified, called by client driver to access PMT +* data (instead of direct copy). +* * pdev: PCI device reference for the callback's use +* * guid: ID of data to acccss +* * data: buffer for the data to be copied +* * off: offset into the requested buffer +* * count: size of buffer */ struct pmt_callbacks {int (*read_telem)(struct pci_dev *pdev,u32 guid,u64 *data,loff_t off,u32 count);
@@ -120,7 +120,7 @@ struct intel_vsec_platform_info { };/** -* struct intel_sec_device - Auxbus specific device information +* struct intel_vsec_device - Auxbus specific device information * @auxdev: auxbus device struct for auxbus access * @pcidev: pci device associated with the device * @resource: any resources shared by the parent
@@ -128,6 +128,7 @@ struct intel_vsec_platform_info {* @num_resources: number of resources * @id: xarray id * @priv_data: any private data needed +* @priv_data_size: size of private data area * @quirks: specified quirks * @base_addr: base address of entries (if specified) * @cap_id: the enumerated id of the vsec feature
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 684/1611 platform/x86/intel/vsec: Decouple add/link helpers from PCI
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David E. Box <[email protected]>
[ Upstream commit c62fd96a04e4a7b847448f97ecfe9f3fe706e7b3 ]
This refactor prepares for adding ACPI-enumerated PMT endpoints. While intel_vsec is bound to PCI today, some helpers are used by code that will also register PMT endpoints from non-PCI (ACPI) paths. Clean up PCI-specific plumbing where it isn’t strictly required and rely on generic struct device where possible.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- drivers/platform/x86/intel/vsec.c | 13 +++++++++---- drivers/platform/x86/intel/vsec_tpmi.c | 2 +- include/linux/intel_vsec.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-)
drivers/platform/x86/intel/vsec.c +9 -4
@@ -158,18 +158,23 @@ static bool vsec_driver_present(int cap_id)*/ static const struct pci_device_id intel_vsec_pci_ids[]; -static int intel_vsec_link_devices (struct pci_dev *pdev,struct device *dev, +static int intel_vsec_link_devices (struct device *parent,struct device *dev,int consumer_id) {const struct vsec_feature_dependency *deps;enum vsec_device_state *state;struct device **suppliers;struct vsec_priv *priv; +struct pci_dev *pdev;int supplier_id;if (!consumer_id)return 0 ; +if (!dev_is_pci (parent)) +return 0 ; + + pdev =to_pci_dev (parent);if (!pci_match_id (intel_vsec_pci_ids, pdev))return 0 ;
@@ -204,7 +209,7 @@ static int intel_vsec_link_devices(struct pci_dev *pdev, struct device *dev,return 0 ; } -int intel_vsec_add_aux (struct pci_dev *pdev,struct device *parent, +int intel_vsec_add_aux (struct device *parent,struct intel_vsec_device *intel_vsec_dev,const char *name) {
@@ -252,7 +257,7 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent,if (ret) goto cleanup_aux; - ret =intel_vsec_link_devices (pdev, &auxdev->dev, intel_vsec_dev->cap_id); + ret =intel_vsec_link_devices (parent, &auxdev->dev, intel_vsec_dev->cap_id);if (ret) goto cleanup_aux;
@@ -343,7 +348,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he* Pass the ownership of intel_vsec_dev and resource within it to * intel_vsec_add_aux() */ -return intel_vsec_add_aux (pdev, parent,no_free_ptr (intel_vsec_dev), +return intel_vsec_add_aux (parent,no_free_ptr (intel_vsec_dev),intel_vsec_name (header->id)); }
drivers/platform/x86/intel/vsec_tpmi.c +1 -1
@@ -655,7 +655,7 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,* feature_vsec_dev and res memory are also freed as part of * device deletion. */ -return intel_vsec_add_aux (vsec_dev->pcidev, &vsec_dev->auxdev.dev, +return intel_vsec_add_aux (&vsec_dev->auxdev.dev, feature_vsec_dev, feature_id_name); }
include/linux/intel_vsec.h +1 -1
@@ -184,7 +184,7 @@ struct pmt_feature_group {struct telemetry_region regions[]; }; -int intel_vsec_add_aux (struct pci_dev *pdev,struct device *parent, +int intel_vsec_add_aux (struct device *parent,struct intel_vsec_device *intel_vsec_dev,const char *name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 685/1611 platform/x86/intel/vsec: Switch exported helpers from pci_dev to device
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David E. Box <[email protected]>
[ Upstream commit 353042d54d82f6c46449f0ee38c244b5a13c1fe4 ]
Preparatory refactor for ACPI-enumerated PMT endpoints. Several exported PMT/VSEC interfaces and structs carried struct pci_dev * even though callers only need a generic struct device. Move those to struct device * so the same APIs work for PCI and ACPI parents.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- drivers/gpu/drm/xe/xe_debugfs.c | 2 +- drivers/gpu/drm/xe/xe_hwmon.c | 2 +- drivers/gpu/drm/xe/xe_vsec.c | 7 ++- drivers/gpu/drm/xe/xe_vsec.h | 4 +- drivers/platform/x86/intel/pmc/core.c | 4 +- .../platform/x86/intel/pmc/ssram_telemetry.c | 2 +- drivers/platform/x86/intel/pmt/class.c | 8 ++-- drivers/platform/x86/intel/pmt/class.h | 5 ++- drivers/platform/x86/intel/pmt/discovery.c | 4 +- drivers/platform/x86/intel/pmt/telemetry.c | 13 +++--- drivers/platform/x86/intel/pmt/telemetry.h | 12 ++--- drivers/platform/x86/intel/sdsi.c | 5 ++- drivers/platform/x86/intel/vsec.c | 44 +++++++++++-------- drivers/platform/x86/intel/vsec_tpmi.c | 6 +-- include/linux/intel_vsec.h | 13 +++--- 15 files changed, 71 insertions(+), 60 deletions(-)
drivers/gpu/drm/xe/xe_debugfs.c +1 -1
@@ -45,7 +45,7 @@ static void read_residency_counter(struct xe_device *xe, struct xe_mmio *mmio,u64 residency =0 ;int ret; - ret =xe_pmt_telem_read (to_pci_dev (xe->drm.dev), + ret =xe_pmt_telem_read (xe->drm.dev,xe_mmio_read32 (mmio,PUNIT_TELEMETRY_GUID ), &residency, offset,sizeof (residency));if (ret !=sizeof (residency)) {
drivers/gpu/drm/xe/xe_hwmon.c +1 -1
@@ -464,7 +464,7 @@ xe_hwmon_energy_get(struct xe_hwmon *hwmon, int channel, long *energy)if (hwmon->xe->info.platform ==XE_BATTLEMAGE ) {u64 pmt_val; - ret =xe_pmt_telem_read (to_pci_dev (hwmon->xe->drm.dev), + ret =xe_pmt_telem_read (hwmon->xe->drm.dev,xe_mmio_read32 (mmio,PUNIT_TELEMETRY_GUID ), &pmt_val,BMG_ENERGY_STATUS_PMT_OFFSET ,sizeof (pmt_val));if (ret !=sizeof (pmt_val)) {
drivers/gpu/drm/xe/xe_vsec.c +3 -4
@@ -141,10 +141,10 @@ static int xe_guid_decode(u32 guid, int *index, u32 *offset)return 0 ; } -int xe_pmt_telem_read (struct pci_dev *pdev,u32 guid,u64 *data,loff_t user_offset, +int xe_pmt_telem_read (struct device *dev,u32 guid,u64 *data,loff_t user_offset,u32 count) { -struct xe_device *xe =pdev_to_xe_device (pdev); +struct xe_device *xe =kdev_to_xe_device (dev);void __iomem *telem_addr = xe->mmio.regs +BMG_TELEMETRY_OFFSET ;u32 mem_region;u32 offset;
@@ -197,7 +197,6 @@ void xe_vsec_init(struct xe_device *xe) {struct intel_vsec_platform_info *info;struct device *dev = xe->drm.dev; -struct pci_dev *pdev =to_pci_dev (dev);enum xe_vsec platform; platform =get_platform_info (xe);
@@ -220,6 +219,6 @@ void xe_vsec_init(struct xe_device *xe)* Register a VSEC. Cleanup is handled using device managed * resources. */ -intel_vsec_register (pdev, info); +intel_vsec_register (dev, info); }MODULE_IMPORT_NS ("INTEL_VSEC" );
drivers/gpu/drm/xe/xe_vsec.h +2 -2
@@ -6,10 +6,10 @@#include <linux/types.h> -struct pci_dev ; +struct device ;struct xe_device ;void xe_vsec_init (struct xe_device *xe); -int xe_pmt_telem_read (struct pci_dev *pdev,u32 guid,u64 *data,loff_t user_offset,u32 count); +int xe_pmt_telem_read (struct device *dev,u32 guid,u64 *data,loff_t user_offset,u32 count);#endif
drivers/platform/x86/intel/pmc/core.c +2 -2
@@ -1288,7 +1288,7 @@ static struct telem_endpoint *pmc_core_register_endpoint(struct pci_dev *pcidev,unsigned int i;for (i =0 ; guids[i]; i++) { - ep =pmt_telem_find_and_register_endpoint (pcidev, guids[i],0 ); + ep =pmt_telem_find_and_register_endpoint (&pcidev->dev, guids[i],0 );if (!IS_ERR (ep))return ep; }
@@ -1575,7 +1575,7 @@ static int pmc_core_get_telem_info(struct pmc_dev *pmcdev, struct pmc_dev_info *if (!pmc->map->lpm_req_guid)return -ENXIO ; - ep =pmt_telem_find_and_register_endpoint (pcidev, pmc->map->lpm_req_guid,0 ); + ep =pmt_telem_find_and_register_endpoint (&pcidev->dev, pmc->map->lpm_req_guid,0 );if (IS_ERR (ep)) {dev_dbg (&pmcdev->pdev->dev,"couldn't get telem endpoint %pe" , ep);return -EPROBE_DEFER ;
drivers/platform/x86/intel/pmc/ssram_telemetry.c +1 -1
@@ -60,7 +60,7 @@ pmc_ssram_telemetry_add_pmt(struct pci_dev *pcidev, u64 ssram_base, void __iomem info.base_addr = ssram_base; info.parent = &pcidev->dev; -return intel_vsec_register (pcidev, &info); +return intel_vsec_register (&pcidev->dev, &info); }static inline u64 get_base (void __iomem *addr,u32 offset)
drivers/platform/x86/intel/pmt/class.c +4 -4
@@ -60,11 +60,11 @@ pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count)return count; } -int pmt_telem_read_mmio (struct pci_dev *pdev,struct pmt_callbacks *cb,u32 guid,void *buf, +int pmt_telem_read_mmio (struct device *dev,struct pmt_callbacks *cb,u32 guid,void *buf,void __iomem *addr,loff_t off,u32 count) {if (cb && cb->read_telem) -return cb->read_telem (pdev, guid, buf, off, count); +return cb->read_telem (dev, guid, buf, off, count); addr += off;
@@ -99,7 +99,7 @@ intel_pmt_read(struct file *filp, struct kobject *kobj,if (count > entry->size - off) count = entry->size - off; - count =pmt_telem_read_mmio (entry->pcidev, entry->cb, entry->header.guid, buf, + count =pmt_telem_read_mmio (entry->ep->dev, entry->cb, entry->header.guid, buf, entry->base, off, count);return count;
@@ -208,7 +208,7 @@ static int intel_pmt_populate_entry(struct intel_pmt_entry *entry,struct intel_vsec_device *ivdev, struct resource *disc_res) { - struct pci_dev *pci_dev = ivdev->pcidev; + struct pci_dev *pci_dev = to_pci_dev(ivdev->dev);struct device *dev = &ivdev->auxdev.dev;struct intel_pmt_header *header = &entry->header;u8 bir;
drivers/platform/x86/intel/pmt/class.h +3 -2
@@ -19,11 +19,12 @@#define GET_BIR (v) ((v) & GENMASK(2, 0))#define GET_ADDRESS (v) ((v) & GENMASK(31, 3)) +struct device ;struct pci_dev ;extern struct class intel_pmt_class;struct telem_endpoint { -struct pci_dev *pcidev; +struct device *dev;struct telem_header header;struct pmt_callbacks *cb;void __iomem *base;
@@ -65,7 +66,7 @@ struct intel_pmt_namespace { struct intel_pmt_entry *entry); }; -int pmt_telem_read_mmio (struct pci_dev *pdev,struct pmt_callbacks *cb,u32 guid,void *buf, +int pmt_telem_read_mmio (struct device *dev,struct pmt_callbacks *cb,u32 guid,void *buf,void __iomem *addr,loff_t off,u32 count);bool intel_pmt_is_early_client_hw (struct device *dev); int intel_pmt_dev_create(struct intel_pmt_entry *entry,
drivers/platform/x86/intel/pmt/discovery.c +2 -2
@@ -542,7 +542,7 @@ static int pmt_features_probe(struct auxiliary_device *auxdev, const struct auxiif (!priv)return -ENOMEM ; - priv->parent = &ivdev->pcidev->dev; + priv->parent = ivdev->dev;auxiliary_set_drvdata (auxdev, priv); priv->dev = device_create(&intel_pmt_class, &auxdev->dev, MKDEV(0, 0), priv,
@@ -609,7 +609,7 @@ void intel_pmt_get_features(struct intel_pmt_entry *entry)mutex_lock (&feature_list_lock);list_for_each_entry (feature, &pmt_feature_list, list) { -if (feature->priv->parent != &entry->ep->pcidev->dev) +if (feature->priv->parent != entry->ep->dev)continue ;pmt_get_features (entry, feature);
drivers/platform/x86/intel/pmt/telemetry.c +7 -6
@@ -112,7 +112,7 @@ static int pmt_telem_add_endpoint(struct intel_vsec_device *ivdev,return -ENOMEM ; ep = entry->ep; - ep->pcidev = ivdev->pcidev; + ep->dev = ivdev->dev; ep->header.access_type = entry->header.access_type; ep->header.guid = entry->header.guid; ep->header.base_offset = entry->header.base_offset;
@@ -204,7 +204,7 @@ int pmt_telem_get_endpoint_info(int devid, struct telem_endpoint_info *info) goto unlock; } - info->pdev = entry->ep->pcidev; + info->dev = entry->ep->dev; info->header = entry->ep->header; unlock:
@@ -218,9 +218,10 @@ static int pmt_copy_region(struct telemetry_region *region, struct intel_pmt_entry *entry) { +struct pci_dev *pdev =to_pci_dev (entry->ep->dev);struct oobmsm_plat_info *plat_info; - plat_info =intel_vsec_get_mapping (entry->ep->pcidev); + plat_info =intel_vsec_get_mapping (pdev);if (IS_ERR (plat_info))return PTR_ERR (plat_info);
@@ -308,7 +309,7 @@ int pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, u32 count)if (offset +NUM_BYTES_QWORD (count) > size)return -EINVAL ; -pmt_telem_read_mmio (ep->pcidev, ep->cb, ep->header.guid, data, ep->base, offset, +pmt_telem_read_mmio (ep->dev, ep->cb, ep->header.guid, data, ep->base, offset,NUM_BYTES_QWORD (count));return ep->present ?0 : -EPIPE ;
@@ -335,7 +336,7 @@ int pmt_telem_read32(struct telem_endpoint *ep, u32 id, u32 *data, u32 count)EXPORT_SYMBOL_NS_GPL (pmt_telem_read32,"INTEL_PMT_TELEMETRY" );struct telem_endpoint * -pmt_telem_find_and_register_endpoint (struct pci_dev *pcidev,u32 guid,u16 pos) +pmt_telem_find_and_register_endpoint (struct device *dev,u32 guid,u16 pos) {int devid =0 ;int inst =0 ;
@@ -348,7 +349,7 @@ pmt_telem_find_and_register_endpoint(struct pci_dev *pcidev, u32 guid, u16 pos)if (err)return ERR_PTR (err); -if (ep_info.header.guid == guid && ep_info.pdev == pcidev) { +if (ep_info.header.guid == guid && ep_info.dev == dev) {if (inst == pos)return pmt_telem_register_endpoint (devid); ++inst;
drivers/platform/x86/intel/pmt/telemetry.h +6 -6
@@ -6,8 +6,8 @@#define PMT_TELEM_TELEMETRY 0#define PMT_TELEM_CRASHLOG 1 +struct device ;struct telem_endpoint ; -struct pci_dev ;struct telem_header {u8 access_type;
@@ -17,7 +17,7 @@ struct telem_header { };struct telem_endpoint_info { -struct pci_dev *pdev; +struct device *dev;struct telem_header header; };
@@ -71,8 +71,8 @@ int pmt_telem_get_endpoint_info(int devid, struct telem_endpoint_info *info);/** * pmt_telem_find_and_register_endpoint() - Get a telemetry endpoint from -* pci_dev device, guid and pos -* @pdev: PCI device inside the Intel vsec +* device, guid and pos +* @dev: device inside the Intel vsec * @guid: GUID of the telemetry space * @pos: Instance of the guid *
@@ -80,8 +80,8 @@ int pmt_telem_get_endpoint_info(int devid, struct telem_endpoint_info *info);* * endpoint - On success returns pointer to the telemetry endpoint * * -ENXIO - telemetry endpoint not found */ -struct telem_endpoint *pmt_telem_find_and_register_endpoint (struct pci_dev *pcidev, -u32 guid,u16 pos); +struct telem_endpoint * +pmt_telem_find_and_register_endpoint (struct device *dev,u32 guid,u16 pos);/** * pmt_telem_read() - Read qwords from counter sram using sample id
drivers/platform/x86/intel/sdsi.c +3 -2
@@ -599,13 +599,14 @@ static int sdsi_get_layout(struct sdsi_priv *priv, struct disc_table *table)return 0 ; } -static int sdsi_map_mbox_registers (struct sdsi_priv *priv,struct pci_dev *parent, +static int sdsi_map_mbox_registers (struct sdsi_priv *priv,struct device *dev,struct disc_table *disc_table,struct resource *disc_res) {u32 access_type =FIELD_GET (DT_ACCESS_TYPE , disc_table->access_info);u32 size =FIELD_GET (DT_SIZE , disc_table->access_info);u32 tbir =FIELD_GET (DT_TBIR , disc_table->offset);u32 offset =DT_OFFSET (disc_table->offset); +struct pci_dev *parent =to_pci_dev (dev);struct resource res = {};/* Starting location of SDSi MMIO region based on access type */
@@ -681,7 +682,7 @@ static int sdsi_probe(struct auxiliary_device *auxdev, const struct auxiliary_dereturn ret;/* Map the SDSi mailbox registers */ - ret =sdsi_map_mbox_registers (priv, intel_cap_dev->pcidev, &disc_table, disc_res); + ret =sdsi_map_mbox_registers (priv, intel_cap_dev->dev, &disc_table, disc_res);if (ret)return ret;
drivers/platform/x86/intel/vsec.c +26 -18
148 lines not on this page · raw message
drivers/platform/x86/intel/vsec_tpmi.c +3 -3
@@ -530,7 +530,7 @@ static const struct file_operations mem_write_ops = { .release = single_release, }; -#define tpmi_to_dev (info) (&info->vsec_dev->pcidev->dev) +#define tpmi_to_dev (info) ((info)->vsec_dev->dev)static void tpmi_dbgfs_register (struct intel_tpmi_info *tpmi_info) {
@@ -642,7 +642,7 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, tmp->flags =IORESOURCE_MEM ; } - feature_vsec_dev->pcidev = vsec_dev->pcidev; + feature_vsec_dev->dev = vsec_dev->dev; feature_vsec_dev->resource = res; feature_vsec_dev->num_resources = pfs->pfs_header.num_entries; feature_vsec_dev->priv_data = &tpmi_info->plat_info;
@@ -742,7 +742,7 @@ static int tpmi_fetch_pfs_header(struct intel_tpmi_pm_feature *pfs, u64 start, istatic int intel_vsec_tpmi_init (struct auxiliary_device *auxdev) {struct intel_vsec_device *vsec_dev =auxdev_to_ivdev (auxdev); -struct pci_dev *pci_dev = vsec_dev->pcidev; +struct pci_dev *pci_dev =to_pci_dev (vsec_dev->dev);struct intel_tpmi_info *tpmi_info;u64 pfs_start =0 ;int ret, i;
include/linux/intel_vsec.h +7 -6
@@ -29,6 +29,7 @@#define INTEL_DVSEC_TABLE_OFFSET (x) ((x) & GENMASK(31, 3))#define TABLE_OFFSET_SHIFT 3 +struct device ;struct pci_dev ;struct resource ;
@@ -82,14 +83,14 @@ enum intel_vsec_quirks {* struct pmt_callbacks - Callback infrastructure for PMT devices * @read_telem: when specified, called by client driver to access PMT * data (instead of direct copy). -* * pdev: PCI device reference for the callback's use +* * dev: device reference for the callback's use * * guid: ID of data to acccss * * data: buffer for the data to be copied * * off: offset into the requested buffer * * count: size of buffer */ struct pmt_callbacks { -int (*read_telem)(struct pci_dev *pdev,u32 guid,u64 *data,loff_t off,u32 count); +int (*read_telem)(struct device *dev,u32 guid,u64 *data,loff_t off,u32 count); };struct vsec_feature_dependency {
@@ -122,7 +123,7 @@ struct intel_vsec_platform_info {/** * struct intel_vsec_device - Auxbus specific device information * @auxdev: auxbus device struct for auxbus access -* @pcidev: pci device associated with the device +* @dev: struct device associated with the device * @resource: any resources shared by the parent * @ida: id reference * @num_resources: number of resources
@@ -135,7 +136,7 @@ struct intel_vsec_platform_info {*/ struct intel_vsec_device {struct auxiliary_device auxdev; -struct pci_dev *pcidev; +struct device *dev;struct resource *resource;struct ida *ida;int num_resources;
@@ -199,13 +200,13 @@ static inline struct intel_vsec_device *auxdev_to_ivdev(struct auxiliary_device }#if IS_ENABLED (CONFIG_INTEL_VSEC ) -int intel_vsec_register (struct pci_dev *pdev, +int intel_vsec_register (struct device *dev,const struct intel_vsec_platform_info *info);int intel_vsec_set_mapping (struct oobmsm_plat_info *plat_info,struct intel_vsec_device *vsec_dev);struct oobmsm_plat_info *intel_vsec_get_mapping (struct pci_dev *pdev);#else -static inline int intel_vsec_register (struct pci_dev *pdev, +static inline int intel_vsec_register (struct device *dev,const struct intel_vsec_platform_info *info) {return -ENODEV ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 686/1611 platform/x86/intel/vsec: Return real error codes from registration path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David E. Box <[email protected]>
[ Upstream commit a6ce8bf3c993d8c2e8a6aeb2596429c101fe4462 ]
Stop collapsing registration results into booleans. Make intel_vsec_walk_header() return int and propagate the first non-zero error from intel_vsec_register_device(). intel_vsec_register() now returns that error directly and 0 on success.
This preserves success behavior while surfacing meaningful errors instead of hiding them behind a bool/-ENODEV, which makes debugging and probe ordering issues clearer.
Stable-dep-of: 375bbbbd112a ("platform/x86/intel/vsec: Restore BAR fallback for header walk")
--- drivers/platform/x86/intel/vsec.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/platform/x86/intel/vsec.c +6 -10
@@ -461,20 +461,19 @@ static int intel_vsec_register_device(struct device *dev,return -EAGAIN ; } -static bool intel_vsec_walk_header (struct device *dev, -const struct intel_vsec_platform_info *info) +static int intel_vsec_walk_header (struct device *dev, +const struct intel_vsec_platform_info *info) {struct intel_vsec_header **header = info->headers; -bool have_devices = false;int ret;for ( ; *header; header++) { ret =intel_vsec_register_device (dev, *header, info, info->base_addr); -if (!ret) - have_devices = true; +if (ret) +return ret; } -return have_devices; +return 0 ; } static bool intel_vsec_walk_dvsec(struct pci_dev *pdev,
@@ -580,10 +579,7 @@ int intel_vsec_register(struct device *dev,if (!dev || !info || !info->headers)return -EINVAL ; -if (!intel_vsec_walk_header (dev, info)) -return -ENODEV ; -else -return 0 ; +return intel_vsec_walk_header (dev, info); }EXPORT_SYMBOL_NS_GPL (intel_vsec_register,"INTEL_VSEC" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 687/1611 platform/x86/intel/vsec: Restore BAR fallback for header walk
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David E. Box <[email protected]>
[ Upstream commit 375bbbbd112af028ee0b45d833a6233c23d19bbf ]
The base_addr refactor changed intel_vsec_walk_header() to pass info->base_addr as the discovery-table base address. For the PCI VSEC driver this info comes from driver_data, but exported callers may provide their own static headers and leave base_addr unset.
For xe, this made the discovery-table base address zero instead of the BAR selected by header->tbir, preventing PMT endpoints from being created.
Restore the previous behavior for the header-walk path by falling back to pci_resource_start(pdev, header->tbir) when base_addr is not specified. Keep explicit base_addr override behavior unchanged.
This preserves the refactor structure while fixing the functional regression in manual-header users.
--- drivers/platform/x86/intel/vsec.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/vsec.c +16 -1
@@ -465,10 +465,25 @@ static int intel_vsec_walk_header(struct device *dev, const struct intel_vsec_platform_info *info) {struct intel_vsec_header **header = info->headers; +u64 base_addr;int ret;for ( ; *header; header++) { - ret =intel_vsec_register_device (dev, *header, info, info->base_addr); +if (info->base_addr) { + base_addr = info->base_addr; + }else { +struct pci_dev *pdev; + +if (!dev_is_pci (dev)) { +dev_err (dev,"non-PCI device without a base address\n" ); +return -EINVAL ; + } + + pdev =to_pci_dev (dev); + base_addr =pci_resource_start (pdev, (*header)->tbir); + } + + ret =intel_vsec_register_device (dev, *header, info, base_addr);if (ret)return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 688/1611 perf tools: Fix get_max_num() size_t underflow on empty sysfs file
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 0a012113bb3a44482c163f16f4db03ccaa37a339 ]
get_max_num() reads a sysfs file (cpu/possible, cpu/present, or node/possible) and scans backward from the end to find the last number. If the file is empty, filename__read_str() returns num == 0. The loop while (--num) decrements the size_t from 0 to SIZE_MAX, reading backward across the heap until a comma or hyphen is found or unmapped memory is hit.
Add an early return for empty files before the backward scan.
--- tools/perf/util/cpumap.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/cpumap.c +6 -0
@@ -420,6 +420,12 @@ static int get_max_num(char *path, int *max) buf[num] ='\0' ; +/* empty file — nothing to parse */ +if (num ==0 ) { + err =-1 ; + goto out; + } +/* start on the right, to find highest node num */ while (--num) {if ((buf[num] ==',' ) || (buf[num] =='-' )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 689/1611 perf tools: Use scnprintf() in cpu_map__snprint() to prevent overflow
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 7953a3a9b8e02e98c6e6958f291d0ae22393e46a ]
cpu_map__snprint() accumulates snprintf() return values in ret. snprintf() returns the number of characters that *would have been written* on truncation, not the actual count. When a fragmented CPU list exceeds the buffer, ret grows past size, causing size - ret to underflow (both are size_t), and subsequent snprintf() calls write past the end of the caller's stack buffer.
Switch to scnprintf() which returns the actual number of characters written, making ret accumulation safe by construction.
--- tools/perf/util/cpumap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
tools/perf/util/cpumap.c +9 -9
@@ -664,21 +664,21 @@ size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size)if (start ==-1 ) { start = i;if (last) { - ret +=snprintf (buf + ret, size - ret, -"%s%d" ,COMMA , -perf_cpu_map__cpu (map, i).cpu); + ret +=scnprintf (buf + ret, size - ret, +"%s%d" ,COMMA , +perf_cpu_map__cpu (map, i).cpu); } }else if (((i - start) != (cpu.cpu -perf_cpu_map__cpu (map, start).cpu)) || last) {int end = i -1 ;if (start == end) { - ret +=snprintf (buf + ret, size - ret, -"%s%d" ,COMMA , -perf_cpu_map__cpu (map, start).cpu); + ret +=scnprintf (buf + ret, size - ret, +"%s%d" ,COMMA , +perf_cpu_map__cpu (map, start).cpu); }else { - ret +=snprintf (buf + ret, size - ret, -"%s%d-%d" ,COMMA , -perf_cpu_map__cpu (map, start).cpu,perf_cpu_map__cpu (map, end).cpu); + ret +=scnprintf (buf + ret, size - ret, +"%s%d-%d" ,COMMA , +perf_cpu_map__cpu (map, start).cpu,perf_cpu_map__cpu (map, end).cpu); } first = false; start = i;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 690/1611 perf tools: Use perf_env__get_cpu_topology() in machine__resolve()
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 5484b43a0ec8231c36fba6ead654cb72dbba8b8f ]
machine__resolve() accesses env->cpu[al->cpu].socket_id after checking al->cpu >= 0 and env->cpu != NULL, but without validating al->cpu against env->nr_cpus_avail. Since al->cpu comes from the untrusted perf.data sample, a crafted file with a large CPU index causes an out-of-bounds heap read.
Use perf_env__get_cpu_topology() which validates both NULL and bounds. Also bounds-check al->cpu before the cast to struct perf_cpu (int16_t):
without this, values like 65536 silently truncate to 0, bypassing the accessor's internal check and returning CPU 0's topology.
--- tools/perf/util/event.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/event.c +13 -2
@@ -15,6 +15,7 @@#include <linux/zalloc.h> #include "cpumap.h" #include "dso.h" +#include "env.h" #include "event.h" #include "debug.h" #include "hist.h"
@@ -786,8 +787,18 @@ int machine__resolve(struct machine *machine, struct addr_location *al,if (al->cpu >=0 ) {struct perf_env *env = machine->env; -if (env && env->cpu) - al->socket = env->cpu[al->cpu].socket_id; +/* +* Bounds-check al->cpu (s32) before casting to struct perf_cpu +* (int16_t): without this, e.g. 65536 truncates to 0 and silently +* returns CPU 0's topology. Can go once perf_cpu.cpu is widened. +*/ +if (env && al->cpu < env->nr_cpus_avail) { +struct cpu_topology_map *topo; + + topo =perf_env__get_cpu_topology (env, (struct perf_cpu ){ al->cpu }); +if (topo) + al->socket = topo->socket_id; + } }/* Account for possible out-of-order switch events. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 691/1611 PCI: rcar-host: Remove unused LIST_HEAD(res)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
[ Upstream commit 6ba90ce2069ae923b0ec787aebdf2d786e5d2a58 ]
Remove the unused LIST_HEAD(res) declaration from rcar_pcie_hw_enable().
The macro instantiation defines an unused 'struct list_head res' variable, which conflicts with a valid resource loop-local 'struct resource *res' declaration further down in the function, triggering a compiler variable shadowing warning:
drivers/pci/controller/pcie-rcar-host.c:357:34: warning: declaration of 'res' shadows a previous local [-Wshadow]
357 | struct resource *res = win->res;
--- drivers/pci/controller/pcie-rcar-host.c | 1 - 1 file changed, 1 deletion(-)
drivers/pci/controller/pcie-rcar-host.c +0 -1
@@ -346,7 +346,6 @@ static void rcar_pcie_hw_enable(struct rcar_pcie_host *host)struct rcar_pcie *pcie = &host->pcie;struct pci_host_bridge *bridge =pci_host_bridge_from_priv (host);struct resource_entry *win; -LIST_HEAD (res);int i =0 ;/* Try setting 5 GT/s link speed */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 692/1611 perf sched: Bounds-check prio before test_bit() in timehist
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 4477dc01fcfc7f404772a67e0c1e056541ceb61d ]
timehist_skip_sample() reads prio from untrusted tracepoint data via perf_sample__intval(sample, "prev_prio") without bounds validation. A crafted perf.data with prev_prio >= MAX_PRIO (140) causes test_bit() to read past the end of the prio_bitmap, which is only MAX_PRIO bits.
Add a prio >= 0 guard before the test_bit() call and skip out-of-range values (>= MAX_PRIO) that can never match the user's filter set.
The original prio != -1 already let all negatives other than -1 through (after an undefined-behavior bitmap read); the new prio >= 0 guard preserves that pass-through behavior — negative means "no priority info", so the event is shown unfiltered — while fixing the OOB. Values >= MAX_PRIO are skipped because they cannot be represented in the filter bitmap.
--- tools/perf/builtin-sched.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-sched.c +3 -1
@@ -2631,7 +2631,9 @@ static bool timehist_skip_sample(struct perf_sched *sched,else if (evsel__name_is (evsel,"sched:sched_switch" )) prio =evsel__intval (evsel, sample,"prev_prio" ); -if (prio !=-1 && !test_bit (prio, sched->prio_bitmap)) { +/* negative prio means no info; out-of-range prio can't match the filter */ +if (prio >=0 && + (prio >=MAX_PRIO || !test_bit (prio, sched->prio_bitmap))) { rc = true; sched->skipped_samples++; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 693/1611 perf sched: Fix idle-hist callchain display using wrong rb_first variant
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 d9b99dc8148e0c1f5da3942131b47e0d21187a32 ]
timehist_print_idlehist_callchain() calls rb_first_cached() on sorted_root, but the sort function (callchain_param.sort) populates it via rb_insert_color() on the plain rb_root member — not the cached variant. This means rb_leftmost is never set, so rb_first_cached() always returns NULL and the entire callchain summary is silently dropped from --idle-hist output.
The original code in ba957ebb54893aca ("perf sched timehist: Show callchains for idle stat") was correct — it used struct rb_root and rb_first(). The bug was introduced when sorted_root was converted to rb_root_cached without converting the sort insertion path to use rb_insert_color_cached().
Use rb_first(&root->rb_root) to match how the tree was populated.
--- tools/perf/builtin-sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-sched.c +2 -1
@@ -3111,7 +3111,8 @@ static size_t timehist_print_idlehist_callchain(struct rb_root_cached *root)size_t ret =0 ;FILE *fp = stdout;struct callchain_node *chain; -struct rb_node *rb_node =rb_first_cached (root); +/* sort() uses rb_insert_color() on rb_root, not rb_root_cached */ +struct rb_node *rb_node =rb_first (&root->rb_root);printf (" %16s %8s %s\n" ,"Idle time (msec)" ,"Count" ,"Callchains" ); printf(" %.16s %.8s %.50s\n", graph_dotted_line, graph_dotted_line,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 694/1611 perf bpf: Use scnprintf() in snprintf_hex() and synthesize_bpf_prog_name()
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 cab3a9331ed0b3f884dd61c8a25b3cf123705982 ]
Both functions accumulate formatted output via ret += snprintf(buf + ret, size - ret, ...). If the buffer is too small and snprintf() returns more than the remaining space, ret exceeds size and the next 'size - ret' underflows, causing snprintf() to write past the buffer end.
Switch to scnprintf() which returns the actual number of bytes written, making the accumulation safe.
--- tools/perf/util/bpf-event.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/util/bpf-event.c +6 -5
@@ -36,7 +36,7 @@ static int snprintf_hex(char *buf, size_t size, unsigned char *data, size_t len)size_t i;for (i =0 ; i < len; i++) - ret +=snprintf (buf + ret, size - ret,"%02x" , data[i]); + ret +=scnprintf (buf + ret, size - ret,"%02x" , data[i]);return ret; }
@@ -140,7 +140,7 @@ static int synthesize_bpf_prog_name(char *buf, int size,const struct btf_type *t;int name_len; - name_len =snprintf (buf, size,"bpf_prog_" ); + name_len =scnprintf (buf, size,"bpf_prog_" ); name_len +=snprintf_hex (buf + name_len, size - name_len, prog_tags[sub_id],BPF_TAG_SIZE );if (btf) {
@@ -153,9 +153,10 @@ static int synthesize_bpf_prog_name(char *buf, int size, short_name = info->name; }else short_name ="F" ; -if (short_name) - name_len +=snprintf (buf + name_len, size - name_len, -"_%s" , short_name); +if (short_name) { + name_len +=scnprintf (buf + name_len, size - name_len, +"_%s" , short_name); + }return name_len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 695/1611 perf hists: Fix snprintf() in hists__scnprintf_title() UID filter 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 227a8748742f0263f1fe3131449b44563b77a209 ]
hists__scnprintf_title() accumulates formatted output into a buffer using scnprintf() for all filter clauses except the UID filter, which uses snprintf(). If the buffer fills up and snprintf() returns more than the remaining space, printed exceeds size and the next 'size - printed' underflows, causing later scnprintf() calls to write past the buffer.
Switch the UID filter clause to scnprintf() to match the rest of the function.
--- tools/perf/util/hist.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/hist.c +4 -3
@@ -2960,9 +2960,10 @@ int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool sh ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events); -if (hists->uid_filter_str) - printed +=snprintf (bf + printed, size - printed, -", UID: %s" , hists->uid_filter_str); +if (hists->uid_filter_str) { + printed +=scnprintf (bf + printed, size - printed, +", UID: %s" , hists->uid_filter_str); + }if (thread) {if (hists__has (hists, thread)) { printed += scnprintf(bf + printed, size - printed,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 696/1611 xprtrdma: Fix ep kref imbalance on ADDR_CHANGE
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 af9b65b29af341932625c4283dc7a23cdb62688a ]
rpcrdma_cm_event_handler() falls through to the disconnected: label on RDMA_CM_EVENT_ADDR_CHANGE and calls rpcrdma_ep_put() with no matching get when the event arrives before RDMA_CM_EVENT_ESTABLISHED. The kref then underflows during connect teardown and rpcrdma_xprt_disconnect() operates on a freed ep.
Reference counts across a normal connection lifecycle:
rpcrdma_ep_create() kref_init ->1
rpcrdma_xprt_connect() ep_get ->2 (before post_recvs)
RDMA_CM_EVENT_ESTABLISHED ep_get ->3
RDMA_CM_EVENT_DISCONNECTED ep_put ->2
rpcrdma_xprt_drain() ep_put ->1
rpcrdma_xprt_disconnect() tail ep_put ->0 (ep_destroy)The connect-time get in rpcrdma_xprt_connect(), taken just before rpcrdma_post_recvs() "while there are outstanding Receives," is balanced by rpcrdma_xprt_drain. ADDR_CHANGE before ESTABLISHED has no get to consume, so its put drops the count to 1 and the drain put then frees the ep while rpcrdma_xprt_disconnect() still holds a pointer to it.
Fix by dispatching on the prior re_connect_status via xchg(): for prev == 0 (pre-ESTABLISHED) wake the connect waiter and return with no put; for prev == 1 call rpcrdma_force_disconnect() and return. The case-1 arm relies on the subsequent RDMA_CM_EVENT_DISCONNECTED event -- reliably delivered when rdma_disconnect() is called on a still-connected cm_id -- to balance the ESTABLISHED get; rpcrdma_xprt_drain() continues to balance only that connect-time get. Any other prior value means teardown is already in flight.
--- net/sunrpc/xprtrdma/verbs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/sunrpc/xprtrdma/verbs.c +11 -3
@@ -245,8 +245,17 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)complete (&ep->re_done);return 0 ;case RDMA_CM_EVENT_ADDR_CHANGE : - ep->re_connect_status = -ENODEV ; - goto disconnected; +switch (xchg (&ep->re_connect_status, -ENODEV )) { +case 0 : + goto wake_connect_worker; +case 1 : +/* The later DISCONNECTED event balances the +* ESTABLISHED get; do not put here. +*/ +rpcrdma_force_disconnect (ep); +return 0 ; + } +return 0 ;case RDMA_CM_EVENT_ESTABLISHED :rpcrdma_ep_get (ep); ep->re_connect_status =1 ;
@@ -269,7 +278,6 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)return 0 ;case RDMA_CM_EVENT_DISCONNECTED : ep->re_connect_status = -ECONNABORTED ; -disconnected:rpcrdma_force_disconnect (ep);return rpcrdma_ep_put (ep);default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 697/1611 xprtrdma: Initialize re_id before removal registration
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 bb7caa63e1db22fd03e8dc591b12169e99169dff ]
rpcrdma_create_id() registers ep->re_rn with the rpcrdma ib_client before returning the new rdma_cm_id to rpcrdma_ep_create(). However rpcrdma_ep_create() currently stores that pointer in ep->re_id only after rpcrdma_create_id() returns.
A local administrator can race an NFS/RDMA mount against RDMA device removal. If rpcrdma_remove_one() observes the just-registered notification before rpcrdma_ep_create() assigns ep->re_id, rpcrdma_ep_removal_done() calls trace_xprtrdma_device_removal(NULL). The tracepoint dereferences id->device->name and copies id->route.addr.dst_addr, so the callback can crash the kernel with a NULL pointer dereference.
Store the rdma_cm_id in ep->re_id immediately before publishing ep->re_rn. The existing error path still destroys the id directly if registration fails; ep is then freed by the caller without using ep->re_id. Remove the later duplicate assignment in rpcrdma_ep_create().
--- net/sunrpc/xprtrdma/verbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/xprtrdma/verbs.c +1 -1
@@ -334,6 +334,7 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt,if (rc) goto out; + ep->re_id = id; rc =rpcrdma_rn_register (id->device, &ep->re_rn, rpcrdma_ep_removal_done);if (rc) goto out;
@@ -406,7 +407,6 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) }__module_get (THIS_MODULE ); device = id->device; - ep->re_id = id;reinit_completion (&ep->re_done); ep->re_max_requests = r_xprt->rx_xprt.max_reqs;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 698/1611 xprtrdma: Check frwr_wp_create() during connect
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 0f13fc7c7d2e0427517e63c739277a4cd338b0c5 ]
frwr_wp_create() creates the singleton Memory Region used to encode padding for Write chunks whose payload length is not XDR-aligned. Its failure paths return a negative errno and leave ep->re_write_pad_mr set to NULL.
rpcrdma_xprt_connect() currently ignores that return value. If frwr_wp_create() fails after the rest of the connection setup succeeds, xprt_rdma_connect_worker() treats the connection attempt as successful and sets XPRT_CONNECTED. A later NFS/RDMA read with a non-4-byte-aligned receive page length reaches rpcrdma_encode_write_list(), passes the NULL write-pad MR to encode_rdma_segment(), and dereferences it.
This is locally triggerable on an NFS/RDMA client after a connect or reconnect hits a local MR allocation, DMA-map, MR-map, or post-send failure; a remote peer alone cannot force the local MR setup failure.
Check the return value and fail the connect as -ENOTCONN, matching the adjacent setup failures. This keeps XPRT_CONNECTED clear and lets the normal reconnect path retry.
--- net/sunrpc/xprtrdma/verbs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/verbs.c +11 -1
@@ -549,7 +549,17 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt) goto out; }rpcrdma_mrs_create (r_xprt); -frwr_wp_create (r_xprt); + +/* +* rpcrdma_encode_write_list() dereferences the write-pad +* MR with no NULL check, so fail the connect rather than +* publish a transport whose write-pad MR is NULL. +*/ + rc =frwr_wp_create (r_xprt); +if (rc) { + rc = -ENOTCONN ; + goto out; + } out:trace_xprtrdma_connect (r_xprt, rc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 699/1611 xprtrdma: Document and assert reply-handler invariants
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 797943e8bd1ffcc63bfe79d24faad9a77054ec40 ]
The xprtrdma reply path has been the subject of recurring LLM-driven review claims that 'an RPC can complete while receive buffers are still DMA-mapped' or that 'the req can be freed while the HCA still owns the send buffer.' No runtime reproducer has surfaced, but the absence of a written-down invariant set lets each pass of automated review reach the same hypothetical conclusion. Subsequent fixes against ce2f9a4d9ccc ('xprtrdma: Decouple req recycling from RPC completion') closed the underlying races but did not document the closure where future readers will look for it.
State the invariants explicitly in a comment above rpcrdma_reply_handler() and back four of them with WARN_ON_ONCE() probes positioned where each invariant is locally checkable on the previous patch's cleaned-up ownership state:
- I1 (Receive WR ownership): WARN at rpcrdma_post_recvs() that a rep pulled from rb_free_reps carries rr_rqst == NULL.
- I2 (rep attachment): WARN at rpcrdma_reply_put() that req->rl_reply was NULLed before the matching rep_put.
- I3 (Registered-MR fence): WARN at rpcrdma_complete_rqst() that req->rl_registered is empty. Strong send-queue ordering of the LocalInv WR chain makes the last completion observe the ib_dma_unmap_sg() of every earlier MR, so 'list empty' implies 'all MRs unmapped'.
- I4 (Send-buffer release): WARN at rpcrdma_req_release() that req->rl_sendctx is NULL. Reaching the kref release callback requires both the RPC-layer and Send-side references to have dropped; the Send-side drop runs in rpcrdma_sendctx_unmap(), which clears rl_sendctx (previous patch). A non-NULL rl_sendctx here would mean the Send-side owner had not run -- a contradiction.
The XXX comment in xprt_rdma_free() about signal-driven release racing the Send completion described the pre-decouple state. Replace it with a one-line note pointing at the invariant set, since the kref scheme now holds the req across the in-flight Send regardless of which path released the rpc_task.
I5 (req lifecycle) is stated in the comment but not probed:
making it locally assertible would require moving kref_init out of rpcrdma_req_release(), which in turn requires adding kref_init to the bc_pa_list and backlog-wake reuse paths. That restructuring is deferred -- the invariant is unchanged either way.
Stable-dep-of: 234c0ff695ef ("xprtrdma: Resize reply buffers before reposting receives")
--- net/sunrpc/xprtrdma/rpc_rdma.c | 69 +++++++++++++++++++++++++++++++++ net/sunrpc/xprtrdma/transport.c | 13 +++++-- net/sunrpc/xprtrdma/verbs.c | 6 +++ 3 files changed, 84 insertions(+), 4 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +69 -0
@@ -1381,6 +1381,11 @@ void rpcrdma_complete_rqst(struct rpcrdma_rep *rep)struct rpc_rqst *rqst = rep->rr_rqst;int status; +/* I3: every registered MR has been invalidated and +* ib_dma_unmap_sg()'d before complete_rqst runs. +*/ +WARN_ON_ONCE (!list_empty (&rpcr_to_rdmar (rqst)->rl_registered)); +switch (rep->rr_proc) {case rdma_msg: status =rpcrdma_decode_msg (r_xprt, rep, rqst);
@@ -1412,6 +1417,70 @@ void rpcrdma_complete_rqst(struct rpcrdma_rep *rep) goto out; } +/* Reply-side ownership invariants +* +* I1 (Receive WR ownership). A struct rpcrdma_rep is owned by the +* HCA between ib_post_recv() and the matching Receive completion. +* After ib_dma_sync_single_for_cpu() in rpcrdma_wc_receive() it is +* owned by the CPU until rpcrdma_rep_put() returns it to +* rb_free_reps; a rep on rb_free_reps is not re-posted until +* rpcrdma_post_recvs() pulls it off. Asserted: rpcrdma_post_recvs() +* WARNs that a pulled rep has rr_rqst == NULL. +* +* I2 (rep attachment). While req->rl_reply == rep, the rep cannot be +* re-posted. rpcrdma_reply_put() NULLs req->rl_reply before handing +* the rep to rpcrdma_rep_put(). Asserted: rpcrdma_reply_put() WARNs +* that rl_reply is NULL after the put. +* +* I3 (Registered-MR fence). On entry to rpcrdma_complete_rqst() every +* MR that was on req->rl_registered has had its rkey invalidated +* (remotely via IB_WC_WITH_INVALIDATE or locally via IB_WR_LOCAL_INV) +* and its pages ib_dma_unmap_sg()'d. The LocalInv chain is posted +* on a single QP; strong send-queue ordering makes the last +* completion (frwr_wc_localinv_done) observe the +* ib_dma_unmap_sg() that ran from each earlier completion's +* frwr_mr_put() before complete_rqst is called. The inline +* frwr_reminv() path unmaps its one MR synchronously before +* rpcrdma_reply_handler() reaches complete_rqst. Asserted: +* rpcrdma_complete_rqst() WARNs that rl_registered is empty. +* +* I4 (Send-buffer release). req->rl_kref carries two unconditional +* owners while a Send is outstanding: the RPC-layer reference (set +* at xprt_rdma_alloc_slot / xprt_rdma_bc_rqst_get / rpcrdma_req_release +* pool-entry) and the Send-side reference (kref_get() in +* rpcrdma_prepare_send_sges()). rpcrdma_req_release() runs only +* after both have dropped, so the req does not return to its free +* pool until rpcrdma_sendctx_unmap() has fired -- the HCA has +* released the send buffer before the req can be reused. Asserted: +* rpcrdma_req_release() WARNs that rl_sendctx is NULL. +* +* I5 (req lifecycle). A req is owned by the RPC layer between slot +* acquisition and the matching xprt_rdma_free_slot() (or, for the +* backchannel, xprt_rdma_bc_free_rqst()). While owned, rl_kref >= 1. +* The pools (rb_send_bufs, bc_pa_list, backlog wake target) never +* contain a req with outstanding Send-side or Reply-side work. +* +* Non-hazards. The following claims have been raised by adversarial +* review and are each closed by the invariants above: +* +* * "Reply completes the RPC while the HCA still holds the send +* buffer" -- excluded by I4. The Send-side kref reference is held +* until rpcrdma_sendctx_unmap() runs from Send completion. +* +* * "Signal-driven release races the in-flight Send" -- same +* resolution. xprt_rdma_free() does not touch rl_kref; the +* Send-side reference keeps the req out of its pool until Send +* completion fires. +* +* * "Receive completion races rep reuse" -- excluded by I1. A rep +* is on rb_free_reps only after rpcrdma_rep_put() has been called +* and rpcrdma_post_recvs() owns the next transition back to the HCA. +* +* * "Pages still DMA-mapped when call_decode reads them" -- excluded +* by I3. The matching ib_dma_unmap_sg() for every MR has run on +* the same CPU thread that calls rpcrdma_complete_rqst(). +*/ +/** * rpcrdma_reply_handler - Process received RPC/RDMA messages * @rep: Incoming rpcrdma_rep object to process
net/sunrpc/xprtrdma/transport.c +9 -4
@@ -509,6 +509,11 @@ static void rpcrdma_req_release(struct kref *kref)struct rpc_xprt *xprt = rqst->rq_xprt;struct rpcrdma_xprt *r_xprt; +/* I4: both the RPC-layer and Send-side owners have dropped, +* so rpcrdma_sendctx_unmap() has cleared rl_sendctx. +*/ +WARN_ON_ONCE (req->rl_sendctx); +kref_init (&req->rl_kref);#if defined(CONFIG_SUNRPC_BACKCHANNEL )
@@ -652,10 +657,10 @@ xprt_rdma_free(struct rpc_task *task)frwr_unmap_sync (rpcx_to_rdmax (rqst->rq_xprt), req); } -/* XXX: If the RPC is completing because of a signal and -* not because a reply was received, we ought to ensure -* that the Send completion has fired, so that memory -* involved with the Send is not still visible to the NIC. +/* The Send-side rl_kref owner keeps req out of its free pool +* until rpcrdma_sendctx_unmap() has fired -- see I4 above +* rpcrdma_reply_handler() -- so signal-driven release here +* does not let the HCA touch a recycled send buffer. */ }
net/sunrpc/xprtrdma/verbs.c +6 -0
@@ -1235,6 +1235,10 @@ void rpcrdma_reply_put(struct rpcrdma_buffer *buffers, struct rpcrdma_req *req)rpcrdma_rep_put (buffers, req->rl_reply); req->rl_reply =NULL ; } +/* I2: rl_reply NULL after the put closes the +* 'rep on rb_free_reps still referenced by req' window. +*/ +WARN_ON_ONCE (req->rl_reply); }/**
@@ -1411,6 +1415,8 @@ void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed) rep =rpcrdma_rep_create (r_xprt);if (!rep)break ; +/* I1: a rep on rb_free_reps must carry no rqst pointer. */ +WARN_ON_ONCE (rep->rr_rqst);if (!rpcrdma_regbuf_dma_map (r_xprt, rep->rr_rdmabuf)) {rpcrdma_rep_put (buf, rep);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 700/1611 xprtrdma: Resize reply buffers before reposting receives
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 234c0ff695ef3ffb656931000e6b823d0c2f30fd ]
Commit 0e13dd9ea8be ("xprtrdma: Remove temp allocation of rpcrdma_rep objects") made rpcrdma_rep objects survive disconnects. That is normally fine, but it also means their receive regbufs keep the size they had when they were first allocated.
Each rep's receive buffer is sized to ep->re_inline_recv when the rep is created. rpcrdma_ep_create() resets that threshold to the rdma_max_inline_read ceiling for every new endpoint, and the connect handshake then shrinks it to the peer's advertised inline send size. A rep allocated under a smaller negotiated threshold keeps that size:
on disconnect, rpcrdma_xprt_disconnect() drains and DMA-unmaps the surviving reps but does not free or resize them.
The threshold can come back larger on the next connection. The first peer may supply no RPC-over-RDMA CM private data, defaulting its send size to 1024, while the reconnect target is an ordinary server offering 4096; or, with rdma_max_inline_read raised above its default, the reconnect target may advertise a larger svcrdma_max_req_size than the first. rpcrdma_post_recvs() then reposts a surviving rep whose SGE length is still the old, smaller value, and a larger inline Reply hits a receive length error and forces another disconnect.
The undersized rep returns to the free list when its failed Receive flushes, so the following reconnect reposts the same rep and fails the same way. The transport flaps without making forward progress for as long as the peer keeps advertising the larger inline size.
This is local/admin-triggerable rather than remote-triggerable: a local administrator must create and maintain the NFS/RDMA mount, while the server or reconnect target has to advertise a larger inline send size and return a reply that uses it.
Fix this by checking each rep before it is reposted. If the receive regbuf is smaller than the current endpoint's inline receive size, reallocate it on the current RDMA device's NUMA node and reinitialize the rep's xdr_buf before DMA-mapping and posting the Receive WR.
--- net/sunrpc/xprtrdma/verbs.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/verbs.c +30 -1
@@ -81,6 +81,8 @@ rpcrdma_regbuf_alloc_node(size_t size, enum dma_data_direction direction, int node);static struct rpcrdma_regbuf *rpcrdma_regbuf_alloc (size_t size,enum dma_data_direction direction); +static bool rpcrdma_regbuf_realloc_node (struct rpcrdma_regbuf *rb, +size_t size,gfp_t flags,int node);static void rpcrdma_regbuf_dma_unmap (struct rpcrdma_regbuf *rb);static void rpcrdma_regbuf_free (struct rpcrdma_regbuf *rb);
@@ -1319,10 +1321,16 @@ rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction)* returned, @rb is left untouched. */ bool rpcrdma_regbuf_realloc (struct rpcrdma_regbuf *rb,size_t size,gfp_t flags) +{ +return rpcrdma_regbuf_realloc_node (rb, size, flags,NUMA_NO_NODE ); +} + +static bool rpcrdma_regbuf_realloc_node (struct rpcrdma_regbuf *rb, +size_t size,gfp_t flags,int node) {void *buf; - buf =kmalloc (size, flags); + buf =kmalloc_node (size, flags, node);if (!buf)return false;
@@ -1334,6 +1342,23 @@ bool rpcrdma_regbuf_realloc(struct rpcrdma_regbuf *rb, size_t size, gfp_t flags)return true; } +static bool rpcrdma_rep_resize (struct rpcrdma_xprt *r_xprt, +struct rpcrdma_rep *rep) +{ +struct rpcrdma_regbuf *rb = rep->rr_rdmabuf; +struct rpcrdma_ep *ep = r_xprt->rx_ep; +size_t size = ep->re_inline_recv; + +if (likely (rdmab_length (rb) >= size)) +return true; +if (!rpcrdma_regbuf_realloc_node (rb, size,XPRTRDMA_GFP_FLAGS , +ibdev_to_node (ep->re_id->device))) +return false; + +xdr_buf_init (&rep->rr_hdrbuf,rdmab_data (rb),rdmab_length (rb)); +return true; +} +/** * __rpcrdma_regbuf_dma_map - DMA-map a regbuf * @r_xprt: controlling transport instance
@@ -1417,6 +1442,10 @@ void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed)break ;/* I1: a rep on rb_free_reps must carry no rqst pointer. */ WARN_ON_ONCE (rep->rr_rqst); +if (!rpcrdma_rep_resize (r_xprt, rep)) { +rpcrdma_rep_put (buf, rep); +break ; + }if (!rpcrdma_regbuf_dma_map (r_xprt, rep->rr_rdmabuf)) {rpcrdma_rep_put (buf, rep);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 701/1611 xprtrdma: Fix bcall rep leak and unbounded peek
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 c7653d5cebc8492c77ec0415b5e9c0fb3e644bc6 ]
rpcrdma_is_bcall() decodes a reply's first words to decide whether the frame is a backchannel call. Two issues in that decode path let a short or malformed reply leak the receive buffer and drain the Receive queue.
First, the speculative peek
p = xdr_inline_decode(xdr, 0);
/* five p++ reads follow */asks xdr_inline_decode() for zero bytes, which returns xdr->p without consulting xdr->end. The five subsequent __be32 reads can then walk up to 20 bytes past the wire payload into stale regbuf contents and misclassify the reply as a backchannel call.
Second, after the post-peek
p = xdr_inline_decode(xdr, 3 * sizeof(*p));
if (unlikely(!p))
return true;the short-header arm returns true without calling rpcrdma_bc_receive_call(). The contract with the caller is that a true return transfers ownership of rep to the backchannel path:
rpcrdma_reply_handler()
if (rpcrdma_is_bcall(r_xprt, rep))
return; /* bare return, skips out_post */
...
out_post:
rpcrdma_post_recvs(r_xprt, credits + ...);
Because rpcrdma_bc_receive_call() never ran, no one took rep, but rpcrdma_reply_handler still bare-returns past rpcrdma_rep_put() and rpcrdma_post_recvs(). The rep, with its persistently DMA-mapped receive buffer, is orphaned on rb_all_reps and freed only at transport teardown. This completion reposts nothing, so its slot is reclaimed only when a later forward-channel reply reaches out_post and rpcrdma_post_recvs() allocates a fresh rep to backfill; absent that traffic the Receive queue drains and the peer's Sends draw RNR NAKs.
Fix by consulting xdr->end after the zero-length peek so the five __be32 reads cannot run unless 20 bytes of wire payload remain. A byte-precise comparison against xdr->end is required because a non-4-aligned receive rounds the stream's word count up past the true payload. Also return false from the short-header arm so the reply falls through the normal out_norqst cleanup chain (rpcrdma_rep_put() plus rpcrdma_post_recvs()).
--- net/sunrpc/xprtrdma/rpc_rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/rpc_rdma.c +3 -1
@@ -1133,6 +1133,8 @@ rpcrdma_is_bcall(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep)/* Peek at stream contents without advancing. */ p =xdr_inline_decode (xdr,0 ); +if ((char *)xdr->end - (char *)p <5 *XDR_UNIT ) +return false;/* Chunk lists */ if (xdr_item_is_present (p++))
@@ -1157,7 +1159,7 @@ rpcrdma_is_bcall(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep)*/ p =xdr_inline_decode (xdr,3 *sizeof (*p));if (unlikely (!p)) -return true; +return false;rpcrdma_bc_receive_call (r_xprt, rep);return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 702/1611 xprtrdma: Sanitize the reply credit grant after parsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c3a628aab2dc8f5fd7bff86ceaeae64de590e60a ]
The out_norqst exit in rpcrdma_reply_handler() branches away before the credit clamp, so a reply that matches no pending request reaches out_post carrying the raw credit value parsed from the wire. rpcrdma_post_recvs() does not bound its @needed argument: the refill loop allocates and chains Receive WRs until the count is satisfied or allocation fails. A peer that sends a well-formed reply carrying an unknown XID and an inflated credit grant therefore drives rep allocation and Receive posting past re_max_requests on every such reply.
Move the clamp to immediately after the credit field is parsed, ahead of the first branch that can reach out_post, so every later consumer sees a sanitized value. The cwnd update stays on the matched-request path.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +8 -4
@@ -1517,6 +1517,14 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep) credits =be32_to_cpu (*p++); rep->rr_proc = *p++; +/* The credit grant from the wire is not trustworthy; +* sanitize it before any code path consumes it. +*/ +if (credits ==0 ) + credits =1 ;/* don't deadlock */ +else if (credits > r_xprt->rx_ep->re_max_requests) + credits = r_xprt->rx_ep->re_max_requests; +if (rep->rr_vers != rpcrdma_version) goto out_badversion;
@@ -1533,10 +1541,6 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)xprt_pin_rqst (rqst);spin_unlock (&xprt->queue_lock); -if (credits ==0 ) - credits =1 ;/* don't deadlock */ -else if (credits > r_xprt->rx_ep->re_max_requests) - credits = r_xprt->rx_ep->re_max_requests;if (buf->rb_credits != credits)rpcrdma_update_cwnd (r_xprt, credits);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 703/1611 xprtrdma: Repost Receive buffers for malformed replies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit abc011ddaf1617e3e82d8a1e87daa7ddbfb9bac5 ]
rpcrdma_wc_receive() decrements the transport's Receive count for every completion before it dispatches a successful Receive to rpcrdma_reply_handler(). The handler must post a replacement Receive WR before returning unless ownership of the rep has moved elsewhere, as on the backchannel path.
Commit 2ae50ad68cd7 ("xprtrdma: Close window between waking RPC senders and posting Receives") moved the Receive refill out of rpcrdma_wc_receive(), where it had run ahead of every reply, into rpcrdma_reply_handler() so that the responder's credit grant could be parsed before reposting. The bad-version and short-reply exits never reach that refill: they recycle the rep and return without calling rpcrdma_post_recvs().
A remote peer can therefore drain the client's posted Receive queue by sending a sustained stream of replies that are shorter than the fixed transport header or that carry an unrecognized RPC/RDMA version. Each such reply consumes one posted Receive without replacing it. Once the queue empties, the peer's next Send finds no posted Receive and the transport stalls until reconnect.
Route both malformed-reply exits through the shared repost tail after recycling the rep, refilling against buf->rb_credits, the most recent accepted credit grant. Neither exit updates the congestion window, so RPCs admitted under the previous grant remain in flight awaiting replies. A smaller refill target would let a stream of malformed replies ratchet the posted Receive count down to the batch floor while the congestion window still admits rb_credits RPCs; a burst of valid replies to those RPCs could then overrun the posted Receives, and because the client connects with rnr_retry_count of zero, a single RNR NAK terminates the connection. Refilling against rb_credits also restores the target that applied to malformed replies before commit 2ae50ad68cd7 ("xprtrdma: Close window between waking RPC senders and posting Receives") when rpcrdma_post_recvs() computed it from rb_credits internally. rb_credits is at least one from connection establishment onward, so the repost path always keeps Receives posted.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +5 -3
@@ -1573,11 +1573,13 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep) out_badversion:trace_xprtrdma_reply_vers_err (rep); - goto out; +rpcrdma_rep_put (buf, rep); + credits = buf->rb_credits; + goto out_post; out_shortreply:trace_xprtrdma_reply_short_err (rep); - -out:rpcrdma_rep_put (buf, rep); + credits = buf->rb_credits; + goto out_post; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 704/1611 xprtrdma: Return sendctx slot after Send preparation failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 60e7870052f417d83965db144f70ae21fcfcf37f ]
rpcrdma_prepare_send_sges() gets a sendctx before it maps the SGEs for the Send WR. If one of the mapping helpers fails, no Send WR is posted, so no Send completion is guaranteed to advance rb_sc_tail.
Current cleanup clears sc_req so a later completion can sweep over that slot, but a consecutive run of preparation failures can still advance rb_sc_head until the ring appears full. At that point rpcrdma_sendctx_get_locked() returns NULL and no Send can be posted to produce the completion needed to recover the ring.
The trigger requires CONFIG_SUNRPC_XPRT_RDMA and an NFS/RDMA mount. Mount setup and reliable DMA-map fault injection require local admin authority. Unprivileged I/O on an existing mount can exercise the send path, but a remote peer alone cannot force this local DMA-map failure.
Add rpcrdma_sendctx_unget_locked() for the single-consumer send path to rewind rb_sc_head when the just-acquired sendctx is canceled before ib_post_send(). Wake waiters after making the slot available again. After the rewind, every slot the completion sweep visits belongs to a posted Send, so rpcrdma_sendctx_put_locked() no longer needs to test sc_req before unmapping.
--- net/sunrpc/xprtrdma/rpc_rdma.c | 5 ++++- net/sunrpc/xprtrdma/verbs.c | 40 +++++++++++++++++++++++++++++---- net/sunrpc/xprtrdma/xprt_rdma.h | 2 ++ 3 files changed, 42 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +4 -1
@@ -792,6 +792,7 @@ inline int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,struct xdr_buf *xdr, enum rpcrdma_chunktype rtype) { + struct rpcrdma_sendctx *sc;int ret; ret = -EAGAIN ;
@@ -834,7 +835,9 @@ inline int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,return 0 ; out_unmap: -rpcrdma_sendctx_cancel (req->rl_sendctx); + sc = req->rl_sendctx; +rpcrdma_sendctx_cancel (sc); +rpcrdma_sendctx_unget_locked (r_xprt, sc); out_nosc:trace_xprtrdma_prepsend_failed (&req->rl_slot, ret);return ret;
net/sunrpc/xprtrdma/verbs.c +36 -4
@@ -631,6 +631,11 @@ static void rpcrdma_sendctxs_destroy(struct rpcrdma_xprt *r_xprt)/* The QP is drained, but the final unsignaled Sends might not * have been walked by a signaled Send completion. Release those * Send owners before request buffers are reset. +* +* Unlike the completion sweep, this walk can visit slots with +* no Send posted: after a partial rpcrdma_sendctxs_create() +* failure on reconnect, rb_sc_head and rb_sc_tail are stale, +* and slots between them can be NULL or have sc_req clear. */ for (i = rpcrdma_sendctx_next(buf, buf->rb_sc_tail); i != rpcrdma_sendctx_next(buf, buf->rb_sc_head);
@@ -703,6 +708,12 @@ static unsigned long rpcrdma_sendctx_next(struct rpcrdma_buffer *buf,return likely (item < buf->rb_sc_last) ? item +1 :0 ; } +static unsigned long rpcrdma_sendctx_prev (struct rpcrdma_buffer *buf, +unsigned long item) +{ +return item >0 ? item -1 : buf->rb_sc_last; +} +/** * rpcrdma_sendctx_get_locked - Acquire a send context * @r_xprt: controlling transport instance
@@ -747,6 +758,29 @@ struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_xprt *r_xprt)return NULL ; } +/** +* rpcrdma_sendctx_unget_locked - Release an unposted send context +* @r_xprt: controlling transport instance +* @sc: send context to release +* +* Usage: Called when no Send is posted for the sendctx most +* recently returned by rpcrdma_sendctx_get_locked(). +* +* The caller serializes calls to this function and to +* rpcrdma_sendctx_get_locked() (per transport). +*/ +void rpcrdma_sendctx_unget_locked (struct rpcrdma_xprt *r_xprt, +struct rpcrdma_sendctx *sc) +{ +struct rpcrdma_buffer *buf = &r_xprt->rx_buf; + +if (WARN_ON_ONCE (buf->rb_sc_ctxs[buf->rb_sc_head] != sc)) +return ; + + buf->rb_sc_head =rpcrdma_sendctx_prev (buf, buf->rb_sc_head); +xprt_write_space (&r_xprt->rx_xprt); +} +/** * rpcrdma_sendctx_put_locked - Release a send context * @r_xprt: controlling transport instance
@@ -764,8 +798,7 @@ static void rpcrdma_sendctx_put_locked(struct rpcrdma_xprt *r_xprt,unsigned long next_tail;/* Release previously completed but unsignaled Sends by walking -* up the queue until @sc is found. Entries left behind by a -* failed rpcrdma_prepare_send_sges() have sc_req cleared. +* up the queue until @sc is found. */ next_tail = buf->rb_sc_tail; do {
@@ -775,8 +808,7 @@ static void rpcrdma_sendctx_put_locked(struct rpcrdma_xprt *r_xprt,/* ORDER: item must be accessed _before_ tail is updated */ cur = buf->rb_sc_ctxs[next_tail]; -if (cur->sc_req) -rpcrdma_sendctx_unmap (cur); +rpcrdma_sendctx_unmap (cur); }while (buf->rb_sc_ctxs[next_tail] != sc);
net/sunrpc/xprtrdma/xprt_rdma.h +2 -0
@@ -478,6 +478,8 @@ void rpcrdma_req_destroy(struct rpcrdma_req *req);int rpcrdma_buffer_create (struct rpcrdma_xprt *);void rpcrdma_buffer_destroy (struct rpcrdma_buffer *);struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked (struct rpcrdma_xprt *r_xprt); +void rpcrdma_sendctx_unget_locked (struct rpcrdma_xprt *r_xprt, +struct rpcrdma_sendctx *sc);struct rpcrdma_mr *rpcrdma_mr_get (struct rpcrdma_xprt *r_xprt);void rpcrdma_mrs_refresh (struct rpcrdma_xprt *r_xprt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 705/1611 perf s390: Fix TEXTREL in Python extension by compiling as PIC
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Remus <[email protected]>
[ Upstream commit 49f5f6ae67dec54014584bb3126a5a94f14e2a5c ]
On s390 the Python extension build fails as follows when using a linker that is configured to treat text relocations (TEXTREL) in shared libraries as error by default:
GEN python/perf.cpython-314-s390x-linux-gnu.so/usr/bin/ld.bfd: error: read-only segment has dynamic relocations
This occurrs because util/llvm-c-helpers.o is erroneously built from util/llvm-c-helpers.cpp without compiler option -fPIC but linked into the shared library (via libperf-util.a(perf-util-in.o)).
On s390, object files must be compiled as position-indepedent code (PIC) in order to be linked into shared libraries. Commit a9a3f1d18a6c ("perf
s390: Always build with -fPIC") added compiler option -fPIC to CFLAGS for s390, which is used in C compiles. Add -fPIC to CXXFLAGS for s390 as well, so that it is also used in C++ compiles.
--- tools/perf/Makefile.config | 1 + 1 file changed, 1 insertion(+)
tools/perf/Makefile.config +1 -0
@@ -110,6 +110,7 @@ endif ifeq ($(ARCH),s390) CFLAGS += -fPIC + CXXFLAGS += -fPIC endif ifeq ($(ARCH),mips)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 706/1611 perf cs-etm: Queue context packets for frontend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 68ca50bc0fa64841cd73b8a1538df1d7f7eb4108 ]
PE_CONTEXT elements update the context ID and exception level, but the decoder may still have prior packets cached for frontend processing. Updating the context immediately in the decoder backend can make those cached packets get consumed with the wrong thread or EL state.
Add a CS_ETM_CONTEXT packet carrying the TID and EL to the frontend, this keeps context changes ordered with the rest of the packet stream and avoids mismatches when synthesizing samples from cached packets.
Separate the memory access function into one for the frontend and one for decoding. The frontend also needs memory access to attach the instruction to samples. Because the frontend does memory access for both previous and current packets, change all the frontend memory access function signatures to take both a tidq and packet. But backend always uses the current backend EL and thread from the tidq.
Treat context packets as a boundary for branch sample generation and remove tidq->prev_packet_thread because it's not possible to branch to a different thread, so only tracking the current thread is required for sample generation.
--- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 21 +- tools/perf/util/cs-etm.c | 236 +++++++++++------- tools/perf/util/cs-etm.h | 8 +- 3 files changed, 163 insertions(+), 102 deletions(-)
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +16 -5
@@ -399,6 +399,8 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq, packet_queue->packet_buffer[et].flags =0 ; packet_queue->packet_buffer[et].exception_number =UINT32_MAX ; packet_queue->packet_buffer[et].trace_chan_id = trace_chan_id; + packet_queue->packet_buffer[et].el = ocsd_EL_unknown; + packet_queue->packet_buffer[et].tid =-1 ;if (packet_queue->packet_count ==CS_ETM_PACKET_MAX_BUFFER -1 )return OCSD_RESP_WAIT ;
@@ -446,6 +448,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq, packet->last_instr_type = elem->last_i_type; packet->last_instr_subtype = elem->last_i_subtype; packet->last_instr_cond = elem->last_instr_cond; + packet->el = elem->context.exception_level;if (elem->last_i_type ==OCSD_INSTR_BR || elem->last_i_type ==OCSD_INSTR_BR_INDIRECT ) packet->last_instr_taken_branch = elem->last_instr_exec;
@@ -522,7 +525,9 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { + struct cs_etm_packet *packet;pid_t tid =-1 ; +int ret;/* * Process the PE_CONTEXT packets if we have a valid contextID or VMID.
@@ -543,12 +548,18 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,break ; } -if (cs_etm__etmq_set_tid_el (etmq, tid, trace_chan_id, - elem->context.exception_level)) +if (cs_etm__etmq_update_decode_context (etmq, trace_chan_id, + elem->context.exception_level, tid))return OCSD_RESP_FATAL_SYS_ERR ; -if (tid ==-1 ) -return OCSD_RESP_CONT ; + ret =cs_etm_decoder__buffer_packet (etmq, packet_queue, trace_chan_id, +CS_ETM_CONTEXT ); +if (ret !=OCSD_RESP_CONT && ret !=OCSD_RESP_WAIT ) +return ret; + + packet = &packet_queue->packet_buffer[packet_queue->tail]; + packet->tid = tid; + packet->el = elem->context.exception_level;/* * A timestamp is generated after a PE_CONTEXT element so make sure
@@ -556,7 +567,7 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,*/ cs_etm_decoder__reset_timestamp (packet_queue); -return OCSD_RESP_CONT ; +return ret; } static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
tools/perf/util/cs-etm.c +141 -95
533 lines not on this page · raw message
tools/perf/util/cs-etm.h +6 -2
@@ -158,6 +158,7 @@ enum cs_etm_sample_type {CS_ETM_DISCONTINUITY ,CS_ETM_EXCEPTION ,CS_ETM_EXCEPTION_RET , + CS_ETM_CONTEXT, }; enum cs_etm_isa {
@@ -184,6 +185,8 @@ struct cs_etm_packet {u8 last_instr_size;u8 trace_chan_id;int cpu; +int el; +pid_t tid; };#define CS_ETM_PACKET_MAX_BUFFER 1024
@@ -244,8 +247,9 @@ enum cs_etm_pid_fmt {#include <opencsd/ocsd_if_types.h> int cs_etm__get_cpu (struct cs_etm_queue *etmq,u8 trace_chan_id,int *cpu);enum cs_etm_pid_fmt cs_etm__get_pid_fmt (struct cs_etm_queue *etmq); -int cs_etm__etmq_set_tid_el (struct cs_etm_queue *etmq,pid_t tid, -u8 trace_chan_id,ocsd_ex_level el); +int cs_etm__etmq_update_decode_context (struct cs_etm_queue *etmq, +u8 trace_chan_id,ocsd_ex_level el, +pid_t tid);bool cs_etm__etmq_is_timeless (struct cs_etm_queue *etmq);void cs_etm__etmq_set_traceid_queue_timestamp (struct cs_etm_queue *etmq,u8 trace_chan_id);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 707/1611 perf pmu: Fix pmu_id() heap underwrite on empty identifier file
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 836455e6dbd34eb3d12eeab5e2d2b9a7f1512459 ]
pmu_id() calls filename__read_str() then strips the trailing newline via str[len - 1] = 0. If the PMU identifier file is empty, filename__read_str() succeeds with len = 0. len - 1 underflows size_t to SIZE_MAX, writing a null byte before the heap allocation.
Add a len == 0 check before the newline stripping.
--- tools/perf/util/pmu.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/pmu.c +6 -0
@@ -856,6 +856,12 @@ static char *pmu_id(const char *name)if (filename__read_str (path, &str, &len) <0 )return NULL ; +/* empty identifier file — nothing useful */ +if (len ==0 ) { +free (str); +return NULL ; + } + str[len -1 ] =0 ;/* remove line feed */ return str;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 708/1611 perf pmu: Fix perf_pmu__parse_scale/unit() OOB access on empty sysfs file
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 33035f7dd4e49f3f117e70c5e36c8c1ae88d37f2 ]
perf_pmu__parse_scale() reads a PMU scale file then accesses scale[sret - 1] to strip a trailing newline. Only sret < 0 is guarded, so an empty file (sret == 0) causes scale[-1] — a stack buffer underflow that reads and potentially writes out of bounds.
perf_pmu__parse_unit() has the same pattern: alias->unit[sret - 1] with sret == 0 accesses the byte before the struct member, which may corrupt the adjacent pmu_name pointer field.
Change both guards from sret < 0 to sret <= 0 so that empty files are treated as read errors.
--- tools/perf/util/pmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/pmu.c +2 -2
@@ -328,7 +328,7 @@ static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_alias *al goto error; sret =read (fd, scale,sizeof (scale)-1 ); -if (sret <0 ) +if (sret <=0 ) goto error;if (scale[sret -1 ] =='\n' )
@@ -360,7 +360,7 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *alireturn -1 ; sret =read (fd, alias->unit,UNIT_MAX_LEN ); -if (sret <0 ) +if (sret <=0 ) goto error;close (fd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 709/1611 tools lib api: Fix missing null termination in filename__read_int/ull()
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 52b1f9678499b13b7aeb0186d9c6f486c043283f ]
filename__read_int() passes a stack buffer to read() using the full sizeof(line) and then hands it to atoi() without null-terminating. If a sysfs file fills the 64-byte buffer exactly, atoi() reads past the array into uninitialized stack memory.
filename__read_ull_base() has the same issue with strtoull().
Fix both by reading sizeof(line) - 1 bytes and explicitly null-terminating after a successful read.
--- tools/lib/api/fs/fs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/lib/api/fs/fs.c +8 -2
@@ -294,11 +294,14 @@ int filename__read_int(const char *filename, int *value) {char line[64 ];int fd =open (filename,O_RDONLY ), err =-1 ; +ssize_t n;if (fd <0 )return -errno; -if (read (fd, line,sizeof (line)) >0 ) { + n =read (fd, line,sizeof (line) -1 ); +if (n >0 ) { + line[n] ='\0' ; *value =atoi (line); err =0 ; }
@@ -312,11 +315,14 @@ static int filename__read_ull_base(const char *filename, {char line[64 ];int fd =open (filename,O_RDONLY ), err =-1 ; +ssize_t n;if (fd <0 )return -errno; -if (read (fd, line,sizeof (line)) >0 ) { + n =read (fd, line,sizeof (line) -1 ); +if (n >0 ) { + line[n] ='\0' ; *value =strtoull (line,NULL , base);if (*value !=ULLONG_MAX ) err =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/1611 perf symbols: Fix signed overflow in sysfs__read_build_id() size check
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 6eaa8ee3e2abe5112e80e94c27196bb175689469 ]
sysfs__read_build_id() reads ELF note headers from sysfs files. The note's namesz and descsz fields are used to compute the skip size:
int n = namesz + descsz;
if (n > (int)sizeof(bf))Both namesz and descsz are size_t from NOTE_ALIGN() of 32-bit note header fields. Their sum can exceed INT_MAX, overflowing the signed int n to a negative value. The check n > sizeof(bf) then evaluates false (negative < positive in signed comparison), and read(fd, bf, n) reinterprets the negative n as a huge size_t count — the kernel writes up to MAX_RW_COUNT bytes into the 8192-byte stack buffer.
In practice the overflow is bounded by the sysfs file's actual size, so a real sysfs notes file won't trigger it organically. But crafted input (e.g. via a mounted debugfs/sysfs image) could.
Fix by validating namesz and descsz individually against the buffer size before summing, and change n to size_t to avoid the signed overflow entirely.
--- tools/perf/util/symbol-elf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/util/symbol-elf.c +6 -3
@@ -962,14 +962,17 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid) }else if (read (fd, bf, descsz) != (ssize_t )descsz)break ; }else { -int n = namesz + descsz; +size_t n; -if (n > (int )sizeof (bf)) { +/* int sum of namesz+descsz can overflow negative, bypassing size check */ +if (namesz >sizeof (bf) || descsz >sizeof (bf) - namesz) { n =sizeof (bf);pr_debug ("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n" , __func__, filename, nhdr.n_namesz, nhdr.n_descsz); + }else { + n = namesz + descsz; } -if (read (fd, bf, n) != n) +if (read (fd, bf, n) != (ssize_t )n)break ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/1611 perf symbols: Bounds-check .gnu_debuglink section data
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 9c74f0aab398cb32ab250401f323c0fdc9a3a496 ]
filename__read_debuglink() copies .gnu_debuglink section data into a caller-provided buffer via:
strncpy(debuglink, data->d_buf, size);
where size is PATH_MAX. If the ELF section is smaller than size and lacks a null terminator, strncpy reads past data->d_buf into adjacent memory. A malformed ELF file can trigger this, potentially causing a segfault or leaking heap data.
Additionally, strncpy does not guarantee null termination when the source fills the buffer.
Replace with an explicit memcpy bounded by both the output buffer size and the actual section data size (data->d_size), followed by explicit null termination.
--- tools/perf/util/symbol-elf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/symbol-elf.c +8 -1
@@ -1025,7 +1025,14 @@ int filename__read_debuglink(const char *filename, char *debuglink, goto out_elf_end;/* the start of this section is a zero-terminated string */ -strncpy (debuglink, data->d_buf, size); +if (data->d_size >0 ) { +size_t len =min (size -1 , data->d_size); + +memcpy (debuglink, data->d_buf, len); + debuglink[len] ='\0' ; + }else { + debuglink[0 ] ='\0' ; + } err =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/1611 perf intel-pt: Fix snprintf size tracking bug in insn decoder
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 b6bb3b005dcdd960b8e0b7f9d6869132b3de08d5 ]
dump_insn() tracks remaining buffer space with a 'left' variable, but the loop subtracts the cumulative offset 'n' each iteration instead of just the per-iteration delta:
n += snprintf(x->out + n, left, "%02x ", inbuf[i]); left -= n; /* BUG: n is cumulative, not the delta */
After two iterations left goes massively negative, wrapping to a huge value when passed as size_t to snprintf(), disabling all bounds checking for the rest of the loop.
Switch to scnprintf() accumulation using sizeof(x->out) - n as the remaining space, which is always correct and eliminates the separate 'left' variable entirely.
--- .../util/intel-pt-decoder/intel-pt-insn-decoder.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c +3 -8
@@ -220,7 +220,6 @@ const char *dump_insn(struct perf_insn *x, uint64_t ip __maybe_unused, {struct insn insn;int n, i, ret; -int left; ret =insn_decode (&insn, inbuf, inlen, x->is64bit ?INSN_MODE_64 :INSN_MODE_32 );
@@ -229,13 +228,9 @@ const char *dump_insn(struct perf_insn *x, uint64_t ip __maybe_unused,return "<bad>" ;if (lenp) *lenp = insn.length; - left =sizeof (x->out); - n =snprintf (x->out, left,"insn: " ); - left -= n; -for (i =0 ; i < insn.length; i++) { - n +=snprintf (x->out + n, left,"%02x " , inbuf[i]); - left -= n; - } + n =scnprintf (x->out,sizeof (x->out),"insn: " ); +for (i =0 ; i < insn.length; i++) + n +=scnprintf (x->out + n,sizeof (x->out) - n,"%02x " , inbuf[i]);return x->out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/1611 perf tools: Fix thread__set_comm_from_proc() on empty comm file
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 31d596054550f793508abe7dd593853ece47d428 ]
thread__set_comm_from_proc() calls procfs__read_str() then strips the trailing newline via comm[sz - 1] = '\0'. procfs__read_str() allocates the buffer before reading, so on an empty /proc/pid/comm (reachable during late exit teardown) it returns success with sz = 0 and an unterminated heap buffer.
The sz - 1 underflow was the original sashiko finding: it writes a null byte before the allocation. But even with a sz > 0 guard on the newline strip, the unterminated buffer would still be passed to thread__set_comm() which calls strlen() — an unbounded heap read.
Fix by treating sz == 0 as failure: free the buffer and return -1. This is consistent with pmu.c's perf_pmu__parse_scale/unit which already treat len == 0 from filename__read_str as an error.
--- tools/perf/util/thread.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/util/thread.c +5 -0
@@ -294,6 +294,11 @@ int thread__set_comm_from_proc(struct thread *thread)if (!(snprintf (path,sizeof (path),"%d/task/%d/comm" ,thread__pid (thread),thread__tid (thread)) >= (int )sizeof (path)) &&procfs__read_str (path, &comm, &sz) ==0 ) { +/* sz==0: read got nothing, e.g. race during exit teardown */ +if (sz ==0 ) { +free (comm); +return -1 ; + } comm[sz -1 ] ='\0' ; err =thread__set_comm (thread, comm,0 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/1611 perf hwmon: Fix off-by-one null termination on sysfs reads
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 1847c5fae344a0fb9cc0f95be40b378359c6fc3b ]
Three functions read sysfs files into fixed-size stack buffers using the full buffer size, then null-terminate at buf[read_len]. If the read fills the buffer exactly, read_len equals sizeof(buf) and the null byte writes one past the array, corrupting an adjacent stack variable.
Fix all three by reading sizeof(buf) - 1 bytes, reserving space for the null terminator:
- hwmon_pmu__read_events(): buf[128]
- hwmon_pmu__describe_items(): buf[64]
- evsel__hwmon_pmu_read(): buf[32]
--- tools/perf/util/hwmon_pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/hwmon_pmu.c +3 -3
@@ -289,7 +289,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)if (fd <0 )continue ; - read_len =read (fd, buf,sizeof (buf)); + read_len =read (fd, buf,sizeof (buf) -1 );while (read_len >0 && buf[read_len -1 ] =='\n' ) read_len--;
@@ -432,7 +432,7 @@ static size_t hwmon_pmu__describe_items(struct hwmon_pmu *hwm, char *out_buf, si is_alarm ? "_alarm" : ""); fd =openat (dir, buf,O_RDONLY );if (fd >0 ) { -ssize_t read_len =read (fd, buf,sizeof (buf)); +ssize_t read_len =read (fd, buf,sizeof (buf) -1 );while (read_len >0 && buf[read_len -1 ] =='\n' ) read_len--;
@@ -816,7 +816,7 @@ int evsel__hwmon_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread) count =perf_counts (evsel->counts, cpu_map_idx, thread); fd =FD (evsel, cpu_map_idx, thread); - len =pread (fd, buf,sizeof (buf),0 ); + len =pread (fd, buf,sizeof (buf) -1 ,0 );if (len <=0 ) { count->lost++;return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/1611 perf hwmon: Use scnprintf() in hwmon_pmu__for_each_event()
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 ae75956c166fe169b8c137bf375305fc97820a62 ]
hwmon_pmu__for_each_event() formats description strings via:
len = snprintf(desc_buf, sizeof(desc_buf), "%s in unit %s named %s.", ...);
len += hwmon_pmu__describe_items(hwm, desc_buf + len, sizeof(desc_buf) - len, ...);If value->label is long enough to cause snprintf() to truncate, it returns the would-have-been-written count, making len exceed sizeof(desc_buf). The subsequent sizeof(desc_buf) - len underflows to a huge size_t value, disabling bounds checking in hwmon_pmu__describe_items().
The alias_buf snprintf has the same issue. Switch both to scnprintf() which returns actual bytes written.
--- tools/perf/util/hwmon_pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/hwmon_pmu.c +3 -3
@@ -514,14 +514,14 @@ int hwmon_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callbint ret;size_t len; - len =snprintf (alias_buf,sizeof (alias_buf),"%s%d" , - hwmon_type_strs[key.type], key.num); +scnprintf (alias_buf,sizeof (alias_buf),"%s%d" , + hwmon_type_strs[key.type], key.num);if (!info.name) { info.name = info.alias; info.alias =NULL ; } - len =snprintf (desc_buf,sizeof (desc_buf),"%s in unit %s named %s." , + len =scnprintf (desc_buf,sizeof (desc_buf),"%s in unit %s named %s." , hwmon_desc[key.type], pmu->name +6 , value->label ?: info.name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 716/1611 perf hwmon: Fix parse_hwmon_filename() strlcpy buffer overflow
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 e1a2c9d70b312acc262f6be936dd5bbd9bbc6236 ]
parse_hwmon_filename() strips the "_alarm" suffix from event names by copying into a 24-byte stack buffer:
strlcpy(fn_type, fn_item, fn_item_len - 5);
The third argument is the source length minus the suffix, not the destination buffer capacity. A long event name ending in "_alarm" can have fn_item_len - 5 > sizeof(fn_type), causing strlcpy() to write past the 24-byte fn_type[] array. The assert() only validates that the longest *valid* hwmon item fits, but does not protect against crafted input.
Clamp the strlcpy size to min(fn_item_len - 5, sizeof(fn_type)).
--- tools/perf/util/hwmon_pmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/hwmon_pmu.c +2 -1
@@ -202,7 +202,8 @@ bool parse_hwmon_filename(const char *filename, fn_item_len =strlen (fn_item);if (fn_item_len >6 && !strcmp (&fn_item[fn_item_len -6 ],"_alarm" )) {assert (strlen (LONGEST_HWMON_ITEM_STR ) <sizeof (fn_type)); -strlcpy (fn_type, fn_item, fn_item_len -5 ); +/* fn_item_len - 5 strips "_alarm"; clamp to buffer size */ +strlcpy (fn_type, fn_item,min_t (size_t, fn_item_len -5 ,sizeof (fn_type))); fn_item = fn_type; *alarm = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 717/1611 perf symbols: Bounds-check descsz in sysfs__read_build_id() GNU fallback
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 1b4e9fbdeabc549965e70ac0cd8095d57ff6df06 ]
When sysfs__read_build_id() matches NT_GNU_BUILD_ID with the right namesz but the name content is not "GNU", it falls back to reading descsz bytes into the stack buffer bf[BUFSIZ]:
} else if (read(fd, bf, descsz) != (ssize_t)descsz)
Unlike the else branch which validates namesz + descsz against sizeof(bf), this path passes descsz directly to read() without any bounds check. A crafted sysfs file with a large n_descsz overflows the 8192-byte stack buffer.
Add a descsz > sizeof(bf) check before the read, breaking out of the loop on oversized values.
--- tools/perf/util/symbol-elf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/symbol-elf.c +7 -2
@@ -959,8 +959,13 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid) err =0 ;break ; } - }else if (read (fd, bf, descsz) != (ssize_t )descsz) -break ; + }else { +/* descsz from untrusted file — clamp to buffer */ +if (descsz >sizeof (bf)) +break ; +if (read (fd, bf, descsz) != (ssize_t )descsz) +break ; + } }else {size_t n;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/1611 perf hwmon: Guard label read against empty or failed reads
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 34d3d93fac6d92237cb9d730ca04c37ed361c7a6 ]
hwmon_pmu__read_events() reads label files with read() into a stack buffer, strips trailing newlines, then checks buf[0] == '\0'. When read() returns 0 (empty file) or -1 (error), the buffer is never written, so buf[0] reads uninitialized stack memory. If the garbage byte is non-zero, the code falls through to strdup(buf) which copies arbitrary stack data as the label string.
Fix by checking read_len <= 0 before accessing buf contents, closing the fd and skipping the entry.
--- tools/perf/util/hwmon_pmu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/hwmon_pmu.c +5 -2
@@ -295,8 +295,11 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)while (read_len >0 && buf[read_len -1 ] =='\n' ) read_len--; -if (read_len >0 ) - buf[read_len] ='\0' ; +if (read_len <=0 ) { +close (fd); +continue ; + } + buf[read_len] ='\0' ;if (buf[0 ] =='\0' ) { pr_debug("hwmon_pmu: empty label file %s %s\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/1611 perf tools: Use snprintf() in dso__read_running_kernel_build_id()
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 2ea64782a428bed74f595961e651ceb8c4c5bf22 ]
dso__read_running_kernel_build_id() uses sprintf() to format a sysfs path from machine->root_dir into a PATH_MAX buffer. If root_dir is close to PATH_MAX in length, appending "/sys/kernel/notes" (18 bytes) overflows the stack buffer.
Switch to snprintf() with sizeof(path) to prevent the overflow.
--- tools/perf/util/dso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/dso.c +1 -1
@@ -1703,7 +1703,7 @@ void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)if (machine__is_default_guest (machine))return ; -sprintf (path,"%s/sys/kernel/notes" , machine->root_dir); +snprintf (path,sizeof (path),"%s/sys/kernel/notes" , machine->root_dir);sysfs__read_build_id (path, &bid);dso__set_build_id (dso, &bid); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/1611 tools lib api: Fix filename__write_int() writing uninitialized stack data
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 438ece06185696e14c63c6113d5e2d34ec0a9680 ]
filename__write_int() formats an integer into a 64-byte buffer with sprintf() then passes sizeof(buf) (64) as the write length. This writes all 64 bytes including uninitialized stack data past the formatted string. Most sysfs files reject the oversized write, making the function always return -1.
Fix by capturing the sprintf() return value and using it as the write length.
--- tools/lib/api/fs/fs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/lib/api/fs/fs.c +3 -2
@@ -376,12 +376,13 @@ int filename__write_int(const char *filename, int value) {int fd =open (filename,O_WRONLY ), err =-1 ;char buf[64 ]; +int len;if (fd <0 )return -errno; -sprintf (buf,"%d" , value); -if (write (fd, buf,sizeof (buf)) ==sizeof (buf)) + len =sprintf (buf,"%d" , value); +if (write (fd, buf, len) == len) err =0 ;close (fd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/1611 tools lib api: Fix mount_overload() snprintf truncation and toupper range
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 fd1f70776add263f8ef38a87ae593c75303f1dcd ]
mount_overload() builds an environment variable name like "PERF_SYSFS_ENVIRONMENT" from fs->name. Two bugs:
1) snprintf() uses name_len as the buffer size instead of sizeof(upper_name). For fs->name = "sysfs" (len=5), the output is truncated to "PERF" (4 chars + null), so getenv() never finds the intended variable.
2) mem_toupper() only uppercases name_len bytes, converting just the "PERF" prefix rather than the full string including the filesystem name portion.
Fix by using sizeof(upper_name) for snprintf and strlen(upper_name) for mem_toupper, so the full "PERF_SYSFS_ENVIRONMENT" string is correctly formatted and uppercased.
--- tools/lib/api/fs/fs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/api/fs/fs.c +2 -2
@@ -261,8 +261,8 @@ static const char *mount_overload(struct fs *fs)/* "PERF_" + name + "_ENVIRONMENT" + '\0' */ char upper_name[5 + name_len +12 +1 ]; -snprintf (upper_name, name_len,"PERF_%s_ENVIRONMENT" , fs->name); -mem_toupper (upper_name, name_len); +snprintf (upper_name,sizeof (upper_name),"PERF_%s_ENVIRONMENT" , fs->name); +mem_toupper (upper_name,strlen (upper_name));return getenv (upper_name) ?: *fs->mounts; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/1611 perf bpf: Add NULL check for btf__type_by_id() in synthesize_bpf_prog_name()
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 903b0526dcf86d030c5970b4b0a67f9c227368e2 ]
synthesize_bpf_prog_name() calls btf__type_by_id() and immediately dereferences the result via t->name_off without checking for NULL. btf__type_by_id() returns NULL when the type_id is invalid or out of range. When processing perf.data files, finfo->type_id comes from untrusted input, so an invalid ID causes a NULL pointer dereference.
Fix by checking t for NULL before dereferencing.
--- tools/perf/util/bpf-event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/bpf-event.c +2 -1
@@ -146,7 +146,8 @@ static int synthesize_bpf_prog_name(char *buf, int size,if (btf) { finfo = func_infos + sub_id * info->func_info_rec_size; t =btf__type_by_id (btf, finfo->type_id); - short_name =btf__name_by_offset (btf, t->name_off); +if (t) + short_name =btf__name_by_offset (btf, t->name_off); }else if (sub_id ==0 && sub_prog_cnt ==1 ) {/* no subprog */ if (info->name[0 ])
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/1611 perf bpf: Fix map data leak in bpf_metadata_create() on alloc failure
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 aece2b8966fc8de5be46ee9287d0f60d6690c300 ]
bpf_metadata_create() calls bpf_metadata_read_map_data() which allocates map.btf and map.rodata. If the subsequent bpf_metadata_alloc() fails, the code does 'continue' which skips bpf_metadata_free_map_data(), permanently leaking both allocations.
Fix by calling bpf_metadata_free_map_data() before continue.
--- tools/perf/util/bpf-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/bpf-event.c +3 -1
@@ -395,8 +395,10 @@ static struct bpf_metadata *bpf_metadata_create(struct bpf_prog_info *info)continue ; metadata =bpf_metadata_alloc (info->nr_prog_tags, map.num_vars); -if (!metadata) +if (!metadata) { +bpf_metadata_free_map_data (&map);continue ; + }bpf_metadata_fill_event (&map, &metadata->event->bpf_metadata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/1611 perf bpf: Fix metadata leak in perf_env__add_bpf_info() on duplicate insert
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 a0e4362a3e7b592f1d58949ffe3d6decad39a17c ]
When perf_env__insert_bpf_prog_info() returns false (duplicate program), the error path frees info_linear and info_node but not info_node->metadata. If bpf_metadata_create() had succeeded, the metadata allocation is permanently leaked.
Fix by calling bpf_metadata_free() on info_node->metadata before freeing info_node. bpf_metadata_free() handles NULL, so this is safe even when bpf_metadata_create() returned NULL.
--- tools/perf/util/bpf-event.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/bpf-event.c +1 -0
@@ -875,6 +875,7 @@ static int perf_env__add_bpf_info(struct perf_env *env, u32 id)if (!perf_env__insert_bpf_prog_info (env, info_node)) {pr_debug ("%s: duplicate add bpf info request for id %u\n" , __func__, btf_id); +bpf_metadata_free (info_node->metadata);free (info_linear);free (info_node); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/1611 perf symbols: Add bounds checks to elf_read_build_id() note iteration
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 acc56d3941fc2997a5a21ea9233a8ac3d87c4f2f ]
elf_read_build_id() iterates ELF notes using pointer arithmetic driven by n_namesz and n_descsz from the note headers. Neither the note header read nor the subsequent name/desc advances are checked against the section boundary. A malformed ELF file with oversized note sizes causes out-of-bounds reads past the section data buffer.
Add two bounds checks: verify the note header fits within the remaining section data, and verify that namesz + descsz (after alignment) fits before advancing the pointer.
--- tools/perf/util/symbol-elf.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
tools/perf/util/symbol-elf.c +16 -2
@@ -836,10 +836,24 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size) ptr = data->d_buf;while (ptr < (data->d_buf + data->d_size)) {GElf_Nhdr *nhdr = ptr; -size_t namesz =NOTE_ALIGN (nhdr->n_namesz), - descsz =NOTE_ALIGN (nhdr->n_descsz); +size_t namesz, descsz, remaining;const char *name; +/* ensure the note header fits within the section */ +if (ptr +sizeof (*nhdr) > data->d_buf + data->d_size) +break ; + + namesz =NOTE_ALIGN (nhdr->n_namesz); + descsz =NOTE_ALIGN (nhdr->n_descsz); + +/* validate individually to avoid size_t overflow on 32-bit */ + remaining = data->d_buf + data->d_size - ptr -sizeof (*nhdr); +if (namesz > remaining || descsz > remaining - namesz) { +pr_warning ("%s: oversized note: n_namesz=%u, n_descsz=%u\n" , + __func__, nhdr->n_namesz, nhdr->n_descsz); +break ; + } + ptr +=sizeof (*nhdr); name = ptr; ptr += namesz;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/1611 perf symbols: Add bounds checks to read_build_id() note iteration in minimal build
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 52e582e316c48c53bb3082c29f7862ebc554087e ]
symbol-minimal.c's read_build_id() iterates ELF notes with the same pattern as symbol-elf.c's elf_read_build_id(): pointer arithmetic driven by n_namesz and n_descsz from 32-bit note header fields, without validating that the name and desc fit within the note section data. A malformed ELF file with oversized note sizes causes out-of-bounds reads past the section data buffer.
Add the same bounds check as the libelf path: validate namesz and descsz individually against remaining data before advancing the pointer, avoiding size_t overflow on 32-bit.
--- tools/perf/util/symbol-minimal.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tools/perf/util/symbol-minimal.c +10 -1
@@ -1,3 +1,4 @@ +#include "debug.h" #include "dso.h" #include "symbol.h" #include "symsrc.h"
@@ -44,7 +45,7 @@ static int read_build_id(void *note_data, size_t note_len, struct build_id *bid, ptr = note_data;while ((ptr +sizeof (*nhdr)) < (note_data + note_len)) {const char *name; -size_t namesz, descsz; +size_t namesz, descsz, remaining; nhdr = ptr;if (need_swap) {
@@ -56,6 +57,14 @@ static int read_build_id(void *note_data, size_t note_len, struct build_id *bid, namesz =NOTE_ALIGN (nhdr->n_namesz); descsz =NOTE_ALIGN (nhdr->n_descsz); +/* validate individually to avoid size_t overflow on 32-bit */ + remaining = note_data + note_len - ptr -sizeof (*nhdr); +if (namesz > remaining || descsz > remaining - namesz) { +pr_warning ("%s: oversized note: n_namesz=%u, n_descsz=%u\n" , + __func__, nhdr->n_namesz, nhdr->n_descsz); +break ; + } + ptr +=sizeof (*nhdr); name = ptr; ptr += namesz;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 727/1611 dt-bindings: phy: sc8280xp-qmp-pcie: Disallow bifurcation register on Purwa
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 b3ee497970c63cea37976aeaa84bac39611fe0eb ]
Neither of the two Gen4x4 PHYs found on Purwa supports bifurcation. The PHY is however physically laid out as if it were to, since there are two separate ports (A/B).
Split out a new if-then block to un-require the bifurcation register handle to squash this warning:
purwa-iot-evk.dtb: phy@1bd4000 (qcom,x1p42100-qmp-gen4x4-pcie-phy): 'qcom,4ln-config-sel' is a required property
--- .../bindings/phy/qcom,sc8280xp-qmp-pcie-phy.yaml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-pcie-phy.yaml +11 -2
@@ -134,13 +134,22 @@ allOf: items: - description: port a - description: port b - required: - - qcom,4ln-config-sel else: properties: reg: maxItems: 1 + - if: + properties: + compatible: + contains: + enum: + - qcom,sc8280xp-qmp-gen3x4-pcie-phy + - qcom,x1e80100-qmp-gen4x4-pcie-phy + then: + required: + - qcom,4ln-config-sel + - if: properties: compatible:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 728/1611 PCI: mediatek: Fix possible truncation in mtk_pcie_parse_port()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryder Lee <[email protected]>
[ Upstream commit ab4a4043db1fcc4fd4c5745c5be8caf053502e29 ]
As reported by the W=1 warning below, content of the 'name' variable might get truncated with the existing size of 10 bytes. Though it is not practically possible to exceed the 10 bytes size, increase it to 20 to silence the warning for a clean W=1 build:
$ make W=1 drivers/pci/controller/pcie-mediatek.o
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC drivers/pci/controller/pcie-mediatek.o
drivers/pci/controller/pcie-mediatek.c: In function ‘mtk_pcie_parse_port’:
drivers/pci/controller/pcie-mediatek.c:963:43: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Werror=format-truncation=]
963 | snprintf(name, sizeof(name), "port%d", slot);
| ^~
drivers/pci/controller/pcie-mediatek.c:963:38: note: directive argument in the range [0, 2147483647]
963 | snprintf(name, sizeof(name), "port%d", slot);
| ^~~~~~~~
drivers/pci/controller/pcie-mediatek.c:963:9: note: ‘snprintf’ output between 6 and 15 bytes into a destination of size 10
963 | snprintf(name, sizeof(name), "port%d", slot);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Stable-dep-of: ebc1d9906894 ("PCI: mediatek: Use actual physical address instead of virt_to_phys()")
--- drivers/pci/controller/pcie-mediatek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mediatek.c +1 -1
@@ -920,7 +920,7 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,struct mtk_pcie_port *port;struct device *dev = pcie->dev;struct platform_device *pdev =to_platform_device (dev); -char name[10 ]; +char name[20 ];int err; port =devm_kzalloc (dev,sizeof (*port),GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 729/1611 PCI: mediatek: Use actual physical address instead of virt_to_phys()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit ebc1d9906894703286d12306a6f242d90cfb49e8 ]
The driver previously used virt_to_phys() on the ioremapped register base (port->base) to compute the MSI message address. Using virt_to_phys() on an IO mapped address is incorrect because it expects a kernel virtual address.
To fix it, store the physical start of the I/O register region in mtk_pcie_port->phys_base and use it to build the MSI address. This replaces the incorrect virt_to_phys() usage and ensures MSI addresses are generated correctly.
--- drivers/pci/controller/pcie-mediatek.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-mediatek.c +13 -3
@@ -166,6 +166,7 @@ struct mtk_pcie_soc {/** * struct mtk_pcie_port - PCIe port information * @base: IO mapped register base +* @phys_base: Physical address of the I/O register base region * @list: port list * @pcie: pointer to PCIe host info * @reset: pointer to port reset control
@@ -187,6 +188,7 @@ struct mtk_pcie_soc {*/ struct mtk_pcie_port {void __iomem *base; +phys_addr_t phys_base;struct list_head list;struct mtk_pcie *pcie;struct reset_control *reset;
@@ -396,7 +398,7 @@ static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)phys_addr_t addr;/* MT2712/MT7622 only support 32-bit MSI addresses */ - addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + addr = port->phys_base +PCIE_MSI_VECTOR ; msg->address_hi =0 ; msg->address_lo =lower_32_bits (addr);
@@ -511,7 +513,7 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)u32 val;phys_addr_t msg_addr; - msg_addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + msg_addr = port->phys_base +PCIE_MSI_VECTOR ; val =lower_32_bits (msg_addr);writel (val, port->base +PCIE_IMSI_ADDR );
@@ -920,6 +922,7 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,struct mtk_pcie_port *port;struct device *dev = pcie->dev;struct platform_device *pdev =to_platform_device (dev); +struct resource *res;char name[20 ];int err;
@@ -928,7 +931,14 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,return -ENOMEM ;snprintf (name,sizeof (name),"port%d" , slot); - port->base =devm_platform_ioremap_resource_byname (pdev, name); + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , name); +if (!res) { +dev_err (dev,"failed to get port%d base\n" , slot); +return -EINVAL ; + } + + port->phys_base = res->start; + port->base =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (port->base)) {dev_err (dev,"failed to map port%d base\n" , slot);return PTR_ERR (port->base);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 730/1611 phy: freescale: phy-fsl-imx8qm-lvds-phy: Fix missing pm_runtime_disable() on probe error path
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 799e7cf2f0b50b34660b5ffce0f7d8dec376a0d5 ]
If mixel_lvds_phy_reset() fails in probe after pm_runtime_enable(), the function returns directly without calling pm_runtime_disable(), leaving runtime PM permanently enabled for the device.
Fix this by using devm_pm_runtime_enable() so that cleanup is automatic on any probe failure or driver unbind. This also allows removing the manual err label and the .remove callback.
--- .../phy/freescale/phy-fsl-imx8qm-lvds-phy.c | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/phy/freescale/phy-fsl-imx8qm-lvds-phy.c +7 -17
@@ -347,7 +347,9 @@ static int mixel_lvds_phy_probe(struct platform_device *pdev)dev_set_drvdata (dev, priv); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) +return ret; ret =mixel_lvds_phy_reset (dev);if (ret) {
@@ -357,17 +359,15 @@ static int mixel_lvds_phy_probe(struct platform_device *pdev)for (i =0 ; i <PHY_NUM ; i++) { lvds_phy =devm_kzalloc (dev,sizeof (*lvds_phy),GFP_KERNEL ); -if (!lvds_phy) { - ret = -ENOMEM ; - goto err; - } +if (!lvds_phy) +return -ENOMEM ; phy =devm_phy_create (dev,NULL , &mixel_lvds_phy_ops);if (IS_ERR (phy)) { ret =PTR_ERR (phy);dev_err (dev,"failed to create PHY for channel%d: %d\n" , i, ret); - goto err; +return ret; } lvds_phy->phy = phy;
@@ -381,19 +381,10 @@ static int mixel_lvds_phy_probe(struct platform_device *pdev)if (IS_ERR (phy_provider)) { ret =PTR_ERR (phy_provider);dev_err (dev,"failed to register PHY provider: %d\n" , ret); - goto err; +return ret; }return 0 ; -err: -pm_runtime_disable (dev); - -return ret; -} - -static void mixel_lvds_phy_remove (struct platform_device *pdev) -{ -pm_runtime_disable (&pdev->dev); }static int __maybe_unused mixel_lvds_phy_runtime_suspend (struct device *dev)
@@ -434,7 +425,6 @@ MODULE_DEVICE_TABLE(of, mixel_lvds_phy_of_match);static struct platform_driver mixel_lvds_phy_driver = { .probe = mixel_lvds_phy_probe, - .remove = mixel_lvds_phy_remove, .driver = { .pm = &mixel_lvds_phy_pm_ops, .name ="mixel-lvds-phy" ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 731/1611 PCI: dwc: Avoid dwc_pcie_rasdes_debugfs_deinit() NULL dereference when no RAS DES capability
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuvam Pandey <[email protected]>
[ Upstream commit 26b67fa10ef84ea667942491b50e6261a45f098d ]
dwc_pcie_rasdes_debugfs_init() returns success when the controller has no RAS DES capability, leaving pci->debugfs->rasdes_info unset. The common debugfs teardown path still calls dwc_pcie_rasdes_debugfs_deinit(), which dereferences rasdes_info unconditionally.
Return early when no RAS DES state was allocated. In that case no RAS DES mutex was initialized, so there is nothing to destroy.
--- drivers/pci/controller/dwc/pcie-designware-debugfs.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +3 -0
@@ -560,6 +560,9 @@ static void dwc_pcie_rasdes_debugfs_deinit(struct dw_pcie *pci) {struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info; +if (!rinfo) +return ; +mutex_destroy (&rinfo->reg_event_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 732/1611 Revert "PCI/MSI: Unmap MSI-X region on error"
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuanhe Shu <[email protected]>
[ Upstream commit f64e03da0d83cb173743888bff4a7e61476a8fc2 ]
This reverts commit 1a8d4c6ecb4c81261bcdf13556abd4a958eca202.
Commit 1a8d4c6ecb4c ("PCI/MSI: Unmap MSI-X region on error") added an iounmap(dev->msix_base) on the error path of msix_capability_init() to release the MSI-X region when msix_setup_interrupts() fails.
When msix_setup_interrupts() fails, the call chain is:
msix_setup_interrupts()
-> __msix_setup_interrupts()
struct pci_dev *dev __free(free_msi_irqs) = __dev;
...
return ret; // __free cleanup fires on errorThe __free(free_msi_irqs) cleanup calls pci_free_msi_irqs(), which already handles the unmap:
void pci_free_msi_irqs(struct pci_dev *dev)
{
pci_msi_teardown_msi_irqs(dev);
if (dev->msix_base) {
iounmap(dev->msix_base); // already unmapped here
dev->msix_base = NULL; // and set to NULL
}
}So dev->msix_base is unmapped and set to NULL before msix_setup_interrupts() returns to msix_capability_init(). The "goto out_unmap" introduced by commit 1a8d4c6ecb4c ("PCI/MSI: Unmap MSI-X region on error") then calls iounmap() a second time on a NULL pointer.
This was reproduced on Intel Emerald Rapids (192 CPUs) while running tools/testing/selftests/kexec/test_kexec_jump.sh:
WARNING: CPU#44 at iounmap+0x2a/0xe0
RIP: 0010:iounmap+0x2a/0xe0 RDI: 0000000000000000 Call Trace: msix_capability_init+0x317/0x3f0 __pci_enable_msix_range+0x21d/0x2c0 pci_alloc_irq_vectors_affinity+0xa9/0x130 nvme_setup_io_queues+0x2a8/0x420 [nvme] nvme_reset_work+0x151/0x340 [nvme] ...
RDI=0 confirms iounmap() is called with NULL.
Restore the original "goto out_disable" and leave the unmap to the existing __free(free_msi_irqs) cleanup.
--- drivers/pci/msi/msi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/msi/msi.c +1 -3
@@ -737,7 +737,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, ret =msix_setup_interrupts (dev, entries, nvec, affd);if (ret) - goto out_unmap; + goto out_disable;/* Disable INTX */ pci_intx_for_msi (dev,0 );
@@ -758,8 +758,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,pcibios_free_irq (dev);return 0 ; -out_unmap: -iounmap (dev->msix_base); out_disable: dev->msix_enabled =0 ;pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_MASKALL |PCI_MSIX_FLAGS_ENABLE ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 733/1611 apparmor: fix shadowing of plabel that prevents cache from being updated
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 4483efe4f21510b30c24bc97d9fd0e8feab94125 ]
Unfortunately the plabel was being shadowed by an unused local var. This didn't affect the mediation check but did cauase the cache to not correctly be updated resulting in extra mediation checks.
--- security/apparmor/af_unix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
security/apparmor/af_unix.c +1 -2
@@ -758,11 +758,10 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,unix_fs_perm (op, request, subj_cred, label, is_unix_fs(peer_sk) ? &peer_path : NULL)); }else if (!is_sk_fs) { -struct aa_label *plabel;struct aa_sk_ctx *pctx =aa_sock (peer_sk);rcu_read_lock (); - plabel =aa_get_label_rcu (&pctx->label); + plabel =aa_get_newest_label (pctx->label);rcu_read_unlock ();/* no fs check of aa_unix_peer_perm because conditions above * ensure they will never be done
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 734/1611 apparmor: fix race in unix socket mediation when peer_path is used
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 b1aea2c1960771a276d7e68c7424168eccd0c3da ]
The holding a reference to the peer_sk is not enough to ensure access to the peer sk path. Accessing the path outside of the state lock allows for a race with unix_release_sock(). Fix this by taking the state lock and getting a reference to the path under lock.
Ideally for connected sockets we would cache this information so we don't have to take the lock here. But for now just fix the race.
--- security/apparmor/af_unix.c | 64 ++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 29 deletions(-)
security/apparmor/af_unix.c +35 -29
@@ -748,41 +748,47 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,if (!peer_sk) goto out; - peer_addr =aa_sunaddr (unix_sk (peer_sk), &peer_addrlen); - -struct path peer_path; - - peer_path =unix_sk (peer_sk)->path; -if (!is_sk_fs &&is_unix_fs (peer_sk)) { -last_error (error, -unix_fs_perm (op, request, subj_cred, label, -is_unix_fs (peer_sk) ? &peer_path :NULL )); - }else if (!is_sk_fs) { -struct aa_sk_ctx *pctx =aa_sock (peer_sk); - -rcu_read_lock (); - plabel =aa_get_newest_label (pctx->label); -rcu_read_unlock (); -/* no fs check of aa_unix_peer_perm because conditions above -* ensure they will never be done -*/ -last_error (error, -xcheck (unix_peer_perm (subj_cred, label, op, +if (!is_sk_fs) { +bool is_peer_fs =is_unix_fs (peer_sk); + + peer_addr =aa_sunaddr (unix_sk (peer_sk), &peer_addrlen); +if (is_peer_fs) { +struct path peer_path; + +unix_state_lock (peer_sk); + peer_path =unix_sk (peer_sk)->path; +if (peer_path.dentry) +path_get (&peer_path); +unix_state_unlock (peer_sk); + +last_error (error, +unix_fs_perm (op, request, subj_cred, label, + &peer_path)); +if (peer_path.dentry) +path_put (&peer_path); + }else { +struct aa_sk_ctx *pctx =aa_sock (peer_sk); + +rcu_read_lock (); + plabel =aa_get_newest_label (pctx->label); +rcu_read_unlock (); +/* no fs check of aa_unix_peer_perm because conditions +* above ensure they will never be done +*/ +last_error (error, +xcheck (unix_peer_perm (subj_cred, label, op,MAY_READ |MAY_WRITE , sock->sk, is_sk_fs ? &path :NULL , peer_addr, peer_addrlen, -is_unix_fs (peer_sk) ? - &peer_path :NULL , - plabel), -unix_peer_perm (file->f_cred, plabel, op, +NULL , plabel), +unix_peer_perm (file->f_cred, plabel, op,MAY_READ |MAY_WRITE , peer_sk, -is_unix_fs (peer_sk) ? - &peer_path :NULL , - addr, addrlen, +NULL , addr, addrlen, is_sk_fs ? &path :NULL , label))); -if (!error && !__aa_subj_label_is_cached (plabel, label)) -update_peer_ctx (peer_sk, pctx, label); +if (!error && !__aa_subj_label_is_cached (plabel, label)) +update_peer_ctx (peer_sk, pctx, label); + } }sock_put (peer_sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 735/1611 apparmor: fix refcount leak when updating the sk_ctx
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 6d25e7b47616cb2db43351210929c8f19dc305a3 ]
Currently update_sk_ctx() transfers the plabel reference, unfortunately it is also unconditionally put in the caller. Ideally we would make the caller conditionally put the reference based on whether it was transferred but for now just fix the bug by getting a reference.
--- security/apparmor/af_unix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
security/apparmor/af_unix.c +4 -2
@@ -674,9 +674,11 @@ static void update_sk_ctx(struct sock *sk, struct aa_label *label, old =rcu_dereference_protected (ctx->peer,lockdep_is_held (&unix_sk (sk)->lock));if (old == plabel) { -rcu_assign_pointer (ctx->peer_lastupdate, plabel); +rcu_assign_pointer (ctx->peer_lastupdate, +aa_get_label (plabel)); }else if (aa_label_is_subset (plabel, old)) { -rcu_assign_pointer (ctx->peer_lastupdate, plabel); +rcu_assign_pointer (ctx->peer_lastupdate, +aa_get_label (plabel));rcu_assign_pointer (ctx->peer,aa_get_label (plabel));aa_put_label (old); }/* else race or a subset - don't update */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 736/1611 security/apparmor/apparmorfs.c: conditionally compile get_loaddata_common_ref()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Morton <[email protected]>
[ Upstream commit d62d9bfe050f44f772d05a32079dba3e3523ab2a ]
Some config did this:
security/apparmor/apparmorfs.c:177:28: warning: 'get_loaddata_common_ref' defined but not used [-Wunused-function]
177 | static struct aa_loaddata *get_loaddata_common_ref(struct aa_common_ref *ref)
get_loaddata_common_ref() is only used ifCONFIG_SECURITY_APPARMOR_EXPORT_BINARY=y.
(Or of course move the function into that block if maintainers perfer)
--- security/apparmor/apparmorfs.c | 2 ++ 1 file changed, 2 insertions(+)
security/apparmor/apparmorfs.c +2 -0
@@ -174,6 +174,7 @@ static struct aa_proxy *get_proxy_common_ref(struct aa_common_ref *ref)return NULL ; } +#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY static struct aa_loaddata *get_loaddata_common_ref (struct aa_common_ref *ref) {if (ref)
@@ -181,6 +182,7 @@ static struct aa_loaddata *get_loaddata_common_ref(struct aa_common_ref *ref) count)); return NULL; } +#endif static void aa_put_common_ref (struct aa_common_ref *ref) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 737/1611 apparmor: check label build before no_new_privs test
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 a58cafd38b46fb1a2220e2fbbcfe291ea75fa147 ]
aa_change_profile() builds a replacement label with fn_label_build_in_scope() before the no_new_privs subset check. The build helper can fail and return NULL or an ERR_PTR, but the result was passed to aa_label_is_unconfined_subset() before the existing IS_ERR_OR_NULL() check.
Reuse the existing target-label build failure handling immediately after the build. This preserves the current audit handling while preventing the subset helper from dereferencing an invalid label.
--- security/apparmor/domain.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
security/apparmor/domain.c +15 -10
@@ -1525,6 +1525,8 @@ int aa_change_profile(const char *fqname, int flags) new =fn_label_build_in_ns (label, profile,GFP_KERNEL ,aa_get_label (target),aa_get_label (&profile->label)); +if (IS_ERR_OR_NULL (new)) + goto build_fail;/* * no new privs prevents domain transitions that would * reduce restrictions.
@@ -1543,16 +1545,8 @@ int aa_change_profile(const char *fqname, int flags)/* only transition profiles in the current ns */ if (stack) new =aa_label_merge (label, target,GFP_KERNEL ); -if (IS_ERR_OR_NULL (new)) { - info ="failed to build target label" ; -if (!new) - error = -ENOMEM ; -else - error =PTR_ERR (new); - new =NULL ; - perms.allow =0 ; - goto audit; - } +if (IS_ERR_OR_NULL (new)) + goto build_fail; error =aa_replace_current_label (new); }else {if (new) {
@@ -1564,6 +1558,17 @@ int aa_change_profile(const char *fqname, int flags)aa_set_current_onexec (target, stack); } + goto audit; + +build_fail: + info ="failed to build target label" ; +if (!new) + error = -ENOMEM ; +else + error =PTR_ERR (new); + new =NULL ; + perms.allow =0 ; + audit: error = fn_for_each_in_ns(label, profile, aa_audit_file(subj_cred,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 738/1611 apparmor: aa_label_alloc use aa_label_free on alloc failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit 654fe7505dc6889724d4094fa64f89991afabfc3 ]
aa_label_alloc() allocates a secid before allocating or taking the label proxy. If the later proxy step fails, the error path only freed the label memory, leaking any resources initialized by aa_label_init().
Use aa_label_free() on the failure path so partially initialized labels release their secid and other label resources before the backing memory is freed.
--- security/apparmor/label.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/label.c +1 -1
@@ -458,7 +458,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)return new; fail: -kfree (new); +aa_label_free (new);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 739/1611 apparmor: fix rawdata_f_data implicit flex array
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 ad213bbbc0e3e270ce7df2d9d80d4ce3826993d7 ]
rawdata_f_data has a blob of data that is allocated at its end but not explicitly declared. Makes sure it is correctly declared as a flex_rray.
--- security/apparmor/apparmorfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
security/apparmor/apparmorfs.c +3 -4
@@ -71,10 +71,10 @@struct rawdata_f_data {struct aa_loaddata *loaddata; + DECLARE_FLEX_ARRAY(char, data); };#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY -#define RAWDATA_F_DATA_BUF (p) (char *)(p + 1)static void rawdata_f_data_free (struct rawdata_f_data *private) {
@@ -1442,7 +1442,7 @@ static ssize_t rawdata_read(struct file *file, char __user *buf, size_t size,struct rawdata_f_data *private = file->private_data;return simple_read_from_buffer (buf, size, ppos, -RAWDATA_F_DATA_BUF (private), + private->data, private->loaddata->size); }
@@ -1475,8 +1475,7 @@ static int rawdata_open(struct inode *inode, struct file *file) private->loaddata = loaddata; error =decompress_zstd (loaddata->data, loaddata->compressed_size, -RAWDATA_F_DATA_BUF (private), - loaddata->size); + private->data, loaddata->size);if (error) goto fail_decompress;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 740/1611 apparmor: grab ns lock and refresh when looking up changehat child profiles
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Lee <[email protected]>
[ Upstream commit 32e92764d6f8d251c1bca62be33793287b453a81 ]
There was a race condition involving change_hat and profile replacement in which replacement of the parent profile during a changehat operation could result in the list of children becoming empty and the changehat operation failing. To prevent this:
- grab the namespace lock until we've built the hat transition, and
- use aa_get_newest_profile to avoid using stale profile objects.
--- security/apparmor/domain.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
security/apparmor/domain.c +31 -2
@@ -12,6 +12,7 @@#include <linux/fs.h> #include <linux/file.h> #include <linux/mount.h> +#include <linux/mutex.h> #include <linux/syscalls.h> #include <linux/personality.h> #include <linux/xattr.h>
@@ -1107,6 +1108,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, int count, int flags) {struct aa_profile *profile, *root, *hat =NULL ; +struct aa_ns *ns, *new_ns;struct aa_label *new;struct label_it it;bool sibling = false;
@@ -1117,6 +1119,32 @@ static struct aa_label *change_hat(const struct cred *subj_cred,AA_BUG (!hats);AA_BUG (count <1 ); +/* +* Acquire the newest label and then hold the lock until we choose a +* hat, so that profile replacement doesn't atomically truncate the +* list of potential hats. Because we are getting the namespaces from +* the profiles and label, we can rely on the namespaces being live +* and avoid incrementing their refcounts while grabbing the lock. +*/ + label =aa_get_label (label); + ns =labels_ns (label); + +retry: +mutex_lock_nested (&ns->lock, ns->level); +if (label_is_stale (label)) { + new =aa_get_newest_label (label); + new_ns =labels_ns (new); +if (new_ns != ns) { +aa_put_label (new); +mutex_unlock (&ns->lock); + ns = new_ns; + label = new; + goto retry; + } +aa_put_label (label); + label = new; + } +if (PROFILE_IS_HAT (labels_profile (label))) sibling = true;
@@ -1125,7 +1153,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, name = hats[i];label_for_each_in_ns (it,labels_ns (label), label, profile) {if (sibling &&PROFILE_IS_HAT (profile)) { - root =aa_get_profile_rcu (&profile->parent); + root =aa_get_profile (profile->parent); }else if (!sibling && !PROFILE_IS_HAT (profile)) { root =aa_get_profile (profile); }else {/* conflicting change type */
@@ -1185,6 +1213,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, GLOBAL_ROOT_UID, info, error); } } +mutex_unlock (&ns->lock);return ERR_PTR (error); build:
@@ -1197,7 +1226,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, error = -ENOMEM ; goto fail; }/* else if (IS_ERR) build_change_hat has logged error so return new */ - +mutex_unlock (&ns->lock);return new; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 741/1611 apparmor: fix potential UAF in aa_replace_profiles
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Bélair <[email protected]>
[ Upstream commit 7b42f95813dc9ceb6bda35afcf914630909a19f9 ]
The function aa_replace_profiles was accessing udata->size after calling aa_put_loaddata(udata), causing a potential UAF.
Fixed this by saving the size to a local variable before dropping the reference.
--- security/apparmor/policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
security/apparmor/policy.c +3 -1
@@ -1358,13 +1358,15 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,mutex_unlock (&ns->lock); out: +ssize_t udata_sz = udata->size; +aa_put_ns (ns);aa_put_profile_loaddata (udata);kfree (ns_name);if (error)return error; -return udata->size; +return udata_sz; fail_lock:mutex_unlock (&ns->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 742/1611 apparmor: fix NULL pointer dereference in unpack_pdb
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgia Garcia <[email protected]>
[ Upstream commit 7681ca43d2b1c776e62fe77e3167835fb1ab8319 ]
pdb->dfa could be NULL if unpack_dfa fails, causing a NULL pointer dereference.
--- security/apparmor/policy_unpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/policy_unpack.c +1 -1
@@ -804,7 +804,7 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy, }/* accept2 is in some cases being allocated, even with perms */ -if (pdb->perms && !pdb->dfa->tables[YYTD_ID_ACCEPT2 ]) { +if (pdb->dfa && pdb->perms && !pdb->dfa->tables[YYTD_ID_ACCEPT2 ]) {/* add dfa flags table missing in v2 */ u32 noents = pdb->dfa->tables[YYTD_ID_ACCEPT ]->td_lolen;u16 tdflags = pdb->dfa->tables[YYTD_ID_ACCEPT ]->td_flags;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 743/1611 apparmor: remove or add symlinks to rawdata according to export_binary
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgia Garcia <[email protected]>
[ Upstream commit 59fe6fbc4cd45582bc8893de0a382a36562317b3 ]
When the export_binary parameter is set, then rawdata is available and there should be a symbolic link for the rawdata in the profile directory in apparmorfs. If the parameter is unset, then the symlinks should not exist.
The issue arises when changing the value of export_binary on runtime and replacing profiles. If export_binary was set when the profile was originally loaded, then changed to 0 and the profile was reloaded, then the symbolic links would still exist but would return ENOENT because the rawdata no longer exists.
On the opposite side, if export_binary was unset when the profile was originally loaded, then changed to 1 and the profile was reloaded, then the symbolic links would not exist, even though the rawdata does.
--- security/apparmor/apparmorfs.c | 102 +++++++++++++++++++------ security/apparmor/include/apparmorfs.h | 12 +++ security/apparmor/policy.c | 15 ++++ 3 files changed, 104 insertions(+), 25 deletions(-)
security/apparmor/apparmorfs.c +77 -25
@@ -1759,6 +1759,80 @@ static const struct inode_operations rawdata_link_abi_iops = {static const struct inode_operations rawdata_link_data_iops = { .get_link = rawdata_get_link_data, }; + +/* +* Requires: @profile->ns->lock held +*/ +void __aa_remove_rawdata_symlink_dents (struct aa_profile *profile) +{ +aafs_remove (profile->dents[AAFS_PROF_RAW_HASH ]); + profile->dents[AAFS_PROF_RAW_HASH ] =NULL ; +aafs_remove (profile->dents[AAFS_PROF_RAW_ABI ]); + profile->dents[AAFS_PROF_RAW_ABI ] =NULL ; +aafs_remove (profile->dents[AAFS_PROF_RAW_DATA ]); + profile->dents[AAFS_PROF_RAW_DATA ] =NULL ; +} + +static inline int create_symlink_dent (struct aa_profile *profile, +const char *name, +enum aafs_prof_type type, +const struct inode_operations *iops) +{ +struct dentry *dent =NULL ; +struct dentry *dir =prof_dir (profile); + +if (profile->dents[type]) +return 0 ; + + dent =aafs_create (name,S_IFLNK |0444 , dir, + &profile->label.proxy->count,NULL ,NULL , iops); +if (IS_ERR (dent)) +return PTR_ERR (dent); + + profile->dents[type] = dent; +return 0 ; +} + +/* +* Requires: @profile->ns->lock held +*/ +int __aa_create_rawdata_symlink_dents (struct aa_profile *profile) +{ +int error; + +if (!profile || + (profile->dents[AAFS_PROF_RAW_HASH ] && + profile->dents[AAFS_PROF_RAW_ABI ] && + profile->dents[AAFS_PROF_RAW_DATA ])) +return 0 ; + +if (!profile->rawdata) +return 0 ; + +if (aa_g_hash_policy) { + error =create_symlink_dent (profile,"raw_sha256" , +AAFS_PROF_RAW_HASH , + &rawdata_link_sha256_iops); +if (error) +return error; + } + + error =create_symlink_dent (profile,"raw_abi" , +AAFS_PROF_RAW_ABI , + &rawdata_link_abi_iops); +if (error) +return error; + + + error =create_symlink_dent (profile,"raw_data" , +AAFS_PROF_RAW_DATA , + &rawdata_link_data_iops); +if (error) +return error; + +return 0 ; +} +#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */ /*
@@ -1834,31 +1908,9 @@ int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent) profile->dents[AAFS_PROF_HASH ] = dent; } -#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY -if (profile->rawdata) { -if (aa_g_hash_policy) { - dent =aafs_create ("raw_sha256" ,S_IFLNK |0444 , dir, - &profile->label.proxy->count,NULL , -NULL , &rawdata_link_sha256_iops); -if (IS_ERR (dent)) - goto fail; - profile->dents[AAFS_PROF_RAW_HASH ] = dent; - } - dent =aafs_create ("raw_abi" ,S_IFLNK |0444 , dir, - &profile->label.proxy->count,NULL ,NULL , - &rawdata_link_abi_iops); -if (IS_ERR (dent)) - goto fail; - profile->dents[AAFS_PROF_RAW_ABI ] = dent; - - dent =aafs_create ("raw_data" ,S_IFLNK |0444 , dir, - &profile->label.proxy->count,NULL ,NULL , - &rawdata_link_data_iops); -if (IS_ERR (dent)) - goto fail; - profile->dents[AAFS_PROF_RAW_DATA ] = dent; - } -#endif /*CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */ + error =__aa_create_rawdata_symlink_dents (profile); +if (error) + goto fail2;list_for_each_entry (child, &profile->base.profiles, base.list) { error =__aafs_profile_mkdir (child,prof_child_dir (profile));
security/apparmor/include/apparmorfs.h +12 -0
@@ -118,6 +118,8 @@ struct aa_loaddata;#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY void __aa_fs_remove_rawdata (struct aa_loaddata *rawdata);int __aa_fs_create_rawdata (struct aa_ns *ns,struct aa_loaddata *rawdata); +void __aa_remove_rawdata_symlink_dents (struct aa_profile *profile); +int __aa_create_rawdata_symlink_dents (struct aa_profile *profile);#else static inline void __aa_fs_remove_rawdata (struct aa_loaddata *rawdata) {
@@ -129,6 +131,16 @@ static inline int __aa_fs_create_rawdata(struct aa_ns *ns, {return 0 ; } + +static inline void __aa_remove_rawdata_symlink_dents (struct aa_profile *profile) +{ +/* empty stub */ +} + +static inline int __aa_create_rawdata_symlink_dents (struct aa_profile *profile) +{ +return 0 ; +}#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */ #endif /* __AA_APPARMORFS_H */
security/apparmor/policy.c +15 -0
@@ -1329,6 +1329,16 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label, goto skip; } +if (!aa_g_export_binary) { +if (ent->old && ent->old->rawdata && + ent->old->dents[AAFS_LOADDATA_DIR ]) { +/* remove rawdata symlinks because the symlink +* target will be removed +*/ +__aa_remove_rawdata_symlink_dents (ent->old); + } + } +/* * TODO: finer dedup based on profile range in data. Load set * can differ but profile may remain unchanged
@@ -1339,6 +1349,11 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,if (ent->old) {share_name (ent->old, ent->new);__replace_profile (ent->old, ent->new); +if (aa_g_export_binary) { +/* recreate rawdata symlinks */ +if (!ent->old->rawdata) +__aa_create_rawdata_symlink_dents (ent->new); + } }else {struct list_head *lh;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 744/1611 apparmor: Fix return in ns_mkdir_op
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit b7a2b49bba4e5994a476c49d662b796818079e5e ]
Return NULL instead of passing to ERR_PTR while error is zero.
Fixes smatch warning:
- security/apparmor/apparmorfs.c:1846 ns_mkdir_op() warn:
passing zero to 'ERR_PTR'
--- security/apparmor/apparmorfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/apparmorfs.c +1 -1
@@ -1977,7 +1977,7 @@ static struct dentry *ns_mkdir_op(struct mnt_idmap *idmap, struct inode *dir,mutex_unlock (&parent->lock);aa_put_ns (parent); -return ERR_PTR (error); +return error ?ERR_PTR (error) :NULL ; }static int ns_rmdir_op (struct inode *dir,struct dentry *dentry)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 745/1611 apparmor: fail policy unpack on accept2 allocation failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit 45cf568241048e560a81aa2053f06a62069f5640 ]
unpack_pdb() may need to allocate a missing ACCEPT2 table for older policy data. If that allocation failed, it set an error message but jumped to the success path, returning a policydb with the required table missing.
Return -ENOMEM through the normal failure path when the ACCEPT2 allocation fails. Remove the now-unused out label.
--- security/apparmor/policy_unpack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/apparmor/policy_unpack.c +2 -2
@@ -813,7 +813,8 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy, pdb->dfa->tables[YYTD_ID_ACCEPT2 ] =kvzalloc (tsize,GFP_KERNEL );if (!pdb->dfa->tables[YYTD_ID_ACCEPT2 ]) { *info ="failed to alloc dfa flags table" ; - goto out; + error = -ENOMEM ; + goto fail; } pdb->dfa->tables[YYTD_ID_ACCEPT2 ]->td_lolen = noents; pdb->dfa->tables[YYTD_ID_ACCEPT2 ]->td_flags = tdflags;
@@ -837,7 +838,6 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy,* - move free of unneeded trans table here, has to be done * after perm mapping. */ -out: *policy = pdb;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 746/1611 apparmor: aa_getprocattr free procattr leak on format failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit fea23bf73f0cae8ccb1d0684e4a3003874771f41 ]
aa_getprocattr() allocates the output string before rendering the label into it. If the second aa_label_snxprint() call fails, the function returned without freeing that allocation.
Free and clear the output pointer on the uncommon formatting failure path before dropping the namespace reference.
--- security/apparmor/procattr.c | 2 ++ 1 file changed, 2 insertions(+)
security/apparmor/procattr.c +2 -0
@@ -54,6 +54,8 @@ int aa_getprocattr(struct aa_label *label, char **string, bool newline)FLAG_SHOW_MODE |FLAG_VIEW_SUBNS | FLAG_HIDDEN_UNCONFINED);if (len <0 ) { +kfree (*string); + *string =NULL ;aa_put_ns (current_ns);return len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 747/1611 apparmor: put secmark label after secid lookup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit 340372688bb87da45ff8d4e2f82ccfd1b64c65ff ]
apparmor_secmark_init() parses a configured secmark label to obtain its secid. aa_label_strn_parse() returns a refcounted label, but the success path kept that reference after copying the secid.
--- security/apparmor/net.c | 1 + 1 file changed, 1 insertion(+)
security/apparmor/net.c +1 -0
@@ -356,6 +356,7 @@ static int apparmor_secmark_init(struct aa_secmark *secmark)return PTR_ERR (label); secmark->secid = label->secid; +aa_put_label (label);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 748/1611 apparmor: dont audit files pointing to aa_null.dentry
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgia Garcia <[email protected]>
[ Upstream commit add2b70038bea194bcdef8a680f9153ee7f93ac0 ]
In
commit 4a134723f9f1 ("apparmor: move check for aa_null file to cover all cases")
there was a change to not audit files pointing to
aa_null.dentry because they provide no value, but setting the error variable instead of returning -EACCES was still causing them to be audited.
--- security/apparmor/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/file.c +1 -1
@@ -156,7 +156,7 @@ static int path_name(const char *op, const struct cred *subj_cred,/* don't reaudit files closed during inheritance */ if (unlikely (path->dentry == aa_null.dentry)) - error = -EACCES ; +return -EACCES ;else error =aa_path_name (path, flags, buffer, name, &info,labels_profile (label)->disconnected);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 749/1611 apparmor: fix uninitialised pointer passed to audit_log_untrustedstring()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciek Borzecki <[email protected]>
[ Upstream commit bcd1b34c21748531a3febaf7440632b89d8deab7 ]
Commit 4a134723f9f1 ("apparmor: move check for aa_null file to cover all cases") intrdouced a small bug, where path_name() may pass a potentially uninitialized *name to aa_audit_file() if the path->dentry had been replaced with aa_null.dentry earlier on. This can lead to page fault like one observed on 7.0.2 openSUSE Tumbleweed kernel:
[51692.242756] [ T24690] BUG: unable to handle page fault for address: 0000000f00000003 [51692.242762] [ T24690] #PF: supervisor read access in kernel mode [51692.242763] [ T24690] #PF: error_code(0x0000) - not-present page [51692.242765] [ T24690] PGD 0 P4D 0 [51692.242768] [ T24690] Oops: Oops: 0000 [#1] SMP NOPTI [51692.242772] [ T24690] CPU: 3 UID: 1020 PID: 24690 Comm: snap-confine Tainted: G O 7.0.2-1-default #1 PREEMPT(full) openSUSE Tumbleweed ab90b4c9940707f9cafa19bdad80b2cec52dbe51 [51692.242775] [ T24690] Tainted: [O]=OOT_MODULE [51692.242777] [ T24690] Hardware name: Framework Laptop 13 (AMD Ryzen 7040Series)/FRANMDCP05, BIOS 03.18 01/08/2026 [51692.242778] [ T24690] RIP: 0010:strlen+0x4/0x30 [51692.242783] [ T24690] Code: f7 75 ec 31 c0 e9 17 9f 00 ff 48 89 f8 e9 0f 9f 00 ff 0f 1f 40 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa <80> 3f 00 74 18 48 89 f8 0f 1f 40 00 48 83 c0 01 80 38 00 75 f7 48 [51692.242785] [ T24690] RSP: 0018:ffffd015eb1e3608 EFLAGS: 00010282 [51692.242787] [ T24690] RAX: 0000000000000000 RBX: ffff89796198a360 RCX: 0000000000000000 [51692.242788] [ T24690] RDX: 00000000000000d1 RSI: 0000000f00000003 RDI: 0000000f00000003 [51692.242790] [ T24690] RBP: ffffffffb7ede090 R08: 00000000000005f5 R09: 0000000000000000 [51692.242791] [ T24690] R10: 0000000000000000 R11: 0000000000000000 R12: ffffd015eb1e3700 [51692.242792] [ T24690] R13: ffff8977a22bc380 R14: ffffffffb7ec5190 R15: ffff8977a0c8aa80 [51692.242794] [ T24690] FS: 0000000000000000(0000) GS:ffff897f640d8000(0000) knlGS:0000000000000000 [51692.242796] [ T24690] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [51692.242797] [ T24690] CR2: 0000000f00000003 CR3: 00000006ad15f000 CR4: 0000000000f50ef0 [51692.242799] [ T24690] PKRU: 55555554 [51692.242800] [ T24690] Call Trace: [51692.242802] [ T24690] <TASK> [51692.242804] [ T24690] audit_log_untrustedstring+0x1d/0x40 [51692.242811] [ T24690] common_lsm_audit+0x71/0x1d0 [51692.242816] [ T24690] aa_audit+0x5a/0x170 [51692.242819] [ T24690] aa_audit_file+0x18a/0x1b0 [51692.242825] [ T24690] path_name+0xd2/0x100 [51692.242829] [ T24690] profile_path_perm.part.0+0x58/0xb0 [51692.242832] [ T24690] aa_path_perm+0xef/0x150 [51692.242837] [ T24690] apparmor_file_open+0x153/0x2e0 [51692.242840] [ T24690] security_file_open+0x46/0xd0 [51692.242844] [ T24690] do_dentry_open+0xe9/0x4d0 [51692.242848] [ T24690] vfs_open+0x30/0x100
While here, initialise variables which are passed down to path_name().
--- security/apparmor/file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
security/apparmor/file.c +5 -5
@@ -157,9 +157,9 @@ static int path_name(const char *op, const struct cred *subj_cred,/* don't reaudit files closed during inheritance */ if (unlikely (path->dentry == aa_null.dentry))return -EACCES ; -else - error =aa_path_name (path, flags, buffer, name, &info, -labels_profile (label)->disconnected); + + error =aa_path_name (path, flags, buffer, name, &info, +labels_profile (label)->disconnected);if (error) { fn_for_each_confined(label, profile, aa_audit_file(subj_cred,
@@ -249,7 +249,7 @@ static int profile_path_perm(const char *op, const struct cred *subj_cred, struct path_cond *cond, int flags, struct aa_perms *perms) { - const char *name; + const char *name = NULL;int error;if (profile_unconfined (profile))
@@ -327,7 +327,7 @@ static int profile_path_link(const struct cred *subj_cred, struct path_cond *cond) {struct aa_ruleset *rules = profile->label.rules[0 ]; -const char *lname, *tname =NULL ; +const char *lname =NULL , *tname =NULL ;struct aa_perms lperms = {}, perms;const char *info =NULL ;u32 request =AA_MAY_LINK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 750/1611 i3c: mipi-i3c-hci: Quieten initialization messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 581d5b7953b8f24d2f379c8c56ceaa7d163488ce ]
The copious initialization messages are at most useful only for debugging. Change them from dev_info() or dev_notice() to dev_dbg().
Stable-dep-of: 093eb8e73c90 ("i3c: mipi-i3c-hci: Preserve RUN bit when aborting DMA ring")
--- drivers/i3c/master/mipi-i3c-hci/core.c | 18 +++---- drivers/i3c/master/mipi-i3c-hci/dma.c | 4 +- drivers/i3c/master/mipi-i3c-hci/ext_caps.c | 55 ++++++++++------------ drivers/i3c/master/mipi-i3c-hci/pio.c | 16 +++---- 4 files changed, 45 insertions(+), 48 deletions(-)
drivers/i3c/master/mipi-i3c-hci/core.c +9 -9
@@ -599,8 +599,8 @@ static int i3c_hci_init(struct i3c_hci *hci) hci->DAT_entry_size =FIELD_GET (DAT_ENTRY_SIZE , regval) ?0 :8 ;if (size_in_dwords) hci->DAT_entries =4 * hci->DAT_entries / hci->DAT_entry_size; -dev_info (&hci->master.dev,"DAT: %u %u-bytes entries at offset %#x\n" , - hci->DAT_entries, hci->DAT_entry_size, offset); +dev_dbg (&hci->master.dev,"DAT: %u %u-bytes entries at offset %#x\n" , + hci->DAT_entries, hci->DAT_entry_size, offset); regval =reg_read (DCT_SECTION ); offset =FIELD_GET (DCT_TABLE_OFFSET , regval);
@@ -609,23 +609,23 @@ static int i3c_hci_init(struct i3c_hci *hci) hci->DCT_entry_size =FIELD_GET (DCT_ENTRY_SIZE , regval) ?0 :16 ;if (size_in_dwords) hci->DCT_entries =4 * hci->DCT_entries / hci->DCT_entry_size; -dev_info (&hci->master.dev,"DCT: %u %u-bytes entries at offset %#x\n" , - hci->DCT_entries, hci->DCT_entry_size, offset); +dev_dbg (&hci->master.dev,"DCT: %u %u-bytes entries at offset %#x\n" , + hci->DCT_entries, hci->DCT_entry_size, offset); regval =reg_read (RING_HEADERS_SECTION ); offset =FIELD_GET (RING_HEADERS_OFFSET , regval); hci->RHS_regs = offset ? hci->base_regs + offset :NULL ; -dev_info (&hci->master.dev,"Ring Headers at offset %#x\n" , offset); +dev_dbg (&hci->master.dev,"Ring Headers at offset %#x\n" , offset); regval =reg_read (PIO_SECTION ); offset =FIELD_GET (PIO_REGS_OFFSET , regval); hci->PIO_regs = offset ? hci->base_regs + offset :NULL ; -dev_info (&hci->master.dev,"PIO section at offset %#x\n" , offset); +dev_dbg (&hci->master.dev,"PIO section at offset %#x\n" , offset); regval =reg_read (EXT_CAPS_SECTION ); offset =FIELD_GET (EXT_CAPS_OFFSET , regval); hci->EXTCAPS_regs = offset ? hci->base_regs + offset :NULL ; -dev_info (&hci->master.dev,"Extended Caps at offset %#x\n" , offset); +dev_dbg (&hci->master.dev,"Extended Caps at offset %#x\n" , offset); ret =i3c_hci_parse_ext_caps (hci);if (ret)
@@ -710,7 +710,7 @@ static int i3c_hci_init(struct i3c_hci *hci) ret = -EIO ; }else { hci->io = &mipi_i3c_hci_dma; -dev_info (&hci->master.dev,"Using DMA\n" ); +dev_dbg (&hci->master.dev,"Using DMA\n" ); } }
@@ -722,7 +722,7 @@ static int i3c_hci_init(struct i3c_hci *hci) ret = -EIO ; }else { hci->io = &mipi_i3c_hci_pio; -dev_info (&hci->master.dev,"Using PIO\n" ); +dev_dbg (&hci->master.dev,"Using PIO\n" ); } }
drivers/i3c/master/mipi-i3c-hci/dma.c +2 -2
@@ -213,7 +213,7 @@ static int hci_dma_init(struct i3c_hci *hci) regval =rhs_reg_read (CONTROL ); nr_rings =FIELD_GET (MAX_HEADER_COUNT_CAP , regval); -dev_info (&hci->master.dev,"%d DMA rings available\n" , nr_rings); +dev_dbg (&hci->master.dev,"%d DMA rings available\n" , nr_rings);if (unlikely (nr_rings >8 )) {dev_err (&hci->master.dev,"number of rings should be <= 8\n" ); nr_rings =8 ;
@@ -233,7 +233,7 @@ static int hci_dma_init(struct i3c_hci *hci)for (i =0 ; i < rings->total; i++) {u32 offset =rhs_reg_read (RHn_OFFSET (i)); -dev_info (&hci->master.dev,"Ring %d at offset %#x\n" , i, offset); +dev_dbg (&hci->master.dev,"Ring %d at offset %#x\n" , i, offset); ret = -EINVAL ;if (!offset) goto err_out;
drivers/i3c/master/mipi-i3c-hci/ext_caps.c +26 -29
154 lines not on this page · raw message
drivers/i3c/master/mipi-i3c-hci/pio.c +8 -8
@@ -147,14 +147,14 @@ static int hci_pio_init(struct i3c_hci *hci) hci->io_data = pio; size_val =pio_reg_read (QUEUE_SIZE ); -dev_info (&hci->master.dev,"CMD/RESP FIFO = %ld entries\n" , -FIELD_GET (CR_QUEUE_SIZE , size_val)); -dev_info (&hci->master.dev,"IBI FIFO = %ld bytes\n" , -4 *FIELD_GET (IBI_STATUS_SIZE , size_val)); -dev_info (&hci->master.dev,"RX data FIFO = %d bytes\n" , -4 * (2 <<FIELD_GET (RX_DATA_BUFFER_SIZE , size_val))); -dev_info (&hci->master.dev,"TX data FIFO = %d bytes\n" , -4 * (2 <<FIELD_GET (TX_DATA_BUFFER_SIZE , size_val))); +dev_dbg (&hci->master.dev,"CMD/RESP FIFO = %ld entries\n" , +FIELD_GET (CR_QUEUE_SIZE , size_val)); +dev_dbg (&hci->master.dev,"IBI FIFO = %ld bytes\n" , +4 *FIELD_GET (IBI_STATUS_SIZE , size_val)); +dev_dbg (&hci->master.dev,"RX data FIFO = %d bytes\n" , +4 * (2 <<FIELD_GET (RX_DATA_BUFFER_SIZE , size_val))); +dev_dbg (&hci->master.dev,"TX data FIFO = %d bytes\n" , +4 * (2 <<FIELD_GET (TX_DATA_BUFFER_SIZE , size_val)));/* * Let's initialize data thresholds to half of the actual FIFO size.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 751/1611 i3c: mipi-i3c-hci: Allow for Multi-Bus Instances
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit b8460480f62e16751876a1f367dc14fb62867463 ]
Add support for MIPI I3C Host Controllers with the Multi-Bus Instance capability. These controllers can host multiple I3C buses (up to 15) within a single hardware function (e.g., PCIe B/D/F), providing one indepedent HCI register set and corresponding I3C bus controller logic per bus.
A separate platform device will represent each instance, but it is necessary to allow for shared resources.
Multi-bus instances share the same MMIO address space, but the ranges are not guaranteed to be contiguous. To avoid overlapping mappings, pass base_regs from the parent mapping to child devices.
Allow the IRQ to be shared among instances.
Stable-dep-of: 093eb8e73c90 ("i3c: mipi-i3c-hci: Preserve RUN bit when aborting DMA ring")
--- drivers/i3c/master/mipi-i3c-hci/core.c | 21 +++++++++++++++++---- include/linux/platform_data/mipi-i3c-hci.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 include/linux/platform_data/mipi-i3c-hci.h
drivers/i3c/master/mipi-i3c-hci/core.c +17 -4
@@ -14,6 +14,7 @@#include <linux/interrupt.h> #include <linux/iopoll.h> #include <linux/module.h> +#include <linux/platform_data/mipi-i3c-hci.h> #include <linux/platform_device.h> #include "hci.h"
@@ -742,15 +743,27 @@ static int i3c_hci_init(struct i3c_hci *hci)static int i3c_hci_probe (struct platform_device *pdev) { +const struct mipi_i3c_hci_platform_data *pdata = pdev->dev.platform_data;struct i3c_hci *hci;int irq, ret; hci =devm_kzalloc (&pdev->dev,sizeof (*hci),GFP_KERNEL );if (!hci)return -ENOMEM ; - hci->base_regs =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (hci->base_regs)) -return PTR_ERR (hci->base_regs); + +/* +* Multi-bus instances share the same MMIO address range, but not +* necessarily in separate contiguous sub-ranges. To avoid overlapping +* mappings, provide base_regs from the parent mapping. +*/ +if (pdata) + hci->base_regs = pdata->base_regs; + +if (!hci->base_regs) { + hci->base_regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (hci->base_regs)) +return PTR_ERR (hci->base_regs); + }platform_set_drvdata (pdev, hci);/* temporary for dev_printk's, to be replaced in i3c_master_register */
@@ -764,7 +777,7 @@ static int i3c_hci_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 ); ret =devm_request_irq (&pdev->dev, irq, i3c_hci_irq_handler, -0 ,NULL , hci); +IRQF_SHARED ,NULL , hci);if (ret)return ret;
include/linux/platform_data/mipi-i3c-hci.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef INCLUDE_PLATFORM_DATA_MIPI_I3C_HCI_H +#define INCLUDE_PLATFORM_DATA_MIPI_I3C_HCI_H + +#include <linux/compiler_types.h> + +/** +* struct mipi_i3c_hci_platform_data - Platform-dependent data for mipi_i3c_hci +* @base_regs: Register set base address (to support multi-bus instances) +*/ +struct mipi_i3c_hci_platform_data { +void __iomem *base_regs; +}; + +#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 752/1611 i3c: mipi-i3c-hci: Switch PIO data allocation to devm_kzalloc()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 11d17c2855bfc04550557017eae02e92f3eeab1c ]
The driver already uses managed resources, so convert the PIO data structure allocation to devm_zalloc(). Remove the manual kfree().
Stable-dep-of: 093eb8e73c90 ("i3c: mipi-i3c-hci: Preserve RUN bit when aborting DMA ring")
--- drivers/i3c/master/mipi-i3c-hci/pio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i3c/master/mipi-i3c-hci/pio.c +1 -3
@@ -140,7 +140,7 @@ static int hci_pio_init(struct i3c_hci *hci)struct hci_pio_data *pio;u32 val, size_val, rx_thresh, tx_thresh, ibi_val; - pio =kzalloc (sizeof (*pio),GFP_KERNEL ); + pio =devm_kzalloc (hci->master.dev.parent,sizeof (*pio),GFP_KERNEL );if (!pio)return -ENOMEM ;
@@ -217,8 +217,6 @@ static void hci_pio_cleanup(struct i3c_hci *hci)BUG_ON (pio->curr_rx);BUG_ON (pio->curr_tx);BUG_ON (pio->curr_resp); -kfree (pio); - hci->io_data =NULL ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 753/1611 i3c: mipi-i3c-hci: Preserve RUN bit when aborting DMA ring
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 093eb8e73c90aa0c8cfb0421aa85bd70c23488be ]
The MIPI I3C HCI specification does not require the DMA ring RUN bit (RUN_STOP) to be cleared when issuing an ABORT. That allows the DMA ring to continue to receive IBIs, although an IBI is anyway not lost because it can be received once the ring restarts if the I3C device has not given up. Note, currently ABORT is only used on a timeout error path so the change has very little effect in practice. In the more common case of a transfer error, the ring (bundle) operation is halted by the controller anyway.
Adjust the RING_CONTROL handling to set ABORT without clearing RUN_STOP, bringing the driver into alignment with the specification.
--- drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master/mipi-i3c-hci/dma.c +1 -1
@@ -493,7 +493,7 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci,if (ring_status &RING_STATUS_RUNNING ) {/* stop the ring */ reinit_completion (&rh->op_done); -rh_reg_write (RING_CONTROL ,RING_CTRL_ENABLE |RING_CTRL_ABORT ); +rh_reg_write (RING_CONTROL ,rh_reg_read (RING_CONTROL ) |RING_CTRL_ABORT );wait_for_completion_timeout (&rh->op_done,HZ ); ring_status =rh_reg_read (RING_STATUS );if (ring_status &RING_STATUS_RUNNING ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 754/1611 i3c: master: add WQ_PERCPU to alloc_workqueue users
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Crivellari <[email protected]>
[ Upstream commit de53ad6ca49e5d73bba72d24b49ec5d40f33ee01 ]
Currently if a user enqueues a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistency cannot be addressed without refactoring the API.
alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated.
This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
Stable-dep-of: 527756cb9ebb ("i3c: master: Make hot-join workqueue freezable to block hot-join during suspend")
--- drivers/i3c/master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master.c +1 -1
@@ -2927,7 +2927,7 @@ int i3c_master_register(struct i3c_master_controller *master,if (ret) goto err_put_dev; - master->wq =alloc_workqueue ("%s" ,0 ,0 ,dev_name (parent)); + master->wq =alloc_workqueue ("%s" ,WQ_PERCPU ,0 ,dev_name (parent));if (!master->wq) { ret = -ENOMEM ; goto err_put_dev;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 755/1611 i3c: master: Make hot-join workqueue freezable to block hot-join during suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 527756cb9ebb277dca12fff00af9fbb3b9ec8cc8 ]
The I3C master workqueue (master->wq) is used to defer work that needs thread context and the bus maintenance lock, most notably Hot Join processing (which calls i3c_master_do_daa() to assign dynamic addresses to newly joined devices).
Currently the workqueue keeps running across system suspend, which can race with the suspend path:
- do_daa() may execute after the controller has been suspended, issuing bus transactions on a powered-down or otherwise unusable controller.
- New I3C devices can be enumerated and added to the bus mid-suspend, registering driver model objects at a point where the I3C subsystem and its consumers are not prepared to handle them.
Mark the workqueue WQ_FREEZABLE so its workers are frozen for the duration of system suspend/hibernate and resumed afterwards. This naturally defers any pending or newly queued Hot Join work until the system (and the controller) is fully resumed, closing both races without adding explicit suspend/resume synchronization in the master drivers.
Update the kerneldoc for struct i3c_master_controller::wq to reflect that the workqueue is freezable.
--- drivers/i3c/master.c | 2 +- include/linux/i3c/master.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/i3c/master.c +1 -1
@@ -2927,7 +2927,7 @@ int i3c_master_register(struct i3c_master_controller *master,if (ret) goto err_put_dev; - master->wq =alloc_workqueue ("%s" ,WQ_PERCPU ,0 ,dev_name (parent)); + master->wq =alloc_workqueue ("%s" ,WQ_PERCPU |WQ_FREEZABLE ,0 ,dev_name (parent));if (!master->wq) { ret = -ENOMEM ; goto err_put_dev;
include/linux/i3c/master.h +1 -1
@@ -509,7 +509,7 @@ struct i3c_master_controller_ops {* @boardinfo.i2c: list of I2C boardinfo objects * @boardinfo: board-level information attached to devices connected on the bus * @bus: I3C bus exposed by this master -* @wq: workqueue which can be used by master +* @wq: freezable workqueue which can be used by master * drivers if they need to postpone operations that need to take place * in a thread context. Typical examples are Hot Join processing which * requires taking the bus lock in maintenance, which in turn, can only
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 756/1611 i3c: add sysfs entry and attribute for Device NACK Retry count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Ng Ho Yin <[email protected]>
[ Upstream commit b58f47eb392680d4c6626c8b3b1fcf6412a0a02c ]
Document sysfs attribute dev_nack_retry_cnt that controls the number of automatic retries performed by the I3C controller when a target device returns a NACK
Add a dev_nack_retry_count sysfs attribute to allow reading and updating the device NACK retry count. A new dev_nack_retry_count field and an optional set_dev_nack_retry() callback are added to i3c_master_controller. The attribute is created only when the callback is implemented.
Updates are applied under the I3C bus maintenance lock to ensure safe hardware reconfiguration.
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- Documentation/ABI/testing/sysfs-bus-i3c | 11 +++++++ drivers/i3c/master.c | 39 +++++++++++++++++++++++++ include/linux/i3c/master.h | 6 ++++ 3 files changed, 56 insertions(+)
Documentation/ABI/testing/sysfs-bus-i3c +11 -0
@@ -161,3 +161,14 @@ Contact: [email protected] Description: These directories are just symbolic links to /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dev_nack_retry_count +KernelVersion: 6.18 +Contact: [email protected] +Description: + Expose the dev_nak_retry_count which controls the number of + automatic retries that will be performed by the controller when + the target device returns a NACK response. A value of 0 disables + the automatic retries. Exist only when I3C constroller supports + this retry on nack feature. +
drivers/i3c/master.c +39 -0
@@ -686,6 +686,39 @@ static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, chastatic DEVICE_ATTR_RW (hotjoin); +static ssize_t dev_nack_retry_count_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%u\n" ,dev_to_i3cmaster (dev)->dev_nack_retry_count); +} + +static ssize_t dev_nack_retry_count_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct i3c_bus *i3cbus =dev_to_i3cbus (dev); +struct i3c_master_controller *master =dev_to_i3cmaster (dev); +unsigned long val; +int ret; + + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret; + +i3c_bus_maintenance_lock (i3cbus); + ret = master->ops->set_dev_nack_retry (master, val); +i3c_bus_maintenance_unlock (i3cbus); + +if (ret) +return ret; + + master->dev_nack_retry_count = val; + +return count; +} + +static DEVICE_ATTR_RW (dev_nack_retry_count); +static struct attribute *i3c_masterdev_attrs[] = { &dev_attr_mode.attr, &dev_attr_current_master.attr,
@@ -2964,6 +2997,9 @@ int i3c_master_register(struct i3c_master_controller *master,i3c_master_register_new_i3c_devs (master);i3c_bus_normaluse_unlock (&master->bus); +if (master->ops->set_dev_nack_retry) +device_create_file (&master->dev, &dev_attr_dev_nack_retry_count); +return 0 ; err_del_dev:
@@ -2989,6 +3025,9 @@ void i3c_master_unregister(struct i3c_master_controller *master) {i3c_bus_notify (&master->bus,I3C_NOTIFY_BUS_REMOVE ); +if (master->ops->set_dev_nack_retry) +device_remove_file (&master->dev, &dev_attr_dev_nack_retry_count); +i3c_master_i2c_adapter_cleanup (master);i3c_master_unregister_i3c_devs (master);i3c_master_bus_cleanup (master);
include/linux/i3c/master.h +6 -0
@@ -462,6 +462,8 @@ struct i3c_bus {* @enable_hotjoin: enable hot join event detect. * @disable_hotjoin: disable hot join event detect. * @set_speed: adjust I3C open drain mode timing. +* @set_dev_nack_retry: configure device NACK retry count for the master +* controller. */ struct i3c_master_controller_ops {int (*bus_init)(struct i3c_master_controller *master);
@@ -491,6 +493,8 @@ struct i3c_master_controller_ops {int (*enable_hotjoin)(struct i3c_master_controller *master);int (*disable_hotjoin)(struct i3c_master_controller *master);int (*set_speed)(struct i3c_master_controller *master,enum i3c_open_drain_speed speed); +int (*set_dev_nack_retry)(struct i3c_master_controller *master, +unsigned long dev_nack_retry_cnt); };/**
@@ -514,6 +518,7 @@ struct i3c_master_controller_ops {* in a thread context. Typical examples are Hot Join processing which * requires taking the bus lock in maintenance, which in turn, can only * be done from a sleep-able context +* @dev_nack_retry_count: retry count when slave device nack * * A &struct i3c_master_controller has to be registered to the I3C subsystem * through i3c_master_register(). None of &struct i3c_master_controller fields
@@ -534,6 +539,7 @@ struct i3c_master_controller { } boardinfo;struct i3c_bus bus;struct workqueue_struct *wq; +unsigned int dev_nack_retry_count; };/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 757/1611 i3c: master: Replace WARN_ON() with dev_err() in i3c_dev_free_ibi_locked()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 471895799c2f46688792e175ced936ffeb6cdf01 ]
IBI disable failures are not indicative of a software bug, so using WARN_ON() is not appropriate. Replace these warnings with dev_err().
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- drivers/i3c/master.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/i3c/master.c +5 -2
@@ -3157,8 +3157,11 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)if (!dev->ibi)return ; -if (WARN_ON (dev->ibi->enabled)) -WARN_ON (i3c_dev_disable_ibi_locked (dev)); +if (dev->ibi->enabled) { +dev_err (&master->dev,"Freeing IBI that is still enabled\n" ); +if (i3c_dev_disable_ibi_locked (dev)) +dev_err (&master->dev,"Failed to disable IBI before freeing\n" ); + } master->ops->free_ibi (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 758/1611 i3c: master: Introduce optional Runtime PM support
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 990c149c61ee45da4fb6372e6b2fdd9808414e7a ]
Master drivers currently manage Runtime PM individually, but all require runtime resume for bus operations. This can be centralized in common code.
Add optional Runtime PM support to ensure the parent device is runtime resumed before bus operations and auto-suspended afterward.
Notably, do not call ->bus_cleanup() if runtime resume fails. Master drivers that opt-in to core runtime PM support must take that into account.
Also provide an option to allow IBIs and hot-joins while runtime suspended.
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- drivers/i3c/device.c | 46 +++++++++++++++++-- drivers/i3c/internals.h | 4 ++ drivers/i3c/master.c | 93 +++++++++++++++++++++++++++++++++++--- include/linux/i3c/master.h | 4 ++ 4 files changed, 138 insertions(+), 9 deletions(-)
drivers/i3c/device.c +43 -3
@@ -47,10 +47,16 @@ int i3c_device_do_priv_xfers(struct i3c_device *dev,return -EINVAL ; } + ret =i3c_bus_rpm_get (dev->bus); +if (ret) +return ret; +i3c_bus_normaluse_lock (dev->bus); ret =i3c_dev_do_priv_xfers_locked (dev->desc, xfers, nxfers);i3c_bus_normaluse_unlock (dev->bus); +i3c_bus_rpm_put (dev->bus); +return ret; }EXPORT_SYMBOL_GPL (i3c_device_do_priv_xfers);
@@ -67,10 +73,16 @@ int i3c_device_do_setdasa(struct i3c_device *dev) {int ret; + ret =i3c_bus_rpm_get (dev->bus); +if (ret) +return ret; +i3c_bus_normaluse_lock (dev->bus); ret =i3c_dev_setdasa_locked (dev->desc);i3c_bus_normaluse_unlock (dev->bus); +i3c_bus_rpm_put (dev->bus); +return ret; }EXPORT_SYMBOL_GPL (i3c_device_do_setdasa);
@@ -107,16 +119,27 @@ EXPORT_SYMBOL_GPL(i3c_device_get_info);*/ int i3c_device_disable_ibi (struct i3c_device *dev) { -int ret = -ENOENT ; +int ret; + +if (i3c_bus_rpm_ibi_allowed (dev->bus)) { + ret =i3c_bus_rpm_get (dev->bus); +if (ret) +return ret; + }i3c_bus_normaluse_lock (dev->bus);if (dev->desc) {mutex_lock (&dev->desc->ibi_lock); ret =i3c_dev_disable_ibi_locked (dev->desc);mutex_unlock (&dev->desc->ibi_lock); + }else { + ret = -ENOENT ; }i3c_bus_normaluse_unlock (dev->bus); +if (!ret ||i3c_bus_rpm_ibi_allowed (dev->bus)) +i3c_bus_rpm_put (dev->bus); +return ret; }EXPORT_SYMBOL_GPL (i3c_device_disable_ibi);
@@ -136,16 +159,25 @@ EXPORT_SYMBOL_GPL(i3c_device_disable_ibi);*/ int i3c_device_enable_ibi (struct i3c_device *dev) { -int ret = -ENOENT ; +int ret; + + ret =i3c_bus_rpm_get (dev->bus); +if (ret) +return ret;i3c_bus_normaluse_lock (dev->bus);if (dev->desc) {mutex_lock (&dev->desc->ibi_lock); ret =i3c_dev_enable_ibi_locked (dev->desc);mutex_unlock (&dev->desc->ibi_lock); + }else { + ret = -ENOENT ; }i3c_bus_normaluse_unlock (dev->bus); +if (ret ||i3c_bus_rpm_ibi_allowed (dev->bus)) +i3c_bus_rpm_put (dev->bus); +return ret; }EXPORT_SYMBOL_GPL (i3c_device_enable_ibi);
@@ -164,19 +196,27 @@ EXPORT_SYMBOL_GPL(i3c_device_enable_ibi);int i3c_device_request_ibi (struct i3c_device *dev,const struct i3c_ibi_setup *req) { -int ret = -ENOENT ; +int ret;if (!req->handler || !req->num_slots)return -EINVAL ; + ret =i3c_bus_rpm_get (dev->bus); +if (ret) +return ret; +i3c_bus_normaluse_lock (dev->bus);if (dev->desc) {mutex_lock (&dev->desc->ibi_lock); ret =i3c_dev_request_ibi_locked (dev->desc, req);mutex_unlock (&dev->desc->ibi_lock); + }else { + ret = -ENOENT ; }i3c_bus_normaluse_unlock (dev->bus); +i3c_bus_rpm_put (dev->bus); +return ret; }EXPORT_SYMBOL_GPL (i3c_device_request_ibi);
drivers/i3c/internals.h +4 -0
@@ -11,6 +11,10 @@#include <linux/i3c/master.h> #include <linux/io.h> +int __must_check i3c_bus_rpm_get (struct i3c_bus *bus); +void i3c_bus_rpm_put (struct i3c_bus *bus); +bool i3c_bus_rpm_ibi_allowed (struct i3c_bus *bus); +void i3c_bus_normaluse_lock (struct i3c_bus *bus);void i3c_bus_normaluse_unlock (struct i3c_bus *bus);
drivers/i3c/master.c +87 -6
181 lines not on this page · raw message
include/linux/i3c/master.h +4 -0
@@ -509,6 +509,8 @@ struct i3c_master_controller_ops {* @secondary: true if the master is a secondary master * @init_done: true when the bus initialization is done * @hotjoin: true if the master support hotjoin +* @rpm_allowed: true if Runtime PM allowed +* @rpm_ibi_allowed: true if IBI and Hot-Join allowed while runtime suspended * @boardinfo.i3c: list of I3C boardinfo objects * @boardinfo.i2c: list of I2C boardinfo objects * @boardinfo: board-level information attached to devices connected on the bus
@@ -533,6 +535,8 @@ struct i3c_master_controller { unsigned int secondary : 1; unsigned int init_done : 1; unsigned int hotjoin: 1; + unsigned int rpm_allowed: 1; + unsigned int rpm_ibi_allowed: 1;struct {struct list_head i3c;struct list_head i2c;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 759/1611 i3c: master: Add i3c_master_do_daa_ext() for post-hibernation address recovery
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit c481ef12e713fb7c292d04f53b3532ac0804ab3d ]
After system hibernation, I3C Dynamic Addresses may be reassigned at boot and no longer match the values recorded before suspend. Introduce i3c_master_do_daa_ext() to handle this situation.
The restore procedure is straightforward: issue a Reset Dynamic Address Assignment (RSTDAA), then run the standard DAA sequence. The existing DAA logic already supports detecting and updating devices whose dynamic addresses differ from previously known values.
Refactor the DAA path by introducing a shared helper used by both the normal i3c_master_do_daa() path and the new extended restore function, and correct the kernel-doc in the process.
Export i3c_master_do_daa_ext() so that master drivers can invoke it from their PM restore callbacks.
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- drivers/i3c/master.c | 49 +++++++++++++++++++++++++++++--------- include/linux/i3c/master.h | 1 + 2 files changed, 39 insertions(+), 11 deletions(-)
drivers/i3c/master.c +38 -11
@@ -1770,22 +1770,24 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master) }/** -* i3c_master_do_daa() - do a DAA (Dynamic Address Assignment) -* @master: master doing the DAA +* i3c_master_do_daa_ext() - Dynamic Address Assignment (extended version) +* @master: controller +* @rstdaa: whether to first perform Reset of Dynamic Addresses (RSTDAA) * -* This function is instantiating an I3C device object and adding it to the -* I3C device list. All device information are automatically retrieved using -* standard CCC commands. -* -* The I3C device object is returned in case the master wants to attach -* private data to it using i3c_dev_set_master_data(). +* Perform Dynamic Address Assignment with optional support for System +* Hibernation (@rstdaa is true). * -* This function must be called with the bus lock held in write mode. +* After System Hibernation, Dynamic Addresses can have been reassigned at boot +* time to different values. A simple strategy is followed to handle that. +* Perform a Reset of Dynamic Addresses (RSTDAA) followed by the normal DAA +* procedure which has provision for reassigning addresses that differ from the +* previously recorded addresses. * * Return: a 0 in case of success, an negative error code otherwise. */ -int i3c_master_do_daa (struct i3c_master_controller *master) +int i3c_master_do_daa_ext (struct i3c_master_controller *master,bool rstdaa) { +int rstret =0 ;int ret; ret =i3c_master_rpm_get (master);
@@ -1793,7 +1795,15 @@ int i3c_master_do_daa(struct i3c_master_controller *master)return ret;i3c_bus_maintenance_lock (&master->bus); + +if (rstdaa) { + rstret =i3c_master_rstdaa_locked (master,I3C_BROADCAST_ADDR ); +if (rstret ==I3C_ERROR_M2 ) + rstret =0 ; + } + ret = master->ops->do_daa (master); +i3c_bus_maintenance_unlock (&master->bus);if (ret)
@@ -1804,7 +1814,24 @@ int i3c_master_do_daa(struct i3c_master_controller *master)i3c_bus_normaluse_unlock (&master->bus); out:i3c_master_rpm_put (master); -return ret; + +return rstret ?: ret; +} +EXPORT_SYMBOL_GPL (i3c_master_do_daa_ext); + +/** +* i3c_master_do_daa() - do a DAA (Dynamic Address Assignment) +* @master: master doing the DAA +* +* This function instantiates I3C device objects and adds them to the +* I3C device list. All device information is automatically retrieved using +* standard CCC commands. +* +* Return: a 0 in case of success, an negative error code otherwise. +*/ +int i3c_master_do_daa (struct i3c_master_controller *master) +{ +return i3c_master_do_daa_ext (master, false); }EXPORT_SYMBOL_GPL (i3c_master_do_daa);
include/linux/i3c/master.h +1 -0
@@ -605,6 +605,7 @@ int i3c_master_get_free_addr(struct i3c_master_controller *master,int i3c_master_add_i3c_dev_locked (struct i3c_master_controller *master,u8 addr);int i3c_master_do_daa (struct i3c_master_controller *master); +int i3c_master_do_daa_ext (struct i3c_master_controller *master,bool rstdaa);struct i3c_dma *i3c_master_dma_map_single (struct device *dev,void *ptr,size_t len,bool force_bounce,enum dma_data_direction dir);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 760/1611 i3c: master: Move rstdaa error suppression
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jorge Marques <[email protected]>
[ Upstream commit 19a1b61fa623748f37f467e7813c58a2a792b90c ]
Prepare to fix improper Mx positive error propagation in later commits by handling Mx error codes where the i3c_ccc_cmd command is allocated. Two of the four i3c_master_rstdaa_locked() are error paths that already suppressed the return value, the remaining two are changed to handle the I3C_ERROR_M2 Mx error code inside i3c_master_rstdaa_locked(), checking cmd->err directly.
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- drivers/i3c/master.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/i3c/master.c +6 -5
@@ -1018,6 +1018,10 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master, ret =i3c_master_send_ccc_cmd_locked (master, &cmd);i3c_ccc_cmd_dest_cleanup (&dest); +/* No active devices on the bus. */ +if (ret && cmd.err ==I3C_ERROR_M2 ) + ret =0 ; +return ret; }
@@ -1796,11 +1800,8 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)i3c_bus_maintenance_lock (&master->bus); -if (rstdaa) { +if (rstdaa) rstret =i3c_master_rstdaa_locked (master,I3C_BROADCAST_ADDR ); -if (rstret ==I3C_ERROR_M2 ) - rstret =0 ; - } ret = master->ops->do_daa (master);
@@ -2096,7 +2097,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)* (assigned by the bootloader for example). */ ret =i3c_master_rstdaa_locked (master,I3C_BROADCAST_ADDR ); -if (ret && ret !=I3C_ERROR_M2 ) +if (ret) goto err_bus_cleanup;if (master->ops->set_speed) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 761/1611 i3c: master: Consolidate Hot-Join DAA work in the core
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 828c6130235db8144f4810b329b61390dc82719b ]
Three master drivers (dw-i3c-master, i3c-master-cdns, svc-i3c-master) each carry an essentially identical Hot-Join handler: a struct work_struct embedded in their private state, a work function that just calls i3c_master_do_daa() on the embedded i3c_master_controller, plus matching INIT_WORK()/cancel_work_sync() boilerplate in probe/remove (and shutdown for dw-i3c). The IBI/ISR paths then queue that work onto master->wq, which already lives in the core.
Move this pattern into the I3C core:
- Add struct work_struct hj_work to struct i3c_master_controller and initialise it in i3c_master_register() with a core-provided handler i3c_master_hj_work_fn() that performs i3c_master_do_daa().
- Cancel the work in i3c_master_unregister() so all controllers get correct teardown ordering against the workqueue for free.
- Export i3c_master_queue_hotjoin() as the single entry point drivers call from their Hot-Join IBI handler.
Convert the three existing users to the new API: drop their private hj_work fields, work functions, INIT_WORK() and cancel_work_sync() calls, and replace the queue_work(master->wq, &drv->hj_work) call sites with i3c_master_queue_hotjoin(&drv->base). The dw-i3c shutdown path still needs to flush pending Hot-Join work before tearing down the hardware, so it is updated to cancel master->base.hj_work directly.
No functional change intended: the work is still queued on the same master->wq, runs the same i3c_master_do_daa(), and is cancelled at controller teardown. Future Hot-Join improvements now only need to be made in one place.
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- drivers/i3c/master.c | 21 +++++++++++++++++++++ drivers/i3c/master/dw-i3c-master.c | 15 ++------------- drivers/i3c/master/dw-i3c-master.h | 2 -- drivers/i3c/master/i3c-master-cdns.c | 14 +------------- drivers/i3c/master/svc-i3c-master.c | 14 +------------- include/linux/i3c/master.h | 4 ++++ 6 files changed, 29 insertions(+), 41 deletions(-)
drivers/i3c/master.c +21 -0
@@ -635,6 +635,13 @@ static ssize_t i2c_scl_frequency_show(struct device *dev, }static DEVICE_ATTR_RO (i2c_scl_frequency); +static void i3c_master_hj_work_fn (struct work_struct *work) +{ +struct i3c_master_controller *master =container_of (work,typeof (*master), hj_work); + +i3c_master_do_daa (master); +} +static int i3c_set_hotjoin (struct i3c_master_controller *master,bool enable) {int ret;
@@ -713,6 +720,18 @@ int i3c_master_disable_hotjoin(struct i3c_master_controller *master) }EXPORT_SYMBOL_GPL (i3c_master_disable_hotjoin); +/** +* i3c_master_queue_hotjoin - Queue DAA processing after a Hot-Join event +* @master: I3C master object +* +* Queue the hot-join worker on the master's workqueue. +*/ +void i3c_master_queue_hotjoin (struct i3c_master_controller *master) +{ +queue_work (master->wq, &master->hj_work); +} +EXPORT_SYMBOL_GPL (i3c_master_queue_hotjoin); +static ssize_t hotjoin_show (struct device *dev,struct device_attribute *da,char *buf) {struct i3c_bus *i3cbus =dev_to_i3cbus (dev);
@@ -3064,6 +3083,7 @@ int i3c_master_register(struct i3c_master_controller *master, ret = -ENOMEM ; goto err_put_dev; } +INIT_WORK (&master->hj_work, i3c_master_hj_work_fn); ret =i3c_master_bus_init (master);if (ret)
@@ -3126,6 +3146,7 @@ EXPORT_SYMBOL_GPL(i3c_master_register);void i3c_master_unregister (struct i3c_master_controller *master) {i3c_bus_notify (&master->bus,I3C_NOTIFY_BUS_REMOVE ); +cancel_work_sync (&master->hj_work);if (master->ops->set_dev_nack_retry)device_remove_file (&master->dev, &dev_attr_dev_nack_retry_count);
drivers/i3c/master/dw-i3c-master.c +2 -13
@@ -1449,7 +1449,7 @@ static void dw_i3c_master_irq_handle_ibis(struct dw_i3c_master *master)if (IBI_TYPE_SIRQ (reg)) {dw_i3c_master_handle_ibi_sir (master, reg); }else if (IBI_TYPE_HJ (reg)) { -queue_work (master->base.wq, &master->hj_work); +i3c_master_queue_hotjoin (&master->base); }else { len =IBI_QUEUE_STATUS_DATA_LEN (reg); dev_info(&master->base.dev,
@@ -1523,14 +1523,6 @@ static const struct dw_i3c_platform_ops dw_i3c_platform_ops_default = { .set_dat_ibi = dw_i3c_platform_set_dat_ibi_nop, }; -static void dw_i3c_hj_work (struct work_struct *work) -{ -struct dw_i3c_master *master = -container_of (work,typeof (*master), hj_work); - -i3c_master_do_daa (&master->base); -} -int dw_i3c_common_probe (struct dw_i3c_master *master,struct platform_device *pdev) {
@@ -1592,8 +1584,6 @@ int dw_i3c_common_probe(struct dw_i3c_master *master, master->quirks = (unsigned long )device_get_match_data (&pdev->dev); -INIT_WORK (&master->hj_work, dw_i3c_hj_work); -device_set_of_node_from_dev (&master->base.i2c.dev, &pdev->dev); ret =i3c_master_register (&master->base, &pdev->dev, &dw_mipi_i3c_ops, false);
@@ -1613,7 +1603,6 @@ EXPORT_SYMBOL_GPL(dw_i3c_common_probe);void dw_i3c_common_remove (struct dw_i3c_master *master) { -cancel_work_sync (&master->hj_work);i3c_master_unregister (&master->base);pm_runtime_disable (master->dev);
@@ -1749,7 +1738,7 @@ static void dw_i3c_shutdown(struct platform_device *pdev)return ; } -cancel_work_sync (&master->hj_work); +cancel_work_sync (&master->base.hj_work);/* Disable interrupts */ writel ((u32 )~INTR_ALL , master->regs +INTR_STATUS_EN );
drivers/i3c/master/dw-i3c-master.h +0 -2
@@ -68,8 +68,6 @@ struct dw_i3c_master {/* platform-specific data */ const struct dw_i3c_platform_ops *platform_ops; - -struct work_struct hj_work; };struct dw_i3c_platform_ops {
drivers/i3c/master/i3c-master-cdns.c +1 -13
@@ -398,7 +398,6 @@ struct cdns_i3c_data { };struct cdns_i3c_master { -struct work_struct hj_work;struct i3c_master_controller base;u32 free_rr_slots;unsigned int maxdevs;
@@ -1357,7 +1356,7 @@ static void cnds_i3c_master_demux_ibis(struct cdns_i3c_master *master)case IBIR_TYPE_HJ :WARN_ON (IBIR_XFER_BYTES (ibir) || (ibir &IBIR_ERROR )); -queue_work (master->base.wq, &master->hj_work); +i3c_master_queue_hotjoin (&master->base);break ;case IBIR_TYPE_MR :
@@ -1528,15 +1527,6 @@ static const struct i3c_master_controller_ops cdns_i3c_master_ops = { .recycle_ibi_slot = cdns_i3c_master_recycle_ibi_slot, }; -static void cdns_i3c_master_hj (struct work_struct *work) -{ -struct cdns_i3c_master *master =container_of (work, - struct cdns_i3c_master, - hj_work); - -i3c_master_do_daa (&master->base); -} -static struct cdns_i3c_data cdns_i3c_devdata = { .thd_delay_ns =10 , };
@@ -1584,7 +1574,6 @@ static int cdns_i3c_master_probe(struct platform_device *pdev)spin_lock_init (&master->xferqueue.lock);INIT_LIST_HEAD (&master->xferqueue.list); -INIT_WORK (&master->hj_work, cdns_i3c_master_hj);writel (0xffffffff , master->regs +MST_IDR );writel (0xffffffff , master->regs +SLV_IDR ); ret = devm_request_irq(&pdev->dev, irq, cdns_i3c_master_interrupt, 0,
@@ -1627,7 +1616,6 @@ static void cdns_i3c_master_remove(struct platform_device *pdev) {struct cdns_i3c_master *master =platform_get_drvdata (pdev); -cancel_work_sync (&master->hj_work);i3c_master_unregister (&master->base); }
drivers/i3c/master/svc-i3c-master.c +1 -13
@@ -201,7 +201,6 @@ struct svc_i3c_drvdata {* @free_slots: Bit array of available slots * @addrs: Array containing the dynamic addresses of each attached device * @descs: Array of descriptors, one per attached device -* @hj_work: Hot-join work * @irq: Main interrupt * @num_clks: I3C clock number * @fclk: Fast clock (bus)
@@ -228,7 +227,6 @@ struct svc_i3c_master {u32 free_slots;u8 addrs[SVC_I3C_MAX_DEVS ];struct i3c_dev_desc *descs[SVC_I3C_MAX_DEVS ]; -struct work_struct hj_work;int irq;int num_clks;struct clk *fclk;
@@ -359,14 +357,6 @@ to_svc_i3c_master(struct i3c_master_controller *master) return container_of(master, struct svc_i3c_master, base); } -static void svc_i3c_master_hj_work (struct work_struct *work) -{ -struct svc_i3c_master *master; - - master = container_of(work, struct svc_i3c_master, hj_work); -i3c_master_do_daa (&master->base); -} -static struct i3c_dev_desc *svc_i3c_master_dev_from_addr (struct svc_i3c_master *master,unsigned int ibiaddr)
@@ -614,7 +604,7 @@ static void svc_i3c_master_ibi_isr(struct svc_i3c_master *master)case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN :svc_i3c_master_emit_stop (master);if (is_events_enabled (master,SVC_I3C_EVENT_HOTJOIN )) -queue_work (master->base.wq, &master->hj_work); +i3c_master_queue_hotjoin (&master->base);break ;case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST :svc_i3c_master_emit_stop (master);
@@ -1949,7 +1939,6 @@ static int svc_i3c_master_probe(struct platform_device *pdev)if (ret)return dev_err_probe (dev, ret,"can't enable I3C clocks\n" ); -INIT_WORK (&master->hj_work, svc_i3c_master_hj_work);mutex_init (&master->lock); ret = devm_request_irq(dev, master->irq, svc_i3c_master_irq_handler,
@@ -2008,7 +1997,6 @@ static void svc_i3c_master_remove(struct platform_device *pdev) {struct svc_i3c_master *master =platform_get_drvdata (pdev); -cancel_work_sync (&master->hj_work);i3c_master_unregister (&master->base);pm_runtime_dont_use_autosuspend (&pdev->dev);
include/linux/i3c/master.h +4 -0
@@ -520,6 +520,8 @@ struct i3c_master_controller_ops {* in a thread context. Typical examples are Hot Join processing which * requires taking the bus lock in maintenance, which in turn, can only * be done from a sleep-able context +* @hj_work: work item used to run DAA after a Hot-Join event is detected. +* Queued to @wq by i3c_master_queue_hotjoin() * @dev_nack_retry_count: retry count when slave device nack * * A &struct i3c_master_controller has to be registered to the I3C subsystem
@@ -543,6 +545,7 @@ struct i3c_master_controller { } boardinfo;struct i3c_bus bus;struct workqueue_struct *wq; +struct work_struct hj_work;unsigned int dev_nack_retry_count; };
@@ -623,6 +626,7 @@ int i3c_master_register(struct i3c_master_controller *master,void i3c_master_unregister (struct i3c_master_controller *master);int i3c_master_enable_hotjoin (struct i3c_master_controller *master);int i3c_master_disable_hotjoin (struct i3c_master_controller *master); +void i3c_master_queue_hotjoin (struct i3c_master_controller *master);/** * i3c_dev_get_master_data() - get master private data attached to an I3C
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 762/1611 i3c: master: Ensure Hot-Join operations are stopped on shutdown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 8323e783dc3904839e64cb08cfcc7571ef9212c4 ]
System shutdown invokes each device's bus shutdown callback to quiesce hardware, but the I3C bus type does not currently implement one. As a result, on shutdown the controller's Hot-Join work and any in-flight i3c_master_do_daa() can keep running (or be newly triggered) while the rest of the system is being torn down.
A similar window exists at i3c_master_unregister() time: cancel_work_sync() on hj_work prevents queued work from completing, but does not stop a fresh Hot-Join IBI from re-queueing the worker, nor a concurrent sysfs writer from toggling Hot-Join via i3c_set_hotjoin().
Introduce a single "shutting down" gate in the I3C core, set under the bus maintenance lock so it is observed by any in-progress DAA path before pending work is cancelled. Install an i3c_bus_type shutdown callback that engages this gate for master devices during system shutdown, and use the same gate in i3c_master_unregister() so both paths get identical guarantees.
Once the gate is engaged, the Hot-Join worker, i3c_master_do_daa_ext() and i3c_set_hotjoin() all bail out cleanly, so Hot-Join IBIs that race with shutdown become no-ops, direct DAA callers see -ENODEV, and sysfs writers can no longer re-enable Hot-Join through ops->enable_hotjoin() while the controller is going away.
No functional change for the steady-state runtime path; the new checks only take effect once the controller has been marked as shutting down.
Note, this patch depends on patch "i3c: master: Consolidate Hot-Join DAA work in the core".
Stable-dep-of: 3f79dac3ea1c ("i3c: master: Defer new-device registration out of DAA caller context")
--- drivers/i3c/master.c | 52 +++++++++++++++++++++++++++----------- include/linux/i3c/master.h | 2 ++ 2 files changed, 39 insertions(+), 15 deletions(-)
drivers/i3c/master.c +37 -15
@@ -370,14 +370,6 @@ static void i3c_device_remove(struct device *dev)i3c_device_free_ibi (i3cdev); } -const struct bus_type i3c_bus_type = { - .name ="i3c" , - .match = i3c_device_match, - .probe = i3c_device_probe, - .remove = i3c_device_remove, -}; -EXPORT_SYMBOL_GPL (i3c_bus_type); -static enum i3c_addr_slot_status i3c_bus_get_addr_slot_status_mask (struct i3c_bus *bus,u16 addr,u32 mask) {
@@ -639,7 +631,8 @@ static void i3c_master_hj_work_fn(struct work_struct *work) {struct i3c_master_controller *master =container_of (work,typeof (*master), hj_work); -i3c_master_do_daa (master); +if (!master->shutting_down) +i3c_master_do_daa (master); }static int i3c_set_hotjoin (struct i3c_master_controller *master,bool enable)
@@ -660,7 +653,9 @@ static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable)i3c_bus_normaluse_lock (&master->bus); -if (enable) +if (master->shutting_down) + ret = -ENODEV ; +else if (enable) ret = master->ops->enable_hotjoin (master);else ret = master->ops->disable_hotjoin (master);
@@ -812,6 +807,30 @@ static const struct device_type i3c_masterdev_type = { .groups = i3c_masterdev_groups, }; +static void i3c_master_shutdown (struct i3c_master_controller *master) +{ +i3c_bus_maintenance_lock (&master->bus); + master->shutting_down = true; +i3c_bus_maintenance_unlock (&master->bus); + +cancel_work_sync (&master->hj_work); +} + +static void i3c_device_shutdown (struct device *dev) +{ +if (dev->type == &i3c_masterdev_type) +i3c_master_shutdown (dev_to_i3cmaster (dev)); +} + +const struct bus_type i3c_bus_type = { + .name ="i3c" , + .match = i3c_device_match, + .probe = i3c_device_probe, + .remove = i3c_device_remove, + .shutdown = i3c_device_shutdown, +}; +EXPORT_SYMBOL_GPL (i3c_bus_type); +static int i3c_bus_set_mode (struct i3c_bus *i3cbus,enum i3c_bus_mode mode,unsigned long max_i2c_scl_rate) {
@@ -1819,10 +1838,13 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)i3c_bus_maintenance_lock (&master->bus); -if (rstdaa) - rstret =i3c_master_rstdaa_locked (master,I3C_BROADCAST_ADDR ); - - ret = master->ops->do_daa (master); +if (master->shutting_down) { + ret = -ENODEV ; + }else { +if (rstdaa) + rstret =i3c_master_rstdaa_locked (master,I3C_BROADCAST_ADDR ); + ret = master->ops->do_daa (master); + }i3c_bus_maintenance_unlock (&master->bus);
@@ -3146,7 +3168,7 @@ EXPORT_SYMBOL_GPL(i3c_master_register);void i3c_master_unregister (struct i3c_master_controller *master) {i3c_bus_notify (&master->bus,I3C_NOTIFY_BUS_REMOVE ); -cancel_work_sync (&master->hj_work); +i3c_master_shutdown (master);if (master->ops->set_dev_nack_retry)device_remove_file (&master->dev, &dev_attr_dev_nack_retry_count);
include/linux/i3c/master.h +2 -0
@@ -511,6 +511,7 @@ struct i3c_master_controller_ops {* @hotjoin: true if the master support hotjoin * @rpm_allowed: true if Runtime PM allowed * @rpm_ibi_allowed: true if IBI and Hot-Join allowed while runtime suspended +* @shutting_down: set to true when master begins shutdown or unregister * @boardinfo.i3c: list of I3C boardinfo objects * @boardinfo.i2c: list of I2C boardinfo objects * @boardinfo: board-level information attached to devices connected on the bus
@@ -539,6 +540,7 @@ struct i3c_master_controller { unsigned int hotjoin: 1; unsigned int rpm_allowed: 1; unsigned int rpm_ibi_allowed: 1; +bool shutting_down;struct {struct list_head i3c;struct list_head i2c;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 763/1611 i3c: master: Defer new-device registration out of DAA caller context
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 3f79dac3ea1c30516fcc791770af034387c7f917 ]
Master drivers may invoke i3c_master_do_daa_ext() during resume to re-run Dynamic Address Assignment. As well as assigning addresses to any newly arrived devices, this restores the dynamic address of devices that lost it across system suspend, so it has to run as part of the controller's resume path.
A side effect of i3c_master_do_daa_ext() today is that it also registers any newly discovered I3C devices with the driver model inline, via i3c_master_register_new_i3c_devs(). Doing that from the resume path is problematic: a hot-join-capable device may join the bus during this same DAA, and registering it immediately would push driver model work (probing, sysfs, etc.) into the controller's resume context, where the rest of the system is not yet fully resumed and the controller driver is still partway through its own resume sequence.
Decouple discovery from registration: add a reg_work work item to struct i3c_master_controller and have i3c_master_do_daa_ext() queue it on master->wq (the freezable workqueue) instead of calling i3c_master_register_new_i3c_devs() directly. The worker performs the registration only when the controller is not shutting_down, and is cancelled alongside hj_work in i3c_master_shutdown(). Because wq is freezable, any newly observed devices end up being registered after the system has finished resuming.
i3c_master_register() also routes its initial post-bus-init registration through reg_work, using flush_work() to keep probe-time behavior synchronous. This keeps a single registration code path and ensures the worker is the only writer of desc->dev.
--- drivers/i3c/master.c | 27 ++++++++++++++++++++------- include/linux/i3c/master.h | 6 ++++++ 2 files changed, 26 insertions(+), 7 deletions(-)
drivers/i3c/master.c +20 -7
@@ -814,6 +814,7 @@ static void i3c_master_shutdown(struct i3c_master_controller *master)i3c_bus_maintenance_unlock (&master->bus);cancel_work_sync (&master->hj_work); +cancel_work_sync (&master->reg_work); }static void i3c_device_shutdown (struct device *dev)
@@ -1811,6 +1812,16 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master) } } +static void i3c_master_reg_work_fn (struct work_struct *work) +{ +struct i3c_master_controller *master =container_of (work,typeof (*master), reg_work); + +i3c_bus_normaluse_lock (&master->bus); +if (!master->shutting_down) +i3c_master_register_new_i3c_devs (master); +i3c_bus_normaluse_unlock (&master->bus); +} +/** * i3c_master_do_daa_ext() - Dynamic Address Assignment (extended version) * @master: controller
@@ -1851,9 +1862,7 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)if (ret) goto out; -i3c_bus_normaluse_lock (&master->bus); -i3c_master_register_new_i3c_devs (master); -i3c_bus_normaluse_unlock (&master->bus); +queue_work (master->wq, &master->reg_work); out:i3c_master_rpm_put (master);
@@ -3106,6 +3115,7 @@ int i3c_master_register(struct i3c_master_controller *master, goto err_put_dev; }INIT_WORK (&master->hj_work, i3c_master_hj_work_fn); +INIT_WORK (&master->reg_work, i3c_master_reg_work_fn); ret =i3c_master_bus_init (master);if (ret)
@@ -3131,12 +3141,15 @@ int i3c_master_register(struct i3c_master_controller *master,/* * We're done initializing the bus and the controller, we can now -* register I3C devices discovered during the initial DAA. +* register I3C devices discovered during the initial DAA. Device +* registration is done via reg_work because that keeps a single +* registration code path and ensures the worker is the only writer +* of desc->dev. Flush the work to preserve synchronous probe-time +* behavior. */ master->init_done = true; -i3c_bus_normaluse_lock (&master->bus); -i3c_master_register_new_i3c_devs (master); -i3c_bus_normaluse_unlock (&master->bus); +queue_work (master->wq, &master->reg_work); +flush_work (&master->reg_work);if (master->ops->set_dev_nack_retry)device_create_file (&master->dev, &dev_attr_dev_nack_retry_count);
include/linux/i3c/master.h +6 -0
@@ -523,6 +523,11 @@ struct i3c_master_controller_ops {* be done from a sleep-able context * @hj_work: work item used to run DAA after a Hot-Join event is detected. * Queued to @wq by i3c_master_queue_hotjoin() +* @reg_work: work item used to register newly discovered I3C devices with +* the driver model. Queued to @wq by i3c_master_do_daa_ext() so +* that device registration is deferred out of the DAA caller's +* context (notably the resume path), and is skipped if the +* controller is shutting down * @dev_nack_retry_count: retry count when slave device nack * * A &struct i3c_master_controller has to be registered to the I3C subsystem
@@ -548,6 +553,7 @@ struct i3c_master_controller {struct i3c_bus bus;struct workqueue_struct *wq;struct work_struct hj_work; +struct work_struct reg_work;unsigned int dev_nack_retry_count; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 764/1611 i3c: master: Prevent reuse of dynamic address on device add failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit b3ba8383da4d0cff15810e32ea785eceb0a80813 ]
i3c_master_add_i3c_dev_locked() is called after a device has already been assigned a dynamic address. If the function fails, the address remains marked as free and may be reallocated to another device, leading to address conflicts on the bus.
Ensure the address is not marked as free on failure, by updating the address slot state to prevent the address from being re-used.
Emit an error message to inform of the failure.
Opportunistically remove the !master check because it is impossible.
Note, directly resetting the device's dynamic address is no longer an option, since Direct RSTDAA was deprecated from I3C starting from version 1.1 and v1.1 (or later) target devices are meant to NACK it.
--- drivers/i3c/master.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/i3c/master.c +14 -5
@@ -2295,12 +2295,11 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,bool enable_ibi = false;int ret; -if (!master) -return -EINVAL ; - newdev =i3c_master_alloc_i3c_dev (master, &info); -if (IS_ERR (newdev)) -return PTR_ERR (newdev); +if (IS_ERR (newdev)) { + ret =PTR_ERR (newdev); + goto err_prevent_addr_reuse; + } ret =i3c_master_attach_i3c_dev (master, newdev);if (ret)
@@ -2422,6 +2421,16 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, err_free_dev:i3c_master_free_i3c_dev (newdev); +err_prevent_addr_reuse: +/* +* Although the device has not been added, the address has been +* assigned. Prevent the address from being used again. +*/ +if (i3c_bus_get_addr_slot_status (&master->bus, addr) ==I3C_ADDR_SLOT_FREE ) +i3c_bus_set_addr_slot_status (&master->bus, addr,I3C_ADDR_SLOT_I3C_DEV ); + +dev_err (&master->dev,"Failed to add I3C device at address %u, error %d\n" , addr, ret); +return ret; }EXPORT_SYMBOL_GPL (i3c_master_add_i3c_dev_locked);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 765/1611 apparmor: fix label can not be immediately before a declaration
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 1ed40bd525c00d22af666016af9aef7167f8085f ]
Fix error reported by kernel test robot
security/apparmor/policy.c:1381:2: error: a label can only be part of a statement and a declaration is not a statement
All errors (new ones prefixed by >>):
security/apparmor/policy.c: In function 'aa_replace_profiles':
Quoted 1 line
Quoted 1 line
security/apparmor/policy.c:1381:2: error: a label can only be part
of a statement and a declaration is not a statement
ssize_t udata_sz = udata->size;
^~~~~--- security/apparmor/policy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/apparmor/policy.c +2 -1
@@ -1373,9 +1373,10 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,mutex_unlock (&ns->lock); out: +aa_put_ns (ns); +ssize_t udata_sz = udata->size; -aa_put_ns (ns);aa_put_profile_loaddata (udata);kfree (ns_name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 766/1611 accel/ivpu: fix HWS command queue leak on registration failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karol Wachowski <[email protected]>
[ Upstream commit e7ab91e2bf01b024691d6ce488546533943e7a6b ]
A command queue is considered valid and usable by the driver only when it has a doorbell ID assigned (db_id != 0), meaning both the FW cmdq creation and doorbell registration completed successfully.
However, when either ivpu_register_db() or set_context_sched_properties() fails after ivpu_hws_cmdq_init() has already created the cmdq in FW, the command queue is left registered in FW while the driver treats it as uninitialized (db_id remains 0). On the next submission attempt the driver tries to register the same cmdq again, which fails because FW already has an entry for it.
Fix by calling ivpu_jsm_hws_destroy_cmdq() on error paths to properly unwind FW state and allow subsequent registration attempts to succeed.
--- drivers/accel/ivpu/ivpu_job.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/accel/ivpu/ivpu_job.c +5 -5
@@ -195,9 +195,9 @@ static int ivpu_hws_cmdq_init(struct ivpu_file_priv *file_priv, struct ivpu_cmdq ret =ivpu_jsm_hws_set_context_sched_properties (vdev, file_priv->ctx.id, cmdq->id, priority);if (ret) -return ret; +ivpu_jsm_hws_destroy_cmdq (vdev, file_priv->ctx.id, cmdq->id); -return 0 ; +return ret; }static int ivpu_register_db (struct ivpu_file_priv *file_priv,struct ivpu_cmdq *cmdq)
@@ -255,10 +255,10 @@ static int ivpu_cmdq_register(struct ivpu_file_priv *file_priv, struct ivpu_cmdq } ret =ivpu_register_db (file_priv, cmdq); -if (ret) -return ret; +if (ret && vdev->fw->sched_mode ==VPU_SCHEDULING_MODE_HW ) +ivpu_jsm_hws_destroy_cmdq (vdev, file_priv->ctx.id, cmdq->id); -return 0 ; +return ret; }static int ivpu_cmdq_unregister (struct ivpu_file_priv *file_priv,struct ivpu_cmdq *cmdq)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 767/1611 sparc: led: avoid trimming a newline from empty writes
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 7eb475e8a738ee6fd1260aa59ddccb610fdd4300 ]
led_proc_write() duplicates up to LED_MAX_LENGTH bytes with memdup_user_nul() and then unconditionally inspects buf[count - 1] to strip a trailing newline. A zero-length write therefore reads one byte before the duplicated buffer.
The previous version rejected empty writes, but empty input already falls through to the existing default case and turns the LED off like any other unrecognized string. Preserve that behavior and only skip the newline trim when there is no input byte to inspect.
--- arch/sparc/kernel/led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/led.c +1 -1
@@ -78,7 +78,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,return PTR_ERR (buf);/* work around \n when echo'ing into proc */ -if (buf[count -1 ] =='\n' ) +if (count >0 && buf[count -1 ] =='\n' ) buf[count -1 ] ='\0' ;/* before we change anything we want to stop any running timers,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 768/1611 perf maps: Add maps__mutate_mapping
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 75a4888b7029a1f98613aef91f517b2ee1f03d43 ]
During kernel ELF symbol parsing (dso__process_kernel_symbol), proc kallsyms image loading (dso__load_kernel_sym, dso__load_guest_kernel_sym), and dynamic kernel memory map alignment updates (machine__update_kernel_mmap), the loader directly modifies live virtual address boundary keys fields on map objects.
If these boundaries are mutated while the map pointer actively resides inside the parent maps cache array list (kmaps) outside of any lock closure, an unsafe concurrent window is exposed where parallel worker lookup threads (e.g., inside perf top) can mistakenly assume the cache remains sorted based on stale parameters, executing binary search queries (bsearch) across an unsorted range and triggering lookup failures.
Fix this by introducing maps__mutate_mapping() that explicitly acquires the parent maps write semaphore lock, executes an incoming mutation callback block to perform the field updates under lock protection, and invalidates the sorted tracking flags prior to releasing the write lock.
This guarantees synchronization invariants, closing the concurrent lookup race window. The adjacent module alignment pass inside machine__create_kernel_maps() is safely preserved as a high-performance lockless pass, as its invocation lifecycle bounds remain strictly single-threaded by contract during session initialization construction.
To safely support this unconditional down_write write lock mutator without recursive read-to-write self-deadlock upgrades during lazy symbol loading, we introduce a public maps__load_maps() API.
It copies map pointers under a brief read lock and force-loads all modules locklessly outside the lock. Callers (such as perf inject) must pre-load all kernel symbol maps up front at startup using maps__load_maps(), completely bypassing dynamic runtime mutations.
--- tools/perf/util/machine.c | 32 +++++--- tools/perf/util/maps.c | 148 ++++++++++++++++++++++++++++------- tools/perf/util/maps.h | 3 + tools/perf/util/symbol-elf.c | 41 ++++++---- tools/perf/util/symbol.c | 17 +++- 5 files changed, 183 insertions(+), 58 deletions(-)
tools/perf/util/machine.c +20 -12
@@ -1522,22 +1522,30 @@ static void machine__set_kernel_mmap(struct machine *machine,map__set_end (machine->vmlinux_map, ~0ULL ); } -static int machine__update_kernel_mmap (struct machine *machine, -u64 start,u64 end) +struct kernel_mmap_mutation_ctx { +u64 start; +u64 end; +}; + +static int kernel_mmap_mutate_cb (struct map *map,void *data) { -struct map *orig, *updated; -int err; +struct kernel_mmap_mutation_ctx *ctx = data; - orig = machine->vmlinux_map; - updated =map__get (orig); +map__set_start (map, ctx->start); +map__set_end (map, ctx->end); +if (ctx->start ==0 && ctx->end ==0 ) +map__set_end (map, ~0ULL ); +return 0 ; +} - machine->vmlinux_map = updated; -maps__remove (machine__kernel_maps (machine), orig); -machine__set_kernel_mmap (machine, start, end); - err =maps__insert (machine__kernel_maps (machine), updated); -map__put (orig); +static int machine__update_kernel_mmap (struct machine *machine, +u64 start,u64 end) +{ +struct kernel_mmap_mutation_ctx ctx = { .start = start, .end = end }; -return err; +return maps__mutate_mapping (machine__kernel_maps (machine), + machine->vmlinux_map, + kernel_mmap_mutate_cb, &ctx); }int machine__create_kernel_maps (struct machine *machine)
tools/perf/util/maps.c +121 -27
173 lines not on this page · raw message
tools/perf/util/maps.h +3 -0
@@ -55,8 +55,11 @@ void maps__set_unwind_libunwind_ops(struct maps *maps, const struct unwind_libunsize_t maps__fprintf (struct maps *maps,FILE *fp); +int maps__load_maps (struct maps *maps);int maps__insert (struct maps *maps,struct map *map);void maps__remove (struct maps *maps,struct map *map); +int maps__mutate_mapping (struct maps *maps,struct map *map, +int (*mutate_cb)(struct map *map,void *data),void *data);struct map *maps__find (struct maps *maps,u64 addr);struct symbol *maps__find_symbol (struct maps *maps,u64 addr,struct map **mapp);
tools/perf/util/symbol-elf.c +26 -15
54 lines not on this page · raw message
tools/perf/util/symbol.c +13 -4
@@ -49,6 +49,13 @@#include <symbol/kallsyms.h> #include <sys/utsname.h> +static int map_fixup_cb (struct map *map,void *data__maybe_unused ) +{ +map__fixup_start (map); +map__fixup_end (map); +return 0 ; +} +static int dso__load_kernel_sym (struct dso *dso,struct map *map);static int dso__load_guest_kernel_sym (struct dso *dso,struct map *map);static bool symbol__is_idle (const char *name);
@@ -2124,10 +2131,11 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)free (kallsyms_allocated_filename);if (err >0 && !dso__is_kcore (dso)) { +struct maps *kmaps =map__kmaps (map); +dso__set_binary_type (dso,DSO_BINARY_TYPE__KALLSYMS );dso__set_long_name (dso,DSO__NAME_KALLSYMS , false); -map__fixup_start (map); -map__fixup_end (map); +maps__mutate_mapping (kmaps, map, map_fixup_cb,NULL ); }return err;
@@ -2167,10 +2175,11 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)if (err >0 )pr_debug ("Using %s for symbols\n" , kallsyms_filename);if (err >0 && !dso__is_kcore (dso)) { +struct maps *kmaps =map__kmaps (map); +dso__set_binary_type (dso,DSO_BINARY_TYPE__GUEST_KALLSYMS );dso__set_long_name (dso, machine->mmap_name, false); -map__fixup_start (map); -map__fixup_end (map); +maps__mutate_mapping (kmaps, map, map_fixup_cb,NULL ); }return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 769/1611 perf symbols: Fix bswap copy-paste error for 32-bit ELF p_filesz
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 081b387c7397498c583b1ba7c2fdaf4c6da6b538 ]
filename__read_build_id() byte-swaps 32-bit ELF program headers on cross-endian files, but line 178 passes p_offset to bswap_32() instead of p_filesz:
hdrs.phdr32[i].p_filesz = bswap_32(hdrs.phdr32[i].p_offset);
This clobbers p_filesz with the already-swapped p_offset value. The 64-bit path on line 182 is correct and swaps p_filesz from p_filesz.
The consequence is that the PT_NOTE segment read uses the wrong size, which can cause either a short read (missing the build-id) or an oversized read (reading past the segment into adjacent data).
Fix by swapping the correct field.
--- tools/perf/util/symbol-minimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol-minimal.c +1 -1
@@ -168,7 +168,7 @@ int filename__read_build_id(const char *filename, struct build_id *bid, bool bloif (elf32) { hdrs.phdr32[i].p_type =bswap_32 (hdrs.phdr32[i].p_type); hdrs.phdr32[i].p_offset =bswap_32 (hdrs.phdr32[i].p_offset); - hdrs.phdr32[i].p_filesz =bswap_32 (hdrs.phdr32[i].p_offset); + hdrs.phdr32[i].p_filesz =bswap_32 (hdrs.phdr32[i].p_filesz); }else { hdrs.phdr64[i].p_type =bswap_32 (hdrs.phdr64[i].p_type); hdrs.phdr64[i].p_offset =bswap_64 (hdrs.phdr64[i].p_offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 770/1611 perf symbols: Validate p_filesz before use in filename__read_build_id()
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 2a3716544359d4312c81b0fa909a13301186da17 ]
filename__read_build_id() stores ELF p_filesz in a ssize_t variable. A crafted 32-bit ELF with p_filesz = 0xFFFFFFFF produces ssize_t value -1. The comparison p_filesz > buf_size evaluates false because signed -1 is less than any non-negative buf_size, so the realloc is skipped and buf remains NULL.
The subsequent read(fd, NULL, -1) returns -1, which equals p_filesz, passing the error check. read_build_id() then dereferences the NULL buffer.
Add an explicit check for p_filesz <= 0 before using the value, catching both zero-length and sign-wrapped negative sizes from crafted ELF files.
--- tools/perf/util/symbol-minimal.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/symbol-minimal.c +3 -0
@@ -179,6 +179,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid, bool blocontinue ; p_filesz = elf32 ? hdrs.phdr32[i].p_filesz : hdrs.phdr64[i].p_filesz; +/* ssize_t can go negative with crafted ELF p_filesz values */ +if (p_filesz <=0 ) +continue ;if (p_filesz > buf_size) {void *tmp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 771/1611 perf symbols: Break infinite loop on zero-filled notes in sysfs__read_build_id()
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 063c647b24f640657d6d9e2e90d620ea3ee19ae6 ]
sysfs__read_build_id() iterates ELF note headers from sysfs files in a while(1) loop. If the file contains a zero-filled note header (both n_namesz and n_descsz are 0), the code computes n = namesz + descsz = 0 and calls read(fd, bf, 0). read() with count 0 returns 0, which matches the expected (ssize_t)n value, so the error check passes and the loop repeats — reading the same zero bytes and spinning forever.
This can happen with corrupted or zero-padded sysfs pseudo-files.
Add a check for n == 0 before the read, since no valid ELF note has both name and description of zero length.
--- tools/perf/util/symbol-elf.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/symbol-elf.c +3 -0
@@ -991,6 +991,9 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid) }else { n = namesz + descsz; } +/* no valid note has both namesz and descsz zero */ +if (n ==0 ) +break ;if (read (fd, bf, n) != (ssize_t )n)break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 772/1611 perf tools: Dont read build-ids from non-regular files
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 834ebb5678d75d844f5d4f44ede78724d8c96630 ]
Simplify the build ID reading code by removing the non-blocking option. Having to pass the correct option to this function was fragile and a mistake would result in a hang, see the linked fix. Furthermore, compressed files are always opened blocking anyway, ignoring the non-blocking option.
We also don't expect to read build IDs from non-regular files. The only hits to this function that are non-regular are devices that won't be elf files with build IDs, for example "/dev/dri/renderD129".
Now instead of opening these as non-blocking and failing to read, we skip them. Even if something like a pipe or character device did have a build ID, I don't think it would have worked because you need to call read() in a loop, check for -EAGAIN and handle timeouts to make non-blocking reads work.
Stable-dep-of: f973e52a9977 ("perf dso: Fix heap overflow in dso__get_filename() on decompressed path")
--- tools/perf/bench/inject-buildid.c | 2 +- tools/perf/builtin-buildid-cache.c | 8 ++++---- tools/perf/builtin-inject.c | 4 ++-- tools/perf/tests/pe-file-parsing.c | 4 ++-- tools/perf/tests/sdt.c | 2 +- tools/perf/util/build-id.c | 4 ++-- tools/perf/util/debuginfo.c | 2 +- tools/perf/util/dsos.c | 4 ++-- tools/perf/util/libbfd.c | 9 +++++++-- tools/perf/util/libbfd.h | 5 ++--- tools/perf/util/symbol-elf.c | 13 +++++++------ tools/perf/util/symbol-minimal.c | 11 ++++++++--- tools/perf/util/symbol.c | 5 ++--- tools/perf/util/symbol.h | 2 +- tools/perf/util/synthetic-events.c | 2 +- 15 files changed, 43 insertions(+), 34 deletions(-)
tools/perf/bench/inject-buildid.c +1 -1
@@ -85,7 +85,7 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,if (typeflag ==FTW_D || typeflag ==FTW_SL )return 0 ; -if (filename__read_build_id (fpath, &bid,/*block=*/ true) <0 ) +if (filename__read_build_id (fpath, &bid) <0 )return 0 ; dso->name =realpath (fpath,NULL );
tools/perf/builtin-buildid-cache.c +4 -4
@@ -180,7 +180,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)struct nscookie nsc;nsinfo__mountns_enter (nsi, &nsc); - err =filename__read_build_id (filename, &bid,/*block=*/ true); + err =filename__read_build_id (filename, &bid);nsinfo__mountns_exit (&nsc);if (err <0 ) {pr_debug ("Couldn't read a build-id in %s\n" , filename);
@@ -204,7 +204,7 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)int err;nsinfo__mountns_enter (nsi, &nsc); - err =filename__read_build_id (filename, &bid,/*block=*/ true); + err =filename__read_build_id (filename, &bid);nsinfo__mountns_exit (&nsc);if (err <0 ) {pr_debug ("Couldn't read a build-id in %s\n" , filename);
@@ -280,7 +280,7 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true; -if (filename__read_build_id (filename, &bid,/*block=*/ true) ==-1 ) { +if (filename__read_build_id (filename, &bid) ==-1 ) {if (errno ==ENOENT )return false;
@@ -309,7 +309,7 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)int err;nsinfo__mountns_enter (nsi, &nsc); - err =filename__read_build_id (filename, &bid,/*block=*/ true); + err =filename__read_build_id (filename, &bid);nsinfo__mountns_exit (&nsc);if (err <0 ) {pr_debug ("Couldn't read a build-id in %s\n" , filename);
tools/perf/builtin-inject.c +2 -2
@@ -877,12 +877,12 @@ static int dso__read_build_id(struct dso *dso)mutex_lock (dso__lock (dso));nsinfo__mountns_enter (dso__nsinfo (dso), &nsc); -if (filename__read_build_id (dso__long_name (dso), &bid,/*block=*/ true) >0 ) +if (filename__read_build_id (dso__long_name (dso), &bid) >0 )dso__set_build_id (dso, &bid);else if (dso__nsinfo (dso)) {char *new_name =dso__filename_with_chroot (dso,dso__long_name (dso)); -if (new_name &&filename__read_build_id (new_name, &bid,/*block=*/ true) >0 ) +if (new_name &&filename__read_build_id (new_name, &bid) >0 )dso__set_build_id (dso, &bid);free (new_name); }
tools/perf/tests/pe-file-parsing.c +2 -2
@@ -37,7 +37,7 @@ static int run_dir(const char *d)size_t idx;scnprintf (filename,PATH_MAX ,"%s/pe-file.exe" , d); - ret =filename__read_build_id (filename, &bid,/*block=*/ true); + ret =filename__read_build_id (filename, &bid);TEST_ASSERT_VAL ("Failed to read build_id" , ret ==sizeof (expect_build_id)); TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid.data, expect_build_id,
@@ -49,7 +49,7 @@ static int run_dir(const char *d) !strcmp(debuglink, expect_debuglink));scnprintf (debugfile,PATH_MAX ,"%s/%s" , d, debuglink); - ret =filename__read_build_id (debugfile, &bid,/*block=*/ true); + ret =filename__read_build_id (debugfile, &bid);TEST_ASSERT_VAL ("Failed to read debug file build_id" , ret ==sizeof (expect_build_id)); TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid.data, expect_build_id,
tools/perf/tests/sdt.c +1 -1
@@ -31,7 +31,7 @@ static int build_id_cache__add_file(const char *filename)struct build_id bid = { .size =0 , };int err; - err =filename__read_build_id (filename, &bid,/*block=*/ true); + err =filename__read_build_id (filename, &bid);if (err <0 ) {pr_debug ("Failed to read build id of %s\n" , filename);return err;
tools/perf/util/build-id.c +2 -2
@@ -122,7 +122,7 @@ int filename__snprintf_build_id(const char *pathname, char *sbuild_id, size_t sbstruct build_id bid = { .size =0 , };int ret; - ret =filename__read_build_id (pathname, &bid,/*block=*/ true); + ret =filename__read_build_id (pathname, &bid);if (ret <0 )return ret;
@@ -848,7 +848,7 @@ static int filename__read_build_id_ns(const char *filename,int ret;nsinfo__mountns_enter (nsi, &nsc); - ret =filename__read_build_id (filename, bid,/*block=*/ true); + ret =filename__read_build_id (filename, bid);nsinfo__mountns_exit (&nsc);return ret;
tools/perf/util/debuginfo.c +1 -1
@@ -118,7 +118,7 @@ struct debuginfo *debuginfo__new(const char *path)* incase the path isn't for a regular file. */ assert (!dso__has_build_id (dso)); -if (filename__read_build_id (path, &bid,/*block=*/ false) >0 ) +if (filename__read_build_id (path, &bid) >0 )dso__set_build_id (dso, &bid); for (type = distro_dwarf_types;
tools/perf/util/dsos.c +2 -2
@@ -81,13 +81,13 @@ static int dsos__read_build_ids_cb(struct dso *dso, void *data)return 0 ; }nsinfo__mountns_enter (dso__nsinfo (dso), &nsc); -if (filename__read_build_id (dso__long_name (dso), &bid,/*block=*/ true) >0 ) { +if (filename__read_build_id (dso__long_name (dso), &bid) >0 ) {dso__set_build_id (dso, &bid); args->have_build_id = true; }else if (errno ==ENOENT &&dso__nsinfo (dso)) {char *new_name =dso__filename_with_chroot (dso,dso__long_name (dso)); -if (new_name &&filename__read_build_id (new_name, &bid,/*block=*/ true) >0 ) { +if (new_name &&filename__read_build_id (new_name, &bid) >0 ) {dso__set_build_id (dso, &bid); args->have_build_id = true; }
tools/perf/util/libbfd.c +7 -2
@@ -418,13 +418,18 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)return err; } -int libbfd__read_build_id (const char *filename,struct build_id *bid,bool block) +int libbfd__read_build_id (const char *filename,struct build_id *bid) {size_t size =sizeof (bid->data);int err =-1 , fd;bfd *abfd; - fd =open (filename, block ?O_RDONLY : (O_RDONLY |O_NONBLOCK )); +if (!filename) +return -EFAULT ; +if (!is_regular_file (filename)) +return -EWOULDBLOCK ; + + fd =open (filename,O_RDONLY );if (fd <0 )return -1 ;
tools/perf/util/libbfd.h +2 -3
@@ -25,7 +25,7 @@ void dso__free_a2l_libbfd(struct dso *dso);int symbol__disassemble_libbfd (const char *filename,struct symbol *sym,struct annotate_args *args); -int libbfd__read_build_id (const char *filename,struct build_id *bid,bool block); +int libbfd__read_build_id (const char *filename,struct build_id *bid);int libbfd_filename__read_debuglink (const char *filename,char *debuglink,size_t size);
@@ -59,8 +59,7 @@ static inline int symbol__disassemble_libbfd(const char *filename __always_unuse }static inline int libbfd__read_build_id (const char *filename__always_unused , -struct build_id *bid__always_unused , -bool block__always_unused ) +struct build_id *bid__always_unused ) {return -1 ; }
tools/perf/util/symbol-elf.c +7 -6
@@ -874,20 +874,20 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } -static int read_build_id (const char *filename,struct build_id *bid,bool block) +static int read_build_id (const char *filename,struct build_id *bid) {size_t size =sizeof (bid->data);int fd, err;Elf *elf; - err =libbfd__read_build_id (filename, bid, block); + err =libbfd__read_build_id (filename, bid);if (err >=0 ) goto out;if (size <BUILD_ID_SIZE ) goto out; - fd =open (filename, block ?O_RDONLY : (O_RDONLY |O_NONBLOCK )); + fd =open (filename,O_RDONLY );if (fd <0 ) goto out;
@@ -908,7 +908,7 @@ static int read_build_id(const char *filename, struct build_id *bid, bool block)return err; } -int filename__read_build_id (const char *filename,struct build_id *bid,bool block) +int filename__read_build_id (const char *filename,struct build_id *bid) {struct kmod_path m = { .name =NULL , };char path[PATH_MAX ];
@@ -916,6 +916,8 @@ int filename__read_build_id(const char *filename, struct build_id *bid, bool bloif (!filename)return -EFAULT ; +if (!is_regular_file (filename)) +return -EWOULDBLOCK ; err =kmod_path__parse (&m, filename);if (err)
@@ -932,10 +934,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid, bool blo }close (fd); filename = path; - block = true; } - err =read_build_id (filename, bid, block); + err =read_build_id (filename, bid);if (m.comp)unlink (filename);
tools/perf/util/symbol-minimal.c +8 -3
@@ -94,7 +94,7 @@ int filename__read_debuglink(const char *filename __maybe_unused,/* * Just try PT_NOTE header otherwise fails */ -int filename__read_build_id (const char *filename,struct build_id *bid,bool block) +int filename__read_build_id (const char *filename,struct build_id *bid) {int fd, ret =-1 ;bool need_swap = false, elf32;
@@ -111,7 +111,12 @@ int filename__read_build_id(const char *filename, struct build_id *bid, bool blovoid *phdr, *buf =NULL ;ssize_t phdr_size, ehdr_size, buf_size =0 ; - fd =open (filename, block ?O_RDONLY : (O_RDONLY |O_NONBLOCK )); +if (!filename) +return -EFAULT ; +if (!is_regular_file (filename)) +return -EWOULDBLOCK ; + + fd =open (filename,O_RDONLY );if (fd <0 )return -1 ;
@@ -335,7 +340,7 @@ int dso__load_sym(struct dso *dso, struct map *map __maybe_unused,if (ret >=0 )RC_CHK_ACCESS (dso)->is_64_bit = ret; -if (filename__read_build_id (ss->name, &bid,/*block=*/ true) >0 ) +if (filename__read_build_id (ss->name, &bid) >0 )dso__set_build_id (dso, &bid);return 0 ; }
tools/perf/util/symbol.c +2 -3
@@ -1755,14 +1755,13 @@ int dso__load(struct dso *dso, struct map *map)/* * Read the build id if possible. This is required for -* DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work. Don't block in case path -* isn't for a regular file. +* DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work. */ if (!dso__has_build_id (dso)) {struct build_id bid = { .size =0 , };__symbol__join_symfs (name,PATH_MAX ,dso__long_name (dso)); -if (filename__read_build_id (name, &bid,/*block=*/ false) >0 ) +if (filename__read_build_id (name, &bid) >0 )dso__set_build_id (dso, &bid); }
tools/perf/util/symbol.h +1 -1
@@ -140,7 +140,7 @@ struct symbol *dso__next_symbol(struct symbol *sym);enum dso_type dso__type_fd (int fd); -int filename__read_build_id (const char *filename,struct build_id *id,bool block); +int filename__read_build_id (const char *filename,struct build_id *id);int sysfs__read_build_id (const char *filename,struct build_id *bid); int modules__parse(const char *filename, void *arg, int (*process_module)(void *arg, const char *name,
tools/perf/util/synthetic-events.c +1 -1
@@ -401,7 +401,7 @@ static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event, nsi =nsinfo__new (event->pid);nsinfo__mountns_enter (nsi, &nc); - rc =filename__read_build_id (event->filename, &bid,/*block=*/ false) >0 ?0 :-1 ; + rc =filename__read_build_id (event->filename, &bid) >0 ?0 :-1 ;nsinfo__mountns_exit (&nc);nsinfo__put (nsi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 773/1611 perf tools: Add O_CLOEXEC to open() calls in DSO and ELF code
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 b145137fec13dc8fc7fcb14193ce395a1164e3a1 ]
open() calls in dso.c and symbol-elf.c omit O_CLOEXEC, which leaks file descriptors to child processes spawned during symbol resolution (e.g., addr2line, objdump). This can exhaust the fd limit during long profiling sessions or when processing many DSOs.
Add O_CLOEXEC to all open() calls in both files (12 call sites).
Stable-dep-of: f973e52a9977 ("perf dso: Fix heap overflow in dso__get_filename() on decompressed path")
--- tools/perf/util/dso.c | 4 ++-- tools/perf/util/symbol-elf.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-)
tools/perf/util/dso.c +2 -2
@@ -343,7 +343,7 @@ int filename__decompress(const char *name, char *pathname,* descriptor to the uncompressed file. */ if (!compressions[comp].is_compressed (name)) -return open (name,O_RDONLY ); +return open (name,O_RDONLY |O_CLOEXEC ); fd =mkstemp (tmpbuf);if (fd <0 ) {
@@ -1843,7 +1843,7 @@ static const u8 *__dso__read_symbol(struct dso *dso, const char *symfs_filename,int saved_errno;nsinfo__mountns_enter (dso__nsinfo (dso), &nsc); - fd =open (symfs_filename,O_RDONLY ); + fd =open (symfs_filename,O_RDONLY |O_CLOEXEC ); saved_errno = errno;nsinfo__mountns_exit (&nsc);if (fd <0 ) {
tools/perf/util/symbol-elf.c +10 -10
@@ -217,7 +217,7 @@ bool filename__has_section(const char *filename, const char *sec)GElf_Shdr shdr;bool found = false; - fd =open (filename,O_RDONLY ); + fd =open (filename,O_RDONLY |O_CLOEXEC );if (fd <0 )return false;
@@ -887,7 +887,7 @@ static int read_build_id(const char *filename, struct build_id *bid)if (size <BUILD_ID_SIZE ) goto out; - fd =open (filename,O_RDONLY ); + fd =open (filename,O_RDONLY |O_CLOEXEC );if (fd <0 ) goto out;
@@ -948,7 +948,7 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid)size_t size =sizeof (bid->data);int fd, err =-1 ; - fd =open (filename,O_RDONLY ); + fd =open (filename,O_RDONLY |O_CLOEXEC );if (fd <0 ) goto out;
@@ -1019,7 +1019,7 @@ int filename__read_debuglink(const char *filename, char *debuglink,if (err >=0 ) goto out; - fd =open (filename,O_RDONLY ); + fd =open (filename,O_RDONLY |O_CLOEXEC );if (fd <0 ) goto out;
@@ -1184,7 +1184,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, type =dso__symtab_type (dso); }else { - fd =open (name,O_RDONLY ); + fd =open (name,O_RDONLY |O_CLOEXEC );if (fd <0 ) { *dso__load_errno (dso) = errno;return -1 ;
@@ -1985,7 +1985,7 @@ static int kcore__open(struct kcore *kcore, const char *filename) {GElf_Ehdr *ehdr; - kcore->fd =open (filename,O_RDONLY ); + kcore->fd =open (filename,O_RDONLY |O_CLOEXEC );if (kcore->fd ==-1 )return -1 ;
@@ -2018,7 +2018,7 @@ static int kcore__init(struct kcore *kcore, char *filename, int elfclass,if (temp) kcore->fd =mkstemp (filename);else - kcore->fd =open (filename,O_WRONLY |O_CREAT |O_EXCL ,0400 ); + kcore->fd =open (filename,O_WRONLY |O_CREAT |O_EXCL |O_CLOEXEC ,0400 );if (kcore->fd ==-1 )return -1 ;
@@ -2494,11 +2494,11 @@ static int kcore_copy__compare_files(const char *from_filename, {int from, to, err =-1 ; - from =open (from_filename,O_RDONLY ); + from =open (from_filename,O_RDONLY |O_CLOEXEC );if (from <0 )return -1 ; - to =open (to_filename,O_RDONLY ); + to =open (to_filename,O_RDONLY |O_CLOEXEC );if (to <0 ) goto out_close_from;
@@ -2916,7 +2916,7 @@ int get_sdt_note_list(struct list_head *head, const char *target)Elf *elf;int fd, ret; - fd =open (target,O_RDONLY ); + fd =open (target,O_RDONLY |O_CLOEXEC );if (fd <0 )return -EBADF ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 774/1611 perf tools: Fix uninitialized pathname on uncompressed fallback in filename__decompress()
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 51cdb188edeaf389e4377859b9c483c19ce5a259 ]
filename__decompress() has an early return path for files that are not actually compressed. This path returns the fd from open() directly but never writes to the pathname output parameter, leaving the caller with an uninitialized buffer despite a successful return.
Callers like dso__decompress_kmodule_path() pass pathname to decompress_kmodule() which uses it to set the decompressed file path. If pathname is uninitialized, subsequent operations on the path produce undefined behavior.
Fix by setting pathname to an empty string on the uncompressed path. Callers already check for an empty pathname to distinguish temporary decompressed files (which need unlink) from the original file.
Stable-dep-of: f973e52a9977 ("perf dso: Fix heap overflow in dso__get_filename() on decompressed path")
--- tools/perf/tests/code-reading.c | 7 +++++-- tools/perf/util/disasm.c | 7 +++++-- tools/perf/util/dso.c | 12 +++++++++--- tools/perf/util/symbol-elf.c | 6 ++++-- 4 files changed, 23 insertions(+), 9 deletions(-)
tools/perf/tests/code-reading.c +5 -2
@@ -465,8 +465,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, goto out; } - decomp = true; - objdump_name = decomp_name; +/* empty pathname means file wasn't actually compressed */ +if (decomp_name[0 ] !='\0' ) { + decomp = true; + objdump_name = decomp_name; + } }/* Read the object code using objdump */
tools/perf/util/disasm.c +5 -2
@@ -1684,8 +1684,11 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)if (dso__decompress_kmodule_path (dso, symfs_filename, tmp,sizeof (tmp)) <0 )return -1 ; - decomp = true; -strcpy (symfs_filename, tmp); +/* empty pathname means file wasn't actually compressed */ +if (tmp[0 ] !='\0' ) { + decomp = true; +strcpy (symfs_filename, tmp); + } }/*
tools/perf/util/dso.c +9 -3
@@ -342,8 +342,11 @@ int filename__decompress(const char *name, char *pathname,* To keep this transparent, we detect this and return the file * descriptor to the uncompressed file. */ -if (!compressions[comp].is_compressed (name)) +if (!compressions[comp].is_compressed (name)) { +if (pathname && len >0 ) + pathname[0 ] ='\0' ;return open (name,O_RDONLY |O_CLOEXEC ); + } fd =mkstemp (tmpbuf);if (fd <0 ) {
@@ -600,8 +603,11 @@ static char *dso__get_filename(struct dso *dso, const char *root_dir, goto out; } - *decomp = true; -strcpy (name, newpath); +/* empty pathname means file wasn't actually compressed */ +if (newpath[0 ] !='\0' ) { + *decomp = true; +strcpy (name, newpath); + } }return name;
tools/perf/util/symbol-elf.c +4 -2
@@ -933,12 +933,14 @@ int filename__read_build_id(const char *filename, struct build_id *bid)return -1 ; }close (fd); - filename = path; +/* non-empty path means a temp file was created */ +if (path[0 ] !='\0' ) + filename = path; } err =read_build_id (filename, bid); -if (m.comp) +if (m.comp && filename == path)unlink (filename);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 775/1611 perf dso: Fix heap overflow in dso__get_filename() on decompressed 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 f973e52a99776fcc473488984828d1fce56d5382 ]
dso__get_filename() allocates name with malloc(PATH_MAX), but the dso__filename_with_chroot() path replaces name with an asprintf'd exact-size string (e.g. 8 bytes for "/a/b.ko"). When the DSO needs decompression, dso__decompress_kmodule_path() writes the temp path ("/tmp/perf-kmod-XXXXXX", 22 bytes) into newpath, and strcpy(name, newpath) overflows the smaller allocation.
Replace the strcpy with strdup(newpath) + free(name) so the buffer is always correctly sized for its content.
--- tools/perf/util/dso.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/dso.c +8 -1
@@ -605,8 +605,15 @@ static char *dso__get_filename(struct dso *dso, const char *root_dir,/* empty pathname means file wasn't actually compressed */ if (newpath[0 ] !='\0' ) { +char *tmp =strdup (newpath); + +if (!tmp) { +unlink (newpath); + goto out; + } +free (name); + name = tmp; *decomp = true; -strcpy (name, newpath); } }return name;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 776/1611 perf dso: Set error code when open() fails on uncompressed fallback 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 d2c6069d68ee9d53b05fe38bc2049cc4286fbb16 ]
filename__decompress() has an early return for files that are not actually compressed, where it calls open() directly. When open() fails, the function returns -1 but never sets *err. The caller chain (decompress_kmodule → dso__decompress_kmodule_path → dso__get_filename) then reads *dso__load_errno(dso) to set errno, but that field was never populated, so errno gets a stale or zero value.
With errno=0, __open_dso() computes fd = -errno = 0, which is non- negative, so callers treat fd 0 (stdin) as a valid DSO file descriptor.
Set *err = errno when open() fails on the uncompressed path, matching the error handling on the compressed path at line 354.
--- tools/perf/util/dso.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/dso.c +4 -1
@@ -343,9 +343,12 @@ int filename__decompress(const char *name, char *pathname,* descriptor to the uncompressed file. */ if (!compressions[comp].is_compressed (name)) { + fd =open (name,O_RDONLY |O_CLOEXEC ); +if (fd <0 ) + *err = errno;if (pathname && len >0 ) pathname[0 ] ='\0' ; -return open (name,O_RDONLY |O_CLOEXEC ); +return fd; } fd =mkstemp (tmpbuf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 777/1611 perf tools: Use snprintf() for root_dir path construction
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 7b0df6f4d498b1608afccfd6dffb264e6da91693 ]
get_kernel_version() in machine.c and dso__load_guest_kernel_sym() in symbol.c use sprintf() to construct paths by prepending root_dir to "/proc/version" and "/proc/kallsyms" respectively. Both write into PATH_MAX stack buffers, but root_dir comes from --guestmount or KVM configuration and is not length-checked. A root_dir at or near PATH_MAX causes a stack buffer overflow.
Switch to snprintf() with sizeof(path) to prevent overflow.
--- tools/perf/util/machine.c | 2 +- tools/perf/util/symbol.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +1 -1
@@ -1319,7 +1319,7 @@ static char *get_kernel_version(const char *root_dir)char *name, *tmp;const char *prefix ="Linux version " ; -sprintf (version,"%s/proc/version" , root_dir); +snprintf (version,sizeof (version),"%s/proc/version" , root_dir); file =fopen (version,"r" );if (!file)return NULL ;
tools/perf/util/symbol.c +1 -1
@@ -2166,7 +2166,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)if (!kallsyms_filename)return -1 ; }else { -sprintf (path,"%s/proc/kallsyms" , machine->root_dir); +snprintf (path,sizeof (path),"%s/proc/kallsyms" , machine->root_dir); kallsyms_filename = path; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 778/1611 perf hwmon: Fix fd check to accept fd 0 in hwmon_pmu__describe_items()
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 cfafef390ca9c753b34c7e97b5abee4cab0ce270 ]
hwmon_pmu__describe_items() checks 'if (fd > 0)' after openat(), which incorrectly rejects fd 0. While fd 0 is normally stdin, if stdin has been closed (common in daemon/service contexts), the kernel reuses fd 0 for the next open. With fd > 0, the sysfs file is not read and the fd is leaked.
Change to 'if (fd >= 0)' to match the standard openat() error check.
--- tools/perf/util/hwmon_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/hwmon_pmu.c +1 -1
@@ -435,7 +435,7 @@ static size_t hwmon_pmu__describe_items(struct hwmon_pmu *hwm, char *out_buf, si hwmon_item_strs[bit], is_alarm ? "_alarm" : ""); fd =openat (dir, buf,O_RDONLY ); -if (fd >0 ) { +if (fd >=0 ) {ssize_t read_len =read (fd, buf,sizeof (buf) -1 );while (read_len >0 && buf[read_len -1 ] =='\n' )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 779/1611 perf sched: Replace (void*)1 sentinel with proper runtime allocation
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 500f5dd0a8b6f7bd174102587c7dff5a7d2fecbf ]
map__findnew_thread() marks color-pid threads by storing (void*)1 as the thread private data via thread__set_priv(). This sentinel value causes two problems:
1. thread__get_runtime() returns (void*)1 as a struct thread_runtime pointer. Any field access (e.g. tr->shortname) dereferences address 1, which is an unmapped page — immediate segfault.
2. cmd_sched() registers free() as the thread priv destructor, so thread cleanup calls free((void*)1) — undefined behavior that corrupts the heap on many allocators.
Fix by adding a 'color' flag to struct thread_runtime and allocating a real runtime struct for color-pid threads. thread__has_color() now checks the flag instead of relying on priv being non-NULL.
--- tools/perf/builtin-sched.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
tools/perf/builtin-sched.c +17 -6
@@ -267,6 +267,7 @@ struct thread_runtime {u64 migrations;int prio; +bool color; };/* per event run time data */
@@ -1589,22 +1590,32 @@ static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unusstatic bool thread__has_color (struct thread *thread) { -return thread__priv (thread) !=NULL ; +struct thread_runtime *tr =thread__priv (thread); + +return tr !=NULL && tr->color; }static struct thread *map__findnew_thread (struct perf_sched *sched,struct machine *machine,pid_t pid,pid_t tid) {struct thread *thread =machine__findnew_thread (machine, pid, tid); -bool color = false; -if (!sched->map.color_pids || !thread ||thread__priv (thread)) +if (!sched->map.color_pids || !thread)return thread; -if (thread_map__has (sched->map.color_pids, tid)) - color = true; +/* +* Always check the color-pids map, even if thread__priv() is +* already set. COMM events processed before the first sched_switch +* allocate a thread_runtime via thread__get_runtime(), so priv is +* non-NULL before we ever get here. Skipping the check on non-NULL +* priv would prevent those threads from being colored. +*/ +if (thread_map__has (sched->map.color_pids, tid)) { +struct thread_runtime *tr =thread__get_runtime (thread); -thread__set_priv (thread, color ? ((void *)1 ) :NULL ); +if (tr) + tr->color = true; + }return thread; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 780/1611 perf bpf: Validate func_info_rec_size and sub_id in synthesize_bpf_prog_name()
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 10b3c3d63ecc17c6acb855bac5f40367f1115765 ]
synthesize_bpf_prog_name() computes a pointer into the func_info array using sub_id * info->func_info_rec_size without validating either value. Both come from perf.data and are untrusted:
- A func_info_rec_size smaller than sizeof(struct bpf_func_info) means the finfo pointer would reference a truncated entry, reading past it into adjacent data.
- A sub_id >= nr_func_info computes an offset past the func_info buffer, causing an out-of-bounds read.
Add bounds checks for both values before computing the pointer offset. When validation fails, fall through to the non-BTF name path instead of reading garbage.
--- tools/perf/util/bpf-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/bpf-event.c +3 -1
@@ -143,7 +143,9 @@ static int synthesize_bpf_prog_name(char *buf, int size, name_len =scnprintf (buf, size,"bpf_prog_" ); name_len +=snprintf_hex (buf + name_len, size - name_len, prog_tags[sub_id],BPF_TAG_SIZE ); -if (btf) { +if (btf && + info->func_info_rec_size >=sizeof (*finfo) && + sub_id < info->nr_func_info) { finfo = func_infos + sub_id * info->func_info_rec_size; t =btf__type_by_id (btf, finfo->type_id);if (t)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 781/1611 perf bpf: Reject oversized BPF metadata events that truncate 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 2d6ea0875093da9033fcb62c09a9e2f1de49fe91 ]
bpf_metadata_alloc() computes event_size from the number of BPF metadata variables and stores it in header.size, which is __u16. With 204 or more .rodata variables prefixed "bpf_metadata_", event_size exceeds 65535 and silently truncates.
The truncated header.size causes synthesize_perf_record_bpf_metadata() to allocate a buffer sized by the truncated value, then memcpy the full event data into it — a heap buffer overflow.
Add a check that event_size fits in __u16 before proceeding. BPF programs with that many metadata variables are exotic enough that silently dropping the metadata is acceptable.
--- tools/perf/util/bpf-event.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/util/bpf-event.c +9 -0
@@ -369,6 +369,15 @@ static struct bpf_metadata *bpf_metadata_alloc(__u32 nr_prog_tags, event_size =sizeof (metadata->event->bpf_metadata) + nr_variables *sizeof (metadata->event->bpf_metadata.entries[0 ]); +/* +* header.size is __u16. synthesize_perf_record_bpf_metadata() +* adds machine->id_hdr_size (up to ~64 bytes) after this, so +* leave headroom to prevent the final size from wrapping. +*/ +if (event_size >UINT16_MAX -256 ) { +bpf_metadata_free (metadata); +return NULL ; + } metadata->event =zalloc (event_size);if (!metadata->event) {bpf_metadata_free (metadata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 782/1611 perf bpf: Bounds-check array offsets in bpil_offs_to_addr()
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 033e85edfbf271f92979d2a39aeaf40f8472a795 ]
bpil_offs_to_addr() converts offsets stored in perf.data's bpf_prog_info_linear structure into heap pointers by adding the offset to the data allocation base. The offsets come from untrusted file input and are not validated against data_len.
If an offset exceeds data_len, the computed address points outside the allocated data buffer. Callers like synthesize_bpf_prog_name() then dereference prog_tags[sub_id] or func_info pointers, reading arbitrary heap memory.
Add a bounds check: when an offset exceeds data_len, zero the field and skip the conversion. This prevents out-of-bounds pointer construction from crafted perf.data files.
--- tools/perf/util/bpf-utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/perf/util/bpf-utils.c +16 -0
@@ -264,12 +264,28 @@ void bpil_offs_to_addr(struct perf_bpil *info_linear)for (i =PERF_BPIL_FIRST_ARRAY ; i <PERF_BPIL_LAST_ARRAY ; ++i) {const struct bpil_array_desc *desc = &bpil_array_desc[i];__u64 addr, offs; +__u32 count, size;if ((info_linear->arrays & (1UL << i)) ==0 )continue ; offs =bpf_prog_info_read_offset_u64 (&info_linear->info, desc->array_offset); + count =bpf_prog_info_read_offset_u32 (&info_linear->info, + desc->count_offset); + size =bpf_prog_info_read_offset_u32 (&info_linear->info, + desc->size_offset); +/* offset and extent from perf.data are untrusted — keep within data[] */ +if (offs >= info_linear->data_len || + (u64 )count * size > info_linear->data_len - offs) { +bpf_prog_info_set_offset_u64 (&info_linear->info, + desc->array_offset,0 ); +bpf_prog_info_set_offset_u32 (&info_linear->info, + desc->count_offset,0 ); +/* clear the bit so bpil_addr_to_offs() won't reverse a zeroed address */ + info_linear->arrays &= ~(1UL << i); +continue ; + } addr = offs +ptr_to_u64 (info_linear->data);bpf_prog_info_set_offset_u64 (&info_linear->info, desc->array_offset, addr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 783/1611 perf: Remove redundant kernel.h include
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit 7a0ba3891104da77cfd1a16d41699e0fdf45603a ]
Now that the bitfield dependency is resolved, the explicit inclusion of kernel.h is no longer needed.
Remove the redundant include.
Stable-dep-of: 542e88a4c6f7 ("perf cs-etm: Reject CPU IDs that would overflow signed comparison")
--- tools/perf/arch/arm64/util/header.c | 1 - tools/perf/util/cs-etm.c | 1 - 2 files changed, 2 deletions(-)
tools/perf/arch/arm64/util/header.c +0 -1
@@ -1,4 +1,3 @@ -#include <linux/kernel.h> #include <linux/bits.h> #include <linux/bitfield.h> #include <stdio.h>
tools/perf/util/cs-etm.c +0 -1
@@ -6,7 +6,6 @@* Author: Mathieu Poirier <[email protected]> */ -#include <linux/kernel.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/coresight-pmu.h>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 784/1611 perf cs-etm: Reject CPU IDs that would overflow signed comparison
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 542e88a4c6f7b6edd1326ce767d4cb3c2ea9d61d ]
metadata[j][CS_ETM_CPU] is a u64 from perf.data, but the comparison with max_cpu casts it to (int). A crafted value like 0xFFFFFFFF becomes -1 after the cast, which compares less than max_cpu (0), so the queue array is never sized to accommodate it. When the value is later passed to cs_etm__get_queue(), it indexes queue_array with the original large value, causing an out-of-bounds access.
Validate that CS_ETM_CPU fits in an int before using it in the signed comparison.
--- tools/perf/util/cs-etm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +8 -1
@@ -6,6 +6,7 @@* Author: Mathieu Poirier <[email protected]> */ +#include <limits.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/coresight-pmu.h>
@@ -3479,7 +3480,13 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, goto err_free_metadata; } -if ((int ) metadata[j][CS_ETM_CPU ] > max_cpu) +/* CPU id comes from perf.data and must fit max_cpu + 1 without overflow */ +if (metadata[j][CS_ETM_CPU ] >=INT_MAX ) { + err = -EINVAL ; + goto err_free_metadata; + } + +if ((int )metadata[j][CS_ETM_CPU ] > max_cpu) max_cpu = metadata[j][CS_ETM_CPU ]; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 785/1611 gpio: mlxbf3: fail probe if gpiochip registration fails
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 0482862a90169f4daaba0ed31a85d8304bf51e04 ]
mlxbf3_gpio_probe() logs a devm_gpiochip_add_data() failure but still returns success. That leaves the platform device bound even though the GPIO chip was not registered.
Return the registration error so probe failure matches the missing gpiochip state.
--- drivers/gpio/gpio-mlxbf3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mlxbf3.c +2 -1
@@ -255,7 +255,8 @@ static int mlxbf3_gpio_probe(struct platform_device *pdev) ret =devm_gpiochip_add_data (dev, gc, gs);if (ret) -dev_err_probe (dev, ret,"Failed adding memory mapped gpiochip\n" ); +return dev_err_probe (dev, ret, +"Failed adding memory mapped gpiochip\n" );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 786/1611 drm/i915: clear CRTC color blob pointers after dropping refs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 31f077088e0faae6be8377741f356dea1b94ba46 ]
intel_crtc_put_color_blobs() drops the CRTC color blob references, but leaves the corresponding pointers unchanged.
This can matter in intel_crtc_prepare_cleared_state(), which frees the old CRTC hw state before calling intel_dp_tunnel_atomic_clear_stream_bw(). The latter can fail while looking up the DP tunnel group state, for example with -EDEADLK.
If that happens, the function returns without completing the cleared state preparation. The failed atomic state will then be cleared by the atomic core and intel_crtc_free_hw_state() can be called again for the same state, dropping the same blob references again.
Clear the blob pointers after dropping the references so repeated cleanup of the same CRTC hw state is safe.
--- drivers/gpu/drm/i915/display/intel_atomic.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/display/intel_atomic.c +6 -0
@@ -289,6 +289,12 @@ static void intel_crtc_put_color_blobs(struct intel_crtc_state *crtc_state)drm_property_blob_put (crtc_state->pre_csc_lut);drm_property_blob_put (crtc_state->post_csc_lut); + + crtc_state->hw.degamma_lut =NULL ; + crtc_state->hw.gamma_lut =NULL ; + crtc_state->hw.ctm =NULL ; + crtc_state->pre_csc_lut =NULL ; + crtc_state->post_csc_lut =NULL ; }void intel_crtc_free_hw_state (struct intel_crtc_state *crtc_state)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 787/1611 drm/xe: Fix wa_oob codegen recipe for external module builds
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Hellström <[email protected]>
[ Upstream commit 92dc59ab2a09097cdf249e0288ff9b69261761c6 ]
When building with 'make M=drivers/gpu/drm/xe modules', kbuild invokes scripts/Makefile.build with obj=., causing $(obj) to expand to '.'. Make normalizes './xe_gen_wa_oob' to 'xe_gen_wa_oob' when constructing the $^ automatic variable (target name normalization), so the recipe command becomes just 'xe_gen_wa_oob ...' without any path prefix, and the shell cannot find the tool.
Fix by replacing $^ with explicit $(obj)/xe_gen_wa_oob and $(src)/<rules-file> references in both wa_oob recipe commands. In recipe strings, make does not apply target name normalization, so $(obj)/xe_gen_wa_oob correctly expands to './xe_gen_wa_oob' and the shell can execute it. This matches the pattern already used by other DRM drivers (e.g. radeon's mkregtable).
--- drivers/gpu/drm/xe/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/Makefile +2 -2
@@ -16,14 +16,14 @@ subdir-ccflags-y += -I$(obj) -I$(src) hostprogs := xe_gen_wa_oob generated_oob := $(obj)/generated/xe_wa_oob.c $(obj)/generated/xe_wa_oob.h quiet_cmd_wa_oob = GEN $(notdir $(generated_oob)) - cmd_wa_oob = mkdir -p $(@D); $^ $(generated_oob) + cmd_wa_oob = mkdir -p $(@D); $(obj)/xe_gen_wa_oob $(src)/xe_wa_oob.rules $(generated_oob) $(obj)/generated/%_wa_oob.c $(obj)/generated/%_wa_oob.h: $(obj)/xe_gen_wa_oob \ $(src)/xe_wa_oob.rules $(call cmd,wa_oob) generated_device_oob := $(obj)/generated/xe_device_wa_oob.c $(obj)/generated/xe_device_wa_oob.h quiet_cmd_device_wa_oob = GEN $(notdir $(generated_device_oob)) - cmd_device_wa_oob = mkdir -p $(@D); $^ $(generated_device_oob) + cmd_device_wa_oob = mkdir -p $(@D); $(obj)/xe_gen_wa_oob $(src)/xe_device_wa_oob.rules $(generated_device_oob) $(obj)/generated/%_device_wa_oob.c $(obj)/generated/%_device_wa_oob.h: $(obj)/xe_gen_wa_oob \ $(src)/xe_device_wa_oob.rules $(call cmd,device_wa_oob)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 788/1611 spi: dw: fix wrong BAUDR setting after resume
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jisheng Zhang <[email protected]>
[ Upstream commit 66b6605bcea7af7aca3d1d858b9c5f14903f9f9a ]
After resuming from suspend to ram, spi transfer stops working. Further debugging shows that the BAUDR register isn't correctly set, this is due to dws->current_freq doesn't match the HW BAUDR setting, specifically, the dws->current_freq equals to speed_hz, but BAUDR is 0. so the dw_spi_set_clk() in below code won't be called:
if (dws->current_freq != speed_hz) {
dw_spi_set_clk(dws, clk_div);
dws->current_freq = speed_hz;
}The mismatch comes from dw_spi_shutdown_chip() when suspending. Fix this mismatch by setting dws->current_freq to 0 as well when clearing BAUDR reg in dw_spi_shutdown_chip().
--- drivers/spi/spi-dw.h | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spi-dw.h +1 -0
@@ -282,6 +282,7 @@ static inline void dw_spi_shutdown_chip(struct dw_spi *dws) {dw_spi_enable_chip (dws,0 );dw_spi_set_clk (dws,0 ); + dws->current_freq =0 ; }extern void dw_spi_set_cs (struct spi_device *spi,bool enable);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 789/1611 i3c: master: Update dev_nack_retry_count under maintenance lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit ab5f9c5cb527c03790a92142ad368881a9100aaf ]
Protect master->dev_nack_retry_count against concurrent sysfs updates by updating it while holding the bus maintenance lock.
Consequently, combine adjacent return statements into one.
For consistency, read dev_nack_retry_count while holding the bus normaluse lock.
--- drivers/i3c/master.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/i3c/master.c +11 -7
@@ -744,7 +744,14 @@ static DEVICE_ATTR_RW(hotjoin);static ssize_t dev_nack_retry_count_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sysfs_emit (buf,"%u\n" ,dev_to_i3cmaster (dev)->dev_nack_retry_count); +struct i3c_bus *i3cbus =dev_to_i3cbus (dev); +ssize_t ret; + +i3c_bus_normaluse_lock (i3cbus); + ret =sysfs_emit (buf,"%u\n" ,dev_to_i3cmaster (dev)->dev_nack_retry_count); +i3c_bus_normaluse_unlock (i3cbus); + +return ret; } static ssize_t dev_nack_retry_count_store(struct device *dev,
@@ -762,14 +769,11 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,i3c_bus_maintenance_lock (i3cbus); ret = master->ops->set_dev_nack_retry (master, val); +if (!ret) + master->dev_nack_retry_count = val;i3c_bus_maintenance_unlock (i3cbus); -if (ret) -return ret; - - master->dev_nack_retry_count = val; - -return count; +return ret ?: count; }static DEVICE_ATTR_RW (dev_nack_retry_count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 790/1611 i3c: master: Add missing runtime PM get in dev_nack_retry_count_store()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 79ce29e100ab3de0cad66eb48d32a7de4043e2ae ]
Ensure the device is runtime resumed while updating the retry configuration to avoid accessing the controller while suspended.
Call i3c_master_rpm_get() before accessing the controller in dev_nack_retry_count_store() and release it with i3c_master_rpm_put() afterwards.
--- drivers/i3c/master.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i3c/master.c +6 -0
@@ -767,12 +767,18 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,if (ret)return ret; + ret =i3c_master_rpm_get (master); +if (ret) +return ret; +i3c_bus_maintenance_lock (i3cbus); ret = master->ops->set_dev_nack_retry (master, val);if (!ret) master->dev_nack_retry_count = val;i3c_bus_maintenance_unlock (i3cbus); +i3c_master_rpm_put (master); +return ret ?: count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 791/1611 ALSA: usb-audio: qcom: Free sideband sg_table objects
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 7d69804a35103a50852eae41bfe6a2e0061c68fd ]
The Qualcomm USB audio offload driver obtains an endpoint transfer-ring table by calling xhci_sideband_get_endpoint_buffer(). This getter passes the endpoint ring to xhci_ring_to_sgtable(), which allocates the outer struct sg_table with kzalloc_obj(*sgt). The event-ring path is
equivalent: xhci_sideband_get_event_buffer() also returns the result of xhci_ring_to_sgtable().
Inside xhci_ring_to_sgtable(), sg_alloc_table_from_pages() separately allocates the scatterlist storage referenced by sgt->sgl. The returned object therefore has two allocation layers: the outer struct sg_table and its internal scatterlist storage.
The Qualcomm caller only invokes sg_free_table(sgt). sg_free_table() releases the scatterlist storage owned by the table, but it does not free the separately allocated outer struct sg_table. The local sgt pointer is then discarded, so every successful endpoint or event-ring query leaks the outer object.
Call kfree(sgt) after sg_free_table(sgt) in both setup paths, after the required page and DMA addresses have been copied out.
--- sound/usb/qcom/qc_audio_offload.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/qcom/qc_audio_offload.c +2 -0
@@ -1165,6 +1165,7 @@ uaudio_endpoint_setup(struct snd_usb_substream *subs, tr_pa =page_to_phys (pg); mem_info->dma =sg_dma_address (sgt->sgl);sg_free_table (sgt); +kfree (sgt);/* data transfer ring */ iova = uaudio_iommu_map_pa(MEM_XFER_RING, dma_coherent, tr_pa,
@@ -1234,6 +1235,7 @@ static int uaudio_event_ring_setup(struct snd_usb_substream *subs, er_pa =page_to_phys (pg); mem_info->dma =sg_dma_address (sgt->sgl);sg_free_table (sgt); +kfree (sgt); iova =uaudio_iommu_map_pa (MEM_EVENT_RING , dma_coherent, er_pa,PAGE_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 792/1611 xfrm: Fix xfrm state cache insertion race
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herbert Xu <[email protected]>
[ Upstream commit ddd3d0132920319ac426e12456013eadbae67e15 ]
The xfrm input state cache insertion code checks the validity of the state before acquiring the global xfrm_state_lock. Thus it's possible for someone else to kill the state after it passed the validity check, and then the insertion will add the dead state to the cache.
Fix this by moving the validity check inside the lock.
This entire function is called on the input path, where BH must be off (e.g., the caller of this function xfrm_input acquires its spinlocks without disabling BH).
So there is no need to disable BH here or take the RCU read lock. Remove both and replace them with an assertion that trips if BH is accidentally enabled on some future calling path.
--- net/xfrm/xfrm_state.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
net/xfrm/xfrm_state.c +14 -7
@@ -1207,9 +1207,11 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,struct hlist_head *state_cache_input;struct xfrm_state *x =NULL ; +/* BH is always disabled on the input path. */ +lockdep_assert_in_softirq (); + state_cache_input =raw_cpu_ptr (net->xfrm.state_cache_input); -rcu_read_lock ();hlist_for_each_entry_rcu (x, state_cache_input, state_cache_input) { if (x->props.family != family || x->id.spi != spi ||
@@ -1227,20 +1229,25 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,xfrm_hash_ptrs_get (net, &state_ptrs); x =__xfrm_state_lookup (&state_ptrs, mark, daddr, spi, proto, family); - -if (x && x->km.state ==XFRM_STATE_VALID ) { -spin_lock_bh (&net->xfrm.xfrm_state_lock); -if (hlist_unhashed (&x->state_cache_input)) { +if (x) { +spin_lock (&net->xfrm.xfrm_state_lock); +if (x->km.state !=XFRM_STATE_VALID ) { +/* +* The state is about to be destroyed. +* +* Don't add it to the cache but still +* return it to the caller. +*/ + }else if (hlist_unhashed (&x->state_cache_input)) {hlist_add_head_rcu (&x->state_cache_input, state_cache_input); }else {hlist_del_rcu (&x->state_cache_input);hlist_add_head_rcu (&x->state_cache_input, state_cache_input); } -spin_unlock_bh (&net->xfrm.xfrm_state_lock); +spin_unlock (&net->xfrm.xfrm_state_lock); } out: -rcu_read_unlock ();return x; }EXPORT_SYMBOL (xfrm_input_state_lookup);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 793/1611 xfrm: annotate data-races around xfrm_policy_count[] and xfrm_policy_default[]
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 68de007d5ac9df0e3f4f187a179c5c842bb5a2be ]
KCSAN reported a data race involving net->xfrm.policy_count access.
Add missing READ_ONCE()/WRITE_ONCE() annotations on xfrm_policy_count and xfrm_policy_default.
--- include/net/xfrm.h | 8 ++++---- net/xfrm/xfrm_policy.c | 24 ++++++++++++------------ net/xfrm/xfrm_user.c | 18 +++++++++--------- 3 files changed, 25 insertions(+), 25 deletions(-)
include/net/xfrm.h +4 -4
@@ -1250,8 +1250,8 @@ int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb,static inline bool __xfrm_check_nopolicy (struct net *net,struct sk_buff *skb,int dir) { -if (!net->xfrm.policy_count[dir] && !secpath_exists (skb)) -return net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_ACCEPT ; +if (!READ_ONCE (net->xfrm.policy_count[dir]) && !secpath_exists (skb)) +return READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_ACCEPT ;return false; }
@@ -1351,8 +1351,8 @@ static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) {struct net *net =dev_net (skb->dev); -if (!net->xfrm.policy_count[XFRM_POLICY_OUT ] && - net->xfrm.policy_default[XFRM_POLICY_OUT ] ==XFRM_USERPOLICY_ACCEPT ) +if (!READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]) && +READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]) ==XFRM_USERPOLICY_ACCEPT )return true; return (skb_dst(skb)->flags & DST_NOXFRM) ||
net/xfrm/xfrm_policy.c +12 -12
@@ -685,7 +685,7 @@ static void xfrm_byidx_resize(struct net *net)static inline int xfrm_bydst_should_resize (struct net *net,int dir,int *total) { -unsigned int cnt = net->xfrm.policy_count[dir]; +unsigned int cnt =READ_ONCE (net->xfrm.policy_count[dir]);unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;if (total)
@@ -711,12 +711,12 @@ static inline int xfrm_byidx_should_resize(struct net *net, int total)void xfrm_spd_getinfo (struct net *net,struct xfrmk_spdinfo *si) { - si->incnt = net->xfrm.policy_count[XFRM_POLICY_IN ]; - si->outcnt = net->xfrm.policy_count[XFRM_POLICY_OUT ]; - si->fwdcnt = net->xfrm.policy_count[XFRM_POLICY_FWD ]; - si->inscnt = net->xfrm.policy_count[XFRM_POLICY_IN +XFRM_POLICY_MAX ]; - si->outscnt = net->xfrm.policy_count[XFRM_POLICY_OUT +XFRM_POLICY_MAX ]; - si->fwdscnt = net->xfrm.policy_count[XFRM_POLICY_FWD +XFRM_POLICY_MAX ]; + si->incnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_IN ]); + si->outcnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]); + si->fwdcnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_FWD ]); + si->inscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_IN +XFRM_POLICY_MAX ]); + si->outscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT +XFRM_POLICY_MAX ]); + si->fwdscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_FWD +XFRM_POLICY_MAX ]); si->spdhcnt = net->xfrm.policy_idx_hmask; si->spdhmcnt = xfrm_policy_hashmax; }
@@ -2318,7 +2318,7 @@ static void __xfrm_policy_link(struct xfrm_policy *pol, int dir) }list_add (&pol->walk.all, &net->xfrm.policy_all); - net->xfrm.policy_count[dir]++; +WRITE_ONCE (net->xfrm.policy_count[dir], net->xfrm.policy_count[dir] +1 );xfrm_pol_hold (pol); }
@@ -2337,7 +2337,7 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol, }list_del_init (&pol->walk.all); - net->xfrm.policy_count[dir]--; +WRITE_ONCE (net->xfrm.policy_count[dir], net->xfrm.policy_count[dir] -1 );return pol; }
@@ -3222,7 +3222,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,/* To accelerate a bit... */ if (!if_id && ((dst_orig->flags &DST_NOXFRM ) || - !net->xfrm.policy_count[XFRM_POLICY_OUT ])) + !READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]))) goto nopol; xdst =xfrm_bundle_lookup (net, fl, family, dir, &xflo, if_id);
@@ -3296,7 +3296,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net, nopol:if ((!dst_orig->dev || !(dst_orig->dev->flags &IFF_LOOPBACK )) && - net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_BLOCK ) { +READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_BLOCK ) { err = -EPERM ; goto error; }
@@ -3750,7 +3750,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,const bool is_crypto_offload = sp && (xfrm_input_state (skb)->xso.type ==XFRM_DEV_OFFLOAD_CRYPTO ); -if (net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_BLOCK ) { +if (READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_BLOCK ) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOPOLS );return 0 ; }
net/xfrm/xfrm_user.c +9 -9
@@ -2476,9 +2476,9 @@ static int xfrm_notify_userpolicy(struct net *net) } up =nlmsg_data (nlh); - up->in = net->xfrm.policy_default[XFRM_POLICY_IN ]; - up->fwd = net->xfrm.policy_default[XFRM_POLICY_FWD ]; - up->out = net->xfrm.policy_default[XFRM_POLICY_OUT ]; + up->in =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ]); + up->fwd =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ]); + up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (skb, nlh);
@@ -2502,13 +2502,13 @@ static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_userpolicy_default *up =nlmsg_data (nlh);if (xfrm_userpolicy_is_valid (up->in)) - net->xfrm.policy_default[XFRM_POLICY_IN ] = up->in; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ], up->in);if (xfrm_userpolicy_is_valid (up->fwd)) - net->xfrm.policy_default[XFRM_POLICY_FWD ] = up->fwd; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ], up->fwd);if (xfrm_userpolicy_is_valid (up->out)) - net->xfrm.policy_default[XFRM_POLICY_OUT ] = up->out; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ], up->out);rt_genid_bump_all (net);
@@ -2538,9 +2538,9 @@ static int xfrm_get_default(struct sk_buff *skb, struct nlmsghdr *nlh, } r_up =nlmsg_data (r_nlh); - r_up->in = net->xfrm.policy_default[XFRM_POLICY_IN ]; - r_up->fwd = net->xfrm.policy_default[XFRM_POLICY_FWD ]; - r_up->out = net->xfrm.policy_default[XFRM_POLICY_OUT ]; + r_up->in =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ]); + r_up->fwd =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ]); + r_up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (r_skb, r_nlh);return nlmsg_unicast (net->xfrm.nlsk, r_skb, portid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 794/1611 xfrm: validate selector family and prefixlen during match
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 40f0b1047918539f0b0f795ac65e35336b4c2c78 ]
syzbot reported a shift-out-of-bounds in xfrm_selector_match() due to AF_UNSPEC selector with large prefixlen (e.g. 128) matched against IPv4 flow (when XFRM_STATE_AF_UNSPEC is set).
Fix this by:
- Rejecting mismatched families in xfrm_selector_match.
- Returning false in addr4_match if prefixlen > 32.
- Returning false in addr_match if prefixlen > 128 (prevents overflow).
--- include/net/xfrm.h | 7 +++++++ net/xfrm/xfrm_policy.c | 3 +++ 2 files changed, 10 insertions(+)
include/net/xfrm.h +7 -0
@@ -943,6 +943,9 @@ static inline bool addr_match(const void *token1, const void *token2,unsigned int pdw;unsigned int pbi; +if (prefixlen >128 ) +return false; + pdw = prefixlen >>5 ;/* num of whole u32 in prefix */ pbi = prefixlen &0x1f ;/* num of bits in incomplete u32 in prefix */
@@ -967,6 +970,10 @@ static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */ if (sizeof (long ) ==4 && prefixlen ==0 )return true; + +if (prefixlen >32 ) +return false; +return !((a1 ^ a2) &htonl (~0UL << (32 - prefixlen))); }
net/xfrm/xfrm_policy.c +3 -0
@@ -242,6 +242,9 @@ __xfrm6_selector_match(const struct xfrm_selector *sel, const struct flowi *fl)bool xfrm_selector_match (const struct xfrm_selector *sel,const struct flowi *fl,unsigned short family) { +if (family != sel->family && sel->family !=AF_UNSPEC ) +return false; +switch (family) {case AF_INET :return __xfrm4_selector_match (sel, fl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 795/1611 perf machine: Use snprintf() for guestmount path construction
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 fe63d3bca288c5bb983304efd5fc3a5ff3183403 ]
machines__findnew() and machines__create_guest_kernel_maps() use sprintf() to build paths by prepending symbol_conf.guestmount. Both write into PATH_MAX stack buffers, but guestmount comes from user configuration and is not length-checked. A guestmount path at or near PATH_MAX causes a stack buffer overflow.
Switch to snprintf() with sizeof() to prevent overflow. The subsequent access()/fopen() calls will fail on a truncated path.
--- tools/perf/util/machine.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/machine.c +4 -4
@@ -327,7 +327,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)if ((pid !=HOST_KERNEL_ID ) && (pid !=DEFAULT_GUEST_KERNEL_ID ) && (symbol_conf.guestmount)) { -sprintf (path,"%s/%d" , symbol_conf.guestmount, pid); +snprintf (path,sizeof (path),"%s/%d" , symbol_conf.guestmount, pid);if (access (path,R_OK )) {static struct strlist *seen;
@@ -1239,9 +1239,9 @@ int machines__create_guest_kernel_maps(struct machines *machines) namelist[i]->d_name);continue ; } -sprintf (path,"%s/%s/proc/kallsyms" , - symbol_conf.guestmount, - namelist[i]->d_name); +snprintf (path,sizeof (path),"%s/%s/proc/kallsyms" , + symbol_conf.guestmount, + namelist[i]->d_name); ret =access (path,R_OK );if (ret) {pr_debug ("Can't access file %s\n" , path);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 796/1611 perf cs-etm: Validate num_cpu before metadata allocation
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 312d91329b8fc6989a916a3f9a12d0674167b7e4 ]
cs_etm__process_auxtrace_info_full() reads num_cpu from untrusted perf.data and uses it to allocate the metadata pointer array:
metadata = zalloc(sizeof(*metadata) * num_cpu);
On 32-bit, sizeof(*metadata) is 4, so num_cpu = 0x40000000 overflows the multiplication to 0, causing zalloc(0) to return a valid zero-sized allocation followed by out-of-bounds writes in the population loop.
Fix by computing priv_size early and using it to bound num_cpu: each CPU needs at least one u64 metadata entry, so num_cpu cannot exceed the total number of u64 entries in the event's private data area.
--- tools/perf/util/cs-etm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/perf/util/cs-etm.c +12 -0
@@ -3442,6 +3442,18 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,/* First the global part */ ptr = (u64 *) auxtrace_info->priv; num_cpu = ptr[CS_PMU_TYPE_CPUS ] &0xffffffff ; + +/* +* Bound num_cpu by the event size: the global header consumes +* CS_ETM_HEADER_SIZE bytes, and each CPU needs at least one u64 +* metadata entry after that. +*/ + priv_size = total_size - event_header_size -INFO_HEADER_SIZE - +CS_ETM_HEADER_SIZE ; +if (num_cpu <=0 || priv_size <=0 || + num_cpu > priv_size / (int )sizeof (u64)) +return -EINVAL ; + metadata =zalloc (sizeof (*metadata) * num_cpu);if (!metadata)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 797/1611 perf cs-etm: Require full global header in auxtrace_info size check
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 78d8ba680126f3545e8d0fba667e12d79fd4353b ]
cs_etm__process_auxtrace_info() checks that header.size covers event_header_size + INFO_HEADER_SIZE (16 bytes total), but then accesses ptr[CS_PMU_TYPE_CPUS] at offset 24 from the start of the event. A crafted 16-byte auxtrace_info event passes the size check but reads out-of-bounds.
Include CS_ETM_HEADER_SIZE in the minimum size check so that the global header entries (version, pmu_type_cpus, snapshot) are guaranteed to fit within the event.
--- tools/perf/util/cs-etm-base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm-base.c +3 -1
@@ -170,7 +170,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event,u64 *ptr =NULL ;u64 hdr_version; -if (auxtrace_info->header.size < (event_header_size +INFO_HEADER_SIZE )) +/* Ensure priv[] is large enough for the global header entries */ +if (auxtrace_info->header.size < (event_header_size +INFO_HEADER_SIZE + +CS_ETM_HEADER_SIZE ))return -EINVAL ;/* First the global part */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 798/1611 perf cs-etm: Bounds-check CPU in cs_etm__get_queue()
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 9a989e60cc6e29d98aed2087425cba53bf4b392d ]
cs_etm__get_queue() indexes etm->queues.queue_array[cpu] without validating that cpu is within nr_queues. When processing AUX_OUTPUT_HW_ID events, the cpu value comes from untrusted perf.data trace payload and flows through cs_etm__process_trace_id_v0_1() and cs_etm__queue_aux_fragment() without bounds checking, allowing an out-of-bounds read with a crafted file.
Add a bounds check in cs_etm__get_queue() and NULL checks in all callers.
Also add NULL checks for queue_array[i].priv in the queue iteration loops in cs_etm__map_trace_id_v0() and cs_etm__process_trace_id_v0_1() — after auxtrace_queues__grow() new entries are zero-initialized so .priv can be NULL. Add a get_cpu_data() NULL check in cs_etm__process_trace_id_v0_1(), matching the existing check in cs_etm__process_trace_id_v0().
--- tools/perf/util/cs-etm.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +23 -2
@@ -292,8 +292,11 @@ static struct cs_etm_queue *cs_etm__get_queue(struct cs_etm_auxtrace *etm, int c {if (etm->per_thread_decoding)return etm->queues.queue_array[0 ].priv; -else -return etm->queues.queue_array[cpu].priv; + +if (cpu <0 || cpu >= (int )etm->queues.nr_queues) +return NULL ; + +return etm->queues.queue_array[cpu].priv; } static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_id,
@@ -306,6 +309,9 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_id* queue associated with that CPU so only one decoder is made. */ etmq =cs_etm__get_queue (etm, cpu_metadata[CS_ETM_CPU ]); +if (!etmq) +return -EINVAL ; +if (etmq->format ==UNFORMATTED )return cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);
@@ -318,6 +324,9 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_idint ret; etmq = etm->queues.queue_array[i].priv; +if (!etmq) +continue ; + ret =cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);if (ret)
@@ -358,6 +367,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu,u32 sink_id =FIELD_GET (CS_AUX_HW_ID_SINK_ID_MASK , hw_id);u8 trace_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id); +if (!etmq) +return -EINVAL ; +/* * Check sink id hasn't changed in per-cpu mode. In per-thread mode, * let it pass for now until an actual overlapping trace ID is hit. In
@@ -375,6 +387,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu,for (unsigned int i =0 ; i < etm->queues.nr_queues; ++i) {struct cs_etm_queue *other_etmq = etm->queues.queue_array[i].priv; +if (!other_etmq) +continue ; +/* Different sinks, skip */ if (other_etmq->sink_id != etmq->sink_id)continue ;
@@ -396,6 +411,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu, } cpu_data =get_cpu_data (etm, cpu); +if (!cpu_data) +return -EINVAL ; + ret =cs_etm__insert_trace_id_node (etmq, trace_id, cpu_data);if (ret)return ret;
@@ -3155,6 +3173,9 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o aux_offset + aux_size <= auxtrace_event->offset + auxtrace_event->size) {struct cs_etm_queue *etmq =cs_etm__get_queue (etm, auxtrace_event->cpu); +if (!etmq) +return -EINVAL ; +/* * If this AUX event was inside this buffer somewhere, create a new auxtrace event * based on the sizes of the aux event, and queue that fragment.
Signature · 1 line
2.53.0