All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Julien Grall <julien.grall@linaro.org>, xen-devel@lists.xen.org
Cc: Jun Nakajima <jun.nakajima@intel.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Razvan Cojocaru <rcojocaru@bitdefender.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Tim Deegan <tim@xen.org>, Ian Jackson <ian.jackson@eu.citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Tamas K Lengyel <tamas@tklengyel.com>,
	Jan Beulich <jbeulich@suse.com>,
	Shane Wang <shane.wang@intel.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Gang Wei <gang.wei@intel.com>,
	Paul Durrant <paul.durrant@citrix.com>
Subject: Re: [PATCH 7/7] xen: Convert __page_to_mfn and __mfn_to_page to use typesafe MFN
Date: Thu, 5 Oct 2017 00:27:37 +0100	[thread overview]
Message-ID: <52aab653-7e67-7a6f-5b73-175353f29ab1@citrix.com> (raw)
In-Reply-To: <20171004181526.9405-8-julien.grall@linaro.org>

On 04/10/2017 19:15, Julien Grall wrote:
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 093ebf1a8e..0753d03aac 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -104,11 +104,11 @@ static bool insert_11_bank(struct domain *d,
>                             unsigned int order)
>  {
>      int res, i;
> -    paddr_t spfn;
> +    mfn_t smfn;
>      paddr_t start, size;
>  
> -    spfn = page_to_mfn(pg);
> -    start = pfn_to_paddr(spfn);
> +    smfn = page_to_mfn(pg);
> +    start = mfn_to_maddr(smfn);
>      size = pfn_to_paddr(1UL << order);

Wouldn't it be cleaner to move this renaming into patch 1, along with an
extra set of undef/override, to be taken out here?  (perhaps not given
the rework effort?)

>  
>      D11PRINT("Allocated %#"PRIpaddr"-%#"PRIpaddr" (%ldMB/%ldMB, order %d)\n",
> @@ -678,8 +678,8 @@ static void pvpmu_finish(struct domain *d, xen_pmu_params_t *params)
>  
>      if ( xenpmu_data )
>      {
> -        mfn = domain_page_map_to_mfn(xenpmu_data);
> -        ASSERT(mfn_valid(_mfn(mfn)));
> +        mfn = _mfn(domain_page_map_to_mfn(xenpmu_data));

Seeing as you convert every(?) call to domain_page_map_to_mfn(), it
would be cleaner to change the return type while making the change.

I'd be happy for such a change being folded into this patch, because
doing so would be by far the least disruptive way of making the change.

> +        ASSERT(mfn_valid(mfn));
>          unmap_domain_page_global(xenpmu_data);
>          put_page_and_type(mfn_to_page(mfn));
>      }
> @@ -1185,8 +1180,8 @@ int __mem_sharing_unshare_page(struct domain *d,
>          return -ENOMEM;
>      }
>  
> -    s = map_domain_page(_mfn(__page_to_mfn(old_page)));
> -    t = map_domain_page(_mfn(__page_to_mfn(page)));
> +    s = map_domain_page(page_to_mfn(old_page));
> +    t = map_domain_page(page_to_mfn(page));
>      memcpy(t, s, PAGE_SIZE);
>      unmap_domain_page(s);
>      unmap_domain_page(t);

This whole lot could turn into copy_domain_page()

> diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c
> index 81973af124..371221a302 100644
> --- a/xen/arch/x86/pv/descriptor-tables.c
> +++ b/xen/arch/x86/pv/descriptor-tables.c
> @@ -25,12 +25,6 @@
>  #include <asm/p2m.h>
>  #include <asm/pv/mm.h>
>  
> -/* Override macros from asm/page.h to make them work with mfn_t */
> -#undef mfn_to_page
> -#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
> -#undef page_to_mfn
> -#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
> -
>  /*******************
>   * Descriptor Tables
>   */

If you're making this change, please take out the Descriptor Tables
comment like you do with I/O below, because the entire file is dedicated
to descriptor table support and it will save me one item on a cleanup
patch :).

> diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
> index dd90713acf..9ccbd021ef 100644
> --- a/xen/arch/x86/pv/emul-priv-op.c
> +++ b/xen/arch/x86/pv/emul-priv-op.c
> @@ -43,16 +43,6 @@
>  #include "emulate.h"
>  #include "mm.h"
>  
> -/* Override macros from asm/page.h to make them work with mfn_t */
> -#undef mfn_to_page
> -#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
> -#undef page_to_mfn
> -#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
> -
> -/***********************
> - * I/O emulation support
> - */
> -
>  struct priv_op_ctxt {
>      struct x86_emulate_ctxt ctxt;
>      struct {
> @@ -873,22 +873,22 @@ int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn,
>      for ( entry = page; ;  )
>      {
>          unsigned long ind;
> -        unsigned long mfn;
> +        mfn_t mfn;
>  
>          ind = kimage_entry_ind(entry, compat);
> -        mfn = kimage_entry_mfn(entry, compat);
> +        mfn = _mfn(kimage_entry_mfn(entry, compat));

Again, modify the return type of kimage_entry_mfn() ?

> diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h
> index 45ca742678..8737ef16ff 100644
> --- a/xen/include/asm-x86/page.h
> +++ b/xen/include/asm-x86/page.h
> @@ -273,8 +273,8 @@ void copy_page_sse2(void *, const void *);
>  #define pfn_to_paddr(pfn)   __pfn_to_paddr(pfn)
>  #define paddr_to_pfn(pa)    __paddr_to_pfn(pa)
>  #define paddr_to_pdx(pa)    pfn_to_pdx(paddr_to_pfn(pa))
> -#define vmap_to_mfn(va)     l1e_get_pfn(*virt_to_xen_l1e((unsigned long)(va)))
> -#define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
> +#define vmap_to_mfn(va)     _mfn(l1e_get_pfn(*virt_to_xen_l1e((unsigned long)(va))))

l1e_get_mfn(*virt_to_xen_l1e((unsigned long)(va)))

> +#define vmap_to_page(va)    __mfn_to_page(vmap_to_mfn(va))
>  
>  #endif /* !defined(__ASSEMBLY__) */
>  
> diff --git a/xen/include/xen/tmem_xen.h b/xen/include/xen/tmem_xen.h
> index 542c0b3f20..8516a0b131 100644
> --- a/xen/include/xen/tmem_xen.h
> +++ b/xen/include/xen/tmem_xen.h
> @@ -25,7 +25,7 @@
>  typedef uint32_t pagesize_t;  /* like size_t, must handle largest PAGE_SIZE */
>  
>  #define IS_PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE)
> -#define IS_VALID_PAGE(_pi)    mfn_valid(_mfn(page_to_mfn(_pi)))
> +#define IS_VALID_PAGE(_pi)    mfn_valid(page_to_mfn(_pi))

/sigh  This is tautological.  The definition of a "valid mfn" in this
case is one for which we have frametable entry, and by having a struct
page_info in our hands, this is by definition true (unless you have a
wild pointer, at which point your bug is elsewhere).

IS_VALID_PAGE() is only ever used in assertions and never usefully, so
instead I would remove it entirely rather than trying to fix it up.

As for TMEM itself (Julien: This my no means blocks the patch.  It is
more an observation for Konrad to see about fixing), I see that TMEM is
broken on x86 machines with more than 5TB of RAM, because it is not
legal to call page_to_virt() on a struct page_info allocated from the
domheap (which is why alloc_xenheap_page() returns a void *, and
alloc_domheap_page() specifically doesn't).  The easy fix for this is to
swap the allocation primitives over to using xenheap allocations, which
would remove the need for page_to_virt() and back, or a better fix would
be to not pass everything thing by virtual address (at which point
retaining use of the domheap is fine).

~Andrew

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

  parent reply	other threads:[~2017-10-04 23:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04 18:15 [PATCH 0/7] xen: Convert __page_to_mfn and __mfn_to_page to use typesafe MFN Julien Grall
2017-10-04 18:15 ` [PATCH 1/7] xen/arm: domain_build: Clean-up insert_11_bank Julien Grall
2017-10-04 22:39   ` Andrew Cooper
2017-10-05 11:08     ` Julien Grall
2017-10-04 18:15 ` [PATCH 2/7] xen/arm32: mm: Rework is_xen_heap_page to avoid nameclash Julien Grall
2017-10-04 18:15 ` [PATCH 3/7] xen/x86: Use maddr_to_page and maddr_to_mfn to avoid open-coded >> PAGE_SHIFT Julien Grall
2017-10-04 22:41   ` Andrew Cooper
2017-10-04 18:15 ` [PATCH 4/7] xen/kimage: Remove defined but unused variables Julien Grall
2017-10-04 22:42   ` Andrew Cooper
2017-10-04 18:15 ` [PATCH 5/7] xen/xenoprof: Convert the file to use typesafe MFN Julien Grall
2017-10-04 22:43   ` Andrew Cooper
2017-10-04 18:15 ` [PATCH 6/7] xen/tmem: Convert the file common/tmem_xen.c " Julien Grall
2017-10-04 22:46   ` Andrew Cooper
2017-10-04 18:15 ` [PATCH 7/7] xen: Convert __page_to_mfn and __mfn_to_page " Julien Grall
2017-10-04 19:38   ` Razvan Cojocaru
2017-10-04 22:10   ` Tamas K Lengyel
2017-10-04 23:27   ` Andrew Cooper [this message]
2017-10-05  9:34     ` Jan Beulich
2017-10-05 14:54     ` Julien Grall
2017-10-06 17:31 ` [PATCH 0/7] " Tim Deegan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52aab653-7e67-7a6f-5b73-175353f29ab1@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=gang.wei@intel.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=julien.grall@linaro.org \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=konrad.wilk@oracle.com \
    --cc=paul.durrant@citrix.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=shane.wang@intel.com \
    --cc=sstabellini@kernel.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tamas@tklengyel.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.