From patchwork Tue Jun 6 07:46:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 690278 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 806C8C7EE24 for ; Tue, 6 Jun 2023 07:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236446AbjFFHvf (ORCPT ); Tue, 6 Jun 2023 03:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237515AbjFFHu7 (ORCPT ); Tue, 6 Jun 2023 03:50:59 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5844B30E5 for ; Tue, 6 Jun 2023 00:47:20 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6b15e510630so1907199a34.3 for ; Tue, 06 Jun 2023 00:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686037629; x=1688629629; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MlFTV010nZQAE6a30Glk0hPHQmKZoo0vKsFtf+4D2Uk=; b=HIGV/CmWz7y7WrCFPo3V41nbzrubjgc5bQ1J/hcSntZSJCUYc1H0PYn7ddavlOfLhC HNlTNIZxixuQufsN1uIHgSQVKtGbcbp7WnHO4qCF8ea3ryQlbTmrc6BFh1UsgsDQUdPp akoLeV4s/a/XYd+z0Zn2o/xjqN3V5ZJsKeMrM4Z0wUcPTNdH2qsRHqqpk+d3sxotNQhi AMmEnODQR85S9AwfSyP7QZkbxToObBv2U/o7sQL8M/5XGGbjJZfEQ44zTjQsvZcjLc/w 75gldNdlLGjy7/h5kwdDffrpxgzvYKTgfUr0sC5qmXe65ZU1TLyBFnQKGO4xw0fNtPu3 GNvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686037629; x=1688629629; 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=MlFTV010nZQAE6a30Glk0hPHQmKZoo0vKsFtf+4D2Uk=; b=SQID1kz7h4iyYsk373LbgC52ne27j4bF8KQKa/SOiN7/8VfKOagghdSYYtik8XhLc9 VH/yPZI89qPffLad+A8tJf/SWVC30nk03p4qhLOWsFaRQRU5OGFO/j0rgi8POGA7NnyQ I1/jByQqloaGoHPltARo2/OYeeWVNroORtYEoGBqMrIigIZmeUQjR8eO7IDnyvrh6IVb nthert0OtaVgIRwjc9I/rCrLauoYNQiN4EpfbGuT7AbZO1HomFPstlA2MCmRzkUKLpw9 OPr5lp+jvs7YcDHHtOyGS3TK5WsJubT2Ve08vdz0eTICm9GXXriaaXvwmGcyx/t/jqfM eyMw== X-Gm-Message-State: AC+VfDwXdUznWX3JbgKjrJqXf5aPHmcfSBnT/jmY6Ar6cFUOCZBhk76Q CoHqtYiymTwD35V2AAiez81y X-Google-Smtp-Source: ACHHUZ7LAgd37C5kKnCNBQWTGKJbGCJ5fd/gl0zPmNmKxpAwVLpglV/5zNTs1pfze7+ZOctzhxe41g== X-Received: by 2002:a05:6358:c027:b0:129:c886:9603 with SMTP id ez39-20020a056358c02700b00129c8869603mr931501rwb.11.1686037628588; Tue, 06 Jun 2023 00:47:08 -0700 (PDT) Received: from localhost.localdomain ([117.202.186.178]) by smtp.gmail.com with ESMTPSA id k16-20020a63d110000000b00528b78ddbcesm6927063pgg.70.2023.06.06.00.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 00:47:08 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH] PCI: endpoint: epf-mhi: Fix the outbound window offset handling Date: Tue, 6 Jun 2023 13:16:57 +0530 Message-Id: <20230606074657.31622-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 __pci_epf_mhi_alloc_map() allocates and maps the PCI outbound window memory to endpoint local memory. For taking care of alignment restrictions, the caller needs to specify the address alignment offset. Currently, this offset is not added to the allocated physical and virtual addresses before returning from the function. But __pci_epf_mhi_unmap_free() function substracts the offset before unmapping and freeing the memory, leading to incorrect unmap and free. Fix this issue by adding the offset to physical and virtual addresses in __pci_epf_mhi_alloc_map() itself. This also removes the need to add the offset while doing memcpy in iatu_{read/write}. Fixes: fd0fda1ef61a ("PCI: endpoint: Add PCI Endpoint function driver for MHI bus") Signed-off-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-mhi.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c index f5bbaded49d4..18e46ee446c2 100644 --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c @@ -148,6 +148,9 @@ static int __pci_epf_mhi_alloc_map(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, return ret; } + *paddr = *paddr + offset; + *vaddr = *vaddr + offset; + return 0; } @@ -158,17 +161,9 @@ static int pci_epf_mhi_alloc_map(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl); struct pci_epc *epc = epf_mhi->epf->epc; size_t offset = pci_addr & (epc->mem->window.page_size - 1); - int ret; - ret = __pci_epf_mhi_alloc_map(mhi_cntrl, pci_addr, paddr, vaddr, + return __pci_epf_mhi_alloc_map(mhi_cntrl, pci_addr, paddr, vaddr, offset, size); - if (ret) - return ret; - - *paddr = *paddr + offset; - *vaddr = *vaddr + offset; - - return 0; } static void __pci_epf_mhi_unmap_free(struct mhi_ep_cntrl *mhi_cntrl, @@ -230,7 +225,7 @@ static int pci_epf_mhi_iatu_read(struct mhi_ep_cntrl *mhi_cntrl, u64 from, return ret; } - memcpy_fromio(to, tre_buf + offset, size); + memcpy_fromio(to, tre_buf, size); __pci_epf_mhi_unmap_free(mhi_cntrl, from, tre_phys, tre_buf, offset, size); @@ -258,7 +253,7 @@ static int pci_epf_mhi_iatu_write(struct mhi_ep_cntrl *mhi_cntrl, return ret; } - memcpy_toio(tre_buf + offset, from, size); + memcpy_toio(tre_buf, from, size); __pci_epf_mhi_unmap_free(mhi_cntrl, to, tre_phys, tre_buf, offset, size);