public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: Ard Biesheuvel <ardb@kernel.org>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>,
	Rebecca Cran <rebecca@bsdio.com>
Cc: Andrew Fish <afish@apple.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Liu, Zhiguang" <zhiguang.liu@intel.com>
Subject: Re: [edk2-devel] Is Xcode5ExceptionHandlerAsm.nasm still needed?
Date: Thu, 30 Mar 2023 14:25:30 +0000	[thread overview]
Message-ID: <MN6PR11MB8244608E77DDA409C8CE7E5E8C8E9@MN6PR11MB8244.namprd11.prod.outlook.com> (raw)
In-Reply-To: <CAMj1kXF0QPnKG7-e2RDm38g9TL4bsUFpJGBp0y9uMSnkv9g3Yw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3557 bytes --]

I am afraid they are not template code.
That means if nx is set for data section, they can not be executed.


thanks,
ray
________________________________
From: Ard Biesheuvel <ardb@kernel.org>
Sent: Thursday, March 30, 2023 7:47:03 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>; Ni, Ray <ray.ni@intel.com>; Rebecca Cran <rebecca@bsdio.com>
Cc: Andrew Fish <afish@apple.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com>
Subject: Re: [edk2-devel] Is Xcode5ExceptionHandlerAsm.nasm still needed?

(cc Rebecca)

On Thu, 30 Mar 2023 at 12:48, Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Thu, 30 Mar 2023 at 12:16, Ni, Ray <ray.ni@intel.com> wrote:
> >
> > Andrew,
> >
> > In UefiCpuPkg\Library\CpuExceptionHandlerLib\X64\, there are two nasm files: ExceptionHandlerAsm.nasm and the other XCODE version.
> >
> >
> >
> > The major diff between the two is the second operand in “mov rax, ASM_PFX(CommonInterruptEntry)” is patched at runtime by code, instead of relying on linker/loader to fix it.
> >
> > Can I know more background why it’s needed for XCODE?
> >
> >
> >
> > Given Apple is switching away from X86 CPU, is the XCODE version still needed?
> >
> >
> >
> > + Mike because I found another commit by you for bug: 565 – Fix X64 XCODE5/NASM compatibility issue in UefiCpuPkg MpInitLib (tianocore.org).
> >
> >
>
>
> Yes, we still need it, also for non-Xcode clang + lld
>
> The problem is that the little code templates use absolute addressing
> to refer to the jump targets. This is necessary because these
> templates are copied into the vector table, and so they are moved
> independently from the code they refer to, and so relative addressing
> is not an option here.
>
> One thing I haven't tried yet is to emit the template code into .data
> instead of .text, which /should/ be fine given that the template code
> is never executed directly, only the copied versions are executed.

I had a quick go at this, and the change below appears to work: it
moves the template code into .data, and changes the absolute
references to relative ones in the code that executes from where it
gets loaded.

I'm not sure how to test this, though.



--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
@@ -27,7 +27,6 @@ extern ASM_PFX(CommonExceptionHandler)
 SECTION .data

 DEFAULT REL
-SECTION .text

 ALIGN   8

@@ -51,6 +50,9 @@ HookAfterStubHeaderBegin:
     push    rax
     mov     rax, HookAfterStubHeaderEnd
     jmp     rax
+
+SECTION .text
+
 HookAfterStubHeaderEnd:
     mov     rax, rsp
     and     sp,  0xfff0        ; make sure 16-byte aligned for
exception context
@@ -276,8 +278,7 @@ DrFinish:
     ; and make sure RSP is 16-byte aligned
     ;
     sub     rsp, 4 * 8 + 8
-    mov     rax, ASM_PFX(CommonExceptionHandler)
-    call    rax
+    call    ASM_PFX(CommonExceptionHandler)
     add     rsp, 4 * 8 + 8

     cli
@@ -384,10 +385,10 @@ DoIret:
 ; comments here for definition of address map
 global ASM_PFX(AsmGetTemplateAddressMap)
 ASM_PFX(AsmGetTemplateAddressMap):
-    mov     rax, AsmIdtVectorBegin
+    lea     rax, AsmIdtVectorBegin
     mov     qword [rcx], rax
     mov     qword [rcx + 0x8],  (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32
-    mov     rax, HookAfterStubHeaderBegin
+    lea     rax, HookAfterStubHeaderBegin
     mov     qword [rcx + 0x10], rax
     ret

[-- Attachment #2: Type: text/html, Size: 5666 bytes --]

  reply	other threads:[~2023-03-30 14:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 10:16 Is Xcode5ExceptionHandlerAsm.nasm still needed? Ni, Ray
2023-03-30 10:48 ` [edk2-devel] " Ard Biesheuvel
2023-03-30 11:47   ` Ard Biesheuvel
2023-03-30 14:25     ` Ni, Ray [this message]
2023-03-30 15:04       ` Ard Biesheuvel
2023-03-30 16:33         ` Ard Biesheuvel
2023-03-30 16:47           ` Ard Biesheuvel
2023-03-30 16:54           ` Rebecca Cran
2023-03-30 17:03             ` Ard Biesheuvel
2023-03-30 15:30 ` Michael D Kinney

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-list 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=MN6PR11MB8244608E77DDA409C8CE7E5E8C8E9@MN6PR11MB8244.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox