* [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
@ 2024-06-05 22:44 Paolo Bonzini
2024-06-06 3:45 ` Zhao Liu
2024-06-06 16:06 ` Xiaoyao Li
0 siblings, 2 replies; 6+ messages in thread
From: Paolo Bonzini @ 2024-06-05 22:44 UTC (permalink / raw)
To: qemu-devel; +Cc: pankaj.gupta
There can be other confidential computing classes that are not derived
from sev-common. Avoid aborting when encountering them.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/sev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 004c667ac14..97e15f8b7a9 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -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) {
--
2.45.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
2024-06-05 22:44 [PATCH] target/i386: SEV: do not assume machine->cgs is SEV Paolo Bonzini
@ 2024-06-06 3:45 ` Zhao Liu
2024-06-06 3:52 ` Richard Henderson
2024-06-06 16:06 ` Xiaoyao Li
1 sibling, 1 reply; 6+ messages in thread
From: Zhao Liu @ 2024-06-06 3:45 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, pankaj.gupta
On Thu, Jun 06, 2024 at 12:44:09AM +0200, Paolo Bonzini wrote:
> Date: Thu, 6 Jun 2024 00:44:09 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
> X-Mailer: git-send-email 2.45.1
>
> There can be other confidential computing classes that are not derived
> from sev-common. Avoid aborting when encountering them.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target/i386/sev.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 004c667ac14..97e15f8b7a9 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -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)
> /* Only update if we have valid reset information */
> if (!sev_common || !sev_common->reset_data_valid) {
> --
> 2.45.1
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
2024-06-06 3:45 ` Zhao Liu
@ 2024-06-06 3:52 ` Richard Henderson
2024-06-06 6:32 ` Paolo Bonzini
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2024-06-06 3:52 UTC (permalink / raw)
To: Zhao Liu, Paolo Bonzini; +Cc: qemu-devel, pankaj.gupta
On 6/5/24 20:45, Zhao Liu wrote:
>> @@ -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)
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~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
2024-06-06 3:52 ` Richard Henderson
@ 2024-06-06 6:32 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2024-06-06 6:32 UTC (permalink / raw)
To: Richard Henderson; +Cc: Zhao Liu, qemu-devel, Pankaj Gupta
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
Il gio 6 giu 2024, 05:52 Richard Henderson <richard.henderson@linaro.org>
ha scritto:
> > 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
>
> r~
>
>
[-- Attachment #2: Type: text/html, Size: 1154 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
2024-06-05 22:44 [PATCH] target/i386: SEV: do not assume machine->cgs is SEV Paolo Bonzini
2024-06-06 3:45 ` Zhao Liu
@ 2024-06-06 16:06 ` Xiaoyao Li
2024-06-06 16:10 ` Paolo Bonzini
1 sibling, 1 reply; 6+ messages in thread
From: Xiaoyao Li @ 2024-06-06 16:06 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: pankaj.gupta
On 6/6/2024 6:44 AM, Paolo Bonzini wrote:
> 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.)
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target/i386/sev.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 004c667ac14..97e15f8b7a9 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -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.
> {
> 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) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] target/i386: SEV: do not assume machine->cgs is SEV
2024-06-06 16:06 ` Xiaoyao Li
@ 2024-06-06 16:10 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2024-06-06 16:10 UTC (permalink / raw)
To: Xiaoyao Li; +Cc: qemu-devel, pankaj.gupta
On Thu, Jun 6, 2024 at 6:07 PM Xiaoyao Li <xiaoyao.li@intel.com> wrote:
>
> On 6/6/2024 6:44 AM, Paolo Bonzini wrote:
> > 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.)
>
> 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.
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-06 16:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-05 22:44 [PATCH] target/i386: SEV: do not assume machine->cgs is SEV Paolo Bonzini
2024-06-06 3:45 ` Zhao Liu
2024-06-06 3:52 ` Richard Henderson
2024-06-06 6:32 ` Paolo Bonzini
2024-06-06 16:06 ` Xiaoyao Li
2024-06-06 16:10 ` Paolo Bonzini
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).