linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] nvme: retain split access workaround for capability reads
@ 2019-10-02  7:36 Ard Biesheuvel
  2019-10-02 22:05 ` Nadolski, Edmund
  2019-10-03 11:49 ` Keith Busch
  0 siblings, 2 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2019-10-02  7:36 UTC (permalink / raw)
  To: linux-nvme; +Cc: sagi, Ard Biesheuvel, ilias.apalodimas, axboe, kbusch, hch

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.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
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(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index c0808f9eb8ab..bb012075fbb2 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -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;
 }
 
-- 
2.20.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] nvme: retain split access workaround for capability reads
  2019-10-02  7:36 [RFC PATCH] nvme: retain split access workaround for capability reads Ard Biesheuvel
@ 2019-10-02 22:05 ` Nadolski, Edmund
  2019-10-03 11:49 ` Keith Busch
  1 sibling, 0 replies; 7+ messages in thread
From: Nadolski, Edmund @ 2019-10-02 22:05 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-nvme; +Cc: axboe, kbusch, ilias.apalodimas, sagi, hch

On 10/2/2019 1:36 AM, Ard Biesheuvel wrote:
> 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.

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

> 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

> This fixes a boot issue on some ARM boxes with NVMe behind a
> Synopsys DesignWare PCIe host controller.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 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(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index c0808f9eb8ab..bb012075fbb2 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -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
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] nvme: retain split access workaround for capability reads
  2019-10-02  7:36 [RFC PATCH] nvme: retain split access workaround for capability reads Ard Biesheuvel
  2019-10-02 22:05 ` Nadolski, Edmund
@ 2019-10-03 11:49 ` Keith Busch
  2019-10-03 11:51   ` Ard Biesheuvel
  1 sibling, 1 reply; 7+ messages in thread
From: Keith Busch @ 2019-10-03 11:49 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: axboe, ilias.apalodimas, sagi, linux-nvme, hch

On Wed, Oct 02, 2019 at 09:36:43AM +0200, Ard Biesheuvel wrote:
> 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.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 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
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] nvme: retain split access workaround for capability reads
  2019-10-03 11:49 ` Keith Busch
@ 2019-10-03 11:51   ` Ard Biesheuvel
  2019-10-03 12:03     ` Keith Busch
  0 siblings, 1 reply; 7+ messages in thread
From: Ard Biesheuvel @ 2019-10-03 11:51 UTC (permalink / raw)
  To: Keith Busch; +Cc: axboe, Ilias Apalodimas, sagi, linux-nvme, Christoph Hellwig

On Thu, 3 Oct 2019 at 13:49, Keith Busch <kbusch@kernel.org> wrote:
>
> On Wed, Oct 02, 2019 at 09:36:43AM +0200, Ard Biesheuvel wrote:
> > 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.
> >
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > ---
> > 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.

> 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
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] nvme: retain split access workaround for capability reads
  2019-10-03 11:51   ` Ard Biesheuvel
@ 2019-10-03 12:03     ` Keith Busch
  2019-10-03 12:05       ` Ard Biesheuvel
  0 siblings, 1 reply; 7+ messages in thread
From: Keith Busch @ 2019-10-03 12:03 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: axboe, Ilias Apalodimas, sagi, linux-nvme, Christoph Hellwig

On Thu, Oct 03, 2019 at 01:51:03PM +0200, Ard Biesheuvel wrote:
> On Thu, 3 Oct 2019 at 13:49, Keith Busch <kbusch@kernel.org> wrote:
> > On Wed, Oct 02, 2019 at 09:36:43AM +0200, Ard Biesheuvel wrote:
> > > 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
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] nvme: retain split access workaround for capability reads
  2019-10-03 12:03     ` Keith Busch
@ 2019-10-03 12:05       ` Ard Biesheuvel
  2019-10-04 21:57         ` Sagi Grimberg
  0 siblings, 1 reply; 7+ messages in thread
From: Ard Biesheuvel @ 2019-10-03 12:05 UTC (permalink / raw)
  To: Keith Busch; +Cc: axboe, Ilias Apalodimas, sagi, linux-nvme, Christoph Hellwig

On Thu, 3 Oct 2019 at 14:03, Keith Busch <kbusch@kernel.org> wrote:
>
> On Thu, Oct 03, 2019 at 01:51:03PM +0200, Ard Biesheuvel wrote:
> > On Thu, 3 Oct 2019 at 13:49, Keith Busch <kbusch@kernel.org> wrote:
> > > On Wed, Oct 02, 2019 at 09:36:43AM +0200, Ard Biesheuvel wrote:
> > > > 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.

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

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] nvme: retain split access workaround for capability reads
  2019-10-03 12:05       ` Ard Biesheuvel
@ 2019-10-04 21:57         ` Sagi Grimberg
  0 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2019-10-04 21:57 UTC (permalink / raw)
  To: Ard Biesheuvel, Keith Busch
  Cc: axboe, Ilias Apalodimas, Christoph Hellwig, linux-nvme


>>>>> 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.
> 
> 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
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-10-04 21:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02  7:36 [RFC PATCH] nvme: retain split access workaround for capability reads Ard Biesheuvel
2019-10-02 22:05 ` Nadolski, Edmund
2019-10-03 11:49 ` Keith Busch
2019-10-03 11:51   ` Ard Biesheuvel
2019-10-03 12:03     ` Keith Busch
2019-10-03 12:05       ` Ard Biesheuvel
2019-10-04 21:57         ` Sagi Grimberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).