Received: by 10.192.165.148 with SMTP id m20csp4172274imm; Mon, 30 Apr 2018 13:09:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZobEMv2Iw2bWWVDbhr2S92WmqGq3Fw5Mn10ifhP58IpGWXTRttzd1zfmlDoVKpXNnJD4H+W X-Received: by 2002:a63:345:: with SMTP id 66-v6mr10979716pgd.98.1525118949458; Mon, 30 Apr 2018 13:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525118949; cv=none; d=google.com; s=arc-20160816; b=ksr5E+5yhHfc7Nz1BFKQcGDFluQNWotuumNeVKZb4PLy9tn85mNxztElkRumEvWR8J Lh04y1gNQRA67jSWk4TA4txJfYPnvYhOCUE3szmxA3hc4djS4jUS7VPS4kYm9vgqsSjX Xk0HvHIFG+2UW7AW3n91b/fkVgqj676waCWsp+spmoZBBjGGzK15SGcsT86bVmwIUnLB Z/YLSgejrwaCySEvrL+z0Jtn1aFmamFzK0cpIptwuNvH9iiP87WNPTrIx7boHVb8tybi FYgNViZOv1X7ypLTU7hIUx6gPCWFj0UB6gir7JD+/MYNalgJNvsoQLW6tfqeH1UgBfZj cxbg== 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=KccKTyRYjXTZNcfRR4AFB3YYLP13f4VUckmmWxmT+Rw=; b=0tz5P6jIn/a4wPhCA7R2lgBzWsunDf58GLfxHYiWU13HzYNSt1bgDjPljIpx+bSaVV SXLL+wsuC36wbzNu4sVCj4DTn7ifYEdRDWirkG9PhUqchmcfKGCBHUlUS/h5Q48YsQnk whFIjxM0xwavUvky9Ei0IWO6Wwsmwd9IcOgaYDKiLdV6MMYJ7IgIwixMCDgCAGCq7buM /Fnb0OLOwNFYorupGawLIDfvRyNjwqU3FwQuORZ8eC9lcwyZFYjTBmDrhrfQs8Xl7QDR Q/rPifEuGL+gJI5Opfi3N0wi+/YmsH3SFGFEgobNuaXOMMZO3Gw8Cbp4CweA1glbp7N4 dGmg== 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-v6si8252519plt.284.2018.04.30.13.08.55; Mon, 30 Apr 2018 13:09: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 S932193AbeD3UIS (ORCPT + 99 others); Mon, 30 Apr 2018 16:08:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:33710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932161AbeD3T1W (ORCPT ); Mon, 30 Apr 2018 15:27:22 -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 7E44E22DCB; Mon, 30 Apr 2018 19:27:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E44E22DCB 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.14 51/91] mtd: cfi: cmdset_0001: Do not allow read/write to suspend erase block. Date: Mon, 30 Apr 2018 12:24:33 -0700 Message-Id: <20180430184006.846857768@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@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.14-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