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

[PATCH v8 8/8] libxc: add xc_domain_get_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:48 +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=vr27EYwUretTM/Dq+PyfAOGCISVwP5n1Gf77dWn0KhU=; b=H1jMqkN9PhcSFBVoQDmnk0jxw/dv0cLGGiM+soD/YnarE8cAJTynewjfdCOGGRL8RHRY+LEWF8xTvpEnNfSqDne3UMBwTzsVxTePOF3NuVNETIxJlvIAwF6fQxml00udgqVNoavBAqwA7jl+C3WaVa4KayPy/SMsMdVxRDrthKQAzQwWr0LVfAZalQbBIRJG9AUFRPvmImWjA3XCPI6eiNZXdnugY/ixtv/y5sZTx9F4QWrB4PpPkJQNdMy+W9CrjqMVqOaZoLBj/95wn2SGq/SEG4Ku+eYpHQadYE20mh8ZmZ0ne8jXz3BEEyED8NZwStsjWBkFKTMpsTiJgorwww==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qlt2TSLRxxhHLJGwH3yhLtiAwfAo/mky+JAkebiP+CX1kQIw8oFQVLvm42HOiM6+fCQ5H1oXK30K8vsmU5uDeZgf6JmzJb2sxtA+h1iIDxvg0TTlpNLGs3I8rre2/2e7Ndc7WD0VVzoLBaEYruyE4lf2D1rT4CANSuQFxDjfExZWDHwuPigvGiHKHkVgkmcqI6hz9lcKuYZzu+UT7WpkreXOsamikuZ2Hq3DZ4qUVQLpLDkZGBtDFhOqzjQNy/ciwoK/aHbjNE8Hmt+YkefXSImlYIwCctgT7fI4TIPGnuBpAsGCauKsGbgl+gjnsHSO428O0M7oOHTRnc865kM40w==
  • 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:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add xc_domain_get_memory_claims() with *nr_claims as the
array capacity on input and the entry count on output.

- Use an output-only bounce buffer, copying back only the
  returned entries on success and nothing on failure.

- This leaves unused array capacity untouched and preserves
  the caller's claims array on failure.

- If capacity is insufficient, fail with errno set to ENOBUFS
  and update *nr_claims to the required count without modifying
  the claims array.

- Pass NULL for claims and set *nr_claims to zero to query the
  count.

- Add the query interfaces to the memory-claims changelog entry.

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 and rename the wrapper to xc_domain_get_memory_claims().
- Use the new domctl operation XEN_DOMCTL_get_memory_claims.
- For consistency across the wrappers and claim path, rename
  the function arguments and pass the array before its count.
- Drop the mode argument. This dedicated get wrapper uses
  XC_HYPERCALL_BUFFER_BOUNCE_OUT because the array is output-only.
- Copy back only the entries returned by Xen.
- Add XEN_DOMCTL_get_memory_claims/xc_domain_get_memory_claims()
  to CHANGELOG.md.
---
 tools/include/xenctrl.h     | 12 ++++++++++++
 tools/libs/ctrl/xc_domain.c | 27 +++++++++++++++++++++++++++
 CHANGELOG.md                |  1 +
 3 files changed, 40 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index f2ce836c9c..94ba904de8 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2680,6 +2680,18 @@ int xc_domain_set_memory_claims(xc_interface *xch, 
uint32_t domid,
                                 const xen_domctl_memory_claim_t *claims,
                                 uint32_t nr_claims);
 
+/*
+ * Get the memory claims of a domain.
+ * *nr_claims is the array capacity on input and the number of entries
+ * returned on success. If the capacity is too small, fail with errno set
+ * to ENOBUFS, set *nr_claims to the required size in entries, and leave the
+ * array unchanged. Pass NULL for claims and set *nr_claims to zero to
+ * query the count.
+ */
+int xc_domain_get_memory_claims(xc_interface *xch, uint32_t domid,
+                                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 35143d00db..5653b3d4ca 100644
--- a/tools/libs/ctrl/xc_domain.c
+++ b/tools/libs/ctrl/xc_domain.c
@@ -2246,6 +2246,33 @@ int xc_domain_set_memory_claims(xc_interface *xch, 
uint32_t domid,
     return ret;
 }
 
+int xc_domain_get_memory_claims(xc_interface *xch, uint32_t domid,
+                                xen_domctl_memory_claim_t *claims,
+                                uint32_t *nr_claims)
+{
+    struct xen_domctl domctl = {};
+    DECLARE_HYPERCALL_BOUNCE(claims, sizeof(*claims) * *nr_claims,
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, claims) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_get_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);
+    *nr_claims = domctl.u.memory_claims.nr_claims;
+
+    /* Claims are returned only on success; copy back just those. */
+    HYPERCALL_BOUNCE_SET_SIZE(claims, ret ? 0 : sizeof(*claims) * *nr_claims);
+    xc_hypercall_bounce_post(xch, claims);
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 64c0f87062..60543964d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ The format is based on [Keep a 
Changelog](https://keepachangelog.com/en/1.0.0/)
    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.
+   - XEN_DOMCTL_get_memory_claims/xc_domain_get_memory_claims() reads them.
 
 ### 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®.