Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2336200pxu; Mon, 7 Dec 2020 04:08:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGTVfeJN9t+Ayi95qlBZC8MRVUdaLtRKEi0xGiguj5Iqp67zNB3JoeZN/602uvpqgofZBI X-Received: by 2002:aa7:c353:: with SMTP id j19mr3335464edr.204.1607342899308; Mon, 07 Dec 2020 04:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607342899; cv=none; d=google.com; s=arc-20160816; b=l2g4cYPEGiZOIzIgqyuszvDwTid1Wsvg9ehD8cm5XhSi/SLliQGOjuJAb8Jb7CRHex hH55J0BeYRL2opqYPvZtcfYj7K/P3usPDeLJ7gAo59VKy/KCpPsT5x/WYHfEHXDZRA2R pDhZH13DJLLSPl6EyrJNukIiTcMv88y3toRrbSD5dAM8JJCvj6s9UJA0oMEkTB0il873 kch4f/iXwy8sDJQR0+XbmFEG6Lj9aGV/dKGWomUP5p/fB1kt6yysLbMt7Jd1gqbFYahJ f5fiLxiAJXAzh2KjheA6om7YXVZebuheO+cqHY0XOVkLEyWiel5MmxPU0884FE7y7t2p LXkQ== 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=3ThzSq+PXQ6LSMYulmkX82CfKLIyYuP+MgvRV0c41so=; b=kH/n6NDGkLDq28Qqa0WoNHmWXc/fSpSfHLgWwgc3uhb/tKPq4Z9h2dHmBq0g/AU3x9 xR/HVKgpkWgg7dhH8Sl/dandSDuqAQbZ+/7kHAe9sb8lfJ/PG0KxYNu1oNJtmGBRYv5k sb5cT5SIpD41f7E6Vib3q5Vb6He4pjPRshrnhdtZi5hWZ7t4FdTcNJQzgvDm1EewPMMY IqKA7a0B8kE2QnJI6OZzZoJaYVhKehN+XUQiHxijmVEHIZroc3GNyyOuLivUJtyMIx4v aF2eAiPGgw+bZsD2leiLoh14BvHWE/cftzr/F/G05Cys3/a7EQEabHhPe8YCByxEQNO/ qC/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m6pwNfCh; 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 ec12si6127272ejb.727.2020.12.07.04.07.54; Mon, 07 Dec 2020 04:08:19 -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=m6pwNfCh; 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 S1727020AbgLGMGO (ORCPT + 99 others); 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); > > /* > >