From: Chao Peng <[email protected]>
Override kvm_arch_has_private_mem() to use fd-based private memory.
Return true when a VM has a type of KVM_X86_TDX_VM.
Signed-off-by: Chao Peng <[email protected]>
Signed-off-by: Isaku Yamahata <[email protected]>
---
arch/x86/kvm/x86.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d548d3af6428..a8b555935fd8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -13498,6 +13498,11 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
}
EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);
+bool kvm_arch_has_private_mem(struct kvm *kvm)
+{
+ return kvm->arch.vm_type == KVM_X86_TDX_VM;
+}
+
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_entry);
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit);
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio);
--
2.25.1
On Thu, 2023-01-12 at 08:31 -0800, [email protected] wrote:
> From: Chao Peng <[email protected]>
>
> Override kvm_arch_has_private_mem() to use fd-based private memory.
> Return true when a VM has a type of KVM_X86_TDX_VM.
>
> Signed-off-by: Chao Peng <[email protected]>
> Signed-off-by: Isaku Yamahata <[email protected]>
> ---
> arch/x86/kvm/x86.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d548d3af6428..a8b555935fd8 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -13498,6 +13498,11 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
> }
> EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);
>
> +bool kvm_arch_has_private_mem(struct kvm *kvm)
> +{
> + return kvm->arch.vm_type == KVM_X86_TDX_VM;
> +}
> +
AMD's series has a different solution:
https://lore.kernel.org/lkml/[email protected]/
I think somehow this needs to get aligned.
Simply checking whether VM is TD certainly won't work for AMD, so my first
glance we should use something similar to AMD's solution. But I haven't
thought thoroughly that is absolutely needed, for instance, perhaps we can use
'gfn_shared_mask', etc.
On Mon, Jan 16, 2023, Huang, Kai wrote:
> On Thu, 2023-01-12 at 08:31 -0800, [email protected] wrote:
> > From: Chao Peng <[email protected]>
> >
> > Override kvm_arch_has_private_mem() to use fd-based private memory.
> > Return true when a VM has a type of KVM_X86_TDX_VM.
> >
> > Signed-off-by: Chao Peng <[email protected]>
> > Signed-off-by: Isaku Yamahata <[email protected]>
> > ---
> > arch/x86/kvm/x86.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index d548d3af6428..a8b555935fd8 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -13498,6 +13498,11 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
> > }
> > EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);
> >
> > +bool kvm_arch_has_private_mem(struct kvm *kvm)
> > +{
> > + return kvm->arch.vm_type == KVM_X86_TDX_VM;
> > +}
> > +
>
> AMD's series has a different solution:
>
> https://lore.kernel.org/lkml/[email protected]/
>
> I think somehow this needs to get aligned.
Ya. My thought is
bool kvm_arch_has_private_mem(struct kvm *kvm)
{
return kvm->arch.vm_type != KVM_X86_DEFAULT_VM;
}
where the VM types end up being:
#define KVM_X86_DEFAULT_VM 0
#define KVM_X86_PROTECTED_VM 1
#define KVM_X86_TDX_VM 2
#define KVM_X86_SNP_VM 3
Don't spend too much time reworking the TDX series at this point, I'm going to do
a trial run of combining UPM+TDX+SNP sometime in the next few weeks to see how all
the pieces fit together, this is one of the common touchpoints that I'll make sure
to look at. Though if you have ideas on, by all means post them.
On Tue, 2023-01-17 at 16:40 +0000, Sean Christopherson wrote:
> On Mon, Jan 16, 2023, Huang, Kai wrote:
> > On Thu, 2023-01-12 at 08:31 -0800, [email protected] wrote:
> > > From: Chao Peng <[email protected]>
> > >
> > > Override kvm_arch_has_private_mem() to use fd-based private memory.
> > > Return true when a VM has a type of KVM_X86_TDX_VM.
> > >
> > > Signed-off-by: Chao Peng <[email protected]>
> > > Signed-off-by: Isaku Yamahata <[email protected]>
> > > ---
> > > arch/x86/kvm/x86.c | 5 +++++
> > > 1 file changed, 5 insertions(+)
> > >
> > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > index d548d3af6428..a8b555935fd8 100644
> > > --- a/arch/x86/kvm/x86.c
> > > +++ b/arch/x86/kvm/x86.c
> > > @@ -13498,6 +13498,11 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
> > > }
> > > EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);
> > >
> > > +bool kvm_arch_has_private_mem(struct kvm *kvm)
> > > +{
> > > + return kvm->arch.vm_type == KVM_X86_TDX_VM;
> > > +}
> > > +
> >
> > AMD's series has a different solution:
> >
> > https://lore.kernel.org/lkml/[email protected]/
> >
> > I think somehow this needs to get aligned.
>
> Ya. My thought is
>
> bool kvm_arch_has_private_mem(struct kvm *kvm)
> {
> return kvm->arch.vm_type != KVM_X86_DEFAULT_VM;
> }
>
> where the VM types end up being:
>
> #define KVM_X86_DEFAULT_VM 0
> #define KVM_X86_PROTECTED_VM 1
> #define KVM_X86_TDX_VM 2
> #define KVM_X86_SNP_VM 3
What's the difference between PROTECTED_VM vs TDX_VM/SNP_VM, may I ask?
>
> Don't spend too much time reworking the TDX series at this point, I'm going to do
> a trial run of combining UPM+TDX+SNP sometime in the next few weeks to see how all
> the pieces fit together, this is one of the common touchpoints that I'll make sure
> to look at. Though if you have ideas on, by all means post them.
Glad to know. Thanks for your time.
On Tue, Jan 17, 2023, Huang, Kai wrote:
> On Tue, 2023-01-17 at 16:40 +0000, Sean Christopherson wrote:
> > On Mon, Jan 16, 2023, Huang, Kai wrote:
> > > AMD's series has a different solution:
> > >
> > > https://lore.kernel.org/lkml/[email protected]/
> > >
> > > I think somehow this needs to get aligned.
> >
> > Ya. My thought is
> >
> > bool kvm_arch_has_private_mem(struct kvm *kvm)
> > {
> > return kvm->arch.vm_type != KVM_X86_DEFAULT_VM;
> > }
> >
> > where the VM types end up being:
> >
> > #define KVM_X86_DEFAULT_VM 0
> > #define KVM_X86_PROTECTED_VM 1
> > #define KVM_X86_TDX_VM 2
> > #define KVM_X86_SNP_VM 3
>
> What's the difference between PROTECTED_VM vs TDX_VM/SNP_VM, may I ask?
Not sure :-)
At this point, PROTECTED_VM is a handwavy "guest that can access restricted memory".
I think/hope it can be used in combination with existing SEV/SEV-ES APIs to allow
backing such guests with restrictedmem.
As for TDX_VM and SNP_VM, I'm speculating that KVM will need to differentiate between
SNP, TDX, and everything else. E.g. if KVM needs to uniquely identify TDX VMs at
creation time, then adding dedicated VM types seems like the obvious choice. Ditto
for SNP VMs.
That's partly why I want to smush everything together, to see if we actually need
multiple VM types.