Message ID | 1443544141-26568-1-git-send-email-somlo@cmu.edu |
---|---|
State | New |
Headers | show |
Paolo, On 09/29/15 18:29, Gabriel L. Somlo wrote: > Allow users to provide custom fw_cfg blobs with ascii string > payloads specified directly on the qemu command line. > > Suggested-by: Jordan Justen <jordan.l.justen@intel.com> > Suggested-by: Laszlo Ersek <lersek@redhat.com> > Signed-off-by: Gabriel Somlo <somlo@cmu.edu> > Reviewd-by: Laszlo Ersek <lersek@redhat.com> > --- > > New since v3: s/content/string/g for the option name, at Gerd's > suggestion (to potentially allow for additional content > types directly on the command line, should the need arise > at a future date) > > Thanks, > --Gabriel > > docs/specs/fw_cfg.txt | 15 +++++++++++++++ > qemu-options.hx | 7 ++++++- > vl.c | 33 +++++++++++++++++++++++++++------ > 3 files changed, 48 insertions(+), 7 deletions(-) I'm sure you're going to want to give me a hug for bringing this up, but can you please pick this up? O:-) Or maybe Peter can apply it directly? Thanks! Laszlo > diff --git a/docs/specs/fw_cfg.txt b/docs/specs/fw_cfg.txt > index b5f4b5d..a5ae930 100644 > --- a/docs/specs/fw_cfg.txt > +++ b/docs/specs/fw_cfg.txt > @@ -236,6 +236,21 @@ the following syntax: > where <item_name> is the fw_cfg item name, and <path> is the location > on the host file system of a file containing the data to be inserted. > > +Small enough items may be provided directly as strings on the command > +line, using the syntax: > + > + -fw_cfg [name=]<item_name>,string=<string> > + > +The terminating NUL character of the content <string> will NOT be > +included as part of the fw_cfg item data, which is consistent with > +the absence of a NUL terminator for items inserted via the file option. > + > +Both <item_name> and, if applicable, the content <string> are passed > +through by QEMU without any interpretation, expansion, or further > +processing. Any such processing (potentially performed e.g., by the shell) > +is outside of QEMU's responsibility; as such, using plain ASCII characters > +is recommended. > + > NOTE: Users *SHOULD* choose item names beginning with the prefix "opt/" > when using the "-fw_cfg" command line option, to avoid conflicting with > item names used internally by QEMU. For instance: > diff --git a/qemu-options.hx b/qemu-options.hx > index 328404c..408c5b4 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -2724,13 +2724,18 @@ ETEXI > > DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg, > "-fw_cfg [name=]<name>,file=<file>\n" > - " add named fw_cfg entry from file\n", > + " add named fw_cfg entry from file\n" > + "-fw_cfg [name=]<name>,string=<str>\n" > + " add named fw_cfg entry from string\n", > QEMU_ARCH_ALL) > STEXI > @item -fw_cfg [name=]@var{name},file=@var{file} > @findex -fw_cfg > Add named fw_cfg entry from file. @var{name} determines the name of > the entry in the fw_cfg file directory exposed to the guest. > + > +@item -fw_cfg [name=]@var{name},string=@var{str} > +Add named fw_cfg entry from string. > ETEXI > > DEF("serial", HAS_ARG, QEMU_OPTION_serial, \ > diff --git a/vl.c b/vl.c > index e211f6a..854bd8b 100644 > --- a/vl.c > +++ b/vl.c > @@ -512,6 +512,10 @@ static QemuOptsList qemu_fw_cfg_opts = { > .type = QEMU_OPT_STRING, > .help = "Sets the name of the file from which\n" > "the fw_cfg blob will be loaded", > + }, { > + .name = "string", > + .type = QEMU_OPT_STRING, > + .help = "Sets content of the blob to be inserted from a string", > }, > { /* end of list */ } > }, > @@ -2232,11 +2236,16 @@ char *qemu_find_file(int type, const char *name) > return NULL; > } > > +static inline bool nonempty_str(const char *str) > +{ > + return str && *str; > +} > + > static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) > { > gchar *buf; > size_t size; > - const char *name, *file; > + const char *name, *file, *str; > > if (opaque == NULL) { > error_report("fw_cfg device not available"); > @@ -2244,8 +2253,15 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) > } > name = qemu_opt_get(opts, "name"); > file = qemu_opt_get(opts, "file"); > - if (name == NULL || *name == '\0' || file == NULL || *file == '\0') { > - error_report("invalid argument value"); > + str = qemu_opt_get(opts, "string"); > + > + /* we need name and either a file or the content string */ > + if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))) { > + error_report("invalid argument(s)"); > + return -1; > + } > + if (nonempty_str(file) && nonempty_str(str)) { > + error_report("file and string are mutually exclusive"); > return -1; > } > if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { > @@ -2256,9 +2272,14 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) > error_report("WARNING: externally provided fw_cfg item names " > "should be prefixed with \"opt/\"!"); > } > - if (!g_file_get_contents(file, &buf, &size, NULL)) { > - error_report("can't load %s", file); > - return -1; > + if (nonempty_str(str)) { > + size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ > + buf = g_memdup(str, size); > + } else { > + if (!g_file_get_contents(file, &buf, &size, NULL)) { > + error_report("can't load %s", file); > + return -1; > + } > } > fw_cfg_add_file((FWCfgState *)opaque, name, buf, size); > return 0; >
On Mi, 2015-10-14 at 16:22 +0200, Laszlo Ersek wrote: > Paolo, > > On 09/29/15 18:29, Gabriel L. Somlo wrote: > > Allow users to provide custom fw_cfg blobs with ascii string > > payloads specified directly on the qemu command line. > > > > Suggested-by: Jordan Justen <jordan.l.justen@intel.com> > > Suggested-by: Laszlo Ersek <lersek@redhat.com> > > Signed-off-by: Gabriel Somlo <somlo@cmu.edu> > > Reviewd-by: Laszlo Ersek <lersek@redhat.com> > > --- > > > > New since v3: s/content/string/g for the option name, at Gerd's > > suggestion (to potentially allow for additional content > > types directly on the command line, should the need arise > > at a future date) > > > > Thanks, > > --Gabriel > > > > docs/specs/fw_cfg.txt | 15 +++++++++++++++ > > qemu-options.hx | 7 ++++++- > > vl.c | 33 +++++++++++++++++++++++++++------ > > 3 files changed, 48 insertions(+), 7 deletions(-) > > I'm sure you're going to want to give me a hug for bringing this up, but > can you please pick this up? O:-) > > Or maybe Peter can apply it directly? I guess I'll go prepare a fw_cfg pull request, probably tomorrow. There also is the fw_cfg_dma series from Marc ... While being at it: anything else which is ready? The fw_cfg acpi patches seem still to be on discussion still ... cheers, Gerd
On 10/15/15 11:24, Gerd Hoffmann wrote: > On Mi, 2015-10-14 at 16:22 +0200, Laszlo Ersek wrote: >> Paolo, >> >> On 09/29/15 18:29, Gabriel L. Somlo wrote: >>> Allow users to provide custom fw_cfg blobs with ascii string >>> payloads specified directly on the qemu command line. >>> >>> Suggested-by: Jordan Justen <jordan.l.justen@intel.com> >>> Suggested-by: Laszlo Ersek <lersek@redhat.com> >>> Signed-off-by: Gabriel Somlo <somlo@cmu.edu> >>> Reviewd-by: Laszlo Ersek <lersek@redhat.com> >>> --- >>> >>> New since v3: s/content/string/g for the option name, at Gerd's >>> suggestion (to potentially allow for additional content >>> types directly on the command line, should the need arise >>> at a future date) >>> >>> Thanks, >>> --Gabriel >>> >>> docs/specs/fw_cfg.txt | 15 +++++++++++++++ >>> qemu-options.hx | 7 ++++++- >>> vl.c | 33 +++++++++++++++++++++++++++------ >>> 3 files changed, 48 insertions(+), 7 deletions(-) >> >> I'm sure you're going to want to give me a hug for bringing this up, but >> can you please pick this up? O:-) >> >> Or maybe Peter can apply it directly? > > I guess I'll go prepare a fw_cfg pull request, probably tomorrow. > There also is the fw_cfg_dma series from Marc ... Great, thanks! > > While being at it: anything else which is ready? The fw_cfg acpi > patches seem still to be on discussion still ... That's my impression as well, yes. And, in any case, Marc's work and Gabriel's conflict (in context, not in purpose / implementation), so I guess Gabriel will have to rebase (purely because Marc's work has converged first). Thanks! Laszlo > > cheers, > Gerd > >
On Thu, Oct 15, 2015 at 05:50:03PM +0200, Laszlo Ersek wrote: > On 10/15/15 11:24, Gerd Hoffmann wrote: > > On Mi, 2015-10-14 at 16:22 +0200, Laszlo Ersek wrote: > >> Paolo, > >> > >> On 09/29/15 18:29, Gabriel L. Somlo wrote: > >>> Allow users to provide custom fw_cfg blobs with ascii string > >>> payloads specified directly on the qemu command line. > >>> > >>> Suggested-by: Jordan Justen <jordan.l.justen@intel.com> > >>> Suggested-by: Laszlo Ersek <lersek@redhat.com> > >>> Signed-off-by: Gabriel Somlo <somlo@cmu.edu> > >>> Reviewd-by: Laszlo Ersek <lersek@redhat.com> > >>> --- > >>> > >>> New since v3: s/content/string/g for the option name, at Gerd's > >>> suggestion (to potentially allow for additional content > >>> types directly on the command line, should the need arise > >>> at a future date) > >>> > >>> Thanks, > >>> --Gabriel > >>> > >>> docs/specs/fw_cfg.txt | 15 +++++++++++++++ > >>> qemu-options.hx | 7 ++++++- > >>> vl.c | 33 +++++++++++++++++++++++++++------ > >>> 3 files changed, 48 insertions(+), 7 deletions(-) > >> > >> I'm sure you're going to want to give me a hug for bringing this up, but > >> can you please pick this up? O:-) > >> > >> Or maybe Peter can apply it directly? > > > > I guess I'll go prepare a fw_cfg pull request, probably tomorrow. > > There also is the fw_cfg_dma series from Marc ... > > Great, thanks! > > > > > While being at it: anything else which is ready? The fw_cfg acpi > > patches seem still to be on discussion still ... > > That's my impression as well, yes. And, in any case, Marc's work and > Gabriel's conflict (in context, not in purpose / implementation), so I > guess Gabriel will have to rebase (purely because Marc's work has > converged first). That's right, and rebasing is what I had planned. Plus, I'll need to figure out how to write a guest-side kernel driver which works with both DT and ACPI, builds on all affected architectures, and hopefully doesn't need to use *too* many ifdefs in the process :) Cheers, --Gabriel
diff --git a/docs/specs/fw_cfg.txt b/docs/specs/fw_cfg.txt index b5f4b5d..a5ae930 100644 --- a/docs/specs/fw_cfg.txt +++ b/docs/specs/fw_cfg.txt @@ -236,6 +236,21 @@ the following syntax: where <item_name> is the fw_cfg item name, and <path> is the location on the host file system of a file containing the data to be inserted. +Small enough items may be provided directly as strings on the command +line, using the syntax: + + -fw_cfg [name=]<item_name>,string=<string> + +The terminating NUL character of the content <string> will NOT be +included as part of the fw_cfg item data, which is consistent with +the absence of a NUL terminator for items inserted via the file option. + +Both <item_name> and, if applicable, the content <string> are passed +through by QEMU without any interpretation, expansion, or further +processing. Any such processing (potentially performed e.g., by the shell) +is outside of QEMU's responsibility; as such, using plain ASCII characters +is recommended. + NOTE: Users *SHOULD* choose item names beginning with the prefix "opt/" when using the "-fw_cfg" command line option, to avoid conflicting with item names used internally by QEMU. For instance: diff --git a/qemu-options.hx b/qemu-options.hx index 328404c..408c5b4 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2724,13 +2724,18 @@ ETEXI DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg, "-fw_cfg [name=]<name>,file=<file>\n" - " add named fw_cfg entry from file\n", + " add named fw_cfg entry from file\n" + "-fw_cfg [name=]<name>,string=<str>\n" + " add named fw_cfg entry from string\n", QEMU_ARCH_ALL) STEXI @item -fw_cfg [name=]@var{name},file=@var{file} @findex -fw_cfg Add named fw_cfg entry from file. @var{name} determines the name of the entry in the fw_cfg file directory exposed to the guest. + +@item -fw_cfg [name=]@var{name},string=@var{str} +Add named fw_cfg entry from string. ETEXI DEF("serial", HAS_ARG, QEMU_OPTION_serial, \ diff --git a/vl.c b/vl.c index e211f6a..854bd8b 100644 --- a/vl.c +++ b/vl.c @@ -512,6 +512,10 @@ static QemuOptsList qemu_fw_cfg_opts = { .type = QEMU_OPT_STRING, .help = "Sets the name of the file from which\n" "the fw_cfg blob will be loaded", + }, { + .name = "string", + .type = QEMU_OPT_STRING, + .help = "Sets content of the blob to be inserted from a string", }, { /* end of list */ } }, @@ -2232,11 +2236,16 @@ char *qemu_find_file(int type, const char *name) return NULL; } +static inline bool nonempty_str(const char *str) +{ + return str && *str; +} + static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) { gchar *buf; size_t size; - const char *name, *file; + const char *name, *file, *str; if (opaque == NULL) { error_report("fw_cfg device not available"); @@ -2244,8 +2253,15 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) } name = qemu_opt_get(opts, "name"); file = qemu_opt_get(opts, "file"); - if (name == NULL || *name == '\0' || file == NULL || *file == '\0') { - error_report("invalid argument value"); + str = qemu_opt_get(opts, "string"); + + /* we need name and either a file or the content string */ + if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))) { + error_report("invalid argument(s)"); + return -1; + } + if (nonempty_str(file) && nonempty_str(str)) { + error_report("file and string are mutually exclusive"); return -1; } if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { @@ -2256,9 +2272,14 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) error_report("WARNING: externally provided fw_cfg item names " "should be prefixed with \"opt/\"!"); } - if (!g_file_get_contents(file, &buf, &size, NULL)) { - error_report("can't load %s", file); - return -1; + if (nonempty_str(str)) { + size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ + buf = g_memdup(str, size); + } else { + if (!g_file_get_contents(file, &buf, &size, NULL)) { + error_report("can't load %s", file); + return -1; + } } fw_cfg_add_file((FWCfgState *)opaque, name, buf, size); return 0;
Allow users to provide custom fw_cfg blobs with ascii string payloads specified directly on the qemu command line. Suggested-by: Jordan Justen <jordan.l.justen@intel.com> Suggested-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Gabriel Somlo <somlo@cmu.edu> Reviewd-by: Laszlo Ersek <lersek@redhat.com> --- New since v3: s/content/string/g for the option name, at Gerd's suggestion (to potentially allow for additional content types directly on the command line, should the need arise at a future date) Thanks, --Gabriel docs/specs/fw_cfg.txt | 15 +++++++++++++++ qemu-options.hx | 7 ++++++- vl.c | 33 +++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 7 deletions(-)