From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: stefano.stabellini@citrix.com,
Julien Grall <julien.grall@linaro.org>,
tim@xen.org, ian.campbell@citrix.com, patches@linaro.org
Subject: [PATCH v3 04/10] xen/arm: Store p2m type in each page of the guest
Date: Tue, 10 Dec 2013 14:18:16 +0000 [thread overview]
Message-ID: <1386685102-563-5-git-send-email-julien.grall@linaro.org> (raw)
In-Reply-To: <1386685102-563-1-git-send-email-julien.grall@linaro.org>
Use the field 'avail' to store the type of the page. Rename it to 'type' for
convenience.
The information stored in this field will be retrieved in a future patch to
change the behaviour when the page is removed.
Also introduce guest_physmap_add_entry to map and set a specific p2m type for
a page.
Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
Changes in v3:
- Typo in the commit message
- Rename 'p2mt' field to 'type'
- Remove default in switch to let the compiler warns
- Move BUILD_BUG_ON to patch #3
Changes in v2:
- Rename 'avail' field to 'p2mt' in the p2m structure
- Add BUILD_BUG_ON to check if the enum value will fit in the field
- Implement grant mapping type
---
xen/arch/arm/p2m.c | 56 ++++++++++++++++++++++++++++++++------------
xen/include/asm-arm/p2m.h | 18 ++++++++++----
xen/include/asm-arm/page.h | 2 +-
3 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 691cdfa..3a79927 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -128,7 +128,8 @@ int p2m_pod_decrease_reservation(struct domain *d,
return -ENOSYS;
}
-static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr)
+static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr,
+ p2m_type_t t)
{
paddr_t pa = ((paddr_t) mfn) << PAGE_SHIFT;
lpae_t e = (lpae_t) {
@@ -136,14 +137,34 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr)
.p2m.af = 1,
.p2m.sh = LPAE_SH_OUTER,
.p2m.read = 1,
- .p2m.write = 1,
.p2m.mattr = mattr,
.p2m.table = 1,
.p2m.valid = 1,
+ .p2m.type = t,
};
BUILD_BUG_ON(p2m_max_real_type > (1 << 4));
+ switch (t)
+ {
+ case p2m_grant_map_rw:
+ e.p2m.xn = 1;
+ /* Fallthrough */
+ case p2m_ram_rw:
+ case p2m_mmio_direct:
+ case p2m_map_foreign:
+ e.p2m.write = 1;
+ break;
+
+ case p2m_grant_map_ro:
+ e.p2m.xn = 1;
+ /* Fallthrough */
+ case p2m_invalid:
+ case p2m_ram_ro:
+ default:
+ e.p2m.write = 0;
+ }
+
ASSERT(!(pa & ~PAGE_MASK));
ASSERT(!(pa & ~PADDR_MASK));
@@ -173,7 +194,7 @@ static int p2m_create_table(struct domain *d,
clear_page(p);
unmap_domain_page(p);
- pte = mfn_to_p2m_entry(page_to_mfn(page), MATTR_MEM);
+ pte = mfn_to_p2m_entry(page_to_mfn(page), MATTR_MEM, p2m_invalid);
write_pte(entry, pte);
@@ -191,7 +212,8 @@ static int create_p2m_entries(struct domain *d,
paddr_t start_gpaddr,
paddr_t end_gpaddr,
paddr_t maddr,
- int mattr)
+ int mattr,
+ p2m_type_t t)
{
int rc, flush;
struct p2m_domain *p2m = &d->arch.p2m;
@@ -271,14 +293,15 @@ static int create_p2m_entries(struct domain *d,
goto out;
}
- pte = mfn_to_p2m_entry(page_to_mfn(page), mattr);
+ pte = mfn_to_p2m_entry(page_to_mfn(page), mattr, t);
write_pte(&third[third_table_offset(addr)], pte);
}
break;
case INSERT:
{
- lpae_t pte = mfn_to_p2m_entry(maddr >> PAGE_SHIFT, mattr);
+ lpae_t pte = mfn_to_p2m_entry(maddr >> PAGE_SHIFT,
+ mattr, t);
write_pte(&third[third_table_offset(addr)], pte);
maddr += PAGE_SIZE;
}
@@ -313,7 +336,8 @@ int p2m_populate_ram(struct domain *d,
paddr_t start,
paddr_t end)
{
- return create_p2m_entries(d, ALLOCATE, start, end, 0, MATTR_MEM);
+ return create_p2m_entries(d, ALLOCATE, start, end,
+ 0, MATTR_MEM, p2m_ram_rw);
}
int map_mmio_regions(struct domain *d,
@@ -321,18 +345,20 @@ int map_mmio_regions(struct domain *d,
paddr_t end_gaddr,
paddr_t maddr)
{
- return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr, maddr, MATTR_DEV);
+ return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr,
+ maddr, MATTR_DEV, p2m_mmio_direct);
}
-int guest_physmap_add_page(struct domain *d,
- unsigned long gpfn,
- unsigned long mfn,
- unsigned int page_order)
+int guest_physmap_add_entry(struct domain *d,
+ unsigned long gpfn,
+ unsigned long mfn,
+ unsigned long page_order,
+ p2m_type_t t)
{
return create_p2m_entries(d, INSERT,
pfn_to_paddr(gpfn),
- pfn_to_paddr(gpfn + (1<<page_order)),
- pfn_to_paddr(mfn), MATTR_MEM);
+ pfn_to_paddr(gpfn + (1 << page_order)),
+ pfn_to_paddr(mfn), MATTR_MEM, t);
}
void guest_physmap_remove_page(struct domain *d,
@@ -342,7 +368,7 @@ void guest_physmap_remove_page(struct domain *d,
create_p2m_entries(d, REMOVE,
pfn_to_paddr(gpfn),
pfn_to_paddr(gpfn + (1<<page_order)),
- pfn_to_paddr(mfn), MATTR_MEM);
+ pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid);
}
int p2m_alloc_table(struct domain *d)
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index c833c39..dba44fd 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -68,11 +68,21 @@ int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);
int map_mmio_regions(struct domain *d, paddr_t start_gaddr,
paddr_t end_gaddr, paddr_t maddr);
+int guest_physmap_add_entry(struct domain *d,
+ unsigned long gfn,
+ unsigned long mfn,
+ unsigned long page_order,
+ p2m_type_t t);
+
/* Untyped version for RAM only, for compatibility */
-int guest_physmap_add_page(struct domain *d,
- unsigned long gfn,
- unsigned long mfn,
- unsigned int page_order);
+static inline int guest_physmap_add_page(struct domain *d,
+ unsigned long gfn,
+ unsigned long mfn,
+ unsigned int page_order)
+{
+ return guest_physmap_add_entry(d, gfn, mfn, page_order, p2m_ram_rw);
+}
+
void guest_physmap_remove_page(struct domain *d,
unsigned long gpfn,
unsigned long mfn, unsigned int page_order);
diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h
index 0625464..670d4e7 100644
--- a/xen/include/asm-arm/page.h
+++ b/xen/include/asm-arm/page.h
@@ -153,7 +153,7 @@ typedef struct {
unsigned long contig:1; /* In a block of 16 contiguous entries */
unsigned long sbz2:1;
unsigned long xn:1; /* eXecute-Never */
- unsigned long avail:4; /* Ignored by hardware */
+ unsigned long type:4; /* Ignore by hardware. Used to store p2m types */
unsigned long sbz1:5;
} __attribute__((__packed__)) lpae_p2m_t;
--
1.7.10.4
next prev parent reply other threads:[~2013-12-10 14:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-10 14:18 [PATCH v3 00/10] xen/arm: Handle correctly foreign mapping Julien Grall
2013-12-10 14:18 ` [PATCH v3 01/10] xen/arm: Introduce steps in domain_relinquish_resource Julien Grall
2013-12-10 14:18 ` [PATCH v3 02/10] xen/arm: move mfn_to_p2m_entry in arch/arm/p2m.c Julien Grall
2013-12-10 14:18 ` [PATCH v3 03/10] xen/arm: Implement p2m_type_t as an enum Julien Grall
2013-12-10 14:18 ` Julien Grall [this message]
2013-12-10 14:18 ` [PATCH v3 05/10] xen/arm: p2m: Extend p2m_lookup parameters to retrieve the p2m type Julien Grall
2013-12-10 14:18 ` [PATCH v3 06/10] xen/arm: Retrieve p2m type in get_page_from_gfn Julien Grall
2013-12-10 14:18 ` [PATCH v3 07/10] xen/arm: Implement xen_rem_foreign_from_p2m Julien Grall
2013-12-10 14:18 ` [PATCH v3 08/10] xen/arm: Add relinquish_p2m_mapping to remove reference on every mapped page Julien Grall
2013-12-10 14:18 ` [PATCH v3 09/10] xen/arm: Set foreign page type to p2m_map_foreign Julien Grall
2013-12-10 14:18 ` [PATCH v3 10/10] xen/arm: grant-table: Support read-only mapping Julien Grall
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=1386685102-563-5-git-send-email-julien.grall@linaro.org \
--to=julien.grall@linaro.org \
--cc=ian.campbell@citrix.com \
--cc=patches@linaro.org \
--cc=stefano.stabellini@citrix.com \
--cc=tim@xen.org \
--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).