From d2dfdfe107651fa8f96751845381ea76e5e3872e Mon Sep 17 00:00:00 2001
From: rockyautomation <rockyautomation@rockylinux.org>
Date: Tue, 21 Sep 2021 20:59:10 +0000
Subject: [PATCH] import grub2-2.02-99.el8_4.1

---
 ...eee1275-ofdisk-retry-on-open-failure.patch | 103 ++++++++++++++++++
 SOURCES/grub.patches                          |   1 +
 SOURCES/sbat.csv.in                           |   1 +
 SPECS/grub2.spec                              |  23 ++--
 4 files changed, 120 insertions(+), 8 deletions(-)
 create mode 100644 SOURCES/0481-ieee1275-ofdisk-retry-on-open-failure.patch

diff --git a/SOURCES/0481-ieee1275-ofdisk-retry-on-open-failure.patch b/SOURCES/0481-ieee1275-ofdisk-retry-on-open-failure.patch
new file mode 100644
index 0000000..93ad912
--- /dev/null
+++ b/SOURCES/0481-ieee1275-ofdisk-retry-on-open-failure.patch
@@ -0,0 +1,103 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Diego Domingos <diegodo@br.ibm.com>
+Date: Wed, 10 Mar 2021 14:17:52 -0500
+Subject: [PATCH] ieee1275/ofdisk: retry on open failure
+
+This patch aims to make grub more robust when booting from SAN/Multipath disks.
+
+If a path is failing intermittently so grub will retry the OPEN and READ the
+disk (grub_ieee1275_open and grub_ieee1275_read) until the total amount of times
+specified in MAX_RETRIES.
+
+Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
+---
+ grub-core/disk/ieee1275/ofdisk.c | 25 ++++++++++++++++++++-----
+ include/grub/ieee1275/ofdisk.h   |  8 ++++++++
+ 2 files changed, 28 insertions(+), 5 deletions(-)
+
+diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
+index f3a6ecd797f..98325ca982f 100644
+--- a/grub-core/disk/ieee1275/ofdisk.c
++++ b/grub-core/disk/ieee1275/ofdisk.c
+@@ -225,7 +225,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
+       char *buf, *bufptr;
+       unsigned i;
+ 
+-      if (grub_ieee1275_open (alias->path, &ihandle))
++
++      RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle)
++      if (! ihandle)
+ 	return;
+ 
+       /* This method doesn't need memory allocation for the table. Open
+@@ -305,7 +307,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
+           return;
+         }
+ 
+-      if (grub_ieee1275_open (alias->path, &ihandle))
++      RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle);
++
++      if (! ihandle)
+         {
+           grub_free (buf);
+           grub_free (table);
+@@ -495,7 +499,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
+     last_ihandle = 0;
+     last_devpath = NULL;
+ 
+-    grub_ieee1275_open (op->open_path, &last_ihandle);
++    RETRY_IEEE1275_OFDISK_OPEN(op->open_path, &last_ihandle);
+     if (! last_ihandle)
+       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+     last_devpath = op->open_path;
+@@ -571,7 +575,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
+       last_ihandle = 0;
+       last_devpath = NULL;
+ 
+-      grub_ieee1275_open (disk->data, &last_ihandle);
++      RETRY_IEEE1275_OFDISK_OPEN(disk->data, &last_ihandle);
+       if (! last_ihandle)
+ 	return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+       last_devpath = disk->data;      
+@@ -598,12 +602,23 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
+     return err;
+   grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
+ 		      &actual);
+-  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
++  int i = 0;
++  while(actual != (grub_ssize_t) (size  << disk->log_sector_size)){
++    if (i>MAX_RETRIES){
+     return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
+ 					       "from `%s'"),
+ 		       (unsigned long long) sector,
+ 		       disk->name);
++    }
++    last_devpath = NULL;
++    err = grub_ofdisk_prepare (disk, sector);
++    if (err)
++      return err;
+ 
++    grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
++                      &actual);
++    i++;
++  }
+   return 0;
+ }
+ 
+diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h
+index 2f69e3f191d..7d2d5409305 100644
+--- a/include/grub/ieee1275/ofdisk.h
++++ b/include/grub/ieee1275/ofdisk.h
+@@ -22,4 +22,12 @@
+ extern void grub_ofdisk_init (void);
+ extern void grub_ofdisk_fini (void);
+ 
++#define MAX_RETRIES 20
++
++
++#define RETRY_IEEE1275_OFDISK_OPEN(device, last_ihandle) unsigned retry_i=0;for(retry_i=0; retry_i < MAX_RETRIES; retry_i++){ \
++						if(!grub_ieee1275_open(device, last_ihandle)) \
++						break; \
++						grub_dprintf("ofdisk","Opening disk %s failed. Retrying...\n",device); }
++
+ #endif /* ! GRUB_INIT_HEADER */
diff --git a/SOURCES/grub.patches b/SOURCES/grub.patches
index cc743e3..b685013 100644
--- a/SOURCES/grub.patches
+++ b/SOURCES/grub.patches
@@ -478,3 +478,4 @@ Patch0477: 0477-kern-misc-Add-function-to-check-printf-format-agains.patch
 Patch0478: 0478-gfxmenu-gui-Check-printf-format-in-the-gui_progress_.patch
 Patch0479: 0479-kern-mm-Fix-grub_debug_calloc-compilation-error.patch
 Patch0480: 0480-efi-net-Fix-malformed-device-path-arithmetic-errors-.patch
