target/i386: SEV: do not assume machine->cgs is SEV
PATCH 1/1 target/i386: SEV: do not assume machine->cgs is SEV
There can be other confidential computing classes that are not derived from sev-common. Avoid aborting when encountering them.
--- target/i386/sev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target/i386/sev.c +3 -1
@@ -1710,7 +1710,9 @@ void sev_es_set_reset_vector(CPUState *cpu) {X86CPU *x86;CPUX86State *env; -SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); +ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; +SevCommonState *sev_common =SEV_COMMON ( +object_dynamic_cast (OBJECT (cgs),TYPE_SEV_COMMON ));/* Only update if we have valid reset information */ if (!sev_common || !sev_common->reset_data_valid) {
Signature · 1 line
2.45.1
Quoted 18 lines · Paolo Bonzini
Date: Thu, 6 Jun 2024 00:44:09 +0200
From: Paolo Bonzini <[email protected]>
Subject: [PATCH] target/i386: SEV: do not assumemachine->cgsis SEV
X-Mailer: git-send-email 2.45.1There can be other confidential computing classes that are not derived from sev-common. Avoid aborting when encountering them.
Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/sev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)target/i386/sev.c +0
-0
target/i386/sev.c void sev_es_set_reset_vector(CPUState *cpu) · line 1715
Quoted 7 lines
target/i386/sev.c +3
-1@@ -1710,7 +1710,9 @@ void sev_es_set_reset_vector(CPUState *cpu) {X86CPU *x86;CPUX86State *env; -SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); +ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; +SevCommonState *sev_common =SEV_COMMON ( +object_dynamic_cast (OBJECT (cgs),TYPE_SEV_COMMON ));
SEV_COMMON(object_dynamic_cast()) looks to be twice cast, we can just force to do conversion with pointer type:
(SevCommonState *) object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON)
Quoted 6 lines
target/i386/sev.c +0
-0/* Only update if we have valid reset information */ if (!sev_common || !sev_common->reset_data_valid) {Signature · 1 line
2.45.1
Quoted 12 lines · Zhao Liu
target/i386/sev.c void sev_es_set_reset_vector(CPUState *cpu) · line 1715
Quoted 8 lines
target/i386/sev.c +3
-1@@ -1710,7 +1710,9 @@ void sev_es_set_reset_vector(CPUState *cpu) {X86CPU *x86;CPUX86State *env; -SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); +ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; +SevCommonState *sev_common =SEV_COMMON ( +object_dynamic_cast (OBJECT (cgs),TYPE_SEV_COMMON ));SEV_COMMON(object_dynamic_cast()) looks to be twice cast, we can just force to do conversion with pointer type:
Quoted 1 line
(SevCommonState *)
object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON)
You don't need the explicit cast either, since C auto-converts from void*.
sev_common = object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON);
r~
Il gio 6 giu 2024, 05:52 Richard Henderson <[email protected]> ha scritto:
Quoted 9 lines
Quoted 4 lines
SEV_COMMON(object_dynamic_cast()) looks to be twice cast, we can just force to do conversion with pointer type:
(SevCommonState *)
object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON)You don't need the explicit cast either, since C auto-converts from void*.
sev_common = object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON);
Doh, of course. Thanks to both!
Paolo
Quoted 4 lines
r~
Quoted 2 lines · Paolo Bonzini
There can be other confidential computing classes that are not derived from sev-common. Avoid aborting when encountering them.
I hit it today when rebasing TDX patches to latest QEMU master, which has the SEV-SNP series merged. (I didn't get time to review it between it gets merged.)
target/i386/sev.c void sev_es_set_reset_vector(CPUState *cpu)
Quoted 10 lines
Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/sev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)target/i386/sev.c +0
-0@@ -1710,7 +1710,9 @@ void sev_es_set_reset_vector(CPUState *cpu)
my approach is to guard with sev_enabled() when calling sev_es_set_reset_vector() in kvm_arch_reset_vcpu(), because calling sev* specific function in generic kvm code doesn't look reasonable to me.
Quoted 10 lines
target/i386/sev.c +3
-1{X86CPU *x86;CPUX86State *env; -SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); +ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; +SevCommonState *sev_common =SEV_COMMON ( +object_dynamic_cast (OBJECT (cgs),TYPE_SEV_COMMON ));/* Only update if we have valid reset information */ if (!sev_common || !sev_common->reset_data_valid) {
Quoted 5 lines · Xiaoyao Li
Quoted 2 lines · Paolo Bonzini
There can be other confidential computing classes that are not derived from sev-common. Avoid aborting when encountering them.
Quoted 7 lines
I hit it today when rebasing TDX patches to latest QEMU master, which has the SEV-SNP series merged. (I didn't get time to review it between it gets merged.)
my approach is to guard with
sev_enabled()when callingsev_es_set_reset_vector()inkvm_arch_reset_vcpu(), because calling sev* specific function in generic kvm code doesn't look reasonable to me.
On the other hand I would like to avoid too many sev/tdx conditionals in common code. Neither choice is great.
Another possibility is to make this a X86ConfidentialGuest method, if the TDX code has anything similar.
Feel free to keep this patch, or anything that replaces it, in your TDX series.
Apart from this issue, I could rebase the previous TDX patches on top of SEV-SNP without any problems.
Paolo