qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Igor Mammedov" <imammedo@redhat.com>
Cc: Zhao Liu <zhao1.liu@intel.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Huacai Chen <chenhuacai@kernel.org>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	Francesco Lavra <francescolavra.fl@gmail.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [PATCH v7 12/52] i386/tdx: Validate TD attributes
Date: Wed, 5 Feb 2025 18:31:15 +0800	[thread overview]
Message-ID: <ebedb603-ee42-4db6-86b9-edb270970935@intel.com> (raw)
In-Reply-To: <20250124132048.3229049-13-xiaoyao.li@intel.com>

On 1/24/2025 9:20 PM, Xiaoyao Li wrote:
> Validate TD attributes with tdx_caps that only supported bits arer
> allowed by KVM.
> 
> Besides, sanity check the attribute bits that have not been supported by
> QEMU yet. e.g., debug bit, it will be allowed in the future when debug
> TD support lands in QEMU.

This patches got squashed with next one "i386/tdx: Support user 
configurable mrconfigid/mrowner/mrownerconfig" in v6 by accident.

I'll fix it in the next version.

> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> Changes in v7:
> - Define TDX_SUPPORTED_TD_ATTRS as QEMU supported mask, to validates
>    user's request. (Rick)
> 
> Changes in v3:
> - using error_setg() for error report; (Daniel)
> ---
>   qapi/qom.json         |  16 +++++-
>   target/i386/kvm/tdx.c | 118 +++++++++++++++++++++++++++++++++++++++++-
>   target/i386/kvm/tdx.h |   3 ++
>   3 files changed, 134 insertions(+), 3 deletions(-)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 8740626c4ee6..a53000ca6fb4 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -1060,11 +1060,25 @@
>   #     pages.  Some guest OS (e.g., Linux TD guest) may require this to
>   #     be set, otherwise they refuse to boot.
>   #
> +# @mrconfigid: ID for non-owner-defined configuration of the guest TD,
> +#     e.g., run-time or OS configuration (base64 encoded SHA384 digest).
> +#     Defaults to all zeros.
> +#
> +# @mrowner: ID for the guest TD’s owner (base64 encoded SHA384 digest).
> +#     Defaults to all zeros.
> +#
> +# @mrownerconfig: ID for owner-defined configuration of the guest TD,
> +#     e.g., specific to the workload rather than the run-time or OS
> +#     (base64 encoded SHA384 digest).  Defaults to all zeros.
> +#
>   # Since: 10.0
>   ##
>   { 'struct': 'TdxGuestProperties',
>     'data': { '*attributes': 'uint64',
> -            '*sept-ve-disable': 'bool' } }
> +            '*sept-ve-disable': 'bool',
> +            '*mrconfigid': 'str',
> +            '*mrowner': 'str',
> +            '*mrownerconfig': 'str' } }
>   
>   ##
>   # @ThreadContextProperties:
> diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
> index 653942d83bcb..ed843af1d0b6 100644
> --- a/target/i386/kvm/tdx.c
> +++ b/target/i386/kvm/tdx.c
> @@ -11,17 +11,24 @@
>   
>   #include "qemu/osdep.h"
>   #include "qemu/error-report.h"
> +#include "qemu/base64.h"
>   #include "qapi/error.h"
>   #include "qom/object_interfaces.h"
> +#include "crypto/hash.h"
>   
>   #include "hw/i386/x86.h"
>   #include "kvm_i386.h"
>   #include "tdx.h"
>   
> +#define TDX_TD_ATTRIBUTES_DEBUG             BIT_ULL(0)
>   #define TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE   BIT_ULL(28)
>   #define TDX_TD_ATTRIBUTES_PKS               BIT_ULL(30)
>   #define TDX_TD_ATTRIBUTES_PERFMON           BIT_ULL(63)
>   
> +#define TDX_SUPPORTED_TD_ATTRS  (TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE |\
> +                                 TDX_TD_ATTRIBUTES_PKS | \
> +                                 TDX_TD_ATTRIBUTES_PERFMON)
> +
>   static TdxGuest *tdx_guest;
>   
>   static struct kvm_tdx_capabilities *tdx_caps;
> @@ -153,13 +160,33 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg)
>       return KVM_X86_TDX_VM;
>   }
>   
> -static void setup_td_guest_attributes(X86CPU *x86cpu)
> +static int tdx_validate_attributes(TdxGuest *tdx, Error **errp)
> +{
> +    if ((tdx->attributes & ~tdx_caps->supported_attrs)) {
> +        error_setg(errp, "Invalid attributes 0x%lx for TDX VM "
> +                   "(KVM supported: 0x%llx)", tdx->attributes,
> +                   tdx_caps->supported_attrs);
> +        return -1;
> +    }
> +
> +    if (tdx->attributes & ~TDX_SUPPORTED_TD_ATTRS) {
> +        warn_report("Some QEMU unsupported TD attribute bits being requested:"
> +                    "requested: 0x%lx QEMU supported: 0x%llx",
> +                    tdx->attributes, TDX_SUPPORTED_TD_ATTRS);
> +    }
> +
> +    return 0;
> +}
> +
> +static int setup_td_guest_attributes(X86CPU *x86cpu, Error **errp)
>   {
>       CPUX86State *env = &x86cpu->env;
>   
>       tdx_guest->attributes |= (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_PKS) ?
>                                TDX_TD_ATTRIBUTES_PKS : 0;
>       tdx_guest->attributes |= x86cpu->enable_pmu ? TDX_TD_ATTRIBUTES_PERFMON : 0;
> +
> +    return tdx_validate_attributes(tdx_guest, errp);
>   }
>   
>   static int setup_td_xfam(X86CPU *x86cpu, Error **errp)
> @@ -214,6 +241,7 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
>       CPUX86State *env = &x86cpu->env;
>       g_autofree struct kvm_tdx_init_vm *init_vm = NULL;
>       Error *local_err = NULL;
> +    size_t data_len;
>       int retry = 10000;
>       int r = 0;
>   
> @@ -225,7 +253,40 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
>       init_vm = g_malloc0(sizeof(struct kvm_tdx_init_vm) +
>                           sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_ENTRIES);
>   
> -    setup_td_guest_attributes(x86cpu);
> +    if (tdx_guest->mrconfigid) {
> +        g_autofree uint8_t *data = qbase64_decode(tdx_guest->mrconfigid,
> +                              strlen(tdx_guest->mrconfigid), &data_len, errp);
> +        if (!data || data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
> +            error_setg(errp, "TDX: failed to decode mrconfigid");
> +            return -1;
> +        }
> +        memcpy(init_vm->mrconfigid, data, data_len);
> +    }
> +
> +    if (tdx_guest->mrowner) {
> +        g_autofree uint8_t *data = qbase64_decode(tdx_guest->mrowner,
> +                              strlen(tdx_guest->mrowner), &data_len, errp);
> +        if (!data || data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
> +            error_setg(errp, "TDX: failed to decode mrowner");
> +            return -1;
> +        }
> +        memcpy(init_vm->mrowner, data, data_len);
> +    }
> +
> +    if (tdx_guest->mrownerconfig) {
> +        g_autofree uint8_t *data = qbase64_decode(tdx_guest->mrownerconfig,
> +                            strlen(tdx_guest->mrownerconfig), &data_len, errp);
> +        if (!data || data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
> +            error_setg(errp, "TDX: failed to decode mrownerconfig");
> +            return -1;
> +        }
> +        memcpy(init_vm->mrownerconfig, data, data_len);
> +    }
> +
> +    r = setup_td_guest_attributes(x86cpu, errp);
> +    if (r) {
> +        return r;
> +    }
>   
>       r = setup_td_xfam(x86cpu, errp);
>       if (r) {
> @@ -283,6 +344,51 @@ static void tdx_guest_set_sept_ve_disable(Object *obj, bool value, Error **errp)
>       }
>   }
>   
> +static char *tdx_guest_get_mrconfigid(Object *obj, Error **errp)
> +{
> +    TdxGuest *tdx = TDX_GUEST(obj);
> +
> +    return g_strdup(tdx->mrconfigid);
> +}
> +
> +static void tdx_guest_set_mrconfigid(Object *obj, const char *value, Error **errp)
> +{
> +    TdxGuest *tdx = TDX_GUEST(obj);
> +
> +    g_free(tdx->mrconfigid);
> +    tdx->mrconfigid = g_strdup(value);
> +}
> +
> +static char *tdx_guest_get_mrowner(Object *obj, Error **errp)
> +{
> +    TdxGuest *tdx = TDX_GUEST(obj);
> +
> +    return g_strdup(tdx->mrowner);
> +}
> +
> +static void tdx_guest_set_mrowner(Object *obj, const char *value, Error **errp)
> +{
> +    TdxGuest *tdx = TDX_GUEST(obj);
> +
> +    g_free(tdx->mrowner);
> +    tdx->mrowner = g_strdup(value);
> +}
> +
> +static char *tdx_guest_get_mrownerconfig(Object *obj, Error **errp)
> +{
> +    TdxGuest *tdx = TDX_GUEST(obj);
> +
> +    return g_strdup(tdx->mrownerconfig);
> +}
> +
> +static void tdx_guest_set_mrownerconfig(Object *obj, const char *value, Error **errp)
> +{
> +    TdxGuest *tdx = TDX_GUEST(obj);
> +
> +    g_free(tdx->mrownerconfig);
> +    tdx->mrownerconfig = g_strdup(value);
> +}
> +
>   /* tdx guest */
>   OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest,
>                                      tdx_guest,
> @@ -306,6 +412,14 @@ static void tdx_guest_init(Object *obj)
>       object_property_add_bool(obj, "sept-ve-disable",
>                                tdx_guest_get_sept_ve_disable,
>                                tdx_guest_set_sept_ve_disable);
> +    object_property_add_str(obj, "mrconfigid",
> +                            tdx_guest_get_mrconfigid,
> +                            tdx_guest_set_mrconfigid);
> +    object_property_add_str(obj, "mrowner",
> +                            tdx_guest_get_mrowner, tdx_guest_set_mrowner);
> +    object_property_add_str(obj, "mrownerconfig",
> +                            tdx_guest_get_mrownerconfig,
> +                            tdx_guest_set_mrownerconfig);
>   }
>   
>   static void tdx_guest_finalize(Object *obj)
> diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h
> index 4e2b5c61ff5b..e472b11fb0dd 100644
> --- a/target/i386/kvm/tdx.h
> +++ b/target/i386/kvm/tdx.h
> @@ -24,6 +24,9 @@ typedef struct TdxGuest {
>       bool initialized;
>       uint64_t attributes;    /* TD attributes */
>       uint64_t xfam;
> +    char *mrconfigid;       /* base64 encoded sha348 digest */
> +    char *mrowner;          /* base64 encoded sha348 digest */
> +    char *mrownerconfig;    /* base64 encoded sha348 digest */
>   } TdxGuest;
>   
>   #ifdef CONFIG_TDX



  parent reply	other threads:[~2025-02-05 10:31 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-24 13:19 [PATCH v7 00/52] QEMU TDX support Xiaoyao Li
2025-01-24 13:19 ` [PATCH v7 01/52] *** HACK *** linux-headers: Update headers to pull in TDX API changes Xiaoyao Li
2025-01-24 13:19 ` [PATCH v7 02/52] i386: Introduce tdx-guest object Xiaoyao Li
2025-01-24 13:19 ` [PATCH v7 03/52] i386/tdx: Implement tdx_kvm_type() for TDX Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 04/52] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 05/52] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES Xiaoyao Li
2025-02-18 19:21   ` Francesco Lavra
2025-02-25  8:59     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 06/52] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 07/52] kvm: Introduce kvm_arch_pre_create_vcpu() Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 08/52] i386/tdx: Initialize TDX before creating TD vcpus Xiaoyao Li
2025-02-19 10:14   ` Francesco Lavra
2025-02-25  9:55     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 09/52] i386/tdx: Add property sept-ve-disable for tdx-guest object Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 10/52] i386/tdx: Make sept_ve_disable set by default Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 11/52] i386/tdx: Wire CPU features up with attributes of TD guest Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 12/52] i386/tdx: Validate TD attributes Xiaoyao Li
2025-02-05  9:06   ` Markus Armbruster
2025-02-05 10:29     ` Xiaoyao Li
2025-02-05 10:31   ` Xiaoyao Li [this message]
2025-01-24 13:20 ` [PATCH v7 13/52] i386/tdx: Set APIC bus rate to match with what TDX module enforces Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 14/52] i386/tdx: Implement user specified tsc frequency Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 15/52] i386/tdx: load TDVF for TD guest Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 16/52] i386/tdvf: Introduce function to parse TDVF metadata Xiaoyao Li
2025-02-19 10:58   ` Francesco Lavra
2025-02-25 11:59     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 17/52] i386/tdx: Parse TDVF metadata for TDX VM Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 18/52] i386/tdx: Don't initialize pc.rom for TDX VMs Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 19/52] i386/tdx: Track mem_ptr for each firmware entry of TDVF Xiaoyao Li
2025-02-19 11:26   ` Francesco Lavra
2025-02-26  9:07     ` Xiaoyao Li
2025-02-19 18:40   ` Francesco Lavra
2025-02-26  9:08     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 20/52] i386/tdx: Track RAM entries for TDX VM Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 21/52] headers: Add definitions from UEFI spec for volumes, resources, etc Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 22/52] i386/tdx: Setup the TD HOB list Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 23/52] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 24/52] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 25/52] i386/tdx: Finalize TDX VM Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 26/52] i386/tdx: Enable user exit on KVM_HC_MAP_GPA_RANGE Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 27/52] i386/tdx: Handle KVM_SYSTEM_EVENT_TDX_FATAL Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 28/52] i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility Xiaoyao Li
2025-02-05  9:19   ` Markus Armbruster
2025-02-05 10:19     ` Xiaoyao Li
2025-02-27 16:30   ` Francesco Lavra
2025-03-03  2:36     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 29/52] i386/cpu: introduce x86_confidential_guest_cpu_instance_init() Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 30/52] i386/tdx: implement tdx_cpu_instance_init() Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 31/52] i386/cpu: Introduce enable_cpuid_0x1f to force exposing CPUID 0x1f Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 32/52] i386/tdx: Force " Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 33/52] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 34/52] i386/tdx: Disable SMM for TDX VMs Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 35/52] i386/tdx: Disable PIC " Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 36/52] i386/tdx: Don't synchronize guest tsc for TDs Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 37/52] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() " Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 38/52] i386/apic: Skip kvm_apic_put() for TDX Xiaoyao Li
2025-02-27 16:57   ` Francesco Lavra
2025-03-03  2:42     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 39/52] cpu: Don't set vcpu_dirty when guest_state_protected Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 40/52] i386/cgs: Rename *mask_cpuid_features() to *adjust_cpuid_features() Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 41/52] i386/tdx: Implement adjust_cpuid_features() for TDX Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 42/52] i386/tdx: Apply TDX fixed0 and fixed1 information to supported CPUIDs Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 43/52] i386/tdx: Mask off CPUID bits by unsupported TD Attributes Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 44/52] i386/cpu: Move CPUID_XSTATE_XSS_MASK to header file and introduce CPUID_XSTATE_MASK Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 45/52] i386/tdx: Mask off CPUID bits by unsupported XFAM Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 46/52] i386/tdx: Mark the configurable bit not reported by KVM as unsupported Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 47/52] i386/cgs: Introduce x86_confidential_guest_check_features() Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 48/52] i386/tdx: Fetch and validate CPUID of TD guest Xiaoyao Li
2025-02-05  9:28   ` Markus Armbruster
2025-02-05 10:29     ` Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 49/52] i386/tdx: Don't treat SYSCALL as unavailable Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 50/52] i386/tdx: Make invtsc default on Xiaoyao Li
2025-01-24 13:20 ` [PATCH v7 51/52] i386/tdx: Validate phys_bits against host value Xiaoyao Li
2025-01-31 18:27   ` Paolo Bonzini
2025-02-02 14:39     ` Xiaoyao Li
2025-02-03 18:15       ` Paolo Bonzini
2025-01-24 13:20 ` [PATCH v7 52/52] docs: Add TDX documentation Xiaoyao Li
2025-03-25 18:46   ` Daniel P. Berrangé
2025-03-26  3:36     ` Xiaoyao Li
2025-03-26  6:48       ` Xiaoyao Li
2025-03-26  9:22       ` Daniel P. Berrangé

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-all 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=ebedb603-ee42-4db6-86b9-edb270970935@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=chenhuacai@kernel.org \
    --cc=eblake@redhat.com \
    --cc=francescolavra.fl@gmail.com \
    --cc=imammedo@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=zhao1.liu@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).