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

[PATCH v8 6/8] libxc: add xc_domain_set_memory_claims()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
  • From: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
  • Date: Tue, 01 Dec 2026 18:29:46 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f34UU+zAn43Oa7qp354ZgTy42S0hwTh3k6EY0XK3594=; b=sIfZnQDazB91mzAPONFMjjKGv3MkCJaYe90TLXuXZ7lXmGLrNtrjaACJ6CGt0e63Bj75eCS+8Cdzof0CKiEO7XMhKVVqDuQQU8b2mGa3Ad7R2vbbbIFkgbDl1Y4rs6HFJ2C2gSv9CQ1B1I8Dfttb+e8R8sqoPZiRFrKfke7SviUq1sLHIix+vGpaEF5GhkXbOMn+jxhgQFSYKQrFCQ7nBLcYDU+EaIk1a4YLl1jVQQNhChuG0mIaPIS0MJkoT5Ez+v1k2xgl7oy2Naa9i21E4SLflj312SYSJIMi6hZq4um3azeOKe8LzqT0yjUW556rMpjSI9rippGlDB/uwKJ8cA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jRSQVvhAH9HSDUCfdibqjrYQx+2HvGLUuUeCGNU5M6UDcFijGzRNr0FGshCBWu8zpSpALgX+NpKITbsc/Gg5pVzYxrTucWe23Ei+YcSKsIPqixPBRxzyhOLlmjPHTrzsabzsscMwHB1kYnLK/f4fOuvpP9y7IYOq2ZQOvJq4hDQ9Kl7MDbTYj7G/ya1BnxnJmZL/z6SSBaBiQ2AJ4RyrnzyiAdnnpjHlF67uqLJF9i1oPDr1Qat+fpz6s6eCiFs4Hi4AyZT4hgSDyn1WmYk9zOF34mRSdOZ1yunPbTQlPQdxifjmzzObYBKFZkpvTRq4k1R0cxM6huKPSd7pUu/sSw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Community Manager <community.manager@xxxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Bernhard Kaindl <contact@xxxxxxxxxxxxxxxxxxx>, Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
  • Delivery-date: Tue, 01 Dec 2026 17:30:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add xc_domain_set_memory_claims() as the libxc wrapper for
XEN_DOMCTL_set_memory_claims.

Passing NULL for claims and zero for nr_claims releases
all claims without allocating an array buffer.

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.
- Split the get/set operations into dedicated code paths.
- Rename the operation to XEN_DOMCTL_set_memory_claims.
- Rename the wrapper to xc_domain_set_memory_claims().
- Drop the mode argument. This dedicated set wrapper uses
  DECLARE_HYPERCALL_BOUNCE_IN() because the array is input-only.
- Rename the arguments, pass the array before its count, add const
  where appropriate, and improve the documentation.
- Add a CHANGELOG.md entry for per-node NUMA memory claims, listing
  XEN_DOMCTL_set_memory_claims/xc_domain_set_memory_claims().
---
 tools/include/xenctrl.h     | 10 ++++++++++
 tools/libs/ctrl/xc_domain.c | 24 ++++++++++++++++++++++++
 CHANGELOG.md                |  4 ++++
 3 files changed, 38 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 6f4ea7ca62..f2ce836c9c 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2670,6 +2670,16 @@ int xc_domain_set_llc_colors(xc_interface *xch, uint32_t 
domid,
                              const uint32_t *llc_colors,
                              uint32_t num_llc_colors);
 
+/*
+ * Atomically set a domain's host-wide and per-node memory claims before
+ * its creation finishes. The domain must have no outstanding claims.
+ * Each array entry reserves pages on one NUMA node or host-wide.
+ * Pass NULL for claims and zero for nr_claims to release all claims.
+ */
+int xc_domain_set_memory_claims(xc_interface *xch, uint32_t domid,
+                                const xen_domctl_memory_claim_t *claims,
+                                uint32_t nr_claims);
+
 #if defined(__arm__) || defined(__aarch64__)
 int xc_dt_overlay(xc_interface *xch, void *overlay_fdt,
                   uint32_t overlay_fdt_size, uint8_t overlay_op);
diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c
index 94cfab0fa1..35143d00db 100644
--- a/tools/libs/ctrl/xc_domain.c
+++ b/tools/libs/ctrl/xc_domain.c
@@ -2222,6 +2222,30 @@ out:
 
     return ret;
 }
+
+int xc_domain_set_memory_claims(xc_interface *xch, uint32_t domid,
+                                const xen_domctl_memory_claim_t *claims,
+                                uint32_t nr_claims)
+{
+    struct xen_domctl domctl = {};
+    DECLARE_HYPERCALL_BOUNCE_IN(claims, sizeof(*claims) * nr_claims);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, claims) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_set_memory_claims;
+    domctl.domain = domid;
+    domctl.u.memory_claims.nr_claims = nr_claims;
+    set_xen_guest_handle(domctl.u.memory_claims.claims, claims);
+
+    ret = do_domctl(xch, &domctl);
+
+    xc_hypercall_bounce_post(xch, claims);
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f967437eda..64c0f87062 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,10 @@ The format is based on [Keep a 
Changelog](https://keepachangelog.com/en/1.0.0/)
      afterwards.
 
 ### Added
+ - Support for per-node NUMA memory claims, so toolstacks can reserve memory
+   on selected NUMA nodes while building a domain:
+   - XEN_DOMCTL_set_memory_claims/xc_domain_set_memory_claims() atomically
+     sets a domain's host-wide claim and per-node claims.
 
 ### Removed
  - On Arm:

-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.