Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2774419ybg; Mon, 28 Oct 2019 02:07:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN/3Ps+jWBuveSh8Z9dWlfy5XVXK5IxH7L+042hG+2qDckKdPo7SXDOqE4zdfEQOj1I/ZP X-Received: by 2002:a50:9fc1:: with SMTP id c59mr18737359edf.305.1572253625421; Mon, 28 Oct 2019 02:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572253625; cv=none; d=google.com; s=arc-20160816; b=UCOYZ/B/92rtyl8lMark8KWsh+IPuvq1S+/1oXlhOZaYUDVY5hN/+UDhP1KJRC9bLz XCieqXhYpKR/BXX5thINBOqO8jYtAI11f4EMOZI5SnhXXcBG4aFl2zmjgrdDJr96Z4z7 ps/32uq23pN2vw9yWhZamTjSvLQLz/Vb0FdykNrxH44FuglfKuRhfbLrRrd4YO7XzuZb wGHVPau3ukwbGEyCivkA7Z9LdQAK4xQ2jqP6Z+rX/VZWhMNUUmCW86h17iCtTdaq7EY3 DKjJCcLNODNGtuzc7XxQRA6z6KS24P808L8Dmppcp0T2Pvy1Unu2leCAOZlHKxl5h2mN ynhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rtuptaWbCRj22I96CBMFmw/AuTA6hXpQhtOZ7SXHdp0=; b=THdpmtx3KFuX5JA330v3m4BpTEsN4Yx7dolNz40NSYnKHMAan2SPe9Zw086dBRx49E /CJxunUMhVMAI0PSbYSr+ovV3fNCvhykoJfPI6v3D+/DGE2+YOBRW+Y0dpiCzNCV+org IVXDQ6JfOPVovy+1As8PDH/zhkOI/AVg6hL8koCEyEd6hbueT71vSjGUDYVHKwE4Xp0L xy47SG/Kt8Qda0OsIVRZjuaIuBpJCZZPI15vj5jBMKLBVnvpE+GTeedVO5Lx6m823/pW T3hg5iRp786FCbh7YNnNKjzasWrmQ/pGI7xvbijckKRa2IXVpqbTEWi+ygiqVrmkTfWA BHKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yjis6Ax6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si5504108eje.331.2019.10.28.02.06.42; Mon, 28 Oct 2019 02:07:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yjis6Ax6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732250AbfJ0VWy (ORCPT + 99 others); Sun, 27 Oct 2019 17:22:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:43954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732245AbfJ0VWw (ORCPT ); Sun, 27 Oct 2019 17:22:52 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5D06F205C9; Sun, 27 Oct 2019 21:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211371; bh=d7BXlQMeshVMcQHLgh1CG8CHXyxlJSuwgcNotI58I5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yjis6Ax6qCzquvNJTrwXm4zHL2t1p8NXeGB7TcdoxtdSUidu85Zl3viI6Fh3S9Lnj jO7dJTjmdOEtbEtmm89TfUYu+RRhTvrjm30f3e+lz/GY8UE7qUeAxh2ZTUyk7d8DiS daidl9dg5UqR61F+sB0/0ogQCrzyjyOQffIgDZIc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Neil Armstrong , Steven Price , Rob Herring Subject: [PATCH 5.3 126/197] drm/panfrost: Handle resetting on timeout better Date: Sun, 27 Oct 2019 22:00:44 +0100 Message-Id: <20191027203358.534250985@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Price commit 5b3ec8134f5f9fa1ed0a538441a495521078bbee upstream. Panfrost uses multiple schedulers (one for each slot, so 2 in reality), and on a timeout has to stop all the schedulers to safely perform a reset. However more than one scheduler can trigger a timeout at the same time. This race condition results in jobs being freed while they are still in use. When stopping other slots use cancel_delayed_work_sync() to ensure that any timeout started for that slot has completed. Also use mutex_trylock() to obtain reset_lock. This means that only one thread attempts the reset, the other threads will simply complete without doing anything (the first thread will wait for this in the call to cancel_delayed_work_sync()). While we're here and since the function is already dependent on sched_job not being NULL, let's remove the unnecessary checks. Fixes: aa20236784ab ("drm/panfrost: Prevent concurrent resets") Tested-by: Neil Armstrong Signed-off-by: Steven Price Cc: stable@vger.kernel.org Signed-off-by: Rob Herring Link: https://patchwork.freedesktop.org/patch/msgid/20191009094456.9704-1-steven.price@arm.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/panfrost/panfrost_job.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -384,13 +384,19 @@ static void panfrost_job_timedout(struct job_read(pfdev, JS_TAIL_LO(js)), sched_job); - mutex_lock(&pfdev->reset_lock); + if (!mutex_trylock(&pfdev->reset_lock)) + return; - for (i = 0; i < NUM_JOB_SLOTS; i++) - drm_sched_stop(&pfdev->js->queue[i].sched, sched_job); + for (i = 0; i < NUM_JOB_SLOTS; i++) { + struct drm_gpu_scheduler *sched = &pfdev->js->queue[i].sched; - if (sched_job) - drm_sched_increase_karma(sched_job); + drm_sched_stop(sched, sched_job); + if (js != i) + /* Ensure any timeouts on other slots have finished */ + cancel_delayed_work_sync(&sched->work_tdr); + } + + drm_sched_increase_karma(sched_job); /* panfrost_core_dump(pfdev); */