diff mbox series

[Xen-devel,8/8] xen: Swich parameter in get_page_from_gfn to use typesafe gfn

Message ID 20181106191454.22143-9-julien.grall@arm.com
State New
Headers show
Series xen/arm: Add xentrace support | expand

Commit Message

Julien Grall Nov. 6, 2018, 7:14 p.m. UTC
No functional change intended.

Only reasonable clean-ups are done in this patch. The rest will use _gfn
for the time being.

Signed-off-by: Julien Grall <julie.grall@arm.com>
---
 xen/arch/arm/guestcopy.c             |  2 +-
 xen/arch/arm/mm.c                    |  2 +-
 xen/arch/x86/cpu/vpmu.c              |  2 +-
 xen/arch/x86/domain.c                | 12 ++++++------
 xen/arch/x86/domctl.c                |  6 +++---
 xen/arch/x86/hvm/dm.c                |  2 +-
 xen/arch/x86/hvm/domain.c            |  2 +-
 xen/arch/x86/hvm/hvm.c               |  9 +++++----
 xen/arch/x86/hvm/svm/svm.c           |  8 ++++----
 xen/arch/x86/hvm/viridian/viridian.c | 24 ++++++++++++------------
 xen/arch/x86/hvm/vmx/vmx.c           |  4 ++--
 xen/arch/x86/hvm/vmx/vvmx.c          | 12 ++++++------
 xen/arch/x86/mm.c                    | 24 ++++++++++++++----------
 xen/arch/x86/mm/p2m.c                |  2 +-
 xen/arch/x86/mm/shadow/hvm.c         |  6 +++---
 xen/arch/x86/physdev.c               |  3 ++-
 xen/arch/x86/pv/descriptor-tables.c  |  5 ++---
 xen/arch/x86/pv/emul-priv-op.c       |  6 +++---
 xen/arch/x86/pv/mm.c                 |  2 +-
 xen/arch/x86/traps.c                 | 11 ++++++-----
 xen/common/domain.c                  |  2 +-
 xen/common/event_fifo.c              | 12 ++++++------
 xen/common/memory.c                  |  4 ++--
 xen/common/tmem_xen.c                |  2 +-
 xen/include/asm-arm/p2m.h            |  6 +++---
 xen/include/asm-x86/p2m.h            | 11 +++++++----
 26 files changed, 95 insertions(+), 86 deletions(-)

Comments

Andrew Cooper Nov. 6, 2018, 8:11 p.m. UTC | #1
Hi - just some cosmetic suggestions.

Subject s/Swich/Switch/

> diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
> index f73ea4a163..a529ebcc3f 100644
> --- a/xen/arch/x86/pv/emul-priv-op.c
> +++ b/xen/arch/x86/pv/emul-priv-op.c
> @@ -760,12 +760,12 @@ static int write_cr(unsigned int reg, unsigned long val,
>      case 3: /* Write CR3 */
>      {
>          struct domain *currd = curr->domain;
> -        unsigned long gfn;
> +        gfn_t gfn;
>          struct page_info *page;
>          int rc;
>  
> -        gfn = !is_pv_32bit_domain(currd)
> -              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val);
> +        gfn = _gfn(!is_pv_32bit_domain(currd)
> +              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val));

Please re-indent.

>          page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);
>          if ( !page )
>              break;
> diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
> index 9471d89022..d967e49432 100644
> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -817,13 +817,14 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)
>  
>              if ( p2m_is_paging(t) )
>              {
> -                p2m_mem_paging_populate(d, gmfn);
> +                p2m_mem_paging_populate(d, gfn_x(gfn));
>                  return X86EMUL_RETRY;
>              }
>  
>              gdprintk(XENLOG_WARNING,
> -                     "Bad GMFN %lx (MFN %#"PRI_mfn") to MSR %08x\n",
> -                     gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN), base);
> +                     "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn") to MSR %08x\n",

GMFN => GFN.

> +                     gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN),
> +                     base);
>              return X86EMUL_EXCEPTION;
>          }
>  
> diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
> index d08c595887..db1ec37610 100644
> --- a/xen/include/asm-x86/p2m.h
> +++ b/xen/include/asm-x86/p2m.h
> @@ -489,18 +489,21 @@ struct page_info *p2m_get_page_from_gfn(struct p2m_domain *p2m, gfn_t gfn,
>                                          p2m_query_t q);
>  
>  static inline struct page_info *get_page_from_gfn(
> -    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)
> +    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)
>  {
>      struct page_info *page;
> +    mfn_t mfn;
>  
>      if ( paging_mode_translate(d) )
> -        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t, NULL, q);
> +        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL, q);
>  
>      /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */
>      if ( t )
>          *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct;
> -    page = mfn_to_page(_mfn(gfn));
> -    return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL;
> +
> +    mfn = _mfn(gfn_x(gfn));
> +    page = mfn_to_page(mfn);
> +    return mfn_valid(mfn) && get_page(page, d) ? page : NULL;

This looks like it would be cleaner by not splitting mfn out into a
separate variable.

page = mfn_to_page(_mfn(gfn_x(gfn)));

return mfn_valid(mfn) && get_page(page, d) ? page : NULL;

The only reason this looks odd is because of the mfn => gfn equality,
but we are just beside a comment explaining that we are non-translated.

~Andrew
Paul Durrant Nov. 7, 2018, 8:57 a.m. UTC | #2
> -----Original Message-----

> From: Andrew Cooper

> Sent: 06 November 2018 20:12

> To: Julien Grall <julien.grall@arm.com>; sstabellini@kernel.org; xen-

> devel@lists.xenproject.org

> Cc: George Dunlap <George.Dunlap@citrix.com>; Ian Jackson

> <Ian.Jackson@citrix.com>; Jan Beulich <jbeulich@suse.com>; Konrad

> Rzeszutek Wilk <konrad.wilk@oracle.com>; Tim (Xen.org) <tim@xen.org>; Wei

> Liu <wei.liu2@citrix.com>; Boris Ostrovsky <boris.ostrovsky@oracle.com>;

> Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>; Brian Woods

> <brian.woods@amd.com>; Paul Durrant <Paul.Durrant@citrix.com>; Jun

> Nakajima <jun.nakajima@intel.com>; Kevin Tian <kevin.tian@intel.com>;

> Julien Grall <julie.grall@arm.com>

> Subject: Re: [PATCH 8/8] xen: Swich parameter in get_page_from_gfn to use

> typesafe gfn

> 

> Hi - just some cosmetic suggestions.

> 

> Subject s/Swich/Switch/

> 

> > diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-

> op.c

> > index f73ea4a163..a529ebcc3f 100644

> > --- a/xen/arch/x86/pv/emul-priv-op.c

> > +++ b/xen/arch/x86/pv/emul-priv-op.c

> > @@ -760,12 +760,12 @@ static int write_cr(unsigned int reg, unsigned

> long val,

> >      case 3: /* Write CR3 */

> >      {

> >          struct domain *currd = curr->domain;

> > -        unsigned long gfn;

> > +        gfn_t gfn;

> >          struct page_info *page;

> >          int rc;

> >

> > -        gfn = !is_pv_32bit_domain(currd)

> > -              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val);

> > +        gfn = _gfn(!is_pv_32bit_domain(currd)

> > +              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val));

> 

> Please re-indent.

> 

> >          page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);

> >          if ( !page )

> >              break;

> > diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c

> > index 9471d89022..d967e49432 100644

> > --- a/xen/arch/x86/traps.c

> > +++ b/xen/arch/x86/traps.c

> > @@ -817,13 +817,14 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx,

> uint64_t val)

> >

> >              if ( p2m_is_paging(t) )

> >              {

> > -                p2m_mem_paging_populate(d, gmfn);

> > +                p2m_mem_paging_populate(d, gfn_x(gfn));

> >                  return X86EMUL_RETRY;

> >              }

> >

> >              gdprintk(XENLOG_WARNING,

> > -                     "Bad GMFN %lx (MFN %#"PRI_mfn") to MSR %08x\n",

> > -                     gmfn, mfn_x(page ? page_to_mfn(page) :

> INVALID_MFN), base);

> > +                     "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn") to MSR

> %08x\n",

> 

> GMFN => GFN.

> 

> > +                     gfn_x(gfn), mfn_x(page ? page_to_mfn(page) :

> INVALID_MFN),

> > +                     base);

> >              return X86EMUL_EXCEPTION;

> >          }

> >

> > diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h

> > index d08c595887..db1ec37610 100644

> > --- a/xen/include/asm-x86/p2m.h

> > +++ b/xen/include/asm-x86/p2m.h

> > @@ -489,18 +489,21 @@ struct page_info *p2m_get_page_from_gfn(struct

> p2m_domain *p2m, gfn_t gfn,

> >                                          p2m_query_t q);

> >

> >  static inline struct page_info *get_page_from_gfn(

> > -    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)

> > +    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)

> >  {

> >      struct page_info *page;

> > +    mfn_t mfn;

> >

> >      if ( paging_mode_translate(d) )

> > -        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t,

> NULL, q);

> > +        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL,

> q);

> >

> >      /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */

> >      if ( t )

> >          *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct;

> > -    page = mfn_to_page(_mfn(gfn));

> > -    return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL;

> > +

> > +    mfn = _mfn(gfn_x(gfn));

> > +    page = mfn_to_page(mfn);

> > +    return mfn_valid(mfn) && get_page(page, d) ? page : NULL;

> 

> This looks like it would be cleaner by not splitting mfn out into a

> separate variable.

> 

> page = mfn_to_page(_mfn(gfn_x(gfn)));

> 

> return mfn_valid(mfn) && get_page(page, d) ? page : NULL;


^^ er... how's that mfn_valid() going to work? You'd need mfn_valid(page_to_mfn(pahge)), or somesuch.

  Paul

> 

> The only reason this looks odd is because of the mfn => gfn equality,

> but we are just beside a comment explaining that we are non-translated.

> 

