Received: by 10.192.165.148 with SMTP id m20csp4184545imm; Mon, 30 Apr 2018 13:24:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoOUn0PllIyRER4A1jpoxvEgxGRsXXlu3RKW9OSTWrMj0rsatX7rpK3ykEHEmSmv5nyYJ9k X-Received: by 2002:a17:902:b681:: with SMTP id c1-v6mr5877207pls.286.1525119875101; Mon, 30 Apr 2018 13:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119875; cv=none; d=google.com; s=arc-20160816; b=DWFz4EFTxCj7nEkgckoO1B0Jf5OafFHLP/iJWo6nlL4bMOta/Re0sJL5m66tgB8DLB YsyCa2/i+Ki3EYpqf6wlabRL7URxFIMkfWASi25B/UqbbGpBbKdT7FGOnVMVSHVzKxqY axLDvvsvL7sNlbtHKbIVlbADWIiGqiWk9y22imdd+gbAEPzWF7B/1YRmnMxxcJ14Zh2l 8DytKGcmkL12wnn4XRuxZIlBVmlWkI1gEU+/1rGJT2hcBybP/Lnar3kXzfhIwp/YQ/26 w9Kdgbs/Bgd+FQwRZ+fAKsrcXnZc+p/Yjg4F1AdKYP6msTEC2uHv8KAFxCwOgTOB5vtN NPUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=Be4FtGUJuVS9C6KT9cjfdvb31M5YY+aTmkoKFTTw/rg=; b=oIKCFagHh3V3rxQJSwgqVHCETmrLQu9ePq+ry1gQ5cpnwFH3/DhKWeuFEFNPoZyW7P TyLkXZDTbVZzfDohYqjgqIQNm3doZIGdepzNn9slkOfqYazQ21fmgeY6xj0DQZC6810m mnFXgjdZaUHTI+QRMLqyjPaMJg1uIHYiV8g40TgZ9dUkGh4qsFY0kvMrw7zSQ7vdC5My vS09L93B6y/m1xuY3LW2xo3EZJ7kI/tgB8NppQ2kCiWen16VzQNUb0vBe5knbVgRHMx/ XpsMGbN0Zk+fVS7zpy/pGbd6pgCkZ9fqcLw5oAE30lbzFtL3h8ZLLQLPCCG22qXuT2/6 rNRQ== ARC-Authentication-Results: i=1; mx.google.com; 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 k17si254986pfj.310.2018.04.30.13.23.50; Mon, 30 Apr 2018 13:24:35 -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; 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 S1755716AbeD3T0g (ORCPT + 99 others); Mon, 30 Apr 2018 15:26:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:60372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755635AbeD3T0e (ORCPT ); Mon, 30 Apr 2018 15:26:34 -0400 Received: from localhost (unknown [104.132.1.102]) (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 776E222E02; Mon, 30 Apr 2018 19:26:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 776E222E02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joakim Tjernlund , Richard Weinberger , Boris Brezillon Subject: [PATCH 4.9 36/61] mtd: cfi: cmdset_0001: Do not allow read/write to suspend erase block. Date: Mon, 30 Apr 2018 12:24:39 -0700 Message-Id: <20180430183954.424222264@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joakim Tjernlund commit 6510bbc88e3258631831ade49033537081950605 upstream. Currently it is possible to read and/or write to suspend EB's. Writing /dev/mtdX or /dev/mtdblockX from several processes may break the flash state machine. Signed-off-by: Joakim Tjernlund Cc: Reviewed-by: Richard Weinberger Signed-off-by: Boris Brezillon Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/chips/cfi_cmdset_0001.c | 16 +++++++++++----- include/linux/mtd/flashchip.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c @@ -831,21 +831,25 @@ static int chip_ready (struct map_info * (mode == FL_WRITING && (cfip->SuspendCmdSupport & 1)))) goto sleep; + /* Do not allow suspend iff read/write to EB address */ + if ((adr & chip->in_progress_block_mask) == + chip->in_progress_block_addr) + goto sleep; /* Erase suspend */ - map_write(map, CMD(0xB0), adr); + map_write(map, CMD(0xB0), chip->in_progress_block_addr); /* If the flash has finished erasing, then 'erase suspend' * appears to make some (28F320) flash devices switch to * 'read' mode. Make sure that we switch to 'read status' * mode so we get the right data. --rmk */ - map_write(map, CMD(0x70), adr); + map_write(map, CMD(0x70), chip->in_progress_block_addr); chip->oldstate = FL_ERASING; chip->state = FL_ERASE_SUSPENDING; chip->erase_suspended = 1; for (;;) { - status = map_read(map, adr); + status = map_read(map, chip->in_progress_block_addr); if (map_word_andequal(map, status, status_OK, status_OK)) break; @@ -1041,8 +1045,8 @@ static void put_chip(struct map_info *ma sending the 0x70 (Read Status) command to an erasing chip and expecting it to be ignored, that's what we do. */ - map_write(map, CMD(0xd0), adr); - map_write(map, CMD(0x70), adr); + map_write(map, CMD(0xd0), chip->in_progress_block_addr); + map_write(map, CMD(0x70), chip->in_progress_block_addr); chip->oldstate = FL_READY; chip->state = FL_ERASING; break; @@ -1933,6 +1937,8 @@ static int __xipram do_erase_oneblock(st map_write(map, CMD(0xD0), adr); chip->state = FL_ERASING; chip->erase_suspended = 0; + chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(len - 1); ret = INVAL_CACHE_AND_WAIT(map, chip, adr, adr, len, --- a/include/linux/mtd/flashchip.h +++ b/include/linux/mtd/flashchip.h @@ -85,6 +85,7 @@ struct flchip { unsigned int write_suspended:1; unsigned int erase_suspended:1; unsigned long in_progress_block_addr; + unsigned long in_progress_block_mask; struct mutex mutex; wait_queue_head_t wq; /* Wait on here when we're waiting for the chip