x86/realmode: Consolidate real-mode blob size calculation
PATCH 1/1 x86/realmode: Consolidate real-mode blob size calculation
rmpiggy.S page-aligns both real_mode_blob and real_mode_blob_end. Their difference is therefore already page-aligned and does not require ALIGN() or PAGE_ALIGN().
Since the real-mode blob size is calculated in three different places, add the real_mode_blob_size() helper and use it in real_mode_size_needed(), setup_real_mode(), and set_real_mode_permissions().
No functional change.
---
This patch depends on the following patch, which has been acked by hpa but hasn't been merged yet:
https://lore.kernel.org/r/[email protected]/
arch/x86/include/asm/realmode.h | 8 +++++++- arch/x86/realmode/init.c | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-)
arch/x86/include/asm/realmode.h +7 -1
@@ -78,12 +78,18 @@ extern unsigned char secondary_startup_64[];extern unsigned char secondary_startup_64_no_verify[];#endif +static __always_inline size_t real_mode_blob_size(void) +{ +/* rmpiggy.S page-aligns both ends of the blob. */ +return real_mode_blob_end - real_mode_blob; +} + static __always_inline size_t real_mode_size_needed(void) {if (real_mode_header)return 0 ;/* already allocated. */ -return ALIGN (real_mode_blob_end - real_mode_blob,PAGE_SIZE ); +return real_mode_blob_size (); }static inline void set_real_mode_mem (phys_addr_t mem)
arch/x86/realmode/init.c +2 -2
@@ -96,7 +96,7 @@ static void __init setup_real_mode(void)unsigned char *base;unsigned long phys_base;struct trampoline_header *trampoline_header; -size_t size =PAGE_ALIGN (real_mode_blob_end - real_mode_blob); +size_t size =real_mode_blob_size ();#ifdef CONFIG_X86_64 u64 *trampoline_pgd;u64 efer;
@@ -187,7 +187,7 @@ static void __init setup_real_mode(void)static void __init set_real_mode_permissions (void ) {unsigned char *base = (unsigned char *) real_mode_header; -size_t size =PAGE_ALIGN (real_mode_blob_end - real_mode_blob); +size_t size =real_mode_blob_size ();size_t ro_size = PAGE_ALIGN(real_mode_header->ro_end) -
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
prerequisite-patch-id: 65b53ab526487dba9029340376ea5a469c8a50dc
Quoted 10 lines · Thorsten Blum
rmpiggy.Spage-aligns bothreal_mode_blobandreal_mode_blob_end. Their difference is therefore already page-aligned and does not requireALIGN()orPAGE_ALIGN().Since the real-mode blob size is calculated in three different places, add the
real_mode_blob_size()helper and use it inreal_mode_size_needed(),setup_real_mode(), andset_real_mode_permissions().No functional change.
Hi Thorsten,
For me, it's a pass on patches like these. They have a real risk of causing regressions and don't meaningfully make the code more maintainable.
So, it's all downside.
These are hurting the kernel more than helping at the moment. Please stop.