> ~Andrew
Paul Durrant Nov. 7, 2018, 9:24 a.m. UTC | #3
> -----Original Message-----
> From: Julien Grall [mailto:julien.grall@arm.com]
> Sent: 06 November 2018 19:15
> To: sstabellini@kernel.org; xen-devel@lists.xenproject.org
> Cc: Julien Grall <julien.grall@arm.com>; Andrew Cooper
> <Andrew.Cooper3@citrix.com>; George Dunlap <George.Dunlap@citrix.com>; Ian
> Jackson <Ian.Jackson@citrix.com>; Jan Beulich <jbeulich@suse.com>; Konrad
> Rzeszutek Wilk <konrad.wilk@oracle.com>; Tim (Xen.org) <tim@xen.org>; Wei
> Liu <wei.liu2@citrix.com>; Boris Ostrovsky <boris.ostrovsky@oracle.com>;
> Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>; Brian Woods
> <brian.woods@amd.com>; Paul Durrant <Paul.Durrant@citrix.com>; Jun
> Nakajima <jun.nakajima@intel.com>; Kevin Tian <kevin.tian@intel.com>;
> Julien Grall <julie.grall@arm.com>
> Subject: [PATCH 8/8] xen: Swich parameter in get_page_from_gfn to use
> typesafe gfn
> 
> No functional change intended.
> 
> Only reasonable clean-ups are done in this patch. The rest will use _gfn
> for the time being.
> 
> Signed-off-by: Julien Grall <julie.grall@arm.com>
> ---
>  xen/arch/arm/guestcopy.c             |  2 +-
>  xen/arch/arm/mm.c                    |  2 +-
>  xen/arch/x86/cpu/vpmu.c              |  2 +-
>  xen/arch/x86/domain.c                | 12 ++++++------
>  xen/arch/x86/domctl.c                |  6 +++---
>  xen/arch/x86/hvm/dm.c                |  2 +-
>  xen/arch/x86/hvm/domain.c            |  2 +-
>  xen/arch/x86/hvm/hvm.c               |  9 +++++----
>  xen/arch/x86/hvm/svm/svm.c           |  8 ++++----
>  xen/arch/x86/hvm/viridian/viridian.c | 24 ++++++++++++------------
>  xen/arch/x86/hvm/vmx/vmx.c           |  4 ++--
>  xen/arch/x86/hvm/vmx/vvmx.c          | 12 ++++++------
>  xen/arch/x86/mm.c                    | 24 ++++++++++++++----------
>  xen/arch/x86/mm/p2m.c                |  2 +-
>  xen/arch/x86/mm/shadow/hvm.c         |  6 +++---
>  xen/arch/x86/physdev.c               |  3 ++-
>  xen/arch/x86/pv/descriptor-tables.c  |  5 ++---
>  xen/arch/x86/pv/emul-priv-op.c       |  6 +++---
>  xen/arch/x86/pv/mm.c                 |  2 +-
>  xen/arch/x86/traps.c                 | 11 ++++++-----
>  xen/common/domain.c                  |  2 +-
>  xen/common/event_fifo.c              | 12 ++++++------
>  xen/common/memory.c                  |  4 ++--
>  xen/common/tmem_xen.c                |  2 +-
>  xen/include/asm-arm/p2m.h            |  6 +++---
>  xen/include/asm-x86/p2m.h            | 11 +++++++----
>  26 files changed, 95 insertions(+), 86 deletions(-)
> 
[snip]
> diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
> index 5d00256aaa..a7419bd444 100644
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -317,7 +317,7 @@ static int svm_vmcb_restore(struct vcpu *v, struct
> hvm_hw_cpu *c)
>      {
>          if ( c->cr0 & X86_CR0_PG )
>          {
> -            page = get_page_from_gfn(v->domain, c->cr3 >> PAGE_SHIFT,
> +            page = get_page_from_gfn(v->domain, gaddr_to_gfn(c->cr3),
>                                       NULL, P2M_ALLOC);
>              if ( !page )
>              {
> @@ -2412,9 +2412,9 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t
> vmcbaddr)
>          return NULL;
> 
>      /* Need to translate L1-GPA to MPA */
> -    page = get_page_from_gfn(v->domain,
> -                            nv->nv_vvmcxaddr >> PAGE_SHIFT,
> -                            &p2mt, P2M_ALLOC | P2M_UNSHARE);
> +    page = get_page_from_gfn(v->domain,
> +                             gaddr_to_gfn(nv->nv_vvmcxaddr >>
> PAGE_SHIFT),

Don't you need to lose the '>> PAGE_SHIFT' now?

  Paul

> +                             &p2mt, P2M_ALLOC | P2M_UNSHARE);
>      if ( !page )
>          return NULL;
>
Julien Grall Nov. 7, 2018, 1:05 p.m. UTC | #4
Hi Paul,

On 07/11/2018 09:24, Paul Durrant wrote:
>> -----Original Message-----
>> From: Julien Grall [mailto:julien.grall@arm.com]
>> Sent: 06 November 2018 19:15
>> To: sstabellini@kernel.org; xen-devel@lists.xenproject.org
>> Cc: Julien Grall <julien.grall@arm.com>; Andrew Cooper
>> <Andrew.Cooper3@citrix.com>; George Dunlap <George.Dunlap@citrix.com>; Ian
>> Jackson <Ian.Jackson@citrix.com>; Jan Beulich <jbeulich@suse.com>; Konrad
>> Rzeszutek Wilk <konrad.wilk@oracle.com>; Tim (Xen.org) <tim@xen.org>; Wei
>> Liu <wei.liu2@citrix.com>; Boris Ostrovsky <boris.ostrovsky@oracle.com>;
>> Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>; Brian Woods
>> <brian.woods@amd.com>; Paul Durrant <Paul.Durrant@citrix.com>; Jun
>> Nakajima <jun.nakajima@intel.com>; Kevin Tian <kevin.tian@intel.com>;
>> Julien Grall <julie.grall@arm.com>
>> Subject: [PATCH 8/8] xen: Swich parameter in get_page_from_gfn to use
>> typesafe gfn
>>
>> No functional change intended.
>>
>> Only reasonable clean-ups are done in this patch. The rest will use _gfn
>> for the time being.
>>
>> Signed-off-by: Julien Grall <julie.grall@arm.com>
>> ---
>>   xen/arch/arm/guestcopy.c             |  2 +-
>>   xen/arch/arm/mm.c                    |  2 +-
>>   xen/arch/x86/cpu/vpmu.c              |  2 +-
>>   xen/arch/x86/domain.c                | 12 ++++++------
>>   xen/arch/x86/domctl.c                |  6 +++---
>>   xen/arch/x86/hvm/dm.c                |  2 +-
>>   xen/arch/x86/hvm/domain.c            |  2 +-
>>   xen/arch/x86/hvm/hvm.c               |  9 +++++----
>>   xen/arch/x86/hvm/svm/svm.c           |  8 ++++----
>>   xen/arch/x86/hvm/viridian/viridian.c | 24 ++++++++++++------------
>>   xen/arch/x86/hvm/vmx/vmx.c           |  4 ++--
>>   xen/arch/x86/hvm/vmx/vvmx.c          | 12 ++++++------
>>   xen/arch/x86/mm.c                    | 24 ++++++++++++++----------
>>   xen/arch/x86/mm/p2m.c                |  2 +-
>>   xen/arch/x86/mm/shadow/hvm.c         |  6 +++---
>>   xen/arch/x86/physdev.c               |  3 ++-
>>   xen/arch/x86/pv/descriptor-tables.c  |  5 ++---
>>   xen/arch/x86/pv/emul-priv-op.c       |  6 +++---
>>   xen/arch/x86/pv/mm.c                 |  2 +-
>>   xen/arch/x86/traps.c                 | 11 ++++++-----
>>   xen/common/domain.c                  |  2 +-
>>   xen/common/event_fifo.c              | 12 ++++++------
>>   xen/common/memory.c                  |  4 ++--
>>   xen/common/tmem_xen.c                |  2 +-
>>   xen/include/asm-arm/p2m.h            |  6 +++---
>>   xen/include/asm-x86/p2m.h            | 11 +++++++----
>>   26 files changed, 95 insertions(+), 86 deletions(-)
>>
> [snip]
>> diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
>> index 5d00256aaa..a7419bd444 100644
>> --- a/xen/arch/x86/hvm/svm/svm.c
>> +++ b/xen/arch/x86/hvm/svm/svm.c
>> @@ -317,7 +317,7 @@ static int svm_vmcb_restore(struct vcpu *v, struct
>> hvm_hw_cpu *c)
>>       {
>>           if ( c->cr0 & X86_CR0_PG )
>>           {
>> -            page = get_page_from_gfn(v->domain, c->cr3 >> PAGE_SHIFT,
>> +            page = get_page_from_gfn(v->domain, gaddr_to_gfn(c->cr3),
>>                                        NULL, P2M_ALLOC);
>>               if ( !page )
>>               {
>> @@ -2412,9 +2412,9 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t
>> vmcbaddr)
>>           return NULL;
>>
>>       /* Need to translate L1-GPA to MPA */
>> -    page = get_page_from_gfn(v->domain,
>> -                            nv->nv_vvmcxaddr >> PAGE_SHIFT,
>> -                            &p2mt, P2M_ALLOC | P2M_UNSHARE);
>> +    page = get_page_from_gfn(v->domain,
>> +                             gaddr_to_gfn(nv->nv_vvmcxaddr >>
>> PAGE_SHIFT),
> 
> Don't you need to lose the '>> PAGE_SHIFT' now?

Yes. Brian reported on IRC and now it is fixed.

Thank you for the review.

Cheers,
Julien Grall Nov. 7, 2018, 1:08 p.m. UTC | #5
Hi Andrew,

On 06/11/2018 20:11, Andrew Cooper wrote:
> This looks like it would be cleaner by not splitting mfn out into a
> separate variable.
> 
> page = mfn_to_page(_mfn(gfn_x(gfn)));
> 
> return mfn_valid(mfn) && get_page(page, d) ? page : NULL;
> 
> The only reason this looks odd is because of the mfn => gfn equality,
> but we are just beside a comment explaining that we are non-translated.

I introduced the mfn variable to avoid duplicating _mfn(gfn_x(gfn)) in the two 
places where gfn was used.

I am happy to duplicated if you prefer.

Cheers,
Andrew Cooper Nov. 7, 2018, 1:08 p.m. UTC | #6
On 07/11/18 08:57, Paul Durrant wrote:
>>
>>>  static inline struct page_info *get_page_from_gfn(
>>> -    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)
>>> +    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)
>>>  {
>>>      struct page_info *page;
>>> +    mfn_t mfn;
>>>
>>>      if ( paging_mode_translate(d) )
>>> -        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t,
>> NULL, q);
>>> +        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL,
>> q);
>>>      /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */
>>>      if ( t )
>>>          *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct;
>>> -    page = mfn_to_page(_mfn(gfn));
>>> -    return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL;
>>> +
>>> +    mfn = _mfn(gfn_x(gfn));
>>> +    page = mfn_to_page(mfn);
>>> +    return mfn_valid(mfn) && get_page(page, d) ? page : NULL;
>> This looks like it would be cleaner by not splitting mfn out into a
>> separate variable.
>>
>> page = mfn_to_page(_mfn(gfn_x(gfn)));
>>
>> return mfn_valid(mfn) && get_page(page, d) ? page : NULL;
> ^^ er... how's that mfn_valid() going to work? You'd need mfn_valid(page_to_mfn(pahge)), or somesuch.

Oops - I'm blind.  Sorry for the noise.

~Andrew
Andrii Anisov Nov. 12, 2018, 4:49 p.m. UTC | #7
Hello Julien,

I'm just wondering if this patch really belongs to xentrace series.
It rather looks like a separate cleanup patch.

Sincerely,
Andrii Anisov.


вт, 6 лист. 2018 о 21:16 Julien Grall <julien.grall@arm.com> пише:

> No functional change intended.

>

> Only reasonable clean-ups are done in this patch. The rest will use _gfn

> for the time being.

>

> Signed-off-by: Julien Grall <julie.grall@arm.com>

> ---

>  xen/arch/arm/guestcopy.c             |  2 +-

>  xen/arch/arm/mm.c                    |  2 +-

>  xen/arch/x86/cpu/vpmu.c              |  2 +-

>  xen/arch/x86/domain.c                | 12 ++++++------

>  xen/arch/x86/domctl.c                |  6 +++---

>  xen/arch/x86/hvm/dm.c                |  2 +-

>  xen/arch/x86/hvm/domain.c            |  2 +-

>  xen/arch/x86/hvm/hvm.c               |  9 +++++----

>  xen/arch/x86/hvm/svm/svm.c           |  8 ++++----

>  xen/arch/x86/hvm/viridian/viridian.c | 24 ++++++++++++------------

>  xen/arch/x86/hvm/vmx/vmx.c           |  4 ++--

>  xen/arch/x86/hvm/vmx/vvmx.c          | 12 ++++++------

>  xen/arch/x86/mm.c                    | 24 ++++++++++++++----------

>  xen/arch/x86/mm/p2m.c                |  2 +-

>  xen/arch/x86/mm/shadow/hvm.c         |  6 +++---

>  xen/arch/x86/physdev.c               |  3 ++-

>  xen/arch/x86/pv/descriptor-tables.c  |  5 ++---

>  xen/arch/x86/pv/emul-priv-op.c       |  6 +++---

>  xen/arch/x86/pv/mm.c                 |  2 +-

>  xen/arch/x86/traps.c                 | 11 ++++++-----

>  xen/common/domain.c                  |  2 +-

>  xen/common/event_fifo.c              | 12 ++++++------

>  xen/common/memory.c                  |  4 ++--

>  xen/common/tmem_xen.c                |  2 +-

>  xen/include/asm-arm/p2m.h            |  6 +++---

>  xen/include/asm-x86/p2m.h            | 11 +++++++----

>  26 files changed, 95 insertions(+), 86 deletions(-)

>

> diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c

> index 7a0f3e9d5f..55892062bb 100644

> --- a/xen/arch/arm/guestcopy.c

> +++ b/xen/arch/arm/guestcopy.c

> @@ -37,7 +37,7 @@ static struct page_info *translate_get_page(copy_info_t

> info, uint64_t addr,

>          return get_page_from_gva(info.gva.v, addr,

>                                   write ? GV2M_WRITE : GV2M_READ);

>

> -    page = get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &p2mt,

> P2M_ALLOC);

> +    page = get_page_from_gfn(info.gpa.d, gaddr_to_gfn(addr), &p2mt,

> P2M_ALLOC);

>

>      if ( !page )

>          return NULL;

> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c

> index 72d0285768..88711096ef 100644

> --- a/xen/arch/arm/mm.c

> +++ b/xen/arch/arm/mm.c

> @@ -1268,7 +1268,7 @@ int xenmem_add_to_physmap_one(

>

>          /* Take reference to the foreign domain page.

>           * Reference will be released in XENMEM_remove_from_physmap */

> -        page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC);

> +        page = get_page_from_gfn(od, _gfn(idx), &p2mt, P2M_ALLOC);

>          if ( !page )

>          {

>              put_pg_owner(od);

> diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c

> index 8a4f753eae..4d8f153031 100644

> --- a/xen/arch/x86/cpu/vpmu.c

> +++ b/xen/arch/x86/cpu/vpmu.c

> @@ -607,7 +607,7 @@ static int pvpmu_init(struct domain *d,

> xen_pmu_params_t *params)

>      struct vcpu *v;

>      struct vpmu_struct *vpmu;

>      struct page_info *page;

> -    uint64_t gfn = params->val;

> +    gfn_t gfn = _gfn(params->val);

>

>      if ( (params->vcpu >= d->max_vcpus) || (d->vcpu[params->vcpu] ==

> NULL) )

>          return -EINVAL;

> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c

> index f6fe954313..c5cce4b38d 100644

> --- a/xen/arch/x86/domain.c

> +++ b/xen/arch/x86/domain.c

> @@ -797,7 +797,7 @@ int arch_set_info_guest(

>      unsigned long flags;

>      bool compat;

>  #ifdef CONFIG_PV

> -    unsigned long cr3_gfn;

> +    gfn_t cr3_gfn;

>      struct page_info *cr3_page;

>      unsigned long cr4;

>      int rc = 0;

> @@ -1061,9 +1061,9 @@ int arch_set_info_guest(

>      set_bit(_VPF_in_reset, &v->pause_flags);

>

>      if ( !compat )

> -        cr3_gfn = xen_cr3_to_pfn(c.nat->ctrlreg[3]);

> +        cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat->ctrlreg[3]));

>      else

> -        cr3_gfn = compat_cr3_to_pfn(c.cmp->ctrlreg[3]);

> +        cr3_gfn = _gfn(compat_cr3_to_pfn(c.cmp->ctrlreg[3]));

>      cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC);

>

>      if ( !cr3_page )

> @@ -1092,7 +1092,7 @@ int arch_set_info_guest(

>          case 0:

>              if ( !compat && !VM_ASSIST(d, m2p_strict) &&

>                   !paging_mode_refcounts(d) )

> -                fill_ro_mpt(_mfn(cr3_gfn));

> +                fill_ro_mpt(_mfn(gfn_x(cr3_gfn)));

>              break;

>          default:

>              if ( cr3_page == current->arch.old_guest_table )

> @@ -1107,7 +1107,7 @@ int arch_set_info_guest(

>          v->arch.guest_table = pagetable_from_page(cr3_page);

>          if ( c.nat->ctrlreg[1] )

>          {

> -            cr3_gfn = xen_cr3_to_pfn(c.nat->ctrlreg[1]);

> +            cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat->ctrlreg[1]));

>              cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC);

>

>              if ( !cr3_page )

> @@ -1132,7 +1132,7 @@ int arch_set_info_guest(

>                      break;

>                  case 0:

>                      if ( VM_ASSIST(d, m2p_strict) )

> -                        zap_ro_mpt(_mfn(cr3_gfn));

> +                        zap_ro_mpt(_mfn(gfn_x(cr3_gfn)));

>                      break;

>                  }

>              }

> diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c

> index 33f9a869c0..6b0d8075cd 100644

> --- a/xen/arch/x86/domctl.c

> +++ b/xen/arch/x86/domctl.c

> @@ -448,7 +448,7 @@ long arch_do_domctl(

>                  break;

>              }

>

> -            page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC);

> +            page = get_page_from_gfn(d, _gfn(gfn), &t, P2M_ALLOC);

>

>              if ( unlikely(!page) ||

>                   unlikely(is_xen_heap_page(page)) )

> @@ -498,11 +498,11 @@ long arch_do_domctl(

>

>      case XEN_DOMCTL_hypercall_init:

>      {

> -        unsigned long gmfn = domctl->u.hypercall_init.gmfn;

> +        gfn_t gfn = _gfn(domctl->u.hypercall_init.gmfn);

>          struct page_info *page;

>          void *hypercall_page;

>

> -        page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);

> +        page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);

>

>          if ( !page || !get_page_type(page, PGT_writable_page) )

>          {

> diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c

> index d6d0e8be89..3b3ad27938 100644

> --- a/xen/arch/x86/hvm/dm.c

> +++ b/xen/arch/x86/hvm/dm.c

> @@ -186,7 +186,7 @@ static int modified_memory(struct domain *d,

>          {

>              struct page_info *page;

>

> -            page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE);

> +            page = get_page_from_gfn(d, _gfn(pfn), NULL, P2M_UNSHARE);

>              if ( page )

>              {

>                  paging_mark_pfn_dirty(d, _pfn(pfn));

> diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c

> index 5d5a746a25..73d2da8441 100644

> --- a/xen/arch/x86/hvm/domain.c

> +++ b/xen/arch/x86/hvm/domain.c

> @@ -297,7 +297,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const

> vcpu_hvm_context_t *ctx)

>      {

>          /* Shadow-mode CR3 change. Check PDBR and update refcounts. */

>          struct page_info *page = get_page_from_gfn(v->domain,

> -                                 v->arch.hvm.guest_cr[3] >> PAGE_SHIFT,

> +                                 gaddr_to_gfn(v->arch.hvm.guest_cr[3]),

>                                   NULL, P2M_ALLOC);

>          if ( !page )

>          {

> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c

> index 7be9cf4454..be262e5a1d 100644

> --- a/xen/arch/x86/hvm/hvm.c

> +++ b/xen/arch/x86/hvm/hvm.c

> @@ -2146,7 +2146,7 @@ int hvm_set_cr0(unsigned long value, bool may_defer)

>  {

>      struct vcpu *v = current;

>      struct domain *d = v->domain;

> -    unsigned long gfn, old_value = v->arch.hvm.guest_cr[0];

> +    unsigned long old_value = v->arch.hvm.guest_cr[0];

>      struct page_info *page;

>

>      HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value = %lx", value);

> @@ -2201,7 +2201,8 @@ int hvm_set_cr0(unsigned long value, bool may_defer)

>          if ( !paging_mode_hap(d) )

>          {

>              /* The guest CR3 must be pointing to the guest physical. */

> -            gfn = v->arch.hvm.guest_cr[3] >> PAGE_SHIFT;

> +            gfn_t gfn = gaddr_to_gfn(v->arch.hvm.guest_cr[3]);

> +

>              page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);

>              if ( !page )

>              {

> @@ -2293,7 +2294,7 @@ int hvm_set_cr3(unsigned long value, bool may_defer)

>      {

>          /* Shadow-mode CR3 change. Check PDBR and update refcounts. */

>          HVM_DBG_LOG(DBG_LEVEL_VMMU, "CR3 value = %lx", value);

> -        page = get_page_from_gfn(v->domain, value >> PAGE_SHIFT,

> +        page = get_page_from_gfn(v->domain, gaddr_to_gfn(value),

>                                   NULL, P2M_ALLOC);

>          if ( !page )

>              goto bad_cr3;

> @@ -3120,7 +3121,7 @@ enum hvm_translation_result hvm_translate_get_page(

>           && hvm_mmio_internal(gfn_to_gaddr(gfn)) )

>          return HVMTRANS_bad_gfn_to_mfn;

>

> -    page = get_page_from_gfn(v->domain, gfn_x(gfn), &p2mt, P2M_UNSHARE);

> +    page = get_page_from_gfn(v->domain, gfn, &p2mt, P2M_UNSHARE);

>

>      if ( !page )

>          return HVMTRANS_bad_gfn_to_mfn;

> diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c

> index 5d00256aaa..a7419bd444 100644

> --- a/xen/arch/x86/hvm/svm/svm.c

> +++ b/xen/arch/x86/hvm/svm/svm.c

> @@ -317,7 +317,7 @@ static int svm_vmcb_restore(struct vcpu *v, struct

> hvm_hw_cpu *c)

>      {

>          if ( c->cr0 & X86_CR0_PG )

>          {

> -            page = get_page_from_gfn(v->domain, c->cr3 >> PAGE_SHIFT,

> +            page = get_page_from_gfn(v->domain, gaddr_to_gfn(c->cr3),

>                                       NULL, P2M_ALLOC);

>              if ( !page )

>              {

> @@ -2412,9 +2412,9 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t

> vmcbaddr)

>          return NULL;

>

>      /* Need to translate L1-GPA to MPA */

> -    page = get_page_from_gfn(v->domain,

> -                            nv->nv_vvmcxaddr >> PAGE_SHIFT,

> -                            &p2mt, P2M_ALLOC | P2M_UNSHARE);

> +    page = get_page_from_gfn(v->domain,

> +                             gaddr_to_gfn(nv->nv_vvmcxaddr >> PAGE_SHIFT),

> +                             &p2mt, P2M_ALLOC | P2M_UNSHARE);

>      if ( !page )

>          return NULL;

>

> diff --git a/xen/arch/x86/hvm/viridian/viridian.c

> b/xen/arch/x86/hvm/viridian/viridian.c

> index 2dc86dd0f3..1d3be156db 100644

> --- a/xen/arch/x86/hvm/viridian/viridian.c

> +++ b/xen/arch/x86/hvm/viridian/viridian.c

> @@ -332,16 +332,16 @@ static void dump_reference_tsc(const struct domain

> *d)

>

>  static void enable_hypercall_page(struct domain *d)

>  {

> -    unsigned long gmfn = d->arch.hvm.viridian.hypercall_gpa.fields.pfn;

> -    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);

> +    gfn_t gfn = _gfn(d->arch.hvm.viridian.hypercall_gpa.fields.pfn);

> +    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);

>      uint8_t *p;

>

>      if ( !page || !get_page_type(page, PGT_writable_page) )

>      {

>          if ( page )

>              put_page(page);

> -        gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN

> %#"PRI_mfn")\n",

> -                 gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));

> +        gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN

> %#"PRI_mfn")\n",

> +                 gfn_x(gfn), mfn_x(page ? page_to_mfn(page) :

> INVALID_MFN));

>          return;

>      }

>

> @@ -367,8 +367,8 @@ static void enable_hypercall_page(struct domain *d)

>  static void initialize_vp_assist(struct vcpu *v)

>  {

>      struct domain *d = v->domain;

> -    unsigned long gmfn = v->arch.hvm.viridian.vp_assist.msr.fields.pfn;

> -    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);

> +    gfn_t gfn = _gfn(v->arch.hvm.viridian.vp_assist.msr.fields.pfn);

> +    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);

>      void *va;

>

>      ASSERT(!v->arch.hvm.viridian.vp_assist.va);

> @@ -395,8 +395,8 @@ static void initialize_vp_assist(struct vcpu *v)

>      return;

>

>   fail:

> -    gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",

> -             gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));

> +    gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",

> +             gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));

>  }

>

>  static void teardown_vp_assist(struct vcpu *v)

> @@ -465,16 +465,16 @@ void viridian_apic_assist_clear(struct vcpu *v)

>

>  static void update_reference_tsc(struct domain *d, bool_t initialize)

>  {

> -    unsigned long gmfn = d->arch.hvm.viridian.reference_tsc.fields.pfn;

> -    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);

> +    gfn_t gfn = _gfn(d->arch.hvm.viridian.reference_tsc.fields.pfn);

> +    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);

>      HV_REFERENCE_TSC_PAGE *p;

>

>      if ( !page || !get_page_type(page, PGT_writable_page) )

>      {

>          if ( page )

>              put_page(page);

> -        gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN

> %#"PRI_mfn")\n",

> -                 gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));

> +        gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN

> %#"PRI_mfn")\n",

> +                 gfn_x(gfn), mfn_x(page ? page_to_mfn(page) :

> INVALID_MFN));

>          return;

>      }

