nvme-pci: add a memory barrier to nvme_dbbuf_update_and_check_event
Subsystems (2)
commit ID: f1ed3df20d2d223e0852cc4ac1f19bba869a7e3c
Please merge this patch into stable tree (already exist in Linus’ tree). The initial patch submission lacked "Cc: [email protected]" by mistake. The kernel versions that should get patch:
4.19
4.18
4.14
Quoted 1 line
From
f1ed3df20d2d223e0852cc4ac1f19bba869a7e3cMon Sep 17 00:00:00 2001
From: Michal Wnukowski <[email protected]>
Date: Wed, 15 Aug 2018 15:51:57 -0700
Subject: nvme-pci: add a memory barrier to nvme_dbbuf_update_and_check_event
In many architectures loads may be reordered with older stores to different locations. In the nvme driver the following two operations could be reordered:
- Write shadow doorbell (dbbuf_db) into memory.
- Read EventIdx (dbbuf_ei) from memory.
This can result in a potential race condition between driver and VM host processing requests (if given virtual NVMe controller has a support for shadow doorbell). If that occurs, then the NVMe controller may decide to wait for MMIO doorbell from guest operating system, and guest driver may decide not to issue MMIO doorbell on any of subsequent commands.
This issue is purely timing-dependent one, so there is no easy way to reproduce it. Currently the easiest known approach is to run "Oracle IO Numbers" (orion) that is shipped with Oracle DB:
orion -run advanced -num_large 0 -size_small 8 -type rand -simulate \
concat -write 40 -duration 120 -matrix row -testname nvme_test
Where nvme_test is a .lun file that contains a list of NVMe block devices to run test against. Limiting number of vCPUs assigned to given VM instance seems to increase chances for this bug to occur. On test environment with VM that got 4 NVMe drives and 1 vCPU assigned the virtual NVMe controller hang could be observed within 10-20 minutes. That correspond to about 400-500k IO operations processed (or about 100GB of IO read/writes).
Orion tool was used as a validation and set to run in a loop for 36 hours (equivalent of pushing 550M IO operations). No issues were observed. That suggest that the patch fixes the issue.
--- drivers/nvme/host/pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)
(limited to 'drivers/nvme/host/pci.c')
drivers/nvme/host/pci.c +8 -0
@@ -316,6 +316,14 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, u32 *dbbuf_db, old_value = *dbbuf_db; *dbbuf_db = value; +/* +* Ensure that the doorbell is updated before reading the event +* index from memory. The controller needs to provide similar +* ordering to ensure the envent index is updated before reading +* the doorbell. +*/ +mb (); +if (!nvme_dbbuf_need_event (*dbbuf_ei, value, old_value))return false; }
Signature · 1 line
cgit 1.2-0.3.lf.el7
Quoted 8 lines · Michal Wnukowski
commit ID:
f1ed3df20d2d223e0852cc4ac1f19bba869a7e3cPlease merge this patch into stable tree (already exist in Linus’ tree). The initial patch submission lacked "Cc: [email protected]" by mistake. The kernel versions that should get patch:
4.19
4.18
4.14
Now queued up, thanks.
greg k-h