From: Mukesh Rathor <mukesh.rathor@oracle.com>
To: Xen-devel@lists.xensource.com
Subject: [PATCH 16/17] PVH xen: elf and iommu related changes to prep for dom0 PVH
Date: Tue, 23 Apr 2013 14:26:05 -0700 [thread overview]
Message-ID: <1366752366-16594-17-git-send-email-mukesh.rathor@oracle.com> (raw)
In-Reply-To: <1366752366-16594-1-git-send-email-mukesh.rathor@oracle.com>
This patch prepares for dom0 PVH by making some changes in the elf
code; add a new parameter to indicate PVH dom0 and use different copy
function for PVH. Also, add check in iommu.c to check for iommu
enabled for dom0 PVH.
Changes in V2: None
Changes in V3:
- introduct early_pvh_copy_or_zero() to replace dbg_rw_mem().
Signed-off-by: Mukesh Rathor <mukesh.rathor@oracle.com>
---
xen/arch/x86/domain_build.c | 39 +++++++++++++++++++++++++++++++++++-
xen/common/libelf/libelf-loader.c | 40 +++++++++++++++++++++++++++++++++---
xen/drivers/passthrough/iommu.c | 22 ++++++++++++++++++-
xen/include/xen/libelf.h | 3 +-
4 files changed, 96 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c
index c8f435d..f8cae52 100644
--- a/xen/arch/x86/domain_build.c
+++ b/xen/arch/x86/domain_build.c
@@ -307,6 +307,43 @@ static void __init process_dom0_ioports_disable(void)
}
}
+ /*
+ * Copy or zero function for dom0 only during boot. This because
+ * raw_copy_to_guest -> copy_to_user_hvm -> __hvm_copy needs curr to
+ * point to the hvm/pvh vcpu which is not all setup yet.
+ *
+ * If src is NULL, then len bytes are zeroed.
+ */
+void __init early_pvh_copy_or_zero(unsigned long dest, char *src, int len,
+ unsigned long v_start)
+{
+ while ( len > 0 )
+ {
+ char *va;
+ p2m_type_t gfntype;
+ unsigned long mfn, gfn, pagecnt;
+ struct domain *d = get_domain_by_id(0);
+
+ pagecnt = min_t(unsigned long, PAGE_SIZE - (dest & ~PAGE_MASK), len);
+
+ gfn = (dest - v_start) >> PAGE_SHIFT;
+ if ( (mfn = mfn_x(get_gfn_query(d, gfn, &gfntype))) == INVALID_MFN )
+ panic("Unable to get mfn for gfn:%lx\n", gfn);
+ put_gfn(d, gfn);
+
+ va = map_domain_page(mfn) + (dest & (PAGE_SIZE-1));
+ if ( src )
+ memcpy(va, src, pagecnt);
+ else
+ memset(va, 0, pagecnt);
+ unmap_domain_page(va);
+
+ dest += pagecnt;
+ src = src ? src + pagecnt : 0;
+ len -= pagecnt;
+ }
+}
+
int __init construct_dom0(
struct domain *d,
const module_t *image, unsigned long image_headroom,
@@ -766,7 +803,7 @@ int __init construct_dom0(
/* Copy the OS image and free temporary buffer. */
elf.dest = (void*)vkern_start;
- rc = elf_load_binary(&elf);
+ rc = elf_load_binary(&elf, (is_pvh_domain(d) ? v_start : 0));
if ( rc < 0 )
{
printk("Failed to load the kernel binary\n");
diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c
index 3cf9c59..077f3dd 100644
--- a/xen/common/libelf/libelf-loader.c
+++ b/xen/common/libelf/libelf-loader.c
@@ -108,7 +108,8 @@ void elf_set_log(struct elf_binary *elf, elf_log_callback *log_callback,
elf->verbose = verbose;
}
-static int elf_load_image(void *dst, const void *src, uint64_t filesz, uint64_t memsz)
+static int elf_load_image(void *dst, const void *src, uint64_t filesz,
+ uint64_t memsz, int not_used)
{
memcpy(dst, src, filesz);
memset(dst + filesz, 0, memsz - filesz);
@@ -122,11 +123,25 @@ void elf_set_verbose(struct elf_binary *elf)
elf->verbose = 1;
}
-static int elf_load_image(void *dst, const void *src, uint64_t filesz, uint64_t memsz)
+extern void __init early_pvh_copy_or_zero(unsigned long dest, char *src,
+ int len, unsigned long v_start);
+
+static int elf_load_image(void *dst, const void *src, uint64_t filesz,
+ uint64_t memsz, unsigned long v_start)
{
int rc;
if ( filesz > ULONG_MAX || memsz > ULONG_MAX )
return -1;
+
+ if ( v_start )
+ {
+ unsigned long addr = (unsigned long)dst;
+ early_pvh_copy_or_zero(addr, (char *)src, filesz, v_start);
+ early_pvh_copy_or_zero(addr + filesz, NULL, memsz - filesz, v_start);
+
+ return 0;
+ }
+
rc = raw_copy_to_guest(dst, src, filesz);
if ( rc != 0 )
return -1;
@@ -260,7 +275,11 @@ void elf_parse_binary(struct elf_binary *elf)
__FUNCTION__, elf->pstart, elf->pend);
}
-int elf_load_binary(struct elf_binary *elf)
+/*
+ * This function called from the libraries when building guests, and also for
+ * dom0 from construct_dom0().
+ */
+static int _elf_load_binary(struct elf_binary *elf, unsigned long v_start)
{
const elf_phdr *phdr;
uint64_t i, count, paddr, offset, filesz, memsz;
@@ -279,7 +298,8 @@ int elf_load_binary(struct elf_binary *elf)
dest = elf_get_ptr(elf, paddr);
elf_msg(elf, "%s: phdr %" PRIu64 " at 0x%p -> 0x%p\n",
__func__, i, dest, dest + filesz);
- if ( elf_load_image(dest, elf->image + offset, filesz, memsz) != 0 )
+ if ( elf_load_image(dest, elf->image + offset, filesz, memsz,
+ v_start) != 0 )
return -1;
}
@@ -287,6 +307,18 @@ int elf_load_binary(struct elf_binary *elf)
return 0;
}
+#ifdef __XEN__
+int elf_load_binary(struct elf_binary *elf, unsigned long v_start)
+{
+ return _elf_load_binary(elf, v_start);
+}
+#else
+int elf_load_binary(struct elf_binary *elf)
+{
+ return _elf_load_binary(elf, 0);
+}
+#endif
+
void *elf_get_ptr(struct elf_binary *elf, unsigned long addr)
{
return elf->dest + addr - elf->pstart;
diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 93ad122..64ba44e 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -125,15 +125,25 @@ int iommu_domain_init(struct domain *d)
return hd->platform_ops->init(d);
}
+static inline void check_dom0_pvh_reqs(struct domain *d)
+{
+ if (!iommu_enabled || iommu_passthrough)
+ panic("For pvh dom0, iommu must be enabled, dom0-passthrough must "
+ "not be enabled \n");
+}
+
void __init iommu_dom0_init(struct domain *d)
{
struct hvm_iommu *hd = domain_hvm_iommu(d);
+ if ( is_pvh_domain(d) )
+ check_dom0_pvh_reqs(d);
+
if ( !iommu_enabled )
return;
register_keyhandler('o', &iommu_p2m_table);
- d->need_iommu = !!iommu_dom0_strict;
+ d->need_iommu = is_pvh_domain(d) || !!iommu_dom0_strict;
if ( need_iommu(d) )
{
struct page_info *page;
@@ -146,7 +156,15 @@ void __init iommu_dom0_init(struct domain *d)
((page->u.inuse.type_info & PGT_type_mask)
== PGT_writable_page) )
mapping |= IOMMUF_writable;
- hd->platform_ops->map_page(d, mfn, mfn, mapping);
+
+ if ( is_pvh_domain(d) )
+ {
+ unsigned long gfn = mfn_to_gfn(d, _mfn(mfn));
+ hd->platform_ops->map_page(d, gfn, mfn, mapping);
+ }
+ else
+ hd->platform_ops->map_page(d, mfn, mfn, mapping);
+
if ( !(i++ & 0xfffff) )
process_pending_softirqs();
}
diff --git a/xen/include/xen/libelf.h b/xen/include/xen/libelf.h
index 218bb18..9d695b7 100644
--- a/xen/include/xen/libelf.h
+++ b/xen/include/xen/libelf.h
@@ -192,13 +192,14 @@ int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr);
int elf_init(struct elf_binary *elf, const char *image, size_t size);
#ifdef __XEN__
void elf_set_verbose(struct elf_binary *elf);
+int elf_load_binary(struct elf_binary *elf, unsigned long v_start);
#else
void elf_set_log(struct elf_binary *elf, elf_log_callback*,
void *log_caller_pointer, int verbose);
+int elf_load_binary(struct elf_binary *elf);
#endif
void elf_parse_binary(struct elf_binary *elf);
-int elf_load_binary(struct elf_binary *elf);
void *elf_get_ptr(struct elf_binary *elf, unsigned long addr);
uint64_t elf_lookup_addr(struct elf_binary *elf, const char *symbol);
--
1.7.2.3
next prev parent reply other threads:[~2013-04-23 21:26 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-23 21:25 [PATCH 00/17][V4]: PVH xen: version 4 patches Mukesh Rathor
2013-04-23 21:25 ` [PATCH 01/17] PVH xen: turn gdb_frames/gdt_ents into union Mukesh Rathor
2013-04-23 21:25 ` [PATCH 02/17] PVH xen: add XENMEM_add_to_physmap_range Mukesh Rathor
2013-04-23 21:25 ` [PATCH 03/17] PVH xen: create domctl_memory_mapping() function Mukesh Rathor
2013-04-24 7:01 ` Jan Beulich
2013-04-23 21:25 ` [PATCH 04/17] PVH xen: add params to read_segment_register Mukesh Rathor
2013-04-23 21:25 ` [PATCH 05/17] PVH xen: vmx realted preparatory changes for PVH Mukesh Rathor
2013-04-23 21:25 ` [PATCH 06/17] PVH xen: Introduce PVH guest type Mukesh Rathor
2013-04-24 7:07 ` Jan Beulich
2013-04-24 23:01 ` Mukesh Rathor
2013-04-25 8:28 ` Jan Beulich
2013-04-23 21:25 ` [PATCH 07/17] PVH xen: tools changes to create PVH domain Mukesh Rathor
2013-04-24 7:10 ` Jan Beulich
2013-04-24 23:02 ` Mukesh Rathor
2013-04-23 21:25 ` [PATCH 08/17] PVH xen: domain creation code changes Mukesh Rathor
2013-04-23 21:25 ` [PATCH 09/17] PVH xen: create PVH vmcs, and also initialization Mukesh Rathor
2013-04-24 7:42 ` Jan Beulich
2013-04-30 21:01 ` Mukesh Rathor
2013-04-30 21:04 ` Mukesh Rathor
2013-04-23 21:25 ` [PATCH 10/17] PVH xen: introduce vmx_pvh.c and pvh.c Mukesh Rathor
2013-04-24 8:47 ` Jan Beulich
2013-04-25 0:57 ` Mukesh Rathor
2013-04-25 8:36 ` Jan Beulich
2013-04-26 1:16 ` Mukesh Rathor
2013-04-26 1:58 ` Mukesh Rathor
2013-04-26 7:29 ` Jan Beulich
2013-04-26 7:20 ` Jan Beulich
2013-04-27 2:06 ` Mukesh Rathor
2013-05-01 0:51 ` Mukesh Rathor
2013-05-01 13:52 ` Jan Beulich
2013-05-02 1:10 ` Mukesh Rathor
2013-05-02 6:42 ` Jan Beulich
2013-05-03 1:03 ` Mukesh Rathor
2013-05-10 1:51 ` Mukesh Rathor
2013-05-10 7:07 ` Jan Beulich
2013-05-10 23:44 ` Mukesh Rathor
2013-05-02 1:17 ` Mukesh Rathor
2013-05-02 6:53 ` Jan Beulich
2013-05-03 0:40 ` Mukesh Rathor
2013-05-03 6:33 ` Jan Beulich
2013-05-04 1:40 ` Mukesh Rathor
2013-05-06 6:44 ` Jan Beulich
2013-05-07 1:25 ` Mukesh Rathor
2013-05-07 8:07 ` Jan Beulich
2013-05-11 0:30 ` Mukesh Rathor
2013-04-25 11:19 ` Tim Deegan
2013-04-23 21:26 ` [PATCH 11/17] PVH xen: some misc changes like mtrr, intr, msi Mukesh Rathor
2013-04-23 21:26 ` [PATCH 12/17] PVH xen: support invalid op, return PVH features etc Mukesh Rathor
2013-04-24 9:01 ` Jan Beulich
2013-04-25 1:01 ` Mukesh Rathor
2013-04-23 21:26 ` [PATCH 13/17] PVH xen: p2m related changes Mukesh Rathor
2013-04-25 11:28 ` Tim Deegan
2013-04-25 21:59 ` Mukesh Rathor
2013-04-26 8:53 ` Tim Deegan
2013-04-23 21:26 ` [PATCH 14/17] PVH xen: Add and remove foreign pages Mukesh Rathor
2013-04-25 11:38 ` Tim Deegan
2013-04-23 21:26 ` [PATCH 15/17] PVH xen: Miscellaneous changes Mukesh Rathor
2013-04-24 9:06 ` Jan Beulich
2013-05-10 1:54 ` Mukesh Rathor
2013-05-10 7:10 ` Jan Beulich
2013-04-23 21:26 ` Mukesh Rathor [this message]
2013-04-24 9:15 ` [PATCH 16/17] PVH xen: elf and iommu related changes to prep for dom0 PVH Jan Beulich
2013-05-14 1:16 ` Mukesh Rathor
2013-05-14 6:56 ` Jan Beulich
2013-05-14 19:14 ` Mukesh Rathor
2013-04-23 21:26 ` [PATCH 17/17] PVH xen: PVH dom0 creation Mukesh Rathor
2013-04-24 9:28 ` Jan Beulich
2013-04-26 1:18 ` Mukesh Rathor
2013-04-26 7:22 ` Jan Beulich
2013-05-10 1:53 ` Mukesh Rathor
2013-05-10 7:14 ` Jan Beulich
2013-05-15 1:18 ` Mukesh Rathor
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=1366752366-16594-17-git-send-email-mukesh.rathor@oracle.com \
--to=mukesh.rathor@oracle.com \
--cc=Xen-devel@lists.xensource.com \
/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;
as well as URLs for NNTP newsgroup(s).