From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 040AAC433FE for ; Tue, 1 Mar 2022 23:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237474AbiCAXaw (ORCPT ); Tue, 1 Mar 2022 18:30:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232607AbiCAXas (ORCPT ); Tue, 1 Mar 2022 18:30:48 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 783375B3D9; Tue, 1 Mar 2022 15:30:02 -0800 (PST) X-UUID: bbcaa81436984a8397dd5bbe6dff26f7-20220302 X-UUID: bbcaa81436984a8397dd5bbe6dff26f7-20220302 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 118112189; Wed, 02 Mar 2022 07:29:55 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Wed, 2 Mar 2022 07:29:53 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Mar 2022 07:29:53 +0800 From: Miles Chen To: CC: , , , , , , , , , , Subject: Re: [PATCH v2] iommu/iova: Reset max32_alloc_size after cleaning Date: Wed, 2 Mar 2022 07:29:53 +0800 Message-ID: <20220301232953.17331-1-miles.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yunfei, >> Since __alloc_and_insert_iova_range fail will set the current alloc >> iova size to max32_alloc_size (iovad->max32_alloc_size = size), >> when the retry is executed into the __alloc_and_insert_iova_range >> function, the retry action will be blocked by the check condition >> (size >= iovad->max32_alloc_size) and goto iova32_full directly, >> causes the action of retry regular alloc iova in >> __alloc_and_insert_iova_range to not actually be executed. >> >> Based on the above, so need reset max32_alloc_size before retry alloc >> iova when alloc iova fail, that is set the initial dma_32bit_pfn value >> of iovad to max32_alloc_size, so that the action of retry alloc iova >> in __alloc_and_insert_iova_range can be executed. > > Have you observed this making any difference in practice? > > Given that both free_cpu_cached_iovas() and free_global_cached_iovas() > call iova_magazine_free_pfns(), which calls remove_iova(), which calls > __cached_rbnode_delete_update(), I'm thinking no... > > Robin. > Like Robin pointed out, if some cached iovas are freed by free_global_cached_iovas()/free_cpu_cached_iovas(), the max32_alloc_size should be reset to iovad->dma_32bit_pfn. If no cached iova is freed, resetting max32_alloc_size before the retry allocation only give us a retry. Is it possible that other users free their iovas during the additional retry? alloc_iova_fast() retry: alloc_iova() // failed, iovad->max32_alloc_size = size free_cpu_cached_iovas() iova_magazine_free_pfns() remove_iova() __cached_rbnode_delete_update() iovad->max32_alloc_size = iovad->dma_32bit_pfn // reset free_global_cached_iovas() iova_magazine_free_pfns() remove_iova() __cached_rbnode_delete_update() iovad->max32_alloc_size = iovad->dma_32bit_pfn // reset goto retry; thanks, Miles