Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp594892pxu; Fri, 23 Oct 2020 08:37:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUNwI0Mv5+fPFMjOfZbTZSnKgexTeGtR0lcuf05TV4q1igOLg3a2qiedYZHJze3OMvXY0O X-Received: by 2002:a17:906:f90a:: with SMTP id lc10mr2615765ejb.272.1603467453246; Fri, 23 Oct 2020 08:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603467453; cv=none; d=google.com; s=arc-20160816; b=lg4h7705P2S6e+mayffIvP+xHFhCVWdObzvkVwM63L/f+Dhq1Km2Ro/zpU+QBNblhu DbKZcWezVCyGOP8uOalvOvsbYSV7qbklsB9+8xQ9lD4N0bkLBd3XfVIwJQNCmzqbHz+A g8C9CIJfgizPKKreCTUGOjssD2QTXBQ5yFgTqo/IwPge+yUhwOGmCJSeaODYMECjByrX 75V1Nd2NQ5egjqjtUveVfXfcyVuwVMFRDM4i1E4NQIwMb52LSmhw1Aw7hADQA0/KcHOQ 6Xe+ZWgJNzjBd3GEyx7vFWXl7W1+05sr8iLXAOA0MNn1wwolHy9sZ0rsEfz9nwZL02vh H0AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=p5BydNFBY8pGvZf9rRLVFMcdKSAY7LZJO9KPlwGcheA=; b=Tx+qSJzKZ0HXySXiDVUO17mKk2K/u6nrknNatkXP+IlHKVs21f37tXFA7QUYkVbGQG e0iV8QFMgKrukQCKvLHrZT3aVyUzivdfLqUJZ95uwOgXKOf907fL4U0VGfhZ1rEGDUHn jv2g3drHml2Qti52pEZ1TVMgMEQuNPsOyNxFe2BP23MjRoBYHXN3pMQpCEIXP3EKF+nh v6pzY8oVrqr35uTdozN3vv90irazVH2QqdINg22esuhuq7RIY3K2OKsoXR9epH4ZCjyY GWCh8xUc3xB4KMQMyxMyjF02PGqM6aCLr9CW+Lcg+rRvPFH+dY9tBwa/59aFvpPqET+y hPWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hULYTVvL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si1296087ejm.548.2020.10.23.08.37.09; Fri, 23 Oct 2020 08:37:33 -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; dkim=pass header.i=@kernel.org header.s=default header.b=hULYTVvL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S462856AbgJWLRu (ORCPT + 99 others); Fri, 23 Oct 2020 07:17:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:37642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S462682AbgJWLRt (ORCPT ); Fri, 23 Oct 2020 07:17:49 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 99D83207BB; Fri, 23 Oct 2020 11:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603451868; bh=FMY1pwU92BhVoBdk6p1+lhsYf8oY2OspVIzwsdBME40=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hULYTVvLFl4f+Cpv5lt8polFR0TAAUl17U/ruVVcZpILx6kRHx3YJpFAxHaF/TdfF bcUfdlnYX9W4ehIxlXHqLUrnouA5UJIvo6J/CjFUer4nwlY8Ivwwl0vCRsQhSgP66H xlIc9+GM6ulIV4o9PEs1acazSYt7uer0MMAv371o= Date: Fri, 23 Oct 2020 12:17:41 +0100 From: Will Deacon To: Yong Wu Cc: Joerg Roedel , Matthias Brugger , Rob Herring , Robin Murphy , Krzysztof Kozlowski , Evan Green , Tomasz Figa , linux-mediatek@lists.infradead.org, srv_heupstream@mediatek.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, youlin.pei@mediatek.com, Nicolas Boichat , anan.sun@mediatek.com, chao.hao@mediatek.com, ming-fan.chen@mediatek.com, Greg Kroah-Hartman , kernel-team@android.com Subject: Re: [PATCH v3 08/24] iommu/io-pgtable-arm-v7s: Use ias to check the valid iova in unmap Message-ID: <20201023111740.GA20933@willie-the-truck> References: <20200930070647.10188-1-yong.wu@mediatek.com> <20200930070647.10188-9-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200930070647.10188-9-yong.wu@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 30, 2020 at 03:06:31PM +0800, Yong Wu wrote: > Use the ias for the valid iova checking in arm_v7s_unmap. This is a > preparing patch for supporting iova 34bit for MediaTek. > BTW, change the ias/oas checking format in arm_v7s_map. > > Signed-off-by: Yong Wu > --- > drivers/iommu/io-pgtable-arm-v7s.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c > index a688f22cbe3b..4c9d8dccfc5a 100644 > --- a/drivers/iommu/io-pgtable-arm-v7s.c > +++ b/drivers/iommu/io-pgtable-arm-v7s.c > @@ -526,8 +526,7 @@ static int arm_v7s_map(struct io_pgtable_ops *ops, unsigned long iova, > if (!(prot & (IOMMU_READ | IOMMU_WRITE))) > return 0; > > - if (WARN_ON(iova >= (1ULL << data->iop.cfg.ias) || > - paddr >= (1ULL << data->iop.cfg.oas))) > + if (WARN_ON(iova >> data->iop.cfg.ias || paddr >> data->iop.cfg.oas)) > return -ERANGE; As discussed when reviewing these for Android, please leave this code as-is. > > ret = __arm_v7s_map(data, iova, paddr, size, prot, 1, data->pgd, gfp); > @@ -717,7 +716,7 @@ static size_t arm_v7s_unmap(struct io_pgtable_ops *ops, unsigned long iova, > { > struct arm_v7s_io_pgtable *data = io_pgtable_ops_to_data(ops); > > - if (WARN_ON(upper_32_bits(iova))) > + if (WARN_ON(iova >> data->iop.cfg.ias)) > return 0; And avoid the UB here for 32-bit machines by comparing with 1ULL << iop.cfg.ias instead. Thanks, Will