Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965356AbdIYRqr (ORCPT ); Mon, 25 Sep 2017 13:46:47 -0400 Received: from mail-bl2nam02on0094.outbound.protection.outlook.com ([104.47.38.94]:11027 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934514AbdIYRqo (ORCPT ); Mon, 25 Sep 2017 13:46:44 -0400 From: Casey Leedom To: Robin Murphy , Herbert Xu , "Harsh Jain" CC: "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , "dwmw2@infradead.org" , David Woodhouse , Dan Williams Subject: Re: DMA error when sg->offset value is greater than PAGE_SIZE in Intel IOMMU Thread-Topic: DMA error when sg->offset value is greater than PAGE_SIZE in Intel IOMMU Thread-Index: AQHTLrKuCX/YGlya50aETYTEmnILyqK9cAoAgAAkZQCACFcnkg== Date: Mon, 25 Sep 2017 17:46:40 +0000 Message-ID: References: <20170920080151.GA3348@gondor.apana.org.au>,<26992a1e-edb3-ed78-ce8e-31e0739d75f4@arm.com> In-Reply-To: <26992a1e-edb3-ed78-ce8e-31e0739d75f4@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=leedom@chelsio.com; x-originating-ip: [12.32.117.8] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR12MB1952;6:NLrmyqSsEHbUBTAdLcSqmLLrDnNaUOwB/XGuQvUeXZk5ilMz9RWEwHQWfrcxvslZ+yEx+6RHq8mXdSy/jGbCaHKbupAzQLo9pfl85eWhCLRZr/H0iYW0seaOitrE6DAhNh7b/esAMKDGbxDCWbJZ9yogEYYcZ35zs2Ki9LVZUO58k54vL/aG9zOHGhT78ZTtjg2OeDomYOQ4mtXcFxNBDJdWAahkuFszYOqdvfDxDswG0qj9/lxdLGJkvIYkehgZQUHxvmXRUSIuP8Qyky79GrJhuDqhiSv/RHJLieH4KBlpLA3I1D1z155u/VPSz8exVq6TNvD3UlqBXYO2sqSbfA==;5:2i5m0vhjsomduwWgBE/12+wYTmi810+o1Vqz8qcZP0kgKmGgAO2T4M1+BO5YnpvAPyoDnwhVkYAn4gkBJ8AKq/MZojx9u59V/x8ZVRfm3Q/ag7Eb4/acaMUiS4GJ9Wmaoj2zIz5E6E4Obl1+sINuMg==;24:WI+bUQTlljZpW9gH6qGr3LpMcJlZ6hBDkya1TXxTftPF6KsXMnd5WEUR1BpK7ilLKn6vvcluFVRhgK4eTTM833RvNIdtcsJkYfiJP7lvnpI=;7:i6JOGyB0KOJfKuMPBQAQPWBy+Lyf8H8B+LWTH9XvdOEIKHGxzeFdJ0pJVj2OG0JI7xWw9OZefDF/HsPYsVW/qjJDcxX7UKz8y4CyjkIsRvdDb502B1HZJukNTHvUW9VnkJgOhw1CrPTlLiWjn5IeHc1yEFMI0iSmVl6vX5illYB4TYTpdFwiSYheCWphbpaZA7+vWDGMXNCGN6awYFeTqNFtDtjLyhBMmZCG7CG79ck= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(6009001)(346002)(376002)(199003)(189002)(24454002)(377454003)(8676002)(7696004)(106356001)(2900100001)(110136005)(14454004)(55016002)(50986999)(6246003)(97736004)(66066001)(25786009)(53936002)(54356999)(76176999)(9686003)(105586002)(4326008)(189998001)(2906002)(101416001)(81156014)(33656002)(86362001)(3660700001)(81166006)(5660300001)(68736007)(478600001)(3280700002)(2950100002)(8936002)(99286003)(6506006)(229853002)(77096006)(6636002)(54906003)(316002)(7736002)(53546010)(102836003)(6116002)(6436002)(305945005)(74316002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR12MB1952;H:MWHPR12MB1600.namprd12.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-correlation-id: 07ee93c1-55f1-400a-c489-08d5043d60fb x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(2017082002075)(2017052603199)(201703131423075)(201702281549075);SRVR:MWHPR12MB1952; x-ms-traffictypediagnostic: MWHPR12MB1952: x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123555025)(2016111802025)(20161123558100)(20161123564025)(20161123560025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(6043046)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR12MB1952;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR12MB1952; x-forefront-prvs: 04410E544A spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 X-OriginatorOrg: chelsio.com X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Sep 2017 17:46:40.7234 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 065db76d-a7ae-4c60-b78a-501e8fc17095 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1952 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v8PHmGVU025916 Content-Length: 2636 Lines: 58 | From: Robin Murphy | Sent: Wednesday, September 20, 2017 3:12 AM | | On 20/09/17 09:01, Herbert Xu wrote: | > | > Harsh Jain wrote: | >> | >> While debugging DMA mapping error in chelsio crypto driver we | >> observed that when scatter/gather list received by driver has | >> some entry with page->offset > 4096 (PAGE_SIZE). It starts | >> giving DMA error. Without IOMMU it works fine. | > | > This is not a bug. The network stack can and will feed us such | > SG lists. | > | >> 2) It cannot be driver's responsibilty to update received sg | >> entries to adjust offset and page because we are not the only | >> one who directly uses received sg list. | > | > No the driver must deal with this. Having said that, if we can | > improve our driver helper interface to make this easier then we | > should do that too. What we certainly shouldn't do is to take a | > whack-a-mole approach like this patch does. | | AFAICS this is entirely on intel-iommu - from a brief look it appears | that all the IOVA calculations would handle the offset correctly, but | then __domain_mapping() blindly uses sg_page() for the physical address, | so if offset is larger than a page it would end up with the DMA mapping | covering the wrong part of the buffer. | | Does the diff below help? | | Robin. | | ----->8----- | diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c | index b3914fce8254..2ed43d928135 100644 | --- a/drivers/iommu/intel-iommu.c | +++ b/drivers/iommu/intel-iommu.c | @@ -2253,7 +2253,7 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, | sg_res = aligned_nrpages(sg->offset, sg->length); | sg->dma_address = ((dma_addr_t)iov_pfn << VTD_PAGE_SHIFT) + sg->offset; | sg->dma_length = sg->length; | - pteval = page_to_phys(sg_page(sg)) | prot; | + pteval = (sg_phys(sg) & PAGE_MASK) | prot; | phys_pfn = pteval >> VTD_PAGE_SHIFT; | } Adding some likely people to the Cc list so they can comment on this. Dan Williams submitted that specific piece of code in kernel.org:3e6110fd54 ... but there are lots of similar bits in that function. Hopefully one of the Intel I/O MMU Gurus will have a better idea of what may be going wrong here. In the mean time I've asked our team to gather far more detailed debug traces showing the exact Scatter/Gather Lists we're getting, what they get translated to in the DMA Mappings, and what DMA Addresses were seeing in error. Casey