Message ID | 20190603160350.29806-10-julien.grall@arm.com |
---|---|
State | New |
Headers | show |
Series | xen/arm: Properly disable M2P on Arm | expand |
>>> On 03.06.19 at 18:03, <julien.grall@arm.com> wrote: > --- a/xen/include/asm-x86/mm.h > +++ b/xen/include/asm-x86/mm.h > @@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t *desc); > > extern paddr_t mem_hotplug; > > +extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ Ah, now I see what Andrew was talking about. In my patch, I'll move the declarations ahead of the asm/mm.h inclusion point then. > @@ -483,24 +485,25 @@ extern paddr_t mem_hotplug; > #define SHARED_M2P(_e) ((_e) == SHARED_M2P_ENTRY) > > #define compat_machine_to_phys_mapping ((unsigned int > *)RDWR_COMPAT_MPT_VIRT_START) > -#define _set_gpfn_from_mfn(mfn, pfn) ({ \ > - struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); \ > - unsigned long entry = (d && (d == dom_cow)) ? \ > - SHARED_M2P_ENTRY : (pfn); \ > - ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \ > - (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(entry))), \ > - machine_to_phys_mapping[(mfn)] = (entry)); \ > - }) > > /* > * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) until > * the machine_to_phys_mapping is actually set up. > */ > extern bool machine_to_phys_mapping_valid; > -#define set_gpfn_from_mfn(mfn, pfn) do { \ > - if ( machine_to_phys_mapping_valid ) \ > - _set_gpfn_from_mfn(mfn, pfn); \ > -} while (0) > + > +static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) > +{ > + struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); const? And with that then Reviewed-by: Jan Beulich <jbeulich@suse.com> Jan
Hi Jan, On 6/4/19 5:21 PM, Jan Beulich wrote: >>>> On 03.06.19 at 18:03, <julien.grall@arm.com> wrote: >> --- a/xen/include/asm-x86/mm.h >> +++ b/xen/include/asm-x86/mm.h >> @@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t *desc); >> >> extern paddr_t mem_hotplug; >> >> +extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ > > Ah, now I see what Andrew was talking about. In my patch, I'll move > the declarations ahead of the asm/mm.h inclusion point then. Do you plan to merge your patch first? Just to know if I need to rebase. > >> @@ -483,24 +485,25 @@ extern paddr_t mem_hotplug; >> #define SHARED_M2P(_e) ((_e) == SHARED_M2P_ENTRY) >> >> #define compat_machine_to_phys_mapping ((unsigned int >> *)RDWR_COMPAT_MPT_VIRT_START) >> -#define _set_gpfn_from_mfn(mfn, pfn) ({ \ >> - struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); \ >> - unsigned long entry = (d && (d == dom_cow)) ? \ >> - SHARED_M2P_ENTRY : (pfn); \ >> - ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \ >> - (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(entry))), \ >> - machine_to_phys_mapping[(mfn)] = (entry)); \ >> - }) >> >> /* >> * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) until >> * the machine_to_phys_mapping is actually set up. >> */ >> extern bool machine_to_phys_mapping_valid; >> -#define set_gpfn_from_mfn(mfn, pfn) do { \ >> - if ( machine_to_phys_mapping_valid ) \ >> - _set_gpfn_from_mfn(mfn, pfn); \ >> -} while (0) >> + >> +static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) >> +{ >> + struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); > > const? And with that then Hmmm yes. I can't remember why I didn't do that before. > Reviewed-by: Jan Beulich <jbeulich@suse.com> Thank you! Cheers,
>>> On 04.06.19 at 18:23, <julien.grall@arm.com> wrote: > On 6/4/19 5:21 PM, Jan Beulich wrote: >>>>> On 03.06.19 at 18:03, <julien.grall@arm.com> wrote: >>> --- a/xen/include/asm-x86/mm.h >>> +++ b/xen/include/asm-x86/mm.h >>> @@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t *desc); >>> >>> extern paddr_t mem_hotplug; >>> >>> +extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ >> >> Ah, now I see what Andrew was talking about. In my patch, I'll move >> the declarations ahead of the asm/mm.h inclusion point then. > > Do you plan to merge your patch first? Just to know if I need to rebase. Well, that largely depends on having the necessary acks (i.e. in particular yours for the Arm changes) in place. If I had an Arm ack, the patch could go in right away (with the adjustments made as requested by Andrew) afaict. Jan
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index bf90916077..dcae558764 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t *desc); extern paddr_t mem_hotplug; +extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ + /****************************************************************************** * With shadow pagetables, the different kinds of address start * to get get confusing. @@ -483,24 +485,25 @@ extern paddr_t mem_hotplug; #define SHARED_M2P(_e) ((_e) == SHARED_M2P_ENTRY) #define compat_machine_to_phys_mapping ((unsigned int *)RDWR_COMPAT_MPT_VIRT_START) -#define _set_gpfn_from_mfn(mfn, pfn) ({ \ - struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); \ - unsigned long entry = (d && (d == dom_cow)) ? \ - SHARED_M2P_ENTRY : (pfn); \ - ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \ - (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(entry))), \ - machine_to_phys_mapping[(mfn)] = (entry)); \ - }) /* * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) until * the machine_to_phys_mapping is actually set up. */ extern bool machine_to_phys_mapping_valid; -#define set_gpfn_from_mfn(mfn, pfn) do { \ - if ( machine_to_phys_mapping_valid ) \ - _set_gpfn_from_mfn(mfn, pfn); \ -} while (0) + +static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) +{ + struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); + unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn; + + if ( !machine_to_phys_mapping_valid ) + return; + + if ( mfn < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 ) + compat_machine_to_phys_mapping[mfn] = entry; + machine_to_phys_mapping[mfn] = entry; +} extern struct rangeset *mmio_ro_ranges; @@ -590,8 +593,6 @@ unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits); unsigned long domain_get_maximum_gpfn(struct domain *d); -extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ - /* Definition of an mm lock: spinlock with extra fields for debugging */ typedef struct mm_lock { spinlock_t lock;
set_gpfn_from_mfn() is currently implement in a 2 part macros. The second macro is only called within the first macro, so they can be folded together. Furthermore, this is now converted to a static inline making the code more readable and safer. As set_gpfn_from_mfn is now a static inline function, the extern variable dom_cow should be defined earlier on. For convenience, the definition of all dom_* variables are moved earlier on. Signed-off-by: Julien Grall <julien.grall@arm.com> --- Changes in v3: - Add missing blank - Fix condition Changes in v2: - Patch added --- xen/include/asm-x86/mm.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)