Skip to content

Commit

Permalink
runtime: Allow no initrd path for IBM Z Secure Execution
Browse files Browse the repository at this point in the history
This is to reintroduce a configuration rule for IBM Z Secure Execution,
where no initrd path should be configured. For the TEE of interest,
only a kernel image should be specified with `confidential_guest=true`.

Fixes: #8692

Signed-off-by: Hyounggyu Choi <Hyounggyu.Choi@ibm.com>
  • Loading branch information
BbolroC committed Dec 18, 2023
1 parent 0f80dc6 commit 5904d34
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/runtime/pkg/govmm/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2999,14 +2999,18 @@ func (config *Config) appendVGA() {
}
}

func (config *Config) appendKernel() {
func (config *Config) appendKernel(logger QMPLog) {
if config.Kernel.Path != "" {
config.qemuParams = append(config.qemuParams, "-kernel")
config.qemuParams = append(config.qemuParams, config.Kernel.Path)

if config.Kernel.InitrdPath != "" {
config.qemuParams = append(config.qemuParams, "-initrd")
config.qemuParams = append(config.qemuParams, config.Kernel.InitrdPath)
} else {
if logger != nil {
logger.Infof("initrd path is empty, assuming IBM Z Secure Execution")
}
}

if config.Kernel.Params != "" {
Expand Down Expand Up @@ -3163,7 +3167,7 @@ func LaunchQemu(config Config, logger QMPLog) (*exec.Cmd, io.ReadCloser, error)
config.appendPFlashParam()
config.appendVGA()
config.appendKnobs()
config.appendKernel()
config.appendKernel(logger)
config.appendBios()
config.appendIOThreads()
config.appendIncoming()
Expand Down
16 changes: 13 additions & 3 deletions src/runtime/pkg/govmm/qemu/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func testConfigAppend(config *Config, structure interface{}, expected string, t

case Kernel:
config.Kernel = s
config.appendKernel()
config.appendKernel(nil)

case Memory:
config.Memory = s
Expand Down Expand Up @@ -668,7 +668,7 @@ func TestNoRebootKnob(t *testing.T) {

var kernelString = "-kernel /opt/vmlinux.container -initrd /opt/initrd.container -append root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable"

func TestAppendKernel(t *testing.T) {
func TestAppendKernelWithInitrd(t *testing.T) {
kernel := Kernel{
Path: "/opt/vmlinux.container",
InitrdPath: "/opt/initrd.container",
Expand All @@ -678,6 +678,16 @@ func TestAppendKernel(t *testing.T) {
testAppend(kernel, kernelString, t)
}

func TestAppendKernelWithoutInitrd(t *testing.T) {
kernel := Kernel{
Path: "/opt/vmlinux.container",
InitrdPath: "",
Params: "root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable",
}

testAppend(kernel, kernelString, t)
}

var memoryString = "-m 2G,slots=2,maxmem=3G"

func TestAppendMemory(t *testing.T) {
Expand Down Expand Up @@ -1077,7 +1087,7 @@ func TestBadVGA(t *testing.T) {

func TestBadKernel(t *testing.T) {
c := &Config{}
c.appendKernel()
c.appendKernel(nil)
if len(c.qemuParams) != 0 {
t.Errorf("Expected empty qemuParams, found %s", c.qemuParams)
}
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ func (conf *HypervisorConfig) ImageOrInitrdAssetPath() (string, types.AssetType,
initrd = a.Path()
}

if conf.ConfidentialGuest && conf.HypervisorMachineType == QemuCCWVirtio {
return "", types.SecureBootAsset, nil
}

path, assetType, err := checkAndReturn(image, initrd)
if assetType != types.UnkownAsset {
return path, assetType, nil
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,13 @@ func (q *qemu) buildDevices(ctx context.Context, kernelPath string) ([]govmmQemu
if err != nil {
return nil, nil, nil, err
}
} else {
} else if assetType == types.InitrdAsset {
// InitrdAsset, need to set kernel initrd path
kernel.InitrdPath = assetPath
} else if assetType == types.SecureBootAsset {
// SecureBootAsset, no need to set image or initrd path
q.Logger().Info("Neither image nor initrd is set, secure boot for IBM Z is enabled")
kernel.InitrdPath = ""
}

if q.config.IOMMU {
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/virtcontainers/types/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const (
// InitrdAsset is an initrd asset.
InitrdAsset AssetType = "initrd"

// SecureBootAsset is a secure boot asset.
// (IBM Z Secure Execution only)
SecureBootAsset AssetType = "secure_boot"

// HypervisorAsset is an hypervisor asset.
HypervisorAsset AssetType = "hypervisor"

Expand Down

0 comments on commit 5904d34

Please sign in to comment.