Skip to contentSkip to conversation

livepatch: Add metadata runtime retrieval mechanism

PATCH In review Pawel Wieczorkiewicz 2 participants 4 messages Aug 15, 2019 – Aug 16, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 livepatch: Add metadata runtime retrieval mechanism

Extend the livepatch list operation to fetch also payloads' metadata. This is achieved by extending the sysctl list interface with 2 extra guest handles:
* metadata - an array of arbitrary size strings
* metadata_len - an array of metadata strings' lengths (uin32_t each)

Payloads' metadata is a string of arbitrary size and does not have an upper bound limit. It may also vary in size between payloads.

In order to let the userland allocate enough space for the incoming data add a metadata total size field to the list sysctl operation and fill it with total size of all payloads' metadata.

Extend the libxc to handle the metadata back-to-back data transfers as well as metadata length array data transfers.

The xen-livepatch userland tool is extended to always display the metadata for each received module. The metadata is received with the following format: key=value\0key=value\0...key=value\0. The format is modified to the following one: key=value;key=value;...key=value. The new format allows to easily parse the metadata for a given module by a machine.

---
 tools/libxc/include/xenctrl.h | 22 +++++++++++----
 tools/libxc/xc_misc.c         | 66 +++++++++++++++++++++++++++++++++++--------
 tools/misc/xen-livepatch.c    | 43 ++++++++++++++++++++++------
 xen/common/livepatch.c        | 22 +++++++++++----
 xen/include/public/sysctl.h   | 19 +++++++++----
 5 files changed, 134 insertions(+), 38 deletions(-)
tools/libxc/include/xenctrl.h +16 -6
index e0ebb586b6..7a3762f44e 100644
@@ -2561,7 +2561,7 @@ int xc_livepatch_get(xc_interface *xch,
 
 /*
  * Get a number of available payloads and get actual total size of
- * the payloads' name array.
+ * the payloads' name and metadata arrays.
  *
  * This functions is typically executed first before the xc_livepatch_list()
  * to obtain the sizes and correctly allocate all necessary data resources.
@@ -2572,13 +2572,16 @@ int xc_livepatch_get(xc_interface *xch,
  * will contain the hypercall error code value.
  */
 int xc_livepatch_list_get_sizes(xc_interface *xch, unsigned int *nr,
-                                uint64_t *name_total_size);
+                                uint64_t *name_total_size,
+                                uint64_t *metadata_total_size);
 
 /*
  * The heart of this function is to get an array of the following objects:
  *   - xen_livepatch_status_t: states and return codes of payloads
  *   - name: names of payloads
  *   - len: lengths of corresponding payloads' names
+ *   - metadata: payloads' metadata
+ *   - metadata_len: lengths of corresponding payloads' metadata
  *
  * However it is complex because it has to deal with the hypervisor
  * returning some of the requested data or data being stale
@@ -2591,12 +2594,13 @@ int xc_livepatch_list_get_sizes(xc_interface *xch, unsigned int *nr,
  *
  * It is expected that the caller of this function will first issue the
  * xc_livepatch_list_get_sizes() in order to obtain total sizes of names
- * as well as the current number of payload entries.
- * The total sizes are required and supplied via the 'name_total_size'
- * parameter.
+ * and all metadata as well as the current number of payload entries.
+ * The total sizes are required and supplied via the 'name_total_size' and
+ * 'metadata_total_size' parameters.
  *
  * The 'max' is to be provided by the caller with the maximum number of
- * entries that 'info', 'name', 'len' arrays can be filled up with.
+ * entries that 'info', 'name', 'len', 'metadata' and 'metadata_len' arrays
+ * can be filled up with.
  *
  * Each entry in the 'info' array is expected to be of xen_livepatch_status_t
  * structure size.
@@ -2605,6 +2609,10 @@ int xc_livepatch_list_get_sizes(xc_interface *xch, unsigned int *nr,
  *
  * Each entry in the 'len' array is expected to be of uint32_t size.
  *
+ * Each entry in the 'metadata' array may have an arbitrary size.
+ *
+ * Each entry in the 'metadata_len' array is expected to be of uint32_t size.
+ *
  * The return value is zero if the hypercall completed successfully.
  * Note that the return value is _not_ the amount of entries filled
  * out - that is saved in 'done'.
@@ -2619,6 +2627,8 @@ int xc_livepatch_list(xc_interface *xch, const unsigned int max,
                       struct xen_livepatch_status *info,
                       char *name, uint32_t *len,
                       const uint64_t name_total_size,
+                      char *metadata, uint32_t *metadata_len,
+                      const uint64_t metadata_total_size,
                       unsigned int *done, unsigned int *left);
 
 /*
tools/libxc/xc_misc.c +54 -12

192 lines not on this page · raw message

tools/misc/xen-livepatch.c +34 -9

85 lines not on this page · raw message

xen/common/livepatch.c +17 -5
index f486cb3021..49a76f1029 100644
@@ -1163,7 +1163,8 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
 
     if ( list->nr &&
          (!guest_handle_okay(list->status, list->nr) ||
-          !guest_handle_okay(list->len, list->nr)) )
+          !guest_handle_okay(list->len, list->nr) ||
+          !guest_handle_okay(list->metadata_len, list->nr)) )
         return -EINVAL;
 
     spin_lock(&payload_lock);
@@ -1174,13 +1175,14 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
     }
 
     list->name_total_size = 0;
+    list->metadata_total_size = 0;
     if ( list->nr )
     {
-        uint64_t name_offset = 0;
+        uint64_t name_offset = 0, metadata_offset = 0;
 
         list_for_each_entry( data, &payload_list, list )
         {
-            uint32_t name_len;
+            uint32_t name_len, metadata_len;
 
             if ( list->idx > i++ )
                 continue;
@@ -1191,8 +1193,13 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
             name_len = strlen(data->name) + 1;
             list->name_total_size += name_len;
 
+            metadata_len = data->metadata.len;
+            list->metadata_total_size += metadata_len;
+
             if ( !guest_handle_subrange_okay(list->name, name_offset,
-                                             name_offset + name_len - 1) )
+                                             name_offset + name_len - 1) ||
+                 !guest_handle_subrange_okay(list->metadata, metadata_offset,
+                                             metadata_offset + metadata_len - 1) )
             {
                 rc = -EINVAL;
                 break;
@@ -1202,7 +1209,10 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
             if ( __copy_to_guest_offset(list->name, name_offset,
                                         data->name, name_len) ||
                 __copy_to_guest_offset(list->len, idx, &name_len, 1) ||
-                __copy_to_guest_offset(list->status, idx, &status, 1) )
+                __copy_to_guest_offset(list->status, idx, &status, 1) ||
+                __copy_to_guest_offset(list->metadata, metadata_offset,
+                                       data->metadata.data, metadata_len) ||
+                __copy_to_guest_offset(list->metadata_len, idx, &metadata_len, 1) )
             {
                 rc = -EFAULT;
                 break;
@@ -1210,6 +1220,7 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
 
             idx++;
             name_offset += name_len;
+            metadata_offset += metadata_len;
 
             if ( (idx >= list->nr) || hypercall_preempt_check() )
                 break;
@@ -1220,6 +1231,7 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
         list_for_each_entry( data, &payload_list, list )
         {
             list->name_total_size += strlen(data->name) + 1;
+            list->metadata_total_size += data->metadata.len;
         }
     }
     list->nr = payload_cnt - i; /* Remaining amount. */