>

> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c

> index e065f8bbdb..2070e78358 100644

> --- a/xen/arch/x86/hvm/vmx/vmx.c

> +++ b/xen/arch/x86/hvm/vmx/vmx.c

> @@ -674,7 +674,7 @@ static int vmx_restore_cr0_cr3(

>      {

>          if ( cr0 & X86_CR0_PG )

>          {

> -            page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT,

> +            page = get_page_from_gfn(v->domain, gaddr_to_gfn(cr3),

>                                       NULL, P2M_ALLOC);

>              if ( !page )

>              {

> @@ -1373,7 +1373,7 @@ static void vmx_load_pdptrs(struct vcpu *v)

>      if ( (cr3 & 0x1fUL) && !hvm_pcid_enabled(v) )

>          goto crash;

>

> -    page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, &p2mt,

> P2M_UNSHARE);

> +    page = get_page_from_gfn(v->domain, gaddr_to_gfn(cr3), &p2mt,

> P2M_UNSHARE);

>      if ( !page )

>      {

>          /* Ideally you don't want to crash but rather go into a wait

> diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c

> index dfd08e2d0a..2953d05a17 100644

> --- a/xen/arch/x86/hvm/vmx/vvmx.c

> +++ b/xen/arch/x86/hvm/vmx/vvmx.c

> @@ -649,11 +649,11 @@ static void nvmx_update_apic_access_address(struct

> vcpu *v)

>      if ( ctrl & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES )

>      {

>          p2m_type_t p2mt;

> -        unsigned long apic_gpfn;

> +        gfn_t apic_gfn;

>          struct page_info *apic_pg;

>

> -        apic_gpfn = get_vvmcs(v, APIC_ACCESS_ADDR) >> PAGE_SHIFT;

> -        apic_pg = get_page_from_gfn(v->domain, apic_gpfn, &p2mt,

> P2M_ALLOC);

> +        apic_gfn = gaddr_to_gfn(get_vvmcs(v, APIC_ACCESS_ADDR));

> +        apic_pg = get_page_from_gfn(v->domain, apic_gfn, &p2mt,

> P2M_ALLOC);

>          ASSERT(apic_pg && !p2m_is_paging(p2mt));

>          __vmwrite(APIC_ACCESS_ADDR, page_to_maddr(apic_pg));

>          put_page(apic_pg);

> @@ -670,11 +670,11 @@ static void nvmx_update_virtual_apic_address(struct

> vcpu *v)

>      if ( ctrl & CPU_BASED_TPR_SHADOW )

>      {

>          p2m_type_t p2mt;

> -        unsigned long vapic_gpfn;

> +        gfn_t vapic_gfn;

>          struct page_info *vapic_pg;

>

> -        vapic_gpfn = get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR) >> PAGE_SHIFT;

> -        vapic_pg = get_page_from_gfn(v->domain, vapic_gpfn, &p2mt,

> P2M_ALLOC);

> +        vapic_gfn = gaddr_to_gfn(get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR));

> +        vapic_pg = get_page_from_gfn(v->domain, vapic_gfn, &p2mt,

> P2M_ALLOC);

>          ASSERT(vapic_pg && !p2m_is_paging(p2mt));

>          __vmwrite(VIRTUAL_APIC_PAGE_ADDR, page_to_maddr(vapic_pg));

>          put_page(vapic_pg);

> diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c

> index 9363e9bd96..e3462f8a77 100644

> --- a/xen/arch/x86/mm.c

> +++ b/xen/arch/x86/mm.c

> @@ -2052,7 +2052,7 @@ static int mod_l1_entry(l1_pgentry_t *pl1e,

> l1_pgentry_t nl1e,

>              p2m_query_t q = l1e_get_flags(nl1e) & _PAGE_RW ?

>                              P2M_ALLOC | P2M_UNSHARE : P2M_ALLOC;

>

> -            page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), &p2mt, q);

> +            page = get_page_from_gfn(pg_dom, _gfn(l1e_get_pfn(nl1e)),

> &p2mt, q);

>

>              if ( p2m_is_paged(p2mt) )

>              {

> @@ -3223,7 +3223,8 @@ long do_mmuext_op(

>              if ( paging_mode_refcounts(pg_owner) )

>                  break;

>

> -            page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL,

> P2M_ALLOC);

> +            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL,

> +                                     P2M_ALLOC);

>              if ( unlikely(!page) )

>              {

>                  rc = -EINVAL;

> @@ -3288,7 +3289,8 @@ long do_mmuext_op(

>              if ( paging_mode_refcounts(pg_owner) )

>                  break;

>

> -            page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL,

> P2M_ALLOC);

> +            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL,

> +                                     P2M_ALLOC);

>              if ( unlikely(!page) )

>              {

>                  gdprintk(XENLOG_WARNING,

> @@ -3504,7 +3506,8 @@ long do_mmuext_op(

>          }

>

>          case MMUEXT_CLEAR_PAGE:

> -            page = get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt,

> P2M_ALLOC);

> +            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p2mt,

> +                                     P2M_ALLOC);

>              if ( unlikely(p2mt != p2m_ram_rw) && page )

>              {

>                  put_page(page);

> @@ -3532,7 +3535,7 @@ long do_mmuext_op(

>          {

>              struct page_info *src_page, *dst_page;

>

> -            src_page = get_page_from_gfn(pg_owner, op.arg2.src_mfn, &p2mt,

> +            src_page = get_page_from_gfn(pg_owner, _gfn(op.arg2.src_mfn),

> &p2mt,

>                                           P2M_ALLOC);

>              if ( unlikely(p2mt != p2m_ram_rw) && src_page )

>              {

> @@ -3548,7 +3551,7 @@ long do_mmuext_op(

>                  break;

>              }

>

> -            dst_page = get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt,

> +            dst_page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn),

> &p2mt,

>                                           P2M_ALLOC);

>              if ( unlikely(p2mt != p2m_ram_rw) && dst_page )

>              {

> @@ -3636,7 +3639,8 @@ long do_mmu_update(

>  {

>      struct mmu_update req;

>      void *va = NULL;

> -    unsigned long gpfn, gmfn, mfn;

> +    unsigned long gpfn, mfn;

> +    gfn_t gfn;

>      struct page_info *page;

>      unsigned int cmd, i = 0, done = 0, pt_dom;

>      struct vcpu *curr = current, *v = curr;

> @@ -3749,8 +3753,8 @@ long do_mmu_update(

>              rc = -EINVAL;

>

>              req.ptr -= cmd;

> -            gmfn = req.ptr >> PAGE_SHIFT;

> -            page = get_page_from_gfn(pt_owner, gmfn, &p2mt, P2M_ALLOC);

> +            gfn = gaddr_to_gfn(req.ptr);

> +            page = get_page_from_gfn(pt_owner, gfn, &p2mt, P2M_ALLOC);

>

>              if ( unlikely(!page) || p2mt != p2m_ram_rw )

>              {

> @@ -3758,7 +3762,7 @@ long do_mmu_update(

>                      put_page(page);

>                  if ( p2m_is_paged(p2mt) )

>                  {

> -                    p2m_mem_paging_populate(pt_owner, gmfn);

> +                    p2m_mem_paging_populate(pt_owner, gfn_x(gfn));

>                      rc = -ENOENT;

>                  }

>                  else

> diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c

> index a00a3c1bff..3b2aac8804 100644

> --- a/xen/arch/x86/mm/p2m.c

> +++ b/xen/arch/x86/mm/p2m.c

> @@ -2718,7 +2718,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned

> long fgfn,

>       * Take a refcnt on the mfn. NB: following supported for foreign

> mapping:

>       *     ram_rw | ram_logdirty | ram_ro | paging_out.

>       */

> -    page = get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC);

> +    page = get_page_from_gfn(fdom, _gfn(fgfn), &p2mt, P2M_ALLOC);

>      if ( !page ||

>           !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )

>      {

> diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c

> index 4cc75916b8..9275ba476c 100644

> --- a/xen/arch/x86/mm/shadow/hvm.c

> +++ b/xen/arch/x86/mm/shadow/hvm.c

> @@ -313,15 +313,15 @@ const struct x86_emulate_ops hvm_shadow_emulator_ops

> = {

>  static mfn_t emulate_gva_to_mfn(struct vcpu *v, unsigned long vaddr,

>                                  struct sh_emulate_ctxt *sh_ctxt)

>  {

> -    unsigned long gfn;

> +    gfn_t gfn;

>      struct page_info *page;

>      mfn_t mfn;

>      p2m_type_t p2mt;

>      uint32_t pfec = PFEC_page_present | PFEC_write_access;

>

>      /* Translate the VA to a GFN. */

> -    gfn = paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec);

> -    if ( gfn == gfn_x(INVALID_GFN) )

> +    gfn = _gfn(paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec));

> +    if ( gfn_eq(gfn, INVALID_GFN) )

>      {

>          x86_emul_pagefault(pfec, vaddr, &sh_ctxt->ctxt);

>

> diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c

> index 3a3c15890b..4f3f438614 100644

> --- a/xen/arch/x86/physdev.c

> +++ b/xen/arch/x86/physdev.c

> @@ -229,7 +229,8 @@ ret_t do_physdev_op(int cmd,

> XEN_GUEST_HANDLE_PARAM(void) arg)

>              break;

>

>          ret = -EINVAL;

> -        page = get_page_from_gfn(current->domain, info.gmfn, NULL,

> P2M_ALLOC);

> +        page = get_page_from_gfn(current->domain, _gfn(info.gmfn),

> +                                 NULL, P2M_ALLOC);

>          if ( !page )

>              break;

>          if ( !get_page_type(page, PGT_writable_page) )

> diff --git a/xen/arch/x86/pv/descriptor-tables.c

> b/xen/arch/x86/pv/descriptor-tables.c

> index 8b2d55fc2e..7e8f41d3fd 100644

> --- a/xen/arch/x86/pv/descriptor-tables.c

> +++ b/xen/arch/x86/pv/descriptor-tables.c

> @@ -112,7 +112,7 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames,

> unsigned int entries)

>      {

>          struct page_info *page;

>

> -        page = get_page_from_gfn(d, frames[i], NULL, P2M_ALLOC);

> +        page = get_page_from_gfn(d, _gfn(frames[i]), NULL, P2M_ALLOC);

>          if ( !page )

>              goto fail;

>          if ( !get_page_type(page, PGT_seg_desc_page) )

> @@ -209,7 +209,6 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint)

> frame_list,

>  long do_update_descriptor(uint64_t pa, uint64_t desc)

>  {

>      struct domain *currd = current->domain;

> -    unsigned long gmfn = pa >> PAGE_SHIFT;

>      unsigned long mfn;

>      unsigned int  offset;

>      struct desc_struct *gdt_pent, d;

> @@ -220,7 +219,7 @@ long do_update_descriptor(uint64_t pa, uint64_t desc)

>

>      *(uint64_t *)&d = desc;

>

> -    page = get_page_from_gfn(currd, gmfn, NULL, P2M_ALLOC);

> +    page = get_page_from_gfn(currd, gaddr_to_gfn(pa), NULL, P2M_ALLOC);

>      if ( (((unsigned int)pa % sizeof(struct desc_struct)) != 0) ||

>           !page ||

>           !check_descriptor(currd, &d) )

> diff --git a/xen/arch/x86/pv/emul-priv-op.c

> b/xen/arch/x86/pv/emul-priv-op.c

> index f73ea4a163..a529ebcc3f 100644

> --- a/xen/arch/x86/pv/emul-priv-op.c

> +++ b/xen/arch/x86/pv/emul-priv-op.c

> @@ -760,12 +760,12 @@ static int write_cr(unsigned int reg, unsigned long

> val,

>      case 3: /* Write CR3 */

>      {

>          struct domain *currd = curr->domain;

> -        unsigned long gfn;

> +        gfn_t gfn;

>          struct page_info *page;

>          int rc;

>

> -        gfn = !is_pv_32bit_domain(currd)

> -              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val);

> +        gfn = _gfn(!is_pv_32bit_domain(currd)

> +              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val));

>          page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);

>          if ( !page )

>              break;

> diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c

> index f5ea00ca4e..c9ad1152b4 100644

> --- a/xen/arch/x86/pv/mm.c

> +++ b/xen/arch/x86/pv/mm.c

> @@ -106,7 +106,7 @@ bool pv_map_ldt_shadow_page(unsigned int offset)

>      if ( unlikely(!(l1e_get_flags(gl1e) & _PAGE_PRESENT)) )

>          return false;

>

> -    page = get_page_from_gfn(currd, l1e_get_pfn(gl1e), NULL, P2M_ALLOC);

> +    page = get_page_from_gfn(currd, _gfn(l1e_get_pfn(gl1e)), NULL,

> P2M_ALLOC);

>      if ( unlikely(!page) )

>          return false;

>

> diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c

> index 9471d89022..d967e49432 100644

> --- a/xen/arch/x86/traps.c

> +++ b/xen/arch/x86/traps.c

> @@ -795,7 +795,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx,

> uint64_t val)

>      case 0: /* Write hypercall page */

>      {

>          void *hypercall_page;

> -        unsigned long gmfn = val >> PAGE_SHIFT;

> +        gfn_t gfn = gaddr_to_gfn(val);

>          unsigned int page_index = val & (PAGE_SIZE - 1);

>          struct page_info *page;

>          p2m_type_t t;

> @@ -808,7 +808,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx,

> uint64_t val)

>              return X86EMUL_EXCEPTION;

>          }

>

> -        page = get_page_from_gfn(d, gmfn, &t, P2M_ALLOC);

> +        page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC);

>

>          if ( !page || !get_page_type(page, PGT_writable_page) )

>          {

> @@ -817,13 +817,14 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx,

> uint64_t val)

>

>              if ( p2m_is_paging(t) )

>              {

> -                p2m_mem_paging_populate(d, gmfn);

> +                p2m_mem_paging_populate(d, gfn_x(gfn));

>                  return X86EMUL_RETRY;

>              }

>

>              gdprintk(XENLOG_WARNING,

> -                     "Bad GMFN %lx (MFN %#"PRI_mfn") to MSR %08x\n",

> -                     gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN),

> base);

