From patchwork Tue Sep 26 20:50:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Leedom X-Patchwork-Id: 9972727 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E0135602BD for ; Tue, 26 Sep 2017 20:50:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF2BC28FDF for ; Tue, 26 Sep 2017 20:50:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDAB92900D; Tue, 26 Sep 2017 20:50:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 657AD28FDF for ; Tue, 26 Sep 2017 20:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968877AbdIZUuJ (ORCPT ); Tue, 26 Sep 2017 16:50:09 -0400 Received: from mail-dm3nam03on0128.outbound.protection.outlook.com ([104.47.41.128]:13344 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967477AbdIZUuI (ORCPT ); Tue, 26 Sep 2017 16:50:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chelsious.onmicrosoft.com; s=selector1-chelsio-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=7BULyt85eCb1sd70RRrL6q0pYWM5ni4Pk9ib6zAk2Jc=; b=UYj2u1r2w4+oikeW4NflfTjFOLHzHJZsyfqEhsg52Ey45gOzVvTnCgyG8YwIK2kFnHeTa9fshNov/AS8jBs+jUGM0CuzlpKi6uXfU02tAkNPSPDQ63Im1e0Z72A9Een4oaEtcgr9mBxfHsp8tedtRAUDrvd1FpKQ7Tyo/4QxkN4= Received: from MWHPR12MB1600.namprd12.prod.outlook.com (10.172.56.13) by MWHPR12MB1952.namprd12.prod.outlook.com (10.175.56.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Tue, 26 Sep 2017 20:50:03 +0000 Received: from MWHPR12MB1600.namprd12.prod.outlook.com ([10.172.56.13]) by MWHPR12MB1600.namprd12.prod.outlook.com ([10.172.56.13]) with mapi id 15.20.0077.011; Tue, 26 Sep 2017 20:50:02 +0000 From: Casey Leedom To: "Raj, Ashok" , Robin Murphy CC: "Harsh Jain" , Herbert Xuy , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , Dan Williams , "dwmw2@infradead.org" 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/4CAAANTgIAAAaSAgABj5z8= Date: Tue, 26 Sep 2017 20:50:02 +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> <20170926143441.GA136940@otc-nc-03>, <20170926144032.GA90930@otc-nc-03> In-Reply-To: <20170926144032.GA90930@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; MWHPR12MB1952; 6:1mRW8Clbg5HOSQ5R6N2acfLq6em/coDZ+IY1z5yE14ctmru+rTCNuzecA2iYa8giMIBAy4qcL+GYALFWHdfaq5Oni1u+mahvedza6Pe76LtPFdMLxbFzZGJiiY57W2gCUHUotvqP5lKv6t27fT+ZHGNZcZvWScnU6WYXBvj5+FtE+MViWeL12lL6Haqypxl3XBG6+RgOpbimaE/GeyGwSBtNKGw0bzgqAkvG69whiIDXGu3R48Tk4CLb7uNDLv3rlUyLuk6t4KHABIrWXaHjwySQa/fKAJGgjHFb5pZNhE9X91ydbkCmK5AhWp8QtJE4bRDFOxXlzz/qvSGWmsp7BQ==; 5:SQV3tK0slOOM20CJeElOlgzZ6yeVLnx3R81gmCS96FVU7b2/7taKSDChTvl8+KzpbHst5nrsdIfKOrOTmWKK6WIU2hBhpZXfr0ooUnwxN4Xv0+8JPv0R1CvSrkFMQW2qbBUWrmLRaLVXbsrKsOApwQ==; 24:SsKDoa5rMpEPaeSkackdJ+sIrJ9A0XjiFQl1W4Lw2uf4yltU9lTxqdvVz/+NEu4x04wAKg3KUKEO/woBOCFlHEFpYi4kLHOagxYTwRHUf48=; 7:G9Qa/xr4dS+UZLoi84caCCLWxxk8Ed37e515IgxiN+krSnMYf1v/5EVpoY/rCjjHqCM83Ziqj7FdaGvAQvDWb1cBX5GwHaShDHmq8HixtUkR/qCAL0NOmaNU/Ds+Hdf9vLdjfeiTwxjJhGuxa6pSp7pLkBbHCXcd5yN1Z/xPyjLmghHJaTQezAQNBrcq2B9oMocPO4qRunxotPxNkHlBh2evmFc0VKM2nzADGt+D61A= 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)(99286003)(8936002)(8676002)(229853002)(6506006)(7696004)(106356001)(97736004)(110136005)(2900100001)(50986999)(55016002)(66066001)(76176999)(14454004)(53936002)(25786009)(54356999)(4326008)(105586002)(9686003)(189998001)(2906002)(86362001)(101416001)(6116002)(81166006)(3280700002)(5660300001)(3660700001)(93886005)(33656002)(81156014)(478600001)(6246003)(2950100002)(68736007)(77096006)(316002)(7736002)(102836003)(6436002)(305945005)(74316002)(54906003)(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: c40104b8-e4ea-4453-57ea-08d50520290c 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:; 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)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123560025)(20161123558100)(2016111802025)(20161123564025)(6043046)(6072148)(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 received-spf: None (protection.outlook.com: chelsio.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: chelsio.com X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Sep 2017 20:50:02.7154 (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-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So just to be 100% sure I understand the patch you're proposing, you got the first use of VTD_PAGE_SHIFT wrong; it should have been VTD_PAGE_MASK? I.e. ??? And I'm still confused about this portion: - sg->dma_address = ((dma_addr_t)iov_pfn << VTD_PAGE_SHIFT) + sg->offset; + sg->dma_address = ((dma_addr_t) + (iov_pfn + sg->offset) << VTD_PAGE_SHIFT) + off; Isn't iov_pfn a Physical Page Number and we're adding a Byte Offset to that? I would have though that it would be more like: size_t page_off = sg->offset & ~VTD_PAGE_MASK; unsigned long pfn_off = sg->offset >> VTD_PAGE_MASK; ... sg->dma_address = ((dma_addr_t) (iov_pfn + pfn_off) << VTD_PAGE_SHIFT) + page_off; I want to be sure that Harsh has a concrete patch to work with when he wakes up. How about it Robin, Dan, David, Herbert, what do you guys think of Raj's proposed patch? Casey diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 6784a05..d43b566 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2254,10 +2254,13 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, uint64_t tmp; if (!sg_res) { + size_t off = sg->offset & ~VTD_PAGE_MASK; sg_res = aligned_nrpages(sg->offset, sg->length); - sg->dma_address = ((dma_addr_t)iov_pfn << VTD_PAGE_SHIFT) + sg->offset; + sg->dma_address = ((dma_addr_t) + (iov_pfn + sg->offset) << VTD_PAGE_SHIFT) + off; sg->dma_length = sg->length; - pteval = page_to_phys(sg_page(sg)) | prot; + pteval = (page_to_phys(sg_page(sg)) + + (sg->offset << VTD_PAGE_SHIFT)) | prot; phys_pfn = pteval >> VTD_PAGE_SHIFT; }