From a1578a2be872251eae422538193c4f8735b812aa Mon Sep 17 00:00:00 2001 From: wangyueliang Date: Tue, 30 Apr 2024 10:05:43 +0800 Subject: [PATCH] qemu: Refactor memory to actually use memfd and other adjustments about mem [upstream] 3f84fd0dfda148b6dcb08ee04aca53c42f991022 55658b494c83a89d2389e86750eb055cc59e417d 33107f89177a0de037533983ed5bf8cd12fbc385 860a98b126ffa95f1d5b9f96ada39ed3ff9f3a3d --- mantle/cmd/kola/qemuexec.go | 4 +-- mantle/cmd/kola/testiso.go | 3 +++ mantle/kola/tests/ignition/qemufailure.go | 2 +- mantle/platform/machine/qemu/cluster.go | 4 +-- mantle/platform/machine/qemuiso/cluster.go | 2 +- mantle/platform/metal.go | 2 +- mantle/platform/qemu.go | 29 ++++++++++++++-------- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/mantle/cmd/kola/qemuexec.go b/mantle/cmd/kola/qemuexec.go index 2e0f4c8b..6491202c 100644 --- a/mantle/cmd/kola/qemuexec.go +++ b/mantle/cmd/kola/qemuexec.go @@ -331,13 +331,13 @@ func runQemuExec(cmd *cobra.Command, args []string) error { builder.Hostname = hostname // for historical reasons, both --memory and --qemu-memory are supported if memory != 0 { - builder.Memory = memory + builder.MemoryMiB = memory } else if kola.QEMUOptions.Memory != "" { parsedMem, err := strconv.ParseInt(kola.QEMUOptions.Memory, 10, 32) if err != nil { return errors.Wrapf(err, "parsing memory option") } - builder.Memory = int(parsedMem) + builder.MemoryMiB = int(parsedMem) } else if kola.QEMUOptions.SecureExecution { builder.MemoryMiB = 4096 // SE needs at least 4GB } diff --git a/mantle/cmd/kola/testiso.go b/mantle/cmd/kola/testiso.go index 07fb53bf..6787f2c9 100644 --- a/mantle/cmd/kola/testiso.go +++ b/mantle/cmd/kola/testiso.go @@ -99,6 +99,9 @@ var ( // "iso-offline-install.4k.s390fw", "pxe-online-install.s390fw", "pxe-offline-install.s390fw", + "miniso-install.s390fw", + "miniso-install.nm.s390fw", + "miniso-install.4k.nm.s390fw", } tests_ppc64le = []string{ "iso-live-login.ppcfw", diff --git a/mantle/kola/tests/ignition/qemufailure.go b/mantle/kola/tests/ignition/qemufailure.go index 529b827c..681f2295 100644 --- a/mantle/kola/tests/ignition/qemufailure.go +++ b/mantle/kola/tests/ignition/qemufailure.go @@ -63,7 +63,7 @@ func ignitionFailure(c cluster.TestCluster) error { if err != nil { return err } - builder.Memory = 1024 + builder.MemoryMiB = 1024 builder.Firmware = kola.QEMUOptions.Firmware inst, err := builder.Exec() if err != nil { diff --git a/mantle/platform/machine/qemu/cluster.go b/mantle/platform/machine/qemu/cluster.go index 5bd2005d..874b5387 100644 --- a/mantle/platform/machine/qemu/cluster.go +++ b/mantle/platform/machine/qemu/cluster.go @@ -125,9 +125,9 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl if err != nil { return nil, errors.Wrapf(err, "parsing memory option") } - builder.Memory = int(memory) + builder.MemoryMiB = int(memory) } else if options.MinMemory != 0 { - builder.Memory = options.MinMemory + builder.MemoryMiB = options.MinMemory } else if qc.flight.opts.SecureExecution { builder.MemoryMiB = 4096 // SE needs at least 4GB } diff --git a/mantle/platform/machine/qemuiso/cluster.go b/mantle/platform/machine/qemuiso/cluster.go index a73eb3e9..b430bb35 100644 --- a/mantle/platform/machine/qemuiso/cluster.go +++ b/mantle/platform/machine/qemuiso/cluster.go @@ -112,7 +112,7 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl if err != nil { return nil, errors.Wrapf(err, "parsing memory option") } - builder.Memory = int(memory) + builder.MemoryMiB = int(memory) } if err := builder.AddIso(qc.flight.opts.IsoPath, "", qc.flight.opts.AsDisk); err != nil { diff --git a/mantle/platform/metal.go b/mantle/platform/metal.go index e758b4b4..a2c9e0d4 100644 --- a/mantle/platform/metal.go +++ b/mantle/platform/metal.go @@ -73,7 +73,7 @@ func NewMetalQemuBuilderDefault() *QemuBuilder { builder := NewQemuBuilder() // https://github.com/coreos/fedora-coreos-tracker/issues/388 // https://github.com/coreos/fedora-coreos-docs/pull/46 - builder.Memory = 4096 + builder.MemoryMiB = 4096 return builder } diff --git a/mantle/platform/qemu.go b/mantle/platform/qemu.go index d9c003d3..7ccbaad3 100644 --- a/mantle/platform/qemu.go +++ b/mantle/platform/qemu.go @@ -433,8 +433,8 @@ type QemuBuilder struct { // If set, use QEMU full emulation for the target architecture architecture string - // Memory defaults to 1024 on most architectures, others it may be 2048 - Memory int + // MemoryMiB defaults to 1024 on most architectures, others it may be 2048 + MemoryMiB int // Processors < 0 means to use host count, unset means 1, values > 1 are directly used Processors int UUID string @@ -1245,7 +1245,7 @@ func (builder *QemuBuilder) finalize() { if builder.finalized { return } - if builder.Memory == 0 { + if builder.MemoryMiB == 0 { // FIXME; Required memory should really be a property of the tests, and // let's try to drop these arch-specific overrides. ARM was bumped via // commit 09391907c0b25726374004669fa6c2b161e3892f @@ -1263,7 +1263,7 @@ func (builder *QemuBuilder) finalize() { case "aarch64", "s390x", "ppc64le": memory = 2048 } - builder.Memory = memory + builder.MemoryMiB = memory } builder.finalized = true } @@ -1275,30 +1275,36 @@ func (builder *QemuBuilder) Append(args ...string) { // baseQemuArgs takes a board and returns the basic qemu // arguments needed for the current architecture. -func baseQemuArgs(arch string) ([]string, error) { - accel := "accel=kvm" +func baseQemuArgs(arch string, memoryMiB int) ([]string, error) { + // memoryDevice is the object identifier we use for the backing RAM + const memoryDevice = "mem" + kvm := true hostArch := coreosarch.CurrentRpmArch() + // The machine argument needs to reference our memory device; see below + machineArg := "memory-backend=" + memoryDevice + accel := "accel=kvm" if _, ok := os.LookupEnv("COSA_NO_KVM"); ok || hostArch != arch { accel = "accel=tcg" kvm = false } + machineArg += "," + accel var ret []string switch arch { case "x86_64": ret = []string{ "qemu-system-x86_64", - "-machine", accel, + "-machine", machineArg, } case "aarch64": ret = []string{ "qemu-system-aarch64", - "-machine", "virt,gic-version=max," + accel, + "-machine", "virt,gic-version=max," + machineArg, } case "s390x": ret = []string{ "qemu-system-s390x", - "-machine", "s390-ccw-virtio," + accel, + "-machine", "s390-ccw-virtio," + machineArg, } case "ppc64le": ret = []string{ @@ -1320,6 +1326,9 @@ func baseQemuArgs(arch string) ([]string, error) { ret = append(ret, "-cpu", "Nehalem") } } + // And define memory using a memfd (in shared mode), which is needed for virtiofs + ret = append(ret, "-object", fmt.Sprintf("memory-backend-memfd,id=%s,size=%dM,share=on", memoryDevice, memoryMiB)) + ret = append(ret, "-m", fmt.Sprintf("%d", memoryMiB)) return ret, nil } @@ -1581,7 +1590,7 @@ func (builder *QemuBuilder) Exec() (*QemuInstance, error) { } }() - argv, err := baseQemuArgs(builder.architecture) + argv, err := baseQemuArgs(builder.architecture, builder.MemoryMiB) if err != nil { return nil, err } -- Gitee