From: Konrad Rzeszutek Wilk <konrad@darnok.org>
To: Haozhong Zhang <haozhong.zhang@intel.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
xen-devel@lists.xen.org, Jan Beulich <jbeulich@suse.com>,
Xiao Guangrong <guangrong.xiao@linux.intel.com>
Subject: Re: [RFC XEN PATCH 09/16] tools/libacpi: add callbacks to access XenStore
Date: Fri, 27 Jan 2017 16:10:26 -0500 [thread overview]
Message-ID: <20170127211025.GD18581@localhost.localdomain> (raw)
In-Reply-To: <20161010003235.4213-10-haozhong.zhang@intel.com>
On Mon, Oct 10, 2016 at 08:32:28AM +0800, Haozhong Zhang wrote:
> libacpi needs to access information placed in XenStore in order to load
> ACPI built by the device model.
>
> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> ---
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> ---
> tools/firmware/hvmloader/util.c | 50 +++++++++++++++++++++++++++++++++++++++
> tools/firmware/hvmloader/util.h | 2 ++
> tools/firmware/hvmloader/xenbus.c | 20 ++++++++++++++++
> tools/libacpi/libacpi.h | 10 ++++++++
> tools/libxl/libxl_x86_acpi.c | 24 +++++++++++++++++++
> 5 files changed, 106 insertions(+)
>
> diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
> index 504ae6a..dba954a 100644
> --- a/tools/firmware/hvmloader/util.c
> +++ b/tools/firmware/hvmloader/util.c
> @@ -888,6 +888,51 @@ static void acpi_mem_free(struct acpi_ctxt *ctxt,
> /* ACPI builder currently doesn't free memory so this is just a stub */
> }
>
> +static const char *acpi_xs_read(struct acpi_ctxt *ctxt, const char *path)
> +{
> + return xenstore_read(path, NULL);
> +}
> +
> +static int acpi_xs_write(struct acpi_ctxt *ctxt,
> + const char *path, const char *value)
> +{
> + return xenstore_write(path, value);
> +}
> +
> +static unsigned int count_strings(const char *strings, unsigned int len)
> +{
> + const char *p;
> + unsigned int n;
> +
> + for ( p = strings, n = 0; p < strings + len; p++ )
> + if ( *p == '\0' )
> + n++;
> +
> + return n;
> +}
> +
> +static char **acpi_xs_directory(struct acpi_ctxt *ctxt,
> + const char *path, unsigned int *num)
> +{
> + const char *strings;
> + char *s, *p, **ret;
> + unsigned int len, n;
> +
> + strings = xenstore_directory(path, &len, NULL);
> + if ( !strings )
> + return NULL;
> +
> + n = count_strings(strings, len);
> + ret = ctxt->mem_ops.alloc(ctxt, n * sizeof(char *) + len, 0);
sizeof(*s)
But you may also check ret against NULL before you memcpy data in there.
> + memcpy(&ret[n], strings, len);
> +
> + s = (char *)&ret[n];
> + for ( p = s, *num = 0; p < s + len; p+= strlen(p) + 1 )
Perhaps add an space before += ?
> + ret[(*num)++] = p;
> +
> + return ret;
> +}
> +
> static uint8_t acpi_lapic_id(unsigned cpu)
> {
> return LAPIC_ID(cpu);
> @@ -975,6 +1020,11 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
> ctxt.min_alloc_unit = PAGE_SIZE;
> ctxt.min_alloc_align = 16;
>
> + ctxt.xs_ops.read = acpi_xs_read;
> + ctxt.xs_ops.write = acpi_xs_write;
> + ctxt.xs_ops.directory = acpi_xs_directory;
> + ctxt.xs_opaque = NULL;
> +
> acpi_build_tables(&ctxt, config);
>
> hvm_param_set(HVM_PARAM_VM_GENERATION_ID_ADDR, config->vm_gid_addr);
> diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
> index 6a50dae..9443673 100644
> --- a/tools/firmware/hvmloader/util.h
> +++ b/tools/firmware/hvmloader/util.h
> @@ -225,6 +225,8 @@ const char *xenstore_read(const char *path, const char *default_resp);
> */
> int xenstore_write(const char *path, const char *value);
>
> +const char *xenstore_directory(const char *path, uint32_t *len,
> + const char *default_resp);
>
> /* Get a HVM param.
> */
> diff --git a/tools/firmware/hvmloader/xenbus.c b/tools/firmware/hvmloader/xenbus.c
> index 448157d..70bdadd 100644
> --- a/tools/firmware/hvmloader/xenbus.c
> +++ b/tools/firmware/hvmloader/xenbus.c
> @@ -296,6 +296,26 @@ int xenstore_write(const char *path, const char *value)
> return ret;
> }
>
> +const char *xenstore_directory(const char *path, uint32_t *len,
> + const char *default_resp)
> +{
> + uint32_t type = 0;
> + const char *answer = NULL;
> +
> + xenbus_send(XS_DIRECTORY,
> + path, strlen(path),
> + "", 1, /* nul separator */
> + NULL, 0);
> +
> + if ( xenbus_recv(len, &answer, &type) || (type != XS_DIRECTORY) )
> + answer = NULL;
> +
> + if ( (default_resp != NULL) && ((answer == NULL) || (*answer == '\0')) )
> + answer = default_resp;
> +
> + return answer;
This function looks very similar to xenstore_read. Could xenstore_read
become __xenstore_read with an extra argument (type) and then the
new xenstore_read along with xenstore_dir would call in it?
> +}
> +
> /*
> * Local variables:
> * mode: C
> diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h
> index 0fb16e7..12cafd8 100644
> --- a/tools/libacpi/libacpi.h
> +++ b/tools/libacpi/libacpi.h
> @@ -50,6 +50,16 @@ struct acpi_ctxt {
>
> uint32_t min_alloc_unit;
> uint32_t min_alloc_align;
> +
> + struct acpi_xs_ops {
> + const char *(*read)(struct acpi_ctxt *ctxt, const char *path);
> + int (*write)(struct acpi_ctxt *ctxt,
> + const char *path, const char *value);
> + char **(*directory)(struct acpi_ctxt *ctxt,
> + const char *path, unsigned int *num);
> + } xs_ops;
> +
> + void *xs_opaque;
> };
>
> struct acpi_config {
> diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c
> index baf60ac..1afd2e3 100644
> --- a/tools/libxl/libxl_x86_acpi.c
> +++ b/tools/libxl/libxl_x86_acpi.c
> @@ -93,6 +93,25 @@ static void acpi_mem_free(struct acpi_ctxt *ctxt,
> {
> }
>
> +static const char *acpi_xs_read(struct acpi_ctxt *ctxt, const char *path)
> +{
> + return libxl__xs_read((libxl__gc *)ctxt->xs_opaque, XBT_NULL, path);
> +}
> +
> +static int acpi_xs_write(struct acpi_ctxt *ctxt,
> + const char *path, const char *value)
> +{
> + return libxl__xs_write_checked((libxl__gc *)ctxt->xs_opaque, XBT_NULL,
> + path, value);
> +}
> +
> +static char **acpi_xs_directory(struct acpi_ctxt *ctxt,
> + const char *path, unsigned int *num)
> +{
> + return libxl__xs_directory((libxl__gc *)ctxt->xs_opaque, XBT_NULL,
> + path, num);
> +}
> +
> static uint8_t acpi_lapic_id(unsigned cpu)
> {
> return cpu * 2;
> @@ -190,6 +209,11 @@ int libxl__dom_load_acpi(libxl__gc *gc,
> libxl_ctxt.c.min_alloc_unit = libxl_ctxt.page_size;
> libxl_ctxt.c.min_alloc_align = 16;
>
> + libxl_ctxt.c.xs_ops.read = acpi_xs_read;
> + libxl_ctxt.c.xs_ops.write = acpi_xs_write;
> + libxl_ctxt.c.xs_ops.directory = acpi_xs_directory;
> + libxl_ctxt.c.xs_opaque = gc;
> +
> rc = init_acpi_config(gc, dom, b_info, &config);
> if (rc) {
> LOG(ERROR, "init_acpi_config failed (rc=%d)", rc);
> --
> 2.10.1
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-27 21:10 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-10 0:32 [RFC XEN PATCH 00/16] Add vNVDIMM support to HVM domains Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 01/16] x86_64/mm: explicitly specify the location to place the frame table Haozhong Zhang
2016-12-09 21:35 ` Konrad Rzeszutek Wilk
2016-12-12 2:27 ` Haozhong Zhang
2016-12-12 8:25 ` Jan Beulich
2016-10-10 0:32 ` [RFC XEN PATCH 02/16] x86_64/mm: explicitly specify the location to place the M2P table Haozhong Zhang
2016-12-09 21:38 ` Konrad Rzeszutek Wilk
2016-12-12 2:31 ` Haozhong Zhang
2016-12-12 8:26 ` Jan Beulich
2016-12-12 8:35 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 03/16] xen/x86: add a hypercall XENPF_pmem_add to report host pmem regions Haozhong Zhang
2016-10-11 19:13 ` Andrew Cooper
2016-12-09 22:02 ` Konrad Rzeszutek Wilk
2016-12-12 4:16 ` Haozhong Zhang
2016-12-12 8:30 ` Jan Beulich
2016-12-12 8:38 ` Haozhong Zhang
2016-12-12 14:44 ` Konrad Rzeszutek Wilk
2016-12-13 1:08 ` Haozhong Zhang
2016-12-22 11:58 ` Jan Beulich
2016-10-10 0:32 ` [RFC XEN PATCH 04/16] xen/x86: add XENMEM_populate_pmemmap to map host pmem pages to guest Haozhong Zhang
2016-12-09 22:22 ` Konrad Rzeszutek Wilk
2016-12-12 4:38 ` Haozhong Zhang
2016-12-22 12:19 ` Jan Beulich
2016-10-10 0:32 ` [RFC XEN PATCH 05/16] xen/x86: release pmem pages at domain destroy Haozhong Zhang
2016-12-09 22:27 ` Konrad Rzeszutek Wilk
2016-12-12 4:47 ` Haozhong Zhang
2016-12-22 12:22 ` Jan Beulich
2016-10-10 0:32 ` [RFC XEN PATCH 06/16] tools: reserve guest memory for ACPI from device model Haozhong Zhang
2017-01-27 20:44 ` Konrad Rzeszutek Wilk
2017-02-08 1:39 ` Haozhong Zhang
2017-02-08 14:31 ` Konrad Rzeszutek Wilk
2016-10-10 0:32 ` [RFC XEN PATCH 07/16] tools/libacpi: add callback acpi_ctxt.p2v to get a pointer from physical address Haozhong Zhang
2017-01-27 20:46 ` Konrad Rzeszutek Wilk
2017-02-08 1:42 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 08/16] tools/libacpi: expose details of memory allocation callback Haozhong Zhang
2017-01-27 20:58 ` Konrad Rzeszutek Wilk
2017-02-08 2:12 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 09/16] tools/libacpi: add callbacks to access XenStore Haozhong Zhang
2017-01-27 21:10 ` Konrad Rzeszutek Wilk [this message]
2017-02-08 2:19 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 10/16] tools/libacpi: add a simple AML builder Haozhong Zhang
2017-01-27 21:19 ` Konrad Rzeszutek Wilk
2017-02-08 2:33 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 11/16] tools/libacpi: load ACPI built by the device model Haozhong Zhang
2017-01-27 21:40 ` Konrad Rzeszutek Wilk
2017-02-08 5:38 ` Haozhong Zhang
2017-02-08 14:35 ` Konrad Rzeszutek Wilk
2016-10-10 0:32 ` [RFC XEN PATCH 12/16] tools/libxl: build qemu options from xl vNVDIMM configs Haozhong Zhang
2017-01-27 21:47 ` Konrad Rzeszutek Wilk
2017-02-08 5:42 ` Haozhong Zhang
2017-01-27 21:48 ` Konrad Rzeszutek Wilk
2017-02-08 5:47 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 13/16] tools/libxl: add support to map host pmem device to guests Haozhong Zhang
2017-01-27 22:06 ` Konrad Rzeszutek Wilk
2017-01-27 22:09 ` Konrad Rzeszutek Wilk
2017-02-08 5:59 ` Haozhong Zhang
2017-02-08 14:37 ` Konrad Rzeszutek Wilk
2016-10-10 0:32 ` [RFC XEN PATCH 14/16] tools/libxl: add support to map files on pmem devices " Haozhong Zhang
2017-01-27 22:10 ` Konrad Rzeszutek Wilk
2017-02-08 6:03 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 15/16] tools/libxl: handle return code of libxl__qmp_initializations() Haozhong Zhang
2017-01-27 22:11 ` Konrad Rzeszutek Wilk
2017-02-08 6:07 ` Haozhong Zhang
2017-02-08 10:31 ` Wei Liu
2017-02-09 2:47 ` Haozhong Zhang
2017-02-09 10:13 ` Wei Liu
2017-02-09 10:16 ` Wei Liu
2017-02-10 2:37 ` Haozhong Zhang
2017-02-10 8:11 ` Wei Liu
2017-02-10 8:23 ` Wei Liu
2017-02-10 8:24 ` Haozhong Zhang
2016-10-10 0:32 ` [RFC XEN PATCH 16/16] tools/libxl: initiate pmem mapping via qmp callback Haozhong Zhang
2017-01-27 22:13 ` Konrad Rzeszutek Wilk
2017-02-08 6:08 ` Haozhong Zhang
2016-10-24 16:37 ` [RFC XEN PATCH 00/16] Add vNVDIMM support to HVM domains Wei Liu
2016-10-25 6:55 ` Haozhong Zhang
2016-10-25 11:28 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170127211025.GD18581@localhost.localdomain \
--to=konrad@darnok.org \
--cc=andrew.cooper3@citrix.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=haozhong.zhang@intel.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).