From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933338AbdKPB5v (ORCPT ); Wed, 15 Nov 2017 20:57:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42102 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932317AbdKPB5l (ORCPT ); Wed, 15 Nov 2017 20:57:41 -0500 Date: Thu, 16 Nov 2017 03:57:38 +0200 From: "Michael S. Tsirkin" To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: linux-kernel@vger.kernel.org, somlo@cmu.edu, qemu-devel@nongnu.org Subject: Re: [PATCH v6 5/5] fw_cfg: write vmcoreinfo details Message-ID: <20171116035606-mutt-send-email-mst@kernel.org> References: <20171113192958.22953-1-marcandre.lureau@redhat.com> <20171113192958.22953-6-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171113192958.22953-6-marcandre.lureau@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 16 Nov 2017 01:57:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 13, 2017 at 08:29:58PM +0100, Marc-André Lureau wrote: > If the "etc/vmcoreinfo" fw_cfg file is present and we are not running > the kdump kernel, write the addr/size of the vmcoreinfo ELF note. > > Signed-off-by: Marc-André Lureau > Reviewed-by: Gabriel Somlo > --- > drivers/firmware/qemu_fw_cfg.c | 87 +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 86 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c > index 2ac4cd869fe6..7a70e7a549f6 100644 > --- a/drivers/firmware/qemu_fw_cfg.c > +++ b/drivers/firmware/qemu_fw_cfg.c > @@ -35,6 +35,8 @@ > #include > #include > #include > +#include > +#include > > MODULE_AUTHOR("Gabriel L. Somlo "); > MODULE_DESCRIPTION("QEMU fw_cfg sysfs support"); > @@ -59,6 +61,8 @@ MODULE_LICENSE("GPL"); > /* fw_cfg "file name" is up to 56 characters (including terminating nul) */ > #define FW_CFG_MAX_FILE_PATH 56 > > +#define VMCOREINFO_FORMAT_ELF 0x1 > + > /* platform device for dma mapping */ > static struct device *dev; > > @@ -127,7 +131,8 @@ static ssize_t fw_cfg_dma_transfer(void *address, u32 length, u32 control) > dma_addr_t dma; > ssize_t ret = length; > enum dma_data_direction dir = > - (control & FW_CFG_DMA_CTL_READ ? DMA_FROM_DEVICE : 0); > + (control & FW_CFG_DMA_CTL_READ ? DMA_FROM_DEVICE : 0) | > + (control & FW_CFG_DMA_CTL_WRITE ? DMA_TO_DEVICE : 0); > > if (address && length) { > dma_addr = dma_map_single(dev, address, length, dir); > @@ -225,6 +230,48 @@ static ssize_t fw_cfg_read_blob(u16 key, > return ret; > } > > +#ifdef CONFIG_CRASH_CORE > +/* write chunk of given fw_cfg blob (caller responsible for sanity-check) */ > +static ssize_t fw_cfg_write_blob(u16 key, > + void *buf, loff_t pos, size_t count) > +{ > + u32 glk = -1U; > + acpi_status status; > + ssize_t ret = count; > + > + /* If we have ACPI, ensure mutual exclusion against any potential > + * device access by the firmware, e.g. via AML methods: > + */ > + status = acpi_acquire_global_lock(ACPI_WAIT_FOREVER, &glk); > + if (ACPI_FAILURE(status) && status != AE_NOT_CONFIGURED) { > + /* Should never get here */ > + WARN(1, "%s: Failed to lock ACPI!\n", __func__); > + memset(buf, 0, count); > + return -EINVAL; > + } > + > + mutex_lock(&fw_cfg_dev_lock); > + if (pos == 0) { > + ret = fw_cfg_dma_transfer(buf, count, key << 16 > + | FW_CFG_DMA_CTL_SELECT > + | FW_CFG_DMA_CTL_WRITE); > + } else { > + iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); > + ret = fw_cfg_dma_transfer(NULL, pos, FW_CFG_DMA_CTL_SKIP); > + if (ret < 0) > + goto end; > + ret = fw_cfg_dma_transfer(buf, count, FW_CFG_DMA_CTL_WRITE); > + } > + > +end: > + mutex_unlock(&fw_cfg_dev_lock); > + > + acpi_release_global_lock(glk); > + > + return ret; > +} > +#endif /* CONFIG_CRASH_CORE */ > + > /* clean up fw_cfg device i/o */ > static void fw_cfg_io_cleanup(void) > { > @@ -343,6 +390,37 @@ struct fw_cfg_sysfs_entry { > struct list_head list; > }; > > +#ifdef CONFIG_CRASH_CORE > +static ssize_t write_vmcoreinfo(const struct fw_cfg_file *f) > +{ > + struct vmci { > + __le16 host_format; > + __le16 guest_format; > + __le32 size; > + __le64 paddr; > + } __packed; > + struct vmci *data; > + ssize_t ret; > + > + data = kmalloc(sizeof(struct vmci), GFP_KERNEL | GFP_DMA); > + if (!data) > + return -ENOMEM; It's a small bit of data - you can just keep it in a global variable, this way failures won't be an issue. > + > + /* spare ourself reading host format support for now since we > + * don't know what else to format - host may ignore ours > + */ > + *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()) > + }; > + ret = fw_cfg_write_blob(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) > { > @@ -582,6 +660,13 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f) > int err; > struct fw_cfg_sysfs_entry *entry; > > +#ifdef CONFIG_CRASH_CORE > + if (strcmp(f->name, "etc/vmcoreinfo") == 0 && !is_kdump_kernel()) { > + if (write_vmcoreinfo(f) < 0) > + pr_warn("fw_cfg: failed to write vmcoreinfo"); > + } > +#endif > + > /* allocate new entry */ > entry = kzalloc(sizeof(*entry), GFP_KERNEL); > if (!entry) > -- > 2.15.0.125.g8f49766d64 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eF9R5-0004x9-R3 for qemu-devel@nongnu.org; Wed, 15 Nov 2017 20:57:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eF9R0-0003a2-VF for qemu-devel@nongnu.org; Wed, 15 Nov 2017 20:57:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48310) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eF9R0-0003ZI-L3 for qemu-devel@nongnu.org; Wed, 15 Nov 2017 20:57:42 -0500 Date: Thu, 16 Nov 2017 03:57:38 +0200 From: "Michael S. Tsirkin" Message-ID: <20171116035606-mutt-send-email-mst@kernel.org> References: <20171113192958.22953-1-marcandre.lureau@redhat.com> <20171113192958.22953-6-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20171113192958.22953-6-marcandre.lureau@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v6 5/5] fw_cfg: write vmcoreinfo details List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: linux-kernel@vger.kernel.org, somlo@cmu.edu, qemu-devel@nongnu.org On Mon, Nov 13, 2017 at 08:29:58PM +0100, Marc-Andr=E9 Lureau wrote: > If the "etc/vmcoreinfo" fw_cfg file is present and we are not running > the kdump kernel, write the addr/size of the vmcoreinfo ELF note. >=20 > Signed-off-by: Marc-Andr=E9 Lureau > Reviewed-by: Gabriel Somlo > --- > drivers/firmware/qemu_fw_cfg.c | 87 ++++++++++++++++++++++++++++++++++= +++++++- > 1 file changed, 86 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_= cfg.c > index 2ac4cd869fe6..7a70e7a549f6 100644 > --- a/drivers/firmware/qemu_fw_cfg.c > +++ b/drivers/firmware/qemu_fw_cfg.c > @@ -35,6 +35,8 @@ > #include > #include > #include > +#include > +#include > =20 > MODULE_AUTHOR("Gabriel L. Somlo "); > MODULE_DESCRIPTION("QEMU fw_cfg sysfs support"); > @@ -59,6 +61,8 @@ MODULE_LICENSE("GPL"); > /* fw_cfg "file name" is up to 56 characters (including terminating nu= l) */ > #define FW_CFG_MAX_FILE_PATH 56 > =20 > +#define VMCOREINFO_FORMAT_ELF 0x1 > + > /* platform device for dma mapping */ > static struct device *dev; > =20 > @@ -127,7 +131,8 @@ static ssize_t fw_cfg_dma_transfer(void *address, u= 32 length, u32 control) > dma_addr_t dma; > ssize_t ret =3D length; > enum dma_data_direction dir =3D > - (control & FW_CFG_DMA_CTL_READ ? DMA_FROM_DEVICE : 0); > + (control & FW_CFG_DMA_CTL_READ ? DMA_FROM_DEVICE : 0) | > + (control & FW_CFG_DMA_CTL_WRITE ? DMA_TO_DEVICE : 0); > =20 > if (address && length) { > dma_addr =3D dma_map_single(dev, address, length, dir); > @@ -225,6 +230,48 @@ static ssize_t fw_cfg_read_blob(u16 key, > return ret; > } > =20 > +#ifdef CONFIG_CRASH_CORE > +/* write chunk of given fw_cfg blob (caller responsible for sanity-che= ck) */ > +static ssize_t fw_cfg_write_blob(u16 key, > + void *buf, loff_t pos, size_t count) > +{ > + u32 glk =3D -1U; > + acpi_status status; > + ssize_t ret =3D count; > + > + /* If we have ACPI, ensure mutual exclusion against any potential > + * device access by the firmware, e.g. via AML methods: > + */ > + status =3D acpi_acquire_global_lock(ACPI_WAIT_FOREVER, &glk); > + if (ACPI_FAILURE(status) && status !=3D AE_NOT_CONFIGURED) { > + /* Should never get here */ > + WARN(1, "%s: Failed to lock ACPI!\n", __func__); > + memset(buf, 0, count); > + return -EINVAL; > + } > + > + mutex_lock(&fw_cfg_dev_lock); > + if (pos =3D=3D 0) { > + ret =3D fw_cfg_dma_transfer(buf, count, key << 16 > + | FW_CFG_DMA_CTL_SELECT > + | FW_CFG_DMA_CTL_WRITE); > + } else { > + iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); > + ret =3D fw_cfg_dma_transfer(NULL, pos, FW_CFG_DMA_CTL_SKIP); > + if (ret < 0) > + goto end; > + ret =3D fw_cfg_dma_transfer(buf, count, FW_CFG_DMA_CTL_WRITE); > + } > + > +end: > + mutex_unlock(&fw_cfg_dev_lock); > + > + acpi_release_global_lock(glk); > + > + return ret; > +} > +#endif /* CONFIG_CRASH_CORE */ > + > /* clean up fw_cfg device i/o */ > static void fw_cfg_io_cleanup(void) > { > @@ -343,6 +390,37 @@ struct fw_cfg_sysfs_entry { > struct list_head list; > }; > =20 > +#ifdef CONFIG_CRASH_CORE > +static ssize_t write_vmcoreinfo(const struct fw_cfg_file *f) > +{ > + struct vmci { > + __le16 host_format; > + __le16 guest_format; > + __le32 size; > + __le64 paddr; > + } __packed; > + struct vmci *data; > + ssize_t ret; > + > + data =3D kmalloc(sizeof(struct vmci), GFP_KERNEL | GFP_DMA); > + if (!data) > + return -ENOMEM; It's a small bit of data - you can just keep it in a global variable, this way failures won't be an issue. > + > + /* spare ourself reading host format support for now since we > + * don't know what else to format - host may ignore ours > + */ > + *data =3D (struct vmci) { > + .guest_format =3D cpu_to_le16(VMCOREINFO_FORMAT_ELF), > + .size =3D cpu_to_le32(VMCOREINFO_NOTE_SIZE), > + .paddr =3D cpu_to_le64(paddr_vmcoreinfo_note()) > + }; > + ret =3D fw_cfg_write_blob(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= ) > { > @@ -582,6 +660,13 @@ static int fw_cfg_register_file(const struct fw_cf= g_file *f) > int err; > struct fw_cfg_sysfs_entry *entry; > =20 > +#ifdef CONFIG_CRASH_CORE > + if (strcmp(f->name, "etc/vmcoreinfo") =3D=3D 0 && !is_kdump_kernel())= { > + if (write_vmcoreinfo(f) < 0) > + pr_warn("fw_cfg: failed to write vmcoreinfo"); > + } > +#endif > + > /* allocate new entry */ > entry =3D kzalloc(sizeof(*entry), GFP_KERNEL); > if (!entry) > --=20 > 2.15.0.125.g8f49766d64