Skip to contentSkip to conversation

KVM: SVM: Cgroup support for SVM SEV ASIDs

RFC PATCH In review Vipin Sharma 12 participants 30 messages Sep 22, 2020 – Nov 27, 2020 1 message not in the archive

Subsystems (6)
Documentation x86 KVM s390 +2 more subsystems
lore
Share & tools
lore
#0 lore raw

cover KVM: SVM: Cgroup support for SVM SEV ASIDs

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

Patch 1 - Overview, motivation, and implementation details of the SEV
controller.
Patch 2 - Kernel documentation of the SEV controller for both
cgroup v1 and v2.

Thanks

Vipin Sharma (2):
KVM: SVM: Create SEV cgroup controller.
KVM: SVM: SEV cgroup controller documentation

 Documentation/admin-guide/cgroup-v1/sev.rst |  94 +++++
 Documentation/admin-guide/cgroup-v2.rst     |  56 ++-
 arch/x86/kvm/Makefile                       |   1 +
 arch/x86/kvm/svm/sev.c                      |  16 +-
 arch/x86/kvm/svm/sev_cgroup.c               | 414 ++++++++++++++++++++
 arch/x86/kvm/svm/sev_cgroup.h               |  40 ++
 include/linux/cgroup_subsys.h               |   3 +
 init/Kconfig                                |  14 +
 8 files changed, 634 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/admin-guide/cgroup-v1/sev.rst
 create mode 100644 arch/x86/kvm/svm/sev_cgroup.c
 create mode 100644 arch/x86/kvm/svm/sev_cgroup.h
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
#1 lore raw

RFC PATCH 1/2 KVM: SVM: Create SEV cgroup controller.

Create SEV cgroup controller for SEV ASIDs on the AMD platform.

SEV ASIDs are used to encrypt virtual machines memory and isolate the guests from the hypervisor. However, number of SEV ASIDs are limited on a platform. This leads to the resource constraints and cause issues like:

1. Some applications exhausting all of the SEV ASIDs and depriving others on a host.
2. No capability with the system admin to allocate and limit the number of SEV ASIDs used by tasks.
3. Difficult for the cloud service providers to optimally schedule VMs and sandboxes across its fleet without knowing the overall picture of SEV ASIDs usage.

SEV controller tracks the usage and provides capability to limit SEV ASIDs used by tasks.

Controller is enabled by CGROUP_SEV config option, it is dependent on KVM_AMD_SEV option in the config file.

SEV Controller has 3 interface files:

1. max - Sets the max limit of the SEV ASIDs in the cgroup.

2. current - Shows the current count of the SEV ASIDs in the cgroup.

3. events - Event file to show the SEV ASIDs allocation denied in the cgroup.

When kvm-amd module is installed it calls SEV controller API and informs how many SEV ASIDs are available on the platform. Controller use this value to allocate an array which stores ASID to cgroup mapping.

New SEV ASID allocation gets charged to the task's SEV cgroup. Migration of charge is not supported, so, a charged ASID remains charged to the same cgroup until that SEV ASID is freed. This feature is similar to the memory cgroup as it is a stateful resource

On deletion of an empty cgroup whose tasks have moved to some other cgroup but a SEV ASID is still charged to it, the SEV ASID gets mapped to the parent cgroup.

Mapping array tells which cgroup to uncharge, and update mapping when the cgroup is deleted. Mapping array is freed when kvm-amd module is unloaded.

---
 arch/x86/kvm/Makefile         |   1 +
 arch/x86/kvm/svm/sev.c        |  16 +-
 arch/x86/kvm/svm/sev_cgroup.c | 414 ++++++++++++++++++++++++++++++++++
 arch/x86/kvm/svm/sev_cgroup.h |  40 ++++
 include/linux/cgroup_subsys.h |   3 +
 init/Kconfig                  |  14 ++
 6 files changed, 487 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/kvm/svm/sev_cgroup.c
 create mode 100644 arch/x86/kvm/svm/sev_cgroup.h
arch/x86/kvm/Makefile +1 -0
index 4a3081e9f4b5..bbbf10fc1b50 100644
@@ -16,6 +16,7 @@ kvm-$(CONFIG_KVM_ASYNC_PF)	+= $(KVM)/async_pf.o
 kvm-y			+= x86.o emulate.o i8259.o irq.o lapic.o \
 			   i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \
 			   hyperv.o debugfs.o mmu/mmu.o mmu/page_track.o
+kvm-$(CONFIG_CGROUP_SEV)	+= svm/sev_cgroup.o
 
 kvm-intel-y		+= vmx/vmx.o vmx/vmenter.o vmx/pmu_intel.o vmx/vmcs12.o vmx/evmcs.o vmx/nested.o
 kvm-amd-y		+= svm/svm.o svm/vmenter.o svm/pmu.o svm/nested.o svm/avic.o svm/sev.o
arch/x86/kvm/svm/sev.c +15 -1
index 7bf7bf734979..2cc0bea21a76 100644
@@ -17,6 +17,7 @@
 
 #include "x86.h"
 #include "svm.h"
+#include "sev_cgroup.h"
 
 static int sev_flush_asids(void);
 static DECLARE_RWSEM(sev_deactivate_lock);
@@ -80,7 +81,7 @@ static bool __sev_recycle_asids(void)
 static int sev_asid_new(void)
 {
 	bool retry = true;
-	int pos;
+	int pos, ret;
 
 	mutex_lock(&sev_bitmap_lock);
 
@@ -98,6 +99,12 @@ static int sev_asid_new(void)
 		return -EBUSY;
 	}
 
+	ret = sev_asid_try_charge(pos);
+	if (ret) {
+		mutex_unlock(&sev_bitmap_lock);
+		return ret;
+	}
+
 	__set_bit(pos, sev_asid_bitmap);
 
 	mutex_unlock(&sev_bitmap_lock);
@@ -127,6 +134,8 @@ static void sev_asid_free(int asid)
 		sd->sev_vmcbs[pos] = NULL;
 	}
 
+	sev_asid_uncharge(pos);
+
 	mutex_unlock(&sev_bitmap_lock);
 }
 
@@ -1143,6 +1152,9 @@ int __init sev_hardware_setup(void)
 	if (!status)
 		return 1;
 
+	if (sev_cgroup_setup(max_sev_asid))
+		return 1;
+
 	/*
 	 * Check SEV platform status.
 	 *
@@ -1157,6 +1169,7 @@ int __init sev_hardware_setup(void)
 	pr_info("SEV supported\n");
 
 err:
+	sev_cgroup_teardown();
 	kfree(status);
 	return rc;
 }
@@ -1170,6 +1183,7 @@ void sev_hardware_teardown(void)
 	bitmap_free(sev_reclaim_asid_bitmap);
 
 	sev_flush_asids();
+	sev_cgroup_teardown();
 }
 
 void pre_sev_run(struct vcpu_svm *svm, int cpu)
arch/x86/kvm/svm/sev_cgroup.c new file +414 -0

414 lines not on this page · raw message

arch/x86/kvm/svm/sev_cgroup.h new file +40 -0
new file mode 100644
index 000000000000..d2d69870a005
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SEV cgroup interface for charging and uncharging the cgroup.
+ *
+ * Copyright 2020 Google LLC
+ * Author: Vipin Sharma <[email protected]>
+ */
+
+#ifndef _SEV_CGROUP_H_
+#define _SEV_CGROUP_H_
+
+#ifdef CONFIG_CGROUP_SEV
+
+int sev_asid_try_charge(int pos);
+void sev_asid_uncharge(int pos);
+int sev_cgroup_setup(unsigned int max);
+void sev_cgroup_teardown(void);
+
+#else /* CONFIG_CGROUP_SEV */
+
+static inline int sev_asid_try_charge(int pos)
+{
+	return 0;
+}
+
+static inline void sev_asid_uncharge(int pos)
+{
+}
+
+static inline int sev_cgroup_setup(unsigned int max)
+{
+	return 0;
+}
+
+static inline void sev_cgroup_teardown(void)
+{
+}
+#endif /* CONFIG_CGROUP_SEV */
+
+#endif /* _SEV_CGROUP_H_ */
include/linux/cgroup_subsys.h +3 -0
index acb77dcff3b4..d21a5b4a2037 100644
@@ -61,6 +61,9 @@ SUBSYS(pids)
 SUBSYS(rdma)
 #endif
 
