From: Arianna Avanzini <avanzini.arianna@gmail.com>
To: xen-devel@lists.xen.org
Cc: Ian.Campbell@eu.citrix.com, paolo.valente@unimore.it,
keir@xen.org, stefano.stabellini@eu.citrix.com,
Ian.Jackson@eu.citrix.com, dario.faggioli@citrix.com,
tim@xen.org, julien.grall@citrix.com, etrudeau@broadcom.com,
andrew.cooper3@citrix.com, JBeulich@suse.com,
avanzini.arianna@gmail.com, viktor.kleinik@globallogic.com,
andrii.tseglytskyi@globallogic.com
Subject: [PATCH v12 02/14] arch/arm: unmap partially-mapped memory regions
Date: Sat, 30 Aug 2014 18:29:37 +0200 [thread overview]
Message-ID: <1409416189-16564-3-git-send-email-avanzini.arianna@gmail.com> (raw)
In-Reply-To: <1409416189-16564-1-git-send-email-avanzini.arianna@gmail.com>
This commit modifies the function apply_p2m_changes() so that it
destroys changes performed while mapping a memory region, if errors are
seen during the operation. The implemented behaviour includes destroying
only mappings created during the latest invocation of apply_p2m_changes().
This is useful to avoid that memory areas remain partially accessible
to guests.
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Cc: Dario Faggioli <dario.faggioli@citrix.com>
Cc: Paolo Valente <paolo.valente@unimore.it>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Julien Grall <julien.grall@citrix.com>
Cc: Ian Campbell <Ian.Campbell@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Eric Trudeau <etrudeau@broadcom.com>
Cc: Viktor Kleinik <viktor.kleinik@globallogic.com>
Cc: Andrii Tseglytskyi <andrii.tseglytskyi@globallogic.com>
---
v12:
- Unmap only the memory area actually affected by the current
invocation of apply_p2m_changes().
- Use the correct mattr instead of always using MATTR_DEV when
unmapping a partially-mapped memory region.
v11:
- Handle partially-mapped memory regions regardless of their being
I/O-memory regions or not.
v10:
- Recursively call apply_p2m_changes() on the whole I/O-memory range
when unmapping a partially-mapped I/O-memory region.
v9:
- Let apply_p2m_ranges() unwind its own progress instead of relying on
the caller to unmap partially-mapped I/O-memory regions.
- Adapt to rework of p2m-related functions for ARM.
---
xen/arch/arm/p2m.c | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 8f83d17..96d7dd8 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -440,6 +440,14 @@ static bool_t is_mapping_aligned(const paddr_t start_gpaddr,
#define P2M_ONE_PROGRESS_NOP 0x1
#define P2M_ONE_PROGRESS 0x10
+/* Helpers to lookup the properties of each level */
+const paddr_t level_sizes[] =
+ { ZEROETH_SIZE, FIRST_SIZE, SECOND_SIZE, THIRD_SIZE };
+const paddr_t level_masks[] =
+ { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK };
+const paddr_t level_shifts[] =
+ { ZEROETH_SHIFT, FIRST_SHIFT, SECOND_SHIFT, THIRD_SHIFT };
+
/*
* 0 == (P2M_ONE_DESCEND) continue to descend the tree
* +ve == (P2M_ONE_PROGRESS_*) handled at this level, continue, flush,
@@ -460,13 +468,6 @@ static int apply_one_level(struct domain *d,
int mattr,
p2m_type_t t)
{
- /* Helpers to lookup the properties of each level */
- const paddr_t level_sizes[] =
- { ZEROETH_SIZE, FIRST_SIZE, SECOND_SIZE, THIRD_SIZE };
- const paddr_t level_masks[] =
- { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK };
- const paddr_t level_shifts[] =
- { ZEROETH_SHIFT, FIRST_SHIFT, SECOND_SHIFT, THIRD_SHIFT };
const paddr_t level_size = level_sizes[level];
const paddr_t level_mask = level_masks[level];
const paddr_t level_shift = level_shifts[level];
@@ -713,7 +714,8 @@ static int apply_p2m_changes(struct domain *d,
int rc, ret;
struct p2m_domain *p2m = &d->arch.p2m;
lpae_t *first = NULL, *second = NULL, *third = NULL;
- paddr_t addr;
+ paddr_t addr, orig_maddr = maddr;
+ unsigned int level = 0;
unsigned long cur_first_page = ~0,
cur_first_offset = ~0,
cur_second_offset = ~0;
@@ -769,8 +771,9 @@ static int apply_p2m_changes(struct domain *d,
* current hardware doesn't support super page mappings at
* level 0 anyway */
+ level = 1;
ret = apply_one_level(d, &first[first_table_offset(addr)],
- 1, flush_pt, op,
+ level, flush_pt, op,
start_gpaddr, end_gpaddr,
&addr, &maddr, &flush,
mattr, t);
@@ -790,8 +793,9 @@ static int apply_p2m_changes(struct domain *d,
}
/* else: second already valid */
+ level = 2;
ret = apply_one_level(d,&second[second_table_offset(addr)],
- 2, flush_pt, op,
+ level, flush_pt, op,
start_gpaddr, end_gpaddr,
&addr, &maddr, &flush,
mattr, t);
@@ -809,8 +813,9 @@ static int apply_p2m_changes(struct domain *d,
cur_second_offset = second_table_offset(addr);
}
+ level = 3;
ret = apply_one_level(d, &third[third_table_offset(addr)],
- 3, flush_pt, op,
+ level, flush_pt, op,
start_gpaddr, end_gpaddr,
&addr, &maddr, &flush,
mattr, t);
@@ -844,6 +849,20 @@ out:
if (third) unmap_domain_page(third);
if (second) unmap_domain_page(second);
if (first) unmap_domain_page(first);
+ if ( rc < 0 && ( op == INSERT || op == ALLOCATE ) &&
+ addr != start_gpaddr )
+ {
+ BUG_ON(addr == end_gpaddr);
+ /*
+ * addr keeps the address of the last successfully-inserted mapping,
+ * while apply_p2m_changes() considers an address range which is
+ * exclusive of end_gpaddr: add level_size to addr to obtain the
+ * right end of the range
+ */
+ apply_p2m_changes(d, REMOVE,
+ start_gpaddr, addr + level_sizes[level], orig_maddr,
+ mattr, p2m_invalid);
+ }
spin_unlock(&p2m->lock);
--
2.1.0
next prev parent reply other threads:[~2014-08-30 16:29 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-30 16:29 [PATCH v12 00/14] Implement the XEN_DOMCTL_memory_mapping hypercall for ARM Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 01/14] arch/arm: add consistency check to REMOVE p2m changes Arianna Avanzini
2014-08-30 16:29 ` Arianna Avanzini [this message]
2014-09-01 17:53 ` [PATCH v12 02/14] arch/arm: unmap partially-mapped memory regions Julien Grall
2014-09-01 20:13 ` Arianna Avanzini
2014-09-01 23:47 ` [PATCH] " Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 03/14] arch/x86: warn if to-be-removed mapping does not exist Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 04/14] arch/x86: cleanup memory_mapping DOMCTL Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 05/14] xen/common: add ARM stub for the function memory_type_changed() Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 06/14] xen/x86: factor out map and unmap from the memory_mapping DOMCTL Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 07/14] xen/common: move the memory_mapping DOMCTL hypercall to common code Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 08/14] tools/libxl: parse optional start gfn from the iomem config option Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 09/14] tools/libxl: handle the iomem parameter with the memory_mapping hcall Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 10/14] xsm/flask: avoid spurious error messages when mapping I/O-memory Arianna Avanzini
2014-09-03 11:22 ` Ian Campbell
2014-09-03 11:30 ` Ian Campbell
2014-09-03 14:41 ` Daniel De Graaf
2014-09-04 11:49 ` [PATCH] xsm/flask: handle XEN_DOMCTL_memory_mapping for all architectures Arianna Avanzini
2014-09-08 10:11 ` Ian Campbell
2014-09-08 12:24 ` Arianna Avanzini
2014-09-08 12:38 ` Ian Campbell
2014-09-08 12:50 ` Arianna Avanzini
2014-09-09 12:35 ` Ian Campbell
2014-09-09 13:13 ` Arianna Avanzini
2014-09-09 14:45 ` Ian Campbell
2014-09-10 20:07 ` Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 11/14] flask/policy: allow domU to use previously-mapped I/O-memory Arianna Avanzini
2014-09-03 11:21 ` Ian Campbell
2014-09-03 14:45 ` Daniel De Graaf
2014-09-05 23:25 ` Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 12/14] tools/libxl: explicitly grant access to needed I/O-memory ranges Arianna Avanzini
2014-09-03 11:26 ` Ian Campbell
2014-09-08 15:05 ` [PATCH 0/3] Separate the functions of the memory_mapping and iomem_permission DOMCTLs Arianna Avanzini
2014-09-08 15:05 ` [PATCH 1/3] tools/libxl: explicitly grant access to needed I/O-memory ranges Arianna Avanzini
2014-09-08 15:05 ` [PATCH 2/3] tools/libxl: cleanup the do_pci_add() function Arianna Avanzini
2014-09-08 15:05 ` [PATCH 3/3] xen/common: do not implicitly permit access to mapped I/O memory Arianna Avanzini
2014-08-30 16:29 ` [PATCH v12 13/14] tools/libxl: cleanup the do_pci_add() function Arianna Avanzini
2014-09-03 11:27 ` Ian Campbell
2014-08-30 16:29 ` [PATCH v12 14/14] xen/common: do not implicitly permit access to mapped I/O memory Arianna Avanzini
2014-09-03 12:15 ` [PATCH v12 00/14] Implement the XEN_DOMCTL_memory_mapping hypercall for ARM Ian Campbell
2014-09-03 13:55 ` Arianna Avanzini
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=1409416189-16564-3-git-send-email-avanzini.arianna@gmail.com \
--to=avanzini.arianna@gmail.com \
--cc=Ian.Campbell@eu.citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=andrii.tseglytskyi@globallogic.com \
--cc=dario.faggioli@citrix.com \
--cc=etrudeau@broadcom.com \
--cc=julien.grall@citrix.com \
--cc=keir@xen.org \
--cc=paolo.valente@unimore.it \
--cc=stefano.stabellini@eu.citrix.com \
--cc=tim@xen.org \
--cc=viktor.kleinik@globallogic.com \
--cc=xen-devel@lists.xen.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).