public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/27] mtd: spi-nor: Enhance software protection
@ 2026-01-08 16:57 Miquel Raynal
  2026-01-08 16:57 ` [PATCH v2 01/27] mtd: spi-nor: Drop duplicate Kconfig dependency Miquel Raynal
                   ` (26 more replies)
  0 siblings, 27 replies; 30+ messages in thread
From: Miquel Raynal @ 2026-01-08 16:57 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Richard Weinberger,
	Vignesh Raghavendra, Jonathan Corbet
  Cc: Sean Anderson, Thomas Petazzoni, Steam Lin, linux-mtd,
	linux-kernel, linux-doc, Miquel Raynal, stable

Hello,

As recently raised on the mailing-list (link below), it seems that the
"locking" support in SPI NOR could benefit from some enhancements. As I
myself had to dig into it recently, here is a proposal.

First issue that I see, the MEMLOCK ioctl is not behaving correctly
in some cases, as addressed in:

    mtd: spi-nor: swp: Improve locking user experience

Then there is no clear explanation of the shortcuts taken by the kernel
in terms of uAPI, so there is an attempt to list them in:

    mtd: spi-nor: swp: Explain the MEMLOCK ioctl implementation behaviour

Plus, Tudor also asked if we could cover locking in the testing
procedure, which is done in:

    mtd: spi-nor: Add steps for testing locking support

In order to simplify this procedure, and because it got very helpful
during my testing/development, I want to propose additions to the
debugfs output:

    mtd: spi-nor: debugfs: Add locking support TODO: make the captures again

Finally, I am providing an implementation for the complement (CMP)
feature in order to allow finer control of the regions locked. This
feature is for instance available on Winbond chips:

    [core] mtd: spi-nor: swp: Add support for the complement feature
    [doc]  mtd: spi-nor: Add steps for testing locking with CMP
    [use]  mtd: spi-nor: winbond: Add CMP locking support

Disclaimer: it was much less straightforward than I initially thought to
get the CMP feature working correctly. I tested it with as much focus as
I could, and I am improving the test coverage for the new cases, I am
also providing extra test cases in the metadata of the commit (which do
not make sense to test for chip additions, but may be sensible show when
making core additions like this one), but honestly there are so many
possibilities, I may still be missing corner cases. I hope this will
anyway be helpful to others!

All the other patches are misc improvements or style fixes which I faced
and fixed during my development.

Link: https://lore.kernel.org/linux-mtd/92e99a96-5582-48a5-a4f9-e9b33fcff171@linux.dev/

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
Changes in v2:
- Collect tags.
- Add missing Fixes/Cc: stable tags.
- Add a comment explaining why can_be_top && can_be_bottom is a specific
  condition.
- Fix commit logs following Michael Walle's reviews.
- Amend the documentation following our discussion with Michael Walle as
  well.
- Cache the SR register for debugfs use.
- Create a locked sector map file instead of dumping it as part of the
  `params` file output.
- Improved greatly the output of the map as suggested by Michael.
- Add a patch fixing a duplicate dependency in Kconfig.
- Add an important comment in the doc about the small 4kiB erase size
  choice.
- Add test runs for each and every chip for which the CMP feature is
  added. This prove me that testing of each and every chip was needed,
  as some of them seem to feature a broken BFPT table which does not
  advertise a working 35h (Read CR) command.
- Added a condition on which the CMP feature is enabled: RDCR must be
  possible.
- Link to v1: https://lore.kernel.org/r/20251114-winbond-v6-18-rc1-spi-nor-swp-v1-0-487bc7129931@bootlin.com

