From patchwork Mon Oct 10 00:35:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9368799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9FE646048F for ; Mon, 10 Oct 2016 00:35:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92690288B0 for ; Mon, 10 Oct 2016 00:35:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8653D288C5; Mon, 10 Oct 2016 00:35:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C409D288B0 for ; Mon, 10 Oct 2016 00:35:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B76331A1E48; Sun, 9 Oct 2016 17:35:53 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3781A1A1E48 for ; Sun, 9 Oct 2016 17:35:52 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP; 09 Oct 2016 17:35:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,469,1473145200"; d="scan'208";a="178161540" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by fmsmga004.fm.intel.com with ESMTP; 09 Oct 2016 17:35:49 -0700 From: Haozhong Zhang To: linux-nvdimm@lists.01.org, xen-devel@lists.xenproject.org Subject: [RFC KERNEL PATCH 2/2] xen, nvdimm: report pfn devices in PFN_MODE_XEN to Xen hypervisor Date: Mon, 10 Oct 2016 08:35:23 +0800 Message-Id: <20161010003523.4423-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161010003523.4423-1-haozhong.zhang@intel.com> References: <20161010003523.4423-1-haozhong.zhang@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Xiao Guangrong , Arnd Bergmann , linux-kernel@vger.kernel.org, Stefano Stabellini , David Vrabel , Boris Ostrovsky MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Xen hypervisor does not include NVDIMM driver and relies on the driver in Dom0 Linux to probe pfn devices in PFN_MODE_XEN. Whenever such a pfn device is probed, Dom0 Linux reports pages of the entire device, its reserved area and data area to Xen hypervisor. Signed-off-by: Haozhong Zhang --- Cc: Ross Zwisler Cc: Dan Williams Cc: Boris Ostrovsky Cc: David Vrabel Cc: Juergen Gross Cc: Stefano Stabellini Cc: Arnd Bergmann Cc: linux-kernel@vger.kernel.org Cc: xen-devel@lists.xenproject.org --- drivers/nvdimm/pmem.c | 25 +++++++++++++++++++ drivers/xen/Makefile | 2 +- drivers/xen/pmem.c | 53 ++++++++++++++++++++++++++++++++++++++++ include/xen/interface/platform.h | 13 ++++++++++ include/xen/pmem.h | 32 ++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 drivers/xen/pmem.c create mode 100644 include/xen/pmem.h diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index d2c9ead..eab1ee4 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -33,6 +33,11 @@ #include "pfn.h" #include "nd.h" +#ifdef CONFIG_XEN +#include +#include +#endif + static struct device *to_dev(struct pmem_device *pmem) { /* @@ -364,6 +369,26 @@ static int pmem_attach_disk(struct device *dev, revalidate_disk(disk); +#ifdef CONFIG_XEN + if (xen_initial_domain() && is_nd_pfn_xen(dev)) { + uint64_t rsv_off, rsv_size, data_off, data_size; + int err; + + rsv_off = le64_to_cpu(pfn_sb->start_pad) + + PFN_PHYS(altmap->reserve); + rsv_size = PFN_PHYS(altmap->free); + data_off = le32_to_cpu(pfn_sb->start_pad) + pmem->data_offset; + data_size = pmem->size - pmem->pfn_pad - pmem->data_offset; + + err = xen_pmem_add(pmem->phys_addr, pmem->size, + rsv_off, rsv_size, data_off, data_size); + if (err) { + dev_err(dev, "failed to register to Xen\n"); + return err; + } + } +#endif + return 0; } diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index 8feab810..7f95156 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile @@ -1,6 +1,6 @@ obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o obj-$(CONFIG_X86) += fallback.o -obj-y += grant-table.o features.o balloon.o manage.o preempt.o time.o +obj-y += grant-table.o features.o balloon.o manage.o preempt.o time.o pmem.o obj-y += events/ obj-y += xenbus/ diff --git a/drivers/xen/pmem.c b/drivers/xen/pmem.c new file mode 100644 index 0000000..bb027a5 --- /dev/null +++ b/drivers/xen/pmem.c @@ -0,0 +1,53 @@ +/****************************************************************************** + * pmem.c + * pmem file for domain 0 kernel + * + * Copyright (c) 2016, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Author: Haozhong Zhang + */ + +#include +#include +#include + +int xen_pmem_add(uint64_t spa, size_t size, + uint64_t rsv_off, size_t rsv_size, + uint64_t data_off, size_t data_size) +{ + int rc; + struct xen_platform_op op; + + if ((spa | size | rsv_off | rsv_size | data_off | data_size) & + (PAGE_SIZE - 1)) + return -EINVAL; + + op.cmd = XENPF_pmem_add; + op.u.pmem_add.spfn = PHYS_PFN(spa); + op.u.pmem_add.epfn = PHYS_PFN(spa) + PHYS_PFN(size); + op.u.pmem_add.rsv_spfn = PHYS_PFN(spa + rsv_off); + op.u.pmem_add.rsv_epfn = PHYS_PFN(spa + rsv_off + rsv_size); + op.u.pmem_add.data_spfn = PHYS_PFN(spa + data_off); + op.u.pmem_add.data_epfn = PHYS_PFN(spa + data_off + data_size); + + rc = HYPERVISOR_platform_op(&op); + if (rc) + pr_err("Xen pmem add failed on 0x%llx ~ 0x%llx, error: %d\n", + spa, spa + size, rc); + + return rc; +} +EXPORT_SYMBOL(xen_pmem_add); diff --git a/include/xen/interface/platform.h b/include/xen/interface/platform.h index 732efb0..6c51f0c 100644 --- a/include/xen/interface/platform.h +++ b/include/xen/interface/platform.h @@ -500,6 +500,18 @@ struct xenpf_symdata { }; DEFINE_GUEST_HANDLE_STRUCT(xenpf_symdata); +#define XENPF_pmem_add 64 +struct xenpf_pmem_add { + /* IN variables */ + uint64_t spfn; /* start PFN of the whole pmem region */ + uint64_t epfn; /* end PFN of the whole pmem region */ + uint64_t rsv_spfn; /* start PFN of the reserved area */ + uint64_t rsv_epfn; /* end PFN of the reserved area */ + uint64_t data_spfn; /* start PFN of the data area */ + uint64_t data_epfn; /* end PFN of the data area */ +}; +DEFINE_GUEST_HANDLE_STRUCT(xenpf_pmem_add); + struct xen_platform_op { uint32_t cmd; uint32_t interface_version; /* XENPF_INTERFACE_VERSION */ @@ -523,6 +535,7 @@ struct xen_platform_op { struct xenpf_mem_hotadd mem_add; struct xenpf_core_parking core_parking; struct xenpf_symdata symdata; + struct xenpf_pmem_add pmem_add; uint8_t pad[128]; } u; }; diff --git a/include/xen/pmem.h b/include/xen/pmem.h new file mode 100644 index 0000000..896422a --- /dev/null +++ b/include/xen/pmem.h @@ -0,0 +1,32 @@ +/****************************************************************************** + * pmem.h + * pmem file for domain 0 kernel + * + * Copyright (c) 2016, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Author: Haozhong Zhang + */ + +#ifndef __XEN_PMEM_H__ +#define __XEN_PMEM_H__ + +#include + +int xen_pmem_add(uint64_t spa, size_t size, + uint64_t rsv_off, size_t rsv_size, + uint64_t data_off, size_t data_size); + +#endif /* __XEN_PMEM_H__ */