Received: by 10.223.176.5 with SMTP id f5csp222575wra; Thu, 1 Feb 2018 19:00:41 -0800 (PST) X-Google-Smtp-Source: AH8x227/ko9mi/4GL3QvNL8Y9XUqvlXVJb8TPUYsfINzKKoYHClwgpoB7Jp+yLVJD21pSaBjSuvg X-Received: by 10.99.143.2 with SMTP id n2mr32014678pgd.14.1517540441278; Thu, 01 Feb 2018 19:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517540441; cv=none; d=google.com; s=arc-20160816; b=SWK6wKKxLJEiZglchiluDUw3L3uKecW0ZuQH2nlafgm4J9CIGnSoXntW8T5TRW5vZ+ krw6jgC7XDRCTL9ucfHaLDLPVEQgHFzb8/39AkHkG4ENRKTTG+MuMrtPRj3uTsYlImmH Ee098JlzB5e97J6yLV6/ywvOHBK4bk9ZCnn0OtAqsZ95ghx/IlIydIRlxQGssQKxDiJt 7rxJ8fgllaa77wPCw1+QxKH/kiYV6YZVl4mDqWg7gkMmN1qf6fk/jA2nUMf8D8cYtsfV rokc5UrwBZM8qjuCtt1C1Tl+KUA4NQOAjhP413EafLw0f75hBwsqMCn8jxqqmtPjkvNA jiyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=MglWVCmhLigEAdSJaALfxpyF/pv9o/9TreJ3rKB3Bjk=; b=jx2JewaP9WP7r8I9AvF23IBHkS9Cmx9atXPDf6ZMJEsYGQMG/jYd+xx5PmjffkpjjM 8VdH5VjUybz2DzIEGc4STxn3L6gcCbuNGU903+3CTU8H9ApO32cgzK5PVGGC9CzFTkx/ o7VUMHWSlQHKHArsJoQtCK+k+SO3SDGJY3X3j1HPesehXjOAv0PYDlQLUXiny/CShCi9 xaXe3Zeca9QDFfqHkiD7q2GclorvefkAXE4cEB1JPJ36+10KGJJcfqZZY4kM3/qMDli5 qclIqmGORVFPiGbLBkjy8is0dIhYW+drbw8IXE21QWrNJuoWsplkuAxd+DHXoaMJIt56 rxRA== 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 w13si711008pgq.199.2018.02.01.19.00.26; Thu, 01 Feb 2018 19:00:41 -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 S1751660AbeBBCob (ORCPT + 99 others); Thu, 1 Feb 2018 21:44:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56886 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751521AbeBBCoZ (ORCPT ); Thu, 1 Feb 2018 21:44:25 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB0D54E906; Fri, 2 Feb 2018 02:44:25 +0000 (UTC) Received: from redhat.com (ovpn-121-50.rdu2.redhat.com [10.10.121.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id B09265D9CC; Fri, 2 Feb 2018 02:44:20 +0000 (UTC) Date: Fri, 2 Feb 2018 04:44:20 +0200 From: "Michael S. Tsirkin" To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau 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 Message-ID: <20180202044330-mutt-send-email-mst@kernel.org> References: <20180201130300.9962-1-marcandre.lureau@redhat.com> <20180201130300.9962-5-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: <20180201130300.9962-5-marcandre.lureau@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 02 Feb 2018 02:44:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; }