Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3623452imu; Mon, 28 Jan 2019 08:01:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN4EKp/GnN1WTthD21D6r2RBLG2oEx6743QDkuIJ6vXBSd2qjaFtJRFK6WjQeXD/271ezfJK X-Received: by 2002:a62:4641:: with SMTP id t62mr22179935pfa.141.1548691316264; Mon, 28 Jan 2019 08:01:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691316; cv=none; d=google.com; s=arc-20160816; b=lSysf9fTxOSg5p4lYb9vm2pXcJw5w+usyOllSZ6qYLRiEeeHfMKLliKIMe+8E35T68 FqluDTKax1Q+axQfe8v6f849+ds6tkXXY+hQRGbEJ09RHIfPjwcBnRWLB0no5GSGzixY wKOU0Pj+ninS42zn9+j5Mii8LvkSxFlrIP5rwACWaGhfyhlhFXe+8bWDbxF1Tu73D3vY Vs0lESvLBu3s2GFZG+RfiJ0Dk1bGN0udpawQpQ2gr9FVpiFx2RuhzQDpobIzKiYwadIT JZVHL3ZURyuUeu14wpMgoU60hw5DrVmB1oyblOKBQoVqUkQQ6aYVQJCDiA8SOfVtwLdH yIiQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=roc4S8sv/pfsomYKNQJnYKjOAX51TD0hDKRHFDqcOkg=; b=gQBtqnYcJJvvkR9VZcvsJY5GTSZ77fUHxW4fZd8UWKzaDlNhnRu1oh2lJo8Nvyc4Mr GFnQrNTlc++nPI3aKIgR6vscE81QESUpes1bP+VgYseYFhHq7KwvC0D93VNB/8bDl5Dv ZJrXzi3SdHuYPMiStqBoE4uNkdxfjFfUv2NdkR0vkikAyGF8wSGslnCAKXcBp5H+9mVI syPTAvMgmcP6ls8TCFit6gB4VGn6RUfsFE0Cv/sZyslo/yJJfPmfKKRwFjpRo22HFkbh xou9ZG1NRfRT4vWGxk5t7k6/Qr2f8zdu7cXkYvV+2tyEz3hMo6gHOW0slcV3rDrYkZ0b Rq7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dSP4NiJA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si33507336plp.114.2019.01.28.08.01.40; Mon, 28 Jan 2019 08:01:56 -0800 (PST) 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=dSP4NiJA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730091AbfA1P7x (ORCPT + 99 others); Mon, 28 Jan 2019 10:59:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:45160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730638AbfA1P7v (ORCPT ); Mon, 28 Jan 2019 10:59:51 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B2372175B; Mon, 28 Jan 2019 15:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691190; bh=1uMWs1PJfJtH4xyUfZyBSupDsuVE092Sz9H+aaRFgeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dSP4NiJAgH7Z7/NZIbWwHGqP09yIWgadE+RbOTGNDS9np2SwrKLfx7ydZzx9Sv8qv G7vgxlZkmYke2/0sYUy8hWOugyBITPA3jhwTLakVdOFu8IQ23cIzLt4fB7s0JVbBdZ HWkug4Qtht4dNB6/Lxh9gvLm3h1jqQqIDlYmlk0o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.19 009/258] gpu: ipu-v3: image-convert: Prevent race between run and unprepare Date: Mon, 28 Jan 2019 10:55:15 -0500 Message-Id: <20190128155924.51521-9-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steve Longerbeam [ Upstream commit 819bec35c8c9706185498c9222bd244e0781ad35 ] Prevent possible race by parallel threads between ipu_image_convert_run() and ipu_image_convert_unprepare(). This involves setting ctx->aborting to true unconditionally so that no new job runs can be queued during unprepare, and holding the ctx->aborting flag until the context is freed. Note that the "normal" ipu_image_convert_abort() case (e.g. not during context unprepare) should clear the ctx->aborting flag after aborting any active run and clearing the context's pending queue. This is because it should be possible to continue to use the conversion context and queue more runs after an abort. Signed-off-by: Steve Longerbeam Tested-by: Philipp Zabel Signed-off-by: Philipp Zabel Signed-off-by: Sasha Levin --- drivers/gpu/ipu-v3/ipu-image-convert.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-image-convert.c b/drivers/gpu/ipu-v3/ipu-image-convert.c index f4081962784c..91653adc41cc 100644 --- a/drivers/gpu/ipu-v3/ipu-image-convert.c +++ b/drivers/gpu/ipu-v3/ipu-image-convert.c @@ -1524,7 +1524,7 @@ int ipu_image_convert_queue(struct ipu_image_convert_run *run) EXPORT_SYMBOL_GPL(ipu_image_convert_queue); /* Abort any active or pending conversions for this context */ -void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx) +static void __ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx) { struct ipu_image_convert_chan *chan = ctx->chan; struct ipu_image_convert_priv *priv = chan->priv; @@ -1551,7 +1551,7 @@ void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx) need_abort = (run_count || active_run); - ctx->aborting = need_abort; + ctx->aborting = true; spin_unlock_irqrestore(&chan->irqlock, flags); @@ -1572,7 +1572,11 @@ void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx) dev_warn(priv->ipu->dev, "%s: timeout\n", __func__); force_abort(ctx); } +} +void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx) +{ + __ipu_image_convert_abort(ctx); ctx->aborting = false; } EXPORT_SYMBOL_GPL(ipu_image_convert_abort); @@ -1586,7 +1590,7 @@ void ipu_image_convert_unprepare(struct ipu_image_convert_ctx *ctx) bool put_res; /* make sure no runs are hanging around */ - ipu_image_convert_abort(ctx); + __ipu_image_convert_abort(ctx); dev_dbg(priv->ipu->dev, "%s: task %u: removing ctx %p\n", __func__, chan->ic_task, ctx); -- 2.19.1