From: "Lendacky, Thomas" <thomas.lendacky@amd.com>
To: Laszlo Ersek <lersek@redhat.com>, devel@edk2.groups.io
Cc: Jordan Justen <jordan.l.justen@intel.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <liming.gao@intel.com>,
Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
Brijesh Singh <brijesh.singh@amd.com>
Subject: Re: [edk2-devel] [RFC PATCH v3 37/43] OvmfPkg: Reserve a page in memory for the SEV-ES AP reset vector
Date: Fri, 22 Nov 2019 10:40:09 -0600 [thread overview]
Message-ID: <f1a2cefd-9d9e-c5f8-31d4-090e23b561eb@amd.com> (raw)
In-Reply-To: <cf2c6b3e-4d37-410d-bf4e-2e5ea2ee0b1e@redhat.com>
On 11/22/19 10:06 AM, Laszlo Ersek wrote:
> On 11/21/19 23:49, Tom Lendacky wrote:
>> On 11/21/19 1:27 PM, Laszlo Ersek wrote:
>>> On 11/20/19 21:06, Lendacky, Thomas wrote:
>
>>>> +; sevEsResetBlock:
>>>> +; For the initial boot of an AP under SEV-ES, the "reset" RIP must be
>>>> +; programmed to the RAM area defined by SEV_ES_RESET_IP. A known offset
>>>> +; and GUID will be used to locate this block in the firmware and extract
>>>> +; the build time RIP value. The GUID must always be 48 bytes from the
>>>> +; end of the firmware.
>>>> +;
>>>> +; 0xffffffca (-0x36) - IP value
>>>> +; 0xffffffcc (-0x34) - CS selector value
>>>
>>> (5) I think the documentation of these four bytes is incorrect.
>>> (Similarly in the previous patch, in the commit message.) We populate
>>> these bytes with the *linear address* of the "reset trampoline" where
>>> the host will have to boot the AP for the first time. It's not
>>> expressed in real mode CS:IP notation / meaning.
>>
>> This is correct. The code will be in "big real mode" as you note below
>> (the reset vector is actually 0xfffffff0, just below 4GB and running
>> in 16-bit mode).
>>
>> If you look in Qemu, target/i386/cpu.c, x86_cpu_reset(), you'll see
>> where the CS segment is being loaded with a base of 0xffff0000 and the
>> eip gets loaded with 0xfff0.
>
> That still doesn't explain the above field names to me ("IP value" and
> "CS selector value"). Once the firmware image is built, we have:
>
> - CS: 0x0080
> - IP: 0xB000
>
> I don't understand the CS=0x80 part as
> - either a genuine segment selector
> - or the linear segment base address 0x800 (formed per real-address
> mode).
>
>> So the change to Qemu takes the "CS selector value" and effectively
>> left shifts it 16-bits to set the base
>
> This logic seems correct, as it translates 0x80 to 0x80_0000, i.e. 8 MB.
>
> However, I still think it's wrong to call the 16-bit value 0x0080 that
> we store at 0xffff_ffcc a "CS selector value". It is not a CS selector
> value, because it neither points into a segment descriptor table, nor is
> it left-shifted by 4-bits to form a linear base address, as in
> real-address mode.
>
> I would call this field
>
> most significant 16 bits of the CS base address [1]
>
>> and sets the eip to the "IP value" (in actuality, Qemu reads this as a
>> 32-bit value starting at the IP value and ANDs it with 0xffff0000 to
>> get the base and 0x0000ffff to get the eip.
>
> That seems correct to me.
>
> So... to summarize my point (5), *all* I'm asking for is to change the
> field description from "CS selector value" to [1] (or something to the
> same effect).
>
>>
>>>
>>>
>>> (6) Which brings me to my main point... Value 0x00B000 (for the
>>> "base" PCD) is relative to the base address of FD.MEMFD, namely 8MB
>>> (see MEMFD_BASE_ADDRESS).
>>>
>>> IOW, the ultimate value of SEV_ES_RESET_IP will be 0x0x0080_B000.
>>> That address is larger than 1MB.
>>
>> Which is ok since Qemu will set up CS appropriately.
>>
>>>
>>> Therefore, the host will have to launch the AP (for the first time)
>>> above 1MB (in guest-phys address space).
>>
>> Which is also OK, just like the BSP was launched at 0xFFFF_FFF0.
>>
>>>
>>> How can that work, if the AP is supposed to start in real mode? The
>>> linear address 0x0x0080_B000 cannot be expressed in 16-bit real mode
>>> CS:IP notation at all.
>>>
>>> Does the hypervisor start the AP in "big real mode" (16-bit mode with
>>> 4GB segment limits, and CS containing a segment selector, not the
>>> actual segment base)?
>
> Actually, I have to retract my question (6), because here I got lost in
> the weeds. I keep forgetting the following quirk in the Intel SDM:
>
> 9.1.4 First Instruction Executed
>
> The first instruction that is fetched and executed following a
> hardware reset is located at physical address FFFFFFF0H. This
> address is 16 bytes below the processors uppermost physical address.
> The EPROM containing the software- initialization code must be
> located at this address.
>
> The address FFFFFFF0H is beyond the 1-MByte addressable range of the
> processor while in real-address mode. The processor is initialized
> to this starting address as follows. The CS register has two parts:
> the visible segment selector part and the hidden base address part.
> In real-address mode, the base address is normally formed by
> shifting the 16-bit segment selector value 4 bits to the left to
> produce a 20-bit base address. However, during a hardware reset, the
> segment selector in the CS register is loaded with F000H and the
> base address is loaded with FFFF0000H. The starting address is thus
> formed by adding the base address to the value in the EIP register
> (that is, FFFF0000 + FFF0H = FFFFFFF0H).
>
> The first time the CS register is loaded with a new value after a
> hardware reset, the processor will follow the normal rule for
> address translation in real-address mode (that is, [CS base address
> = CS segment selector * 16]). To insure that the base address in the
> CS register remains unchanged until the EPROM based software-
> initialization code is completed, the code must not contain a far
> jump or far call or allow an interrupt to occur (which would cause
> the CS selector value to be changed).
>
> I need to be reminded of this every once in a while!
>
> While reviewing your patch, I thought that in real mode, the CS base
> address played no part, only the CS selector did -- which would be
> left-shifted by 4 bits directly, to form the segment base, in
> real-address mode.
>
> However, the fact is that the CS base address *always* plays a part
> (even in real mode). The "left shifting by 4 bits" does not occur when
> the CS:IP *reference* is made, but when the CS register is *loaded*
> explicitly, in real-address mode.
>
> And, at reset, CS is *pre-loaded*
> - with selector=0xF000, and
> - (as a quirk!) with base=0xFFFF_0000 (and *not* with base=0xF_0000, as
> the selector would otherwise dictate in real-address mode).
>
> And the QEMU change is that, at first AP boot, the CS will be pre-loaded
> - with selector=0x80 (which is a complete happenstance -- it's
> irrelevant!),
> - and, importantly, with base=0x80_0000 (and *not* with base=0x800, as
> the selector would otherwise dictate in real-address mode).
>
> So, it's all clear now (as long as you can please confirm that my
> understanding is finally correct).
>
> Thus, question (6) falls away.
>
>>> ... I guess that would answer my question (6) -- and the last few
>>> patches in this series, before this one, *do* suggest "big real mode"
>>> to me --, but the documentation around (5), and in the commit message
>>> of the previous patch, still doesn't match that.
>>
>> I'll expand on the commit message to indicate that Qemu, or others,
>> must do something similar relative to the CS register setup.
>
> To summarize, my request would be:
>
> - in the previous patch, please replace, in the commit message,
>
> Reset CS
>
> with
>
> most significant 16 bits of the reset CS base address
>
> - in this patch, please replace, in the code comment,
>
> CS selector value
>
> with
>
> most significant 16 bits of the CS base address
>
> (I mean... you *could* keep the current language in both places, but
> then you would have to describe this *entirely new* quirk for forming
> the CS base address from the CS selector value. This new SEV-ES / QEMU
> method does not match *any* { CS selector --> CS base address }
> transformation from the SDM, so you'd have to be quite verbose in the
> documenation.
>
> Given that the CS selector value 0x80 is completely irrelevant here, and
> we only care about the ultimate CS base address 0x80_0000, I'd suggest
> defining the 16-bit field at 0xffffffcc in terms of the desired CS base
> address [1], and not once mentioning "selector".)
Let me work on the wording and see what I come up with. I'll pass it by
you to see if it makes sense.
Thanks,
Tom
>
> Thanks!
> Laszlo
>
next prev parent reply other threads:[~2019-11-22 16:40 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-20 20:06 [RFC PATCH v3 00/43] SEV-ES guest support Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 01/43] MdePkg: Create PCDs to be used in support of SEV-ES Lendacky, Thomas
2019-12-12 6:53 ` Ni, Ray
2019-12-12 20:48 ` Lendacky, Thomas
2019-12-13 1:21 ` Ni, Ray
2019-11-20 20:06 ` [RFC PATCH v3 02/43] MdePkg: Add the MSR definition for the GHCB register Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 03/43] MdePkg: Add a structure definition for the GHCB Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 04/43] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Lendacky, Thomas
2019-12-12 6:53 ` [edk2-devel] " Ni, Ray
2019-12-12 20:58 ` Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 05/43] MdePkg/BaseLib: Add support for the XGETBV instruction Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 06/43] MdePkg/BaseLib: Add support for the VMGEXIT instruction Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 07/43] UefiCpuPkg: Implement library support for VMGEXIT Lendacky, Thomas
2019-11-21 11:15 ` [edk2-devel] " Laszlo Ersek
2019-11-21 16:48 ` Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 08/43] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 09/43] UefiCpuPkg/CpuExceptionHandler: Add support for IOIO_PROT NAE events Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 10/43] UefiCpuPkg/CpuExceptionHandler: Support string IO " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 11/43] UefiCpuPkg/CpuExceptionHandler: Add support for CPUID " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 12/43] UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 13/43] UefiCpuPkg/CpuExceptionHandler: Add support for NPF NAE events (MMIO) Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 14/43] UefiCpuPkg/CpuExceptionHandler: Add support for WBINVD NAE events Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 15/43] UefiCpuPkg/CpuExceptionHandler: Add support for RDTSC " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 16/43] UefiCpuPkg/CpuExceptionHandler: Add support for RDPMC " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 17/43] UefiCpuPkg/CpuExceptionHandler: Add support for INVD " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 18/43] UefiCpuPkg/CpuExceptionHandler: Add support for VMMCALL " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 19/43] UefiCpuPkg/CpuExceptionHandler: Add support for RDTSCP " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 20/43] UefiCpuPkg/CpuExceptionHandler: Add support for MONITOR/MONITORX " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 21/43] UefiCpuPkg/CpuExceptionHandler: Add support for MWAIT/MWAITX " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 22/43] UefiCpuPkg/CpuExceptionHandler: Add support for DR7 Read/Write " Lendacky, Thomas
2019-12-12 6:53 ` Ni, Ray
2019-12-12 20:27 ` Lendacky, Thomas
2019-12-12 6:53 ` Ni, Ray
2019-12-12 20:39 ` Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 23/43] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 24/43] OvmfPkg: Add support to perform SEV-ES initialization Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 25/43] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Lendacky, Thomas
2019-11-21 11:02 ` [edk2-devel] " Laszlo Ersek
2019-11-20 20:06 ` [RFC PATCH v3 26/43] OvmfPkg: Create a GHCB page for use during Sec phase Lendacky, Thomas
2019-11-21 11:29 ` [edk2-devel] " Laszlo Ersek
2019-11-20 20:06 ` [RFC PATCH v3 27/43] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 28/43] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Lendacky, Thomas
2019-12-12 6:54 ` Ni, Ray
2019-12-12 21:03 ` Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 29/43] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 30/43] OvmfPkg/Sec: Add #VC exception handling for Sec phase Lendacky, Thomas
2019-11-21 12:06 ` [edk2-devel] " Laszlo Ersek
2019-11-21 20:46 ` Lendacky, Thomas
2019-11-22 12:52 ` Laszlo Ersek
2019-11-22 16:30 ` Lendacky, Thomas
2019-11-22 21:10 ` Laszlo Ersek
2019-11-22 22:48 ` Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 31/43] OvmfPkg/Sec: Enable cache early to speed up booting Lendacky, Thomas
2019-11-21 12:08 ` [edk2-devel] " Laszlo Ersek
2019-11-20 20:06 ` [RFC PATCH v3 32/43] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES is enabled Lendacky, Thomas
2019-11-21 12:31 ` [edk2-devel] " Laszlo Ersek
2019-11-21 21:11 ` Lendacky, Thomas
2019-11-22 12:20 ` Laszlo Ersek
2019-11-20 20:06 ` [RFC PATCH v3 33/43] MdeModulePkg: Reserve a 16-bit protected mode code segment descriptor Lendacky, Thomas
2019-12-12 6:57 ` Ni, Ray
2019-12-12 21:19 ` [edk2-devel] " Lendacky, Thomas
2019-12-13 1:20 ` Ni, Ray
2019-11-20 20:06 ` [RFC PATCH v3 34/43] UefiCpuPkg: Add " Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 35/43] UefiCpuPkg/MpInitLib: Add a CPU MP data flag to indicate if SEV-ES is enabled Lendacky, Thomas
2019-12-12 7:01 ` Ni, Ray
2019-12-12 21:21 ` Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 36/43] UefiCpuPkg: Allow AP booting under SEV-ES Lendacky, Thomas
2019-11-20 20:06 ` [RFC PATCH v3 37/43] OvmfPkg: Reserve a page in memory for the SEV-ES AP reset vector Lendacky, Thomas
2019-11-21 19:27 ` [edk2-devel] " Laszlo Ersek
2019-11-21 22:49 ` Lendacky, Thomas
2019-11-22 16:06 ` Laszlo Ersek
2019-11-22 16:40 ` Lendacky, Thomas [this message]
2019-11-20 20:07 ` [RFC PATCH v3 38/43] OvmfPkg: Move the GHCB allocations into reserved memory Lendacky, Thomas
2019-11-20 20:07 ` [RFC PATCH v3 39/43] MdePkg: Add a finalization function to the CPU protocol Lendacky, Thomas
2019-11-20 21:32 ` [RFC PATCH v3 40/43] UefiCpuPkg/MpInitLib: Add MP finalization interface to MpInitLib Lendacky, Thomas
2019-11-20 21:32 ` [RFC PATCH v3 41/43] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Lendacky, Thomas
2019-11-20 21:32 ` [RFC PATCH v3 42/43] UefiCpuPkg/CpuDxe: Provide an DXE MP finalization routine to support SEV-ES Lendacky, Thomas
2019-11-20 21:32 ` [RFC PATCH v3 43/43] MdeModulePkg/DxeCore: Perform the CPU protocol finalization support Lendacky, Thomas
2019-11-21 1:53 ` [edk2-devel] [RFC PATCH v3 00/43] SEV-ES guest support Nate DeSimone
2019-11-21 15:50 ` Lendacky, Thomas
2019-11-21 9:45 ` Laszlo Ersek
2019-11-21 9:48 ` Laszlo Ersek
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=f1a2cefd-9d9e-c5f8-31d4-090e23b561eb@amd.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