Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp264858pxu; Thu, 7 Jan 2021 04:33:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzr7QL4dqmMQA2E6KiGZ+MaWjkN33R6nsaGmS5XStYrhX6/rxuqoplzrwCJDOtH8ZfTACSJ X-Received: by 2002:a05:6402:746:: with SMTP id p6mr1518907edy.313.1610022832739; Thu, 07 Jan 2021 04:33:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610022832; cv=none; d=google.com; s=arc-20160816; b=p0eHOFm9n2yIGDURaxWsIiWeO2/UVaYcmQwBv5ifysODJRtxM/HptTFm2vdZjOwyeX 0mf4X+r3mccKT5y85dailmcWZNn7ULFtY3ig8lgyZlJhOLdKlO+0AJe4bdSvHnhBzmm5 /XfNzcXSV1ZduuQ3vPVX3FsdQL/+PUKwhPakgBjLXh2AKQIZVhlhyyWSlEUG0OmE15QQ uE0WloEEFRphOvyUisbOtuScLOXvCtKcQoO3vAvPKIMjMAZhQQe7UFTBznDMm9Q2bHhE Sx3DKhDrL/X8KtW9lLlHSkK6lanuQPuyP+v6yp28cpw12CsdWpfLIJT0jCqa4GdPRNpP 2/xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=0KP/pVupHfYKYgb7JKAyRh0VRr12dXbadT1KziMqDYI=; b=AYuLbyQ6dzq7GFChk+2Pdts4VHChK9MBFn5AZncWyV7I9ydAp1BKewUGCSH5s7zggO ETuMf18/6lwJeywfdAhmSPBmVTFn7naTRl5p95musxtI83tNC5w6bjAyVZYgRZAbtUWu 0i09W0IwFJPzX4njxOc7AOgHx4Uvbh24hWo1Q7MABdiV9yt1cJIvHFH9dg0RuEvvu0Ax w8trQS85XKIK3hxRgqVGZfnCMuQdZwtQM1zsEMBFvjcpEhmyA78iuU/ONjH3dS7Xl8/S qIi3XVnE/ZHj6Zvo22tMHPtsoOuVZMY4iYV/5KIFzLEAA96kYHUm9RsICPmqmrseTihu 7KrQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo16si2182582ejb.86.2021.01.07.04.33.29; Thu, 07 Jan 2021 04:33:52 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728188AbhAGMaz (ORCPT + 99 others); Thu, 7 Jan 2021 07:30:55 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:41356 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725835AbhAGMay (ORCPT ); Thu, 7 Jan 2021 07:30:54 -0500 X-UUID: 86e73c3f0034401a82a686edce92bb07-20210107 X-UUID: 86e73c3f0034401a82a686edce92bb07-20210107 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1210095996; Thu, 07 Jan 2021 20:30:08 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 7 Jan 2021 20:30:06 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 7 Jan 2021 20:30:00 +0800 From: Yong Wu To: Joerg Roedel , Will Deacon , Robin Murphy CC: Matthias Brugger , Krzysztof Kozlowski , Tomasz Figa , , , , , , , , Nicolas Boichat , , , Greg Kroah-Hartman , , Christoph Hellwig , David Laight Subject: [PATCH v4 4/7] iommu: Switch gather->end to the inclusive end Date: Thu, 7 Jan 2021 20:29:06 +0800 Message-ID: <20210107122909.16317-5-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210107122909.16317-1-yong.wu@mediatek.com> References: <20210107122909.16317-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently gather->end is "unsigned long" which may be overflow in arch32 in the corner case: 0xfff00000 + 0x100000(iova + size). Although it doesn't affect the size(end - start), it affects the checking "gather->end < end" This patch changes this "end" to the real end address (end = start + size - 1). Correspondingly, update the length to "end - start + 1". Fixes: a7d20dc19d9e ("iommu: Introduce struct iommu_iotlb_gather for batching TLB flushes") Signed-off-by: Yong Wu --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/mtk_iommu.c | 2 +- drivers/iommu/tegra-gart.c | 2 +- include/linux/iommu.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 8ca7415d785d..c70d6e79f534 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2280,7 +2280,7 @@ static void arm_smmu_iotlb_sync(struct iommu_domain *domain, { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - arm_smmu_tlb_inv_range(gather->start, gather->end - gather->start, + arm_smmu_tlb_inv_range(gather->start, gather->end - gather->start + 1, gather->pgsize, true, smmu_domain); } diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index f579fc21971e..66a00a2cb445 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -443,7 +443,7 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, struct iommu_iotlb_gather *gather) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); - size_t length = gather->end - gather->start; + size_t length = gather->end - gather->start + 1; if (gather->start == ULONG_MAX) return; diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index 05e8e19b8269..6f130e51f072 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -270,7 +270,7 @@ static void gart_iommu_sync_map(struct iommu_domain *domain, unsigned long iova, static void gart_iommu_sync(struct iommu_domain *domain, struct iommu_iotlb_gather *gather) { - size_t length = gather->end - gather->start; + size_t length = gather->end - gather->start + 1; gart_iommu_sync_map(domain, gather->start, length); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 9ce0aa9e236b..ae8eddd4621b 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -170,7 +170,7 @@ enum iommu_dev_features { * struct iommu_iotlb_gather - Range information for a pending IOTLB flush * * @start: IOVA representing the start of the range to be flushed - * @end: IOVA representing the end of the range to be flushed (exclusive) + * @end: IOVA representing the end of the range to be flushed (inclusive) * @pgsize: The interval at which to perform the flush * * This structure is intended to be updated by multiple calls to the @@ -539,7 +539,7 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, struct iommu_iotlb_gather *gather, unsigned long iova, size_t size) { - unsigned long start = iova, end = start + size; + unsigned long start = iova, end = start + size - 1; /* * If the new page is disjoint from the current range or is mapped at -- 2.18.0