From nobody Mon Apr 29 08:40:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516725750042869.5961483303895; Tue, 23 Jan 2018 08:42:30 -0800 (PST) Received: from localhost ([::1]:39301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1eX-0004ot-9V for importer@patchew.org; Tue, 23 Jan 2018 11:42:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1d9-00042b-8n for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ee1d6-0005v7-3x for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47838) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ee1d5-0005ue-R8 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1E50780E8; Tue, 23 Jan 2018 16:40:58 +0000 (UTC) Received: from localhost (ovpn-112-59.ams2.redhat.com [10.36.112.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3B1F6A838; Tue, 23 Jan 2018 16:40:57 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-kernel@vger.kernel.org Date: Tue, 23 Jan 2018 17:40:38 +0100 Message-Id: <20180123164041.30339-2-marcandre.lureau@redhat.com> In-Reply-To: <20180123164041.30339-1-marcandre.lureau@redhat.com> References: <20180123164041.30339-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 23 Jan 2018 16:40:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v10 1/4] fw_cfg: add DMA register X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bhe@redhat.com, slp@redhat.com, mst@redhat.com, somlo@cmu.edu, xiaolong.ye@intel.com, peterx@redhat.com, qemu-devel@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add an optional kernel module (or command line) parameter using the following syntax: [qemu_fw_cfg.]ioport=3D@[::[:]] or [qemu_fw_cfg.]mmio=3D@[::[:]] and initializes the register address using given or default offset. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Gabriel Somlo --- drivers/firmware/qemu_fw_cfg.c | 53 ++++++++++++++++++++++++++++++++------= ---- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c index deb483064f53..740df0df2260 100644 --- a/drivers/firmware/qemu_fw_cfg.c +++ b/drivers/firmware/qemu_fw_cfg.c @@ -10,20 +10,21 @@ * and select subsets of aarch64), a Device Tree node (on arm), or using * a kernel module (or command line) parameter with the following syntax: * - * [qemu_fw_cfg.]ioport=3D@[::] + * [qemu_fw_cfg.]ioport=3D@[::[:]] * or - * [qemu_fw_cfg.]mmio=3D@[::] + * [qemu_fw_cfg.]mmio=3D@[::[:]] * * where: * :=3D size of ioport or mmio range * :=3D physical base address of ioport or mmio range * :=3D (optional) offset of control register * :=3D (optional) offset of data register + * :=3D (optional) offset of dma register * * e.g.: - * qemu_fw_cfg.ioport=3D2@0x510:0:1 (the default on x86) + * qemu_fw_cfg.ioport=3D12@0x510:0:1:4 (the default on x86) * or - * qemu_fw_cfg.mmio=3D0xA@0x9020000:8:0 (the default on arm) + * qemu_fw_cfg.mmio=3D16@0x9020000:8:0:16 (the default on arm) */ =20 #include @@ -63,6 +64,7 @@ static resource_size_t fw_cfg_p_size; static void __iomem *fw_cfg_dev_base; static void __iomem *fw_cfg_reg_ctrl; static void __iomem *fw_cfg_reg_data; +static void __iomem *fw_cfg_reg_dma; =20 /* atomic access to fw_cfg device (potentially slow i/o, so using mutex) */ static DEFINE_MUTEX(fw_cfg_dev_lock); @@ -118,12 +120,14 @@ static void fw_cfg_io_cleanup(void) # if (defined(CONFIG_ARM) || defined(CONFIG_ARM64)) # define FW_CFG_CTRL_OFF 0x08 # define FW_CFG_DATA_OFF 0x00 +# define FW_CFG_DMA_OFF 0x10 # elif (defined(CONFIG_PPC_PMAC) || defined(CONFIG_SPARC32)) /* ppc/mac,su= n4m */ # define FW_CFG_CTRL_OFF 0x00 # define FW_CFG_DATA_OFF 0x02 # elif (defined(CONFIG_X86) || defined(CONFIG_SPARC64)) /* x86, sun4u */ # define FW_CFG_CTRL_OFF 0x00 # define FW_CFG_DATA_OFF 0x01 +# define FW_CFG_DMA_OFF 0x04 # else # error "QEMU FW_CFG not available on this architecture!" # endif @@ -133,7 +137,7 @@ static void fw_cfg_io_cleanup(void) static int fw_cfg_do_platform_probe(struct platform_device *pdev) { char sig[FW_CFG_SIG_SIZE]; - struct resource *range, *ctrl, *data; + struct resource *range, *ctrl, *data, *dma; =20 /* acquire i/o range details */ fw_cfg_is_mmio =3D false; @@ -170,6 +174,7 @@ static int fw_cfg_do_platform_probe(struct platform_dev= ice *pdev) /* were custom register offsets provided (e.g. on the command line)? */ ctrl =3D platform_get_resource_byname(pdev, IORESOURCE_REG, "ctrl"); data =3D platform_get_resource_byname(pdev, IORESOURCE_REG, "data"); + dma =3D platform_get_resource_byname(pdev, IORESOURCE_REG, "dma"); if (ctrl && data) { fw_cfg_reg_ctrl =3D fw_cfg_dev_base + ctrl->start; fw_cfg_reg_data =3D fw_cfg_dev_base + data->start; @@ -179,6 +184,13 @@ static int fw_cfg_do_platform_probe(struct platform_de= vice *pdev) fw_cfg_reg_data =3D fw_cfg_dev_base + FW_CFG_DATA_OFF; } =20 + if (dma) + fw_cfg_reg_dma =3D fw_cfg_dev_base + dma->start; +#ifdef FW_CFG_DMA_OFF + else + fw_cfg_reg_dma =3D fw_cfg_dev_base + FW_CFG_DMA_OFF; +#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) !=3D 0) { @@ -629,6 +641,7 @@ static struct platform_device *fw_cfg_cmdline_dev; /* use special scanf/printf modifier for phys_addr_t, resource_size_t */ #define PH_ADDR_SCAN_FMT "@%" __PHYS_ADDR_PREFIX "i%n" \ ":%" __PHYS_ADDR_PREFIX "i" \ + ":%" __PHYS_ADDR_PREFIX "i%n" \ ":%" __PHYS_ADDR_PREFIX "i%n" =20 #define PH_ADDR_PR_1_FMT "0x%" __PHYS_ADDR_PREFIX "x@" \ @@ -638,12 +651,15 @@ static struct platform_device *fw_cfg_cmdline_dev; ":%" __PHYS_ADDR_PREFIX "u" \ ":%" __PHYS_ADDR_PREFIX "u" =20 +#define PH_ADDR_PR_4_FMT PH_ADDR_PR_3_FMT \ + ":%" __PHYS_ADDR_PREFIX "u" + static int fw_cfg_cmdline_set(const char *arg, const struct kernel_param *= kp) { - struct resource res[3] =3D {}; + struct resource res[4] =3D {}; char *str; phys_addr_t base; - resource_size_t size, ctrl_off, data_off; + resource_size_t size, ctrl_off, data_off, dma_off; int processed, consumed =3D 0; =20 /* only one fw_cfg device can exist system-wide, so if one @@ -659,19 +675,20 @@ static int fw_cfg_cmdline_set(const char *arg, const = struct kernel_param *kp) /* consume "" portion of command line argument */ size =3D memparse(arg, &str); =20 - /* get "@[::]" chunks */ + /* get "@[::[:]]" chunks */ processed =3D sscanf(str, PH_ADDR_SCAN_FMT, &base, &consumed, - &ctrl_off, &data_off, &consumed); + &ctrl_off, &data_off, &consumed, + &dma_off, &consumed); =20 - /* sscanf() must process precisely 1 or 3 chunks: + /* sscanf() must process precisely 1, 3 or 4 chunks: * is mandatory, optionally followed by - * and ; + * and , and ; * there must be no extra characters after the last chunk, * so str[consumed] must be '\0'. */ if (str[consumed] || - (processed !=3D 1 && processed !=3D 3)) + (processed !=3D 1 && processed !=3D 3 && processed !=3D 4)) return -EINVAL; =20 res[0].start =3D base; @@ -688,6 +705,11 @@ static int fw_cfg_cmdline_set(const char *arg, const s= truct kernel_param *kp) res[2].start =3D data_off; res[2].flags =3D IORESOURCE_REG; } + if (processed > 3) { + res[3].name =3D "dma"; + res[3].start =3D dma_off; + res[3].flags =3D IORESOURCE_REG; + } =20 /* "processed" happens to nicely match the number of resources * we need to pass in to this platform device. @@ -722,6 +744,13 @@ static int fw_cfg_cmdline_get(char *buf, const struct = kernel_param *kp) fw_cfg_cmdline_dev->resource[0].start, fw_cfg_cmdline_dev->resource[1].start, fw_cfg_cmdline_dev->resource[2].start); + case 4: + return snprintf(buf, PAGE_SIZE, PH_ADDR_PR_4_FMT, + resource_size(&fw_cfg_cmdline_dev->resource[0]), + fw_cfg_cmdline_dev->resource[0].start, + fw_cfg_cmdline_dev->resource[1].start, + fw_cfg_cmdline_dev->resource[2].start, + fw_cfg_cmdline_dev->resource[3].start); } =20 /* Should never get here */ --=20 2.16.0.rc1.1.gef27df75a1 From nobody Mon Apr 29 08:40:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516725975356524.8119446737768; Tue, 23 Jan 2018 08:46:15 -0800 (PST) Received: from localhost ([::1]:39484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1iA-0007YC-HP for importer@patchew.org; Tue, 23 Jan 2018 11:46:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1dK-0004Aj-53 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ee1dF-00062z-Rq for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28715) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ee1dF-000625-J0 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0D7C85541; Tue, 23 Jan 2018 16:41:08 +0000 (UTC) Received: from localhost (ovpn-112-59.ams2.redhat.com [10.36.112.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2BC4BA9C; Tue, 23 Jan 2018 16:41:00 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-kernel@vger.kernel.org Date: Tue, 23 Jan 2018 17:40:39 +0100 Message-Id: <20180123164041.30339-3-marcandre.lureau@redhat.com> In-Reply-To: <20180123164041.30339-1-marcandre.lureau@redhat.com> References: <20180123164041.30339-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 23 Jan 2018 16:41:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v10 2/4] fw_cfg: do DMA read operation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bhe@redhat.com, slp@redhat.com, mst@redhat.com, somlo@cmu.edu, xiaolong.ye@intel.com, peterx@redhat.com, qemu-devel@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify fw_cfg_read_blob() to use DMA if the device supports it. Return errors, because the operation may fail. The DMA operation is expected to run synchronously with today qemu, but the specification states that it may become async, so we run "control" field check in a loop for eventual changes. We may want to switch all the *buf addresses to use only kmalloc'ed buffers (instead of using stack/image addresses with dma=3Dfalse). Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Peter Xu --- drivers/firmware/qemu_fw_cfg.c | 131 ++++++++++++++++++++++++++++++++++---= ---- 1 file changed, 111 insertions(+), 20 deletions(-) diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c index 740df0df2260..686f0e839858 100644 --- a/drivers/firmware/qemu_fw_cfg.c +++ b/drivers/firmware/qemu_fw_cfg.c @@ -33,6 +33,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Gabriel L. Somlo "); MODULE_DESCRIPTION("QEMU fw_cfg sysfs support"); @@ -43,12 +44,22 @@ MODULE_LICENSE("GPL"); #define FW_CFG_ID 0x01 #define FW_CFG_FILE_DIR 0x19 =20 +#define FW_CFG_VERSION_DMA 0x02 +#define FW_CFG_DMA_CTL_ERROR 0x01 +#define FW_CFG_DMA_CTL_READ 0x02 +#define FW_CFG_DMA_CTL_SKIP 0x04 +#define FW_CFG_DMA_CTL_SELECT 0x08 +#define FW_CFG_DMA_CTL_WRITE 0x10 + /* size in bytes of fw_cfg signature */ #define FW_CFG_SIG_SIZE 4 =20 /* fw_cfg "file name" is up to 56 characters (including terminating nul) */ #define FW_CFG_MAX_FILE_PATH 56 =20 +/* fw_cfg revision attribute, in /sys/firmware/qemu_fw_cfg top-level dir. = */ +static u32 fw_cfg_rev; + /* fw_cfg file directory entry type */ struct fw_cfg_file { u32 size; @@ -57,6 +68,12 @@ struct fw_cfg_file { char name[FW_CFG_MAX_FILE_PATH]; }; =20 +struct fw_cfg_dma { + u32 control; + u32 length; + u64 address; +} __packed; + /* fw_cfg device i/o register addresses */ static bool fw_cfg_is_mmio; static phys_addr_t fw_cfg_p_base; @@ -75,12 +92,68 @@ static inline u16 fw_cfg_sel_endianness(u16 key) return fw_cfg_is_mmio ? cpu_to_be16(key) : cpu_to_le16(key); } =20 +static inline bool fw_cfg_dma_enabled(void) +{ + return fw_cfg_rev & FW_CFG_VERSION_DMA && fw_cfg_reg_dma; +} + +/* qemu fw_cfg device is sync today, but spec says it may become async */ +static void fw_cfg_wait_for_control(struct fw_cfg_dma *d) +{ + do { + u32 ctrl =3D be32_to_cpu(READ_ONCE(d->control)); + + if ((ctrl & ~FW_CFG_DMA_CTL_ERROR) =3D=3D 0) + return; + + usleep_range(50, 100); + } while (true); +} + +static ssize_t fw_cfg_dma_transfer(struct device *dev, + void *address, u32 length, u32 control) +{ + phys_addr_t dma; + struct fw_cfg_dma *d =3D NULL; + ssize_t ret =3D length; + + d =3D kmalloc(sizeof(*d), GFP_KERNEL); + if (!d) { + ret =3D -ENOMEM; + goto end; + } + + *d =3D (struct fw_cfg_dma) { + .address =3D cpu_to_be64(virt_to_phys(address)), + .length =3D cpu_to_be32(length), + .control =3D cpu_to_be32(control) + }; + + dma =3D virt_to_phys(d); + + iowrite32be((u64)dma >> 32, fw_cfg_reg_dma); + iowrite32be(dma, fw_cfg_reg_dma + 4); + + fw_cfg_wait_for_control(d); + + if (be32_to_cpu(READ_ONCE(d->control)) & FW_CFG_DMA_CTL_ERROR) { + ret =3D -EIO; + } + +end: + kfree(d); + + return ret; +} + /* read chunk of given fw_cfg blob (caller responsible for sanity-check) */ -static inline void fw_cfg_read_blob(u16 key, - void *buf, loff_t pos, size_t count) +static ssize_t fw_cfg_read_blob(struct device *dev, u16 key, + void *buf, loff_t pos, size_t count, + bool dma) { u32 glk =3D -1U; acpi_status status; + ssize_t ret =3D count; =20 /* If we have ACPI, ensure mutual exclusion against any potential * device access by the firmware, e.g. via AML methods: @@ -90,17 +163,36 @@ static inline void fw_cfg_read_blob(u16 key, /* Should never get here */ WARN(1, "fw_cfg_read_blob: Failed to lock ACPI!\n"); memset(buf, 0, count); - return; + return -EINVAL; } =20 mutex_lock(&fw_cfg_dev_lock); - iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); - while (pos-- > 0) - ioread8(fw_cfg_reg_data); - ioread8_rep(fw_cfg_reg_data, buf, count); + if (dma && fw_cfg_dma_enabled()) { + if (pos =3D=3D 0) { + ret =3D fw_cfg_dma_transfer(dev, buf, count, key << 16 + | FW_CFG_DMA_CTL_SELECT + | FW_CFG_DMA_CTL_READ); + } else { + iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); + ret =3D fw_cfg_dma_transfer(dev, NULL, pos, FW_CFG_DMA_CTL_SKIP); + if (ret < 0) + goto end; + ret =3D fw_cfg_dma_transfer(dev, buf, count, + FW_CFG_DMA_CTL_READ); + } + } else { + iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); + while (pos-- > 0) + ioread8(fw_cfg_reg_data); + ioread8_rep(fw_cfg_reg_data, buf, count); + } + +end: mutex_unlock(&fw_cfg_dev_lock); =20 acpi_release_global_lock(glk); + + return ret; } =20 /* clean up fw_cfg device i/o */ @@ -192,7 +284,7 @@ static int fw_cfg_do_platform_probe(struct platform_dev= ice *pdev) #endif =20 /* verify fw_cfg device signature */ - fw_cfg_read_blob(FW_CFG_SIGNATURE, sig, 0, FW_CFG_SIG_SIZE); + fw_cfg_read_blob(&pdev->dev, FW_CFG_SIGNATURE, sig, 0, FW_CFG_SIG_SIZE, f= alse); if (memcmp(sig, "QEMU", FW_CFG_SIG_SIZE) !=3D 0) { fw_cfg_io_cleanup(); return -ENODEV; @@ -201,9 +293,6 @@ static int fw_cfg_do_platform_probe(struct platform_dev= ice *pdev) return 0; } =20 -/* fw_cfg revision attribute, in /sys/firmware/qemu_fw_cfg top-level dir. = */ -static u32 fw_cfg_rev; - static ssize_t fw_cfg_showrev(struct kobject *k, struct attribute *a, char= *buf) { return sprintf(buf, "%u\n", fw_cfg_rev); @@ -222,6 +311,7 @@ struct fw_cfg_sysfs_entry { struct kobject kobj; struct fw_cfg_file f; struct list_head list; + struct device *dev; }; =20 /* get fw_cfg_sysfs_entry from kobject member */ @@ -344,6 +434,7 @@ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp,= struct kobject *kobj, char *buf, loff_t pos, size_t count) { struct fw_cfg_sysfs_entry *entry =3D to_entry(kobj); + struct device *dev =3D entry->dev; =20 if (pos > entry->f.size) return -EINVAL; @@ -351,8 +442,7 @@ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp,= struct kobject *kobj, if (count > entry->f.size - pos) count =3D entry->f.size - pos; =20 - fw_cfg_read_blob(entry->f.select, buf, pos, count); - return count; + return fw_cfg_read_blob(dev, entry->f.select, buf, pos, count, true); } =20 static struct bin_attribute fw_cfg_sysfs_attr_raw =3D { @@ -459,7 +549,7 @@ static struct kobject *fw_cfg_sel_ko; static struct kset *fw_cfg_fname_kset; =20 /* register an individual fw_cfg file */ -static int fw_cfg_register_file(const struct fw_cfg_file *f) +static int fw_cfg_register_file(struct device *dev, const struct fw_cfg_fi= le *f) { int err; struct fw_cfg_sysfs_entry *entry; @@ -471,6 +561,7 @@ static int fw_cfg_register_file(const struct fw_cfg_fil= e *f) =20 /* set file entry information */ memcpy(&entry->f, f, sizeof(struct fw_cfg_file)); + entry->dev =3D dev; =20 /* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */ err =3D kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype, @@ -498,14 +589,14 @@ static int fw_cfg_register_file(const struct fw_cfg_f= ile *f) } =20 /* iterate over all fw_cfg directory entries, registering each one */ -static int fw_cfg_register_dir_entries(void) +static int fw_cfg_register_dir_entries(struct device *dev) { int ret =3D 0; u32 count, i; struct fw_cfg_file *dir; size_t dir_size; =20 - fw_cfg_read_blob(FW_CFG_FILE_DIR, &count, 0, sizeof(count)); + fw_cfg_read_blob(dev, FW_CFG_FILE_DIR, &count, 0, sizeof(count), false); count =3D be32_to_cpu(count); dir_size =3D count * sizeof(struct fw_cfg_file); =20 @@ -513,12 +604,12 @@ static int fw_cfg_register_dir_entries(void) if (!dir) return -ENOMEM; =20 - fw_cfg_read_blob(FW_CFG_FILE_DIR, dir, sizeof(count), dir_size); + fw_cfg_read_blob(dev, FW_CFG_FILE_DIR, dir, sizeof(count), dir_size, true= ); =20 for (i =3D 0; i < count; i++) { dir[i].size =3D be32_to_cpu(dir[i].size); dir[i].select =3D be16_to_cpu(dir[i].select); - ret =3D fw_cfg_register_file(&dir[i]); + ret =3D fw_cfg_register_file(dev, &dir[i]); if (ret) break; } @@ -562,14 +653,14 @@ static int fw_cfg_sysfs_probe(struct platform_device = *pdev) goto err_probe; =20 /* get revision number, add matching top-level attribute */ - fw_cfg_read_blob(FW_CFG_ID, &fw_cfg_rev, 0, sizeof(fw_cfg_rev)); + fw_cfg_read_blob(&pdev->dev, FW_CFG_ID, &fw_cfg_rev, 0, sizeof(fw_cfg_rev= ), false); fw_cfg_rev =3D le32_to_cpu(fw_cfg_rev); err =3D sysfs_create_file(fw_cfg_top_ko, &fw_cfg_rev_attr.attr); if (err) goto err_rev; =20 /* process fw_cfg file directory entry, registering each file */ - err =3D fw_cfg_register_dir_entries(); + err =3D fw_cfg_register_dir_entries(&pdev->dev); if (err) goto err_dir; =20 --=20 2.16.0.rc1.1.gef27df75a1 From nobody Mon Apr 29 08:40:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516726066722376.59207087937455; Tue, 23 Jan 2018 08:47:46 -0800 (PST) Received: from localhost ([::1]:39550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1je-0008H1-1R for importer@patchew.org; Tue, 23 Jan 2018 11:47:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1dY-0004Ms-JG for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ee1dU-0006G9-Hu for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ee1dU-0006FT-Bi for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:24 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B0C55F739; Tue, 23 Jan 2018 16:41:23 +0000 (UTC) Received: from localhost (ovpn-112-59.ams2.redhat.com [10.36.112.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4639518AD6; Tue, 23 Jan 2018 16:41:10 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-kernel@vger.kernel.org Date: Tue, 23 Jan 2018 17:40:40 +0100 Message-Id: <20180123164041.30339-4-marcandre.lureau@redhat.com> In-Reply-To: <20180123164041.30339-1-marcandre.lureau@redhat.com> References: <20180123164041.30339-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 23 Jan 2018 16:41:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v10 3/4] crash: export paddr_vmcoreinfo_note() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tony Luck , bhe@redhat.com, slp@redhat.com, mst@redhat.com, somlo@cmu.edu, xiaolong.ye@intel.com, peterx@redhat.com, qemu-devel@nongnu.org, Hari Bathini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Andrew Morton , Dave Young , Vivek Goyal Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The following patch is going to use the symbol from the fw_cfg module, to call the function and write the note location details in the vmcoreinfo entry, so qemu can produce dumps with the vmcoreinfo note. CC: Andrew Morton CC: Baoquan He CC: Dave Young CC: Dave Young CC: Hari Bathini CC: Tony Luck CC: Vivek Goyal Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Gabriel Somlo --- kernel/crash_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 4f63597c824d..a93590cdd9e1 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -376,6 +376,7 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void) { return __pa(vmcoreinfo_note); } +EXPORT_SYMBOL(paddr_vmcoreinfo_note); =20 static int __init crash_save_vmcoreinfo_init(void) { --=20 2.16.0.rc1.1.gef27df75a1 From nobody Mon Apr 29 08:40:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516725860532739.6745656465132; Tue, 23 Jan 2018 08:44:20 -0800 (PST) Received: from localhost ([::1]:39376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1gJ-0006AT-T0 for importer@patchew.org; Tue, 23 Jan 2018 11:44:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee1e1-0004j1-TX for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ee1e0-0006h8-RO for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ee1e0-0006fD-Iq for qemu-devel@nongnu.org; Tue, 23 Jan 2018 11:41:56 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A78FC272C0; Tue, 23 Jan 2018 16:41:55 +0000 (UTC) Received: from localhost (ovpn-112-59.ams2.redhat.com [10.36.112.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id E429460BE1; Tue, 23 Jan 2018 16:41:24 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-kernel@vger.kernel.org Date: Tue, 23 Jan 2018 17:40:41 +0100 Message-Id: <20180123164041.30339-5-marcandre.lureau@redhat.com> In-Reply-To: <20180123164041.30339-1-marcandre.lureau@redhat.com> References: <20180123164041.30339-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 23 Jan 2018 16:41:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v10 4/4] fw_cfg: write vmcoreinfo details X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bhe@redhat.com, slp@redhat.com, mst@redhat.com, somlo@cmu.edu, xiaolong.ye@intel.com, peterx@redhat.com, qemu-devel@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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=C3=A9 Lureau Reviewed-by: Gabriel Somlo --- drivers/firmware/qemu_fw_cfg.c | 83 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 83 insertions(+) diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c index 686f0e839858..b4904649f316 100644 --- a/drivers/firmware/qemu_fw_cfg.c +++ b/drivers/firmware/qemu_fw_cfg.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Gabriel L. Somlo "); MODULE_DESCRIPTION("QEMU fw_cfg sysfs support"); @@ -57,6 +58,8 @@ MODULE_LICENSE("GPL"); /* fw_cfg "file name" is up to 56 characters (including terminating nul) */ #define FW_CFG_MAX_FILE_PATH 56 =20 +#define VMCOREINFO_FORMAT_ELF 0x1 + /* fw_cfg revision attribute, in /sys/firmware/qemu_fw_cfg top-level dir. = */ static u32 fw_cfg_rev; =20 @@ -195,6 +198,47 @@ static ssize_t fw_cfg_read_blob(struct device *dev, u1= 6 key, return ret; } =20 +#ifdef CONFIG_CRASH_CORE +/* write chunk of given fw_cfg blob (caller responsible for sanity-check) = */ +static ssize_t fw_cfg_write_blob(struct device *dev, 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__); + return -EINVAL; + } + + mutex_lock(&fw_cfg_dev_lock); + if (pos =3D=3D 0) { + ret =3D fw_cfg_dma_transfer(dev, 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(dev, NULL, pos, FW_CFG_DMA_CTL_SKIP); + if (ret < 0) + goto end; + ret =3D fw_cfg_dma_transfer(dev, 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) { @@ -314,6 +358,37 @@ struct fw_cfg_sysfs_entry { struct device *dev; }; =20 +#ifdef CONFIG_CRASH_CORE +static ssize_t write_vmcoreinfo(struct device *dev, const struct fw_cfg_fi= le *f) +{ + struct vmci { + __le16 host_format; + __le16 guest_format; + __le32 size; + __le64 paddr; + } __packed; + static struct vmci *data; + ssize_t ret; + + data =3D kmalloc(sizeof(struct vmci), GFP_KERNEL); + if (!data) + return -ENOMEM; + + *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()) + }; + /* spare ourself reading host format support for now since we + * don't know what else to format - host may ignore ours + */ + ret =3D 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) { @@ -554,6 +629,14 @@ static int fw_cfg_register_file(struct device *dev, co= nst struct fw_cfg_file *f) int err; struct fw_cfg_sysfs_entry *entry; =20 +#ifdef CONFIG_CRASH_CORE + if (fw_cfg_dma_enabled() && + strcmp(f->name, "etc/vmcoreinfo") =3D=3D 0 && !is_kdump_kernel()) { + if (write_vmcoreinfo(dev, 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.16.0.rc1.1.gef27df75a1