qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 1/2] hostmem: use a static size for maxnode, validate poli


From: David Hildenbrand
Subject: Re: [PATCH v1 1/2] hostmem: use a static size for maxnode, validate policy everywhere
Date: Tue, 7 Dec 2021 09:31:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

On 07.12.21 08:06, Daniil Tatianin wrote:
> Previously we would calculate the last set bit in the mask, and add
> 2 to that value to get the maxnode value. This is unnecessary since
> the mbind syscall allows the bitmap to be any (reasonable) size as
> long as all the unused bits are clear. This also adds policy validation
> in multiple places so that it's guaranteed to be valid when we call
> mbind.
> 
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
>  backends/hostmem.c | 64 +++++++++++++++++++++++++++++++---------------
>  1 file changed, 43 insertions(+), 21 deletions(-)
> 
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 4c05862ed5..392026efe6 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -38,6 +38,29 @@ host_memory_backend_get_name(HostMemoryBackend *backend)
>      return object_get_canonical_path(OBJECT(backend));
>  }
>  
> +static bool
> +validate_policy(HostMemPolicy policy, bool nodes_empty, Error **errp)
> +{
> +    /*
> +     * check for invalid host-nodes and policies and give more verbose
> +     * error messages than mbind().
> +     */
> +    if (!nodes_empty && 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 false;
> +    }
> +
> +    if (nodes_empty && policy != MPOL_DEFAULT) {
> +        error_setg(errp, "host-nodes must be set for policy %s",
> +                   HostMemPolicy_str(policy));
> +        return false;
> +    }
> +
> +    return true;
> +}

Hm, we set two properties individually but bail out when the current 
combination 
is impossible, which is nasty. It means we have modify properties in the right 
order
(which will differ based on the policy) to make a change.

Do we have any sane use case of modifying the policy/host-nodes at runtime?
I mean, it's just completely wrong when we already have any memory
preallocated/touched inside the range, as we won't issue another mbind call.

I suggest instead to fix this hole:

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 4c05862ed5..7edc3a075e 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -111,6 +111,11 @@ host_memory_backend_set_host_nodes(Object *obj, Visitor 
*v, const char *name,
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
     uint16List *l, *host_nodes = NULL;
 
+    if (host_memory_backend_mr_inited(backend)) {
+        error_setg(errp, "Property 'host-nodes' cannot be changed anymore.");
+        return;
+    }
+
     visit_type_uint16List(v, name, &host_nodes, errp);
 
     for (l = host_nodes; l; l = l->next) {
@@ -142,6 +147,12 @@ static void
 host_memory_backend_set_policy(Object *obj, int policy, Error **errp)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (host_memory_backend_mr_inited(backend)) {
+        error_setg(errp, "Property 'policy' cannot be changed anymore.");
+        return;
+    }
+
     backend->policy = policy;
 
 #ifndef CONFIG_NUMA


-- 
Thanks,

David / dhildenb




reply via email to

[Prev in Thread] Current Thread [Next in Thread]