Skip to contentSkip to conversation

nvme: retain split access workaround for capability reads

RFC PATCH Superseded Ard Biesheuvel 4 participants 7 messages Oct 2, 2019 – Oct 4, 2019 NVMe

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 nvme: retain split access workaround for capability reads

Recent changes to the NVMe core have re-introduced an issue that we have attempted to work around in the past, in commit a310acd7a7ea ("NVMe: use split lo_hi_{read,write}q").

The problem is that some PCIe NVMe controllers do not implement 64-bit outbound accesses correctly, which is why the commit above switched to using lo_hi_[read|write]q for all 64-bit BAR accesses.

In the mean time, the NVMe subsystem has been refactored, and now calls into the PCIe support layer for NVMe via a .reg_read64() method, which fails to use lo_hi_readq(), and thus reintroduces the problem that the commit above aimed to address.

Given that, at the moment, .reg_read64() is only used to read the capability register [which is known to tolerate split reads, which is not guaranteed in the general case, given that the NVMe BAR may be non-prefetchable], let's switch .reg_read64() to lo_hi_readq() as well.

To ensure that we will spot any changes that will start using the .reg_read64() method for other purposes, WARN() if the requested offset != NVME_REG_CAP.

This fixes a boot issue on some ARM boxes with NVMe behind a Synopsys DesignWare PCIe host controller.

---
Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Given that reg_read64() is only used in a single place to read the capability register, it would be cleaner to just drop it and add a .reg_readcap() method instead, but this is a more invasive change.

 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index c0808f9eb8ab..bb012075fbb2 100644
@@ -2672,7 +2672,8 @@ static int nvme_pci_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)
 
 static int nvme_pci_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val)
 {
-	*val = readq(to_nvme_dev(ctrl)->bar + off);
+	WARN_ON(off != NVME_REG_CAP);
+	*val = lo_hi_readq(to_nvme_dev(ctrl)->bar + off);
 	return 0;
 }
 
Signature · 7 lines
2.20.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#1 lore raw
Quoted 13 lines · Ard Biesheuvel

Recent changes to the NVMe core have re-introduced an issue that we have attempted to work around in the past, in commit a310acd7a7ea ("NVMe: use split lo_hi_{read,write}q").

The problem is that some PCIe NVMe controllers do not implement 64-bit outbound accesses correctly, which is why the commit above switched to using lo_hi_[read|write]q for all 64-bit BAR accesses.

In the mean time, the NVMe subsystem has been refactored, and now calls into the PCIe support layer for NVMe via a .reg_read64() method, which fails to use lo_hi_readq(), and thus reintroduces the problem that the commit above aimed to address.

Quoted 5 lines

Given that, at the moment, .reg_read64() is only used to read the capability register [which is known to tolerate split reads, which is not guaranteed in the general case, given that the NVMe BAR may be non-prefetchable], let's switch .reg_read64() to lo_hi_readq() as well.

Might be good to include this as a comment, for clarity and so it won't get refactored out again.

Quoted 3 lines

To ensure that we will spot any changes that will start using the .reg_read64() method for other purposes, WARN() if the requested offset != NVME_REG_CAP.

Would WARN_ONCE() suffice?

Ed

Quoted 21 lines

This fixes a boot issue on some ARM boxes with NVMe behind a Synopsys DesignWare PCIe host controller.

---
Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Given that reg_read64() is only used in a single place to read the capability register, it would be cleaner to just drop it and add a .reg_readcap() method instead, but this is a more invasive change.

  drivers/nvme/host/pci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +0 -0
index c0808f9eb8ab..bb012075fbb2 100644

drivers/nvme/host/pci.c static int nvme_pci_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val) · line 2679

Quoted 9 lines
drivers/nvme/host/pci.c +2 -1
@@ -2672,7 +2672,8 @@ static int nvme_pci_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)
 
  static int nvme_pci_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val)
  {
-	*val = readq(to_nvme_dev(ctrl)->bar + off);
+	WARN_ON(off != NVME_REG_CAP);
+	*val = lo_hi_readq(to_nvme_dev(ctrl)->bar + off);
  	return 0;
  }
 

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#2 lore raw
In reply to Ard Biesheuvel
Quoted 23 lines · Ard Biesheuvel

Recent changes to the NVMe core have re-introduced an issue that we have attempted to work around in the past, in commit a310acd7a7ea ("NVMe: use split lo_hi_{read,write}q").

The problem is that some PCIe NVMe controllers do not implement 64-bit outbound accesses correctly, which is why the commit above switched to using lo_hi_[read|write]q for all 64-bit BAR accesses.

In the mean time, the NVMe subsystem has been refactored, and now calls into the PCIe support layer for NVMe via a .reg_read64() method, which fails to use lo_hi_readq(), and thus reintroduces the problem that the commit above aimed to address.

Given that, at the moment, .reg_read64() is only used to read the capability register [which is known to tolerate split reads, which is not guaranteed in the general case, given that the NVMe BAR may be non-prefetchable], let's switch .reg_read64() to lo_hi_readq() as well.

To ensure that we will spot any changes that will start using the .reg_read64() method for other purposes, WARN() if the requested offset != NVME_REG_CAP.

Quoted 7 lines

This fixes a boot issue on some ARM boxes with NVMe behind a Synopsys DesignWare PCIe host controller.

---
Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Since 5.3?! 'git blame' says the code has been this way since 7fd8930f26be4, which was from 2015 during the 4.4 development cycle.

Please add a:

Fixes 7fd8930f26be4 ("nvme: add a common helper to read Identify Controller data")

to your change log above your sign-off, and remove the WARN_ON().

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#3 lore raw
Quoted 28 lines · Keith Busch
Quoted 26 lines · Ard Biesheuvel

Recent changes to the NVMe core have re-introduced an issue that we have attempted to work around in the past, in commit a310acd7a7ea ("NVMe: use split lo_hi_{read,write}q").

The problem is that some PCIe NVMe controllers do not implement 64-bit outbound accesses correctly, which is why the commit above switched to using lo_hi_[read|write]q for all 64-bit BAR accesses.

In the mean time, the NVMe subsystem has been refactored, and now calls into the PCIe support layer for NVMe via a .reg_read64() method, which fails to use lo_hi_readq(), and thus reintroduces the problem that the commit above aimed to address.

Given that, at the moment, .reg_read64() is only used to read the capability register [which is known to tolerate split reads, which is not guaranteed in the general case, given that the NVMe BAR may be non-prefetchable], let's switch .reg_read64() to lo_hi_readq() as well.

To ensure that we will spot any changes that will start using the .reg_read64() method for other purposes, WARN() if the requested offset != NVME_REG_CAP.

This fixes a boot issue on some ARM boxes with NVMe behind a Synopsys DesignWare PCIe host controller.

Quoted 8 lines
Quoted 4 lines

---
Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Since 5.3?! 'git blame' says the code has been this way since 7fd8930f26be4, which was from 2015 during the 4.4 development cycle.

That may be true, but the box in question happily boots a v5.2 kernel.

Quoted 5 lines

Please add a:

Fixes 7fd8930f26be4 ("nvme: add a common helper to read Identify Controller data")

to your change log above your sign-off, and remove the WARN_ON().

Sure.

Thanks,
Ard.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#4 lore raw
Quoted 10 lines · Ard Biesheuvel
Quoted 7 lines · Keith Busch
Quoted 2 lines · Ard Biesheuvel

Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Since 5.3?! 'git blame' says the code has been this way since 7fd8930f26be4, which was from 2015 during the 4.4 development cycle.

That may be true, but the box in question happily boots a v5.2 kernel.

Looks like your observation was introduced with c0f2f45be2976abe.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#5 lore raw
Quoted 7 lines · Keith Busch
Quoted 5 lines · Ard Biesheuvel
Quoted 4 lines · Keith Busch
Quoted 2 lines · Ard Biesheuvel

Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Since 5.3?! 'git blame' says the code has been this way since 7fd8930f26be4, which was from 2015 during the 4.4 development cycle.

That may be true, but the box in question happily boots a v5.2 kernel.

Looks like your observation was introduced with c0f2f45be2976abe.

Indeed. The corrupted read produces a bogus minimum page size, and the driver gives up.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#6 lore raw
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Broken since v5.3, so if this gets fixed one way or the other, please add cc: stable.

Since 5.3?! 'git blame' says the code has been this way since 7fd8930f26be4, which was from 2015 during the 4.4 development cycle.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

That may be true, but the box in question happily boots a v5.2 kernel.

Looks like your observation was introduced with c0f2f45be2976abe.

Indeed. The corrupted read produces a bogus minimum page size, and the driver gives up.

Oops... Sorry... But in all fairness that was bound to happen at some point...

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme