mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
qemu: tdx: Adapt to the TDX 1.5 stack
QEMU for TDX 1.5 makes use of private memory map/unmap. Make changes to govmm to support this. Support for private backing fd for memory is added as knob to the qemu config. Userspace's map/unmap operations are done by fallocate() ioctl on the backing store fd. Reference: https://lore.kernel.org/linux-mm/20220519153713.819591-1-chao.p.peng@linux.intel.com/ Fixes: #7770 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com> Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
8115a0522d
commit
1e34220c41
@ -141,9 +141,16 @@ const (
|
|||||||
func isDimmSupported(config *Config) bool {
|
func isDimmSupported(config *Config) bool {
|
||||||
switch runtime.GOARCH {
|
switch runtime.GOARCH {
|
||||||
case "amd64", "386", "ppc64le", "arm64":
|
case "amd64", "386", "ppc64le", "arm64":
|
||||||
if config != nil && config.Machine.Type == MachineTypeMicrovm {
|
if config != nil {
|
||||||
// microvm does not support NUMA
|
if config.Machine.Type == MachineTypeMicrovm {
|
||||||
return false
|
// microvm does not support NUMA
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if config.Knobs.MemFDPrivate {
|
||||||
|
// TDX guests rely on MemFD Private, which
|
||||||
|
// does not have NUMA support yet
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
@ -2628,6 +2635,9 @@ type Knobs struct {
|
|||||||
// MemPrealloc will allocate all the RAM upfront
|
// MemPrealloc will allocate all the RAM upfront
|
||||||
MemPrealloc bool
|
MemPrealloc bool
|
||||||
|
|
||||||
|
// Private Memory FD meant for private memory map/unmap.
|
||||||
|
MemFDPrivate bool
|
||||||
|
|
||||||
// FileBackedMem requires Memory.Size and Memory.Path of the VM to
|
// FileBackedMem requires Memory.Size and Memory.Path of the VM to
|
||||||
// be set.
|
// be set.
|
||||||
FileBackedMem bool
|
FileBackedMem bool
|
||||||
@ -2992,10 +3002,13 @@ func (config *Config) appendMemoryKnobs() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var objMemParam, numaMemParam string
|
var objMemParam, numaMemParam string
|
||||||
|
|
||||||
dimmName := "dimm1"
|
dimmName := "dimm1"
|
||||||
if config.Knobs.HugePages {
|
if config.Knobs.HugePages {
|
||||||
objMemParam = "memory-backend-file,id=" + dimmName + ",size=" + config.Memory.Size + ",mem-path=/dev/hugepages"
|
objMemParam = "memory-backend-file,id=" + dimmName + ",size=" + config.Memory.Size + ",mem-path=/dev/hugepages"
|
||||||
numaMemParam = "node,memdev=" + dimmName
|
numaMemParam = "node,memdev=" + dimmName
|
||||||
|
} else if config.Knobs.MemFDPrivate {
|
||||||
|
objMemParam = "memory-backend-memfd-private,id=" + dimmName + ",size=" + config.Memory.Size
|
||||||
} else if config.Knobs.FileBackedMem && config.Memory.Path != "" {
|
} else if config.Knobs.FileBackedMem && config.Memory.Path != "" {
|
||||||
objMemParam = "memory-backend-file,id=" + dimmName + ",size=" + config.Memory.Size + ",mem-path=" + config.Memory.Path
|
objMemParam = "memory-backend-file,id=" + dimmName + ",size=" + config.Memory.Size + ",mem-path=" + config.Memory.Path
|
||||||
numaMemParam = "node,memdev=" + dimmName
|
numaMemParam = "node,memdev=" + dimmName
|
||||||
|
@ -632,6 +632,29 @@ func TestAppendMemoryFileBackedMemPrealloc(t *testing.T) {
|
|||||||
testConfigAppend(conf, knobs, memString+" "+knobsString, t)
|
testConfigAppend(conf, knobs, memString+" "+knobsString, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppendMemoryBackedMemFdPrivate(t *testing.T) {
|
||||||
|
conf := &Config{
|
||||||
|
Memory: Memory{
|
||||||
|
Size: "1G",
|
||||||
|
Slots: 8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
memString := "-m 1G,slots=8"
|
||||||
|
testConfigAppend(conf, conf.Memory, memString, t)
|
||||||
|
|
||||||
|
knobs := Knobs{
|
||||||
|
MemFDPrivate: true,
|
||||||
|
MemShared: false,
|
||||||
|
}
|
||||||
|
objMemString := "-object memory-backend-memfd-private,id=dimm1,size=1G"
|
||||||
|
memBackendString := "-machine memory-backend=dimm1"
|
||||||
|
|
||||||
|
knobsString := objMemString + " "
|
||||||
|
knobsString += memBackendString
|
||||||
|
|
||||||
|
testConfigAppend(conf, knobs, memString+" "+knobsString, t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNoRebootKnob(t *testing.T) {
|
func TestNoRebootKnob(t *testing.T) {
|
||||||
conf := &Config{}
|
conf := &Config{}
|
||||||
|
|
||||||
|
@ -604,6 +604,23 @@ func (q *qemu) CreateVM(ctx context.Context, id string, network Network, hypervi
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if q.config.ConfidentialGuest {
|
||||||
|
// At this point we're safe to just check for the protection field
|
||||||
|
// on the hypervisor specific code, as availableGuestProtection()
|
||||||
|
// has been called earlier and we know we have the value stored.
|
||||||
|
if q.arch.getProtection() == tdxProtection {
|
||||||
|
knobs.MemFDPrivate = true
|
||||||
|
|
||||||
|
// In case Nydus or VirtioFS is used, which may become a reality
|
||||||
|
// in the future, whenever we get those hardened for TDX, those
|
||||||
|
// knobs below would be automatically set. Let's make sure we
|
||||||
|
// pre-emptively disable them, and with that we can avoid some
|
||||||
|
// headaches in the future.
|
||||||
|
knobs.FileBackedMem = false
|
||||||
|
knobs.MemShared = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
kernelPath, err := q.config.KernelAssetPath()
|
kernelPath, err := q.config.KernelAssetPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -71,6 +71,9 @@ type qemuArch interface {
|
|||||||
// memoryTopology returns the memory topology using the given amount of memoryMb and hostMemoryMb
|
// memoryTopology returns the memory topology using the given amount of memoryMb and hostMemoryMb
|
||||||
memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory
|
memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory
|
||||||
|
|
||||||
|
// protection returns platform protection
|
||||||
|
getProtection() guestProtection
|
||||||
|
|
||||||
// appendConsole appends a console to devices
|
// appendConsole appends a console to devices
|
||||||
appendConsole(ctx context.Context, devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error)
|
appendConsole(ctx context.Context, devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error)
|
||||||
|
|
||||||
@ -280,6 +283,10 @@ func (q *qemuArchBase) machine() govmmQemu.Machine {
|
|||||||
return q.qemuMachine
|
return q.qemuMachine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *qemuArchBase) getProtection() guestProtection {
|
||||||
|
return q.protection
|
||||||
|
}
|
||||||
|
|
||||||
func (q *qemuArchBase) qemuPath() string {
|
func (q *qemuArchBase) qemuPath() string {
|
||||||
return q.qemuExePath
|
return q.qemuExePath
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user