From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
wei.liu2@citrix.com, George.Dunlap@eu.citrix.com,
andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com,
dfaggioli@suse.com, jbeulich@suse.com
Subject: [PATCH RFC v2 07/12] x86: allow per-domain mappings without NX bit or with specific mfn
Date: Mon, 22 Jan 2018 13:32:51 +0100 [thread overview]
Message-ID: <20180122123256.1431-8-jgross@suse.com> (raw)
In-Reply-To: <20180122123256.1431-1-jgross@suse.com>
For support of per-vcpu stacks we need per-vcpu trampolines. To be
able to put those into the per-domain mappings the upper levels
page tables must not have NX set for per-domain mappings.
In order to be able to reset the NX bit for a per-domain mapping add
a helper flipflags_perdomain_mapping() for flipping page table flags
of a specific mapped page.
To be able to use a page from xen heap for the last per-vcpu stack
page add a helper to map an arbitrary mfn in the perdomain area.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
xen/arch/x86/mm.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++--
xen/include/asm-x86/mm.h | 3 ++
2 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 74cdb6e14d..ab990cc667 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -1568,7 +1568,7 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,
/* Slot 260: Per-domain mappings (if applicable). */
l4t[l4_table_offset(PERDOMAIN_VIRT_START)] =
- d ? l4e_from_page(d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW)
+ d ? l4e_from_page(d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR)
: l4e_empty();
/* Slot 261-: text/data/bss, RW M2P, vmap, frametable, directmap. */
@@ -5269,7 +5269,7 @@ int create_perdomain_mapping(struct domain *d, unsigned long va,
}
l2tab = __map_domain_page(pg);
clear_page(l2tab);
- l3tab[l3_table_offset(va)] = l3e_from_page(pg, __PAGE_HYPERVISOR_RW);
+ l3tab[l3_table_offset(va)] = l3e_from_page(pg, __PAGE_HYPERVISOR);
}
else
l2tab = map_l2t_from_l3e(l3tab[l3_table_offset(va)]);
@@ -5311,7 +5311,7 @@ int create_perdomain_mapping(struct domain *d, unsigned long va,
l1tab = __map_domain_page(pg);
}
clear_page(l1tab);
- *pl2e = l2e_from_page(pg, __PAGE_HYPERVISOR_RW);
+ *pl2e = l2e_from_page(pg, __PAGE_HYPERVISOR);
}
else if ( !l1tab )
l1tab = map_l1t_from_l2e(*pl2e);
@@ -5401,6 +5401,81 @@ void destroy_perdomain_mapping(struct domain *d, unsigned long va,
unmap_domain_page(l3tab);
}
+void flipflags_perdomain_mapping(struct domain *d, unsigned long va,
+ unsigned int flags)
+{
+ const l3_pgentry_t *l3tab, *pl3e;
+
+ ASSERT(va >= PERDOMAIN_VIRT_START &&
+ va < PERDOMAIN_VIRT_SLOT(PERDOMAIN_SLOTS));
+
+ if ( !d->arch.perdomain_l3_pg )
+ return;
+
+ l3tab = __map_domain_page(d->arch.perdomain_l3_pg);
+ pl3e = l3tab + l3_table_offset(va);
+
+ if ( l3e_get_flags(*pl3e) & _PAGE_PRESENT )
+ {
+ const l2_pgentry_t *l2tab = map_l2t_from_l3e(*pl3e);
+ const l2_pgentry_t *pl2e = l2tab + l2_table_offset(va);
+
+ if ( l2e_get_flags(*pl2e) & _PAGE_PRESENT )
+ {
+ l1_pgentry_t *l1tab = map_l1t_from_l2e(*pl2e);
+ unsigned int off = l1_table_offset(va);
+
+ if ( (l1e_get_flags(l1tab[off]) & (_PAGE_PRESENT | _PAGE_AVAIL0)) ==
+ (_PAGE_PRESENT | _PAGE_AVAIL0) )
+ l1e_flip_flags(l1tab[off], flags);
+
+ unmap_domain_page(l1tab);
+ }
+
+ unmap_domain_page(l2tab);
+ }
+
+ unmap_domain_page(l3tab);
+}
+
+void addmfn_to_perdomain_mapping(struct domain *d, unsigned long va, mfn_t mfn)
+{
+ const l3_pgentry_t *l3tab, *pl3e;
+
+ ASSERT(va >= PERDOMAIN_VIRT_START &&
+ va < PERDOMAIN_VIRT_SLOT(PERDOMAIN_SLOTS));
+
+ if ( !d->arch.perdomain_l3_pg )
+ return;
+
+ l3tab = __map_domain_page(d->arch.perdomain_l3_pg);
+ pl3e = l3tab + l3_table_offset(va);
+
+ if ( l3e_get_flags(*pl3e) & _PAGE_PRESENT )
+ {
+ const l2_pgentry_t *l2tab = map_l2t_from_l3e(*pl3e);
+ const l2_pgentry_t *pl2e = l2tab + l2_table_offset(va);
+
+ if ( l2e_get_flags(*pl2e) & _PAGE_PRESENT )
+ {
+ l1_pgentry_t *l1tab = map_l1t_from_l2e(*pl2e);
+ unsigned int off = l1_table_offset(va);
+
+ if ( (l1e_get_flags(l1tab[off]) & (_PAGE_PRESENT | _PAGE_AVAIL0)) ==
+ (_PAGE_PRESENT | _PAGE_AVAIL0) )
+ free_domheap_page(l1e_get_page(l1tab[off]));
+
+ l1tab[off] = l1e_from_mfn(mfn, __PAGE_HYPERVISOR_RW);
+
+ unmap_domain_page(l1tab);
+ }
+
+ unmap_domain_page(l2tab);
+ }
+
+ unmap_domain_page(l3tab);
+}
+
void free_perdomain_mappings(struct domain *d)
{
l3_pgentry_t *l3tab;
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 3013c266fe..fa158bd96a 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -582,6 +582,9 @@ int create_perdomain_mapping(struct domain *, unsigned long va,
struct page_info **);
void destroy_perdomain_mapping(struct domain *, unsigned long va,
unsigned int nr);
+void flipflags_perdomain_mapping(struct domain *d, unsigned long va,
+ unsigned int flags);
+void addmfn_to_perdomain_mapping(struct domain *d, unsigned long va, mfn_t mfn);
void free_perdomain_mappings(struct domain *);
extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
--
2.13.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-01-22 12:33 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 12:32 [PATCH RFC v2 00/12] xen/x86: use per-vcpu stacks for 64 bit pv domains Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 01/12] x86: cleanup processor.h Juergen Gross
2018-01-22 12:52 ` Jan Beulich
[not found] ` <5A65ECA502000078001A111C@suse.com>
2018-01-22 14:10 ` Juergen Gross
2018-01-22 14:25 ` Andrew Cooper
2018-01-22 14:32 ` Jan Beulich
2018-01-22 12:32 ` [PATCH RFC v2 02/12] x86: don't use hypervisor stack size for dumping guest stacks Juergen Gross
2018-01-23 9:26 ` Jan Beulich
[not found] ` <5A670DEF02000078001A16AF@suse.com>
2018-01-23 9:58 ` Juergen Gross
2018-01-23 10:11 ` Jan Beulich
[not found] ` <5A67187C02000078001A1742@suse.com>
2018-01-23 10:19 ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 03/12] x86: do a revert of e871e80c38547d9faefc6604532ba3e985e65873 Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 04/12] x86: revert 5784de3e2067ed73efc2fe42e62831e8ae7f46c4 Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 05/12] x86: don't access saved user regs via rsp in trap handlers Juergen Gross
2018-01-30 14:49 ` Jan Beulich
[not found] ` <5A70941B02000078001A3BF0@suse.com>
2018-01-30 16:33 ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 06/12] x86: add a xpti command line parameter Juergen Gross
2018-01-30 15:39 ` Jan Beulich
[not found] ` <5A709FDF02000078001A3C2C@suse.com>
2018-01-30 16:51 ` Juergen Gross
2018-01-22 12:32 ` Juergen Gross [this message]
2018-01-29 17:06 ` [PATCH RFC v2 07/12] x86: allow per-domain mappings without NX bit or with specific mfn Jan Beulich
[not found] ` <5A6F62B602000078001A3810@suse.com>
2018-01-30 8:02 ` Juergen Gross
2018-01-30 8:41 ` Jan Beulich
2018-01-31 10:30 ` Jan Beulich
2018-01-22 12:32 ` [PATCH RFC v2 08/12] xen/x86: use dedicated function for tss initialization Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 09/12] x86: enhance syscall stub to work in per-domain mapping Juergen Gross
2018-01-30 15:11 ` Jan Beulich
[not found] ` <5A70991902000078001A3C16@suse.com>
2018-01-30 16:50 ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 10/12] x86: allocate per-vcpu stacks for interrupt entries Juergen Gross
2018-01-30 15:40 ` Jan Beulich
2018-02-09 12:35 ` Juergen Gross
2018-02-13 9:10 ` Jan Beulich
[not found] ` <5A70A01402000078001A3C30@suse.com>
2018-01-30 17:12 ` Juergen Gross
2018-01-31 10:18 ` Jan Beulich
2018-01-22 12:32 ` [PATCH RFC v2 11/12] x86: modify interrupt handlers to support stack switching Juergen Gross
2018-01-30 16:07 ` Jan Beulich
[not found] ` <5A70A63D02000078001A3C7C@suse.com>
2018-01-30 17:19 ` Juergen Gross
2018-01-31 10:36 ` Jan Beulich
[not found] ` <5A71AA4202000078001A3F56@suse.com>
2018-02-02 15:42 ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 12/12] x86: activate per-vcpu stacks in case of xpti Juergen Gross
2018-01-30 16:33 ` Jan Beulich
[not found] ` <5A70AC7F02000078001A3CA6@suse.com>
2018-01-30 17:33 ` Juergen Gross
2018-01-31 10:40 ` Jan Beulich
2018-01-22 12:50 ` [PATCH RFC v2 00/12] xen/x86: use per-vcpu stacks for 64 bit pv domains Jan Beulich
[not found] ` <5A65EC0A02000078001A1118@suse.com>
2018-01-22 14:18 ` Juergen Gross
2018-01-22 14:22 ` Jan Beulich
[not found] ` <5A6601D302000078001A1230@suse.com>
2018-01-22 14:38 ` Juergen Gross
2018-01-22 14:48 ` Jan Beulich
[not found] ` <5A6607DB02000078001A127B@suse.com>
2018-01-22 15:00 ` Juergen Gross
2018-01-22 16:51 ` Jan Beulich
2018-01-22 18:39 ` Andrew Cooper
2018-01-22 18:48 ` George Dunlap
2018-01-22 19:02 ` Andrew Cooper
2018-01-23 8:36 ` Jan Beulich
2018-01-23 11:23 ` Andrew Cooper
2018-01-23 11:06 ` George Dunlap
2018-01-23 6:34 ` Juergen Gross
2018-01-23 7:21 ` Juergen Gross
2018-01-23 8:53 ` Jan Beulich
[not found] ` <5A67061F02000078001A1669@suse.com>
2018-01-23 9:24 ` Juergen Gross
2018-01-23 9:31 ` Jan Beulich
[not found] ` <5A670F0E02000078001A16C9@suse.com>
2018-01-23 10:10 ` Juergen Gross
2018-01-23 11:45 ` Andrew Cooper
2018-01-23 13:31 ` Juergen Gross
2018-01-23 13:24 ` Dario Faggioli
2018-01-23 16:45 ` George Dunlap
2018-01-23 16:56 ` Juergen Gross
2018-01-23 17:33 ` George Dunlap
2018-01-24 7:37 ` Jan Beulich
[not found] ` <5A6624A602000078001A1375@suse.com>
2018-01-23 5:50 ` Juergen Gross
2018-01-23 8:40 ` Jan Beulich
[not found] ` <5A67030F02000078001A164B@suse.com>
2018-01-23 9:45 ` Juergen Gross
2018-01-22 21:45 ` Konrad Rzeszutek Wilk
2018-01-23 6:38 ` Juergen Gross
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=20180122123256.1431-8-jgross@suse.com \
--to=jgross@suse.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=dfaggioli@suse.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=wei.liu2@citrix.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;
as well as URLs for NNTP newsgroup(s).