Skip to contentSkip to conversation

efidisk: Breakup large reads into batches

PATCH In review Mate Kukri 3 participants 3 messages Feb 23, 2024

lore
Share & tools
lore

Mate Kukri

author
#0 lore raw

PATCH 1/1 efidisk: Breakup large reads into batches

From: David F <[email protected]>

Work around firmware bugs that cause large reads to fail from certain devices.

---
 grub-core/disk/efi/efidisk.c | 43 +++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 13 deletions(-)
grub-core/disk/efi/efidisk.c +30 -13
index 3b5ed5691..079b72ab7 100644
@@ -27,6 +27,9 @@
 #include <grub/efi/efi.h>
 #include <grub/efi/disk.h>
 
+/* break up io to prevent problems under some UEFI envrionments */
+#define EFIDISK_C_MAXIOSECS 0x100U
+
 struct grub_efidisk_data
 {
   grub_efi_handle_t handle;
@@ -599,20 +602,34 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
 		   grub_size_t size, char *buf)
 {
   grub_efi_status_t status;
+  grub_size_t sector_count;
 
-  grub_dprintf ("efidisk",
-		"reading 0x%lx sectors at the sector 0x%llx from %s\n",
-		(unsigned long) size, (unsigned long long) sector, disk->name);
-
-  status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
-
-  if (status == GRUB_EFI_NO_MEDIA)
-    return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name);
-  else if (status != GRUB_EFI_SUCCESS)
-    return grub_error (GRUB_ERR_READ_ERROR,
-		       N_("failure reading sector 0x%llx from `%s'"),
-		       (unsigned long long) sector,
-		       disk->name);
+  /* break up reads to EFIDISK_C_MAXIOSECS size chunks */
+  do
+    {
+      /* determine number of sectors this cycle */
+      sector_count = (size > EFIDISK_C_MAXIOSECS) ? EFIDISK_C_MAXIOSECS : size;
+
+      /* output debug information */
+      grub_dprintf ("efidisk",
+		    "reading 0x%lx sectors at the sector 0x%llx from %s\n",
+		    (unsigned long) sector_count, (unsigned long long) sector, disk->name);
+
+      status = grub_efidisk_readwrite (disk, sector, sector_count, buf, 0);
+
+      if (status == GRUB_EFI_NO_MEDIA)
+	return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name);
+      if (status != GRUB_EFI_SUCCESS)
+	return grub_error (GRUB_ERR_READ_ERROR,
+			   N_("failure reading 0x%lx sector(s) from sector 0x%llx on `%s'"),
+			   (unsigned long) sector_count, (unsigned long long) sector, disk->name);
+
+      /* next cycle */
+      buf += (grub_efi_uintn_t) sector_count << disk->log_sector_size;;
+      sector += sector_count;
+      size -= sector_count;
+    }
+  while (size);
 
   return GRUB_ERR_NONE;
 }
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

Why is setting max_agglomerate not enough to achieve the same effect?

Quoted 82 lines · Mate Kukri

From: David F <[email protected]>

Work around firmware bugs that cause large reads to fail from certain devices.

---
 grub-core/disk/efi/efidisk.c | 43 +++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 13 deletions(-)
grub-core/disk/efi/efidisk.c +30 -14
index 3b5ed5691..079b72ab7 100644
@@ -27,6 +27,9 @@
 #include <grub/efi/efi.h>
 #include <grub/efi/disk.h>
 
+/* break up io to prevent problems under some UEFI envrionments */
+#define EFIDISK_C_MAXIOSECS 0x100U
+
 struct grub_efidisk_data
 {
   grub_efi_handle_t handle;
@@ -599,20 +602,34 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
                   grub_size_t size, char *buf)
 {
   grub_efi_status_t status;
+  grub_size_t sector_count;
 
-  grub_dprintf ("efidisk",
-               "reading 0x%lx sectors at the sector 0x%llx from %s\n",
-               (unsigned long) size, (unsigned long long) sector, disk->name);
-
-  status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
-
-  if (status == GRUB_EFI_NO_MEDIA)
-    return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name);
-  else if (status != GRUB_EFI_SUCCESS)
-    return grub_error (GRUB_ERR_READ_ERROR,
-                      N_("failure reading sector 0x%llx from `%s'"),
-                      (unsigned long long) sector,
-                      disk->name);
+  /* break up reads to EFIDISK_C_MAXIOSECS size chunks */
+  do
+    {
+      /* determine number of sectors this cycle */
+      sector_count = (size > EFIDISK_C_MAXIOSECS) ? EFIDISK_C_MAXIOSECS : size;
+
+      /* output debug information */
+      grub_dprintf ("efidisk",
+                   "reading 0x%lx sectors at the sector 0x%llx from %s\n",
+                   (unsigned long) sector_count, (unsigned long long) sector, disk->name);
+
+      status = grub_efidisk_readwrite (disk, sector, sector_count, buf, 0);
+
+      if (status == GRUB_EFI_NO_MEDIA)
+       return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name);
+      if (status != GRUB_EFI_SUCCESS)
+       return grub_error (GRUB_ERR_READ_ERROR,
+                          N_("failure reading 0x%lx sector(s) from sector 0x%llx on `%s'"),
+                          (unsigned long) sector_count, (unsigned long long) sector, disk->name);
+
+      /* next cycle */
+      buf += (grub_efi_uintn_t) sector_count << disk->log_sector_size;;
+      sector += sector_count;
+      size -= sector_count;
+    }
+  while (size);
 
   return GRUB_ERR_NONE;
 }
--

2.39.2

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 7 lines
Regards
Vladimir 'phcoder' Serbinenko

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel