* [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE
@ 2024-07-10 18:07 Adrian Hunter
2024-07-11 4:01 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Adrian Hunter @ 2024-07-10 18:07 UTC (permalink / raw)
To: Ulf Hansson
Cc: Jon Hunter, Christoph Hellwig, Jens Axboe, Thierry Reding,
linux-tegra, linux-mmc
blk_queue_max_segment_size() ensured:
if (max_size < PAGE_SIZE)
max_size = PAGE_SIZE;
whereas:
blk_validate_limits() makes it an error:
if (WARN_ON_ONCE(lim->max_segment_size < PAGE_SIZE))
return -EINVAL;
The change from one to the other, exposed sdhci which was setting maximum
segment size too low in some circumstances.
Fix the maximum segment size when it is too low.
Fixes: 616f87661792 ("mmc: pass queue_limits to blk_mq_alloc_disk")
Cc: stable@vger.kernel.org
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
drivers/mmc/host/sdhci.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index a20df9383b20..4b91c9e96635 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -4708,6 +4708,21 @@ int sdhci_setup_host(struct sdhci_host *host)
if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) {
host->max_adma = 65532; /* 32-bit alignment */
mmc->max_seg_size = 65535;
+ /*
+ * sdhci_adma_table_pre() expects to define 1 DMA
+ * descriptor per segment, so the maximum segment size
+ * is set accordingly. SDHCI allows up to 64KiB per DMA
+ * descriptor (16-bit field), but some controllers do
+ * not support "zero means 65536" reducing the maximum
+ * for them to 65535. That is a problem if PAGE_SIZE is
+ * 64KiB because the block layer does not support
+ * max_seg_size < PAGE_SIZE, however
+ * sdhci_adma_table_pre() has a workaround to handle
+ * that case, and split the descriptor. Refer also
+ * comment in sdhci_adma_table_pre().
+ */
+ if (mmc->max_seg_size < PAGE_SIZE)
+ mmc->max_seg_size = PAGE_SIZE;
} else {
mmc->max_seg_size = 65536;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE
2024-07-10 18:07 [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE Adrian Hunter
@ 2024-07-11 4:01 ` Christoph Hellwig
2024-07-11 5:17 ` Adrian Hunter
2024-07-11 9:47 ` Jon Hunter
2024-07-11 16:03 ` Ulf Hansson
2 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2024-07-11 4:01 UTC (permalink / raw)
To: Adrian Hunter
Cc: Ulf Hansson, Jon Hunter, Christoph Hellwig, Jens Axboe,
Thierry Reding, linux-tegra, linux-mmc
On Wed, Jul 10, 2024 at 09:07:37PM +0300, Adrian Hunter wrote:
> blk_queue_max_segment_size() ensured:
>
> if (max_size < PAGE_SIZE)
> max_size = PAGE_SIZE;
This is a bit misleading, as it also warned about it and papered over it
with the above as it had no way to return errors. Any everyone seeing
these problems now ignored the warnings before, probably for years..
Except for that:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE
2024-07-11 4:01 ` Christoph Hellwig
@ 2024-07-11 5:17 ` Adrian Hunter
2024-07-11 6:48 ` Christoph Hellwig
0 siblings, 1 reply; 6+ messages in thread
From: Adrian Hunter @ 2024-07-11 5:17 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Ulf Hansson, Jon Hunter, Jens Axboe, Thierry Reding, linux-tegra,
linux-mmc
On 11/07/24 07:01, Christoph Hellwig wrote:
> On Wed, Jul 10, 2024 at 09:07:37PM +0300, Adrian Hunter wrote:
>> blk_queue_max_segment_size() ensured:
>>
>> if (max_size < PAGE_SIZE)
>> max_size = PAGE_SIZE;
>
> This is a bit misleading, as it also warned about it and papered over it
> with the above as it had no way to return errors. Any everyone seeing
> these problems now ignored the warnings before, probably for years..
Was there a warning, since the message in blk_queue_max_segment_size()
was:
pr_info("%s: set to minimum %u\n", __func__, max_size);
>
> Except for that:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE
2024-07-11 5:17 ` Adrian Hunter
@ 2024-07-11 6:48 ` Christoph Hellwig
0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2024-07-11 6:48 UTC (permalink / raw)
To: Adrian Hunter
Cc: Christoph Hellwig, Ulf Hansson, Jon Hunter, Jens Axboe,
Thierry Reding, linux-tegra, linux-mmc
On Thu, Jul 11, 2024 at 08:17:47AM +0300, Adrian Hunter wrote:
> On 11/07/24 07:01, Christoph Hellwig wrote:
> > On Wed, Jul 10, 2024 at 09:07:37PM +0300, Adrian Hunter wrote:
> >> blk_queue_max_segment_size() ensured:
> >>
> >> if (max_size < PAGE_SIZE)
> >> max_size = PAGE_SIZE;
> >
> > This is a bit misleading, as it also warned about it and papered over it
> > with the above as it had no way to return errors. Any everyone seeing
> > these problems now ignored the warnings before, probably for years..
>
> Was there a warning, since the message in blk_queue_max_segment_size()
> was:
>
> pr_info("%s: set to minimum %u\n", __func__, max_size);
It stated out as a plain printk and became an info later, but yes,
not the big warning sign it was supposed to be.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE
2024-07-10 18:07 [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE Adrian Hunter
2024-07-11 4:01 ` Christoph Hellwig
@ 2024-07-11 9:47 ` Jon Hunter
2024-07-11 16:03 ` Ulf Hansson
2 siblings, 0 replies; 6+ messages in thread
From: Jon Hunter @ 2024-07-11 9:47 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Christoph Hellwig, Jens Axboe, Thierry Reding, linux-tegra,
linux-mmc
On 10/07/2024 19:07, Adrian Hunter wrote:
> blk_queue_max_segment_size() ensured:
>
> if (max_size < PAGE_SIZE)
> max_size = PAGE_SIZE;
>
> whereas:
>
> blk_validate_limits() makes it an error:
>
> if (WARN_ON_ONCE(lim->max_segment_size < PAGE_SIZE))
> return -EINVAL;
>
> The change from one to the other, exposed sdhci which was setting maximum
> segment size too low in some circumstances.
>
> Fix the maximum segment size when it is too low.
>
> Fixes: 616f87661792 ("mmc: pass queue_limits to blk_mq_alloc_disk")
> Cc: stable@vger.kernel.org
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> drivers/mmc/host/sdhci.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index a20df9383b20..4b91c9e96635 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -4708,6 +4708,21 @@ int sdhci_setup_host(struct sdhci_host *host)
> if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) {
> host->max_adma = 65532; /* 32-bit alignment */
> mmc->max_seg_size = 65535;
> + /*
> + * sdhci_adma_table_pre() expects to define 1 DMA
> + * descriptor per segment, so the maximum segment size
> + * is set accordingly. SDHCI allows up to 64KiB per DMA
> + * descriptor (16-bit field), but some controllers do
> + * not support "zero means 65536" reducing the maximum
> + * for them to 65535. That is a problem if PAGE_SIZE is
> + * 64KiB because the block layer does not support
> + * max_seg_size < PAGE_SIZE, however
> + * sdhci_adma_table_pre() has a workaround to handle
> + * that case, and split the descriptor. Refer also
> + * comment in sdhci_adma_table_pre().
> + */
> + if (mmc->max_seg_size < PAGE_SIZE)
> + mmc->max_seg_size = PAGE_SIZE;
> } else {
> mmc->max_seg_size = 65536;
> }
Acked-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Thanks!
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE
2024-07-10 18:07 [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE Adrian Hunter
2024-07-11 4:01 ` Christoph Hellwig
2024-07-11 9:47 ` Jon Hunter
@ 2024-07-11 16:03 ` Ulf Hansson
2 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2024-07-11 16:03 UTC (permalink / raw)
To: Adrian Hunter
Cc: Jon Hunter, Christoph Hellwig, Jens Axboe, Thierry Reding,
linux-tegra, linux-mmc
On Wed, 10 Jul 2024 at 20:09, Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> blk_queue_max_segment_size() ensured:
>
> if (max_size < PAGE_SIZE)
> max_size = PAGE_SIZE;
>
> whereas:
>
> blk_validate_limits() makes it an error:
>
> if (WARN_ON_ONCE(lim->max_segment_size < PAGE_SIZE))
> return -EINVAL;
>
> The change from one to the other, exposed sdhci which was setting maximum
> segment size too low in some circumstances.
>
> Fix the maximum segment size when it is too low.
>
> Fixes: 616f87661792 ("mmc: pass queue_limits to blk_mq_alloc_disk")
> Cc: stable@vger.kernel.org
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Applied for fixes, thanks!
If we want to log a message due to the wrong max_seg_size, let's do
that from a patch on top.
Kind regards
Uffe
> ---
> drivers/mmc/host/sdhci.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index a20df9383b20..4b91c9e96635 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -4708,6 +4708,21 @@ int sdhci_setup_host(struct sdhci_host *host)
> if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) {
> host->max_adma = 65532; /* 32-bit alignment */
> mmc->max_seg_size = 65535;
> + /*
> + * sdhci_adma_table_pre() expects to define 1 DMA
> + * descriptor per segment, so the maximum segment size
> + * is set accordingly. SDHCI allows up to 64KiB per DMA
> + * descriptor (16-bit field), but some controllers do
> + * not support "zero means 65536" reducing the maximum
> + * for them to 65535. That is a problem if PAGE_SIZE is
> + * 64KiB because the block layer does not support
> + * max_seg_size < PAGE_SIZE, however
> + * sdhci_adma_table_pre() has a workaround to handle
> + * that case, and split the descriptor. Refer also
> + * comment in sdhci_adma_table_pre().
> + */
> + if (mmc->max_seg_size < PAGE_SIZE)
> + mmc->max_seg_size = PAGE_SIZE;
> } else {
> mmc->max_seg_size = 65536;
> }
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-07-11 16:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-10 18:07 [PATCH] mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE Adrian Hunter
2024-07-11 4:01 ` Christoph Hellwig
2024-07-11 5:17 ` Adrian Hunter
2024-07-11 6:48 ` Christoph Hellwig
2024-07-11 9:47 ` Jon Hunter
2024-07-11 16:03 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox