Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp116257pxf; Wed, 7 Apr 2021 22:01:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycgybB7b4j3tBebr9zK4PGRnazqz7+znfRN3HfILAtXK+JbTizqX31oQvsNOIr55DHcOa5 X-Received: by 2002:a17:906:94d2:: with SMTP id d18mr163488ejy.531.1617858095836; Wed, 07 Apr 2021 22:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617858095; cv=none; d=google.com; s=arc-20160816; b=ADx5piKz9gfX9yNUiPjrjWpi+oWd+d3MS8bFT5VrzO9QUCf/a7n/v4TIm94hyht3s3 eSCkUh7cacSLDE5Bjnm2D0X7LNgzc7QelhFWMCabJzm0Zt+fAkiVGBQh5QS4cM+Nstw1 xDFokGE59LqJ4fyukJXJAqOCG4zL7chSMhU3tsADv2uCorwC/kA0e/uJgGNH3nJUUdKe ad0C41N7n85hEr1cnK1s2Wdsf6b2VTK9fafw0KVAK8pKlPV5GvSbhu/6qYLpSBimKIvp rpIvXOqGHEH7g1jfCvmVbE+TOJRO59aYnfx2TF6Fef7s4nsibYpqjx85wvsQaYAULCvx 6/xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yAhu6CqdAQ+BdgBQcTHerGRp4ijsbWysCLX6FzCbuNw=; b=mcuA7i81pfpALGvisUQcr6kc51CC18M4DmUMZ+cqi482FZs1wE5set7wtWQIMw7Hnt OhPfUqgTVx9tpr4SffG61ZCwisUibPO6X8Zn+HvS68hyt+DEe2Jkaj0vpRkmqZOqe6pG iFznKfk2QuAfUb0wt/IBbXPya+dbzn0qVMa7V84XInXYeQdEYwn4hjmPVlB3seQdmfSM qVBS/HAymrdzqpQ6RKKo3JcvVrHF/KyTlKsqriP/MxAK7KNP8+98wqNGnbZ6hu63s+6p HG7sSgQqhq8DtGDnQdnnFo4mNi+qIp63kZEQhbGLyEIpRIqo7diALefLmETa43g6wzs+ 1BOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ADhdKz4S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x14si9847206ejw.262.2021.04.07.22.01.12; Wed, 07 Apr 2021 22:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ADhdKz4S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229579AbhDHFAf (ORCPT + 99 others); Thu, 8 Apr 2021 01:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbhDHFAf (ORCPT ); Thu, 8 Apr 2021 01:00:35 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C304C061761 for ; Wed, 7 Apr 2021 22:00:24 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id h25so533566pgm.3 for ; Wed, 07 Apr 2021 22:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yAhu6CqdAQ+BdgBQcTHerGRp4ijsbWysCLX6FzCbuNw=; b=ADhdKz4Sx9y75de5EanjHhDJY5wMx53a0RBpg55jv4x21G0Bt/bR3dpLd2DEUyprKN aZTY3tjatR+vD34kAUTWc6yMHUc39U9snLdbdNI/3JtD+Z9ZET5Fd7TK+FvfWZuMbqm9 dp4d2H6TcXRdMqXoBY9SeW4EJDR6lFDEnS1ls= 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:mime-version :content-transfer-encoding; bh=yAhu6CqdAQ+BdgBQcTHerGRp4ijsbWysCLX6FzCbuNw=; b=LVKulHduInJtA1Fsl+0ahtfMR/x05gIqVeRGsB49Sk1xQZBjrkUaxHmn25eohrQZ3u 4fBVfmYDlsJ7f0GI/qro84+H7nZkSDBpUgz0/neLSF+Z9uAT04tnWRbv4nd7i9H2afIU N6M6q8o6z2GkcG9vmEIdJ4+gm2erY6SDuYQx+d6Gcc6f5M8/MtBfcxQJRUXcvPr2u9hN Fe7ARpJHn6iSSkIcd6pbo1jUgVgC8ssctDMupNyZoOznW43qdn1Xj1UTJpQucTqD7UfC Kt6zuCCFAxJ8U1VXMkN7suwZ/Cm/tZyUY42CwMUyg/XULrXXAPL+3S+1OtgyXybbndYP 4o/w== X-Gm-Message-State: AOAM531peOc/hCy9o9efhDcbJZ5acTB4EYp+2B0531ToaX9q8KTkeWkx Lo8F2LE3ld6MC7QjI0+s7Z756Q== X-Received: by 2002:a65:5c88:: with SMTP id a8mr6238482pgt.130.1617858024006; Wed, 07 Apr 2021 22:00:24 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:25d8:8458:73e8:75ac]) by smtp.gmail.com with UTF8SMTPSA id w67sm23753647pgb.87.2021.04.07.22.00.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Apr 2021 22:00:23 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Sumit Semwal , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, David Stevens Subject: [PATCH] Revert "drm/syncobj: use dma_fence_get_stub" Date: Thu, 8 Apr 2021 13:59:26 +0900 Message-Id: <20210408045926.3202160-1-stevensd@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Stevens This reverts commit 86bbd89d5da66fe760049ad3f04adc407ec0c4d6. Using the singleton stub fence in drm_syncobj_assign_null_handle means that all syncobjs created in an already signaled state or any syncobjs signaled by userspace will reference the singleton fence when exported to a sync_file. If those sync_files are queried with SYNC_IOC_FILE_INFO, then the timestamp_ns value returned will correspond to whenever the singleton stub fence was first initialized. This can break the ability of userspace to use timestamps of these fences, as the singleton stub fence's timestamp bears no relationship to any meaningful event. Signed-off-by: David Stevens --- drivers/gpu/drm/drm_syncobj.c | 58 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 349146049849..7cc11f1a83f4 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -211,6 +211,21 @@ struct syncobj_wait_entry { static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj, struct syncobj_wait_entry *wait); +struct drm_syncobj_stub_fence { + struct dma_fence base; + spinlock_t lock; +}; + +static const char *drm_syncobj_stub_fence_get_name(struct dma_fence *fence) +{ + return "syncobjstub"; +} + +static const struct dma_fence_ops drm_syncobj_stub_fence_ops = { + .get_driver_name = drm_syncobj_stub_fence_get_name, + .get_timeline_name = drm_syncobj_stub_fence_get_name, +}; + /** * drm_syncobj_find - lookup and reference a sync object. * @file_private: drm file private pointer @@ -344,18 +359,24 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, } EXPORT_SYMBOL(drm_syncobj_replace_fence); -/** - * drm_syncobj_assign_null_handle - assign a stub fence to the sync object - * @syncobj: sync object to assign the fence on - * - * Assign a already signaled stub fence to the sync object. - */ -static void drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) +static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) { - struct dma_fence *fence = dma_fence_get_stub(); + struct drm_syncobj_stub_fence *fence; - drm_syncobj_replace_fence(syncobj, fence); - dma_fence_put(fence); + fence = kzalloc(sizeof(*fence), GFP_KERNEL); + if (fence == NULL) + return -ENOMEM; + + spin_lock_init(&fence->lock); + dma_fence_init(&fence->base, &drm_syncobj_stub_fence_ops, + &fence->lock, 0, 0); + dma_fence_signal(&fence->base); + + drm_syncobj_replace_fence(syncobj, &fence->base); + + dma_fence_put(&fence->base); + + return 0; } /* 5s default for wait submission */ @@ -469,6 +490,7 @@ EXPORT_SYMBOL(drm_syncobj_free); int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, struct dma_fence *fence) { + int ret; struct drm_syncobj *syncobj; syncobj = kzalloc(sizeof(struct drm_syncobj), GFP_KERNEL); @@ -479,8 +501,13 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock); - if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) - drm_syncobj_assign_null_handle(syncobj); + if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { + ret = drm_syncobj_assign_null_handle(syncobj); + if (ret < 0) { + drm_syncobj_put(syncobj); + return ret; + } + } if (fence) drm_syncobj_replace_fence(syncobj, fence); @@ -1322,8 +1349,11 @@ drm_syncobj_signal_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_assign_null_handle(syncobjs[i]); + for (i = 0; i < args->count_handles; i++) { + ret = drm_syncobj_assign_null_handle(syncobjs[i]); + if (ret < 0) + break; + } drm_syncobj_array_free(syncobjs, args->count_handles); -- 2.31.0.208.g409f899ff0-goog