Linux Documentation
 help / color / mirror / Atom feed
* [PATCH v5 00/28] mtd: spi-nor: Enhance software protection
@ 2026-05-07 16:46 Miquel Raynal
  2026-05-07 16:46 ` [PATCH v5 01/28] mtd: spi-nor: Drop duplicate Kconfig dependency Miquel Raynal
                   ` (28 more replies)
  0 siblings, 29 replies; 40+ messages in thread
From: Miquel Raynal @ 2026-05-07 16:46 UTC (permalink / raw)
  To: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
	Richard Weinberger, Vignesh Raghavendra, Jonathan Corbet,
	Tudor Ambarus, Shuah Khan
  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 v5:
- Fixed the writing of SR2 in the locking ops for devices without RDCR
  capability.
- Moved the ioctl comments to an existing comment as advised by
  Pratyush.
- Changed the documentation to use the concept of lock sector instead of
  block because on small density devices, the two amounts are typically
  different.
- Renamed the debugfs output "#blocks" -> "#sectors" for the same
  reason.
- Added a patch to make sure the QE bit is not badly overwritten when
  using the core's SR/CR status write helpers.
- Link to v4: https://lore.kernel.org/r/20260403-winbond-v6-18-rc1-spi-nor-swp-v4-0-833dab5e7288@bootlin.com

Changes in v4:
- Make sure we don't try to show the (SR specific) debugfs info if the
  chip does not support an SR based locking scheme. For this, add a new
  helper to derive whether we are using the default ops or not.
- Fix compilation issue on arm32, by using div_u64.
- Link to v3: https://lore.kernel.org/r/20260317-winbond-v6-18-rc1-spi-nor-swp-v3-0-2ca9ea4e7b9b@bootlin.com

Changes in v3:
- No change at all, just rebased on top of v7.0-rc1.
- Collected 2 R-by from M. Walle.
- Link to v2: https://lore.kernel.org/r/20260108-winbond-v6-18-rc1-spi-nor-swp-v2-0-c462ef806130@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 (28):
      mtd: spi-nor: Drop duplicate Kconfig dependency
      mtd: spi-nor: debugfs: Fix the flags list
      mtd: spi-nor: Make sure the QE bit is kept enabled if useful
      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 | 169 +++++++++++++++
 drivers/mtd/spi-nor/Kconfig              |   1 -
 drivers/mtd/spi-nor/core.c               |  78 ++++++-
 drivers/mtd/spi-nor/core.h               |  25 ++-
 drivers/mtd/spi-nor/debugfs.c            |  69 +++++-
 drivers/mtd/spi-nor/swp.c                | 359 ++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/winbond.c            |  41 +++-
 include/linux/mtd/spi-nor.h              |   7 +-
 8 files changed, 656 insertions(+), 93 deletions(-)
---
base-commit: 2df04c01437d44ea7cac641cb4d0c9fd1275df45
change-id: 20251114-winbond-v6-18-rc1-spi-nor-swp-865d36f4f695

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


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

end of thread, other threads:[~2026-05-22 16:39 UTC | newest]

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

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