From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 3/5] x86/pv: Consistently use typesafe helpers in all files
Date: Tue, 29 Aug 2017 12:19:14 +0100 [thread overview]
Message-ID: <1504005556-30394-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1504005556-30394-1-git-send-email-andrew.cooper3@citrix.com>
Rather than having a mix of code behaviour. This requires updating
pagetable_{get,from}_page() to use the non-overridden helpers.
This requires some adjustments in priv_op_{read,write}_cr(), which is most
easily done by switching CR3 handling to using mfn_t.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
xen/arch/x86/pv/callback.c | 6 ++++++
xen/arch/x86/pv/domain.c | 6 ++++++
xen/arch/x86/pv/emul-gate-op.c | 6 ++++++
xen/arch/x86/pv/emul-priv-op.c | 20 +++++++++++++-------
xen/arch/x86/pv/iret.c | 6 ++++++
xen/arch/x86/pv/traps.c | 6 ++++++
xen/include/asm-x86/page.h | 4 ++--
7 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/xen/arch/x86/pv/callback.c b/xen/arch/x86/pv/callback.c
index 5957cb5..97d8438 100644
--- a/xen/arch/x86/pv/callback.c
+++ b/xen/arch/x86/pv/callback.c
@@ -31,6 +31,12 @@
#include <public/callback.h>
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
static int register_guest_nmi_callback(unsigned long address)
{
struct vcpu *curr = current;
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 6cb61f2..c8b9cb6 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -11,6 +11,12 @@
#include <asm/pv/domain.h>
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
static void noreturn continue_nonidle_domain(struct vcpu *v)
{
check_wakeup_from_wait();
diff --git a/xen/arch/x86/pv/emul-gate-op.c b/xen/arch/x86/pv/emul-gate-op.c
index cdf3b30..0a7381a 100644
--- a/xen/arch/x86/pv/emul-gate-op.c
+++ b/xen/arch/x86/pv/emul-gate-op.c
@@ -41,6 +41,12 @@
#include "emulate.h"
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
static int read_gate_descriptor(unsigned int gate_sel,
const struct vcpu *v,
unsigned int *sel,
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index d50f519..af1624a 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -42,6 +42,12 @@
#include "../x86_64/mmconfig.h"
#include "emulate.h"
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
/***********************
* I/O emulation support
*/
@@ -709,21 +715,21 @@ static int priv_op_read_cr(unsigned int reg, unsigned long *val,
case 3: /* Read CR3 */
{
const struct domain *currd = curr->domain;
- unsigned long mfn;
+ mfn_t mfn;
if ( !is_pv_32bit_domain(currd) )
{
- mfn = pagetable_get_pfn(curr->arch.guest_table);
- *val = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn));
+ mfn = pagetable_get_mfn(curr->arch.guest_table);
+ *val = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn)));
}
else
{
l4_pgentry_t *pl4e =
- map_domain_page(_mfn(pagetable_get_pfn(curr->arch.guest_table)));
+ map_domain_page(pagetable_get_mfn(curr->arch.guest_table));
- mfn = l4e_get_pfn(*pl4e);
+ mfn = l4e_get_mfn(*pl4e);
unmap_domain_page(pl4e);
- *val = compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn));
+ *val = compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn)));
}
/* PTs should not be shared */
BUG_ON(page_get_owner(mfn_to_page(mfn)) == dom_cow);
@@ -768,7 +774,7 @@ static int priv_op_write_cr(unsigned int reg, unsigned long val,
page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);
if ( !page )
break;
- rc = new_guest_cr3(page_to_mfn(page));
+ rc = new_guest_cr3(mfn_x(page_to_mfn(page)));
put_page(page);
switch ( rc )
diff --git a/xen/arch/x86/pv/iret.c b/xen/arch/x86/pv/iret.c
index ca433a6..56aeac3 100644
--- a/xen/arch/x86/pv/iret.c
+++ b/xen/arch/x86/pv/iret.c
@@ -24,6 +24,12 @@
#include <asm/current.h>
#include <asm/traps.h>
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
unsigned long do_iret(void)
{
struct cpu_user_regs *regs = guest_cpu_user_regs();
diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c
index 2a605ed..d122881 100644
--- a/xen/arch/x86/pv/traps.c
+++ b/xen/arch/x86/pv/traps.c
@@ -29,6 +29,12 @@
#include <asm/shared.h>
#include <asm/traps.h>
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
void do_entry_int82(struct cpu_user_regs *regs)
{
if ( unlikely(untrusted_msi) )
diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h
index b4ce5ae..cde5c6b 100644
--- a/xen/include/asm-x86/page.h
+++ b/xen/include/asm-x86/page.h
@@ -215,13 +215,13 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)
/* Page-table type. */
typedef struct { u64 pfn; } pagetable_t;
#define pagetable_get_paddr(x) ((paddr_t)(x).pfn << PAGE_SHIFT)
-#define pagetable_get_page(x) mfn_to_page((x).pfn)
+#define pagetable_get_page(x) __mfn_to_page((x).pfn)
#define pagetable_get_pfn(x) ((x).pfn)
#define pagetable_get_mfn(x) _mfn(((x).pfn))
#define pagetable_is_null(x) ((x).pfn == 0)
#define pagetable_from_pfn(pfn) ((pagetable_t) { (pfn) })
#define pagetable_from_mfn(mfn) ((pagetable_t) { mfn_x(mfn) })
-#define pagetable_from_page(pg) pagetable_from_pfn(page_to_mfn(pg))
+#define pagetable_from_page(pg) pagetable_from_pfn(__page_to_mfn(pg))
#define pagetable_from_paddr(p) pagetable_from_pfn((p)>>PAGE_SHIFT)
#define pagetable_null() pagetable_from_pfn(0)
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-08-29 11:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-29 11:19 [PATCH 0/5] x86: Misc cleanup and improvements Andrew Cooper
2017-08-29 11:19 ` [PATCH 1/5] x86/pv: Switch {fill, zap}_ro_mpt() to using mfn_t Andrew Cooper
2017-08-29 11:52 ` Tim Deegan
2017-08-29 12:01 ` George Dunlap
2017-08-29 12:17 ` Wei Liu
2017-08-29 14:00 ` Jan Beulich
2017-08-29 11:19 ` [PATCH 2/5] x86/pv: map_ldt_shadow_page() cleanup Andrew Cooper
2017-08-29 12:35 ` Wei Liu
2017-08-29 14:14 ` Jan Beulich
2017-08-29 14:54 ` Andrew Cooper
2017-08-29 15:57 ` [PATCH v2 " Andrew Cooper
2017-08-30 8:21 ` Jan Beulich
2017-08-29 11:19 ` Andrew Cooper [this message]
2017-08-29 13:39 ` [PATCH 3/5] x86/pv: Consistently use typesafe helpers in all files Wei Liu
2017-08-29 14:19 ` Jan Beulich
2017-08-29 11:19 ` [PATCH 4/5] x86/pv: Simplify access to the LDT/GDT ptes Andrew Cooper
2017-08-29 13:43 ` Wei Liu
2017-08-29 14:23 ` Jan Beulich
2017-08-29 11:19 ` [PATCH 5/5] x86/percpu: Misc cleanup Andrew Cooper
2017-08-29 13:44 ` Wei Liu
2017-08-29 14:24 ` Jan Beulich
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=1504005556-30394-4-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=wei.liu2@citrix.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).