kernel: bump 5.10 to 5.10.121
[openwrt/staging/pepe2k.git] / target / linux / generic / pending-5.10 / 402-mtd-spi-nor-write-support-for-minor-aligned-partitions.patch
1 From patchwork Tue Jun 8 04:07:19 2021
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: John Thomson <git@johnthomson.fastmail.com.au>
6 X-Patchwork-Id: 1489105
7 X-Patchwork-Delegate: tudor.ambarus@gmail.com
8 Return-Path:
9 <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>
10 X-Original-To: incoming@patchwork.ozlabs.org
11 Delivered-To: patchwork-incoming@bilbo.ozlabs.org
12 Authentication-Results: ozlabs.org;
13 spf=none (no SPF record) smtp.mailfrom=lists.infradead.org
14 (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org;
15 envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;
16 receiver=<UNKNOWN>)
17 Authentication-Results: ozlabs.org;
18 dkim=pass (2048-bit key;
19 secure) header.d=lists.infradead.org header.i=@lists.infradead.org
20 header.a=rsa-sha256 header.s=bombadil.20210309 header.b=EMabhVoR;
21 dkim=fail reason="signature verification failed" (2048-bit key;
22 unprotected) header.d=fastmail.com.au header.i=@fastmail.com.au
23 header.a=rsa-sha256 header.s=fm3 header.b=dLzuZ6dB;
24 dkim=fail reason="signature verification failed" (2048-bit key;
25 unprotected) header.d=messagingengine.com header.i=@messagingengine.com
26 header.a=rsa-sha256 header.s=fm3 header.b=nSRGsW+C;
27 dkim-atps=neutral
28 Received: from bombadil.infradead.org (bombadil.infradead.org
29 [IPv6:2607:7c80:54:e::133])
30 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
31 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest
32 SHA256)
33 (No client certificate requested)
34 by ozlabs.org (Postfix) with ESMTPS id 4FzcFN1j1nz9sW8
35 for <incoming@patchwork.ozlabs.org>; Tue, 8 Jun 2021 14:09:28 +1000 (AEST)
36 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
37 d=lists.infradead.org; s=bombadil.20210309; h=Sender:
38 Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:
39 List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc
40 :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:
41 Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:
42 List-Owner; bh=6mUWQd71FwsINycGYY1qOhKz+ecWJVNtwDkTebG3XkA=; b=EMabhVoRE3ad89
43 o3L2AgyKrs+blSofUC3hoSsQe7gi3m4si8S9HW8Z+8SsS5TufUsvGwDl80qSYGlQOytQF+1yRUWvE
44 6FJ/+bqv+TwjqZFibgJ6+9OVsQN9dZ/no1R0bBXIpmrf8ORUmv58QK4ZQquaFKbyXKpFeWOC2MSv4
45 H2MAhyhTU8a3gtooH6G8+KvsJEfVgh6C+aDbwxyh2UY3chHKuw1kvL6AktbfUE2xl4zxi3x3kc70B
46 Wi3LiJBFokxVdgnROXxTU5tI0XboWYkQV64gLuQNV4XKClcuhVpzloDK8Iok6NTd7b32a7TdEFlCS
47 lGKsEKmxtUlW2FpfoduA==;
48 Received: from localhost ([::1] helo=bombadil.infradead.org)
49 by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux))
50 id 1lqT1r-006OAW-DX; Tue, 08 Jun 2021 04:07:51 +0000
51 Received: from new1-smtp.messagingengine.com ([66.111.4.221])
52 by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux))
53 id 1lqT1l-006O9b-Fq
54 for linux-mtd@lists.infradead.org; Tue, 08 Jun 2021 04:07:50 +0000
55 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42])
56 by mailnew.nyi.internal (Postfix) with ESMTP id 4456B580622;
57 Tue, 8 Jun 2021 00:07:42 -0400 (EDT)
58 Received: from mailfrontend2 ([10.202.2.163])
59 by compute2.internal (MEProxy); Tue, 08 Jun 2021 00:07:42 -0400
60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com.au;
61 h=from:to:cc:subject:date:message-id:mime-version
62 :content-transfer-encoding; s=fm3; bh=ZXRH+YluM1mHCS1EWUiCY/Sg8O
63 LccfHe1oW5iAay6y8=; b=dLzuZ6dBYf7ZA8tWLOBFZYLi7ERsGe/4vnMXG+ovvb
64 dNBO0+SaFGwoqYSFrfq/TeyHfKyvxrA7+LCdopIuT4abpLHxtRwtRiafQcDYCPat
65 qJIqOZO+wCZC5S9Jc1OP7+t1FviGpgevqIMotci37P+RWc5u3AweMzFljZk90E8C
66 uorV6rXagD+OssJQzllRnAIK88+rOAC9ZyXv2gWxy4d1HSCwSWgzx2vnV9CNp918
67 YC/3tiHas9krbrPIaAsdBROr7Bvoe/ShRRzruKRuvZVgg5NN90vX+/5ZjI8u04GM
68 p2bWCbC62CP6wlcgDaz+c/Sgr5ITd2GPENJsHfqmLRBA==
69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
70 messagingengine.com; h=cc:content-transfer-encoding:date:from
71 :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy
72 :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=ZXRH+YluM1mHCS1EW
73 UiCY/Sg8OLccfHe1oW5iAay6y8=; b=nSRGsW+CQ2Zx1RVpIUu8W/VD/k5P+32BW
74 5k2ltd+UhI3dfldBPzHrYiOP/IJqGkNW+V+rHASacW/vFygnaZoxNjRYKnOsu+26
75 wb2yK3jpl6lsNTg3N1Z4XJrYY2lf9H29DMFbhC67l0PTc050rcZk4XsKTLAlv14Q
76 VA4WREYSaX/4IN4O+ES4TMq0a/3gKZh6nvbbJXbsXfK0WlSHTGZtZmW3fyrqvbXa
77 t+R7L8vvqWvwls0pV+Sn8LeQqb7+A69w0UOnuznjkcA3sCc2YehcHbxcUEnMH+9N
78 bxOjmIDeg9/4X/829tUWUJiLhE5SFmQZ1P6oFtmbWoLrDz0ZJIVBw==
79 X-ME-Sender: <xms:C-2-YD2uka4HsA6gcdsV2Ia7vebY4Yjp9E8q7KBMb54jnAzGL7-67Q>
80 <xme:C-2-YCEaxASy5VlcrvNO_jLFpMDGkFCRsuVNuZGEQsiRZygk8jPHWq7unPjeT6uYS
81 2pUP6PrTQ2rggjEIg>
82 X-ME-Received:
83 <xmr:C-2-YD4exeK49N_YZWWf2BWDhVyCbCY3wwvjTyDOFxeugx7Jg08pzMUToo9oJjrBpcVTaA3kbfk>
84 X-ME-Proxy-Cause:
85 gggruggvucftvghtrhhoucdtuddrgeduledrfedtkedgjeduucetufdoteggodetrfdotf
86 fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
87 uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne
88 cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeflohhhnhcuvfhh
89 ohhmshhonhcuoehgihhtsehjohhhnhhthhhomhhsohhnrdhfrghsthhmrghilhdrtghomh
90 drrghuqeenucggtffrrghtthgvrhhnpefffeeihfdukedtuedufeetieeuudfhhefhkefh
91 tefgtdeuffekffelleetveduieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh
92 epmhgrihhlfhhrohhmpehgihhtsehjohhhnhhthhhomhhsohhnrdhfrghsthhmrghilhdr
93 tghomhdrrghu
94 X-ME-Proxy: <xmx:C-2-YI0AJZGjcB3wIbI9BoC9X8VNl4i9A7cQnBkvwZ25czWJlkKCLw>
95 <xmx:C-2-YGGufw99T-O81-FeiSyEruv6_Pr0IHFhspQdxjv5k1VFTZ0lzQ>
96 <xmx:C-2-YJ8BW7DhSDSCEAPSJWrwh_hHP79qreTZtWh_kOUwSh1c0MMlAg>
97 <xmx:Du2-YJBeX2Fg9oFZVXGwEJ1ZrZnXHiAqNON8tbpzquYgcm2o_LM48g>
98 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue,
99 8 Jun 2021 00:07:35 -0400 (EDT)
100 From: John Thomson <git@johnthomson.fastmail.com.au>
101 To: Miquel Raynal <miquel.raynal@bootlin.com>,
102 Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>,
103 Tudor Ambarus <tudor.ambarus@microchip.com>,
104 Michael Walle <michael@walle.cc>, Pratyush Yadav <p.yadav@ti.com>,
105 linux-mtd@lists.infradead.org
106 Cc: linux-kernel@vger.kernel.org,
107 John Thomson <git@johnthomson.fastmail.com.au>,
108 kernel test robot <lkp@intel.com>, Dan Carpenter <dan.carpenter@oracle.com>
109 Subject: [PATCH] mtd: spi-nor: write support for minor aligned partitions
110 Date: Tue, 8 Jun 2021 14:07:19 +1000
111 Message-Id: <20210608040719.14431-1-git@johnthomson.fastmail.com.au>
112 X-Mailer: git-send-email 2.31.1
113 MIME-Version: 1.0
114 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3
115 X-CRM114-CacheID: sfid-20210607_210745_712053_67A7D864
116 X-CRM114-Status: GOOD ( 26.99 )
117 X-Spam-Score: -0.8 (/)
118 X-Spam-Report: Spam detection software,
119 running on the system "bombadil.infradead.org",
120 has NOT identified this incoming email as spam. The original
121 message has been attached to this so you can view it or label
122 similar future email. If you have any questions, see
123 the administrator of that system for details.
124 Content preview: Do not prevent writing to mtd partitions where a partition
125 boundary sits on a minor erasesize boundary. This addresses a FIXME that
126 has been present since the start of the linux git history: /* Doesn' [...]
127 Content analysis details: (-0.8 points, 5.0 required)
128 pts rule name description
129 ---- ----------------------
130 --------------------------------------------------
131 -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/,
132 low trust [66.111.4.221 listed in list.dnswl.org]
133 -0.0 SPF_PASS SPF: sender matches SPF record
134 -0.0 SPF_HELO_PASS SPF: HELO matches SPF record
135 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3)
136 [66.111.4.221 listed in wl.mailspike.net]
137 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
138 0.1 DKIM_SIGNED Message has a DKIM or DK signature,
139 not necessarily
140 valid
141 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
142 envelope-from domain
143 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders
144 X-BeenThere: linux-mtd@lists.infradead.org
145 X-Mailman-Version: 2.1.34
146 Precedence: list
147 List-Id: Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>
148 List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-mtd>,
149 <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>
150 List-Archive: <http://lists.infradead.org/pipermail/linux-mtd/>
151 List-Post: <mailto:linux-mtd@lists.infradead.org>
152 List-Help: <mailto:linux-mtd-request@lists.infradead.org?subject=help>
153 List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-mtd>,
154 <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>
155 Sender: "linux-mtd" <linux-mtd-bounces@lists.infradead.org>
156 Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org
157
158 Do not prevent writing to mtd partitions where a partition boundary sits
159 on a minor erasesize boundary.
160 This addresses a FIXME that has been present since the start of the
161 linux git history:
162 /* Doesn't start on a boundary of major erase size */
163 /* FIXME: Let it be writable if it is on a boundary of
164 * _minor_ erase size though */
165
166 Allow a uniform erase region spi-nor device to be configured
167 to use the non-uniform erase regions code path for an erase with:
168 CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE=y
169
170 On supporting hardware (SECT_4K: majority of current SPI-NOR device)
171 provide the facility for an erase to use the least number
172 of SPI-NOR operations, as well as access to 4K erase without
173 requiring CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
174
175 Introduce erasesize_minor to the mtd struct,
176 the smallest erasesize supported by the device
177
178 On existing devices, this is useful where write support is wanted
179 for data on a 4K partition, such as some u-boot-env partitions,
180 or RouterBoot soft_config, while still netting the performance
181 benefits of using 64K sectors
182
183 Performance:
184 time mtd erase firmware
185 OpenWrt 5.10 ramips MT7621 w25q128jv 0xfc0000 partition length
186
187 Without this patch
188 MTD_SPI_NOR_USE_4K_SECTORS=y |n
189 real 2m 11.66s |0m 50.86s
190 user 0m 0.00s |0m 0.00s
191 sys 1m 56.20s |0m 50.80s
192
193 With this patch
194 MTD_SPI_NOR_USE_VARIABLE_ERASE=n|y |4K_SECTORS=y
195 real 0m 51.68s |0m 50.85s |2m 12.89s
196 user 0m 0.00s |0m 0.00s |0m 0.01s
197 sys 0m 46.94s |0m 50.38s |2m 12.46s
198
199 Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
200 ---
201 Have not tested on variable erase regions device.
202
203 checkpatch does not like the printk(KERN_WARNING
204 these should be changed separately beforehand?
205
206 Changes RFC -> v1:
207 Fix uninitialized variable smatch warning
208 Reported-by: kernel test robot <lkp@intel.com>
209 Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
210 ---
211 drivers/mtd/mtdpart.c | 52 ++++++++++++++++++++++++++++---------
212 drivers/mtd/spi-nor/Kconfig | 10 +++++++
213 drivers/mtd/spi-nor/core.c | 10 +++++--
214 include/linux/mtd/mtd.h | 2 ++
215 4 files changed, 60 insertions(+), 14 deletions(-)
216
217 --- a/drivers/mtd/mtdpart.c
218 +++ b/drivers/mtd/mtdpart.c
219 @@ -40,10 +40,11 @@ static struct mtd_info *allocate_partiti
220 struct mtd_info *master = mtd_get_master(parent);
221 int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
222 master->writesize : master->erasesize;
223 + int wr_alignment_minor = 0;
224 u64 parent_size = mtd_is_partition(parent) ?
225 parent->part.size : parent->size;
226 struct mtd_info *child;
227 - u32 remainder;
228 + u32 remainder, remainder_minor;
229 char *name;
230 u64 tmp;
231
232 @@ -145,6 +146,7 @@ static struct mtd_info *allocate_partiti
233 int i, max = parent->numeraseregions;
234 u64 end = child->part.offset + child->part.size;
235 struct mtd_erase_region_info *regions = parent->eraseregions;
236 + uint32_t erasesize_minor = child->erasesize;
237
238 /* Find the first erase regions which is part of this
239 * partition. */
240 @@ -155,15 +157,24 @@ static struct mtd_info *allocate_partiti
241 if (i > 0)
242 i--;
243
244 - /* Pick biggest erasesize */
245 for (; i < max && regions[i].offset < end; i++) {
246 + /* Pick biggest erasesize */
247 if (child->erasesize < regions[i].erasesize)
248 child->erasesize = regions[i].erasesize;
249 + /* Pick smallest non-zero erasesize */
250 + if ((erasesize_minor > regions[i].erasesize) && (regions[i].erasesize > 0))
251 + erasesize_minor = regions[i].erasesize;
252 }
253 +
254 + if (erasesize_minor < child->erasesize)
255 + child->erasesize_minor = erasesize_minor;
256 +
257 BUG_ON(child->erasesize == 0);
258 } else {
259 /* Single erase size */
260 child->erasesize = master->erasesize;
261 + if (master->erasesize_minor)
262 + child->erasesize_minor = master->erasesize_minor;
263 }
264
265 /*
266 @@ -171,26 +182,43 @@ static struct mtd_info *allocate_partiti
267 * exposes several regions with different erasesize. Adjust
268 * wr_alignment accordingly.
269 */
270 - if (!(child->flags & MTD_NO_ERASE))
271 + if (!(child->flags & MTD_NO_ERASE)) {
272 wr_alignment = child->erasesize;
273 + if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE) && child->erasesize_minor)
274 + wr_alignment_minor = child->erasesize_minor;
275 + }
276
277 tmp = mtd_get_master_ofs(child, 0);
278 remainder = do_div(tmp, wr_alignment);
279 if ((child->flags & MTD_WRITEABLE) && remainder) {
280 - /* Doesn't start on a boundary of major erase size */
281 - /* FIXME: Let it be writable if it is on a boundary of
282 - * _minor_ erase size though */
283 - child->flags &= ~MTD_WRITEABLE;
284 - printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
285 - part->name);
286 + if (wr_alignment_minor) {
287 + tmp = mtd_get_master_ofs(child, 0);
288 + remainder_minor = do_div(tmp, wr_alignment_minor);
289 + if (remainder_minor == 0)
290 + child->erasesize = child->erasesize_minor;
291 + }
292 +
293 + if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
294 + child->flags &= ~MTD_WRITEABLE;
295 + printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
296 + part->name);
297 + }
298 }
299
300 tmp = mtd_get_master_ofs(child, 0) + child->part.size;
301 remainder = do_div(tmp, wr_alignment);
302 if ((child->flags & MTD_WRITEABLE) && remainder) {
303 - child->flags &= ~MTD_WRITEABLE;
304 - printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
305 - part->name);
306 + if (wr_alignment_minor) {
307 + tmp = mtd_get_master_ofs(child, 0) + child->part.size;
308 + remainder_minor = do_div(tmp, wr_alignment_minor);
309 + if (remainder_minor == 0)
310 + child->erasesize = child->erasesize_minor;
311 + }
312 + if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
313 + child->flags &= ~MTD_WRITEABLE;
314 + printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
315 + part->name);
316 + }
317 }
318
319 child->size = child->part.size;
320 --- a/drivers/mtd/spi-nor/Kconfig
321 +++ b/drivers/mtd/spi-nor/Kconfig
322 @@ -10,6 +10,16 @@ menuconfig MTD_SPI_NOR
323
324 if MTD_SPI_NOR
325
326 +config MTD_SPI_NOR_USE_VARIABLE_ERASE
327 + bool "Disable uniform_erase to allow use of all hardware supported erasesizes"
328 + depends on !MTD_SPI_NOR_USE_4K_SECTORS
329 + default n
330 + help
331 + Allow mixed use of all hardware supported erasesizes,
332 + by forcing spi_nor to use the multiple eraseregions code path.
333 + For example: A 68K erase will use one 64K erase, and one 4K erase
334 + on supporting hardware.
335 +
336 config MTD_SPI_NOR_USE_4K_SECTORS
337 bool "Use small 4096 B erase sectors"
338 default y
339 --- a/drivers/mtd/spi-nor/core.c
340 +++ b/drivers/mtd/spi-nor/core.c
341 @@ -1084,6 +1084,8 @@ static u8 spi_nor_convert_3to4_erase(u8
342
343 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)
344 {
345 + if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE))
346 + return false;
347 return !!nor->params->erase_map.uniform_erase_type;
348 }
349
350 @@ -2569,6 +2571,7 @@ static int spi_nor_select_erase(struct s
351 {
352 struct spi_nor_erase_map *map = &nor->params->erase_map;
353 const struct spi_nor_erase_type *erase = NULL;
354 + const struct spi_nor_erase_type *erase_minor = NULL;
355 struct mtd_info *mtd = &nor->mtd;
356 u32 wanted_size = nor->info->sector_size;
357 int i;
358 @@ -2601,8 +2604,9 @@ static int spi_nor_select_erase(struct s
359 */
360 for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
361 if (map->erase_type[i].size) {
362 - erase = &map->erase_type[i];
363 - break;
364 + if (!erase)
365 + erase = &map->erase_type[i];
366 + erase_minor = &map->erase_type[i];
367 }
368 }
369
370 @@ -2610,6 +2614,8 @@ static int spi_nor_select_erase(struct s
371 return -EINVAL;
372
373 mtd->erasesize = erase->size;
374 + if (erase_minor && erase_minor->size < erase->size)
375 + mtd->erasesize_minor = erase_minor->size;
376 return 0;
377 }
378
379 --- a/include/linux/mtd/mtd.h
380 +++ b/include/linux/mtd/mtd.h
381 @@ -242,6 +242,8 @@ struct mtd_info {
382 * information below if they desire
383 */
384 uint32_t erasesize;
385 + /* "Minor" (smallest) erase size supported by the whole device */
386 + uint32_t erasesize_minor;
387 /* Minimal writable flash unit size. In case of NOR flash it is 1 (even
388 * though individual bits can be cleared), in case of NAND flash it is
389 * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR