From patchwork Fri Jun 24 09:08:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9197049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A493C60754 for ; Fri, 24 Jun 2016 09:11:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9317A2846F for ; Fri, 24 Jun 2016 09:11:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 872E52849B; Fri, 24 Jun 2016 09:11:42 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085602846F for ; Fri, 24 Jun 2016 09:11:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 365F06E100; Fri, 24 Jun 2016 09:11:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id BB4C56E2F6 for ; Fri, 24 Jun 2016 09:09:44 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id r201so3347571wme.0 for ; Fri, 24 Jun 2016 02:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=o20ptkQu1HaEPMbzhQvUXFNc+odqJOX7L9RTmY7SdWA=; b=RqA9CYMX8nuuNdnWfDF26pci0Ne/hwvB0pGam5jIhmqpbaD02kbILLmbxxnrEvg+nt SsRGHwwAb7Qd4UOWC09HZnioben5PQqZUVisloyTqfdjl7jPznZBTakO7+OMuFePBcx6 8ZGJGWeCRAvS99mxWooDumaTZ0l78S09nNK98+vEaKj8z1e4RtTu0UVgjDg1H6sUw+/j 2F1i5irs4L5VOmiPuCZcSEP0hNmqzkiXzikJNh8tnMPjajVFDHNFm6bZEwZP74uEY8KS TUV1omwBk+Ab76CwmA2BpAmI7vXIT0bQWV5zDh8OSiF8RV+5KCPWPHkBjaw4MRwRM53t XrrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=o20ptkQu1HaEPMbzhQvUXFNc+odqJOX7L9RTmY7SdWA=; b=MZXqFHfB2Asusjjwg9qpdKr0Wt7ig+S1KQnT7tLjMir7BM3/VPSyGGqQoSky8GS8Dq Pn4p5rxHKcx8QmdY8BD0767kEqsPmUyLSc8affwkdNg97tiGk4dzFhQKQPJ/i8movnON VWKgzzACJubMuniwmJoNzMPh4rL4Y6ziHkAvxsu5TsxT/c6owPEs5vRdhVmLI41+//q9 1mI7TBJ0X1FF1CfpJCph+dFBrzQVAksuAXr33gODPD+CLjA/QriZjHeVIwCCo6z2X02c HZrjr7O+l3EEJQRXSkOWV6VhFEXIL6ylsbo1XEXp/JOEQgJss/obllBHQmSIS3B81otx eA3w== X-Gm-Message-State: ALyK8tKCXQPqCfiuF5eOuu6S2IibWTr1qzszOe+tla0SjFpAD5wE6ImxeAasxwDOY8Cjog== X-Received: by 10.28.46.147 with SMTP id u141mr17603339wmu.74.1466759383016; Fri, 24 Jun 2016 02:09:43 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id x194sm2123900wmf.13.2016.06.24.02.09.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jun 2016 02:09:42 -0700 (PDT) From: Chris Wilson To: linux-kernel@vger.kernel.org Subject: [PATCH 4/9] async: Extend kfences for listening on DMA fences Date: Fri, 24 Jun 2016 10:08:48 +0100 Message-Id: <1466759333-4703-5-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466759333-4703-1-git-send-email-chris@chris-wilson.co.uk> References: <1466759333-4703-1-git-send-email-chris@chris-wilson.co.uk> Cc: "Peter Zijlstra \(Intel\)" , Daniel Vetter , Rasmus Villemoes , dri-devel@lists.freedesktop.org, Alexander Potapenko , Ingo Molnar , Davidlohr Bueso , Shuah Khan , Andrey Ryabinin , "Paul E. McKenney" , linux-media@vger.kernel.org, Kees Cook , Nikolay Aleksandrov , linaro-mm-sig@lists.linaro.org, Dan Williams , Andy Shevchenko , Dmitry Vyukov , Thomas Gleixner , Tejun Heo , Andrew Morton , "David S. Miller" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP dma-buf provides an interfaces for receiving notifications from DMA hardware. kfence provides a useful interface for collecting such fences and combining them with other events. Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: Shuah Khan Cc: Tejun Heo Cc: Daniel Vetter Cc: Andrew Morton Cc: Ingo Molnar Cc: Kees Cook Cc: Thomas Gleixner Cc: "Paul E. McKenney" Cc: Dan Williams Cc: Andrey Ryabinin Cc: Davidlohr Bueso Cc: Nikolay Aleksandrov Cc: "David S. Miller" Cc: "Peter Zijlstra (Intel)" Cc: Rasmus Villemoes Cc: Andy Shevchenko Cc: Dmitry Vyukov Cc: Alexander Potapenko Cc: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org --- include/linux/kfence.h | 4 ++++ kernel/async.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/include/linux/kfence.h b/include/linux/kfence.h index 82096bfafaa1..d71f30c626ae 100644 --- a/include/linux/kfence.h +++ b/include/linux/kfence.h @@ -15,6 +15,7 @@ #include struct completion; +struct fence; struct kfence { wait_queue_head_t wait; @@ -29,6 +30,9 @@ extern int kfence_add(struct kfence *fence, struct kfence *after, gfp_t gfp); extern int kfence_add_completion(struct kfence *fence, struct completion *x, gfp_t gfp); +extern int kfence_add_dma(struct kfence *fence, + struct fence *dma, + gfp_t gfp); extern void kfence_pending(struct kfence *fence); extern void kfence_signal(struct kfence *fence); extern void kfence_wait(struct kfence *fence); diff --git a/kernel/async.c b/kernel/async.c index db22b890711e..01552d23a916 100644 --- a/kernel/async.c +++ b/kernel/async.c @@ -50,6 +50,7 @@ asynchronous and synchronous parts of the kernel. #include #include +#include #include #include #include @@ -122,9 +123,10 @@ static atomic_t entry_count; * allowing multiple pending / signals to be sent before the kfence is * complete. * - * kfence_add() / kfence_add_completion() + * kfence_add() / kfence_add_completion() / kfence_add_dma() * - * sets the kfence to wait upon another fence, or completion respectively. + * sets the kfence to wait upon another fence, completion, or DMA fence + * respectively. * * Unlike completions, kfences are expected to live inside more complex graphs * and form the basis for parallel execution of interdependent and so are @@ -484,6 +486,63 @@ int kfence_add_completion(struct kfence *fence, struct completion *x, gfp_t gfp) } EXPORT_SYMBOL_GPL(kfence_add_completion); +struct dma_fence_cb { + struct fence_cb base; + struct kfence *fence; +}; + +static void dma_kfence_wake(struct fence *dma, struct fence_cb *data) +{ + struct dma_fence_cb *cb = container_of(data, typeof(*cb), base); + kfence_signal(cb->fence); + kfence_put(cb->fence); + kfree(cb); +} + +/** + * kfence_add_dma - set the fence to wait upon a DMA fence + * @fence: this kfence + * @dma: target DMA fence to wait upon + * @gfp: the allowed allocation type + * + * kfence_add_dma() causes the @fence to wait upon completion of a DMA fence. + * + * Returns 1 if the @fence was successfully to the waitqueue of @dma, 0 + * if @dma was already signaled (and so not added), or a negative error code. + */ +int kfence_add_dma(struct kfence *fence, struct fence *dma, gfp_t gfp) +{ + struct dma_fence_cb *cb; + int ret; + + if (!dma || fence_is_signaled(dma)) + return 0; + + cb = kmalloc(sizeof(*cb), gfp); + if (!cb) { + if (!gfpflags_allow_blocking(gfp)) + return -ENOMEM; + + return fence_wait(dma, false); + } + + cb->fence = kfence_get(fence); + kfence_pending(fence); + + ret = fence_add_callback(dma, &cb->base, dma_kfence_wake); + if (ret == 0) { + /* signal fence add and is pending */ + ret = 1; + } else { + dma_kfence_wake(dma, &cb->base); + if (ret == -ENOENT) /* fence already signaled */ + ret = 0; + } + + return ret; +} +EXPORT_SYMBOL_GPL(kfence_add_dma); + static async_cookie_t lowest_in_progress(struct async_domain *domain) { struct list_head *pending;