Received: by 10.223.176.46 with SMTP id f43csp4387621wra; Tue, 23 Jan 2018 08:42:53 -0800 (PST) X-Google-Smtp-Source: AH8x224PDN63axgpMjqd0xio2KKc3HqKCY5jiNnLTfJRzzVN1nZcmodrf1f8fhb2AnoL4//gVRmF X-Received: by 10.36.5.15 with SMTP id 15mr4200881itl.123.1516725773872; Tue, 23 Jan 2018 08:42:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516725773; cv=none; d=google.com; s=arc-20160816; b=wTOfhhErL9pcx6ipTKd6zJzkYW1N2/8FY+ASYiKrrnO+Rqx8REI2YSKMdOWlNdQlkX Vf4X16RKkiRczr5j0Tl4JR4yV/wHhKxFUZkL6JZn2ixwEt8LwA1l0Xyw4iKm8ynT9XZa mQRnHrd2pqH//4k4gFNNAJ8wR5uforplBGK1EwAfqK/A8OlY+Cgq4uLic+U46LW0/H5/ EPD0vKBGF3QChHp2oHMsZT1ATAnai2ZFKTUE+ZCT9aofl8ErtO9ulz0h/58WsgrPWAqS +74sjc6f5Mf8ybP1U23KAt0FnBNocECx4QikR91GgESiG2oQe3C6uR4Nja24Pny+vAKe 8qWA== 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 :arc-authentication-results; bh=KVM+LWygrOzKoO6bK+ISaTIopAVVtIeY7Iz0qImbJb4=; b=TCoub3EllcTlruA8+MGoX24sUV0sC4rnJb0BSTMWGY5ZhpNqaWW9OPCJ5nCYs46kAR qjvksmCST2OlqGXCxalGwQJR6TMQPZyc1f7gsDrPb8qIqcyqPNvYa7CqwSsQ5Tqs6U1o VVEVEcqMyFGDvcQfIUclKLDXaBMMUSPeEVCp/hLLg/YkkhdmoG2oAzzyyCw1S+/rVs8E 3Qo/ek+RyleODWlgrHWCL79azasbI3efRm5CLVAnZgf5rh2wp2OuO9/WWXZQQUngEjUT 8db1A6rz9o+3bzW/ffepK4U5EDYWLCrfUUF4MNQ/U/FfxzM+p7i714Ly/pSlGOfGyWXv gaHQ== 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 v186si8534023itc.139.2018.01.23.08.42.41; Tue, 23 Jan 2018 08:42:53 -0800 (PST) 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 S1752020AbeAWQl7 (ORCPT + 99 others); Tue, 23 Jan 2018 11:41:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44552 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751916AbeAWQlz (ORCPT ); Tue, 23 Jan 2018 11:41:55 -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 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?= Subject: [PATCH v10 4/4] fw_cfg: write vmcoreinfo details 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) 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 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 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 +#define VMCOREINFO_FORMAT_ELF 0x1 + /* fw_cfg revision attribute, in /sys/firmware/qemu_fw_cfg top-level dir. */ static u32 fw_cfg_rev; @@ -195,6 +198,47 @@ static ssize_t fw_cfg_read_blob(struct device *dev, 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(struct device *dev, 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__); + return -EINVAL; + } + + mutex_lock(&fw_cfg_dev_lock); + if (pos == 0) { + ret = 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 = fw_cfg_dma_transfer(dev, NULL, pos, FW_CFG_DMA_CTL_SKIP); + if (ret < 0) + goto end; + ret = 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; }; +#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) { @@ -554,6 +629,14 @@ static int fw_cfg_register_file(struct device *dev, const struct fw_cfg_file *f) int err; struct fw_cfg_sysfs_entry *entry; +#ifdef CONFIG_CRASH_CORE + if (fw_cfg_dma_enabled() && + strcmp(f->name, "etc/vmcoreinfo") == 0 && !is_kdump_kernel()) { + if (write_vmcoreinfo(dev, f) < 0) + pr_warn("fw_cfg: failed to write vmcoreinfo"); + } +#endif + /* allocate new entry */ entry = kzalloc(sizeof(*entry), GFP_KERNEL); if (!entry) -- 2.16.0.rc1.1.gef27df75a1