---
Miquel Raynal (27):
      mtd: spi-nor: Drop duplicate Kconfig dependency
      mtd: spi-nor: debugfs: Fix the flags list
      mtd: spi-nor: swp: Improve locking user experience
      mtd: spi-nor: Improve opcodes documentation
      mtd: spi-nor: debugfs: Align variable access with the rest of the file
      mtd: spi-nor: debugfs: Enhance output
      mtd: spi-nor: swp: Explain the MEMLOCK ioctl implementation behaviour
      mtd: spi-nor: swp: Clarify a comment
      mtd: spi-nor: swp: Use a pointer for SR instead of a single byte
      mtd: spi-nor: swp: Create a helper that writes SR, CR and checks
      mtd: spi-nor: swp: Rename a mask
      mtd: spi-nor: swp: Create a TB intermediate variable
      mtd: spi-nor: swp: Create helpers for building the SR register
      mtd: spi-nor: swp: Simplify checking the locked/unlocked range
      mtd: spi-nor: swp: Cosmetic changes
      mtd: spi-nor: Create a local SR cache
      mtd: spi-nor: debugfs: Add locking support
      mtd: spi-nor: debugfs: Add a locked sectors map
      mtd: spi-nor: Add steps for testing locking support
      mtd: spi-nor: swp: Add support for the complement feature
      mtd: spi-nor: Add steps for testing locking with CMP
      mtd: spi-nor: winbond: Add W25H512NWxxAM CMP locking support
      mtd: spi-nor: winbond: Add W25H01NWxxAM CMP locking support
      mtd: spi-nor: winbond: Add W25H02NWxxAM CMP locking support
      mtd: spi-nor: winbond: Add W25H01NWxxIQ CMP locking support
      mtd: spi-nor: winbond: Add W25Q01NWxxIM CMP locking support
      mtd: spi-nor: winbond: Add W25Q02NWxxIM CMP locking support

 Documentation/driver-api/mtd/spi-nor.rst | 164 ++++++++++++++
 drivers/mtd/spi-nor/Kconfig              |   1 -
 drivers/mtd/spi-nor/core.c               |  74 ++++++-
 drivers/mtd/spi-nor/core.h               |  10 +
 drivers/mtd/spi-nor/debugfs.c            |  63 +++++-
 drivers/mtd/spi-nor/swp.c                | 359 ++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/winbond.c            |  41 +++-
 include/linux/mtd/spi-nor.h              |   7 +-
 8 files changed, 631 insertions(+), 88 deletions(-)
---
base-commit: 99bb09369a9eaed5de0e647cc1aab215668ddc6f
change-id: 20251114-winbond-v6-18-rc1-spi-nor-swp-865d36f4f695

Best regards,
-- 
Miquel Raynal <miquel.raynal@bootlin.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2026-02-09 10:39 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-08 16:57 [PATCH v2 00/27] mtd: spi-nor: Enhance software protection Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 01/27] mtd: spi-nor: Drop duplicate Kconfig dependency Miquel Raynal
2026-02-09 10:35   ` Michael Walle
2026-01-08 16:57 ` [PATCH v2 02/27] mtd: spi-nor: debugfs: Fix the flags list Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 03/27] mtd: spi-nor: swp: Improve locking user experience Miquel Raynal
2026-02-09 10:39   ` Michael Walle
2026-01-08 16:57 ` [PATCH v2 04/27] mtd: spi-nor: Improve opcodes documentation Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 05/27] mtd: spi-nor: debugfs: Align variable access with the rest of the file Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 06/27] mtd: spi-nor: debugfs: Enhance output Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 07/27] mtd: spi-nor: swp: Explain the MEMLOCK ioctl implementation behaviour Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 08/27] mtd: spi-nor: swp: Clarify a comment Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 09/27] mtd: spi-nor: swp: Use a pointer for SR instead of a single byte Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 10/27] mtd: spi-nor: swp: Create a helper that writes SR, CR and checks Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 11/27] mtd: spi-nor: swp: Rename a mask Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 12/27] mtd: spi-nor: swp: Create a TB intermediate variable Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 13/27] mtd: spi-nor: swp: Create helpers for building the SR register Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 14/27] mtd: spi-nor: swp: Simplify checking the locked/unlocked range Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 15/27] mtd: spi-nor: swp: Cosmetic changes Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 16/27] mtd: spi-nor: Create a local SR cache Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 17/27] mtd: spi-nor: debugfs: Add locking support Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 18/27] mtd: spi-nor: debugfs: Add a locked sectors map Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 19/27] mtd: spi-nor: Add steps for testing locking support Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 20/27] mtd: spi-nor: swp: Add support for the complement feature Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 21/27] mtd: spi-nor: Add steps for testing locking with CMP Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 22/27] mtd: spi-nor: winbond: Add W25H512NWxxAM CMP locking support Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 23/27] mtd: spi-nor: winbond: Add W25H01NWxxAM " Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 24/27] mtd: spi-nor: winbond: Add W25H02NWxxAM " Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 25/27] mtd: spi-nor: winbond: Add W25H01NWxxIQ " Miquel Raynal
2026-01-08 16:57 ` [PATCH v2 26/27] mtd: spi-nor: winbond: Add W25Q01NWxxIM " Miquel Raynal
2026-01-08 16:58 ` [PATCH v2 27/27] mtd: spi-nor: winbond: Add W25Q02NWxxIM " Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox