Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966535AbdIYXl6 (ORCPT ); Mon, 25 Sep 2017 19:41:58 -0400 Received: from mail-cys01nam02on0112.outbound.protection.outlook.com ([104.47.37.112]:22978 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965197AbdIYXl4 (ORCPT ); Mon, 25 Sep 2017 19:41:56 -0400 From: Casey Leedom To: "Raj, Ashok" , Dan Williams CC: Herbert Xu , "dwmw2@infradead.org" , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , "Harsh Jain" , "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/YGlya50aETYTEmnILyqK9cAoAgAAkZQCACFcnkoAAINWAgAAIn0mAAAJkAP//7QmAgABL8sk= Date: Mon, 25 Sep 2017 23:41:52 +0000 Message-ID: References: <20170920080151.GA3348@gondor.apana.org.au> <26992a1e-edb3-ed78-ce8e-31e0739d75f4@arm.com> ,<20170925190310.GA132175@otc-nc-03> In-Reply-To: <20170925190310.GA132175@otc-nc-03> 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;MWHPR12MB1950;6:eev2FJ3FdfOKvnuJDRd+kCvK6lTB5cqEOHRryfyUI7vwh2YR9hVqQKmD17x2eXKJE7qKhgxFfsldbaFniP27gGA4EnK7FmW4OMT1r65JhIbsCKiCI0bBGWxSdyCqtq+CVg7tw9J8Y6oFxZ74UkTxkNCoudCQ5I12MQNPIjD2wFjRyWbZ/+K1wegdiotEU6zMtZAeBXlJtAQisHckYg+PzPKbCnkYkMzuEmb6FKYCpC14jwyt7oNc9rRVY0Nxc+WvSb4WAmXu/3MZTyx6shTPBcCVdCIjAsQL6OcGcpzCUsBIwxDxO2ReRmZGRi5JFqKuh8IdMSCO3zOB2XTMx/MQdw==;5:TGhz/x6E044XDElQUqtTAAxpuPsH+HhTA/OlYra93WpoEkh5m3o9fm8UBZA6BR1gAuPBc11jL2ffBl0puMmmatljy5Us3do8iWS5N0TjSoTE9Gggb+4FyJ7vlAaWQPduin7eBmt/Sji3AGYVdqfCyw==;24:2UtzInD4aTE/2v1HGY2e5ZHmd+ELTB30JNDrWnBALYvSsfkVe3E9yCr1L6lvIslASVZeNHTsnUWyJnlQxjttokJD9qGjkZ4T8nWTTqOc9OI=;7:STsle/SrElBLd2YKkF3MIxL5IldHeviz3VdfmqLZOC4WFY+M1lmEA2Xf18oYZ5k2JLXQivWk+xUAhr2FlExa8C4/xqcksfpCyspula5GwOXBRH6R2TN+V4HAm4Bu3Y/fFotKpz2GgahQ8pO/8fDICNT9vuDz6ajX4eROcSm/OfePTmqN5Sj0wz0f63nnmHJqlbcGPTotJym5b05M4k5kvo2D9xef9KKqOZgy28oB65o= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(6009001)(39830400002)(376002)(346002)(189002)(24454002)(199003)(377454003)(81156014)(33656002)(97736004)(9686003)(81166006)(8676002)(316002)(102836003)(6246003)(2900100001)(6116002)(3846002)(4326008)(107886003)(8936002)(53546010)(189998001)(55016002)(68736007)(99286003)(2906002)(6436002)(54906003)(110136005)(14454004)(86362001)(53936002)(7696004)(3280700002)(106356001)(5660300001)(25786009)(229853002)(6506006)(478600001)(77096006)(101416001)(105586002)(305945005)(50986999)(76176999)(7736002)(3660700001)(54356999)(74316002)(93886005)(66066001)(2950100002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR12MB1950;H:MWHPR12MB1600.namprd12.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-ms-office365-filtering-correlation-id: cf3ad7ca-dcea-42ff-e88c-08d5046eff72 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(2017082002075)(2017052603199)(201703131423075)(201702281549075);SRVR:MWHPR12MB1950; x-ms-traffictypediagnostic: MWHPR12MB1950: x-exchange-antispam-report-test: UriScan:(228905959029699); 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)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123555025)(20161123562025)(20161123558100)(2016111802025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(6072148)(6043046)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR12MB1950;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR12MB1950; 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 23:41:52.0490 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 065db76d-a7ae-4c60-b78a-501e8fc17095 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1950 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 v8PNgPT2016825 Content-Length: 2073 Lines: 49 | From: Raj, Ashok | Sent: Monday, September 25, 2017 12:03 PM | | On Mon, Sep 25, 2017 at 01:11:04PM -0700, Dan Williams wrote: | > On Mon, Sep 25, 2017 at 1:05 PM, Casey Leedom wrote: | > > | From: Dan Williams | > > | Sent: Monday, September 25, 2017 12:31 PM | > > | ... | > > | IIUC it looks like this has been broken ever since commit e1605495c716 | > > | "intel-iommu: Introduce domain_sg_mapping() to speed up | > > | intel_map_sg()". I.e. it looks like the calculation for pte_val should | > > | be: | > > | | > > | pteval = (page_to_phys(sg_page(sg)) + sg->offset) | prot; | > > | > > Hhmmm, shouldn't that be: | > > | > > pteval = (page_to_phys(sg_page(sg)) + (sg->offset>>PAGE_SHIFT)) | prot; | > | > Yes, I think you're right. We do want to mask off the page-unaligned | > portion of sg->offset. | | Shoulnd't we normalize the entire sg_page(sg) + sg_offset. | | if when you only mask the page-unaligned portion i suspect you might be | pointing to a different region? | | something like (sg_page(sg) + (sg->offset << VTD_PAGE_SHIFT)) | | then add the unaligned part.. sg->offset>>VTD_PAGE_SHIFT | | Is this happening because you are using a 2M page? not sure what triggers | this or causes the driver to get passed in larger than 4K offset, or | running 32bit kernel? | | if its legal to get passed in such odd values, we should fix IOMMU driver to | handle it properly, otherwise we should atleast fail those requests. (woof) This is all above me. I've spent a chunk of time fruitlessly trying to find documentation which says that scatterlist's are allowed to have offset/length values which extend outside the sg_page(sg). So someone much more familiar with this stuff is going to need to say what's allowed. As I said, I've asked Harsh to provide us with a detailed trace of exactly what he's seeing and what the Scatter/Gather Lists are getting translated into. That information may make it easier to understand if/how __domain_mapping() is screwing up ... Casey