* [PATCH v3 0/3] Add modem debug features @ 2020-07-22 20:10 Sibi Sankar 2020-07-22 20:10 ` [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load Sibi Sankar ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Sibi Sankar @ 2020-07-22 20:10 UTC (permalink / raw) To: bjorn.andersson Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad, Sibi Sankar The series adds support for the following modem debug features: * Modem debug policy which enables coredumps/live debug on secure devices * MBA text logs extraction on SC7180 SoCs The series also includes fixes for a couple of mem aborts seen when mba/modem blob size exceeds mba/mpss regions respectively. V3: * Drop mba text log extraction support since its already picked up by Bjorn * Fix dp_fw leak and create a separate func for dp load [Bjorn] * Reset dp_size on mba_reclaim * 2 new patches are included and they validate mba/modem blob size before load V2: * Use request_firmware_direct [Bjorn] * Use Bjorn's template to show if debug policy is present * Add size check to prevent memcpy out of bounds [Bjorn] * Don't dump logs in mba_reclaim path [Bjorn] * Move has_mba_logs check to q6v5_dump_mba_logs [Bjorn] * SDM845 mss was incorrectly marked to support mba logs * Drop patch 3 where mba text logs are added to imem Sibi Sankar (3): remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load remoteproc: qcom_q6v5_mss: Add modem debug policy support drivers/remoteproc/qcom_q6v5_mss.c | 36 ++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load 2020-07-22 20:10 [PATCH v3 0/3] Add modem debug features Sibi Sankar @ 2020-07-22 20:10 ` Sibi Sankar 2020-07-28 5:45 ` Bjorn Andersson 2020-07-22 20:10 ` [PATCH v3 2/3] remoteproc: qcom_q6v5_mss: Validate modem blob " Sibi Sankar 2020-07-22 20:10 ` [PATCH v3 3/3] remoteproc: qcom_q6v5_mss: Add modem debug policy support Sibi Sankar 2 siblings, 1 reply; 7+ messages in thread From: Sibi Sankar @ 2020-07-22 20:10 UTC (permalink / raw) To: bjorn.andersson Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad, Sibi Sankar, stable The following mem abort is observed when the mba firmware size exceeds the allocated mba region. MBA firmware size is restricted to a maximum size of 1M and remaining memory region is used by modem debug policy firmware when available. Hence verify whether the MBA firmware size lies within the allocated memory region and is not greater than 1M before loading. Err Logs: Unable to handle kernel paging request at virtual address Mem abort info: ... Call trace: __memcpy+0x110/0x180 rproc_start+0x40/0x218 rproc_boot+0x5b4/0x608 state_store+0x54/0xf8 dev_attr_store+0x44/0x60 sysfs_kf_write+0x58/0x80 kernfs_fop_write+0x140/0x230 vfs_write+0xc4/0x208 ksys_write+0x74/0xf8 __arm64_sys_write+0x24/0x30 ... Fixes: 051fb70fd4ea4 ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5") Cc: stable@vger.kernel.org Signed-off-by: Sibi Sankar <sibis@codeaurora.org> --- drivers/remoteproc/qcom_q6v5_mss.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 718acebae777f..4e72c9e30426c 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -412,6 +412,12 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw) { struct q6v5 *qproc = rproc->priv; + /* MBA is restricted to a maximum size of 1M */ + if (fw->size > qproc->mba_size || fw->size > SZ_1M) { + dev_err(qproc->dev, "MBA firmware load failed\n"); + return -EINVAL; + } + memcpy(qproc->mba_region, fw->data, fw->size); return 0; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load 2020-07-22 20:10 ` [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load Sibi Sankar @ 2020-07-28 5:45 ` Bjorn Andersson 0 siblings, 0 replies; 7+ messages in thread From: Bjorn Andersson @ 2020-07-28 5:45 UTC (permalink / raw) To: Sibi Sankar Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad, stable On Wed 22 Jul 13:10 PDT 2020, Sibi Sankar wrote: > The following mem abort is observed when the mba firmware size exceeds > the allocated mba region. MBA firmware size is restricted to a maximum > size of 1M and remaining memory region is used by modem debug policy > firmware when available. Hence verify whether the MBA firmware size lies > within the allocated memory region and is not greater than 1M before > loading. > > Err Logs: > Unable to handle kernel paging request at virtual address > Mem abort info: > ... > Call trace: > __memcpy+0x110/0x180 > rproc_start+0x40/0x218 > rproc_boot+0x5b4/0x608 > state_store+0x54/0xf8 > dev_attr_store+0x44/0x60 > sysfs_kf_write+0x58/0x80 > kernfs_fop_write+0x140/0x230 > vfs_write+0xc4/0x208 > ksys_write+0x74/0xf8 > __arm64_sys_write+0x24/0x30 > ... > > Fixes: 051fb70fd4ea4 ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5") > Cc: stable@vger.kernel.org Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> > Signed-off-by: Sibi Sankar <sibis@codeaurora.org> > --- > drivers/remoteproc/qcom_q6v5_mss.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c > index 718acebae777f..4e72c9e30426c 100644 > --- a/drivers/remoteproc/qcom_q6v5_mss.c > +++ b/drivers/remoteproc/qcom_q6v5_mss.c > @@ -412,6 +412,12 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw) > { > struct q6v5 *qproc = rproc->priv; > > + /* MBA is restricted to a maximum size of 1M */ > + if (fw->size > qproc->mba_size || fw->size > SZ_1M) { > + dev_err(qproc->dev, "MBA firmware load failed\n"); I'll change this to "MBA firmware exceeds size limit\n". Please let me know if you object. Regards, Bjorn > + return -EINVAL; > + } > + > memcpy(qproc->mba_region, fw->data, fw->size); > > return 0; > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 2/3] remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load 2020-07-22 20:10 [PATCH v3 0/3] Add modem debug features Sibi Sankar 2020-07-22 20:10 ` [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load Sibi Sankar @ 2020-07-22 20:10 ` Sibi Sankar 2020-07-28 6:04 ` Bjorn Andersson 2020-07-22 20:10 ` [PATCH v3 3/3] remoteproc: qcom_q6v5_mss: Add modem debug policy support Sibi Sankar 2 siblings, 1 reply; 7+ messages in thread From: Sibi Sankar @ 2020-07-22 20:10 UTC (permalink / raw) To: bjorn.andersson Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad, Sibi Sankar, stable The following mem abort is observed when one of the modem blob firmware size exceeds the allocated mpss region. Fix this by restricting the copy size to segment size using request_firmware_into_buf before load. Err Logs: Unable to handle kernel paging request at virtual address Mem abort info: ... Call trace: __memcpy+0x110/0x180 rproc_start+0xd0/0x190 rproc_boot+0x404/0x550 state_store+0x54/0xf8 dev_attr_store+0x44/0x60 sysfs_kf_write+0x58/0x80 kernfs_fop_write+0x140/0x230 vfs_write+0xc4/0x208 ksys_write+0x74/0xf8 ... Fixes: 051fb70fd4ea4 ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5") Cc: stable@vger.kernel.org Signed-off-by: Sibi Sankar <sibis@codeaurora.org> --- drivers/remoteproc/qcom_q6v5_mss.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 4e72c9e30426c..f4aa61ba220dc 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1174,15 +1174,14 @@ static int q6v5_mpss_load(struct q6v5 *qproc) } else if (phdr->p_filesz) { /* Replace "xxx.xxx" with "xxx.bxx" */ sprintf(fw_name + fw_name_len - 3, "b%02d", i); - ret = request_firmware(&seg_fw, fw_name, qproc->dev); + ret = request_firmware_into_buf(&seg_fw, fw_name, qproc->dev, + ptr, phdr->p_filesz); if (ret) { dev_err(qproc->dev, "failed to load %s\n", fw_name); iounmap(ptr); goto release_firmware; } - memcpy(ptr, seg_fw->data, seg_fw->size); - release_firmware(seg_fw); } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/3] remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load 2020-07-22 20:10 ` [PATCH v3 2/3] remoteproc: qcom_q6v5_mss: Validate modem blob " Sibi Sankar @ 2020-07-28 6:04 ` Bjorn Andersson 0 siblings, 0 replies; 7+ messages in thread From: Bjorn Andersson @ 2020-07-28 6:04 UTC (permalink / raw) To: Sibi Sankar Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad, stable On Wed 22 Jul 13:10 PDT 2020, Sibi Sankar wrote: > The following mem abort is observed when one of the modem blob firmware > size exceeds the allocated mpss region. Fix this by restricting the copy > size to segment size using request_firmware_into_buf before load. > > Err Logs: > Unable to handle kernel paging request at virtual address > Mem abort info: > ... > Call trace: > __memcpy+0x110/0x180 > rproc_start+0xd0/0x190 > rproc_boot+0x404/0x550 > state_store+0x54/0xf8 > dev_attr_store+0x44/0x60 > sysfs_kf_write+0x58/0x80 > kernfs_fop_write+0x140/0x230 > vfs_write+0xc4/0x208 > ksys_write+0x74/0xf8 > ... > > Fixes: 051fb70fd4ea4 ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5") > Cc: stable@vger.kernel.org > Signed-off-by: Sibi Sankar <sibis@codeaurora.org> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> > --- > drivers/remoteproc/qcom_q6v5_mss.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c > index 4e72c9e30426c..f4aa61ba220dc 100644 > --- a/drivers/remoteproc/qcom_q6v5_mss.c > +++ b/drivers/remoteproc/qcom_q6v5_mss.c > @@ -1174,15 +1174,14 @@ static int q6v5_mpss_load(struct q6v5 *qproc) > } else if (phdr->p_filesz) { > /* Replace "xxx.xxx" with "xxx.bxx" */ > sprintf(fw_name + fw_name_len - 3, "b%02d", i); > - ret = request_firmware(&seg_fw, fw_name, qproc->dev); > + ret = request_firmware_into_buf(&seg_fw, fw_name, qproc->dev, > + ptr, phdr->p_filesz); > if (ret) { > dev_err(qproc->dev, "failed to load %s\n", fw_name); > iounmap(ptr); > goto release_firmware; > } > > - memcpy(ptr, seg_fw->data, seg_fw->size); > - > release_firmware(seg_fw); > } > > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 3/3] remoteproc: qcom_q6v5_mss: Add modem debug policy support 2020-07-22 20:10 [PATCH v3 0/3] Add modem debug features Sibi Sankar 2020-07-22 20:10 ` [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load Sibi Sankar 2020-07-22 20:10 ` [PATCH v3 2/3] remoteproc: qcom_q6v5_mss: Validate modem blob " Sibi Sankar @ 2020-07-22 20:10 ` Sibi Sankar 2020-07-28 5:48 ` Bjorn Andersson 2 siblings, 1 reply; 7+ messages in thread From: Sibi Sankar @ 2020-07-22 20:10 UTC (permalink / raw) To: bjorn.andersson Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad, Sibi Sankar Add modem debug policy support which will enable coredumps and live debug support when the msadp firmware is present on secure devices. Signed-off-by: Sibi Sankar <sibis@codeaurora.org> --- v3: * Fix dp_fw leak and create a separate func for dp load [Bjorn] * Reset dp_size on mba_reclaim v2: * Use request_firmware_direct [Bjorn] * Use Bjorn's template to show if debug policy is present * Add size check to prevent memcpy out of bounds [Bjorn] drivers/remoteproc/qcom_q6v5_mss.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index f4aa61ba220dc..da99c8504a346 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -191,6 +191,7 @@ struct q6v5 { phys_addr_t mba_phys; void *mba_region; size_t mba_size; + size_t dp_size; phys_addr_t mpss_phys; phys_addr_t mpss_reloc; @@ -408,6 +409,21 @@ static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm, current_perm, next, perms); } +static void q6v5_debug_policy_load(struct q6v5 *qproc) +{ + const struct firmware *dp_fw; + + if (request_firmware_direct(&dp_fw, "msadp", qproc->dev)) + return; + + if (SZ_1M + dp_fw->size <= qproc->mba_size) { + memcpy(qproc->mba_region + SZ_1M, dp_fw->data, dp_fw->size); + qproc->dp_size = dp_fw->size; + } + + release_firmware(dp_fw); +} + static int q6v5_load(struct rproc *rproc, const struct firmware *fw) { struct q6v5 *qproc = rproc->priv; @@ -419,6 +435,7 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw) } memcpy(qproc->mba_region, fw->data, fw->size); + q6v5_debug_policy_load(qproc); return 0; } @@ -928,6 +945,10 @@ static int q6v5_mba_load(struct q6v5 *qproc) } writel(qproc->mba_phys, qproc->rmb_base + RMB_MBA_IMAGE_REG); + if (qproc->dp_size) { + writel(qproc->mba_phys + SZ_1M, qproc->rmb_base + RMB_PMI_CODE_START_REG); + writel(qproc->dp_size, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); + } ret = q6v5proc_reset(qproc); if (ret) @@ -996,6 +1017,7 @@ static void q6v5_mba_reclaim(struct q6v5 *qproc) u32 val; qproc->dump_mba_loaded = false; + qproc->dp_size = 0; q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_q6); q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_modem); @@ -1290,7 +1312,8 @@ static int q6v5_start(struct rproc *rproc) if (ret) return ret; - dev_info(qproc->dev, "MBA booted, loading mpss\n"); + dev_info(qproc->dev, "MBA booted with%s debug policy, loading mpss\n", + qproc->dp_size ? "" : "out"); ret = q6v5_mpss_load(qproc); if (ret) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/3] remoteproc: qcom_q6v5_mss: Add modem debug policy support 2020-07-22 20:10 ` [PATCH v3 3/3] remoteproc: qcom_q6v5_mss: Add modem debug policy support Sibi Sankar @ 2020-07-28 5:48 ` Bjorn Andersson 0 siblings, 0 replies; 7+ messages in thread From: Bjorn Andersson @ 2020-07-28 5:48 UTC (permalink / raw) To: Sibi Sankar Cc: agross, linux-arm-msm, linux-remoteproc, linux-kernel, evgreen, ohad On Wed 22 Jul 13:10 PDT 2020, Sibi Sankar wrote: > Add modem debug policy support which will enable coredumps and live > debug support when the msadp firmware is present on secure devices. > > Signed-off-by: Sibi Sankar <sibis@codeaurora.org> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> > --- > > v3: > * Fix dp_fw leak and create a separate func for dp load [Bjorn] > * Reset dp_size on mba_reclaim > > v2: > * Use request_firmware_direct [Bjorn] > * Use Bjorn's template to show if debug policy is present > * Add size check to prevent memcpy out of bounds [Bjorn] > > drivers/remoteproc/qcom_q6v5_mss.c | 25 ++++++++++++++++++++++++- > 1 file changed, 24 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c > index f4aa61ba220dc..da99c8504a346 100644 > --- a/drivers/remoteproc/qcom_q6v5_mss.c > +++ b/drivers/remoteproc/qcom_q6v5_mss.c > @@ -191,6 +191,7 @@ struct q6v5 { > phys_addr_t mba_phys; > void *mba_region; > size_t mba_size; > + size_t dp_size; > > phys_addr_t mpss_phys; > phys_addr_t mpss_reloc; > @@ -408,6 +409,21 @@ static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm, > current_perm, next, perms); > } > > +static void q6v5_debug_policy_load(struct q6v5 *qproc) > +{ > + const struct firmware *dp_fw; > + > + if (request_firmware_direct(&dp_fw, "msadp", qproc->dev)) > + return; > + > + if (SZ_1M + dp_fw->size <= qproc->mba_size) { > + memcpy(qproc->mba_region + SZ_1M, dp_fw->data, dp_fw->size); > + qproc->dp_size = dp_fw->size; > + } > + > + release_firmware(dp_fw); > +} > + > static int q6v5_load(struct rproc *rproc, const struct firmware *fw) > { > struct q6v5 *qproc = rproc->priv; > @@ -419,6 +435,7 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw) > } > > memcpy(qproc->mba_region, fw->data, fw->size); > + q6v5_debug_policy_load(qproc); > > return 0; > } > @@ -928,6 +945,10 @@ static int q6v5_mba_load(struct q6v5 *qproc) > } > > writel(qproc->mba_phys, qproc->rmb_base + RMB_MBA_IMAGE_REG); > + if (qproc->dp_size) { > + writel(qproc->mba_phys + SZ_1M, qproc->rmb_base + RMB_PMI_CODE_START_REG); > + writel(qproc->dp_size, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); > + } > > ret = q6v5proc_reset(qproc); > if (ret) > @@ -996,6 +1017,7 @@ static void q6v5_mba_reclaim(struct q6v5 *qproc) > u32 val; > > qproc->dump_mba_loaded = false; > + qproc->dp_size = 0; > > q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_q6); > q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_modem); > @@ -1290,7 +1312,8 @@ static int q6v5_start(struct rproc *rproc) > if (ret) > return ret; > > - dev_info(qproc->dev, "MBA booted, loading mpss\n"); > + dev_info(qproc->dev, "MBA booted with%s debug policy, loading mpss\n", > + qproc->dp_size ? "" : "out"); > > ret = q6v5_mpss_load(qproc); > if (ret) > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-07-28 6:08 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-07-22 20:10 [PATCH v3 0/3] Add modem debug features Sibi Sankar 2020-07-22 20:10 ` [PATCH v3 1/3] remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load Sibi Sankar 2020-07-28 5:45 ` Bjorn Andersson 2020-07-22 20:10 ` [PATCH v3 2/3] remoteproc: qcom_q6v5_mss: Validate modem blob " Sibi Sankar 2020-07-28 6:04 ` Bjorn Andersson 2020-07-22 20:10 ` [PATCH v3 3/3] remoteproc: qcom_q6v5_mss: Add modem debug policy support Sibi Sankar 2020-07-28 5:48 ` Bjorn Andersson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).