xen/include/public/sysctl.h +13 -6
index b86804b7a6..e4c8f4fe63 100644
@@ -921,16 +921,17 @@ struct xen_sysctl_livepatch_get {
 };
 
 /*
- * Retrieve an array of abbreviated status and names of payloads that are
- * loaded in the hypervisor.
+ * Retrieve an array of abbreviated status, names and metadata of payloads that
+ * are loaded in the hypervisor.
  *
  * If the hypercall returns an positive number, it is the number (up to `nr`)
  * of the payloads returned, along with `nr` updated with the number of remaining
  * payloads, `version` updated (it may be the same across hypercalls. If it varies
- * the data is stale and further calls could fail) and the name_total_size
- * containing total size of transfered data for the array.
- * The `status`, `name`, `len` are updated at their designed index value (`idx`)
- * with the returned value of data.
+ * the data is stale and further calls could fail), `name_total_size` and
+ * `metadata_total_size` containing total sizes of transfered data for both the
+ * arrays.
+ * The `status`, `name`, `len`, `metadata` and `metadata_len` are updated at their
+ * designed index value (`idx`) with the returned value of data.
  *
  * If the hypercall returns E2BIG the `nr` is too big and should be
  * lowered. The upper limit of `nr` is left to the implemention.
@@ -954,6 +955,7 @@ struct xen_sysctl_livepatch_list {
                                                OUT: How many payloads left. */
     uint32_t pad;                           /* IN: Must be zero. */
     uint64_t name_total_size;               /* OUT: Total size of all transfer names */
+    uint64_t metadata_total_size;           /* OUT: Total size of all transfer metadata */
     XEN_GUEST_HANDLE_64(xen_livepatch_status_t) status;  /* OUT. Must have enough
                                                space allocate for nr of them. */
     XEN_GUEST_HANDLE_64(char) name;         /* OUT: Array of names. Each member
@@ -962,6 +964,11 @@ struct xen_sysctl_livepatch_list {
                                                nr of them. */
     XEN_GUEST_HANDLE_64(uint32) len;        /* OUT: Array of lengths of name's.
                                                Must have nr of them. */
+    XEN_GUEST_HANDLE_64(char) metadata;     /* OUT: Array of metadata strings. Each
+                                               member may have an arbitrary length.
+                                               Must have nr of them. */
+    XEN_GUEST_HANDLE_64(uint32) metadata_len;  /* OUT: Array of lengths of metadata's.
+                                                  Must have nr of them. */
 };
 
 /*
Signature · 20 lines
2.16.5




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 27 lines · Pawel Wieczorkiewicz

Extend the livepatch list operation to fetch also payloads' metadata. This is achieved by extending the sysctl list interface with 2 extra guest handles:
* metadata - an array of arbitrary size strings
* metadata_len - an array of metadata strings' lengths (uin32_t each)

Payloads' metadata is a string of arbitrary size and does not have an upper bound limit. It may also vary in size between payloads.

In order to let the userland allocate enough space for the incoming data add a metadata total size field to the list sysctl operation and fill it with total size of all payloads' metadata.

Extend the libxc to handle the metadata back-to-back data transfers as well as metadata length array data transfers.

The xen-livepatch userland tool is extended to always display the metadata for each received module. The metadata is received with the following format: key=value\0key=value\0...key=value\0. The format is modified to the following one: key=value;key=value;...key=value. The new format allows to easily parse the metadata for a given module by a machine.

Quoted 6 lines
---
 tools/libxc/include/xenctrl.h | 22 +++++++++++----
 tools/libxc/xc_misc.c         | 66 +++++++++++++++++++++++++++++++++++--------
 tools/misc/xen-livepatch.c    | 43 ++++++++++++++++++++++------
 xen/common/livepatch.c        | 22 +++++++++++----
 xen/include/public/sysctl.h   | 19 +++++++++----

Mostly look good. One comment below...

xen/include/public/sysctl.h

Quoted 4 lines
xen/include/public/sysctl.h +0 -0
index b86804b7a6..e4c8f4fe63 100644

If it hasn't been done for this release already, changing sysctl interface requires bumping the version number in this header.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 9 lines · Wei Liu
Quoted 5 lines · Pawel Wieczorkiewicz

Extend the livepatch list operation to fetch also payloads' metadata. This is achieved by extending the sysctl list interface with 2 extra guest handles:
* metadata - an array of arbitrary size strings
* metadata_len - an array of metadata strings' lengths (uin32_t each)

…snip...

Quoted 13 lines
Quoted 10 lines

---

tools/libxc/include/xenctrl.h | 22 +++++++++++----
tools/libxc/xc_misc.c         | 66 +++++++++++++++++++++++++++++++++++--------
tools/misc/xen-livepatch.c    | 43 ++++++++++++++++++++++------
xen/common/livepatch.c        | 22 +++++++++++----
xen/include/public/sysctl.h   | 19 +++++++++----

Mostly look good. One comment below...

Quoted 8 lines

xen/include/public/sysctl.h

Quoted 4 lines
xen/include/public/sysctl.h +0 -0
index b86804b7a6..e4c8f4fe63 100644

If it hasn't been done for this release already, changing sysctl interface requires bumping the version number in this header.

ACK. Will do (also for earlier patches…).

Quoted 1 line

Wei.

Best Regards,
Pawel Wieczorkiewicz

Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 34 lines · Pawel
Quoted 9 lines · Wei Liu
Quoted 5 lines · Pawel Wieczorkiewicz

Extend the livepatch list operation to fetch also payloads' metadata. This is achieved by extending the sysctl list interface with 2 extra guest handles:
* metadata - an array of arbitrary size strings
* metadata_len - an array of metadata strings' lengths (uin32_t each)

…snip...

Quoted 13 lines
Quoted 10 lines

---

tools/libxc/include/xenctrl.h | 22 +++++++++++----
tools/libxc/xc_misc.c         | 66 +++++++++++++++++++++++++++++++++++--------
tools/misc/xen-livepatch.c    | 43 ++++++++++++++++++++++------
xen/common/livepatch.c        | 22 +++++++++++----
xen/include/public/sysctl.h   | 19 +++++++++----

Mostly look good. One comment below...

Quoted 8 lines

xen/include/public/sysctl.h

Quoted 4 lines
xen/include/public/sysctl.h +0 -0
index b86804b7a6..e4c8f4fe63 100644

If it hasn't been done for this release already, changing sysctl interface requires bumping the version number in this header.

Quoted 2 lines

ACK. Will do (also for earlier patches…).

We only need to do it once per release. :-)

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel