From patchwork Thu Feb 21 18:42:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 10825427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CC7B139A for ; Fri, 22 Feb 2019 08:21:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C0EF31B16 for ; Fri, 22 Feb 2019 08:21:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6008231B21; Fri, 22 Feb 2019 08:21:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DFB3731B16 for ; Fri, 22 Feb 2019 08:21:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FDDE891D9; Fri, 22 Feb 2019 08:20:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by gabe.freedesktop.org (Postfix) with ESMTPS id 662B88915E for ; Thu, 21 Feb 2019 18:42:36 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIp-0000hK-TU; Thu, 21 Feb 2019 18:42:35 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 25/34] drm/i915: Convert vgpus_idr to XArray Date: Thu, 21 Feb 2019 10:42:07 -0800 Message-Id: <20190221184226.2149-48-willy@infradead.org> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190221184226.2149-1-willy@infradead.org> References: <20190221184226.2149-1-willy@infradead.org> X-Mailman-Approved-At: Fri, 22 Feb 2019 08:20:52 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=0xD+3CfCYcPCl+GO+p4+FVJHfF64kA7WSEar2RRypm4=; b=uRTE40kkXtN2rTriEHLKkWGB7 vY/Ym6ogIF7kCCDQZlhRmac1eQPo9HCKnnJcbnlRTcDb165c4f0RoMUrqThBwpIBzSxP1Np1RWE1F GiBubRxokVu9MwXF8ChLPyFj/bqHNF5e/6LHfyazoMa4siZNWKlajr497fo1LXPNikgE1qtRe95Cn 6BRkCkHEBlbvf8SL92ahr6pdn3C/j3toSVRX6gUOqHp60zsQD6GwjTYcA1G6T1/Y96pNx+gi2t3nu 1nyXcrAh34WvccCeMNQZXik0cEmw2mOMsepnPgGP0i56lk0LXryjQqLiUW+cLe4AkedNLjHI+/UHF BEaZH+h4w==; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthew Wilcox MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/i915/gvt/display.c | 5 +++-- drivers/gpu/drm/i915/gvt/gvt.c | 4 +--- drivers/gpu/drm/i915/gvt/gvt.h | 5 +++-- drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +- drivers/gpu/drm/i915/gvt/sched_policy.c | 2 +- drivers/gpu/drm/i915/gvt/vgpu.c | 20 ++++++++++---------- 6 files changed, 19 insertions(+), 19 deletions(-) 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);