Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751529AbdITIwg (ORCPT ); Wed, 20 Sep 2017 04:52:36 -0400 Received: from mail-co1nam03on0069.outbound.protection.outlook.com ([104.47.40.69]:62123 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751095AbdITIwd (ORCPT ); Wed, 20 Sep 2017 04:52:33 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tomasz.Nowicki@cavium.com; From: Tomasz Nowicki To: joro@8bytes.org, robin.murphy@arm.com, will.deacon@arm.com Cc: nwatters@codeaurora.org, lorenzo.pieralisi@arm.com, Jayachandran.Nair@cavium.com, Ganapatrao.Kulkarni@cavium.com, ard.biesheuvel@linaro.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, Tomasz Nowicki Subject: [PATCH V2 0/1] Optimise IOVA allocations for PCI devices Date: Wed, 20 Sep 2017 10:52:01 +0200 Message-Id: <1505897522-9237-1-git-send-email-tomasz.nowicki@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [31.172.191.173] X-ClientProxiedBy: VI1PR0101CA0084.eurprd01.prod.exchangelabs.com (2603:10a6:800:1f::52) To SN4PR0701MB3661.namprd07.prod.outlook.com (2603:10b6:803:4d::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9f322a55-7e8b-4c85-37a7-08d50004eda8 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN4PR0701MB3661; X-Microsoft-Exchange-Diagnostics: 1;SN4PR0701MB3661;3:V2dikwwUjh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CqSP/5icCdN4r8P9h/qnuh7kR3g5hiF7RAKubrY8LBPz34AWg30ks5Rrzf0c/EU5GrlIWh/4QY1pOAbRZTgKmTQeooRwgjS49Llm45EFrL5WJsGlxh1/VDcO2X7TlsW8Z/OxiCpSNJ++f2In/oXObPUouAIC0Vh+tId5Ms+AeL0sU+ofPojGd0iG/ZTKZbhj8pPuo/767AokkX9EHB2tuPoo5TbTUQkWZOF+aJux4Su8VJs0UUQSKYXjsc5HrC3o20S4vCV0UgwO4IpHtphTAL4W4XW7pOXiRzzn6p9GrYMy95HL2UdBHRNp/BvoY52/9F2VvHWkwSOcZyJoTB1mqajUkPrH6IDjZOm4WJrTSlXHwKJxHdHq6ky7zIPKQi+MNu8QEZAcDikuiSx+Tubl+oKXIm25DVgPKciXd8igkS+D3AX2h1syAzJeXiPFiRU=;4:SXU2k05L6HnLGreOSmMPq7NwLoW4h7y+ZfiZ1kHpWVEhEBY+z20lfi7gusaIj4SjrUs6VF9mNGXXZSJWeMvLb2xdfkyepOlQemREgdmL3TBONrqIfABINb8dKSqgeK0M9I8e2om1SRLyG7+ZHtkQS0FQcLFYUlDAYeB7X5ahnEqkA1IPmSB6sU/FNmwJpppTetDhVOhtXHmE5a+IahstsGJwb5AJGCaqXMq1OTlju3D+tRcHwBltTG0RZ8cF7COM 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)(100000703101)(100105400095)(10201501046)(93006095)(3002001)(6041248)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN4PR0701MB3661;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN4PR0701MB3661; X-Forefront-PRVS: 04362AC73B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(979002)(6009001)(346002)(376002)(54534003)(199003)(189002)(97736004)(6116002)(5003940100001)(3846002)(72206003)(8936002)(53936002)(6512007)(2906002)(16526017)(316002)(16586007)(36756003)(48376002)(4326008)(47776003)(66066001)(189998001)(68736007)(50466002)(107886003)(25786009)(33646002)(5660300001)(101416001)(81166006)(6486002)(81156014)(6506006)(50226002)(42882006)(8676002)(6666003)(50986999)(106356001)(105586002)(7736002)(305945005)(478600001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN4PR0701MB3661;H:desktop.semihalf.local;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN4PR0701MB3661;23:dEfQXto2Lhf4SQzdsnyN3msJhof8iuWKjf9EVkv?= =?us-ascii?Q?VJY1MNbtstYkagl0RI665iWzVl8ZKsYt9+4cPSn/zsJKqOZOcH7PDwSxocEg?= =?us-ascii?Q?wUNS9buyoTOb2MSGrBBlFIH/idQ4+NBiiQMNmFOuK3n1RvCmvutxRTvvgLKA?= =?us-ascii?Q?X71LbFAt6rcyf0g/DDPZzMT1F8aSJaArAsixtv8/PjwOCoD47J/+fyT5a6Nd?= =?us-ascii?Q?LWuPGX9Xy5kjy0tZ9hCTHKWXJEt9wqPIb6DiRiW0j/12ZpAIIbK2CfiDHUNk?= =?us-ascii?Q?HYkwoYAzlBROdud7k689suW22dRI/UPmkjViyjIymS8SuoSZ36HEebt/1i1d?= =?us-ascii?Q?qeanRqIu5juFgLF32XXjUyVHhajQelLqrkJ/Rrgp/UxWpC6/S/juqsCEzn11?= =?us-ascii?Q?8F/8tPpWfVYyH8B1uK0MA2usMkiwzELoL4HX0kWhLfNTmSyRGY0QuLXh+YEi?= =?us-ascii?Q?a7gwaFed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26qdWhsziTKxnJ9rmeX0syfDQfbRCdeE3t1Vp2MTwVDznO0n7b2rlcp4M5ZEZ0YAaA0uB/MVimdNf9x6jtFEvpVTpmwx5bwfla/FvJuk618nLg93e9q8iw4Ba2NHLJwsRwBYCo90yfiLZXcALLnsK+X/jPkXVzAWBokcp/E8AnnCEQIshzh9w==;5:VB/7nluTyHwXQjIZBErhXKtakYcMd0t88JtQZjnID2jwcDsowQhF1Jp7qJOx0OdORH7yFGM9aknua/MOopF6cVZb7OQMj002Pmdxynn2wDJWLjxqyNoRUc9nih2Si0VYvpVS75NBlwN1IxefVkaZ9A==;24:HT+atUwOtjAqdwg3Jfn0pZ4DkxYwQE569JKFv+clC4rtDXZBYCoNasQVGFtgBFLa33XDe9nCao3IrhMvgC6Zo02Rvgtu2uW4nqN4XnQQcYU=;7:ADpbdPvsSluXq+Rx7PNJMebXCYSSApHetHUKzvqT5tHUA0pdeueTkv2ePQOfZT/iQafQg5rKdqjKEFvG49yLywBFcKAnVdlOMkWzVc+4qibl8UR4g3dNmkhTz/ceLSt+vLH+8jK4CPBe9oDzHpvJiBYYKYzcH69MDmSQJKQu2ZzAUj1oSsKeiFlMf7l5YcU4Pvb0z0U6ATgYrB4Rn2OLvt3KlFXYScjiZQpmig5MsYk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2017 08:52:28.9261 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0701MB3661 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2032 Lines: 55 Here is my test setup where I have stareted performance measurements. ------------ PCIe ------------- TX ------------- PCIe ----- | ThunderX2 |------| Intel XL710 | ---> | Intel XL710 |------| X86 | | (128 cpus) | | 40GbE | | 40GbE | ----- ------------ ------------- ------------- As the reference lets take v4.13 host, SMMUv3 off and 1-thread iperf taskset to one CPU. The performance results I got: SMMU off -> 100% SMMU on -> 0,02% I followed down the DMA mapping path and found out IOVA 32-bit space full so that kernel was flushing rcaches for all CPUs in (1). For 128 CPUs, this kills the performance. Furthermore, for my case, rcaches contained PFNs > 32-bit mostly so the second round of IOVA allocation failed as well. As the consequence IOVA had to be allocated outside of 32-bit (2) from scratch since all rcaches have been flushed in (1). if (dma_limit > DMA_BIT_MASK(32) && dev_is_pci(dev)) (1)--> iova = alloc_iova_fast(iovad, iova_len, DMA_BIT_MASK(32) >> shift); if (!iova) (2)--> iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift); My fix simply introduces parameter for alloc_iova_fast() to decide whether rcache flush has to be done or not. All users follow mentioned scenario so they should let flush as the last chance to avoid time costly iteration over all CPUs. This bring my iperf performance back to 100% with SMMU on. My bad feelings regarding this solution is that machines with relatively small numbers of CPUs may get DAC addresses more frequently for PCI devices. Please let me know your thoughts. Changelog: v1 --> v2 - add missing documentation - fix typo Tomasz Nowicki (1): iommu/iova: Make rcache flush optional on IOVA allocation failure drivers/iommu/amd_iommu.c | 5 +++-- drivers/iommu/dma-iommu.c | 6 ++++-- drivers/iommu/intel-iommu.c | 5 +++-- drivers/iommu/iova.c | 11 ++++++----- include/linux/iova.h | 5 +++-- 5 files changed, 19 insertions(+), 13 deletions(-) -- 2.7.4