From patchwork Fri Mar 1 14:03:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10835407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 233C5922 for ; Fri, 1 Mar 2019 14:05:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1194C2DFC8 for ; Fri, 1 Mar 2019 14:05:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05C952F18F; Fri, 1 Mar 2019 14:05:01 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 80ECF2DFC8 for ; Fri, 1 Mar 2019 14:05:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D9BC6E320; Fri, 1 Mar 2019 14:04:51 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id D683C6E314 for ; Fri, 1 Mar 2019 14:04:48 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 15744255-1500050 for multiple; Fri, 01 Mar 2019 14:04:20 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 1 Mar 2019 14:03:46 +0000 Message-Id: <20190301140404.26690-20-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190301140404.26690-1-chris@chris-wilson.co.uk> References: <20190301140404.26690-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 20/38] drm/i915: Allow userspace to clone contexts on creation X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP A usecase arose out of handling context recovery in mesa, whereby they wish to recreate a context with fresh logical state but preserving all other details of the original. Currently, they create a new context and iterate over which bits they want to copy across, but it would much more convenient if they were able to just pass in a target context to clone during creation. This essentially extends the setparam during creation to pull the details from a target context instead of the user supplied parameters. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_gem_context.c | 71 +++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 14 +++++ 2 files changed, 85 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index d8e2228636ba..48fb2ffb5f8c 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -1456,8 +1456,79 @@ static int create_setparam(struct i915_user_extension __user *ext, void *data) return ctx_setparam(data, &local.setparam); } +static void clone_sseu(struct i915_gem_context *dst, + struct i915_gem_context *src) +{ + const struct intel_sseu default_sseu = + intel_device_default_sseu(dst->i915); + struct intel_engine_cs *engine; + enum intel_engine_id id; + + for_each_engine(engine, dst->i915, id) { + struct intel_context *ce; + struct intel_sseu sseu; + + ce = to_intel_context(src, engine); + if (!ce) + continue; + + sseu = ce->sseu; + if (!memcmp(&sseu, &default_sseu, sizeof(sseu))) + continue; + + ce = to_intel_context(dst, engine); + ce->sseu = sseu; + } +} + +static int create_clone(struct i915_user_extension __user *ext, void *data) +{ + struct drm_i915_gem_context_create_ext_clone local; + struct i915_gem_context *dst = data; + struct i915_gem_context *src; + + if (copy_from_user(&local, ext, sizeof(local))) + return -EFAULT; + + if (local.flags & I915_CONTEXT_CLONE_UNKNOWN) + return -EINVAL; + + if (local.rsvd) + return -EINVAL; + + rcu_read_lock(); + src = __i915_gem_context_lookup_rcu(dst->file_priv, local.clone); + rcu_read_unlock(); + if (!src) + return -ENOENT; + + if (local.flags & I915_CONTEXT_CLONE_FLAGS) + dst->user_flags = src->user_flags; + + if (local.flags & I915_CONTEXT_CLONE_SCHED) + dst->sched = src->sched; + + if (local.flags & I915_CONTEXT_CLONE_SSEU) + clone_sseu(dst, src); + + if (local.flags & I915_CONTEXT_CLONE_TIMELINE && src->timeline) { + if (dst->timeline) + i915_timeline_put(dst->timeline); + dst->timeline = i915_timeline_get(src->timeline); + } + + if (local.flags & I915_CONTEXT_CLONE_VM && src->ppgtt) { + if (dst->ppgtt) + i915_ppgtt_put(dst->ppgtt); + dst->ppgtt = i915_ppgtt_get(src->ppgtt); + } + + return 0; +} + static const i915_user_extension_fn create_extensions[] = { [I915_CONTEXT_CREATE_EXT_SETPARAM] = create_setparam, + [I915_CONTEXT_CREATE_EXT_CLONE] = create_clone, }; static bool client_is_banned(struct drm_i915_file_private *file_priv) diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 451d2f36830b..60cbb2e4f140 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -1577,6 +1577,20 @@ struct drm_i915_gem_context_create_ext_setparam { struct drm_i915_gem_context_param setparam; }; +struct drm_i915_gem_context_create_ext_clone { +#define I915_CONTEXT_CREATE_EXT_CLONE 1 + struct i915_user_extension base; + __u32 clone; + __u32 flags; +#define I915_CONTEXT_CLONE_FLAGS (1u << 0) +#define I915_CONTEXT_CLONE_SCHED (1u << 1) +#define I915_CONTEXT_CLONE_SSEU (1u << 2) +#define I915_CONTEXT_CLONE_TIMELINE (1u << 3) +#define I915_CONTEXT_CLONE_VM (1u << 4) +#define I915_CONTEXT_CLONE_UNKNOWN -(I915_CONTEXT_CLONE_VM << 1) + __u64 rsvd; +}; + struct drm_i915_gem_context_destroy { __u32 ctx_id; __u32 pad;