From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FD8EC4361B for ; Mon, 7 Dec 2020 12:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43262233A0 for ; Mon, 7 Dec 2020 12:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727093AbgLGMGO (ORCPT ); Mon, 7 Dec 2020 07:06:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:38578 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgLGMGO (ORCPT ); Mon, 7 Dec 2020 07:06:14 -0500 Date: Mon, 7 Dec 2020 12:05:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607342733; bh=xYecpIocncYbomw151SJIMvBkPsNpdC8hHd472+icVw=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=m6pwNfChCGfEwJgZDaxOPHG38w9DWpq6iTj5WODngrXSZTnR/zZIR1ybJwAKOK96O eNVCDCdxh/MFbRkVEtl9g9AuV33pDZpktiuIyX5Us/43J7fpbreJ1InBv01aRopTjJ 3c2mkN/qfPCqvrReEg4ZOB5vuhhP3EqknFaAkDQ21GTgGAzyQ93a5Fn+TD3uXsjSuu wpqNSqiDXWJb3l6nFlgGE1wpC9SlObbPJnBPfu5uNyKrMZw6hYKX1RN6DZ3nyr6fcZ uCZo08hhXvMqfzBV4JbKxQpO7GX0/2TBjDGrdG9X/GfDn5jV11ugt4hUQie1cQurUt AfkL/90K4KKkg== From: Will Deacon To: Robin Murphy Cc: Keqian Zhu , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, 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 Subject: Re: [PATCH] iommu: Up front sanity check in the arm_lpae_map Message-ID: <20201207120527.GA4474@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: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 07, 2020 at 12:01:09PM +0000, Robin Murphy wrote: > 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? I thought it was the other way round -- doesn't this patch move the "empty prot" check later, so we have a chance to check the size and addresses first? Will > > 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); > > /* > >