From patchwork Tue Aug 27 20:12:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hurley X-Patchwork-Id: 2850305 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 753B49F271 for ; Tue, 27 Aug 2013 20:17:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7883520353 for ; Tue, 27 Aug 2013 20:17:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 820C5202EA for ; Tue, 27 Aug 2013 20:17:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6E990E76A1 for ; Tue, 27 Aug 2013 13:17:49 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout02.c08.mtsvc.net (mailout02.c08.mtsvc.net [205.186.168.190]) by gabe.freedesktop.org (Postfix) with ESMTP id 92644E767C for ; Tue, 27 Aug 2013 13:13:42 -0700 (PDT) Received: from n18.c08.mtsvc.net ([205.186.176.18]) by mailout02.c08.mtsvc.net with esmtp (Exim 4.72) (envelope-from ) id 1VEPdy-0001sB-G5; Tue, 27 Aug 2013 13:13:38 -0700 Received: from 68-184-16-174.dhcp.unas.ma.charter.com ([68.184.16.174]:56256 helo=thor.lan) by n18.c08.mtsvc.net with esmtpsa (TLS1.1:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80.1) (envelope-from ) id 1VEPdv-0001XP-Lw; Tue, 27 Aug 2013 13:13:38 -0700 From: Peter Hurley To: Dave Airlie , Ben Skeggs Subject: [PATCH 3/9] drm/nouveau: Allocate local event handlers Date: Tue, 27 Aug 2013 16:12:56 -0400 Message-Id: <1377634382-13872-4-git-send-email-peter@hurleysoftware.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1377634382-13872-1-git-send-email-peter@hurleysoftware.com> References: <1377634382-13872-1-git-send-email-peter@hurleysoftware.com> X-Authenticated-User: 125194 peter@hurleysoftware.com X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Level: Cc: nouveau@lists.freedesktop.org, Peter Hurley , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prepare for transition to RCU-based event handler list; since RCU list traversal may have stale pointers, local storage may go out of scope before handler completes. Introduce nouveau_event_handler_create/_destroy which provides suitable semantics for multiple, temporary event handlers. Signed-off-by: Peter Hurley --- drivers/gpu/drm/nouveau/core/core/event.c | 24 +++++++++++++++++++++++ drivers/gpu/drm/nouveau/core/include/core/event.h | 6 ++++++ drivers/gpu/drm/nouveau/nouveau_fence.c | 15 +++++++------- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/nouveau/core/core/event.c b/drivers/gpu/drm/nouveau/core/core/event.c index e69c463..1a8d685 100644 --- a/drivers/gpu/drm/nouveau/core/core/event.c +++ b/drivers/gpu/drm/nouveau/core/core/event.c @@ -23,6 +23,30 @@ #include #include +int +nouveau_event_handler_create(struct nouveau_event *event, int index, + int (*func)(struct nouveau_eventh*, int), + void *priv, struct nouveau_eventh **phandler) +{ + struct nouveau_eventh *handler; + + handler = *phandler = kzalloc(sizeof(*handler), GFP_KERNEL); + if (!handler) + return -ENOMEM; + handler->func = func; + handler->priv = priv; + nouveau_event_get(event, index, handler); + return 0; +} + +void +nouveau_event_handler_destroy(struct nouveau_event *event, int index, + struct nouveau_eventh *handler) +{ + nouveau_event_put(event, index, handler); + kfree(handler); +} + static void nouveau_event_put_locked(struct nouveau_event *event, int index, struct nouveau_eventh *handler) diff --git a/drivers/gpu/drm/nouveau/core/include/core/event.h b/drivers/gpu/drm/nouveau/core/include/core/event.h index ad4d8c2..bdf1a0a 100644 --- a/drivers/gpu/drm/nouveau/core/include/core/event.h +++ b/drivers/gpu/drm/nouveau/core/include/core/event.h @@ -34,4 +34,10 @@ void nouveau_event_get(struct nouveau_event *, int index, void nouveau_event_put(struct nouveau_event *, int index, struct nouveau_eventh *); +int nouveau_event_handler_create(struct nouveau_event *, int index, + int (*func)(struct nouveau_eventh*, int), + void *priv, struct nouveau_eventh **); +void nouveau_event_handler_destroy(struct nouveau_event *, int index, + struct nouveau_eventh *); + #endif diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c index c2e3167..6dde483 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c @@ -180,13 +180,14 @@ nouveau_fence_wait_uevent(struct nouveau_fence *fence, bool intr) struct nouveau_channel *chan = fence->channel; struct nouveau_fifo *pfifo = nouveau_fifo(chan->drm->device); struct nouveau_fence_priv *priv = chan->drm->fence; - struct nouveau_eventh handler = { - .func = nouveau_fence_wait_uevent_handler, - .priv = priv, - }; - int ret = 0; + struct nouveau_eventh *handler; + int ret; - nouveau_event_get(pfifo->uevent, 0, &handler); + ret = nouveau_event_handler_create(pfifo->uevent, 0, + nouveau_fence_wait_uevent_handler, + priv, &handler); + if (ret) + return ret; if (fence->timeout) { unsigned long timeout = fence->timeout - jiffies; @@ -218,7 +219,7 @@ nouveau_fence_wait_uevent(struct nouveau_fence *fence, bool intr) } } - nouveau_event_put(pfifo->uevent, 0, &handler); + nouveau_event_handler_destroy(pfifo->uevent, 0, handler); if (unlikely(ret < 0)) return ret;