Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-03 Thread Laszlo Ersek
On 11/04/16 00:19, Marvin Häuser wrote:
> Hey Laszlo,
> 
> I'm quoting Jordan's mail because, for some reason, I didn't receive yours.
> Sure, I'm fine with you re-posting the patches, though I thought I considered 
> everything you had said in v3 (not abstracting the size and adding the error 
> message).
> Sorry if I didn't consider something, in that case I must have overread it.
> 
> Thanks for 'fixing' the patches!

My email is overflowing and I've switched into batched / temporarily
write-only mode. I think I got out of sync with you guys. I'll look at
your v3 patches soon -- they take priority over my modifications, of course.

Thanks
Laszlo

>> -Original Message-
>> From: Jordan Justen [mailto:jordan.l.jus...@intel.com]
>> Sent: Friday, November 4, 2016 12:10 AM
>> To: Laszlo Ersek <ler...@redhat.com>; Marvin Häuser
>> <marvin.haeu...@outlook.com>
>> Cc: edk2-devel@lists.01.org
>> Subject: Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD
>> values of the page tables.
>>
>> On 2016-11-03 15:55:10, Laszlo Ersek wrote:
>>> Hi Marvin,
>>>
>>> On 11/03/16 20:18, Marvin Häuser wrote:
>>>> Currently, the values of the page tables' address and size are
>>>> hard-coded in the ResetVector. This patch replaces this with a PCD
>>>> dependency for the NASM Reset Vector. The ASM Reset Vector remains
>>>> using a hard-coded value due to the lack of C preprocessing.
>>>>
>>>> Checks for the size have been added to alert the developer to
>>>> rewrite the ASM according to the new size, if it has been changed.
>>>>
>>>> Contributed-under: TianoCore Contribution Agreement 1.0
>>>> Signed-off-by: Marvin Haeuser <marvin.haeu...@outlook.com>
>>>> ---
>>>>  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++-
>> -
>>>>  OvmfPkg/ResetVector/ResetVector.inf   |  5 +
>>>>  OvmfPkg/ResetVector/ResetVector.nasmb |  7 ++
>>>>  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++
>>>>  4 files changed, 39 insertions(+), 12 deletions(-)
>>>
>>> I'll soon send a modified / simplified version of your patch (keeping
>>> your authorship and S-o-b in the first place of course). I find that
>>> simpler than struggling with an explanation :) I hope you're fine with this.
>>>
>>
>> Marvin's v3 seemed okay, but of course, it should be a series, together with
>> his separate patch that removes the unused ResetVectorCode.asm file.
>>
>> If your tweaks are minor, you can add my
>>
>> Reviewed-by: Jordan Justen <jordan.l.jus...@intel.com>
>>
>> to both of his patches.
>>
>> Thanks,
>>
>> -Jordan

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-03 Thread Marvin Häuser
Hey Laszlo,

I'm quoting Jordan's mail because, for some reason, I didn't receive yours.
Sure, I'm fine with you re-posting the patches, though I thought I considered 
everything you had said in v3 (not abstracting the size and adding the error 
message).
Sorry if I didn't consider something, in that case I must have overread it.

Thanks for 'fixing' the patches!

Regards,
Marvin.

> -Original Message-
> From: Jordan Justen [mailto:jordan.l.jus...@intel.com]
> Sent: Friday, November 4, 2016 12:10 AM
> To: Laszlo Ersek <ler...@redhat.com>; Marvin Häuser
> <marvin.haeu...@outlook.com>
> Cc: edk2-devel@lists.01.org
> Subject: Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD
> values of the page tables.
> 
> On 2016-11-03 15:55:10, Laszlo Ersek wrote:
> > Hi Marvin,
> >
> > On 11/03/16 20:18, Marvin Häuser wrote:
> > > Currently, the values of the page tables' address and size are
> > > hard-coded in the ResetVector. This patch replaces this with a PCD
> > > dependency for the NASM Reset Vector. The ASM Reset Vector remains
> > > using a hard-coded value due to the lack of C preprocessing.
> > >
> > > Checks for the size have been added to alert the developer to
> > > rewrite the ASM according to the new size, if it has been changed.
> > >
> > > Contributed-under: TianoCore Contribution Agreement 1.0
> > > Signed-off-by: Marvin Haeuser <marvin.haeu...@outlook.com>
> > > ---
> > >  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++-
> -
> > >  OvmfPkg/ResetVector/ResetVector.inf   |  5 +
> > >  OvmfPkg/ResetVector/ResetVector.nasmb |  7 ++
> > >  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++
> > >  4 files changed, 39 insertions(+), 12 deletions(-)
> >
> > I'll soon send a modified / simplified version of your patch (keeping
> > your authorship and S-o-b in the first place of course). I find that
> > simpler than struggling with an explanation :) I hope you're fine with this.
> >
> 
> Marvin's v3 seemed okay, but of course, it should be a series, together with
> his separate patch that removes the unused ResetVectorCode.asm file.
> 
> If your tweaks are minor, you can add my
> 
> Reviewed-by: Jordan Justen <jordan.l.jus...@intel.com>
> 
> to both of his patches.
> 
> Thanks,
> 
> -Jordan
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-03 Thread Jordan Justen
On 2016-11-03 15:55:10, Laszlo Ersek wrote:
> Hi Marvin,
> 
> On 11/03/16 20:18, Marvin Häuser wrote:
> > Currently, the values of the page tables' address and size are
> > hard-coded in the ResetVector. This patch replaces this with a PCD
> > dependency for the NASM Reset Vector. The ASM Reset Vector remains
> > using a hard-coded value due to the lack of C preprocessing.
> > 
> > Checks for the size have been added to alert the developer to rewrite
> > the ASM according to the new size, if it has been changed.
> > 
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Marvin Haeuser 
> > ---
> >  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++--
> >  OvmfPkg/ResetVector/ResetVector.inf   |  5 +
> >  OvmfPkg/ResetVector/ResetVector.nasmb |  7 ++
> >  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++
> >  4 files changed, 39 insertions(+), 12 deletions(-)
> 
> I'll soon send a modified / simplified version of your patch (keeping
> your authorship and S-o-b in the first place of course). I find that
> simpler than struggling with an explanation :) I hope you're fine with this.
> 

Marvin's v3 seemed okay, but of course, it should be a series,
together with his separate patch that removes the unused
ResetVectorCode.asm file.

If your tweaks are minor, you can add my

Reviewed-by: Jordan Justen 

to both of his patches.

Thanks,

-Jordan
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-03 Thread Laszlo Ersek
Hi Marvin,

On 11/03/16 20:18, Marvin Häuser wrote:
> Currently, the values of the page tables' address and size are
> hard-coded in the ResetVector. This patch replaces this with a PCD
> dependency for the NASM Reset Vector. The ASM Reset Vector remains
> using a hard-coded value due to the lack of C preprocessing.
> 
> Checks for the size have been added to alert the developer to rewrite
> the ASM according to the new size, if it has been changed.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Marvin Haeuser 
> ---
>  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++--
>  OvmfPkg/ResetVector/ResetVector.inf   |  5 +
>  OvmfPkg/ResetVector/ResetVector.nasmb |  7 ++
>  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++
>  4 files changed, 39 insertions(+), 12 deletions(-)

I'll soon send a modified / simplified version of your patch (keeping
your authorship and S-o-b in the first place of course). I find that
simpler than struggling with an explanation :) I hope you're fine with this.

Thanks!
Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-03 Thread Marvin Häuser
Hey Jordan,
Hey Laszlo,

I just pushed a v3. Changes:
* Pushed a patch to remove ResetVector.asm. As this is not really connected to 
the change after, I made it a separate patch rather than a series.

* Don't abstract or use the PCD size as, as Laszlo pointed out, it makes little 
sense, because the rest of the ASM needs to be adapter to the size change 
anyway, if one changes it. Do you see a way to make this dynamic too? Maybe 
calculate the offsets by division?
* Make clear in the comment that the PCD value is used for the address.
* Move PT_ADDR() to the ResetVector file so there is no need to abstract the 
Address PCD for the PageTables file.
* Include addition/subtractions after PT_ADDR() into the brackets, as suggested 
by Jordan.

Regards,
Marvin.

> -Original Message-
> From: Jordan Justen [mailto:jordan.l.jus...@intel.com]
> Sent: Thursday, November 3, 2016 9:59 PM
> To: Marvin Häuser ; edk2-
> de...@lists.01.org
> Cc: ler...@redhat.com
> Subject: Re: [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the
> page tables.
> 
> On 2016-11-03 12:18:56, Marvin Häuser wrote:
> > Currently, the values of the page tables' address and size are
> > hard-coded in the ResetVector. This patch replaces this with a PCD
> > dependency for the NASM Reset Vector. The ASM Reset Vector remains
> > using a hard-coded value due to the lack of C preprocessing.
> >
> > Checks for the size have been added to alert the developer to rewrite
> > the ASM according to the new size, if it has been changed.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Marvin Haeuser 
> > ---
> >  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++--
> >  OvmfPkg/ResetVector/ResetVector.inf   |  5 +
> >  OvmfPkg/ResetVector/ResetVector.nasmb |  7 ++
> >  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++
> >  4 files changed, 39 insertions(+), 12 deletions(-)
> >
> > diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > index b5a4cf8d7187..7ff394b1afc3 100644
> > --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > @@ -37,6 +37,8 @@ BITS32
> > PAGE_READ_WRITE + \
> > PAGE_PRESENT)
> >
> > +%define PT_ADDR(Offset) (OVMF_SEC_PAGE_TABLES_BASE + (Offset))
> > +
> >
> >  ;
> >  ; Modified:  EAX, ECX
> > @@ -46,31 +48,28 @@ SetCr3ForPageTables64:
> >  ;
> >  ; For OVMF, build some initial page tables at 0x80-0x806000.
> >  ;
> > -; This range should match with PcdOvmfSecPageTablesBase and
> > -; PcdOvmfSecPageTablesSize which are declared in the FDF files.
> > -;
> >  ; At the end of PEI, the pages tables will be rebuilt into a
> >  ; more permanent location by DxeIpl.
> >  ;
> >
> > -mov ecx, 6 * 0x1000 / 4
> > +mov ecx, OVMF_SEC_PAGE_TABLES_SIZE / 4
> >  xor eax, eax
> >  clearPageTablesMemoryLoop:
> > -mov dword[ecx * 4 + 0x80 - 4], eax
> > +mov dword[ecx * 4 + PT_ADDR (0) - 4], eax
> >  loopclearPageTablesMemoryLoop
> >
> >  ;
> >  ; Top level Page Directory Pointers (1 * 512GB entry)
> >  ;
> > -mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
> > +mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR
> >
> >  ;
> >  ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
> >  ;
> > -mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
> > -mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
> > -mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
> > -mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
> > +mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) +
> PAGE_PDP_ATTR
> > +mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) +
> PAGE_PDP_ATTR
> > +mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) +
> PAGE_PDP_ATTR
> > +mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) +
> PAGE_PDP_ATTR
> >
> >  ;
> >  ; Page Table Entries (2048 * 2MB entries => 4GB) @@ -81,13 +80,13
> > @@ pageTableEntriesLoop:
> >  dec eax
> >  shl eax, 21
> >  add eax, PAGE_2M_PDE_ATTR
> > -mov [ecx * 8 + 0x802000 - 8], eax
> > +mov [ecx * 8 + PT_ADDR (0x2000) - 8], eax
> 
> I think the '- 8' should be in the PT_ADDR.
> 
> This patch is basically
> 
> Reviewed-by: Jordan Justen 
> 
> except, like Laszlo pointed out, I think that ResetVectorCode.asm should
> have been deleted in 70e46f44cd13.
> 
> So, before this patch, I think we should add a patch to delete it.
> Then you won't need to modify it, and only the PCD's will be used.
> 
> Would you like to make these changes, or would you like me to?
> 
> Thanks,
> 
> -Jordan
> 
> >  looppageTableEntriesLoop
> >
> >  ;
> >  ; Set CR3 now that the paging structures are available
> 

