From: Haozhong Zhang <haozhong.zhang@intel.com>
To: linux-nvdimm@lists.01.org, xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
Xiao Guangrong <guangrong.xiao@linux.intel.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org,
Stefano Stabellini <stefano@aporeto.com>,
David Vrabel <david.vrabel@citrix.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>
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 [thread overview]
Message-ID: <20161010003523.4423-3-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20161010003523.4423-1-haozhong.zhang@intel.com>
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 <haozhong.zhang@intel.com>
---
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <stefano@aporeto.com>
Cc: Arnd Bergmann <arnd@arndb.de>
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 <xen/xen.h>
+#include <xen/pmem.h>
+#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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Haozhong Zhang <haozhong.zhang@intel.com>
+ */
+
+#include <linux/types.h>
+#include <xen/interface/platform.h>
+#include <asm/xen/hypercall.h>
+
+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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Haozhong Zhang <haozhong.zhang@intel.com>
+ */
+
+#ifndef __XEN_PMEM_H__
+#define __XEN_PMEM_H__
+
+#include <linux/types.h>
+
+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__ */
--
2.10.1
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next prev parent reply other threads:[~2016-10-10 0:35 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-10 0:35 [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen Haozhong Zhang
2016-10-10 0:35 ` [RFC KERNEL PATCH 1/2] nvdimm: add PFN_MODE_XEN to pfn device for Xen usage Haozhong Zhang
2016-10-10 0:35 ` Haozhong Zhang [this message]
2016-10-10 3:45 ` [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen Dan Williams
2016-10-10 6:32 ` Haozhong Zhang
2016-10-10 16:24 ` Dan Williams
2016-10-11 7:11 ` Haozhong Zhang
2016-10-10 16:43 ` [Xen-devel] " Andrew Cooper
2016-10-11 5:52 ` Haozhong Zhang
2016-10-11 18:37 ` Andrew Cooper
[not found] ` <de62aa59-37e0-b01f-1617-6fc8f6fb3620-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
2016-10-11 18:45 ` Konrad Rzeszutek Wilk
2016-10-11 18:48 ` Konrad Rzeszutek Wilk
2016-10-11 13:08 ` Jan Beulich
2016-10-11 15:53 ` Dan Williams
2016-10-11 16:58 ` Konrad Rzeszutek Wilk
2016-10-11 17:51 ` Dan Williams
2016-10-11 18:15 ` Andrew Cooper
2016-10-11 18:42 ` Konrad Rzeszutek Wilk
2016-10-11 19:43 ` Konrad Rzeszutek Wilk
2016-10-11 18:33 ` Konrad Rzeszutek Wilk
2016-10-11 19:28 ` Dan Williams
2016-10-11 19:48 ` Konrad Rzeszutek Wilk
2016-10-11 20:17 ` Dan Williams
2016-10-12 10:33 ` Haozhong Zhang
2016-10-12 11:32 ` Jan Beulich
2016-10-12 14:58 ` Haozhong Zhang
2016-10-12 15:39 ` Jan Beulich
2016-10-12 15:42 ` Dan Williams
2016-10-12 16:01 ` Jan Beulich
2016-10-12 16:19 ` Dan Williams
2016-10-13 8:34 ` Jan Beulich
2016-10-13 8:53 ` Haozhong Zhang
2016-10-13 9:08 ` Jan Beulich
2016-10-13 15:40 ` Dan Williams
2016-10-13 16:01 ` Andrew Cooper
2016-10-13 18:59 ` Dan Williams
2016-10-13 19:33 ` Andrew Cooper
2016-10-14 7:08 ` Haozhong Zhang
2016-10-14 12:18 ` Andrew Cooper
2016-10-20 9:14 ` Haozhong Zhang
2016-10-20 21:46 ` Andrew Cooper
2016-10-14 10:03 ` Jan Beulich
2016-10-13 15:46 ` Haozhong Zhang
2016-10-14 10:16 ` Jan Beulich
2016-10-20 9:15 ` Haozhong Zhang
2016-10-13 9:08 ` Haozhong Zhang
2016-10-11 20:18 ` Andrew Cooper
2016-10-12 7:25 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161010003523.4423-3-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=arnd@arndb.de \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=stefano@aporeto.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox