[bug report] iommu/amd: Introduce gDomID-to-hDomID Mapping and handle parent domain invalidation

From: Dan Carpenter

Date: Fri Feb 06 2026 - 08:38:51 EST


[ Smatch checking is paused while we raise funding. #SadFace
https://lore.kernel.org/all/aTaiGSbWZ9DJaGo7@stanley.mountain/ -dan ]

Hello Suravee Suthikulpanit,

Commit 757d2b1fdf5b ("iommu/amd: Introduce gDomID-to-hDomID Mapping
and handle parent domain invalidation") from Jan 15, 2026
(linux-next), leads to the following Smatch static checker warning:

drivers/iommu/amd/nested.c:161 amd_iommu_alloc_domain_nested()
warn: 'gdom_info->hdom_id' unsigned <= 0

drivers/iommu/amd/nested.c
148 /* Check if gDomID exist */
149 if (refcount_inc_not_zero(&gdom_info->users)) {
150 ndom->gdom_info = gdom_info;
151 xa_unlock(&aviommu->gdomid_array);
152
153 pr_debug("%s: Found gdom_id=%#x, hdom_id=%#x\n",
154 __func__, ndom->gdom_id, gdom_info->hdom_id);
155
156 return &ndom->domain;
157 }
158
159 /* The gDomID does not exist. We allocate new hdom_id */
160 gdom_info->hdom_id = amd_iommu_pdom_id_alloc();
--> 161 if (gdom_info->hdom_id <= 0) {

gdom_info->hdom_id is unsigned. amd_iommu_pdom_id_alloc() can't return
zero. It either returns negatives or 1-65535.

162 __xa_cmpxchg(&aviommu->gdomid_array,
163 ndom->gdom_id, gdom_info, NULL, GFP_ATOMIC);
164 xa_unlock(&aviommu->gdomid_array);
165 ret = -ENOSPC;
166 goto out_err_gdom_info;
167 }
168
169 ndom->gdom_info = gdom_info;

regards,
dan carpenter