From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xen.org
Cc: proskurin@sec.in.tum.de, Julien Grall <julien.grall@arm.com>,
sstabellini@kernel.org, steve.capper@arm.com,
wei.chen@linaro.org
Subject: [for-4.8][PATCH v2 19/23] xen/arm: p2m: Re-implement p2m_remove_using using p2m_set_entry
Date: Thu, 15 Sep 2016 12:28:35 +0100 [thread overview]
Message-ID: <1473938919-31976-20-git-send-email-julien.grall@arm.com> (raw)
In-Reply-To: <1473938919-31976-1-git-send-email-julien.grall@arm.com>
The function p2m_insert_mapping can be re-implemented using the generic
function p2m_set_entry.
Also drop the operation REMOVE in apply_* as nobody is using it anymore.
Note that the functions could have been dropped in one go at the end,
however I find easier to drop the operations one by one avoiding a big
deletion in the patch that converts the last operation.
Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabelini <sstabellini@kernel.org>
---
Changes in v2:
- Add Stefano's reviewed-by
---
xen/arch/arm/p2m.c | 125 ++++++-----------------------------------------------
1 file changed, 13 insertions(+), 112 deletions(-)
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index ce09c4c..6c9a6b2 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -753,7 +753,6 @@ static int p2m_mem_access_radix_set(struct p2m_domain *p2m, gfn_t gfn,
enum p2m_operation {
INSERT,
- REMOVE,
MEMACCESS,
};
@@ -1232,7 +1231,6 @@ static int apply_one_level(struct domain *d,
p2m_access_t a)
{
const paddr_t level_size = level_sizes[level];
- const paddr_t level_mask = level_masks[level];
struct p2m_domain *p2m = &d->arch.p2m;
lpae_t pte;
@@ -1317,74 +1315,6 @@ static int apply_one_level(struct domain *d,
break;
- case REMOVE:
- if ( !p2m_valid(orig_pte) )
- {
- /* Progress up to next boundary */
- *addr = (*addr + level_size) & level_mask;
- *maddr = (*maddr + level_size) & level_mask;
- return P2M_ONE_PROGRESS_NOP;
- }
-
- if ( level < 3 )
- {
- if ( p2m_table(orig_pte) )
- return P2M_ONE_DESCEND;
-
- if ( op == REMOVE &&
- !is_mapping_aligned(*addr, end_gpaddr,
- 0, /* maddr doesn't matter for remove */
- level_size) )
- {
- /*
- * Removing a mapping from the middle of a superpage. Shatter
- * and descend.
- */
- *flush = true;
- rc = p2m_shatter_page(p2m, entry, level);
- if ( rc < 0 )
- return rc;
-
- return P2M_ONE_DESCEND;
- }
- }
-
- /*
- * Ensure that the guest address addr currently being
- * handled (that is in the range given as argument to
- * this function) is actually mapped to the corresponding
- * machine address in the specified range. maddr here is
- * the machine address given to the function, while
- * orig_pte.p2m.base is the machine frame number actually
- * mapped to the guest address: check if the two correspond.
- */
- if ( op == REMOVE &&
- pfn_to_paddr(orig_pte.p2m.base) != *maddr )
- printk(XENLOG_G_WARNING
- "p2m_remove dom%d: mapping at %"PRIpaddr" is of maddr %"PRIpaddr" not %"PRIpaddr" as expected\n",
- d->domain_id, *addr, pfn_to_paddr(orig_pte.p2m.base),
- *maddr);
-
- *flush = true;
-
- p2m_remove_pte(entry, p2m->clean_pte);
- p2m_mem_access_radix_set(p2m, _gfn(paddr_to_pfn(*addr)),
- p2m_access_rwx);
-
- *addr += level_size;
- *maddr += level_size;
-
- p2m->stats.mappings[level]--;
-
- if ( level == 3 )
- p2m_put_l3_page(orig_pte);
-
- /*
- * This is still a single pte write, no matter the level, so no need to
- * scale.
- */
- return P2M_ONE_PROGRESS;
-
case MEMACCESS:
if ( level < 3 )
{
@@ -1596,43 +1526,6 @@ static int apply_p2m_changes(struct domain *d,
}
BUG_ON(level > 3);
-
- if ( op == REMOVE )
- {
- for ( ; level > P2M_ROOT_LEVEL; level-- )
- {
- lpae_t old_entry;
- lpae_t *entry;
- unsigned int offset;
-
- pg = pages[level];
-
- /*
- * No need to try the previous level if the current one
- * still contains some mappings.
- */
- if ( pg->u.inuse.p2m_refcount )
- break;
-
- offset = offsets[level - 1];
- entry = &mappings[level - 1][offset];
- old_entry = *entry;
-
- page_list_del(pg, &p2m->pages);
-
- p2m_remove_pte(entry, p2m->clean_pte);
-
- p2m->stats.mappings[level - 1]--;
- update_reference_mapping(pages[level - 1], old_entry, *entry);
-
- /*
- * We can't free the page now because it may be present
- * in the guest TLB. Queue it and free it after the TLB
- * has been flushed.
- */
- page_list_add(pg, &free_pages);
- }
- }
}
if ( op == INSERT )
@@ -1674,8 +1567,10 @@ out:
* addr keeps the address of the end of the last successfully-inserted
* mapping.
*/
- apply_p2m_changes(d, REMOVE, sgfn, gfn - gfn_x(sgfn), smfn,
- 0, p2m_invalid, d->arch.p2m.default_access);
+ p2m_write_lock(p2m);
+ p2m_set_entry(p2m, sgfn, gfn - gfn_x(sgfn), INVALID_MFN,
+ p2m_invalid, p2m_access_rwx);
+ p2m_write_unlock(p2m);
}
return rc;
@@ -1696,9 +1591,15 @@ static inline int p2m_remove_mapping(struct domain *d,
unsigned long nr,
mfn_t mfn)
{
- return apply_p2m_changes(d, REMOVE, start_gfn, nr, mfn,
- /* arguments below not used when removing mapping */
- 0, p2m_invalid, d->arch.p2m.default_access);
+ struct p2m_domain *p2m = &d->arch.p2m;
+ int rc;
+
+ p2m_write_lock(p2m);
+ rc = p2m_set_entry(p2m, start_gfn, nr, INVALID_MFN,
+ p2m_invalid, p2m_access_rwx);
+ p2m_write_unlock(p2m);
+
+ return rc;
}
int map_regions_rw_cache(struct domain *d,
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-09-15 11:28 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-15 11:28 [for-4.8][PATCH v2 00/23] xen/arm: Rework the P2M code to follow break-before-make sequence Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 01/23] xen/arm: do_trap_instr_abort_guest: Move the IPA computation out of the switch Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 02/23] xen/arm: p2m: Store in p2m_domain whether we need to clean the entry Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 03/23] xen/arm: p2m: Rename parameter in p2m_{remove, write}_pte Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 04/23] xen/arm: p2m: Use typesafe gfn in p2m_mem_access_radix_set Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 05/23] xen/arm: p2m: Add a back pointer to domain in p2m_domain Julien Grall
2016-09-17 1:16 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 06/23] xen/arm: traps: Move MMIO emulation code in a separate helper Julien Grall
2016-09-17 1:17 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 07/23] xen/arm: traps: Check the P2M before injecting a data/instruction abort Julien Grall
2016-09-17 1:22 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 08/23] xen/arm: p2m: Invalidate the TLBs when write unlocking the p2m Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 09/23] xen/arm: p2m: Change the type of level_shifts from paddr_t to uint8_t Julien Grall
2016-09-17 1:23 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 10/23] xen/arm: p2m: Move the lookup helpers at the top of the file Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 11/23] xen/arm: p2m: Introduce p2m_get_root_pointer and use it in __p2m_lookup Julien Grall
2016-09-17 1:26 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 12/23] xen/arm: p2m: Introduce p2m_get_entry and use it to implement __p2m_lookup Julien Grall
2016-09-17 1:36 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 13/23] xen/arm: p2m: Replace all usage of __p2m_lookup with p2m_get_entry Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 14/23] xen/arm: p2m: Re-implement p2m_cache_flush using p2m_get_entry Julien Grall
2016-09-17 1:42 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 15/23] xen/arm: p2m: Make p2m_{valid, table, mapping} helpers inline Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 16/23] xen/arm: p2m: Introduce a helper to check if an entry is a superpage Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 17/23] xen/arm: p2m: Introduce p2m_set_entry and __p2m_set_entry Julien Grall
2016-09-22 2:18 ` Stefano Stabellini
2016-09-15 11:28 ` [for-4.8][PATCH v2 18/23] xen/arm: p2m: Re-implement relinquish_p2m_mapping using p2m_{get, set}_entry Julien Grall
2016-09-20 2:14 ` Stefano Stabellini
2016-09-15 11:28 ` Julien Grall [this message]
2016-09-15 11:28 ` [for-4.8][PATCH v2 20/23] xen/arm: p2m: Re-implement p2m_insert_mapping using p2m_set_entry Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 21/23] xen/arm: p2m: Re-implement p2m_set_mem_access using p2m_{set, get}_entry Julien Grall
2016-09-15 11:41 ` Razvan Cojocaru
2016-09-15 11:28 ` [for-4.8][PATCH v2 22/23] xen/arm: p2m: Do not handle shattering in p2m_create_table Julien Grall
2016-09-15 13:50 ` Julien Grall
2016-09-15 11:28 ` [for-4.8][PATCH v2 23/23] xen/arm: p2m: Export p2m_*_lock helpers Julien Grall
2016-09-15 17:23 ` [for-4.8][PATCH v2 00/23] xen/arm: Rework the P2M code to follow break-before-make sequence Tamas K Lengyel
2016-09-28 1:14 ` Stefano Stabellini
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=1473938919-31976-20-git-send-email-julien.grall@arm.com \
--to=julien.grall@arm.com \
--cc=proskurin@sec.in.tum.de \
--cc=sstabellini@kernel.org \
--cc=steve.capper@arm.com \
--cc=wei.chen@linaro.org \
--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).