aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2024-01-05 16:08:58 +0000
committerPeter Maydell <peter.maydell@linaro.org>2024-01-05 16:08:58 +0000
commit0c1eccd368af8805ec0fb11e6cf25d0684d37328 (patch)
tree09ab2fae2789e2674d8f8ca979521a62d8654538 /backends
parentc8193acc078e297fd46b6229e02b819b65c6702e (diff)
parenta318da6b3f6a88e6cfd6953c519def9457e8962f (diff)
Merge tag 'hw-cpus-20240105' of https://github.com/philmd/qemu into staging
HW core patch queue - Unify CPU QOM type checks (Gavin) - Simplify uses of some CPU related property (Philippe) (start-powered-off, ARM reset-cbar and mp-affinity) - Header and documentation cleanups (Zhao, Philippe) - Have Memory API return boolean indicating possible error - Fix frame filter mask in CAN sja1000 model (Pavel) - QOM embed MCF5206 timer into SoC (Thomas) - Simplify LEON3 qemu_irq_ack handler (Clément) # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAmWYIxwACgkQ4+MsLN6t # wN66fA//UBwgYqcdpg6Wz17qzgq1TWeZHHzYh7HbZRUCxhdSgS6TSQOH9Fi8VNYq # Ed5a5l4ovP/2NRN1/S5PPBydyKXTU7wintHm2+suQbLSmplIE6yr0Ca6o8FLEeJ3 # hnE0dAoQCLS7eDpoeOEpGjzmJFiBSWLvyqAZLa/rZkCnCiZRHB6g/nAEM8I3I9bl # //H20d3a/fektZxGnpEAeoMxrl4iA9hkFYVW8lbu6EhNFBPUkkj5Y8w47Kq/BIvD # NmLTPgu4d7oahwlfsM6jWdRDG9zlEkXQor817PHwl00o45yAfeITsy40GvJeEYaI # BcDLFfWrSm9SQb7/suXGeyU/SLmx7rsmJWfNYUoMr6807QcSH4ScPCfgzEQ4j8IV # PmeVsxxLxT9CSzfxhMx5cXt33H2l+tEzwJ5UJCLQvmvTu+aDkt46Q09X/7j0z89m # zSk/HBtdACIzwEWBAJsKuzarRTZNUvyXEsOxZ5l7xOxJpzpsNV2YVuChClVGtHOJ # kr1PE2hxEMPY1vDyKU6ckDvW+XXgYhOXrPAxdx8gIwwd4oyDC5vVlIajvlqbOAsp # Es7zq40b/is3ZnByEDbZ+yYvdYRLtVf/lDPK3KIv7IhrTNzH/HT1egshOQAVirY1 # Gw8f3fXqL3/84w383VI4efrSlKBJeb0i2SJ50y2N1clrF1qnlx0= # =an4B # -----END PGP SIGNATURE----- # gpg: Signature made Fri 05 Jan 2024 15:41:16 GMT # gpg: using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * tag 'hw-cpus-20240105' of https://github.com/philmd/qemu: (71 commits) target/sparc: Simplify qemu_irq_ack hw/net/can/sja1000: fix bug for single acceptance filter and standard frame hw/m68k/mcf5206: Embed m5206_timer_state in m5206_mbar_state hw/pci-host/raven: Propagate error in raven_realize() hw/nvram: Simplify memory_region_init_rom_device() calls hw/misc: Simplify memory_region_init_ram_from_fd() calls hw/sparc: Simplify memory_region_init_ram_nomigrate() calls hw/arm: Simplify memory_region_init_rom() calls hw: Simplify memory_region_init_ram() calls misc: Simplify qemu_prealloc_mem() calls util/oslib: Have qemu_prealloc_mem() handler return a boolean backends: Reduce variable scope in host_memory_backend_memory_complete backends: Have HostMemoryBackendClass::alloc() handler return a boolean backends: Simplify host_memory_backend_memory_complete() backends: Use g_autofree in HostMemoryBackendClass::alloc() handlers memory: Have memory_region_init_ram_from_fd() handler return a boolean memory: Have memory_region_init_ram_from_file() handler return a boolean memory: Have memory_region_init_resizeable_ram() return a boolean memory: Have memory_region_init_rom_device() handler return a boolean memory: Simplify memory_region_init_rom_device_nomigrate() calls ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'backends')
-rw-r--r--backends/hostmem-epc.c14
-rw-r--r--backends/hostmem-file.c22
-rw-r--r--backends/hostmem-memfd.c13
-rw-r--r--backends/hostmem-ram.c12
-rw-r--r--backends/hostmem.c144
5 files changed, 97 insertions, 108 deletions
diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c
index 4e162d6789..735e2e1cf8 100644
--- a/backends/hostmem-epc.c
+++ b/backends/hostmem-epc.c
@@ -17,31 +17,29 @@
#include "sysemu/hostmem.h"
#include "hw/i386/hostmem-epc.h"
-static void
+static bool
sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
+ g_autofree char *name = NULL;
uint32_t ram_flags;
- char *name;
int fd;
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
- return;
+ return false;
}
fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
if (fd < 0) {
error_setg_errno(errp, errno,
"failed to open /dev/sgx_vepc to alloc SGX EPC");
- return;
+ return false;
}
name = object_get_canonical_path(OBJECT(backend));
ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED;
- memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
- name, backend->size, ram_flags,
- fd, 0, errp);
- g_free(name);
+ return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name,
+ backend->size, ram_flags, fd, 0, errp);
}
static void sgx_epc_backend_instance_init(Object *obj)
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 361d4a8103..ac3e433cbd 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -36,24 +36,25 @@ struct HostMemoryBackendFile {
OnOffAuto rom;
};
-static void
+static bool
file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
#ifndef CONFIG_POSIX
error_setg(errp, "backend '%s' not supported on this host",
object_get_typename(OBJECT(backend)));
+ return false;
#else
HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
+ g_autofree gchar *name = NULL;
uint32_t ram_flags;
- gchar *name;
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
- return;
+ return false;
}
if (!fb->mem_path) {
error_setg(errp, "mem-path property not set");
- return;
+ return false;
}
switch (fb->rom) {
@@ -65,18 +66,18 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
if (!fb->readonly) {
error_setg(errp, "property 'rom' = 'on' is not supported with"
" 'readonly' = 'off'");
- return;
+ return false;
}
break;
case ON_OFF_AUTO_OFF:
if (fb->readonly && backend->share) {
error_setg(errp, "property 'rom' = 'off' is incompatible with"
" 'readonly' = 'on' and 'share' = 'on'");
- return;
+ return false;
}
break;
default:
- assert(false);
+ g_assert_not_reached();
}
name = host_memory_backend_get_name(backend);
@@ -86,10 +87,9 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
ram_flags |= fb->is_pmem ? RAM_PMEM : 0;
ram_flags |= RAM_NAMED_FILE;
- memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name,
- backend->size, fb->align, ram_flags,
- fb->mem_path, fb->offset, errp);
- g_free(name);
+ return memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name,
+ backend->size, fb->align, ram_flags,
+ fb->mem_path, fb->offset, errp);
#endif
}
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 3fc85c3db8..3923ea9364 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -31,17 +31,17 @@ struct HostMemoryBackendMemfd {
bool seal;
};
-static void
+static bool
memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
HostMemoryBackendMemfd *m = MEMORY_BACKEND_MEMFD(backend);
+ g_autofree char *name = NULL;
uint32_t ram_flags;
- char *name;
int fd;
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
- return;
+ return false;
}
fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size,
@@ -49,15 +49,14 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL : 0,
errp);
if (fd == -1) {
- return;
+ return false;
}
name = host_memory_backend_get_name(backend);
ram_flags = backend->share ? RAM_SHARED : 0;
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
- memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name,
- backend->size, ram_flags, fd, 0, errp);
- g_free(name);
+ return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name,
+ backend->size, ram_flags, fd, 0, errp);
}
static bool
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index b8e55cdbd0..d121249f0f 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -16,23 +16,23 @@
#include "qemu/module.h"
#include "qom/object_interfaces.h"
-static void
+static bool
ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
+ g_autofree char *name = NULL;
uint32_t ram_flags;
- char *name;
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
- return;
+ return false;
}
name = host_memory_backend_get_name(backend);
ram_flags = backend->share ? RAM_SHARED : 0;
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
- memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), name,
- backend->size, ram_flags, errp);
- g_free(name);
+ return memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend),
+ name, backend->size,
+ ram_flags, errp);
}
static void
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 747e7838c0..30f69b2cb5 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -219,7 +219,6 @@ static bool host_memory_backend_get_prealloc(Object *obj, Error **errp)
static void host_memory_backend_set_prealloc(Object *obj, bool value,
Error **errp)
{
- Error *local_err = NULL;
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
if (!backend->reserve && value) {
@@ -237,10 +236,8 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
void *ptr = memory_region_get_ram_ptr(&backend->mr);
uint64_t sz = memory_region_size(&backend->mr);
- qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
- backend->prealloc_context, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (!qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
+ backend->prealloc_context, errp)) {
return;
}
backend->prealloc = true;
@@ -324,91 +321,86 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
{
HostMemoryBackend *backend = MEMORY_BACKEND(uc);
HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
- Error *local_err = NULL;
void *ptr;
uint64_t sz;
- if (bc->alloc) {
- bc->alloc(backend, &local_err);
- if (local_err) {
- goto out;
- }
+ if (!bc->alloc) {
+ return;
+ }
+ if (!bc->alloc(backend, errp)) {
+ return;
+ }
- ptr = memory_region_get_ram_ptr(&backend->mr);
- sz = memory_region_size(&backend->mr);
+ ptr = memory_region_get_ram_ptr(&backend->mr);
+ sz = memory_region_size(&backend->mr);
- if (backend->merge) {
- qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE);
- }
- if (!backend->dump) {
- qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
- }
+ if (backend->merge) {
+ qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE);
+ }
+ if (!backend->dump) {
+ qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
+ }
#ifdef CONFIG_NUMA
- unsigned long lastbit = find_last_bit(backend->host_nodes, MAX_NODES);
- /* lastbit == MAX_NODES means maxnode = 0 */
- unsigned long maxnode = (lastbit + 1) % (MAX_NODES + 1);
- /* ensure policy won't be ignored in case memory is preallocated
- * before mbind(). note: MPOL_MF_STRICT is ignored on hugepages so
- * this doesn't catch hugepage case. */
- unsigned flags = MPOL_MF_STRICT | MPOL_MF_MOVE;
- int mode = backend->policy;
-
- /* check for invalid host-nodes and policies and give more verbose
- * error messages than mbind(). */
- if (maxnode && backend->policy == MPOL_DEFAULT) {
- error_setg(errp, "host-nodes must be empty for policy default,"
- " or you should explicitly specify a policy other"
- " than default");
- return;
- } else if (maxnode == 0 && backend->policy != MPOL_DEFAULT) {
- error_setg(errp, "host-nodes must be set for policy %s",
- HostMemPolicy_str(backend->policy));
- return;
- }
+ unsigned long lastbit = find_last_bit(backend->host_nodes, MAX_NODES);
+ /* lastbit == MAX_NODES means maxnode = 0 */
+ unsigned long maxnode = (lastbit + 1) % (MAX_NODES + 1);
+ /* ensure policy won't be ignored in case memory is preallocated
+ * before mbind(). note: MPOL_MF_STRICT is ignored on hugepages so
+ * this doesn't catch hugepage case. */
+ unsigned flags = MPOL_MF_STRICT | MPOL_MF_MOVE;
+ int mode = backend->policy;
+
+ /* check for invalid host-nodes and policies and give more verbose
+ * error messages than mbind(). */
+ if (maxnode && backend->policy == MPOL_DEFAULT) {
+ error_setg(errp, "host-nodes must be empty for policy default,"
+ " or you should explicitly specify a policy other"
+ " than default");
+ return;
+ } else if (maxnode == 0 && backend->policy != MPOL_DEFAULT) {
+ error_setg(errp, "host-nodes must be set for policy %s",
+ HostMemPolicy_str(backend->policy));
+ return;
+ }
- /* We can have up to MAX_NODES nodes, but we need to pass maxnode+1
- * as argument to mbind() due to an old Linux bug (feature?) which
- * cuts off the last specified node. This means backend->host_nodes
- * must have MAX_NODES+1 bits available.
- */
- assert(sizeof(backend->host_nodes) >=
- BITS_TO_LONGS(MAX_NODES + 1) * sizeof(unsigned long));
- assert(maxnode <= MAX_NODES);
+ /* We can have up to MAX_NODES nodes, but we need to pass maxnode+1
+ * as argument to mbind() due to an old Linux bug (feature?) which
+ * cuts off the last specified node. This means backend->host_nodes
+ * must have MAX_NODES+1 bits available.
+ */
+ assert(sizeof(backend->host_nodes) >=
+ BITS_TO_LONGS(MAX_NODES + 1) * sizeof(unsigned long));
+ assert(maxnode <= MAX_NODES);
#ifdef HAVE_NUMA_HAS_PREFERRED_MANY
- if (mode == MPOL_PREFERRED && numa_has_preferred_many() > 0) {
- /*
- * Replace with MPOL_PREFERRED_MANY otherwise the mbind() below
- * silently picks the first node.
- */
- mode = MPOL_PREFERRED_MANY;
- }
+ if (mode == MPOL_PREFERRED && numa_has_preferred_many() > 0) {
+ /*
+ * Replace with MPOL_PREFERRED_MANY otherwise the mbind() below
+ * silently picks the first node.
+ */
+ mode = MPOL_PREFERRED_MANY;
+ }
#endif
- if (maxnode &&
- mbind(ptr, sz, mode, backend->host_nodes, maxnode + 1, flags)) {
- if (backend->policy != MPOL_DEFAULT || errno != ENOSYS) {
- error_setg_errno(errp, errno,
- "cannot bind memory to host NUMA nodes");
- return;
- }
+ if (maxnode &&
+ mbind(ptr, sz, mode, backend->host_nodes, maxnode + 1, flags)) {
+ if (backend->policy != MPOL_DEFAULT || errno != ENOSYS) {
+ error_setg_errno(errp, errno,
+ "cannot bind memory to host NUMA nodes");
+ return;
}
+ }
#endif
- /* Preallocate memory after the NUMA policy has been instantiated.
- * This is necessary to guarantee memory is allocated with
- * specified NUMA policy in place.
- */
- if (backend->prealloc) {
- qemu_prealloc_mem(memory_region_get_fd(&backend->mr), ptr, sz,
- backend->prealloc_threads,
- backend->prealloc_context, &local_err);
- if (local_err) {
- goto out;
- }
- }
+ /* Preallocate memory after the NUMA policy has been instantiated.
+ * This is necessary to guarantee memory is allocated with
+ * specified NUMA policy in place.
+ */
+ if (backend->prealloc && !qemu_prealloc_mem(memory_region_get_fd(&backend->mr),
+ ptr, sz,
+ backend->prealloc_threads,
+ backend->prealloc_context, errp)) {
+ return;
}
-out:
- error_propagate(errp, local_err);
}
static bool