> +                     "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn") to MSR

> %08x\n",

> +                     gfn_x(gfn), mfn_x(page ? page_to_mfn(page) :

> INVALID_MFN),

> +                     base);

>              return X86EMUL_EXCEPTION;

>          }

>

> diff --git a/xen/common/domain.c b/xen/common/domain.c

> index d6650f0656..5e3c05b96c 100644

> --- a/xen/common/domain.c

> +++ b/xen/common/domain.c

> @@ -1250,7 +1250,7 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn,

> unsigned offset)

>      if ( (v != current) && !(v->pause_flags & VPF_down) )

>          return -EINVAL;

>

> -    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);

> +    page = get_page_from_gfn(d, _gfn(gfn), NULL, P2M_ALLOC);

>      if ( !page )

>          return -EINVAL;

>

> diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c

> index c49f446754..71a6f673b2 100644

> --- a/xen/common/event_fifo.c

> +++ b/xen/common/event_fifo.c

> @@ -358,7 +358,7 @@ static const struct evtchn_port_ops

> evtchn_port_ops_fifo =

>      .print_state   = evtchn_fifo_print_state,

>  };

>

> -static int map_guest_page(struct domain *d, uint64_t gfn, void **virt)

> +static int map_guest_page(struct domain *d, gfn_t gfn, void **virt)

>  {

>      struct page_info *p;

>

> @@ -419,7 +419,7 @@ static int setup_control_block(struct vcpu *v)

>      return 0;

>  }

>

> -static int map_control_block(struct vcpu *v, uint64_t gfn, uint32_t

> offset)

> +static int map_control_block(struct vcpu *v, gfn_t gfn, uint32_t offset)

>  {

>      void *virt;

>      unsigned int i;

> @@ -505,7 +505,7 @@ int evtchn_fifo_init_control(struct

> evtchn_init_control *init_control)

>  {

>      struct domain *d = current->domain;

>      uint32_t vcpu_id;

> -    uint64_t gfn;

> +    gfn_t gfn;

>      uint32_t offset;

>      struct vcpu *v;

>      int rc;

> @@ -513,7 +513,7 @@ int evtchn_fifo_init_control(struct

> evtchn_init_control *init_control)

>      init_control->link_bits = EVTCHN_FIFO_LINK_BITS;

>

>      vcpu_id = init_control->vcpu;

> -    gfn     = init_control->control_gfn;

> +    gfn     = _gfn(init_control->control_gfn);

>      offset  = init_control->offset;

>

>      if ( vcpu_id >= d->max_vcpus || !d->vcpu[vcpu_id] )

> @@ -569,7 +569,7 @@ int evtchn_fifo_init_control(struct

> evtchn_init_control *init_control)

>      return rc;

>  }

>

> -static int add_page_to_event_array(struct domain *d, unsigned long gfn)

> +static int add_page_to_event_array(struct domain *d, gfn_t gfn)

>  {

>      void *virt;

>      unsigned int slot;

> @@ -619,7 +619,7 @@ int evtchn_fifo_expand_array(const struct

> evtchn_expand_array *expand_array)

>          return -EOPNOTSUPP;

>

>      spin_lock(&d->event_lock);

> -    rc = add_page_to_event_array(d, expand_array->array_gfn);

> +    rc = add_page_to_event_array(d, _gfn(expand_array->array_gfn));

>      spin_unlock(&d->event_lock);

>

>      return rc;

> diff --git a/xen/common/memory.c b/xen/common/memory.c

> index 987395fbb3..e02733dba0 100644

> --- a/xen/common/memory.c

> +++ b/xen/common/memory.c

> @@ -1365,7 +1365,7 @@ long do_memory_op(unsigned long cmd,

> XEN_GUEST_HANDLE_PARAM(void) arg)

>              return rc;

>          }

>

> -        page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC);

> +        page = get_page_from_gfn(d, _gfn(xrfp.gpfn), NULL, P2M_ALLOC);

>          if ( page )

>          {

>              rc = guest_physmap_remove_page(d, _gfn(xrfp.gpfn),

> @@ -1636,7 +1636,7 @@ int check_get_page_from_gfn(struct domain *d, gfn_t

> gfn, bool readonly,

>      p2m_type_t p2mt;

>      struct page_info *page;

>

> -    page = get_page_from_gfn(d, gfn_x(gfn), &p2mt, q);

> +    page = get_page_from_gfn(d, gfn, &p2mt, q);

>

>  #ifdef CONFIG_HAS_MEM_PAGING

>      if ( p2m_is_paging(p2mt) )

> diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c

> index bf7b14f79a..72cba7f10c 100644

> --- a/xen/common/tmem_xen.c

> +++ b/xen/common/tmem_xen.c

> @@ -52,7 +52,7 @@ static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t

> *pcli_mfn,

>      p2m_type_t t;

>      struct page_info *page;

>

> -    page = get_page_from_gfn(current->domain, cmfn, &t, P2M_ALLOC);

> +    page = get_page_from_gfn(current->domain, _gfn(cmfn), &t, P2M_ALLOC);

>      if ( !page || t != p2m_ram_rw )

>      {

>          if ( page )

> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h

> index 7c67806056..5e598a0b37 100644

> --- a/xen/include/asm-arm/p2m.h

> +++ b/xen/include/asm-arm/p2m.h

> @@ -278,7 +278,7 @@ struct page_info *p2m_get_page_from_gfn(struct domain

> *d, gfn_t gfn,

>                                          p2m_type_t *t);

>

>  static inline struct page_info *get_page_from_gfn(

> -    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)

> +    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)

>  {

>      mfn_t mfn;

>      p2m_type_t _t;

> @@ -289,7 +289,7 @@ static inline struct page_info *get_page_from_gfn(

>       * not auto-translated.

>       */

>      if ( unlikely(d != dom_xen) )

> -        return p2m_get_page_from_gfn(d, _gfn(gfn), t);

> +        return p2m_get_page_from_gfn(d, gfn, t);

>

>      if ( !t )

>          t = &_t;

> @@ -300,7 +300,7 @@ static inline struct page_info *get_page_from_gfn(

>       * DOMID_XEN see 1-1 RAM. The p2m_type is based on the type of the

>       * page.

>       */

> -    mfn = _mfn(gfn);

> +    mfn = _mfn(gfn_x(gfn));

>      page = mfn_to_page(mfn);

>

>      if ( !mfn_valid(mfn) || !get_page(page, d) )

> diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h

> index d08c595887..db1ec37610 100644

> --- a/xen/include/asm-x86/p2m.h

> +++ b/xen/include/asm-x86/p2m.h

> @@ -489,18 +489,21 @@ struct page_info *p2m_get_page_from_gfn(struct

> p2m_domain *p2m, gfn_t gfn,

>                                          p2m_query_t q);

>

>  static inline struct page_info *get_page_from_gfn(

> -    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)

> +    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)

>  {

>      struct page_info *page;

> +    mfn_t mfn;

>

>      if ( paging_mode_translate(d) )

> -        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t,

> NULL, q);

> +        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL, q);

>

>      /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */

>      if ( t )

>          *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct;

> -    page = mfn_to_page(_mfn(gfn));

> -    return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL;

> +

> +    mfn = _mfn(gfn_x(gfn));

> +    page = mfn_to_page(mfn);

> +    return mfn_valid(mfn) && get_page(page, d) ? page : NULL;

>  }

>

>  /* General conversion function from mfn to gfn */

> --

> 2.11.0

>

>

> _______________________________________________

> Xen-devel mailing list

> Xen-devel@lists.xenproject.org

> https://lists.xenproject.org/mailman/listinfo/xen-devel
<div dir="ltr">Hello Julien,<div><br></div><div>I&#39;m just wondering if this patch really belongs to xentrace series.</div><div>It rather looks like a separate cleanup patch.</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Sincerely,<div>Andrii Anisov.</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">вт, 6 лист. 2018 о 21:16 Julien Grall &lt;<a href="mailto:julien.grall@arm.com">julien.grall@arm.com</a>&gt; пише:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">No functional change intended.<br>
<br>
Only reasonable clean-ups are done in this patch. The rest will use _gfn<br>
for the time being.<br>
<br>
Signed-off-by: Julien Grall &lt;<a href="mailto:julie.grall@arm.com" target="_blank">julie.grall@arm.com</a>&gt;<br>

---<br>
 xen/arch/arm/guestcopy.c             |  2 +-<br>
 xen/arch/arm/mm.c                    |  2 +-<br>
 xen/arch/x86/cpu/vpmu.c              |  2 +-<br>
 xen/arch/x86/domain.c                | 12 ++++++------<br>
 xen/arch/x86/domctl.c                |  6 +++---<br>
 xen/arch/x86/hvm/dm.c                |  2 +-<br>
 xen/arch/x86/hvm/domain.c            |  2 +-<br>
 xen/arch/x86/hvm/hvm.c               |  9 +++++----<br>
 xen/arch/x86/hvm/svm/svm.c           |  8 ++++----<br>
 xen/arch/x86/hvm/viridian/viridian.c | 24 ++++++++++++------------<br>
 xen/arch/x86/hvm/vmx/vmx.c           |  4 ++--<br>
 xen/arch/x86/hvm/vmx/vvmx.c          | 12 ++++++------<br>
 xen/arch/x86/mm.c                    | 24 ++++++++++++++----------<br>
 xen/arch/x86/mm/p2m.c                |  2 +-<br>
 xen/arch/x86/mm/shadow/hvm.c         |  6 +++---<br>
 xen/arch/x86/physdev.c               |  3 ++-<br>
 xen/arch/x86/pv/descriptor-tables.c  |  5 ++---<br>
 xen/arch/x86/pv/emul-priv-op.c       |  6 +++---<br>
 xen/arch/x86/pv/mm.c                 |  2 +-<br>
 xen/arch/x86/traps.c                 | 11 ++++++-----<br>
 xen/common/domain.c                  |  2 +-<br>
 xen/common/event_fifo.c              | 12 ++++++------<br>
 xen/common/memory.c                  |  4 ++--<br>
 xen/common/tmem_xen.c                |  2 +-<br>
 xen/include/asm-arm/p2m.h            |  6 +++---<br>
 xen/include/asm-x86/p2m.h            | 11 +++++++----<br>
 26 files changed, 95 insertions(+), 86 deletions(-)<br>
<br>
diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c<br>
index 7a0f3e9d5f..55892062bb 100644<br>
--- a/xen/arch/arm/guestcopy.c<br>
+++ b/xen/arch/arm/guestcopy.c<br>
@@ -37,7 +37,7 @@ static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,<br>
         return get_page_from_gva(info.gva.v, addr,<br>
                                  write ? GV2M_WRITE : GV2M_READ);<br>
<br>
-    page = get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &amp;p2mt, P2M_ALLOC);<br>
+    page = get_page_from_gfn(info.gpa.d, gaddr_to_gfn(addr), &amp;p2mt, P2M_ALLOC);<br>
<br>
     if ( !page )<br>
         return NULL;<br>
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c<br>
index 72d0285768..88711096ef 100644<br>
--- a/xen/arch/arm/mm.c<br>
+++ b/xen/arch/arm/mm.c<br>
@@ -1268,7 +1268,7 @@ int xenmem_add_to_physmap_one(<br>
<br>
         /* Take reference to the foreign domain page.<br>
          * Reference will be released in XENMEM_remove_from_physmap */<br>
-        page = get_page_from_gfn(od, idx, &amp;p2mt, P2M_ALLOC);<br>
+        page = get_page_from_gfn(od, _gfn(idx), &amp;p2mt, P2M_ALLOC);<br>
         if ( !page )<br>
         {<br>
             put_pg_owner(od);<br>
diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c<br>
index 8a4f753eae..4d8f153031 100644<br>
--- a/xen/arch/x86/cpu/vpmu.c<br>
+++ b/xen/arch/x86/cpu/vpmu.c<br>
@@ -607,7 +607,7 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)<br>
     struct vcpu *v;<br>
     struct vpmu_struct *vpmu;<br>
     struct page_info *page;<br>
-    uint64_t gfn = params-&gt;val;<br>
+    gfn_t gfn = _gfn(params-&gt;val);<br>
<br>
     if ( (params-&gt;vcpu &gt;= d-&gt;max_vcpus) || (d-&gt;vcpu[params-&gt;vcpu] == NULL) )<br>
         return -EINVAL;<br>
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c<br>
index f6fe954313..c5cce4b38d 100644<br>
--- a/xen/arch/x86/domain.c<br>
+++ b/xen/arch/x86/domain.c<br>
@@ -797,7 +797,7 @@ int arch_set_info_guest(<br>
     unsigned long flags;<br>
     bool compat;<br>
 #ifdef CONFIG_PV<br>
-    unsigned long cr3_gfn;<br>
+    gfn_t cr3_gfn;<br>
     struct page_info *cr3_page;<br>
     unsigned long cr4;<br>
     int rc = 0;<br>
@@ -1061,9 +1061,9 @@ int arch_set_info_guest(<br>
     set_bit(_VPF_in_reset, &amp;v-&gt;pause_flags);<br>
<br>
     if ( !compat )<br>
-        cr3_gfn = xen_cr3_to_pfn(c.nat-&gt;ctrlreg[3]);<br>
+        cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat-&gt;ctrlreg[3]));<br>
     else<br>
-        cr3_gfn = compat_cr3_to_pfn(c.cmp-&gt;ctrlreg[3]);<br>
+        cr3_gfn = _gfn(compat_cr3_to_pfn(c.cmp-&gt;ctrlreg[3]));<br>
     cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC);<br>
<br>
     if ( !cr3_page )<br>
@@ -1092,7 +1092,7 @@ int arch_set_info_guest(<br>
         case 0:<br>
             if ( !compat &amp;&amp; !VM_ASSIST(d, m2p_strict) &amp;&amp;<br>
                  !paging_mode_refcounts(d) )<br>
-                fill_ro_mpt(_mfn(cr3_gfn));<br>
+                fill_ro_mpt(_mfn(gfn_x(cr3_gfn)));<br>
             break;<br>
         default:<br>
             if ( cr3_page == current-&gt;arch.old_guest_table )<br>
@@ -1107,7 +1107,7 @@ int arch_set_info_guest(<br>
         v-&gt;arch.guest_table = pagetable_from_page(cr3_page);<br>
         if ( c.nat-&gt;ctrlreg[1] )<br>
         {<br>
-            cr3_gfn = xen_cr3_to_pfn(c.nat-&gt;ctrlreg[1]);<br>
+            cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat-&gt;ctrlreg[1]));<br>
             cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC);<br>
<br>
             if ( !cr3_page )<br>
@@ -1132,7 +1132,7 @@ int arch_set_info_guest(<br>
                     break;<br>
                 case 0:<br>
                     if ( VM_ASSIST(d, m2p_strict) )<br>
-                        zap_ro_mpt(_mfn(cr3_gfn));<br>
+                        zap_ro_mpt(_mfn(gfn_x(cr3_gfn)));<br>
                     break;<br>
                 }<br>
             }<br>
diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c<br>
index 33f9a869c0..6b0d8075cd 100644<br>
--- a/xen/arch/x86/domctl.c<br>
+++ b/xen/arch/x86/domctl.c<br>
@@ -448,7 +448,7 @@ long arch_do_domctl(<br>
                 break;<br>
             }<br>
<br>
-            page = get_page_from_gfn(d, gfn, &amp;t, P2M_ALLOC);<br>
+            page = get_page_from_gfn(d, _gfn(gfn), &amp;t, P2M_ALLOC);<br>
<br>
             if ( unlikely(!page) ||<br>
                  unlikely(is_xen_heap_page(page)) )<br>
@@ -498,11 +498,11 @@ long arch_do_domctl(<br>
<br>
     case XEN_DOMCTL_hypercall_init:<br>
     {<br>
-        unsigned long gmfn = domctl-&gt;u.hypercall_init.gmfn;<br>
+        gfn_t gfn = _gfn(domctl-&gt;u.hypercall_init.gmfn);<br>
         struct page_info *page;<br>
         void *hypercall_page;<br>
<br>
-        page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);<br>
+        page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);<br>
<br>
         if ( !page || !get_page_type(page, PGT_writable_page) )<br>
         {<br>
diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c<br>
index d6d0e8be89..3b3ad27938 100644<br>
--- a/xen/arch/x86/hvm/dm.c<br>
+++ b/xen/arch/x86/hvm/dm.c<br>
@@ -186,7 +186,7 @@ static int modified_memory(struct domain *d,<br>
         {<br>
             struct page_info *page;<br>
<br>
-            page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE);<br>
+            page = get_page_from_gfn(d, _gfn(pfn), NULL, P2M_UNSHARE);<br>
             if ( page )<br>
             {<br>
                 paging_mark_pfn_dirty(d, _pfn(pfn));<br>
diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c<br>
index 5d5a746a25..73d2da8441 100644<br>
--- a/xen/arch/x86/hvm/domain.c<br>
+++ b/xen/arch/x86/hvm/domain.c<br>
@@ -297,7 +297,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx)<br>
     {<br>
         /* Shadow-mode CR3 change. Check PDBR and update refcounts. */<br>
         struct page_info *page = get_page_from_gfn(v-&gt;domain,<br>
-                                 v-&gt;arch.hvm.guest_cr[3] &gt;&gt; PAGE_SHIFT,<br>
+                                 gaddr_to_gfn(v-&gt;arch.hvm.guest_cr[3]),<br>
                                  NULL, P2M_ALLOC);<br>
         if ( !page )<br>
         {<br>
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c<br>
index 7be9cf4454..be262e5a1d 100644<br>
--- a/xen/arch/x86/hvm/hvm.c<br>
+++ b/xen/arch/x86/hvm/hvm.c<br>
@@ -2146,7 +2146,7 @@ int hvm_set_cr0(unsigned long value, bool may_defer)<br>
 {<br>
     struct vcpu *v = current;<br>
     struct domain *d = v-&gt;domain;<br>
-    unsigned long gfn, old_value = v-&gt;arch.hvm.guest_cr[0];<br>
+    unsigned long old_value = v-&gt;arch.hvm.guest_cr[0];<br>
     struct page_info *page;<br>
<br>
     HVM_DBG_LOG(DBG_LEVEL_VMMU, &quot;Update CR0 value = %lx&quot;, value);<br>
@@ -2201,7 +2201,8 @@ int hvm_set_cr0(unsigned long value, bool may_defer)<br>
         if ( !paging_mode_hap(d) )<br>
         {<br>
             /* The guest CR3 must be pointing to the guest physical. */<br>
-            gfn = v-&gt;arch.hvm.guest_cr[3] &gt;&gt; PAGE_SHIFT;<br>
+            gfn_t gfn = gaddr_to_gfn(v-&gt;arch.hvm.guest_cr[3]);<br>
+<br>
             page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);<br>
             if ( !page )<br>
             {<br>
@@ -2293,7 +2294,7 @@ int hvm_set_cr3(unsigned long value, bool may_defer)<br>
     {<br>
         /* Shadow-mode CR3 change. Check PDBR and update refcounts. */<br>
         HVM_DBG_LOG(DBG_LEVEL_VMMU, &quot;CR3 value = %lx&quot;, value);<br>
-        page = get_page_from_gfn(v-&gt;domain, value &gt;&gt; PAGE_SHIFT,<br>
+        page = get_page_from_gfn(v-&gt;domain, gaddr_to_gfn(value),<br>
                                  NULL, P2M_ALLOC);<br>
         if ( !page )<br>
             goto bad_cr3;<br>
@@ -3120,7 +3121,7 @@ enum hvm_translation_result hvm_translate_get_page(<br>
          &amp;&amp; hvm_mmio_internal(gfn_to_gaddr(gfn)) )<br>
         return HVMTRANS_bad_gfn_to_mfn;<br>
<br>
-    page = get_page_from_gfn(v-&gt;domain, gfn_x(gfn), &amp;p2mt, P2M_UNSHARE);<br>
+    page = get_page_from_gfn(v-&gt;domain, gfn, &amp;p2mt, P2M_UNSHARE);<br>
<br>
     if ( !page )<br>
         return HVMTRANS_bad_gfn_to_mfn;<br>
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c<br>
index 5d00256aaa..a7419bd444 100644<br>
--- a/xen/arch/x86/hvm/svm/svm.c<br>
+++ b/xen/arch/x86/hvm/svm/svm.c<br>
@@ -317,7 +317,7 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)<br>
     {<br>
         if ( c-&gt;cr0 &amp; X86_CR0_PG )<br>
         {<br>
-            page = get_page_from_gfn(v-&gt;domain, c-&gt;cr3 &gt;&gt; PAGE_SHIFT,<br>
+            page = get_page_from_gfn(v-&gt;domain, gaddr_to_gfn(c-&gt;cr3),<br>
                                      NULL, P2M_ALLOC);<br>
             if ( !page )<br>
             {<br>
@@ -2412,9 +2412,9 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t vmcbaddr)<br>
         return NULL;<br>
<br>
     /* Need to translate L1-GPA to MPA */<br>
-    page = get_page_from_gfn(v-&gt;domain, <br>
-                            nv-&gt;nv_vvmcxaddr &gt;&gt; PAGE_SHIFT, <br>
-                            &amp;p2mt, P2M_ALLOC | P2M_UNSHARE);<br>
+    page = get_page_from_gfn(v-&gt;domain,<br>
+                             gaddr_to_gfn(nv-&gt;nv_vvmcxaddr &gt;&gt; PAGE_SHIFT),<br>
+                             &amp;p2mt, P2M_ALLOC | P2M_UNSHARE);<br>
     if ( !page )<br>
         return NULL;<br>
<br>
diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c<br>
index 2dc86dd0f3..1d3be156db 100644<br>
--- a/xen/arch/x86/hvm/viridian/viridian.c<br>
+++ b/xen/arch/x86/hvm/viridian/viridian.c<br>
@@ -332,16 +332,16 @@ static void dump_reference_tsc(const struct domain *d)<br>
<br>
 static void enable_hypercall_page(struct domain *d)<br>
 {<br>
-    unsigned long gmfn = d-&gt;arch.hvm.viridian.hypercall_gpa.fields.pfn;<br>
-    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);<br>
+    gfn_t gfn = _gfn(d-&gt;arch.hvm.viridian.hypercall_gpa.fields.pfn);<br>
+    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);<br>
     uint8_t *p;<br>
<br>
     if ( !page || !get_page_type(page, PGT_writable_page) )<br>
     {<br>
         if ( page )<br>
             put_page(page);<br>
-        gdprintk(XENLOG_WARNING, &quot;Bad GMFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;)\n&quot;,<br>
-                 gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));<br>
+        gdprintk(XENLOG_WARNING, &quot;Bad GFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;)\n&quot;,<br>
+                 gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));<br>
         return;<br>
     }<br>
<br>
@@ -367,8 +367,8 @@ static void enable_hypercall_page(struct domain *d)<br>
 static void initialize_vp_assist(struct vcpu *v)<br>
 {<br>
     struct domain *d = v-&gt;domain;<br>
-    unsigned long gmfn = v-&gt;arch.hvm.viridian.vp_assist.msr.fields.pfn;<br>
-    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);<br>
+    gfn_t gfn = _gfn(v-&gt;arch.hvm.viridian.vp_assist.msr.fields.pfn);<br>
+    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);<br>
     void *va;<br>
<br>
     ASSERT(!v-&gt;<a href="http://arch.hvm.viridian.vp_assist.va" rel="noreferrer" target="_blank">arch.hvm.viridian.vp_assist.va</a>);<br>
@@ -395,8 +395,8 @@ static void initialize_vp_assist(struct vcpu *v)<br>
     return;<br>
<br>
  fail:<br>
-    gdprintk(XENLOG_WARNING, &quot;Bad GMFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;)\n&quot;,<br>
-             gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));<br>
+    gdprintk(XENLOG_WARNING, &quot;Bad GFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;)\n&quot;,<br>
+             gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));<br>
 }<br>
<br>
 static void teardown_vp_assist(struct vcpu *v)<br>
@@ -465,16 +465,16 @@ void viridian_apic_assist_clear(struct vcpu *v)<br>
<br>
 static void update_reference_tsc(struct domain *d, bool_t initialize)<br>
 {<br>
-    unsigned long gmfn = d-&gt;arch.hvm.viridian.reference_tsc.fields.pfn;<br>
-    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);<br>
+    gfn_t gfn = _gfn(d-&gt;arch.hvm.viridian.reference_tsc.fields.pfn);<br>
+    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);<br>
     HV_REFERENCE_TSC_PAGE *p;<br>
<br>
     if ( !page || !get_page_type(page, PGT_writable_page) )<br>
     {<br>
         if ( page )<br>
             put_page(page);<br>
-        gdprintk(XENLOG_WARNING, &quot;Bad GMFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;)\n&quot;,<br>
-                 gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));<br>
+        gdprintk(XENLOG_WARNING, &quot;Bad GFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;)\n&quot;,<br>
+                 gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));<br>
         return;<br>
     }<br>
<br>
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c<br>
index e065f8bbdb..2070e78358 100644<br>
--- a/xen/arch/x86/hvm/vmx/vmx.c<br>
+++ b/xen/arch/x86/hvm/vmx/vmx.c<br>
@@ -674,7 +674,7 @@ static int vmx_restore_cr0_cr3(<br>
     {<br>
         if ( cr0 &amp; X86_CR0_PG )<br>
         {<br>
-            page = get_page_from_gfn(v-&gt;domain, cr3 &gt;&gt; PAGE_SHIFT,<br>
+            page = get_page_from_gfn(v-&gt;domain, gaddr_to_gfn(cr3),<br>
                                      NULL, P2M_ALLOC);<br>
             if ( !page )<br>
             {<br>
@@ -1373,7 +1373,7 @@ static void vmx_load_pdptrs(struct vcpu *v)<br>
     if ( (cr3 &amp; 0x1fUL) &amp;&amp; !hvm_pcid_enabled(v) )<br>
         goto crash;<br>
<br>
-    page = get_page_from_gfn(v-&gt;domain, cr3 &gt;&gt; PAGE_SHIFT, &amp;p2mt, P2M_UNSHARE);<br>
+    page = get_page_from_gfn(v-&gt;domain, gaddr_to_gfn(cr3), &amp;p2mt, P2M_UNSHARE);<br>
     if ( !page )<br>
     {<br>
         /* Ideally you don&#39;t want to crash but rather go into a wait <br>
diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c<br>
index dfd08e2d0a..2953d05a17 100644<br>
--- a/xen/arch/x86/hvm/vmx/vvmx.c<br>
+++ b/xen/arch/x86/hvm/vmx/vvmx.c<br>
@@ -649,11 +649,11 @@ static void nvmx_update_apic_access_address(struct vcpu *v)<br>
     if ( ctrl &amp; SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES )<br>
     {<br>
         p2m_type_t p2mt;<br>
-        unsigned long apic_gpfn;<br>
+        gfn_t apic_gfn;<br>
         struct page_info *apic_pg;<br>
<br>
-        apic_gpfn = get_vvmcs(v, APIC_ACCESS_ADDR) &gt;&gt; PAGE_SHIFT;<br>
-        apic_pg = get_page_from_gfn(v-&gt;domain, apic_gpfn, &amp;p2mt, P2M_ALLOC);<br>
+        apic_gfn = gaddr_to_gfn(get_vvmcs(v, APIC_ACCESS_ADDR));<br>
+        apic_pg = get_page_from_gfn(v-&gt;domain, apic_gfn, &amp;p2mt, P2M_ALLOC);<br>
         ASSERT(apic_pg &amp;&amp; !p2m_is_paging(p2mt));<br>
         __vmwrite(APIC_ACCESS_ADDR, page_to_maddr(apic_pg));<br>
         put_page(apic_pg);<br>
@@ -670,11 +670,11 @@ static void nvmx_update_virtual_apic_address(struct vcpu *v)<br>
     if ( ctrl &amp; CPU_BASED_TPR_SHADOW )<br>
     {<br>
         p2m_type_t p2mt;<br>
-        unsigned long vapic_gpfn;<br>
+        gfn_t vapic_gfn;<br>
         struct page_info *vapic_pg;<br>
<br>
-        vapic_gpfn = get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR) &gt;&gt; PAGE_SHIFT;<br>
-        vapic_pg = get_page_from_gfn(v-&gt;domain, vapic_gpfn, &amp;p2mt, P2M_ALLOC);<br>
+        vapic_gfn = gaddr_to_gfn(get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR));<br>
+        vapic_pg = get_page_from_gfn(v-&gt;domain, vapic_gfn, &amp;p2mt, P2M_ALLOC);<br>
         ASSERT(vapic_pg &amp;&amp; !p2m_is_paging(p2mt));<br>
         __vmwrite(VIRTUAL_APIC_PAGE_ADDR, page_to_maddr(vapic_pg));<br>
         put_page(vapic_pg);<br>
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c<br>
index 9363e9bd96..e3462f8a77 100644<br>
--- a/xen/arch/x86/mm.c<br>
+++ b/xen/arch/x86/mm.c<br>
@@ -2052,7 +2052,7 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,<br>
             p2m_query_t q = l1e_get_flags(nl1e) &amp; _PAGE_RW ?<br>
                             P2M_ALLOC | P2M_UNSHARE : P2M_ALLOC;<br>
<br>
-            page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), &amp;p2mt, q);<br>
+            page = get_page_from_gfn(pg_dom, _gfn(l1e_get_pfn(nl1e)), &amp;p2mt, q);<br>
<br>
             if ( p2m_is_paged(p2mt) )<br>
             {<br>
@@ -3223,7 +3223,8 @@ long do_mmuext_op(<br>
             if ( paging_mode_refcounts(pg_owner) )<br>
                 break;<br>
<br>
-            page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC);<br>
+            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL,<br>
+                                     P2M_ALLOC);<br>
             if ( unlikely(!page) )<br>
             {<br>
                 rc = -EINVAL;<br>
@@ -3288,7 +3289,8 @@ long do_mmuext_op(<br>
             if ( paging_mode_refcounts(pg_owner) )<br>
                 break;<br>
<br>
-            page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC);<br>
+            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL,<br>
+                                     P2M_ALLOC);<br>
             if ( unlikely(!page) )<br>
             {<br>
                 gdprintk(XENLOG_WARNING,<br>
@@ -3504,7 +3506,8 @@ long do_mmuext_op(<br>
         }<br>
<br>
         case MMUEXT_CLEAR_PAGE:<br>
-            page = get_page_from_gfn(pg_owner, op.arg1.mfn, &amp;p2mt, P2M_ALLOC);<br>
+            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &amp;p2mt,<br>
+                                     P2M_ALLOC);<br>
             if ( unlikely(p2mt != p2m_ram_rw) &amp;&amp; page )<br>
             {<br>
                 put_page(page);<br>
@@ -3532,7 +3535,7 @@ long do_mmuext_op(<br>
         {<br>
             struct page_info *src_page, *dst_page;<br>
<br>
-            src_page = get_page_from_gfn(pg_owner, op.arg2.src_mfn, &amp;p2mt,<br>
+            src_page = get_page_from_gfn(pg_owner, _gfn(op.arg2.src_mfn), &amp;p2mt,<br>
                                          P2M_ALLOC);<br>
             if ( unlikely(p2mt != p2m_ram_rw) &amp;&amp; src_page )<br>
             {<br>
@@ -3548,7 +3551,7 @@ long do_mmuext_op(<br>
                 break;<br>
             }<br>
<br>
-            dst_page = get_page_from_gfn(pg_owner, op.arg1.mfn, &amp;p2mt,<br>
+            dst_page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &amp;p2mt,<br>
                                          P2M_ALLOC);<br>
             if ( unlikely(p2mt != p2m_ram_rw) &amp;&amp; dst_page )<br>
             {<br>
@@ -3636,7 +3639,8 @@ long do_mmu_update(<br>
 {<br>
     struct mmu_update req;<br>
     void *va = NULL;<br>
-    unsigned long gpfn, gmfn, mfn;<br>
+    unsigned long gpfn, mfn;<br>
+    gfn_t gfn;<br>
     struct page_info *page;<br>
     unsigned int cmd, i = 0, done = 0, pt_dom;<br>
     struct vcpu *curr = current, *v = curr;<br>
@@ -3749,8 +3753,8 @@ long do_mmu_update(<br>
             rc = -EINVAL;<br>
<br>
             req.ptr -= cmd;<br>
-            gmfn = req.ptr &gt;&gt; PAGE_SHIFT;<br>
-            page = get_page_from_gfn(pt_owner, gmfn, &amp;p2mt, P2M_ALLOC);<br>
+            gfn = gaddr_to_gfn(req.ptr);<br>
+            page = get_page_from_gfn(pt_owner, gfn, &amp;p2mt, P2M_ALLOC);<br>
<br>
             if ( unlikely(!page) || p2mt != p2m_ram_rw )<br>
             {<br>
@@ -3758,7 +3762,7 @@ long do_mmu_update(<br>
                     put_page(page);<br>
                 if ( p2m_is_paged(p2mt) )<br>
                 {<br>
-                    p2m_mem_paging_populate(pt_owner, gmfn);<br>
+                    p2m_mem_paging_populate(pt_owner, gfn_x(gfn));<br>
                     rc = -ENOENT;<br>
                 }<br>
                 else<br>
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c<br>
index a00a3c1bff..3b2aac8804 100644<br>
--- a/xen/arch/x86/mm/p2m.c<br>
+++ b/xen/arch/x86/mm/p2m.c<br>
@@ -2718,7 +2718,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,<br>
      * Take a refcnt on the mfn. NB: following supported for foreign mapping:<br>
      *     ram_rw | ram_logdirty | ram_ro | paging_out.<br>
      */<br>
-    page = get_page_from_gfn(fdom, fgfn, &amp;p2mt, P2M_ALLOC);<br>
+    page = get_page_from_gfn(fdom, _gfn(fgfn), &amp;p2mt, P2M_ALLOC);<br>
     if ( !page ||<br>
          !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )<br>
     {<br>
diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c<br>
index 4cc75916b8..9275ba476c 100644<br>
--- a/xen/arch/x86/mm/shadow/hvm.c<br>
+++ b/xen/arch/x86/mm/shadow/hvm.c<br>
@@ -313,15 +313,15 @@ const struct x86_emulate_ops hvm_shadow_emulator_ops = {<br>
 static mfn_t emulate_gva_to_mfn(struct vcpu *v, unsigned long vaddr,<br>
                                 struct sh_emulate_ctxt *sh_ctxt)<br>
 {<br>
-    unsigned long gfn;<br>
+    gfn_t gfn;<br>
     struct page_info *page;<br>
     mfn_t mfn;<br>
     p2m_type_t p2mt;<br>
     uint32_t pfec = PFEC_page_present | PFEC_write_access;<br>
<br>
     /* Translate the VA to a GFN. */<br>
-    gfn = paging_get_hostmode(v)-&gt;gva_to_gfn(v, NULL, vaddr, &amp;pfec);<br>
-    if ( gfn == gfn_x(INVALID_GFN) )<br>
+    gfn = _gfn(paging_get_hostmode(v)-&gt;gva_to_gfn(v, NULL, vaddr, &amp;pfec));<br>
+    if ( gfn_eq(gfn, INVALID_GFN) )<br>
     {<br>
         x86_emul_pagefault(pfec, vaddr, &amp;sh_ctxt-&gt;ctxt);<br>
<br>
diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c<br>
index 3a3c15890b..4f3f438614 100644<br>
--- a/xen/arch/x86/physdev.c<br>
+++ b/xen/arch/x86/physdev.c<br>
@@ -229,7 +229,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)<br>
             break;<br>
<br>
         ret = -EINVAL;<br>
-        page = get_page_from_gfn(current-&gt;domain, info.gmfn, NULL, P2M_ALLOC);<br>
+        page = get_page_from_gfn(current-&gt;domain, _gfn(info.gmfn),<br>
+                                 NULL, P2M_ALLOC);<br>
         if ( !page )<br>
             break;<br>
         if ( !get_page_type(page, PGT_writable_page) )<br>
diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c<br>
index 8b2d55fc2e..7e8f41d3fd 100644<br>
--- a/xen/arch/x86/pv/descriptor-tables.c<br>
+++ b/xen/arch/x86/pv/descriptor-tables.c<br>
@@ -112,7 +112,7 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames, unsigned int entries)<br>
     {<br>
         struct page_info *page;<br>
<br>
-        page = get_page_from_gfn(d, frames[i], NULL, P2M_ALLOC);<br>
+        page = get_page_from_gfn(d, _gfn(frames[i]), NULL, P2M_ALLOC);<br>
         if ( !page )<br>
             goto fail;<br>
         if ( !get_page_type(page, PGT_seg_desc_page) )<br>
@@ -209,7 +209,6 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) frame_list,<br>
 long do_update_descriptor(uint64_t pa, uint64_t desc)<br>
 {<br>
     struct domain *currd = current-&gt;domain;<br>
-    unsigned long gmfn = pa &gt;&gt; PAGE_SHIFT;<br>
     unsigned long mfn;<br>
     unsigned int  offset;<br>
     struct desc_struct *gdt_pent, d;<br>
@@ -220,7 +219,7 @@ long do_update_descriptor(uint64_t pa, uint64_t desc)<br>
<br>
     *(uint64_t *)&amp;d = desc;<br>
<br>
-    page = get_page_from_gfn(currd, gmfn, NULL, P2M_ALLOC);<br>
+    page = get_page_from_gfn(currd, gaddr_to_gfn(pa), NULL, P2M_ALLOC);<br>
     if ( (((unsigned int)pa % sizeof(struct desc_struct)) != 0) ||<br>
          !page ||<br>
          !check_descriptor(currd, &amp;d) )<br>
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c<br>
index f73ea4a163..a529ebcc3f 100644<br>
--- a/xen/arch/x86/pv/emul-priv-op.c<br>
+++ b/xen/arch/x86/pv/emul-priv-op.c<br>
@@ -760,12 +760,12 @@ static int write_cr(unsigned int reg, unsigned long val,<br>
     case 3: /* Write CR3 */<br>
     {<br>
         struct domain *currd = curr-&gt;domain;<br>
-        unsigned long gfn;<br>
+        gfn_t gfn;<br>
         struct page_info *page;<br>
         int rc;<br>
<br>
-        gfn = !is_pv_32bit_domain(currd)<br>
-              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val);<br>
+        gfn = _gfn(!is_pv_32bit_domain(currd)<br>
+              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val));<br>
         page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);<br>
         if ( !page )<br>
             break;<br>
diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c<br>
index f5ea00ca4e..c9ad1152b4 100644<br>
--- a/xen/arch/x86/pv/mm.c<br>
+++ b/xen/arch/x86/pv/mm.c<br>
@@ -106,7 +106,7 @@ bool pv_map_ldt_shadow_page(unsigned int offset)<br>
     if ( unlikely(!(l1e_get_flags(gl1e) &amp; _PAGE_PRESENT)) )<br>
         return false;<br>
<br>
-    page = get_page_from_gfn(currd, l1e_get_pfn(gl1e), NULL, P2M_ALLOC);<br>
+    page = get_page_from_gfn(currd, _gfn(l1e_get_pfn(gl1e)), NULL, P2M_ALLOC);<br>
     if ( unlikely(!page) )<br>
         return false;<br>
<br>
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c<br>
index 9471d89022..d967e49432 100644<br>
--- a/xen/arch/x86/traps.c<br>
+++ b/xen/arch/x86/traps.c<br>
@@ -795,7 +795,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)<br>
     case 0: /* Write hypercall page */<br>
     {<br>
         void *hypercall_page;<br>
-        unsigned long gmfn = val &gt;&gt; PAGE_SHIFT;<br>
+        gfn_t gfn = gaddr_to_gfn(val);<br>
         unsigned int page_index = val &amp; (PAGE_SIZE - 1);<br>
         struct page_info *page;<br>
         p2m_type_t t;<br>
@@ -808,7 +808,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)<br>
             return X86EMUL_EXCEPTION;<br>
         }<br>
<br>
-        page = get_page_from_gfn(d, gmfn, &amp;t, P2M_ALLOC);<br>
+        page = get_page_from_gfn(d, gfn, &amp;t, P2M_ALLOC);<br>
<br>
         if ( !page || !get_page_type(page, PGT_writable_page) )<br>
         {<br>
@@ -817,13 +817,14 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)<br>
<br>
             if ( p2m_is_paging(t) )<br>
             {<br>
-                p2m_mem_paging_populate(d, gmfn);<br>
+                p2m_mem_paging_populate(d, gfn_x(gfn));<br>
                 return X86EMUL_RETRY;<br>
             }<br>
<br>
             gdprintk(XENLOG_WARNING,<br>
-                     &quot;Bad GMFN %lx (MFN %#&quot;PRI_mfn&quot;) to MSR %08x\n&quot;,<br>
-                     gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN), base);<br>
+                     &quot;Bad GMFN %#&quot;PRI_gfn&quot; (MFN %#&quot;PRI_mfn&quot;) to MSR %08x\n&quot;,<br>
+                     gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN),<br>
+                     base);<br>
             return X86EMUL_EXCEPTION;<br>
         }<br>
<br>
diff --git a/xen/common/domain.c b/xen/common/domain.c<br>
index d6650f0656..5e3c05b96c 100644<br>
--- a/xen/common/domain.c<br>
+++ b/xen/common/domain.c<br>
@@ -1250,7 +1250,7 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset)<br>
     if ( (v != current) &amp;&amp; !(v-&gt;pause_flags &amp; VPF_down) )<br>
         return -EINVAL;<br>
<br>
-    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);<br>
+    page = get_page_from_gfn(d, _gfn(gfn), NULL, P2M_ALLOC);<br>
     if ( !page )<br>
         return -EINVAL;<br>
<br>
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c<br>
index c49f446754..71a6f673b2 100644<br>
--- a/xen/common/event_fifo.c<br>
+++ b/xen/common/event_fifo.c<br>
@@ -358,7 +358,7 @@ static const struct evtchn_port_ops evtchn_port_ops_fifo =<br>
     .print_state   = evtchn_fifo_print_state,<br>
 };<br>
<br>
-static int map_guest_page(struct domain *d, uint64_t gfn, void **virt)<br>
+static int map_guest_page(struct domain *d, gfn_t gfn, void **virt)<br>
 {<br>
     struct page_info *p;<br>
<br>
@@ -419,7 +419,7 @@ static int setup_control_block(struct vcpu *v)<br>
     return 0;<br>
 }<br>
<br>
-static int map_control_block(struct vcpu *v, uint64_t gfn, uint32_t offset)<br>
+static int map_control_block(struct vcpu *v, gfn_t gfn, uint32_t offset)<br>
 {<br>
     void *virt;<br>
     unsigned int i;<br>
@@ -505,7 +505,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)<br>
 {<br>
     struct domain *d = current-&gt;domain;<br>
     uint32_t vcpu_id;<br>
-    uint64_t gfn;<br>
+    gfn_t gfn;<br>
     uint32_t offset;<br>
     struct vcpu *v;<br>
     int rc;<br>
@@ -513,7 +513,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)<br>
     init_control-&gt;link_bits = EVTCHN_FIFO_LINK_BITS;<br>
<br>
     vcpu_id = init_control-&gt;vcpu;<br>
-    gfn     = init_control-&gt;control_gfn;<br>
+    gfn     = _gfn(init_control-&gt;control_gfn);<br>
     offset  = init_control-&gt;offset;<br>
<br>
     if ( vcpu_id &gt;= d-&gt;max_vcpus || !d-&gt;vcpu[vcpu_id] )<br>
@@ -569,7 +569,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)<br>
     return rc;<br>
 }<br>
<br>
-static int add_page_to_event_array(struct domain *d, unsigned long gfn)<br>
+static int add_page_to_event_array(struct domain *d, gfn_t gfn)<br>
 {<br>
     void *virt;<br>
     unsigned int slot;<br>
@@ -619,7 +619,7 @@ int evtchn_fifo_expand_array(const struct evtchn_expand_array *expand_array)<br>
         return -EOPNOTSUPP;<br>
<br>
     spin_lock(&amp;d-&gt;event_lock);<br>
-    rc = add_page_to_event_array(d, expand_array-&gt;array_gfn);<br>
+    rc = add_page_to_event_array(d, _gfn(expand_array-&gt;array_gfn));<br>
     spin_unlock(&amp;d-&gt;event_lock);<br>
<br>
     return rc;<br>
diff --git a/xen/common/memory.c b/xen/common/memory.c<br>
index 987395fbb3..e02733dba0 100644<br>
--- a/xen/common/memory.c<br>
+++ b/xen/common/memory.c<br>
@@ -1365,7 +1365,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)<br>
             return rc;<br>
         }<br>
