Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp83686yba; Mon, 20 May 2019 05:25:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIv4lWKu1o/IjOtmp2nCKjjysSdMizalX7udTqjeE8N55FjGJSpAVUiHrHQvznb0aFS445 X-Received: by 2002:a63:1512:: with SMTP id v18mr23761685pgl.69.1558355116711; Mon, 20 May 2019 05:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355116; cv=none; d=google.com; s=arc-20160816; b=uJPdWMSBZMrbpscWrjlPptJmOs3VQHbWUZzPHzW84y2pYA1hUZUFVAiXgw0TGkakpL 9EhfwPePPxG2P1K6/QNck441RqP2+Hp6+Mob+33Gq+y6W88DdJH490mYvvWrUHBv4NU1 Cg4eCOA4l/6OhDszb7S8ogONgc1BmLCYU2nwkCeuj+Kj0YyOWH4+vSq+Mp7Vzbw8rSR6 aOQllj6qBP3VQXHcdEE7CRCn2TXRzfCkJEg6OCZ4lL3affPzSKn0XGrdiEQcPL5itBkG DsAEOtgGjs4xzXmQvUnh2owICN5D8L3doseS58UaINV8jDfq9FzDagdDj5jKydridMyD qxbg== 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=OUbzVVtM7MQ/wSAhao3nimC9tkKycQItCXsObbSuRNg=; b=O7T9XVQn/hz4PfviasiGBjSAh/cUl0OYIniJIpRO1XLuZOTutgrnS3vgmB7paC/dUD BJJhhZuZMcEDIHQVxmVbvhGz2fZO4/oQcmy1geZiyKmdlcJW6oXX9Aw3NVdHCoKuN8EZ AGXoM2+e0yvJRVcdSNf6Gami0x3vUkWZHYV1cuPmWeWTrmS9l2vsvwwS/CbYU9OiLtsZ s78F65ceVBUvQ78zAKeUZhHHZnDtLT+VFFisAeDMiJcsHbj63kgXFGmciYZvzZQNehJk LuZgnkCE4WYEf4UPzd3vqSCWJCoMPemvIvWul59+mNufJNcK490qds/nHLKrgz+/Mdjq nGVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IeraMrAT; 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 h96si18167615plb.281.2019.05.20.05.25.02; Mon, 20 May 2019 05:25:16 -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=IeraMrAT; 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 S2388601AbfETMX2 (ORCPT + 99 others); Mon, 20 May 2019 08:23:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:37850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388023AbfETMX0 (ORCPT ); Mon, 20 May 2019 08:23:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 E8D2820645; Mon, 20 May 2019 12:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355006; bh=5QImTVuc0lxp89bL2HI9b6Gh4NBrFme6P7Laz59P0CI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IeraMrATHXBQyuFFuGhMPnnACvG2ch/VM5XiXnvfSduvnPKfCCVb/yzQZiF1ABeDX o9ijt/rVtvcbOq0b6XxwMHUGVCKpEo9mie80+jLVHrf0ZfKDQuhlI4wC4mZ3yYSPY2 jyiY2CcHRddbJjduQp4A3wzsm6jJcRqjSRIidUgw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Romain Porte , Pascal Fabreges , Alexander Sverdlin , Tudor Ambarus , Mika Westerberg , Miquel Raynal Subject: [PATCH 4.19 062/105] mtd: spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Date: Mon, 20 May 2019 14:14:08 +0200 Message-Id: <20190520115251.429329643@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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: Alexander Sverdlin commit 2b75ebeea6f4937d4d05ec4982c471cef9a29b7f upstream. It was observed that reads crossing 4K address boundary are failing. This limitation is mentioned in Intel documents: Intel(R) 9 Series Chipset Family Platform Controller Hub (PCH) Datasheet: "5.26.3 Flash Access Program Register Access: * Program Register Accesses are not allowed to cross a 4 KB boundary..." Enhanced Serial Peripheral Interface (eSPI) Interface Base Specification (for Client and Server Platforms): "5.1.4 Address For other memory transactions, the address may start or end at any byte boundary. However, the address and payload length combination must not cross the naturally aligned address boundary of the corresponding Maximum Payload Size. It must not cross a 4 KB address boundary." Avoid this by splitting an operation crossing the boundary into two operations. Fixes: 8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller") Cc: stable@vger.kernel.org Reported-by: Romain Porte Tested-by: Pascal Fabreges Signed-off-by: Alexander Sverdlin Reviewed-by: Tudor Ambarus Acked-by: Mika Westerberg Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/spi-nor/intel-spi.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/mtd/spi-nor/intel-spi.c +++ b/drivers/mtd/spi-nor/intel-spi.c @@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi while (len > 0) { block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ); + /* Read cannot cross 4K boundary */ + block_size = min_t(loff_t, from + block_size, + round_up(from + 1, SZ_4K)) - from; + writel(from, ispi->base + FADDR); val = readl(ispi->base + HSFSTS_CTL); @@ -685,6 +689,10 @@ static ssize_t intel_spi_write(struct sp while (len > 0) { block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ); + /* Write cannot cross 4K boundary */ + block_size = min_t(loff_t, to + block_size, + round_up(to + 1, SZ_4K)) - to; + writel(to, ispi->base + FADDR); val = readl(ispi->base + HSFSTS_CTL);