diff --git a/drivers/gpu/drm/i915/gvt/display.c b/drivers/gpu/drm/i915/gvt/display.c
index df1e14145747..e0b25efd9fee 100644
--- a/drivers/gpu/drm/i915/gvt/display.c
+++ b/drivers/gpu/drm/i915/gvt/display.c
@@ -359,7 +359,8 @@ void intel_gvt_check_vblank_emulation(struct intel_gvt *gvt)
 {
 	struct intel_gvt_irq *irq = &gvt->irq;
 	struct intel_vgpu *vgpu;
-	int pipe, id;
+	unsigned long id;
+	int pipe;
 	int found = false;
 
 	mutex_lock(&gvt->lock);
@@ -434,7 +435,7 @@ static void emulate_vblank(struct intel_vgpu *vgpu)
 void intel_gvt_emulate_vblank(struct intel_gvt *gvt)
 {
 	struct intel_vgpu *vgpu;
-	int id;
+	unsigned long id;
 
 	mutex_lock(&gvt->lock);
 	for_each_active_vgpu(gvt, vgpu, id)
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
index 733a2a0d0c30..ef6c62ebc2be 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -329,7 +329,6 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
 	intel_gvt_clean_irq(gvt);
 	intel_gvt_free_firmware(gvt);
 	intel_gvt_clean_mmio_info(gvt);
-	idr_destroy(&gvt->vgpu_idr);
 
 	kfree(dev_priv->gvt);
 	dev_priv->gvt = NULL;
@@ -368,7 +367,7 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
 
 	gvt_dbg_core("init gvt device\n");
 
-	idr_init(&gvt->vgpu_idr);
+	xa_init_flags(&gvt->vgpus, XA_FLAGS_ALLOC1);
 	spin_lock_init(&gvt->scheduler.mmio_context_lock);
 	mutex_init(&gvt->lock);
 	mutex_init(&gvt->sched_lock);
@@ -462,7 +461,6 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
 out_clean_mmio_info:
 	intel_gvt_clean_mmio_info(gvt);
 out_clean_idr:
-	idr_destroy(&gvt->vgpu_idr);
 	kfree(gvt);
 	return ret;
 }
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index ffb181a086be..843d199dc82a 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -314,7 +314,7 @@ struct intel_gvt {
 	struct mutex sched_lock;
 
 	struct drm_i915_private *dev_priv;
-	struct idr vgpu_idr;	/* vGPU IDR pool */
+	struct xarray vgpus;	/* vGPU IDR pool */
 
 	struct intel_gvt_device_info device_info;
 	struct intel_gvt_gm gm;
@@ -458,8 +458,9 @@ void intel_vgpu_write_fence(struct intel_vgpu *vgpu,
 #define vgpu_sreg(vgpu, offset) \
 	(*(u32 *)(vgpu->mmio.sreg + (offset)))
 
+/* Can this use an XArray mark instead? */
 #define for_each_active_vgpu(gvt, vgpu, id) \
-	idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) \
+	xa_for_each((&(gvt)->vgpus), (id), (vgpu)) \
 		for_each_if(vgpu->active)
 
 static inline void intel_vgpu_write_pci_bar(struct intel_vgpu *vgpu,
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index dd3dfd00f4e6..7f761879c14a 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1587,7 +1587,7 @@ static bool __kvmgt_vgpu_exist(struct intel_vgpu *vgpu, struct kvm *kvm)
 {
 	struct intel_vgpu *itr;
 	struct kvmgt_guest_info *info;
-	int id;
+	unsigned long id;
 	bool ret = false;
 
 	mutex_lock(&vgpu->gvt->lock);
diff --git a/drivers/gpu/drm/i915/gvt/sched_policy.c b/drivers/gpu/drm/i915/gvt/sched_policy.c
index c32e7d5e8629..f0223e0a1a23 100644
--- a/drivers/gpu/drm/i915/gvt/sched_policy.c
+++ b/drivers/gpu/drm/i915/gvt/sched_policy.c
@@ -334,7 +334,7 @@ static void tbs_sched_clean_vgpu(struct intel_vgpu *vgpu)
 	vgpu->sched_data = NULL;
 
 	/* this vgpu id has been removed */
-	if (idr_is_empty(&gvt->vgpu_idr))
+	if (xa_empty(&gvt->vgpus))
 		hrtimer_cancel(&sched_data->timer);
 }
 
diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index c1db9a6a1281..5dfdfa20331f 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -290,8 +290,8 @@ void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu)
 	mutex_unlock(&vgpu->vgpu_lock);
 
 	mutex_lock(&gvt->lock);
-	idr_remove(&gvt->vgpu_idr, vgpu->id);
-	if (idr_is_empty(&gvt->vgpu_idr))
+	xa_erase(&gvt->vgpus, vgpu->id);
+	if (xa_empty(&gvt->vgpus))
 		intel_gvt_clean_irq(gvt);
 	intel_gvt_update_vgpu_types(gvt);
 	mutex_unlock(&gvt->lock);
@@ -299,7 +299,8 @@ void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu)
 	vfree(vgpu);
 }
 
-#define IDLE_VGPU_IDR 0
+/* Don't change this without changing the XA_FLAGS_ALLOC1 initialisation */
+#define IDLE_VGPU_ID 0
 
 /**
  * intel_gvt_create_idle_vgpu - create an idle virtual GPU
@@ -320,7 +321,7 @@ struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt)
 	if (!vgpu)
 		return ERR_PTR(-ENOMEM);
 
-	vgpu->id = IDLE_VGPU_IDR;
+	vgpu->id = IDLE_VGPU_ID;
 	vgpu->gvt = gvt;
 	mutex_init(&vgpu->vgpu_lock);
 
@@ -370,12 +371,11 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
 	if (!vgpu)
 		return ERR_PTR(-ENOMEM);
 
-	ret = idr_alloc(&gvt->vgpu_idr, vgpu, IDLE_VGPU_IDR + 1, GVT_MAX_VGPU,
-		GFP_KERNEL);
+	ret = xa_alloc(&gvt->vgpus, &vgpu->id, vgpu,
+			XA_LIMIT(0, GVT_MAX_VGPU), GFP_KERNEL);
 	if (ret < 0)
 		goto out_free_vgpu;
 
-	vgpu->id = ret;
 	vgpu->handle = param->handle;
 	vgpu->gvt = gvt;
 	vgpu->sched_ctl.weight = param->weight;
@@ -388,7 +388,7 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
 
 	ret = intel_vgpu_init_mmio(vgpu);
 	if (ret)
-		goto out_clean_idr;
+		goto out_erase;
 
 	ret = intel_vgpu_alloc_resource(vgpu, param);
 	if (ret)
@@ -446,8 +446,8 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
 	intel_vgpu_free_resource(vgpu);
 out_clean_vgpu_mmio:
 	intel_vgpu_clean_mmio(vgpu);
-out_clean_idr:
-	idr_remove(&gvt->vgpu_idr, vgpu->id);
+out_erase:
+	xa_erase(&gvt->vgpus, vgpu->id);
 out_free_vgpu:
 	vfree(vgpu);
 	return ERR_PTR(ret);