+Patch0481: 0481-ieee1275-ofdisk-retry-on-open-failure.patch
diff --git a/SOURCES/sbat.csv.in b/SOURCES/sbat.csv.in
index cdfc7f2..4260504 100755
--- a/SOURCES/sbat.csv.in
+++ b/SOURCES/sbat.csv.in
@@ -1,3 +1,4 @@
 sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
 grub,1,Free Software Foundation,grub,2.02,https://www.gnu.org/software/grub/
+grub.rhel8,1,Red Hat Enterprise Linux 8,grub2,@@VERSION@@,mail:secalert@redhat.com
 grub.rocky8,1,Rocky Linux 8,grub2,@@VERSION@@,mail:security@rockylinux.org
diff --git a/SPECS/grub2.spec b/SPECS/grub2.spec
index 644091f..78147ac 100644
--- a/SPECS/grub2.spec
+++ b/SPECS/grub2.spec
@@ -7,7 +7,7 @@
 Name:                 grub2
 Epoch:                1
 Version:              2.02
-Release:              99%{?dist}
+Release:              99%{?dist}.1.1
 Summary:              Bootloader with support for Linux, Multiboot and more
 Group:                System Environment/Base
 License:              GPLv3+
@@ -502,24 +502,31 @@ fi
 %endif
 
 %changelog
-* Sun Jul 18 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99
-- Adding prod certs
+* Tue Sep 21 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99.1
+- Preserving rhel8 sbat entry based on shim-review feedback ticket no. 194 and adding .1 to release
 
-* Sun Jul 18 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99
+* Tue Sep 21 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99.1
+- Adding prod cert
+
+* Tue Sep 21 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99.1
 - Porting to 8.4
 
-* Sun Jul 18 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99
+* Tue Sep 21 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99.1
 - Cleaning up grup.macro extra signing certs and updating rocky test CA and CERT
 
-* Sun Jul 18 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99
+* Tue Sep 21 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99.1
 - Cleaning up grup.macro extra signing certs
 
-* Sun Jul 18 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99
+* Tue Sep 21 2021 Sherif Nagy <sherif@rockylinux.org> - 2.02-99.1
 - Adding Rocky testing CA, CERT and sbat files
 
-* Sun Jul 18 2021 Rich Alloway <ralloway@perforce.com> - 2.02-99
+* Tue Sep 21 2021 Rich Alloway <ralloway@perforce.com> - 2.02-99.1
 - Apply Rocky Linux debranding changes
 
+* Mon May 17 2021 Javier Martinez Canillas <javierm@redhat.com> - 2.02-99.el8_4.1
+- Fix boot failures in ppc64le caused by storage race condition (diegodo)
+  Resolves: rhbz#1961265
+
 * Thu Feb 25 2021 Javier Martinez Canillas <javierm@redhat.com> - 2.02-99
 - Fix bug of grub2-install not checking for the SBAT option
   Resolves: CVE-2020-14372
-- 
GitLab