Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3341267B89 for ; Mon, 25 May 2026 01:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779673634; cv=none; b=cUARQDSheJ0SSFYk7o2Qzwm/dd0LAAmx9eh/c/rfNV9onLx1gdH02BWaGs91EOvFFy9v8pkcTVVzGZwalUhTH1RXEldPp96Pr0/A5m0mYsQnuCRwQFCCX/iwVmJyrErNif0Oyr03M2O6FDv0DNFRcBwxcHfIENDCi/n4Jbrn1Qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779673634; c=relaxed/simple; bh=WlEkZOv5nj0ARZNqtX9/2kxG01H0k9HKinBRL/jDQrg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nvirsEqfPec1qmWBYxoPbXekxkUbLVZTc5x7LxIbCCNH2tnLGyE7pSpfK+A+1xJlp/JDQvxFegnQFAf1xvBCCdEJFxU/LaKp8p6HGj33IY/E9daXdytVrBRNWskHerBXecjeH0lXJT3cyJHjK8PxUJeO7CRyECebL2Dfg9EWi5M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=dtfltjvX; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="dtfltjvX" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=kkywFzGdQQywiGFe2xfuQHQyuwWQgBARrNGTnWz1u1w=; b=dtfltjvXYtDGgW3Du5vG9ZMz5AXZ5Vcocg7mTvzDJh/7dI0RQfP3H1Os28T8fCiGv5+wTy+cW m9TwCy0WXvoy0fta7+smjnLZe+yjyYZoBk9I/Brfmqu5NEQPoXzIWlgh5jgkgg6RgYAf8RTT9jo 2OWOGr9rsZ+8WOyFm2C4JHI= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4gNz7q4XDFzLlTc; Mon, 25 May 2026 09:39:19 +0800 (CST) Received: from kwepemj200003.china.huawei.com (unknown [7.202.194.15]) by mail.maildlp.com (Postfix) with ESMTPS id 7907A40565; Mon, 25 May 2026 09:47:03 +0800 (CST) Received: from localhost.huawei.com (10.90.31.46) by kwepemj200003.china.huawei.com (7.202.194.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 25 May 2026 09:47:02 +0800 From: Qinxin Xia To: CC: , , Balbir Singh , , Jason Gunthorpe , Jean-Philippe Brucker , Will Deacon , Robin Murphy , Joerg Roedel , Jason Gunthorpe Subject: [PATCH OLK-6.6 4/4] iommu/arm-smmu-v3: Fix pgsize_bit for sva domains Date: Mon, 25 May 2026 09:46:51 +0800 Message-ID: <20260525014651.3531030-5-xiaqinxin@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20260525014651.3531030-1-xiaqinxin@huawei.com> References: <20260525014651.3531030-1-xiaqinxin@huawei.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemj200003.china.huawei.com (7.202.194.15) From: Balbir Singh mainline inclusion from mainline-v6.15-rc5 commit 12f78021973ae422564b234136c702a305932d73 category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9215 CVE: NA Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=12f78021973ae422564b234136c702a305932d73 ---------------------------------------------------------------------- UBSan caught a bug with IOMMU SVA domains, where the reported exponent value in __arm_smmu_tlb_inv_range() was >= 64. __arm_smmu_tlb_inv_range() uses the domain's pgsize_bitmap to compute the number of pages to invalidate and the invalidation range. Currently arm_smmu_sva_domain_alloc() does not setup the iommu domain's pgsize_bitmap. This leads to __ffs() on the value returning 64 and that leads to undefined behaviour w.r.t. shift operations Fix this by initializing the iommu_domain's pgsize_bitmap to PAGE_SIZE. Effectively the code needs to use the smallest page size for invalidation Cc: stable@vger.kernel.org Fixes: eb6c97647be2 ("iommu/arm-smmu-v3: Avoid constructing invalid range commands") Suggested-by: Jason Gunthorpe Signed-off-by: Balbir Singh Cc: Jean-Philippe Brucker Cc: Will Deacon Cc: Robin Murphy Cc: Joerg Roedel Cc: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20250412002354.3071449-1-balbirs@nvidia.com Signed-off-by: Will Deacon Signed-off-by: Qinxin Xia Signed-off-by: Hongye Lin --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 9342fac71801..4075ef00c4c9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -402,6 +402,12 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, return ERR_CAST(smmu_domain); smmu_domain->domain.type = IOMMU_DOMAIN_SVA; smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; + + /* + * Choose page_size as the leaf page size for invalidation when + * ARM_SMMU_FEAT_RANGE_INV is present + */ + smmu_domain->domain.pgsize_bitmap = PAGE_SIZE; smmu_domain->smmu = smmu; ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain, -- 2.33.0