7.1.5-rc1 review
Subsystems (15)
Greg Kroah-Hartman
maintainerPATCH 808/2077 RDMA/bnxt_re: Update msn table size for app allocated QPs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sriharsha Basavapatna <[email protected]>
[ Upstream commit 9ce2a8c81c3099f68d371d040d77aab8cd1a9ed5 ]
For app allocated QPs, the driver shouldn't use slots/round-up logic to compute the msn table size. The application handles this logic and computes 'sq_npsn' and passes it to the driver using a new uapi parameter.
Stable-dep-of: dc95931b7e13 ("RDMA/bnxt_re: Add a max slot check for SQ")
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 61 +++++++++++++++--------- include/uapi/rdma/bnxt_re-abi.h | 1 + 2 files changed, 40 insertions(+), 22 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +39 -22
@@ -1159,29 +1159,39 @@ static int bnxt_re_setup_sginfo(struct bnxt_re_dev *rdev,static int bnxt_re_get_psn_bytes (struct bnxt_re_dev *rdev,struct bnxt_re_ucontext *cntx,struct bnxt_qplib_qp *qplib_qp, -struct bnxt_re_qp_req *ureq) +struct bnxt_re_qp_req *ureq, +bool fixed_que_attr) {int psn_sz, psn_nume; - psn_sz =bnxt_qplib_is_chip_gen_p5_p7 (rdev->chip_ctx) ? -sizeof (struct sq_psn_search_ext ) : -sizeof (struct sq_psn_search ); -if (cntx &&bnxt_re_is_var_size_supported (rdev, cntx)) { - psn_nume = ureq->sq_slots; +if (rdev->dev_attr && +_is_host_msn_table (rdev->dev_attr->dev_cap_flags2)) + psn_sz =sizeof (struct sq_msn_search ); +else + psn_sz =bnxt_qplib_is_chip_gen_p5_p7 (rdev->chip_ctx) ? +sizeof (struct sq_psn_search_ext ) : +sizeof (struct sq_psn_search ); +if (!fixed_que_attr) { +if (cntx &&bnxt_re_is_var_size_supported (rdev, cntx)) { + psn_nume = ureq->sq_slots; + }else { + psn_nume = (qplib_qp->wqe_mode ==BNXT_QPLIB_WQE_MODE_STATIC ) ? + qplib_qp->sq.max_wqe : ((qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) / +sizeof (struct bnxt_qplib_sge )); + } +if (_is_host_msn_table (rdev->qplib_res.dattr->dev_cap_flags2)) + psn_nume =roundup_pow_of_two (psn_nume); }else { - psn_nume = (qplib_qp->wqe_mode ==BNXT_QPLIB_WQE_MODE_STATIC ) ? - qplib_qp->sq.max_wqe : ((qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) / -sizeof (struct bnxt_qplib_sge )); + psn_nume = ureq->sq_npsn; } -if (_is_host_msn_table (rdev->qplib_res.dattr->dev_cap_flags2)) - psn_nume =roundup_pow_of_two (psn_nume);return psn_nume * psn_sz; }static int bnxt_re_init_user_qp (struct bnxt_re_dev *rdev,struct bnxt_re_pd *pd,struct bnxt_re_qp *qp,struct bnxt_re_ucontext *cntx, -struct bnxt_re_qp_req *ureq) +struct bnxt_re_qp_req *ureq, +bool fixed_que_attr) {struct bnxt_qplib_qp *qplib_qp;struct ib_umem *umem;
@@ -1193,7 +1203,7 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd, bytes = (qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size);/* Consider mapping PSN search memory only for RC QPs. */ if (qplib_qp->type ==CMDQ_CREATE_QP_TYPE_RC ) - bytes +=bnxt_re_get_psn_bytes (rdev, cntx, qplib_qp, ureq); + bytes +=bnxt_re_get_psn_bytes (rdev, cntx, qplib_qp, ureq, fixed_que_attr); bytes =PAGE_ALIGN (bytes); umem = ib_umem_get(&rdev->ibdev, ureq->qpsva, bytes,
@@ -1636,7 +1646,9 @@ static int bnxt_re_init_qp_type(struct bnxt_re_dev *rdev,return qptype; } -static void bnxt_re_qp_calculate_msn_psn_size (struct bnxt_re_qp *qp) +static void bnxt_re_qp_calculate_msn_psn_size (struct bnxt_re_qp *qp, +bool fixed_que_attr, +struct bnxt_re_qp_req *req) {struct bnxt_qplib_qp *qplib_qp = &qp->qplib_qp;struct bnxt_qplib_q *sq = &qplib_qp->sq;
@@ -1659,12 +1671,17 @@ static void bnxt_re_qp_calculate_msn_psn_size(struct bnxt_re_qp *qp)/* Update msn tbl size */ if (qplib_qp->is_host_msn_tbl && qplib_qp->psn_sz) { -if (wqe_mode ==BNXT_QPLIB_WQE_MODE_STATIC ) - qplib_qp->msn_tbl_sz = -roundup_pow_of_two (bnxt_qplib_set_sq_size (sq, wqe_mode)); -else - qplib_qp->msn_tbl_sz = -roundup_pow_of_two (bnxt_qplib_set_sq_size (sq, wqe_mode)) /2 ; +if (!fixed_que_attr) { +if (wqe_mode ==BNXT_QPLIB_WQE_MODE_STATIC ) + qplib_qp->msn_tbl_sz = +roundup_pow_of_two (bnxt_qplib_set_sq_size (sq, wqe_mode)); +else + qplib_qp->msn_tbl_sz = +roundup_pow_of_two (bnxt_qplib_set_sq_size (sq, wqe_mode)) + /2 ; + }else { + qplib_qp->msn_tbl_sz = req->sq_npsn; + } qplib_qp->msn =0 ; } }
@@ -1738,12 +1755,12 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,bnxt_re_adjust_gsi_sq_attr (qp, init_attr, uctx);if (uctx) {/* This will update DPI and qp_handle */ - rc =bnxt_re_init_user_qp (rdev, pd, qp, uctx, ureq); + rc =bnxt_re_init_user_qp (rdev, pd, qp, uctx, ureq, fixed_que_attr);if (rc)return rc; } -bnxt_re_qp_calculate_msn_psn_size (qp); +bnxt_re_qp_calculate_msn_psn_size (qp, fixed_que_attr, ureq); rc =bnxt_re_setup_qp_hwqs (qp);if (rc)
include/uapi/rdma/bnxt_re-abi.h +1 -0
@@ -135,6 +135,7 @@ struct bnxt_re_qp_req {__aligned_u64 qp_handle;__aligned_u64 comp_mask;__u32 sq_slots; +__u32 sq_npsn; };struct bnxt_re_qp_resp {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 809/2077 RDMA/bnxt_re: Enhance dbr usecnt logic in doorbell uapis
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sriharsha Basavapatna <[email protected]>
[ Upstream commit 73607410f4f1b0d5c3d0af2d70a79c265482a0e3 ]
The current logic in the doorbell cleanup function is not sufficient for a change in a subsequent patch, that fails doorbell remove operation in some conditions. The cleanup should facilitate freeing of the dbr object when the caller may not retry the teardown operation (implicit teardown:
process-exit/driver-removal).
Extend this counter to use kref mechanism so that the dbr object gets freed (via kref callback) when there are no more references to it, rather than directly freeing it in the cleanup uapi.
Stable-dep-of: dc95931b7e13 ("RDMA/bnxt_re: Add a max slot check for SQ")
--- drivers/infiniband/hw/bnxt_re/ib_verbs.h | 3 ++- drivers/infiniband/hw/bnxt_re/uapi.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.h +2 -1
@@ -167,7 +167,7 @@ struct bnxt_re_dbr_obj {struct bnxt_re_dev *rdev;struct bnxt_qplib_dpi dpi;struct bnxt_re_user_mmap_entry *entry; -atomic_t usecnt;/* QPs using this dbr */ +struct kref usecnt;/* 1 (uobject) + n (QPs using this dbr) */ };struct bnxt_re_flow {
@@ -308,4 +308,5 @@ void bnxt_re_unlock_cqs(struct bnxt_re_qp *qp, unsigned long flags);struct bnxt_re_user_mmap_entry *bnxt_re_mmap_entry_insert (struct bnxt_re_ucontext *uctx,u64 mem_offset,enum bnxt_re_mmap_flag mmap_flag,u64 *offset); +void bnxt_re_dbr_kref_release (struct kref *ref);#endif /* __BNXT_RE_IB_VERBS_H__ */
drivers/infiniband/hw/bnxt_re/uapi.c +13 -3
@@ -369,6 +369,7 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_DBR_ALLOC)(struct uverbs_attr_bundle *a } obj->rdev = rdev; +kref_init (&obj->usecnt); uobj->object = obj;uverbs_finalize_uobj_create (attrs,BNXT_RE_ALLOC_DBR_HANDLE );
@@ -391,15 +392,24 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_DBR_ALLOC)(struct uverbs_attr_bundle *areturn ret; } +void bnxt_re_dbr_kref_release (struct kref *ref) +{ +struct bnxt_re_dbr_obj *obj = + container_of(ref, struct bnxt_re_dbr_obj, usecnt); +struct bnxt_re_dev *rdev = obj->rdev; + +rdma_user_mmap_entry_remove (&obj->entry->rdma_entry); +bnxt_qplib_free_uc_dpi (&rdev->qplib_res, &obj->dpi); +kfree (obj); +} +static int bnxt_re_dbr_cleanup (struct ib_uobject *uobject,enum rdma_remove_reason why,struct uverbs_attr_bundle *attrs) {struct bnxt_re_dbr_obj *obj = uobject->object; -struct bnxt_re_dev *rdev = obj->rdev; -rdma_user_mmap_entry_remove (&obj->entry->rdma_entry); -bnxt_qplib_free_uc_dpi (&rdev->qplib_res, &obj->dpi); +kref_put (&obj->usecnt, bnxt_re_dbr_kref_release);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 810/2077 RDMA/bnxt_re: Support doorbells for app allocated QPs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sriharsha Basavapatna <[email protected]>
[ Upstream commit 7e812673a948395675e9893e75b0fc60d19bbf27 ]
App allocated QPs can use a separate doorbell for each QP. This doorbell region can be passed through a new driver specific DBR_HANDLE attribute, during QP creation. When this attribute is set, associate the QP with the given doorbell region.
While the QP holds a reference to the dbr, the dbr itself cannot be destroyed and is rejected with EBUSY error.
Stable-dep-of: dc95931b7e13 ("RDMA/bnxt_re: Add a max slot check for SQ")
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 35 ++++++++++++++++++++---- drivers/infiniband/hw/bnxt_re/ib_verbs.h | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 24 ++++++++++++++++ include/uapi/rdma/bnxt_re-abi.h | 4 +++ 4 files changed, 59 insertions(+), 5 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +30 -5
@@ -1024,6 +1024,9 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp, struct ib_udata *udata)if (rc)ibdev_err (&rdev->ibdev,"Failed to destroy HW QP" ); +if (qp->dbr_obj) +kref_put (&qp->dbr_obj->usecnt, bnxt_re_dbr_kref_release); +if (rdma_is_kernel_res (&qp->ib_qp.res)) { flags =bnxt_re_lock_cqs (qp);bnxt_qplib_clean_qp (&qp->qplib_qp);
@@ -1191,7 +1194,8 @@ static int bnxt_re_get_psn_bytes(struct bnxt_re_dev *rdev,static int bnxt_re_init_user_qp (struct bnxt_re_dev *rdev,struct bnxt_re_pd *pd,struct bnxt_re_qp *qp,struct bnxt_re_ucontext *cntx,struct bnxt_re_qp_req *ureq, -bool fixed_que_attr) +bool fixed_que_attr, +struct bnxt_re_dbr_obj *dbr_obj) {struct bnxt_qplib_qp *qplib_qp;struct ib_umem *umem;
@@ -1234,8 +1238,11 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd, goto rqfail; done: +if (dbr_obj) + qplib_qp->dpi = &dbr_obj->dpi; +else + qplib_qp->dpi = &cntx->dpi; qplib_qp->qp_handle = ureq->qp_handle; - qplib_qp->dpi = &cntx->dpi; qplib_qp->is_user = true;return 0 ;
@@ -1689,7 +1696,8 @@ static void bnxt_re_qp_calculate_msn_psn_size(struct bnxt_re_qp *qp,static int bnxt_re_init_qp_attr (struct bnxt_re_qp *qp,struct bnxt_re_pd *pd,struct ib_qp_init_attr *init_attr,struct bnxt_re_ucontext *uctx, -struct bnxt_re_qp_req *ureq) +struct bnxt_re_qp_req *ureq, +struct bnxt_re_dbr_obj *dbr_obj) {struct bnxt_qplib_dev_attr *dev_attr;struct bnxt_qplib_qp *qplqp;
@@ -1755,7 +1763,8 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,bnxt_re_adjust_gsi_sq_attr (qp, init_attr, uctx);if (uctx) {/* This will update DPI and qp_handle */ - rc =bnxt_re_init_user_qp (rdev, pd, qp, uctx, ureq, fixed_que_attr); + rc =bnxt_re_init_user_qp (rdev, pd, qp, uctx, ureq, fixed_que_attr, + dbr_obj);if (rc)return rc; }
@@ -1891,7 +1900,9 @@ static int bnxt_re_add_unique_gid(struct bnxt_re_dev *rdev)int bnxt_re_create_qp (struct ib_qp *ib_qp,struct ib_qp_init_attr *qp_init_attr,struct ib_udata *udata) { +struct bnxt_re_dbr_obj *dbr_obj =NULL ;struct bnxt_qplib_dev_attr *dev_attr; +struct uverbs_attr_bundle *attrs;struct bnxt_re_ucontext *uctx;struct bnxt_re_qp_req ureq;struct bnxt_re_dev *rdev;
@@ -1912,6 +1923,17 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr, rc =ib_copy_validate_udata_in_cm (udata, ureq, qp_handle,0 );if (rc)return rc; + + attrs =rdma_udata_to_uverbs_attr_bundle (udata); +if (uverbs_attr_is_valid (attrs, +BNXT_RE_CREATE_QP_ATTR_DBR_HANDLE )) { + dbr_obj =uverbs_attr_get_obj (attrs, +BNXT_RE_CREATE_QP_ATTR_DBR_HANDLE ); +if (IS_ERR (dbr_obj)) +return PTR_ERR (dbr_obj); +kref_get (&dbr_obj->usecnt); + qp->dbr_obj = dbr_obj; + } } rc =bnxt_re_test_qp_limits (rdev, qp_init_attr, dev_attr);
@@ -1921,7 +1943,8 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr, } qp->rdev = rdev; - rc =bnxt_re_init_qp_attr (qp, pd, qp_init_attr, uctx, &ureq); + rc =bnxt_re_init_qp_attr (qp, pd, qp_init_attr, uctx, &ureq, + dbr_obj);if (rc) goto fail;
@@ -1991,6 +2014,8 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,bnxt_qplib_free_qp_res (&rdev->qplib_res, &qp->qplib_qp);bnxt_re_qp_free_umem (qp); fail: +if (dbr_obj) +kref_put (&dbr_obj->usecnt, bnxt_re_dbr_kref_release);return rc; }
drivers/infiniband/hw/bnxt_re/ib_verbs.h +1 -0
@@ -96,6 +96,7 @@ struct bnxt_re_qp {struct bnxt_re_cq *scq;struct bnxt_re_cq *rcq;struct dentry *dentry; +struct bnxt_re_dbr_obj *dbr_obj;/* doorbell region */ };struct bnxt_re_cq {
drivers/infiniband/hw/bnxt_re/uapi.c +24 -0
@@ -409,6 +409,15 @@ static int bnxt_re_dbr_cleanup(struct ib_uobject *uobject, {struct bnxt_re_dbr_obj *obj = uobject->object; +/* If it is being destroyed explicitly while QPs still hold a +* reference (> 1), reject it with EBUSY. If no QP references +* or implicit teardown (process exit, driver removal), drop +* the uobject reference unconditionally. The object gets freed +* (bnxt_re_dbr_kref_release) when the usecnt goes to zero. +*/ +if (why ==RDMA_REMOVE_DESTROY &&kref_read (&obj->usecnt) >1 ) +return -EBUSY ; +kref_put (&obj->usecnt, bnxt_re_dbr_kref_release);return 0 ; }
@@ -469,11 +478,26 @@ DECLARE_UVERBS_NAMED_METHOD(BNXT_RE_METHOD_GET_DEFAULT_DBR,DECLARE_UVERBS_GLOBAL_METHODS (BNXT_RE_OBJECT_DEFAULT_DBR , &UVERBS_METHOD (BNXT_RE_METHOD_GET_DEFAULT_DBR )); +ADD_UVERBS_ATTRIBUTES_SIMPLE ( + bnxt_re_qp_create, +UVERBS_OBJECT_QP , +UVERBS_METHOD_QP_CREATE , +UVERBS_ATTR_IDR (BNXT_RE_CREATE_QP_ATTR_DBR_HANDLE , +BNXT_RE_OBJECT_DBR , +UVERBS_ACCESS_READ , +UA_OPTIONAL )); + +const struct uapi_definition bnxt_re_create_qp_defs[] = { +UAPI_DEF_CHAIN_OBJ_TREE (UVERBS_OBJECT_QP , &bnxt_re_qp_create), + {}, +}; +const struct uapi_definition bnxt_re_uapi_defs[] = {UAPI_DEF_CHAIN_OBJ_TREE_NAMED (BNXT_RE_OBJECT_ALLOC_PAGE ),UAPI_DEF_CHAIN_OBJ_TREE_NAMED (BNXT_RE_OBJECT_NOTIFY_DRV ),UAPI_DEF_CHAIN_OBJ_TREE_NAMED (BNXT_RE_OBJECT_GET_TOGGLE_MEM ),UAPI_DEF_CHAIN_OBJ_TREE_NAMED (BNXT_RE_OBJECT_DBR ),UAPI_DEF_CHAIN_OBJ_TREE_NAMED (BNXT_RE_OBJECT_DEFAULT_DBR ), +UAPI_DEF_CHAIN (bnxt_re_create_qp_defs), {} };
include/uapi/rdma/bnxt_re-abi.h +4 -0
@@ -138,6 +138,10 @@ struct bnxt_re_qp_req {__u32 sq_npsn; }; +enum bnxt_re_create_qp_attrs { +BNXT_RE_CREATE_QP_ATTR_DBR_HANDLE =UVERBS_ID_DRIVER_NS_WITH_UHW , +}; +struct bnxt_re_qp_resp {__u32 qpid;__u32 rsvd;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 811/2077 RDMA/bnxt_re: Enable app allocated QPs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sriharsha Basavapatna <[email protected]>
[ Upstream commit 47b730054f05a05acd497c138bf3255a5de1a973 ]
The driver supports a new comp_mask: REQ_MASK_FIXED_QUE_ATTR. The application sets this comp_mask bit in the CREATE_QP ureq to indicate direct control of the QP. The driver goes through the required processing for app allocated QPs (previous patches). Only variable WQE mode is supported for these QPs.
This patch removes an unused comp_mask:
BNXT_RE_QP_REQ_MASK_VAR_WQE_SQ_SLOTS
Stable-dep-of: dc95931b7e13 ("RDMA/bnxt_re: Add a max slot check for SQ")
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 18 +++++++++++++++--- include/uapi/rdma/bnxt_re-abi.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +15 -3
@@ -1697,7 +1697,8 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,struct ib_qp_init_attr *init_attr, struct bnxt_re_ucontext *uctx, struct bnxt_re_qp_req *ureq, - struct bnxt_re_dbr_obj *dbr_obj) + struct bnxt_re_dbr_obj *dbr_obj, + bool fixed_que_attr) { struct bnxt_qplib_dev_attr *dev_attr;struct bnxt_qplib_qp *qplqp;
@@ -1720,6 +1721,13 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,return qptype; qplqp->type = (u8 )qptype; qplqp->wqe_mode =bnxt_re_is_var_size_supported (rdev, uctx); +if (fixed_que_attr) { +if (qplqp->wqe_mode !=BNXT_QPLIB_WQE_MODE_VARIABLE ) +return -EOPNOTSUPP ; +if (!ureq->sq_npsn || + ureq->sq_npsn >roundup_pow_of_two (ureq->sq_slots /2 )) +return -EINVAL ; + } qplqp->dev_cap_flags = dev_attr->dev_cap_flags; qplqp->cctx = rdev->chip_ctx;if (init_attr->qp_type ==IB_QPT_RC ) {
@@ -1904,6 +1912,7 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,struct bnxt_qplib_dev_attr *dev_attr;struct uverbs_attr_bundle *attrs;struct bnxt_re_ucontext *uctx; +bool fixed_que_attr = false;struct bnxt_re_qp_req ureq;struct bnxt_re_dev *rdev;struct bnxt_re_pd *pd;
@@ -1920,7 +1929,8 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr, uctx = rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext, ib_uctx);if (udata) { - rc =ib_copy_validate_udata_in_cm (udata, ureq, qp_handle,0 ); + rc =ib_copy_validate_udata_in_cm (udata, ureq, qp_handle, +BNXT_RE_QP_REQ_MASK_FIXED_QUE_ATTR );if (rc)return rc;
@@ -1934,6 +1944,8 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,kref_get (&dbr_obj->usecnt); qp->dbr_obj = dbr_obj; } +if (ureq.comp_mask &BNXT_RE_QP_REQ_MASK_FIXED_QUE_ATTR ) + fixed_que_attr = true; } rc =bnxt_re_test_qp_limits (rdev, qp_init_attr, dev_attr);
@@ -1944,7 +1956,7 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr, qp->rdev = rdev; rc =bnxt_re_init_qp_attr (qp, pd, qp_init_attr, uctx, &ureq, - dbr_obj); + dbr_obj, fixed_que_attr);if (rc) goto fail;
include/uapi/rdma/bnxt_re-abi.h +1 -1
@@ -126,7 +126,7 @@ struct bnxt_re_resize_cq_req { };enum bnxt_re_qp_mask { -BNXT_RE_QP_REQ_MASK_VAR_WQE_SQ_SLOTS =0x1 , +BNXT_RE_QP_REQ_MASK_FIXED_QUE_ATTR =0x1 , };struct bnxt_re_qp_req {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 812/2077 RDMA/bnxt_re: Add a max slot check for SQ
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
[ Upstream commit dc95931b7e1326dacae547874bf38c092e5960d8 ]
The variable WQE mode must be validated against the maximum slots supported by HW. The max supported value is 64K. Adding a max and min check and fail if user supplied value is more than the max supported and zero.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 3 +++ drivers/infiniband/hw/bnxt_re/qplib_sp.h | 1 + 2 files changed, 4 insertions(+)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3 -0
@@ -1721,6 +1721,9 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,return qptype; qplqp->type = (u8 )qptype; qplqp->wqe_mode =bnxt_re_is_var_size_supported (rdev, uctx); +if (uctx && qplqp->wqe_mode ==BNXT_QPLIB_WQE_MODE_VARIABLE && + (!ureq->sq_slots || ureq->sq_slots >BNXT_RE_MAX_SQ_SLOTS )) +return -EINVAL ;if (fixed_que_attr) {if (qplqp->wqe_mode !=BNXT_QPLIB_WQE_MODE_VARIABLE )return -EOPNOTSUPP ;
drivers/infiniband/hw/bnxt_re/qplib_sp.h +1 -0
@@ -369,6 +369,7 @@ int bnxt_qplib_destroy_flow(struct bnxt_qplib_res *res);#define BNXT_VAR_MAX_SLOT_ALIGN 256#define BNXT_VAR_MAX_SGE 13#define BNXT_RE_MAX_RQ_WQES 65536 +#define BNXT_RE_MAX_SQ_SLOTS 65536#define BNXT_STATIC_MAX_SGE 6
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 813/2077 RDMA/bnxt_re: Proper rollback if the ioremap fails
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
[ Upstream commit 87267803a8c824616eb147c5dad7030a5db6f878 ]
bnxt_qplib_alloc_dpi returns success even if ioremap fails. Add the proper rollback when the ioremap fails and return -ENOMEM status.
--- drivers/infiniband/hw/bnxt_re/qplib_res.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/infiniband/hw/bnxt_re/qplib_res.c +11 -0
@@ -764,9 +764,13 @@ int bnxt_qplib_alloc_dpi(struct bnxt_qplib_res *res,break ;case BNXT_QPLIB_DPI_TYPE_WC : dpi->dbr =ioremap_wc (umaddr,PAGE_SIZE ); +if (!dpi->dbr) + goto fail_ioremap;break ;default : dpi->dbr =ioremap (umaddr,PAGE_SIZE ); +if (!dpi->dbr) + goto fail_ioremap;break ; }
@@ -774,6 +778,13 @@ int bnxt_qplib_alloc_dpi(struct bnxt_qplib_res *res,mutex_unlock (&res->dpi_tbl_lock);return 0 ; +fail_ioremap: +/* Roll back the bit we just claimed. */ +set_bit (bit_num, dpit->tbl); + dpit->app_tbl[bit_num] =NULL ; +mutex_unlock (&res->dpi_tbl_lock); +return -ENOMEM ; + } int bnxt_qplib_dealloc_dpi(struct bnxt_qplib_res *res,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 814/2077 RDMA/bnxt_re: Avoid repeated requests to allocate WC pages
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
[ Upstream commit 441baa79043431807115fd030d7d0bb14ed441a0 ]
Applications can request multiple WC pages for the same ucontext. As of now, only 1 WC page per ucontext is supported. Add a lock to avoid concurrent access and a check to fail repeated requests. Also, if the mmap entry insert fails for the WC, free the Doorbell page index mapped for the WC page.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.h | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 33 +++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +1 -0
@@ -4720,6 +4720,7 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata) goto fail; }spin_lock_init (&uctx->sh_lock); +mutex_init (&uctx->wcdpi_lock); resp.comp_mask =BNXT_RE_UCNTX_CMASK_HAVE_CCTX ; chip_met_rev_num = rdev->chip_ctx->chip_num;
drivers/infiniband/hw/bnxt_re/ib_verbs.h +1 -0
@@ -142,6 +142,7 @@ struct bnxt_re_ucontext {struct bnxt_re_dev *rdev;struct bnxt_qplib_dpi dpi;struct bnxt_qplib_dpi wcdpi; +struct mutex wcdpi_lock;/* serialises WC DPI alloc/free */ void *shpg;spinlock_t sh_lock;/* protect shpg */ struct rdma_user_mmap_entry *shpage_mmap;
drivers/infiniband/hw/bnxt_re/uapi.c +27 -6
@@ -98,14 +98,23 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *switch (alloc_type) {case BNXT_RE_ALLOC_WC_PAGE : -if (cctx->modes.db_push) { +if (cctx->modes.db_push) { +mutex_lock (&uctx->wcdpi_lock); +/* already allocated — one WC page per context */ +if (uctx->wcdpi.dbr) { +mutex_unlock (&uctx->wcdpi_lock); +return -EEXIST ; + }if (bnxt_qplib_alloc_dpi (&rdev->qplib_res, &uctx->wcdpi, - uctx,BNXT_QPLIB_DPI_TYPE_WC )) + uctx,BNXT_QPLIB_DPI_TYPE_WC )) { +mutex_unlock (&uctx->wcdpi_lock);return -ENOMEM ; + } length =PAGE_SIZE ; dpi = uctx->wcdpi.dpi; addr = (u64 )uctx->wcdpi.umdbr; mmap_flag =BNXT_RE_MMAP_WC_DB ; +mutex_unlock (&uctx->wcdpi_lock); }else {return -EINVAL ; }
@@ -128,8 +137,15 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle * } entry =bnxt_re_mmap_entry_insert (uctx, addr, mmap_flag, &mmap_offset); -if (!entry) +if (!entry) { +if (mmap_flag ==BNXT_RE_MMAP_WC_DB ) { +mutex_lock (&uctx->wcdpi_lock); +bnxt_qplib_dealloc_dpi (&rdev->qplib_res, &uctx->wcdpi); + uctx->wcdpi.dbr =NULL ; +mutex_unlock (&uctx->wcdpi_lock); + }return -ENOMEM ; + } uobj->object = entry;uverbs_finalize_uobj_create (attrs,BNXT_RE_ALLOC_PAGE_HANDLE );
@@ -160,11 +176,16 @@ static int alloc_page_obj_cleanup(struct ib_uobject *uobject,switch (entry->mmap_flag) {case BNXT_RE_MMAP_WC_DB : -if (uctx && uctx->wcdpi.dbr) { +if (uctx) {struct bnxt_re_dev *rdev = uctx->rdev; -bnxt_qplib_dealloc_dpi (&rdev->qplib_res, &uctx->wcdpi); - uctx->wcdpi.dbr =NULL ; +mutex_lock (&uctx->wcdpi_lock); +if (uctx->wcdpi.dbr) { +bnxt_qplib_dealloc_dpi (&rdev->qplib_res, + &uctx->wcdpi); + uctx->wcdpi.dbr =NULL ; + } +mutex_unlock (&uctx->wcdpi_lock); }break ;case BNXT_RE_MMAP_DBR_BAR :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 815/2077 RDMA/bnxt_re: Fail DBR related page allocation UAPIs if the feature is disabled
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
[ Upstream commit a57592c6392a8e333c9c2731701297a5a279313a ]
No need to support the DBR related page allocations if the pacing feature is disabled. Fail the request if pacing is disabled.
--- drivers/infiniband/hw/bnxt_re/uapi.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/bnxt_re/uapi.c +4 -0
@@ -121,12 +121,16 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *break ;case BNXT_RE_ALLOC_DBR_BAR_PAGE : +if (!rdev->pacing.dbr_pacing) +return -EOPNOTSUPP ; length =PAGE_SIZE ; addr = (u64 )rdev->pacing.dbr_bar_addr; mmap_flag =BNXT_RE_MMAP_DBR_BAR ;break ;case BNXT_RE_ALLOC_DBR_PAGE : +if (!rdev->pacing.dbr_pacing) +return -EOPNOTSUPP ; length =PAGE_SIZE ; addr = (u64 )rdev->pacing.dbr_page; mmap_flag =BNXT_RE_MMAP_DBR_PAGE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 816/2077 RDMA/bnxt_re: Reject GET_TOGGLE_MEM when toggle page was not allocated
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
[ Upstream commit 33a215f499b0643cd88a32ab5b8de1547be419c6 ]
If a user calls BNXT_RE_METHOD_GET_TOGGLE_MEM on a device that does not support the CQ/SRQ toggle feature, uctx_cq_page or uctx_srq_page will be NULL.
Add an explicit -EOPNOTSUPP return after capturing the address from uctx_cq_page / uctx_srq_page if the address is zero.
--- drivers/infiniband/hw/bnxt_re/uapi.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/bnxt_re/uapi.c +4 -0
@@ -277,6 +277,8 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_GET_TOGGLE_MEM)(struct uverbs_attr_bundreturn -EINVAL ; addr = (u64 )cq->uctx_cq_page; +if (!addr) +return -EOPNOTSUPP ;break ;case BNXT_RE_SRQ_TOGGLE_MEM : srq =bnxt_re_search_for_srq (rdev, res_id);
@@ -284,6 +286,8 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_GET_TOGGLE_MEM)(struct uverbs_attr_bundreturn -EINVAL ; addr = (u64 )srq->uctx_srq_page; +if (!addr) +return -EOPNOTSUPP ;break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 817/2077 RDMA/hns: Fix memory leak of bonding resources
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junxian Huang <[email protected]>
[ Upstream commit c0bd03b850d81a8914168d87ddf7f6ffa58875ef ]
In a corner case of concurrent driver removal and driver reset, bonding resource is first released in hns_roce_hw_v2_exit() during driver removal, and then is allocated again in hns_roce_register_device() during driver reset. This leads to memory leak because the release timing has already passed. This may also lead to a kernel panic as below because of the leaked notifier callback:
Call trace: 0xffffa20fccc04978 (P) raw_notifier_call_chain+0x20/0x38 call_netdevice_notifiers_info+0x60/0xb8 netdev_lower_state_changed+0x4c/0xb8
As Sashiko suggested, the teardown order of bonding resources should be inverted to make sure the resources are released when the driver is removed.
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +1 -1
@@ -7586,8 +7586,8 @@ static int __init hns_roce_hw_v2_init(void) static void __exit hns_roce_hw_v2_exit(void) { -hns_roce_dealloc_bond_grp ();hnae3_unregister_client (&hns_roce_hw_v2_client); +hns_roce_dealloc_bond_grp ();hns_roce_cleanup_debugfs (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 818/2077 RDMA/irdma: Replace waitqueue and flag with completion
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Moroni <[email protected]>
[ Upstream commit d9c8c45e6d2f438a3c8e643ae78b59454fa0fadd ]
The driver previously used a waitqueue along with an explicit request_done flag, but without proper barriers around request_done.
An earlier patch by Gui-Dong Han <[email protected]> attempted to fix this by adding the missing memory barriers. Rather than adding the barriers, this patch replaces the waitqueue+flag with a completion, which is designed for this exact purpose.
--- drivers/infiniband/hw/irdma/hw.c | 7 +++---- drivers/infiniband/hw/irdma/main.h | 3 +-- drivers/infiniband/hw/irdma/utils.c | 12 +++++------- 3 files changed, 9 insertions(+), 13 deletions(-)
drivers/infiniband/hw/irdma/hw.c +3 -4
@@ -235,8 +235,7 @@ static void irdma_complete_cqp_request(struct irdma_cqp *cqp, struct irdma_cqp_request *cqp_request) {if (cqp_request->waiting) { -WRITE_ONCE (cqp_request->request_done, true); -wake_up (&cqp_request->waitq); +complete_all (&cqp_request->comp); }else if (cqp_request->callback_fcn) { cqp_request->callback_fcn (cqp_request); }
@@ -1107,9 +1106,9 @@ static int irdma_create_cqp(struct irdma_pci_f *rf)INIT_LIST_HEAD (&cqp->cqp_avail_reqs);INIT_LIST_HEAD (&cqp->cqp_pending_reqs); -/* init the waitqueue of the cqp_requests and add them to the list */ +/* init the completion of the cqp_requests and add them to the list */ for (i =0 ; i < sqsize; i++) { -init_waitqueue_head (&cqp->cqp_requests[i].waitq); +init_completion (&cqp->cqp_requests[i].comp);list_add_tail (&cqp->cqp_requests[i].list, &cqp->cqp_avail_reqs); }init_waitqueue_head (&cqp->remove_wq);
drivers/infiniband/hw/irdma/main.h +1 -2
@@ -161,13 +161,12 @@ struct irdma_cqp_compl_info {struct irdma_cqp_request {struct cqp_cmds_info info; -wait_queue_head_t waitq; +struct completion comp;struct list_head list;refcount_t refcnt;void (*callback_fcn)(struct irdma_cqp_request *cqp_request);void *param;struct irdma_cqp_compl_info compl_info; -bool request_done;/* READ/WRITE_ONCE macros operate on it */ bool waiting:1 ;bool dynamic:1 ;bool pending:1 ;
drivers/infiniband/hw/irdma/utils.c +5 -7
@@ -442,7 +442,7 @@ struct irdma_cqp_request *irdma_alloc_and_get_cqp_request(struct irdma_cqp *cqp,if (cqp_request) { cqp_request->dynamic = true;if (wait) -init_waitqueue_head (&cqp_request->waitq); +init_completion (&cqp_request->comp); } }if (!cqp_request) {
@@ -480,7 +480,7 @@ void irdma_free_cqp_request(struct irdma_cqp *cqp,if (cqp_request->dynamic) {kfree (cqp_request); }else { -WRITE_ONCE (cqp_request->request_done, false); +reinit_completion (&cqp_request->comp); cqp_request->callback_fcn =NULL ; cqp_request->waiting = false; cqp_request->pending = false;
@@ -515,8 +515,7 @@ irdma_free_pending_cqp_request(struct irdma_cqp *cqp, {if (cqp_request->waiting) { cqp_request->compl_info.error = true; -WRITE_ONCE (cqp_request->request_done, true); -wake_up (&cqp_request->waitq); +complete_all (&cqp_request->comp); }wait_event_timeout (cqp->remove_wq,refcount_read (&cqp_request->refcnt) ==1 ,1000 );
@@ -609,9 +608,8 @@ static int irdma_wait_event(struct irdma_pci_f *rf, cqp_timeout.compl_cqp_cmds =atomic64_read (&rf->sc_dev.cqp->completed_ops); do { irdma_cqp_ce_handler(rf, &rf->ccq.sc_cq); - if (wait_event_timeout(cqp_request->waitq, - READ_ONCE(cqp_request->request_done), - msecs_to_jiffies(CQP_COMPL_WAIT_TIME_MS))) + if (wait_for_completion_timeout(&cqp_request->comp, + msecs_to_jiffies(CQP_COMPL_WAIT_TIME_MS))) break; if (cqp_request->pending)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 819/2077 net: serialize netif_running() check in enqueue_to_backlog()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 46762cefe7f4e5bffc1eb467810a7bbb02e461d7 ]
Syzbot reported a KASAN slab-use-after-free in fib_rules_lookup().
The root cause is a race condition where packets can escape the backlog flushing during device unregistration (e.g., during netns exit).
Commit e9e4dd3267d0 ("net: do not process device backlog during unregistration") introduced a lockless netif_running() check in enqueue_to_backlog() to prevent queuing packets to an unregistering device.
However, this creates a TOCTOU race window.
A lockless transmitter (like veth_xmit) can pass
the check before dev_close() clears IFF_UP. If the transmitter is then delayed, flush_all_backlogs() can run and finish before the transmitter grabs the backlog lock and queues the packet. The packet then escapes the flush and triggers UAF later when processed.
Fix this by moving the netif_running() check inside the backlog lock. This serializes the check with the flush work (which also grabs the lock). We then either queue the packet before the flush runs (so it gets flushed), or check netif_running() after the flush/close completes (so it gets dropped).
--- net/core/dev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/core/dev.c +4 -2
@@ -5381,8 +5381,6 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,u32 tail; reason =SKB_DROP_REASON_DEV_READY ; -if (unlikely (!netif_running (skb->dev))) - goto bad_dev; sd = &per_cpu (softnet_data, cpu);
@@ -5394,6 +5392,10 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,backlog_lock_irq_save (sd, &flags); qlen =skb_queue_len (&sd->input_pkt_queue);if (likely (qlen <= max_backlog)) { +if (unlikely (!netif_running (skb->dev))) { +backlog_unlock_irq_restore (sd, flags); + goto bad_dev; + }if (!qlen) {/* Schedule NAPI for backlog device. We can use * non atomic operation as we own the queue lock.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 820/2077 ksmbd: fix use-after-free in same_client_has_lease()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 65b655f65c3ca1ab5d598d3832bb0ff531725858 ]
same_client_has_lease() returns an opinfo pointer from ci->m_op_list after dropping ci->m_lock without taking a reference.
smb_grant_oplock() then dereferences that pointer in copy_lease() and when checking breaking_cnt. A concurrent close can remove the old lease from ci->m_op_list and drop the last reference before the caller uses the returned pointer, leading to a use-after-free.
Take a reference when same_client_has_lease() selects an existing lease, drop any previous match while scanning, and release the returned reference in smb_grant_oplock() after copying the lease state.
--- fs/smb/server/oplock.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/smb/server/oplock.c +6 -0
@@ -528,7 +528,12 @@ static struct oplock_info *same_client_has_lease(struct ksmbd_inode *ci, ret =compare_guid_key (opinfo, client_guid, lctx->lease_key);if (ret) { +if (!atomic_inc_not_zero (&opinfo->refcount)) +continue ; +if (m_opinfo) +opinfo_put (m_opinfo); m_opinfo = opinfo; +/* skip upgrading lease about breaking lease */ if (atomic_read (&opinfo->breaking_cnt))continue ;
@@ -1246,6 +1251,7 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,if (atomic_read (&m_opinfo->breaking_cnt)) opinfo->o_lease->flags =SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE ; +opinfo_put (m_opinfo); goto out; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 821/2077 mfd: bd72720: Drop BUCK11 ID
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matti Vaittinen <[email protected]>
[ Upstream commit 6a2cb13761d90ef3fa960db189a2cc1bdf965ae1 ]
The BD72720 header reserves an ID for BUCK11. While this does not (at the moment) cause problems I can see, it is misleading as the BD72720 contains only 10 BUCKs.
Make the code clearer and drop the BUCK11 ID.
--- include/linux/mfd/rohm-bd72720.h | 1 - 1 file changed, 1 deletion(-)
include/linux/mfd/rohm-bd72720.h +0 -1
@@ -21,7 +21,6 @@ enum {BD72720_BUCK8 ,BD72720_BUCK9 ,BD72720_BUCK10 , -BD72720_BUCK11 ,BD72720_LDO1 ,BD72720_LDO2 , BD72720_LDO3,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 822/2077 mfd: rsmu: Fix page register setup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Bystrin <[email protected]>
[ Upstream commit 6bc38f26ed07197b11a2b588edf1f43bfbc81d76 ]
Fix writes to page register in 8A3400x family (Clock Matrix).
All calls to rsmu_write_page_register() (both in i2c and spi) have resulted in early return, because all addresses in include/linux/mfd/idt8a340_reg.h are less than RSMU_CM_SCSR_BASE.
There were 2 separate patch series which have to be merged in one time:
mfd and ptp. The latter have been merged, the former[1] have not.
--- drivers/mfd/rsmu_i2c.c | 6 +----- drivers/mfd/rsmu_spi.c | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-)
drivers/mfd/rsmu_i2c.c +1 -5
@@ -134,14 +134,10 @@ static int rsmu_i2c_write_device(struct rsmu_ddata *rsmu, u8 reg, u8 *buf, u8 bystatic int rsmu_write_page_register (struct rsmu_ddata *rsmu,u32 reg,rsmu_rw_device rsmu_write_device) { -u32 page = reg &RSMU_CM_PAGE_MASK ; +u32 page = (reg |RSMU_CM_SCSR_BASE ) &RSMU_CM_PAGE_MASK ;u8 buf[4 ];int err; -/* Do not modify offset register for none-scsr registers */ -if (reg <RSMU_CM_SCSR_BASE ) -return 0 ; -/* Simply return if we are on the same page */ if (rsmu->page == page)return 0 ;
drivers/mfd/rsmu_spi.c +1 -4
@@ -101,11 +101,8 @@ static int rsmu_write_page_register(struct rsmu_ddata *rsmu, u32 reg)switch (rsmu->type) {case RSMU_CM : -/* Do not modify page register for none-scsr registers */ -if (reg <RSMU_CM_SCSR_BASE ) -return 0 ; page_reg =RSMU_CM_PAGE_ADDR ; - page = reg &RSMU_PAGE_MASK ; + page = (reg |RSMU_CM_SCSR_BASE ) &RSMU_PAGE_MASK ; buf[0 ] = (u8)(page &0xFF ); buf[1 ] = (u8)((page >>8 ) &0xFF ); buf[2 ] = (u8)((page >>16 ) &0xFF );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 823/2077 mfd: cs42l43: Sanity check firmware size
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Charles Keepax <[email protected]>
[ Upstream commit b6ef1a74b3ec254f87a6a3c554fe8f8083ebd37c ]
Currently the code checks if a firmware was received, however it does not verify that the firmware size is larger than the firmware header. As the firmware pointer is dereferenced as a pointer to the header structure this could lead to an out of bounds memory access. Add the missing check.
--- drivers/mfd/cs42l43.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/cs42l43.c +1 -1
@@ -722,7 +722,7 @@ static void cs42l43_mcu_load_firmware(const struct firmware *firmware, void *conunsigned int loadaddr, val;int ret; -if (!firmware) { +if (!firmware || firmware->size <sizeof (*hdr)) {dev_err (cs42l43->dev,"Failed to load firmware\n" ); cs42l43->firmware_error = -ENODEV ; goto err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 824/2077 ocfs2: fix circular locking dependency in ocfs2_dio_end_io_write
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
[ Upstream commit ff6f26c58421614b02694ac9d219ac61d924bc68 ]
A circular locking dependency involves INODE_ALLOC_SYSTEM_INODE, EXTENT_ALLOC_SYSTEM_INODE, and ORPHAN_DIR_SYSTEM_INODE.
1. ocfs2_mknod() acquires INODE_ALLOC then EXTENT_ALLOC.
2. ocfs2_dio_end_io_write() acquires EXTENT_ALLOC for unwritten extents, then ORPHAN_DIR via ocfs2_del_inode_from_orphan() while still holding EXTENT_ALLOC.
3. ocfs2_wipe_inode() acquires ORPHAN_DIR then INODE_ALLOC via ocfs2_remove_inode.
Break the cycle in ocfs2_dio_end_io_write() by freeing the allocation contexts (releasing EXTENT_ALLOC) before acquiring ORPHAN_DIR.
WARNING: possible circular locking dependency detected
------------------------------------------------------
is trying to acquire lock:ffff8881e78b33a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at:ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
but task is already holding lock:ffff8881e78b4fa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at:ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
the existing dependency chain (in reverse order) is:
-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_del_inode_from_orphan+0x12e/0x7a0 fs/ocfs2/namei.c:2728
ocfs2_dio_end_io+0xf9c/0x1370 fs/ocfs2/aops.c:2418
dio_complete+0x25b/0x790 fs/direct-io.c:281-> #1 (&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_reserve_suballoc_bits+0x16d/0x4840 fs/ocfs2/suballoc.c:882
ocfs2_reserve_new_metadata_blocks+0x415/0x9a0
fs/ocfs2/suballoc.c:1078
ocfs2_mknod+0x10f3/0x2260 fs/ocfs2/namei.c:351-> #0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
Chain exists of:
&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE] -->
&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE] -->
&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]
Possible unsafe locking scenario: CPU0 CPU1
---- ----
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]); lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
*** DEADLOCK ***
--- fs/ocfs2/aops.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/ocfs2/aops.c +9 -4
@@ -2372,6 +2372,15 @@ static int ocfs2_dio_end_io_write(struct inode *inode, unlock:up_write (&oi->ip_alloc_sem); +if (data_ac) { +ocfs2_free_alloc_context (data_ac); + data_ac =NULL ; + } +if (meta_ac) { +ocfs2_free_alloc_context (meta_ac); + meta_ac =NULL ; + } +/* everything looks good, let's start the cleanup */ if (!ret && dwc->dw_orphaned) {BUG_ON (dwc->dw_writer_pid !=task_pid_nr (current));
@@ -2383,10 +2392,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,ocfs2_inode_unlock (inode,1 );brelse (di_bh); out: -if (data_ac) -ocfs2_free_alloc_context (data_ac); -if (meta_ac) -ocfs2_free_alloc_context (meta_ac);ocfs2_run_deallocs (osb, &dealloc);ocfs2_dio_free_write_ctx (inode, dwc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 825/2077 9p: avoid returning ERR_PTR(0) from mkdir operations
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit 314b58c01a9047567fd19446ca5fd46c473b89ff ]
When mkdir succeeds, v9fs_vfs_mkdir_dotl() and v9fs_vfs_mkdir() return ERR_PTR(0) which is incorrect. They should return NULL instead for success and ERR_PTR() only with negative error codes for failure.
Return NULL instead of passing to ERR_PTR while err is zero
Fixes smatch warnings:
fs/9p/vfs_inode_dotl.c:420 v9fs_vfs_mkdir_dotl() warn: passing zero to 'ERR_PTR' fs/9p/vfs_inode.c:695 v9fs_vfs_mkdir() warn: passing zero to 'ERR_PTR'
The v9fs_vfs_mkdir() code was further simplified because v9fs_create() can never return NULL, so we do not need to check for fid being set separately, and the error path can be a simple return immediately after v9fs_create() failure.
There is no intended functional change.
Message-ID: <[email protected]>
--- fs/9p/vfs_inode.c | 19 ++++++------------- fs/9p/vfs_inode_dotl.c | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-)
fs/9p/vfs_inode.c +6 -13
@@ -672,27 +672,20 @@ v9fs_vfs_create(struct mnt_idmap *idmap, struct inode *dir,static struct dentry *v9fs_vfs_mkdir (struct mnt_idmap *idmap,struct inode *dir,struct dentry *dentry,umode_t mode) { -int err;u32 perm;struct p9_fid *fid;struct v9fs_session_info *v9ses;p9_debug (P9_DEBUG_VFS ,"name %pd\n" , dentry); - err =0 ; v9ses =v9fs_inode2v9ses (dir); perm =unixmode2p9mode (v9ses, mode |S_IFDIR ); fid =v9fs_create (v9ses, dir, dentry,NULL , perm,P9_OREAD ); -if (IS_ERR (fid)) { - err =PTR_ERR (fid); - fid =NULL ; - }else { -inc_nlink (dir); -v9fs_invalidate_inode_attr (dir); - } - -if (fid) -p9_fid_put (fid); -return ERR_PTR (err); +if (IS_ERR (fid)) +return ERR_CAST (fid); +inc_nlink (dir); +v9fs_invalidate_inode_attr (dir); +p9_fid_put (fid); +return NULL ; }/**
fs/9p/vfs_inode_dotl.c +2 -2
@@ -349,7 +349,7 @@ static struct dentry *v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t omode) { - int err; + int err = 0;struct v9fs_session_info *v9ses;struct p9_fid *fid =NULL , *dfid =NULL ;kgid_t gid;
@@ -412,7 +412,7 @@ static struct dentry *v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,p9_fid_put (fid);v9fs_put_acl (dacl, pacl);p9_fid_put (dfid); -return ERR_PTR (err); +return err ?ERR_PTR (err) :NULL ; } static int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 826/2077 net/9p: fix race condition on rdma->state in trans_rdma.c
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
[ Upstream commit 7d54894a1ee265a72d70f7cae1da6cc774cccc71 ]
The rdma->state field is modified without holding req_lock in both recv_done() and p9_cm_event_handler(), while rdma_request() accesses the same field under the req_lock spinlock. This inconsistent locking creates a race condition:
- recv_done() running in softirq completion context sets rdma->state = P9_RDMA_FLUSHING without acquiring req_lock
- p9_cm_event_handler() modifies rdma->state at multiple points (ADDR_RESOLVED, ROUTE_RESOLVED, ESTABLISHED, CLOSED) without req_lock
- rdma_request() uses spin_lock_irqsave(&rdma->req_lock, flags) to protect the read-modify-write of rdma->state
The race can cause lost state transitions: recv_done() or the CM event handler could set state to FLUSHING/CLOSED while rdma_request() is concurrently checking or modifying state under the lock, leading to the FLUSHING transition being silently overwritten by CLOSING. This corrupts the connection state machine and can cause use-after-free on RDMA request objects during teardown.
Fix by adding req_lock protection to all rdma->state modifications in recv_done() and p9_cm_event_handler(), matching the pattern already used in rdma_request(). Use spin_lock_irqsave/spin_unlock_irqrestore in the CM event handler since it can race with recv_done() which runs in softirq context.
Tested with a kernel module that races two threads (simulating rdma_request and recv_done/CM handler) on rdma->state with proper
locking: 5.5M+ FLUSHING writes over 27M iterations with 0 lost transitions.
Message-ID: <[email protected]>
--- net/9p/trans_rdma.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
net/9p/trans_rdma.c +17 -2
@@ -128,25 +128,36 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) {struct p9_client *c = id->context;struct p9_trans_rdma *rdma = c->trans; +unsigned long flags; +switch (event->event) {case RDMA_CM_EVENT_ADDR_RESOLVED : +spin_lock_irqsave (&rdma->req_lock, flags);BUG_ON (rdma->state !=P9_RDMA_INIT ); rdma->state =P9_RDMA_ADDR_RESOLVED ; +spin_unlock_irqrestore (&rdma->req_lock, flags);break ;case RDMA_CM_EVENT_ROUTE_RESOLVED : +spin_lock_irqsave (&rdma->req_lock, flags);BUG_ON (rdma->state !=P9_RDMA_ADDR_RESOLVED ); rdma->state =P9_RDMA_ROUTE_RESOLVED ; +spin_unlock_irqrestore (&rdma->req_lock, flags);break ;case RDMA_CM_EVENT_ESTABLISHED : +spin_lock_irqsave (&rdma->req_lock, flags);BUG_ON (rdma->state !=P9_RDMA_ROUTE_RESOLVED ); rdma->state =P9_RDMA_CONNECTED ; +spin_unlock_irqrestore (&rdma->req_lock, flags);break ;case RDMA_CM_EVENT_DISCONNECTED : -if (rdma) +if (rdma) { +spin_lock_irqsave (&rdma->req_lock, flags); rdma->state =P9_RDMA_CLOSED ; +spin_unlock_irqrestore (&rdma->req_lock, flags); + } c->status = Disconnected;break ;
@@ -184,6 +195,7 @@ recv_done(struct ib_cq *cq, struct ib_wc *wc)struct p9_req_t *req;int err =0 ;int16_t tag; +unsigned long flags; req =NULL ; ib_dma_unmap_single(rdma->cm_id->device, c->busa, client->msize,
@@ -220,7 +232,10 @@ recv_done(struct ib_cq *cq, struct ib_wc *wc) err_out:p9_debug (P9_DEBUG_ERROR ,"req %p err %d status %d\n" , req, err, wc->status); - rdma->state =P9_RDMA_FLUSHING ; +spin_lock_irqsave (&rdma->req_lock, flags); +if (rdma->state <P9_RDMA_FLUSHING ) + rdma->state =P9_RDMA_FLUSHING ; +spin_unlock_irqrestore (&rdma->req_lock, flags); client->status = Disconnected; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 827/2077 9p: Add missing read barrier in virtio zero-copy path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gui-Dong Han <[email protected]>
[ Upstream commit aa88278693cbfaf7a2acf961379973fbb63b165c ]
Commit 2b6e72ed747f ("9P: Add memory barriers to protect request fields over cb/rpc threads handoff") added a read barrier after p9_client_rpc() waits for req->status, pairing with the write barrier in p9_client_cb(). The virtio zero-copy wait path was missed.
Add the same read barrier after the zero-copy wait before reading the completed request.
Message-ID: <[email protected]>
--- net/9p/trans_virtio.c | 5 +++++ 1 file changed, 5 insertions(+)
net/9p/trans_virtio.c +5 -0
@@ -532,6 +532,11 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,p9_debug (P9_DEBUG_TRANS ,"virtio request kicked\n" ); err =io_wait_event_killable (req->wq,READ_ONCE (req->status) >=REQ_STATUS_RCVD ); +/* +* Make sure our req is coherent with regard to updates in other +* threads - echoes to wmb() in the callback +*/ +smp_rmb ();// RERROR needs reply (== error string) in static data if (READ_ONCE (req->status) ==REQ_STATUS_RCVD &&unlikely (req->rc.sdata[4 ] ==P9_RERROR ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 828/2077 eventpoll: expand top-of-file overview / locking doc
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 7c25a0bd4bf7139944c5893ff61211f4b5a3455e ]
The existing ~40-line "LOCKING:" banner covered the three-level lock hierarchy (epnested_mutex > ep->mtx > ep->lock) but nothing else. Lifetime rules, the ready-list state machine, the three removal paths, and the POLLFREE contract are implicit in the code. The recent UAF series (a6dc643c6931, 07712db80857, 8c2e52ebbe88, f2e467a48287) rode on invariants that were only implicit.
Codify them at the top of the file: the subsystem overview, the lock hierarchy and its mutex_lock_nested() subclass convention (reworded from the old banner), a field-protection table for struct eventpoll and struct epitem that names the two faces of the rbn/rcu union (rbn under ep->mtx while linked into ep->rbr; rcu touched only by kfree_rcu(epi) on the free path), the ovflist sentinel encoding and scan-flip invariants, the three removal paths (A ep_remove, B ep_clear_and_put, C eventpoll_release_file) and the epi_fget() pin that orchestrates A vs C, and the POLLFREE store-release / load-acquire handshake.
No functional change.
Stable-dep-of: 0c4aefe3c2d0 ("eventpoll: Fix epoll_wait() report false negative")
--- fs/eventpoll.c | 199 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 162 insertions(+), 37 deletions(-)
fs/eventpoll.c +162 -37
@@ -41,45 +41,170 @@#include <net/busy_poll.h> /* -* LOCKING: -* There are three level of locking required by epoll : +* fs/eventpoll.c - Efficient event polling ("epoll") kernel implementation. * -* 1) epnested_mutex (mutex) -* 2) ep->mtx (mutex) -* 3) ep->lock (spinlock) * -* The acquire order is the one listed above, from 1 to 3. -* We need a spinlock (ep->lock) because we manipulate objects -* from inside the poll callback, that might be triggered from -* a wake_up() that in turn might be called from IRQ context. -* So we can't sleep inside the poll callback and hence we need -* a spinlock. During the event transfer loop (from kernel to -* user space) we could end up sleeping due a copy_to_user(), so -* we need a lock that will allow us to sleep. This lock is a -* mutex (ep->mtx). It is acquired during the event transfer loop, -* during epoll_ctl(EPOLL_CTL_DEL) and during eventpoll_release_file(). -* The epnested_mutex is acquired when inserting an epoll fd onto another -* epoll fd. We do this so that we walk the epoll tree and ensure that this -* insertion does not create a cycle of epoll file descriptors, which -* could lead to deadlock. We need a global mutex to prevent two -* simultaneous inserts (A into B and B into A) from racing and -* constructing a cycle without either insert observing that it is -* going to. -* It is necessary to acquire multiple "ep->mtx"es at once in the -* case when one epoll fd is added to another. In this case, we -* always acquire the locks in the order of nesting (i.e. after -* epoll_ctl(e1, EPOLL_CTL_ADD, e2), e1->mtx will always be acquired -* before e2->mtx). Since we disallow cycles of epoll file -* descriptors, this ensures that the mutexes are well-ordered. In -* order to communicate this nesting to lockdep, when walking a tree -* of epoll file descriptors, we use the current recursion depth as -* the lockdep subkey. -* It is possible to drop the "ep->mtx" and to use the global -* mutex "epnested_mutex" (together with "ep->lock") to have it working, -* but having "ep->mtx" will make the interface more scalable. -* Events that require holding "epnested_mutex" are very rare, while for -* normal operations the epoll private "ep->mtx" will guarantee -* a better scalability. +* Overview +* -------- +* +* Each epoll_create(2) returns an anonymous [eventpoll] file whose +* ->private_data is a struct eventpoll. Each EPOLL_CTL_ADD installs +* a struct epitem linking one (watched file, fd) pair back to that +* eventpoll via the watched file's f_op->poll() wait queue(s). When +* the watched file signals readiness, ep_poll_callback() fires and +* marks the epitem ready. epoll_wait(2) drains the ready list under +* ep->mtx, re-queueing items in level-triggered mode. +* +* epoll instances can watch other epoll instances up to EP_MAX_NESTS +* deep; cycles are forbidden and detected at EPOLL_CTL_ADD time. +* +* +* Locking +* ------- +* +* Three levels, acquired from outer to inner: +* +* epnested_mutex (global; rare; taken only for EPOLL_CTL_ADD +* loop / path checks) +* > ep->mtx (per-eventpoll; sleepable; serializes most ops) +* > ep->lock (per-eventpoll; IRQ-safe spinlock) +* +* file->f_lock (per-file; NOT IRQ-safe; guards f_ep hlist ops; +* nested inside ep->mtx, outside ep->lock) +* +* Rationale: +* - ep->lock is a spinlock because ep_poll_callback() is called from +* wake_up() which may run in hard-IRQ context. All ep->lock +* critical sections use spin_lock_irqsave(). +* - ep->mtx is a sleepable mutex because the event delivery loop +* calls copy_to_user(), and ep_insert() may sleep in +* kmem_cache_alloc() and f_op->poll(). +* - epnested_mutex is global because cycle detection needs a global +* view of the epoll topology; a per-object scheme would let two +* concurrent inserts (A into B, B into A) construct a cycle +* without either observer seeing it. +* - Per-ep ep->mtx is preferred for scalability elsewhere. Events +* that require epnested_mutex are rare. +* +* When EPOLL_CTL_ADD nests one eventpoll inside another we acquire +* ep->mtx on both: outer first, target second. Since cycles are +* forbidden the set of live ep->mtx holds is always a strict chain, +* communicated to lockdep via mutex_lock_nested() subclasses derived +* from the current recursion depth. +* +* +* Field protection +* ---------------- +* +* struct eventpoll: +* mtx - self +* rbr - ep->mtx +* ovflist, rdllist - ep->lock (IRQ-safe) +* wq - ep->lock for queue mutation +* poll_wait - internal waitqueue spinlock +* refs - file->f_lock for adds; ep->mtx for removes; +* RCU for readers (hlist_del_rcu + kfree_rcu(ep)) +* ws - ep->mtx +* gen, loop_check_depth - epnested_mutex +* file, user - immutable after setup +* refcount - atomic (refcount_t) +* napi_* - READ_ONCE / WRITE_ONCE +* +* struct epitem: +* rbn / rcu union - rbn: ep->mtx (while epi is linked in ep->rbr). +* rcu: written only by kfree_rcu(epi) on the free +* path; otherwise untouched by epoll code. +* rdllink, next - ep->lock +* ffd, ep - immutable after ep_insert() +* pwqlist - ep->mtx for writes; POLLFREE clears pwq->whead +* via smp_store_release(), see below +* fllink - file->f_lock for mutation; hlist_del_rcu + +* kfree_rcu(epi) for safe RCU readers +* ws - RCU (rcu_assign_pointer / +* rcu_dereference_check(mtx)) +* event - ep->mtx for writes; lockless read in +* ep_poll_callback pairs with smp_mb() in +* ep_modify() +* +* +* Ready-list state machine +* ------------------------ +* +* Readiness is tracked in two lists under ep->lock: +* +* rdllist - doubly-linked FIFO; the "current" ready list. +* ovflist - singly-linked LIFO; used during a scan to catch +* events that arrive while rdllist is being iterated +* without ep->lock. +* +* Encoded in ep->ovflist: +* EP_UNACTIVE_PTR - no scan active; callback appends to rdllist. +* NULL - scan active, no spill yet. +* pointer to epi - scan active with spilled items (LIFO). +* +* Encoded in epi->next: +* EP_UNACTIVE_PTR - epi is not on ovflist. +* otherwise - next epi on ovflist (NULL at tail). +* +* ep_start_scan() flips "not scanning" to "scanning" and splices +* rdllist into a caller-local txlist. ep_done_scan() drains ovflist +* back to rdllist (list_add head-insert reverses LIFO to FIFO), +* flips back to "not scanning", and re-splices any items the caller +* left in txlist (e.g., level-triggered re-queues). +* +* +* Removal paths +* ------------- +* +* Three paths dispose of epitems and/or eventpolls: +* +* A. ep_remove() - EPOLL_CTL_DEL and ep_insert() +* rollback. Caller holds ep->mtx. +* B. ep_clear_and_put() - close of the epoll fd itself +* (ep_eventpoll_release). +* C. eventpoll_release_file() - close of a watched file, invoked +* from __fput(). +* +* Coordination: +* A and C exclude each other via the watched file's refcount. +* A pins the file with epi_fget() before touching file->f_ep or +* file->f_lock; if the pin fails, __fput() is in flight and C +* will clean this epi up. See the epi_fget() block comment. +* A and B both hold ep->mtx serially. B walks the rbtree with +* rb_next() captured before ep_remove() erases the current node. +* B and C both take ep->mtx; the loser sees fewer entries or an +* empty file->f_ep. +* +* Within every path the internal order is strict: +* ep_unregister_pollwait() - drain pwqlist; synchronizes with any +* in-flight ep_poll_callback via the +* watched wait-queue head's lock. +* ep_remove_file() - hlist_del_rcu of epi->fllink and, +* if last watcher, clear file->f_ep, +* under file->f_lock. +* ep_remove_epi() - rb_erase, rdllist unlink (ep->lock), +* wakeup_source_unregister, +* kfree_rcu(epi). +* +* kfree_rcu(epi) defers the free past RCU readers in +* reverse_path_check_proc(); kfree_rcu(ep) defers past readers in +* ep_get_upwards_depth_proc(). +* +* +* POLLFREE handshake +* ------------------ +* +* When a subsystem tears down a wait-queue head that an epitem is +* registered on (binder, signalfd, ...), it wakes the callback with +* POLLFREE and must RCU-defer the head's free. The store/load pair: +* +* ep_poll_callback() POLLFREE branch: +* smp_store_release(&pwq->whead, NULL) +* +* ep_remove_wait_queue(): +* smp_load_acquire(&pwq->whead) +* +* See those sites for the full argument. */ /* Epoll private bits inside the event mask */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 829/2077 eventpoll: rename epi->next and txlist for clarity
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit f38567bb63ae029e3b63fcb99b6a2dcc6f421e69 ]
Two list-related names were confusing in isolation:
struct epitem::next
A singly-linked link slot used only when an epi is queued on ep->ovflist during an ep_start_scan/ep_done_scan window. The bare name "next" suggests a generic list link and doesn't say which list it belongs to.
txlist
The caller-local list_head used by ep_send_events() and __ep_eventpoll_poll() to hold the batch of items stolen from ep->rdllist for the current scan. "txlist" ("transmission list") is abbreviated and overloaded: it doesn't distinguish itself from ep->rdllist or ep->ovflist at a glance.
Rename for what each actually is:
struct epitem::next -> struct epitem::ovflist_next
local txlist -> scan_batch
With these in place:
- epi->ovflist_next reads as "this is the ep->ovflist link slot", matching the rdllink pattern above it.
- scan_batch reads as "the batch currently being scanned", clearly distinct from rdllist (canonical ready list) and ovflist (scan-window overflow).
ep->rdllist and ep->ovflist struct field names are preserved -- they are long-standing interface-facing identifiers, and the new inline helpers (ep_is_scanning, epi_on_ovflist, ...) already hide the sentinel semantics at call sites.
No functional change.
Stable-dep-of: 0c4aefe3c2d0 ("eventpoll: Fix epoll_wait() report false negative")
--- fs/eventpoll.c | 62 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 30 deletions(-)
fs/eventpoll.c +32 -30
@@ -142,15 +142,15 @@* NULL - scan active, no spill yet. * pointer to epi - scan active with spilled items (LIFO). * -* Encoded in epi->next: +* Encoded in epi->ovflist_next: * EP_UNACTIVE_PTR - epi is not on ovflist. * otherwise - next epi on ovflist (NULL at tail). * * ep_start_scan() flips "not scanning" to "scanning" and splices -* rdllist into a caller-local txlist. ep_done_scan() drains ovflist +* rdllist into a caller-local scan_batch. ep_done_scan() drains ovflist * back to rdllist (list_add head-insert reverses LIFO to FIFO), * flips back to "not scanning", and re-splices any items the caller -* left in txlist (e.g., level-triggered re-queues). +* left in scan_batch (e.g., level-triggered re-queues). * * * Removal paths
@@ -261,14 +261,16 @@ struct epitem {struct rcu_head rcu; }; -/* List header used to link this structure to the eventpoll ready list */ +/* Link on the owning eventpoll's ready list (ep->rdllist). */ struct list_head rdllink;/* -* Works together "struct eventpoll"->ovflist in keeping the -* single linked chain of items. +* Link on the owning eventpoll's scan-overflow list (ep->ovflist), +* EP_UNACTIVE_PTR when not linked. See epi_on_ovflist() / +* epi_clear_ovflist() and the "Ready-list state machine" section +* in the top-of-file banner. */ -struct epitem *next; +struct epitem *ovflist_next;/* The file descriptor information this item refers to */ struct epoll_filefd ffd;
@@ -525,13 +527,13 @@ static inline void ep_exit_scan(struct eventpoll *ep)/* True iff @epi is currently linked on its ep's ovflist. */ static inline bool epi_on_ovflist (const struct epitem *epi) { -return epi->next !=EP_UNACTIVE_PTR ; +return epi->ovflist_next !=EP_UNACTIVE_PTR ; }/* Mark @epi as not on any ovflist (init and post-drain). */ static inline void epi_clear_ovflist (struct epitem *epi) { - epi->next =EP_UNACTIVE_PTR ; + epi->ovflist_next =EP_UNACTIVE_PTR ; }/**
@@ -884,7 +886,7 @@ static inline void ep_pm_stay_awake_rcu(struct epitem *epi)* ep->mutex needs to be held because we could be hit by * eventpoll_release_file() and epoll_ctl(). */ -static void ep_start_scan (struct eventpoll *ep,struct list_head *txlist) +static void ep_start_scan (struct eventpoll *ep,struct list_head *scan_batch) {/* * Steal the ready list, and re-init the original one to the
@@ -896,13 +898,13 @@ static void ep_start_scan(struct eventpoll *ep, struct list_head *txlist)*/ lockdep_assert_irqs_enabled ();spin_lock_irq (&ep->lock); -list_splice_init (&ep->rdllist, txlist); +list_splice_init (&ep->rdllist, scan_batch);ep_enter_scan (ep);spin_unlock_irq (&ep->lock); }static void ep_done_scan (struct eventpoll *ep, -struct list_head *txlist) +struct list_head *scan_batch) {struct epitem *epi, *nepi;
@@ -913,10 +915,10 @@ static void ep_done_scan(struct eventpoll *ep,* We re-insert them inside the main ready-list here. */ for (nepi =READ_ONCE (ep->ovflist); (epi = nepi) !=NULL ; ) { - nepi = epi->next; + nepi = epi->ovflist_next;epi_clear_ovflist (epi);/* -* Skip items that the caller already returned via @txlist +* Skip items that the caller already returned via @scan_batch * -- the list_splice() below takes care of those. */ if (!ep_is_linked (epi)) {
@@ -932,9 +934,9 @@ static void ep_done_scan(struct eventpoll *ep,ep_exit_scan (ep);/* -* Quickly re-inject items left on "txlist". +* Quickly re-inject items left on "scan_batch". */ -list_splice (txlist, &ep->rdllist); +list_splice (scan_batch, &ep->rdllist);__pm_relax (ep->ws);if (!list_empty (&ep->rdllist)) {
@@ -1155,7 +1157,7 @@ static __poll_t ep_item_poll(const struct epitem *epi, poll_table *pt, int depthstatic __poll_t __ep_eventpoll_poll (struct file *file,poll_table *wait,int depth) {struct eventpoll *ep = file->private_data; -LIST_HEAD (txlist); +LIST_HEAD (scan_batch);struct epitem *epi, *tmp;poll_table pt;__poll_t res =0 ;
@@ -1170,8 +1172,8 @@ static __poll_t __ep_eventpoll_poll(struct file *file, poll_table *wait, int dep* the ready list. */ mutex_lock_nested (&ep->mtx, depth); -ep_start_scan (ep, &txlist); -list_for_each_entry_safe (epi, tmp, &txlist, rdllink) { +ep_start_scan (ep, &scan_batch); +list_for_each_entry_safe (epi, tmp, &scan_batch, rdllink) {if (ep_item_poll (epi, &pt, depth +1 )) { res =EPOLLIN |EPOLLRDNORM ;break ;
@@ -1185,7 +1187,7 @@ static __poll_t __ep_eventpoll_poll(struct file *file, poll_table *wait, int deplist_del_init (&epi->rdllink); } } -ep_done_scan (ep, &txlist); +ep_done_scan (ep, &scan_batch);mutex_unlock (&ep->mtx);return res; }
@@ -1441,7 +1443,7 @@ static int ep_poll_callback(wait_queue_entry_t *wait, unsigned mode, int sync, v*/ if (ep_is_scanning (ep)) {if (!epi_on_ovflist (epi)) { - epi->next =READ_ONCE (ep->ovflist); + epi->ovflist_next =READ_ONCE (ep->ovflist);WRITE_ONCE (ep->ovflist, epi);ep_pm_stay_awake_rcu (epi); }
@@ -1962,7 +1964,7 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi,* next slot), 0 if the re-poll reported no caller-requested events * (@epi drops out of the ready list; a future callback will re-add * it), or -EFAULT if copy_to_user() faulted (in which case @epi is -* re-inserted at the head of @txlist so ep_done_scan() merges it +* re-inserted at the head of @scan_batch so ep_done_scan() merges it * back to rdllist for the next attempt). * * PM bookkeeping and level-triggered re-queue are handled here.
@@ -1971,7 +1973,7 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi,static int ep_deliver_event (struct eventpoll *ep,struct epitem *epi,poll_table *pt,struct epoll_event __user **uevents, -struct list_head *txlist) +struct list_head *scan_batch) {struct epoll_event __user *next;struct wakeup_source *ws;
@@ -2009,7 +2011,7 @@ static int ep_deliver_event(struct eventpoll *ep, struct epitem *epi,* ep_done_scan() splices it onto rdllist for the next * attempt. */ -list_add (&epi->rdllink, txlist); +list_add (&epi->rdllink, scan_batch);ep_pm_stay_awake (epi);return -EFAULT ; }
@@ -2035,7 +2037,7 @@ static int ep_send_events(struct eventpoll *ep, struct epoll_event __user *events, int maxevents) {struct epitem *epi, *tmp; -LIST_HEAD (txlist); +LIST_HEAD (scan_batch);poll_table pt;int res =0 ;
@@ -2050,19 +2052,19 @@ static int ep_send_events(struct eventpoll *ep,init_poll_funcptr (&pt,NULL );mutex_lock (&ep->mtx); -ep_start_scan (ep, &txlist); +ep_start_scan (ep, &scan_batch);/* * We can loop without lock because we are passed a task-private -* txlist; items cannot vanish while we hold ep->mtx. +* scan_batch; items cannot vanish while we hold ep->mtx. */ -list_for_each_entry_safe (epi, tmp, &txlist, rdllink) { +list_for_each_entry_safe (epi, tmp, &scan_batch, rdllink) {int delivered;if (res >= maxevents)break ; - delivered =ep_deliver_event (ep, epi, &pt, &events, &txlist); + delivered =ep_deliver_event (ep, epi, &pt, &events, &scan_batch);if (delivered <0 ) {if (!res) res = delivered;
@@ -2071,7 +2073,7 @@ static int ep_send_events(struct eventpoll *ep, res += delivered; } -ep_done_scan (ep, &txlist); +ep_done_scan (ep, &scan_batch);mutex_unlock (&ep->mtx);return res;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 830/2077 eventpoll: Fix epoll_wait() report false negative
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nam Cao <[email protected]>
[ Upstream commit 0c4aefe3c2d0f272a2ad73699a12d4446ffdbe7b ]
ep_events_available() checks for available events by looking at ep->rdllist and ep_is_scanning(). However, this is done without a lock and can report false negative if ep_start_scan() or ep_done_scan() are executed by another task concurrently. For example:
_________________________________________________________________________
|ep_start_scan()
| list_splice_init(&ep->rdllist, ...)
ep_events_available() |
!list_empty_careful(&ep->rdllist)|
|| ep_is_scanning(ep) | | ep_enter_scan(ep)
___________________________________|_____________________________________
Another example:
_________________________________________________________________________
ep_events_available() |
|ep_start_scan()
| list_splice_init(&ep->rdllist, ...)
| ep_enter_scan(ep)
!list_empty_careful(&ep->rdllist)|
|ep_done_scan()
| ep_exit_scan(ep)
| list_splice(..., &ep->rdllist)
|| ep_is_scanning(ep) |
___________________________________|_____________________________________In the above examples, ep_events_available() sees no event despite events being available. In case epoll_wait() is called with timeout=0, epoll_wait() will wrongly return "no event" to user.
Introduce a sequence lock to resolve this issue.
Measuring the time consumption of 10 million loop iterations doing epoll_wait(), the following performance drop is observed:
timeout #event before after diff
0ms 0 3727ms 3974ms +6.6%
0ms 1 8099ms 9134ms +13%
1ms 1 13525ms 13586ms +0.45%Considering the use case of epoll_wait() (wait for events, do something with the events, repeat), it should only contribute to a small portion of user's CPU consumption. Therefore this performance drop is not alarming.
--- fs/eventpoll.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
fs/eventpoll.c +19 -1
@@ -38,6 +38,7 @@#include <linux/compat.h> #include <linux/rculist.h> #include <linux/capability.h> +#include <linux/seqlock.h> #include <net/busy_poll.h> /*
@@ -317,6 +318,9 @@ struct eventpoll {/* Lock which protects rdllist and ovflist */ spinlock_t lock; +/* Protect switching between rdllist and ovflist */ +seqcount_spinlock_t seq; +/* RB tree root used to store monitored fd structs */ struct rb_root_cached rbr;
@@ -546,7 +550,10 @@ static inline void epi_clear_ovflist(struct epitem *epi)*/ static inline int ep_events_available (struct eventpoll *ep) { -return !list_empty_careful (&ep->rdllist) ||ep_is_scanning (ep); +unsigned int seq =read_seqcount_begin (&ep->seq); + +return !list_empty_careful (&ep->rdllist) ||ep_is_scanning (ep) || +read_seqcount_retry (&ep->seq, seq); }#ifdef CONFIG_NET_RX_BUSY_POLL
@@ -898,8 +905,12 @@ static void ep_start_scan(struct eventpoll *ep, struct list_head *scan_batch)*/ lockdep_assert_irqs_enabled ();spin_lock_irq (&ep->lock); +write_seqcount_begin (&ep->seq); +list_splice_init (&ep->rdllist, scan_batch);ep_enter_scan (ep); + +write_seqcount_end (&ep->seq);spin_unlock_irq (&ep->lock); }
@@ -930,6 +941,9 @@ static void ep_done_scan(struct eventpoll *ep,ep_pm_stay_awake (epi); } } + +write_seqcount_begin (&ep->seq); +/* Back out of scan mode; callbacks target ep->rdllist again. */ ep_exit_scan (ep);
@@ -937,6 +951,9 @@ static void ep_done_scan(struct eventpoll *ep,* Quickly re-inject items left on "scan_batch". */ list_splice (scan_batch, &ep->rdllist); + +write_seqcount_end (&ep->seq); +__pm_relax (ep->ws);if (!list_empty (&ep->rdllist)) {
@@ -1313,6 +1330,7 @@ static int ep_alloc(struct eventpoll **pep)mutex_init (&ep->mtx);spin_lock_init (&ep->lock); +seqcount_spinlock_init (&ep->seq, &ep->lock);init_waitqueue_head (&ep->wq);init_waitqueue_head (&ep->poll_wait);INIT_LIST_HEAD (&ep->rdllist);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 831/2077 gpiolib: acpi: Only trigger ActiveBoth interrupts on boot
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 3bb62e3f99a557d257e5f5a803200051b7de3afa ]
Commit ca876c7483b6 ("gpiolib-acpi: make sure we trigger edge events at least once on boot") introduced logic to trigger edge-based GPIO interrupts during initialization to ensure proper initial state setup when firmware doesn't initialize it.
However, according to the Microsoft GPIO documentation, triggering GPIO interrupts during initialization should only happen for interrupts marked as ActiveBoth (both IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING) and only when the associated GPIO line is already asserted (logic level low).
The current implementation incorrectly triggers:
1. Any edge-triggered interrupt (RISING-only or FALLING-only)
2. RISING interrupts when value is high and FALLING when value is low
This causes problems at bootup for single-edge interrupts that don't follow the ActiveBoth pattern.
Fix this by:
- Only triggering when BOTH rising and falling edges are configured
- Only triggering when the GPIO line is asserted (value == 0)
--- drivers/gpio/gpiolib-acpi-core.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib-acpi-core.c +15 -4
@@ -233,12 +233,23 @@ static void acpi_gpiochip_request_irq(struct acpi_gpio_chip *acpi_gpio, event->irq_requested = true; -/* Make sure we trigger the initial state of edge-triggered IRQs */ +/* +* Make sure we trigger the initial state of ActiveBoth IRQs. +* +* According to the Microsoft GPIO documentation, triggering GPIO +* interrupts marked as ActiveBoth during initialization is correct +* as long as the associated GPIO line is already "asserted" +* (logic level low). We should not trigger edge-based GPIO +* interrupts not marked as ActiveBoth. +* +* See: https://learn.microsoft.com/en-us/windows-hardware/drivers/bringup/general-purpose-i-o--gpio- +* Section: "GPIO controllers and ActiveBoth interrupts" +*/ if (acpi_gpio_need_run_edge_events_on_boot () && - (event->irqflags & (IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING ))) { + ((event->irqflags & (IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING )) == + (IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING ))) { value =gpiod_get_raw_value_cansleep (event->desc); -if (((event->irqflags &IRQF_TRIGGER_RISING ) && value ==1 ) || - ((event->irqflags &IRQF_TRIGGER_FALLING ) && value ==0 )) +if (value ==0 ) event->handler (event->irq, event); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 832/2077 i3c: master: svc: Fix missed IBI after false SLVSTART on NPCM845
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Chu <[email protected]>
[ Upstream commit fa1d4fa118f4229168e9ca88cea260c5e5a94652 ]
The NPCM845 I3C controller may raise a false SLVSTART interrupt. The handler first latches MSTATUS and then clears SLVSTART. If a real IBI request arrives after the handler latches MSTATUS but before it clears the SLVSTART interrupt status, HW sets the SLVREQ state. However, the handler still relies on the stale MSTATUS snapshot, returns early, and misses the real IBI. No further interrupt is generated for this pending IBI.
Re-read MSTATUS to obtain the latest state and avoid missing a real IBI due to this race condition.
--- drivers/i3c/master/svc-i3c-master.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/i3c/master/svc-i3c-master.c +12 -4
@@ -672,10 +672,18 @@ static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)/* Clear the interrupt status */ writel (SVC_I3C_MINT_SLVSTART , master->regs +SVC_I3C_MSTATUS ); -/* Ignore the false event */ -if (svc_has_quirk (master,SVC_I3C_QUIRK_FALSE_SLVSTART ) && - !SVC_I3C_MSTATUS_STATE_SLVREQ (active)) -return IRQ_HANDLED ; +if (svc_has_quirk (master,SVC_I3C_QUIRK_FALSE_SLVSTART )) { +/* +* Re-read MSTATUS to obtain the latest state and avoid +* missing an IBI that arrives after MSTATUS is latched +* but before SLVSTART is cleared. +*/ + active =readl (master->regs +SVC_I3C_MSTATUS ); + +/* Ignore the false event */ +if (!SVC_I3C_MSTATUS_STATE_SLVREQ (active)) +return IRQ_HANDLED ; + }/* * The SDA line remains low until the request is processed.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 833/2077 staging: rtl8723bs: fix stainfo check in rtw_aes_decrypt
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maksym Pikhotskyi <[email protected]>
[ Upstream commit 9a3f9b3c47d8f071b0eb9e63906ac0448058278d ]
The null-pointer-guard was incorrect, returning _FAIL on valid pointer. Invert the guard, so it returns _FAIL on invalid pointer.
--- drivers/staging/rtl8723bs/core/rtw_security.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
@@ -1212,7 +1212,7 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)if (prxattrib->encrypt != _AES_)return _SUCCESS; stainfo =rtw_get_stainfo (&padapter->stapriv, &prxattrib->ta[0 ]); -if (stainfo) +if (!stainfo)return _FAIL;if (is_multicast_ether_addr (prxattrib->ra)) {static unsigned long start;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 834/2077 staging: nvec: fix use-after-free in nvec_rx_completed()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandru Hossu <[email protected]>
[ Upstream commit 26813881181deb3a32fbb59eadb2599cbe8423f6 ]
In nvec_rx_completed(), when an incomplete RX transfer is detected, nvec_msg_free() is called to return the message back to the pool by clearing its 'used' atomic flag. Immediately after this, the code accesses nvec->rx->data[0] to check the message type.
Since nvec_msg_free() marks the pool slot as available via atomic_set(), any concurrent or subsequent call to nvec_msg_alloc() could claim that same slot and overwrite its data[] array. Reading nvec->rx->data[0] after freeing the message is therefore a use-after-free.
Fix this by saving the message type byte before calling nvec_msg_free(), then using the saved value for the battery quirk check.
--- drivers/staging/nvec/nvec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/nvec/nvec.c +3 -1
@@ -494,6 +494,8 @@ static void nvec_tx_completed(struct nvec_chip *nvec)static void nvec_rx_completed (struct nvec_chip *nvec) {if (nvec->rx->pos !=nvec_msg_size (nvec->rx)) { +unsigned char msg_type = nvec->rx->data[0 ]; +dev_err (nvec->dev,"RX incomplete: Expected %u bytes, got %u\n" , (uint )nvec_msg_size (nvec->rx), (uint )nvec->rx->pos);
@@ -502,7 +504,7 @@ static void nvec_rx_completed(struct nvec_chip *nvec) nvec->state =0 ;/* Battery quirk - Often incomplete, and likes to crash */ -if (nvec->rx->data[0 ] ==NVEC_BAT ) +if (msg_type ==NVEC_BAT )complete (&nvec->ec_transfer);return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 835/2077 perf dwarf-aux: Fix libdw segmentation fault in cu_walk_functions_at
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit d37a5467709e627370124d7346ef71ce605ababa ]
A segmentation fault was observed in libdw when running perf kmem with --page stat on some workloads. The crash occurred deep inside libdw (specifically in dwarf_child and dwarf_diename) when processing DWARF information.
The root cause was improper error handling of dwarf_getfuncs in die_find_realfunc and die_find_tailfunc.
dwarf_getfuncs returns:
- 0 on success (when all functions have been processed).
- A positive offset if the callback aborts early (e.g., via DWARF_CB_ABORT when a match is found).
- -1 on error.
The original code used if (!dwarf_getfuncs(...)) return NULL;. On error (-1), !-1 evaluates to 0 (false), bypassing the error check. Execution then proceeded as if a match was found, returning uninitialized stack memory (die_mem) to the caller (cu_walk_functions_at). When cu_walk_functions_at passed this uninitialized memory to libdw via dwarf_diename, it caused a segmentation fault.
Fix this by correcting the error check to if (dwarf_getfuncs(...) <= 0).
--- tools/perf/util/dwarf-aux.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/dwarf-aux.c +2 -3
@@ -171,7 +171,6 @@ int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr, }return ret; - }/**
@@ -620,7 +619,7 @@ Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, ad.addr = addr; ad.die_mem = die_mem;/* dwarf_getscopes can't find subprogram. */ -if (!dwarf_getfuncs (cu_die, __die_search_func_tail_cb, &ad,0 )) +if (dwarf_getfuncs (cu_die, __die_search_func_tail_cb, &ad,0 ) <=0 )return NULL ;else return die_mem;
@@ -659,7 +658,7 @@ Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, ad.addr = addr; ad.die_mem = die_mem;/* dwarf_getscopes can't find subprogram. */ -if (!dwarf_getfuncs (cu_die, __die_search_func_cb, &ad,0 )) +if (dwarf_getfuncs (cu_die, __die_search_func_cb, &ad,0 ) <=0 )return NULL ;else return die_mem;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 836/2077 perf dwarf-aux: Fix libdw API contract violations
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 17e9b4243e76f0a0fe951d30ce990d6081a8b426 ]
Check return values of dwarf_decl_line (where non-optional), dwarf_getfuncs, and dwarf_lineaddr to prevent using uninitialized stack variables or incorrectly reporting success on failure.
For the root DIE in die_walk_lines(), dwarf_decl_line and die_get_decl_file are optional and their failures are handled gracefully to avoid breaking line walking on valid functions. Specifically, remove the strict !decf (declared file) check that would prematurely abort line walking on generated or artificial functions lacking this optional attribute.
Additionally:
- Add NULL pointer protection for strcmp() in die_walk_lines() when inf or decf are NULL to prevent crashes on generated code.
- Use dwarf_attr_integrate in die_get_data_member_location to correctly resolve inherited member locations (e.g. via abstract origin or specification).
--- tools/perf/util/dwarf-aux.c | 34 +++++++++++++++++----------------- tools/perf/util/dwarf-aux.h | 5 +++++ 2 files changed, 22 insertions(+), 17 deletions(-)
tools/perf/util/dwarf-aux.c +17 -17
@@ -125,7 +125,8 @@ int cu_find_lineinfo(Dwarf_Die *cu_die, Dwarf_Addr addr, &&die_entrypc (&die_mem, &faddr) ==0 && faddr == addr) { *fname =die_get_decl_file (&die_mem); -dwarf_decl_line (&die_mem, lineno); +if (dwarf_decl_line (&die_mem, lineno) !=0 ) +return -ENOENT ; goto out; }
@@ -459,7 +460,7 @@ int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)size_t nexpr;int ret; -if (dwarf_attr (mb_die, DW_AT_data_member_location, &attr) ==NULL ) +if (dwarf_attr_integrate (mb_die, DW_AT_data_member_location, &attr) ==NULL )return -ENOENT ;if (dwarf_formudata (&attr, offs) !=0 ) {
@@ -795,8 +796,7 @@ static int __die_walk_instances_cb(Dwarf_Die *inst, void *data)/* Ignore redundant instances */ if (dwarf_tag (inst) == DW_TAG_inlined_subroutine) { -dwarf_decl_line (origin, &tmp); -if (die_get_call_lineno (inst) == tmp) { +if (dwarf_decl_line (origin, &tmp) ==0 &&die_get_call_lineno (inst) == tmp) { tmp =die_get_decl_fileno (origin);if (die_get_call_fileno (inst) == tmp)return DIE_FIND_CB_CONTINUE ;
@@ -950,11 +950,6 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data) cu_die =dwarf_diecu (rt_die, &die_mem,NULL ,NULL );dwarf_decl_line (rt_die, &decl); decf =die_get_decl_file (rt_die); -if (!decf) { -pr_debug2 ("Failed to get the declared file name of %s\n" , -dwarf_diename (rt_die)); -return -EINVAL ; - } }else cu_die = rt_die;if (!cu_die) {
@@ -998,11 +993,12 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data)if (die_find_inlinefunc (rt_die, addr, &die_mem)) {/* Call-site check */ inf =die_get_call_file (&die_mem); -if ((inf && !strcmp (inf, decf)) && +if ((inf == decf || (inf && decf && !strcmp (inf, decf))) &&die_get_call_lineno (&die_mem) == lineno) goto found; -dwarf_decl_line (&die_mem, &inl); +if (dwarf_decl_line (&die_mem, &inl) !=0 ) + inl =0 ;if (inl != decl || decf !=die_get_decl_file (&die_mem))continue ;
@@ -1034,8 +1030,10 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data) .data = data, .retval = 0, }; -dwarf_getfuncs (cu_die, __die_walk_culines_cb, ¶m,0 ); - ret = param.retval; +if (dwarf_getfuncs (cu_die, __die_walk_culines_cb, ¶m,0 ) <0 ) + ret = -EINVAL ; +else + ret = param.retval; }return ret;
@@ -1939,10 +1937,12 @@ static bool die_get_postprologue_addr(unsigned long entrypc_idx,break ; } -dwarf_lineaddr (line, postprologue_addr); -if (*postprologue_addr >= highpc) -dwarf_lineaddr (dwarf_onesrcline (lines, i -1 ), - postprologue_addr); +if (dwarf_lineaddr (line, postprologue_addr) !=0 ) +return false; +if (*postprologue_addr >= highpc) { +if (dwarf_lineaddr (dwarf_onesrcline (lines, i -1 ), postprologue_addr) !=0 ) +return false; + }return true; }
tools/perf/util/dwarf-aux.h +5 -0
@@ -10,6 +10,11 @@#include <elfutils/libdwfl.h> #include <elfutils/version.h> +static inline const char *die_name (Dwarf_Die *die) +{ +return dwarf_diename (die) ?:"<unknown>" ; +} +struct strbuf ;/* Find the realpath of the target file */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 837/2077 perf libdw: Fix libdw API contract violations and memory leaks
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 9c6d535ddb794fb540c3b142ab1d7416d469c1de ]
Check return values of dwfl_report_end and dwfl_module_addrdie to prevent using uninitialized stack variables or reporting success on failure.
Additionally:
- Ensure *file is freed and inline frames are cleared on error in libdw__addr2line() to prevent memory leaks and duplicated callchains when falling back to other unwinders.
- Use die_name() safe wrapper inside the inline function unwinding callback (libdw_a2l_cb).
- Refactor libdw_a2l_cb's repeated memory error handling/cleanup paths using a cleaner goto control flow.
--- tools/perf/util/libdw.c | 49 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-)
tools/perf/util/libdw.c +43 -6
@@ -60,7 +60,10 @@ struct Dwfl *dso__libdw_dwfl(struct dso *dso)return NULL ; } -dwfl_report_end (dwfl,/*removed=*/ NULL ,/*arg=*/ NULL ); +if (dwfl_report_end (dwfl,/*removed=*/ NULL ,/*arg=*/ NULL ) !=0 ) { +dwfl_end (dwfl); +return NULL ; + }dso__set_libdw (dso, dwfl);return dwfl;
@@ -72,18 +75,19 @@ struct libdw_a2l_cb_args {struct inline_node *node;char *leaf_srcline;bool leaf_srcline_used; +int err; };static int libdw_a2l_cb (Dwarf_Die *die,void *_args) {struct libdw_a2l_cb_args *args = _args; -struct symbol *inline_sym =new_inline_sym (args->dso, args->sym,dwarf_diename (die)); +struct symbol *inline_sym =new_inline_sym (args->dso, args->sym,die_name (die));const char *call_fname =die_get_call_file (die);char *call_srcline = srcline__unknown;struct inline_list *ilist;if (!inline_sym) -return -ENOMEM ; + goto abort_enomem;/* Assign caller information to the parent. */ if (call_fname)
@@ -103,12 +107,27 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args)/* Add this symbol to the chain as the leaf. */ if (!args->leaf_srcline_used) { -inline_list__append_tail (inline_sym, args->leaf_srcline, args->node); +if (inline_list__append_tail (inline_sym, args->leaf_srcline, args->node) !=0 ) + goto abort_delete_sym; args->leaf_srcline_used = true; }else { -inline_list__append_tail (inline_sym,strdup (args->leaf_srcline), args->node); +char *srcline =strdup (args->leaf_srcline); + +if (!srcline) + goto abort_delete_sym; +if (inline_list__append_tail (inline_sym, srcline, args->node) !=0 ) { +free (srcline); + goto abort_delete_sym; + } }return 0 ; + +abort_delete_sym: +if (inline_sym->inlined) +symbol__delete (inline_sym); +abort_enomem: + args->err = -ENOMEM ; +return DWARF_CB_ABORT ; } int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr,
@@ -162,11 +181,29 @@ int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr, .leaf_srcline = srcline_from_fileline(src ?: "<unknown>", lineno), }; +if (!args.leaf_srcline) { +if (file && *file) { +free (*file); + *file =NULL ; + } +return 0 ; + } +/* Walk from the parent down to the leaf. */ -cu_walk_functions_at (cudie, addr, libdw_a2l_cb, &args); +if (cudie) +cu_walk_functions_at (cudie, addr, libdw_a2l_cb, &args);if (!args.leaf_srcline_used)free (args.leaf_srcline); + +if (args.err) { +if (file && *file) { +free (*file); + *file =NULL ; + } +inline_node__clear_frames (node); +return 0 ; + } }return 1 ; }
Signature · 1 line
2.53.0
Re: [PATCH 7.1 0837/2077] perf libdw: Fix libdw API contract violations and memory leaks
Quoted 25 lines · Greg Kroah-Hartman
7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit
9c6d535ddb794fb540c3b142ab1d7416d469c1de]tools/perf/util/libdw.c +10
-1@@ -162,11 +181,29 @@ int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr, .leaf_srcline = srcline_from_fileline(src ?: "<unknown>", lineno), }; +if (!args.leaf_srcline) { +if (file && *file) { +free (*file); + *file =NULL ; + } +return 0 ; + } +/* Walk from the parent down to the leaf. */ -cu_walk_functions_at (cudie, addr, libdw_a2l_cb, &args); +if (cudie) +cu_walk_functions_at (cudie, addr, libdw_a2l_cb, &args);
tools/perf/util/libdw.c int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr, · line 204
Quoted 10 lines
tools/perf/util/libdw.c +7
-0if (!args.leaf_srcline_used)free (args.leaf_srcline); + +if (args.err) { +if (file && *file) { +free (*file); + *file =NULL ; + } +inline_node__clear_frames (node);
This one needs:674dea094ef6 perf srcline: Introduce inline_node__clear_frames()
Signature · 2 lines
js suse labs
Greg Kroah-Hartman
maintainerRe: [PATCH 7.1 0837/2077] perf libdw: Fix libdw API contract violations and memory leaks
Quoted 29 lines · Jiri Slaby
Quoted 28 lines · Greg Kroah-Hartman
7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit
9c6d535ddb794fb540c3b142ab1d7416d469c1de]tools/perf/util/libdw.c +12
-1@@ -162,11 +181,29 @@ int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr, .leaf_srcline = srcline_from_fileline(src ?: "<unknown>", lineno), }; +if (!args.leaf_srcline) { +if (file && *file) { +free (*file); + *file =NULL ; + } +return 0 ; + } +/* Walk from the parent down to the leaf. */ -cu_walk_functions_at (cudie, addr, libdw_a2l_cb, &args); +if (cudie) +cu_walk_functions_at (cudie, addr, libdw_a2l_cb, &args);if (!args.leaf_srcline_used)free (args.leaf_srcline); + +if (args.err) {
Quoted 8 lines
tools/perf/util/libdw.c int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr, · line 204
Quoted 5 lines
tools/perf/util/libdw.c +5
-0+if (file && *file) { +free (*file); + *file =NULL ; + } +inline_node__clear_frames (node);This one needs:
674dea094ef6perf srcline: Introduceinline_node__clear_frames()
Now fixed up, thanks.
greg k-h
Greg Kroah-Hartman
maintainerPATCH 838/2077 perf probe-finder: Fix libdw API contract violations
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 9a2ef19b5f5218d35c161f272a901f6c070faf79 ]
Check return values of dwarf_formsdata, dwarf_entrypc, dwarf_highpc, dwarf_bytesize, dwarf_attr, dwarf_decl_line, dwarf_getfuncs, and dwarf_formref_die. Validate dwarf_diename and dwarf_diecu results to prevent potential crashes. Fix C90 mixed declarations.
Additionally:
- Avoid vfprintf undefined behavior with NULL strings by using the die_name() helper for dwarf_diename() in pr_* calls, including when warning about tail calls.
- Prevent NULL pointer dereference in convert_variable_fields() when processing array elements for variables in registers.
- Fallback to offset 0 in line_range_search_cb() instead of skipping functions without DW_AT_decl_line.
- Relax dwarf_getfuncs error checking in find_probe_point_by_func() and find_line_range_by_func() to prevent premature CU search aborts, ensuring robustness against corrupted CUs.
--- tools/perf/util/probe-finder.c | 102 +++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 37 deletions(-)
tools/perf/util/probe-finder.c +65 -37
@@ -79,7 +79,7 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,unsigned int regn;Dwarf_Word offs =0 ;bool ref = false; -const char *regs; +const char *regs, *name;int ret, ret2 =0 ;if (dwarf_attr (vr_die, DW_AT_external, &attr) !=NULL )
@@ -93,7 +93,8 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,if (!tvar)return 0 ; -dwarf_formsdata (&attr, &snum); +if (dwarf_formsdata (&attr, &snum) !=0 ) +return -ENOENT ; ret =asprintf (&tvar->value,"\\%ld" , (long )snum);return ret <0 ? -ENOMEM :0 ;
@@ -103,8 +104,7 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,if (dwarf_attr (vr_die, DW_AT_location, &attr) ==NULL )return -EINVAL ;/* Broken DIE ? */ if (dwarf_getlocation_addr (&attr, addr, &op, &nops,1 ) <=0 ) { - ret =dwarf_entrypc (sp_die, &tmp); -if (ret) +if (dwarf_entrypc (sp_die, &tmp) !=0 )return -ENOENT ; if (probe_conf.show_location_range &&
@@ -115,8 +115,7 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,return -ENOENT ; } - ret =dwarf_highpc (sp_die, &tmp); -if (ret) +if (dwarf_highpc (sp_die, &tmp) !=0 )return -ENOENT ;/* * This is fuzzed by fentry mcount. We try to find the
@@ -138,12 +137,16 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, static_var:if (!tvar)return ret2; +/* Static variables on memory (not stack), make @varname */ - ret =strlen (dwarf_diename (vr_die)); + name =dwarf_diename (vr_die); +if (!name) +return -ENOENT ; + ret =strlen (name); tvar->value =zalloc (ret +2 );if (tvar->value ==NULL )return -ENOMEM ; -snprintf (tvar->value, ret +2 ,"@%s" ,dwarf_diename (vr_die)); +snprintf (tvar->value, ret +2 ,"@%s" , name); tvar->ref =alloc_trace_arg_ref ((long )offs);if (tvar->ref ==NULL )return -ENOMEM ;
@@ -234,13 +237,14 @@ static int convert_variable_type(Dwarf_Die *vr_die, }if (die_get_real_type (vr_die, &type) ==NULL ) { -pr_warning ("Failed to get a type information of %s.\n" , -dwarf_diename (vr_die)); +const char *name =dwarf_diename (vr_die); + +pr_warning ("Failed to get a type information of %s.\n" , name ?:"<unknown>" );return -ENOENT ; }pr_debug ("%s type is %s.\n" , -dwarf_diename (vr_die),dwarf_diename (&type)); +die_name (vr_die),die_name (&type));if (cast && (!strcmp (cast,"string" ) || !strcmp (cast,"ustring" ))) {/* String type */
@@ -249,7 +253,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, ret != DW_TAG_array_type) {pr_warning ("Failed to cast into string: " "%s(%s) is not a pointer nor array.\n" , -dwarf_diename (vr_die),dwarf_diename (&type)); +die_name (vr_die),die_name (&type));return -EINVAL ; }if (die_get_real_type (&type, &type) ==NULL ) {
@@ -272,7 +276,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, !die_compare_name(&type, "unsigned char")) {pr_warning ("Failed to cast into string: " "%s is not (unsigned) char *.\n" , -dwarf_diename (vr_die)); +die_name (vr_die));return -EINVAL ; } tvar->type =strdup (cast);
@@ -299,7 +303,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,/* Check the bitwidth */ if (ret >MAX_BASIC_TYPE_BITS ) {pr_info ("%s exceeds max-bitwidth. Cut down to %d bits.\n" , -dwarf_diename (&type),MAX_BASIC_TYPE_BITS ); +die_name (&type),MAX_BASIC_TYPE_BITS ); ret =MAX_BASIC_TYPE_BITS ; } ret =snprintf (buf,16 ,"%c%d" , prefix, ret);
@@ -333,12 +337,14 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,pr_warning ("Failed to get the type of %s.\n" , varname);return -ENOENT ; } -pr_debug2 ("Var real type: %s (%x)\n" ,dwarf_diename (&type), +pr_debug2 ("Var real type: %s (%x)\n" ,die_name (&type), (unsigned )dwarf_dieoffset (&type)); tag =dwarf_tag (&type);if (field->name[0 ] =='[' && (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)) { +int bsize; +/* Save original type for next field or type */ memcpy (die_mem, &type,sizeof (*die_mem));/* Get the type of this array */
@@ -346,7 +352,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,pr_warning ("Failed to get the type of %s.\n" , varname);return -ENOENT ; } -pr_debug2 ("Array real type: %s (%x)\n" ,dwarf_diename (&type), +pr_debug2 ("Array real type: %s (%x)\n" ,die_name (&type), (unsigned )dwarf_dieoffset (&type));if (tag == DW_TAG_pointer_type) { ref =zalloc (sizeof (struct probe_trace_arg_ref ));
@@ -357,7 +363,15 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,else *ref_ptr = ref; } - ref->offset +=dwarf_bytesize (&type) * field->index; + bsize =dwarf_bytesize (&type); + +if (bsize <0 ) +return -EINVAL ; +if (!ref) { +pr_warning ("Array indexing not supported for variables in registers.\n" ); +return -ENOTSUP ; + } + ref->offset += bsize * field->index; ref->user_access = user_access; goto next; }else if (tag == DW_TAG_pointer_type) {
@@ -414,7 +428,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,if (die_find_member (&type, field->name, die_mem) ==NULL ) {pr_warning ("%s(type:%s) has no member %s.\n" , varname, -dwarf_diename (&type), field->name); +die_name (&type), field->name);return -EINVAL ; }
@@ -461,7 +475,7 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)int ret;pr_debug ("Converting variable %s into trace event.\n" , -dwarf_diename (vr_die)); +die_name (vr_die)); ret =convert_variable_location (vr_die, pf->addr, pf->fb_ops, &pf->sp_die, pf, pf->tvar);
@@ -542,7 +556,7 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod,/* Verify the address is correct */ if (!dwarf_haspc (sp_die, paddr)) {pr_warning ("Specified offset is out of %s\n" , -dwarf_diename (sp_die)); +die_name (sp_die));return -EINVAL ; }
@@ -599,7 +613,7 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf)if (!die_find_realfunc (&pf->cu_die, pf->addr, &pf->sp_die)) {if (die_find_tailfunc (&pf->cu_die, pf->addr, &pf->sp_die)) {pr_warning ("Ignoring tail call from %s\n" , -dwarf_diename (&pf->sp_die)); +die_name (&pf->sp_die));return 0 ; }else { pr_warning("Failed to find probe point in any "
@@ -611,10 +625,16 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf)memcpy (&pf->sp_die, sc_die,sizeof (Dwarf_Die));/* Get the frame base attribute/ops from subprogram */ -dwarf_attr (&pf->sp_die, DW_AT_frame_base, &fb_attr); - ret =dwarf_getlocation_addr (&fb_attr, pf->addr, &pf->fb_ops, &nops,1 ); -if (ret <=0 || nops ==0 ) { +if (dwarf_attr (&pf->sp_die, DW_AT_frame_base, &fb_attr) ==NULL ) { pf->fb_ops =NULL ; + }else { + ret =dwarf_getlocation_addr (&fb_attr, pf->addr, &pf->fb_ops, &nops,1 ); +if (ret <=0 || nops ==0 ) + pf->fb_ops =NULL ; + } + +if (pf->fb_ops ==NULL ) { +/* Not supported */ }else if (nops ==1 && pf->fb_ops[0 ].atom == DW_OP_call_frame_cfa && (pf->cfi_eh !=NULL || pf->cfi_dbg !=NULL )) { if ((dwarf_cfi_addrframe(pf->cfi_eh, pf->addr, &frame) != 0 &&
@@ -667,8 +687,8 @@ static int find_best_scope_cb(Dwarf_Die *fn_die, void *data) } }else {/* With the line number, find the nearest declared DIE */ -dwarf_decl_line (fn_die, &lno); -if (lno < fsp->line && fsp->diff > fsp->line - lno) { +if (dwarf_decl_line (fn_die, &lno) ==0 && lno < fsp->line && + fsp->diff > fsp->line - lno) {/* Keep a candidate and continue */ fsp->diff = fsp->line - lno;memcpy (fsp->die_mem, fn_die,sizeof (Dwarf_Die));
@@ -924,12 +944,12 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)/* Get probe address */ if (die_entrypc (in_die, &addr) !=0 ) {pr_warning ("Failed to get entry address of %s.\n" , -dwarf_diename (in_die)); +die_name (in_die));return -ENOENT ; }if (addr ==0 ) {pr_debug ("%s has no valid entry address. skipped.\n" , -dwarf_diename (in_die)); +die_name (in_die));return -ENOENT ; } pf->addr = addr;
@@ -971,12 +991,13 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)if (pp->file && fname &&strtailcmp (pp->file, fname))return DWARF_CB_OK ; -pr_debug ("Matched function: %s [%lx]\n" ,dwarf_diename (sp_die), +pr_debug ("Matched function: %s [%lx]\n" ,die_name (sp_die), (unsigned long )dwarf_dieoffset (sp_die)); pf->fname = fname; pf->abstrace_dieoffset =dwarf_dieoffset (sp_die);if (pp->line) {/* Function relative line */ -dwarf_decl_line (sp_die, &pf->lno); +if (dwarf_decl_line (sp_die, &pf->lno) !=0 ) +return DWARF_CB_OK ; pf->lno += pp->line; param->retval =find_probe_point_by_line (pf); }else if (die_is_func_instance (sp_die)) {
@@ -985,7 +1006,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)/* But in some case the entry address is 0 */ if (pf->addr ==0 ) {pr_debug ("%s has no entry PC. Skipped\n" , -dwarf_diename (sp_die)); +die_name (sp_die)); param->retval =0 ;/* Real function */ }else if (pp->lazy_line)
@@ -1018,7 +1039,8 @@ static int find_probe_point_by_func(struct probe_finder *pf) {struct dwarf_callback_param _param = {.data = (void *)pf, .retval =0 }; -dwarf_getfuncs (&pf->cu_die, probe_point_search_cb, &_param,0 ); +if (dwarf_getfuncs (&pf->cu_die, probe_point_search_cb, &_param,0 ) <0 ) +pr_debug ("Failed to get functions from CU\n" );return _param.retval; }
@@ -1207,7 +1229,8 @@ static int copy_variables_cb(Dwarf_Die *die_mem, void *data)* points to correct die. */ if (dwarf_attr (die_mem, DW_AT_abstract_origin, &attr)) { -dwarf_formref_die (&attr, &var_die); +if (dwarf_formref_die (&attr, &var_die) ==NULL ) + goto out;if (pf->abstrace_dieoffset !=dwarf_dieoffset (&var_die)) goto out; }
@@ -1293,13 +1316,16 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf)if (ret <0 ) goto end; - tev->point.realname =strdup (dwarf_diename (sc_die)); + tev->point.realname =strdup (die_name (sc_die));if (!tev->point.realname) { ret = -ENOMEM ; goto end; } - tev->lang =dwarf_srclang (dwarf_diecu (sc_die, &pf->cu_die,NULL ,NULL )); +if (dwarf_diecu (sc_die, &pf->cu_die,NULL ,NULL ) !=NULL ) + tev->lang =dwarf_srclang (&pf->cu_die); +else + tev->lang =DW_LANG_C ;/* Fallback */ pr_debug ("Probe point found: %s+%lu\n" , tev->point.symbol, tev->point.offset);
@@ -1794,7 +1820,8 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)if (die_match_name (sp_die, lr->function) &&die_is_func_def (sp_die)) { lf->fname =die_get_decl_file (sp_die); -dwarf_decl_line (sp_die, &lr->offset); +if (dwarf_decl_line (sp_die, &lr->offset) !=0 ) + lr->offset =0 ;/* Fallback if no line info */ pr_debug ("fname: %s, lineno:%d\n" , lf->fname, lr->offset); lf->lno_s = lr->offset + lr->start;if (lf->lno_s <0 )/* Overflow */
@@ -1818,7 +1845,8 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)static int find_line_range_by_func (struct line_finder *lf) {struct dwarf_callback_param param = {.data = (void *)lf, .retval =0 }; -dwarf_getfuncs (&lf->cu_die, line_range_search_cb, ¶m,0 ); +if (dwarf_getfuncs (&lf->cu_die, line_range_search_cb, ¶m,0 ) <0 ) +pr_debug ("Failed to get functions from CU\n" );return param.retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 839/2077 perf annotate-data: Fix libdw API contract violations
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 5aa1941900050a2c80d29bc7ee0dfbddbad8f294 ]
Check return values of dwarf_aggregate_size and dwarf_formudata.
Additionally:
- Avoid vfprintf undefined behavior with NULL strings by using the die_name() helper for dwarf_diename() in pr_* calls.
- Use die_get_data_member_location() (updated to use dwarf_attr_integrate) to correctly parse location expressions for inherited member locations in the fallback path when dwarf_formudata() fails.
--- tools/perf/util/annotate-data.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
tools/perf/util/annotate-data.c +17 -10
@@ -74,7 +74,8 @@ void pr_debug_type_name(Dwarf_Die *die, enum type_state_kind kind)break ; } -dwarf_aggregate_size (die, &size); +if (dwarf_aggregate_size (die, &size) !=0 ) + size =0 ;strbuf_init (&sb,32 );die_get_typename_from_type (die, &sb);
@@ -146,9 +147,9 @@ static void pr_debug_scope(Dwarf_Die *scope_die) tag =dwarf_tag (scope_die);if (tag == DW_TAG_subprogram) -pr_info ("[function] %s\n" ,dwarf_diename (scope_die)); +pr_info ("[function] %s\n" ,die_name (scope_die));else if (tag == DW_TAG_inlined_subroutine) -pr_info ("[inlined] %s\n" ,dwarf_diename (scope_die)); +pr_info ("[inlined] %s\n" ,die_name (scope_die));else if (tag == DW_TAG_lexical_block)pr_info ("[block]\n" );else
@@ -250,9 +251,12 @@ static int __add_member_cb(Dwarf_Die *die, void *arg)if (dwarf_aggregate_size (&die_mem, &size) <0 ) size =0 ; -if (dwarf_attr_integrate (die, DW_AT_data_member_location, &attr)) -dwarf_formudata (&attr, &loc); -else { +if (dwarf_attr_integrate (die, DW_AT_data_member_location, &attr)) { +if (dwarf_formudata (&attr, &loc) !=0 ) { +if (die_get_data_member_location (die, &loc) !=0 ) + loc =0 ; + } + }else {/* bitfield member */ if (dwarf_attr_integrate (die, DW_AT_data_bit_offset, &attr) &&dwarf_formudata (&attr, &loc) ==0 )
@@ -273,7 +277,9 @@ static int __add_member_cb(Dwarf_Die *die, void *arg) dwarf_diename(die), (long)bit_size) < 0) member->var_name =NULL ; }else { - member->var_name =strdup (dwarf_diename (die)); +const char *name =dwarf_diename (die); + + member->var_name = name ?strdup (name) :NULL ; }if (member->var_name ==NULL ) {
@@ -370,7 +376,8 @@ static struct annotated_data_type *dso__findnew_data_type(struct dso *dso,if (dwarf_tag (type_die) == DW_TAG_typedef)die_get_real_type (type_die, type_die); -dwarf_aggregate_size (type_die, &size); +if (dwarf_aggregate_size (type_die, &size) !=0 ) + size =0 ;/* Check existing nodes in dso->data_types tree */ key.self.type_name = type_name;
@@ -1569,7 +1576,7 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) offset = loc->offset;pr_debug_dtp ("CU for %s (die:%#lx)\n" , -dwarf_diename (&cu_die), (long )dwarf_dieoffset (&cu_die)); +die_name (&cu_die), (long )dwarf_dieoffset (&cu_die));if (reg ==DWARF_REG_PC ) { if (get_global_var_type(&cu_die, dloc, dloc->ip, dloc->var_addr,
@@ -1636,7 +1643,7 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) }pr_debug_dtp ("found \"%s\" (die: %#lx) in scope=%d/%d (die: %#lx) " , -dwarf_diename (&var_die), (long )dwarf_dieoffset (&var_die), +die_name (&var_die), (long )dwarf_dieoffset (&var_die), i+1 , nr_scopes, (long )dwarf_dieoffset (&scopes[i]));if (reg ==DWARF_REG_PC ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 840/2077 perf debuginfo: Fix libdw API contract violations
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 31088ccf0312b1a547046f1f69890ede07834a30 ]
Check return value of dwfl_report_end during offline initialization. Validate dwfl_module_relocation_info result before passing to strcmp to avoid potential segmentation faults.
Additionally:
- Fix a file descriptor leak in debuginfo__init_offline_dwarf() when dwfl_report_offline() or subsequent setup calls fail.
--- tools/perf/util/debuginfo.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/util/debuginfo.c +6 -3
@@ -42,6 +42,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, {GElf_Addr dummy;int fd; +bool fd_consumed = false; fd =open (path,O_RDONLY );if (fd <0 )
@@ -55,6 +56,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, dbg->mod =dwfl_report_offline (dbg->dwfl,"" ,"" , fd);if (!dbg->mod) goto error; + fd_consumed = true; dbg->dbg =dwfl_module_getdwarf (dbg->mod, &dbg->bias);if (!dbg->dbg)
@@ -62,13 +64,14 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg,dwfl_module_build_id (dbg->mod, &dbg->build_id, &dummy); -dwfl_report_end (dbg->dwfl,NULL ,NULL ); +if (dwfl_report_end (dbg->dwfl,NULL ,NULL ) !=0 ) + goto error;return 0 ; error:if (dbg->dwfl)dwfl_end (dbg->dwfl); -else +if (!fd_consumed)close (fd);memset (dbg,0 ,sizeof (*dbg));
@@ -167,7 +170,7 @@ int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,/* Search the relocation related .text section */ for (i =0 ; i < n; i++) { p =dwfl_module_relocation_info (dbg->mod, i, &shndx); -if (strcmp (p,".text" ) ==0 ) { +if (p &&strcmp (p,".text" ) ==0 ) {/* OK, get the section header */ scn =elf_getscn (elf, shndx);if (!scn)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 841/2077 perf callchain: Handle multiple address spaces
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Richter <[email protected]>
[ Upstream commit ae15db3e9b639491007cc1e9e99638e4b6091781 ]
perf test 'perf inject to convert DWARF callchains to regular ones' fails on s390. It was introduced with commit 92ea788d2af4e65a ("perf
inject: Add --convert-callchain option")
The failure comes the difference in output. Without the inject script to convert DWARF the callchains is:
# perf record -F 999 --call-graph dwarf -- perf test -w noploop
# perf report -i perf.data --stdio --no-children -q \
--percent-limit=1 > /tmp/111
# cat /tmp/111
99.30% perf-noploop perf [.] noploop
|
---noploop
run_workload (inlined)
cmd_test
run_builtin (inlined)
handle_internal_command
run_argv (inlined)
main
__libc_start_call_main
__libc_start_main_impl (inlined)
_start
#With the inject script step the output is:
# perf inject -i perf.data --convert-callchain -o /tmp/perf-inject-1.out
# perf report -i /tmp/perf-inject-1.out --stdio --no-children -q \
--percent-limit=1 > /tmp/222
# cat /tmp/222
99.40% perf-noploop perf [.] noploop
|
---noploop
run_workload (inlined)
cmd_test
run_builtin (inlined)
handle_internal_command
run_argv (inlined)
main
_start
# diff /tmp/111 /tmp/222
1c1
< 99.30% perf-noploop perf [.] noploop
---Quoted 1 line
99.40% perf-noploop perf [.] noploop
10,11d9
< __libc_start_call_main
< __libc_start_main_impl (inlined)
#
The difference are the symbols __libc_start_call_main and __libc_start_main_impl.
On x86_64, kernel and user space share a single virtual address space, with the kernel mapped to the upper end of memory. The instruction pointer value alone is sufficient to distinguish between user space and kernel space addresses.
This is not true for s390, which uses separate address spaces for user and kernel.
The same virtual address can be valid in both address spaces, so the instruction pointer value alone cannot determine whether an address belongs to the kernel or user space.
Instead, perf must rely on the cpumode metadata derived from the processor status word (PSW) at sample time.
In function perf_event__convert_sample_callchain() the first part copies a kernel callchain and context entries, if any.
It then appends additional entries ignoring the address space architecture. Taking that into account, the symbols at addresses
0x3ff970348cb __libc_start_call_main
0x3ff970349c5 __libc_start_main_impl
(located after the kernel address space on s390) are now included.
Output before:
# perf test 83 83: perf inject to convert DWARF callchains to regular ones : FAILED!
Output after:
# perf test 83 83: perf inject to convert DWARF callchains to regular ones : Ok
Question to Namhyung:
In function perf_event__convert_sample_callchain() just before the for() loop this patch modifies, the kernel callchain is copied, see this comment and the next 5 lines:
/* copy kernel callchain and context entries */
Then why is machine__kernel_ip() needed in the for() loop, when the kernel entries have been copied just before the loop?
Note: This patch was tested on x86_64 virtual machine and succeeded.
--- tools/perf/arch/common.c | 4 +++- tools/perf/builtin-inject.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
tools/perf/arch/common.c +3 -1
@@ -237,5 +237,7 @@ int perf_env__lookup_objdump(struct perf_env *env, char **path)*/ bool perf_env__single_address_space (struct perf_env *env) { -return strcmp (perf_env__arch (env),"sparc" ); +const char *arch =perf_env__arch (env); + +return strcmp (arch,"s390" ) &&strcmp (arch,"sparc" ); }
tools/perf/builtin-inject.c +2 -1
@@ -438,7 +438,8 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool, node = cursor->first;for (k =0 ; k < cursor->nr && i <PERF_MAX_STACK_DEPTH ; k++) { -if (machine__kernel_ip (machine, node->ip)) +if (machine->single_address_space && +machine__kernel_ip (machine, node->ip))/* kernel IPs were added already */ ;else if (node->ms.sym && node->ms.sym->inlined)/* we can't handle inlined callchains */ ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 842/2077 coresight: cti: Fix DT filter signals silently ignored
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingchao Deng <[email protected]>
[ Upstream commit 551bb2fd5e4ed63d33aa11f07102cce5179b7595 ]
In cti_plat_process_filter_sigs(), after allocating a temporary cti_trig_grp struct via kzalloc_obj(), the code never assigns tg->nr_sigs = nr_filter_sigs. Since kzalloc zero-initialises the struct, tg->nr_sigs remains 0. cti_plat_read_trig_group() guards with:
if (!tgrp->nr_sigs)
return 0;so it returns immediately without reading any signal indices from DT.
Fix by assigning tg->nr_sigs before calling cti_plat_read_trig_group().
--- drivers/hwtracing/coresight/coresight-cti-platform.c | 1 + 1 file changed, 1 insertion(+)
drivers/hwtracing/coresight/coresight-cti-platform.c +1 -0
@@ -329,6 +329,7 @@ static int cti_plat_process_filter_sigs(struct cti_drvdata *drvdata,if (!tg)return -ENOMEM ; + tg->nr_sigs = nr_filter_sigs; err =cti_plat_read_trig_group (tg, fwnode,CTI_DT_FILTER_OUT_SIGS );if (!err) drvdata->config.trig_out_filter |= tg->used_mask;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 843/2077 soundwire: dont program SDW_SCP_BUSCLOCK_SCALE on a unattached Peripheral
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bard Liao <[email protected]>
[ Upstream commit c368dd5cbd61ffab2b6f8a89b0d5775e2e16cde6 ]
The SDW_SCP_BUSCLOCK_SCALE register will be programmed when the Peripheral is attached. We can and should skip programming the SDW_SCP_BUSCLOCK_SCALE register when the Peripheral is unattached.
--- drivers/soundwire/stream.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/soundwire/stream.c +7 -0
@@ -697,6 +697,13 @@ static int sdw_program_params(struct sdw_bus *bus, bool prepare)if (scale_index <0 )return scale_index; +/* Skip the unattached Peripherals */ +if (!completion_done (&slave->enumeration_complete)) { +dev_warn (&slave->dev, +"Not enumerated, skip programming BUSCLOCK_SCALE\n" ); +continue ; + } + ret =sdw_write_no_pm (slave, addr1, scale_index);if (ret <0 ) {dev_err (&slave->dev,"SDW_SCP_BUSCLOCK_SCALE register write failed\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 844/2077 soundwire: fix bug in sdw_add_element_group_count found by syzkaller
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baoli.Zhang <[email protected]>
[ Upstream commit f772ff5a0e6758fd412803c09e03ba3bca5f5878 ]
The original implementation caused an out-of-bounds memory access in the sdw_add_element_group_count for-loop when i == num.
for (i = 0; i <= num; i++) {
if (rate == group->rates[i] && lane == group->lanes[i])
...To fix this error, the function now checks for existing rate/lane entries in the group(a function parameter) using a for-loop before adding them.
No functional changes apart from this fix.
--- .../soundwire/generic_bandwidth_allocation.c | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-)
drivers/soundwire/generic_bandwidth_allocation.c +22 -25
@@ -299,39 +299,36 @@ static int sdw_add_element_group_count(struct sdw_group *group,int num = group->count;int i; -for (i =0 ; i <= num; i++) { +for (i =0 ; i < num; i++) {if (rate == group->rates[i] && lane == group->lanes[i]) -break ; - -if (i != num) -continue ; - -if (group->count >= group->max_size) { -unsigned int *rates; -unsigned int *lanes; +return 0 ; + } - group->max_size +=1 ; - rates =krealloc (group->rates, - (sizeof (int ) * group->max_size), -GFP_KERNEL ); -if (!rates) -return -ENOMEM ; +if (group->count >= group->max_size) { +unsigned int *rates; +unsigned int *lanes; - group->rates = rates; + group->max_size +=1 ; + rates =krealloc (group->rates, + (sizeof (int ) * group->max_size), +GFP_KERNEL ); +if (!rates) +return -ENOMEM ; - lanes =krealloc (group->lanes, - (sizeof (int ) * group->max_size), -GFP_KERNEL ); -if (!lanes) -return -ENOMEM ; + group->rates = rates; - group->lanes = lanes; - } + lanes =krealloc (group->lanes, + (sizeof (int ) * group->max_size), +GFP_KERNEL ); +if (!lanes) +return -ENOMEM ; - group->rates[group->count] = rate; - group->lanes[group->count++] = lane; + group->lanes = lanes; } + group->rates[group->count] = rate; + group->lanes[group->count++] = lane; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 845/2077 coresight: tmc: Fix overflow when calculating is bigger than 2GiB
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit f195d54deef1bc6dd3326394975baff02c7ae487 ]
When specifying a 2GB AUX buffer, the ETR driver ends up allocating only a 1MB buffer instead:
# echo 'file coresight-tmc-etr.c +p' > \ /sys/kernel/debug/dynamic_debug/control # perf record -e cs_etm/@tmc_etr0,timestamp=0/u -C 0 -m ,2G -- test coresight tmc_etr0: allocated buffer of size 1024KB in mode 0
The page index is an 'int' type, and shifting it by PAGE_SHIFT overflows when the resulting value exceeds 2GB. This produces a negative value, causing the driver to fall back to the minimum buffer size (1MB).
Cast the page index to a wider type to accommodate large buffer sizes. Also fix a similar issue in the buffer offset calculation.
--- drivers/hwtracing/coresight/coresight-tmc-etr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-etr.c +2 -2
@@ -154,7 +154,7 @@ tmc_pages_get_offset(struct tmc_pages *tmc_pages, dma_addr_t addr)for (i =0 ; i < tmc_pages->nr_pages; i++) { page_start = tmc_pages->daddrs[i];if (addr >= page_start && addr < (page_start +PAGE_SIZE )) -return i *PAGE_SIZE + (addr - page_start); +return (long )i *PAGE_SIZE + (addr - page_start); }return -EINVAL ;
@@ -1379,7 +1379,7 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, node = (event->cpu ==-1 ) ?NUMA_NO_NODE :cpu_to_node (event->cpu);/* Use the minimum limit if the required size is smaller */ - size = nr_pages <<PAGE_SHIFT ; + size = (ssize_t )nr_pages <<PAGE_SHIFT ; size =max_t (ssize_t, size,TMC_ETR_PERF_MIN_BUF_SIZE );/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 846/2077 coresight: ete: Always save state on power down
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 2ab4645fe4206c142a5f1491e191c906279686cf ]
System register ETMs and ETE are unlikely to be preserved on CPU power down. The ETE DT binding also never documented "arm,coresight-loses-context-with-cpu" so nobody would have legitimately been able to use that binding to fix it and ACPI has no such binding at all.
Fix it by hard coding the setting for sysreg ETMs (ETE is always sysreg) or ACPI boots. Use a local variable when setting up save_state so that it's immune to concurrent probing when devices have different configurations which is an issue with modifying the global.
This fixes the following error when using Coresight with ACPI on the FVP which supports CPU PM:
coresight ete0: External agent took claim tag
WARNING: drivers/hwtracing/coresight/coresight-core.c:248 at coresight_disclaim_device_unlocked+0xe0/0xe8, CPU#0: perf/117
--- .../coresight/coresight-etm4x-core.c | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +34 -14
@@ -56,10 +56,14 @@ MODULE_PARM_DESC(boot_enable, "Enable tracing on boot");#define PARAM_PM_SAVE_NEVER 1/* never save any state */ #define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ +/* +* Save option for ETM4. ETE, sysreg ETM4s and ACPI boots ignore this option and +* will always save. +*/ static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ;module_param (pm_save_enable, int,0444 );MODULE_PARM_DESC (pm_save_enable, -"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +"Save/restore state on power down: 1 = never, 2 = self-hosted. MMIO and DT only." );static struct etmv4_drvdata *etmdrvdata[NR_CPUS ];static void etm4_set_default_config (struct etmv4_config *config);
@@ -2012,7 +2016,7 @@ static int etm4_cpu_save(struct etmv4_drvdata *drvdata) {int ret =0 ; -if (pm_save_enable !=PARAM_PM_SAVE_SELF_HOSTED ) +if (!drvdata->save_state)return 0 ;/*
@@ -2127,7 +2131,7 @@ static void __etm4_cpu_restore(struct etmv4_drvdata *drvdata)static void etm4_cpu_restore (struct etmv4_drvdata *drvdata) { -if (pm_save_enable !=PARAM_PM_SAVE_SELF_HOSTED ) +if (!drvdata->save_state)return ;if (coresight_get_mode (drvdata->csdev))
@@ -2212,6 +2216,17 @@ static void etm4_pm_clear(void) } } +static bool etm4x_always_pm_save (struct device *dev,struct csdev_access *csa) +{ +/* +* Only IO mem ETM devices will benefit from skipping PM save and only +* DT has the option to control it, not ACPI. Otherwise system register +* based ETMs and ETEs will always lose context on CPU power down, so +* always save. +*/ +return !csa->io_mem ||is_acpi_device_node (dev_fwnode (dev)); +} +static int etm4_add_coresight_dev (struct etm4_init_arg *init_arg) {int ret;
@@ -2221,6 +2236,7 @@ static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg)struct coresight_desc desc = {0 };u8 major, minor;char *type_name; +bool pm_save;if (!drvdata)return -EINVAL ;
@@ -2248,6 +2264,21 @@ static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg)etm4_set_default (&drvdata->config); +if (etm4x_always_pm_save (dev, init_arg->csa)) + pm_save = true; +else if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) + pm_save =coresight_loses_context_with_cpu (dev); +else + pm_save = pm_save_enable !=PARAM_PM_SAVE_NEVER ; + +if (pm_save) { + drvdata->save_state =devm_kmalloc (dev, +sizeof (struct etmv4_save_state ), +GFP_KERNEL ); +if (!drvdata->save_state) +return -ENOMEM ; + } + pdata =coresight_get_platform_data (dev);if (IS_ERR (pdata))return PTR_ERR (pdata);
@@ -2305,17 +2336,6 @@ static int etm4_probe(struct device *dev)if (ret)return ret; -if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) - pm_save_enable =coresight_loses_context_with_cpu (dev) ? -PARAM_PM_SAVE_SELF_HOSTED :PARAM_PM_SAVE_NEVER ; - -if (pm_save_enable !=PARAM_PM_SAVE_NEVER ) { - drvdata->save_state =devm_kmalloc (dev, -sizeof (struct etmv4_save_state ),GFP_KERNEL ); -if (!drvdata->save_state) -return -ENOMEM ; - } -raw_spin_lock_init (&drvdata->spinlock); drvdata->cpu =coresight_get_cpu (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 847/2077 coresight: etm4x: Correct TRCVMIDCCTLR1 save and restore
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit 0ec0a8785d21f63db520bd9d2a67c55e855d36a8 ]
It is a typo to use trcvmidcctlr0 to save and restore TRCVMIDCCTLR1. Use trcvmidcctlr1 instead.
--- drivers/hwtracing/coresight/coresight-etm4x-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +2 -2
@@ -1983,7 +1983,7 @@ static int __etm4_cpu_save(struct etmv4_drvdata *drvdata) state->trcvmidcctlr0 =etm4x_read32 (csa,TRCVMIDCCTLR0 );if (drvdata->numvmidc >4 ) - state->trcvmidcctlr0 =etm4x_read32 (csa,TRCVMIDCCTLR1 ); + state->trcvmidcctlr1 =etm4x_read32 (csa,TRCVMIDCCTLR1 ); state->trcclaimset =etm4x_read32 (csa,TRCCLAIMCLR );
@@ -2106,7 +2106,7 @@ static void __etm4_cpu_restore(struct etmv4_drvdata *drvdata)etm4x_relaxed_write32 (csa, state->trcvmidcctlr0,TRCVMIDCCTLR0 );if (drvdata->numvmidc >4 ) -etm4x_relaxed_write32 (csa, state->trcvmidcctlr0,TRCVMIDCCTLR1 ); +etm4x_relaxed_write32 (csa, state->trcvmidcctlr1,TRCVMIDCCTLR1 );etm4x_relaxed_write32 (csa, state->trcclaimset,TRCCLAIMSET );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 848/2077 PCI/ASPM: Dont reconfigure ASPM entering low-power state
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlos Bilbao <[email protected]>
[ Upstream commit c855c9921da72e535c24737c748f603a52d03f7e ]
Reconfiguring ASPM when a device transitions to low-power state can enable L1.1/L1.2 substates on the PCIe link at a time when the device is sleeping and may be unable to exit them. ASPM should be reconfigured on D0 entry (resume), not on the way down.
pci_set_low_power_state() calls pcie_aspm_pm_state_change() after writing D3hot to PCI_PM_CTRL. pcie_aspm_pm_state_change() resets link->aspm_capable to link->aspm_support and then calls pcie_config_aspm_path(), which can enable ASPM L1.1/L1.2 substates on the PCIe link. If the device cannot recover the link from L1.2 while in D3hot, subsequent config space reads return 0xFFFF ("device inaccessible") and pci_power_up() fails with messages like:
vfio-pci 0000:5d:00.0: Unable to change power state from D3hot to D0, device inaccessible
This was observed on NVIDIA H100 SXM5 GPUs bound to vfio-pci when Linux runtime PM suspends them to D3hot: the GPU becomes permanently inaccessible and disappears from the PCIe bus.
The call to pcie_aspm_pm_state_change() in pci_set_low_power_state() was restored by f93e71aea6c6 ("Revert "PCI/ASPM: Remove pcie_aspm_pm_state_change()""), which reverted 08d0cc5f3426 ("PCI/ASPM:
Remove pcie_aspm_pm_state_change()"). The revert was necessary because the removal broke suspend/resume on certain platforms that required ASPM to be reconfigured on D0 entry. However, the revert restored the call in both pci_set_full_power_state() (D0 entry) and pci_set_low_power_state() (low-power entry).
Only the D0-entry call is needed to fix the suspend/resume regression. The low-power-entry call is harmful: reconfiguring ASPM immediately after putting a device into D3hot can enable link substates that the device or platform cannot exit while the device is sleeping.
Remove the pcie_aspm_pm_state_change() call from pci_set_low_power_state(). ASPM will still be reconfigured correctly when the device returns to D0 via pci_set_full_power_state().
--- drivers/pci/pci.c | 3 --- 1 file changed, 3 deletions(-)
drivers/pci/pci.c +0 -3
@@ -1514,9 +1514,6 @@ static int pci_set_low_power_state(struct pci_dev *dev, pci_power_t state, boolpci_power_name (dev->current_state), pci_power_name(state)); -if (dev->bus->self) -pcie_aspm_pm_state_change (dev->bus->self, locked); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 849/2077 PCI: Introduce named defines for PCI ROM
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit 113e86bc58a918f85d250723436a4d541a873358 ]
Convert the magic numbers associated with PCI ROM into named definitions. Some of these definitions will be used in the second fix patch.
Stable-dep-of: 538796b807fc ("PCI: Check ROM header and data structure addr before accessing")
--- drivers/pci/rom.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
drivers/pci/rom.c +28 -12
@@ -5,13 +5,28 @@* (C) Copyright 2004 Jon Smirl <[email protected]> * (C) Copyright 2004 Silicon Graphics, Inc. Jesse Barnes <[email protected]> */ + +#include <linux/bits.h> #include <linux/kernel.h> #include <linux/export.h> #include <linux/pci.h> +#include <linux/sizes.h> #include <linux/slab.h> #include "pci.h" +#define PCI_ROM_HEADER_SIZE 0x1A +#define PCI_ROM_POINTER_TO_DATA_STRUCT 0x18 +#define PCI_ROM_LAST_IMAGE_INDICATOR 0x15 +#define PCI_ROM_LAST_IMAGE_INDICATOR_BIT BIT(7) +#define PCI_ROM_IMAGE_LEN 0x10 +#define PCI_ROM_IMAGE_SECTOR_SIZE SZ_512 +#define PCI_ROM_IMAGE_SIGNATURE 0xAA55 + +/* Data structure signature is "PCIR" in ASCII representation */ +#define PCI_ROM_DATA_STRUCT_SIGNATURE 0x52494350 +#define PCI_ROM_DATA_STRUCT_LEN 0x0A +/** * pci_enable_rom - enable ROM decoding for a PCI device * @pdev: PCI device to enable
@@ -91,26 +106,27 @@ static size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, do { void __iomem *pds; /* Standard PCI ROMs start out with these bytes 55 AA */ - if (readw(image) != 0xAA55) { - pci_info(pdev, "Invalid PCI ROM header signature: expecting 0xaa55, got %#06x\n", - readw(image)); + if (readw(image) != PCI_ROM_IMAGE_SIGNATURE) { + pci_info(pdev, "Invalid PCI ROM header signature: expecting %#06x, got %#06x\n", + PCI_ROM_IMAGE_SIGNATURE, readw(image)); break; } - /* get the PCI data structure and check its "PCIR" signature */ - pds = image + readw(image + 24); - if (readl(pds) != 0x52494350) { - pci_info(pdev, "Invalid PCI ROM data signature: expecting 0x52494350, got %#010x\n", - readl(pds)); + /* Get the PCI data structure and check its "PCIR" signature */ + pds = image + readw(image + PCI_ROM_POINTER_TO_DATA_STRUCT); + if (readl(pds) != PCI_ROM_DATA_STRUCT_SIGNATURE) { + pci_info(pdev, "Invalid PCI ROM data signature: expecting %#010x, got %#010x\n", + PCI_ROM_DATA_STRUCT_SIGNATURE, readl(pds)); break; } - last_image = readb(pds + 21) & 0x80; - length = readw(pds + 16); - image += length * 512; + last_image = readb(pds + PCI_ROM_LAST_IMAGE_INDICATOR) & + PCI_ROM_LAST_IMAGE_INDICATOR_BIT; + length = readw(pds + PCI_ROM_IMAGE_LEN); + image += length * PCI_ROM_IMAGE_SECTOR_SIZE; /* Avoid iterating through memory outside the resource window */ if (image >= rom + size) break; if (!last_image) { - if (readw(image) != 0xAA55) { + if (readw(image) != PCI_ROM_IMAGE_SIGNATURE) { pci_info(pdev, "No more image in the PCI ROM\n"); break; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 850/2077 PCI: Check ROM header and data structure addr before accessing
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit 538796b807fcfb81b2ce40cc97a614fd8588feb5 ]
We meet a crash when running stress-ng on x86_64 machine:
BUG: unable to handle page fault for address: ffa0000007f40000
RIP: 0010:pci_get_rom_size+0x52/0x220
Call Trace:
<TASK>
pci_map_rom+0x80/0x130
pci_read_rom+0x4b/0xe0
kernfs_file_read_iter+0x96/0x180
vfs_read+0x1b1/0x300Our analysis reveals that the ROM space's start address is 0xffa0000007f30000, and size is 0x10000. Because of broken ROM space, before calling readl(pds), the pds's value is 0xffa0000007f3ffff, which is already pointed to the ROM space end, invoking readl() would read 4 bytes therefore cause an out-of-bounds access and trigger a crash. Fix this by adding image header and data structure checking.
We also found another crash on arm64 machine:
Unable to handle kernel paging request at virtual address ffff8000dd1393ff Mem abort info: ESR = 0x0000000096000021 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x21: alignment fault
The call trace is the same with x86_64, but the crash reason is that the data structure addr is not aligned with 4, and arm64 machine report "alignment fault". Fix this by adding alignment checking.
--- drivers/pci/rom.c | 123 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 18 deletions(-)
drivers/pci/rom.c +105 -18
@@ -6,9 +6,12 @@* (C) Copyright 2004 Silicon Graphics, Inc. Jesse Barnes <[email protected]> */ +#include <linux/align.h> #include <linux/bits.h> #include <linux/kernel.h> #include <linux/export.h> +#include <linux/io.h> +#include <linux/overflow.h> #include <linux/pci.h> #include <linux/sizes.h> #include <linux/slab.h>
@@ -27,6 +30,15 @@#define PCI_ROM_DATA_STRUCT_SIGNATURE 0x52494350#define PCI_ROM_DATA_STRUCT_LEN 0x0A +/* +* Per PCI Firmware r3.3, sec 5.1.3, a conformant PCI Data Structure is at +* least 24 bytes (0x18), large enough to cover every fixed field this +* driver reads (up to the Indicator byte at offset 0x15). Reject smaller +* device-claimed lengths so the follow-up readers in pci_get_rom_size() +* cannot escape the mapped ROM window. +*/ +#define PCI_ROM_DATA_STRUCT_MIN_LEN 0x18 +/** * pci_enable_rom - enable ROM decoding for a PCI device * @pdev: PCI device to enable
@@ -84,6 +96,91 @@ void pci_disable_rom(struct pci_dev *pdev) }EXPORT_SYMBOL_GPL (pci_disable_rom); +static bool pci_rom_header_valid (struct pci_dev *pdev,void __iomem *image, +void __iomem *rom,size_t size, +bool expect_valid) +{ +unsigned long rom_end = (unsigned long )rom + size -1 ; +unsigned long header_end; +u16 signature; + +/* +* Per PCI Firmware r3.3, sec 5.1, each image must start on a +* 512-byte boundary and must contain the PCI Expansion ROM header. +* Because @rom is page-aligned (returned by ioremap()), checking +* 512-byte alignment of @image is equivalent to enforcing the +* spec's sector-aligned layout within the ROM. This also +* satisfies the natural-alignment requirement of readw() on archs +* such as arm64 that disallow unaligned IOMEM access. +*/ +if (!IS_ALIGNED ((unsigned long )image,PCI_ROM_IMAGE_SECTOR_SIZE )) +return false; + +if (check_add_overflow ((unsigned long )image,PCI_ROM_HEADER_SIZE -1 , + &header_end)) +return false; + +if (image < rom || header_end > rom_end) +return false; + +/* Standard PCI ROMs start out with these bytes 55 AA */ + signature =readw (image); +if (signature !=PCI_ROM_IMAGE_SIGNATURE ) { +if (expect_valid) { +pci_info (pdev,"Invalid PCI ROM header signature: expecting %#06x, got %#06x\n" , +PCI_ROM_IMAGE_SIGNATURE , signature); + }else { +pci_info (pdev,"No more images in PCI ROM\n" ); + } +return false; + } + +return true; +} + +static bool pci_rom_data_struct_valid (struct pci_dev *pdev,void __iomem *pds, +void __iomem *rom,size_t size) +{ +unsigned long rom_end = (unsigned long )rom + size -1 ; +unsigned long end; +u32 signature; +u16 data_len; + +/* +* Some CPU architectures require IOMEM access addresses to be +* aligned, for example arm64, so since we're about to call +* readl(), check here for 4-byte alignment. +*/ +if (!IS_ALIGNED ((unsigned long )pds,4 )) +return false; + +if (check_add_overflow ((unsigned long )pds,PCI_ROM_DATA_STRUCT_LEN +1 , + &end)) +return false; + +if (pds < rom || end > rom_end) +return false; + + signature =readl (pds); +if (signature !=PCI_ROM_DATA_STRUCT_SIGNATURE ) { +pci_info (pdev,"Invalid PCI ROM data signature: expecting %#010x, got %#010x\n" , +PCI_ROM_DATA_STRUCT_SIGNATURE , signature); +return false; + } + + data_len =readw (pds +PCI_ROM_DATA_STRUCT_LEN ); +if (data_len <PCI_ROM_DATA_STRUCT_MIN_LEN || data_len ==U16_MAX ) +return false; + +if (check_add_overflow ((unsigned long )pds, data_len -1 , &end)) +return false; + +if (end > rom_end) +return false; + +return true; +} +/** * pci_get_rom_size - obtain the actual size of the ROM image * @pdev: target PCI device
@@ -99,38 +196,28 @@ static size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size) {void __iomem *image; -int last_image;unsigned int length; +bool last_image; image = rom;do {void __iomem *pds; -/* Standard PCI ROMs start out with these bytes 55 AA */ -if (readw (image) !=PCI_ROM_IMAGE_SIGNATURE ) { -pci_info (pdev,"Invalid PCI ROM header signature: expecting %#06x, got %#06x\n" , -PCI_ROM_IMAGE_SIGNATURE ,readw (image)); +if (!pci_rom_header_valid (pdev, image, rom, size, true))break ; - } +/* Get the PCI data structure and check its "PCIR" signature */ pds = image +readw (image +PCI_ROM_POINTER_TO_DATA_STRUCT ); -if (readl (pds) !=PCI_ROM_DATA_STRUCT_SIGNATURE ) { -pci_info (pdev,"Invalid PCI ROM data signature: expecting %#010x, got %#010x\n" , -PCI_ROM_DATA_STRUCT_SIGNATURE ,readl (pds)); +if (!pci_rom_data_struct_valid (pdev, pds, rom, size))break ; - } + last_image =readb (pds +PCI_ROM_LAST_IMAGE_INDICATOR ) &PCI_ROM_LAST_IMAGE_INDICATOR_BIT ; length =readw (pds +PCI_ROM_IMAGE_LEN ); image += length *PCI_ROM_IMAGE_SECTOR_SIZE ; -/* Avoid iterating through memory outside the resource window */ -if (image >= rom + size) + +if (!last_image && + !pci_rom_header_valid (pdev, image, rom, size, false))break ; -if (!last_image) { -if (readw (image) !=PCI_ROM_IMAGE_SIGNATURE ) { -pci_info (pdev,"No more image in the PCI ROM\n" ); -break ; - } - } }while (length && !last_image);/* never return a size larger than the PCI resource window */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 851/2077 x86/platform/olpc: xo15: Drop wakeup source on driver removal
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit cc966553e6ff0849978b5754531b768b0ff54985 ]
Prevent leaking a wakeup source object after removing the driver by adding appropriate cleanup code to its remove callback function.
--- arch/x86/platform/olpc/olpc-xo15-sci.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/platform/olpc/olpc-xo15-sci.c +1 -0
@@ -186,6 +186,7 @@ static int xo15_sci_add(struct acpi_device *device)static void xo15_sci_remove (struct acpi_device *device) { +device_init_wakeup (&device->dev, false);acpi_disable_gpe (NULL , xo15_sci_gpe);acpi_remove_gpe_handler (NULL , xo15_sci_gpe, xo15_sci_gpe_handler);cancel_work_sync (&sci_work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 852/2077 platform/x86: xo15-ebook: Fix wakeup source and GPE handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit b2fc2c6ebbd2d49935c8960755d8170faead2159 ]
The device_set_wakeup_enable() call in ebook_switch_add() doesn't actually do anything because power.can_wakeup is not set for ACPI device objects. Moreover, had it done anything, it would have registered a wakeup source object that wouldn't have been used going forward and that wakeup source would have been leaked after driver removal because ebook_switch_remove() doesn't clean it up. Accordingly, remove that call from ebook_switch_add().
Also prevent leaking an enabled ACPI GPE after removing the driver by adding appropriate cleanup code to ebook_switch_remove().
--- drivers/platform/x86/xo15-ebook.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/platform/x86/xo15-ebook.c +6 -1
@@ -38,6 +38,7 @@ MODULE_DEVICE_TABLE(acpi, ebook_device_ids);struct ebook_switch {struct input_dev *input;char phys[32 ];/* for input device */ +bool gpe_enabled; };static int ebook_send_state (struct acpi_device *device)
@@ -128,7 +129,7 @@ static int ebook_switch_add(struct acpi_device *device)/* Button's GPE is run-wake GPE */ acpi_enable_gpe (device->wakeup.gpe_device, device->wakeup.gpe_number); -device_set_wakeup_enable (&device->dev, true); + button->gpe_enabled = true; }return 0 ;
@@ -144,6 +145,10 @@ static void ebook_switch_remove(struct acpi_device *device) {struct ebook_switch *button =acpi_driver_data (device); +if (button->gpe_enabled) +acpi_disable_gpe (device->wakeup.gpe_device, + device->wakeup.gpe_number); +input_unregister_device (button->input);kfree (button); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 853/2077 perf sched: Add missing mmap2 handler in timehist
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 91182741369b261c441e63e6678893032a6d7e4c ]
perf_sched__timehist() registers event handlers for options using the sched->tool struct. It registers handlers for MMAP, COMM, EXIT, FORK, etc. but completely omits registering a handler for MMAP2 events.
Failing to register both MMAP and MMAP2 handlers causes modern systems (which primarily output MMAP2 records) to silently drop VMA map mappings. This results in uninitialized machine/thread mapping structures, making it impossible to resolve shared library instruction pointers (IPs) to dynamic symbols/DSOs during timehist callchain analysis.
Fix this by correctly registering perf_event__process_mmap2 in sched->tool inside perf_sched__timehist().
--- tools/perf/builtin-sched.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/builtin-sched.c +1 -0
@@ -3299,6 +3299,7 @@ static int perf_sched__timehist(struct perf_sched *sched)*/ sched->tool.sample = perf_timehist__process_sample; sched->tool.mmap = perf_event__process_mmap; + sched->tool.mmap2 = perf_event__process_mmap2; sched->tool.comm = perf_event__process_comm; sched->tool.exit = perf_event__process_exit; sched->tool.fork = perf_event__process_fork;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 854/2077 perf tool: Fix missing schedstat delegates and dont_split_sample_group in delegate_tool
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 09d355618f7ccc27ffc7fc668b2e232872962079 ]
delegate_tool was missing the delegate overrides for schedstat_cpu and schedstat_domain. As a result, when allocated with zalloc, these callbacks defaulted to NULL, causing a segmentation fault crash if any schedstat events were delivered during event processing. Fix this by adding delegate_schedstat_cpu and delegate_schedstat_domain via the CREATE_DELEGATE_OP2 macro, and ensuring delegate_tool__init correctly registers them.
Additionally, delegate_tool__init completely omitted copying the dont_split_sample_group property from the delegate. This would cause wrapper tools to default the flag to false, which corrupts piped event processing (e.g., in perf inject) by triggering duplicate event deliveries on split sample values in deliver_sample_group().
Similarly, perf_tool__init() omitted the initialization of this boolean field. On stack-allocated tools that rely on this initializer (like intel-tpebs or __cmd_evlist), this could result in uninitialized stack garbage evaluating to true—silently dropping non-leader event members in deliver_sample_group().
Fix both issues by properly copying the field in delegate_tool__init and initializing it to false in perf_tool__init.
--- tools/perf/util/tool.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/tool.c +6 -0
@@ -285,6 +285,7 @@ void perf_tool__init(struct perf_tool *tool, bool ordered_events) tool->no_warn = false; tool->show_feat_hdr =SHOW_FEAT_NO_HEADER ; tool->merge_deferred_callchains = true; + tool->dont_split_sample_group = false; tool->sample = process_event_sample_stub; tool->mmap = process_event_stub;
@@ -433,6 +434,8 @@ CREATE_DELEGATE_OP2(stat_config);CREATE_DELEGATE_OP2 (stat_round);CREATE_DELEGATE_OP2 (thread_map);CREATE_DELEGATE_OP2 (time_conv); +CREATE_DELEGATE_OP2 (schedstat_cpu); +CREATE_DELEGATE_OP2 (schedstat_domain);CREATE_DELEGATE_OP2 (tracing_data);#define CREATE_DELEGATE_OP3 (name) \
@@ -470,6 +473,7 @@ void delegate_tool__init(struct delegate_tool *tool, struct perf_tool *delegate) tool->tool.no_warn = delegate->no_warn; tool->tool.show_feat_hdr = delegate->show_feat_hdr; tool->tool.merge_deferred_callchains = delegate->merge_deferred_callchains; + tool->tool.dont_split_sample_group = delegate->dont_split_sample_group; tool->tool.sample = delegate_sample; tool->tool.read = delegate_read;
@@ -516,4 +520,6 @@ void delegate_tool__init(struct delegate_tool *tool, struct perf_tool *delegate) tool->tool.bpf_metadata = delegate_bpf_metadata; tool->tool.compressed = delegate_compressed; tool->tool.auxtrace = delegate_auxtrace; + tool->tool.schedstat_cpu = delegate_schedstat_cpu; + tool->tool.schedstat_domain = delegate_schedstat_domain; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 855/2077 PCI: intel-gw: Move interrupt enable to own function
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Eckert <[email protected]>
[ Upstream commit abddc0539e5931f4ad2f589a03cbba5a6a64485f ]
To improve the readability of the code, move the interrupt enable instructions to a separate function. That is already done for the disable interrupt instruction.
In addition, clear and disable all pending interrupts, as is done in intel_pcie_core_irq_disable(). After that, enable all relevant interrupts again. The 'PCIE_APP_IRNEN' definition contains all the relevant interrupts that are of interest.
This change is also done in the MaxLinear SDK [1]. As I unfortunately don’t have any documentation for this IP core, I suspect that the intention is to set the IP core for interrupt handling to a specific state. Perhaps the problem is that the IP core did not reinitialize the interrupt register properly after a power cycle.
In my view, it can’t do any harm to switch the interrupt off and then on again to set them to a specific state.
The reason why the MaxLinear SDK is used as a reference here is, that this PCIe DWC IP is used in the URX851 and URX850 SoC. This SoC was originally developed by Intel when they acquired Lantiq’s home networking division in 2015 [2]. In 2020 the home network division was sold to MaxLinear [3]. Since then, this SoC belongs to MaxLinear. They use their own SDK, which runs on kernel version '5.15.x'.
[1] https://github.com/maxlinear/linux/blob/updk_9.1.90/drivers/pci/controller/dwc/pcie-intel-gw.c#L431
[2] https://www.intc.com/news-events/press-releases/detail/364/intel-to-acquire-lantiq-advancing-the-connected-home
[3] https://investors.maxlinear.com/press-releases/detail/395/maxlinear-to-acquire-intels-home-gateway-platform
Stable-dep-of: 1eedabe7c617 ("PCI: intel-gw: Add .start_link() callback")
--- drivers/pci/controller/dwc/pcie-intel-gw.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-intel-gw.c +8 -3
@@ -196,6 +196,13 @@ static void intel_pcie_device_rst_deassert(struct intel_pcie *pcie)gpiod_set_value_cansleep (pcie->reset_gpio,0 ); } +static void intel_pcie_core_irq_enable (struct intel_pcie *pcie) +{ +pcie_app_wr (pcie,PCIE_APP_IRNEN ,0 ); +pcie_app_wr (pcie,PCIE_APP_IRNCR ,PCIE_APP_IRN_INT ); +pcie_app_wr (pcie,PCIE_APP_IRNEN ,PCIE_APP_IRN_INT ); +} +static void intel_pcie_core_irq_disable (struct intel_pcie *pcie) {pcie_app_wr (pcie,PCIE_APP_IRNEN ,0 );
@@ -317,9 +324,7 @@ static int intel_pcie_host_setup(struct intel_pcie *pcie)if (ret) goto app_init_err; -/* Enable integrated interrupts */ -pcie_app_wr_mask (pcie,PCIE_APP_IRNEN ,PCIE_APP_IRN_INT , -PCIE_APP_IRN_INT ); +intel_pcie_core_irq_enable (pcie);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 856/2077 PCI: intel-gw: Enable clock before PHY init
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Eckert <[email protected]>
[ Upstream commit febf9ed3c35e5eec7ea384ebbd55a5296e3ca5e9 ]
To ensure that the boot sequence is correct, the DWC PCIe core clock must be switched on before PHY init call [1]. This changes are based on patched kernel sources of the MaxLinear SDK.
The reason why the MaxLinear SDK is used as a reference here is, that this PCIe DWC IP is used in the URX851 and URX850 SoC. This SoC was originally developed by Intel when they acquired Lantiq’s home networking division in 2015 [2]. In 2020 the home network division was sold to MaxLinear [3]. Since then, this SoC belongs to MaxLinear. They use their own SDK, which runs on kernel version '5.15.x'.
[1] https://github.com/maxlinear/linux/blob/updk_9.1.90/drivers/pci/controller/dwc/pcie-intel-gw.c#L544
[2] https://www.intc.com/news-events/press-releases/detail/364/intel-to-acquire-lantiq-advancing-the-connected-home
[3] https://investors.maxlinear.com/press-releases/detail/395/maxlinear-to-acquire-intels-home-gateway-platform
Stable-dep-of: 1eedabe7c617 ("PCI: intel-gw: Add .start_link() callback")
--- drivers/pci/controller/dwc/pcie-intel-gw.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/pci/controller/dwc/pcie-intel-gw.c +10 -9
@@ -292,13 +292,9 @@ static int intel_pcie_host_setup(struct intel_pcie *pcie)intel_pcie_core_rst_assert (pcie);intel_pcie_device_rst_assert (pcie); - - ret =phy_init (pcie->phy); -if (ret) -return ret; -intel_pcie_core_rst_deassert (pcie); +/* Controller clock must be provided earlier than PHY */ ret =clk_prepare_enable (pcie->core_clk);if (ret) {dev_err (pcie->pci.dev,"Core clock enable failed: %d\n" , ret);
@@ -307,13 +303,17 @@ static int intel_pcie_host_setup(struct intel_pcie *pcie) pci->atu_base = pci->dbi_base +0xC0000 ; + ret =phy_init (pcie->phy); +if (ret) + goto phy_err; +intel_pcie_ltssm_disable (pcie);intel_pcie_link_setup (pcie);intel_pcie_init_n_fts (pci); ret =dw_pcie_setup_rc (&pci->pp);if (ret) - goto app_init_err; + goto err;dw_pcie_upconfig_setup (pci);
@@ -322,17 +322,18 @@ static int intel_pcie_host_setup(struct intel_pcie *pcie) ret =dw_pcie_wait_for_link (pci);if (ret) - goto app_init_err; + goto err;intel_pcie_core_irq_enable (pcie);return 0 ; -app_init_err: +err: +phy_exit (pcie->phy); +phy_err:clk_disable_unprepare (pcie->core_clk); clk_err:intel_pcie_core_rst_assert (pcie); -phy_exit (pcie->phy);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 857/2077 PCI: intel-gw: Add .start_link() callback
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Eckert <[email protected]>
[ Upstream commit 1eedabe7c6170b5c73c7d801f427c127be74916e ]
The pcie-intel-gw driver had no .start_link() callback. Add one so the driver works again and does not abort with the following error messages during probing:
intel-gw-pcie d1000000.pcie: host bridge /soc/pcie@d1000000 ranges:
intel-gw-pcie d1000000.pcie: MEM 0x00dc000000..0x00ddffffff -> 0x00dc000000
intel-combo-phy d0c00000.combo-phy: Set combo mode: combophy[1]: mode: PCIe single lane mode intel-gw-pcie d1000000.pcie: No outbound iATU found
intel-gw-pcie d1000000.pcie: Cannot initialize host
intel-gw-pcie d1000000.pcie: probe with driver intel-gw-pcie failed with error -22 intel-gw-pcie c1100000.pcie: host bridge /soc/pcie@c1100000 ranges:
intel-gw-pcie c1100000.pcie: MEM 0x00ce000000..0x00cfffffff -> 0x00ce000000
intel-combo-phy c0c00000.combo-phy: Set combo mode: combophy[3]: mode: PCIe single lane mode intel-gw-pcie c1100000.pcie: No outbound iATU found
intel-gw-pcie c1100000.pcie: Cannot initialize host
intel-gw-pcie c1100000.pcie: probe with driver intel-gw-pcie failed with error -22
--- drivers/pci/controller/dwc/pcie-intel-gw.c | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/pci/controller/dwc/pcie-intel-gw.c +11 -13
@@ -285,6 +285,16 @@ static void intel_pcie_turn_off(struct intel_pcie *pcie)pcie_rc_cfg_wr_mask (pcie,PCI_COMMAND ,PCI_COMMAND_MEMORY ,0 ); } +static int intel_pcie_start_link (struct dw_pcie *pci) +{ +struct intel_pcie *pcie =dev_get_drvdata (pci->dev); + +intel_pcie_device_rst_deassert (pcie); +intel_pcie_ltssm_enable (pcie); + +return 0 ; +} +static int intel_pcie_host_setup (struct intel_pcie *pcie) {int ret;
@@ -311,25 +321,12 @@ static int intel_pcie_host_setup(struct intel_pcie *pcie)intel_pcie_link_setup (pcie);intel_pcie_init_n_fts (pci); - ret =dw_pcie_setup_rc (&pci->pp); -if (ret) - goto err; -dw_pcie_upconfig_setup (pci); -intel_pcie_device_rst_deassert (pcie); -intel_pcie_ltssm_enable (pcie); - - ret =dw_pcie_wait_for_link (pci); -if (ret) - goto err; -intel_pcie_core_irq_enable (pcie);return 0 ; -err: -phy_exit (pcie->phy); phy_err:clk_disable_unprepare (pcie->core_clk); clk_err:
@@ -387,6 +384,7 @@ static int intel_pcie_rc_init(struct dw_pcie_rp *pp) }static const struct dw_pcie_ops intel_pcie_ops = { + .start_link = intel_pcie_start_link, };static const struct dw_pcie_host_ops intel_pcie_dw_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 858/2077 PCI: loongson: Do not ignore downstream devices on external bridges
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rong Zhang <[email protected]>
[ Upstream commit 1389ab9bf9f627d4daed86f492091b00f110aa86 ]
Loongson PCI host controllers have a hardware quirk that requires software to ignore downstream devices with device number > 0 on the internal bridges. The current implementation applies the workaround to all non-root buses, which breaks external bridges (e.g., PCIe switches) with multiple downstream devices.
Fix it by only applying the workaround to internal bridges.
Tested on Loongson-LS3A4000-7A1000-NUC-SE, using AMD Promontory 21 chipset add-in card [1].
$ lspci -tnnnvvv
-[0000:00]-+-00.0 Loongson Technology LLC 7A1000 Chipset Hyper Transport Bridge Controller [0014:7a00]
+-00.1 Loongson Technology LLC 7A2000 Chipset Hyper Transport Bridge Controller [0014:7a10]
+-03.0 Loongson Technology LLC 2K1000/2000 / 7A1000 Chipset Gigabit Ethernet Controller [0014:7a03]
+-04.0 Loongson Technology LLC 2K1000 / 7A1000/2000 Chipset USB OHCI Controller [0014:7a24]
+-04.1 Loongson Technology LLC 2K1000 / 7A1000/2000 Chipset USB EHCI Controller [0014:7a14]
+-05.0 Loongson Technology LLC 2K1000 / 7A1000/2000 Chipset USB OHCI Controller [0014:7a24]
+-05.1 Loongson Technology LLC 2K1000 / 7A1000/2000 Chipset USB EHCI Controller [0014:7a14]
+-06.0 Loongson Technology LLC 7A1000 Chipset Vivante GC1000 GPU [0014:7a15]
+-06.1 Loongson Technology LLC 2K1000 / 7A1000 Chipset Display Controller [0014:7a06]
+-07.0 Loongson Technology LLC 2K1000/2000/3000 / 3B6000M / 7A1000/2000 Chipset HD Audio Controller [0014:7a07]
+-08.0 Loongson Technology LLC 2K1000 / 7A1000 Chipset 3Gb/s SATA AHCI Controller [0014:7a08]
+-08.1 Loongson Technology LLC 2K1000 / 7A1000 Chipset 3Gb/s SATA AHCI Controller [0014:7a08]
+-08.2 Loongson Technology LLC 2K1000 / 7A1000 Chipset 3Gb/s SATA AHCI Controller [0014:7a08]
+-09.0-[01]----00.0 Qualcomm Technologies, Inc QCNFA765 Wireless Network Adapter [17cb:1103]
+-0a.0-[02]----00.0 Etron Technology, Inc. EJ188/EJ198 USB 3.0 Host Controller [1b6f:7052]
+-0f.0-[03-08]----00.0-[04-08]--+-00.0-[05]----00.0 Shenzhen Longsys Electronics Co., Ltd. FORESEE XP1000 / Lexar Professional CFexpress Type B Gold series, NM620 PCIe NVME SSD (DRAM-less) [1d97:5216]
| +-08.0-[06]----00.0 MAXIO Technology (Hangzhou) Ltd. NVMe SSD Controller MAP1202 (DRAM-less) [1e4b:1202]
| +-0c.0-[07]----00.0 Advanced Micro Devices, Inc. [AMD] 600 Series Chipset USB 3.2 Controller [1022:43f7]
| \-0d.0-[08]----00.0 Advanced Micro Devices, Inc. [AMD] 600 Series Chipset SATA Controller [1022:43f6]
\-16.0 Loongson Technology LLC 7A1000 Chipset SPI Controller [0014:7a0b]--- drivers/pci/controller/pci-loongson.c | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-)
drivers/pci/controller/pci-loongson.c +16 -15
@@ -80,6 +80,18 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LOONGSON,DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_LOONGSON ,DEV_LS7A_LPC , system_bus_quirk); +static const struct pci_device_id loongson_internal_bridge_devids[] = { + {PCI_VDEVICE (LOONGSON ,DEV_LS2K_PCIE_PORT0 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT0 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT1 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT2 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT3 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT4 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT5 ) }, + {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT6 ) }, + {0 , }, +}; +/* * Some Loongson PCIe ports have hardware limitations on their Maximum Read * Request Size. They can't handle anything larger than this. Sane
@@ -92,24 +104,13 @@ static void loongson_set_min_mrrs_quirk(struct pci_dev *pdev) {struct pci_bus *bus = pdev->bus;struct pci_dev *bridge; -static const struct pci_device_id bridge_devids[] = { - {PCI_VDEVICE (LOONGSON ,DEV_LS2K_PCIE_PORT0 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT0 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT1 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT2 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT3 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT4 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT5 ) }, - {PCI_VDEVICE (LOONGSON ,DEV_LS7A_PCIE_PORT6 ) }, - {0 , }, - };/* look for the matching bridge */ while (!pci_is_root_bus (bus)) { bridge = bus->self; bus = bus->parent; -if (pci_match_id (bridge_devids, bridge)) { +if (pci_match_id (loongson_internal_bridge_devids, bridge)) {if (pcie_get_readrq (pdev) >256 ) {pci_info (pdev,"limiting MRRS to 256\n" );pcie_set_readrq (pdev,256 );
@@ -266,11 +267,11 @@ static void __iomem *pci_loongson_map_bus(struct pci_bus *bus,struct loongson_pci *priv =pci_bus_to_loongson_pci (bus);/* -* Do not read more than one device on the bus other than -* the host bus. +* Do not read more than one device on the internal bridges. */ if ((priv->data->flags &FLAG_DEV_FIX ) && bus->self) { -if (!pci_is_root_bus (bus) && (device >0 )) +if (!pci_is_root_bus (bus) && (device >0 ) && +pci_match_id (loongson_internal_bridge_devids, bus->self))return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 859/2077 rust: alloc: fix assert in `Vec::reserve` doc test
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hsiu Che Yu <[email protected]>
[ Upstream commit 75619f2df7a5da6ffb61eedc2a73fdf70c65471c ]
The assert in the doctest used >= 10, which only checks that the capacity can hold additional elements, ignoring the existing length of v. The correct check should ensure there is room for additional *extra* elements on top of what is already in the vector.
Fix the assert to use >= v.len() + 10 so the example accurately reflects the actual semantics of the function.
--- rust/kernel/alloc/kvec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/alloc/kvec.rs +1 -1
@@ -614,7 +614,7 @@ where/// /// v.reserve(10, GFP_KERNEL)?; /// let cap = v.capacity(); -/// assert!(cap >= 10); +/// assert!(cap >= v.len() + 10); /// /// v.reserve(10, GFP_KERNEL)?; /// let new_cap = v.capacity();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 860/2077 bus: mhi: ep: Fix potential deadlock in mhi_ep_reset_worker()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sumit Kumar <[email protected]>
[ Upstream commit 9dece4435d396e9877e27483552b910ba8654169 ]
There is a potential deadlock scenario in mhi_ep_reset_worker() where the state_lock mutex is acquired twice in the same call chain:
mhi_ep_reset_worker()
mutex_lock(&mhi_cntrl->state_lock)
mhi_ep_power_up()
mhi_ep_set_ready_state()
mutex_lock(&mhi_cntrl->state_lock) <- DeadlockFix this by releasing the state_lock before calling mhi_ep_power_up(). The lock is only needed to protect current MHI state read operation. The lock can be safely released before proceeding with the power up sequence.
--- drivers/bus/mhi/ep/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/bus/mhi/ep/main.c +3 -4
@@ -1087,11 +1087,12 @@ static void mhi_ep_reset_worker(struct work_struct *work)mhi_ep_power_down (mhi_cntrl); -mutex_lock (&mhi_cntrl->state_lock); -/* Reset MMIO to signal host that the MHI_RESET is completed in endpoint */ mhi_ep_mmio_reset (mhi_cntrl); + +mutex_lock (&mhi_cntrl->state_lock); cur_state = mhi_cntrl->mhi_state; +mutex_unlock (&mhi_cntrl->state_lock);/* * Only proceed further if the reset is due to SYS_ERR. The host will
@@ -1100,8 +1101,6 @@ static void mhi_ep_reset_worker(struct work_struct *work)*/ if (cur_state ==MHI_STATE_SYS_ERR )mhi_ep_power_up (mhi_cntrl); - -mutex_unlock (&mhi_cntrl->state_lock); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 861/2077 bus: mhi: ep: Add missing state_lock protection for mhi_state access
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sumit Kumar <[email protected]>
[ Upstream commit ce3e534ee9c8d13a68c8a611c3b7bd0c2152d2ab ]
The mhi_cntrl->mhi_state field should be protected by state_lock to ensure atomic state transitions. However, mhi_ep_power_up() access mhi_state without holding this lock, which can race with concurrent state transitions and lead to state corruption.
Add proper state_lock protection around mhi_state access.
--- drivers/bus/mhi/ep/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bus/mhi/ep/main.c +2 -0
@@ -1147,7 +1147,9 @@ int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl)for (i =0 ; i < mhi_cntrl->event_rings; i++)mhi_ep_ring_init (&mhi_cntrl->mhi_event[i].ring,RING_TYPE_ER , i); +mutex_lock (&mhi_cntrl->state_lock); mhi_cntrl->mhi_state =MHI_STATE_RESET ; +mutex_unlock (&mhi_cntrl->state_lock);/* Set AMSS EE before signaling ready state */ mhi_ep_mmio_set_env (mhi_cntrl,MHI_EE_AMSS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 862/2077 coresight: fix missing error code when trace ID is invalid
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jie Gan <[email protected]>
[ Upstream commit f4526ffee6ff9f5845b430957417149eded74bf3 ]
When coresight_path_assign_trace_id() cannot assign a valid trace ID, coresight_enable_sysfs() takes the err_path goto with ret still 0, returning success to the caller despite no trace session being started.
Change coresight_path_assign_trace_id() to return int, moving the IS_VALID_CS_TRACE_ID() check inside it so it returns -EINVAL on failure and 0 on success. Update both callers to propagate this return value directly instead of inspecting path->trace_id after the call.
--- drivers/hwtracing/coresight/coresight-core.c | 23 +++++++++++-------- .../hwtracing/coresight/coresight-etm-perf.c | 5 ++-- drivers/hwtracing/coresight/coresight-priv.h | 2 +- drivers/hwtracing/coresight/coresight-sysfs.c | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-)
drivers/hwtracing/coresight/coresight-core.c +13 -10
@@ -739,8 +739,8 @@ static int coresight_get_trace_id(struct coresight_device *csdev,* Call this after creating the path and before enabling it. This leaves * the trace ID set on the path, or it remains 0 if it couldn't be assigned. */ -void coresight_path_assign_trace_id (struct coresight_path *path, -enum cs_mode mode) +int coresight_path_assign_trace_id (struct coresight_path *path, +enum cs_mode mode) {struct coresight_device *sink =coresight_get_sink (path);struct coresight_node *nd;
@@ -750,15 +750,18 @@ void coresight_path_assign_trace_id(struct coresight_path *path,/* Assign a trace ID to the path for the first device that wants to do it */ trace_id =coresight_get_trace_id (nd->csdev, mode, sink); -/* -* 0 in this context is that it didn't want to assign so keep searching. -* Non 0 is either success or fail. -*/ -if (trace_id !=0 ) { - path->trace_id = trace_id; -return ; - } +/* 0 means the device has no ID assignment, so keep searching */ +if (trace_id ==0 ) +continue ; + +if (!IS_VALID_CS_TRACE_ID (trace_id)) +return -EINVAL ; + + path->trace_id = trace_id; +return 0 ; } + +return -EINVAL ; }/**
drivers/hwtracing/coresight/coresight-etm-perf.c +3 -2
@@ -324,6 +324,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,struct coresight_device *sink =NULL ;struct coresight_device *user_sink =NULL , *last_sink =NULL ;struct etm_event_data *event_data =NULL ; +int ret; event_data =alloc_event_data (cpu);if (!event_data)
@@ -420,8 +421,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ -coresight_path_assign_trace_id (path,CS_MODE_PERF ); -if (!IS_VALID_CS_TRACE_ID (path->trace_id)) { + ret =coresight_path_assign_trace_id (path,CS_MODE_PERF ); +if (ret) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);continue ;
drivers/hwtracing/coresight/coresight-priv.h +1 -1
@@ -153,7 +153,7 @@ int coresight_make_links(struct coresight_device *orig,void coresight_remove_links (struct coresight_device *orig,struct coresight_connection *conn);u32 coresight_get_sink_id (struct coresight_device *csdev); -void coresight_path_assign_trace_id (struct coresight_path *path, +int coresight_path_assign_trace_id (struct coresight_path *path,enum cs_mode mode);#if IS_ENABLED (CONFIG_CORESIGHT_SOURCE_ETM3X )
drivers/hwtracing/coresight/coresight-sysfs.c +2 -2
@@ -211,8 +211,8 @@ int coresight_enable_sysfs(struct coresight_device *csdev) goto out; } -coresight_path_assign_trace_id (path,CS_MODE_SYSFS ); -if (!IS_VALID_CS_TRACE_ID (path->trace_id)) + ret =coresight_path_assign_trace_id (path,CS_MODE_SYSFS ); +if (ret) goto err_path; ret =coresight_enable_path (path,CS_MODE_SYSFS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 863/2077 clk: qcom: cmnpll: Account for reference clock divider
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luo Jie <[email protected]>
[ Upstream commit 88c543fff756450bcd04ec4560c4440be36c9e75 ]
The clk_cmn_pll_recalc_rate() function must account for the reference clock divider programmed in CMN_PLL_REFCLK_CONFIG. Without this fix, platforms with a reference divider other than 1 calculate incorrect CMN PLL rates. For example, on IPQ5332 where the reference divider is 2, the computed rate becomes twice the actual output.
Read CMN_PLL_REFCLK_DIV and divide the parent rate by this value before applying the 2 * FACTOR scaling. This yields the correct rate calculation:
rate = (parent_rate / ref_div) * 2 * factor.
Maintain backward compatibility with earlier platforms (e.g. IPQ9574, IPQ5424, IPQ5018) that use ref_div = 1.
--- drivers/clk/qcom/ipq-cmn-pll.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/clk/qcom/ipq-cmn-pll.c +9 -2
@@ -199,7 +199,7 @@ static unsigned long clk_cmn_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) {struct clk_cmn_pll *cmn_pll =to_clk_cmn_pll (hw); -u32 val, factor; +u32 val, factor, ref_div;/* * The value of CMN_PLL_DIVIDER_CTRL_FACTOR is automatically adjusted
@@ -207,8 +207,15 @@ static unsigned long clk_cmn_pll_recalc_rate(struct clk_hw *hw,*/ regmap_read (cmn_pll->regmap,CMN_PLL_DIVIDER_CTRL , &val); factor =FIELD_GET (CMN_PLL_DIVIDER_CTRL_FACTOR , val); +if (WARN_ON (factor ==0 )) + factor =1 ; -return parent_rate *2 * factor; +regmap_read (cmn_pll->regmap,CMN_PLL_REFCLK_CONFIG , &val); + ref_div =FIELD_GET (CMN_PLL_REFCLK_DIV , val); +if (WARN_ON (ref_div ==0 )) + ref_div =1 ; + +return div_u64 ((u64 )parent_rate *2 * factor, ref_div); } static int clk_cmn_pll_determine_rate(struct clk_hw *hw,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 864/2077 dt-bindings: clock: qcom,sm6125-dispcc: reference qcom,gcc.yaml
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Biswapriyo Nath <[email protected]>
[ Upstream commit dbabf6a32ffb69a604f966ec01a20a060836939d ]
Just like most of Qualcomm clock controllers, we can reference common qcom,gcc.yaml schema to unify the common parts of the binding. This also adds the '#reset-cells' property which is permitted for the SM6125 SoC clock controllers, but not listed as a valid property.
--- .../bindings/clock/qcom,dispcc-sm6125.yaml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
Documentation/devicetree/bindings/clock/qcom,dispcc-sm6125.yaml +5 -12
@@ -42,12 +42,6 @@ properties: - const: cfg_ahb_clk - const: gcc_disp_gpll0_div_clk_src - '#clock-cells': - const: 1 - - '#power-domain-cells': - const: 1 - power-domains: description: A phandle and PM domain specifier for the CX power domain.
@@ -58,18 +52,16 @@ properties: A phandle to an OPP node describing the power domain's performance point. maxItems: 1 - reg: - maxItems: 1 - required: - compatible - - reg - clocks - clock-names - - '#clock-cells' - '#power-domain-cells' -additionalProperties: false +allOf: + - $ref: qcom,gcc.yaml# + +unevaluatedProperties: false examples: - |
@@ -101,6 +93,7 @@ examples: power-domains = <&rpmpd SM6125_VDDCX>; #clock-cells = <1>; + #reset-cells = <1>; #power-domain-cells = <1>; }; ...
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 865/2077 PCI: dwc: Apply ECRC workaround for DesignWare cores prior to 5.10a
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manikanta Maddireddy <[email protected]>
[ Upstream commit 1e1b554c2b910591aa3fffdb8077a2ca33bf3cb2 ]
The ECRC (TLP digest) workaround was originally applied only for DesignWare core version 4.90a. Per discussion in Synopsys case, the dependency of the iATU TD bit on ECRC generation was removed in 5.10a, so apply the workaround for all DWC versions below that release.
Replace the misleading comment that referred to raw version constants with readable DesignWare release name to help readability.
--- drivers/pci/controller/dwc/pcie-designware.c | 16 ++++++++-------- drivers/pci/controller/dwc/pcie-designware.h | 1 + 2 files changed, 9 insertions(+), 8 deletions(-)
drivers/pci/controller/dwc/pcie-designware.c +8 -8
@@ -487,13 +487,13 @@ static inline void dw_pcie_writel_atu_ob(struct dw_pcie *pci, u32 index, u32 regstatic inline u32 dw_pcie_enable_ecrc (u32 val) {/* -* DWC versions 0x3530302a and 0x3536322a have a design issue where -* the 'TD' bit in the Control register-1 of the ATU outbound -* region acts like an override for the ECRC setting, i.e., the -* presence of TLP Digest (ECRC) in the outgoing TLPs is solely -* determined by this bit. This is contrary to the PCIe spec which -* says that the enablement of the ECRC is solely determined by the -* AER registers. +* DesignWare core versions prior to 5.10A have a design issue where the +* 'TD' bit in the Control register-1 of the ATU outbound region acts +* like an override for the ECRC setting, i.e., the presence of TLP +* Digest (ECRC) in the outgoing TLPs is solely determined by this +* bit. This is contrary to the PCIe spec which says that the +* enablement of the ECRC is solely determined by the AER +* registers. * * Because of this, even when the ECRC is enabled through AER * registers, the transactions going through ATU won't have TLP
@@ -563,7 +563,7 @@ int dw_pcie_prog_outbound_atu(struct dw_pcie *pci,if (upper_32_bits (limit_addr) >upper_32_bits (parent_bus_addr) && dw_pcie_ver_is_ge(pci, 460A)) val |=PCIE_ATU_INCREASE_REGION_SIZE ; - if (dw_pcie_ver_is(pci, 490A) || dw_pcie_ver_is(pci, 500A)) + if (!dw_pcie_ver_is_ge(pci, 510A)) val =dw_pcie_enable_ecrc (val);dw_pcie_writel_atu_ob (pci, atu->index,PCIE_ATU_REGION_CTRL1 , val);
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -35,6 +35,7 @@#define DW_PCIE_VER_480A 0x3438302a#define DW_PCIE_VER_490A 0x3439302a#define DW_PCIE_VER_500A 0x3530302a +#define DW_PCIE_VER_510A 0x3531302a#define DW_PCIE_VER_520A 0x3532302a#define DW_PCIE_VER_540A 0x3534302a#define DW_PCIE_VER_562A 0x3536322a
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 866/2077 PCI: qcom: Set max OPP before DBI access during resume
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiang Yu <[email protected]>
[ Upstream commit 5dc31cd4a91a7f006d23efa97a5594a7e3ac7790 ]
During resume, qcom_pcie_icc_opp_update() may access DBI registers before the OPP votes are restored, triggering NoC errors.
Set the PCIe controller to the maximum OPP first in resume_noirq(), then proceed with link/DBI accesses. The OPP is later updated again based on the actual link bandwidth requirements.
Introduce a helper to reuse the max-OPP setup code and share it with probe().
--- drivers/pci/controller/dwc/pcie-qcom.c | 42 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-)
drivers/pci/controller/dwc/pcie-qcom.c +26 -16
@@ -1613,6 +1613,22 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie) } } +static int qcom_pcie_set_max_opp (struct device *dev) +{ +unsigned long max_freq =ULONG_MAX ; +struct dev_pm_opp *opp; +int ret; + + opp =dev_pm_opp_find_freq_floor (dev, &max_freq); +if (IS_ERR (opp)) +return PTR_ERR (opp); + + ret =dev_pm_opp_set_opp (dev, opp); +dev_pm_opp_put (opp); + +return ret; +} +static int qcom_pcie_link_transition_count (struct seq_file *s,void *data) {struct qcom_pcie *pcie = (struct qcom_pcie *)dev_get_drvdata (s->private);
@@ -1851,9 +1867,7 @@ static int qcom_pcie_probe(struct platform_device *pdev)struct qcom_pcie_perst *perst, *tmp_perst;struct qcom_pcie_port *port, *tmp_port;const struct qcom_pcie_cfg *pcie_cfg; -unsigned long max_freq =ULONG_MAX ;struct device *dev = &pdev->dev; -struct dev_pm_opp *opp;struct qcom_pcie *pcie;struct dw_pcie_rp *pp;struct resource *res;
@@ -1957,21 +1971,9 @@ static int qcom_pcie_probe(struct platform_device *pdev)* probe(), OPP will be updated using qcom_pcie_icc_opp_update(). */ if (!ret) { - opp =dev_pm_opp_find_freq_floor (dev, &max_freq); -if (IS_ERR (opp)) { - ret =PTR_ERR (opp); -dev_err_probe (pci->dev, ret, -"Unable to find max freq OPP\n" ); - goto err_pm_runtime_put; - }else { - ret =dev_pm_opp_set_opp (dev, opp); - } - -dev_pm_opp_put (opp); + ret =qcom_pcie_set_max_opp (dev);if (ret) { -dev_err_probe (pci->dev, ret, -"Failed to set OPP for freq %lu\n" , - max_freq); +dev_err_probe (dev, ret,"Failed to set max OPP\n" ); goto err_pm_runtime_put; }
@@ -2106,6 +2108,14 @@ static int qcom_pcie_resume_noirq(struct device *dev)return 0 ;if (pm_suspend_target_state !=PM_SUSPEND_MEM ) { +if (pcie->use_pm_opp) { + ret =qcom_pcie_set_max_opp (dev); +if (ret) { +dev_err (dev,"Failed to set max OPP: %d\n" , ret); +return ret; + } + } + ret =icc_enable (pcie->icc_cpu);if (ret) {dev_err (dev,"Failed to enable CPU-PCIe interconnect path: %d\n" , ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 867/2077 phy: phy-can-transceiver: Check driver match and driver data against NULL
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit ebee9004cc0200b2b708ebf7ac625d35c71c049f ]
Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override() so platform drivers that rely on the existence of a device's driver data need to verify its presence.
Accordingly, add requisite match and driver data checks against NULL to the driver where they are missing.
--- drivers/phy/phy-can-transceiver.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/phy/phy-can-transceiver.c +3 -0
@@ -162,6 +162,9 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)int err, i, num_ch =1 ; match =of_match_node (can_transceiver_phy_ids, pdev->dev.of_node); +if (!match || !match->data) +return -ENODEV ; + drvdata = match->data;if (drvdata->flags &CAN_TRANSCEIVER_DUAL_CH ) num_ch =2 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 868/2077 perf pmu-events AMD: Switch l2_itlb_misses to bp_l1_tlb_miss_l2_tlb_miss.all
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 41a543c86d110073275e5294852d692e5faf6b3b ]
l2_itlb_misses is a valid legacy cache event name, hence allowing it in all_events in metric.py. l2_itlb_misses was also a json event for AMD zen1, zen2 and zen3.
For zen4, zen5 and zen6 the checking that metric events are within the json was skipping l2_itlb_misses as it is a valid legacy event, however, the PMU driver lacks the event mapping causing it to be a bad event when used in the metric.
Add bp_l1_tlb_miss_l2_tlb_miss.all as the l2 itlb miss event (bp = branch predictor, the AMD way to say itlb), so that is used in preference to l2_itlb_misses when the event exists.
Remove l2_itlb_misses from metric.py as the legacy event isn't used by any metrics and having it is error prone for newer AMD zen models.
--- tools/perf/pmu-events/amd_metrics.py | 2 +- tools/perf/pmu-events/metric.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
tools/perf/pmu-events/amd_metrics.py +1 -1
@@ -268,7 +268,7 @@ def AmdDtlb() -> Optional[MetricGroup]: def AmdItlb(): global _zen_model l2h = Event("bp_l1_tlb_miss_l2_tlb_hit", "bp_l1_tlb_miss_l2_hit") - l2m = Event("l2_itlb_misses") + l2m = Event("bp_l1_tlb_miss_l2_tlb_miss.all", "l2_itlb_misses",) l2r = l2h + l2m itlb_l1_mg = None
tools/perf/pmu-events/metric.py +0 -1
@@ -25,7 +25,6 @@ def LoadEvents(directory: str) -> None: "cycles", "duration_time", "instructions", - "l2_itlb_misses", } for file in os.listdir(os.fsencode(directory)): filename = os.fsdecode(file)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 869/2077 perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 4248ae6e799605b3e62855be6085935d89de50d1 ]
Currently, both libdw and libunwind define 'unwind__get_entries'. This causes a duplicate symbol build failure when both are compiled into perf.
This commit refactors the DWARF unwind post-processing to be configurable at runtime via the .perfconfig file option 'unwind.style', or using the argument '--unwind-style' in the commands 'perf report', 'perf script' and 'perf inject', in a similar manner to the addr2line or the disassembler style.
The file 'tools/perf/util/unwind.c' adds the top-level dispatch function 'unwind__get_entries'. The backend implementations are renamed to 'libdw__get_entries' and 'libunwind__get_entries'. Both are attempted as fallbacks if not configured, or if the primary backend fails.
--- tools/perf/builtin-inject.c | 4 + tools/perf/builtin-report.c | 4 + tools/perf/builtin-script.c | 4 + tools/perf/util/Build | 1 + tools/perf/util/config.c | 4 + tools/perf/util/symbol_conf.h | 10 +++ tools/perf/util/unwind-libdw.c | 20 ++++- tools/perf/util/unwind-libunwind-local.c | 27 ++++-- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/unwind.c | 104 +++++++++++++++++++++++ tools/perf/util/unwind.h | 61 ++++++++----- 11 files changed, 208 insertions(+), 33 deletions(-) create mode 100644 tools/perf/util/unwind.c
tools/perf/builtin-inject.c +4 -0
@@ -26,6 +26,7 @@#include "util/synthetic-events.h" #include "util/thread.h" #include "util/namespaces.h" +#include "util/unwind.h" #include "util/util.h" #include "util/tsc.h"
@@ -2563,6 +2564,9 @@ int cmd_inject(int argc, const char **argv)OPT_STRING (0 ,"guestmount" , &symbol_conf.guestmount,"directory" ,"guest mount directory under which every guest os" " instance has a subdir" ), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_BOOLEAN (0 ,"convert-callchain" , &inject.convert_callchain,"Generate callchains using DWARF and drop register/stack data" ),OPT_END ()
tools/perf/builtin-report.c +4 -0
@@ -48,6 +48,7 @@#include "util/time-utils.h" #include "util/auxtrace.h" #include "util/units.h" +#include "util/unwind.h" #include "util/util.h" // perf_tip() #include "ui/ui.h" #include "ui/progress.h"
@@ -1449,6 +1450,9 @@ int cmd_report(int argc, const char **argv)OPT_CALLBACK (0 ,"addr2line-style" ,NULL ,"addr2line style" ,"addr2line styles (libdw,llvm,libbfd,addr2line)" , report_parse_addr2line_config), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_BOOLEAN (0 ,"demangle" , &symbol_conf.demangle,"Symbol demangling. Enabled by default, use --no-demangle to disable." ), OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
tools/perf/builtin-script.c +4 -0
@@ -63,6 +63,7 @@#include <linux/err.h> #include "util/dlfilter.h" #include "util/record.h" +#include "util/unwind.h" #include "util/util.h" #include "util/cgroup.h" #include "util/annotate.h"
@@ -4159,6 +4160,9 @@ int cmd_script(int argc, const char **argv) "Enable symbol demangling"),OPT_BOOLEAN (0 ,"demangle-kernel" , &symbol_conf.demangle_kernel,"Enable kernel symbol demangling" ), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_STRING (0 ,"addr2line" , &symbol_conf.addr2line_path,"path" ,"addr2line binary to use for line numbers" ), OPT_STRING(0, "time", &script.time_str, "str",
tools/perf/util/Build +1 -0
@@ -216,6 +216,7 @@ ifndef CONFIG_SETNS perf-util-y += setns.o endif +perf-util-y += unwind.o perf-util-$(CONFIG_LIBDW) += probe-finder.o perf-util-$(CONFIG_LIBDW) += dwarf-aux.o perf-util-$(CONFIG_LIBDW) += dwarf-regs.o
tools/perf/util/config.c +4 -0
@@ -23,6 +23,7 @@#include "build-id.h" #include "debug.h" #include "config.h" +#include "unwind.h" #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h>
@@ -525,6 +526,9 @@ int perf_default_config(const char *var, const char *value,if (strstarts (var,"addr2line." ))return addr2line_configure (var, value, dummy); +if (strstarts (var,"unwind." )) +return unwind__configure (var, value, dummy); +/* Add other config variables here. */ return 0 ; }
tools/perf/util/symbol_conf.h +10 -0
@@ -9,6 +9,15 @@struct strlist ;struct intlist ; +enum unwind_style { +UNWIND_STYLE_UNKNOWN =0 , +UNWIND_STYLE_LIBDW , +UNWIND_STYLE_LIBUNWIND , +}; + +#define MAX_UNWIND_STYLE (UNWIND_STYLE_LIBUNWIND + 1) + +enum a2l_style {A2L_STYLE_UNKNOWN =0 ,A2L_STYLE_LIBDW ,
@@ -81,6 +90,7 @@ struct symbol_conf {const char *addr2line_path;enum a2l_style addr2line_style[MAX_A2L_STYLE ];int addr2line_timeout_ms; +enum unwind_style unwind_style[MAX_UNWIND_STYLE ];unsigned long time_quantum;struct strlist *dso_list, *comm_list,
tools/perf/util/unwind-libdw.c +16 -4
@@ -339,7 +339,7 @@ frame_callback(Dwfl_Frame *state, void *arg) DWARF_CB_ABORT :DWARF_CB_OK ; } -int unwind__get_entries(unwind_entry_cb_t cb, void *arg, +int libdw__get_entries(unwind_entry_cb_t cb, void *arg, struct thread *thread, struct perf_sample *data, int max_stack,
@@ -353,10 +353,10 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,static struct unwind_info *ui;Dwfl *dwfl;Dwarf_Word ip; -int err = -EINVAL , i; +int err = -EINVAL , i, entries;if (!data->user_regs || !data->user_regs->regs) -return -EINVAL ; +return 0 ; ui =zalloc (sizeof (*ui) +sizeof (ui->entries[0 ]) * max_stack);if (!ui)
@@ -430,6 +430,18 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,map_symbol__exit (&ui->entries[i].ms); dwfl_ui_ti->ui =NULL ; + entries = (int )ui->idx;free (ui); -return 0 ; +/* +* Unwinder return contract: +* > 0 : unwinding succeeded (stops fallback). If we found frames but hit an error +* (e.g. truncated stack), report success to preserve existing frames. +* 0 : unwinding failed without yielding frames. Ignore non-fatal errors +* (e.g. missing debug info, DWARF corruption) to allow fallback unwinder or +* kernel callchain resolution to proceed. +* < 0 : fatal error (e.g. -ENOMEM). Aborts unwinding entirely. +*/ +if (err) +return (err == -ENOMEM ) ? -ENOMEM : (entries >0 ?1 :0 ); +return entries; }
tools/perf/util/unwind-libunwind-local.c +21 -6
@@ -744,7 +744,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, ret =perf_reg_value (&val,perf_sample__user_regs (ui->sample),perf_arch_reg_ip (e_machine));if (ret) -return ret; +return 0 ; ips[i++] = (unw_word_t ) val;
@@ -757,7 +757,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, addr_space =maps__addr_space (thread__maps (ui->thread));if (addr_space ==NULL ) -return -1 ; +return 0 ; ret =unw_init_remote (&c, addr_space, ui);if (ret && !ui->best_effort)
@@ -785,15 +785,30 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,/* * Display what we got based on the order setup. */ +int entries =0 ;for (i =0 ; i < max_stack && !ret; i++) {int j = i;if (callchain_param.order ==ORDER_CALLER ) j = max_stack - i -1 ; - ret = ips[j] ?entry (ips[j], ui->thread, cb, arg) :0 ; +if (ips[j]) { + ret =entry (ips[j], ui->thread, cb, arg); +if (ret) +break ; + entries++; + } } -return ret; +/* +* Unwinder return contract: +* > 0 : unwinding succeeded (stops fallback). +* 0 : unwinding failed without yielding frames. Ignore non-fatal errors +* (e.g. stepping failure) to allow fallback unwinder or kernel callchains. +* < 0 : fatal error (e.g. -ENOMEM). Aborts unwinding entirely. +*/ +if (ret == -ENOMEM ) +return -ENOMEM ; +return (entries >0 || ret ==0 ) ? entries :0 ; } static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,
@@ -809,10 +824,10 @@ static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg, };if (!data->user_regs || !data->user_regs->regs) -return -EINVAL ; +return 0 ;if (max_stack <=0 ) -return -EINVAL ; +return 0 ;return get_entries (&ui, cb, arg, max_stack); }
tools/perf/util/unwind-libunwind.c +1 -1
@@ -79,7 +79,7 @@ void unwind__finish_access(struct maps *maps) ops->finish_access (maps); } -int unwind__get_entries (unwind_entry_cb_t cb,void *arg, +int libunwind__get_entries (unwind_entry_cb_t cb,void *arg,struct thread *thread,struct perf_sample *data,int max_stack,bool best_effort)
tools/perf/util/unwind.c new file +104 -0
104 lines not on this page · raw message
tools/perf/util/unwind.h +39 -22
93 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 870/2077 perf pmu: Skip test on Arm64 when #slots is zero
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit 2e2ba7d1ea554ee6e9e751a53eebf3e9270b0670 ]
Some Arm64 PMUs expose 'caps/slots' as 0 when the slot count is not implemented, tool_pmu__read_event() currently returns false for this, so metrics that reference #slots are reported as syntax error.
Since the commit 3a61fd866ef9 ("perf expr: Return -EINVAL for syntax error in expr__find_ids()"), these syntax errors are populated as failures and make the PMU metric test fail:
9.3: Parsing of PMU event table metrics:
--- start ---
...
Found metric 'backend_bound'
metric expr 100 * (stall_slot_backend / (#slots * cpu_cycles)) for backend_bound parsing metric: 100 * (stall_slot_backend / (#slots * cpu_cycles)) Failure to read '#slots'
literal: #slots = nan
syntax error
Fail to parse metric or group `backend_bound'
...
---- end(-1) ----
9.3: Parsing of PMU event table metrics : FAILED!
This commit introduces a new function is_expected_broken_metric() to identify broken metrics, and treats metrics containing "#slots" as expected broken when #slots == 0 on Arm64 platforms.
--- tools/perf/tests/pmu-events.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
tools/perf/tests/pmu-events.c +22 -2
@@ -15,6 +15,7 @@#include "util/expr.h" #include "util/hashmap.h" #include "util/parse-events.h" +#include "util/tool_pmu.h" #include "metricgroup.h" #include "stat.h"
@@ -817,6 +818,26 @@ struct metric {struct metric_ref metric_ref; }; +static bool is_expected_broken_metric (const struct pmu_metric *pm) +{ +if (!strcmp (pm->metric_name,"M1" ) || !strcmp (pm->metric_name,"M2" ) || + !strcmp (pm->metric_name,"M3" )) +return true; + +#if defined(__aarch64__) +/* +* Arm64 platforms may return "#slots == 0", which is treated as a +* syntax error by the parser. Don't test these metrics when running +* on such platforms. +*/ +if (strstr (pm->metric_expr,"#slots" ) && + !tool_pmu__cpu_slots_per_cycle ()) +return true; +#endif + +return false; +} +static int test__parsing_callback (const struct pmu_metric *pm,const struct pmu_metrics_table *table,void *data)
@@ -852,8 +873,7 @@ static int test__parsing_callback(const struct pmu_metric *pm, err =metricgroup__parse_groups_test (evlist, table, pm->metric_name);if (err) { -if (!strcmp (pm->metric_name,"M1" ) || !strcmp (pm->metric_name,"M2" ) || - !strcmp (pm->metric_name,"M3" )) { +if (is_expected_broken_metric (pm)) { (*failures)--;pr_debug ("Expected broken metric %s skipping\n" , pm->metric_name); err =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 871/2077 clk: at91: sam9x7: Fix gmac_gclk clock definition
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mihai Sain <[email protected]>
[ Upstream commit b6f6ebb0fb57ae6da622fb8fd4ebdc9ba1ae5756 ]
According to the datasheet (see link section), table 12.1, instance ID 24 is used for the GMAC generic clock, while instance ID 67 is reserved. Add the correct gmac_gclk entry at ID 24, aligned with the SoC clock layout, and remove the old misplaced entry at ID 67.
--- drivers/clk/at91/sam9x7.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/clk/at91/sam9x7.c +9 -9
@@ -569,6 +569,15 @@ static const struct { .pp_chg_id = INT_MIN, }, + { + .n = "gmac_gclk", + .id = 24, + .pp = { "audiopll_divpmcck", "plla_div2pmcck", }, + .pp_mux_table = { 6, 8, }, + .pp_count =2 , + .pp_chg_id = INT_MIN, + }, + { .n ="lcd_gclk" , .id = 25,
@@ -702,15 +711,6 @@ static const struct { .pp_count = 1, .pp_chg_id = INT_MIN, }, - - { - .n = "gmac_gclk", - .id = 67, - .pp = { "audiopll_divpmcck", "plla_div2pmcck", }, - .pp_mux_table = { 6, 8, }, - .pp_count = 2, - .pp_chg_id = INT_MIN, - }, };static void __init sam9x7_pmc_setup (struct device_node *np)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 872/2077 iio: light: acpi-als: Check ACPI_COMPANION() against NULL
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit ff29241030eb6f4505d903d87c29f51c1866a95d ]
Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.
Accordingly, add a requisite ACPI_COMPANION() check against NULL to the acpi-als IIO driver.
--- drivers/iio/light/acpi-als.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/light/acpi-als.c +5 -1
@@ -179,11 +179,15 @@ static irqreturn_t acpi_als_trigger_handler(int irq, void *p)static int acpi_als_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct acpi_device *device =ACPI_COMPANION (dev); +struct acpi_device *device;struct iio_dev *indio_dev;struct acpi_als *als;int ret; + device =ACPI_COMPANION (dev); +if (!device) +return -ENODEV ; + indio_dev =devm_iio_device_alloc (dev,sizeof (*als));if (!indio_dev)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 873/2077 soundwire: intel_ace2x: release bpt_stream when close it
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bard Liao <[email protected]>
[ Upstream commit 8a7fe10eec64bfb7cf4091bca540de4c55d56bfa ]
The BPT stream was allocated in intel_ace2x_bpt_open_stream(), we need to free it in intel_ace2x_bpt_close_stream().
--- drivers/soundwire/intel_ace2x.c | 1 + 1 file changed, 1 insertion(+)
drivers/soundwire/intel_ace2x.c +1 -0
@@ -317,6 +317,7 @@ static void intel_ace2x_bpt_close_stream(struct sdw_intel *sdw, struct sdw_slavedev_err (cdns->dev,"%s: remove slave failed: %d\n" , __func__, ret); +sdw_release_stream (cdns->bus.bpt_stream); cdns->bus.bpt_stream =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 874/2077 coresight: Fix source not disabled on idr_alloc_u32 failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jie Gan <[email protected]>
[ Upstream commit ea2c2b9e2a66e2b4aa0455b2d70058e2f0ea4d23 ]
In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM, OTHERS), the source device is enabled via coresight_enable_source_sysfs() before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the original code jumped directly to err_source, which only calls coresight_disable_path() and coresight_release_path(). The source device was left enabled with an incremented refcnt but no path tracked for it, leaving the device in an inconsistent state.
Disable the source before jumping to err_source so the enable and path operations are fully unwound.
--- drivers/hwtracing/coresight/coresight-sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-sysfs.c +3 -1
@@ -244,8 +244,10 @@ int coresight_enable_sysfs(struct coresight_device *csdev)*/ hash =hashlen_hash (hashlen_string (NULL ,dev_name (&csdev->dev))); ret =idr_alloc_u32 (&path_idr, path, &hash, hash,GFP_KERNEL ); -if (ret) +if (ret) { +coresight_disable_source_sysfs (csdev,NULL ); goto err_source; + }break ;default :/* We can't be here */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 875/2077 coresight: Handle helper enable failure properly
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit 864754d0a084141085f154db044401fb2dce6a34 ]
If a helper fails to be enabled, unwind any helpers that were already enabled earlier in the loop. This avoids leaving partially enabled helpers behind.
--- drivers/hwtracing/coresight/coresight-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-core.c +10 -1
@@ -499,10 +499,19 @@ static int coresight_enable_helpers(struct coresight_device *csdev, ret =coresight_enable_helper (helper, mode, path);if (ret) -return ret; + goto err; }return 0 ; + +err: +while (i--) { + helper = csdev->pdata->out_conns[i]->dest_dev; +if (helper &&coresight_is_helper (helper)) +coresight_disable_helper (helper, path); + } + +return ret; }int coresight_enable_path (struct coresight_path *path,enum cs_mode mode)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 876/2077 PCI: mediatek-gen3: Do full device power down on removal
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit d39d55d7411c18ca6aeb63aafa8035f4ad8b317f ]
When power control for downstream devices was introduced in the mediatek-gen3 PCIe controller driver, only the power to the downstream devices was cut when the controller driver is removed. This matched existing behavior, but in hindsight a proper power down sequence should have been followed.
Call mtk_pcie_devices_power_down() on driver removal so that in addition to removing power from the downstream devices, PERST# is asserted.
--- drivers/pci/controller/pcie-mediatek-gen3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mediatek-gen3.c +1 -1
@@ -1260,7 +1260,7 @@ static void mtk_pcie_remove(struct platform_device *pdev)pci_remove_root_bus (host->bus);pci_unlock_rescan_remove (); -pci_pwrctrl_power_off_devices (pcie->dev); +mtk_pcie_devices_power_down (pcie);mtk_pcie_power_down (pcie);pci_pwrctrl_destroy_devices (pcie->dev);mtk_pcie_irq_teardown (pcie);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 877/2077 mailbox: mpfs: fix check for syscon presence in mpfs_mbox_inbox_isr()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Conor Dooley <[email protected]>
[ Upstream commit e30d8b2730a33e5e8789371e947c3529789a6070 ]
mpfs_mbox_inbox_isr() writes to the sysreg scb syscon, not the control scb syscon, but checks for the presence of the latter. Ultimately this makes little difference because if one syscon is present, both will be.
--- drivers/mailbox/mailbox-mpfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mailbox/mailbox-mpfs.c +1 -1
@@ -201,7 +201,7 @@ static irqreturn_t mpfs_mbox_inbox_isr(int irq, void *data)struct mbox_chan *chan = data;struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv; -if (mbox->control_scb) +if (mbox->sysreg_scb)regmap_write (mbox->sysreg_scb,MESSAGE_INT_OFFSET ,0 );else writel_relaxed (0 , mbox->int_reg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 878/2077 mailbox: mtk-adsp: fix UAF during device teardown
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergey Senozhatsky <[email protected]>
[ Upstream commit b57d1a40bc43258372fa1f4d39305e093947a262 ]
When the SOF audio driver fails to initialize (e.g. firmware boot timeout), its devres unwind frees the snd_sof_dev object that the mailbox client (mtk-adsp-ipc) reaches via chan->cl->rx_callback. The mtk-adsp-mailbox shutdown clears the mailbox command registers but leaves the IRQ line unmasked, so a late interrupt can still queue a threaded handler after mbox_free_channel() had cleared chan->cl, and mbox_chan_received_data() would then trigger UAF:
BUG: KASAN: slab-use-after-free in sof_ipc3_validate_fw_version sof_ipc3_validate_fw_version sof_ipc3_do_rx_work sof_ipc3_rx_msg mt8196_dsp_handle_request mtk_adsp_ipc_recv mbox_chan_received_data mtk_adsp_mbox_isr irq_thread_fn Freed by task ...: kfree devres_release_all really_probe ... (sof-audio-of-mt8196 probe failure)
The crash was observed roughly three seconds after the failed probe.
disable_irq() in shutdown and enable_irq() in startup. disable_irq() also waits for any in-flight interrupts, so by the time mbox_free_channel() proceeds to clear chan->cl no rx_callback can run.
In addition, request the IRQ with IRQF_NO_AUTOEN so it stays masked between probe and the first client bind — otherwise an early interrupt can crash on chan->cl == NULL in mbox_chan_received_data().
--- drivers/mailbox/mtk-adsp-mailbox.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/mailbox/mtk-adsp-mailbox.c +8 -1
@@ -19,6 +19,7 @@ struct mtk_adsp_mbox_priv {struct mbox_controller mbox;void __iomem *va_mboxreg;const struct mtk_adsp_mbox_cfg *cfg; +int irq; };struct mtk_adsp_mbox_cfg {
@@ -67,6 +68,8 @@ static int mtk_adsp_mbox_startup(struct mbox_chan *chan)writel (0xFFFFFFFF , priv->va_mboxreg + priv->cfg->clr_in);writel (0xFFFFFFFF , priv->va_mboxreg + priv->cfg->clr_out); +enable_irq (priv->irq); +return 0 ; }
@@ -74,6 +77,8 @@ static void mtk_adsp_mbox_shutdown(struct mbox_chan *chan) {struct mtk_adsp_mbox_priv *priv =get_mtk_adsp_mbox_priv (chan->mbox); +disable_irq (priv->irq); +/* Clear ADSP mbox command */ writel (0xFFFFFFFF , priv->va_mboxreg + priv->cfg->clr_in);writel (0xFFFFFFFF , priv->va_mboxreg + priv->cfg->clr_out);
@@ -139,8 +144,10 @@ static int mtk_adsp_mbox_probe(struct platform_device *pdev)if (irq <0 )return irq; + priv->irq = irq; ret =devm_request_threaded_irq (dev, irq, mtk_adsp_mbox_irq, - mtk_adsp_mbox_isr,IRQF_TRIGGER_NONE , + mtk_adsp_mbox_isr, +IRQF_TRIGGER_NONE |IRQF_NO_AUTOEN ,dev_name (dev), mbox->chans);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 879/2077 mailbox: dont free the channel if the startup callback failed
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wolfram Sang <[email protected]>
[ Upstream commit 4f176444dcc977d1888fd9220c357a4d32338ee0 ]
If the optional startup() callbacks fails, we need to clear some states. Currently, this is done by freeing the channel. This does, however, more than needed which creates problems. Namely, it is calling the shutdown() callback. This is totally not intuitive. No user expects that shutdown() is called when startup() fails, similar to remove() not being called when probe() fails. Currently, quite some mailbox users register the IRQ in startup() and free them in shutdown(). These drivers will get a WARN about freeing an already free IRQ. Other subtle issues could arise from this unexpected behaviour.
To solve this problem, introduce a helper which does the minimal cleanup and use it in both, in free_channel() and after startup() failed.
--- drivers/mailbox/mailbox.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/mailbox/mailbox.c +15 -11
@@ -327,6 +327,19 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout) }EXPORT_SYMBOL_GPL (mbox_flush); +static void mbox_clean_and_put_channel (struct mbox_chan *chan) +{ +/* The queued TX requests are simply aborted, no callbacks are made */ + scoped_guard(spinlock_irqsave, &chan->lock) { + chan->cl =NULL ; + chan->active_req =MBOX_NO_MSG ; +if (chan->txdone_method ==MBOX_TXDONE_BY_ACK ) + chan->txdone_method =MBOX_TXDONE_BY_POLL ; + } + +module_put (chan->mbox->dev->driver->owner); +} +static int __mbox_bind_client (struct mbox_chan *chan,struct mbox_client *cl) {struct device *dev = cl->dev;
@@ -350,10 +363,9 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)if (chan->mbox->ops->startup) { ret = chan->mbox->ops->startup (chan); -if (ret) {dev_err (dev,"Unable to startup the chan (%d)\n" , ret); -mbox_free_channel (chan); +mbox_clean_and_put_channel (chan);return ret; } }
@@ -495,15 +507,7 @@ void mbox_free_channel(struct mbox_chan *chan)if (chan->mbox->ops->shutdown) chan->mbox->ops->shutdown (chan); -/* The queued TX requests are simply aborted, no callbacks are made */ - scoped_guard(spinlock_irqsave, &chan->lock) { - chan->cl =NULL ; - chan->active_req =MBOX_NO_MSG ; -if (chan->txdone_method ==MBOX_TXDONE_BY_ACK ) - chan->txdone_method =MBOX_TXDONE_BY_POLL ; - } - -module_put (chan->mbox->dev->driver->owner); +mbox_clean_and_put_channel (chan); }EXPORT_SYMBOL_GPL (mbox_free_channel);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 880/2077 PCI/pwrctrl: Lock device when calling device_is_bound()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 548f3d287d92bcbc908b02db57fb889f8a8276a0 ]
The kerneldoc for device_is_bound() states that it must be called with the device lock taken. Synchronize the two calls in pwrctrl core.
--- drivers/pci/pwrctrl/core.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/pci/pwrctrl/core.c +15 -11
@@ -161,10 +161,12 @@ static void pci_pwrctrl_power_off_device(struct device_node *np)if (!pdev)return ; -if (device_is_bound (&pdev->dev)) { - ret =__pci_pwrctrl_power_off_device (&pdev->dev); -if (ret) -dev_err (&pdev->dev,"Failed to power off device: %d" , ret); + scoped_guard(device, &pdev->dev) { +if (device_is_bound (&pdev->dev)) { + ret =__pci_pwrctrl_power_off_device (&pdev->dev); +if (ret) +dev_err (&pdev->dev,"Failed to power off device: %d" , ret); + } }platform_device_put (pdev);
@@ -205,7 +207,7 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)static int pci_pwrctrl_power_on_device (struct device_node *np) {struct platform_device *pdev; -int ret; +int ret =0 ;for_each_available_child_of_node_scoped (np, child) { ret =pci_pwrctrl_power_on_device (child);
@@ -217,12 +219,14 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)if (!pdev)return 0 ; -if (device_is_bound (&pdev->dev)) { - ret =__pci_pwrctrl_power_on_device (&pdev->dev); - }else { -/* FIXME: Use blocking wait instead of probe deferral */ -dev_dbg (&pdev->dev,"driver is not bound\n" ); - ret = -EPROBE_DEFER ; + scoped_guard(device, &pdev->dev) { +if (device_is_bound (&pdev->dev)) { + ret =__pci_pwrctrl_power_on_device (&pdev->dev); + }else { +/* FIXME: Use blocking wait instead of probe deferral */ +dev_dbg (&pdev->dev,"driver is not bound\n" ); + ret = -EPROBE_DEFER ; + } }platform_device_put (pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 881/2077 coresight: platform: defer connection counter increment until alloc succeeds
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jie Gan <[email protected]>
[ Upstream commit 1563ae33dc4f5ebac96b93af2ef72e72aaaa31ae ]
coresight_add_out_conn() increments nr_outconns before calling devm_krealloc_array() and again before devm_kmalloc(). If either allocation fails, the counter is already bumped while the corresponding array entry is NULL or uninitialized garbage.
coresight_add_in_conn() has the same problem with nr_inconns and devm_krealloc_array().
In both cases the probe returns -ENOMEM, which causes coresight_get_platform_data() to call coresight_release_platform_data() for cleanup. That function iterates up to nr_outconns (or nr_inconns) entries and dereferences each pointer unconditionally, hitting the NULL or garbage entry and panicking instead of failing gracefully.
Fix by moving the counter increments to after all allocations succeed, so the struct is always consistent on any error path.
--- drivers/hwtracing/coresight/coresight-platform.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-platform.c +6 -6
@@ -45,9 +45,8 @@ coresight_add_out_conn(struct device *dev, } } - pdata->nr_outconns++; pdata->out_conns = -devm_krealloc_array (dev, pdata->out_conns, pdata->nr_outconns, +devm_krealloc_array (dev, pdata->out_conns, pdata->nr_outconns +1 ,sizeof (*pdata->out_conns),GFP_KERNEL );if (!pdata->out_conns)return ERR_PTR (-ENOMEM );
@@ -63,7 +62,8 @@ coresight_add_out_conn(struct device *dev,* used right away. */ *conn = *new_conn; - pdata->out_conns[pdata->nr_outconns -1 ] = conn; + pdata->out_conns[pdata->nr_outconns] = conn; + pdata->nr_outconns++;return conn; }EXPORT_SYMBOL_GPL (coresight_add_out_conn);
@@ -86,13 +86,13 @@ int coresight_add_in_conn(struct coresight_connection *out_conn)return 0 ; } - pdata->nr_inconns++; pdata->in_conns = -devm_krealloc_array (dev, pdata->in_conns, pdata->nr_inconns, +devm_krealloc_array (dev, pdata->in_conns, pdata->nr_inconns +1 ,sizeof (*pdata->in_conns),GFP_KERNEL );if (!pdata->in_conns)return -ENOMEM ; - pdata->in_conns[pdata->nr_inconns -1 ] = out_conn; + pdata->in_conns[pdata->nr_inconns] = out_conn; + pdata->nr_inconns++;return 0 ; }EXPORT_SYMBOL_GPL (coresight_add_in_conn);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 882/2077 PCI: dwc: Fix signedness bug in fault injection test code
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 94ac934d2c054fba4a22d8dc84749094c5fa0ec0 ]
The kstrtou32() function returns negative error code or zero on success. However, in this case "val" is a u32 and the function returns signed long, so negative error codes from kstrtou32() are returned as high positive values.
Store the error code in an int instead.
--- drivers/pci/controller/dwc/pcie-designware-debugfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +4 -3
@@ -306,6 +306,7 @@ static ssize_t err_inj_write(struct file *file, const char __user *buf,u32 val, counter, vc_num, err_group, type_mask;int val_diff =0 ;char *kern_buf; +int ret; err_group = err_inj_list[pdata->idx].err_inj_group; type_mask = err_inj_type_mask[err_group];
@@ -327,10 +328,10 @@ static ssize_t err_inj_write(struct file *file, const char __user *buf,return -EINVAL ; } }else { - val =kstrtou32 (kern_buf,0 , &counter); -if (val) { + ret =kstrtou32 (kern_buf,0 , &counter); +if (ret) {kfree (kern_buf); -return val; +return ret; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 883/2077 PCI: mediatek-gen3: Fix incorrectly skipped pwrctrl error message
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit 8ba433753d9b131c2e43b1ff7ba8c5730cef8231 ]
When pwrctrl integration was added, the error message for pci_pwrctrl_create_devices() failure was incorrectly added after the goto statement, causing it to be skipped.
Move the goto statement after the dev_err_probe() call so that the error message actually gets printed (or saved if probe is deferred).
--- drivers/pci/controller/pcie-mediatek-gen3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mediatek-gen3.c +1 -1
@@ -1222,8 +1222,8 @@ static int mtk_pcie_probe(struct platform_device *pdev) err =pci_pwrctrl_create_devices (pcie->dev);if (err) { - goto err_tear_down_irq;dev_err_probe (dev, err,"failed to create pwrctrl devices\n" ); + goto err_tear_down_irq; } err =mtk_pcie_setup (pcie);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 884/2077 platform/x86: classmate-laptop: Address memory leaks on driver removal
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 4baf44b4051940ba1abc68ef5136d25cb1806521 ]
Switch over cmpc_accel_add_v4() and cmpc_accel_add() to using devm_kzalloc() for allocating the accel object which will cause it to be freed automatically on device removal, so it won't be leaked any more.
This also simplifies the rollback paths in these functions somewhat.
--- drivers/platform/x86/classmate-laptop.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/platform/x86/classmate-laptop.c +4 -8
@@ -400,7 +400,7 @@ static int cmpc_accel_add_v4(struct acpi_device *acpi)struct input_dev *inputdev;struct cmpc_accel *accel; - accel =kmalloc_obj (*accel); + accel =devm_kzalloc (&acpi->dev,sizeof (*accel),GFP_KERNEL );if (!accel)return -ENOMEM ;
@@ -411,7 +411,7 @@ static int cmpc_accel_add_v4(struct acpi_device *acpi) error =device_create_file (&acpi->dev, &cmpc_accel_sensitivity_attr_v4);if (error) - goto failed_sensitivity; +return error; accel->g_select =CMPC_ACCEL_G_SELECT_DEFAULT ;cmpc_accel_set_g_select_v4 (acpi->handle, accel->g_select);
@@ -434,8 +434,6 @@ static int cmpc_accel_add_v4(struct acpi_device *acpi)device_remove_file (&acpi->dev, &cmpc_accel_g_select_attr_v4); failed_g_select:device_remove_file (&acpi->dev, &cmpc_accel_sensitivity_attr_v4); -failed_sensitivity: -kfree (accel);return error; }
@@ -650,7 +648,7 @@ static int cmpc_accel_add(struct acpi_device *acpi)struct input_dev *inputdev;struct cmpc_accel *accel; - accel =kmalloc_obj (*accel); + accel =devm_kzalloc (&acpi->dev,sizeof (*accel),GFP_KERNEL );if (!accel)return -ENOMEM ;
@@ -659,7 +657,7 @@ static int cmpc_accel_add(struct acpi_device *acpi) error =device_create_file (&acpi->dev, &cmpc_accel_sensitivity_attr);if (error) - goto failed_file; +return error; error =cmpc_add_acpi_notify_device (acpi,"cmpc_accel" , cmpc_accel_idev_init);
@@ -673,8 +671,6 @@ static int cmpc_accel_add(struct acpi_device *acpi) failed_input:device_remove_file (&acpi->dev, &cmpc_accel_sensitivity_attr); -failed_file: -kfree (accel);return error; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 885/2077 clk: microchip: mpfs-ccc: fix peripheral driver registration failures after oob fix
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Conor Dooley <[email protected]>
[ Upstream commit c8a3be5bc2b2f2d53c56a8b9cab731e917b95c07 ]
Commit 2f7ae8ab6aa73 ("clk: microchip: mpfs-ccc: fix out of bounds access during output registration") fixed the out of bounds access, but it did so by packing sparse indices into a linear space. When peripheral drivers request clocks, they obviously don't care for this compression and use the sparse indices, and therefore try to request the wrong clocks or clocks that don't exist.
The most straightforward fix here seems to stop being clever with the packing and just overallocate the array.
--- drivers/clk/microchip/clk-mpfs-ccc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/clk/microchip/clk-mpfs-ccc.c +4 -11
@@ -32,6 +32,7 @@#define MPFS_CCC_FIXED_DIV 4#define MPFS_CCC_OUTPUTS_PER_PLL 4#define MPFS_CCC_REFS_PER_PLL 2 +#define MPFS_CCC_NUM_CLKS 16struct mpfs_ccc_data {void __iomem **pll_base;
@@ -178,7 +179,7 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_return dev_err_probe (dev, ret,"failed to register clock id: %d\n" , out_hw->id); - data->hw_data.hws[out_hw->id -2 ] = &out_hw->divider.hw; + data->hw_data.hws[out_hw->id] = &out_hw->divider.hw; }return 0 ;
@@ -231,17 +232,9 @@ static int mpfs_ccc_probe(struct platform_device *pdev) {struct mpfs_ccc_data *clk_data;void __iomem *pll_base[ARRAY_SIZE (mpfs_ccc_pll_clks)]; -unsigned int num_clks;int ret; -/* -* If DLLs get added here, mpfs_ccc_register_outputs() currently packs -* sparse clock IDs in the hws array -*/ - num_clks =ARRAY_SIZE (mpfs_ccc_pll_clks) +ARRAY_SIZE (mpfs_ccc_pll0out_clks) + -ARRAY_SIZE (mpfs_ccc_pll1out_clks); - - clk_data =devm_kzalloc (&pdev->dev,struct_size (clk_data, hw_data.hws, num_clks), + clk_data =devm_kzalloc (&pdev->dev,struct_size (clk_data, hw_data.hws,MPFS_CCC_NUM_CLKS ),GFP_KERNEL );if (!clk_data)return -ENOMEM ;
@@ -255,7 +248,7 @@ static int mpfs_ccc_probe(struct platform_device *pdev)return PTR_ERR (pll_base[1 ]); clk_data->pll_base = pll_base; - clk_data->hw_data.num = num_clks; + clk_data->hw_data.num =MPFS_CCC_NUM_CLKS ; clk_data->dev = &pdev->dev; ret = mpfs_ccc_register_plls(clk_data->dev, mpfs_ccc_pll_clks,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 886/2077 perf build-id: Fix off-by-one bug when printing kernel/module build-id
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Petlan <[email protected]>
[ Upstream commit 017bca78e4d72b1ff027d368c20a1b2c654edaf7 ]
When changing sprintf functions to snprintf, one byte got lost. Since snprintf ones do not handle the '\0' terminating character, the number of printed characters is 40, while sizeof(sbuild_id) is 41, including the terminating '\0' character.
This makes the later check fail so that nothing is printed.
Fix that.
Before:
[Michael@Carbon ~]$ perf buildid-list -k
[Michael@Carbon ~]$
After:
[Michael@Carbon ~]$ perf buildid-list -k
a527806324d543c4bc3ff2f9c9519d494fed5f68
[Michael@Carbon ~]$--- tools/perf/builtin-buildid-list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-buildid-list.c +2 -2
@@ -61,7 +61,7 @@ static int sysfs__fprintf_build_id(FILE *fp)int ret; ret =sysfs__snprintf_build_id ("/" , sbuild_id,sizeof (sbuild_id)); -if (ret !=sizeof (sbuild_id)) +if (ret +1 !=sizeof (sbuild_id))return ret <0 ? ret : -EINVAL ;return fprintf (fp,"%s\n" , sbuild_id);
@@ -73,7 +73,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)int ret; ret =filename__snprintf_build_id (name, sbuild_id,sizeof (sbuild_id)); -if (ret !=sizeof (sbuild_id)) +if (ret +1 !=sizeof (sbuild_id))return ret <0 ? ret : -EINVAL ;return fprintf (fp,"%s\n" , sbuild_id);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 887/2077 perf event: Fix size of synthesized sample with branch stacks
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 059e9100d82aae2254f1b06835a55755936b1417 ]
Synthesizing branch stacks for Intel-PT highlighted an issue where PERF_SAMPLE_BRANCH_HW_INDEX was assumed to always be set in the perf_event_attr branch_sample_type. This caused an incorrect size calculation.
Fix the writing of the nr and hw_idx values during sample event synthesis by passing the branch_sample_type into the sample size and synthesis functions. Also update hardware tracers (Intel PT, ARM SPE, CS-ETM) to retrieve and pass their branch_sample_type dynamically to prevent payload misalignment.
--- tools/perf/bench/inject-buildid.c | 9 ++++++--- tools/perf/builtin-inject.c | 12 +++++++++--- tools/perf/tests/dlfilter-test.c | 8 ++++++-- tools/perf/tests/sample-parsing.c | 5 +++-- tools/perf/util/arm-spe.c | 28 ++++++++++++++++++++++++---- tools/perf/util/cs-etm.c | 28 +++++++++++++++++++++++----- tools/perf/util/intel-bts.c | 3 ++- tools/perf/util/intel-pt.c | 27 +++++++++++++++++++++++---- tools/perf/util/synthetic-events.c | 25 ++++++++++++++++++------- tools/perf/util/synthetic-events.h | 6 ++++-- 10 files changed, 118 insertions(+), 33 deletions(-)
tools/perf/bench/inject-buildid.c +6 -3
@@ -228,9 +228,12 @@ static ssize_t synthesize_sample(struct bench_data *data, struct bench_dso *dso, event.header.type =PERF_RECORD_SAMPLE ; event.header.misc =PERF_RECORD_MISC_USER ; - event.header.size =perf_event__sample_event_size (&sample, bench_sample_type,0 ); - -perf_event__synthesize_sample (&event, bench_sample_type,0 , &sample); + event.header.size =perf_event__sample_event_size (&sample, bench_sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); +perf_event__synthesize_sample (&event, bench_sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , &sample);return writen (data->input_pipe[1 ], &event, event.header.size); }
tools/perf/builtin-inject.c +9 -3
@@ -465,8 +465,13 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool,/* remove sample_type {STACK,REGS}_USER for synthesize */ sample_type &= ~(PERF_SAMPLE_STACK_USER |PERF_SAMPLE_REGS_USER ); -perf_event__synthesize_sample (event_copy, sample_type, - evsel->core.attr.read_format, sample); + ret =perf_event__synthesize_sample (event_copy, sample_type, + evsel->core.attr.read_format, + evsel->core.attr.branch_sample_type, sample); +if (ret) { +pr_err ("Failed to synthesize sample\n" ); +return ret; + }return perf_event__repipe_synth (tool, event_copy); }
@@ -1102,7 +1107,8 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, sample_sw.period = sample->period; sample_sw.time = sample->time;perf_event__synthesize_sample (event_sw, evsel->core.attr.sample_type, - evsel->core.attr.read_format, &sample_sw); + evsel->core.attr.read_format, + evsel->core.attr.branch_sample_type, &sample_sw);build_id__mark_dso_hit (tool, event_sw, &sample_sw, evsel, machine); ret =perf_event__repipe (tool, event_sw, &sample_sw, machine);perf_sample__exit (&sample_sw);
tools/perf/tests/dlfilter-test.c +6 -2
@@ -188,8 +188,12 @@ static int write_sample(struct test_data *td, u64 sample_type, u64 id, pid_t pid event->header.type =PERF_RECORD_SAMPLE ; event->header.misc =PERF_RECORD_MISC_USER ; - event->header.size =perf_event__sample_event_size (&sample, sample_type,0 ); - err =perf_event__synthesize_sample (event, sample_type,0 , &sample); + event->header.size =perf_event__sample_event_size (&sample, sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); + err =perf_event__synthesize_sample (event, sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , &sample);if (err)return test_result ("perf_event__synthesize_sample() failed" ,TEST_FAIL );
tools/perf/tests/sample-parsing.c +3 -2
@@ -310,7 +310,8 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) sample.read.one.lost =1 ; } - sz =perf_event__sample_event_size (&sample, sample_type, read_format); + sz =perf_event__sample_event_size (&sample, sample_type, read_format, + evsel.core.attr.branch_sample_type); bufsz = sz +4096 ;/* Add a bit for overrun checking */ event =malloc (bufsz);if (!event) {
@@ -324,7 +325,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) event->header.size = sz; err =perf_event__synthesize_sample (event, sample_type, read_format, - &sample); + evsel.core.attr.branch_sample_type, &sample);if (err) {pr_debug ("%s failed for sample_type %#" PRIx64", error %d\n" ,"perf_event__synthesize_sample" , sample_type, err);
tools/perf/util/arm-spe.c +24 -4
@@ -482,10 +482,30 @@ static void arm_spe__prep_branch_stack(struct arm_spe_queue *speq) bstack->hw_idx =-1ULL ; } -static int arm_spe__inject_event (union perf_event *event,struct perf_sample *sample,u64 type) +static int arm_spe__inject_event (struct arm_spe *spe,union perf_event *event, +struct perf_sample *sample,u64 type) { - event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample); +struct evsel *evsel = sample->evsel; +u64 branch_sample_type =0 ; +size_t sz; + +if (!evsel && spe->session && spe->session->evlist) + evsel =evlist__id2evsel (spe->session->evlist, sample->id); + +if (evsel) + branch_sample_type = evsel->core.attr.branch_sample_type; + + event->header.type =PERF_RECORD_SAMPLE ; + sz =perf_event__sample_event_size (sample, type,/*read_format=*/ 0 , + branch_sample_type); +if (sz >=PERF_SAMPLE_MAX_SIZE ) { +pr_err ("Sample size %zu exceeds max size %d\n" , sz,PERF_SAMPLE_MAX_SIZE ); +return -EFAULT ; + } + event->header.size = sz; + +return perf_event__synthesize_sample (event, type,/*read_format=*/ 0 , + branch_sample_type, sample); } static inline int
@@ -497,7 +517,7 @@ arm_spe_deliver_synth_event(struct arm_spe *spe,int ret;if (spe->synth_opts.inject) { - ret =arm_spe__inject_event (event, sample, spe->sample_type); + ret =arm_spe__inject_event (spe, event, sample, spe->sample_type);if (ret)return ret; }
tools/perf/util/cs-etm.c +23 -5
@@ -1422,11 +1422,29 @@ static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq, bs->nr +=1 ; } -static int cs_etm__inject_event (union perf_event *event, +static int cs_etm__inject_event (struct cs_etm_auxtrace *etm,union perf_event *event,struct perf_sample *sample,u64 type) { - event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample); +struct evsel *evsel = sample->evsel; +u64 branch_sample_type =0 ; +size_t sz; + +if (!evsel && etm->session && etm->session->evlist) + evsel =evlist__id2evsel (etm->session->evlist, sample->id); + +if (evsel) + branch_sample_type = evsel->core.attr.branch_sample_type; + + sz =perf_event__sample_event_size (sample, type,/*read_format=*/ 0 , + branch_sample_type); +if (sz >=PERF_SAMPLE_MAX_SIZE ) { +pr_err ("Sample size %zu exceeds max size %d\n" , sz,PERF_SAMPLE_MAX_SIZE ); +return -EFAULT ; + } + event->header.size = sz; + +return perf_event__synthesize_sample (event, type,/*read_format=*/ 0 , + branch_sample_type, sample); }
@@ -1592,7 +1610,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, sample.branch_stack = tidq->last_branch;if (etm->synth_opts.inject) { - ret =cs_etm__inject_event (event, &sample, + ret =cs_etm__inject_event (etm, event, &sample, etm->instructions_sample_type);if (ret)return ret;
@@ -1667,7 +1685,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, }if (etm->synth_opts.inject) { - ret =cs_etm__inject_event (event, &sample, + ret =cs_etm__inject_event (etm, event, &sample, etm->branches_sample_type);if (ret)return ret;
tools/perf/util/intel-bts.c +2 -1
@@ -303,7 +303,8 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, event.sample.header.size = bts->branches_event_size; ret =perf_event__synthesize_sample (&event, bts->branches_sample_type, -0 , &sample); +/*read_format=*/ 0 ,/*branch_sample_type=*/ 0 , + &sample);if (ret)return ret; }
tools/perf/util/intel-pt.c +23 -4
@@ -1728,11 +1728,30 @@ static void intel_pt_prep_b_sample(struct intel_pt *pt, event->sample.header.misc = sample->cpumode; } -static int intel_pt_inject_event (union perf_event *event, +static int intel_pt_inject_event (struct intel_pt *pt,union perf_event *event,struct perf_sample *sample,u64 type) { - event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample); +struct evsel *evsel = sample->evsel; +u64 branch_sample_type =0 ; +size_t sz; + +if (!evsel && pt->session && pt->session->evlist) + evsel =evlist__id2evsel (pt->session->evlist, sample->id); + +if (evsel) + branch_sample_type = evsel->core.attr.branch_sample_type; + + event->header.type =PERF_RECORD_SAMPLE ; + sz =perf_event__sample_event_size (sample, type,/*read_format=*/ 0 , + branch_sample_type); +if (sz >=PERF_SAMPLE_MAX_SIZE ) { +pr_err ("Sample size %zu exceeds max size %d\n" , sz,PERF_SAMPLE_MAX_SIZE ); +return -EFAULT ; + } + event->header.size = sz; + +return perf_event__synthesize_sample (event, type,/*read_format=*/ 0 , + branch_sample_type, sample); } static inline int intel_pt_opt_inject(struct intel_pt *pt,
@@ -1742,7 +1761,7 @@ static inline int intel_pt_opt_inject(struct intel_pt *pt,if (!pt->synth_opts.inject)return 0 ; -return intel_pt_inject_event (event, sample, type); +return intel_pt_inject_event (pt, event, sample, type); } static int intel_pt_deliver_synth_event(struct intel_pt *pt,
tools/perf/util/synthetic-events.c +18 -7
@@ -1455,7 +1455,8 @@ int perf_event__synthesize_stat_round(const struct perf_tool *tool,return process (tool, (union perf_event *) &event,NULL , machine); } -size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type,u64 read_format) +size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type,u64 read_format, +u64 branch_sample_type) {size_t sz, result =sizeof (struct perf_record_sample );
@@ -1515,8 +1516,10 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (type &PERF_SAMPLE_BRANCH_STACK ) { sz = sample->branch_stack->nr *sizeof (struct branch_entry ); -/* nr, hw_idx */ - sz +=2 *sizeof (u64); +/* nr */ + sz +=sizeof (u64); +if (branch_sample_type &PERF_SAMPLE_BRANCH_HW_INDEX ) + sz +=sizeof (u64); result += sz; }
@@ -1605,7 +1608,7 @@ static __u64 *copy_read_group_values(__u64 *array, __u64 read_format, }int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, -const struct perf_sample *sample) +u64 branch_sample_type,const struct perf_sample *sample) {__u64 *array;size_t sz;
@@ -1719,9 +1722,17 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_foif (type &PERF_SAMPLE_BRANCH_STACK ) { sz = sample->branch_stack->nr *sizeof (struct branch_entry ); -/* nr, hw_idx */ - sz +=2 *sizeof (u64); -memcpy (array, sample->branch_stack, sz); + + *array++ = sample->branch_stack->nr; + +if (branch_sample_type &PERF_SAMPLE_BRANCH_HW_INDEX ) { +if (sample->no_hw_idx) + *array++ =0 ; +else + *array++ = sample->branch_stack->hw_idx; + } + +memcpy (array,perf_sample__branch_entries ((struct perf_sample *)sample), sz); array = (void *)array + sz; }
tools/perf/util/synthetic-events.h +4 -2
@@ -81,7 +81,8 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool, union perf_int perf_event__synthesize_modules (const struct perf_tool *tool,perf_event__handler_t process,struct machine *machine);int perf_event__synthesize_namespaces (const struct perf_tool *tool,union perf_event *event,pid_t pid,pid_t tgid,perf_event__handler_t process,struct machine *machine);int perf_event__synthesize_cgroups (const struct perf_tool *tool,perf_event__handler_t process,struct machine *machine); -int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format,const struct perf_sample *sample); +int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, +u64 branch_sample_type,const struct perf_sample *sample);int perf_event__synthesize_stat_config (const struct perf_tool *tool,struct perf_stat_config *config,perf_event__handler_t process,struct machine *machine);int perf_event__synthesize_stat_events (struct perf_stat_config *config,const struct perf_tool *tool,struct evlist *evlist,perf_event__handler_t process,bool attrs);int perf_event__synthesize_stat_round (const struct perf_tool *tool,u64 time,u64 type,perf_event__handler_t process,struct machine *machine);
@@ -97,7 +98,8 @@ void perf_event__synthesize_final_bpf_metadata(struct perf_session *session,int perf_tool__process_synth_event (const struct perf_tool *tool,union perf_event *event,struct machine *machine,perf_event__handler_t process); -size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type,u64 read_format); +size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type, +u64 read_format,u64 branch_sample_type); int __machine__synthesize_threads(struct machine *machine, const struct perf_tool *tool, struct target *target, struct perf_thread_map *threads,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 888/2077 perf inject: Fix itrace branch stack synthesis
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit daac18e7c42c012e289bfd310503f9417e4a9481 ]
When using "perf inject --itrace=L" to synthesize branch stacks from AUX data, several issues caused failures with the generated file:
1. The synthesized samples were delivered without the PERF_SAMPLE_BRANCH_STACK flag if it was not in the original event's sample_type. Fixed by using sample_type | evsel->synth_sample_type in intel_pt_do_synth_pebs_sample.
2. Modifying evsel->core.attr.sample_type early in __cmd_inject caused parse failures for subsequent records in the input file. Fixed by moving this modification to just before writing the header.
3. perf_event__repipe_sample was narrowed to only synthesize samples when branch stack injection was requested, and restored the use of perf_inject__cut_auxtrace_sample as a fallback to preserve functionality.
4. Potential Heap Overflow in perf_event__repipe_sample: Addressed by adding a check that prints an error and returns -EFAULT if the calculated event size exceeds PERF_SAMPLE_MAX_SIZE.
5. Header vs Payload Mismatch in __cmd_inject: Addressed by narrowing the condition so that HEADER_BRANCH_STACK is only set in the file header if add_last_branch was true.
6. NULL Pointer Dereference in intel-pt.c: When branch stack injection is requested (add_last_branch is true) but last_branch is false (e.g., perf inject --itrace=L), ptq->last_branch was not allocated. However, PEBS branch stack synthesis (via synth_sample_type) still forced LBR handling in do_synth_pebs_sample(), dereferencing the NULL ptq->last_branch pointer. Guarding the dereference is not sufficient because downstream sample size calculation and synthesis strictly require a non-NULL branch_stack when the bit is set. Fixed by ensuring ptq->last_branch is allocated in intel_pt_alloc_queue() when add_last_branch is requested.
7. Modifying event attributes in perf_event__repipe_attr in-place caused SIGSEGV on read-only mmap buffers in file mode and downstream parser breakage in pipe mode. Fixed by processing the unmodified attribute first, returning immediately in non-pipe mode, and correctly synthesizing a new attribute event for pipe output using perf_event__synthesize_attr. Also:
- Added a size validation check and integer underflow protection when parsing n_ids.
- Prevented Trailing ID memory corruption by zero-initializing the local attr copy and safely copying using min_t(size_t, sizeof(attr), event->attr.attr.size).
- Resolved ID array parsing mismatch downstream by expanding attr.size to sizeof(struct perf_event_attr) before synthesis to guarantee perfect header/attribute size alignment.
8. Potential dangling pointer vulnerability in perf_event__repipe_sample:
Addressed by restoring the original sample->branch_stack pointer before returning, including on early error return paths.
9. Off-by-one error in sample size check in perf_event__repipe_sample:
Fixed by checking if sz >= PERF_SAMPLE_MAX_SIZE instead of >.
10. Unadvertised size field left in payload by cut_auxtrace_sample:
Addressed by excluding the 8-byte size field from the copied payload to correctly match the cleared PERF_SAMPLE_AUX bit. Cut the AUX sample payload even if size is 0.
11. Inaccurate sample size calculation and uninitialized memory leaks in
convert_sample_callchain: Fixed by replacing manual arithmetic with perf_event__sample_event_size and adding a bounds check against PERF_SAMPLE_MAX_SIZE.
12. Omission of branch_sample_type in file headers: Addressed by expanding older, smaller attributes to PERF_ATTR_SIZE_VER2 in __cmd_inject to ensure branch_sample_type is not silently omitted.
--- tools/perf/builtin-inject.c | 153 ++++++++++++++++++++++++++++++++---- tools/perf/util/intel-pt.c | 8 +- 2 files changed, 142 insertions(+), 19 deletions(-)
tools/perf/builtin-inject.c +137 -16
@@ -216,12 +216,23 @@ static int perf_event__repipe_op4_synth(const struct perf_tool *tool,return perf_event__repipe_synth (tool, event); } +static int perf_event__repipe_synth_cb (const struct perf_tool *tool, +union perf_event *event, +struct perf_sample *sample__maybe_unused , +struct machine *machine__maybe_unused ) +{ +return perf_event__repipe_synth (tool, event); +} +static int perf_event__repipe_attr (const struct perf_tool *tool,union perf_event *event,struct evlist **pevlist) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); +struct perf_event_attr attr; +size_t n_ids; +u64 *ids;int ret; ret =perf_event__process_attr (tool, event, pevlist);
@@ -232,7 +243,37 @@ static int perf_event__repipe_attr(const struct perf_tool *tool,if (!inject->output.is_pipe)return 0 ; -return perf_event__repipe_synth (tool, event); +if (!inject->itrace_synth_opts.set) +return perf_event__repipe_synth (tool, event); + +if (event->header.size <sizeof (struct perf_event_header ) +sizeof (u64)) { +pr_err ("Attribute event size %u is too small\n" , event->header.size); +return -EINVAL ; + } + +if (event->header.size -sizeof (event->header) < event->attr.attr.size) { +pr_err ("Attribute event size %u is too small for attr.size %u\n" , + event->header.size, event->attr.attr.size); +return -EINVAL ; + } + +memset (&attr,0 ,sizeof (attr)); +memcpy (&attr, &event->attr.attr, +min_t (size_t,sizeof (attr), (size_t )event->attr.attr.size)); + + n_ids = event->header.size -sizeof (event->header) - event->attr.attr.size; + n_ids /=sizeof (u64); + ids =perf_record_header_attr_id (event); + + attr.size =sizeof (struct perf_event_attr ); + attr.sample_type &= ~PERF_SAMPLE_AUX ; + +if (inject->itrace_synth_opts.add_last_branch) { + attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; + attr.branch_sample_type |=PERF_SAMPLE_BRANCH_HW_INDEX ; + } +return perf_event__synthesize_attr (tool, &attr, (u32 )n_ids, ids, + perf_event__repipe_synth_cb); } static int perf_event__repipe_event_update(const struct perf_tool *tool,
@@ -331,8 +372,8 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *inject,union perf_event *event, struct perf_sample *sample) { - size_t sz1 = sample->aux_sample.data - (void *)event; -size_t sz2 = event->header.size - sample->aux_sample.size - sz1; + size_t sz1 = sample->aux_sample.data - (void *)event - sizeof(u64); +size_t sz2 = event->header.size - sample->aux_sample.size - (sz1 +sizeof (u64));union perf_event *ev;if (inject->event_copy ==NULL ) {
@@ -343,13 +384,12 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *inject, ev = (union perf_event *)inject->event_copy;if (sz1 > event->header.size || sz2 > event->header.size || sz1 + sz2 > event->header.size || - sz1 <sizeof (struct perf_event_header ) +sizeof (u64)) + sz1 <sizeof (struct perf_event_header ))return event;memcpy (ev, event, sz1);memcpy ((void *)ev + sz1, (void *)event + event->header.size - sz2, sz2); ev->header.size = sz1 + sz2; - ((u64 *)((void *)ev + sz1))[-1 ] =0 ;return ev; }
@@ -369,14 +409,77 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, struct perf_inject *inject = container_of(tool, struct perf_inject, tool); -if (evsel && evsel->handler) { +if (evsel ==NULL ) +return perf_event__repipe_synth (tool, event); + +if (evsel->handler) {inject_handler f = evsel->handler;return f (tool, event, sample, evsel, machine); }build_id__mark_dso_hit (tool, event, sample, evsel, machine); -if (inject->itrace_synth_opts.set && sample->aux_sample.size) { +if (inject->itrace_synth_opts.set && + (inject->itrace_synth_opts.last_branch || + inject->itrace_synth_opts.add_last_branch)) { +union perf_event *event_copy = (void *)inject->event_copy; +struct branch_stack dummy_bs = { .nr =0 , .hw_idx =0 }; +int err; +size_t sz; +u64 orig_type = evsel->core.attr.sample_type; +u64 orig_branch_type = evsel->core.attr.branch_sample_type; + +struct branch_stack *orig_bs = sample->branch_stack; + +if (event_copy ==NULL ) { + inject->event_copy =malloc (PERF_SAMPLE_MAX_SIZE ); +if (!inject->event_copy) +return -ENOMEM ; + + event_copy = (void *)inject->event_copy; + } + +if (!sample->branch_stack) + sample->branch_stack = &dummy_bs; + +if (inject->itrace_synth_opts.add_last_branch) { +/* Temporarily add in type bits for synthesis. */ + evsel->core.attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; + evsel->core.attr.branch_sample_type |=PERF_SAMPLE_BRANCH_HW_INDEX ; + } + evsel->core.attr.sample_type &= ~PERF_SAMPLE_AUX ; + + sz =perf_event__sample_event_size (sample, evsel->core.attr.sample_type, + evsel->core.attr.read_format, + evsel->core.attr.branch_sample_type); + +if (sz >=PERF_SAMPLE_MAX_SIZE ) { +pr_err ("Sample size %zu exceeds max size %d\n" , sz,PERF_SAMPLE_MAX_SIZE ); + evsel->core.attr.sample_type = orig_type; + evsel->core.attr.branch_sample_type = orig_branch_type; + sample->branch_stack = orig_bs; +return -EFAULT ; + } + + event_copy->header.type =PERF_RECORD_SAMPLE ; + event_copy->header.misc = event->header.misc; + event_copy->header.size = sz; + + err =perf_event__synthesize_sample (event_copy, evsel->core.attr.sample_type, + evsel->core.attr.read_format, + evsel->core.attr.branch_sample_type, sample); + + evsel->core.attr.sample_type = orig_type; + evsel->core.attr.branch_sample_type = orig_branch_type; + sample->branch_stack = orig_bs; + +if (err) { +pr_err ("Failed to synthesize sample\n" ); +return err; + } + event = event_copy; + }else if (inject->itrace_synth_opts.set && + (evsel->core.attr.sample_type &PERF_SAMPLE_AUX )) { event =perf_inject__cut_auxtrace_sample (inject, event, sample);if (IS_ERR (event))return PTR_ERR (event);
@@ -397,7 +500,7 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool,struct callchain_cursor_node *node;struct thread *thread;u64 sample_type = evsel->core.attr.sample_type; -u32 sample_size = event->header.size; +size_t sz;u64 i, k;int ret;
@@ -456,15 +559,18 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool, out:memcpy (event_copy, event,sizeof (event->header)); -/* adjust sample size for stack and regs */ - sample_size -= sample->user_stack.size; - sample_size -= (hweight64 (evsel->core.attr.sample_regs_user) +1 ) *sizeof (u64); - sample_size += (sample->callchain->nr +1 ) *sizeof (u64); - event_copy->header.size = sample_size; -/* remove sample_type {STACK,REGS}_USER for synthesize */ sample_type &= ~(PERF_SAMPLE_STACK_USER |PERF_SAMPLE_REGS_USER ); + sz =perf_event__sample_event_size (sample, sample_type, + evsel->core.attr.read_format, + evsel->core.attr.branch_sample_type); +if (sz >=PERF_SAMPLE_MAX_SIZE ) { +pr_err ("Sample size %zu exceeds max size %d\n" , sz,PERF_SAMPLE_MAX_SIZE ); +return -EFAULT ; + } + event_copy->header.size = sz; + ret =perf_event__synthesize_sample (event_copy, sample_type, evsel->core.attr.read_format, evsel->core.attr.branch_sample_type, sample);
@@ -2442,12 +2548,27 @@ static int __cmd_inject(struct perf_inject *inject)* synthesized hardware events, so clear the feature flag. */ if (inject->itrace_synth_opts.set) { +struct evsel *evsel; +perf_header__clear_feat (&session->header,HEADER_AUXTRACE ); -if (inject->itrace_synth_opts.last_branch || - inject->itrace_synth_opts.add_last_branch) + +evlist__for_each_entry (session->evlist, evsel) { + evsel->core.attr.sample_type &= ~PERF_SAMPLE_AUX ; + } + +if (inject->itrace_synth_opts.add_last_branch) {perf_header__set_feat (&session->header,HEADER_BRANCH_STACK ); + +evlist__for_each_entry (session->evlist, evsel) { + evsel->core.attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; +if (evsel->core.attr.size <PERF_ATTR_SIZE_VER2 ) + evsel->core.attr.size =PERF_ATTR_SIZE_VER2 ; + evsel->core.attr.branch_sample_type |= +PERF_SAMPLE_BRANCH_HW_INDEX ; + } + } }/*
tools/perf/util/intel-pt.c +5 -3
@@ -1307,7 +1307,8 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, goto out_free; } -if (pt->synth_opts.last_branch || pt->synth_opts.other_events) { +if (pt->synth_opts.last_branch || pt->synth_opts.add_last_branch || + pt->synth_opts.other_events) {unsigned int entry_cnt =max (LBRS_MAX , pt->br_stack_sz); ptq->last_branch =intel_pt_alloc_br_stack (entry_cnt);
@@ -2505,7 +2506,7 @@ static int intel_pt_do_synth_pebs_sample(struct intel_pt_queue *ptq, struct evseintel_pt_add_xmm (intr_regs, pos, items, regs_mask); } -if (sample_type &PERF_SAMPLE_BRANCH_STACK ) { +if ((sample_type | evsel->synth_sample_type) &PERF_SAMPLE_BRANCH_STACK ) {if (items->mask[INTEL_PT_LBR_0_POS ] || items->mask[INTEL_PT_LBR_1_POS ] || items->mask[INTEL_PT_LBR_2_POS ]) {
@@ -2576,7 +2577,8 @@ static int intel_pt_do_synth_pebs_sample(struct intel_pt_queue *ptq, struct evse sample.transaction = txn; } - ret =intel_pt_deliver_synth_event (pt, event, &sample, sample_type); + ret =intel_pt_deliver_synth_event (pt, event, &sample, + sample_type | evsel->synth_sample_type);perf_sample__exit (&sample);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 889/2077 staging: most: video: avoid double free on video register failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 7cb1c5b32a2bfde961fff8d5204526b609bcb30a ]
comp_register_videodev() allocates a video_device with video_device_alloc() and releases it if video_register_device() fails.
This can double free the video_device when __video_register_device() reaches device_register() and that call fails:
video_register_device()
-> __video_register_device()
-> device_register() fails
-> put_device(&vdev->dev)
-> v4l2_device_release()
-> vdev->release(vdev)
-> video_device_release(vdev) comp_register_videodev()
-> video_device_release(mdev->vdev)
Use video_device_release_empty() while registering the device so that registration failure paths do not free mdev->vdev through vdev->release(). comp_register_videodev() then releases mdev->vdev exactly once on failure. Restore video_device_release() after successful registration so the registered device keeps its normal lifetime handling.
This issue was found by a static analysis tool I am developing.
--- drivers/staging/most/video/video.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/staging/most/video/video.c +6 -1
@@ -420,6 +420,7 @@ static int comp_register_videodev(struct most_video_dev *mdev)/* Fill the video capture device struct */ *mdev->vdev = comp_videodev_template; + mdev->vdev->release = video_device_release_empty; mdev->vdev->v4l2_dev = &mdev->v4l2_dev; mdev->vdev->lock = &mdev->lock; snprintf(mdev->vdev->name, sizeof(mdev->vdev->name), "MOST: %s",
@@ -432,9 +433,13 @@ static int comp_register_videodev(struct most_video_dev *mdev)v4l2_err (&mdev->v4l2_dev,"video_register_device failed (%d)\n" , ret);video_device_release (mdev->vdev); +return ret; } -return ret; + mdev->vdev->release = video_device_release; + +return 0 ; + }static void comp_unregister_videodev (struct most_video_dev *mdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 890/2077 usb: host: max3421: Fix shift-out-of-bounds in max3421_hub_control()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seungjin Bae <[email protected]>
[ Upstream commit cff06b03b530ae1fe8a13e93a7848f2130e00fb4 ]
The max3421_hub_control() function handles USB hub class requests to the virtual root hub. In the default branches of both the ClearPortFeature and SetPortFeature switch statements, it modifies max3421_hcd->port_status by left shifting 1 by the request's value parameter. However, it does not validate whether this shift will exceed the width of port_status.
So if a malicious userspace task with access to the root hub via /dev/bus/usb/.../001 issues a USBDEVFS_CONTROL ioctl with wValue greater than or equal to 32, the left shift operation invokes shift-out-of-bounds undefined behavior. This results in arbitrary bit corruption of port_status, including the normally-immutable change bits, which can bypass internal state checks and confuse the hub status.
Fix this by rejecting requests whose value exceeds the shift width before performing the shift.
This issue was found using a KLEE-based symbolic execution tool for kernel drivers that I'm currently developing.
--- drivers/usb/host/max3421-hcd.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/host/max3421-hcd.c +4 -0
@@ -1694,6 +1694,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index, !pdata->vbus_active_level); fallthrough;default : +if (value >=32 ) + goto error; max3421_hcd->port_status &= ~(1 << value); }break ;
@@ -1747,6 +1749,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,max3421_reset_port (hcd); fallthrough;default : +if (value >=32 ) + goto error;if ((max3421_hcd->port_status &USB_PORT_STAT_POWER ) !=0 ) max3421_hcd->port_status |= (1 << value);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 891/2077 usb: host: max3421: Reject hub port requests for non-existent ports
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seungjin Bae <[email protected]>
[ Upstream commit 11b5c101e2fd206104b05bc92554d356989423a8 ]
The max3421_hub_control() function handles USB hub class requests to the virtual root hub. The GetPortStatus case correctly rejects requests with index != 1, since the virtual root hub has only a single port. However, the ClearPortFeature and SetPortFeature cases lack the same check.
Fix this by extending the index != 1 rejection to both cases, matching the existing behavior of GetPortStatus.
--- drivers/usb/host/max3421-hcd.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/host/max3421-hcd.c +4 -0
@@ -1685,6 +1685,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,case ClearHubFeature:break ;case ClearPortFeature: +if (index !=1 ) + goto error;switch (value) {case USB_PORT_FEAT_SUSPEND :break ;
@@ -1728,6 +1730,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,break ;case SetPortFeature: +if (index !=1 ) + goto error;switch (value) {case USB_PORT_FEAT_LINK_STATE :case USB_PORT_FEAT_U1_TIMEOUT :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 892/2077 perf test amd ibs: Fix incorrect kernel version check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravi Bangoria <[email protected]>
[ Upstream commit 0b97e92393a178765ee1ea01fe5087efece2c425 ]
"AMD IBS sample period" unit test is getting skipped on kernel v7.x. Fix the kernel version >= v6.15 check.
--- tools/perf/arch/x86/tests/amd-ibs-period.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/tests/amd-ibs-period.c +1 -1
@@ -932,7 +932,7 @@ static bool kernel_v6_15_or_newer(void) endptr++; minor =strtol (endptr,NULL ,10 ); -return major >=6 && minor >=15 ; +return major >6 || (major ==6 && minor >=15 ); } int test__amd_ibs_period(struct test_suite *test __maybe_unused,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 893/2077 gpib: Fix inappropriate ioctl error return
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Penkler <[email protected]>
[ Upstream commit 70ea440324e8c1a10837f721352f5bd469c85007 ]
The driver was returning -ENOTTY in the case the ioctl command was not recognised. Change it to -EBADRQC.
--- drivers/gpib/common/gpib_os.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpib/common/gpib_os.c +1 -2
@@ -613,7 +613,7 @@ long ibioctl(struct file *filep, unsigned int cmd, unsigned long arg)unsigned int minor =iminor (file_inode (filep));struct gpib_board *board;struct gpib_file_private *file_priv = filep->private_data; -long retval = -ENOTTY ; +long retval = -EBADRQC ;if (minor >=GPIB_MAX_NUM_BOARDS ) {pr_err ("gpib: invalid minor number of device file\n" );
@@ -806,7 +806,6 @@ long ibioctl(struct file *filep, unsigned int cmd, unsigned long arg)mutex_unlock (&board->big_gpib_mutex);return write_ioctl (file_priv, board, arg);default : - retval = -ENOTTY ; goto done; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 894/2077 char: tlclk: fix use-after-free in tlclk_cleanup()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Kim <[email protected]>
[ Upstream commit bbf003b7794d6ad6f939fdd29f1f1bde8ac554c1 ]
This patch improves the module cleanup process in the tlclk driver to prevent potential use-after-free and race conditions.
Currently, the file_operations structure does not specify the .owner field, which could allow the module to be unloaded while user-space processes are still interacting with the device. Additionally, the tlclk_cleanup() function frees the alarm_events memory before ensuring that blocked processes in the waitqueue are fully awakened and that the switchover_timer has completed.
To address these cases, this patch:
- Sets '.owner = THIS_MODULE' in tlclk_fops to safely defer module unloading while the device is in use.
- Updates tlclk_cleanup() to explicitly wake up all blocked readers (wake_up_all), properly release hardware I/O regions, and safely delete the timer (timer_delete_sync) prior to freeing memory.
--- drivers/char/tlclk.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/char/tlclk.c +4 -0
@@ -264,6 +264,7 @@ static ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count, }static const struct file_operations tlclk_fops = { + .owner =THIS_MODULE , .read = tlclk_read, .open = tlclk_open, .release = tlclk_release,
@@ -837,6 +838,9 @@ static void __exit tlclk_cleanup(void)misc_deregister (&tlclk_miscdev);unregister_chrdev (tlclk_major,"telco_clock" ); + got_event =1 ; +wake_up_all (&wq); +release_region (TLCLK_BASE ,8 );timer_delete_sync (&switchover_timer);kfree (alarm_events);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 895/2077 hpet: Check ACPI_COMPANION() against NULL at probe time
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit fa5e2952341b792b72d5410dbfcd0b2ac8046d2a ]
Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.
Accordingly, add a requisite ACPI_COMPANION() check against NULL to the hpet driver.
--- drivers/char/hpet.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/char/hpet.c +5 -1
@@ -976,10 +976,14 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)static int hpet_acpi_probe (struct platform_device *pdev) { -struct acpi_device *device =ACPI_COMPANION (&pdev->dev); +struct acpi_device *device;acpi_status result;struct hpet_data data; + device =ACPI_COMPANION (&pdev->dev); +if (!device) +return -ENODEV ; +memset (&data,0 ,sizeof (data)); result =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 896/2077 sonypi: Check ACPI_COMPANION() against NULL at probe time
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 950f35211b85db26fc1aae67bf1e14ccef393a0a ]
Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.
Accordingly, add a requisite ACPI_COMPANION() check against NULL to the sonypi driver.
--- drivers/char/sonypi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/char/sonypi.c +5 -1
@@ -1117,7 +1117,11 @@ static int sonypi_disable(void)#ifdef CONFIG_ACPI static int sonypi_acpi_probe (struct platform_device *pdev) { -struct acpi_device *device =ACPI_COMPANION (&pdev->dev); +struct acpi_device *device; + + device =ACPI_COMPANION (&pdev->dev); +if (!device) +return -ENODEV ; sonypi_acpi_device = device;strcpy (acpi_device_name (device),"Sony laptop hotkeys" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 897/2077 gpib: fix double decrement of descriptor_busy in command_ioctl()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adam Crosser <[email protected]>
[ Upstream commit c4faab452b3c1ada003d49c477609dd80523b9bf ]
commit d1857f8296dc ("gpib: fix use-after-free in IO ioctl handlers") introduced a descriptor_busy reference counter to pin struct gpib_descriptor across IO ioctl operations. In command_ioctl(), the error path inside the loop decrements descriptor_busy and breaks, but execution then falls through to the unconditional decrement after the loop, underflowing the counter to -1.
This re-enables the use-after-free that the original fix was meant to
prevent: a concurrent close_dev_ioctl() sees descriptor_busy == 0 on an actively-used descriptor and frees it.
Remove the early decrement from the error path. The post-loop decrement already handles all exit paths, matching the correct pattern used in read_ioctl() and write_ioctl().
--- drivers/gpib/common/gpib_os.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpib/common/gpib_os.c +0 -1
@@ -1017,7 +1017,6 @@ static int command_ioctl(struct gpib_file_private *file_priv, userbuf += bytes_written;if (retval <0 ) {atomic_set (&desc->io_in_progress,0 ); -atomic_dec (&desc->descriptor_busy);wake_up_interruptible (&board->wait);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 898/2077 gpib: cb7210: Fix region leak when request_irq fails
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit 5ad28496055858166eb2268344c8fda2c26d3561 ]
When request_irq() fails, the region allocated by request_region() is not released. Fix this by calling release_region() before returning.
Smatch warning:
drivers/gpib/cb7210/cb7210.c:1068 cb_isa_attach() warn: 'config->ibbase'
from __request_region() not released on lines: 1064.
--- drivers/gpib/cb7210/cb7210.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpib/cb7210/cb7210.c +1 -0
@@ -1062,6 +1062,7 @@ static int cb_isa_attach(struct gpib_board *board, const struct gpib_board_confi// install interrupt handler if (request_irq (config->ibirq, cb7210_interrupt, isr_flags,DRV_NAME , board)) {dev_err (board->gpib_dev,"failed to obtain IRQ %d\n" , config->ibirq); +release_region (nec7210_iobase (cb_priv), cb7210_iosize);return -EBUSY ; } cb_priv->irq = config->ibirq;
Signature · 1 line
2.53.0
Re: [PATCH 7.1 0898/2077] gpib: cb7210: Fix region leak when request_irq fails
Quoted 7 lines · Greg Kroah-Hartman
7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit
5ad28496055858166eb2268344c8fda2c26d3561]
This was reverted upstream by:285ecb7d9e1b Revert "gpib: cb7210: Fix region leak when request_irq fails"
Quoted 28 lines
When
request_irq()fails, the region allocated byrequest_region()is not released. Fix this by callingrelease_region()before returning.Smatch warning:
drivers/gpib/cb7210/cb7210.c:1068 cb_isa_attach() warn: 'config->ibbase'from
__request_region()not released on lines: 1064.Fixes 82e3508046f9 ("staging: gpib: cb7210 console messaging cleanup")Signed-off-by Hongling Zeng <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- drivers/gpib/cb7210/cb7210.c | 1 + 1 file changed, 1 insertion(+)drivers/gpib/cb7210/cb7210.c +1
-0@@ -1062,6 +1062,7 @@ static int cb_isa_attach(struct gpib_board *board, const struct gpib_board_confi// install interrupt handler if (request_irq (config->ibirq, cb7210_interrupt, isr_flags,DRV_NAME , board)) {dev_err (board->gpib_dev,"failed to obtain IRQ %d\n" , config->ibirq); +release_region (nec7210_iobase (cb_priv), cb7210_iosize);return -EBUSY ; } cb_priv->irq = config->ibirq;
Signature · 2 lines
js suse labs
Greg Kroah-Hartman
maintainerRe: [PATCH 7.1 0898/2077] gpib: cb7210: Fix region leak when request_irq fails
Quoted 11 lines · Jiri Slaby
Quoted 7 lines · Greg Kroah-Hartman
7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit
5ad28496055858166eb2268344c8fda2c26d3561]This was reverted upstream by:
285ecb7d9e1bRevert "gpib: cb7210: Fix region leak whenrequest_irqfails"
Ah, good catch, I missed that, thanks.
Now queued up.
Sasha Levin
maintainerRe: [PATCH 7.1 0898/2077] gpib: cb7210: Fix region leak when request_irq fails
In reply to Jiri SlabyQuoted 2 lines · Jiri Slaby
This was reverted upstream by:
285ecb7d9e1bRevert "gpib: cb7210: Fix region leak whenrequest_irqfails"
For 7.1 Greg already queued the upstream revert, so the fix and the revert cancel out there and both stay in the queue.
The same broken fix was also still queued for 6.18 (as a backport of the sibling commit 2eae90a457ba, which upstream likewise reverted via 05d5d79440c2) - dropped it from the 6.18 queue. Both upstream commits are now recorded in our dropped-commits list so they don't get picked up again.
Thanks for the report.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 899/2077 clk: renesas: rzg2l: Rename iterator in for_each_mod_clock() to avoid shadowing
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
[ Upstream commit 1f10c4509649e7c5f6d5d3acccf3ef6fbb5cdd46 ]
Rename the internal loop iterator variable in the for_each_mod_clock() macro from 'i' to '__i'.
The current naming conflicts with local loop variables named 'i' inside code blocks that utilize the macro, triggering compiler warnings due to variable shadowing:
drivers/clk/renesas/rzg2l-cpg.c:1494:36: warning: declaration of i shadows a previous local [-Wshadow]
1494 | for (unsigned int i = 0; i < clk->num_shared_mstop_clks; i++)
Using a unique identifier for the macro-internal iterator resolves the shadowing warnings globally across all macro expansions.
--- drivers/clk/renesas/rzg2l-cpg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/renesas/rzg2l-cpg.c +3 -3
@@ -1340,10 +1340,10 @@ struct mod_clock {#define to_mod_clock (_hw) container_of(_hw, struct mod_clock, hw)#define for_each_mod_clock (mod_clock, hw, priv) \ - for (unsigned int i = 0; (priv) && i < (priv)->num_mod_clks; i++) \ - if ((priv)->clks[(priv)->num_core_clks + i] == ERR_PTR(-ENOENT)) \ + for (unsigned int __i = 0; (priv) && __i < (priv)->num_mod_clks; __i++) \ + if ((priv)->clks[(priv)->num_core_clks + __i] == ERR_PTR(-ENOENT)) \ continue; \ - else if (((hw) = __clk_get_hw((priv)->clks[(priv)->num_core_clks + i])) && \ + else if (((hw) = __clk_get_hw((priv)->clks[(priv)->num_core_clks + __i])) && \ ((mod_clock) = to_mod_clock(hw)))/* Need to be called with a lock held to avoid concurrent access to mstop->usecnt. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 900/2077 docs: threat-model: add missing closing parenthesis
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baruch Siach <[email protected]>
[ Upstream commit 89f332c1ef348e260a885085cd7821d6d72db7ec ]
Message-ID: <da8ee1e8b4e99261ec11544c4e1a4f81316ae965.1779032501.git.baruch@tkos.co.il>
--- Documentation/process/threat-model.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/process/threat-model.rst +1 -1
@@ -176,7 +176,7 @@ regular bug: * problems seen only under development simulators, emulators, or combinations that do not exist on real systems at the time of reporting (issues involving tens of millions of threads, tens of thousands of CPUs, - unrealistic CPU frequencies, RAM sizes or disk capacities, network speeds. + unrealistic CPU frequencies, RAM sizes or disk capacities, network speeds). * issues whose reproduction requires hardware modification or emulation, including fake USB devices that pretend to be another one.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 901/2077 powerpc tools perf: Initialize error code in auxtrace_record_init function
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Athira Rajeev <[email protected]>
[ Upstream commit 789d22d77879eabb042627f6627cdb62787bc142 ]
perf trace record fails some cases in powerpc
# perf test "perf trace record and replay" 128: perf trace record and replay : FAILED!
# perf trace record sleep 1
# echo $?
32This is happening because of non-zero err value from auxtrace_record__init() function.
static int record__auxtrace_init(struct record *rec)
{
int err;
if ((rec->opts.auxtrace_snapshot_opts || rec->opts.auxtrace_sample_opts)
&& record__threads_enabled(rec)) {
pr_err("AUX area tracing options are not available in parallel streaming mode.\n");
return -EINVAL;
}
if (!rec->itr) {
rec->itr = auxtrace_record__init(rec->evlist, &err);
if (err)
return err;
}Here "int err" is not initialised. The code expects "err" to be set from auxtrace_record__init() function.
Update auxtrace_record__init() in arch/powerpc/util/auxtrace.c to clear err value in the beginning.
- Clear err value in beginning of function. Any fail later will set appropriate return code to err.
- Even if we haven't found any event for auxtrace, perf record should continue for other events. NULL return
will indicate that there is no auxtrace record initialized.
- Not having "err" set here will affect monitoring of other events also because perf record will fail seeing random value in err.
Set err to -EINVAL before invoking auxtrace_record__init() in builtin-record.c
With the fix,
# perf trace record sleep 1 [ perf record: Woken up 2 times to write data ] [ perf record: Captured and wrote 0.033 MB perf.data (228 samples) ]
--- tools/perf/arch/powerpc/util/auxtrace.c | 6 ++++++ tools/perf/builtin-record.c | 1 + 2 files changed, 7 insertions(+)
tools/perf/arch/powerpc/util/auxtrace.c +6 -0
@@ -71,6 +71,12 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,struct evsel *pos;int found =0 ; +/* +* Set err value to zero here. Any fail later +* will set appropriate return code to err. +*/ + *err =0 ; +evlist__for_each_entry (evlist, pos) {if (strstarts (pos->name,"vpa_dtl" )) { found =1 ;
tools/perf/builtin-record.c +1 -0
@@ -865,6 +865,7 @@ static int record__auxtrace_init(struct record *rec) }if (!rec->itr) { + err = -EINVAL ; rec->itr =auxtrace_record__init (rec->evlist, &err);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 902/2077 PCI: qcom: Disable ASPM L0s for SA8775P
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
[ Upstream commit 29f692985819f4089f02a86e151a72f6d4cdd90d ]
Due to a hardware issue, L0s is not properly supported by the PCIe controller on the SA8775p SoC. If enabled, the L0s to L0 transition triggers below correctable AER errors and may also affect link stability:
pcieport 0000:00:00.0: PME: Signaling with IRQ 332
pcieport 0000:00:00.0: AER: enabled with IRQ 332
pcieport 0000:00:00.0: AER: Correctable error message received from 0000:01:00.0 pci 0000:01:00.0: PCIe Bus Error: severity=Correctable, type=Data Link Layer, (Transmitter ID)
pci 0000:01:00.0: device [17cb:1103] error status/mask=00001000/0000e000
pci 0000:01:00.0: [12] Timeout
pcieport 0000:00:00.0: AER: Multiple Correctable error message received from 0000:01:00.0 pcieport 0000:00:00.0: PCIe Bus Error: severity=Correctable, type=Data Link Layer, (Transmitter ID)
pcieport 0000:00:00.0: device [17cb:0115] error status/mask=00001000/0000e000
pcieport 0000:00:00.0: [12] Timeout
Hence, disable L0s for the SA8775p SoC to allow it to properly function by sacrificing a little bit of power saving.
--- drivers/pci/controller/dwc/pcie-qcom.c | 1 + 1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pcie-qcom.c +1 -0
@@ -1473,6 +1473,7 @@ static const struct qcom_pcie_cfg cfg_1_9_0 = {static const struct qcom_pcie_cfg cfg_1_34_0 = { .ops = &ops_1_9_0, .override_no_snoop = true, + .no_l0s = true, };static const struct qcom_pcie_cfg cfg_2_1_0 = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 903/2077 timers/migration: Update stale @online doc to @available
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 45a13ba52c82dbec9715222c51e629e85daa37d7 ]
Commit 8312cab5ff47 ("timers/migration: Rename 'online' bit to 'available'") renamed the 'online' field of struct tmigr_cpu to 'available'. The kernel doc comment above the struct still describes the old field name.
Update it to reflect the actual field name and use the 'available' wording in the description.
--- kernel/time/timer_migration.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
kernel/time/timer_migration.h +10 -8
@@ -75,15 +75,17 @@ struct tmigr_group {/** * struct tmigr_cpu - timer migration per CPU group * @lock: Lock protecting the tmigr_cpu group information -* @online: Indicates whether the CPU is online; In deactivate path -* it is required to know whether the migrator in the top -* level group is to be set offline, while a timer is -* pending. Then another online CPU needs to be notified to -* take over the migrator role. Furthermore the information -* is required in CPU hotplug path as the CPU is able to go -* idle before the timer migration hierarchy hotplug AP is -* reached. During this phase, the CPU has to handle the +* @available: Indicates whether the CPU is available for handling +* global timers. In the deactivate path it is required to +* know whether the migrator in the top level group is to +* be set offline, while a timer is pending. Then another +* available CPU needs to be notified to take over the +* migrator role. Furthermore the information is required +* in the CPU hotplug path as the CPU is able to go idle +* before the timer migration hierarchy hotplug callback is +* reached. During this phase, the CPU has to handle the * global timers on its own and must not act as a migrator. +* @idle: Indicates whether the CPU is idle in the timer migration * hierarchy * @remote: Is set when timers of the CPU are expired remotely
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 904/2077 perf header: Sanity check HEADER_EVENT_DESC attr.size before swap
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 944f65c8b8231d26d4db6be67bcb641142603cb4 ]
read_event_desc() reads nre (event count), sz (attr size), and nr (IDs per event) from the file and uses them to control allocations and loops without validating them against the section size.
A crafted perf.data could trigger large allocations or many loop iterations before __do_read() eventually rejects the reads.
Add bounds checks in read_event_desc():
- Reject sz smaller than PERF_ATTR_SIZE_VER0.
- Require at least one event (nre > 0).
- Check that nre events fit in the remaining section, using the minimum per-event footprint of sz + sizeof(u32).
- Pre-swap attr->size to native byte order, then reject values below PERF_ATTR_SIZE_VER0 or above sz before calling perf_event__attr_swap() to prevent heap out-of-bounds access.
- Handle ABI0 (attr.size == 0): substitute PERF_ATTR_SIZE_VER0, and on native-endian files write the value back so free_event_desc() does not treat the zero as its end-of-array sentinel (it iterates while attr.size != 0). The swap path skips the write-back — perf_event__attr_swap() has its own ABI0 fallback that sets VER0 after swapping.
- Check that nr IDs fit in the remaining section before allocating.
--- tools/perf/util/header.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
tools/perf/util/header.c +54 -0
@@ -2135,9 +2135,28 @@ static struct evsel *read_event_desc(struct feat_fd *ff)if (do_read_u32 (ff, &nre)) goto error; +/* Size of each of the nre attributes. */ if (do_read_u32 (ff, &sz)) goto error; +/* +* Require at least one event with an attr no smaller than the +* first published struct, and reject sz values where +* sz + sizeof(u32) would overflow size_t (possible on 32-bit) +* or nre == UINT32_MAX where nre + 1 wraps to 0 in the calloc. +* +* The minimum section footprint per event is sz bytes for the +* attr plus a u32 for the id count, check that nre events fit. +*/ +if (!nre || sz <PERF_ATTR_SIZE_VER0 || + sz > ff->size || (size_t )sz >SIZE_MAX -sizeof (u32) || + nre ==UINT32_MAX || + nre > (ff->size - ff->offset) / (sz +sizeof (u32))) { +pr_err ("Invalid HEADER_EVENT_DESC: nre=%u sz=%u (min %d)\n" , + nre, sz,PERF_ATTR_SIZE_VER0 ); + goto error; + } +/* buffer to hold on file attr struct */ buf =malloc (sz);if (!buf)
@@ -2153,6 +2172,9 @@ static struct evsel *read_event_desc(struct feat_fd *ff) msz = sz;for (i =0 , evsel = events; i < nre; evsel++, i++) { +struct perf_event_attr *attr = buf; +u32 attr_size; + evsel->core.idx = i;/*
@@ -2162,6 +2184,32 @@ static struct evsel *read_event_desc(struct feat_fd *ff)if (__do_read (ff, buf, sz)) goto error; +/* Reject before attr_swap to prevent OOB via bswap_safe() */ + attr_size = ff->ph->needs_swap ?bswap_32 (attr->size) : attr->size; +/* ABI0: size == 0 means the producer didn't set it */ +if (!attr_size) { + attr_size =PERF_ATTR_SIZE_VER0 ; +/* +* Write back so free_event_desc() doesn't +* treat this event as the end-of-array sentinel +* (it iterates while attr.size != 0). +* +* Only for native — the swap path must NOT +* write native-endian VER0 here because +* perf_event__attr_swap() would re-swap it +* to 0x40000000, defeating bswap_safe() bounds. +* perf_event__attr_swap() has its own ABI0 +* fallback that sets VER0 after swapping. +*/ +if (!ff->ph->needs_swap) + attr->size = attr_size; + } +if (attr_size <PERF_ATTR_SIZE_VER0 || attr_size > sz) { +pr_err ("Event %d attr.size (%u) invalid (min: %d, max: %u)\n" , + i, attr_size,PERF_ATTR_SIZE_VER0 , sz); + goto error; + } +if (ff->ph->needs_swap)perf_event__attr_swap (buf);
@@ -2183,6 +2231,12 @@ static struct evsel *read_event_desc(struct feat_fd *ff)if (!nr)continue ; +/* Prevent oversized allocation from crafted nr */ +if (nr > (ff->size - ff->offset) /sizeof (*id)) { +pr_err ("Event %d: id count %u exceeds remaining section\n" , i, nr); + goto error; + } + id =calloc (nr,sizeof (*id));if (!id) goto error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 905/2077 perf header: Validate bitmap size before allocating in do_read_bitmap()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 3669697bda41c562d90eb38f54881cc02ef3d51c ]
do_read_bitmap() reads a u64 bit count from the file and passes it to bitmap_zalloc() without checking it against the remaining section size. A crafted perf.data could trigger a large allocation that would only fail later when the per-element reads exceed section bounds.
Additionally, bitmap_zalloc() takes an int parameter, so a crafted size with bits set above bit 31 (e.g. 0x100000040) would pass the section bounds check but truncate when passed to bitmap_zalloc(), allocating a much smaller buffer than the subsequent read loop expects.
Reject size values that exceed INT_MAX, and check that the data needed (BITS_TO_U64(size) u64 values) fits in the remaining section before allocating. Switch from bitmap_zalloc() to calloc() of u64 units so the allocation size matches the u64 read/write granularity and avoids unsigned long vs u64 mismatch on 32-bit architectures.
Fix do_write_bitmap() to use memcpy to read u64-sized chunks from the unsigned long bitmap, preventing out-of-bounds reads on 32-bit systems where sizeof(unsigned long) is 4 but the bitmap is stored in u64 units.
Fix process_mem_topology() minimum section size: the check used nr * 2 * sizeof(u64) per node, but do_read_bitmap() reads an additional u64 for the bitmap size, so the minimum is 3 * sizeof(u64).
Fix memory leak in process_mem_topology() error paths: replace free(nodes) with memory_node__delete_nodes() to free per-node bitmaps allocated by do_read_bitmap().
Currently used by process_mem_topology() for HEADER_MEM_TOPOLOGY.
--- tools/perf/util/header.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
tools/perf/util/header.c +29 -5
@@ -158,15 +158,25 @@ int do_write(struct feat_fd *ff, const void *buf, size_t size)/* Return: 0 if succeeded, -ERR if failed. */ static int do_write_bitmap (struct feat_fd *ff,unsigned long *set,u64 size) { -u64 *p = (u64 *) set; +size_t byte_size =BITS_TO_LONGS (size) *sizeof (unsigned long );int i, ret; ret =do_write (ff, &size,sizeof (size));if (ret <0 )return ret; +/* +* The on-disk format uses u64 elements, but the in-memory bitmap +* uses unsigned long, which is only 4 bytes on 32-bit architectures. +* Copy with bounded size so the last element doesn't read past the +* bitmap allocation when BITS_TO_LONGS(size) is odd. +*/ for (i =0 ; (u64 ) i <BITS_TO_U64 (size); i++) { - ret =do_write (ff, p + i,sizeof (*p)); +u64 val =0 ; +size_t off = i *sizeof (val); + +memcpy (&val, (char *)set + off,min (sizeof (val), byte_size - off)); + ret =do_write (ff, &val,sizeof (val));if (ret <0 )return ret; }
@@ -297,7 +307,20 @@ static int do_read_bitmap(struct feat_fd *ff, unsigned long **pset, u64 *psize)if (ret)return ret; - set =bitmap_zalloc (size); +/* Bitmap APIs use int for nbits; reject u64 values that truncate. */ +if (size >INT_MAX || +BITS_TO_U64 (size) > (ff->size - ff->offset) /sizeof (u64)) { +pr_debug ("do_read_bitmap: size %" PRIu64" exceeds section bounds\n" , size); +return -1 ; + } + +/* +* bitmap_zalloc() allocates in unsigned long units, which are only +* 4 bytes on 32-bit architectures. The read loop below casts the +* buffer to u64 * and writes 8-byte elements, so allocate in u64 +* units to ensure the buffer is large enough. +*/ + set =calloc (BITS_TO_U64 (size),sizeof (u64));if (!set)return -ENOMEM ;
@@ -3411,7 +3434,8 @@ static int process_mem_topology(struct feat_fd *ff,return -1 ; } -if (ff->size <3 *sizeof (u64) + nr *2 *sizeof (u64)) { +/* Per node: node_id(u64) + mem_size(u64) + bitmap_nr_bits(u64) */ +if (ff->size <3 *sizeof (u64) + nr *3 *sizeof (u64)) {pr_err ("Invalid HEADER_MEM_TOPOLOGY: section too small (%zu) for %llu nodes\n" , ff->size, (unsigned long long )nr);return -1 ;
@@ -3446,7 +3470,7 @@ static int process_mem_topology(struct feat_fd *ff, out:if (ret) -free (nodes); +memory_node__delete_nodes (nodes, nr);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 906/2077 iio: light: si1133: reset counter to prevent race condition
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
[ Upstream commit 0a5f45ed2342aabae1e32c72558d15be28940a95 ]
Sashiko reported a potential race condition happening when the driver returns an errno after a timeout in the si1133_command() function. The premature exit causes the hardware and software counters to become out of sync by not updating data->rsp_seq, therefore the internal hardware counter keeps incrementing.
Fix this by adding a call to si1133_cmd_reset_counter() before returning from timeout.
--- drivers/iio/light/si1133.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iio/light/si1133.c +5 -0
@@ -427,6 +427,11 @@ static int si1133_command(struct si1133_data *data, u8 cmd)dev_warn (dev,"Failed to read command 0x%02x, ret=%d\n" , cmd, err); +/* +* Reset counter on err to prevent software and hardware +* counters being out of sync. +*/ +si1133_cmd_reset_counter (data); goto out; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 907/2077 iio: light: si1133: prevent race condition on timeout
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
[ Upstream commit 8c50a95ceb230d17801758a9e41ffbbbe46f8b4d ]
Sashiko reported a bug where the si1133_command exits on timeout without halting the sensor or masking the interrupt. If the sensor completes the command later, any subsequent command to the sensor will cause the IRQ handler to complete immediately, returning stale data to the driver all while the command hasn't finished yet, shifting all potential reads in the future.
Fix this by masking the IRQ if wait_for_completion_timeout() fails. When initiating a new command, do a dummy read of the IRQ_STATUS register and turn the IRQ back on.
--- drivers/iio/light/si1133.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/iio/light/si1133.c +8 -1
@@ -395,8 +395,14 @@ static int si1133_command(struct si1133_data *data, u8 cmd) expected_seq = (data->rsp_seq +1 ) &SI1133_MAX_CMD_CTR ; -if (cmd ==SI1133_CMD_FORCE ) +if (cmd ==SI1133_CMD_FORCE ) { +/* Flush pending IRQs from a previous timeout. */ +regmap_read (data->regmap,SI1133_REG_IRQ_STATUS , &resp); +regmap_write (data->regmap,SI1133_REG_IRQ_ENABLE , +SI1133_IRQ_CHANNEL_ENABLE ); +reinit_completion (&data->completion); + } err =regmap_write (data->regmap,SI1133_REG_COMMAND , cmd);if (err) {
@@ -409,6 +415,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)/* wait for irq */ if (!wait_for_completion_timeout (&data->completion,msecs_to_jiffies (SI1133_COMPLETION_TIMEOUT_MS ))) { +regmap_write (data->regmap,SI1133_REG_IRQ_ENABLE ,0 ); err = -ETIMEDOUT ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 908/2077 iio: magnetometer: ak8975: fix potential kernel stack memory leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
[ Upstream commit a9a00d727b7bbc5e913a919530a9dd468935bf95 ]
Currently in the AK8975 driver there are four instances where potential uninitialized kernel stack memory leaks can occur. If i2c_smbus_read_i2c_block_data_or_emulated() returns a value less than the size of the buffer, uninitialized bytes are retained in the buffer and later the buffer is passed on to IIO buffers, potentially leaking memory to userspace.
Fix this by adding checks whether the return value of the function is equal to the size of the buffer and subsequently if the value is lesser than zero to distinguish from a returned error code.
--- drivers/iio/magnetometer/ak8975.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/iio/magnetometer/ak8975.c +14 -0
@@ -495,6 +495,10 @@ static int ak8975_who_i_am(struct i2c_client *client,dev_err (&client->dev,"Error reading WIA\n" );return ret; } +if (ret !=sizeof (wia_val)) { +dev_err (&client->dev,"Error reading WIA\n" ); +return -EIO ; + }if (wia_val[0 ] !=AK8975_DEVICE_ID )return -ENODEV ;
@@ -619,6 +623,10 @@ static int ak8975_setup(struct i2c_client *client)dev_err (&client->dev,"Not able to read asa data\n" );return ret; } +if (ret !=sizeof (data->asa)) { +dev_err (&client->dev,"Error reading asa data\n" ); +return -EIO ; + }/* After reading fuse ROM data set power-down mode */ ret =ak8975_set_mode (data,POWER_DOWN );
@@ -758,6 +766,10 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) sizeof(rval), (u8*)&rval);if (ret <0 ) goto exit; +if (ret !=sizeof (rval)) { + ret = -EIO ; + goto exit; + }/* Read out ST2 for release lock on measurement data. */ ret =i2c_smbus_read_byte_data (client, data->def->ctrl_regs[ST2 ]);
@@ -874,6 +886,8 @@ static void ak8975_fill_buffer(struct iio_dev *indio_dev) (u8 *)fval);if (ret <0 ) goto unlock; +if (ret !=sizeof (fval)) + goto unlock;mutex_unlock (&data->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 909/2077 iio: adc: xilinx-ams: fix out-of-bounds channel lookup in event handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guilherme Ivo Bozi <[email protected]>
[ Upstream commit 947eb6f0a274f8b15a0248051a65b069effd5057 ]
ams_event_to_channel() may return a pointer past the end of dev->channels when no matching scan_index is found. This can lead to invalid memory access in ams_handle_event().
Add a bounds check in ams_event_to_channel() and return NULL when no channel is found. Also guard the caller to safely handle this case.
--- drivers/iio/adc/xilinx-ams.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iio/adc/xilinx-ams.c +5 -0
@@ -871,6 +871,9 @@ static const struct iio_chan_spec *ams_event_to_channel(struct iio_dev *dev,if (dev->channels[i].scan_index == scan_index)break ; +if (i == dev->num_channels) +return NULL ; +return &dev->channels[i]; }
@@ -1012,6 +1015,8 @@ static void ams_handle_event(struct iio_dev *indio_dev, u32 event)const struct iio_chan_spec *chan; chan =ams_event_to_channel (indio_dev, event); +if (!chan) +return ;if (chan->type ==IIO_TEMP ) {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 910/2077 iio: accel: mma8452: handle I2C read error(s) in mma8452_read()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanjay Chitroda <[email protected]>
[ Upstream commit 5bdff291d20c31b365d9ddfe9c426fbfb41da5bb ]
Currently, If i2c_smbus_read_i2c_block_data() fails but mma8452_set_runtime_pm_state() succeeds, mma8452_read() returns 0.
As a result, the caller mma8452_read_raw() assumes the read was successful and proceeds to use a buffer containing uninitialized stack memory.
Add proper checking of the I2C read return value and propagate errors to the caller.
--- drivers/iio/accel/mma8452.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/accel/mma8452.c +2 -0
@@ -252,6 +252,8 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) ret =i2c_smbus_read_i2c_block_data (data->client,MMA8452_OUT_X ,3 *sizeof (__be16), (u8 *)buf); +if (ret <0 ) +return ret; ret =mma8452_set_runtime_pm_state (data->client, false);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 911/2077 iio: tcs3472: power down chip on probe failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Conte <[email protected]>
[ Upstream commit b39f3bb9f5580d19bc0c10dea9224d75fed45f1d ]
If tcs3472_probe() fails after enabling the chip (by writing PON | AEN to the ENABLE register), the error paths return without powering down the device.
Add an 'error_powerdown' label at the end of the cleanup chain that calls tcs3472_powerdown() to power down the chip. The existing label cascade is rerouted to fall through to the new label.
Move tcs3472_powerdown() above tcs3472_probe() so the probe can call it without a forward declaration.
Found by code inspection while reviewing the probe error paths in preparation for the devm_ conversion.
--- drivers/iio/light/tcs3472.c | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
drivers/iio/light/tcs3472.c +20 -18
@@ -440,6 +440,23 @@ static const struct iio_info tcs3472_info = { .attrs = &tcs3472_attribute_group, }; +static int tcs3472_powerdown (struct tcs3472_data *data) +{ +int ret; +u8 enable_mask =TCS3472_ENABLE_AEN |TCS3472_ENABLE_PON ; + +mutex_lock (&data->lock); + + ret =i2c_smbus_write_byte_data (data->client,TCS3472_ENABLE , + data->enable & ~enable_mask); +if (!ret) + data->enable &= ~enable_mask; + +mutex_unlock (&data->lock); + +return ret; +} +static int tcs3472_probe (struct i2c_client *client) {struct tcs3472_data *data;
@@ -513,7 +530,7 @@ static int tcs3472_probe(struct i2c_client *client) ret =iio_triggered_buffer_setup (indio_dev,NULL , tcs3472_trigger_handler,NULL );if (ret <0 ) -return ret; + goto error_powerdown;if (client->irq) { ret = request_threaded_irq(client->irq, NULL,
@@ -536,23 +553,8 @@ static int tcs3472_probe(struct i2c_client *client)free_irq (client->irq, indio_dev); buffer_cleanup:iio_triggered_buffer_cleanup (indio_dev); -return ret; -} - -static int tcs3472_powerdown (struct tcs3472_data *data) -{ -int ret; -u8 enable_mask =TCS3472_ENABLE_AEN |TCS3472_ENABLE_PON ; - -mutex_lock (&data->lock); - - ret =i2c_smbus_write_byte_data (data->client,TCS3472_ENABLE , - data->enable & ~enable_mask); -if (!ret) - data->enable &= ~enable_mask; - -mutex_unlock (&data->lock); - +error_powerdown: +tcs3472_powerdown (data);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 912/2077 clk: at91: keep securam node alive while mapping it
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 22fa1c39ba6fe726b547c877c924379b7fee260a ]
pmc_register_ops() gets an owned reference to the "atmel,sama5d2-securam" node with of_find_compatible_node(). The success path dropped that reference before passing the node to of_iomap(), leaving of_iomap() to consume a node pointer after the caller had released its reference.
Move of_node_put() after of_iomap() so the node remains referenced for the mapping operation. The unavailable-node error path already releases the reference.
--- drivers/clk/at91/pmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/at91/pmc.c +1 -1
@@ -180,9 +180,9 @@ static int __init pmc_register_ops(void)of_node_put (np);return -ENODEV ; } -of_node_put (np); at91_pmc_backup_suspend =of_iomap (np,0 ); +of_node_put (np);if (!at91_pmc_backup_suspend) {pr_warn ("%s(): unable to map securam\n" , __func__);return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 913/2077 HID: logitech-hidpp: remove excess kernel-doc member in hidpp_scroll_counter
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit f22a5db8a7d38152556f230d6d68e59dbc27971b ]
The @dev member described in the kernel-doc does not exist in the struct. Remove the stale entry.
--- drivers/hid/hid-logitech-hidpp.c | 1 - 1 file changed, 1 deletion(-)
drivers/hid/hid-logitech-hidpp.c +0 -1
@@ -164,7 +164,6 @@ struct hidpp_battery {/** * struct hidpp_scroll_counter - Utility class for processing high-resolution * scroll events. -* @dev: the input device for which events should be reported. * @wheel_multiplier: the scalar multiplier to be applied to each wheel event * @remainder: counts the number of high-resolution units moved since the last * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 914/2077 docs: changes.rst: restore pahole 1.26 minimum (regressed by sort)
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 2c1ccd9a1d786503086e83fe83e5c3b3c953b70e ]
Commit 9edd04c4189e ("docs: Raise minimum pahole version to 1.26 for KF_IMPLICIT_ARGS kfuncs") raised the minimum required pahole version from 1.22 to 1.26 in the requirements table and added a paragraph explaining the failure mode for distributions still shipping pahole v1.25 (e.g. Ubuntu 24.04 LTS).
The next day, commit ece7e57afd51 ("docs: changes.rst and ver_linux:
sort the lists") came through a different tree (docs vs sched_ext) and re-flowed the table alphabetically, but its base did not include 9edd04c4189e. When the two commits met in mainline, the textual rewrite of the table won and the version bump was lost. The added "Since Linux 7.0..." paragraph also disappeared.
The result is that changes.rst on master (v7.1-rc5) lists pahole 1.22 again, even though sched_ext kfuncs annotated with KF_IMPLICIT_ARGS genuinely require v1.26 to produce a correct vmlinux BTF. Users on distributions with pahole v1.25 hit "func_proto incompatible with vmlinux" when loading any sched_ext BPF program (scx_simple, scx_qmap, ...) and have no documentation pointing them at the version gap.
Restore both changes from 9edd04c4189e.
Message-ID: <[email protected]>
--- Documentation/process/changes.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/process/changes.rst +6 -1
@@ -53,7 +53,7 @@ mcelog 0.6 mcelog --version mkimage (optional) 2017.01 mkimage --version nfs-utils 1.0.5 showmount --version openssl & libcrypto 1.0.0 openssl version -pahole 1.22 pahole --version +pahole 1.26 pahole --version pcmciautils 004 pccardctl -V PPP 2.4.0 pppd --version procps 3.2.0 ps --version
@@ -147,6 +147,11 @@ Since Linux 5.2, if CONFIG_DEBUG_INFO_BTF is selected, the build system generates BTF (BPF Type Format) from DWARF in vmlinux, a bit later from kernel modules as well. This requires pahole v1.22 or later. +Since Linux 7.0, kfuncs annotated with KF_IMPLICIT_ARGS require pahole v1.26 +or later. Without it, such kfuncs will have incorrect BTF prototypes in +vmlinux, causing BPF programs to fail to load with a "func_proto incompatible +with vmlinux" error. Many sched_ext kfuncs are affected. + It is found in the 'dwarves' or 'pahole' distro packages or from https://fedorapeople.org/~acme/dwarves/.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 915/2077 clk: spacemit: k3: Switch to pll2_d6 as parent for PCIe clock
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yixun Lan <[email protected]>
[ Upstream commit d8a4cef90b1a4ae9196a5bfba683eb9a0c75acdc ]
According to SpacemiT updated docs, the PCIe master and slave clock's parent is the pll2_d6 clock, so fix it.
--- drivers/clk/spacemit/ccu-k3.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/clk/spacemit/ccu-k3.c +10 -10
@@ -947,16 +947,16 @@ static const struct clk_parent_data edp1_pclk_parents[] = { };CCU_MUX_GATE_DEFINE (edp1_pxclk, edp1_pclk_parents,APMU_LCD_EDP_CTRL ,18 ,1 ,BIT (17 ),0 ); -CCU_GATE_DEFINE (pciea_mstr_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_A ,BIT (2 ),0 ); -CCU_GATE_DEFINE (pciea_slv_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_A ,BIT (1 ),0 ); -CCU_GATE_DEFINE (pcieb_mstr_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_B ,BIT (2 ),0 ); -CCU_GATE_DEFINE (pcieb_slv_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_B ,BIT (1 ),0 ); -CCU_GATE_DEFINE (pciec_mstr_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_C ,BIT (2 ),0 ); -CCU_GATE_DEFINE (pciec_slv_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_C ,BIT (1 ),0 ); -CCU_GATE_DEFINE (pcied_mstr_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_D ,BIT (2 ),0 ); -CCU_GATE_DEFINE (pcied_slv_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_D ,BIT (1 ),0 ); -CCU_GATE_DEFINE (pciee_mstr_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_E ,BIT (2 ),0 ); -CCU_GATE_DEFINE (pciee_slv_clk,CCU_PARENT_HW (axi_clk),APMU_PCIE_CLK_RES_CTRL_E ,BIT (1 ),0 ); +CCU_GATE_DEFINE (pciea_mstr_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_A ,BIT (2 ),0 ); +CCU_GATE_DEFINE (pciea_slv_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_A ,BIT (1 ),0 ); +CCU_GATE_DEFINE (pcieb_mstr_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_B ,BIT (2 ),0 ); +CCU_GATE_DEFINE (pcieb_slv_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_B ,BIT (1 ),0 ); +CCU_GATE_DEFINE (pciec_mstr_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_C ,BIT (2 ),0 ); +CCU_GATE_DEFINE (pciec_slv_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_C ,BIT (1 ),0 ); +CCU_GATE_DEFINE (pcied_mstr_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_D ,BIT (2 ),0 ); +CCU_GATE_DEFINE (pcied_slv_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_D ,BIT (1 ),0 ); +CCU_GATE_DEFINE (pciee_mstr_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_E ,BIT (2 ),0 ); +CCU_GATE_DEFINE (pciee_slv_clk,CCU_PARENT_HW (pll2_d6),APMU_PCIE_CLK_RES_CTRL_E ,BIT (1 ),0 );static const struct clk_parent_data emac_1588_parents[] = {CCU_PARENT_NAME (vctcxo_24m),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 916/2077 clk: spacemit: k3: Fix PCIe clock register offset
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yixun Lan <[email protected]>
[ Upstream commit 2f20c859a82a291483a8b3f01cbfbb1642782a14 ]
The offset of PCIe Clock CTRL register for port B and C controller was wrongly swapped, correct it here.
--- include/soc/spacemit/k3-syscon.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/soc/spacemit/k3-syscon.h +2 -2
@@ -168,8 +168,8 @@#define APMU_CPU_C2_CLK_CTRL 0x394#define APMU_CPU_C3_CLK_CTRL 0x208#define APMU_PCIE_CLK_RES_CTRL_A 0x1f0 -#define APMU_PCIE_CLK_RES_CTRL_B 0x1c8 -#define APMU_PCIE_CLK_RES_CTRL_C 0x1d0 +#define APMU_PCIE_CLK_RES_CTRL_B 0x1d0 +#define APMU_PCIE_CLK_RES_CTRL_C 0x1c8#define APMU_PCIE_CLK_RES_CTRL_D 0x1e0#define APMU_PCIE_CLK_RES_CTRL_E 0x1e8#define APMU_EMAC0_CLK_RES_CTRL 0x3e4
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 917/2077 fs/ntfs3: add bounds check to run_get_highest_vcn()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
[ Upstream commit bb11485a87fbb2254b62cfed630b699d50e57da8 ]
run_get_highest_vcn() parses a packed NTFS mapping-pairs buffer without any length bound, relying solely on a 0x00 terminator to stop. A crafted $LogFile UpdateMappingPairs record whose embedded attribute contains mapping-pairs runs without a terminator causes the function to read past the slab allocation, triggering a KASAN slab-out-of-bounds read on mount.
The sibling function run_unpack() received an analogous bounds-check in commit b62567bca474 ("ntfs3: add buffer boundary checks to run_unpack()"), but run_get_highest_vcn() was missed.
Take a run_buf_size parameter and reject any run header whose payload would extend past the buffer end, mirroring the pattern used by run_unpack(). The caller in fslog.c passes the remaining attribute bytes after the mapping-pairs offset.
KASAN report (on mainline v7.1 merge window HEAD):
BUG: KASAN: slab-out-of-bounds in run_get_highest_vcn+0x3c0/0x410 Read of size 1 at addr ffff88800e2d5400 by task mount/72 Call Trace: run_get_highest_vcn+0x3c0/0x410 do_action.isra.0+0x3ba8/0x7b50 log_replay+0x9ddd/0x10200 ntfs_loadlog_and_replay+0x4ad/0x610 ntfs_fill_super+0x214a/0x4540
--- fs/ntfs3/fslog.c | 5 ++++- fs/ntfs3/ntfs_fs.h | 3 ++- fs/ntfs3/run.c | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-)
fs/ntfs3/fslog.c +4 -1
@@ -3368,7 +3368,10 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,memmove (Add2Ptr (attr, aoff), data, dlen);if (run_get_highest_vcn (le64_to_cpu (attr->nres.svcn), -attr_run (attr), &t64)) { +attr_run (attr), +le32_to_cpu (attr->size) - +le16_to_cpu (attr->nres.run_off), + &t64)) { goto dirty_vol; }
fs/ntfs3/ntfs_fs.h +2 -1
@@ -877,7 +877,8 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,#else #define run_unpack_ex run_unpack#endif -int run_get_highest_vcn (CLST vcn,const u8 *run_buf,u64 *highest_vcn); +int run_get_highest_vcn (CLST vcn,const u8 *run_buf,size_t run_buf_size, +u64 *highest_vcn);int run_clone (const struct runs_tree *run,struct runs_tree *new_run);bool run_remove_range (struct runs_tree *run,CLST vcn,CLST len,CLST *done);CLST run_len (const struct runs_tree *run);
fs/ntfs3/run.c +7 -2
@@ -1205,18 +1205,23 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,* Return the highest vcn from a mapping pairs array * it used while replaying log file. */ -int run_get_highest_vcn (CLST vcn,const u8 *run_buf,u64 *highest_vcn) +int run_get_highest_vcn (CLST vcn,const u8 *run_buf,size_t run_buf_size, +u64 *highest_vcn) { +const u8 *run_last = run_buf + run_buf_size;u64 vcn64 = vcn;u8 size_size; -while ((size_size = *run_buf &0xF )) { +while (run_buf < run_last && (size_size = *run_buf &0xF )) {u8 offset_size = *run_buf++ >>4 ;u64 len;if (size_size >8 || offset_size >8 )return -EINVAL ; +if (run_buf + size_size + offset_size > run_last) +return -EINVAL ; + len =run_unpack_s64 (run_buf, size_size,0 );if (!len)return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 918/2077 fs/ntfs3: fix wrong LCN in run_remove_range() when splitting a run
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 36c7276816ed4266c155b71b1fa747b2785f23f7 ]
When run_remove_range() removes a middle portion of a non-sparse run, it splits the run into head and tail parts. The tail is inserted via run_add_entry() but uses the original r->lcn as its starting LCN instead of advancing it by the split offset.
For example, removing VCN range [10, 20) from a run {vcn=0, lcn=100, len=30} should produce:
{vcn=0, lcn=100, len=10} (head)
{vcn=20, lcn=120, len=10} (tail, lcn advanced by 20)
But the current code produces:
{vcn=0, lcn=100, len=10}
{vcn=20, lcn=100, len=10} (wrong: points to same physical clusters)
This creates overlapping physical mappings in the in-memory run tree, which can corrupt cluster allocation decisions and lead to data corruption.
The correct pattern is already used in run_insert_range():
CLST lcn2 = r->lcn == SPARSE_LCN ? SPARSE_LCN : (r->lcn + len1);
Apply the same logic in run_remove_range().
--- fs/ntfs3/run.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ntfs3/run.c +4 -1
@@ -1297,9 +1297,12 @@ bool run_remove_range(struct runs_tree *run, CLST vcn, CLST len, CLST *done)if (r_end > end) {/* Remove a middle part, split. */ +CLST tail_lcn = r->lcn ==SPARSE_LCN ? +SPARSE_LCN : (r->lcn + (end - r->vcn)); + *done += len; r->len = d; -return run_add_entry (run, end, r->lcn, r_end - end, +return run_add_entry (run, end, tail_lcn, r_end - end, false); }/* Remove tail of run .*/
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 919/2077 fs/ntfs3: call _ntfs_bad_inode() when failing to rename
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helen Koike <[email protected]>
[ Upstream commit e8ed78f40eecd0176fda71d673f6957c98e7ffbe ]
It is safe to call _ntfs_bad_inode on live inodes since:
commit 519b078998ce ("fs/ntfs3: Exclude call make_bad_inode for live nodes.")
The WARN_ON was added when it wasn't safe by:
commit d99208b91933 ("fs/ntfs3: cancle set bad inode after removing name fails")
Replace the WARN_ON with a call to _ntfs_bad_inode() to prevent further operations on the inconsistent inode.
--- fs/ntfs3/frecord.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/frecord.c +2 -2
@@ -2800,8 +2800,8 @@ int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni, err =ni_add_name (new_dir_ni, ni, new_de);if (!err) { err =ni_remove_name (dir_ni, ni, de, &de2, &undo); -WARN_ON (err && -ni_remove_name (new_dir_ni, ni, new_de, &de2, &undo)); +if (err &&ni_remove_name (new_dir_ni, ni, new_de, &de2, &undo)) +_ntfs_bad_inode (&ni->vfs_inode); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 920/2077 ntfs3: Allocate iomap inline_data using alloc_page
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mihai Brodschi <[email protected]>
[ Upstream commit 70d3855594cf6e8791970714b65cac3202d6160e ]
This fixes a BUG reported in iomap_write_end_inline:iomap_inline_data_valid checks that the inline_data fits within a page. If the inline_data is allocated with kmemdup there's no guarantee that it's page-aligned, so the check sometimes fails. Allocate it with alloc_page to ensure it's page-aligned.
--- fs/ntfs3/attrib.c | 10 +++++++--- fs/ntfs3/inode.c | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-)
fs/ntfs3/attrib.c +7 -3
@@ -1004,6 +1004,7 @@ int attr_data_get_block_locked(struct ntfs_inode *ni, CLST vcn, CLST clen,struct ATTRIB *attr, *attr_b;struct ATTR_LIST_ENTRY *le, *le_b;struct mft_inode *mi, *mi_b; +struct page *page;CLST hint, svcn, to_alloc, evcn1, next_svcn, asize, end, vcn0;CLST alloc, evcn;unsigned fr;
@@ -1042,10 +1043,13 @@ int attr_data_get_block_locked(struct ntfs_inode *ni, CLST vcn, CLST clen, *lcn =RESIDENT_LCN ; *len = data_size;if (res && data_size) { - *res =kmemdup (resident_data (attr_b), data_size, -GFP_KERNEL ); -if (!*res) + page =alloc_page (GFP_KERNEL ); +if (!page) { err = -ENOMEM ; + }else { + *res =page_address (page); +memcpy (*res,resident_data (attr_b), data_size); + } } goto out; }
fs/ntfs3/inode.c +2 -2
@@ -801,7 +801,7 @@ static int ntfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,if (lcn ==RESIDENT_LCN ) {if (offset >= clen) { -kfree (res); +__free_page (virt_to_page (res));if (flags &IOMAP_REPORT ) {/* special code for report. */ return -ENOENT ;
@@ -921,7 +921,7 @@ static int ntfs_iomap_end(struct inode *inode, loff_t pos, loff_t length, out:if (iomap->type ==IOMAP_INLINE ) { -kfree (iomap->private); +__free_page (virt_to_page (iomap->private)); iomap->private =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 921/2077 ntfs3: avoid another -Wmaybe-uninitialized warning
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit 1bf15dd17385e3730521d17e9e158c475cd7474b ]
The ntfs3 specific -Wmaybe-uninitialized flag found one more false-postive, this time with gcc-10 on s390:
fs/ntfs3/frecord.c: In function 'ni_expand_list':fs/ntfs3/frecord.c:1370:16: error: 'ins_attr' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Add an explicit NULL pointer check before using the pointer, and initialize it to NULL.
--- fs/ntfs3/frecord.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/frecord.c +2 -2
@@ -1330,7 +1330,7 @@ int ni_expand_list(struct ntfs_inode *ni) {int err =0 ;u32 asize, done =0 ; -struct ATTRIB *attr, *ins_attr; +struct ATTRIB *attr, *ins_attr =NULL ;struct ATTR_LIST_ENTRY *le;bool is_mft = ni->mi.rno ==MFT_REC_MFT ;struct MFT_REF ref;
@@ -1363,7 +1363,7 @@ int ni_expand_list(struct ntfs_inode *ni)le16_to_cpu (attr->name_off), true, &ins_attr, NULL, NULL); -if (err) +if (err || !ins_attr) goto out;memcpy (ins_attr, attr, asize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 922/2077 fs/ntfs3: fix mount failure on 64K page-size kernels
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamie Nguyen <[email protected]>
[ Upstream commit b7a9125cac8645245d2473c6c0a50e338280ad23 ]
On 64K page-size kernels, mounting NTFS volumes smaller than ~650 MB fails with EINVAL. The issue is in log_replay(): the initial log page size probe uses PAGE_SIZE (65536) instead of DefaultLogPageSize (4096) when PAGE_SIZE exceeds DefaultLogPageSize * 2.
This makes norm_file_page() require the $LogFile to be at least 50 * 65536 = 3.2 MB, but mkfs.ntfs creates a $LogFile of only ~1.5 MB for a typical 300 MB volume. norm_file_page() returns 0 and the mount is rejected with EINVAL.
On 4K kernels the #if guard evaluates to true, so use_default=true is passed and DefaultLogPageSize (4096) is used, requiring only ~200 KB. This path works fine.
Fix this by always passing use_default=true, which forces the initial probe to use DefaultLogPageSize regardless of the kernel's PAGE_SIZE. This is safe because, after reading the on-disk restart area, log_replay() already re-adjusts log->page_size to match the volume's actual sys_page_size.
Also fix read_log_page() to pass log->page_size instead of PAGE_SIZE to ntfs_fix_post_read(), matching the actual buffer size.
--- fs/ntfs3/fslog.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
fs/ntfs3/fslog.c +1 -5
@@ -1172,7 +1172,7 @@ static int read_log_page(struct ntfs_log *log, u32 vbo, goto out;if (page_buf->rhdr.sign !=NTFS_FFFF_SIGNATURE ) -ntfs_fix_post_read (&page_buf->rhdr,PAGE_SIZE , false); +ntfs_fix_post_read (&page_buf->rhdr, log->page_size, false);if (page_buf != *buffer)memcpy (*buffer,Add2Ptr (page_buf, page_off), bytes);
@@ -3799,11 +3799,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) log->l_size = log->orig_file_size = ni->vfs_inode.i_size;/* Get the size of page. NOTE: To replay we can use default page. */ -#if PAGE_SIZE >= DefaultLogPageSize &&PAGE_SIZE <= DefaultLogPageSize *2 log->page_size =norm_file_page (PAGE_SIZE , &log->l_size, true); -#else - log->page_size =norm_file_page (PAGE_SIZE , &log->l_size, false); -#endif if (!log->page_size) { err = -EINVAL ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 923/2077 drm/amd/display: Add missing kdoc for ALLM parameters
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivasan Shanmugam <[email protected]>
[ Upstream commit d4c6ec729fb7a8bf8a27b19bd70a1b945ad93dac ]
Add descriptions for the missing parameters for ALLMEnabled and ALLMValue to keep the function documentation synchronized with the function prototype mod_build_hf_vsif_infopacket().
Fixes the below with gcc W=1:../display/modules/info_packet/info_packet.c:507 function parameter 'ALLMEnabled' not described in 'mod_build_hf_vsif_infopacket' ../display/modules/info_packet/info_packet.c:507 function parameter 'ALLMValue' not described in 'mod_build_hf_vsif_infopacket'
--- drivers/gpu/drm/amd/display/modules/info_packet/info_packet.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/modules/info_packet/info_packet.c +2 -0
@@ -502,6 +502,8 @@ void mod_build_vsc_infopacket(const struct dc_stream_state *stream,* * @stream: contains data we may need to construct VSIF (i.e. timing_3d_format, etc.) * @info_packet: output structure where to store VSIF +* @ALLMEnabled: indicates whether ALLM HF-VSIF should be generated +* @ALLMValue: ALLM bit value to advertise in HF-VSIF */ void mod_build_hf_vsif_infopacket (const struct dc_stream_state *stream,struct dc_info_packet *info_packet)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 924/2077 thunderbolt: debugfs: Fix margining error counter buffer leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 503c5ae1e72aa9ed91925dafa3d82ee2e992747f ]
When USB4 lane margining debugfs write support is enabled, margining_error_counter_write() copies the user input with validate_and_copy_from_user(). This allocates a temporary page that is only needed while parsing the requested error counter mode.
The function currently returns without freeing that page. This leaks one page per write to the error_counter debugfs file, including successful writes and writes that later fail while taking the domain lock or because software margining is not enabled.
Free the temporary page once parsing has completed, and also before returning from the invalid-input path.
--- drivers/thunderbolt/debugfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/thunderbolt/debugfs.c +7 -1
@@ -956,7 +956,9 @@ margining_error_counter_write(struct file *file, const char __user *user_buf,else if (!strcmp (buf,"stop" )) error_counter =USB4_MARGIN_SW_ERROR_COUNTER_STOP ;else -return -EINVAL ; + goto err_free; + +free_page ((unsigned long )buf); scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) {if (!margining->software)
@@ -966,6 +968,10 @@ margining_error_counter_write(struct file *file, const char __user *user_buf, }return count; + +err_free: +free_page ((unsigned long )buf); +return -EINVAL ; }static int margining_error_counter_show (struct seq_file *s,void *not_used)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 925/2077 dmaengine: imx-sdma: Refine spba bus searching in probe
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengjiu Wang <[email protected]>
[ Upstream commit d52d42e2e5d9f13166e81ac837ebb023d1306e61 ]
There are multi spba-busses for i.MX8M* platforms, if only search for the first spba-bus in DT, the found spba-bus may not the real bus of audio devices, which cause issue for sdma p2p case, as the sdma p2p script presently does not deal with the transactions involving two devices connected to the AIPS bus.
Search the SDMA parent node first, which should be the AIPS bus, then search the child node whose compatible string is spba-bus under that AIPS bus for the above multi spba-busses case.
--- drivers/dma/imx-sdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dma/imx-sdma.c +3 -1
@@ -2364,7 +2364,9 @@ static int sdma_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev, ret,"failed to register controller\n" ); - spba_bus =of_find_compatible_node (NULL ,NULL ,"fsl,spba-bus" ); + struct device_node *sdma_parent_np __free(device_node) = of_get_parent(np); + + spba_bus =of_get_compatible_child (sdma_parent_np,"fsl,spba-bus" ); ret =of_address_to_resource (spba_bus,0 , &spba_res);if (!ret) { sdma->spba_start_addr = spba_res.start;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 926/2077 dt-bindings: dma: nvidia,tegra186-gpc-dma: Make reset optional
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akhil R <[email protected]>
[ Upstream commit cc6049bd3fa8501ee27042df469a19ed69cf406d ]
On Tegra264, GPCDMA reset control is not exposed to Linux and is handled by the boot firmware.
Although reset was not exposed in Tegra234 as well, the firmware supported a dummy reset which just returns success on reset without doing an actual reset. This is also not supported in Tegra264 BPMP. Therefore mark 'reset' and 'reset-names' properties as required only for devices prior to Tegra264.
This also necessitates that the Tegra264 compatible be standalone and cannot have the fallback compatible of Tegra186. Since there is no functional impact, we keep reset as required for Tegra234 to avoid breaking the ABI.
--- .../bindings/dma/nvidia,tegra186-gpc-dma.yaml | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml +16 -7
@@ -15,16 +15,14 @@ maintainers: - Jon Hunter <[email protected]> - Rajesh Gumasta <[email protected]> -allOf: - - $ref: dma-controller.yaml# - properties: compatible: oneOf: - - const: nvidia,tegra186-gpcdma + - enum: + - nvidia,tegra264-gpcdma + - nvidia,tegra186-gpcdma - items: - enum: - - nvidia,tegra264-gpcdma - nvidia,tegra234-gpcdma - nvidia,tegra194-gpcdma - const: nvidia,tegra186-gpcdma
@@ -60,12 +58,23 @@ required: - compatible - reg - interrupts - - resets - - reset-names - "#dma-cells" - iommus - dma-channel-mask +allOf: + - $ref: dma-controller.yaml# + - if: + properties: + compatible: + contains: + enum: + - nvidia,tegra186-gpcdma + then: + required: + - resets + - reset-names + additionalProperties: false examples:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 927/2077 perf: Fix off-by-one stack buffer overflow in kallsyms__parse()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rui Qi <[email protected]>
[ Upstream commit 68018df3f55eba96a20dd703f5f276a6518f4963 ]
In kallsyms__parse(), the loop reading symbol names iterates with i < sizeof(symbol_name), which allows i to reach sizeof(symbol_name) upon loop exit. The subsequent symbol_name[i] = '\0' then writes one byte past the end of the stack-allocated symbol_name[] array.
Fix this by changing the loop bound to KSYM_NAME_LEN, so the null terminator always lands within the array. The overflow is triggerable by a kallsyms entry with a symbol name of KSYM_NAME_LEN+1 or more characters (e.g., long Rust mangled names or a malicious /proc/kallsyms).
--- tools/lib/symbol/kallsyms.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/lib/symbol/kallsyms.c +4 -1
@@ -60,7 +60,7 @@ int kallsyms__parse(const char *filename, void *arg,read_to_eol (&io);continue ; } -for (i =0 ; i <sizeof (symbol_name); i++) { +for (i =0 ; i <KSYM_NAME_LEN ; i++) { ch =io__get_char (&io);if (ch <0 || ch =='\n' )break ;
@@ -68,6 +68,9 @@ int kallsyms__parse(const char *filename, void *arg, } symbol_name[i] ='\0' ; +if (i ==KSYM_NAME_LEN ) +read_to_eol (&io); + err =process_symbol (arg, symbol_name, symbol_type, start);if (err)break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 928/2077 perf annotate: Fix crashes on empty annotate windows
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 74802634e4a7e556429417963a8cbda27dd8b4b3 ]
Annotate can open with an empty window if the disassembly tool fails. After the linked change, the TUI started assuming there was a current annotation line and could assert or segfault in the seek, refresh, and source-toggle paths.
Handle empty annotate windows explicitly: set the asm entry count before resetting the browser, return early when refreshing an empty list, and ignore source line toggle when there is no current annotation line.
Fixes the following when opening an annotation:
perf: ui/browser.c:125: ui_browser__list_head_seek: Assertion `pos != NULL' failed. Aborted
--- tools/perf/ui/browser.c | 3 +++ tools/perf/ui/browsers/annotate.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-)
tools/perf/ui/browser.c +3 -0
@@ -513,6 +513,9 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)struct list_head *head = browser->entries;int row =0 ; +if (browser->nr_entries ==0 ) +return 0 ; +if (browser->top ==NULL || browser->top == browser->entries) browser->top =ui_browser__list_head_filter_entries (browser, head->next);
tools/perf/ui/browsers/annotate.c +4 -1
@@ -449,6 +449,9 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser,struct annotation_line *al;off_t offset = browser->b.index - browser->b.top_idx; +if (browser->b.nr_entries ==0 ) +return false; + browser->b.seek (&browser->b, offset,SEEK_CUR ); al = list_entry(browser->b.top, struct annotation_line, node);
@@ -542,8 +545,8 @@ static void annotate_browser__show_full_location(struct ui_browser *browser)static void ui_browser__init_asm_mode (struct ui_browser *browser) {struct annotation *notes =browser__annotation (browser); -ui_browser__reset_index (browser); browser->nr_entries = notes->src->nr_asm_entries; +ui_browser__reset_index (browser); } static int sym_title(struct symbol *sym, struct map *map, char *title,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 929/2077 perf tools: Guard test_bit from out-of-bounds sample CPU
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit a5498ccf8079fc91c938f122ff9697b0c526b2fd ]
When PERF_SAMPLE_CPU is absent from a perf.data file, sample->cpu is initialized to (u32)-1 by evsel__parse_sample(). Five call sites pass this value directly to test_bit(sample->cpu, cpu_bitmap), reading massively out of bounds past the DECLARE_BITMAP(..., MAX_NR_CPUS) allocation of 4096 bits.
Add a sample->cpu >= MAX_NR_CPUS guard before each test_bit() call, matching the existing safe pattern in builtin-kwork.c. This catches both the (u32)-1 sentinel and any corrupted CPU value exceeding the bitmap size.
--- tools/perf/builtin-annotate.c | 3 ++- tools/perf/builtin-diff.c | 3 ++- tools/perf/builtin-report.c | 3 ++- tools/perf/builtin-sched.c | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-)
tools/perf/builtin-annotate.c +2 -1
@@ -298,7 +298,8 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; } -if (ann->cpu_list && !test_bit (sample->cpu, ann->cpu_bitmap)) +if (ann->cpu_list && (sample->cpu >=MAX_NR_CPUS || + !test_bit (sample->cpu, ann->cpu_bitmap))) goto out_put; if (!al.filtered &&
tools/perf/builtin-diff.c +2 -1
@@ -416,7 +416,8 @@ static int diff__process_sample_event(const struct perf_tool *tool, goto out; } -if (cpu_list && !test_bit (sample->cpu, cpu_bitmap)) { +if (cpu_list && (sample->cpu >=MAX_NR_CPUS || + !test_bit (sample->cpu, cpu_bitmap))) { ret =0 ; goto out; }
tools/perf/builtin-report.c +2 -1
@@ -300,7 +300,8 @@ static int process_sample_event(const struct perf_tool *tool,if (symbol_conf.hide_unresolved && al.sym ==NULL ) goto out_put; -if (rep->cpu_list && !test_bit (sample->cpu, rep->cpu_bitmap)) +if (rep->cpu_list && (sample->cpu >=MAX_NR_CPUS || + !test_bit (sample->cpu, rep->cpu_bitmap))) goto out_put;if (sort__mode ==SORT_MODE__BRANCH ) {
tools/perf/builtin-sched.c +4 -2
@@ -2175,7 +2175,8 @@ static void timehist_print_sample(struct perf_sched *sched,char nstr[30 ];u64 wait_time; -if (cpu_list && !test_bit (sample->cpu, cpu_bitmap)) +if (cpu_list && (sample->cpu >=MAX_NR_CPUS || + !test_bit (sample->cpu, cpu_bitmap)))return ;timestamp__scnprintf_usec (t, tstr,sizeof (tstr));
@@ -2857,7 +2858,8 @@ static int timehist_sched_change_event(const struct perf_tool *tool, }if (!sched->idle_hist ||thread__tid (thread) ==0 ) { -if (!cpu_list ||test_bit (sample->cpu, cpu_bitmap)) +if (!cpu_list || (sample->cpu <MAX_NR_CPUS && +test_bit (sample->cpu, cpu_bitmap)))timehist_update_runtime_stats (tr, t, tprev);if (sched->idle_hist) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 930/2077 perf sched: Fix thread reference leak in latency_switch_event
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 66ea9de60396a4dea5276bc87025884691876c36 ]
In latency_switch_event(), after acquiring thread references for sched_out and sched_in via machine__findnew_thread(), the first add_sched_out_event() failure path does 'return -1', bypassing the out_put label that calls thread__put() on both references.
The second and third add_sched_out_event() failures correctly use 'goto out_put'. Fix the first one to match.
--- tools/perf/builtin-sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-sched.c +1 -1
@@ -1177,7 +1177,7 @@ static int latency_switch_event(struct perf_sched *sched, } }if (add_sched_out_event (out_events, prev_state, timestamp)) -return -1 ; + goto out_put; in_events =thread_atoms_search (&sched->atom_root, sched_in, &sched->cmp_pid);if (!in_events) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 931/2077 perf sched: Replace BUG_ON on invalid CPU with graceful skip
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 1e2c83f732deb329ebce23e26cbc482f4c4bf194 ]
latency_switch_event(), latency_runtime_event(), and map_switch_event() use BUG_ON(cpu >= MAX_CPUS || cpu < 0) to validate the sample CPU. When PERF_SAMPLE_CPU is absent from the sample type, evsel__parse_sample() initializes sample->cpu to (u32)-1. Casting this to int yields -1, which triggers the BUG_ON and aborts perf sched.
The central CPU validation in perf_session__deliver_event() intentionally preserves the (u32)-1 sentinel for downstream tools like perf script and perf inject, so leaf callbacks must handle it themselves.
Replace the three BUG_ON calls with graceful skips using pr_warning(), matching the existing pattern in process_sched_switch_event() and process_sched_runtime_event() earlier in the same file. Include the file offset for cross-referencing with perf report -D.
Stable-dep-of: 8cbca8a480e1 ("perf sched: Fix NULL dereference in latency_runtime_event")
--- tools/perf/builtin-sched.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
tools/perf/builtin-sched.c +19 -3
@@ -1147,7 +1147,12 @@ static int latency_switch_event(struct perf_sched *sched,int cpu = sample->cpu, err =-1 ;s64 delta; -BUG_ON (cpu >=MAX_CPUS || cpu <0 ); +/* perf.data is untrusted input — CPU may be absent or corrupted */ +if (cpu >=MAX_CPUS || cpu <0 ) { +pr_warning ("WARNING: at offset %#" PRIx64": out-of-bound sample CPU %d, skipping sample\n" , + sample->file_offset, cpu); +return 0 ; + } timestamp0 = sched->cpu_last_switched[cpu]; sched->cpu_last_switched[cpu] = timestamp;
@@ -1218,7 +1223,13 @@ static int latency_runtime_event(struct perf_sched *sched,if (thread ==NULL )return -1 ; -BUG_ON (cpu >=MAX_CPUS || cpu <0 ); +/* perf.data is untrusted input — CPU may be absent or corrupted */ +if (cpu >=MAX_CPUS || cpu <0 ) { +pr_warning ("WARNING: at offset %#" PRIx64": out-of-bound sample CPU %d, skipping sample\n" , + sample->file_offset, cpu); + err =0 ; + goto out_put; + }if (!atoms) {if (thread_atoms_insert (sched, thread)) goto out_put;
@@ -1647,7 +1658,12 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,const char *str;int ret =-1 ; -BUG_ON (this_cpu.cpu >=MAX_CPUS || this_cpu.cpu <0 ); +/* perf.data is untrusted input — CPU may be absent or corrupted */ +if (this_cpu.cpu >=MAX_CPUS || this_cpu.cpu <0 ) { +pr_warning ("WARNING: at offset %#" PRIx64": out-of-bound sample CPU %d, skipping sample\n" , + sample->file_offset, this_cpu.cpu); +return 0 ; + }if (this_cpu.cpu > sched->max_cpu.cpu) sched->max_cpu = this_cpu;
Signature · 1 line
2.53.0
Re: [PATCH 7.1 0931/2077] perf sched: Replace BUG_ON on invalid CPU with graceful skip
Quoted 38 lines · Greg Kroah-Hartman
7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit
1e2c83f732deb329ebce23e26cbc482f4c4bf194]
latency_switch_event(),latency_runtime_event(), andmap_switch_event()useBUG_ON(cpu >= MAX_CPUS || cpu < 0)to validate the sample CPU. WhenPERF_SAMPLE_CPUis absent from the sample type,evsel__parse_sample()initializessample->cputo (u32)-1. Casting this to int yields -1, which triggers theBUG_ONand aborts perf sched.The central CPU validation in
perf_session__deliver_event()intentionally preserves the (u32)-1 sentinel for downstream tools like perf script and perf inject, so leaf callbacks must handle it themselves.Replace the three
BUG_ONcalls with graceful skips usingpr_warning(), matching the existing pattern inprocess_sched_switch_event()andprocess_sched_runtime_event()earlier in the same file. Include the file offset for cross-referencing with perf report -D.Reported-by [email protected] # Running on a local machineReviewed-by Ian Rogers <[email protected]>Assisted-by Claude:claude-opus-4.6Signed-off-by Arnaldo Carvalho de Melo <[email protected]>Stable-dep-of:
8cbca8a480e1("perf sched: Fix NULL dereference inlatency_runtime_event")Signed-off-by Sasha Levin <[email protected]>--- tools/perf/builtin-sched.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)tools/perf/builtin-sched.c +0
-0
tools/perf/builtin-sched.c static int latency_switch_event(struct perf_sched *sched, · line 1153
Quoted 8 lines
tools/perf/builtin-sched.c +4
-1@@ -1147,7 +1147,12 @@ static int latency_switch_event(struct perf_sched *sched,int cpu = sample->cpu, err =-1 ;s64 delta; -BUG_ON (cpu >=MAX_CPUS || cpu <0 ); +/* perf.data is untrusted input — CPU may be absent or corrupted */ +if (cpu >=MAX_CPUS || cpu <0 ) { +pr_warning ("WARNING: at offset %#" PRIx64": out-of-bound sample CPU %d, skipping sample\n" , + sample->file_offset, cpu);
This needs:7a490187f22b perf sample: Add file_offset field to struct perf_sample
Signature · 2 lines
js suse labs
Greg Kroah-Hartman
maintainerRe: [PATCH 7.1 0931/2077] perf sched: Replace BUG_ON on invalid CPU with graceful skip
Quoted 34 lines · Jiri Slaby
Quoted 33 lines · Greg Kroah-Hartman
7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit
1e2c83f732deb329ebce23e26cbc482f4c4bf194]
latency_switch_event(),latency_runtime_event(), andmap_switch_event()useBUG_ON(cpu >= MAX_CPUS || cpu < 0)to validate the sample CPU. WhenPERF_SAMPLE_CPUis absent from the sample type,evsel__parse_sample()initializessample->cputo (u32)-1. Casting this to int yields -1, which triggers theBUG_ONand aborts perf sched.The central CPU validation in
perf_session__deliver_event()intentionally preserves the (u32)-1 sentinel for downstream tools like perf script and perf inject, so leaf callbacks must handle it themselves.Replace the three
BUG_ONcalls with graceful skips usingpr_warning(), matching the existing pattern inprocess_sched_switch_event()andprocess_sched_runtime_event()earlier in the same file. Include the file offset for cross-referencing with perf report -D.Reported-by [email protected] # Running on a local machineReviewed-by Ian Rogers <[email protected]>Assisted-by Claude:claude-opus-4.6Signed-off-by Arnaldo Carvalho de Melo <[email protected]>Stable-dep-of:
8cbca8a480e1("perf sched: Fix NULL dereference inlatency_runtime_event")Signed-off-by Sasha Levin <[email protected]>--- tools/perf/builtin-sched.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
Quoted 15 lines
tools/perf/builtin-sched.c static int latency_switch_event(struct perf_sched *sched, · line 1152
Quoted 12 lines
tools/perf/builtin-sched.c +4
-1@@ -1147,7 +1147,12 @@ static int latency_switch_event(struct perf_sched *sched,int cpu = sample->cpu, err =-1 ;s64 delta; -BUG_ON (cpu >=MAX_CPUS || cpu <0 ); +/* perf.data is untrusted input — CPU may be absent or corrupted */ +if (cpu >=MAX_CPUS || cpu <0 ) { +pr_warning ("WARNING: at offset %#" PRIx64": out-of-bound sample CPU %d, skipping sample\n" , + sample->file_offset, cpu);This needs:
7a490187f22bperf sample: Addfile_offsetfield to structperf_sample
Thanks, now added.
greg k-h
Greg Kroah-Hartman
maintainerPATCH 932/2077 perf sched: Fix NULL dereference in latency_runtime_event
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 8cbca8a480e15f6326ce94287570993f27a4b2d5 ]
latency_runtime_event() passes the return value of machine__findnew_thread() directly to thread_atoms_search() at line 1216, before checking for NULL at line 1220. thread_atoms_search() calls pid_cmp() which dereferences the thread pointer via thread__tid(), causing a NULL pointer dereference if the allocation fails.
All other callers of thread_atoms_search() in this file (latency_switch_event, latency_wakeup_event, latency_migrate_task_event) correctly check for NULL first.
Move the atoms assignment after the NULL check to match the pattern used by the other callers.
--- tools/perf/builtin-sched.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-sched.c +3 -1
@@ -1216,13 +1216,15 @@ static int latency_runtime_event(struct perf_sched *sched,const u32 pid =evsel__intval (evsel, sample,"pid" );const u64 runtime =evsel__intval (evsel, sample,"runtime" );struct thread *thread =machine__findnew_thread (machine,-1 , pid); -struct work_atoms *atoms =thread_atoms_search (&sched->atom_root, thread, &sched->cmp_pid); +struct work_atoms *atoms;u64 timestamp = sample->time;int cpu = sample->cpu, err =-1 ;if (thread ==NULL )return -1 ; + atoms =thread_atoms_search (&sched->atom_root, thread, &sched->cmp_pid); +/* perf.data is untrusted input — CPU may be absent or corrupted */ if (cpu >=MAX_CPUS || cpu <0 ) { pr_warning("WARNING: at offset %#" PRIx64 ": out-of-bound sample CPU %d, skipping sample\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 933/2077 perf sched: Fix comp_cpus heap overflow with cross-machine recordings
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit c8b04142078a9ccb9e402ab7c38de7123256f4a5 ]
setup_map_cpus() allocates comp_cpus based on sysconf(_SC_NPROCESSORS_CONF), the host machine's CPU count. But map_switch_event() indexes comp_cpus using cpus_nr derived from bitmap_weight(comp_cpus_mask, MAX_CPUS), where comp_cpus_mask is declared as DECLARE_BITMAP(..., MAX_CPUS) with MAX_CPUS=4096.
When analyzing a perf.data recording from a machine with more CPUs than the analysis host (e.g. 128-CPU server recording analyzed on an 8-CPU laptop), cpus_nr exceeds the allocation size, causing a heap buffer overflow.
Also fix a type mismatch: comp_cpus is 'struct perf_cpu *' (2 bytes per element) but was allocated with sizeof(int) (4 bytes per element).
Allocate comp_cpus with MAX_CPUS entries using the correct element size, matching the comp_cpus_mask bitmap bounds. Remove the sysconf(_SC_NPROCESSORS_CONF) initialization of max_cpu — its only consumer was the comp_cpus allocation, and max_cpu is dynamically updated from the recording's events during processing. Fix the non-compact path to use max_cpu.cpu + 1 as cpus_nr, converting from 0-based index to count — sysconf() returned a count which masked this off-by-one.
--- tools/perf/builtin-sched.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/builtin-sched.c +2 -4
@@ -1677,7 +1677,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, new_cpu = true; } }else - cpus_nr = sched->max_cpu.cpu; + cpus_nr = sched->max_cpu.cpu +1 ; timestamp0 = sched->cpu_last_switched[this_cpu.cpu]; sched->cpu_last_switched[this_cpu.cpu] = timestamp;
@@ -3577,10 +3577,8 @@ static int perf_sched__lat(struct perf_sched *sched)static int setup_map_cpus (struct perf_sched *sched) { - sched->max_cpu.cpu =sysconf (_SC_NPROCESSORS_CONF); -if (sched->map.comp) { - sched->map.comp_cpus =calloc (sched->max_cpu.cpu,sizeof (int )); + sched->map.comp_cpus =calloc (MAX_CPUS ,sizeof (*sched->map.comp_cpus));if (!sched->map.comp_cpus)return -1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 934/2077 perf tools: Guard remaining test_bit calls from OOB sample CPU
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 7ccd2e6cecd5bb02a5a15f0dd7199d1e81380bda ]
auxtrace.c:filter_cpu() and builtin-script.c:filter_cpu() call test_bit(cpu, cpu_bitmap) where cpu_bitmap is declared with MAX_NR_CPUS bits. When the CPU value from a perf.data event is corrupt or absent (e.g. negative or >= MAX_NR_CPUS), test_bit reads out of bounds.
Add bounds checks before test_bit(): >= 0 for the int16_t cpu.cpu in auxtrace (which also covers the -1 sentinel), and < MAX_NR_CPUS for both sites. Matches the pattern applied in the previous series for builtin-annotate.c, builtin-diff.c, builtin-report.c, and builtin-sched.c.
--- tools/perf/builtin-script.c | 2 +- tools/perf/util/auxtrace.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +1 -1
@@ -2638,7 +2638,7 @@ static int cleanup_scripting(void)static bool filter_cpu (struct perf_sample *sample) { -if (cpu_list && sample->cpu != (u32)-1 ) +if (cpu_list && sample->cpu != (u32)-1 && sample->cpu <MAX_NR_CPUS )return !test_bit (sample->cpu, cpu_bitmap);return false; }
tools/perf/util/auxtrace.c +2 -1
@@ -372,7 +372,8 @@ static bool filter_cpu(struct perf_session *session, struct perf_cpu cpu) {unsigned long *cpu_bitmap = session->itrace_synth_opts->cpu_bitmap; -return cpu_bitmap && cpu.cpu !=-1 && !test_bit (cpu.cpu, cpu_bitmap); +return cpu_bitmap && cpu.cpu >=0 && cpu.cpu <MAX_NR_CPUS && + !test_bit (cpu.cpu, cpu_bitmap); } static int auxtrace_queues__add_buffer(struct auxtrace_queues *queues,
Signature · 1 line
2.53.0