All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/8] Use correctly the Xen memory terminologies in Linux
@ 2015-08-04 18:12 ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	Boris Ostrovsky, David Vrabel, Dmitry Torokhov,
	Greg Kroah-Hartman, H. Peter Anvin, Ingo Molnar,
	James E.J. Bottomley, Jean-Christophe Plagniol-Villard,
	Jiri Slaby, Juergen Gross, Konrad Rzeszutek Wilk, linux-api,
	linux-arm-kernel, linux-fbdev, linux-input, linuxppc-dev,
	linux-scsi, netdev, Roger Pau Monné,
	Russell King, Thomas Gleixner, Tomi Valkeinen, Wei Liu, x86

Hi all,

This patch series aims to use the memory terminologies described in
include/xen/mm.h [1] for Linux xen code.

Linux is using mistakenly MFN when GFN is meant, I suspect this is because the
first support of Xen was for PV. This has brought some misimplementation
of memory helpers on ARM and make the developper confused about the expected
behavior.

For instance, with pfn_to_mfn, we expect to get a MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.
Most of the callers are also using it this way.

The first 2 patches of this series is ARM related in order to remove
PV specific helpers which should not be used and fixing the implementation of
pfn_to_mfn.

The rest of the series is here rename most of the usage in the common code
of MFN to GFN. I also took the opportunity to replace most of the call to
pfn_to_gfn in the common code by page_to_gfn avoid construction such
as pfn_to_gfn(page_to_pfn(...).

Note the one xen-blkfront will be dropped by 64K series [2], I can include it
if necessary.

Major changes in v2:
    - Use bfn rather than dfn for the DMA address
    - Re-introduced pfn_to_mfn for PV guests only
    - Typoes

For all the changes see in each patch.

This series is based on linus's branch. A branch with all the patches
can be found here:
    git://xenbits.xen.org/people/julieng/linux-arm.git branch page-renaming-v2

It was been boot tested on ARM64 and only built for x86 and ARM32.
I would be happy if someone can give a try on x86 as I don't have a x86
box setup with Xen.

Sincerely yours,

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
[2] https://lkml.org/lkml/2015/7/9/628

Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-input@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-scsi@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: x86@kernel.org

Julien Grall (8):
  arm/xen: Remove helpers which are PV specific
  xen: Make clear that swiotlb and biomerge are dealing with DMA address
  arm/xen: implement correctly pfn_to_mfn
  xen: Use the correctly the Xen memory terminologies
  xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  video/xen-fbfront: Further s/MFN/GFN clean-up
  hvc/xen: Further s/MFN/GFN clean-up
  xen/privcmd: Further s/MFN/GFN/ clean-up

 arch/arm/include/asm/xen/page.h         | 44 ++++++++++++++++-----------------
 arch/arm/xen/enlighten.c                | 18 +++++++-------
 arch/arm/xen/mm.c                       |  4 +--
 arch/x86/include/asm/xen/page.h         | 37 +++++++++++++++++++++------
 arch/x86/xen/mmu.c                      | 32 ++++++++++++------------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 ++---
 drivers/input/misc/xen-kbdfront.c       |  4 +--
 drivers/net/xen-netback/netback.c       |  4 +--
 drivers/net/xen-netfront.c              |  8 +++---
 drivers/scsi/xen-scsifront.c            |  8 +++---
 drivers/tty/hvc/hvc_xen.c               | 18 ++++++--------
 drivers/video/fbdev/xen-fbfront.c       | 20 +++++++--------
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/biomerge.c                  |  6 ++---
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 +--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/privcmd.c                   | 44 ++++++++++++++++-----------------
 drivers/xen/swiotlb-xen.c               | 16 ++++++------
 drivers/xen/tmem.c                      | 21 ++++++----------
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++---
 drivers/xen/xlate_mmu.c                 | 18 +++++++-------
 include/uapi/xen/privcmd.h              |  4 +++
 include/xen/page.h                      |  4 +--
 include/xen/xen-ops.h                   | 10 ++++----
 29 files changed, 183 insertions(+), 170 deletions(-)

-- 
2.1.4


^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 0/8] Use correctly the Xen memory terminologies in Linux
@ 2015-08-04 18:12 ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, x86, netdev, H. Peter Anvin, Jiri Slaby,
	Thomas Gleixner, Russell King, linux-scsi, Tomi Valkeinen,
	stefano.stabellini, Ingo Molnar, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, Julien Grall, David Vrabel

Hi all,

This patch series aims to use the memory terminologies described in
include/xen/mm.h [1] for Linux xen code.

Linux is using mistakenly MFN when GFN is meant, I suspect this is because the
first support of Xen was for PV. This has brought some misimplementation
of memory helpers on ARM and make the developper confused about the expected
behavior.

For instance, with pfn_to_mfn, we expect to get a MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.
Most of the callers are also using it this way.

The first 2 patches of this series is ARM related in order to remove
PV specific helpers which should not be used and fixing the implementation of
pfn_to_mfn.

The rest of the series is here rename most of the usage in the common code
of MFN to GFN. I also took the opportunity to replace most of the call to
pfn_to_gfn in the common code by page_to_gfn avoid construction such
as pfn_to_gfn(page_to_pfn(...).

Note the one xen-blkfront will be dropped by 64K series [2], I can include it
if necessary.

Major changes in v2:
    - Use bfn rather than dfn for the DMA address
    - Re-introduced pfn_to_mfn for PV guests only
    - Typoes

For all the changes see in each patch.

This series is based on linus's branch. A branch with all the patches
can be found here:
    git://xenbits.xen.org/people/julieng/linux-arm.git branch page-renaming-v2

It was been boot tested on ARM64 and only built for x86 and ARM32.
I would be happy if someone can give a try on x86 as I don't have a x86
box setup with Xen.

Sincerely yours,

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
[2] https://lkml.org/lkml/2015/7/9/628

Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-input@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-scsi@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: x86@kernel.org

Julien Grall (8):
  arm/xen: Remove helpers which are PV specific
  xen: Make clear that swiotlb and biomerge are dealing with DMA address
  arm/xen: implement correctly pfn_to_mfn
  xen: Use the correctly the Xen memory terminologies
  xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  video/xen-fbfront: Further s/MFN/GFN clean-up
  hvc/xen: Further s/MFN/GFN clean-up
  xen/privcmd: Further s/MFN/GFN/ clean-up

 arch/arm/include/asm/xen/page.h         | 44 ++++++++++++++++-----------------
 arch/arm/xen/enlighten.c                | 18 +++++++-------
 arch/arm/xen/mm.c                       |  4 +--
 arch/x86/include/asm/xen/page.h         | 37 +++++++++++++++++++++------
 arch/x86/xen/mmu.c                      | 32 ++++++++++++------------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 ++---
 drivers/input/misc/xen-kbdfront.c       |  4 +--
 drivers/net/xen-netback/netback.c       |  4 +--
 drivers/net/xen-netfront.c              |  8 +++---
 drivers/scsi/xen-scsifront.c            |  8 +++---
 drivers/tty/hvc/hvc_xen.c               | 18 ++++++--------
 drivers/video/fbdev/xen-fbfront.c       | 20 +++++++--------
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/biomerge.c                  |  6 ++---
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 +--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/privcmd.c                   | 44 ++++++++++++++++-----------------
 drivers/xen/swiotlb-xen.c               | 16 ++++++------
 drivers/xen/tmem.c                      | 21 ++++++----------
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++---
 drivers/xen/xlate_mmu.c                 | 18 +++++++-------
 include/uapi/xen/privcmd.h              |  4 +++
 include/xen/page.h                      |  4 +--
 include/xen/xen-ops.h                   | 10 ++++----
 29 files changed, 183 insertions(+), 170 deletions(-)

-- 
2.1.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 0/8] Use correctly the Xen memory terminologies in Linux
@ 2015-08-04 18:12 ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, x86, netdev, H. Peter Anvin, Jiri Slaby,
	Thomas Gleixner, Russell King, linux-scsi, Tomi Valkeinen,
	stefano.stabellini, Ingo Molnar, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, Julien Grall, David Vrabel

Hi all,

This patch series aims to use the memory terminologies described in
include/xen/mm.h [1] for Linux xen code.

Linux is using mistakenly MFN when GFN is meant, I suspect this is because the
first support of Xen was for PV. This has brought some misimplementation
of memory helpers on ARM and make the developper confused about the expected
behavior.

For instance, with pfn_to_mfn, we expect to get a MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.
Most of the callers are also using it this way.

The first 2 patches of this series is ARM related in order to remove
PV specific helpers which should not be used and fixing the implementation of
pfn_to_mfn.

The rest of the series is here rename most of the usage in the common code
of MFN to GFN. I also took the opportunity to replace most of the call to
pfn_to_gfn in the common code by page_to_gfn avoid construction such
as pfn_to_gfn(page_to_pfn(...).

Note the one xen-blkfront will be dropped by 64K series [2], I can include it
if necessary.

Major changes in v2:
    - Use bfn rather than dfn for the DMA address
    - Re-introduced pfn_to_mfn for PV guests only
    - Typoes

For all the changes see in each patch.

This series is based on linus's branch. A branch with all the patches
can be found here:
    git://xenbits.xen.org/people/julieng/linux-arm.git branch page-renaming-v2

It was been boot tested on ARM64 and only built for x86 and ARM32.
I would be happy if someone can give a try on x86 as I don't have a x86
box setup with Xen.

Sincerely yours,

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
[2] https://lkml.org/lkml/2015/7/9/628

Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-input@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-scsi@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: x86@kernel.org

Julien Grall (8):
  arm/xen: Remove helpers which are PV specific
  xen: Make clear that swiotlb and biomerge are dealing with DMA address
  arm/xen: implement correctly pfn_to_mfn
  xen: Use the correctly the Xen memory terminologies
  xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  video/xen-fbfront: Further s/MFN/GFN clean-up
  hvc/xen: Further s/MFN/GFN clean-up
  xen/privcmd: Further s/MFN/GFN/ clean-up

 arch/arm/include/asm/xen/page.h         | 44 ++++++++++++++++-----------------
 arch/arm/xen/enlighten.c                | 18 +++++++-------
 arch/arm/xen/mm.c                       |  4 +--
 arch/x86/include/asm/xen/page.h         | 37 +++++++++++++++++++++------
 arch/x86/xen/mmu.c                      | 32 ++++++++++++------------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 ++---
 drivers/input/misc/xen-kbdfront.c       |  4 +--
 drivers/net/xen-netback/netback.c       |  4 +--
 drivers/net/xen-netfront.c              |  8 +++---
 drivers/scsi/xen-scsifront.c            |  8 +++---
 drivers/tty/hvc/hvc_xen.c               | 18 ++++++--------
 drivers/video/fbdev/xen-fbfront.c       | 20 +++++++--------
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/biomerge.c                  |  6 ++---
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 +--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/privcmd.c                   | 44 ++++++++++++++++-----------------
 drivers/xen/swiotlb-xen.c               | 16 ++++++------
 drivers/xen/tmem.c                      | 21 ++++++----------
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++---
 drivers/xen/xlate_mmu.c                 | 18 +++++++-------
 include/uapi/xen/privcmd.h              |  4 +++
 include/xen/page.h                      |  4 +--
 include/xen/xen-ops.h                   | 10 ++++----
 29 files changed, 183 insertions(+), 170 deletions(-)

-- 
2.1.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 0/8] Use correctly the Xen memory terminologies in Linux
@ 2015-08-04 18:12 ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, x86, netdev, H. Peter Anvin, Jiri Slaby,
	Thomas Gleixner, Russell King, linux-scsi, Tomi Valkeinen,
	stefano.stabellini, Ingo Molnar, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, Julien Grall, David Vrabel

Hi all,

This patch series aims to use the memory terminologies described in
include/xen/mm.h [1] for Linux xen code.

Linux is using mistakenly MFN when GFN is meant, I suspect this is because the
first support of Xen was for PV. This has brought some misimplementation
of memory helpers on ARM and make the developper confused about the expected
behavior.

For instance, with pfn_to_mfn, we expect to get a MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.
Most of the callers are also using it this way.

The first 2 patches of this series is ARM related in order to remove
PV specific helpers which should not be used and fixing the implementation of
pfn_to_mfn.

The rest of the series is here rename most of the usage in the common code
of MFN to GFN. I also took the opportunity to replace most of the call to
pfn_to_gfn in the common code by page_to_gfn avoid construction such
as pfn_to_gfn(page_to_pfn(...).

Note the one xen-blkfront will be dropped by 64K series [2], I can include it
if necessary.

Major changes in v2:
    - Use bfn rather than dfn for the DMA address
    - Re-introduced pfn_to_mfn for PV guests only
    - Typoes

For all the changes see in each patch.

This series is based on linus's branch. A branch with all the patches
can be found here:
    git://xenbits.xen.org/people/julieng/linux-arm.git branch page-renaming-v2

It was been boot tested on ARM64 and only built for x86 and ARM32.
I would be happy if someone can give a try on x86 as I don't have a x86
box setup with Xen.

Sincerely yours,

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;hç58ed14f390342513405dd766e874934573e6cb
[2] https://lkml.org/lkml/2015/7/9/628

Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-input@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-scsi@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: x86@kernel.org

Julien Grall (8):
  arm/xen: Remove helpers which are PV specific
  xen: Make clear that swiotlb and biomerge are dealing with DMA address
  arm/xen: implement correctly pfn_to_mfn
  xen: Use the correctly the Xen memory terminologies
  xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  video/xen-fbfront: Further s/MFN/GFN clean-up
  hvc/xen: Further s/MFN/GFN clean-up
  xen/privcmd: Further s/MFN/GFN/ clean-up

 arch/arm/include/asm/xen/page.h         | 44 ++++++++++++++++-----------------
 arch/arm/xen/enlighten.c                | 18 +++++++-------
 arch/arm/xen/mm.c                       |  4 +--
 arch/x86/include/asm/xen/page.h         | 37 +++++++++++++++++++++------
 arch/x86/xen/mmu.c                      | 32 ++++++++++++------------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 ++---
 drivers/input/misc/xen-kbdfront.c       |  4 +--
 drivers/net/xen-netback/netback.c       |  4 +--
 drivers/net/xen-netfront.c              |  8 +++---
 drivers/scsi/xen-scsifront.c            |  8 +++---
 drivers/tty/hvc/hvc_xen.c               | 18 ++++++--------
 drivers/video/fbdev/xen-fbfront.c       | 20 +++++++--------
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/biomerge.c                  |  6 ++---
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 +--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/privcmd.c                   | 44 ++++++++++++++++-----------------
 drivers/xen/swiotlb-xen.c               | 16 ++++++------
 drivers/xen/tmem.c                      | 21 ++++++----------
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++---
 drivers/xen/xlate_mmu.c                 | 18 +++++++-------
 include/uapi/xen/privcmd.h              |  4 +++
 include/xen/page.h                      |  4 +--
 include/xen/xen-ops.h                   | 10 ++++----
 29 files changed, 183 insertions(+), 170 deletions(-)

-- 
2.1.4


^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 0/8] Use correctly the Xen memory terminologies in Linux
@ 2015-08-04 18:12 ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

Hi all,

This patch series aims to use the memory terminologies described in
include/xen/mm.h [1] for Linux xen code.

Linux is using mistakenly MFN when GFN is meant, I suspect this is because the
first support of Xen was for PV. This has brought some misimplementation
of memory helpers on ARM and make the developper confused about the expected
behavior.

For instance, with pfn_to_mfn, we expect to get a MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.
Most of the callers are also using it this way.

The first 2 patches of this series is ARM related in order to remove
PV specific helpers which should not be used and fixing the implementation of
pfn_to_mfn.

The rest of the series is here rename most of the usage in the common code
of MFN to GFN. I also took the opportunity to replace most of the call to
pfn_to_gfn in the common code by page_to_gfn avoid construction such
as pfn_to_gfn(page_to_pfn(...).

Note the one xen-blkfront will be dropped by 64K series [2], I can include it
if necessary.

Major changes in v2:
    - Use bfn rather than dfn for the DMA address
    - Re-introduced pfn_to_mfn for PV guests only
    - Typoes

For all the changes see in each patch.

This series is based on linus's branch. A branch with all the patches
can be found here:
    git://xenbits.xen.org/people/julieng/linux-arm.git branch page-renaming-v2

It was been boot tested on ARM64 and only built for x86 and ARM32.
I would be happy if someone can give a try on x86 as I don't have a x86
box setup with Xen.

Sincerely yours,

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
[2] https://lkml.org/lkml/2015/7/9/628

Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: linux-api at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-fbdev at vger.kernel.org
Cc: linux-input at vger.kernel.org
Cc: linuxppc-dev at lists.ozlabs.org
Cc: linux-scsi at vger.kernel.org
Cc: netdev at vger.kernel.org
Cc: "Roger Pau Monn?" <roger.pau@citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: x86 at kernel.org

Julien Grall (8):
  arm/xen: Remove helpers which are PV specific
  xen: Make clear that swiotlb and biomerge are dealing with DMA address
  arm/xen: implement correctly pfn_to_mfn
  xen: Use the correctly the Xen memory terminologies
  xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  video/xen-fbfront: Further s/MFN/GFN clean-up
  hvc/xen: Further s/MFN/GFN clean-up
  xen/privcmd: Further s/MFN/GFN/ clean-up

 arch/arm/include/asm/xen/page.h         | 44 ++++++++++++++++-----------------
 arch/arm/xen/enlighten.c                | 18 +++++++-------
 arch/arm/xen/mm.c                       |  4 +--
 arch/x86/include/asm/xen/page.h         | 37 +++++++++++++++++++++------
 arch/x86/xen/mmu.c                      | 32 ++++++++++++------------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 ++---
 drivers/input/misc/xen-kbdfront.c       |  4 +--
 drivers/net/xen-netback/netback.c       |  4 +--
 drivers/net/xen-netfront.c              |  8 +++---
 drivers/scsi/xen-scsifront.c            |  8 +++---
 drivers/tty/hvc/hvc_xen.c               | 18 ++++++--------
 drivers/video/fbdev/xen-fbfront.c       | 20 +++++++--------
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/biomerge.c                  |  6 ++---
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 +--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/privcmd.c                   | 44 ++++++++++++++++-----------------
 drivers/xen/swiotlb-xen.c               | 16 ++++++------
 drivers/xen/tmem.c                      | 21 ++++++----------
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++---
 drivers/xen/xlate_mmu.c                 | 18 +++++++-------
 include/uapi/xen/privcmd.h              |  4 +++
 include/xen/page.h                      |  4 +--
 include/xen/xen-ops.h                   | 10 ++++----
 29 files changed, 183 insertions(+), 170 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 1/8] arm/xen: Remove helpers which are PV specific
  2015-08-04 18:12 ` Julien Grall
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	Russell King, linux-arm-kernel

ARM guests are always HVM. The current implementation is assuming a 1:1
mapping which is only true for DOM0 and may not be at all in the future.

Furthermore, all the helpers but arbitrary_virt_to_machine are used in
x86 specific code (or only compiled for).

The helper arbitrary_virt_to_machine is only used in PV specific code.
Therefore we should never call the function.

Add a BUG() in this helper and drop all the others.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org

---
    Changes in v2:
        - Typoes
        - Add Stefano's acked-by
---
 arch/arm/include/asm/xen/page.h | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 1bee8ca..98b1084 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -54,26 +54,14 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 
 #define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
 
-static inline xmaddr_t phys_to_machine(xpaddr_t phys)
-{
-	unsigned offset = phys.paddr & ~PAGE_MASK;
-	return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
-}
-
-static inline xpaddr_t machine_to_phys(xmaddr_t machine)
-{
-	unsigned offset = machine.maddr & ~PAGE_MASK;
-	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
-}
 /* VIRT <-> MACHINE conversion */
-#define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
 
+/* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
 {
-	/* TODO: assuming it is mapped in the kernel 1:1 */
-	return virt_to_machine(vaddr);
+	BUG();
 }
 
 /* TODO: this shouldn't be here but it is because the frontend drivers
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 1/8] arm/xen: Remove helpers which are PV specific
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

ARM guests are always HVM. The current implementation is assuming a 1:1
mapping which is only true for DOM0 and may not be at all in the future.

Furthermore, all the helpers but arbitrary_virt_to_machine are used in
x86 specific code (or only compiled for).

The helper arbitrary_virt_to_machine is only used in PV specific code.
Therefore we should never call the function.

Add a BUG() in this helper and drop all the others.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel at lists.infradead.org

---
    Changes in v2:
        - Typoes
        - Add Stefano's acked-by
---
 arch/arm/include/asm/xen/page.h | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 1bee8ca..98b1084 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -54,26 +54,14 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 
 #define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
 
-static inline xmaddr_t phys_to_machine(xpaddr_t phys)
-{
-	unsigned offset = phys.paddr & ~PAGE_MASK;
-	return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
-}
-
-static inline xpaddr_t machine_to_phys(xmaddr_t machine)
-{
-	unsigned offset = machine.maddr & ~PAGE_MASK;
-	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
-}
 /* VIRT <-> MACHINE conversion */
-#define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
 
+/* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
 {
-	/* TODO: assuming it is mapped in the kernel 1:1 */
-	return virt_to_machine(vaddr);
+	BUG();
 }
 
 /* TODO: this shouldn't be here but it is because the frontend drivers
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 1/8] arm/xen: Remove helpers which are PV specific
  2015-08-04 18:12 ` Julien Grall
                   ` (3 preceding siblings ...)
  (?)
@ 2015-08-04 18:12 ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: Russell King, ian.campbell, stefano.stabellini, linux-kernel,
	Julien Grall, linux-arm-kernel

ARM guests are always HVM. The current implementation is assuming a 1:1
mapping which is only true for DOM0 and may not be at all in the future.

Furthermore, all the helpers but arbitrary_virt_to_machine are used in
x86 specific code (or only compiled for).

The helper arbitrary_virt_to_machine is only used in PV specific code.
Therefore we should never call the function.

Add a BUG() in this helper and drop all the others.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org

---
    Changes in v2:
        - Typoes
        - Add Stefano's acked-by
---
 arch/arm/include/asm/xen/page.h | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 1bee8ca..98b1084 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -54,26 +54,14 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 
 #define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
 
-static inline xmaddr_t phys_to_machine(xpaddr_t phys)
-{
-	unsigned offset = phys.paddr & ~PAGE_MASK;
-	return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
-}
-
-static inline xpaddr_t machine_to_phys(xmaddr_t machine)
-{
-	unsigned offset = machine.maddr & ~PAGE_MASK;
-	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
-}
 /* VIRT <-> MACHINE conversion */
-#define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
 
+/* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
 {
-	/* TODO: assuming it is mapped in the kernel 1:1 */
-	return virt_to_machine(vaddr);
+	BUG();
 }
 
 /* TODO: this shouldn't be here but it is because the frontend drivers
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
  2015-08-04 18:12 ` Julien Grall
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	linux-arm-kernel

The swiotlb is required when programming a DMA address on ARM when a
device is not protected by an IOMMU.

In this case, the DMA address should always be equal to the machine address.
For DOM0 memory, Xen ensure it by have an identity mapping between the
guest address and host address. However, when mapping a foreign grant
reference, the 1:1 model doesn't work.

For ARM guest, most of the callers of pfn_to_mfn expects to get a GFN
(Guest Frame Number), i.e a PFN (Page Frame Number) from the Linux point
of view given that all ARM guest are auto-translated.

Even though the name pfn_to_mfn is misleading, we need to ensure that
those caller get a GFN and not by mistake a MFN. In pratical, I haven't
seen error related to this but we should fix it for the sake of
correctness.

In order to fix the implementation of pfn_to_mfn on ARM in a follow-up
patch, we have to introduce new helpers to return the DMA from a PFN and
the invert.

On x86, the new helpers will be an alias of pfn_to_mfn and mfn_to_pfn.

The helpers will be used in swiotlb and xen_biovec_phys_mergeable.

This is necessary in the latter because we have to ensure that the
biovec code will not try to merge a biovec using foreign page and
another using Linux memory.

Lastly, the helper mfn_to_local_pfn has been renamed to dnf_to_local_pfn
given that the only usage was in swiotlb.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-arm-kernel@lists.infradead.org

---
    Changes in v2:
        - Use bfn (Bus Frame Number) rather than dfn to match the
        proposed terminology for pv-iommu hypercall.
---
 arch/arm/include/asm/xen/page.h | 23 +++++++++++++++++++++--
 arch/arm/xen/mm.c               |  4 ++--
 arch/x86/include/asm/xen/page.h |  8 ++++++--
 drivers/xen/biomerge.c          |  6 +++---
 drivers/xen/swiotlb-xen.c       | 16 ++++++++--------
 5 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 98b1084..bc5e77c 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -52,7 +52,26 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 	return mfn;
 }
 
-#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
+/* Pseudo-physical <-> BUS conversion */
+static inline unsigned long pfn_to_bfn(unsigned long pfn)
+{
+	unsigned long mfn;
+
+	if (phys_to_mach.rb_node != NULL) {
+		mfn = __pfn_to_mfn(pfn);
+		if (mfn != INVALID_P2M_ENTRY)
+			return mfn;
+	}
+
+	return pfn;
+}
+
+static inline unsigned long bfn_to_pfn(unsigned long bfn)
+{
+	return bfn;
+}
+
+#define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
@@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
-			   unsigned long mfn);
+			   unsigned long dfn);
 unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 03e75fe..12bde72 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -139,9 +139,9 @@ void __xen_dma_sync_single_for_device(struct device *hwdev,
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
-			   unsigned long mfn)
+			   unsigned long dfn)
 {
-	return (!hypercall_cflush && (pfn != mfn) && !is_device_dma_coherent(dev));
+	return (!hypercall_cflush && (pfn != dfn) && !is_device_dma_coherent(dev));
 }
 
 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index c44a5d5..8ba04b8 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -178,6 +178,10 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Bus conversion */
+#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
+#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+
 /*
  * We detect special mappings in one of two ways:
  *  1. If the MFN is an I/O page then Xen will set the m2p entry
@@ -198,7 +202,7 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  *      require. In all the cases we care about, the FOREIGN_FRAME bit is
  *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
  */
-static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
+static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
@@ -264,7 +268,7 @@ void make_lowmem_page_readwrite(void *vaddr);
 
 static inline bool xen_arch_need_swiotlb(struct device *dev,
 					 unsigned long pfn,
-					 unsigned long mfn)
+					 unsigned long bfn)
 {
 	return false;
 }
diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
index 0edb91c..8ae2fc90 100644
--- a/drivers/xen/biomerge.c
+++ b/drivers/xen/biomerge.c
@@ -6,10 +6,10 @@
 bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
 			       const struct bio_vec *vec2)
 {
-	unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page));
-	unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page));
+	unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
+	unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
 
 	return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) &&
-		((mfn1 == mfn2) || ((mfn1+1) == mfn2));
+		((bfn1 == bfn2) || ((bfn1+1) == bfn2));
 }
 EXPORT_SYMBOL(xen_biovec_phys_mergeable);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 4c54932..d757a3e 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -82,8 +82,8 @@ static u64 start_dma_addr;
  */
 static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 {
-	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
-	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
+	unsigned long bfn = pfn_to_bfn(PFN_DOWN(paddr));
+	dma_addr_t dma = (dma_addr_t)bfn << PAGE_SHIFT;
 
 	dma |= paddr & ~PAGE_MASK;
 
@@ -92,7 +92,7 @@ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 
 static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
 {
-	unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr));
+	unsigned long pfn = bfn_to_pfn(PFN_DOWN(baddr));
 	dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT;
 	phys_addr_t paddr = dma;
 
@@ -110,15 +110,15 @@ static int check_pages_physically_contiguous(unsigned long pfn,
 					     unsigned int offset,
 					     size_t length)
 {
-	unsigned long next_mfn;
+	unsigned long next_bfn;
 	int i;
 	int nr_pages;
 
-	next_mfn = pfn_to_mfn(pfn);
+	next_bfn = pfn_to_bfn(pfn);
 	nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
 
 	for (i = 1; i < nr_pages; i++) {
-		if (pfn_to_mfn(++pfn) != ++next_mfn)
+		if (pfn_to_bfn(++pfn) != ++next_bfn)
 			return 0;
 	}
 	return 1;
@@ -138,8 +138,8 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
 
 static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
 {
-	unsigned long mfn = PFN_DOWN(dma_addr);
-	unsigned long pfn = mfn_to_local_pfn(mfn);
+	unsigned long bfn = PFN_DOWN(dma_addr);
+	unsigned long pfn = bfn_to_local_pfn(bfn);
 	phys_addr_t paddr;
 
 	/* If the address is outside our domain, it CAN
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

The swiotlb is required when programming a DMA address on ARM when a
device is not protected by an IOMMU.

In this case, the DMA address should always be equal to the machine address.
For DOM0 memory, Xen ensure it by have an identity mapping between the
guest address and host address. However, when mapping a foreign grant
reference, the 1:1 model doesn't work.

For ARM guest, most of the callers of pfn_to_mfn expects to get a GFN
(Guest Frame Number), i.e a PFN (Page Frame Number) from the Linux point
of view given that all ARM guest are auto-translated.

Even though the name pfn_to_mfn is misleading, we need to ensure that
those caller get a GFN and not by mistake a MFN. In pratical, I haven't
seen error related to this but we should fix it for the sake of
correctness.

In order to fix the implementation of pfn_to_mfn on ARM in a follow-up
patch, we have to introduce new helpers to return the DMA from a PFN and
the invert.

On x86, the new helpers will be an alias of pfn_to_mfn and mfn_to_pfn.

The helpers will be used in swiotlb and xen_biovec_phys_mergeable.

This is necessary in the latter because we have to ensure that the
biovec code will not try to merge a biovec using foreign page and
another using Linux memory.

Lastly, the helper mfn_to_local_pfn has been renamed to dnf_to_local_pfn
given that the only usage was in swiotlb.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86 at kernel.org
Cc: linux-arm-kernel at lists.infradead.org

---
    Changes in v2:
        - Use bfn (Bus Frame Number) rather than dfn to match the
        proposed terminology for pv-iommu hypercall.
---
 arch/arm/include/asm/xen/page.h | 23 +++++++++++++++++++++--
 arch/arm/xen/mm.c               |  4 ++--
 arch/x86/include/asm/xen/page.h |  8 ++++++--
 drivers/xen/biomerge.c          |  6 +++---
 drivers/xen/swiotlb-xen.c       | 16 ++++++++--------
 5 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 98b1084..bc5e77c 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -52,7 +52,26 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 	return mfn;
 }
 
-#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
+/* Pseudo-physical <-> BUS conversion */
+static inline unsigned long pfn_to_bfn(unsigned long pfn)
+{
+	unsigned long mfn;
+
+	if (phys_to_mach.rb_node != NULL) {
+		mfn = __pfn_to_mfn(pfn);
+		if (mfn != INVALID_P2M_ENTRY)
+			return mfn;
+	}
+
+	return pfn;
+}
+
+static inline unsigned long bfn_to_pfn(unsigned long bfn)
+{
+	return bfn;
+}
+
+#define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
@@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
-			   unsigned long mfn);
+			   unsigned long dfn);
 unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 03e75fe..12bde72 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -139,9 +139,9 @@ void __xen_dma_sync_single_for_device(struct device *hwdev,
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
-			   unsigned long mfn)
+			   unsigned long dfn)
 {
-	return (!hypercall_cflush && (pfn != mfn) && !is_device_dma_coherent(dev));
+	return (!hypercall_cflush && (pfn != dfn) && !is_device_dma_coherent(dev));
 }
 
 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index c44a5d5..8ba04b8 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -178,6 +178,10 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Bus conversion */
+#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
+#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+
 /*
  * We detect special mappings in one of two ways:
  *  1. If the MFN is an I/O page then Xen will set the m2p entry
@@ -198,7 +202,7 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  *      require. In all the cases we care about, the FOREIGN_FRAME bit is
  *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
  */
-static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
+static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
@@ -264,7 +268,7 @@ void make_lowmem_page_readwrite(void *vaddr);
 
 static inline bool xen_arch_need_swiotlb(struct device *dev,
 					 unsigned long pfn,
-					 unsigned long mfn)
+					 unsigned long bfn)
 {
 	return false;
 }
diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
index 0edb91c..8ae2fc90 100644
--- a/drivers/xen/biomerge.c
+++ b/drivers/xen/biomerge.c
@@ -6,10 +6,10 @@
 bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
 			       const struct bio_vec *vec2)
 {
-	unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page));
-	unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page));
+	unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
+	unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
 
 	return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) &&
-		((mfn1 == mfn2) || ((mfn1+1) == mfn2));
+		((bfn1 == bfn2) || ((bfn1+1) == bfn2));
 }
 EXPORT_SYMBOL(xen_biovec_phys_mergeable);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 4c54932..d757a3e 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -82,8 +82,8 @@ static u64 start_dma_addr;
  */
 static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 {
-	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
-	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
+	unsigned long bfn = pfn_to_bfn(PFN_DOWN(paddr));
+	dma_addr_t dma = (dma_addr_t)bfn << PAGE_SHIFT;
 
 	dma |= paddr & ~PAGE_MASK;
 
@@ -92,7 +92,7 @@ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 
 static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
 {
-	unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr));
+	unsigned long pfn = bfn_to_pfn(PFN_DOWN(baddr));
 	dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT;
 	phys_addr_t paddr = dma;
 
@@ -110,15 +110,15 @@ static int check_pages_physically_contiguous(unsigned long pfn,
 					     unsigned int offset,
 					     size_t length)
 {
-	unsigned long next_mfn;
+	unsigned long next_bfn;
 	int i;
 	int nr_pages;
 
-	next_mfn = pfn_to_mfn(pfn);
+	next_bfn = pfn_to_bfn(pfn);
 	nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
 
 	for (i = 1; i < nr_pages; i++) {
-		if (pfn_to_mfn(++pfn) != ++next_mfn)
+		if (pfn_to_bfn(++pfn) != ++next_bfn)
 			return 0;
 	}
 	return 1;
@@ -138,8 +138,8 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
 
 static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
 {
-	unsigned long mfn = PFN_DOWN(dma_addr);
-	unsigned long pfn = mfn_to_local_pfn(mfn);
+	unsigned long bfn = PFN_DOWN(dma_addr);
+	unsigned long pfn = bfn_to_local_pfn(bfn);
 	phys_addr_t paddr;
 
 	/* If the address is outside our domain, it CAN
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
  2015-08-04 18:12 ` Julien Grall
                   ` (6 preceding siblings ...)
  (?)
@ 2015-08-04 18:12 ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: x86, Russell King, ian.campbell, stefano.stabellini,
	linux-kernel, Julien Grall, Ingo Molnar, David Vrabel,
	H. Peter Anvin, Boris Ostrovsky, Thomas Gleixner,
	linux-arm-kernel

The swiotlb is required when programming a DMA address on ARM when a
device is not protected by an IOMMU.

In this case, the DMA address should always be equal to the machine address.
For DOM0 memory, Xen ensure it by have an identity mapping between the
guest address and host address. However, when mapping a foreign grant
reference, the 1:1 model doesn't work.

For ARM guest, most of the callers of pfn_to_mfn expects to get a GFN
(Guest Frame Number), i.e a PFN (Page Frame Number) from the Linux point
of view given that all ARM guest are auto-translated.

Even though the name pfn_to_mfn is misleading, we need to ensure that
those caller get a GFN and not by mistake a MFN. In pratical, I haven't
seen error related to this but we should fix it for the sake of
correctness.

In order to fix the implementation of pfn_to_mfn on ARM in a follow-up
patch, we have to introduce new helpers to return the DMA from a PFN and
the invert.

On x86, the new helpers will be an alias of pfn_to_mfn and mfn_to_pfn.

The helpers will be used in swiotlb and xen_biovec_phys_mergeable.

This is necessary in the latter because we have to ensure that the
biovec code will not try to merge a biovec using foreign page and
another using Linux memory.

Lastly, the helper mfn_to_local_pfn has been renamed to dnf_to_local_pfn
given that the only usage was in swiotlb.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-arm-kernel@lists.infradead.org

---
    Changes in v2:
        - Use bfn (Bus Frame Number) rather than dfn to match the
        proposed terminology for pv-iommu hypercall.
---
 arch/arm/include/asm/xen/page.h | 23 +++++++++++++++++++++--
 arch/arm/xen/mm.c               |  4 ++--
 arch/x86/include/asm/xen/page.h |  8 ++++++--
 drivers/xen/biomerge.c          |  6 +++---
 drivers/xen/swiotlb-xen.c       | 16 ++++++++--------
 5 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 98b1084..bc5e77c 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -52,7 +52,26 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 	return mfn;
 }
 
-#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
+/* Pseudo-physical <-> BUS conversion */
+static inline unsigned long pfn_to_bfn(unsigned long pfn)
+{
+	unsigned long mfn;
+
+	if (phys_to_mach.rb_node != NULL) {
+		mfn = __pfn_to_mfn(pfn);
+		if (mfn != INVALID_P2M_ENTRY)
+			return mfn;
+	}
+
+	return pfn;
+}
+
+static inline unsigned long bfn_to_pfn(unsigned long bfn)
+{
+	return bfn;
+}
+
+#define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
@@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
-			   unsigned long mfn);
+			   unsigned long dfn);
 unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 03e75fe..12bde72 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -139,9 +139,9 @@ void __xen_dma_sync_single_for_device(struct device *hwdev,
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
-			   unsigned long mfn)
+			   unsigned long dfn)
 {
-	return (!hypercall_cflush && (pfn != mfn) && !is_device_dma_coherent(dev));
+	return (!hypercall_cflush && (pfn != dfn) && !is_device_dma_coherent(dev));
 }
 
 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index c44a5d5..8ba04b8 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -178,6 +178,10 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Bus conversion */
+#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
+#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+
 /*
  * We detect special mappings in one of two ways:
  *  1. If the MFN is an I/O page then Xen will set the m2p entry
@@ -198,7 +202,7 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  *      require. In all the cases we care about, the FOREIGN_FRAME bit is
  *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
  */
-static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
+static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
@@ -264,7 +268,7 @@ void make_lowmem_page_readwrite(void *vaddr);
 
 static inline bool xen_arch_need_swiotlb(struct device *dev,
 					 unsigned long pfn,
-					 unsigned long mfn)
+					 unsigned long bfn)
 {
 	return false;
 }
diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
index 0edb91c..8ae2fc90 100644
--- a/drivers/xen/biomerge.c
+++ b/drivers/xen/biomerge.c
@@ -6,10 +6,10 @@
 bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
 			       const struct bio_vec *vec2)
 {
-	unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page));
-	unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page));
+	unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
+	unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
 
 	return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) &&
-		((mfn1 == mfn2) || ((mfn1+1) == mfn2));
+		((bfn1 == bfn2) || ((bfn1+1) == bfn2));
 }
 EXPORT_SYMBOL(xen_biovec_phys_mergeable);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 4c54932..d757a3e 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -82,8 +82,8 @@ static u64 start_dma_addr;
  */
 static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 {
-	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
-	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
+	unsigned long bfn = pfn_to_bfn(PFN_DOWN(paddr));
+	dma_addr_t dma = (dma_addr_t)bfn << PAGE_SHIFT;
 
 	dma |= paddr & ~PAGE_MASK;
 
@@ -92,7 +92,7 @@ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
 
 static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
 {
-	unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr));
+	unsigned long pfn = bfn_to_pfn(PFN_DOWN(baddr));
 	dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT;
 	phys_addr_t paddr = dma;
 
@@ -110,15 +110,15 @@ static int check_pages_physically_contiguous(unsigned long pfn,
 					     unsigned int offset,
 					     size_t length)
 {
-	unsigned long next_mfn;
+	unsigned long next_bfn;
 	int i;
 	int nr_pages;
 
-	next_mfn = pfn_to_mfn(pfn);
+	next_bfn = pfn_to_bfn(pfn);
 	nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
 
 	for (i = 1; i < nr_pages; i++) {
-		if (pfn_to_mfn(++pfn) != ++next_mfn)
+		if (pfn_to_bfn(++pfn) != ++next_bfn)
 			return 0;
 	}
 	return 1;
@@ -138,8 +138,8 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
 
 static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
 {
-	unsigned long mfn = PFN_DOWN(dma_addr);
-	unsigned long pfn = mfn_to_local_pfn(mfn);
+	unsigned long bfn = PFN_DOWN(dma_addr);
+	unsigned long pfn = bfn_to_local_pfn(bfn);
 	phys_addr_t paddr;
 
 	/* If the address is outside our domain, it CAN
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn
  2015-08-04 18:12 ` Julien Grall
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	Russell King, linux-arm-kernel

After the commit introducing convertion between DMA and guest address,
all the callers of pfn_to_mfn are expecting to get a GFN (Guest Frame
Number). On ARM, all the guests are auto-translated so the GFN is equal
to the Linux PFN (Pseudo-physical Frame Number).

The current implementation may return an MFN if the caller is passing a
PFN associated to a mapped foreign grant. In pratical, I haven't seen
the problem on running guest but we should fix it for the sake of
correctness.

Correct the implementation by always returning the pfn passed in parameter.

A follow-up patch will take care to rename pfn_to_mfn to a suitable
name.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/arm/include/asm/xen/page.h | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index bc5e77c..087d86e 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -36,14 +36,6 @@ extern struct rb_root phys_to_mach;
 
 static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
-	unsigned long mfn;
-
-	if (phys_to_mach.rb_node != NULL) {
-		mfn = __pfn_to_mfn(pfn);
-		if (mfn != INVALID_P2M_ENTRY)
-			return mfn;
-	}
-
 	return pfn;
 }
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

After the commit introducing convertion between DMA and guest address,
all the callers of pfn_to_mfn are expecting to get a GFN (Guest Frame
Number). On ARM, all the guests are auto-translated so the GFN is equal
to the Linux PFN (Pseudo-physical Frame Number).

The current implementation may return an MFN if the caller is passing a
PFN associated to a mapped foreign grant. In pratical, I haven't seen
the problem on running guest but we should fix it for the sake of
correctness.

Correct the implementation by always returning the pfn passed in parameter.

A follow-up patch will take care to rename pfn_to_mfn to a suitable
name.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel at lists.infradead.org
---
 arch/arm/include/asm/xen/page.h | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index bc5e77c..087d86e 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -36,14 +36,6 @@ extern struct rb_root phys_to_mach;
 
 static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
-	unsigned long mfn;
-
-	if (phys_to_mach.rb_node != NULL) {
-		mfn = __pfn_to_mfn(pfn);
-		if (mfn != INVALID_P2M_ENTRY)
-			return mfn;
-	}
-
 	return pfn;
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn
  2015-08-04 18:12 ` Julien Grall
                   ` (8 preceding siblings ...)
  (?)
@ 2015-08-04 18:12 ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: Russell King, ian.campbell, stefano.stabellini, linux-kernel,
	Julien Grall, linux-arm-kernel

After the commit introducing convertion between DMA and guest address,
all the callers of pfn_to_mfn are expecting to get a GFN (Guest Frame
Number). On ARM, all the guests are auto-translated so the GFN is equal
to the Linux PFN (Pseudo-physical Frame Number).

The current implementation may return an MFN if the caller is passing a
PFN associated to a mapped foreign grant. In pratical, I haven't seen
the problem on running guest but we should fix it for the sake of
correctness.

Correct the implementation by always returning the pfn passed in parameter.

A follow-up patch will take care to rename pfn_to_mfn to a suitable
name.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/arm/include/asm/xen/page.h | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index bc5e77c..087d86e 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -36,14 +36,6 @@ extern struct rb_root phys_to_mach;
 
 static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
-	unsigned long mfn;
-
-	if (phys_to_mach.rb_node != NULL) {
-		mfn = __pfn_to_mfn(pfn);
-		if (mfn != INVALID_P2M_ENTRY)
-			return mfn;
-	}
-
 	return pfn;
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12 ` Julien Grall
                     ` (2 preceding siblings ...)
  (?)
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev, linux-scsi, linuxppc-dev,
	linux-fbdev, linux-arm-kernel

Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
is meant, I suspect this is because the first support for Xen was for
PV. This resulted in some misimplementation of helpers on ARM and
confused developers about the expected behavior.

For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.

For clarity and avoid new confusion, replace any reference to mfn with
gfn in any helpers used by PV drivers. The x86 code will still keep some
reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
to ensure this). No changes as been made in the hypercall field, even
though they may be invalid, in order to keep the same as the defintion
in xen repo.

Take also the opportunity to simplify simple construction such
as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
will come in follow-up patches.

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-input@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org

---
    Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
    The helpers contain a BUG_ON to ensure that it's never called for
    auto-translated guests. I did as best as my can to determine whether
    mfn or gfn helpers should be used. Although, I haven't tried to boot
    it.

    It may be possible to do further cleanup in the mmu.c where I found
    some check to auto-translated. I'm not sure why given that the pvmmu
    callback are only used for non-auto translated guest.

    Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.

    Changes in v2:
        - Give directly the URL to the commit rather than the commit ID
        - xenstored_local_init: keep the cast to void *
        - Typoes
        - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
        used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
        smp.c and mm.c
---
 arch/arm/include/asm/xen/page.h         | 13 +++++++------
 arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 +++---
 drivers/input/misc/xen-kbdfront.c       |  4 ++--
 drivers/net/xen-netback/netback.c       |  4 ++--
 drivers/net/xen-netfront.c              |  8 ++++----
 drivers/scsi/xen-scsifront.c            |  8 +++-----
 drivers/tty/hvc/hvc_xen.c               |  5 +++--
 drivers/video/fbdev/xen-fbfront.c       |  4 ++--
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 ++--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/tmem.c                      |  4 ++--
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
 include/xen/page.h                      |  4 ++--
 20 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 087d86e..51e5bf1 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -34,14 +34,15 @@ typedef struct xpaddr {
 unsigned long __pfn_to_mfn(unsigned long pfn);
 extern struct rb_root phys_to_mach;
 
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
 {
 	return pfn;
 }
 
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
 {
-	return mfn;
+	return gfn;
 }
 
 /* Pseudo-physical <-> BUS conversion */
@@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
 
 #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
-#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
 
 /* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 8ba04b8..c2da42f 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
 	unsigned long mfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return pfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	mfn = __pfn_to_mfn(pfn);
 
@@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return mfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	pfn = mfn_to_pfn_no_overrides(mfn);
 	if (__pfn_to_mfn(pfn) != mfn)
@@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return pfn;
+	else
+		return pfn_to_mfn(pfn);
+}
+
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return gfn;
+	else
+		return mfn_to_pfn(gfn);
+}
+
 /* Pseudo-physical <-> Bus conversion */
-#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
-#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
+#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
 
 /*
  * We detect special mappings in one of two ways:
@@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
-#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
+
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
 
 static inline unsigned long pte_mfn(pte_t pte)
 {
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 8648438..1e0931b 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
 	}
 #endif
 	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
-	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
+	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
 	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
 		BUG();
 
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 6d89ed3..2e541a4 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
                                struct blkfront_info *info)
 {
 	struct grant *gnt_list_entry;
-	unsigned long buffer_mfn;
+	unsigned long buffer_gfn;
 
 	BUG_ON(list_empty(&info->grants));
 	gnt_list_entry = list_first_entry(&info->grants, struct grant,
@@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
 		BUG_ON(!pfn);
 		gnt_list_entry->pfn = pfn;
 	}
-	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
+	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
 	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
 	                                info->xbdev->otherend_id,
-	                                buffer_mfn, 0);
+	                                buffer_gfn, 0);
 	return gnt_list_entry;
 }
 
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 95599e4..23d0549 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 	struct xenbus_transaction xbt;
 
 	ret = gnttab_grant_foreign_access(dev->otherend_id,
-	                                  virt_to_mfn(info->page), 0);
+	                                  virt_to_gfn(info->page), 0);
 	if (ret < 0)
 		return ret;
 	info->gref = ret;
@@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 		goto error_irqh;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 7d50711..3b7b7c3 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
 		} else {
 			copy_gop->source.domid = DOMID_SELF;
 			copy_gop->source.u.gmfn =
-				virt_to_mfn(page_address(page));
+				virt_to_gfn(page_address(page));
 		}
 		copy_gop->source.offset = offset;
 
@@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
 
 		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
-			virt_to_mfn(skb->data);
+			virt_to_gfn(skb->data);
 		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
 		queue->tx_copy_ops[*copy_ops].dest.offset =
 			offset_in_page(skb->data);
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index f948c46..5cdab73 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		struct sk_buff *skb;
 		unsigned short id;
 		grant_ref_t ref;
-		unsigned long pfn;
+		unsigned long gfn;
 		struct xen_netif_rx_request *req;
 
 		skb = xennet_alloc_one_rx_buffer(queue);
@@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		BUG_ON((signed short)ref < 0);
 		queue->grant_rx_ref[id] = ref;
 
-		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
+		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 
 		req = RING_GET_REQUEST(&queue->rx, req_prod);
 		gnttab_grant_foreign_access_ref(ref,
 						queue->info->xbdev->otherend_id,
-						pfn_to_mfn(pfn),
+						gfn,
 						0);
 
 		req->id = id;
@@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
 	BUG_ON((signed short)ref < 0);
 
 	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
-					page_to_mfn(page), GNTMAP_readonly);
+					page_to_gfn(page), GNTMAP_readonly);
 
 	queue->tx_skbs[id].skb = skb;
 	queue->grant_tx_page[id] = page;
diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index fad22ca..cdf00d1 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 	unsigned int data_len = scsi_bufflen(sc);
 	unsigned int data_grants = 0, seg_grants = 0;
 	struct scatterlist *sg;
-	unsigned long mfn;
 	struct scsiif_request_segment *seg;
 
 	ring_req->nr_segments = 0;
@@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, 1);
+				info->dev->otherend_id, page_to_gfn(page), 1);
 			shadow->gref[ref_cnt] = ref;
 			ring_req->seg[ref_cnt].gref   = ref;
 			ring_req->seg[ref_cnt].offset = (uint16_t)off;
@@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, grant_ro);
+				info->dev->otherend_id, page_to_gfn(page),
+				grant_ro);
 
 			shadow->gref[ref_cnt] = ref;
 			seg->gref   = ref;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index a9d837f..efe5124 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
 		return 0;
 	}
 	info->evtchn = xen_start_info->console.domU.evtchn;
-	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
+	/* GFN == MFN for PV guest */
+	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
 	info->vtermno = HVC_COOKIE;
 
 	spin_lock(&xencons_lock);
@@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
 	if (xen_pv_domain())
-		mfn = virt_to_mfn(info->intf);
+		mfn = virt_to_gfn(info->intf);
 	else
 		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 09dc447..25e3cce 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
 
 static unsigned long vmalloc_to_mfn(void *address)
 {
-	return pfn_to_mfn(vmalloc_to_pfn(address));
+	return pfn_to_gfn(vmalloc_to_pfn(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
@@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
 		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index bf4a23c..5df28cd 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 	/* Update direct mapping, invalidate P2M, and add to balloon. */
 	for (i = 0; i < nr_pages; i++) {
 		pfn = frame_list[i];
-		frame_list[i] = pfn_to_mfn(pfn);
+		frame_list[i] = pfn_to_gfn(pfn);
 		page = pfn_to_page(pfn);
 
 #ifdef CONFIG_XEN_HAVE_PVMMU
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 1495ecc..10fd9c6 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
 		struct physdev_pirq_eoi_gmfn eoi_gmfn;
 
 		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
-		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
+		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
 		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
 		/* TODO: No PVH support for PIRQ EOI */
 		if (rc != 0) {
diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 6df8aac..2e55e90 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -111,7 +111,7 @@ static int init_control_block(int cpu,
 	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
 		q->head[i] = 0;
 
-	init_control.control_gfn = virt_to_mfn(control_block);
+	init_control.control_gfn = virt_to_gfn(control_block);
 	init_control.offset      = 0;
 	init_control.vcpu        = cpu;
 
@@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
 		/* Mask all events in this page before adding it. */
 		init_array_page(array_page);
 
-		expand_array.array_gfn = virt_to_mfn(array_page);
+		expand_array.array_gfn = virt_to_gfn(array_page);
 
 		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
 		if (ret < 0)
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index e53fe19..13e1458 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
 
 		/* Grant foreign access to the page. */
 		rc = gnttab_grant_foreign_access(op->domid,
-			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
+						 page_to_gfn(gref->page),
+						 readonly);
 		if (rc < 0)
 			goto undo;
 		gref_ids[i] = gref->gref_id = rc;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index d10effe..e12bd36 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -80,7 +80,7 @@ static int xen_suspend(void *data)
 	 * is resuming in a new domain.
 	 */
 	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
-                                           ? virt_to_mfn(xen_start_info)
+                                           ? virt_to_gfn(xen_start_info)
                                            : 0);
 
 	xen_arch_post_suspend(si->cancelled);
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 239738f..28c97ff 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
@@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 9ad3272..daa267a 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
 
 	for (i = 0; i < nr_pages; i++) {
 		err = gnttab_grant_foreign_access(dev->otherend_id,
-						  virt_to_mfn(vaddr), 0);
+						  virt_to_gfn(vaddr), 0);
 		if (err < 0) {
 			xenbus_dev_fatal(dev, err,
 					 "granting access to ring page");
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
index b17707e..ee6d9ef 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
 		goto out_err;
 
 	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
-			virt_to_mfn(xen_store_interface), 0 /* writable */);
+			virt_to_gfn(xen_store_interface), 0 /* writable */);
 
 	arg.dom = DOMID_SELF;
 	arg.remote_dom = domid;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 4308fb3..b3870f4 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
 	if (!page)
 		goto out_err;
 
-	xen_store_mfn = xen_start_info->store_mfn =
-		pfn_to_mfn(virt_to_phys((void *)page) >>
-			   PAGE_SHIFT);
+	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
 
 	/* Next allocate a local port which xenstored can bind to */
 	alloc_unbound.dom        = DOMID_SELF;
@@ -787,12 +785,12 @@ static int __init xenbus_init(void)
 		err = xenstored_local_init();
 		if (err)
 			goto out_error;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_PV:
 		xen_store_evtchn = xen_start_info->store_evtchn;
 		xen_store_mfn = xen_start_info->store_mfn;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_HVM:
 		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
diff --git a/include/xen/page.h b/include/xen/page.h
index c5ed20b..e7e1425 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -3,9 +3,9 @@
 
 #include <asm/xen/page.h>
 
-static inline unsigned long page_to_mfn(struct page *page)
+static inline unsigned long page_to_gfn(struct page *page)
 {
-	return pfn_to_mfn(page_to_pfn(page));
+	return pfn_to_gfn(page_to_pfn(page));
 }
 
 struct xen_memory_region {
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Thomas Gleixner,
	stefano.stabellini, Russell King, linux-scsi, x86,
	Tomi Valkeinen, linux-input, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, Julien Grall, David Vrabel,
	netdev, linuxppc-dev

Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
is meant, I suspect this is because the first support for Xen was for
PV. This resulted in some misimplementation of helpers on ARM and
confused developers about the expected behavior.

For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.

For clarity and avoid new confusion, replace any reference to mfn with
gfn in any helpers used by PV drivers. The x86 code will still keep some
reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
to ensure this). No changes as been made in the hypercall field, even
though they may be invalid, in order to keep the same as the defintion
in xen repo.

Take also the opportunity to simplify simple construction such
as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
will come in follow-up patches.

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-input@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org

---
    Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
    The helpers contain a BUG_ON to ensure that it's never called for
    auto-translated guests. I did as best as my can to determine whether
    mfn or gfn helpers should be used. Although, I haven't tried to boot
    it.

    It may be possible to do further cleanup in the mmu.c where I found
    some check to auto-translated. I'm not sure why given that the pvmmu
    callback are only used for non-auto translated guest.

    Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.

    Changes in v2:
        - Give directly the URL to the commit rather than the commit ID
        - xenstored_local_init: keep the cast to void *
        - Typoes
        - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
        used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
        smp.c and mm.c
---
 arch/arm/include/asm/xen/page.h         | 13 +++++++------
 arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 +++---
 drivers/input/misc/xen-kbdfront.c       |  4 ++--
 drivers/net/xen-netback/netback.c       |  4 ++--
 drivers/net/xen-netfront.c              |  8 ++++----
 drivers/scsi/xen-scsifront.c            |  8 +++-----
 drivers/tty/hvc/hvc_xen.c               |  5 +++--
 drivers/video/fbdev/xen-fbfront.c       |  4 ++--
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 ++--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/tmem.c                      |  4 ++--
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
 include/xen/page.h                      |  4 ++--
 20 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 087d86e..51e5bf1 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -34,14 +34,15 @@ typedef struct xpaddr {
 unsigned long __pfn_to_mfn(unsigned long pfn);
 extern struct rb_root phys_to_mach;
 
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
 {
 	return pfn;
 }
 
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
 {
-	return mfn;
+	return gfn;
 }
 
 /* Pseudo-physical <-> BUS conversion */
@@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
 
 #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
-#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
 
 /* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 8ba04b8..c2da42f 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
 	unsigned long mfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return pfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	mfn = __pfn_to_mfn(pfn);
 
@@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return mfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	pfn = mfn_to_pfn_no_overrides(mfn);
 	if (__pfn_to_mfn(pfn) != mfn)
@@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return pfn;
+	else
+		return pfn_to_mfn(pfn);
+}
+
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return gfn;
+	else
+		return mfn_to_pfn(gfn);
+}
+
 /* Pseudo-physical <-> Bus conversion */
-#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
-#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
+#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
 
 /*
  * We detect special mappings in one of two ways:
@@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
-#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
+
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
 
 static inline unsigned long pte_mfn(pte_t pte)
 {
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 8648438..1e0931b 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
 	}
 #endif
 	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
-	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
+	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
 	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
 		BUG();
 
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 6d89ed3..2e541a4 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
                                struct blkfront_info *info)
 {
 	struct grant *gnt_list_entry;
-	unsigned long buffer_mfn;
+	unsigned long buffer_gfn;
 
 	BUG_ON(list_empty(&info->grants));
 	gnt_list_entry = list_first_entry(&info->grants, struct grant,
@@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
 		BUG_ON(!pfn);
 		gnt_list_entry->pfn = pfn;
 	}
-	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
+	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
 	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
 	                                info->xbdev->otherend_id,
-	                                buffer_mfn, 0);
+	                                buffer_gfn, 0);
 	return gnt_list_entry;
 }
 
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 95599e4..23d0549 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 	struct xenbus_transaction xbt;
 
 	ret = gnttab_grant_foreign_access(dev->otherend_id,
-	                                  virt_to_mfn(info->page), 0);
+	                                  virt_to_gfn(info->page), 0);
 	if (ret < 0)
 		return ret;
 	info->gref = ret;
@@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 		goto error_irqh;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 7d50711..3b7b7c3 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
 		} else {
 			copy_gop->source.domid = DOMID_SELF;
 			copy_gop->source.u.gmfn =
-				virt_to_mfn(page_address(page));
+				virt_to_gfn(page_address(page));
 		}
 		copy_gop->source.offset = offset;
 
@@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
 
 		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
-			virt_to_mfn(skb->data);
+			virt_to_gfn(skb->data);
 		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
 		queue->tx_copy_ops[*copy_ops].dest.offset =
 			offset_in_page(skb->data);
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index f948c46..5cdab73 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		struct sk_buff *skb;
 		unsigned short id;
 		grant_ref_t ref;
-		unsigned long pfn;
+		unsigned long gfn;
 		struct xen_netif_rx_request *req;
 
 		skb = xennet_alloc_one_rx_buffer(queue);
@@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		BUG_ON((signed short)ref < 0);
 		queue->grant_rx_ref[id] = ref;
 
-		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
+		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 
 		req = RING_GET_REQUEST(&queue->rx, req_prod);
 		gnttab_grant_foreign_access_ref(ref,
 						queue->info->xbdev->otherend_id,
-						pfn_to_mfn(pfn),
+						gfn,
 						0);
 
 		req->id = id;
@@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
 	BUG_ON((signed short)ref < 0);
 
 	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
-					page_to_mfn(page), GNTMAP_readonly);
+					page_to_gfn(page), GNTMAP_readonly);
 
 	queue->tx_skbs[id].skb = skb;
 	queue->grant_tx_page[id] = page;
diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index fad22ca..cdf00d1 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 	unsigned int data_len = scsi_bufflen(sc);
 	unsigned int data_grants = 0, seg_grants = 0;
 	struct scatterlist *sg;
-	unsigned long mfn;
 	struct scsiif_request_segment *seg;
 
 	ring_req->nr_segments = 0;
@@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, 1);
+				info->dev->otherend_id, page_to_gfn(page), 1);
 			shadow->gref[ref_cnt] = ref;
 			ring_req->seg[ref_cnt].gref   = ref;
 			ring_req->seg[ref_cnt].offset = (uint16_t)off;
@@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, grant_ro);
+				info->dev->otherend_id, page_to_gfn(page),
+				grant_ro);
 
 			shadow->gref[ref_cnt] = ref;
 			seg->gref   = ref;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index a9d837f..efe5124 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
 		return 0;
 	}
 	info->evtchn = xen_start_info->console.domU.evtchn;
-	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
+	/* GFN == MFN for PV guest */
+	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
 	info->vtermno = HVC_COOKIE;
 
 	spin_lock(&xencons_lock);
@@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
 	if (xen_pv_domain())
-		mfn = virt_to_mfn(info->intf);
+		mfn = virt_to_gfn(info->intf);
 	else
 		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 09dc447..25e3cce 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
 
 static unsigned long vmalloc_to_mfn(void *address)
 {
-	return pfn_to_mfn(vmalloc_to_pfn(address));
+	return pfn_to_gfn(vmalloc_to_pfn(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
@@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
 		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index bf4a23c..5df28cd 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 	/* Update direct mapping, invalidate P2M, and add to balloon. */
 	for (i = 0; i < nr_pages; i++) {
 		pfn = frame_list[i];
-		frame_list[i] = pfn_to_mfn(pfn);
+		frame_list[i] = pfn_to_gfn(pfn);
 		page = pfn_to_page(pfn);
 
 #ifdef CONFIG_XEN_HAVE_PVMMU
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 1495ecc..10fd9c6 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
 		struct physdev_pirq_eoi_gmfn eoi_gmfn;
 
 		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
-		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
+		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
 		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
 		/* TODO: No PVH support for PIRQ EOI */
 		if (rc != 0) {
diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 6df8aac..2e55e90 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -111,7 +111,7 @@ static int init_control_block(int cpu,
 	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
 		q->head[i] = 0;
 
-	init_control.control_gfn = virt_to_mfn(control_block);
+	init_control.control_gfn = virt_to_gfn(control_block);
 	init_control.offset      = 0;
 	init_control.vcpu        = cpu;
 
@@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
 		/* Mask all events in this page before adding it. */
 		init_array_page(array_page);
 
-		expand_array.array_gfn = virt_to_mfn(array_page);
+		expand_array.array_gfn = virt_to_gfn(array_page);
 
 		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
 		if (ret < 0)
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index e53fe19..13e1458 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
 
 		/* Grant foreign access to the page. */
 		rc = gnttab_grant_foreign_access(op->domid,
-			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
+						 page_to_gfn(gref->page),
+						 readonly);
 		if (rc < 0)
 			goto undo;
 		gref_ids[i] = gref->gref_id = rc;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index d10effe..e12bd36 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -80,7 +80,7 @@ static int xen_suspend(void *data)
 	 * is resuming in a new domain.
 	 */
 	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
-                                           ? virt_to_mfn(xen_start_info)
+                                           ? virt_to_gfn(xen_start_info)
                                            : 0);
 
 	xen_arch_post_suspend(si->cancelled);
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 239738f..28c97ff 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
@@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 9ad3272..daa267a 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
 
 	for (i = 0; i < nr_pages; i++) {
 		err = gnttab_grant_foreign_access(dev->otherend_id,
-						  virt_to_mfn(vaddr), 0);
+						  virt_to_gfn(vaddr), 0);
 		if (err < 0) {
 			xenbus_dev_fatal(dev, err,
 					 "granting access to ring page");
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
index b17707e..ee6d9ef 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
 		goto out_err;
 
 	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
-			virt_to_mfn(xen_store_interface), 0 /* writable */);
+			virt_to_gfn(xen_store_interface), 0 /* writable */);
 
 	arg.dom = DOMID_SELF;
 	arg.remote_dom = domid;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 4308fb3..b3870f4 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
 	if (!page)
 		goto out_err;
 
-	xen_store_mfn = xen_start_info->store_mfn =
-		pfn_to_mfn(virt_to_phys((void *)page) >>
-			   PAGE_SHIFT);
+	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
 
 	/* Next allocate a local port which xenstored can bind to */
 	alloc_unbound.dom        = DOMID_SELF;
@@ -787,12 +785,12 @@ static int __init xenbus_init(void)
 		err = xenstored_local_init();
 		if (err)
 			goto out_error;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_PV:
 		xen_store_evtchn = xen_start_info->store_evtchn;
 		xen_store_mfn = xen_start_info->store_mfn;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_HVM:
 		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
diff --git a/include/xen/page.h b/include/xen/page.h
index c5ed20b..e7e1425 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -3,9 +3,9 @@
 
 #include <asm/xen/page.h>
 
-static inline unsigned long page_to_mfn(struct page *page)
+static inline unsigned long page_to_gfn(struct page *page)
 {
-	return pfn_to_mfn(page_to_pfn(page));
+	return pfn_to_gfn(page_to_pfn(page));
 }
 
 struct xen_memory_region {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Thomas Gleixner,
	stefano.stabellini, Russell King, linux-scsi, x86,
	Tomi Valkeinen, linux-input, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, Julien Grall, David Vrabel,
	netdev, linuxppc-dev

Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
is meant, I suspect this is because the first support for Xen was for
PV. This resulted in some misimplementation of helpers on ARM and
confused developers about the expected behavior.

For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.

For clarity and avoid new confusion, replace any reference to mfn with
gfn in any helpers used by PV drivers. The x86 code will still keep some
reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
to ensure this). No changes as been made in the hypercall field, even
though they may be invalid, in order to keep the same as the defintion
in xen repo.

Take also the opportunity to simplify simple construction such
as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
will come in follow-up patches.

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-input@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org

---
    Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
    The helpers contain a BUG_ON to ensure that it's never called for
    auto-translated guests. I did as best as my can to determine whether
    mfn or gfn helpers should be used. Although, I haven't tried to boot
    it.

    It may be possible to do further cleanup in the mmu.c where I found
    some check to auto-translated. I'm not sure why given that the pvmmu
    callback are only used for non-auto translated guest.

    Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.

    Changes in v2:
        - Give directly the URL to the commit rather than the commit ID
        - xenstored_local_init: keep the cast to void *
        - Typoes
        - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
        used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
        smp.c and mm.c
---
 arch/arm/include/asm/xen/page.h         | 13 +++++++------
 arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 +++---
 drivers/input/misc/xen-kbdfront.c       |  4 ++--
 drivers/net/xen-netback/netback.c       |  4 ++--
 drivers/net/xen-netfront.c              |  8 ++++----
 drivers/scsi/xen-scsifront.c            |  8 +++-----
 drivers/tty/hvc/hvc_xen.c               |  5 +++--
 drivers/video/fbdev/xen-fbfront.c       |  4 ++--
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 ++--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/tmem.c                      |  4 ++--
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
 include/xen/page.h                      |  4 ++--
 20 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 087d86e..51e5bf1 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -34,14 +34,15 @@ typedef struct xpaddr {
 unsigned long __pfn_to_mfn(unsigned long pfn);
 extern struct rb_root phys_to_mach;
 
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
 {
 	return pfn;
 }
 
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
 {
-	return mfn;
+	return gfn;
 }
 
 /* Pseudo-physical <-> BUS conversion */
@@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
 
 #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
-#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
 
 /* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 8ba04b8..c2da42f 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
 	unsigned long mfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return pfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	mfn = __pfn_to_mfn(pfn);
 
@@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return mfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	pfn = mfn_to_pfn_no_overrides(mfn);
 	if (__pfn_to_mfn(pfn) != mfn)
@@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return pfn;
+	else
+		return pfn_to_mfn(pfn);
+}
+
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return gfn;
+	else
+		return mfn_to_pfn(gfn);
+}
+
 /* Pseudo-physical <-> Bus conversion */
-#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
-#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
+#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
 
 /*
  * We detect special mappings in one of two ways:
@@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
-#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
+
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
 
 static inline unsigned long pte_mfn(pte_t pte)
 {
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 8648438..1e0931b 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
 	}
 #endif
 	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
-	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
+	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
 	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
 		BUG();
 
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 6d89ed3..2e541a4 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
                                struct blkfront_info *info)
 {
 	struct grant *gnt_list_entry;
-	unsigned long buffer_mfn;
+	unsigned long buffer_gfn;
 
 	BUG_ON(list_empty(&info->grants));
 	gnt_list_entry = list_first_entry(&info->grants, struct grant,
@@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
 		BUG_ON(!pfn);
 		gnt_list_entry->pfn = pfn;
 	}
-	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
+	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
 	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
 	                                info->xbdev->otherend_id,
-	                                buffer_mfn, 0);
+	                                buffer_gfn, 0);
 	return gnt_list_entry;
 }
 
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 95599e4..23d0549 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 	struct xenbus_transaction xbt;
 
 	ret = gnttab_grant_foreign_access(dev->otherend_id,
-	                                  virt_to_mfn(info->page), 0);
+	                                  virt_to_gfn(info->page), 0);
 	if (ret < 0)
 		return ret;
 	info->gref = ret;
@@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 		goto error_irqh;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 7d50711..3b7b7c3 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
 		} else {
 			copy_gop->source.domid = DOMID_SELF;
 			copy_gop->source.u.gmfn =
-				virt_to_mfn(page_address(page));
+				virt_to_gfn(page_address(page));
 		}
 		copy_gop->source.offset = offset;
 
@@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
 
 		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
-			virt_to_mfn(skb->data);
+			virt_to_gfn(skb->data);
 		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
 		queue->tx_copy_ops[*copy_ops].dest.offset =
 			offset_in_page(skb->data);
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index f948c46..5cdab73 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		struct sk_buff *skb;
 		unsigned short id;
 		grant_ref_t ref;
-		unsigned long pfn;
+		unsigned long gfn;
 		struct xen_netif_rx_request *req;
 
 		skb = xennet_alloc_one_rx_buffer(queue);
@@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		BUG_ON((signed short)ref < 0);
 		queue->grant_rx_ref[id] = ref;
 
-		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
+		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 
 		req = RING_GET_REQUEST(&queue->rx, req_prod);
 		gnttab_grant_foreign_access_ref(ref,
 						queue->info->xbdev->otherend_id,
-						pfn_to_mfn(pfn),
+						gfn,
 						0);
 
 		req->id = id;
@@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
 	BUG_ON((signed short)ref < 0);
 
 	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
-					page_to_mfn(page), GNTMAP_readonly);
+					page_to_gfn(page), GNTMAP_readonly);
 
 	queue->tx_skbs[id].skb = skb;
 	queue->grant_tx_page[id] = page;
diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index fad22ca..cdf00d1 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 	unsigned int data_len = scsi_bufflen(sc);
 	unsigned int data_grants = 0, seg_grants = 0;
 	struct scatterlist *sg;
-	unsigned long mfn;
 	struct scsiif_request_segment *seg;
 
 	ring_req->nr_segments = 0;
@@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, 1);
+				info->dev->otherend_id, page_to_gfn(page), 1);
 			shadow->gref[ref_cnt] = ref;
 			ring_req->seg[ref_cnt].gref   = ref;
 			ring_req->seg[ref_cnt].offset = (uint16_t)off;
@@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, grant_ro);
+				info->dev->otherend_id, page_to_gfn(page),
+				grant_ro);
 
 			shadow->gref[ref_cnt] = ref;
 			seg->gref   = ref;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index a9d837f..efe5124 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
 		return 0;
 	}
 	info->evtchn = xen_start_info->console.domU.evtchn;
-	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
+	/* GFN == MFN for PV guest */
+	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
 	info->vtermno = HVC_COOKIE;
 
 	spin_lock(&xencons_lock);
@@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
 	if (xen_pv_domain())
-		mfn = virt_to_mfn(info->intf);
+		mfn = virt_to_gfn(info->intf);
 	else
 		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 09dc447..25e3cce 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
 
 static unsigned long vmalloc_to_mfn(void *address)
 {
-	return pfn_to_mfn(vmalloc_to_pfn(address));
+	return pfn_to_gfn(vmalloc_to_pfn(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
@@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
 		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index bf4a23c..5df28cd 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 	/* Update direct mapping, invalidate P2M, and add to balloon. */
 	for (i = 0; i < nr_pages; i++) {
 		pfn = frame_list[i];
-		frame_list[i] = pfn_to_mfn(pfn);
+		frame_list[i] = pfn_to_gfn(pfn);
 		page = pfn_to_page(pfn);
 
 #ifdef CONFIG_XEN_HAVE_PVMMU
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 1495ecc..10fd9c6 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
 		struct physdev_pirq_eoi_gmfn eoi_gmfn;
 
 		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
-		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
+		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
 		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
 		/* TODO: No PVH support for PIRQ EOI */
 		if (rc != 0) {
diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 6df8aac..2e55e90 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -111,7 +111,7 @@ static int init_control_block(int cpu,
 	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
 		q->head[i] = 0;
 
-	init_control.control_gfn = virt_to_mfn(control_block);
+	init_control.control_gfn = virt_to_gfn(control_block);
 	init_control.offset      = 0;
 	init_control.vcpu        = cpu;
 
@@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
 		/* Mask all events in this page before adding it. */
 		init_array_page(array_page);
 
-		expand_array.array_gfn = virt_to_mfn(array_page);
+		expand_array.array_gfn = virt_to_gfn(array_page);
 
 		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
 		if (ret < 0)
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index e53fe19..13e1458 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
 
 		/* Grant foreign access to the page. */
 		rc = gnttab_grant_foreign_access(op->domid,
-			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
+						 page_to_gfn(gref->page),
+						 readonly);
 		if (rc < 0)
 			goto undo;
 		gref_ids[i] = gref->gref_id = rc;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index d10effe..e12bd36 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -80,7 +80,7 @@ static int xen_suspend(void *data)
 	 * is resuming in a new domain.
 	 */
 	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
-                                           ? virt_to_mfn(xen_start_info)
+                                           ? virt_to_gfn(xen_start_info)
                                            : 0);
 
 	xen_arch_post_suspend(si->cancelled);
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 239738f..28c97ff 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
@@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 9ad3272..daa267a 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
 
 	for (i = 0; i < nr_pages; i++) {
 		err = gnttab_grant_foreign_access(dev->otherend_id,
-						  virt_to_mfn(vaddr), 0);
+						  virt_to_gfn(vaddr), 0);
 		if (err < 0) {
 			xenbus_dev_fatal(dev, err,
 					 "granting access to ring page");
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
index b17707e..ee6d9ef 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
 		goto out_err;
 
 	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
-			virt_to_mfn(xen_store_interface), 0 /* writable */);
+			virt_to_gfn(xen_store_interface), 0 /* writable */);
 
 	arg.dom = DOMID_SELF;
 	arg.remote_dom = domid;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 4308fb3..b3870f4 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
 	if (!page)
 		goto out_err;
 
-	xen_store_mfn = xen_start_info->store_mfn =
-		pfn_to_mfn(virt_to_phys((void *)page) >>
-			   PAGE_SHIFT);
+	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
 
 	/* Next allocate a local port which xenstored can bind to */
 	alloc_unbound.dom        = DOMID_SELF;
@@ -787,12 +785,12 @@ static int __init xenbus_init(void)
 		err = xenstored_local_init();
 		if (err)
 			goto out_error;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_PV:
 		xen_store_evtchn = xen_start_info->store_evtchn;
 		xen_store_mfn = xen_start_info->store_mfn;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_HVM:
 		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
diff --git a/include/xen/page.h b/include/xen/page.h
index c5ed20b..e7e1425 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -3,9 +3,9 @@
 
 #include <asm/xen/page.h>
 
-static inline unsigned long page_to_mfn(struct page *page)
+static inline unsigned long page_to_gfn(struct page *page)
 {
-	return pfn_to_mfn(page_to_pfn(page));
+	return pfn_to_gfn(page_to_pfn(page));
 }
 
 struct xen_memory_region {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
is meant, I suspect this is because the first support for Xen was for
PV. This resulted in some misimplementation of helpers on ARM and
confused developers about the expected behavior.

For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.

For clarity and avoid new confusion, replace any reference to mfn with
gfn in any helpers used by PV drivers. The x86 code will still keep some
reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
to ensure this). No changes as been made in the hypercall field, even
though they may be invalid, in order to keep the same as the defintion
in xen repo.

Take also the opportunity to simplify simple construction such
as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
will come in follow-up patches.

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;hç58ed14f390342513405dd766e874934573e6cb

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-input@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org

---
    Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
    The helpers contain a BUG_ON to ensure that it's never called for
    auto-translated guests. I did as best as my can to determine whether
    mfn or gfn helpers should be used. Although, I haven't tried to boot
    it.

    It may be possible to do further cleanup in the mmu.c where I found
    some check to auto-translated. I'm not sure why given that the pvmmu
    callback are only used for non-auto translated guest.

    Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.

    Changes in v2:
        - Give directly the URL to the commit rather than the commit ID
        - xenstored_local_init: keep the cast to void *
        - Typoes
        - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
        used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
        smp.c and mm.c
---
 arch/arm/include/asm/xen/page.h         | 13 +++++++------
 arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 +++---
 drivers/input/misc/xen-kbdfront.c       |  4 ++--
 drivers/net/xen-netback/netback.c       |  4 ++--
 drivers/net/xen-netfront.c              |  8 ++++----
 drivers/scsi/xen-scsifront.c            |  8 +++-----
 drivers/tty/hvc/hvc_xen.c               |  5 +++--
 drivers/video/fbdev/xen-fbfront.c       |  4 ++--
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 ++--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/tmem.c                      |  4 ++--
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
 include/xen/page.h                      |  4 ++--
 20 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 087d86e..51e5bf1 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -34,14 +34,15 @@ typedef struct xpaddr {
 unsigned long __pfn_to_mfn(unsigned long pfn);
 extern struct rb_root phys_to_mach;
 
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
 {
 	return pfn;
 }
 
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
 {
-	return mfn;
+	return gfn;
 }
 
 /* Pseudo-physical <-> BUS conversion */
@@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
 
 #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
-#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
 
 /* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 8ba04b8..c2da42f 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
 	unsigned long mfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return pfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	mfn = __pfn_to_mfn(pfn);
 
@@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return mfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	pfn = mfn_to_pfn_no_overrides(mfn);
 	if (__pfn_to_mfn(pfn) != mfn)
@@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return pfn;
+	else
+		return pfn_to_mfn(pfn);
+}
+
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return gfn;
+	else
+		return mfn_to_pfn(gfn);
+}
+
 /* Pseudo-physical <-> Bus conversion */
-#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
-#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
+#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
 
 /*
  * We detect special mappings in one of two ways:
@@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
-#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
+
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
 
 static inline unsigned long pte_mfn(pte_t pte)
 {
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 8648438..1e0931b 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
 	}
 #endif
 	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
-	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
+	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
 	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
 		BUG();
 
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 6d89ed3..2e541a4 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
                                struct blkfront_info *info)
 {
 	struct grant *gnt_list_entry;
-	unsigned long buffer_mfn;
+	unsigned long buffer_gfn;
 
 	BUG_ON(list_empty(&info->grants));
 	gnt_list_entry = list_first_entry(&info->grants, struct grant,
@@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
 		BUG_ON(!pfn);
 		gnt_list_entry->pfn = pfn;
 	}
-	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
+	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
 	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
 	                                info->xbdev->otherend_id,
-	                                buffer_mfn, 0);
+	                                buffer_gfn, 0);
 	return gnt_list_entry;
 }
 
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 95599e4..23d0549 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 	struct xenbus_transaction xbt;
 
 	ret = gnttab_grant_foreign_access(dev->otherend_id,
-	                                  virt_to_mfn(info->page), 0);
+	                                  virt_to_gfn(info->page), 0);
 	if (ret < 0)
 		return ret;
 	info->gref = ret;
@@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 		goto error_irqh;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 7d50711..3b7b7c3 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
 		} else {
 			copy_gop->source.domid = DOMID_SELF;
 			copy_gop->source.u.gmfn -				virt_to_mfn(page_address(page));
+				virt_to_gfn(page_address(page));
 		}
 		copy_gop->source.offset = offset;
 
@@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
 
 		queue->tx_copy_ops[*copy_ops].dest.u.gmfn -			virt_to_mfn(skb->data);
+			virt_to_gfn(skb->data);
 		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
 		queue->tx_copy_ops[*copy_ops].dest.offset  			offset_in_page(skb->data);
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index f948c46..5cdab73 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		struct sk_buff *skb;
 		unsigned short id;
 		grant_ref_t ref;
-		unsigned long pfn;
+		unsigned long gfn;
 		struct xen_netif_rx_request *req;
 
 		skb = xennet_alloc_one_rx_buffer(queue);
@@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		BUG_ON((signed short)ref < 0);
 		queue->grant_rx_ref[id] = ref;
 
-		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
+		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 
 		req = RING_GET_REQUEST(&queue->rx, req_prod);
 		gnttab_grant_foreign_access_ref(ref,
 						queue->info->xbdev->otherend_id,
-						pfn_to_mfn(pfn),
+						gfn,
 						0);
 
 		req->id = id;
@@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
 	BUG_ON((signed short)ref < 0);
 
 	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
-					page_to_mfn(page), GNTMAP_readonly);
+					page_to_gfn(page), GNTMAP_readonly);
 
 	queue->tx_skbs[id].skb = skb;
 	queue->grant_tx_page[id] = page;
diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index fad22ca..cdf00d1 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 	unsigned int data_len = scsi_bufflen(sc);
 	unsigned int data_grants = 0, seg_grants = 0;
 	struct scatterlist *sg;
-	unsigned long mfn;
 	struct scsiif_request_segment *seg;
 
 	ring_req->nr_segments = 0;
@@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref = -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, 1);
+				info->dev->otherend_id, page_to_gfn(page), 1);
 			shadow->gref[ref_cnt] = ref;
 			ring_req->seg[ref_cnt].gref   = ref;
 			ring_req->seg[ref_cnt].offset = (uint16_t)off;
@@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref = -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, grant_ro);
+				info->dev->otherend_id, page_to_gfn(page),
+				grant_ro);
 
 			shadow->gref[ref_cnt] = ref;
 			seg->gref   = ref;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index a9d837f..efe5124 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
 		return 0;
 	}
 	info->evtchn = xen_start_info->console.domU.evtchn;
-	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
+	/* GFN = MFN for PV guest */
+	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
 	info->vtermno = HVC_COOKIE;
 
 	spin_lock(&xencons_lock);
@@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
 	if (xen_pv_domain())
-		mfn = virt_to_mfn(info->intf);
+		mfn = virt_to_gfn(info->intf);
 	else
 		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 09dc447..25e3cce 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
 
 static unsigned long vmalloc_to_mfn(void *address)
 {
-	return pfn_to_mfn(vmalloc_to_pfn(address));
+	return pfn_to_gfn(vmalloc_to_pfn(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
@@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
 		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index bf4a23c..5df28cd 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 	/* Update direct mapping, invalidate P2M, and add to balloon. */
 	for (i = 0; i < nr_pages; i++) {
 		pfn = frame_list[i];
-		frame_list[i] = pfn_to_mfn(pfn);
+		frame_list[i] = pfn_to_gfn(pfn);
 		page = pfn_to_page(pfn);
 
 #ifdef CONFIG_XEN_HAVE_PVMMU
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 1495ecc..10fd9c6 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
 		struct physdev_pirq_eoi_gmfn eoi_gmfn;
 
 		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
-		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
+		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
 		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
 		/* TODO: No PVH support for PIRQ EOI */
 		if (rc != 0) {
diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 6df8aac..2e55e90 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -111,7 +111,7 @@ static int init_control_block(int cpu,
 	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
 		q->head[i] = 0;
 
-	init_control.control_gfn = virt_to_mfn(control_block);
+	init_control.control_gfn = virt_to_gfn(control_block);
 	init_control.offset      = 0;
 	init_control.vcpu        = cpu;
 
@@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
 		/* Mask all events in this page before adding it. */
 		init_array_page(array_page);
 
-		expand_array.array_gfn = virt_to_mfn(array_page);
+		expand_array.array_gfn = virt_to_gfn(array_page);
 
 		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
 		if (ret < 0)
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index e53fe19..13e1458 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
 
 		/* Grant foreign access to the page. */
 		rc = gnttab_grant_foreign_access(op->domid,
-			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
+						 page_to_gfn(gref->page),
+						 readonly);
 		if (rc < 0)
 			goto undo;
 		gref_ids[i] = gref->gref_id = rc;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index d10effe..e12bd36 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -80,7 +80,7 @@ static int xen_suspend(void *data)
 	 * is resuming in a new domain.
 	 */
 	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
-                                           ? virt_to_mfn(xen_start_info)
+                                           ? virt_to_gfn(xen_start_info)
                                            : 0);
 
 	xen_arch_post_suspend(si->cancelled);
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 239738f..28c97ff 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
@@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 9ad3272..daa267a 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
 
 	for (i = 0; i < nr_pages; i++) {
 		err = gnttab_grant_foreign_access(dev->otherend_id,
-						  virt_to_mfn(vaddr), 0);
+						  virt_to_gfn(vaddr), 0);
 		if (err < 0) {
 			xenbus_dev_fatal(dev, err,
 					 "granting access to ring page");
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
index b17707e..ee6d9ef 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
 		goto out_err;
 
 	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
-			virt_to_mfn(xen_store_interface), 0 /* writable */);
+			virt_to_gfn(xen_store_interface), 0 /* writable */);
 
 	arg.dom = DOMID_SELF;
 	arg.remote_dom = domid;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 4308fb3..b3870f4 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
 	if (!page)
 		goto out_err;
 
-	xen_store_mfn = xen_start_info->store_mfn -		pfn_to_mfn(virt_to_phys((void *)page) >>
-			   PAGE_SHIFT);
+	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
 
 	/* Next allocate a local port which xenstored can bind to */
 	alloc_unbound.dom        = DOMID_SELF;
@@ -787,12 +785,12 @@ static int __init xenbus_init(void)
 		err = xenstored_local_init();
 		if (err)
 			goto out_error;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_PV:
 		xen_store_evtchn = xen_start_info->store_evtchn;
 		xen_store_mfn = xen_start_info->store_mfn;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_HVM:
 		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
diff --git a/include/xen/page.h b/include/xen/page.h
index c5ed20b..e7e1425 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -3,9 +3,9 @@
 
 #include <asm/xen/page.h>
 
-static inline unsigned long page_to_mfn(struct page *page)
+static inline unsigned long page_to_gfn(struct page *page)
 {
-	return pfn_to_mfn(page_to_pfn(page));
+	return pfn_to_gfn(page_to_pfn(page));
 }
 
 struct xen_memory_region {
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
is meant, I suspect this is because the first support for Xen was for
PV. This resulted in some misimplementation of helpers on ARM and
confused developers about the expected behavior.

For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.

For clarity and avoid new confusion, replace any reference to mfn with
gfn in any helpers used by PV drivers. The x86 code will still keep some
reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
to ensure this). No changes as been made in the hypercall field, even
though they may be invalid, in order to keep the same as the defintion
in xen repo.

Take also the opportunity to simplify simple construction such
as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
will come in follow-up patches.

[1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86 at kernel.org
Cc: "Roger Pau Monn?" <roger.pau@citrix.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-input at vger.kernel.org
Cc: netdev at vger.kernel.org
Cc: linux-scsi at vger.kernel.org
Cc: linuxppc-dev at lists.ozlabs.org
Cc: linux-fbdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org

---
    Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
    The helpers contain a BUG_ON to ensure that it's never called for
    auto-translated guests. I did as best as my can to determine whether
    mfn or gfn helpers should be used. Although, I haven't tried to boot
    it.

    It may be possible to do further cleanup in the mmu.c where I found
    some check to auto-translated. I'm not sure why given that the pvmmu
    callback are only used for non-auto translated guest.

    Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.

    Changes in v2:
        - Give directly the URL to the commit rather than the commit ID
        - xenstored_local_init: keep the cast to void *
        - Typoes
        - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
        used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
        smp.c and mm.c
---
 arch/arm/include/asm/xen/page.h         | 13 +++++++------
 arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
 arch/x86/xen/smp.c                      |  2 +-
 drivers/block/xen-blkfront.c            |  6 +++---
 drivers/input/misc/xen-kbdfront.c       |  4 ++--
 drivers/net/xen-netback/netback.c       |  4 ++--
 drivers/net/xen-netfront.c              |  8 ++++----
 drivers/scsi/xen-scsifront.c            |  8 +++-----
 drivers/tty/hvc/hvc_xen.c               |  5 +++--
 drivers/video/fbdev/xen-fbfront.c       |  4 ++--
 drivers/xen/balloon.c                   |  2 +-
 drivers/xen/events/events_base.c        |  2 +-
 drivers/xen/events/events_fifo.c        |  4 ++--
 drivers/xen/gntalloc.c                  |  3 ++-
 drivers/xen/manage.c                    |  2 +-
 drivers/xen/tmem.c                      |  4 ++--
 drivers/xen/xenbus/xenbus_client.c      |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
 include/xen/page.h                      |  4 ++--
 20 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 087d86e..51e5bf1 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -34,14 +34,15 @@ typedef struct xpaddr {
 unsigned long __pfn_to_mfn(unsigned long pfn);
 extern struct rb_root phys_to_mach;
 
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
 {
 	return pfn;
 }
 
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
 {
-	return mfn;
+	return gfn;
 }
 
 /* Pseudo-physical <-> BUS conversion */
@@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
 
 #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
-#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
 
 /* Only used in PV code. But ARM guests are always HVM. */
 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 8ba04b8..c2da42f 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
 	unsigned long mfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return pfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	mfn = __pfn_to_mfn(pfn);
 
@@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 {
 	unsigned long pfn;
 
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return mfn;
+	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
 
 	pfn = mfn_to_pfn_no_overrides(mfn);
 	if (__pfn_to_mfn(pfn) != mfn)
@@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
 	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
 }
 
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return pfn;
+	else
+		return pfn_to_mfn(pfn);
+}
+
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
+{
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return gfn;
+	else
+		return mfn_to_pfn(gfn);
+}
+
 /* Pseudo-physical <-> Bus conversion */
-#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
-#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
+#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
+#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
 
 /*
  * We detect special mappings in one of two ways:
@@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
 
 /* VIRT <-> MACHINE conversion */
 #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
-#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
 #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
 #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
+
+/* VIRT <-> GUEST conversion */
+#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
+#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
 
 static inline unsigned long pte_mfn(pte_t pte)
 {
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 8648438..1e0931b 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
 	}
 #endif
 	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
-	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
+	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
 	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
 		BUG();
 
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 6d89ed3..2e541a4 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
                                struct blkfront_info *info)
 {
 	struct grant *gnt_list_entry;
-	unsigned long buffer_mfn;
+	unsigned long buffer_gfn;
 
 	BUG_ON(list_empty(&info->grants));
 	gnt_list_entry = list_first_entry(&info->grants, struct grant,
@@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
 		BUG_ON(!pfn);
 		gnt_list_entry->pfn = pfn;
 	}
-	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
+	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
 	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
 	                                info->xbdev->otherend_id,
-	                                buffer_mfn, 0);
+	                                buffer_gfn, 0);
 	return gnt_list_entry;
 }
 
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 95599e4..23d0549 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 	struct xenbus_transaction xbt;
 
 	ret = gnttab_grant_foreign_access(dev->otherend_id,
-	                                  virt_to_mfn(info->page), 0);
+	                                  virt_to_gfn(info->page), 0);
 	if (ret < 0)
 		return ret;
 	info->gref = ret;
@@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
 		goto error_irqh;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 7d50711..3b7b7c3 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
 		} else {
 			copy_gop->source.domid = DOMID_SELF;
 			copy_gop->source.u.gmfn =
-				virt_to_mfn(page_address(page));
+				virt_to_gfn(page_address(page));
 		}
 		copy_gop->source.offset = offset;
 
@@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
 
 		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
-			virt_to_mfn(skb->data);
+			virt_to_gfn(skb->data);
 		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
 		queue->tx_copy_ops[*copy_ops].dest.offset =
 			offset_in_page(skb->data);
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index f948c46..5cdab73 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		struct sk_buff *skb;
 		unsigned short id;
 		grant_ref_t ref;
-		unsigned long pfn;
+		unsigned long gfn;
 		struct xen_netif_rx_request *req;
 
 		skb = xennet_alloc_one_rx_buffer(queue);
@@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 		BUG_ON((signed short)ref < 0);
 		queue->grant_rx_ref[id] = ref;
 
-		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
+		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 
 		req = RING_GET_REQUEST(&queue->rx, req_prod);
 		gnttab_grant_foreign_access_ref(ref,
 						queue->info->xbdev->otherend_id,
-						pfn_to_mfn(pfn),
+						gfn,
 						0);
 
 		req->id = id;
@@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
 	BUG_ON((signed short)ref < 0);
 
 	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
-					page_to_mfn(page), GNTMAP_readonly);
+					page_to_gfn(page), GNTMAP_readonly);
 
 	queue->tx_skbs[id].skb = skb;
 	queue->grant_tx_page[id] = page;
diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index fad22ca..cdf00d1 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 	unsigned int data_len = scsi_bufflen(sc);
 	unsigned int data_grants = 0, seg_grants = 0;
 	struct scatterlist *sg;
-	unsigned long mfn;
 	struct scsiif_request_segment *seg;
 
 	ring_req->nr_segments = 0;
@@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, 1);
+				info->dev->otherend_id, page_to_gfn(page), 1);
 			shadow->gref[ref_cnt] = ref;
 			ring_req->seg[ref_cnt].gref   = ref;
 			ring_req->seg[ref_cnt].offset = (uint16_t)off;
@@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
 			ref = gnttab_claim_grant_reference(&gref_head);
 			BUG_ON(ref == -ENOSPC);
 
-			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-				info->dev->otherend_id, mfn, grant_ro);
+				info->dev->otherend_id, page_to_gfn(page),
+				grant_ro);
 
 			shadow->gref[ref_cnt] = ref;
 			seg->gref   = ref;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index a9d837f..efe5124 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
 		return 0;
 	}
 	info->evtchn = xen_start_info->console.domU.evtchn;
-	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
+	/* GFN == MFN for PV guest */
+	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
 	info->vtermno = HVC_COOKIE;
 
 	spin_lock(&xencons_lock);
@@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
 	if (xen_pv_domain())
-		mfn = virt_to_mfn(info->intf);
+		mfn = virt_to_gfn(info->intf);
 	else
 		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 09dc447..25e3cce 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
 
 static unsigned long vmalloc_to_mfn(void *address)
 {
-	return pfn_to_mfn(vmalloc_to_pfn(address));
+	return pfn_to_gfn(vmalloc_to_pfn(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
@@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
 		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
-			    virt_to_mfn(info->page));
+			    virt_to_gfn(info->page));
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index bf4a23c..5df28cd 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 	/* Update direct mapping, invalidate P2M, and add to balloon. */
 	for (i = 0; i < nr_pages; i++) {
 		pfn = frame_list[i];
-		frame_list[i] = pfn_to_mfn(pfn);
+		frame_list[i] = pfn_to_gfn(pfn);
 		page = pfn_to_page(pfn);
 
 #ifdef CONFIG_XEN_HAVE_PVMMU
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 1495ecc..10fd9c6 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
 		struct physdev_pirq_eoi_gmfn eoi_gmfn;
 
 		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
-		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
+		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
 		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
 		/* TODO: No PVH support for PIRQ EOI */
 		if (rc != 0) {
diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 6df8aac..2e55e90 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -111,7 +111,7 @@ static int init_control_block(int cpu,
 	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
 		q->head[i] = 0;
 
-	init_control.control_gfn = virt_to_mfn(control_block);
+	init_control.control_gfn = virt_to_gfn(control_block);
 	init_control.offset      = 0;
 	init_control.vcpu        = cpu;
 
@@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
 		/* Mask all events in this page before adding it. */
 		init_array_page(array_page);
 
-		expand_array.array_gfn = virt_to_mfn(array_page);
+		expand_array.array_gfn = virt_to_gfn(array_page);
 
 		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
 		if (ret < 0)
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index e53fe19..13e1458 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
 
 		/* Grant foreign access to the page. */
 		rc = gnttab_grant_foreign_access(op->domid,
-			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
+						 page_to_gfn(gref->page),
+						 readonly);
 		if (rc < 0)
 			goto undo;
 		gref_ids[i] = gref->gref_id = rc;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index d10effe..e12bd36 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -80,7 +80,7 @@ static int xen_suspend(void *data)
 	 * is resuming in a new domain.
 	 */
 	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
-                                           ? virt_to_mfn(xen_start_info)
+                                           ? virt_to_gfn(xen_start_info)
                                            : 0);
 
 	xen_arch_post_suspend(si->cancelled);
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 239738f..28c97ff 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
@@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
 			     u32 index, unsigned long pfn)
 {
-	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
+	unsigned long gmfn = pfn_to_gfn(pfn);
 
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
 		gmfn, 0, 0, 0);
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 9ad3272..daa267a 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
 
 	for (i = 0; i < nr_pages; i++) {
 		err = gnttab_grant_foreign_access(dev->otherend_id,
-						  virt_to_mfn(vaddr), 0);
+						  virt_to_gfn(vaddr), 0);
 		if (err < 0) {
 			xenbus_dev_fatal(dev, err,
 					 "granting access to ring page");
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
index b17707e..ee6d9ef 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
 		goto out_err;
 
 	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
-			virt_to_mfn(xen_store_interface), 0 /* writable */);
+			virt_to_gfn(xen_store_interface), 0 /* writable */);
 
 	arg.dom = DOMID_SELF;
 	arg.remote_dom = domid;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 4308fb3..b3870f4 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
 	if (!page)
 		goto out_err;
 
-	xen_store_mfn = xen_start_info->store_mfn =
-		pfn_to_mfn(virt_to_phys((void *)page) >>
-			   PAGE_SHIFT);
+	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
 
 	/* Next allocate a local port which xenstored can bind to */
 	alloc_unbound.dom        = DOMID_SELF;
@@ -787,12 +785,12 @@ static int __init xenbus_init(void)
 		err = xenstored_local_init();
 		if (err)
 			goto out_error;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_PV:
 		xen_store_evtchn = xen_start_info->store_evtchn;
 		xen_store_mfn = xen_start_info->store_mfn;
-		xen_store_interface = mfn_to_virt(xen_store_mfn);
+		xen_store_interface = gfn_to_virt(xen_store_mfn);
 		break;
 	case XS_HVM:
 		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
diff --git a/include/xen/page.h b/include/xen/page.h
index c5ed20b..e7e1425 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -3,9 +3,9 @@
 
 #include <asm/xen/page.h>
 
-static inline unsigned long page_to_mfn(struct page *page)
+static inline unsigned long page_to_gfn(struct page *page)
 {
-	return pfn_to_mfn(page_to_pfn(page));
+	return pfn_to_gfn(page_to_pfn(page));
 }
 
 struct xen_memory_region {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  2015-08-04 18:12 ` Julien Grall
                   ` (10 preceding siblings ...)
  (?)
@ 2015-08-04 18:12 ` Julien Grall
  2015-08-05 10:01   ` Stefano Stabellini
  2015-08-05 10:01   ` Stefano Stabellini
  -1 siblings, 2 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	Konrad Rzeszutek Wilk, Boris Ostrovsky, David Vrabel

All the caller of xen_tmem_{get,put}_page have a struct page * in hand
and call pfn_to_gfn for the only benefits of these 2 functions.

Rather than passing the pfn in parameter, pass directly the page and use
directly page_to_gfn.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/tmem.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 28c97ff..e0c8dc7 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -129,21 +129,17 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 /* xen generic tmem ops */
 
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
-			     u32 index, unsigned long pfn)
+			     u32 index, struct page *page)
 {
-	unsigned long gmfn = pfn_to_gfn(pfn);
-
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
-		gmfn, 0, 0, 0);
+			   page_to_gfn(page), 0, 0, 0);
 }
 
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
-			     u32 index, unsigned long pfn)
+			     u32 index, struct page *page)
 {
-	unsigned long gmfn = pfn_to_gfn(pfn);
-
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
-		gmfn, 0, 0, 0);
+			   page_to_gfn(page), 0, 0, 0);
 }
 
 static int xen_tmem_flush_page(u32 pool_id, struct tmem_oid oid, u32 index)
@@ -173,14 +169,13 @@ static void tmem_cleancache_put_page(int pool, struct cleancache_filekey key,
 {
 	u32 ind = (u32) index;
 	struct tmem_oid oid = *(struct tmem_oid *)&key;
-	unsigned long pfn = page_to_pfn(page);
 
 	if (pool < 0)
 		return;
 	if (ind != index)
 		return;
 	mb(); /* ensure page is quiescent; tmem may address it with an alias */
-	(void)xen_tmem_put_page((u32)pool, oid, ind, pfn);
+	(void)xen_tmem_put_page((u32)pool, oid, ind, page);
 }
 
 static int tmem_cleancache_get_page(int pool, struct cleancache_filekey key,
@@ -287,7 +282,6 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
 {
 	u64 ind64 = (u64)offset;
 	u32 ind = (u32)offset;
-	unsigned long pfn = page_to_pfn(page);
 	int pool = tmem_frontswap_poolid;
 	int ret;
 
@@ -296,7 +290,7 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
 	if (ind64 != ind)
 		return -1;
 	mb(); /* ensure page is quiescent; tmem may address it with an alias */
-	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), pfn);
+	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), page);
 	/* translate Xen tmem return values to linux semantics */
 	if (ret == 1)
 		return 0;
@@ -313,7 +307,6 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
 {
 	u64 ind64 = (u64)offset;
 	u32 ind = (u32)offset;
-	unsigned long pfn = page_to_pfn(page);
 	int pool = tmem_frontswap_poolid;
 	int ret;
 
@@ -321,7 +314,7 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
 		return -1;
 	if (ind64 != ind)
 		return -1;
-	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), pfn);
+	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), page);
 	/* translate Xen tmem return values to linux semantics */
 	if (ret == 1)
 		return 0;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  2015-08-04 18:12 ` Julien Grall
                   ` (11 preceding siblings ...)
  (?)
@ 2015-08-04 18:12 ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	David Vrabel, Boris Ostrovsky

All the caller of xen_tmem_{get,put}_page have a struct page * in hand
and call pfn_to_gfn for the only benefits of these 2 functions.

Rather than passing the pfn in parameter, pass directly the page and use
directly page_to_gfn.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/tmem.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index 28c97ff..e0c8dc7 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -129,21 +129,17 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
 /* xen generic tmem ops */
 
 static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
-			     u32 index, unsigned long pfn)
+			     u32 index, struct page *page)
 {
-	unsigned long gmfn = pfn_to_gfn(pfn);
-
 	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
-		gmfn, 0, 0, 0);
+			   page_to_gfn(page), 0, 0, 0);
 }
 
 static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
-			     u32 index, unsigned long pfn)
+			     u32 index, struct page *page)
 {
-	unsigned long gmfn = pfn_to_gfn(pfn);
-
 	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
-		gmfn, 0, 0, 0);
+			   page_to_gfn(page), 0, 0, 0);
 }
 
 static int xen_tmem_flush_page(u32 pool_id, struct tmem_oid oid, u32 index)
@@ -173,14 +169,13 @@ static void tmem_cleancache_put_page(int pool, struct cleancache_filekey key,
 {
 	u32 ind = (u32) index;
 	struct tmem_oid oid = *(struct tmem_oid *)&key;
-	unsigned long pfn = page_to_pfn(page);
 
 	if (pool < 0)
 		return;
 	if (ind != index)
 		return;
 	mb(); /* ensure page is quiescent; tmem may address it with an alias */
-	(void)xen_tmem_put_page((u32)pool, oid, ind, pfn);
+	(void)xen_tmem_put_page((u32)pool, oid, ind, page);
 }
 
 static int tmem_cleancache_get_page(int pool, struct cleancache_filekey key,
@@ -287,7 +282,6 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
 {
 	u64 ind64 = (u64)offset;
 	u32 ind = (u32)offset;
-	unsigned long pfn = page_to_pfn(page);
 	int pool = tmem_frontswap_poolid;
 	int ret;
 
@@ -296,7 +290,7 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
 	if (ind64 != ind)
 		return -1;
 	mb(); /* ensure page is quiescent; tmem may address it with an alias */
-	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), pfn);
+	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), page);
 	/* translate Xen tmem return values to linux semantics */
 	if (ret == 1)
 		return 0;
@@ -313,7 +307,6 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
 {
 	u64 ind64 = (u64)offset;
 	u32 ind = (u32)offset;
-	unsigned long pfn = page_to_pfn(page);
 	int pool = tmem_frontswap_poolid;
 	int ret;
 
@@ -321,7 +314,7 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
 		return -1;
 	if (ind64 != ind)
 		return -1;
-	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), pfn);
+	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), page);
 	/* translate Xen tmem return values to linux semantics */
 	if (ret == 1)
 		return 0;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 6/8] video/xen-fbfront: Further s/MFN/GFN clean-up
  2015-08-04 18:12 ` Julien Grall
  (?)
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	David Vrabel, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	linux-fbdev

The PV driver xen-fbfront is only dealing with GFN and not MFN. Rename
all the occurence of MFN to GFN.

Also take the opportunity to replace to usage of pfn_to_gfn by
page_to_pfn.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-fbdev@vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 drivers/video/fbdev/xen-fbfront.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 25e3cce..3112168 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -46,7 +46,7 @@ struct xenfb_info {
 	int			nr_pages;
 	int			irq;
 	struct xenfb_page	*page;
-	unsigned long 		*mfns;
+	unsigned long 		*gfns;
 	int			update_wanted; /* XENFB_TYPE_UPDATE wanted */
 	int			feature_resize; /* XENFB_TYPE_RESIZE ok */
 	struct xenfb_resize	resize;		/* protected by resize_lock */
@@ -402,8 +402,8 @@ static int xenfb_probe(struct xenbus_device *dev,
 
 	info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-	info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
-	if (!info->mfns)
+	info->gfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
+	if (!info->gfns)
 		goto error_nomem;
 
 	/* set up shared page */
@@ -530,29 +530,29 @@ static int xenfb_remove(struct xenbus_device *dev)
 		framebuffer_release(info->fb_info);
 	}
 	free_page((unsigned long)info->page);
-	vfree(info->mfns);
+	vfree(info->gfns);
 	vfree(info->fb);
 	kfree(info);
 
 	return 0;
 }
 
-static unsigned long vmalloc_to_mfn(void *address)
+static unsigned long vmalloc_to_gfn(void *address)
 {
-	return pfn_to_gfn(vmalloc_to_pfn(address));
+	return page_to_gfn(vmalloc_to_page(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
 				   struct fb_info *fb_info)
 {
 	int i;
-	int epd = PAGE_SIZE / sizeof(info->mfns[0]);
+	int epd = PAGE_SIZE / sizeof(info->gfns[0]);
 
 	for (i = 0; i < info->nr_pages; i++)
-		info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
+		info->gfns[i] = vmalloc_to_gfn(info->fb + i * PAGE_SIZE);
 
 	for (i = 0; i * epd < info->nr_pages; i++)
-		info->page->pd[i] = vmalloc_to_mfn(&info->mfns[i * epd]);
+		info->page->pd[i] = vmalloc_to_gfn(&info->gfns[i * epd]);
 
 	info->page->width = fb_info->var.xres;
 	info->page->height = fb_info->var.yres;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 6/8] video/xen-fbfront: Further s/MFN/GFN clean-up
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	David Vrabel, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	linux-fbdev

The PV driver xen-fbfront is only dealing with GFN and not MFN. Rename
all the occurence of MFN to GFN.

Also take the opportunity to replace to usage of pfn_to_gfn by
page_to_pfn.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-fbdev@vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 drivers/video/fbdev/xen-fbfront.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 25e3cce..3112168 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -46,7 +46,7 @@ struct xenfb_info {
 	int			nr_pages;
 	int			irq;
 	struct xenfb_page	*page;
-	unsigned long 		*mfns;
+	unsigned long 		*gfns;
 	int			update_wanted; /* XENFB_TYPE_UPDATE wanted */
 	int			feature_resize; /* XENFB_TYPE_RESIZE ok */
 	struct xenfb_resize	resize;		/* protected by resize_lock */
@@ -402,8 +402,8 @@ static int xenfb_probe(struct xenbus_device *dev,
 
 	info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-	info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
-	if (!info->mfns)
+	info->gfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
+	if (!info->gfns)
 		goto error_nomem;
 
 	/* set up shared page */
@@ -530,29 +530,29 @@ static int xenfb_remove(struct xenbus_device *dev)
 		framebuffer_release(info->fb_info);
 	}
 	free_page((unsigned long)info->page);
-	vfree(info->mfns);
+	vfree(info->gfns);
 	vfree(info->fb);
 	kfree(info);
 
 	return 0;
 }
 
-static unsigned long vmalloc_to_mfn(void *address)
+static unsigned long vmalloc_to_gfn(void *address)
 {
-	return pfn_to_gfn(vmalloc_to_pfn(address));
+	return page_to_gfn(vmalloc_to_page(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
 				   struct fb_info *fb_info)
 {
 	int i;
-	int epd = PAGE_SIZE / sizeof(info->mfns[0]);
+	int epd = PAGE_SIZE / sizeof(info->gfns[0]);
 
 	for (i = 0; i < info->nr_pages; i++)
-		info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
+		info->gfns[i] = vmalloc_to_gfn(info->fb + i * PAGE_SIZE);
 
 	for (i = 0; i * epd < info->nr_pages; i++)
-		info->page->pd[i] = vmalloc_to_mfn(&info->mfns[i * epd]);
+		info->page->pd[i] = vmalloc_to_gfn(&info->gfns[i * epd]);
 
 	info->page->width = fb_info->var.xres;
 	info->page->height = fb_info->var.yres;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 6/8] video/xen-fbfront: Further s/MFN/GFN clean-up
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, ian.campbell, stefano.stabellini, linux-kernel,
	Julien Grall, Tomi Valkeinen, David Vrabel,
	Jean-Christophe Plagniol-Villard

The PV driver xen-fbfront is only dealing with GFN and not MFN. Rename
all the occurence of MFN to GFN.

Also take the opportunity to replace to usage of pfn_to_gfn by
page_to_pfn.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: linux-fbdev@vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 drivers/video/fbdev/xen-fbfront.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
index 25e3cce..3112168 100644
--- a/drivers/video/fbdev/xen-fbfront.c
+++ b/drivers/video/fbdev/xen-fbfront.c
@@ -46,7 +46,7 @@ struct xenfb_info {
 	int			nr_pages;
 	int			irq;
 	struct xenfb_page	*page;
-	unsigned long 		*mfns;
+	unsigned long 		*gfns;
 	int			update_wanted; /* XENFB_TYPE_UPDATE wanted */
 	int			feature_resize; /* XENFB_TYPE_RESIZE ok */
 	struct xenfb_resize	resize;		/* protected by resize_lock */
@@ -402,8 +402,8 @@ static int xenfb_probe(struct xenbus_device *dev,
 
 	info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-	info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
-	if (!info->mfns)
+	info->gfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
+	if (!info->gfns)
 		goto error_nomem;
 
 	/* set up shared page */
@@ -530,29 +530,29 @@ static int xenfb_remove(struct xenbus_device *dev)
 		framebuffer_release(info->fb_info);
 	}
 	free_page((unsigned long)info->page);
-	vfree(info->mfns);
+	vfree(info->gfns);
 	vfree(info->fb);
 	kfree(info);
 
 	return 0;
 }
 
-static unsigned long vmalloc_to_mfn(void *address)
+static unsigned long vmalloc_to_gfn(void *address)
 {
-	return pfn_to_gfn(vmalloc_to_pfn(address));
+	return page_to_gfn(vmalloc_to_page(address));
 }
 
 static void xenfb_init_shared_page(struct xenfb_info *info,
 				   struct fb_info *fb_info)
 {
 	int i;
-	int epd = PAGE_SIZE / sizeof(info->mfns[0]);
+	int epd = PAGE_SIZE / sizeof(info->gfns[0]);
 
 	for (i = 0; i < info->nr_pages; i++)
-		info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
+		info->gfns[i] = vmalloc_to_gfn(info->fb + i * PAGE_SIZE);
 
 	for (i = 0; i * epd < info->nr_pages; i++)
-		info->page->pd[i] = vmalloc_to_mfn(&info->mfns[i * epd]);
+		info->page->pd[i] = vmalloc_to_gfn(&info->gfns[i * epd]);
 
 	info->page->width = fb_info->var.xres;
 	info->page->height = fb_info->var.yres;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 7/8] hvc/xen: Further s/MFN/GFN clean-up
  2015-08-04 18:12 ` Julien Grall
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	David Vrabel, Greg Kroah-Hartman, Jiri Slaby, linuxppc-dev

HVM_PARAM_CONSOLE_PFN is used to retrieved the console PFN for HVM
guest. It returns a PFN (aka GFN) and not a MFN.

Furthermore, use directly virt_to_gfn for both PV and HVM domain rather
than doing a special case for each of the them.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: linuxppc-dev@lists.ozlabs.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 drivers/tty/hvc/hvc_xen.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index efe5124..10beb15 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -200,7 +200,7 @@ static int xen_hvm_console_init(void)
 {
 	int r;
 	uint64_t v = 0;
-	unsigned long mfn;
+	unsigned long gfn;
 	struct xencons_info *info;
 
 	if (!xen_hvm_domain())
@@ -217,7 +217,7 @@ static int xen_hvm_console_init(void)
 	}
 	/*
 	 * If the toolstack (or the hypervisor) hasn't set these values, the
-	 * default value is 0. Even though mfn = 0 and evtchn = 0 are
+	 * default value is 0. Even though gfn = 0 and evtchn = 0 are
 	 * theoretically correct values, in practice they never are and they
 	 * mean that a legacy toolstack hasn't initialized the pv console correctly.
 	 */
@@ -229,8 +229,8 @@ static int xen_hvm_console_init(void)
 	r = hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
 	if (r < 0 || v == 0)
 		goto err;
-	mfn = v;
-	info->intf = xen_remap(mfn << PAGE_SHIFT, PAGE_SIZE);
+	gfn = v;
+	info->intf = xen_remap(gfn << PAGE_SHIFT, PAGE_SIZE);
 	if (info->intf == NULL)
 		goto err;
 	info->vtermno = HVC_COOKIE;
@@ -375,7 +375,6 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	int ret, evtchn, devid, ref, irq;
 	struct xenbus_transaction xbt;
 	grant_ref_t gref_head;
-	unsigned long mfn;
 
 	ret = xenbus_alloc_evtchn(dev, &evtchn);
 	if (ret)
@@ -390,10 +389,6 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 			irq, &domU_hvc_ops, 256);
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
-	if (xen_pv_domain())
-		mfn = virt_to_gfn(info->intf);
-	else
-		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
 	if (ret < 0)
 		return ret;
@@ -402,7 +397,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (ref < 0)
 		return ref;
 	gnttab_grant_foreign_access_ref(ref, info->xbdev->otherend_id,
-			mfn, 0);
+					virt_to_gfn(info->intf), 0);
 
  again:
 	ret = xenbus_transaction_start(&xbt);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 7/8] hvc/xen: Further s/MFN/GFN clean-up
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, Greg Kroah-Hartman,
	linux-kernel, Julien Grall, David Vrabel, Jiri Slaby,
	linuxppc-dev

HVM_PARAM_CONSOLE_PFN is used to retrieved the console PFN for HVM
guest. It returns a PFN (aka GFN) and not a MFN.

Furthermore, use directly virt_to_gfn for both PV and HVM domain rather
than doing a special case for each of the them.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: linuxppc-dev@lists.ozlabs.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 drivers/tty/hvc/hvc_xen.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index efe5124..10beb15 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -200,7 +200,7 @@ static int xen_hvm_console_init(void)
 {
 	int r;
 	uint64_t v = 0;
-	unsigned long mfn;
+	unsigned long gfn;
 	struct xencons_info *info;
 
 	if (!xen_hvm_domain())
@@ -217,7 +217,7 @@ static int xen_hvm_console_init(void)
 	}
 	/*
 	 * If the toolstack (or the hypervisor) hasn't set these values, the
-	 * default value is 0. Even though mfn = 0 and evtchn = 0 are
+	 * default value is 0. Even though gfn = 0 and evtchn = 0 are
 	 * theoretically correct values, in practice they never are and they
 	 * mean that a legacy toolstack hasn't initialized the pv console correctly.
 	 */
@@ -229,8 +229,8 @@ static int xen_hvm_console_init(void)
 	r = hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
 	if (r < 0 || v == 0)
 		goto err;
-	mfn = v;
-	info->intf = xen_remap(mfn << PAGE_SHIFT, PAGE_SIZE);
+	gfn = v;
+	info->intf = xen_remap(gfn << PAGE_SHIFT, PAGE_SIZE);
 	if (info->intf == NULL)
 		goto err;
 	info->vtermno = HVC_COOKIE;
@@ -375,7 +375,6 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	int ret, evtchn, devid, ref, irq;
 	struct xenbus_transaction xbt;
 	grant_ref_t gref_head;
-	unsigned long mfn;
 
 	ret = xenbus_alloc_evtchn(dev, &evtchn);
 	if (ret)
@@ -390,10 +389,6 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 			irq, &domU_hvc_ops, 256);
 	if (IS_ERR(info->hvc))
 		return PTR_ERR(info->hvc);
-	if (xen_pv_domain())
-		mfn = virt_to_gfn(info->intf);
-	else
-		mfn = __pa(info->intf) >> PAGE_SHIFT;
 	ret = gnttab_alloc_grant_references(1, &gref_head);
 	if (ret < 0)
 		return ret;
@@ -402,7 +397,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
 	if (ref < 0)
 		return ref;
 	gnttab_grant_foreign_access_ref(ref, info->xbdev->otherend_id,
-			mfn, 0);
+					virt_to_gfn(info->intf), 0);
 
  again:
 	ret = xenbus_transaction_start(&xbt);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 8/8] xen/privcmd: Further s/MFN/GFN/ clean-up
  2015-08-04 18:12 ` Julien Grall
  (?)
@ 2015-08-04 18:12   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	David Vrabel, Russell King, Konrad Rzeszutek Wilk,
	Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86, linux-arm-kernel, linux-api

The privcmd code is mixing the usage of GFN and MFN within the same
functions which make the code difficult to understand when you only work
with auto-translated guests.

The privcmd driver is only dealing with GFN so replace all the mention
of MFN into GFN.

The ioctl structure used to map foreign change has been left unchanged
given that the userspace is using it. Nonetheless, add a comment to
explain the expected value within the "mfn" field.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-api@vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 arch/arm/xen/enlighten.c   | 18 +++++++++---------
 arch/x86/xen/mmu.c         | 32 ++++++++++++++++----------------
 drivers/xen/privcmd.c      | 44 ++++++++++++++++++++++----------------------
 drivers/xen/xlate_mmu.c    | 18 +++++++++---------
 include/uapi/xen/privcmd.h |  4 ++++
 include/xen/xen-ops.h      | 10 +++++-----
 6 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 6c09cc4..a8b8806 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -56,35 +56,35 @@ static __read_mostly unsigned int xen_events_irq;
 
 static __initdata struct device_node *xen_node;
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages)
 {
-	return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+	return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 					 prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Not used by XENFEAT_auto_translated guests. */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
                               unsigned long addr,
-                              xen_pfn_t mfn, int nr,
+                              xen_pfn_t gfn, int nr,
                               pgprot_t prot, unsigned domid,
                               struct page **pages)
 {
 	return -ENOSYS;
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int nr, struct page **pages)
 {
 	return xen_xlate_unmap_gfn_range(vma, nr, pages);
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
 
 static void xen_percpu_init(void)
 {
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index dd151b2..87db1ff 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -2465,9 +2465,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
 	return 0;
 }
 
-static int do_remap_mfn(struct vm_area_struct *vma,
+static int do_remap_gfn(struct vm_area_struct *vma,
 			unsigned long addr,
-			xen_pfn_t *mfn, int nr,
+			xen_pfn_t *gfn, int nr,
 			int *err_ptr, pgprot_t prot,
 			unsigned domid,
 			struct page **pages)
@@ -2483,14 +2483,14 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 	if (xen_feature(XENFEAT_auto_translated_physmap)) {
 #ifdef CONFIG_XEN_PVH
 		/* We need to update the local page tables and the xen HAP */
-		return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 						 prot, domid, pages);
 #else
 		return -EINVAL;
 #endif
         }
 
-	rmd.mfn = mfn;
+	rmd.mfn = gfn;
 	rmd.prot = prot;
 	/* We use the err_ptr to indicate if there we are doing a contigious
 	 * mapping or a discontigious mapping. */
@@ -2518,8 +2518,8 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 						    batch_left, &done, domid);
 
 			/*
-			 * @err_ptr may be the same buffer as @mfn, so
-			 * only clear it after each chunk of @mfn is
+			 * @err_ptr may be the same buffer as @gfn, so
+			 * only clear it after each chunk of @gfn is
 			 * used.
 			 */
 			if (err_ptr) {
@@ -2549,19 +2549,19 @@ out:
 	return err < 0 ? err : mapped;
 }
 
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t mfn, int nr,
+			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
-	return do_remap_mfn(vma, addr, &mfn, nr, NULL, prot, domid, pages);
+	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
@@ -2570,13 +2570,13 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
 	 * cause of "wrong memory was mapped in".
 	 */
 	BUG_ON(err_ptr == NULL);
-	return do_remap_mfn(vma, addr, mfn, nr, err_ptr, prot, domid, pages);
+	return do_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 
 /* Returns: 0 success */
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages)
 {
 	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
@@ -2588,4 +2588,4 @@ int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
 	return -EINVAL;
 #endif
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 5a29616..c6deb87 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -193,16 +193,16 @@ static int traverse_pages_block(unsigned nelem, size_t size,
 	return ret;
 }
 
-struct mmap_mfn_state {
+struct mmap_gfn_state {
 	unsigned long va;
 	struct vm_area_struct *vma;
 	domid_t domain;
 };
 
-static int mmap_mfn_range(void *data, void *state)
+static int mmap_gfn_range(void *data, void *state)
 {
 	struct privcmd_mmap_entry *msg = data;
-	struct mmap_mfn_state *st = state;
+	struct mmap_gfn_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	int rc;
 
@@ -216,7 +216,7 @@ static int mmap_mfn_range(void *data, void *state)
 	    ((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end))
 		return -EINVAL;
 
-	rc = xen_remap_domain_mfn_range(vma,
+	rc = xen_remap_domain_gfn_range(vma,
 					msg->va & PAGE_MASK,
 					msg->mfn, msg->npages,
 					vma->vm_page_prot,
@@ -236,7 +236,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 	struct vm_area_struct *vma;
 	int rc;
 	LIST_HEAD(pagelist);
-	struct mmap_mfn_state state;
+	struct mmap_gfn_state state;
 
 	/* We only support privcmd_ioctl_mmap_batch for auto translated. */
 	if (xen_feature(XENFEAT_auto_translated_physmap))
@@ -273,7 +273,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 
 	rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry),
 			    &pagelist,
-			    mmap_mfn_range, &state);
+			    mmap_gfn_range, &state);
 
 
 out_up:
@@ -299,18 +299,18 @@ struct mmap_batch_state {
 	int global_error;
 	int version;
 
-	/* User-space mfn array to store errors in the second pass for V1. */
-	xen_pfn_t __user *user_mfn;
+	/* User-space gfn array to store errors in the second pass for V1. */
+	xen_pfn_t __user *user_gfn;
 	/* User-space int array to store errors in the second pass for V2. */
 	int __user *user_err;
 };
 
-/* auto translated dom0 note: if domU being created is PV, then mfn is
- * mfn(addr on bus). If it's auto xlated, then mfn is pfn (input to HAP).
+/* auto translated dom0 note: if domU being created is PV, then gfn is
+ * mfn(addr on bus). If it's auto xlated, then gfn is pfn (input to HAP).
  */
 static int mmap_batch_fn(void *data, int nr, void *state)
 {
-	xen_pfn_t *mfnp = data;
+	xen_pfn_t *gfnp = data;
 	struct mmap_batch_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	struct page **pages = vma->vm_private_data;
@@ -321,8 +321,8 @@ static int mmap_batch_fn(void *data, int nr, void *state)
 		cur_pages = &pages[st->index];
 
 	BUG_ON(nr < 0);
-	ret = xen_remap_domain_mfn_array(st->vma, st->va & PAGE_MASK, mfnp, nr,
-					 (int *)mfnp, st->vma->vm_page_prot,
+	ret = xen_remap_domain_gfn_array(st->vma, st->va & PAGE_MASK, gfnp, nr,
+					 (int *)gfnp, st->vma->vm_page_prot,
 					 st->domain, cur_pages);
 
 	/* Adjust the global_error? */
@@ -347,22 +347,22 @@ static int mmap_return_error(int err, struct mmap_batch_state *st)
 
 	if (st->version == 1) {
 		if (err) {
-			xen_pfn_t mfn;
+			xen_pfn_t gfn;
 
-			ret = get_user(mfn, st->user_mfn);
+			ret = get_user(gfn, st->user_gfn);
 			if (ret < 0)
 				return ret;
 			/*
 			 * V1 encodes the error codes in the 32bit top
-			 * nibble of the mfn (with its known
+			 * nibble of the gfn (with its known
 			 * limitations vis-a-vis 64 bit callers).
 			 */
-			mfn |= (err == -ENOENT) ?
+			gfn |= (err == -ENOENT) ?
 				PRIVCMD_MMAPBATCH_PAGED_ERROR :
 				PRIVCMD_MMAPBATCH_MFN_ERROR;
-			return __put_user(mfn, st->user_mfn++);
+			return __put_user(gfn, st->user_gfn++);
 		} else
-			st->user_mfn++;
+			st->user_gfn++;
 	} else { /* st->version == 2 */
 		if (err)
 			return __put_user(err, st->user_err++);
@@ -388,7 +388,7 @@ static int mmap_return_errors(void *data, int nr, void *state)
 	return 0;
 }
 
-/* Allocate pfns that are then mapped with gmfns from foreign domid. Update
+/* Allocate pfns that are then mapped with gfns from foreign domid. Update
  * the vma with the page info to use later.
  * Returns: 0 if success, otherwise -errno
  */
@@ -526,7 +526,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	if (state.global_error) {
 		/* Write back errors in second pass. */
-		state.user_mfn = (xen_pfn_t *)m.arr;
+		state.user_gfn = (xen_pfn_t *)m.arr;
 		state.user_err = m.err;
 		ret = traverse_pages_block(m.num, sizeof(xen_pfn_t),
 					   &pagelist, mmap_return_errors, &state);
@@ -587,7 +587,7 @@ static void privcmd_close(struct vm_area_struct *vma)
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_gfn_range(vma, numpgs, pages);
 	if (rc == 0)
 		free_xenballooned_pages(numpgs, pages);
 	else
diff --git a/drivers/xen/xlate_mmu.c b/drivers/xen/xlate_mmu.c
index 58a5389..cff2387 100644
--- a/drivers/xen/xlate_mmu.c
+++ b/drivers/xen/xlate_mmu.c
@@ -38,8 +38,8 @@
 #include <xen/interface/xen.h>
 #include <xen/interface/memory.h>
 
-/* map fgmfn of domid to lpfn in the current domain */
-static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
+/* map fgfn of domid to lpfn in the current domain */
+static int map_foreign_page(unsigned long lpfn, unsigned long fgfn,
 			    unsigned int domid)
 {
 	int rc;
@@ -49,7 +49,7 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 		.size = 1,
 		.space = XENMAPSPACE_gmfn_foreign,
 	};
-	xen_ulong_t idx = fgmfn;
+	xen_ulong_t idx = fgfn;
 	xen_pfn_t gpfn = lpfn;
 	int err = 0;
 
@@ -62,13 +62,13 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 }
 
 struct remap_data {
-	xen_pfn_t *fgmfn; /* foreign domain's gmfn */
+	xen_pfn_t *fgfn; /* foreign domain's gfn */
 	pgprot_t prot;
 	domid_t  domid;
 	struct vm_area_struct *vma;
 	int index;
 	struct page **pages;
-	struct xen_remap_mfn_info *info;
+	struct xen_remap_gfn_info *info;
 	int *err_ptr;
 	int mapped;
 };
@@ -82,20 +82,20 @@ static int remap_pte_fn(pte_t *ptep, pgtable_t token, unsigned long addr,
 	pte_t pte = pte_mkspecial(pfn_pte(pfn, info->prot));
 	int rc;
 
-	rc = map_foreign_page(pfn, *info->fgmfn, info->domid);
+	rc = map_foreign_page(pfn, *info->fgfn, info->domid);
 	*info->err_ptr++ = rc;
 	if (!rc) {
 		set_pte_at(info->vma->vm_mm, addr, ptep, pte);
 		info->mapped++;
 	}
-	info->fgmfn++;
+	info->fgfn++;
 
 	return 0;
 }
 
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-			      xen_pfn_t *mfn, int nr,
+			      xen_pfn_t *gfn, int nr,
 			      int *err_ptr, pgprot_t prot,
 			      unsigned domid,
 			      struct page **pages)
@@ -108,7 +108,7 @@ int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 	   x86 PVOPS */
 	BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));
 
-	data.fgmfn = mfn;
+	data.fgfn = gfn;
 	data.prot  = prot;
 	data.domid = domid;
 	data.vma   = vma;
diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h
index a853168..7ddeeda 100644
--- a/include/uapi/xen/privcmd.h
+++ b/include/uapi/xen/privcmd.h
@@ -44,6 +44,10 @@ struct privcmd_hypercall {
 
 struct privcmd_mmap_entry {
 	__u64 va;
+	/*
+	 * This should be a GFN. It's not possible to change the name because
+	 * it's exposed to the user-space.
+	 */
 	__u64 mfn;
 	__u64 npages;
 };
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 0ce4f32..e4e214a 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -30,7 +30,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
 struct vm_area_struct;
 
 /*
- * xen_remap_domain_mfn_array() - map an array of foreign frames
+ * xen_remap_domain_gfn_array() - map an array of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     Array of GFNs to map
@@ -46,14 +46,14 @@ struct vm_area_struct;
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages);
 
-/* xen_remap_domain_mfn_range() - map a range of foreign frames
+/* xen_remap_domain_gfn_range() - map a range of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     First GFN to map.
@@ -65,12 +65,12 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages);
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages);
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 8/8] xen/privcmd: Further s/MFN/GFN/ clean-up
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Julien Grall,
	David Vrabel, Russell King, Konrad Rzeszutek Wilk,
	Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86, linux-arm-kernel, linux-api

The privcmd code is mixing the usage of GFN and MFN within the same
functions which make the code difficult to understand when you only work
with auto-translated guests.

The privcmd driver is only dealing with GFN so replace all the mention
of MFN into GFN.

The ioctl structure used to map foreign change has been left unchanged
given that the userspace is using it. Nonetheless, add a comment to
explain the expected value within the "mfn" field.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-api@vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 arch/arm/xen/enlighten.c   | 18 +++++++++---------
 arch/x86/xen/mmu.c         | 32 ++++++++++++++++----------------
 drivers/xen/privcmd.c      | 44 ++++++++++++++++++++++----------------------
 drivers/xen/xlate_mmu.c    | 18 +++++++++---------
 include/uapi/xen/privcmd.h |  4 ++++
 include/xen/xen-ops.h      | 10 +++++-----
 6 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 6c09cc4..a8b8806 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -56,35 +56,35 @@ static __read_mostly unsigned int xen_events_irq;
 
 static __initdata struct device_node *xen_node;
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages)
 {
-	return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+	return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 					 prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Not used by XENFEAT_auto_translated guests. */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
                               unsigned long addr,
-                              xen_pfn_t mfn, int nr,
+                              xen_pfn_t gfn, int nr,
                               pgprot_t prot, unsigned domid,
                               struct page **pages)
 {
 	return -ENOSYS;
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int nr, struct page **pages)
 {
 	return xen_xlate_unmap_gfn_range(vma, nr, pages);
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
 
 static void xen_percpu_init(void)
 {
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index dd151b2..87db1ff 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -2465,9 +2465,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
 	return 0;
 }
 
-static int do_remap_mfn(struct vm_area_struct *vma,
+static int do_remap_gfn(struct vm_area_struct *vma,
 			unsigned long addr,
-			xen_pfn_t *mfn, int nr,
+			xen_pfn_t *gfn, int nr,
 			int *err_ptr, pgprot_t prot,
 			unsigned domid,
 			struct page **pages)
@@ -2483,14 +2483,14 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 	if (xen_feature(XENFEAT_auto_translated_physmap)) {
 #ifdef CONFIG_XEN_PVH
 		/* We need to update the local page tables and the xen HAP */
-		return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 						 prot, domid, pages);
 #else
 		return -EINVAL;
 #endif
         }
 
-	rmd.mfn = mfn;
+	rmd.mfn = gfn;
 	rmd.prot = prot;
 	/* We use the err_ptr to indicate if there we are doing a contigious
 	 * mapping or a discontigious mapping. */
@@ -2518,8 +2518,8 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 						    batch_left, &done, domid);
 
 			/*
-			 * @err_ptr may be the same buffer as @mfn, so
-			 * only clear it after each chunk of @mfn is
+			 * @err_ptr may be the same buffer as @gfn, so
+			 * only clear it after each chunk of @gfn is
 			 * used.
 			 */
 			if (err_ptr) {
@@ -2549,19 +2549,19 @@ out:
 	return err < 0 ? err : mapped;
 }
 
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t mfn, int nr,
+			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
-	return do_remap_mfn(vma, addr, &mfn, nr, NULL, prot, domid, pages);
+	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
@@ -2570,13 +2570,13 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
 	 * cause of "wrong memory was mapped in".
 	 */
 	BUG_ON(err_ptr == NULL);
-	return do_remap_mfn(vma, addr, mfn, nr, err_ptr, prot, domid, pages);
+	return do_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 
 /* Returns: 0 success */
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages)
 {
 	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
@@ -2588,4 +2588,4 @@ int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
 	return -EINVAL;
 #endif
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 5a29616..c6deb87 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -193,16 +193,16 @@ static int traverse_pages_block(unsigned nelem, size_t size,
 	return ret;
 }
 
-struct mmap_mfn_state {
+struct mmap_gfn_state {
 	unsigned long va;
 	struct vm_area_struct *vma;
 	domid_t domain;
 };
 
-static int mmap_mfn_range(void *data, void *state)
+static int mmap_gfn_range(void *data, void *state)
 {
 	struct privcmd_mmap_entry *msg = data;
-	struct mmap_mfn_state *st = state;
+	struct mmap_gfn_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	int rc;
 
@@ -216,7 +216,7 @@ static int mmap_mfn_range(void *data, void *state)
 	    ((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end))
 		return -EINVAL;
 
-	rc = xen_remap_domain_mfn_range(vma,
+	rc = xen_remap_domain_gfn_range(vma,
 					msg->va & PAGE_MASK,
 					msg->mfn, msg->npages,
 					vma->vm_page_prot,
@@ -236,7 +236,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 	struct vm_area_struct *vma;
 	int rc;
 	LIST_HEAD(pagelist);
-	struct mmap_mfn_state state;
+	struct mmap_gfn_state state;
 
 	/* We only support privcmd_ioctl_mmap_batch for auto translated. */
 	if (xen_feature(XENFEAT_auto_translated_physmap))
@@ -273,7 +273,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 
 	rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry),
 			    &pagelist,
-			    mmap_mfn_range, &state);
+			    mmap_gfn_range, &state);
 
 
 out_up:
@@ -299,18 +299,18 @@ struct mmap_batch_state {
 	int global_error;
 	int version;
 
-	/* User-space mfn array to store errors in the second pass for V1. */
-	xen_pfn_t __user *user_mfn;
+	/* User-space gfn array to store errors in the second pass for V1. */
+	xen_pfn_t __user *user_gfn;
 	/* User-space int array to store errors in the second pass for V2. */
 	int __user *user_err;
 };
 
-/* auto translated dom0 note: if domU being created is PV, then mfn is
- * mfn(addr on bus). If it's auto xlated, then mfn is pfn (input to HAP).
+/* auto translated dom0 note: if domU being created is PV, then gfn is
+ * mfn(addr on bus). If it's auto xlated, then gfn is pfn (input to HAP).
  */
 static int mmap_batch_fn(void *data, int nr, void *state)
 {
-	xen_pfn_t *mfnp = data;
+	xen_pfn_t *gfnp = data;
 	struct mmap_batch_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	struct page **pages = vma->vm_private_data;
@@ -321,8 +321,8 @@ static int mmap_batch_fn(void *data, int nr, void *state)
 		cur_pages = &pages[st->index];
 
 	BUG_ON(nr < 0);
-	ret = xen_remap_domain_mfn_array(st->vma, st->va & PAGE_MASK, mfnp, nr,
-					 (int *)mfnp, st->vma->vm_page_prot,
+	ret = xen_remap_domain_gfn_array(st->vma, st->va & PAGE_MASK, gfnp, nr,
+					 (int *)gfnp, st->vma->vm_page_prot,
 					 st->domain, cur_pages);
 
 	/* Adjust the global_error? */
@@ -347,22 +347,22 @@ static int mmap_return_error(int err, struct mmap_batch_state *st)
 
 	if (st->version == 1) {
 		if (err) {
-			xen_pfn_t mfn;
+			xen_pfn_t gfn;
 
-			ret = get_user(mfn, st->user_mfn);
+			ret = get_user(gfn, st->user_gfn);
 			if (ret < 0)
 				return ret;
 			/*
 			 * V1 encodes the error codes in the 32bit top
-			 * nibble of the mfn (with its known
+			 * nibble of the gfn (with its known
 			 * limitations vis-a-vis 64 bit callers).
 			 */
-			mfn |= (err == -ENOENT) ?
+			gfn |= (err == -ENOENT) ?
 				PRIVCMD_MMAPBATCH_PAGED_ERROR :
 				PRIVCMD_MMAPBATCH_MFN_ERROR;
-			return __put_user(mfn, st->user_mfn++);
+			return __put_user(gfn, st->user_gfn++);
 		} else
-			st->user_mfn++;
+			st->user_gfn++;
 	} else { /* st->version == 2 */
 		if (err)
 			return __put_user(err, st->user_err++);
@@ -388,7 +388,7 @@ static int mmap_return_errors(void *data, int nr, void *state)
 	return 0;
 }
 
-/* Allocate pfns that are then mapped with gmfns from foreign domid. Update
+/* Allocate pfns that are then mapped with gfns from foreign domid. Update
  * the vma with the page info to use later.
  * Returns: 0 if success, otherwise -errno
  */
@@ -526,7 +526,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	if (state.global_error) {
 		/* Write back errors in second pass. */
-		state.user_mfn = (xen_pfn_t *)m.arr;
+		state.user_gfn = (xen_pfn_t *)m.arr;
 		state.user_err = m.err;
 		ret = traverse_pages_block(m.num, sizeof(xen_pfn_t),
 					   &pagelist, mmap_return_errors, &state);
@@ -587,7 +587,7 @@ static void privcmd_close(struct vm_area_struct *vma)
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_gfn_range(vma, numpgs, pages);
 	if (rc == 0)
 		free_xenballooned_pages(numpgs, pages);
 	else
diff --git a/drivers/xen/xlate_mmu.c b/drivers/xen/xlate_mmu.c
index 58a5389..cff2387 100644
--- a/drivers/xen/xlate_mmu.c
+++ b/drivers/xen/xlate_mmu.c
@@ -38,8 +38,8 @@
 #include <xen/interface/xen.h>
 #include <xen/interface/memory.h>
 
-/* map fgmfn of domid to lpfn in the current domain */
-static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
+/* map fgfn of domid to lpfn in the current domain */
+static int map_foreign_page(unsigned long lpfn, unsigned long fgfn,
 			    unsigned int domid)
 {
 	int rc;
@@ -49,7 +49,7 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 		.size = 1,
 		.space = XENMAPSPACE_gmfn_foreign,
 	};
-	xen_ulong_t idx = fgmfn;
+	xen_ulong_t idx = fgfn;
 	xen_pfn_t gpfn = lpfn;
 	int err = 0;
 
@@ -62,13 +62,13 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 }
 
 struct remap_data {
-	xen_pfn_t *fgmfn; /* foreign domain's gmfn */
+	xen_pfn_t *fgfn; /* foreign domain's gfn */
 	pgprot_t prot;
 	domid_t  domid;
 	struct vm_area_struct *vma;
 	int index;
 	struct page **pages;
-	struct xen_remap_mfn_info *info;
+	struct xen_remap_gfn_info *info;
 	int *err_ptr;
 	int mapped;
 };
@@ -82,20 +82,20 @@ static int remap_pte_fn(pte_t *ptep, pgtable_t token, unsigned long addr,
 	pte_t pte = pte_mkspecial(pfn_pte(pfn, info->prot));
 	int rc;
 
-	rc = map_foreign_page(pfn, *info->fgmfn, info->domid);
+	rc = map_foreign_page(pfn, *info->fgfn, info->domid);
 	*info->err_ptr++ = rc;
 	if (!rc) {
 		set_pte_at(info->vma->vm_mm, addr, ptep, pte);
 		info->mapped++;
 	}
-	info->fgmfn++;
+	info->fgfn++;
 
 	return 0;
 }
 
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-			      xen_pfn_t *mfn, int nr,
+			      xen_pfn_t *gfn, int nr,
 			      int *err_ptr, pgprot_t prot,
 			      unsigned domid,
 			      struct page **pages)
@@ -108,7 +108,7 @@ int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 	   x86 PVOPS */
 	BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));
 
-	data.fgmfn = mfn;
+	data.fgfn = gfn;
 	data.prot  = prot;
 	data.domid = domid;
 	data.vma   = vma;
diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h
index a853168..7ddeeda 100644
--- a/include/uapi/xen/privcmd.h
+++ b/include/uapi/xen/privcmd.h
@@ -44,6 +44,10 @@ struct privcmd_hypercall {
 
 struct privcmd_mmap_entry {
 	__u64 va;
+	/*
+	 * This should be a GFN. It's not possible to change the name because
+	 * it's exposed to the user-space.
+	 */
 	__u64 mfn;
 	__u64 npages;
 };
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 0ce4f32..e4e214a 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -30,7 +30,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
 struct vm_area_struct;
 
 /*
- * xen_remap_domain_mfn_array() - map an array of foreign frames
+ * xen_remap_domain_gfn_array() - map an array of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     Array of GFNs to map
@@ -46,14 +46,14 @@ struct vm_area_struct;
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages);
 
-/* xen_remap_domain_mfn_range() - map a range of foreign frames
+/* xen_remap_domain_gfn_range() - map a range of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     First GFN to map.
@@ -65,12 +65,12 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages);
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages);
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 8/8] xen/privcmd: Further s/MFN/GFN/ clean-up
@ 2015-08-04 18:12   ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

The privcmd code is mixing the usage of GFN and MFN within the same
functions which make the code difficult to understand when you only work
with auto-translated guests.

The privcmd driver is only dealing with GFN so replace all the mention
of MFN into GFN.

The ioctl structure used to map foreign change has been left unchanged
given that the userspace is using it. Nonetheless, add a comment to
explain the expected value within the "mfn" field.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86 at kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-api at vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 arch/arm/xen/enlighten.c   | 18 +++++++++---------
 arch/x86/xen/mmu.c         | 32 ++++++++++++++++----------------
 drivers/xen/privcmd.c      | 44 ++++++++++++++++++++++----------------------
 drivers/xen/xlate_mmu.c    | 18 +++++++++---------
 include/uapi/xen/privcmd.h |  4 ++++
 include/xen/xen-ops.h      | 10 +++++-----
 6 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 6c09cc4..a8b8806 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -56,35 +56,35 @@ static __read_mostly unsigned int xen_events_irq;
 
 static __initdata struct device_node *xen_node;
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages)
 {
-	return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+	return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 					 prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Not used by XENFEAT_auto_translated guests. */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
                               unsigned long addr,
-                              xen_pfn_t mfn, int nr,
+                              xen_pfn_t gfn, int nr,
                               pgprot_t prot, unsigned domid,
                               struct page **pages)
 {
 	return -ENOSYS;
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int nr, struct page **pages)
 {
 	return xen_xlate_unmap_gfn_range(vma, nr, pages);
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
 
 static void xen_percpu_init(void)
 {
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index dd151b2..87db1ff 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -2465,9 +2465,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
 	return 0;
 }
 
-static int do_remap_mfn(struct vm_area_struct *vma,
+static int do_remap_gfn(struct vm_area_struct *vma,
 			unsigned long addr,
-			xen_pfn_t *mfn, int nr,
+			xen_pfn_t *gfn, int nr,
 			int *err_ptr, pgprot_t prot,
 			unsigned domid,
 			struct page **pages)
@@ -2483,14 +2483,14 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 	if (xen_feature(XENFEAT_auto_translated_physmap)) {
 #ifdef CONFIG_XEN_PVH
 		/* We need to update the local page tables and the xen HAP */
-		return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 						 prot, domid, pages);
 #else
 		return -EINVAL;
 #endif
         }
 
-	rmd.mfn = mfn;
+	rmd.mfn = gfn;
 	rmd.prot = prot;
 	/* We use the err_ptr to indicate if there we are doing a contigious
 	 * mapping or a discontigious mapping. */
@@ -2518,8 +2518,8 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 						    batch_left, &done, domid);
 
 			/*
-			 * @err_ptr may be the same buffer as @mfn, so
-			 * only clear it after each chunk of @mfn is
+			 * @err_ptr may be the same buffer as @gfn, so
+			 * only clear it after each chunk of @gfn is
 			 * used.
 			 */
 			if (err_ptr) {
@@ -2549,19 +2549,19 @@ out:
 	return err < 0 ? err : mapped;
 }
 
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t mfn, int nr,
+			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
-	return do_remap_mfn(vma, addr, &mfn, nr, NULL, prot, domid, pages);
+	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
@@ -2570,13 +2570,13 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
 	 * cause of "wrong memory was mapped in".
 	 */
 	BUG_ON(err_ptr == NULL);
-	return do_remap_mfn(vma, addr, mfn, nr, err_ptr, prot, domid, pages);
+	return do_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 
 /* Returns: 0 success */
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages)
 {
 	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
@@ -2588,4 +2588,4 @@ int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
 	return -EINVAL;
 #endif
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 5a29616..c6deb87 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -193,16 +193,16 @@ static int traverse_pages_block(unsigned nelem, size_t size,
 	return ret;
 }
 
-struct mmap_mfn_state {
+struct mmap_gfn_state {
 	unsigned long va;
 	struct vm_area_struct *vma;
 	domid_t domain;
 };
 
-static int mmap_mfn_range(void *data, void *state)
+static int mmap_gfn_range(void *data, void *state)
 {
 	struct privcmd_mmap_entry *msg = data;
-	struct mmap_mfn_state *st = state;
+	struct mmap_gfn_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	int rc;
 
@@ -216,7 +216,7 @@ static int mmap_mfn_range(void *data, void *state)
 	    ((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end))
 		return -EINVAL;
 
-	rc = xen_remap_domain_mfn_range(vma,
+	rc = xen_remap_domain_gfn_range(vma,
 					msg->va & PAGE_MASK,
 					msg->mfn, msg->npages,
 					vma->vm_page_prot,
@@ -236,7 +236,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 	struct vm_area_struct *vma;
 	int rc;
 	LIST_HEAD(pagelist);
-	struct mmap_mfn_state state;
+	struct mmap_gfn_state state;
 
 	/* We only support privcmd_ioctl_mmap_batch for auto translated. */
 	if (xen_feature(XENFEAT_auto_translated_physmap))
@@ -273,7 +273,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 
 	rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry),
 			    &pagelist,
-			    mmap_mfn_range, &state);
+			    mmap_gfn_range, &state);
 
 
 out_up:
@@ -299,18 +299,18 @@ struct mmap_batch_state {
 	int global_error;
 	int version;
 
-	/* User-space mfn array to store errors in the second pass for V1. */
-	xen_pfn_t __user *user_mfn;
+	/* User-space gfn array to store errors in the second pass for V1. */
+	xen_pfn_t __user *user_gfn;
 	/* User-space int array to store errors in the second pass for V2. */
 	int __user *user_err;
 };
 
-/* auto translated dom0 note: if domU being created is PV, then mfn is
- * mfn(addr on bus). If it's auto xlated, then mfn is pfn (input to HAP).
+/* auto translated dom0 note: if domU being created is PV, then gfn is
+ * mfn(addr on bus). If it's auto xlated, then gfn is pfn (input to HAP).
  */
 static int mmap_batch_fn(void *data, int nr, void *state)
 {
-	xen_pfn_t *mfnp = data;
+	xen_pfn_t *gfnp = data;
 	struct mmap_batch_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	struct page **pages = vma->vm_private_data;
@@ -321,8 +321,8 @@ static int mmap_batch_fn(void *data, int nr, void *state)
 		cur_pages = &pages[st->index];
 
 	BUG_ON(nr < 0);
-	ret = xen_remap_domain_mfn_array(st->vma, st->va & PAGE_MASK, mfnp, nr,
-					 (int *)mfnp, st->vma->vm_page_prot,
+	ret = xen_remap_domain_gfn_array(st->vma, st->va & PAGE_MASK, gfnp, nr,
+					 (int *)gfnp, st->vma->vm_page_prot,
 					 st->domain, cur_pages);
 
 	/* Adjust the global_error? */
@@ -347,22 +347,22 @@ static int mmap_return_error(int err, struct mmap_batch_state *st)
 
 	if (st->version == 1) {
 		if (err) {
-			xen_pfn_t mfn;
+			xen_pfn_t gfn;
 
-			ret = get_user(mfn, st->user_mfn);
+			ret = get_user(gfn, st->user_gfn);
 			if (ret < 0)
 				return ret;
 			/*
 			 * V1 encodes the error codes in the 32bit top
-			 * nibble of the mfn (with its known
+			 * nibble of the gfn (with its known
 			 * limitations vis-a-vis 64 bit callers).
 			 */
-			mfn |= (err == -ENOENT) ?
+			gfn |= (err == -ENOENT) ?
 				PRIVCMD_MMAPBATCH_PAGED_ERROR :
 				PRIVCMD_MMAPBATCH_MFN_ERROR;
-			return __put_user(mfn, st->user_mfn++);
+			return __put_user(gfn, st->user_gfn++);
 		} else
-			st->user_mfn++;
+			st->user_gfn++;
 	} else { /* st->version == 2 */
 		if (err)
 			return __put_user(err, st->user_err++);
@@ -388,7 +388,7 @@ static int mmap_return_errors(void *data, int nr, void *state)
 	return 0;
 }
 
-/* Allocate pfns that are then mapped with gmfns from foreign domid. Update
+/* Allocate pfns that are then mapped with gfns from foreign domid. Update
  * the vma with the page info to use later.
  * Returns: 0 if success, otherwise -errno
  */
@@ -526,7 +526,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	if (state.global_error) {
 		/* Write back errors in second pass. */
-		state.user_mfn = (xen_pfn_t *)m.arr;
+		state.user_gfn = (xen_pfn_t *)m.arr;
 		state.user_err = m.err;
 		ret = traverse_pages_block(m.num, sizeof(xen_pfn_t),
 					   &pagelist, mmap_return_errors, &state);
@@ -587,7 +587,7 @@ static void privcmd_close(struct vm_area_struct *vma)
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_gfn_range(vma, numpgs, pages);
 	if (rc == 0)
 		free_xenballooned_pages(numpgs, pages);
 	else
diff --git a/drivers/xen/xlate_mmu.c b/drivers/xen/xlate_mmu.c
index 58a5389..cff2387 100644
--- a/drivers/xen/xlate_mmu.c
+++ b/drivers/xen/xlate_mmu.c
@@ -38,8 +38,8 @@
 #include <xen/interface/xen.h>
 #include <xen/interface/memory.h>
 
-/* map fgmfn of domid to lpfn in the current domain */
-static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
+/* map fgfn of domid to lpfn in the current domain */
+static int map_foreign_page(unsigned long lpfn, unsigned long fgfn,
 			    unsigned int domid)
 {
 	int rc;
@@ -49,7 +49,7 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 		.size = 1,
 		.space = XENMAPSPACE_gmfn_foreign,
 	};
-	xen_ulong_t idx = fgmfn;
+	xen_ulong_t idx = fgfn;
 	xen_pfn_t gpfn = lpfn;
 	int err = 0;
 
@@ -62,13 +62,13 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 }
 
 struct remap_data {
-	xen_pfn_t *fgmfn; /* foreign domain's gmfn */
+	xen_pfn_t *fgfn; /* foreign domain's gfn */
 	pgprot_t prot;
 	domid_t  domid;
 	struct vm_area_struct *vma;
 	int index;
 	struct page **pages;
-	struct xen_remap_mfn_info *info;
+	struct xen_remap_gfn_info *info;
 	int *err_ptr;
 	int mapped;
 };
@@ -82,20 +82,20 @@ static int remap_pte_fn(pte_t *ptep, pgtable_t token, unsigned long addr,
 	pte_t pte = pte_mkspecial(pfn_pte(pfn, info->prot));
 	int rc;
 
-	rc = map_foreign_page(pfn, *info->fgmfn, info->domid);
+	rc = map_foreign_page(pfn, *info->fgfn, info->domid);
 	*info->err_ptr++ = rc;
 	if (!rc) {
 		set_pte_at(info->vma->vm_mm, addr, ptep, pte);
 		info->mapped++;
 	}
-	info->fgmfn++;
+	info->fgfn++;
 
 	return 0;
 }
 
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-			      xen_pfn_t *mfn, int nr,
+			      xen_pfn_t *gfn, int nr,
 			      int *err_ptr, pgprot_t prot,
 			      unsigned domid,
 			      struct page **pages)
@@ -108,7 +108,7 @@ int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 	   x86 PVOPS */
 	BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));
 
-	data.fgmfn = mfn;
+	data.fgfn = gfn;
 	data.prot  = prot;
 	data.domid = domid;
 	data.vma   = vma;
diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h
index a853168..7ddeeda 100644
--- a/include/uapi/xen/privcmd.h
+++ b/include/uapi/xen/privcmd.h
@@ -44,6 +44,10 @@ struct privcmd_hypercall {
 
 struct privcmd_mmap_entry {
 	__u64 va;
+	/*
+	 * This should be a GFN. It's not possible to change the name because
+	 * it's exposed to the user-space.
+	 */
 	__u64 mfn;
 	__u64 npages;
 };
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 0ce4f32..e4e214a 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -30,7 +30,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
 struct vm_area_struct;
 
 /*
- * xen_remap_domain_mfn_array() - map an array of foreign frames
+ * xen_remap_domain_gfn_array() - map an array of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     Array of GFNs to map
@@ -46,14 +46,14 @@ struct vm_area_struct;
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages);
 
-/* xen_remap_domain_mfn_range() - map a range of foreign frames
+/* xen_remap_domain_gfn_range() - map a range of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     First GFN to map.
@@ -65,12 +65,12 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages);
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages);
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH v2 8/8] xen/privcmd: Further s/MFN/GFN/ clean-up
  2015-08-04 18:12 ` Julien Grall
                   ` (15 preceding siblings ...)
  (?)
@ 2015-08-04 18:12 ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-04 18:12 UTC (permalink / raw)
  To: xen-devel
  Cc: x86, Russell King, ian.campbell, stefano.stabellini, linux-api,
	linux-kernel, Julien Grall, Ingo Molnar, David Vrabel,
	H. Peter Anvin, Boris Ostrovsky, Thomas Gleixner,
	linux-arm-kernel

The privcmd code is mixing the usage of GFN and MFN within the same
functions which make the code difficult to understand when you only work
with auto-translated guests.

The privcmd driver is only dealing with GFN so replace all the mention
of MFN into GFN.

The ioctl structure used to map foreign change has been left unchanged
given that the userspace is using it. Nonetheless, add a comment to
explain the expected value within the "mfn" field.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-api@vger.kernel.org

---
    Changes in v2:
        - Add David's reviewed-by
---
 arch/arm/xen/enlighten.c   | 18 +++++++++---------
 arch/x86/xen/mmu.c         | 32 ++++++++++++++++----------------
 drivers/xen/privcmd.c      | 44 ++++++++++++++++++++++----------------------
 drivers/xen/xlate_mmu.c    | 18 +++++++++---------
 include/uapi/xen/privcmd.h |  4 ++++
 include/xen/xen-ops.h      | 10 +++++-----
 6 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 6c09cc4..a8b8806 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -56,35 +56,35 @@ static __read_mostly unsigned int xen_events_irq;
 
 static __initdata struct device_node *xen_node;
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages)
 {
-	return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+	return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 					 prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Not used by XENFEAT_auto_translated guests. */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
                               unsigned long addr,
-                              xen_pfn_t mfn, int nr,
+                              xen_pfn_t gfn, int nr,
                               pgprot_t prot, unsigned domid,
                               struct page **pages)
 {
 	return -ENOSYS;
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int nr, struct page **pages)
 {
 	return xen_xlate_unmap_gfn_range(vma, nr, pages);
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
 
 static void xen_percpu_init(void)
 {
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index dd151b2..87db1ff 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -2465,9 +2465,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
 	return 0;
 }
 
-static int do_remap_mfn(struct vm_area_struct *vma,
+static int do_remap_gfn(struct vm_area_struct *vma,
 			unsigned long addr,
-			xen_pfn_t *mfn, int nr,
+			xen_pfn_t *gfn, int nr,
 			int *err_ptr, pgprot_t prot,
 			unsigned domid,
 			struct page **pages)
@@ -2483,14 +2483,14 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 	if (xen_feature(XENFEAT_auto_translated_physmap)) {
 #ifdef CONFIG_XEN_PVH
 		/* We need to update the local page tables and the xen HAP */
-		return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
 						 prot, domid, pages);
 #else
 		return -EINVAL;
 #endif
         }
 
-	rmd.mfn = mfn;
+	rmd.mfn = gfn;
 	rmd.prot = prot;
 	/* We use the err_ptr to indicate if there we are doing a contigious
 	 * mapping or a discontigious mapping. */
@@ -2518,8 +2518,8 @@ static int do_remap_mfn(struct vm_area_struct *vma,
 						    batch_left, &done, domid);
 
 			/*
-			 * @err_ptr may be the same buffer as @mfn, so
-			 * only clear it after each chunk of @mfn is
+			 * @err_ptr may be the same buffer as @gfn, so
+			 * only clear it after each chunk of @gfn is
 			 * used.
 			 */
 			if (err_ptr) {
@@ -2549,19 +2549,19 @@ out:
 	return err < 0 ? err : mapped;
 }
 
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t mfn, int nr,
+			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
-	return do_remap_mfn(vma, addr, &mfn, nr, NULL, prot, domid, pages);
+	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
 
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
-			       xen_pfn_t *mfn, int nr,
+			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
@@ -2570,13 +2570,13 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
 	 * cause of "wrong memory was mapped in".
 	 */
 	BUG_ON(err_ptr == NULL);
-	return do_remap_mfn(vma, addr, mfn, nr, err_ptr, prot, domid, pages);
+	return do_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, pages);
 }
-EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
+EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 
 /* Returns: 0 success */
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages)
 {
 	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
@@ -2588,4 +2588,4 @@ int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
 	return -EINVAL;
 #endif
 }
-EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
+EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 5a29616..c6deb87 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -193,16 +193,16 @@ static int traverse_pages_block(unsigned nelem, size_t size,
 	return ret;
 }
 
-struct mmap_mfn_state {
+struct mmap_gfn_state {
 	unsigned long va;
 	struct vm_area_struct *vma;
 	domid_t domain;
 };
 
-static int mmap_mfn_range(void *data, void *state)
+static int mmap_gfn_range(void *data, void *state)
 {
 	struct privcmd_mmap_entry *msg = data;
-	struct mmap_mfn_state *st = state;
+	struct mmap_gfn_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	int rc;
 
@@ -216,7 +216,7 @@ static int mmap_mfn_range(void *data, void *state)
 	    ((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end))
 		return -EINVAL;
 
-	rc = xen_remap_domain_mfn_range(vma,
+	rc = xen_remap_domain_gfn_range(vma,
 					msg->va & PAGE_MASK,
 					msg->mfn, msg->npages,
 					vma->vm_page_prot,
@@ -236,7 +236,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 	struct vm_area_struct *vma;
 	int rc;
 	LIST_HEAD(pagelist);
-	struct mmap_mfn_state state;
+	struct mmap_gfn_state state;
 
 	/* We only support privcmd_ioctl_mmap_batch for auto translated. */
 	if (xen_feature(XENFEAT_auto_translated_physmap))
@@ -273,7 +273,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
 
 	rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry),
 			    &pagelist,
-			    mmap_mfn_range, &state);
+			    mmap_gfn_range, &state);
 
 
 out_up:
@@ -299,18 +299,18 @@ struct mmap_batch_state {
 	int global_error;
 	int version;
 
-	/* User-space mfn array to store errors in the second pass for V1. */
-	xen_pfn_t __user *user_mfn;
+	/* User-space gfn array to store errors in the second pass for V1. */
+	xen_pfn_t __user *user_gfn;
 	/* User-space int array to store errors in the second pass for V2. */
 	int __user *user_err;
 };
 
-/* auto translated dom0 note: if domU being created is PV, then mfn is
- * mfn(addr on bus). If it's auto xlated, then mfn is pfn (input to HAP).
+/* auto translated dom0 note: if domU being created is PV, then gfn is
+ * mfn(addr on bus). If it's auto xlated, then gfn is pfn (input to HAP).
  */
 static int mmap_batch_fn(void *data, int nr, void *state)
 {
-	xen_pfn_t *mfnp = data;
+	xen_pfn_t *gfnp = data;
 	struct mmap_batch_state *st = state;
 	struct vm_area_struct *vma = st->vma;
 	struct page **pages = vma->vm_private_data;
@@ -321,8 +321,8 @@ static int mmap_batch_fn(void *data, int nr, void *state)
 		cur_pages = &pages[st->index];
 
 	BUG_ON(nr < 0);
-	ret = xen_remap_domain_mfn_array(st->vma, st->va & PAGE_MASK, mfnp, nr,
-					 (int *)mfnp, st->vma->vm_page_prot,
+	ret = xen_remap_domain_gfn_array(st->vma, st->va & PAGE_MASK, gfnp, nr,
+					 (int *)gfnp, st->vma->vm_page_prot,
 					 st->domain, cur_pages);
 
 	/* Adjust the global_error? */
@@ -347,22 +347,22 @@ static int mmap_return_error(int err, struct mmap_batch_state *st)
 
 	if (st->version == 1) {
 		if (err) {
-			xen_pfn_t mfn;
+			xen_pfn_t gfn;
 
-			ret = get_user(mfn, st->user_mfn);
+			ret = get_user(gfn, st->user_gfn);
 			if (ret < 0)
 				return ret;
 			/*
 			 * V1 encodes the error codes in the 32bit top
-			 * nibble of the mfn (with its known
+			 * nibble of the gfn (with its known
 			 * limitations vis-a-vis 64 bit callers).
 			 */
-			mfn |= (err == -ENOENT) ?
+			gfn |= (err == -ENOENT) ?
 				PRIVCMD_MMAPBATCH_PAGED_ERROR :
 				PRIVCMD_MMAPBATCH_MFN_ERROR;
-			return __put_user(mfn, st->user_mfn++);
+			return __put_user(gfn, st->user_gfn++);
 		} else
-			st->user_mfn++;
+			st->user_gfn++;
 	} else { /* st->version == 2 */
 		if (err)
 			return __put_user(err, st->user_err++);
@@ -388,7 +388,7 @@ static int mmap_return_errors(void *data, int nr, void *state)
 	return 0;
 }
 
-/* Allocate pfns that are then mapped with gmfns from foreign domid. Update
+/* Allocate pfns that are then mapped with gfns from foreign domid. Update
  * the vma with the page info to use later.
  * Returns: 0 if success, otherwise -errno
  */
@@ -526,7 +526,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	if (state.global_error) {
 		/* Write back errors in second pass. */
-		state.user_mfn = (xen_pfn_t *)m.arr;
+		state.user_gfn = (xen_pfn_t *)m.arr;
 		state.user_err = m.err;
 		ret = traverse_pages_block(m.num, sizeof(xen_pfn_t),
 					   &pagelist, mmap_return_errors, &state);
@@ -587,7 +587,7 @@ static void privcmd_close(struct vm_area_struct *vma)
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_gfn_range(vma, numpgs, pages);
 	if (rc == 0)
 		free_xenballooned_pages(numpgs, pages);
 	else
diff --git a/drivers/xen/xlate_mmu.c b/drivers/xen/xlate_mmu.c
index 58a5389..cff2387 100644
--- a/drivers/xen/xlate_mmu.c
+++ b/drivers/xen/xlate_mmu.c
@@ -38,8 +38,8 @@
 #include <xen/interface/xen.h>
 #include <xen/interface/memory.h>
 
-/* map fgmfn of domid to lpfn in the current domain */
-static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
+/* map fgfn of domid to lpfn in the current domain */
+static int map_foreign_page(unsigned long lpfn, unsigned long fgfn,
 			    unsigned int domid)
 {
 	int rc;
@@ -49,7 +49,7 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 		.size = 1,
 		.space = XENMAPSPACE_gmfn_foreign,
 	};
-	xen_ulong_t idx = fgmfn;
+	xen_ulong_t idx = fgfn;
 	xen_pfn_t gpfn = lpfn;
 	int err = 0;
 
@@ -62,13 +62,13 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 }
 
 struct remap_data {
-	xen_pfn_t *fgmfn; /* foreign domain's gmfn */
+	xen_pfn_t *fgfn; /* foreign domain's gfn */
 	pgprot_t prot;
 	domid_t  domid;
 	struct vm_area_struct *vma;
 	int index;
 	struct page **pages;
-	struct xen_remap_mfn_info *info;
+	struct xen_remap_gfn_info *info;
 	int *err_ptr;
 	int mapped;
 };
@@ -82,20 +82,20 @@ static int remap_pte_fn(pte_t *ptep, pgtable_t token, unsigned long addr,
 	pte_t pte = pte_mkspecial(pfn_pte(pfn, info->prot));
 	int rc;
 
-	rc = map_foreign_page(pfn, *info->fgmfn, info->domid);
+	rc = map_foreign_page(pfn, *info->fgfn, info->domid);
 	*info->err_ptr++ = rc;
 	if (!rc) {
 		set_pte_at(info->vma->vm_mm, addr, ptep, pte);
 		info->mapped++;
 	}
-	info->fgmfn++;
+	info->fgfn++;
 
 	return 0;
 }
 
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-			      xen_pfn_t *mfn, int nr,
+			      xen_pfn_t *gfn, int nr,
 			      int *err_ptr, pgprot_t prot,
 			      unsigned domid,
 			      struct page **pages)
@@ -108,7 +108,7 @@ int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 	   x86 PVOPS */
 	BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));
 
-	data.fgmfn = mfn;
+	data.fgfn = gfn;
 	data.prot  = prot;
 	data.domid = domid;
 	data.vma   = vma;
diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h
index a853168..7ddeeda 100644
--- a/include/uapi/xen/privcmd.h
+++ b/include/uapi/xen/privcmd.h
@@ -44,6 +44,10 @@ struct privcmd_hypercall {
 
 struct privcmd_mmap_entry {
 	__u64 va;
+	/*
+	 * This should be a GFN. It's not possible to change the name because
+	 * it's exposed to the user-space.
+	 */
 	__u64 mfn;
 	__u64 npages;
 };
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 0ce4f32..e4e214a 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -30,7 +30,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
 struct vm_area_struct;
 
 /*
- * xen_remap_domain_mfn_array() - map an array of foreign frames
+ * xen_remap_domain_gfn_array() - map an array of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     Array of GFNs to map
@@ -46,14 +46,14 @@ struct vm_area_struct;
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t *gfn, int nr,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid,
 			       struct page **pages);
 
-/* xen_remap_domain_mfn_range() - map a range of foreign frames
+/* xen_remap_domain_gfn_range() - map a range of foreign frames
  * @vma:     VMA to map the pages into
  * @addr:    Address at which to map the pages
  * @gfn:     First GFN to map.
@@ -65,12 +65,12 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
  * Returns the number of successfully mapped frames, or a -ve error
  * code.
  */
-int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       unsigned long addr,
 			       xen_pfn_t gfn, int nr,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages);
-int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
+int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
 			       int numpgs, struct page **pages);
 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
 			      unsigned long addr,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
  (?)
  (?)
@ 2015-08-04 23:16     ` Boris Ostrovsky
  -1 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-04 23:16 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: ian.campbell, stefano.stabellini, linux-kernel, Russell King,
	Konrad Rzeszutek Wilk, David Vrabel, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev, linux-scsi, linuxppc-dev,
	linux-fbdev, linux-arm-kernel

On 08/04/2015 02:12 PM, Julien Grall wrote:
>   
>   /*
>    * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>   
>   /* VIRT <-> MACHINE conversion */
>   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))

This looks like unnecessary change.


> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>   
>   static unsigned long vmalloc_to_mfn(void *address)
>   {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>   }

Are you sure? This will return vmalloc_to_pfn(address)).


-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 23:16     ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-04 23:16 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev

On 08/04/2015 02:12 PM, Julien Grall wrote:
>   
>   /*
>    * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>   
>   /* VIRT <-> MACHINE conversion */
>   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))

This looks like unnecessary change.


> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>   
>   static unsigned long vmalloc_to_mfn(void *address)
>   {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>   }

Are you sure? This will return vmalloc_to_pfn(address)).


-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 23:16     ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-04 23:16 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/04/2015 02:12 PM, Julien Grall wrote:
>   
>   /*
>    * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>   
>   /* VIRT <-> MACHINE conversion */
>   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))

This looks like unnecessary change.


> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>   
>   static unsigned long vmalloc_to_mfn(void *address)
>   {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>   }

Are you sure? This will return vmalloc_to_pfn(address)).


-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-04 23:16     ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-04 23:16 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/04/2015 02:12 PM, Julien Grall wrote:
>   
>   /*
>    * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>   
>   /* VIRT <-> MACHINE conversion */
>   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))

This looks like unnecessary change.


> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>   
>   static unsigned long vmalloc_to_mfn(void *address)
>   {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>   }

Are you sure? This will return vmalloc_to_pfn(address)).


-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
                     ` (4 preceding siblings ...)
  (?)
@ 2015-08-04 23:16   ` Boris Ostrovsky
  -1 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-04 23:16 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Thomas Gleixner, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev, Roger Pau Monné

On 08/04/2015 02:12 PM, Julien Grall wrote:
>   
>   /*
>    * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>   
>   /* VIRT <-> MACHINE conversion */
>   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))

This looks like unnecessary change.


> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>   
>   static unsigned long vmalloc_to_mfn(void *address)
>   {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>   }

Are you sure? This will return vmalloc_to_pfn(address)).


-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
  2015-08-04 18:12   ` Julien Grall
@ 2015-08-05  9:49     ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05  9:49 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> The swiotlb is required when programming a DMA address on ARM when a
> device is not protected by an IOMMU.
> 
> In this case, the DMA address should always be equal to the machine address.
> For DOM0 memory, Xen ensure it by have an identity mapping between the
> guest address and host address. However, when mapping a foreign grant
> reference, the 1:1 model doesn't work.
> 
> For ARM guest, most of the callers of pfn_to_mfn expects to get a GFN
> (Guest Frame Number), i.e a PFN (Page Frame Number) from the Linux point
> of view given that all ARM guest are auto-translated.
> 
> Even though the name pfn_to_mfn is misleading, we need to ensure that
> those caller get a GFN and not by mistake a MFN. In pratical, I haven't
> seen error related to this but we should fix it for the sake of
> correctness.
> 
> In order to fix the implementation of pfn_to_mfn on ARM in a follow-up
> patch, we have to introduce new helpers to return the DMA from a PFN and
> the invert.
> 
> On x86, the new helpers will be an alias of pfn_to_mfn and mfn_to_pfn.
> 
> The helpers will be used in swiotlb and xen_biovec_phys_mergeable.
> 
> This is necessary in the latter because we have to ensure that the
> biovec code will not try to merge a biovec using foreign page and
> another using Linux memory.
> 
> Lastly, the helper mfn_to_local_pfn has been renamed to dnf_to_local_pfn
                                                          ^ please update


> given that the only usage was in swiotlb.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> 
> ---
>     Changes in v2:
>         - Use bfn (Bus Frame Number) rather than dfn to match the
>         proposed terminology for pv-iommu hypercall.
> ---
>  arch/arm/include/asm/xen/page.h | 23 +++++++++++++++++++++--
>  arch/arm/xen/mm.c               |  4 ++--
>  arch/x86/include/asm/xen/page.h |  8 ++++++--
>  drivers/xen/biomerge.c          |  6 +++---
>  drivers/xen/swiotlb-xen.c       | 16 ++++++++--------
>  5 files changed, 40 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 98b1084..bc5e77c 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -52,7 +52,26 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  	return mfn;
>  }
>  
> -#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
> +/* Pseudo-physical <-> BUS conversion */
> +static inline unsigned long pfn_to_bfn(unsigned long pfn)
> +{
> +	unsigned long mfn;
> +
> +	if (phys_to_mach.rb_node != NULL) {
> +		mfn = __pfn_to_mfn(pfn);
> +		if (mfn != INVALID_P2M_ENTRY)
> +			return mfn;
> +	}
> +
> +	return pfn;
> +}
> +
> +static inline unsigned long bfn_to_pfn(unsigned long bfn)
> +{
> +	return bfn;
> +}
> +
> +#define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> @@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
>  
>  bool xen_arch_need_swiotlb(struct device *dev,
>  			   unsigned long pfn,
> -			   unsigned long mfn);
> +			   unsigned long dfn);
>  unsigned long xen_get_swiotlb_free_pages(unsigned int order);

You missed a bunch of dfn->bfn renamings.

Aside from those and the commit message error:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  #endif /* _ASM_ARM_XEN_PAGE_H */
> diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
> index 03e75fe..12bde72 100644
> --- a/arch/arm/xen/mm.c
> +++ b/arch/arm/xen/mm.c
> @@ -139,9 +139,9 @@ void __xen_dma_sync_single_for_device(struct device *hwdev,
>  
>  bool xen_arch_need_swiotlb(struct device *dev,
>  			   unsigned long pfn,
> -			   unsigned long mfn)
> +			   unsigned long dfn)
>  {
> -	return (!hypercall_cflush && (pfn != mfn) && !is_device_dma_coherent(dev));
> +	return (!hypercall_cflush && (pfn != dfn) && !is_device_dma_coherent(dev));
>  }
>  
>  int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index c44a5d5..8ba04b8 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -178,6 +178,10 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Bus conversion */
> +#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> +#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +
>  /*
>   * We detect special mappings in one of two ways:
>   *  1. If the MFN is an I/O page then Xen will set the m2p entry
> @@ -198,7 +202,7 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>   *      require. In all the cases we care about, the FOREIGN_FRAME bit is
>   *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
>   */
> -static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
> +static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> @@ -264,7 +268,7 @@ void make_lowmem_page_readwrite(void *vaddr);
>  
>  static inline bool xen_arch_need_swiotlb(struct device *dev,
>  					 unsigned long pfn,
> -					 unsigned long mfn)
> +					 unsigned long bfn)
>  {
>  	return false;
>  }
> diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
> index 0edb91c..8ae2fc90 100644
> --- a/drivers/xen/biomerge.c
> +++ b/drivers/xen/biomerge.c
> @@ -6,10 +6,10 @@
>  bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
>  			       const struct bio_vec *vec2)
>  {
> -	unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page));
> -	unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page));
> +	unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
> +	unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
>  
>  	return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) &&
> -		((mfn1 == mfn2) || ((mfn1+1) == mfn2));
> +		((bfn1 == bfn2) || ((bfn1+1) == bfn2));
>  }
>  EXPORT_SYMBOL(xen_biovec_phys_mergeable);
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 4c54932..d757a3e 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -82,8 +82,8 @@ static u64 start_dma_addr;
>   */
>  static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  {
> -	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
> -	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
> +	unsigned long bfn = pfn_to_bfn(PFN_DOWN(paddr));
> +	dma_addr_t dma = (dma_addr_t)bfn << PAGE_SHIFT;
>  
>  	dma |= paddr & ~PAGE_MASK;
>  
> @@ -92,7 +92,7 @@ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  
>  static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
>  {
> -	unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr));
> +	unsigned long pfn = bfn_to_pfn(PFN_DOWN(baddr));
>  	dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT;
>  	phys_addr_t paddr = dma;
>  
> @@ -110,15 +110,15 @@ static int check_pages_physically_contiguous(unsigned long pfn,
>  					     unsigned int offset,
>  					     size_t length)
>  {
> -	unsigned long next_mfn;
> +	unsigned long next_bfn;
>  	int i;
>  	int nr_pages;
>  
> -	next_mfn = pfn_to_mfn(pfn);
> +	next_bfn = pfn_to_bfn(pfn);
>  	nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
>  
>  	for (i = 1; i < nr_pages; i++) {
> -		if (pfn_to_mfn(++pfn) != ++next_mfn)
> +		if (pfn_to_bfn(++pfn) != ++next_bfn)
>  			return 0;
>  	}
>  	return 1;
> @@ -138,8 +138,8 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
>  
>  static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
>  {
> -	unsigned long mfn = PFN_DOWN(dma_addr);
> -	unsigned long pfn = mfn_to_local_pfn(mfn);
> +	unsigned long bfn = PFN_DOWN(dma_addr);
> +	unsigned long pfn = bfn_to_local_pfn(bfn);
>  	phys_addr_t paddr;
>  
>  	/* If the address is outside our domain, it CAN
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
@ 2015-08-05  9:49     ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05  9:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> The swiotlb is required when programming a DMA address on ARM when a
> device is not protected by an IOMMU.
> 
> In this case, the DMA address should always be equal to the machine address.
> For DOM0 memory, Xen ensure it by have an identity mapping between the
> guest address and host address. However, when mapping a foreign grant
> reference, the 1:1 model doesn't work.
> 
> For ARM guest, most of the callers of pfn_to_mfn expects to get a GFN
> (Guest Frame Number), i.e a PFN (Page Frame Number) from the Linux point
> of view given that all ARM guest are auto-translated.
> 
> Even though the name pfn_to_mfn is misleading, we need to ensure that
> those caller get a GFN and not by mistake a MFN. In pratical, I haven't
> seen error related to this but we should fix it for the sake of
> correctness.
> 
> In order to fix the implementation of pfn_to_mfn on ARM in a follow-up
> patch, we have to introduce new helpers to return the DMA from a PFN and
> the invert.
> 
> On x86, the new helpers will be an alias of pfn_to_mfn and mfn_to_pfn.
> 
> The helpers will be used in swiotlb and xen_biovec_phys_mergeable.
> 
> This is necessary in the latter because we have to ensure that the
> biovec code will not try to merge a biovec using foreign page and
> another using Linux memory.
> 
> Lastly, the helper mfn_to_local_pfn has been renamed to dnf_to_local_pfn
                                                          ^ please update


> given that the only usage was in swiotlb.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86 at kernel.org
> Cc: linux-arm-kernel at lists.infradead.org
> 
> ---
>     Changes in v2:
>         - Use bfn (Bus Frame Number) rather than dfn to match the
>         proposed terminology for pv-iommu hypercall.
> ---
>  arch/arm/include/asm/xen/page.h | 23 +++++++++++++++++++++--
>  arch/arm/xen/mm.c               |  4 ++--
>  arch/x86/include/asm/xen/page.h |  8 ++++++--
>  drivers/xen/biomerge.c          |  6 +++---
>  drivers/xen/swiotlb-xen.c       | 16 ++++++++--------
>  5 files changed, 40 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 98b1084..bc5e77c 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -52,7 +52,26 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  	return mfn;
>  }
>  
> -#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
> +/* Pseudo-physical <-> BUS conversion */
> +static inline unsigned long pfn_to_bfn(unsigned long pfn)
> +{
> +	unsigned long mfn;
> +
> +	if (phys_to_mach.rb_node != NULL) {
> +		mfn = __pfn_to_mfn(pfn);
> +		if (mfn != INVALID_P2M_ENTRY)
> +			return mfn;
> +	}
> +
> +	return pfn;
> +}
> +
> +static inline unsigned long bfn_to_pfn(unsigned long bfn)
> +{
> +	return bfn;
> +}
> +
> +#define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> @@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
>  
>  bool xen_arch_need_swiotlb(struct device *dev,
>  			   unsigned long pfn,
> -			   unsigned long mfn);
> +			   unsigned long dfn);
>  unsigned long xen_get_swiotlb_free_pages(unsigned int order);

You missed a bunch of dfn->bfn renamings.

Aside from those and the commit message error:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  #endif /* _ASM_ARM_XEN_PAGE_H */
> diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
> index 03e75fe..12bde72 100644
> --- a/arch/arm/xen/mm.c
> +++ b/arch/arm/xen/mm.c
> @@ -139,9 +139,9 @@ void __xen_dma_sync_single_for_device(struct device *hwdev,
>  
>  bool xen_arch_need_swiotlb(struct device *dev,
>  			   unsigned long pfn,
> -			   unsigned long mfn)
> +			   unsigned long dfn)
>  {
> -	return (!hypercall_cflush && (pfn != mfn) && !is_device_dma_coherent(dev));
> +	return (!hypercall_cflush && (pfn != dfn) && !is_device_dma_coherent(dev));
>  }
>  
>  int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index c44a5d5..8ba04b8 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -178,6 +178,10 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Bus conversion */
> +#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> +#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +
>  /*
>   * We detect special mappings in one of two ways:
>   *  1. If the MFN is an I/O page then Xen will set the m2p entry
> @@ -198,7 +202,7 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>   *      require. In all the cases we care about, the FOREIGN_FRAME bit is
>   *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
>   */
> -static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
> +static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> @@ -264,7 +268,7 @@ void make_lowmem_page_readwrite(void *vaddr);
>  
>  static inline bool xen_arch_need_swiotlb(struct device *dev,
>  					 unsigned long pfn,
> -					 unsigned long mfn)
> +					 unsigned long bfn)
>  {
>  	return false;
>  }
> diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
> index 0edb91c..8ae2fc90 100644
> --- a/drivers/xen/biomerge.c
> +++ b/drivers/xen/biomerge.c
> @@ -6,10 +6,10 @@
>  bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
>  			       const struct bio_vec *vec2)
>  {
> -	unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page));
> -	unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page));
> +	unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
> +	unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
>  
>  	return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) &&
> -		((mfn1 == mfn2) || ((mfn1+1) == mfn2));
> +		((bfn1 == bfn2) || ((bfn1+1) == bfn2));
>  }
>  EXPORT_SYMBOL(xen_biovec_phys_mergeable);
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 4c54932..d757a3e 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -82,8 +82,8 @@ static u64 start_dma_addr;
>   */
>  static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  {
> -	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
> -	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
> +	unsigned long bfn = pfn_to_bfn(PFN_DOWN(paddr));
> +	dma_addr_t dma = (dma_addr_t)bfn << PAGE_SHIFT;
>  
>  	dma |= paddr & ~PAGE_MASK;
>  
> @@ -92,7 +92,7 @@ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  
>  static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
>  {
> -	unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr));
> +	unsigned long pfn = bfn_to_pfn(PFN_DOWN(baddr));
>  	dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT;
>  	phys_addr_t paddr = dma;
>  
> @@ -110,15 +110,15 @@ static int check_pages_physically_contiguous(unsigned long pfn,
>  					     unsigned int offset,
>  					     size_t length)
>  {
> -	unsigned long next_mfn;
> +	unsigned long next_bfn;
>  	int i;
>  	int nr_pages;
>  
> -	next_mfn = pfn_to_mfn(pfn);
> +	next_bfn = pfn_to_bfn(pfn);
>  	nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
>  
>  	for (i = 1; i < nr_pages; i++) {
> -		if (pfn_to_mfn(++pfn) != ++next_mfn)
> +		if (pfn_to_bfn(++pfn) != ++next_bfn)
>  			return 0;
>  	}
>  	return 1;
> @@ -138,8 +138,8 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
>  
>  static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
>  {
> -	unsigned long mfn = PFN_DOWN(dma_addr);
> -	unsigned long pfn = mfn_to_local_pfn(mfn);
> +	unsigned long bfn = PFN_DOWN(dma_addr);
> +	unsigned long pfn = bfn_to_local_pfn(bfn);
>  	phys_addr_t paddr;
>  
>  	/* If the address is outside our domain, it CAN
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
  2015-08-04 18:12   ` Julien Grall
  (?)
  (?)
@ 2015-08-05  9:49   ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05  9:49 UTC (permalink / raw)
  To: Julien Grall
  Cc: x86, Russell King, ian.campbell, stefano.stabellini,
	linux-kernel, Ingo Molnar, David Vrabel, H. Peter Anvin,
	xen-devel, Boris Ostrovsky, Thomas Gleixner, linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> The swiotlb is required when programming a DMA address on ARM when a
> device is not protected by an IOMMU.
> 
> In this case, the DMA address should always be equal to the machine address.
> For DOM0 memory, Xen ensure it by have an identity mapping between the
> guest address and host address. However, when mapping a foreign grant
> reference, the 1:1 model doesn't work.
> 
> For ARM guest, most of the callers of pfn_to_mfn expects to get a GFN
> (Guest Frame Number), i.e a PFN (Page Frame Number) from the Linux point
> of view given that all ARM guest are auto-translated.
> 
> Even though the name pfn_to_mfn is misleading, we need to ensure that
> those caller get a GFN and not by mistake a MFN. In pratical, I haven't
> seen error related to this but we should fix it for the sake of
> correctness.
> 
> In order to fix the implementation of pfn_to_mfn on ARM in a follow-up
> patch, we have to introduce new helpers to return the DMA from a PFN and
> the invert.
> 
> On x86, the new helpers will be an alias of pfn_to_mfn and mfn_to_pfn.
> 
> The helpers will be used in swiotlb and xen_biovec_phys_mergeable.
> 
> This is necessary in the latter because we have to ensure that the
> biovec code will not try to merge a biovec using foreign page and
> another using Linux memory.
> 
> Lastly, the helper mfn_to_local_pfn has been renamed to dnf_to_local_pfn
                                                          ^ please update


> given that the only usage was in swiotlb.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> 
> ---
>     Changes in v2:
>         - Use bfn (Bus Frame Number) rather than dfn to match the
>         proposed terminology for pv-iommu hypercall.
> ---
>  arch/arm/include/asm/xen/page.h | 23 +++++++++++++++++++++--
>  arch/arm/xen/mm.c               |  4 ++--
>  arch/x86/include/asm/xen/page.h |  8 ++++++--
>  drivers/xen/biomerge.c          |  6 +++---
>  drivers/xen/swiotlb-xen.c       | 16 ++++++++--------
>  5 files changed, 40 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 98b1084..bc5e77c 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -52,7 +52,26 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  	return mfn;
>  }
>  
> -#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
> +/* Pseudo-physical <-> BUS conversion */
> +static inline unsigned long pfn_to_bfn(unsigned long pfn)
> +{
> +	unsigned long mfn;
> +
> +	if (phys_to_mach.rb_node != NULL) {
> +		mfn = __pfn_to_mfn(pfn);
> +		if (mfn != INVALID_P2M_ENTRY)
> +			return mfn;
> +	}
> +
> +	return pfn;
> +}
> +
> +static inline unsigned long bfn_to_pfn(unsigned long bfn)
> +{
> +	return bfn;
> +}
> +
> +#define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> @@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
>  
>  bool xen_arch_need_swiotlb(struct device *dev,
>  			   unsigned long pfn,
> -			   unsigned long mfn);
> +			   unsigned long dfn);
>  unsigned long xen_get_swiotlb_free_pages(unsigned int order);

You missed a bunch of dfn->bfn renamings.

Aside from those and the commit message error:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  #endif /* _ASM_ARM_XEN_PAGE_H */
> diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
> index 03e75fe..12bde72 100644
> --- a/arch/arm/xen/mm.c
> +++ b/arch/arm/xen/mm.c
> @@ -139,9 +139,9 @@ void __xen_dma_sync_single_for_device(struct device *hwdev,
>  
>  bool xen_arch_need_swiotlb(struct device *dev,
>  			   unsigned long pfn,
> -			   unsigned long mfn)
> +			   unsigned long dfn)
>  {
> -	return (!hypercall_cflush && (pfn != mfn) && !is_device_dma_coherent(dev));
> +	return (!hypercall_cflush && (pfn != dfn) && !is_device_dma_coherent(dev));
>  }
>  
>  int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index c44a5d5..8ba04b8 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -178,6 +178,10 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Bus conversion */
> +#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> +#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +
>  /*
>   * We detect special mappings in one of two ways:
>   *  1. If the MFN is an I/O page then Xen will set the m2p entry
> @@ -198,7 +202,7 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>   *      require. In all the cases we care about, the FOREIGN_FRAME bit is
>   *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
>   */
> -static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
> +static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> @@ -264,7 +268,7 @@ void make_lowmem_page_readwrite(void *vaddr);
>  
>  static inline bool xen_arch_need_swiotlb(struct device *dev,
>  					 unsigned long pfn,
> -					 unsigned long mfn)
> +					 unsigned long bfn)
>  {
>  	return false;
>  }
> diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
> index 0edb91c..8ae2fc90 100644
> --- a/drivers/xen/biomerge.c
> +++ b/drivers/xen/biomerge.c
> @@ -6,10 +6,10 @@
>  bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
>  			       const struct bio_vec *vec2)
>  {
> -	unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page));
> -	unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page));
> +	unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
> +	unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
>  
>  	return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) &&
> -		((mfn1 == mfn2) || ((mfn1+1) == mfn2));
> +		((bfn1 == bfn2) || ((bfn1+1) == bfn2));
>  }
>  EXPORT_SYMBOL(xen_biovec_phys_mergeable);
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 4c54932..d757a3e 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -82,8 +82,8 @@ static u64 start_dma_addr;
>   */
>  static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  {
> -	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
> -	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
> +	unsigned long bfn = pfn_to_bfn(PFN_DOWN(paddr));
> +	dma_addr_t dma = (dma_addr_t)bfn << PAGE_SHIFT;
>  
>  	dma |= paddr & ~PAGE_MASK;
>  
> @@ -92,7 +92,7 @@ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  
>  static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
>  {
> -	unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr));
> +	unsigned long pfn = bfn_to_pfn(PFN_DOWN(baddr));
>  	dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT;
>  	phys_addr_t paddr = dma;
>  
> @@ -110,15 +110,15 @@ static int check_pages_physically_contiguous(unsigned long pfn,
>  					     unsigned int offset,
>  					     size_t length)
>  {
> -	unsigned long next_mfn;
> +	unsigned long next_bfn;
>  	int i;
>  	int nr_pages;
>  
> -	next_mfn = pfn_to_mfn(pfn);
> +	next_bfn = pfn_to_bfn(pfn);
>  	nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
>  
>  	for (i = 1; i < nr_pages; i++) {
> -		if (pfn_to_mfn(++pfn) != ++next_mfn)
> +		if (pfn_to_bfn(++pfn) != ++next_bfn)
>  			return 0;
>  	}
>  	return 1;
> @@ -138,8 +138,8 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
>  
>  static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
>  {
> -	unsigned long mfn = PFN_DOWN(dma_addr);
> -	unsigned long pfn = mfn_to_local_pfn(mfn);
> +	unsigned long bfn = PFN_DOWN(dma_addr);
> +	unsigned long pfn = bfn_to_local_pfn(bfn);
>  	phys_addr_t paddr;
>  
>  	/* If the address is outside our domain, it CAN
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn
  2015-08-04 18:12   ` Julien Grall
@ 2015-08-05  9:52     ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05  9:52 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> After the commit introducing convertion between DMA and guest address,
                                                                  ^ addresses

> all the callers of pfn_to_mfn are expecting to get a GFN (Guest Frame
> Number). On ARM, all the guests are auto-translated so the GFN is equal
> to the Linux PFN (Pseudo-physical Frame Number).
> 
> The current implementation may return an MFN if the caller is passing a
> PFN associated to a mapped foreign grant. In pratical, I haven't seen
                                               ^ practice


> the problem on running guest but we should fix it for the sake of
> correctness.
> 
> Correct the implementation by always returning the pfn passed in parameter.
> 
> A follow-up patch will take care to rename pfn_to_mfn to a suitable
> name.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: linux-arm-kernel@lists.infradead.org

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  arch/arm/include/asm/xen/page.h | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index bc5e77c..087d86e 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -36,14 +36,6 @@ extern struct rb_root phys_to_mach;
>  
>  static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
> -	unsigned long mfn;
> -
> -	if (phys_to_mach.rb_node != NULL) {
> -		mfn = __pfn_to_mfn(pfn);
> -		if (mfn != INVALID_P2M_ENTRY)
> -			return mfn;
> -	}
> -
>  	return pfn;
>  }
>  
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn
@ 2015-08-05  9:52     ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05  9:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> After the commit introducing convertion between DMA and guest address,
                                                                  ^ addresses

> all the callers of pfn_to_mfn are expecting to get a GFN (Guest Frame
> Number). On ARM, all the guests are auto-translated so the GFN is equal
> to the Linux PFN (Pseudo-physical Frame Number).
> 
> The current implementation may return an MFN if the caller is passing a
> PFN associated to a mapped foreign grant. In pratical, I haven't seen
                                               ^ practice


> the problem on running guest but we should fix it for the sake of
> correctness.
> 
> Correct the implementation by always returning the pfn passed in parameter.
> 
> A follow-up patch will take care to rename pfn_to_mfn to a suitable
> name.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: linux-arm-kernel at lists.infradead.org

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  arch/arm/include/asm/xen/page.h | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index bc5e77c..087d86e 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -36,14 +36,6 @@ extern struct rb_root phys_to_mach;
>  
>  static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
> -	unsigned long mfn;
> -
> -	if (phys_to_mach.rb_node != NULL) {
> -		mfn = __pfn_to_mfn(pfn);
> -		if (mfn != INVALID_P2M_ENTRY)
> -			return mfn;
> -	}
> -
>  	return pfn;
>  }
>  
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn
  2015-08-04 18:12   ` Julien Grall
  (?)
@ 2015-08-05  9:52   ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05  9:52 UTC (permalink / raw)
  To: Julien Grall
  Cc: Russell King, ian.campbell, stefano.stabellini, linux-kernel,
	xen-devel, linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> After the commit introducing convertion between DMA and guest address,
                                                                  ^ addresses

> all the callers of pfn_to_mfn are expecting to get a GFN (Guest Frame
> Number). On ARM, all the guests are auto-translated so the GFN is equal
> to the Linux PFN (Pseudo-physical Frame Number).
> 
> The current implementation may return an MFN if the caller is passing a
> PFN associated to a mapped foreign grant. In pratical, I haven't seen
                                               ^ practice


> the problem on running guest but we should fix it for the sake of
> correctness.
> 
> Correct the implementation by always returning the pfn passed in parameter.
> 
> A follow-up patch will take care to rename pfn_to_mfn to a suitable
> name.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: linux-arm-kernel@lists.infradead.org

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  arch/arm/include/asm/xen/page.h | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index bc5e77c..087d86e 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -36,14 +36,6 @@ extern struct rb_root phys_to_mach;
>  
>  static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
> -	unsigned long mfn;
> -
> -	if (phys_to_mach.rb_node != NULL) {
> -		mfn = __pfn_to_mfn(pfn);
> -		if (mfn != INVALID_P2M_ENTRY)
> -			return mfn;
> -	}
> -
>  	return pfn;
>  }
>  
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  2015-08-04 18:12 ` [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn Julien Grall
@ 2015-08-05 10:01   ` Stefano Stabellini
  2015-08-05 10:01   ` Stefano Stabellini
  1 sibling, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Konrad Rzeszutek Wilk, Boris Ostrovsky, David Vrabel

On Tue, 4 Aug 2015, Julien Grall wrote:
> All the caller of xen_tmem_{get,put}_page have a struct page * in hand
> and call pfn_to_gfn for the only benefits of these 2 functions.
> 
> Rather than passing the pfn in parameter, pass directly the page and use
> directly page_to_gfn.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  drivers/xen/tmem.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 28c97ff..e0c8dc7 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -129,21 +129,17 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  /* xen generic tmem ops */
>  
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
> -			     u32 index, unsigned long pfn)
> +			     u32 index, struct page *page)
>  {
> -	unsigned long gmfn = pfn_to_gfn(pfn);
> -
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
> -		gmfn, 0, 0, 0);
> +			   page_to_gfn(page), 0, 0, 0);
>  }
>  
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
> -			     u32 index, unsigned long pfn)
> +			     u32 index, struct page *page)
>  {
> -	unsigned long gmfn = pfn_to_gfn(pfn);
> -
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
> -		gmfn, 0, 0, 0);
> +			   page_to_gfn(page), 0, 0, 0);
>  }
>  
>  static int xen_tmem_flush_page(u32 pool_id, struct tmem_oid oid, u32 index)
> @@ -173,14 +169,13 @@ static void tmem_cleancache_put_page(int pool, struct cleancache_filekey key,
>  {
>  	u32 ind = (u32) index;
>  	struct tmem_oid oid = *(struct tmem_oid *)&key;
> -	unsigned long pfn = page_to_pfn(page);
>  
>  	if (pool < 0)
>  		return;
>  	if (ind != index)
>  		return;
>  	mb(); /* ensure page is quiescent; tmem may address it with an alias */
> -	(void)xen_tmem_put_page((u32)pool, oid, ind, pfn);
> +	(void)xen_tmem_put_page((u32)pool, oid, ind, page);
>  }
>  
>  static int tmem_cleancache_get_page(int pool, struct cleancache_filekey key,
> @@ -287,7 +282,6 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
>  {
>  	u64 ind64 = (u64)offset;
>  	u32 ind = (u32)offset;
> -	unsigned long pfn = page_to_pfn(page);
>  	int pool = tmem_frontswap_poolid;
>  	int ret;
>  
> @@ -296,7 +290,7 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
>  	if (ind64 != ind)
>  		return -1;
>  	mb(); /* ensure page is quiescent; tmem may address it with an alias */
> -	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), pfn);
> +	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), page);
>  	/* translate Xen tmem return values to linux semantics */
>  	if (ret == 1)
>  		return 0;
> @@ -313,7 +307,6 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
>  {
>  	u64 ind64 = (u64)offset;
>  	u32 ind = (u32)offset;
> -	unsigned long pfn = page_to_pfn(page);
>  	int pool = tmem_frontswap_poolid;
>  	int ret;
>  
> @@ -321,7 +314,7 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
>  		return -1;
>  	if (ind64 != ind)
>  		return -1;
> -	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), pfn);
> +	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), page);
>  	/* translate Xen tmem return values to linux semantics */
>  	if (ret == 1)
>  		return 0;
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn
  2015-08-04 18:12 ` [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn Julien Grall
  2015-08-05 10:01   ` Stefano Stabellini
@ 2015-08-05 10:01   ` Stefano Stabellini
  1 sibling, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: ian.campbell, stefano.stabellini, linux-kernel, David Vrabel,
	xen-devel, Boris Ostrovsky

On Tue, 4 Aug 2015, Julien Grall wrote:
> All the caller of xen_tmem_{get,put}_page have a struct page * in hand
> and call pfn_to_gfn for the only benefits of these 2 functions.
> 
> Rather than passing the pfn in parameter, pass directly the page and use
> directly page_to_gfn.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>  drivers/xen/tmem.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 28c97ff..e0c8dc7 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -129,21 +129,17 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  /* xen generic tmem ops */
>  
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
> -			     u32 index, unsigned long pfn)
> +			     u32 index, struct page *page)
>  {
> -	unsigned long gmfn = pfn_to_gfn(pfn);
> -
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
> -		gmfn, 0, 0, 0);
> +			   page_to_gfn(page), 0, 0, 0);
>  }
>  
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
> -			     u32 index, unsigned long pfn)
> +			     u32 index, struct page *page)
>  {
> -	unsigned long gmfn = pfn_to_gfn(pfn);
> -
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
> -		gmfn, 0, 0, 0);
> +			   page_to_gfn(page), 0, 0, 0);
>  }
>  
>  static int xen_tmem_flush_page(u32 pool_id, struct tmem_oid oid, u32 index)
> @@ -173,14 +169,13 @@ static void tmem_cleancache_put_page(int pool, struct cleancache_filekey key,
>  {
>  	u32 ind = (u32) index;
>  	struct tmem_oid oid = *(struct tmem_oid *)&key;
> -	unsigned long pfn = page_to_pfn(page);
>  
>  	if (pool < 0)
>  		return;
>  	if (ind != index)
>  		return;
>  	mb(); /* ensure page is quiescent; tmem may address it with an alias */
> -	(void)xen_tmem_put_page((u32)pool, oid, ind, pfn);
> +	(void)xen_tmem_put_page((u32)pool, oid, ind, page);
>  }
>  
>  static int tmem_cleancache_get_page(int pool, struct cleancache_filekey key,
> @@ -287,7 +282,6 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
>  {
>  	u64 ind64 = (u64)offset;
>  	u32 ind = (u32)offset;
> -	unsigned long pfn = page_to_pfn(page);
>  	int pool = tmem_frontswap_poolid;
>  	int ret;
>  
> @@ -296,7 +290,7 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
>  	if (ind64 != ind)
>  		return -1;
>  	mb(); /* ensure page is quiescent; tmem may address it with an alias */
> -	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), pfn);
> +	ret = xen_tmem_put_page(pool, oswiz(type, ind), iswiz(ind), page);
>  	/* translate Xen tmem return values to linux semantics */
>  	if (ret == 1)
>  		return 0;
> @@ -313,7 +307,6 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
>  {
>  	u64 ind64 = (u64)offset;
>  	u32 ind = (u32)offset;
> -	unsigned long pfn = page_to_pfn(page);
>  	int pool = tmem_frontswap_poolid;
>  	int ret;
>  
> @@ -321,7 +314,7 @@ static int tmem_frontswap_load(unsigned type, pgoff_t offset,
>  		return -1;
>  	if (ind64 != ind)
>  		return -1;
> -	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), pfn);
> +	ret = xen_tmem_get_page(pool, oswiz(type, ind), iswiz(ind), page);
>  	/* translate Xen tmem return values to linux semantics */
>  	if (ret == 1)
>  		return 0;
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 23:16     ` Boris Ostrovsky
  (?)
  (?)
@ 2015-08-05 10:07       ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:07 UTC (permalink / raw)
  To: Boris Ostrovsky
  Cc: Julien Grall, xen-devel, ian.campbell, stefano.stabellini,
	linux-kernel, Russell King, Konrad Rzeszutek Wilk, David Vrabel,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev, linux-scsi, linuxppc-dev,
	linux-fbdev, linux-arm-kernel

On Tue, 4 Aug 2015, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
> >     /*
> >    * We detect special mappings in one of two ways:
> > @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned
> > long mfn)
> >     /* VIRT <-> MACHINE conversion */
> >   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> > -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> >   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> >   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> > +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.
> 
> 
> > diff --git a/drivers/video/fbdev/xen-fbfront.c
> > b/drivers/video/fbdev/xen-fbfront.c
> > index 09dc447..25e3cce 100644
> > --- a/drivers/video/fbdev/xen-fbfront.c
> > +++ b/drivers/video/fbdev/xen-fbfront.c
> > @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
> >     static unsigned long vmalloc_to_mfn(void *address)
> >   {
> > -	return pfn_to_mfn(vmalloc_to_pfn(address));
> > +	return pfn_to_gfn(vmalloc_to_pfn(address));
> >   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I think that is OK: there is no behavioural change here.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:07       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:07 UTC (permalink / raw)
  To: Boris Ostrovsky
  Cc: Julien Grall, xen-devel, ian.campbell, stefano.stabellini,
	linux-kernel, Russell King, Konrad Rzeszutek Wilk, David Vrabel,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev

On Tue, 4 Aug 2015, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
> >     /*
> >    * We detect special mappings in one of two ways:
> > @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned
> > long mfn)
> >     /* VIRT <-> MACHINE conversion */
> >   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> > -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> >   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> >   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> > +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.
> 
> 
> > diff --git a/drivers/video/fbdev/xen-fbfront.c
> > b/drivers/video/fbdev/xen-fbfront.c
> > index 09dc447..25e3cce 100644
> > --- a/drivers/video/fbdev/xen-fbfront.c
> > +++ b/drivers/video/fbdev/xen-fbfront.c
> > @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
> >     static unsigned long vmalloc_to_mfn(void *address)
> >   {
> > -	return pfn_to_mfn(vmalloc_to_pfn(address));
> > +	return pfn_to_gfn(vmalloc_to_pfn(address));
> >   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I think that is OK: there is no behavioural change here.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:07       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:07 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 4 Aug 2015, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
> >     /*
> >    * We detect special mappings in one of two ways:
> > @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned
> > long mfn)
> >     /* VIRT <-> MACHINE conversion */
> >   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> > -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> >   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> >   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> > +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.
> 
> 
> > diff --git a/drivers/video/fbdev/xen-fbfront.c
> > b/drivers/video/fbdev/xen-fbfront.c
> > index 09dc447..25e3cce 100644
> > --- a/drivers/video/fbdev/xen-fbfront.c
> > +++ b/drivers/video/fbdev/xen-fbfront.c
> > @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
> >     static unsigned long vmalloc_to_mfn(void *address)
> >   {
> > -	return pfn_to_mfn(vmalloc_to_pfn(address));
> > +	return pfn_to_gfn(vmalloc_to_pfn(address));
> >   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I think that is OK: there is no behavioural change here.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:07       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:07 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 4 Aug 2015, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
> >     /*
> >    * We detect special mappings in one of two ways:
> > @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned
> > long mfn)
> >     /* VIRT <-> MACHINE conversion */
> >   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> > -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> >   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> >   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> > +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.
> 
> 
> > diff --git a/drivers/video/fbdev/xen-fbfront.c
> > b/drivers/video/fbdev/xen-fbfront.c
> > index 09dc447..25e3cce 100644
> > --- a/drivers/video/fbdev/xen-fbfront.c
> > +++ b/drivers/video/fbdev/xen-fbfront.c
> > @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
> >     static unsigned long vmalloc_to_mfn(void *address)
> >   {
> > -	return pfn_to_mfn(vmalloc_to_pfn(address));
> > +	return pfn_to_gfn(vmalloc_to_pfn(address));
> >   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I think that is OK: there is no behavioural change here.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 23:16     ` Boris Ostrovsky
                       ` (2 preceding siblings ...)
  (?)
@ 2015-08-05 10:07     ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:07 UTC (permalink / raw)
  To: Boris Ostrovsky
  Cc: linux-fbdev, H. Peter Anvin, Russell King, linux-scsi, x86,
	Tomi Valkeinen, Jiri Slaby, xen-devel,
	Jean-Christophe Plagniol-Villard, linux-input, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, Julien Grall,
	David Vrabel, netdev, linuxppc-dev

On Tue, 4 Aug 2015, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
> >     /*
> >    * We detect special mappings in one of two ways:
> > @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned
> > long mfn)
> >     /* VIRT <-> MACHINE conversion */
> >   #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> > -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> >   #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> >   #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> > +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.
> 
> 
> > diff --git a/drivers/video/fbdev/xen-fbfront.c
> > b/drivers/video/fbdev/xen-fbfront.c
> > index 09dc447..25e3cce 100644
> > --- a/drivers/video/fbdev/xen-fbfront.c
> > +++ b/drivers/video/fbdev/xen-fbfront.c
> > @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
> >     static unsigned long vmalloc_to_mfn(void *address)
> >   {
> > -	return pfn_to_mfn(vmalloc_to_pfn(address));
> > +	return pfn_to_gfn(vmalloc_to_pfn(address));
> >   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I think that is OK: there is no behavioural change here.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
  (?)
  (?)
@ 2015-08-05 10:08     ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:08 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev, linux-scsi, linuxppc-dev,
	linux-fbdev, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 22710 bytes --]

On Tue, 4 Aug 2015, Julien Grall wrote:
> Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> is meant, I suspect this is because the first support for Xen was for
> PV. This resulted in some misimplementation of helpers on ARM and
> confused developers about the expected behavior.
> 
> For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> Although, if we look at the implementation on x86, it's returning a GFN.
> 
> For clarity and avoid new confusion, replace any reference to mfn with
> gfn in any helpers used by PV drivers. The x86 code will still keep some
> reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> to ensure this). No changes as been made in the hypercall field, even
> though they may be invalid, in order to keep the same as the defintion
> in xen repo.
> 
> Take also the opportunity to simplify simple construction such
> as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> will come in follow-up patches.
> 
> [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: linux-input@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Cc: linux-scsi@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-fbdev@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org

Aside from the x86 bits:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>     Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
>     The helpers contain a BUG_ON to ensure that it's never called for
>     auto-translated guests. I did as best as my can to determine whether
>     mfn or gfn helpers should be used. Although, I haven't tried to boot
>     it.
> 
>     It may be possible to do further cleanup in the mmu.c where I found
>     some check to auto-translated. I'm not sure why given that the pvmmu
>     callback are only used for non-auto translated guest.
> 
>     Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.
> 
>     Changes in v2:
>         - Give directly the URL to the commit rather than the commit ID
>         - xenstored_local_init: keep the cast to void *
>         - Typoes
>         - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
>         used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
>         smp.c and mm.c
> ---
>  arch/arm/include/asm/xen/page.h         | 13 +++++++------
>  arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
>  arch/x86/xen/smp.c                      |  2 +-
>  drivers/block/xen-blkfront.c            |  6 +++---
>  drivers/input/misc/xen-kbdfront.c       |  4 ++--
>  drivers/net/xen-netback/netback.c       |  4 ++--
>  drivers/net/xen-netfront.c              |  8 ++++----
>  drivers/scsi/xen-scsifront.c            |  8 +++-----
>  drivers/tty/hvc/hvc_xen.c               |  5 +++--
>  drivers/video/fbdev/xen-fbfront.c       |  4 ++--
>  drivers/xen/balloon.c                   |  2 +-
>  drivers/xen/events/events_base.c        |  2 +-
>  drivers/xen/events/events_fifo.c        |  4 ++--
>  drivers/xen/gntalloc.c                  |  3 ++-
>  drivers/xen/manage.c                    |  2 +-
>  drivers/xen/tmem.c                      |  4 ++--
>  drivers/xen/xenbus/xenbus_client.c      |  2 +-
>  drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
>  drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
>  include/xen/page.h                      |  4 ++--
>  20 files changed, 69 insertions(+), 51 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 087d86e..51e5bf1 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -34,14 +34,15 @@ typedef struct xpaddr {
>  unsigned long __pfn_to_mfn(unsigned long pfn);
>  extern struct rb_root phys_to_mach;
>  
> -static inline unsigned long pfn_to_mfn(unsigned long pfn)
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>  	return pfn;
>  }
>  
> -static inline unsigned long mfn_to_pfn(unsigned long mfn)
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
>  {
> -	return mfn;
> +	return gfn;
>  }
>  
>  /* Pseudo-physical <-> BUS conversion */
> @@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
>  
>  #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
> -/* VIRT <-> MACHINE conversion */
> -#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
>  
>  /* Only used in PV code. But ARM guests are always HVM. */
>  static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 8ba04b8..c2da42f 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
>  	unsigned long mfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return pfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	mfn = __pfn_to_mfn(pfn);
>  
> @@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return mfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	pfn = mfn_to_pfn_no_overrides(mfn);
>  	if (__pfn_to_mfn(pfn) != mfn)
> @@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return pfn;
> +	else
> +		return pfn_to_mfn(pfn);
> +}
> +
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return gfn;
> +	else
> +		return mfn_to_pfn(gfn);
> +}
> +
>  /* Pseudo-physical <-> Bus conversion */
> -#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> -#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
> +#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
>  
>  /*
>   * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>  #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> +
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
>  
>  static inline unsigned long pte_mfn(pte_t pte)
>  {
> diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
> index 8648438..1e0931b 100644
> --- a/arch/x86/xen/smp.c
> +++ b/arch/x86/xen/smp.c
> @@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
>  	}
>  #endif
>  	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
> -	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
> +	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
>  	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
>  		BUG();
>  
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 6d89ed3..2e541a4 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>                                 struct blkfront_info *info)
>  {
>  	struct grant *gnt_list_entry;
> -	unsigned long buffer_mfn;
> +	unsigned long buffer_gfn;
>  
>  	BUG_ON(list_empty(&info->grants));
>  	gnt_list_entry = list_first_entry(&info->grants, struct grant,
> @@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>  		BUG_ON(!pfn);
>  		gnt_list_entry->pfn = pfn;
>  	}
> -	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
> +	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
>  	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
>  	                                info->xbdev->otherend_id,
> -	                                buffer_mfn, 0);
> +	                                buffer_gfn, 0);
>  	return gnt_list_entry;
>  }
>  
> diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> index 95599e4..23d0549 100644
> --- a/drivers/input/misc/xen-kbdfront.c
> +++ b/drivers/input/misc/xen-kbdfront.c
> @@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  	struct xenbus_transaction xbt;
>  
>  	ret = gnttab_grant_foreign_access(dev->otherend_id,
> -	                                  virt_to_mfn(info->page), 0);
> +	                                  virt_to_gfn(info->page), 0);
>  	if (ret < 0)
>  		return ret;
>  	info->gref = ret;
> @@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  		goto error_irqh;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index f948c46..5cdab73 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		struct sk_buff *skb;
>  		unsigned short id;
>  		grant_ref_t ref;
> -		unsigned long pfn;
> +		unsigned long gfn;
>  		struct xen_netif_rx_request *req;
>  
>  		skb = xennet_alloc_one_rx_buffer(queue);
> @@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		BUG_ON((signed short)ref < 0);
>  		queue->grant_rx_ref[id] = ref;
>  
> -		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
> +		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
>  
>  		req = RING_GET_REQUEST(&queue->rx, req_prod);
>  		gnttab_grant_foreign_access_ref(ref,
>  						queue->info->xbdev->otherend_id,
> -						pfn_to_mfn(pfn),
> +						gfn,
>  						0);
>  
>  		req->id = id;
> @@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
>  	BUG_ON((signed short)ref < 0);
>  
>  	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
> -					page_to_mfn(page), GNTMAP_readonly);
> +					page_to_gfn(page), GNTMAP_readonly);
>  
>  	queue->tx_skbs[id].skb = skb;
>  	queue->grant_tx_page[id] = page;
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index fad22ca..cdf00d1 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  	unsigned int data_len = scsi_bufflen(sc);
>  	unsigned int data_grants = 0, seg_grants = 0;
>  	struct scatterlist *sg;
> -	unsigned long mfn;
>  	struct scsiif_request_segment *seg;
>  
>  	ring_req->nr_segments = 0;
> @@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, 1);
> +				info->dev->otherend_id, page_to_gfn(page), 1);
>  			shadow->gref[ref_cnt] = ref;
>  			ring_req->seg[ref_cnt].gref   = ref;
>  			ring_req->seg[ref_cnt].offset = (uint16_t)off;
> @@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, grant_ro);
> +				info->dev->otherend_id, page_to_gfn(page),
> +				grant_ro);
>  
>  			shadow->gref[ref_cnt] = ref;
>  			seg->gref   = ref;
> diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
> index a9d837f..efe5124 100644
> --- a/drivers/tty/hvc/hvc_xen.c
> +++ b/drivers/tty/hvc/hvc_xen.c
> @@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
>  		return 0;
>  	}
>  	info->evtchn = xen_start_info->console.domU.evtchn;
> -	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
> +	/* GFN == MFN for PV guest */
> +	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
>  	info->vtermno = HVC_COOKIE;
>  
>  	spin_lock(&xencons_lock);
> @@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
>  	if (IS_ERR(info->hvc))
>  		return PTR_ERR(info->hvc);
>  	if (xen_pv_domain())
> -		mfn = virt_to_mfn(info->intf);
> +		mfn = virt_to_gfn(info->intf);
>  	else
>  		mfn = __pa(info->intf) >> PAGE_SHIFT;
>  	ret = gnttab_alloc_grant_references(1, &gref_head);
> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>  
>  static unsigned long vmalloc_to_mfn(void *address)
>  {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>  }
>  
>  static void xenfb_init_shared_page(struct xenfb_info *info,
> @@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
>  		goto unbind_irq;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> index bf4a23c..5df28cd 100644
> --- a/drivers/xen/balloon.c
> +++ b/drivers/xen/balloon.c
> @@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
>  	/* Update direct mapping, invalidate P2M, and add to balloon. */
>  	for (i = 0; i < nr_pages; i++) {
>  		pfn = frame_list[i];
> -		frame_list[i] = pfn_to_mfn(pfn);
> +		frame_list[i] = pfn_to_gfn(pfn);
>  		page = pfn_to_page(pfn);
>  
>  #ifdef CONFIG_XEN_HAVE_PVMMU
> diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
> index 1495ecc..10fd9c6 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
>  		struct physdev_pirq_eoi_gmfn eoi_gmfn;
>  
>  		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
> -		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
> +		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
>  		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
>  		/* TODO: No PVH support for PIRQ EOI */
>  		if (rc != 0) {
> diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
> index 6df8aac..2e55e90 100644
> --- a/drivers/xen/events/events_fifo.c
> +++ b/drivers/xen/events/events_fifo.c
> @@ -111,7 +111,7 @@ static int init_control_block(int cpu,
>  	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
>  		q->head[i] = 0;
>  
> -	init_control.control_gfn = virt_to_mfn(control_block);
> +	init_control.control_gfn = virt_to_gfn(control_block);
>  	init_control.offset      = 0;
>  	init_control.vcpu        = cpu;
>  
> @@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
>  		/* Mask all events in this page before adding it. */
>  		init_array_page(array_page);
>  
> -		expand_array.array_gfn = virt_to_mfn(array_page);
> +		expand_array.array_gfn = virt_to_gfn(array_page);
>  
>  		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
>  		if (ret < 0)
> diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
> index e53fe19..13e1458 100644
> --- a/drivers/xen/gntalloc.c
> +++ b/drivers/xen/gntalloc.c
> @@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
>  
>  		/* Grant foreign access to the page. */
>  		rc = gnttab_grant_foreign_access(op->domid,
> -			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
> +						 page_to_gfn(gref->page),
> +						 readonly);
>  		if (rc < 0)
>  			goto undo;
>  		gref_ids[i] = gref->gref_id = rc;
> diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
> index d10effe..e12bd36 100644
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -80,7 +80,7 @@ static int xen_suspend(void *data)
>  	 * is resuming in a new domain.
>  	 */
>  	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
> -                                           ? virt_to_mfn(xen_start_info)
> +                                           ? virt_to_gfn(xen_start_info)
>                                             : 0);
>  
>  	xen_arch_post_suspend(si->cancelled);
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 239738f..28c97ff 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> @@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
> index 9ad3272..daa267a 100644
> --- a/drivers/xen/xenbus/xenbus_client.c
> +++ b/drivers/xen/xenbus/xenbus_client.c
> @@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
>  
>  	for (i = 0; i < nr_pages; i++) {
>  		err = gnttab_grant_foreign_access(dev->otherend_id,
> -						  virt_to_mfn(vaddr), 0);
> +						  virt_to_gfn(vaddr), 0);
>  		if (err < 0) {
>  			xenbus_dev_fatal(dev, err,
>  					 "granting access to ring page");
> diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
> index b17707e..ee6d9ef 100644
> --- a/drivers/xen/xenbus/xenbus_dev_backend.c
> +++ b/drivers/xen/xenbus/xenbus_dev_backend.c
> @@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
>  		goto out_err;
>  
>  	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
> -			virt_to_mfn(xen_store_interface), 0 /* writable */);
> +			virt_to_gfn(xen_store_interface), 0 /* writable */);
>  
>  	arg.dom = DOMID_SELF;
>  	arg.remote_dom = domid;
> diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> index 4308fb3..b3870f4 100644
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
>  	if (!page)
>  		goto out_err;
>  
> -	xen_store_mfn = xen_start_info->store_mfn =
> -		pfn_to_mfn(virt_to_phys((void *)page) >>
> -			   PAGE_SHIFT);
> +	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
>  
>  	/* Next allocate a local port which xenstored can bind to */
>  	alloc_unbound.dom        = DOMID_SELF;
> @@ -787,12 +785,12 @@ static int __init xenbus_init(void)
>  		err = xenstored_local_init();
>  		if (err)
>  			goto out_error;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_PV:
>  		xen_store_evtchn = xen_start_info->store_evtchn;
>  		xen_store_mfn = xen_start_info->store_mfn;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_HVM:
>  		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }
>  
>  struct xen_memory_region {
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:08     ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:08 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev

[-- Attachment #1: Type: text/plain, Size: 22710 bytes --]

On Tue, 4 Aug 2015, Julien Grall wrote:
> Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> is meant, I suspect this is because the first support for Xen was for
> PV. This resulted in some misimplementation of helpers on ARM and
> confused developers about the expected behavior.
> 
> For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> Although, if we look at the implementation on x86, it's returning a GFN.
> 
> For clarity and avoid new confusion, replace any reference to mfn with
> gfn in any helpers used by PV drivers. The x86 code will still keep some
> reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> to ensure this). No changes as been made in the hypercall field, even
> though they may be invalid, in order to keep the same as the defintion
> in xen repo.
> 
> Take also the opportunity to simplify simple construction such
> as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> will come in follow-up patches.
> 
> [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: linux-input@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Cc: linux-scsi@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-fbdev@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org

Aside from the x86 bits:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>     Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
>     The helpers contain a BUG_ON to ensure that it's never called for
>     auto-translated guests. I did as best as my can to determine whether
>     mfn or gfn helpers should be used. Although, I haven't tried to boot
>     it.
> 
>     It may be possible to do further cleanup in the mmu.c where I found
>     some check to auto-translated. I'm not sure why given that the pvmmu
>     callback are only used for non-auto translated guest.
> 
>     Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.
> 
>     Changes in v2:
>         - Give directly the URL to the commit rather than the commit ID
>         - xenstored_local_init: keep the cast to void *
>         - Typoes
>         - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
>         used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
>         smp.c and mm.c
> ---
>  arch/arm/include/asm/xen/page.h         | 13 +++++++------
>  arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
>  arch/x86/xen/smp.c                      |  2 +-
>  drivers/block/xen-blkfront.c            |  6 +++---
>  drivers/input/misc/xen-kbdfront.c       |  4 ++--
>  drivers/net/xen-netback/netback.c       |  4 ++--
>  drivers/net/xen-netfront.c              |  8 ++++----
>  drivers/scsi/xen-scsifront.c            |  8 +++-----
>  drivers/tty/hvc/hvc_xen.c               |  5 +++--
>  drivers/video/fbdev/xen-fbfront.c       |  4 ++--
>  drivers/xen/balloon.c                   |  2 +-
>  drivers/xen/events/events_base.c        |  2 +-
>  drivers/xen/events/events_fifo.c        |  4 ++--
>  drivers/xen/gntalloc.c                  |  3 ++-
>  drivers/xen/manage.c                    |  2 +-
>  drivers/xen/tmem.c                      |  4 ++--
>  drivers/xen/xenbus/xenbus_client.c      |  2 +-
>  drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
>  drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
>  include/xen/page.h                      |  4 ++--
>  20 files changed, 69 insertions(+), 51 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 087d86e..51e5bf1 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -34,14 +34,15 @@ typedef struct xpaddr {
>  unsigned long __pfn_to_mfn(unsigned long pfn);
>  extern struct rb_root phys_to_mach;
>  
> -static inline unsigned long pfn_to_mfn(unsigned long pfn)
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>  	return pfn;
>  }
>  
> -static inline unsigned long mfn_to_pfn(unsigned long mfn)
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
>  {
> -	return mfn;
> +	return gfn;
>  }
>  
>  /* Pseudo-physical <-> BUS conversion */
> @@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
>  
>  #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
> -/* VIRT <-> MACHINE conversion */
> -#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
>  
>  /* Only used in PV code. But ARM guests are always HVM. */
>  static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 8ba04b8..c2da42f 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
>  	unsigned long mfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return pfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	mfn = __pfn_to_mfn(pfn);
>  
> @@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return mfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	pfn = mfn_to_pfn_no_overrides(mfn);
>  	if (__pfn_to_mfn(pfn) != mfn)
> @@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return pfn;
> +	else
> +		return pfn_to_mfn(pfn);
> +}
> +
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return gfn;
> +	else
> +		return mfn_to_pfn(gfn);
> +}
> +
>  /* Pseudo-physical <-> Bus conversion */
> -#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> -#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
> +#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
>  
>  /*
>   * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>  #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> +
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
>  
>  static inline unsigned long pte_mfn(pte_t pte)
>  {
> diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
> index 8648438..1e0931b 100644
> --- a/arch/x86/xen/smp.c
> +++ b/arch/x86/xen/smp.c
> @@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
>  	}
>  #endif
>  	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
> -	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
> +	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
>  	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
>  		BUG();
>  
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 6d89ed3..2e541a4 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>                                 struct blkfront_info *info)
>  {
>  	struct grant *gnt_list_entry;
> -	unsigned long buffer_mfn;
> +	unsigned long buffer_gfn;
>  
>  	BUG_ON(list_empty(&info->grants));
>  	gnt_list_entry = list_first_entry(&info->grants, struct grant,
> @@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>  		BUG_ON(!pfn);
>  		gnt_list_entry->pfn = pfn;
>  	}
> -	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
> +	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
>  	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
>  	                                info->xbdev->otherend_id,
> -	                                buffer_mfn, 0);
> +	                                buffer_gfn, 0);
>  	return gnt_list_entry;
>  }
>  
> diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> index 95599e4..23d0549 100644
> --- a/drivers/input/misc/xen-kbdfront.c
> +++ b/drivers/input/misc/xen-kbdfront.c
> @@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  	struct xenbus_transaction xbt;
>  
>  	ret = gnttab_grant_foreign_access(dev->otherend_id,
> -	                                  virt_to_mfn(info->page), 0);
> +	                                  virt_to_gfn(info->page), 0);
>  	if (ret < 0)
>  		return ret;
>  	info->gref = ret;
> @@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  		goto error_irqh;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index f948c46..5cdab73 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		struct sk_buff *skb;
>  		unsigned short id;
>  		grant_ref_t ref;
> -		unsigned long pfn;
> +		unsigned long gfn;
>  		struct xen_netif_rx_request *req;
>  
>  		skb = xennet_alloc_one_rx_buffer(queue);
> @@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		BUG_ON((signed short)ref < 0);
>  		queue->grant_rx_ref[id] = ref;
>  
> -		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
> +		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
>  
>  		req = RING_GET_REQUEST(&queue->rx, req_prod);
>  		gnttab_grant_foreign_access_ref(ref,
>  						queue->info->xbdev->otherend_id,
> -						pfn_to_mfn(pfn),
> +						gfn,
>  						0);
>  
>  		req->id = id;
> @@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
>  	BUG_ON((signed short)ref < 0);
>  
>  	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
> -					page_to_mfn(page), GNTMAP_readonly);
> +					page_to_gfn(page), GNTMAP_readonly);
>  
>  	queue->tx_skbs[id].skb = skb;
>  	queue->grant_tx_page[id] = page;
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index fad22ca..cdf00d1 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  	unsigned int data_len = scsi_bufflen(sc);
>  	unsigned int data_grants = 0, seg_grants = 0;
>  	struct scatterlist *sg;
> -	unsigned long mfn;
>  	struct scsiif_request_segment *seg;
>  
>  	ring_req->nr_segments = 0;
> @@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, 1);
> +				info->dev->otherend_id, page_to_gfn(page), 1);
>  			shadow->gref[ref_cnt] = ref;
>  			ring_req->seg[ref_cnt].gref   = ref;
>  			ring_req->seg[ref_cnt].offset = (uint16_t)off;
> @@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, grant_ro);
> +				info->dev->otherend_id, page_to_gfn(page),
> +				grant_ro);
>  
>  			shadow->gref[ref_cnt] = ref;
>  			seg->gref   = ref;
> diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
> index a9d837f..efe5124 100644
> --- a/drivers/tty/hvc/hvc_xen.c
> +++ b/drivers/tty/hvc/hvc_xen.c
> @@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
>  		return 0;
>  	}
>  	info->evtchn = xen_start_info->console.domU.evtchn;
> -	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
> +	/* GFN == MFN for PV guest */
> +	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
>  	info->vtermno = HVC_COOKIE;
>  
>  	spin_lock(&xencons_lock);
> @@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
>  	if (IS_ERR(info->hvc))
>  		return PTR_ERR(info->hvc);
>  	if (xen_pv_domain())
> -		mfn = virt_to_mfn(info->intf);
> +		mfn = virt_to_gfn(info->intf);
>  	else
>  		mfn = __pa(info->intf) >> PAGE_SHIFT;
>  	ret = gnttab_alloc_grant_references(1, &gref_head);
> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>  
>  static unsigned long vmalloc_to_mfn(void *address)
>  {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>  }
>  
>  static void xenfb_init_shared_page(struct xenfb_info *info,
> @@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
>  		goto unbind_irq;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> index bf4a23c..5df28cd 100644
> --- a/drivers/xen/balloon.c
> +++ b/drivers/xen/balloon.c
> @@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
>  	/* Update direct mapping, invalidate P2M, and add to balloon. */
>  	for (i = 0; i < nr_pages; i++) {
>  		pfn = frame_list[i];
> -		frame_list[i] = pfn_to_mfn(pfn);
> +		frame_list[i] = pfn_to_gfn(pfn);
>  		page = pfn_to_page(pfn);
>  
>  #ifdef CONFIG_XEN_HAVE_PVMMU
> diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
> index 1495ecc..10fd9c6 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
>  		struct physdev_pirq_eoi_gmfn eoi_gmfn;
>  
>  		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
> -		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
> +		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
>  		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
>  		/* TODO: No PVH support for PIRQ EOI */
>  		if (rc != 0) {
> diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
> index 6df8aac..2e55e90 100644
> --- a/drivers/xen/events/events_fifo.c
> +++ b/drivers/xen/events/events_fifo.c
> @@ -111,7 +111,7 @@ static int init_control_block(int cpu,
>  	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
>  		q->head[i] = 0;
>  
> -	init_control.control_gfn = virt_to_mfn(control_block);
> +	init_control.control_gfn = virt_to_gfn(control_block);
>  	init_control.offset      = 0;
>  	init_control.vcpu        = cpu;
>  
> @@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
>  		/* Mask all events in this page before adding it. */
>  		init_array_page(array_page);
>  
> -		expand_array.array_gfn = virt_to_mfn(array_page);
> +		expand_array.array_gfn = virt_to_gfn(array_page);
>  
>  		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
>  		if (ret < 0)
> diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
> index e53fe19..13e1458 100644
> --- a/drivers/xen/gntalloc.c
> +++ b/drivers/xen/gntalloc.c
> @@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
>  
>  		/* Grant foreign access to the page. */
>  		rc = gnttab_grant_foreign_access(op->domid,
> -			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
> +						 page_to_gfn(gref->page),
> +						 readonly);
>  		if (rc < 0)
>  			goto undo;
>  		gref_ids[i] = gref->gref_id = rc;
> diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
> index d10effe..e12bd36 100644
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -80,7 +80,7 @@ static int xen_suspend(void *data)
>  	 * is resuming in a new domain.
>  	 */
>  	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
> -                                           ? virt_to_mfn(xen_start_info)
> +                                           ? virt_to_gfn(xen_start_info)
>                                             : 0);
>  
>  	xen_arch_post_suspend(si->cancelled);
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 239738f..28c97ff 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> @@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
> index 9ad3272..daa267a 100644
> --- a/drivers/xen/xenbus/xenbus_client.c
> +++ b/drivers/xen/xenbus/xenbus_client.c
> @@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
>  
>  	for (i = 0; i < nr_pages; i++) {
>  		err = gnttab_grant_foreign_access(dev->otherend_id,
> -						  virt_to_mfn(vaddr), 0);
> +						  virt_to_gfn(vaddr), 0);
>  		if (err < 0) {
>  			xenbus_dev_fatal(dev, err,
>  					 "granting access to ring page");
> diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
> index b17707e..ee6d9ef 100644
> --- a/drivers/xen/xenbus/xenbus_dev_backend.c
> +++ b/drivers/xen/xenbus/xenbus_dev_backend.c
> @@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
>  		goto out_err;
>  
>  	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
> -			virt_to_mfn(xen_store_interface), 0 /* writable */);
> +			virt_to_gfn(xen_store_interface), 0 /* writable */);
>  
>  	arg.dom = DOMID_SELF;
>  	arg.remote_dom = domid;
> diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> index 4308fb3..b3870f4 100644
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
>  	if (!page)
>  		goto out_err;
>  
> -	xen_store_mfn = xen_start_info->store_mfn =
> -		pfn_to_mfn(virt_to_phys((void *)page) >>
> -			   PAGE_SHIFT);
> +	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
>  
>  	/* Next allocate a local port which xenstored can bind to */
>  	alloc_unbound.dom        = DOMID_SELF;
> @@ -787,12 +785,12 @@ static int __init xenbus_init(void)
>  		err = xenstored_local_init();
>  		if (err)
>  			goto out_error;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_PV:
>  		xen_store_evtchn = xen_start_info->store_evtchn;
>  		xen_store_mfn = xen_start_info->store_mfn;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_HVM:
>  		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }
>  
>  struct xen_memory_region {
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:08     ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:08 UTC (permalink / raw)
  To: linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 22710 bytes --]

On Tue, 4 Aug 2015, Julien Grall wrote:
> Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> is meant, I suspect this is because the first support for Xen was for
> PV. This resulted in some misimplementation of helpers on ARM and
> confused developers about the expected behavior.
> 
> For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> Although, if we look at the implementation on x86, it's returning a GFN.
> 
> For clarity and avoid new confusion, replace any reference to mfn with
> gfn in any helpers used by PV drivers. The x86 code will still keep some
> reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> to ensure this). No changes as been made in the hypercall field, even
> though they may be invalid, in order to keep the same as the defintion
> in xen repo.
> 
> Take also the opportunity to simplify simple construction such
> as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> will come in follow-up patches.
> 
> [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: linux-input@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Cc: linux-scsi@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-fbdev@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org

Aside from the x86 bits:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>     Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
>     The helpers contain a BUG_ON to ensure that it's never called for
>     auto-translated guests. I did as best as my can to determine whether
>     mfn or gfn helpers should be used. Although, I haven't tried to boot
>     it.
> 
>     It may be possible to do further cleanup in the mmu.c where I found
>     some check to auto-translated. I'm not sure why given that the pvmmu
>     callback are only used for non-auto translated guest.
> 
>     Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.
> 
>     Changes in v2:
>         - Give directly the URL to the commit rather than the commit ID
>         - xenstored_local_init: keep the cast to void *
>         - Typoes
>         - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
>         used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
>         smp.c and mm.c
> ---
>  arch/arm/include/asm/xen/page.h         | 13 +++++++------
>  arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
>  arch/x86/xen/smp.c                      |  2 +-
>  drivers/block/xen-blkfront.c            |  6 +++---
>  drivers/input/misc/xen-kbdfront.c       |  4 ++--
>  drivers/net/xen-netback/netback.c       |  4 ++--
>  drivers/net/xen-netfront.c              |  8 ++++----
>  drivers/scsi/xen-scsifront.c            |  8 +++-----
>  drivers/tty/hvc/hvc_xen.c               |  5 +++--
>  drivers/video/fbdev/xen-fbfront.c       |  4 ++--
>  drivers/xen/balloon.c                   |  2 +-
>  drivers/xen/events/events_base.c        |  2 +-
>  drivers/xen/events/events_fifo.c        |  4 ++--
>  drivers/xen/gntalloc.c                  |  3 ++-
>  drivers/xen/manage.c                    |  2 +-
>  drivers/xen/tmem.c                      |  4 ++--
>  drivers/xen/xenbus/xenbus_client.c      |  2 +-
>  drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
>  drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
>  include/xen/page.h                      |  4 ++--
>  20 files changed, 69 insertions(+), 51 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 087d86e..51e5bf1 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -34,14 +34,15 @@ typedef struct xpaddr {
>  unsigned long __pfn_to_mfn(unsigned long pfn);
>  extern struct rb_root phys_to_mach;
>  
> -static inline unsigned long pfn_to_mfn(unsigned long pfn)
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>  	return pfn;
>  }
>  
> -static inline unsigned long mfn_to_pfn(unsigned long mfn)
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
>  {
> -	return mfn;
> +	return gfn;
>  }
>  
>  /* Pseudo-physical <-> BUS conversion */
> @@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
>  
>  #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
> -/* VIRT <-> MACHINE conversion */
> -#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
>  
>  /* Only used in PV code. But ARM guests are always HVM. */
>  static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 8ba04b8..c2da42f 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
>  	unsigned long mfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return pfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	mfn = __pfn_to_mfn(pfn);
>  
> @@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return mfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	pfn = mfn_to_pfn_no_overrides(mfn);
>  	if (__pfn_to_mfn(pfn) != mfn)
> @@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return pfn;
> +	else
> +		return pfn_to_mfn(pfn);
> +}
> +
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return gfn;
> +	else
> +		return mfn_to_pfn(gfn);
> +}
> +
>  /* Pseudo-physical <-> Bus conversion */
> -#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> -#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
> +#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
>  
>  /*
>   * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>  #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> +
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
>  
>  static inline unsigned long pte_mfn(pte_t pte)
>  {
> diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
> index 8648438..1e0931b 100644
> --- a/arch/x86/xen/smp.c
> +++ b/arch/x86/xen/smp.c
> @@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
>  	}
>  #endif
>  	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
> -	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
> +	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
>  	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
>  		BUG();
>  
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 6d89ed3..2e541a4 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>                                 struct blkfront_info *info)
>  {
>  	struct grant *gnt_list_entry;
> -	unsigned long buffer_mfn;
> +	unsigned long buffer_gfn;
>  
>  	BUG_ON(list_empty(&info->grants));
>  	gnt_list_entry = list_first_entry(&info->grants, struct grant,
> @@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>  		BUG_ON(!pfn);
>  		gnt_list_entry->pfn = pfn;
>  	}
> -	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
> +	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
>  	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
>  	                                info->xbdev->otherend_id,
> -	                                buffer_mfn, 0);
> +	                                buffer_gfn, 0);
>  	return gnt_list_entry;
>  }
>  
> diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> index 95599e4..23d0549 100644
> --- a/drivers/input/misc/xen-kbdfront.c
> +++ b/drivers/input/misc/xen-kbdfront.c
> @@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  	struct xenbus_transaction xbt;
>  
>  	ret = gnttab_grant_foreign_access(dev->otherend_id,
> -	                                  virt_to_mfn(info->page), 0);
> +	                                  virt_to_gfn(info->page), 0);
>  	if (ret < 0)
>  		return ret;
>  	info->gref = ret;
> @@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  		goto error_irqh;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index f948c46..5cdab73 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		struct sk_buff *skb;
>  		unsigned short id;
>  		grant_ref_t ref;
> -		unsigned long pfn;
> +		unsigned long gfn;
>  		struct xen_netif_rx_request *req;
>  
>  		skb = xennet_alloc_one_rx_buffer(queue);
> @@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		BUG_ON((signed short)ref < 0);
>  		queue->grant_rx_ref[id] = ref;
>  
> -		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
> +		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
>  
>  		req = RING_GET_REQUEST(&queue->rx, req_prod);
>  		gnttab_grant_foreign_access_ref(ref,
>  						queue->info->xbdev->otherend_id,
> -						pfn_to_mfn(pfn),
> +						gfn,
>  						0);
>  
>  		req->id = id;
> @@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
>  	BUG_ON((signed short)ref < 0);
>  
>  	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
> -					page_to_mfn(page), GNTMAP_readonly);
> +					page_to_gfn(page), GNTMAP_readonly);
>  
>  	queue->tx_skbs[id].skb = skb;
>  	queue->grant_tx_page[id] = page;
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index fad22ca..cdf00d1 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  	unsigned int data_len = scsi_bufflen(sc);
>  	unsigned int data_grants = 0, seg_grants = 0;
>  	struct scatterlist *sg;
> -	unsigned long mfn;
>  	struct scsiif_request_segment *seg;
>  
>  	ring_req->nr_segments = 0;
> @@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, 1);
> +				info->dev->otherend_id, page_to_gfn(page), 1);
>  			shadow->gref[ref_cnt] = ref;
>  			ring_req->seg[ref_cnt].gref   = ref;
>  			ring_req->seg[ref_cnt].offset = (uint16_t)off;
> @@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, grant_ro);
> +				info->dev->otherend_id, page_to_gfn(page),
> +				grant_ro);
>  
>  			shadow->gref[ref_cnt] = ref;
>  			seg->gref   = ref;
> diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
> index a9d837f..efe5124 100644
> --- a/drivers/tty/hvc/hvc_xen.c
> +++ b/drivers/tty/hvc/hvc_xen.c
> @@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
>  		return 0;
>  	}
>  	info->evtchn = xen_start_info->console.domU.evtchn;
> -	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
> +	/* GFN == MFN for PV guest */
> +	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
>  	info->vtermno = HVC_COOKIE;
>  
>  	spin_lock(&xencons_lock);
> @@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
>  	if (IS_ERR(info->hvc))
>  		return PTR_ERR(info->hvc);
>  	if (xen_pv_domain())
> -		mfn = virt_to_mfn(info->intf);
> +		mfn = virt_to_gfn(info->intf);
>  	else
>  		mfn = __pa(info->intf) >> PAGE_SHIFT;
>  	ret = gnttab_alloc_grant_references(1, &gref_head);
> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>  
>  static unsigned long vmalloc_to_mfn(void *address)
>  {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>  }
>  
>  static void xenfb_init_shared_page(struct xenfb_info *info,
> @@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
>  		goto unbind_irq;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> index bf4a23c..5df28cd 100644
> --- a/drivers/xen/balloon.c
> +++ b/drivers/xen/balloon.c
> @@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
>  	/* Update direct mapping, invalidate P2M, and add to balloon. */
>  	for (i = 0; i < nr_pages; i++) {
>  		pfn = frame_list[i];
> -		frame_list[i] = pfn_to_mfn(pfn);
> +		frame_list[i] = pfn_to_gfn(pfn);
>  		page = pfn_to_page(pfn);
>  
>  #ifdef CONFIG_XEN_HAVE_PVMMU
> diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
> index 1495ecc..10fd9c6 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
>  		struct physdev_pirq_eoi_gmfn eoi_gmfn;
>  
>  		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
> -		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
> +		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
>  		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
>  		/* TODO: No PVH support for PIRQ EOI */
>  		if (rc != 0) {
> diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
> index 6df8aac..2e55e90 100644
> --- a/drivers/xen/events/events_fifo.c
> +++ b/drivers/xen/events/events_fifo.c
> @@ -111,7 +111,7 @@ static int init_control_block(int cpu,
>  	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
>  		q->head[i] = 0;
>  
> -	init_control.control_gfn = virt_to_mfn(control_block);
> +	init_control.control_gfn = virt_to_gfn(control_block);
>  	init_control.offset      = 0;
>  	init_control.vcpu        = cpu;
>  
> @@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
>  		/* Mask all events in this page before adding it. */
>  		init_array_page(array_page);
>  
> -		expand_array.array_gfn = virt_to_mfn(array_page);
> +		expand_array.array_gfn = virt_to_gfn(array_page);
>  
>  		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
>  		if (ret < 0)
> diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
> index e53fe19..13e1458 100644
> --- a/drivers/xen/gntalloc.c
> +++ b/drivers/xen/gntalloc.c
> @@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
>  
>  		/* Grant foreign access to the page. */
>  		rc = gnttab_grant_foreign_access(op->domid,
> -			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
> +						 page_to_gfn(gref->page),
> +						 readonly);
>  		if (rc < 0)
>  			goto undo;
>  		gref_ids[i] = gref->gref_id = rc;
> diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
> index d10effe..e12bd36 100644
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -80,7 +80,7 @@ static int xen_suspend(void *data)
>  	 * is resuming in a new domain.
>  	 */
>  	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
> -                                           ? virt_to_mfn(xen_start_info)
> +                                           ? virt_to_gfn(xen_start_info)
>                                             : 0);
>  
>  	xen_arch_post_suspend(si->cancelled);
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 239738f..28c97ff 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> @@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
> index 9ad3272..daa267a 100644
> --- a/drivers/xen/xenbus/xenbus_client.c
> +++ b/drivers/xen/xenbus/xenbus_client.c
> @@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
>  
>  	for (i = 0; i < nr_pages; i++) {
>  		err = gnttab_grant_foreign_access(dev->otherend_id,
> -						  virt_to_mfn(vaddr), 0);
> +						  virt_to_gfn(vaddr), 0);
>  		if (err < 0) {
>  			xenbus_dev_fatal(dev, err,
>  					 "granting access to ring page");
> diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
> index b17707e..ee6d9ef 100644
> --- a/drivers/xen/xenbus/xenbus_dev_backend.c
> +++ b/drivers/xen/xenbus/xenbus_dev_backend.c
> @@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
>  		goto out_err;
>  
>  	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
> -			virt_to_mfn(xen_store_interface), 0 /* writable */);
> +			virt_to_gfn(xen_store_interface), 0 /* writable */);
>  
>  	arg.dom = DOMID_SELF;
>  	arg.remote_dom = domid;
> diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> index 4308fb3..b3870f4 100644
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
>  	if (!page)
>  		goto out_err;
>  
> -	xen_store_mfn = xen_start_info->store_mfn =
> -		pfn_to_mfn(virt_to_phys((void *)page) >>
> -			   PAGE_SHIFT);
> +	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
>  
>  	/* Next allocate a local port which xenstored can bind to */
>  	alloc_unbound.dom        = DOMID_SELF;
> @@ -787,12 +785,12 @@ static int __init xenbus_init(void)
>  		err = xenstored_local_init();
>  		if (err)
>  			goto out_error;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_PV:
>  		xen_store_evtchn = xen_start_info->store_evtchn;
>  		xen_store_mfn = xen_start_info->store_mfn;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_HVM:
>  		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }
>  
>  struct xen_memory_region {
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:08     ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:08 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 4 Aug 2015, Julien Grall wrote:
> Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> is meant, I suspect this is because the first support for Xen was for
> PV. This resulted in some misimplementation of helpers on ARM and
> confused developers about the expected behavior.
> 
> For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> Although, if we look at the implementation on x86, it's returning a GFN.
> 
> For clarity and avoid new confusion, replace any reference to mfn with
> gfn in any helpers used by PV drivers. The x86 code will still keep some
> reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> to ensure this). No changes as been made in the hypercall field, even
> though they may be invalid, in order to keep the same as the defintion
> in xen repo.
> 
> Take also the opportunity to simplify simple construction such
> as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> will come in follow-up patches.
> 
> [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86 at kernel.org
> Cc: "Roger Pau Monn?" <roger.pau@citrix.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: linux-input at vger.kernel.org
> Cc: netdev at vger.kernel.org
> Cc: linux-scsi at vger.kernel.org
> Cc: linuxppc-dev at lists.ozlabs.org
> Cc: linux-fbdev at vger.kernel.org
> Cc: linux-arm-kernel at lists.infradead.org

Aside from the x86 bits:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>     Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
>     The helpers contain a BUG_ON to ensure that it's never called for
>     auto-translated guests. I did as best as my can to determine whether
>     mfn or gfn helpers should be used. Although, I haven't tried to boot
>     it.
> 
>     It may be possible to do further cleanup in the mmu.c where I found
>     some check to auto-translated. I'm not sure why given that the pvmmu
>     callback are only used for non-auto translated guest.
> 
>     Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.
> 
>     Changes in v2:
>         - Give directly the URL to the commit rather than the commit ID
>         - xenstored_local_init: keep the cast to void *
>         - Typoes
>         - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
>         used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
>         smp.c and mm.c
> ---
>  arch/arm/include/asm/xen/page.h         | 13 +++++++------
>  arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
>  arch/x86/xen/smp.c                      |  2 +-
>  drivers/block/xen-blkfront.c            |  6 +++---
>  drivers/input/misc/xen-kbdfront.c       |  4 ++--
>  drivers/net/xen-netback/netback.c       |  4 ++--
>  drivers/net/xen-netfront.c              |  8 ++++----
>  drivers/scsi/xen-scsifront.c            |  8 +++-----
>  drivers/tty/hvc/hvc_xen.c               |  5 +++--
>  drivers/video/fbdev/xen-fbfront.c       |  4 ++--
>  drivers/xen/balloon.c                   |  2 +-
>  drivers/xen/events/events_base.c        |  2 +-
>  drivers/xen/events/events_fifo.c        |  4 ++--
>  drivers/xen/gntalloc.c                  |  3 ++-
>  drivers/xen/manage.c                    |  2 +-
>  drivers/xen/tmem.c                      |  4 ++--
>  drivers/xen/xenbus/xenbus_client.c      |  2 +-
>  drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
>  drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
>  include/xen/page.h                      |  4 ++--
>  20 files changed, 69 insertions(+), 51 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 087d86e..51e5bf1 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -34,14 +34,15 @@ typedef struct xpaddr {
>  unsigned long __pfn_to_mfn(unsigned long pfn);
>  extern struct rb_root phys_to_mach;
>  
> -static inline unsigned long pfn_to_mfn(unsigned long pfn)
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>  	return pfn;
>  }
>  
> -static inline unsigned long mfn_to_pfn(unsigned long mfn)
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
>  {
> -	return mfn;
> +	return gfn;
>  }
>  
>  /* Pseudo-physical <-> BUS conversion */
> @@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
>  
>  #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>  
> -/* VIRT <-> MACHINE conversion */
> -#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
>  
>  /* Only used in PV code. But ARM guests are always HVM. */
>  static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 8ba04b8..c2da42f 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
>  	unsigned long mfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return pfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	mfn = __pfn_to_mfn(pfn);
>  
> @@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>  
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return mfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>  
>  	pfn = mfn_to_pfn_no_overrides(mfn);
>  	if (__pfn_to_mfn(pfn) != mfn)
> @@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>  
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return pfn;
> +	else
> +		return pfn_to_mfn(pfn);
> +}
> +
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return gfn;
> +	else
> +		return mfn_to_pfn(gfn);
> +}
> +
>  /* Pseudo-physical <-> Bus conversion */
> -#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> -#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
> +#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
>  
>  /*
>   * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>  
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>  #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> +
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
>  
>  static inline unsigned long pte_mfn(pte_t pte)
>  {
> diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
> index 8648438..1e0931b 100644
> --- a/arch/x86/xen/smp.c
> +++ b/arch/x86/xen/smp.c
> @@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
>  	}
>  #endif
>  	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
> -	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
> +	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
>  	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
>  		BUG();
>  
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 6d89ed3..2e541a4 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>                                 struct blkfront_info *info)
>  {
>  	struct grant *gnt_list_entry;
> -	unsigned long buffer_mfn;
> +	unsigned long buffer_gfn;
>  
>  	BUG_ON(list_empty(&info->grants));
>  	gnt_list_entry = list_first_entry(&info->grants, struct grant,
> @@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>  		BUG_ON(!pfn);
>  		gnt_list_entry->pfn = pfn;
>  	}
> -	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
> +	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
>  	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
>  	                                info->xbdev->otherend_id,
> -	                                buffer_mfn, 0);
> +	                                buffer_gfn, 0);
>  	return gnt_list_entry;
>  }
>  
> diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> index 95599e4..23d0549 100644
> --- a/drivers/input/misc/xen-kbdfront.c
> +++ b/drivers/input/misc/xen-kbdfront.c
> @@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  	struct xenbus_transaction xbt;
>  
>  	ret = gnttab_grant_foreign_access(dev->otherend_id,
> -	                                  virt_to_mfn(info->page), 0);
> +	                                  virt_to_gfn(info->page), 0);
>  	if (ret < 0)
>  		return ret;
>  	info->gref = ret;
> @@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  		goto error_irqh;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index f948c46..5cdab73 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		struct sk_buff *skb;
>  		unsigned short id;
>  		grant_ref_t ref;
> -		unsigned long pfn;
> +		unsigned long gfn;
>  		struct xen_netif_rx_request *req;
>  
>  		skb = xennet_alloc_one_rx_buffer(queue);
> @@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		BUG_ON((signed short)ref < 0);
>  		queue->grant_rx_ref[id] = ref;
>  
> -		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
> +		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
>  
>  		req = RING_GET_REQUEST(&queue->rx, req_prod);
>  		gnttab_grant_foreign_access_ref(ref,
>  						queue->info->xbdev->otherend_id,
> -						pfn_to_mfn(pfn),
> +						gfn,
>  						0);
>  
>  		req->id = id;
> @@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
>  	BUG_ON((signed short)ref < 0);
>  
>  	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
> -					page_to_mfn(page), GNTMAP_readonly);
> +					page_to_gfn(page), GNTMAP_readonly);
>  
>  	queue->tx_skbs[id].skb = skb;
>  	queue->grant_tx_page[id] = page;
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index fad22ca..cdf00d1 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  	unsigned int data_len = scsi_bufflen(sc);
>  	unsigned int data_grants = 0, seg_grants = 0;
>  	struct scatterlist *sg;
> -	unsigned long mfn;
>  	struct scsiif_request_segment *seg;
>  
>  	ring_req->nr_segments = 0;
> @@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, 1);
> +				info->dev->otherend_id, page_to_gfn(page), 1);
>  			shadow->gref[ref_cnt] = ref;
>  			ring_req->seg[ref_cnt].gref   = ref;
>  			ring_req->seg[ref_cnt].offset = (uint16_t)off;
> @@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>  
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, grant_ro);
> +				info->dev->otherend_id, page_to_gfn(page),
> +				grant_ro);
>  
>  			shadow->gref[ref_cnt] = ref;
>  			seg->gref   = ref;
> diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
> index a9d837f..efe5124 100644
> --- a/drivers/tty/hvc/hvc_xen.c
> +++ b/drivers/tty/hvc/hvc_xen.c
> @@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
>  		return 0;
>  	}
>  	info->evtchn = xen_start_info->console.domU.evtchn;
> -	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
> +	/* GFN == MFN for PV guest */
> +	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
>  	info->vtermno = HVC_COOKIE;
>  
>  	spin_lock(&xencons_lock);
> @@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
>  	if (IS_ERR(info->hvc))
>  		return PTR_ERR(info->hvc);
>  	if (xen_pv_domain())
> -		mfn = virt_to_mfn(info->intf);
> +		mfn = virt_to_gfn(info->intf);
>  	else
>  		mfn = __pa(info->intf) >> PAGE_SHIFT;
>  	ret = gnttab_alloc_grant_references(1, &gref_head);
> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>  
>  static unsigned long vmalloc_to_mfn(void *address)
>  {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>  }
>  
>  static void xenfb_init_shared_page(struct xenfb_info *info,
> @@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
>  		goto unbind_irq;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> index bf4a23c..5df28cd 100644
> --- a/drivers/xen/balloon.c
> +++ b/drivers/xen/balloon.c
> @@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
>  	/* Update direct mapping, invalidate P2M, and add to balloon. */
>  	for (i = 0; i < nr_pages; i++) {
>  		pfn = frame_list[i];
> -		frame_list[i] = pfn_to_mfn(pfn);
> +		frame_list[i] = pfn_to_gfn(pfn);
>  		page = pfn_to_page(pfn);
>  
>  #ifdef CONFIG_XEN_HAVE_PVMMU
> diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
> index 1495ecc..10fd9c6 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
>  		struct physdev_pirq_eoi_gmfn eoi_gmfn;
>  
>  		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
> -		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
> +		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
>  		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
>  		/* TODO: No PVH support for PIRQ EOI */
>  		if (rc != 0) {
> diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
> index 6df8aac..2e55e90 100644
> --- a/drivers/xen/events/events_fifo.c
> +++ b/drivers/xen/events/events_fifo.c
> @@ -111,7 +111,7 @@ static int init_control_block(int cpu,
>  	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
>  		q->head[i] = 0;
>  
> -	init_control.control_gfn = virt_to_mfn(control_block);
> +	init_control.control_gfn = virt_to_gfn(control_block);
>  	init_control.offset      = 0;
>  	init_control.vcpu        = cpu;
>  
> @@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
>  		/* Mask all events in this page before adding it. */
>  		init_array_page(array_page);
>  
> -		expand_array.array_gfn = virt_to_mfn(array_page);
> +		expand_array.array_gfn = virt_to_gfn(array_page);
>  
>  		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
>  		if (ret < 0)
> diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
> index e53fe19..13e1458 100644
> --- a/drivers/xen/gntalloc.c
> +++ b/drivers/xen/gntalloc.c
> @@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
>  
>  		/* Grant foreign access to the page. */
>  		rc = gnttab_grant_foreign_access(op->domid,
> -			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
> +						 page_to_gfn(gref->page),
> +						 readonly);
>  		if (rc < 0)
>  			goto undo;
>  		gref_ids[i] = gref->gref_id = rc;
> diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
> index d10effe..e12bd36 100644
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -80,7 +80,7 @@ static int xen_suspend(void *data)
>  	 * is resuming in a new domain.
>  	 */
>  	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
> -                                           ? virt_to_mfn(xen_start_info)
> +                                           ? virt_to_gfn(xen_start_info)
>                                             : 0);
>  
>  	xen_arch_post_suspend(si->cancelled);
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 239738f..28c97ff 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> @@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>  
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
> index 9ad3272..daa267a 100644
> --- a/drivers/xen/xenbus/xenbus_client.c
> +++ b/drivers/xen/xenbus/xenbus_client.c
> @@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
>  
>  	for (i = 0; i < nr_pages; i++) {
>  		err = gnttab_grant_foreign_access(dev->otherend_id,
> -						  virt_to_mfn(vaddr), 0);
> +						  virt_to_gfn(vaddr), 0);
>  		if (err < 0) {
>  			xenbus_dev_fatal(dev, err,
>  					 "granting access to ring page");
> diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
> index b17707e..ee6d9ef 100644
> --- a/drivers/xen/xenbus/xenbus_dev_backend.c
> +++ b/drivers/xen/xenbus/xenbus_dev_backend.c
> @@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
>  		goto out_err;
>  
>  	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
> -			virt_to_mfn(xen_store_interface), 0 /* writable */);
> +			virt_to_gfn(xen_store_interface), 0 /* writable */);
>  
>  	arg.dom = DOMID_SELF;
>  	arg.remote_dom = domid;
> diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> index 4308fb3..b3870f4 100644
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
>  	if (!page)
>  		goto out_err;
>  
> -	xen_store_mfn = xen_start_info->store_mfn =
> -		pfn_to_mfn(virt_to_phys((void *)page) >>
> -			   PAGE_SHIFT);
> +	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
>  
>  	/* Next allocate a local port which xenstored can bind to */
>  	alloc_unbound.dom        = DOMID_SELF;
> @@ -787,12 +785,12 @@ static int __init xenbus_init(void)
>  		err = xenstored_local_init();
>  		if (err)
>  			goto out_error;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_PV:
>  		xen_store_evtchn = xen_start_info->store_evtchn;
>  		xen_store_mfn = xen_start_info->store_mfn;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_HVM:
>  		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }
>  
>  struct xen_memory_region {
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
                     ` (6 preceding siblings ...)
  (?)
@ 2015-08-05 10:08   ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-05 10:08 UTC (permalink / raw)
  To: Julien Grall
  Cc: linux-fbdev, H. Peter Anvin, Thomas Gleixner, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, Jiri Slaby,
	xen-devel, Jean-Christophe Plagniol-Villard, linux-input,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 23167 bytes --]

On Tue, 4 Aug 2015, Julien Grall wrote:
> Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> is meant, I suspect this is because the first support for Xen was for
> PV. This resulted in some misimplementation of helpers on ARM and
> confused developers about the expected behavior.
>
> For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> Although, if we look at the implementation on x86, it's returning a GFN.
>
> For clarity and avoid new confusion, replace any reference to mfn with
> gfn in any helpers used by PV drivers. The x86 code will still keep some
> reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> to ensure this). No changes as been made in the hypercall field, even
> though they may be invalid, in order to keep the same as the defintion
> in xen repo.
>
> Take also the opportunity to simplify simple construction such
> as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> will come in follow-up patches.
>
> [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
>
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: linux-input@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Cc: linux-scsi@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-fbdev@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org

Aside from the x86 bits:

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>


>     Note that I've re-introduced mfn_to_pfn & co only for x86 PV code.
>     The helpers contain a BUG_ON to ensure that it's never called for
>     auto-translated guests. I did as best as my can to determine whether
>     mfn or gfn helpers should be used. Although, I haven't tried to boot
>     it.
>
>     It may be possible to do further cleanup in the mmu.c where I found
>     some check to auto-translated. I'm not sure why given that the pvmmu
>     callback are only used for non-auto translated guest.
>
>     Finally, given those changes, I didn't retain the Reviewed-by/Acked-by.
>
>     Changes in v2:
>         - Give directly the URL to the commit rather than the commit ID
>         - xenstored_local_init: keep the cast to void *
>         - Typoes
>         - Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
>         used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
>         smp.c and mm.c
> ---
>  arch/arm/include/asm/xen/page.h         | 13 +++++++------
>  arch/x86/include/asm/xen/page.h         | 33 ++++++++++++++++++++++++++-------
>  arch/x86/xen/smp.c                      |  2 +-
>  drivers/block/xen-blkfront.c            |  6 +++---
>  drivers/input/misc/xen-kbdfront.c       |  4 ++--
>  drivers/net/xen-netback/netback.c       |  4 ++--
>  drivers/net/xen-netfront.c              |  8 ++++----
>  drivers/scsi/xen-scsifront.c            |  8 +++-----
>  drivers/tty/hvc/hvc_xen.c               |  5 +++--
>  drivers/video/fbdev/xen-fbfront.c       |  4 ++--
>  drivers/xen/balloon.c                   |  2 +-
>  drivers/xen/events/events_base.c        |  2 +-
>  drivers/xen/events/events_fifo.c        |  4 ++--
>  drivers/xen/gntalloc.c                  |  3 ++-
>  drivers/xen/manage.c                    |  2 +-
>  drivers/xen/tmem.c                      |  4 ++--
>  drivers/xen/xenbus/xenbus_client.c      |  2 +-
>  drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
>  drivers/xen/xenbus/xenbus_probe.c       |  8 +++-----
>  include/xen/page.h                      |  4 ++--
>  20 files changed, 69 insertions(+), 51 deletions(-)
>
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 087d86e..51e5bf1 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -34,14 +34,15 @@ typedef struct xpaddr {
>  unsigned long __pfn_to_mfn(unsigned long pfn);
>  extern struct rb_root phys_to_mach;
>
> -static inline unsigned long pfn_to_mfn(unsigned long pfn)
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>  	return pfn;
>  }
>
> -static inline unsigned long mfn_to_pfn(unsigned long mfn)
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
>  {
> -	return mfn;
> +	return gfn;
>  }
>
>  /* Pseudo-physical <-> BUS conversion */
> @@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
>
>  #define bfn_to_local_pfn(bfn)	bfn_to_pfn(bfn)
>
> -/* VIRT <-> MACHINE conversion */
> -#define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
> -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(m)		(__va(gfn_to_pfn(m) << PAGE_SHIFT))
>
>  /* Only used in PV code. But ARM guests are always HVM. */
>  static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 8ba04b8..c2da42f 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -103,8 +103,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
>  {
>  	unsigned long mfn;
>
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return pfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>
>  	mfn = __pfn_to_mfn(pfn);
>
> @@ -149,8 +148,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
>  {
>  	unsigned long pfn;
>
> -	if (xen_feature(XENFEAT_auto_translated_physmap))
> -		return mfn;
> +	BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
>
>  	pfn = mfn_to_pfn_no_overrides(mfn);
>  	if (__pfn_to_mfn(pfn) != mfn)
> @@ -178,9 +176,26 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
>  	return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
>  }
>
> +/* Pseudo-physical <-> Guest conversion */
> +static inline unsigned long pfn_to_gfn(unsigned long pfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return pfn;
> +	else
> +		return pfn_to_mfn(pfn);
> +}
> +
> +static inline unsigned long gfn_to_pfn(unsigned long gfn)
> +{
> +	if (xen_feature(XENFEAT_auto_translated_physmap))
> +		return gfn;
> +	else
> +		return mfn_to_pfn(gfn);
> +}
> +
>  /* Pseudo-physical <-> Bus conversion */
> -#define pfn_to_bfn(pfn)		pfn_to_mfn(pfn)
> -#define bfn_to_pfn(bfn)		mfn_to_pfn(bfn)
> +#define pfn_to_bfn(pfn)		pfn_to_gfn(pfn)
> +#define bfn_to_pfn(bfn)		gfn_to_pfn(bfn)
>
>  /*
>   * We detect special mappings in one of two ways:
> @@ -217,9 +232,13 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
>
>  /* VIRT <-> MACHINE conversion */
>  #define virt_to_machine(v)	(phys_to_machine(XPADDR(__pa(v))))
> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>  #define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> +
> +/* VIRT <-> GUEST conversion */
> +#define virt_to_gfn(v)		(pfn_to_gfn(virt_to_pfn(v)))
> +#define gfn_to_virt(g)		(__va(gfn_to_pfn(g) << PAGE_SHIFT))
>
>  static inline unsigned long pte_mfn(pte_t pte)
>  {
> diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
> index 8648438..1e0931b 100644
> --- a/arch/x86/xen/smp.c
> +++ b/arch/x86/xen/smp.c
> @@ -429,7 +429,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
>  	}
>  #endif
>  	ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
> -	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
> +	ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
>  	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
>  		BUG();
>
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 6d89ed3..2e541a4 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -247,7 +247,7 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>                                 struct blkfront_info *info)
>  {
>  	struct grant *gnt_list_entry;
> -	unsigned long buffer_mfn;
> +	unsigned long buffer_gfn;
>
>  	BUG_ON(list_empty(&info->grants));
>  	gnt_list_entry = list_first_entry(&info->grants, struct grant,
> @@ -266,10 +266,10 @@ static struct grant *get_grant(grant_ref_t *gref_head,
>  		BUG_ON(!pfn);
>  		gnt_list_entry->pfn = pfn;
>  	}
> -	buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
> +	buffer_gfn = pfn_to_gfn(gnt_list_entry->pfn);
>  	gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
>  	                                info->xbdev->otherend_id,
> -	                                buffer_mfn, 0);
> +	                                buffer_gfn, 0);
>  	return gnt_list_entry;
>  }
>
> diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> index 95599e4..23d0549 100644
> --- a/drivers/input/misc/xen-kbdfront.c
> +++ b/drivers/input/misc/xen-kbdfront.c
> @@ -232,7 +232,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  	struct xenbus_transaction xbt;
>
>  	ret = gnttab_grant_foreign_access(dev->otherend_id,
> -	                                  virt_to_mfn(info->page), 0);
> +	                                  virt_to_gfn(info->page), 0);
>  	if (ret < 0)
>  		return ret;
>  	info->gref = ret;
> @@ -255,7 +255,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
>  		goto error_irqh;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index f948c46..5cdab73 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -291,7 +291,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		struct sk_buff *skb;
>  		unsigned short id;
>  		grant_ref_t ref;
> -		unsigned long pfn;
> +		unsigned long gfn;
>  		struct xen_netif_rx_request *req;
>
>  		skb = xennet_alloc_one_rx_buffer(queue);
> @@ -307,12 +307,12 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
>  		BUG_ON((signed short)ref < 0);
>  		queue->grant_rx_ref[id] = ref;
>
> -		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
> +		gfn = page_to_gfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
>
>  		req = RING_GET_REQUEST(&queue->rx, req_prod);
>  		gnttab_grant_foreign_access_ref(ref,
>  						queue->info->xbdev->otherend_id,
> -						pfn_to_mfn(pfn),
> +						gfn,
>  						0);
>
>  		req->id = id;
> @@ -431,7 +431,7 @@ static struct xen_netif_tx_request *xennet_make_one_txreq(
>  	BUG_ON((signed short)ref < 0);
>
>  	gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
> -					page_to_mfn(page), GNTMAP_readonly);
> +					page_to_gfn(page), GNTMAP_readonly);
>
>  	queue->tx_skbs[id].skb = skb;
>  	queue->grant_tx_page[id] = page;
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index fad22ca..cdf00d1 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -377,7 +377,6 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  	unsigned int data_len = scsi_bufflen(sc);
>  	unsigned int data_grants = 0, seg_grants = 0;
>  	struct scatterlist *sg;
> -	unsigned long mfn;
>  	struct scsiif_request_segment *seg;
>
>  	ring_req->nr_segments = 0;
> @@ -420,9 +419,8 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, 1);
> +				info->dev->otherend_id, page_to_gfn(page), 1);
>  			shadow->gref[ref_cnt] = ref;
>  			ring_req->seg[ref_cnt].gref   = ref;
>  			ring_req->seg[ref_cnt].offset = (uint16_t)off;
> @@ -454,9 +452,9 @@ static int map_data_for_request(struct vscsifrnt_info *info,
>  			ref = gnttab_claim_grant_reference(&gref_head);
>  			BUG_ON(ref == -ENOSPC);
>
> -			mfn = pfn_to_mfn(page_to_pfn(page));
>  			gnttab_grant_foreign_access_ref(ref,
> -				info->dev->otherend_id, mfn, grant_ro);
> +				info->dev->otherend_id, page_to_gfn(page),
> +				grant_ro);
>
>  			shadow->gref[ref_cnt] = ref;
>  			seg->gref   = ref;
> diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
> index a9d837f..efe5124 100644
> --- a/drivers/tty/hvc/hvc_xen.c
> +++ b/drivers/tty/hvc/hvc_xen.c
> @@ -265,7 +265,8 @@ static int xen_pv_console_init(void)
>  		return 0;
>  	}
>  	info->evtchn = xen_start_info->console.domU.evtchn;
> -	info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
> +	/* GFN == MFN for PV guest */
> +	info->intf = gfn_to_virt(xen_start_info->console.domU.mfn);
>  	info->vtermno = HVC_COOKIE;
>
>  	spin_lock(&xencons_lock);
> @@ -390,7 +391,7 @@ static int xencons_connect_backend(struct xenbus_device *dev,
>  	if (IS_ERR(info->hvc))
>  		return PTR_ERR(info->hvc);
>  	if (xen_pv_domain())
> -		mfn = virt_to_mfn(info->intf);
> +		mfn = virt_to_gfn(info->intf);
>  	else
>  		mfn = __pa(info->intf) >> PAGE_SHIFT;
>  	ret = gnttab_alloc_grant_references(1, &gref_head);
> diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c
> index 09dc447..25e3cce 100644
> --- a/drivers/video/fbdev/xen-fbfront.c
> +++ b/drivers/video/fbdev/xen-fbfront.c
> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>
>  static unsigned long vmalloc_to_mfn(void *address)
>  {
> -	return pfn_to_mfn(vmalloc_to_pfn(address));
> +	return pfn_to_gfn(vmalloc_to_pfn(address));
>  }
>
>  static void xenfb_init_shared_page(struct xenfb_info *info,
> @@ -586,7 +586,7 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
>  		goto unbind_irq;
>  	}
>  	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
> -			    virt_to_mfn(info->page));
> +			    virt_to_gfn(info->page));
>  	if (ret)
>  		goto error_xenbus;
>  	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> index bf4a23c..5df28cd 100644
> --- a/drivers/xen/balloon.c
> +++ b/drivers/xen/balloon.c
> @@ -441,7 +441,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
>  	/* Update direct mapping, invalidate P2M, and add to balloon. */
>  	for (i = 0; i < nr_pages; i++) {
>  		pfn = frame_list[i];
> -		frame_list[i] = pfn_to_mfn(pfn);
> +		frame_list[i] = pfn_to_gfn(pfn);
>  		page = pfn_to_page(pfn);
>
>  #ifdef CONFIG_XEN_HAVE_PVMMU
> diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
> index 1495ecc..10fd9c6 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1694,7 +1694,7 @@ void __init xen_init_IRQ(void)
>  		struct physdev_pirq_eoi_gmfn eoi_gmfn;
>
>  		pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
> -		eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map);
> +		eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
>  		rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn);
>  		/* TODO: No PVH support for PIRQ EOI */
>  		if (rc != 0) {
> diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
> index 6df8aac..2e55e90 100644
> --- a/drivers/xen/events/events_fifo.c
> +++ b/drivers/xen/events/events_fifo.c
> @@ -111,7 +111,7 @@ static int init_control_block(int cpu,
>  	for (i = 0; i < EVTCHN_FIFO_MAX_QUEUES; i++)
>  		q->head[i] = 0;
>
> -	init_control.control_gfn = virt_to_mfn(control_block);
> +	init_control.control_gfn = virt_to_gfn(control_block);
>  	init_control.offset      = 0;
>  	init_control.vcpu        = cpu;
>
> @@ -167,7 +167,7 @@ static int evtchn_fifo_setup(struct irq_info *info)
>  		/* Mask all events in this page before adding it. */
>  		init_array_page(array_page);
>
> -		expand_array.array_gfn = virt_to_mfn(array_page);
> +		expand_array.array_gfn = virt_to_gfn(array_page);
>
>  		ret = HYPERVISOR_event_channel_op(EVTCHNOP_expand_array, &expand_array);
>  		if (ret < 0)
> diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
> index e53fe19..13e1458 100644
> --- a/drivers/xen/gntalloc.c
> +++ b/drivers/xen/gntalloc.c
> @@ -142,7 +142,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
>
>  		/* Grant foreign access to the page. */
>  		rc = gnttab_grant_foreign_access(op->domid,
> -			pfn_to_mfn(page_to_pfn(gref->page)), readonly);
> +						 page_to_gfn(gref->page),
> +						 readonly);
>  		if (rc < 0)
>  			goto undo;
>  		gref_ids[i] = gref->gref_id = rc;
> diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
> index d10effe..e12bd36 100644
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -80,7 +80,7 @@ static int xen_suspend(void *data)
>  	 * is resuming in a new domain.
>  	 */
>  	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
> -                                           ? virt_to_mfn(xen_start_info)
> +                                           ? virt_to_gfn(xen_start_info)
>                                             : 0);
>
>  	xen_arch_post_suspend(si->cancelled);
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index 239738f..28c97ff 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -131,7 +131,7 @@ static int xen_tmem_new_pool(struct tmem_pool_uuid uuid,
>  static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>
>  	return xen_tmem_op(TMEM_PUT_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> @@ -140,7 +140,7 @@ static int xen_tmem_put_page(u32 pool_id, struct tmem_oid oid,
>  static int xen_tmem_get_page(u32 pool_id, struct tmem_oid oid,
>  			     u32 index, unsigned long pfn)
>  {
> -	unsigned long gmfn = xen_pv_domain() ? pfn_to_mfn(pfn) : pfn;
> +	unsigned long gmfn = pfn_to_gfn(pfn);
>
>  	return xen_tmem_op(TMEM_GET_PAGE, pool_id, oid, index,
>  		gmfn, 0, 0, 0);
> diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
> index 9ad3272..daa267a 100644
> --- a/drivers/xen/xenbus/xenbus_client.c
> +++ b/drivers/xen/xenbus/xenbus_client.c
> @@ -380,7 +380,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
>
>  	for (i = 0; i < nr_pages; i++) {
>  		err = gnttab_grant_foreign_access(dev->otherend_id,
> -						  virt_to_mfn(vaddr), 0);
> +						  virt_to_gfn(vaddr), 0);
>  		if (err < 0) {
>  			xenbus_dev_fatal(dev, err,
>  					 "granting access to ring page");
> diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
> index b17707e..ee6d9ef 100644
> --- a/drivers/xen/xenbus/xenbus_dev_backend.c
> +++ b/drivers/xen/xenbus/xenbus_dev_backend.c
> @@ -49,7 +49,7 @@ static long xenbus_alloc(domid_t domid)
>  		goto out_err;
>
>  	gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
> -			virt_to_mfn(xen_store_interface), 0 /* writable */);
> +			virt_to_gfn(xen_store_interface), 0 /* writable */);
>
>  	arg.dom = DOMID_SELF;
>  	arg.remote_dom = domid;
> diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> index 4308fb3..b3870f4 100644
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -711,9 +711,7 @@ static int __init xenstored_local_init(void)
>  	if (!page)
>  		goto out_err;
>
> -	xen_store_mfn = xen_start_info->store_mfn =
> -		pfn_to_mfn(virt_to_phys((void *)page) >>
> -			   PAGE_SHIFT);
> +	xen_store_mfn = xen_start_info->store_mfn = virt_to_gfn((void *)page);
>
>  	/* Next allocate a local port which xenstored can bind to */
>  	alloc_unbound.dom        = DOMID_SELF;
> @@ -787,12 +785,12 @@ static int __init xenbus_init(void)
>  		err = xenstored_local_init();
>  		if (err)
>  			goto out_error;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_PV:
>  		xen_store_evtchn = xen_start_info->store_evtchn;
>  		xen_store_mfn = xen_start_info->store_mfn;
> -		xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		xen_store_interface = gfn_to_virt(xen_store_mfn);
>  		break;
>  	case XS_HVM:
>  		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>
>  #include <asm/xen/page.h>
>
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }
>
>  struct xen_memory_region {
> --
> 2.1.4
> 

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
  2015-08-05  9:49     ` Stefano Stabellini
@ 2015-08-05 10:31       ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:31 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel, ian.campbell, linux-kernel, Russell King,
	Konrad Rzeszutek Wilk, Boris Ostrovsky, David Vrabel,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	linux-arm-kernel

Hi Stefano,

On 05/08/15 10:49, Stefano Stabellini wrote:
>>  /* VIRT <-> MACHINE conversion */
>>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>> @@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
>>  
>>  bool xen_arch_need_swiotlb(struct device *dev,
>>  			   unsigned long pfn,
>> -			   unsigned long mfn);
>> +			   unsigned long dfn);
>>  unsigned long xen_get_swiotlb_free_pages(unsigned int order);
> 
> You missed a bunch of dfn->bfn renamings.

Sorry, I forgot to double check that before sending the patch. I will
fix it in the next version.

> Aside from those and the commit message error:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Thank you!

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
@ 2015-08-05 10:31       ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Stefano,

On 05/08/15 10:49, Stefano Stabellini wrote:
>>  /* VIRT <-> MACHINE conversion */
>>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>> @@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
>>  
>>  bool xen_arch_need_swiotlb(struct device *dev,
>>  			   unsigned long pfn,
>> -			   unsigned long mfn);
>> +			   unsigned long dfn);
>>  unsigned long xen_get_swiotlb_free_pages(unsigned int order);
> 
> You missed a bunch of dfn->bfn renamings.

Sorry, I forgot to double check that before sending the patch. I will
fix it in the next version.

> Aside from those and the commit message error:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Thank you!

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address
  2015-08-05  9:49     ` Stefano Stabellini
  (?)
  (?)
@ 2015-08-05 10:31     ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:31 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Russell King, ian.campbell, x86, linux-kernel, Ingo Molnar,
	David Vrabel, H. Peter Anvin, xen-devel, Boris Ostrovsky,
	Thomas Gleixner, linux-arm-kernel

Hi Stefano,

On 05/08/15 10:49, Stefano Stabellini wrote:
>>  /* VIRT <-> MACHINE conversion */
>>  #define virt_to_mfn(v)		(pfn_to_mfn(virt_to_pfn(v)))
>> @@ -96,7 +115,7 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
>>  
>>  bool xen_arch_need_swiotlb(struct device *dev,
>>  			   unsigned long pfn,
>> -			   unsigned long mfn);
>> +			   unsigned long dfn);
>>  unsigned long xen_get_swiotlb_free_pages(unsigned int order);
> 
> You missed a bunch of dfn->bfn renamings.

Sorry, I forgot to double check that before sending the patch. I will
fix it in the next version.

> Aside from those and the commit message error:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Thank you!

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 23:16     ` Boris Ostrovsky
                         ` (2 preceding siblings ...)
  (?)
@ 2015-08-05 10:51       ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:51 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

Hi Boris,

On 05/08/15 00:16, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
>>     /*
>>    * We detect special mappings in one of two ways:
>> @@ -217,9 +232,13 @@ static inline unsigned long
>> bfn_to_local_pfn(unsigned long mfn)
>>     /* VIRT <-> MACHINE conversion */
>>   #define virt_to_machine(v)    (phys_to_machine(XPADDR(__pa(v))))
>> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>>   #define virt_to_mfn(v)        (pfn_to_mfn(virt_to_pfn(v)))
>>   #define mfn_to_virt(m)        (__va(mfn_to_pfn(m) << PAGE_SHIFT))
>> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.

Right, I made the mistake when I re-introduced virt_to_mfn in this
version. It was dropped in the previous one.

>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>> b/drivers/video/fbdev/xen-fbfront.c
>> index 09dc447..25e3cce 100644
>> --- a/drivers/video/fbdev/xen-fbfront.c
>> +++ b/drivers/video/fbdev/xen-fbfront.c
>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>     static unsigned long vmalloc_to_mfn(void *address)
>>   {
>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?

If so, it will be only the case on auto-translated case (because pfn ==
gfn). In the case of PV, the mfn will be returned.

Although, this function is misnamed. It's fixed in a follow-up patch
(see #6) because it's required more renaming than this function. I
didn't want to add such changes within this patch.

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:51       ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:51 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev

Hi Boris,

On 05/08/15 00:16, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
>>     /*
>>    * We detect special mappings in one of two ways:
>> @@ -217,9 +232,13 @@ static inline unsigned long
>> bfn_to_local_pfn(unsigned long mfn)
>>     /* VIRT <-> MACHINE conversion */
>>   #define virt_to_machine(v)    (phys_to_machine(XPADDR(__pa(v))))
>> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>>   #define virt_to_mfn(v)        (pfn_to_mfn(virt_to_pfn(v)))
>>   #define mfn_to_virt(m)        (__va(mfn_to_pfn(m) << PAGE_SHIFT))
>> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.

Right, I made the mistake when I re-introduced virt_to_mfn in this
version. It was dropped in the previous one.

>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>> b/drivers/video/fbdev/xen-fbfront.c
>> index 09dc447..25e3cce 100644
>> --- a/drivers/video/fbdev/xen-fbfront.c
>> +++ b/drivers/video/fbdev/xen-fbfront.c
>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>     static unsigned long vmalloc_to_mfn(void *address)
>>   {
>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?

If so, it will be only the case on auto-translated case (because pfn ==
gfn). In the case of PV, the mfn will be returned.

Although, this function is misnamed. It's fixed in a follow-up patch
(see #6) because it's required more renaming than this function. I
didn't want to add such changes within this patch.

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:51       ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:51 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev

Hi Boris,

On 05/08/15 00:16, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
>>     /*
>>    * We detect special mappings in one of two ways:
>> @@ -217,9 +232,13 @@ static inline unsigned long
>> bfn_to_local_pfn(unsigned long mfn)
>>     /* VIRT <-> MACHINE conversion */
>>   #define virt_to_machine(v)    (phys_to_machine(XPADDR(__pa(v))))
>> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>>   #define virt_to_mfn(v)        (pfn_to_mfn(virt_to_pfn(v)))
>>   #define mfn_to_virt(m)        (__va(mfn_to_pfn(m) << PAGE_SHIFT))
>> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.

Right, I made the mistake when I re-introduced virt_to_mfn in this
version. It was dropped in the previous one.

>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>> b/drivers/video/fbdev/xen-fbfront.c
>> index 09dc447..25e3cce 100644
>> --- a/drivers/video/fbdev/xen-fbfront.c
>> +++ b/drivers/video/fbdev/xen-fbfront.c
>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>     static unsigned long vmalloc_to_mfn(void *address)
>>   {
>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?

If so, it will be only the case on auto-translated case (because pfn ==
gfn). In the case of PV, the mfn will be returned.

Although, this function is misnamed. It's fixed in a follow-up patch
(see #6) because it's required more renaming than this function. I
didn't want to add such changes within this patch.

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:51       ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:51 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Boris,

On 05/08/15 00:16, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
>>     /*
>>    * We detect special mappings in one of two ways:
>> @@ -217,9 +232,13 @@ static inline unsigned long
>> bfn_to_local_pfn(unsigned long mfn)
>>     /* VIRT <-> MACHINE conversion */
>>   #define virt_to_machine(v)    (phys_to_machine(XPADDR(__pa(v))))
>> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>>   #define virt_to_mfn(v)        (pfn_to_mfn(virt_to_pfn(v)))
>>   #define mfn_to_virt(m)        (__va(mfn_to_pfn(m) << PAGE_SHIFT))
>> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.

Right, I made the mistake when I re-introduced virt_to_mfn in this
version. It was dropped in the previous one.

>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>> b/drivers/video/fbdev/xen-fbfront.c
>> index 09dc447..25e3cce 100644
>> --- a/drivers/video/fbdev/xen-fbfront.c
>> +++ b/drivers/video/fbdev/xen-fbfront.c
>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>     static unsigned long vmalloc_to_mfn(void *address)
>>   {
>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?

If so, it will be only the case on auto-translated case (because pfn =
gfn). In the case of PV, the mfn will be returned.

Although, this function is misnamed. It's fixed in a follow-up patch
(see #6) because it's required more renaming than this function. I
didn't want to add such changes within this patch.

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 10:51       ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:51 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Boris,

On 05/08/15 00:16, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
>>     /*
>>    * We detect special mappings in one of two ways:
>> @@ -217,9 +232,13 @@ static inline unsigned long
>> bfn_to_local_pfn(unsigned long mfn)
>>     /* VIRT <-> MACHINE conversion */
>>   #define virt_to_machine(v)    (phys_to_machine(XPADDR(__pa(v))))
>> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>>   #define virt_to_mfn(v)        (pfn_to_mfn(virt_to_pfn(v)))
>>   #define mfn_to_virt(m)        (__va(mfn_to_pfn(m) << PAGE_SHIFT))
>> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.

Right, I made the mistake when I re-introduced virt_to_mfn in this
version. It was dropped in the previous one.

>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>> b/drivers/video/fbdev/xen-fbfront.c
>> index 09dc447..25e3cce 100644
>> --- a/drivers/video/fbdev/xen-fbfront.c
>> +++ b/drivers/video/fbdev/xen-fbfront.c
>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>     static unsigned long vmalloc_to_mfn(void *address)
>>   {
>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?

If so, it will be only the case on auto-translated case (because pfn ==
gfn). In the case of PV, the mfn will be returned.

Although, this function is misnamed. It's fixed in a follow-up patch
(see #6) because it's required more renaming than this function. I
didn't want to add such changes within this patch.

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 23:16     ` Boris Ostrovsky
                       ` (4 preceding siblings ...)
  (?)
@ 2015-08-05 10:51     ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 10:51 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

Hi Boris,

On 05/08/15 00:16, Boris Ostrovsky wrote:
> On 08/04/2015 02:12 PM, Julien Grall wrote:
>>     /*
>>    * We detect special mappings in one of two ways:
>> @@ -217,9 +232,13 @@ static inline unsigned long
>> bfn_to_local_pfn(unsigned long mfn)
>>     /* VIRT <-> MACHINE conversion */
>>   #define virt_to_machine(v)    (phys_to_machine(XPADDR(__pa(v))))
>> -#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
>>   #define virt_to_mfn(v)        (pfn_to_mfn(virt_to_pfn(v)))
>>   #define mfn_to_virt(m)        (__va(mfn_to_pfn(m) << PAGE_SHIFT))
>> +#define virt_to_pfn(v)          (PFN_DOWN(__pa(v)))
> 
> This looks like unnecessary change.

Right, I made the mistake when I re-introduced virt_to_mfn in this
version. It was dropped in the previous one.

>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>> b/drivers/video/fbdev/xen-fbfront.c
>> index 09dc447..25e3cce 100644
>> --- a/drivers/video/fbdev/xen-fbfront.c
>> +++ b/drivers/video/fbdev/xen-fbfront.c
>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>     static unsigned long vmalloc_to_mfn(void *address)
>>   {
>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>   }
> 
> Are you sure? This will return vmalloc_to_pfn(address)).

I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?

If so, it will be only the case on auto-translated case (because pfn ==
gfn). In the case of PV, the mfn will be returned.

Although, this function is misnamed. It's fixed in a follow-up patch
(see #6) because it's required more renaming than this function. I
didn't want to add such changes within this patch.

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 10:51       ` Julien Grall
  (?)
  (?)
@ 2015-08-05 12:19         ` Boris Ostrovsky
  -1 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:19 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

On 08/05/2015 06:51 AM, Julien Grall wrote:
>
>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>> b/drivers/video/fbdev/xen-fbfront.c
>>> index 09dc447..25e3cce 100644
>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>    {
>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>    }
>> Are you sure? This will return vmalloc_to_pfn(address)).
> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>
> If so, it will be only the case on auto-translated case (because pfn ==
> gfn). In the case of PV, the mfn will be returned.

How will mfn be returned on PV when pfn_to_gfn() is an identity function?

static inline unsigned long pfn_to_gfn(unsigned long pfn)
  {
      return pfn;
  }


-boris

>
> Although, this function is misnamed. It's fixed in a follow-up patch
> (see #6) because it's required more renaming than this function. I
> didn't want to add such changes within this patch.
>
> Regards,
>


^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:19         ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:19 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	Konrad Rzeszutek Wilk, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev

On 08/05/2015 06:51 AM, Julien Grall wrote:
>
>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>> b/drivers/video/fbdev/xen-fbfront.c
>>> index 09dc447..25e3cce 100644
>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>    {
>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>    }
>> Are you sure? This will return vmalloc_to_pfn(address)).
> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>
> If so, it will be only the case on auto-translated case (because pfn ==
> gfn). In the case of PV, the mfn will be returned.

How will mfn be returned on PV when pfn_to_gfn() is an identity function?

static inline unsigned long pfn_to_gfn(unsigned long pfn)
  {
      return pfn;
  }


-boris

>
> Although, this function is misnamed. It's fixed in a follow-up patch
> (see #6) because it's required more renaming than this function. I
> didn't want to add such changes within this patch.
>
> Regards,
>


^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:19         ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:19 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/05/2015 06:51 AM, Julien Grall wrote:
>
>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>> b/drivers/video/fbdev/xen-fbfront.c
>>> index 09dc447..25e3cce 100644
>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>    {
>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>    }
>> Are you sure? This will return vmalloc_to_pfn(address)).
> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>
> If so, it will be only the case on auto-translated case (because pfn =
> gfn). In the case of PV, the mfn will be returned.

How will mfn be returned on PV when pfn_to_gfn() is an identity function?

static inline unsigned long pfn_to_gfn(unsigned long pfn)
  {
      return pfn;
  }


-boris

>
> Although, this function is misnamed. It's fixed in a follow-up patch
> (see #6) because it's required more renaming than this function. I
> didn't want to add such changes within this patch.
>
> Regards,
>


^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:19         ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:19 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/05/2015 06:51 AM, Julien Grall wrote:
>
>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>> b/drivers/video/fbdev/xen-fbfront.c
>>> index 09dc447..25e3cce 100644
>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>    {
>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>    }
>> Are you sure? This will return vmalloc_to_pfn(address)).
> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>
> If so, it will be only the case on auto-translated case (because pfn ==
> gfn). In the case of PV, the mfn will be returned.

How will mfn be returned on PV when pfn_to_gfn() is an identity function?

static inline unsigned long pfn_to_gfn(unsigned long pfn)
  {
      return pfn;
  }


-boris

>
> Although, this function is misnamed. It's fixed in a follow-up patch
> (see #6) because it's required more renaming than this function. I
> didn't want to add such changes within this patch.
>
> Regards,
>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 10:51       ` Julien Grall
                         ` (3 preceding siblings ...)
  (?)
@ 2015-08-05 12:19       ` Boris Ostrovsky
  -1 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:19 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

On 08/05/2015 06:51 AM, Julien Grall wrote:
>
>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>> b/drivers/video/fbdev/xen-fbfront.c
>>> index 09dc447..25e3cce 100644
>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>    {
>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>    }
>> Are you sure? This will return vmalloc_to_pfn(address)).
> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>
> If so, it will be only the case on auto-translated case (because pfn ==
> gfn). In the case of PV, the mfn will be returned.

How will mfn be returned on PV when pfn_to_gfn() is an identity function?

static inline unsigned long pfn_to_gfn(unsigned long pfn)
  {
      return pfn;
  }


-boris

>
> Although, this function is misnamed. It's fixed in a follow-up patch
> (see #6) because it's required more renaming than this function. I
> didn't want to add such changes within this patch.
>
> Regards,
>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 12:19         ` Boris Ostrovsky
                             ` (2 preceding siblings ...)
  (?)
@ 2015-08-05 12:33           ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 12:33 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

On 05/08/15 13:19, Boris Ostrovsky wrote:
> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>
>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>> index 09dc447..25e3cce 100644
>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>>    {
>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>    }
>>> Are you sure? This will return vmalloc_to_pfn(address)).
>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>
>> If so, it will be only the case on auto-translated case (because pfn ==
>> gfn). In the case of PV, the mfn will be returned.
> 
> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
> 
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>      return pfn;
>  }

The identity function is only for ARM guest which are always
auto-translated (arch/arm/include/asm/xen/page.h).

The x86 version contains a check if the guest is auto-translated or not
(arch/x86/include/asm/xen/page.):

static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
        else
                return pfn_to_mfn(pfn);
}

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:33           ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 12:33 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

On 05/08/15 13:19, Boris Ostrovsky wrote:
> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>
>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>> index 09dc447..25e3cce 100644
>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>>    {
>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>    }
>>> Are you sure? This will return vmalloc_to_pfn(address)).
>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>
>> If so, it will be only the case on auto-translated case (because pfn ==
>> gfn). In the case of PV, the mfn will be returned.
> 
> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
> 
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>      return pfn;
>  }

The identity function is only for ARM guest which are always
auto-translated (arch/arm/include/asm/xen/page.h).

The x86 version contains a check if the guest is auto-translated or not
(arch/x86/include/asm/xen/page.):

static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
        else
                return pfn_to_mfn(pfn);
}

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:33           ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 12:33 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

On 05/08/15 13:19, Boris Ostrovsky wrote:
> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>
>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>> index 09dc447..25e3cce 100644
>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>>    {
>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>    }
>>> Are you sure? This will return vmalloc_to_pfn(address)).
>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>
>> If so, it will be only the case on auto-translated case (because pfn ==
>> gfn). In the case of PV, the mfn will be returned.
> 
> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
> 
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>      return pfn;
>  }

The identity function is only for ARM guest which are always
auto-translated (arch/arm/include/asm/xen/page.h).

The x86 version contains a check if the guest is auto-translated or not
(arch/x86/include/asm/xen/page.):

static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
        else
                return pfn_to_mfn(pfn);
}

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:33           ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 12:33 UTC (permalink / raw)
  To: linux-arm-kernel

On 05/08/15 13:19, Boris Ostrovsky wrote:
> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>
>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>> index 09dc447..25e3cce 100644
>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>>    {
>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>    }
>>> Are you sure? This will return vmalloc_to_pfn(address)).
>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>
>> If so, it will be only the case on auto-translated case (because pfn =
>> gfn). In the case of PV, the mfn will be returned.
> 
> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
> 
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>      return pfn;
>  }

The identity function is only for ARM guest which are always
auto-translated (arch/arm/include/asm/xen/page.h).

The x86 version contains a check if the guest is auto-translated or not
(arch/x86/include/asm/xen/page.):

static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
        else
                return pfn_to_mfn(pfn);
}

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:33           ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 12:33 UTC (permalink / raw)
  To: linux-arm-kernel

On 05/08/15 13:19, Boris Ostrovsky wrote:
> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>
>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>> index 09dc447..25e3cce 100644
>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>>    {
>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>    }
>>> Are you sure? This will return vmalloc_to_pfn(address)).
>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>
>> If so, it will be only the case on auto-translated case (because pfn ==
>> gfn). In the case of PV, the mfn will be returned.
> 
> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
> 
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>      return pfn;
>  }

The identity function is only for ARM guest which are always
auto-translated (arch/arm/include/asm/xen/page.h).

The x86 version contains a check if the guest is auto-translated or not
(arch/x86/include/asm/xen/page.):

static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
        else
                return pfn_to_mfn(pfn);
}

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 12:19         ` Boris Ostrovsky
                           ` (2 preceding siblings ...)
  (?)
@ 2015-08-05 12:33         ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-05 12:33 UTC (permalink / raw)
  To: Boris Ostrovsky, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu, netdev,
	Dmitry Torokhov, linux-kernel, David Vrabel, Greg Kroah-Hartman,
	linuxppc-dev, Roger Pau Monné

On 05/08/15 13:19, Boris Ostrovsky wrote:
> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>
>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>> index 09dc447..25e3cce 100644
>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>      static unsigned long vmalloc_to_mfn(void *address)
>>>>    {
>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>    }
>>> Are you sure? This will return vmalloc_to_pfn(address)).
>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>
>> If so, it will be only the case on auto-translated case (because pfn ==
>> gfn). In the case of PV, the mfn will be returned.
> 
> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
> 
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>  {
>      return pfn;
>  }

The identity function is only for ARM guest which are always
auto-translated (arch/arm/include/asm/xen/page.h).

The x86 version contains a check if the guest is auto-translated or not
(arch/x86/include/asm/xen/page.):

static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
        else
                return pfn_to_mfn(pfn);
}

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 12:33           ` Julien Grall
  (?)
  (?)
@ 2015-08-05 12:44             ` Boris Ostrovsky
  -1 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:44 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev, Roger Pau Monné

On 08/05/2015 08:33 AM, Julien Grall wrote:
> On 05/08/15 13:19, Boris Ostrovsky wrote:
>> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>>> index 09dc447..25e3cce 100644
>>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>>       static unsigned long vmalloc_to_mfn(void *address)
>>>>>     {
>>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>>     }
>>>> Are you sure? This will return vmalloc_to_pfn(address)).
>>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>>
>>> If so, it will be only the case on auto-translated case (because pfn ==
>>> gfn). In the case of PV, the mfn will be returned.
>> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
>>
>> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>>   {
>>       return pfn;
>>   }
> The identity function is only for ARM guest which are always
> auto-translated (arch/arm/include/asm/xen/page.h).
>
> The x86 version contains a check if the guest is auto-translated or not
> (arch/x86/include/asm/xen/page.):
>
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
> {
>          if (xen_feature(XENFEAT_auto_translated_physmap))
>                  return pfn;
>          else
>                  return pfn_to_mfn(pfn);
> }

Of course --- I was looking at the top of the patch and didn't realize 
it was ARM changes. Sorry for the noise.

-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:44             ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:44 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu, netdev,
	Dmitry Torokhov, linux-kernel, David Vrabel, Greg Kroah-Hartman,
	linuxppc-dev, Roger Pau Monné

On 08/05/2015 08:33 AM, Julien Grall wrote:
> On 05/08/15 13:19, Boris Ostrovsky wrote:
>> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>>> index 09dc447..25e3cce 100644
>>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>>       static unsigned long vmalloc_to_mfn(void *address)
>>>>>     {
>>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>>     }
>>>> Are you sure? This will return vmalloc_to_pfn(address)).
>>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>>
>>> If so, it will be only the case on auto-translated case (because pfn ==
>>> gfn). In the case of PV, the mfn will be returned.
>> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
>>
>> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>>   {
>>       return pfn;
>>   }
> The identity function is only for ARM guest which are always
> auto-translated (arch/arm/include/asm/xen/page.h).
>
> The x86 version contains a check if the guest is auto-translated or not
> (arch/x86/include/asm/xen/page.):
>
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
> {
>          if (xen_feature(XENFEAT_auto_translated_physmap))
>                  return pfn;
>          else
>                  return pfn_to_mfn(pfn);
> }

Of course --- I was looking at the top of the patch and didn't realize 
it was ARM changes. Sorry for the noise.

-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:44             ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:44 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/05/2015 08:33 AM, Julien Grall wrote:
> On 05/08/15 13:19, Boris Ostrovsky wrote:
>> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>>> index 09dc447..25e3cce 100644
>>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>>       static unsigned long vmalloc_to_mfn(void *address)
>>>>>     {
>>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>>     }
>>>> Are you sure? This will return vmalloc_to_pfn(address)).
>>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>>
>>> If so, it will be only the case on auto-translated case (because pfn =
>>> gfn). In the case of PV, the mfn will be returned.
>> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
>>
>> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>>   {
>>       return pfn;
>>   }
> The identity function is only for ARM guest which are always
> auto-translated (arch/arm/include/asm/xen/page.h).
>
> The x86 version contains a check if the guest is auto-translated or not
> (arch/x86/include/asm/xen/page.):
>
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
> {
>          if (xen_feature(XENFEAT_auto_translated_physmap))
>                  return pfn;
>          else
>                  return pfn_to_mfn(pfn);
> }

Of course --- I was looking at the top of the patch and didn't realize 
it was ARM changes. Sorry for the noise.

-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 12:44             ` Boris Ostrovsky
  0 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:44 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/05/2015 08:33 AM, Julien Grall wrote:
> On 05/08/15 13:19, Boris Ostrovsky wrote:
>> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>>> index 09dc447..25e3cce 100644
>>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>>       static unsigned long vmalloc_to_mfn(void *address)
>>>>>     {
>>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>>     }
>>>> Are you sure? This will return vmalloc_to_pfn(address)).
>>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>>
>>> If so, it will be only the case on auto-translated case (because pfn ==
>>> gfn). In the case of PV, the mfn will be returned.
>> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
>>
>> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>>   {
>>       return pfn;
>>   }
> The identity function is only for ARM guest which are always
> auto-translated (arch/arm/include/asm/xen/page.h).
>
> The x86 version contains a check if the guest is auto-translated or not
> (arch/x86/include/asm/xen/page.):
>
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
> {
>          if (xen_feature(XENFEAT_auto_translated_physmap))
>                  return pfn;
>          else
>                  return pfn_to_mfn(pfn);
> }

Of course --- I was looking at the top of the patch and didn't realize 
it was ARM changes. Sorry for the noise.

-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 12:33           ` Julien Grall
                             ` (3 preceding siblings ...)
  (?)
@ 2015-08-05 12:44           ` Boris Ostrovsky
  -1 siblings, 0 replies; 112+ messages in thread
From: Boris Ostrovsky @ 2015-08-05 12:44 UTC (permalink / raw)
  To: Julien Grall, xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Russell King,
	linux-scsi, x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu, netdev,
	Dmitry Torokhov, linux-kernel, David Vrabel, Greg Kroah-Hartman,
	linuxppc-dev, Roger Pau Monné

On 08/05/2015 08:33 AM, Julien Grall wrote:
> On 05/08/15 13:19, Boris Ostrovsky wrote:
>> On 08/05/2015 06:51 AM, Julien Grall wrote:
>>>>> diff --git a/drivers/video/fbdev/xen-fbfront.c
>>>>> b/drivers/video/fbdev/xen-fbfront.c
>>>>> index 09dc447..25e3cce 100644
>>>>> --- a/drivers/video/fbdev/xen-fbfront.c
>>>>> +++ b/drivers/video/fbdev/xen-fbfront.c
>>>>> @@ -539,7 +539,7 @@ static int xenfb_remove(struct xenbus_device *dev)
>>>>>       static unsigned long vmalloc_to_mfn(void *address)
>>>>>     {
>>>>> -    return pfn_to_mfn(vmalloc_to_pfn(address));
>>>>> +    return pfn_to_gfn(vmalloc_to_pfn(address));
>>>>>     }
>>>> Are you sure? This will return vmalloc_to_pfn(address)).
>>> I guess you mean vmalloc_to_mfn will return vmalloc_to_pfn?
>>>
>>> If so, it will be only the case on auto-translated case (because pfn ==
>>> gfn). In the case of PV, the mfn will be returned.
>> How will mfn be returned on PV when pfn_to_gfn() is an identity function?
>>
>> static inline unsigned long pfn_to_gfn(unsigned long pfn)
>>   {
>>       return pfn;
>>   }
> The identity function is only for ARM guest which are always
> auto-translated (arch/arm/include/asm/xen/page.h).
>
> The x86 version contains a check if the guest is auto-translated or not
> (arch/x86/include/asm/xen/page.):
>
> static inline unsigned long pfn_to_gfn(unsigned long pfn)
> {
>          if (xen_feature(XENFEAT_auto_translated_physmap))
>                  return pfn;
>          else
>                  return pfn_to_mfn(pfn);
> }

Of course --- I was looking at the top of the patch and didn't realize 
it was ARM changes. Sorry for the noise.

-boris

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 10:08     ` Stefano Stabellini
  (?)
  (?)
@ 2015-08-05 16:52       ` Dmitry Torokhov
  -1 siblings, 0 replies; 112+ messages in thread
From: Dmitry Torokhov @ 2015-08-05 16:52 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Julien Grall, xen-devel, ian.campbell, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Wei Liu, Juergen Gross, James E.J. Bottomley, Greg Kroah-Hartman,
	Jiri Slaby, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	linux-input, netdev, linux-scsi, linuxppc-dev, linux-fbdev,
	linux-arm-kernel

On Wed, Aug 05, 2015 at 11:08:55AM +0100, Stefano Stabellini wrote:
> On Tue, 4 Aug 2015, Julien Grall wrote:
> > Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> > is meant, I suspect this is because the first support for Xen was for
> > PV. This resulted in some misimplementation of helpers on ARM and
> > confused developers about the expected behavior.
> > 
> > For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> > Although, if we look at the implementation on x86, it's returning a GFN.
> > 
> > For clarity and avoid new confusion, replace any reference to mfn with
> > gfn in any helpers used by PV drivers. The x86 code will still keep some
> > reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> > to ensure this). No changes as been made in the hypercall field, even
> > though they may be invalid, in order to keep the same as the defintion
> > in xen repo.
> > 
> > Take also the opportunity to simplify simple construction such
> > as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> > will come in follow-up patches.
> > 
> > [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> > 
> > Signed-off-by: Julien Grall <julien.grall@citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Russell King <linux@arm.linux.org.uk>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: David Vrabel <david.vrabel@citrix.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: x86@kernel.org
> > Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Juergen Gross <jgross@suse.com>
> > Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> > Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> > Cc: linux-input@vger.kernel.org
> > Cc: netdev@vger.kernel.org
> > Cc: linux-scsi@vger.kernel.org
> > Cc: linuxppc-dev@lists.ozlabs.org
> > Cc: linux-fbdev@vger.kernel.org
> > Cc: linux-arm-kernel@lists.infradead.org
> 
> Aside from the x86 bits:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Not really important, but just in case anyone waits for my ack on input
bits:

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 16:52       ` Dmitry Torokhov
  0 siblings, 0 replies; 112+ messages in thread
From: Dmitry Torokhov @ 2015-08-05 16:52 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Julien Grall, xen-devel, ian.campbell, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Wei Liu, Juergen Gross, James E.J. Bottomley, Greg Kroah-Hartman,
	Jiri Slaby, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	linux-input, netdev, linux-scsi, linuxppc-dev

On Wed, Aug 05, 2015 at 11:08:55AM +0100, Stefano Stabellini wrote:
> On Tue, 4 Aug 2015, Julien Grall wrote:
> > Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> > is meant, I suspect this is because the first support for Xen was for
> > PV. This resulted in some misimplementation of helpers on ARM and
> > confused developers about the expected behavior.
> > 
> > For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> > Although, if we look at the implementation on x86, it's returning a GFN.
> > 
> > For clarity and avoid new confusion, replace any reference to mfn with
> > gfn in any helpers used by PV drivers. The x86 code will still keep some
> > reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> > to ensure this). No changes as been made in the hypercall field, even
> > though they may be invalid, in order to keep the same as the defintion
> > in xen repo.
> > 
> > Take also the opportunity to simplify simple construction such
> > as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> > will come in follow-up patches.
> > 
> > [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> > 
> > Signed-off-by: Julien Grall <julien.grall@citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Russell King <linux@arm.linux.org.uk>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: David Vrabel <david.vrabel@citrix.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: x86@kernel.org
> > Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Juergen Gross <jgross@suse.com>
> > Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> > Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> > Cc: linux-input@vger.kernel.org
> > Cc: netdev@vger.kernel.org
> > Cc: linux-scsi@vger.kernel.org
> > Cc: linuxppc-dev@lists.ozlabs.org
> > Cc: linux-fbdev@vger.kernel.org
> > Cc: linux-arm-kernel@lists.infradead.org
> 
> Aside from the x86 bits:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Not really important, but just in case anyone waits for my ack on input
bits:

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 16:52       ` Dmitry Torokhov
  0 siblings, 0 replies; 112+ messages in thread
From: Dmitry Torokhov @ 2015-08-05 16:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Aug 05, 2015 at 11:08:55AM +0100, Stefano Stabellini wrote:
> On Tue, 4 Aug 2015, Julien Grall wrote:
> > Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> > is meant, I suspect this is because the first support for Xen was for
> > PV. This resulted in some misimplementation of helpers on ARM and
> > confused developers about the expected behavior.
> > 
> > For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> > Although, if we look at the implementation on x86, it's returning a GFN.
> > 
> > For clarity and avoid new confusion, replace any reference to mfn with
> > gfn in any helpers used by PV drivers. The x86 code will still keep some
> > reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> > to ensure this). No changes as been made in the hypercall field, even
> > though they may be invalid, in order to keep the same as the defintion
> > in xen repo.
> > 
> > Take also the opportunity to simplify simple construction such
> > as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> > will come in follow-up patches.
> > 
> > [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;hç58ed14f390342513405dd766e874934573e6cb
> > 
> > Signed-off-by: Julien Grall <julien.grall@citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Russell King <linux@arm.linux.org.uk>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: David Vrabel <david.vrabel@citrix.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: x86@kernel.org
> > Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Juergen Gross <jgross@suse.com>
> > Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> > Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> > Cc: linux-input@vger.kernel.org
> > Cc: netdev@vger.kernel.org
> > Cc: linux-scsi@vger.kernel.org
> > Cc: linuxppc-dev@lists.ozlabs.org
> > Cc: linux-fbdev@vger.kernel.org
> > Cc: linux-arm-kernel@lists.infradead.org
> 
> Aside from the x86 bits:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Not really important, but just in case anyone waits for my ack on input
bits:

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 16:52       ` Dmitry Torokhov
  0 siblings, 0 replies; 112+ messages in thread
From: Dmitry Torokhov @ 2015-08-05 16:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Aug 05, 2015 at 11:08:55AM +0100, Stefano Stabellini wrote:
> On Tue, 4 Aug 2015, Julien Grall wrote:
> > Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> > is meant, I suspect this is because the first support for Xen was for
> > PV. This resulted in some misimplementation of helpers on ARM and
> > confused developers about the expected behavior.
> > 
> > For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> > Although, if we look at the implementation on x86, it's returning a GFN.
> > 
> > For clarity and avoid new confusion, replace any reference to mfn with
> > gfn in any helpers used by PV drivers. The x86 code will still keep some
> > reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> > to ensure this). No changes as been made in the hypercall field, even
> > though they may be invalid, in order to keep the same as the defintion
> > in xen repo.
> > 
> > Take also the opportunity to simplify simple construction such
> > as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> > will come in follow-up patches.
> > 
> > [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> > 
> > Signed-off-by: Julien Grall <julien.grall@citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Russell King <linux@arm.linux.org.uk>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: David Vrabel <david.vrabel@citrix.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: x86 at kernel.org
> > Cc: "Roger Pau Monn?" <roger.pau@citrix.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Juergen Gross <jgross@suse.com>
> > Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> > Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> > Cc: linux-input at vger.kernel.org
> > Cc: netdev at vger.kernel.org
> > Cc: linux-scsi at vger.kernel.org
> > Cc: linuxppc-dev at lists.ozlabs.org
> > Cc: linux-fbdev at vger.kernel.org
> > Cc: linux-arm-kernel at lists.infradead.org
> 
> Aside from the x86 bits:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Not really important, but just in case anyone waits for my ack on input
bits:

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-05 10:08     ` Stefano Stabellini
                       ` (3 preceding siblings ...)
  (?)
@ 2015-08-05 16:52     ` Dmitry Torokhov
  -1 siblings, 0 replies; 112+ messages in thread
From: Dmitry Torokhov @ 2015-08-05 16:52 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: linux-fbdev, H. Peter Anvin, Thomas Gleixner, Russell King,
	linux-scsi, x86, Tomi Valkeinen, Jiri Slaby, xen-devel,
	Jean-Christophe Plagniol-Villard, linux-input, ian.campbell,
	James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	linux-kernel, Julien Grall, David Vrabel, netdev, linuxppc-dev

On Wed, Aug 05, 2015 at 11:08:55AM +0100, Stefano Stabellini wrote:
> On Tue, 4 Aug 2015, Julien Grall wrote:
> > Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
> > is meant, I suspect this is because the first support for Xen was for
> > PV. This resulted in some misimplementation of helpers on ARM and
> > confused developers about the expected behavior.
> > 
> > For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
> > Although, if we look at the implementation on x86, it's returning a GFN.
> > 
> > For clarity and avoid new confusion, replace any reference to mfn with
> > gfn in any helpers used by PV drivers. The x86 code will still keep some
> > reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
> > to ensure this). No changes as been made in the hypercall field, even
> > though they may be invalid, in order to keep the same as the defintion
> > in xen repo.
> > 
> > Take also the opportunity to simplify simple construction such
> > as pfn_to_mfn(page_to_pfn(page)) into page_to_gfn. More complex clean up
> > will come in follow-up patches.
> > 
> > [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
> > 
> > Signed-off-by: Julien Grall <julien.grall@citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Russell King <linux@arm.linux.org.uk>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: David Vrabel <david.vrabel@citrix.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: x86@kernel.org
> > Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Juergen Gross <jgross@suse.com>
> > Cc: "James E.J. Bottomley" <JBottomley@odin.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
> > Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> > Cc: linux-input@vger.kernel.org
> > Cc: netdev@vger.kernel.org
> > Cc: linux-scsi@vger.kernel.org
> > Cc: linuxppc-dev@lists.ozlabs.org
> > Cc: linux-fbdev@vger.kernel.org
> > Cc: linux-arm-kernel@lists.infradead.org
> 
> Aside from the x86 bits:
> 
> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Not really important, but just in case anyone waits for my ack on input
bits:

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
                       ` (2 preceding siblings ...)
  (?)
@ 2015-08-05 17:01     ` Wei Liu
  -1 siblings, 0 replies; 112+ messages in thread
From: Wei Liu @ 2015-08-05 17:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev, linux-scsi, linuxppc-dev,
	linux-fbdev, linux-arm-kernel

On Tue, Aug 04, 2015 at 07:12:48PM +0100, Julien Grall wrote:
[...]
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 17:01     ` Wei Liu
  0 siblings, 0 replies; 112+ messages in thread
From: Wei Liu @ 2015-08-05 17:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev

On Tue, Aug 04, 2015 at 07:12:48PM +0100, Julien Grall wrote:
[...]
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 17:01     ` Wei Liu
  0 siblings, 0 replies; 112+ messages in thread
From: Wei Liu @ 2015-08-05 17:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, ian.campbell, stefano.stabellini, linux-kernel,
	Russell King, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Roger Pau Monné,
	Dmitry Torokhov, Wei Liu, Juergen Gross, James E.J. Bottomley,
	Greg Kroah-Hartman, Jiri Slaby, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-input, netdev

On Tue, Aug 04, 2015 at 07:12:48PM +0100, Julien Grall wrote:
[...]
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 17:01     ` Wei Liu
  0 siblings, 0 replies; 112+ messages in thread
From: Wei Liu @ 2015-08-05 17:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 04, 2015 at 07:12:48PM +0100, Julien Grall wrote:
[...]
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn > -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn > -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset >  			offset_in_page(skb->data);

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-05 17:01     ` Wei Liu
  0 siblings, 0 replies; 112+ messages in thread
From: Wei Liu @ 2015-08-05 17:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 04, 2015 at 07:12:48PM +0100, Julien Grall wrote:
[...]
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
                     ` (8 preceding siblings ...)
  (?)
@ 2015-08-05 17:01   ` Wei Liu
  -1 siblings, 0 replies; 112+ messages in thread
From: Wei Liu @ 2015-08-05 17:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: linux-fbdev, H. Peter Anvin, Thomas Gleixner, stefano.stabellini,
	Russell King, linux-scsi, x86, Tomi Valkeinen, Jiri Slaby,
	xen-devel, Jean-Christophe Plagniol-Villard, linux-input,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev, Rog

On Tue, Aug 04, 2015 at 07:12:48PM +0100, Julien Grall wrote:
[...]
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..3b7b7c3 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -314,7 +314,7 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb
>  		} else {
>  			copy_gop->source.domid = DOMID_SELF;
>  			copy_gop->source.u.gmfn =
> -				virt_to_mfn(page_address(page));
> +				virt_to_gfn(page_address(page));
>  		}
>  		copy_gop->source.offset = offset;
>  
> @@ -1284,7 +1284,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  		queue->tx_copy_ops[*copy_ops].source.offset = txreq.offset;
>  
>  		queue->tx_copy_ops[*copy_ops].dest.u.gmfn =
> -			virt_to_mfn(skb->data);
> +			virt_to_gfn(skb->data);
>  		queue->tx_copy_ops[*copy_ops].dest.domid = DOMID_SELF;
>  		queue->tx_copy_ops[*copy_ops].dest.offset =
>  			offset_in_page(skb->data);

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
                       ` (2 preceding siblings ...)
  (?)
@ 2015-08-06 11:00     ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:00 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Thomas Gleixner,
	stefano.stabellini, Russell King, linux-scsi, x86,
	Tomi Valkeinen, linux-input, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev, Roger Pau Monné

Hi,


On 04/08/15 19:12, Julien Grall wrote:
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }

I've just noticed that there is a function gfn_to_page used for KVM.

Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
with KVM one?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:00     ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:00 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Thomas Gleixner,
	stefano.stabellini, Russell King, linux-scsi, x86,
	Tomi Valkeinen, linux-input, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev

Hi,


On 04/08/15 19:12, Julien Grall wrote:
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }

I've just noticed that there is a function gfn_to_page used for KVM.

Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
with KVM one?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:00     ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:00 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Thomas Gleixner,
	stefano.stabellini, Russell King, linux-scsi, x86,
	Tomi Valkeinen, linux-input, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev

Hi,


On 04/08/15 19:12, Julien Grall wrote:
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }

I've just noticed that there is a function gfn_to_page used for KVM.

Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
with KVM one?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:00     ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:00 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,


On 04/08/15 19:12, Julien Grall wrote:
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }

I've just noticed that there is a function gfn_to_page used for KVM.

Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
with KVM one?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:00     ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:00 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,


On 04/08/15 19:12, Julien Grall wrote:
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }

I've just noticed that there is a function gfn_to_page used for KVM.

Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
with KVM one?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-04 18:12   ` Julien Grall
                     ` (10 preceding siblings ...)
  (?)
@ 2015-08-06 11:00   ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:00 UTC (permalink / raw)
  To: xen-devel
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Boris Ostrovsky,
	Russell King, linux-scsi, Tomi Valkeinen, x86, Ingo Molnar,
	linux-input, Jean-Christophe Plagniol-Villard, ian.campbell,
	stefano.stabellini, James E.J. Bottomley, Thomas Gleixner,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev

Hi,


On 04/08/15 19:12, Julien Grall wrote:
> diff --git a/include/xen/page.h b/include/xen/page.h
> index c5ed20b..e7e1425 100644
> --- a/include/xen/page.h
> +++ b/include/xen/page.h
> @@ -3,9 +3,9 @@
>  
>  #include <asm/xen/page.h>
>  
> -static inline unsigned long page_to_mfn(struct page *page)
> +static inline unsigned long page_to_gfn(struct page *page)
>  {
> -	return pfn_to_mfn(page_to_pfn(page));
> +	return pfn_to_gfn(page_to_pfn(page));
>  }

I've just noticed that there is a function gfn_to_page used for KVM.

Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
with KVM one?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-06 11:00     ` Julien Grall
                         ` (2 preceding siblings ...)
  (?)
@ 2015-08-06 11:06       ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 11:06 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, linux-fbdev, H. Peter Anvin, Jiri Slaby,
	Thomas Gleixner, stefano.stabellini, Russell King, linux-scsi,
	x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev, Roger Pau Monné

On Thu, 6 Aug 2015, Julien Grall wrote:
> Hi,
> 
> 
> On 04/08/15 19:12, Julien Grall wrote:
> > diff --git a/include/xen/page.h b/include/xen/page.h
> > index c5ed20b..e7e1425 100644
> > --- a/include/xen/page.h
> > +++ b/include/xen/page.h
> > @@ -3,9 +3,9 @@
> >  
> >  #include <asm/xen/page.h>
> >  
> > -static inline unsigned long page_to_mfn(struct page *page)
> > +static inline unsigned long page_to_gfn(struct page *page)
> >  {
> > -	return pfn_to_mfn(page_to_pfn(page));
> > +	return pfn_to_gfn(page_to_pfn(page));
> >  }
> 
> I've just noticed that there is a function gfn_to_page used for KVM.
> 
> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> with KVM one?

Yeah, prepending xen would help to avoid namespace pollution.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:06       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 11:06 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, linux-fbdev, H. Peter Anvin, Jiri Slaby,
	Thomas Gleixner, stefano.stabellini, Russell King, linux-scsi,
	x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev, linuxpp

On Thu, 6 Aug 2015, Julien Grall wrote:
> Hi,
> 
> 
> On 04/08/15 19:12, Julien Grall wrote:
> > diff --git a/include/xen/page.h b/include/xen/page.h
> > index c5ed20b..e7e1425 100644
> > --- a/include/xen/page.h
> > +++ b/include/xen/page.h
> > @@ -3,9 +3,9 @@
> >  
> >  #include <asm/xen/page.h>
> >  
> > -static inline unsigned long page_to_mfn(struct page *page)
> > +static inline unsigned long page_to_gfn(struct page *page)
> >  {
> > -	return pfn_to_mfn(page_to_pfn(page));
> > +	return pfn_to_gfn(page_to_pfn(page));
> >  }
> 
> I've just noticed that there is a function gfn_to_page used for KVM.
> 
> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> with KVM one?

Yeah, prepending xen would help to avoid namespace pollution.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:06       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 11:06 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, linux-fbdev, H. Peter Anvin, Jiri Slaby,
	Thomas Gleixner, stefano.stabellini, Russell King, linux-scsi,
	x86, Tomi Valkeinen, linux-input,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Boris Ostrovsky, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev, linuxpp

On Thu, 6 Aug 2015, Julien Grall wrote:
> Hi,
> 
> 
> On 04/08/15 19:12, Julien Grall wrote:
> > diff --git a/include/xen/page.h b/include/xen/page.h
> > index c5ed20b..e7e1425 100644
> > --- a/include/xen/page.h
> > +++ b/include/xen/page.h
> > @@ -3,9 +3,9 @@
> >  
> >  #include <asm/xen/page.h>
> >  
> > -static inline unsigned long page_to_mfn(struct page *page)
> > +static inline unsigned long page_to_gfn(struct page *page)
> >  {
> > -	return pfn_to_mfn(page_to_pfn(page));
> > +	return pfn_to_gfn(page_to_pfn(page));
> >  }
> 
> I've just noticed that there is a function gfn_to_page used for KVM.
> 
> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> with KVM one?

Yeah, prepending xen would help to avoid namespace pollution.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:06       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 11:06 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 6 Aug 2015, Julien Grall wrote:
> Hi,
> 
> 
> On 04/08/15 19:12, Julien Grall wrote:
> > diff --git a/include/xen/page.h b/include/xen/page.h
> > index c5ed20b..e7e1425 100644
> > --- a/include/xen/page.h
> > +++ b/include/xen/page.h
> > @@ -3,9 +3,9 @@
> >  
> >  #include <asm/xen/page.h>
> >  
> > -static inline unsigned long page_to_mfn(struct page *page)
> > +static inline unsigned long page_to_gfn(struct page *page)
> >  {
> > -	return pfn_to_mfn(page_to_pfn(page));
> > +	return pfn_to_gfn(page_to_pfn(page));
> >  }
> 
> I've just noticed that there is a function gfn_to_page used for KVM.
> 
> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> with KVM one?

Yeah, prepending xen would help to avoid namespace pollution.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:06       ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 11:06 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 6 Aug 2015, Julien Grall wrote:
> Hi,
> 
> 
> On 04/08/15 19:12, Julien Grall wrote:
> > diff --git a/include/xen/page.h b/include/xen/page.h
> > index c5ed20b..e7e1425 100644
> > --- a/include/xen/page.h
> > +++ b/include/xen/page.h
> > @@ -3,9 +3,9 @@
> >  
> >  #include <asm/xen/page.h>
> >  
> > -static inline unsigned long page_to_mfn(struct page *page)
> > +static inline unsigned long page_to_gfn(struct page *page)
> >  {
> > -	return pfn_to_mfn(page_to_pfn(page));
> > +	return pfn_to_gfn(page_to_pfn(page));
> >  }
> 
> I've just noticed that there is a function gfn_to_page used for KVM.
> 
> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> with KVM one?

Yeah, prepending xen would help to avoid namespace pollution.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-06 11:00     ` Julien Grall
                       ` (3 preceding siblings ...)
  (?)
@ 2015-08-06 11:06     ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 11:06 UTC (permalink / raw)
  To: Julien Grall
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Boris Ostrovsky,
	Russell King, linux-scsi, Tomi Valkeinen, x86, Ingo Molnar,
	linux-input, xen-devel, Jean-Christophe Plagniol-Villard,
	ian.campbell, stefano.stabellini, James E.J. Bottomley,
	Thomas Gleixner, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev

On Thu, 6 Aug 2015, Julien Grall wrote:
> Hi,
> 
> 
> On 04/08/15 19:12, Julien Grall wrote:
> > diff --git a/include/xen/page.h b/include/xen/page.h
> > index c5ed20b..e7e1425 100644
> > --- a/include/xen/page.h
> > +++ b/include/xen/page.h
> > @@ -3,9 +3,9 @@
> >  
> >  #include <asm/xen/page.h>
> >  
> > -static inline unsigned long page_to_mfn(struct page *page)
> > +static inline unsigned long page_to_gfn(struct page *page)
> >  {
> > -	return pfn_to_mfn(page_to_pfn(page));
> > +	return pfn_to_gfn(page_to_pfn(page));
> >  }
> 
> I've just noticed that there is a function gfn_to_page used for KVM.
> 
> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> with KVM one?

Yeah, prepending xen would help to avoid namespace pollution.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-06 11:06       ` Stefano Stabellini
  (?)
  (?)
@ 2015-08-06 11:17         ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:17 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Boris Ostrovsky,
	Russell King, linux-scsi, Tomi Valkeinen, x86, Ingo Molnar,
	linux-input, xen-devel, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Thomas Gleixner,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev, Roger Pau Monné

On 06/08/15 12:06, Stefano Stabellini wrote:
> On Thu, 6 Aug 2015, Julien Grall wrote:
>> Hi,
>>
>>
>> On 04/08/15 19:12, Julien Grall wrote:
>>> diff --git a/include/xen/page.h b/include/xen/page.h
>>> index c5ed20b..e7e1425 100644
>>> --- a/include/xen/page.h
>>> +++ b/include/xen/page.h
>>> @@ -3,9 +3,9 @@
>>>  
>>>  #include <asm/xen/page.h>
>>>  
>>> -static inline unsigned long page_to_mfn(struct page *page)
>>> +static inline unsigned long page_to_gfn(struct page *page)
>>>  {
>>> -	return pfn_to_mfn(page_to_pfn(page));
>>> +	return pfn_to_gfn(page_to_pfn(page));
>>>  }
>>
>> I've just noticed that there is a function gfn_to_page used for KVM.
>>
>> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
>> with KVM one?
> 
> Yeah, prepending xen would help to avoid namespace pollution.

Will do. May I keep your Reviewed-by for this mechanical change?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:17         ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:17 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Boris Ostrovsky,
	Russell King, linux-scsi, Tomi Valkeinen, x86, Ingo Molnar,
	linux-input, xen-devel, Jean-Christophe Plagniol-Villard,
	ian.campbell, James E.J. Bottomley, Thomas Gleixner,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev

On 06/08/15 12:06, Stefano Stabellini wrote:
> On Thu, 6 Aug 2015, Julien Grall wrote:
>> Hi,
>>
>>
>> On 04/08/15 19:12, Julien Grall wrote:
>>> diff --git a/include/xen/page.h b/include/xen/page.h
>>> index c5ed20b..e7e1425 100644
>>> --- a/include/xen/page.h
>>> +++ b/include/xen/page.h
>>> @@ -3,9 +3,9 @@
>>>  
>>>  #include <asm/xen/page.h>
>>>  
>>> -static inline unsigned long page_to_mfn(struct page *page)
>>> +static inline unsigned long page_to_gfn(struct page *page)
>>>  {
>>> -	return pfn_to_mfn(page_to_pfn(page));
>>> +	return pfn_to_gfn(page_to_pfn(page));
>>>  }
>>
>> I've just noticed that there is a function gfn_to_page used for KVM.
>>
>> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
>> with KVM one?
> 
> Yeah, prepending xen would help to avoid namespace pollution.

Will do. May I keep your Reviewed-by for this mechanical change?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:17         ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/08/15 12:06, Stefano Stabellini wrote:
> On Thu, 6 Aug 2015, Julien Grall wrote:
>> Hi,
>>
>>
>> On 04/08/15 19:12, Julien Grall wrote:
>>> diff --git a/include/xen/page.h b/include/xen/page.h
>>> index c5ed20b..e7e1425 100644
>>> --- a/include/xen/page.h
>>> +++ b/include/xen/page.h
>>> @@ -3,9 +3,9 @@
>>>  
>>>  #include <asm/xen/page.h>
>>>  
>>> -static inline unsigned long page_to_mfn(struct page *page)
>>> +static inline unsigned long page_to_gfn(struct page *page)
>>>  {
>>> -	return pfn_to_mfn(page_to_pfn(page));
>>> +	return pfn_to_gfn(page_to_pfn(page));
>>>  }
>>
>> I've just noticed that there is a function gfn_to_page used for KVM.
>>
>> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
>> with KVM one?
> 
> Yeah, prepending xen would help to avoid namespace pollution.

Will do. May I keep your Reviewed-by for this mechanical change?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 11:17         ` Julien Grall
  0 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/08/15 12:06, Stefano Stabellini wrote:
> On Thu, 6 Aug 2015, Julien Grall wrote:
>> Hi,
>>
>>
>> On 04/08/15 19:12, Julien Grall wrote:
>>> diff --git a/include/xen/page.h b/include/xen/page.h
>>> index c5ed20b..e7e1425 100644
>>> --- a/include/xen/page.h
>>> +++ b/include/xen/page.h
>>> @@ -3,9 +3,9 @@
>>>  
>>>  #include <asm/xen/page.h>
>>>  
>>> -static inline unsigned long page_to_mfn(struct page *page)
>>> +static inline unsigned long page_to_gfn(struct page *page)
>>>  {
>>> -	return pfn_to_mfn(page_to_pfn(page));
>>> +	return pfn_to_gfn(page_to_pfn(page));
>>>  }
>>
>> I've just noticed that there is a function gfn_to_page used for KVM.
>>
>> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
>> with KVM one?
> 
> Yeah, prepending xen would help to avoid namespace pollution.

Will do. May I keep your Reviewed-by for this mechanical change?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-06 11:06       ` Stefano Stabellini
                         ` (3 preceding siblings ...)
  (?)
@ 2015-08-06 11:17       ` Julien Grall
  -1 siblings, 0 replies; 112+ messages in thread
From: Julien Grall @ 2015-08-06 11:17 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Boris Ostrovsky,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	xen-devel, Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Thomas Gleixner, Ingo Molnar,
	linux-arm-kernel, Juergen Gross, Wei Liu, Greg Kroah-Hartman,
	Dmitry Torokhov, linux-kernel, David Vrabel, netdev,
	linuxppc-dev

On 06/08/15 12:06, Stefano Stabellini wrote:
> On Thu, 6 Aug 2015, Julien Grall wrote:
>> Hi,
>>
>>
>> On 04/08/15 19:12, Julien Grall wrote:
>>> diff --git a/include/xen/page.h b/include/xen/page.h
>>> index c5ed20b..e7e1425 100644
>>> --- a/include/xen/page.h
>>> +++ b/include/xen/page.h
>>> @@ -3,9 +3,9 @@
>>>  
>>>  #include <asm/xen/page.h>
>>>  
>>> -static inline unsigned long page_to_mfn(struct page *page)
>>> +static inline unsigned long page_to_gfn(struct page *page)
>>>  {
>>> -	return pfn_to_mfn(page_to_pfn(page));
>>> +	return pfn_to_gfn(page_to_pfn(page));
>>>  }
>>
>> I've just noticed that there is a function gfn_to_page used for KVM.
>>
>> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
>> with KVM one?
> 
> Yeah, prepending xen would help to avoid namespace pollution.

Will do. May I keep your Reviewed-by for this mechanical change?

Regards,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-06 11:17         ` Julien Grall
                             ` (2 preceding siblings ...)
  (?)
@ 2015-08-06 14:20           ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 14:20 UTC (permalink / raw)
  To: Julien Grall
  Cc: Stefano Stabellini, linux-fbdev, H. Peter Anvin, Jiri Slaby,
	Boris Ostrovsky, Russell King, linux-scsi, Tomi Valkeinen, x86,
	Ingo Molnar, linux-input, xen-devel,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Thomas Gleixner, linux-arm-kernel,
	Juergen Gross, Wei Liu, Greg Kroah-Hartman, Dmitry Torokhov,
	linux-kernel, David Vrabel, netdev, linuxppc-dev,
	Roger Pau Monné

On Thu, 6 Aug 2015, Julien Grall wrote:
> On 06/08/15 12:06, Stefano Stabellini wrote:
> > On Thu, 6 Aug 2015, Julien Grall wrote:
> >> Hi,
> >>
> >>
> >> On 04/08/15 19:12, Julien Grall wrote:
> >>> diff --git a/include/xen/page.h b/include/xen/page.h
> >>> index c5ed20b..e7e1425 100644
> >>> --- a/include/xen/page.h
> >>> +++ b/include/xen/page.h
> >>> @@ -3,9 +3,9 @@
> >>>  
> >>>  #include <asm/xen/page.h>
> >>>  
> >>> -static inline unsigned long page_to_mfn(struct page *page)
> >>> +static inline unsigned long page_to_gfn(struct page *page)
> >>>  {
> >>> -	return pfn_to_mfn(page_to_pfn(page));
> >>> +	return pfn_to_gfn(page_to_pfn(page));
> >>>  }
> >>
> >> I've just noticed that there is a function gfn_to_page used for KVM.
> >>
> >> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> >> with KVM one?
> > 
> > Yeah, prepending xen would help to avoid namespace pollution.
> 
> Will do. May I keep your Reviewed-by for this mechanical change?

Yes


^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 14:20           ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 14:20 UTC (permalink / raw)
  To: Julien Grall
  Cc: Stefano Stabellini, linux-fbdev, H. Peter Anvin, Jiri Slaby,
	Boris Ostrovsky, Russell King, linux-scsi, Tomi Valkeinen, x86,
	Ingo Molnar, linux-input, xen-devel,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Thomas Gleixner, linux-arm-kernel,
	Juergen Gross, Wei Liu, Greg Kroah-Hartman, Dmitry Torokhov,
	linux-kernel, David Vrabel, netdev

On Thu, 6 Aug 2015, Julien Grall wrote:
> On 06/08/15 12:06, Stefano Stabellini wrote:
> > On Thu, 6 Aug 2015, Julien Grall wrote:
> >> Hi,
> >>
> >>
> >> On 04/08/15 19:12, Julien Grall wrote:
> >>> diff --git a/include/xen/page.h b/include/xen/page.h
> >>> index c5ed20b..e7e1425 100644
> >>> --- a/include/xen/page.h
> >>> +++ b/include/xen/page.h
> >>> @@ -3,9 +3,9 @@
> >>>  
> >>>  #include <asm/xen/page.h>
> >>>  
> >>> -static inline unsigned long page_to_mfn(struct page *page)
> >>> +static inline unsigned long page_to_gfn(struct page *page)
> >>>  {
> >>> -	return pfn_to_mfn(page_to_pfn(page));
> >>> +	return pfn_to_gfn(page_to_pfn(page));
> >>>  }
> >>
> >> I've just noticed that there is a function gfn_to_page used for KVM.
> >>
> >> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> >> with KVM one?
> > 
> > Yeah, prepending xen would help to avoid namespace pollution.
> 
> Will do. May I keep your Reviewed-by for this mechanical change?

Yes

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 14:20           ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 14:20 UTC (permalink / raw)
  To: Julien Grall
  Cc: Stefano Stabellini, linux-fbdev, H. Peter Anvin, Jiri Slaby,
	Boris Ostrovsky, Russell King, linux-scsi, Tomi Valkeinen, x86,
	Ingo Molnar, linux-input, xen-devel,
	Jean-Christophe Plagniol-Villard, ian.campbell,
	James E.J. Bottomley, Thomas Gleixner, linux-arm-kernel,
	Juergen Gross, Wei Liu, Greg Kroah-Hartman, Dmitry Torokhov,
	linux-kernel, David Vrabel, netdev

On Thu, 6 Aug 2015, Julien Grall wrote:
> On 06/08/15 12:06, Stefano Stabellini wrote:
> > On Thu, 6 Aug 2015, Julien Grall wrote:
> >> Hi,
> >>
> >>
> >> On 04/08/15 19:12, Julien Grall wrote:
> >>> diff --git a/include/xen/page.h b/include/xen/page.h
> >>> index c5ed20b..e7e1425 100644
> >>> --- a/include/xen/page.h
> >>> +++ b/include/xen/page.h
> >>> @@ -3,9 +3,9 @@
> >>>  
> >>>  #include <asm/xen/page.h>
> >>>  
> >>> -static inline unsigned long page_to_mfn(struct page *page)
> >>> +static inline unsigned long page_to_gfn(struct page *page)
> >>>  {
> >>> -	return pfn_to_mfn(page_to_pfn(page));
> >>> +	return pfn_to_gfn(page_to_pfn(page));
> >>>  }
> >>
> >> I've just noticed that there is a function gfn_to_page used for KVM.
> >>
> >> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> >> with KVM one?
> > 
> > Yeah, prepending xen would help to avoid namespace pollution.
> 
> Will do. May I keep your Reviewed-by for this mechanical change?

Yes

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 14:20           ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 14:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 6 Aug 2015, Julien Grall wrote:
> On 06/08/15 12:06, Stefano Stabellini wrote:
> > On Thu, 6 Aug 2015, Julien Grall wrote:
> >> Hi,
> >>
> >>
> >> On 04/08/15 19:12, Julien Grall wrote:
> >>> diff --git a/include/xen/page.h b/include/xen/page.h
> >>> index c5ed20b..e7e1425 100644
> >>> --- a/include/xen/page.h
> >>> +++ b/include/xen/page.h
> >>> @@ -3,9 +3,9 @@
> >>>  
> >>>  #include <asm/xen/page.h>
> >>>  
> >>> -static inline unsigned long page_to_mfn(struct page *page)
> >>> +static inline unsigned long page_to_gfn(struct page *page)
> >>>  {
> >>> -	return pfn_to_mfn(page_to_pfn(page));
> >>> +	return pfn_to_gfn(page_to_pfn(page));
> >>>  }
> >>
> >> I've just noticed that there is a function gfn_to_page used for KVM.
> >>
> >> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> >> with KVM one?
> > 
> > Yeah, prepending xen would help to avoid namespace pollution.
> 
> Will do. May I keep your Reviewed-by for this mechanical change?

Yes


^ permalink raw reply	[flat|nested] 112+ messages in thread

* [Xen-devel] [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
@ 2015-08-06 14:20           ` Stefano Stabellini
  0 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 14:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 6 Aug 2015, Julien Grall wrote:
> On 06/08/15 12:06, Stefano Stabellini wrote:
> > On Thu, 6 Aug 2015, Julien Grall wrote:
> >> Hi,
> >>
> >>
> >> On 04/08/15 19:12, Julien Grall wrote:
> >>> diff --git a/include/xen/page.h b/include/xen/page.h
> >>> index c5ed20b..e7e1425 100644
> >>> --- a/include/xen/page.h
> >>> +++ b/include/xen/page.h
> >>> @@ -3,9 +3,9 @@
> >>>  
> >>>  #include <asm/xen/page.h>
> >>>  
> >>> -static inline unsigned long page_to_mfn(struct page *page)
> >>> +static inline unsigned long page_to_gfn(struct page *page)
> >>>  {
> >>> -	return pfn_to_mfn(page_to_pfn(page));
> >>> +	return pfn_to_gfn(page_to_pfn(page));
> >>>  }
> >>
> >> I've just noticed that there is a function gfn_to_page used for KVM.
> >>
> >> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> >> with KVM one?
> > 
> > Yeah, prepending xen would help to avoid namespace pollution.
> 
> Will do. May I keep your Reviewed-by for this mechanical change?

Yes

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies
  2015-08-06 11:17         ` Julien Grall
                           ` (3 preceding siblings ...)
  (?)
@ 2015-08-06 14:20         ` Stefano Stabellini
  -1 siblings, 0 replies; 112+ messages in thread
From: Stefano Stabellini @ 2015-08-06 14:20 UTC (permalink / raw)
  To: Julien Grall
  Cc: linux-fbdev, H. Peter Anvin, Jiri Slaby, Boris Ostrovsky,
	Russell King, linux-scsi, x86, Tomi Valkeinen, linux-input,
	xen-devel, Jean-Christophe Plagniol-Villard, ian.campbell,
	Stefano Stabellini, James E.J. Bottomley, Thomas Gleixner,
	Ingo Molnar, linux-arm-kernel, Juergen Gross, Wei Liu,
	Greg Kroah-Hartman, Dmitry Torokhov, linux-kernel, David Vrabel,
	netdev, linuxppc-dev

On Thu, 6 Aug 2015, Julien Grall wrote:
> On 06/08/15 12:06, Stefano Stabellini wrote:
> > On Thu, 6 Aug 2015, Julien Grall wrote:
> >> Hi,
> >>
> >>
> >> On 04/08/15 19:12, Julien Grall wrote:
> >>> diff --git a/include/xen/page.h b/include/xen/page.h
> >>> index c5ed20b..e7e1425 100644
> >>> --- a/include/xen/page.h
> >>> +++ b/include/xen/page.h
> >>> @@ -3,9 +3,9 @@
> >>>  
> >>>  #include <asm/xen/page.h>
> >>>  
> >>> -static inline unsigned long page_to_mfn(struct page *page)
> >>> +static inline unsigned long page_to_gfn(struct page *page)
> >>>  {
> >>> -	return pfn_to_mfn(page_to_pfn(page));
> >>> +	return pfn_to_gfn(page_to_pfn(page));
> >>>  }
> >>
> >> I've just noticed that there is a function gfn_to_page used for KVM.
> >>
> >> Maybe I should rename page_to_gfn to xen_page_to_gfn to avoid confusion
> >> with KVM one?
> > 
> > Yeah, prepending xen would help to avoid namespace pollution.
> 
> Will do. May I keep your Reviewed-by for this mechanical change?

Yes

^ permalink raw reply	[flat|nested] 112+ messages in thread

end of thread, other threads:[~2015-08-06 14:22 UTC | newest]

Thread overview: 112+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-04 18:12 [PATCH v2 0/8] Use correctly the Xen memory terminologies in Linux Julien Grall
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 1/8] arm/xen: Remove helpers which are PV specific Julien Grall
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 2/8] xen: Make clear that swiotlb and biomerge are dealing with DMA address Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-05  9:49   ` Stefano Stabellini
2015-08-05  9:49     ` Stefano Stabellini
2015-08-05 10:31     ` Julien Grall
2015-08-05 10:31       ` Julien Grall
2015-08-05 10:31     ` Julien Grall
2015-08-05  9:49   ` Stefano Stabellini
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 3/8] arm/xen: implement correctly pfn_to_mfn Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-05  9:52   ` Stefano Stabellini
2015-08-05  9:52   ` Stefano Stabellini
2015-08-05  9:52     ` Stefano Stabellini
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 4/8] xen: Use the correctly the Xen memory terminologies Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 23:16   ` Boris Ostrovsky
2015-08-04 23:16     ` Boris Ostrovsky
2015-08-04 23:16     ` Boris Ostrovsky
2015-08-04 23:16     ` Boris Ostrovsky
2015-08-05 10:07     ` Stefano Stabellini
2015-08-05 10:07     ` Stefano Stabellini
2015-08-05 10:07       ` Stefano Stabellini
2015-08-05 10:07       ` Stefano Stabellini
2015-08-05 10:07       ` Stefano Stabellini
2015-08-05 10:51     ` Julien Grall
2015-08-05 10:51     ` Julien Grall
2015-08-05 10:51       ` Julien Grall
2015-08-05 10:51       ` Julien Grall
2015-08-05 10:51       ` Julien Grall
2015-08-05 10:51       ` Julien Grall
2015-08-05 12:19       ` Boris Ostrovsky
2015-08-05 12:19       ` Boris Ostrovsky
2015-08-05 12:19         ` Boris Ostrovsky
2015-08-05 12:19         ` Boris Ostrovsky
2015-08-05 12:19         ` Boris Ostrovsky
2015-08-05 12:33         ` Julien Grall
2015-08-05 12:33         ` [Xen-devel] " Julien Grall
2015-08-05 12:33           ` Julien Grall
2015-08-05 12:33           ` Julien Grall
2015-08-05 12:33           ` Julien Grall
2015-08-05 12:33           ` Julien Grall
2015-08-05 12:44           ` Boris Ostrovsky
2015-08-05 12:44           ` [Xen-devel] " Boris Ostrovsky
2015-08-05 12:44             ` Boris Ostrovsky
2015-08-05 12:44             ` Boris Ostrovsky
2015-08-05 12:44             ` Boris Ostrovsky
2015-08-04 23:16   ` Boris Ostrovsky
2015-08-05 10:08   ` Stefano Stabellini
2015-08-05 10:08     ` Stefano Stabellini
2015-08-05 10:08     ` Stefano Stabellini
2015-08-05 10:08     ` Stefano Stabellini
2015-08-05 16:52     ` Dmitry Torokhov
2015-08-05 16:52       ` Dmitry Torokhov
2015-08-05 16:52       ` Dmitry Torokhov
2015-08-05 16:52       ` Dmitry Torokhov
2015-08-05 16:52     ` Dmitry Torokhov
2015-08-05 10:08   ` Stefano Stabellini
2015-08-05 17:01   ` Wei Liu
2015-08-05 17:01     ` Wei Liu
2015-08-05 17:01     ` Wei Liu
2015-08-05 17:01     ` Wei Liu
2015-08-05 17:01     ` Wei Liu
2015-08-05 17:01   ` Wei Liu
2015-08-06 11:00   ` [Xen-devel] " Julien Grall
2015-08-06 11:00     ` Julien Grall
2015-08-06 11:00     ` Julien Grall
2015-08-06 11:00     ` Julien Grall
2015-08-06 11:00     ` Julien Grall
2015-08-06 11:06     ` Stefano Stabellini
2015-08-06 11:06     ` [Xen-devel] " Stefano Stabellini
2015-08-06 11:06       ` Stefano Stabellini
2015-08-06 11:06       ` Stefano Stabellini
2015-08-06 11:06       ` Stefano Stabellini
2015-08-06 11:06       ` Stefano Stabellini
2015-08-06 11:17       ` Julien Grall
2015-08-06 11:17       ` [Xen-devel] " Julien Grall
2015-08-06 11:17         ` Julien Grall
2015-08-06 11:17         ` Julien Grall
2015-08-06 11:17         ` Julien Grall
2015-08-06 14:20         ` Stefano Stabellini
2015-08-06 14:20           ` Stefano Stabellini
2015-08-06 14:20           ` Stefano Stabellini
2015-08-06 14:20           ` Stefano Stabellini
2015-08-06 14:20           ` Stefano Stabellini
2015-08-06 14:20         ` Stefano Stabellini
2015-08-06 11:00   ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 5/8] xen/tmem: Use page_to_gfn rather than pfn_to_gfn Julien Grall
2015-08-05 10:01   ` Stefano Stabellini
2015-08-05 10:01   ` Stefano Stabellini
2015-08-04 18:12 ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 6/8] video/xen-fbfront: Further s/MFN/GFN clean-up Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 7/8] hvc/xen: " Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12 ` [PATCH v2 8/8] xen/privcmd: Further s/MFN/GFN/ clean-up Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12   ` Julien Grall
2015-08-04 18:12 ` Julien Grall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.