From: "Michael S. Tsirkin" <mst@redhat.com>
To: Marc-Andre Lureau <mlureau@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"Baoquan He" <bhe@redhat.com>,
"Sergio Lopez Pascual" <slp@redhat.com>,
"Somlo, Gabriel" <somlo@cmu.edu>,
xiaolong.ye@intel.com
Subject: Re: [PATCH v14 9/9] RFC: fw_cfg: do DMA read operation
Date: Wed, 14 Feb 2018 19:12:03 +0200 [thread overview]
Message-ID: <20180214190943-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <CAMxuvaxC-JynbreyVet2KHNqWnuwqUyPyt-m3qjazW32c3e8Bg@mail.gmail.com>
On Wed, Feb 14, 2018 at 06:08:48PM +0100, Marc-Andre Lureau wrote:
> Hi
>
> On Wed, Feb 14, 2018 at 5:59 PM, Michael S. Tsirkin <mst@redhat.com> wrote:
> > On Wed, Feb 14, 2018 at 05:52:10PM +0100, Marc-Andre Lureau wrote:
> >> >> @@ -282,8 +320,9 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)
> >> >> #endif
> >> >>
> >> >> /* verify fw_cfg device signature */
> >> >> - fw_cfg_read_blob(FW_CFG_SIGNATURE, sig, 0, FW_CFG_SIG_SIZE);
> >> >> - if (memcmp(sig, "QEMU", FW_CFG_SIG_SIZE) != 0) {
> >> >> + if (fw_cfg_read_blob(FW_CFG_SIGNATURE, sig,
> >> >> + 0, FW_CFG_SIG_SIZE, false) < 0 ||
> >> >> + memcmp(sig, "QEMU", FW_CFG_SIG_SIZE) != 0) {
> >> >> fw_cfg_io_cleanup();
> >> >> return -ENODEV;
> >> >> }
> >> >
> >> > Rather than add dead code, how about a promise not to
> >> > fail if dma is disabled? Patch will be smaller then.
> >>
> >> Even with dma disabled, you could have a locking bug which was
> >> silently ignored before and is now taken into account.
> >
> > I see. I'd start with a patch reporting errors to users then.
> > That would be a bugfix and can be merged for this version.
>
> silently is the wrong word for it, there is already a WARN().
it's not visible to userspace though.
> However,
> the memcmp was done on uninitialzed sig[] (which likely resulted in
> returning -ENODEV in the function)
Oh, we have an access to an uninitialized memory too. Fun!
> Now it can check if the function failed to read before doing the memcmp.
>
> Hope that clarifies it.
I think I get it. I'd make it a bugfix patch as patch 7 in the series.
(patch 1-6 are applied in my tree, will merge in this window if they do not blow up).
> >
> >> >
> >> >> @@ -466,8 +505,8 @@ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp, struct kobject *kobj,
> >> >> if (count > entry->size - pos)
> >> >> count = entry->size - pos;
> >> >>
> >> >> - fw_cfg_read_blob(entry->select, buf, pos, count);
> >> >> - return count;
> >> >> + /* do not use DMA, virt_to_phys(buf) might not be ok */
> >> >> + return fw_cfg_read_blob(entry->select, buf, pos, count, false);
> >> >> }
> >> >>
> >> >> static struct bin_attribute fw_cfg_sysfs_attr_raw = {
> >> >> @@ -632,7 +671,12 @@ static int fw_cfg_register_dir_entries(void)
> >> >> struct fw_cfg_file *dir;
> >> >> size_t dir_size;
> >> >>
> >> >> - fw_cfg_read_blob(FW_CFG_FILE_DIR, &files.count, 0, sizeof(files.count));
> >> >> + ret = fw_cfg_read_blob(FW_CFG_FILE_DIR, &files.count,
> >> >> + 0, sizeof(files.count), false);
> >> >> + if (ret < 0) {
> >> >> + return ret;
> >> >> + }
> >> >> +
> >> >> count = be32_to_cpu(files.count);
> >> >> dir_size = count * sizeof(struct fw_cfg_file);
> >> >>
> >> >> @@ -640,7 +684,11 @@ static int fw_cfg_register_dir_entries(void)
> >> >> if (!dir)
> >> >> return -ENOMEM;
> >> >>
> >> >> - fw_cfg_read_blob(FW_CFG_FILE_DIR, dir, sizeof(files.count), dir_size);
> >> >> + ret = fw_cfg_read_blob(FW_CFG_FILE_DIR, dir,
> >> >> + sizeof(files.count), dir_size, false);
> >> >> + if (ret < 0) {
> >> >> + goto end;
> >> >> + }
> >> >>
> >> >> for (i = 0; i < count; i++) {
> >> >> ret = fw_cfg_register_file(&dir[i]);
> >> >> @@ -648,6 +696,7 @@ static int fw_cfg_register_dir_entries(void)
> >> >> break;
> >> >> }
> >> >>
> >> >> +end:
> >> >> kfree(dir);
> >> >> return ret;
> >> >> }
> >> >> @@ -688,7 +737,10 @@ static int fw_cfg_sysfs_probe(struct platform_device *pdev)
> >> >> goto err_probe;
> >> >>
> >> >> /* get revision number, add matching top-level attribute */
> >> >> - fw_cfg_read_blob(FW_CFG_ID, &rev, 0, sizeof(rev));
> >> >> + err = fw_cfg_read_blob(FW_CFG_ID, &rev, 0, sizeof(rev), false);
> >> >> + if (err < 0) {
> >> >> + goto err_probe;
> >> >> + }
> >> >> fw_cfg_rev = le32_to_cpu(rev);
> >> >> err = sysfs_create_file(fw_cfg_top_ko, &fw_cfg_rev_attr.attr);
> >> >> if (err)
> >> >> --
> >> >> 2.16.1.73.g5832b7e9f2
prev parent reply other threads:[~2018-02-14 17:12 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-14 14:18 [PATCH v14 0/9] fw_cfg: add DMA operations & etc/vmcoreinfo support Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 1/9] crash: export paddr_vmcoreinfo_note() Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 2/9] fw_cfg: add a public uapi header Marc-André Lureau
2018-02-14 19:37 ` Michael S. Tsirkin
2018-02-15 9:29 ` Marc-Andre Lureau
2018-02-15 18:22 ` Michael S. Tsirkin
2018-02-14 20:41 ` Michael S. Tsirkin
2018-02-15 9:25 ` Marc-Andre Lureau
2018-02-15 18:20 ` Michael S. Tsirkin
2018-02-15 18:33 ` Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 3/9] fw_cfg: fix sparse warnings in fw_cfg_sel_endianness() Marc-André Lureau
2018-02-14 20:46 ` Michael S. Tsirkin
2018-02-15 9:34 ` Marc-Andre Lureau
2018-02-15 18:25 ` Michael S. Tsirkin
2018-02-14 14:18 ` [PATCH v14 4/9] fw_cfg: fix sparse warnings with fw_cfg_file Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 5/9] fw_cfg: fix sparse warning reading FW_CFG_ID Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 6/9] fw_cfg: fix sparse warnings around FW_CFG_FILE_DIR read Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 7/9] fw_cfg: add DMA register Marc-André Lureau
2018-02-14 14:18 ` [PATCH v14 8/9] fw_cfg: write vmcoreinfo details Marc-André Lureau
2018-02-15 18:09 ` Michael S. Tsirkin
2018-02-15 18:24 ` Marc-André Lureau
2018-02-15 18:35 ` Michael S. Tsirkin
2018-02-14 14:18 ` [PATCH v14 9/9] RFC: fw_cfg: do DMA read operation Marc-André Lureau
2018-02-14 16:48 ` Michael S. Tsirkin
2018-02-14 16:52 ` Marc-Andre Lureau
2018-02-14 16:59 ` Michael S. Tsirkin
2018-02-14 17:08 ` Marc-Andre Lureau
2018-02-14 17:12 ` Michael S. Tsirkin [this message]
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=20180214190943-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=bhe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marcandre.lureau@redhat.com \
--cc=mlureau@redhat.com \
--cc=slp@redhat.com \
--cc=somlo@cmu.edu \
--cc=xiaolong.ye@intel.com \
/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