From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: linux-kernel@vger.kernel.org, slp@redhat.com, bhe@redhat.com,
somlo@cmu.edu, xiaolong.ye@intel.com
Subject: Re: [PATCH v11 4/4] fw_cfg: write vmcoreinfo details
Date: Fri, 2 Feb 2018 04:44:20 +0200 [thread overview]
Message-ID: <20180202044330-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20180201130300.9962-5-marcandre.lureau@redhat.com>
On Thu, Feb 01, 2018 at 02:03:00PM +0100, Marc-André Lureau wrote:
> @@ -314,6 +359,37 @@ struct fw_cfg_sysfs_entry {
> struct device *dev;
> };
>
> +#ifdef CONFIG_CRASH_CORE
> +static ssize_t write_vmcoreinfo(struct device *dev, const struct fw_cfg_file *f)
> +{
> + struct vmci {
> + __le16 host_format;
> + __le16 guest_format;
> + __le32 size;
> + __le64 paddr;
> + } __packed;
> + static struct vmci *data;
> + ssize_t ret;
> +
> + data = kmalloc(sizeof(struct vmci), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + *data = (struct vmci) {
> + .guest_format = cpu_to_le16(VMCOREINFO_FORMAT_ELF),
> + .size = cpu_to_le32(VMCOREINFO_NOTE_SIZE),
> + .paddr = cpu_to_le64(paddr_vmcoreinfo_note())
> + };
> + /* spare ourself reading host format support for now since we
> + * don't know what else to format - host may ignore ours
> + */
> + ret = fw_cfg_write_blob(dev, f->select, data, 0, sizeof(struct vmci));
> +
> + kfree(data);
> + return ret;
> +}
> +#endif /* CONFIG_CRASH_CORE */
> +
> /* get fw_cfg_sysfs_entry from kobject member */
> static inline struct fw_cfg_sysfs_entry *to_entry(struct kobject *kobj)
> {
kmalloc during crash is I think a bad idea.
How about preallocating on probe?
diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 33e0256..ffd81d1 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -363,22 +363,33 @@ struct fw_cfg_sysfs_entry {
};
#ifdef CONFIG_CRASH_CORE
+
+struct vmci {
+ __le16 host_format;
+ __le16 guest_format;
+ __le32 size;
+ __le64 paddr;
+} *fw_cfg_vmcore_data;
+
+static int fw_cfg_vmcore_init(void)
+{
+ fw_cfg_vmcore_data = kmalloc(sizeof(*fw_cfg_vmcore_data), GFP_KERNEL);
+ if (!fw_cfg_vmcore_data)
+ return -ENOMEM;
+ return 0;
+}
+
+static int fw_cfg_vmcore_cleanup(void)
+{
+ kfree(fw_cfg_vmcore_data);
+}
+
static ssize_t write_vmcoreinfo(struct device *dev, const struct fw_cfg_file *f)
{
- struct vmci {
- __le16 host_format;
- __le16 guest_format;
- __le32 size;
- __le64 paddr;
- } __packed;
static struct vmci *data;
ssize_t ret;
- data = kmalloc(sizeof(struct vmci), GFP_KERNEL);
- if (!data)
- return -ENOMEM;
-
- *data = (struct vmci) {
+ *fw_cfg_vmcore_data = (struct vmci) {
.guest_format = cpu_to_le16(VMCOREINFO_FORMAT_ELF),
.size = cpu_to_le32(VMCOREINFO_NOTE_SIZE),
.paddr = cpu_to_le64(paddr_vmcoreinfo_note())
@@ -386,11 +397,23 @@ static ssize_t write_vmcoreinfo(struct device *dev, const struct fw_cfg_file *f)
/* spare ourself reading host format support for now since we
* don't know what else to format - host may ignore ours
*/
- ret = fw_cfg_write_blob(dev, f->select, data, 0, sizeof(struct vmci));
+ ret = fw_cfg_write_blob(dev, f->select, fw_cfg_vmcore_data, 0,
+ sizeof(*fw_cfg_vmcore_data));
- kfree(data);
return ret;
}
+
+#else
+
+static int fw_cfg_vmcore_init(void)
+{
+ return 0;
+}
+
+static int fw_cfg_vmcore_cleanup(void)
+{
+}
+
#endif /* CONFIG_CRASH_CORE */
/* get fw_cfg_sysfs_entry from kobject member */
@@ -725,11 +748,15 @@ static int fw_cfg_sysfs_probe(struct platform_device *pdev)
if (fw_cfg_sel_ko)
return -EBUSY;
+ err = fw_cfg_vmcore_init();
+ if (err)
+ goto err_sel;
+
/* create by_key and by_name subdirs of /sys/firmware/qemu_fw_cfg/ */
err = -ENOMEM;
fw_cfg_sel_ko = kobject_create_and_add("by_key", fw_cfg_top_ko);
if (!fw_cfg_sel_ko)
- goto err_sel;
+ goto err_vmcore;
fw_cfg_fname_kset = kset_create_and_add("by_name", NULL, fw_cfg_top_ko);
if (!fw_cfg_fname_kset)
goto err_name;
@@ -764,6 +791,8 @@ static int fw_cfg_sysfs_probe(struct platform_device *pdev)
fw_cfg_kset_unregister_recursive(fw_cfg_fname_kset);
err_name:
fw_cfg_kobj_cleanup(fw_cfg_sel_ko);
+err_vmcore:
+ fw_cfg_vmcore_cleanup();
err_sel:
return err;
}
@@ -776,6 +805,7 @@ static int fw_cfg_sysfs_remove(struct platform_device *pdev)
fw_cfg_io_cleanup();
fw_cfg_kset_unregister_recursive(fw_cfg_fname_kset);
fw_cfg_kobj_cleanup(fw_cfg_sel_ko);
+ fw_cfg_vmcore_cleanup();
return 0;
}
next prev parent reply other threads:[~2018-02-02 2:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-01 13:02 [PATCH v11 0/4] fw_cfg: add DMA operations & etc/vmcoreinfo support Marc-André Lureau
2018-02-01 13:02 ` [PATCH v11 1/4] fw_cfg: add DMA register Marc-André Lureau
2018-02-01 13:02 ` [PATCH v11 2/4] fw_cfg: do DMA read operation Marc-André Lureau
2018-02-02 2:47 ` Michael S. Tsirkin
2018-02-01 13:02 ` [PATCH v11 3/4] crash: export paddr_vmcoreinfo_note() Marc-André Lureau
2018-02-01 13:03 ` [PATCH v11 4/4] fw_cfg: write vmcoreinfo details Marc-André Lureau
2018-02-02 2:44 ` Michael S. Tsirkin [this message]
2018-02-02 9:43 ` Marc-Andre Lureau
2018-02-02 2:50 ` [PATCH v11 0/4] fw_cfg: add DMA operations & etc/vmcoreinfo support Michael S. Tsirkin
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=20180202044330-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=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
Powered by JetHome