<br>
-        page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC);<br>
+        page = get_page_from_gfn(d, _gfn(xrfp.gpfn), NULL, P2M_ALLOC);<br>
         if ( page )<br>
         {<br>
             rc = guest_physmap_remove_page(d, _gfn(xrfp.gpfn),<br>
@@ -1636,7 +1636,7 @@ int check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly,<br>
     p2m_type_t p2mt;<br>
     struct page_info *page;<br>
<br>
-    page = get_page_from_gfn(d, gfn_x(gfn), &amp;p2mt, q);<br>
+    page = get_page_from_gfn(d, gfn, &amp;p2mt, q);<br>
<br>
 #ifdef CONFIG_HAS_MEM_PAGING<br>
     if ( p2m_is_paging(p2mt) )<br>
diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c<br>
index bf7b14f79a..72cba7f10c 100644<br>
--- a/xen/common/tmem_xen.c<br>
+++ b/xen/common/tmem_xen.c<br>
@@ -52,7 +52,7 @@ static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn,<br>
     p2m_type_t t;<br>
     struct page_info *page;<br>
<br>
-    page = get_page_from_gfn(current-&gt;domain, cmfn, &amp;t, P2M_ALLOC);<br>
+    page = get_page_from_gfn(current-&gt;domain, _gfn(cmfn), &amp;t, P2M_ALLOC);<br>
     if ( !page || t != p2m_ram_rw )<br>
     {<br>
         if ( page )<br>
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h<br>
index 7c67806056..5e598a0b37 100644<br>
--- a/xen/include/asm-arm/p2m.h<br>
+++ b/xen/include/asm-arm/p2m.h<br>
@@ -278,7 +278,7 @@ struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn,<br>
                                         p2m_type_t *t);<br>
<br>
 static inline struct page_info *get_page_from_gfn(<br>
-    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)<br>
+    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)<br>
 {<br>
     mfn_t mfn;<br>
     p2m_type_t _t;<br>
@@ -289,7 +289,7 @@ static inline struct page_info *get_page_from_gfn(<br>
      * not auto-translated.<br>
      */<br>
     if ( unlikely(d != dom_xen) )<br>
-        return p2m_get_page_from_gfn(d, _gfn(gfn), t);<br>
+        return p2m_get_page_from_gfn(d, gfn, t);<br>
<br>
     if ( !t )<br>
         t = &amp;_t;<br>
@@ -300,7 +300,7 @@ static inline struct page_info *get_page_from_gfn(<br>
      * DOMID_XEN see 1-1 RAM. The p2m_type is based on the type of the<br>
      * page.<br>
      */<br>
-    mfn = _mfn(gfn);<br>
+    mfn = _mfn(gfn_x(gfn));<br>
     page = mfn_to_page(mfn);<br>
<br>
     if ( !mfn_valid(mfn) || !get_page(page, d) )<br>
diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h<br>
index d08c595887..db1ec37610 100644<br>
--- a/xen/include/asm-x86/p2m.h<br>
+++ b/xen/include/asm-x86/p2m.h<br>
@@ -489,18 +489,21 @@ struct page_info *p2m_get_page_from_gfn(struct p2m_domain *p2m, gfn_t gfn,<br>
                                         p2m_query_t q);<br>
<br>
 static inline struct page_info *get_page_from_gfn(<br>
-    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)<br>
+    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)<br>
 {<br>
     struct page_info *page;<br>
+    mfn_t mfn;<br>
<br>
     if ( paging_mode_translate(d) )<br>
-        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t, NULL, q);<br>
+        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL, q);<br>
<br>
     /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */<br>
     if ( t )<br>
         *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct;<br>
-    page = mfn_to_page(_mfn(gfn));<br>
-    return mfn_valid(_mfn(gfn)) &amp;&amp; get_page(page, d) ? page : NULL;<br>
+<br>
+    mfn = _mfn(gfn_x(gfn));<br>
+    page = mfn_to_page(mfn);<br>
+    return mfn_valid(mfn) &amp;&amp; get_page(page, d) ? page : NULL;<br>
 }<br>
<br>
 /* General conversion function from mfn to gfn */<br>
-- <br>
2.11.0<br>
<br>
<br>
_______________________________________________<br>
Xen-devel mailing list<br>
<a href="mailto:Xen-devel@lists.xenproject.org" target="_blank">Xen-devel@lists.xenproject.org</a><br>
<a href="https://lists.xenproject.org/mailman/listinfo/xen-devel" rel="noreferrer" target="_blank">https://lists.xenproject.org/mailman/listinfo/xen-devel</a></blockquote></div>
Julien Grall Nov. 12, 2018, 4:52 p.m. UTC | #8
On 11/12/18 4:49 PM, Andrii Anisov wrote:
> Hello Julien,

Hi,

> 
> I'm just wondering if this patch really belongs to xentrace series.
> It rather looks like a separate cleanup patch.

What's wrong with including clean-up patch in a series adding a feature?

Cheers,
Andrii Anisov Nov. 12, 2018, 4:58 p.m. UTC | #9
> What's wrong with including clean-up patch in a series adding a feature?

I do not mean it is wrong.
Just assuming that introducing a new feature and cleaning up a code
might be different processes with a different review period.

Sincerely,
Andrii Anisov.
Julien Grall Nov. 12, 2018, 5:09 p.m. UTC | #10
Hi,

On 11/12/18 4:58 PM, Andrii Anisov wrote:
>> What's wrong with including clean-up patch in a series adding a feature?
> 
> I do not mean it is wrong.
> Just assuming that introducing a new feature and cleaning up a code
> might be different processes with a different review period.

We don't have different process nor different review period between 
clean-up and new feature.

I tend to do clean-up when writing new features... See my cacheflush 
series as well. If the clean-up is small then I will append/prepend to 
the feature series.

This patch modify a function that was called by this patch and therefore 
depends on the rest of the series. This was written with this series so 
it makes sense to me to do it together as it dictates the order I would 
like the patches applied and simplify tracking (I have many series in 
flight).

Cheers,
diff mbox series

Patch

diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c
index 7a0f3e9d5f..55892062bb 100644
--- a/xen/arch/arm/guestcopy.c
+++ b/xen/arch/arm/guestcopy.c
@@ -37,7 +37,7 @@  static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,
         return get_page_from_gva(info.gva.v, addr,
                                  write ? GV2M_WRITE : GV2M_READ);
 
-    page = get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &p2mt, P2M_ALLOC);
+    page = get_page_from_gfn(info.gpa.d, gaddr_to_gfn(addr), &p2mt, P2M_ALLOC);
 
     if ( !page )
         return NULL;
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 72d0285768..88711096ef 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1268,7 +1268,7 @@  int xenmem_add_to_physmap_one(
 
         /* Take reference to the foreign domain page.
          * Reference will be released in XENMEM_remove_from_physmap */
-        page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC);
+        page = get_page_from_gfn(od, _gfn(idx), &p2mt, P2M_ALLOC);
         if ( !page )
         {
             put_pg_owner(od);
diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c
index 8a4f753eae..4d8f153031 100644
--- a/xen/arch/x86/cpu/vpmu.c
+++ b/xen/arch/x86/cpu/vpmu.c
@@ -607,7 +607,7 @@  static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)
     struct vcpu *v;
     struct vpmu_struct *vpmu;
     struct page_info *page;
-    uint64_t gfn = params->val;
+    gfn_t gfn = _gfn(params->val);
 
     if ( (params->vcpu >= d->max_vcpus) || (d->vcpu[params->vcpu] == NULL) )
         return -EINVAL;
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index f6fe954313..c5cce4b38d 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -797,7 +797,7 @@  int arch_set_info_guest(
     unsigned long flags;
     bool compat;
 #ifdef CONFIG_PV
-    unsigned long cr3_gfn;
+    gfn_t cr3_gfn;
     struct page_info *cr3_page;
     unsigned long cr4;
     int rc = 0;
@@ -1061,9 +1061,9 @@  int arch_set_info_guest(
     set_bit(_VPF_in_reset, &v->pause_flags);
 
     if ( !compat )
-        cr3_gfn = xen_cr3_to_pfn(c.nat->ctrlreg[3]);
+        cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat->ctrlreg[3]));
     else
-        cr3_gfn = compat_cr3_to_pfn(c.cmp->ctrlreg[3]);
+        cr3_gfn = _gfn(compat_cr3_to_pfn(c.cmp->ctrlreg[3]));
     cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC);
 
     if ( !cr3_page )
@@ -1092,7 +1092,7 @@  int arch_set_info_guest(
         case 0:
             if ( !compat && !VM_ASSIST(d, m2p_strict) &&
                  !paging_mode_refcounts(d) )
-                fill_ro_mpt(_mfn(cr3_gfn));
+                fill_ro_mpt(_mfn(gfn_x(cr3_gfn)));
             break;
         default:
             if ( cr3_page == current->arch.old_guest_table )
@@ -1107,7 +1107,7 @@  int arch_set_info_guest(
         v->arch.guest_table = pagetable_from_page(cr3_page);
         if ( c.nat->ctrlreg[1] )
         {
-            cr3_gfn = xen_cr3_to_pfn(c.nat->ctrlreg[1]);
+            cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat->ctrlreg[1]));
             cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC);
 
             if ( !cr3_page )
@@ -1132,7 +1132,7 @@  int arch_set_info_guest(
                     break;
                 case 0:
                     if ( VM_ASSIST(d, m2p_strict) )
-                        zap_ro_mpt(_mfn(cr3_gfn));
+                        zap_ro_mpt(_mfn(gfn_x(cr3_gfn)));
                     break;
                 }
             }
diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 33f9a869c0..6b0d8075cd 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -448,7 +448,7 @@  long arch_do_domctl(
                 break;
             }
 
-            page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC);
+            page = get_page_from_gfn(d, _gfn(gfn), &t, P2M_ALLOC);
 
             if ( unlikely(!page) ||
                  unlikely(is_xen_heap_page(page)) )