Re: [edk2] [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-03 Thread Jordan Justen
On 2016-11-03 12:18:56, Marvin Häuser wrote:
> Currently, the values of the page tables' address and size are
> hard-coded in the ResetVector. This patch replaces this with a PCD
> dependency for the NASM Reset Vector. The ASM Reset Vector remains
> using a hard-coded value due to the lack of C preprocessing.
> 
> Checks for the size have been added to alert the developer to rewrite
> the ASM according to the new size, if it has been changed.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Marvin Haeuser 
> ---
>  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++--
>  OvmfPkg/ResetVector/ResetVector.inf   |  5 +
>  OvmfPkg/ResetVector/ResetVector.nasmb |  7 ++
>  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++
>  4 files changed, 39 insertions(+), 12 deletions(-)
> 
> diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
> b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> index b5a4cf8d7187..7ff394b1afc3 100644
> --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> @@ -37,6 +37,8 @@ BITS32
> PAGE_READ_WRITE + \
> PAGE_PRESENT)
>  
> +%define PT_ADDR(Offset) (OVMF_SEC_PAGE_TABLES_BASE + (Offset))
> +
>  
>  ;
>  ; Modified:  EAX, ECX
> @@ -46,31 +48,28 @@ SetCr3ForPageTables64:
>  ;
>  ; For OVMF, build some initial page tables at 0x80-0x806000.
>  ;
> -; This range should match with PcdOvmfSecPageTablesBase and
> -; PcdOvmfSecPageTablesSize which are declared in the FDF files.
> -;
>  ; At the end of PEI, the pages tables will be rebuilt into a
>  ; more permanent location by DxeIpl.
>  ;
>  
> -mov ecx, 6 * 0x1000 / 4
> +mov ecx, OVMF_SEC_PAGE_TABLES_SIZE / 4
>  xor eax, eax
>  clearPageTablesMemoryLoop:
> -mov dword[ecx * 4 + 0x80 - 4], eax
> +mov dword[ecx * 4 + PT_ADDR (0) - 4], eax
>  loopclearPageTablesMemoryLoop
>  
>  ;
>  ; Top level Page Directory Pointers (1 * 512GB entry)
>  ;
> -mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
> +mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR
>  
>  ;
>  ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
>  ;
> -mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
> -mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
> -mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
> -mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
> +mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDP_ATTR
> +mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) + PAGE_PDP_ATTR
> +mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) + PAGE_PDP_ATTR
> +mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) + PAGE_PDP_ATTR
>  
>  ;
>  ; Page Table Entries (2048 * 2MB entries => 4GB)
> @@ -81,13 +80,13 @@ pageTableEntriesLoop:
>  dec eax
>  shl eax, 21
>  add eax, PAGE_2M_PDE_ATTR
> -mov [ecx * 8 + 0x802000 - 8], eax
> +mov [ecx * 8 + PT_ADDR (0x2000) - 8], eax

I think the '- 8' should be in the PT_ADDR.

This patch is basically

Reviewed-by: Jordan Justen 

except, like Laszlo pointed out, I think that ResetVectorCode.asm
should have been deleted in 70e46f44cd13.

So, before this patch, I think we should add a patch to delete it.
Then you won't need to modify it, and only the PCD's will be used.

Would you like to make these changes, or would you like me to?

Thanks,

-Jordan

>  looppageTableEntriesLoop
>  
>  ;
>  ; Set CR3 now that the paging structures are available
>  ;
> -mov eax, 0x80
> +mov eax, OVMF_SEC_PAGE_TABLES_BASE
>  mov cr3, eax
>  
>  OneTimeCallRet SetCr3ForPageTables64
> diff --git a/OvmfPkg/ResetVector/ResetVector.inf 
> b/OvmfPkg/ResetVector/ResetVector.inf
> index 46610d243ecf..d1e5d4d9bdea 100644
> --- a/OvmfPkg/ResetVector/ResetVector.inf
> +++ b/OvmfPkg/ResetVector/ResetVector.inf
> @@ -29,9 +29,14 @@ [Sources]
>ResetVector.nasmb
>  
>  [Packages]
> +  OvmfPkg/OvmfPkg.dec
>MdePkg/MdePkg.dec
>UefiCpuPkg/UefiCpuPkg.dec
>  
>  [BuildOptions]
> *_*_IA32_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
> *_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
> +
> +[Pcd]
> +  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
> +  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
> diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
> b/OvmfPkg/ResetVector/ResetVector.nasmb
> index 31ac06ae4a8c..62597ea95cf5 100644
> --- a/OvmfPkg/ResetVector/ResetVector.nasmb
> +++ b/OvmfPkg/ResetVector/ResetVector.nasmb
> @@ -53,6 +53,13 @@
>  %include "Ia32/SearchForSecEntry.asm"
>  
>  %ifdef ARCH_X64
> +  #include 
> +  %define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32 (PcdOvmfSecPageTablesBase)
> +  %define OVMF_SEC_PAGE_TABLES_SIZE