|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 5/8] xen/domctl: add XEN_DOMCTL_set_memory_claims
Introduce XEN_DOMCTL_set_memory_claims to pass claim requests to domain_set_claims(): - Reuse FLASK's existing setclaim permission through flask_domctl(). - Reject new claim requests after domain creation has finished. - Reject new claims with a separate Xenheap or LLC coloring: - the admission counters would include Xen-only pages, and - the colored allocator does not redeem claims. The domctl lock serializes installation with domain destruction. An empty request to release outstanding claims is routed to domain_set_outstanding_pages(d, 0). Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Assisted-by: Vibe:Mistral-Medium-3.5, Copilot:claude-opus-5-5 # review Assisted-by: Copilot:gpt-6.2-astra, Copilot:gpt-6.2-sol # review Signed-off-by: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx> --- v8: - Refactor the submission into smaller topic-focused patches. - Document the operation's failure modes by error code. - Adapt to the domctl changes in Xen 4.22: check the setclaim permission in flask_domctl() instead of calling xsm_claim_pages(). - Rename the operation from XEN_DOMCTL_claim_memory to XEN_DOMCTL_set_memory_claims. - Rename the fields claim_set and nr_entries to claims and nr_claims. - Allow release before the lifecycle and LLC-coloring checks; reject nonzero padding for both installation and release. - Use domain_set_outstanding_pages(d, 0) to release all claims. - Use xvmalloc_array() because the buffer need not be physically contiguous. - Reject new claims with a separate Xenheap builds: The counters would include Xen-only pages, so claim protection would not work. - Reject installation after domain creation finishes and document the domain builder's serialization requirement. - Roger suggested restricting claims to domain build: https://lore.kernel.org/xen-devel/Z9BZ-V8fWHOAwMJ7@macbook.local/ Afterwards, return -EEXIST as XEN_DOMCTL_set_cpu_policy does. --- xen/include/public/domctl.h | 48 +++++++++++++++++++++++++++++++++++++ xen/xsm/flask/policy/access_vectors | 2 +- xen/xsm/flask/hooks.c | 3 +++ xen/common/domctl.c | 44 ++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 163e246ff4..76d6b81687 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1279,6 +1279,7 @@ struct xen_domctl_get_domain_state { uint64_t unique_id; /* Unique domain identifier. */ }; +/* XEN_DOMCTL_set_memory_claims */ /* * Special target for a host-wide claim, not associated with a NUMA node. * Other values with bit 31 set are reserved for future special targets. @@ -1291,6 +1292,51 @@ typedef struct xen_domctl_memory_claim { uint32_t target; /* NUMA node or special target constant. */ uint32_t pad; /* Must be zero. */ } xen_domctl_memory_claim_t; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_memory_claim_t); + +/* + * XEN_DOMCTL_set_memory_claims + * + * The purpose of this domctl is to allow a domain builder to reserve + * memory on the host and the NUMA nodes where the domain will be placed + * before starting to populate the physmap of a new domain. + * + * The domain builder must serialize claim installation with allocations + * for the domain, including completion of any allocation continuation. + * + * Each claim reserves pages either on one online NUMA node or host-wide. + * Targets must be unique, and each claim must be for at least one page. + * New claims can only be set while the domain has no outstanding claims + * and domain creation is not yet complete. At installation, the sum of + * allocated and requested pages must not exceed the domain's page limit. + * An empty array releases all outstanding claims. The domain builder + * should release unused claims before completing domain creation. + * + * Ref-counted buddy allocations consume claims: first the domain's claim + * on the allocation node, then its host-wide claim, and then its claims + * on other nodes. + * + * XEN_DOMCTL_set_memory_claims fails without changing the claims with: + * EOPNOTSUPP - non-empty request with separate Xen heap or LLC coloring + * E2BIG - nr_claims is above the maximum number of nodes plus one + * for the host-wide claim + * ESRCH - the domain does not exist, or claims were requested for + * an already dying domain + * EEXIST - claims requested for a domain whose creation is finished + * EFAULT - the claims array cannot be read from the guest + * ENOENT - a request targets a node that does not exist or is offline + * EINVAL - pad not zero, duplicate or reserved target, claims for + * zero pages, claims plus allocated pages above the maximum + * of the domain, or the domain already has outstanding claims + * ENOMEM - allocation failure or not enough unclaimed memory, + * in total or on a node + */ +struct xen_domctl_memory_claims { + /* IN: array of claims. */ + XEN_GUEST_HANDLE_64(xen_domctl_memory_claim_t) claims; + uint32_t nr_claims; /* IN: number of claims. */ + uint32_t pad; /* IN: Must be zero. */ +}; struct xen_domctl { /* Stable domctl ops: interface_version is required to be 0. */ @@ -1384,6 +1430,7 @@ struct xen_domctl { #define XEN_DOMCTL_gsi_permission 88 #define XEN_DOMCTL_set_llc_colors 89 #define XEN_DOMCTL_get_domain_state 90 /* stable interface */ +#define XEN_DOMCTL_set_memory_claims 91 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1452,6 +1499,7 @@ struct xen_domctl { #endif struct xen_domctl_set_llc_colors set_llc_colors; struct xen_domctl_get_domain_state get_domain_state; + struct xen_domctl_memory_claims memory_claims; uint8_t pad[128]; } u; }; diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors index bbb9c117ec..0658853f23 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -215,7 +215,7 @@ class domain2 settsc # XEN_DOMCTL_scheduler_op with XEN_DOMCTL_SCHEDOP_putinfo setscheduler -# XENMEM_claim_pages +# XENMEM_claim_pages, XEN_DOMCTL_set_memory_claims setclaim # XEN_DOMCTL_cacheflush cacheflush diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index d65ba0aeae..f9b6eab109 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -881,6 +881,9 @@ static int cf_check flask_domctl(struct domain *d, struct xen_domctl *op) case XEN_DOMCTL_set_llc_colors: return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_LLC_COLORS); + case XEN_DOMCTL_set_memory_claims: + return flask_claim_pages(d); + default: return avc_unknown_permission("domctl", op->cmd); } diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 83405a766a..55906bd301 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -51,6 +51,46 @@ static int xenctl_bitmap_to_nodemask(nodemask_t *nodemask, MAX_NUMNODES); } +static int set_memory_claims(struct domain *d, + const struct xen_domctl_memory_claims *op) +{ + struct claim_request request = { .nr_entries = op->nr_claims }; + int ret; + + if ( op->pad ) + return -EINVAL; + + /* Releasing is harmless in any domain state. */ + if ( !op->nr_claims ) + return domain_set_outstanding_pages(d, 0); + + if ( IS_ENABLED(CONFIG_SEPARATE_XENHEAP) || llc_coloring_enabled ) + return -EOPNOTSUPP; + + if ( d->is_dying ) + return -ESRCH; + + /* Allow one claim for every node plus one host-wide claim. */ + if ( op->nr_claims > MAX_NUMNODES + 1U ) + return -E2BIG; + + if ( d->creation_finished ) + return -EEXIST; + + request.entries = xvmalloc_array(struct xen_domctl_memory_claim, + request.nr_entries); + if ( !request.entries ) + return -ENOMEM; + + if ( copy_from_guest(request.entries, op->claims, request.nr_entries) ) + ret = -EFAULT; + else + ret = domain_set_claims(d, &request); + + xvfree(request.entries); + return ret; +} + void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info) { struct vcpu *v; @@ -853,6 +893,10 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) break; } + case XEN_DOMCTL_set_memory_claims: + ret = set_memory_claims(d, &op->u.memory_claims); + break; + case XEN_DOMCTL_setdomainhandle: memcpy(d->handle, op->u.setdomainhandle.handle, sizeof(xen_domain_handle_t)); -- 2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |