Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2333615pxu; Mon, 7 Dec 2020 04:04:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQomrJt9lFN6/LxIGexHQ6pJj9dtJe5nQRgjxH5FB/1FhQe2OGBDp0QgffuMAp6sdltwNQ X-Received: by 2002:a17:906:cc8c:: with SMTP id oq12mr19208699ejb.419.1607342679699; Mon, 07 Dec 2020 04:04:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607342679; cv=none; d=google.com; s=arc-20160816; b=j6ZK7WpeByKpCovfgNbgt4aT/q/RlpAwxRzkZJzsAFE1dC7jGKkqkcK3vz4w32aN/X Octa4hMYqKN32FAGrE0PJ99/sGx/89ILRdvKaTYU2ZjOeDJDeSWcuKAE8GxKe/WEeLYp YCM3aTYke4syB5IXdRXaKEQ7wh/7rLzPmpm57+3rc3/b4j1jPa2JZ81cwEbMGGGMdc4i N5HF+DMRidyZ1DbJMi0gPYOhUsdlRRVafNT0OUmoJXnSE2CkFD9mUZD3sAos37FfNBNB CU1yiN3+bQB2U+I0P/UFhA9MckvV7eSm65jzZ2KKCrQVPUl4WlX2q2ra7Cmj/z+6Zof3 768Q== 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=y/lSWyrwwQ1iKnk54KTu4WK752ZoOJCqVn4vCnyAN2o=; b=yGxwPv7d1VzWk+QW61RukBWcxQTfLINPrbGk0LuVz//e7BRfd3zbwjg7EuyCN/sWq+ SzmA9zp+R/dojMJWvRaKeIz2xYrzNJqM0ntE56TFzffKBCHe7SkvNN2DO0hEUE3GUIHy yyIgw3HWEBrhbsRX2S+yR3MdcIpX6MJdhZC4T5YKmMcGzTOb5xxdc8F1bSUiI3q3drWA HQlxEaOkPPvYVFAfqZtMfSTZZj8ZQe/PncKlmXt5I32qwS0/1WwmbLBEXEto5v4SvoH7 af6smyiD5roSv2TlWR40OgIRAUsePhNv4HAHi7PDH9G/nSRDTpk8nnCM8AAwXxyuH0kn 16TA== 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 j12si6549126ejb.431.2020.12.07.04.04.15; Mon, 07 Dec 2020 04:04:39 -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 S1726880AbgLGMCF (ORCPT + 99 others); Mon, 7 Dec 2020 07:02:05 -0500 Received: from foss.arm.com ([217.140.110.172]:48686 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbgLGMCE (ORCPT ); Mon, 7 Dec 2020 07:02:04 -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 02E561042; Mon, 7 Dec 2020 04:01:19 -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 7C97D3F718; Mon, 7 Dec 2020 04:01:16 -0800 (PST) Subject: Re: [PATCH] iommu: Up front sanity check in the arm_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: <20201205082957.12544-1-zhukeqian1@huawei.com> From: Robin Murphy Message-ID: Date: Mon, 7 Dec 2020 12:01:09 +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: <20201205082957.12544-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-05 08:29, Keqian Zhu wrote: > ... then we have more chance to detect wrong code logic. I don't follow that justification - it's still the same check with the same outcome, so how does moving it have any effect on the chance to detect errors? AFAICS the only difference it would make is to make some errors *less* obvious - if a sufficiently broken caller passes an empty prot value alongside an invalid size or already-mapped address, this will now quietly hide the warnings from the more serious condition(s). Yes, it will bail out a bit faster in the specific case where the prot value is the only thing wrong, but since when do we optimise for fundamentally incorrect API usage? Robin. > Signed-off-by: Keqian Zhu > --- > drivers/iommu/io-pgtable-arm.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > 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); > /* >