Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp628659imu; Fri, 11 Jan 2019 06:27:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN73YR6aYbkmuYQtMXhtsyZRgWQI+isOMF19sT0tNLVZck4JOohaWuAE2D2c9OxjofljwFVm X-Received: by 2002:a63:d818:: with SMTP id b24mr13257482pgh.174.1547216850194; Fri, 11 Jan 2019 06:27:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547216850; cv=none; d=google.com; s=arc-20160816; b=PUJfjw8kupZONZQcfm3L9PPKo5XYWAIIcl7JWrF+jmcMgWv0pznbEaks0hByKhfgtL SsR8caySIOFsChqFcqszf4SroX3W/LWQhFRdH6hnoee3g3UQ+OsZyWDy5Wv7b9eC5Ucg yfyVGGDnEwWGqX6Q+aN1gvdkK7CTt8WFuCBZjlcKw+5vKFwVVnFJDfs1oGKm9Kw20bZ7 D+M5LB0Mgi2sX/J3RFHQFGJx7MMC+QitA6jWCJtnILao3DT8PFPU02mj+HX1H623GZUa MO7t3qtkYsGVOwIHNjDzX3EVpni2ygSTgqPLpIeae5AJDLi76O7PtYs6/MtWRAgqdJlw oNIg== 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=9AdEAgFaCHRuNo7Q8SqWaAb6EqKP0qWHJpyIeIwAKGw=; b=ipmBm8PxDIJZwkhjYXfoPG4329tnl5sNjFGy1FZP4czhNf7sZx6yETdWz25lLvxCqS RZNXXIITbFm5mQLn3puAMbToIdDHVU7gfRVtvnKMzPYk21l8matlVIBdtX4d9TNQCv/n Jrg2KN9Q/RDNehtmpYpVWXhRyHd0bC0iN5pAT+qyP7+1T7BOufWmFRo6m3ZRXQKsPm2A eJeNmGZ2Cp18QshZ1+rBmHxyhswJwd1xeL/JhQxZq7hE2WL+aaYhqN0UDqhFO22sS81P DC54uavsIWW5bRfQHmeCMrvcUResz1cxkjb/X2mO0TuutOzEsCAjVg1OKuqW5MzJeYBF qA3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I6FqHEyG; 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 d15si3743433pgt.498.2019.01.11.06.27.15; Fri, 11 Jan 2019 06:27:30 -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=I6FqHEyG; 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 S1731943AbfAKOT3 (ORCPT + 99 others); Fri, 11 Jan 2019 09:19:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:36386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729359AbfAKOTZ (ORCPT ); Fri, 11 Jan 2019 09:19:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 96E1421783; Fri, 11 Jan 2019 14:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216365; bh=4stqkj2j/0Rl9oP6ZCWB6uVhGHEVfsFocRqvqhbK9PA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I6FqHEyGB7BQJ3Rc79I3iAu8Nm49xMw3RKVTZumjRQATZvayUAbbfcmCtUgc4bHHq Xzn0bSZNucls+JCl69xuh/CHA+tm4DgUa9fSFJpNLyIepW3CzOsQY3LGXBy+eJPHZo DRWsneS49aOHtn2CxC0LgHeZsh1EHyg/JcypM0P0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Mathias Duckeck , Frank Pavlic , Martin Sperl , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Mark Brown Subject: [PATCH 4.4 46/88] spi: bcm2835: Fix race on DMA termination Date: Fri, 11 Jan 2019 15:08:15 +0100 Message-Id: <20190111131052.955380354@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131045.137499039@linuxfoundation.org> References: <20190111131045.137499039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit e82b0b3828451c1cd331d9f304c6078fcd43b62e upstream. If a DMA transfer finishes orderly right when spi_transfer_one_message() determines that it has timed out, the callbacks bcm2835_spi_dma_done() and bcm2835_spi_handle_err() race to call dmaengine_terminate_all(), potentially leading to double termination. Prevent by atomically changing the dma_pending flag before calling dmaengine_terminate_all(). Signed-off-by: Lukas Wunner Fixes: 3ecd37edaa2a ("spi: bcm2835: enable dma modes for transfers meeting certain conditions") Cc: stable@vger.kernel.org # v4.2+ Cc: Mathias Duckeck Cc: Frank Pavlic Cc: Martin Sperl Cc: Noralf Trønnes Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-bcm2835.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -233,10 +233,9 @@ static void bcm2835_spi_dma_done(void *d * is called the tx-dma must have finished - can't get to this * situation otherwise... */ - dmaengine_terminate_all(master->dma_tx); - - /* mark as no longer pending */ - bs->dma_pending = 0; + if (cmpxchg(&bs->dma_pending, true, false)) { + dmaengine_terminate_all(master->dma_tx); + } /* and mark as completed */; complete(&master->xfer_completion); @@ -617,10 +616,9 @@ static void bcm2835_spi_handle_err(struc struct bcm2835_spi *bs = spi_master_get_devdata(master); /* if an error occurred and we have an active dma, then terminate */ - if (bs->dma_pending) { + if (cmpxchg(&bs->dma_pending, true, false)) { dmaengine_terminate_all(master->dma_tx); dmaengine_terminate_all(master->dma_rx); - bs->dma_pending = 0; } /* and reset */ bcm2835_spi_reset_hw(master);