Re: [PATCH 11/15] tools/helpers: Add get_overlay

2024-04-25 Thread Henry Wang

Hi Stewart,

On 4/26/2024 9:45 AM, Stewart Hildebrand wrote:

On 4/24/24 20:43, Henry Wang wrote:

Hi Jan,

On 4/24/2024 2:08 PM, Jan Beulich wrote:

On 24.04.2024 05:34, Henry Wang wrote:

From: Vikram Garhwal 

This user level application copies the overlay dtbo shared by dom0 while doing
overlay node assignment operation. It uses xenstore to communicate with dom0.
More information on the protocol is writtien in docs/misc/overlay.txt file.

Signed-off-by: Vikram Garhwal 
Signed-off-by: Stefano Stabellini 
Signed-off-by: Henry Wang 
---
   tools/helpers/Makefile  |   8 +
   tools/helpers/get_overlay.c | 393 
   2 files changed, 401 insertions(+)
   create mode 100644 tools/helpers/get_overlay.c

As mentioned before on various occasions - new files preferably use dashes as
separators in preference to underscores. You not doing so is particularly
puzzling seeing ...


--- a/tools/helpers/Makefile
+++ b/tools/helpers/Makefile
@@ -12,6 +12,7 @@ TARGETS += init-xenstore-domain
   endif
   ifeq ($(CONFIG_ARM),y)
   TARGETS += init-dom0less
+TARGETS += get_overlay

... patch context here (demonstrating a whopping 3 dashes used in similar
cases).

I am not very sure why Vikram used "_" in the original patch. However I agree you are 
correct. Since I am currently doing the follow up of this series, I will use "-" in v2 as 
suggested. Thanks.

Please also add tools/helpers/get-overlay to .gitignore


Thanks for the reminder! Yes sure I will add it.

Kind regards,
Henry



Re: [PATCH 11/15] tools/helpers: Add get_overlay

2024-04-25 Thread Stewart Hildebrand
On 4/24/24 20:43, Henry Wang wrote:
> Hi Jan,
> 
> On 4/24/2024 2:08 PM, Jan Beulich wrote:
>> On 24.04.2024 05:34, Henry Wang wrote:
>>> From: Vikram Garhwal 
>>>
>>> This user level application copies the overlay dtbo shared by dom0 while 
>>> doing
>>> overlay node assignment operation. It uses xenstore to communicate with 
>>> dom0.
>>> More information on the protocol is writtien in docs/misc/overlay.txt file.
>>>
>>> Signed-off-by: Vikram Garhwal 
>>> Signed-off-by: Stefano Stabellini 
>>> Signed-off-by: Henry Wang 
>>> ---
>>>   tools/helpers/Makefile  |   8 +
>>>   tools/helpers/get_overlay.c | 393 
>>>   2 files changed, 401 insertions(+)
>>>   create mode 100644 tools/helpers/get_overlay.c
>> As mentioned before on various occasions - new files preferably use dashes as
>> separators in preference to underscores. You not doing so is particularly
>> puzzling seeing ...
>>
>>> --- a/tools/helpers/Makefile
>>> +++ b/tools/helpers/Makefile
>>> @@ -12,6 +12,7 @@ TARGETS += init-xenstore-domain
>>>   endif
>>>   ifeq ($(CONFIG_ARM),y)
>>>   TARGETS += init-dom0less
>>> +TARGETS += get_overlay
>> ... patch context here (demonstrating a whopping 3 dashes used in similar
>> cases).
> 
> I am not very sure why Vikram used "_" in the original patch. However I agree 
> you are correct. Since I am currently doing the follow up of this series, I 
> will use "-" in v2 as suggested. Thanks.

Please also add tools/helpers/get-overlay to .gitignore



Re: [PATCH 11/15] tools/helpers: Add get_overlay

2024-04-24 Thread Henry Wang

Hi Jan,

On 4/24/2024 2:08 PM, Jan Beulich wrote:

On 24.04.2024 05:34, Henry Wang wrote:

From: Vikram Garhwal 

This user level application copies the overlay dtbo shared by dom0 while doing
overlay node assignment operation. It uses xenstore to communicate with dom0.
More information on the protocol is writtien in docs/misc/overlay.txt file.

Signed-off-by: Vikram Garhwal 
Signed-off-by: Stefano Stabellini 
Signed-off-by: Henry Wang 
---
  tools/helpers/Makefile  |   8 +
  tools/helpers/get_overlay.c | 393 
  2 files changed, 401 insertions(+)
  create mode 100644 tools/helpers/get_overlay.c

As mentioned before on various occasions - new files preferably use dashes as
separators in preference to underscores. You not doing so is particularly
puzzling seeing ...


--- a/tools/helpers/Makefile
+++ b/tools/helpers/Makefile
@@ -12,6 +12,7 @@ TARGETS += init-xenstore-domain
  endif
  ifeq ($(CONFIG_ARM),y)
  TARGETS += init-dom0less
+TARGETS += get_overlay

... patch context here (demonstrating a whopping 3 dashes used in similar
cases).


I am not very sure why Vikram used "_" in the original patch. However I 
agree you are correct. Since I am currently doing the follow up of this 
series, I will use "-" in v2 as suggested. Thanks.


Kind regards,
Henry



Jan





Re: [PATCH 11/15] tools/helpers: Add get_overlay

2024-04-24 Thread Jan Beulich
On 24.04.2024 05:34, Henry Wang wrote:
> From: Vikram Garhwal 
> 
> This user level application copies the overlay dtbo shared by dom0 while doing
> overlay node assignment operation. It uses xenstore to communicate with dom0.
> More information on the protocol is writtien in docs/misc/overlay.txt file.
> 
> Signed-off-by: Vikram Garhwal 
> Signed-off-by: Stefano Stabellini 
> Signed-off-by: Henry Wang 
> ---
>  tools/helpers/Makefile  |   8 +
>  tools/helpers/get_overlay.c | 393 
>  2 files changed, 401 insertions(+)
>  create mode 100644 tools/helpers/get_overlay.c

As mentioned before on various occasions - new files preferably use dashes as
separators in preference to underscores. You not doing so is particularly
puzzling seeing ...

> --- a/tools/helpers/Makefile
> +++ b/tools/helpers/Makefile
> @@ -12,6 +12,7 @@ TARGETS += init-xenstore-domain
>  endif
>  ifeq ($(CONFIG_ARM),y)
>  TARGETS += init-dom0less
> +TARGETS += get_overlay

... patch context here (demonstrating a whopping 3 dashes used in similar
cases).

Jan



[PATCH 11/15] tools/helpers: Add get_overlay

2024-04-23 Thread Henry Wang
From: Vikram Garhwal 

This user level application copies the overlay dtbo shared by dom0 while doing
overlay node assignment operation. It uses xenstore to communicate with dom0.
More information on the protocol is writtien in docs/misc/overlay.txt file.

Signed-off-by: Vikram Garhwal 
Signed-off-by: Stefano Stabellini 
Signed-off-by: Henry Wang 
---
 tools/helpers/Makefile  |   8 +
 tools/helpers/get_overlay.c | 393 
 2 files changed, 401 insertions(+)
 create mode 100644 tools/helpers/get_overlay.c

diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile
index 09590eb5b6..dfe17ef269 100644
--- a/tools/helpers/Makefile
+++ b/tools/helpers/Makefile
@@ -12,6 +12,7 @@ TARGETS += init-xenstore-domain
 endif
 ifeq ($(CONFIG_ARM),y)
 TARGETS += init-dom0less
+TARGETS += get_overlay
 endif
 endif
 
@@ -39,6 +40,9 @@ $(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
 $(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxenevtchn)
 init-dom0less: LDLIBS += $(call xenlibs-ldlibs,ctrl evtchn toollog store light 
guest foreignmemory)
 
+SHARE_OVERLAY_OBJS = get_overlay.o
+$(SHARE_OVERLAY_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxenstore) 
$(CFLAGS_libxenctrl)
+
 .PHONY: all
 all: $(TARGETS)
 
@@ -51,6 +55,10 @@ init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS)
 init-dom0less: $(INIT_DOM0LESS_OBJS)
