Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2321242pxu; Mon, 7 Dec 2020 03:40:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxD1+YlFU3eZq1ANOj0Ov2+9EwbCu86M8FdrGGmjz9wD69ZMu/4QDdsxtSbb4xCWRyvoAtg X-Received: by 2002:a17:906:c244:: with SMTP id bl4mr17649883ejb.430.1607341252064; Mon, 07 Dec 2020 03:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607341252; cv=none; d=google.com; s=arc-20160816; b=LqiHl4nyDc7toaU1vR0fbm566+EfkHezDTQudZvbZ8780cvZEcRAEbxN2+Fz0PwQJK WooBU4bqFJg5mHcswbvmkqFzSSkL4pSuVRUF2Swgbf24RS8pHeY2OjqZ2vgVGnZB3n6y v+GSPRUdYsIQBg8UFP+sxuX+WycG3PvV6XcGgyL5/O/FFOFlzUet8wmGLPtklIVANcsM pc8dw1pqEXKPOIfXQ0KGoRTce0SCm6ARm9Y45lvYtw76mxCYe6sHPyR95naHC38o0hiA BL8fnIfKVptuxzhuQcdoopzjsnDULnHpy+nSJeXG9Dz0h8s7digc361ZUNLXC2QfaAqX uwwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=gfkWw8yU+/Y5Z6HydP7D3mnAh0eIzb9p4kE+6b/3yAM=; b=nJlgszl8Jd0odd3gGloUyitHfnlfF57joVZbCD6XxJxafcW+DaYWWA96ClmOADVBKn ni03JqB6qlQH0y4U8PVkqPNREiLelzaDPSwi41mBwrigx44SpMLlh5aUM8ntqS4u9R4o k2GfKNGVmPVl2aPZyT7Tz46OPka2XcwFpozGDGNeU0N2AN6ioLcdA7EITDU6Gj9en+fN y+eKGwWwhhf/hUTsjXnxT9/LOMxEUiagGffOx4Co18trcsyLR2JbeVSUgStXB36gnnym OWLTF626O95VZsV2syUakB4yQFG++8DR2hyikSk7lPELfeCDJ2J0QUWFH5jNwFjlnvMq 0PPw== 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 bm11si6425819ejb.442.2020.12.07.03.40.29; Mon, 07 Dec 2020 03:40:52 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727742AbgLGLiA (ORCPT + 99 others); Mon, 7 Dec 2020 06:38:00 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9025 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727240AbgLGLhz (ORCPT ); Mon, 7 Dec 2020 06:37:55 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CqLqs5J27zhmfP; Mon, 7 Dec 2020 19:36:41 +0800 (CST) Received: from [10.174.187.37] (10.174.187.37) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Dec 2020 19:37:05 +0800 Subject: Re: [PATCH] iommu: Up front sanity check in the arm_lpae_map To: Will Deacon References: <20201205082957.12544-1-zhukeqian1@huawei.com> <20201207105900.GB4198@willie-the-truck> CC: , , , Marc Zyngier , "Robin Murphy" , Joerg Roedel , "Catalin Marinas" , James Morse , "Suzuki K Poulose" , Sean Christopherson , Julien Thierry , Mark Brown , "Thomas Gleixner" , Andrew Morton , Alexios Zavras , , From: zhukeqian Message-ID: <94799248-f9d1-3a2e-6b82-23d613d4e74b@huawei.com> Date: Mon, 7 Dec 2020 19:37:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20201207105900.GB4198@willie-the-truck> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Will, On 2020/12/7 18:59, Will Deacon wrote: > On Sat, Dec 05, 2020 at 04:29:57PM +0800, Keqian Zhu wrote: >> ... then we have more chance to detect wrong code logic. > > This could do with being a bit more explicit. Something like: > > 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. This looks well, thanks. > >> 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; > > This looks sensible to me, but please can you make the same change for > io-pgtable-arm-v7s.c so that the behaviour is consistent across the two > formats? > OK. I can do it right now. Thanks, Keqian > Thanks, > > Will > . >