From patchwork Thu Sep 2 09:11:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Ser X-Patchwork-Id: 12471075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAD6CC432BE for ; Thu, 2 Sep 2021 09:11:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5F9E960F90 for ; Thu, 2 Sep 2021 09:11:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5F9E960F90 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=emersion.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AE3F26E497; Thu, 2 Sep 2021 09:11:55 +0000 (UTC) Received: from mail-40136.protonmail.ch (mail-40136.protonmail.ch [185.70.40.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2EB036E497 for ; Thu, 2 Sep 2021 09:11:54 +0000 (UTC) Date: Thu, 02 Sep 2021 09:11:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail; t=1630573911; bh=IeKFquLOkYg8xBkDVgO6TgOkTaCu1dEVC4MZVq4Iehg=; h=Date:To:From:Cc:Reply-To:Subject:From; b=EnLOlea6mrfkReBiuHGYkthOpSorShO45AaS5qeDjyb6RI/K90yLSX8FSrDL1QMoL ralyKD+W/hTrxlma0EFmcK0hXjFSnHYEUfiLpDf3Ru0w8sLCgxMpAoDCkfTL16Yn/M LgQpEKHkReXKV4kkXHECkbfPO+GJrxJStiMB2+tI+Az1rhHWz1XutC3MOLvlbgSyKv Zd0b+kYN2lYdAbRTJaGI9BobUDFsppEr+XdV/uTcIAVFux+bspPpeF7tMlF1wwxLC1 Hv2d8QxGvtjVcz8uomZC4S3vBo4hLMR4sGSa+FzqkDd5b+8VHu36O9JjGwqHXbPDxD 5MXXkspY5vGdQ== To: dri-devel@lists.freedesktop.org From: Simon Ser Cc: Daniel Vetter , Daniel Stone , Pekka Paalanen , =?utf-8?q?Michel_D=C3=A4nz?= =?utf-8?q?er?= , Emil Velikov , Keith Packard , Boris Brezillon , Dave Airlie Subject: [PATCH] drm/lease: allow empty leases Message-ID: <20210902091126.2312-1-contact@emersion.fr> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Simon Ser Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This can be used to create a separate DRM file description, thus creating a new GEM handle namespace. See [1]. Example usage in wlroots is available at [2]. [1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110 [2]: https://github.com/swaywm/wlroots/pull/3158 Signed-off-by: Simon Ser Cc: Daniel Vetter Cc: Daniel Stone Cc: Pekka Paalanen Cc: Michel Dänzer Cc: Emil Velikov Cc: Keith Packard Cc: Boris Brezillon Cc: Dave Airlie --- drivers/gpu/drm/drm_lease.c | 39 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c index dee4f24a1808..d72c2fac0ff1 100644 --- a/drivers/gpu/drm/drm_lease.c +++ b/drivers/gpu/drm/drm_lease.c @@ -489,12 +489,6 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, if (!drm_core_check_feature(dev, DRIVER_MODESET)) return -EOPNOTSUPP; - /* need some objects */ - if (cl->object_count == 0) { - DRM_DEBUG_LEASE("no objects in lease\n"); - return -EINVAL; - } - if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) { DRM_DEBUG_LEASE("invalid flags\n"); return -EINVAL; @@ -510,23 +504,26 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, object_count = cl->object_count; - object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), - array_size(object_count, sizeof(__u32))); - if (IS_ERR(object_ids)) { - ret = PTR_ERR(object_ids); - goto out_lessor; - } - + /* Handle leased objects, if any */ idr_init(&leases); + if (object_count != 0) { + object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), + array_size(object_count, sizeof(__u32))); + if (IS_ERR(object_ids)) { + ret = PTR_ERR(object_ids); + idr_destroy(&leases); + goto out_lessor; + } - /* fill and validate the object idr */ - ret = fill_object_idr(dev, lessor_priv, &leases, - object_count, object_ids); - kfree(object_ids); - if (ret) { - DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret); - idr_destroy(&leases); - goto out_lessor; + /* fill and validate the object idr */ + ret = fill_object_idr(dev, lessor_priv, &leases, + object_count, object_ids); + kfree(object_ids); + if (ret) { + DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret); + idr_destroy(&leases); + goto out_lessor; + } } /* Allocate a file descriptor for the lease */