NVMe write protection support

Christoph Hellwig hch at infradead.org
Mon Sep 19 07:59:05 PDT 2022


On Tue, Sep 13, 2022 at 07:17:57PM +0200, Gilles BULOZ wrote:
> But in my case the WP pin when enabled would make the initial state of the
> namespace at the time of its creation be "Write Protect". Or I could
> simulate a transition from "No Write Protect" to "Write Protect" but this
> would be without "Set Features" command.
> In both cases I would be out of specs.

I don't think you need that.  Just set bit 0 of the NSATTR field in
the Identify Namespace stucture to 1 and ignore the Set/Get Features
parts.  If your pin can be chaned at runtime, make sure that the bit
is updated based on it and that the Namespace Attribute Changed
AEN is sent when that happens.

> Also if the implementation is correct in the NVMe, and assuming the kernel
> already supports this case gracefully, what king of kernel message would I
> get (in dmesg) in case of a write to a protected device ?

Opening a block devie that was set to read only before will return
-EACCES.  If it is set to read-only after it was opened there is no
special handling and you'll get a good old -EIO.




More information about the Linux-nvme mailing list