Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1726596pxj; Wed, 19 May 2021 12:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGskDCYfbwgHlLqdq240K8DHriAxc+wKH5hPB/ooaByuJPT0I3aXeQCAfJ6G3DT+WqrSdY X-Received: by 2002:a92:b07:: with SMTP id b7mr603777ilf.268.1621452354885; Wed, 19 May 2021 12:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621452354; cv=none; d=google.com; s=arc-20160816; b=u6yMCwHYgTlLqd4Rwue/+rij+R7DmGJ/Lf4RNLmusftCuWLHVDaiQKLOKxCG+DNEc/ KXEKJkBuRJHbG4877agP3Smhub0iEr7F1tGN/OgMFuGv5Xvh7TIU0/na1b9inl1uXzSI SNAFA6WP0RV5bg6Y6gbVuOyu5UiJ7kK6kDXDN6bAmwDCqK2YkF7EaY4fgCoA3ttIRpsz Yp0aoj4KNdWx02Po38r64494reNybPYuhTgUPW66S+fkE3jXUwdaRVUyiolMrIFQ2+eH qZMtAOjieVLeb9X5KI48dksy3Dai5krX9a538Sx78Mg6ejmUdQ/C3X57EUycJb3kqGLX gjYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SQ+gml4LvMD8zSi99059FCr0a0trcCbJkYA9m5n6+4Q=; b=MXgs9J/p41ZFDBp5C/aY1yHPuXnIBPdr3KJB45QFuXG9O8pWXWSiJn6+Rw3wBPhxBK r7uorAdeniXd2kd4umDpoI/H7NCyNw3R/x6z6m5esFd4TvM+FFJ9E1zI8wB5qGoDYiIE qZLkoNf1DVTpbbd8vxHFzfaESqSUkfEOhsCcOoYE47D9ltWwXTjSKhYFi5jUcqCx2t/S 2aL8NRlGAxzd3/CBiAfF1JVl1+BWDER3XUPil8CN694B5Srf1Yu9CZDXczwPEnlgu4tn nQC9SuUy4dvBSmk0Ce0l52HQNuWt2l8NxQWhwIM+Z0wAs092rF699LlP9+bmRwdG1w9j JaTw== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y5si666144ily.21.2021.05.19.12.25.41; Wed, 19 May 2021 12:25:54 -0700 (PDT) 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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346062AbhESJp4 (ORCPT + 99 others); Wed, 19 May 2021 05:45:56 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4745 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345252AbhESJpq (ORCPT ); Wed, 19 May 2021 05:45:46 -0400 Received: from dggems703-chm.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FlSY42yz2zpfb5; Wed, 19 May 2021 17:40:56 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by dggems703-chm.china.huawei.com (10.3.19.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Wed, 19 May 2021 17:44:17 +0800 Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 19 May 2021 17:44:17 +0800 From: Kunkun Jiang To: Will Deacon , Robin Murphy , "Eric Auger" , "moderated list:ARM SMMU DRIVERS" , "open list:IOMMU DRIVERS" , open list CC: , Keqian Zhu , "Zenghui Yu" , Kunkun Jiang Subject: [RFC PATCH v1 1/2] iommu/arm-smmu-v3: Align invalid range with leaf page size upwards when support RIL Date: Wed, 19 May 2021 17:43:06 +0800 Message-ID: <20210519094307.3275-2-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20210519094307.3275-1-jiangkunkun@huawei.com> References: <20210519094307.3275-1-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.185.210] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the __arm_smmu_tlb_inv_range(), the fileds of TLBI CMD is calculated based on the invalid range and the leaf page size, when SMMU supports RIL. It will cause some errors when the invalid range isn't aligned with the leaf page size. 1. The num_pages will be zero, if the invalid range is less than b. Then it will enter an endless loop in __arm_smmu_tlb_inv_range(). 2. The actual invalid range will only be part of the invalid range. If the invalid range is not an integral multiple of the leaf page size. To align invalid range with leaf page size upwards will solve the two issues. Reported-by: Nianyao Tang Signed-off-by: Kunkun Jiang --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++++ 1 file changed, 4 insertions(+) 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 54b2f27b81d4..8a2cacbb1ef8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1703,7 +1703,9 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, if (smmu->features & ARM_SMMU_FEAT_RANGE_INV) { /* Get the leaf page size */ + size_t leaf_pgsize; tg = __ffs(smmu_domain->domain.pgsize_bitmap); + leaf_pgsize = 1 << tg; /* Convert page size of 12,14,16 (log2) to 1,2,3 */ cmd->tlbi.tg = (tg - 10) / 2; @@ -1711,6 +1713,8 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, /* Determine what level the granule is at */ cmd->tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3)); + /* Align size with the leaf page size upwards */ + size = ALIGN(size, leaf_pgsize); num_pages = size >> tg; } -- 2.23.0