From mboxrd@z Thu Jan 1 00:00:00 1970 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=-4.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, HK_RANDOM_FROM,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 27FD3C33C99 for ; Tue, 7 Jan 2020 11:15:44 +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 03B78207E0 for ; Tue, 7 Jan 2020 11:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03B78207E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8215389DD2; Tue, 7 Jan 2020 11:15:43 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id B5E4589DD2 for ; Tue, 7 Jan 2020 11:15:42 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jan 2020 03:15:42 -0800 X-IronPort-AV: E=Sophos;i="5.69,406,1571727600"; d="scan'208";a="215516851" Received: from kumarjai-mobl1.ger.corp.intel.com (HELO [10.251.83.12]) ([10.251.83.12]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/AES256-SHA; 07 Jan 2020 03:15:41 -0800 To: Chris Wilson , intel-gfx@lists.freedesktop.org References: <20191222233558.2201901-1-chris@chris-wilson.co.uk> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc Message-ID: Date: Tue, 7 Jan 2020 11:15:39 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191222233558.2201901-1-chris@chris-wilson.co.uk> Content-Language: en-US Subject: Re: [Intel-gfx] [PATCH] drm/i915: Mark the GEM context link as RCU protected X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On 22/12/2019 23:35, Chris Wilson wrote: > The only protection for intel_context.gem_cotext is granted by RCU, so > annotate it as a rcu protected pointer and carefully dereference it in > the few occasions we need to use it. > > Fixes: 9f3ccd40acf4 ("drm/i915: Drop GEM context as a direct link from i915_request") > Signed-off-by: Chris Wilson > Cc: Andi Shyti > --- > drivers/gpu/drm/i915/gem/i915_gem_context.c | 5 ++- > drivers/gpu/drm/i915/gt/intel_context_types.h | 2 +- > drivers/gpu/drm/i915/gt/intel_reset.c | 26 +++++++++--- > .../gpu/drm/i915/gt/intel_ring_submission.c | 2 +- > drivers/gpu/drm/i915/i915_gpu_error.c | 40 ++++++++++++------- > drivers/gpu/drm/i915/i915_request.c | 6 +-- > drivers/gpu/drm/i915/i915_request.h | 8 ++++ > 7 files changed, 62 insertions(+), 27 deletions(-) > [snip] > > static void engine_record_requests(struct intel_engine_cs *engine, > @@ -1298,28 +1304,34 @@ static void error_record_engine_execlists(const struct intel_engine_cs *engine, > static bool record_context(struct drm_i915_error_context *e, > const struct i915_request *rq) > { > - const struct i915_gem_context *ctx = rq->context->gem_context; > + struct i915_gem_context *ctx; > + struct task_struct *task; > + bool capture; > > + rcu_read_lock(); > + ctx = rcu_dereference(rq->context->gem_context); > + if (ctx && !kref_get_unless_zero(&ctx->ref)) > + ctx = NULL; > + rcu_read_unlock(); > if (!ctx) > return false; > > - if (ctx->pid) { > - struct task_struct *task; > - > - rcu_read_lock(); > - task = pid_task(ctx->pid, PIDTYPE_PID); > - if (task) { > - strcpy(e->comm, task->comm); > - e->pid = task->pid; > - } > - rcu_read_unlock(); > + rcu_read_lock(); > + task = pid_task(ctx->pid, PIDTYPE_PID); > + if (task) { > + strcpy(e->comm, task->comm); > + e->pid = task->pid; > } > + rcu_read_unlock(); Why is this rcu_read_lock section needed? The first one obtained the reference to the context so should be good. Regards, Tvrtko _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx