Received: by 10.223.176.5 with SMTP id f5csp527044wra; Fri, 2 Feb 2018 01:44:30 -0800 (PST) X-Google-Smtp-Source: AH8x2274jVmurrtbMJdbIBUkU7AwMyhfR+QTMKR5Iivhrai4S1iAgnhGOtpyBop9cKsmOk7ZSuLC X-Received: by 10.99.115.94 with SMTP id d30mr22021054pgn.172.1517564670541; Fri, 02 Feb 2018 01:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517564670; cv=none; d=google.com; s=arc-20160816; b=xTPoX/x8k0nRYdQE1WikyPMaYHn6jCuHPsltRJBc87DXiH1u1ixrLt3F3qgnMRq8SO 3ATSnDDMpzep5qpUcSlIoSQnEh6jAbhznt0iVWtp+J0bXZWIF5izU6YihEzA7u7G1p9+ aqh8lBVY1FFM86RPImxnWMIF9190yMKwL8v9if+1VKsSg1VrvrbM5WgpnJOxhGYKZySI qpcYViPzxXKmuYCxIEAIU7i0nUbyIOcie6Rna85rzR0Q5VY62IF/f8hYZrA1TszVrXLW 7saI4M1QtosO6tgFh5hi273wDdUvPU6THJ/4jb8HJhEjaU41tOF7AO6bHmZSRCDDEPe1 F1qw== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :arc-authentication-results; bh=WpEANsmAO3SFN8FTl+z3lmJmC2N/AqJTpzhlpBaJUlw=; b=ayXbRVwcAhPtiLmsyt3gYFMhFgvhVVmPCdXxOSUXWr2YpP9t/ZYlv7IXzJ/aXKFwCq L8Q40xIQvHzQp6t81eAmoPwwhlV6tUvsAQ3vtQTNCf+OJQaGiN8+SC4emddZs6xqK4Ht 3NbyU3ZBtZDUJD2A7gxPtaJe0yu9isN6M0f5c39/ruYUJ1A1JNbqmROJLA2vSoAArnDN ai/ip/4YCiPWXX2X224p2035wMZ7CM7SRRvH/OczboT73GsRxWX167zllP04tg6UYGCF rCHo5YK/AFsFs1gWMrm655i3eUnN8T9pgwC9Ihxmaig3ZoPgsM2n9+gW1Sew/fFd+7YA 5krw== 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 o6-v6si1424674pls.35.2018.02.02.01.44.14; Fri, 02 Feb 2018 01:44:30 -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 S1751656AbeBBJnt convert rfc822-to-8bit (ORCPT + 99 others); Fri, 2 Feb 2018 04:43:49 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:43466 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751567AbeBBJnp (ORCPT ); Fri, 2 Feb 2018 04:43:45 -0500 Received: by mail-qt0-f196.google.com with SMTP id m11so2593673qtn.10 for ; Fri, 02 Feb 2018 01:43:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Znc37Lk1ZS9XJ5MP2HZ0ySUPvT70mzuVTBRWPekD7wo=; b=M2oFc3A9l12V4Hh1624w20YO0rq+/9Acr/EYeSJlfsEEBaVJEDbhpTY1N6L87ESicw Hl5Q+XUWmC0IdKUiPUx/Mhn/ehBzKnyvMPk1p1rN/JaVe3Qa7ro/wZ4s3YFXynXiTda3 M1RryqRI73lOlKgwPOPeIN6e5+F90W+eDYEYORjv1wSbDGQ6JihOQfjmStmrpM9dbTMV a6Zr0nknc6xRLN/jZhpA3hPG9RuW3dJXTdIku8wSGkR9tV1kYJjc2j8ANZ5M9Frd30A6 1KYWM4N3cP46bcJkXEQ76mpS2pGnWrmhHy7EIgjfGL9ut6Zb1e0Yax8hsCYXdBeH2AND o59g== X-Gm-Message-State: APf1xPDZWWQL0/5JSt0ctukB5bQ2K78udAV18KcQZi17jtPFdRqr43KY XibDfSI+1Sbfq5F6TeHEy40sJpnNd4KBn3hX9iuHwg== X-Received: by 10.200.69.10 with SMTP id q10mr6659930qtn.167.1517564624735; Fri, 02 Feb 2018 01:43:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.146.155 with HTTP; Fri, 2 Feb 2018 01:43:44 -0800 (PST) In-Reply-To: <20180202044330-mutt-send-email-mst@kernel.org> References: <20180201130300.9962-1-marcandre.lureau@redhat.com> <20180201130300.9962-5-marcandre.lureau@redhat.com> <20180202044330-mutt-send-email-mst@kernel.org> From: Marc-Andre Lureau Date: Fri, 2 Feb 2018 10:43:44 +0100 Message-ID: Subject: Re: [PATCH v11 4/4] fw_cfg: write vmcoreinfo details To: "Michael S. Tsirkin" Cc: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Linux Kernel Mailing List , Sergio Lopez Pascual , Baoquan He , "Somlo, Gabriel" , xiaolong.ye@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi On Fri, Feb 2, 2018 at 3:44 AM, Michael S. Tsirkin wrote: > 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? It doesn't kmalloc during crash, it kmalloc during boot. As such, I don't see a reason to change it. > > 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; > } >