From patchwork Fri Sep 1 07:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13372148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE119CA0FE1 for ; Fri, 1 Sep 2023 07:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344980AbjIAHfW (ORCPT ); Fri, 1 Sep 2023 03:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242819AbjIAHfV (ORCPT ); Fri, 1 Sep 2023 03:35:21 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5189110D3 for ; Fri, 1 Sep 2023 00:35:18 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68a3e271491so1235511b3a.0 for ; Fri, 01 Sep 2023 00:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693553718; x=1694158518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=twC24zwbv4rxrutTxkfSyT3gLWKA93+iK2AGFx/l/NE=; b=SKnLI9TUQ8UOQzraFdSHVXjnDnmc1JKu2SlQ2/VzdUVinUuyArUplhvL56QySnOSWd 2qVV7svLC2z5cYaLwP/KUm7pONjXDM2k7qQt62ZAUeuNizG2ou2oeptFVf3BbGwQgMQS qLpjH5DKebm2ZrxktUW9lkVv8JjTNU/G01WM7vJtPK1XS4o8nGiw2Q9/FxgJD2r60k3b 3pfejLDTiWWIvLZbZSKCHRtovus+JPGkL69TMeP7N/Al71QUt1hvgAhtJFz8ZpZQdsRL tDo2ZGFTPn/TKFSAEnmW4PsG4xebfGZsMG48PI0JQDdcOIQHmmsSToHOr+ohcL1V7cap YJXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693553718; x=1694158518; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=twC24zwbv4rxrutTxkfSyT3gLWKA93+iK2AGFx/l/NE=; b=Ec+E8fZCvR3fdt7oY9WqXVaw7yO7MlDXzxr9pkOToBBBjVrdIqiK6DSYqht+2KjL/J MB5m3Tk3S42KMOrzoqqfkWjIjoPMXOtJD2w/5yO0ZH5eBy/o12Bz5LjfxUFSqdxwLE6G jWLikHnEUuX7BViIFpm4CzCXLzaDvFG4v9fGDSF5XEaHub97nJOdYPj6vwhytTMQwiu8 OBDFIi6TQNcLNtBnLNfVbjBYWoIkLP6WaUI90ZRZturlT0lAyH0Nm5EWMO5CkiRqqSZs e0FJ+wMCK1/fuj0EGNqveyeO71ymTEGacFVPqVSC/hgZtqp0zK7R/j2lkynxbncvHSlA LO6Q== X-Gm-Message-State: AOJu0YxjFQ4pupHuJ7uCZa6mIpu64e7okgfHAkh9vtJlwtKOcckElIe2 CzoorWE8XJxIphTft6dtu/Ux X-Google-Smtp-Source: AGHT+IEbqx6ojHyG0IAXecWFY7u2o3fb/zTxAc6jY/6YNuNvZeWI4jiOxr2Du4dLiD2wjQrRHcx6Iw== X-Received: by 2002:a05:6a00:180f:b0:68a:3bb9:7e86 with SMTP id y15-20020a056a00180f00b0068a3bb97e86mr2327112pfa.0.1693553717713; Fri, 01 Sep 2023 00:35:17 -0700 (PDT) Received: from localhost.localdomain ([59.92.102.217]) by smtp.gmail.com with ESMTPSA id g20-20020a62e314000000b00688214cff65sm2376427pfh.44.2023.09.01.00.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 00:35:17 -0700 (PDT) From: Manivannan Sadhasivam To: mhi@lists.linux.dev Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_msarkar@quicinc.com, schintav@quicinc.com, Manivannan Sadhasivam , stable@vger.kernel.org Subject: [PATCH] bus: mhi: ep: Do not allocate event ring element on stack Date: Fri, 1 Sep 2023 13:05:02 +0530 Message-Id: <20230901073502.69385-1-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 --- 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)