Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp633371pxb; Tue, 5 Apr 2022 16:41:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznFmySz6FOVoCa6l5SW3vBsKLaTVPNjsiLgJI1A9ra13WAJqKaNfSYUc/TzdjnI1Ymw1za X-Received: by 2002:a17:90a:fe12:b0:1ca:b7e8:1086 with SMTP id ck18-20020a17090afe1200b001cab7e81086mr6813263pjb.213.1649202070973; Tue, 05 Apr 2022 16:41:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202070; cv=none; d=google.com; s=arc-20160816; b=HAHMB/m7xKjIuJ8AmThIwbp2Th6sXJeK7BEI5qC26xbOwzg2qxvESAfBXdUUPbJlRl g9ZvTVecN8onFyxE4OPDJ3CfJZZYaeBB8kbUgvttECVOV1fZw2lXLih8Do3WY/4fXSsz pmr/OTTA7tul5znxK1TT5l9DucY1UMtkU3+WGwf1W0WTOn99cAKa26yD0XOQVFCJn+mN SRKrLCiYa5birxzTnAb5vGtVhm91DWxDZW0gVrSCbAcON6kl2vjF8fOBZYPZeDBMpmv/ oasQpLKn1Vl/ZZ5kNRwhLHokZD1eV827b7lb4xmTLp1ZszDMdDucpqL+KHsfDgVkZJrg lICw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e19qyC51gX5dYVozN4t6VdG6IEcfDtwwvBWoSYLQlD8=; b=THLBI9SJgaRbMGGcUgThYYev4WxyBGez84Qwdink/HwTN5DYgey7QnsZEhy/3Ri8pK uH/fU7gVzizo+chnXW/2KWLMQlRn9AfswYjSkohXHJjowikXQt+jODBJ6z0o3/OMGLmh M3nJ6+5tEdO0mAY4+yFloZ9+RQWqQDKNTfCn6LO0Dhrtl7rek0R3xP86H2Hm2fchWcqv TetP5YOhIEhO6OVXROFfBksXnaTNoIzC+2XHBwMWpm/jP8P1Ab0RWyHucE/ITaAGKrP8 LyECwuOVgZ2bW3jPlbg7XSw1K3IJHecq0KvIiEpGvsPiByiqadR6dBw8VgEw99WBXyB0 jznQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B94tKboA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k65-20020a633d44000000b003821ef6f3bcsi15896129pga.365.2022.04.05.16.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:41:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B94tKboA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 089B61D192F; Tue, 5 Apr 2022 16:25:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380150AbiDEOQL (ORCPT + 99 others); Tue, 5 Apr 2022 10:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238296AbiDEJcT (ORCPT ); Tue, 5 Apr 2022 05:32:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46EE92F6; Tue, 5 Apr 2022 02:19:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0A0E9B81B14; Tue, 5 Apr 2022 09:19:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69995C385A0; Tue, 5 Apr 2022 09:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150356; bh=DpptYNvzmaQips2U1GttCoBegXwuOEZ0c9LRe8FGdjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B94tKboAlKFLT5NCWJSCqe6kFOj1RX3VSiyEZn4Hkc926WHsn8PsewLC3O/Wc7xah l4PVzuzaCjpBj5g7fz7A1xGmLEv7LmcqtqysRcRXD3PzoFQLIlMFV8yyyZSU8wn0RJ jkBuWM0f/bXX57ACPtvGSDTnIjyEj6ULcTgRgQbY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunfei Wang , Robin Murphy , Miles Chen , Joerg Roedel Subject: [PATCH 5.15 028/913] iommu/iova: Improve 32-bit free space estimate Date: Tue, 5 Apr 2022 09:18:10 +0200 Message-Id: <20220405070340.659782345@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy commit 5b61343b50590fb04a3f6be2cdc4868091757262 upstream. For various reasons based on the allocator behaviour and typical use-cases at the time, when the max32_alloc_size optimisation was introduced it seemed reasonable to couple the reset of the tracked size to the update of cached32_node upon freeing a relevant IOVA. However, since subsequent optimisations focused on helping genuine 32-bit devices make best use of even more limited address spaces, it is now a lot more likely for cached32_node to be anywhere in a "full" 32-bit address space, and as such more likely for space to become available from IOVAs below that node being freed. At this point, the short-cut in __cached_rbnode_delete_update() really doesn't hold up any more, and we need to fix the logic to reliably provide the expected behaviour. We still want cached32_node to only move upwards, but we should reset the allocation size if *any* 32-bit space has become available. Reported-by: Yunfei Wang Signed-off-by: Robin Murphy Reviewed-by: Miles Chen Link: https://lore.kernel.org/r/033815732d83ca73b13c11485ac39336f15c3b40.1646318408.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel Cc: Miles Chen Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/iova.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -154,10 +154,11 @@ __cached_rbnode_delete_update(struct iov cached_iova = to_iova(iovad->cached32_node); if (free == cached_iova || (free->pfn_hi < iovad->dma_32bit_pfn && - free->pfn_lo >= cached_iova->pfn_lo)) { + free->pfn_lo >= cached_iova->pfn_lo)) iovad->cached32_node = rb_next(&free->node); + + if (free->pfn_lo < iovad->dma_32bit_pfn) iovad->max32_alloc_size = iovad->dma_32bit_pfn; - } cached_iova = to_iova(iovad->cached_node); if (free->pfn_lo >= cached_iova->pfn_lo)