Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp524230img; Mon, 18 Mar 2019 08:21:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGf9j5cxxik9Y9Cmf0ZXLUfhnrGo6vMXXdQ0FbzZq09VgK1CkREyQxLncfqLXUyzmkiDMl X-Received: by 2002:a63:6f49:: with SMTP id k70mr18454686pgc.132.1552922475114; Mon, 18 Mar 2019 08:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552922475; cv=none; d=google.com; s=arc-20160816; b=G+i/xwd1hhsydqahkc3W9XpoIUtI3jHH19UoWQPk5ntbkMqgxsauzFmQZLtrVZXpMU 1bFXchCUNo14X9PbnqshXykWxXCH9C3q3XxVHXePU0BUp0ixUYeCanfxihriTTD0LAw7 XDEb154SIL/pd2lMHQdexieIi7mdE8daUMHZUx6VKDFzayZ+Q/EAp7PYVDNRws+1LSEC f4uJ/LaV3ggbItFf+1C+L2+2ChAacmPSmH4WY4QJsqZ1ZI0aKJ7zL4+CyiCWjYHqbZWH OyobRKSUWu2f3vt2B1HHqEwbCB/dxd/SKO7ZElMOTbqZVC98mVxNyXHZEfuCWGXfAgyG bWqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=+JWgyga+6eRiKAvlohtMUtIF6FXve3e3KYbxxO4l5yA=; b=JDEqHkC+Ev1OZ43/oYkwojtvINZBvh7umCrxvZEr1TRXNK6oCGa0JNqmjNw1bZKsBV DoP3SHu42Nn04uvc/lwWupw4RBACLoebOKEbWURUaUlrFvPDZC9qh7bvxmnntN1hNVnS SgH1+k7qvgg1mgDFwg7VDq21gtrKTx6dLkcOR1P8BJu+mQ/FWeF7cAIod7EY9x/1XsNg YsfhlwXkp0ThcK3gCbzrVJC5XmPtEdhsKhwkj3dfsleZjFWMkzu2Nu95l9hmH99WHTy5 QJ9+oBw5HpN0hw9fxbt+YmVuR9pWeOD5RSPXtIfjdq5XWMi0nwat4ez1xFhvbxvaGr7J i5yg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r33si9208898pgm.248.2019.03.18.08.20.58; Mon, 18 Mar 2019 08:21:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727378AbfCRPT1 (ORCPT + 99 others); Mon, 18 Mar 2019 11:19:27 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36168 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbfCRPT0 (ORCPT ); Mon, 18 Mar 2019 11:19:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DDFEF1650; Mon, 18 Mar 2019 08:19:25 -0700 (PDT) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ED8A03F59C; Mon, 18 Mar 2019 08:19:24 -0700 (PDT) Subject: Re: [PATCH] iommu/iova: Fix tracking of recently failed iova address size To: Robert Richter , Joerg Roedel Cc: Ganapatrao Kulkarni , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" References: <20190315155553.11857-1-rrichter@marvell.com> From: Robin Murphy Message-ID: <7515342b-f4b2-9406-5249-93ae7880835a@arm.com> Date: Mon, 18 Mar 2019 15:19:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190315155553.11857-1-rrichter@marvell.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/03/2019 15:56, Robert Richter wrote: > We track the smallest size that failed for a 32 bit allocation. The > Size decreases only and if we actually walked the tree and noticed an > allocation failure. Current code is broken and wrongly updates the > size value even if we did not try an allocation. This leads to > increased size values and we might go the slow path again even if we > have seen a failure before for the same or a smaller size. That description wasn't too clear (since it rather contradicts itself by starting off with "XYZ happens" when the whole point is that XYZ doesn't actually happen properly), but having gone and looked at the code in context I think I understand it now - specifically, it's that the early-exit path for detecting that a 32-bit allocation request is too big to possibly succeed should never have gone via the route which assigns to max32_alloc_size. In that respect, the diff looks correct, so modulo possibly tweaking the commit message, Reviewed-by: Robin Murphy Thanks, Robin. > Cc: # 4.20+ > Fixes: bee60e94a1e2 ("iommu/iova: Optimise attempts to allocate iova from 32bit address range") > Signed-off-by: Robert Richter > --- > drivers/iommu/iova.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index f8d3ba247523..2de8122e218f 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -207,8 +207,10 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > curr_iova = rb_entry(curr, struct iova, node); > } while (curr && new_pfn <= curr_iova->pfn_hi); > > - if (limit_pfn < size || new_pfn < iovad->start_pfn) > + if (limit_pfn < size || new_pfn < iovad->start_pfn) { > + iovad->max32_alloc_size = size; > goto iova32_full; > + } > > /* pfn_lo will point to size aligned address if size_aligned is set */ > new->pfn_lo = new_pfn; > @@ -222,7 +224,6 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > return 0; > > iova32_full: > - iovad->max32_alloc_size = size; > spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); > return -ENOMEM; > } >