[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN



>>> On 07.05.19 at 17:14, <julien.grall@xxxxxxx> wrote:
> --- a/xen/arch/x86/mm/mem_sharing.c
> +++ b/xen/arch/x86/mm/mem_sharing.c
> @@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct 
> page_info *page,
>      xfree(gfn_info);
>  }
>  
> -static struct page_info* mem_sharing_lookup(unsigned long mfn)
> +static struct page_info* mem_sharing_lookup(mfn_t mfn)

Could you fix the style issue (swapped * and blank) here at the same time?

> @@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
>                  /* check for 1GB super page */
>                  if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
>                  {
> -                    mfn = l3e_get_pfn(l3e[i3]);
> -                    ASSERT(mfn_valid(_mfn(mfn)));
> +                    mfn = l3e_get_mfn(l3e[i3]);
> +                    ASSERT(mfn_valid(mfn));
>                      /* we have to cover 512x512 4K pages */
>                      for ( i2 = 0; 
>                            i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
>                            i2++)
>                      {
> -                        m2pfn = get_gpfn_from_mfn(mfn+i2);
> +                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
>                          if ( m2pfn != (gfn + i2) )
>                          {
>                              pmbad++;
> -                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
> -                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
> +                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" 
> gfn %#lx\n",
> +                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),

I think the shorter mfn_x(mfn) + i2 would be preferable here (and
similarly below).

> @@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
>                                  entry_count++;
>                              continue;
>                          }
> -                        mfn = l1e_get_pfn(l1e[i1]);
> -                        ASSERT(mfn_valid(_mfn(mfn)));
> -                        m2pfn = get_gpfn_from_mfn(mfn);
> +                        mfn = l1e_get_mfn(l1e[i1]);
> +                        ASSERT(mfn_valid(mfn));
> +                        m2pfn = get_pfn_from_mfn(mfn);
>                          if ( m2pfn != gfn &&
>                               type != p2m_mmio_direct &&
>                               !p2m_is_grant(type) &&
>                               !p2m_is_shared(type) )
>                          {
>                              pmbad++;
> -                            printk("mismatch: gfn %#lx -> mfn %#lx"
> -                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
> -                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
> -                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
> +                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> 
> gfn %#lx\n",
> +                                   gfn, mfn_x(mfn), m2pfn);
> +                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" 
> -> gfn %#lx\n",
> +                                       gfn, mfn_x(mfn), m2pfn);

George, do we really mean to have printk() and P2M_PRINTK() here?

> @@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
>      spin_lock(&d->page_alloc_lock);
>      page_list_for_each ( page, &d->page_list )
>      {
> -        mfn = mfn_x(page_to_mfn(page));
> +        mfn = page_to_mfn(page);
>  
> -        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
> +        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
>  
>          od = page_get_owner(page);
>  
>          if ( od != d )
>          {
> -            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
> -                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
> +            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
> +                       mfn_x(mfn), od, (od?od->domain_id:-1), d, 
> d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output
(which are an effect of the # flag that you delete), at least when
log messages contain a mix of hex and dec numbers. (I am, btw,
not convinced that switching to PRI_mfn here is helpful.)

Also would you mind fixing the formatting (missing blanks) here?

> --- a/xen/arch/x86/x86_64/traps.c
> +++ b/xen/arch/x86/x86_64/traps.c
> @@ -184,7 +184,8 @@ void vcpu_show_registers(const struct vcpu *v)
>  
>  void show_page_walk(unsigned long addr)
>  {
> -    unsigned long pfn, mfn = read_cr3() >> PAGE_SHIFT;
> +    unsigned long pfn;
> +    mfn_t mfn = maddr_to_mfn(read_cr3());

I realize you simply take what has been there and transform it, but
maddr_to_mfn() (other than shifting by PAGE_SHIFT) is not truly
applicable here: What the CR3 register holds is not a physical address,
both the low twelve bits as well as the high twelve ones have different
meaning. The shift is correct currently because the high ones are
(right now) zero on reads. Please consider AND-ing with
X86_CR3_ADDR_MASK (or keeping the shift).

> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -1424,7 +1424,7 @@ static void free_heap_pages(
>  
>          /* This page is not a guest frame any more. */
>          page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
> -        set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);
> +        set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY);

Stray leftover + ?

> --- a/xen/include/asm-x86/mm.h
> +++ b/xen/include/asm-x86/mm.h
> @@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow;       
> /* for vmcoreinfo */
>   */
>  extern bool machine_to_phys_mapping_valid;
>  
> -static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
> +static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn)
>  {
> -    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
> +    const unsigned long mfn_ = mfn_x(mfn);

I'm not overly happy to see a trailing underscore used outside a macro
definition, but other than perhaps "frame" this may indeed be the best
thing to do here.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.