{"id":2219626,"url":"http://patchwork.ozlabs.org/api/1.0/covers/2219626/?format=json","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/1.0/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260403-winbond-v6-18-rc1-spi-nor-swp-v4-0-833dab5e7288@bootlin.com>","date":"2026-04-03T16:09:18","name":"[v4,00/27] mtd: spi-nor: Enhance software protection","submitter":{"id":73368,"url":"http://patchwork.ozlabs.org/api/1.0/people/73368/?format=json","name":"Miquel Raynal","email":"miquel.raynal@bootlin.com"},"series":[{"id":498652,"url":"http://patchwork.ozlabs.org/api/1.0/series/498652/?format=json","date":"2026-04-03T16:09:18","name":"mtd: spi-nor: Enhance software protection","version":4,"mbox":"http://patchwork.ozlabs.org/series/498652/mbox/"}],"headers":{"Return-Path":"\n <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=FyL9DHL3;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256\n header.s=dkim header.b=dTophB3G;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fnNwB4mGMz1yCs\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 04 Apr 2026 03:09:46 +1100 (AEDT)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8h5Y-00000002GSY-0EZR;\n\tFri, 03 Apr 2026 16:09:40 +0000","from smtpout-02.galae.net ([185.246.84.56])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8h5U-00000002GJW-1NmK\n\tfor linux-mtd@lists.infradead.org;\n\tFri, 03 Apr 2026 16:09:38 +0000","from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233])\n\tby smtpout-02.galae.net (Postfix) with ESMTPS id D02F21A312B;\n\tFri,  3 Apr 2026 16:09:34 +0000 (UTC)","from mail.galae.net (mail.galae.net [212.83.136.155])\n\tby smtpout-01.galae.net (Postfix) with ESMTPS id A6AFF603C1;\n\tFri,  3 Apr 2026 16:09:34 +0000 (UTC)","from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon)\n with ESMTPSA id C39FD104500FA;\n\tFri,  3 Apr 2026 18:09:30 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Message-Id:Date:\n\tSubject:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:\n\tResent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:\n\tList-Owner; bh=atAeSIaGWOPEkymDJazkkgxchzSDbUfwIT+Vlqpa4o4=; b=FyL9DHL3FPXIAd\n\tcBQJkqnLUfTZclHQOxYZSeyrcfOI8T1umfJ/loJNH6cx8JBzu3RL9Cyx2gz3gVO5VDwGYe2nD8SPe\n\t27v7rjPm9T/RZ9i/n3/IF807tkZcEinSp23VuyqJ+dyaj+4pErShf/au6mr5co9mGhfbFaTDAG9x+\n\tVRAHz3B3vxPTq1vHdqe9aK5M184oKfhT4VhS0Xti3mHScihMGVtmCA3DZfaGitSIubyP986ownoPx\n\t76GmZFHQhcd/wOwvkZpWpZ2OY1CRpcTh2jGtDy5sW0lWgHZR05t0b7Uv99DGXT2jfnGXHzqBdwH2W\n\tBvj4ju+oj3kPZMQOO1/A==;","v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim;\n\tt=1775232573; h=from:subject:date:message-id:to:cc:mime-version:content-type:\n\t content-transfer-encoding; bh=lwx4GL+YP18+KXWG9qAxiqZd8QCkawuHr7FPaYnFw4I=;\n\tb=dTophB3GMl/tfwGd7FEpZfPrYX9Iz1VbfEXxyezCo8jYRtXz8k0N3bUYyYEMqV3aBwc2Ms\n\tg4/oRe65Zt9ngOgU3nCoGQ9Huua6vx4VIXW8uduM1zfu264H3PM/q4r5MhMpPDmEshaE+0\n\tEZnFqYBBKbvdA24+kSZL7hqvo8cKuF4LsD06vLQhQ4kUBa7s+f8XyanlKRfkLpirNI+732\n\t3A1eFWVq2KhXOFxtz1vMAoQDKd3DZ2Die1Wg9DlvA1SI65E2pczabdxeOrrIQ40d4+7Ohp\n\t8BqxhjN6Azzq21Pti02h+Sp9YCtI+Pf5jsfHi+hIkDbCUKCtYkZc/rC996wbJQ=="],"From":"Miquel Raynal <miquel.raynal@bootlin.com>","Subject":"[PATCH v4 00/27] mtd: spi-nor: Enhance software protection","Date":"Fri, 03 Apr 2026 18:09:18 +0200","Message-Id":"\n <20260403-winbond-v6-18-rc1-spi-nor-swp-v4-0-833dab5e7288@bootlin.com>","MIME-Version":"1.0","X-B4-Tracking":"v=1; b=H4sIAAAAAAAC/43NwW4CIRSF4VcxrL0NFxgGXPU9GhcDw+hNFCYwQ\n Rsz7140aZrGhS7/s/jOjZWQKRS229xYDpUKpdhCbTfMH4d4CEBjaya46BBRwYWiS3GEqgENZI9\n QZoKYMpTLDEZ3o9STmrTtWDPmHCa6PvyvfesjlSXl78ddxfv6rlwROCjTO9+jsFbip0tpOVH88\n OnM7nYVv57myM0rTzTPKy3CZLhGyZ89+edJ7F95snnCDzYMKvTOuv/euq4/YaCxcWwBAAA=","X-Change-ID":"20251114-winbond-v6-18-rc1-spi-nor-swp-865d36f4f695","To":"Pratyush Yadav <pratyush@kernel.org>, Michael Walle <mwalle@kernel.org>,\n Takahiro Kuwano <takahiro.kuwano@infineon.com>,\n Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>,\n Jonathan Corbet <corbet@lwn.net>","Cc":"Sean Anderson <sean.anderson@linux.dev>,\n Thomas Petazzoni <thomas.petazzoni@bootlin.com>,\n Steam Lin <STLin2@winbond.com>, linux-mtd@lists.infradead.org,\n linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,\n Miquel Raynal <miquel.raynal@bootlin.com>, stable@kernel.org","X-Mailer":"b4 0.14.3","X-Last-TLS-Session-Version":"TLSv1.3","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260403_090936_575867_D03F6779 ","X-CRM114-Status":"GOOD (  22.53  )","X-Spam-Score":"-2.1 (--)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  Hello, As recently raised on the mailing-list (link below),\n    it seems that the \"locking\" support in SPI NOR could benefit from some\n enhancements.\n    As I myself had to dig into it recently, here is a proposal.\n Content analysis details:   (-2.1 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n  0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to\n                              Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                             [185.246.84.56 listed in sa-accredit.habeas.com]\n  0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The\n                             query to Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                          [185.246.84.56 listed in\n sa-trusted.bondedsender.org]\n -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]\n  0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to\n                              Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                             [185.246.84.56 listed in\n bl.score.senderscore.com]","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"Hello,\n\nAs recently raised on the mailing-list (link below), it seems that the\n\"locking\" support in SPI NOR could benefit from some enhancements. As I\nmyself had to dig into it recently, here is a proposal.\n\nFirst issue that I see, the MEMLOCK ioctl is not behaving correctly\nin some cases, as addressed in:\n\n    mtd: spi-nor: swp: Improve locking user experience\n\nThen there is no clear explanation of the shortcuts taken by the kernel\nin terms of uAPI, so there is an attempt to list them in:\n\n    mtd: spi-nor: swp: Explain the MEMLOCK ioctl implementation behaviour\n\nPlus, Tudor also asked if we could cover locking in the testing\nprocedure, which is done in:\n\n    mtd: spi-nor: Add steps for testing locking support\n\nIn order to simplify this procedure, and because it got very helpful\nduring my testing/development, I want to propose additions to the\ndebugfs output:\n\n    mtd: spi-nor: debugfs: Add locking support TODO: make the captures again\n\nFinally, I am providing an implementation for the complement (CMP)\nfeature in order to allow finer control of the regions locked. This\nfeature is for instance available on Winbond chips:\n\n    [core] mtd: spi-nor: swp: Add support for the complement feature\n    [doc]  mtd: spi-nor: Add steps for testing locking with CMP\n    [use]  mtd: spi-nor: winbond: Add CMP locking support\n\nDisclaimer: it was much less straightforward than I initially thought to\nget the CMP feature working correctly. I tested it with as much focus as\nI could, and I am improving the test coverage for the new cases, I am\nalso providing extra test cases in the metadata of the commit (which do\nnot make sense to test for chip additions, but may be sensible show when\nmaking core additions like this one), but honestly there are so many\npossibilities, I may still be missing corner cases. I hope this will\nanyway be helpful to others!\n\nAll the other patches are misc improvements or style fixes which I faced\nand fixed during my development.\n\nLink: https://lore.kernel.org/linux-mtd/92e99a96-5582-48a5-a4f9-e9b33fcff171@linux.dev/\n\nSigned-off-by: Miquel Raynal <miquel.raynal@bootlin.com>\n---\nChanges in v4:\n- Make sure we don't try to show the (SR specific) debugfs info if the\n  chip does not support an SR based locking scheme. For this, add a new\n  helper to derive whether we are using the default ops or not.\n- Fix compilation issue on arm32, by using div_u64.\n- Link to v3: https://lore.kernel.org/r/20260317-winbond-v6-18-rc1-spi-nor-swp-v3-0-2ca9ea4e7b9b@bootlin.com\n\nChanges in v3:\n- No change at all, just rebased on top of v7.0-rc1.\n- Collected 2 R-by from M. Walle.\n- Link to v2: https://lore.kernel.org/r/20260108-winbond-v6-18-rc1-spi-nor-swp-v2-0-c462ef806130@bootlin.com\n\nChanges in v2:\n- Collect tags.\n- Add missing Fixes/Cc: stable tags.\n- Add a comment explaining why can_be_top && can_be_bottom is a specific\n  condition.\n- Fix commit logs following Michael Walle's reviews.\n- Amend the documentation following our discussion with Michael Walle as\n  well.\n- Cache the SR register for debugfs use.\n- Create a locked sector map file instead of dumping it as part of the\n  `params` file output.\n- Improved greatly the output of the map as suggested by Michael.\n- Add a patch fixing a duplicate dependency in Kconfig.\n- Add an important comment in the doc about the small 4kiB erase size\n  choice.\n- Add test runs for each and every chip for which the CMP feature is\n  added. This prove me that testing of each and every chip was needed,\n  as some of them seem to feature a broken BFPT table which does not\n  advertise a working 35h (Read CR) command.\n- Added a condition on which the CMP feature is enabled: RDCR must be\n  possible.\n- Link to v1: https://lore.kernel.org/r/20251114-winbond-v6-18-rc1-spi-nor-swp-v1-0-487bc7129931@bootlin.com\n\n---\nMiquel Raynal (27):\n      mtd: spi-nor: Drop duplicate Kconfig dependency\n      mtd: spi-nor: debugfs: Fix the flags list\n      mtd: spi-nor: swp: Improve locking user experience\n      mtd: spi-nor: Improve opcodes documentation\n      mtd: spi-nor: debugfs: Align variable access with the rest of the file\n      mtd: spi-nor: debugfs: Enhance output\n      mtd: spi-nor: swp: Explain the MEMLOCK ioctl implementation behaviour\n      mtd: spi-nor: swp: Clarify a comment\n      mtd: spi-nor: swp: Use a pointer for SR instead of a single byte\n      mtd: spi-nor: swp: Create a helper that writes SR, CR and checks\n      mtd: spi-nor: swp: Rename a mask\n      mtd: spi-nor: swp: Create a TB intermediate variable\n      mtd: spi-nor: swp: Create helpers for building the SR register\n      mtd: spi-nor: swp: Simplify checking the locked/unlocked range\n      mtd: spi-nor: swp: Cosmetic changes\n      mtd: spi-nor: Create a local SR cache\n      mtd: spi-nor: debugfs: Add locking support\n      mtd: spi-nor: debugfs: Add a locked sectors map\n      mtd: spi-nor: Add steps for testing locking support\n      mtd: spi-nor: swp: Add support for the complement feature\n      mtd: spi-nor: Add steps for testing locking with CMP\n      mtd: spi-nor: winbond: Add W25H512NWxxAM CMP locking support\n      mtd: spi-nor: winbond: Add W25H01NWxxAM CMP locking support\n      mtd: spi-nor: winbond: Add W25H02NWxxAM CMP locking support\n      mtd: spi-nor: winbond: Add W25H01NWxxIQ CMP locking support\n      mtd: spi-nor: winbond: Add W25Q01NWxxIM CMP locking support\n      mtd: spi-nor: winbond: Add W25Q02NWxxIM CMP locking support\n\n Documentation/driver-api/mtd/spi-nor.rst | 164 ++++++++++++++\n drivers/mtd/spi-nor/Kconfig              |   1 -\n drivers/mtd/spi-nor/core.c               |  74 ++++++-\n drivers/mtd/spi-nor/core.h               |  11 +\n drivers/mtd/spi-nor/debugfs.c            |  69 +++++-\n drivers/mtd/spi-nor/swp.c                | 364 ++++++++++++++++++++++++-------\n drivers/mtd/spi-nor/winbond.c            |  41 +++-\n include/linux/mtd/spi-nor.h              |   7 +-\n 8 files changed, 643 insertions(+), 88 deletions(-)\n---\nbase-commit: 2cd9033836346e630afaf847c4f1ced08c4d1846\nchange-id: 20251114-winbond-v6-18-rc1-spi-nor-swp-865d36f4f695\n\nBest regards,"}