+#if IS_ENABLED(CONFIG_CGROUP_SEV)
+SUBSYS(sev)
+#endif
 /*
  * The following subsystems are not supported on the default hierarchy.
  */
init/Kconfig +14 -0
index d6a0b31b13dc..1a57c362b803 100644
@@ -1101,6 +1101,20 @@ config CGROUP_BPF
 	  BPF_CGROUP_INET_INGRESS will be executed on the ingress path of
 	  inet sockets.
 
+config CGROUP_SEV
+	bool "SEV ASID controller"
+	depends on KVM_AMD_SEV
+	default n
+	help
+	  Provides a controller for AMD SEV ASIDs. This controller limits and
+	  shows the total usage of SEV ASIDs used in encrypted VMs on AMD
+	  processors. Whenever a new encrypted VM is created using SEV on an
+	  AMD processor, this controller will check the current limit in the
+	  cgroup to which the task belongs and will deny the SEV ASID if the
+	  cgroup has already reached its limit.
+
+	  Say N if unsure.
+
 config CGROUP_DEBUG
 	bool "Debug controller"
 	default n
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
reviewer
#2 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

Hi,

Quoted 11 lines · Vipin Sharma
init/Kconfig +3 -0
index d6a0b31b13dc..1a57c362b803 100644
@@ -1101,6 +1101,20 @@ config CGROUP_BPF
 	  BPF_CGROUP_INET_INGRESS will be executed on the ingress path of
 	  inet sockets.
 
+config CGROUP_SEV
+	bool "SEV ASID controller"
+	depends on KVM_AMD_SEV

init/Kconfig config CGROUP_BPF · line 1116

Quoted 10 lines
init/Kconfig +10 -0
+	default n
+	help
+	  Provides a controller for AMD SEV ASIDs. This controller limits and
+	  shows the total usage of SEV ASIDs used in encrypted VMs on AMD
+	  processors. Whenever a new encrypted VM is created using SEV on an
+	  AMD processor, this controller will check the current limit in the
+	  cgroup to which the task belongs and will deny the SEV ASID if the
+	  cgroup has already reached its limit.
+
+	  Say N if unsure.

Something here (either in the bool prompt string or the help text) should let a reader know w.t.h. SEV means.

Without having to look in other places...

thanks.

Signature · 1 line
~Randy
#3 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

Quoted 28 lines · Randy Dunlap

Hi,

Quoted 11 lines · Vipin Sharma
init/Kconfig +3 -0
index d6a0b31b13dc..1a57c362b803 100644
@@ -1101,6 +1101,20 @@ config CGROUP_BPF
 	  BPF_CGROUP_INET_INGRESS will be executed on the ingress path of
 	  inet sockets.
 
+config CGROUP_SEV
+	bool "SEV ASID controller"
+	depends on KVM_AMD_SEV

init/Kconfig config CGROUP_BPF · line 1116

Quoted 10 lines
init/Kconfig +10 -0
+	default n
+	help
+	  Provides a controller for AMD SEV ASIDs. This controller limits and
+	  shows the total usage of SEV ASIDs used in encrypted VMs on AMD
+	  processors. Whenever a new encrypted VM is created using SEV on an
+	  AMD processor, this controller will check the current limit in the
+	  cgroup to which the task belongs and will deny the SEV ASID if the
+	  cgroup has already reached its limit.
+
+	  Say N if unsure.

Something here (either in the bool prompt string or the help text) should let a reader know w.t.h. SEV means.

Quoted 1 line

Without having to look in other places...

ASIDs too. I'd also love to see more info in the docs and/or cover letter to explain why ASID management on SEV requires a cgroup. I know what an ASID is, and have a decent idea of how KVM manages ASIDs for legacy VMs, but I know nothing about why ASIDs are limited for SEV and not legacy VMs.

#4 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

Quoted 29 lines · Sean Christopherson
Quoted 28 lines · Randy Dunlap

Hi,

Quoted 11 lines · Vipin Sharma
init/Kconfig +3 -0
index d6a0b31b13dc..1a57c362b803 100644
@@ -1101,6 +1101,20 @@ config CGROUP_BPF
 	  BPF_CGROUP_INET_INGRESS will be executed on the ingress path of
 	  inet sockets.
 
+config CGROUP_SEV
+	bool "SEV ASID controller"
+	depends on KVM_AMD_SEV

init/Kconfig config CGROUP_BPF · line 1116

Quoted 10 lines
init/Kconfig +10 -0
+	default n
+	help
+	  Provides a controller for AMD SEV ASIDs. This controller limits and
+	  shows the total usage of SEV ASIDs used in encrypted VMs on AMD
+	  processors. Whenever a new encrypted VM is created using SEV on an
+	  AMD processor, this controller will check the current limit in the
+	  cgroup to which the task belongs and will deny the SEV ASID if the
+	  cgroup has already reached its limit.
+
+	  Say N if unsure.

Something here (either in the bool prompt string or the help text) should let a reader know w.t.h. SEV means.

Quoted 6 lines
Quoted 1 line

Without having to look in other places...

ASIDs too. I'd also love to see more info in the docs and/or cover letter to explain why ASID management on SEV requires a cgroup. I know what an ASID is, and have a decent idea of how KVM manages ASIDs for legacy VMs, but I know nothing about why ASIDs are limited for SEV and not legacy VMs.

Thanks for the feedback, I will add more details in the Kconfig and the documentation about SEV and ASID.

#5 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

In reply to Sean Christopherson
Quoted 35 lines · Sean Christopherson
Quoted 34 lines · Randy Dunlap

Hi,

Quoted 24 lines · Vipin Sharma
init/Kconfig +0 -0
index d6a0b31b13dc..1a57c362b803 100644
@@ -1101,6 +1101,20 @@ config CGROUP_BPF
 	  BPF_CGROUP_INET_INGRESS will be executed on the ingress path

of

init/Kconfig +6 -0
 	  inet sockets.
 
+config CGROUP_SEV
+	bool "SEV ASID controller"
+	depends on KVM_AMD_SEV
+	default n
+	help
+	  Provides a controller for AMD SEV ASIDs. This controller

limits and

init/Kconfig +1 -0
+	  shows the total usage of SEV ASIDs used in encrypted VMs on

AMD

init/Kconfig +1 -0
+	  processors. Whenever a new encrypted VM is created using SEV

on an

init/Kconfig +1 -0
+	  AMD processor, this controller will check the current limit

in the

init/Kconfig +1 -0
+	  cgroup to which the task belongs and will deny the SEV ASID

if the

init/Kconfig config CGROUP_BPF · line 1116

Quoted 3 lines
init/Kconfig +3 -0
+	  cgroup has already reached its limit.
+
+	  Say N if unsure.

Something here (either in the bool prompt string or the help text) should let a reader know w.t.h. SEV means.

Quoted 7 lines
Quoted 1 line

Without having to look in other places...

ASIDs too. I'd also love to see more info in the docs and/or cover letter to explain why ASID management on SEV requires a cgroup. I know what an ASID is, and have a decent idea of how KVM manages ASIDs for legacy VMs, but I know nothing about why ASIDs are limited for SEV and not legacy VMs.

Well, also, why would we only have a cgroup for ASIDs but not MSIDs?

For the reader at home a Space ID (SID) is simply a tag that can be placed on a cache line to control things like flushing. Intel and AMD use MSIDs which are allocated per process to allow fast context switching by flushing all the process pages using a flush by SID. ASIDs are also used by both Intel and AMD to control nested/extended paging of virtual machines, so ASIDs are allocated per VM. So far it's universal.

AMD invented a mechanism for tying their memory encryption technology to the ASID asserted on the memory bus, so now they can do encrypted virtual machines since each VM is tagged by ASID which the memory encryptor sees. It is suspected that the forthcoming intel TDX technology to encrypt VMs will operate in the same way as well. This isn't everything you have to do to get an encrypted VM, but it's a core part of it.

The problem with SIDs (both A and M) is that they get crammed into spare bits in the CPU (like the upper bits of %CR3 for MSID) so we don't have enough of them to do a 1:1 mapping of MSID to process or ASID to VM. Thus we have to ration them somewhat, which is what I assume this patch is about?

James

#6 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

Quoted 8 lines · James Bottomley
Quoted 5 lines · Sean Christopherson

ASIDs too. I'd also love to see more info in the docs and/or cover letter to explain why ASID management on SEV requires a cgroup. I know what an ASID is, and have a decent idea of how KVM manages ASIDs for legacy VMs, but I know nothing about why ASIDs are limited for SEV and not legacy VMs.

Well, also, why would we only have a cgroup for ASIDs but not MSIDs?

Assuming MSID==PCID in Intel terminology, which may be a bad assumption, the answer is that rationing PCIDs is a fools errand, at least on Intel CPUs.

Quoted 7 lines

For the reader at home a Space ID (SID) is simply a tag that can be placed on a cache line to control things like flushing. Intel and AMD use MSIDs which are allocated per process to allow fast context switching by flushing all the process pages using a flush by SID. ASIDs are also used by both Intel and AMD to control nested/extended paging of virtual machines, so ASIDs are allocated per VM. So far it's universal.

On Intel CPUs, multiple things factor into the actual ASID that is used to tag TLB entries. And underneath the hood, there are a _very_ limited number of ASIDs that are globally shared, i.e. a process in the host has an ASID, same as a process in the guest, and the CPU only supports tagging translations for N ASIDs at any given time.

E.g. with TDX, the hardware/real ASID is derived from:

VPID + PCID + SEAM + EPTP

where VPID=0 for host, PCID=0 if PCID is disabled, SEAM=1 for the TDX-Module and TDX VMs, and obviously EPTP is invalid/ignored when EPT is disabled.

Quoted 5 lines

AMD invented a mechanism for tying their memory encryption technology to the ASID asserted on the memory bus, so now they can do encrypted virtual machines since each VM is tagged by ASID which the memory encryptor sees. It is suspected that the forthcoming intel TDX technology to encrypt VMs will operate in the same way as well. This

TDX uses MKTME keys, which are not tied to the ASID. The KeyID is part of the physical address, at least in the initial hardware implementations, which means that from a memory perspective, each KeyID is a unique physical address. This is completely orthogonal to ASIDs, e.g. a given KeyID+PA combo can have mutliple TLB entries if it's accessed by multiple ASIDs.

Quoted 5 lines

isn't everything you have to do to get an encrypted VM, but it's a core part of it.

The problem with SIDs (both A and M) is that they get crammed into spare bits in the CPU (like the upper bits of %CR3 for MSID) so we

This CR3 reference is why I assume MSID==PCID, but the PCID is carved out of the lower bits (11:0) of CR3, which is why I'm unsure I interpreted this correctly.

Quoted 3 lines

don't have enough of them to do a 1:1 mapping of MSID to process or ASID to VM. Thus we have to ration them somewhat, which is what I assume this patch is about?

This cgroup is more about a hard limitation than about performance.

With PCIDs, VPIDs, and AMD's ASIDs, there is always the option of recycling an existing ID (used for PCIDs and ASIDs), or simply disabling the feature (used for VPIDs). In both cases, exhausting the resource affects performance due to incurring TLB flushes at transition points, but doesn't prevent creating new processes/VMs.

And due to the way PCID=>ASID derivation works on Intel CPUs, the kernel doesn't even bother trying to use a large number of PCIDs. IIRC, the current number of PCIDs used by the kernel is 5, i.e. the kernel intentionally recycles PCIDs long before it's forced to do so by the architectural limitation of 4k PCIDs, because using more than 5 PCIDs actually hurts performance (forced PCID recycling allows the kernel to keep *its* ASID live by flushing userspace PCIDs, whereas CPU recycling of ASIDs is indiscriminate).

MKTME KeyIDs and SEV ASIDs are different. There is a hard, relatively low limit on the number of IDs that are available, and exhausting that pool effectively prevents creating a new encrypted VM[*]. E.g. with TDX, on first gen hardware there is a hard limit of 127 KeyIDs that can be used to create TDX VMs. IIRC, SEV-ES is capped 512 or so ASIDs. Hitting that cap means no more protected VMs can be created.

[*] KeyID exhaustion for TDX is a hard restriction, the old VM _must_ be torn
down to reuse the KeyID. ASID exhaustion for SEV is not technically a hard limit, e.g. KVM could theoretically park a VM to reuse its ASID, but for all intents and purposes that VM is no longer live.

#7 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

Quoted 8 lines · Sean Christopherson
Quoted 7 lines · James Bottomley
Quoted 5 lines · Sean Christopherson

ASIDs too. I'd also love to see more info in the docs and/or cover letter to explain why ASID management on SEV requires a cgroup. I know what an ASID is, and have a decent idea of how KVM manages ASIDs for legacy VMs, but I know nothing about why ASIDs are limited for SEV and not legacy VMs.

Quoted 6 lines
Quoted 2 lines

Well, also, why would we only have a cgroup for ASIDs but not MSIDs?

Assuming MSID==PCID in Intel terminology, which may be a bad assumption, the answer is that rationing PCIDs is a fools errand, at least on Intel CPUs.

Yes, sorry, I should probably have confessed that I'm most used to parisc SIDs, which are additional 32 bit qualifiers the CPU explicitly adds to every virtual address. The perform exactly the same function, though except they're a bit more explicit (and we have more bits). On PA every virtual address is actually a GVA consisting of 32 bit of SID and 64 bits of VA and we use this 96 byte address for virtual indexing and things. And parisc doesn't have virtualization acceleration so we only have one type of SID.

Thanks for the rest of the elaboration.

James

#8 lore raw

Re: [RFC Patch 1/2] KVM: SVM: Create SEV cgroup controller.

In reply to Vipin Sharma
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Vipin,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on kvm/linux-next]
[also build test WARNING on vhost/linux-next linus/master cgroup/for-next v5.9-rc6 next-20200921] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Vipin-Sharma/KVM-SVM-Cgroup-support-for-SVM-SEV-ASIDs/20200922-084116
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> arch/x86/kvm/svm/sev_cgroup.c:103:5: warning: no previous prototype for 'sev_asid_try_charge' [-Wmissing-prototypes]
     103 | int sev_asid_try_charge(int pos)
         |     ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/svm/sev_cgroup.c:145:6: warning: no previous prototype for 'sev_asid_uncharge' [-Wmissing-prototypes]
     145 | void sev_asid_uncharge(int pos)
         |      ^~~~~~~~~~~~~~~~~
>> arch/x86/kvm/svm/sev_cgroup.c:171:5: warning: no previous prototype for 'sev_cgroup_setup' [-Wmissing-prototypes]
     171 | int sev_cgroup_setup(unsigned int max)
         |     ^~~~~~~~~~~~~~~~
>> arch/x86/kvm/svm/sev_cgroup.c:198:6: warning: no previous prototype for 'sev_cgroup_teardown' [-Wmissing-prototypes]

198 | void sev_cgroup_teardown(void)
| ^~~~~~~~~~~~~~~~~~~

# https://github.com/0day-ci/linux/commit/a6ea9901dcea64e24118ff35965406ed101d614f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Vipin-Sharma/KVM-SVM-Cgroup-support-for-SVM-SEV-ASIDs/20200922-084116 git checkout a6ea9901dcea64e24118ff35965406ed101d614f
vim +/sev_asid_try_charge +103 arch/x86/kvm/svm/sev_cgroup.c

