Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751671AbdISIKp (ORCPT ); Tue, 19 Sep 2017 04:10:45 -0400 Received: from mail-dm3nam03on0073.outbound.protection.outlook.com ([104.47.41.73]:2513 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751589AbdISIKm (ORCPT ); Tue, 19 Sep 2017 04:10:42 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tomasz.Nowicki@cavium.com; Subject: Re: [PATCH 1/1] iommu/iova: Make rcache flush optional on IOVA allocation failure To: Nate Watterson , Robin Murphy , Tomasz Nowicki , joro@8bytes.org, will.deacon@arm.com Cc: 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 References: <1505732214-9052-1-git-send-email-tomasz.nowicki@caviumnetworks.com> <1505732214-9052-2-git-send-email-tomasz.nowicki@caviumnetworks.com> <250f41c9-fb37-49b7-c336-68e163f77e16@arm.com> From: Tomasz Nowicki Message-ID: <03297a05-8490-a86d-12ab-a99cf73c09ba@caviumnetworks.com> Date: Tue, 19 Sep 2017 10:10:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Originating-IP: [31.172.191.173] X-ClientProxiedBy: VI1PR08CA0132.eurprd08.prod.outlook.com (2603:10a6:800:d4::34) To MWHPR0701MB3659.namprd07.prod.outlook.com (2603:10b6:301:7e::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72118d64-8b69-4ed7-e40c-08d4ff35ea3b X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:MWHPR0701MB3659; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3659;3:lHnIk/CgixOjEP9QoJx5oHYquV3/4uaOebtLt6cCOg7FNDkZ2qA6KURFCSQmifSZSlPtD9UfIQGCFDL3koM34T7K3kb1lyq/2bLJAu4BX58NVrMZsTxwQGuqGZSE8Ue+hwfV797aFACpj4Itrr7reqGyYsIheEVt0xFG2zR38kmB7qS6zSHBZa2NhdaAkgkppLtGgOneSfpKI8DHIptEB1TWefG05UKw2Ewvb6JWXR2Z5uZ2RdB1YObQ3AKTKDTF;25:ufIir3LgpmnCnDTrWtRwafmeDj9SUeyXl/ZXRrIATr1BrBIMmDNVQsXqGX5p2AyB/9BLE24BH6mo1QvvtBSfuN0ZZ5St+JyV3Eb2B6JYImyvoZrt4+18YIaNUUkDWvlqxvAo6Pt6XeBCzqU8f9PHvGdd+//+bjEF5v2BHz5ZhiX8wCUCHtLk2Lnho+UqY4+zih9oYnejTfg+sjN9DnJ1GrxZQO0zq1Qt+hmH7/jzTCQ2AH72JvQL8Lj21/iysLQrxhSgjxcZ76MXKsP5T1krDSpb7ykXr+FSZjPdNmEqYna75Dt0T1wi3TGbqdCxZFkBUho57vFOO70gCuB4JjaXiA==;31:qIpbUZX1tpHNE8uwGtmVUO/h7Jga1JpB0asAcZPrtzkAD6AJLCNasvUYy1kSFrlnYnvpkg7blnE58BPlLETH3xg/8KOdIj4G6ZYWPa4QfgmIZLpzv9jkKMvfVrqTdOKbBFddjhJ/cv+DJV7xH9VXTEpkPAftzFywlv3X0ROSU6kcnhM1ZgN5e9ryUzTQrcHwlloN2xQI9ymQXqFo0K2TZVqs9m8WIXmgA7erbMUeXgM= X-MS-TrafficTypeDiagnostic: MWHPR0701MB3659: X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3659;20:jzYmIqyApBK8dK1hU91VKRJtCY+ZzHf+hTjAM1cCJ1iPpLZFDwBpcteBHDrziQTgYG2CWXatxlAOmgxscewDPWr57Vg3fPW00bYXzrTXjXBztwfmcljT3EGWVtX6KJjc1UiAqv54be38khzEYwY9uTyqRywTX9pXplzYWcqL98u4ddTyC3g5G7G/Kd9ddQB+ny7yYACNZfbadHtcIvdMuhWaddv/wiKZKJQ6ZlB9dKa2dzaVwMPEzeGKmRhvlSdR67h4g1o4kLMI4yBbjBdlw9kuPqXH7ULLA43np117W8eTFmTFLUsQODHOei5HgtaTqRsbM5qxFtHvM+xGiv5o/HEPcg7v0W5HNQwuwBEsF7vuM4k8mzPWXNuEdwAN17d71LGcwZVlooIZuBxqp5h2+cjuPmc6cYKbQp9dR/LDzAvYWJzrbrND4hrN6/duQ7kBikzVCcbAer43cJp6jmiunPQWUIdzDWTPAziwPApxoXM8uQ1h2MY1a4GWvU+U8l2jzQpqc72A/I5w6XWw1X1N1rPeWJ/jVgKYCF55/9BqbngHFEKc857iq04DvyE5OtkYBKcq3K4p95//WtHYsbC4cfCH8Eq1HtNj1LWHrEEtGiM= X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(278021516957215); 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)(6041248)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123564025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR0701MB3659;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR0701MB3659; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3659;4:asC+NUa4jUopema8vRFAuWrB9WlmFZ7pNvxs9DpQSnhVs/QeBHgDyo6kHchRXAvhlOGJsCostxW89Er0jA99iq8Iq0IBc75euaeiTmKzasqpPGAthPFj6jznszmgaszXjNyryogP5Nw4guK3+RtBD0bQGbGzqAoaXjdImsS42O1xcjtSkiLTEceN5oxEJ1Hy+ayjySRJWXdB9qYSfljj1/jbD/h+tvSAvWHKxyhHq3LfVik1leb+x9n+dAu6vuvPE7uRUN0NeLvgT4NHceA8NXQu33TtkvoVUUoSAqxFVL+nS+kpUtUlQom/XrVgmp3oJIZ3jh6W5mos3MWjkOYTFQ== X-Forefront-PRVS: 04359FAD81 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6049001)(346002)(376002)(24454002)(199003)(52314003)(377454003)(189002)(16576012)(16526017)(72206003)(53546010)(8676002)(97736004)(23676002)(81166006)(81156014)(189998001)(36756003)(8936002)(110136005)(58126008)(478600001)(77096006)(6486002)(64126003)(305945005)(53936002)(50466002)(93886005)(83506001)(76176999)(50986999)(31686004)(2906002)(33646002)(6306002)(7736002)(5660300001)(68736007)(31696002)(66066001)(65956001)(6116002)(3846002)(2950100002)(4326008)(316002)(229853002)(42882006)(6246003)(101416001)(6666003)(106356001)(230700001)(25786009)(105586002)(47776003)(54356999);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR0701MB3659;H:[10.0.0.85];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjA3MDFNQjM2NTk7MjM6eFc5UEwzSjhndVVpTVdzL25ZVGpvdXpX?= =?utf-8?B?M1JUdzZ4THN1M05rVnQwbC9PYUZNMHA0UjZmQ1IxcVA4b0F1U25KTytsejgx?= =?utf-8?B?RzFNcllhWGlCYkZGL2NBMzcxY3dXTjBOQlNUdVJwNW9TOGsrRE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6lFcdfinc1NMKsqSYOoZJ7587+N7uprBuOxRNjr2LFSAdVe97/jeZkRx7bXnvV0tRoX8utXxlIuI/BASyDAfJIBnETq93D5KCyxlZteHXgvpWcdC/m7xIlqP8pa59d8mMy54msGw9jsN7uQxdKqOaBECbPdveAryKxSqLlswtOO4FynAkrDbQ+bpxgzTSPoqjWA/7kD8wurpMq33f/QoNrAmm3f0o0leFqF9yLzICvl3bRhdvqzrhE7ySSndw9H7SYaz+uVfx9M0e23AcHIc4WczYnpA+HHtYZA36A5Q==;5:n2yV2ZhdqEpQ++xYmx4ZIB2PfK5g5/VLcrHLDfHt2B8dBreGqu9teKrnJ+/CYVe+V1WjMob88TyfMUZSBQfY/lXUpYbQeRdWGbrjZLFBE4SUWL50+AnK0FZeO9oOnis0YDmBEiCoOqA4BSA+514ixA==;24:49NmGAxUDX4U+BHPK14cqdQl2NpKIAlQ9KQ//lA05lpuCSxd6bK4K/li5v3KgzBrixzlH5/sLTXTMBcPOcqskX3VDiRWi0iRMHnNRYDu9vI=;7:zEQqTMfp1MZQQ6yHePWOnKXggbJVAN2W6tC7W42dihkxBXJhyISmZI41CAvsLAgbt0Xym8Z7GCCj1ik5DswP1RLzQPKJejxYpzQvBqoc5UEShVn0sG/hNR1s1P738pIdF2zF3xMI2bupjt7tnkcJgJZg5BguPI4iZIE0jK8TOdc8W2DfCtde/TZjHw0lD9zsoaSfbPo5Fz7dL5FBbNq7oLGQpIBM4d4jm4+S82vD35M= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2017 08:10:36.8444 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0701MB3659 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2516 Lines: 72 Hi Nate, On 19.09.2017 04:57, Nate Watterson wrote: > Hi Tomasz, > > On 9/18/2017 12:02 PM, Robin Murphy wrote: >> Hi Tomasz, >> >> On 18/09/17 11:56, Tomasz Nowicki wrote: >>> Since IOVA allocation failure is not unusual case we need to flush >>> CPUs' rcache in hope we will succeed in next round. >>> >>> However, it is useful to decide whether we need rcache flush step >>> because >>> of two reasons: >>> - Not scalability. On large system with ~100 CPUs iterating and flushing >>> rcache for each CPU becomes serious bottleneck so we may want to >>> deffer it. > s/deffer/defer > >>> - free_cpu_cached_iovas() does not care about max PFN we are >>> interested in. >>> Thus we may flush our rcaches and still get no new IOVA like in the >>> commonly used scenario: >>> >>> if (dma_limit > DMA_BIT_MASK(32) && dev_is_pci(dev)) >>> iova = alloc_iova_fast(iovad, iova_len, DMA_BIT_MASK(32) >> >>> shift); >>> >>> if (!iova) >>> iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift); >>> >>> 1. First alloc_iova_fast() call is limited to DMA_BIT_MASK(32) to >>> get >>> PCI devices a SAC address >>> 2. alloc_iova() fails due to full 32-bit space >>> 3. rcaches contain PFNs out of 32-bit space so >>> free_cpu_cached_iovas() >>> throws entries away for nothing and alloc_iova() fails again >>> 4. Next alloc_iova_fast() call cannot take advantage of rcache >>> since we >>> have just defeated caches. In this case we pick the slowest >>> option >>> to proceed. >>> >>> This patch reworks flushed_rcache local flag to be additional function >>> argument instead and control rcache flush step. Also, it updates all >>> users >>> to do the flush as the last chance. >> >> Looks like you've run into the same thing Nate found[1] - I came up with >> almost the exact same patch, only with separate alloc_iova_fast() and >> alloc_iova_fast_noretry() wrapper functions, but on reflection, just >> exposing the bool to callers is probably simpler. One nit, can you >> document it in the kerneldoc comment too? With that: >> >> Reviewed-by: Robin Murphy >> >> Thanks, >> Robin. >> >> [1]:https://www.mail-archive.com/iommu@lists.linux-foundation.org/msg19758.html >> > This patch completely resolves the issue I reported in [1]!! I somehow missed your observations in [1] :/ Anyway, it's great it fixes performance for you too. > Tested-by: Nate Watterson Thanks! Tomasz