From patchwork Wed Dec 6 08:50:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 845068 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MAT0FLkK"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=de.bosch.com header.i=@de.bosch.com header.b="ZDJ5Mtfg"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ysCGm6PfYz9s4s for ; Wed, 6 Dec 2017 19:59:28 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KS3HToF1B57c0Ixa8rj5mIjrrFv+3pKrGlEo/u/1iGk=; b=MAT0FLkK+ywU+W YEHDC/IcOJqPZN4AEVooDm9tyMK1fm5HEnTVpgFAcyLlDyE92zHOerkGNdQsh1fx/BXQT6/m2+UIU iN2xZ9pzE4ujg380SdhwETE2t0KvhqhZGHXE9u5A03BquV8P1S6Q3BBFYJUoLHKXxc6AAANVtONaI jtUBcM3q2B/Rhn9npV3CMwDd8pMhaktlKsKTgSFx5HR4uRFf/lmUfw5ZuNyMruE48Dqr4wcM9bTlZ LSa4BIcNau0fpMXhJwlKYmoh5JsDctu1NOArAixtuiPyA7uVKkTh+7A+76EUg40I5LAu56NknCfsH bakcqGoOuWnLWPFywuMQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMVY0-0006QP-KA; Wed, 06 Dec 2017 08:59:20 +0000 Received: from imta21.fe.bosch.de ([139.15.243.226]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMVXr-00068l-Lq for linux-mtd@lists.infradead.org; Wed, 06 Dec 2017 08:59:16 +0000 Received: from smtp6-v.fe.bosch.de (imta24.fe.bosch.de [139.15.243.27]) by imta21.fe.bosch.de (Postfix) with ESMTP id E2113C07E6 for ; Wed, 6 Dec 2017 09:49:23 +0100 (CET) Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta24.fe.bosch.de (Postfix) with ESMTP id 26840D8021E; Wed, 6 Dec 2017 09:48:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1512550085; bh=eQksyDOgK9eUOo6EfpSEeZh5Z0StvM2J6rFWqp5v52Y=; l=10; h=From:From:Reply-To:Sender; b=ZDJ5Mtfgt8XT/bsCa7qLt76i7u2V1G/BN4t3B9Jg4/ZbeoptJNI/jE+kcMCWkS+XO +O03AjWEYRCX4ro7a8u1aFlazKCPx4es00W93B88HCzwEw0p+TNnvq+LSVbxumz7vP FNwecw2+GE+AipTdGtZRgMyxxU4ZWqjhJf0ZGMmI= Received: from SI-HUB1001.de.bosch.com (vsgw23.fe.internet.bosch.com [10.4.98.23]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 0FA9E1B8074E; Wed, 6 Dec 2017 09:50:42 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.319.2; Wed, 6 Dec 2017 09:50:41 +0100 From: Dirk Behme To: , Richard Weinberger Subject: [PATCH 1/5] mtdram: expose write size and writebuf size as module parameters Date: Wed, 6 Dec 2017 09:50:35 +0100 Message-ID: <20171206085039.27164-2-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com> References: <20171206085039.27164-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-23510.005 X-TMASE-MatchedRID: zGezedWykkQvwW0E4MGWVBWCVBr+Ay98u56wFPSkMVEUtdRZTmEaIfMT uIrC6WWhQQeuuk4pPUf+xBHYoGxcr6uIeo5V4l3THFAJdqqxfcm+CP3vLx6KVhMjeku6KX9+3/0 3qUr0ofrwNFheFiTN2dRuNw2/kbVibXwNw7f7LolN3UUbIf4esvbk9+ac+oPv+3n3Z6rbGhOhc1 YBFv1Ribj73R2aT5mjTdSbrZ5NwPwYB2fOueQzjxRFJJyf5BJeAPpGmOpAZoX6C0ePs7A07cjHc hynrO5bE0bZpYC/VZjhalyb1GFb3I3obvtEZV7lZoi1w1puCSw= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_005912_397415_2E3F3A88 X-CRM114-Status: GOOD ( 11.72 ) X-Spam-Score: -7.0 (-------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-7.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [139.15.243.226 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [139.15.243.226 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dirk.behme@de.bosch.com, manfred@colorfullife.com, Manfred Spraul Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Manfred Spraul Right now, mtdram reports itself as a device with a 1 byte write size, and the writebuf size can only be changed at compile time. The patch: - allows to change the write size, both at compile and at module load time - allows to change the writebuf size at module load time. Increasing the write size e.g. speeds up nandwrite significantly, and it allows to test how UBI behaves with/without subpage writes. Signed-off-by: Manfred Spraul Cc: Manfred Spraul --- drivers/mtd/devices/Kconfig | 19 +++++++++++++++++++ drivers/mtd/devices/mtdram.c | 7 +++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index 6def5445e03e..d8b67ba0b5de 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig @@ -181,6 +181,25 @@ config MTDRAM_ERASE_SIZE as a module, it is also possible to specify this as a parameter when loading the module. +config MTDRAM_WRITE_SIZE + int "MTDRAM write size in bytes" + depends on MTD_MTDRAM + default "1" + help + This allows you to configure the minimum write size in the device + emulated by the MTDRAM driver. If the MTDRAM driver is built + as a module, it is also possible to specify this as a parameter when + loading the module. Common values are 1 (NOR), 512 (NAND with sub- + page writes) or 2048 (NAND without sub-page writes). + +config MTDRAM_WRITEBUF_SIZE + int "MTDRAM writebuf size in bytes" + depends on MTD_MTDRAM + default "64" + help + This allows you to specify the writebuf size that is reported + by the device emulated by the MTDRAM driver. + config MTD_BLOCK2MTD tristate "MTD using block device" depends on BLOCK diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index 0bf4aeaf0cb8..0c8652ac0395 100644 --- a/drivers/mtd/devices/mtdram.c +++ b/drivers/mtd/devices/mtdram.c @@ -20,7 +20,8 @@ static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; -static unsigned long writebuf_size = 64; +static unsigned long writebuf_size = CONFIG_MTDRAM_WRITEBUF_SIZE; +static unsigned long write_size = CONFIG_MTDRAM_WRITE_SIZE; #define MTDRAM_TOTAL_SIZE (total_size * 1024) #define MTDRAM_ERASE_SIZE (erase_size * 1024) @@ -31,6 +32,8 @@ module_param(erase_size, ulong, 0); MODULE_PARM_DESC(erase_size, "Device erase block size in KiB"); module_param(writebuf_size, ulong, 0); MODULE_PARM_DESC(writebuf_size, "Device write buf size in Bytes (Default: 64)"); +module_param(write_size, ulong, 0); +MODULE_PARM_DESC(write_size, "Device write size in Bytes (Default: 1)"); #endif // We could store these in the mtd structure, but we only support 1 device.. @@ -134,7 +137,7 @@ int mtdram_init_device(struct mtd_info *mtd, void *mapped_address, mtd->type = MTD_RAM; mtd->flags = MTD_CAP_RAM; mtd->size = size; - mtd->writesize = 1; + mtd->writesize = write_size; mtd->writebufsize = writebuf_size; mtd->erasesize = MTDRAM_ERASE_SIZE; mtd->priv = mapped_address; From patchwork Wed Dec 6 08:50:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 845073 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aGJ/dPFV"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=de.bosch.com header.i=@de.bosch.com header.b="ZDJ5Mtfg"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ysCJb5b5Tz9s4s for ; Wed, 6 Dec 2017 20:01:03 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=88PJuKYBb1mesgIQqDj51nkiIZ5SKXGd/B2eBc1/x24=; b=aGJ/dPFVCQhTFy XrAKaEpwF6Q4rgctYkrqLPjtjI1RPLohX9kSg5/RN7wH413N5YTrXU9PYDDkj/I8zE70kdDIKbXvs alssawDb32uCt1dwJS2oaGYnESt8Vc1x52Al2GzrLKzHtpJoQQN3DH7nFpNrASgpH8BIlbA564YV9 roYtidfbyQn1WjnpDGyAk4w3KYD0+32CHwQSRrioFbksh00om07q3QEq3bvfezvw3DHww3eFGqX/c 4WDfTtLGYy5zlz2Kpp8lfE+Pl7sZ+Ko9+lwCvepKFiZjegGyMiKlWcNJxcUknrEpCsEJosQeM2foX 947RIRLMGuJEGtSwsnAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMVZU-0000Q5-6n; Wed, 06 Dec 2017 09:00:52 +0000 Received: from imta21.fe.bosch.de ([139.15.243.226]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMVXs-00068m-5G for linux-mtd@lists.infradead.org; Wed, 06 Dec 2017 08:59:22 +0000 Received: from smtp6-v.fe.bosch.de (imta24.fe.bosch.de [139.15.243.27]) by imta21.fe.bosch.de (Postfix) with ESMTP id D80E4C09AF for ; Wed, 6 Dec 2017 09:49:18 +0100 (CET) Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta24.fe.bosch.de (Postfix) with ESMTP id 60BB4D80220; Wed, 6 Dec 2017 09:48:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1512550085; bh=eQksyDOgK9eUOo6EfpSEeZh5Z0StvM2J6rFWqp5v52Y=; l=10; h=From:From:Reply-To:Sender; b=ZDJ5Mtfgt8XT/bsCa7qLt76i7u2V1G/BN4t3B9Jg4/ZbeoptJNI/jE+kcMCWkS+XO +O03AjWEYRCX4ro7a8u1aFlazKCPx4es00W93B88HCzwEw0p+TNnvq+LSVbxumz7vP FNwecw2+GE+AipTdGtZRgMyxxU4ZWqjhJf0ZGMmI= Received: from SI-HUB1001.de.bosch.com (vsgw23.fe.internet.bosch.com [10.4.98.23]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 490D01B80756; Wed, 6 Dec 2017 09:50:42 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.319.2; Wed, 6 Dec 2017 09:50:41 +0100 From: Dirk Behme To: , Richard Weinberger Subject: [PATCH 2/5] mtdram: Add flight recorder Date: Wed, 6 Dec 2017 09:50:36 +0100 Message-ID: <20171206085039.27164-3-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com> References: <20171206085039.27164-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-23510.005 X-TMASE-MatchedRID: FE65JTruMqmjbvGIi5SCUEZakoam9+aeCt59Uh3p/NWs+Tw+m35CVUdI auW0nwSGMMYy8ayOMup7CRtj4pxOfRLmJd2F/yFuDB+ErBr0bANMjQ19j30wyTb9TB28Ubkie56 s8xvuUhANyipwLHeFYVOligAVJfQ/6qLlkd1ucwbil2r2x2PwtRI1EOUVOliS4pinC0b7AdUZx9 9rBvY6bCrl9K+CCKOC67Tryj0uZPpLabL+ig5qby0x8J2DopENKFFZAe4nyZ4w/z1bc8SNlqt3L bZQ6GwMJWv0OwaavTvcdnlVO7ZBOfV1unj0D4HCyeVujmXuYYUYR+gKWoGXzt9zZd3pUn7Kg0iF WTqnQw78bQRM2WaSHIAy6p60ZV62fJ5/bZ6npdiQZS2ujCtcuA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_005912_729894_4EBBF8F5 X-CRM114-Status: GOOD ( 18.13 ) X-Spam-Score: -7.0 (-------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-7.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [139.15.243.226 listed in wl.mailspike.net] -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [139.15.243.226 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dirk.behme@de.bosch.com, manfred@colorfullife.com, Manfred Spraul Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Manfred Spraul The patch adds the option to enable a flight recorder for the mtdram test device: All ERASE and WRITE commands are logged, e.g. to perform targeted power fail testing. Signed-off-by: Manfred Spraul Cc: Manfred Spraul --- drivers/mtd/devices/Kconfig | 25 +++++ drivers/mtd/devices/mtdram.c | 239 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 252 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index d8b67ba0b5de..8647214089c9 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig @@ -200,6 +200,31 @@ config MTDRAM_WRITEBUF_SIZE This allows you to specify the writebuf size that is reported by the device emulated by the MTDRAM driver. +config MTDRAM_FLIGHTRECORDER + bool "Flight recorder for MTDRAM test device" + depends on (MTD_MTDRAM && DEBUG_FS) + default n + help + This allows you to enable flight recorder mode for the MTDRAM test + device: All ERASE and WRITE commands are logged and exposed in + debugfs. + +config MTDRAM_FLIGHTRECORDER_BUFFER_SIZE + int "MTDRAM flightrecorder buffer size in KiB" + depends on MTDRAM_FLIGHTRECORDER + default "131072" + help + This allows you to set the size of the flight recorder buffer for + the MTDRAM test device. + +config MTDRAM_FLIGHTRECORDER_ENABLED + bool "Flight recorder for MTDRAM test device" + default y + depends on MTDRAM_FLIGHTRECORDER + help + This flag sets the initial setting of the flight recorder. If enabled, + the recording starts immediate at module start. + config MTD_BLOCK2MTD tristate "MTD using block device" depends on BLOCK diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index 0c8652ac0395..1dc0a5ce0f07 100644 --- a/drivers/mtd/devices/mtdram.c +++ b/drivers/mtd/devices/mtdram.c @@ -18,6 +18,190 @@ #include #include +#ifdef CONFIG_MTDRAM_FLIGHTRECORDER + +#include +#include + +static unsigned long fr_buffersize = CONFIG_MTDRAM_FLIGHTRECORDER_BUFFER_SIZE; + +#define FR_BUFFER_TOTAL_SIZE (fr_buffersize * 1024) +#define FR_BUFFER_MARGIN 512 + +static bool fr_enabled = CONFIG_MTDRAM_FLIGHTRECORDER_ENABLED; + +#ifdef MODULE +module_param(fr_buffersize, ulong, 0); +MODULE_PARM_DESC(fr_buffersize, "Flight recorder buffer size KiB"); +module_param(fr_enabled, bool, 0); +MODULE_PARM_DESC(fr_enabled, "Set the initial enabled/disabled status"); +#endif + +static char *fr_buffer; +static int fr_pos; +static struct dentry *fr_dentry; + +static DEFINE_MUTEX(fr_mutex); +static DECLARE_WAIT_QUEUE_HEAD(fr_wait); + +static ssize_t nandrec_read_file(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + ssize_t r; + + mutex_lock(&fr_mutex); + + /* Every read must read all available data */ + if (count < fr_pos) { + r = -EINVAL; + goto out_unlock; + } + + if (fr_pos == 0) { + r = 0; + goto out_unlock; + } + + *ppos = 0; + + r = debugfs_file_get(fr_dentry); + count = fr_pos; + if (likely(!r)) { + r = simple_read_from_buffer(user_buf, count, ppos, fr_buffer, + FR_BUFFER_TOTAL_SIZE); + debugfs_file_put(fr_dentry); + } + + /* Every read must read all available data */ + WARN_ON(fr_pos != r); + + /* Every read clears the kernel buffer */ + fr_pos = 0; + + /* if someone waits, wake him up */ + if (waitqueue_active(&fr_wait)) + wake_up(&fr_wait); + +out_unlock: + mutex_unlock(&fr_mutex); + return r; +} + +static const struct file_operations fr_fops = { + .read = nandrec_read_file, + .open = simple_open, +}; + +#define MAGIC_START 0x12345678UL +#define MAGIC_END 0x87654321UL + +#define FUNC_WRITE 1UL +#define FUNC_ERASE 2UL + +static void write_u32(u32 data) +{ + u32 *target = (u32 *)(fr_buffer + fr_pos); + + if (fr_enabled) { + *target = cpu_to_le32(data); + fr_pos += round_up(sizeof(u32), 8); + } +} + +static void write_u64(u64 data) +{ + u64 *target = (u64 *)(fr_buffer + fr_pos); + + if (fr_enabled) { + *target = cpu_to_le64(data); + fr_pos += round_up(sizeof(u64), 8); + } +} + +static void write_blob(const u_char *data, int len) +{ + u32 *target = (u32 *)(fr_buffer + fr_pos); + + if (fr_enabled) { + memcpy(target, data, len); + fr_pos += round_up(len, 8); + } +} + +static void start_write(int size) +{ + mutex_lock(&fr_mutex); + + if (fr_enabled) { + while (fr_pos + size + 2*8 >= + FR_BUFFER_TOTAL_SIZE - FR_BUFFER_MARGIN) { + DEFINE_WAIT(wait); + + pr_info("%p: Waiting - write count %d, current %d.\n", + current, size, fr_pos); + + prepare_to_wait(&fr_wait, &wait, TASK_UNINTERRUPTIBLE); + + mutex_unlock(&fr_mutex); + + schedule(); + mutex_lock(&fr_mutex); + finish_wait(&fr_wait, &wait); + } + write_u32(MAGIC_START); + } +} + +static void end_write(void) +{ + if (fr_enabled) { + write_u32(MAGIC_END); + WARN_ON(fr_pos > FR_BUFFER_TOTAL_SIZE - FR_BUFFER_MARGIN); + } + mutex_unlock(&fr_mutex); +} + +static int fr_init(void) +{ + fr_buffer = vmalloc(FR_BUFFER_TOTAL_SIZE); + if (!fr_buffer) + return -ENOMEM; + + memset(fr_buffer, 0xfa, FR_BUFFER_TOTAL_SIZE); + + fr_dentry = debugfs_create_file("mtdram", 0600, NULL, NULL, + &fr_fops); + + if (IS_ERR(fr_dentry)) { + vfree(fr_buffer); + fr_buffer = NULL; + return -ENOMEM; + } + return 0; +} + +static void fr_exit(void) +{ + if (fr_buffer) { + debugfs_remove(fr_dentry); + vfree(fr_buffer); + fr_buffer = NULL; + } +} + +#else /* CONFIG_MTDRAM_FLIGHTRECORDER */ + +static int fr_init(void) +{ + return 0; +} + +static void fr_exit(void) +{ +} + +#endif /* CONFIG_MTDRAM_FLIGHTRECORDER */ + static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; static unsigned long writebuf_size = CONFIG_MTDRAM_WRITEBUF_SIZE; @@ -63,6 +247,15 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) if (check_offs_len(mtd, instr->addr, instr->len)) return -EINVAL; memset((char *)mtd->priv + instr->addr, 0xff, instr->len); + +#ifdef CONFIG_MTDRAM_FLIGHTRECORDER + start_write(3*8); + write_u32(FUNC_ERASE); + write_u64(instr->addr); + write_u64(instr->len); + end_write(); +#endif + instr->state = MTD_ERASE_DONE; mtd_erase_callback(instr); return 0; @@ -114,12 +307,23 @@ static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { memcpy((char *)mtd->priv + to, buf, len); + +#ifdef CONFIG_MTDRAM_FLIGHTRECORDER + start_write(3*8 + len); + write_u32(FUNC_WRITE); + write_u64(to); + write_u64(len); + write_blob(buf, len); + end_write(); +#endif + *retlen = len; return 0; } static void __exit cleanup_mtdram(void) { + fr_exit(); if (mtd_info) { mtd_device_unregister(mtd_info); vfree(mtd_info->priv); @@ -163,25 +367,36 @@ static int __init init_mtdram(void) if (!total_size) return -EINVAL; + err = -ENOMEM; + /* Allocate some memory */ mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); if (!mtd_info) - return -ENOMEM; + goto fail_mtdinfo; addr = vmalloc(MTDRAM_TOTAL_SIZE); - if (!addr) { - kfree(mtd_info); - mtd_info = NULL; - return -ENOMEM; - } + if (!addr) + goto fail_ramdisk; + err = mtdram_init_device(mtd_info, addr, MTDRAM_TOTAL_SIZE, "mtdram test device"); - if (err) { - vfree(addr); - kfree(mtd_info); - mtd_info = NULL; - return err; - } + if (err) + goto fail_init_device; + memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE); + err = fr_init(); + if (err) + goto fail_fr_init; + + return 0; + +fail_fr_init: + mtd_device_unregister(mtd_info); +fail_init_device: + vfree(addr); +fail_ramdisk: + kfree(mtd_info); + mtd_info = NULL; +fail_mtdinfo: return err; } From patchwork Wed Dec 6 08:50:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 845069 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LqIe+8y/"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=de.bosch.com header.i=@de.bosch.com header.b="fhgeZTIy"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ysCH228Vyz9s4s for ; Wed, 6 Dec 2017 19:59:42 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iRSljclu7Nr5L1yT3LExdEkx8XXGFLPbOfyutMqBvKo=; b=LqIe+8y/l97+f9 oUXTMlbcarg14mUPGkNWJNeM202gj9K/V5moJTwrgzfBfkMQEzPlPPhflw5J5kyxbCN6w1OoD6EX4 aZqG7mrMSxvWwSv0A123A7BCM0N3YYceVEshik2J6Ajk2/lHZFovD3iox0UaOYifjQQQhRqI3/y9+ TrTBLU6sJaMDYMgbU7Zi4KCn7ut9KKDeh42uCy7AHIwIe6oTp3sY65IdNFYBjP1dkMLHpYZL7VU2E bWlQ9DEoVI8gOhB2HqunUFVCuYLVJXZeHziVEOkoiUZ/ll2jdMLfXJaEU8EIGrm+ci4oGU3eO+pwc lzdq7rkN3MTdH1TElRdA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMVYG-0006fm-0R; Wed, 06 Dec 2017 08:59:36 +0000 Received: from imta21.fe.bosch.de ([139.15.243.226]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMVXr-00068n-Ou for linux-mtd@lists.infradead.org; Wed, 06 Dec 2017 08:59:16 +0000 Received: from smtp6-v.fe.bosch.de (imta23.fe.bosch.de [139.15.243.227]) by imta21.fe.bosch.de (Postfix) with ESMTP id D93ABC09B0 for ; Wed, 6 Dec 2017 09:49:18 +0100 (CET) Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta23.fe.bosch.de (Postfix) with ESMTP id 7D95C15801B4; Wed, 6 Dec 2017 09:48:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1512550089; bh=eQksyDOgK9eUOo6EfpSEeZh5Z0StvM2J6rFWqp5v52Y=; l=10; h=From:From:Reply-To:Sender; b=fhgeZTIy9O3GGRlkDnve4T2ckoDQYWtB2DUUY/9VPVKe3YseFbZYKdTuB9LRRsQGv aVqG4HHhibcpQTFU/0ZGMGgSXl2qMWNkgVpCw9zNfV3mSUV9dx6UvEdPqBDGrM2RL5 ylv0k+JHe/RgKozmnGI0UuPA1L6XZWIVe67n3e4w= Received: from SI-HUB1001.de.bosch.com (vsgw23.fe.internet.bosch.com [10.4.98.23]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 7E6051B80759; Wed, 6 Dec 2017 09:50:42 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.319.2; Wed, 6 Dec 2017 09:50:41 +0100 From: Dirk Behme To: , Richard Weinberger Subject: [PATCH 3/5] mtdram: Allow to enable/disable flight recorder mode at runtime. Date: Wed, 6 Dec 2017 09:50:37 +0100 Message-ID: <20171206085039.27164-4-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com> References: <20171206085039.27164-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-23510.005 X-TMASE-MatchedRID: X5ozMMNqzDoPv5/+N9RjEu7KTDtx8Cggvgj97y8eilZWLCpfN4pF7PlY oV6p/cSxpROtlYgxy5XyyB+gEfX5m5sYdIGP6PlZ4RtSDjG+z7BvAd/85EsfAZsoi2XrUn/Jn6K dMrRsL14qtq5d3cxkNcN9MitkD6wjtWL1UM/odDxoTfjRiF/ZKxqlt4UjlrCz+bnD0Oc/ch3sux 7mbEyXnWtxR75auxrM2Ynv9lyyjZVRvGoEv97UyztF7iEBca7BXyZ6pl/oDQ1+Az0rNWZh1oK3x HwHujePLauJU5NC5kJDDKa3G4nrLQ== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_005912_339134_FD80C750 X-CRM114-Status: UNSURE ( 9.23 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -7.0 (-------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-7.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [139.15.243.226 listed in wl.mailspike.net] -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [139.15.243.226 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dirk.behme@de.bosch.com, manfred@colorfullife.com, Manfred Spraul Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Manfred Spraul The patch allows to enable/disable the flight recorder mode by writing to the debugfs file. Signed-off-by: Manfred Spraul Cc: Manfred Spraul --- drivers/mtd/devices/mtdram.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index 1dc0a5ce0f07..a6f5a656eb94 100644 --- a/drivers/mtd/devices/mtdram.c +++ b/drivers/mtd/devices/mtdram.c @@ -87,8 +87,45 @@ static ssize_t nandrec_read_file(struct file *file, char __user *user_buf, return r; } +static ssize_t nandrec_write_file(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) +{ + ssize_t r; + char kbuf[8]; + + mutex_lock(&fr_mutex); + + *ppos = 0; + memset(kbuf, 0, sizeof(kbuf)); + + r = debugfs_file_get(fr_dentry); + if (likely(!r)) { + r = simple_write_to_buffer(kbuf, sizeof(kbuf) - 1, + ppos, buf, count); + debugfs_file_put(fr_dentry); + } + + if (r > 0) { + unsigned long newval; + int ret; + + ret = kstrtoul(kbuf, 0, &newval); + if (ret == 0) + fr_enabled = newval; + else + r = ret; + } + if (fr_enabled) + pr_info("MTDRAM flight recorder enabled.\n"); + else + pr_info("MTDRAM flight recorder disabled.\n"); + mutex_unlock(&fr_mutex); + return r; +} + static const struct file_operations fr_fops = { .read = nandrec_read_file, + .write = nandrec_write_file, .open = simple_open, }; From patchwork Wed Dec 6 08:50:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 845072 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Z85zE94c"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=de.bosch.com header.i=@de.bosch.com header.b="vNY8qTxt"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ysCJF5KjQz9s4s for ; Wed, 6 Dec 2017 20:00:45 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6+JF6GvyYPvTpld3Ud9Pqy9ezilRBQsKu2W44JV1lv8=; b=Z85zE94cezNUGD oAaA1UM2nnGyF3WFJv5PxcEG1kdraXZ53hXZ+esQc+aHEkqvW3Ty1FnOP+hG0zcENAivEWGOYimHd CvNDoP+Bw4xiMt4q0BRia8LjimC54cA8fPyRGHrZNIqoQ2TtNweF442KYmRZ9NK6b9KsDrqP39KRZ rdglzoO4a2JAEj+DCz4GIsh9OU04DoZot8YpYCR9+5KeKzW1ggwckTE1+4QTf05N89arHOzHP3p1/ 7nlV3hcoIrezUf+GVQcH1EPxYK3xpqGWdgbDMvMpUF57Jwv1+mPhpM1lmXQNBAOlVDExC2o53nlTh LS7Lc8RueVzEdJcaNQqA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMVZB-0008FQ-HK; Wed, 06 Dec 2017 09:00:33 +0000 Received: from imta21.fe.bosch.de ([139.15.243.226]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMVXr-00068Z-Oz for linux-mtd@lists.infradead.org; Wed, 06 Dec 2017 08:59:22 +0000 Received: from smtp6-v.fe.bosch.de (imta24.fe.bosch.de [139.15.243.27]) by imta21.fe.bosch.de (Postfix) with ESMTP id C3D89C09AE for ; Wed, 6 Dec 2017 09:49:18 +0100 (CET) Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta24.fe.bosch.de (Postfix) with ESMTP id 41C39D80212; Wed, 6 Dec 2017 09:48:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1512550086; bh=eQksyDOgK9eUOo6EfpSEeZh5Z0StvM2J6rFWqp5v52Y=; l=10; h=From:From:Reply-To:Sender; b=vNY8qTxt9Zmn4Nrpwx7T0RC4jCQGfBR6/Eyg8zdqryGQUbCbynJiLk+4TJPA3Ojmd zH/DcrfxIaVTaSsyWYd/CiXBp9X3CF4cMALg5YITq+DO6bW4KlNjHttIfttk7aUIDP VM6mnX1VY7SE1xr83A7ayDumkXZJDZSWkkBcPi9k= Received: from SI-HUB1001.de.bosch.com (vsgw23.fe.internet.bosch.com [10.4.98.23]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 306E91B80752; Wed, 6 Dec 2017 09:50:43 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.319.2; Wed, 6 Dec 2017 09:50:42 +0100 From: Dirk Behme To: , Richard Weinberger Subject: [PATCH 4/5] mtdram: Convert the flight recorder to a ring buffer. Date: Wed, 6 Dec 2017 09:50:38 +0100 Message-ID: <20171206085039.27164-5-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com> References: <20171206085039.27164-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-23510.005 X-TMASE-MatchedRID: YCgvwslmwAWw8kFTdnBpUX9NanCUA4VeLnm5T9fCGql+bUTCaUVYBLWz maSkbtF9Cs950MJfLPLJrAzifcLE6pCoy9iDotiwGXsV1o1VQtxudYzMeKOrpHSExGWyc6iXEUS 33ulD4LwzFcG8k1fXxW0xEofE8TgXzpFIpbxp7n0uLk8NfSpYehp1+ygGfwqVuWYx8s2K6RqDtx 8lDD0Wx8R8uH5v1UzhgDLqnrRlXrZ8nn9tnqel2LI7zVffJqTz6QL/cIKp/2gSR41Grm13K+cxw /8+f+xb+wGHp1YVc7naH4xMUGDOe37cGd19dSFd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_005912_688235_BB69610D X-CRM114-Status: GOOD ( 14.31 ) X-Spam-Score: -7.0 (-------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-7.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [139.15.243.226 listed in wl.mailspike.net] -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [139.15.243.226 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dirk.behme@de.bosch.com, manfred@colorfullife.com, Manfred Spraul Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Manfred Spraul In flight recorder mode, all erase and write operations are logged. The patch converts the internal buffer to a ring buffer, i.e. it is not necessary anymore to read the complete buffer in one syscall. Signed-off-by: Manfred Spraul Cc: Manfred Spraul --- drivers/mtd/devices/mtdram.c | 119 ++++++++++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 29 deletions(-) diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index a6f5a656eb94..202696bc92ef 100644 --- a/drivers/mtd/devices/mtdram.c +++ b/drivers/mtd/devices/mtdram.c @@ -38,45 +38,101 @@ MODULE_PARM_DESC(fr_enabled, "Set the initial enabled/disabled status"); #endif static char *fr_buffer; -static int fr_pos; +static int fr_head; +static int fr_tail; static struct dentry *fr_dentry; static DEFINE_MUTEX(fr_mutex); static DECLARE_WAIT_QUEUE_HEAD(fr_wait); +static int nandrec_available_read(void) +{ + if (fr_head >= fr_tail) + return fr_head - fr_tail; + + return fr_head + FR_BUFFER_TOTAL_SIZE - fr_tail; +} + +static int nandrec_available_write(void) +{ + return FR_BUFFER_TOTAL_SIZE + - nandrec_available_read() - FR_BUFFER_MARGIN; +} + +static void nandrec_advance_head(int count) +{ + WARN_ON(count > nandrec_available_write()); + + fr_head += count; + if (fr_head > FR_BUFFER_TOTAL_SIZE) + fr_head -= FR_BUFFER_TOTAL_SIZE; +} + +static void nandrec_advance_tail(int count) +{ + WARN_ON(count > nandrec_available_read()); + + fr_tail += count; + if (fr_tail > FR_BUFFER_TOTAL_SIZE) + fr_tail -= FR_BUFFER_TOTAL_SIZE; + + if (fr_tail == fr_head) { + fr_tail = 0; + fr_head = 0; + } +} + static ssize_t nandrec_read_file(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { ssize_t r; + int max_data; mutex_lock(&fr_mutex); - /* Every read must read all available data */ - if (count < fr_pos) { - r = -EINVAL; - goto out_unlock; - } + max_data = nandrec_available_read(); - if (fr_pos == 0) { + if (max_data == 0) { r = 0; goto out_unlock; } + if (count > max_data) + count = max_data; + *ppos = 0; r = debugfs_file_get(fr_dentry); - count = fr_pos; if (likely(!r)) { - r = simple_read_from_buffer(user_buf, count, ppos, fr_buffer, - FR_BUFFER_TOTAL_SIZE); + loff_t rpos; + + rpos = fr_tail; + if (fr_tail + count > FR_BUFFER_TOTAL_SIZE) { + ssize_t tmp; + + tmp = FR_BUFFER_TOTAL_SIZE - fr_tail; + r = simple_read_from_buffer(user_buf, tmp, + &rpos, fr_buffer, + FR_BUFFER_TOTAL_SIZE); + if (r == tmp) { + rpos = 0; + tmp = simple_read_from_buffer(user_buf + tmp, + count - tmp, + &rpos, fr_buffer, + FR_BUFFER_TOTAL_SIZE); + if (tmp > 0) + r += tmp; + } + } else { + r = simple_read_from_buffer(user_buf, count, + &rpos, fr_buffer, + FR_BUFFER_TOTAL_SIZE); + } debugfs_file_put(fr_dentry); } - /* Every read must read all available data */ - WARN_ON(fr_pos != r); - - /* Every read clears the kernel buffer */ - fr_pos = 0; + if (r > 0) + nandrec_advance_tail(r); /* if someone waits, wake him up */ if (waitqueue_active(&fr_wait)) @@ -137,31 +193,39 @@ static const struct file_operations fr_fops = { static void write_u32(u32 data) { - u32 *target = (u32 *)(fr_buffer + fr_pos); + u32 *target = (u32 *)(fr_buffer + fr_head); if (fr_enabled) { *target = cpu_to_le32(data); - fr_pos += round_up(sizeof(u32), 8); + nandrec_advance_head(round_up(sizeof(u32), 8)); } } static void write_u64(u64 data) { - u64 *target = (u64 *)(fr_buffer + fr_pos); + u64 *target = (u64 *)(fr_buffer + fr_head); if (fr_enabled) { *target = cpu_to_le64(data); - fr_pos += round_up(sizeof(u64), 8); + nandrec_advance_head(round_up(sizeof(u64), 8)); } } static void write_blob(const u_char *data, int len) { - u32 *target = (u32 *)(fr_buffer + fr_pos); + u32 *target = (u32 *)(fr_buffer + fr_head); if (fr_enabled) { - memcpy(target, data, len); - fr_pos += round_up(len, 8); + if (fr_head + len > FR_BUFFER_TOTAL_SIZE) { + int p1; + + p1 = FR_BUFFER_TOTAL_SIZE - fr_head; + memcpy(target, data, p1); + memcpy(fr_buffer, data + p1, len - p1); + } else { + memcpy(target, data, len); + } + nandrec_advance_head(round_up(len, 8)); } } @@ -170,12 +234,11 @@ static void start_write(int size) mutex_lock(&fr_mutex); if (fr_enabled) { - while (fr_pos + size + 2*8 >= - FR_BUFFER_TOTAL_SIZE - FR_BUFFER_MARGIN) { + while (nandrec_available_write() < size + 2*8) { DEFINE_WAIT(wait); - pr_info("%p: Waiting - write count %d, current %d.\n", - current, size, fr_pos); + pr_info("%p: Waiting - write count %d, current %d/%d.\n", + current, size, fr_tail, fr_head); prepare_to_wait(&fr_wait, &wait, TASK_UNINTERRUPTIBLE); @@ -191,10 +254,8 @@ static void start_write(int size) static void end_write(void) { - if (fr_enabled) { + if (fr_enabled) write_u32(MAGIC_END); - WARN_ON(fr_pos > FR_BUFFER_TOTAL_SIZE - FR_BUFFER_MARGIN); - } mutex_unlock(&fr_mutex); } From patchwork Wed Dec 6 08:50:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 845070 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MQ4gzOOC"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=de.bosch.com header.i=@de.bosch.com header.b="iEPFbEus"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ysCHN4kfkz9s4s for ; Wed, 6 Dec 2017 20:00:00 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4dCeJcriMZp+4PJ7rQEA2ebm7+FN0aOoHKS/NTD+AAg=; b=MQ4gzOOCsm3wbB uZmmgcWy5P6iQXegRl8xsvrbljFybvoGSU8yXWPCkMqHJ/JWBNO+qGcEFdl7tMyUjrdAlrwR2xusl 8BxTBa8qKn1tNEtbYotYF6cmcfc1mDwS4XKX0VA5Ohsw1lvQgZv/5qd6HFnxA1kPysKiJsZxy/49x 4sAO2eR4M+7UifhX52SIGmTLlk8L6J+nxomPkC6J7ozWG9NcOKyW9Oc1yGI3NJZVPVMOWxNuCYDQN X+gBNL0x+eetTUQeKKq6lKtrJ6ar++bXKZPWHsl3LtkRdpeW4Z3DAlGvTpJfjCsoz+cdL48IdofQx VFD9EOnTI8d6h052VEsA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMVYV-0006v5-Ef; Wed, 06 Dec 2017 08:59:51 +0000 Received: from imta21.fe.bosch.de ([139.15.243.226]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMVXs-00068k-5I for linux-mtd@lists.infradead.org; Wed, 06 Dec 2017 08:59:19 +0000 Received: from smtp6-v.fe.bosch.de (imta23.fe.bosch.de [139.15.243.227]) by imta21.fe.bosch.de (Postfix) with ESMTP id E3EE5C09B2 for ; Wed, 6 Dec 2017 09:49:18 +0100 (CET) Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta23.fe.bosch.de (Postfix) with ESMTP id 69D76158022D; Wed, 6 Dec 2017 09:48:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1512550090; bh=eQksyDOgK9eUOo6EfpSEeZh5Z0StvM2J6rFWqp5v52Y=; l=10; h=From:From:Reply-To:Sender; b=iEPFbEusdtX6wu9B5Jn1625io7e4oEIi3MDQG19be08JmeuWqR6TTtbiwfRvuqGs9 vqOmJgrjzCJOPoV9ZAfp7wzqI/bmBZPd+KGdofTXXdPu+q/CUUDcxdcjqOSg6w9Rue mTr1aHCCjpJN04EG3Lz5Tt/kBNlodR0kDITpiTtk= Received: from SI-HUB1001.de.bosch.com (vsgw23.fe.internet.bosch.com [10.4.98.23]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 67A151B8074E; Wed, 6 Dec 2017 09:50:43 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.319.2; Wed, 6 Dec 2017 09:50:42 +0100 From: Dirk Behme To: , Richard Weinberger Subject: [PATCH 5/5] mtdram flight recorder: Add checksums. Date: Wed, 6 Dec 2017 09:50:39 +0100 Message-ID: <20171206085039.27164-6-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com> References: <20171206085039.27164-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-23510.005 X-TMASE-MatchedRID: yvDAzrttxFXxoFpSGnAM9Y6MisxJraxHwx0jRRxcQfP4JyR+b5tvoGyC j7kGFS5bMMYy8ayOMupVF51vxLbfWZCoy9iDotiwSHCU59h5KrH+rFFXesuqjblmMfLNiukaFWo Asts4LpU6hUOcTonr9IAy6p60ZV62fJ5/bZ6npdjGVuWouVipcoquDTfUyfQi+FMBUyufmG+yhj kYN0Ww/yztPf2SGXatwtmDEcPlSS3LgSGp3SZac8CFsem4o9u2oxShiDBjN/T1EJ4DVpFBEIISr dkIFqeuO4Y2dUBhL/BTBYT7RGXoWxJAEJH0NuHT9aAnbWsWzHc= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_005912_723737_1FD0782C X-CRM114-Status: UNSURE ( 9.18 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -7.0 (-------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-7.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [139.15.243.226 listed in wl.mailspike.net] -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [139.15.243.226 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dirk.behme@de.bosch.com, manfred@colorfullife.com, Manfred Spraul Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Manfred Spraul Add checksums, to ensure that corruptions can be detected. To allow userspace to detect the new fields, use new IDs for WRITE/ERASE commands. Signed-off-by: Manfred Spraul Cc: Manfred Spraul --- drivers/mtd/devices/mtdram.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index 202696bc92ef..cdf5ae90943b 100644 --- a/drivers/mtd/devices/mtdram.c +++ b/drivers/mtd/devices/mtdram.c @@ -190,6 +190,11 @@ static const struct file_operations fr_fops = { #define FUNC_WRITE 1UL #define FUNC_ERASE 2UL +#define FUNC_WRITE_CHK 3UL +#define FUNC_ERASE_CHK 4UL +#define CHECK_VAL1 7ULL +#define CHECK_VAL2 (2*76777ULL) +#define CHECK_VAL3 104677ULL static void write_u32(u32 data) { @@ -348,9 +353,10 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) #ifdef CONFIG_MTDRAM_FLIGHTRECORDER start_write(3*8); - write_u32(FUNC_ERASE); + write_u32(FUNC_ERASE_CHK); write_u64(instr->addr); write_u64(instr->len); + write_u64(CHECK_VAL1*(u64)instr->len + CHECK_VAL2*(u64)instr->addr); end_write(); #endif @@ -407,12 +413,23 @@ static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, memcpy((char *)mtd->priv + to, buf, len); #ifdef CONFIG_MTDRAM_FLIGHTRECORDER - start_write(3*8 + len); - write_u32(FUNC_WRITE); - write_u64(to); - write_u64(len); - write_blob(buf, len); - end_write(); + start_write(4*8 + len); + { + u64 i; + u64 chk; + + write_u32(FUNC_WRITE_CHK); + + chk = CHECK_VAL1*(u64)to + CHECK_VAL2*(u64)len; + for (i = 0; i < len; i++) + chk += (i + buf[i])*CHECK_VAL3; + + write_u64(to); + write_u64(len); + write_blob(buf, len); + write_u64(chk); + end_write(); + } #endif *retlen = len;