Re: [PATCH v6 34/60] i386/tdx: implement tdx_cpu_realizefn()

Paolo Bonzini
2024-11-05T10:06:34Z

On 11/5/24 07:23, Xiaoyao Li wrote:
> +static void tdx_cpu_realizefn(X86ConfidentialGuest *cg, CPUState *cs,
> + Error **errp)
> +{
> + X86CPU *cpu = X86_CPU(cs);
> + uint32_t host_phys_bits = host_cpu_phys_bits();
> +
> + if (!cpu->phys_bits) {
> + cpu->phys_bits = host_phys_bits;
> + } else if (cpu->phys_bits != host_phys_bits) {
> + error_setg(errp, "TDX only supports host physical bits (%u)",
> + host_phys_bits);
> + }
> +}

This should be already handled by host_cpu_realizefn(), which is reached
via cpu_exec_realizefn().

Why is it needed earlier, but not as early as instance_init? If
absolutely needed I would do the assignment in patch 33, but I don't
understand why it's necessary.

Either way, the check should be in tdx_check_features.

Paolo

> static int tdx_validate_attributes(TdxGuest *tdx, Error **errp)
> {
> if ((tdx->attributes & ~tdx_caps->supported_attrs)) {
> @@ -733,4 +749,5 @@ static void tdx_guest_class_init(ObjectClass *oc, void *data)
> klass->kvm_init = tdx_kvm_init;
> x86_klass->kvm_type = tdx_kvm_type;
> x86_klass->cpu_instance_init = tdx_cpu_instance_init;
> + x86_klass->cpu_realizefn = tdx_cpu_realizefn;
> }