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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,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 451BBC4167B for ; Mon, 7 Dec 2020 12:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12620233CF for ; Mon, 7 Dec 2020 12:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727472AbgLGMQO (ORCPT ); Mon, 7 Dec 2020 07:16:14 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9027 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727099AbgLGMQO (ORCPT ); Mon, 7 Dec 2020 07:16:14 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CqMh45cdtzhntL; Mon, 7 Dec 2020 20:15:00 +0800 (CST) Received: from [10.174.187.37] (10.174.187.37) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Dec 2020 20:15:22 +0800 Subject: Re: [PATCH] iommu: Up front sanity check in the arm_lpae_map To: Will Deacon , Robin Murphy References: <20201205082957.12544-1-zhukeqian1@huawei.com> <20201207120527.GA4474@willie-the-truck> CC: , , , Marc Zyngier , "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: <2b0ec25b-0fa4-65ca-7c1b-109ce766197f@huawei.com> Date: Mon, 7 Dec 2020 20:15:21 +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: <20201207120527.GA4474@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, On 2020/12/7 20:05, Will Deacon wrote: > 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? Yes, this is my original idea. For that we treat iommu_prot with no permission as success at early start, defer this early return can expose hidden errors. Thanks, Keqian > > 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); >>> /* >>> > . > 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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 BDBA1C4361B for ; Mon, 7 Dec 2020 12:15:41 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EC032339D for ; Mon, 7 Dec 2020 12:15:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EC032339D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id B9C2C87254; Mon, 7 Dec 2020 12:15:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qx5Xv6bDcqdT; Mon, 7 Dec 2020 12:15:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 4061B8710D; Mon, 7 Dec 2020 12:15:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 33F10C0FA7; Mon, 7 Dec 2020 12:15:40 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 84426C013B for ; Mon, 7 Dec 2020 12:15:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7118A87254 for ; Mon, 7 Dec 2020 12:15:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rpUzEy33Mh2I for ; Mon, 7 Dec 2020 12:15:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by whitealder.osuosl.org (Postfix) with ESMTPS id A23DB8710D for ; Mon, 7 Dec 2020 12:15:35 +0000 (UTC) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CqMh45cdtzhntL; Mon, 7 Dec 2020 20:15:00 +0800 (CST) Received: from [10.174.187.37] (10.174.187.37) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Dec 2020 20:15:22 +0800 Subject: Re: [PATCH] iommu: Up front sanity check in the arm_lpae_map To: Will Deacon , Robin Murphy References: <20201205082957.12544-1-zhukeqian1@huawei.com> <20201207120527.GA4474@willie-the-truck> From: zhukeqian Message-ID: <2b0ec25b-0fa4-65ca-7c1b-109ce766197f@huawei.com> Date: Mon, 7 Dec 2020 20:15:21 +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: <20201207120527.GA4474@willie-the-truck> X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Cc: Suzuki K Poulose , Marc Zyngier , jiangkunkun@huawei.com, linux-kernel@vger.kernel.org, Sean Christopherson , Alexios Zavras , iommu@lists.linux-foundation.org, Mark Brown , James Morse , Julien Thierry , Catalin Marinas , wanghaibin.wang@huawei.com, Thomas Gleixner , Andrew Morton , linux-arm-kernel@lists.infradead.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" Hi, On 2020/12/7 20:05, Will Deacon wrote: > 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? Yes, this is my original idea. For that we treat iommu_prot with no permission as success at early start, defer this early return can expose hidden errors. Thanks, Keqian > > 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); >>> /* >>> > . > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu 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=-15.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,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 7CE9EC4361B for ; Mon, 7 Dec 2020 12:16:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BD5D233ED for ; Mon, 7 Dec 2020 12:16:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BD5D233ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IqDI60vcceCUGRybLeDt9W8QGK1em/51/47ITIgcObo=; b=l77ieRlOpTPjFtOqWhYsjJ7bk o1rrj94CT34TWRdJFfSX/1grPeUfhTETfdG3X5NXR4tew1elhJlEjbwJ7/82OVZKr9rf2ZMt7I0tj DwO4G84Q5qMO6WwBzBP8SDVCszLxWyOJeDHMZ7mmhPMKXauaerXwhoRIQpARUKQO192YxJNHrfxER cyOmPcCmHu/q5Nwtc9hfjWqy+xyyMJqfbIwFf94HXwx77SvS3JrjprcI8vwiaVStu+tundXu4p0uF KTQezWAuZl79uucadgWQJgJwrg2CIaZPtg5cRIxVQ96iEqJVmB6dy/sugJyfUvkiox7o7wjZJ/XQF wMOvZBBnw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmFQY-0008NC-B7; Mon, 07 Dec 2020 12:15:38 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmFQW-0008MM-4p for linux-arm-kernel@lists.infradead.org; Mon, 07 Dec 2020 12:15:37 +0000 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CqMh45cdtzhntL; Mon, 7 Dec 2020 20:15:00 +0800 (CST) Received: from [10.174.187.37] (10.174.187.37) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Dec 2020 20:15:22 +0800 Subject: Re: [PATCH] iommu: Up front sanity check in the arm_lpae_map To: Will Deacon , Robin Murphy References: <20201205082957.12544-1-zhukeqian1@huawei.com> <20201207120527.GA4474@willie-the-truck> From: zhukeqian Message-ID: <2b0ec25b-0fa4-65ca-7c1b-109ce766197f@huawei.com> Date: Mon, 7 Dec 2020 20:15:21 +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: <20201207120527.GA4474@willie-the-truck> X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201207_071536_683635_19B5EF1F X-CRM114-Status: GOOD ( 18.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Suzuki K Poulose , Marc Zyngier , Joerg Roedel , jiangkunkun@huawei.com, linux-kernel@vger.kernel.org, Sean Christopherson , Alexios Zavras , iommu@lists.linux-foundation.org, Mark Brown , James Morse , Julien Thierry , Catalin Marinas , wanghaibin.wang@huawei.com, Thomas Gleixner , Andrew Morton , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On 2020/12/7 20:05, Will Deacon wrote: > 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? Yes, this is my original idea. For that we treat iommu_prot with no permission as success at early start, defer this early return can expose hidden errors. Thanks, Keqian > > 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); >>> /* >>> > . > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel