NVMe write protection support

Gilles BULOZ gilles.buloz at kontron.com
Fri Sep 30 10:49:38 PDT 2022


Hi Christoph,
Our disk manufacturer told me their NVMe does not follow NVMe specification 2.0 but 1.3.
Is there also something in 1.3 to handle the write protection cleanly ?
Currently the only thing I get is a medium error, or an I/O error due to an aborted command leading to problems even when working at 
block device level (using dd) : the device file /dev/nvme0n1 disappears ! So I can't imaging what this would do with a real 
filesystem on top of that.
I'm using kernel 5.18.13 (fedora 36 with updates)
Thanks
Gilles

Le 19/09/2022 à 16:59, Christoph Hellwig a écrit :
> 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