Skip to contentSkip to conversation

mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE

PATCH In review Adrian Hunter 4 participants 6 messages Jul 10, 2024 – Jul 11, 2024

Subsystems (3)
lore
Share & tools
lore

Adrian Hunter

author maintainer
#0 lore raw

PATCH 1/1 mmc: sdhci: Fix max_seg_size for 64KiB PAGE_SIZE

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")
---
 drivers/mmc/host/sdhci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/mmc/host/sdhci.c +15 -0
index a20df9383b20..4b91c9e96635 100644
@@ -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;
 		}
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Adrian Hunter

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:

author maintainer
#2 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Adrian Hunter

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);
Quoted 5 lines

Except for that:

#3 lore raw
Quoted 7 lines · Adrian Hunter
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Adrian Hunter

blk_queue_max_segment_size() ensured:

	if (max_size < PAGE_SIZE)
		max_size = PAGE_SIZE;
Quoted 8 lines
Quoted 3 lines

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.

maintainer Acked-by Tested-by on v1 1/1
#4 lore raw
In reply to Adrian Hunter
Quoted 40 lines · Adrian Hunter

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")
---
  drivers/mmc/host/sdhci.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
drivers/mmc/host/sdhci.c +8 -0
index a20df9383b20..4b91c9e96635 100644
@@ -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

drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4728

Quoted 10 lines
drivers/mmc/host/sdhci.c +7 -0
+			 * 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;
  		}

Thanks!
Jon

Signature · 1 line
nvpublic
#5 lore raw
In reply to Adrian Hunter
Quoted 13 lines · Adrian Hunter

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;
Quoted 8 lines

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")

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

Quoted 33 lines
---
 drivers/mmc/host/sdhci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/mmc/host/sdhci.c +15 -1
index a20df9383b20..4b91c9e96635 100644
@@ -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