Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751561AbdISIEH (ORCPT ); Tue, 19 Sep 2017 04:04:07 -0400 Received: from mail-sn1nam02on0081.outbound.protection.outlook.com ([104.47.36.81]:33944 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751024AbdISIEF (ORCPT ); Tue, 19 Sep 2017 04:04:05 -0400 Subject: Re: [PATCH 1/1] iommu/iova: Make rcache flush optional on IOVA allocation failure To: 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, Nate Watterson 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: <5632227b-3d9b-0f03-db3d-2b2d7ccc8079@caviumnetworks.com> Date: Tue, 19 Sep 2017 10:03:47 +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: <250f41c9-fb37-49b7-c336-68e163f77e16@arm.com> 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: VI1PR08CA0109.eurprd08.prod.outlook.com (2603:10a6:800:d4::11) To MWHPR0701MB3658.namprd07.prod.outlook.com (2603:10b6:301:7d::39) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d05768f-4a54-4a05-ae48-08d4ff34fc03 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:MWHPR0701MB3658; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3658;3:tMwMModlgXsA0ZWx2Vn1h178wc7WG25aFdn8xcJ1ORuVY0lJtw/61xVAwuBZM1aTXTXui/T51j1li414CL1waLOh4ev6eTKIWKyFVVZBd6bhOzreKvRTeh1YWxXs9n8OLCfyiVjmji/VFP1QUQB6+aCE6U7Pa+ZJJmORKPkk74eAOXpF5oMfgLvEQOPLyyjNlwhIaXnFy+acYN35nLLixINUpZiaPIghnvVxHOxnJDVnlqFcHvukjVOZK4ycIGjR;25:FSYqJs254hoCLXVinricEu5hqPGEEaEPopMXCaOLP3LH5Iej3tVLOJQodkyRSGK/9oYGVYkRm4Oa5CQp90deRt81Z7GHi82J9iQbojCoC/kk0fdwjgvp+ejNL345tAPO270/QiGf/sgMFGfmeP0XiRGbzNXbAoJ3P+6+IUyQ8LLzG/0n8niDLfuGpfaIV7dPt7OELOo3LpklYt+NDl7LqDqPdXc4r0ZaEH1rTh3GfswWknWc2DKtcVQlm5zifYXYRdujprNTTlUNUaat98pPtaLq/qO5+iMTFr8dbK6grxRnbi5LJvfYxLGEjDx+4K5JKqbH1IgP+kcxUQtj9Wp+6w==;31:T1CH1zkk15lGsacCs8la1MWXYBmqjgQ5uEdRsx128DsAaDL59ZVjnIDCEJycwMi0PHEa1WKaOAC/Z+bgkXP88juc5tWbPtbaIvX5FuuiFuqJoMQHTic5UisjlpFpTRsEkE5052CHZ6Ziz+caR6MH2jSS774g9okWeBXfemuzm95b+8LY+4sAEJK8cw8XUyniSbLQSup71hNA2GbWNSX8j0+af+ioLiIt4nb1vJsCfbw= X-MS-TrafficTypeDiagnostic: MWHPR0701MB3658: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tomasz.Nowicki@cavium.com; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3658;20:4aHtSjBqAcLciglyRW2SbdEBNHSr4cR3HFEU41KEGa0CQpYqPZBJWQxsCPVPz0o69P8LJaZdEABz7FI2U1+UhIYq4UuzsWQSjrepmL0d5dX5G7sdjjLn4AFNPfESJZEQZvOUhc1MQtOls3hIlCwwYXD0/uBhulH+VkWbXl8lneWzthJnum6PI+sd+8gKdX6puKnmOM5Kt2Sd3d2uhC/2vNDvXJj+evd9tbRO1yU44gBlRnCesiFprKcxviDPP84NV5PmxBBg92+RHwEcksrFYhUBW5Z93txccadt5/+aKicbQMrnyDhygmlGmVQNRMzGy/m+In3L5fIri40rdJPmqyCi7EG9SR0usWp6W3GHpc/jsj80PzcgO1rlZWHgOvjv45Rb45C3XXzv9FaiiP+4Z8KH3OjmfI1FS6acbtiBEQFC8RUcAz6oV9k/fTB/l3/6EjQEkGoRcRQCCF6OofjYSbm4cikqMn/sdQvJUl8MLEmSkP/b9IPyMYMvzOc2PzrnpUBed3u87wLzZeS55hXxyhyyCzt6sgmBjVwhPhU+Kvez3tHvmCeINQFsoC5c4+A03b1zCeTlgl80a6m/IHXt+T5+lpsYRtcf3K2mq+56MdA=;4:65diqiUt57aP65y1h2CHjvl6KFr7opu8UA2Q6DLZHGrj69zuuzBZ3XkjTNhoPjXijFM/uAodefuUA3tH+27YeXaYT1+cZz/p7bOgaE0uApZdMt9gxe+fEOrWoT419s5nTJRleaK2BTrdxTUtatSaOkPWmX+aFTry8Y1gCLzONc65UyGDD4+OHLF8+GEB3IXpYgq+T/GE9tagx2LXBKogSz+rDOpKHvE1l0rW1Ymdf13IHsYN/AZQu0m9IxywSJjd4N18D9X7wlfzw/X5VbaGdfxJW4i8IDhbhqzXTEMkdOw= X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); 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)(93006095)(100000703101)(100105400095)(3002001)(10201501046)(6041248)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123558100)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR0701MB3658;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR0701MB3658; X-Forefront-PRVS: 04359FAD81 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6049001)(376002)(346002)(189002)(24454002)(199003)(42882006)(16526017)(31696002)(230700001)(81156014)(25786009)(2950100002)(64126003)(6666003)(81166006)(53936002)(6116002)(3846002)(8936002)(53546010)(31686004)(72206003)(33646002)(478600001)(6246003)(105586002)(16576012)(8676002)(189998001)(68736007)(229853002)(54356999)(106356001)(110136005)(65956001)(66066001)(47776003)(76176999)(50986999)(316002)(36756003)(23676002)(4326008)(77096006)(6486002)(101416001)(97736004)(305945005)(58126008)(50466002)(7736002)(2906002)(83506001)(5660300001);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR0701MB3658;H:[10.0.0.85];FPR:;SPF:None;PTR:InfoNoRecords;MX:3;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjA3MDFNQjM2NTg7MjM6ZFdLUjFKQmlOYUxQaTBsa0R6NXZCOEpG?= =?utf-8?B?QXRWWjNlcC9hWEdIL1grTi84dURobE1pVnpMeFdCeTJBZE5aRDZqakNMTVF0?= =?utf-8?B?bXlueFZaMDhpOVpwMGhyOGhnZHpHV0ZQc0xrZm9SN2V5bVk2d2NSaG5qWTdJ?= =?utf-8?B?QllONDRldXpSWHBpdGdYbHpRT2FGM0RJdXhWbHYzWGYvSlpDbm51blZ3QUY3?= =?utf-8?B?eVl2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VV0bFMVr8NB74RAJnpwNplwwpH42pc5L6xQ0eaiQ5XdT80l4f7T1Ps4cDznUvAzB9d2ad0WB+pbFhg==;5:C1T13VCzvctnlYX2mTFHyDJ39RmVw9jjSb8zqd987FgVKfzigG8GxdSPm4h+JTD+M7pebu+TLgM1WQRNT4H0izbiUXWh5afNIwE5OeMBHCwndQRPDTS4eKnrN6wj06c4NjrF11xiJisLKpRxF8VInQ==;24:LP70P0vVbbs68PkY4B4obSCC32N9k3GjUwt/VqEnVBfz1vB17EF7AEdG6TK9KIVRv79sV6XYY80hoMAfgqwutbd6QHbnpZsslas+NCRRbYI=;7:/tyuVmmSxCw0j6tRGWoWv1RJ1Kih8oMOvyx07NraHBQG8MSD95QxHfCUqZ7flF8CPTPh1qpSeINRiN+rLGsmMAd1kOz8jUWl6vEjNuVy4xDBI2uyNT32rL3Dhl6ZPy5zI3TN0yf//qxqEiqmCWRhxsqc/k1PE1teGFbHVgEDObEQEhqEQ0c+oOo3yLfsQSKNLRy5AxMOgNx2INlxwpurvmN+x+4d4VcNNjbpVdyWJeY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2017 08:03:57.1782 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0701MB3658 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2050 Lines: 47 Hi Robin, On 18.09.2017 18:02, 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. >> - 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! I will add missing comment. Tomasz