From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
To: mhi@lists.linux.dev
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
quic_msarkar@quicinc.com, schintav@quicinc.com,
stable@vger.kernel.org
Subject: Re: [PATCH] bus: mhi: ep: Do not allocate event ring element on stack
Date: Tue, 17 Oct 2023 13:06:42 +0530 [thread overview]
Message-ID: <20231017073642.GA5274@thinkpad> (raw)
In-Reply-To: <20230901073502.69385-1-manivannan.sadhasivam@linaro.org>
On Fri, Sep 01, 2023 at 01:05:02PM +0530, Manivannan Sadhasivam wrote:
> It is possible that the host controller driver would use DMA framework to
> write the event ring element. So avoid allocating event ring element on the
> stack as DMA cannot work on vmalloc memory.
>
> Cc: stable@vger.kernel.org
> Fixes: 961aeb689224 ("bus: mhi: ep: Add support for sending events to the host")
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Applied to mhi-next!
- Mani
> ---
> drivers/bus/mhi/ep/main.c | 52 +++++++++++++++++++++++++--------------
> 1 file changed, 34 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
> index 600881808982..66ca470bf302 100644
> --- a/drivers/bus/mhi/ep/main.c
> +++ b/drivers/bus/mhi/ep/main.c
> @@ -71,45 +71,61 @@ static int mhi_ep_send_event(struct mhi_ep_cntrl *mhi_cntrl, u32 ring_idx,
> static int mhi_ep_send_completion_event(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring,
> struct mhi_ring_element *tre, u32 len, enum mhi_ev_ccs code)
> {
> - struct mhi_ring_element event = {};
> + struct mhi_ring_element *event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL);
> + int ret;
> +
> + event->ptr = cpu_to_le64(ring->rbase + ring->rd_offset * sizeof(*tre));
> + event->dword[0] = MHI_TRE_EV_DWORD0(code, len);
> + event->dword[1] = MHI_TRE_EV_DWORD1(ring->ch_id, MHI_PKT_TYPE_TX_EVENT);
>
> - event.ptr = cpu_to_le64(ring->rbase + ring->rd_offset * sizeof(*tre));
> - event.dword[0] = MHI_TRE_EV_DWORD0(code, len);
> - event.dword[1] = MHI_TRE_EV_DWORD1(ring->ch_id, MHI_PKT_TYPE_TX_EVENT);
> + ret = mhi_ep_send_event(mhi_cntrl, ring->er_index, event, MHI_TRE_DATA_GET_BEI(tre));
> + kfree(event);
>
> - return mhi_ep_send_event(mhi_cntrl, ring->er_index, &event, MHI_TRE_DATA_GET_BEI(tre));
> + return ret;
> }
>
> int mhi_ep_send_state_change_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_state state)
> {
> - struct mhi_ring_element event = {};
> + struct mhi_ring_element *event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL);
> + int ret;
> +
> + event->dword[0] = MHI_SC_EV_DWORD0(state);
> + event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_STATE_CHANGE_EVENT);
>
> - event.dword[0] = MHI_SC_EV_DWORD0(state);
> - event.dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_STATE_CHANGE_EVENT);
> + ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
> + kfree(event);
>
> - return mhi_ep_send_event(mhi_cntrl, 0, &event, 0);
> + return ret;
> }
>
> int mhi_ep_send_ee_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ee_type exec_env)
> {
> - struct mhi_ring_element event = {};
> + struct mhi_ring_element *event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL);
> + int ret;
> +
> + event->dword[0] = MHI_EE_EV_DWORD0(exec_env);
> + event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_EE_EVENT);
>
> - event.dword[0] = MHI_EE_EV_DWORD0(exec_env);
> - event.dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_EE_EVENT);
> + ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
> + kfree(event);
>
> - return mhi_ep_send_event(mhi_cntrl, 0, &event, 0);
> + return ret;
> }
>
> static int mhi_ep_send_cmd_comp_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ev_ccs code)
> {
> + struct mhi_ring_element *event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL);
> struct mhi_ep_ring *ring = &mhi_cntrl->mhi_cmd->ring;
> - struct mhi_ring_element event = {};
> + int ret;
> +
> + event->ptr = cpu_to_le64(ring->rbase + ring->rd_offset * sizeof(struct mhi_ring_element));
> + event->dword[0] = MHI_CC_EV_DWORD0(code);
> + event->dword[1] = MHI_CC_EV_DWORD1(MHI_PKT_TYPE_CMD_COMPLETION_EVENT);
>
> - event.ptr = cpu_to_le64(ring->rbase + ring->rd_offset * sizeof(struct mhi_ring_element));
> - event.dword[0] = MHI_CC_EV_DWORD0(code);
> - event.dword[1] = MHI_CC_EV_DWORD1(MHI_PKT_TYPE_CMD_COMPLETION_EVENT);
> + ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
> + kfree(event);
>
> - return mhi_ep_send_event(mhi_cntrl, 0, &event, 0);
> + return ret;
> }
>
> static int mhi_ep_process_cmd_ring(struct mhi_ep_ring *ring, struct mhi_ring_element *el)
> --
> 2.25.1
>
--
மணிவண்ணன் சதாசிவம்
prev parent reply other threads:[~2023-10-17 7:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 7:35 [PATCH] bus: mhi: ep: Do not allocate event ring element on stack Manivannan Sadhasivam
2023-10-17 7:36 ` Manivannan Sadhasivam [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231017073642.GA5274@thinkpad \
--to=manivannan.sadhasivam@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhi@lists.linux.dev \
--cc=quic_msarkar@quicinc.com \
--cc=schintav@quicinc.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox