Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp829508imu; Tue, 11 Dec 2018 08:12:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/US6RT8CQ91VGY1SgbZUzVxlmChg0OPliPHyzoc49GK6PAhh6kAEJtWkZiPxoOM6TaMIjZo X-Received: by 2002:a62:2fc3:: with SMTP id v186mr17009684pfv.82.1544544740612; Tue, 11 Dec 2018 08:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544544740; cv=none; d=google.com; s=arc-20160816; b=KqXn57SnGRhKoHxGSTn9css7k8H/KKUfZphAOtFpc2xcxyQhhB0HXCorDEEi0XD7uH eUMI3ozQr3lQLW+CPjcmxk9x4Aqj/GqWa6MFHKCxsZiplcOQ1QQOWkVmhj+XboI739Km oY6kzUxUP1ojALMhMe4KilXoLMQjnUayI1xVu0700QhU697msLD0wVn6B5xK7qZFC4Ky ApP8dM8k7Xc3Ts4VJxxHvNSc+LnOXH6r9rR/Z2RVx65sPsA98VNiu9BM1zKRpjETyQJ+ F96nZpfpfMxVQDXzE21NUHPvhX1hZP6OQ28AzfDR78TkO4K8QN5NEZwXiptPopBfLRJd hFvA== 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=Tbcgq176Zk1C+GwEEdvF3kP6wB3moDPaiRy/FYj41a8=; b=HkivGKY640Wlzj2qEf+nA44bO0N/IBswac0tqzqPvlj3VSbiq97Kw9gSlrR3lcjQrk Jh5XSTEzmKrQK0cVnQlg7M8WIqgB5dEdPP2GaLQNvyDiFe1h9EnL8MOMPafoZefzubUg GRYxkVM3WVcmy2KqPB3H9KHlrX74ykW43vvZzKU4Icy8G0sV8jR/u5NDoC+BvvyaV0vd HaSnm9CS1BehGDaOV968baD2eHXPZNgb+WfjVX3hZ6tSQsL5qukKJMl8lWVu/tTY9nLy Jd+mtj6PhGRvszzFsNy1ZlekfRmnPDYS12NWr0w+rC1g0Imqq+NexG8beeKsSYkfHdUX iKrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wj8MD1w9; 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 u202si12291925pgb.115.2018.12.11.08.12.05; Tue, 11 Dec 2018 08:12:20 -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=Wj8MD1w9; 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 S1729071AbeLKPvm (ORCPT + 99 others); Tue, 11 Dec 2018 10:51:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:40328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729548AbeLKPvk (ORCPT ); Tue, 11 Dec 2018 10:51:40 -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 BE4D02084E; Tue, 11 Dec 2018 15:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543499; bh=lVYGa6LOLilxaIgoH4y/C11aRxiuqv1QiTdQpHhRAXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wj8MD1w9Cx9ZawIuqTUkWAGEHJK3YUl8D88ASucfTzbABRZNC9VEDoN2JwafpCrE3 LVQ08PL+nVhCBuSgJafoc1PToTl+GdcCvd4Xffs3f8owXJMoUXzE2Gu2kAj8Qli2LM Dcq/ONNBZEhq2jICFYVJqZ/S150coN9iDzPnPiOw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Amborzewicz , Thor Thayer , Boris Brezillon , Sasha Levin Subject: [PATCH 4.14 21/67] mtd: spi-nor: Fix Cadence QSPI page fault kernel panic Date: Tue, 11 Dec 2018 16:41:21 +0100 Message-Id: <20181211151631.465718966@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151630.378216233@linuxfoundation.org> References: <20181211151630.378216233@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit a6a66f80c85e8e20573ca03fabf32445954a88d5 ] The current Cadence QSPI driver caused a kernel panic sporadically when writing to QSPI. The problem was caused by writing more bytes than needed because the QSPI operated on 4 bytes at a time. [ 11.202044] Unable to handle kernel paging request at virtual address bffd3000 [ 11.209254] pgd = e463054d [ 11.211948] [bffd3000] *pgd=2fffb811, *pte=00000000, *ppte=00000000 [ 11.218202] Internal error: Oops: 7 [#1] SMP ARM [ 11.222797] Modules linked in: [ 11.225844] CPU: 1 PID: 1317 Comm: systemd-hwdb Not tainted 4.17.7-d0c45cd44a8f [ 11.235796] Hardware name: Altera SOCFPGA Arria10 [ 11.240487] PC is at __raw_writesl+0x70/0xd4 [ 11.244741] LR is at cqspi_write+0x1a0/0x2cc On a page boundary limit the number of bytes copied from the tx buffer to remain within the page. This patch uses a temporary buffer to hold the 4 bytes to write and then copies only the bytes required from the tx buffer. Reported-by: Adrian Amborzewicz Signed-off-by: Thor Thayer Signed-off-by: Boris Brezillon Signed-off-by: Sasha Levin --- drivers/mtd/spi-nor/cadence-quadspi.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/spi-nor/cadence-quadspi.c b/drivers/mtd/spi-nor/cadence-quadspi.c index 8d89204b90d2..f22dd34f4f83 100644 --- a/drivers/mtd/spi-nor/cadence-quadspi.c +++ b/drivers/mtd/spi-nor/cadence-quadspi.c @@ -625,9 +625,23 @@ static int cqspi_indirect_write_execute(struct spi_nor *nor, reg_base + CQSPI_REG_INDIRECTWR); while (remaining > 0) { + size_t write_words, mod_bytes; + write_bytes = remaining > page_size ? page_size : remaining; - iowrite32_rep(cqspi->ahb_base, txbuf, - DIV_ROUND_UP(write_bytes, 4)); + write_words = write_bytes / 4; + mod_bytes = write_bytes % 4; + /* Write 4 bytes at a time then single bytes. */ + if (write_words) { + iowrite32_rep(cqspi->ahb_base, txbuf, write_words); + txbuf += (write_words * 4); + } + if (mod_bytes) { + unsigned int temp = 0xFFFFFFFF; + + memcpy(&temp, txbuf, mod_bytes); + iowrite32(temp, cqspi->ahb_base); + txbuf += mod_bytes; + } ret = wait_for_completion_timeout(&cqspi->transfer_complete, msecs_to_jiffies @@ -638,7 +652,6 @@ static int cqspi_indirect_write_execute(struct spi_nor *nor, goto failwr; } - txbuf += write_bytes; remaining -= write_bytes; if (remaining > 0) -- 2.19.1