A set of trivial patches from the Fedora package
cover A set of trivial patches from the Fedora package
Hello,
This is another set of patches that we have been carrying in the Fedora package for some time. The changes are mostly trivial and I guess won't be that controversial.
The paches don't have dependency with each other and can be independently applied. I'm posting it as a set because I think that will make the review easier, but please let me know if you want them to be posted individually.
Best regards,
Javier
Alexander Graf (1):
efi/gop: Add support for BLT_ONLY adapters
Andrei Borzenkov (1):
efi/uga: Use 64 bit for fb_base
Peter Jones (8):
linux/getroot: Handle rssd storage device names
efi: Print more debug info in our module loader
Makefile: Make libgrub.pp depend on config-util.h
kern: Add grub_debug_enabled() normal/completion: Fix possible NULL pointer dereference
kern: Make grub_error() more verbose
video: Add more debug output on GOP and UGA probing
efi: Fix the type of grub_efi_status_t
Makefile.am | 2 +- grub-core/kern/efi/efi.c | 16 ++++++++++++--- grub-core/kern/efi/mm.c | 17 ++++++++++++--- grub-core/kern/err.c | 13 ++++++++++-- grub-core/kern/misc.c | 21 ++++++++++++++----- grub-core/normal/completion.c | 3 ++- grub-core/osdep/linux/getroot.c | 13 ++++++++++++ grub-core/video/efi_gop.c | 10 ++++++++- grub-core/video/efi_uga.c | 33 +++++++++++++++--------------- include/grub/efi/api.h | 2 +- include/grub/efi/graphics_output.h | 3 ++- include/grub/err.h | 5 ++++- include/grub/misc.h | 1 + 13 files changed, 104 insertions(+), 35 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/10 linux/getroot: Handle rssd storage device names
From: Peter Jones <[email protected]>
The Micron PCIe SSDs Linux driver (mtip32xx) exposes block devices as /dev/rssd[a-z]+[0-9]*. Add support for these rssd device names.
---
grub-core/osdep/linux/getroot.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
grub-core/osdep/linux/getroot.c +13 -0
@@ -921,6 +921,19 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st,return path; } +/* If this is an rssd device. */ +if ((strncmp ("rssd" , p,4 ) ==0 ) && p[4 ] >='a' && p[4 ] <='z' ) + { +char *pp = p +4 ; +while (*pp >='a' && *pp <='z' ) + pp++; +if (*pp) + *is_part =1 ; +/* /dev/rssd[a-z]+[0-9]* */ + *pp ='\0' ; +return path; + } +/* If this is a loop device */ if ((strncmp ("loop" , p,4 ) ==0 ) && p[4 ] >='0' && p[4 ] <='9' ) {
Signature · 1 line
2.24.1
PATCH 2/10 efi: Print more debug info in our module loader
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
The function that searches the mods section base address does not have any debug information. Add some debugging outputs that could be useful.
---
grub-core/kern/efi/efi.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
grub-core/kern/efi/efi.c +13 -3
@@ -308,13 +308,23 @@ grub_efi_modules_addr (void) }if (i == coff_header->num_sections) -return 0 ; + { +grub_dprintf ("sections" ,"section %d is last section; invalid.\n" , i); +return 0 ; + } info = (struct grub_module_info *) ((char *) image->image_base + section->virtual_address); -if (info->magic !=GRUB_MODULE_MAGIC ) -return 0 ; +if (section->name[0 ] !='.' && info->magic !=GRUB_MODULE_MAGIC ) + { +grub_dprintf ("sections" , +"section %d has bad magic %08x, should be %08x\n" , + i, info->magic,GRUB_MODULE_MAGIC ); +return 0 ; + } +grub_dprintf ("sections" ,"returning section info for section %d: \"%s\"\n" , + i, section->name);return (grub_addr_t ) info; }
Signature · 1 line
2.24.1
PATCH 3/10 Makefile: Make libgrub.pp depend on config-util.h
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
If you build with "make -j48" a lot, sometimes you see:
gcc -E -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I../grub-core/lib/minilzo -I../grub-core/lib/xzembed -DMINILZO_HAVE_CONFIG_H -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I./grub-core/gnulib -I../grub-core/gnulib -I/builddir/build/BUILD/grub-2.02/grub-aarch64-efi-2.02 -D_FILE_OFFSET_BITS=64 \
-D'GRUB_MOD_INIT(x)=@MARKER@x@' grub_script.tab.h grub_script.yy.h ../grub-core/commands/blocklist.c ../grub-core/commands/macbless.c ../grub-core/commands/xnu_uuid.c ../grub-core/commands/testload.c ../grub-core/commands/ls.c ../grub-core/disk/dmraid_nvidia.c ../grub-core/disk/loopback.c ../grub-core/disk/lvm.c ../grub-core/disk/mdraid_linux.c ../grub-core/disk/mdraid_linux_be.c ../grub-core/disk/mdraid1x_linux.c ../grub-core/disk/raid5_recover.c ../grub-core/disk/raid6_recover.c ../grub-core/font/font.c ../grub-core/gfxmenu/font.c ../grub-core/normal/charset.c ../grub-core/video/fb/fbblit.c ../grub-core/video/fb/fbutil.c ../grub-core/video/fb/fbfill.c ../grub-core/video/fb/video_fb.c ../grub-core/video/video.c ../grub-core/video/capture.c ../grub-core/video/colors.c ../grub-core/unidata.c ../grub-core/io/bufio.c ../grub-core/fs/affs.c ../grub-core/fs/afs.c ../grub-core/fs/bfs.c ../grub-core/fs/btrfs.c ../grub-core/fs/cbfs.c ../grub-core/fs/cpio.c ../grub-core/fs/cpio_be.c ../grub-core/fs/odc.c ../grub-core/fs/newc.c ../grub-core/fs/ext2.c ../grub-core/fs/fat.c ../grub-core/fs/exfat.c ../grub-core/fs/fshelp.c ../grub-core/fs/hfs.c ../grub-core/fs/hfsplus.c ../grub-core/fs/hfspluscomp.c ../grub-core/fs/iso9660.c ../grub-core/fs/jfs.c ../grub-core/fs/minix.c ../grub-core/fs/minix2.c ../grub-core/fs/minix3.c ../grub-core/fs/minix_be.c ../grub-core/fs/minix2_be.c ../grub-core/fs/minix3_be.c ../grub-core/fs/nilfs2.c ../grub-core/fs/ntfs.c ../grub-core/fs/ntfscomp.c ../grub-core/fs/reiserfs.c ../grub-core/fs/romfs.c ../grub-core/fs/sfs.c ../grub-core/fs/squash4.c ../grub-core/fs/tar.c ../grub-core/fs/udf.c ../grub-core/fs/ufs2.c ../grub-core/fs/ufs.c ../grub-core/fs/ufs_be.c ../grub-core/fs/xfs.c ../grub-core/fs/zfs/zfscrypt.c ../grub-core/fs/zfs/zfs.c ../grub-core/fs/zfs/zfsinfo.c ../grub-core/fs/zfs/zfs_lzjb.c ../grub-core/fs/zfs/zfs_lz4.c ../grub-core/fs/zfs/zfs_sha256.c ../grub-core/fs/zfs/zfs_fletcher.c ../grub-core/lib/envblk.c ../grub-core/lib/hexdump.c ../grub-core/lib/LzFind.c ../grub-core/lib/LzmaEnc.c ../grub-core/lib/crc.c ../grub-core/lib/adler32.c ../grub-core/lib/crc64.c ../grub-core/normal/datetime.c ../grub-core/normal/misc.c ../grub-core/partmap/acorn.c ../grub-core/partmap/amiga.c ../grub-core/partmap/apple.c ../grub-core/partmap/sun.c ../grub-core/partmap/plan.c ../grub-core/partmap/dvh.c ../grub-core/partmap/sunpc.c ../grub-core/partmap/bsdlabel.c ../grub-core/partmap/dfly.c ../grub-core/script/function.c ../grub-core/script/lexer.c ../grub-core/script/main.c ../grub-core/script/script.c ../grub-core/script/argv.c ../grub-core/io/gzio.c ../grub-core/io/xzio.c ../grub-core/io/lzopio.c ../grub-core/kern/ia64/dl_helper.c ../grub-core/kern/arm/dl_helper.c ../grub-core/kern/arm64/dl_helper.c ../grub-core/lib/minilzo/minilzo.c ../grub-core/lib/xzembed/xz_dec_bcj.c ../grub-core/lib/xzembed/xz_dec_lzma2.c ../grub-core/lib/xzembed/xz_dec_stream.c ../util/misc.c ../grub-core/kern/command.c ../grub-core/kern/device.c ../grub-core/kern/disk.c ../grub-core/lib/disk.c ../util/getroot.c ../grub-core/osdep/unix/getroot.c ../grub-core/osdep/getroot.c ../grub-core/osdep/devmapper/getroot.c ../grub-core/osdep/relpath.c ../grub-core/kern/emu/hostdisk.c ../grub-core/osdep/devmapper/hostdisk.c ../grub-core/osdep/hostdisk.c ../grub-core/osdep/unix/hostdisk.c ../grub-core/osdep/exec.c ../grub-core/osdep/sleep.c ../grub-core/osdep/password.c ../grub-core/kern/emu/misc.c ../grub-core/kern/emu/mm.c ../grub-core/kern/env.c ../grub-core/kern/err.c ../grub-core/kern/file.c ../grub-core/kern/fs.c ../grub-core/kern/list.c ../grub-core/kern/misc.c ../grub-core/kern/partition.c ../grub-core/lib/crypto.c ../grub-core/disk/luks.c ../grub-core/disk/geli.c ../grub-core/disk/cryptodisk.c ../grub-core/disk/AFSplitter.c ../grub-core/lib/pbkdf2.c ../grub-core/commands/extcmd.c ../grub-core/lib/arg.c ../grub-core/disk/ldm.c ../grub-core/disk/diskfilter.c ../grub-core/partmap/gpt.c ../grub-core/partmap/msdos.c ../grub-core/fs/proc.c ../grub-core/fs/archelp.c > libgrub.pp || (rm -f libgrub.pp; exit 1)
rm -f stamp-h1
touch ../config-util.h.in
cd . && /bin/sh ./config.status config-util.h
config.status: creating config-util.h
In file included from ../include/grub/mm.h:25:0,
from ../include/grub/disk.h:29,
from ../include/grub/file.h:26,
from ../grub-core/fs/btrfs.c:21:
./config.h:38:10: fatal error: ./config-util.h: No such file or directory
#include <config-util.h>
^~~~~~~~~~~~~~~compilation terminated.
make: *** [Makefile:13098: libgrub.pp] Error 1
This is because libgrub.pp is built with -DGRUB_UTIL=1, which means it'll try to include config-util.h, but a parallel make is actually building that file. I think.
---
Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.am +1 -1
@@ -37,7 +37,7 @@ grub_script.yy.c: grub_script.yy.h CLEANFILES += grub_script.yy.c grub_script.yy.h # For libgrub.a -libgrub.pp: grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) +libgrub.pp: config-util.h grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrubmods_a_CPPFLAGS) $(libgrubkern_a_CPPFLAGS) $(CPPFLAGS) \ -D'GRUB_MOD_INIT(x)=@MARKER@x@' $^ > $@ || (rm -f $@; exit 1) CLEANFILES += libgrub.pp
Signature · 1 line
2.24.1
PATCH 4/10 kern: Add grub_debug_enabled()
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
Add a grub_debug_enabled() helper function instead of open coding it.
---
grub-core/kern/misc.c | 21 ++++++++++++++++----- include/grub/misc.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)
grub-core/kern/misc.c +16 -5
@@ -158,17 +158,28 @@ int grub_err_printf (const char *fmt, ...) __attribute__ ((alias("grub_printf")));#endif +int +grub_debug_enabled (const char * condition) +{ +const char *debug; + + debug =grub_env_get ("debug" ); +if (!debug) +return 0 ; + +if (grub_strword (debug,"all" ) ||grub_strword (debug, condition)) +return 1 ; + +return 0 ; +} +void grub_real_dprintf (const char *file,const int line,const char *condition,const char *fmt, ...) {va_list args; -const char *debug =grub_env_get ("debug" ); - -if (! debug) -return ; -if (grub_strword (debug,"all" ) ||grub_strword (debug, condition)) +if (grub_debug_enabled (condition)) {grub_printf ("%s:%d: " , file, line);va_start (args, fmt);
include/grub/misc.h +1 -0
@@ -322,6 +322,7 @@ grub_puts (const char *s) }int EXPORT_FUNC (grub_puts_ ) (const char *s); +int EXPORT_FUNC (grub_debug_enabled ) (const char *condition); void EXPORT_FUNC(grub_real_dprintf) (const char *file, const int line, const char *condition,
Signature · 1 line
2.24.1
PATCH 5/10 normal/completion: Fix possible NULL pointer dereference
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
Coverity Scan reports that the grub_strrchr() function can return NULL if the character is not found. Check if that's the case for dirfile pointer.
---
grub-core/normal/completion.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/normal/completion.c +2 -1
@@ -284,7 +284,8 @@ complete_file (void)/* Cut away the filename part. */ dirfile =grub_strrchr (dir,'/' ); - dirfile[1 ] ='\0' ; +if (dirfile) + dirfile[1 ] ='\0' ;/* Iterate the directory. */ (fs->fs_dir) (dev, dir, iterate_dir,NULL );
Signature · 1 line
2.24.1
PATCH 6/10 efi/gop: Add support for BLT_ONLY adapters
In reply to Javier Martinez CanillasFrom: Alexander Graf <[email protected]>
EFI GOP has support for multiple different bitness types of frame buffers and for a special "BLT only" type which is always defined to be RGBx.
Because grub2 doesn't ever directly access the frame buffer but instead only renders graphics via the BLT interface anyway, we can easily support these adapters.
The reason this has come up now is the emerging support for virtio-gpu in OVMF. That adapter does not have the notion of a memory mapped frame buffer and thus is BLT only.
---
grub-core/video/efi_gop.c | 2 ++ include/grub/efi/graphics_output.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
grub-core/video/efi_gop.c +2 -0
@@ -121,6 +121,7 @@ grub_video_gop_get_bpp (struct grub_efi_gop_mode_info *in) {case GRUB_EFI_GOT_BGRA8 :case GRUB_EFI_GOT_RGBA8 : +case GRUB_EFI_GOT_BLT_ONLY :return 32 ;case GRUB_EFI_GOT_BITMASK :
@@ -187,6 +188,7 @@ grub_video_gop_fill_real_mode_info (unsigned mode,switch (in->pixel_format) {case GRUB_EFI_GOT_RGBA8 : +case GRUB_EFI_GOT_BLT_ONLY : out->red_mask_size =8 ; out->red_field_pos =0 ; out->green_mask_size =8 ;
include/grub/efi/graphics_output.h +2 -1
@@ -28,7 +28,8 @@ typedef enum {GRUB_EFI_GOT_RGBA8 ,GRUB_EFI_GOT_BGRA8 , - GRUB_EFI_GOT_BITMASK +GRUB_EFI_GOT_BITMASK , +GRUB_EFI_GOT_BLT_ONLY , } grub_efi_gop_pixel_format_t;
Signature · 1 line
2.24.1
PATCH 7/10 efi/uga: Use 64 bit for fb_base
In reply to Javier Martinez CanillasFrom: Andrei Borzenkov <[email protected]>
We get 64 bit from PCI BAR but then truncate by assigning to 32 bit. Make sure to check that pointer does not overflow on 32 bit platform.
---
grub-core/video/efi_uga.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
grub-core/video/efi_uga.c +16 -15
@@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+");static grub_efi_guid_t uga_draw_guid =GRUB_EFI_UGA_DRAW_GUID ;static struct grub_efi_uga_draw_protocol *uga; -static grub_uint32_t uga_fb; +static grub_uint64_t uga_fb;static grub_uint32_t uga_pitch; static struct
@@ -52,7 +52,7 @@ static struct#define FBTEST_COUNT 8static int -find_line_len (grub_uint32_t *fb_base,grub_uint32_t *line_len) +find_line_len (grub_uint64_t *fb_base,grub_uint32_t *line_len) {grub_uint32_t *base = (grub_uint32_t *) (grub_addr_t) *fb_base;int i;
@@ -67,7 +67,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) {if ((base[j] &RGB_MASK ) ==RGB_MAGIC ) { - *fb_base = (grub_uint32_t ) (grub_addr_t ) base; + *fb_base = (grub_uint64_t ) (grub_addr_t ) base; *line_len = j <<2 ;return 1 ;
@@ -84,7 +84,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len)/* Context for find_framebuf. */ struct find_framebuf_ctx { -grub_uint32_t *fb_base; +grub_uint64_t *fb_base;grub_uint32_t *line_len;int found; };
@@ -129,7 +129,9 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)if (i ==5 )break ; - old_bar2 =grub_pci_read (addr +4 ); + i++; + addr +=4 ; + old_bar2 =grub_pci_read (addr); }else old_bar2 =0 ;
@@ -138,10 +140,15 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) base64 <<=32 ; base64 |= (old_bar1 &GRUB_PCI_ADDR_MEM_MASK ); -grub_dprintf ("fb" ,"%s(%d): 0x%llx\n" , +grub_dprintf ("fb" ,"%s(%d): 0x%" PRIxGRUB_UINT64_T"\n" , ((old_bar1 &GRUB_PCI_ADDR_MEM_PREFETCH ) ? -"VMEM" :"MMIO" ), i, - (unsigned long long ) base64); +"VMEM" :"MMIO" ), type ==GRUB_PCI_ADDR_MEM_TYPE_64 ? i -1 : i, + base64); + +#if GRUB_CPU_SIZEOF_VOID_P ==4 +if (old_bar2) +continue ; +#endif if ((old_bar1 &GRUB_PCI_ADDR_MEM_PREFETCH ) && (! ctx->found)) {
@@ -149,12 +156,6 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)if (find_line_len (ctx->fb_base, ctx->line_len)) ctx->found++; } - -if (type ==GRUB_PCI_ADDR_MEM_TYPE_64 ) - { - i++; - addr +=4 ; - } } }
@@ -162,7 +163,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) }static int -find_framebuf (grub_uint32_t *fb_base,grub_uint32_t *line_len) +find_framebuf (grub_uint64_t *fb_base,grub_uint32_t *line_len) {struct find_framebuf_ctx ctx = { .fb_base = fb_base,
Signature · 1 line
2.24.1
PATCH 8/10 kern: Make grub_error() more verbose
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
Add file and line to grub_error() output to make troubleshooting easier.
---
grub-core/kern/efi/mm.c | 17 ++++++++++++++--- grub-core/kern/err.c | 13 +++++++++++-- include/grub/err.h | 5 ++++- 3 files changed, 29 insertions(+), 6 deletions(-)
grub-core/kern/efi/mm.c +14 -3
@@ -125,12 +125,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,/* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address >GRUB_EFI_MAX_USABLE_ADDRESS ) -return 0 ; + { +grub_error (GRUB_ERR_BAD_ARGUMENT , +N_ ("invalid memory address (0x%llx > 0x%llx)" ), + address,GRUB_EFI_MAX_USABLE_ADDRESS ); +return NULL ; + } b = grub_efi_system_table->boot_services; status =efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);if (status !=GRUB_EFI_SUCCESS ) -return 0 ; + { +grub_error (GRUB_ERR_OUT_OF_MEMORY ,N_ ("out of memory" )); +return NULL ; + }if (address ==0 ) {
@@ -140,7 +148,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, status =efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);grub_efi_free_pages (0 , pages);if (status !=GRUB_EFI_SUCCESS ) -return 0 ; + { +grub_error (GRUB_ERR_OUT_OF_MEMORY ,N_ ("out of memory" )); +return NULL ; + } }grub_efi_store_alloc (address, pages);
grub-core/kern/err.c +11 -2
@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];static int grub_error_stack_pos;static int grub_error_stack_assert; +#ifdef grub_error +#undef grub_error +#endif +grub_err_t -grub_error (grub_err_t n,const char *fmt, ...) +grub_error (grub_err_t n,const char *file,const int line,const char *fmt, ...) {va_list ap; +int m; grub_errno = n; + m =grub_snprintf (grub_errmsg,sizeof (grub_errmsg),"%s:%d:" , file, line); +if (m <0 ) + m =0 ; +va_start (ap, fmt); -grub_vsnprintf (grub_errmsg,sizeof (grub_errmsg),_ (fmt), ap); +grub_vsnprintf (grub_errmsg + m,sizeof (grub_errmsg) - m,_ (fmt), ap);va_end (ap);return n;
include/grub/err.h +4 -1
@@ -85,7 +85,10 @@ struct grub_error_savedextern grub_err_t EXPORT_VAR (grub_errno );extern char EXPORT_VAR (grub_errmsg )[GRUB_MAX_ERRMSG ]; -grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *fmt, ...); +grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *file,const int line,const char *fmt, ...); + +#define grub_error (n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__) +void EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));void EXPORT_FUNC (grub_error_push ) (void );int EXPORT_FUNC (grub_error_pop ) (void );
Signature · 1 line
2.24.1
Re: [PATCH 08/10] kern: Make grub_error() more verbose
Quoted 3 lines · Javier Martinez Canillas
From: Peter Jones <[email protected]>
Add file and line to
grub_error()output to make troubleshooting easier.
This patch does more than that. I think it requires splitting into two separate ones...
Daniel
Quoted 97 lines
Signed-off-by Peter Jones <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
grub-core/kern/efi/mm.c | 17 ++++++++++++++--- grub-core/kern/err.c | 13 +++++++++++-- include/grub/err.h | 5 ++++- 3 files changed, 29 insertions(+), 6 deletions(-)grub-core/kern/efi/mm.c +14
-3@@ -125,12 +125,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,/* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address >GRUB_EFI_MAX_USABLE_ADDRESS ) -return 0 ; + { +grub_error (GRUB_ERR_BAD_ARGUMENT , +N_ ("invalid memory address (0x%llx > 0x%llx)" ), + address,GRUB_EFI_MAX_USABLE_ADDRESS ); +return NULL ; + } b = grub_efi_system_table->boot_services; status =efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);if (status !=GRUB_EFI_SUCCESS ) -return 0 ; + { +grub_error (GRUB_ERR_OUT_OF_MEMORY ,N_ ("out of memory" )); +return NULL ; + }if (address ==0 ) {@@ -140,7 +148,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, status =efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);grub_efi_free_pages (0 , pages);if (status !=GRUB_EFI_SUCCESS ) -return 0 ; + { +grub_error (GRUB_ERR_OUT_OF_MEMORY ,N_ ("out of memory" )); +return NULL ; + } }grub_efi_store_alloc (address, pages);grub-core/kern/err.c +11
-2@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];static int grub_error_stack_pos;static int grub_error_stack_assert; +#ifdef grub_error +#undef grub_error +#endif +grub_err_t -grub_error (grub_err_t n,const char *fmt, ...) +grub_error (grub_err_t n,const char *file,const int line,const char *fmt, ...) {va_list ap; +int m; grub_errno = n; + m =grub_snprintf (grub_errmsg,sizeof (grub_errmsg),"%s:%d:" , file, line); +if (m <0 ) + m =0 ; +va_start (ap, fmt); -grub_vsnprintf (grub_errmsg,sizeof (grub_errmsg),_ (fmt), ap); +grub_vsnprintf (grub_errmsg + m,sizeof (grub_errmsg) - m,_ (fmt), ap);va_end (ap);return n;include/grub/err.h +4
-2@@ -85,7 +85,10 @@ struct grub_error_savedextern grub_err_t EXPORT_VAR (grub_errno );extern char EXPORT_VAR (grub_errmsg )[GRUB_MAX_ERRMSG ]; -grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *fmt, ...); +grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *file,const int line,const char *fmt, ...); + +#define grub_error (n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__) +void EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));void EXPORT_FUNC (grub_error_push ) (void );int EXPORT_FUNC (grub_error_pop ) (void ); --2.24.1
PATCH 9/10 video: Add more debug output on GOP and UGA probing
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
Add debug information to EFI GOP and UGA video drivers probing function.
---
grub-core/video/efi_gop.c | 8 +++++++- grub-core/video/efi_uga.c | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-)
grub-core/video/efi_gop.c +7 -1
@@ -71,7 +71,10 @@ check_protocol (void) handles =grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL , &graphics_output_guid,NULL , &num_handles);if (!handles || num_handles ==0 ) -return 0 ; + { +grub_dprintf ("video" ,"GOP: no handles\n" ); +return 0 ; + }for (i =0 ; i < num_handles; i++) {
@@ -81,6 +84,7 @@ check_protocol (void)grub_video_gop_iterate (check_protocol_hook, &have_usable_mode);if (have_usable_mode) { +grub_dprintf ("video" ,"GOP: found usable mode\n" );grub_free (handles);return 1 ; }
@@ -89,6 +93,8 @@ check_protocol (void) gop =0 ; gop_handle =0 ; +grub_dprintf ("video" ,"GOP: no usable mode\n" ); +return 0 ; }
grub-core/video/efi_uga.c +2 -2
@@ -110,7 +110,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) {int i; -grub_dprintf ("fb" ,"Display controller: %d:%d.%d\nDevice id: %x\n" , +grub_dprintf ("video" ,"Display controller: %d:%d.%d\nDevice id: %x\n" ,grub_pci_get_bus (dev),grub_pci_get_device (dev),grub_pci_get_function (dev), pciid); addr +=8 ;
@@ -140,7 +140,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) base64 <<=32 ; base64 |= (old_bar1 &GRUB_PCI_ADDR_MEM_MASK ); -grub_dprintf ("fb" ,"%s(%d): 0x%" PRIxGRUB_UINT64_T"\n" , +grub_dprintf ("video" ,"%s(%d): 0x%" PRIxGRUB_UINT64_T"\n" , ((old_bar1 &GRUB_PCI_ADDR_MEM_PREFETCH ) ?"VMEM" :"MMIO" ), type ==GRUB_PCI_ADDR_MEM_TYPE_64 ? i -1 : i, base64);
Signature · 1 line
2.24.1
Re: [PATCH 09/10] video: Add more debug output on GOP and UGA probing
Quoted 3 lines · Javier Martinez Canillas
From: Peter Jones <[email protected]>
Add debug information to EFI GOP and UGA video drivers probing function.
Same as for patch #8...
Daniel
Quoted 66 lines
Signed-off-by Peter Jones <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
grub-core/video/efi_gop.c | 8 +++++++- grub-core/video/efi_uga.c | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-)grub-core/video/efi_gop.c +7
-1@@ -71,7 +71,10 @@ check_protocol (void) handles =grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL , &graphics_output_guid,NULL , &num_handles);if (!handles || num_handles ==0 ) -return 0 ; + { +grub_dprintf ("video" ,"GOP: no handles\n" ); +return 0 ; + }for (i =0 ; i < num_handles; i++) {@@ -81,6 +84,7 @@ check_protocol (void)grub_video_gop_iterate (check_protocol_hook, &have_usable_mode);if (have_usable_mode) { +grub_dprintf ("video" ,"GOP: found usable mode\n" );grub_free (handles);return 1 ; }@@ -89,6 +93,8 @@ check_protocol (void) gop =0 ; gop_handle =0 ; +grub_dprintf ("video" ,"GOP: no usable mode\n" ); +return 0 ; }grub-core/video/efi_uga.c +2
-2@@ -110,7 +110,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) {int i; -grub_dprintf ("fb" ,"Display controller: %d:%d.%d\nDevice id: %x\n" , +grub_dprintf ("video" ,"Display controller: %d:%d.%d\nDevice id: %x\n" ,grub_pci_get_bus (dev),grub_pci_get_device (dev),grub_pci_get_function (dev), pciid); addr +=8 ;@@ -140,7 +140,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) base64 <<=32 ; base64 |= (old_bar1 &GRUB_PCI_ADDR_MEM_MASK ); -grub_dprintf ("fb" ,"%s(%d): 0x%" PRIxGRUB_UINT64_T"\n" , +grub_dprintf ("video" ,"%s(%d): 0x%" PRIxGRUB_UINT64_T"\n" , ((old_bar1 &GRUB_PCI_ADDR_MEM_PREFETCH ) ?"VMEM" :"MMIO" ), type ==GRUB_PCI_ADDR_MEM_TYPE_64 ? i -1 : i, base64);Signature · 1 line
2.24.1
PATCH 10/10 efi: Fix the type of grub_efi_status_t
In reply to Javier Martinez CanillasFrom: Peter Jones <[email protected]>
Currently, in some builds with some checkers, we see:
1. grub-core/disk/efi/efidisk.c:601: error[shiftTooManyBitsSigned]: Shifting signed 64-bit value by 63 bits is undefined behaviour
This is because grub_efi_status_t is defined as grub_efi_intn_t, which is signed, and shifting into the sign bit is not defined behavior. UEFI fixed this in the spec in 2.3:
2.3 | Change the defined type of EFI_STATUS from INTN to UINTN | May 7, 2009
And the current EDK2 code has:
MdePkg/Include/Base.h-//
MdePkg/Include/Base.h-// Status codes common to all execution phases
MdePkg/Include/Base.h-//
MdePkg/Include/Base.h:typedef UINTN RETURN_STATUS;
MdePkg/Include/Base.h-
MdePkg/Include/Base.h-/**
MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit set. MdePkg/Include/Base.h-
MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code.
MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF.
MdePkg/Include/Base.h-
MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit set. MdePkg/Include/Base.h-
MdePkg/Include/Base.h-**/
MdePkg/Include/Base.h-#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode)))
MdePkg/Include/Base.h-
MdePkg/Include/Base.h-/**
MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit clear. MdePkg/Include/Base.h-
MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code.
MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF.
MdePkg/Include/Base.h-
MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit clear. MdePkg/Include/Base.h-
MdePkg/Include/Base.h-**/
MdePkg/Include/Base.h-#define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode))
MdePkg/Include/Base.h-
MdePkg/Include/Base.h-/**
MdePkg/Include/Base.h- Returns TRUE if a specified RETURN_STATUS code is an error code. MdePkg/Include/Base.h-
MdePkg/Include/Base.h- This function returns TRUE if StatusCode has the high bit set. Otherwise, FALSE is returned. MdePkg/Include/Base.h-
MdePkg/Include/Base.h- @param StatusCode The status code value to evaluate.
MdePkg/Include/Base.h-
MdePkg/Include/Base.h- @retval TRUE The high bit of StatusCode is set. MdePkg/Include/Base.h- @retval FALSE The high bit of StatusCode is clear.
MdePkg/Include/Base.h-
MdePkg/Include/Base.h-**/
MdePkg/Include/Base.h-#define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0)
...
Uefi/UefiBaseType.h:typedef RETURN_STATUS EFI_STATUS;
This patch makes grub's implementation match the Edk2 declaration with regards to the signedness of the type.
---
include/grub/efi/api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/efi/api.h +1 -1
@@ -531,7 +531,7 @@ typedef grub_uint64_t grub_efi_uint64_t;typedef grub_uint8_t grub_efi_char8_t ;typedef grub_uint16_t grub_efi_char16_t ; -typedef grub_efi_intn_t grub_efi_status_t ; +typedef grub_efi_uintn_t grub_efi_status_t ;#define GRUB_EFI_ERROR_CODE (value) \ ((((grub_efi_status_t) 1) << (sizeof (grub_efi_status_t) * 8 - 1)) | (value))
Signature · 1 line
2.24.1
Quoted 9 lines · Javier Martinez Canillas
Hello,
This is another set of patches that we have been carrying in the Fedora package for some time. The changes are mostly trivial and I guess won't be that controversial.
The paches don't have dependency with each other and can be independently applied. I'm posting it as a set because I think that will make the review easier, but please let me know if you want them to be posted individually.
Except patches #8 and #9 Reviewed-by: Daniel Kiper <[email protected]>
Daniel