Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1708359ybk; Thu, 21 May 2020 13:18:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCfXeDCDpUfYXxndSVQqNSN76bO/S8xPoYkxUeJzFKNF2jhOkJiv1tIq12ydlV3Oz+hX34 X-Received: by 2002:a17:906:858b:: with SMTP id v11mr5046154ejx.348.1590092316196; Thu, 21 May 2020 13:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590092316; cv=none; d=google.com; s=arc-20160816; b=wiMjJopeJC/Vhydq3Px+YIC+lauzb8ZR9Zo/L4KqnK9b8RiRF0S+IpwbTQFPMKXuRl Xg/w1BhKffgaBaarzM2a60vDNpRXeWYm3vxiZcdhzkvB67MmKZWiSF694L8qaP96SO/e +yCvbOtZSCK1TnUucVP0AH1n29PUNkDTplE6iCzHfdsZeOV7JFPC2fXt782qa0XWJtt9 P3DyN9QrPAa91xQ7QqM3zOevSYxsfIb0lK/tQjaYu3/M5njnKEYCHuPEKUp2lQcRGL/f 9Mpp/IPN3KR9C1eJKGGbcGdDSrG4GCDY2TPwUFtquSOpmSYzYyRdE9Zha6q6ZPjNR3uf oAZA== 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=zoEKDHAOLrGnifSzSfeBvL4IrtprARdS9hU3Xs8ekkU=; b=a2FKi9rNcXdiCtE3RfoJOKEXaW3bmqfexB92yyh6l0Nw6vwLTF+ij5tIEIBjE6MYRO Qs7xLWJhOvv7x7B+YlJAz2iVEpItazPaIV2Q3TV3dQ41kAXJ/QVKqxnn8E32DALdscKW uOR1m3V8Ccvc4p8WrhI/10ePZN6OhQ667tBKs7XjqpUMLlD5RtmJ2fFcVFALHwLcdQeO yhoHAUFyb/OnDRlzOGe+OVLFb4rooGuOF2ErN3mmQojqO/tsjjimRwX+z4o1B9sJSnC6 54LBVZMDqWnZblct5+wyao+Qoe9ACqwkH6h+ou4Wp7mWzuli9KwqhwOn7ZL49neWHqfi q1Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m21si3756224edb.534.2020.05.21.13.18.09; Thu, 21 May 2020 13:18:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728517AbgEUUQd (ORCPT + 99 others); Thu, 21 May 2020 16:16:33 -0400 Received: from foss.arm.com ([217.140.110.172]:52854 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgEUUQd (ORCPT ); Thu, 21 May 2020 16:16:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 99CC130E; Thu, 21 May 2020 13:16:32 -0700 (PDT) Received: from [10.57.0.164] (unknown [10.57.0.164]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 880AF3F305; Thu, 21 May 2020 13:16:31 -0700 (PDT) Subject: Re: [PATCH] iommu/dma: limit iova free size to unmmaped iova To: Prakash Gupta , akpm@linux-foundation.org, mhocko@suse.com, joro@8bytes.org Cc: linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20200521113004.12438-1-guptap@codeaurora.org> From: Robin Murphy Message-ID: <7aaa8dcc-6a47-f256-431d-2a1b034b4076@arm.com> Date: Thu, 21 May 2020 21:16:30 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200521113004.12438-1-guptap@codeaurora.org> 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 2020-05-21 12:30, Prakash Gupta wrote: > Limit the iova size while freeing based on unmapped size. In absence of > this even with unmap failure, invalid iova is pushed to iova rcache and > subsequently can cause panic while rcache magazine is freed. Can you elaborate on that panic? > Signed-off-by: Prakash Gupta > > :100644 100644 4959f5df21bd 098f7d377e04 M drivers/iommu/dma-iommu.c > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 4959f5df21bd..098f7d377e04 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -472,7 +472,8 @@ static void __iommu_dma_unmap(struct device *dev, dma_addr_t dma_addr, > > if (!cookie->fq_domain) > iommu_tlb_sync(domain, &iotlb_gather); > - iommu_dma_free_iova(cookie, dma_addr, size); > + if (unmapped) > + iommu_dma_free_iova(cookie, dma_addr, unmapped); Frankly, if any part of the unmap fails then things have gone catastrophically wrong already, but either way this isn't right. The IOVA API doesn't support partial freeing - an IOVA *must* be freed with its original size, or not freed at all, otherwise it will corrupt the state of the rcaches and risk a cascade of further misbehaviour for future callers. TBH my gut feeling here is that you're really just trying to treat a symptom of another bug elsewhere, namely some driver calling dma_unmap_* or dma_free_* with the wrong address or size in the first place. Robin. > } > > static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, >