Received: by 10.213.65.68 with SMTP id h4csp2117670imn; Sun, 8 Apr 2018 20:08:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx49DbTXVbnGih+qhr5YsEfVCSN5Dr1HoDc1RwE3yF+va04bdwcVn9uYUXYJHqilHHsfVhz0N X-Received: by 10.101.83.7 with SMTP id m7mr23840864pgq.1.1523243325043; Sun, 08 Apr 2018 20:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243325; cv=none; d=google.com; s=arc-20160816; b=XRap/BjDj+aZ61ckGrBFTy6gB92PvzRW+jBI+pXj2+DnbnzE4gTcTLkMfO1AIYtXTJ PRHH98VMnGu2NAJHW3YM4BrUPRBIC0AuwjKhha56yGm2BZ2zLYO+ZN/Eagh6gYj0EUdu ul34G8M0Y/6vIJeI7QjUa07ZQxFXh5VWnLoQ3l68kXt7si/uF31SizExww7v+6vbrvAS LNrrFxtLWehcY5GViSSmzqAX7supkxLD+XEePn6E4Ui07Ua/91xQN7LYDdJsYWun2rTl JeDMC/HL/F78630RCLAFc/sT1oQdFn/00o8tYxc4afYGOLEceXSnYs1QC9bwvxkkRai3 EmiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=VZ+rwi0QDDz/WfFYp/37rj62wNYV3fyp+pYLbXzZ3Qc=; b=vaPI+N/ZOYtlP0wJViFKBmFx1Pn6L31uKs8AuEZSbd/gQuZBqDdsD4tkchObgG714J QZf3GbeVmS4IW+499c40vb3jLiQhr7fsK5KWWgfxA0/V2c1cM3U6DRaqpmQnvyNnFmSZ fUo36gTbAoLSJxU+VsO124GdWJVtVitfozWVhKqL3+1D7zCpgUmCvGkL6szqRmv45iqQ NT+pa/9+ZGZShRpwQQYPkfFkVEivQ1qcct6RZGidGEu5W373PNBuQ7GMKc4OxMzQydOh 7eCufvoQnNzxQRO+Dk1tpYch+g0g1/d2/VIJ2WTgulFIR06JnJ9MKa37LrjOu5fgzDKG Yo6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=FBeh/puw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l84si12041079pfj.344.2018.04.08.20.08.08; Sun, 08 Apr 2018 20:08:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=FBeh/puw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757736AbeDICKc (ORCPT + 99 others); Sun, 8 Apr 2018 22:10:32 -0400 Received: from mail-by2nam03on0135.outbound.protection.outlook.com ([104.47.42.135]:16544 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756212AbeDIAbQ (ORCPT ); Sun, 8 Apr 2018 20:31:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VZ+rwi0QDDz/WfFYp/37rj62wNYV3fyp+pYLbXzZ3Qc=; b=FBeh/puwbwki7gUUckOsMDd/1kvo/LK3y7cMDcjruQNT9srU67qg6fyeu8lWbIo7vtonAAYK1gODi0AbphADvUOjzR6p1CRYheT83SnY0L1izbSdcQTkv7QRu/EBYDWlaD2cUOI2LAh7O5UZkRYweQgDGnWHV5A/rdzxmiUZ0JA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0917.namprd21.prod.outlook.com (52.132.132.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:31:12 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:31:12 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Vladimir Murzin , Joerg Roedel , Christian Borntraeger , Christoph Hellwig , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 162/293] dma: Take into account dma_pfn_offset Thread-Topic: [PATCH AUTOSEL for 4.9 162/293] dma: Take into account dma_pfn_offset Thread-Index: AQHTz5kxsxKS10aH9keVfokOyy1kRw== Date: Mon, 9 Apr 2018 00:25:00 +0000 Message-ID: <20180409002239.163177-162-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0917;7:S2Ckg+raItUKFKUyXoycijiIH1PzmZl/VCZ/sq0BUHmFRmm5Zn6TXaGIC64lozP5oWUdCG8dWgWvInK/iboTPtEu8hNJyYtwMpMLGeA2QLL0T6rRqrN8GeQIBwUHrOmtHpVbxIrntOBNIkM6CuK/179zK9dwl606pyMbaqxpRg2F0mC6KSXN6Ndwvw8UuJnmOfI7OqSIT9lxCsLifisIWiihIu3h+Zj4HFPMb1LpEPAU2nO6XvD72Tw9C9R0uqKx;20:cHJU8nC49AZ0rBGHbZmOD64Og75Pqgf44D2Bc3VFucCLV4Ks7TR8Ee9Cxrfz3WhfaxjUmqK1AINWCxNzEybTIr7RaJrnJMK0ANeaIwZvaJkExDaN/QroS2ztdW6/gasll+bOCLsxW6hmRQHYgMRarpNyENDN3VKJU0IPjl9T+LY= X-MS-Office365-Filtering-Correlation-Id: c6268656-e28c-4763-602f-08d59db132ac x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB0917; x-ms-traffictypediagnostic: DM5PR2101MB0917: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171)(190383065149520)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0917;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0917; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(366004)(396003)(346002)(376002)(189003)(199004)(99286004)(22452003)(106356001)(26005)(110136005)(478600001)(54906003)(10290500003)(316002)(1076002)(72206003)(186003)(4326008)(97736004)(66066001)(11346002)(25786009)(86362001)(476003)(446003)(2906002)(6666003)(6486002)(105586002)(86612001)(3280700002)(3660700001)(6512007)(3846002)(6116002)(6436002)(2616005)(486006)(53936002)(7736002)(8676002)(81166006)(81156014)(8936002)(68736007)(305945005)(10090500001)(76176011)(6506007)(102836004)(36756003)(107886003)(59450400001)(2900100001)(2501003)(14454004)(5660300001)(15650500001)(5250100002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0917;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: X7cFl7mj+Luxmg9bHw9ND5s6TcDhi7bGq56CXworsPBHrfwi3QIia3p3chkNp1csf+rKIGSLNgPEN+XYw+2IGGcFQD+dD6TpQwH2eq4KzGRw7bpXgIz47g1/nOYUWXyHwcOOiGLoWPxpplbL/mVzs1JEOAOghRdIS2EQJfHOiOzB/vcHpANSx2SSsi5Do6vyAIW9VMtbgf5SDUbH5Wfzv2OCqxLaLtTz2pb7xbwrPR1KuRvGrgvI8B+7KoNrEiH3ROQgYbEAFV2Np0PKGg0WjTZsHlFdTEExqPHb8GkDzulVidVzHZAqBQkdyC0GUGC6dPUvKpDvHI5zKlhaTywywxGaqMlE5GOljHFhedtEIdsdCx9EJ7U4O8WyRcPHv7tBvzWPig49uWkuVeDU4GKS2om7jeohQVDYG44ZWBtEk1k= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6268656-e28c-4763-602f-08d59db132ac X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:25:00.1907 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0917 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Murzin [ Upstream commit 25f1e18870881f3366a5abec27b651983ce9032c ] Even though dma-noop-ops assumes 1:1 memory mapping DMA memory range can be different to RAM. For example, ARM STM32F4 MCU offers the possibility to remap SDRAM from 0xc000_0000 to 0x0 to get CPU performance boost, but DMA continue to see SDRAM at 0xc000_0000. This difference in mapping is handled via device-tree "dma-range" property which leads to dev->dma_pfn_offset is set nonzero. To handle such cases take dma_pfn_offset into account. Cc: Joerg Roedel Cc: Christian Borntraeger Reported-by: Benjamin Gaignard Tested-by: Benjamin Gaignard Tested-by: Andras Szemzo Tested-by: Alexandre TORGUE Reviewed-by: Robin Murphy Signed-off-by: Vladimir Murzin Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- lib/dma-noop.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/dma-noop.c b/lib/dma-noop.c index 3d766e78fbe2..9a7b5ed7ceac 100644 --- a/lib/dma-noop.c +++ b/lib/dma-noop.c @@ -7,6 +7,7 @@ #include #include #include +#include =20 static void *dma_noop_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, @@ -16,7 +17,8 @@ static void *dma_noop_alloc(struct device *dev, size_t si= ze, =20 ret =3D (void *)__get_free_pages(gfp, get_order(size)); if (ret) - *dma_handle =3D virt_to_phys(ret); + *dma_handle =3D virt_to_phys(ret) - PFN_PHYS(dev->dma_pfn_offset); + return ret; } =20 @@ -32,7 +34,7 @@ static dma_addr_t dma_noop_map_page(struct device *dev, s= truct page *page, enum dma_data_direction dir, unsigned long attrs) { - return page_to_phys(page) + offset; + return page_to_phys(page) + offset - PFN_PHYS(dev->dma_pfn_offset); } =20 static int dma_noop_map_sg(struct device *dev, struct scatterlist *sgl, in= t nents, @@ -43,11 +45,12 @@ static int dma_noop_map_sg(struct device *dev, struct s= catterlist *sgl, int nent struct scatterlist *sg; =20 for_each_sg(sgl, sg, nents, i) { + dma_addr_t offset =3D PFN_PHYS(dev->dma_pfn_offset); void *va; =20 BUG_ON(!sg_page(sg)); va =3D sg_virt(sg); - sg_dma_address(sg) =3D (dma_addr_t)virt_to_phys(va); + sg_dma_address(sg) =3D (dma_addr_t)virt_to_phys(va) - offset; sg_dma_len(sg) =3D sg->length; } =20 --=20 2.15.1