All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baskov Evgeniy <baskov@ispras.ru>
To: grub-devel@gnu.org
Cc: Baskov Evgeniy <baskov@ispras.ru>
Subject: [PATCH RFC 2/3] relocator: allocate trampoline in lower 640k
Date: Thu,  7 Apr 2022 06:32:27 +0300	[thread overview]
Message-ID: <20220407033228.30242-3-baskov@ispras.ru> (raw)
In-Reply-To: <20220407033228.30242-1-baskov@ispras.ru>

For simplification, allocate trampoline in lower memory
for every x86 variation.

This would help setting right attributes for memory
in UEFI environments that restricts execution of some
memory regions.

Signed-off-by: Baskov Evgeniy <baskov@ispras.ru>

diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
index 54a1dcd8b..0b5a22dea 100644
--- a/grub-core/lib/i386/relocator.c
+++ b/grub-core/lib/i386/relocator.c
@@ -172,14 +172,13 @@ grub_relocator16_boot (struct grub_relocator *rel,
 
 grub_err_t
 grub_relocator64_boot (struct grub_relocator *rel,
-		       struct grub_relocator64_state state,
-		       grub_addr_t min_addr, grub_addr_t max_addr)
+		       struct grub_relocator64_state state)
 {
   grub_err_t err;
   void *relst;
   grub_relocator_chunk_t ch;
 
-  err = grub_relocator_alloc_chunk_align_safe (rel, &ch, min_addr, max_addr,
+  err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x1000, 0xa0000,
 					       RELOCATOR_SIZEOF (64), 16,
 					       GRUB_RELOCATOR_PREFERENCE_NONE, 0);
   if (err)
diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
index 68ef1289a..131b6859f 100644
--- a/grub-core/lib/relocator.c
+++ b/grub-core/lib/relocator.c
@@ -24,6 +24,7 @@
 #include <grub/memory.h>
 #include <grub/dl.h>
 #include <grub/i18n.h>
+#include <grub/efi/efi.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
diff --git a/grub-core/lib/x86_64/efi/relocator.c b/grub-core/lib/x86_64/efi/relocator.c
index 7d200a125..d438f9a05 100644
--- a/grub-core/lib/x86_64/efi/relocator.c
+++ b/grub-core/lib/x86_64/efi/relocator.c
@@ -47,10 +47,10 @@ grub_relocator64_efi_boot (struct grub_relocator *rel,
   grub_relocator_chunk_t ch;
 
   /*
-   * 64-bit relocator code may live above 4 GiB quite well.
-   * However, I do not want ask for problems. Just in case.
+   * GRUB relocator may be placed at any address but GRUB EFI setup code
+   * only guaranties the range [0x1000; 0xa0000) to be executable.
    */
-  err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0, 0x100000000,
+  err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0, 0xa0000,
 					       RELOCATOR_SIZEOF (64_efi), 16,
 					       GRUB_RELOCATOR_PREFERENCE_NONE, 1);
   if (err)
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
index 799a24cd2..8b4ae5ba2 100644
--- a/grub-core/loader/i386/bsd.c
+++ b/grub-core/loader/i386/bsd.c
@@ -763,7 +763,7 @@ grub_freebsd_boot (void)
       stack[0] = entry;
       stack[1] = bi.tags;
       stack[2] = kern_end;
-      return grub_relocator64_boot (relocator, state, 0, 0x40000000);
+      return grub_relocator64_boot (relocator, state);
     }
   else
     {
diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
index 2a56c3b54..0dbd1f25c 100644
--- a/include/grub/i386/relocator.h
+++ b/include/grub/i386/relocator.h
@@ -87,8 +87,7 @@ grub_err_t grub_relocator32_boot (struct grub_relocator *rel,
 				  int avoid_efi_bootservices);
 
 grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
-				  struct grub_relocator64_state state,
-				  grub_addr_t min_addr, grub_addr_t max_addr);
+				  struct grub_relocator64_state state);
 
 #ifdef GRUB_MACHINE_EFI
 #ifdef __x86_64__
-- 
2.35.1



  parent reply	other threads:[~2022-04-07 14:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07  3:32 [PATCH RFC 0/3] EFI memory attributes Baskov Evgeniy
2022-04-07  3:32 ` [PATCH RFC 1/3] efi: provide definitions of DXE services table Baskov Evgeniy
2022-04-11  7:12   ` Paul Menzel
2022-04-14 15:15     ` baskov
2022-04-07  3:32 ` Baskov Evgeniy [this message]
2022-04-07  3:32 ` [PATCH RFC 3/3] efi: explicitly set memory attributes for memory Baskov Evgeniy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220407033228.30242-3-baskov@ispras.ru \
    --to=baskov@ispras.ru \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.