Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1003345pxu; Sat, 5 Dec 2020 00:35:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjWDlM6SC4B1VQD2Skyuim8kYLQR0NCuG+qck+fJ1rsRsLFrl2ODWGspy2Y7XL6adMDj2I X-Received: by 2002:a17:906:fa12:: with SMTP id lo18mr10956992ejb.354.1607157344385; Sat, 05 Dec 2020 00:35:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607157344; cv=none; d=google.com; s=arc-20160816; b=o5BgKfags3DQC+AUVisYtoeZzJHAATVNPOd8duayme89TC+iyEYBRv8Glp00Q84gxG ihATctnuhUgQ498UAFzaIu9FwVZa2Agox2858hUTzSx82Oy8VOyXEdJ3xonU8Xfv8BcU cn8ZYL+6/KQVYdr+ffkUDxLNpR+cjc1ovj2ZjiJbU2jxlpjYtpfWSSMNb7Z/Qc45a6dR ofkEVS0AsjeXyxwhMv7G90Kxh+OU+ZaABHicHtSbjkznACtOW0ylbmRw5WDjcN3ismPc T3Dve/h7vrn0RczrKMmikk/YxN22+G+rp0EHXxt/Y/htk0+raPGS47t6Y9QFPia/PZdY bPOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=J2iEV8hMEJeMxHgp/uifJ89A9jzp20nMVs7lpDIlRek=; b=JXIdSz8e7lRM2ADUSyovqL+OX7aA17mXXoUbFMGru7tTT/l1mKO1KUNkbQRPlmJq2c dqLYXDYsHLpt6/kOhl2TgvlmoTblOUa1UvWqBj0T2G5UA4UOq8jWXBWdDQh81Sqaomsc lLyXzsO+BkslMxRXKzFEwHrBPiUC5Bo9tzepbLYOTylP/PvniL/1CQklYJNDPMRzR54u 9sn4XFZUtI7vU3RvEa1q72rnPkgpHX83Yp44HLWdlJN5HfjbdGQx2t//8iSOt8UVT4Mj 9Y5mt0IUNcReSqCFIbcFaXxqJTsqyKF85VdJdfj9TZANfEasovJGUZKHbTdffWvE2K9S V2jw== 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 hr14si2813642ejc.396.2020.12.05.00.35.21; Sat, 05 Dec 2020 00:35:44 -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 S1726841AbgLEIdA (ORCPT + 99 others); Sat, 5 Dec 2020 03:33:00 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:8667 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbgLEIbv (ORCPT ); Sat, 5 Dec 2020 03:31:51 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Cp2nd3m6Mz15XHm; Sat, 5 Dec 2020 16:30:13 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.37) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Sat, 5 Dec 2020 16:30:32 +0800 From: Keqian Zhu To: , , CC: Will Deacon , 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 , , , Keqian Zhu Subject: [PATCH] iommu: Up front sanity check in the arm_lpae_map Date: Sat, 5 Dec 2020 16:29:57 +0800 Message-ID: <20201205082957.12544-1-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ... then we have more chance to detect wrong code logic. 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); /* -- 2.23.0