Hi Ersek
I think S3ResumePei supports Ia32 and Ia32X64. It does not support X64. So I 
believe Ia32X64 crash is a bug somewhere.

Since you already run into SmmRestoreCpu(), would you please help to check 
where is last instruction causing crash?

Thank you
Yao Jiewen

-----Original Message-----
From: Laszlo Ersek [mailto:[email protected]] 
Sent: Thursday, October 29, 2015 7:59 AM
To: Yao, Jiewen; Kinney, Michael D; Fan, Jeff
Cc: edk2-devel-01
Subject: Re: about the SMM_S3_RESUME_SMM_64 branch in S3Resume2Pei

On 10/28/15 23:41, Laszlo Ersek wrote:
> On 10/28/15 23:26, Yao, Jiewen wrote:
>> Right. It seems S3Resume2Pei does not consider X64 mode. I found at least 3 
>> functions need enhancement on mode transition:
>> 1) S3RestoreConfig2() - S3Resume <-> SmmCpu (DXE mode);
>> 2) S3ResumeExecuteBootScript() - S3Resume <-> BootScriptExecutor (DXE 
>> mode)
>> 3) S3ResumeBootOs() - S3Resume -> OS WakingVector (OS decide).
> 
> In practice at least, these problems appear specific to SMM / SMRAM 
> usage. When we use OVMF's custom (insecure) LockBoxLib instance, the 
> X64 build of S3Resume2Pei (actually, a fully X64 build of OVMF) 
> provides a working S3 feature, including Windows 7 and later guests, 
> and Linux guests. Even a minimal boot script is executed correctly (it 
> has just an INFO opcode).
> 
> If I remember correctly, quite a few code paths are possible through 
> S3Resume2Pei. I don't exactly recall which one is taken in the above 
> case, but I thought I'd point out that it works very well in practice.
> (The fact notwithstanding that the lockbox is not protected from the 
> runtime guest OS.)
> 
> The pure Ia32 case works well both with and without OVMF's SMM feature.
> 
> I don't recall ever testing S3 with the Ia32X64 build; I plan to do 
> that soonish.

Ia32X64 crashes (with SMM enabled) with the following messages leading up to it:

--------
SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Exit (Success) 
S3NvsPageTableAddress - 7DFDE000 (1)
SMM S3 Signature                = 534D4D53
SMM S3 Stack Base               = 7FF8A000
SMM S3 Stack Size               = 8000
SMM S3 Resume Entry Point       = 7FFB5617
SMM S3 CR0                      = 80000033
SMM S3 CR3                      = 7FF84000
SMM S3 CR4                      = 668
SMM S3 Return CS                = 10
SMM S3 Return Entry Point       = 846C69
SMM S3 Return Context1          = 7F6FA000
SMM S3 Return Context2          = 7E039000
SMM S3 Return Stack Pointer     = 81730C
SMM S3 Smst                     = 7FFFDE00
SmmRestoreCpu()
<CRASH>
--------

If I build without SMM, then Ia32X64 works fine as well.

Summary:
- without SMM: S3 works in all three of the Ia32, Ia32X64, and X64
  OVMF builds
- with SMM: Ia32 works, the other two crash.

I guess this just confirms what you've already determined from the code.
But, at least, it confirms it. :)

Thank you all for looking into it!
Laszlo


> 
> Thanks,
> Laszlo
> 
>> Thank you
>> Yao Jiewen
>>
>> -----Original Message-----
>> From: Laszlo Ersek [mailto:[email protected]]
>> Sent: Thursday, October 29, 2015 1:34 AM
>> To: Kinney, Michael D; Fan, Jeff; Yao, Jiewen
>> Cc: edk2-devel-01
>> Subject: Re: about the SMM_S3_RESUME_SMM_64 branch in S3Resume2Pei
>>
>> On 10/28/15 17:54, Kinney, Michael D wrote:
>>> Laszlo,
>>>
>>> I do not believe any X64 PEI testing has not been performed with this 
>>> module.  We will investigate a fix.
>>
>> Thank you.
>>
>> In any case, in OVMF we might be able to use this module nonetheless, with 
>> the OvmfPkgIa32X64.dsc build (== 32-bit PEI, 64-bit DXE).
>>
>> Thanks!
>> Laszlo
>>
>>>
>>> Thanks,
>>>
>>> Mike
>>>
>>>> -----Original Message-----
>>>> From: Laszlo Ersek [mailto:[email protected]]
>>>> Sent: Wednesday, October 28, 2015 8:57 AM
>>>> To: Fan, Jeff; Yao, Jiewen
>>>> Cc: edk2-devel-01; Kinney, Michael D
>>>> Subject: about the SMM_S3_RESUME_SMM_64 branch in S3Resume2Pei
>>>>
>>>> Hi,
>>>>
>>>> I have a question about the following code in 
>>>> "UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c", function
>>>> S3RestoreConfig2():
>>>>
>>>>>     if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) {
>>>>>       //
>>>>>       // Switch to long mode to complete resume.
>>>>>       //
>>>>>
>>>>>       InterruptStatus = SaveAndDisableInterrupts ();
>>>>>       //
>>>>>       // Need to make sure the GDT is loaded with values that 
>>>>> support long
>>>> mode and real mode.
>>>>>       //
>>>>>       AsmWriteGdtr (&mGdt);
>>>>>       //
>>>>>       // update segment selectors per the new GDT.
>>>>>       //
>>>>>       AsmSetDataSelectors (DATA_SEGEMENT_SELECTOR);
>>>>>       //
>>>>>       // Restore interrupt state.
>>>>>       //
>>>>>       SetInterruptState (InterruptStatus);
>>>>>
>>>>>       AsmWriteCr3 ((UINTN)SmmS3ResumeState->SmmS3Cr3);
>>>>>
>>>>>       //
>>>>>       // Disable interrupt of Debug timer, since IDT table cannot 
>>>>> work in long
>>>> mode.
>>>>>       // NOTE: On x64 platforms, because DisablePaging64() will 
>>>>> disable
>>>> interrupts,
>>>>>       // the code in S3ResumeExecuteBootScript() cannot be halted 
>>>>> by soft
>>>> debugger.
>>>>>       //
>>>>>       SaveAndSetDebugTimerInterrupt (FALSE);
>>>>>
>>>>>       AsmEnablePaging64 (
>>>>>         0x38,
>>>>>         SmmS3ResumeState->SmmS3ResumeEntryPoint,
>>>>>         (UINT64)(UINTN)AcpiS3Context,
>>>>>         0,
>>>>>         SmmS3ResumeState->SmmS3StackBase + SmmS3ResumeState- 
>>>>> SmmS3StackSize
>>>>>         );
>>>>>     }
>>>>
>>>> At the end of this block, the AsmEnablePaging64() function is called. 
>>>> That call results in the following call tree, *if* the module was built 
>>>> for X64:
>>>>
>>>> AsmEnablePaging64()           [MdePkg/Library/BaseLib/X86EnablePaging64.c]
>>>>  InternalX86EnablePaging64() [MdePkg/Library/BaseLib/X64/Non-existing.c]
>>>>    ASSERT (FALSE)
>>>>
>>>> This is because the InternalX86EnablePaging64() functionality is 
>>>> unavailable in BaseLib on X64.
>>>>
>>>> My question: how is this branch in S3RestoreConfig2() supposed to 
>>>> work *at
>>>> all* in an X64 PEI build?
>>>>
>>>> Thank you,
>>>> Laszlo
>>
> 

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to