[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 3/5] x86/pv: Consistently use typesafe helpers in all files
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@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> --- 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@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |