Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969332AbdIZRaW (ORCPT ); Tue, 26 Sep 2017 13:30:22 -0400 Received: from mail-cys01nam02on0112.outbound.protection.outlook.com ([104.47.37.112]:22496 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S968060AbdIZRaS (ORCPT ); Tue, 26 Sep 2017 13:30:18 -0400 From: Casey Leedom To: Robin Murphy , "Harsh Jain" , "Raj, Ashok" CC: Herbert Xu , David Woodhouse , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , Dan Williams , "dwmw2@infradead.org" , Michael Werner 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/YGlya50aETYTEmnILyqK9cAoAgAAkZQCACFcnkv//5CkAgAAvAguAAJgAAIAAj7QAgAAh/4CAADJrlA== Date: Tue, 26 Sep 2017 17:30:15 +0000 Message-ID: References: <20170920080151.GA3348@gondor.apana.org.au> <26992a1e-edb3-ed78-ce8e-31e0739d75f4@arm.com> <20170925155430.GB131920@otc-nc-03> <6d2af675-7b97-6eaf-4daa-d7bf80a05923@chelsio.com>,<437a9bd8-d4d6-22ca-1a64-1a3e73f1101a@arm.com> In-Reply-To: <437a9bd8-d4d6-22ca-1a64-1a3e73f1101a@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:aOdbEwM+esADipXfaMYhxCIll16MD90XFq53w9uAIYsCWiuabescaLZhpCu5iqeG1hwbTRcVGSka+3Y4l6enoh0Kt55rLJ9gXaVScFe1PnbKfahAfKcQs9c4RiBdNYt+pvvY+udCekk+ZELM5dITYLEArzdgwea9Cxz8biSpIriqRPNJFHB5ScCpkKd66UNZaN3kapwv4lvz9DKNkTprjau7Qynr8azju5Wk+YKohI+x0xtzzHIWVBS+Ws+7tmQzQvWioqHSLxHbfeb3gfcvfmeXLQDIMvTU1yfb+TLVKxTscKTc/Lcql/k96p1cBduTBbQmbgXueD1tbojZLyz1sw==;5:m5bLAbKM3gjpF+TiRmb4f8Sf7k2SriwH6YRUPzbyI5nCWdGcHkJMSvVY9LgOHFKh2+MSzhqZpC8vJtyYafov7s3NSAyeXy9RQiKmMjKK0gJwGk6z+g9L4qucA3ZS/nPLN0K43iY4N5ERrgNyWtDsPQ==;24:dMlMWsqAh68mt9wJlJbPVq74wfOeEZMIzpr9wBghG9QquPgceml5dD8KU/dsR5YhPwWJAAYRqSQxeLjWQe6bsgeaFMYUVrtrhnKthtKR2B0=;7:pjOgFVH+Y4T2p3kwr1zO7U0eL7S0z0I7KL3gLgnxtPsw8vPczpfoHvD/07jRO7fUIWnIw4qjeAN7AteTU+ctyorcLO/RXKCi+8E/hq8AbDBvTFsuP31/Hfs7Sg3ceHyZ81iHD/I+WYEOSkNrVwfixG/nhWhpKpz3FMnM+7oDpeQnoC/ynH/IpO0Ck3ctqh6lU0qqRhqTCI0JnItprXQzJHdcYubSogAY9mqjfr4wMIs= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(6009001)(346002)(376002)(189002)(24454002)(377454003)(199003)(81156014)(33656002)(6246003)(478600001)(68736007)(93886005)(2950100002)(3280700002)(3660700001)(81166006)(5660300001)(7736002)(305945005)(102836003)(6436002)(316002)(54906003)(53546010)(74316002)(3846002)(8936002)(5890100001)(77096006)(107886003)(66066001)(97736004)(76176999)(14454004)(55016002)(50986999)(105586002)(9686003)(25786009)(53936002)(54356999)(4326008)(7696004)(6506006)(229853002)(99286003)(8676002)(110136005)(2900100001)(106356001)(6116002)(86362001)(2906002)(189998001)(101416001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR12MB1952;H:MWHPR12MB1600.namprd12.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-ms-office365-filtering-correlation-id: 0419956f-a987-418c-ad27-08d505044036 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)(8121501046)(5005006)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6041248)(20161123558100)(20161123562025)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(2016111802025)(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: 0442E569BC 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: 26 Sep 2017 17:30:15.7501 (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 v8QHUWdb032020 Content-Length: 2211 Lines: 50 | From: Robin Murphy | Sent: Tuesday, September 26, 2017 7:22 AM | | On 26/09/17 13:21, Harsh Jain wrote: | > Find attached new set of log. After repeated tries it panics. | | Thanks, that makes things a bit clearer - looks like fixing the physical | address/pteval calculation to not be off by a page in one direction wasn't | helping much because the returned DMA address is actually also off by a | page in the other direction, and thus overflowing past the allocated IOVA | into whoever else's mapping happened to be there; complete carnage ensues. | | After another look through the intel_map_sg() path, here's my second (still | completely untested) guess at a possible fix. | | Robin. | | ----->8----- | diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c | index 6784a05dd6b2..d7f7def81613 100644 | --- a/drivers/iommu/intel-iommu.c | +++ b/drivers/iommu/intel-iommu.c | @@ -2254,10 +2254,12 @@ static int __domain_mapping(struct dmar_domain *doma! | uint64_t tmp; | | if (!sg_res) { | + size_t off = sg->offset & ~PAGE_MASK; | + | sg_res = aligned_nrpages(sg->offset, sg->length); | - sg->dma_address = ((dma_addr_t)iov_pfn << VTD_PAGE_S! | + sg->dma_address = ((dma_addr_t)iov_pfn << VTD_PAGE_S! | sg->dma_length = sg->length; | - pteval = page_to_phys(sg_page(sg)) | prot; | + pteval = (page_to_phys(sg_page(sg)) + sg->offset - o! | phys_pfn = pteval >> VTD_PAGE_SHIFT; | } Robin, Harsh was able to do an initial test of you proposed patch above and his test setup survived for 2 minutes with iperf traffic before his PEER went belly up. Since his PEER isn't on a Remote Power IPMI, we'll have to wait till tomorrow for further tests -- Harsh does have to sleep some time ... :-) But the 2 minutes his test machine did survive were Very Promising! And I see that Raj has also sent a couple of proposed fixes now. It's just as well that Harsh is off to bed now so we can hash things out while he sleeps ... Casey