From patchwork Fri Aug 25 17:52:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 9922599 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 E469D600C5 for ; Fri, 25 Aug 2017 17:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D293328426 for ; Fri, 25 Aug 2017 17:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C654A2842B; Fri, 25 Aug 2017 17:52:56 +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]) (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 7333828426 for ; Fri, 25 Aug 2017 17:52:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F3E836E8E9; Fri, 25 Aug 2017 17:52:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B91A6E8E9 for ; Fri, 25 Aug 2017 17:52:49 +0000 (UTC) Received: by mail-pg0-x244.google.com with SMTP id t3so643456pgt.5 for ; Fri, 25 Aug 2017 10:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fTc+spmwd5w5cKWsPHLy8AaB5lwktLMZI6sexwPYYsA=; b=re/6jR5DzTUdzoIrL+GRznfShyN15nVcMdwRxUMnwlfp2uD5cbpi65DpoBQ1KJ9Mb5 2nCKbC1+AxmwAijia6H/Grk/FfGgSPPUR5OrrHG7l0AJbxKgxJliIVxX+ydpyTeIyuFT ikBYZen9DuYSeb6Z4VGkwFYORvmSEMiz1CCPvd4k18uc81BTNIXWw64mr5JvZj4ynIZR FBUgRDpNZyt70L1roc7jaw+Yc07SFYPbmQGmYdA1naxgfWwFC2JuXp8V/9XPPjuRIH6n X++JNQJxTYHyeUtPWrQZk9v9aeWmd8rgwwJ5giHcjZs4/5a8+Zjvy+Zldy0rlqz1u3lo PNZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fTc+spmwd5w5cKWsPHLy8AaB5lwktLMZI6sexwPYYsA=; b=Gm2IbK3aHay4ec1VZnOswuDgbe7dtzhT6oCY/ZpMo3feN6G+VVxbMiC1z+ml46KJg8 e/WIZG2jqkAu9PEXOO3uhgeZYk5NLwXyJh5tI2KKMCMcwGjq0CpBBmzGS+Dyz1KhyclG Hqu8J1PVdamxys81yQ9ju1AeOFFazMRwSYaqvLbg6r8XQX+SIB3UWCQuHD88ULN6vGRx k54YjCZYezuWWg5vW1wlAGF5gqHAy36VUuuNlQ73Z0exyp9L2NQeFuPpAB/zN5+Q4BFt ISmTUH7OAlAJK7n5ud59tZzkCBpcmhZoyZVCh6ZBCmMv5uZdP/M9QODr0Jf6Lfz4zuK2 CiYg== X-Gm-Message-State: AHYfb5jyEC+ujSGntsdE1Jwu51faB9djekecGbRcjZLiI/gBWMrZb2Zb tEy9nvKe7LnHgXV622AQpw== X-Received: by 10.101.86.72 with SMTP id m8mr10398927pgs.94.1503683568584; Fri, 25 Aug 2017 10:52:48 -0700 (PDT) Received: from omlet.jlekstrand.net (static-50-43-41-117.bvtn.or.frontiernet.net. [50.43.41.117]) by smtp.gmail.com with ESMTPSA id z8sm11024919pgs.25.2017.08.25.10.52.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Aug 2017 10:52:47 -0700 (PDT) From: Jason Ekstrand X-Google-Original-From: Jason Ekstrand To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/10] drm/syncobj: Add a syncobj_array_find helper Date: Fri, 25 Aug 2017 10:52:26 -0700 Message-Id: <1503683548-23548-8-git-send-email-jason.ekstrand@intel.com> X-Mailer: git-send-email 2.5.0.400.gff86faf In-Reply-To: <1503683548-23548-1-git-send-email-jason.ekstrand@intel.com> References: <1503683548-23548-1-git-send-email-jason.ekstrand@intel.com> Cc: Jason Ekstrand , Jason Ekstrand 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 The wait ioctl has a bunch of code to read an syncobj handle array from userspace and turn it into an array of syncobj pointers. We're about to add two new IOCTLs which will need to work with arrays of syncobj handles so let's make some helpers. Signed-off-by: Jason Ekstrand --- drivers/gpu/drm/drm_syncobj.c | 89 ++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index cccd3bd..15e74ca 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -798,58 +798,43 @@ static int drm_syncobj_array_wait(struct drm_device *dev, return 0; } -int -drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, - struct drm_file *file_private) +static int drm_syncobj_array_find(struct drm_file *file_private, + void *user_handles, uint32_t count_handles, + struct drm_syncobj ***syncobjs_out) { - struct drm_syncobj_wait *args = data; - uint32_t *handles; + uint32_t i, *handles; struct drm_syncobj **syncobjs; - int ret = 0; - uint32_t i; - - if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) - return -ENODEV; - - if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | - DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT)) - return -EINVAL; - - if (args->count_handles == 0) - return -EINVAL; + int ret; - /* Get the handles from userspace */ - handles = kmalloc_array(args->count_handles, sizeof(uint32_t), - GFP_KERNEL); + handles = kmalloc_array(count_handles, sizeof(*handles), GFP_KERNEL); if (handles == NULL) return -ENOMEM; - if (copy_from_user(handles, - u64_to_user_ptr(args->handles), - sizeof(uint32_t) * args->count_handles)) { + if (copy_from_user(handles, user_handles, + sizeof(uint32_t) * count_handles)) { ret = -EFAULT; goto err_free_handles; } - syncobjs = kcalloc(args->count_handles, - sizeof(struct drm_syncobj *), GFP_KERNEL); - if (!syncobjs) { + syncobjs = kmalloc_array(count_handles, sizeof(*syncobjs), GFP_KERNEL); + if (syncobjs == NULL) { ret = -ENOMEM; goto err_free_handles; } - for (i = 0; i < args->count_handles; i++) { + for (i = 0; i < count_handles; i++) { syncobjs[i] = drm_syncobj_find(file_private, handles[i]); if (!syncobjs[i]) { ret = -ENOENT; - goto err_free_fence_array; + goto err_put_syncobjs; } } - ret = drm_syncobj_array_wait(dev, file_private, - args, syncobjs); + kfree(handles); + *syncobjs_out = syncobjs; + return 0; -err_free_fence_array: +err_put_syncobjs: while (i-- > 0) drm_syncobj_put(syncobjs[i]); kfree(syncobjs); @@ -858,3 +843,45 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, return ret; } + +static void drm_syncobj_array_free(struct drm_syncobj **syncobjs, + uint32_t count) +{ + uint32_t i; + for (i = 0; i < count; i++) + drm_syncobj_put(syncobjs[i]); + kfree(syncobjs); +} + +int +drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_private) +{ + struct drm_syncobj_wait *args = data; + struct drm_syncobj **syncobjs; + int ret = 0; + + if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) + return -ENODEV; + + if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT)) + return -EINVAL; + + if (args->count_handles == 0) + return -EINVAL; + + ret = drm_syncobj_array_find(file_private, + u64_to_user_ptr(args->handles), + args->count_handles, + &syncobjs); + if (ret < 0) + return ret; + + ret = drm_syncobj_array_wait(dev, file_private, + args, syncobjs); + + drm_syncobj_array_free(syncobjs, args->count_handles); + + return ret; +}