xen/x86: move d->arch.physaddr_bitsize field handling to pv32
PATCH 1/1 xen/x86: move d->arch.physaddr_bitsize field handling to pv32
From: Grygorii Strashko <[email protected]>
The d->arch.physaddr_bitsize field is used only by PV32 code, so:
- move domain_set_alloc_bitsize() function into PV32 code and clean up unused domain_set_alloc_bitsize() defines from other arches
- move domain_clamp_alloc_bitsize() function into PV32 code, rename to _domain_clamp_alloc_bitsize() and use generic domain_clamp_alloc_bitsize() define instead, clean up domain_clamp_alloc_bitsize() defines from !X86 arches
- move d->arch.physaddr_bitsize field under PV32 ifdef
--- xen/arch/arm/include/asm/mm.h | 3 --- xen/arch/ppc/include/asm/mm.h | 3 --- xen/arch/riscv/include/asm/mm.h | 3 --- xen/arch/x86/include/asm/domain.h | 2 +- xen/arch/x86/include/asm/mm.h | 10 +++++++--- xen/arch/x86/pv/dom0_build.c | 2 ++ xen/arch/x86/pv/domain.c | 21 +++++++++++++++++++++ xen/arch/x86/x86_64/mm.c | 20 -------------------- xen/include/xen/mm.h | 4 ++++ 9 files changed, 35 insertions(+), 33 deletions(-)
xen/arch/arm/include/asm/mm.h +0 -3
@@ -313,9 +313,6 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,/* Arch-specific portion of memory_op hypercall. */ long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg); -#define domain_set_alloc_bitsize (d) ((void)0) -#define domain_clamp_alloc_bitsize (d, b) (b) -unsigned long domain_get_maximum_gpfn (struct domain *d);/* Release all __init and __initdata ranges to be reused */
xen/arch/ppc/include/asm/mm.h +0 -3
@@ -96,9 +96,6 @@ static inline struct page_info *virt_to_page(const void *v)/* TODO: implement */ #define mfn_valid (mfn) ({ (void) (mfn); 0; }) -#define domain_set_alloc_bitsize (d) ((void)(d)) -#define domain_clamp_alloc_bitsize (d, b) (b) -#define PFN_ORDER (pfn_) ((pfn_)->v.free.order)struct page_info
xen/arch/riscv/include/asm/mm.h +0 -3
@@ -292,9 +292,6 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)/* TODO: implement */ #define mfn_valid (mfn) ({ (void)(mfn); 0; }) -#define domain_set_alloc_bitsize (d) ((void)(d)) -#define domain_clamp_alloc_bitsize (d, b) ((void)(d), (b)) -#define PFN_ORDER (pg) ((pg)->v.free.order)extern unsigned char cpu0_boot_stack[];
xen/arch/x86/include/asm/domain.h +1 -1
@@ -314,10 +314,10 @@ struct arch_domain#ifdef CONFIG_PV32 unsigned int hv_compat_vstart; -#endif /* Maximum physical-address bitwidth supported by this guest. */ unsigned int physaddr_bitsize; +#endif /* I/O-port admin-specified access capabilities. */ struct rangeset *ioport_caps;
xen/arch/x86/include/asm/mm.h +7 -3
@@ -619,9 +619,6 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);extern int memory_add (unsigned long spfn,unsigned long epfn,unsigned int pxm); -void domain_set_alloc_bitsize (struct domain *d); -unsigned int domain_clamp_alloc_bitsize (struct domain *d,unsigned int bits); -unsigned long domain_get_maximum_gpfn (struct domain *d);/* Definition of an mm lock: spinlock with extra fields for debugging */
@@ -659,4 +656,11 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr) return (mfn + nr) <= (virt_to_mfn(eva - 1) + 1); } +#ifdef CONFIG_PV32 +unsigned int _domain_clamp_alloc_bitsize (const struct domain *d, +unsigned int bits); +#define domain_clamp_alloc_bitsize (d, bits) \ + _domain_clamp_alloc_bitsize((d), (bits)) +#endif +#endif /* __ASM_X86_MM_H__ */
xen/arch/x86/pv/dom0_build.c +2 -0
@@ -626,6 +626,7 @@ static int __init dom0_construct(const struct boot_domain *bd) initrd_mfn =paddr_to_pfn (initrd->start); mfn = initrd_mfn; count =PFN_UP (initrd_len); +#ifdef CONFIG_PV32 if ( d->arch.physaddr_bitsize && ((mfn + count -1 ) >> (d->arch.physaddr_bitsize -PAGE_SHIFT )) ) {
@@ -650,6 +651,7 @@ static int __init dom0_construct(const struct boot_domain *bd) initrd->start = pfn_to_paddr(initrd_mfn); } else +#endif {while ( count-- )if (assign_pages (mfn_to_page (_mfn (mfn++)),1 , d,0 ) )
xen/arch/x86/pv/domain.c +21 -0
@@ -230,6 +230,27 @@ unsigned long pv_make_cr4(const struct vcpu *v) }#ifdef CONFIG_PV32 +unsigned int _domain_clamp_alloc_bitsize (const struct domain *d, +unsigned int bits) +{ +if ( (d ==NULL ) || (d->arch.physaddr_bitsize ==0 ) ) +return bits; +return min (d->arch.physaddr_bitsize, bits); +} + +static void domain_set_alloc_bitsize (struct domain *d) +{ +if ( !is_pv_32bit_domain (d) || + (MACH2PHYS_COMPAT_NR_ENTRIES (d) >= max_page) || + d->arch.physaddr_bitsize >0 ) +return ; + d->arch.physaddr_bitsize = +/* 2^n entries can be contained in guest's p2m mapping space */ +fls (MACH2PHYS_COMPAT_NR_ENTRIES (d)) -1 +/* 2^n pages -> 2^(n+PAGE_SHIFT) bits */ + +PAGE_SHIFT ; +} +int switch_compat (struct domain *d) {struct vcpu *v;
xen/arch/x86/x86_64/mm.c +0 -20
@@ -1119,26 +1119,6 @@ unmap:return ret; } -void domain_set_alloc_bitsize (struct domain *d) -{ -if ( !is_pv_32bit_domain (d) || - (MACH2PHYS_COMPAT_NR_ENTRIES (d) >= max_page) || - d->arch.physaddr_bitsize >0 ) -return ; - d->arch.physaddr_bitsize = -/* 2^n entries can be contained in guest's p2m mapping space */ -fls (MACH2PHYS_COMPAT_NR_ENTRIES (d)) -1 -/* 2^n pages -> 2^(n+PAGE_SHIFT) bits */ - +PAGE_SHIFT ; -} - -unsigned int domain_clamp_alloc_bitsize (struct domain *d,unsigned int bits) -{ -if ( (d ==NULL ) || (d->arch.physaddr_bitsize ==0 ) ) -return bits; -return min (d->arch.physaddr_bitsize, bits); -} -static int transfer_pages_to_heap (struct mem_hotadd_info *info) {unsigned long i;
xen/include/xen/mm.h +4 -0
@@ -641,4 +641,8 @@ static inline void put_page_alloc_ref(struct page_info *page) } } +#ifndef domain_clamp_alloc_bitsize +#define domain_clamp_alloc_bitsize (d, b) ((void)(d), (b)) +#endif +#endif /* __XEN_MM_H__ */
Signature · 1 line
2.34.1
Quoted 6 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
The
d->arch.physaddr_bitsizefield is used only by PV32 code, so:- move
domain_set_alloc_bitsize()function into PV32 code and clean up unuseddomain_set_alloc_bitsize()defines from other arches
This could be two separate patches, which likely would be pretty uncontroversial (and hence be able to go in quickly): One to drop the entirely unused #define-s for non-x86, and the other to move the x86 function so it can become static in the sole file using it.
The former patch may want to have several Fixes: tags (as to being Misra violations), as from all I can see there had never been a need to introduce those #define-s. Even in 3.2.x they were already confined to x86-only code.
xen/arch/x86/include/asm/domain.h struct arch_domain · line 320
Quoted 11 lines
xen/arch/x86/include/asm/domain.h +1
-1@@ -314,10 +314,10 @@ struct arch_domain#ifdef CONFIG_PV32 unsigned int hv_compat_vstart; -#endif /* Maximum physical-address bitwidth supported by this guest. */ unsigned int physaddr_bitsize; +#endif
I'm not happy to see the anomaly here being widened. PV-only items really belong in struct pv_domain.
Quoted 13 lines
xen/arch/x86/include/asm/mm.h +0
-3@@ -619,9 +619,6 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);extern int memory_add (unsigned long spfn,unsigned long epfn,unsigned int pxm); -void domain_set_alloc_bitsize (struct domain *d); -unsigned int domain_clamp_alloc_bitsize (struct domain *d,unsigned int bits); -unsigned long domain_get_maximum_gpfn (struct domain *d);/* Definition of an mm lock: spinlock with extra fields for debugging */
xen/arch/x86/include/asm/mm.h static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr) · line 661
Quoted 6 lines
xen/arch/x86/include/asm/mm.h +3
-0@@ -659,4 +656,11 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)return (mfn + nr) <= (virt_to_mfn (eva -1 ) +1 ); } +#ifdef CONFIG_PV32 +unsigned int _domain_clamp_alloc_bitsize (const struct domain *d, +unsigned int bits);
This introduces a (C language spec) naming violation - identifiers with this kind of a name a reserved for file-scope use.
xen/arch/x86/include/asm/mm.h static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr) · line 663
Quoted 2 lines
xen/arch/x86/include/asm/mm.h +2
-0+#define domain_clamp_alloc_bitsize (d, bits) \ + _domain_clamp_alloc_bitsize((d), (bits))
Nit: No need for the inner parentheses; they only hamper readability.
xen/arch/x86/pv/domain.c unsigned long pv_make_cr4(const struct vcpu *v) · line 239
Quoted 13 lines
xen/arch/x86/pv/domain.c +7
-0@@ -230,6 +230,27 @@ unsigned long pv_make_cr4(const struct vcpu *v) }#ifdef CONFIG_PV32 +unsigned int _domain_clamp_alloc_bitsize (const struct domain *d, +unsigned int bits) +{ +if ( (d ==NULL ) || (d->arch.physaddr_bitsize ==0 ) ) +return bits; +return min (d->arch.physaddr_bitsize, bits); +}
While moving, please make minimal style adjustments: Add the missing blank line before the final "return" here, and ...
xen/arch/x86/pv/domain.c unsigned long pv_make_cr4(const struct vcpu *v) · line 252
Quoted 12 lines
xen/arch/x86/pv/domain.c +12
-0+static void domain_set_alloc_bitsize (struct domain *d) +{ +if ( !is_pv_32bit_domain (d) || + (MACH2PHYS_COMPAT_NR_ENTRIES (d) >= max_page) || + d->arch.physaddr_bitsize >0 ) +return ; + d->arch.physaddr_bitsize = +/* 2^n entries can be contained in guest's p2m mapping space */ +fls (MACH2PHYS_COMPAT_NR_ENTRIES (d)) -1 +/* 2^n pages -> 2^(n+PAGE_SHIFT) bits */ + +PAGE_SHIFT ; +}
... add a blank line between the two statements here. In the former function please further consider switching == NULL and == 0 to our more common use of !.
Jan
Quoted 12 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
The
d->arch.physaddr_bitsizefield is used only by PV32 code, so:- move
domain_set_alloc_bitsize()function into PV32 code and clean up unuseddomain_set_alloc_bitsize()defines from other arches- move
domain_clamp_alloc_bitsize()function into PV32 code, rename to_domain_clamp_alloc_bitsize()and use genericdomain_clamp_alloc_bitsize()define instead, clean updomain_clamp_alloc_bitsize()defines from !X86 arches
Quoted 6 lines
- move
d->arch.physaddr_bitsizefield under PV32 ifdefSigned-off-by Grygorii Strashko <[email protected]>--- xen/arch/arm/include/asm/mm.h | 3 --- xen/arch/ppc/include/asm/mm.h | 3 ---
As I noticed only by getting a mail delivery failure back - please also be sure your submissions are up-to-date wrt ./MAINTAINERS: You meant to Cc Timothy for PPC, not Shawn.
Jan
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h | 3 --- xen/arch/x86/include/asm/domain.h | 2 +- xen/arch/x86/include/asm/mm.h | 10 +++++++--- xen/arch/x86/pv/dom0_build.c | 2 ++ xen/arch/x86/pv/domain.c | 21 +++++++++++++++++++++ xen/arch/x86/x86_64/mm.c | 20 -------------------- xen/include/xen/mm.h | 4 ++++ 9 files changed, 35 insertions(+), 33 deletions(-)