Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3210487pxu; Tue, 8 Dec 2020 06:25:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwPge0aBlB4snP9NBmLd8mkntYdoIPeO+F8xNjhL28pTjcGmu6W/1Tq2lWaGNw9HkYttkv X-Received: by 2002:a50:ee11:: with SMTP id g17mr16216385eds.259.1607437541743; Tue, 08 Dec 2020 06:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607437541; cv=none; d=google.com; s=arc-20160816; b=ep9r06Xo+WTPsflkWjvNqo3zziqB+8UUFZ7/4zRi0VSK8JVN3ANl5hyTmBq1R+ATk0 3Td2ZmOIkMcwHKZ11Y0gGsgXJqzTTioP4TxQhivqp2WSKzceQXoQZVOU0XRZvWnX+wdK gslDkuNO320Ne0Hp22WqZxgnUKtHaAXiVUwjvZQYaPWkBOwsCgaZU4a3zSzW5jtE0IOg joJjvVUms+nvPbwgkMpNyjFEk9bnl84R5940Wg2I6tupimO7FVaY8L1zpAR7UbOzV0XC bEyILDX5fMMuUHiY19W7t6oyAhXExaYww30Y/YwOvctm1BkwG968X9NJ6dULJR7aahpE fOjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=hfA6xVJ5aWIWfxM+5SnYST2ofXUnSrHKxkyseGncOqk=; b=MMkj9WmTXrFIOT5kWm1pNh7ouXV8O/1PpUJF6wXGT+rUPxeIb0/GzvQCE0g8zigNvK LREqDLAOMggWaW4euTAAYaCFCmuCmuRGyuBezXOcqFF3kU/SwTuQPuuFSAVNvSQ4P15b lPUP2DJRBOsAyfFUVT6ciyMG2mM9delyMd5Fb4Gw0z8TxQ5wz7F/PJsvrDv/yA5PnHA2 s9dpK64ZMk3Zzug3AwgbFw5sjv9Hzro8SayXZdGGnb+JAMrrv9SadM1PcmVkdO3gX5ek GFeDtnUe//UXc+pwkH/CNJOmpBj+6UieuN8OH0S54OaQCemn7ctwA1qW4b7Rj5WkpR3f FwQA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si8296875ejg.677.2020.12.08.06.25.15; Tue, 08 Dec 2020 06:25:41 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729598AbgLHOVR (ORCPT + 99 others); Tue, 8 Dec 2020 09:21:17 -0500 Received: from foss.arm.com ([217.140.110.172]:49638 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgLHOVR (ORCPT ); Tue, 8 Dec 2020 09:21:17 -0500 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 4401930E; Tue, 8 Dec 2020 06:20:31 -0800 (PST) Received: from [10.57.61.6] (unknown [10.57.61.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D72C23F718; Tue, 8 Dec 2020 06:20:27 -0800 (PST) Subject: Re: [PATCH v2] iommu: Defer the early return in arm_(v7s/lpae)_map To: Keqian Zhu , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Cc: Will Deacon , Marc Zyngier , Joerg Roedel , Catalin Marinas , James Morse , Suzuki K Poulose , Sean Christopherson , Julien Thierry , Mark Brown , Thomas Gleixner , Andrew Morton , Alexios Zavras , wanghaibin.wang@huawei.com, jiangkunkun@huawei.com References: <20201207115758.9400-1-zhukeqian1@huawei.com> From: Robin Murphy Message-ID: Date: Tue, 8 Dec 2020 14:20:27 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20201207115758.9400-1-zhukeqian1@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-12-07 11:57, Keqian Zhu wrote: > Although handling a mapping request with no permissions is a > trivial no-op, defer the early return until after the size/range > checks so that we are consistent with other mapping requests. Reviewed-by: Robin Murphy > Signed-off-by: Keqian Zhu > --- > drivers/iommu/io-pgtable-arm-v7s.c | 8 ++++---- > drivers/iommu/io-pgtable-arm.c | 8 ++++---- > 2 files changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c > index a688f22cbe3b..359b96b0fa3e 100644 > --- a/drivers/iommu/io-pgtable-arm-v7s.c > +++ b/drivers/iommu/io-pgtable-arm-v7s.c > @@ -522,14 +522,14 @@ static int arm_v7s_map(struct io_pgtable_ops *ops, unsigned long iova, > struct io_pgtable *iop = &data->iop; > int ret; > > - /* If no access, then nothing to do */ > - if (!(prot & (IOMMU_READ | IOMMU_WRITE))) > - return 0; > - > if (WARN_ON(iova >= (1ULL << data->iop.cfg.ias) || > paddr >= (1ULL << data->iop.cfg.oas))) > return -ERANGE; > > + /* If no access, then nothing to do */ > + if (!(prot & (IOMMU_READ | IOMMU_WRITE))) > + return 0; > + > ret = __arm_v7s_map(data, iova, paddr, size, prot, 1, data->pgd, gfp); > /* > * Synchronise all PTE updates for the new mapping before there's > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index a7a9bc08dcd1..8ade72adab31 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -444,10 +444,6 @@ static int arm_lpae_map(struct io_pgtable_ops *ops, unsigned long iova, > arm_lpae_iopte prot; > long iaext = (s64)iova >> cfg->ias; > > - /* If no access, then nothing to do */ > - if (!(iommu_prot & (IOMMU_READ | IOMMU_WRITE))) > - return 0; > - > if (WARN_ON(!size || (size & cfg->pgsize_bitmap) != size)) > return -EINVAL; > > @@ -456,6 +452,10 @@ static int arm_lpae_map(struct io_pgtable_ops *ops, unsigned long iova, > if (WARN_ON(iaext || paddr >> cfg->oas)) > return -ERANGE; > > + /* If no access, then nothing to do */ > + if (!(iommu_prot & (IOMMU_READ | IOMMU_WRITE))) > + return 0; > + > prot = arm_lpae_prot_to_pte(data, iommu_prot); > ret = __arm_lpae_map(data, iova, paddr, size, prot, lvl, ptep, gfp); > /* >