Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751981AbdI0RSO (ORCPT ); Wed, 27 Sep 2017 13:18:14 -0400 Received: from mail-eopbgr40040.outbound.protection.outlook.com ([40.107.4.40]:25659 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751902AbdI0RSK (ORCPT ); Wed, 27 Sep 2017 13:18:10 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Robin.Murphy@arm.com; Date: Wed, 27 Sep 2017 18:18:02 +0100 From: Robin Murphy To: Casey Leedom Cc: Dan Williams , "Harsh Jain" , "Raj, Ashok" , Herbert Xu , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , "dwmw2@infradead.org" , Michael Werner , nd@arm.com Subject: Re: DMA error when sg->offset value is greater than PAGE_SIZE in Intel IOMMU Message-ID: <20170927181802.3dcd7efb@m750.lan> In-Reply-To: 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> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [91.125.195.39] X-ClientProxiedBy: VI1PR0802CA0018.eurprd08.prod.outlook.com (2603:10a6:800:aa::28) To AM5PR0802MB2450.eurprd08.prod.outlook.com (2603:10a6:203:9f::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6cbc49e1-707d-4ea0-90e2-08d505cbb8a0 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075);SRVR:AM5PR0802MB2450; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0802MB2450;3:xHIyKNlLpZLt4lJPfDPpmFdV1HxPSm0+0DYkzpkCscvsVUuX3avU4BATXuIU4Fq+LF+GKBEoPMShWq0USP0cJVNdGXiS87ezv6lbAZRF2gd4tf/oBEwxZ3t7dFXlmkOVOZkaVacfQWFXnQUBFYauDgy5g+i3r8d2ZYcZvPddMnqhmu3KXZKlf+6BPgEieK4fi1JJYRq5FhabTY+mUPjUAg5SCQK+4i8UB6Bx/PfOBjP9PKLI67ZbVaCZD54aVj0T;25:LTW68pvzYTsNApkN9r4SqxV5vX8vnj4erU4xSXmTKy5yEAzFrefcFHez+D+s1buB5lD+NtPYkT+98gRxvHAOpHJr0bfQ4OhQs1Bb3qTRhnVZdI12Xsj0LCryB6mPsOKito037jaQHLFptDaRaB0W2XK4KPKvTx6E3xmurcaRuRHFfgLnO6BgmIpLwjJdvZG/IBMC6Li8UE9LuTaT7ymMgyjBVnLA4YEMyq9qhhVKbuJU6UOd8P5lejmb3sO3TBbva3ox2WpPfePOvdKBb3tD7fK2p8oOadK8Y2WvSxLb+TeXyekSy6LNXLKcprxcPC+a31GiCgZUpdXUcXB2pQG9Nw==;31:BUNXRlpCLOEfGjrmESGqqeR5x4HD2UffrWjnG/qIqdlH3/qUzP++/8u3lkt+28/4tTs2pqmOeTfVGKEGhGY6dRM3YDWeMkdZgFJ740OrW+V43VOK4NgcRhvPwYC6lGiF4m79xbKWmNS27DVIe15XuYbG8R3b8ZR++QQ/sYlGxgUokrKsq26LiLm1KH+n1E4dYzXaSbgtb4qvYvq1Cp+DVePBizgRvg1Zv8EEqBgz+IA= X-MS-TrafficTypeDiagnostic: AM5PR0802MB2450: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1;AM5PR0802MB2450;20:5kRhrPc+SPERAwCRx+TGNGb/JF54sh04Ml/hkrEVVdVpNaR7DivHZf4la6EHieJp80KM0uNBzLps2Den0qNITgajMgL/TmT/0wcxUsAKYbsLN2LVee17vjtnEr/gLC1Rbwhcy7a3ZDjPFJtl6QczRQ2PS/b0HahUkQ+S+IcR1Zo=;4:+/xGJ9yOxZwcWos/ffoj7sBRVVKiNQPr+siF6EGBMZCBQUhqe65cM+OqSR2YMxaZDHa4Kdsy3LJi/UDaDDt5I19h2CmGxW8UGZQck2/u6Xkcbn3BILpSu9cqTrUfn8CEuQfRREm9qLzfWf3/CZeYV8rMl4T/z8i6ra7eYbjgMkJ1R70t2iWtnRA5TIy5nzufWcLp/sdYBsUEgGYajdWozFoU3Y3hQ0v4wRjwv6QxYrw6cHzMcanNTaLGoe+ac+mNQFUFJH3Q3hWh8R3znm4hR6DA8wcUz4RbX6lUNUWFlu5r+rn4Lkjs6aeOSbl35hyz268O6OVo/F8lIt4k9BmIdA== X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(228905959029699); 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)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:AM5PR0802MB2450;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:AM5PR0802MB2450; X-Forefront-PRVS: 04433051BF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(376002)(346002)(189002)(24454002)(199003)(377454003)(6116002)(36756003)(50466002)(7736002)(50226002)(305945005)(6506006)(5660300001)(53546010)(68736007)(66066001)(6916009)(101416001)(53936002)(47776003)(50986999)(76176999)(478600001)(25786009)(69596002)(229853002)(2906002)(86362001)(8746002)(8936002)(2950100002)(81166006)(97736004)(81156014)(105586002)(6246003)(93886005)(106356001)(7416002)(6666003)(8676002)(21086003)(72206003)(3846002)(9686003)(316002)(4326008)(189998001)(1076002)(16526017)(23726003)(54906003)(55016002)(33646002)(39210200001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0802MB2450;H:m750.lan;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM5PR0802MB2450;23:tYfYXSx+5wWmI/q3KToovvfFxY6s70/FsaHuSGS?= =?us-ascii?Q?6ZXNkhaOLIM3Y3vUDXA4nvuthojjc4ZSySlIqKSKUJzTOVLIIK6OoGQoyA8r?= =?us-ascii?Q?rr9+wc/8eap40LgT6rQolwys9rJRSKyWZ1vK7+qJ6W0Gxg/u1kYCHK9wlvsi?= =?us-ascii?Q?kPEXY0gfy5oSdB8xJB/ofMhmBtX9RoFRG4T/itcFlustPDOx4xan77fgUGT6?= =?us-ascii?Q?6XUIs+tNjv0LRCUeNJ2CxXPT+ZQzX2I2FMxhtlj/fmB0AZCSfdB1tbNsmeDY?= =?us-ascii?Q?YN+tuU1rnh/UcxWm/YAxUBt9QPWqARQBZNtCbxbFzdP5GPfC8iNkIqE/wstz?= =?us-ascii?Q?NFBZ/w1ECRgCmieersMap7IwfnXYw9siM7vY2z1goK0iJTEHyOE1z3QgfBYM?= =?us-ascii?Q?BSEnXr+DdHwDZ+Kb5UeeWznK8FsYfy5xyg+40L84mX4fKhoIlXGU6g3VVa2B?= =?us-ascii?Q?S1FLOoOc3RPfiH5MT3xH+zijI6umFg/ECPTiewIYexF9VYat0qsREEAdoyBJ?= =?us-ascii?Q?C/nEtBZ4P8HJVhLZgRgWpGafUqQAH0YuHGhmxfkbhWkc/5nGO7b/4NuAJrGp?= =?us-ascii?Q?BqGmjKFscu1H8PJKpI2R5bZL0rBj5vseBwFfPLspOSFXo8flF8/9ouWqzN0J?= =?us-ascii?Q?l7iggozpp1zlSQgc2NMO2AtBYK8DvPAnxHrP7z/uWjLFlttnj3E9FE+L46TQ?= =?us-ascii?Q?RwUOV0JEDdTtYh+0gvR02loSLskN39u3ZBVp9+/ZB4axe74vi8EOs4lu5nfz?= =?us-ascii?Q?uRxa323d7bZh8G6/MMlwQdf8kUOtsZ7s8GviN6Bp0DZi/hagaJaZCka34ZGh?= =?us-ascii?Q?0IwjPyvF187NOQv71k3i3LWHgXlw/DAMcq7UHP0KJcxD0XCK6Bx3lMoqeT/1?= =?us-ascii?Q?s/xt2bdzaU3x+h3CqSfNtPMBfbjIEG5ZbI8hTembaQE9NMgpGuCnpKaVRRFG?= =?us-ascii?Q?TfHRsCEl+/fOit6azu0qXM4Jp4WJN/HkBR5SJtgm4qrFIUICJNTmjgU+1wZp?= =?us-ascii?Q?s0zdZyOhAdYWB+4JjocNOqaBiHONxBJF0C9pfB+fWSQw2gdcBuL81sPW91ut?= =?us-ascii?Q?24jIAC+CyhpjqVKFBBsbt3djX2QQCt+5KuPgmH2RdeX9lcah20RQwED194z5?= =?us-ascii?Q?NJR8fr21SIwi8NUpOZu3V9TuD/ZswngbnzUI1Ax8topsAISE255x5Fb02oX+?= =?us-ascii?Q?uADoFAOhVn06TqfolNAoUnHFlZ+QLWC6R25FQTvmrwuidKHzxH1ZI2b3oXAd?= =?us-ascii?Q?FwAvbKRN4BbcW1v/viFFflah0hLI79GHlaa35oQeSMdPMAfPWRPe+ElT2Atg?= =?us-ascii?Q?Dz5+ADngTL2yG2gl+RD7MQoVYvuD5KyuVcBaOm44eUTFG?= X-Microsoft-Exchange-Diagnostics: 1;AM5PR0802MB2450;6:CJFGrT3BXAqBZNYSpp67yMw2iiiXFFvHG5fc+Nu6krdydXeFguMTBby52cvBsoHph6bQvDz8kGdtvinlD9lsrJi3C720nzpLxnt5HmuhC4xtICzekLolal8hFhBvDx1SmyOH1afxrB8YfoQvrLHFfaXMYFY8t+/bqjtkUkMb23qKSNxtzM/MekEkK9nuP3KrsjkVmXjTXxgJWl8g4f4SXlb67pXm4NAz6sHsrY+x5R2pk9C5Mcv6793l1o4QieIP4f645uEUFxIlZIF0P3/0/TH8PrpWjm0OPRe5wPmCjOcC+Mw0+ypN9gVuFWNv4oDYmIi15Ig+mw5hlP5d9W4z/A==;5:5tFY4GQqZuYJjzgYrczBzUmpwr9Wxl9dINnFS7JfdlwiEStxyN2GTXMPFQU4CrIRdEkiNNIxhQFwrq1t4axGsdLXEO9bgEpM9siV9Ggms2L5Ao9exoKJXO6wkSQl/GYnVowfnBZixL8Rx1fAfa8oDQ==;24:FOL19dXoLJjPMRlHQbI5F6G8NhJcOwnXYbf/UAriIw5SORNI8mY8z1LFR0Vz3uKVOzot55x4WW4Q4EiTWBvWO8xg0w/K3YlxpJvfiz9jgEM=;7:pxmbowWf4YZvEPFYL5F9iFvlt/IX8ZxH+1x7ZfejnYq2lQrhEz9KN8F2aM6TdtpBpxu8IK6az6KSk+8mddRRc1pihVe5HsqZRu4JwQxzviEuWMLyC8aRY+xl3decTI5Y7mVr2/QaTaEYnlGfzmkBAYIXfzvO4NVCEIiZwCwGqmkKteALbIXbMKbqkKSNuLQ3hZnPGDfTGqq4Di+I1HL+kEt8jamz3+81CtJISQQ6cbU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2017 17:18:06.8542 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2450 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 v8RHINXK004284 Content-Length: 1996 Lines: 40 On Wed, 27 Sep 2017 16:31:04 +0000 Casey Leedom wrote: > | From: Dan Williams > | Sent: Tuesday, September 26, 2017 9:10 AM > | > | On Tue, Sep 26, 2017 at 9:06 AM, Casey Leedom > wrote: | > | From: Robin Murphy > | > | Sent: Tuesday, September 26, 2017 7:22 AM > | > |... > | > ... > | > Regardless, it seems that you agree that there's an issue with > the Intel | > I/O MMU support code with regard to the legal values > which a (struct | > scatterlist) can take on? I still can't find any > documentation for this | > and, personally, I'm a bit baffled by a > Page-oriented Scatter/Gather List | > representation where [Offset, > Offset+Length) can reside outside the Page. | > | Consider the case where the page represents a huge page, then an > | offset greater than PAGE_SIZE (up to HPAGE_SIZE) makes sense. > > Okay, but whatever the underlaying Page Size is, should [Offset, > Offset+Length) completely reside within the referenced Page? I'm just > trying to understand the Invariance Conditions which are assumed by > all of the code which processes Scatter/gather Lists ... >From my experience, in general terms each scatterlist segment represents some contiguous quantity of pages, of which sg->page is the first, while sg->length and sg->offset describe the specific bounds of that segment's data. As such, the length may certainly (and frequently does) exceed PAGE_SIZE; for the offset, it's unlikely that the producer would initially construct one greater than PAGE_SIZE instead of just pointing sg->page further forward, but it seems reasonable for it to come about if some intermediate subsystem is processing an existing list in-place (as seems to be the case with crypto here). My opinion is that this may be a slightly unusual case, but I would not consider it an illegal one. I think most DMA mapping implementations would handle it whether intentionally or not. Robin.