From 3a1b16ab2119f4e702cb99f49736cc2916064db3 Mon Sep 17 00:00:00 2001 From: LeoLiu-oc Date: Wed, 13 Aug 2025 19:29:14 +0800 Subject: [PATCH 1/2] i386: Check for cpuid family when flush cache only on VIA CPUs Signed-off-by: LeoLiu-oc --- ...puid-family-when-flush-cache-only-on.patch | 39 +++++++++++++++++++ grub.patches | 1 + grub2.spec | 5 ++- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 1017-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch diff --git a/1017-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch b/1017-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch new file mode 100644 index 0000000..dee82cc --- /dev/null +++ b/1017-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch @@ -0,0 +1,39 @@ +From 4bce390aa0fb4a215a0e7e46032d1fcc49a12123 Mon Sep 17 00:00:00 2001 +From: LeoLiu-oc +Date: Wed, 13 Aug 2025 19:21:42 +0800 +Subject: [PATCH] i386: Check for cpuid family when flush cache only on VIA + CPUs + +Due to company changes, Zhaoxin is currently using the CPU ID +CentaurHauls. +CPUs designed and developed by Zhaoxin start with a family of 7, and the +model may be less than 10. + +Zhaoxin CPUs do not have cache coherence problems, add this patch to +avoid executing wbinvd on Zhaoxin CPUs. + +Signed-off-by: Tony W Wang-oc +Signed-off-by: LeoLiu-oc +--- + grub-core/kern/i386/pc/init.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c +index 326d491..f42c129 100644 +--- a/grub-core/kern/i386/pc/init.c ++++ b/grub-core/kern/i386/pc/init.c +@@ -204,6 +204,11 @@ grub_via_workaround_init (void) + { + grub_cpuid (1, proc_info, /* Don't care. */ manufacturer[0], + manufacturer[2], manufacturer[1]); ++ ++ /* Check family, apply only to family 6 and lower. */ ++ if (((proc_info & 0xf00) >> 8) > 6) ++ return; ++ + /* Check model, apply only to VIA C3 and lower. */ + if (((proc_info & 0xf0) >> 4 | (proc_info & 0xf0000) >> 12) > 10) + return; +-- +2.43.0 + diff --git a/grub.patches b/grub.patches index 2806751..570b57f 100644 --- a/grub.patches +++ b/grub.patches @@ -214,3 +214,4 @@ Patch1012: 1012-Clear-buffer-to-zero-for-screen-information.patch Patch1014: 1014-loongarch-Disable-vector-instructions.patch Patch1015: 1015-misc-Implement-grub_strlcpy.patch Patch1016: 1016-CVE-2025-0624-net-Fix-OOB-write-in-grub_net_search_config_file.patch +Patch1017: 1017-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch diff --git a/grub2.spec b/grub2.spec index a6ff615..bf4cdcd 100644 --- a/grub2.spec +++ b/grub2.spec @@ -1,4 +1,4 @@ -%define anolis_release 14 +%define anolis_release 15 %global _lto_cflags %{nil} %undefine _hardened_build @@ -506,6 +506,9 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %endif %changelog +* Wed Aug 13 2025 LeoLiu-oc -2.12-15 +- i386: Check for cpuid family when flush cache only on VIA CPUs + * Tue Jul 29 2025 zjl002254423 -2.12-14 - Fix CVE-2025-0624 -- Gitee From 0fe355bd92bab0e08aa167b5ebe5c65ed03764b8 Mon Sep 17 00:00:00 2001 From: LeoLiu-oc Date: Wed, 13 Aug 2025 19:41:04 +0800 Subject: [PATCH 2/2] i386: Reduce the time of set VESA mode by clearing FB directly for Zhaoxin/Glenfly card Signed-off-by: LeoLiu-oc --- ...time-of-set-VESA-mode-by-clearing-FB.patch | 82 +++++++++++++++++++ grub.patches | 1 + grub2.spec | 5 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 1018-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch diff --git a/1018-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch b/1018-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch new file mode 100644 index 0000000..246058c --- /dev/null +++ b/1018-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch @@ -0,0 +1,82 @@ +From ae98b5c12a8e8c119a436bdf86b7c8f28b9aa137 Mon Sep 17 00:00:00 2001 +From: LeoLiu-oc +Date: Wed, 13 Aug 2025 19:36:34 +0800 +Subject: [PATCH] i386: Reduce the time of set VESA mode by clearing FB + directly for Zhaoxin/Glenfly card + +While calling VBIOS to set VESA mode, BIOS/GRUB can indicate VBIOS to +clear frame buffer, it can also indicate VBIOS to skip this and do the +clearing itself by access linear frame buffer directly. + +Zhaoxin/Glenfly VBIOS is running at real mode and can only access the +first 1M memory, which means it can't access linear frame buffer directly. +So the first way will take more time. + +Add a patch here to use the second way to save time for Zhaoxin/Glenfly +card. + +Signed-off-by: Joanne Bao +Signed-off-by: Tony W Wang-oc +Tested-by: Sherry Zhang +Suggested-by: Jason He +Signed-off-by: LeoLiu-oc +--- + grub-core/video/i386/pc/vbe.c | 42 +++++++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c +index a0bb9af..9b2aa7c 100644 +--- a/grub-core/video/i386/pc/vbe.c ++++ b/grub-core/video/i386/pc/vbe.c +@@ -618,6 +618,48 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode, + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + ++ grub_uint32_t string_seg = (controller_info.oem_string_ptr & 0xFFFF0000) >> 16; ++ grub_uint32_t string_offset = controller_info.oem_string_ptr & 0xFFFF; ++ const char * oem_string = (const char *) (string_seg << 4) + string_offset; ++ ++ /* ++ * While calling VBIOS to set VESA mode, BIOS/GRUB can indicate VBIOS to clear ++ * frame buffer, it can also indicate VBIOS to skip this and do the clearing ++ * itself by access linear frame buffer directly. ++ * ++ * Zhaoxin/Glenfly VBIOS is running at real mode and can only access the first ++ * 1M memory, which means it can't access linear frame buffer directly. So the ++ * first way will take more time. ++ */ ++ ++ if (vbe_mode >= 0x100 && oem_string != NULL && *oem_string != '\0') ++ { ++ if (grub_strncmp(oem_string, "Zhaoxin", 7) == 0 || grub_strncmp(oem_string, "Glenfly", 7) == 0) ++ { ++ grub_uint8_t * fb_ptr; ++ struct grub_video_mode_info local_mode_info; ++ grub_size_t page_size; ++ grub_size_t vram_size = controller_info.total_memory << 16; ++ local_mode_info.height = new_vbe_mode_info.y_resolution; ++ ++ if (controller_info.version >= 0x300) ++ local_mode_info.pitch = new_vbe_mode_info.lin_bytes_per_scan_line; ++ else ++ local_mode_info.pitch = new_vbe_mode_info.bytes_per_scan_line; ++ ++ fb_ptr = (grub_uint8_t *) new_vbe_mode_info.phys_base_addr; ++ ++ page_size = local_mode_info.pitch * local_mode_info.height; ++ ++ if (vram_size >= 2 * page_size) ++ grub_memset(fb_ptr, 0, 2 * page_size); ++ else ++ grub_memset(fb_ptr, 0, page_size); ++ ++ vbe_mode |= 1 << 15; ++ } ++ } ++ + /* Try to get mode info. */ + grub_vbe_get_video_mode_info (vbe_mode, &new_vbe_mode_info); + if (grub_errno != GRUB_ERR_NONE) +-- +2.43.0 + diff --git a/grub.patches b/grub.patches index 570b57f..b072370 100644 --- a/grub.patches +++ b/grub.patches @@ -215,3 +215,4 @@ Patch1014: 1014-loongarch-Disable-vector-instructions.patch Patch1015: 1015-misc-Implement-grub_strlcpy.patch Patch1016: 1016-CVE-2025-0624-net-Fix-OOB-write-in-grub_net_search_config_file.patch Patch1017: 1017-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch +Patch1018: 1018-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch diff --git a/grub2.spec b/grub2.spec index bf4cdcd..c3b9165 100644 --- a/grub2.spec +++ b/grub2.spec @@ -1,4 +1,4 @@ -%define anolis_release 15 +%define anolis_release 16 %global _lto_cflags %{nil} %undefine _hardened_build @@ -506,6 +506,9 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %endif %changelog +* Wed Aug 13 2025 LeoLiu-oc -2.12-16 +- i386: Reduce the time of set VESA mode by clearing FB directly for Zhaoxin/Glenfly card + * Wed Aug 13 2025 LeoLiu-oc -2.12-15 - i386: Check for cpuid family when flush cache only on VIA CPUs -- Gitee