88
89 /**
90 * sev_asid_try_charge() - Try charging an SEV ASID to the cgroup.
91 * @pos: Index of SEV ASID in the SEV ASIDs bitmap.
92 *
93 * Try charging an SEV ASID to the current task's cgroup and all its ancestors
94 * up to the root. If charging is not possible due to the limit constraint,
95 * then notify the event file and return -errorno.
96 *
97 * Context: Process context. Takes and release sev_cgroup_lock mutex.
98 * Return:
99 * * 0 - If successfully charged the cgroup.
100 * * -EINVAL - If pos is not valid.
101 * * -EBUSY - If usage has already reached the limit.
102 */

 > 103	int sev_asid_try_charge(int pos)
   104	{
   105		struct sev_cgroup *start, *i, *j;
   106		int ret = 0;
   107	
   108		mutex_lock(&sev_cgroup_lock);
   109	
   110		start = css_sev(task_css(current, sev_cgrp_id));
   111	
   112		for (i = start; i; i = parent_sev_cgroup(i)) {
   113			if (i->usage == i->max)
   114				goto e_limit;
   115	
   116			i->usage++;
   117		}
   118	
   119		sev_asids_cgroup_array[pos] = start;
   120	exit:
   121		mutex_unlock(&sev_cgroup_lock);
   122		return ret;
   123	
   124	e_limit:
   125		for (j = start; j != i; j = parent_sev_cgroup(j))
   126			sev_asid_cgroup_dec(j);
   127	
   128		start->allocation_failure_event++;
   129		cgroup_file_notify(&start->events_file);
   130	
   131		ret = -EBUSY;
   132		goto exit;
   133	}
   134	EXPORT_SYMBOL(sev_asid_try_charge);
   135	
   136	/**
   137	 * sev_asid_uncharge() - Uncharge an SEV ASID from the cgroup.
   138	 * @pos: Index of SEV ASID in the SEV ASIDs bitmap.
   139	 *
   140	 * Uncharge an SEV ASID from the cgroup to which it was charged in
   141	 * sev_asid_try_charge().
   142	 *
   143	 * Context: Process context. Takes and release sev_cgroup_lock mutex.
   144	 */
 > 145	void sev_asid_uncharge(int pos)
   146	{
   147		struct sev_cgroup *i;
   148	
   149		mutex_lock(&sev_cgroup_lock);
   150	
   151		for (i = sev_asids_cgroup_array[pos]; i; i = parent_sev_cgroup(i))
   152			sev_asid_cgroup_dec(i);
   153	
   154		sev_asids_cgroup_array[pos] = NULL;
   155	
   156		mutex_unlock(&sev_cgroup_lock);
   157	}
   158	EXPORT_SYMBOL(sev_asid_uncharge);
   159	
   160	/**
   161	 * sev_cgroup_setup() - Setup the sev cgroup before charging.
   162	 * @max: Maximum number of SEV ASIDs supported by the platform.
   163	 *
   164	 * Initialize the sev_asids_cgroup_array which stores ASID to cgroup mapping.
   165	 *
   166	 * Context: Process context. Takes and release sev_cgroup_lock mutex.
   167	 * Return:
   168	 * * 0 - If setup was successful.
   169	 * * -ENOMEM - If memory not available to allocate the array.
   170	 */
 > 171	int sev_cgroup_setup(unsigned int max)
   172	{
   173		int ret = 0;
   174	
   175		mutex_lock(&sev_cgroup_lock);
   176	
   177		sev_max_asids = max;
   178		sev_asids_cgroup_array = kcalloc(sev_max_asids,
   179						 sizeof(struct sev_cgroup *),
   180						 GFP_KERNEL);
   181		if (!sev_asids_cgroup_array) {
   182			sev_max_asids = 0;
   183			ret = -ENOMEM;
   184		}
   185	
   186		mutex_unlock(&sev_cgroup_lock);
   187	
   188		return ret;
   189	}
   190	EXPORT_SYMBOL(sev_cgroup_setup);
   191	
   192	/**
   193	 * sev_cgroup_teardown() - Release resources, no more charging/uncharging will
   194	 *			   happen.
   195	 *
   196	 * Context: Process context. Takes and release sev_cgroup_lock mutex.
   197	 */
 > 198	void sev_cgroup_teardown(void)

199 {
200 mutex_lock(&sev_cgroup_lock);
201
202 kfree(sev_asids_cgroup_array);
203 sev_asids_cgroup_array = NULL;
204 sev_max_asids = 0;
205
206 mutex_unlock(&sev_cgroup_lock);
207 }
208 EXPORT_SYMBOL(sev_cgroup_teardown);
209

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#9 lore raw

RFC PATCH 2/2 KVM: SVM: SEV cgroup controller documentation

In reply to Vipin Sharma

SEV cgroup controller documentation.

Documentation for both cgroup versions, v1 and v2, of SEV cgroup controller. SEV controller is used to distribute and account SEV ASIDs usage by KVM on AMD processor.

---
 Documentation/admin-guide/cgroup-v1/sev.rst | 94 +++++++++++++++++++++
 Documentation/admin-guide/cgroup-v2.rst     | 56 +++++++++++-
 2 files changed, 147 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/admin-guide/cgroup-v1/sev.rst
Documentation/admin-guide/cgroup-v1/sev.rst new file +94 -0
new file mode 100644
index 000000000000..04d0024360a1
@@ -0,0 +1,94 @@
+==============
+SEV Controller
+==============
+
+Overview
+========
+
+The SEV controller regulates the distribution of SEV ASIDs. SEV ASIDs are used
+in creating encrypted VMs on AMD processors. SEV ASIDs are stateful and one
+ASID is only used in one KVM object at a time. It cannot be used with other KVM
+before unbinding it from the previous KVM.
+
+All SEV ASIDs are tracked by this controller and it allows for accounting and
+distribution of this resource.
+
+How to Enable Controller
+========================
+
+- Enable memory encryption on AMD platform::
+
+        CONFIG_KVM_AMD_SEV=y
+
+- Enable SEV controller::
+
+        CONFIG_CGROUP_SEV=y
+
+- Above options will build SEV controller support in the kernel.
+  To mount sev controller::
+
+        mount -t cgroup -o sev none /sys/fs/cgroup/sev
+
+Interface Files
+==============
+
+  sev.current
+        A read-only single value file which exists on non-root cgroups.
+
+        The total number of SEV ASIDs currently in use by the cgroup and its
+        descendants.
+
+  sev.max
+        A read-write single value file which exists on non-root cgroups. The
+        default is "max".
+
+        SEV ASIDs usage hard limit. If the cgroup's current SEV ASIDs usage
+        reach this limit then the new SEV VMs creation will return error
+        -EBUSY.  This limit cannot be set lower than sev.current.
+
+  sev.events
+        A read-only flat-keyed single value file which exists on non-root
+        cgroups. A value change in this file generates a file modified event.
+
+          max
+                 The number of times the cgroup's SEV ASIDs usage was about to
+                 go over the max limit. This is a tally of SEV VM creation
+                 failures in the cgroup.
+
+Hierarchy
+=========
+
+SEV controller supports hierarchical accounting. It supports following
+features:
+
+1. SEV ASID usage in the cgroup includes itself and its descendent cgroups.
+2. SEV ASID usage can never exceed the max limit set in the cgroup and its
+   ancestor's chain up to the root.
+3. SEV events keep a tally of SEV VM creation failures in the cgroup and not in
+   its child subtree.
+
+Suppose the following example hierarchy::
+
+                        root
+                        /  \
+                       A    B
+                       |
+                       C
+
+1. A will show the count of SEV ASID used in A and C.
+2. C's SEV ASID usage may not exceed any of the max limits set in C, A, or
+   root.
+3. A's event file lists only SEV VM creation failed in A, and not the ones in
+   C.
+
+Migration and SEV ASID ownership
+================================
+
+An SEV ASID is charged to the cgroup which instantiated it, and stays charged
+to that cgroup until that SEV ASID is freed. Migrating a process to a different
+cgroup do not move the SEV ASID charge to the destination cgroup where the
+process has moved.
+
+Deletion of a cgroup with existing ASIDs charges will migrate those ASIDs to
+the parent cgroup.
+
Documentation/admin-guide/cgroup-v2.rst +53 -3

74 lines not on this page · raw message

Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
#10 lore raw
In reply to Vipin Sharma
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

#11 lore raw
Quoted 21 lines · Sean Christopherson
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

I read about the TDX and its use of the KeyID for encrypting VMs. TDX has two kinds of KeyIDs private and shared.

On AMD platform there are two types of ASIDs for encryption.
1. SEV ASID - Normal runtime guest memory encryption.
2. SEV-ES ASID - Extends SEV ASID by adding register state encryption with integrity.

Both types of ASIDs have their own maximum value which is provisioned in the firmware

So, we are talking about 4 different types of resources:
1. AMD SEV ASID (implemented in this patch as sev.* files in SEV cgroup)
2. AMD SEV-ES ASID (in future, adding files like sev_es.*)
3. Intel TDX private KeyID
4. Intel TDX shared KeyID

TDX private KeyID is similar to SEV and SEV-ES ASID. I think coming up with the same name which can be used by both platforms will not be easy, and extensible with the future enhancements. This will get even more difficult if Arm also comes up with something similar but with different nuances.

I like the idea of the KVM cgroup and when it is mounted it will have different files based on the hardware platform.

1. KVM cgroup on AMD will have:
sev.max & sev.current.
sev_es.max & sev_es.current.

2. KVM cgroup mounted on Intel:
tdx_private_keys.max
tdx_shared_keys.max

The KVM cgroup can be used to have control files which are generic (no use case in my mind right now) and hardware platform specific files also.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 41 lines · Sean Christopherson
Quoted 29 lines · Vipin Sharma
Quoted 21 lines · Sean Christopherson
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 2 lines

I read about the TDX and its use of the KeyID for encrypting VMs. TDX has two kinds of KeyIDs private and shared.

To clarify, "shared" KeyIDs are simply legacy MKTME KeyIDs. This is relevant because those KeyIDs can be used without TDX or KVM in the picture.

Quoted 5 lines

On AMD platform there are two types of ASIDs for encryption.
1. SEV ASID - Normal runtime guest memory encryption.
2. SEV-ES ASID - Extends SEV ASID by adding register state encryption with integrity.

Quoted 7 lines
Quoted 2 lines

Both types of ASIDs have their own maximum value which is provisioned in the firmware

Ugh, I missed that detail in the SEV-ES RFC. Does SNP add another ASID type, or does it reuse SEV-ES ASIDs? If it does add another type, is that trend expected to continue, i.e. will SEV end up with SEV, SEV-ES, SEV-ES-SNP, SEV-ES-SNP-X, SEV-ES-SNP-X-Y, etc...?

SEV-SNP and SEV-ES share the same ASID range.

Thanks,
Tom

Quoted 52 lines
Quoted 7 lines

So, we are talking about 4 different types of resources:
1. AMD SEV ASID (implemented in this patch as sev.* files in SEV cgroup)
2. AMD SEV-ES ASID (in future, adding files like sev_es.*)
3. Intel TDX private KeyID
4. Intel TDX shared KeyID

Quoted 5 lines

TDX private KeyID is similar to SEV and SEV-ES ASID. I think coming up with the same name which can be used by both platforms will not be easy, and extensible with the future enhancements. This will get even more difficult if Arm also comes up with something similar but with different nuances.

Honest question, what's easier for userspace/orchestration layers? Having an abstract but common name, or conrete but different names? My gut reaction is to provide a common interface, but I can see how that could do more harm than good, e.g. some amount of hardware capabilitiy discovery is possible with concrete names. And I'm guessing there's already a fair amount of vendor specific knowledge bleeding into userspace for these features...

And if SNP is adding another ASID namespace, trying to abstract the types is probably a lost cause.

From a code perspective, I doubt it will matter all that much, e.g. it should
be easy enough to provide helpers for exposing a new asid/key type.

Quoted 2 lines

I like the idea of the KVM cgroup and when it is mounted it will have different files based on the hardware platform.

I don't think a KVM cgroup is the correct approach, e.g. there are potential use cases for "legacy" MKTME without KVM. Maybe something like Encryption Keys cgroup?

Quoted 11 lines

1. KVM cgroup on AMD will have:
sev.max & sev.current.
sev_es.max & sev_es.current.

2. KVM cgroup mounted on Intel:
tdx_private_keys.max
tdx_shared_keys.max

The KVM cgroup can be used to have control files which are generic (no use case in my mind right now) and hardware platform specific files also.

My "generic KVM cgroup" suggestion was probably a pretty bad suggestion. Except for ASIDs/KeyIDs, KVM itself doesn't manage any constrained resources, e.g. memory, logical CPUs, time slices, etc... are all generic resources that are consumed by KVM but managed elsewhere. We definitely don't want to change that, nor do I think we want to do anything, such as creating a KVM cgroup, that would imply that having KVM manage resources is a good idea.

#14 lore raw
Quoted 50 lines · Tom Lendacky
Quoted 41 lines · Sean Christopherson
Quoted 29 lines · Vipin Sharma
Quoted 21 lines · Sean Christopherson
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 2 lines

I read about the TDX and its use of the KeyID for encrypting VMs. TDX has two kinds of KeyIDs private and shared.

To clarify, "shared" KeyIDs are simply legacy MKTME KeyIDs. This is relevant because those KeyIDs can be used without TDX or KVM in the picture.

Quoted 5 lines

On AMD platform there are two types of ASIDs for encryption.
1. SEV ASID - Normal runtime guest memory encryption.
2. SEV-ES ASID - Extends SEV ASID by adding register state encryption with integrity.

Quoted 7 lines
Quoted 2 lines

Both types of ASIDs have their own maximum value which is provisioned in the firmware

Ugh, I missed that detail in the SEV-ES RFC. Does SNP add another ASID type, or does it reuse SEV-ES ASIDs? If it does add another type, is that trend expected to continue, i.e. will SEV end up with SEV, SEV-ES, SEV-ES-SNP, SEV-ES-SNP-X, SEV-ES-SNP-X-Y, etc...?

Quoted 24 lines

SEV-SNP and SEV-ES share the same ASID range.

Thanks,
Tom

Quoted 19 lines
Quoted 7 lines

So, we are talking about 4 different types of resources:
1. AMD SEV ASID (implemented in this patch as sev.* files in SEV cgroup)
2. AMD SEV-ES ASID (in future, adding files like sev_es.*)
3. Intel TDX private KeyID
4. Intel TDX shared KeyID

Quoted 5 lines

TDX private KeyID is similar to SEV and SEV-ES ASID. I think coming up with the same name which can be used by both platforms will not be easy, and extensible with the future enhancements. This will get even more difficult if Arm also comes up with something similar but with different nuances.

Honest question, what's easier for userspace/orchestration layers? Having an abstract but common name, or conrete but different names? My gut reaction is to provide a common interface, but I can see how that could do more harm than good, e.g. some amount of hardware capabilitiy discovery is possible with concrete names. And I'm guessing there's already a fair amount of vendor specific knowledge bleeding into userspace for these features...

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Control files: slots.{max, current, events}

Contents of the slot.max:
default max
default: Corresponds to all kinds of encryption capabilities on
a platform. For AMD, it will be SEV and SEV-ES. For Intel, it will be TDX and MKTME. This can also be used by other devices not just CPU.

max: max or any number to denote limit on the cgroup.

A user who wants the finer control, then they need to know about the capabilities a platform provides and use them, e.g. on AMD:

$ echo "sev-es 1000" > slot.max
$ cat slots.max
default max sev-es 1000

This means that in the cgroup maximum SEV-ES ASIDs which can be used is 1000 and SEV ASIDs is max (default, no limit). Each platform can provide their own extensions which can be overwritten by a user, otherwise extensions will have the default limit.

This is kind of similar to the IO and the rdma controller.

I think it is keeping abstraction for userspace and also providing finer control for HW specific features.

What do you think about the above approach?

Quoted 7 lines
Quoted 7 lines

And if SNP is adding another ASID namespace, trying to abstract the types is probably a lost cause.

From a code perspective, I doubt it will matter all that much, e.g. it should
be easy enough to provide helpers for exposing a new asid/key type.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I like the idea of the KVM cgroup and when it is mounted it will have different files based on the hardware platform.

I don't think a KVM cgroup is the correct approach, e.g. there are potential use cases for "legacy" MKTME without KVM. Maybe something like Encryption Keys cgroup?

Added some suggestion in the above approach. I think we should not add key in the name because here limitation is on the number of keys that can be used simultaneously.

Quoted 20 lines
Quoted 20 lines
Quoted 5 lines

1. KVM cgroup on AMD will have:
sev.max & sev.current.
sev_es.max & sev_es.current.

Quoted 7 lines

2. KVM cgroup mounted on Intel:
tdx_private_keys.max
tdx_shared_keys.max

The KVM cgroup can be used to have control files which are generic (no use case in my mind right now) and hardware platform specific files also.

My "generic KVM cgroup" suggestion was probably a pretty bad suggestion. Except for ASIDs/KeyIDs, KVM itself doesn't manage any constrained resources, e.g. memory, logical CPUs, time slices, etc... are all generic resources that are consumed by KVM but managed elsewhere. We definitely don't want to change that, nor do I think we want to do anything, such as creating a KVM cgroup, that would imply that having KVM manage resources is a good idea.

#15 lore raw
Quoted 106 lines · Vipin Sharma
Quoted 50 lines · Tom Lendacky
Quoted 41 lines · Sean Christopherson
Quoted 29 lines · Vipin Sharma
Quoted 21 lines · Sean Christopherson
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 2 lines

I read about the TDX and its use of the KeyID for encrypting VMs. TDX has two kinds of KeyIDs private and shared.

To clarify, "shared" KeyIDs are simply legacy MKTME KeyIDs. This is relevant because those KeyIDs can be used without TDX or KVM in the picture.

Quoted 5 lines

On AMD platform there are two types of ASIDs for encryption.
1. SEV ASID - Normal runtime guest memory encryption.
2. SEV-ES ASID - Extends SEV ASID by adding register state encryption with integrity.

Quoted 7 lines
Quoted 2 lines

Both types of ASIDs have their own maximum value which is provisioned in the firmware

Ugh, I missed that detail in the SEV-ES RFC. Does SNP add another ASID type, or does it reuse SEV-ES ASIDs? If it does add another type, is that trend expected to continue, i.e. will SEV end up with SEV, SEV-ES, SEV-ES-SNP, SEV-ES-SNP-X, SEV-ES-SNP-X-Y, etc...?

Quoted 24 lines

SEV-SNP and SEV-ES share the same ASID range.

Thanks,
Tom

Quoted 19 lines
Quoted 7 lines

So, we are talking about 4 different types of resources:
1. AMD SEV ASID (implemented in this patch as sev.* files in SEV cgroup)
2. AMD SEV-ES ASID (in future, adding files like sev_es.*)
3. Intel TDX private KeyID
4. Intel TDX shared KeyID

Quoted 5 lines

TDX private KeyID is similar to SEV and SEV-ES ASID. I think coming up with the same name which can be used by both platforms will not be easy, and extensible with the future enhancements. This will get even more difficult if Arm also comes up with something similar but with different nuances.

Honest question, what's easier for userspace/orchestration layers? Having an abstract but common name, or conrete but different names? My gut reaction is to provide a common interface, but I can see how that could do more harm than good, e.g. some amount of hardware capabilitiy discovery is possible with concrete names. And I'm guessing there's already a fair amount of vendor specific knowledge bleeding into userspace for these features...

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Control files: slots.{max, current, events}

Contents of the slot.max:
default max
default: Corresponds to all kinds of encryption capabilities on
a platform. For AMD, it will be SEV and SEV-ES. For Intel, it will be TDX and MKTME. This can also be used by other devices not just CPU.

max: max or any number to denote limit on the cgroup.

A user who wants the finer control, then they need to know about the capabilities a platform provides and use them, e.g. on AMD:

$ echo "sev-es 1000" > slot.max
$ cat slots.max
default max sev-es 1000

This means that in the cgroup maximum SEV-ES ASIDs which can be used is 1000 and SEV ASIDs is max (default, no limit). Each platform can provide their own extensions which can be overwritten by a user, otherwise extensions will have the default limit.

Quoted 7 lines

This is kind of similar to the IO and the rdma controller.

I think it is keeping abstraction for userspace and also providing finer control for HW specific features.

What do you think about the above approach?

Hi Sean,

Any feedback/concern for the above abstraction approach?

Thanks

#16 lore raw
Quoted 9 lines · Vipin Sharma
Quoted 8 lines · Vipin Sharma

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Control files: slots.{max, current, events}

I don't particularly like the "slots" name, mostly because it could be confused with KVM's memslots. Maybe encryption_ids.ids.{max, current, events}? I don't love those names either, but "encryption" and "IDs" are the two obvious commonalities betwee TDX's encryption key IDs and SEV's encryption address space IDs.

#17 lore raw
Quoted 9 lines · Sean Christopherson
Quoted 8 lines · Vipin Sharma
Quoted 7 lines · Vipin Sharma

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Control files: slots.{max, current, events}

I don't particularly like the "slots" name, mostly because it could be confused with KVM's memslots. Maybe encryption_ids.ids.{max, current, events}? I don't love those names either, but "encryption" and "IDs" are the two obvious commonalities betwee TDX's encryption key IDs and SEV's encryption address space IDs.

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned separately so we treat them as their own resource here.

So which is easier?

$ cat encryption.sev.max
10
$ echo -n 15 > encryption.sev.max

or

$ cat encryption.max
sev 10
sev_es 10
keyid 0
$ echo -n "sev 10" > encryption.max

I would argue the former is simplest (always preferring one-value-per-file) and avoids any string parsing or resource controller lookups that need to match on that string in the kernel.

The set of encryption.{sev,sev_es,keyid} files that exist would depend on CONFIG_CGROUP_ENCRYPTION and whether CONFIG_AMD_MEM_ENCRYPT or CONFIG_INTEL_TDX is configured. Both can be configured so we have all three files, but the root file will obviously indicate 0 keys available for one of them (can't run on AMD and Intel at the same time :).

So I'm inclined to suggest that the one-value-per-file format is the ideal way to go unless there are objections to it.

#18 lore raw
Quoted 21 lines · David Rientjes
Quoted 9 lines · Sean Christopherson
Quoted 8 lines · Vipin Sharma
Quoted 7 lines · Vipin Sharma

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Control files: slots.{max, current, events}

I don't particularly like the "slots" name, mostly because it could be confused with KVM's memslots. Maybe encryption_ids.ids.{max, current, events}? I don't love those names either, but "encryption" and "IDs" are the two obvious commonalities betwee TDX's encryption key IDs and SEV's encryption address space IDs.

Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

Quoted 10 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

Quoted 4 lines

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

Quoted 16 lines

separately so we treat them as their own resource here.

So which is easier?

$ cat encryption.sev.max                                                      
10                                                                            
$ echo -n 15 > encryption.sev.max                                             

or

$ cat encryption.max                                                          
sev 10                                                                        
sev_es 10                                                                     
keyid 0                                                                       
$ echo -n "sev 10" > encryption.max                                           
Quoted 3 lines

I would argue the former is simplest (always preferring one-value-per-file) and avoids any string parsing or resource controller lookups that need to match on that string in the kernel.

Ya, I prefer individual files as well.

I don't think "keyid" is the best name for TDX, it doesn't leave any wiggle room if there are other flavors of key IDs on Intel platform, e.g. private vs. shared in the future. It's also inconsistent with the SEV names, e.g. "asid" isn't mentioned anywhere. And "keyid" sort of reads as "max key id", rather than "max number of keyids". Maybe "tdx_private", or simply "tdx"? Doesn't have to be solved now though, there's plenty of time before TDX will be upstream. :-)

Quoted 8 lines

The set of encryption.{sev,sev_es,keyid} files that exist would depend on CONFIG_CGROUP_ENCRYPTION and whether CONFIG_AMD_MEM_ENCRYPT or CONFIG_INTEL_TDX is configured. Both can be configured so we have all three files, but the root file will obviously indicate 0 keys available for one of them (can't run on AMD and Intel at the same time :).

So I'm inclined to suggest that the one-value-per-file format is the ideal way to go unless there are objections to it.

#19 lore raw
Quoted 41 lines · Sean Christopherson
Quoted 21 lines · David Rientjes
Quoted 9 lines · Sean Christopherson
Quoted 8 lines · Vipin Sharma
Quoted 7 lines · Vipin Sharma

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Control files: slots.{max, current, events}

I don't particularly like the "slots" name, mostly because it could be confused with KVM's memslots. Maybe encryption_ids.ids.{max, current, events}? I don't love those names either, but "encryption" and "IDs" are the two obvious commonalities betwee TDX's encryption key IDs and SEV's encryption address space IDs.

Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

Quoted 10 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

Quoted 9 lines
Quoted 4 lines

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

We will be showing encryption_ids.{sev,sev_es}.{max,current} I am inclined to not provide "events" as I am not using it, let me know if this file is required, I can provide it then.

I will provide an encryption_ids.{sev,sev_es}.stat file, which shows total available ids on the platform. This one will be useful for scheduling jobs in the cloud infrastructure based on total supported capacity.

Quoted 37 lines
Quoted 16 lines

separately so we treat them as their own resource here.

So which is easier?

$ cat encryption.sev.max                                                      
10                                                                            
$ echo -n 15 > encryption.sev.max                                             

or

$ cat encryption.max                                                          
sev 10                                                                        
sev_es 10                                                                     
keyid 0                                                                       
$ echo -n "sev 10" > encryption.max                                           
Quoted 3 lines

I would argue the former is simplest (always preferring one-value-per-file) and avoids any string parsing or resource controller lookups that need to match on that string in the kernel.

Ya, I prefer individual files as well.

I don't think "keyid" is the best name for TDX, it doesn't leave any wiggle room if there are other flavors of key IDs on Intel platform, e.g. private vs. shared in the future. It's also inconsistent with the SEV names, e.g. "asid" isn't mentioned anywhere. And "keyid" sort of reads as "max key id", rather than "max number of keyids". Maybe "tdx_private", or simply "tdx"? Doesn't have to be solved now though, there's plenty of time before TDX will be upstream. :-)

Quoted 8 lines

The set of encryption.{sev,sev_es,keyid} files that exist would depend on CONFIG_CGROUP_ENCRYPTION and whether CONFIG_AMD_MEM_ENCRYPT or CONFIG_INTEL_TDX is configured. Both can be configured so we have all three files, but the root file will obviously indicate 0 keys available for one of them (can't run on AMD and Intel at the same time :).

So I'm inclined to suggest that the one-value-per-file format is the ideal way to go unless there are objections to it.

#20 lore raw
Quoted 9 lines · Vipin Sharma
Quoted 9 lines
Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

Agreed.

Quoted 20 lines
Quoted 10 lines
Quoted 10 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

Quoted 9 lines
Quoted 4 lines

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

Quoted 9 lines

We will be showing encryption_ids.{sev,sev_es}.{max,current} I am inclined to not provide "events" as I am not using it, let me know if this file is required, I can provide it then.

I will provide an encryption_ids.{sev,sev_es}.stat file, which shows total available ids on the platform. This one will be useful for scheduling jobs in the cloud infrastructure based on total supported capacity.

Makes sense. I assume the stat file is only at the cgroup root level since it would otherwise be duplicating its contents in every cgroup under it. Probably not very helpful for child cgroup to see stat = 509 ASIDs but max = 100 :)

#21 lore raw
Quoted 44 lines · David Rientjes
Quoted 9 lines · Vipin Sharma
Quoted 9 lines
Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

Agreed.

Quoted 20 lines
Quoted 10 lines
Quoted 10 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

Quoted 9 lines
Quoted 4 lines

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

Quoted 9 lines

We will be showing encryption_ids.{sev,sev_es}.{max,current} I am inclined to not provide "events" as I am not using it, let me know if this file is required, I can provide it then.

I will provide an encryption_ids.{sev,sev_es}.stat file, which shows total available ids on the platform. This one will be useful for scheduling jobs in the cloud infrastructure based on total supported capacity.

Quoted 4 lines

Makes sense. I assume the stat file is only at the cgroup root level since it would otherwise be duplicating its contents in every cgroup under it. Probably not very helpful for child cgroup to see stat = 509 ASIDs but max = 100 :)

Yes, only at root.

#22 lore raw
Quoted 30 lines · Vipin Sharma
Quoted 29 lines · David Rientjes
Quoted 9 lines · Vipin Sharma
Quoted 9 lines
Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

Agreed.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

We will be showing encryption_ids.{sev,sev_es}.{max,current} I am inclined to not provide "events" as I am not using it, let me know if this file is required, I can provide it then.

I've no objection to omitting current until it's needed.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I will provide an encryption_ids.{sev,sev_es}.stat file, which shows total available ids on the platform. This one will be useful for scheduling jobs in the cloud infrastructure based on total supported capacity.

Quoted 6 lines
Quoted 4 lines

Makes sense. I assume the stat file is only at the cgroup root level since it would otherwise be duplicating its contents in every cgroup under it. Probably not very helpful for child cgroup to see stat = 509 ASIDs but max = 100 :)

Yes, only at root.

Is a root level stat file needed? Can't the infrastructure do .max - .current on the root cgroup to calculate the number of available ids in the system?

#23 lore raw
Quoted 53 lines · Sean Christopherson
Quoted 30 lines · Vipin Sharma
Quoted 29 lines · David Rientjes
Quoted 9 lines · Vipin Sharma
Quoted 9 lines
Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

Agreed.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

We will be showing encryption_ids.{sev,sev_es}.{max,current} I am inclined to not provide "events" as I am not using it, let me know if this file is required, I can provide it then.

I've no objection to omitting current until it's needed.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

I will provide an encryption_ids.{sev,sev_es}.stat file, which shows total available ids on the platform. This one will be useful for scheduling jobs in the cloud infrastructure based on total supported capacity.

Makes sense. I assume the stat file is only at the cgroup root level since it would otherwise be duplicating its contents in every cgroup under it. Probably not very helpful for child cgroup to see stat = 509 ASIDs but max = 100 :)

Quoted 4 lines
Quoted 1 line

Yes, only at root.

Is a root level stat file needed? Can't the infrastructure do .max - .current on the root cgroup to calculate the number of available ids in the system?

For an efficient scheduling of workloads in the cloud infrastructure, a scheduler needs to know the total capacity supported and the current usage of the host to get the overall picture. There are some issues with .max -.current approach:

1. Cgroup v2 convention is to not put resource control files in the root. This will mean we need to sum (.max -.current) in all of the immediate children of the root.

2. .max can have any limit unless we add a check to not allow a user to set any value more than the supported one. This will theoretically change the encryption_ids cgroup resource distribution model from the limit based to the allocation based. It will require the same validations in the children cgroups. I think providing separate file on the root is a simpler approach.

For someone to set the max limit, they need to know what is the supported capacity. In the case of SEV and SEV-ES it is not shown anywhere and the only way to know this is to use a CPUID instructions. The "stat" file will provide an easy way to know it.

Since current approach is not migrating charges, this means when a process migrates to an another cgroup and the old cgroup is deleted (user won't see it but it will be present in the cgroup hierarchy internally), we cannot get the correct usage by going through other cgroup directories in this case.

I am suggesting that the root stat file should show both available and used information.

$ cat encryption_ids.sev.stat
total 509
used 102

It will be very easy for a cloud scheduler to retrieve the system state quickly.

#24 lore raw
Quoted 4 lines · Vipin Sharma
Quoted 2 lines · Sean Christopherson

Is a root level stat file needed? Can't the infrastructure do .max - .current on the root cgroup to calculate the number of available ids in the system?

Quoted 8 lines

For an efficient scheduling of workloads in the cloud infrastructure, a scheduler needs to know the total capacity supported and the current usage of the host to get the overall picture. There are some issues with .max -.current approach:

1. Cgroup v2 convention is to not put resource control files in the root. This will mean we need to sum (.max -.current) in all of the immediate children of the root.

Ah, that's annoying. Now that you mention it, I do vaguely recall this behavior.

Quoted 2 lines

2. .max can have any limit unless we add a check to not allow a user to set any value more than the supported one.

Duh, didn't think that one through.

Thanks!

#25 lore raw
In reply to Sean Christopherson
Quoted 22 lines · Sean Christopherson
Quoted 21 lines · David Rientjes
Quoted 17 lines · Sean Christopherson
Quoted 9 lines · Vipin Sharma
Quoted 8 lines · Vipin Sharma

I agree with you that the abstract name is better than the concrete name, I also feel that we must provide HW extensions. Here is one approach:

Cgroup name: cpu_encryption, encryption_slots, or memcrypt (open to suggestions)

Control files: slots.{max, current, events}

I don't particularly like the "slots" name, mostly because it could be confused with KVM's memslots. Maybe encryption_ids.ids.{max, current, events}? I don't love those names either, but "encryption" and "IDs" are the two obvious commonalities betwee TDX's encryption key IDs and SEV's encryption address space IDs.

Quoted 8 lines
Quoted 4 lines

Looping Janosch and Christian back into the thread.

I interpret this suggestion as encryption.{sev,sev_es,keyids}.{max,current,events} for AMD and Intel

I think it makes sense to use encryption_ids instead of simply encryption, that way it's clear the cgroup is accounting ids as opposed to restricting what techs can be used on yes/no basis.

For what its worth the IDs for s390x are called SEIDs (secure execution IDs)

Quoted 11 lines
Quoted 11 lines

offerings, which was my thought on this as well.

Certainly the kernel could provide a single interface for all of these and key value pairs depending on the underlying encryption technology but it seems to only introduce additional complexity in the kernel in string parsing that can otherwise be avoided. I think we all agree that a single interface for all encryption keys or one-value-per-file could be done in the kernel and handled by any userspace agent that is configuring these values.

Quoted 28 lines
Quoted 4 lines

I think Vipin is adding a root level file that describes how many keys we have available on the platform for each technology. So I think this comes down to, for example, a single encryption.max file vs encryption.{sev,sev_es,keyid}.max. SEV and SEV-ES ASIDs are provisioned

Are you suggesting that the cgroup omit "current" and "events"? I agree there's no need to enumerate platform total, but not knowing how many of the allowed IDs have been allocated seems problematic.

Quoted 19 lines

separately so we treat them as their own resource here.

So which is easier?

$ cat encryption.sev.max                                                      
10                                                                            
$ echo -n 15 > encryption.sev.max                                             

or

$ cat encryption.max                                                          
sev 10                                                                        
sev_es 10                                                                     
keyid 0                                                                       
$ echo -n "sev 10" > encryption.max                                           

I would argue the former is simplest (always preferring one-value-per-file) and avoids any string parsing or resource controller lookups that need to match on that string in the kernel.

I like the idea of having encryption_ids.max for all platforms. If we go for individual files using "seid" for s390 seems the best name.

Quoted 18 lines

Ya, I prefer individual files as well.

I don't think "keyid" is the best name for TDX, it doesn't leave any wiggle room if there are other flavors of key IDs on Intel platform, e.g. private vs. shared in the future. It's also inconsistent with the SEV names, e.g. "asid" isn't mentioned anywhere. And "keyid" sort of reads as "max key id", rather than "max number of keyids". Maybe "tdx_private", or simply "tdx"? Doesn't have to be solved now though, there's plenty of time before TDX will be upstream. :-)

Quoted 8 lines

The set of encryption.{sev,sev_es,keyid} files that exist would depend on CONFIG_CGROUP_ENCRYPTION and whether CONFIG_AMD_MEM_ENCRYPT or CONFIG_INTEL_TDX is configured. Both can be configured so we have all three files, but the root file will obviously indicate 0 keys available for one of them (can't run on AMD and Intel at the same time :).

So I'm inclined to suggest that the one-value-per-file format is the ideal way to go unless there are objections to it.

#26 lore raw
In reply to Tom Lendacky
Quoted 46 lines · Tom Lendacky
Quoted 44 lines · Sean Christopherson
Quoted 29 lines · Vipin Sharma
Quoted 21 lines · Sean Christopherson
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 2 lines

I read about the TDX and its use of the KeyID for encrypting VMs. TDX has two kinds of KeyIDs private and shared.

To clarify, "shared" KeyIDs are simply legacy MKTME KeyIDs. This is relevant because those KeyIDs can be used without TDX or KVM in the picture.

Quoted 7 lines

On AMD platform there are two types of ASIDs for encryption.
1. SEV ASID - Normal runtime guest memory encryption.
2. SEV-ES ASID - Extends SEV ASID by adding register state encryption with integrity.

Both types of ASIDs have their own maximum value which is provisioned in the firmware

Quoted 6 lines
Quoted 4 lines

Ugh, I missed that detail in the SEV-ES RFC. Does SNP add another ASID type, or does it reuse SEV-ES ASIDs? If it does add another type, is that trend expected to continue, i.e. will SEV end up with SEV, SEV-ES, SEV-ES-SNP, SEV-ES-SNP-X, SEV-ES-SNP-X-Y, etc...?

SEV-SNP and SEV-ES share the same ASID range.

Where is this documented? From the SEV-SNP FW ABI Spec 0.8 "The firmware checks that ASID is an encryption capable ASID. If not, the firmware returns INVALID_ASID." that doesn't seem clear that an SEV-ES ASID is required. Should this document be more clear?

#27 lore raw
Quoted 52 lines · Peter Gonda
Quoted 51 lines · Tom Lendacky
Quoted 48 lines · Sean Christopherson
Quoted 29 lines · Vipin Sharma
Quoted 21 lines · Sean Christopherson
Quoted 5 lines · Vipin Sharma

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

Quoted 8 lines

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 2 lines

I read about the TDX and its use of the KeyID for encrypting VMs. TDX has two kinds of KeyIDs private and shared.

To clarify, "shared" KeyIDs are simply legacy MKTME KeyIDs. This is relevant because those KeyIDs can be used without TDX or KVM in the picture.

Quoted 7 lines

On AMD platform there are two types of ASIDs for encryption.
1. SEV ASID - Normal runtime guest memory encryption.
2. SEV-ES ASID - Extends SEV ASID by adding register state encryption with integrity.

Both types of ASIDs have their own maximum value which is provisioned in the firmware

Ugh, I missed that detail in the SEV-ES RFC. Does SNP add another ASID type, or does it reuse SEV-ES ASIDs? If it does add another type, is that trend expected to continue, i.e. will SEV end up with SEV, SEV-ES, SEV-ES-SNP, SEV-ES-SNP-X, SEV-ES-SNP-X-Y, etc...?

Quoted 6 lines
Quoted 1 line

SEV-SNP and SEV-ES share the same ASID range.

Where is this documented? From the SEV-SNP FW ABI Spec 0.8 "The firmware checks that ASID is an encryption capable ASID. If not, the firmware returns INVALID_ASID." that doesn't seem clear that an SEV-ES ASID is required. Should this document be more clear?

I let the owner of the spec know and it will be updated.

Thanks,
Tom

Quoted 1 line
maintainer
#28 lore raw
In reply to Sean Christopherson
Quoted 6 lines · Sean Christopherson

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Or also MANY:1 (we are thinking of having multiple VMs share the same SEV ASID).

It might even be the same on s390 and PPC, in which case we probably want to implement this in virt/kvm. Paul, Janosch, do you think this would make sense for you? The original commit message is below.

Paolo

Quoted 14 lines · Vipin Sharma
Quoted 13 lines

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

#29 lore raw
Quoted 14 lines · Paolo Bonzini
Quoted 6 lines · Sean Christopherson

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 24 lines

Or also MANY:1 (we are thinking of having multiple VMs share the same SEV ASID).

It might even be the same on s390 and PPC, in which case we probably want to implement this in virt/kvm. Paul, Janosch, do you think this would make sense for you? The original commit message is below.

Paolo

Quoted 14 lines · Vipin Sharma
Quoted 13 lines

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

On s390 we currently support a few million protected guests per LPAR so guest IDs are not exactly scarce. However having accounting for them might add some value nevertheless, especially when having large amount of protected containers.

@Christian: Any thoughts on this?

#30 lore raw
Quoted 40 lines · Janosch Frank
Quoted 14 lines · Paolo Bonzini
Quoted 6 lines · Sean Christopherson

This should be genericized to not be SEV specific. TDX has a similar scarcity issue in the form of key IDs, which IIUC are analogous to SEV ASIDs (gave myself a quick crash course on SEV ASIDs). Functionally, I doubt it would change anything, I think it'd just be a bunch of renaming. The hardest part would probably be figuring out a name :-).

Quoted 6 lines

Another idea would be to go even more generic and implement a KVM cgroup that accounts the number of VMs of a particular type, e.g. legacy, SEV, SEV-ES?, and TDX. That has potential future problems though as it falls apart if hardware every supports 1:MANY VMs:KEYS, or if there is a need to account keys outside of KVM, e.g. if MKTME for non-KVM cases ever sees the light of day.

Quoted 24 lines

Or also MANY:1 (we are thinking of having multiple VMs share the same SEV ASID).

It might even be the same on s390 and PPC, in which case we probably want to implement this in virt/kvm. Paul, Janosch, do you think this would make sense for you? The original commit message is below.

Paolo

Quoted 14 lines · Vipin Sharma
Quoted 13 lines

Hello,

This patch series adds a new SEV controller for tracking and limiting the usage of SEV ASIDs on the AMD SVM platform.

SEV ASIDs are used in creating encrypted VM and lightweight sandboxes but this resource is in very limited quantity on a host.

This limited quantity creates issues like SEV ASID starvation and unoptimized scheduling in the cloud infrastructure.

SEV controller provides SEV ASID tracking and resource control mechanisms.

Quoted 6 lines

On s390 we currently support a few million protected guests per LPAR so guest IDs are not exactly scarce. However having accounting for them might add some value nevertheless, especially when having large amount of protected containers.

@Christian: Any thoughts on this?

Yes, maybe it is a good idea to limit containers to only have a sane number of secure guests, so that a malicious pod cannot consume all IDs by calling CREATE_VM and KVM_PV_ENABLE million times or so.