Message ID | 20171004181526.9405-6-julien.grall@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | xen: Convert __page_to_mfn and __mfn_to_page to use typesafe MFN | expand |
On 04/10/2017 19:15, Julien Grall wrote: > @@ -134,25 +140,26 @@ static void xenoprof_reset_buf(struct domain *d) > } > > static int > -share_xenoprof_page_with_guest(struct domain *d, unsigned long mfn, int npages) > +share_xenoprof_page_with_guest(struct domain *d, mfn_t mfn, int npages) > { > int i; > > /* Check if previous page owner has released the page. */ > for ( i = 0; i < npages; i++ ) > { > - struct page_info *page = mfn_to_page(mfn + i); > + struct page_info *page = mfn_to_page(mfn_add(mfn, i)); A newline would be nice here... > if ( (page->count_info & (PGC_allocated|PGC_count_mask)) != 0 ) > { > printk(XENLOG_G_INFO "dom%d mfn %#lx page->count_info %#lx\n", > - d->domain_id, mfn + i, page->count_info); > + d->domain_id, mfn_x(mfn_add(mfn, i)), page->count_info); > return -EBUSY; > } > page_set_owner(page, NULL); > } > > for ( i = 0; i < npages; i++ ) > - share_xen_page_with_guest(mfn_to_page(mfn + i), d, XENSHARE_writable); > + share_xen_page_with_guest(mfn_to_page(mfn_add(mfn, i)), > + d, XENSHARE_writable); > > return 0; > } > @@ -161,11 +168,11 @@ static void > unshare_xenoprof_page_with_guest(struct xenoprof *x) > { > int i, npages = x->npages; > - unsigned long mfn = virt_to_mfn(x->rawbuf); > + mfn_t mfn = virt_to_mfn(x->rawbuf); > > for ( i = 0; i < npages; i++ ) > { > - struct page_info *page = mfn_to_page(mfn + i); > + struct page_info *page = mfn_to_page(mfn_add(mfn, i)); ... and here. This can easily be fixed on commit, so Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> > BUG_ON(page_get_owner(page) != current->domain); > if ( test_and_clear_bit(_PGC_allocated, &page->count_info) ) > put_page(page);
diff --git a/xen/common/xenoprof.c b/xen/common/xenoprof.c index a5fe6204a5..98937c9ac6 100644 --- a/xen/common/xenoprof.c +++ b/xen/common/xenoprof.c @@ -19,6 +19,12 @@ #include <xsm/xsm.h> #include <xen/hypercall.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) +#undef mfn_to_page +#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn)) + /* Limit amount of pages used for shared buffer (per domain) */ #define MAX_OPROF_SHARED_PAGES 32 @@ -134,25 +140,26 @@ static void xenoprof_reset_buf(struct domain *d) } static int -share_xenoprof_page_with_guest(struct domain *d, unsigned long mfn, int npages) +share_xenoprof_page_with_guest(struct domain *d, mfn_t mfn, int npages) { int i; /* Check if previous page owner has released the page. */ for ( i = 0; i < npages; i++ ) { - struct page_info *page = mfn_to_page(mfn + i); + struct page_info *page = mfn_to_page(mfn_add(mfn, i)); if ( (page->count_info & (PGC_allocated|PGC_count_mask)) != 0 ) { printk(XENLOG_G_INFO "dom%d mfn %#lx page->count_info %#lx\n", - d->domain_id, mfn + i, page->count_info); + d->domain_id, mfn_x(mfn_add(mfn, i)), page->count_info); return -EBUSY; } page_set_owner(page, NULL); } for ( i = 0; i < npages; i++ ) - share_xen_page_with_guest(mfn_to_page(mfn + i), d, XENSHARE_writable); + share_xen_page_with_guest(mfn_to_page(mfn_add(mfn, i)), + d, XENSHARE_writable); return 0; } @@ -161,11 +168,11 @@ static void unshare_xenoprof_page_with_guest(struct xenoprof *x) { int i, npages = x->npages; - unsigned long mfn = virt_to_mfn(x->rawbuf); + mfn_t mfn = virt_to_mfn(x->rawbuf); for ( i = 0; i < npages; i++ ) { - struct page_info *page = mfn_to_page(mfn + i); + struct page_info *page = mfn_to_page(mfn_add(mfn, i)); BUG_ON(page_get_owner(page) != current->domain); if ( test_and_clear_bit(_PGC_allocated, &page->count_info) ) put_page(page);
The file common/xenoprof.c is now converted to use typesafe. This is requiring to override the macros virt_to_mfn and mfn_to_page to make them work with mfn_t. Signed-off-by: Julien Grall <julien.grall@linaro.org> --- Cc: Andrew Cooper <andrew.cooper3@citrix.com> Cc: George Dunlap <George.Dunlap@eu.citrix.com> Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Jan Beulich <jbeulich@suse.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Stefano Stabellini <sstabellini@kernel.org> Cc: Tim Deegan <tim@xen.org> Cc: Wei Liu <wei.liu2@citrix.com> --- xen/common/xenoprof.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)