[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM |
Date: |
Mon, 21 Aug 2023 10:38:18 +0100 |
User-agent: |
Mutt/2.2.9 (2022-11-12) |
On Fri, Aug 18, 2023 at 05:50:15AM -0400, Xiaoyao Li wrote:
> The RAM of TDX VM can be classified into two types:
>
> - TDX_RAM_UNACCEPTED: default type of TDX memory, which needs to be
> accepted by TDX guest before it can be used and will be all-zeros
> after being accepted.
>
> - TDX_RAM_ADDED: the RAM that is ADD'ed to TD guest before running, and
> can be used directly. E.g., TD HOB and TEMP MEM that needed by TDVF.
>
> Maintain TdxRamEntries[] which grabs the initial RAM info from e820 table
> and mark each RAM range as default type TDX_RAM_UNACCEPTED.
>
> Then turn the range of TD HOB and TEMP MEM to TDX_RAM_ADDED since these
> ranges will be ADD'ed before TD runs and no need to be accepted runtime.
>
> The TdxRamEntries[] are later used to setup the memory TD resource HOB
> that passes memory info from QEMU to TDVF.
>
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
>
> ---
> Changes from RFC v4:
> - simplify the algorithm of tdx_accept_ram_range() (Suggested-by: Gerd
> Hoffman)
> (1) Change the existing entry to cover the accepted ram range.
> (2) If there is room before the accepted ram range add a
> TDX_RAM_UNACCEPTED entry for that.
> (3) If there is room after the accepted ram range add a
> TDX_RAM_UNACCEPTED entry for that.
> ---
> target/i386/kvm/tdx.c | 110 ++++++++++++++++++++++++++++++++++++++++++
> target/i386/kvm/tdx.h | 14 ++++++
> 2 files changed, 124 insertions(+)
>
> diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
> index bb806736b4ff..ed617ebab266 100644
> --- a/target/i386/kvm/tdx.c
> +++ b/target/i386/kvm/tdx.c
> +static int tdx_accept_ram_range(uint64_t address, uint64_t length)
> +{
> + uint64_t head_start, tail_start, head_length, tail_length;
> + uint64_t tmp_address, tmp_length;
> + TdxRamEntry *e;
> + int i;
> +
> + for (i = 0; i < tdx_guest->nr_ram_entries; i++) {
> + e = &tdx_guest->ram_entries[i];
> +
> + if (address + length <= e->address ||
> + e->address + e->length <= address) {
> + continue;
Indented too far
> + }
> +
> + /*
> + * The to-be-accepted ram range must be fully contained by one
> + * RAM entry.
> + */
> + if (e->address > address ||
> + e->address + e->length < address + length) {
> + return -EINVAL;
> + }
> +
> + if (e->type == TDX_RAM_ADDED) {
> + return -EINVAL;
> + }
> +
> + break;
> + }
> +
> + if (i == tdx_guest->nr_ram_entries) {
> + return -1;
> + }
> +
> + tmp_address = e->address;
> + tmp_length = e->length;
> +
> + e->address = address;
> + e->length = length;
> + e->type = TDX_RAM_ADDED;
> +
> + head_length = address - tmp_address;
> + if (head_length > 0) {
> + head_start = tmp_address;
> + tdx_add_ram_entry(head_start, head_length, TDX_RAM_UNACCEPTED);
> + }
> +
> + tail_start = address + length;
> + if (tail_start < tmp_address + tmp_length) {
> + tail_length = tmp_address + tmp_length - tail_start;
> + tdx_add_ram_entry(tail_start, tail_length, TDX_RAM_UNACCEPTED);
> + }
> +
> + return 0;
> +}
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- Re: [PATCH v2 25/58] kvm/tdx: Don't complain when converting vMMIO region to shared, (continued)
- [PATCH v2 28/58] i386/tdx: Parse TDVF metadata for TDX VM, Xiaoyao Li, 2023/08/18
- [PATCH v2 26/58] kvm/tdx: Ignore memory conversion to shared of unassigned region, Xiaoyao Li, 2023/08/18
- [PATCH v2 27/58] i386/tdvf: Introduce function to parse TDVF metadata, Xiaoyao Li, 2023/08/18
- [PATCH v2 24/58] i386/tdx: Create kvm gmem for TD, Xiaoyao Li, 2023/08/18
- [PATCH v2 23/58] i386/tdx: Make memory type private by default, Xiaoyao Li, 2023/08/18
- [PATCH v2 29/58] i386/tdx: Skip BIOS shadowing setup, Xiaoyao Li, 2023/08/18
- [PATCH v2 30/58] i386/tdx: Don't initialize pc.rom for TDX VMs, Xiaoyao Li, 2023/08/18
- [PATCH v2 31/58] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2023/08/18
- [PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2023/08/18
- [PATCH v2 33/58] headers: Add definitions from UEFI spec for volumes, resources, etc..., Xiaoyao Li, 2023/08/18
- [PATCH v2 34/58] i386/tdx: Setup the TD HOB list, Xiaoyao Li, 2023/08/18
- [PATCH v2 37/58] i386/tdx: register TDVF as private memory, Xiaoyao Li, 2023/08/18
- [PATCH v2 47/58] i386/tdx: Wire REPORT_FATAL_ERROR with GuestPanic facility, Xiaoyao Li, 2023/08/18