@@ -498,11 +498,11 @@  long arch_do_domctl(
 
     case XEN_DOMCTL_hypercall_init:
     {
-        unsigned long gmfn = domctl->u.hypercall_init.gmfn;
+        gfn_t gfn = _gfn(domctl->u.hypercall_init.gmfn);
         struct page_info *page;
         void *hypercall_page;
 
-        page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
+        page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
 
         if ( !page || !get_page_type(page, PGT_writable_page) )
         {
diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index d6d0e8be89..3b3ad27938 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -186,7 +186,7 @@  static int modified_memory(struct domain *d,
         {
             struct page_info *page;
 
-            page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE);
+            page = get_page_from_gfn(d, _gfn(pfn), NULL, P2M_UNSHARE);
             if ( page )
             {
                 paging_mark_pfn_dirty(d, _pfn(pfn));
diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c
index 5d5a746a25..73d2da8441 100644
--- a/xen/arch/x86/hvm/domain.c
+++ b/xen/arch/x86/hvm/domain.c
@@ -297,7 +297,7 @@  int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx)
     {
         /* Shadow-mode CR3 change. Check PDBR and update refcounts. */
         struct page_info *page = get_page_from_gfn(v->domain,
-                                 v->arch.hvm.guest_cr[3] >> PAGE_SHIFT,
+                                 gaddr_to_gfn(v->arch.hvm.guest_cr[3]),
                                  NULL, P2M_ALLOC);
         if ( !page )
         {
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 7be9cf4454..be262e5a1d 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2146,7 +2146,7 @@  int hvm_set_cr0(unsigned long value, bool may_defer)
 {
     struct vcpu *v = current;
     struct domain *d = v->domain;
-    unsigned long gfn, old_value = v->arch.hvm.guest_cr[0];
+    unsigned long old_value = v->arch.hvm.guest_cr[0];
     struct page_info *page;
 
     HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value = %lx", value);
@@ -2201,7 +2201,8 @@  int hvm_set_cr0(unsigned long value, bool may_defer)
         if ( !paging_mode_hap(d) )
         {
             /* The guest CR3 must be pointing to the guest physical. */
-            gfn = v->arch.hvm.guest_cr[3] >> PAGE_SHIFT;
+            gfn_t gfn = gaddr_to_gfn(v->arch.hvm.guest_cr[3]);
+
             page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
             if ( !page )
             {
@@ -2293,7 +2294,7 @@  int hvm_set_cr3(unsigned long value, bool may_defer)
     {
         /* Shadow-mode CR3 change. Check PDBR and update refcounts. */
         HVM_DBG_LOG(DBG_LEVEL_VMMU, "CR3 value = %lx", value);
-        page = get_page_from_gfn(v->domain, value >> PAGE_SHIFT,
+        page = get_page_from_gfn(v->domain, gaddr_to_gfn(value),
                                  NULL, P2M_ALLOC);
         if ( !page )
             goto bad_cr3;
@@ -3120,7 +3121,7 @@  enum hvm_translation_result hvm_translate_get_page(
          && hvm_mmio_internal(gfn_to_gaddr(gfn)) )
         return HVMTRANS_bad_gfn_to_mfn;
 
-    page = get_page_from_gfn(v->domain, gfn_x(gfn), &p2mt, P2M_UNSHARE);
+    page = get_page_from_gfn(v->domain, gfn, &p2mt, P2M_UNSHARE);
 
     if ( !page )
         return HVMTRANS_bad_gfn_to_mfn;
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 5d00256aaa..a7419bd444 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -317,7 +317,7 @@  static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)
     {
         if ( c->cr0 & X86_CR0_PG )
         {
-            page = get_page_from_gfn(v->domain, c->cr3 >> PAGE_SHIFT,
+            page = get_page_from_gfn(v->domain, gaddr_to_gfn(c->cr3),
                                      NULL, P2M_ALLOC);
             if ( !page )
             {
@@ -2412,9 +2412,9 @@  nsvm_get_nvmcb_page(struct vcpu *v, uint64_t vmcbaddr)
         return NULL;
 
     /* Need to translate L1-GPA to MPA */
-    page = get_page_from_gfn(v->domain, 
-                            nv->nv_vvmcxaddr >> PAGE_SHIFT, 
-                            &p2mt, P2M_ALLOC | P2M_UNSHARE);
+    page = get_page_from_gfn(v->domain,
+                             gaddr_to_gfn(nv->nv_vvmcxaddr >> PAGE_SHIFT),
+                             &p2mt, P2M_ALLOC | P2M_UNSHARE);
     if ( !page )
         return NULL;
 
diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c
index 2dc86dd0f3..1d3be156db 100644
--- a/xen/arch/x86/hvm/viridian/viridian.c
+++ b/xen/arch/x86/hvm/viridian/viridian.c
@@ -332,16 +332,16 @@  static void dump_reference_tsc(const struct domain *d)
 
 static void enable_hypercall_page(struct domain *d)
 {
-    unsigned long gmfn = d->arch.hvm.viridian.hypercall_gpa.fields.pfn;
-    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
+    gfn_t gfn = _gfn(d->arch.hvm.viridian.hypercall_gpa.fields.pfn);
+    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
     uint8_t *p;
 
     if ( !page || !get_page_type(page, PGT_writable_page) )
     {
         if ( page )
             put_page(page);
-        gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",
-                 gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));
+        gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",
+                 gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));
         return;
     }
 
@@ -367,8 +367,8 @@  static void enable_hypercall_page(struct domain *d)
 static void initialize_vp_assist(struct vcpu *v)
 {
     struct domain *d = v->domain;
-    unsigned long gmfn = v->arch.hvm.viridian.vp_assist.msr.fields.pfn;
-    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
+    gfn_t gfn = _gfn(v->arch.hvm.viridian.vp_assist.msr.fields.pfn);
+    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
     void *va;
 
     ASSERT(!v->arch.hvm.viridian.vp_assist.va);
@@ -395,8 +395,8 @@  static void initialize_vp_assist(struct vcpu *v)
     return;
 
  fail:
-    gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",
-             gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));
+    gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",
+             gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));
 }
 
 static void teardown_vp_assist(struct vcpu *v)
@@ -465,16 +465,16 @@  void viridian_apic_assist_clear(struct vcpu *v)
 
 static void update_reference_tsc(struct domain *d, bool_t initialize)
 {
-    unsigned long gmfn = d->arch.hvm.viridian.reference_tsc.fields.pfn;
-    struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
+    gfn_t gfn = _gfn(d->arch.hvm.viridian.reference_tsc.fields.pfn);
+    struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
     HV_REFERENCE_TSC_PAGE *p;
 
     if ( !page || !get_page_type(page, PGT_writable_page) )
     {
         if ( page )
             put_page(page);
-        gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",
-                 gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN));
+        gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n",
+                 gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN));
         return;
     }
 
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index e065f8bbdb..2070e78358 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -674,7 +674,7 @@  static int vmx_restore_cr0_cr3(
     {
         if ( cr0 & X86_CR0_PG )
         {
-            page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT,
+            page = get_page_from_gfn(v->domain, gaddr_to_gfn(cr3),
                                      NULL, P2M_ALLOC);
             if ( !page )
             {
@@ -1373,7 +1373,7 @@  static void vmx_load_pdptrs(struct vcpu *v)
     if ( (cr3 & 0x1fUL) && !hvm_pcid_enabled(v) )
         goto crash;
 
-    page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, &p2mt, P2M_UNSHARE);
+    page = get_page_from_gfn(v->domain, gaddr_to_gfn(cr3), &p2mt, P2M_UNSHARE);
     if ( !page )
     {
         /* Ideally you don't want to crash but rather go into a wait 
diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index dfd08e2d0a..2953d05a17 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -649,11 +649,11 @@  static void nvmx_update_apic_access_address(struct vcpu *v)
     if ( ctrl & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES )
     {
         p2m_type_t p2mt;
-        unsigned long apic_gpfn;
+        gfn_t apic_gfn;
         struct page_info *apic_pg;
 
-        apic_gpfn = get_vvmcs(v, APIC_ACCESS_ADDR) >> PAGE_SHIFT;
-        apic_pg = get_page_from_gfn(v->domain, apic_gpfn, &p2mt, P2M_ALLOC);
+        apic_gfn = gaddr_to_gfn(get_vvmcs(v, APIC_ACCESS_ADDR));
+        apic_pg = get_page_from_gfn(v->domain, apic_gfn, &p2mt, P2M_ALLOC);
         ASSERT(apic_pg && !p2m_is_paging(p2mt));
         __vmwrite(APIC_ACCESS_ADDR, page_to_maddr(apic_pg));
         put_page(apic_pg);
@@ -670,11 +670,11 @@  static void nvmx_update_virtual_apic_address(struct vcpu *v)
     if ( ctrl & CPU_BASED_TPR_SHADOW )
     {
         p2m_type_t p2mt;
-        unsigned long vapic_gpfn;
+        gfn_t vapic_gfn;
         struct page_info *vapic_pg;
 
-        vapic_gpfn = get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR) >> PAGE_SHIFT;
-        vapic_pg = get_page_from_gfn(v->domain, vapic_gpfn, &p2mt, P2M_ALLOC);
+        vapic_gfn = gaddr_to_gfn(get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR));
+        vapic_pg = get_page_from_gfn(v->domain, vapic_gfn, &p2mt, P2M_ALLOC);
         ASSERT(vapic_pg && !p2m_is_paging(p2mt));
         __vmwrite(VIRTUAL_APIC_PAGE_ADDR, page_to_maddr(vapic_pg));
         put_page(vapic_pg);
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 9363e9bd96..e3462f8a77 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2052,7 +2052,7 @@  static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
             p2m_query_t q = l1e_get_flags(nl1e) & _PAGE_RW ?
                             P2M_ALLOC | P2M_UNSHARE : P2M_ALLOC;
 
-            page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), &p2mt, q);
+            page = get_page_from_gfn(pg_dom, _gfn(l1e_get_pfn(nl1e)), &p2mt, q);
 
             if ( p2m_is_paged(p2mt) )
             {
@@ -3223,7 +3223,8 @@  long do_mmuext_op(
             if ( paging_mode_refcounts(pg_owner) )
                 break;
 
-            page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC);
+            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL,
+                                     P2M_ALLOC);
             if ( unlikely(!page) )
             {
                 rc = -EINVAL;
@@ -3288,7 +3289,8 @@  long do_mmuext_op(
             if ( paging_mode_refcounts(pg_owner) )
                 break;
 
-            page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC);
+            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL,
+                                     P2M_ALLOC);
             if ( unlikely(!page) )
             {
                 gdprintk(XENLOG_WARNING,
@@ -3504,7 +3506,8 @@  long do_mmuext_op(
         }
 
         case MMUEXT_CLEAR_PAGE:
-            page = get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt, P2M_ALLOC);
+            page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p2mt,
+                                     P2M_ALLOC);
             if ( unlikely(p2mt != p2m_ram_rw) && page )
             {
                 put_page(page);
@@ -3532,7 +3535,7 @@  long do_mmuext_op(
         {
             struct page_info *src_page, *dst_page;
 
-            src_page = get_page_from_gfn(pg_owner, op.arg2.src_mfn, &p2mt,
+            src_page = get_page_from_gfn(pg_owner, _gfn(op.arg2.src_mfn), &p2mt,
                                          P2M_ALLOC);
             if ( unlikely(p2mt != p2m_ram_rw) && src_page )
             {
@@ -3548,7 +3551,7 @@  long do_mmuext_op(
                 break;
             }
 
-            dst_page = get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt,
+            dst_page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p2mt,
                                          P2M_ALLOC);
             if ( unlikely(p2mt != p2m_ram_rw) && dst_page )
             {
@@ -3636,7 +3639,8 @@  long do_mmu_update(
 {
     struct mmu_update req;
     void *va = NULL;
-    unsigned long gpfn, gmfn, mfn;
+    unsigned long gpfn, mfn;
+    gfn_t gfn;
     struct page_info *page;
     unsigned int cmd, i = 0, done = 0, pt_dom;
     struct vcpu *curr = current, *v = curr;
@@ -3749,8 +3753,8 @@  long do_mmu_update(
             rc = -EINVAL;
 
             req.ptr -= cmd;
-            gmfn = req.ptr >> PAGE_SHIFT;
-            page = get_page_from_gfn(pt_owner, gmfn, &p2mt, P2M_ALLOC);
+            gfn = gaddr_to_gfn(req.ptr);
+            page = get_page_from_gfn(pt_owner, gfn, &p2mt, P2M_ALLOC);
 
             if ( unlikely(!page) || p2mt != p2m_ram_rw )
             {
@@ -3758,7 +3762,7 @@  long do_mmu_update(
                     put_page(page);
                 if ( p2m_is_paged(p2mt) )
                 {
-                    p2m_mem_paging_populate(pt_owner, gmfn);
+                    p2m_mem_paging_populate(pt_owner, gfn_x(gfn));
                     rc = -ENOENT;
                 }
                 else
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index a00a3c1bff..3b2aac8804 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -2718,7 +2718,7 @@  int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
      * Take a refcnt on the mfn. NB: following supported for foreign mapping:
      *     ram_rw | ram_logdirty | ram_ro | paging_out.
      */
-    page = get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC);
+    page = get_page_from_gfn(fdom, _gfn(fgfn), &p2mt, P2M_ALLOC);
     if ( !page ||
          !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )
     {
diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c
index 4cc75916b8..9275ba476c 100644
--- a/xen/arch/x86/mm/shadow/hvm.c
+++ b/xen/arch/x86/mm/shadow/hvm.c
@@ -313,15 +313,15 @@  const struct x86_emulate_ops hvm_shadow_emulator_ops = {
 static mfn_t emulate_gva_to_mfn(struct vcpu *v, unsigned long vaddr,
                                 struct sh_emulate_ctxt *sh_ctxt)
 {
-    unsigned long gfn;
+    gfn_t gfn;
     struct page_info *page;
     mfn_t mfn;
     p2m_type_t p2mt;
     uint32_t pfec = PFEC_page_present | PFEC_write_access;
 
     /* Translate the VA to a GFN. */
-    gfn = paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec);
-    if ( gfn == gfn_x(INVALID_GFN) )
+    gfn = _gfn(paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec));
+    if ( gfn_eq(gfn, INVALID_GFN) )
     {
         x86_emul_pagefault(pfec, vaddr, &sh_ctxt->ctxt);
 
diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c
index 3a3c15890b..4f3f438614 100644
--- a/xen/arch/x86/physdev.c
+++ b/xen/arch/x86/physdev.c
@@ -229,7 +229,8 @@  ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
             break;
 
         ret = -EINVAL;
-        page = get_page_from_gfn(current->domain, info.gmfn, NULL, P2M_ALLOC);
+        page = get_page_from_gfn(current->domain, _gfn(info.gmfn),
+                                 NULL, P2M_ALLOC);
         if ( !page )
             break;
         if ( !get_page_type(page, PGT_writable_page) )
diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c
index 8b2d55fc2e..7e8f41d3fd 100644
--- a/xen/arch/x86/pv/descriptor-tables.c
+++ b/xen/arch/x86/pv/descriptor-tables.c
@@ -112,7 +112,7 @@  long pv_set_gdt(struct vcpu *v, unsigned long *frames, unsigned int entries)
     {
         struct page_info *page;
 
-        page = get_page_from_gfn(d, frames[i], NULL, P2M_ALLOC);
+        page = get_page_from_gfn(d, _gfn(frames[i]), NULL, P2M_ALLOC);
         if ( !page )
             goto fail;
         if ( !get_page_type(page, PGT_seg_desc_page) )
@@ -209,7 +209,6 @@  int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) frame_list,
 long do_update_descriptor(uint64_t pa, uint64_t desc)
 {
     struct domain *currd = current->domain;
-    unsigned long gmfn = pa >> PAGE_SHIFT;
     unsigned long mfn;
     unsigned int  offset;
     struct desc_struct *gdt_pent, d;
@@ -220,7 +219,7 @@  long do_update_descriptor(uint64_t pa, uint64_t desc)
 
     *(uint64_t *)&d = desc;
 
-    page = get_page_from_gfn(currd, gmfn, NULL, P2M_ALLOC);
+    page = get_page_from_gfn(currd, gaddr_to_gfn(pa), NULL, P2M_ALLOC);
     if ( (((unsigned int)pa % sizeof(struct desc_struct)) != 0) ||
          !page ||
          !check_descriptor(currd, &d) )
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index f73ea4a163..a529ebcc3f 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -760,12 +760,12 @@  static int write_cr(unsigned int reg, unsigned long val,
     case 3: /* Write CR3 */
     {
         struct domain *currd = curr->domain;
-        unsigned long gfn;
+        gfn_t gfn;
         struct page_info *page;
         int rc;
 
-        gfn = !is_pv_32bit_domain(currd)
-              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val);
+        gfn = _gfn(!is_pv_32bit_domain(currd)
+              ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val));
         page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);
         if ( !page )
             break;
diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c
index f5ea00ca4e..c9ad1152b4 100644
--- a/xen/arch/x86/pv/mm.c
+++ b/xen/arch/x86/pv/mm.c
@@ -106,7 +106,7 @@  bool pv_map_ldt_shadow_page(unsigned int offset)
     if ( unlikely(!(l1e_get_flags(gl1e) & _PAGE_PRESENT)) )
         return false;
 
-    page = get_page_from_gfn(currd, l1e_get_pfn(gl1e), NULL, P2M_ALLOC);
+    page = get_page_from_gfn(currd, _gfn(l1e_get_pfn(gl1e)), NULL, P2M_ALLOC);
     if ( unlikely(!page) )
         return false;
 
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 9471d89022..d967e49432 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -795,7 +795,7 @@  int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)
     case 0: /* Write hypercall page */
     {
         void *hypercall_page;
-        unsigned long gmfn = val >> PAGE_SHIFT;
+        gfn_t gfn = gaddr_to_gfn(val);
         unsigned int page_index = val & (PAGE_SIZE - 1);
         struct page_info *page;
         p2m_type_t t;
@@ -808,7 +808,7 @@  int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)
             return X86EMUL_EXCEPTION;
         }
 
-        page = get_page_from_gfn(d, gmfn, &t, P2M_ALLOC);
+        page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC);
 
         if ( !page || !get_page_type(page, PGT_writable_page) )
         {
@@ -817,13 +817,14 @@  int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val)
 
             if ( p2m_is_paging(t) )
             {
-                p2m_mem_paging_populate(d, gmfn);
+                p2m_mem_paging_populate(d, gfn_x(gfn));
                 return X86EMUL_RETRY;
             }
 
             gdprintk(XENLOG_WARNING,
-                     "Bad GMFN %lx (MFN %#"PRI_mfn") to MSR %08x\n",
-                     gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN), base);
+                     "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn") to MSR %08x\n",
+                     gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN),
+                     base);
             return X86EMUL_EXCEPTION;
         }
 
diff --git a/xen/common/domain.c b/xen/common/domain.c
index d6650f0656..5e3c05b96c 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1250,7 +1250,7 @@  int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset)
     if ( (v != current) && !(v->pause_flags & VPF_down) )
         return -EINVAL;
 
-    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
+    page = get_page_from_gfn(d, _gfn(gfn), NULL, P2M_ALLOC);
     if ( !page )
         return -EINVAL;
 
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index c49f446754..71a6f673b2 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -358,7 +358,7 @@  static const struct evtchn_port_ops evtchn_port_ops_fifo =
     .print_state   = evtchn_fifo_print_state,
 };
 
-static int map_guest_page(struct domain *d, uint64_t gfn, void **virt)
+static int map_guest_page(struct domain *d, gfn_t gfn, void **virt)
 {
     struct page_info *p;
 
@@ -419,7 +419,7 @@  static int setup_control_block(struct vcpu *v)
     return 0;
 }
 
-static int map_control_block(struct vcpu *v, uint64_t gfn, uint32_t offset)
+static int map_control_block(struct vcpu *v, gfn_t gfn, uint32_t offset)
 {
     void *virt;
     unsigned int i;
@@ -505,7 +505,7 @@  int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
 {
     struct domain *d = current->domain;
     uint32_t vcpu_id;
-    uint64_t gfn;
+    gfn_t gfn;
     uint32_t offset;
     struct vcpu *v;
     int rc;
@@ -513,7 +513,7 @@  int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     init_control->link_bits = EVTCHN_FIFO_LINK_BITS;
 
     vcpu_id = init_control->vcpu;
-    gfn     = init_control->control_gfn;
+    gfn     = _gfn(init_control->control_gfn);
     offset  = init_control->offset;
 
     if ( vcpu_id >= d->max_vcpus || !d->vcpu[vcpu_id] )
@@ -569,7 +569,7 @@  int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     return rc;
 }
 
-static int add_page_to_event_array(struct domain *d, unsigned long gfn)
+static int add_page_to_event_array(struct domain *d, gfn_t gfn)
 {
     void *virt;
     unsigned int slot;
@@ -619,7 +619,7 @@  int evtchn_fifo_expand_array(const struct evtchn_expand_array *expand_array)
         return -EOPNOTSUPP;
 
     spin_lock(&d->event_lock);
-    rc = add_page_to_event_array(d, expand_array->array_gfn);
+    rc = add_page_to_event_array(d, _gfn(expand_array->array_gfn));
     spin_unlock(&d->event_lock);
 
     return rc;
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 987395fbb3..e02733dba0 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1365,7 +1365,7 @@  long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
             return rc;
         }
 
-        page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC);
+        page = get_page_from_gfn(d, _gfn(xrfp.gpfn), NULL, P2M_ALLOC);
         if ( page )
         {
             rc = guest_physmap_remove_page(d, _gfn(xrfp.gpfn),
@@ -1636,7 +1636,7 @@  int check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly,
     p2m_type_t p2mt;
     struct page_info *page;
 
-    page = get_page_from_gfn(d, gfn_x(gfn), &p2mt, q);
+    page = get_page_from_gfn(d, gfn, &p2mt, q);
 
 #ifdef CONFIG_HAS_MEM_PAGING
     if ( p2m_is_paging(p2mt) )
diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c
index bf7b14f79a..72cba7f10c 100644
--- a/xen/common/tmem_xen.c
+++ b/xen/common/tmem_xen.c
@@ -52,7 +52,7 @@  static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn,
     p2m_type_t t;
     struct page_info *page;
 
-    page = get_page_from_gfn(current->domain, cmfn, &t, P2M_ALLOC);
+    page = get_page_from_gfn(current->domain, _gfn(cmfn), &t, P2M_ALLOC);
     if ( !page || t != p2m_ram_rw )
     {
         if ( page )
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 7c67806056..5e598a0b37 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -278,7 +278,7 @@  struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn,
                                         p2m_type_t *t);
 
 static inline struct page_info *get_page_from_gfn(
-    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)
+    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)
 {
     mfn_t mfn;
     p2m_type_t _t;
@@ -289,7 +289,7 @@  static inline struct page_info *get_page_from_gfn(
      * not auto-translated.
      */
     if ( unlikely(d != dom_xen) )
-        return p2m_get_page_from_gfn(d, _gfn(gfn), t);
+        return p2m_get_page_from_gfn(d, gfn, t);
 
     if ( !t )
         t = &_t;
@@ -300,7 +300,7 @@  static inline struct page_info *get_page_from_gfn(
      * DOMID_XEN see 1-1 RAM. The p2m_type is based on the type of the
      * page.
      */
-    mfn = _mfn(gfn);
+    mfn = _mfn(gfn_x(gfn));
     page = mfn_to_page(mfn);
 
     if ( !mfn_valid(mfn) || !get_page(page, d) )
diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
index d08c595887..db1ec37610 100644
--- a/xen/include/asm-x86/p2m.h
+++ b/xen/include/asm-x86/p2m.h
@@ -489,18 +489,21 @@  struct page_info *p2m_get_page_from_gfn(struct p2m_domain *p2m, gfn_t gfn,
                                         p2m_query_t q);
 
 static inline struct page_info *get_page_from_gfn(
-    struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)
+    struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q)
 {
     struct page_info *page;
+    mfn_t mfn;
 
     if ( paging_mode_translate(d) )
-        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t, NULL, q);
+        return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL, q);
 
     /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */
     if ( t )
         *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct;
-    page = mfn_to_page(_mfn(gfn));
-    return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL;
+
+    mfn = _mfn(gfn_x(gfn));
+    page = mfn_to_page(mfn);
+    return mfn_valid(mfn) && get_page(page, d) ? page : NULL;
 }
 
 /* General conversion function from mfn to gfn */