diff mbox series

[19/34] drm/i915: Convert spt_tree to XArray

Message ID 20190221184226.2149-39-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert DRM to XArray | expand

Commit Message

Matthew Wilcox Feb. 21, 2019, 6:41 p.m. UTC
A straightforward conversion.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/i915/gvt/gtt.c  | 18 ++++++++----------
 drivers/gpu/drm/i915/gvt/gtt.h  |  2 +-
 drivers/gpu/drm/i915/i915_drv.h |  1 +
 3 files changed, 10 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
index c7103dd2d8d5..4b8468839312 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -735,7 +735,7 @@  static void ppgtt_free_spt(struct intel_vgpu_ppgtt_spt *spt)
 	dma_unmap_page(kdev, spt->shadow_page.mfn << I915_GTT_PAGE_SHIFT, 4096,
 		       PCI_DMA_BIDIRECTIONAL);
 
-	radix_tree_delete(&spt->vgpu->gtt.spt_tree, spt->shadow_page.mfn);
+	xa_erase(&spt->vgpu->gtt.spts, spt->shadow_page.mfn);
 
 	if (spt->guest_page.gfn) {
 		if (spt->guest_page.oos_page)
@@ -751,11 +751,9 @@  static void ppgtt_free_spt(struct intel_vgpu_ppgtt_spt *spt)
 static void ppgtt_free_all_spt(struct intel_vgpu *vgpu)
 {
 	struct intel_vgpu_ppgtt_spt *spt;
-	struct radix_tree_iter iter;
-	void **slot;
+	unsigned long index;
 
-	radix_tree_for_each_slot(slot, &vgpu->gtt.spt_tree, &iter, 0) {
-		spt = radix_tree_deref_slot(slot);
+	xa_for_each(&vgpu->gtt.spts, index, spt) {
 		ppgtt_free_spt(spt);
 	}
 }
@@ -798,7 +796,7 @@  static struct intel_vgpu_ppgtt_spt *intel_vgpu_find_spt_by_gfn(
 static inline struct intel_vgpu_ppgtt_spt *intel_vgpu_find_spt_by_mfn(
 		struct intel_vgpu *vgpu, unsigned long mfn)
 {
-	return radix_tree_lookup(&vgpu->gtt.spt_tree, mfn);
+	return xa_load(&vgpu->gtt.spts, mfn);
 }
 
 static int reclaim_one_ppgtt_mm(struct intel_gvt *gvt);
@@ -840,13 +838,13 @@  static struct intel_vgpu_ppgtt_spt *ppgtt_alloc_spt(
 	spt->shadow_page.vaddr = page_address(spt->shadow_page.page);
 	spt->shadow_page.mfn = daddr >> I915_GTT_PAGE_SHIFT;
 
-	ret = radix_tree_insert(&vgpu->gtt.spt_tree, spt->shadow_page.mfn, spt);
-	if (ret)
+	if (xa_store(&vgpu->gtt.spts, spt->shadow_page.mfn, spt, GFP_KERNEL))
 		goto err_unmap_dma;
 
 	return spt;
 
 err_unmap_dma:
+	ret = -ENOMEM;
 	dma_unmap_page(kdev, daddr, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
 err_free_spt:
 	free_spt(spt);
@@ -2407,7 +2405,7 @@  int intel_vgpu_init_gtt(struct intel_vgpu *vgpu)
 {
 	struct intel_vgpu_gtt *gtt = &vgpu->gtt;
 
-	INIT_RADIX_TREE(&gtt->spt_tree, GFP_KERNEL);
+	xa_init(&gtt->spts);
 
 	INIT_LIST_HEAD(&gtt->ppgtt_mm_list_head);
 	INIT_LIST_HEAD(&gtt->oos_page_list_head);
@@ -2439,7 +2437,7 @@  static void intel_vgpu_destroy_all_ppgtt_mm(struct intel_vgpu *vgpu)
 	if (GEM_WARN_ON(!list_empty(&vgpu->gtt.ppgtt_mm_list_head)))
 		gvt_err("vgpu ppgtt mm is not fully destroyed\n");
 
-	if (GEM_WARN_ON(!radix_tree_empty(&vgpu->gtt.spt_tree))) {
+	if (GEM_WARN_ON(!xa_empty(&vgpu->gtt.spts))) {
 		gvt_err("Why we still has spt not freed?\n");
 		ppgtt_free_all_spt(vgpu);
 	}
diff --git a/drivers/gpu/drm/i915/gvt/gtt.h b/drivers/gpu/drm/i915/gvt/gtt.h
index d8cb04cc946d..b7a858aab356 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.h
+++ b/drivers/gpu/drm/i915/gvt/gtt.h
@@ -198,7 +198,7 @@  struct intel_vgpu_gtt {
 	struct intel_vgpu_mm *ggtt_mm;
 	unsigned long active_ppgtt_mm_bitmap;
 	struct list_head ppgtt_mm_list_head;
-	struct radix_tree_root spt_tree;
+	struct xarray spts;
 	struct list_head oos_page_list_head;
 	struct list_head post_shadow_list_head;
 	struct intel_vgpu_scratch_pt scratch_pt[GTT_TYPE_MAX];
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index b1c31967194b..4b5ce517cbcf 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -45,6 +45,7 @@ 
 #include <linux/pm_qos.h>
 #include <linux/reservation.h>
 #include <linux/shmem_fs.h>
+#include <linux/xarray.h>
 
 #include <drm/drmP.h>
 #include <drm/intel-gtt.h>