Received: by 10.223.164.221 with SMTP id h29csp4015033wrb; Tue, 31 Oct 2017 08:22:01 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Ro2l4+ZjRtYbu8CfP5YWEWQlZLHeYNoF1B19ZnjPWhXQDHCFhCkuz1mu6o0vvC8lXlpKX+ X-Received: by 10.99.109.14 with SMTP id i14mr2126254pgc.355.1509463321317; Tue, 31 Oct 2017 08:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509463321; cv=none; d=google.com; s=arc-20160816; b=ovMBQFzNLARIuHcmBcdvkbwwSxjWGMeMrql3Ukr/P/KvZLWxLIF/18dSaOWa74PGve L1tAZz8SijKcINpYoGPX8q7nyJ5Vr2fNRIUHP7KwmM7n1RAISxuZL/A61Kc5JGeJiEdd 1lMB+38Ucq1zA2C0PsTxfxo0tiiWbFU2k3ko65iY/udosGqZI1WWuwtcyRNYsM4CD6Ie snp4TETk+L5ccig8nt4CL0lpPYVpkkzBTQB/4xyByoxAppFHWR1jeMa8QRVE+YIQC/R/ jfb92+WdX5T/jpca5rVz9WwpfQJNxq7dlNCXixKzEJOjlQVIBe+U4PmK8fyOvUXzxTp/ /RCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dmarc-filter:arc-authentication-results; bh=FgbSFN8qk409kxS4eV8HXV9W/7tIcX3+jdJxVw0M4J8=; b=MVkymgzSxh71VKL8lafSyZWcyKvtghre6mG0EqXatW+Wnb6C9BzZK+YQE93exj6jj+ xpTD7Eo9aSw1HIeBPgSYkVSkiTpL+MTqiKbIfWB/+KLZ5d3PFZlIb2Zo4Pt60XbCLc+/ W5r3PY6cAPNhpBj2xJjo5zv4nduQ8zZtbwDGglEHDoRx0hnl7vm8RFKYxGmap2rTsbmJ cVkN//CxCNYLXWuDeznSbLYUqZnho3xsuARWFI1jg29geeLNmgr9+7Mu9910MslzVJcw 3ziBFR7+JrOW4wwYFihlViK2b4oqMThj1AhXR7SPFUH1BFDhQeVVneh4O6pk/L9Sp3Rg IRSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si1707266plg.194.2017.10.31.08.21.47; Tue, 31 Oct 2017 08:22:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753714AbdJaPUq (ORCPT + 99 others); Tue, 31 Oct 2017 11:20:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43107 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753693AbdJaPUp (ORCPT ); Tue, 31 Oct 2017 11:20:45 -0400 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 10378C00DBA6; Tue, 31 Oct 2017 15:20:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 10378C00DBA6 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (ovpn-112-65.ams2.redhat.com [10.36.112.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C4E9600D2; Tue, 31 Oct 2017 15:20:30 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-kernel@vger.kernel.org Cc: somlo@cmu.edu, qemu-devel@nongnu.org, mst@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v4 5/5] fw_cfg: write vmcoreinfo details Date: Tue, 31 Oct 2017 16:19:38 +0100 Message-Id: <20171031151938.14982-6-marcandre.lureau@redhat.com> In-Reply-To: <20171031151938.14982-1-marcandre.lureau@redhat.com> References: <20171031151938.14982-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.31]); Tue, 31 Oct 2017 15:20:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 8ce5e49b7c62..ebd9bb134900 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 -EBUSY; + } + + 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(0, 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; + + /* 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.rc0.40.gaefcc5f6f From 1583356855699916626@xxx Mon Nov 06 22:19:26 +0000 2017 X-GM-THRID: 1583356855699916626 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread