[PATCHv2 1/2] nvme-pci: clear shadow doorbell memory on resets

John Levon levon at movementarian.org
Thu Oct 14 14:21:25 PDT 2021


On Thu, Oct 14, 2021 at 09:45:42AM -0700, Keith Busch wrote:

> The host memory doorbell and event buffers need to be initialized on
> each reset so the driver doesn't observe stale values from the previous
> instantiation.
> 
> Signed-off-by: Keith Busch <kbusch at kernel.org>

I reverted our workaround and tried this patch with my simple test case:

mkfs /dev/nvme0n1
echo 1 >/sys/devices/pci0000:00/0000:00:06.0/reset
mkfs /dev/nvme0n1

Works fine where previously it would essentially permanently hang the
controller.

Tested-by: John Levon <john.levon at nutanix.com>

thanks
john

> ---
>  drivers/nvme/host/pci.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 0dd4b44b59cd..9dd173bfa57b 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -245,8 +245,15 @@ static int nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
>  {
>  	unsigned int mem_size = nvme_dbbuf_size(dev);
>  
> -	if (dev->dbbuf_dbs)
> +	if (dev->dbbuf_dbs) {
> +		/*
> +		 * Clear the dbbuf memory so the driver doesn't observe stale
> +		 * values from the previous instantiation.
> +		 */
> +		memset(dev->dbbuf_dbs, 0, mem_size);
> +		memset(dev->dbbuf_eis, 0, mem_size);
>  		return 0;
> +	}
>  
>  	dev->dbbuf_dbs = dma_alloc_coherent(dev->dev, mem_size,
>  					    &dev->dbbuf_dbs_dma_addr,



More information about the Linux-nvme mailing list