Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp680120pxb; Tue, 5 Apr 2022 18:30:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbczrnwg7sJa2RKn/Y0QnG5ADoeI1srWbc8Z2OmQtKZW8APmRMiPg8EXSIX5sr8joPB9M5 X-Received: by 2002:a17:902:f64c:b0:156:4349:7e9b with SMTP id m12-20020a170902f64c00b0015643497e9bmr6166498plg.139.1649208609849; Tue, 05 Apr 2022 18:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649208609; cv=none; d=google.com; s=arc-20160816; b=iCS9rVHC+lv3hhA8znNs88oLccLhrU72A+Ah6hbOeCHOcI3pbfaLllZOwgAxqZeSl5 YfjG+yU46eSXbrPvkBy2Ufb0RyAcptTJT8VTSYH11gh34pt402U77/8XW2ClrCmu+KZ0 BLRkz9hi1nw4Ggx1nC7X4yORIaTAJi7YYYfYSPuzenKo1GidUmT9W5Kxsgl9t1s3J/wv 1yVSEoEvMsvOCElKE5ltNZr6pWpmEEnwnN3tuvuLo45+NA4E3CtMQL++9dqJlN09jsW+ ucrzYk+BWxEpxRIwJCfLz2GDzhlmhXYQEi0oCajWdw15mGF5W1E7vLmb3uN94Mhhv2Yg Q1zg== 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=1OTdRCBZUiKRf/i5VfzUNgPgA2JClUOF7dxsl6wvqmA=; b=q81bXUjxPytWBrm/qpV3qHTbXG6WPob3R+oyM5YyWihAKz//wp6TH8pcdb3SNpGd2S PSpOF6BgHcesYOjEoEFQ+hGo4XBvGIgexpOX88ImE4K9+iHH5uU+yJZ0BD9/QNpgV83y 3xIgMDy9l0ZNo7qChHaN6cgT9ujuSEA7P2I2OCOHlZykVwb7pJV/ViufEsXNHrWsqCRt XpRFtZ4tcsP+XIqJ/Fw9GEqXy2UvItRTjssz9jDdenXKhZujV4jumpRunmCUWYPRd0Uf t4M6YHQspkZE3XSa9TZL1krCy09FgymFodxgx6byBMU0jFxsoaDoyMRBxk1E8AQCbEd7 yGDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eVhNGOQo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j16-20020a056a00235000b004fa7630aa94si14680263pfj.126.2022.04.05.18.29.53; Tue, 05 Apr 2022 18:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eVhNGOQo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231714AbiDEHlC (ORCPT + 99 others); Tue, 5 Apr 2022 03:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231398AbiDEHk6 (ORCPT ); Tue, 5 Apr 2022 03:40:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE3315811; Tue, 5 Apr 2022 00:39:01 -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 C4C46B81B16; Tue, 5 Apr 2022 07:38:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C8D2C340EE; Tue, 5 Apr 2022 07:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144338; bh=/wvZ5ttyt/Itqm3u0TEWzjsazWNXuAryuErqxEh3zXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eVhNGOQoToK9ceABS6CkBID6xDDEmS0K9r7TMhH9n/fFS5DIDDCFbaTb1N4CbwosO q6DM5G7fLI+uPEPb8w0ssliYuHb880Lge1pcAfiBNPDdEqbwlFfyh26hi1u37lT/4b QO1vmCB8pzZrPMa1xhbeVh5jYp9jonu9EwK5e0eo= 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.17 0010/1126] iommu/iova: Improve 32-bit free space estimate Date: Tue, 5 Apr 2022 09:12:37 +0200 Message-Id: <20220405070407.840025181@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 @@ -95,10 +95,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)