From: Laszlo Ersek <lersek@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
"Gabriel L. Somlo" <somlo@cmu.edu>
Cc: gsomlo@gmail.com, matt.fleming@intel.com, qemu-devel@nongnu.org,
kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH V4 4/4] fw_cfg: insert fw_cfg file blobs via qemu cmdline
Date: Mon, 01 Jun 2015 09:06:19 +0200 [thread overview]
Message-ID: <556C046B.9070704@redhat.com> (raw)
In-Reply-To: <20150531181048.GC5268@redhat.com>
On 05/31/15 20:10, Michael S. Tsirkin wrote:
> On Wed, Apr 29, 2015 at 11:21:53AM -0400, Gabriel L. Somlo wrote:
>> Allow user supplied files to be inserted into the fw_cfg
>> device before starting the guest. Since fw_cfg_add_file()
>> already disallows duplicate fw_cfg file names, qemu will
>> exit with an error message if the user supplies multiple
>> blobs with the same fw_cfg file name, or if a blob name
>> collides with a fw_cfg name programmatically added from
>> within the QEMU source code. A warning message will be
>> printed if the fw_cfg item name does not begin with the
>> prefix "opt/", which is recommended for external, user
>> provided blobs.
>>
>> Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
>> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> Would it make sense to make an illegal prefix a hard failure
> instead?
> If we don't, we'll be unable to add new file names without
> fear of conflicts in the future.
We discussed this earlier. The idea was "mechanism, not policy", and
that if a user violates the convention (not rule) / ignores the warning
at some point, he's on his own when it breaks in the next version.
I don't feel overly strongly about it; just "mechanism, not policy"
looks like a good tradition (well, good excuse anyway).
Thanks
Laszlo
>> ---
>> docs/specs/fw_cfg.txt | 21 +++++++++++++++++
>> qemu-options.hx | 11 +++++++++
>> vl.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 95 insertions(+)
>>
>> diff --git a/docs/specs/fw_cfg.txt b/docs/specs/fw_cfg.txt
>> index 6accd92..74351dd 100644
>> --- a/docs/specs/fw_cfg.txt
>> +++ b/docs/specs/fw_cfg.txt
>> @@ -203,3 +203,24 @@ completes fully overwriting the item's data.
>>
>> NOTE: This function is deprecated, and will be completely removed
>> starting with QEMU v2.4.
>> +
>> +== Externally Provided Items ==
>> +
>> +As of v2.4, "file" fw_cfg items (i.e., items with selector keys above
>> +FW_CFG_FILE_FIRST, and with a corresponding entry in the fw_cfg file
>> +directory structure) may be inserted via the QEMU command line, using
>> +the following syntax:
>> +
>> + -fw_cfg [name=]<item_name>,file=<path>
>> +
>> +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.
>> +
>> +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:
>> +
>> + -fw_cfg name=opt/my_item_name,file=./my_blob.bin
>> +
>> +Similarly, QEMU developers *SHOULD NOT* use item names prefixed with
>> +"opt/" when inserting items programmatically, e.g. via fw_cfg_add_file().
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index 319d971..aa386b4 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -2668,6 +2668,17 @@ STEXI
>> @table @option
>> ETEXI
>>
>> +DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg,
>> + "-fw_cfg [name=]<name>,file=<file>\n"
>> + " add named fw_cfg entry from file\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.
>> +ETEXI
>> +
>> DEF("serial", HAS_ARG, QEMU_OPTION_serial, \
>> "-serial dev redirect the serial port to char device 'dev'\n",
>> QEMU_ARCH_ALL)
>> diff --git a/vl.c b/vl.c
>> index 74c2681..b02b2d4 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -490,6 +490,25 @@ static QemuOptsList qemu_semihosting_config_opts = {
>> },
>> };
>>
>> +static QemuOptsList qemu_fw_cfg_opts = {
>> + .name = "fw_cfg",
>> + .implied_opt_name = "name",
>> + .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head),
>> + .desc = {
>> + {
>> + .name = "name",
>> + .type = QEMU_OPT_STRING,
>> + .help = "Sets the fw_cfg name of the blob to be inserted",
>> + }, {
>> + .name = "file",
>> + .type = QEMU_OPT_STRING,
>> + .help = "Sets the name of the file from which\n"
>> + "the fw_cfg blob will be loaded",
>> + },
>> + { /* end of list */ }
>> + },
>> +};
>> +
>> /**
>> * Get machine options
>> *
>> @@ -2118,6 +2137,38 @@ char *qemu_find_file(int type, const char *name)
>> return NULL;
>> }
>>
>> +static int parse_fw_cfg(QemuOpts *opts, void *opaque)
>> +{
>> + gchar *buf;
>> + size_t size;
>> + const char *name, *file;
>> +
>> + if (opaque == NULL) {
>> + error_report("fw_cfg device not available");
>> + return -1;
>> + }
>> + 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");
>> + return -1;
>> + }
>> + if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
>> + error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH - 1);
>> + return -1;
>> + }
>> + if (strncmp(name, "opt/", 4) != 0) {
>> + 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;
>> + }
>> + fw_cfg_add_file((FWCfgState *)opaque, name, buf, size);
>> + return 0;
>> +}
>> +
>> static int device_help_func(QemuOpts *opts, void *opaque)
>> {
>> return qdev_device_help(opts);
>> @@ -2806,6 +2857,7 @@ int main(int argc, char **argv, char **envp)
>> qemu_add_opts(&qemu_numa_opts);
>> qemu_add_opts(&qemu_icount_opts);
>> qemu_add_opts(&qemu_semihosting_config_opts);
>> + qemu_add_opts(&qemu_fw_cfg_opts);
>>
>> runstate_init();
>>
>> @@ -3422,6 +3474,12 @@ int main(int argc, char **argv, char **envp)
>> }
>> do_smbios_option(opts);
>> break;
>> + case QEMU_OPTION_fwcfg:
>> + opts = qemu_opts_parse(qemu_find_opts("fw_cfg"), optarg, 1);
>> + if (opts == NULL) {
>> + exit(1);
>> + }
>> + break;
>> case QEMU_OPTION_enable_kvm:
>> olist = qemu_find_opts("machine");
>> qemu_opts_parse(olist, "accel=kvm", 0);
>> @@ -4233,6 +4291,11 @@ int main(int argc, char **argv, char **envp)
>>
>> numa_post_machine_init();
>>
>> + if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
>> + parse_fw_cfg, fw_cfg_find(), 1) != 0) {
>> + exit(1);
>> + }
>> +
>> /* init USB devices */
>> if (usb_enabled()) {
>> if (foreach_device_config(DEV_USB, usb_parse) < 0)
>> --
>> 2.1.0
>>
next prev parent reply other threads:[~2015-06-01 7:06 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-29 15:21 [Qemu-devel] [PATCH V4 0/4] fw-cfg: cleanup and user-provided command line blobs Gabriel L. Somlo
2015-04-29 15:21 ` [Qemu-devel] [PATCH V4 1/4] fw_cfg: remove support for guest-side data writes Gabriel L. Somlo
2015-04-29 15:21 ` [Qemu-devel] [PATCH V4 2/4] fw_cfg: prevent selector key conflict Gabriel L. Somlo
2015-04-29 15:21 ` [Qemu-devel] [PATCH V4 3/4] fw_cfg: prohibit insertion of duplicate fw_cfg file names Gabriel L. Somlo
2015-04-29 15:21 ` [Qemu-devel] [PATCH V4 4/4] fw_cfg: insert fw_cfg file blobs via qemu cmdline Gabriel L. Somlo
2015-05-31 18:10 ` Michael S. Tsirkin
2015-06-01 7:06 ` Laszlo Ersek [this message]
2015-06-01 7:28 ` Michael S. Tsirkin
2015-06-01 9:01 ` Paolo Bonzini
2015-06-01 10:23 ` Michael S. Tsirkin
2015-06-01 10:35 ` Laszlo Ersek
2015-06-01 10:42 ` Michael S. Tsirkin
2015-06-01 11:19 ` Laszlo Ersek
2015-06-01 10:43 ` Paolo Bonzini
2015-06-01 10:48 ` Michael S. Tsirkin
2015-06-01 10:50 ` Paolo Bonzini
2015-06-01 11:00 ` Michael S. Tsirkin
2015-06-01 11:18 ` Paolo Bonzini
2015-06-01 11:05 ` Gabriel L. Somlo
2015-06-01 11:20 ` Markus Armbruster
2015-06-01 11:21 ` Paolo Bonzini
2015-06-01 11:26 ` Laszlo Ersek
2015-06-01 12:38 ` Michael S. Tsirkin
2015-06-01 12:39 ` Paolo Bonzini
2015-06-01 12:41 ` Michael S. Tsirkin
2015-06-01 12:43 ` Paolo Bonzini
2015-06-02 7:37 ` Gerd Hoffmann
2015-06-02 8:28 ` Michael S. Tsirkin
2015-06-02 9:43 ` Gerd Hoffmann
2015-06-01 13:21 ` Laszlo Ersek
2015-06-01 11:24 ` Laszlo Ersek
2015-05-18 13:05 ` [Qemu-devel] [PATCH V4 0/4] fw-cfg: cleanup and user-provided command line blobs Gabriel L. Somlo
2015-05-29 12:41 ` Gerd Hoffmann
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=556C046B.9070704@redhat.com \
--to=lersek@redhat.com \
--cc=gsomlo@gmail.com \
--cc=kraxel@redhat.com \
--cc=matt.fleming@intel.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=somlo@cmu.edu \
/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).