$(CC) $(LDFLAGS) -o $@ $(INIT_DOM0LESS_OBJS) $(LDLIBS) $(APPEND_LDFLAGS)
 
+get_overlay: $(SHARE_OVERLAY_OBJS)
+   $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenvchan) $(LDLIBS_libxenstore) 
$(LDLIBS_libxenctrl) $(LDLIBS_libxengnttab) $(APPEND_LDFLAGS)
+
+
 .PHONY: install
 install: all
$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
diff --git a/tools/helpers/get_overlay.c b/tools/helpers/get_overlay.c
new file mode 100644
index 00..ca3007570e
--- /dev/null
+++ b/tools/helpers/get_overlay.c
@@ -0,0 +1,393 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PAGE_SIZE 4096
+
+static int xs_create_overlay_node(int domain, const char *xs_base,
+  struct xs_handle *xs)
+{
+int ret = -1;
+struct xs_permissions perms[2];
+char buf[64];
+char ref[16];
+char *domid_str = NULL;
+int overlay_size = 0;
+
+xs_transaction_t xs_trans = XBT_NULL;
+
+domid_str = xs_read(xs, XBT_NULL, "domid", NULL);
+
+if (!domid_str)
+return ret;
+
+/* owner domain is us */
+perms[0].id = atoi(domid_str);
+/* permissions for domains not listed = none. */
+perms[0].perms = XS_PERM_NONE;
+/* other domains i.e. domain provided by user gets r/w permissions. */
+perms[1].id = domain;
+perms[1].perms =  XS_PERM_READ | XS_PERM_WRITE;
+
+retry_transaction:
+
+xs_trans = xs_transaction_start(xs);
+if (!xs_trans)
+goto fail_xs_transaction;
+
+/* Create overlay-size node. */
+snprintf(ref, sizeof(ref), "%d", overlay_size);
+snprintf(buf, sizeof(buf), "%s/overlay-size", xs_base);
+
+if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+goto fail_xs_transaction;
+if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+goto fail_xs_transaction;
+
+/* Create domU status node. */
+snprintf(ref, sizeof(ref), "%s", "waiting");
+snprintf(buf, sizeof(buf), "%s/receiver-status", xs_base);
+
+if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+goto fail_xs_transaction;
+if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+goto fail_xs_transaction;
+
+/* Create dom0 status node. */
+snprintf(ref, sizeof(ref), "%s", "not_ready");
+snprintf(buf, sizeof(buf), "%s/sender-status", xs_base);
+
+if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+goto fail_xs_transaction;
+if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+goto fail_xs_transaction;
+
+if (!xs_transaction_end(xs, xs_trans, 0)) {
+if (errno == EAGAIN)
+goto retry_transaction;
+else
+goto fail_xs_transaction;
+} else
+ret = 0;
+
+fail_xs_transaction:
+free(domid_str);
+
+return ret;
+}
+
+static int get_overlay_size(struct xs_handle *xs, int domain,
+const char *xs_path)
+{
+char buf[128];
+char *ref;
+unsigned int len;
+int dt_size = 0;
+
+snprintf(buf, sizeof(buf), "%s/overlay-size", xs_path);
+
+ref = xs_read(xs, XBT_NULL, buf, );
+
+if (!ref)
+return dt_size;
+
+dt_size = atoi(ref);
+
+free(ref);
+
+return dt_size;
+}
+
+static uint32_t get_num_pages(int dtbo_size)
+{
+int num_pages = 1;
+
+while (dtbo_size > PAGE_SIZE) {
+dtbo_size = dtbo_size - PAGE_SIZE;
+num_pages++;
+}
+
+return num_pages;
+}
+
+static void *create_shared_buffer(int domain, uint32_t *refs, uint32_t pages,
+  xengntshr_handle *gntshr)
+{
+return