Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2301283pxu; Mon, 7 Dec 2020 03:03:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlC1+7R7+cRed5FZwOfRnTQZaNLsWiZjXEbu68pjOOeHPFrgAietTg/mfifjwq54XfZGxX X-Received: by 2002:a50:cdc8:: with SMTP id h8mr3807498edj.293.1607339009900; Mon, 07 Dec 2020 03:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607339009; cv=none; d=google.com; s=arc-20160816; b=totpq7K5yveQR2ykzDWqYAFN9BxIseygR1HI/rivZjrQVqQn8/M6GlkaSfWq1vlSUt kPOngzSk6CK++5E+wKCEFQQp4gw/T+vEdsmQG4I8Gh9aoKRyiYqTIYgxX6igRhuJV55I LA9oZJtIj16eTF/t9R2FCPqSx6002n6L1QqSS+7eBMgTk7RLAkmzsK1Ksi3/M7h7y5S8 +oev9CZqgrHFrI8Ya8u+b3C77DFYjkV5xt+Rsf52kzFyzygZBFq99lE7XrIcrK304BvW mjlUK+EZ6HhR070IN17KM37qkVcfZHrWKUXHUkVZ0piM4A93DbeUc0fqZrQ28ypFvhak 9ocQ== 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 :dkim-signature:date; bh=2B/FUAcLl+XKpevoBlXld2VWnke9jtjsai6TrfbnFZQ=; b=vJB7cubbg2K7Etj4tQnp5/l8d8k5eCuA5Wd6RntfgSzpUzXbaYoh+F71O1CwGpcD1S 69Z1VNo/pId4R80jTXDuQpECuoQClOW0ncg4LguGDVA5W2pTC0d+5eaR5Kb32VTXx5j6 8/I4ee3bmwK1ndBrhSUjrfZtidLKsQ+yUNqKcURTgCg7T5oJp/ADaEsSnFviJqecUn09 LO8rW0qpCQMTPCQ2gDtdUUlpCr5BgW4ab8QsNVBwx0pImYDqANeNQhkt3LMG895taO9y ZOt6sHw48uxD3DGkQSy5HfEGknFX3lFNZPDME4uFExxfY6k4FyzPtzXbL8hSLxas4gaP SlEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jrzTGziG; 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 c12si6105067ejb.751.2020.12.07.03.03.07; Mon, 07 Dec 2020 03:03:29 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jrzTGziG; 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 S1726269AbgLGK7s (ORCPT + 99 others); Mon, 7 Dec 2020 05:59:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:42534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725842AbgLGK7s (ORCPT ); Mon, 7 Dec 2020 05:59:48 -0500 Date: Mon, 7 Dec 2020 10:59:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607338747; bh=5X4Wa2tCGKFImboi89kNZo+q4agi1Sa5rC9nKY4bhJQ=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=jrzTGziG9p7kWufm4+jEWs1AcM3mYrffolvbVjt22y4jw6bR3+ct20YSRnbiynHtY ZKE4tl6T1gvC3TKkkMTo/b8kXbzkCoXXHxURN09nnRyqZFNrEPrEn83Z41+TK1Zqwk G/615OmtLz2u9VS2i5XQ0/7GIGsucMsjONeks3mxeOu1f+arJCjNu3kaZUeUFxelQr DNGxIeO6iSofrDL7Ns3ta0vdln1BnNkwvVlXYvmKDJTZ/qSrzCa6t+mACfEOgZYdQH frsrxtr2ZGwh5MPOQK6sc+0eE+hXtrY1f3UI29nQvj6YO4X00Zq/0NUDIJzW2ji1UD dX4ymbMZkAhKg== From: Will Deacon To: Keqian Zhu Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, 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 , wanghaibin.wang@huawei.com, jiangkunkun@huawei.com Subject: Re: [PATCH] iommu: Up front sanity check in the arm_lpae_map Message-ID: <20201207105900.GB4198@willie-the-truck> References: <20201205082957.12544-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201205082957.12544-1-zhukeqian1@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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? Thanks, Will