Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6746876rwd; Tue, 6 Jun 2023 01:01:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gjFtpjP1ARh555emotQIqmbkLETVkTDXlOp8U5F2Un4f3bJ44suWiEZghgXs/jgBluWm6 X-Received: by 2002:a17:90a:4302:b0:259:343:8e74 with SMTP id q2-20020a17090a430200b0025903438e74mr1214684pjg.7.1686038484517; Tue, 06 Jun 2023 01:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686038484; cv=none; d=google.com; s=arc-20160816; b=khYB/rdfktXf5DzFvkh4QtVvniDb5F8+7I4Cut22k/CnOu51AXzoVnekTY0Ok8b//Q W2i4Ka4aZBBfS1DyAVmJnIu/EZW2dK4BVh78BuyMjxfdoT4Hd9vac2rpohjx73qi1YUz sQq0OP6W2VvHaPRpKJKlseyXwmC0r5IGLNUhr6EOZfweIS70BXd/OXmIx2+gOb7IV2A1 zM266lPsfBpbUY6zY4SePOfVFlYkAdn4BfN+ki2FF+q6Htnxn/YkQPMiqD3NpeVS3zm+ 7hBNSQHpmpDNGO0HSfeX71ho8EbiId+UyoM5yYB3xC4hFb5let9l/2gMbTe5Yh8qtnnL KR7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MlFTV010nZQAE6a30Glk0hPHQmKZoo0vKsFtf+4D2Uk=; b=SCsriFBySEhdMBVVPiQkXyIx2ftiwcgxYTSYIZEUyKoIr1ZSk7VKo0beDjWYZ1bcuZ s5i5MsG3RQlhOP0CTxG2+VDIGC80UpZSxfkb07j9HasYxO5WM+8gOg7ZbJX5yLq5mu7G vv/5snvOHL7ZCJft7GsPHE5qSQ0yw9glCutb/vO7x25v9QAfWPyN9FfuyuWnC4EII0Yr kZ4KH4wKkBxPnR+xnQZRAARTwvqHvgXolyNIdAR7xreAcGF7C4dQ8L5ES1yzqH2q2KDc a6eJ6BYRIJg7wmLDS8s+zJhGEUDLpWjDXdksfDTdikDABv97oI5c5kJYhayFgbMs81YX ElKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HIGV/CmW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a17090a73c600b0024664356ef7si8580757pjk.152.2023.06.06.01.01.12; Tue, 06 Jun 2023 01:01:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HIGV/CmW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229532AbjFFHvn (ORCPT + 99 others); Tue, 6 Jun 2023 03:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237506AbjFFHu6 (ORCPT ); Tue, 6 Jun 2023 03:50:58 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A2D30DF for ; Tue, 6 Jun 2023 00:47:18 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6b160f3f185so1715487a34.0 for ; Tue, 06 Jun 2023 00:47:18 -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=YisFdExy6aUBo2imP0A4TxP21orwenii8Nk8bhTrbm/wh81RfSQqGIt/Lxg3ZNmyKd nyXtcOdKzbjFBd0wyX0BoZbJkRN34VQ7pqkOHqV7rECOCbVQscEqwyF5kKLa4mThaEvX G5G971DaW3f6BG5chQldMLHGgFsTwAPVmxHUErMwHPZXXGLtnogPVfx/9COWYur4ENFy 390gsfeVM9dOpQ8vlhx77b940r1cjTH9yUToqwslnp32sGrJKAJwQwnBLML3MwoTRc6e 5GY3anLFIBJl9X+ElmMHqThJVAKxRDJV6wTUpdgk8jC5fnb3Tb2dcSX4YljszdaaZOvY 1S/w== X-Gm-Message-State: AC+VfDyXojDiVQ2kbdQYtWDlQb2suGPoQVUGOXF6nwCx8KfyuFHd4mq0 myMxQWlCvmK36HE4MPat7OV1 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.25.1