RE: [PATCH v5 06/16] x86/hyperv: allocate output arg pages if required
From: Wei Liu Sent: Wednesday, January 20, 2021 4:01 AM > > When Linux runs as the root partition, it will need to make hypercalls > which return data from the hypervisor. > > Allocate pages for storing results when Linux runs as the root > partition. > > Signed-off-by: Lillian Grassin-Drake > Co-Developed-by: Lillian Grassin-Drake > Signed-off-by: Wei Liu > --- > v3: Fix hv_cpu_die to use free_pages. > v2: Address Vitaly's comments > --- > arch/x86/hyperv/hv_init.c | 35 - > arch/x86/include/asm/mshyperv.h | 1 + > 2 files changed, 31 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index e04d90af4c27..6f4cb40e53fe 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -41,6 +41,9 @@ EXPORT_SYMBOL_GPL(hv_vp_assist_page); > void __percpu **hyperv_pcpu_input_arg; > EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); > > +void __percpu **hyperv_pcpu_output_arg; > +EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); > + > u32 hv_max_vp_index; > EXPORT_SYMBOL_GPL(hv_max_vp_index); > > @@ -73,12 +76,19 @@ static int hv_cpu_init(unsigned int cpu) > void **input_arg; > struct page *pg; > > - input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ > - pg = alloc_page(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); > + pg = alloc_pages(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL, > hv_root_partition ? > 1 : 0); > if (unlikely(!pg)) > return -ENOMEM; > + > + input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > *input_arg = page_address(pg); > + if (hv_root_partition) { > + void **output_arg; > + > + output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); > + *output_arg = page_address(pg + 1); > + } > > hv_get_vp_index(msr_vp_index); > > @@ -205,14 +215,23 @@ static int hv_cpu_die(unsigned int cpu) > unsigned int new_cpu; > unsigned long flags; > void **input_arg; > - void *input_pg = NULL; > + void *pg; > > local_irq_save(flags); > input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > - input_pg = *input_arg; > + pg = *input_arg; > *input_arg = NULL; > + > + if (hv_root_partition) { > + void **output_arg; > + > + output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); > + *output_arg = NULL; > + } > + > local_irq_restore(flags); > - free_page((unsigned long)input_pg); > + > + free_pages((unsigned long)pg, hv_root_partition ? 1 : 0); > > if (hv_vp_assist_page && hv_vp_assist_page[cpu]) > wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); > @@ -346,6 +365,12 @@ void __init hyperv_init(void) > > BUG_ON(hyperv_pcpu_input_arg == NULL); > > + /* Allocate the per-CPU state for output arg for root */ > + if (hv_root_partition) { > + hyperv_pcpu_output_arg = alloc_percpu(void *); > + BUG_ON(hyperv_pcpu_output_arg == NULL); > + } > + > /* Allocate percpu VP index */ > hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), > GFP_KERNEL); > diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h > index ac2b0d110f03..62d9390f1ddf 100644 > --- a/arch/x86/include/asm/mshyperv.h > +++ b/arch/x86/include/asm/mshyperv.h > @@ -76,6 +76,7 @@ static inline void hv_disable_stimer0_percpu_irq(int irq) {} > #if IS_ENABLED(CONFIG_HYPERV) > extern void *hv_hypercall_pg; > extern void __percpu **hyperv_pcpu_input_arg; > +extern void __percpu **hyperv_pcpu_output_arg; > > static inline u64 hv_do_hypercall(u64 control, void *input, void *output) > { > -- > 2.20.1 I think this all works OK. But a meta question: Do we need a separate per-cpu output argument page? From the Hyper-V hypercall standpoint, I don't think input and output args need to be in separate pages. They both just need to not cross a page boundary. As long as we don't have a hypercall where the sum of the sizes of the input and output args exceeds a page, we could just have a single page, and split it up in any manner that works for the particular hypercall. Thoughts? Michael ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v5 06/16] x86/hyperv: allocate output arg pages if required
On Wed, Jan 20, 2021 at 7:01 AM Wei Liu wrote: > > When Linux runs as the root partition, it will need to make hypercalls > which return data from the hypervisor. > > Allocate pages for storing results when Linux runs as the root > partition. > > Signed-off-by: Lillian Grassin-Drake > Co-Developed-by: Lillian Grassin-Drake > Signed-off-by: Wei Liu Reviewed-by: Pavel Tatashin The new warnings reported by the robot are the same as for the input argument. Pasha > --- > v3: Fix hv_cpu_die to use free_pages. > v2: Address Vitaly's comments > --- > arch/x86/hyperv/hv_init.c | 35 - > arch/x86/include/asm/mshyperv.h | 1 + > 2 files changed, 31 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index e04d90af4c27..6f4cb40e53fe 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -41,6 +41,9 @@ EXPORT_SYMBOL_GPL(hv_vp_assist_page); > void __percpu **hyperv_pcpu_input_arg; > EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); > > +void __percpu **hyperv_pcpu_output_arg; > +EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); > + > u32 hv_max_vp_index; > EXPORT_SYMBOL_GPL(hv_max_vp_index); > > @@ -73,12 +76,19 @@ static int hv_cpu_init(unsigned int cpu) > void **input_arg; > struct page *pg; > > - input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ > - pg = alloc_page(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); > + pg = alloc_pages(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL, > hv_root_partition ? 1 : 0); > if (unlikely(!pg)) > return -ENOMEM; > + > + input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > *input_arg = page_address(pg); > + if (hv_root_partition) { > + void **output_arg; > + > + output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); > + *output_arg = page_address(pg + 1); > + } > > hv_get_vp_index(msr_vp_index); > > @@ -205,14 +215,23 @@ static int hv_cpu_die(unsigned int cpu) > unsigned int new_cpu; > unsigned long flags; > void **input_arg; > - void *input_pg = NULL; > + void *pg; > > local_irq_save(flags); > input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > - input_pg = *input_arg; > + pg = *input_arg; > *input_arg = NULL; > + > + if (hv_root_partition) { > + void **output_arg; > + > + output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); > + *output_arg = NULL; > + } > + > local_irq_restore(flags); > - free_page((unsigned long)input_pg); > + > + free_pages((unsigned long)pg, hv_root_partition ? 1 : 0); > > if (hv_vp_assist_page && hv_vp_assist_page[cpu]) > wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); > @@ -346,6 +365,12 @@ void __init hyperv_init(void) > > BUG_ON(hyperv_pcpu_input_arg == NULL); > > + /* Allocate the per-CPU state for output arg for root */ > + if (hv_root_partition) { > + hyperv_pcpu_output_arg = alloc_percpu(void *); > + BUG_ON(hyperv_pcpu_output_arg == NULL); > + } > + > /* Allocate percpu VP index */ > hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), > GFP_KERNEL); > diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h > index ac2b0d110f03..62d9390f1ddf 100644 > --- a/arch/x86/include/asm/mshyperv.h > +++ b/arch/x86/include/asm/mshyperv.h > @@ -76,6 +76,7 @@ static inline void hv_disable_stimer0_percpu_irq(int irq) {} > #if IS_ENABLED(CONFIG_HYPERV) > extern void *hv_hypercall_pg; > extern void __percpu **hyperv_pcpu_input_arg; > +extern void __percpu **hyperv_pcpu_output_arg; > > static inline u64 hv_do_hypercall(u64 control, void *input, void *output) > { > -- > 2.20.1 > ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v5 06/16] x86/hyperv: allocate output arg pages if required
Hi Wei, I love your patch! Perhaps something to improve: [auto build test WARNING on e71ba9452f0b5b2e8dc8aa5445198cd9214a6a62] url: https://github.com/0day-ci/linux/commits/Wei-Liu/Introducing-Linux-root-partition-support-for-Microsoft-Hypervisor/20210120-215640 base:e71ba9452f0b5b2e8dc8aa5445198cd9214a6a62 config: x86_64-randconfig-s021-20210120 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-208-g46a52ca4-dirty # https://github.com/0day-ci/linux/commit/f93337fc44e13a1506633f5d308bf74a8311dada git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Wei-Liu/Introducing-Linux-root-partition-support-for-Microsoft-Hypervisor/20210120-215640 git checkout f93337fc44e13a1506633f5d308bf74a8311dada # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot "sparse warnings: (new ones prefixed by >>)" arch/x86/hyperv/hv_init.c:84:30: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] __percpu *__vpp_verify @@ got void [noderef] __percpu ** @@ arch/x86/hyperv/hv_init.c:84:30: sparse: expected void const [noderef] __percpu *__vpp_verify arch/x86/hyperv/hv_init.c:84:30: sparse: got void [noderef] __percpu ** arch/x86/hyperv/hv_init.c:89:39: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] __percpu *__vpp_verify @@ got void [noderef] __percpu ** @@ arch/x86/hyperv/hv_init.c:89:39: sparse: expected void const [noderef] __percpu *__vpp_verify arch/x86/hyperv/hv_init.c:89:39: sparse: got void [noderef] __percpu ** arch/x86/hyperv/hv_init.c:221:30: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] __percpu *__vpp_verify @@ got void [noderef] __percpu ** @@ arch/x86/hyperv/hv_init.c:221:30: sparse: expected void const [noderef] __percpu *__vpp_verify arch/x86/hyperv/hv_init.c:221:30: sparse: got void [noderef] __percpu ** arch/x86/hyperv/hv_init.c:228:39: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] __percpu *__vpp_verify @@ got void [noderef] __percpu ** @@ arch/x86/hyperv/hv_init.c:228:39: sparse: expected void const [noderef] __percpu *__vpp_verify arch/x86/hyperv/hv_init.c:228:39: sparse: got void [noderef] __percpu ** arch/x86/hyperv/hv_init.c:364:31: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected void [noderef] __percpu **extern [addressable] [toplevel] hyperv_pcpu_input_arg @@ got void *[noderef] __percpu * @@ arch/x86/hyperv/hv_init.c:364:31: sparse: expected void [noderef] __percpu **extern [addressable] [toplevel] hyperv_pcpu_input_arg arch/x86/hyperv/hv_init.c:364:31: sparse: got void *[noderef] __percpu * >> arch/x86/hyperv/hv_init.c:370:40: sparse: sparse: incorrect type in >> assignment (different address spaces) @@ expected void [noderef] >> __percpu **extern [addressable] [toplevel] hyperv_pcpu_output_arg @@ got >> void *[noderef] __percpu * @@ arch/x86/hyperv/hv_init.c:370:40: sparse: expected void [noderef] __percpu **extern [addressable] [toplevel] hyperv_pcpu_output_arg arch/x86/hyperv/hv_init.c:370:40: sparse: got void *[noderef] __percpu * vim +370 arch/x86/hyperv/hv_init.c 211 212 static int hv_cpu_die(unsigned int cpu) 213 { 214 struct hv_reenlightenment_control re_ctrl; 215 unsigned int new_cpu; 216 unsigned long flags; 217 void **input_arg; 218 void *pg; 219 220 local_irq_save(flags); > 221 input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); 222 pg = *input_arg; 223 *input_arg = NULL; 224 225 if (hv_root_partition) { 226 void **output_arg; 227 228 output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); 229 *output_arg = NULL; 230 } 231 232 local_irq_restore(flags); 233 234 free_pages((unsigned long)pg, hv_root_partition ? 1 : 0); 235 236 if (hv_vp_assist_page && hv_vp_assist_page[cpu]) 237 wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); 238 239 if (hv_reenlightenment_cb == NULL) 240 return 0; 241 242 rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)_ctrl)); 243 if (re_ctrl.target_vp == hv_vp_index[cpu]) { 244 /* 245 * Reassign