Received: by 10.192.165.148 with SMTP id m20csp4154319imm; Mon, 30 Apr 2018 12:48:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpSkbznDvvC8473L81TVNewVE3OQ7IRYeDMPCxOlzv1MSVqFXkXv8en0N8LD86YUjaqsJGK X-Received: by 2002:a63:6f82:: with SMTP id k124-v6mr10662314pgc.301.1525117689344; Mon, 30 Apr 2018 12:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117689; cv=none; d=google.com; s=arc-20160816; b=TRJX1i7tx+uXKfK9d9EV9Sc5WSgS9xZUWSTxk5RBlVqxbniYXDdixNa7b4kHLQZSbj NwFIaKFDWTPlshTlCMgvsp14DbOhu4dqcdTAb/BlBLiYsiglMM40OP2GFy+XqJAKYz71 TQUjkS67IHMzbah3JzfxJFFpxM12BfY5nUMFj+1GXg+OfkPWdtuDA4NEfU0rYEo/OWP2 999uX8BXeLBcvZqQd0gnvqrwD1s9PEfXZa8cm74CQLDRBHtKSEkCdcZaCM4A6a46+ZW+ UR0vamVDZ0CjAyg8GDMV0B4pzknUJPwJQRt7sPJ9fDHkKzvcEc5pbssolbnSLdXCwnOR Ov8w== 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=RKMzk0aad9ldAG7vzg1j40JNqw650IQdp3OrST22jFk=; b=OOsSv6SVAC+VExTEEROZT/eQS1JAqxx6PwMqgwDLkexcAaxXMK11h5xR1yWQEQIt4w t+hplOGujBTwKxOwQ1vehQEtE+s3a0Je4TW4060afnxROkZN6+lgAhA9+Egmorq1FnsO IvLD+7l7lRqPKuQIKYyBlQEl+lptXG/+eJwLKQaK9GA4NoNfeWrPoI7sRWf0F3pRm7jq 60zNeDL2v6A2NfA1r2DpYLPPU9vukk4JLU/aFf9D1EX+olXKjAeMdYaXZUhG64G896nN Zx3eYFfkDSuwLnV7iW0M8qpDsPFxvL1w9bT9eyZ2nAOBFHjiCuzPVii7yzbSaAMt4aj3 vBpQ== 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 g11-v6si8214836plt.284.2018.04.30.12.47.55; Mon, 30 Apr 2018 12:48:09 -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 S932356AbeD3Tp7 (ORCPT + 99 others); Mon, 30 Apr 2018 15:45:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:35914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932247AbeD3T2V (ORCPT ); Mon, 30 Apr 2018 15:28:21 -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 707D322DAC; Mon, 30 Apr 2018 19:28:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 707D322DAC 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.16 055/113] mtd: cfi: cmdset_0001: Do not allow read/write to suspend erase block. Date: Mon, 30 Apr 2018 12:24:26 -0700 Message-Id: <20180430184017.386404824@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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